[asterisk-commits] trunk r14953 - in /trunk: ./ apps/ channels/ configs/ include/asterisk/ res/

asterisk-commits at lists.digium.com asterisk-commits at lists.digium.com
Sat Mar 25 16:50:14 MST 2006


Author: markster
Date: Sat Mar 25 17:50:09 2006
New Revision: 14953

URL: http://svn.digium.com/view/asterisk?rev=14953&view=rev
Log:
Add micro-http server and abstract manager interface, make snmp not die 
on reload.

Added:
    trunk/configs/http.conf.sample   (with props)
    trunk/http.c   (with props)
    trunk/include/asterisk/http.h   (with props)
Modified:
    trunk/Makefile
    trunk/apps/app_queue.c
    trunk/asterisk.c
    trunk/channels/chan_agent.c
    trunk/channels/chan_iax2.c
    trunk/channels/chan_sip.c
    trunk/channels/chan_zap.c
    trunk/db.c
    trunk/include/asterisk/manager.h
    trunk/loader.c
    trunk/manager.c
    trunk/res/res_features.c
    trunk/res/res_snmp.c

Modified: trunk/Makefile
URL: http://svn.digium.com/view/asterisk/trunk/Makefile?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/Makefile (original)
+++ trunk/Makefile Sat Mar 25 17:50:09 2006
@@ -364,7 +364,7 @@
 	astmm.o enum.o srv.o dns.o aescrypt.o aestab.o aeskey.o \
 	utils.o plc.o jitterbuf.o dnsmgr.o devicestate.o \
 	netsock.o slinfactory.o ast_expr2.o ast_expr2f.o \
-	cryptostub.o sha1.o
+	cryptostub.o sha1.o http.o
 
 # we need to link in the objects statically, not as a library, because
 # otherwise modules will not have them available if none of the static

Modified: trunk/apps/app_queue.c
URL: http://svn.digium.com/view/asterisk/trunk/apps/app_queue.c?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/apps/app_queue.c (original)
+++ trunk/apps/app_queue.c Sat Mar 25 17:50:09 2006
@@ -3357,7 +3357,7 @@
 	AST_LIST_UNLOCK(&queues);
 }
 
-static int __queues_show(int manager, int fd, int argc, char **argv, int queue_show)
+static int __queues_show(struct mansession *s, int manager, int fd, int argc, char **argv, int queue_show)
 {
 	struct ast_call_queue *q;
 	struct queue_ent *qe;
@@ -3381,10 +3381,17 @@
 	AST_LIST_LOCK(&queues);
 	if (AST_LIST_EMPTY(&queues)) {
 		AST_LIST_UNLOCK(&queues);
-		if (queue_show)
-			ast_cli(fd, "No such queue: %s.%s",argv[2], term);
-		else
-			ast_cli(fd, "No queues.%s", term);
+		if (queue_show) {
+			if (s)
+				astman_append(s, "No such queue: %s.%s",argv[2], term);
+			else
+				ast_cli(fd, "No such queue: %s.%s",argv[2], term);
+		} else {
+			if (s)
+				astman_append(s, "No queues.%s", term);
+			else
+				ast_cli(fd, "No queues.%s", term);
+		}
 		return RESULT_SUCCESS;
 	}
 	AST_LIST_TRAVERSE(&queues, q, list) {
@@ -3409,10 +3416,17 @@
 		sl = 0;
 		if(q->callscompleted > 0)
 			sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
-		ast_cli(fd, "%-12.12s has %d calls (max %s) in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds%s",
-			q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel, term);
+		if (s)
+			astman_append(s, "%-12.12s has %d calls (max %s) in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds%s",
+				q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel, term);
+		else
+			ast_cli(fd, "%-12.12s has %d calls (max %s) in '%s' strategy (%ds holdtime), W:%d, C:%d, A:%d, SL:%2.1f%% within %ds%s",
+				q->name, q->count, max_buf, int2strat(q->strategy), q->holdtime, q->weight, q->callscompleted, q->callsabandoned,sl,q->servicelevel, term);
 		if (q->members) {
-			ast_cli(fd, "   Members: %s", term);
+			if (s)
+				astman_append(s, "   Members: %s", term);
+			else
+				ast_cli(fd, "   Members: %s", term);
 			for (mem = q->members; mem; mem = mem->next) {
 				max_buf[0] = '\0';
 				max = max_buf;
@@ -3429,19 +3443,37 @@
 							 mem->calls, (long)(time(NULL) - mem->lastcall));
 				} else
 					ast_build_string(&max, &max_left, " has taken no calls yet");
-				ast_cli(fd, "      %s%s%s", mem->interface, max_buf, term);
-			}
-		} else
+				if (s)
+					astman_append(s, "      %s%s%s", mem->interface, max_buf, term);
+				else
+					ast_cli(fd, "      %s%s%s", mem->interface, max_buf, term);
+			}
+		} else if (s)
+			astman_append(s, "   No Members%s", term);
+		else	
 			ast_cli(fd, "   No Members%s", term);
 		if (q->head) {
 			pos = 1;
-			ast_cli(fd, "   Callers: %s", term);
-			for (qe = q->head; qe; qe = qe->next) 
-				ast_cli(fd, "      %d. %s (wait: %ld:%2.2ld, prio: %d)%s", pos++, qe->chan->name,
-					(long)(now - qe->start) / 60, (long)(now - qe->start) % 60, qe->prio, term);
-		} else
+			if (s)
+				astman_append(s, "   Callers: %s", term);
+			else
+				ast_cli(fd, "   Callers: %s", term);
+			for (qe = q->head; qe; qe = qe->next) {
+				if (s)
+					astman_append(s, "      %d. %s (wait: %ld:%2.2ld, prio: %d)%s", pos++, qe->chan->name,
+						(long)(now - qe->start) / 60, (long)(now - qe->start) % 60, qe->prio, term);
+				else
+					ast_cli(fd, "      %d. %s (wait: %ld:%2.2ld, prio: %d)%s", pos++, qe->chan->name,
+						(long)(now - qe->start) / 60, (long)(now - qe->start) % 60, qe->prio, term);
+			}
+		} else if (s)
+			astman_append(s, "   No Callers%s", term);
+		else
 			ast_cli(fd, "   No Callers%s", term);
