Mercurial > pidgin
annotate src/protocols/zephyr/zephyr.c @ 9434:c5cf752acc4a
[gaim-migrate @ 10254]
" Adds slash commands, ensures that server supplied
subscriptions are not ignored, cleans up some cases
where non-utf8 text was passed to display widgets, and
adds a utility function -- zephyr_send_message() -- to
get rid of code duplication.
Added slash commands:
/msg sends an IM to a user.
/inst /instance both set the instance for the current class
/zl and /zlocate will return user location information
(like Get Info) for a user.
/sub will allow a user to join a new chat
/zi sends message to <"message",instance,"*">
/zc sends message to <class,"PERSONAL","*">
/zci sends a message to <class,instance,"*">
/zcir sends a message to <class,instance,recipient or
realm>
/zir sends a message to <"message",instance,recipient
or realm>" --Arun A Tharuvai
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Wed, 30 Jun 2004 20:38:41 +0000 |
parents | 66b3f54527e6 |
children | d9f8658b305d |
rev | line source |
---|---|
2086 | 1 /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
2 /* | |
3 * gaim | |
4 * | |
5 * Copyright (C) 1998-2001, Mark Spencer <markster@marko.net> | |
6 * Some code borrowed from GtkZephyr, by | |
7084
0909ebf6fb28
[gaim-migrate @ 7649]
Christian Hammond <chipx86@chipx86.com>
parents:
7070
diff
changeset
|
7 * Jag/Sean Dilda <agrajag@linuxpower.org>/<smdilda@unity.ncsu.edu> |
0909ebf6fb28
[gaim-migrate @ 7649]
Christian Hammond <chipx86@chipx86.com>
parents:
7070
diff
changeset
|
8 * http://gtkzephyr.linuxpower.org/ |
2086 | 9 * |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 * | |
24 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
25 /* XXX eww */ |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
26 #include "src/internal.h" |
2086 | 27 |
8212 | 28 #include "accountopt.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
30 #include "multi.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
31 #include "notify.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
32 #include "prpl.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
33 #include "server.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
34 #include "util.h" |
9434 | 35 #include "cmds.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
36 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
37 #include "zephyr/zephyr.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
38 |
8386 | 39 #include <strings.h> |
40 | |
8560 | 41 #define ZEPHYR_FALLBACK_CHARSET "ISO-8859-1" |
42 | |
2086 | 43 extern Code_t ZGetLocations(ZLocations_t *, int *); |
44 extern Code_t ZSetLocation(char *); | |
45 extern Code_t ZUnsetLocation(); | |
46 | |
47 typedef struct _zframe zframe; | |
48 typedef struct _zephyr_triple zephyr_triple; | |
49 | |
50 /* struct I need for zephyr_to_html */ | |
51 struct _zframe { | |
52 /* true for everything but @color, since inside the parens of that one is | |
8644 | 53 * the color. */ |
2086 | 54 gboolean has_closer; |
55 /* </i>, </font>, </b>, etc. */ | |
56 char *closing; | |
57 /* text including the opening html thingie. */ | |
58 GString *text; | |
59 struct _zframe *enclosing; | |
60 }; | |
61 | |
62 struct _zephyr_triple { | |
63 char *class; | |
64 char *instance; | |
65 char *recipient; | |
66 char *name; | |
67 gboolean open; | |
68 int id; | |
69 }; | |
70 | |
71 #define z_call(func) if (func != ZERR_NONE)\ | |
72 return; | |
73 #define z_call_r(func) if (func != ZERR_NONE)\ | |
74 return TRUE; | |
75 #define z_call_s(func, err) if (func != ZERR_NONE) {\ | |
5606 | 76 gaim_connection_error(zgc, err);\ |
2086 | 77 return;\ |
78 } | |
79 | |
9328 | 80 char *local_zephyr_normalize(const char *); |
7322 | 81 static const char *zephyr_normalize(const GaimAccount *, const char *); |
9328 | 82 static const char *gaim_zephyr_get_realm(); |
9434 | 83 static void zephyr_chat_set_topic(GaimConnection * gc, int id, const char *topic); |
9328 | 84 |
85 char *zephyr_strip_foreign_realm(const char* user){ | |
86 /* | |
87 Takes in a username of the form username or username@realm | |
88 and returns: | |
89 username, if there is no realm, or the realm is the local realm | |
90 or: | |
91 username@realm if there is a realm and it is foreign | |
92 */ | |
93 char *tmp = g_strdup(user); | |
94 char *at = strchr(tmp,'@'); | |
95 if (at && !g_ascii_strcasecmp(at+1,gaim_zephyr_get_realm())) { | |
96 /* We're passed in a username of the form user@users-realm */ | |
97 char* tmp2; | |
98 *at = '\0'; | |
99 tmp2 = g_strdup(tmp); | |
100 g_free(tmp); | |
101 return tmp2; | |
102 } | |
103 else { | |
104 /* We're passed in a username of the form user or user@foreign-realm */ | |
105 return tmp; | |
106 } | |
107 } | |
2086 | 108 |
109 /* this is so bad, and if Zephyr weren't so fucked up to begin with I | |
110 * wouldn't do this. but it is so i will. */ | |
111 static guint32 nottimer = 0; | |
112 static guint32 loctimer = 0; | |
5606 | 113 GaimConnection *zgc = NULL; |
2086 | 114 static GList *pending_zloc_names = NULL; |
115 static GSList *subscrips = NULL; | |
116 static int last_id = 0; | |
117 | |
9328 | 118 /* just for debugging */ |
2086 | 119 static void handle_unknown(ZNotice_t notice) |
120 { | |
9328 | 121 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_packet: %s\n", notice.z_packet); |
122 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_version: %s\n", notice.z_version); | |
123 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_kind: %d\n", (int)(notice.z_kind)); | |
124 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class: %s\n", notice.z_class); | |
125 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class_inst: %s\n", notice.z_class_inst); | |
126 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_opcode: %s\n", notice.z_opcode); | |
127 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_sender: %s\n", notice.z_sender); | |
128 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_recipient: %s\n", notice.z_recipient); | |
129 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message: %s\n", notice.z_message); | |
130 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message_len: %d\n", notice.z_message_len); | |
2086 | 131 } |
9328 | 132 |
2086 | 133 |
134 static zephyr_triple *new_triple(const char *c, const char *i, const char *r) | |
135 { | |
136 zephyr_triple *zt; | |
8644 | 137 |
2086 | 138 zt = g_new0(zephyr_triple, 1); |
139 zt->class = g_strdup(c); | |
140 zt->instance = g_strdup(i); | |
141 zt->recipient = g_strdup(r); | |
142 zt->name = g_strdup_printf("%s,%s,%s", c, i, r); | |
143 zt->id = ++last_id; | |
144 zt->open = FALSE; | |
145 return zt; | |
146 } | |
147 | |
8644 | 148 static void free_triple(zephyr_triple * zt) |
2086 | 149 { |
150 g_free(zt->class); | |
151 g_free(zt->instance); | |
152 g_free(zt->recipient); | |
153 g_free(zt->name); | |
154 g_free(zt); | |
155 } | |
156 | |
8644 | 157 static const char *gaim_zephyr_get_sender() |
158 { | |
8568 | 159 /* will be useful once this plugin can use a backend other |
160 than libzephyr */ | |
161 return ZGetSender(); | |
8354 | 162 } |
163 | |
8644 | 164 static const char *gaim_zephyr_get_realm() |
165 { | |
8568 | 166 /* will be useful once this plugin can use a backend other |
167 than libzephyr */ | |
168 return ZGetRealm(); | |
8354 | 169 } |
170 | |
9328 | 171 /* returns true if zt1 is a subset of zt2. This function is used to |
172 determine whether a zephyr sent to zt1 should be placed in the chat | |
173 with triple zt2 | |
174 | |
175 zt1 is a subset of zt2 | |
176 iff. the classnames are identical ignoring case | |
177 AND. the instance names are identical (ignoring case), or zt2->instance is *. | |
178 AND. the recipient names are identical | |
179 */ | |
180 | |
8644 | 181 static gboolean triple_subset(zephyr_triple * zt1, zephyr_triple * zt2) |
2086 | 182 { |
9328 | 183 if (g_ascii_strcasecmp(zt2->class, zt1->class)) { |
2086 | 184 return FALSE; |
185 } | |
8644 | 186 if (g_ascii_strcasecmp(zt2->instance, zt1->instance) && g_ascii_strcasecmp(zt2->instance, "*")) { |
2086 | 187 return FALSE; |
188 } | |
9328 | 189 if (g_ascii_strcasecmp(zt2->recipient, zt1->recipient)) { |
2086 | 190 return FALSE; |
191 } | |
192 return TRUE; | |
193 } | |
194 | |
8644 | 195 static zephyr_triple *find_sub_by_triple(zephyr_triple * zt) |
2086 | 196 { |
197 zephyr_triple *curr_t; | |
198 GSList *curr = subscrips; | |
8644 | 199 |
2086 | 200 while (curr) { |
201 curr_t = curr->data; | |
202 if (triple_subset(zt, curr_t)) | |
203 return curr_t; | |
204 curr = curr->next; | |
205 } | |
206 return NULL; | |
207 } | |
208 | |
209 static zephyr_triple *find_sub_by_id(int id) | |
210 { | |
211 zephyr_triple *zt; | |
212 GSList *curr = subscrips; | |
8644 | 213 |
2086 | 214 while (curr) { |
215 zt = curr->data; | |
216 if (zt->id == id) | |
217 return zt; | |
218 curr = curr->next; | |
219 } | |
220 return NULL; | |
221 } | |
222 | |
9328 | 223 /* |
9434 | 224 Converts strings to utf-8 if necessary using user specified encoding |
9328 | 225 */ |
226 | |
9434 | 227 static gchar *zephyr_recv_convert(gchar *string, int len) |
8560 | 228 { |
229 gchar *utf8; | |
230 GError *err = NULL; | |
8644 | 231 |
232 if (g_utf8_validate(string, len, NULL)) { | |
8568 | 233 return g_strdup(string); |
234 } else { | |
8644 | 235 utf8 = g_convert(string, len, "UTF-8", gaim_account_get_string(zgc->account, "encoding", ZEPHYR_FALLBACK_CHARSET), NULL, NULL, &err); |
8568 | 236 if (err) { |
237 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "recv conversion error: %s\n", err->message); | |
238 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); | |
8954 | 239 g_error_free(err); |
8568 | 240 } |
241 | |
242 return utf8; | |
243 } | |
8560 | 244 } |
245 | |
2086 | 246 /* utility macros that are useful for zephyr_to_html */ |
247 | |
248 #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) | |
249 #define IS_CLOSER(c) ((c == '}') || (c == ']') || (c == ')') || (c == '>')) | |
250 | |
8451 | 251 /* This parses HTML formatting (put out by one of the gtkimhtml widgets |
252 And converts it to zephyr formatting. | |
253 It currently deals properly with <b>, <br>, <i>, <font face=...>, <font color=...>, | |
254 It ignores <font back=...> | |
255 It does | |
256 <font size = "1 or 2" -> @small | |
257 3 or 4 @medium() | |
258 5,6, or 7 @large() | |
259 <a href is dealt with by ignoring the description and outputting the link | |
260 */ | |
261 | |
262 static char *html_to_zephyr(const char *message) | |
263 { | |
8644 | 264 int len, cnt, retcount; |
265 char *ret; | |
266 | |
267 len = strlen(message); | |
268 ret = g_new0(char, len * 3); | |
269 | |
270 bzero(ret, len * 3); | |
271 retcount = 0; | |
272 cnt = 0; | |
273 while (cnt <= len) { | |
274 if (message[cnt] == '<') { | |
275 if (!g_ascii_strncasecmp(message + cnt + 1, "i>", 2)) { | |
276 strncpy(ret + retcount, "@i(", 3); | |
277 cnt += 3; | |
278 retcount += 3; | |
279 } else if (!g_ascii_strncasecmp(message + cnt + 1, "b>", 2)) { | |
280 strncpy(ret + retcount, "@b(", 3); | |
281 cnt += 3; | |
282 retcount += 3; | |
283 } else if (!g_ascii_strncasecmp(message + cnt + 1, "br>", 3)) { | |
284 strncpy(ret + retcount, "\n", 1); | |
285 cnt += 4; | |
286 retcount += 1; | |
287 } else if (!g_ascii_strncasecmp(message + cnt + 1, "a href=\"", 8)) { | |
288 cnt += 9; | |
289 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
290 ret[retcount] = message[cnt]; | |
291 retcount++; | |
292 cnt++; | |
293 } | |
294 cnt += 2; | |
295 /* ignore descriptive string */ | |
296 while (g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) { | |
297 cnt++; | |
298 } | |
299 cnt += 4; | |
300 } else if (!g_ascii_strncasecmp(message + cnt + 1, "font", 4)) { | |
301 cnt += 5; | |
302 while (!g_ascii_strncasecmp(message + cnt, " ", 1)) | |
303 cnt++; | |
304 if (!g_ascii_strncasecmp(message + cnt, "color=\"", 7)) { | |
305 cnt += 7; | |
306 strncpy(ret + retcount, "@color(", 7); | |
307 retcount += 7; | |
308 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
309 ret[retcount] = message[cnt]; | |
310 retcount++; | |
311 cnt++; | |
312 } | |
313 ret[retcount] = ')'; | |
314 retcount++; | |
315 cnt += 2; | |
316 } else if (!g_ascii_strncasecmp(message + cnt, "face=\"", 6)) { | |
317 cnt += 6; | |
318 strncpy(ret + retcount, "@font(", 6); | |
319 retcount += 6; | |
320 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
321 ret[retcount] = message[cnt]; | |
322 retcount++; | |
323 cnt++; | |
324 } | |
325 ret[retcount] = ')'; | |
326 retcount++; | |
327 cnt += 2; | |
328 } else if (!g_ascii_strncasecmp(message + cnt, "size=\"", 6)) { | |
329 cnt += 6; | |
330 if ((message[cnt] == '1') || (message[cnt] == '2')) { | |
331 strncpy(ret + retcount, "@small(", 7); | |
332 retcount += 7; | |
333 } else if ((message[cnt] == '3') | |
334 || (message[cnt] == '4')) { | |
335 strncpy(ret + retcount, "@medium(", 8); | |
336 retcount += 8; | |
337 } else if ((message[cnt] == '5') | |
338 || (message[cnt] == '6') | |
339 || (message[cnt] == '7')) { | |
340 strncpy(ret + retcount, "@large(", 7); | |
341 retcount += 7; | |
342 } | |
343 cnt += 3; | |
344 } else { | |
345 /* Drop all unrecognized/misparsed font tags */ | |
346 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
347 cnt++; | |
348 } | |
349 cnt += 2; | |
350 } | |
351 } else if (!g_ascii_strncasecmp(message + cnt + 1, "/i>", 3) | |
352 || !g_ascii_strncasecmp(message + cnt + 1, "/b>", 3)) { | |
353 cnt += 4; | |
354 ret[retcount] = ')'; | |
355 retcount++; | |
356 } else if (!g_ascii_strncasecmp(message + cnt + 1, "/font>", 6)) { | |
357 cnt += 7; | |
358 strncpy(ret + retcount, "@font(fixed)", 12); | |
359 retcount += 12; | |
360 } else { | |
361 /* Catch all for all unrecognized/misparsed <foo> tage */ | |
362 while (g_ascii_strncasecmp(message + cnt, ">", 1) != 0) { | |
363 ret[retcount] = message[cnt]; | |
364 retcount++; | |
365 cnt++; | |
366 } | |
367 } | |
368 } else { | |
369 /* Duh */ | |
370 ret[retcount] = message[cnt]; | |
371 retcount++; | |
372 cnt++; | |
373 } | |
374 } | |
375 return ret; | |
8451 | 376 } |
377 | |
2086 | 378 /* this parses zephyr formatting and converts it to html. For example, if |
379 * you pass in "@{@color(blue)@i(hello)}" you should get out | |
380 * "<font color=blue><i>hello</i></font>". */ | |
381 static char *zephyr_to_html(char *message) | |
382 { | |
383 int len, cnt; | |
384 zframe *frames, *curr; | |
385 char *ret; | |
386 | |
387 frames = g_new(zframe, 1); | |
388 frames->text = g_string_new(""); | |
389 frames->enclosing = NULL; | |
390 frames->closing = ""; | |
391 frames->has_closer = FALSE; | |
392 | |
393 len = strlen(message); | |
394 cnt = 0; | |
395 while (cnt <= len) { | |
396 if (message[cnt] == '@') { | |
397 zframe *new_f; | |
398 char *buf; | |
399 int end; | |
8644 | 400 |
401 for (end = 1; (cnt + end) <= len && !IS_OPENER(message[cnt + end]) | |
402 && !IS_CLOSER(message[cnt + end]); end++); | |
2086 | 403 buf = g_new0(char, end); |
8644 | 404 |
2086 | 405 if (end) { |
8644 | 406 g_snprintf(buf, end, "%s", message + cnt + 1); |
2086 | 407 } |
8644 | 408 if (!g_ascii_strcasecmp(buf, "italic") || !g_ascii_strcasecmp(buf, "i")) { |
2086 | 409 new_f = g_new(zframe, 1); |
410 new_f->enclosing = frames; | |
411 new_f->text = g_string_new("<i>"); | |
412 new_f->closing = "</i>"; | |
413 new_f->has_closer = TRUE; | |
414 frames = new_f; | |
8644 | 415 cnt += end + 1; /* cnt points to char after opener */ |
416 } else if (!g_ascii_strcasecmp(buf, "small")) { | |
417 new_f = g_new(zframe, 1); | |
418 new_f->enclosing = frames; | |
419 new_f->text = g_string_new("<font size=\"1\">"); | |
420 new_f->closing = "</font>"; | |
421 frames = new_f; | |
422 cnt += end + 1; | |
423 } else if (!g_ascii_strcasecmp(buf, "medium")) { | |
424 new_f = g_new(zframe, 1); | |
425 new_f->enclosing = frames; | |
426 new_f->text = g_string_new("<font size=\"3\">"); | |
427 new_f->closing = "</font>"; | |
428 frames = new_f; | |
429 cnt += end + 1; | |
430 } else if (!g_ascii_strcasecmp(buf, "large")) { | |
431 new_f = g_new(zframe, 1); | |
432 new_f->enclosing = frames; | |
433 new_f->text = g_string_new("<font size=\"7\">"); | |
434 new_f->closing = "</font>"; | |
435 frames = new_f; | |
436 cnt += end + 1; | |
437 } else if (!g_ascii_strcasecmp(buf, "bold") | |
438 || !g_ascii_strcasecmp(buf, "b")) { | |
2086 | 439 new_f = g_new(zframe, 1); |
440 new_f->enclosing = frames; | |
441 new_f->text = g_string_new("<b>"); | |
442 new_f->closing = "</b>"; | |
443 new_f->has_closer = TRUE; | |
444 frames = new_f; | |
8644 | 445 cnt += end + 1; |
446 } else if (!g_ascii_strcasecmp(buf, "font")) { | |
447 cnt += end + 1; | |
8451 | 448 new_f = g_new(zframe, 1); |
449 new_f->enclosing = frames; | |
450 new_f->text = g_string_new("<font face="); | |
451 for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
452 g_string_append_c(new_f->text, message[cnt]); | |
453 } | |
8644 | 454 cnt++; /* point to char after closer */ |
8451 | 455 g_string_append_c(new_f->text, '>'); |
456 new_f->closing = "</font>"; | |
457 new_f->has_closer = FALSE; | |
458 frames = new_f; | |
8568 | 459 } else if (!g_ascii_strcasecmp(buf, "color")) { |
8644 | 460 cnt += end + 1; |
2086 | 461 new_f = g_new(zframe, 1); |
462 new_f->enclosing = frames; | |
463 new_f->text = g_string_new("<font color="); | |
464 for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
465 g_string_append_c(new_f->text, message[cnt]); | |
466 } | |
8644 | 467 cnt++; /* point to char after closer */ |
2086 | 468 g_string_append_c(new_f->text, '>'); |
469 new_f->closing = "</font>"; | |
470 new_f->has_closer = FALSE; | |
471 frames = new_f; | |
4793 | 472 } else if (!g_ascii_strcasecmp(buf, "")) { |
2086 | 473 new_f = g_new(zframe, 1); |
474 new_f->enclosing = frames; | |
475 new_f->text = g_string_new(""); | |
476 new_f->closing = ""; | |
477 new_f->has_closer = TRUE; | |
478 frames = new_f; | |
8644 | 479 cnt += end + 1; /* cnt points to char after opener */ |
2086 | 480 } else { |
8644 | 481 if ((cnt + end) > len) { |
2086 | 482 g_string_append_c(frames->text, '@'); |
483 cnt++; | |
8644 | 484 } else if (IS_CLOSER(message[cnt + end])) { |
485 /* We have @chars..closer . This is | |
486 merely a sequence of chars that isn't a formatting tag | |
487 */ | |
488 int tmp = cnt; | |
489 | |
490 while (tmp <= cnt + end) { | |
491 g_string_append_c(frames->text, message[tmp]); | |
492 tmp++; | |
493 } | |
494 cnt += end + 1; | |
495 } else { | |
2086 | 496 /* unrecognized thingie. act like it's not there, but we |
497 * still need to take care of the corresponding closer, | |
498 * make a frame that does nothing. */ | |
499 new_f = g_new(zframe, 1); | |
500 new_f->enclosing = frames; | |
501 new_f->text = g_string_new(""); | |
502 new_f->closing = ""; | |
503 new_f->has_closer = TRUE; | |
504 frames = new_f; | |
8644 | 505 cnt += end + 1; /* cnt points to char after opener */ |
2086 | 506 } |
507 } | |
508 } else if (IS_CLOSER(message[cnt])) { | |
509 zframe *popped; | |
510 gboolean last_had_closer; | |
8644 | 511 |
2086 | 512 if (frames->enclosing) { |
513 do { | |
514 popped = frames; | |
515 frames = frames->enclosing; | |
516 g_string_append(frames->text, popped->text->str); | |
517 g_string_append(frames->text, popped->closing); | |
518 g_string_free(popped->text, TRUE); | |
519 last_had_closer = popped->has_closer; | |
520 g_free(popped); | |
521 } while (frames && frames->enclosing && !last_had_closer); | |
522 } else { | |
523 g_string_append_c(frames->text, message[cnt]); | |
524 } | |
525 cnt++; | |
526 } else if (message[cnt] == '\n') { | |
527 g_string_append(frames->text, "<br>"); | |
528 cnt++; | |
529 } else { | |
530 g_string_append_c(frames->text, message[cnt++]); | |
531 } | |
532 } | |
533 /* go through all the stuff that they didn't close */ | |
534 while (frames->enclosing) { | |
535 curr = frames; | |
536 g_string_append(frames->enclosing->text, frames->text->str); | |
537 g_string_append(frames->enclosing->text, frames->closing); | |
538 g_string_free(frames->text, TRUE); | |
539 frames = frames->enclosing; | |
540 g_free(curr); | |
541 } | |
542 ret = frames->text->str; | |
543 g_string_free(frames->text, FALSE); | |
544 g_free(frames); | |
545 return ret; | |
546 } | |
547 | |
548 static gboolean pending_zloc(char *who) | |
549 { | |
550 GList *curr; | |
8644 | 551 |
2086 | 552 for (curr = pending_zloc_names; curr != NULL; curr = curr->next) { |
9328 | 553 char* normalized_who = local_zephyr_normalize(who); |
554 if (!g_ascii_strcasecmp(normalized_who, (char *)curr->data)) { | |
8644 | 555 g_free((char *)curr->data); |
2086 | 556 pending_zloc_names = g_list_remove(pending_zloc_names, curr->data); |
557 return TRUE; | |
558 } | |
559 } | |
560 return FALSE; | |
561 } | |
562 | |
9328 | 563 /* Called when the server notifies us a message couldn't get sent */ |
564 | |
8559 | 565 static void message_failed(ZNotice_t notice, struct sockaddr_in from) |
566 { | |
8644 | 567 if (g_ascii_strcasecmp(notice.z_class, "message")) { |
9328 | 568 gchar* chat_failed = g_strdup_printf(_("Unable send to chat %s,%s,%s"),notice.z_class,notice.z_class_inst,notice.z_recipient); |
569 gaim_notify_error(zgc,"",chat_failed,NULL); | |
570 g_free(chat_failed); | |
8644 | 571 } else { |
572 gaim_notify_error(zgc, notice.z_recipient, _("User is offline"), NULL); | |
573 } | |
8559 | 574 } |
575 | |
2086 | 576 static void handle_message(ZNotice_t notice, struct sockaddr_in from) |
577 { | |
4793 | 578 if (!g_ascii_strcasecmp(notice.z_class, LOGIN_CLASS)) { |
3277 | 579 /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */ |
4793 | 580 } else if (!g_ascii_strcasecmp(notice.z_class, LOCATE_CLASS)) { |
581 if (!g_ascii_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
2086 | 582 int nlocs; |
583 char *user; | |
6695 | 584 GaimBuddy *b; |
2086 | 585 |
586 if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) | |
587 return; | |
8435 | 588 |
8644 | 589 if ((b = gaim_find_buddy(zgc->account, user)) == NULL) { |
2086 | 590 char *e = strchr(user, '@'); |
8644 | 591 |
592 if (e && !g_ascii_strcasecmp(e + 1, gaim_zephyr_get_realm())) { | |
593 *e = '\0'; | |
594 } | |
4687 | 595 b = gaim_find_buddy(zgc->account, user); |
8644 | 596 } |
597 if ((b && pending_zloc(b->name)) || pending_zloc(user)) { | |
2086 | 598 ZLocations_t locs; |
599 int one = 1; | |
600 GString *str = g_string_new(""); | |
8644 | 601 |
602 g_string_append_printf(str, _("<b>User:</b> %s<br>"), b ? b->name : user); | |
8435 | 603 if (b && b->alias) |
5132 | 604 g_string_append_printf(str, _("<b>Alias:</b> %s<br>"), b->alias); |
2086 | 605 if (!nlocs) { |
5132 | 606 g_string_append_printf(str, _("<br>Hidden or not logged-in")); |
2086 | 607 } |
608 for (; nlocs > 0; nlocs--) { | |
609 ZGetLocations(&locs, &one); | |
8644 | 610 g_string_append_printf(str, _("<br>At %s since %s"), locs.host, locs.time); |
2086 | 611 } |
8644 | 612 gaim_notify_formatted(zgc, NULL, _("Buddy Information"), NULL, str->str, NULL, NULL); |
2086 | 613 g_string_free(str, TRUE); |
614 } else | |
4732 | 615 serv_got_update(zgc, b->name, nlocs, 0, 0, 0, 0); |
2086 | 616 |
9434 | 617 g_free(user); |
2086 | 618 } |
619 } else { | |
8560 | 620 char *buf, *buf2, *buf3; |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
621 char *send_inst; |
8644 | 622 GaimConversation *gconv1; |
623 GaimConvChat *gcc; | |
2086 | 624 char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
8876 | 625 int len = notice.z_message_len - (strlen(notice.z_message) +1); |
8644 | 626 char *sendertmp = g_strdup_printf("%s", gaim_zephyr_get_sender()); |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
627 GaimConvImFlags flags = 0; |
8644 | 628 |
2086 | 629 if (len > 0) { |
8644 | 630 gchar *tmpescape; |
8560 | 631 |
8644 | 632 buf = g_malloc(len + 1); |
633 g_snprintf(buf, len + 1, "%s", ptr); | |
634 g_strchomp(buf); | |
635 tmpescape = gaim_escape_html(buf); | |
636 buf2 = zephyr_to_html(tmpescape); | |
637 buf3 = zephyr_recv_convert(buf2, strlen(buf2)); | |
638 g_free(buf2); | |
639 g_free(buf); | |
640 g_free(tmpescape); | |
641 | |
9328 | 642 if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL") |
643 && !g_ascii_strcasecmp(notice.z_recipient,gaim_zephyr_get_sender())) { | |
644 gchar* stripped_sender; | |
4793 | 645 if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
646 flags |= GAIM_CONV_IM_AUTO_RESP; |
9328 | 647 stripped_sender = zephyr_strip_foreign_realm(notice.z_sender); |
648 serv_got_im(zgc, stripped_sender, buf3, flags, time(NULL)); | |
649 g_free(stripped_sender); | |
2086 | 650 } else { |
651 zephyr_triple *zt1, *zt2; | |
8644 | 652 |
653 zt1 = new_triple(notice.z_class, notice.z_class_inst, notice.z_recipient); | |
2086 | 654 zt2 = find_sub_by_triple(zt1); |
655 if (!zt2) { | |
9434 | 656 /* This is a server supplied subscription */ |
657 subscrips = g_slist_append(subscrips, zt1); | |
658 zt2 = find_sub_by_triple(zt1); | |
659 } | |
660 /*else { */ | |
8644 | 661 GList *gltmp; |
662 int found = 0; | |
9434 | 663 gchar *send_inst_utf8; |
664 /* GError *err; */ | |
665 | |
2086 | 666 if (!zt2->open) { |
667 zt2->open = TRUE; | |
668 serv_got_joined_chat(zgc, zt2->id, zt2->name); | |
9434 | 669 zephyr_chat_set_topic(zgc,zt2->id,notice.z_class_inst); |
2086 | 670 } |
9328 | 671 g_free(sendertmp); /* fix memory leak? */ |
3277 | 672 /* If the person is in the default Realm, then strip the |
673 Realm from the sender field */ | |
9328 | 674 sendertmp = zephyr_strip_foreign_realm(notice.z_sender); |
675 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); | |
9434 | 676 send_inst_utf8 = zephyr_recv_convert(send_inst, strlen(send_inst)); |
677 if (!send_inst_utf8) { | |
678 fprintf(stderr, "zephyr: send_inst %s became null\n",send_inst); | |
679 gaim_debug(GAIM_DEBUG_ERROR, "zephyr","send_inst %s became null\n", send_inst); | |
680 send_inst_utf8 = "malformed instance"; | |
681 } | |
8212 | 682 |
9434 | 683 serv_got_chat_in(zgc, zt2->id, send_inst_utf8, FALSE, buf3, time(NULL)); |
684 g_free(send_inst); | |
8644 | 685 gconv1 = gaim_find_conversation_with_account(zt2->name, zgc->account); |
686 gcc = gaim_conversation_get_chat_data(gconv1); | |
9434 | 687 |
8644 | 688 for (gltmp = gaim_conv_chat_get_users(gcc); gltmp; gltmp = gltmp->next) { |
689 if (!g_ascii_strcasecmp(gltmp->data, sendertmp)) | |
690 found = 1; | |
691 } | |
692 if (!found) { | |
693 /* force interpretation in network byte order */ | |
694 unsigned char *addrs = (unsigned char *)&(notice.z_sender_addr.s_addr); | |
9328 | 695 gchar* ipaddr = g_strdup_printf("%hhd.%hhd.%hhd.%hhd", (unsigned char)addrs[0], |
696 (unsigned char)addrs[1], (unsigned char)addrs[2], | |
697 (unsigned char) addrs[3]); | |
8644 | 698 |
9328 | 699 gaim_conv_chat_add_user(gcc, sendertmp, ipaddr); |
700 g_free(ipaddr); /* fix memory leak? */ | |
8644 | 701 |
702 } | |
3277 | 703 g_free(sendertmp); |
9434 | 704 g_free(send_inst_utf8); |
705 | |
706 /* } */ | |
2086 | 707 free_triple(zt1); |
708 } | |
8560 | 709 g_free(buf3); |
2086 | 710 } |
711 } | |
712 } | |
713 | |
714 static gint check_notify(gpointer data) | |
715 { | |
716 while (ZPending()) { | |
717 ZNotice_t notice; | |
718 struct sockaddr_in from; | |
8644 | 719 |
2086 | 720 z_call_r(ZReceiveNotice(¬ice, &from)); |
721 | |
722 switch (notice.z_kind) { | |
723 case UNSAFE: | |
724 case UNACKED: | |
725 case ACKED: | |
726 handle_message(notice, from); | |
727 break; | |
8644 | 728 case SERVACK: |
729 if (!(g_ascii_strcasecmp(notice.z_message, ZSRVACK_NOTSENT))) { | |
730 message_failed(notice, from); | |
731 } | |
732 break; | |
9328 | 733 case CLIENTACK: |
734 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "Client ack received\n"); | |
2086 | 735 default: |
736 /* we'll just ignore things for now */ | |
9328 | 737 handle_unknown(notice); |
738 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "Unhandled notice.\n"); | |
2086 | 739 break; |
740 } | |
741 | |
742 ZFreeNotice(¬ice); | |
743 } | |
744 | |
745 return TRUE; | |
746 } | |
747 | |
748 static gint check_loc(gpointer data) | |
749 { | |
6695 | 750 GaimBlistNode *gnode, *cnode, *bnode; |
2086 | 751 ZAsyncLocateData_t ald; |
752 | |
753 ald.user = NULL; | |
754 memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
755 ald.version = NULL; | |
756 | |
8644 | 757 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
758 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4785 | 759 continue; |
8644 | 760 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
761 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
4785 | 762 continue; |
8644 | 763 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
764 GaimBuddy *b = (GaimBuddy *) bnode; | |
765 | |
766 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
6695 | 767 continue; |
8644 | 768 if (b->account->gc == zgc) { |
7261 | 769 const char *chk; |
8644 | 770 |
8354 | 771 chk = local_zephyr_normalize(b->name); |
6695 | 772 /* doesn't matter if this fails or not; we'll just move on to the next one */ |
773 ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
9434 | 774 g_free(ald.user); |
775 g_free(ald.version); | |
6695 | 776 } |
4349 | 777 } |
2086 | 778 } |
779 } | |
780 | |
781 return TRUE; | |
782 } | |
783 | |
784 static char *get_exposure_level() | |
785 { | |
786 char *exposure = ZGetVariable("exposure"); | |
787 | |
788 if (!exposure) | |
789 return EXPOSE_REALMVIS; | |
4793 | 790 if (!g_ascii_strcasecmp(exposure, EXPOSE_NONE)) |
2086 | 791 return EXPOSE_NONE; |
4793 | 792 if (!g_ascii_strcasecmp(exposure, EXPOSE_OPSTAFF)) |
2086 | 793 return EXPOSE_OPSTAFF; |
4793 | 794 if (!g_ascii_strcasecmp(exposure, EXPOSE_REALMANN)) |
2086 | 795 return EXPOSE_REALMANN; |
4793 | 796 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETVIS)) |
2086 | 797 return EXPOSE_NETVIS; |
4793 | 798 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETANN)) |
2086 | 799 return EXPOSE_NETANN; |
800 return EXPOSE_REALMVIS; | |
801 } | |
802 | |
803 static void strip_comments(char *str) | |
804 { | |
805 char *tmp = strchr(str, '#'); | |
8644 | 806 |
2086 | 807 if (tmp) |
808 *tmp = '\0'; | |
809 g_strchug(str); | |
810 g_strchomp(str); | |
811 } | |
812 | |
813 static void process_zsubs() | |
814 { | |
9434 | 815 /* Loads zephyr chats "(subscriptions) from ~/.zephyr.subs, and |
816 registers (subscribes to) them on the server */ | |
817 | |
818 /* XXX write subscriptions into the buddy list somehow "a Zephyr Chats group?"*/ | |
819 /* XXX deal with unsubscriptions */ | |
820 /* XXX deal with punts */ | |
821 | |
2086 | 822 FILE *f; |
823 gchar *fname; | |
824 gchar buff[BUFSIZ]; | |
8644 | 825 |
3630 | 826 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
2086 | 827 f = fopen(fname, "r"); |
828 if (f) { | |
829 char **triple; | |
830 ZSubscription_t sub; | |
831 char *recip; | |
8644 | 832 |
2086 | 833 while (fgets(buff, BUFSIZ, f)) { |
834 strip_comments(buff); | |
835 if (buff[0]) { | |
836 triple = g_strsplit(buff, ",", 3); | |
8644 | 837 if (triple[0] && triple[1]) { |
838 char *tmp = g_strdup_printf("%s", gaim_zephyr_get_sender()); | |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
839 char *atptr; |
8644 | 840 |
2086 | 841 sub.zsub_class = triple[0]; |
842 sub.zsub_classinst = triple[1]; | |
8644 | 843 if (triple[2] == NULL) { |
3277 | 844 recip = g_malloc0(1); |
4793 | 845 } else if (!g_ascii_strcasecmp(triple[2], "%me%")) { |
8644 | 846 recip = g_strdup_printf("%s", gaim_zephyr_get_sender()); |
4793 | 847 } else if (!g_ascii_strcasecmp(triple[2], "*")) { |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
848 /* wildcard |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
849 * form of class,instance,* */ |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
850 recip = g_malloc0(1); |
4793 | 851 } else if (!g_ascii_strcasecmp(triple[2], tmp)) { |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
852 /* form of class,instance,aatharuv@ATHENA.MIT.EDU */ |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
853 recip = g_strdup(triple[2]); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
854 } else if ((atptr = strchr(triple[2], '@')) != NULL) { |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
855 /* form of class,instance,*@ANDREW.CMU.EDU |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
856 * class,instance,@ANDREW.CMU.EDU |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
857 * If realm is local realm, blank recipient, else |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
858 * @REALM-NAME |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
859 */ |
8644 | 860 char *realmat = g_strdup_printf("@%s", |
861 gaim_zephyr_get_realm()); | |
862 | |
4793 | 863 if (!g_ascii_strcasecmp(atptr, realmat)) |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
864 recip = g_malloc0(1); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
865 else |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
866 recip = g_strdup(atptr); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
867 g_free(realmat); |
2086 | 868 } else { |
869 recip = g_strdup(triple[2]); | |
870 } | |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
871 g_free(tmp); |
2086 | 872 sub.zsub_recipient = recip; |
873 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
8644 | 874 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "Couldn't subscribe to %s, %s, %s\n", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient); |
2086 | 875 } |
8644 | 876 subscrips = g_slist_append(subscrips, new_triple(triple[0], triple[1], recip)); |
2086 | 877 g_free(recip); |
878 } | |
879 g_strfreev(triple); | |
880 } | |
881 } | |
882 } | |
883 } | |
884 | |
885 static void process_anyone() | |
886 { | |
887 FILE *fd; | |
888 gchar buff[BUFSIZ], *filename; | |
6695 | 889 GaimGroup *g; |
890 GaimBuddy *b; | |
4775 | 891 |
892 if (!(g = gaim_find_group(_("Anyone")))) { | |
893 g = gaim_group_new(_("Anyone")); | |
894 gaim_blist_add_group(g, NULL); | |
895 } | |
6695 | 896 |
3630 | 897 filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); |
2086 | 898 if ((fd = fopen(filename, "r")) != NULL) { |
899 while (fgets(buff, BUFSIZ, fd)) { | |
900 strip_comments(buff); | |
4687 | 901 if (buff[0]) { |
8644 | 902 if (!(b = gaim_find_buddy(zgc->account, buff))) { |
903 b = gaim_buddy_new(zgc->account, buff, NULL); | |
904 gaim_blist_add_buddy(b, NULL, g, NULL); | |
905 } | |
906 } | |
2086 | 907 } |
908 fclose(fd); | |
909 } | |
910 g_free(filename); | |
911 } | |
912 | |
8644 | 913 static void zephyr_login(GaimAccount * account) |
2086 | 914 { |
915 ZSubscription_t sub; | |
9427 | 916 |
2086 | 917 if (zgc) { |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
918 gaim_notify_error(account->gc, NULL, |
8644 | 919 _("Already logged in with Zephyr"), _("Because Zephyr uses your system username, you " "are unable to have multiple accounts on it " "when logged in as the same user.")); |
2086 | 920 return; |
921 } | |
922 | |
5606 | 923 zgc = gaim_account_get_connection(account); |
8644 | 924 zgc->flags |= GAIM_CONNECTION_HTML; |
8645 | 925 gaim_connection_update_progress(zgc, _("Connecting"), 0, 2); |
926 | |
2086 | 927 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); |
9427 | 928 z_call_s(ZOpenPort(NULL), "Couldn't open port"); |
8644 | 929 z_call_s(ZSetLocation((char *) |
930 gaim_account_get_string(zgc->account, "exposure_level", EXPOSE_REALMVIS)), "Couldn't set location"); | |
2086 | 931 |
932 sub.zsub_class = "MESSAGE"; | |
933 sub.zsub_classinst = "PERSONAL"; | |
8354 | 934 sub.zsub_recipient = (char *)gaim_zephyr_get_sender(); |
9427 | 935 |
2086 | 936 /* we don't care if this fails. i'm lying right now. */ |
937 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
8644 | 938 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "Couldn't subscribe to messages!\n"); |
2086 | 939 } |
940 | |
5606 | 941 gaim_connection_set_state(zgc, GAIM_CONNECTED); |
2086 | 942 serv_finish_login(zgc); |
943 | |
944 process_anyone(); | |
945 process_zsubs(); | |
946 | |
8273
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8212
diff
changeset
|
947 nottimer = gaim_timeout_add(100, check_notify, NULL); |
f24172f53650
[gaim-migrate @ 8997]
Christian Hammond <chipx86@chipx86.com>
parents:
8212
diff
changeset
|
948 loctimer = gaim_timeout_add(20000, check_loc, NULL); |
2086 | 949 } |
950 | |
951 static void write_zsubs() | |
952 { | |
9434 | 953 /* Exports subscription (chat) list back to |
954 * .zephyr.subs | |
955 * XXX deal with %host%, %canon%, unsubscriptions, and negative subscriptions (punts?) | |
956 */ | |
957 | |
2086 | 958 GSList *s = subscrips; |
959 zephyr_triple *zt; | |
960 FILE *fd; | |
961 char *fname; | |
962 | |
8644 | 963 char **triple; |
964 | |
3630 | 965 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
2086 | 966 fd = fopen(fname, "w"); |
8644 | 967 |
2086 | 968 if (!fd) { |
969 g_free(fname); | |
970 return; | |
971 } | |
8644 | 972 |
2086 | 973 while (s) { |
974 zt = s->data; | |
8644 | 975 triple = g_strsplit(zt->name, ",", 3); |
3277 | 976 if (triple[2] != NULL) { |
4793 | 977 if (!g_ascii_strcasecmp(triple[2], "")) { |
3277 | 978 fprintf(fd, "%s,%s,*\n", triple[0], triple[1]); |
8354 | 979 } else if (!g_ascii_strcasecmp(triple[2], gaim_zephyr_get_sender())) { |
8644 | 980 fprintf(fd, "%s,%s,%%me%%\n", triple[0], triple[1]); |
3277 | 981 } else { |
982 fprintf(fd, "%s\n", zt->name); | |
983 } | |
984 } else { | |
8644 | 985 fprintf(fd, "%s,%s,*\n", triple[0], triple[1]); |
3277 | 986 } |
987 g_free(triple); | |
2086 | 988 s = s->next; |
989 } | |
990 g_free(fname); | |
991 fclose(fd); | |
992 } | |
993 | |
994 static void write_anyone() | |
995 { | |
6695 | 996 GaimBlistNode *gnode, *cnode, *bnode; |
997 GaimBuddy *b; | |
3277 | 998 char *ptr, *fname, *ptr2; |
2086 | 999 FILE *fd; |
1000 | |
3630 | 1001 fname = g_strdup_printf("%s/.anyone", gaim_home_dir()); |
2086 | 1002 fd = fopen(fname, "w"); |
1003 if (!fd) { | |
1004 g_free(fname); | |
1005 return; | |
1006 } | |
1007 | |
8644 | 1008 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
1009 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4785 | 1010 continue; |
8644 | 1011 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
1012 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
4785 | 1013 continue; |
8644 | 1014 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
1015 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
6695 | 1016 continue; |
8644 | 1017 b = (GaimBuddy *) bnode; |
1018 if (b->account == zgc->account) { | |
6695 | 1019 if ((ptr = strchr(b->name, '@')) != NULL) { |
1020 ptr2 = ptr + 1; | |
1021 /* We should only strip the realm name if the principal | |
1022 is in the user's realm | |
8644 | 1023 */ |
1024 if (!g_ascii_strcasecmp(ptr2, gaim_zephyr_get_realm())) { | |
6695 | 1025 *ptr = '\0'; |
1026 } | |
4349 | 1027 } |
6695 | 1028 fprintf(fd, "%s\n", b->name); |
1029 if (ptr) | |
1030 *ptr = '@'; | |
3277 | 1031 } |
1032 } | |
2086 | 1033 } |
1034 } | |
1035 | |
1036 fclose(fd); | |
1037 g_free(fname); | |
1038 } | |
1039 | |
8644 | 1040 static void zephyr_close(GaimConnection * gc) |
2086 | 1041 { |
1042 GList *l; | |
1043 GSList *s; | |
8644 | 1044 |
2086 | 1045 l = pending_zloc_names; |
1046 while (l) { | |
8644 | 1047 g_free((char *)l->data); |
2086 | 1048 l = l->next; |
1049 } | |
1050 g_list_free(pending_zloc_names); | |
8644 | 1051 |
1052 if (gaim_account_get_bool(zgc->account, "write_anyone", FALSE)) | |
8212 | 1053 write_anyone(); |
8644 | 1054 |
1055 if (gaim_account_get_bool(zgc->account, "write_zsubs", FALSE)) | |
8212 | 1056 write_zsubs(); |
8644 | 1057 |
2086 | 1058 s = subscrips; |
1059 while (s) { | |
8644 | 1060 free_triple((zephyr_triple *) s->data); |
2086 | 1061 s = s->next; |
1062 } | |
1063 g_slist_free(subscrips); | |
8644 | 1064 |
2086 | 1065 if (nottimer) |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
1066 gaim_timeout_remove(nottimer); |
2086 | 1067 nottimer = 0; |
1068 if (loctimer) | |
8287
ef881489396e
[gaim-migrate @ 9011]
Christian Hammond <chipx86@chipx86.com>
parents:
8273
diff
changeset
|
1069 gaim_timeout_remove(loctimer); |
2086 | 1070 loctimer = 0; |
1071 zgc = NULL; | |
1072 z_call(ZCancelSubscriptions(0)); | |
1073 z_call(ZUnsetLocation()); | |
1074 z_call(ZClosePort()); | |
1075 } | |
1076 | |
9434 | 1077 static int zephyr_send_message(char* zclass, char* instance, char* recipient, const char *im, |
1078 const char *sig) ; | |
1079 | |
1080 const char * zephyr_get_signature() | |
1081 { | |
1082 const char * sig; | |
1083 sig = ZGetVariable("zwrite-signature"); | |
1084 if (!sig) { | |
1085 sig = g_get_real_name(); | |
1086 } | |
1087 return sig; | |
1088 } | |
1089 | |
8644 | 1090 static int zephyr_chat_send(GaimConnection * gc, int id, const char *im) |
2086 | 1091 { |
1092 zephyr_triple *zt; | |
1093 const char *sig; | |
8644 | 1094 GaimConversation *gconv1; |
1095 GaimConvChat *gcc; | |
1096 char *inst; | |
9434 | 1097 char *recipient; |
2086 | 1098 |
1099 zt = find_sub_by_id(id); | |
1100 if (!zt) | |
1101 /* this should never happen. */ | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1102 return -EINVAL; |
8644 | 1103 |
9434 | 1104 sig = zephyr_get_signature(); |
2086 | 1105 |
8644 | 1106 gconv1 = gaim_find_conversation_with_account(zt->name, zgc->account); |
1107 gcc = gaim_conversation_get_chat_data(gconv1); | |
8212 | 1108 |
8644 | 1109 if (!(inst = (char *)gaim_conv_chat_get_topic(gcc))) |
9434 | 1110 inst = g_strdup("PERSONAL"); |
8644 | 1111 |
4793 | 1112 if (!g_ascii_strcasecmp(zt->recipient, "*")) |
9434 | 1113 recipient = local_zephyr_normalize(""); |
2086 | 1114 else |
9434 | 1115 recipient = local_zephyr_normalize(zt->recipient); |
8451 | 1116 |
9434 | 1117 zephyr_send_message(zt->class,inst,recipient,im,sig); |
1118 /* g_free(inst); */ | |
1119 /* g_free(recipient); */ | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1120 return 0; |
2086 | 1121 } |
1122 | |
9434 | 1123 |
8644 | 1124 static int zephyr_send_im(GaimConnection * gc, const char *who, const char *im, GaimConvImFlags flags) |
1125 { | |
2086 | 1126 const char *sig; |
8644 | 1127 |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
1128 if (flags & GAIM_CONV_IM_AUTO_RESP) |
2086 | 1129 sig = "Automated reply:"; |
1130 else { | |
9434 | 1131 sig = zephyr_get_signature(); |
2086 | 1132 } |
9434 | 1133 zephyr_send_message("MESSAGE","PERSONAL",local_zephyr_normalize(who),im,sig); |
1134 | |
1135 return 1; | |
1136 } | |
2086 | 1137 |
9434 | 1138 static int zephyr_send_message(char* zclass, char* instance, char* recipient, const char *im, |
1139 const char *sig) | |
1140 { | |
1141 char *html_buf; | |
1142 char *html_buf2; | |
1143 char *buf; | |
1144 ZNotice_t notice; | |
8451 | 1145 |
9434 | 1146 html_buf = html_to_zephyr(im); |
1147 html_buf2 = gaim_unescape_html(html_buf); | |
1148 | |
1149 buf = g_strdup_printf("%s%c%s", sig, '\0', html_buf2); | |
2086 | 1150 bzero((char *)¬ice, sizeof(notice)); |
9434 | 1151 |
2086 | 1152 notice.z_kind = ACKED; |
1153 notice.z_port = 0; | |
1154 notice.z_opcode = ""; | |
9434 | 1155 notice.z_class = zclass; |
1156 notice.z_class_inst = instance; | |
1157 notice.z_recipient = recipient; | |
1158 notice.z_sender = 0; | |
1159 notice.z_default_format = "Class $class, Instance $instance:\n" "To: @bold($recipient) at $time $date\n" "From: @bold($1) <$sender>\n\n$2"; | |
8451 | 1160 notice.z_message_len = strlen(html_buf2) + strlen(sig) + 2; |
2086 | 1161 notice.z_message = buf; |
8644 | 1162 g_free(html_buf2); |
1163 g_free(html_buf); | |
8451 | 1164 |
6904 | 1165 ZSendNotice(¬ice, ZAUTH); |
2086 | 1166 g_free(buf); |
9434 | 1167 return 1; |
2086 | 1168 } |
1169 | |
8644 | 1170 static const char *zephyr_normalize(const GaimAccount * account, const char *orig) |
2086 | 1171 { |
9328 | 1172 /* returns the string you gave it. Maybe this function shouldn't be here */ |
2086 | 1173 static char buf[80]; |
8644 | 1174 |
7126 | 1175 if (!g_ascii_strcasecmp(orig, "")) { |
1176 buf[0] = '\0'; | |
1177 return buf; | |
8354 | 1178 } else { |
8644 | 1179 g_snprintf(buf, 80, "%s", orig); |
1180 } | |
1181 return buf; | |
8354 | 1182 } |
1183 | |
1184 | |
9328 | 1185 char *local_zephyr_normalize(const char *orig) |
8354 | 1186 { |
9328 | 1187 /* |
1188 Basically the inverse of zephyr_strip_foreign_realm | |
1189 */ | |
8644 | 1190 static char buf[80]; |
1191 | |
8354 | 1192 if (!g_ascii_strcasecmp(orig, "")) { |
1193 buf[0] = '\0'; | |
1194 return buf; | |
7126 | 1195 } |
8644 | 1196 |
2086 | 1197 if (strchr(orig, '@')) { |
1198 g_snprintf(buf, 80, "%s", orig); | |
1199 } else { | |
8644 | 1200 g_snprintf(buf, 80, "%s@%s", orig, gaim_zephyr_get_realm()); |
2086 | 1201 } |
1202 return buf; | |
1203 } | |
1204 | |
9030 | 1205 static void zephyr_zloc(GaimConnection *gc, const char *who) |
2086 | 1206 { |
1207 ZAsyncLocateData_t ald; | |
9328 | 1208 gchar* normalized_who = local_zephyr_normalize(who); |
7261 | 1209 |
9328 | 1210 if (ZRequestLocations(normalized_who, &ald, UNACKED, ZAUTH) == ZERR_NONE) { |
9030 | 1211 pending_zloc_names = g_list_append(pending_zloc_names, |
9328 | 1212 g_strdup(normalized_who)); |
2086 | 1213 } |
1214 } | |
1215 | |
8644 | 1216 static void zephyr_set_away(GaimConnection * gc, const char *state, const char *msg) |
2086 | 1217 { |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1218 if (gc->away) { |
2086 | 1219 g_free(gc->away); |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1220 gc->away = NULL; |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1221 } |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1222 |
5132 | 1223 if (!g_ascii_strcasecmp(state, _("Hidden"))) { |
2086 | 1224 ZSetLocation(EXPOSE_OPSTAFF); |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1225 gc->away = g_strdup(""); |
5132 | 1226 } else if (!g_ascii_strcasecmp(state, _("Online"))) |
2086 | 1227 ZSetLocation(get_exposure_level()); |
1228 else /* state is GAIM_AWAY_CUSTOM */ if (msg) | |
1229 gc->away = g_strdup(msg); | |
1230 } | |
1231 | |
8644 | 1232 static GList *zephyr_away_states(GaimConnection * gc) |
2086 | 1233 { |
1234 GList *m = NULL; | |
1235 | |
5132 | 1236 m = g_list_append(m, _("Online")); |
2086 | 1237 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
5132 | 1238 m = g_list_append(m, _("Hidden")); |
2086 | 1239 |
1240 return m; | |
1241 } | |
1242 | |
8644 | 1243 static GList *zephyr_chat_info(GaimConnection * gc) |
1244 { | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1245 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1246 struct proto_chat_entry *pce; |
2086 | 1247 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1248 pce = g_new0(struct proto_chat_entry, 1); |
8644 | 1249 |
7841 | 1250 pce->label = _("_Class:"); |
5234 | 1251 pce->identifier = "class"; |
3158 | 1252 m = g_list_append(m, pce); |
2086 | 1253 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1254 pce = g_new0(struct proto_chat_entry, 1); |
8644 | 1255 |
7841 | 1256 pce->label = _("_Instance:"); |
5234 | 1257 pce->identifier = "instance"; |
3158 | 1258 m = g_list_append(m, pce); |
2086 | 1259 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1260 pce = g_new0(struct proto_chat_entry, 1); |
8644 | 1261 |
7841 | 1262 pce->label = _("_Recipient:"); |
5234 | 1263 pce->identifier = "recipient"; |
3158 | 1264 m = g_list_append(m, pce); |
2086 | 1265 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1266 return m; |
2086 | 1267 } |
1268 | |
8644 | 1269 static void zephyr_join_chat(GaimConnection * gc, GHashTable * data) |
2086 | 1270 { |
1271 ZSubscription_t sub; | |
1272 zephyr_triple *zt1, *zt2; | |
1273 const char *classname; | |
1274 const char *instname; | |
1275 const char *recip; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1276 |
5234 | 1277 classname = g_hash_table_lookup(data, "class"); |
1278 instname = g_hash_table_lookup(data, "instance"); | |
1279 recip = g_hash_table_lookup(data, "recipient"); | |
1280 | |
9328 | 1281 if (!classname) |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1282 return; |
9328 | 1283 if (!instname || !strlen(instname)) |
1284 instname = "*"; | |
1285 if (!recip || (*recip == '*')) | |
1286 recip = ""; | |
4793 | 1287 if (!g_ascii_strcasecmp(recip, "%me%")) |
8354 | 1288 recip = gaim_zephyr_get_sender(); |
2086 | 1289 |
1290 zt1 = new_triple(classname, instname, recip); | |
1291 zt2 = find_sub_by_triple(zt1); | |
1292 if (zt2) { | |
1293 free_triple(zt1); | |
9328 | 1294 if (!zt2->open) { |
1295 if (!g_ascii_strcasecmp(instname,"*")) | |
1296 instname = "PERSONAL"; | |
9434 | 1297 serv_got_joined_chat(gc, zt2->id, zt2->name); |
1298 zephyr_chat_set_topic(zgc,zt2->id,instname); | |
9328 | 1299 zt2->open = TRUE; |
1300 } | |
2086 | 1301 return; |
1302 } | |
9434 | 1303 |
2086 | 1304 sub.zsub_class = zt1->class; |
1305 sub.zsub_classinst = zt1->instance; | |
1306 sub.zsub_recipient = zt1->recipient; | |
9434 | 1307 |
2086 | 1308 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { |
1309 free_triple(zt1); | |
1310 return; | |
1311 } | |
1312 | |
1313 subscrips = g_slist_append(subscrips, zt1); | |
1314 zt1->open = TRUE; | |
1315 serv_got_joined_chat(gc, zt1->id, zt1->name); | |
9328 | 1316 if (!g_ascii_strcasecmp(instname,"*")) |
1317 instname = "PERSONAL"; | |
9434 | 1318 zephyr_chat_set_topic(zgc,zt1->id,instname); |
2086 | 1319 } |
1320 | |
8644 | 1321 static void zephyr_chat_leave(GaimConnection * gc, int id) |
2086 | 1322 { |
1323 zephyr_triple *zt; | |
8644 | 1324 |
2086 | 1325 zt = find_sub_by_id(id); |
1326 if (zt) { | |
1327 zt->open = FALSE; | |
1328 zt->id = ++last_id; | |
1329 } | |
1330 } | |
1331 | |
8644 | 1332 static const char *zephyr_list_icon(GaimAccount * a, GaimBuddy * b) |
5202 | 1333 { |
1334 return "zephyr"; | |
1335 } | |
1336 | |
8212 | 1337 |
9434 | 1338 |
1339 | |
8644 | 1340 static void zephyr_chat_set_topic(GaimConnection * gc, int id, const char *topic) |
1341 { | |
1342 zephyr_triple *zt; | |
1343 GaimConversation *gconv; | |
1344 GaimConvChat *gcc; | |
9434 | 1345 gchar *topic_utf8; |
8644 | 1346 char *sender = (char *)gaim_zephyr_get_sender(); |
8212 | 1347 |
8644 | 1348 zt = find_sub_by_id(id); |
1349 gconv = gaim_find_conversation_with_account(zt->name, zgc->account); | |
1350 gcc = gaim_conversation_get_chat_data(gconv); | |
9434 | 1351 |
1352 topic_utf8 = zephyr_recv_convert((gchar *)topic,strlen(topic)); | |
1353 gaim_conv_chat_set_topic(gcc,sender,topic_utf8); | |
1354 g_free(topic_utf8); | |
1355 return; | |
1356 } | |
1357 | |
1358 /* commands */ | |
1359 | |
1360 static GaimCmdRet zephyr_gaim_cmd_msg(GaimConversation *conv, | |
1361 const char *cmd, char **args, char **error) | |
1362 { | |
1363 char *recipient; | |
1364 if (!g_ascii_strcasecmp(args[0],"*")) | |
1365 recipient = local_zephyr_normalize(""); | |
1366 else | |
1367 recipient = local_zephyr_normalize(args[0]); | |
1368 | |
1369 if (zephyr_send_message("MESSAGE","PERSONAL",recipient,args[1],zephyr_get_signature())) | |
1370 return GAIM_CMD_RET_OK; | |
1371 else | |
1372 return GAIM_CMD_RET_FAILED; | |
1373 } | |
1374 | |
1375 static GaimCmdRet zephyr_gaim_cmd_zlocate(GaimConversation *conv, | |
1376 const char *cmd, char **args, char **error) | |
1377 { | |
1378 zephyr_zloc(zgc,args[0]); | |
1379 return GAIM_CMD_RET_OK; | |
1380 } | |
1381 | |
1382 static GaimCmdRet zephyr_gaim_cmd_instance(GaimConversation *conv, | |
1383 const char *cmd, char **args, char **error) | |
1384 { | |
1385 /* Currently it sets the instance with leading spaces and | |
1386 * all. This might not be the best thing to do, though having | |
1387 * one word isn't ideal either. */ | |
1388 | |
1389 GaimConvChat *gc = gaim_conversation_get_chat_data(conv); | |
1390 int id = gc->id; | |
1391 const char* instance = args[0]; | |
1392 zephyr_chat_set_topic(zgc,id,instance); | |
1393 return GAIM_CMD_RET_OK; | |
1394 } | |
1395 | |
1396 static GaimCmdRet zephyr_gaim_cmd_joinchat_cir(GaimConversation *conv, | |
1397 const char *cmd, char **args, char **error) | |
1398 { | |
1399 /* Join a new zephyr chat */ | |
1400 GHashTable *triple = g_hash_table_new(NULL,NULL); | |
1401 g_hash_table_insert(triple,"class",args[0]); | |
1402 g_hash_table_insert(triple,"instance",args[1]); | |
1403 g_hash_table_insert(triple,"recipient",args[2]); | |
1404 zephyr_join_chat(zgc,triple); | |
1405 return GAIM_CMD_RET_OK; | |
1406 } | |
1407 | |
1408 static GaimCmdRet zephyr_gaim_cmd_zi(GaimConversation *conv, | |
1409 const char *cmd, char **args, char **error) | |
1410 { | |
1411 /* args = instance, message */ | |
1412 if (zephyr_send_message("message",args[0],"",args[1],zephyr_get_signature())) | |
1413 return GAIM_CMD_RET_OK; | |
1414 else | |
1415 return GAIM_CMD_RET_FAILED; | |
1416 } | |
1417 | |
1418 static GaimCmdRet zephyr_gaim_cmd_zci(GaimConversation *conv, | |
1419 const char *cmd, char **args, char **error) | |
1420 { | |
1421 /* args = class, instance, message */ | |
1422 if ( zephyr_send_message(args[0],args[1],"",args[2],zephyr_get_signature())) | |
1423 return GAIM_CMD_RET_OK; | |
1424 else | |
1425 return GAIM_CMD_RET_FAILED; | |
1426 } | |
8644 | 1427 |
9434 | 1428 static GaimCmdRet zephyr_gaim_cmd_zcir(GaimConversation *conv, |
1429 const char *cmd, char **args, char **error) | |
1430 { | |
1431 /* args = class, instance, recipient, message */ | |
1432 if ( zephyr_send_message(args[0],args[1],args[2],args[3],zephyr_get_signature())) | |
1433 return GAIM_CMD_RET_OK; | |
1434 else | |
1435 return GAIM_CMD_RET_FAILED; | |
8212 | 1436 } |
1437 | |
9434 | 1438 static GaimCmdRet zephyr_gaim_cmd_zir(GaimConversation *conv, |
1439 const char *cmd, char **args, char **error) | |
1440 { | |
1441 /* args = instance, recipient, message */ | |
1442 if ( zephyr_send_message("message",args[0],args[1],args[2],zephyr_get_signature())) | |
1443 return GAIM_CMD_RET_OK; | |
1444 else | |
1445 return GAIM_CMD_RET_FAILED; | |
1446 } | |
1447 | |
1448 static GaimCmdRet zephyr_gaim_cmd_zc(GaimConversation *conv, | |
1449 const char *cmd, char **args, char **error) | |
1450 { | |
1451 /* args = class, message */ | |
1452 if ( zephyr_send_message(args[0],"PERSONAL","",args[1],zephyr_get_signature())) | |
1453 return GAIM_CMD_RET_OK; | |
1454 else | |
1455 return GAIM_CMD_RET_FAILED; | |
1456 } | |
1457 | |
1458 static void zephyr_register_slash_commands() | |
1459 { | |
1460 | |
1461 gaim_cmd_register("msg","ws", GAIM_CMD_P_PRPL, | |
1462 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1463 "prpl-zephyr", | |
1464 zephyr_gaim_cmd_msg, _("msg <nick> <message>: Send a private message to a user")); | |
1465 | |
1466 gaim_cmd_register("zlocate","w", GAIM_CMD_P_PRPL, | |
1467 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1468 "prpl-zephyr", | |
1469 zephyr_gaim_cmd_zlocate, _("zlocate <nick>: Locate user")); | |
1470 | |
1471 gaim_cmd_register("zl","w", GAIM_CMD_P_PRPL, | |
1472 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1473 "prpl-zephyr", | |
1474 zephyr_gaim_cmd_zlocate, _("zl <nick>: Locate user")); | |
1475 | |
1476 gaim_cmd_register("instance","s", GAIM_CMD_P_PRPL, | |
1477 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1478 "prpl-zephyr", | |
1479 zephyr_gaim_cmd_instance, _("inst <instance>: Set the instance to be used on this class")); | |
1480 | |
1481 gaim_cmd_register("inst","s", GAIM_CMD_P_PRPL, | |
1482 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1483 "prpl-zephyr", | |
1484 zephyr_gaim_cmd_instance, _("instance <instance>: Set the instance to be used on this class")); | |
1485 | |
1486 gaim_cmd_register("sub", "www", GAIM_CMD_P_PRPL, | |
1487 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1488 "prpl-zephyr", | |
1489 zephyr_gaim_cmd_joinchat_cir, | |
1490 _("sub <class> <instance> <recipient>: Join a new chat")); | |
1491 | |
1492 gaim_cmd_register("zi","ws", GAIM_CMD_P_PRPL, | |
1493 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1494 "prpl-zephyr", | |
1495 zephyr_gaim_cmd_zi, _("zi <instance>: Send a message to <message,<i>instance</i>,*>")); | |
1496 | |
1497 gaim_cmd_register("zci","wws",GAIM_CMD_P_PRPL, | |
1498 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1499 "prpl-zephyr", | |
1500 zephyr_gaim_cmd_zci, | |
1501 _("zci <class> <instance>: Send a message to <<i>class</i>,<i>instance</i>,*>")); | |
1502 | |
1503 gaim_cmd_register("zcir","wwws",GAIM_CMD_P_PRPL, | |
1504 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1505 "prpl-zephyr", | |
1506 zephyr_gaim_cmd_zcir, | |
1507 _("zcir <class> <instance> <recipient>: Send a message to <<i>class</i>,<i>instance</i>,<i>recipient</i>>")); | |
1508 | |
1509 gaim_cmd_register("zir","wws",GAIM_CMD_P_PRPL, | |
1510 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1511 "prpl-zephyr", | |
1512 zephyr_gaim_cmd_zir, | |
1513 _("zir <instance> <recipient>: Send a message to <MESSAGE,<i>instance</i>,<i>recipient</i>>")); | |
1514 | |
1515 gaim_cmd_register("zc","ws", GAIM_CMD_P_PRPL, | |
1516 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
1517 "prpl-zephyr", | |
1518 zephyr_gaim_cmd_zc, _("zc <class>: Send a message to <<i>class</i>,PERSONAL,*>")); | |
1519 | |
1520 } | |
1521 | |
1522 | |
9427 | 1523 static int zephyr_resubscribe(GaimConnection *gc) |
1524 { | |
1525 /* Resubscribe to the in-memory list of subscriptions and also | |
1526 unsubscriptions*/ | |
1527 | |
1528 GSList *s = subscrips; | |
1529 zephyr_triple *zt; | |
1530 ZSubscription_t zst; | |
1531 while (s) { | |
1532 zt = s->data; | |
1533 zst.zsub_class = zt->class; | |
1534 zst.zsub_classinst = zt->instance; | |
1535 zst.zsub_recipient = zt->recipient; | |
1536 ZSubscribeTo(&zst, 1, 0); | |
1537 /* XXX We really should care if this fails */ | |
1538 s = s->next; | |
1539 } | |
1540 /* XXX handle unsubscriptions */ | |
1541 return 1; | |
1542 } | |
1543 | |
9434 | 1544 |
9427 | 1545 static void zephyr_action_resubscribe(GaimPluginAction *action) |
1546 { | |
1547 | |
1548 GaimConnection *gc = (GaimConnection *) action->context; | |
1549 zephyr_resubscribe(gc); | |
1550 } | |
1551 | |
1552 | |
1553 static GList *zephyr_actions(GaimPlugin *plugin, gpointer context) | |
1554 { | |
1555 GList *list = NULL; | |
1556 GaimPluginAction *act = NULL; | |
1557 | |
1558 act = gaim_plugin_action_new(_("Resubscribe"), zephyr_action_resubscribe); | |
1559 list = g_list_append(list, act); | |
1560 | |
1561 return list; | |
1562 } | |
1563 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1564 static GaimPlugin *my_protocol = NULL; |
2086 | 1565 |
8644 | 1566 static GaimPluginProtocolInfo prpl_info = { |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
1567 GAIM_PRPL_API_VERSION, |
8644 | 1568 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1569 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1570 NULL, |
9308 | 1571 NO_BUDDY_ICONS, |
1572 zephyr_list_icon, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1573 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1574 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1575 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1576 zephyr_away_states, |
9030 | 1577 NULL, |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1578 zephyr_chat_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1579 zephyr_login, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1580 zephyr_close, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1581 zephyr_send_im, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1582 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1583 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1584 zephyr_zloc, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1585 zephyr_set_away, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1586 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1587 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1588 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1589 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1590 NULL, |
8644 | 1591 NULL, |
1592 NULL, | |
1593 NULL, | |
1594 NULL, | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1595 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1596 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1597 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1598 zephyr_join_chat, |
8644 | 1599 NULL, /* reject chat invite */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1600 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1601 zephyr_chat_leave, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1602 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1603 zephyr_chat_send, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1604 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1605 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1606 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1607 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1608 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1609 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1610 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1611 NULL, |
8568 | 1612 NULL, |
8212 | 1613 zephyr_normalize, |
8568 | 1614 NULL, |
1615 NULL, | |
1616 NULL, | |
8586 | 1617 zephyr_chat_set_topic, |
8644 | 1618 NULL, |
1619 NULL, | |
1620 NULL, | |
1621 NULL | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1622 }; |
2086 | 1623 |
8644 | 1624 static GaimPluginInfo info = { |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
1625 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
8644 | 1626 GAIM_PLUGIN_PROTOCOL, /**< type */ |
1627 NULL, /**< ui_requirement */ | |
1628 0, /**< flags */ | |
1629 NULL, /**< dependencies */ | |
1630 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1631 |
8644 | 1632 "prpl-zephyr", /**< id */ |
1633 "Zephyr", /**< name */ | |
1634 VERSION, /**< version */ | |
1635 /** summary */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1636 N_("Zephyr Protocol Plugin"), |
8644 | 1637 /** description */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1638 N_("Zephyr Protocol Plugin"), |
8644 | 1639 NULL, /**< author */ |
1640 GAIM_WEBSITE, /**< homepage */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1641 |
8644 | 1642 NULL, /**< load */ |
1643 NULL, /**< unload */ | |
1644 NULL, /**< destroy */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1645 |
8644 | 1646 NULL, /**< ui_info */ |
8993 | 1647 &prpl_info, /**< extra_info */ |
1648 NULL, | |
9427 | 1649 zephyr_actions |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1650 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1651 |
8644 | 1652 static void init_plugin(GaimPlugin * plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1653 { |
8212 | 1654 GaimAccountOption *option; |
8644 | 1655 char *tmp = get_exposure_level(); |
1656 | |
1657 option = gaim_account_option_bool_new(_("Export to .anyone"), "write_anyone", FALSE); | |
1658 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8212 | 1659 |
8644 | 1660 option = gaim_account_option_bool_new(_("Export to .zephyr.subs"), "write_zsubs", FALSE); |
1661 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8212 | 1662 |
8644 | 1663 option = gaim_account_option_string_new(_("Exposure"), "exposure_level", tmp ? tmp : EXPOSE_REALMVIS); |
1664 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8212 | 1665 |
8644 | 1666 option = gaim_account_option_string_new(_("Encoding"), "encoding", ZEPHYR_FALLBACK_CHARSET); |
1667 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8560 | 1668 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1669 my_protocol = plugin; |
9434 | 1670 zephyr_register_slash_commands(); |
2086 | 1671 } |
1672 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1673 GAIM_INIT_PLUGIN(zephyr, init_plugin, info); |