Mercurial > hg
annotate mcabber/src/commands.c @ 699:ee03b56b93ee
Update Copyright (2006)
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 12 Feb 2006 11:39:32 +0100 |
parents | ee06382dfb22 |
children | b26a0bde4cdb |
rev | line source |
---|---|
47 | 1 /* |
699 | 2 * commands.c -- user commands handling |
393 | 3 * |
699 | 4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.lilotux.net> |
47 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
95 | 22 #include <string.h> |
23 | |
47 | 24 #include "commands.h" |
25 #include "jabglue.h" | |
81 | 26 #include "roster.h" |
47 | 27 #include "screen.h" |
95 | 28 #include "compl.h" |
113 | 29 #include "hooks.h" |
191 | 30 #include "hbuf.h" |
47 | 31 #include "utils.h" |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
32 #include "settings.h" |
47 | 33 |
104 | 34 // Commands callbacks |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
35 static void do_roster(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
36 static void do_status(char *arg); |
444 | 37 static void do_status_to(char *arg); |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
38 static void do_add(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
39 static void do_del(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
40 static void do_group(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
41 static void do_say(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
42 static void do_msay(char *arg); |
480 | 43 static void do_say_to(char *arg); |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
44 static void do_buffer(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
45 static void do_clear(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
46 static void do_info(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
47 static void do_rename(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
48 static void do_move(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
49 static void do_set(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
50 static void do_alias(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
51 static void do_bind(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
52 static void do_connect(char *arg); |
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
53 static void do_disconnect(char *arg); |
436 | 54 static void do_rawxml(char *arg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
55 static void do_room(char *arg); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
56 static void do_authorization(char *arg); |
622 | 57 static void do_version(char *arg); |
693 | 58 static void do_request(char *arg); |
47 | 59 |
104 | 60 // Global variable for the commands list |
95 | 61 static GSList *Commands; |
62 | |
104 | 63 |
95 | 64 // cmd_add() |
65 // Adds a command to the commands list and to the CMD completion list | |
66 void cmd_add(const char *name, const char *help, | |
104 | 67 guint flags_row1, guint flags_row2, void (*f)()) |
95 | 68 { |
69 cmd *n_cmd = g_new0(cmd, 1); | |
70 strncpy(n_cmd->name, name, 32-1); | |
71 n_cmd->help = help; | |
72 n_cmd->completion_flags[0] = flags_row1; | |
73 n_cmd->completion_flags[1] = flags_row2; | |
74 n_cmd->func = f; | |
102 | 75 Commands = g_slist_append(Commands, n_cmd); |
95 | 76 // Add to completion CMD category |
77 compl_add_category_word(COMPL_CMD, name); | |
78 } | |
79 | |
80 // cmd_init() | |
81 // ... | |
82 void cmd_init(void) | |
83 { | |
124 | 84 cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add); |
285 | 85 cmd_add("alias", "Add an alias", 0, 0, &do_alias); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
86 cmd_add("authorization", "Manage subscription authorizations", |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
87 COMPL_AUTH, COMPL_JID, &do_authorization); |
288 | 88 cmd_add("bind", "Add an key binding", 0, 0, &do_bind); |
187 | 89 cmd_add("buffer", "Manipulate current buddy's buffer (chat window)", |
90 COMPL_BUFFER, 0, &do_buffer); | |
108 | 91 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
|
92 cmd_add("connect", "Connect to the server", 0, 0, &do_connect); |
205 | 93 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
|
94 cmd_add("disconnect", "Disconnect from server", 0, 0, &do_disconnect); |
128 | 95 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
|
96 //cmd_add("help", "Display some help", COMPL_CMD, 0, NULL); |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
97 cmd_add("info", "Show basic info on current buddy", 0, 0, &do_info); |
225 | 98 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME, |
99 0, &do_move); | |
238 | 100 cmd_add("msay", "Send a multi-lines message to the selected buddy", |
101 COMPL_MULTILINE, 0, &do_msay); | |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
102 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room); |
693 | 103 cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID, |
104 &do_request); | |
95 | 105 cmd_add("quit", "Exit the software", 0, 0, NULL); |
436 | 106 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml); |
208 | 107 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename); |
128 | 108 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0, |
109 &do_roster); | |
132 | 110 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
|
111 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
|
112 &do_say_to); |
95 | 113 //cmd_add("search"); |
310 | 114 cmd_add("set", "Set/query an option value", 0, 0, &do_set); |
116 | 115 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status); |
444 | 116 cmd_add("status_to", "Show or set your status for one recipient", |
117 COMPL_JID, COMPL_STATUS, &do_status_to); | |
622 | 118 cmd_add("version", "Show mcabber version", 0, 0, &do_version); |
95 | 119 |
120 // Status category | |
121 compl_add_category_word(COMPL_STATUS, "online"); | |
122 compl_add_category_word(COMPL_STATUS, "avail"); | |
123 compl_add_category_word(COMPL_STATUS, "invisible"); | |
124 compl_add_category_word(COMPL_STATUS, "free"); | |
125 compl_add_category_word(COMPL_STATUS, "dnd"); | |
126 compl_add_category_word(COMPL_STATUS, "notavail"); | |
127 compl_add_category_word(COMPL_STATUS, "away"); | |
103 | 128 |
129 // Roster category | |
130 compl_add_category_word(COMPL_ROSTER, "bottom"); | |
265 | 131 compl_add_category_word(COMPL_ROSTER, "top"); |
377
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
132 compl_add_category_word(COMPL_ROSTER, "up"); |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
133 compl_add_category_word(COMPL_ROSTER, "down"); |
103 | 134 compl_add_category_word(COMPL_ROSTER, "hide_offline"); |
135 compl_add_category_word(COMPL_ROSTER, "show_offline"); | |
290
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
136 compl_add_category_word(COMPL_ROSTER, "toggle_offline"); |
330 | 137 compl_add_category_word(COMPL_ROSTER, "alternate"); |
265 | 138 compl_add_category_word(COMPL_ROSTER, "search"); |
236 | 139 compl_add_category_word(COMPL_ROSTER, "unread_first"); |
140 compl_add_category_word(COMPL_ROSTER, "unread_next"); | |
127 | 141 |
187 | 142 // Roster category |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
506
diff
changeset
|
143 compl_add_category_word(COMPL_BUFFER, "clear"); |
187 | 144 compl_add_category_word(COMPL_BUFFER, "bottom"); |
145 compl_add_category_word(COMPL_BUFFER, "top"); | |
508
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
506
diff
changeset
|
146 compl_add_category_word(COMPL_BUFFER, "up"); |
5a2132ba2220
Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents:
506
diff
changeset
|
147 compl_add_category_word(COMPL_BUFFER, "down"); |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
148 compl_add_category_word(COMPL_BUFFER, "search_backward"); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
149 compl_add_category_word(COMPL_BUFFER, "search_forward"); |
464 | 150 compl_add_category_word(COMPL_BUFFER, "date"); |
462 | 151 compl_add_category_word(COMPL_BUFFER, "%"); |
187 | 152 |
127 | 153 // Group category |
240 | 154 compl_add_category_word(COMPL_GROUP, "fold"); |
155 compl_add_category_word(COMPL_GROUP, "unfold"); | |
130 | 156 compl_add_category_word(COMPL_GROUP, "toggle"); |
238 | 157 |
158 // Multi-line (msay) category | |
159 compl_add_category_word(COMPL_MULTILINE, "abort"); | |
160 compl_add_category_word(COMPL_MULTILINE, "begin"); | |
161 compl_add_category_word(COMPL_MULTILINE, "send"); | |
636 | 162 compl_add_category_word(COMPL_MULTILINE, "send_to"); |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
163 compl_add_category_word(COMPL_MULTILINE, "verbatim"); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
164 |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
165 // Room category |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
166 compl_add_category_word(COMPL_ROOM, "affil"); |
571 | 167 compl_add_category_word(COMPL_ROOM, "ban"); |
599 | 168 compl_add_category_word(COMPL_ROOM, "destroy"); |
486 | 169 compl_add_category_word(COMPL_ROOM, "invite"); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
170 compl_add_category_word(COMPL_ROOM, "join"); |
568 | 171 compl_add_category_word(COMPL_ROOM, "kick"); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
172 compl_add_category_word(COMPL_ROOM, "leave"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
173 compl_add_category_word(COMPL_ROOM, "names"); |
470 | 174 compl_add_category_word(COMPL_ROOM, "nick"); |
490 | 175 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
|
176 compl_add_category_word(COMPL_ROOM, "remove"); |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
177 compl_add_category_word(COMPL_ROOM, "role"); |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
178 compl_add_category_word(COMPL_ROOM, "topic"); |
449 | 179 compl_add_category_word(COMPL_ROOM, "unlock"); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
180 compl_add_category_word(COMPL_ROOM, "whois"); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
181 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
182 // Authorization category |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
183 compl_add_category_word(COMPL_AUTH, "allow"); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
184 compl_add_category_word(COMPL_AUTH, "cancel"); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
185 compl_add_category_word(COMPL_AUTH, "request"); |
693 | 186 |
187 // Request (query) category | |
188 compl_add_category_word(COMPL_REQUEST, "time"); | |
189 compl_add_category_word(COMPL_REQUEST, "version"); | |
95 | 190 } |
94 | 191 |
285 | 192 // expandalias(line) |
193 // If there is one, expand the alias in line and returns a new allocated line | |
194 // If no alias is found, returns line | |
195 // Note : if the returned pointer is different from line, the caller should | |
196 // g_free() the pointer after use | |
197 char *expandalias(char *line) | |
198 { | |
199 const char *p1, *p2; | |
200 char *word; | |
201 const gchar *value; | |
202 char *newline = line; | |
203 | |
204 // Ignore leading '/' | |
205 for (p1 = line ; *p1 == '/' ; p1++) | |
206 ; | |
207 // Locate the end of the word | |
208 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++) | |
209 ; | |
210 // Extract the word | |
211 word = g_strndup(p1, p2-p1); | |
212 | |
213 // Look for an alias in the list | |
214 value = settings_get(SETTINGS_TYPE_ALIAS, (const char*)word); | |
215 if (value) { | |
216 // There is an alias to expand | |
217 newline = g_new(char, strlen(value)+strlen(p2)+2); | |
218 *newline = '/'; | |
219 strcpy(newline+1, value); | |
220 strcat(newline, p2); | |
221 } | |
222 g_free(word); | |
223 | |
224 return newline; | |
225 } | |
226 | |
102 | 227 // cmd_get |
228 // Finds command in the command list structure. | |
229 // Returns a pointer to the cmd entry, or NULL if command not found. | |
238 | 230 cmd *cmd_get(const char *command) |
102 | 231 { |
238 | 232 const char *p1, *p2; |
102 | 233 char *com; |
234 GSList *sl_com; | |
285 | 235 |
102 | 236 // Ignore leading '/' |
237 for (p1 = command ; *p1 == '/' ; p1++) | |
238 ; | |
239 // Locate the end of the command | |
240 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++) | |
241 ; | |
242 // Copy the clean command | |
243 com = g_strndup(p1, p2-p1); | |
244 | |
245 // Look for command in the list | |
246 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) { | |
247 if (!strcasecmp(com, ((cmd*)sl_com->data)->name)) | |
248 break; | |
249 } | |
250 g_free(com); | |
251 | |
252 if (sl_com) // Command has been found. | |
253 return (cmd*)sl_com->data; | |
254 return NULL; | |
255 } | |
256 | |
47 | 257 // send_message(msg) |
258 // Write the message in the buddy's window and send the message on | |
259 // the network. | |
636 | 260 static void send_message(const char *msg) |
47 | 261 { |
81 | 262 const char *jid; |
393 | 263 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
264 if (!jb_getonline()) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
265 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
266 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
267 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
268 |
81 | 269 if (!current_buddy) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
270 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected."); |
81 | 271 return; |
272 } | |
273 | |
274 jid = CURRENT_JID; | |
275 if (!jid) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
276 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected."); |
81 | 277 return; |
278 } | |
47 | 279 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
280 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
281 // 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
|
282 hk_message_out(jid, NULL, 0, msg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
283 } |
47 | 284 |
285 // Network part | |
475
fa49ac0bb8f3
Add "/room topic", and display topic changes
Mikael Berthe <mikael@lilotux.net>
parents:
472
diff
changeset
|
286 jb_send_msg(jid, msg, buddy_gettype(BUDDATA(current_buddy)), NULL); |
47 | 287 } |
288 | |
288 | 289 // process_command(line) |
290 // Process a command line. | |
291 // Return 255 if this is the /quit command, and 0 for the other commands. | |
292 int process_command(char *line) | |
47 | 293 { |
101 | 294 char *p; |
285 | 295 char *xpline; |
104 | 296 cmd *curcmd; |
297 | |
101 | 298 // Remove trailing spaces: |
299 for (p=line ; *p ; p++) | |
300 ; | |
301 for (p-- ; p>line && (*p == ' ') ; p--) | |
302 *p = 0; | |
303 | |
285 | 304 // We do alias expansion here |
288 | 305 if (scr_get_multimode() != 2) |
306 xpline = expandalias(line); | |
307 else | |
308 xpline = line; // No expansion in verbatim multi-line mode | |
285 | 309 |
101 | 310 // Command "quit"? |
285 | 311 if ((!strncasecmp(xpline, "/quit", 5)) && (scr_get_multimode() != 2) ) |
312 if (!xpline[5] || xpline[5] == ' ') | |
116 | 313 return 255; |
104 | 314 |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
315 // If verbatim multi-line mode, we check if another /msay command is typed |
285 | 316 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
|
317 // It isn't an /msay command |
285 | 318 scr_append_multiline(xpline); |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
319 return 0; |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
320 } |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
321 |
47 | 322 // Commands handling |
285 | 323 curcmd = cmd_get(xpline); |
47 | 324 |
104 | 325 if (!curcmd) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
326 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command. " |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
327 "Please see the manual for a list of known commands."); |
285 | 328 if (xpline != line) g_free(xpline); |
104 | 329 return 0; |
330 } | |
331 if (!curcmd->func) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
332 scr_LogPrint(LPRINT_NORMAL, |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
333 "This functionality is not yet implemented, sorry."); |
285 | 334 if (xpline != line) g_free(xpline); |
104 | 335 return 0; |
336 } | |
337 // Lets go to the command parameters | |
285 | 338 for (p = xpline+1; *p && (*p != ' ') ; p++) |
104 | 339 ; |
340 // Skip spaces | |
285 | 341 while (*p && (*p == ' ')) |
342 p++; | |
104 | 343 // Call command-specific function |
285 | 344 (*curcmd->func)(p); |
345 if (xpline != line) g_free(xpline); | |
47 | 346 return 0; |
347 } | |
348 | |
288 | 349 // process_line(line) |
350 // Process a command/message line. | |
351 // If this isn't a command, this is a message and it is sent to the | |
352 // currently selected buddy. | |
353 // Return 255 if the line is the /quit command, or 0. | |
354 int process_line(char *line) | |
355 { | |
356 if (!*line) { // User only pressed enter | |
357 if (scr_get_multimode()) { | |
358 scr_append_multiline(""); | |
359 return 0; | |
360 } | |
361 if (current_buddy) { | |
647
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
362 // Enter chat mode |
288 | 363 scr_set_chatmode(TRUE); |
364 scr_ShowBuddyWindow(); | |
365 } | |
366 return 0; | |
367 } | |
368 | |
369 if (*line != '/') { | |
370 // This isn't a command | |
371 if (scr_get_multimode()) | |
372 scr_append_multiline(line); | |
373 else | |
374 do_say(line); | |
375 return 0; | |
376 } | |
377 | |
378 /* It is (probably) a command -- except for verbatim multi-line mode */ | |
379 return process_command(line); | |
380 } | |
381 | |
104 | 382 /* Commands callback functions */ |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
383 /* All these do_*() functions will be called with a "arg" parameter */ |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
384 /* (with arg not null) */ |
104 | 385 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
386 static void do_roster(char *arg) |
104 | 387 { |
388 if (!strcasecmp(arg, "top")) { | |
389 scr_RosterTop(); | |
128 | 390 update_roster = TRUE; |
104 | 391 } else if (!strcasecmp(arg, "bottom")) { |
392 scr_RosterBottom(); | |
128 | 393 update_roster = TRUE; |
104 | 394 } else if (!strcasecmp(arg, "hide_offline")) { |
120 | 395 buddylist_set_hide_offline_buddies(TRUE); |
104 | 396 if (current_buddy) |
397 buddylist_build(); | |
128 | 398 update_roster = TRUE; |
104 | 399 } else if (!strcasecmp(arg, "show_offline")) { |
120 | 400 buddylist_set_hide_offline_buddies(FALSE); |
124 | 401 buddylist_build(); |
128 | 402 update_roster = TRUE; |
290
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
403 } else if (!strcasecmp(arg, "toggle_offline")) { |
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
404 buddylist_set_hide_offline_buddies(-1); |
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
405 buddylist_build(); |
f63839a4cb35
Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents:
288
diff
changeset
|
406 update_roster = TRUE; |
236 | 407 } else if (!strcasecmp(arg, "unread_first")) { |
408 scr_RosterUnreadMessage(0); | |
409 } else if (!strcasecmp(arg, "unread_next")) { | |
410 scr_RosterUnreadMessage(1); | |
330 | 411 } else if (!strcasecmp(arg, "alternate")) { |
412 scr_RosterJumpAlternate(); | |
265 | 413 } else if (!strncasecmp(arg, "search", 6)) { |
414 char *string = arg+6; | |
415 if (*string && (*string != ' ')) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
416 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
265 | 417 return; |
418 } | |
419 while (*string == ' ') | |
420 string++; | |
421 if (!*string) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
422 scr_LogPrint(LPRINT_NORMAL, "What name or JID are you looking for?"); |
265 | 423 return; |
424 } | |
425 scr_RosterSearch(string); | |
426 update_roster = TRUE; | |
377
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
427 } else if (!strcasecmp(arg, "up")) { |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
428 scr_RosterUp(); |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
429 } else if (!strcasecmp(arg, "down")) { |
00809e3e327e
Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents:
374
diff
changeset
|
430 scr_RosterDown(); |
104 | 431 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
432 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
104 | 433 } |
108 | 434 |
444 | 435 // setstatus(recipient, arg) |
436 // Set your Jabber status. | |
437 // - if recipient is not NULL, the status is sent to this contact only | |
438 // - arg must be "status message" (message is optional) | |
439 static void setstatus(const char *recipient, const char *arg) | |
116 | 440 { |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
441 char **paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
442 char *status; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
443 char *msg; |
116 | 444 enum imstatus st; |
445 | |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
446 if (!jb_getonline()) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
447 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
448 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
449 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
450 |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
451 paramlst = split_arg(arg, 2, 0); // status, message |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
452 status = *paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
453 msg = *(paramlst+1); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
454 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
455 if (!status) { |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
456 free_arg_lst(paramlst); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
457 return; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
458 } |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
459 |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
460 if (!strcasecmp(status, "offline")) st = offline; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
461 else if (!strcasecmp(status, "online")) st = available; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
462 else if (!strcasecmp(status, "avail")) st = available; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
463 else if (!strcasecmp(status, "away")) st = away; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
464 else if (!strcasecmp(status, "invisible")) st = invisible; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
465 else if (!strcasecmp(status, "dnd")) st = dontdisturb; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
466 else if (!strcasecmp(status, "notavail")) st = notavail; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
467 else if (!strcasecmp(status, "free")) st = freeforchat; |
116 | 468 else { |
444 | 469 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!"); |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
470 free_arg_lst(paramlst); |
116 | 471 return; |
472 } | |
473 | |
677
633a0522bd37
Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents:
659
diff
changeset
|
474 // Use provided message |
633a0522bd37
Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents:
659
diff
changeset
|
475 if (msg && !*msg) { |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
476 msg = NULL; |
677
633a0522bd37
Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents:
659
diff
changeset
|
477 } |
318
45076d02eeef
The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
478 |
528
2f714bd701a1
Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents:
519
diff
changeset
|
479 // If a recipient is specified, let's don't use default status messages |
2f714bd701a1
Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents:
519
diff
changeset
|
480 if (recipient && !msg) |
2f714bd701a1
Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents:
519
diff
changeset
|
481 msg = ""; |
2f714bd701a1
Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents:
519
diff
changeset
|
482 |
444 | 483 jb_setstatus(st, recipient, msg); |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
484 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
485 free_arg_lst(paramlst); |
444 | 486 } |
487 | |
488 static void do_status(char *arg) | |
489 { | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
490 if (!*arg) { |
519
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
508
diff
changeset
|
491 const char *sm = jb_getstatusmsg(); |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
508
diff
changeset
|
492 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
|
493 imstatus2char[jb_getstatus()], |
5c338d31de56
Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents:
508
diff
changeset
|
494 (sm ? sm : "")); |
444 | 495 return; |
496 } | |
497 setstatus(NULL, arg); | |
498 } | |
499 | |
500 static void do_status_to(char *arg) | |
501 { | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
502 char **paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
503 char *jid, *st, *msg; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
504 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
505 paramlst = split_arg(arg, 3, 1); // jid, status, [message] |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
506 jid = *paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
507 st = *(paramlst+1); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
508 msg = *(paramlst+2); |
444 | 509 |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
510 if (!jid || !st) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
511 scr_LogPrint(LPRINT_NORMAL, |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
512 "Please specify both a Jabber ID and a status."); |
640
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
513 free_arg_lst(paramlst); |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
514 return; |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
515 } |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
516 |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
517 // Allow things like /status_to "" away |
641
62679532ea55
Allow special jid "." in commands /add and /status_to
Mikael Berthe <mikael@lilotux.net>
parents:
640
diff
changeset
|
518 if (!*jid || !strcmp(jid, ".")) |
640
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
519 jid = NULL; |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
520 |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
521 if (jid) { |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
522 // The JID has been specified. Quick check... |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
523 if (check_jid_syntax(jid)) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
524 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); |
640
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
525 jid = NULL; |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
526 } else { |
696
ee06382dfb22
/status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents:
694
diff
changeset
|
527 // Convert jid to lowercase |
ee06382dfb22
/status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents:
694
diff
changeset
|
528 char *p = jid; |
ee06382dfb22
/status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents:
694
diff
changeset
|
529 for ( ; *p && *p != '/'; p++) |
ee06382dfb22
/status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents:
694
diff
changeset
|
530 *p = tolower(*p); |
640
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
531 } |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
532 } else { |
640
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
533 // Add the current buddy |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
534 if (current_buddy) |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
535 jid = (char*)buddy_getjid(BUDDATA(current_buddy)); |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
536 if (!jid) |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
537 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); |
640
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
538 } |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
539 |
1cd7f8e3895b
"/status_to" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
638
diff
changeset
|
540 if (jid) { |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
541 char *cmd; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
542 if (!msg) |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
543 msg = ""; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
544 cmd = g_strdup_printf("%s %s", st, msg); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
545 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", jid, cmd); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
546 setstatus(jid, cmd); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
547 g_free(cmd); |
444 | 548 } |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
549 free_arg_lst(paramlst); |
116 | 550 } |
551 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
552 static void do_add(char *arg) |
124 | 553 { |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
554 char **paramlst; |
244 | 555 char *id, *nick; |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
556 |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
557 if (!jb_getonline()) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
558 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
559 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
560 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
561 |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
562 paramlst = split_arg(arg, 2, 0); // jid, [nickname] |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
563 id = *paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
564 nick = *(paramlst+1); |
244 | 565 |
638
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
566 if (!id) |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
567 nick = NULL; // Allow things like: /add "" nick |
641
62679532ea55
Allow special jid "." in commands /add and /status_to
Mikael Berthe <mikael@lilotux.net>
parents:
640
diff
changeset
|
568 else if (!*id || !strcmp(id, ".")) |
638
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
569 id = NULL; |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
570 |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
571 if (id) { |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
572 // The JID has been specified. Quick check... |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
573 if (check_jid_syntax(id)) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
574 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", id); |
638
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
575 id = NULL; |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
576 } else { |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
577 mc_strtolower(id); |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
578 } |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
579 } else { |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
580 // Add the current buddy |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
581 if (current_buddy) |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
582 id = (char*)buddy_getjid(BUDDATA(current_buddy)); |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
583 if (!id) |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
584 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); |
638
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
585 } |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
586 |
f6946251acdf
"/add" can be used with no jid (it will use the current buddy's jid)
Mikael Berthe <mikael@lilotux.net>
parents:
636
diff
changeset
|
587 if (id) { |
452 | 588 // 2nd parameter = optional nickname |
589 jb_addbuddy(id, nick, NULL); | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
590 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>.", |
452 | 591 id); |
592 } | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
593 free_arg_lst(paramlst); |
124 | 594 } |
128 | 595 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
596 static void do_del(char *arg) |
206 | 597 { |
598 const char *jid; | |
599 | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
600 if (*arg) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
601 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter; " |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
602 "the currently-selected buddy will be deleted."); |
206 | 603 return; |
604 } | |
605 | |
606 if (!current_buddy) return; | |
607 jid = buddy_getjid(BUDDATA(current_buddy)); | |
608 if (!jid) return; | |
609 | |
540
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
610 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_ROOM) { |
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
611 // This is a chatroom |
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
612 // If there are resources, we haven't left |
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
650
diff
changeset
|
613 if (buddy_getinsideroom(BUDDATA(current_buddy))) { |
540
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
614 scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!"); |
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
615 return; |
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
616 } |
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
617 } |
887c1bd37617
Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents:
539
diff
changeset
|
618 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
619 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", jid); |
206 | 620 jb_delbuddy(jid); |
598 | 621 scr_ShowBuddyWindow(); |
206 | 622 } |
623 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
624 static void do_group(char *arg) |
128 | 625 { |
626 gpointer group; | |
166 | 627 guint leave_windowbuddy; |
128 | 628 |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
629 if (!*arg) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
630 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
128 | 631 return; |
632 } | |
633 | |
166 | 634 if (!current_buddy) return; |
128 | 635 |
166 | 636 group = buddy_getgroup(BUDDATA(current_buddy)); |
212 | 637 // We'll have to redraw the chat window if we're not currently on the group |
638 // entry itself, because it means we'll have to leave the current buddy | |
639 // chat window. | |
166 | 640 leave_windowbuddy = (group != BUDDATA(current_buddy)); |
641 | |
128 | 642 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
643 scr_LogPrint(LPRINT_NORMAL, "You need to select a group."); |
128 | 644 return; |
645 } | |
166 | 646 |
647 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) { | |
128 | 648 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE); |
166 | 649 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) { |
128 | 650 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE); |
130 | 651 } else if (!strcasecmp(arg, "toggle")) { |
652 buddy_setflags(group, ROSTER_FLAG_HIDE, | |
653 !(buddy_getflags(group) & ROSTER_FLAG_HIDE)); | |
128 | 654 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
655 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
128 | 656 return; |
657 } | |
658 | |
659 buddylist_build(); | |
660 update_roster = TRUE; | |
166 | 661 if (leave_windowbuddy) scr_ShowBuddyWindow(); |
128 | 662 } |
663 | |
636 | 664 static int send_message_to(const char *jid, const char *msg) |
665 { | |
666 char *bare_jid, *rp; | |
667 | |
668 if (!jid || !*jid) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
669 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID."); |
636 | 670 return 1; |
671 } | |
672 if (!msg || !*msg) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
673 scr_LogPrint(LPRINT_NORMAL, "You must specify a message."); |
636 | 674 return 1; |
675 } | |
676 if (check_jid_syntax((char*)jid)) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
677 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); |
636 | 678 return 1; |
679 } | |
680 | |
681 // We must use the bare jid in hk_message_out() | |
682 rp = strchr(jid, '/'); | |
683 if (rp) bare_jid = g_strndup(jid, rp - jid); | |
684 else bare_jid = (char*)jid; | |
685 | |
686 // Jump to window, create one if needed | |
687 scr_RosterJumpJid(bare_jid); | |
688 | |
689 // Check if we're sending a message to a conference room | |
690 // If not, we must make sure rp is NULL, for hk_message_out() | |
691 if (rp) { | |
692 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) rp++; | |
693 else rp = NULL; | |
694 } | |
695 | |
696 // local part (UI, logging, etc.) | |
697 hk_message_out(bare_jid, rp, 0, msg); | |
698 | |
699 // Network part | |
700 jb_send_msg(jid, msg, ROSTER_TYPE_USER, NULL); | |
701 | |
702 if (rp) g_free(bare_jid); | |
703 return 0; | |
704 } | |
705 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
706 static void do_say(char *arg) |
132 | 707 { |
164 | 708 gpointer bud; |
132 | 709 |
710 scr_set_chatmode(TRUE); | |
164 | 711 |
712 if (!current_buddy) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
713 scr_LogPrint(LPRINT_NORMAL, |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
714 "Whom are you talking to? Please select a buddy."); |
164 | 715 return; |
132 | 716 } |
164 | 717 |
718 bud = BUDDATA(current_buddy); | |
631
423c24e5875a
Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents:
626
diff
changeset
|
719 if (!(buddy_gettype(bud) & |
423c24e5875a
Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents:
626
diff
changeset
|
720 (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT|ROSTER_TYPE_ROOM))) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
721 scr_LogPrint(LPRINT_NORMAL, "This is not a user."); |
164 | 722 return; |
723 } | |
724 | |
725 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
726 send_message(arg); | |
132 | 727 } |
728 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
729 static void do_msay(char *arg) |
238 | 730 { |
636 | 731 /* Parameters: begin verbatim abort send send_to */ |
732 char **paramlst; | |
733 char *subcmd; | |
734 | |
735 paramlst = split_arg(arg, 2, 1); // subcmd, arg | |
736 subcmd = *paramlst; | |
737 arg = *(paramlst+1); | |
238 | 738 |
636 | 739 if (!subcmd || !*subcmd) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
740 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
636 | 741 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using " |
742 "the /msay command."); | |
743 scr_LogPrint(LPRINT_NORMAL, "(Use \"/msay begin\" to enter " | |
744 "multi-line mode...)"); | |
745 free_arg_lst(paramlst); | |
746 return; | |
747 } | |
748 | |
749 if (!strcasecmp(subcmd, "abort")) { | |
315
65aa05520556
First Ctrl-C now also leaves multi-line message mode
Mikael Berthe <mikael@lilotux.net>
parents:
310
diff
changeset
|
750 if (scr_get_multimode()) |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
751 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode."); |
238 | 752 scr_set_multimode(FALSE); |
753 return; | |
636 | 754 } else if ((!strcasecmp(subcmd, "begin")) || |
755 (!strcasecmp(subcmd, "verbatim"))) { | |
756 if (!strcasecmp(subcmd, "verbatim")) | |
260
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
757 scr_set_multimode(2); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
758 else |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
759 scr_set_multimode(1); |
33e1a05864a6
Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents:
244
diff
changeset
|
760 |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
761 scr_LogPrint(LPRINT_NORMAL, "Entered multi-line message mode."); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
762 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"/msay send\" " |
238 | 763 "when your message is ready."); |
764 return; | |
636 | 765 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
766 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
238 | 767 return; |
768 } | |
769 | |
636 | 770 /* send/send_to command */ |
238 | 771 |
772 if (!scr_get_multimode()) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
773 scr_LogPrint(LPRINT_NORMAL, "No message to send. " |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
774 "Use \"/msay begin\" first."); |
238 | 775 return; |
776 } | |
777 | |
778 scr_set_chatmode(TRUE); | |
779 | |
636 | 780 if (!strcasecmp(subcmd, "send_to")) { |
781 // Let's send to the specified JID. We leave now if there | |
782 // has been an error (so we don't leave multi-line mode). | |
783 if (send_message_to(arg, scr_get_multiline())) | |
784 return; | |
785 } else { // Send to currently selected buddy | |
786 gpointer bud; | |
238 | 787 |
636 | 788 if (!current_buddy) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
789 scr_LogPrint(LPRINT_NORMAL, "Whom are you talking to?"); |
636 | 790 return; |
791 } | |
792 | |
793 bud = BUDDATA(current_buddy); | |
794 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
795 scr_LogPrint(LPRINT_NORMAL, "This is not a user."); |
636 | 796 return; |
797 } | |
798 | |
799 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE); | |
800 send_message(scr_get_multiline()); | |
238 | 801 } |
802 scr_set_multimode(FALSE); | |
803 } | |
804 | |
480 | 805 static void do_say_to(char *arg) |
806 { | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
807 char **paramlst; |
480 | 808 char *jid, *msg; |
809 | |
810 if (!jb_getonline()) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
811 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
480 | 812 return; |
813 } | |
814 | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
815 paramlst = split_arg(arg, 2, 1); // jid, message |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
816 jid = *paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
817 msg = *(paramlst+1); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
818 |
636 | 819 if (!jid) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
820 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
821 free_arg_lst(paramlst); |
480 | 822 return; |
823 } | |
824 | |
636 | 825 send_message_to(jid, msg); |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
826 free_arg_lst(paramlst); |
480 | 827 } |
828 | |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
829 // buffer_updown(updown, nblines) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
830 // updown: -1=up, +1=down |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
831 inline static void buffer_updown(int updown, char *nlines) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
832 { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
833 int nblines; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
834 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
835 if (!nlines || !*nlines) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
836 nblines = 0; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
837 else |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
838 nblines = atoi(nlines); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
839 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
840 if (nblines >= 0) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
841 scr_BufferScrollUpDown(updown, nblines); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
842 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
843 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
844 static void buffer_search(int direction, char *arg) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
845 { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
846 if (!arg || !*arg) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
847 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
848 return; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
849 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
850 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
851 scr_BufferSearch(direction, arg); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
852 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
853 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
854 static void buffer_date(char *date) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
855 { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
856 time_t t; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
857 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
858 if (!date || !*date) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
859 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
860 return; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
861 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
862 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
863 strip_arg_special_chars(date); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
864 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
865 t = from_iso8601(date, 0); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
866 if (t) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
867 scr_BufferDate(t); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
868 else |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
869 scr_LogPrint(LPRINT_NORMAL, "The date you specified is " |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
870 "not correctly formatted or invalid."); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
871 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
872 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
873 static void buffer_percent(char *arg1, char *arg2) |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
874 { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
875 // Basically, user has typed "%arg1 arg2" |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
876 // "%50" -> arg1 = 50, arg2 null pointer |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
877 // "% 50" -> arg1 = \0, arg2 = 50 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
878 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
879 if (!*arg1 && (!arg2 || !*arg2)) { // No value |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
880 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
881 return; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
882 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
883 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
884 if (*arg1 && arg2 && *arg2) { // Two values |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
885 scr_LogPrint(LPRINT_NORMAL, "Wrong parameters."); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
886 return; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
887 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
888 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
889 scr_BufferPercent(atoi((*arg1 ? arg1 : arg2))); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
890 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
891 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
892 static void do_buffer(char *arg) |
187 | 893 { |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
894 char **paramlst; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
895 char *subcmd; |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
896 |
471
82a27508fb85
Fix segfaults when using /buffer and /room while not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
897 if (!current_buddy) return; |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
898 |
446 | 899 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_GROUP) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
900 scr_LogPrint(LPRINT_NORMAL, "Groups have no buffer."); |
446 | 901 return; |
902 } | |
903 | |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
904 paramlst = split_arg(arg, 2, 1); // subcmd, arg |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
905 subcmd = *paramlst; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
906 arg = *(paramlst+1); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
907 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
908 if (!subcmd || !*subcmd) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
909 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
910 free_arg_lst(paramlst); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
911 return; |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
912 } |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
913 |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
914 if (!strcasecmp(subcmd, "top")) { |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
915 scr_BufferTopBottom(-1); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
916 } else if (!strcasecmp(subcmd, "bottom")) { |
361
51ff319947c3
Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents:
336
diff
changeset
|
917 scr_BufferTopBottom(1); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
918 } else if (!strcasecmp(subcmd, "clear")) { |
369
499170ed71c9
Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents:
364
diff
changeset
|
919 scr_BufferClear(); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
920 } else if (!strcasecmp(subcmd, "up")) { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
921 buffer_updown(-1, arg); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
922 } else if (!strcasecmp(subcmd, "down")) { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
923 buffer_updown(1, arg); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
924 } else if (!strcasecmp(subcmd, "search_backward")) { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
925 buffer_search(-1, arg); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
926 } else if (!strcasecmp(subcmd, "search_forward")) { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
927 buffer_search(1, arg); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
928 } else if (!strcasecmp(subcmd, "date")) { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
929 buffer_date(arg); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
930 } else if (*subcmd == '%') { |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
931 buffer_percent(subcmd+1, arg); |
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
932 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
933 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
934 } |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
369
diff
changeset
|
935 |
558
db019a5f874f
Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents:
557
diff
changeset
|
936 free_arg_lst(paramlst); |
187 | 937 } |
938 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
939 static void do_clear(char *arg) // Alias for "/buffer clear" |
187 | 940 { |
941 do_buffer("clear"); | |
942 } | |
943 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
944 static void do_info(char *arg) |
191 | 945 { |
946 gpointer bud; | |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
947 const char *jid, *name; |
191 | 948 guint type; |
949 char *buffer; | |
604
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
950 enum subscr esub; |
191 | 951 |
952 if (!current_buddy) return; | |
953 bud = BUDDATA(current_buddy); | |
954 | |
955 jid = buddy_getjid(bud); | |
956 name = buddy_getname(bud); | |
957 type = buddy_gettype(bud); | |
604
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
958 esub = buddy_getsubscription(bud); |
191 | 959 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
960 buffer = g_new(char, 4096); |
191 | 961 |
962 if (jid) { | |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
963 GSList *resources; |
604
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
964 char *bstr = "unknown"; |
191 | 965 |
647
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
966 // Enter chat mode |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
967 scr_set_chatmode(TRUE); |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
968 scr_ShowBuddyWindow(); |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
969 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
970 snprintf(buffer, 4095, "jid: <%s>", jid); |
191 | 971 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
972 if (name) { | |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
973 snprintf(buffer, 4095, "Name: %s", name); |
191 | 974 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
975 } | |
976 | |
604
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
977 if (type == ROSTER_TYPE_USER) bstr = "user"; |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
978 else if (type == ROSTER_TYPE_ROOM) bstr = "chatroom"; |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
979 else if (type == ROSTER_TYPE_AGENT) bstr = "agent"; |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
980 snprintf(buffer, 127, "Type: %s", bstr); |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
981 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
982 |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
983 if (esub == sub_both) bstr = "both"; |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
984 else if (esub & sub_from) bstr = "from"; |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
985 else if (esub & sub_to) bstr = "to"; |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
986 else bstr = "none"; |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
987 snprintf(buffer, 64, "Subscription: %s", bstr); |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
988 if (esub & sub_pending) |
2e8342168ebc
"/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents:
600
diff
changeset
|
989 strcat(buffer, " (pending)"); |
191 | 990 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
991 |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
992 resources = buddy_getresources(bud); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
993 for ( ; resources ; resources = g_slist_next(resources) ) { |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
994 gchar rprio; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
995 enum imstatus rstatus; |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
996 const char *rst_msg; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
997 time_t rst_time; |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
998 |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
999 rprio = buddy_getresourceprio(bud, resources->data); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1000 rstatus = buddy_getstatus(bud, resources->data); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1001 rst_msg = buddy_getstatusmsg(bud, resources->data); |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1002 rst_time = buddy_getstatustime(bud, resources->data); |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1003 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1004 snprintf(buffer, 4095, "Resource: [%c] (%d) %s", imstatus2char[rstatus], |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1005 rprio, (char*)resources->data); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1006 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1007 if (rst_msg) { |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1008 snprintf(buffer, 4095, "Status message: %s", rst_msg); |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1009 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1010 } |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1011 if (rst_time) { |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1012 char tbuf[128]; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1013 |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1014 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", localtime(&rst_time)); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1015 snprintf(buffer, 127, "Status timestamp: %s", tbuf); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1016 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1017 } |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1018 } |
191 | 1019 } else { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1020 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name); |
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1021 scr_LogPrint(LPRINT_NORMAL, "Type: %s", |
439
63562fd409a1
/info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents:
438
diff
changeset
|
1022 ((type == ROSTER_TYPE_GROUP) ? "group" : "unknown")); |
191 | 1023 } |
1024 | |
1025 g_free(buffer); | |
1026 } | |
1027 | |
504
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1028 // room_names() is a variation of do_info(), for chatrooms only |
552 | 1029 static void room_names(gpointer bud, char *arg) |
504
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1030 { |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1031 const char *jid; |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1032 char *buffer; |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1033 GSList *resources; |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1034 |
552 | 1035 if (*arg) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1036 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter."); |
504
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1037 return; |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1038 } |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1039 |
647
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1040 // Enter chat mode |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1041 scr_set_chatmode(TRUE); |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1042 scr_ShowBuddyWindow(); |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1043 |
504
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1044 jid = buddy_getjid(bud); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1045 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1046 buffer = g_new(char, 4096); |
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1047 strncpy(buffer, "Room members:", 127); |
504
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1048 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1049 |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1050 resources = buddy_getresources(bud); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1051 for ( ; resources ; resources = g_slist_next(resources) ) { |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1052 enum imstatus rstatus; |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1053 const char *rst_msg; |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1054 |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1055 rstatus = buddy_getstatus(bud, resources->data); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1056 rst_msg = buddy_getstatusmsg(bud, resources->data); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1057 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1058 snprintf(buffer, 4095, "[%c] %s", imstatus2char[rstatus], |
504
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1059 (char*)resources->data); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1060 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1061 if (rst_msg) { |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1062 snprintf(buffer, 4095, "Status message: %s", rst_msg); |
504
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1063 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1064 } |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1065 } |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1066 |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1067 g_free(buffer); |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1068 } |
321ae11e7ddb
Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents:
490
diff
changeset
|
1069 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1070 static void do_rename(char *arg) |
208 | 1071 { |
1072 gpointer bud; | |
1073 const char *jid, *group; | |
1074 guint type; | |
1075 char *newname, *p; | |
1076 | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1077 if (!*arg) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1078 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID to rename."); |
208 | 1079 return; |
1080 } | |
1081 | |
1082 if (!current_buddy) return; | |
1083 bud = BUDDATA(current_buddy); | |
1084 | |
1085 jid = buddy_getjid(bud); | |
1086 group = buddy_getgroupname(bud); | |
1087 type = buddy_gettype(bud); | |
1088 | |
1089 if (type & ROSTER_TYPE_GROUP) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1090 scr_LogPrint(LPRINT_NORMAL, "You can't rename groups."); |
208 | 1091 return; |
1092 } | |
1093 | |
1094 newname = g_strdup(arg); | |
1095 // Remove trailing space | |
1096 for (p = newname; *p; p++) ; | |
1097 while (p > newname && *p == ' ') *p = 0; | |
1098 | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1099 strip_arg_special_chars(newname); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1100 |
208 | 1101 buddy_setname(bud, newname); |
1102 jb_updatebuddy(jid, newname, group); | |
1103 | |
1104 g_free(newname); | |
1105 update_roster = TRUE; | |
1106 } | |
1107 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1108 static void do_move(char *arg) |
210 | 1109 { |
1110 gpointer bud; | |
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1111 const char *jid, *name, *oldgroupname; |
210 | 1112 guint type; |
1113 char *newgroupname, *p; | |
1114 | |
1115 if (!current_buddy) return; | |
1116 bud = BUDDATA(current_buddy); | |
1117 | |
1118 jid = buddy_getjid(bud); | |
1119 name = buddy_getname(bud); | |
1120 type = buddy_gettype(bud); | |
1121 | |
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1122 oldgroupname = buddy_getgroupname(bud); |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1123 |
210 | 1124 if (type & ROSTER_TYPE_GROUP) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1125 scr_LogPrint(LPRINT_NORMAL, "You can't move groups!"); |
210 | 1126 return; |
1127 } | |
1128 | |
1129 newgroupname = g_strdup(arg); | |
1130 // Remove trailing space | |
1131 for (p = newgroupname; *p; p++) ; | |
608
89f5672eb523
/move: really strip trailing space, and assign to no group if no group is specified
Mikael Berthe <mikael@lilotux.net>
parents:
604
diff
changeset
|
1132 while (p > newgroupname && *p == ' ') *p-- = 0; |
210 | 1133 |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1134 strip_arg_special_chars(newgroupname); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1135 |
620
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1136 if (strcmp(oldgroupname, newgroupname)) { |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1137 jb_updatebuddy(jid, name, *newgroupname ? newgroupname : NULL); |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1138 scr_RosterUp(); |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1139 buddy_setgroup(bud, newgroupname); |
97dd14e22b2a
Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents:
617
diff
changeset
|
1140 } |
210 | 1141 |
1142 g_free(newgroupname); | |
1143 update_roster = TRUE; | |
1144 } | |
1145 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1146 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
|
1147 { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1148 guint assign; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1149 const gchar *option, *value; |
393 | 1150 |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1151 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
|
1152 if (!option) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1153 scr_LogPrint(LPRINT_NORMAL, "Set what option?"); |
283
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1154 return; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1155 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1156 if (!assign) { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1157 // This is a query |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1158 value = settings_opt_get(option); |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1159 if (value) { |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1160 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
|
1161 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1162 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
|
1163 return; |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1164 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1165 // Update the option |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1166 // 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
|
1167 // (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
|
1168 // (hide_offline_buddies for ex.) |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1169 if (!value) { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1170 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
|
1171 } else { |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1172 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
|
1173 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1174 } |
00b2377539ac
Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents:
277
diff
changeset
|
1175 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1176 static void do_alias(char *arg) |
285 | 1177 { |
1178 guint assign; | |
1179 const gchar *alias, *value; | |
393 | 1180 |
285 | 1181 assign = parse_assigment(arg, &alias, &value); |
1182 if (!alias) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1183 scr_LogPrint(LPRINT_NORMAL, "Alias what?"); |
285 | 1184 return; |
1185 } | |
1186 if (!assign) { | |
1187 // This is a query | |
1188 value = settings_get(SETTINGS_TYPE_ALIAS, alias); | |
1189 if (value) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1190 scr_LogPrint(LPRINT_NORMAL, "%s = %s", alias, value); |
285 | 1191 } else |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1192 scr_LogPrint(LPRINT_NORMAL, "Alias '%s' does not exist", alias); |
285 | 1193 return; |
1194 } | |
1195 // Check the alias does not conflict with a registered command | |
1196 if (cmd_get(alias)) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1197 scr_LogPrint(LPRINT_NORMAL, "'%s' is a reserved word!", alias); |
285 | 1198 return; |
1199 } | |
1200 // Update the alias | |
1201 if (!value) { | |
1202 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) { | |
1203 settings_del(SETTINGS_TYPE_ALIAS, alias); | |
1204 // Remove alias from the completion list | |
1205 compl_del_category_word(COMPL_CMD, alias); | |
1206 } | |
1207 } else { | |
1208 // Add alias to the completion list, if not already in | |
1209 if (!settings_get(SETTINGS_TYPE_ALIAS, alias)) | |
1210 compl_add_category_word(COMPL_CMD, alias); | |
1211 settings_set(SETTINGS_TYPE_ALIAS, alias, value); | |
1212 } | |
1213 } | |
1214 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1215 static void do_bind(char *arg) |
288 | 1216 { |
1217 guint assign; | |
1218 const gchar *keycode, *value; | |
393 | 1219 |
288 | 1220 assign = parse_assigment(arg, &keycode, &value); |
1221 if (!keycode) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1222 scr_LogPrint(LPRINT_NORMAL, "Bind what keycode?"); |
288 | 1223 return; |
1224 } | |
1225 if (!assign) { | |
1226 // This is a query | |
1227 value = settings_get(SETTINGS_TYPE_BINDING, keycode); | |
1228 if (value) { | |
374
bd5638c21834
Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents:
371
diff
changeset
|
1229 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", keycode, value); |
288 | 1230 } else |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1231 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", keycode); |
288 | 1232 return; |
1233 } | |
1234 // Update the key binding | |
1235 if (!value) | |
1236 settings_del(SETTINGS_TYPE_BINDING, keycode); | |
1237 else | |
1238 settings_set(SETTINGS_TYPE_BINDING, keycode, value); | |
1239 } | |
1240 | |
436 | 1241 static void do_rawxml(char *arg) |
1242 { | |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1243 char **paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1244 char *subcmd; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1245 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1246 if (!jb_getonline()) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1247 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1248 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1249 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1250 |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1251 paramlst = split_arg(arg, 2, 1); // subcmd, arg |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1252 subcmd = *paramlst; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1253 arg = *(paramlst+1); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1254 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1255 if (!subcmd || !*subcmd) { |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1256 scr_LogPrint(LPRINT_NORMAL, "Please read the manual page" |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1257 " before using /rawxml :-)"); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1258 free_arg_lst(paramlst); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1259 return; |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1260 } |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1261 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1262 if (!strcasecmp(subcmd, "send")) { |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
1263 gchar *buffer; |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1264 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1265 if (!subcmd || !*subcmd) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1266 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1267 free_arg_lst(paramlst); |
461
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
1268 return; |
1d8f5b3a5f2b
Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents:
454
diff
changeset
|
1269 } |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1270 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1271 // We don't strip_arg_special_chars() here, because it would be a pain for |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1272 // the user to escape quotes in a XML stream... |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1273 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1274 buffer = to_utf8(arg); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1275 if (buffer) { |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1276 scr_LogPrint(LPRINT_NORMAL, "Sending XML string"); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1277 jb_send_raw(buffer); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1278 g_free(buffer); |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1279 } else { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1280 scr_LogPrint(LPRINT_NORMAL, "Conversion error in XML string."); |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1281 } |
436 | 1282 } else { |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1283 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
436 | 1284 } |
557
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1285 |
c72a66dfd2d4
Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents:
555
diff
changeset
|
1286 free_arg_lst(paramlst); |
436 | 1287 } |
1288 | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1289 // check_room_subcommand(arg, param_needed, buddy_must_be_a_room) |
552 | 1290 // - Check if this is a room, if buddy_must_be_a_room is not null |
1291 // - Check there is at least 1 parameter, if param_needed is true | |
1292 // - Return null if one of the checks fails, or a pointer to the first | |
1293 // non-space character. | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1294 static char *check_room_subcommand(char *arg, bool param_needed, |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1295 gpointer buddy_must_be_a_room) |
552 | 1296 { |
1297 if (buddy_must_be_a_room && | |
1298 !(buddy_gettype(buddy_must_be_a_room) & ROSTER_TYPE_ROOM)) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1299 scr_LogPrint(LPRINT_NORMAL, "This isn't a conference room."); |
552 | 1300 return NULL; |
1301 } | |
1302 | |
1303 if (param_needed) { | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1304 if (!arg) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1305 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
552 | 1306 return NULL; |
1307 } | |
1308 } | |
1309 | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1310 if (arg) |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1311 return arg; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1312 else |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1313 return ""; |
552 | 1314 } |
1315 | |
1316 static void room_join(gpointer bud, char *arg) | |
1317 { | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1318 char **paramlst; |
552 | 1319 char *roomname, *nick; |
659
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1320 char *tmpnick = NULL; |
552 | 1321 |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1322 paramlst = split_arg(arg, 2, 0); // roomid, nickname |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1323 roomname = *paramlst; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1324 nick = *(paramlst+1); |
552 | 1325 |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1326 |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1327 if (!roomname || strchr(roomname, '/')) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1328 scr_LogPrint(LPRINT_NORMAL, "Invalid room name."); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1329 free_arg_lst(paramlst); |
552 | 1330 return; |
1331 } | |
1332 | |
659
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1333 // If no nickname is provided with the /join command, |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1334 // we try the "nickname" option, then the username part of the jid. |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1335 if (!nick || !*nick) { |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1336 nick = (char*)settings_opt_get("nickname"); |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1337 if (!nick) { |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1338 nick = (char*)settings_opt_get("username"); |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1339 if (nick && (strchr(nick, '@') > nick)) { |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1340 char *p; |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1341 nick = tmpnick = g_strdup(nick); |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1342 p = strchr(nick, '@'); |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1343 *p = 0; |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1344 } |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1345 } |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1346 } |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1347 // If we still have no nickname, give up |
565
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1348 if (!nick || !*nick) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1349 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname."); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1350 free_arg_lst(paramlst); |
552 | 1351 return; |
1352 } | |
1353 | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1354 // Note that roomname is part of the array allocated by split_arg(), |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1355 // so we can modify it. |
552 | 1356 mc_strtolower(roomname); |
1357 jb_room_join(roomname, nick); | |
1358 | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1359 scr_LogPrint(LPRINT_LOGNORM, "Sent a join request to <%s>...", roomname); |
653
d5db5be78eb0
MUC: Be more verbose when joining a room
Mikael Berthe <mikael@lilotux.net>
parents:
652
diff
changeset
|
1360 |
552 | 1361 buddylist_build(); |
1362 update_roster = TRUE; | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1363 free_arg_lst(paramlst); |
659
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1364 if (tmpnick) |
e61aa455c61b
MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents:
653
diff
changeset
|
1365 g_free(tmpnick); |
552 | 1366 } |
1367 | |
1368 static void room_invite(gpointer bud, char *arg) | |
1369 { | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1370 char **paramlst; |
552 | 1371 const gchar *roomname; |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1372 char* jid; |
552 | 1373 |
570
29806b0fe830
Some parsing improvements
Mikael Berthe <mikael@lilotux.net>
parents:
568
diff
changeset
|
1374 paramlst = split_arg(arg, 2, 1); // jid, [reason] |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1375 jid = *paramlst; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1376 arg = *(paramlst+1); |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1377 // An empty reason is no reason... |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1378 if (arg && !*arg) |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1379 arg = NULL; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1380 |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1381 if (!jid || !*jid) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1382 scr_LogPrint(LPRINT_NORMAL, "Missing or incorrect Jabber ID."); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1383 free_arg_lst(paramlst); |
552 | 1384 return; |
1385 } | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1386 |
552 | 1387 roomname = buddy_getjid(bud); |
1388 jb_room_invite(roomname, jid, arg); | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1389 scr_LogPrint(LPRINT_LOGNORM, "Invitation sent to <%s>...", jid); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1390 free_arg_lst(paramlst); |
552 | 1391 } |
1392 | |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1393 static void room_affil(gpointer bud, char *arg) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1394 { |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1395 char **paramlst; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1396 gchar *jid, *rolename; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1397 struct role_affil ra; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1398 const char *roomid = buddy_getjid(bud); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1399 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1400 paramlst = split_arg(arg, 3, 1); // jid, new_affil, [reason] |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1401 jid = *paramlst; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1402 rolename = *(paramlst+1); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1403 arg = *(paramlst+2); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1404 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1405 if (!jid || !*jid || !rolename || !*rolename) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1406 scr_LogPrint(LPRINT_NORMAL, "Please specify both a Jabber ID and a role."); |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1407 free_arg_lst(paramlst); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1408 return; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1409 } |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1410 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1411 ra.type = type_affil; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1412 ra.val.affil = affil_none; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1413 for (; ra.val.affil < imaffiliation_size; ra.val.affil++) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1414 if (!strcasecmp(rolename, straffil[ra.val.affil])) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1415 break; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1416 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1417 if (ra.val.affil < imaffiliation_size) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1418 jb_room_setattrib(roomid, jid, NULL, ra, arg); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1419 else |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1420 scr_LogPrint(LPRINT_NORMAL, "Wrong affiliation parameter."); |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1421 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1422 free_arg_lst(paramlst); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1423 } |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1424 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1425 static void room_role(gpointer bud, char *arg) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1426 { |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1427 char **paramlst; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1428 gchar *jid, *rolename; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1429 struct role_affil ra; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1430 const char *roomid = buddy_getjid(bud); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1431 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1432 paramlst = split_arg(arg, 3, 1); // jid, new_role, [reason] |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1433 jid = *paramlst; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1434 rolename = *(paramlst+1); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1435 arg = *(paramlst+2); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1436 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1437 if (!jid || !*jid || !rolename || !*rolename) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1438 scr_LogPrint(LPRINT_NORMAL, "Please specify both a Jabber ID and a role."); |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1439 free_arg_lst(paramlst); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1440 return; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1441 } |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1442 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1443 ra.type = type_role; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1444 ra.val.role = role_none; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1445 for (; ra.val.role < imrole_size; ra.val.role++) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1446 if (!strcasecmp(rolename, strrole[ra.val.role])) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1447 break; |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1448 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1449 if (ra.val.role < imrole_size) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1450 jb_room_setattrib(roomid, jid, NULL, ra, arg); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1451 else |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1452 scr_LogPrint(LPRINT_NORMAL, "Wrong role parameter."); |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1453 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1454 free_arg_lst(paramlst); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1455 } |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1456 |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1457 |
571 | 1458 // The expected argument is a Jabber id |
1459 static void room_ban(gpointer bud, char *arg) | |
1460 { | |
1461 char **paramlst; | |
1462 gchar *jid; | |
584 | 1463 struct role_affil ra; |
571 | 1464 const char *roomid = buddy_getjid(bud); |
1465 | |
1466 paramlst = split_arg(arg, 2, 1); // jid, [reason] | |
1467 jid = *paramlst; | |
1468 arg = *(paramlst+1); | |
1469 | |
1470 if (!jid || !*jid) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1471 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); |
571 | 1472 free_arg_lst(paramlst); |
1473 return; | |
1474 } | |
1475 | |
584 | 1476 ra.type = type_affil; |
1477 ra.val.affil = affil_outcast; | |
1478 | |
1479 jb_room_setattrib(roomid, jid, NULL, ra, arg); | |
571 | 1480 |
1481 free_arg_lst(paramlst); | |
1482 } | |
1483 | |
1484 // The expected argument is a nickname | |
568 | 1485 static void room_kick(gpointer bud, char *arg) |
1486 { | |
1487 char **paramlst; | |
1488 gchar *nick; | |
584 | 1489 struct role_affil ra; |
568 | 1490 const char *roomid = buddy_getjid(bud); |
1491 | |
571 | 1492 paramlst = split_arg(arg, 2, 1); // nickname, [reason] |
568 | 1493 nick = *paramlst; |
1494 arg = *(paramlst+1); | |
1495 | |
1496 if (!nick || !*nick) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1497 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname."); |
568 | 1498 free_arg_lst(paramlst); |
1499 return; | |
1500 } | |
1501 | |
584 | 1502 ra.type = type_role; |
1503 ra.val.affil = role_none; | |
1504 | |
1505 jb_room_setattrib(roomid, NULL, nick, ra, arg); | |
568 | 1506 |
1507 free_arg_lst(paramlst); | |
1508 } | |
1509 | |
552 | 1510 static void room_leave(gpointer bud, char *arg) |
1511 { | |
1512 gchar *roomid, *utf8_nickname; | |
650
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1513 const char *nickname; |
552 | 1514 |
650
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1515 nickname = buddy_getnickname(bud); |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1516 if (!nickname) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1517 scr_LogPrint(LPRINT_NORMAL, "You are not in this room."); |
650
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1518 return; |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1519 } |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1520 |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1521 utf8_nickname = to_utf8(nickname); |
552 | 1522 roomid = g_strdup_printf("%s/%s", buddy_getjid(bud), utf8_nickname); |
1523 jb_setstatus(offline, roomid, arg); | |
1524 g_free(utf8_nickname); | |
1525 g_free(roomid); | |
1526 } | |
1527 | |
1528 static void room_nick(gpointer bud, char *arg) | |
1529 { | |
650
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1530 if (!buddy_getinsideroom(bud)) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1531 scr_LogPrint(LPRINT_NORMAL, "You are not in this room."); |
650
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1532 return; |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1533 } |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1534 |
565
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1535 if (!arg || !*arg) { |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1536 const char *nick = buddy_getnickname(bud); |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1537 if (nick) |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1538 scr_LogPrint(LPRINT_NORMAL, "Your nickname is: %s", nick); |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1539 else |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1540 scr_LogPrint(LPRINT_NORMAL, "You have no nickname in this room."); |
565
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1541 } else { |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1542 gchar *cmd; |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1543 cmd = g_strdup_printf("%s %s", buddy_getjid(bud), arg); |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1544 room_join(bud, cmd); |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1545 g_free(cmd); |
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1546 } |
552 | 1547 } |
1548 | |
1549 static void room_privmsg(gpointer bud, char *arg) | |
1550 { | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1551 char **paramlst; |
552 | 1552 gchar *nick, *cmd; |
1553 | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1554 paramlst = split_arg(arg, 2, 0); // nickname, message |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1555 nick = *paramlst; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1556 arg = *(paramlst+1); |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1557 |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1558 if (!nick || !*nick || !arg || !*arg) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1559 scr_LogPrint(LPRINT_NORMAL, |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1560 "Please specify both a Jabber ID and a message."); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1561 free_arg_lst(paramlst); |
552 | 1562 return; |
1563 } | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1564 |
552 | 1565 cmd = g_strdup_printf("%s/%s %s", buddy_getjid(bud), nick, arg); |
1566 do_say_to(cmd); | |
1567 g_free(cmd); | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1568 free_arg_lst(paramlst); |
552 | 1569 } |
1570 | |
1571 static void room_remove(gpointer bud, char *arg) | |
1572 { | |
1573 if (*arg) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1574 scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter; " |
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1575 "the currently-selected room will be removed."); |
552 | 1576 return; |
1577 } | |
1578 | |
1579 // Quick check: if there are resources, we haven't left | |
652
b243d3b3ff1b
We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents:
650
diff
changeset
|
1580 if (buddy_getinsideroom(bud)) { |
552 | 1581 scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!"); |
1582 return; | |
1583 } | |
1584 // Delete the room | |
1585 roster_del_user(buddy_getjid(bud)); | |
598 | 1586 scr_ShowBuddyWindow(); |
552 | 1587 buddylist_build(); |
1588 update_roster = TRUE; | |
1589 } | |
1590 | |
1591 static void room_topic(gpointer bud, char *arg) | |
1592 { | |
1593 gchar *msg; | |
1594 | |
650
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1595 if (!buddy_getinsideroom(bud)) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1596 scr_LogPrint(LPRINT_NORMAL, "You are not in this room."); |
650
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1597 return; |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1598 } |
c2d50b97ced4
MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents:
647
diff
changeset
|
1599 |
552 | 1600 // If no parameter is given, display the current topic |
1601 if (!*arg) { | |
1602 const char *topic = buddy_gettopic(bud); | |
1603 if (topic) | |
1604 scr_LogPrint(LPRINT_NORMAL, "Topic: %s", topic); | |
1605 else | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1606 scr_LogPrint(LPRINT_NORMAL, "No topic has been set."); |
552 | 1607 return; |
1608 } | |
1609 | |
1610 // Set the topic | |
1611 msg = g_strdup_printf("/me has set the topic to: %s", arg); | |
1612 jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg); | |
1613 g_free(msg); | |
1614 } | |
1615 | |
599 | 1616 static void room_destroy(gpointer bud, char *arg) |
1617 { | |
1618 gchar *msg; | |
1619 | |
1620 if (arg && *arg) | |
1621 msg = arg; | |
1622 else | |
1623 msg = NULL; | |
1624 | |
1625 jb_room_destroy(buddy_getjid(bud), NULL, msg); | |
1626 } | |
1627 | |
552 | 1628 static void room_unlock(gpointer bud, char *arg) |
1629 { | |
1630 if (*arg) { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1631 scr_LogPrint(LPRINT_NORMAL, "Unknown parameter."); |
552 | 1632 return; |
1633 } | |
1634 | |
1635 jb_room_unlock(buddy_getjid(bud)); | |
1636 } | |
1637 | |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1638 static void room_whois(gpointer bud, char *arg) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1639 { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1640 char **paramlst; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1641 gchar *nick, *buffer; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1642 const char *jid, *realjid; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1643 const char *rst_msg; |
575 | 1644 gchar rprio; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1645 enum imstatus rstatus; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1646 enum imrole role; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1647 enum imaffiliation affil; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1648 time_t rst_time; |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1649 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1650 char *strroles[] = { "none", "moderator", "participant", "visitor" }; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1651 char *straffil[] = { "none", "owner", "admin", "member", "outcast" }; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1652 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1653 paramlst = split_arg(arg, 1, 0); // nickname |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1654 nick = *paramlst; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1655 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1656 if (!nick || !*nick) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1657 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname."); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1658 free_arg_lst(paramlst); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1659 return; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1660 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1661 |
647
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1662 // Enter chat mode |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1663 scr_set_chatmode(TRUE); |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1664 scr_ShowBuddyWindow(); |
c6c41dd2464a
Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents:
644
diff
changeset
|
1665 |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1666 jid = buddy_getjid(bud); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1667 rstatus = buddy_getstatus(bud, nick); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1668 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1669 if (rstatus == offline) { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1670 scr_LogPrint(LPRINT_NORMAL, "No such member: %s", nick); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1671 free_arg_lst(paramlst); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1672 return; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1673 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1674 |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1675 rst_time = buddy_getstatustime(bud, nick); |
575 | 1676 rprio = buddy_getresourceprio(bud, nick); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1677 rst_msg = buddy_getstatusmsg(bud, nick); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1678 if (!rst_msg) rst_msg = ""; |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1679 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1680 role = buddy_getrole(bud, nick); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1681 affil = buddy_getaffil(bud, nick); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1682 realjid = buddy_getrjid(bud, nick); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1683 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1684 buffer = g_new(char, 4096); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1685 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1686 snprintf(buffer, 4095, "Whois [%s]", nick); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1687 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1688 snprintf(buffer, 4095, "Status : [%c] %s", imstatus2char[rstatus], |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1689 rst_msg); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1690 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1691 |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1692 if (rst_time) { |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1693 char tbuf[128]; |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1694 |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1695 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S", localtime(&rst_time)); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1696 snprintf(buffer, 127, "Timestamp: %s", tbuf); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1697 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1698 } |
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1699 |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1700 if (realjid) { |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1701 snprintf(buffer, 4095, "JID : <%s>", realjid); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1702 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1703 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1704 |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1705 snprintf(buffer, 4095, "Role : %s", strroles[role]); |
575 | 1706 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1707 snprintf(buffer, 4095, "Affiliat.: %s", straffil[affil]); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1708 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
626
b75f4105ce32
Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents:
625
diff
changeset
|
1709 snprintf(buffer, 4095, "Priority : %d", rprio); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1710 scr_WriteIncomingMessage(jid, buffer, 0, HBB_PREFIX_INFO); |
625
028c01940490
Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
622
diff
changeset
|
1711 |
575 | 1712 scr_WriteIncomingMessage(jid, "End of WHOIS", 0, HBB_PREFIX_INFO); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1713 |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1714 g_free(buffer); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1715 free_arg_lst(paramlst); |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1716 } |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1717 |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1718 static void do_room(char *arg) |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1719 { |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1720 char **paramlst; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1721 char *subcmd; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1722 gpointer bud; |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1723 |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1724 if (!jb_getonline()) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1725 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
472
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1726 return; |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1727 } |
75442262c082
Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents:
471
diff
changeset
|
1728 |
471
82a27508fb85
Fix segfaults when using /buffer and /room while not connected
Mikael Berthe <mikael@lilotux.net>
parents:
470
diff
changeset
|
1729 if (!current_buddy) return; |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1730 bud = BUDDATA(current_buddy); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1731 |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1732 paramlst = split_arg(arg, 2, 1); // subcmd, arg |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1733 subcmd = *paramlst; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1734 arg = *(paramlst+1); |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1735 |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1736 if (!subcmd || !*subcmd) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1737 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1738 free_arg_lst(paramlst); |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1739 return; |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1740 } |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1741 |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1742 if (!strcasecmp(subcmd, "join")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1743 if ((arg = check_room_subcommand(arg, TRUE, NULL)) != NULL) |
552 | 1744 room_join(bud, arg); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1745 } else if (!strcasecmp(subcmd, "invite")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1746 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) |
552 | 1747 room_invite(bud, arg); |
585
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1748 } else if (!strcasecmp(subcmd, "affil")) { |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1749 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1750 room_affil(bud, arg); |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1751 } else if (!strcasecmp(subcmd, "role")) { |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1752 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) |
7eff2c1481fa
Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents:
584
diff
changeset
|
1753 room_role(bud, arg); |
571 | 1754 } else if (!strcasecmp(subcmd, "ban")) { |
1755 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) | |
1756 room_ban(bud, arg); | |
568 | 1757 } else if (!strcasecmp(subcmd, "kick")) { |
1758 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) | |
1759 room_kick(bud, arg); | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1760 } else if (!strcasecmp(subcmd, "leave")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1761 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) |
552 | 1762 room_leave(bud, arg); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1763 } else if (!strcasecmp(subcmd, "names")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1764 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) |
552 | 1765 room_names(bud, arg); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1766 } else if (!strcasecmp(subcmd, "nick")) { |
565
89c347b3e4c1
MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents:
558
diff
changeset
|
1767 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) |
552 | 1768 room_nick(bud, arg); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1769 } else if (!strcasecmp(subcmd, "privmsg")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1770 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) |
552 | 1771 room_privmsg(bud, arg); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1772 } else if (!strcasecmp(subcmd, "remove")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1773 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) |
552 | 1774 room_remove(bud, arg); |
599 | 1775 } else if (!strcasecmp(subcmd, "destroy")) { |
1776 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) | |
1777 room_destroy(bud, arg); | |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1778 } else if (!strcasecmp(subcmd, "unlock")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1779 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) |
552 | 1780 room_unlock(bud, arg); |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1781 } else if (!strcasecmp(subcmd, "topic")) { |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1782 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL) |
552 | 1783 room_topic(bud, arg); |
572
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1784 } else if (!strcasecmp(subcmd, "whois")) { |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1785 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL) |
afc2bd38b15c
Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents:
571
diff
changeset
|
1786 room_whois(bud, arg); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1787 } else { |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1788 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1789 } |
554
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1790 |
2424bbf0a6db
Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents:
552
diff
changeset
|
1791 free_arg_lst(paramlst); |
447
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1792 } |
03bb57383cea
Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents:
446
diff
changeset
|
1793 |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1794 static void do_authorization(char *arg) |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1795 { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1796 char **paramlst; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1797 char *subcmd; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1798 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1799 if (!jb_getonline()) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1800 scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1801 return; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1802 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1803 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1804 paramlst = split_arg(arg, 2, 0); // subcmd, [jid] |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1805 subcmd = *paramlst; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1806 arg = *(paramlst+1); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1807 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1808 if (!subcmd || !*subcmd) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1809 scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1810 free_arg_lst(paramlst); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1811 return; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1812 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1813 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1814 // Use the provided jid, if it looks valid |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1815 if (arg) { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1816 if (!*arg) { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1817 // If no jid is provided, we use the current selected buddy |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1818 arg = NULL; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1819 } else { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1820 if (check_jid_syntax(arg)) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1821 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", arg); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1822 free_arg_lst(paramlst); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1823 return; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1824 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1825 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1826 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1827 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1828 if (!arg) { // Use the current selected buddy's jid |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1829 gpointer bud; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1830 guint type; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1831 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1832 if (!current_buddy) return; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1833 bud = BUDDATA(current_buddy); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1834 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1835 arg = (char*)buddy_getjid(bud); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1836 type = buddy_gettype(bud); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1837 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1838 if (!(type & (ROSTER_TYPE_USER|ROSTER_TYPE_AGENT))) { |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1839 scr_LogPrint(LPRINT_NORMAL, "Invalid buddy."); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1840 return; |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1841 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1842 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1843 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1844 if (!strcasecmp(subcmd, "allow")) { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1845 jb_subscr_send_auth(arg); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1846 scr_LogPrint(LPRINT_LOGNORM, |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1847 "<%s> is now allowed to receive your presence updates.", arg); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1848 } else if (!strcasecmp(subcmd, "cancel")) { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1849 jb_subscr_cancel_auth(arg); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1850 scr_LogPrint(LPRINT_LOGNORM, |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1851 "<%s> will no longer receive your presence updates.", |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1852 arg); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1853 } else if (!strcasecmp(subcmd, "request")) { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1854 jb_subscr_request_auth(arg); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1855 scr_LogPrint(LPRINT_LOGNORM, |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1856 "Sent presence notification request to <%s>...", arg); |
617
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1857 } else { |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1858 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1859 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1860 |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1861 free_arg_lst(paramlst); |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1862 } |
d3a8b43bf9e7
Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents:
608
diff
changeset
|
1863 |
622 | 1864 static void do_version(char *arg) |
1865 { | |
681
8dc602a246a4
Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents:
677
diff
changeset
|
1866 scr_LogPrint(LPRINT_NORMAL, "This is mcabber version %s.", PACKAGE_VERSION); |
622 | 1867 } |
1868 | |
693 | 1869 static void do_request(char *arg) |
1870 { | |
1871 char **paramlst; | |
1872 char *jid, *type; | |
1873 enum iqreq_type numtype; | |
1874 | |
1875 paramlst = split_arg(arg, 2, 0); // type, jid | |
1876 type = *paramlst; | |
1877 jid = *(paramlst+1); | |
1878 | |
1879 if (type) { | |
1880 // Quick check... | |
1881 if (!strcasecmp(type, "version")) | |
1882 numtype = iqreq_version; | |
1883 else if (!strcasecmp(type, "time")) | |
1884 numtype = iqreq_time; | |
694
6d6fdaf846ed
Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents:
693
diff
changeset
|
1885 else if (!strcasecmp(type, "show_list")) { |
6d6fdaf846ed
Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents:
693
diff
changeset
|
1886 // Undocumented command, for debugging purposes only |
6d6fdaf846ed
Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents:
693
diff
changeset
|
1887 jb_iqs_display_list(); |
6d6fdaf846ed
Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents:
693
diff
changeset
|
1888 free_arg_lst(paramlst); |
6d6fdaf846ed
Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents:
693
diff
changeset
|
1889 return; |
6d6fdaf846ed
Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents:
693
diff
changeset
|
1890 } |
693 | 1891 } |
1892 | |
1893 if (!type || !numtype) { | |
1894 scr_LogPrint(LPRINT_NORMAL, | |
1895 "Please specify a query type (version, time)."); | |
1896 free_arg_lst(paramlst); | |
1897 return; | |
1898 } | |
1899 | |
1900 // Allow special jid "" or "." (current buddy) | |
1901 if (jid && (!*jid || !strcmp(jid, "."))) | |
1902 jid = NULL; | |
1903 | |
1904 if (jid) { | |
1905 // The JID has been specified. Quick check... | |
1906 if (check_jid_syntax(jid)) { | |
1907 scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); | |
1908 jid = NULL; | |
1909 } else { | |
1910 // Convert jid to lowercase | |
1911 char *p = jid; | |
1912 for ( ; *p && *p != '/'; p++) | |
1913 *p = tolower(*p); | |
1914 } | |
1915 } else { | |
1916 // Add the current buddy | |
1917 if (current_buddy) | |
1918 jid = (char*)buddy_getjid(BUDDATA(current_buddy)); | |
1919 if (!jid) | |
1920 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); | |
1921 } | |
1922 | |
1923 if (jid) { | |
1924 switch (numtype) { | |
1925 case iqreq_version: | |
1926 case iqreq_time: | |
1927 jb_request(jid, numtype); | |
1928 break; | |
1929 default: | |
1930 break; | |
1931 } | |
1932 } | |
1933 free_arg_lst(paramlst); | |
1934 } | |
1935 | |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1936 static void do_connect(char *arg) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1937 { |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1938 mcabber_connect(); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1939 } |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1940 |
336
eb994ee40029
Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents:
330
diff
changeset
|
1941 static void do_disconnect(char *arg) |
298
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1942 { |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1943 jb_disconnect(); |
35cda94e570d
Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents:
290
diff
changeset
|
1944 } |
576 | 1945 |
580 | 1946 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |