From 0d5afce5f1e9158c9fa74a40737f8c26e2ac5dec Mon Sep 17 00:00:00 2001 From: Amin Ben Ramdhane Date: Tue, 25 May 2021 15:11:29 +0100 Subject: [PATCH] VoiceService: Fix some issues - Device.Services.VoiceService.{i}.CallControl.Line.{i}.Enable: change the type to boolean instead of string - Device.Services.VoiceService.{i}.SIP.Network.{i}.ProxyServerPort: define its default value - Fix static code analysis issue - Update TR104 JSON mapping --- dmtree/json/tr104.json | 51 ++++++++++++++++-- .../tr104/servicesvoiceservicecallcontrol.c | 4 +- dmtree/tr104/servicesvoiceservicesip.c | 52 ++++--------------- 3 files changed, 59 insertions(+), 48 deletions(-) diff --git a/dmtree/json/tr104.json b/dmtree/json/tr104.json index 2349927d..244896db 100644 --- a/dmtree/json/tr104.json +++ b/dmtree/json/tr104.json @@ -3981,6 +3981,21 @@ "TCP", "TLS", "SCTP" + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "asterisk", + "section": { + "type": "sip_service_provider", + "index": "@i-1" + }, + "option": { + "name": "transport" + } + } + } ] }, "OutboundProxy": { @@ -4007,7 +4022,7 @@ "index": "@i-1" }, "option": { - "name": "outboundproxy" + "name": "outbound_proxy" } } } @@ -4067,7 +4082,7 @@ "index": "@i-1" }, "option": { - "name": "outboundproxy" + "name": "outbound_proxy_port" } } } @@ -7002,7 +7017,22 @@ "cwmp", "usp" ], - "datatype": "boolean" + "datatype": "boolean", + "mapping": [ + { + "type": "uci", + "uci": { + "file": "asterisk", + "section": { + "type": "tel_line", + "index": "@i-1" + }, + "option": { + "name": "enabled" + } + } + } + ] }, "QuiescentMode": { "type": "boolean", @@ -7106,6 +7136,21 @@ { "max": 256 } + ], + "mapping": [ + { + "type": "uci", + "uci": { + "file": "asterisk", + "section": { + "type": "tel_line", + "index": "@i-1" + }, + "option": { + "name": "sip_account" + } + } + } ] }, "CallingFeatures": { diff --git a/dmtree/tr104/servicesvoiceservicecallcontrol.c b/dmtree/tr104/servicesvoiceservicecallcontrol.c index 8843a9b5..0ffb7ab9 100644 --- a/dmtree/tr104/servicesvoiceservicecallcontrol.c +++ b/dmtree/tr104/servicesvoiceservicecallcontrol.c @@ -336,6 +336,7 @@ static int set_ServicesVoiceServiceCallControlLine_Provider(char *refparam, stru return 0; } +/*#Device.Services.VoiceService.{i}.CallControl.Line.{i}.Enable!UCI:asterisk/tel_line,@i-1/enabled*/ static int get_ServicesVoiceServiceCallControlLine_Enable(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "enabled", "1"); @@ -559,13 +560,12 @@ DMOBJ tServicesVoiceServiceCallControlObj[] = { /* *** Device.Services.VoiceService.{i}.CallControl.Line.{i}. *** */ DMLEAF tServicesVoiceServiceCallControlLineParams[] = { /* PARAM, permission, type, getvalue, setvalue, bbfdm_type*/ +{"Enable", &DMWRITE, DMT_BOOL, get_ServicesVoiceServiceCallControlLine_Enable, set_ServicesVoiceServiceCallControlLine_Enable, BBFDM_BOTH}, {"Status", &DMREAD, DMT_STRING, get_ServicesVoiceServiceCallControlLine_Status, NULL, BBFDM_BOTH}, {"CallStatus", &DMREAD, DMT_STRING, get_ServicesVoiceServiceCallControlLine_CallStatus, NULL, BBFDM_BOTH}, {"Origin", &DMREAD, DMT_STRING, get_ServicesVoiceServiceCallControlLine_Origin, NULL, BBFDM_BOTH}, {"DirectoryNumber", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceCallControlLine_DirectoryNumber, set_ServicesVoiceServiceCallControlLine_DirectoryNumber, BBFDM_BOTH}, {"Provider", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceCallControlLine_Provider, set_ServicesVoiceServiceCallControlLine_Provider, BBFDM_BOTH}, -{"Enable", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceCallControlLine_Enable, set_ServicesVoiceServiceCallControlLine_Enable, BBFDM_BOTH}, - {0} }; diff --git a/dmtree/tr104/servicesvoiceservicesip.c b/dmtree/tr104/servicesvoiceservicesip.c index 75f7100d..f0e64a89 100644 --- a/dmtree/tr104/servicesvoiceservicesip.c +++ b/dmtree/tr104/servicesvoiceservicesip.c @@ -286,7 +286,6 @@ static int get_ServicesVoiceServiceSIPClient_RegisterURI(char *refparam, struct { char *value_user = NULL; char *value_address = NULL; - char buf[256] = {0}; dmuci_get_value_by_section_string((struct uci_section *)data, "user", &value_user); dmuci_get_value_by_section_string((struct uci_section *)data, "domain", &value_address); @@ -295,11 +294,7 @@ static int get_ServicesVoiceServiceSIPClient_RegisterURI(char *refparam, struct dmuci_get_value_by_section_string((struct uci_section *)data, "outbound_proxy", &value_address); } - snprintf(buf, sizeof(buf), "%s@%s", value_user, value_address); - - if (buf[0] != '\0') - *value = dmstrdup(buf); - + dmasprintf(value, "%s@%s", value_user, value_address); return 0; } @@ -587,7 +582,8 @@ static int set_ServicesVoiceServiceSIPNetwork_ProxyServerPort(char *refparam, st } /*#Device.Services.VoiceService.{i}.SIP.Network.{i}.ProxyServerTransport!UCI:asterisk/sip_service_provider,@i-1/transport*/ -static int get_ServicesVoiceServiceSIPNetwork_ProxyServerTransport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) +/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.UserAgentTransport!UCI:asterisk/sip_service_provider,@i-1/transport*/ +static int get_ServicesVoiceServiceSIPNetwork_Transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "transport", value); if (*value && **value) { @@ -600,7 +596,7 @@ static int get_ServicesVoiceServiceSIPNetwork_ProxyServerTransport(char *refpara return 0; } -static int set_ServicesVoiceServiceSIPNetwork_ProxyServerTransport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) +static int set_ServicesVoiceServiceSIPNetwork_Transport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) { switch (action) { case VALUECHECK: @@ -708,7 +704,7 @@ static int set_ServicesVoiceServiceSIPNetwork_UserAgentDomain(char *refparam, st return 0; } -/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.OutboundProxy!UCI:asterisk/sip_service_provider,@i-1/outboundproxy*/ +/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.OutboundProxy!UCI:asterisk/sip_service_provider,@i-1/outbound_proxy*/ static int get_ServicesVoiceServiceSIPNetwork_OutboundProxy(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { dmuci_get_value_by_section_string((struct uci_section *)data, "outbound_proxy", value); @@ -729,10 +725,10 @@ static int set_ServicesVoiceServiceSIPNetwork_OutboundProxy(char *refparam, stru return 0; } -/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.OutboundProxyPort!UCI:asterisk/sip_service_provider,@i-1/outboundproxy*/ +/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.OutboundProxyPort!UCI:asterisk/sip_service_provider,@i-1/outbound_proxy_port*/ static int get_ServicesVoiceServiceSIPNetwork_OutboundProxyPort(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { - dmuci_get_value_by_section_string((struct uci_section *)data, "outbound_proxy_port", value); + *value = dmuci_get_value_by_section_fallback_def((struct uci_section *)data, "outbound_proxy_port", DEFAULT_SIP_PORT_STR); return 0; } @@ -750,36 +746,6 @@ static int set_ServicesVoiceServiceSIPNetwork_OutboundProxyPort(char *refparam, return 0; } -/*#Device.Services.VoiceService.{i}.SIP.Network.{i}.UserAgentTransport!UCI:asterisk/sip_service_provider,@i-1/transport*/ -static int get_ServicesVoiceServiceSIPNetwork_UserAgentTransport(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) -{ - dmuci_get_value_by_section_string((struct uci_section *)data, "transport", value); - if (*value && **value) { - // Convert to uppercase - for (char *ch = *value; *ch != '\0'; ch++) - *ch = toupper(*ch); - } else { - *value = "UDP"; - } - return 0; -} - -static int set_ServicesVoiceServiceSIPNetwork_UserAgentTransport(char *refparam, struct dmctx *ctx, void *data, char *instance, char *value, int action) -{ - switch (action) { - case VALUECHECK: - if (dm_validate_string(value, -1, -1, ProxyServerTransport, NULL)) - return FAULT_9007; - break; - case VALUESET: - for (char *ch = value; *ch != '\0'; ch++) - *ch = tolower(*ch); - dmuci_set_value_by_section((struct uci_section *)data, "transport", value); - break; - } - return 0; -} - /*#Device.Services.VoiceService.{i}.SIP.Network.{i}.STUNServer!UCI:asterisk/sip_advanced,sip_options/stun_server*/ static int get_ServicesVoiceServiceSIPNetwork_STUNServer(char *refparam, struct dmctx *ctx, void *data, char *instance, char **value) { @@ -1084,14 +1050,14 @@ DMLEAF tServicesVoiceServiceSIPNetworkParams[] = { {"Status", &DMREAD, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_Status, NULL, BBFDM_BOTH}, {"ProxyServer", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_ProxyServer, set_ServicesVoiceServiceSIPNetwork_ProxyServer, BBFDM_BOTH}, {"ProxyServerPort", &DMWRITE, DMT_UNINT, get_ServicesVoiceServiceSIPNetwork_ProxyServerPort, set_ServicesVoiceServiceSIPNetwork_ProxyServerPort, BBFDM_BOTH}, -{"ProxyServerTransport", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_ProxyServerTransport, set_ServicesVoiceServiceSIPNetwork_ProxyServerTransport, BBFDM_BOTH}, +{"ProxyServerTransport", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_Transport, set_ServicesVoiceServiceSIPNetwork_Transport, BBFDM_BOTH}, {"RegistrarServer", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_RegistrarServer, set_ServicesVoiceServiceSIPNetwork_RegistrarServer, BBFDM_BOTH}, {"RegistrarServerPort", &DMWRITE, DMT_UNINT, get_ServicesVoiceServiceSIPNetwork_RegistrarServerPort, set_ServicesVoiceServiceSIPNetwork_RegistrarServerPort, BBFDM_BOTH}, {"RegistrarServerTransport", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_RegistrarServerTransport, set_ServicesVoiceServiceSIPNetwork_RegistrarServerTransport, BBFDM_BOTH}, {"UserAgentDomain", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_UserAgentDomain, set_ServicesVoiceServiceSIPNetwork_UserAgentDomain, BBFDM_BOTH}, {"OutboundProxy", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_OutboundProxy, set_ServicesVoiceServiceSIPNetwork_OutboundProxy, BBFDM_BOTH}, {"OutboundProxyPort", &DMWRITE, DMT_UNINT, get_ServicesVoiceServiceSIPNetwork_OutboundProxyPort, set_ServicesVoiceServiceSIPNetwork_OutboundProxyPort, BBFDM_BOTH}, -{"UserAgentTransport", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_UserAgentTransport, set_ServicesVoiceServiceSIPNetwork_UserAgentTransport, BBFDM_BOTH}, +{"UserAgentTransport", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_Transport, set_ServicesVoiceServiceSIPNetwork_Transport, BBFDM_BOTH}, {"STUNServer", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_STUNServer, set_ServicesVoiceServiceSIPNetwork_STUNServer, BBFDM_BOTH}, {"RegistrationPeriod", &DMWRITE, DMT_UNINT, get_ServicesVoiceServiceSIPNetwork_RegistrationPeriod, set_ServicesVoiceServiceSIPNetwork_RegistrationPeriod, BBFDM_BOTH}, {"Realm", &DMWRITE, DMT_STRING, get_ServicesVoiceServiceSIPNetwork_Realm, set_ServicesVoiceServiceSIPNetwork_Realm, BBFDM_BOTH},