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