]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
PJSIP: Handle defaults properly
authorKinsey Moore <kmoore@digium.com>
Wed, 1 Oct 2014 12:24:12 +0000 (12:24 +0000)
committerKinsey Moore <kmoore@digium.com>
Wed, 1 Oct 2014 12:24:12 +0000 (12:24 +0000)
This updates the code behind PJSIP configuration options with custom
handlers to deal with the assigned default values properly where it
makes sense and adjusting the default value where it doesn't. Before
applying this patch, there were several cases where the default value
for an option would prevent that config section from loading properly.

Reported by: Thomas Thompson
Review: https://reviewboard.asterisk.org/r/4019/

git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/12@424263 65c4cc65-6c06-0410-ace0-fbb531ad65f3

configs/pjsip.conf.sample
res/res_pjsip/config_transport.c
res/res_pjsip/location.c
res/res_pjsip/pjsip_configuration.c
res/res_pjsip_endpoint_identifier_ip.c

index 58774dc7c02c4020082a30e90ca83f2e94349a3e..2a09c77d99d02cbbfc40697ab65a1d96e2a031ed 100644 (file)
 ;aors=  ; AoR s to be used with the endpoint (default: "")
 ;auth=  ; Authentication Object s associated with the endpoint (default: "")
 ;callerid=      ; CallerID information for the endpoint (default: "")
-;callerid_privacy=      ; Default privacy level (default: "")
+;callerid_privacy=allowed      ; Default privacy level (default: "allowed")
 ;callerid_tag=  ; Internal id_tag for the endpoint (default: "")
 ;context=default        ; Dialplan context for inbound sessions (default:
                         ; "default")
                 ; this endpoint (default: "")
 ;from_domain=   ; Domain to user in From header for requests to this endpoint
                 ; (default: "")
