<p>Friendly Automation <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10881">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Joshua C. Colp: Looks good to me, but someone else must approve
George Joseph: Looks good to me, approved
Friendly Automation: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">pjsip/config_global: regcontext context not created<br><br>The context specified by 'regcontext' was not being created, so when Asterisk<br>attempted to later dynamically add an extension it would fail. This patch now<br>creates the context if a 'regcontext' is specified.<br><br>ASTERISK-28238<br><br>Change-Id: I0f36cf4ab0a93ff4b1cc5548d617ecfd45e09265<br>---<br>M res/res_pjsip/config_global.c<br>M res/res_pjsip/include/res_pjsip_private.h<br>M res/res_pjsip/pjsip_configuration.c<br>3 files changed, 95 insertions(+), 1 deletion(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/res/res_pjsip/config_global.c b/res/res_pjsip/config_global.c</span><br><span>index 61a21c2..38383c5 100644</span><br><span>--- a/res/res_pjsip/config_global.c</span><br><span>+++ b/res/res_pjsip/config_global.c</span><br><span>@@ -23,6 +23,7 @@</span><br><span> </span><br><span> #include "asterisk/res_pjsip.h"</span><br><span> #include "include/res_pjsip_private.h"</span><br><span style="color: hsl(120, 100%, 40%);">+#include "asterisk/pbx.h"</span><br><span> #include "asterisk/sorcery.h"</span><br><span> #include "asterisk/taskprocessor.h"</span><br><span> #include "asterisk/ast_version.h"</span><br><span>@@ -131,6 +132,46 @@</span><br><span> return cfg;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*</span><br><span style="color: hsl(120, 100%, 40%);">+ * There is ever only one global section, so we can use a single global</span><br><span style="color: hsl(120, 100%, 40%);">+ * value here to track the regcontext through reloads.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+static char *previous_regcontext = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+static int check_regcontext(const struct global_config *cfg)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ char *current = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (previous_regcontext && !strcmp(previous_regcontext, cfg->regcontext)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Nothing changed so nothing to do */</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(cfg->regcontext)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ current = ast_strdup(cfg->regcontext);</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!current) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_sip_persistent_endpoint_add_to_regcontext(cfg->regcontext)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(current);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_strlen_zero(previous_regcontext)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_context_destroy_by_name(previous_regcontext, "PJSIP");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(previous_regcontext);</span><br><span style="color: hsl(120, 100%, 40%);">+ previous_regcontext = NULL;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (current) {</span><br><span style="color: hsl(120, 100%, 40%);">+ previous_regcontext = current;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> static int global_apply(const struct ast_sorcery *sorcery, void *obj)</span><br><span> {</span><br><span> struct global_config *cfg = obj;</span><br><span>@@ -154,6 +195,10 @@</span><br><span> ast_sip_add_global_request_header("User-Agent", cfg->useragent, 1);</span><br><span> ast_sip_add_global_response_header("Server", cfg->useragent, 1);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (check_regcontext(cfg)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_t_global_obj_replace_unref(global_cfg, cfg, "Applying global settings");</span><br><span> return 0;</span><br><span> }</span><br><span>@@ -515,11 +560,17 @@</span><br><span> </span><br><span> ast_sorcery_instance_observer_remove(sorcery, &observer_callbacks_global);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+ if (previous_regcontext) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_context_destroy_by_name(previous_regcontext, "PJSIP");</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_free(previous_regcontext);</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> ao2_t_global_obj_release(global_cfg, "Module is unloading");</span><br><span> </span><br><span> return 0;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_sip_initialize_sorcery_global(void)</span><br><span> {</span><br><span> struct ast_sorcery *sorcery = ast_sip_get_sorcery();</span><br><span>diff --git a/res/res_pjsip/include/res_pjsip_private.h b/res/res_pjsip/include/res_pjsip_private.h</span><br><span>index 2fd6d31..7af5b27 100644</span><br><span>--- a/res/res_pjsip/include/res_pjsip_private.h</span><br><span>+++ b/res/res_pjsip/include/res_pjsip_private.h</span><br><span>@@ -398,4 +398,14 @@</span><br><span> */</span><br><span> void ast_sip_destroy_transport_management(void);</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \internal</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Add online persistent endpoints to the given regcontext</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param regcontext The context to add endpoints to</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \retval -1 on error, 0 on success</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_persistent_endpoint_add_to_regcontext(const char *regcontext);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> #endif /* RES_PJSIP_PRIVATE_H_ */</span><br><span>diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c</span><br><span>index d88024a..e6ac8ec 100644</span><br><span>--- a/res/res_pjsip/pjsip_configuration.c</span><br><span>+++ b/res/res_pjsip/pjsip_configuration.c</span><br><span>@@ -1128,6 +1128,39 @@</span><br><span> ast_endpoint_shutdown(persistent->endpoint);</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+static int add_to_regcontext(void *obj, void *arg, int flags)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ struct sip_persistent_endpoint *persistent = obj;</span><br><span style="color: hsl(120, 100%, 40%);">+ const char *regcontext = arg;</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_endpoint_get_state(persistent->endpoint) == AST_ENDPOINT_ONLINE) {</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_exists_extension(NULL, regcontext, ast_endpoint_get_resource(</span><br><span style="color: hsl(120, 100%, 40%);">+ persistent->endpoint), 1, NULL)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_add_extension(regcontext, 1, ast_endpoint_get_resource(persistent->endpoint), 1, NULL, NULL,</span><br><span style="color: hsl(120, 100%, 40%);">+ "Noop", ast_strdup(ast_endpoint_get_resource(persistent->endpoint)), ast_free_ptr, "PJSIP");</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_sip_persistent_endpoint_add_to_regcontext(const char *regcontext)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (ast_strlen_zero(regcontext)) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Make sure the regcontext exists */</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!ast_context_find_or_create(NULL, NULL, regcontext, "PJSIP")) {</span><br><span style="color: hsl(120, 100%, 40%);">+ ast_log(LOG_ERROR, "Failed to create regcontext '%s'\n", regcontext);</span><br><span style="color: hsl(120, 100%, 40%);">+ return -1;</span><br><span style="color: hsl(120, 100%, 40%);">+ }</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+ /* Add any online endpoints */</span><br><span style="color: hsl(120, 100%, 40%);">+ ao2_callback(persistent_endpoints, OBJ_NODATA, add_to_regcontext, (void *)regcontext);</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_sip_persistent_endpoint_update_state(const char *endpoint_name, enum ast_endpoint_state state)</span><br><span> {</span><br><span> struct sip_persistent_endpoint *persistent;</span><br><span>@@ -1154,7 +1187,7 @@</span><br><span> if (!ast_strlen_zero(regcontext)) {</span><br><span> if (!ast_exists_extension(NULL, regcontext, ast_endpoint_get_resource(persistent->endpoint), 1, NULL)) {</span><br><span> ast_add_extension(regcontext, 1, ast_endpoint_get_resource(persistent->endpoint), 1, NULL, NULL,</span><br><span style="color: hsl(0, 100%, 40%);">- "Noop", ast_strdup(ast_endpoint_get_resource(persistent->endpoint)), ast_free_ptr, "SIP");</span><br><span style="color: hsl(120, 100%, 40%);">+ "Noop", ast_strdup(ast_endpoint_get_resource(persistent->endpoint)), ast_free_ptr, "PJSIP");</span><br><span> }</span><br><span> }</span><br><span> </span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10881">change 10881</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/10881"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I0f36cf4ab0a93ff4b1cc5548d617ecfd45e09265 </div>
<div style="display:none"> Gerrit-Change-Number: 10881 </div>
<div style="display:none"> Gerrit-PatchSet: 3 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua C. Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Sean Bright <sean.bright@gmail.com> </div>