[asterisk-commits] russell: branch group/aoc r227384 - in /team/group/aoc: ./ apps/ channels/ co...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Nov 3 14:19:15 CST 2009


Author: russell
Date: Tue Nov  3 14:19:10 2009
New Revision: 227384

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

Added:
    team/group/aoc/configs/res_pktccops.conf.sample
      - copied unchanged from r227372, trunk/configs/res_pktccops.conf.sample
    team/group/aoc/include/asterisk/pktccops.h
      - copied unchanged from r227372, trunk/include/asterisk/pktccops.h
    team/group/aoc/res/res_pktccops.c
      - copied unchanged from r227372, trunk/res/res_pktccops.c
Modified:
    team/group/aoc/   (props changed)
    team/group/aoc/CHANGES
    team/group/aoc/Makefile
    team/group/aoc/apps/app_controlplayback.c
    team/group/aoc/channels/chan_mgcp.c
    team/group/aoc/channels/chan_sip.c
    team/group/aoc/configs/extensions.conf.sample
    team/group/aoc/configs/mgcp.conf.sample
    team/group/aoc/funcs/func_speex.c
    team/group/aoc/main/Makefile

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

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

Propchange: team/group/aoc/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Tue Nov  3 14:19:10 2009
@@ -1,1 +1,1 @@
-/trunk:1-226990
+/trunk:1-227380

Modified: team/group/aoc/CHANGES
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/CHANGES?view=diff&rev=227384&r1=227383&r2=227384
==============================================================================
--- team/group/aoc/CHANGES (original)
+++ team/group/aoc/CHANGES Tue Nov  3 14:19:10 2009
@@ -67,6 +67,8 @@
  * Added ability to preset channel variables on indicated lines with the setvar
    configuration option.  Also, clearvars=all resets the list of variables back
    to none.
+ * PacketCable NCS 1.0 support has been added for Docsis/Eurodocsis Networks.
+   See configs/res_pktccops.conf for more information.
 
 Applications
 ------------

Modified: team/group/aoc/Makefile
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/Makefile?view=diff&rev=227384&r1=227383&r2=227384
==============================================================================
--- team/group/aoc/Makefile (original)
+++ team/group/aoc/Makefile Tue Nov  3 14:19:10 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/aoc/apps/app_controlplayback.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/apps/app_controlplayback.c?view=diff&rev=227384&r1=227383&r2=227384
==============================================================================
--- team/group/aoc/apps/app_controlplayback.c (original)
+++ team/group/aoc/apps/app_controlplayback.c Tue Nov  3 14:19:10 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/aoc/channels/chan_mgcp.c
URL: http://svnview.digium.com/svn/asterisk/team/group/aoc/channels/chan_mgcp.c?view=diff&rev=227384&r1=227383&r2=227384
==============================================================================
--- team/group/aoc/channels/chan_mgcp.c (original)
+++ team/group/aoc/channels/chan_mgcp.c Tue Nov  3 14:19:10 2009
@@ -71,6 +71,7 @@
 #include "asterisk/abstract_jb.h"
 #include "asterisk/event.h"
 #include "asterisk/chanvars.h"
+#include "asterisk/pktccops.h"
 
 /*
  * Define to work around buggy dlink MGCP phone firmware which
@@ -150,6 +151,9 @@
 
 static int dtmfmode = 0;
 static int nat = 0;
+static int ncs = 0;
+static int pktcgatealloc = 0;
+static int hangupongateremove = 0;
 
 static ast_group_t cur_callergroup = 0;
 static ast_group_t cur_pickupgroup = 0;
@@ -206,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);
@@ -222,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
 
@@ -272,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];
@@ -296,6 +302,8 @@
 	int iseq;                      /*!< Not used? RTP? */
 	int outgoing;
 	int alreadygone;
+	int sdpsent;
+	struct cops_gate *gate;
 	struct mgcp_subchannel *next;  /*!< for out circular linked list */
 };
 
@@ -338,6 +346,9 @@
 	int hidecallerid;
 	int dtmfmode;
 	int amaflags;
+	int ncs;
+	int pktcgatealloc;
+	int hangupongateremove;
 	int type;
 	int slowsequence;			/*!< MS: Sequence the endpoint as a whole */
 	int group;
