[asterisk-commits] seanbright: branch group/asterisk-cpp r169435 - in /team/group/asterisk-cpp: ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Mon Jan 19 14:43:08 CST 2009


Author: seanbright
Date: Mon Jan 19 14:43:07 2009
New Revision: 169435

URL: http://svn.digium.com/svn-view/asterisk?view=rev&rev=169435
Log:
Merged revisions 169365,169367,169369 via svnmerge from 
https://origsvn.digium.com/svn/asterisk/trunk

................
  r169365 | tilghman | 2009-01-19 15:05:52 -0500 (Mon, 19 Jan 2009) | 11 lines
  
  Merged revisions 169364 via svnmerge from 
  https://origsvn.digium.com/svn/asterisk/branches/1.4
  
  ........
    r169364 | tilghman | 2009-01-19 13:49:25 -0600 (Mon, 19 Jan 2009) | 4 lines
    
    Truncate userevents at the end of a line, when the command exceeds the buffer.
    (closes issue #14278)
     Reported by: fnordian
  ........
................
  r169367 | mvanbaak | 2009-01-19 15:09:11 -0500 (Mon, 19 Jan 2009) | 15 lines
  
  Redo the event-based MWI in chan_skinny.
  
  Dan saw regular segfaults with the old implementation and
  rewrote it to make it really eventbased.
  I altered it to be trunk compatible and wedhorn gave some feedback
  and ideas how to make it even better.
  
  (closes issue #13821)
  Reported by: DEA
  Patches:
        chan_skinny-mwi-events.txt uploaded by DEA (license 3)
  Tested by: mvanbaak, DEA
  
  "no probs by me" from wedhorn
................
  r169369 | mvanbaak | 2009-01-19 15:14:27 -0500 (Mon, 19 Jan 2009) | 7 lines
  
  fix assignment in swapmode plug.
  Spotted and fix provided by ys
  
  (closes issue #14129)
  Reported by: ys
  Tested by: ys
................

Modified:
    team/group/asterisk-cpp/   (props changed)
    team/group/asterisk-cpp/apps/app_userevent.c
    team/group/asterisk-cpp/channels/chan_skinny.c
    team/group/asterisk-cpp/main/asterisk.c
    team/group/asterisk-cpp/main/manager.c

Propchange: team/group/asterisk-cpp/
------------------------------------------------------------------------------
    automerge = *

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

Propchange: team/group/asterisk-cpp/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Jan 19 14:43:07 2009
@@ -1,1 +1,1 @@
-/trunk:1-169334
+/trunk:1-169434

Modified: team/group/asterisk-cpp/apps/app_userevent.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/asterisk-cpp/apps/app_userevent.c?view=diff&rev=169435&r1=169434&r2=169435
==============================================================================
--- team/group/asterisk-cpp/apps/app_userevent.c (original)
+++ team/group/asterisk-cpp/apps/app_userevent.c Mon Jan 19 14:43:07 2009
@@ -58,15 +58,22 @@
 
 static int userevent_exec(struct ast_channel *chan, void *data)
 {
-	char *parse, buf[2048] = "";
-	int x, buflen = 0;
+	char *parse;
+	int x;
 	AST_DECLARE_APP_ARGS(args,
 		AST_APP_ARG(eventname);
 		AST_APP_ARG(extra)[100];
 	);
+	struct ast_str *body = ast_str_create(16);
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
+		ast_free(body);
+		return -1;
+	}
+
+	if (!body) {
+		ast_log(LOG_WARNING, "Unable to allocate buffer\n");
 		return -1;
 	}
 
@@ -75,13 +82,11 @@
 	AST_STANDARD_APP_ARGS(args, parse);
 
 	for (x = 0; x < args.argc - 1; x++) {
-		ast_copy_string(buf + buflen, args.extra[x], sizeof(buf) - buflen - 2);
-		buflen += strlen(args.extra[x]);
-		ast_copy_string(buf + buflen, "\r\n", 3);
-		buflen += 2;
+		ast_str_append(&body, 0, "%s\r\n", args.extra[x]);
 	}
 
-	manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, buf);
+	manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, ast_str_buffer(body));
+	ast_free(body);
 
 	return 0;
 }

