Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/commands.c @ 472:75442262c082
Disable some commands when not connected
Disable status/status_to, add, rawxml, room, say/msay when not connected,
as these commands could be called with an empty buddylist.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 02 Oct 2005 18:05:34 +0200 |
parents | 82a27508fb85 |
children | fa49ac0bb8f3 |
rev | line source |
---|---|
47 | 1 /* |
2 * commands.c -- user commands handling | |
393 | 3 * |
47 | 4 * Copyright (C) 2005 Mikael Berthe <bmikael@lists.lilotux.net> |
5 * | |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
95 | 22 #include <string.h> |
23 | |
47 | 24 #include "commands.h" |
25 #include "jabglue.h" | |
81 | 26 #include "roster.h" |
47 | 27 #include "screen.h" |
95 | 28 #include "compl.h" |
113 | 29 #include "hooks.h" |
191 | 30 #include "hbuf.h" |
47 | 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" |
47 | 33 |
104 | 34 // Commands callbacks |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
35 static void do_roster(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
36 static void do_status(char *arg); |
444 | 37 static void do_status_to(char *arg); |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
38 static void do_add(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
39 static void do_del(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
40 static void do_group(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
41 static void do_say(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
42 static void do_msay(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
43 static void do_buffer(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
44 static void do_clear(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
45 static void do_info(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
46 static void do_rename(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
47 static void do_move(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
48 static void do_set(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
49 static void do_alias(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
50 static void do_bind(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
51 static void do_connect(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
52 static void do_disconnect(char *arg); |
436 | 53 static void do_rawxml(char *arg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
54 static void do_room(char *arg); |
47 | 55 |
104 | 56 // Global variable for the commands list |
95 | 57 static GSList *Commands; |
58 | |
104 | 59 |
95 | 60 // cmd_add() |
61 // Adds a command to the commands list and to the CMD completion list | |
62 void cmd_add(const char *name, const char *help, | |
104 | 63 guint flags_row1, guint flags_row2, void (*f)()) |
95 | 64 { |
65 cmd *n_cmd = g_new0(cmd, 1); | |
66 strncpy(n_cmd->name, name, 32-1); | |
67 n_cmd->help = help; | |
68 n_cmd->completion_flags[0] = flags_row1; | |
69 n_cmd->completion_flags[1] = flags_row2; | |
70 n_cmd->func = f; | |
102 | 71 Commands = g_slist_append(Commands, n_cmd); |
95 | 72 // Add to completion CMD category |
73 compl_add_category_word(COMPL_CMD, name); | |
74 } | |
75 | |
76 // cmd_init() | |
77 // ... | |
78 void cmd_init(void) | |
79 { | |
124 | 80 cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add); |
285 | 81 cmd_add("alias", "Add an alias", 0, 0, &do_alias); |
288 | 82 cmd_add("bind", "Add an key binding", 0, 0, &do_bind); |
187 | 83 cmd_add("buffer", "Manipulate current buddy's buffer (chat window)", |
84 COMPL_BUFFER, 0, &do_buffer); | |
108 | 85 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
|
86 cmd_add("connect", "Connect to the server", 0, 0, &do_connect); |
205 | 87 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
|
88 cmd_add("disconnect", "Disconnect from server", 0, 0, &do_disconnect); |
128 | 89 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
|
90 //cmd_add("help", "Display some help", COMPL_CMD, 0, NULL); |
191 | 91 cmd_add("info", "Show basic infos on current buddy", 0, 0, &do_info); |
225 | 92 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME, |
93 0, &do_move); | |
238 | 94 cmd_add("msay", "Send a multi-lines message to the selected buddy", |
95 COMPL_MULTILINE, 0, &do_msay); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
96 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room); |
95 | 97 cmd_add("quit", "Exit the software", 0, 0, NULL); |
436 | 98 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml); |
208 | 99 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); |
95 | 100 //cmd_add("request_auth"); |
128 | 101 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, |
102 &do_roster); | |
132 | 103 cmd_add("say", "Say something to the selected buddy", 0, 0, &do_say); |
95 | 104 //cmd_add("search"); |
105 //cmd_add("send_auth"); | |
310 | 106 cmd_add("set", "Set/query an option value", 0, 0, &do_set); |
116 | 107 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status); |
444 | 108 cmd_add("status_to", "Show or set your status for one recipient", |
109 COMPL_JID, COMPL_STATUS, &do_status_to); | |
95 | 110 |
111 // Status category | |
112 compl_add_category_word(COMPL_STATUS, "online"); | |
113 compl_add_category_word(COMPL_STATUS, "avail"); | |
114 compl_add_category_word(COMPL_STATUS, "invisible"); | |
115 compl_add_category_word(COMPL_STATUS, "free"); | |
116 compl_add_category_word(COMPL_STATUS, "dnd"); | |
117 compl_add_category_word(COMPL_STATUS, "notavail"); | |
118 compl_add_category_word(COMPL_STATUS, "away"); | |
103 | 119 |
120 // Roster category | |
121 compl_add_category_word(COMPL_ROSTER, "bottom"); | |
265 | 122 compl_add_category_word(COMPL_ROSTER, "top"); |
377
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
123 compl_add_category_word(COMPL_ROSTER, "up"); |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
124 compl_add_category_word(COMPL_ROSTER, "down"); |
103 | 125 compl_add_category_word(COMPL_ROSTER, "hide_offline"); |
126 compl_add_category_word(COMPL_ROSTER, "show_offline"); | |
290
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
127 compl_add_category_word(COMPL_ROSTER, "toggle_offline"); |
330 | 128 compl_add_category_word(COMPL_ROSTER, "alternate"); |
265 | 129 compl_add_category_word(COMPL_ROSTER, "search"); |
236 | 130 compl_add_category_word(COMPL_ROSTER, "unread_first"); |
131 compl_add_category_word(COMPL_ROSTER, "unread_next"); | |
127 | 132 |
187 | 133 // Roster category |
134 compl_add_category_word(COMPL_BUFFER, "bottom"); | |
135 compl_add_category_word(COMPL_BUFFER, "clear"); | |
136 compl_add_category_word(COMPL_BUFFER, "top"); | |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
137 compl_add_category_word(COMPL_BUFFER, "search_backward"); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
138 compl_add_category_word(COMPL_BUFFER, "search_forward"); |
464 | 139 compl_add_category_word(COMPL_BUFFER, "date"); |
462 | 140 compl_add_category_word(COMPL_BUFFER, "%"); |
187 | 141 |
127 | 142 // Group category |
240 | 143 compl_add_category_word(COMPL_GROUP, "fold"); |
144 compl_add_category_word(COMPL_GROUP, "unfold"); | |
130 | 145 compl_add_category_word(COMPL_GROUP, "toggle"); |
238 | 146 |
147 // Multi-line (msay) category | |
148 compl_add_category_word(COMPL_MULTILINE, "abort"); | |
149 compl_add_category_word(COMPL_MULTILINE, "begin"); | |
150 compl_add_category_word(COMPL_MULTILINE, "send"); | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
151 compl_add_category_word(COMPL_MULTILINE, "verbatim"); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
152 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
153 // Room category |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
154 compl_add_category_word(COMPL_ROOM, "join"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
155 compl_add_category_word(COMPL_ROOM, "leave"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
156 compl_add_category_word(COMPL_ROOM, "names"); |
470 | 157 compl_add_category_word(COMPL_ROOM, "nick"); |
448
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
158 compl_add_category_word(COMPL_ROOM, "remove"); |
449 | 159 compl_add_category_word(COMPL_ROOM, "unlock"); |
95 | 160 } |
94 | 161 |
285 | 162 // expandalias(line) |
163 // If there is one, expand the alias in line and returns a new allocated line | |
164 // If no alias is found, returns line | |
165 // Note : if the returned pointer is different from line, the caller should | |
166 // g_free() the pointer after use | |
167 char *expandalias(char *line) | |
168 { | |
169 const char *p1, *p2; | |
170 char *word; | |
171 const gchar *value; | |
172 char *newline = line; | |
173 | |
174 // Ignore leading '/' | |
175 for (p1 = line ; *p1 == '/' ; p1++) | |
176 ; | |
177 // Locate the end of the word | |
178 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++) | |
179 ; | |
180 // Extract the word | |
181 word = g_strndup(p1, p2-p1); | |
182 | |
183 // Look for an alias in the list | |
184 value = settings_get(SETTINGS_TYPE_ALIAS, (const char*)word); | |
185 if (value) { | |
186 // There is an alias to expand | |
187 newline = g_new(char, strlen(value)+strlen(p2)+2); | |
188 *newline = '/'; | |
189 strcpy(newline+1, value); | |
190 strcat(newline, p2); | |
191 } | |
192 g_free(word); | |
193 | |
194 return newline; | |
195 } | |
196 | |
102 | 197 // cmd_get |
198 // Finds command in the command list structure. | |
199 // Returns a pointer to the cmd entry, or NULL if command not found. | |
238 | 200 cmd *cmd_get(const char *command) |
102 | 201 { |
238 | 202 const char *p1, *p2; |
102 | 203 char *com; |
204 GSList *sl_com; | |
285 | 205 |
102 | 206 // Ignore leading '/' |
207 for (p1 = command ; *p1 == '/' ; p1++) | |
208 ; | |
209 // Locate the end of the command | |
210 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++) | |
211 ; | |
212 // Copy the clean command | |
213 com = g_strndup(p1, p2-p1); | |
214 | |
215 // Look for command in the list | |
216 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) { | |
217 if (!strcasecmp(com, ((cmd*)sl_com->data)->name)) | |
218 break; | |
219 } | |
220 g_free(com); | |
221 | |
222 if (sl_com) // Command has been found. | |
223 return (cmd*)sl_com->data; | |
224 return NULL; | |
225 } | |
226 | |
47 | 227 // send_message(msg) |
228 // Write the message in the buddy's window and send the message on | |
229 // the network. | |
238 | 230 void send_message(const char *msg) |
47 | 231 { |
81 | 232 const char *jid; |
393 | 233 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
234 if (!jb_getonline()) { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
235 scr_LogPrint(LPRINT_NORMAL, "You are not connected"); |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
236 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
237 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
238 |
81 | 239 if (!current_buddy) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
240 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected."); |
81 | 241 return; |
242 } | |
243 | |
244 jid = CURRENT_JID; | |
245 if (!jid) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
246 scr_LogPrint(LPRINT_NORMAL, "No buddy currently selected."); |
81 | 247 return; |
248 } | |
47 | 249 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
250 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
251 // local part (UI, logging, etc.) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
252 hk_message_out(jid, 0, msg); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
253 } |
47 | 254 |
255 // Network part | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
256 jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy))); |
47 | 257 } |
258 | |
288 | 259 // process_command(line) |
260 // Process a command line. | |
261 // Return 255 if this is the /quit command, and 0 for the other commands. | |
262 int process_command(char *line) | |
47 | 263 { |
101 | 264 char *p; |
285 | 265 char *xpline; |
104 | 266 cmd *curcmd; |
267 | |
101 | 268 // Remove trailing spaces: |
269 for (p=line ; *p ; p++) | |
270 ; | |
271 for (p-- ; p>line && (*p == ' ') ; p--) | |
272 *p = 0; | |
273 | |
285 | 274 // We do alias expansion here |
288 | 275 if (scr_get_multimode() != 2) |
276 xpline = expandalias(line); | |
277 else | |
278 xpline = line; // No expansion in verbatim multi-line mode | |
285 | 279 |
101 | 280 // Command "quit"? |
285 | 281 if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) ) |
282 if (!xpline[5] || xpline[5] == ' ') | |
116 | 283 return 255; |
104 | 284 |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
285 // If verbatim multi-line mode, we check if another /msay command is typed |
285 | 286 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
|
287 // It isn't an /msay command |
285 | 288 scr_append_multiline(xpline); |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
289 return 0; |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
290 } |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
291 |
47 | 292 // Commands handling |
285 | 293 curcmd = cmd_get(xpline); |
47 | 294 |
104 | 295 if (!curcmd) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
296 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command, sorry."); |
285 | 297 if (xpline != line) g_free(xpline); |
104 | 298 return 0; |
299 } | |
300 if (!curcmd->func) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
301 scr_LogPrint(LPRINT_NORMAL, "Not yet implemented, sorry."); |
285 | 302 if (xpline != line) g_free(xpline); |
104 | 303 return 0; |
304 } | |
305 // Lets go to the command parameters | |
285 | 306 for (p = xpline+1; *p && (*p != ' ') ; p++) |
104 | 307 ; |
308 // Skip spaces | |
285 | 309 while (*p && (*p == ' ')) |
310 p++; | |
104 | 311 // Call command-specific function |
285 | 312 (*curcmd->func)(p); |
313 if (xpline != line) g_free(xpline); | |
47 | 314 return 0; |
315 } | |
316 | |
288 | 317 // process_line(line) |
318 // Process a command/message line. | |
319 // If this isn't a command, this is a message and it is sent to the | |
320 // currently selected buddy. | |
321 // Return 255 if the line is the /quit command, or 0. | |
322 int process_line(char *line) | |
323 { | |
324 if (!*line) { // User only pressed enter | |
325 if (scr_get_multimode()) { | |
326 scr_append_multiline(""); | |
327 return 0; | |
328 } | |
329 if (current_buddy) { | |
330 scr_set_chatmode(TRUE); | |
331 buddy_setflags(BUDDATA(current_buddy), ROSTER_FLAG_LOCK, TRUE); | |
332 scr_ShowBuddyWindow(); | |
333 } | |
334 return 0; | |
335 } | |
336 | |
337 if (*line != '/') { | |
338 // This isn't a command | |
339 if (scr_get_multimode()) | |
340 scr_append_multiline(line); | |
341 else | |
342 do_say(line); | |
343 return 0; | |
344 } | |
345 | |
346 /* It is (probably) a command -- except for verbatim multi-line mode */ | |
347 return process_command(line); | |
348 } | |
349 | |
104 | 350 /* Commands callback functions */ |
351 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
352 static void do_roster(char *arg) |
104 | 353 { |
354 if (!strcasecmp(arg, "top")) { | |
355 scr_RosterTop(); | |
128 | 356 update_roster = TRUE; |
104 | 357 } else if (!strcasecmp(arg, "bottom")) { |
358 scr_RosterBottom(); | |
128 | 359 update_roster = TRUE; |
104 | 360 } else if (!strcasecmp(arg, "hide_offline")) { |
120 | 361 buddylist_set_hide_offline_buddies(TRUE); |
104 | 362 if (current_buddy) |
363 buddylist_build(); | |
128 | 364 update_roster = TRUE; |
104 | 365 } else if (!strcasecmp(arg, "show_offline")) { |
120 | 366 buddylist_set_hide_offline_buddies(FALSE); |
124 | 367 buddylist_build(); |
128 | 368 update_roster = TRUE; |
290
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
369 } else if (!strcasecmp(arg, "toggle_offline")) { |
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
370 buddylist_set_hide_offline_buddies(-1); |
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
371 buddylist_build(); |
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
372 update_roster = TRUE; |
236 | 373 } else if (!strcasecmp(arg, "unread_first")) { |
374 scr_RosterUnreadMessage(0); | |
375 } else if (!strcasecmp(arg, "unread_next")) { | |
376 scr_RosterUnreadMessage(1); | |
330 | 377 } else if (!strcasecmp(arg, "alternate")) { |
378 scr_RosterJumpAlternate(); | |
265 | 379 } else if (!strncasecmp(arg, "search", 6)) { |
380 char *string = arg+6; | |
381 if (*string && (*string != ' ')) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
382 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
265 | 383 return; |
384 } | |
385 while (*string == ' ') | |
386 string++; | |
387 if (!*string) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
388 scr_LogPrint(LPRINT_NORMAL, "What name or jid are you looking for?"); |
265 | 389 return; |
390 } | |
391 scr_RosterSearch(string); | |
392 update_roster = TRUE; | |
377
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
393 } else if (!strcasecmp(arg, "up")) { |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
394 scr_RosterUp(); |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
395 } else if (!strcasecmp(arg, "down")) { |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
396 scr_RosterDown(); |
104 | 397 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
398 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
104 | 399 } |
108 | 400 |
444 | 401 // setstatus(recipient, arg) |
402 // Set your Jabber status. | |
403 // - if recipient is not NULL, the status is sent to this contact only | |
404 // - arg must be "status message" (message is optional) | |
405 static void setstatus(const char *recipient, const char *arg) | |
116 | 406 { |
407 enum imstatus st; | |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
408 int len; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
409 char *msg; |
116 | 410 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
411 if (!jb_getonline()) { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
412 scr_LogPrint(LPRINT_NORMAL, "You are not connected"); |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
413 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
414 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
415 |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
416 msg = strchr(arg, ' '); |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
417 if (!msg) |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
418 len = strlen(arg); |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
419 else |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
420 len = msg - arg; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
421 |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
422 if (!strncasecmp(arg, "offline", len)) st = offline; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
423 else if (!strncasecmp(arg, "online", len)) st = available; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
424 else if (!strncasecmp(arg, "avail", len)) st = available; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
425 else if (!strncasecmp(arg, "away", len)) st = away; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
426 else if (!strncasecmp(arg, "invisible", len)) st = invisible; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
427 else if (!strncasecmp(arg, "dnd", len)) st = dontdisturb; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
428 else if (!strncasecmp(arg, "notavail", len)) st = notavail; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
429 else if (!strncasecmp(arg, "free", len)) st = freeforchat; |
116 | 430 else { |
444 | 431 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!"); |
116 | 432 return; |
433 } | |
434 | |
416
48e7808c4191
Allow offline status message
Mikael Berthe <mikael@lilotux.net>
parents:
402
diff
changeset
|
435 if (msg && st != invisible) { |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
436 for (msg++ ; *msg && *msg == ' ' ; msg++) ; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
437 if (!*msg) msg = NULL; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
438 } else |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
439 msg = NULL; |
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
440 |
444 | 441 jb_setstatus(st, recipient, msg); |
442 } | |
443 | |
444 static void do_status(char *arg) | |
445 { | |
446 if (!arg || (!*arg)) { | |
447 scr_LogPrint(LPRINT_NORMAL, "Your status is: %c", | |
448 imstatus2char[jb_getstatus()]); | |
449 return; | |
450 } | |
451 setstatus(NULL, arg); | |
452 } | |
453 | |
454 static void do_status_to(char *arg) | |
455 { | |
456 char *id, *st; | |
457 if (!arg || (*arg == 0)) { | |
458 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); | |
459 return; | |
460 } | |
461 | |
462 // Split recipient jid, status | |
463 id = g_strdup(arg); | |
464 st = strchr(id, ' '); | |
465 if (!st) { | |
466 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); | |
467 g_free(id); | |
468 return; | |
469 } | |
470 | |
471 *st++ = 0; | |
472 while (*st && *st == ' ') | |
473 st++; | |
474 | |
452 | 475 if (check_jid_syntax(id)) { |
476 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", id); | |
477 } else { | |
478 mc_strtolower(id); | |
479 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", id, st); | |
480 setstatus(id, st); | |
481 } | |
482 g_free(id); | |
116 | 483 } |
484 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
485 static void do_add(char *arg) |
124 | 486 { |
244 | 487 char *id, *nick; |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
488 |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
489 if (!jb_getonline()) { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
490 scr_LogPrint(LPRINT_NORMAL, "You are not connected"); |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
491 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
492 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
493 |
446 | 494 if (!arg || (!*arg)) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
495 scr_LogPrint(LPRINT_NORMAL, "Wrong usage"); |
124 | 496 return; |
497 } | |
498 | |
244 | 499 id = g_strdup(arg); |
500 nick = strchr(id, ' '); | |
501 if (nick) { | |
502 *nick++ = 0; | |
503 while (*nick && *nick == ' ') | |
504 nick++; | |
505 } | |
506 | |
452 | 507 if (check_jid_syntax(id)) { |
508 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber id", id); | |
509 } else { | |
510 mc_strtolower(id); | |
511 // 2nd parameter = optional nickname | |
512 jb_addbuddy(id, nick, NULL); | |
513 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>", | |
514 id); | |
515 } | |
244 | 516 g_free(id); |
124 | 517 } |
128 | 518 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
519 static void do_del(char *arg) |
206 | 520 { |
521 const char *jid; | |
522 | |
523 if (arg && (*arg)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
524 scr_LogPrint(LPRINT_NORMAL, "Wrong usage"); |
206 | 525 return; |
526 } | |
527 | |
528 if (!current_buddy) return; | |
529 jid = buddy_getjid(BUDDATA(current_buddy)); | |
530 if (!jid) return; | |
531 | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
532 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", jid); |
206 | 533 jb_delbuddy(jid); |
534 } | |
535 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
536 static void do_group(char *arg) |
128 | 537 { |
538 gpointer group; | |
166 | 539 guint leave_windowbuddy; |
128 | 540 |
446 | 541 if (!arg || (!*arg)) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
542 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
128 | 543 return; |
544 } | |
545 | |
166 | 546 if (!current_buddy) return; |
128 | 547 |
166 | 548 group = buddy_getgroup(BUDDATA(current_buddy)); |
212 | 549 // We'll have to redraw the chat window if we're not currently on the group |
550 // entry itself, because it means we'll have to leave the current buddy | |
551 // chat window. | |
166 | 552 leave_windowbuddy = (group != BUDDATA(current_buddy)); |
553 | |
128 | 554 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
555 scr_LogPrint(LPRINT_NORMAL, "You need to select a group"); |
128 | 556 return; |
557 } | |
166 | 558 |
559 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) { | |
128 | 560 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE); |
166 | 561 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) { |
128 | 562 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE); |
130 | 563 } else if (!strcasecmp(arg, "toggle")) { |
564 buddy_setflags(group, ROSTER_FLAG_HIDE, | |
565 !(buddy_getflags(group) & ROSTER_FLAG_HIDE)); | |
128 | 566 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
567 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
128 | 568 return; |
569 } | |
570 | |
571 buddylist_build(); | |
572 update_roster = TRUE; | |
166 | 573 if (leave_windowbuddy) scr_ShowBuddyWindow(); |
128 | 574 } |
575 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
576 static void do_say(char *arg) |
132 | 577 { |
164 | 578 gpointer bud; |
132 | 579 |
580 scr_set_chatmode(TRUE); | |
164 | 581 |
582 if (!current_buddy) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
583 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); |
164 | 584 return; |
132 | 585 } |
164 | 586 |
587 bud = BUDDATA(current_buddy); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
588 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
589 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); |
164 | 590 return; |
591 } | |
592 | |
593 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
594 send_message(arg); | |
132 | 595 } |
596 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
597 static void do_msay(char *arg) |
238 | 598 { |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
599 /* Parameters: begin verbatim abort send */ |
238 | 600 gpointer bud; |
601 | |
602 if (!strcasecmp(arg, "abort")) { | |
315
65aa05520556
First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
603 if (scr_get_multimode()) |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
604 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode"); |
238 | 605 scr_set_multimode(FALSE); |
606 return; | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
607 } else if ((!strcasecmp(arg, "begin")) || (!strcasecmp(arg, "verbatim"))) { |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
608 if (!strcasecmp(arg, "verbatim")) |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
609 scr_set_multimode(2); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
610 else |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
611 scr_set_multimode(1); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
612 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
613 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
614 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " |
238 | 615 "when your message is ready."); |
616 return; | |
446 | 617 } else if (!*arg) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
618 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
619 "the /msay command."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
620 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
621 "multi-line mode...)"); |
238 | 622 return; |
623 } else if (strcasecmp(arg, "send")) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
624 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
238 | 625 return; |
626 } | |
627 | |
628 // send command | |
629 | |
630 if (!scr_get_multimode()) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
631 scr_LogPrint(LPRINT_NORMAL, "No message to send. " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
632 "Use \"/msay begin\" first."); |
238 | 633 return; |
634 } | |
635 | |
636 scr_set_chatmode(TRUE); | |
637 | |
638 if (!current_buddy) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
639 scr_LogPrint(LPRINT_NORMAL, "Who are you talking to??"); |
238 | 640 return; |
641 } | |
642 | |
643 bud = BUDDATA(current_buddy); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
644 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
645 scr_LogPrint(LPRINT_NORMAL, "This is not a user"); |
238 | 646 return; |
647 } | |
648 | |
649 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
650 send_message(scr_get_multiline()); | |
651 scr_set_multimode(FALSE); | |
652 } | |
653 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
654 static void do_buffer(char *arg) |
187 | 655 { |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
656 int search_dir = 0; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
657 |
471
82a27508fb85
Fix segfaults when using /buffer and /room while not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
658 if (!current_buddy) return; |
446 | 659 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_GROUP) { |
660 scr_LogPrint(LPRINT_NORMAL, "Groups have no buffer"); | |
661 return; | |
662 } | |
663 | |
187 | 664 if (!strcasecmp(arg, "top")) { |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
665 scr_BufferTopBottom(-1); |
187 | 666 } else if (!strcasecmp(arg, "bottom")) { |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
667 scr_BufferTopBottom(1); |
187 | 668 } else if (!strcasecmp(arg, "clear")) { |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
669 scr_BufferClear(); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
670 } else if (!strncasecmp(arg, "search_backward", 15)) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
671 arg += 15; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
672 if (*arg++ == ' ') |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
673 search_dir = -1; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
674 else |
446 | 675 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
676 } else if (!strncasecmp(arg, "search_forward", 14)) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
677 arg += 14; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
678 if (*arg++ == ' ') |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
679 search_dir = 1; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
680 else |
446 | 681 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); |
464 | 682 } else if (!strncasecmp(arg, "date", 4)) { |
683 arg += 4; | |
684 if (*arg++ != ' ') { | |
685 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); | |
686 return; | |
687 } | |
688 while (*arg == ' ') arg++; | |
689 if (*arg) { | |
690 time_t t = from_iso8601(arg, 0); | |
691 if (t) | |
692 scr_BufferDate(t); | |
693 else | |
694 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); | |
695 } | |
696 else | |
697 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); | |
462 | 698 } else if (*arg == '%') { |
699 arg++; | |
700 while (*arg == ' ') arg++; | |
701 if (*arg) | |
702 scr_BufferPercent(atoi(arg)); | |
703 else | |
704 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); | |
187 | 705 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
706 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
707 |
371
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
708 if (search_dir) { // It is a string search command |
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
709 for ( ; *arg && *arg == ' ' ; arg++) |
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
710 ; |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
711 scr_BufferSearch(search_dir, arg); |
371
bc54af8ed048
/buffer search_*: skip leading spaces (if any) in string parameter
Mikael Berthe <mikael@lilotux.net>
parents:
370
diff
changeset
|
712 } |
187 | 713 } |
714 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
715 static void do_clear(char *arg) // Alias for "/buffer clear" |
187 | 716 { |
717 do_buffer("clear"); | |
718 } | |
719 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
720 static void do_info(char *arg) |
191 | 721 { |
722 gpointer bud; | |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
723 const char *jid, *name; |
191 | 724 guint type; |
725 char *buffer; | |
726 | |
727 if (!current_buddy) return; | |
728 bud = BUDDATA(current_buddy); | |
729 | |
730 jid = buddy_getjid(bud); | |
731 name = buddy_getname(bud); | |
732 type = buddy_gettype(bud); | |
733 | |
734 buffer = g_new(char, 128); | |
735 | |
736 if (jid) { | |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
737 GSList *resources; |
191 | 738 char *typestr = "unknown"; |
739 | |
740 snprintf(buffer, 127, "jid: <%s>", jid); | |
741 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
742 if (name) { | |
743 snprintf(buffer, 127, "Name: %s", name); | |
744 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
745 } | |
746 | |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
747 if (type == ROSTER_TYPE_USER) typestr = "user"; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
748 else if (type == ROSTER_TYPE_ROOM) typestr = "chatroom"; |
191 | 749 else if (type == ROSTER_TYPE_AGENT) typestr = "agent"; |
750 snprintf(buffer, 127, "Type: %s", typestr); | |
751 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); | |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
752 |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
753 resources = buddy_getresources(bud); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
754 for ( ; resources ; resources = g_slist_next(resources) ) { |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
755 gchar rprio; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
756 enum imstatus rstatus; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
757 const char *rst_msg; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
758 |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
759 rprio = buddy_getresourceprio(bud, resources->data); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
760 rstatus = buddy_getstatus(bud, resources->data); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
761 rst_msg = buddy_getstatusmsg(bud, resources->data); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
762 |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
763 snprintf(buffer, 127, "Resource: [%c] (%d) %s", imstatus2char[rstatus], |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
764 rprio, (char*)resources->data); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
765 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
766 if (rst_msg) { |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
767 snprintf(buffer, 127, "Status message: %s", rst_msg); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
768 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
769 } |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
770 } |
191 | 771 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
772 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
773 scr_LogPrint(LPRINT_NORMAL, "Type: %s", |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
774 ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown")); |
191 | 775 } |
776 | |
777 g_free(buffer); | |
778 } | |
779 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
780 static void do_rename(char *arg) |
208 | 781 { |
782 gpointer bud; | |
783 const char *jid, *group; | |
784 guint type; | |
785 char *newname, *p; | |
786 | |
446 | 787 if (!arg || (!*arg)) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
788 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
208 | 789 return; |
790 } | |
791 | |
792 if (!current_buddy) return; | |
793 bud = BUDDATA(current_buddy); | |
794 | |
795 jid = buddy_getjid(bud); | |
796 group = buddy_getgroupname(bud); | |
797 type = buddy_gettype(bud); | |
798 | |
799 if (type & ROSTER_TYPE_GROUP) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
800 scr_LogPrint(LPRINT_NORMAL, "You can't rename groups"); |
208 | 801 return; |
802 } | |
803 | |
804 newname = g_strdup(arg); | |
805 // Remove trailing space | |
806 for (p = newname; *p; p++) ; | |
807 while (p > newname && *p == ' ') *p = 0; | |
808 | |
809 buddy_setname(bud, newname); | |
810 jb_updatebuddy(jid, newname, group); | |
811 | |
812 g_free(newname); | |
813 update_roster = TRUE; | |
814 } | |
815 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
816 static void do_move(char *arg) |
210 | 817 { |
818 gpointer bud; | |
819 const char *jid, *name; | |
820 guint type; | |
821 char *newgroupname, *p; | |
822 | |
823 if (!current_buddy) return; | |
824 bud = BUDDATA(current_buddy); | |
825 | |
826 jid = buddy_getjid(bud); | |
827 name = buddy_getname(bud); | |
828 type = buddy_gettype(bud); | |
829 | |
830 if (type & ROSTER_TYPE_GROUP) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
831 scr_LogPrint(LPRINT_NORMAL, "You can't move groups!"); |
210 | 832 return; |
833 } | |
834 | |
835 newgroupname = g_strdup(arg); | |
836 // Remove trailing space | |
837 for (p = newgroupname; *p; p++) ; | |
838 while (p > newgroupname && *p == ' ') *p = 0; | |
839 | |
840 // Call to buddy_setgroup() should be at the end, as current implementation | |
841 // clones the buddy and deletes the old one (and thus, jid and name are | |
842 // freed) | |
843 jb_updatebuddy(jid, name, newgroupname); | |
844 buddy_setgroup(bud, newgroupname); | |
845 | |
846 g_free(newgroupname); | |
847 update_roster = TRUE; | |
848 } | |
849 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
850 static void do_set(char *arg) |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
851 { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
852 guint assign; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
853 const gchar *option, *value; |
393 | 854 |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
855 assign = parse_assigment(arg, &option, &value); |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
856 if (!option) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
857 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
858 return; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
859 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
860 if (!assign) { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
861 // This is a query |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
862 value = settings_opt_get(option); |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
863 if (value) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
864 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option, value); |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
865 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
866 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option); |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
867 return; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
868 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
869 // Update the option |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
870 // XXX Maybe some options should be protected when user is connected |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
871 // (server, username, etc.). And we should catch some options here, too |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
872 // (hide_offline_buddies for ex.) |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
873 if (!value) { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
874 settings_del(SETTINGS_TYPE_OPTION, option); |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
875 } else { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
876 settings_set(SETTINGS_TYPE_OPTION, option, value); |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
877 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
878 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
879 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
880 static void do_alias(char *arg) |
285 | 881 { |
882 guint assign; | |
883 const gchar *alias, *value; | |
393 | 884 |
285 | 885 assign = parse_assigment(arg, &alias, &value); |
886 if (!alias) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
887 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
285 | 888 return; |
889 } | |
890 if (!assign) { | |
891 // This is a query | |
892 value = settings_get(SETTINGS_TYPE_ALIAS, alias); | |
893 if (value) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
894 scr_LogPrint(LPRINT_NORMAL, "%s = %s", alias, value); |
285 | 895 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
896 scr_LogPrint(LPRINT_NORMAL, "Alias '%s' does not exist", alias); |
285 | 897 return; |
898 } | |
899 // Check the alias does not conflict with a registered command | |
900 if (cmd_get(alias)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
901 scr_LogPrint(LPRINT_NORMAL, "'%s' is a reserved word!", alias); |
285 | 902 return; |
903 } | |
904 // Update the alias | |
905 if (!value) { | |
906 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { | |
907 settings_del(SETTINGS_TYPE_ALIAS, alias); | |
908 // Remove alias from the completion list | |
909 compl_del_category_word(COMPL_CMD, alias); | |
910 } | |
911 } else { | |
912 // Add alias to the completion list, if not already in | |
913 if (!settings_get(SETTINGS_TYPE_ALIAS, alias)) | |
914 compl_add_category_word(COMPL_CMD, alias); | |
915 settings_set(SETTINGS_TYPE_ALIAS, alias, value); | |
916 } | |
917 } | |
918 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
919 static void do_bind(char *arg) |
288 | 920 { |
921 guint assign; | |
922 const gchar *keycode, *value; | |
393 | 923 |
288 | 924 assign = parse_assigment(arg, &keycode, &value); |
925 if (!keycode) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
926 scr_LogPrint(LPRINT_NORMAL, "Huh?"); |
288 | 927 return; |
928 } | |
929 if (!assign) { | |
930 // This is a query | |
931 value = settings_get(SETTINGS_TYPE_BINDING, keycode); | |
932 if (value) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
933 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", keycode, value); |
288 | 934 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
935 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound", keycode); |
288 | 936 return; |
937 } | |
938 // Update the key binding | |
939 if (!value) | |
940 settings_del(SETTINGS_TYPE_BINDING, keycode); | |
941 else | |
942 settings_set(SETTINGS_TYPE_BINDING, keycode, value); | |
943 } | |
944 | |
436 | 945 static void do_rawxml(char *arg) |
946 { | |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
947 if (!jb_getonline()) { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
948 scr_LogPrint(LPRINT_NORMAL, "You are not connected"); |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
949 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
950 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
951 |
436 | 952 if (!strncasecmp(arg, "send ", 5)) { |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
953 gchar *buffer; |
436 | 954 for (arg += 5; *arg && *arg == ' '; arg++) |
955 ; | |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
956 buffer = to_utf8(arg); |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
957 if (!buffer) { |
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
958 scr_LogPrint(LPRINT_NORMAL, "Conversion error in XML string"); |
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
959 return; |
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
960 } |
436 | 961 scr_LogPrint(LPRINT_NORMAL, "Sending XML string"); |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
962 jb_send_raw(buffer); |
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
963 g_free(buffer); |
436 | 964 } else { |
965 scr_LogPrint(LPRINT_NORMAL, "Please read the manual page" | |
966 " before using /rawxml :-)"); | |
967 } | |
968 } | |
969 | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
970 static void do_room(char *arg) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
971 { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
972 gpointer bud; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
973 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
974 if (!jb_getonline()) { |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
975 scr_LogPrint(LPRINT_NORMAL, "You are not connected"); |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
976 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
977 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
978 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
979 if (!arg || (!*arg)) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
980 scr_LogPrint(LPRINT_NORMAL, "Missing parameter"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
981 return; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
982 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
983 |
471
82a27508fb85
Fix segfaults when using /buffer and /room while not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
984 if (!current_buddy) return; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
985 bud = BUDDATA(current_buddy); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
986 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
987 if (!strncasecmp(arg, "join", 4)) { |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
988 char *roomname, *nick; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
989 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
990 arg += 4; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
991 if (*arg++ != ' ') { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
992 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
993 return; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
994 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
995 for (; *arg && *arg == ' '; arg++) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
996 ; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
997 |
454
d647b92e541f
MUC: Disallow room names with a '/'
Mikael Berthe <mikael@lilotux.net>
parents:
452
diff
changeset
|
998 if (strchr(arg, '/')) { |
d647b92e541f
MUC: Disallow room names with a '/'
Mikael Berthe <mikael@lilotux.net>
parents:
452
diff
changeset
|
999 scr_LogPrint(LPRINT_NORMAL, "Invalid room name"); |
d647b92e541f
MUC: Disallow room names with a '/'
Mikael Berthe <mikael@lilotux.net>
parents:
452
diff
changeset
|
1000 return; |
d647b92e541f
MUC: Disallow room names with a '/'
Mikael Berthe <mikael@lilotux.net>
parents:
452
diff
changeset
|
1001 } |
d647b92e541f
MUC: Disallow room names with a '/'
Mikael Berthe <mikael@lilotux.net>
parents:
452
diff
changeset
|
1002 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1003 roomname = g_strdup(arg); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1004 nick = strchr(roomname, ' '); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1005 if (!nick) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1006 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (nickname)"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1007 g_free(roomname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1008 return; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1009 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1010 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1011 *nick++ = 0; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1012 while (*nick && *nick == ' ') |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1013 nick++; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1014 if (!*nick) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1015 scr_LogPrint(LPRINT_NORMAL, "Missing parameter (nickname)"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1016 g_free(roomname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1017 return; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1018 } |
452 | 1019 |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
1020 mc_strtolower(roomname); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
1021 jb_room_join(roomname, nick); |
452 | 1022 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1023 g_free(roomname); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1024 buddylist_build(); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1025 update_roster = TRUE; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1026 } else if (!strncasecmp(arg, "leave", 5)) { |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
1027 gchar *roomid, *utf8_nickname; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1028 arg += 5; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1029 for (; *arg && *arg == ' '; arg++) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1030 ; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1031 if (!(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1032 scr_LogPrint(LPRINT_NORMAL, "This isn't a chatroom"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1033 return; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1034 } |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
1035 utf8_nickname = to_utf8(buddy_getnickname(bud)); |
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
1036 roomid = g_strdup_printf("%s/%s", buddy_getjid(bud), utf8_nickname); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1037 jb_setstatus(offline, roomid, arg); |
469
a926523d2392
Use UTF8 to handle resources and room nicknames
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
1038 g_free(utf8_nickname); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1039 g_free(roomid); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1040 buddy_setnickname(bud, NULL); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1041 buddy_del_all_resources(bud); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1042 scr_LogPrint(LPRINT_NORMAL, "You have left %s", buddy_getjid(bud)); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1043 } else if (!strcasecmp(arg, "names")) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1044 if (!(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1045 scr_LogPrint(LPRINT_NORMAL, "This isn't a chatroom"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1046 return; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1047 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1048 do_info(NULL); |
470 | 1049 } else if (!strncasecmp(arg, "nick", 4)) { |
1050 gchar *cmd; | |
1051 arg += 4; | |
1052 if (*arg++ != ' ') { | |
1053 scr_LogPrint(LPRINT_NORMAL, "Wrong or missing parameter"); | |
1054 return; | |
1055 } | |
1056 for (; *arg && *arg == ' '; arg++) | |
1057 ; | |
1058 if (!(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) { | |
1059 scr_LogPrint(LPRINT_NORMAL, "This isn't a chatroom"); | |
1060 return; | |
1061 } | |
1062 cmd = g_strdup_printf("join %s %s", buddy_getjid(bud), arg); | |
1063 do_room(cmd); | |
1064 g_free(cmd); | |
448
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1065 } else if (!strcasecmp(arg, "remove")) { |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1066 if (!(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) { |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1067 scr_LogPrint(LPRINT_NORMAL, "This isn't a chatroom"); |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1068 return; |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1069 } |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1070 // Quick check: if there are resources, we haven't left |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1071 if (buddy_getresources(bud)) { |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1072 scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!"); |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1073 return; |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1074 } |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1075 // Delete the room |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1076 roster_del_user(buddy_getjid(bud)); |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1077 buddylist_build(); |
39a28cb59af3
Add "/room remove", to remove an old chatroom from the roster
Mikael Berthe <mikael@lilotux.net>
parents:
447
diff
changeset
|
1078 update_roster = TRUE; |
449 | 1079 } else if (!strcasecmp(arg, "unlock")) { |
1080 if (!(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) { | |
1081 scr_LogPrint(LPRINT_NORMAL, "This isn't a chatroom"); | |
1082 return; | |
1083 } | |
1084 jb_room_unlock(buddy_getjid(bud)); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1085 } else { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1086 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1087 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1088 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1089 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1090 static void do_connect(char *arg) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1091 { |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1092 mcabber_connect(); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1093 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1094 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1095 static void do_disconnect(char *arg) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1096 { |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1097 jb_disconnect(); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1098 } |