@@ -388,12 +399,13 @@
 /* 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;
 	struct mgcp_response *responses;
 	struct mgcp_gateway *next;
-} *gateways;
+} *gateways = NULL;
 
 AST_MUTEX_DEFINE_STATIC(mgcp_reload_lock);
 static int mgcp_reloading = 0;
@@ -409,12 +421,13 @@
 static int transmit_response(struct mgcp_subchannel *sub, char *msg, struct mgcp_request *req, char *msgrest);
 static int transmit_notify_request(struct mgcp_subchannel *sub, char *tone);
 static int transmit_modify_request(struct mgcp_subchannel *sub);
+static int transmit_connect(struct mgcp_subchannel *sub);
 static int transmit_notify_request_with_callerid(struct mgcp_subchannel *sub, char *tone, char *callernum, char *callername);
 static int transmit_modify_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp, int codecs);
 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);
@@ -431,14 +444,18 @@
 static int mgcp_senddigit_begin(struct ast_channel *ast, char digit);
 static int mgcp_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration);
 static int mgcp_devicestate(void *data);
-static void add_header_offhook(struct mgcp_subchannel *sub, struct mgcp_request *resp);
+static void add_header_offhook(struct mgcp_subchannel *sub, struct mgcp_request *resp, char *tone);
+static int transmit_connect_with_sdp(struct mgcp_subchannel *sub, struct ast_rtp_instance *rtp);
+static struct mgcp_gateway *build_gateway(char *cat, struct ast_variable *v);
+static int mgcp_alloc_pktcgate(struct mgcp_subchannel *sub);
+static int acf_channel_read(struct ast_channel *chan, const char *funcname, char *preparse, char *buf, size_t buflen);
 static struct ast_variable *add_var(const char *buf, struct ast_variable *list);
 static struct ast_variable *copy_vars(struct ast_variable *src);
 
 static const struct ast_channel_tech mgcp_tech = {
 	.type = "MGCP",
 	.description = tdesc,
-	.capabilities = AST_FORMAT_ULAW,
+	.capabilities = AST_FORMAT_ULAW | AST_FORMAT_ALAW,
 	.properties = AST_CHAN_TP_WANTSJITTER | AST_CHAN_TP_CREATESJITTER,
 	.requester = mgcp_request,
 	.devicestate = mgcp_devicestate,
@@ -452,6 +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,
 };
 
 static void mwi_event_cb(const struct ast_event *event, void *userdata)
@@ -510,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;
 }
 
@@ -520,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));
@@ -532,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;
@@ -545,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;
@@ -560,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);
@@ -594,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);
@@ -603,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);
@@ -619,8 +631,9 @@
 			} else {
 				DEADLOCK_AVOIDANCE(&sub->lock);
 			}
-		} else
+		} else {
 			break;
+		}
 	}
 }
 
@@ -640,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;
@@ -662,7 +669,6 @@
 				cur->seqno, gw->name);
 
 			w = cur;
-			cur = cur->next;
 
 			if (exq) {
 				w->next = exq;
@@ -684,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);
 	}
@@ -693,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;
@@ -727,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;
@@ -742,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;
@@ -778,12 +763,15 @@
 			ast_mutex_lock(l);
 			q = sub->cx_queue;
 			/* delete pending cx cmds */
-			while (q) {
-				r = q->next;
-				ast_free(q);
-				q = r;
-			}
-			*queue = NULL;
+			/* buggy sb5120 */
+			if (!sub->parent->ncs) {
+				while (q) {
+					r = q->next;
+					ast_free(q);
+					q = r;
+				}
+				*queue = NULL;
+			}
 			break;
 
 		case MGCP_CMD_CRCX:
@@ -807,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;
@@ -816,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 */
@@ -853,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;
@@ -871,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, "L/wt", sizeof(tone));
-			if (mgcpdebug) {
-				ast_verb(3, "MGCP normal callwait %s\n", tone);
-			}
+			ast_copy_string(tone, (p->ncs ? "L/wt1" : "L/wt"), sizeof(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;
 	}
@@ -906,6 +879,7 @@
 	res = 0;
 	sub->outgoing = 1;
 	sub->cxmode = MGCP_CX_RECVONLY;
+	ast_setstate(ast, AST_STATE_RINGING);
 	if (p->type == TYPE_LINE) {
 		if (!sub->rtp) {
 			start_rtp(sub);
@@ -932,7 +906,6 @@
 		res = -1;
 	}
 	ast_mutex_unlock(&sub->lock);
-	ast_queue_control(ast, AST_CONTROL_RINGING);
 	return res;
 }
 
@@ -951,24 +924,36 @@
 		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;
 		}
 	}
 
 	sub->owner = NULL;
