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;
}
/*! \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) )
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;
}
/*! \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;
}
}
/* 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)
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)))) {
res = 0;
break;
}
- prev = cur;
- cur = cur->next;
}
ast_mutex_unlock(&p->lock);
if (option_debug)
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)))) {
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");
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)) {
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;
}
/* 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;
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);
}
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));
ast_mutex_unlock(&iflock);
return p;
}
- p = p->next;
}
ast_mutex_unlock(&iflock);
p = sip_alloc(callid, sin, 1, intended_method);
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;
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)
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;
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 )
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;
ast_copy_string(p, route->hop, rem); p += n;
*p++ = '>';
rem -= (n+2);
- route = route->next;
}
*p = '\0';
add_header(req, "Route", r);
return -1;
}
/* XXX maybe trim_blanks() ? */
- while( isspace( *(--e) ) ) {}
+ while( isspace( *(--e) ) )
+ ;
if ( *e == '>' ) {
*e = '\0';
} else {
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 == '"')
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 */
/* 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);
}
break;
}
- sip_pvt_ptr = sip_pvt_ptr->next;
}
ast_mutex_unlock(&iflock);
return sip_pvt_ptr;
}
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>") );
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)")),
);
numchans++;
}
- cur = cur->next;
}
ast_mutex_unlock(&iflock);
if (!subscriptions)
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;
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;
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;
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);
}
/* 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@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 */
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 {