[asterisk-commits] oej: branch oej/bufo-manager-setvar r318053 - in /team/oej/bufo-manager-setva...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Sat May 7 10:46:46 CDT 2011


Author: oej
Date: Sat May  7 10:46:33 2011
New Revision: 318053

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=318053
Log:
Reset stuff

Modified:
    team/oej/bufo-manager-setvar/   (props changed)
    team/oej/bufo-manager-setvar/apps/app_dial.c
    team/oej/bufo-manager-setvar/apps/app_voicemail.c
    team/oej/bufo-manager-setvar/channels/chan_agent.c
    team/oej/bufo-manager-setvar/channels/chan_local.c
    team/oej/bufo-manager-setvar/channels/chan_sip.c
    team/oej/bufo-manager-setvar/channels/chan_skinny.c
    team/oej/bufo-manager-setvar/configs/http.conf.sample
    team/oej/bufo-manager-setvar/configs/skinny.conf.sample
    team/oej/bufo-manager-setvar/configure
    team/oej/bufo-manager-setvar/configure.ac
    team/oej/bufo-manager-setvar/contrib/scripts/safe_asterisk
    team/oej/bufo-manager-setvar/formats/format_wav.c
    team/oej/bufo-manager-setvar/include/asterisk/autoconfig.h.in
    team/oej/bufo-manager-setvar/include/asterisk/select.h
    team/oej/bufo-manager-setvar/main/http.c
    team/oej/bufo-manager-setvar/res/res_agi.c
    team/oej/bufo-manager-setvar/res/res_features.c

Propchange: team/oej/bufo-manager-setvar/
------------------------------------------------------------------------------
    automerge = http://www.codename-pineapple.org/

Propchange: team/oej/bufo-manager-setvar/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Sat May  7 10:46:33 2011
@@ -1,1 +1,1 @@
-/branches/1.4:1-314318
+/branches/1.4:1-318052

Modified: team/oej/bufo-manager-setvar/apps/app_dial.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/apps/app_dial.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/apps/app_dial.c (original)
+++ team/oej/bufo-manager-setvar/apps/app_dial.c Sat May  7 10:46:33 2011
@@ -1453,14 +1453,6 @@
 	time(&start_time);
 	peer = wait_for_answer(chan, outgoing, &to, peerflags, &sentringing, status, sizeof(status), numbusy, numnochan, numcongestion, ast_test_flag(&opts, OPT_PRIORITY_JUMP), &result);
 
