annotate mcabber/src/commands.c @ 1226:2521efbf3b72

New (debug) subcommand, buffer list
author Mikael Berthe <mikael@lilotux.net>
date Sat, 19 May 2007 11:56:32 +0200
parents 0dd5df7eb007
children 58d6e7713164
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
1 /*
699
ee03b56b93ee Update Copyright (2006)
Mikael Berthe <mikael@lilotux.net>
parents: 696
diff changeset
2 * commands.c -- user commands handling
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
3 *
1205
2de8f8ba1f34 Update copyrights
Mikael Berthe <mikael@lilotux.net>
parents: 1202
diff changeset
4 * Copyright (C) 2005-2007 Mikael Berthe <mikael@lilotux.net>
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
5 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or (at
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
9 * your option) any later version.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
10 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful, but
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
14 * General Public License for more details.
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
15 *
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
19 * USA
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
20 */
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
21
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
22 #include <string.h>
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
23
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
24 #include "commands.h"
868
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
25 #include "help.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
26 #include "jabglue.h"
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
27 #include "roster.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
28 #include "screen.h"
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
29 #include "compl.h"
113
8ac67e951eab [/trunk] Changeset 127 by mikael
mikael
parents: 108
diff changeset
30 #include "hooks.h"
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
31 #include "hbuf.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
32 #include "utils.h"
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
33 #include "settings.h"
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
34 #include "events.h"
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
35
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
36 #define IMSTATUS_AWAY "away"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
37 #define IMSTATUS_ONLINE "online"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
38 #define IMSTATUS_OFFLINE "offline"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
39 #define IMSTATUS_FREE4CHAT "free"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
40 #define IMSTATUS_INVISIBLE "invisible"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
41 #define IMSTATUS_AVAILABLE "avail"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
42 #define IMSTATUS_NOTAVAILABLE "notavail"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
43 #define IMSTATUS_DONOTDISTURB "dnd"
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
44
1173
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
45 // Return value container for the following functions
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
46 static int retval_for_cmds;
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
47
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
48 // Commands callbacks
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
49 static void do_roster(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
50 static void do_status(char *arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
51 static void do_status_to(char *arg);
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
52 static void do_add(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
53 static void do_del(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
54 static void do_group(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
55 static void do_say(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
56 static void do_msay(char *arg);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
57 static void do_say_to(char *arg);
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
58 static void do_buffer(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
59 static void do_clear(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
60 static void do_info(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
61 static void do_rename(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
62 static void do_move(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
63 static void do_set(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
64 static void do_alias(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
65 static void do_bind(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
66 static void do_connect(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
67 static void do_disconnect(char *arg);
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
68 static void do_rawxml(char *arg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
69 static void do_room(char *arg);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
70 static void do_authorization(char *arg);
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
71 static void do_version(char *arg);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
72 static void do_request(char *arg);
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
73 static void do_event(char *arg);
868
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
74 static void do_help(char *arg);
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
75 static void do_pgp(char *arg);
1171
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
76 static void do_iline(char *arg);
1172
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
77 static void do_screen_refresh(char *arg);
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
78 static void do_chat_disable(char *arg);
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
79 static void do_source(char *arg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
80
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
81 // Global variable for the commands list
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
82 static GSList *Commands;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
83
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
84
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
85 // cmd_add()
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
86 // Adds a command to the commands list and to the CMD completion list
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
87 static void cmd_add(const char *name, const char *help,
1059
875d2c9d399c Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
88 guint flags_row1, guint flags_row2, void (*f)(char*))
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
89 {
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
90 cmd *n_cmd = g_new0(cmd, 1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
91 strncpy(n_cmd->name, name, 32-1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
92 n_cmd->help = help;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
93 n_cmd->completion_flags[0] = flags_row1;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
94 n_cmd->completion_flags[1] = flags_row2;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
95 n_cmd->func = f;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
96 Commands = g_slist_append(Commands, n_cmd);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
97 // Add to completion CMD category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
98 compl_add_category_word(COMPL_CMD, name);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
99 }
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
100
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
101 // cmd_init()
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
102 // Commands table initialization
1173
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
103 // !!!
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
104 // After changing commands names and it arguments names here, you must change
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
105 // ones in init_bindings()!
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
106 //
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
107 void cmd_init(void)
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
108 {
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
109 cmd_add("add", "Add a jabber user", COMPL_JID, 0, &do_add);
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
110 cmd_add("alias", "Add an alias", 0, 0, &do_alias);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
111 cmd_add("authorization", "Manage subscription authorizations",
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
112 COMPL_AUTH, COMPL_JID, &do_authorization);
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
113 cmd_add("bind", "Add an key binding", 0, 0, &do_bind);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
114 cmd_add("buffer", "Manipulate current buddy's buffer (chat window)",
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
115 COMPL_BUFFER, 0, &do_buffer);
1221
0dd5df7eb007 Fix wrong command completion order (reported by Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
116 cmd_add("chat_disable", "Disable chat mode", 0, 0, &do_chat_disable);
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
117 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
118 cmd_add("connect", "Connect to the server", 0, 0, &do_connect);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 191
diff changeset
119 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
120 cmd_add("disconnect", "Disconnect from server", 0, 0, &do_disconnect);
757
ae23c8826efb Improve completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 755
diff changeset
121 cmd_add("event", "Process an event", COMPL_EVENTSID, COMPL_EVENTS, &do_event);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
122 cmd_add("group", "Change group display settings", COMPL_GROUP, 0, &do_group);
868
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
123 cmd_add("help", "Display some help", COMPL_CMD, 0, &do_help);
1221
0dd5df7eb007 Fix wrong command completion order (reported by Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
124 cmd_add("iline", "Manipulate input buffer", 0, 0, &do_iline);
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
125 cmd_add("info", "Show basic info on current buddy", 0, 0, &do_info);
225
d5ae42cbe1fa [/trunk] Changeset 237 by mikael
mikael
parents: 221
diff changeset
126 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
d5ae42cbe1fa [/trunk] Changeset 237 by mikael
mikael
parents: 221
diff changeset
127 0, &do_move);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
128 cmd_add("msay", "Send a multi-lines message to the selected buddy",
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
129 COMPL_MULTILINE, 0, &do_msay);
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
130 cmd_add("pgp", "Manage PGP settings", COMPL_PGP, COMPL_JID, &do_pgp);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
131 cmd_add("quit", "Exit the software", 0, 0, NULL);
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
132 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
133 cmd_add("rename", "Rename the current buddy", 0, 0, &do_rename);
902
2016f52a167f Sort commands (for the completion system)
Mikael Berthe <mikael@lilotux.net>
parents: 900
diff changeset
134 cmd_add("request", "Send a Jabber IQ request", COMPL_REQUEST, COMPL_JID,
2016f52a167f Sort commands (for the completion system)
Mikael Berthe <mikael@lilotux.net>
parents: 900
diff changeset
135 &do_request);
2016f52a167f Sort commands (for the completion system)
Mikael Berthe <mikael@lilotux.net>
parents: 900
diff changeset
136 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
137 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
138 &do_roster);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
139 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
140 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
141 &do_say_to);
1221
0dd5df7eb007 Fix wrong command completion order (reported by Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1205
diff changeset
142 cmd_add("screen_refresh", "Redraw mcabber screen", 0, 0, &do_screen_refresh);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
143 //cmd_add("search");
310
29b27c8692ea Post-0.6.3 changes
Mikael Berthe <mikael@lilotux.net>
parents: 308
diff changeset
144 cmd_add("set", "Set/query an option value", 0, 0, &do_set);
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
145 cmd_add("source", "Read a configuration file", 0, 0, &do_source);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
146 cmd_add("status", "Show or set your status", COMPL_STATUS, 0, &do_status);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
147 cmd_add("status_to", "Show or set your status for one recipient",
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
148 COMPL_JID, COMPL_STATUS, &do_status_to);
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
149 cmd_add("version", "Show mcabber version", 0, 0, &do_version);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
150
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
151 // Status category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
152 compl_add_category_word(COMPL_STATUS, "online");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
153 compl_add_category_word(COMPL_STATUS, "avail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
154 compl_add_category_word(COMPL_STATUS, "invisible");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
155 compl_add_category_word(COMPL_STATUS, "free");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
156 compl_add_category_word(COMPL_STATUS, "dnd");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
157 compl_add_category_word(COMPL_STATUS, "notavail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
158 compl_add_category_word(COMPL_STATUS, "away");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
159
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
160 // Roster category
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
161 compl_add_category_word(COMPL_ROSTER, "bottom");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
162 compl_add_category_word(COMPL_ROSTER, "top");
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
163 compl_add_category_word(COMPL_ROSTER, "up");
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
164 compl_add_category_word(COMPL_ROSTER, "down");
1086
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
165 compl_add_category_word(COMPL_ROSTER, "group_prev");
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
166 compl_add_category_word(COMPL_ROSTER, "group_next");
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
167 compl_add_category_word(COMPL_ROSTER, "hide");
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
168 compl_add_category_word(COMPL_ROSTER, "show");
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
169 compl_add_category_word(COMPL_ROSTER, "toggle");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
170 compl_add_category_word(COMPL_ROSTER, "hide_offline");
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
171 compl_add_category_word(COMPL_ROSTER, "show_offline");
290
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
172 compl_add_category_word(COMPL_ROSTER, "toggle_offline");
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
173 compl_add_category_word(COMPL_ROSTER, "item_lock");
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
174 compl_add_category_word(COMPL_ROSTER, "item_unlock");
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
175 compl_add_category_word(COMPL_ROSTER, "alternate");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
176 compl_add_category_word(COMPL_ROSTER, "search");
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
177 compl_add_category_word(COMPL_ROSTER, "unread_first");
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
178 compl_add_category_word(COMPL_ROSTER, "unread_next");
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
179 compl_add_category_word(COMPL_ROSTER, "note");
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
180
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
181 // Roster category
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
182 compl_add_category_word(COMPL_BUFFER, "clear");
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
183 compl_add_category_word(COMPL_BUFFER, "bottom");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
184 compl_add_category_word(COMPL_BUFFER, "top");
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
185 compl_add_category_word(COMPL_BUFFER, "up");
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
186 compl_add_category_word(COMPL_BUFFER, "down");
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
187 compl_add_category_word(COMPL_BUFFER, "search_backward");
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
188 compl_add_category_word(COMPL_BUFFER, "search_forward");
464
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
189 compl_add_category_word(COMPL_BUFFER, "date");
462
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
190 compl_add_category_word(COMPL_BUFFER, "%");
866
b30df2ab457f Add "/buffer purge"
Mikael Berthe <mikael@lilotux.net>
parents: 865
diff changeset
191 compl_add_category_word(COMPL_BUFFER, "purge");
1135
5d7c05932b13 Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents: 1130
diff changeset
192 compl_add_category_word(COMPL_BUFFER, "close");
1138
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
193 compl_add_category_word(COMPL_BUFFER, "close_all");
873
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
194 compl_add_category_word(COMPL_BUFFER, "scroll_lock");
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
195 compl_add_category_word(COMPL_BUFFER, "scroll_unlock");
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
196 compl_add_category_word(COMPL_BUFFER, "scroll_toggle");
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
197
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
198 // Group category
240
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
199 compl_add_category_word(COMPL_GROUP, "fold");
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
200 compl_add_category_word(COMPL_GROUP, "unfold");
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
201 compl_add_category_word(COMPL_GROUP, "toggle");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
202
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
203 // Multi-line (msay) category
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
204 compl_add_category_word(COMPL_MULTILINE, "abort");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
205 compl_add_category_word(COMPL_MULTILINE, "begin");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
206 compl_add_category_word(COMPL_MULTILINE, "send");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
207 compl_add_category_word(COMPL_MULTILINE, "send_to");
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
208 compl_add_category_word(COMPL_MULTILINE, "toggle");
838
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
209 compl_add_category_word(COMPL_MULTILINE, "toggle_verbatim");
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
210 compl_add_category_word(COMPL_MULTILINE, "verbatim");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
211
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
212 // Room category
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
213 compl_add_category_word(COMPL_ROOM, "affil");
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
214 compl_add_category_word(COMPL_ROOM, "ban");
1009
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
215 compl_add_category_word(COMPL_ROOM, "bookmark");
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
216 compl_add_category_word(COMPL_ROOM, "destroy");
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 484
diff changeset
217 compl_add_category_word(COMPL_ROOM, "invite");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
218 compl_add_category_word(COMPL_ROOM, "join");
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
219 compl_add_category_word(COMPL_ROOM, "kick");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
220 compl_add_category_word(COMPL_ROOM, "leave");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
221 compl_add_category_word(COMPL_ROOM, "names");
470
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
222 compl_add_category_word(COMPL_ROOM, "nick");
490
af6e31e32d9e Add "/room privmsg"
Mikael Berthe <mikael@lilotux.net>
parents: 488
diff changeset
223 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
224 compl_add_category_word(COMPL_ROOM, "remove");
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
225 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
226 compl_add_category_word(COMPL_ROOM, "topic");
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 448
diff changeset
227 compl_add_category_word(COMPL_ROOM, "unlock");
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
228 compl_add_category_word(COMPL_ROOM, "whois");
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
229
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
230 // Authorization category
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
231 compl_add_category_word(COMPL_AUTH, "allow");
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
232 compl_add_category_word(COMPL_AUTH, "cancel");
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
233 compl_add_category_word(COMPL_AUTH, "request");
835
6a732d2ad4b4 Add "/authorization request_unsubscribe"
Mikael Berthe <mikael@lilotux.net>
parents: 831
diff changeset
234 compl_add_category_word(COMPL_AUTH, "request_unsubscribe");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
235
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
236 // Request (query) category
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
237 compl_add_category_word(COMPL_REQUEST, "last");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
238 compl_add_category_word(COMPL_REQUEST, "time");
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
239 compl_add_category_word(COMPL_REQUEST, "vcard");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
240 compl_add_category_word(COMPL_REQUEST, "version");
750
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
241
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
242 // Events category
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
243 compl_add_category_word(COMPL_EVENTS, "accept");
755
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
244 compl_add_category_word(COMPL_EVENTS, "ignore");
750
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
245 compl_add_category_word(COMPL_EVENTS, "reject");
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
246
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
247 // PGP category
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
248 compl_add_category_word(COMPL_PGP, "disable");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
249 compl_add_category_word(COMPL_PGP, "enable");
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
250 compl_add_category_word(COMPL_PGP, "force");
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
251 compl_add_category_word(COMPL_PGP, "info");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
252 compl_add_category_word(COMPL_PGP, "setkey");
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
253 }
94
9a4aa2797f02 [/trunk] Changeset 108 by mikael
mikael
parents: 81
diff changeset
254
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
255 // expandalias(line)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
256 // If there is one, expand the alias in line and returns a new allocated line
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
257 // If no alias is found, returns line
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
258 // Note : if the returned pointer is different from line, the caller should
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
259 // g_free() the pointer after use
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
260 char *expandalias(char *line)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
261 {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
262 const char *p1, *p2;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
263 char *word;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
264 const gchar *value;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
265 char *newline = line;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
266
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
267 // Ignore leading COMMAND_CHAR
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
268 for (p1 = line ; *p1 == COMMAND_CHAR ; p1++)
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
269 ;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
270 // Locate the end of the word
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
271 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
272 ;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
273 // Extract the word
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
274 word = g_strndup(p1, p2-p1);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
275
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
276 // Look for an alias in the list
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
277 value = settings_get(SETTINGS_TYPE_ALIAS, (const char*)word);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
278 if (value) {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
279 // There is an alias to expand
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
280 newline = g_new(char, strlen(value)+strlen(p2)+2);
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
281 *newline = COMMAND_CHAR;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
282 strcpy(newline+1, value);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
283 strcat(newline, p2);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
284 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
285 g_free(word);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
286
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
287 return newline;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
288 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
289
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
290 // cmd_get
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
291 // Finds command in the command list structure.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
292 // Returns a pointer to the cmd entry, or NULL if command not found.
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
293 cmd *cmd_get(const char *command)
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
294 {
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
295 const char *p1, *p2;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
296 char *com;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
297 GSList *sl_com;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
298
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
299 // Ignore leading COMMAND_CHAR
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
300 for (p1 = command ; *p1 == COMMAND_CHAR ; p1++)
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
301 ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
302 // Locate the end of the command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
303 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
304 ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
305 // Copy the clean command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
306 com = g_strndup(p1, p2-p1);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
307
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
308 // Look for command in the list
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
309 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) {
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
310 if (!strcasecmp(com, ((cmd*)sl_com->data)->name))
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
311 break;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
312 }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
313 g_free(com);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
314
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
315 if (sl_com) // Command has been found.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
316 return (cmd*)sl_com->data;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
317 return NULL;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
318 }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
319
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
320 // send_message(msg)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
321 // Write the message in the buddy's window and send the message on
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
322 // the network.
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
323 static void send_message(const char *msg, const char *subj)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
324 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
325 const char *bjid;
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
326 gint crypted;
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
327
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
328 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
329 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
330 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
331 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
332
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
333 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
334 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
335 return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
336 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
337
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
338 bjid = CURRENT_JID;
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
339 if (!bjid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
340 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
341 return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
342 }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
343
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
344 // Network part
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
345 jb_send_msg(bjid, msg, buddy_gettype(BUDDATA(current_buddy)), subj, NULL,
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
346 &crypted);
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
347
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
348 if (crypted == -1) {
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
349 scr_LogPrint(LPRINT_LOGNORM, "Encryption error. Message was not sent.");
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
350 return;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
351 }
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
352
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
353 // Hook
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
354 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
355 // local part (UI, logging, etc.)
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
356 gchar *hmsg;
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
357 if (subj)
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
358 hmsg = g_strdup_printf("[%s]\n%s", subj, msg);
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
359 else
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
360 hmsg = (char*)msg;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
361 hk_message_out(bjid, NULL, 0, hmsg, crypted);
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
362 if (hmsg != msg) g_free(hmsg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
363 }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
364 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
365
1187
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
366 // process_command(line, iscmd)
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
367 // Process a command line.
1187
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
368 // If iscmd is TRUE, process the command even if verbatim mmode is set;
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
369 // it is intended to be used for key bindings.
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
370 // Return 255 if this is the /quit command, and 0 for the other commands.
1187
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
371 int process_command(char *line, guint iscmd)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
372 {
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
373 char *p;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
374 char *xpline;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
375 cmd *curcmd;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
376
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
377 // We do alias expansion here
1187
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
378 if (iscmd || scr_get_multimode() != 2)
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
379 xpline = expandalias(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
380 else
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
381 xpline = line; // No expansion in verbatim multi-line mode
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
382
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
383 // We want to have a copy
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
384 if (xpline == line)
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
385 xpline = g_strdup(line);
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
386
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
387 // Remove trailing spaces:
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
388 for (p=xpline ; *p ; p++)
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
389 ;
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
390 for (p-- ; p>xpline && (*p == ' ') ; p--)
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
391 *p = 0;
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
392
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
393 // Command "quit"?
1187
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
394 if ((iscmd || scr_get_multimode() != 2)
1126
771eb6aa2d41 Fix another memory leak, spotted by valgrind
misc@mandriva.org
parents: 1100
diff changeset
395 && (!strncasecmp(xpline, mkcmdstr("quit"), strlen(mkcmdstr("quit"))))) {
771eb6aa2d41 Fix another memory leak, spotted by valgrind
misc@mandriva.org
parents: 1100
diff changeset
396 if (!xpline[5] || xpline[5] == ' ') {
771eb6aa2d41 Fix another memory leak, spotted by valgrind
misc@mandriva.org
parents: 1100
diff changeset
397 g_free(xpline);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
398 return 255;
1126
771eb6aa2d41 Fix another memory leak, spotted by valgrind
misc@mandriva.org
parents: 1100
diff changeset
399 }
771eb6aa2d41 Fix another memory leak, spotted by valgrind
misc@mandriva.org
parents: 1100
diff changeset
400 }
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
401
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
402 // If verbatim multi-line mode, we check if another /msay command is typed
1187
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
403 if (!iscmd && scr_get_multimode() == 2
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
404 && (strncasecmp(xpline, mkcmdstr("msay "), strlen(mkcmdstr("msay "))))) {
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
405 // It isn't an /msay command
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
406 scr_append_multiline(xpline);
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
407 g_free(xpline);
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
408 return 0;
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
409 }
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
410
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
411 // Commands handling
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
412 curcmd = cmd_get(xpline);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
413
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
414 if (!curcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
415 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command. "
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
416 "Please see the manual for a list of known commands.");
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
417 g_free(xpline);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
418 return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
419 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
420 if (!curcmd->func) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
421 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
422 "This functionality is not yet implemented, sorry.");
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
423 g_free(xpline);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
424 return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
425 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
426 // Lets go to the command parameters
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
427 for (p = xpline+1; *p && (*p != ' ') ; p++)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
428 ;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
429 // Skip spaces
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
430 while (*p && (*p == ' '))
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
431 p++;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
432 // Call command-specific function
1173
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
433 retval_for_cmds = 0;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
434 (*curcmd->func)(p);
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
435 g_free(xpline);
1173
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
436 return retval_for_cmds;
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
437 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
438
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
439 // process_line(line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
440 // Process a command/message line.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
441 // If this isn't a command, this is a message and it is sent to the
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
442 // currently selected buddy.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
443 // Return 255 if the line is the /quit command, or 0.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
444 int process_line(char *line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
445 {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
446 if (!*line) { // User only pressed enter
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
447 if (scr_get_multimode()) {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
448 scr_append_multiline("");
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
449 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
450 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
451 if (current_buddy) {
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
452 // Enter chat mode
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
453 scr_set_chatmode(TRUE);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
454 scr_ShowBuddyWindow();
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
455 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
456 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
457 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
458
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
459 if (*line != COMMAND_CHAR) {
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
460 // This isn't a command
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
461 if (scr_get_multimode())
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
462 scr_append_multiline(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
463 else
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
464 do_say(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
465 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
466 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
467
1187
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
468 /* It is _probably_ a command -- except for verbatim multi-line mode */
16abe7ec3056 Fix a conflict between verbatim multiline mode and the key binding system
Mikael Berthe <mikael@lilotux.net>
parents: 1181
diff changeset
469 return process_command(line, FALSE);
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
470 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
471
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
472 // Helper routine for buffer item_{lock,unlock}
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
473 static void roster_buddylock(char *bjid, bool lock)
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
474 {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
475 gpointer bud = NULL;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
476 bool may_need_refresh = FALSE;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
477
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
478 // Allow special jid "" or "." (current buddy)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
479 if (bjid && (!*bjid || !strcmp(bjid, ".")))
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
480 bjid = NULL;
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
481
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
482 if (bjid) {
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
483 // The JID has been specified. Quick check...
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
484 if (check_jid_syntax(bjid)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
485 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
486 "<%s> is not a valid Jabber ID.", bjid);
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
487 } else {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
488 // Find the buddy
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
489 GSList *roster_elt;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
490 roster_elt = roster_find(bjid, jidsearch,
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
491 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
492 if (roster_elt)
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
493 bud = roster_elt->data;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
494 else
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
495 scr_LogPrint(LPRINT_NORMAL, "This jid isn't in the roster.");
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
496 may_need_refresh = TRUE;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
497 }
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
498 } else {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
499 // Use the current buddy
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
500 if (current_buddy)
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
501 bud = BUDDATA(current_buddy);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
502 }
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
503
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
504 // Update the ROSTER_FLAG_USRLOCK flag
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
505 if (bud) {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
506 buddy_setflags(bud, ROSTER_FLAG_USRLOCK, lock);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
507 if (may_need_refresh)
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
508 buddylist_build();
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
509 update_roster = TRUE;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
510 }
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
511 }
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
512
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
513 // display_and_free_note(note, winId)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
514 // Display the note information in the winId buffer, and free note
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
515 // (winId is a bare jid or NULL for the status window, in which case we
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
516 // display the note jid too)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
517 static void display_and_free_note(struct annotation *note, const char *winId)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
518 {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
519 gchar tbuf[128];
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
520 GString *sbuf;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
521 guint msg_flag = HBB_PREFIX_INFO;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
522 /* We use the flag prefix_info for the first line, and prefix_none
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
523 for the other lines, for better readability */
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
524
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
525 if (!note)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
526 return;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
527
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
528 sbuf = g_string_new("");
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
529
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
530 if (!winId) {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
531 // We're writing to the status window, so let's show the jid too.
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
532 g_string_printf(sbuf, "Annotation on <%s>", note->jid);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
533 scr_WriteIncomingMessage(winId, sbuf->str, 0, msg_flag);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
534 msg_flag = HBB_PREFIX_NONE;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
535 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
536
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
537 // If we have the creation date, display it
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
538 if (note->cdate) {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
539 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S",
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
540 localtime(&note->cdate));
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
541 g_string_printf(sbuf, "Note created %s", tbuf);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
542 scr_WriteIncomingMessage(winId, sbuf->str, 0, msg_flag);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
543 msg_flag = HBB_PREFIX_NONE;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
544 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
545 // If we have the modification date, display it
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
546 // unless it's the same as the creation date
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
547 if (note->mdate && note->mdate != note->cdate) {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
548 strftime(tbuf, sizeof(tbuf), "%Y-%m-%d %H:%M:%S",
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
549 localtime(&note->mdate));
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
550 g_string_printf(sbuf, "Note modified %s", tbuf);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
551 scr_WriteIncomingMessage(winId, sbuf->str, 0, msg_flag);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
552 msg_flag = HBB_PREFIX_NONE;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
553 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
554 // Note text
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
555 g_string_printf(sbuf, "Note: %s", note->text);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
556 scr_WriteIncomingMessage(winId, sbuf->str, 0, msg_flag);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
557
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
558 g_string_free(sbuf, TRUE);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
559 g_free(note->text);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
560 g_free(note->jid);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
561 g_free(note);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
562 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
563
1059
875d2c9d399c Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
564 static void display_all_annotations(void)
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
565 {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
566 GSList *notes;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
567 notes = jb_get_all_storage_rosternotes();
1163
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
568
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
569 if (!notes)
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
570 return;
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
571
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
572 // Call display_and_free_note() for each note,
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
573 // with winId = NULL (special window)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
574 g_slist_foreach(notes, (GFunc)&display_and_free_note, NULL);
1163
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
575 scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE);
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
576 update_roster = TRUE;
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
577 g_slist_free(notes);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
578 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
579
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
580 static void roster_note(char *arg)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
581 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
582 const char *bjid;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
583 guint type;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
584
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
585 if (!current_buddy)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
586 return;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
587
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
588 bjid = buddy_getjid(BUDDATA(current_buddy));
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
589 type = buddy_gettype(BUDDATA(current_buddy));
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
590
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
591 if (!bjid && type == ROSTER_TYPE_SPECIAL && !arg) {
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
592 // We're in the status window (the only special buffer currently)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
593 // Let's display all server notes
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
594 display_all_annotations();
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
595 return;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
596 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
597
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
598 if (!bjid || (type != ROSTER_TYPE_USER &&
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
599 type != ROSTER_TYPE_ROOM &&
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
600 type != ROSTER_TYPE_AGENT)) {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
601 scr_LogPrint(LPRINT_NORMAL, "This item can't have a note.");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
602 return;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
603 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
604
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
605 if (arg && *arg) { // Set a note
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
606 gchar *msg, *notetxt;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
607 msg = to_utf8(arg);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
608 if (!strcmp(msg, "-"))
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
609 notetxt = NULL; // delete note
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
610 else
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
611 notetxt = msg;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
612 jb_set_storage_rosternotes(bjid, notetxt);
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
613 g_free(msg);
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
614 } else { // Display a note
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
615 struct annotation *note = jb_get_storage_rosternotes(bjid, FALSE);
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
616 if (note) {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
617 display_and_free_note(note, bjid);
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
618 } else {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
619 scr_WriteIncomingMessage(bjid, "This item doesn't have a note.", 0,
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
620 HBB_PREFIX_INFO);
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
621 }
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
622 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
623 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
624
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
625 /* Commands callback functions */
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
626 /* 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
627 /* (with arg not null) */
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
628
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
629 static void do_roster(char *arg)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
630 {
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
631 char **paramlst;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
632 char *subcmd;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
633
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
634 paramlst = split_arg(arg, 2, 1); // subcmd, arg
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
635 subcmd = *paramlst;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
636 arg = *(paramlst+1);
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
637
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
638 if (!subcmd || !*subcmd) {
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
639 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
640 free_arg_lst(paramlst);
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
641 return;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
642 }
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
643
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
644 if (!strcasecmp(subcmd, "top")) {
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
645 scr_RosterTop();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
646 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
647 } else if (!strcasecmp(subcmd, "bottom")) {
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
648 scr_RosterBottom();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
649 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
650 } else if (!strcasecmp(subcmd, "hide")) {
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
651 scr_RosterVisibility(0);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
652 } else if (!strcasecmp(subcmd, "show")) {
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
653 scr_RosterVisibility(1);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
654 } else if (!strcasecmp(subcmd, "toggle")) {
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
655 scr_RosterVisibility(-1);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
656 } else if (!strcasecmp(subcmd, "hide_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
657 buddylist_set_hide_offline_buddies(TRUE);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
658 if (current_buddy)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
659 buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
660 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
661 } else if (!strcasecmp(subcmd, "show_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
662 buddylist_set_hide_offline_buddies(FALSE);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
663 buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
664 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
665 } else if (!strcasecmp(subcmd, "toggle_offline")) {
290
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
666 buddylist_set_hide_offline_buddies(-1);
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
667 buddylist_build();
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
668 update_roster = TRUE;
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
669 } else if (!strcasecmp(subcmd, "item_lock")) {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
670 roster_buddylock(arg, TRUE);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
671 } else if (!strcasecmp(subcmd, "item_unlock")) {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
672 roster_buddylock(arg, FALSE);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
673 } else if (!strcasecmp(subcmd, "unread_first")) {
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
674 scr_RosterUnreadMessage(0);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
675 } else if (!strcasecmp(subcmd, "unread_next")) {
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
676 scr_RosterUnreadMessage(1);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
677 } else if (!strcasecmp(subcmd, "alternate")) {
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
678 scr_RosterJumpAlternate();
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
679 } else if (!strncasecmp(subcmd, "search", 6)) {
979
ea939ff047d8 Improve /buffer search_*
Mikael Berthe <mikael@lilotux.net>
parents: 978
diff changeset
680 strip_arg_special_chars(arg);
ea939ff047d8 Improve /buffer search_*
Mikael Berthe <mikael@lilotux.net>
parents: 978
diff changeset
681 if (!arg || !*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
682 scr_LogPrint(LPRINT_NORMAL, "What name or JID are you looking for?");
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
683 free_arg_lst(paramlst);
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
684 return;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
685 }
978
a58dfdd6d058 Fix /roster search
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
686 scr_RosterSearch(arg);
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
687 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
688 } else if (!strcasecmp(subcmd, "up")) {
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
689 scr_RosterUp();
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
690 } else if (!strcasecmp(subcmd, "down")) {
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
691 scr_RosterDown();
1086
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
692 } else if (!strcasecmp(subcmd, "group_prev")) {
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
693 scr_RosterPrevGroup();
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
694 } else if (!strcasecmp(subcmd, "group_next")) {
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
695 scr_RosterNextGroup();
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
696 } else if (!strcasecmp(subcmd, "note")) {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
697 roster_note(arg);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
698 } else
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
699 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
700 free_arg_lst(paramlst);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
701 }
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
702
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
703 // setstatus(recipient, arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
704 // Set your Jabber status.
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
705 // - if recipient is not NULL, the status is sent to this contact only
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
706 // - arg must be "status message" (message is optional)
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1138
diff changeset
707 void setstatus(const char *recipient, const char *arg)
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
708 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
709 char **paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
710 char *status;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
711 char *msg;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
712 enum imstatus st;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
713
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
714 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
715 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
716 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
717 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
718
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
719 paramlst = split_arg(arg, 2, 0); // status, message
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
720 status = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
721 msg = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
722
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
723 if (!status) {
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
724 free_arg_lst(paramlst);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
725 return;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
726 }
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
727
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
728 if (!strcasecmp(status, IMSTATUS_OFFLINE)) st = offline;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
729 else if (!strcasecmp(status, IMSTATUS_ONLINE)) st = available;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
730 else if (!strcasecmp(status, IMSTATUS_AVAILABLE)) st = available;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
731 else if (!strcasecmp(status, IMSTATUS_AWAY)) st = away;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
732 else if (!strcasecmp(status, IMSTATUS_INVISIBLE)) st = invisible;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
733 else if (!strcasecmp(status, IMSTATUS_DONOTDISTURB)) st = dontdisturb;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
734 else if (!strcasecmp(status, IMSTATUS_NOTAVAILABLE)) st = notavail;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
735 else if (!strcasecmp(status, IMSTATUS_FREE4CHAT)) st = freeforchat;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
736 else {
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
737 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!");
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
738 free_arg_lst(paramlst);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
739 return;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
740 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
741
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
742 // Use provided message
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
743 if (msg && !*msg) {
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
744 msg = NULL;
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
745 }
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
746
528
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
747 // 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
748 if (recipient && !msg)
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
749 msg = "";
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
750
1050
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
751 jb_setstatus(st, recipient, msg, FALSE);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
752
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
753 free_arg_lst(paramlst);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
754 }
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
755
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
756 static void do_status(char *arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
757 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
758 if (!*arg) {
519
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
759 const char *sm = jb_getstatusmsg();
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
760 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
761 imstatus2char[jb_getstatus()],
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
762 (sm ? sm : ""));
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
763 return;
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
764 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
765 arg = to_utf8(arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
766 setstatus(NULL, arg);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
767 g_free(arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
768 }
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
769
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
770 static void do_status_to(char *arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
771 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
772 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
773 char *fjid, *st, *msg;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
774 char *jid_utf8 = NULL;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
775
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
776 paramlst = split_arg(arg, 3, 1); // jid, status, [message]
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
777 fjid = *paramlst;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
778 st = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
779 msg = *(paramlst+2);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
780
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
781 if (!fjid || !st) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
782 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
783 "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
784 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
785 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
786 }
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
787
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
788 // Allow things like /status_to "" away
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
789 if (!*fjid || !strcmp(fjid, "."))
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
790 fjid = NULL;
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
791
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
792 if (fjid) {
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
793 // The JID has been specified. Quick check...
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
794 if (check_jid_syntax(fjid)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
795 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
796 "<%s> is not a valid Jabber ID.", fjid);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
797 fjid = NULL;
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
798 } else {
696
ee06382dfb22 /status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents: 694
diff changeset
799 // Convert jid to lowercase
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
800 char *p = fjid;
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 974
diff changeset
801 for ( ; *p && *p != JID_RESOURCE_SEPARATOR; p++)
696
ee06382dfb22 /status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents: 694
diff changeset
802 *p = tolower(*p);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
803 fjid = jid_utf8 = to_utf8(fjid);
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
804 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
805 } 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
806 // 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
807 if (current_buddy)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
808 fjid = (char*)buddy_getjid(BUDDATA(current_buddy));
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
809 if (!fjid)
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
810 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
811 }
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
812
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
813 if (fjid) {
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
814 char *cmdline;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
815 if (!msg)
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
816 msg = "";
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
817 msg = to_utf8(msg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
818 cmdline = g_strdup_printf("%s %s", st, msg);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
819 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", fjid, cmdline);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
820 setstatus(fjid, cmdline);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
821 g_free(msg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
822 g_free(cmdline);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
823 g_free(jid_utf8);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
824 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
825 free_arg_lst(paramlst);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
826 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
827
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
828 static void do_add(char *arg)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
829 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
830 char **paramlst;
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
831 char *id, *nick;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
832 char *jid_utf8 = NULL;
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
833
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
834 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
835 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
836 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
837 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
838
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
839 paramlst = split_arg(arg, 2, 0); // jid, [nickname]
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
840 id = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
841 nick = *(paramlst+1);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
842
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
843 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
844 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
845 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
846 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
847
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
848 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
849 // 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
850 if (check_jid_syntax(id)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
851 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
852 "<%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
853 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
854 } 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
855 mc_strtolower(id);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
856 // Actually an UTF-8 id isn't needed because only the bare jid will
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
857 // be used.
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
858 id = jid_utf8 = to_utf8(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
859 }
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
860 } 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
861 // 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
862 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
863 id = (char*)buddy_getjid(BUDDATA(current_buddy));
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
864 if (!id)
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
865 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
866 }
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
867
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
868 if (nick)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
869 nick = to_utf8(nick);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
870
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
871 if (id) {
452
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
872 // 2nd parameter = optional nickname
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
873 jb_addbuddy(id, nick, NULL);
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
874 scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>.",
452
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
875 id);
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
876 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
877
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
878 g_free(jid_utf8);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
879 g_free(nick);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
880 free_arg_lst(paramlst);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
881 }
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
882
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
883 static void do_del(char *arg)
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
884 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
885 const char *bjid;
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
886
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
887 if (*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
888 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
889 "the currently-selected buddy will be deleted.");
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
890 return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
891 }
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
892
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
893 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
894 return;
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
895 bjid = buddy_getjid(BUDDATA(current_buddy));
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
896 if (!bjid)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
897 return;
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
898
540
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
899 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
900 // This is a chatroom
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 650
diff changeset
901 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
902 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
903 return;
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
904 }
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
905 }
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
906
1165
d5b26a0a9771 Close a buffer when using /del
Mikael Berthe <mikael@lilotux.net>
parents: 1163
diff changeset
907 // Close the buffer
d5b26a0a9771 Close a buffer when using /del
Mikael Berthe <mikael@lilotux.net>
parents: 1163
diff changeset
908 scr_BufferPurge(1);
d5b26a0a9771 Close a buffer when using /del
Mikael Berthe <mikael@lilotux.net>
parents: 1163
diff changeset
909
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
910 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", bjid);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
911 jb_delbuddy(bjid);
865
cee8d6be04e1 Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents: 861
diff changeset
912 scr_UpdateBuddyWindow();
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
913 }
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
914
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
915 static void do_group(char *arg)
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
916 {
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
917 gpointer group;
958
30b799632653 Cosmetics (change a variable name)
Mikael Berthe <mikael@lilotux.net>
parents: 957
diff changeset
918 guint leave_buddywindow;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
919
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
920 if (!*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
921 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
922 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
923 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
924
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
925 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
926 return;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
927
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
928 group = buddy_getgroup(BUDDATA(current_buddy));
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
929 if (!group)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
930 return;
853
bdd526ec62bc Fix segfault when using /group with the [status] entry
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
931
212
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
932 // We'll have to redraw the chat window if we're not currently on the group
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
933 // entry itself, because it means we'll have to leave the current buddy
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
934 // chat window.
958
30b799632653 Cosmetics (change a variable name)
Mikael Berthe <mikael@lilotux.net>
parents: 957
diff changeset
935 leave_buddywindow = (group != BUDDATA(current_buddy));
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
936
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
937 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
938 scr_LogPrint(LPRINT_NORMAL, "You need to select a group.");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
939 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
940 }
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
941
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
942 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
943 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE);
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
944 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
945 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE);
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
946 } else if (!strcasecmp(arg, "toggle")) {
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
947 buddy_setflags(group, ROSTER_FLAG_HIDE,
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
948 !(buddy_getflags(group) & ROSTER_FLAG_HIDE));
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
949 } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
950 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
951 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
952 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
953
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
954 buddylist_build();
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
955 update_roster = TRUE;
958
30b799632653 Cosmetics (change a variable name)
Mikael Berthe <mikael@lilotux.net>
parents: 957
diff changeset
956 if (leave_buddywindow) scr_ShowBuddyWindow();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
957 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
958
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
959 static int send_message_to(const char *fjid, const char *msg, const char *subj)
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
960 {
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
961 char *bare_jid, *rp;
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
962 char *hmsg;
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
963 gint crypted;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
964 gint retval = 0;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
965
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
966 if (!fjid || !*fjid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
967 scr_LogPrint(LPRINT_NORMAL, "You must specify a Jabber ID.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
968 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
969 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
970 if (!msg || !*msg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
971 scr_LogPrint(LPRINT_NORMAL, "You must specify a message.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
972 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
973 }
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
974 if (check_jid_syntax((char*)fjid)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
975 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
976 "<%s> is not a valid Jabber ID.", fjid);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
977 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
978 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
979
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
980 // We must use the bare jid in hk_message_out()
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
981 rp = strchr(fjid, JID_RESOURCE_SEPARATOR);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
982 if (rp) bare_jid = g_strndup(fjid, rp - fjid);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
983 else bare_jid = (char*)fjid;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
984
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
985 // Jump to window, create one if needed
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
986 scr_RosterJumpJid(bare_jid);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
987
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
988 // Check if we're sending a message to a conference room
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
989 // If not, we must make sure rp is NULL, for hk_message_out()
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
990 if (rp) {
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
991 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) rp++;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
992 else rp = NULL;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
993 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
994
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
995 // local part (UI, logging, etc.)
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
996 if (subj)
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
997 hmsg = g_strdup_printf("[%s]\n%s", subj, msg);
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
998 else
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
999 hmsg = (char*)msg;
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1000
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
1001 // Network part
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1002 jb_send_msg(fjid, msg, ROSTER_TYPE_USER, subj, NULL, &crypted);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1003
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1004 if (crypted == -1) {
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1005 scr_LogPrint(LPRINT_LOGNORM, "Encryption error. Message was not sent.");
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1006 retval = 1;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1007 goto send_message_to_return;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1008 }
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1009
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
1010 // Hook
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
1011 hk_message_out(bare_jid, rp, 0, hmsg, crypted);
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1012
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1013 send_message_to_return:
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
1014 if (hmsg != msg) g_free(hmsg);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1015 if (rp) g_free(bare_jid);
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
1016 return retval;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1017 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1018
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1019 static void do_say(char *arg)
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1020 {
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1021 gpointer bud;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1022
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1023 scr_set_chatmode(TRUE);
1130
b2040a7fb7fc Refresh chat buffer when sending a message in non-chatmode
Mikael Berthe <mikael@lilotux.net>
parents: 1126
diff changeset
1024 scr_ShowBuddyWindow();
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1025
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1026 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1027 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1028 "Whom are you talking to? Please select a buddy.");
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1029 return;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1030 }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1031
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1032 bud = BUDDATA(current_buddy);
631
423c24e5875a Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 626
diff changeset
1033 if (!(buddy_gettype(bud) &
423c24e5875a Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 626
diff changeset
1034 (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
1035 scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1036 return;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1037 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1038
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
1039 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1040 arg = to_utf8(arg);
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1041 send_message(arg, NULL);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1042 g_free(arg);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1043 }
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1044
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1045 static void do_msay(char *arg)
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1046 {
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1047 /* Parameters: begin verbatim abort send send_to */
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1048 char **paramlst;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1049 char *subcmd;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1050
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1051 paramlst = split_arg(arg, 2, 1); // subcmd, arg
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1052 subcmd = *paramlst;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1053 arg = *(paramlst+1);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1054
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1055 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1056 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1057 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using "
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1058 "the /msay command.");
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1059 scr_LogPrint(LPRINT_NORMAL, "(Use \"%s begin\" to enter "
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1060 "multi-line mode...)", mkcmdstr("msay"));
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1061 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1062 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1063
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1064 if (!strcasecmp(subcmd, "toggle")) {
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1065 if (scr_get_multimode())
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1066 subcmd = "send";
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1067 else
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1068 subcmd = "begin";
838
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1069 } else if (!strcasecmp(subcmd, "toggle_verbatim")) {
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1070 if (scr_get_multimode())
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1071 subcmd = "send";
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1072 else
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1073 subcmd = "verbatim";
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1074 }
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1075
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1076 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
1077 if (scr_get_multimode())
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1078 scr_LogPrint(LPRINT_NORMAL, "Leaving multi-line message mode.");
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1079 scr_set_multimode(FALSE, NULL);
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1080 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1081 } else if ((!strcasecmp(subcmd, "begin")) ||
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1082 (!strcasecmp(subcmd, "verbatim"))) {
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1083 bool verbat;
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1084 gchar *subj_utf8 = to_utf8(arg);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1085 if (!strcasecmp(subcmd, "verbatim")) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1086 scr_set_multimode(2, subj_utf8);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1087 verbat = TRUE;
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1088 } else {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1089 scr_set_multimode(1, subj_utf8);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1090 verbat = FALSE;
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1091 }
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
1092
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1093 scr_LogPrint(LPRINT_NORMAL, "Entered %smulti-line message mode.",
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1094 verbat ? "VERBATIM " : "");
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1095 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"%s send\" "
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1096 "when your message is ready.", mkcmdstr("msay"));
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1097 if (verbat)
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1098 scr_LogPrint(LPRINT_NORMAL, "Use \"%s abort\" to abort this mode.",
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1099 mkcmdstr("msay"));
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1100 g_free(subj_utf8);
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1101 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1102 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1103 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1104 goto do_msay_return;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1105 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1106
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1107 /* send/send_to command */
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1108
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1109 if (!scr_get_multimode()) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1110 scr_LogPrint(LPRINT_NORMAL, "No message to send. "
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1111 "Use \"%s begin\" first.", mkcmdstr("msay"));
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1112 goto do_msay_return;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1113 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1114
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1115 scr_set_chatmode(TRUE);
1130
b2040a7fb7fc Refresh chat buffer when sending a message in non-chatmode
Mikael Berthe <mikael@lilotux.net>
parents: 1126
diff changeset
1116 scr_ShowBuddyWindow();
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1117
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1118 if (!strcasecmp(subcmd, "send_to")) {
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1119 int err = FALSE;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1120 gchar *msg_utf8;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1121 // Let's send to the specified JID. We leave now if there
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1122 // has been an error (so we don't leave multi-line mode).
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1123 arg = to_utf8(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1124 msg_utf8 = to_utf8(scr_get_multiline());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1125 if (msg_utf8) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1126 err = send_message_to(arg, msg_utf8, scr_get_multimode_subj());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1127 g_free(msg_utf8);
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1128 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1129 g_free(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1130 if (err)
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1131 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1132 } else { // Send to currently selected buddy
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1133 gpointer bud;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1134 gchar *msg_utf8;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1135
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1136 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1137 scr_LogPrint(LPRINT_NORMAL, "Whom are you talking to?");
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1138 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1139 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1140
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1141 bud = BUDDATA(current_buddy);
1181
807815928754 Allow sending a multi-line message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 1177
diff changeset
1142 if (!(buddy_gettype(bud) &
807815928754 Allow sending a multi-line message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 1177
diff changeset
1143 (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
1144 scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1145 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1146 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1147
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1148 buddy_setflags(bud, ROSTER_FLAG_LOCK, TRUE);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1149 msg_utf8 = to_utf8(scr_get_multiline());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1150 if (msg_utf8) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1151 send_message(msg_utf8, scr_get_multimode_subj());
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1152 g_free(msg_utf8);
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1153 }
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1154 }
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1155 scr_set_multimode(FALSE, NULL);
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1156 scr_LogPrint(LPRINT_NORMAL, "You have left multi-line message mode.");
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1157 do_msay_return:
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1158 free_arg_lst(paramlst);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1159 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1160
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1161 static void do_say_to(char *arg)
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1162 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1163 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1164 char *fjid, *msg;
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1165
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1166 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1167 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1168 return;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1169 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1170
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1171 paramlst = split_arg(arg, 2, 1); // jid, message
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1172 fjid = *paramlst;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1173 msg = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1174
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1175 if (!fjid || !strcmp(fjid, ".")) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1176 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
1177 free_arg_lst(paramlst);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1178 return;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1179 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1180
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1181 fjid = to_utf8(fjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1182 msg = to_utf8(msg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1183
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1184 send_message_to(fjid, msg, NULL);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1185
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1186 g_free(fjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1187 g_free(msg);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1188 free_arg_lst(paramlst);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1189 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1190
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1191 // buffer_updown(updown, nblines)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1192 // updown: -1=up, +1=down
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1193 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
1194 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1195 int nblines;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1196
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1197 if (!nlines || !*nlines)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1198 nblines = 0;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1199 else
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1200 nblines = atoi(nlines);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1201
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1202 if (nblines >= 0)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1203 scr_BufferScrollUpDown(updown, nblines);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1204 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1205
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1206 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
1207 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1208 if (!arg || !*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1209 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1210 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1211 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1212
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1213 scr_BufferSearch(direction, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1214 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1215
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1216 static void buffer_date(char *date)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1217 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1218 time_t t;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1219
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1220 if (!date || !*date) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1221 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1222 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1223 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1224
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1225 strip_arg_special_chars(date);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1226
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1227 t = from_iso8601(date, 0);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1228 if (t)
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1229 scr_BufferDate(t);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1230 else
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1231 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
1232 "not correctly formatted or invalid.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1233 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1234
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1235 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
1236 {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1237 // Basically, user has typed "%arg1 arg2"
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1238 // "%50" -> arg1 = 50, arg2 null pointer
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1239 // "% 50" -> arg1 = \0, arg2 = 50
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1240
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1241 if (!*arg1 && (!arg2 || !*arg2)) { // No value
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1242 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1243 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1244 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1245
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1246 if (*arg1 && arg2 && *arg2) { // Two values
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1247 scr_LogPrint(LPRINT_NORMAL, "Wrong parameters.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1248 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1249 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1250
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1251 scr_BufferPercent(atoi((*arg1 ? arg1 : arg2)));
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1252 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1253
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1254 static void do_buffer(char *arg)
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1255 {
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1256 char **paramlst;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1257 char *subcmd;
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1258
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1259 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1260 return;
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1261
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1262 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
1263 subcmd = *paramlst;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1264 arg = *(paramlst+1);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1265
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1266 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1267 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1268 free_arg_lst(paramlst);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1269 return;
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1270 }
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1271
1138
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1272 if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_GROUP &&
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1273 strcasecmp(subcmd, "close_all")) {
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1274 scr_LogPrint(LPRINT_NORMAL, "Groups have no buffer.");
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1275 free_arg_lst(paramlst);
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1276 return;
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1277 }
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1278
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1279 if (!strcasecmp(subcmd, "top")) {
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 336
diff changeset
1280 scr_BufferTopBottom(-1);
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1281 } else if (!strcasecmp(subcmd, "bottom")) {
361
51ff319947c3 Code cleanup/optimization
Mikael Berthe <mikael@lilotux.net>
parents: 336
diff changeset
1282 scr_BufferTopBottom(1);
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1283 } else if (!strcasecmp(subcmd, "clear")) {
369
499170ed71c9 Rename some buffer commands, for homogeneity
Mikael Berthe <mikael@lilotux.net>
parents: 364
diff changeset
1284 scr_BufferClear();
1135
5d7c05932b13 Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents: 1130
diff changeset
1285 } else if (!strcasecmp(subcmd, "close")) {
5d7c05932b13 Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents: 1130
diff changeset
1286 scr_BufferPurge(1);
1138
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1287 } else if (!strcasecmp(subcmd, "close_all")) {
8ba4b1e8b42d Add command /buffer close_all
Mikael Berthe <mikael@lilotux.net>
parents: 1135
diff changeset
1288 scr_BufferPurgeAll(1);
866
b30df2ab457f Add "/buffer purge"
Mikael Berthe <mikael@lilotux.net>
parents: 865
diff changeset
1289 } else if (!strcasecmp(subcmd, "purge")) {
1135
5d7c05932b13 Add command /buffer close
Mikael Berthe <mikael@lilotux.net>
parents: 1130
diff changeset
1290 scr_BufferPurge(0);
873
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
1291 } else if (!strcasecmp(subcmd, "scroll_lock")) {
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
1292 scr_BufferScrollLock(1);
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
1293 } else if (!strcasecmp(subcmd, "scroll_unlock")) {
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
1294 scr_BufferScrollLock(0);
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
1295 } else if (!strcasecmp(subcmd, "scroll_toggle")) {
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
1296 scr_BufferScrollLock(-1);
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1297 } else if (!strcasecmp(subcmd, "up")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1298 buffer_updown(-1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1299 } else if (!strcasecmp(subcmd, "down")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1300 buffer_updown(1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1301 } else if (!strcasecmp(subcmd, "search_backward")) {
979
ea939ff047d8 Improve /buffer search_*
Mikael Berthe <mikael@lilotux.net>
parents: 978
diff changeset
1302 strip_arg_special_chars(arg);
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1303 buffer_search(-1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1304 } else if (!strcasecmp(subcmd, "search_forward")) {
979
ea939ff047d8 Improve /buffer search_*
Mikael Berthe <mikael@lilotux.net>
parents: 978
diff changeset
1305 strip_arg_special_chars(arg);
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1306 buffer_search(1, arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1307 } else if (!strcasecmp(subcmd, "date")) {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1308 buffer_date(arg);
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1309 } else if (*subcmd == '%') {
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1310 buffer_percent(subcmd+1, arg);
1226
2521efbf3b72 New (debug) subcommand, buffer list
Mikael Berthe <mikael@lilotux.net>
parents: 1221
diff changeset
1311 #ifdef DEBUG_ENABLE
2521efbf3b72 New (debug) subcommand, buffer list
Mikael Berthe <mikael@lilotux.net>
parents: 1221
diff changeset
1312 } else if (!strcasecmp(subcmd, "list")) {
2521efbf3b72 New (debug) subcommand, buffer list
Mikael Berthe <mikael@lilotux.net>
parents: 1221
diff changeset
1313 scr_BufferList();
2521efbf3b72 New (debug) subcommand, buffer list
Mikael Berthe <mikael@lilotux.net>
parents: 1221
diff changeset
1314 #endif
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1315 } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1316 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1317 }
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
1318
558
db019a5f874f Split do_buffer() and use split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 557
diff changeset
1319 free_arg_lst(paramlst);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1320 }
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1321
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1322 static void do_clear(char *arg) // Alias for "buffer clear"
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1323 {
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1324 do_buffer("clear");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1325 }
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
1326
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1327 static void do_info(char *arg)
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1328 {
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1329 gpointer bud;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1330 const char *bjid, *name;
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1331 guint type;
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1332 char *buffer;
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1333 enum subscr esub;
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1334
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1335 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1336 return;
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1337 bud = BUDDATA(current_buddy);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1338
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1339 bjid = buddy_getjid(bud);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1340 name = buddy_getname(bud);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1341 type = buddy_gettype(bud);
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1342 esub = buddy_getsubscription(bud);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1343
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1344 buffer = g_new(char, 4096);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1345
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1346 if (bjid) {
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1347 GSList *resources, *p_res;
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1348 char *bstr = "unknown";
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1349
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1350 // Enter chat mode
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1351 scr_set_chatmode(TRUE);
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1352 scr_ShowBuddyWindow();
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1353
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1354 snprintf(buffer, 4095, "jid: <%s>", bjid);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1355 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1356 if (name) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1357 snprintf(buffer, 4095, "Name: %s", name);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1358 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1359 }
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1360
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1361 if (type == ROSTER_TYPE_USER) bstr = "user";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1362 else if (type == ROSTER_TYPE_ROOM) bstr = "chatroom";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1363 else if (type == ROSTER_TYPE_AGENT) bstr = "agent";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1364 snprintf(buffer, 127, "Type: %s", bstr);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1365 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
604
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1366
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1367 if (esub == sub_both) bstr = "both";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1368 else if (esub & sub_from) bstr = "from";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1369 else if (esub & sub_to) bstr = "to";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1370 else bstr = "none";
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1371 snprintf(buffer, 64, "Subscription: %s", bstr);
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1372 if (esub & sub_pending)
2e8342168ebc "/info" shows buddy subscription
Mikael Berthe <mikael@lilotux.net>
parents: 600
diff changeset
1373 strcat(buffer, " (pending)");
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1374 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1375
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1376 resources = buddy_getresources(bud);
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1377 if (!resources && type == ROSTER_TYPE_USER) {
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1378 // No resource; display last status message, if any.
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1379 const char *rst_msg = buddy_getstatusmsg(bud, "");
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1380 if (rst_msg) {
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1381 snprintf(buffer, 4095, "Last status message: %s", rst_msg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1382 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
843
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1383 }
915a7f17474a Remember the status message when a buddy goes offline
Mikael Berthe <mikael@lilotux.net>
parents: 841
diff changeset
1384 }
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1385 for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) {
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1386 gchar rprio;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1387 enum imstatus rstatus;
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1388 const char *rst_msg;
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1389 time_t rst_time;
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1390 struct pgp_data *rpgp;
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1391
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1392 rprio = buddy_getresourceprio(bud, p_res->data);
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1393 rstatus = buddy_getstatus(bud, p_res->data);
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1394 rst_msg = buddy_getstatusmsg(bud, p_res->data);
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1395 rst_time = buddy_getstatustime(bud, p_res->data);
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1396 rpgp = buddy_resource_pgp(bud, p_res->data);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1397
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1398 snprintf(buffer, 4095, "Resource: [%c] (%d) %s", imstatus2char[rstatus],
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1399 rprio, (char*)p_res->data);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1400 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1401 if (rst_msg) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1402 snprintf(buffer, 4095, "Status message: %s", rst_msg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1403 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1404 }
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1405 if (rst_time) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1406 char tbuf[128];
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1407
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1408 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
1409 snprintf(buffer, 127, "Status timestamp: %s", tbuf);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1410 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
1411 }
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1412 #ifdef HAVE_GPGME
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1413 if (rpgp && rpgp->sign_keyid) {
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1414 snprintf(buffer, 4095, "PGP key id: %s", rpgp->sign_keyid);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1415 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1416 if (rpgp->last_sigsum) {
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1417 gpgme_sigsum_t ss = rpgp->last_sigsum;
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1418 snprintf(buffer, 4095, "Last PGP signature: %s",
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1419 (ss & GPGME_SIGSUM_GREEN ? "good":
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1420 (ss & GPGME_SIGSUM_RED ? "bad" : "unknown")));
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1421 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
1043
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1422 }
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1423 }
ebbde723614b Store contacts PGP keys
Mikael Berthe <mikael@lilotux.net>
parents: 1038
diff changeset
1424 #endif
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1425 g_free(p_res->data);
439
63562fd409a1 /info can show multiple resources
Mikael Berthe <mikael@lilotux.net>
parents: 438
diff changeset
1426 }
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1427 g_slist_free(resources);
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1428 } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1429 if (name) scr_LogPrint(LPRINT_NORMAL, "Name: %s", name);
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1430 scr_LogPrint(LPRINT_NORMAL, "Type: %s",
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1431 type == ROSTER_TYPE_GROUP ? "group" :
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1432 (type == ROSTER_TYPE_SPECIAL ? "special" : "unknown"));
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1433 }
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1434 g_free(buffer);
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1435
1020
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1436 // Tell the user if this item has an annotation.
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1437 if (type == ROSTER_TYPE_USER ||
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1438 type == ROSTER_TYPE_ROOM ||
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1439 type == ROSTER_TYPE_AGENT) {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1440 struct annotation *note = jb_get_storage_rosternotes(bjid, TRUE);
1020
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1441 if (note) {
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1442 // We do not display the note, we just tell the user.
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1443 g_free(note->text);
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
1444 g_free(note->jid);
1020
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1445 g_free(note);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1446 scr_WriteIncomingMessage(bjid, "(This item has an annotation)", 0,
1020
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1447 HBB_PREFIX_INFO);
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1448 }
60c94b697f61 Show in /info when the contact has an annotation
Mikael Berthe <mikael@lilotux.net>
parents: 1019
diff changeset
1449 }
191
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1450 }
24e6bcb589b0 [/trunk] Changeset 203 by mikael
mikael
parents: 187
diff changeset
1451
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1452 // room_names() is a variation of do_info(), for chatrooms only
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1453 static void room_names(gpointer bud, char *arg)
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1454 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1455 const char *bjid;
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1456 char *buffer;
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1457 GSList *resources, *p_res;
1162
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1458 enum { style_normal = 0, style_short, style_quiet } style = 0;
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1459
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1460 if (*arg) {
1162
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1461 if (!strcasecmp(arg, "--short"))
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1462 style = style_short;
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1463 else if (!strcasecmp(arg, "--quiet"))
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1464 style = style_quiet;
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1465 else {
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1466 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1467 return;
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1468 }
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1469 }
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1470
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1471 // Enter chat mode
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1472 scr_set_chatmode(TRUE);
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1473 scr_ShowBuddyWindow();
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
1474
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1475 bjid = buddy_getjid(bud);
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1476
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1477 buffer = g_new(char, 4096);
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
1478 strncpy(buffer, "Room members:", 127);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1479 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1480
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1481 resources = buddy_getresources(bud);
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1482 for (p_res = resources ; p_res ; p_res = g_slist_next(p_res)) {
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1483 enum imstatus rstatus;
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1484 const char *rst_msg;
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1485
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1486 rstatus = buddy_getstatus(bud, p_res->data);
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1487 rst_msg = buddy_getstatusmsg(bud, p_res->data);
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1488
1162
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1489 if (style == style_short) {
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1490 snprintf(buffer, 4095, "[%c] %s%s%s", imstatus2char[rstatus],
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1491 (char*)p_res->data,
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1492 rst_msg ? " -- " : "", rst_msg ? rst_msg : "");
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1493 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1494 } else {
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1495 // (Style "normal" or "quiet")
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1496 snprintf(buffer, 4095, "[%c] %s", imstatus2char[rstatus],
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1497 (char*)p_res->data);
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1498 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1499 if (rst_msg && style == style_normal) {
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1500 snprintf(buffer, 4095, "Status message: %s", rst_msg);
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1501 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
39b20ea22ce9 /room names: add options --short, --quiet
Mikael Berthe <mikael@lilotux.net>
parents: 1158
diff changeset
1502 }
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1503 }
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1504 g_free(p_res->data);
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1505 }
1072
2a3cfb98bd5e Fix memory leaks after calls to buddy_getresources()
Mikael Berthe <mikael@lilotux.net>
parents: 1070
diff changeset
1506 g_slist_free(resources);
504
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1507 g_free(buffer);
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1508 }
321ae11e7ddb Prettier display for "/room names"
Mikael Berthe <mikael@lilotux.net>
parents: 490
diff changeset
1509
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1510 static void move_group_member(gpointer bud, void *groupnamedata)
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1511 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1512 const char *bjid, *name, *groupname;
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1513
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1514 groupname = (char *)groupnamedata;
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1515
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1516 bjid = buddy_getjid(bud);
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1517 name = buddy_getname(bud);
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1518
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1519 jb_updatebuddy(bjid, name, *groupname ? groupname : NULL);
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1520 }
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1521
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1522 static void do_rename(char *arg)
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1523 {
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1524 gpointer bud;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1525 const char *bjid, *group;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1526 guint type;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1527 char *newname, *p;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1528 char *name_utf8;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1529
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1530 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1531 return;
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1532 bud = BUDDATA(current_buddy);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1533
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1534 bjid = buddy_getjid(bud);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1535 group = buddy_getgroupname(bud);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1536 type = buddy_gettype(bud);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1537
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1538 if (type & ROSTER_TYPE_SPECIAL) {
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1539 scr_LogPrint(LPRINT_NORMAL, "You can't rename this item.");
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1540 return;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1541 }
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1542
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1543 if (!*arg && !(type & ROSTER_TYPE_GROUP)) {
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1544 scr_LogPrint(LPRINT_NORMAL, "Please specify a new name.");
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1545 return;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1546 }
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1547
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1548 newname = g_strdup(arg);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1549 // Remove trailing space
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1550 for (p = newname; *p; p++) ;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1551 while (p > newname && *p == ' ') *p = 0;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1552
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1553 strip_arg_special_chars(newname);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1554
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1555 name_utf8 = to_utf8(newname);
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1556
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1557 if (type & ROSTER_TYPE_GROUP) {
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1558 // Rename a whole group
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1559 foreach_group_member(bud, &move_group_member, name_utf8);
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1560 // Let's jump to the previous buddy, because this group name should
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1561 // disappear when we receive the server answer.
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1562 scr_RosterUp();
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1563 } else {
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1564 // Rename a single buddy
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1565 buddy_setname(bud, name_utf8);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1566 jb_updatebuddy(bjid, name_utf8, group);
885
afdd81c2c44d Allow /rename for groups
Mikael Berthe <mikael@lilotux.net>
parents: 873
diff changeset
1567 }
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1568
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1569 g_free(name_utf8);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1570 g_free(newname);
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1571 update_roster = TRUE;
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1572 }
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
1573
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1574 static void do_move(char *arg)
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1575 {
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1576 gpointer bud;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1577 const char *bjid, *name, *oldgroupname;
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1578 guint type;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1579 char *newgroupname, *p;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1580 char *group_utf8;
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1581
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1582 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1583 return;
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1584 bud = BUDDATA(current_buddy);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1585
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1586 bjid = buddy_getjid(bud);
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1587 name = buddy_getname(bud);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1588 type = buddy_gettype(bud);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1589
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 617
diff changeset
1590 oldgroupname = buddy_getgroupname(bud);
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 617
diff changeset
1591
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1592 if (type & ROSTER_TYPE_GROUP) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1593 scr_LogPrint(LPRINT_NORMAL, "You can't move groups!");
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1594 return;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1595 }
848
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1596 if (type & ROSTER_TYPE_SPECIAL) {
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1597 scr_LogPrint(LPRINT_NORMAL, "You can't move this item.");
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1598 return;
a9161d2dc414 Introduce special buffer stuff
Mikael Berthe <mikael@lilotux.net>
parents: 847
diff changeset
1599 }
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1600
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1601 newgroupname = g_strdup(arg);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1602 // Remove trailing space
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1603 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
1604 while (p > newgroupname && *p == ' ') *p-- = 0;
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1605
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1606 strip_arg_special_chars(newgroupname);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1607
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1608 group_utf8 = to_utf8(newgroupname);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1609 if (strcmp(oldgroupname, group_utf8)) {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1610 jb_updatebuddy(bjid, name, *group_utf8 ? group_utf8 : NULL);
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 617
diff changeset
1611 scr_RosterUp();
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1612 buddy_setgroup(bud, group_utf8);
620
97dd14e22b2a Rewrite buddy_setgroup()
Mikael Berthe <mikael@lilotux.net>
parents: 617
diff changeset
1613 }
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1614
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1615 g_free(group_utf8);
210
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1616 g_free(newgroupname);
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1617 update_roster = TRUE;
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1618 }
f64818ba3503 [/trunk] Changeset 222 by mikael
mikael
parents: 208
diff changeset
1619
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1620 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
1621 {
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1622 guint assign;
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1623 gchar *option, *value;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1624 gchar *option_utf8;
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
1625
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1626 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
1627 if (!option) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1628 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
1629 return;
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1630 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1631 option_utf8 = to_utf8(option);
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1632 g_free(option);
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1633 if (!assign) { // This is a query
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1634 const char *val = settings_opt_get(option_utf8);
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1635 if (val)
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1636 scr_LogPrint(LPRINT_NORMAL, "%s = [%s]", option_utf8, val);
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1637 else
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1638 scr_LogPrint(LPRINT_NORMAL, "Option %s is not set", option_utf8);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1639 g_free(option_utf8);
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1640 return;
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1641 }
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1642 // Update the option
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1643 // Maybe some options should be protected when user is connected (server,
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1644 // username, etc.). And we should catch some options here, too
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1645 // (hide_offline_buddies for ex.)
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1646 if (!value) {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1647 settings_del(SETTINGS_TYPE_OPTION, option_utf8);
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1648 } else {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1649 gchar *value_utf8 = to_utf8(value);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1650 settings_set(SETTINGS_TYPE_OPTION, option_utf8, value_utf8);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1651 g_free(value_utf8);
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1652 g_free(value);
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1653 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1654 g_free(option_utf8);
283
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1655 }
00b2377539ac Add /set command (to get/set/unset options values)
Mikael Berthe <mikael@lilotux.net>
parents: 277
diff changeset
1656
1070
9eaacc0ad3a2 Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents: 1066
diff changeset
1657 static void dump_alias(char *k, char *v, void *param)
867
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1658 {
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1659 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, "Alias %s = %s", k, v);
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1660 }
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1661
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1662 static void do_alias(char *arg)
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1663 {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1664 guint assign;
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1665 gchar *alias, *value;
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
1666
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1667 assign = parse_assigment(arg, &alias, &value);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1668 if (!alias) {
867
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1669 settings_foreach(SETTINGS_TYPE_ALIAS, &dump_alias, NULL);
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1670 return;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1671 }
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1672 if (!assign) { // This is a query
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1673 const char *val = settings_get(SETTINGS_TYPE_ALIAS, alias);
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1674 // NOTE: LPRINT_NOTUTF8 here, see below why it isn't encoded...
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1675 if (val)
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1676 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, "%s = %s", alias, val);
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1677 else
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1678 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1679 "Alias '%s' does not exist", alias);
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1680 goto do_alias_return;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1681 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1682 // Check the alias does not conflict with a registered command
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1683 if (cmd_get(alias)) {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1684 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1685 "'%s' is a reserved word!", alias);
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1686 goto do_alias_return;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1687 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1688 // Update the alias
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1689 if (!value) {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1690 if (settings_get(SETTINGS_TYPE_ALIAS, alias)) {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1691 settings_del(SETTINGS_TYPE_ALIAS, alias);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1692 // Remove alias from the completion list
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1693 compl_del_category_word(COMPL_CMD, alias);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1694 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1695 } else {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1696 /* Add alias to the completion list, if not already in.
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1697 NOTE: We're not UTF8-encoding "alias" and "value" here because UTF-8 is
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1698 not yet supported in the UI... (and we use the values in the completion
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1699 system)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1700 */
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1701 if (!settings_get(SETTINGS_TYPE_ALIAS, alias))
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1702 compl_add_category_word(COMPL_CMD, alias);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1703 settings_set(SETTINGS_TYPE_ALIAS, alias, value);
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1704 g_free(value);
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1705 }
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1706 do_alias_return:
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1707 g_free(alias);
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1708 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
1709
1070
9eaacc0ad3a2 Use a hash for settings
Mikael Berthe <mikael@lilotux.net>
parents: 1066
diff changeset
1710 static void dump_bind(char *k, char *v, void *param)
867
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1711 {
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1712 scr_LogPrint(LPRINT_NORMAL, "Key %4s is bound to: %s", k, v);
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1713 }
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1714
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1715 static void do_bind(char *arg)
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1716 {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1717 guint assign;
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1718 gchar *k_code, *value;
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
1719
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1720 assign = parse_assigment(arg, &k_code, &value);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1721 if (!k_code) {
867
7f056c566569 Commands /alias & /bind list the key bindings and aliases
Mikael Berthe <mikael@lilotux.net>
parents: 866
diff changeset
1722 settings_foreach(SETTINGS_TYPE_BINDING, &dump_bind, NULL);
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1723 return;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1724 }
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1725 if (!assign) { // This is a query
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1726 const char *val = settings_get(SETTINGS_TYPE_BINDING, k_code);
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1727 if (val)
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1728 scr_LogPrint(LPRINT_NORMAL, "Key %s is bound to: %s", k_code, val);
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1729 else
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1730 scr_LogPrint(LPRINT_NORMAL, "Key %s is not bound.", k_code);
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1731 g_free(k_code);
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1732 return;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1733 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1734 // Update the key binding
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1735 if (!value) {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1736 settings_del(SETTINGS_TYPE_BINDING, k_code);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1737 } else {
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1738 gchar *value_utf8 = to_utf8(value);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1739 settings_set(SETTINGS_TYPE_BINDING, k_code, value_utf8);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1740 g_free(value_utf8);
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1741 g_free(value);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1742 }
1074
b2fc694a8228 Fix a few memory leaks after calls to parse_assigment()
Mikael Berthe <mikael@lilotux.net>
parents: 1073
diff changeset
1743 g_free(k_code);
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1744 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
1745
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
1746 static void do_rawxml(char *arg)
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
1747 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1748 char **paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1749 char *subcmd;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1750
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
1751 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1752 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
1753 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
1754 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
1755
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1756 paramlst = split_arg(arg, 2, 1); // subcmd, arg
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1757 subcmd = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1758 arg = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1759
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1760 if (!subcmd || !*subcmd) {
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1761 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
1762 " before using /rawxml :-)");
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1763 free_arg_lst(paramlst);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1764 return;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1765 }
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1766
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1767 if (!strcasecmp(subcmd, "send")) {
461
1d8f5b3a5f2b Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents: 454
diff changeset
1768 gchar *buffer;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1769
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1770 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1771 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1772 free_arg_lst(paramlst);
461
1d8f5b3a5f2b Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents: 454
diff changeset
1773 return;
1d8f5b3a5f2b Convert /rawxml argument to UTF8
Mikael Berthe <mikael@lilotux.net>
parents: 454
diff changeset
1774 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1775
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1776 // 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
1777 // 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
1778
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1779 buffer = to_utf8(arg);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1780 if (buffer) {
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1781 scr_LogPrint(LPRINT_NORMAL, "Sending XML string");
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1782 jb_send_raw(buffer);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1783 g_free(buffer);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1784 } else {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1785 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
1786 }
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
1787 } else {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1788 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
1789 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1790
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1791 free_arg_lst(paramlst);
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
1792 }
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
1793
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1794 // check_room_subcommand(arg, param_needed, buddy_must_be_a_room)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1795 // - Check if this is a room, if buddy_must_be_a_room is not null
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1796 // - Check there is at least 1 parameter, if param_needed is true
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1797 // - Return null if one of the checks fails, or a pointer to the first
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1798 // non-space character.
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1799 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
1800 gpointer buddy_must_be_a_room)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1801 {
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1802 if (buddy_must_be_a_room &&
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1803 !(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
1804 scr_LogPrint(LPRINT_NORMAL, "This isn't a conference room.");
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1805 return NULL;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1806 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1807
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1808 if (param_needed) {
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1809 if (!arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1810 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1811 return NULL;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1812 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1813 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1814
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1815 if (arg)
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1816 return arg;
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1817 else
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1818 return "";
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1819 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1820
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1821 static void room_join(gpointer bud, char *arg)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1822 {
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1823 char **paramlst;
1033
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1824 char *roomname, *nick, *pass;
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1825 char *roomname_tmp = NULL;
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1826 char *pass_utf8;
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1827
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1828 paramlst = split_arg(arg, 3, 0); // roomid, nickname, password
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1829 roomname = *paramlst;
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1830 nick = *(paramlst+1);
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1831 pass = *(paramlst+2);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1832
1033
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1833 if (!roomname)
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1834 nick = NULL;
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1835 if (!nick)
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1836 pass = NULL;
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1837
841
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1838 if (!roomname || !strcmp(roomname, ".")) {
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1839 // If the current_buddy is recognized as a room, the room name
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1840 // can be omitted (or "." can be used).
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1841 if (!bud || !(buddy_gettype(bud) & ROSTER_TYPE_ROOM)) {
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1842 scr_LogPrint(LPRINT_NORMAL, "Please specify a room name.");
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1843 free_arg_lst(paramlst);
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1844 return;
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1845 }
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1846 roomname = (char*)buddy_getjid(bud);
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
1847 } else if (strchr(roomname, '/')) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1848 scr_LogPrint(LPRINT_NORMAL, "Invalid room name.");
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1849 free_arg_lst(paramlst);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1850 return;
1033
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1851 } else {
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1852 // The room id has been specified. Let's convert it and use it.
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1853 roomname_tmp = to_utf8(roomname);
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1854 mc_strtolower(roomname_tmp);
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1855 roomname = roomname_tmp;
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1856 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1857
659
e61aa455c61b MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents: 653
diff changeset
1858 // If no nickname is provided with the /join command,
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
1859 // we try to get a default nickname.
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
1860 if (!nick || !*nick)
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
1861 nick = default_muc_nickname();
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
1862 else
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
1863 nick = to_utf8(nick);
659
e61aa455c61b MUC: Add "nickname" option variable
Mikael Berthe <mikael@lilotux.net>
parents: 653
diff changeset
1864 // 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
1865 if (!nick || !*nick) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1866 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname.");
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
1867 g_free(nick);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1868 free_arg_lst(paramlst);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1869 return;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1870 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1871
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1872 pass_utf8 = to_utf8(pass);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1873
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1874 jb_room_join(roomname, nick, pass_utf8);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1875
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1876 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
1877
1033
056364952b0d [BP-7f216b904315] Fix a potential double UTF-8 encoding
Mikael Berthe <mikael@lilotux.net>
parents: 960
diff changeset
1878 g_free(roomname_tmp);
1004
b57a01ffeed6 Use existing conference bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1003
diff changeset
1879 g_free(nick);
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
1880 g_free(pass_utf8);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1881 buddylist_build();
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1882 update_roster = TRUE;
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1883 free_arg_lst(paramlst);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1884 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1885
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1886 static void room_invite(gpointer bud, char *arg)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1887 {
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1888 char **paramlst;
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1889 const gchar *roomname;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1890 char* fjid;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1891 gchar *reason_utf8;
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1892
570
29806b0fe830 Some parsing improvements
Mikael Berthe <mikael@lilotux.net>
parents: 568
diff changeset
1893 paramlst = split_arg(arg, 2, 1); // jid, [reason]
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1894 fjid = *paramlst;
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1895 arg = *(paramlst+1);
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1896 // An empty reason is no reason...
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1897 if (arg && !*arg)
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1898 arg = NULL;
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1899
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1900 if (!fjid || !*fjid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1901 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
1902 free_arg_lst(paramlst);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1903 return;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1904 }
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1905
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1906 roomname = buddy_getjid(bud);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1907 reason_utf8 = to_utf8(arg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1908 jb_room_invite(roomname, fjid, reason_utf8);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1909 scr_LogPrint(LPRINT_LOGNORM, "Invitation sent to <%s>.", fjid);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
1910 g_free(reason_utf8);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
1911 free_arg_lst(paramlst);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1912 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
1913
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1914 static void room_affil(gpointer bud, char *arg)
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1915 {
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1916 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1917 gchar *fjid, *rolename;
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1918 struct role_affil ra;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1919 const char *roomid = buddy_getjid(bud);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1920
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1921 paramlst = split_arg(arg, 3, 1); // jid, new_affil, [reason]
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1922 fjid = *paramlst;
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1923 rolename = *(paramlst+1);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1924 arg = *(paramlst+2);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1925
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1926 if (!fjid || !*fjid || !rolename || !*rolename) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1927 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
1928 free_arg_lst(paramlst);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1929 return;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1930 }
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1931
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1932 ra.type = type_affil;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1933 ra.val.affil = affil_none;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1934 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
1935 if (!strcasecmp(rolename, straffil[ra.val.affil]))
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1936 break;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1937
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1938 if (ra.val.affil < imaffiliation_size) {
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1939 gchar *jid_utf8, *reason_utf8;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1940 jid_utf8 = to_utf8(fjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1941 reason_utf8 = to_utf8(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1942 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
1943 g_free(jid_utf8);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
1944 g_free(reason_utf8);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1945 } else
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1946 scr_LogPrint(LPRINT_NORMAL, "Wrong affiliation parameter.");
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1947
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1948 free_arg_lst(paramlst);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1949 }
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1950
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1951 static void room_role(gpointer bud, char *arg)
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1952 {
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1953 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1954 gchar *fjid, *rolename;
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1955 struct role_affil ra;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1956 const char *roomid = buddy_getjid(bud);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1957
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1958 paramlst = split_arg(arg, 3, 1); // jid, new_role, [reason]
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1959 fjid = *paramlst;
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1960 rolename = *(paramlst+1);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1961 arg = *(paramlst+2);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1962
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1963 if (!fjid || !*fjid || !rolename || !*rolename) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1964 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
1965 free_arg_lst(paramlst);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1966 return;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1967 }
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1968
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1969 ra.type = type_role;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1970 ra.val.role = role_none;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1971 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
1972 if (!strcasecmp(rolename, strrole[ra.val.role]))
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1973 break;
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1974
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1975 if (ra.val.role < imrole_size) {
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1976 gchar *jid_utf8, *reason_utf8;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1977 jid_utf8 = to_utf8(fjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1978 reason_utf8 = to_utf8(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1979 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
1980 g_free(jid_utf8);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
1981 g_free(reason_utf8);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1982 } else
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1983 scr_LogPrint(LPRINT_NORMAL, "Wrong role parameter.");
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1984
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1985 free_arg_lst(paramlst);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1986 }
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1987
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
1988
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
1989 // The expected argument is a Jabber id
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
1990 static void room_ban(gpointer bud, char *arg)
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
1991 {
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
1992 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1993 gchar *fjid;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1994 gchar *jid_utf8, *reason_utf8;
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
1995 struct role_affil ra;
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
1996 const char *roomid = buddy_getjid(bud);
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
1997
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
1998 paramlst = split_arg(arg, 2, 1); // jid, [reason]
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1999 fjid = *paramlst;
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2000 arg = *(paramlst+1);
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2001
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2002 if (!fjid || !*fjid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2003 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2004 free_arg_lst(paramlst);
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2005 return;
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2006 }
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2007
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
2008 ra.type = type_affil;
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
2009 ra.val.affil = affil_outcast;
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
2010
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2011 jid_utf8 = to_utf8(fjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2012 reason_utf8 = to_utf8(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2013 jb_room_setattrib(roomid, jid_utf8, NULL, ra, reason_utf8);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
2014 g_free(jid_utf8);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
2015 g_free(reason_utf8);
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2016
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2017 free_arg_lst(paramlst);
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2018 }
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2019
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2020 // The expected argument is a nickname
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2021 static void room_kick(gpointer bud, char *arg)
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2022 {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2023 char **paramlst;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2024 gchar *nick;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2025 gchar *nick_utf8, *reason_utf8;
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
2026 struct role_affil ra;
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2027 const char *roomid = buddy_getjid(bud);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2028
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2029 paramlst = split_arg(arg, 2, 1); // nickname, [reason]
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2030 nick = *paramlst;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2031 arg = *(paramlst+1);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2032
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2033 if (!nick || !*nick) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2034 scr_LogPrint(LPRINT_NORMAL, "Please specify a nickname.");
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2035 free_arg_lst(paramlst);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2036 return;
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2037 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2038
584
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
2039 ra.type = type_role;
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
2040 ra.val.affil = role_none;
414fbf558f1e jb_room_setattrib()
Mikael Berthe <mikael@lilotux.net>
parents: 580
diff changeset
2041
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2042 nick_utf8 = to_utf8(nick);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2043 reason_utf8 = to_utf8(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2044 jb_room_setattrib(roomid, NULL, nick_utf8, ra, reason_utf8);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
2045 g_free(nick_utf8);
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
2046 g_free(reason_utf8);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2047
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2048 free_arg_lst(paramlst);
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2049 }
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2050
1158
c30c315dc447 XEP-0146 support (Remote Controlling Clients)
misc@mandriva.org
parents: 1138
diff changeset
2051 void room_leave(gpointer bud, char *arg)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2052 {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2053 gchar *roomid, *desc;
650
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2054 const char *nickname;
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2055
650
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2056 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
2057 if (!nickname) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2058 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
2059 return;
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2060 }
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2061
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2062 roomid = g_strdup_printf("%s/%s", buddy_getjid(bud), nickname);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2063 desc = to_utf8(arg);
1050
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
2064 jb_setstatus(offline, roomid, desc, TRUE);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2065 g_free(desc);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2066 g_free(roomid);
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2067 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2068
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2069 static void room_nick(gpointer bud, char *arg)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2070 {
650
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2071 if (!buddy_getinsideroom(bud)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2072 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
2073 return;
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2074 }
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2075
565
89c347b3e4c1 MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents: 558
diff changeset
2076 if (!arg || !*arg) {
89c347b3e4c1 MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents: 558
diff changeset
2077 const char *nick = buddy_getnickname(bud);
89c347b3e4c1 MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents: 558
diff changeset
2078 if (nick)
89c347b3e4c1 MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents: 558
diff changeset
2079 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
2080 else
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2081 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
2082 } else {
900
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2083 gchar *roomname, *roomname_tmp, *nick;
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2084 roomname_tmp = g_strdup(buddy_getjid(bud));
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2085 mc_strtolower(roomname_tmp);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2086 roomname = to_utf8(roomname_tmp);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2087 g_free(roomname_tmp);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2088 nick = to_utf8(arg);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2089
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2090 jb_room_join(roomname, nick, NULL);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2091 g_free(roomname);
b41684465283 MUC: join password-protected room
Mikael Berthe <mikael@lilotux.net>
parents: 885
diff changeset
2092 g_free(nick);
565
89c347b3e4c1 MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents: 558
diff changeset
2093 }
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2094 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2095
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2096 static void room_privmsg(gpointer bud, char *arg)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2097 {
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2098 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2099 gchar *nick, *cmdline;
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2100
1100
2bef748356de Do not strip quotes in /room privmsg
Mikael Berthe <mikael@lilotux.net>
parents: 1086
diff changeset
2101 paramlst = split_arg(arg, 2, 1); // nickname, message
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2102 nick = *paramlst;
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2103 arg = *(paramlst+1);
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2104
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2105 if (!nick || !*nick || !arg || !*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2106 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2107 "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
2108 free_arg_lst(paramlst);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2109 return;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2110 }
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2111
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2112 cmdline = g_strdup_printf("%s/%s %s", buddy_getjid(bud), nick, arg);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2113 do_say_to(cmdline);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2114 g_free(cmdline);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2115 free_arg_lst(paramlst);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2116 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2117
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2118 static void room_remove(gpointer bud, char *arg)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2119 {
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2120 if (*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2121 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
2122 "the currently-selected room will be removed.");
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2123 return;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2124 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2125
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2126 // 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
2127 if (buddy_getinsideroom(bud)) {
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2128 scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!");
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2129 return;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2130 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2131 // Delete the room
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2132 roster_del_user(buddy_getjid(bud));
865
cee8d6be04e1 Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents: 861
diff changeset
2133 scr_UpdateBuddyWindow();
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2134 buddylist_build();
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2135 update_roster = TRUE;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2136 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2137
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2138 static void room_topic(gpointer bud, char *arg)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2139 {
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2140 gchar *msg;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2141
650
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2142 if (!buddy_getinsideroom(bud)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2143 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
2144 return;
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2145 }
c2d50b97ced4 MUC: /room {leave,nick,topic} can only be used when inside a room
Mikael Berthe <mikael@lilotux.net>
parents: 647
diff changeset
2146
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2147 // If no parameter is given, display the current topic
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2148 if (!*arg) {
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2149 const char *topic = buddy_gettopic(bud);
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2150 if (topic)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2151 scr_LogPrint(LPRINT_NORMAL, "Topic: %s", topic);
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2152 else
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2153 scr_LogPrint(LPRINT_NORMAL, "No topic has been set.");
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2154 return;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2155 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2156
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2157 arg = to_utf8(arg);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2158 // Set the topic
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
2159 msg = g_strdup_printf("%s has set the topic to: %s", mkcmdstr("me"), arg);
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
2160 jb_send_msg(buddy_getjid(bud), msg, ROSTER_TYPE_ROOM, arg, NULL, NULL);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2161 g_free(arg);
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2162 g_free(msg);
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2163 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2164
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2165 static void room_destroy(gpointer bud, char *arg)
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2166 {
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2167 gchar *msg;
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2168
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2169 if (arg && *arg)
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2170 msg = to_utf8(arg);
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2171 else
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2172 msg = NULL;
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2173
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2174 jb_room_destroy(buddy_getjid(bud), NULL, msg);
774
46304b773a44 Remove useless checks before g_free() calls
Mikael Berthe <mikael@lilotux.net>
parents: 772
diff changeset
2175 g_free(msg);
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2176 }
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2177
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2178 static void room_unlock(gpointer bud, char *arg)
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2179 {
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2180 if (*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2181 scr_LogPrint(LPRINT_NORMAL, "Unknown parameter.");
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2182 return;
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2183 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2184
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2185 jb_room_unlock(buddy_getjid(bud));
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2186 }
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2187
960
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2188 // room_whois(..)
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2189 // If interactive is TRUE, chatmode can be enabled.
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2190 void room_whois(gpointer bud, char *arg, guint interactive)
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2191 {
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2192 char **paramlst;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2193 gchar *nick, *buffer;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2194 const char *bjid, *realjid;
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2195 const char *rst_msg;
575
1b8e024c3a10 Improve /room whois
Mikael Berthe <mikael@lilotux.net>
parents: 572
diff changeset
2196 gchar rprio;
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2197 enum imstatus rstatus;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2198 enum imrole role;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2199 enum imaffiliation affil;
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2200 time_t rst_time;
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2201
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2202 paramlst = split_arg(arg, 1, 0); // nickname
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2203 nick = *paramlst;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2204
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2205 if (!nick || !*nick) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2206 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
2207 free_arg_lst(paramlst);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2208 return;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2209 }
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2210
791
6c9e8fb69965 Fix "/room whois" with UTF-8 nickname
Mikael Berthe <mikael@lilotux.net>
parents: 777
diff changeset
2211 nick = to_utf8(nick);
6c9e8fb69965 Fix "/room whois" with UTF-8 nickname
Mikael Berthe <mikael@lilotux.net>
parents: 777
diff changeset
2212
960
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2213 if (interactive) {
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2214 // Enter chat mode
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2215 scr_set_chatmode(TRUE);
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2216 scr_ShowBuddyWindow();
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2217 }
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
2218
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2219 bjid = buddy_getjid(bud);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2220 rstatus = buddy_getstatus(bud, nick);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2221
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2222 if (rstatus == offline) {
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2223 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
2224 free_arg_lst(paramlst);
791
6c9e8fb69965 Fix "/room whois" with UTF-8 nickname
Mikael Berthe <mikael@lilotux.net>
parents: 777
diff changeset
2225 g_free(nick);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2226 return;
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2227 }
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2228
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2229 rst_time = buddy_getstatustime(bud, nick);
575
1b8e024c3a10 Improve /room whois
Mikael Berthe <mikael@lilotux.net>
parents: 572
diff changeset
2230 rprio = buddy_getresourceprio(bud, nick);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2231 rst_msg = buddy_getstatusmsg(bud, nick);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2232 if (!rst_msg) rst_msg = "";
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2233
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2234 role = buddy_getrole(bud, nick);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2235 affil = buddy_getaffil(bud, nick);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2236 realjid = buddy_getrjid(bud, nick);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2237
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
2238 buffer = g_new(char, 4096);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2239
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
2240 snprintf(buffer, 4095, "Whois [%s]", nick);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2241 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_INFO);
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
2242 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
2243 rst_msg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2244 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2245
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2246 if (rst_time) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
2247 char tbuf[128];
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2248
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2249 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
2250 snprintf(buffer, 127, "Timestamp: %s", tbuf);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2251 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2252 }
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2253
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2254 if (realjid) {
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
2255 snprintf(buffer, 4095, "JID : <%s>", realjid);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2256 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2257 }
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2258
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2259 snprintf(buffer, 4095, "Role : %s", strrole[role]);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2260 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
2261 snprintf(buffer, 4095, "Affiliat.: %s", straffil[affil]);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2262 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
626
b75f4105ce32 Use a larger buffer for commands like /info
Mikael Berthe <mikael@lilotux.net>
parents: 625
diff changeset
2263 snprintf(buffer, 4095, "Priority : %d", rprio);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2264 scr_WriteIncomingMessage(bjid, buffer, 0, HBB_PREFIX_NONE);
625
028c01940490 Show presence timestamps in "/info" and "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 622
diff changeset
2265
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2266 scr_WriteIncomingMessage(bjid, "End of WHOIS", 0, HBB_PREFIX_INFO);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2267
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2268 g_free(buffer);
791
6c9e8fb69965 Fix "/room whois" with UTF-8 nickname
Mikael Berthe <mikael@lilotux.net>
parents: 777
diff changeset
2269 g_free(nick);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2270 free_arg_lst(paramlst);
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2271 }
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2272
1009
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2273 static void room_bookmark(gpointer bud, char *arg)
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2274 {
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2275 const char *roomid;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2276 const char *name = NULL, *nick = NULL;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2277 enum { bm_add = 0, bm_del = 1 } action = 0;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2278 int autojoin = 0;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2279
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2280 if (arg && *arg) {
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2281 // /room bookmark [add|del] [[+|-]autojoin]
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2282 char **paramlst;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2283 char **pp;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2284
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2285 paramlst = split_arg(arg, 2, 0); // At most 2 parameters
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2286 for (pp = paramlst; *pp; pp++) {
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2287 if (!strcasecmp(*pp, "add"))
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2288 action = bm_add;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2289 else if (!strcasecmp(*pp, "del"))
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2290 action = bm_del;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2291 else if (!strcasecmp(*pp, "-autojoin"))
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2292 autojoin = 0;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2293 else if (!strcasecmp(*pp, "+autojoin") || !strcasecmp(*pp, "autojoin"))
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2294 autojoin = 1;
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2295 }
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2296 free_arg_lst(paramlst);
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2297 }
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2298
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2299 roomid = buddy_getjid(bud);
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2300
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2301 if (action == bm_add) {
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2302 name = buddy_getname(bud);
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2303 nick = buddy_getnickname(bud);
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2304 }
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2305
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2306 jb_set_storage_bookmark(roomid, name, nick, NULL, autojoin);
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2307 }
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2308
1163
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2309 static void display_all_bookmarks(void)
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2310 {
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2311 GSList *bm, *bmp;
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2312 GString *sbuf;
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2313
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2314 bm = jb_get_all_storage_bookmarks();
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2315
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2316 if (!bm)
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2317 return;
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2318
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2319 sbuf = g_string_new("");
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2320
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2321 scr_WriteIncomingMessage(NULL, "List of MUC bookmarks:", 0, HBB_PREFIX_INFO);
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2322
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2323 for (bmp = bm; bmp; bmp = g_slist_next(bmp)) {
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2324 g_string_printf(sbuf, "<%s>", (char*)bmp->data);
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2325 scr_WriteIncomingMessage(NULL, sbuf->str, 0, HBB_PREFIX_NONE);
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2326 }
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2327
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2328 scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE);
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2329 update_roster = TRUE;
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2330 g_string_free(sbuf, TRUE);
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2331 g_slist_free(bm);
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2332 }
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2333
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2334
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2335 static void do_room(char *arg)
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2336 {
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2337 char **paramlst;
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2338 char *subcmd;
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2339 gpointer bud;
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2340
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
2341 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2342 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
2343 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
2344 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
2345
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2346 paramlst = split_arg(arg, 2, 1); // subcmd, arg
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2347 subcmd = *paramlst;
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2348 arg = *(paramlst+1);
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2349
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2350 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2351 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2352 free_arg_lst(paramlst);
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2353 return;
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2354 }
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2355
831
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2356 if (current_buddy) {
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2357 bud = BUDDATA(current_buddy);
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2358 } else {
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2359 if (strcasecmp(subcmd, "join")) {
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2360 free_arg_lst(paramlst);
831
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2361 return;
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2362 }
831
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2363 // "room join" is a special case, we don't need to have a valid
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2364 // current_buddy.
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2365 bud = NULL;
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2366 }
dd865cc57aa2 Fix joining a room when the buddylist is empty
Mikael Berthe <mikael@lilotux.net>
parents: 820
diff changeset
2367
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2368 if (!strcasecmp(subcmd, "join")) {
841
f8c0447beec2 Allow "/room join . [nick]" if the current item is a MUC room
Mikael Berthe <mikael@lilotux.net>
parents: 840
diff changeset
2369 if ((arg = check_room_subcommand(arg, FALSE, NULL)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2370 room_join(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2371 } else if (!strcasecmp(subcmd, "invite")) {
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2372 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2373 room_invite(bud, arg);
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
2374 } else if (!strcasecmp(subcmd, "affil")) {
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
2375 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
2376 room_affil(bud, arg);
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
2377 } else if (!strcasecmp(subcmd, "role")) {
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
2378 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
2379 room_role(bud, arg);
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2380 } else if (!strcasecmp(subcmd, "ban")) {
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2381 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL)
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
2382 room_ban(bud, arg);
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2383 } else if (!strcasecmp(subcmd, "kick")) {
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2384 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL)
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
2385 room_kick(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2386 } else if (!strcasecmp(subcmd, "leave")) {
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2387 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2388 room_leave(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2389 } else if (!strcasecmp(subcmd, "names")) {
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2390 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2391 room_names(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2392 } else if (!strcasecmp(subcmd, "nick")) {
565
89c347b3e4c1 MUC: Make "/room nick" display the current nickname
Mikael Berthe <mikael@lilotux.net>
parents: 558
diff changeset
2393 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2394 room_nick(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2395 } else if (!strcasecmp(subcmd, "privmsg")) {
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2396 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2397 room_privmsg(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2398 } else if (!strcasecmp(subcmd, "remove")) {
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2399 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2400 room_remove(bud, arg);
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2401 } else if (!strcasecmp(subcmd, "destroy")) {
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2402 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
2403 room_destroy(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2404 } else if (!strcasecmp(subcmd, "unlock")) {
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2405 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2406 room_unlock(bud, arg);
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2407 } else if (!strcasecmp(subcmd, "topic")) {
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2408 if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
552
ba5271b49f21 Split do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 549
diff changeset
2409 room_topic(bud, arg);
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2410 } else if (!strcasecmp(subcmd, "whois")) {
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
2411 if ((arg = check_room_subcommand(arg, TRUE, bud)) != NULL)
960
90ff94f0fbbb Auto-whois shouldn't enable chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 958
diff changeset
2412 room_whois(bud, arg, TRUE);
1009
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2413 } else if (!strcasecmp(subcmd, "bookmark")) {
1163
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2414 if (!arg && !buddy_getjid(BUDDATA(current_buddy)) &&
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2415 buddy_gettype(BUDDATA(current_buddy)) == ROSTER_TYPE_SPECIAL)
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2416 display_all_bookmarks();
2913310a7be6 Make /roster bookmark in the status buffer show all bookmarks
Mikael Berthe <mikael@lilotux.net>
parents: 1162
diff changeset
2417 else if ((arg = check_room_subcommand(arg, FALSE, bud)) != NULL)
1009
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
2418 room_bookmark(bud, arg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2419 } else {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2420 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2421 }
554
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2422
2424bbf0a6db Some more work on do_room()
Mikael Berthe <mikael@lilotux.net>
parents: 552
diff changeset
2423 free_arg_lst(paramlst);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2424 }
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
2425
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2426 static void do_authorization(char *arg)
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2427 {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2428 char **paramlst;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2429 char *subcmd;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2430 char *jid_utf8;
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2431
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2432 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2433 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2434 return;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2435 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2436
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2437 paramlst = split_arg(arg, 2, 0); // subcmd, [jid]
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2438 subcmd = *paramlst;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2439 arg = *(paramlst+1);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2440
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2441 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2442 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2443 goto do_authorization_return;
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2444 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2445
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2446 // Use the provided jid, if it looks valid
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2447 if (arg) {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2448 if (!*arg) {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2449 // If no jid is provided, we use the current selected buddy
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2450 arg = NULL;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2451 } else {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2452 if (check_jid_syntax(arg)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
2453 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
2454 "<%s> is not a valid Jabber ID.", arg);
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2455 goto do_authorization_return;
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2456 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2457 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2458 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2459
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2460 if (!arg) { // Use the current selected buddy's jid
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2461 gpointer bud;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2462 guint type;
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2463
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2464 if (!current_buddy)
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2465 goto do_authorization_return;
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2466 bud = BUDDATA(current_buddy);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2467
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2468 jid_utf8 = arg = (char*)buddy_getjid(bud);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2469 type = buddy_gettype(bud);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2470
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2471 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
2472 scr_LogPrint(LPRINT_NORMAL, "Invalid buddy.");
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2473 goto do_authorization_return;
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2474 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2475 } else {
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2476 jid_utf8 = to_utf8(arg);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2477 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2478
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2479 if (!strcasecmp(subcmd, "allow")) {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2480 jb_subscr_send_auth(jid_utf8);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2481 scr_LogPrint(LPRINT_LOGNORM,
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2482 "<%s> is now allowed to receive your presence updates.",
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2483 jid_utf8);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2484 } else if (!strcasecmp(subcmd, "cancel")) {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2485 jb_subscr_cancel_auth(jid_utf8);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2486 scr_LogPrint(LPRINT_LOGNORM,
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
2487 "<%s> will no longer receive your presence updates.",
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2488 jid_utf8);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2489 } else if (!strcasecmp(subcmd, "request")) {
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2490 jb_subscr_request_auth(jid_utf8);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2491 scr_LogPrint(LPRINT_LOGNORM,
957
82aaa7afbd03 Cosmetic changes
Mikael Berthe <mikael@lilotux.net>
parents: 954
diff changeset
2492 "Sent presence notification request to <%s>.", jid_utf8);
835
6a732d2ad4b4 Add "/authorization request_unsubscribe"
Mikael Berthe <mikael@lilotux.net>
parents: 831
diff changeset
2493 } else if (!strcasecmp(subcmd, "request_unsubscribe")) {
6a732d2ad4b4 Add "/authorization request_unsubscribe"
Mikael Berthe <mikael@lilotux.net>
parents: 831
diff changeset
2494 jb_subscr_request_cancel(jid_utf8);
6a732d2ad4b4 Add "/authorization request_unsubscribe"
Mikael Berthe <mikael@lilotux.net>
parents: 831
diff changeset
2495 scr_LogPrint(LPRINT_LOGNORM,
957
82aaa7afbd03 Cosmetic changes
Mikael Berthe <mikael@lilotux.net>
parents: 954
diff changeset
2496 "Sent presence notification unsubscription request to <%s>.",
835
6a732d2ad4b4 Add "/authorization request_unsubscribe"
Mikael Berthe <mikael@lilotux.net>
parents: 831
diff changeset
2497 jid_utf8);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2498 } else {
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2499 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2500 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2501
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2502 // Only free jid_utf8 if it has been allocated, i.e. if != arg.
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2503 if (jid_utf8 && jid_utf8 != arg)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2504 g_free(jid_utf8);
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
2505 do_authorization_return:
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2506 free_arg_lst(paramlst);
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2507 }
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
2508
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
2509 static void do_version(char *arg)
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
2510 {
777
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
2511 gchar *ver = mcabber_version();
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
2512 scr_LogPrint(LPRINT_NORMAL, "This is mcabber version %s.", ver);
e6d42f239541 "/version" shows Mercurial changeset (if there's one)
Mikael Berthe <mikael@lilotux.net>
parents: 774
diff changeset
2513 g_free(ver);
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
2514 }
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
2515
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2516 static void do_request(char *arg)
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2517 {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2518 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2519 char *fjid, *type;
740
1877838d3c27 Kill two gcc warnings
Mikael Berthe <mikael@lilotux.net>
parents: 707
diff changeset
2520 enum iqreq_type numtype = iqreq_none;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2521 char *jid_utf8 = NULL;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2522
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2523 paramlst = split_arg(arg, 2, 0); // type, jid
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2524 type = *paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2525 fjid = *(paramlst+1);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2526
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2527 if (type) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2528 // Quick check...
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2529 if (!strcasecmp(type, "version"))
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2530 numtype = iqreq_version;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2531 else if (!strcasecmp(type, "time"))
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2532 numtype = iqreq_time;
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
2533 else if (!strcasecmp(type, "last"))
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
2534 numtype = iqreq_last;
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
2535 else if (!strcasecmp(type, "vcard"))
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
2536 numtype = iqreq_vcard;
694
6d6fdaf846ed Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
2537 else if (!strcasecmp(type, "show_list")) {
6d6fdaf846ed Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
2538 // Undocumented command, for debugging purposes only
6d6fdaf846ed Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
2539 jb_iqs_display_list();
6d6fdaf846ed Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
2540 free_arg_lst(paramlst);
6d6fdaf846ed Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
2541 return;
6d6fdaf846ed Add "/request show_list"
Mikael Berthe <mikael@lilotux.net>
parents: 693
diff changeset
2542 }
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2543 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2544
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2545 if (!type || !numtype) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2546 scr_LogPrint(LPRINT_NORMAL,
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
2547 "Please specify a query type (version, time...).");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2548 free_arg_lst(paramlst);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2549 return;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2550 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2551
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2552 // Allow special jid "" or "." (current buddy)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2553 if (fjid && (!*fjid || !strcmp(fjid, ".")))
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2554 fjid = NULL;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2555
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2556 if (fjid) {
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2557 // The JID has been specified. Quick check...
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2558 if (check_jid_syntax(fjid)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
2559 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
2560 "<%s> is not a valid Jabber ID.", fjid);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2561 fjid = NULL;
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2562 } else {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2563 // Convert jid to lowercase
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2564 char *p;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2565 for (p = fjid; *p && *p != JID_RESOURCE_SEPARATOR; p++)
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2566 *p = tolower(*p);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2567 fjid = jid_utf8 = to_utf8(fjid);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2568 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2569 } else {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2570 // Add the current buddy
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2571 if (current_buddy)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2572 fjid = (char*)buddy_getjid(BUDDATA(current_buddy));
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2573 if (!fjid)
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2574 scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID.");
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2575 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2576
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2577 if (fjid) {
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2578 switch (numtype) {
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2579 case iqreq_version:
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2580 case iqreq_time:
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
2581 case iqreq_last:
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
2582 case iqreq_vcard:
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
2583 jb_request(fjid, numtype);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2584 break;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2585 default:
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2586 break;
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2587 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2588 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
2589 g_free(jid_utf8);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2590 free_arg_lst(paramlst);
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2591 }
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
2592
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2593 static void do_event(char *arg)
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2594 {
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2595 char **paramlst;
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2596 char *evid, *subcmd;
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2597 int action = -1;
820
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2598 GSList *evidlst;
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2599
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2600 paramlst = split_arg(arg, 2, 0); // id, subcmd
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2601 evid = *paramlst;
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2602 subcmd = *(paramlst+1);
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2603
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2604 if (!evid || !subcmd) {
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2605 // Special case: /event list
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2606 if (evid && !strcasecmp(evid, "list"))
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2607 evs_display_list();
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2608 else
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2609 scr_LogPrint(LPRINT_NORMAL,
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2610 "Missing parameter. Usage: /event num action");
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2611 free_arg_lst(paramlst);
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2612 return;
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2613 }
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2614
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2615 if (!strcasecmp(subcmd, "reject"))
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2616 action = 0;
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2617 else if (!strcasecmp(subcmd, "accept"))
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2618 action = 1;
755
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2619 else if (!strcasecmp(subcmd, "ignore"))
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2620 action = 2;
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2621
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2622 if (action == -1) {
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2623 scr_LogPrint(LPRINT_NORMAL, "Wrong action parameter.");
755
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2624 } else if (action >= 0 && action <= 2) {
820
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2625 GSList *p;
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2626
755
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2627 if (action == 2) {
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2628 action = EVS_CONTEXT_CANCEL;
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2629 } else {
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2630 action += EVS_CONTEXT_USER;
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
2631 }
820
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2632
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2633 if (!strcmp(evid, "*")) {
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2634 // Use completion list
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2635 evidlst = evs_geteventslist(FALSE);
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2636 } else {
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2637 // Let's create a slist with the provided event id
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2638 evidlst = g_slist_append(NULL, g_strdup(evid));
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2639 }
820
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2640 for (p = evidlst; p; p = g_slist_next(p)) {
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2641 if (evs_callback(p->data, action) == -1) {
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2642 scr_LogPrint(LPRINT_NORMAL, "Event %s not found.", p->data);
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2643 }
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2644 g_free(p->data);
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2645 }
80bd7f49075f Allow '*' in /event command
Mikael Berthe <mikael@lilotux.net>
parents: 807
diff changeset
2646 g_slist_free(evidlst);
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2647 }
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2648
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2649 free_arg_lst(paramlst);
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2650 }
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
2651
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2652 static void do_pgp(char *arg)
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2653 {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2654 char **paramlst;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2655 char *fjid, *subcmd, *keyid;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2656 enum {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2657 pgp_none,
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2658 pgp_enable,
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2659 pgp_disable,
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2660 pgp_setkey,
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2661 pgp_force,
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2662 pgp_info
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2663 } op = 0;
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2664 int force = FALSE;
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2665
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2666 paramlst = split_arg(arg, 3, 0); // subcmd, jid, [key]
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2667 subcmd = *paramlst;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2668 fjid = *(paramlst+1);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2669 keyid = *(paramlst+2);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2670
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2671 if (!subcmd)
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2672 fjid = NULL;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2673 if (!fjid)
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2674 keyid = NULL;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2675
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2676 if (subcmd) {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2677 if (!strcasecmp(subcmd, "enable"))
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2678 op = pgp_enable;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2679 else if (!strcasecmp(subcmd, "disable"))
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2680 op = pgp_disable;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2681 else if (!strcasecmp(subcmd, "setkey"))
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2682 op = pgp_setkey;
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2683 else if ((!strcasecmp(subcmd, "force")) ||
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2684 (!strcasecmp(subcmd, "+force"))) {
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2685 op = pgp_force;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2686 force = TRUE;
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2687 } else if (!strcasecmp(subcmd, "-force"))
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2688 op = pgp_force;
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2689 else if (!strcasecmp(subcmd, "info"))
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2690 op = pgp_info;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2691 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2692
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2693 if (!op) {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2694 scr_LogPrint(LPRINT_NORMAL, "Unrecognized or missing parameter!");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2695 free_arg_lst(paramlst);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2696 return;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2697 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2698
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2699 // Allow special jid "" or "." (current buddy)
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2700 if (fjid && (!*fjid || !strcmp(fjid, ".")))
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2701 fjid = NULL;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2702
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2703 if (fjid) {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2704 // The JID has been specified. Quick check...
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2705 if (check_jid_syntax(fjid) || !strchr(fjid, '@')) {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2706 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2707 "<%s> is not a valid Jabber ID.", fjid);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2708 fjid = NULL;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2709 } else {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2710 // Convert jid to lowercase and strip resource
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2711 char *p;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2712 for (p = fjid; *p && *p != JID_RESOURCE_SEPARATOR; p++)
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2713 *p = tolower(*p);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2714 if (*p == JID_RESOURCE_SEPARATOR)
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2715 *p = '\0';
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2716 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2717 } else {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2718 gpointer bud = NULL;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2719 if (current_buddy)
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2720 bud = BUDDATA(current_buddy);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2721 if (bud) {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2722 guint type = buddy_gettype(bud);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2723 if (type & ROSTER_TYPE_USER) // Is it a user?
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2724 fjid = (char*)buddy_getjid(bud);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2725 else
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2726 scr_LogPrint(LPRINT_NORMAL, "The selected item should be a user.");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2727 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2728 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2729
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2730 if (fjid) { // fjid is actually a bare jid...
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2731 guint disabled;
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2732 GString *sbuf;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2733 switch (op) {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2734 case pgp_enable:
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2735 case pgp_disable:
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2736 settings_pgp_setdisabled(fjid, (op == pgp_disable ? TRUE : FALSE));
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2737 break;
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2738 case pgp_force:
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2739 settings_pgp_setforce(fjid, force);
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2740 break;
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2741 case pgp_setkey:
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2742 settings_pgp_setkeyid(fjid, keyid);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2743 break;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2744 case pgp_info:
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2745 sbuf = g_string_new("");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2746 if (settings_pgp_getkeyid(fjid)) {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2747 g_string_printf(sbuf, "PGP Encryption key id: %s",
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2748 settings_pgp_getkeyid(fjid));
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2749 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2750 }
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2751 disabled = settings_pgp_getdisabled(fjid);
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2752 g_string_printf(sbuf, "PGP encryption is %s",
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2753 (disabled ? "disabled" : "enabled"));
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2754 scr_WriteIncomingMessage(fjid, sbuf->str, 0, HBB_PREFIX_INFO);
1197
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2755 if (!disabled && settings_pgp_getforce(fjid)) {
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2756 scr_WriteIncomingMessage(fjid,
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2757 "Encryption enforced (no negotiation)",
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2758 0, HBB_PREFIX_INFO);
6f602d3270a4 Add /pgp [-]force
Mikael Berthe <mikael@lilotux.net>
parents: 1192
diff changeset
2759 }
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2760 g_string_free(sbuf, TRUE);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2761 break;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2762 default:
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2763 break;
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2764 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2765 } else {
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2766 scr_LogPrint(LPRINT_NORMAL, "Please specify a valid Jabber ID.");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2767 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2768
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2769 free_arg_lst(paramlst);
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2770 }
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
2771
1173
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
2772 /* !!!
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
2773 After changing the /iline arguments names here, you must change ones
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
2774 in init_bindings().
960f34ec22a2 Add init_bindings() for default key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1172
diff changeset
2775 */
1171
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2776 static void do_iline(char *arg)
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2777 {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2778 if (!strcasecmp(arg, "fword")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2779 readline_forward_word();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2780 } else if (!strcasecmp(arg, "bword")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2781 readline_backward_word();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2782 } else if (!strcasecmp(arg, "word_fdel")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2783 readline_forward_kill_word();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2784 } else if (!strcasecmp(arg, "word_bdel")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2785 readline_backward_kill_word();
1172
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2786 } else if (!strcasecmp(arg, "word_upcase")) {
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2787 readline_updowncase_word(1);
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2788 } else if (!strcasecmp(arg, "word_downcase")) {
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2789 readline_updowncase_word(0);
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2790 } else if (!strcasecmp(arg, "word_capit")) {
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2791 readline_capitalize_word();
1171
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2792 } else if (!strcasecmp(arg, "fchar")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2793 readline_forward_char();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2794 } else if (!strcasecmp(arg, "bchar")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2795 readline_backward_char();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2796 } else if (!strcasecmp(arg, "char_fdel")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2797 readline_forward_kill_char();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2798 } else if (!strcasecmp(arg, "char_bdel")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2799 readline_backward_kill_char();
1172
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2800 } else if (!strcasecmp(arg, "char_swap")) {
1171
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2801 readline_transpose_chars();
1190
be06bbe7e449 Add readline_hist_beginning_search_bwd/fwd functions
Mikael Berthe <mikael@lilotux.net>
parents: 1187
diff changeset
2802 } else if (!strcasecmp(arg, "hist_beginning_search_bwd")) {
be06bbe7e449 Add readline_hist_beginning_search_bwd/fwd functions
Mikael Berthe <mikael@lilotux.net>
parents: 1187
diff changeset
2803 readline_hist_beginning_search_bwd();
be06bbe7e449 Add readline_hist_beginning_search_bwd/fwd functions
Mikael Berthe <mikael@lilotux.net>
parents: 1187
diff changeset
2804 } else if (!strcasecmp(arg, "hist_beginning_search_fwd")) {
be06bbe7e449 Add readline_hist_beginning_search_bwd/fwd functions
Mikael Berthe <mikael@lilotux.net>
parents: 1187
diff changeset
2805 readline_hist_beginning_search_fwd();
1171
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2806 } else if (!strcasecmp(arg, "hist_prev")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2807 readline_hist_prev();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2808 } else if (!strcasecmp(arg, "hist_next")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2809 readline_hist_next();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2810 } else if (!strcasecmp(arg, "iline_start")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2811 readline_iline_start();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2812 } else if (!strcasecmp(arg, "iline_end")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2813 readline_iline_end();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2814 } else if (!strcasecmp(arg, "iline_fdel")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2815 readline_forward_kill_iline();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2816 } else if (!strcasecmp(arg, "iline_bdel")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2817 readline_backward_kill_iline();
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2818 } else if (!strcasecmp(arg, "send_multiline")) {
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2819 readline_send_multiline();
1172
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2820 } else if (!strcasecmp(arg, "iline_accept")) {
1177
10733d7de004 Refactor readline_accept_line() and readline_accept_line_down_hist()
Mikael Berthe <mikael@lilotux.net>
parents: 1173
diff changeset
2821 retval_for_cmds = readline_accept_line(FALSE);
10733d7de004 Refactor readline_accept_line() and readline_accept_line_down_hist()
Mikael Berthe <mikael@lilotux.net>
parents: 1173
diff changeset
2822 } else if (!strcasecmp(arg, "iline_accept_down_hist")) {
10733d7de004 Refactor readline_accept_line() and readline_accept_line_down_hist()
Mikael Berthe <mikael@lilotux.net>
parents: 1173
diff changeset
2823 retval_for_cmds = readline_accept_line(TRUE);
1172
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2824 } else if (!strcasecmp(arg, "compl_cancel")) {
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2825 readline_cancel_completion();
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2826 } else if (!strcasecmp(arg, "compl_do")) {
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2827 readline_do_completion();
1171
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2828 }
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2829 }
03a38b7ad2e0 Add a collection of commands for key bindings (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1165
diff changeset
2830
1172
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2831 static void do_screen_refresh(char *arg)
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2832 {
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2833 readline_refresh_screen();
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2834 }
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2835
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2836 static void do_chat_disable(char *arg)
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2837 {
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2838 readline_disable_chat_mode();
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2839 }
334ae9f498f1 Add some more iline functions (Lego12239)
Mikael Berthe <mikael@lilotux.net>
parents: 1171
diff changeset
2840
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2841 static void do_source(char *arg)
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2842 {
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2843 static int recur_level;
1202
ede6c7aa59b0 Handle "~" in /source paths
Mikael Berthe <mikael@lilotux.net>
parents: 1197
diff changeset
2844 gchar *filename, *expfname;
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2845 if (!*arg) {
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2846 scr_LogPrint(LPRINT_NORMAL, "Missing filename.");
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2847 return;
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2848 }
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2849 if (recur_level > 20) {
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2850 scr_LogPrint(LPRINT_LOGNORM, "** Too many source commands!");
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2851 return;
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2852 }
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2853 filename = g_strdup(arg);
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2854 strip_arg_special_chars(filename);
1202
ede6c7aa59b0 Handle "~" in /source paths
Mikael Berthe <mikael@lilotux.net>
parents: 1197
diff changeset
2855 expfname = expand_filename(filename);
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2856 recur_level++;
1202
ede6c7aa59b0 Handle "~" in /source paths
Mikael Berthe <mikael@lilotux.net>
parents: 1197
diff changeset
2857 cfg_read_file(expfname, FALSE);
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2858 recur_level--;
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2859 g_free(filename);
1202
ede6c7aa59b0 Handle "~" in /source paths
Mikael Berthe <mikael@lilotux.net>
parents: 1197
diff changeset
2860 g_free(expfname);
1192
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2861 }
7b8765c10abb New command: /source
Mikael Berthe <mikael@lilotux.net>
parents: 1190
diff changeset
2862
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
2863 static void do_connect(char *arg)
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
2864 {
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
2865 mcabber_connect();
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
2866 }
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
2867
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
2868 static void do_disconnect(char *arg)
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
2869 {
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
2870 jb_disconnect();
1014
99c5278bf6b8 Keep the status and status messages when we're disconnected
Mikael Berthe <mikael@lilotux.net>
parents: 1012
diff changeset
2871 AutoConnection = false;
298
35cda94e570d Add /connect and /disconnect commands
Mikael Berthe <mikael@lilotux.net>
parents: 290
diff changeset
2872 }
576
8b3db0b555a1 Add Vim modelines
Mikael Berthe <mikael@lilotux.net>
parents: 575
diff changeset
2873
868
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
2874 static void do_help(char *arg)
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
2875 {
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
2876 help_process(arg);
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
2877 }
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
2878
580
fed6d1e4d7a9 Fix modelines
Mikael Berthe <mikael@lilotux.net>
parents: 576
diff changeset
2879 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */