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