Index: loader.c
===================================================================
--- loader.c	(revision 18749)
+++ loader.c	(working copy)
@@ -45,7 +45,6 @@
 #include "asterisk/cdr.h"
 #include "asterisk/enum.h"
 #include "asterisk/rtp.h"
-#include "asterisk/http.h"
 #include "asterisk/lock.h"
 #ifdef DLFCNCOMPAT
 #include "asterisk/dlfcn-compat.h"
@@ -465,7 +464,6 @@
 	{ "enum",	ast_enum_reload },
 	{ "manager",	reload_manager },
 	{ "rtp",	ast_rtp_reload },
-	{ "http",	ast_http_reload },
 	{ NULL, NULL }
 };
 
Index: manager.c
===================================================================
--- manager.c	(revision 18749)
+++ manager.c	(working copy)
@@ -65,7 +65,6 @@
 #include "asterisk/md5.h"
 #include "asterisk/acl.h"
 #include "asterisk/utils.h"
-#include "asterisk/http.h"
 
 struct fast_originate_helper {
 	char tech[AST_MAX_MANHEADER_LEN];
@@ -83,25 +82,19 @@
 	struct ast_variable *vars;
 };
 
-struct eventqent {
-	int usecount;
-	int category;
-	ast_mutex_t lock;
-	struct eventqent *next;
-	char eventdata[1];
-};
-
-static int enabled = 0;
+int manager_enabled = 0;
+int webenabled = 0;
 static int portno = DEFAULT_MANAGER_PORT;
 static int asock = -1;
-static int displayconnects = 1;
+int displayconnects = 1;
 static int timestampevents = 0;
-static int httptimeout = 60;
+int httptimeout = 60;
 
 static pthread_t t;
-AST_MUTEX_DEFINE_STATIC(sessionlock);
+/*AST_MUTEX_DEFINE_STATIC(sessionlock);*/
+ast_mutex_t sessionlock;
 static int block_sockets = 0;
-static int num_sessions = 0;
+int num_sessions = 0;
 struct eventqent *master_eventq = NULL;
 
 static struct permalias {
@@ -119,51 +112,7 @@
 	{ 0, "none" },
 };
 
-static struct mansession {
-	/*! Execution thread */
-	pthread_t t;
-	/*! Thread lock -- don't use in action callbacks, it's already taken care of  */
-	ast_mutex_t __lock;
-	/*! socket address */
-	struct sockaddr_in sin;
-	/*! TCP socket */
-	int fd;
-	/*! Whether or not we're busy doing an action */
-	int busy;
-	/*! Whether or not we're "dead" */
-	int dead;
-	/*! Whether an HTTP manager is in use */
-	int inuse;
-	/*! Whether an HTTP session should be destroyed */
-	int needdestroy;
-	/*! Whether an HTTP session has someone waiting on events */
-	pthread_t waiting_thread;
-	/*! Unique manager identifer */
-	unsigned long managerid;
-	/*! Session timeout if HTTP */
-	time_t sessiontimeout;
-	/*! Output from manager interface */
-	char *outputstr;
-	/*! Logged in username */
-	char username[80];
-	/*! Authentication challenge */
-	char challenge[10];
-	/*! Authentication status */
-	int authenticated;
-	/*! Authorization for reading */
-	int readperm;
-	/*! Authorization for writing */
-	int writeperm;
-	/*! Buffer */
-	char inbuf[AST_MAX_MANHEADER_LEN];
-	int inlen;
-	int send_events;
-	/* Queued events that we've not had the ability to send yet */
-	struct eventqent *eventq;
-	/* Timeout for ast_carefulwrite() */
-	int writetimeout;
-	struct mansession *next;
-} *sessions = NULL;
+struct mansession *sessions = NULL;
 
 static struct manager_action *first_action = NULL;
 AST_MUTEX_DEFINE_STATIC(actionlock);
@@ -238,167 +187,6 @@
 	return ret;
 }
 
