<p>Joshua Colp <strong>submitted</strong> this change.</p><p><a href="https://gerrit.asterisk.org/c/asterisk/+/14752">View Change</a></p><div style="white-space:pre-wrap">Approvals:
  Joshua Colp: Looks good to me, approved; Approved for Submit
  Sean Bright: Looks good to me, but someone else must approve
  Benjamin Keith Ford: Looks good to me, but someone else must approve

</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip: Fix codec preference defaults.<br><br>When reading in a codec preference configuration option<br>the value would be set on the respective option before<br>applying any default adjustments, resulting in the<br>configuration not being as expected.<br><br>This was exposed by the REST API push configuration as<br>it used the configuration returned by Asterisk to then do<br>a modification. In the case of codec preferences one of<br>the options had a transcode value of "unspecified" when the<br>defaults should have ensured it would be "allow" instead.<br><br>This also renames the options in other places that were<br>missed.<br><br>Change-Id: I4ad42e74fdf181be2e17bc75901c62591d403964<br>---<br>M res/res_pjsip/pjsip_configuration.c<br>1 file changed, 23 insertions(+), 12 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c</span><br><span>index 20acdcf..b23de7e 100644</span><br><span>--- a/res/res_pjsip/pjsip_configuration.c</span><br><span>+++ b/res/res_pjsip/pjsip_configuration.c</span><br><span>@@ -1170,6 +1170,7 @@</span><br><span>        struct ast_variable *var, void *obj)</span><br><span> {</span><br><span>    struct ast_sip_endpoint *endpoint = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+      struct ast_stream_codec_negotiation_prefs *option_prefs;</span><br><span>     struct ast_stream_codec_negotiation_prefs prefs;</span><br><span>     struct ast_str *error_message = ast_str_create(128);</span><br><span>         enum ast_stream_codec_negotiation_prefs_prefer_values default_prefer;</span><br><span>@@ -1185,7 +1186,7 @@</span><br><span>        }</span><br><span>    ast_free(error_message);</span><br><span> </span><br><span style="color: hsl(0, 100%, 40%);">-    if (strcmp(var->name, "incoming_offer_codec_prefs") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+      if (strcmp(var->name, "codec_prefs_incoming_offer") == 0) {</span><br><span>             if (prefs.operation == CODEC_NEGOTIATION_OPERATION_UNION) {</span><br><span>                  ast_log(LOG_ERROR, "Endpoint '%s': Codec preference '%s' has invalid value '%s' for option: '%s'",</span><br><span>                                 ast_sorcery_object_get_id(endpoint),</span><br><span>@@ -1194,21 +1195,26 @@</span><br><span>                               var->name);</span><br><span>                       return -1;</span><br><span>           }</span><br><span style="color: hsl(0, 100%, 40%);">-               endpoint->media.codec_prefs_incoming_offer = prefs;</span><br><span style="color: hsl(120, 100%, 40%);">+                option_prefs = &endpoint->media.codec_prefs_incoming_offer;</span><br><span>           default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;</span><br><span>           default_operation = CODEC_NEGOTIATION_OPERATION_INTERSECT;</span><br><span style="color: hsl(0, 100%, 40%);">-      } else if (strcmp(var->name, "outgoing_offer_codec_prefs") == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-         endpoint->media.codec_prefs_outgoing_offer = prefs;</span><br><span style="color: hsl(120, 100%, 40%);">+        } else if (strcmp(var->name, "codec_prefs_outgoing_offer") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+               option_prefs = &endpoint->media.codec_prefs_outgoing_offer;</span><br><span>           default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;</span><br><span>           default_operation = CODEC_NEGOTIATION_OPERATION_UNION;</span><br><span style="color: hsl(0, 100%, 40%);">-  } else if (strcmp(var->name, "incoming_answer_codec_prefs") == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                endpoint->media.codec_prefs_incoming_answer = prefs;</span><br><span style="color: hsl(120, 100%, 40%);">+       } else if (strcmp(var->name, "codec_prefs_incoming_answer") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              option_prefs = &endpoint->media.codec_prefs_incoming_answer;</span><br><span>          default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;</span><br><span>           default_operation = CODEC_NEGOTIATION_OPERATION_INTERSECT;</span><br><span style="color: hsl(0, 100%, 40%);">-      } else if (strcmp(var->name, "outgoing_answer_codec_prefs") == 0) {</span><br><span style="color: hsl(0, 100%, 40%);">-                endpoint->media.codec_prefs_outgoing_answer = prefs;</span><br><span style="color: hsl(120, 100%, 40%);">+       } else if (strcmp(var->name, "codec_prefs_outgoing_answer") == 0) {</span><br><span style="color: hsl(120, 100%, 40%);">+              option_prefs = &endpoint->media.codec_prefs_outgoing_answer;</span><br><span>          default_prefer = CODEC_NEGOTIATION_PREFER_PENDING;</span><br><span>           default_operation = CODEC_NEGOTIATION_OPERATION_INTERSECT;</span><br><span style="color: hsl(120, 100%, 40%);">+    } else {</span><br><span style="color: hsl(120, 100%, 40%);">+              ast_log(LOG_ERROR, "Endpoint '%s': Unsupported option '%s'\n",</span><br><span style="color: hsl(120, 100%, 40%);">+                      ast_sorcery_object_get_id(endpoint),</span><br><span style="color: hsl(120, 100%, 40%);">+                  var->name);</span><br><span style="color: hsl(120, 100%, 40%);">+                return -1;</span><br><span>   }</span><br><span> </span><br><span>        if (prefs.prefer == CODEC_NEGOTIATION_PREFER_UNSPECIFIED) {</span><br><span>@@ -1227,6 +1233,11 @@</span><br><span>                 prefs.transcode = CODEC_NEGOTIATION_TRANSCODE_ALLOW;</span><br><span>         }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ /* Now that defaults have been applied as needed we apply the full codec</span><br><span style="color: hsl(120, 100%, 40%);">+       * preference configuration to the option.</span><br><span style="color: hsl(120, 100%, 40%);">+     */</span><br><span style="color: hsl(120, 100%, 40%);">+   *option_prefs = prefs;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span>     return 0;</span><br><span> }</span><br><span> </span><br><span>@@ -2128,16 +2139,16 @@</span><br><span>                 call_offer_pref_handler, incoming_call_offer_pref_to_str, NULL, 0, 0);</span><br><span>       ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "outgoing_call_offer_pref", "remote",</span><br><span>                call_offer_pref_handler, outgoing_call_offer_pref_to_str, NULL, 0, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-  ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "incoming_offer_codec_prefs",</span><br><span style="color: hsl(120, 100%, 40%);">+   ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_incoming_offer",</span><br><span>          "prefer: pending, operation: intersect, keep: all, transcode: allow",</span><br><span>              codec_prefs_handler, incoming_offer_codec_prefs_to_str, NULL, 0, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-    ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "outgoing_offer_codec_prefs",</span><br><span style="color: hsl(120, 100%, 40%);">+   ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_outgoing_offer",</span><br><span>          "prefer: pending, operation: union, keep: all, transcode: allow",</span><br><span>          codec_prefs_handler, outgoing_offer_codec_prefs_to_str, NULL, 0, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-    ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "incoming_answer_codec_prefs",</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_incoming_answer",</span><br><span>                 "prefer: pending, operation: intersect, keep: all",</span><br><span>                codec_prefs_handler, incoming_answer_codec_prefs_to_str, NULL, 0, 0);</span><br><span style="color: hsl(0, 100%, 40%);">-   ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "outgoing_answer_codec_prefs",</span><br><span style="color: hsl(120, 100%, 40%);">+  ast_sorcery_object_field_register_custom(sip_sorcery, "endpoint", "codec_prefs_outgoing_answer",</span><br><span>                 "prefer: pending, operation: intersect, keep: all",</span><br><span>                codec_prefs_handler, outgoing_answer_codec_prefs_to_str, NULL, 0, 0);</span><br><span>        ast_sorcery_object_field_register(sip_sorcery, "endpoint", "stir_shaken", "no", OPT_BOOL_T, 1, FLDSET(struct ast_sip_endpoint, stir_shaken));</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/14752">change 14752</a>. To unsubscribe, or for help writing mail filters, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/c/asterisk/+/14752"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 18 </div>
<div style="display:none"> Gerrit-Change-Id: I4ad42e74fdf181be2e17bc75901c62591d403964 </div>
<div style="display:none"> Gerrit-Change-Number: 14752 </div>
<div style="display:none"> Gerrit-PatchSet: 2 </div>
<div style="display:none"> Gerrit-Owner: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: merged </div>