some code simplifications using S_OR() to remove some if blocks

and duplicate code.



git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@31868 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Luigi Rizzo 2006-06-03 23:17:54 +00:00
parent ec46b5a4ce
commit d18e363523
1 changed files with 16 additions and 30 deletions

View File

@ -6026,10 +6026,7 @@ static int transmit_register(struct sip_registry *r, int sipmethod, const char *
/* Fromdomain is what we are registering to, regardless of actual /* Fromdomain is what we are registering to, regardless of actual
host name from SRV */ host name from SRV */
if (!ast_strlen_zero(p->fromdomain)) snprintf(addr, sizeof(addr), "sip:%s", S_OR(p->fromdomain, r->hostname));
snprintf(addr, sizeof(addr), "sip:%s", p->fromdomain);
else
snprintf(addr, sizeof(addr), "sip:%s", r->hostname);
ast_string_field_set(p, uri, addr); ast_string_field_set(p, uri, addr);
p->branch ^= ast_random(); p->branch ^= ast_random();
@ -7141,11 +7138,11 @@ static int get_destination(struct sip_pvt *p, struct sip_request *oreq)
} }
from += 4; from += 4;
from = strsep(&from, ";"); from = strsep(&from, ";");
if ((a = strchr(from, '@'))) { if ((a = strchr(from, '@')))
*a = '\0'; *a++ = '\0';
ast_string_field_set(p, fromdomain, a + 1); else
} else a = from; /* just a domain */
ast_string_field_set(p, fromdomain, from); ast_string_field_set(p, fromdomain, a);
} }
/* Skip any options and find the domain */ /* Skip any options and find the domain */
@ -7371,12 +7368,10 @@ static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoi
if ((ptr = strchr(refer_to, '@'))) { /* Separate domain */ if ((ptr = strchr(refer_to, '@'))) { /* Separate domain */
char *urioption; char *urioption;
*ptr = '\0';
ptr++; *ptr++ = '\0';
if ((urioption = strchr(ptr, ';'))) { if ((urioption = strchr(ptr, ';')))
*urioption = '\0'; *urioption++ = '\0';
urioption++;
}
/* Save the domain for the dial plan */ /* Save the domain for the dial plan */
strncpy(referdata->refer_to_domain, ptr, sizeof(referdata->refer_to_domain)); strncpy(referdata->refer_to_domain, ptr, sizeof(referdata->refer_to_domain));
if (urioption) if (urioption)
@ -7397,12 +7392,8 @@ static int get_refer_info(struct sip_pvt *transferer, struct sip_request *outgoi
/* By default, use the context in the channel sending the REFER */ /* By default, use the context in the channel sending the REFER */
if (ast_strlen_zero(transfer_context)) { if (ast_strlen_zero(transfer_context)) {
if (!ast_strlen_zero(transferer->owner->macrocontext)) transfer_context = S_OR(transferer->owner->macrocontext,
transfer_context=transferer->owner->macrocontext; S_OR(transferer->context, default_context));
else if (ast_strlen_zero(transferer->context))
transfer_context = default_context;
else
transfer_context = transferer->context;
} }
strncpy(referdata->refer_to_context, transfer_context, sizeof(referdata->refer_to_context)); strncpy(referdata->refer_to_context, transfer_context, sizeof(referdata->refer_to_context));
@ -7449,8 +7440,7 @@ static int get_also_info(struct sip_pvt *p, struct sip_request *oreq)
} }
c += 4; c += 4;
if ((a = strchr(c, '@'))) { /* Separate Domain */ if ((a = strchr(c, '@'))) { /* Separate Domain */
*a = '\0'; *a++ = '\0';
a++;
ast_copy_string(referdata->refer_to_domain, a, sizeof(referdata->refer_to_domain)); ast_copy_string(referdata->refer_to_domain, a, sizeof(referdata->refer_to_domain));
} }
@ -7464,13 +7454,9 @@ static int get_also_info(struct sip_pvt *p, struct sip_request *oreq)
transfer_context = pbx_builtin_getvar_helper(p->owner, "TRANSFER_CONTEXT"); transfer_context = pbx_builtin_getvar_helper(p->owner, "TRANSFER_CONTEXT");
/* By default, use the context in the channel sending the REFER */ /* By default, use the context in the channel sending the REFER */
if (!transfer_context || ast_strlen_zero(transfer_context)) { if (ast_strlen_zero(transfer_context)) {
if (!ast_strlen_zero(p->owner->macrocontext)) transfer_context = S_OR(p->owner->macrocontext,
transfer_context = p->owner->macrocontext; S_OR(p->context, default_context));
else if (ast_strlen_zero(p->context))
transfer_context = default_context;
else
transfer_context = p->context;
} }
if (ast_exists_extension(NULL, transfer_context, c, 1, NULL)) { if (ast_exists_extension(NULL, transfer_context, c, 1, NULL)) {
/* This is a blind transfer */ /* This is a blind transfer */