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

SVN commits to the Digium repositories svn-commits at lists.digium.com
Fri Aug 28 14:47:18 CDT 2009


Author: marquis
Date: Fri Aug 28 14:47:14 2009
New Revision: 214694

URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214694
Log:
If ever one changes from XEP-0060 to XEP-0248 mode, or changes the whitelist of owners, they'll have to purge the PubSub nodes.  Let's give them a CLI command to accomplish this.

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=214694&r1=214693&r2=214694
==============================================================================
--- team/marquis/pubsub-distributed-events/res/res_jabber.c (original)
+++ team/marquis/pubsub-distributed-events/res/res_jabber.c Fri Aug 28 14:47:14 2009
@@ -249,16 +249,21 @@
 	struct ast_cli_args *a);
 static char *aji_cli_delete_pubsub_node(struct ast_cli_entry *e, int cmd, struct
 	ast_cli_args *a);
+static char *aji_cli_purge_pubsub_nodes(struct ast_cli_entry *e, int cmd, struct
+		ast_cli_args *a);
 static iks *jabber_make_auth(iksid * id, const char *pass, const char *sid);
 static int aji_receive_node_list(void *data, ikspak* pak);
 static void aji_init_event_distribution(struct aji_client *client);
 static iks* aji_create_pubsub_node(struct aji_client *client, const char *node_type,
 	const char *name, const char *collection_name);
-static iks* aji_build_node_config(iks *pubsub, const char *node_type, const char *collection_name);
-static void aji_create_pubsub_collection(struct aji_client *client, const char *collection_name);
+static iks* aji_build_node_config(iks *pubsub, const char *node_type,
+	const char *collection_name);
+static void aji_create_pubsub_collection(struct aji_client *client,
+	const char *collection_name);
 static void aji_create_pubsub_leaf(struct aji_client *client, const char *collection_name,
    const char *leaf_name);
