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