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