# HG changeset patch # User Mikael Berthe # Date 1139667525 -3600 # Node ID e98abd3ce28c7456e841ffb606604fbcd4e3b4e5 # Parent d3511f846d474929b5b51154115a7c8497863197 Add /request command Usage: /request version|time [jid] diff -r d3511f846d47 -r e98abd3ce28c mcabber/src/commands.c --- a/mcabber/src/commands.c Thu Feb 09 23:25:25 2006 +0100 +++ b/mcabber/src/commands.c Sat Feb 11 15:18:45 2006 +0100 @@ -55,6 +55,7 @@ static void do_room(char *arg); static void do_authorization(char *arg); static void do_version(char *arg); +static void do_request(char *arg); // Global variable for the commands list static GSList *Commands; @@ -99,6 +100,8 @@ cmd_add("msay", "Send a multi-lines message to the selected buddy", COMPL_MULTILINE, 0, &do_msay); cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room); + cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID, + &do_request); cmd_add("quit", "Exit the software", 0, 0, NULL); cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml); cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); @@ -180,6 +183,10 @@ compl_add_category_word(COMPL_AUTH, "allow"); compl_add_category_word(COMPL_AUTH, "cancel"); compl_add_category_word(COMPL_AUTH, "request"); + + // Request (query) category + compl_add_category_word(COMPL_REQUEST, "time"); + compl_add_category_word(COMPL_REQUEST, "version"); } // expandalias(line) @@ -1857,6 +1864,67 @@ scr_LogPrint(LPRINT_NORMAL, "This is mcabber version %s.", PACKAGE_VERSION); } +static void do_request(char *arg) +{ + char **paramlst; + char *jid, *type; + enum iqreq_type numtype; + + paramlst = split_arg(arg, 2, 0); // type, jid + type = *paramlst; + jid = *(paramlst+1); + + if (type) { + // Quick check... + if (!strcasecmp(type, "version")) + numtype = iqreq_version; + else if (!strcasecmp(type, "time")) + numtype = iqreq_time; + } + + if (!type || !numtype) { + scr_LogPrint(LPRINT_NORMAL, + "Please specify a query type (version, time)."); + free_arg_lst(paramlst); + return; + } + + // Allow special jid "" or "." (current buddy) + if (jid && (!*jid || !strcmp(jid, "."))) + jid = NULL; + + if (jid) { + // The JID has been specified. Quick check... + if (check_jid_syntax(jid)) { + scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); + jid = NULL; + } else { + // Convert jid to lowercase + char *p = jid; + for ( ; *p && *p != '/'; p++) + *p = tolower(*p); + } + } else { + // Add the current buddy + if (current_buddy) + jid = (char*)buddy_getjid(BUDDATA(current_buddy)); + if (!jid) + scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); + } + + if (jid) { + switch (numtype) { + case iqreq_version: + case iqreq_time: + jb_request(jid, numtype); + break; + default: + break; + } + } + free_arg_lst(paramlst); +} + static void do_connect(char *arg) { mcabber_connect(); diff -r d3511f846d47 -r e98abd3ce28c mcabber/src/compl.h --- a/mcabber/src/compl.h Thu Feb 09 23:25:25 2006 +0100 +++ b/mcabber/src/compl.h Sat Feb 11 15:18:45 2006 +0100 @@ -17,6 +17,7 @@ #define COMPL_ROOM (1<<12) #define COMPL_RESOURCE (1<<13) #define COMPL_AUTH (1<<14) +#define COMPL_REQUEST (1<<15) void compl_add_category_word(guint, const char *command); void compl_del_category_word(guint categ, const char *word); diff -r d3511f846d47 -r e98abd3ce28c mcabber/src/jabglue.c --- a/mcabber/src/jabglue.c Thu Feb 09 23:25:25 2006 +0100 +++ b/mcabber/src/jabglue.c Sat Feb 11 15:18:45 2006 +0100 @@ -571,9 +571,46 @@ g_free(cleanjid); } -void jb_request_time(const char *fulljid) +void jb_request(const char *jid, enum iqreq_type reqtype) { - request_time(fulljid); + GSList *resources; + GSList *roster_elt; + + if (reqtype == iqreq_none) return; + + if (strchr(jid, '/')) { + // This is a full JID + if (reqtype == iqreq_version) { + request_version(jid); + scr_LogPrint(LPRINT_NORMAL, "Sent version request to <%s>", jid); + } else if (reqtype == iqreq_time) { + request_time(jid); + scr_LogPrint(LPRINT_NORMAL, "Sent time request to <%s>", jid); + } + return; + } + + // The resource has not been specified + roster_elt = roster_find(jid, jidsearch, ROSTER_TYPE_USER|ROSTER_TYPE_ROOM); + if (!roster_elt) { + scr_LogPrint(LPRINT_NORMAL, "User <%s> isn't in the roster."); + return; + } + + // Send a request to each resource + resources = buddy_getresources(roster_elt->data); + for ( ; resources ; resources = g_slist_next(resources) ) { + gchar *fulljid; + fulljid = g_strdup_printf("%s/%s", jid, (char*)resources->data); + if (reqtype == iqreq_version) { + request_version(fulljid); + scr_LogPrint(LPRINT_NORMAL, "Sent version request to <%s>", fulljid); + } else if (reqtype == iqreq_time) { + request_time(fulljid); + scr_LogPrint(LPRINT_NORMAL, "Sent time request to <%s>", fulljid); + } + g_free(fulljid); + } } // Join a MUC room diff -r d3511f846d47 -r e98abd3ce28c mcabber/src/jabglue.h --- a/mcabber/src/jabglue.h Thu Feb 09 23:25:25 2006 +0100 +++ b/mcabber/src/jabglue.h Sat Feb 11 15:18:45 2006 +0100 @@ -20,10 +20,16 @@ // Status chars: '_', 'o', 'i', 'f', 'd', 'n', 'a' enum agtype { - unknown, - groupchat, - transport, - search + unknown, + groupchat, + transport, + search +}; + +enum iqreq_type { + iqreq_none, + iqreq_version, + iqreq_time }; char *compose_jid(const char *username, const char *servername, @@ -55,6 +61,7 @@ int jb_room_setattrib(const char *roomid, const char *jid, const char *nick, struct role_affil ra, const char *reason); void jb_iqs_display_list(void); +void jb_request(const char *jid, enum iqreq_type reqtype); #endif /* __JABGLUE_H__ */