annotate mcabber/src/commands.c @ 519:5c338d31de56

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