avoid repeated calls to strlen in command completion functions and normalize

some loops


git-svn-id: https://origsvn.digium.com/svn/asterisk/trunk@7657 65c4cc65-6c06-0410-ace0-fbb531ad65f3
This commit is contained in:
Russell Bryant 2005-12-27 18:18:41 +00:00
parent 478052caa0
commit e4e5b423a4

View file

@ -8294,17 +8294,16 @@ static char *complete_sipch(char *line, char *word, int pos, int state)
int which=0; int which=0;
struct sip_pvt *cur; struct sip_pvt *cur;
char *c = NULL; char *c = NULL;
int wordlen = strlen(word);
ast_mutex_lock(&iflock); ast_mutex_lock(&iflock);
cur = iflist; for (cur = iflist; cur; cur = cur->next) {
while(cur) { if (!strncasecmp(word, cur->callid, wordlen)) {
if (!strncasecmp(word, cur->callid, strlen(word))) {
if (++which > state) { if (++which > state) {
c = strdup(cur->callid); c = strdup(cur->callid);
break; break;
} }
} }
cur = cur->next;
} }
ast_mutex_unlock(&iflock); ast_mutex_unlock(&iflock);
return c; return c;
@ -8384,22 +8383,21 @@ static char *complete_sipnotify(char *line, char *word, int pos, int state)
if (pos == 2) { if (pos == 2) {
int which = 0; int which = 0;
char *cat; char *cat = NULL;
int wordlen = strlen(word);
/* do completion for notify type */ /* do completion for notify type */
if (!notify_types) if (!notify_types)
return NULL; return NULL;
cat = ast_category_browse(notify_types, NULL); while ( (cat = ast_category_browse(notify_types, cat)) ) {
while(cat) { if (!strncasecmp(word, cat, wordlen)) {
if (!strncasecmp(word, cat, strlen(word))) {
if (++which > state) { if (++which > state) {
c = strdup(cat); c = strdup(cat);
break; break;
} }
} }
cat = ast_category_browse(notify_types, cat);
} }
return c; return c;
} }
@ -8439,9 +8437,8 @@ static int sip_show_channel(int fd, int argc, char *argv[])
return RESULT_SHOWUSAGE; return RESULT_SHOWUSAGE;
len = strlen(argv[3]); len = strlen(argv[3]);
ast_mutex_lock(&iflock); ast_mutex_lock(&iflock);
cur = iflist; for (cur = iflist; cur; cur = cur->next) {
while(cur) { if (!strncasecmp(cur->callid, argv[3], len)) {
if (!strncasecmp(cur->callid, argv[3],len)) {
ast_cli(fd,"\n"); ast_cli(fd,"\n");
if (cur->subscribed != NONE) if (cur->subscribed != NONE)
ast_cli(fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed)); ast_cli(fd, " * Subscription (type: %s)\n", subscription_type2str(cur->subscribed));
@ -8486,7 +8483,6 @@ static int sip_show_channel(int fd, int argc, char *argv[])
ast_cli(fd, "\n\n"); ast_cli(fd, "\n\n");
found++; found++;
} }
cur = cur->next;
} }
ast_mutex_unlock(&iflock); ast_mutex_unlock(&iflock);
if (!found) if (!found)
@ -8509,8 +8505,7 @@ static int sip_show_history(int fd, int argc, char *argv[])
ast_cli(fd, "\n***Note: History recording is currently DISABLED. Use 'sip history' to ENABLE.\n"); ast_cli(fd, "\n***Note: History recording is currently DISABLED. Use 'sip history' to ENABLE.\n");
len = strlen(argv[3]); len = strlen(argv[3]);
ast_mutex_lock(&iflock); ast_mutex_lock(&iflock);
cur = iflist; for (cur = iflist; cur; cur = cur->next) {
while(cur) {
if (!strncasecmp(cur->callid, argv[3], len)) { if (!strncasecmp(cur->callid, argv[3], len)) {
ast_cli(fd,"\n"); ast_cli(fd,"\n");
if (cur->subscribed != NONE) if (cur->subscribed != NONE)
@ -8528,7 +8523,6 @@ static int sip_show_history(int fd, int argc, char *argv[])
ast_cli(fd, "Call '%s' has no history\n", cur->callid); ast_cli(fd, "Call '%s' has no history\n", cur->callid);
found++; found++;
} }
cur = cur->next;
} }
ast_mutex_unlock(&iflock); ast_mutex_unlock(&iflock);
if (!found) if (!found)
@ -8552,11 +8546,9 @@ void sip_dump_history(struct sip_pvt *dialog)
else else
ast_log(LOG_DEBUG, " * SIP Call\n"); ast_log(LOG_DEBUG, " * SIP Call\n");
x = 0; x = 0;
hist = dialog->history; for (hist = dialog->history; hist; hist = hist->next) {
while(hist) {
x++; x++;
ast_log(LOG_DEBUG, " %d. %s\n", x, hist->event); ast_log(LOG_DEBUG, " %d. %s\n", x, hist->event);
hist = hist->next;
} }
if (!x) if (!x)
ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid); ast_log(LOG_DEBUG, "Call '%s' has no history\n", dialog->callid);
@ -11207,8 +11199,7 @@ static void *do_monitor(void *data)
ast_mutex_lock(&iflock); ast_mutex_lock(&iflock);
restartsearch: restartsearch:
time(&t); time(&t);
sip = iflist; for (sip = iflist; sip; sip = sip->next) {
while(sip) {
ast_mutex_lock(&sip->lock); ast_mutex_lock(&sip->lock);
if (sip->rtp && sip->owner && (sip->owner->_state == AST_STATE_UP) && !sip->redirip.sin_addr.s_addr) { if (sip->rtp && sip->owner && (sip->owner->_state == AST_STATE_UP) && !sip->redirip.sin_addr.s_addr) {
if (sip->lastrtptx && sip->rtpkeepalive && t > sip->lastrtptx + sip->rtpkeepalive) { if (sip->lastrtptx && sip->rtpkeepalive && t > sip->lastrtptx + sip->rtpkeepalive) {
@ -11246,7 +11237,6 @@ restartsearch:
goto restartsearch; goto restartsearch;
} }
ast_mutex_unlock(&sip->lock); ast_mutex_unlock(&sip->lock);
sip = sip->next;
} }
ast_mutex_unlock(&iflock); ast_mutex_unlock(&iflock);
/* Don't let anybody kill us right away. Nobody should lock the interface list /* Don't let anybody kill us right away. Nobody should lock the interface list
@ -11828,13 +11818,11 @@ static int clear_realm_authentication(struct sip_auth *authlist)
/*! \brief find_realm_authentication: Find authentication for a specific realm ---*/ /*! \brief find_realm_authentication: Find authentication for a specific realm ---*/
static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, char *realm) static struct sip_auth *find_realm_authentication(struct sip_auth *authlist, char *realm)
{ {
struct sip_auth *a = authlist; /* First entry in auth list */ struct sip_auth *a;
while (a) { for (a = authlist; a; a = a->next) {
if (!strcasecmp(a->realm, realm)){ if (!strcasecmp(a->realm, realm))
break; break;
}
a = a->next;
} }
return a; return a;