<p>Richard Mudgett has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/8163">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">endpoint identifiers: Some code cleanup.<br><br>res_pjsip_endpoint_identifier_user.c:<br>* Fix copy/paste error in find_endpoint(). We were using a constant<br>"anonymous" string instead of the passed in endpoint_name when checking<br>the transport domain for an endpoint match.<br>* Eliminate RAII_VAR in find_endpoint().<br>* Remove always true check in find_transport_state_in_use().<br>* Remove useless CMD_STOP in find_transport_state_in_use().<br><br>res_pjsip_endpoint_identifier_anonymous.c:<br>* Eliminate RAII_VAR in anonymous_identify().<br>* Remove always true check in find_transport_state_in_use().<br>* Remove useless CMD_STOP in find_transport_state_in_use().<br><br>Change-Id: I86924c31db5bd225ca0c1219c761b668c6f91189<br>---<br>M res/res_pjsip_endpoint_identifier_anonymous.c<br>M res/res_pjsip_endpoint_identifier_user.c<br>2 files changed, 50 insertions(+), 29 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/63/8163/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/res/res_pjsip_endpoint_identifier_anonymous.c b/res/res_pjsip_endpoint_identifier_anonymous.c<br>index 918aec5..63fc405 100644<br>--- a/res/res_pjsip_endpoint_identifier_anonymous.c<br>+++ b/res/res_pjsip_endpoint_identifier_anonymous.c<br>@@ -47,10 +47,11 @@<br> struct ast_sip_transport_state *transport_state = obj;<br> pjsip_rx_data *rdata = arg;<br> <br>- if (transport_state && ((transport_state->transport == rdata->tp_info.transport) ||<br>- (transport_state->factory && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host) &&<br>- transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port))) {<br>- return CMP_MATCH | CMP_STOP;<br>+ if (transport_state->transport == rdata->tp_info.transport<br>+ || (transport_state->factory<br>+ && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host)<br>+ && transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port)) {<br>+ return CMP_MATCH;<br> }<br> <br> return 0;<br>@@ -62,28 +63,33 @@<br> {<br> char domain_name[DOMAIN_NAME_LEN + 1];<br> struct ast_sip_endpoint *endpoint;<br>- RAII_VAR(struct ast_sip_domain_alias *, alias, NULL, ao2_cleanup);<br>- RAII_VAR(struct ao2_container *, transport_states, NULL, ao2_cleanup);<br>- RAII_VAR(struct ast_sip_transport_state *, transport_state, NULL, ao2_cleanup);<br>- RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);<br> <br> if (get_endpoint_details(rdata, domain_name, sizeof(domain_name))) {<br> return NULL;<br> }<br> <br> if (!ast_sip_get_disable_multi_domain()) {<br>+ struct ast_sip_domain_alias *alias;<br>+ struct ao2_container *transport_states;<br>+ struct ast_sip_transport_state *transport_state = NULL;<br>+ struct ast_sip_transport *transport = NULL;<br> char id[sizeof("anonymous@") + DOMAIN_NAME_LEN];<br> <br> /* Attempt to find the endpoint given the name and domain provided */<br> snprintf(id, sizeof(id), "anonymous@%s", domain_name);<br>- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {<br>+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);<br>+ if (endpoint) {<br> goto done;<br> }<br> <br> /* See if an alias exists for the domain provided */<br>- if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {<br>+ alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias",<br>+ domain_name);<br>+ if (alias) {<br> snprintf(id, sizeof(id), "anonymous@%s", alias->domain);<br>- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {<br>+ ao2_ref(alias, -1);<br>+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);<br>+ if (endpoint) {<br> goto done;<br> }<br> }<br>@@ -94,9 +100,13 @@<br> && (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))<br> && !ast_strlen_zero(transport->domain)) {<br> snprintf(id, sizeof(id), "anonymous@%s", transport->domain);<br>- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {<br>- goto done;<br>- }<br>+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);<br>+ }<br>+ ao2_cleanup(transport);<br>+ ao2_cleanup(transport_state);<br>+ ao2_cleanup(transport_states);<br>+ if (endpoint) {<br>+ goto done;<br> }<br> }<br> <br>diff --git a/res/res_pjsip_endpoint_identifier_user.c b/res/res_pjsip_endpoint_identifier_user.c<br>index e18d2fa..46e82db 100644<br>--- a/res/res_pjsip_endpoint_identifier_user.c<br>+++ b/res/res_pjsip_endpoint_identifier_user.c<br>@@ -65,10 +65,11 @@<br> struct ast_sip_transport_state *transport_state = obj;<br> pjsip_rx_data *rdata = arg;<br> <br>- if (transport_state && ((transport_state->transport == rdata->tp_info.transport) ||<br>- (transport_state->factory && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host) &&<br>- transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port))) {<br>- return CMP_MATCH | CMP_STOP;<br>+ if (transport_state->transport == rdata->tp_info.transport<br>+ || (transport_state->factory<br>+ && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host)<br>+ && transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port)) {<br>+ return CMP_MATCH;<br> }<br> <br> return 0;<br>@@ -81,36 +82,46 @@<br> char *domain_name)<br> {<br> struct ast_sip_endpoint *endpoint;<br>- RAII_VAR(struct ast_sip_domain_alias *, alias, NULL, ao2_cleanup);<br>- RAII_VAR(struct ao2_container *, transport_states, NULL, ao2_cleanup);<br>- RAII_VAR(struct ast_sip_transport_state *, transport_state, NULL, ao2_cleanup);<br>- RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);<br> <br> if (!ast_sip_get_disable_multi_domain()) {<br>+ struct ast_sip_domain_alias *alias;<br>+ struct ao2_container *transport_states;<br>+ struct ast_sip_transport_state *transport_state = NULL;<br>+ struct ast_sip_transport *transport = NULL;<br> char id[DOMAIN_NAME_LEN + USERNAME_LEN + sizeof("@")];<br> <br> /* Attempt to find the endpoint given the name and domain provided */<br> snprintf(id, sizeof(id), "%s@%s", endpoint_name, domain_name);<br>- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {<br>+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);<br>+ if (endpoint) {<br> return endpoint;<br> }<br> <br> /* See if an alias exists for the domain provided */<br>- if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {<br>+ alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias",<br>+ domain_name);<br>+ if (alias) {<br> snprintf(id, sizeof(id), "%s@%s", endpoint_name, alias->domain);<br>- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {<br>+ ao2_ref(alias, -1);<br>+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);<br>+ if (endpoint) {<br> return endpoint;<br> }<br> }<br>+<br> /* See if the transport this came in on has a provided domain */<br> if ((transport_states = ast_sip_get_transport_states())<br> && (transport_state = ao2_callback(transport_states, 0, find_transport_state_in_use, rdata))<br> && (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))<br> && !ast_strlen_zero(transport->domain)) {<br>- snprintf(id, sizeof(id), "anonymous@%s", transport->domain);<br>- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {<br>- return endpoint;<br>- }<br>+ snprintf(id, sizeof(id), "%s@%s", endpoint_name, transport->domain);<br>+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);<br>+ }<br>+ ao2_cleanup(transport);<br>+ ao2_cleanup(transport_state);<br>+ ao2_cleanup(transport_states);<br>+ if (endpoint) {<br>+ return endpoint;<br> }<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8163">change 8163</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/8163"/><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: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I86924c31db5bd225ca0c1219c761b668c6f91189 </div>
<div style="display:none"> Gerrit-Change-Number: 8163 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Richard Mudgett <rmudgett@digium.com> </div>