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