-static void xml_copy_escape(char **dst, size_t *maxlen, const char *src, int lower)
-{
-	while (*src && (*maxlen > 6)) {
-		switch (*src) {
-		case '<':
-			strcpy(*dst, "&lt;");
-			(*dst) += 4;
-			*maxlen -= 4;
-			break;
-		case '>':
-			strcpy(*dst, "&gt;");
-			(*dst) += 4;
-			*maxlen -= 4;
-			break;
-		case '\"':
-			strcpy(*dst, "&quot;");
-			(*dst) += 6;
-			*maxlen -= 6;
-			break;
-		case '\'':
-			strcpy(*dst, "&apos;");
-			(*dst) += 6;
-			*maxlen -= 6;
-			break;
-		case '&':
-			strcpy(*dst, "&amp;");
-			(*dst) += 4;
-			*maxlen -= 4;
-			break;		
-		default:
-			*(*dst)++ = lower ? tolower(*src) : *src;
-			(*maxlen)--;
-		}
-		src++;
-	}
-}
-
-static char *xml_translate(char *in, struct ast_variable *vars)
-{
-	struct ast_variable *v;
-	char *dest = NULL;
-	char *out, *tmp, *var, *val;
-	char *objtype = NULL;
-	int colons = 0;
-	int breaks = 0;
-	size_t len;
-	int count = 1;
-	int escaped = 0;
-	int inobj = 0;
-	int x;
-	v = vars;
-
-	while (v) {
-		if (!dest && !strcasecmp(v->name, "ajaxdest"))
-			dest = v->value;
-		else if (!objtype && !strcasecmp(v->name, "ajaxobjtype")) 
-			objtype = v->value;
-		v = v->next;
-	}
-	if (!dest)
-		dest = "unknown";
-	if (!objtype)
-		objtype = "generic";
-	for (x=0; in[x]; x++) {
-		if (in[x] == ':')
-			colons++;
-		else if (in[x] == '\n')
-			breaks++;
-		else if (strchr("&\"<>", in[x]))
-			escaped++;
-	}
-	len = (size_t) (strlen(in) + colons * 5 + breaks * (40 + strlen(dest) + strlen(objtype)) + escaped * 10); /* foo="bar", "<response type=\"object\" id=\"dest\"", "&amp;" */
-	out = malloc(len);
-	if (!out)
-		return 0;
-	tmp = out;
-	while (*in) {
-		var = in;
-		while (*in && (*in >= 32))
-			in++;
-		if (*in) {
-			if ((count > 3) && inobj) {
-				ast_build_string(&tmp, &len, " /></response>\n");
-				inobj = 0;
-			}
-			count = 0;
-			while (*in && (*in < 32)) {
-				*in = '\0';
-				in++;
-				count++;
-			}
-			val = strchr(var, ':');
-			if (val) {
-				*val = '\0';
-				val++;
-				if (*val == ' ')
-					val++;
-				if (!inobj) {
-					ast_build_string(&tmp, &len, "<response type='object' id='%s'><%s", dest, objtype);
-					inobj = 1;
-				}
-				ast_build_string(&tmp, &len, " ");				
-				xml_copy_escape(&tmp, &len, var, 1);
-				ast_build_string(&tmp, &len, "='");
-				xml_copy_escape(&tmp, &len, val, 0);
-				ast_build_string(&tmp, &len, "'");
-			}
-		}
-	}
-	if (inobj)
-		ast_build_string(&tmp, &len, " /></response>\n");
-	return out;
-}
-
-static char *html_translate(char *in)
-{
-	int x;
-	int colons = 0;
-	int breaks = 0;
-	size_t len;
-	int count = 1;
-	char *tmp, *var, *val, *out;
-
-	for (x=0; in[x]; x++) {
-		if (in[x] == ':')
-			colons++;
-		if (in[x] == '\n')
-			breaks++;
-	}
-	len = strlen(in) + colons * 40 + breaks * 40; /* <tr><td></td><td></td></tr>, "<tr><td colspan=\"2\"><hr></td></tr> */
-	out = malloc(len);
-	if (!out)
-		return 0;
-	tmp = out;
-	while (*in) {
-		var = in;
-		while (*in && (*in >= 32))
-			in++;
-		if (*in) {
-			if ((count % 4) == 0){
-				ast_build_string(&tmp, &len, "<tr><td colspan=\"2\"><hr></td></tr>\r\n");
-			}
-			count = 0;
-			while (*in && (*in < 32)) {
-				*in = '\0';
-				in++;
-				count++;
-			}
-			val = strchr(var, ':');
-			if (val) {
-				*val = '\0';
-				val++;
-				if (*val == ' ')
-					val++;
-				ast_build_string(&tmp, &len, "<tr><td>%s</td><td>%s</td></tr>\r\n", var, val);
-			}
-		}
-	}
-	return out;
-}
-
 void astman_append(struct mansession *s, const char *fmt, ...)
 {
 	char *stuff;
@@ -569,7 +357,7 @@
 	free(s);
 }
 
