<p>Jenkins2 <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/7893">View Change</a></p><div style="white-space:pre-wrap">Approvals:
Benjamin Keith Ford: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, but someone else must approve
Kevin Harwell: Looks good to me, approved
Jenkins2: Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">res_pjsip.c: Fix ident_to_str() and refactor ident_handler().<br><br>* Extracted sip_endpoint_identifier_type2str() and<br>sip_endpoint_identifier_str2type() to simplify the calling functions.<br><br>* Fixed pjsip_configuration.c:ident_to_str() building the endpoint's<br>identify_by value string.<br><br>Change-Id: Ide876768a8d5d828b12052e2a75008b0563fc509<br>---<br>M res/res_pjsip/pjsip_configuration.c<br>1 file changed, 78 insertions(+), 25 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip/pjsip_configuration.c b/res/res_pjsip/pjsip_configuration.c<br>index 9aab75b..ab3b7a5 100644<br>--- a/res/res_pjsip/pjsip_configuration.c<br>+++ b/res/res_pjsip/pjsip_configuration.c<br>@@ -574,12 +574,63 @@<br> return ast_sip_auths_to_str(&endpoint->outbound_auths, buf);<br> }<br> <br>+/*!<br>+ * \internal<br>+ * \brief Convert identify_by method to string.<br>+ *<br>+ * \param method Method value to convert to string<br>+ *<br>+ * \return String representation.<br>+ */<br>+static const char *sip_endpoint_identifier_type2str(enum ast_sip_endpoint_identifier_type method)<br>+{<br>+ const char *str = "<unknown>";<br>+<br>+ switch (method) {<br>+ case AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME:<br>+ str = "username";<br>+ break;<br>+ case AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME:<br>+ str = "auth_username";<br>+ break;<br>+ case AST_SIP_ENDPOINT_IDENTIFY_BY_IP:<br>+ str = "ip";<br>+ break;<br>+ }<br>+ return str;<br>+}<br>+<br>+/*!<br>+ * \internal<br>+ * \brief Convert string to an endpoint identifier token.<br>+ *<br>+ * \param str String to convert<br>+ *<br>+ * \retval enum ast_sip_endpoint_identifier_type token value on success.<br>+ * \retval -1 on failure.<br>+ */<br>+static int sip_endpoint_identifier_str2type(const char *str)<br>+{<br>+ int method;<br>+<br>+ if (!strcasecmp(str, "username")) {<br>+ method = AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME;<br>+ } else if (!strcasecmp(str, "auth_username")) {<br>+ method = AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME;<br>+ } else if (!strcasecmp(str, "ip")) {<br>+ method = AST_SIP_ENDPOINT_IDENTIFY_BY_IP;<br>+ } else {<br>+ method = -1;<br>+ }<br>+ return method;<br>+}<br>+<br> static int ident_handler(const struct aco_option *opt, struct ast_variable *var, void *obj)<br> {<br> struct ast_sip_endpoint *endpoint = obj;<br> char *idents = ast_strdupa(var->value);<br> char *val;<br>- enum ast_sip_endpoint_identifier_type method;<br>+ int method;<br> <br> /*<br> * If there's already something in the vector when we get here,<br>@@ -595,13 +646,8 @@<br> continue;<br> }<br> <br>- if (!strcasecmp(val, "username")) {<br>- method = AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME;<br>- } else if (!strcasecmp(val, "auth_username")) {<br>- method = AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME;<br>- } else if (!strcasecmp(val, "ip")) {<br>- method = AST_SIP_ENDPOINT_IDENTIFY_BY_IP;<br>- } else {<br>+ method = sip_endpoint_identifier_str2type(val);<br>+ if (method == -1) {<br> ast_log(LOG_ERROR, "Unrecognized identification method %s specified for endpoint %s\n",<br> val, ast_sorcery_object_get_id(endpoint));<br> AST_VECTOR_RESET(&endpoint->ident_method_order, AST_VECTOR_ELEM_CLEANUP_NOOP);<br>@@ -624,34 +670,41 @@<br> {<br> const struct ast_sip_endpoint *endpoint = obj;<br> int methods;<br>- char *method;<br>- int i;<br>- int j = 0;<br>+ int idx;<br>+ int buf_used = 0;<br>+ int buf_size = MAX_OBJECT_FIELD;<br> <br> methods = AST_VECTOR_SIZE(&endpoint->ident_method_order);<br> if (!methods) {<br> return 0;<br> }<br> <br>- if (!(*buf = ast_calloc(MAX_OBJECT_FIELD, sizeof(char)))) {<br>+ *buf = ast_malloc(buf_size);<br>+ if (!*buf) {<br> return -1;<br> }<br> <br>- for (i = 0; i < methods; i++) {<br>- switch (AST_VECTOR_GET(&endpoint->ident_method_order, i)) {<br>- case AST_SIP_ENDPOINT_IDENTIFY_BY_USERNAME :<br>- method = "username";<br>- break;<br>- case AST_SIP_ENDPOINT_IDENTIFY_BY_AUTH_USERNAME :<br>- method = "auth_username";<br>- break;<br>- case AST_SIP_ENDPOINT_IDENTIFY_BY_IP :<br>- method = "ip";<br>- break;<br>- default:<br>+ for (idx = 0; idx < methods; ++idx) {<br>+ enum ast_sip_endpoint_identifier_type method;<br>+ const char *method_str;<br>+<br>+ method = AST_VECTOR_GET(&endpoint->ident_method_order, idx);<br>+ method_str = sip_endpoint_identifier_type2str(method);<br>+<br>+ /* Should never have an "<unknown>" method string */<br>+ ast_assert(strcmp(method_str, "<unknown>"));<br>+ if (!strcmp(method_str, "<unknown>")) {<br> continue;<br> }<br>- j = sprintf(*buf + j, "%s%s", method, i < methods - 1 ? "," : "");<br>+<br>+ buf_used += snprintf(*buf + buf_used, buf_size - buf_used, "%s%s",<br>+ method_str, idx < methods - 1 ? "," : "");<br>+ if (buf_size <= buf_used) {<br>+ /* Need more room than available, truncating. */<br>+ *(*buf + (buf_size - 1)) = '\0';<br>+ ast_log(LOG_WARNING, "Truncated identify_by string: %s\n", *buf);<br>+ break;<br>+ }<br> }<br> <br> return 0;<br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7893">change 7893</a>. To unsubscribe, 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/7893"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: Ide876768a8d5d828b12052e2a75008b0563fc509 </div>
<div style="display:none"> Gerrit-Change-Number: 7893 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Benjamin Keith Ford <bford@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>