diff --git a/dmtree/tr181/managementserver.c b/dmtree/tr181/managementserver.c index c4e1f335..cbe10216 100644 --- a/dmtree/tr181/managementserver.c +++ b/dmtree/tr181/managementserver.c @@ -17,18 +17,22 @@ /*#Device.ManagementServer.URL!UCI:cwmp/acs,acs/url*/ static int get_management_server_url(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - char *dhcp = NULL, *url = NULL, *provisioning_value = NULL; + char *dhcp = NULL, *url = NULL, *dhcp_url = NULL; + bool discovery = false; dmuci_get_option_value_string("cwmp", "acs", "dhcp_discovery", &dhcp); dmuci_get_option_value_string("cwmp", "acs", "url", &url); - dmuci_get_option_value_string("cwmp", "acs", "dhcp_url", &provisioning_value); + dmuci_get_option_value_string("cwmp", "acs", "dhcp_url", &dhcp_url); - if ( ((dhcp && strcmp(dhcp, "enable") == 0 ) || ((url == NULL) || (url[0] == '\0'))) && ((provisioning_value != NULL) && (provisioning_value[0] != '\0')) ) - *value = provisioning_value; - else if ((url != NULL) && (url[0] != '\0')) + discovery = dmuci_string_to_boolean(dhcp); + + if ((discovery == true) && (DM_STRLEN(dhcp_url) != 0)) + *value = dhcp_url; + else if (DM_STRLEN(url) != 0) *value = url; else *value = ""; + return 0; } diff --git a/libbbf_api/dmapi.h b/libbbf_api/dmapi.h index 918c4df1..89e64474 100644 --- a/libbbf_api/dmapi.h +++ b/libbbf_api/dmapi.h @@ -56,6 +56,8 @@ do { \ DST[SIZE-1] = '\0'; \ } while(0) +#define DM_STRLEN(SRC) (SRC != NULL) ? strlen(SRC) : 0 + #define UBUS_ARGS (struct ubus_arg[]) #define RANGE_ARGS (struct range_args[]) #define LIST_KEY (const char *[]) diff --git a/libbbf_api/dmuci.c b/libbbf_api/dmuci.c index 7aa9eeea..9d97b978 100644 --- a/libbbf_api/dmuci.c +++ b/libbbf_api/dmuci.c @@ -908,3 +908,19 @@ end: return val; } + +bool dmuci_string_to_boolean(char *value) +{ + if (!value) + return false; + + if (strncasecmp(value, "true", 4) == 0 || + value[0] == '1' || + strncasecmp(value, "on", 2) == 0 || + strncasecmp(value, "yes", 3) == 0 || + strncasecmp(value, "enable", 6) == 0) + return true; + + return false; +} + diff --git a/libbbf_api/dmuci.h b/libbbf_api/dmuci.h index ce67b146..71fb5425 100644 --- a/libbbf_api/dmuci.h +++ b/libbbf_api/dmuci.h @@ -376,6 +376,7 @@ int dmuci_set_value_varstate(char *package, char *section, char *option, char *v char *dmuci_get_value_by_path(char *path, char *package, char *section, char *option); char *dmuci_set_value_by_path(char *path, char *package, char *section, char *option, char *value); +bool dmuci_string_to_boolean(char *value); #endif