[asterisk-commits] russell: branch russell/events r80239 - in /team/russell/events: apps/ includ...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Aug 21 22:52:13 CDT 2007


Author: russell
Date: Tue Aug 21 22:52:12 2007
New Revision: 80239

URL: http://svn.digium.com/view/asterisk?view=rev&rev=80239
Log:
convert app_userevent to just create a custom asterisk event instead of manager
event directly

Modified:
    team/russell/events/apps/app_userevent.c
    team/russell/events/include/asterisk/event_defs.h
    team/russell/events/main/event.c

Modified: team/russell/events/apps/app_userevent.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/apps/app_userevent.c?view=diff&rev=80239&r1=80238&r2=80239
==============================================================================
--- team/russell/events/apps/app_userevent.c (original)
+++ team/russell/events/apps/app_userevent.c Tue Aug 21 22:52:12 2007
@@ -38,6 +38,7 @@
 #include "asterisk/module.h"
 #include "asterisk/manager.h"
 #include "asterisk/app.h"
+#include "asterisk/event.h"
 
 static char *app = "UserEvent";
 
@@ -57,12 +58,13 @@
 
 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_event *event;
 
 	if (ast_strlen_zero(data)) {
 		ast_log(LOG_WARNING, "UserEvent requires an argument (eventname,optional event body)\n");
@@ -73,14 +75,16 @@
 
 	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;
-	}
+	event = ast_event_new(AST_EVENT_USER_EVENT,
+		AST_EVENT_IE_NAME, AST_EVENT_IE_PLTYPE_STR, args.eventname,
+		AST_EVENT_IE_END);
+	if (!event)
+		return -1;
 
-	manager_event(EVENT_FLAG_USER, "UserEvent", "UserEvent: %s\r\n%s", args.eventname, buf);
+	for (x = 0; x < args.argc - 1; x++)
+		ast_event_append_ie_str(&event, AST_EVENT_IE_CUSTOM, args.extra[x]);	
+
+	ast_event_queue(event);
 
 	return 0;
 }

Modified: team/russell/events/include/asterisk/event_defs.h
URL: http://svn.digium.com/view/asterisk/team/russell/events/include/asterisk/event_defs.h?view=diff&rev=80239&r1=80238&r2=80239
==============================================================================
--- team/russell/events/include/asterisk/event_defs.h (original)
+++ team/russell/events/include/asterisk/event_defs.h Tue Aug 21 22:52:12 2007
@@ -111,6 +111,13 @@
 	  * Payload type: str
 	  */
 	 AST_EVENT_IE_CONTEXT  = 0x09,
+	 /*!
+	  * \brief Custom IE
+	  * Used by AST_EVENT_USER_EVENT, also useful for 3rd party apps that
+	  * want to create CUSTOM IEs for CUSTOM events.
+	  * Payload type: str
+	  */
+	 AST_EVENT_IE_CUSTOM   = 0x0A,
 };
 
 /*!

Modified: team/russell/events/main/event.c
URL: http://svn.digium.com/view/asterisk/team/russell/events/main/event.c?view=diff&rev=80239&r1=80238&r2=80239
==============================================================================
--- team/russell/events/main/event.c (original)
+++ team/russell/events/main/event.c Tue Aug 21 22:52:12 2007
@@ -413,6 +413,9 @@
 	unsigned int extra_len;
 	uint16_t event_len;
 
+	if (!event || !*event)
+		return -1;
+
 	event_len = ntohs((*event)->event_len);
 	extra_len = sizeof(*ie) + data_len;
 
@@ -675,6 +678,9 @@
 {
 	struct ast_event_ref *event_ref;
 	uint16_t host_event_type;
+
+	if (!event)
+		return -1;
 
 	host_event_type = ntohs(event->type);
 




More information about the asterisk-commits mailing list