]> git.ipfire.org Git - thirdparty/asterisk.git/commitdiff
res_pjsip: Fix codec preference defaults.
authorJoshua C. Colp <jcolp@sangoma.com>
Thu, 6 Aug 2020 18:10:20 +0000 (15:10 -0300)
committerJoshua Colp <jcolp@sangoma.com>
Tue, 11 Aug 2020 10:43:51 +0000 (05:43 -0500)
When reading in a codec preference configuration option
the value would be set on the respective option before
applying any default adjustments, resulting in the
configuration not being as expected.

This was exposed by the REST API push configuration as
it used the configuration returned by Asterisk to then do
a modification. In the case of codec preferences one of
the options had a transcode value of "unspecified" when the
defaults should have ensured it would be "allow" instead.

This also renames the options in other places that were
missed.

Change-Id: I4ad42e74fdf181be2e17bc75901c62591d403964

res/res_pjsip/pjsip_configuration.c

index 20acdcf2c8692efbfa112fa61a71658a1c901223..b23de7ed930e730b653dfb321c4a290cc71a0b7a 100644 (file)
@@ -1170,6 +1170,7 @@ static int codec_prefs_handler(const struct aco_option *opt,
        struct ast_variable *var, void *obj)
 {
        struct ast_sip_endpoint *endpoint = obj;
+       struct ast_stream_codec_negotiation_prefs *option_prefs;
        struct ast_stream_codec_negotiation_prefs prefs;
        struct ast_str *error_message = ast_str_create(128);
        enum ast_stream_codec_negotiation_prefs_prefer_values default_prefer;
@@ -1185,7 +1186,7 @@ static int codec_prefs_handler(const struct aco_option *opt,
        }
        ast_free(error_message);
 
-       if (strcmp(var->name, "incoming_offer_codec_prefs") == 0) {
+       if (strcmp(var->name, "codec_prefs_incoming_offer") == 0) {
                if (prefs.operation == CODEC_NEGOTIATION_OPERATION_UNION) {
                        ast_log(LOG_ERROR, "Endpoint '%s': Codec preference '%s' has invalid value '%s' for option: '%s'",
                                ast_sorcery_object_get_id(endpoint),
@@ -1194,21 +1195,26 @@ static int codec_prefs_handler(const struct aco_option *opt,
                                var->name);
                        return -1;
                }
-               endpoint->media.codec_prefs_incoming_offer = prefs;
+               option_prefs = &endpoint->media.codec_prefs_incoming_offer;
                default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;
                default_operation = CODEC_NEGOTIATION_OPERATION_INTERSECT;
-       } else if (strcmp(var->name, "outgoing_offer_codec_prefs") == 0) {
-               endpoint->media.codec_prefs_outgoing_offer = prefs;
+       } else if (strcmp(var->name, "codec_prefs_outgoing_offer") == 0) {
+               option_prefs = &endpoint->media.codec_prefs_outgoing_offer;
                default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;
                default_operation = CODEC_NEGOTIATION_OPERATION_UNION;
-       } else if (strcmp(var->name, "incoming_answer_codec_prefs") == 0) {
-               endpoint->media.codec_prefs_incoming_answer = prefs;
+       } else if (strcmp(var->name, "codec_prefs_incoming_answer") == 0) {
+               option_prefs = &endpoint->media.codec_prefs_incoming_answer;
                default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;
                default_operation = CODEC_NEGOTIATION_OPERATION_INTERSECT;
-       } else if (strcmp(var->name, "outgoing_answer_codec_prefs") == 0) {
-               endpoint->media.codec_prefs_outgoing_answer = prefs;
+       } else if (strcmp(var->name, "codec_prefs_outgoing_answer") == 0) {
+               option_prefs = &endpoint->media.codec_prefs_outgoing_answer;
                default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;
                default_operation = CODEC_NEGOTIATION_OPERATION_INTERSECT;
+       } else {
+               ast_log(LOG_ERROR, "Endpoint '%s': Unsupported option '%s'\n",
+                       ast_sorcery_object_get_id(endpoint),
+                       var->name);
+               return -1;
        }
 
        if (prefs.prefer == CODEC_NEGOTIATION_PREFER_UNSPECIFIED) {
@@ -1227,6 +1233,11 @@ static int codec_prefs_handler(const struct aco_option *opt,
                prefs.transcode = CODEC_NEGOTIATION_TRANSCODE_ALLOW;
        }
 
+       /* Now that defaults have been applied as needed we apply the full codec
+        * preference configuration to the option.
+        */
+       *option_prefs = prefs;
+
        return 0;
 }
 
@@ -2128,16 +2139,16 @@ int ast_res_pjsip_initialize_configuration(void)
                call_offer_pref_handler, incoming_call_offer_pref_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "outgoing_call_offer_pref", "remote",
                call_offer_pref_handler, outgoing_call_offer_pref_to_str, NULL, 0, 0);
-       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "incoming_offer_codec_prefs",
+       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_incoming_offer",
                "prefer: pending, operation: intersect, keep: all, transcode: allow",
                codec_prefs_handler, incoming_offer_codec_prefs_to_str, NULL, 0, 0);
-       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "outgoing_offer_codec_prefs",
+       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_outgoing_offer",
                "prefer: pending, operation: union, keep: all, transcode: allow",
                codec_prefs_handler, outgoing_offer_codec_prefs_to_str, NULL, 0, 0);
-       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "incoming_answer_codec_prefs",
+       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_incoming_answer",
                "prefer: pending, operation: intersect, keep: all",
                codec_prefs_handler, incoming_answer_codec_prefs_to_str, NULL, 0, 0);
-       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "outgoing_answer_codec_prefs",
+       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_outgoing_answer",
                "prefer: pending, operation: intersect, keep: all",
                codec_prefs_handler, outgoing_answer_codec_prefs_to_str, NULL, 0, 0);
        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "stir_shaken", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, stir_shaken));