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