--- res/res_jabber.c +++ res/res_jabber.c @@ -366,6 +366,7 @@ static void aji_mwi_cb(const struct ast_event *ast_event, void *data); static iks* aji_build_publish_skeleton(struct aji_client *client, const char *node, const char *event_type); +static char *aji_gtalk_set_invisible(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a); /* No transports in this version */ /* static int aji_create_transport(char *label, struct aji_client *client); @@ -384,6 +385,7 @@ 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"), + AST_CLI_DEFINE(aji_gtalk_set_invisible, "Sets Google Talk client invisible/visible"), }; static char *app_ajisend = "JabberSend"; @@ -4161,6 +4163,83 @@ /*! * \internal + * \brief Set Google Talk client invisible + * \return CLI_SUCCESS,CLI_FAILURE. + */ +static char *aji_gtalk_set_invisible(struct ast_cli_entry *e, int cmd, struct ast_cli_args *a) +{ + struct aji_client *client; + const char *name; + iks *iq = NULL, *qry = NULL, *invisible = NULL; + int err; + char *retval; + + switch (cmd) { + case CLI_INIT: + e->command = "jabber set invisible {on|off}"; + e->usage = + "Usage: jabber set invisible {on|off} \n" + " Sets Google Talk client invisible/visible\n"; + return NULL; + case CLI_GENERATE: + return NULL; + } + + if (a->argc != 5 || + (strncasecmp(a->argv[3], "on", 2) && strncasecmp(a->argv[3], "off", 3))) + return CLI_SHOWUSAGE; + + name = a->argv[4]; + if (!(client = ASTOBJ_CONTAINER_FIND(&clients, name))) { + ast_cli(a->fd, "Unable to find client '%s'!\n", name); + return CLI_FAILURE; + } + + iq = iks_new("iq"); + qry = iks_new("query"); + invisible = iks_new("invisible"); + + if (iq && qry && invisible) { + iks_insert_attrib(iq, "type", "get"); + iks_insert_attrib(iq, "to", client->jid->partial); + iks_insert_attrib(qry, "xmlns", "google:shared-status"); + iks_insert_attrib(qry, "version", "2"); + iks_insert_node(iq, qry); + err = ast_aji_send(client, iq); + + if (err == IKS_OK) { + iks_insert_attrib(iq, "type", "set"); + if (!strncasecmp(a->argv[3], "on", 2)) + iks_insert_attrib(invisible, "value", "true"); + else + iks_insert_attrib(invisible, "value", "false"); + iks_insert_node(qry, invisible); + err = ast_aji_send(client, iq); + } + + if (err != IKS_OK) { + ast_cli(a->fd, "Error sending command.\n"); + retval = CLI_FAILURE; + } else { + ast_cli(a->fd, "Invisible set %s.\n", a->argv[3]); + retval = CLI_SUCCESS; + } + + iks_delete(iq); + iks_delete(qry); + iks_delete(invisible); + } else { + ast_log(LOG_ERROR, "Out of memory.\n"); + retval = CLI_FAILURE; + } + + ASTOBJ_UNREF(client, aji_client_destroy); + return retval; +} + + +/*! + * \internal * \brief Send test message for debugging. * \return CLI_SUCCESS,CLI_FAILURE. */