[svn-commits] russell: branch group/security_events r227378 - in /team/group/security_event...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Tue Nov 3 14:17:35 CST 2009


Author: russell
Date: Tue Nov  3 14:17:31 2009
New Revision: 227378

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=227378
Log:
resolve, reset

Modified:
    team/group/security_events/   (props changed)
    team/group/security_events/Makefile
    team/group/security_events/apps/app_controlplayback.c
    team/group/security_events/channels/chan_mgcp.c
    team/group/security_events/channels/chan_sip.c
    team/group/security_events/configs/extensions.conf.sample
    team/group/security_events/funcs/func_speex.c
    team/group/security_events/main/Makefile

Propchange: team/group/security_events/
------------------------------------------------------------------------------
    automerge = *

Propchange: team/group/security_events/
------------------------------------------------------------------------------
Binary property 'branch-1.4-merged' - no diff available.

Propchange: team/group/security_events/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Nov  3 14:17:31 2009
@@ -1,1 +1,1 @@
-/trunk:1-227064
+/trunk:1-227377

Modified: team/group/security_events/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/group/security_events/Makefile?view=diff&rev=227378&r1=227377&r2=227378
==============================================================================
--- team/group/security_events/Makefile (original)
+++ team/group/security_events/Makefile Tue Nov  3 14:17:31 2009
@@ -276,7 +276,7 @@
 endif
 
 ifeq ($(OSARCH),SunOS)
-  _ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include -D_XPG4_2
+  _ASTCFLAGS+=-Wcast-align -DSOLARIS -I../include/solaris-compat -I/opt/ssl/include -I/usr/local/ssl/include -D_XPG4_2 -D__EXTENSIONS__
 endif
 
 ASTERISKVERSION:=$(shell GREP=$(GREP) AWK=$(AWK) build_tools/make_version .)
@@ -306,7 +306,7 @@
 ifneq ($(findstring darwin,$(OSARCH)),)
   _ASTCFLAGS+=-D__Darwin__
   SOLINK=-bundle -Xlinker -macosx_version_min -Xlinker 10.4 -Xlinker -undefined -Xlinker dynamic_lookup -force_flat_namespace /usr/lib/bundle1.o
-  _ASTLDFLAGS+= /usr/lib/bundle1.o -L/usr/local/lib
+  _ASTLDFLAGS+=  -L/usr/local/lib
 else
 # These are used for all but Darwin
   SOLINK=-shared

Modified: team/group/security_events/apps/app_controlplayback.c
URL: http://svnview.digium.com/svn/asterisk/team/group/security_events/apps/app_controlplayback.c?view=diff&rev=227378&r1=227377&r2=227378
==============================================================================
--- team/group/security_events/apps/app_controlplayback.c (original)
+++ team/group/security_events/apps/app_controlplayback.c Tue Nov  3 14:17:31 2009
@@ -175,7 +175,7 @@
 		else
 			args.rev = NULL;
 	}
-	ast_log(LOG_WARNING, "args.fwd = %s, args.rew = %s\n", args.fwd, args.rev);
+	ast_debug(1, "Forward key = %s, Rewind key = %s\n", args.fwd, args.rev);
 	if (args.stop && !is_on_phonepad(*args.stop))
 		args.stop = NULL;
 	if (args.pause && !is_on_phonepad(*args.pause))

Modified: team/group/security_events/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/security_events/channels/chan_mgcp.c?view=diff&rev=227378&r1=227377&r2=227378
==============================================================================
--- team/group/security_events/channels/chan_mgcp.c (original)
+++ team/group/security_events/channels/chan_mgcp.c Tue Nov  3 14:17:31 2009
@@ -210,7 +210,8 @@
 AST_MUTEX_DEFINE_STATIC(monlock);
 
 /*! This is the thread for the monitor which checks for input on the channels
-    which are not currently in use. */
+ *  which are not currently in use.
+ */
 static pthread_t monitor_thread = AST_PTHREADT_NULL;
 
 static int restart_monitor(void);
@@ -226,9 +227,10 @@
 
 static struct sched_context *sched;
 static struct io_context *io;
-/*! The private structures of the  mgcp channels are linked for
-  ! selecting outgoing channels */
-   
+/*! The private structures of the mgcp channels are linked for
+ * selecting outgoing channels
+ */
+
 #define MGCP_MAX_HEADERS	64
 #define MGCP_MAX_LINES		64
 
@@ -276,20 +278,20 @@
 #define SUB_ALT  1
 
 struct mgcp_subchannel {
-	/*! subchannel magic string. 
-	   Needed to prove that any subchannel pointer passed by asterisk 
+	/*! subchannel magic string.
+	   Needed to prove that any subchannel pointer passed by asterisk
 	   really points to a valid subchannel memory area.
 	   Ugly.. But serves the purpose for the time being.
 	 */
 #define MGCP_SUBCHANNEL_MAGIC "!978!"
-	char magic[6]; 
+	char magic[6];
 	ast_mutex_t lock;
 	int id;
 	struct ast_channel *owner;
 	struct mgcp_endpoint *parent;
 	struct ast_rtp_instance *rtp;
 	struct sockaddr_in tmpdest;
-	char txident[80]; /*! \todo FIXME txident is replaced by rqnt_ident in endpoint. 
+	char txident[80]; /*! \todo FIXME txident is replaced by rqnt_ident in endpoint.
 			This should be obsoleted */
 	char cxident[80];
 	char callid[80];
@@ -397,7 +399,7 @@
 /* Wildcard endpoint name */
 	char wcardep[30];
 	struct mgcp_message *msgs; /*!< gw msg queue */
-	ast_mutex_t msgs_lock;     /*!< queue lock */  
+	ast_mutex_t msgs_lock;     /*!< queue lock */
 	int retransid;             /*!< retrans timer id */
 	int delme;                 /*!< needed for reload */
 	int realtime;
@@ -425,7 +427,7 @@
 static int transmit_connection_del(struct mgcp_subchannel *sub);
 static int transmit_audit_endpoint(struct mgcp_endpoint *p);
 static void start_rtp(struct mgcp_subchannel *sub);
-static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,  
+static void handle_response(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
                             int result, unsigned int ident, struct mgcp_request *resp);
 static void dump_cmd_queues(struct mgcp_endpoint *p, struct mgcp_subchannel *sub);
 static char *mgcp_reload(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
@@ -467,7 +469,7 @@
 	.send_digit_begin = mgcp_senddigit_begin,
 	.send_digit_end = mgcp_senddigit_end,
 	.bridge = ast_rtp_instance_bridge,
- 	.func_channel_read = acf_channel_read,
+	.func_channel_read = acf_channel_read,
 };
 
 static void mwi_event_cb(const struct ast_event *event, void *userdata)
@@ -526,7 +528,7 @@
 		ast_rtp_instance_destroy(sub->rtp);
 		sub->rtp = NULL;
 	}
