[asterisk-commits] marquis: branch marquis/pubsub-distributed-events r214151 - /team/marquis/pub...
SVN commits to the Asterisk project
asterisk-commits at lists.digium.com
Tue Aug 25 17:25:53 CDT 2009
Author: marquis
Date: Tue Aug 25 17:25:49 2009
New Revision: 214151
URL: http://svn.asterisk.org/svn-view/asterisk?view=rev&rev=214151
Log:
Add ability to delete nodes from the CLI.
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=214151&r1=214150&r2=214151
==============================================================================
--- team/marquis/pubsub-distributed-events/res/res_jabber.c (original)
+++ team/marquis/pubsub-distributed-events/res/res_jabber.c Tue Aug 25 17:25:49 2009
@@ -243,8 +243,12 @@
static int aji_register_query_handler(void *data, ikspak *pak);
static int aji_register_approve_handler(void *data, ikspak *pak);
static int aji_reconnect(struct aji_client *client);
-static char *aji_cli_create_collection(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
-static char *aji_cli_list_pubsub_nodes(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a);
+static char *aji_cli_create_collection(struct ast_cli_entry *e, int cmd,
+ struct ast_cli_args *a);
+static char *aji_cli_list_pubsub_nodes(struct ast_cli_entry *e, int cmd,
+ 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 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);
@@ -262,6 +266,7 @@
static int aji_handle_pubsub_error(void *data, ikspak *pak);
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);
/* No transports in this version */
/*
static int aji_create_transport(char *label, struct aji_client *client);
@@ -275,9 +280,10 @@
AST_CLI_DEFINE(aji_show_clients, "Show state of clients and components"),
AST_CLI_DEFINE(aji_show_buddies, "Show buddy lists of our clients"),
AST_CLI_DEFINE(aji_test, "Shows roster, but is generally used for mog's debugging."),
- AST_CLI_DEFINE(aji_cli_create_collection, "Creates a test PubSub node collection."),
- AST_CLI_DEFINE(aji_cli_list_pubsub_nodes, "Lists Pubsub nodes"),
- AST_CLI_DEFINE(aji_cli_create_leafnode, "Creates a test Pubsub leaf node"),
+ AST_CLI_DEFINE(aji_cli_create_collection, "Creates a PubSub node collection."),
+ 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"),
};
static char *app_ajisend = "JabberSend";
@@ -2600,7 +2606,7 @@
}
/*!
- * \brief Subscribe to a Pubsub node
+ * \brief Subscribe to a PubSub node
* \param client the configured XMPP client we use to connect to a XMPP server
* \param node the name of the node to which to subscribe
* \return void
@@ -2791,7 +2797,7 @@
e->command = "jabber list nodes";
e->usage =
"Usage: jabber list nodes [name]\n"
- " Lists nodes on Pubsub server\n"
+ " Lists nodes on PubSub server\n"
" as configured in jabber.conf.\n";
return NULL;
case CLI_GENERATE:
@@ -2812,6 +2818,61 @@
ast_cli(a->fd, "Listing pubsub nodes.\n");
aji_request_pubsub_nodes(client);
return CLI_SUCCESS;
+}
+
+/*!
+ * \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
+ * \return char *
+ */
+static char *aji_cli_delete_pubsub_node(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 delete node";
+ e->usage =
+ "Usage: jabber delete node [name]\n"
+ " Deletes a node 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;
+ }
+ aji_delete_pubsub_node(client, a->argv[4]);
+ return CLI_SUCCESS;
+}
+
+/*!
+ * \brief Delete a PubSub node
+ * \param client the configured XMPP client we use to connect to a XMPP server
+ * \param node_name the name of the node to delete
+ * return void
+ */
+static void aji_delete_pubsub_node(struct aji_client *client, const char *node_name)
+{
+ iks *request = aji_pubsub_iq_create(client, "set");
+ iks *pubsub, *delete;
+ pubsub = iks_insert(request, "pubsub");
+ iks_insert_attrib(pubsub, "xmlns", "http://jabber.org/protocol/pubsub#owner");
+ delete = iks_insert(pubsub, "delete");
+ iks_insert_attrib(delete, "node", node_name);
+ ast_aji_send(client, request);
}
/*!
More information about the asterisk-commits
mailing list