annotate mcabber/src/commands.c @ 1086:5e2e647e781b

Add command /roster group_prev|group_next and update documentation
author Mikael Berthe <mikael@lilotux.net>
date Wed, 06 Dec 2006 22:14:41 +0100
parents b2fc694a8228
children 2bef748356de
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 *
699
ee03b56b93ee Update Copyright (2006)
Mikael Berthe <mikael@lilotux.net>
parents: 696
diff changeset
4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.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
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
45 // Commands callbacks
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
46 static void do_roster(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
47 static void do_status(char *arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
48 static void do_status_to(char *arg);
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
49 static void do_add(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
50 static void do_del(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
51 static void do_group(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
52 static void do_say(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
53 static void do_msay(char *arg);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
54 static void do_say_to(char *arg);
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
55 static void do_buffer(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
56 static void do_clear(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
57 static void do_info(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
58 static void do_rename(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
59 static void do_move(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
60 static void do_set(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
61 static void do_alias(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
62 static void do_bind(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
63 static void do_connect(char *arg);
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
64 static void do_disconnect(char *arg);
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
65 static void do_rawxml(char *arg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
66 static void do_room(char *arg);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
67 static void do_authorization(char *arg);
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
68 static void do_version(char *arg);
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
69 static void do_request(char *arg);
748
53a000411587 Add /event command
Mikael Berthe <mikael@lilotux.net>
parents: 740
diff changeset
70 static void do_event(char *arg);
868
cefdaeb42e67 Add online /help command
Mikael Berthe <mikael@lilotux.net>
parents: 867
diff changeset
71 static void do_help(char *arg);
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
72 static void do_pgp(char *arg);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
73
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
74 // Global variable for the commands list
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
75 static GSList *Commands;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
76
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
77
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
78 // cmd_add()
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
79 // 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
80 static void cmd_add(const char *name, const char *help,
1059
875d2c9d399c Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
81 guint flags_row1, guint flags_row2, void (*f)(char*))
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
82 {
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
83 cmd *n_cmd = g_new0(cmd, 1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
84 strncpy(n_cmd->name, name, 32-1);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
85 n_cmd->help = help;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
86 n_cmd->completion_flags[0] = flags_row1;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
87 n_cmd->completion_flags[1] = flags_row2;
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
88 n_cmd->func = f;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
89 Commands = g_slist_append(Commands, n_cmd);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
90 // Add to completion CMD category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
91 compl_add_category_word(COMPL_CMD, name);
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
92 }
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
93
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
94 // cmd_init()
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
95 // Commands table initialization
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
96 void cmd_init(void)
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
97 {
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
98 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
99 cmd_add("alias", "Add an alias", 0, 0, &do_alias);
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
100 cmd_add("authorization", "Manage subscription authorizations",
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
101 COMPL_AUTH, COMPL_JID, &do_authorization);
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
102 cmd_add("bind", "Add an key binding", 0, 0, &do_bind);
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
103 cmd_add("buffer", "Manipulate current buddy's buffer (chat window)",
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
104 COMPL_BUFFER, 0, &do_buffer);
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
105 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
106 cmd_add("connect", "Connect to the server", 0, 0, &do_connect);
205
e01bf6d9b4b8 [/trunk] Changeset 217 by mikael
mikael
parents: 191
diff changeset
107 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
108 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
109 cmd_add("event", "Process an event", COMPL_EVENTSID, COMPL_EVENTS, &do_event);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
110 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
111 cmd_add("help", "Display some help", COMPL_CMD, 0, &do_help);
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
112 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
113 cmd_add("move", "Move the current buddy to another group", COMPL_GROUPNAME,
d5ae42cbe1fa [/trunk] Changeset 237 by mikael
mikael
parents: 221
diff changeset
114 0, &do_move);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
115 cmd_add("msay", "Send a multi-lines message to the selected buddy",
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
116 COMPL_MULTILINE, 0, &do_msay);
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
117 cmd_add("pgp", "Manage PGP settings", COMPL_PGP, COMPL_JID, &do_pgp);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
118 cmd_add("quit", "Exit the software", 0, 0, NULL);
436
802da817a684 Add /rawxml command
Mikael Berthe <mikael@lilotux.net>
parents: 416
diff changeset
119 cmd_add("rawxml", "Send a raw XML string", 0, 0, &do_rawxml);
208
8b08f34922c5 [/trunk] Changeset 220 by mikael
mikael
parents: 206
diff changeset
120 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
121 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
122 &do_request);
2016f52a167f Sort commands (for the completion system)
Mikael Berthe <mikael@lilotux.net>
parents: 900
diff changeset
123 cmd_add("room", "MUC actions command", COMPL_ROOM, 0, &do_room);
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
124 cmd_add("roster", "Manipulate the roster/buddylist", COMPL_ROSTER, 0,
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
125 &do_roster);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
126 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
127 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
128 &do_say_to);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
129 //cmd_add("search");
310
29b27c8692ea Post-0.6.3 changes
Mikael Berthe <mikael@lilotux.net>
parents: 308
diff changeset
130 cmd_add("set", "Set/query an option value", 0, 0, &do_set);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
131 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
132 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
133 COMPL_JID, COMPL_STATUS, &do_status_to);
622
2b7ef605ddc6 Add /version command
Mikael Berthe <mikael@lilotux.net>
parents: 620
diff changeset
134 cmd_add("version", "Show mcabber version", 0, 0, &do_version);
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
135
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
136 // Status category
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
137 compl_add_category_word(COMPL_STATUS, "online");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
138 compl_add_category_word(COMPL_STATUS, "avail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
139 compl_add_category_word(COMPL_STATUS, "invisible");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
140 compl_add_category_word(COMPL_STATUS, "free");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
141 compl_add_category_word(COMPL_STATUS, "dnd");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
142 compl_add_category_word(COMPL_STATUS, "notavail");
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
143 compl_add_category_word(COMPL_STATUS, "away");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
144
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
145 // Roster category
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
146 compl_add_category_word(COMPL_ROSTER, "bottom");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
147 compl_add_category_word(COMPL_ROSTER, "top");
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
148 compl_add_category_word(COMPL_ROSTER, "up");
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
149 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
150 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
151 compl_add_category_word(COMPL_ROSTER, "group_next");
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
152 compl_add_category_word(COMPL_ROSTER, "hide");
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
153 compl_add_category_word(COMPL_ROSTER, "show");
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
154 compl_add_category_word(COMPL_ROSTER, "toggle");
103
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
155 compl_add_category_word(COMPL_ROSTER, "hide_offline");
93dcc4e15d4a [/trunk] Changeset 117 by mikael
mikael
parents: 102
diff changeset
156 compl_add_category_word(COMPL_ROSTER, "show_offline");
290
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
157 compl_add_category_word(COMPL_ROSTER, "toggle_offline");
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
158 compl_add_category_word(COMPL_ROSTER, "item_lock");
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
159 compl_add_category_word(COMPL_ROSTER, "item_unlock");
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
160 compl_add_category_word(COMPL_ROSTER, "alternate");
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
161 compl_add_category_word(COMPL_ROSTER, "search");
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
162 compl_add_category_word(COMPL_ROSTER, "unread_first");
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
163 compl_add_category_word(COMPL_ROSTER, "unread_next");
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
164 compl_add_category_word(COMPL_ROSTER, "note");
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
165
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
166 // Roster category
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
167 compl_add_category_word(COMPL_BUFFER, "clear");
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
168 compl_add_category_word(COMPL_BUFFER, "bottom");
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
169 compl_add_category_word(COMPL_BUFFER, "top");
508
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
170 compl_add_category_word(COMPL_BUFFER, "up");
5a2132ba2220 Add "/buffer up" and "/buffer down"
Mikael Berthe <mikael@lilotux.net>
parents: 506
diff changeset
171 compl_add_category_word(COMPL_BUFFER, "down");
370
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
172 compl_add_category_word(COMPL_BUFFER, "search_backward");
dd9e2eb52916 Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents: 369
diff changeset
173 compl_add_category_word(COMPL_BUFFER, "search_forward");
464
e4840b288be0 Add "/buffer date"
Mikael Berthe <mikael@lilotux.net>
parents: 462
diff changeset
174 compl_add_category_word(COMPL_BUFFER, "date");
462
d580e87c11ed Add "/buffer %n"
Mikael Berthe <mikael@lilotux.net>
parents: 461
diff changeset
175 compl_add_category_word(COMPL_BUFFER, "%");
866
b30df2ab457f Add "/buffer purge"
Mikael Berthe <mikael@lilotux.net>
parents: 865
diff changeset
176 compl_add_category_word(COMPL_BUFFER, "purge");
873
ee39f6d94d43 Add /buffer {scroll_lock|scroll_unlock|toggle_scroll}
Mikael Berthe <mikael@lilotux.net>
parents: 868
diff changeset
177 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
178 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
179 compl_add_category_word(COMPL_BUFFER, "scroll_toggle");
187
4ce9ff808baa [/trunk] Changeset 199 by mikael
mikael
parents: 166
diff changeset
180
127
0f7ec11efd06 [/trunk] Changeset 140 by mikael
mikael
parents: 124
diff changeset
181 // Group category
240
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
182 compl_add_category_word(COMPL_GROUP, "fold");
723433a677f0 [/trunk] Changeset 253 by mikael
mikael
parents: 238
diff changeset
183 compl_add_category_word(COMPL_GROUP, "unfold");
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
184 compl_add_category_word(COMPL_GROUP, "toggle");
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
185
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
186 // Multi-line (msay) category
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
187 compl_add_category_word(COMPL_MULTILINE, "abort");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
188 compl_add_category_word(COMPL_MULTILINE, "begin");
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
189 compl_add_category_word(COMPL_MULTILINE, "send");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
190 compl_add_category_word(COMPL_MULTILINE, "send_to");
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
191 compl_add_category_word(COMPL_MULTILINE, "toggle");
838
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
192 compl_add_category_word(COMPL_MULTILINE, "toggle_verbatim");
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
193 compl_add_category_word(COMPL_MULTILINE, "verbatim");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
194
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
195 // Room category
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
196 compl_add_category_word(COMPL_ROOM, "affil");
571
d63e6cbdc297 Add "/room ban"
Mikael Berthe <mikael@lilotux.net>
parents: 570
diff changeset
197 compl_add_category_word(COMPL_ROOM, "ban");
1009
c112423ac012 Add /room bookmark
Mikael Berthe <mikael@lilotux.net>
parents: 1004
diff changeset
198 compl_add_category_word(COMPL_ROOM, "bookmark");
599
fb67bf62f4eb Add "/room destroy"
Mikael Berthe <mikael@lilotux.net>
parents: 598
diff changeset
199 compl_add_category_word(COMPL_ROOM, "destroy");
486
2a6a8ebb813b Add "/room invite"
Mikael Berthe <mikael@lilotux.net>
parents: 484
diff changeset
200 compl_add_category_word(COMPL_ROOM, "invite");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
201 compl_add_category_word(COMPL_ROOM, "join");
568
eb1df2371581 Add "/room kick"
Mikael Berthe <mikael@lilotux.net>
parents: 566
diff changeset
202 compl_add_category_word(COMPL_ROOM, "kick");
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
203 compl_add_category_word(COMPL_ROOM, "leave");
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
204 compl_add_category_word(COMPL_ROOM, "names");
470
eaa2ad773192 Add "/room nick"
Mikael Berthe <mikael@lilotux.net>
parents: 469
diff changeset
205 compl_add_category_word(COMPL_ROOM, "nick");
490
af6e31e32d9e Add "/room privmsg"
Mikael Berthe <mikael@lilotux.net>
parents: 488
diff changeset
206 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
207 compl_add_category_word(COMPL_ROOM, "remove");
585
7eff2c1481fa Add "/room affil" and "/room role"
Mikael Berthe <mikael@lilotux.net>
parents: 584
diff changeset
208 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
209 compl_add_category_word(COMPL_ROOM, "topic");
449
e08b0c2d0e54 Add "/room unlock"
Mikael Berthe <mikael@lilotux.net>
parents: 448
diff changeset
210 compl_add_category_word(COMPL_ROOM, "unlock");
572
afc2bd38b15c Implement affiliations handling, add "/room whois"
Mikael Berthe <mikael@lilotux.net>
parents: 571
diff changeset
211 compl_add_category_word(COMPL_ROOM, "whois");
617
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
212
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
213 // Authorization category
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
214 compl_add_category_word(COMPL_AUTH, "allow");
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
215 compl_add_category_word(COMPL_AUTH, "cancel");
d3a8b43bf9e7 Add "/authorization" command
Mikael Berthe <mikael@lilotux.net>
parents: 608
diff changeset
216 compl_add_category_word(COMPL_AUTH, "request");
835
6a732d2ad4b4 Add "/authorization request_unsubscribe"
Mikael Berthe <mikael@lilotux.net>
parents: 831
diff changeset
217 compl_add_category_word(COMPL_AUTH, "request_unsubscribe");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
218
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
219 // Request (query) category
1015
579299b1c9b2 Add /request last
Mikael Berthe <mikael@lilotux.net>
parents: 1014
diff changeset
220 compl_add_category_word(COMPL_REQUEST, "last");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
221 compl_add_category_word(COMPL_REQUEST, "time");
1003
c8b1a52b2fd6 Initial VCard retrieval support
Mikael Berthe <mikael@lilotux.net>
parents: 988
diff changeset
222 compl_add_category_word(COMPL_REQUEST, "vcard");
693
e98abd3ce28c Add /request command
Mikael Berthe <mikael@lilotux.net>
parents: 681
diff changeset
223 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
224
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
225 // Events category
938a8791658c Add partial completion for the "/event" command
Mikael Berthe <mikael@lilotux.net>
parents: 748
diff changeset
226 compl_add_category_word(COMPL_EVENTS, "accept");
755
b747f76e57ae Add "/event n ignore"
Mikael Berthe <mikael@lilotux.net>
parents: 750
diff changeset
227 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
228 compl_add_category_word(COMPL_EVENTS, "reject");
1066
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
229
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
230 // PGP category
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
231 compl_add_category_word(COMPL_PGP, "disable");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
232 compl_add_category_word(COMPL_PGP, "enable");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
233 compl_add_category_word(COMPL_PGP, "info");
6de60e142372 Add command /pgp
Mikael Berthe <mikael@lilotux.net>
parents: 1065
diff changeset
234 compl_add_category_word(COMPL_PGP, "setkey");
95
9e6b7897ec37 [/trunk] Changeset 109 by mikael
mikael
parents: 94
diff changeset
235 }
94
9a4aa2797f02 [/trunk] Changeset 108 by mikael
mikael
parents: 81
diff changeset
236
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
237 // expandalias(line)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
238 // 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
239 // If no alias is found, returns line
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
240 // 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
241 // g_free() the pointer after use
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
242 char *expandalias(char *line)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
243 {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
244 const char *p1, *p2;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
245 char *word;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
246 const gchar *value;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
247 char *newline = line;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
248
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
249 // Ignore leading COMMAND_CHAR
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
250 for (p1 = line ; *p1 == COMMAND_CHAR ; p1++)
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
251 ;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
252 // Locate the end of the word
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
253 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
254 ;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
255 // Extract the word
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
256 word = g_strndup(p1, p2-p1);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
257
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
258 // Look for an alias in the list
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
259 value = settings_get(SETTINGS_TYPE_ALIAS, (const char*)word);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
260 if (value) {
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
261 // There is an alias to expand
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
262 newline = g_new(char, strlen(value)+strlen(p2)+2);
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
263 *newline = COMMAND_CHAR;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
264 strcpy(newline+1, value);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
265 strcat(newline, p2);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
266 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
267 g_free(word);
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
268
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
269 return newline;
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
270 }
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
271
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
272 // cmd_get
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
273 // Finds command in the command list structure.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
274 // 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
275 cmd *cmd_get(const char *command)
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
276 {
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
277 const char *p1, *p2;
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
278 char *com;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
279 GSList *sl_com;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
280
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
281 // Ignore leading COMMAND_CHAR
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
282 for (p1 = command ; *p1 == COMMAND_CHAR ; p1++)
102
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
283 ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
284 // Locate the end of the command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
285 for (p2 = p1 ; *p2 && (*p2 != ' ') ; p2++)
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
286 ;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
287 // Copy the clean command
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
288 com = g_strndup(p1, p2-p1);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
289
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
290 // Look for command in the list
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
291 for (sl_com=Commands; sl_com; sl_com = g_slist_next(sl_com)) {
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
292 if (!strcasecmp(com, ((cmd*)sl_com->data)->name))
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
293 break;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
294 }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
295 g_free(com);
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
296
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
297 if (sl_com) // Command has been found.
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
298 return (cmd*)sl_com->data;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
299 return NULL;
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
300 }
2b4cc6bc5bf2 [/trunk] Changeset 116 by mikael
mikael
parents: 101
diff changeset
301
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
302 // send_message(msg)
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
303 // Write the message in the buddy's window and send the message on
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
304 // the network.
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
305 static void send_message(const char *msg, const char *subj)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
306 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
307 const char *bjid;
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
308 guint crypted;
393
f8f3c7493457 Whitespace cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 384
diff changeset
309
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
310 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
311 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
312 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
313 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
314
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
315 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
316 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
317 return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
318 }
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
319
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
320 bjid = CURRENT_JID;
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
321 if (!bjid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
322 scr_LogPrint(LPRINT_NORMAL, "No buddy is currently selected.");
81
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
323 return;
0bd578421ce9 [/trunk] Changeset 95 by mikael
mikael
parents: 47
diff changeset
324 }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
325
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
326 // Network part
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
327 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
328 &crypted);
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
329
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
330 // Hook
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
331 if (buddy_gettype(BUDDATA(current_buddy)) != ROSTER_TYPE_ROOM) {
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
332 // local part (UI, logging, etc.)
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
333 gchar *hmsg;
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
334 if (subj)
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
335 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
336 else
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
337 hmsg = (char*)msg;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
338 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
339 if (hmsg != msg) g_free(hmsg);
447
03bb57383cea Initial Multi-User Chat support
Mikael Berthe <mikael@lilotux.net>
parents: 446
diff changeset
340 }
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
341 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
342
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
343 // process_command(line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
344 // Process a command line.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
345 // Return 255 if this is the /quit command, and 0 for the other commands.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
346 int process_command(char *line)
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
347 {
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
348 char *p;
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
349 char *xpline;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
350 cmd *curcmd;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
351
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
352 // We do alias expansion here
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
353 if (scr_get_multimode() != 2)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
354 xpline = expandalias(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
355 else
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
356 xpline = line; // No expansion in verbatim multi-line mode
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
357
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
358 // We want to have a copy
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
359 if (xpline == line)
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
360 xpline = g_strdup(line);
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
361
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
362 // Remove trailing spaces:
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
363 for (p=xpline ; *p ; p++)
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
364 ;
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
365 for (p-- ; p>xpline && (*p == ' ') ; p--)
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
366 *p = 0;
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
367
101
4f3ad00b5187 [/trunk] Changeset 115 by mikael
mikael
parents: 98
diff changeset
368 // Command "quit"?
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
369 if ((scr_get_multimode() != 2)
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
370 && (!strncasecmp(xpline, mkcmdstr("quit"), strlen(mkcmdstr("quit")))))
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
371 if (!xpline[5] || xpline[5] == ' ')
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
372 return 255;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
373
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
374 // If verbatim multi-line mode, we check if another /msay command is typed
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
375 if ((scr_get_multimode() == 2)
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
376 && (strncasecmp(xpline, mkcmdstr("msay "), strlen(mkcmdstr("msay "))))) {
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
377 // It isn't an /msay command
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
378 scr_append_multiline(xpline);
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
379 g_free(xpline);
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
380 return 0;
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
381 }
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
382
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
383 // Commands handling
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
384 curcmd = cmd_get(xpline);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
385
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
386 if (!curcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
387 scr_LogPrint(LPRINT_NORMAL, "Unrecognized command. "
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
388 "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
389 g_free(xpline);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
390 return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
391 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
392 if (!curcmd->func) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
393 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
394 "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
395 g_free(xpline);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
396 return 0;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
397 }
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
398 // Lets go to the command parameters
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
399 for (p = xpline+1; *p && (*p != ' ') ; p++)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
400 ;
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
401 // Skip spaces
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
402 while (*p && (*p == ' '))
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
403 p++;
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
404 // Call command-specific function
285
edc263a5d350 Add /alias command
Mikael Berthe <mikael@lilotux.net>
parents: 283
diff changeset
405 (*curcmd->func)(p);
954
27a7b2f986f5 Fix a freeze with UTF-8 locales
Mikael Berthe <mikael@lilotux.net>
parents: 902
diff changeset
406 g_free(xpline);
47
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
407 return 0;
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
408 }
7259a61e1a4b [/trunk] Changeset 63 by mikael
mikael
parents:
diff changeset
409
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
410 // process_line(line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
411 // Process a command/message line.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
412 // 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
413 // currently selected buddy.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
414 // Return 255 if the line is the /quit command, or 0.
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
415 int process_line(char *line)
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
416 {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
417 if (!*line) { // User only pressed enter
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
418 if (scr_get_multimode()) {
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
419 scr_append_multiline("");
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
420 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
421 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
422 if (current_buddy) {
647
c6c41dd2464a Enter chat mode automatically when using some commands
Mikael Berthe <mikael@lilotux.net>
parents: 644
diff changeset
423 // Enter chat mode
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
424 scr_set_chatmode(TRUE);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
425 scr_ShowBuddyWindow();
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
426 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
427 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
428 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
429
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
430 if (*line != COMMAND_CHAR) {
288
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
431 // This isn't a command
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
432 if (scr_get_multimode())
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
433 scr_append_multiline(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
434 else
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
435 do_say(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
436 return 0;
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
437 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
438
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
439 /* It is (probably) a command -- except for verbatim multi-line mode */
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
440 return process_command(line);
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
441 }
1eea0fa0955e Add /bind command
Mikael Berthe <mikael@lilotux.net>
parents: 285
diff changeset
442
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
443 // Helper routine for buffer item_{lock,unlock}
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
444 static void roster_buddylock(char *bjid, bool lock)
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
445 {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
446 gpointer bud = NULL;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
447 bool may_need_refresh = FALSE;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
448
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
449 // Allow special jid "" or "." (current buddy)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
450 if (bjid && (!*bjid || !strcmp(bjid, ".")))
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
451 bjid = NULL;
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
452
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
453 if (bjid) {
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
454 // The JID has been specified. Quick check...
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
455 if (check_jid_syntax(bjid)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
456 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
457 "<%s> is not a valid Jabber ID.", bjid);
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
458 } else {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
459 // Find the buddy
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
460 GSList *roster_elt;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
461 roster_elt = roster_find(bjid, jidsearch,
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
462 ROSTER_TYPE_USER|ROSTER_TYPE_ROOM);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
463 if (roster_elt)
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
464 bud = roster_elt->data;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
465 else
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
466 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
467 may_need_refresh = TRUE;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
468 }
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
469 } else {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
470 // Use the current buddy
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
471 if (current_buddy)
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
472 bud = BUDDATA(current_buddy);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
473 }
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 // Update the ROSTER_FLAG_USRLOCK flag
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
476 if (bud) {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
477 buddy_setflags(bud, ROSTER_FLAG_USRLOCK, lock);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
478 if (may_need_refresh)
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
479 buddylist_build();
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
480 update_roster = TRUE;
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
481 }
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
482 }
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
483
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
484 // display_and_free_note(note, winId)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
485 // 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
486 // (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
487 // display the note jid too)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
488 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
489 {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
490 gchar tbuf[128];
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
491 GString *sbuf;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
492 guint msg_flag = HBB_PREFIX_INFO;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
493 /* 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
494 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
495
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
496 if (!note)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
497 return;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
498
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
499 sbuf = g_string_new("");
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
500
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
501 if (!winId) {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
502 // 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
503 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
504 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
505 msg_flag = HBB_PREFIX_NONE;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
506 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
507
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
508 // 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
509 if (note->cdate) {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
510 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
511 localtime(&note->cdate));
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
512 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
513 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
514 msg_flag = HBB_PREFIX_NONE;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
515 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
516 // 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
517 // 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
518 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
519 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
520 localtime(&note->mdate));
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
521 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
522 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
523 msg_flag = HBB_PREFIX_NONE;
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 // Note text
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
526 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
527 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
528
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
529 g_string_free(sbuf, TRUE);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
530 g_free(note->text);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
531 g_free(note->jid);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
532 g_free(note);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
533 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
534
1059
875d2c9d399c Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1058
diff changeset
535 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
536 {
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
537 GSList *notes;
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
538 notes = jb_get_all_storage_rosternotes();
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
539 // 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
540 // with winId = NULL (special window)
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
541 g_slist_foreach(notes, (GFunc)&display_and_free_note, NULL);
1038
f9e8fd9cb58b Set new_msg flag when listing annotations in the status buffer in non-chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
542 if (notes) {
f9e8fd9cb58b Set new_msg flag when listing annotations in the status buffer in non-chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
543 scr_setmsgflag_if_needed(SPECIAL_BUFFER_STATUS_ID, TRUE);
f9e8fd9cb58b Set new_msg flag when listing annotations in the status buffer in non-chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
544 update_roster = TRUE;
f9e8fd9cb58b Set new_msg flag when listing annotations in the status buffer in non-chat mode
Mikael Berthe <mikael@lilotux.net>
parents: 1037
diff changeset
545 }
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
546 g_slist_free(notes);
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
547 }
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
548
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
549 static void roster_note(char *arg)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
550 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
551 const char *bjid;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
552 guint type;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
553
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
554 if (!current_buddy)
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
555 return;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
556
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
557 bjid = buddy_getjid(BUDDATA(current_buddy));
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
558 type = buddy_gettype(BUDDATA(current_buddy));
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
559
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
560 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
561 // 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
562 // Let's display all server notes
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
563 display_all_annotations();
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
564 return;
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
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
567 if (!bjid || (type != ROSTER_TYPE_USER &&
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
568 type != ROSTER_TYPE_ROOM &&
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
569 type != ROSTER_TYPE_AGENT)) {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
570 scr_LogPrint(LPRINT_NORMAL, "This item can't have a note.");
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
571 return;
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
572 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
573
1022
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
574 if (arg && *arg) { // Set a note
4c8d7b558e83 Annotations listing (/roster note in the status buffer)
Mikael Berthe <mikael@lilotux.net>
parents: 1021
diff changeset
575 gchar *msg, *notetxt;
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
576 msg = to_utf8(arg);
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
577 if (!strcmp(msg, "-"))
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
578 notetxt = NULL; // delete note
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
579 else
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
580 notetxt = msg;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
581 jb_set_storage_rosternotes(bjid, notetxt);
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
582 g_free(msg);
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
583 } else { // Display a note
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
584 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
585 if (note) {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
586 display_and_free_note(note, bjid);
1019
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
587 } else {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
588 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
589 HBB_PREFIX_INFO);
9d5f6e0ea7b3 XEP-0145: display note dates
Mikael Berthe <mikael@lilotux.net>
parents: 1016
diff changeset
590 }
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
591 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
592 }
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
593
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
594 /* Commands callback functions */
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
595 /* 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
596 /* (with arg not null) */
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
597
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
598 static void do_roster(char *arg)
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
599 {
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
600 char **paramlst;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
601 char *subcmd;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
602
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
603 paramlst = split_arg(arg, 2, 1); // subcmd, arg
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
604 subcmd = *paramlst;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
605 arg = *(paramlst+1);
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
606
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
607 if (!subcmd || !*subcmd) {
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
608 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
609 free_arg_lst(paramlst);
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
610 return;
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
611 }
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
612
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
613 if (!strcasecmp(subcmd, "top")) {
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
614 scr_RosterTop();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
615 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
616 } else if (!strcasecmp(subcmd, "bottom")) {
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
617 scr_RosterBottom();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
618 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
619 } else if (!strcasecmp(subcmd, "hide")) {
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
620 scr_RosterVisibility(0);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
621 } else if (!strcasecmp(subcmd, "show")) {
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
622 scr_RosterVisibility(1);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
623 } else if (!strcasecmp(subcmd, "toggle")) {
707
b26a0bde4cdb Add /roster hide|show|toggle
Mikael Berthe <mikael@lilotux.net>
parents: 699
diff changeset
624 scr_RosterVisibility(-1);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
625 } else if (!strcasecmp(subcmd, "hide_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
626 buddylist_set_hide_offline_buddies(TRUE);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
627 if (current_buddy)
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
628 buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
629 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
630 } else if (!strcasecmp(subcmd, "show_offline")) {
120
cfd3df636d5f [/trunk] Changeset 133 by mikael
mikael
parents: 118
diff changeset
631 buddylist_set_hide_offline_buddies(FALSE);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
632 buddylist_build();
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
633 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
634 } else if (!strcasecmp(subcmd, "toggle_offline")) {
290
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
635 buddylist_set_hide_offline_buddies(-1);
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
636 buddylist_build();
f63839a4cb35 Add /roster toggle_offline
Mikael Berthe <mikael@lilotux.net>
parents: 288
diff changeset
637 update_roster = TRUE;
974
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
638 } else if (!strcasecmp(subcmd, "item_lock")) {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
639 roster_buddylock(arg, TRUE);
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
640 } else if (!strcasecmp(subcmd, "item_unlock")) {
36f7753dfb59 Add /roster item_{lock,unlock}
Mikael Berthe <mikael@lilotux.net>
parents: 968
diff changeset
641 roster_buddylock(arg, FALSE);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
642 } else if (!strcasecmp(subcmd, "unread_first")) {
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
643 scr_RosterUnreadMessage(0);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
644 } else if (!strcasecmp(subcmd, "unread_next")) {
236
72fd1273f2b7 [/trunk] Changeset 249 by mikael
mikael
parents: 232
diff changeset
645 scr_RosterUnreadMessage(1);
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
646 } else if (!strcasecmp(subcmd, "alternate")) {
330
a9013124ede6 Add "/roster alternate"
Mikael Berthe <mikael@lilotux.net>
parents: 318
diff changeset
647 scr_RosterJumpAlternate();
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
648 } else if (!strncasecmp(subcmd, "search", 6)) {
979
ea939ff047d8 Improve /buffer search_*
Mikael Berthe <mikael@lilotux.net>
parents: 978
diff changeset
649 strip_arg_special_chars(arg);
ea939ff047d8 Improve /buffer search_*
Mikael Berthe <mikael@lilotux.net>
parents: 978
diff changeset
650 if (!arg || !*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
651 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
652 free_arg_lst(paramlst);
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
653 return;
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
654 }
978
a58dfdd6d058 Fix /roster search
Mikael Berthe <mikael@lilotux.net>
parents: 977
diff changeset
655 scr_RosterSearch(arg);
265
49e9e02dd6d0 Add "/roster search" command
mikael@frmp8452
parents: 262
diff changeset
656 update_roster = TRUE;
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
657 } else if (!strcasecmp(subcmd, "up")) {
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
658 scr_RosterUp();
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
659 } else if (!strcasecmp(subcmd, "down")) {
377
00809e3e327e Add "/roster up" and "/roster down"
Mikael Berthe <mikael@lilotux.net>
parents: 374
diff changeset
660 scr_RosterDown();
1086
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
661 } 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
662 scr_RosterPrevGroup();
5e2e647e781b Add command /roster group_prev|group_next and update documentation
Mikael Berthe <mikael@lilotux.net>
parents: 1074
diff changeset
663 } 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
664 scr_RosterNextGroup();
1016
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
665 } else if (!strcasecmp(subcmd, "note")) {
4d3c48844746 Add /roster note
Mikael Berthe <mikael@lilotux.net>
parents: 1015
diff changeset
666 roster_note(arg);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
667 } else
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
668 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
968
d3bfa9e9d88c Use split_arg() in do_roster()
Mikael Berthe <mikael@lilotux.net>
parents: 967
diff changeset
669 free_arg_lst(paramlst);
104
fe7257d251ac [/trunk] Changeset 118 by mikael
mikael
parents: 103
diff changeset
670 }
108
7fb72bc13732 [/trunk] Changeset 122 by mikael
mikael
parents: 104
diff changeset
671
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
672 // setstatus(recipient, arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
673 // Set your Jabber status.
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
674 // - 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
675 // - arg must be "status message" (message is optional)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
676 static void setstatus(const char *recipient, const char *arg)
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
677 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
678 char **paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
679 char *status;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
680 char *msg;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
681 enum imstatus st;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
682
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
683 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
684 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
685 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
686 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
687
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
688 paramlst = split_arg(arg, 2, 0); // status, message
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
689 status = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
690 msg = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
691
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
692 if (!status) {
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
693 free_arg_lst(paramlst);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
694 return;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
695 }
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
696
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
697 if (!strcasecmp(status, IMSTATUS_OFFLINE)) st = offline;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
698 else if (!strcasecmp(status, IMSTATUS_ONLINE)) st = available;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
699 else if (!strcasecmp(status, IMSTATUS_AVAILABLE)) st = available;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
700 else if (!strcasecmp(status, IMSTATUS_AWAY)) st = away;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
701 else if (!strcasecmp(status, IMSTATUS_INVISIBLE)) st = invisible;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
702 else if (!strcasecmp(status, IMSTATUS_DONOTDISTURB)) st = dontdisturb;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
703 else if (!strcasecmp(status, IMSTATUS_NOTAVAILABLE)) st = notavail;
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
704 else if (!strcasecmp(status, IMSTATUS_FREE4CHAT)) st = freeforchat;
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
705 else {
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
706 scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!");
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
707 free_arg_lst(paramlst);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
708 return;
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
709 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
710
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
711 // Use provided message
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
712 if (msg && !*msg) {
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
713 msg = NULL;
677
633a0522bd37 Using "/status invisible -" did not clear the status message
Mikael Berthe <mikael@lilotux.net>
parents: 659
diff changeset
714 }
318
45076d02eeef The /status command can specify a status message
Mikael Berthe <mikael@lilotux.net>
parents: 310
diff changeset
715
528
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
716 // 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
717 if (recipient && !msg)
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
718 msg = "";
2f714bd701a1 Do not use default status messages with /status_to
Mikael Berthe <mikael@lilotux.net>
parents: 519
diff changeset
719
1050
ea71d31a2607 PGP: Do not sign presence messages to chatrooms
Mikael Berthe <mikael@lilotux.net>
parents: 1043
diff changeset
720 jb_setstatus(st, recipient, msg, FALSE);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
721
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
722 free_arg_lst(paramlst);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
723 }
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
724
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
725 static void do_status(char *arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
726 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
727 if (!*arg) {
519
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
728 const char *sm = jb_getstatusmsg();
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
729 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
730 imstatus2char[jb_getstatus()],
5c338d31de56 Show current global status message in "/status"
Mikael Berthe <mikael@lilotux.net>
parents: 508
diff changeset
731 (sm ? sm : ""));
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
732 return;
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
733 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
734 arg = to_utf8(arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
735 setstatus(NULL, arg);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
736 g_free(arg);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
737 }
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
738
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
739 static void do_status_to(char *arg)
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
740 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
741 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
742 char *fjid, *st, *msg;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
743 char *jid_utf8 = NULL;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
744
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
745 paramlst = split_arg(arg, 3, 1); // jid, status, [message]
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
746 fjid = *paramlst;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
747 st = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
748 msg = *(paramlst+2);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
749
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
750 if (!fjid || !st) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
751 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
752 "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
753 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
754 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
755 }
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
756
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
757 // Allow things like /status_to "" away
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
758 if (!*fjid || !strcmp(fjid, "."))
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
759 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
760
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
761 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
762 // The JID has been specified. Quick check...
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
763 if (check_jid_syntax(fjid)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
764 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
765 "<%s> is not a valid Jabber ID.", fjid);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
766 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
767 } else {
696
ee06382dfb22 /status_to: Do not convert resource name to lower case
Mikael Berthe <mikael@lilotux.net>
parents: 694
diff changeset
768 // Convert jid to lowercase
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
769 char *p = fjid;
977
5b01de4ac5e1 Cosmetic changes
Alexis Hildebrandt <afh [at] 2drop [dot] net>
parents: 974
diff changeset
770 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
771 *p = tolower(*p);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
772 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
773 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
774 } 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
775 // 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
776 if (current_buddy)
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
777 fjid = (char*)buddy_getjid(BUDDATA(current_buddy));
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
778 if (!fjid)
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
779 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
780 }
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
781
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
782 if (fjid) {
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
783 char *cmdline;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
784 if (!msg)
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
785 msg = "";
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
786 msg = to_utf8(msg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
787 cmdline = g_strdup_printf("%s %s", st, msg);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
788 scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", fjid, cmdline);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
789 setstatus(fjid, cmdline);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
790 g_free(msg);
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
791 g_free(cmdline);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
792 g_free(jid_utf8);
444
5927c3bfba13 Add /status_to command
Mikael Berthe <mikael@lilotux.net>
parents: 439
diff changeset
793 }
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
794 free_arg_lst(paramlst);
116
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
795 }
1e7e59775f12 [/trunk] Changeset 130 by mikael
mikael
parents: 113
diff changeset
796
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
797 static void do_add(char *arg)
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
798 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
799 char **paramlst;
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
800 char *id, *nick;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
801 char *jid_utf8 = NULL;
472
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
802
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
803 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
804 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
805 return;
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
806 }
75442262c082 Disable some commands when not connected
Mikael Berthe <mikael@lilotux.net>
parents: 471
diff changeset
807
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
808 paramlst = split_arg(arg, 2, 0); // jid, [nickname]
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
809 id = *paramlst;
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
810 nick = *(paramlst+1);
244
5f8b529412bd [/trunk] Changeset 257 by mikael
mikael
parents: 240
diff changeset
811
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
812 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
813 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
814 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
815 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
816
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
817 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
818 // 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
819 if (check_jid_syntax(id)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
820 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
821 "<%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
822 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
823 } 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
824 mc_strtolower(id);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
825 // 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
826 // be used.
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
827 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
828 }
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
829 } 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
830 // 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
831 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
832 id = (char*)buddy_getjid(BUDDATA(current_buddy));
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
833 if (!id)
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
834 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
835 }
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
836
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
837 if (nick)
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
838 nick = to_utf8(nick);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
839
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
840 if (id) {
452
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
841 // 2nd parameter = optional nickname
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
842 jb_addbuddy(id, nick, NULL);
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
843 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
844 id);
dfd9c62b3a39 Jabber Id syntax checks
Mikael Berthe <mikael@lilotux.net>
parents: 449
diff changeset
845 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
846
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
847 g_free(jid_utf8);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
848 g_free(nick);
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
849 free_arg_lst(paramlst);
124
6d2122c003c4 [/trunk] Changeset 137 by mikael
mikael
parents: 120
diff changeset
850 }
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
851
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
852 static void do_del(char *arg)
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
853 {
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
854 const char *bjid;
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
855
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
856 if (*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
857 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
858 "the currently-selected buddy will be deleted.");
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
859 return;
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
860 }
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
861
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
862 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
863 return;
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
864 bjid = buddy_getjid(BUDDATA(current_buddy));
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
865 if (!bjid)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
866 return;
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
867
540
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
868 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
869 // This is a chatroom
652
b243d3b3ff1b We do not need buddy_isresource() anymore
Mikael Berthe <mikael@lilotux.net>
parents: 650
diff changeset
870 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
871 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
872 return;
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
873 }
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
874 }
887c1bd37617 Prevent deletion from rooms we haven't left
Mikael Berthe <mikael@lilotux.net>
parents: 539
diff changeset
875
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
876 scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", bjid);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
877 jb_delbuddy(bjid);
865
cee8d6be04e1 Improve changeset a3db3ee8b99e, do not enable chatmode when refreshing
Mikael Berthe <mikael@lilotux.net>
parents: 861
diff changeset
878 scr_UpdateBuddyWindow();
206
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
879 }
766167c0c57f [/trunk] Changeset 218 by mikael
mikael
parents: 205
diff changeset
880
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
881 static void do_group(char *arg)
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
882 {
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
883 gpointer group;
958
30b799632653 Cosmetics (change a variable name)
Mikael Berthe <mikael@lilotux.net>
parents: 957
diff changeset
884 guint leave_buddywindow;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
885
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
886 if (!*arg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
887 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
888 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
889 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
890
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
891 if (!current_buddy)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
892 return;
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
893
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
894 group = buddy_getgroup(BUDDATA(current_buddy));
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
895 if (!group)
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
896 return;
853
bdd526ec62bc Fix segfault when using /group with the [status] entry
Mikael Berthe <mikael@lilotux.net>
parents: 848
diff changeset
897
212
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
898 // 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
899 // entry itself, because it means we'll have to leave the current buddy
465d98d2f8e3 [/trunk] Changeset 224 by mikael
mikael
parents: 210
diff changeset
900 // chat window.
958
30b799632653 Cosmetics (change a variable name)
Mikael Berthe <mikael@lilotux.net>
parents: 957
diff changeset
901 leave_buddywindow = (group != BUDDATA(current_buddy));
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
902
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
903 if (!(buddy_gettype(group) & ROSTER_TYPE_GROUP)) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
904 scr_LogPrint(LPRINT_NORMAL, "You need to select a group.");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
905 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
906 }
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
907
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
908 if (!strcasecmp(arg, "expand") || !strcasecmp(arg, "unfold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
909 buddy_setflags(group, ROSTER_FLAG_HIDE, FALSE);
166
aa5b635520ef [/trunk] Changeset 178 by mikael
mikael
parents: 164
diff changeset
910 } else if (!strcasecmp(arg, "shrink") || !strcasecmp(arg, "fold")) {
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
911 buddy_setflags(group, ROSTER_FLAG_HIDE, TRUE);
130
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
912 } else if (!strcasecmp(arg, "toggle")) {
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
913 buddy_setflags(group, ROSTER_FLAG_HIDE,
60694c9ddde3 [/trunk] Changeset 143 by mikael
mikael
parents: 129
diff changeset
914 !(buddy_getflags(group) & ROSTER_FLAG_HIDE));
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
915 } else {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
916 scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!");
128
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
917 return;
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
918 }
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
919
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
920 buddylist_build();
81ccb1091dd8 [/trunk] Changeset 141 by mikael
mikael
parents: 127
diff changeset
921 update_roster = TRUE;
958
30b799632653 Cosmetics (change a variable name)
Mikael Berthe <mikael@lilotux.net>
parents: 957
diff changeset
922 if (leave_buddywindow) scr_ShowBuddyWindow();
128
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 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
926 {
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
927 char *bare_jid, *rp;
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
928 char *hmsg;
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
929 guint crypted;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
930
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
931 if (!fjid || !*fjid) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
932 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
933 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
934 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
935 if (!msg || !*msg) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
936 scr_LogPrint(LPRINT_NORMAL, "You must specify a message.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
937 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
938 }
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
939 if (check_jid_syntax((char*)fjid)) {
1064
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
940 scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8,
516b5f7d1023 Fix some UTF-8 related problems
Mikael Berthe <mikael@lilotux.net>
parents: 1059
diff changeset
941 "<%s> is not a valid Jabber ID.", fjid);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
942 return 1;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
943 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
944
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
945 // We must use the bare jid in hk_message_out()
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
946 rp = strchr(fjid, JID_RESOURCE_SEPARATOR);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
947 if (rp) bare_jid = g_strndup(fjid, rp - fjid);
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
948 else bare_jid = (char*)fjid;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
949
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
950 // Jump to window, create one if needed
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
951 scr_RosterJumpJid(bare_jid);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
952
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
953 // 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
954 // 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
955 if (rp) {
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
956 if (roster_find(bare_jid, jidsearch, ROSTER_TYPE_ROOM)) rp++;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
957 else rp = NULL;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
958 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
959
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
960 // local part (UI, logging, etc.)
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
961 if (subj)
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
962 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
963 else
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
964 hmsg = (char*)msg;
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
965
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
966 // Network part
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
967 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
968
1055
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
969 // Hook
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
970 hk_message_out(bare_jid, rp, 0, hmsg, crypted);
6eb1efea75d0 PGP: Visual encryption flag
Mikael Berthe <mikael@lilotux.net>
parents: 1050
diff changeset
971 if (hmsg != msg) g_free(hmsg);
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
972
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
973 if (rp) g_free(bare_jid);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
974 return 0;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
975 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
976
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
977 static void do_say(char *arg)
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
978 {
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
979 gpointer bud;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
980
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
981 scr_set_chatmode(TRUE);
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
982
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
983 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
984 scr_LogPrint(LPRINT_NORMAL,
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
985 "Whom are you talking to? Please select a buddy.");
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
986 return;
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
987 }
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
988
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
989 bud = BUDDATA(current_buddy);
631
423c24e5875a Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 626
diff changeset
990 if (!(buddy_gettype(bud) &
423c24e5875a Allow sending a message to an agent
Mikael Berthe <mikael@lilotux.net>
parents: 626
diff changeset
991 (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
992 scr_LogPrint(LPRINT_NORMAL, "This is not a user.");
164
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
993 return;
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
994 }
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
995
faf534be8ff0 [/trunk] Changeset 176 by mikael
mikael
parents: 132
diff changeset
996 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
997 arg = to_utf8(arg);
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
998 send_message(arg, NULL);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
999 g_free(arg);
132
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1000 }
6531bcf030ae [/trunk] Changeset 145 by mikael
mikael
parents: 130
diff changeset
1001
336
eb994ee40029 Make some functions static
Mikael Berthe <mikael@lilotux.net>
parents: 330
diff changeset
1002 static void do_msay(char *arg)
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1003 {
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1004 /* Parameters: begin verbatim abort send send_to */
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1005 char **paramlst;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1006 char *subcmd;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1007
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1008 paramlst = split_arg(arg, 2, 1); // subcmd, arg
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1009 subcmd = *paramlst;
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1010 arg = *(paramlst+1);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1011
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1012 if (!subcmd || !*subcmd) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1013 scr_LogPrint(LPRINT_NORMAL, "Missing parameter.");
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1014 scr_LogPrint(LPRINT_NORMAL, "Please read the manual before using "
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1015 "the /msay command.");
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1016 scr_LogPrint(LPRINT_NORMAL, "(Use \"%s begin\" to enter "
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1017 "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
1018 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1019 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1020
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1021 if (!strcasecmp(subcmd, "toggle")) {
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1022 if (scr_get_multimode())
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1023 subcmd = "send";
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1024 else
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1025 subcmd = "begin";
838
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1026 } else if (!strcasecmp(subcmd, "toggle_verbatim")) {
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1027 if (scr_get_multimode())
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1028 subcmd = "send";
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1029 else
ea1204c8a30b Add "/msay toggle_verbatim"
Mikael Berthe <mikael@lilotux.net>
parents: 837
diff changeset
1030 subcmd = "verbatim";
796
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1031 }
79c8823da808 Add "/msay toggle" command
Mikael Berthe <mikael@lilotux.net>
parents: 791
diff changeset
1032
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1033 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
1034 if (scr_get_multimode())
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1035 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
1036 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
1037 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1038 } else if ((!strcasecmp(subcmd, "begin")) ||
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1039 (!strcasecmp(subcmd, "verbatim"))) {
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1040 bool verbat;
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1041 gchar *subj_utf8 = to_utf8(arg);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1042 if (!strcasecmp(subcmd, "verbatim")) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1043 scr_set_multimode(2, subj_utf8);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1044 verbat = TRUE;
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1045 } else {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1046 scr_set_multimode(1, subj_utf8);
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1047 verbat = FALSE;
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1048 }
260
33e1a05864a6 Add "verbatim multi-line" mode, with commands disabled
mikael@frmp8452
parents: 244
diff changeset
1049
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1050 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
1051 verbat ? "VERBATIM " : "");
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1052 scr_LogPrint(LPRINT_NORMAL, "Select a buddy and use \"%s send\" "
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1053 "when your message is ready.", mkcmdstr("msay"));
840
2903fd66c3ad Be more verbose about verbatim mode
Mikael Berthe <mikael@lilotux.net>
parents: 838
diff changeset
1054 if (verbat)
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1055 scr_LogPrint(LPRINT_NORMAL, "Use \"%s abort\" to abort this mode.",
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1056 mkcmdstr("msay"));
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1057 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
1058 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1059 } else if (strcasecmp(subcmd, "send") && strcasecmp(subcmd, "send_to")) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1060 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
1061 goto do_msay_return;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1062 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1063
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1064 /* send/send_to command */
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1065
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1066 if (!scr_get_multimode()) {
374
bd5638c21834 Improve logging system (traces)
Mikael Berthe <mikael@lilotux.net>
parents: 371
diff changeset
1067 scr_LogPrint(LPRINT_NORMAL, "No message to send. "
967
303408ef5e5d Configurable command character
Alexis Hildebrandt
parents: 960
diff changeset
1068 "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
1069 goto do_msay_return;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1070 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1071
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1072 scr_set_chatmode(TRUE);
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1073
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1074 if (!strcasecmp(subcmd, "send_to")) {
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1075 int err = FALSE;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1076 gchar *msg_utf8;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1077 // 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
1078 // 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
1079 arg = to_utf8(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1080 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
1081 if (msg_utf8) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1082 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
1083 g_free(msg_utf8);
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1084 }
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1085 g_free(arg);
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1086 if (err)
1073
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1087 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1088 } else { // Send to currently selected buddy
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1089 gpointer bud;
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1090 gchar *msg_utf8;
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1091
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1092 if (!current_buddy) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1093 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
1094 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1095 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1096
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1097 bud = BUDDATA(current_buddy);
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1098 if (!(buddy_gettype(bud) & (ROSTER_TYPE_USER|ROSTER_TYPE_ROOM))) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1099 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
1100 goto do_msay_return;
636
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1101 }
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1102
f84cce8382e8 Add "/msay send_to"
Mikael Berthe <mikael@lilotux.net>
parents: 631
diff changeset
1103 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
1104 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
1105 if (msg_utf8) {
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1106 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
1107 g_free(msg_utf8);
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1108 }
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1109 }
807
f6cda389db48 Allow messages with a subject (/msay)
Mikael Berthe <mikael@lilotux.net>
parents: 797
diff changeset
1110 scr_set_multimode(FALSE, NULL);
797
5eb701c1bc1f Multi-line mode: Do not send empty messages
Mikael Berthe <mikael@lilotux.net>
parents: 796
diff changeset
1111 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
1112 do_msay_return:
253e8988eb5c Fix a few memory leaks after calls to split_arg()
Mikael Berthe <mikael@lilotux.net>
parents: 1072
diff changeset
1113 free_arg_lst(paramlst);
238
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1114 }
8e30b2bb380e [/trunk] Changeset 251 by mikael
mikael
parents: 236
diff changeset
1115
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1116 static void do_say_to(char *arg)
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1117 {
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1118 char **paramlst;
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1119 char *fjid, *msg;
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1120
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1121 if (!jb_getonline()) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1122 scr_LogPrint(LPRINT_NORMAL, "You are not connected.");
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1123 return;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1124 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1125
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1126 paramlst = split_arg(arg, 2, 1); // jid, message
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1127 fjid = *paramlst;
557
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1128 msg = *(paramlst+1);
c72a66dfd2d4 Use split_arg() in most commands
Mikael Berthe <mikael@lilotux.net>
parents: 555
diff changeset
1129
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1130 if (!fjid || !strcmp(fjid, ".")) {
681
8dc602a246a4 Improve messages in commands.c
Philip M. White <pmw@qnan.org>
parents: 677
diff changeset
1131 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
1132 free_arg_lst(paramlst);
480
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1133 return;
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1134 }
882e1acae422 Add /say_to command
Mikael Berthe <mikael@lilotux.net>
parents: 475
diff changeset
1135
1058
c0d44a9a99bc Code cleanup
Mikael Berthe <mikael@lilotux.net>
parents: 1055
diff changeset
1136 fjid = to_utf8(fjid);
772
464be13343a9 Store most data in UTF-8 internally
Mikael Berthe <mikael@lilotux.net>
parents: 757
diff changeset
1137 msg = to_utf8(msg);