-	/* The ast_channel_datastore_remove() function could fail here if the
-	 * datastore was moved to another channel during a masquerade. If this is
-	 * the case, don't free the datastore here because later, when the channel
-	 * to which the datastore was moved hangs up, it will attempt to free this
-	 * datastore again, causing a crash
-	 */
-	if (!ast_channel_datastore_remove(chan, datastore))
-		ast_channel_datastore_free(datastore);
 	if (!peer) {
 		if (result) {
 			res = result;

Modified: team/oej/bufo-manager-setvar/apps/app_voicemail.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/apps/app_voicemail.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/apps/app_voicemail.c (original)
+++ team/oej/bufo-manager-setvar/apps/app_voicemail.c Sat May  7 10:46:33 2011
@@ -3641,7 +3641,8 @@
 		char *ctype = (!strcasecmp(format, "ogg")) ? "application/" : "audio/x-";
 		char tmpdir[256], newtmp[256];
 		int tmpfd = -1;
-	
+		int soxstatus = 0;
+
 		if (vmu->volgain < -.001 || vmu->volgain > .001) {
 			create_dirpath(tmpdir, sizeof(tmpdir), vmu->context, vmu->mailbox, "tmp");
 			snprintf(newtmp, sizeof(newtmp), "%s/XXXXXX", tmpdir);
@@ -3650,7 +3651,6 @@
 			if (option_debug > 2)
 				ast_log(LOG_DEBUG, "newtmp: %s\n", newtmp);
 			if (tmpfd > -1) {
-				int soxstatus;
 				snprintf(tmpcmd, sizeof(tmpcmd), "sox -v %.4f %s.%s %s.%s", vmu->volgain, attach, format, newtmp, format);
 				if ((soxstatus = ast_safe_system(tmpcmd)) == 0) {
 					attach = newtmp;
@@ -3673,7 +3673,9 @@
 		base_encode(fname, p);
 		fprintf(p, ENDL "--%s--" ENDL "." ENDL, bound);
 		if (tmpfd > -1) {
-			unlink(fname);
+			if (soxstatus == 0) {
+				unlink(fname);
+			}
 			close(tmpfd);
 			unlink(newtmp);
 		}

Modified: team/oej/bufo-manager-setvar/channels/chan_agent.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/channels/chan_agent.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/channels/chan_agent.c (original)
+++ team/oej/bufo-manager-setvar/channels/chan_agent.c Sat May  7 10:46:33 2011
@@ -194,9 +194,9 @@
 	char password[AST_MAX_AGENT];  /*!< Password for Agent login */
 	char name[AST_MAX_AGENT];
 	int inherited_devicestate;     /*!< Does the underlying channel have a devicestate to pass? */
-	ast_mutex_t app_lock;          /**< Synchronization between owning applications */
 	int app_lock_flag;
 	ast_cond_t app_complete_cond;
+	ast_cond_t login_wait_cond;
 	volatile int app_sleep_cond;   /**< Sleep condition for the login app */
 	struct ast_channel *owner;     /**< Agent */
 	/**! channel they logged in from. This may also be used to tell if an agent
@@ -384,8 +384,8 @@
 			return NULL;
 		ast_copy_string(p->agent, agt, sizeof(p->agent));
 		ast_mutex_init(&p->lock);
-		ast_mutex_init(&p->app_lock);
 		ast_cond_init(&p->app_complete_cond, NULL);
+		ast_cond_init(&p->login_wait_cond, NULL);
 		p->app_lock_flag = 0;
 		p->app_sleep_cond = 1;
 		p->group = group;
@@ -429,21 +429,26 @@
  */
 static int agent_cleanup(struct agent_pvt *p)
 {
-	struct ast_channel *chan = p->owner;
+	struct ast_channel *chan = NULL;
+	ast_mutex_lock(&p->lock);
+	chan = p->owner;
 	p->owner = NULL;
 	chan->tech_pvt = NULL;
+	/* Release ownership of the agent to other threads (presumably running the login app). */
 	p->app_sleep_cond = 1;
-	/* Release ownership of the agent to other threads (presumably running the login app). */
 	p->app_lock_flag = 0;
 	ast_cond_signal(&p->app_complete_cond);
 	if (chan)
 		ast_channel_free(chan);
 	if (p->dead) {
+		ast_mutex_unlock(&p->lock);
 		ast_mutex_destroy(&p->lock);
-		ast_mutex_destroy(&p->app_lock);
 		ast_cond_destroy(&p->app_complete_cond);
+		ast_cond_destroy(&p->login_wait_cond);
 		free(p);
-        }
+        } else {
+		ast_mutex_unlock(&p->lock);
+	}
 	return 0;
 }
 
@@ -752,22 +757,24 @@
 	int res = -1;
 	int newstate=0;
 	struct ast_channel *chan;
+
 	ast_mutex_lock(&p->lock);
 	p->acknowledged = 0;
+
+	if (p->pending) {
+		ast_log(LOG_DEBUG, "Pretending to dial on pending agent\n");
+		ast_mutex_unlock(&p->lock);
+		ast_setstate(ast, AST_STATE_DIALING);
+		return 0;
+	}
+
 	if (!p->chan) {
-		if (p->pending) {
-			ast_log(LOG_DEBUG, "Pretending to dial on pending agent\n");
-			newstate = AST_STATE_DIALING;
-			res = 0;
-		} else {
-			ast_log(LOG_NOTICE, "Whoa, they hung up between alloc and call...  what are the odds of that?\n");
-			res = -1;
-		}
+		ast_log(LOG_DEBUG, "Agent disconnected while we were connecting the call\n");
 		ast_mutex_unlock(&p->lock);
-		if (newstate)
-			ast_setstate(ast, newstate);
 		return res;
-	} else if (!ast_strlen_zero(p->loginchan)) {
+	}
+
+	if (!ast_strlen_zero(p->loginchan)) {
 		time(&p->start);
 		/* Call on this agent */
 		if (option_verbose > 2)
@@ -798,8 +805,8 @@
 	}
 
 	ast_mutex_lock(&p->lock);
-	if (p->chan != chan) {
-		/* chan went away while we were streaming */
+	if (!p->chan) {
+		/* chan went away while we were streaming, this shouldn't be possible */
 		res = -1;
 	}
 
@@ -899,6 +906,12 @@
 	ast->tech_pvt = NULL;
 	p->app_sleep_cond = 1;
 	p->acknowledged = 0;
+
+	/* Release ownership of the agent to other threads (presumably running the login app). */
+	if (ast_strlen_zero(p->loginchan)) {
+		p->app_lock_flag = 0;
+		ast_cond_signal(&p->app_complete_cond);
+	}
 
 	/* if they really are hung up then set start to 0 so the test
 	 * later if we're called on an already downed channel
@@ -985,8 +998,8 @@
 		p->abouttograb = 0;
 	} else if (p->dead) {
 		ast_mutex_destroy(&p->lock);
-		ast_mutex_destroy(&p->app_lock);
 		ast_cond_destroy(&p->app_complete_cond);
+		ast_cond_destroy(&p->login_wait_cond);
 		free(p);
 	} else {
 		if (p->chan) {
@@ -995,11 +1008,6 @@
 			/* Store last disconnect time */
 			p->lastdisc = ast_tvadd(ast_tvnow(), ast_samp2tv(p->wrapuptime, 1000));
 			ast_mutex_unlock(&p->lock);
-		}
-		/* Release ownership of the agent to other threads (presumably running the login app). */
-		if (ast_strlen_zero(p->loginchan)) {
-			p->app_lock_flag = 0;
-			ast_cond_signal(&p->app_complete_cond);
 		}
 	}
 	return 0;
@@ -1088,7 +1096,6 @@
 static struct ast_channel *agent_new(struct agent_pvt *p, int state)
 {
 	struct ast_channel *tmp;
-	int alreadylocked;
 #if 0
 	if (!p->chan) {
 		ast_log(LOG_WARNING, "No channel? :(\n");
@@ -1131,50 +1138,6 @@
 #endif
 	ast_update_use_count();
 	tmp->priority = 1;
-	/* Wake up and wait for other applications (by definition the login app)
-	 * to release this channel). Takes ownership of the agent channel
-	 * to this thread only.
-	 * For signalling the other thread, ast_queue_frame is used until we
-	 * can safely use signals for this purpose. The pselect() needs to be
-	 * implemented in the kernel for this.
-	 */
-	p->app_sleep_cond = 0;
-
-	alreadylocked = p->app_lock_flag;
-	p->app_lock_flag = 1;
-
-	if(ast_strlen_zero(p->loginchan) && alreadylocked) {
-		if (p->chan) {
-			ast_queue_frame(p->chan, &ast_null_frame);
-			ast_mutex_unlock(&p->lock);	/* For other thread to read the condition. */
-			p->app_lock_flag = 1;
-			ast_mutex_lock(&p->lock);
-		} else {
-			ast_log(LOG_WARNING, "Agent disconnected while we were connecting the call\n");
-			p->owner = NULL;
-			tmp->tech_pvt = NULL;
-			p->app_sleep_cond = 1;
-			ast_channel_free( tmp );
-			ast_mutex_unlock(&p->lock);	/* For other thread to read the condition. */
-			p->app_lock_flag = 0;
-			ast_cond_signal(&p->app_complete_cond);
-			return NULL;
-		}
-	} else if (!ast_strlen_zero(p->loginchan)) {
-		if (p->chan)
-			ast_queue_frame(p->chan, &ast_null_frame);
-		if (!p->chan) {
-			ast_log(LOG_WARNING, "Agent disconnected while we were connecting the call\n");
-			p->owner = NULL;
-			tmp->tech_pvt = NULL;
-			p->app_sleep_cond = 1;
-			ast_channel_free( tmp );
-			ast_mutex_unlock(&p->lock);     /* For other thread to read the condition. */
-			return NULL;
-		}	
-	} 
-	if (p->chan)
-		ast_indicate(p->chan, AST_CONTROL_UNHOLD);
 	return tmp;
 }
 
@@ -1318,8 +1281,8 @@
 			if (!p->owner) {
 				if (!p->chan) {
 					ast_mutex_destroy(&p->lock);
-					ast_mutex_destroy(&p->app_lock);
 					ast_cond_destroy(&p->app_complete_cond);
+					ast_cond_destroy(&p->login_wait_cond);
 					free(p);
 				} else {
 					/* Cause them to hang up */
@@ -1562,6 +1525,47 @@
 	}
 	*cause = hasagent ? AST_CAUSE_BUSY : AST_CAUSE_UNREGISTERED;
 	AST_LIST_UNLOCK(&agents);
+
+	if (chan) {
+		ast_mutex_lock(&p->lock);
+		if (p->pending) {
+			ast_mutex_unlock(&p->lock);
+			return chan;
+		}
+
+		if (!p->chan) {
+			ast_log(LOG_DEBUG, "Agent disconnected while we were connecting the call\n");
+			*cause = AST_CAUSE_UNREGISTERED;
+			ast_mutex_unlock(&p->lock);
+			agent_hangup(chan);
+			return NULL;
+		}
+
+		/* when not in callback mode we need to take control of the channel
+		 * from the login app thread */
+		if(ast_strlen_zero(p->loginchan)) {
+			p->app_sleep_cond = 0;
+			p->app_lock_flag = 1;
+
+			ast_queue_frame(p->chan, &ast_null_frame);
+			ast_cond_wait(&p->login_wait_cond, &p->lock);
+
+			if (!p->chan) {
+				ast_log(LOG_DEBUG, "Agent disconnected while we were connecting the call\n");
+				p->app_sleep_cond = 1;
+				p->app_lock_flag = 0;
+				ast_cond_signal(&p->app_complete_cond);
+				ast_mutex_unlock(&p->lock);
+				*cause = AST_CAUSE_UNREGISTERED;
+				agent_hangup(chan);
+				return NULL;
+			}
+
+			ast_indicate(p->chan, AST_CONTROL_UNHOLD);
+		}
+		ast_mutex_unlock(&p->lock);
+	}
+
 	return chan;
 }
 
@@ -2314,14 +2318,15 @@
 							}
 							ast_mutex_unlock(&p->lock);
 							AST_LIST_UNLOCK(&agents);
+
 							/*	Synchronize channel ownership between call to agent and itself. */
-							ast_mutex_lock(&p->app_lock);
+							ast_mutex_lock(&p->lock);
 							if (p->app_lock_flag == 1) {
-								ast_cond_wait(&p->app_complete_cond, &p->app_lock);
+								ast_cond_signal(&p->login_wait_cond);
+								ast_cond_wait(&p->app_complete_cond, &p->lock);
 							}
-							ast_mutex_unlock(&p->app_lock);
-							ast_mutex_lock(&p->lock);
 							ast_mutex_unlock(&p->lock);
+
 							if (p->ackcall > 1) 
 								res = agent_ack_sleep(p);
 							else
@@ -2337,13 +2342,21 @@
 							sched_yield();
 						}
 						ast_mutex_lock(&p->lock);
-						if (res && p->owner) 
-							ast_log(LOG_WARNING, "Huh?  We broke out when there was still an owner?\n");
 						/* Log us off if appropriate */
 						if (p->chan == chan) {
 							p->chan = NULL;
 							p->inherited_devicestate = -1;
 						}
+
+						/* Synchronize channel ownership between call to agent and itself. */
+						if (p->app_lock_flag == 1) {
+							ast_cond_signal(&p->login_wait_cond);
+							ast_cond_wait(&p->app_complete_cond, &p->lock);
+						}
+
+						if (res && p->owner)
+							ast_log(LOG_WARNING, "Huh?  We broke out when there was still an owner?\n");
+
 						p->acknowledged = 0;
 						logintime = time(NULL) - p->loginstart;
 						p->loginstart = 0;
@@ -2360,8 +2373,8 @@
 						ast_device_state_changed("Agent/%s", p->agent);
 						if (p->dead && !p->owner) {
 							ast_mutex_destroy(&p->lock);
-							ast_mutex_destroy(&p->app_lock);
 							ast_cond_destroy(&p->app_complete_cond);
+							ast_cond_destroy(&p->login_wait_cond);
 							free(p);
 						}
 					}

Modified: team/oej/bufo-manager-setvar/channels/chan_local.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/channels/chan_local.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/channels/chan_local.c (original)
+++ team/oej/bufo-manager-setvar/channels/chan_local.c Sat May  7 10:46:33 2011
@@ -371,8 +371,8 @@
 					}
 					ast_mutex_unlock(&p->owner->lock);
 				}
-				ast_mutex_unlock(&(p->chan->_bridge)->lock);
 			}
+			ast_mutex_unlock(&(p->chan->_bridge)->lock);
 		}
 	}
 }
@@ -430,7 +430,7 @@
 		p->chan = newchan;
 
 	/* Do not let a masquerade cause a Local channel to be bridged to itself! */
-	if (!ast_check_hangup(newchan) && (p->owner->_bridge == p->chan || p->chan->_bridge == p->owner)) {
+	if (!ast_check_hangup(newchan) && ((p->owner && p->owner->_bridge == p->chan) || (p->chan && p->chan->_bridge == p->owner))) {
 		ast_log(LOG_WARNING, "You can not bridge a Local channel to itself!\n");
 		ao2_unlock(p);
 		ast_queue_hangup(newchan);

Modified: team/oej/bufo-manager-setvar/channels/chan_sip.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/channels/chan_sip.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/channels/chan_sip.c (original)
+++ team/oej/bufo-manager-setvar/channels/chan_sip.c Sat May  7 10:46:33 2011
@@ -2770,7 +2770,7 @@
 	ast_free_ha(peer->ha);
 	if (ast_test_flag(&peer->flags[1], SIP_PAGE2_SELFDESTRUCT))
 		apeerobjs--;
-	else if (ast_test_flag(&peer->flags[0], SIP_REALTIME))
+	else if (!ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && ast_test_flag(&peer->flags[0], SIP_REALTIME))
 		rpeerobjs--;
 	else
 		speerobjs--;
@@ -2978,7 +2978,7 @@
 		ast_variables_destroy(user->chanvars);
 		user->chanvars = NULL;
 	}
-	if (ast_test_flag(&user->flags[0], SIP_REALTIME))
+	if (!ast_test_flag(&global_flags[1], SIP_PAGE2_RTCACHEFRIENDS) && ast_test_flag(&user->flags[0], SIP_REALTIME))
 		ruserobjs--;
 	else
 		suserobjs--;
@@ -4973,10 +4973,7 @@
 		return;
 	}
 
