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