# HG changeset patch # User Mikael Berthe # Date 1128448070 -7200 # Node ID 882e1acae4223dc4a7c91ff00a874db432246a36 # Parent b82428ac107d958ff797792717281279d8e53022 Add /say_to command diff -r b82428ac107d -r 882e1acae422 mcabber/doc/mcabber.1 --- a/mcabber/doc/mcabber.1 Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/doc/mcabber.1 Tue Oct 04 19:47:50 2005 +0200 @@ -232,6 +232,10 @@ Send the text message to the currently selected buddy\&. Can be useful if you want to send a message beginning with a slash, for example\&. .TP +\fB/say_to\fR jid text +Send the text message to the specified jid\&. Please note that this command doesn't set the default resource for a contact, so if you want to send several messages to a specific ressource you will have to use "/say_to" for each message\&. + +.TP \fB/status\fR [online|avail|invisible|free|dnd|notavail|away [StatusMessage]] Set the current status\&. If no status is specified, display the current status\&. If a status message is specified, it will overrride the message* variables\&. diff -r b82428ac107d -r 882e1acae422 mcabber/doc/mcabber.1.html --- a/mcabber/doc/mcabber.1.html Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/doc/mcabber.1.html Tue Oct 04 19:47:50 2005 +0200 @@ -611,6 +611,15 @@ if you want to send a message beginning with a slash, for example.
+/say_to jid text +
+
+ Send the text message to the specified jid. + Please note that this command doesn't set the default resource for + a contact, so if you want to send several messages to a specific + ressource you will have to use "/say_to" for each message. +
+
/status [online|avail|invisible|free|dnd|notavail|away [StatusMessage]]
@@ -653,7 +662,7 @@ diff -r b82428ac107d -r 882e1acae422 mcabber/doc/mcabber.1.txt --- a/mcabber/doc/mcabber.1.txt Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/doc/mcabber.1.txt Tue Oct 04 19:47:50 2005 +0200 @@ -208,6 +208,12 @@ Send the text message to the currently selected buddy. Can be useful if you want to send a message beginning with a slash, for example. +/say_to jid text:: + Send the text message to the specified jid. + Please note that this command doesn't set the default resource for + a contact, so if you want to send several messages to a specific + ressource you will have to use "/say_to" for each message. + /status [online|avail|invisible|free|dnd|notavail|away [StatusMessage]]:: Set the current status. If no status is specified, display the current status. + diff -r b82428ac107d -r 882e1acae422 mcabber/src/commands.c --- a/mcabber/src/commands.c Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/src/commands.c Tue Oct 04 19:47:50 2005 +0200 @@ -40,6 +40,7 @@ static void do_group(char *arg); static void do_say(char *arg); static void do_msay(char *arg); +static void do_say_to(char *arg); static void do_buffer(char *arg); static void do_clear(char *arg); static void do_info(char *arg); @@ -101,6 +102,7 @@ cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, &do_roster); cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say); + cmd_add("say_to", "Say something to a specific buddy", 0, 0, &do_say_to); //cmd_add("search"); //cmd_add("send_auth"); cmd_add("set", "Set/query an option value", 0, 0, &do_set); @@ -652,6 +654,54 @@ scr_set_multimode(FALSE); } +static void do_say_to(char *arg) +{ + char *jid, *msg; + char *bare_jid, *p; + + if (!jb_getonline()) { + scr_LogPrint(LPRINT_NORMAL, "You are not connected"); + return; + } + + msg = strchr(arg, ' '); + if (!msg) { + scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); + return; + } + + jid = g_strndup(arg, msg - arg); + + if (check_jid_syntax(jid)) { + scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", jid); + g_free(jid); + return; + } + + while (*msg == ' ') msg++; + if (!*msg) { + scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); + g_free(jid); + return; + } + + // We must use the bare jid in hk_message_out() + p = strchr(jid, '/'); + if (p) bare_jid = g_strndup(jid, p - jid); + else bare_jid = jid; + + // Jump to window, create one if needed + scr_RosterJumpJid(bare_jid); + + // local part (UI, logging, etc.) + hk_message_out(bare_jid, 0, msg); + + // Network part + jb_send_msg(jid, msg, ROSTER_TYPE_USER, NULL); + g_free(jid); + if (p) g_free(bare_jid); +} + static void do_buffer(char *arg) { int search_dir = 0; diff -r b82428ac107d -r 882e1acae422 mcabber/src/roster.c --- a/mcabber/src/roster.c Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/src/roster.c Tue Oct 04 19:47:50 2005 +0200 @@ -175,7 +175,7 @@ // Comparison function used to search in the roster (compares jids and types) static gint roster_compare_jid_type(roster *a, roster *b) { if (! (a->type & b->type)) - return -1; // arbitrary (but should be != , of course) + return -1; // arbitrary (but should be != 0, of course) return strcasecmp(a->jid, b->jid); } @@ -197,7 +197,7 @@ if (!jidname) return NULL; if (!roster_type) - roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM | + roster_type = ROSTER_TYPE_USER | ROSTER_TYPE_ROOM | ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP; sample.type = roster_type; @@ -893,6 +893,25 @@ return roster_usr->flags; } +// buddy_search_jid(jid) +// Look for a buddy with specified jid. +// Search begins at buddylist; if no match is found in the the buddylist, +// return NULL; +GList *buddy_search_jid(char *jid) +{ + GList *buddy; + roster *roster_usr; + + if (!buddylist) return NULL; + + for (buddy = buddylist; buddy; buddy = g_list_next(buddy)) { + roster_usr = (roster*)buddy->data; + if (roster_usr->jid && !strcasecmp(roster_usr->jid, jid)) + return buddy; + } + return NULL; +} + // buddy_search(string) // Look for a buddy whose name or jid contains string. // Search begins at current_buddy; if no match is found in the the buddylist, diff -r b82428ac107d -r 882e1acae422 mcabber/src/roster.h --- a/mcabber/src/roster.h Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/src/roster.h Tue Oct 04 19:47:50 2005 +0200 @@ -84,6 +84,7 @@ void buddy_del_all_resources(gpointer rosterdata); void buddy_setflags(gpointer rosterdata, guint flags, guint value); guint buddy_getflags(gpointer rosterdata); +GList *buddy_search_jid(char *jid); GList *buddy_search(char *string); gpointer unread_msg(gpointer rosterdata); diff -r b82428ac107d -r 882e1acae422 mcabber/src/screen.c --- a/mcabber/src/screen.c Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/src/screen.c Tue Oct 04 19:47:50 2005 +0200 @@ -777,8 +777,8 @@ doupdate(); } -void scr_WriteMessage(const char *jid, const char *text, time_t timestamp, - guint prefix_flags) +inline void scr_WriteMessage(const char *jid, const char *text, + time_t timestamp, guint prefix_flags) { if (!timestamp) timestamp = time(NULL); @@ -918,6 +918,27 @@ scr_ShowBuddyWindow(); } +// scr_RosterJumpJid(jid) +// Jump to buddy jid. +// NOTE: With this function, the buddy is added to the roster if doesn't exist. +void scr_RosterJumpJid(char *barejid) +{ + GSList *roster_elt; + // Look for an existing buddy + roster_elt = roster_find(barejid, jidsearch, + ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM); + // Create it if necessary + if (!roster_elt) + roster_elt = roster_add_user(barejid, NULL, NULL, ROSTER_TYPE_USER); + // Set a lock to see it in the buddylist + buddy_setflags(BUDDATA(roster_elt), ROSTER_FLAG_LOCK, TRUE); + buddylist_build(); + // Jump to the buddy + set_current_buddy(buddy_search_jid(barejid)); + if (chatmode) + scr_ShowBuddyWindow(); +} + // scr_RosterUnreadMessage(next) // Go to a new message. If next is not null, try to go to the next new // message. If it is not possible or if next is NULL, go to the first new diff -r b82428ac107d -r 882e1acae422 mcabber/src/screen.h --- a/mcabber/src/screen.h Mon Oct 03 23:59:56 2005 +0200 +++ b/mcabber/src/screen.h Tue Oct 04 19:47:50 2005 +0200 @@ -51,6 +51,7 @@ void scr_RosterUp(void); void scr_RosterDown(void); void scr_RosterSearch(char *); +void scr_RosterJumpJid(char *); void scr_BufferTopBottom(int topbottom); void scr_BufferClear(void); void scr_BufferSearch(int direction, const char *text);