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