+
+	/* for deleting gate */
+	if (p->pktcgatealloc && sub->gate) {
+		sub->gate->gate_open = NULL;
+		sub->gate->gate_remove = NULL;
+		sub->gate->got_dq_gi = NULL;
+		sub->gate->tech_pvt = NULL;
+		if (sub->gate->state == GATE_ALLOC_PROGRESS || sub->gate->state == GATE_ALLOCATED) {
+			ast_pktccops_gate_alloc(GATE_DEL, sub->gate, 0, 0, 0, 0, 0, 0, NULL, NULL);
+		} else {
+			sub->gate->deltimer = time(NULL) + 5;
+		}
+		sub->gate = NULL;
+	}
+
 	if (!ast_strlen_zero(sub->cxident)) {
 		transmit_connection_del(sub);
 	}
@@ -976,7 +961,8 @@
 	if ((sub == p->sub) && sub->next->owner) {
 		if (p->hookstate == MGCP_OFFHOOK) {
 			if (sub->next->owner && ast_bridged_channel(sub->next->owner)) {
-				transmit_notify_request_with_callerid(p->sub, "L/wt", ast_bridged_channel(sub->next->owner)->cid.cid_num, ast_bridged_channel(sub->next->owner)->cid.cid_name);
+				/* 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 {
 			/* set our other connection as the primary and swith over to it */
@@ -989,7 +975,7 @@
 		}
 
 	} else if ((sub == p->sub->next) && p->hookstate == MGCP_OFFHOOK) {
-		transmit_notify_request(sub, "L/v");
+		transmit_notify_request(sub, p->ncs ? "" : "L/v");
 	} else if (p->hookstate == MGCP_OFFHOOK) {
 		transmit_notify_request(sub, "L/ro");
 	} else {
@@ -1020,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(-)");
 		}
 	}
@@ -1043,7 +1025,6 @@
 	struct mgcp_endpoint *me;
 	int hasendpoints = 0;
 	struct ast_variable * v = NULL;
-	
 
 	switch (cmd) {
 	case CLI_INIT:
@@ -1056,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;
-		ast_cli(a->fd, "Gateway '%s' at %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->dynamic ? "Dynamic" : "Static");
-		while(me) {
+	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");
+		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");
@@ -1072,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;
@@ -1109,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 >>     ");
@@ -1264,11 +1238,17 @@
 		if (!(frame->subclass & ast->nativeformats)) {
 			ast_log(LOG_WARNING, "Asked to transmit frame type %d, while native formats is %d (read/write = %d/%d)\n",
 				frame->subclass, ast->nativeformats, ast->readformat, ast->writeformat);
-			return -1;
+			/* return -1; */
 		}
 	}
 	if (sub) {
 		ast_mutex_lock(&sub->lock);
+		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);
+			}
+		}
 		if ((sub->parent->sub == sub) || !sub->parent->singlepath) {
 			if (sub->rtp) {
 				res =  ast_rtp_instance_write(sub->rtp, frame);
@@ -1303,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);
@@ -1325,16 +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");
-		tmp[0] = 'D';
-		tmp[1] = '/';
-		tmp[2] = digit;
-		tmp[3] = '\0';
+		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);
+		ast_rtp_instance_dtmf_end(sub->rtp, digit);
 	} else {
 		ast_log(LOG_ERROR, "Don't know about DTMF_MODE %d\n", p->dtmfmode);
 	}
@@ -1367,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)
@@ -1437,24 +1420,24 @@
 	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
-		transmit_notify_request(sub, "G/rt");
-#endif		
+		if (!sub->sdpsent) { /* will hide the inband progress!!! */
+			transmit_notify_request(sub, sub->parent->ncs ? "L/rt" : "G/rt");
+		}
+#endif
 		break;
 	case AST_CONTROL_BUSY:
 		transmit_notify_request(sub, "L/bz");
 		break;
 	case AST_CONTROL_CONGESTION:
