[svn-commits] marquis: branch marquis/pubsub-distributed-events r214268 - /team/marquis/pub...

SVN commits to the Digium repositories svn-commits at lists.digium.com
Wed Aug 26 14:22:54 CDT 2009


Author: marquis
Date: Wed Aug 26 14:22:50 2009
New Revision: 214268

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214268
Log:
Issue and error message and return on a 403 instead of insanely repeating the same request, ad infinitum.  Also, coding guidelines require a space after an 'if', so let's format at least the new code that way. 

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=214268&r1=214267&r2=214268
==============================================================================
--- team/marquis/pubsub-distributed-events/res/res_jabber.c (original)
+++ team/marquis/pubsub-distributed-events/res/res_jabber.c Wed Aug 26 14:22:50 2009
@@ -2506,7 +2506,7 @@
 	if (ast_event_get_type(ast_event) == AST_EVENT_MWI) {
 		ast_log(LOG_ERROR, "Got an MWI event, mailbox: %s\n",
 				ast_event_get_ie_str(ast_event, AST_EVENT_IE_MAILBOX));
-	} else if(ast_event_get_type(ast_event) == AST_EVENT_DEVICE_STATE_CHANGE) {
+	} else if (ast_event_get_type(ast_event) == AST_EVENT_DEVICE_STATE_CHANGE) {
 		device = ast_event_get_ie_str(ast_event, AST_EVENT_IE_DEVICE);
 		device_state = ast_devstate_str(ast_event_get_ie_uint(ast_event, AST_EVENT_IE_STATE));
 		aji_publish_device_state(client, device, device_state);
@@ -2520,11 +2520,11 @@
  */
 static void aji_init_event_distribution(struct aji_client *client)
 {
-	if(!mwi_sub) {
+	if (!mwi_sub) {
 		mwi_sub = ast_event_subscribe(AST_EVENT_MWI, aji_event_cb, "aji_mwi_subscription",
 			client, AST_EVENT_IE_END);
 	}
-	if(!device_state_sub) {
+	if (!device_state_sub) {
 		if (ast_enable_distributed_devstate()) {
 			return;
 		}
@@ -2554,11 +2554,11 @@
 	struct ast_eid pubsub_eid;
 	struct ast_event *event;
 	item = iks_find(iks_find(iks_find(pak->x, "event"), "items"), "item");
-	if(item) {
+	if (item) {
 		device = iks_find_attrib(item, "id");
 		entry = iks_find(item, "entry");
 		state_node = iks_find(entry, "state");
-		if(state_node) {
+		if (state_node) {
 			device_state = iks_find_cdata(entry, "state");
 			ast_str_to_eid(&pubsub_eid, iks_find_attrib(state_node,"eid"));
 			if (!ast_eid_cmp(&ast_eid_default, &pubsub_eid)) {
@@ -2621,7 +2621,7 @@
 	subscribe = iks_insert(pubsub, "subscribe");
 	iks_insert_attrib(subscribe, "jid", client->jid->partial);
 	iks_insert_attrib(subscribe, "node", node);
-	if(ast_test_flag(&globalflags, AJI_XEP0248)) {
+	if (ast_test_flag(&globalflags, AJI_XEP0248)) {
 		iks *options, *x, *sub_options, *sub_type, *sub_depth;
 		options = iks_insert(pubsub, "options");
 		x = iks_insert(options, "x");
@@ -2661,7 +2661,7 @@
 	pubsub = iks_insert(request, "pubsub");
 	iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
 	publish = iks_insert(pubsub, "publish");
-	if(ast_test_flag(&globalflags, AJI_XEP0248)) {
+	if (ast_test_flag(&globalflags, AJI_XEP0248)) {
 		iks_insert_attrib(publish, "node", device);
 	} else {
 		iks_insert_attrib(publish, "node", "device_state");
@@ -2701,13 +2701,19 @@
 	iks *orig_request;
 	iks *orig_pubsub = iks_find(pak->x, "pubsub");
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
-	if(orig_pubsub) {
+	if (orig_pubsub) {
 		orig_request = iks_child(orig_pubsub);
 		node_name = iks_find_attrib(orig_request, "node");
 		
-		if(!strcasecmp(iks_name(orig_request), "publish")) {
-			if(iks_find(iks_find(iks_find(orig_request, "item"), "entry"), "state")) {
-				if(ast_test_flag(&globalflags, AJI_XEP0248)) {
+		if (strcasecmp(iks_find_attrib(iks_find(pak->x, "error"), "code"), "403")) {
+			ast_log(LOG_ERROR,
+				"Error performing operation on PubSub node %s, forbidden.\n", node_name);
+			return IKS_FILTER_EAT;
+		}
+		
+		if (!strcasecmp(iks_name(orig_request), "publish")) {
+			if (iks_find(iks_find(iks_find(orig_request, "item"), "entry"), "state")) {
+				if (ast_test_flag(&globalflags, AJI_XEP0248)) {
 					aji_create_pubsub_leaf(client, "device_state", node_name);
 				} else {
 					aji_create_pubsub_node(client, NULL, node_name, NULL);
@@ -2721,8 +2727,8 @@
 				iks_delete(request);
 				return IKS_FILTER_EAT;
 			}
-		} else if(!strcasecmp(iks_name(orig_request), "subscribe")) {
-			if(ast_test_flag(&globalflags, AJI_XEP0248)) {
+		} else if (!strcasecmp(iks_name(orig_request), "subscribe")) {
+			if (ast_test_flag(&globalflags, AJI_XEP0248)) {
 				aji_create_pubsub_collection(client, node_name);
 			} else {
 				aji_create_pubsub_node(client, NULL, node_name, NULL);
@@ -2737,13 +2743,16 @@
  * \param client the configured XMPP client we use to connect to a XMPP server
  * \return void
  */
-static void aji_request_pubsub_nodes(struct aji_client *client)
+static void aji_request_pubsub_nodes(struct aji_client *client, const char *collection)
 {
 	int res = 0;
 	iks *request = aji_pubsub_iq_create(client, "get");
 	iks *query;
 	query = iks_insert(request, "query");
 	iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
+	if (collection) {
+		iks_insert_attrib(query, "node", collection);
+	}
 	iks_filter_add_rule(client->f, aji_receive_node_list, client, IKS_RULE_TYPE,
 		IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid,
 		IKS_RULE_DONE);
@@ -2764,7 +2773,7 @@
 
 	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
 	iks *item;
-	if(iks_has_children(pak->query)) {	
+	if (iks_has_children(pak->query)) {
 		item = iks_first_tag(pak->query);
 		ast_log(LOG_WARNING, "Connection: %s  Node name: %s\n", client->jid->partial,
 			iks_find_attrib(item, "node"));
@@ -2791,6 +2800,7 @@
 {
 		struct aji_client *client;
 		const char *name = "asterisk";
+		const char *collection = NULL;
 
 		switch (cmd) {
 		case CLI_INIT:
@@ -2804,19 +2814,21 @@
 			return NULL;
 		}
 
-		if (a->argc > 4) {
+		if (a->argc > 5 || a->argc < 4) {
 			return CLI_SHOWUSAGE;
-		} else if (a->argc == 4) {
+		} else if (a->argc == 4 || a->argc == 5) {
 			name = a->argv[3];
 		}
-
+		if (a->argc == 5) {
+			collection = a->argv[4];
+		}
         if (!(client = ASTOBJ_CONTAINER_FIND(&clients, name))) {
 			ast_cli(a->fd, "Unable to find client '%s'!\n", name);
 			return CLI_FAILURE;
 		}
 		
 		ast_cli(a->fd, "Listing pubsub nodes.\n");
-		aji_request_pubsub_nodes(client);
+		aji_request_pubsub_nodes(client, collection);
 		return CLI_SUCCESS;
 }
 
@@ -2939,7 +2951,7 @@
 	iks_insert_attrib(field_owner, "type", "hidden");
 	iks_insert_cdata(iks_insert(field_owner, "value"),
 		"http://jabber.org/protocol/pubsub#owner", 39);
-	if(node_type) {
+	if (node_type) {
 		field_node_type = iks_insert(x, "field");
 		iks_insert_attrib(field_node_type, "var", "pubsub#node_type");
 		iks_insert_cdata(iks_insert(field_node_type, "value"), node_type, strlen(node_type));
@@ -2955,7 +2967,7 @@
 	field_access_model = iks_insert(x, "field");
 	iks_insert_attrib(field_access_model, "var", "pubsub#access_model");
 	iks_insert_cdata(iks_insert(field_access_model, "value"), "whitelist", 9);
-	if(node_type && !strcasecmp(node_type, "leaf")) {
+	if (node_type && !strcasecmp(node_type, "leaf")) {
 		field_pubsub_collection = iks_insert(x, "field");
 		iks_insert_attrib(field_pubsub_collection, "var", "pubsub#collection");
 		iks_insert_cdata(iks_insert(field_pubsub_collection, "value"), collection_name,
@@ -3379,11 +3391,11 @@
 				}
 			}
 		} else if (!strcasecmp(var->name, "distribute_events")) {
-			if(ast_true(var->value)) {
+			if (ast_true(var->value)) {
 				if (client->component) {
 					ast_log(LOG_ERROR, "Client cannot be configured to be both a component and to distribute events!  Event distribution will be disabled.\n");
 				} else {
-					if(ast_test_flag(&globalflags, AJI_PUBSUB)) {
+					if (ast_test_flag(&globalflags, AJI_PUBSUB)) {
 						ast_log(LOG_ERROR, "Only one connection can be configured for distributed events.\n");
 					} else {
 						ast_set_flag(&globalflags, AJI_PUBSUB);
@@ -3742,10 +3754,10 @@
 	ast_unregister_application(app_ajistatus);
 	ast_manager_unregister("JabberSend");
 	ast_custom_function_unregister(&jabberstatus_function);
-	if(mwi_sub) {
+	if (mwi_sub) {
 		ast_event_unsubscribe(mwi_sub);
 	}
-	if(device_state_sub) {
+	if (device_state_sub) {
 		ast_event_unsubscribe(device_state_sub);
 	}
 	ASTOBJ_CONTAINER_TRAVERSE(&clients, 1, {




More information about the svn-commits mailing list