[Asterisk-code-review] endpoint identifiers: Some code cleanup. (asterisk[master])
Richard Mudgett
asteriskteam at digium.com
Fri Feb 2 18:03:06 CST 2018
Richard Mudgett has uploaded this change for review. ( https://gerrit.asterisk.org/8163
Change subject: endpoint identifiers: Some code cleanup.
......................................................................
endpoint identifiers: Some code cleanup.
res_pjsip_endpoint_identifier_user.c:
* Fix copy/paste error in find_endpoint(). We were using a constant
"anonymous" string instead of the passed in endpoint_name when checking
the transport domain for an endpoint match.
* Eliminate RAII_VAR in find_endpoint().
* Remove always true check in find_transport_state_in_use().
* Remove useless CMD_STOP in find_transport_state_in_use().
res_pjsip_endpoint_identifier_anonymous.c:
* Eliminate RAII_VAR in anonymous_identify().
* Remove always true check in find_transport_state_in_use().
* Remove useless CMD_STOP in find_transport_state_in_use().
Change-Id: I86924c31db5bd225ca0c1219c761b668c6f91189
---
M res/res_pjsip_endpoint_identifier_anonymous.c
M res/res_pjsip_endpoint_identifier_user.c
2 files changed, 50 insertions(+), 29 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/63/8163/1
diff --git a/res/res_pjsip_endpoint_identifier_anonymous.c b/res/res_pjsip_endpoint_identifier_anonymous.c
index 918aec5..63fc405 100644
--- a/res/res_pjsip_endpoint_identifier_anonymous.c
+++ b/res/res_pjsip_endpoint_identifier_anonymous.c
@@ -47,10 +47,11 @@
struct ast_sip_transport_state *transport_state = obj;
pjsip_rx_data *rdata = arg;
- if (transport_state && ((transport_state->transport == rdata->tp_info.transport) ||
- (transport_state->factory && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host) &&
- transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port))) {
- return CMP_MATCH | CMP_STOP;
+ if (transport_state->transport == rdata->tp_info.transport
+ || (transport_state->factory
+ && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host)
+ && transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port)) {
+ return CMP_MATCH;
}
return 0;
@@ -62,28 +63,33 @@
{
char domain_name[DOMAIN_NAME_LEN + 1];
struct ast_sip_endpoint *endpoint;
- RAII_VAR(struct ast_sip_domain_alias *, alias, NULL, ao2_cleanup);
- RAII_VAR(struct ao2_container *, transport_states, NULL, ao2_cleanup);
- RAII_VAR(struct ast_sip_transport_state *, transport_state, NULL, ao2_cleanup);
- RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
if (get_endpoint_details(rdata, domain_name, sizeof(domain_name))) {
return NULL;
}
if (!ast_sip_get_disable_multi_domain()) {
+ struct ast_sip_domain_alias *alias;
+ struct ao2_container *transport_states;
+ struct ast_sip_transport_state *transport_state = NULL;
+ struct ast_sip_transport *transport = NULL;
char id[sizeof("anonymous@") + DOMAIN_NAME_LEN];
/* Attempt to find the endpoint given the name and domain provided */
snprintf(id, sizeof(id), "anonymous@%s", domain_name);
- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
+ if (endpoint) {
goto done;
}
/* See if an alias exists for the domain provided */
- if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
+ alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias",
+ domain_name);
+ if (alias) {
snprintf(id, sizeof(id), "anonymous@%s", alias->domain);
- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+ ao2_ref(alias, -1);
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
+ if (endpoint) {
goto done;
}
}
@@ -94,9 +100,13 @@
&& (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))
&& !ast_strlen_zero(transport->domain)) {
snprintf(id, sizeof(id), "anonymous@%s", transport->domain);
- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
- goto done;
- }
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
+ }
+ ao2_cleanup(transport);
+ ao2_cleanup(transport_state);
+ ao2_cleanup(transport_states);
+ if (endpoint) {
+ goto done;
}
}
diff --git a/res/res_pjsip_endpoint_identifier_user.c b/res/res_pjsip_endpoint_identifier_user.c
index e18d2fa..46e82db 100644
--- a/res/res_pjsip_endpoint_identifier_user.c
+++ b/res/res_pjsip_endpoint_identifier_user.c
@@ -65,10 +65,11 @@
struct ast_sip_transport_state *transport_state = obj;
pjsip_rx_data *rdata = arg;
- if (transport_state && ((transport_state->transport == rdata->tp_info.transport) ||
- (transport_state->factory && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host) &&
- transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port))) {
- return CMP_MATCH | CMP_STOP;
+ if (transport_state->transport == rdata->tp_info.transport
+ || (transport_state->factory
+ && !pj_strcmp(&transport_state->factory->addr_name.host, &rdata->tp_info.transport->local_name.host)
+ && transport_state->factory->addr_name.port == rdata->tp_info.transport->local_name.port)) {
+ return CMP_MATCH;
}
return 0;
@@ -81,36 +82,46 @@
char *domain_name)
{
struct ast_sip_endpoint *endpoint;
- RAII_VAR(struct ast_sip_domain_alias *, alias, NULL, ao2_cleanup);
- RAII_VAR(struct ao2_container *, transport_states, NULL, ao2_cleanup);
- RAII_VAR(struct ast_sip_transport_state *, transport_state, NULL, ao2_cleanup);
- RAII_VAR(struct ast_sip_transport *, transport, NULL, ao2_cleanup);
if (!ast_sip_get_disable_multi_domain()) {
+ struct ast_sip_domain_alias *alias;
+ struct ao2_container *transport_states;
+ struct ast_sip_transport_state *transport_state = NULL;
+ struct ast_sip_transport *transport = NULL;
char id[DOMAIN_NAME_LEN + USERNAME_LEN + sizeof("@")];
/* Attempt to find the endpoint given the name and domain provided */
snprintf(id, sizeof(id), "%s@%s", endpoint_name, domain_name);
- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
+ if (endpoint) {
return endpoint;
}
/* See if an alias exists for the domain provided */
- if ((alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias", domain_name))) {
+ alias = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "domain_alias",
+ domain_name);
+ if (alias) {
snprintf(id, sizeof(id), "%s@%s", endpoint_name, alias->domain);
- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
+ ao2_ref(alias, -1);
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
+ if (endpoint) {
return endpoint;
}
}
+
/* See if the transport this came in on has a provided domain */
if ((transport_states = ast_sip_get_transport_states())
&& (transport_state = ao2_callback(transport_states, 0, find_transport_state_in_use, rdata))
&& (transport = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "transport", transport_state->id))
&& !ast_strlen_zero(transport->domain)) {
- snprintf(id, sizeof(id), "anonymous@%s", transport->domain);
- if ((endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id))) {
- return endpoint;
- }
+ snprintf(id, sizeof(id), "%s@%s", endpoint_name, transport->domain);
+ endpoint = ast_sorcery_retrieve_by_id(ast_sip_get_sorcery(), "endpoint", id);
+ }
+ ao2_cleanup(transport);
+ ao2_cleanup(transport_state);
+ ao2_cleanup(transport_states);
+ if (endpoint) {
+ return endpoint;
}
}
--
To view, visit https://gerrit.asterisk.org/8163
To unsubscribe, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I86924c31db5bd225ca0c1219c761b668c6f91189
Gerrit-Change-Number: 8163
Gerrit-PatchSet: 1
Gerrit-Owner: Richard Mudgett <rmudgett at digium.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20180202/f9ad6afe/attachment-0001.html>
More information about the asterisk-code-review
mailing list