-static char *aji_cli_create_leafnode(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *aji_cli_create_leafnode(struct ast_cli_entry *e, int cmd,
+	struct ast_cli_args *a);
 static void aji_create_affiliations(struct aji_client *client, const char *node);
 static iks* aji_pubsub_iq_create(struct aji_client *client, const char *type);
 static void aji_publish_device_state(struct aji_client *client, const char * device,
@@ -267,6 +272,10 @@
 static int aji_handle_pubsub_event(void *data, ikspak *pak);
 static void aji_pubsub_subscribe(struct aji_client *client, const char *node);
 static void aji_delete_pubsub_node(struct aji_client *client, const char *node_name);
+static iks* aji_build_node_request(struct aji_client *client, const char *collection);
+static int aji_delete_node_list(void *data, ikspak* pak);
+static void aji_pubsub_purge_nodes(struct aji_client *client,
+	const char* collection_name);
 /* No transports in this version */
 /*
 static int aji_create_transport(char *label, struct aji_client *client);
@@ -284,6 +293,7 @@
 	AST_CLI_DEFINE(aji_cli_list_pubsub_nodes, "Lists PubSub nodes"),
 	AST_CLI_DEFINE(aji_cli_create_leafnode, "Creates a PubSub leaf node"),
 	AST_CLI_DEFINE(aji_cli_delete_pubsub_node, "Deletes a PubSub node"),
+	AST_CLI_DEFINE(aji_cli_purge_pubsub_nodes, "Purges PubSub nodes"),
 };
 
 static char *app_ajisend = "JabberSend";
@@ -2707,10 +2717,10 @@
 		orig_request = iks_child(orig_pubsub);
 		error = iks_find_attrib(iks_find(pak->x, "error"), "code");
 		node_name = iks_find_attrib(orig_request, "node");
-		if(!sscanf(error, "%30d", &error_num)) {
+		if (!sscanf(error, "%30d", &error_num)) {
 			return IKS_FILTER_EAT;
 		}
-		if (error_num > 399 && error_num < 500) {
+		if (error_num > 399 && error_num < 500 && error_num != 404) {
 			ast_log(LOG_ERROR,
 				"Error performing operation on PubSub node %s, %s.\n", node_name, error);
 			return IKS_FILTER_EAT;
@@ -2749,11 +2759,35 @@
 /*!
  * \brief Request item list from pubsub
  * \param client the configured XMPP client we use to connect to a XMPP server
+ * \param collection name of the collection for request
  * \return void
  */
 static void aji_request_pubsub_nodes(struct aji_client *client, const char *collection)
 {
 	int res = 0;
+	iks *request = aji_build_node_request(client, collection);
+	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);
+	res = ast_aji_send(client, request);
+	iks_delete(request);
+
+}
+
+/*!
+ * \brief Build the a node request
+ * \param client the configured XMPP client we use to connect to a XMPP server
+ * \param collection name of the collection for request
+ * \return iks*
+ */
+static iks* aji_build_node_request(struct aji_client *client, const char *collection)
+{
 	iks *request = aji_pubsub_iq_create(client, "get");
 	iks *query;
 	query = iks_insert(request, "query");
@@ -2761,14 +2795,8 @@
 	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);
-	res = ast_aji_send(client, request);
-	iks_delete(request);
-
-}
-
+	return request;
+}
 
 /*!
  * \brief Receive pubsub item lists
@@ -2800,7 +2828,7 @@
  * \brief Method to expose PubSub node list via CLI.
  * \param e pointer to ast_cli_entry structure
  * \param cmd
- * \param a pionter to ast_cli_args structure
+ * \param a pointer to ast_cli_args structure
  * \return char *
  */
 static char *aji_cli_list_pubsub_nodes(struct ast_cli_entry *e, int cmd, struct
@@ -2841,14 +2869,92 @@
 }
 
 /*!
+ * \brief Method to purge PubSub nodes via CLI.
+ * \param e pointer to ast_cli_entry structure
+ * \param cmd
+ * \param a pointer to ast_cli_args structure
+ * \return char *
+ */
+static char *aji_cli_purge_pubsub_nodes(struct ast_cli_entry *e, int cmd, struct
+	ast_cli_args *a)
+{
+	struct aji_client *client;
+	const char *name = "asterisk";
+
+	switch (cmd) {
+		case CLI_INIT:
+			e->command = "jabber purge nodes";
+			e->usage =
+					"Usage: jabber purge nodes [name]\n"
+					"       Purges nodes on PubSub server\n"
+					"       as configured in jabber.conf.\n";
+			return NULL;
+		case CLI_GENERATE:
+			return NULL;
+	}
+
+	if (a->argc > 5) {
+		return CLI_SHOWUSAGE;
+	} else if (a->argc == 5) {
+		name = a->argv[3];
+	}
+	if (!(client = ASTOBJ_CONTAINER_FIND(&clients, name))) {
+		ast_cli(a->fd, "Unable to find client '%s'!\n", name);
+		return CLI_FAILURE;
+	}
+	if (ast_test_flag(&globalflags, AJI_XEP0248)) {
+		aji_pubsub_purge_nodes(client, a->argv[4]);
+	} else {
+		aji_delete_pubsub_node(client, a->argv[4]);
+	}
+	return CLI_SUCCESS;
+}
+
+static void aji_pubsub_purge_nodes(struct aji_client *client, const char* collection_name)
+{
+	int res = 0;
+	iks *request = aji_build_node_request(client, collection_name);
+	ast_aji_send(client, request);
+	iks_filter_add_rule(client->f, aji_delete_node_list, client, IKS_RULE_TYPE,
+		IKS_PAK_IQ, IKS_RULE_SUBTYPE, IKS_TYPE_RESULT, IKS_RULE_ID, client->mid,
+  		IKS_RULE_DONE);
+	res = ast_aji_send(client, request);
+	iks_delete(request);
+}
+
+/*!
+ * \brief Delete pubsub item lists
+ * \param data pointer to aji_client structure
+ * \param pak response from pubsub diso#items query
+ * \return IKS_FILTER_EAT
+ */
+static int aji_delete_node_list(void *data, ikspak* pak)
+{
+
+	struct aji_client *client = ASTOBJ_REF((struct aji_client *) data);
+	iks *item;
+	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"));
+		while((item = iks_next_tag(item))) {
+			aji_delete_pubsub_node(client, iks_find_attrib(item, "node"));
+		}
+	}
+	iks_delete(item);
+	return IKS_FILTER_EAT;
+}
+
+
+/*!
  * \brief Method to expose PubSub node deletion via CLI.
  * \param e pointer to ast_cli_entry structure
  * \param cmd
- * \param a pionter to ast_cli_args structure
+ * \param a pointer to ast_cli_args structure
  * \return char *
  */
 static char *aji_cli_delete_pubsub_node(struct ast_cli_entry *e, int cmd, struct
-		ast_cli_args *a)
+	ast_cli_args *a)
 {
 	struct aji_client *client;
 	const char *name = "asterisk";




More information about the svn-commits mailing list