[asterisk-commits] pabelanger: branch pabelanger/issue18183 r292863 - /team/pabelanger/issue1818...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat Oct 23 16:07:49 CDT 2010


Author: pabelanger
Date: Sat Oct 23 16:07:43 2010
New Revision: 292863

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=292863
Log:
Fix issue in update_registry.  More formatting changes.

Modified:
    team/pabelanger/issue18183/channels/chan_iax2.c

Modified: team/pabelanger/issue18183/channels/chan_iax2.c
URL: http://svnview.digium.com/svn/asterisk/team/pabelanger/issue18183/channels/chan_iax2.c?view=diff&rev=292863&r1=292862&r2=292863
==============================================================================
--- team/pabelanger/issue18183/channels/chan_iax2.c (original)
+++ team/pabelanger/issue18183/channels/chan_iax2.c Sat Oct 23 16:07:43 2010
@@ -2876,8 +2876,9 @@
 		iaxs[x] = new_iax(sin, host);
 		update_max_nontrunk();
 		if (iaxs[x]) {
-			if (iaxdebug)
+			if (iaxdebug) {
 				ast_debug(1, "Creating new call structure %d\n", x);
+			}
 			iaxs[x]->callno_entry = callno_entry;
 			iaxs[x]->sockfd = sockfd;
 			iaxs[x]->addr.sin_port = sin->sin_port;
@@ -2905,8 +2906,9 @@
 			replace_callno(callno_entry);
 			return 0;
 		}
-		if (!return_locked)
+		if (!return_locked) {
 			ast_mutex_unlock(&iaxsl[x]);
+		}
 		res = x;
 	}
 	return res;
@@ -7890,16 +7892,21 @@
 
 	ast_clear_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
 	/* iaxs[callno]->peer[0] = '\0'; not necc. any more-- stringfield is pre-inited to null string */
-	if (ies->username)
+	if (ies->username) {
 		ast_copy_string(peer, ies->username, sizeof(peer));
-	if (ies->password)
+	}
+	if (ies->password) {
 		ast_copy_string(secret, ies->password, sizeof(secret));
-	if (ies->md5_result)
+	}
+	if (ies->md5_result) {
 		ast_copy_string(md5secret, ies->md5_result, sizeof(md5secret));
-	if (ies->rsa_result)
+	}
+	if (ies->rsa_result) {
 		ast_copy_string(rsasecret, ies->rsa_result, sizeof(rsasecret));
-	if (ies->refresh)
+	}
+	if (ies->refresh) {
 		expire = ies->refresh;
+	}
 
 	if (ast_strlen_zero(peer)) {
 		ast_log(LOG_NOTICE, "Empty registration from %s\n", ast_inet_ntoa(sin->sin_addr));
@@ -7930,21 +7937,24 @@
 				res = 0;
 			}
 		}
-		if (authdebug && !p)
+		if (authdebug && !p) {
 			ast_log(LOG_NOTICE, "No registration for peer '%s' (from %s)\n", peer, ast_inet_ntoa(sin->sin_addr));
+		}
 		goto return_unref;
 	}
 
 	if (!ast_test_flag64(p, IAX_DYNAMIC)) {
-		if (authdebug)
+		if (authdebug) {
 			ast_log(LOG_NOTICE, "Peer '%s' is not dynamic (from %s)\n", peer, ast_inet_ntoa(sin->sin_addr));
+		}
 		goto return_unref;
 	}
 
 	ast_sockaddr_from_sin(&addr, sin);
 	if (!ast_apply_ha(p->ha, &addr)) {
-		if (authdebug)
+		if (authdebug) {
 			ast_log(LOG_NOTICE, "Host %s denied access to register peer '%s'\n", ast_inet_ntoa(sin->sin_addr), p->name);
+		}
 		goto return_unref;
 	}
 	ast_string_field_set(iaxs[callno], secret, p->secret);
@@ -7953,27 +7963,30 @@
 	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;
+			char *stringp = NULL;
 			ast_copy_string(tmpkeys, p->inkeys, sizeof(tmpkeys));
-			stringp=tmpkeys;
+			stringp = tmpkeys;
 			keyn = strsep(&stringp, ":");
