[asterisk-commits] trunk r17943 - /trunk/channels/chan_sip.c
asterisk-commits at lists.digium.com
asterisk-commits at lists.digium.com
Thu Apr 6 10:09:02 MST 2006
Author: rizzo
Date: Thu Apr 6 12:09:00 2006
New Revision: 17943
URL: http://svn.digium.com/view/asterisk?rev=17943&view=rev
Log:
normalize some for() loops.
Modified:
trunk/channels/chan_sip.c
Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=17943&r1=17942&r2=17943&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Thu Apr 6 12:09:00 2006
@@ -1047,7 +1047,7 @@
if (ast_strlen_zero(msg))
return 0;
- for (i = 1; (i < (sizeof(sip_methods) / sizeof(sip_methods[0]))) && !res; i++) {
+ for (i = 1; i < (sizeof(sip_methods) / sizeof(sip_methods[0])) && !res; i++) {
if (!strcasecmp(sip_methods[i].text, msg))
res = sip_methods[i].id;
}
@@ -1057,10 +1057,8 @@
/*! \brief Parse supported header in incoming packet */
static unsigned int parse_sip_options(struct sip_pvt *pvt, char *supported)
{
- char *next = NULL;
- char *sep = NULL;
+ char *next, *sep;
char *temp = ast_strdupa(supported);
- int i;
unsigned int profile = 0;
if (ast_strlen_zero(supported) )
@@ -1069,29 +1067,24 @@
if (option_debug > 2 && sipdebug)
ast_log(LOG_DEBUG, "Begin: parsing SIP \"Supported: %s\"\n", supported);
- next = temp;
- while (next) {
- char res=0;
- if ( (sep = strchr(next, ',')) != NULL) {
- *sep = '\0';
- sep++;
- }
- while (*next == ' ') /* Skip spaces */
- next++;
+ for (next = temp; next; next = sep) {
+ int i, found = 0;
+ if ( (sep = strchr(next, ',')) != NULL)
+ *sep++ = '\0';
+ next = ast_skip_blanks(next);
if (option_debug > 2 && sipdebug)
ast_log(LOG_DEBUG, "Found SIP option: -%s-\n", next);
- for (i=0; (i < (sizeof(sip_options) / sizeof(sip_options[0]))) && !res; i++) {
+ for (i=0; i < (sizeof(sip_options) / sizeof(sip_options[0])); i++) {
if (!strcasecmp(next, sip_options[i].text)) {
profile |= sip_options[i].id;
- res = 1;
+ found = 1;
if (option_debug > 2 && sipdebug)
ast_log(LOG_DEBUG, "Matched SIP option: %s\n", next);
+ break;
}
}
- if (!res)
- if (option_debug > 2 && sipdebug)
- ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next);
- next = sep;
+ if (!found && option_debug > 2 && sipdebug)
+ ast_log(LOG_DEBUG, "Found no match for SIP option: %s (Please file bug report!)\n", next);
}
if (pvt) {
pvt->sipoptions = profile;
@@ -1102,7 +1095,7 @@
}
/*! \brief See if we pass debug IP filter */
-static inline int sip_debug_test_addr(struct sockaddr_in *addr)
+static inline int sip_debug_test_addr(const struct sockaddr_in *addr)
{
if (!sipdebug)
return 0;
@@ -1311,13 +1304,9 @@
}
}
/* In any case, go ahead and remove the packet */
- prev = NULL;
- cur = pkt->owner->packets;
- while(cur) {
+ for (prev = NULL, cur = pkt->owner->packets; cur; prev = cur, cur = cur->next) {
if (cur == pkt)
break;
- prev = cur;
- cur = cur->next;
}
if (cur) {
if (prev)
@@ -1441,8 +1430,7 @@
msg = sip_methods[sipmethod].text;
ast_mutex_lock(&p->lock);
- cur = p->packets;
- while(cur) {
+ for (cur = p->packets; cur; prev = cur, cur = cur->next) {
if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) &&
((ast_test_flag(cur, FLAG_RESPONSE)) ||
(!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) {
@@ -1464,8 +1452,6 @@
res = 0;
break;
}
- prev = cur;
- cur = cur->next;
}
ast_mutex_unlock(&p->lock);
if (option_debug)
@@ -1506,8 +1492,7 @@
int res = -1;
char *msg = sip_methods[sipmethod].text;
- cur = p->packets;
- while(cur) {
+ for (cur = p->packets; cur ; cur = cur->next) {
if ((cur->seqno == seqno) && ((ast_test_flag(cur, FLAG_RESPONSE)) == resp) &&
((ast_test_flag(cur, FLAG_RESPONSE)) ||
(!strncasecmp(msg, cur->data, strlen(msg)) && (cur->data[strlen(msg)] < 33)))) {
@@ -1521,7 +1506,6 @@
res = 0;
break;
}
- cur = cur->next;
}
if (option_debug)
ast_log(LOG_DEBUG, "(Provisional) Stopping retransmission (but retaining packet) on '%s' %s %d: %s\n", p->callid, resp ? "Response" : "Request", seqno, res ? "Not Found" : "Found");
@@ -1598,7 +1582,7 @@
char last_char;
parse = tmp;
- while (1) {
+ for (;;) {
first_quote = strchr(parse, '"');
first_bracket = strchr(parse, '<');
if (first_quote && first_bracket && (first_quote < first_bracket)) {
@@ -2206,12 +2190,10 @@
if (p->autokillid > -1)
ast_sched_del(sched, p->autokillid);
- if (p->rtp) {
+ if (p->rtp)
ast_rtp_destroy(p->rtp);
- }
- if (p->vrtp) {
+ if (p->vrtp)
ast_rtp_destroy(p->vrtp);
- }
if (p->route) {
free_old_route(p->route);
p->route = NULL;
@@ -2234,17 +2216,14 @@
}
/* Clear history */
if (p->history) {
- while(!AST_LIST_EMPTY(p->history)) {
- struct sip_history *hist = AST_LIST_FIRST(p->history);
- AST_LIST_REMOVE_HEAD(p->history, list);
+ struct sip_history *hist;
+ while( (hist = AST_LIST_REMOVE_HEAD(p->history, list)) )
free(hist);
- }
free(p->history);
p->history = NULL;
}
- cur = iflist;
- while(cur) {
+ for (prev = NULL, cur = iflist; cur; prev = cur, cur = cur->next) {
if (cur == p) {
if (prev)
prev->next = cur->next;
@@ -2252,8 +2231,6 @@
iflist = cur->next;
break;
}
- prev = cur;
- cur = cur->next;
}
if (!cur) {
ast_log(LOG_WARNING, "Trying to destroy \"%s\", not found in dialog list?!?! \n", p->callid);
@@ -3354,8 +3331,8 @@
}
ast_mutex_lock(&iflock);
- p = iflist;
- while(p) { /* In pedantic, we do not want packets with bad syntax to be connected to a PVT */
+ for (p = iflist; p; p = p->next) {
+ /* In pedantic, we do not want packets with bad syntax to be connected to a PVT */
int found = FALSE;
if (req->method == SIP_REGISTER)
found = (!strcmp(p->callid, callid));
@@ -3387,7 +3364,6 @@
ast_mutex_unlock(&iflock);
return p;
}
- p = p->next;
}
ast_mutex_unlock(&iflock);
p = sip_alloc(callid, sin, 1, intended_method);
@@ -3657,8 +3633,7 @@
portno = x;
/* Scan through the RTP payload types specified in a "m=" line: */
ast_rtp_pt_clear(p->rtp);
- codecs = m + len;
- while(!ast_strlen_zero(codecs)) {
+ for (codecs = m + len; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
return -1;
@@ -3666,7 +3641,6 @@
if (debug)
ast_verbose("Found RTP audio format %d\n", codec);
ast_rtp_set_m_type(p->rtp, codec);
- codecs = ast_skip_blanks(codecs + len);
}
}
if (p->vrtp)
@@ -3677,8 +3651,7 @@
ast_clear_flag(&p->flags[0], SIP_NOVIDEO);
vportno = x;
/* Scan through the RTP payload types specified in a "m=" line: */
- codecs = m + len;
- while(!ast_strlen_zero(codecs)) {
+ for (codecs = m + len; !ast_strlen_zero(codecs); codecs = ast_skip_blanks(codecs + len)) {
if (sscanf(codecs, "%d%n", &codec, &len) != 1) {
ast_log(LOG_WARNING, "Error in codec string '%s'\n", codecs);
return -1;
@@ -3686,7 +3659,6 @@
if (debug)
ast_verbose("Found RTP video format %d\n", codec);
ast_rtp_set_m_type(p->vrtp, codec);
- codecs = ast_skip_blanks(codecs + len);
}
}
if (!found )
@@ -4062,12 +4034,14 @@
char r[256], *p;
int n, rem = sizeof(r);
- if (!route) return;
+ if (!route)
+ return;
p = r;
- while (route) {
+ for (;route ; route = route->next) {
n = strlen(route->hop);
- if ((n+3)>rem) break;
+ if ( n + 3 > rem)
+ break;
if (p != r) {
*p++ = ',';
--rem;
@@ -4076,7 +4050,6 @@
ast_copy_string(p, route->hop, rem); p += n;
*p++ = '>';
rem -= (n+2);
- route = route->next;
}
*p = '\0';
add_header(req, "Route", r);
@@ -4794,7 +4767,8 @@
return -1;
}
/* XXX maybe trim_blanks() ? */
- while( isspace( *(--e) ) ) {}
+ while( isspace( *(--e) ) )
+ ;
if ( *e == '>' ) {
*e = '\0';
} else {
@@ -5142,11 +5116,8 @@
if (*headdup == '"')
headdup++;
if ((content = strchr(headdup, ':'))) {
- *content = '\0';
- content++; /* Move pointer ahead */
- /* Skip white space */
- while (*content == ' ')
- content++;
+ *content++ = '\0';
+ content = ast_skip_blanks(content); /* Skip white space */
/* Strip the ending " (if it's there) */
end = content + strlen(content) -1;
if (*end == '"')
@@ -6192,10 +6163,8 @@
ast_verbose("list_route: no route\n");
return;
}
- while (route) {
+ for (;route; route = route->next)
ast_verbose("list_route: hop: <%s>\n", route->hop);
- route = route->next;
- }
}
/*! \brief Build route list from Record-Route header */
@@ -6824,8 +6793,7 @@
/* Search interfaces and find the match */
ast_mutex_lock(&iflock);
- sip_pvt_ptr = iflist;
- while(sip_pvt_ptr) {
+ for (sip_pvt_ptr = iflist; sip_pvt_ptr ; sip_pvt_ptr = sip_pvt_ptr->next) {
if (!strcmp(sip_pvt_ptr->callid, callid)) {
/* Go ahead and lock it (and its owner) before returning */
ast_mutex_lock(&sip_pvt_ptr->lock);
@@ -6840,7 +6808,6 @@
}
break;
}
- sip_pvt_ptr = sip_pvt_ptr->next;
}
ast_mutex_unlock(&iflock);
return sip_pvt_ptr;
@@ -8190,11 +8157,9 @@
}
ast_cli(fd, " Secret : %s\n", ast_strlen_zero(peer->secret)?"<Not set>":"<Set>");
ast_cli(fd, " MD5Secret : %s\n", ast_strlen_zero(peer->md5secret)?"<Not set>":"<Set>");
- auth = peer->auth;
- while(auth) {
+ for (auth = peer->auth; auth; auth = auth->next) {
ast_cli(fd, " Realm-auth : Realm %-15.15s User %-10.20s ", auth->realm, auth->username);
ast_cli(fd, "%s\n", !ast_strlen_zero(auth->secret)?"<Secret set>":(!ast_strlen_zero(auth->md5secret)?"<MD5secret set>" : "<Not set>"));
- auth = auth->next;
}
ast_cli(fd, " Context : %s\n", peer->context);
ast_cli(fd, " Subscr.Cont. : %s\n", S_OR(peer->subscribecontext, "<Not set>") );
@@ -8585,7 +8550,7 @@
ast_cli(fd, FORMAT2, "Peer", "User/ANR", "Call ID", "Seq (Tx/Rx)", "Format", "Hold", "Last Message");
else
ast_cli(fd, FORMAT3, "Peer", "User", "Call ID", "Extension", "Last state", "Type", "Mailbox");
- while (cur) {
+ for (; cur; cur = cur->next) {
if (cur->subscribed == NONE && !subscriptions) {
ast_cli(fd, FORMAT, ast_inet_ntoa(iabuf, sizeof(iabuf), cur->sa.sin_addr),
S_OR(cur->username, S_OR(cur->cid_num, "(None)")),
@@ -8609,7 +8574,6 @@
);
numchans++;
}
- cur = cur->next;
}
ast_mutex_unlock(&iflock);
if (!subscriptions)
@@ -8726,11 +8690,9 @@
return NULL;
while ( (cat = ast_category_browse(notify_types, cat)) ) {
- if (!strncasecmp(word, cat, wordlen)) {
- if (++which > state) {
- c = ast_strdup(cat);
- break;
- }
+ if (!strncasecmp(word, cat, wordlen) && ++which > state) {
+ c = ast_strdup(cat);
+ break;
}
}
return c;
@@ -12156,8 +12118,7 @@
char authcopy[256];
char *username=NULL, *realm=NULL, *secret=NULL, *md5secret=NULL;
char *stringp;
- struct sip_auth *auth;
- struct sip_auth *b = NULL, *a = authlist;
+ struct sip_auth *a, *b, *auth;
if (ast_strlen_zero(configuration))
return authlist;
@@ -12169,10 +12130,8 @@
username = stringp;
realm = strrchr(stringp, '@');
- if (realm) {
- *realm = '\0';
- realm++;
- }
+ if (realm)
+ *realm++ = '\0';
if (ast_strlen_zero(username) || ast_strlen_zero(realm)) {
ast_log(LOG_WARNING, "Format for authentication entry is user[:secret]@realm at line %d\n", lineno);
return authlist;
@@ -12196,15 +12155,13 @@
if (md5secret)
ast_copy_string(auth->md5secret, md5secret, sizeof(auth->md5secret));
- /* Add authentication to authl */
- if (!authlist) { /* No existing list */
- return auth;
- }
- while(a) {
- b = a;
- a = a->next;
- }
- b->next = auth; /* Add structure add end of list */
+ /* find the end of the list */
+ for (b = NULL, a = authlist; a ; b = a, a = a->next)
+ ;
+ if (b)
+ b->next = auth; /* Add structure add end of list */
+ else
+ authlist = auth;
if (option_verbose > 2)
ast_verbose("Added authentication for realm %s\n", realm);
@@ -12952,13 +12909,10 @@
}
/* Build list of authentication to various SIP realms, i.e. service providers */
- v = ast_variable_browse(cfg, "authentication");
- while(v) {
+ for (v = ast_variable_browse(cfg, "authentication"); v ; v = v->next) {
/* Format for authentication is auth = username:password at realm */
- if (!strcasecmp(v->name, "auth")) {
+ if (!strcasecmp(v->name, "auth"))
authl = add_realm_authentication(authl, v->value, v->lineno);
- }
- v = v->next;
}
/* Load peers, users and friends */
@@ -13549,11 +13503,9 @@
if (!ast_mutex_lock(&iflock)) {
/* Hangup all interfaces if they have an owner */
- p = iflist;
- while (p) {
+ for (p = iflist; p ; p = p->next) {
if (p->owner)
ast_softhangup(p->owner, AST_SOFTHANGUP_APPUNLOAD);
- p = p->next;
}
ast_mutex_unlock(&iflock);
} else {
More information about the asterisk-commits
mailing list