annotate mcabber/src/commands.c @ 866:b30df2ab457f

Add "/buffer purge"
author Mikael Berthe <mikael@lilotux.net>
date Wed, 24 May 2006 22:29:05 +0200
parents cee8d6be04e1
children 7f056c566569
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
1 /*
699
ee03b56b93ee Update Copyright (2006)
Mikael Berthe <mikael@lilotux.net>
parents: 696
diff changeset
2 * commands.c -- user commands handling
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
3 *
699
ee03b56b93ee Update Copyright (2006)
Mikael Berthe <mikael@lilotux.net>
parents: 696
diff changeset
4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.lilotux.net>
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
5 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
9 * your option) any later version.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
10 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
14 * General Public License for more details.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
15 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
19 * USA
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
20 */
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
21
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
22 #include <string.h>
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
23
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
24 #include "commands.h"
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
25 #include "jabglue.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
26 #include "roster.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
27 #include "screen.h"
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
28 #include "compl.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 108
diff changeset
29 #include "hooks.h"
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
30 #include "hbuf.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
31 #include "utils.h"
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
32 #include "settings.h"
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
33 #include "events.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
34
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
35 // Commands callbacks
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
36 static void do_roster(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
37 static void do_status(char *arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
38 static void do_status_to(char *arg);
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
39 static void do_add(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
40 static void do_del(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
41 static void do_group(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
42 static void do_say(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
43 static void do_msay(char *arg);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
44 static void do_say_to(char *arg);
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
45 static void do_buffer(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
46 static void do_clear(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
47 static void do_info(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
48 static void do_rename(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
49 static void do_move(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
50 static void do_set(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
51 static void do_alias(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
52 static void do_bind(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
53 static void do_connect(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
54 static void do_disconnect(char *arg);
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
55 static void do_rawxml(char *arg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
56 static void do_room(char *arg);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
57 static void do_authorization(char *arg);
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
58 static void do_version(char *arg);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
59 static void do_request(char *arg);
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
60 static void do_event(char *arg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
61
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
62 // Global variable for the commands list
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
63 static GSList *Commands;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
64
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
65
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
66 // cmd_add()
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
67 // Adds a command to the commands list and to the CMD completion list
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
68 static void cmd_add(const char *name, const char *help,
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
69 guint flags_row1, guint flags_row2, void (*f)())
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
70 {
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
71 cmd *n_cmd = g_new0(cmd, 1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
72 strncpy(n_cmd->name, name, 32-1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
73 n_cmd->help = help;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
74 n_cmd->completion_flags[0] = flags_row1;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
75 n_cmd->completion_flags[1] = flags_row2;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
76 n_cmd->func = f;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
77 Commands = g_slist_append(Commands, n_cmd);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
78 // Add to completion CMD category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
79 compl_add_category_word(COMPL_CMD, name);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
80 }
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
81
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
82 // cmd_init()
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
83 // Commands table initialization
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
84 void cmd_init(void)
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
85 {
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
86 cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add);
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
87 cmd_add("alias", "Add an alias", 0, 0, &do_alias);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
88 cmd_add("authorization", "Manage subscription authorizations",
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
89 COMPL_AUTH, COMPL_JID, &do_authorization);
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
90 cmd_add("bind", "Add an key binding", 0, 0, &do_bind);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
91 cmd_add("buffer", "Manipulate current buddy's buffer (chat window)",
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
92 COMPL_BUFFER, 0, &do_buffer);
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
93 cmd_add("clear", "Clear the dialog window", 0, 0, &do_clear);
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
94 cmd_add("connect", "Connect to the server", 0, 0, &do_connect);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 191
diff changeset
95 cmd_add("del", "Delete the current buddy", 0, 0, &do_del);
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
96 cmd_add("disconnect", "Disconnect from server", 0, 0, &do_disconnect);
757
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 755
diff changeset
97 cmd_add("event", "Process an event", COMPL_EVENTSID, COMPL_EVENTS, &do_event);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
98 cmd_add("group", "Change group display settings", COMPL_GROUP, 0, &do_group);
262
ab6f83a82811 Do not add /help to command completion, as it isn't implemented yet.
mikael@frmp8452
parents: 260
diff changeset
99 //cmd_add("help", "Display some help", COMPL_CMD, 0, NULL);
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
100 cmd_add("info", "Show basic info on current buddy", 0, 0, &do_info);
225
d5ae42cbe1fa [/trunk] Changeset 237 by mikael
mikael
parents: 221
diff changeset
101 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
d5ae42cbe1fa [/trunk] Changeset 237 by mikael
mikael
parents: 221
diff changeset
102 0, &do_move);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
103 cmd_add("msay", "Send a multi-lines message to the selected buddy",
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
104 COMPL_MULTILINE, 0, &do_msay);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
105 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
106 cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID,
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
107 &do_request);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
108 cmd_add("quit", "Exit the software", 0, 0, NULL);
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
109 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
110 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
111 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
112 &do_roster);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
113 cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say);
488
9e8519078e00 Enable jid completion for /say_to
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
114 cmd_add("say_to", "Say something to a specific buddy", COMPL_JID, 0,
9e8519078e00 Enable jid completion for /say_to
Mikael Berthe <mikael@lilotux.net>
parents: 486
diff changeset
115 &do_say_to);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
116 //cmd_add("search");
310
29b27c8692ea Post-0.6.3 changes
Mikael Berthe <mikael@lilotux.net>
parents: 308
diff changeset
117 cmd_add("set", "Set/query an option value", 0, 0, &do_set);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
118 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
119 cmd_add("status_to", "Show or set your status for one recipient",
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
120 COMPL_JID, COMPL_STATUS, &do_status_to);
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
121 cmd_add("version", "Show mcabber version", 0, 0, &do_version);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
122
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
123 // Status category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
124 compl_add_category_word(COMPL_STATUS, "online");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
125 compl_add_category_word(COMPL_STATUS, "avail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
126 compl_add_category_word(COMPL_STATUS, "invisible");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
127 compl_add_category_word(COMPL_STATUS, "free");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
128 compl_add_category_word(COMPL_STATUS, "dnd");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
129 compl_add_category_word(COMPL_STATUS, "notavail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
130 compl_add_category_word(COMPL_STATUS, "away");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
131
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
132 // Roster category
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
133 compl_add_category_word(COMPL_ROSTER, "bottom");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
134 compl_add_category_word(COMPL_ROSTER, "top");
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
135 compl_add_category_word(COMPL_ROSTER, "up");
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
136 compl_add_category_word(COMPL_ROSTER, "down");
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
137 compl_add_category_word(COMPL_ROSTER, "hide");
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
138 compl_add_category_word(COMPL_ROSTER, "show");
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
139 compl_add_category_word(COMPL_ROSTER, "toggle");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
140 compl_add_category_word(COMPL_ROSTER, "hide_offline");
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
141 compl_add_category_word(COMPL_ROSTER, "show_offline");
290
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
142 compl_add_category_word(COMPL_ROSTER, "toggle_offline");
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
143 compl_add_category_word(COMPL_ROSTER, "alternate");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
144 compl_add_category_word(COMPL_ROSTER, "search");
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
145 compl_add_category_word(COMPL_ROSTER, "unread_first");
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
146 compl_add_category_word(COMPL_ROSTER, "unread_next");
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
147
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
148 // Roster category
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
149 compl_add_category_word(COMPL_BUFFER, "clear");
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
150 compl_add_category_word(COMPL_BUFFER, "bottom");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
151 compl_add_category_word(COMPL_BUFFER, "top");
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
152 compl_add_category_word(COMPL_BUFFER, "up");
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
153 compl_add_category_word(COMPL_BUFFER, "down");
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
154 compl_add_category_word(COMPL_BUFFER, "search_backward");
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
155 compl_add_category_word(COMPL_BUFFER, "search_forward");
464
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
156 compl_add_category_word(COMPL_BUFFER, "date");
462
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
157 compl_add_category_word(COMPL_BUFFER, "%");
866
b30df2ab457f Add "/buffer purge"
Mikael Berthe <mikael@lilotux.net>
parents: 865
diff changeset
158 compl_add_category_word(COMPL_BUFFER, "purge");
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
159
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
160 // Group category
240
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
161 compl_add_category_word(COMPL_GROUP, "fold");
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
162 compl_add_category_word(COMPL_GROUP, "unfold");
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
163 compl_add_category_word(COMPL_GROUP, "toggle");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
164
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
165 // Multi-line (msay) category
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
166 compl_add_category_word(COMPL_MULTILINE, "abort");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
167 compl_add_category_word(COMPL_MULTILINE, "begin");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
168 compl_add_category_word(COMPL_MULTILINE, "send");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
169 compl_add_category_word(COMPL_MULTILINE, "send_to");
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
170 compl_add_category_word(COMPL_MULTILINE, "toggle");
838
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
171 compl_add_category_word(COMPL_MULTILINE, "toggle_verbatim");
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
172 compl_add_category_word(COMPL_MULTILINE, "verbatim");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
173
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
174 // Room category
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
175 compl_add_category_word(COMPL_ROOM, "affil");
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
176 compl_add_category_word(COMPL_ROOM, "ban");
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
177 compl_add_category_word(COMPL_ROOM, "destroy");
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 484
diff changeset
178 compl_add_category_word(COMPL_ROOM, "invite");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
179 compl_add_category_word(COMPL_ROOM, "join");
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
180 compl_add_category_word(COMPL_ROOM, "kick");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
181 compl_add_category_word(COMPL_ROOM, "leave");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
182 compl_add_category_word(COMPL_ROOM, "names");
470
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
183 compl_add_category_word(COMPL_ROOM, "nick");
490
af6e31e32d9e Add "/room privmsg"
Mikael Berthe <mikael@lilotux.net>
parents: 488
diff changeset
184 compl_add_category_word(COMPL_ROOM, "privmsg");
448
39a28cb59af3 Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents: 447
diff changeset
185 compl_add_category_word(COMPL_ROOM, "remove");
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
186 compl_add_category_word(COMPL_ROOM, "role");
475
fa49ac0bb8f3 Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents: 472
diff changeset
187 compl_add_category_word(COMPL_ROOM, "topic");
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 448
diff changeset
188 compl_add_category_word(COMPL_ROOM, "unlock");
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
189 compl_add_category_word(COMPL_ROOM, "whois");
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
190
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
191 // Authorization category
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
192 compl_add_category_word(COMPL_AUTH, "allow");
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
193 compl_add_category_word(COMPL_AUTH, "cancel");
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
194 compl_add_category_word(COMPL_AUTH, "request");
835
6a732d2ad4b4 Add "/authorization request_unsubscribe"
Mikael Berthe <mikael@lilotux.net>
parents: 831
diff changeset
195 compl_add_category_word(COMPL_AUTH, "request_unsubscribe");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
196
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
197 // Request (query) category
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
198 compl_add_category_word(COMPL_REQUEST, "time");
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
199 compl_add_category_word(COMPL_REQUEST, "version");
750
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
200
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
201 // Events category
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
202 compl_add_category_word(COMPL_EVENTS, "accept");
755
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
203 compl_add_category_word(COMPL_EVENTS, "ignore");
750
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
204 compl_add_category_word(COMPL_EVENTS, "reject");
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
205 }
94
9a4aa2797f02 [/trunk] Changeset 108 by mikael
mikael
parents: 81
diff changeset
206
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
207 // expandalias(line)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
208 // If there is one, expand the alias in line and returns a new allocated line
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
209 // If no alias is found, returns line
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
210 // Note : if the returned pointer is different from line, the caller should
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
211 // g_free() the pointer after use
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
212 char *expandalias(char *line)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
213 {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
214 const char *p1, *p2;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
215 char *word;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
216 const gchar *value;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
217 char *newline = line;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
218
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
219 // Ignore leading '/'
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
220 for (p1 = line ; *p1 == '/' ; p1++)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
221 ;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
222 // Locate the end of the word
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
223 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
224 ;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
225 // Extract the word
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
226 word = g_strndup(p1, p2-p1);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
227
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
228 // Look for an alias in the list
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
229 value = settings_get(SETTINGS_TYPE_ALIAS, (const char*)word);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
230 if (value) {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
231 // There is an alias to expand
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
232 newline = g_new(char, strlen(value)+strlen(p2)+2);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
233 *newline = '/';
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
234 strcpy(newline+1, value);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
235 strcat(newline, p2);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
236 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
237 g_free(word);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
238
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
239 return newline;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
240 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
241
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
242 // cmd_get
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
243 // Finds command in the command list structure.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
244 // Returns a pointer to the cmd entry, or NULL if command not found.
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
245 cmd *cmd_get(const char *command)
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
246 {
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
247 const char *p1, *p2;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
248 char *com;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
249 GSList *sl_com;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
250
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
251 // Ignore leading '/'
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
252 for (p1 = command ; *p1 == '/' ; p1++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
253 ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
254 // Locate the end of the command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
255 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
256 ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
257 // Copy the clean command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
258 com = g_strndup(p1, p2-p1);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
259
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
260 // Look for command in the list
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
261 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) {
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
262 if (!strcasecmp(com, ((cmd*)sl_com->data)->name))
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
263 break;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
264 }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
265 g_free(com);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
266
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
267 if (sl_com) // Command has been found.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
268 return (cmd*)sl_com->data;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
269 return NULL;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
270 }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
271
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
272 // send_message(msg)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
273 // Write the message in the buddy's window and send the message on
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
274 // the network.
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
275 static void send_message(const char *msg, const char *subj)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
276 {
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
277 const char *jid;
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
278
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
279 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
280 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
281 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
282 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
283
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
284 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
285 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
286 return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
287 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
288
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
289 jid = CURRENT_JID;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
290 if (!jid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
291 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
292 return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
293 }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
294
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
295 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
296 // local part (UI, logging, etc.)
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
297 gchar *hmsg;
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
298 if (subj)
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
299 hmsg = g_strdup_printf("[%s]\n%s", subj, msg);
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
300 else
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
301 hmsg = (char*)msg;
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
302 hk_message_out(jid, NULL, 0, hmsg);
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
303 if (hmsg != msg) g_free(hmsg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
304 }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
305
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
306 // Network part
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
307 jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), subj);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
308 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
309
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
310 // process_command(line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
311 // Process a command line.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
312 // Return 255 if this is the /quit command, and 0 for the other commands.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
313 int process_command(char *line)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
314 {
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
315 char *p;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
316 char *xpline;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
317 cmd *curcmd;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
318
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
319 // Remove trailing spaces:
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
320 for (p=line ; *p ; p++)
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
321 ;
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
322 for (p-- ; p>line && (*p == ' ') ; p--)
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
323 *p = 0;
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
324
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
325 // We do alias expansion here
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
326 if (scr_get_multimode() != 2)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
327 xpline = expandalias(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
328 else
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
329 xpline = line; // No expansion in verbatim multi-line mode
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
330
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
331 // Command "quit"?
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
332 if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) )
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
333 if (!xpline[5] || xpline[5] == ' ')
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
334 return 255;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
335
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
336 // If verbatim multi-line mode, we check if another /msay command is typed
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
337 if ((scr_get_multimode() == 2) && (strncasecmp(xpline, "/msay ", 6))) {
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
338 // It isn't an /msay command
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
339 scr_append_multiline(xpline);
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
340 return 0;
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
341 }
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
342
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
343 // Commands handling
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
344 curcmd = cmd_get(xpline);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
345
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
346 if (!curcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
347 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command. "
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
348 "Please see the manual for a list of known commands.");
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
349 if (xpline != line) g_free(xpline);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
350 return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
351 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
352 if (!curcmd->func) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
353 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
354 "This functionality is not yet implemented, sorry.");
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
355 if (xpline != line) g_free(xpline);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
356 return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
357 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
358 // Lets go to the command parameters
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
359 for (p = xpline+1; *p && (*p != ' ') ; p++)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
360 ;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
361 // Skip spaces
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
362 while (*p && (*p == ' '))
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
363 p++;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
364 // Call command-specific function
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
365 (*curcmd->func)(p);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
366 if (xpline != line) g_free(xpline);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
367 return 0;
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
368 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
369
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
370 // process_line(line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
371 // Process a command/message line.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
372 // If this isn't a command, this is a message and it is sent to the
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
373 // currently selected buddy.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
374 // Return 255 if the line is the /quit command, or 0.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
375 int process_line(char *line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
376 {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
377 if (!*line) { // User only pressed enter
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
378 if (scr_get_multimode()) {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
379 scr_append_multiline("");
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
380 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
381 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
382 if (current_buddy) {
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
383 // Enter chat mode
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
384 scr_set_chatmode(TRUE);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
385 scr_ShowBuddyWindow();
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
386 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
387 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
388 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
389
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
390 if (*line != '/') {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
391 // This isn't a command
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
392 if (scr_get_multimode())
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
393 scr_append_multiline(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
394 else
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
395 do_say(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
396 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
397 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
398
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
399 /* It is (probably) a command -- except for verbatim multi-line mode */
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
400 return process_command(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
401 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
402
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
403 /* Commands callback functions */
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
404 /* All these do_*() functions will be called with a "arg" parameter */
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
405 /* (with arg not null) */
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
406
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
407 static void do_roster(char *arg)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
408 {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
409 if (!strcasecmp(arg, "top")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
410 scr_RosterTop();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
411 update_roster = TRUE;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
412 } else if (!strcasecmp(arg, "bottom")) {
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
413 scr_RosterBottom();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
414 update_roster = TRUE;
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
415 } else if (!strcasecmp(arg, "hide")) {
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
416 scr_RosterVisibility(0);
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
417 } else if (!strcasecmp(arg, "show")) {
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
418 scr_RosterVisibility(1);
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
419 } else if (!strcasecmp(arg, "toggle")) {
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
420 scr_RosterVisibility(-1);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
421 } else if (!strcasecmp(arg, "hide_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
422 buddylist_set_hide_offline_buddies(TRUE);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
423 if (current_buddy)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
424 buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
425 update_roster = TRUE;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
426 } else if (!strcasecmp(arg, "show_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
427 buddylist_set_hide_offline_buddies(FALSE);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
428 buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
429 update_roster = TRUE;
290
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
430 } else if (!strcasecmp(arg, "toggle_offline")) {
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
431 buddylist_set_hide_offline_buddies(-1);
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
432 buddylist_build();
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
433 update_roster = TRUE;
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
434 } else if (!strcasecmp(arg, "unread_first")) {
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
435 scr_RosterUnreadMessage(0);
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
436 } else if (!strcasecmp(arg, "unread_next")) {
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
437 scr_RosterUnreadMessage(1);
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
438 } else if (!strcasecmp(arg, "alternate")) {
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
439 scr_RosterJumpAlternate();
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
440 } else if (!strncasecmp(arg, "search", 6)) {
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
441 char *string = arg+6;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
442 if (*string && (*string != ' ')) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
443 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
444 return;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
445 }
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
446 while (*string == ' ')
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
447 string++;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
448 if (!*string) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
449 scr_LogPrint(LPRINT_NORMAL, "What name or JID are you looking for?");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
450 return;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
451 }
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
452 scr_RosterSearch(string);
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
453 update_roster = TRUE;
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
454 } else if (!strcasecmp(arg, "up")) {
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
455 scr_RosterUp();
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
456 } else if (!strcasecmp(arg, "down")) {
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
457 scr_RosterDown();
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
458 } else
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
459 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
460 }
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
461
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
462 // setstatus(recipient, arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
463 // Set your Jabber status.
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
464 // - if recipient is not NULL, the status is sent to this contact only
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
465 // - arg must be "status message" (message is optional)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
466 static void setstatus(const char *recipient, const char *arg)
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
467 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
468 char **paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
469 char *status;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
470 char *msg;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
471 enum imstatus st;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
472
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
473 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
474 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
475 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
476 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
477
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
478 paramlst = split_arg(arg, 2, 0); // status, message
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
479 status = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
480 msg = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
481
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
482 if (!status) {
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
483 free_arg_lst(paramlst);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
484 return;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
485 }
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
486
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
487 if (!strcasecmp(status, "offline")) st = offline;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
488 else if (!strcasecmp(status, "online")) st = available;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
489 else if (!strcasecmp(status, "avail")) st = available;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
490 else if (!strcasecmp(status, "away")) st = away;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
491 else if (!strcasecmp(status, "invisible")) st = invisible;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
492 else if (!strcasecmp(status, "dnd")) st = dontdisturb;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
493 else if (!strcasecmp(status, "notavail")) st = notavail;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
494 else if (!strcasecmp(status, "free")) st = freeforchat;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
495 else {
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
496 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!");
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
497 free_arg_lst(paramlst);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
498 return;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
499 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
500
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
501 // Use provided message
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
502 if (msg && !*msg) {
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
503 msg = NULL;
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
504 }
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
505
528
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
506 // If a recipient is specified, let's don't use default status messages
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
507 if (recipient && !msg)
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
508 msg = "";
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
509
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
510 jb_setstatus(st, recipient, msg);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
511
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
512 free_arg_lst(paramlst);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
513 }
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
514
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
515 static void do_status(char *arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
516 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
517 if (!*arg) {
519
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
518 const char *sm = jb_getstatusmsg();
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
519 scr_LogPrint(LPRINT_NORMAL, "Your status is: [%c] %s",
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
520 imstatus2char[jb_getstatus()],
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
521 (sm ? sm : ""));
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
522 return;
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
523 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
524 arg = to_utf8(arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
525 setstatus(NULL, arg);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
526 g_free(arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
527 }
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
528
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
529 static void do_status_to(char *arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
530 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
531 char **paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
532 char *jid, *st, *msg;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
533 char *jid_utf8 = NULL;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
534
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
535 paramlst = split_arg(arg, 3, 1); // jid, status, [message]
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
536 jid = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
537 st = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
538 msg = *(paramlst+2);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
539
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
540 if (!jid || !st) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
541 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
542 "Please specify both a Jabber ID and a status.");
640
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
543 free_arg_lst(paramlst);
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
544 return;
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
545 }
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
546
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
547 // Allow things like /status_to "" away
641
62679532ea55 Allow special jid "." in commands /add and /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 640
diff changeset
548 if (!*jid || !strcmp(jid, "."))
640
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
549 jid = NULL;
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
550
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
551 if (jid) {
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
552 // The JID has been specified. Quick check...
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
553 if (check_jid_syntax(jid)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
554 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid);
640
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
555 jid = NULL;
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
556 } else {
696
ee06382dfb22 /status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents: 694
diff changeset
557 // Convert jid to lowercase
ee06382dfb22 /status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents: 694
diff changeset
558 char *p = jid;
ee06382dfb22 /status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents: 694
diff changeset
559 for ( ; *p && *p != '/'; p++)
ee06382dfb22 /status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents: 694
diff changeset
560 *p = tolower(*p);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
561 jid = jid_utf8 = to_utf8(jid);
640
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
562 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
563 } else {
640
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
564 // Add the current buddy
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
565 if (current_buddy)
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
566 jid = (char*)buddy_getjid(BUDDATA(current_buddy));
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
567 if (!jid)
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
568 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
640
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
569 }
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
570
1cd7f8e3895b "/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 638
diff changeset
571 if (jid) {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
572 char *cmd;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
573 if (!msg)
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
574 msg = "";
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
575 msg = to_utf8(msg);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
576 cmd = g_strdup_printf("%s %s", st, msg);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
577 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", jid, cmd);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
578 setstatus(jid, cmd);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
579 g_free(msg);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
580 g_free(cmd);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
581 g_free(jid_utf8);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
582 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
583 free_arg_lst(paramlst);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
584 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
585
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
586 static void do_add(char *arg)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
587 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
588 char **paramlst;
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
589 char *id, *nick;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
590 char *jid_utf8 = NULL;
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
591
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
592 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
593 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
594 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
595 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
596
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
597 paramlst = split_arg(arg, 2, 0); // jid, [nickname]
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
598 id = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
599 nick = *(paramlst+1);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
600
638
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
601 if (!id)
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
602 nick = NULL; // Allow things like: /add "" nick
641
62679532ea55 Allow special jid "." in commands /add and /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 640
diff changeset
603 else if (!*id || !strcmp(id, "."))
638
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
604 id = NULL;
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
605
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
606 if (id) {
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
607 // The JID has been specified. Quick check...
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
608 if (check_jid_syntax(id)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
609 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", id);
638
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
610 id = NULL;
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
611 } else {
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
612 mc_strtolower(id);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
613 // Actually an UTF-8 id isn't needed because only the bare jid will
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
614 // be used.
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
615 id = jid_utf8 = to_utf8(id);
638
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
616 }
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
617 } else {
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
618 // Add the current buddy
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
619 if (current_buddy)
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
620 id = (char*)buddy_getjid(BUDDATA(current_buddy));
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
621 if (!id)
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
622 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
638
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
623 }
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
624
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
625 if (nick)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
626 nick = to_utf8(nick);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
627
638
f6946251acdf "/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents: 636
diff changeset
628 if (id) {
452
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
629 // 2nd parameter = optional nickname
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
630 jb_addbuddy(id, nick, NULL);
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
631 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>.",
452
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
632 id);
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
633 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
634
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
635 g_free(jid_utf8);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
636 g_free(nick);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
637 free_arg_lst(paramlst);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
638 }
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
639
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
640 static void do_del(char *arg)
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
641 {
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
642 const char *jid;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
643
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
644 if (*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
645 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter; "
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
646 "the currently-selected buddy will be deleted.");
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
647 return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
648 }
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
649
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
650 if (!current_buddy) return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
651 jid = buddy_getjid(BUDDATA(current_buddy));
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
652 if (!jid) return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
653
540
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
654 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_ROOM) {
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
655 // This is a chatroom
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 650
diff changeset
656 if (buddy_getinsideroom(BUDDATA(current_buddy))) {
540
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
657 scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!");
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
658 return;
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
659 }
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
660 }
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
661
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
662 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", jid);
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
663 jb_delbuddy(jid);
865
cee8d6be04e1 Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents: 861
diff changeset
664 scr_UpdateBuddyWindow();
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
665 }
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
666
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
667 static void do_group(char *arg)
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
668 {
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
669 gpointer group;
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
670 guint leave_windowbuddy;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
671
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
672 if (!*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
673 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
674 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
675 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
676
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
677 if (!current_buddy) return;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
678
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
679 group = buddy_getgroup(BUDDATA(current_buddy));
853
bdd526ec62bc Fix segfault when using /group with the [status] entry
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
680 if (!group) return;
bdd526ec62bc Fix segfault when using /group with the [status] entry
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
681
212
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
682 // We'll have to redraw the chat window if we're not currently on the group
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
683 // entry itself, because it means we'll have to leave the current buddy
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
684 // chat window.
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
685 leave_windowbuddy = (group != BUDDATA(current_buddy));
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
686
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
687 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
688 scr_LogPrint(LPRINT_NORMAL, "You need to select a group.");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
689 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
690 }
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
691
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
692 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
693 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE);
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
694 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
695 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE);
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
696 } else if (!strcasecmp(arg, "toggle")) {
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
697 buddy_setflags(group, ROSTER_FLAG_HIDE,
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
698 !(buddy_getflags(group) & ROSTER_FLAG_HIDE));
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
699 } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
700 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
701 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
702 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
703
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
704 buddylist_build();
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
705 update_roster = TRUE;
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
706 if (leave_windowbuddy) scr_ShowBuddyWindow();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
707 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
708
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
709 static int send_message_to(const char *jid, const char *msg, const char *subj)
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
710 {
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
711 char *bare_jid, *rp;
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
712 char *hmsg;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
713
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
714 if (!jid || !*jid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
715 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
716 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
717 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
718 if (!msg || !*msg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
719 scr_LogPrint(LPRINT_NORMAL, "You must specify a message.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
720 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
721 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
722 if (check_jid_syntax((char*)jid)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
723 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
724 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
725 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
726
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
727 // We must use the bare jid in hk_message_out()
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
728 rp = strchr(jid, '/');
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
729 if (rp) bare_jid = g_strndup(jid, rp - jid);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
730 else bare_jid = (char*)jid;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
731
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
732 // Jump to window, create one if needed
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
733 scr_RosterJumpJid(bare_jid);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
734
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
735 // Check if we're sending a message to a conference room
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
736 // If not, we must make sure rp is NULL, for hk_message_out()
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
737 if (rp) {
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
738 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) rp++;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
739 else rp = NULL;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
740 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
741
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
742 // local part (UI, logging, etc.)
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
743 if (subj)
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
744 hmsg = g_strdup_printf("[%s]\n%s", subj, msg);
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
745 else
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
746 hmsg = (char*)msg;
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
747
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
748 hk_message_out(bare_jid, rp, 0, hmsg);
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
749 if (hmsg != msg) g_free(hmsg);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
750
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
751 // Network part
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
752 jb_send_msg(jid, msg, ROSTER_TYPE_USER, subj);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
753
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
754 if (rp) g_free(bare_jid);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
755 return 0;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
756 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
757
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
758 static void do_say(char *arg)
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
759 {
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
760 gpointer bud;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
761
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
762 scr_set_chatmode(TRUE);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
763
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
764 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
765 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
766 "Whom are you talking to? Please select a buddy.");
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
767 return;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
768 }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
769
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
770 bud = BUDDATA(current_buddy);
631
423c24e5875a Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 626
diff changeset
771 if (!(buddy_gettype(bud) &
423c24e5875a Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 626
diff changeset
772 (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM))) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
773 scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
774 return;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
775 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
776
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
777 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
778 arg = to_utf8(arg);
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
779 send_message(arg, NULL);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
780 g_free(arg);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
781 }
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
782
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
783 static void do_msay(char *arg)
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
784 {
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
785 /* Parameters: begin verbatim abort send send_to */
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
786 char **paramlst;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
787 char *subcmd;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
788
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
789 paramlst = split_arg(arg, 2, 1); // subcmd, arg
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
790 subcmd = *paramlst;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
791 arg = *(paramlst+1);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
792
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
793 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
794 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
795 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using "
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
796 "the /msay command.");
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
797 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter "
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
798 "multi-line mode...)");
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
799 free_arg_lst(paramlst);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
800 return;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
801 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
802
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
803 if (!strcasecmp(subcmd, "toggle")) {
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
804 if (scr_get_multimode())
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
805 subcmd = "send";
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
806 else
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
807 subcmd = "begin";
838
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
808 } else if (!strcasecmp(subcmd, "toggle_verbatim")) {
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
809 if (scr_get_multimode())
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
810 subcmd = "send";
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
811 else
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
812 subcmd = "verbatim";
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
813 }
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
814
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
815 if (!strcasecmp(subcmd, "abort")) {
315
65aa05520556 First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
816 if (scr_get_multimode())
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
817 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode.");
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
818 scr_set_multimode(FALSE, NULL);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
819 return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
820 } else if ((!strcasecmp(subcmd, "begin")) ||
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
821 (!strcasecmp(subcmd, "verbatim"))) {
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
822 bool verbat;
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
823 gchar *subj_utf8 = to_utf8(arg);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
824 if (!strcasecmp(subcmd, "verbatim")) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
825 scr_set_multimode(2, subj_utf8);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
826 verbat = TRUE;
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
827 } else {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
828 scr_set_multimode(1, subj_utf8);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
829 verbat = FALSE;
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
830 }
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
831
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
832 scr_LogPrint(LPRINT_NORMAL, "Entered %smulti-line message mode.",
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
833 verbat ? "VERBATIM " : "");
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
834 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" "
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
835 "when your message is ready.");
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
836 if (verbat)
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
837 scr_LogPrint(LPRINT_NORMAL, "Use \"/msay abort\" to abort this mode.");
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
838 g_free(subj_utf8);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
839 return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
840 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
841 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
842 return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
843 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
844
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
845 /* send/send_to command */
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
846
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
847 if (!scr_get_multimode()) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
848 scr_LogPrint(LPRINT_NORMAL, "No message to send. "
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
849 "Use \"/msay begin\" first.");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
850 return;
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
851 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
852
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
853 scr_set_chatmode(TRUE);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
854
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
855 if (!strcasecmp(subcmd, "send_to")) {
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
856 int err = FALSE;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
857 gchar *msg_utf8;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
858 // Let's send to the specified JID. We leave now if there
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
859 // has been an error (so we don't leave multi-line mode).
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
860 arg = to_utf8(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
861 msg_utf8 = to_utf8(scr_get_multiline());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
862 if (msg_utf8) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
863 err = send_message_to(arg, msg_utf8, scr_get_multimode_subj());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
864 g_free(msg_utf8);
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
865 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
866 g_free(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
867 if (err)
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
868 return;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
869 } else { // Send to currently selected buddy
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
870 gpointer bud;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
871 gchar *msg_utf8;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
872
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
873 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
874 scr_LogPrint(LPRINT_NORMAL, "Whom are you talking to?");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
875 return;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
876 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
877
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
878 bud = BUDDATA(current_buddy);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
879 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
880 scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
881 return;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
882 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
883
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
884 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
885 msg_utf8 = to_utf8(scr_get_multiline());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
886 if (msg_utf8) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
887 send_message(msg_utf8, scr_get_multimode_subj());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
888 g_free(msg_utf8);
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
889 }
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
890 }
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
891 scr_set_multimode(FALSE, NULL);
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
892 scr_LogPrint(LPRINT_NORMAL, "You have left multi-line message mode.");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
893 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
894
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
895 static void do_say_to(char *arg)
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
896 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
897 char **paramlst;
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
898 char *jid, *msg;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
899
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
900 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
901 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
902 return;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
903 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
904
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
905 paramlst = split_arg(arg, 2, 1); // jid, message
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
906 jid = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
907 msg = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
908
844
5002948c7360 "/say_to ." is not valid
Mikael Berthe <mikael@lilotux.net>
parents: 843
diff changeset
909 if (!jid || !strcmp(jid, ".")) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
910 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
911 free_arg_lst(paramlst);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
912 return;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
913 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
914
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
915 jid = to_utf8(jid);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
916 msg = to_utf8(msg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
917
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
918 send_message_to(jid, msg, NULL);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
919
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
920 g_free(jid);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
921 g_free(msg);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
922 free_arg_lst(paramlst);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
923 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
924
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
925 // buffer_updown(updown, nblines)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
926 // updown: -1=up, +1=down
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
927 inline static void buffer_updown(int updown, char *nlines)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
928 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
929 int nblines;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
930
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
931 if (!nlines || !*nlines)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
932 nblines = 0;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
933 else
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
934 nblines = atoi(nlines);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
935
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
936 if (nblines >= 0)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
937 scr_BufferScrollUpDown(updown, nblines);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
938 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
939
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
940 static void buffer_search(int direction, char *arg)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
941 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
942 if (!arg || !*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
943 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
944 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
945 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
946
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
947 scr_BufferSearch(direction, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
948 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
949
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
950 static void buffer_date(char *date)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
951 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
952 time_t t;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
953
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
954 if (!date || !*date) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
955 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
956 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
957 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
958
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
959 strip_arg_special_chars(date);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
960
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
961 t = from_iso8601(date, 0);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
962 if (t)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
963 scr_BufferDate(t);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
964 else
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
965 scr_LogPrint(LPRINT_NORMAL, "The date you specified is "
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
966 "not correctly formatted or invalid.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
967 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
968
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
969 static void buffer_percent(char *arg1, char *arg2)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
970 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
971 // Basically, user has typed "%arg1 arg2"
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
972 // "%50" -> arg1 = 50, arg2 null pointer
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
973 // "% 50" -> arg1 = \0, arg2 = 50
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
974
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
975 if (!*arg1 && (!arg2 || !*arg2)) { // No value
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
976 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
977 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
978 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
979
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
980 if (*arg1 && arg2 && *arg2) { // Two values
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
981 scr_LogPrint(LPRINT_NORMAL, "Wrong parameters.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
982 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
983 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
984
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
985 scr_BufferPercent(atoi((*arg1 ? arg1 : arg2)));
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
986 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
987
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
988 static void do_buffer(char *arg)
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
989 {
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
990 char **paramlst;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
991 char *subcmd;
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
992
471
82a27508fb85 Fix segfaults when using /buffer and /room while not connected
Mikael Berthe <mikael@lilotux.net>
parents: 470
diff changeset
993 if (!current_buddy) return;
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
994
446
9f4e9e9aaf08 Minor changes & cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
995 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_GROUP) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
996 scr_LogPrint(LPRINT_NORMAL, "Groups have no buffer.");
446
9f4e9e9aaf08 Minor changes & cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
997 return;
9f4e9e9aaf08 Minor changes & cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
998 }
9f4e9e9aaf08 Minor changes & cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 444
diff changeset
999
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1000 paramlst = split_arg(arg, 2, 1); // subcmd, arg
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1001 subcmd = *paramlst;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1002 arg = *(paramlst+1);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1003
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1004 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1005 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1006 free_arg_lst(paramlst);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1007 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1008 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1009
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1010 if (!strcasecmp(subcmd, "top")) {
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 336
diff changeset
1011 scr_BufferTopBottom(-1);
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1012 } else if (!strcasecmp(subcmd, "bottom")) {
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 336
diff changeset
1013 scr_BufferTopBottom(1);
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1014 } else if (!strcasecmp(subcmd, "clear")) {
369
499170ed71c9 Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1015 scr_BufferClear();
866
b30df2ab457f Add "/buffer purge"
Mikael Berthe <mikael@lilotux.net>
parents: 865
diff changeset
1016 } else if (!strcasecmp(subcmd, "purge")) {
b30df2ab457f Add "/buffer purge"
Mikael Berthe <mikael@lilotux.net>
parents: 865
diff changeset
1017 scr_BufferPurge();
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1018 } else if (!strcasecmp(subcmd, "up")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1019 buffer_updown(-1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1020 } else if (!strcasecmp(subcmd, "down")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1021 buffer_updown(1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1022 } else if (!strcasecmp(subcmd, "search_backward")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1023 buffer_search(-1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1024 } else if (!strcasecmp(subcmd, "search_forward")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1025 buffer_search(1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1026 } else if (!strcasecmp(subcmd, "date")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1027 buffer_date(arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1028 } else if (*subcmd == '%') {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1029 buffer_percent(subcmd+1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1030 } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1031 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1032 }
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1033
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1034 free_arg_lst(paramlst);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1035 }
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1036
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1037 static void do_clear(char *arg) // Alias for "/buffer clear"
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1038 {
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1039 do_buffer("clear");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1040 }
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1041
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1042 static void do_info(char *arg)
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1043 {
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1044 gpointer bud;
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1045 const char *jid, *name;
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1046 guint type;
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1047 char *buffer;
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1048 enum subscr esub;
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1049
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1050 if (!current_buddy) return;
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1051 bud = BUDDATA(current_buddy);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1052
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1053 jid = buddy_getjid(bud);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1054 name = buddy_getname(bud);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1055 type = buddy_gettype(bud);
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1056 esub = buddy_getsubscription(bud);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1057
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1058 buffer = g_new(char, 4096);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1059
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1060 if (jid) {
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1061 GSList *resources;
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1062 char *bstr = "unknown";
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1063
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1064 // Enter chat mode
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1065 scr_set_chatmode(TRUE);
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1066 scr_ShowBuddyWindow();
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1067
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1068 snprintf(buffer, 4095, "jid: <%s>", jid);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1069 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1070 if (name) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1071 snprintf(buffer, 4095, "Name: %s", name);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1072 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1073 }
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1074
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1075 if (type == ROSTER_TYPE_USER) bstr = "user";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1076 else if (type == ROSTER_TYPE_ROOM) bstr = "chatroom";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1077 else if (type == ROSTER_TYPE_AGENT) bstr = "agent";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1078 snprintf(buffer, 127, "Type: %s", bstr);
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1079 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1080
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1081 if (esub == sub_both) bstr = "both";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1082 else if (esub & sub_from) bstr = "from";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1083 else if (esub & sub_to) bstr = "to";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1084 else bstr = "none";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1085 snprintf(buffer, 64, "Subscription: %s", bstr);
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1086 if (esub & sub_pending)
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1087 strcat(buffer, " (pending)");
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1088 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1089
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1090 resources = buddy_getresources(bud);
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1091 if (!resources && type == ROSTER_TYPE_USER) {
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1092 // No resource; display last status message, if any.
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1093 const char *rst_msg = buddy_getstatusmsg(bud, "");
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1094 if (rst_msg) {
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1095 snprintf(buffer, 4095, "Last status message: %s", rst_msg);
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1096 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1097 }
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1098 }
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1099 for ( ; resources ; resources = g_slist_next(resources) ) {
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1100 gchar rprio;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1101 enum imstatus rstatus;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1102 const char *rst_msg;
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1103 time_t rst_time;
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1104
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1105 rprio = buddy_getresourceprio(bud, resources->data);
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1106 rstatus = buddy_getstatus(bud, resources->data);
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1107 rst_msg = buddy_getstatusmsg(bud, resources->data);
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1108 rst_time = buddy_getstatustime(bud, resources->data);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1109
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1110 snprintf(buffer, 4095, "Resource: [%c] (%d) %s", imstatus2char[rstatus],
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1111 rprio, (char*)resources->data);
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1112 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO);
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1113 if (rst_msg) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1114 snprintf(buffer, 4095, "Status message: %s", rst_msg);
847
e1b7f71b0b1c Improve readability for some commands
Mikael Berthe <mikael@lilotux.net>
parents: 846
diff changeset
1115 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1116 }
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1117 if (rst_time) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1118 char tbuf[128];
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1119
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1120 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", localtime(&rst_time));
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1121 snprintf(buffer, 127, "Status timestamp: %s", tbuf);
847
e1b7f71b0b1c Improve readability for some commands
Mikael Berthe <mikael@lilotux.net>
parents: 846
diff changeset
1122 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_NONE);
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1123 }
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1124 }
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1125 } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1126 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name);
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1127 scr_LogPrint(LPRINT_NORMAL, "Type: %s",
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1128 type == ROSTER_TYPE_GROUP ? "group" :
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1129 (type == ROSTER_TYPE_SPECIAL ? "special" : "unknown"));
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1130 }
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1131
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1132 g_free(buffer);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1133 }
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1134
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1135 // room_names() is a variation of do_info(), for chatrooms only
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1136 static void room_names(gpointer bud, char *arg)
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1137 {
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1138 const char *jid;
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1139 char *buffer;
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1140 GSList *resources;
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1141
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1142 if (*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1143 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter.");
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1144 return;
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1145 }
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1146
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1147 // Enter chat mode
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1148 scr_set_chatmode(TRUE);
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mika