-	if (v->via) {
-		ast_free(v->via);
-	}
-
+	ast_free(v->via);
 	ast_free(v);
 }
 
@@ -5099,6 +5096,21 @@
 	return ((ntohl(addr->s_addr) & 0xf0000000) == 0xe0000000);
 }
 
+/*!
+ * \brief Process the Via header according to RFC 3261 section 18.2.2.
+ * \param p a sip_pvt structure that will be modified according to the received
+ * header
+ * \param req a sip request with a Via header to process
+ *
+ * This function will update the destination of the response according to the
+ * Via header in the request and RFC 3261 section 18.2.2. We do not have a
+ * transport layer so we ignore certain values like the 'received' param (we
+ * set the destination address to the addres the request came from in the
+ * respprep() function).
+ *
+ * \retval -1 error
+ * \retval 0 success
+ */
 static int process_via(struct sip_pvt *p, const struct sip_request *req)
 {
 	struct sip_via *via = parse_via(get_header(req, "Via"));
@@ -5123,16 +5135,12 @@
 		p->sa.sin_family = AF_INET;
 		memcpy(&p->sa.sin_addr, hp->h_addr, sizeof(p->sa.sin_addr));
 
-		if (via->port) {
-			p->sa.sin_port = via->port;
-		} else {
-			p->sa.sin_port = STANDARD_SIP_PORT;
-		}
-
 		if (addr_is_multicast(&p->sa.sin_addr)) {
 			setsockopt(sipsock, IPPROTO_IP, IP_MULTICAST_TTL, &via->ttl, sizeof(via->ttl));
 		}
 	}
+
+	p->sa.sin_port = htons(via->port ? via->port : STANDARD_SIP_PORT);
 
 	free_via(via);
 	return 0;
@@ -6785,6 +6793,9 @@
 
 	/* default to routing the response to the address where the request
 	 * came from.  Since we don't have a transport layer, we do this here.
+	 * The process_via() function will update the port to either the port
+	 * specified in the via header or the default port later on (per RFC
+	 * 3261 section 18.2.2).
 	 */
 	p->sa = p->recv;
 
@@ -9029,7 +9040,7 @@
 	char *firstcuri = NULL;
 	int start = 0;
 	int wildcard_found = 0;
-	int single_binding_found;
+	int single_binding_found = 0;
 
 	ast_copy_string(contact, __get_header(req, "Contact", &start), sizeof(contact));
 
@@ -9083,26 +9094,16 @@
 		return PARSE_REGISTER_QUERY;
 	} else if (!strcasecmp(curi, "*") || !expiry) {	/* Unregister this peer */
 		/* This means remove all registrations and return OK */
-		memset(&peer->addr, 0, sizeof(peer->addr));
 		if (!AST_SCHED_DEL(sched, peer->expire)) {
 			struct sip_peer *peer_ptr = peer;
 			ASTOBJ_UNREF(peer_ptr, sip_destroy_peer);
 		}
 
-		destroy_association(peer);
-		
-		register_peer_exten(peer, 0);	/* Add extension from regexten= setting in sip.conf */
-		peer->fullcontact[0] = '\0';
-		peer->useragent[0] = '\0';
-		peer->sipoptions = 0;
-		peer->lastms = 0;
-		peer->portinuri = 0;
-		pvt->expiry = 0;
+		expire_register(ASTOBJ_REF(peer));
 
 		if (option_verbose > 2)
 			ast_verbose(VERBOSE_PREFIX_3 "Unregistered SIP '%s'\n", peer->name);
 
-		manager_event(EVENT_FLAG_SYSTEM, "PeerStatus", "Peer: SIP/%s\r\nPeerStatus: Unregistered\r\n", peer->name);
 		return PARSE_REGISTER_UPDATE;
 	}
 
@@ -11476,6 +11477,7 @@
 	int multi = FALSE;
 	char *name = NULL;
 	regex_t regexbuf;
+	int havepattern = 0;
 
 	switch (argc) {
 	case 4:
@@ -11534,8 +11536,10 @@
 	}
 
 	if (multi && name) {
-		if (regcomp(&regexbuf, name, REG_EXTENDED | REG_NOSUB))
+		if (regcomp(&regexbuf, name, REG_EXTENDED | REG_NOSUB)) {
 			return RESULT_SHOWUSAGE;
+		}
+		havepattern = 1;
 	}
 
 	if (multi) {
@@ -11608,6 +11612,10 @@
 			} else
 				ast_cli(fd, "User '%s' not found.\n", name);
 		}
+	}
+
+	if (havepattern) {
+		regfree(&regexbuf);
 	}
 
 	return RESULT_SUCCESS;

Modified: team/oej/bufo-manager-setvar/channels/chan_skinny.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/channels/chan_skinny.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/channels/chan_skinny.c (original)
+++ team/oej/bufo-manager-setvar/channels/chan_skinny.c Sat May  7 10:46:33 2011
@@ -96,8 +96,13 @@
 #define DEFAULT_SKINNY_PORT	2000
 #define DEFAULT_SKINNY_BACKLOG	2
 #define SKINNY_MAX_PACKET	1000