-;dtls_verify=   ; Verify that the provided peer certificate is valid (default:
-                ; "")
-;dtls_rekey=    ; Interval at which to renegotiate the TLS session and rekey
-                ; the SRTP session (default: "")
+;dtls_verify=no ; Verify that the provided peer certificate is valid (default:
+                ; "no")
+;dtls_rekey=0   ; Interval at which to renegotiate the TLS session and rekey
+                ; the SRTP session (default: "0")
 ;dtls_cert_file=        ; Path to certificate file to present to peer (default:
                         ; "")
 ;dtls_private_key=      ; Path to private key for certificate file (default:
index 0a56b926345107be2c9ef14b691ba85f6d34e27d..9996ddd08f70ea333d10f6cf67ab958d6684409d 100644 (file)
@@ -349,7 +349,7 @@ static int transport_tls_method_handler(const struct aco_option *opt, struct ast
 {
        struct ast_sip_transport *transport = obj;
 
-       if (!strcasecmp(var->value, "default")) {
+       if (ast_strlen_zero(var->value) || !strcasecmp(var->value, "default")) {
                transport->tls.method = PJSIP_SSL_DEFAULT_METHOD;
        } else if (!strcasecmp(var->value, "unspecified")) {
                transport->tls.method = PJSIP_SSL_UNSPECIFIED_METHOD;
@@ -416,6 +416,10 @@ static int transport_tls_cipher_handler(const struct aco_option *opt, struct ast
        struct ast_sip_transport *transport = obj;
        pj_ssl_cipher cipher;
 
+       if (ast_strlen_zero(var->value)) {
+               return 0;
+       }
+
        if (transport->tls.ciphers_num == (SIP_TLS_MAX_CIPHERS - 1)) {
                return -1;
        }
@@ -468,6 +472,12 @@ static int transport_localnet_handler(const struct aco_option *opt, struct ast_v
        struct ast_sip_transport *transport = obj;
        int error = 0;
 
+       if (ast_strlen_zero(var->value)) {
+               ast_free_ha(transport->localnet);
+               transport->localnet = NULL;
+               return 0;
+       }
+
        if (!(transport->localnet = ast_append_ha("d", var->value, transport->localnet, &error))) {
                return -1;
        }
index d6015c7582ae346092e48b6b95f56f557acffa00..d036ffa15c0696b6e4eb7e00dced817d832cf68f 100644 (file)
@@ -290,9 +290,14 @@ static int permanent_uri_handler(const struct aco_option *opt, struct ast_variab
 {
        struct ast_sip_aor *aor = obj;
        const char *aor_id = ast_sorcery_object_get_id(aor);
-       char *contacts = ast_strdupa(var->value);
+       char *contacts;
        char *contact_uri;
 
+       if (ast_strlen_zero(var->value)) {
+               return 0;
+       }
+
+       contacts = ast_strdupa(var->value);
        while ((contact_uri = strsep(&contacts, ","))) {
                struct ast_sip_contact *contact;
                char contact_id[strlen(aor_id) + strlen(contact_uri) + 2 + 1];
index c7b23e9d48458744e2c0656109b59c6259a9a864..fc383f291be2ebf89436876d063d029e512494a5 100644 (file)
@@ -564,13 +564,9 @@ static int group_handler(const struct aco_option *opt,
        struct ast_sip_endpoint *endpoint = obj;
 
        if (!strncmp(var->name, "call_group", 10)) {
-               if (!(endpoint->pickup.callgroup = ast_get_group(var->value))) {
-                       return -1;
-               }
+               endpoint->pickup.callgroup = ast_get_group(var->value);
        } else if (!strncmp(var->name, "pickup_group", 12)) {
-               if (!(endpoint->pickup.pickupgroup = ast_get_group(var->value))) {
-                       return -1;
-               }
+               endpoint->pickup.pickupgroup = ast_get_group(var->value);
        } else {
                return -1;
        }
@@ -608,12 +604,18 @@ static int named_groups_handler(const struct aco_option *opt,
        struct ast_sip_endpoint *endpoint = obj;
 
        if (!strncmp(var->name, "named_call_group", 16)) {
-               if (!(endpoint->pickup.named_callgroups =
+               if (ast_strlen_zero(var->value)) {
+                       endpoint->pickup.named_callgroups =
+                               ast_unref_namedgroups(endpoint->pickup.named_callgroups);
+               } else if (!(endpoint->pickup.named_callgroups =
                      ast_get_namedgroups(var->value))) {
                        return -1;
                }
        } else if (!strncmp(var->name, "named_pickup_group", 18)) {
-               if (!(endpoint->pickup.named_pickupgroups =
+               if (ast_strlen_zero(var->value)) {
+                       endpoint->pickup.named_pickupgroups =
+                               ast_unref_namedgroups(endpoint->pickup.named_pickupgroups);
+               } else if (!(endpoint->pickup.named_pickupgroups =
                      ast_get_namedgroups(var->value))) {
                        return -1;
                }
@@ -813,7 +815,15 @@ static int set_var_handler(const struct aco_option *opt,
 {
        struct ast_sip_endpoint *endpoint = obj;
        struct ast_variable *new_var;
-       char *name = ast_strdupa(var->value), *val = strchr(name, '=');
+       char *name;
+       char *val;
+
+       if (ast_strlen_zero(var->value)) {
+               return 0;
+       }
+
+       name = ast_strdupa(var->value);
+       val = strchr(name, '=');
 
        if (!val) {
                return -1;
@@ -1682,7 +1692,7 @@ int ast_res_pjsip_initialize_configuration(const struct ast_module_info *ast_mod
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "direct_media_glare_mitigation", "none", direct_media_glare_mitigation_handler, direct_media_glare_mitigation_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "disable_direct_media_on_nat", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, media.direct_media.disable_on_nat));
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "callerid", "", caller_id_handler, caller_id_to_str, NULL, 0, 0);
-       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "callerid_privacy", "", caller_id_privacy_handler, caller_id_privacy_to_str, NULL, 0, 0);
+       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "callerid_privacy", "allowed", caller_id_privacy_handler, caller_id_privacy_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "callerid_tag", "", caller_id_tag_handler, caller_id_tag_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "trust_id_inbound", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.trust_inbound));
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "trust_id_outbound", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, id.trust_outbound));
@@ -1725,8 +1735,8 @@ int ast_res_pjsip_initialize_configuration(const struct ast_module_info *ast_mod
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "from_domain", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, fromdomain));
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "mwi_from_user", "", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, subscription.mwi.fromuser));
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "rtp_engine", "asterisk", OPT_STRINGFIELD_T, 0, STRFLDSET(struct ast_sip_endpoint, media.rtp.engine));
-       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_verify", "", dtls_handler, dtlsverify_to_str, NULL, 0, 0);
-       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_rekey", "", dtls_handler, dtlsrekey_to_str, NULL, 0, 0);
+       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_verify", "no", dtls_handler, dtlsverify_to_str, NULL, 0, 0);
+       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_rekey", "0", dtls_handler, dtlsrekey_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_cert_file", "", dtls_handler, dtlscertfile_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_private_key", "", dtls_handler, dtlsprivatekey_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "dtls_cipher", "", dtls_handler, dtlscipher_to_str, NULL, 0, 0);
index 1633f6a7da3575e58facf231a4c2c17f027940c5..757aca2e55ec22821ba7b618ea29cb35fa641c97 100644 (file)
@@ -160,6 +160,10 @@ static int ip_identify_match_handler(const struct aco_option *opt, struct ast_va
        char *input_string = ast_strdupa(var->value);
        char *current_string;
 
+       if (ast_strlen_zero(var->value)) {
+               return 0;
+       }
+
        while ((current_string = strsep(&input_string, ","))) {
                struct ast_sockaddr *addrs;
                int num_addrs = 0, error = 0, i;