[asterisk-commits] file: branch file/res_xmpp r369003 - /team/file/res_xmpp/res/res_xmpp.c

SVN commits to the Asterisk project asterisk-commits at lists.digium.com
Fri Jun 15 11:00:38 CDT 2012


Author: file
Date: Fri Jun 15 11:00:35 2012
New Revision: 369003

URL: http://svnview.digium.com/svn/asterisk?view=rev&rev=369003
Log:
Incorporate most non-config related review comments.

Modified:
    team/file/res_xmpp/res/res_xmpp.c

Modified: team/file/res_xmpp/res/res_xmpp.c
URL: http://svnview.digium.com/svn/asterisk/team/file/res_xmpp/res/res_xmpp.c?view=diff&rev=369003&r1=369002&r2=369003
==============================================================================
--- team/file/res_xmpp/res/res_xmpp.c (original)
+++ team/file/res_xmpp/res/res_xmpp.c Fri Jun 15 11:00:35 2012
@@ -311,6 +311,9 @@
 /*! \brief Namespace for TLS support */
 #define XMPP_TLS_NS "urn:ietf:params:xml:ns:xmpp-tls"
 
+/*! \brief Status for a disappearing buddy */
+#define STATUS_DISAPPEAR 6
+
 /*! \brief Container for configured XMPP client connections */
 static struct ao2_container *clients;
 
@@ -319,6 +322,9 @@
 
 /*! \brief Enabled pubsub configuration flags */
 static struct ast_flags pubsubflags = { 0 };
+
+/*! \brief Global debug status */
+static int debug;
 
 static int xmpp_client_request_tls(struct ast_xmpp_client *client, int type, iks *node);
 static int xmpp_client_requested_tls(struct ast_xmpp_client *client, int type, iks *node);
@@ -443,14 +449,6 @@
 	struct ast_xmpp_message *message;
 
 	ast_xmpp_client_disconnect(client);