+#define DEFAULT_AUTH_TIMEOUT	30
+#define DEFAULT_AUTH_LIMIT	50
 
 static int keep_alive = 120;
+static int auth_timeout = DEFAULT_AUTH_TIMEOUT;
+static int auth_limit = DEFAULT_AUTH_LIMIT;
+static int unauth_sessions = 0;
 static char date_format[6] = "D-M-Y";
 static char version_id[16] = "P002F202";
 
@@ -1060,6 +1065,7 @@
 static struct skinnysession {
 	pthread_t t;
 	ast_mutex_t lock;
+	time_t start;
 	struct sockaddr_in sin;
 	int fd;
 	char inbuf[SKINNY_MAX_PACKET];
@@ -3064,6 +3070,7 @@
 		transmit_response(s, req);
 		return 0;
 	}
+	ast_atomic_fetchadd_int(&unauth_sessions, -1);
 	if (option_verbose > 2)
 		ast_verbose(VERBOSE_PREFIX_3 "Device '%s' successfully registered\n", name);
 
@@ -4427,6 +4434,9 @@
 		if (s->fd > -1) {
 			close(s->fd);
 		}
+		if (!s->device) {
+			ast_atomic_fetchadd_int(&unauth_sessions, -1);
+		}
 		ast_mutex_destroy(&s->lock);
 		free(s);
 	} else {
@@ -4439,13 +4449,30 @@
 {
 	int res;
 	int dlen = 0;
+	int timeout = keep_alive * 1100;
+	time_t now;
 	int *bufaddr;
 	struct pollfd fds[1];
+
+	if (!s->device) {
+		if(time(&now) == -1) {
+			ast_log(LOG_ERROR, "error executing time(): %s\n", strerror(errno));
+			return -1;
+		}
+
+		timeout = (auth_timeout - (now - s->start)) * 1000;
+		if (timeout < 0) {
+			/* we have timed out */
+			if (skinnydebug)
+				ast_verbose("Skinny Client failed to authenticate in %d seconds\n", auth_timeout);
+			return -1;
+		}
+	}
 
  	fds[0].fd = s->fd;
 	fds[0].events = POLLIN;
 	fds[0].revents = 0;
-	res = ast_poll(fds, 1, (keep_alive * 1100)); /* If nothing has happen, client is dead */
+	res = ast_poll(fds, 1, timeout); /* If nothing has happen, client is dead */
 						 /* we add 10% to the keep_alive to deal */
 						 /* with network delays, etc */
 	if (res < 0) {
@@ -4454,8 +4481,13 @@
 			return res;
 		}
  	} else if (res == 0) {
-		if (skinnydebug)
-			ast_verbose("Skinny Client was lost, unregistering\n");
+		if (skinnydebug) {
+			if (s->device) {
+				ast_verbose("Skinny Client was lost, unregistering\n");
+			} else {
+				ast_verbose("Skinny Client failed to authenticate in %d seconds\n", auth_timeout);
+			}
+		}
 		skinny_unregister(NULL, s);
 		return -1;
 	}
@@ -4594,18 +4626,35 @@
 			ast_log(LOG_NOTICE, "Accept returned -1: %s\n", strerror(errno));
 			continue;
 		}
+
+		if (ast_atomic_fetchadd_int(&unauth_sessions, +1) >= auth_limit) {
+			close(as);
+			ast_atomic_fetchadd_int(&unauth_sessions, -1);
+			continue;
+		}
+
 		p = getprotobyname("tcp");
 		if(p) {
 			if( setsockopt(as, p->p_proto, TCP_NODELAY, (char *)&arg, sizeof(arg) ) < 0 ) {
 				ast_log(LOG_WARNING, "Failed to set Skinny tcp connection to TCP_NODELAY mode: %s\n", strerror(errno));
 			}
 		}
-		if (!(s = ast_calloc(1, sizeof(struct skinnysession))))
+		if (!(s = ast_calloc(1, sizeof(struct skinnysession)))) {
+			close(as);
+			ast_atomic_fetchadd_int(&unauth_sessions, -1);
 			continue;
+		}
 
 		memcpy(&s->sin, &sin, sizeof(sin));
 		ast_mutex_init(&s->lock);
 		s->fd = as;
+
+		if(time(&s->start) == -1) {
+			ast_log(LOG_ERROR, "error executing time(): %s; disconnecting client\n", strerror(errno));
+			destroy_session(s);
+			continue;
+		}
+
 		ast_mutex_lock(&sessionlock);
 		s->next = sessions;
 		sessions = s;
