diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 51d6ec435651afc9a9187fffed3f3addca1d8ba5..526f4918a62225a18abfaec705b23b92c2c1e823 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,15 +1,11 @@ +variables: + SOURCE_FOLDER: "src" + include: - project: 'iopsys/gitlab-ci-pipeline' file: '/static-code-analysis.yml' - ref: '0.32' + ref: '1.2' stages: - static_code_analysis -variables: - DEBUG: 'TRUE' - SOURCE_FOLDER: "./src" - FLAWFINDER_OPTIONS: "-m 4 --error-level=5" - CPPCHECK_OPTIONS: "--enable=all --error-exitcode=1" - COMPILE: "./gitlab-ci/compile.sh" - diff --git a/gitlab-ci/compile.sh b/gitlab-ci/compile.sh deleted file mode 100755 index 06b73c60ce685b607bd2d95eee90330776691e4e..0000000000000000000000000000000000000000 --- a/gitlab-ci/compile.sh +++ /dev/null @@ -1,15 +0,0 @@ -#!/bin/bash - -echo "Install dependencies" -ROOT="${PWD}" - -source ./gitlab-ci/shared.sh - -# install bbfdm -install_bbfdm - -# compile -echo "build stage" -cd ${ROOT}/src/ - -make all diff --git a/gitlab-ci/install-dependencies.sh b/gitlab-ci/install-dependencies.sh new file mode 100755 index 0000000000000000000000000000000000000000..285cc185721796dab4b7e8dba2c5292c8a88c21f --- /dev/null +++ b/gitlab-ci/install-dependencies.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +echo "install dependencies for tests" +source ./gitlab-ci/shared.sh + +# install bbfdm +install_bbfdm diff --git a/gitlab-ci/shared.sh b/gitlab-ci/shared.sh index f098751729cd67463d6d4912bc1bf7ffab42ee40..dc606510de3df2aea40656ed8fb4bd4c8a414169 100644 --- a/gitlab-ci/shared.sh +++ b/gitlab-ci/shared.sh @@ -13,7 +13,7 @@ function exec_cmd() function install_bbfdm() { - [ -d "/opt/dev/bbfdm" ] && rm -rf /opt/dev/bbfdm + [ -d "/opt/dev/bbfdm" ] && return 0 if [ -n "${BBFDM_BRANCH}" ]; then exec_cmd git clone -b ${BBFDM_BRANCH} https://dev.iopsys.eu/bbf/bbfdm.git /opt/dev/bbfdm diff --git a/src/Makefile b/src/Makefile index a0d2a1429f7f9d97a87cb1a15ab10f4e15cd5ba4..765abe50f0028040f11f68501abe743cf71c9425 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,5 +1,6 @@ LIBOUT := dm_usb.so -LIBOBJS := datamodel.o + +LIBOBJS := datamodel.o LIB_LDFLAGS = $(LDFLAGS) FPIC := -fPIC diff --git a/src/datamodel.c b/src/datamodel.c index 3bdb153c2b041ad415167148122f7a2883ffb00f..b2858cdefde95872b208fc7fc5b421edb78cdca1 100644 --- a/src/datamodel.c +++ b/src/datamodel.c @@ -53,13 +53,13 @@ struct usb_interface /************************************************************* * INIT *************************************************************/ -static void init_usb_port(char *folder_name, char *folder_path, struct usb_port *port) +static void init_usb_port(const char *folder_name, const char *folder_path, struct usb_port *port) { port->folder_name = dmstrdup(folder_name); port->folder_path = dmstrdup(folder_path); } -static void init_usb_interface(char *iface_name, char *iface_path, char *statistics_path, char *portlink, struct usb_interface *iface) +static void init_usb_interface(const char *iface_name, const char *iface_path, const char *statistics_path, const char *portlink, struct usb_interface *iface) { iface->iface_name = dmstrdup(iface_name); iface->iface_path = dmstrdup(iface_path); @@ -93,7 +93,8 @@ void free_sysfs_sections_list(struct list_head *dup_list) } } -static int synchronize_system_folders_with_dmmap(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, struct list_head *dup_list) +static int synchronize_system_folders_with_dmmap(const char *sysfsrep, const char *dmmap_package, const char *dmmap_section, + const char *opt_name, struct list_head *dup_list) { struct uci_section *s = NULL, *stmp = NULL, *dmmap_sect = NULL; char sysfs_rep_path[512]; @@ -205,6 +206,7 @@ static int __read_sysfs_usb_iface(const struct usb_interface *iface, const char static void writeFileContent(const char *filepath, const char *data) { + // cppcheck-suppress cert-MSC24-C FILE *fp = fopen(filepath, "ab"); if (fp != NULL) { @@ -228,7 +230,7 @@ static int browseUSBInterfaceInst(struct dmctx *dmctx, DMNODE *parent_node, void struct sysfs_dmsection *p = NULL; struct dm_data data = {0}; - synchronize_system_folders_with_dmmap(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "usb_iface_link", "usb_iface_instance", &dup_list); + synchronize_system_folders_with_dmmap(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_interface", "usb_iface_link", &dup_list); list_for_each_entry(p, &dup_list, list) { char statistics_path[652] = {0}; char iface_path[620] = {0}; @@ -287,7 +289,7 @@ static int browseUSBPortInst(struct dmctx *dmctx, DMNODE *parent_node, void *pre regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]$", 0); regcomp(®ex2, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); - synchronize_system_folders_with_dmmap(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_port", "port_link", "usb_port_instance", &dup_list); + synchronize_system_folders_with_dmmap(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_port", "port_link", &dup_list); list_for_each_entry(p, &dup_list, list) { if (regexec(®ex1, p->sysfs_folder_name, 0, NULL, 0) != 0 && @@ -320,7 +322,7 @@ static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, v LIST_HEAD(dup_list); struct dm_data data = {0}; - synchronize_system_folders_with_dmmap(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", "usb_host_instance", &dup_list); + synchronize_system_folders_with_dmmap(SYSFS_USB_DEVICES_PATH, "dmmap_usb", "dmmap_host", "port_link", &dup_list); list_for_each_entry(p, &dup_list, list) { @@ -342,7 +344,8 @@ static int browseUSBUSBHostsHostInst(struct dmctx *dmctx, DMNODE *parent_node, v return 0; } -static int synchronize_usb_devices_with_dmmap_opt_recursively(char *sysfsrep, char *dmmap_package, char *dmmap_section, char *opt_name, char* inst_opt, int is_root, struct list_head *dup_list) +static int synchronize_usb_devices_with_dmmap_opt_recursively(const char *sysfsrep, const char *dmmap_package, const char *dmmap_section, + const char *opt_name, const char *inst_opt, int is_root, struct list_head *dup_list) { struct uci_section *s = NULL, *stmp = NULL, *dmmap_sect = NULL; DIR *dir = NULL; @@ -553,9 +556,9 @@ static int get_USBInterface_Enable(char *refparam, struct dmctx *ctx, void *data __read_sysfs_usb_iface(p->additional_data, "carrier", carrier, sizeof(carrier)); if (carrier[0] == '1') - *value = "1"; + *value = dmstrdup("1"); else - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -580,9 +583,9 @@ static int get_USBInterface_Status(char *refparam, struct dmctx *ctx, void *data __read_sysfs_usb_iface(p->additional_data, "carrier", carrier, sizeof(carrier)); if (carrier[0] == '1') - *value = "Up"; + *value = dmstrdup("Up"); else - *value = "Down"; + *value = dmstrdup("Down"); return 0; } @@ -609,7 +612,7 @@ static int get_USBInterface_Name(char *refparam, struct dmctx *ctx, void *data, static int get_USBInterface_LastChange(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -624,7 +627,7 @@ static int get_USBInterface_LowerLayers(char *refparam, struct dmctx *ctx, void static int get_USBInterface_Upstream(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -700,13 +703,13 @@ static int get_USBInterfaceStats_ErrorsReceived(char *refparam, struct dmctx *ct static int get_USBInterfaceStats_UnicastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } static int get_USBInterfaceStats_UnicastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -724,7 +727,7 @@ static int get_USBInterfaceStats_DiscardPacketsReceived(char *refparam, struct d static int get_USBInterfaceStats_MulticastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -736,13 +739,13 @@ static int get_USBInterfaceStats_MulticastPacketsReceived(char *refparam, struct static int get_USBInterfaceStats_BroadcastPacketsSent(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } static int get_USBInterfaceStats_BroadcastPacketsReceived(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -791,17 +794,17 @@ static int get_USBPort_Type(char *refparam, struct dmctx *ctx, void *data, char __read_sysfs_usb_port(port, "bDeviceClass", deviceclass, sizeof(deviceclass)); if(DM_LSTRSTR(port->folder_name, "usb") == port->folder_name) - *value= "Host"; + *value = dmstrdup("Host"); else if (DM_LSTRCMP(deviceclass, "09") == 0) - *value= "Hub"; + *value = dmstrdup("Hub"); else - *value= "Device"; + *value = dmstrdup("Device"); return 0; } static int get_USBPort_Receptacle(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value= "Standard-A"; + *value = dmstrdup("Standard-A"); return 0; } @@ -813,13 +816,13 @@ static int get_USBPort_Rate(char *refparam, struct dmctx *ctx, void *data, char __read_sysfs_usb_port(p->additional_data, "speed", speed, sizeof(speed)); if(DM_LSTRCMP(speed, "1.5") == 0) - *value= "Low"; + *value = dmstrdup("Low"); else if(DM_LSTRCMP(speed, "12") == 0) - *value= "Full"; + *value = dmstrdup("Full"); else if(DM_LSTRCMP(speed, "480") == 0) - *value= "High"; + *value = dmstrdup("High"); else - *value= "Super"; + *value = dmstrdup("Super"); return 0; } @@ -831,11 +834,11 @@ static int get_USBPort_Power(char *refparam, struct dmctx *ctx, void *data, char __read_sysfs_usb_port(p->additional_data, "power/control", pwrctl, sizeof(pwrctl)); if (pwrctl[0] == 0) - *value = "Unknown"; + *value = dmstrdup("Unknown"); else if (!DM_LSTRCMP(pwrctl, "auto")) - *value ="Self"; + *value = dmstrdup("Self"); else - *value ="Bus"; + *value = dmstrdup("Bus"); return 0; } @@ -865,7 +868,7 @@ static int get_USBUSBHostsHost_Enable(char *refparam, struct dmctx *ctx, void *d struct dm_data *p = (struct dm_data *)data; __read_sysfs_usb_port(p->additional_data, "power/wakeup", up, sizeof(up)); - *value = DM_LSTRCMP(up, "enabled") == 0 ? "1" : "0"; + *value = DM_LSTRCMP(up, "enabled") == 0 ? dmstrdup("1") : dmstrdup("0"); return 0; } @@ -909,19 +912,19 @@ static int get_USBUSBHostsHost_Type(char *refparam, struct dmctx *ctx, void *dat __read_sysfs_usb_port(p->additional_data, "serial", serial, sizeof(serial)); if(strcasestr(serial, "ohci")!=NULL) - *value= "OHCI"; + *value = dmstrdup("OHCI"); else if(strcasestr(serial, "ehci")!=NULL) - *value= "EHCI"; + *value = dmstrdup("EHCI"); else if(strcasestr(serial, "uhci")!=NULL) - *value= "UHCI"; + *value = dmstrdup("UHCI"); else - *value= "xHCI"; + *value = dmstrdup("xHCI"); return 0; } static int get_USBUSBHostsHost_Reset(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -966,9 +969,9 @@ static int get_USBUSBHostsHost_PowerManagementEnable(char *refparam, struct dmct __read_sysfs_usb_port(p->additional_data, "power/level", power, sizeof(power)); if(power[0] == 0 || DM_LSTRCMP(power, "suspend") == 0) - *value= "false"; + *value = dmstrdup("false"); else - *value= "true"; + *value = dmstrdup("true"); return 0; } @@ -1064,7 +1067,7 @@ static int get_USBUSBHostsHostDevice_ProductID(char *refparam, struct dmctx *ctx unsigned int ui_idproduct; struct dm_data *p = (struct dm_data *)data; - *value = "0"; + *value = dmstrdup("0"); int rc = read_sysfs_usb_port(p->additional_data, "idProduct", &idproduct); if (rc != -1 && idproduct != NULL) { @@ -1080,7 +1083,7 @@ static int get_USBUSBHostsHostDevice_VendorID(char *refparam, struct dmctx *ctx, unsigned int ui_idvendor; struct dm_data *p = (struct dm_data *)data; - *value = "0"; + *value = dmstrdup("0"); int rc = read_sysfs_usb_port(p->additional_data, "idVendor", &idvendor); if (rc != -1 && idvendor != NULL) { @@ -1125,7 +1128,7 @@ static int get_USBUSBHostsHostDevice_Port(char *refparam, struct dmctx *ctx, voi *value = dmstrdup(portname[0]); goto out; } - *value = "0"; + *value = dmstrdup("0"); out: regfree(®ex1); regfree(®ex2); @@ -1154,14 +1157,14 @@ static int get_USBUSBHostsHostDevice_Parent(char *refparam, struct dmctx *ctx, v regcomp(®ex1, "^[0-9][0-9]*-[0-9]*[0-9]\\.[0-9]*[0-9]$", 0); if (regexec(®ex1, usbdev->folder_name, 0, NULL, 0) != 0 || p->dmmap_section == NULL) { - *value = ""; + *value = dmstrdup(""); goto out; } char **filename = strsplit(usbdev->folder_name, "-", &length); char **port = strsplit(filename[1], ".", &length); if (!port || port[0] == NULL) { - *value = ""; + *value = dmstrdup(""); goto out; } @@ -1188,9 +1191,9 @@ static int get_USBUSBHostsHostDevice_IsSuspended(char *refparam, struct dmctx *c __read_sysfs_usb_port(p->additional_data, "power/runtime_status", status, sizeof(status)); if(DM_LSTRNCMP(status, "suspended", 9) == 0) - *value= "1"; + *value = dmstrdup("1"); else - *value = "0"; + *value = dmstrdup("0"); return 0; } @@ -1200,7 +1203,7 @@ static int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx struct dm_data *p = (struct dm_data *)data; read_sysfs_usb_port(p->additional_data, "bmAttribute", &attr); - *value = "0"; + *value = dmstrdup("0"); if (DM_STRLEN(attr)) { unsigned long val = 0; val = strtoul(attr, NULL, 16); @@ -1210,7 +1213,7 @@ static int get_USBUSBHostsHostDevice_IsSelfPowered(char *refparam, struct dmctx val = val & bits; - *value = val ? "1" : "0"; + *value = val ? dmstrdup("1") : dmstrdup("0"); } return 0; }