-		ast_cli(fd, "%s", term);
+		if (s)
+			astman_append(s, "%s", term);
+		else
+			ast_cli(fd, "%s", term);
 		ast_mutex_unlock(&q->lock);
 		if (queue_show)
 			break;
@@ -3452,12 +3484,12 @@
 
 static int queues_show(int fd, int argc, char **argv)
 {
-	return __queues_show(0, fd, argc, argv, 0);
+	return __queues_show(NULL, 0, fd, argc, argv, 0);
 }
 
 static int queue_show(int fd, int argc, char **argv)
 {
-	return __queues_show(0, fd, argc, argv, 1);
+	return __queues_show(NULL, 0, fd, argc, argv, 1);
 }
 
 static char *complete_queue(const char *line, const char *word, int pos, int state)
@@ -3485,8 +3517,8 @@
 static int manager_queues_show( struct mansession *s, struct message *m )
 {
 	char *a[] = { "show", "queues" };
-	__queues_show(1, s->fd, 2, a, 0);
-	ast_cli(s->fd, "\r\n\r\n");	/* Properly terminate Manager output */
+	__queues_show(s, 1, -1, 2, a, 0);
+	astman_append(s, "\r\n\r\n");	/* Properly terminate Manager output */
 
 	return RESULT_SUCCESS;
 } 
