From e3da76a352e90aacd52baf61d6450544debdf4cd Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Wed, 1 Oct 2014 12:27:05 +0000 Subject: [PATCH] PJSIP: Handle defaults properly 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/ ........ Merged revisions 424263 from http://svn.asterisk.org/svn/asterisk/branches/12 git-svn-id: https://origsvn.digium.com/svn/asterisk/branches/13@424266 65c4cc65-6c06-0410-ace0-fbb531ad65f3 --- configs/samples/pjsip.conf.sample | 10 ++++---- res/res_pjsip/config_transport.c | 12 ++++++++- res/res_pjsip/location.c | 7 +++++- res/res_pjsip/pjsip_configuration.c | 34 +++++++++++++++++--------- res/res_pjsip_endpoint_identifier_ip.c | 4 +++ 5 files changed, 48 insertions(+), 19 deletions(-) diff --git a/configs/samples/pjsip.conf.sample b/configs/samples/pjsip.conf.sample index 0377b71d41..7edff2d396 100644 --- a/configs/samples/pjsip.conf.sample +++ b/configs/samples/pjsip.conf.sample @@ -490,7 +490,7 @@ ;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") @@ -596,10 +596,10 @@ ; 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: diff --git a/res/res_pjsip/config_transport.c b/res/res_pjsip/config_transport.c index 0a56b92634..9996ddd08f 100644 --- a/res/res_pjsip/config_transport.c +++ b/res/res_pjsip/config_transport.c @@ -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; } diff --git a/res/res_pjsip/location.c b/res/res_pjsip/location.c index d6015c7582..d036ffa15c 100644 --- a/res/res_pjsip/location.c +++ b/res/res_pjsip/location.c @@ -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]; diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c index 9166d3f337..a5fec86431 100644 --- a/res/res_pjsip/pjsip_configuration.c +++ b/res/res_pjsip/pjsip_configuration.c @@ -559,13 +559,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; } @@ -603,12 +599,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; } @@ -808,7 +810,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; @@ -1677,7 +1687,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)); @@ -1720,8 +1730,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); diff --git a/res/res_pjsip_endpoint_identifier_ip.c b/res/res_pjsip_endpoint_identifier_ip.c index 607e454029..43f1318a8b 100644 --- a/res/res_pjsip_endpoint_identifier_ip.c +++ b/res/res_pjsip_endpoint_identifier_ip.c @@ -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;