-		transmit_notify_request(sub, "G/cg");
+		transmit_notify_request(sub, sub->parent->ncs ? "L/cg" : "G/cg");
 		break;
 	case AST_CONTROL_HOLD:
 		ast_moh_start(ast, data, NULL);
@@ -1467,6 +1450,9 @@
 		break;
 	case AST_CONTROL_AOC:
 		break;
+	case AST_CONTROL_PROGRESS:
+	case AST_CONTROL_PROCEEDING:
+		transmit_modify_request(sub);
 	case -1:
 		transmit_notify_request(sub, "");
 		break;
@@ -1489,11 +1475,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);
@@ -1526,9 +1514,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 */
@@ -1537,8 +1526,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);
@@ -1554,10 +1544,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;
 	}
@@ -1570,19 +1560,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;
@@ -1593,51 +1583,139 @@
 	return "";
 }
 
-static char *__get_header(struct mgcp_request *req, char *name, int *start)
+static char *__get_header(struct mgcp_request *req, char *name, int *start, char *def)
 {
 	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;
 		}
 	}
 	/* Don't return NULL, so get_header is always a valid pointer */
-	return "";
+	return def;
 }
 
 static char *get_header(struct mgcp_request *req, char *name)
 {
 	int start = 0;
-	return __get_header(req, name, &start);
+	return __get_header(req, name, &start, "");
 }
 
 /*! \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;
+}
+
+static struct mgcp_gateway *find_realtime_gw(char *name, char *at, struct sockaddr_in *sin)
+{
+	struct mgcp_gateway *g = NULL;
+	struct ast_variable *mgcpgwconfig = NULL;
+	struct ast_variable *mgcpepconfig = NULL;
+	struct ast_variable *gwv, *epname = NULL;
+	struct mgcp_endpoint *e;
+	char *c = NULL, *line;
+	char lines[256];
+	char tmp[4096];
+	int i, j;
+
+	ast_debug(1, "*** find Realtime MGCPGW\n");
+
+	if (!(i = ast_check_realtime("mgcpgw")) || !(j = ast_check_realtime("mgcpep"))) {
+		return NULL;
+	}
+
+	if (ast_strlen_zero(at)) {
+		ast_debug(1, "null gw name\n");
+		return NULL;
+	}
+
+	if (!(mgcpgwconfig = ast_load_realtime("mgcpgw", "name", at, NULL))) {
+		return NULL;
+	}
+
+	lines[0] = '\0';
+	for (gwv = mgcpgwconfig; gwv; gwv = gwv->next) {
+		if (!strcasecmp(gwv->name, "lines")) {
+			ast_copy_string(lines, gwv->value, sizeof(lines));
+			break;
+		}
+	}
+	for (gwv = gwv && gwv->next ? gwv : mgcpgwconfig; gwv->next; gwv = gwv->next);
+	if (!ast_strlen_zero(lines)) {
+		for (c = lines, line = tmp; *c; c++) {
+			*line = *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")) {
+							epname = gwv->next;
+							gwv->next = gwv->next->next;
+						} else {
+							gwv = gwv->next;
+						}
+					}
+						/* moving the line var to the end */
+					if (epname) {
+						gwv->next = epname;
+						epname->next = NULL;
+						gwv = gwv->next;
+					}
+					mgcpepconfig = NULL;
+					line = tmp;
+			} else {
+				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) {
+		g->next = gateways;
+		g->realtime = 1;
+		gateways = g;
+		for (e = g->endpoints; e; e = e->next) {
+			transmit_audit_endpoint(e);
+			e->needaudit = 0;
+		}
+	}
+	return g;
 }
 
 static struct mgcp_subchannel *find_subchannel_and_lock(char *name, int msgid, struct sockaddr_in *sin)
@@ -1661,12 +1739,12 @@
 	if (at && (at[0] == '[')) {
 		at++;
 		c = strrchr(at, ']');
-		if (c)
+		if (c) {
 			*c = '\0';
-	}
-	g = gateways;
-	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) {
@@ -1677,77 +1755,54 @@
 						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)) {
-					g = g->next;
+					if(!g->next)
+						g = find_realtime_gw(name, at, sin);
+					else
+						g = g->next;
 					continue;
 				}
 			} 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;
 			}
 		}
-		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;
 }
@@ -1761,13 +1816,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++;
@@ -1775,82 +1828,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);
+	}
 }
 

[... 2453 lines stripped ...]



More information about the asterisk-commits mailing list