@@ -3518,7 +3550,7 @@
 		if (ast_strlen_zero(queuefilter) || !strcmp(q->name, queuefilter)) {
 			if(q->callscompleted > 0)
 				sl = 100*((float)q->callscompletedinsl/(float)q->callscompleted);
-			ast_cli(s->fd, "Event: QueueParams\r\n"
+			astman_append(s, "Event: QueueParams\r\n"
 						"Queue: %s\r\n"
 						"Max: %d\r\n"
 						"Calls: %d\r\n"
@@ -3535,7 +3567,7 @@
 			/* List Queue Members */
 			for (mem = q->members; mem; mem = mem->next) {
 				if (ast_strlen_zero(memberfilter) || !strcmp(mem->interface, memberfilter)) {
-					ast_cli(s->fd, "Event: QueueMember\r\n"
+					astman_append(s, "Event: QueueMember\r\n"
 						"Queue: %s\r\n"
 						"Location: %s\r\n"
 						"Membership: %s\r\n"
@@ -3553,7 +3585,7 @@
 			/* List Queue Entries */
 			pos = 1;
 			for (qe = q->head; qe; qe = qe->next) {
-				ast_cli(s->fd, "Event: QueueEntry\r\n"
+				astman_append(s, "Event: QueueEntry\r\n"
 					"Queue: %s\r\n"
 					"Position: %d\r\n"
 					"Channel: %s\r\n"
@@ -3572,7 +3604,7 @@
 	}
 	AST_LIST_UNLOCK(&queues);
 
-	ast_cli(s->fd,
+	astman_append(s,
 		"Event: QueueStatusComplete\r\n"
 		"%s"
 		"\r\n",idText);

Modified: trunk/asterisk.c
URL: http://svn.digium.com/view/asterisk/trunk/asterisk.c?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/asterisk.c (original)
+++ trunk/asterisk.c Sat Mar 25 17:50:09 2006
@@ -107,6 +107,7 @@
 #include "asterisk/pbx.h"
 #include "asterisk/enum.h"
 #include "asterisk/rtp.h"
+#include "asterisk/http.h"
 #if defined(T38_SUPPORT)
 #include "asterisk/udptl.h"
 #endif
@@ -1847,7 +1848,8 @@
 	return 0;
 }
 
-static void ast_readconfig(void) {
+static void ast_readconfig(void) 
+{
 	struct ast_config *cfg;
 	struct ast_variable *v;
 	char *config = AST_CONFIG_FILE;
@@ -2321,6 +2323,7 @@
 		printf(term_quit());
 		exit(1);
 	}
+	ast_http_init();
 	ast_channels_init();
 	if (init_manager()) {
 		printf(term_quit());

Modified: trunk/channels/chan_agent.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_agent.c?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/channels/chan_agent.c (original)
+++ trunk/channels/chan_agent.c Sat Mar 25 17:50:09 2006
@@ -1411,7 +1411,7 @@
 			status = "AGENT_LOGGEDOFF";
 		}
 
-		ast_cli(s->fd, "Event: Agents\r\n"
+		astman_append(s, "Event: Agents\r\n"
 			"Agent: %s\r\n"
 			"Name: %s\r\n"
 			"Status: %s\r\n"
@@ -1424,7 +1424,7 @@
 		ast_mutex_unlock(&p->lock);
 	}
 	AST_LIST_UNLOCK(&agents);
-	ast_cli(s->fd, "Event: AgentsComplete\r\n"
+	astman_append(s, "Event: AgentsComplete\r\n"
 		"%s"
 		"\r\n",idText);
 	return 0;

Modified: trunk/channels/chan_iax2.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_iax2.c?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/channels/chan_iax2.c (original)
+++ trunk/channels/chan_iax2.c Sat Mar 25 17:50:09 2006
@@ -673,7 +673,7 @@
 static struct iax2_peer *realtime_peer(const char *peername, struct sockaddr_in *sin);
 
 static void destroy_peer(struct iax2_peer *peer);
-static int ast_cli_netstats(int fd, int limit_fmt);
+static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt);
 
 #define IAX_IOSTATE_IDLE		0
 #define IAX_IOSTATE_READY		1
@@ -4324,7 +4324,7 @@
 #undef FORMAT2
 }
 
-static int __iax2_show_peers(int manager, int fd, int argc, char *argv[])
+static int __iax2_show_peers(int manager, int fd, struct mansession *s, int argc, char *argv[])
 {
 	regex_t regexbuf;
 	int havepattern = 0;
@@ -4376,7 +4376,10 @@
 	}
 
 	ast_mutex_lock(&peerl.lock);
-	ast_cli(fd, FORMAT2, "Name/Username", "Host", "   ", "Mask", "Port", "   ", "Status", term);
+	if (s)
+		astman_append(s, FORMAT2, "Name/Username", "Host", "   ", "Mask", "Port", "   ", "Status", term);
+	else
+		ast_cli(fd, FORMAT2, "Name/Username", "Host", "   ", "Mask", "Port", "   ", "Status", term);
 	for (peer = peerl.peers;peer;peer = peer->next) {
 		char nm[20];
 		char status[20];
@@ -4410,7 +4413,15 @@
 					ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : "   ",
 					peer->encmethods ? "(E)" : "   ", status, term);
 
-		ast_cli(fd, FORMAT, name, 
+		if (s)
+			astman_append(s, FORMAT, name, 
+					peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
+					ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
+					nm,
+					ntohs(peer->addr.sin_port), ast_test_flag(peer, IAX_TRUNK) ? "(T)" : "   ",
+					peer->encmethods ? "(E)" : "   ", status, term);
+		else
+			ast_cli(fd, FORMAT, name, 
 					peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "(Unspecified)",
 					ast_test_flag(peer, IAX_DYNAMIC) ? "(D)" : "(S)",
 					nm,
@@ -4420,7 +4431,10 @@
 	}
 	ast_mutex_unlock(&peerl.lock);
 
-	ast_cli(fd,"%d iax2 peers [%d online, %d offline, %d unmonitored]%s", total_peers, online_peers, offline_peers, unmonitored_peers, term);
+	if (s)
+		astman_append(s,"%d iax2 peers [%d online, %d offline, %d unmonitored]%s", total_peers, online_peers, offline_peers, unmonitored_peers, term);
+	else
+		ast_cli(fd,"%d iax2 peers [%d online, %d offline, %d unmonitored]%s", total_peers, online_peers, offline_peers, unmonitored_peers, term);
 
 	if (havepattern)
 		regfree(&regexbuf);
@@ -4473,12 +4487,12 @@
 
 static int iax2_show_peers(int fd, int argc, char *argv[])
 {
-	return __iax2_show_peers(0, fd, argc, argv);
+	return __iax2_show_peers(0, fd, NULL, argc, argv);
 }
 static int manager_iax2_show_netstats( struct mansession *s, struct message *m )
 {
-	ast_cli_netstats(s->fd, 0);
-	ast_cli(s->fd, "\r\n");
+	ast_cli_netstats(s, -1, 0);
+	astman_append(s, "\r\n");
 	return RESULT_SUCCESS;
 }
 
@@ -4515,9 +4529,9 @@
 	char *id;
 	id = astman_get_header(m,"ActionID");
 	if (!ast_strlen_zero(id))
-		ast_cli(s->fd, "ActionID: %s\r\n",id);
-	ret = __iax2_show_peers(1, s->fd, 3, a );
-	ast_cli(s->fd, "\r\n\r\n" );
+		astman_append(s, "ActionID: %s\r\n",id);
+	ret = __iax2_show_peers(1, -1, s, 3, a );
+	astman_append(s, "\r\n\r\n" );
 	return ret;
 } /* /JDG */
 
@@ -4651,7 +4665,7 @@
 #undef FORMATB
 }
 
-static int ast_cli_netstats(int fd, int limit_fmt)
+static int ast_cli_netstats(struct mansession *s, int fd, int limit_fmt)
 {
 	int x;
 	int numchans = 0;
@@ -4660,13 +4674,21 @@
 		if (iaxs[x]) {
 #ifdef BRIDGE_OPTIMIZATION
 			if (iaxs[x]->bridgecallno) {
-				if (limit_fmt)	
-					ast_cli(fd, "%-25.25s <NATIVE BRIDGED>",
-						iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
-				else
-					ast_cli(fd, "%s <NATIVE BRIDGED>",
-						iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
-                        } else
+				if (limit_fmt)	 {
+					if (s)
+						astman_append(s, "%-25.25s <NATIVE BRIDGED>",
+							iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
+					else
+						ast_cli(fd, "%-25.25s <NATIVE BRIDGED>",
+							iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
+			 	} else {
+					if (s)
+						astman_append(s, "%s <NATIVE BRIDGED>",
+							iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
+					else
+						ast_cli(fd, "%s <NATIVE BRIDGED>",
+							iaxs[x]->owner ? iaxs[x]->owner->name : "(None)");
+				} else
 #endif
 			{
 				int localjitter, localdelay, locallost, locallosspct, localdropped, localooo;
@@ -4705,7 +4727,27 @@
 					fmt = "%-25.25s %4d %4d %4d %5d %3d %5d %4d %6d %4d %4d %5d %3d %5d %4d %6d\n";
 				else
 					fmt = "%s %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d\n";
-				ast_cli(fd, fmt,
+				if (s)
+				
+					astman_append(s, fmt,
+						iaxs[x]->owner ? iaxs[x]->owner->name : "(None)",
+						iaxs[x]->pingtime,
+						localjitter, 
+						localdelay,
+						locallost,
+						locallosspct,
+						localdropped,
+						localooo,
+						iaxs[x]->frames_received/1000,
+						iaxs[x]->remote_rr.jitter,
+						iaxs[x]->remote_rr.delay,
+						iaxs[x]->remote_rr.losscnt,
+						iaxs[x]->remote_rr.losspct,
+						iaxs[x]->remote_rr.dropped,
+						iaxs[x]->remote_rr.ooo,
+						iaxs[x]->remote_rr.packets/1000);
+				else
+					ast_cli(fd, fmt,
 						iaxs[x]->owner ? iaxs[x]->owner->name : "(None)",
 						iaxs[x]->pingtime,
 						localjitter, 
@@ -4738,7 +4780,7 @@
 		return RESULT_SHOWUSAGE;
 	ast_cli(fd, "                                -------- LOCAL ---------------------  -------- REMOTE --------------------\n");
 	ast_cli(fd, "Channel                    RTT  Jit  Del  Lost   %%  Drop  OOO  Kpkts  Jit  Del  Lost   %%  Drop  OOO  Kpkts\n");
-	numchans = ast_cli_netstats(fd, 1);
+	numchans = ast_cli_netstats(NULL, fd, 1);
 	ast_cli(fd, "%d active IAX channel%s\n", numchans, (numchans != 1) ? "s" : "");
 	return RESULT_SUCCESS;
 }

Modified: trunk/channels/chan_sip.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_sip.c?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/channels/chan_sip.c (original)
+++ trunk/channels/chan_sip.c Sat Mar 25 17:50:09 2006
@@ -7600,9 +7600,9 @@
 
 	astman_send_ack(s, m, "Peer status list will follow");
 	/* List the peers in separate manager events */
-	_sip_show_peers(s->fd, &total, s, m, 3, a);
+	_sip_show_peers(-1, &total, s, m, 3, a);
 	/* Send final confirmation */
-	ast_cli(s->fd,
+	astman_append(s,
 	"Event: PeerlistComplete\r\n"
 	"ListItems: %d\r\n"
 	"%s"
@@ -7712,7 +7712,7 @@
 			realtimepeers ? (ast_test_flag(iterator, SIP_REALTIME) ? "Cached RT":"") : "");
 		} else {	/* Manager format */
 			/* The names here need to be the same as other channels */
-			ast_cli(fd, 
+			astman_append(s, 
 			"Event: PeerEntry\r\n%s"
 			"Channeltype: SIP\r\n"
 			"ObjectName: %s\r\n"
@@ -8031,9 +8031,9 @@
 	a[3] = peer;
 
 	if (!ast_strlen_zero(id))
-		ast_cli(s->fd, "ActionID: %s\r\n",id);
-	ret = _sip_show_peer(1, s->fd, s, m, 4, a );
-	ast_cli( s->fd, "\r\n\r\n" );
+		astman_append(s, "ActionID: %s\r\n",id);
+	ret = _sip_show_peer(1, -1, s, m, 4, a );
+	astman_append(s, "\r\n\r\n" );
 	return ret;
 }
 
@@ -8067,7 +8067,7 @@
 	peer = find_peer(argv[3], NULL, load_realtime);
 	if (s) { 	/* Manager */
 		if (peer)
-			ast_cli(s->fd, "Response: Success\r\n");
+			astman_append(s, "Response: Success\r\n");
 		else {
 			snprintf (cbuf, sizeof(cbuf), "Peer %s not found.\n", argv[3]);
 			astman_send_error(s, m, cbuf);
@@ -8161,73 +8161,73 @@
 	} else  if (peer && type == 1) { /* manager listing */
 		char *actionid = astman_get_header(m,"ActionID");
 
-		ast_cli(fd, "Channeltype: SIP\r\n");
+		astman_append(s, "Channeltype: SIP\r\n");
 		if (actionid)
-			ast_cli(fd, "ActionID: %s\r\n", actionid);
-		ast_cli(fd, "ObjectName: %s\r\n", peer->name);
-		ast_cli(fd, "ChanObjectType: peer\r\n");
-		ast_cli(fd, "SecretExist: %s\r\n", ast_strlen_zero(peer->secret)?"N":"Y");
-		ast_cli(fd, "MD5SecretExist: %s\r\n", ast_strlen_zero(peer->md5secret)?"N":"Y");
-		ast_cli(fd, "Context: %s\r\n", peer->context);
-		ast_cli(fd, "Language: %s\r\n", peer->language);
+			astman_append(s, "ActionID: %s\r\n", actionid);
+		astman_append(s, "ObjectName: %s\r\n", peer->name);
+		astman_append(s, "ChanObjectType: peer\r\n");
+		astman_append(s, "SecretExist: %s\r\n", ast_strlen_zero(peer->secret)?"N":"Y");
+		astman_append(s, "MD5SecretExist: %s\r\n", ast_strlen_zero(peer->md5secret)?"N":"Y");
+		astman_append(s, "Context: %s\r\n", peer->context);
+		astman_append(s, "Language: %s\r\n", peer->language);
 		if (!ast_strlen_zero(peer->accountcode))
-			ast_cli(fd, "Accountcode: %s\r\n", peer->accountcode);
-		ast_cli(fd, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags));
-		ast_cli(fd, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres));
+			astman_append(s, "Accountcode: %s\r\n", peer->accountcode);
+		astman_append(s, "AMAflags: %s\r\n", ast_cdr_flags2str(peer->amaflags));
+		astman_append(s, "CID-CallingPres: %s\r\n", ast_describe_caller_presentation(peer->callingpres));
 		if (!ast_strlen_zero(peer->fromuser))
-			ast_cli(fd, "SIP-FromUser: %s\r\n", peer->fromuser);
+			astman_append(s, "SIP-FromUser: %s\r\n", peer->fromuser);
 		if (!ast_strlen_zero(peer->fromdomain))
-			ast_cli(fd, "SIP-FromDomain: %s\r\n", peer->fromdomain);
-		ast_cli(fd, "Callgroup: ");
+			astman_append(s, "SIP-FromDomain: %s\r\n", peer->fromdomain);
+		astman_append(s, "Callgroup: ");
 		print_group(fd, peer->callgroup, 1);
-		ast_cli(fd, "Pickupgroup: ");
+		astman_append(s, "Pickupgroup: ");
 		print_group(fd, peer->pickupgroup, 1);
-		ast_cli(fd, "VoiceMailbox: %s\r\n", peer->mailbox);
-		ast_cli(fd, "LastMsgsSent: %d\r\n", peer->lastmsgssent);
-		ast_cli(fd, "Call limit: %d\r\n", peer->call_limit);
-		ast_cli(fd, "Dynamic: %s\r\n", (ast_test_flag((&peer->flags_page2), SIP_PAGE2_DYNAMIC)?"Y":"N"));
-		ast_cli(fd, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, ""));
-		ast_cli(fd, "RegExpire: %ld seconds\r\n", ast_sched_when(sched,peer->expire));
-		ast_cli(fd, "SIP-AuthInsecure: %s\r\n", insecure2str(ast_test_flag(peer, SIP_INSECURE_PORT), ast_test_flag(peer, SIP_INSECURE_INVITE)));
-		ast_cli(fd, "SIP-NatSupport: %s\r\n", nat2str(ast_test_flag(peer, SIP_NAT)));
-		ast_cli(fd, "ACL: %s\r\n", (peer->ha?"Y":"N"));
-		ast_cli(fd, "SIP-CanReinvite: %s\r\n", (ast_test_flag(peer, SIP_CAN_REINVITE)?"Y":"N"));
-		ast_cli(fd, "SIP-PromiscRedir: %s\r\n", (ast_test_flag(peer, SIP_PROMISCREDIR)?"Y":"N"));
-		ast_cli(fd, "SIP-UserPhone: %s\r\n", (ast_test_flag(peer, SIP_USEREQPHONE)?"Y":"N"));
+		astman_append(s, "VoiceMailbox: %s\r\n", peer->mailbox);
+		astman_append(s, "LastMsgsSent: %d\r\n", peer->lastmsgssent);
+		astman_append(s, "Call limit: %d\r\n", peer->call_limit);
+		astman_append(s, "Dynamic: %s\r\n", (ast_test_flag((&peer->flags_page2), SIP_PAGE2_DYNAMIC)?"Y":"N"));
+		astman_append(s, "Callerid: %s\r\n", ast_callerid_merge(cbuf, sizeof(cbuf), peer->cid_name, peer->cid_num, ""));
+		astman_append(s, "RegExpire: %ld seconds\r\n", ast_sched_when(sched,peer->expire));
+		astman_append(s, "SIP-AuthInsecure: %s\r\n", insecure2str(ast_test_flag(peer, SIP_INSECURE_PORT), ast_test_flag(peer, SIP_INSECURE_INVITE)));
+		astman_append(s, "SIP-NatSupport: %s\r\n", nat2str(ast_test_flag(peer, SIP_NAT)));
+		astman_append(s, "ACL: %s\r\n", (peer->ha?"Y":"N"));
+		astman_append(s, "SIP-CanReinvite: %s\r\n", (ast_test_flag(peer, SIP_CAN_REINVITE)?"Y":"N"));
+		astman_append(s, "SIP-PromiscRedir: %s\r\n", (ast_test_flag(peer, SIP_PROMISCREDIR)?"Y":"N"));
+		astman_append(s, "SIP-UserPhone: %s\r\n", (ast_test_flag(peer, SIP_USEREQPHONE)?"Y":"N"));
 
 		/* - is enumerated */
-		ast_cli(fd, "SIP-DTMFmode %s\r\n", dtmfmode2str(ast_test_flag(peer, SIP_DTMF)));
-		ast_cli(fd, "SIPLastMsg: %d\r\n", peer->lastmsg);
-		ast_cli(fd, "ToHost: %s\r\n", peer->tohost);
-		ast_cli(fd, "Address-IP: %s\r\nAddress-Port: %d\r\n",  peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", ntohs(peer->addr.sin_port));
-		ast_cli(fd, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
-		ast_cli(fd, "Default-Username: %s\r\n", peer->username);
+		astman_append(s, "SIP-DTMFmode %s\r\n", dtmfmode2str(ast_test_flag(peer, SIP_DTMF)));
+		astman_append(s, "SIPLastMsg: %d\r\n", peer->lastmsg);
+		astman_append(s, "ToHost: %s\r\n", peer->tohost);
+		astman_append(s, "Address-IP: %s\r\nAddress-Port: %d\r\n",  peer->addr.sin_addr.s_addr ? ast_inet_ntoa(iabuf, sizeof(iabuf), peer->addr.sin_addr) : "", ntohs(peer->addr.sin_port));
+		astman_append(s, "Default-addr-IP: %s\r\nDefault-addr-port: %d\r\n", ast_inet_ntoa(iabuf, sizeof(iabuf), peer->defaddr.sin_addr), ntohs(peer->defaddr.sin_port));
+		astman_append(s, "Default-Username: %s\r\n", peer->username);
 		if (!ast_strlen_zero(global_regcontext))
-			ast_cli(fd, "RegExtension: %s\r\n", peer->regexten);
-		ast_cli(fd, "Codecs: ");
+			astman_append(s, "RegExtension: %s\r\n", peer->regexten);
+		astman_append(s, "Codecs: ");
 		ast_getformatname_multiple(codec_buf, sizeof(codec_buf) -1, peer->capability);
-		ast_cli(fd, "%s\r\n", codec_buf);
-		ast_cli(fd, "CodecOrder: ");
+		astman_append(s, "%s\r\n", codec_buf);
+		astman_append(s, "CodecOrder: ");
 		pref = &peer->prefs;
 		for(x = 0; x < 32 ; x++) {
 			codec = ast_codec_pref_index(pref,x);
 			if (!codec)
 				break;
-			ast_cli(fd, "%s", ast_getformatname(codec));
+			astman_append(s, "%s", ast_getformatname(codec));
 			if (x < 31 && ast_codec_pref_index(pref,x+1))
-				ast_cli(fd, ",");
-		}
-
-		ast_cli(fd, "\r\n");
-		ast_cli(fd, "Status: ");
+				astman_append(s, ",");
+		}
+
+		astman_append(s, "\r\n");
+		astman_append(s, "Status: ");
 		peer_status(peer, status, sizeof(status));
-		ast_cli(fd, "%s\r\n", status);
- 		ast_cli(fd, "SIP-Useragent: %s\r\n", peer->useragent);
- 		ast_cli(fd, "Reg-Contact : %s\r\n", peer->fullcontact);
+		astman_append(s, "%s\r\n", status);
+ 		astman_append(s, "SIP-Useragent: %s\r\n", peer->useragent);
+ 		astman_append(s, "Reg-Contact : %s\r\n", peer->fullcontact);
 		if (peer->chanvars) {
 			for (v = peer->chanvars ; v ; v = v->next) {
- 				ast_cli(fd, "ChanVariable:\n");
- 				ast_cli(fd, " %s,%s\r\n", v->name, v->value);
+ 				astman_append(s, "ChanVariable:\n");
+ 				astman_append(s, " %s,%s\r\n", v->name, v->value);
 			}
 		}
 

Modified: trunk/channels/chan_zap.c
URL: http://svn.digium.com/view/asterisk/trunk/channels/chan_zap.c?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/channels/chan_zap.c (original)
+++ trunk/channels/chan_zap.c Sat Mar 25 17:50:09 2006
@@ -10251,7 +10251,7 @@
 	while (tmp) {
 		if (tmp->channel > 0) {
 			int alarm = get_alarms(tmp);
-			ast_cli(s->fd,
+			astman_append(s,
 				"Event: ZapShowChannels\r\n"
 				"Channel: %d\r\n"
 				"Signalling: %s\r\n"
@@ -10270,7 +10270,7 @@
 
 	ast_mutex_unlock(&iflock);
 	
-	ast_cli(s->fd, 
+	astman_append(s, 
 		"Event: ZapShowChannelsComplete\r\n"
 		"%s"
 		"\r\n", 

Added: trunk/configs/http.conf.sample
URL: http://svn.digium.com/view/asterisk/trunk/configs/http.conf.sample?rev=14953&view=auto
==============================================================================
--- trunk/configs/http.conf.sample (added)
+++ trunk/configs/http.conf.sample Sat Mar 25 17:50:09 2006
@@ -1,0 +1,23 @@
+;
+; Asterisk Builtin mini-HTTP server
+;
+;
+[general]
+;
+; Whether HTTP interface is enabled or not.
+;
+enabled=yes
+;
+; Address to bind to
+;
+bindaddr=127.0.0.1
+;
+; Port to bind to
+;
+bindport=8088
+;
+; Prefix allows you to specify a prefix for all requests
+; to the server.  The default is "asterisk" so that all
+; requests must begin with /asterisk
+;
+;prefix=asterisk

Propchange: trunk/configs/http.conf.sample
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/configs/http.conf.sample
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/configs/http.conf.sample
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Modified: trunk/db.c
URL: http://svn.digium.com/view/asterisk/trunk/db.c?rev=14953&r1=14952&r2=14953&view=diff
==============================================================================
--- trunk/db.c (original)
+++ trunk/db.c Sat Mar 25 17:50:09 2006
@@ -568,7 +568,7 @@
 		astman_send_error(s, m, "Database entry not found");
 	} else {
 		astman_send_ack(s, m, "Result will follow");
-		ast_cli(s->fd, "Event: DBGetResponse\r\n"
+		astman_append(s, "Event: DBGetResponse\r\n"
 				"Family: %s\r\n"
 				"Key: %s\r\n"
 				"Val: %s\r\n"

Added: trunk/http.c
URL: http://svn.digium.com/view/asterisk/trunk/http.c?rev=14953&view=auto
==============================================================================
--- trunk/http.c (added)
+++ trunk/http.c Sat Mar 25 17:50:09 2006
@@ -1,0 +1,463 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2006, Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <unistd.h>
+#include <stdlib.h>
+#include <time.h>
+#include <string.h>
+#include <netinet/in.h>
+#include <sys/time.h>
+#include <sys/socket.h>
+#include <sys/signal.h>
+#include <arpa/inet.h>
+#include <errno.h>
+#include <fcntl.h>
+#include <pthread.h>
+#include <asterisk/cli.h>
+#include <asterisk/http.h>
+#include <asterisk/utils.h>
+#include <asterisk/strings.h>
+
+#define MAX_PREFIX 80
+#define DEFAULT_PREFIX "asterisk"
+
+/* This program implements a tiny http server supporting the "get" method
+   only and was inspired by micro-httpd by Jef Poskanzer */
+
+struct ast_http_server_instance {
+	FILE *f;
+	int fd;
+	struct sockaddr_in requestor;
+	ast_http_callback callback;
+};
+
+static struct ast_http_uri *uris;
+
+static int httpfd = -1;
+static pthread_t master = AST_PTHREADT_NULL;
+static char prefix[MAX_PREFIX];
+static int prefix_len = 0;
+static struct sockaddr_in oldsin;
+
+
+static char *httpstatus_callback(struct sockaddr_in *req, const char *uri, struct ast_variable *vars, int *status, char **title, int *contentlength)
+{
+	char result[4096];
+	int reslen = sizeof(result);
+	char *c=result;
+	struct ast_variable *v;
+	char iabuf[INET_ADDRSTRLEN];
+
+	ast_build_string(&c, &reslen,
+		"\r\n"
+		"<title>Asterisk HTTP Status</title>\r\n"
+		"<body bgcolor=\"#ffffff\">\r\n"
+		"<table bgcolor=\"#f1f1f1\" align=\"center\"><tr><td bgcolor=\"#e0e0ff\" colspan=\"2\" width=\"500\">\r\n"
+		"<h2>&nbsp;&nbsp;Asterisk&trade; HTTP Status</h2></td></tr>\r\n");
+
+	ast_build_string(&c, &reslen, "<tr><td><i>Prefix</i></td><td><b>%s</b></td></tr>\r\n", prefix);
+	ast_build_string(&c, &reslen, "<tr><td><i>Bind Address</i></td><td><b>%s</b></td></tr>\r\n",
+			ast_inet_ntoa(iabuf, sizeof(iabuf), oldsin.sin_addr));
+	ast_build_string(&c, &reslen, "<tr><td><i>Bind Port</i></td><td><b>%d</b></td></tr>\r\n",
+			ntohs(oldsin.sin_port));
+	ast_build_string(&c, &reslen, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
+	v = vars;
+	while(v) {
+		ast_build_string(&c, &reslen, "<tr><td><i>Submitted Variable '%s'</i></td><td>%s</td></tr>\r\n", v->name, v->value);
+		v = v->next;
+	}
+	ast_build_string(&c, &reslen, "</table><center><font size=\"-1\"><i>Asterisk and Digium are registered trademarks of Digium, Inc.</i></font></center></body>\r\n");
+	return strdup(result);
+}
+
+static struct ast_http_uri statusuri = {
+	.callback = httpstatus_callback,
+	.description = "Asterisk HTTP General Status",
+	.uri = "httpstatus",
+	.has_subtree = 0,
+};
+	
+char *ast_http_error(int status, const char *title, const char *extra_header, const char *text)
+{
+	char *c = NULL;
+	asprintf(&c,
+		"Content-type: text/html\r\n"
+		"%s"
+		"\r\n"
+		"<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">\r\n"
+		"<html><head>\r\n"
+		"<title>%d %s</title>\r\n"
+		"</head><body>\r\n"
+		"<h1>%s</h1>\r\n"
+		"<p>%s</p>\r\n"
+		"<hr />\r\n"
+		"<address>Asterisk Server</address>\r\n"
+		"</body></html>\r\n",
+			(extra_header ? extra_header : ""), status, title, title, text);
+	return c;
+}
+
+int ast_http_uri_link(struct ast_http_uri *urih)
+{
+	struct ast_http_uri *prev=uris;
+	if (!uris || strlen(uris->uri) <= strlen(urih->uri)) {
+		urih->next = uris;
+		uris = urih;
+	} else {
+		while (prev->next && (strlen(prev->next->uri) > strlen(urih->uri)))
+			prev = prev->next;
+		/* Insert it here */
+		urih->next = prev->next;
+		prev->next = urih;
+	}
+	return 0;
+}	
+
+void ast_http_uri_unlink(struct ast_http_uri *urih)
+{
+	struct ast_http_uri *prev = uris;
+	if (!uris)
+		return;
+	if (uris == urih) {
+		uris = uris->next;
+	}
+	while(prev->next) {
+		if (prev->next == urih) {
+			prev->next = urih->next;
+			break;
+		}
+		prev = prev->next;
+	}
+}
+
+static char *handle_uri(struct sockaddr_in *sin, char *uri, int *status, char **title, int *contentlength)
+{
+	char *c;
+	char *turi;
+	char *params;
+	char *var;
+	char *val;
+	struct ast_http_uri *urih=NULL;
+	int len;
+	struct ast_variable *vars=NULL, *v, *prev = NULL;
+	
+	
+	if (*uri == '/')
+		uri++;
+	params = strchr(uri, '?');
+	if (params) {
+		*params = '\0';
+		params++;
+		while ((var = strsep(&params, "&"))) {
+			val = strchr(var, '=');
+			if (val) {
+				*val = '\0';
+				val++;
+			} else 
+				val = "";
+			ast_uri_decode(val);
+			ast_uri_decode(var);
+			if ((v = ast_variable_new(var, val))) {
+				if (vars)
+					prev->next = v;
+				else
+					vars = v;
+				prev = v;
+			}
+		}
+	}
+	ast_uri_decode(uri);
+	if (!strncasecmp(uri, prefix, prefix_len)) {
+		uri += prefix_len;
+		if (!*uri || (*uri == '/')) {
+			if (*uri == '/')
+				uri++;
+			urih = uris;
+			while(urih) {
+				len = strlen(urih->uri);
+				if (!strncasecmp(urih->uri, uri, len)) {
+					if (!uri[len] || uri[len] == '/') {
+						turi = uri + len;
+						if (*turi == '/')
+							turi++;
+						if (!*turi || urih->has_subtree) {
+							uri = turi;
+							break;
+						}
+					}
+				}
+				urih = urih->next;
+			}
+		}
+	}
+	if (urih) {
+		c = urih->callback(sin, uri, vars, status, title, contentlength);
+		ast_variables_destroy(vars);
+	} else {
+		c = ast_http_error(404, "Not Found", NULL, "The requested URL was not found on this serer.");
+		*status = 404;
+		*title = strdup("Not Found");
+	}
+	return c;
+}
+
+static void *ast_httpd_helper_thread(void *data)
+{
+	char buf[4096];
+	char timebuf[256];
+	struct ast_http_server_instance *ser = data;
+	char *uri, *c, *title=NULL;
+	int status = 200, contentlength = 0;
+	time_t t;
+
+	if (fgets(buf, sizeof(buf), ser->f)) {
+		/* Skip method */
+		uri = buf;
+		while(*uri && (*uri > 32)) uri++;
+		if (*uri) {
+			*uri = '\0';
+			uri++;
+		}
+
+		/* Skip white space */
+		while (*uri && (*uri < 33)) uri++;
+
+		if (*uri) {
+			c = uri;
+			while (*c && (*c > 32)) c++;
+			if (*c) {
+				*c = '\0';
+			}
+		}
+		if (*uri) {
+			if (!strcasecmp(buf, "get")) 
+				c = handle_uri(&ser->requestor, uri, &status, &title, &contentlength);
+			else 
+				c = ast_http_error(501, "Not Implemented", NULL, "Attempt to use unimplemented / unsupported method");\
+		} else 
+			c = ast_http_error(400, "Bad Request", NULL, "Invalid Request");
+		if (!c)
+			c = ast_http_error(500, "Internal Error", NULL, "Internal Server Error");
+		if (c) {
+			time(&t);
+			strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %H:%M:%S GMT", gmtime(&t));
+			ast_cli(ser->fd, "HTTP/1.1 GET %d %s\r\n", status, title ? title : "OK");
+			ast_cli(ser->fd, "Server: Asterisk\r\n");
+			ast_cli(ser->fd, "Date: %s\r\n", timebuf);
+			if (contentlength)
+				ast_cli(ser->fd, "Content-length: %d\r\n", contentlength);
+			ast_cli(ser->fd, "Connection: close\r\n");
+			ast_cli(ser->fd, "%s", c);
+			free(c);
+		}
+		if (title)
+			free(title);
+	}
+	fclose(ser->f);
+	free(ser);
+	return NULL;
+}
+
+static void *http_root(void *data)
+{
+	int fd;
+	struct sockaddr_in sin;
+	int sinlen;
+	struct ast_http_server_instance *ser;
+	pthread_t launched;
+	for (;;) {
+		ast_wait_for_input(httpfd, -1);
+		sinlen = sizeof(sin);
+		fd = accept(httpfd, (struct sockaddr *)&sin, &sinlen);
+		if (fd < 0) {
+			if ((errno != EAGAIN) && (errno != EINTR))
+				ast_log(LOG_WARNING, "Accept failed: %s\n", strerror(errno));
+			continue;
+		}
+		ser = calloc(1, sizeof(*ser));
+		if (ser) {
+			ser->fd = fd;
+			if ((ser->f = fdopen(ser->fd, "w+"))) {
+				if (ast_pthread_create(&launched, NULL, ast_httpd_helper_thread, ser)) {
+					ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
+					fclose(ser->f);
+					free(ser);
+				}
+			} else {
+				ast_log(LOG_WARNING, "fdopen failed!\n");
+				close(ser->fd);
+				free(ser);
+			}
+		} else {
+			ast_log(LOG_WARNING, "Out of memory!\n");
+			close(fd);
+		}
+	}
+	return NULL;
+}
+
+static void http_server_start(struct sockaddr_in *sin)
+{
+	char iabuf[INET_ADDRSTRLEN];
+	int flags;
+	int x = 1;
+	
+	/* Do nothing if nothing has changed */
+	if (!memcmp(&oldsin, sin, sizeof(oldsin))) {
+		ast_log(LOG_DEBUG, "Nothing changed in http\n");
+		return;
+	}
+	
+	memcpy(&oldsin, sin, sizeof(oldsin));
+	
+	/* Shutdown a running server if there is one */
+	if (master != AST_PTHREADT_NULL) {
+		pthread_cancel(master);
+		pthread_kill(master, SIGURG);
+		pthread_join(master, NULL);
+	}
+	
+	if (httpfd != -1)
+		close(httpfd);
+
+	/* If there's no new server, stop here */
+	if (!sin->sin_family)
+		return;
+	
+	
+	httpfd = socket(AF_INET, SOCK_STREAM, 0);
+	if (httpfd < 0) {
+		ast_log(LOG_WARNING, "Unable to allocate socket: %s\n", strerror(errno));
+		return;
+	}
+	
+	setsockopt(httpfd, SOL_SOCKET, SO_REUSEADDR, &x, sizeof(x));
+	if (bind(httpfd, (struct sockaddr *)sin, sizeof(*sin))) {
+		ast_log(LOG_NOTICE, "Unable to bind http server to %s:%d: %s\n",
+			ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port),
+			strerror(errno));
+		close(httpfd);
+		httpfd = -1;
+		return;
+	}
+	if (listen(httpfd, 10)) {
+		ast_log(LOG_NOTICE, "Unable to listen!\n");
+		close(httpfd);
+		httpfd = -1;
+		return;
+	}
+	flags = fcntl(httpfd, F_GETFL);
+	fcntl(httpfd, F_SETFL, flags | O_NONBLOCK);
+	if (ast_pthread_create(&master, NULL, http_root, NULL)) {
+		ast_log(LOG_NOTICE, "Unable to launch http server on %s:%d: %s\n",
+				ast_inet_ntoa(iabuf, sizeof(iabuf), sin->sin_addr), ntohs(sin->sin_port),
+				strerror(errno));
+		close(httpfd);
+		httpfd = -1;
+	}
+}
+
+static int __ast_http_load(int reload)
+{
+	struct ast_config *cfg;
+	struct ast_variable *v;
+	int enabled=0;
+	struct sockaddr_in sin;
+	struct hostent *hp;
+	struct ast_hostent ahp;
+	char newprefix[MAX_PREFIX];
+	memset(&sin, 0, sizeof(sin));
+	sin.sin_port = 8088;
+	strcpy(newprefix, DEFAULT_PREFIX);
+	cfg = ast_config_load("http.conf");
+	if (cfg) {
+		v = ast_variable_browse(cfg, "general");
+		while(v) {
+			if (!strcasecmp(v->name, "enabled"))
+				enabled = ast_true(v->value);
+			else if (!strcasecmp(v->name, "bindport"))
+				sin.sin_port = ntohs(atoi(v->value));
+			else if (!strcasecmp(v->name, "bindaddr")) {
+				if ((hp = ast_gethostbyname(v->value, &ahp))) {
+					memcpy(&sin.sin_addr, hp->h_addr, sizeof(sin.sin_addr));
+				} else {
+					ast_log(LOG_WARNING, "Invalid bind address '%s'\n", v->value);
+				}
+			} else if (!strcasecmp(v->name, "prefix"))
+				ast_copy_string(newprefix, v->value, sizeof(newprefix));
+			v = v->next;
+		}
+		ast_config_destroy(cfg);
+	}
+	if (enabled)
+		sin.sin_family = AF_INET;
+	if (strcmp(prefix, newprefix)) {
+		ast_copy_string(prefix, newprefix, sizeof(prefix));
+		prefix_len = strlen(prefix);
+	}
+	http_server_start(&sin);
+	return 0;
+}
+
+static int handle_show_http(int fd, int argc, char *argv[])
+{
+	char iabuf[INET_ADDRSTRLEN];
+	struct ast_http_uri *urih;
+	if (argc != 2)
+		return RESULT_SHOWUSAGE;
+	ast_cli(fd, "HTTP Server Status:\n");
+	ast_cli(fd, "Prefix: %s\n", prefix);
+	if (oldsin.sin_family)
+		ast_cli(fd, "Server Enabled and Bound to %s:%d\n\n",
+			ast_inet_ntoa(iabuf, sizeof(iabuf), oldsin.sin_addr),
+			ntohs(oldsin.sin_port));
+	else
+		ast_cli(fd, "Server Disabled\n\n");
+	ast_cli(fd, "Enabled URI's:\n");
+	urih = uris;
+	while(urih){
+		ast_cli(fd, "/%s/%s%s => %s\n", prefix, urih->uri, (urih->has_subtree ? "/..." : "" ), urih->description);
+		urih = urih->next;
+	}
+	if (!uris)
+		ast_cli(fd, "None.\n");
+	return RESULT_SUCCESS;
+}
+
+int ast_http_reload(void)
+{
+	return __ast_http_load(1);
+}
+
+static char show_http_help[] =
+"Usage: show http\n"
+"       Shows status of internal HTTP engine\n";
+
+static struct ast_cli_entry http_cli[] = {
+	{ { "show", "http", NULL }, handle_show_http,
+	  "Display HTTP status", show_http_help },
+};
+
+int ast_http_init(void)
+{
+	ast_http_uri_link(&statusuri);
+	ast_cli_register_multiple(http_cli, sizeof(http_cli) / sizeof(http_cli[0]));
+	return __ast_http_load(0);
+}

Propchange: trunk/http.c
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: trunk/http.c
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision

Propchange: trunk/http.c
------------------------------------------------------------------------------
    svn:mime-type = text/plain

Added: trunk/include/asterisk/http.h
URL: http://svn.digium.com/view/asterisk/trunk/include/asterisk/http.h?rev=14953&view=auto
==============================================================================
--- trunk/include/asterisk/http.h (added)
+++ trunk/include/asterisk/http.h Sat Mar 25 17:50:09 2006
@@ -1,0 +1,64 @@
+/*
+ * Asterisk -- An open source telephony toolkit.
+ *
+ * Copyright (C) 1999 - 2006, Digium, Inc.
+ *
+ * Mark Spencer <markster at digium.com>
+ *
+ * See http://www.asterisk.org for more information about
+ * the Asterisk project. Please do not directly contact
+ * any of the maintainers of this project for assistance;
+ * the project provides a web site, mailing lists and IRC
+ * channels for your use.
+ *
+ * This program is free software, distributed under the terms of
+ * the GNU General Public License Version 2. See the LICENSE file
+ * at the top of the source tree.
+ */
+

[... 429 lines stripped ...]


More information about the asterisk-commits mailing list