-static void destroy_session(struct mansession *s)
+void destroy_session(struct mansession *s)
 {
 	struct mansession *cur, *prev = NULL;
 	ast_mutex_lock(&sessionlock);
@@ -1649,7 +1437,7 @@
 	return ret;
 }
 
-static int process_message(struct mansession *s, struct message *m)
+int process_message(struct mansession *s, struct message *m)
 {
 	char action[80] = "";
 	struct manager_action *tmp = first_action;
@@ -2101,7 +1889,7 @@
 /*! @}
  END Doxygen group */
 
-static struct mansession *find_session(unsigned long ident)
+struct mansession *manager_find_session(unsigned long ident)
 {
 	struct mansession *s;
 	ast_mutex_lock(&sessionlock);
@@ -2119,204 +1907,7 @@
 	return s;
 }
 
-
-static void vars2msg(struct message *m, struct ast_variable *vars)
-{
-	int x;
-	for (x = 0; vars && (x < AST_MAX_MANHEADERS); x++, vars = vars->next) {
-		if (!vars)
-			break;
-		m->hdrcount = x + 1;
-		snprintf(m->headers[x], sizeof(m->headers[x]), "%s: %s", vars->name, vars->value);
-	}
-}
-
-#define FORMAT_RAW	0
-#define FORMAT_HTML	1
-#define FORMAT_XML	2
-
-static char *contenttype[] = { "plain", "html", "xml" };
-
-static char *generic_http_callback(int format, struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
-	struct mansession *s = NULL;
-	unsigned long ident = 0;
-	char workspace[256];
-	char cookie[128];
-	char iabuf[INET_ADDRSTRLEN];
-	size_t len = sizeof(workspace);
-	int blastaway = 0;
-	char *c = workspace;
-	char *retval = NULL;
-	struct message m;
-	struct ast_variable *v;
-
-	v = params;
-	while (v) {
-		if (!strcasecmp(v->name, "mansession_id")) {
-			sscanf(v->value, "%lx", &ident);
-			break;
-		}
-		v = v->next;
-	}
-	s = find_session(ident);
-
-	if (!s) {
-		/* Create new session */
-		s = calloc(1, sizeof(struct mansession));
-		memcpy(&s->sin, requestor, sizeof(s->sin));
-		s->fd = -1;
-		s->waiting_thread = AST_PTHREADT_NULL;
-		s->send_events = 0;
-		ast_mutex_init(&s->__lock);
-		ast_mutex_lock(&s->__lock);
-		ast_mutex_lock(&sessionlock);
-		s->inuse = 1;
-		s->managerid = rand() | (unsigned long)s;
-		s->next = sessions;
-		sessions = s;
-		num_sessions++;
-		/* Hook into the last spot in the event queue */
-		s->eventq = master_eventq;
-		while (s->eventq->next)
-			s->eventq = s->eventq->next;
-		ast_mutex_lock(&s->eventq->lock);
-		s->eventq->usecount++;
-		ast_mutex_unlock(&s->eventq->lock);
-		ast_mutex_unlock(&sessionlock);
-	}
-
-	/* Reset HTTP timeout.  If we're not yet authenticated, keep it extremely short */
-	time(&s->sessiontimeout);
-	if (!s->authenticated && (httptimeout > 5))
-		s->sessiontimeout += 5;
-	else
-		s->sessiontimeout += httptimeout;
-	ast_mutex_unlock(&s->__lock);
-	
-	memset(&m, 0, sizeof(m));
-	if (s) {
-		char tmp[80];
-		ast_build_string(&c, &len, "Content-type: text/%s\n", contenttype[format]);
-		sprintf(tmp, "%08lx", s->managerid);
-		ast_build_string(&c, &len, "%s\r\n", ast_http_setcookie("mansession_id", tmp, httptimeout, cookie, sizeof(cookie)));
-		if (format == FORMAT_HTML)
-			ast_build_string(&c, &len, "<title>Asterisk&trade; Manager Test Interface</title>");
-		vars2msg(&m, params);
-		if (format == FORMAT_XML) {
-			ast_build_string(&c, &len, "<ajax-response>\n");
-		} else if (format == FORMAT_HTML) {
-			ast_build_string(&c, &len, "<body bgcolor=\"#ffffff\"><table align=center bgcolor=\"#f1f1f1\" width=\"500\">\r\n");
-			ast_build_string(&c, &len, "<tr><td colspan=\"2\" bgcolor=\"#f1f1ff\"><h1>&nbsp;&nbsp;Manager Tester</h1></td></tr>\r\n");
-		}
-		if (process_message(s, &m)) {
-			if (s->authenticated) {
-				if (option_verbose > 1) {
-					if (displayconnects) 
-						ast_verbose(VERBOSE_PREFIX_2 "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));    
-				}
-				ast_log(LOG_EVENT, "HTTP Manager '%s' logged off from %s\n", s->username, ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
-			} else {
-				if (option_verbose > 1) {
-					if (displayconnects)
-						ast_verbose(VERBOSE_PREFIX_2 "HTTP Connect attempt from '%s' unable to authenticate\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
-				}
-				ast_log(LOG_EVENT, "HTTP Failed attempt from %s\n", ast_inet_ntoa(iabuf, sizeof(iabuf), s->sin.sin_addr));
-			}
-			s->needdestroy = 1;
-		}
-		if (s->outputstr) {
-			char *tmp;
-			if (format == FORMAT_XML)
-				tmp = xml_translate(s->outputstr, params);
-			else if (format == FORMAT_HTML)
-				tmp = html_translate(s->outputstr);
-			else
-				tmp = s->outputstr;
-			if (tmp) {
-				retval = malloc(strlen(workspace) + strlen(tmp) + 128);
-				if (retval) {
-					strcpy(retval, workspace);
-					strcpy(retval + strlen(retval), tmp);
-					c = retval + strlen(retval);
-					len = 120;
-				}
-				free(tmp);
-			}
-			if (tmp != s->outputstr)
-				free(s->outputstr);
-			s->outputstr = NULL;
-		}
-		/* Still okay because c would safely be pointing to workspace even
-		   if retval failed to allocate above */
-		if (format == FORMAT_XML) {
-			ast_build_string(&c, &len, "</ajax-response>\n");
-		} else if (format == FORMAT_HTML)
-			ast_build_string(&c, &len, "</table></body>\r\n");
-	} else {
-		*status = 500;
-		*title = strdup("Server Error");
-	}
-	ast_mutex_lock(&s->__lock);
-	if (s->needdestroy) {
-		if (s->inuse == 1) {
-			ast_log(LOG_DEBUG, "Need destroy, doing it now!\n");
-			blastaway = 1;
-		} else {
-			ast_log(LOG_DEBUG, "Need destroy, but can't do it yet!\n");
-			if (s->waiting_thread != AST_PTHREADT_NULL)
-				pthread_kill(s->waiting_thread, SIGURG);
-			s->inuse--;
-		}
-	} else
-		s->inuse--;
-	ast_mutex_unlock(&s->__lock);
-	
-	if (blastaway)
-		destroy_session(s);
-	if (*status != 200)
-		return ast_http_error(500, "Server Error", NULL, "Internal Server Error (out of memory)\n"); 
-	return retval;
-}
-
-static char *manager_http_callback(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
-	return generic_http_callback(FORMAT_HTML, requestor, uri, params, status, title, contentlength);
-}
-
-static char *mxml_http_callback(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
-	return generic_http_callback(FORMAT_XML, requestor, uri, params, status, title, contentlength);
-}
-
-static char *rawman_http_callback(struct sockaddr_in *requestor, const char *uri, struct ast_variable *params, int *status, char **title, int *contentlength)
-{
-	return generic_http_callback(FORMAT_RAW, requestor, uri, params, status, title, contentlength);
-}
-
-struct ast_http_uri rawmanuri = {
-	.description = "Raw HTTP Manager Event Interface",
-	.uri = "rawman",
-	.has_subtree = 0,
-	.callback = rawman_http_callback,
-};
-
-struct ast_http_uri manageruri = {
-	.description = "HTML Manager Event Interface",
-	.uri = "manager",
-	.has_subtree = 0,
-	.callback = manager_http_callback,
-};
-
-struct ast_http_uri managerxmluri = {
-	.description = "XML Manager Event Interface",
-	.uri = "mxml",
-	.has_subtree = 0,
-	.callback = mxml_http_callback,
-};
-
 static int registered = 0;
-static int webregged = 0;
 
 int init_manager(void)
 {
@@ -2326,7 +1917,6 @@
 	static struct sockaddr_in ba;
 	int x = 1;
 	int flags;
-	int webenabled = 0;
 	int newhttptimeout = 60;
 	if (!registered) {
 		/* Register default actions */
@@ -2365,7 +1955,7 @@
 	}
 	val = ast_variable_retrieve(cfg, "general", "enabled");
 	if (val)
-		enabled = ast_true(val);
+		manager_enabled = ast_true(val);
 
 	val = ast_variable_retrieve(cfg, "general", "block-sockets");
 	if (val)
@@ -2403,7 +1993,7 @@
 	}
 	
 
-	if ((asock > -1) && ((portno != oldportno) || !enabled)) {
+	if ((asock > -1) && ((portno != oldportno) || !manager_enabled)) {
 #if 0
 		/* Can't be done yet */
 		close(asock);
@@ -2413,28 +2003,12 @@
 #endif
 	}
 	ast_config_destroy(cfg);
-	
-	if (webenabled && enabled) {
-		if (!webregged) {
-			ast_http_uri_link(&rawmanuri);
-			ast_http_uri_link(&manageruri);
-			ast_http_uri_link(&managerxmluri);
-			webregged = 1;
-		}
-	} else {
-		if (webregged) {
-			ast_http_uri_unlink(&rawmanuri);
-			ast_http_uri_unlink(&manageruri);
-			ast_http_uri_unlink(&managerxmluri);
-			webregged = 0;
-		}
-	}
 
 	if (newhttptimeout > 0)
 		httptimeout = newhttptimeout;
 
 	/* If not enabled, do nothing */
-	if (!enabled) {
+	if (!manager_enabled) {
 		return 0;
 	}
 
Index: Makefile
===================================================================
--- Makefile	(revision 18749)
+++ Makefile	(working copy)
@@ -354,7 +354,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 http.o
+	cryptostub.o sha1.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
Index: include/asterisk/manager.h
===================================================================
--- include/asterisk/manager.h	(revision 18749)
+++ include/asterisk/manager.h	(working copy)
@@ -59,7 +59,51 @@
 #define AST_MAX_MANHEADERS 80
 #define AST_MAX_MANHEADER_LEN 256
 
-struct mansession;
+struct mansession {
+	/*! Execution thread */
+	pthread_t t;
+	/*! Thread lock -- don't use in action callbacks, it's already taken care of  */
+	ast_mutex_t __lock;
+	/*! socket address */
+	struct sockaddr_in sin;
+	/*! TCP socket */
+	int fd;
+	/*! Whether or not we're busy doing an action */
+	int busy;
+	/*! Whether or not we're "dead" */
+	int dead;
+	/*! Whether an HTTP manager is in use */
+	int inuse;
+	/*! Whether an HTTP session should be destroyed */
+	int needdestroy;
+	/*! Whether an HTTP session has someone waiting on events */
+	pthread_t waiting_thread;
+	/*! Unique manager identifer */
+	unsigned long managerid;
+	/*! Session timeout if HTTP */
+	time_t sessiontimeout;
+	/*! Output from manager interface */
+	char *outputstr;
+	/*! Logged in username */
+	char username[80];
+	/*! Authentication challenge */
+	char challenge[10];
+	/*! Authentication status */
+	int authenticated;
+	/*! Authorization for reading */
+	int readperm;
+	/*! Authorization for writing */
+	int writeperm;
+	/*! Buffer */
+	char inbuf[AST_MAX_MANHEADER_LEN];
+	int inlen;
+	int send_events;
+	/* Queued events that we've not had the ability to send yet */
+	struct eventqent *eventq;
+	/* Timeout for ast_carefulwrite() */
+	int writetimeout;
+	struct mansession *next;
+};
 
 struct message {
 	int hdrcount;
@@ -135,4 +179,16 @@
 /*! Called by Asterisk initialization */
 int reload_manager(void);
 
+struct mansession *manager_find_session(unsigned long ident);
+int process_message(struct mansession *s, struct message *m);
+void destroy_session(struct mansession *s);
+
+struct eventqent {
+	int usecount;
+	int category;
+	ast_mutex_t lock;
+	struct eventqent *next;
+	char eventdata[1];
+};
+
 #endif /* _ASTERISK_MANAGER_H */
Index: include/asterisk/http.h
===================================================================
--- include/asterisk/http.h	(revision 18749)
+++ include/asterisk/http.h	(working copy)
@@ -57,7 +57,4 @@
 
 char *ast_http_setcookie(const char *var, const char *val, int expires, char *buf, size_t buflen);
 
-int ast_http_init(void);
-int ast_http_reload(void);
-
 #endif /* _ASTERISK_SRV_H */
Index: asterisk.c
===================================================================
--- asterisk.c	(revision 18749)
+++ asterisk.c	(working copy)
@@ -107,7 +107,6 @@
 #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
@@ -2326,7 +2325,6 @@
 		printf(term_quit());
 		exit(1);
 	}
-	ast_http_init();
 	ast_channels_init();
 	if (init_manager()) {
 		printf(term_quit());