-			while(keyn) {
+			while (keyn) {
 				key = ast_key_get(keyn, AST_KEY_PUBLIC);
 				if (key && !ast_check_signature(key, iaxs[callno]->challenge, rsasecret)) {
 					ast_set_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
 					break;
-				} else if (!key)
+				} else if (!key) {
 					ast_log(LOG_WARNING, "requested inkey '%s' does not exist\n", keyn);
+				}
 				keyn = strsep(&stringp, ":");
 			}
 			if (!keyn) {
-				if (authdebug)
+				if (authdebug) {
 					ast_log(LOG_NOTICE, "Host %s failed RSA authentication with inkeys '%s'\n", peer, p->inkeys);
+				}
 				goto return_unref;
 			}
 		} else {
-			if (authdebug)
+			if (authdebug) {
 				ast_log(LOG_NOTICE, "Host '%s' trying to do RSA authentication, but we have no inkeys\n", peer);
+			}
 			goto return_unref;
 		}
 	} else if (!ast_strlen_zero(md5secret) && (p->authmethods & IAX_AUTH_MD5) && !ast_strlen_zero(iaxs[callno]->challenge)) {
@@ -7983,31 +7996,36 @@
 
 		tmppw = ast_strdupa(p->secret);
 		stringp = tmppw;
-		while((tmppw = strsep(&stringp, ";"))) {
+		while ((tmppw = strsep(&stringp, ";"))) {
 			MD5Init(&md5);
 			MD5Update(&md5, (unsigned char *)iaxs[callno]->challenge, strlen(iaxs[callno]->challenge));
 			MD5Update(&md5, (unsigned char *)tmppw, strlen(tmppw));
 			MD5Final(digest, &md5);
-			for (x=0;x<16;x++)
+			for (x = 0; x < 16; x++) {
 				sprintf(requeststr + (x << 1), "%2.2x", digest[x]); /* safe */
-			if (!strcasecmp(requeststr, md5secret))
+			}
+			if (!strcasecmp(requeststr, md5secret)) {
 				break;
+			}
 		}
 		if (tmppw) {
 			ast_set_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
 		} else {
-			if (authdebug)
+			if (authdebug) {
 				ast_log(LOG_NOTICE, "Host %s failed MD5 authentication for '%s' (%s != %s)\n", ast_inet_ntoa(sin->sin_addr), p->name, requeststr, md5secret);
+			}
 			goto return_unref;
 		}
 	} 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)
+			if (authdebug) {
 				ast_log(LOG_NOTICE, "Host %s did not provide proper plaintext password for '%s'\n", ast_inet_ntoa(sin->sin_addr), p->name);
+			}
 			goto return_unref;
-		} else
+		} else {
 			ast_set_flag(&iaxs[callno]->state, IAX_STATE_AUTHENTICATED);
+		}
 	} else if (!ast_strlen_zero(iaxs[callno]->challenge) && ast_strlen_zero(md5secret) && ast_strlen_zero(rsasecret)) {
 		/* if challenge has been sent, but no challenge response if given, reject. */
 		goto return_unref;
@@ -8496,7 +8514,6 @@
 	return iax2_append_register(hostname, username, secret, porta);
 }
 
-
 static void register_peer_exten(struct iax2_peer *peer, int onoff)
 {
 	char multi[256];
@@ -8504,13 +8521,14 @@
 	if (!ast_strlen_zero(regcontext)) {
 		ast_copy_string(multi, S_OR(peer->regexten, peer->name), sizeof(multi));
 		stringp = multi;
-		while((ext = strsep(&stringp, "&"))) {
+		while ((ext = strsep(&stringp, "&"))) {
 			if (onoff) {
-				if (!ast_exists_extension(NULL, regcontext, ext, 1, NULL))
-					ast_add_extension(regcontext, 1, ext, 1, NULL, NULL,
-							  "Noop", ast_strdup(peer->name), ast_free_ptr, "IAX2");
-			} else
+				if (!ast_exists_extension(NULL, regcontext, ext, 1, NULL)) {
+					ast_add_extension(regcontext, 1, ext, 1, NULL, NULL, "Noop", ast_strdup(peer->name), ast_free_ptr, "IAX2");
+				}
+			} else {
 				ast_context_remove_extension(regcontext, ext, 1, NULL);
+			}
 		}
 	}
 }
@@ -8657,8 +8675,10 @@
 		return -1;
 	}
 	ast_mutex_lock(&iaxsl[callno]);
-	if (!iaxs[callno])
+
+	if (!iaxs[callno]) {
 		goto return_unref;
+	}
 
 	if (ast_test_flag64((&globalflags), IAX_RTUPDATE) && (ast_test_flag64(p, IAX_TEMPONLY|IAX_RTCACHEFRIENDS))) {
 		if (sin->sin_addr.s_addr) {
@@ -8679,7 +8699,7 @@
 		peercnt_modify(0, 0, &p->addr);
 
 		/* Stash the IP address from which they registered */
-		memcpy(&p->addr, sin, sizeof(p->addr));
+		ast_sockaddr_from_sin(&p->addr, sin);
 
 		snprintf(data, sizeof(data), "%s:%d:%d", ast_inet_ntoa(sin->sin_addr), ntohs(sin->sin_port), p->expiry);
 		if (!ast_test_flag64(p, IAX_TEMPONLY) && sin->sin_addr.s_addr) {
@@ -8723,23 +8743,23 @@
 		}
 	}
 	/* treat an unspecified refresh interval as the minimum */
-	if (!refresh)
+	if (!refresh) {
 		refresh = min_reg_expire;
+	}
 	if (refresh > max_reg_expire) {
-		ast_log(LOG_NOTICE, "Restricting registration for peer '%s' to %d seconds (requested %d)\n",
-			p->name, max_reg_expire, refresh);
+		ast_log(LOG_NOTICE, "Restricting registration for peer '%s' to %d seconds (requested %d)\n", p->name, max_reg_expire, refresh);
 		p->expiry = max_reg_expire;
 	} else if (refresh < min_reg_expire) {
-		ast_log(LOG_NOTICE, "Restricting registration for peer '%s' to %d seconds (requested %d)\n",
-			p->name, min_reg_expire, refresh);
+		ast_log(LOG_NOTICE, "Restricting registration for peer '%s' to %d seconds (requested %d)\n", p->name, min_reg_expire, refresh);
 		p->expiry = min_reg_expire;
 	} else {
 		p->expiry = refresh;
 	}
 	if (p->expiry && sin->sin_addr.s_addr) {
 		p->expire = iax2_sched_add(sched, (p->expiry + 10) * 1000, expire_registry, peer_ref(p));
-		if (p->expire == -1)
+		if (p->expire == -1) {
 			peer_unref(p);
+		}
 	}
 	iax_ie_append_str(&ied, IAX_IE_USERNAME, p->name);
 	iax_ie_append_int(&ied, IAX_IE_DATETIME, iax2_datetime(p->zonetag));
@@ -8757,8 +8777,9 @@
 
 			context = mailbox = ast_strdupa(p->mailbox);
 			strsep(&context, "@");
-			if (ast_strlen_zero(context))
+			if (ast_strlen_zero(context)) {
 				context = "default";
+			}
 
 			event = ast_event_get_cached(AST_EVENT_MWI,
 				AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mailbox,
@@ -8788,8 +8809,9 @@
 		}
 	}
 	version = iax_check_version(devtype);
