[Asterisk-cvs] asterisk/channels chan_iax2.c,1.138,1.139

citats at lists.digium.com citats at lists.digium.com
Wed May 5 17:06:01 CDT 2004


Update of /usr/cvsroot/asterisk/channels
In directory mongoose.digium.com:/home/citats/cvs/asterisk/channels

Modified Files:
	chan_iax2.c 
Log Message:
Use ast_strlen_zero in chan_iax2.c


Index: chan_iax2.c
===================================================================
RCS file: /usr/cvsroot/asterisk/channels/chan_iax2.c,v
retrieving revision 1.138
retrieving revision 1.139
diff -u -d -r1.138 -r1.139
--- chan_iax2.c	3 May 2004 21:00:20 -0000	1.138
+++ chan_iax2.c	5 May 2004 21:14:36 -0000	1.139
@@ -936,7 +936,7 @@
 		close(fd);
 		return -1;
 	}
-	if (fwh2.devname[sizeof(fwh2.devname) - 1] || !strlen(fwh2.devname)) {
+	if (fwh2.devname[sizeof(fwh2.devname) - 1] || ast_strlen_zero(fwh2.devname)) {
 		ast_log(LOG_WARNING, "No or invalid device type specified for '%s'\n", s);
 		close(fd);
 		return -1;
@@ -999,7 +999,7 @@
 {
 	int res = 0;
 	struct iax_firmware *cur;
-	if (dev && strlen(dev)) {
+	if (dev && !ast_strlen_zero(dev)) {
 		ast_mutex_lock(&waresl.lock);
 		cur = waresl.wares;
 		while(cur) {
@@ -1021,7 +1021,7 @@
 	unsigned int start = (desc >> 8) & 0xffffff;
 	unsigned int bytes;
 	struct iax_firmware *cur;
-	if (dev && strlen(dev) && bs) {
+	if (dev && !ast_strlen_zero(dev) && bs) {
 		start *= bs;
 		ast_mutex_lock(&waresl.lock);
 		cur = waresl.wares;
@@ -1528,7 +1528,7 @@
 		if (dp->flags & CACHE_FLAG_UNKNOWN)
 			strcat(tmp, "UNKNOWN|");
 		/* Trim trailing pipe */
-		if (strlen(tmp))
+		if (!ast_strlen_zero(tmp))
 			tmp[strlen(tmp) - 1] = '\0';
 		else
 			strcpy(tmp, "(none)");
@@ -2144,24 +2144,24 @@
 			iax_ie_append_str(&ied, IAX_IE_CALLING_ANI, l);
 		}
 	}
-	if (c->language && strlen(c->language))
+	if (c->language && !ast_strlen_zero(c->language))
 		iax_ie_append_str(&ied, IAX_IE_LANGUAGE, c->language);
-	if (c->dnid && strlen(c->dnid))
+	if (c->dnid && !ast_strlen_zero(c->dnid))
 		iax_ie_append_str(&ied, IAX_IE_DNID, c->dnid);
 	if (rcontext)
 		iax_ie_append_str(&ied, IAX_IE_CALLED_CONTEXT, rcontext);
 	if (username)
 		iax_ie_append_str(&ied, IAX_IE_USERNAME, username);
-	if (!secret && strlen(storedsecret))
+	if (!secret && !ast_strlen_zero(storedsecret))
 		secret = storedsecret;
 	ast_mutex_lock(&iaxsl[callno]);
-	if (strlen(c->context))
+	if (!ast_strlen_zero(c->context))
 		strncpy(iaxs[callno]->context, c->context, sizeof(iaxs[callno]->context));
 	if (secret) {
 		if (secret[0] == '[') {
 			/* This is an RSA key, not a normal secret */
 			strncpy(iaxs[callno]->outkey, secret + 1, sizeof(iaxs[callno]->secret)-1);
-			if (strlen(iaxs[callno]->outkey)) {
+			if (!ast_strlen_zero(iaxs[callno]->outkey)) {
 				iaxs[callno]->outkey[strlen(iaxs[callno]->outkey) - 1] = '\0';
 			}
 		} else
@@ -2492,7 +2492,7 @@
 	struct ast_channel *tmp;
 	tmp = ast_channel_alloc(1);
 	if (tmp) {
-		if (strlen(i->username))
+		if (!ast_strlen_zero(i->username))
 			snprintf(tmp->name, sizeof(tmp->name), "IAX2[%s@%s]/%d", i->username, i->host, i->callno);
 		else
 			snprintf(tmp->name, sizeof(tmp->name), "IAX2[%s]/%d", i->host, i->callno);
@@ -2516,15 +2516,15 @@
 		tmp->pvt->setoption = iax2_setoption;
 		tmp->pvt->bridge = iax2_bridge;
 		tmp->pvt->transfer = iax2_transfer;
-		if (strlen(i->callerid))
+		if (!ast_strlen_zero(i->callerid))
 			tmp->callerid = strdup(i->callerid);
-		if (strlen(i->ani))
+		if (!ast_strlen_zero(i->ani))
 			tmp->ani = strdup(i->ani);
-		if (strlen(i->language))
+		if (!ast_strlen_zero(i->language))
 			strncpy(tmp->language, i->language, sizeof(tmp->language)-1);
-		if (strlen(i->dnid))
+		if (!ast_strlen_zero(i->dnid))
 			tmp->dnid = strdup(i->dnid);
-		if (strlen(i->accountcode))
+		if (!ast_strlen_zero(i->accountcode))
 			strncpy(tmp->accountcode, i->accountcode, sizeof(tmp->accountcode)-1);
 		if (i->amaflags)
 			tmp->amaflags = i->amaflags;
@@ -2936,9 +2936,9 @@
 	ast_mutex_lock(&userl.lock);
 	ast_cli(fd, FORMAT, "Username", "Secret", "Authen", "Def.Context", "A/C");
 	for(user=userl.users;user;user=user->next) {
-		if (strlen(user->secret)) {
+		if (!ast_strlen_zero(user->secret)) {
   			strncpy(auth,user->secret,strlen(auth)-1);
-		} else if (strlen(user->inkeys)) {
+		} else if (!ast_strlen_zero(user->inkeys)) {
   			sprintf(auth,"Key: %-15.15s ",user->inkeys);
  		} else
 			strcpy(auth,"-no secret-");
@@ -2976,7 +2976,7 @@
                 char srch[2000];
 		if (registeredonly && !peer->addr.sin_addr.s_addr)
 			continue;
-		if (strlen(peer->username))
+		if (!ast_strlen_zero(peer->username))
 			snprintf(name, sizeof(name), "%s/%s", peer->name, peer->username);
 		else
 			strncpy(name, peer->name, sizeof(name) - 1);
@@ -3117,7 +3117,7 @@
 		ast_mutex_lock(&iaxsl[x]);
 		if (iaxs[x]) {
 			ast_cli(fd, FORMAT, inet_ntoa(iaxs[x]->addr.sin_addr), 
-						strlen(iaxs[x]->username) ? iaxs[x]->username : "(None)", 
+						!ast_strlen_zero(iaxs[x]->username) ? iaxs[x]->username : "(None)", 
 						iaxs[x]->callno, iaxs[x]->peercallno, 
 						iaxs[x]->oseqno, iaxs[x]->iseqno, 
 						iaxs[x]->lag,
@@ -3360,16 +3360,16 @@
 	/* Search the userlist for a compatible entry, and fill in the rest */
 	user = userl.users;
 	while(user) {
-		if ((!strlen(iaxs[callno]->username) ||				/* No username specified */
+		if ((ast_strlen_zero(iaxs[callno]->username) ||				/* No username specified */
 			!strcmp(iaxs[callno]->username, user->name))	/* Or this username specified */
 			&& ast_apply_ha(user->ha, sin) 	/* Access is permitted from this IP */
-			&& (!strlen(iaxs[callno]->context) ||			/* No context specified */
+			&& (ast_strlen_zero(iaxs[callno]->context) ||			/* No context specified */
 			     apply_context(user->contexts, iaxs[callno]->context))) {			/* Context is permitted */
-			if (strlen(iaxs[callno]->username)) {
+			if (!ast_strlen_zero(iaxs[callno]->username)) {
 				/* Exact match, stop right now. */
 				best = user;
 				break;
-			} else if (!strlen(user->secret)) {
+			} else if (ast_strlen_zero(user->secret)) {
 				/* No required authentication */
 				if (user->ha) {
 					/* There was host authentication and we passed, bonus! */
@@ -3405,9 +3405,9 @@
 	ast_mutex_unlock(&userl.lock);
 	user = best;
 #ifdef MYSQL_FRIENDS
-	if (!user && mysql && strlen(iaxs[callno]->username) && (strlen(iaxs[callno]->username) < 128)) {
+	if (!user && mysql && !ast_strlen_zero(iaxs[callno]->username) && (strlen(iaxs[callno]->username) < 128)) {
 		user = mysql_user(iaxs[callno]->username);
-		if (user && strlen(iaxs[callno]->context) &&			/* No context specified */
+		if (user && !ast_strlen_zero(iaxs[callno]->context) &&			/* No context specified */
 			     !apply_context(user->contexts, iaxs[callno]->context)) {			/* Context is permitted */
 			if (user->contexts)
 				free(user->contexts);
@@ -3420,13 +3420,13 @@
 		/* We found our match (use the first) */
 		
 		/* Store the requested username if not specified */
-		if (!strlen(iaxs[callno]->username))
+		if (ast_strlen_zero(iaxs[callno]->username))
 			strncpy(iaxs[callno]->username, user->name, sizeof(iaxs[callno]->username)-1);
 		/* Store whether this is a trunked call, too, of course, and move if appropriate */
 		iaxs[callno]->trunk = user->trunk;
 		iaxs[callno]->capability = user->capability;
 		/* And use the default context */
-		if (!strlen(iaxs[callno]->context)) {
+		if (ast_strlen_zero(iaxs[callno]->context)) {
 			if (user->contexts)
 				strncpy(iaxs[callno]->context, user->contexts->context, sizeof(iaxs[callno]->context)-1);
 			else
@@ -3439,16 +3439,16 @@
 		/* And the permitted authentication methods */
 		iaxs[callno]->authmethods = user->authmethods;
 		/* If they have callerid, override the given caller id.  Always store the ANI */
-		if (strlen(iaxs[callno]->callerid)) {
+		if (!ast_strlen_zero(iaxs[callno]->callerid)) {
 			if (user->hascallerid)
 				strncpy(iaxs[callno]->callerid, user->callerid, sizeof(iaxs[callno]->callerid)-1);
 			strncpy(iaxs[callno]->ani, user->callerid, sizeof(iaxs[callno]->ani)-1);
 		}
-		if (strlen(user->accountcode))
+		if (!ast_strlen_zero(user->accountcode))
 			strncpy(iaxs[callno]->accountcode, user->accountcode, sizeof(iaxs[callno]->accountcode)-1);
 		if (user->amaflags)
 			iaxs[callno]->amaflags = user->amaflags;
-		if (strlen(user->language))
+		if (!ast_strlen_zero(user->language))
 			strncpy(iaxs[callno]->language, user->language, sizeof(iaxs[callno]->language)-1);
 		iaxs[callno]->notransfer = user->notransfer;
 		res = 0;
@@ -3505,7 +3505,7 @@
 		strncpy(md5secret, ies->md5_result, sizeof(md5secret)-1);
 	if (ies->rsa_result)
 		strncpy(rsasecret, ies->rsa_result, sizeof(rsasecret)-1);
-	if ((p->authmethods & IAX_AUTH_RSA) && strlen(rsasecret) && strlen(p->inkeys)) {
+	if ((p->authmethods & IAX_AUTH_RSA) && !ast_strlen_zero(rsasecret) && !ast_strlen_zero(p->inkeys)) {
 		struct ast_key *key;
 		char *keyn;
 		char tmpkey[256];
@@ -3567,7 +3567,7 @@
 	if (ies->refresh)
 		expire = ies->refresh;
 
-	if (!strlen(peer)) {
+	if (ast_strlen_zero(peer)) {
 		ast_log(LOG_NOTICE, "Empty registration from %s\n", inet_ntoa(sin->sin_addr));
 		return -1;
 	}
@@ -3606,8 +3606,8 @@
 	strncpy(iaxs[callno]->secret, p->secret, sizeof(iaxs[callno]->secret)-1);
 	strncpy(iaxs[callno]->inkeys, p->inkeys, sizeof(iaxs[callno]->inkeys)-1);
 	/* Check secret against what we have on file */
-	if (strlen(rsasecret) && (p->authmethods & IAX_AUTH_RSA) && strlen(iaxs[callno]->challenge)) {
-		if (strlen(p->inkeys)) {
+	if (!ast_strlen_zero(rsasecret) && (p->authmethods & IAX_AUTH_RSA) && !ast_strlen_zero(iaxs[callno]->challenge)) {
+		if (!ast_strlen_zero(p->inkeys)) {
 			char tmpkeys[256];
 			char *stringp=NULL;
 			strncpy(tmpkeys, p->inkeys, sizeof(tmpkeys));
@@ -3636,7 +3636,7 @@
 				free(p);
 			return -1;
 		}
-	} else if (strlen(secret) && (p->authmethods & IAX_AUTH_PLAINTEXT)) {
+	} else if (!ast_strlen_zero(secret) && (p->authmethods & IAX_AUTH_PLAINTEXT)) {
 		/* They've provided a plain text password and we support that */
 		if (strcmp(secret, p->secret)) {
 			if (authdebug)
@@ -3646,7 +3646,7 @@
 			return -1;
 		} else
 			iaxs[callno]->state |= IAX_STATE_AUTHENTICATED;
-	} else if (strlen(md5secret) && (p->authmethods & IAX_AUTH_MD5) && strlen(iaxs[callno]->challenge)) {
+	} else if (!ast_strlen_zero(md5secret) && (p->authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(iaxs[callno]->challenge)) {
 		struct MD5Context md5;
 		unsigned char digest[16];
 		MD5Init(&md5);
@@ -3663,7 +3663,7 @@
 			return -1;
 		} else
 			iaxs[callno]->state |= IAX_STATE_AUTHENTICATED;
-	} else if (strlen(md5secret) || strlen(secret)) {
+	} else if (!ast_strlen_zero(md5secret) || !ast_strlen_zero(secret)) {
 		if (authdebug)
 			ast_log(LOG_NOTICE, "Inappropriate authentication received\n");
 		if (p->temponly)
@@ -3684,11 +3684,11 @@
 {
 	int res = -1;
 	int x;
-	if (keyn && strlen(keyn)) {
+	if (keyn && !ast_strlen_zero(keyn)) {
 		if (!(authmethods & IAX_AUTH_RSA)) {
-			if (!secret || !strlen(secret)) 
+			if (!secret || ast_strlen_zero(secret)) 
 				ast_log(LOG_NOTICE, "Asked to authenticate to %s with an RSA key, but they don't allow RSA authentication\n", inet_ntoa(sin->sin_addr));
-		} else if (!strlen(challenge)) {
+		} else if (ast_strlen_zero(challenge)) {
 			ast_log(LOG_NOTICE, "No challenge provided for RSA authentication to %s\n", inet_ntoa(sin->sin_addr));
 		} else {
 			char sig[256];
@@ -3708,8 +3708,8 @@
 		}
 	} 
 	/* Fall back */
-	if (res && secret && strlen(secret)) {
-		if ((authmethods & IAX_AUTH_MD5) && strlen(challenge)) {
+	if (res && secret && !ast_strlen_zero(secret)) {
+		if ((authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(challenge)) {
 			struct MD5Context md5;
 			unsigned char digest[16];
 			char digres[128] = "";
@@ -3749,16 +3749,16 @@
 		authmethods = ies->authmethods;
 
 	/* Check for override RSA authentication first */
-	if ((override && strlen(override)) || (okey && strlen(okey))) {
+	if ((override && !ast_strlen_zero(override)) || (okey && !ast_strlen_zero(okey))) {
 		/* Normal password authentication */
 		res = authenticate(p->challenge, override, okey, authmethods, &ied, sin);
 	} else {
 		ast_mutex_lock(&peerl.lock);
 		peer = peerl.peers;
 		while(peer) {
-			if ((!strlen(p->peer) || !strcmp(p->peer, peer->name)) 
+			if ((ast_strlen_zero(p->peer) || !strcmp(p->peer, peer->name)) 
 								/* No peer specified at our end, or this is the peer */
-			 && (!strlen(peer->username) || (!strcmp(peer->username, p->username)))
+			 && (ast_strlen_zero(peer->username) || (!strcmp(peer->username, p->username)))
 			 					/* No username specified in peer rule, or this is the right username */
 			 && (!peer->addr.sin_addr.s_addr || ((sin->sin_addr.s_addr & peer->mask.s_addr) == (peer->addr.sin_addr.s_addr & peer->mask.s_addr)))
 			 					/* No specified host, or this is our host */
@@ -4140,7 +4140,7 @@
 		if (sin->sin_addr.s_addr) {
 			iax_ie_append_short(&ied, IAX_IE_REFRESH, p->expirey);
 			iax_ie_append_addr(&ied, IAX_IE_APPARENT_ADDR, &p->addr);
-			if (strlen(p->mailbox)) {
+			if (!ast_strlen_zero(p->mailbox)) {
 				msgcount = ast_app_has_voicemail(p->mailbox);
 				if (msgcount)
 					msgcount = 65535;
@@ -4213,7 +4213,7 @@
 				ast_log(LOG_WARNING, "Received unsolicited registry authenticate request from '%s'\n", inet_ntoa(sin->sin_addr));
 				return -1;
 			}
-			if (!strlen(reg->secret)) {
+			if (ast_strlen_zero(reg->secret)) {
 				ast_log(LOG_NOTICE, "No secret associated with peer '%s'\n", reg->username);
 				reg->regstate = REG_STATE_NOAUTH;
 				return -1;
@@ -5012,7 +5012,7 @@
 					ast_mutex_lock(&iaxsl[fr.callno]);
 				} else
 					exists = 0;
-				if (!strlen(iaxs[fr.callno]->secret) && !strlen(iaxs[fr.callno]->inkeys)) {
+				if (ast_strlen_zero(iaxs[fr.callno]->secret) && ast_strlen_zero(iaxs[fr.callno]->inkeys)) {
 					if (strcmp(iaxs[fr.callno]->exten, "TBD") && !exists) {
 						memset(&ied0, 0, sizeof(ied0));
 						iax_ie_append_str(&ied0, IAX_IE_CAUSE, "No such context/extension");
@@ -5371,7 +5371,7 @@
 					send_command_final(iaxs[fr.callno], AST_FRAME_IAX, IAX_COMMAND_REGREJ, 0, ied0.buf, ied0.pos, -1);
 					break;
 				}
-				if ((!strlen(iaxs[fr.callno]->secret) && !strlen(iaxs[fr.callno]->inkeys)) || (iaxs[fr.callno]->state & IAX_STATE_AUTHENTICATED)) {
+				if ((ast_strlen_zero(iaxs[fr.callno]->secret) && ast_strlen_zero(iaxs[fr.callno]->inkeys)) || (iaxs[fr.callno]->state & IAX_STATE_AUTHENTICATED)) {
 					if (f.subclass == IAX_COMMAND_REGREL)
 						memset(&sin, 0, sizeof(sin));
 					if (update_registry(iaxs[fr.callno]->peer, &sin, fr.callno, ies.devicetype))
@@ -5925,7 +5925,7 @@
 				maskfound++;
 				inet_aton(v->value, &peer->mask);
 			} else if (!strcasecmp(v->name, "context")) {
-				if (!strlen(peer->context))
+				if (ast_strlen_zero(peer->context))
 					strncpy(peer->context, v->value, sizeof(peer->context) - 1);
 			} else if (!strcasecmp(v->name, "port")) {
 				if (peer->dynamic)
@@ -6082,11 +6082,11 @@
 			v = v->next;
 		}
 		if (!user->authmethods) {
-			if (strlen(user->secret)) {
+			if (!ast_strlen_zero(user->secret)) {
 				user->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
-				if (strlen(user->inkeys))
+				if (!ast_strlen_zero(user->inkeys))
 					user->authmethods |= IAX_AUTH_RSA;
-			} else if (strlen(user->inkeys)) {
+			} else if (!ast_strlen_zero(user->inkeys)) {
 				user->authmethods = IAX_AUTH_RSA;
 			} else {
 				user->authmethods = IAX_AUTH_MD5 | IAX_AUTH_PLAINTEXT;
@@ -6368,7 +6368,7 @@
 	set_timing();
 #ifdef MYSQL_FRIENDS
 	/* Connect to db if appropriate */
-	if (!mysql && strlen(mydbname)) {
+	if (!mysql && !ast_strlen_zero(mydbname)) {
 		mysql = mysql_init(NULL);
 		if (!mysql_real_connect(mysql, mydbhost[0] ? mydbhost : NULL, mydbuser, mydbpass, mydbname, 0, NULL, 0)) {
 			memset(mydbpass, '*', strlen(mydbpass));




More information about the svn-commits mailing list