Get forced notifications from a struct dm_parameter array && enhance the function check_instance_wildcard_parameter_by_regex

This commit is contained in:
Omar Kallel 2020-11-21 01:55:21 +01:00
parent e40d1142a9
commit d8eb9efa72
3 changed files with 22 additions and 37 deletions

View file

@ -110,6 +110,14 @@ struct notification notifications[] = {
[6] = {"6", "passive_active_lw"}
};
struct dm_parameter forced_notifications_parameters[] = {
{.name = "Device.DeviceInfo.SoftwareVersion", .notification = "2"},
{.name = "Device.DeviceInfo.ProvisioningCode", .notification = "2"},
{.name = "Device.ManagementServer.ConnectionRequestURL", .notification = "2"},
{.name = "Device.ManagementServer.ConnReqJabberID", .notification = "2"},
{.name = "Device.SoftwareModules.ExecutionUnit.*.Status", .notification = "2"}
};
struct dm_acl dm_acl[] = {
[0] = {DM_PUBLIC_LIST, "public_list"},
[1] = {DM_PUBLIC_READ, "public_read"},
@ -1888,21 +1896,10 @@ int dm_entry_enabled_notify(struct dmctx *dmctx)
char* check_parameter_forced_notification(char *parameter)
{
int i;
struct uci_list *list_notif;
char *pch, *notification = "0";
struct uci_element *e;
for (i = (ARRAY_SIZE(notifications) - 1); i >= 0; i--) {
dmuci_get_option_value_list("cwmp", "@forced_notifications[0]", notifications[i].type, &list_notif);
if (list_notif) {
uci_foreach_element(list_notif, e) {
pch = e->name;
if (strcmp(pch, parameter) == 0 || check_instance_wildcard_parameter_by_regex(parameter, pch) == 0) {
notification = notifications[i].value;
return notification;
}
}
}
for (i=0; i<ARRAY_SIZE(forced_notifications_parameters); i++) {
if (strcmp(forced_notifications_parameters[i].name, parameter) == 0 || check_instance_wildcard_parameter_by_regex(parameter, forced_notifications_parameters[i].name) == 0)
return forced_notifications_parameters[i].notification;
}
return NULL;
}

View file

@ -180,6 +180,7 @@ struct dm_parameter {
char *type;
char *version;
unsigned int flags;
char *notification;
};
struct dm_json_parameter {

View file

@ -1852,28 +1852,15 @@ void append_dot_to_string(char *new_string, const char *string, size_t len)
int check_instance_wildcard_parameter_by_regex(char *parameter, char* regex)
{
char **array_str = strsplit_by_str(regex, ".*.");
int i = 0;
char *res= NULL, *tmp = NULL;
regex_t regex1 = {};
while (array_str[i]) {
if (res == NULL) {
dmasprintf(&res, "^%s", array_str[i]);
i++;
continue;
}
tmp = dmstrdup(res);
FREE(res);
dmasprintf(&res, "%s\\.[0-9][0-9]*\\.%s", tmp, array_str[i]);
FREE(tmp);
i++;
size_t l1, l2;
char **parameter_split = strsplit(parameter, ".", &l1);
char **regex_split = strsplit(regex, ".", &l2);
if (l1 != l2)
return -1;
int i;
for (i=0; i<l1; i++) {
if (strcmp(parameter_split[i], regex_split[i]) != 0 && (strcmp(regex_split[i], "*") != 0 || atoi(parameter_split[i])<=0))
return -1;
}
tmp = dmstrdup(res);
FREE(res);
dmasprintf(&res, "%s%c", tmp, '$');
regcomp(&regex1, res, 0);
int ret = regexec(&regex1, parameter, 0, NULL, 0);
regfree(&regex1);
FREE(res);
return ret;
return 0;
}