-	if (version) 
+	if (version) {
 		iax_ie_append_short(&ied, IAX_IE_FIRMWAREVER, version);
+	}
 
 	res = 0;
 
@@ -11168,11 +11190,12 @@
 				}
 				if ((ast_strlen_zero(iaxs[fr->callno]->secret) && ast_strlen_zero(iaxs[fr->callno]->inkeys)) ||
 						ast_test_flag(&iaxs[fr->callno]->state, IAX_STATE_AUTHENTICATED)) {
-
-					if (f.subclass.integer == IAX_COMMAND_REGREL)
+					if (f.subclass.integer == IAX_COMMAND_REGREL) {
 						memset(&sin, 0, sizeof(sin));
-					if (update_registry(&sin, fr->callno, ies.devicetype, fd, ies.refresh))
+					}
+					if (update_registry(&sin, fr->callno, ies.devicetype, fd, ies.refresh)) {
 						ast_log(LOG_WARNING, "Registry error\n");
+					}
 					if (!iaxs[fr->callno]) {
 						break;
 					}
@@ -11893,7 +11916,9 @@
 		return 0;
 	}
 
-	ast_sockaddr_to_sin(&peer->addr, &peer_addr);
+	if (!ast_sockaddr_to_sin(&peer->addr, &peer_addr)) {
+		return -1;
+	}
 
 	/* The peer could change the callno inside iax2_destroy, since we do deadlock avoidance */
 	if ((callno = peer->callno) > 0) {
@@ -11902,11 +11927,13 @@
 		iax2_destroy(callno);
 		ast_mutex_unlock(&iaxsl[callno]);
 	}
-	if (heldcall)
+	if (heldcall) {
 		ast_mutex_unlock(&iaxsl[heldcall]);
+	}
 	callno = peer->callno = find_callno(0, 0, &peer_addr, NEW_FORCE, peer->sockfd, 0);
-	if (heldcall)
+	if (heldcall) {
 		ast_mutex_lock(&iaxsl[heldcall]);
+	}
 	if (peer->callno < 1) {
 		ast_log(LOG_WARNING, "Unable to allocate call for poking peer '%s'\n", peer->name);
 		return -1;
@@ -11925,13 +11952,15 @@
  
 	/* Queue up a new task to handle no reply */
 	/* If the host is already unreachable then use the unreachable interval instead */
-	if (peer->lastms < 0)
+	if (peer->lastms < 0) {
  		peer->pokeexpire = iax2_sched_add(sched, peer->pokefreqnotok, iax2_poke_noanswer, peer_ref(peer));
-	else
+	} else {
  		peer->pokeexpire = iax2_sched_add(sched, DEFAULT_MAXMS * 2, iax2_poke_noanswer, peer_ref(peer));
-
- 	if (peer->pokeexpire == -1)
+	}
+
+ 	if (peer->pokeexpire == -1) {
  		peer_unref(peer);
+	}
 
 	/* And send the poke */
 	ast_mutex_lock(&iaxsl[callno]);
@@ -12284,7 +12313,7 @@
 			ast_copy_flags64(peer, &globalflags, IAX_USEJITTERBUF | IAX_FORCEJITTERBUF | IAX_SENDCONNECTEDLINE | IAX_RECVCONNECTEDLINE | IAX_FORCE_ENCRYPT);
 			peer->encmethods = iax2_encryption;
 			peer->adsi = adsi;
-			ast_string_field_set(peer,secret,"");
+			ast_string_field_set(peer, secret, "");
 			if (!found) {
 				ast_string_field_set(peer, name, name);
 				/*  TODO: Why do we need to set this? */




More information about the asterisk-commits mailing list