-	dump_cmd_queues(NULL, sub); /* SC */
+	dump_cmd_queues(NULL, sub);
 	return 0;
 }
 
@@ -536,7 +538,7 @@
 	int res;
 	if (gw->addr.sin_addr.s_addr)
 		res=sendto(mgcpsock, data, len, 0, (struct sockaddr *)&gw->addr, sizeof(struct sockaddr_in));
-	else 
+	else
 		res=sendto(mgcpsock, data, len, 0, (struct sockaddr *)&gw->defaddr, sizeof(struct sockaddr_in));
 	if (res != len) {
 		ast_log(LOG_WARNING, "mgcp_xmit returned %d: %s\n", res, strerror(errno));
@@ -548,9 +550,7 @@
 {
 	struct mgcp_endpoint *p = sub->parent;
 	int res;
-	if (mgcpdebug) {
-		ast_verbose("Retransmitting:\n%s\n to %s:%d\n", resp->buf, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
-	}
+	ast_debug(1, "Retransmitting:\n%s\n to %s:%d\n", resp->buf, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
 	res = __mgcp_xmit(p->parent, resp->buf, resp->len);
 	if (res > 0)
 		res = 0;
@@ -561,9 +561,7 @@
 {
 	struct mgcp_endpoint *p = sub->parent;
 	int res;
-	if (mgcpdebug) {
-		ast_verbose("Transmitting:\n%s\n to %s:%d\n", req->data, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
-	}
+	ast_debug(1, "Transmitting:\n%s\n to %s:%d\n", req->data, ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
 	res = __mgcp_xmit(p->parent, req->data, req->len);
 	if (res > 0)
 		res = 0;
@@ -576,27 +574,24 @@
 	struct mgcp_message *cur, *q = NULL, *w, *prev;
 
 	ast_mutex_lock(&gw->msgs_lock);
-	prev = NULL, cur = gw->msgs;
-	while (cur) {
+	for (prev = NULL, cur = gw->msgs; cur; prev = cur, cur = cur->next) {
 		if (!p || cur->owner_ep == p) {
-			if (prev)
+			if (prev) {
 				prev->next = cur->next;
-			else
+			} else {
 				gw->msgs = cur->next;
-
-			ast_log(LOG_NOTICE, "Removing message from %s transaction %u\n", 
+			}
+
+			ast_log(LOG_NOTICE, "Removing message from %s transaction %u\n",
 				gw->name, cur->seqno);
 
 			w = cur;
-			cur = cur->next;
 			if (q) {
 				w->next = q;
 			} else {
 				w->next = NULL;
 			}
 			q = w;
-		} else {
-			prev = cur, cur=cur->next;
 		}
 	}
 	ast_mutex_unlock(&gw->msgs_lock);
@@ -610,7 +605,7 @@
 
 static void mgcp_queue_frame(struct mgcp_subchannel *sub, struct ast_frame *f)
 {
-	for(;;) {
+	for (;;) {
 		if (sub->owner) {
 			if (!ast_channel_trylock(sub->owner)) {
 				ast_queue_frame(sub->owner, f);
@@ -619,14 +614,15 @@
 			} else {
 				DEADLOCK_AVOIDANCE(&sub->lock);
 			}
-		} else
+		} else {
 			break;
+		}
 	}
 }
 
 static void mgcp_queue_hangup(struct mgcp_subchannel *sub)
 {
-	for(;;) {
+	for (;;) {
 		if (sub->owner) {
 			if (!ast_channel_trylock(sub->owner)) {
 				ast_queue_hangup(sub->owner);
@@ -635,8 +631,9 @@
 			} else {
 				DEADLOCK_AVOIDANCE(&sub->lock);
 			}
-		} else
+		} else {
 			break;
+		}
 	}
 }
 
@@ -656,18 +653,12 @@
 	/* find out expired msgs */
 	ast_mutex_lock(&gw->msgs_lock);
 
-	prev = NULL, cur = gw->msgs;
-	while (cur) {
+	for (prev = NULL, cur = gw->msgs; cur; prev = cur, cur = cur->next) {
 		if (cur->retrans < MAX_RETRANS) {
 			cur->retrans++;
-			if (mgcpdebug) {
-				ast_verbose("Retransmitting #%d transaction %u on [%s]\n",
-					cur->retrans, cur->seqno, gw->name);
-			}
+			ast_debug(1, "Retransmitting #%d transaction %u on [%s]\n",
+				cur->retrans, cur->seqno, gw->name);
 			__mgcp_xmit(gw, cur->buf, cur->len);
-
-			prev = cur;
-			cur = cur->next;
 		} else {
 			if (prev)
 				prev->next = cur->next;
@@ -678,7 +669,6 @@
 				cur->seqno, gw->name);
 
 			w = cur;
-			cur = cur->next;
 
 			if (exq) {
 				w->next = exq;
@@ -700,7 +690,7 @@
 	while (exq) {
 		cur = exq;
 		/* time-out transaction */
-		handle_response(cur->owner_ep, cur->owner_sub, 406, cur->seqno, NULL); 
+		handle_response(cur->owner_ep, cur->owner_sub, 406, cur->seqno, NULL);
 		exq = exq->next;
 		ast_free(cur);
 	}
@@ -709,31 +699,22 @@
 }
 
 /* modified for the new transaction mechanism */
-static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub, 
+static int mgcp_postrequest(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
                             char *data, int len, unsigned int seqno)
 {
 	struct mgcp_message *msg;
 	struct mgcp_message *cur;
 	struct mgcp_gateway *gw;
- 	struct timeval now;
-
-	msg = ast_malloc(sizeof(*msg) + len);
-	if (!msg) {
+	struct timeval now;
+
+	if (!(msg = ast_malloc(sizeof(*msg) + len))) {
 		return -1;
 	}
-	gw = ((p && p->parent) ? p->parent : NULL);
-	if (!gw) {
+	if (!(gw = ((p && p->parent) ? p->parent : NULL))) {
 		ast_free(msg);
 		return -1;
 	}
-/* SC
-	time(&t);
-	if (gw->messagepending && (gw->lastouttime + 20 < t)) {
-		ast_log(LOG_NOTICE, "Timeout waiting for response to message:%d,  lastouttime: %ld, now: %ld.  Dumping pending queue\n",
-			gw->msgs ? gw->msgs->seqno : -1, (long) gw->lastouttime, (long) t);
-		dump_queue(sub->parent);
-	}
-*/
+
 	msg->owner_sub = sub;
 	msg->owner_ep = p;
 	msg->seqno = seqno;
@@ -743,10 +724,8 @@
 	memcpy(msg->buf, data, msg->len);
 
 	ast_mutex_lock(&gw->msgs_lock);
-	cur = gw->msgs;
+	for (cur = gw->msgs; cur && cur->next; cur = cur->next);
 	if (cur) {
-		while(cur->next)
-			cur = cur->next;
 		cur->next = msg;
 	} else {
 		gw->msgs = msg;
@@ -758,23 +737,13 @@
 	if (gw->retransid == -1)
 		gw->retransid = ast_sched_add(sched, DEFAULT_RETRANS, retrans_pkt, (void *)gw);
 	ast_mutex_unlock(&gw->msgs_lock);
-/* SC
-	if (!gw->messagepending) {
-		gw->messagepending = 1;
-		gw->lastout = seqno;
-		gw->lastouttime = t;
-*/
 	__mgcp_xmit(gw, msg->buf, msg->len);
-		/* XXX Should schedule retransmission XXX */
-/* SC
-	} else
-		ast_debug(1, "Deferring transmission of transaction %d\n", seqno);
-*/
+	/* XXX Should schedule retransmission XXX */
 	return 0;
 }
 
 /* modified for new transport */
-static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub, 
+static int send_request(struct mgcp_endpoint *p, struct mgcp_subchannel *sub,
                         struct mgcp_request *req, unsigned int seqno)
 {
 	int res = 0;
@@ -794,8 +763,8 @@
 			ast_mutex_lock(l);
 			q = sub->cx_queue;
 			/* delete pending cx cmds */
-			/* bugy sb5120 */
-			if(!sub->parent->ncs) {
+			/* buggy sb5120 */
+			if (!sub->parent->ncs) {
 				while (q) {
 					r = q->next;
 					ast_free(q);
@@ -826,8 +795,7 @@
 		}
 	}
 
-	r = ast_malloc(sizeof(*r));
-	if (!r) {
+	if (!(r = ast_malloc(sizeof(*r)))) {
 		ast_log(LOG_WARNING, "Cannot post MGCP request: insufficient memory\n");
 		ast_mutex_unlock(l);
 		return -1;
@@ -835,17 +803,13 @@
 	memcpy(r, req, sizeof(*r));
 
 	if (!(*queue)) {
-		if (mgcpdebug) {
-			ast_verbose("Posting Request:\n%s to %s:%d\n", req->data, 
-				ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
-		}
+		ast_debug(1, "Posting Request:\n%s to %s:%d\n", req->data,
+			ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
 
 		res = mgcp_postrequest(p, sub, req->data, req->len, seqno);
 	} else {
-		if (mgcpdebug) {
-			ast_verbose("Queueing Request:\n%s to %s:%d\n", req->data, 
-				ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
-		}
+		ast_debug(1, "Queueing Request:\n%s to %s:%d\n", req->data,
+			ast_inet_ntoa(p->parent->addr.sin_addr), ntohs(p->parent->addr.sin_port));
 	}
 
 	/* XXX find tail. We could also keep tail in the data struct for faster access */
@@ -872,9 +836,7 @@
 	struct varshead *headp;
 	struct ast_var_t *current;
 
-	if (mgcpdebug) {
-		ast_verb(3, "MGCP mgcp_call(%s)\n", ast->name);
-	}
+	ast_debug(3, "MGCP mgcp_call(%s)\n", ast->name);
 	sub = ast->tech_pvt;
 	p = sub->parent;
 	headp = &ast->varshead;
@@ -890,28 +852,20 @@
 	case MGCP_OFFHOOK:
 		if (!ast_strlen_zero(distinctive_ring)) {
 			snprintf(tone, sizeof(tone), "L/wt%s", distinctive_ring);
-			if (mgcpdebug) {
-				ast_verb(3, "MGCP distinctive callwait %s\n", tone);
-			}
+			ast_debug(3, "MGCP distinctive callwait %s\n", tone);
 		} else {
 			ast_copy_string(tone, (p->ncs ? "L/wt1" : "L/wt"), sizeof(tone));
-			if (mgcpdebug) {
-				ast_verb(3, "MGCP normal callwait %s\n", tone);
-			}
+			ast_debug(3, "MGCP normal callwait %s\n", tone);
 		}
 		break;
 	case MGCP_ONHOOK:
 	default:
 		if (!ast_strlen_zero(distinctive_ring)) {
 			snprintf(tone, sizeof(tone), "L/r%s", distinctive_ring);
-			if (mgcpdebug) {
-				ast_verb(3, "MGCP distinctive ring %s\n", tone);
-			}
+			ast_debug(3, "MGCP distinctive ring %s\n", tone);
 		} else {
 			ast_copy_string(tone, "L/rg", sizeof(tone));
-			if (mgcpdebug) {
-				ast_verb(3, "MGCP default ring\n");
-			}
+			ast_debug(3, "MGCP default ring\n");
 		}
 		break;
 	}
@@ -970,18 +924,15 @@
 		return 0;
 	}
 	ast_mutex_lock(&sub->lock);
-	if (mgcpdebug) {
-		ast_verb(3, "MGCP mgcp_hangup(%s) on %s@%s\n", ast->name, p->name, p->parent->name);
-	}
+	ast_debug(3, "MGCP mgcp_hangup(%s) on %s@%s\n", ast->name, p->name, p->parent->name);
 
 	if ((p->dtmfmode & MGCP_DTMF_INBAND) && p->dsp) {
 		/* check whether other channel is active. */
 		if (!sub->next->owner) {
-			if (p->dtmfmode & MGCP_DTMF_HYBRID)
+			if (p->dtmfmode & MGCP_DTMF_HYBRID) {
 				p->dtmfmode &= ~MGCP_DTMF_INBAND;
-			if (mgcpdebug) {
-				ast_verb(2, "MGCP free dsp on %s@%s\n", p->name, p->parent->name);
-			}
+			}
+			ast_debug(2, "MGCP free dsp on %s@%s\n", p->name, p->parent->name);
 			ast_dsp_free(p->dsp);
 			p->dsp = NULL;
 		}
@@ -1010,7 +961,7 @@
 	if ((sub == p->sub) && sub->next->owner) {
 		if (p->hookstate == MGCP_OFFHOOK) {
 			if (sub->next->owner && ast_bridged_channel(sub->next->owner)) {
-				// ncs fix!
+				/* ncs fix! */
 				transmit_notify_request_with_callerid(p->sub, (p->ncs ? "L/wt1" : "L/wt"), ast_bridged_channel(sub->next->owner)->cid.cid_num, ast_bridged_channel(sub->next->owner)->cid.cid_name);
 			}
 		} else {
@@ -1055,16 +1006,12 @@
 			p->callwaiting = -1;
 		}
 		if (has_voicemail(p)) {
-			if (mgcpdebug) {
-				ast_verb(3, "MGCP mgcp_hangup(%s) on %s@%s set vmwi(+)\n",
-					ast->name, p->name, p->parent->name);
-			}
+			ast_debug(3, "MGCP mgcp_hangup(%s) on %s@%s set vmwi(+)\n",
+				ast->name, p->name, p->parent->name);
 			transmit_notify_request(sub, "L/vmwi(+)");
 		} else {
-			if (mgcpdebug) {
-				ast_verb(3, "MGCP mgcp_hangup(%s) on %s@%s set vmwi(-)\n",
-					ast->name, p->name, p->parent->name);
-			}
+			ast_debug(3, "MGCP mgcp_hangup(%s) on %s@%s set vmwi(-)\n",
+				ast->name, p->name, p->parent->name);
 			transmit_notify_request(sub, "L/vmwi(-)");
 		}
 	}
@@ -1078,7 +1025,6 @@
 	struct mgcp_endpoint *me;
 	int hasendpoints = 0;
 	struct ast_variable * v = NULL;
-	
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -1091,14 +1037,13 @@
 		return NULL;
 	}
 
-	if (a->argc != 3) 
+	if (a->argc != 3) {
 		return CLI_SHOWUSAGE;
+	}
 	ast_mutex_lock(&gatelock);
-	mg = gateways;
-	while(mg) {
-		me = mg->endpoints;
+	for (mg = gateways; mg; mg = mg->next) {
 		ast_cli(a->fd, "Gateway '%s' at %s (%s%s)\n", mg->name, mg->addr.sin_addr.s_addr ? ast_inet_ntoa(mg->addr.sin_addr) : ast_inet_ntoa(mg->defaddr.sin_addr), mg->realtime ? "Realtime, " : "", mg->dynamic ? "Dynamic" : "Static");
-		while(me) {
+		for (me = mg->endpoints; me; me = me->next) {
 			ast_cli(a->fd, "   -- '%s@%s in '%s' is %s\n", me->name, mg->name, me->context, me->sub->owner ? "active" : "idle");
 			if (me->chanvars) {
 				ast_cli(a->fd, "  Variables:\n");
@@ -1107,12 +1052,10 @@
 				}
 			}
 			hasendpoints = 1;
-			me = me->next;
 		}
 		if (!hasendpoints) {
 			ast_cli(a->fd, "   << No Endpoints Defined >>     ");
 		}
-		mg = mg->next;
 	}
 	ast_mutex_unlock(&gatelock);
 	return CLI_SUCCESS;
@@ -1144,37 +1087,33 @@
 		return CLI_SHOWUSAGE;
 	/* split the name into parts by null */
 	ename = ast_strdupa(a->argv[3]);
-	gname = ename;
-	while (*gname) {
+	for (gname = ename; *gname; gname++) {
 		if (*gname == '@') {
 			*gname = 0;
 			gname++;
 			break;
 		}
+	}
+	if (gname[0] == '[') {
 		gname++;
 	}
-	if (gname[0] == '[')
-		gname++;
-	if ((c = strrchr(gname, ']')))
+	if ((c = strrchr(gname, ']'))) {
 		*c = '\0';
+	}
 	ast_mutex_lock(&gatelock);
-	mg = gateways;
-	while(mg) {
+	for (mg = gateways; mg; mg = mg->next) {
 		if (!strcasecmp(mg->name, gname)) {
-			me = mg->endpoints;
-			while(me) {
+			for (me = mg->endpoints; me; me = me->next) {
 				if (!strcasecmp(me->name, ename)) {
 					found = 1;
 					transmit_audit_endpoint(me);
 					break;
 				}
-				me = me->next;
 			}
 			if (found) {
 				break;
 			}
 		}
-		mg = mg->next;
 	}
 	if (!found) {
 		ast_cli(a->fd, "   << Could not find endpoint >>     ");
@@ -1304,9 +1243,9 @@
 	}
 	if (sub) {
 		ast_mutex_lock(&sub->lock);
-		if(!sub->sdpsent && sub->gate) {
-			if(sub->gate->state == GATE_ALLOCATED) {
-				ast_log(LOG_DEBUG, "GATE ALLOCATED, sending sdp\n");
+		if (!sub->sdpsent && sub->gate) {
+			if (sub->gate->state == GATE_ALLOCATED) {
+				ast_debug(1, "GATE ALLOCATED, sending sdp\n");
 				transmit_modify_with_sdp(sub, NULL, 0);
 			}
 		}
@@ -1344,10 +1283,10 @@
 
 	ast_mutex_lock(&sub->lock);
 	if (p->dtmfmode & MGCP_DTMF_INBAND || p->dtmfmode & MGCP_DTMF_HYBRID) {
-		ast_log(LOG_DEBUG, "Sending DTMF using inband/hybrid\n");
+		ast_debug(1, "Sending DTMF using inband/hybrid\n");
 		res = -1; /* Let asterisk play inband indications */
 	} else if (p->dtmfmode & MGCP_DTMF_RFC2833) {
-		ast_log(LOG_DEBUG, "Sending DTMF using RFC2833");
+		ast_debug(1, "Sending DTMF using RFC2833");
 		ast_rtp_instance_dtmf_begin(sub->rtp, digit);
 	} else {
 		ast_log(LOG_ERROR, "Don't know about DTMF_MODE %d\n", p->dtmfmode);
@@ -1366,22 +1305,21 @@
 
 	ast_mutex_lock(&sub->lock);
 	if (p->dtmfmode & MGCP_DTMF_INBAND || p->dtmfmode & MGCP_DTMF_HYBRID) {
-		ast_log(LOG_DEBUG, "Stopping DTMF using inband/hybrid\n");
+		ast_debug(1, "Stopping DTMF using inband/hybrid\n");
 		res = -1; /* Tell Asterisk to stop inband indications */
 	} else if (p->dtmfmode & MGCP_DTMF_RFC2833) {
-
-  		ast_log(LOG_DEBUG, "Stopping DTMF using RFC2833\n");
- 		if (sub->parent->ncs) {
- 			tmp[0] = digit;
- 			tmp[1] = '\0';
- 		} else {
- 			tmp[0] = 'D';
- 			tmp[1] = '/';
- 			tmp[2] = digit;
- 			tmp[3] = '\0';
- 		}
-  		transmit_notify_request(sub, tmp);
-                ast_rtp_instance_dtmf_end(sub->rtp, digit);
+		ast_debug(1, "Stopping DTMF using RFC2833\n");
+		if (sub->parent->ncs) {
+			tmp[0] = digit;
+			tmp[1] = '\0';
+		} else {
+			tmp[0] = 'D';
+			tmp[1] = '/';
+			tmp[2] = digit;
+			tmp[3] = '\0';
+		}
+		transmit_notify_request(sub, tmp);
+		ast_rtp_instance_dtmf_end(sub->rtp, digit);
 	} else {
 		ast_log(LOG_ERROR, "Don't know about DTMF_MODE %d\n", p->dtmfmode);
 	}
@@ -1414,22 +1352,20 @@
 		goto error;
 
 	ast_mutex_lock(&gatelock);
-	g = gateways;
-	while (g) {
+	for (g = gateways; g; g = g->next) {
 		if (strcasecmp(g->name, gw) == 0) {
 			e = g->endpoints;
 			break;
 		}
-		g = g->next;
 	}
 
 	if (!e)
 		goto error;
 
-	while (e) {
-		if (strcasecmp(e->name, endpt) == 0)
+	for (; e; e = e->next) {
+		if (strcasecmp(e->name, endpt) == 0) {
 			break;
-		e = e->next;
+		}
 	}
 
 	if (!e)
@@ -1484,19 +1420,18 @@
 	struct mgcp_subchannel *sub = ast->tech_pvt;
 	int res = 0;
 
-	if (mgcpdebug) {
-		ast_verb(3, "MGCP asked to indicate %d '%s' condition on channel %s\n",
-			ind, control2str(ind), ast->name);
-	}
+	ast_debug(3, "MGCP asked to indicate %d '%s' condition on channel %s\n",
+		ind, control2str(ind), ast->name);
 	ast_mutex_lock(&sub->lock);
 	switch(ind) {
 	case AST_CONTROL_RINGING:
 #ifdef DLINK_BUGGY_FIRMWARE	
 		transmit_notify_request(sub, "rt");
 #else
-		if(!sub->sdpsent) /* will hide the inband progress!!! */
+		if (!sub->sdpsent) { /* will hide the inband progress!!! */
 			transmit_notify_request(sub, sub->parent->ncs ? "L/rt" : "G/rt");
-#endif		
+		}
+#endif
 		break;
 	case AST_CONTROL_BUSY:
 		transmit_notify_request(sub, "L/bz");
@@ -1538,11 +1473,13 @@
 	if (tmp) {
 		tmp->tech = &mgcp_tech;
 		tmp->nativeformats = i->capability;
-		if (!tmp->nativeformats)
+		if (!tmp->nativeformats) {
 			tmp->nativeformats = capability;
+		}
 		fmt = ast_best_codec(tmp->nativeformats);
-		if (sub->rtp)
+		if (sub->rtp) {
 			ast_channel_set_fd(tmp, 0, ast_rtp_instance_fd(sub->rtp, 0));
+		}
 		if (i->dtmfmode & (MGCP_DTMF_INBAND | MGCP_DTMF_HYBRID)) {
 			i->dsp = ast_dsp_new();
 			ast_dsp_set_features(i->dsp, DSP_FEATURE_DIGIT_DETECT);
@@ -1575,9 +1512,10 @@
 		/* Don't use ast_set_callerid() here because it will
 		 * generate a needless NewCallerID event */
 		tmp->cid.cid_ani = ast_strdup(i->cid_num);
-		
-		if (!i->adsi)
+
+		if (!i->adsi) {
 			tmp->adsicpe = AST_ADSI_UNAVAILABLE;
+		}
 		tmp->priority = 1;
 
 		/* Set channel variables for this call from configuration */
@@ -1586,8 +1524,9 @@
 			pbx_builtin_setvar_helper(tmp, v->name, ast_get_encoded_str(v->value, valuebuf, sizeof(valuebuf)));
 		}
 
-		if (sub->rtp)
+		if (sub->rtp) {
 			ast_jb_configure(tmp, &global_jbconf);
+		}
 		if (state != AST_STATE_DOWN) {
 			if (ast_pbx_start(tmp)) {
 				ast_log(LOG_WARNING, "Unable to start PBX on %s\n", tmp->name);
@@ -1603,10 +1542,10 @@
 	return tmp;
 }
 
-static char* get_sdp_by_line(char* line, char *name, int nameLen)
+static char *get_sdp_by_line(char* line, char *name, int nameLen)
 {
 	if (strncasecmp(line, name, nameLen) == 0 && line[nameLen] == '=') {
-		char* r = line + nameLen + 1;
+		char *r = line + nameLen + 1;
 		while (*r && (*r < 33)) ++r;
 		return r;
 	}
@@ -1619,19 +1558,19 @@
 	int len = strlen(name);
 	char *r;
 
-	for (x=0; x<req->lines; x++) {
+	for (x = 0; x < req->lines; x++) {
 		r = get_sdp_by_line(req->line[x], name, len);
 		if (r[0] != '\0') return r;
 	}
 	return "";
 }
 
-static void sdpLineNum_iterator_init(int* iterator)
+static void sdpLineNum_iterator_init(int *iterator)
 {
 	*iterator = 0;
 }
 
-static char* get_sdp_iterate(int* iterator, struct mgcp_request *req, char *name)
+static char *get_sdp_iterate(int* iterator, struct mgcp_request *req, char *name)
 {
 	int len = strlen(name);
 	char *r;
@@ -1647,13 +1586,14 @@
 	int x;
 	int len = strlen(name);
 	char *r;
-	for (x=*start;x<req->headers;x++) {
-		if (!strncasecmp(req->header[x], name, len) && 
+	for (x = *start; x < req->headers; x++) {
+		if (!strncasecmp(req->header[x], name, len) &&
 		    (req->header[x][len] == ':')) {
 			r = req->header[x] + len + 1;
-			while(*r && (*r < 33))
+			while (*r && (*r < 33)) {
 				r++;
-			*start = x+1;
+			}
+			*start = x + 1;
 			return r;
 		}
 	}
@@ -1668,23 +1608,26 @@
 }
 
 /*! \brief get_csv: (SC:) get comma separated value */
-static char *get_csv(char *c, int *len, char **next) 
+static char *get_csv(char *c, int *len, char **next)
 {
 	char *s;
 
 	*next = NULL, *len = 0;
 	if (!c) return NULL;
 
-	while (*c && (*c < 33 || *c == ','))
+	while (*c && (*c < 33 || *c == ',')) {
 		c++;
+	}
 
 	s = c;
-	while (*c && (*c >= 33 && *c != ','))
+	while (*c && (*c >= 33 && *c != ',')) {
 		c++, (*len)++;
+	}
 	*next = c;
 
-	if (*len == 0)
+	if (*len == 0) {
 		s = NULL, *next = NULL;
+	}
 
 	return s;
 }
@@ -1700,45 +1643,40 @@
 	char lines[256];
 	char tmp[4096];
 	int i, j;
-	if(mgcpdebug) ast_verbose ("*** find Realtime MGCPGW\n");
-
-	if (!(i = ast_check_realtime("mgcpgw")) || !(j = ast_check_realtime("mgcpep")))
+
+	ast_debug(1, "*** find Realtime MGCPGW\n");
+
+	if (!(i = ast_check_realtime("mgcpgw")) || !(j = ast_check_realtime("mgcpep"))) {
 		return NULL;
-
-	if(!at || !strlen(at)) {
-		ast_log(LOG_DEBUG, "null gw name\n");
+	}
+
+	if (ast_strlen_zero(at)) {
+		ast_debug(1, "null gw name\n");
 		return NULL;
 	}
 
-	mgcpgwconfig = ast_load_realtime("mgcpgw", "name", at, NULL);
-	if(!mgcpgwconfig)
+	if (!(mgcpgwconfig = ast_load_realtime("mgcpgw", "name", at, NULL))) {
 		return NULL;
+	}
 
 	lines[0] = '\0';
-	gwv = mgcpgwconfig;
-	while (gwv) {
-		if(!strcasecmp(gwv->name, "lines")) {
-			strcpy(lines, gwv->value);
+	for (gwv = mgcpgwconfig; gwv; gwv = gwv->next) {
+		if (!strcasecmp(gwv->name, "lines")) {
+			ast_copy_string(lines, gwv->value, sizeof(lines));
 			break;
 		}
-		gwv = gwv->next;
-	}
-	gwv = mgcpgwconfig;
-	while (gwv->next) {
-		gwv = gwv->next;
-	}
+	}
+	for (gwv = gwv && gwv->next ? gwv : mgcpgwconfig; gwv->next; gwv = gwv->next);
 	if (!ast_strlen_zero(lines)) {
-		c = lines;
-		line = tmp;
-		while(*c) {
+		for (c = lines, line = tmp; *c; c++) {
 			*line = *c;
-			if(*c == ',') {
+			if (*c == ',') {
 					*(line) = 0;
 					mgcpepconfig = ast_load_realtime("mgcpep", "name", at, "line", tmp, NULL);
 					gwv->next = mgcpepconfig;
 
-					while(gwv->next) {
-						if(!strcasecmp(gwv->next->name, "line")) {
+					while (gwv->next) {
+						if (!strcasecmp(gwv->next->name, "line")) {
 							epname = gwv->next;
 							gwv->next = gwv->next->next;
 						} else {
@@ -1746,7 +1684,7 @@
 						}
 					}
 						/* moving the line var to the end */
-					if(epname) {
+					if (epname) {
 						gwv->next = epname;
 						epname->next = NULL;
 						gwv = gwv->next;
@@ -1754,30 +1692,25 @@
 					mgcpepconfig = NULL;
 					line = tmp;
 			} else {
-				line ++;
-			}
-			c++;
-		}
-	}
-	gwv = mgcpgwconfig;
-	while(gwv) {
-		ast_log(LOG_DEBUG, "MGCP Realtime var: %s => %s\n", gwv->name, gwv->value);
-		gwv = gwv->next;
-	}
-
-	if(mgcpgwconfig) { 
+				line++;
+			}
+		}
+	}
+	for (gwv = mgcpgwconfig; gwv; gwv = gwv->next) {
+		ast_debug(1, "MGCP Realtime var: %s => %s\n", gwv->name, gwv->value);
+	}
+
+	if (mgcpgwconfig) {
 		g = build_gateway(at, mgcpgwconfig);
 		ast_variables_destroy(mgcpgwconfig);
 	}
-	if(g) {
+	if (g) {
 		g->next = gateways;
 		g->realtime = 1;
 		gateways = g;
-		e = g->endpoints;
-		while(e) {
+		for (e = g->endpoints; e; e = e->next) {
 			transmit_audit_endpoint(e);
 			e->needaudit = 0;
-			e = e->next;
 		}
 	}
 	return g;
@@ -1804,14 +1737,12 @@
 	if (at && (at[0] == '[')) {
 		at++;
 		c = strrchr(at, ']');
-		if (c)
+		if (c) {
 			*c = '\0';
-	}
-	g = gateways;
-	if(!g)
-		g = find_realtime_gw(name, at, sin);
-	while(g) {
-		if ((!name || !strcasecmp(g->name, at)) && 
+		}
+	}
+	for (g = gateways ? gateways : find_realtime_gw(name, at, sin); g; g = g->next ? g->next : find_realtime_gw(name, at, sin)) {
+		if ((!name || !strcasecmp(g->name, at)) &&
 		    (sin || g->addr.sin_addr.s_addr || g->defaddr.sin_addr.s_addr)) {
 			/* Found the gateway.  If it's dynamic, save it's address -- now for the endpoint */
 			if (sin && g->dynamic && name) {
@@ -1822,17 +1753,15 @@
 						memcpy(&g->ourip, &__ourip, sizeof(g->ourip));
 					ast_verb(3, "Registered MGCP gateway '%s' at %s port %d\n", g->name, ast_inet_ntoa(g->addr.sin_addr), ntohs(g->addr.sin_port));
 				}
-			}
 			/* not dynamic, check if the name matches */
-			else if (name) {
+			} else if (name) {
 				if (strcasecmp(g->name, at)) {
 					g = g->next;
 					continue;
 				}
-			}
 			/* not dynamic, no name, check if the addr matches */
-			else if (!name && sin) {
- 				if ((g->addr.sin_addr.s_addr != sin->sin_addr.s_addr) ||
+			} else if (!name && sin) {
+				if ((g->addr.sin_addr.s_addr != sin->sin_addr.s_addr) ||
 				    (g->addr.sin_port != sin->sin_port)) {
 					if(!g->next)
 						g = find_realtime_gw(name, at, sin);
@@ -1841,67 +1770,37 @@
 					continue;
 				}
 			} else {
-				if(!g->next)
-					g = find_realtime_gw(name, at, sin);
-				else
-					g = g->next;
 				continue;
 			}
-			/* SC */
-			p = g->endpoints;
-			while(p) {
-				ast_debug(1, "Searching on %s@%s for subchannel\n",
-					p->name, g->name);
+			for (p = g->endpoints; p; p = p->next) {
+				ast_debug(1, "Searching on %s@%s for subchannel\n", p->name, g->name);
 				if (msgid) {
-#if 0 /* new transport mech */
-					sub = p->sub;
-					do {
-						ast_debug(1, "Searching on %s@%s-%d for subchannel with lastout: %d\n",
-							p->name, g->name, sub->id, msgid);
-						if (sub->lastout == msgid) {
-							ast_debug(1, "Found subchannel sub%d to handle request %d sub->lastout: %d\n",
-								sub->id, msgid, sub->lastout);
-							found = 1;
-							break;
-						}
-						sub = sub->next;
-					} while (sub != p->sub);
-					if (found) {
-						break;
-					}
-#endif
-					/* SC */
 					sub = p->sub;
 					found = 1;
-					/* SC */
 					break;
 				} else if (name && !strcasecmp(p->name, tmp)) {
-					ast_debug(1, "Coundn't determine subchannel, assuming current master %s@%s-%d\n", 
+					ast_debug(1, "Coundn't determine subchannel, assuming current master %s@%s-%d\n",
 						p->name, g->name, p->sub->id);
 					sub = p->sub;
 					found = 1;
 					break;
 				}
-				p = p->next;
 			}
 			if (sub && found) {
 				ast_mutex_lock(&sub->lock);
 				break;
 			}
 		}
-		if(!g->next)
-			g = find_realtime_gw(name, at, sin);
-		else
-			g = g->next;
 	}
 	ast_mutex_unlock(&gatelock);
 	if (!sub) {
 		if (name) {
-			if (g)
+			if (g) {
 				ast_log(LOG_NOTICE, "Endpoint '%s' not found on gateway '%s'\n", tmp, at);
-			else
+			} else {
 				ast_log(LOG_NOTICE, "Gateway '%s' (and thus its endpoint '%s') does not exist\n", at, tmp);
-		} 
+			}
+		}
 	}
 	return sub;
 }
@@ -1915,13 +1814,11 @@
 
 	/* First header starts immediately */
 	req->header[f] = c;
-	while(*c) {
+	for (; *c; c++) {
 		if (*c == '\n') {
 			/* We've got a new header */
 			*c = 0;
-#if 0
-			printf("Header: %s (%d)\n", req->header[f], strlen(req->header[f]));
-#endif			
+			ast_debug(3, "Header: %s (%d)\n", req->header[f], strlen(req->header[f]));
 			if (ast_strlen_zero(req->header[f])) {
 				/* Line by itself means we're now in content */
 				c++;
@@ -1929,82 +1826,81 @@
 			}
 			if (f >= MGCP_MAX_HEADERS - 1) {
 				ast_log(LOG_WARNING, "Too many MGCP headers...\n");
-			} else
+			} else {
 				f++;
+			}
 			req->header[f] = c + 1;
 		} else if (*c == '\r') {
 			/* Ignore but eliminate \r's */
 			*c = 0;
 		}
-		c++;
 	}
 	/* Check for last header */
-	if (!ast_strlen_zero(req->header[f])) 
+	if (!ast_strlen_zero(req->header[f])) {
 		f++;
+	}
 	req->headers = f;
 	/* Now we process any mime content */
 	f = 0;
 	req->line[f] = c;
-	while(*c) {
+	for (; *c; c++) {
 		if (*c == '\n') {
 			/* We've got a new line */
 			*c = 0;
-#if 0
-			printf("Line: %s (%d)\n", req->line[f], strlen(req->line[f]));
-#endif			
+			ast_debug(3, "Line: %s (%d)\n", req->line[f], strlen(req->line[f]));
 			if (f >= MGCP_MAX_LINES - 1) {
 				ast_log(LOG_WARNING, "Too many SDP lines...\n");
-			} else
+			} else {
 				f++;
+			}
 			req->line[f] = c + 1;
 		} else if (*c == '\r') {
 			/* Ignore and eliminate \r's */
 			*c = 0;
 		}
-		c++;
 	}
 	/* Check for last line */
-	if (!ast_strlen_zero(req->line[f])) 
+	if (!ast_strlen_zero(req->line[f])) {
 		f++;
+	}
 	req->lines = f;
 	/* Parse up the initial header */
 	c = req->header[0];
-	while(*c && *c < 33) c++;
+	while (*c && *c < 33) c++;
 	/* First the verb */
 	req->verb = c;
-	while(*c && (*c > 32)) c++;
+	while (*c && (*c > 32)) c++;
 	if (*c) {
 		*c = '\0';
 		c++;
-		while(*c && (*c < 33)) c++;
+		while (*c && (*c < 33)) c++;
 		req->identifier = c;
-		while(*c && (*c > 32)) c++;
+		while (*c && (*c > 32)) c++;
 		if (*c) {
 			*c = '\0';
 			c++;
-			while(*c && (*c < 33)) c++;
+			while (*c && (*c < 33)) c++;
 			req->endpoint = c;
-			while(*c && (*c > 32)) c++;
+			while (*c && (*c > 32)) c++;
 			if (*c) {
 				*c = '\0';
 				c++;
-				while(*c && (*c < 33)) c++;
+				while (*c && (*c < 33)) c++;
 				req->version = c;
-				while(*c && (*c > 32)) c++;
-				while(*c && (*c < 33)) c++;
-				while(*c && (*c > 32)) c++;
+				while (*c && (*c > 32)) c++;
+				while (*c && (*c < 33)) c++;
+				while (*c && (*c > 32)) c++;
 				*c = '\0';
 			}
 		}
 	}
-		
-	if (mgcpdebug) {
-		ast_verbose("Verb: '%s', Identifier: '%s', Endpoint: '%s', Version: '%s'\n",
+
+	ast_debug(1, "Verb: '%s', Identifier: '%s', Endpoint: '%s', Version: '%s'\n",
 			req->verb, req->identifier, req->endpoint, req->version);
-		ast_verbose("%d headers, %d lines\n", req->headers, req->lines);
-	}
-	if (*c) 
+	ast_debug(1, "%d headers, %d lines\n", req->headers, req->lines);
+	if (*c) {
 		ast_log(LOG_WARNING, "Odd content, extra stuff left over ('%s')\n", c);
+	}
 }
 
 static int process_sdp(struct mgcp_subchannel *sub, struct mgcp_request *req)
@@ -2041,23 +1937,22 @@
 		return -1;
 	}
 	if (sscanf(m, "audio %30d RTP/AVP %n", &portno, &len) != 1) {
-		ast_log(LOG_WARNING, "Unable to determine port number for RTP in '%s'\n", m); 
+		ast_log(LOG_WARNING, "Unable to determine port number for RTP in '%s'\n", m);
 		return -1;
 	}
 	sin.sin_family = AF_INET;
 	memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
 	sin.sin_port = htons(portno);
 	ast_rtp_instance_set_remote_address(sub->rtp, &sin);
-#if 0
-	printf("Peer RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
-#endif	
+	ast_debug(3, "Peer RTP is at port %s:%d\n", ast_inet_ntoa(sin.sin_addr), ntohs(sin.sin_port));
 	/* Scan through the RTP payload types specified in a "m=" line: */
 	ast_rtp_codecs_payloads_clear(ast_rtp_instance_get_codecs(sub->rtp), sub->rtp);
 	codecs = ast_strdupa(m + len);
 	while (!ast_strlen_zero(codecs)) {
 		if (sscanf(codecs, "%30d%n", &codec, &len) != 1) {
-			if (codec_count)
+			if (codec_count) {
 				break;
+			}
 			ast_log(LOG_WARNING, "Error in codec string '%s' at '%s'\n", m, codecs);
 			return -1;
 		}
@@ -2080,12 +1975,10 @@
 	/* Now gather all of the codecs that were asked for: */
 	ast_rtp_codecs_payload_formats(ast_rtp_instance_get_codecs(sub->rtp), &peercapability, &peerNonCodecCapability);
 	p->capability = capability & peercapability;
-	if (mgcpdebug) {
-		ast_verbose("Capabilities: us - %d, them - %d, combined - %d\n",
-			capability, peercapability, p->capability);
-		ast_verbose("Non-codec capabilities: us - %d, them - %d, combined - %d\n",
-			nonCodecCapability, peerNonCodecCapability, p->nonCodecCapability);
-	}
+	ast_debug(1, "Capabilities: us - %d, them - %d, combined - %d\n",
+		capability, peercapability, p->capability);
+	ast_debug(1, "Non-codec capabilities: us - %d, them - %d, combined - %d\n",
+		nonCodecCapability, peerNonCodecCapability, p->nonCodecCapability);
 	if (!p->capability) {
 		ast_log(LOG_WARNING, "No compatible codecs!\n");
 		return -1;
@@ -2106,13 +1999,13 @@
 	req->header[req->headers] = req->data + req->len;
 	snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s: %s\r\n", var, value);
 	req->len += strlen(req->header[req->headers]);
-	if (req->headers < MGCP_MAX_HEADERS)
+	if (req->headers < MGCP_MAX_HEADERS) {
 		req->headers++;
-	else {
+	} else {
 		ast_log(LOG_WARNING, "Out of header space\n");
 		return -1;
 	}
-	return 0;	
+	return 0;
 }
 
 static int add_line(struct mgcp_request *req, char *line)
@@ -2129,13 +2022,13 @@
 	req->line[req->lines] = req->data + req->len;
 	snprintf(req->line[req->lines], sizeof(req->data) - req->len, "%s", line);
 	req->len += strlen(req->line[req->lines]);
-	if (req->lines < MGCP_MAX_LINES)
+	if (req->lines < MGCP_MAX_LINES) {
 		req->lines++;
-	else {
+	} else {
 		ast_log(LOG_WARNING, "Out of line space\n");
 		return -1;
 	}
-	return 0;	
+	return 0;
 }
 
 static int init_resp(struct mgcp_request *req, char *resp, struct mgcp_request *orig, char *resprest)
@@ -2148,10 +2041,11 @@
 	req->header[req->headers] = req->data + req->len;
 	snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %s %s\r\n", resp, orig->identifier, resprest);
 	req->len += strlen(req->header[req->headers]);
-	if (req->headers < MGCP_MAX_HEADERS)
+	if (req->headers < MGCP_MAX_HEADERS) {
 		req->headers++;
-	else
+	} else {
 		ast_log(LOG_WARNING, "Out of header space\n");
+	}
 	return 0;
 }
 
@@ -2164,15 +2058,17 @@
 	}
 	req->header[req->headers] = req->data + req->len;
 	/* check if we need brackets around the gw name */
-	if (p->parent->isnamedottedip)
+	if (p->parent->isnamedottedip) {
 		snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %d %s@[%s] MGCP 1.0%s\r\n", verb, oseq, p->name, p->parent->name, p->ncs ? " NCS 1.0" : "");
-	else
+	} else {
 +		snprintf(req->header[req->headers], sizeof(req->data) - req->len, "%s %d %s@%s MGCP 1.0%s\r\n", verb, oseq, p->name, p->parent->name, p->ncs ? " NCS 1.0" : "");
+	}
 	req->len += strlen(req->header[req->headers]);
-	if (req->headers < MGCP_MAX_HEADERS)
+	if (req->headers < MGCP_MAX_HEADERS) {
 		req->headers++;
-	else
+	} else {
 		ast_log(LOG_WARNING, "Out of header space\n");
+	}
 	return 0;
 }
 
@@ -2188,8 +2084,9 @@
 {
 	memset(req, 0, sizeof(struct mgcp_request));
 	oseq++;
-	if (oseq > 999999999)
+	if (oseq > 999999999) {
 		oseq = 1;
+	}
 	init_req(p, req, verb);
 	return 0;
 }
@@ -2200,21 +2097,23 @@
 	struct mgcp_endpoint *p = sub->parent;
 	struct mgcp_response *mgr;
 
-	if(!sub)
+	if (!sub) {
 		return -1;
+	}
 
 	respprep(&resp, p, msg, req, msgrest);
-	mgr = ast_calloc(1, sizeof(*mgr) + resp.len + 1);
-	if (mgr) {
-		/* Store MGCP response in case we have to retransmit */
-		sscanf(req->identifier, "%30d", &mgr->seqno);
-		time(&mgr->whensent);
-		mgr->len = resp.len;
-		memcpy(mgr->buf, resp.data, resp.len);
-		mgr->buf[resp.len] = '\0';
-		mgr->next = p->parent->responses;
-		p->parent->responses = mgr;
-	}
+	if (!(mgr = ast_calloc(1, sizeof(*mgr) + resp.len + 1))) {
+		return send_response(sub, &resp);
+	}
+	/* Store MGCP response in case we have to retransmit */
+	sscanf(req->identifier, "%30d", &mgr->seqno);
+	time(&mgr->whensent);
+	mgr->len = resp.len;
+	memcpy(mgr->buf, resp.data, resp.len);
+	mgr->buf[resp.len] = '\0';
+	mgr->next = p->parent->responses;
+	p->parent->responses = mgr;
+
 	return send_response(sub, &resp);
 }
 
@@ -2256,9 +2155,7 @@
 			dest.sin_port = sin.sin_port;
 		}
 	}
-	if (mgcpdebug) {
-		ast_verbose("We're at %s port %d\n", ast_inet_ntoa(p->parent->ourip), ntohs(sin.sin_port));
-	}
+	ast_debug(1, "We're at %s port %d\n", ast_inet_ntoa(p->parent->ourip), ntohs(sin.sin_port));

[... 2118 lines stripped ...]



More information about the svn-commits mailing list