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