author | Myhailo Danylenko <isbear@ukrpost.net> |
Mon, 25 Feb 2013 22:09:55 +0200 | |
changeset 69 | 1b6295674c07 |
parent 68 | c2334fb31211 |
child 70 | e2ef34130809 |
permissions | -rw-r--r-- |
64 | 1 |
# HG changeset patch |
2 |
# Parent 92fa48ef53c909928706ab4c51518953339a38e4 |
|
3 |
Unified command option parsing |
|
4 |
||
66 | 5 |
* cmdopts_parse() & cmdopts_free() in utils.c/h |
6 |
* /roster uses parser |
|
7 |
* buddy_search() now expects argument in utf8 |
|
8 |
* /say_to uses parser |
|
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
9 |
* /color uses parser |
68
c2334fb31211
[cmdopts] Convert /status and /status_to
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
10 |
* /status and /status_to use parser |
c2334fb31211
[cmdopts] Convert /status and /status_to
Myhailo Danylenko <isbear@ukrpost.net>
parents:
67
diff
changeset
|
11 |
* cmd_setstatus() now expects separate status and message arguments |
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
12 |
* /add uses parser |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
13 |
* /del uses parser |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
14 |
* allows specifying jid, as /add does |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
15 |
* -n(--dryrun) switch for debugging purposes |
66 | 16 |
|
65 | 17 |
diff -r 92fa48ef53c9 mcabber/mcabber/commands.c |
18 |
--- a/mcabber/mcabber/commands.c Sun Jan 27 00:40:37 2013 +0200 |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
19 |
+++ b/mcabber/mcabber/commands.c Mon Feb 25 22:07:41 2013 +0200 |
66 | 20 |
@@ -755,7 +755,7 @@ |
21 |
g_slist_free(notes); |
|
22 |
} |
|
23 |
||
24 |
-static void roster_note(char *arg) |
|
25 |
+static void roster_note(gchar *arg) |
|
26 |
{ |
|
27 |
const char *bjid; |
|
28 |
guint type; |
|
29 |
@@ -781,14 +781,9 @@ |
|
30 |
} |
|
31 |
||
32 |
if (arg && *arg) { // Set a note |
|
33 |
- gchar *msg, *notetxt; |
|
34 |
- msg = to_utf8(arg); |
|
35 |
- if (!strcmp(msg, "-")) |
|
36 |
- notetxt = NULL; // delete note |
|
37 |
- else |
|
38 |
- notetxt = msg; |
|
39 |
- xmpp_set_storage_rosternotes(bjid, notetxt); |
|
40 |
- g_free(msg); |
|
41 |
+ if (!strcmp(arg, "-")) |
|
42 |
+ arg = NULL; // delete note |
|
43 |
+ xmpp_set_storage_rosternotes(bjid, arg); |
|
44 |
} else { // Display a note |
|
45 |
struct annotation *note = xmpp_get_storage_rosternotes(bjid, FALSE); |
|
46 |
if (note) { |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
47 |
@@ -819,175 +814,253 @@ |
66 | 48 |
/* All these do_*() functions will be called with a "arg" parameter */ |
49 |
/* (with arg not null) */ |
|
50 |
||
51 |
-static void do_roster(char *arg) |
|
52 |
+static void do_roster(char *args) |
|
53 |
{ |
|
54 |
- char **paramlst; |
|
55 |
- char *subcmd; |
|
56 |
- |
|
57 |
- paramlst = split_arg(arg, 2, 1); // subcmd, arg |
|
58 |
- subcmd = *paramlst; |
|
59 |
- arg = *(paramlst+1); |
|
60 |
- |
|
61 |
- if (!subcmd || !*subcmd) { |
|
62 |
- scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
|
63 |
- free_arg_lst(paramlst); |
|
64 |
- return; |
|
65 |
+ enum roster_subcommand_t { |
|
66 |
+ roster_scmd_bottom, roster_scmd_top, roster_scmd_up, roster_scmd_down, |
|
67 |
+ roster_scmd_group_prev, roster_scmd_group_next, |
|
68 |
+ roster_scmd_alternate, |
|
69 |
+ roster_scmd_unread_first, roster_scmd_unread_next, |
|
70 |
+ roster_scmd_search, |
|
71 |
+ roster_scmd_display, |
|
72 |
+ roster_scmd_hide_offline, roster_scmd_show_offline, roster_scmd_toggle_offline, |
|
73 |
+ roster_scmd_item_lock, roster_scmd_item_unlock, roster_scmd_item_toggle_lock, |
|
74 |
+ roster_scmd_note, |
|
75 |
+ roster_scmd_resource_lock, roster_scmd_resource_unlock, |
|
76 |
+ roster_scmd_hide, roster_scmd_show, roster_scmd_toggle, |
|
77 |
+ } subcmd; |
|
78 |
+#define ROSTER_SCMD_NOARG(NAME) \ |
|
79 |
+ { 0, #NAME, { NULL, NULL, NULL, NULL }, (gpointer)roster_scmd_##NAME } |
|
80 |
+// all of them have at most one argument |
|
81 |
+#define ROSTER_SCMD(NAME, FLAGS, VALUE) \ |
|
82 |
+ { 0, #NAME, { NULL, \ |
|
83 |
+ (cmdarg_t[1]){ \ |
|
84 |
+ { CMDOPT_LAST | FLAGS, { .arg = VALUE } } \ |
|
85 |
+ }, NULL, NULL }, (gpointer)roster_scmd_##NAME } |
|
86 |
+ cmdopts_t options = { |
|
87 |
+ NULL, |
|
88 |
+ (cmdarg_t[1]){ |
|
89 |
+ { CMDOPT_REQUIRED | CMDOPT_SUBCOMMAND | CMDOPT_LAST, { .cmd = NULL } } |
|
90 |
+ }, |
|
91 |
+ (subcmd_t[23]){ |
|
92 |
+ ROSTER_SCMD_NOARG(bottom), |
|
93 |
+ ROSTER_SCMD_NOARG(top), |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
94 |
+ ROSTER_SCMD(up, 0, "1"), // num lines |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
95 |
+ ROSTER_SCMD(down, 0, "1"), // num lines |
66 | 96 |
+ ROSTER_SCMD_NOARG(group_prev), |
97 |
+ ROSTER_SCMD_NOARG(group_next), |
|
98 |
+ ROSTER_SCMD_NOARG(alternate), |
|
99 |
+ ROSTER_SCMD_NOARG(unread_first), |
|
100 |
+ ROSTER_SCMD_NOARG(unread_next), |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
101 |
+ ROSTER_SCMD(search, CMDOPT_REQUIRED | CMDOPT_CATCHALL, NULL), // to find |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
102 |
+ ROSTER_SCMD(display, 0, NULL), // status mask |
66 | 103 |
+ ROSTER_SCMD_NOARG(hide_offline), |
104 |
+ ROSTER_SCMD_NOARG(show_offline), |
|
105 |
+ ROSTER_SCMD_NOARG(toggle_offline), |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
106 |
+ ROSTER_SCMD(item_lock, 0, "."), // jid |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
107 |
+ ROSTER_SCMD(item_unlock, 0, "."), // jid |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
108 |
+ ROSTER_SCMD(item_toggle_lock, 0, "."), // jid |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
109 |
+ ROSTER_SCMD(note, CMDOPT_CATCHALL, NULL), // note |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
110 |
+ ROSTER_SCMD(resource_lock, 0, NULL), // resource/jid |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
111 |
+ ROSTER_SCMD(resource_unlock, 0, NULL), // resource/jid |
66 | 112 |
+ ROSTER_SCMD_NOARG(hide), |
113 |
+ ROSTER_SCMD_NOARG(show), |
|
114 |
+ { CMDOPT_LAST, "toggle", { NULL, NULL, NULL, NULL }, |
|
115 |
+ (gpointer)roster_scmd_toggle }, |
|
116 |
+ }, |
|
117 |
+ NULL, |
|
118 |
+ }; |
|
119 |
+ gchar *arg; |
|
120 |
+ |
|
121 |
+ { |
|
122 |
+ const char *error = cmdopts_parse (args, &options); |
|
123 |
+ if (error != NULL) { |
|
124 |
+ scr_log_print (LPRINT_NORMAL, error); |
|
125 |
+ return; |
|
126 |
+ } |
|
127 |
} |
|
128 |
||
129 |
- if (!strcasecmp(subcmd, "top")) { |
|
130 |
+ subcmd = (enum roster_subcommand_t) (options.args[0].value.cmd -> userdata); |
|
131 |
+ if (options.args[0].value.cmd -> options.args != NULL) { |
|
132 |
+ arg = options.args[0].value.cmd -> options.args[0].value.arg; |
|
133 |
+ } |
|
134 |
+ |
|
135 |
+ if (subcmd == roster_scmd_top) { |
|
136 |
scr_roster_top(); |
|
137 |
update_roster = TRUE; |
|
138 |
- } else if (!strcasecmp(subcmd, "bottom")) { |
|
139 |
+ } else if (subcmd == roster_scmd_bottom) { |
|
140 |
scr_roster_bottom(); |
|
141 |
update_roster = TRUE; |
|
142 |
- } else if (!strcasecmp(subcmd, "hide")) { |
|
143 |
+ } else if (subcmd == roster_scmd_hide) { |
|
144 |
scr_roster_visibility(0); |
|
145 |
- } else if (!strcasecmp(subcmd, "show")) { |
|
146 |
+ } else if (subcmd == roster_scmd_show) { |
|
147 |
scr_roster_visibility(1); |
|
148 |
- } else if (!strcasecmp(subcmd, "toggle")) { |
|
149 |
+ } else if (subcmd == roster_scmd_toggle) { |
|
150 |
scr_roster_visibility(-1); |
|
151 |
- } else if (!strcasecmp(subcmd, "hide_offline")) { |
|
152 |
+ } else if (subcmd == roster_scmd_hide_offline) { |
|
153 |
buddylist_set_hide_offline_buddies(TRUE); |
|
154 |
if (current_buddy) |
|
155 |
buddylist_build(); |
|
156 |
update_roster = TRUE; |
|
157 |
- } else if (!strcasecmp(subcmd, "show_offline")) { |
|
158 |
+ } else if (subcmd == roster_scmd_show_offline) { |
|
159 |
buddylist_set_hide_offline_buddies(FALSE); |
|
160 |
buddylist_build(); |
|
161 |
update_roster = TRUE; |
|
162 |
- } else if (!strcasecmp(subcmd, "toggle_offline")) { |
|
163 |
+ } else if (subcmd == roster_scmd_toggle_offline) { |
|
164 |
buddylist_set_hide_offline_buddies(-1); |
|
165 |
buddylist_build(); |
|
166 |
update_roster = TRUE; |
|
167 |
- } else if (!strcasecmp(subcmd, "display")) { |
|
168 |
+ } else if (subcmd == roster_scmd_display) { |
|
169 |
scr_roster_display(arg); |
|
170 |
- } else if (!strcasecmp(subcmd, "item_lock")) { |
|
171 |
+ } else if (subcmd == roster_scmd_item_lock) { |
|
172 |
roster_buddylock(arg, 1); |
|
173 |
- } else if (!strcasecmp(subcmd, "item_unlock")) { |
|
174 |
+ } else if (subcmd == roster_scmd_item_unlock) { |
|
175 |
roster_buddylock(arg, 0); |
|
176 |
- } else if (!strcasecmp(subcmd, "item_toggle_lock")) { |
|
177 |
+ } else if (subcmd == roster_scmd_item_toggle_lock) { |
|
178 |
roster_buddylock(arg, -1); |
|
179 |
- } else if (!strcasecmp(subcmd, "unread_first")) { |
|
180 |
+ } else if (subcmd == roster_scmd_unread_first) { |
|
181 |
scr_roster_unread_message(0); |
|
182 |
- } else if (!strcasecmp(subcmd, "unread_next")) { |
|
183 |
+ } else if (subcmd == roster_scmd_unread_next) { |
|
184 |
scr_roster_unread_message(1); |
|
185 |
- } else if (!strcasecmp(subcmd, "alternate")) { |
|
186 |
+ } else if (subcmd == roster_scmd_alternate) { |
|
187 |
scr_roster_jump_alternate(); |
|
188 |
- } else if (!strncasecmp(subcmd, "search", 6)) { |
|
189 |
- strip_arg_special_chars(arg); |
|
190 |
- if (!arg || !*arg) { |
|
191 |
- scr_LogPrint(LPRINT_NORMAL, "What name or JID are you looking for?"); |
|
192 |
- free_arg_lst(paramlst); |
|
193 |
+ } else if (subcmd == roster_scmd_search) { |
|
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
194 |
+ scr_roster_search(arg); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
195 |
+ update_roster = TRUE; |
66 | 196 |
+ } else if (subcmd == roster_scmd_up) { |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
197 |
+ roster_updown(-1, arg); |
66 | 198 |
+ } else if (subcmd == roster_scmd_down) { |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
199 |
+ roster_updown(1, arg); |
66 | 200 |
+ } else if (subcmd == roster_scmd_group_prev) { |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
201 |
+ scr_roster_prev_group(); |
66 | 202 |
+ } else if (subcmd == roster_scmd_group_next) { |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
203 |
+ scr_roster_next_group(); |
66 | 204 |
+ } else if (subcmd == roster_scmd_note) { |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
205 |
+ roster_note(arg); |
66 | 206 |
+ } else if (subcmd == roster_scmd_resource_lock) { |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
207 |
+ roster_resourcelock(arg, TRUE); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
208 |
+ } else { // roster_scmd_resource_unlock |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
209 |
+ roster_resourcelock(arg, FALSE); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
210 |
+ } |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
211 |
+ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
212 |
+ cmdopts_free(&options); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
213 |
+} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
214 |
+ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
215 |
+void do_color(char *arg) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
216 |
+{ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
217 |
+ enum color_scmd_t { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
218 |
+ color_scmd_roster, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
219 |
+ color_scmd_mucnick, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
220 |
+ color_scmd_muc, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
221 |
+ } subcmd; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
222 |
+ cmdopts_t options = { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
223 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
224 |
+ (cmdarg_t[1]){ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
225 |
+ { CMDOPT_REQUIRED | CMDOPT_SUBCOMMAND | CMDOPT_LAST, { .cmd = NULL } }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
226 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
227 |
+ (subcmd_t[3]){ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
228 |
+ { 0, "roster", |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
229 |
+ { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
230 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
231 |
+ (cmdarg_t[3]){ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
232 |
+ { CMDOPT_REQUIRED, { .arg = NULL } }, // status mask or "clear" |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
233 |
+ { 0, { .arg = NULL } }, // jid mask |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
234 |
+ { CMDOPT_LAST, { .arg = NULL } }, // color |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
235 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
236 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
237 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
238 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
239 |
+ (gpointer)color_scmd_roster, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
240 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
241 |
+ { 0, "muc", |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
242 |
+ { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
243 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
244 |
+ (cmdarg_t[2]){ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
245 |
+ { CMDOPT_REQUIRED, { .arg = NULL } }, // jid |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
246 |
+ { CMDOPT_LAST, { .arg = "on" } }, // on/off/preset/- |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
247 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
248 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
249 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
250 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
251 |
+ (gpointer)color_scmd_muc, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
252 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
253 |
+ { CMDOPT_LAST, "mucnick", |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
254 |
+ { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
255 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
256 |
+ (cmdarg_t[2]){ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
257 |
+ { CMDOPT_REQUIRED, { .arg = NULL } }, // nick |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
258 |
+ { CMDOPT_REQUIRED | CMDOPT_LAST, { .arg = NULL } }, // color |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
259 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
260 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
261 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
262 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
263 |
+ (gpointer)color_scmd_mucnick, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
264 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
265 |
+ }, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
266 |
+ NULL, |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
267 |
+ }; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
268 |
+ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
269 |
+ { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
270 |
+ const char *error = cmdopts_parse(arg, &options); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
271 |
+ if (error != NULL) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
272 |
+ scr_log_print(LPRINT_NORMAL, error); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
273 |
return; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
274 |
} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
275 |
- scr_roster_search(arg); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
276 |
- update_roster = TRUE; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
277 |
- } else if (!strcasecmp(subcmd, "up")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
278 |
- roster_updown(-1, arg); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
279 |
- } else if (!strcasecmp(subcmd, "down")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
280 |
- roster_updown(1, arg); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
281 |
- } else if (!strcasecmp(subcmd, "group_prev")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
282 |
- scr_roster_prev_group(); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
283 |
- } else if (!strcasecmp(subcmd, "group_next")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
284 |
- scr_roster_next_group(); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
285 |
- } else if (!strcasecmp(subcmd, "note")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
286 |
- roster_note(arg); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
287 |
- } else if (!strcasecmp(subcmd, "resource_lock")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
288 |
- roster_resourcelock(arg, TRUE); |
66 | 289 |
- } else if (!strcasecmp(subcmd, "resource_unlock")) { |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
290 |
- roster_resourcelock(arg, FALSE); |
66 | 291 |
- } else |
292 |
- scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
|
293 |
- free_arg_lst(paramlst); |
|
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
294 |
-} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
295 |
- |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
296 |
-void do_color(char *arg) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
297 |
-{ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
298 |
- char **paramlst; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
299 |
- char *subcmd; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
300 |
- |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
301 |
- paramlst = split_arg(arg, 2, 1); // subcmd, arg |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
302 |
- subcmd = *paramlst; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
303 |
- arg = *(paramlst+1); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
304 |
- |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
305 |
- if (!subcmd || !*subcmd) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
306 |
- scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
307 |
- free_arg_lst(paramlst); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
308 |
- return; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
309 |
} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
310 |
- |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
311 |
- if (!strcasecmp(subcmd, "roster")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
312 |
- char *status, *wildcard, *color; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
313 |
- char **arglist = split_arg(arg, 3, 0); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
314 |
- |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
315 |
- status = *arglist; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
316 |
- wildcard = to_utf8(arglist[1]); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
317 |
- color = arglist[2]; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
318 |
- |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
319 |
- if (status && !strcmp(status, "clear")) { // Not a color command, clear all |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
320 |
+ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
321 |
+ subcmd = (enum color_scmd_t) options.args[0].value.cmd -> userdata; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
322 |
+ |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
323 |
+ if (subcmd == color_scmd_roster) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
324 |
+ const gchar *status = options.cmds[0].options.args[0].value.arg; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
325 |
+ const gchar *wildcard = options.cmds[0].options.args[1].value.arg; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
326 |
+ const gchar *color = options.cmds[0].options.args[2].value.arg; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
327 |
+ if (!strcmp(status, "clear")) { // Not a color command, clear all |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
328 |
scr_roster_clear_color(); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
329 |
update_roster = TRUE; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
330 |
} else { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
331 |
- if (!status || !*status || !wildcard || !*wildcard || !color || !*color) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
332 |
- scr_LogPrint(LPRINT_NORMAL, "Missing argument"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
333 |
+ if (!*status || !wildcard || !*wildcard || !color || !*color) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
334 |
+ scr_log_print(LPRINT_NORMAL, "Missing argument"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
335 |
} else { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
336 |
update_roster = scr_roster_color(status, wildcard, color) || |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
337 |
update_roster; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
338 |
} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
339 |
} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
340 |
- free_arg_lst(arglist); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
341 |
- g_free(wildcard); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
342 |
- } else if (!strcasecmp(subcmd, "muc")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
343 |
- char **arglist = split_arg(arg, 2, 0); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
344 |
- char *free_muc = to_utf8(*arglist); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
345 |
- const char *muc = free_muc, *mode = arglist[1]; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
346 |
- if (!muc || !*muc) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
347 |
- scr_LogPrint(LPRINT_NORMAL, "What MUC?"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
348 |
- else { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
349 |
- if (!strcmp(muc, ".")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
350 |
- if (!(muc = CURRENT_JID)) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
351 |
- scr_LogPrint(LPRINT_NORMAL, "No JID selected"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
352 |
- if (muc) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
353 |
- if (check_jid_syntax(muc) && strcmp(muc, "*")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
354 |
- scr_LogPrint(LPRINT_NORMAL, "Not a JID"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
355 |
- else { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
356 |
- if (!mode || !*mode || !strcasecmp(mode, "on")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
357 |
- scr_muc_color(muc, MC_ALL); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
358 |
- else if (!strcasecmp(mode, "preset")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
359 |
- scr_muc_color(muc, MC_PRESET); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
360 |
- else if (!strcasecmp(mode, "off")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
361 |
- scr_muc_color(muc, MC_OFF); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
362 |
- else if (!strcmp(mode, "-")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
363 |
- scr_muc_color(muc, MC_REMOVE); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
364 |
- else |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
365 |
- scr_LogPrint(LPRINT_NORMAL, "Unknown coloring mode"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
366 |
- } |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
367 |
+ } else if (subcmd == color_scmd_muc) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
368 |
+ const gchar *muc = options.cmds[1].options.args[0].value.arg; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
369 |
+ const gchar *mode = options.cmds[1].options.args[1].value.arg; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
370 |
+ if (!strcmp(muc, ".")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
371 |
+ if (!(muc = CURRENT_JID)) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
372 |
+ scr_LogPrint(LPRINT_NORMAL, "No JID selected"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
373 |
+ if (muc) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
374 |
+ if (check_jid_syntax(muc) && strcmp(muc, "*")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
375 |
+ scr_LogPrint(LPRINT_NORMAL, "Not a JID"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
376 |
+ else { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
377 |
+ if (!strcasecmp(mode, "on")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
378 |
+ scr_muc_color(muc, MC_ALL); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
379 |
+ else if (!strcasecmp(mode, "preset")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
380 |
+ scr_muc_color(muc, MC_PRESET); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
381 |
+ else if (!strcasecmp(mode, "off")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
382 |
+ scr_muc_color(muc, MC_OFF); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
383 |
+ else if (!strcmp(mode, "-")) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
384 |
+ scr_muc_color(muc, MC_REMOVE); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
385 |
+ else |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
386 |
+ scr_LogPrint(LPRINT_NORMAL, "Unknown coloring mode"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
387 |
} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
388 |
} |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
389 |
- free_arg_lst(arglist); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
390 |
- g_free(free_muc); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
391 |
- } else if (!strcasecmp(subcmd, "mucnick")) { |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
392 |
- char **arglist = split_arg(arg, 2, 0); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
393 |
- const char *nick = *arglist, *color = arglist[1]; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
394 |
- if (!nick || !*nick || !color || !*color) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
395 |
- scr_LogPrint(LPRINT_NORMAL, "Missing argument"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
396 |
- else |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
397 |
- scr_muc_nick_color(nick, color); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
398 |
- free_arg_lst(arglist); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
399 |
- } else |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
400 |
- scr_LogPrint(LPRINT_NORMAL, "Unrecognized parameter!"); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
401 |
- free_arg_lst(paramlst); |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
402 |
+ } else { // color_scmd_mucnick |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
403 |
+ const gchar *nick = options.cmds[2].options.args[0].value.arg; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
404 |
+ const gchar *color = options.cmds[2].options.args[1].value.arg; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
405 |
+ scr_muc_nick_color(nick, color); |
66 | 406 |
+ } |
407 |
+ |
|
408 |
+ cmdopts_free(&options); |
|
409 |
} |
|
410 |
||
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
411 |
-// cmd_setstatus(recipient, arg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
412 |
+// cmd_setstatus(recipient, status, message) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
413 |
// Set your Jabber status. |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
414 |
-// - if recipient is not NULL, the status is sent to this contact only |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
415 |
-// - arg must be "status message" (message is optional) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
416 |
-void cmd_setstatus(const char *recipient, const char *arg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
417 |
+// If recipient is not NULL, the status is sent to this contact only. |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
418 |
+void cmd_setstatus(const char *recipient, const char *status, const char *msg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
419 |
{ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
420 |
- char **paramlst; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
421 |
- char *status; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
422 |
- char *msg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
423 |
enum imstatus st; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
424 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
425 |
if (!xmpp_is_online()) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
426 |
@@ -1000,15 +1073,15 @@ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
427 |
if (!recipient) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
428 |
scr_check_auto_away(TRUE); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
429 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
430 |
- paramlst = split_arg(arg, 2, 1); // status, message |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
431 |
- status = *paramlst; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
432 |
- msg = *(paramlst+1); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
433 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
434 |
if (!status) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
435 |
- free_arg_lst(paramlst); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
436 |
return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
437 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
438 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
439 |
+ // Use provided message |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
440 |
+ if (msg && !*msg) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
441 |
+ msg = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
442 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
443 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
444 |
if (!strcasecmp(status, IMSTATUS_OFFLINE)) st = offline; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
445 |
else if (!strcasecmp(status, IMSTATUS_ONLINE)) st = available; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
446 |
else if (!strcasecmp(status, IMSTATUS_AVAILABLE)) st = available; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
447 |
@@ -1020,65 +1093,82 @@ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
448 |
else if (!strcasecmp(status, IMSTATUS_NOTAVAILABLE)) st = notavail; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
449 |
else if (!strcasecmp(status, IMSTATUS_FREE4CHAT)) st = freeforchat; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
450 |
else if (!strcasecmp(status, "message")) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
451 |
- if (!msg || !*msg) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
452 |
+ if (!msg) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
453 |
// We want a message. If there's none, we give up. |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
454 |
scr_LogPrint(LPRINT_NORMAL, "Missing parameter."); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
455 |
- free_arg_lst(paramlst); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
456 |
return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
457 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
458 |
st = xmpp_getstatus(); // Preserve current status |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
459 |
} else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
460 |
scr_LogPrint(LPRINT_NORMAL, "Unrecognized status!"); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
461 |
- free_arg_lst(paramlst); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
462 |
return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
463 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
464 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
465 |
- // Use provided message |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
466 |
- if (msg && !*msg) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
467 |
- msg = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
468 |
- } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
469 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
470 |
// If a recipient is specified, let's don't use default status messages |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
471 |
if (recipient && !msg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
472 |
msg = ""; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
473 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
474 |
xmpp_setstatus(st, recipient, msg, FALSE); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
475 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
476 |
- free_arg_lst(paramlst); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
477 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
478 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
479 |
static void do_status(char *arg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
480 |
{ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
481 |
- if (!*arg) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
482 |
+ cmdopts_t options = { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
483 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
484 |
+ (cmdarg_t[2]){ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
485 |
+ { 0, { .arg = NULL } }, // status |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
486 |
+ { CMDOPT_CATCHALL | CMDOPT_LAST, { .arg = NULL } }, // message |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
487 |
+ }, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
488 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
489 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
490 |
+ }; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
491 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
492 |
+ { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
493 |
+ const char *error = cmdopts_parse(arg, &options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
494 |
+ if (error != NULL) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
495 |
+ scr_log_print(LPRINT_NORMAL, error); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
496 |
+ return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
497 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
498 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
499 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
500 |
+ if (options.args[0].value.arg == NULL) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
501 |
const char *sm = xmpp_getstatusmsg(); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
502 |
scr_LogPrint(LPRINT_NORMAL, "Your status is: [%c] %s", |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
503 |
imstatus2char[xmpp_getstatus()], |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
504 |
(sm ? sm : "")); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
505 |
- return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
506 |
+ } else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
507 |
+ cmd_setstatus(NULL, options.args[0].value.arg, options.args[1].value.arg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
508 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
509 |
- arg = to_utf8(arg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
510 |
- cmd_setstatus(NULL, arg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
511 |
- g_free(arg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
512 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
513 |
+ cmdopts_free(&options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
514 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
515 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
516 |
static void do_status_to(char *arg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
517 |
{ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
518 |
- char **paramlst; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
519 |
+ cmdopts_t options = { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
520 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
521 |
+ (cmdarg_t[3]){ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
522 |
+ { CMDOPT_REQUIRED, { .arg = NULL } }, // jid |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
523 |
+ { CMDOPT_REQUIRED, { .arg = NULL } }, // status |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
524 |
+ { CMDOPT_CATCHALL | CMDOPT_LAST, { .arg = "" } }, // message |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
525 |
+ }, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
526 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
527 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
528 |
+ }; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
529 |
char *fjid, *st, *msg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
530 |
- char *jid_utf8 = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
531 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
532 |
- paramlst = split_arg(arg, 3, 1); // jid, status, [message] |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
533 |
- fjid = *paramlst; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
534 |
- st = *(paramlst+1); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
535 |
- msg = *(paramlst+2); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
536 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
537 |
- if (!fjid || !st) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
538 |
- scr_LogPrint(LPRINT_NORMAL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
539 |
- "Please specify both a Jabber ID and a status."); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
540 |
- free_arg_lst(paramlst); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
541 |
- return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
542 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
543 |
+ { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
544 |
+ const char *error = cmdopts_parse(arg, &options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
545 |
+ if (error != NULL) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
546 |
+ scr_log_print(LPRINT_NORMAL, error); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
547 |
+ return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
548 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
549 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
550 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
551 |
+ fjid = options.args[0].value.arg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
552 |
+ st = options.args[1].value.arg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
553 |
+ msg = options.args[2].value.arg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
554 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
555 |
// Allow things like /status_to "" away |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
556 |
if (!*fjid || !strcmp(fjid, ".")) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
557 |
fjid = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
558 |
@@ -1086,15 +1176,13 @@ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
559 |
if (fjid) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
560 |
// The JID has been specified. Quick check... |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
561 |
if (check_jid_syntax(fjid)) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
562 |
- scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
563 |
- "<%s> is not a valid Jabber ID.", fjid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
564 |
+ scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", fjid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
565 |
fjid = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
566 |
} else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
567 |
// Convert jid to lowercase |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
568 |
char *p = fjid; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
569 |
for ( ; *p && *p != JID_RESOURCE_SEPARATOR; p++) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
570 |
*p = tolower(*p); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
571 |
- fjid = jid_utf8 = to_utf8(fjid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
572 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
573 |
} else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
574 |
// Add the current buddy |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
575 |
@@ -1105,103 +1193,154 @@ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
576 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
577 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
578 |
if (fjid) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
579 |
- char *cmdline; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
580 |
- if (!msg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
581 |
- msg = ""; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
582 |
- msg = to_utf8(msg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
583 |
- cmdline = g_strdup_printf("%s %s", st, msg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
584 |
- scr_LogPrint(LPRINT_LOGNORM, "Sending to <%s> /status %s", fjid, cmdline); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
585 |
- cmd_setstatus(fjid, cmdline); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
586 |
- g_free(msg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
587 |
- g_free(cmdline); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
588 |
- g_free(jid_utf8); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
589 |
+ scr_LogPrint(LPRINT_LOGNORM, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
590 |
+ "Sending to <%s> /status %s %s", fjid, st, msg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
591 |
+ cmd_setstatus(fjid, st, msg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
592 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
593 |
- free_arg_lst(paramlst); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
594 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
595 |
+ cmdopts_free(&options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
596 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
597 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
598 |
static void do_add(char *arg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
599 |
{ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
600 |
- char **paramlst; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
601 |
- char *id, *nick; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
602 |
- char *jid_utf8 = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
603 |
+ cmdopts_t options = { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
604 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
605 |
+ (cmdarg_t[2]){ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
606 |
+ { 0, { .arg = "." } }, // jid |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
607 |
+ { CMDOPT_CATCHALL | CMDOPT_LAST, { .arg = NULL } }, // rostername |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
608 |
+ }, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
609 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
610 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
611 |
+ }; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
612 |
+ gchar *jid, *nick; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
613 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
614 |
if (!xmpp_is_online()) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
615 |
scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
616 |
return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
617 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
618 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
619 |
- paramlst = split_arg(arg, 2, 0); // jid, [nickname] |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
620 |
- id = *paramlst; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
621 |
- nick = *(paramlst+1); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
622 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
623 |
- if (!id) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
624 |
- nick = NULL; // Allow things like: /add "" nick |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
625 |
- else if (!*id || !strcmp(id, ".")) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
626 |
- id = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
627 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
628 |
- if (id) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
629 |
+ { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
630 |
+ const char *error = cmdopts_parse(arg, &options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
631 |
+ if (error) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
632 |
+ scr_log_print(LPRINT_NORMAL, error); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
633 |
+ return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
634 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
635 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
636 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
637 |
+ jid = options.args[0].value.arg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
638 |
+ nick = options.args[1].value.arg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
639 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
640 |
+ if (jid && (!*jid || !strcmp(jid, "."))) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
641 |
+ jid = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
642 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
643 |
+ if (jid) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
644 |
// The JID has been specified. Quick check... |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
645 |
- if (check_jid_syntax(id)) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
646 |
- scr_LogPrint(LPRINT_NORMAL|LPRINT_NOTUTF8, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
647 |
- "<%s> is not a valid Jabber ID.", id); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
648 |
- id = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
649 |
+ if (check_jid_syntax(jid)) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
650 |
+ scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
651 |
+ jid = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
652 |
} else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
653 |
- mc_strtolower(id); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
654 |
- id = jid_utf8 = to_utf8(id); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
655 |
+ mc_strtolower(jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
656 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
657 |
} else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
658 |
// Add the current buddy |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
659 |
if (current_buddy) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
660 |
- id = (char*)buddy_getjid(BUDDATA(current_buddy)); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
661 |
- if (!id) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
662 |
+ jid = (char*)buddy_getjid(BUDDATA(current_buddy)); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
663 |
+ if (!jid) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
664 |
scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
665 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
666 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
667 |
- if (nick) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
668 |
- nick = to_utf8(nick); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
669 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
670 |
- if (id) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
671 |
+ if (jid) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
672 |
// 2nd parameter = optional nickname |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
673 |
- xmpp_addbuddy(id, nick, NULL); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
674 |
+ xmpp_addbuddy(jid, nick, NULL); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
675 |
scr_LogPrint(LPRINT_LOGNORM, "Sent presence notification request to <%s>.", |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
676 |
- id); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
677 |
+ jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
678 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
679 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
680 |
- g_free(jid_utf8); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
681 |
- g_free(nick); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
682 |
- free_arg_lst(paramlst); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
683 |
+ cmdopts_free(&options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
684 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
685 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
686 |
static void do_del(char *arg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
687 |
{ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
688 |
- const char *bjid; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
689 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
690 |
- if (*arg) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
691 |
- scr_LogPrint(LPRINT_NORMAL, "This action does not require a parameter; " |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
692 |
- "the currently-selected buddy will be deleted."); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
693 |
+ cmdopts_t options = { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
694 |
+ (cmdopt_t[1]){ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
695 |
+ { CMDOPT_SWITCH | CMDOPT_LAST, 'n', "dryrun", { .swc = 0 } }, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
696 |
+ }, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
697 |
+ (cmdarg_t[1]){ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
698 |
+ { CMDOPT_LAST, { .arg = "." } }, // jid |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
699 |
+ }, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
700 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
701 |
+ NULL, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
702 |
+ }; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
703 |
+ gchar *jid; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
704 |
+ gpointer buddy; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
705 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
706 |
+ if (!xmpp_is_online()) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
707 |
+ scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
708 |
return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
709 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
710 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
711 |
- if (!current_buddy) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
712 |
- return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
713 |
- bjid = buddy_getjid(BUDDATA(current_buddy)); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
714 |
- if (!bjid) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
715 |
- return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
716 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
717 |
- if (buddy_gettype(BUDDATA(current_buddy)) & ROSTER_TYPE_ROOM) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
718 |
- // This is a chatroom |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
719 |
- if (buddy_getinsideroom(BUDDATA(current_buddy))) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
720 |
- scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!"); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
721 |
+ { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
722 |
+ const char *error = cmdopts_parse(arg, &options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
723 |
+ if (error) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
724 |
+ scr_log_print(LPRINT_NORMAL, error); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
725 |
return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
726 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
727 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
728 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
729 |
- // Close the buffer |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
730 |
- scr_buffer_purge(1, NULL); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
731 |
- |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
732 |
- scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", bjid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
733 |
- xmpp_delbuddy(bjid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
734 |
- scr_update_buddy_window(); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
735 |
+ jid = options.args[0].value.arg; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
736 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
737 |
+ if (jid && (!*jid || !strcmp(jid, "."))) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
738 |
+ jid = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
739 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
740 |
+ if (jid) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
741 |
+ // The JID has been specified. Quick check... |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
742 |
+ if (check_jid_syntax(jid)) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
743 |
+ scr_LogPrint(LPRINT_NORMAL, "<%s> is not a valid Jabber ID.", jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
744 |
+ jid = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
745 |
+ } else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
746 |
+ GSList *found; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
747 |
+ mc_strtolower(jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
748 |
+ found = roster_find(jid, jidsearch, ROSTER_TYPE_USER | |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
749 |
+ ROSTER_TYPE_AGENT | ROSTER_TYPE_GROUP); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
750 |
+ if (!found) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
751 |
+ scr_log_print(LPRINT_NORMAL, "Jabber ID <%s> is not in roster.", jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
752 |
+ jid = NULL; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
753 |
+ } else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
754 |
+ buddy = found -> data; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
755 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
756 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
757 |
+ } else { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
758 |
+ // Use current buddy |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
759 |
+ if (current_buddy) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
760 |
+ jid = (char*)buddy_getjid(BUDDATA(current_buddy)); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
761 |
+ if (!jid) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
762 |
+ scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
763 |
+ else |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
764 |
+ buddy = BUDDATA(current_buddy); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
765 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
766 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
767 |
+ if (jid) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
768 |
+ if (buddy_gettype(buddy) & ROSTER_TYPE_ROOM) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
769 |
+ // This is a chatroom |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
770 |
+ if (buddy_getinsideroom(buddy)) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
771 |
+ scr_LogPrint(LPRINT_NORMAL, "You haven't left this room!"); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
772 |
+ cmdopts_free(&options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
773 |
+ return; |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
774 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
775 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
776 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
777 |
+ scr_LogPrint(LPRINT_LOGNORM, "Removing <%s>...", jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
778 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
779 |
+ if (!options.opts[0].value.swc) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
780 |
+ // Close the buffer |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
781 |
+ scr_buffer_purge(1, jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
782 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
783 |
+ xmpp_delbuddy(jid); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
784 |
+ scr_update_buddy_window(); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
785 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
786 |
+ } |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
787 |
+ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
788 |
+ cmdopts_free(&options); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
789 |
} |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
790 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
791 |
static void do_group(char *arg) |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
792 |
@@ -1634,130 +1773,109 @@ |
65 | 793 |
|
794 |
static void do_say_to(char *arg) |
|
795 |
{ |
|
796 |
- char **paramlst; |
|
797 |
- char *fjid, *msg_utf8; |
|
798 |
+ char *fjid; |
|
799 |
char *msg; |
|
800 |
- char *unescaped_msg = NULL; |
|
801 |
- char *uncompletedfjid = NULL; |
|
802 |
- char *file = NULL; |
|
803 |
+ char *file; |
|
804 |
+ gchar *freeme = NULL; // fjid |
|
805 |
+ gchar *freeme2 = NULL; // msg |
|
806 |
LmMessageSubType msg_type = LM_MESSAGE_SUB_TYPE_NOT_SET; |
|
807 |
- bool quiet = FALSE; |
|
808 |
- bool eval = FALSE; |
|
809 |
+ cmdopts_t options = { |
|
810 |
+ (cmdopt_t[5]){ |
|
811 |
+ { CMDOPT_SWITCH, 'n', "normal", { .swc = 0 } }, |
|
812 |
+ { CMDOPT_SWITCH, 'h', "headline", { .swc = 0 } }, |
|
813 |
+ { CMDOPT_SWITCH, 'e', "escapes", { .swc = 0 } }, |
|
814 |
+ { CMDOPT_SWITCH, 'q', "quiet", { .swc = 0 } }, |
|
815 |
+ { CMDOPT_LAST, 'f', "file", { .opt = NULL } }, |
|
816 |
+ }, |
|
817 |
+ (cmdarg_t[2]){ |
|
818 |
+ { CMDOPT_REQUIRED, { .arg = NULL } }, |
|
819 |
+ { CMDOPT_LAST | CMDOPT_PLAIN | CMDOPT_CATCHALL, { .arg = NULL } }, |
|
820 |
+ }, |
|
821 |
+ NULL, |
|
822 |
+ NULL, |
|
823 |
+ }; |
|
824 |
||
825 |
if (!xmpp_is_online()) { |
|
826 |
scr_LogPrint(LPRINT_NORMAL, "You are not connected."); |
|
827 |
return; |
|
828 |
} |
|
829 |
||
830 |
- msg_type = scan_mtype(&arg); |
|
831 |
- paramlst = split_arg(arg, 2, 1); // jid, message (or option, jid, message) |
|
832 |
- |
|
833 |
- if (!*paramlst) { // No parameter? |
|
834 |
- scr_LogPrint(LPRINT_NORMAL, "Please specify a Jabber ID."); |
|
835 |
- free_arg_lst(paramlst); |
|
836 |
- return; |
|
837 |
+ { // parse arguments |
|
838 |
+ const char *error = cmdopts_parse(arg, &options); |
|
839 |
+ if (error != NULL) { |
|
840 |
+ scr_log_print(LPRINT_NORMAL, error); |
|
841 |
+ return; |
|
842 |
+ } |
|
843 |
} |
|
844 |
||
845 |
- // Check for an option parameter |
|
846 |
- while (*paramlst) { |
|
847 |
- if (!strcmp(*paramlst, "-q")) { |
|
848 |
- char **oldparamlst = paramlst; |
|
849 |
- paramlst = split_arg(*(oldparamlst+1), 2, 1); // jid, message |
|
850 |
- free_arg_lst(oldparamlst); |
|
851 |
- quiet = TRUE; |
|
852 |
- } else if (!strcmp(*paramlst, "-e")) { |
|
853 |
- char **oldparamlst = paramlst; |
|
854 |
- paramlst = split_arg(*(oldparamlst+1), 2, 1); // jid, message |
|
855 |
- free_arg_lst(oldparamlst); |
|
856 |
- eval = TRUE; |
|
857 |
- } else if (!strcmp(*paramlst, "-f")) { |
|
858 |
- char **oldparamlst = paramlst; |
|
859 |
- paramlst = split_arg(*(oldparamlst+1), 2, 1); // filename, jid |
|
860 |
- free_arg_lst(oldparamlst); |
|
861 |
- if (!*paramlst) { |
|
862 |
- scr_LogPrint(LPRINT_NORMAL, "Wrong usage."); |
|
863 |
- free_arg_lst(paramlst); |
|
864 |
- return; |
|
865 |
- } |
|
866 |
- file = g_strdup(*paramlst); |
|
867 |
- // One more parameter shift... |
|
868 |
- oldparamlst = paramlst; |
|
869 |
- paramlst = split_arg(*(oldparamlst+1), 2, 1); // jid, nothing |
|
870 |
- free_arg_lst(oldparamlst); |
|
871 |
- } else |
|
872 |
- break; |
|
873 |
+ if (options.opts[0].value.swc) { |
|
874 |
+ msg_type = LM_MESSAGE_SUB_TYPE_NORMAL; |
|
875 |
+ } else if (options.opts[1].value.swc) { |
|
876 |
+ msg_type = LM_MESSAGE_SUB_TYPE_HEADLINE; |
|
877 |
} |
|
878 |
||
879 |
- if (!*paramlst) { |
|
880 |
- scr_LogPrint(LPRINT_NORMAL, "Wrong usage."); |
|
881 |
- free_arg_lst(paramlst); |
|
882 |
- return; |
|
883 |
- } |
|
884 |
- |
|
885 |
- fjid = *paramlst; |
|
886 |
- msg = *(paramlst+1); |
|
887 |
- |
|
888 |
+ fjid = options.args[0].value.arg; |
|
889 |
+ msg = options.args[1].value.arg; |
|
890 |
+ file = options.opts[4].value.opt; |
|
891 |
+ |
|
892 |
+ // ideally, this should go to commandline parsing subsystem |
|
893 |
if (fjid[0] == '.') { |
|
894 |
const gchar *cjid = (current_buddy ? CURRENT_JID : NULL); |
|
895 |
if (fjid[1] == '\0') { |
|
896 |
- fjid = g_strdup(cjid); |
|
897 |
+ fjid = (char *)cjid; // FIXME |
|
898 |
} else if (fjid[1] == JID_RESOURCE_SEPARATOR) { |
|
899 |
char *res_utf8 = to_utf8(fjid+2); |
|
900 |
- fjid = g_strdup_printf("%s%c%s", cjid, JID_RESOURCE_SEPARATOR, res_utf8); |
|
901 |
+ freeme = fjid = g_strdup_printf("%s%c%s", cjid, JID_RESOURCE_SEPARATOR, res_utf8); |
|
902 |
g_free(res_utf8); |
|
903 |
- } else |
|
904 |
- fjid = to_utf8(fjid); |
|
905 |
- } else |
|
906 |
- fjid = to_utf8(fjid); |
|
907 |
- |
|
908 |
+ } |
|
909 |
+ } |
|
910 |
+ |
|
911 |
+ // ditto |
|
912 |
if (!strchr(fjid, JID_DOMAIN_SEPARATOR)) { |
|
913 |
const gchar *append_server = settings_opt_get("default_server"); |
|
914 |
if (append_server) { |
|
915 |
gchar *res = strchr(fjid, JID_RESOURCE_SEPARATOR); |
|
916 |
- uncompletedfjid = fjid; |
|
917 |
if (res) { |
|
918 |
*res++ = '\0'; |
|
919 |
fjid = g_strdup_printf("%s%c%s%c%s", fjid, JID_DOMAIN_SEPARATOR, append_server, |
|
920 |
JID_RESOURCE_SEPARATOR, res); |
|
921 |
} else |
|
922 |
fjid = g_strdup_printf("%s%c%s", fjid, JID_DOMAIN_SEPARATOR, append_server); |
|
923 |
+ g_free(freeme); |
|
924 |
+ freeme = fjid; |
|
925 |
} |
|
926 |
} |
|
927 |
||
928 |
+ // as well |
|
929 |
if (check_jid_syntax(fjid)) { |
|
930 |
scr_LogPrint(LPRINT_NORMAL, "Please specify a valid Jabber ID."); |
|
931 |
- free_arg_lst(paramlst); |
|
932 |
- g_free(uncompletedfjid); |
|
933 |
- g_free(fjid); |
|
934 |
+ g_free(freeme); |
|
935 |
return; |
|
936 |
} |
|
937 |
||
938 |
- if (!file) { |
|
939 |
- msg_utf8 = to_utf8(msg); |
|
940 |
- if (eval) { |
|
941 |
- unescaped_msg = ut_unescape_tabs_cr(msg_utf8); |
|
942 |
+ if (file == NULL) { |
|
943 |
+ if (options.opts[2].value.swc) { |
|
944 |
+ freeme2 = ut_unescape_tabs_cr(msg); |
|
945 |
// We must not free() if the original string was returned |
|
946 |
- if (unescaped_msg == msg_utf8) |
|
947 |
- unescaped_msg = NULL; |
|
948 |
+ if (freeme2 == msg) |
|
949 |
+ freeme2 = NULL; |
|
950 |
+ else |
|
951 |
+ msg = freeme2; |
|
952 |
} |
|
953 |
- msg = (unescaped_msg ? unescaped_msg : msg_utf8); |
|
954 |
} else { |
|
955 |
char *filename_xp; |
|
956 |
if (msg) |
|
957 |
scr_LogPrint(LPRINT_NORMAL, "say_to: extra parameter ignored."); |
|
958 |
filename_xp = expand_filename(file); |
|
959 |
- msg = msg_utf8 = load_message_from_file(filename_xp); |
|
960 |
+ freeme2 = msg = load_message_from_file(filename_xp); |
|
961 |
g_free(filename_xp); |
|
962 |
- g_free(file); |
|
963 |
} |
|
964 |
||
965 |
- send_message_to(fjid, msg, NULL, msg_type, quiet); |
|
966 |
- |
|
967 |
- g_free(uncompletedfjid); |
|
968 |
- g_free(fjid); |
|
969 |
- g_free(msg_utf8); |
|
970 |
- g_free(unescaped_msg); |
|
971 |
- free_arg_lst(paramlst); |
|
972 |
+ send_message_to(fjid, msg, NULL, msg_type, options.opts[3].value.swc); |
|
973 |
+ |
|
974 |
+ cmdopts_free(&options); |
|
975 |
+ g_free(freeme); |
|
976 |
+ g_free(freeme2); |
|
977 |
} |
|
978 |
||
979 |
// buffer_updown(updown, nblines) |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
980 |
diff -r 92fa48ef53c9 mcabber/mcabber/commands.h |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
981 |
--- a/mcabber/mcabber/commands.h Sun Jan 27 00:40:37 2013 +0200 |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
982 |
+++ b/mcabber/mcabber/commands.h Mon Feb 25 22:07:41 2013 +0200 |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
983 |
@@ -29,7 +29,8 @@ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
984 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
985 |
void cmd_room_whois(gpointer bud, const char *nick, guint interactive); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
986 |
void cmd_room_leave(gpointer bud, char *arg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
987 |
-void cmd_setstatus(const char *recipient, const char *arg); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
988 |
+void cmd_setstatus(const char *recipient, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
989 |
+ const char *status, const char *message); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
990 |
void say_cmd(char *arg, int parse_flags); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
991 |
|
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
992 |
#endif /* __MCABBER_COMMANDS_H__ */ |
66 | 993 |
diff -r 92fa48ef53c9 mcabber/mcabber/roster.c |
994 |
--- a/mcabber/mcabber/roster.c Sun Jan 27 00:40:37 2013 +0200 |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
995 |
+++ b/mcabber/mcabber/roster.c Mon Feb 25 22:07:41 2013 +0200 |
66 | 996 |
@@ -1586,13 +1586,14 @@ |
997 |
// Look for a buddy whose name or jid contains string. |
|
998 |
// Search begins at current_buddy; if no match is found in the the buddylist, |
|
999 |
// return NULL; |
|
1000 |
+// Note: before this function considered its argument to be in local encoding, |
|
1001 |
+// now argument must be in utf8. |
|
1002 |
GList *buddy_search(char *string) |
|
1003 |
{ |
|
1004 |
GList *buddy = current_buddy; |
|
1005 |
roster *roster_usr; |
|
1006 |
if (!buddylist || !current_buddy) return NULL; |
|
1007 |
for (;;) { |
|
1008 |
- gchar *jid_locale, *name_locale; |
|
1009 |
char *found = NULL; |
|
1010 |
||
1011 |
buddy = g_list_next(buddy); |
|
1012 |
@@ -1601,17 +1602,13 @@ |
|
1013 |
||
1014 |
roster_usr = (roster*)buddy->data; |
|
1015 |
||
1016 |
- jid_locale = from_utf8(roster_usr->jid); |
|
1017 |
- if (jid_locale) { |
|
1018 |
- found = strcasestr(jid_locale, string); |
|
1019 |
- g_free(jid_locale); |
|
1020 |
+ if (roster_usr->jid) { |
|
1021 |
+ found = strcasestr(roster_usr->jid, string); |
|
1022 |
if (found) |
|
1023 |
return buddy; |
|
1024 |
} |
|
1025 |
- name_locale = from_utf8(roster_usr->name); |
|
1026 |
- if (name_locale) { |
|
1027 |
- found = strcasestr(name_locale, string); |
|
1028 |
- g_free(name_locale); |
|
1029 |
+ if (roster_usr->name) { |
|
1030 |
+ found = strcasestr(roster_usr->name, string); |
|
1031 |
if (found) |
|
1032 |
return buddy; |
|
1033 |
} |
|
64 | 1034 |
diff -r 92fa48ef53c9 mcabber/mcabber/utils.c |
1035 |
--- a/mcabber/mcabber/utils.c Sun Jan 27 00:40:37 2013 +0200 |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1036 |
+++ b/mcabber/mcabber/utils.c Mon Feb 25 22:07:41 2013 +0200 |
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
1037 |
@@ -555,6 +555,317 @@ |
64 | 1038 |
*str = tolower(*str); |
1039 |
} |
|
1040 |
||
1041 |
+// in_space -> in_space, in_optstart, in_argstart |
|
1042 |
+// in_optstart -> in_shortoptend, in_longoptstart, in_argstart ('-') |
|
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
1043 |
+// in_shortoptend -> in_space, in_argstart, error |
64 | 1044 |
+// in_longoptstart -> in_longopt, in_space, in_argstart ('---') |
1045 |
+// in_longopt -> in_longopt, in_space, error |
|
1046 |
+// in_argstart -> in_arg, success |
|
1047 |
+// in_arg -> in_arg, in_space, error |
|
1048 |
+ |
|
1049 |
+// arguments: rw buffer in utf8, end of buffer pointer, options description struct |
|
1050 |
+static const char *cmdopts_parse_internal(gchar *arg, gchar *e, cmdopts_t *options) |
|
1051 |
+{ |
|
1052 |
+ // parser state |
|
1053 |
+ enum { |
|
1054 |
+ in_space, |
|
1055 |
+ in_optstart, |
|
1056 |
+ in_shortoptstart, |
|
1057 |
+ in_shortoptend, |
|
1058 |
+ in_longoptstart, |
|
1059 |
+ in_longopt, |
|
1060 |
+ in_argstart, |
|
1061 |
+ in_arg, |
|
1062 |
+ } state = in_space; |
|
1063 |
+ // current pointer, start of object pointer |
|
1064 |
+ gchar *p, *s; |
|
66 | 1065 |
+ // inside of quotes in non-plain argument |
64 | 1066 |
+ gboolean quotes = FALSE; |
66 | 1067 |
+ // non-option argument or end-of-options marker encountered |
64 | 1068 |
+ gboolean opts_ended = FALSE; |
1069 |
+ // option, for which argument is currently parsed |
|
1070 |
+ cmdopt_t *option = NULL; |
|
1071 |
+ // argument, that we currently parse |
|
1072 |
+ cmdarg_t *argument = NULL; |
|
1073 |
+ // flags of option/argument |
|
1074 |
+ guint flags = 0; |
|
1075 |
+ // error message to return |
|
1076 |
+ const char *error = NULL; |
|
1077 |
+ |
|
1078 |
+ p = arg; |
|
1079 |
+ // we allow parser to do one extra run on final '\0' |
|
1080 |
+ while (p <= e && error == NULL) { |
|
1081 |
+ if (state == in_space) { // space between args/options |
|
1082 |
+ if (*p == ' ' || *p == '\0') { // still space |
|
1083 |
+ p ++; |
|
1084 |
+ } else if (*p == '-' && !opts_ended) { // option |
|
1085 |
+ state = in_optstart; |
|
1086 |
+ p ++; |
|
1087 |
+ } else { // argument |
|
1088 |
+ if (!option) { |
|
1089 |
+ opts_ended = TRUE; |
|
1090 |
+ } |
|
1091 |
+ s = p; |
|
1092 |
+ state = in_argstart; |
|
1093 |
+ } |
|
1094 |
+ } else if (state == in_optstart) { // long/short option |
|
1095 |
+ if (*p == ' ' || *p == '\0') { // argument '-' |
|
1096 |
+ opts_ended = TRUE; |
|
1097 |
+ s = p - 1; |
|
1098 |
+ state = in_argstart; |
|
1099 |
+ } else if (*p == '-') { // long option |
|
1100 |
+ state = in_longoptstart; |
|
1101 |
+ p ++; |
|
1102 |
+ } else { // short option |
|
1103 |
+ s = p; |
|
1104 |
+ state = in_shortoptend; |
|
1105 |
+ p ++; |
|
1106 |
+ } |
|
1107 |
+ } else if (state == in_shortoptend) { // short option |
|
1108 |
+ if (*p == ' ' || *p == '\0') { // option really ended |
|
1109 |
+ gboolean found = FALSE; |
|
1110 |
+ option = options -> opts; |
|
1111 |
+ if (option) { |
|
1112 |
+ do { |
|
1113 |
+ if (option -> shortopt == *s) { |
|
1114 |
+ found = TRUE; |
|
1115 |
+ break; |
|
1116 |
+ } |
|
1117 |
+ } while ((!(option++ -> flags & CMDOPT_LAST)) && !found); |
|
1118 |
+ } |
|
1119 |
+ if (found) { // option is known |
|
1120 |
+ if (option -> flags & CMDOPT_SWITCH) { // it is switch |
|
1121 |
+ if (option -> flags & CMDOPT_CATCHALL) { |
|
1122 |
+ option -> value.swc ++; |
|
1123 |
+ } else { |
|
1124 |
+ option -> value.swc = !option -> value.swc; |
|
1125 |
+ } |
|
1126 |
+ option = NULL; |
|
1127 |
+ } else { // it is option |
|
1128 |
+ if (*p == '\0') { |
|
1129 |
+ error = "Short option argument not specified"; |
|
1130 |
+ } |
|
1131 |
+ } |
|
1132 |
+ state = in_space; |
|
1133 |
+ p ++; |
|
1134 |
+ } else { // option is unknown |
|
1135 |
+ error = "Unknown short option"; |
|
1136 |
+ } |
|
1137 |
+ } else { // short option not ended |
|
67
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
1138 |
+ // consider it argument (to allow -autojoin) |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
1139 |
+ p --; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
1140 |
+ opts_ended = TRUE; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
1141 |
+ s = p - 1; |
a2f3afbc4000
[cmdopts] convert /color
Myhailo Danylenko <isbear@ukrpost.net>
parents:
66
diff
changeset
|
1142 |
+ state = in_argstart; |
64 | 1143 |
+ } |
1144 |
+ } else if (state == in_longoptstart) { // long option initialization |
|
1145 |
+ if (*p == ' ' || *p == '\0') { // end of options '--' |
|
1146 |
+ opts_ended = TRUE; |
|
1147 |
+ state = in_space; |
|
1148 |
+ p ++; |
|
1149 |
+ } else if (*p == '-') { // argument, starting with '---' |
|
1150 |
+ opts_ended = TRUE; |
|
1151 |
+ s = p - 2; |
|
1152 |
+ state = in_argstart; |
|
1153 |
+ } else { // it is long option |
|
1154 |
+ s = p; |
|
1155 |
+ state = in_longopt; |
|
1156 |
+ p ++; |
|
1157 |
+ } |
|
1158 |
+ } else if (state == in_longopt) { // long option name |
|
1159 |
+ if (*p == ' ' || *p == '\0') { // long option ended |
|
1160 |
+ gboolean found = FALSE; |
|
1161 |
+ gboolean eof = *p == '\0'; |
|
1162 |
+ *p = '\0'; |
|
1163 |
+ option = options -> opts; |
|
1164 |
+ if (option) { |
|
1165 |
+ do { |
|
1166 |
+ if (!g_strcmp0 (option -> longopt, s)) { |
|
1167 |
+ found = TRUE; |
|
1168 |
+ break; |
|
1169 |
+ } |
|
1170 |
+ } while ((!(option++ -> flags & CMDOPT_LAST)) && !found); |
|
1171 |
+ } |
|
1172 |
+ if (found) { // option is known |
|
1173 |
+ if (option -> flags & CMDOPT_SWITCH) { // it is switch |
|
1174 |
+ if (option -> flags & CMDOPT_CATCHALL) { |
|
1175 |
+ option -> value.swc ++; |
|
1176 |
+ } else { |
|
1177 |
+ option -> value.swc = !option -> value.swc; |
|
1178 |
+ } |
|
1179 |
+ option = NULL; |
|
1180 |
+ } else { // it is option |
|
1181 |
+ if (eof) { |
|
1182 |
+ error = "Long option argument not specified"; |
|
1183 |
+ } |
|
1184 |
+ } |
|
1185 |
+ state = in_space; |
|
1186 |
+ p ++; |
|
1187 |
+ } else { // option is unknown |
|
1188 |
+ error = "Unknown long option"; |
|
1189 |
+ } |
|
1190 |
+ } else { // still long option |
|
1191 |
+ p ++; |
|
1192 |
+ } |
|
1193 |
+ } else if (state == in_argstart) { // option/command argument initialization |
|
1194 |
+ if (option) { |
|
1195 |
+ flags = option -> flags & ~CMDOPT_CATCHALL; // catchall in options indicates multi-options |
|
1196 |
+ } else { |
|
1197 |
+ if (!argument) { |
|
1198 |
+ argument = options -> args; |
|
1199 |
+ } |
|
1200 |
+ if (!argument) { // no need to parse arguments at all |
|
1201 |
+ break; |
|
1202 |
+ } |
|
1203 |
+ flags = argument -> flags; |
|
1204 |
+ if ((flags & CMDOPT_CATCHALL) && (flags & CMDOPT_PLAIN)) { // can finish right away |
|
1205 |
+ argument -> value.arg = s; |
|
1206 |
+ break; |
|
1207 |
+ } |
|
1208 |
+ } |
|
1209 |
+ quotes = FALSE; |
|
1210 |
+ state = in_arg; |
|
1211 |
+ } else if (state == in_arg) { // option/command argument value |
|
1212 |
+ if (*p == '\0' && quotes) { // end of line in quotes |
|
1213 |
+ error = "Unfinished quoted argument"; |
|
1214 |
+ } else if ((*p == ' ' && (!quotes) && !(flags & CMDOPT_CATCHALL)) || *p == '\0') { // argument ended |
|
1215 |
+ if (*p != '\0') { |
|
1216 |
+ *p = '\0'; |
|
1217 |
+ p ++; |
|
1218 |
+ } |
|
1219 |
+ if (option) { // option argument |
|
1220 |
+ if (option -> flags & CMDOPT_CATCHALL) { // multi-value option |
|
1221 |
+ option -> value.multiopt = g_slist_append (option -> value.multiopt, s); |
|
1222 |
+ } else { // single-value option |
|
1223 |
+ option -> value.opt = s; |
|
1224 |
+ } |
|
1225 |
+ option = NULL; |
|
1226 |
+ } else { // command argument |
|
1227 |
+ if (argument -> flags & CMDOPT_SUBCOMMAND) { |
|
1228 |
+ gboolean found = FALSE; |
|
1229 |
+ subcmd_t *subcommand = options -> cmds; |
|
1230 |
+ if (subcommand) { |
|
1231 |
+ do { |
|
1232 |
+ if (!g_strcmp0(s, subcommand -> name)) { |
|
1233 |
+ found = TRUE; |
|
1234 |
+ break; |
|
1235 |
+ } |
|
1236 |
+ } while (!(subcommand++ -> flags & CMDOPT_LAST)); |
|
1237 |
+ } |
|
1238 |
+ if (found) { |
|
1239 |
+ argument -> value.cmd = subcommand; |
|
66 | 1240 |
+ error = cmdopts_parse_internal(p, e, &(subcommand -> options)); |
64 | 1241 |
+ break; |
1242 |
+ } else { |
|
1243 |
+ error = "Unknown subcommand"; |
|
1244 |
+ } |
|
1245 |
+ } else { |
|
1246 |
+ argument -> value.arg = s; |
|
1247 |
+ if (argument -> flags & CMDOPT_LAST) { // last argument |
|
1248 |
+ break; |
|
1249 |
+ } |
|
1250 |
+ argument ++; |
|
1251 |
+ } |
|
1252 |
+ } |
|
1253 |
+ state = in_space; |
|
1254 |
+ } else if (*p == '\\' && !(flags & CMDOPT_PLAIN)) { // next char escape |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1255 |
+ memmove(p, p+1, e-(p+1)+1); |
64 | 1256 |
+ e --; |
1257 |
+ if (*p == '\0') { |
|
1258 |
+ error = "Escape at the end of line"; |
|
1259 |
+ } |
|
1260 |
+ p ++; |
|
1261 |
+ } else if (*p == '"' && !(flags & CMDOPT_PLAIN)) { // quotation start/end |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1262 |
+ memmove(p, p+1, e-(p+1)+1); |
64 | 1263 |
+ e --; |
1264 |
+ quotes = !quotes; |
|
1265 |
+ } else { // still argument |
|
1266 |
+ p ++; |
|
1267 |
+ } |
|
1268 |
+ } |
|
1269 |
+ } |
|
1270 |
+ |
|
1271 |
+ // check required flags on options |
|
1272 |
+ if (error == NULL && options -> opts) { |
|
1273 |
+ option = options -> opts; |
|
1274 |
+ do { |
|
1275 |
+ if (option -> flags & CMDOPT_REQUIRED) { |
|
1276 |
+ if (option -> flags & CMDOPT_SWITCH) { |
|
1277 |
+ // no way to check trigger switches, but no point in it as well |
|
1278 |
+ if (option -> flags & CMDOPT_CATCHALL && option -> value.swc == 0) { |
|
1279 |
+ error = "Required switch is not specified"; |
|
1280 |
+ break; |
|
1281 |
+ } |
|
1282 |
+ } else { |
|
1283 |
+ if ((option -> flags & CMDOPT_CATCHALL && option -> value.multiopt == NULL) || |
|
1284 |
+ ((!(option -> flags & CMDOPT_CATCHALL)) && option -> value.opt == NULL)) { |
|
1285 |
+ error = "Required option is not specified"; |
|
1286 |
+ break; |
|
1287 |
+ } |
|
1288 |
+ } |
|
1289 |
+ } |
|
1290 |
+ } while (!(option++ -> flags & CMDOPT_LAST)); |
|
1291 |
+ } |
|
1292 |
+ |
|
1293 |
+ // check required flags on arguments |
|
1294 |
+ if (error == NULL && options -> args) { |
|
1295 |
+ argument = options -> args; |
|
1296 |
+ do { |
|
1297 |
+ if (argument -> flags & CMDOPT_REQUIRED) { |
|
65 | 1298 |
+ if (argument -> flags & CMDOPT_SUBCOMMAND) { |
1299 |
+ if (argument -> value.cmd == NULL) { |
|
1300 |
+ error = "Subcommand is not specified"; |
|
1301 |
+ break; |
|
1302 |
+ } |
|
1303 |
+ } else { |
|
1304 |
+ if (argument -> value.arg == NULL) { |
|
1305 |
+ error = "Required argument is not specified"; |
|
1306 |
+ break; |
|
1307 |
+ } |
|
64 | 1308 |
+ } |
1309 |
+ } |
|
1310 |
+ } while (!(argument++ -> flags & CMDOPT_LAST)); |
|
1311 |
+ } |
|
1312 |
+ |
|
1313 |
+ return error; |
|
1314 |
+} |
|
1315 |
+ |
|
1316 |
+const char *cmdopts_parse(const char *arg, cmdopts_t *options) |
|
1317 |
+{ |
|
1318 |
+ gchar *utf8 = to_utf8(arg); |
|
1319 |
+ gchar *e; |
|
66 | 1320 |
+ const char *error; |
64 | 1321 |
+ |
1322 |
+ for (e = utf8; *e; e++); |
|
1323 |
+ options -> freeme = utf8; |
|
66 | 1324 |
+ error = cmdopts_parse_internal(utf8, e, options); |
1325 |
+ if (error) { |
|
1326 |
+ cmdopts_free(options); |
|
1327 |
+ } |
|
1328 |
+ return error; |
|
64 | 1329 |
+} |
1330 |
+ |
|
1331 |
+void cmdopts_free(cmdopts_t *options) |
|
1332 |
+{ |
|
1333 |
+ cmdopt_t *option = options -> opts; |
|
1334 |
+ subcmd_t *subcommand = options -> cmds; |
|
1335 |
+ if (option) { |
|
1336 |
+ do { |
|
1337 |
+ if ((option -> flags & (CMDOPT_CATCHALL|CMDOPT_SWITCH)) == CMDOPT_CATCHALL) { |
|
1338 |
+ g_slist_free(option -> value.multiopt); |
|
1339 |
+ option -> value.multiopt = NULL; |
|
1340 |
+ } |
|
1341 |
+ } while (!(option++ -> flags & CMDOPT_LAST)); |
|
1342 |
+ } |
|
1343 |
+ if (subcommand) { |
|
1344 |
+ do { |
|
66 | 1345 |
+ cmdopts_free(&(subcommand -> options)); |
64 | 1346 |
+ } while (!(subcommand++ -> flags & CMDOPT_LAST)); |
1347 |
+ } |
|
1348 |
+ g_free(options -> freeme); |
|
1349 |
+ options -> freeme = NULL; |
|
1350 |
+} |
|
1351 |
+ |
|
1352 |
// strip_arg_special_chars(string) |
|
1353 |
// Remove quotes and backslashes before an escaped quote |
|
1354 |
// Only quotes need a backslash |
|
1355 |
diff -r 92fa48ef53c9 mcabber/mcabber/utils.h |
|
1356 |
--- a/mcabber/mcabber/utils.h Sun Jan 27 00:40:37 2013 +0200 |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1357 |
+++ b/mcabber/mcabber/utils.h Mon Feb 25 22:07:41 2013 +0200 |
66 | 1358 |
@@ -43,6 +43,101 @@ |
64 | 1359 |
char **split_arg(const char *arg, unsigned int n, int dontstriplast); |
1360 |
void free_arg_lst(char **arglst); |
|
1361 |
||
1362 |
+// error cmdopts_parse (argstring, optionlist) |
|
1363 |
+// Function parses command argument string according to provided list of |
|
1364 |
+// options and arguments. If in this process it encounters an error, it |
|
1365 |
+// returns error string (that should be displayed and g_free'd afterwards). |
|
1366 |
+// Note: For now returned error is constant string, that shouldn't be freed, |
|
1367 |
+// but we're getting there. |
|
1368 |
+// After processing you should free freeme and any GSList values of catchall |
|
1369 |
+// options (only lists itself, not values). For your convenience, there is |
|
1370 |
+// cmdopts_free(), that does exactly that. |
|
1371 |
+// The function recognizes four kinds of expressions: |
|
1372 |
+// - Options with arguments in a form '-f bar' or '--foo bar' |
|
1373 |
+// - Switches without arguments in a form '-f' or '--foo' |
|
1374 |
+// - End-of-options marker '--' |
|
1375 |
+// - Individual arguments ('-' and '---' are considered arguments too) |
|
1376 |
+// To define command line syntax, you pass cmdopts_t struct, that contains |
|
1377 |
+// two contiguous lists of cmdopt_t and cmdarg_t structs accordingly. The |
|
1378 |
+// last struct in list must have CMDOPT_LAST flag set. |
|
1379 |
+// You can specify your own default values, they will be replaced/appended |
|
1380 |
+// if needed. |
|
1381 |
+// You can omit specifying longopt or shortopt (put NULL or '\0' there). |
|
1382 |
+// Note: returned values and arguments are already converted to utf8. |
|
1383 |
+ |
|
1384 |
+// Flags: |
|
1385 |
+// Only applies to options, defined if option does not have argument. |
|
65 | 1386 |
+#define CMDOPT_SWITCH ( 1<<0 ) |
64 | 1387 |
+// Don't process quotes and escapes in argument (applies to option arguments too). |
1388 |
+#define CMDOPT_PLAIN ( 1<<1 ) |
|
1389 |
+// For options - put all encountered values into GSList value.multiopt |
|
1390 |
+// instead of overwriting value.opt. |
|
1391 |
+// For switches - increment value.swc instead of logical flipping. |
|
1392 |
+// For arguments - grab the rest of the line without splitting on spaces. |
|
1393 |
+// Implicitly last argument. |
|
65 | 1394 |
+#define CMDOPT_CATCHALL ( 1<<2 ) |
64 | 1395 |
+// Option/argument must have value. |
65 | 1396 |
+#define CMDOPT_REQUIRED ( 1<<3 ) |
64 | 1397 |
+// Last entry in struct sequence. |
65 | 1398 |
+#define CMDOPT_LAST ( 1<<4 ) |
64 | 1399 |
+// Argument only, argument is the name for subcommand. |
1400 |
+// Implicitly last argument. |
|
65 | 1401 |
+#define CMDOPT_SUBCOMMAND ( 1<<5 ) |
64 | 1402 |
+ |
66 | 1403 |
+// FURTHER TODO: |
1404 |
+// Allow to specify catchall argument in the middle of string (requires some reverse parser)? |
|
1405 |
+// Better error messages (caller frees them) |
|
1406 |
+// --help generates error with short usage, based on info in options struct |
|
1407 |
+ |
|
64 | 1408 |
+// thoughts about future: |
66 | 1409 |
+// integration with command structure |
64 | 1410 |
+// cmdopt/cmdarg struct contains argument type, that implies completion id and argument correctness checks |
1411 |
+// cmdopt/cmdarg struct contains default value |
|
1412 |
+// when building completion for command, we allow options (if not before --) |
|
1413 |
+// |
|
66 | 1414 |
+// so, the process of command execution would look like: |
64 | 1415 |
+// - we walk through the options, set default values |
66 | 1416 |
+// - we parse argument string, populating options - on this or on next step |
1417 |
+// - we check for required options availability - we can call generic argument check routine, based on argument type |
|
64 | 1418 |
+// - we call callback |
1419 |
+// - we free resources |
|
1420 |
+typedef struct cmdopts_struct cmdopts_t; |
|
66 | 1421 |
+typedef struct subcmd_struct subcmd_t; |
1422 |
+typedef union { |
|
1423 |
+ GSList *multiopt; |
|
1424 |
+ gchar *opt; |
|
1425 |
+ guint swc; |
|
1426 |
+} cmdopt_value_t; |
|
64 | 1427 |
+typedef struct { |
66 | 1428 |
+ guint flags; |
1429 |
+ char shortopt; |
|
1430 |
+ const char *longopt; |
|
1431 |
+ cmdopt_value_t value; |
|
64 | 1432 |
+} cmdopt_t; |
66 | 1433 |
+typedef union { |
1434 |
+ gchar *arg; |
|
1435 |
+ subcmd_t *cmd; |
|
1436 |
+} cmdarg_value_t; |
|
64 | 1437 |
+typedef struct { |
66 | 1438 |
+ guint flags; |
1439 |
+ cmdarg_value_t value; |
|
64 | 1440 |
+} cmdarg_t; |
1441 |
+struct cmdopts_struct { |
|
1442 |
+ cmdopt_t *opts; |
|
1443 |
+ cmdarg_t *args; |
|
1444 |
+ subcmd_t *cmds; |
|
66 | 1445 |
+ gchar *freeme; // private |
1446 |
+}; |
|
1447 |
+struct subcmd_struct { |
|
1448 |
+ guint flags; |
|
1449 |
+ const char *name; |
|
1450 |
+ cmdopts_t options; |
|
1451 |
+ gpointer userdata; // unused, for user convenience |
|
64 | 1452 |
+}; |
1453 |
+ |
|
1454 |
+const char *cmdopts_parse (const char *arg, cmdopts_t *options); |
|
1455 |
+void cmdopts_free(cmdopts_t *options); |
|
1456 |
+ |
|
1457 |
void replace_nl_with_dots(char *bufstr); |
|
1458 |
char *ut_expand_tabs(const char *text); |
|
1459 |
char *ut_unescape_tabs_cr(const char *text); |
|
69
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1460 |
diff -r 92fa48ef53c9 mcabber/mcabber/xmpp_iq.c |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1461 |
--- a/mcabber/mcabber/xmpp_iq.c Sun Jan 27 00:40:37 2013 +0200 |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1462 |
+++ b/mcabber/mcabber/xmpp_iq.c Mon Feb 25 22:07:41 2013 +0200 |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1463 |
@@ -289,10 +289,7 @@ |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1464 |
if (value) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1465 |
for (s = adhoc_status_list; !s->name || strcmp(s->name, value); s++); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1466 |
if (s->name) { |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1467 |
- char *status = g_strdup_printf("%s %s", s->status, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1468 |
- message ? message : ""); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1469 |
- cmd_setstatus(NULL, status); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1470 |
- g_free(status); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1471 |
+ cmd_setstatus(NULL, s->status, message ? message : ""); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1472 |
lm_message_node_set_attribute(command, "status", "completed"); |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1473 |
lm_message_node_add_dataform_result(command, |
1b6295674c07
[cmdopts] Convert /add and /del, fix quotes, add catchall flags
Myhailo Danylenko <isbear@ukrpost.net>
parents:
68
diff
changeset
|
1474 |
"Status has been changed"); |