-
-	if (client->filter) {
-		iks_filter_delete(client->filter);
-	}
-
-	if (client->parser) {
-		iks_parser_delete(client->parser);
-	}
 
 	if (client->stack) {
 		iks_stack_delete(client->stack);
@@ -746,6 +744,11 @@
 	struct ao2_iterator i;
 	struct ast_xmpp_buddy *buddy;
 
+	if (!modify_affiliates) {
+		ast_log(LOG_ERROR, "Could not create IQ for creating affiliations on client '%s'\n", client->name);
+		return;
+	}
+
 	pubsub = iks_insert(modify_affiliates, "pubsub");
 	iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub#owner");
 	affiliations = iks_insert(pubsub, "affiliations");
@@ -963,6 +966,11 @@
 {
 	iks *request = xmpp_pubsub_iq_create(client, "set");
 	iks *pubsub, *subscribe;
+
+	if (!request) {
+		ast_log(LOG_ERROR, "Could not create IQ when creating pubsub subscription on client '%s'\n", client->name);
+		return;
+	}
 
 	pubsub = iks_insert(request, "pubsub");
 	iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub");
@@ -1087,10 +1095,14 @@
 			xmpp_pubsub_create_node(client, NULL, node_name, NULL);
 		}
 
-		request = xmpp_pubsub_iq_create(client, "set");
-		iks_insert_node(request, orig_pubsub);
-		ast_xmpp_client_send(client, request);
-		iks_delete(request);
+		if ((request = xmpp_pubsub_iq_create(client, "set"))) {
+			iks_insert_node(request, orig_pubsub);
+			ast_xmpp_client_send(client, request);
+			iks_delete(request);
+		} else {
+			ast_log(LOG_ERROR, "PubSub publish could not create IQ\n");
+		}
+
 		return IKS_FILTER_EAT;
 	} else if (!strcasecmp(iks_name(orig_request), "subscribe")) {
 		if (ast_test_flag(&pubsubflags, XMPP_XEP0248)) {
@@ -2046,7 +2058,7 @@
 		manager_event(EVENT_FLAG_USER, "JabberEvent", "Account: %s\r\nPacket: %s\r\n", client->name, xmpp);
 	}
 
-	if (!ast_test_flag(&client->flags, XMPP_DEBUG)) {
+	if (!debug && !ast_test_flag(&client->flags, XMPP_DEBUG)) {
 		return;
 	}
 
@@ -2727,7 +2739,7 @@
 	struct ast_xmpp_buddy *buddy;
 	struct ast_xmpp_resource *resource;
 	char *type = iks_find_attrib(pak->x, "type");
-	int status = pak->show ? pak->show : 6;
+	int status = pak->show ? pak->show : STATUS_DISAPPEAR;
 
 	/* If no resource is available this is a general buddy presence update, which we will ignore */
 	if (!pak->from->resource) {
@@ -2737,7 +2749,6 @@
 	if (!(buddy = ao2_find(client->buddies, pak->from->partial, OBJ_KEY))) {
 		ast_log(LOG_WARNING, "Received presence information about '%s' despite not having them in roster on client '%s'\n",
 			pak->from->partial, client->name);
-		ao2_unlock(client->buddies);
 		return 0;
 	}
 
@@ -2750,7 +2761,7 @@
 
 	if (!(resource = ao2_find(buddy->resources, pak->from->resource, OBJ_KEY | OBJ_NOLOCK))) {
 		/* Only create the new resource if it is not going away - in reality this should not happen */
-		if (status != 6) {
+		if (status != STATUS_DISAPPEAR) {
 			if (!(resource = ao2_alloc(sizeof(*resource), xmpp_resource_destructor))) {
 				ast_log(LOG_ERROR, "Could not allocate resource object for resource '%s' of buddy '%s' on client '%s'\n",
 					pak->from->resource, buddy->id, client->name);
@@ -2767,7 +2778,7 @@
 	}
 
 	/* Only update the resource and add it back in if it is not going away */
-	if (resource && (status != 6)) {
+	if (resource && (status != STATUS_DISAPPEAR)) {
 		char *node, *ver;
 
 		/* Try to get the XMPP spec node, and fall back to Google if not found */
@@ -2915,7 +2926,7 @@
 	pak = iks_packet(node);
 
 	/* work around iksemel's impossibility to recognize node names
-	 * containing a semicolon. Set the namespace of the corresponding
+	 * containing a colon. Set the namespace of the corresponding
 	 * node accordingly. */
 	if (iks_has_children(node) && strchr(iks_name(iks_child(node)), ':')) {
 		char *node_ns = NULL;
@@ -3088,7 +3099,7 @@
 				}
 			}
 			newbuf[newbufpos] = c;
-			newbufpos ++;
+			newbufpos++;
 			pos++;
 		}
 		pos = 0;
@@ -3150,7 +3161,7 @@
 		}
 
 		if (res == IKS_HOOK) {
-			ast_log(LOG_WARNING, "JABBER: Got hook event.\n");
+			ast_debug(2, "JABBER: Got hook event.\n");
 		} else if (res == IKS_NET_TLSFAIL) {
 			ast_log(LOG_ERROR, "JABBER:  Failure in TLS.\n");
 		} else if (!client->timeout && client->state == XMPP_STATE_CONNECTED) {
@@ -3461,8 +3472,7 @@
 		return 0;
 	}
 
-	if (strchr(screenname, '@') && message) {
-		ast_xmpp_client_send_message(client, screenname, message);
+	if (strchr(screenname, '@') && !ast_xmpp_client_send_message(client, screenname, message)) {
 		astman_append(s, "Response: Success\r\n");
 	} else {
 		astman_append(s, "Response: Error\r\n");
@@ -3489,6 +3499,10 @@
 {
 	iks *request = xmpp_pubsub_iq_create(client, "get"), *query;
 
+	if (!request) {
+		return NULL;
+	}
+
 	query = iks_insert(request, "query");
 	iks_insert_attrib(query, "xmlns", "http://jabber.org/protocol/disco#items");
 
@@ -3536,6 +3550,11 @@
 static void xmpp_pubsub_request_nodes(struct ast_xmpp_client *client, const char *collection)
 {
 	iks *request = xmpp_pubsub_build_node_request(client, collection);
+
+	if (!request) {
+		ast_log(LOG_ERROR, "Could not request pubsub nodes on client '%s' - IQ could not be created\n", client->name);
+		return;
+	}
 
 	iks_filter_add_rule(client->filter, xmpp_pubsub_receive_node_list, client, IKS_RULE_TYPE,
 			    IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid,
@@ -3803,26 +3822,6 @@
 	return CLI_SUCCESS;
 }
 
-/*! \brief Callback function which turns on debugging for a client */
-static int xmpp_client_enable_debug(void *obj, void *arg, int flags)
-{
-	struct ast_xmpp_client *client = obj;
-
-	ast_set_flag(&client->flags, XMPP_DEBUG);
-
-	return 0;
-}
-
-/*! \brief Callback function which turns off debugging for a client */
-static int xmpp_client_disable_debug(void *obj, void *arg, int flags)
-{
-	struct ast_xmpp_client *client = obj;
-
-	ast_clear_flag(&client->flags, XMPP_DEBUG);
-
-	return 0;
-}
-
 /*!
  * \internal
  * \brief Turn on/off console debugging.
@@ -3846,11 +3845,11 @@
 	}
 
 	if (!strncasecmp(a->argv[e->args - 1], "on", 2)) {
-		ao2_callback(clients, OBJ_NODATA | OBJ_MULTIPLE, xmpp_client_enable_debug, NULL);
+		debug = 1;
 		ast_cli(a->fd, "Jabber Debugging Enabled.\n");
 		return CLI_SUCCESS;
 	} else if (!strncasecmp(a->argv[e->args - 1], "off", 3)) {
-		ao2_callback(clients, OBJ_NODATA | OBJ_MULTIPLE, xmpp_client_disable_debug, NULL);
+		debug = 0;
 		ast_cli(a->fd, "Jabber Debugging Disabled.\n");
 		return CLI_SUCCESS;
 	}
@@ -3970,7 +3969,7 @@
 				ast_cli(a->fd, "\t\tResource: %s\n", resource->resource);
 				ast_cli(a->fd, "\t\t\tnode: %s\n", resource->caps.node);
 				ast_cli(a->fd, "\t\t\tversion: %s\n", resource->caps.version);
-				ast_cli(a->fd, "\t\t\tGoogle capable: %s\n", resource->caps.google ? "yes" : "no");
+				ast_cli(a->fd, "\t\t\tGoogle Talk capable: %s\n", resource->caps.google ? "yes" : "no");
 				ast_cli(a->fd, "\t\t\tJingle capable: %s\n", resource->caps.jingle ? "yes" : "no");
 
 				ao2_ref(resource, -1);
@@ -4055,7 +4054,7 @@
 	ast_mutex_init(&messagelock);
 	ast_cond_init(&message_received_condition, NULL);
 
-	return 0;
+	return AST_MODULE_LOAD_SUCCESS;
 
 end:
 	ao2_ref(clients, -1);




More information about the asterisk-commits mailing list