[asterisk-commits] marquis: branch marquis/pubsub-distributed-events r215251 - /team/marquis/pub...

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Tue Sep 1 16:31:39 CDT 2009


Author: marquis
Date: Tue Sep  1 16:31:35 2009
New Revision: 215251

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=215251
Log:
With this commit, the branch is functionally complete.  Now I just need to test some more and write some documentation about how it all works...

Modified:
    team/marquis/pubsub-distributed-events/res/res_jabber.c

Modified: team/marquis/pubsub-distributed-events/res/res_jabber.c
URL: http://svn.asterisk.org/svn-view/asterisk/team/marquis/pubsub-distributed-events/res/res_jabber.c?view=diff&rev=215251&r1=215250&r2=215251
==============================================================================
--- team/marquis/pubsub-distributed-events/res/res_jabber.c (original)
+++ team/marquis/pubsub-distributed-events/res/res_jabber.c Tue Sep  1 16:31:35 2009
@@ -2588,32 +2588,50 @@
  */
 static int aji_handle_pubsub_event(void *data, ikspak *pak)
 {
-	char *device, *device_state;
-	iks *item, *state_node;
+	char *item_id, *device_state, *context;
+	int oldmsgs, newmsgs;
+	iks *item, *item_content;
 	struct ast_eid pubsub_eid;
 	struct ast_event *event;
 	item = iks_find(iks_find(iks_find(pak->x, "event"), "items"), "item");
-	if (item) {
-		device = iks_find_attrib(item, "id");
-		state_node = iks_find(item, "state");
-		if (state_node) {
-			device_state = iks_find_cdata(item, "state");
-			ast_str_to_eid(&pubsub_eid, iks_find_attrib(state_node,"eid"));
-			if (!ast_eid_cmp(&ast_eid_default, &pubsub_eid)) {
-				ast_log(LOG_DEBUG, "Returning here, eid of incoming event matches ours!\n");
-				return IKS_FILTER_EAT;
-			}
-			if (!(event = ast_event_new(AST_EVENT_DEVICE_STATE_CHANGE,
-				AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, device, AST_EVENT_IE_STATE,
-				AST_EVENT_IE_PLTYPE_UINT, ast_devstate_val(device_state), AST_EVENT_IE_EID,
-				AST_EVENT_IE_PLTYPE_RAW, &pubsub_eid, sizeof(pubsub_eid),
-				AST_EVENT_IE_END))) {
-				return IKS_FILTER_EAT;
-			}
-
-			ast_event_queue_and_cache(event);
-		}
-	}
+	if (!item) {
+		ast_log(LOG_ERROR, "Could not parse incoming PubSub event\n");
+		return IKS_FILTER_EAT;
+	}
+	item_id = iks_find_attrib(item, "id");
+	item_content = iks_child(item);
+	ast_str_to_eid(&pubsub_eid, iks_find_attrib(item_content,"eid"));
+	if (!ast_eid_cmp(&ast_eid_default, &pubsub_eid)) {
+		ast_log(LOG_DEBUG, "Returning here, eid of incoming event matches ours!\n");
+		return IKS_FILTER_EAT;
+	}
+	if (!strcasecmp(iks_name(item_content), "state")) {
+		device_state = iks_find_cdata(item, "state");
+		if (!(event = ast_event_new(AST_EVENT_DEVICE_STATE_CHANGE,
+			AST_EVENT_IE_DEVICE, AST_EVENT_IE_PLTYPE_STR, item_id, AST_EVENT_IE_STATE,
+			AST_EVENT_IE_PLTYPE_UINT, ast_devstate_val(device_state), AST_EVENT_IE_EID,
+			AST_EVENT_IE_PLTYPE_RAW, &pubsub_eid, sizeof(pubsub_eid),
+			AST_EVENT_IE_END))) {
+			return IKS_FILTER_EAT;
+		}
+	} else if (!strcasecmp(iks_name(item_content), "mailbox")) {
+		context = strsep(&item_id, "@");
+		sscanf(iks_find_cdata(item_content, "OLDMSGS"), "%10d", &oldmsgs);
+		sscanf(iks_find_cdata(item_content, "NEWMSGS"), "%10d", &newmsgs);
+		if (!(event = ast_event_new(AST_EVENT_MWI, AST_EVENT_IE_MAILBOX,
+			AST_EVENT_IE_PLTYPE_STR, item_id, AST_EVENT_IE_CONTEXT,
+			AST_EVENT_IE_PLTYPE_STR, context, AST_EVENT_IE_OLDMSGS,
+			AST_EVENT_IE_PLTYPE_UINT, oldmsgs, AST_EVENT_IE_NEWMSGS,
+			AST_EVENT_IE_PLTYPE_UINT, newmsgs, AST_EVENT_IE_EID, AST_EVENT_IE_PLTYPE_RAW,
+			&pubsub_eid, sizeof(pubsub_eid), AST_EVENT_IE_END))) {
+			return IKS_FILTER_EAT;
+		}
+	} else {
+		ast_log(LOG_DEBUG, "Don't know how to handle PubSub event of type %s\n",
+			iks_name(item_content));
+		return IKS_FILTER_EAT;
+	}
+	ast_event_queue_and_cache(event);
 	return IKS_FILTER_EAT;
 }
 




More information about the asterisk-commits mailing list