@@ -4756,6 +4805,24 @@
 			}
 		} else if (!strcasecmp(v->name, "keepalive")) {
 			keep_alive = atoi(v->value);
+		} else if (!strcasecmp(v->name, "authtimeout")) {
+			int timeout = atoi(v->value);
+
+			if (timeout < 1) {
+				ast_log(LOG_WARNING, "Invalid authtimeout value '%s', using default value\n", v->value);
+				auth_timeout = DEFAULT_AUTH_TIMEOUT;
+			} else {
+				auth_timeout = timeout;
+			}
+		} else if (!strcasecmp(v->name, "authlimit")) {
+			int limit = atoi(v->value);
+
+			if (limit < 1) {
+				ast_log(LOG_WARNING, "Invalid authlimit value '%s', using default value\n", v->value);
+				auth_limit = DEFAULT_AUTH_LIMIT;
+			} else {
+				auth_limit = limit;
+			}
 		} else if (!strcasecmp(v->name, "dateformat")) {
 			memcpy(date_format, v->value, sizeof(date_format));
 		} else if (!strcasecmp(v->name, "allow")) {

Modified: team/oej/bufo-manager-setvar/configs/http.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/configs/http.conf.sample?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/configs/http.conf.sample (original)
+++ team/oej/bufo-manager-setvar/configs/http.conf.sample Sat May  7 10:46:33 2011
@@ -26,7 +26,12 @@
 ; requests must begin with /asterisk
 ;
 ;prefix=asterisk
-
+;
+; sessionlimit specifies the maximum number of httpsessions that will be
+; allowed to exist at any given time. (default: 100)
+;
+;sessionlimit=100
+;
 ; The post_mappings section maps URLs to real paths on the filesystem.  If a
 ; POST is done from within an authenticated manager session to one of the
 ; configured POST mappings, then any files in the POST will be placed in the

Modified: team/oej/bufo-manager-setvar/configs/skinny.conf.sample
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/configs/skinny.conf.sample?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/configs/skinny.conf.sample (original)
+++ team/oej/bufo-manager-setvar/configs/skinny.conf.sample Sat May  7 10:46:33 2011
@@ -8,6 +8,15 @@
 			; "A" may also be used, but it must be at the end.
 			; Use M for month, D for day, Y for year, A for 12-hour time.
 keepalive=120
+
+;authtimeout = 30       ; authtimeout specifies the maximum number of seconds a
+			; client has to authenticate.  If the client does not
+			; authenticate beofre this timeout expires, the client
+                        ; will be disconnected.  (default: 30 seconds)
+
+;authlimit = 50         ; authlimit specifies the maximum number of
+			; unauthenticated sessions that will be allowed to
+                        ; connect at any given time. (default: 50)
 
 ;allow=all		; see doc/rtp-packetization for framing options
 ;disallow=

Modified: team/oej/bufo-manager-setvar/configure.ac
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/configure.ac?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/configure.ac (original)
+++ team/oej/bufo-manager-setvar/configure.ac Sat May  7 10:46:33 2011
@@ -159,11 +159,15 @@
 AC_PATH_PROG([LN], [ln], :)
 AC_PATH_PROG([DOT], [dot], :)
 AC_PATH_PROG([WGET], [wget], :)
+AC_PATH_PROG([CURL], [curl], :)
 if test "${WGET}" != ":" ; then
   DOWNLOAD=${WGET}
+else if test "${CURL}" != ":" ; then
+  DOWNLOAD="${CURL} -O --progress-bar -w \"%{url_effective}\n\""
 else
   AC_PATH_PROG([FETCH], [fetch], [:])
   DOWNLOAD=${FETCH}
+fi
 fi
 AC_SUBST(DOWNLOAD)
 

Modified: team/oej/bufo-manager-setvar/contrib/scripts/safe_asterisk
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/contrib/scripts/safe_asterisk?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/contrib/scripts/safe_asterisk (original)
+++ team/oej/bufo-manager-setvar/contrib/scripts/safe_asterisk Sat May  7 10:46:33 2011
@@ -28,7 +28,7 @@
 
 # Check if Asterisk is already running.  If it is, then bug out, because
 # starting safe_asterisk when Asterisk is running is very bad.
-VERSION=`${ASTSBINDIR}/asterisk -rx 'core show version'`
+VERSION=`${ASTSBINDIR}/asterisk -nrx 'core show version'`
 if test "`echo $VERSION | cut -c 1-8`" = "Asterisk" ; then
 	echo "Asterisk is already running.  $0 will exit now."
 	exit 1

Modified: team/oej/bufo-manager-setvar/formats/format_wav.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/formats/format_wav.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/formats/format_wav.c (original)
+++ team/oej/bufo-manager-setvar/formats/format_wav.c Sat May  7 10:46:33 2011
@@ -87,13 +87,68 @@
 #endif
 
 
-static int check_header(FILE *f)
-{
-	int type, size, formtype;
-	int fmt, hsize;
+static int check_header_fmt(FILE *f, int hsize)
+{
 	short format, chans, bysam, bisam;
 	int bysec;
 	int freq;
+	if (hsize < 16) {
+		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
+		return -1;
+	}
+	if (fread(&format, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (format)\n");
+		return -1;
+	}
+	if (ltohs(format) != 1) {
+		ast_log(LOG_WARNING, "Not a wav file %d\n", ltohs(format));
+		return -1;
+	}
+	if (fread(&chans, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (format)\n");
+		return -1;
+	}
+	if (ltohs(chans) != 1) {
+		ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
+		return -1;
+	}
+	if (fread(&freq, 1, 4, f) != 4) {
+		ast_log(LOG_WARNING, "Read failed (freq)\n");
+		return -1;
+	}
+	if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
+		ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
+		return -1;
+	}
+	/* Ignore the byte frequency */
+	if (fread(&bysec, 1, 4, f) != 4) {
+		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SECOND)\n");
+		return -1;
+	}
+	/* Check bytes per sample */
+	if (fread(&bysam, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SAMPLE)\n");
+		return -1;
+	}
+	if (ltohs(bysam) != 2) {
+		ast_log(LOG_WARNING, "Can only handle 16bits per sample: %d\n", ltohs(bysam));
+		return -1;
+	}
+	if (fread(&bisam, 1, 2, f) != 2) {
+		ast_log(LOG_WARNING, "Read failed (Bits Per Sample): %d\n", ltohs(bisam));
+		return -1;
+	}
+	/* Skip any additional header */
+	if (fseek(f,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
+		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 );
+		return -1;
+	}
+	return 0;
+}
+
+static int check_header(FILE *f)
+{
+	int type, size, formtype;
 	int data;
 	if (fread(&type, 1, 4, f) != 4) {
 		ast_log(LOG_WARNING, "Read failed (type)\n");
@@ -114,69 +169,6 @@
 	}
 	if (memcmp(&formtype, "WAVE", 4)) {
 		ast_log(LOG_WARNING, "Does not contain WAVE\n");
-		return -1;
-	}
-	if (fread(&fmt, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (fmt)\n");
-		return -1;
-	}
-	if (memcmp(&fmt, "fmt ", 4)) {
-		ast_log(LOG_WARNING, "Does not say fmt\n");
-		return -1;
-	}
-	if (fread(&hsize, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (formtype)\n");
-		return -1;
-	}
-	if (ltohl(hsize) < 16) {
-		ast_log(LOG_WARNING, "Unexpected header size %d\n", ltohl(hsize));
-		return -1;
-	}
-	if (fread(&format, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (format)\n");
-		return -1;
-	}
-	if (ltohs(format) != 1) {
-		ast_log(LOG_WARNING, "Not a wav file %d\n", ltohs(format));
-		return -1;
-	}
-	if (fread(&chans, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (format)\n");
-		return -1;
-	}
-	if (ltohs(chans) != 1) {
-		ast_log(LOG_WARNING, "Not in mono %d\n", ltohs(chans));
-		return -1;
-	}
-	if (fread(&freq, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (freq)\n");
-		return -1;
-	}
-	if (ltohl(freq) != DEFAULT_SAMPLE_RATE) {
-		ast_log(LOG_WARNING, "Unexpected frequency %d\n", ltohl(freq));
-		return -1;
-	}
-	/* Ignore the byte frequency */
-	if (fread(&bysec, 1, 4, f) != 4) {
-		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SECOND)\n");
-		return -1;
-	}
-	/* Check bytes per sample */
-	if (fread(&bysam, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (BYTES_PER_SAMPLE)\n");
-		return -1;
-	}
-	if (ltohs(bysam) != 2) {
-		ast_log(LOG_WARNING, "Can only handle 16bits per sample: %d\n", ltohs(bysam));
-		return -1;
-	}
-	if (fread(&bisam, 1, 2, f) != 2) {
-		ast_log(LOG_WARNING, "Read failed (Bits Per Sample): %d\n", ltohs(bisam));
-		return -1;
-	}
-	/* Skip any additional header */
-	if (fseek(f,ltohl(hsize)-16,SEEK_CUR) == -1 ) {
-		ast_log(LOG_WARNING, "Failed to skip remaining header bytes: %d\n", ltohl(hsize)-16 );
 		return -1;
 	}
 	/* Skip any facts and get the first data block */
@@ -186,23 +178,25 @@
 	    
 	    /* Begin data chunk */
 	    if (fread(&buf, 1, 4, f) != 4) {
-			ast_log(LOG_WARNING, "Read failed (data)\n");
+			ast_log(LOG_WARNING, "Read failed (block header format)\n");
 			return -1;
 	    }
 	    /* Data has the actual length of data in it */
 	    if (fread(&data, 1, 4, f) != 4) {
-			ast_log(LOG_WARNING, "Read failed (data)\n");
+			ast_log(LOG_WARNING, "Read failed (block '%.4s' header length)\n", buf);
 			return -1;
 	    }
 	    data = ltohl(data);
+		if (memcmp(&buf, "fmt ", 4) == 0) {
+			if (check_header_fmt(f, data))
+				return -1;
+			continue;
+		}
 	    if(memcmp(buf, "data", 4) == 0 ) 
 			break;
-	    if(memcmp(buf, "fact", 4) != 0 ) {
-			ast_log(LOG_WARNING, "Unknown block - not fact or data\n");
-			return -1;
-	    }
+		ast_log(LOG_DEBUG, "Skipping unknown block '%.4s'\n", buf);
 	    if (fseek(f,data,SEEK_CUR) == -1 ) {
-			ast_log(LOG_WARNING, "Failed to skip fact block: %d\n", data );
+			ast_log(LOG_WARNING, "Failed to skip '%.4s' block: %d\n", buf, data);
 			return -1;
 	    }
 	}

Modified: team/oej/bufo-manager-setvar/include/asterisk/autoconfig.h.in
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/include/asterisk/autoconfig.h.in?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/include/asterisk/autoconfig.h.in (original)
+++ team/oej/bufo-manager-setvar/include/asterisk/autoconfig.h.in Sat May  7 10:46:33 2011
@@ -487,7 +487,7 @@
 /* Define to 1 if you have the `strtoq' function. */
 #undef HAVE_STRTOQ
 
-/* Define to 1 if `st_blksize' is member of `struct stat'. */
+/* Define to 1 if `st_blksize' is a member of `struct stat'. */
 #undef HAVE_STRUCT_STAT_ST_BLKSIZE
 
 /* Define to 1 if you have the mISDN Supplemental Services library. */
@@ -680,11 +680,11 @@
 /* Define to the one symbol short name of this package. */
 #undef PACKAGE_TARNAME
 
+/* Define to the home page for this package. */
+#undef PACKAGE_URL
+
 /* Define to the version of this package. */
 #undef PACKAGE_VERSION
-
-/* Define to 1 if the C compiler supports function prototypes. */
-#undef PROTOTYPES
 
 /* Define to necessary symbol if this constant uses a non-standard name on
    your system. */
@@ -704,11 +704,6 @@
 
 /* Define to the type of arg 5 for `select'. */
 #undef SELECT_TYPE_ARG5
-
-/* Define to 1 if the `setvbuf' function takes the buffering type as its
-   second argument and the buffer pointer as the third, as on System V before
-   release 3. */
-#undef SETVBUF_REVERSED
 
 /* The size of `fd_set.fds_bits', as computed by sizeof. */
 #undef SIZEOF_FD_SET_FDS_BITS
@@ -742,23 +737,33 @@
 /* Define to a type of the same size as fd_set.fds_bits[[0]] */
 #undef TYPEOF_FD_SET_FDS_BITS
 
-/* Define to 1 if on AIX 3.
-   System headers sometimes define this.
-   We just want to avoid a redefinition error message.  */
+/* Enable extensions on AIX 3, Interix.  */
 #ifndef _ALL_SOURCE
 # undef _ALL_SOURCE
 #endif
-
-/* Define to 1 if running on Darwin. */
-#undef _DARWIN_UNLIMITED_SELECT
-
-/* Number of bits in a file offset, on hosts where this is settable. */
-#undef _FILE_OFFSET_BITS
-
 /* Enable GNU extensions on systems that have them.  */
 #ifndef _GNU_SOURCE
 # undef _GNU_SOURCE
 #endif
+/* Enable threading extensions on Solaris.  */
+#ifndef _POSIX_PTHREAD_SEMANTICS
+# undef _POSIX_PTHREAD_SEMANTICS
+#endif
+/* Enable extensions on HP NonStop.  */
+#ifndef _TANDEM_SOURCE
+# undef _TANDEM_SOURCE
+#endif
+/* Enable general extensions on Solaris.  */
+#ifndef __EXTENSIONS__
+# undef __EXTENSIONS__
+#endif
+
+
+/* Define to 1 if running on Darwin. */
+#undef _DARWIN_UNLIMITED_SELECT
+
+/* Number of bits in a file offset, on hosts where this is settable. */
+#undef _FILE_OFFSET_BITS
 
 /* Define to 1 to make fseeko visible on some hosts (e.g. glibc 2.2). */
 #undef _LARGEFILE_SOURCE
@@ -775,20 +780,6 @@
 
 /* Define to 1 if you need to in order for `stat' and other things to work. */
 #undef _POSIX_SOURCE
-
-/* Enable extensions on Solaris.  */
-#ifndef __EXTENSIONS__
-# undef __EXTENSIONS__
-#endif
-#ifndef _POSIX_PTHREAD_SEMANTICS
-# undef _POSIX_PTHREAD_SEMANTICS
-#endif
-#ifndef _TANDEM_SOURCE
-# undef _TANDEM_SOURCE
-#endif
-
-/* Define like PROTOTYPES; this can be used by system headers. */
-#undef __PROTOTYPES
 
 /* Define to empty if `const' does not conform to ANSI C. */
 #undef const

Modified: team/oej/bufo-manager-setvar/include/asterisk/select.h
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/include/asterisk/select.h?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/include/asterisk/select.h (original)
+++ team/oej/bufo-manager-setvar/include/asterisk/select.h Sat May  7 10:46:33 2011
@@ -42,12 +42,14 @@
 	TYPEOF_FD_SET_FDS_BITS fds_bits[ast_FDMAX / 8 / SIZEOF_FD_SET_FDS_BITS]; /* 32768 bits */
 } ast_fdset;
 
+#define _bitsize(a)	(sizeof(a) * 8)
+
 #undef FD_ZERO
 #define FD_ZERO(a) \
 	do { \
 		TYPEOF_FD_SET_FDS_BITS *bytes = (TYPEOF_FD_SET_FDS_BITS *) a; \
 		int i; \
-		for (i = 0; i < sizeof(*(a)) / SIZEOF_FD_SET_FDS_BITS; i++) { \
+		for (i = 0; i < ast_FDMAX / _bitsize(TYPEOF_FD_SET_FDS_BITS); i++) { \
 			bytes[i] = 0; \
 		} \
 	} while (0)
@@ -55,10 +57,12 @@
 #define FD_SET(fd, fds) \
 	do { \
 		TYPEOF_FD_SET_FDS_BITS *bytes = (TYPEOF_FD_SET_FDS_BITS *) fds; \
-		if (fd / sizeof(*bytes) + ((fd + 1) % sizeof(*bytes) ? 1 : 0) < sizeof(*(fds))) { \
-			bytes[fd / (sizeof(*bytes) * 8)] |= ((TYPEOF_FD_SET_FDS_BITS) 1) << (fd % (sizeof(*bytes) * 8)); \
+		/* 32bit: FD / 32 + ((FD + 1) % 32 ? 1 : 0) < 1024 */ \
+		/* 64bit: FD / 64 + ((FD + 1) % 64 ? 1 : 0) < 512 */ \
+		if (fd / _bitsize(*bytes) + ((fd + 1) % _bitsize(*bytes) ? 1 : 0) < sizeof(*(fds)) / SIZEOF_FD_SET_FDS_BITS) { \
+			bytes[fd / _bitsize(*bytes)] |= ((TYPEOF_FD_SET_FDS_BITS) 1) << (fd % _bitsize(*bytes)); \
 		} else { \
-			ast_log(LOG_ERROR, "FD %d exceeds the maximum size of ast_fdset!\n", fd); \
+			fprintf(stderr, "FD %d exceeds the maximum size of ast_fdset!\n", fd); \
 		} \
 	} while (0)
 #endif /* HAVE_VARIABLE_FDSET */

Modified: team/oej/bufo-manager-setvar/main/http.c
URL: http://svnview.digium.com/svn/asterisk/team/oej/bufo-manager-setvar/main/http.c?view=diff&rev=318053&r1=318052&r2=318053
==============================================================================
--- team/oej/bufo-manager-setvar/main/http.c (original)
+++ team/oej/bufo-manager-setvar/main/http.c Sat May  7 10:46:33 2011
@@ -60,6 +60,7 @@
 
 #define MAX_PREFIX 80
 #define DEFAULT_PREFIX "/asterisk"
+#define DEFAULT_SESSION_LIMIT 100
 
 struct ast_http_server_instance {
 	FILE *f;
@@ -77,6 +78,8 @@
 static int prefix_len;
 static struct sockaddr_in oldsin;
 static int enablestatic;
+static int session_limit = DEFAULT_SESSION_LIMIT;
+static int session_count = 0;
 
 /*! \brief Limit the kinds of files we're willing to serve up */
 static struct {
@@ -516,6 +519,7 @@
 	}
 	fclose(ser->f);
 	free(ser);
+	ast_atomic_fetchadd_int(&session_count, -1);
 	return NULL;
 }
 
@@ -534,15 +538,23 @@
 		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;
 		}
+
+		if (ast_atomic_fetchadd_int(&session_count, +1) >= session_limit) {
+			close(fd);
+			continue;
+		}
+
 		ser = ast_calloc(1, sizeof(*ser));
 		if (!ser) {
 			ast_log(LOG_WARNING, "No memory for new session: %s\n", strerror(errno));
 			close(fd);
+			ast_atomic_fetchadd_int(&session_count, -1);
 			continue;
 		}
 		flags = fcntl(fd, F_GETFL);
@@ -557,12 +569,14 @@
 				ast_log(LOG_WARNING, "Unable to launch helper thread: %s\n", strerror(errno));
 				fclose(ser->f);
 				free(ser);
+				ast_atomic_fetchadd_int(&session_count, -1);
 			}
 			pthread_attr_destroy(&attr);

[... 85 lines stripped ...]



More information about the asterisk-commits mailing list