Modified: team/group/asterisk-cpp/channels/chan_skinny.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/asterisk-cpp/channels/chan_skinny.c?view=diff&rev=169435&r1=169434&r2=169435
==============================================================================
--- team/group/asterisk-cpp/channels/chan_skinny.c (original)
+++ team/group/asterisk-cpp/channels/chan_skinny.c Mon Jan 19 14:43:07 2009
@@ -1192,6 +1192,7 @@
 	AST_LIST_ENTRY(skinny_line) all;
 	struct skinny_device *device;
 	struct ast_variable *chanvars; /*!< Channel variables to set for inbound call */
+	int newmsgs;
 };
 
 struct skinny_line_options{
@@ -1321,6 +1322,7 @@
 static int skinny_senddigit_begin(struct ast_channel *ast, char digit);
 static int skinny_senddigit_end(struct ast_channel *ast, char digit, unsigned int duration);
 static int handle_time_date_req_message(struct skinny_req *req, struct skinnysession *s);
+static void mwi_event_cb(const struct ast_event *event, void *userdata);
 
 static const struct ast_channel_tech skinny_tech = {
 	.type = "Skinny",
@@ -1849,8 +1851,11 @@
 					/* l->capability = d->capability;
 					l->prefs = d->prefs; */
 					l->instance = instance;
+					l->newmsgs = ast_app_has_voicemail(l->mailbox, NULL);
 					set_callforwards(l, NULL, 0);
 					register_exten(l);
+					/* initialize MWI on line and device */
+					mwi_event_cb(0, l);
 					ast_devstate_changed(AST_DEVICE_NOT_INUSE, "Skinny/%s@%s", l->name, d->name);
 				}
 				--instance;
@@ -2503,65 +2508,44 @@
 
 static void mwi_event_cb(const struct ast_event *event, void *userdata)
 {
-	/* This module does not handle MWI in an event-based manner.  However, it
-	 * subscribes to MWI for each mailbox that is configured so that the core
-	 * knows that we care about it.  Then, chan_skinny will get the MWI from the
-	 * event cache instead of checking the mailbox directly. */
-}
-
-static int has_voicemail(struct skinny_line *l)
-{
-	int new_msgs;
-	struct ast_event *event;
-	char *mbox, *context;
-
-	context = mbox = ast_strdupa(l->mailbox);
-	strsep(&context, "@");
-	if (ast_strlen_zero(context))
-		context = "default";
-
-	event = ast_event_get_cached(AST_EVENT_MWI,
-		AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, mbox,
-		AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, context,
-		AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,
-		AST_EVENT_IE_END);
-
-	if (event) {
-		new_msgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
-		ast_event_destroy(event);
-	} else
-		new_msgs = ast_app_has_voicemail(l->mailbox, NULL);
-
-	return new_msgs;
+	struct skinny_line *l = userdata;
+	struct skinny_device *d = l->device;
+	struct skinnysession *s = d->session;
+	struct skinny_line *l2;
+	int new_msgs = 0;
+	int dev_msgs = 0;
+
+	if (s) {
+		if (event) {
+			l->newmsgs = ast_event_get_ie_uint(event, AST_EVENT_IE_NEWMSGS);
+		}
+
+		if (l->newmsgs) {
+			transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
+		} else {
+			transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF);
+		}
+
+		/* find out wether the device lamp should be on or off */
+		AST_LIST_TRAVERSE(&d->lines, l2, list) {
+			if (l2->newmsgs) {
+				dev_msgs++;
+			}
+		}
+
+		if (dev_msgs) {
+			transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, d->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
+		} else {
+			transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF);
+		}
+		ast_verb(3, "Skinny mwi_event_cb found %d new messages\n", new_msgs);
+	}
 }
 
 static void do_housekeeping(struct skinnysession *s)
 {
-	int device_lamp = 0;
-	struct skinny_device *d = s->device;
-	struct skinny_line *l;
-
 	/* Update time on device */
 	handle_time_date_req_message(NULL, s);
-
-	/* Set MWI on individual lines */
-	AST_LIST_TRAVERSE(&d->lines, l, list) {
-		if (has_voicemail(l)) {
-			if (skinnydebug)
-				ast_verb(1, "Checking for voicemail Skinny %s@%s\n", l->name, d->name);
-			if (skinnydebug)
-				ast_verb(1, "Skinny %s@%s has voicemail!\n", l->name, d->name);
-			transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, l->mwiblink?SKINNY_LAMP_BLINK:SKINNY_LAMP_ON);
-			device_lamp++;
-		} else {
-			transmit_lamp_indication(d, STIMULUS_VOICEMAIL, l->instance, SKINNY_LAMP_OFF);
-		}
-	}
-	/* If at least one line has VM, turn the device level lamp on */
-	if (device_lamp)
-		transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_ON);
-	else
-		transmit_lamp_indication(d, STIMULUS_VOICEMAIL, 0, SKINNY_LAMP_OFF);
 }
 
 /* I do not believe skinny can deal with video.
@@ -6599,7 +6583,7 @@
  		strsep(&cfg_context, "@");
  		if (ast_strlen_zero(cfg_context))
  			 cfg_context = "default";
- 		l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, NULL,
+		l->mwi_event_sub = ast_event_subscribe(AST_EVENT_MWI, mwi_event_cb, l,
  			AST_EVENT_IE_MAILBOX, AST_EVENT_IE_PLTYPE_STR, cfg_mailbox,
  			AST_EVENT_IE_CONTEXT, AST_EVENT_IE_PLTYPE_STR, cfg_context,
  			AST_EVENT_IE_NEWMSGS, AST_EVENT_IE_PLTYPE_EXISTS,

Modified: team/group/asterisk-cpp/main/asterisk.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/asterisk-cpp/main/asterisk.c?view=diff&rev=169435&r1=169434&r2=169435
==============================================================================
--- team/group/asterisk-cpp/main/asterisk.c (original)
+++ team/group/asterisk-cpp/main/asterisk.c Mon Jan 19 14:43:07 2009
@@ -551,7 +551,7 @@
 #elif defined(HAVE_SYSCTL) && !defined(HAVE_SYSINFO)
 static int swapmode(int *used, int *total)
 {
-	used = total = 0;
+	*used = *total = 0;
 	return 1;
 }
 #endif

Modified: team/group/asterisk-cpp/main/manager.c
URL: http://svn.digium.com/svn-view/asterisk/team/group/asterisk-cpp/main/manager.c?view=diff&rev=169435&r1=169434&r2=169435
==============================================================================
--- team/group/asterisk-cpp/main/manager.c (original)
+++ team/group/asterisk-cpp/main/manager.c Mon Jan 19 14:43:07 2009
@@ -913,6 +913,8 @@
  *       initialize the thread local storage key.
  */
 AST_THREADSTORAGE(astman_append_buf);
+AST_THREADSTORAGE(userevent_buf);
+
 /*! \brief initial allocated size for the astman_append_buf */
 #define ASTMAN_APPEND_BUF_INITSIZE   256
 
@@ -2607,18 +2609,15 @@
 static int action_userevent(struct mansession *s, const struct message *m)
 {
 	const char *event = astman_get_header(m, "UserEvent");
-	char body[2048] = "";
-	unsigned int x, bodylen = 0;
-	for (x = 0; x < m->hdrcount; x++) {
+	struct ast_str *body = ast_str_thread_get(&userevent_buf, 16);
+
+	for (size_t x = 0; x < m->hdrcount; x++) {
 		if (strncasecmp("UserEvent:", m->headers[x], strlen("UserEvent:"))) {
-			ast_copy_string(body + bodylen, m->headers[x], sizeof(body) - bodylen - 3);
-			bodylen += strlen(m->headers[x]);
-			ast_copy_string(body + bodylen, "\r\n", 3);
-			bodylen += 2;
-		}
-	}
-
-	manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, body);
+			ast_str_append(&body, 0, "%s\r\n", m->headers[x]);
+		}
+	}
+
+	manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", event, ast_str_buffer(body));
 	return 0;
 }
 




More information about the asterisk-commits mailing list