Mercurial > pidgin
annotate src/protocols/zephyr/zephyr.c @ 6190:7bd5d81a9faf
[gaim-migrate @ 6676]
The day of swine and roses...
committer: Tailor Script <tailor@pidgin.im>
author | Rob Flynn <gaim@robflynn.com> |
---|---|
date | Thu, 17 Jul 2003 22:54:18 +0000 |
parents | d8cd876e613e |
children | 8f94cce8faa5 |
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 | |
7 * Jag/Sean Dilda <agrajag@linuxpower.org>/<smdilda@unity.ncsu.edu> | |
8 * http://gtkzephyr.linuxpower.org/ | |
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 |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
28 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 #include "multi.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" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
34 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
35 #include "zephyr/zephyr.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
36 |
2086 | 37 #include "gaim.h" |
38 | |
39 extern Code_t ZGetLocations(ZLocations_t *, int *); | |
40 extern Code_t ZSetLocation(char *); | |
41 extern Code_t ZUnsetLocation(); | |
42 | |
43 typedef struct _zframe zframe; | |
44 typedef struct _zephyr_triple zephyr_triple; | |
45 | |
46 /* struct I need for zephyr_to_html */ | |
47 struct _zframe { | |
48 /* true for everything but @color, since inside the parens of that one is | |
49 * the color. */ | |
50 gboolean has_closer; | |
51 /* </i>, </font>, </b>, etc. */ | |
52 char *closing; | |
53 /* text including the opening html thingie. */ | |
54 GString *text; | |
55 struct _zframe *enclosing; | |
56 }; | |
57 | |
58 struct _zephyr_triple { | |
59 char *class; | |
60 char *instance; | |
61 char *recipient; | |
62 char *name; | |
63 gboolean open; | |
64 int id; | |
65 }; | |
66 | |
67 #define z_call(func) if (func != ZERR_NONE)\ | |
68 return; | |
69 #define z_call_r(func) if (func != ZERR_NONE)\ | |
70 return TRUE; | |
71 #define z_call_s(func, err) if (func != ZERR_NONE) {\ | |
5606 | 72 gaim_connection_error(zgc, err);\ |
2086 | 73 return;\ |
74 } | |
75 | |
76 static char *zephyr_normalize(const char *); | |
77 | |
78 /* this is so bad, and if Zephyr weren't so fucked up to begin with I | |
79 * wouldn't do this. but it is so i will. */ | |
80 static guint32 nottimer = 0; | |
81 static guint32 loctimer = 0; | |
5606 | 82 GaimConnection *zgc = NULL; |
2086 | 83 static GList *pending_zloc_names = NULL; |
84 static GSList *subscrips = NULL; | |
85 static int last_id = 0; | |
86 | |
87 /* just for debugging | |
88 static void handle_unknown(ZNotice_t notice) | |
89 { | |
3630 | 90 debug_printf("z_packet: %s\n", notice.z_packet); |
91 debug_printf("z_version: %s\n", notice.z_version); | |
92 debug_printf("z_kind: %d\n", notice.z_kind); | |
93 debug_printf("z_class: %s\n", notice.z_class); | |
94 debug_printf("z_class_inst: %s\n", notice.z_class_inst); | |
95 debug_printf("z_opcode: %s\n", notice.z_opcode); | |
96 debug_printf("z_sender: %s\n", notice.z_sender); | |
97 debug_printf("z_recipient: %s\n", notice.z_recipient); | |
98 debug_printf("z_message: %s\n", notice.z_message); | |
99 debug_printf("z_message_len: %d\n", notice.z_message_len); | |
100 debug_printf("\n"); | |
2086 | 101 } |
102 */ | |
103 | |
104 static zephyr_triple *new_triple(const char *c, const char *i, const char *r) | |
105 { | |
106 zephyr_triple *zt; | |
107 zt = g_new0(zephyr_triple, 1); | |
108 zt->class = g_strdup(c); | |
109 zt->instance = g_strdup(i); | |
110 zt->recipient = g_strdup(r); | |
111 zt->name = g_strdup_printf("%s,%s,%s", c, i, r); | |
112 zt->id = ++last_id; | |
113 zt->open = FALSE; | |
114 return zt; | |
115 } | |
116 | |
117 static void free_triple(zephyr_triple *zt) | |
118 { | |
119 g_free(zt->class); | |
120 g_free(zt->instance); | |
121 g_free(zt->recipient); | |
122 g_free(zt->name); | |
123 g_free(zt); | |
124 } | |
125 | |
126 /* returns true if zt1 is a subset of zt2, i.e. zt2 has the same thing or | |
127 * wildcards in each field of zt1. */ | |
128 static gboolean triple_subset(zephyr_triple *zt1, zephyr_triple *zt2) | |
129 { | |
4793 | 130 if (g_ascii_strcasecmp(zt2->class, zt1->class) && |
131 g_ascii_strcasecmp(zt2->class, "*")) { | |
2086 | 132 return FALSE; |
133 } | |
4793 | 134 if (g_ascii_strcasecmp(zt2->instance, zt1->instance) && |
135 g_ascii_strcasecmp(zt2->instance, "*")) { | |
2086 | 136 return FALSE; |
137 } | |
4793 | 138 if (g_ascii_strcasecmp(zt2->recipient, zt1->recipient) && |
139 g_ascii_strcasecmp(zt2->recipient, "*")) { | |
2086 | 140 return FALSE; |
141 } | |
142 return TRUE; | |
143 } | |
144 | |
145 static zephyr_triple *find_sub_by_triple(zephyr_triple *zt) | |
146 { | |
147 zephyr_triple *curr_t; | |
148 GSList *curr = subscrips; | |
149 while (curr) { | |
150 curr_t = curr->data; | |
151 if (triple_subset(zt, curr_t)) | |
152 return curr_t; | |
153 curr = curr->next; | |
154 } | |
155 return NULL; | |
156 } | |
157 | |
158 static zephyr_triple *find_sub_by_id(int id) | |
159 { | |
160 zephyr_triple *zt; | |
161 GSList *curr = subscrips; | |
162 while (curr) { | |
163 zt = curr->data; | |
164 if (zt->id == id) | |
165 return zt; | |
166 curr = curr->next; | |
167 } | |
168 return NULL; | |
169 } | |
170 | |
171 /* utility macros that are useful for zephyr_to_html */ | |
172 | |
173 #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) | |
174 #define IS_CLOSER(c) ((c == '}') || (c == ']') || (c == ')') || (c == '>')) | |
175 | |
176 /* this parses zephyr formatting and converts it to html. For example, if | |
177 * you pass in "@{@color(blue)@i(hello)}" you should get out | |
178 * "<font color=blue><i>hello</i></font>". */ | |
179 static char *zephyr_to_html(char *message) | |
180 { | |
181 int len, cnt; | |
182 zframe *frames, *curr; | |
183 char *ret; | |
184 | |
185 frames = g_new(zframe, 1); | |
186 frames->text = g_string_new(""); | |
187 frames->enclosing = NULL; | |
188 frames->closing = ""; | |
189 frames->has_closer = FALSE; | |
190 | |
191 len = strlen(message); | |
192 cnt = 0; | |
193 while (cnt <= len) { | |
194 if (message[cnt] == '@') { | |
195 zframe *new_f; | |
196 char *buf; | |
197 int end; | |
198 for (end=1; (cnt+end) <= len && | |
199 !IS_OPENER(message[cnt+end]); end++); | |
200 buf = g_new0(char, end); | |
201 if (end) { | |
202 g_snprintf(buf, end, "%s", message+cnt+1); | |
203 } | |
4793 | 204 if (!g_ascii_strcasecmp(buf, "italic") || |
205 !g_ascii_strcasecmp(buf, "i")) { | |
2086 | 206 new_f = g_new(zframe, 1); |
207 new_f->enclosing = frames; | |
208 new_f->text = g_string_new("<i>"); | |
209 new_f->closing = "</i>"; | |
210 new_f->has_closer = TRUE; | |
211 frames = new_f; | |
212 cnt += end+1; /* cnt points to char after opener */ | |
4793 | 213 } else if (!g_ascii_strcasecmp(buf, "bold") |
214 || !g_ascii_strcasecmp(buf, "b")) { | |
2086 | 215 new_f = g_new(zframe, 1); |
216 new_f->enclosing = frames; | |
217 new_f->text = g_string_new("<b>"); | |
218 new_f->closing = "</b>"; | |
219 new_f->has_closer = TRUE; | |
220 frames = new_f; | |
221 cnt += end+1; | |
4793 | 222 } else if (!g_ascii_strcasecmp(buf, "color")) { |
2086 | 223 cnt += end+1; |
224 new_f = g_new(zframe, 1); | |
225 new_f->enclosing = frames; | |
226 new_f->text = g_string_new("<font color="); | |
227 for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
228 g_string_append_c(new_f->text, message[cnt]); | |
229 } | |
230 cnt++; /* point to char after closer */ | |
231 g_string_append_c(new_f->text, '>'); | |
232 new_f->closing = "</font>"; | |
233 new_f->has_closer = FALSE; | |
234 frames = new_f; | |
4793 | 235 } else if (!g_ascii_strcasecmp(buf, "")) { |
2086 | 236 new_f = g_new(zframe, 1); |
237 new_f->enclosing = frames; | |
238 new_f->text = g_string_new(""); | |
239 new_f->closing = ""; | |
240 new_f->has_closer = TRUE; | |
241 frames = new_f; | |
242 cnt += end+1; /* cnt points to char after opener */ | |
243 } else { | |
244 if ((cnt+end) > len) { | |
245 g_string_append_c(frames->text, '@'); | |
246 cnt++; | |
247 } else { | |
248 /* unrecognized thingie. act like it's not there, but we | |
249 * still need to take care of the corresponding closer, | |
250 * make a frame that does nothing. */ | |
251 new_f = g_new(zframe, 1); | |
252 new_f->enclosing = frames; | |
253 new_f->text = g_string_new(""); | |
254 new_f->closing = ""; | |
255 new_f->has_closer = TRUE; | |
256 frames = new_f; | |
257 cnt += end+1; /* cnt points to char after opener */ | |
258 } | |
259 } | |
260 } else if (IS_CLOSER(message[cnt])) { | |
261 zframe *popped; | |
262 gboolean last_had_closer; | |
263 if (frames->enclosing) { | |
264 do { | |
265 popped = frames; | |
266 frames = frames->enclosing; | |
267 g_string_append(frames->text, popped->text->str); | |
268 g_string_append(frames->text, popped->closing); | |
269 g_string_free(popped->text, TRUE); | |
270 last_had_closer = popped->has_closer; | |
271 g_free(popped); | |
272 } while (frames && frames->enclosing && !last_had_closer); | |
273 } else { | |
274 g_string_append_c(frames->text, message[cnt]); | |
275 } | |
276 cnt++; | |
277 } else if (message[cnt] == '\n') { | |
278 g_string_append(frames->text, "<br>"); | |
279 cnt++; | |
280 } else { | |
281 g_string_append_c(frames->text, message[cnt++]); | |
282 } | |
283 } | |
284 /* go through all the stuff that they didn't close */ | |
285 while (frames->enclosing) { | |
286 curr = frames; | |
287 g_string_append(frames->enclosing->text, frames->text->str); | |
288 g_string_append(frames->enclosing->text, frames->closing); | |
289 g_string_free(frames->text, TRUE); | |
290 frames = frames->enclosing; | |
291 g_free(curr); | |
292 } | |
293 ret = frames->text->str; | |
294 g_string_free(frames->text, FALSE); | |
295 g_free(frames); | |
296 return ret; | |
297 } | |
298 | |
299 static gboolean pending_zloc(char *who) | |
300 { | |
301 GList *curr; | |
302 for (curr = pending_zloc_names; curr != NULL; curr = curr->next) { | |
4793 | 303 if (!g_ascii_strcasecmp(who, (char*)curr->data)) { |
2086 | 304 g_free((char*)curr->data); |
305 pending_zloc_names = g_list_remove(pending_zloc_names, curr->data); | |
306 return TRUE; | |
307 } | |
308 } | |
309 return FALSE; | |
310 } | |
311 | |
312 static void handle_message(ZNotice_t notice, struct sockaddr_in from) | |
313 { | |
4793 | 314 if (!g_ascii_strcasecmp(notice.z_class, LOGIN_CLASS)) { |
3277 | 315 /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */ |
4793 | 316 } else if (!g_ascii_strcasecmp(notice.z_class, LOCATE_CLASS)) { |
317 if (!g_ascii_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
2086 | 318 int nlocs; |
319 char *user; | |
320 struct buddy *b; | |
321 | |
322 if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) | |
323 return; | |
4687 | 324 if ((b = gaim_find_buddy(zgc->account, user)) == NULL) { |
2086 | 325 char *e = strchr(user, '@'); |
326 if (e) *e = '\0'; | |
4687 | 327 b = gaim_find_buddy(zgc->account, user); |
2086 | 328 } |
329 if (!b) { | |
330 free(user); | |
331 return; | |
332 } | |
333 if (pending_zloc(b->name)) { | |
334 ZLocations_t locs; | |
335 int one = 1; | |
336 GString *str = g_string_new(""); | |
5132 | 337 g_string_append_printf(str, _("<b>User:</b> %s<br>"), b->name); |
338 if (b->alias) | |
339 g_string_append_printf(str, _("<b>Alias:</b> %s<br>"), b->alias); | |
2086 | 340 if (!nlocs) { |
5132 | 341 g_string_append_printf(str, _("<br>Hidden or not logged-in")); |
2086 | 342 } |
343 for (; nlocs > 0; nlocs--) { | |
344 ZGetLocations(&locs, &one); | |
5132 | 345 g_string_append_printf(str, _("<br>At %s since %s"), locs.host, |
2086 | 346 locs.time); |
347 } | |
2791
8f6365332a05
[gaim-migrate @ 2804]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2773
diff
changeset
|
348 g_show_info_text(NULL, NULL, 2, str->str, NULL); |
2086 | 349 g_string_free(str, TRUE); |
350 } else | |
4732 | 351 serv_got_update(zgc, b->name, nlocs, 0, 0, 0, 0); |
2086 | 352 |
353 free(user); | |
354 } | |
355 } else { | |
356 char *buf, *buf2; | |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
357 char *send_inst; |
3277 | 358 char *realmptr; |
359 char *sendertmp; | |
2086 | 360 char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
361 int len = notice.z_message_len - (ptr - notice.z_message); | |
362 int away; | |
363 if (len > 0) { | |
364 buf = g_malloc(len + 1); | |
365 g_snprintf(buf, len + 1, "%s", ptr); | |
366 g_strchomp(buf); | |
367 buf2 = zephyr_to_html(buf); | |
368 g_free(buf); | |
4793 | 369 if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && |
370 !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL")) { | |
371 if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) | |
2086 | 372 away = TRUE; |
373 else | |
374 away = FALSE; | |
2856
b1e300a85678
[gaim-migrate @ 2869]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2804
diff
changeset
|
375 serv_got_im(zgc, notice.z_sender, buf2, 0, time(NULL), -1); |
2086 | 376 } else { |
377 zephyr_triple *zt1, *zt2; | |
378 zt1 = new_triple(notice.z_class, notice.z_class_inst, | |
4687 | 379 notice.z_recipient); |
2086 | 380 zt2 = find_sub_by_triple(zt1); |
381 if (!zt2) { | |
382 /* we shouldn't be subscribed to this message. ignore. */ | |
383 } else { | |
384 if (!zt2->open) { | |
385 zt2->open = TRUE; | |
386 serv_got_joined_chat(zgc, zt2->id, zt2->name); | |
387 } | |
3277 | 388 /* If the person is in the default Realm, then strip the |
389 Realm from the sender field */ | |
390 sendertmp = g_strdup_printf("%s",notice.z_sender); | |
4682 | 391 if ((realmptr = strchr(sendertmp,'@')) != NULL) { |
4588 | 392 realmptr++; |
4793 | 393 if (!g_ascii_strcasecmp(realmptr,ZGetRealm())) { |
4588 | 394 realmptr--; |
395 sprintf(realmptr,"%c",'\0'); | |
396 send_inst = g_strdup_printf("%s %s",sendertmp, | |
397 notice.z_class_inst); | |
398 } else { | |
399 send_inst = g_strdup_printf("%s %s",notice.z_sender, | |
400 notice.z_class_inst); | |
401 } | |
3277 | 402 } else { |
4588 | 403 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); |
3277 | 404 } |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
405 serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, |
4687 | 406 buf2, time(NULL)); |
3277 | 407 g_free(sendertmp); |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
408 g_free(send_inst); |
2086 | 409 } |
410 free_triple(zt1); | |
411 } | |
412 g_free(buf2); | |
413 } | |
414 } | |
415 } | |
416 | |
417 static gint check_notify(gpointer data) | |
418 { | |
419 while (ZPending()) { | |
420 ZNotice_t notice; | |
421 struct sockaddr_in from; | |
422 z_call_r(ZReceiveNotice(¬ice, &from)); | |
423 | |
424 switch (notice.z_kind) { | |
425 case UNSAFE: | |
426 case UNACKED: | |
427 case ACKED: | |
428 handle_message(notice, from); | |
429 break; | |
430 default: | |
431 /* we'll just ignore things for now */ | |
432 debug_printf("ZEPHYR: Unhandled Notice\n"); | |
433 break; | |
434 } | |
435 | |
436 ZFreeNotice(¬ice); | |
437 } | |
438 | |
439 return TRUE; | |
440 } | |
441 | |
442 static gint check_loc(gpointer data) | |
443 { | |
4785 | 444 GaimBlistNode *gnode,*bnode; |
2086 | 445 ZAsyncLocateData_t ald; |
446 | |
447 ald.user = NULL; | |
448 memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
449 ald.version = NULL; | |
450 | |
4785 | 451 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
452 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
453 continue; | |
454 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
455 struct buddy *b = (struct buddy *)bnode; | |
456 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
457 continue; | |
4491 | 458 if(b->account->gc == zgc) { |
4349 | 459 char *chk; |
460 chk = zephyr_normalize(b->name); | |
461 /* doesn't matter if this fails or not; we'll just move on to the next one */ | |
462 ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
463 free(ald.user); | |
464 free(ald.version); | |
465 } | |
2086 | 466 } |
467 } | |
468 | |
469 return TRUE; | |
470 } | |
471 | |
472 static char *get_exposure_level() | |
473 { | |
474 char *exposure = ZGetVariable("exposure"); | |
475 | |
476 if (!exposure) | |
477 return EXPOSE_REALMVIS; | |
4793 | 478 if (!g_ascii_strcasecmp(exposure, EXPOSE_NONE)) |
2086 | 479 return EXPOSE_NONE; |
4793 | 480 if (!g_ascii_strcasecmp(exposure, EXPOSE_OPSTAFF)) |
2086 | 481 return EXPOSE_OPSTAFF; |
4793 | 482 if (!g_ascii_strcasecmp(exposure, EXPOSE_REALMANN)) |
2086 | 483 return EXPOSE_REALMANN; |
4793 | 484 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETVIS)) |
2086 | 485 return EXPOSE_NETVIS; |
4793 | 486 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETANN)) |
2086 | 487 return EXPOSE_NETANN; |
488 return EXPOSE_REALMVIS; | |
489 } | |
490 | |
491 static void strip_comments(char *str) | |
492 { | |
493 char *tmp = strchr(str, '#'); | |
494 if (tmp) | |
495 *tmp = '\0'; | |
496 g_strchug(str); | |
497 g_strchomp(str); | |
498 } | |
499 | |
500 static void process_zsubs() | |
501 { | |
502 FILE *f; | |
503 gchar *fname; | |
504 gchar buff[BUFSIZ]; | |
505 | |
3630 | 506 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
2086 | 507 f = fopen(fname, "r"); |
508 if (f) { | |
509 char **triple; | |
510 ZSubscription_t sub; | |
511 char *recip; | |
512 while (fgets(buff, BUFSIZ, f)) { | |
513 strip_comments(buff); | |
514 if (buff[0]) { | |
515 triple = g_strsplit(buff, ",", 3); | |
3277 | 516 if (triple[0] && triple[1] ) { |
5132 | 517 /* char *tmp = g_strdup_printf("%s@%s", g_getenv("USER"), ZGetRealm()); */ |
4588 | 518 char *tmp = g_strdup_printf("%s",ZGetSender()); |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
519 char *atptr; |
2086 | 520 sub.zsub_class = triple[0]; |
521 sub.zsub_classinst = triple[1]; | |
3277 | 522 if(triple[2] == NULL) { |
523 recip = g_malloc0(1); | |
4793 | 524 } else if (!g_ascii_strcasecmp(triple[2], "%me%")) { |
4588 | 525 recip = g_strdup_printf("%s",ZGetSender()); |
4793 | 526 } else if (!g_ascii_strcasecmp(triple[2], "*")) { |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
527 /* wildcard |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
528 * form of class,instance,* */ |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
529 recip = g_malloc0(1); |
4793 | 530 } else if (!g_ascii_strcasecmp(triple[2], tmp)) { |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
531 /* form of class,instance,aatharuv@ATHENA.MIT.EDU */ |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
532 recip = g_strdup(triple[2]); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
533 } else if ((atptr = strchr(triple[2], '@')) != NULL) { |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
534 /* form of class,instance,*@ANDREW.CMU.EDU |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
535 * class,instance,@ANDREW.CMU.EDU |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
536 * If realm is local realm, blank recipient, else |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
537 * @REALM-NAME |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
538 */ |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
539 char *realmat = g_strdup_printf("@%s", ZGetRealm()); |
4793 | 540 if (!g_ascii_strcasecmp(atptr, realmat)) |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
541 recip = g_malloc0(1); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
542 else |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
543 recip = g_strdup(atptr); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
544 g_free(realmat); |
2086 | 545 } else { |
546 recip = g_strdup(triple[2]); | |
547 } | |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
548 g_free(tmp); |
2086 | 549 sub.zsub_recipient = recip; |
550 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
551 debug_printf("Zephyr: Couldn't subscribe to %s, %s, " | |
552 "%s\n", | |
553 sub.zsub_class, | |
554 sub.zsub_classinst, | |
555 sub.zsub_recipient); | |
556 } | |
557 subscrips = g_slist_append(subscrips, | |
558 new_triple(triple[0], triple[1], recip)); | |
559 g_free(recip); | |
560 } | |
561 g_strfreev(triple); | |
562 } | |
563 } | |
564 } | |
565 } | |
566 | |
567 static void process_anyone() | |
568 { | |
569 FILE *fd; | |
570 gchar buff[BUFSIZ], *filename; | |
4775 | 571 struct group *g; |
4687 | 572 struct buddy *b; |
4775 | 573 |
574 if (!(g = gaim_find_group(_("Anyone")))) { | |
575 g = gaim_group_new(_("Anyone")); | |
576 gaim_blist_add_group(g, NULL); | |
577 } | |
4687 | 578 |
3630 | 579 filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); |
2086 | 580 if ((fd = fopen(filename, "r")) != NULL) { |
581 while (fgets(buff, BUFSIZ, fd)) { | |
582 strip_comments(buff); | |
4687 | 583 if (buff[0]) { |
584 b = gaim_buddy_new(zgc->account, buff, NULL); | |
585 gaim_blist_add_buddy(b, g, NULL); | |
586 } | |
2086 | 587 } |
588 fclose(fd); | |
589 } | |
590 g_free(filename); | |
591 } | |
592 | |
5606 | 593 static void zephyr_login(GaimAccount *account) |
2086 | 594 { |
595 ZSubscription_t sub; | |
596 | |
597 if (zgc) { | |
5436
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
598 gaim_notify_error(account->gc, NULL, |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
599 _("Already logged in with Zephyr"), |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
600 _("Because Zephyr uses your system username, you " |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
601 "are unable to have multiple accounts on it " |
ad445074d239
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
602 "when logged in as the same user.")); |
2086 | 603 return; |
604 } | |
605 | |
5606 | 606 zgc = gaim_account_get_connection(account); |
2086 | 607 |
608 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); | |
609 z_call_s(ZOpenPort(NULL), "Couldn't open port"); | |
610 z_call_s(ZSetLocation(get_exposure_level()), "Couldn't set location"); | |
611 | |
612 sub.zsub_class = "MESSAGE"; | |
613 sub.zsub_classinst = "PERSONAL"; | |
614 sub.zsub_recipient = ZGetSender(); | |
615 | |
616 /* we don't care if this fails. i'm lying right now. */ | |
617 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
618 debug_printf("Zephyr: Couldn't subscribe to messages!\n"); | |
619 } | |
620 | |
5606 | 621 gaim_connection_set_state(zgc, GAIM_CONNECTED); |
2086 | 622 serv_finish_login(zgc); |
623 | |
624 process_anyone(); | |
625 process_zsubs(); | |
626 | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
627 nottimer = g_timeout_add(100, check_notify, NULL); |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
628 loctimer = g_timeout_add(20000, check_loc, NULL); |
2086 | 629 } |
630 | |
631 static void write_zsubs() | |
632 { | |
633 GSList *s = subscrips; | |
634 zephyr_triple *zt; | |
635 FILE *fd; | |
636 char *fname; | |
637 | |
3277 | 638 char** triple; |
3630 | 639 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
2086 | 640 fd = fopen(fname, "w"); |
641 | |
642 if (!fd) { | |
643 g_free(fname); | |
644 return; | |
645 } | |
646 | |
647 while (s) { | |
648 zt = s->data; | |
3277 | 649 triple = g_strsplit(zt->name,",",3); |
650 if (triple[2] != NULL) { | |
4793 | 651 if (!g_ascii_strcasecmp(triple[2], "")) { |
3277 | 652 fprintf(fd, "%s,%s,*\n", triple[0], triple[1]); |
4793 | 653 } else if (!g_ascii_strcasecmp(triple[2], ZGetSender())) { |
3277 | 654 fprintf(fd, "%s,%s,%%me%%\n",triple[0],triple[1]); |
655 } else { | |
656 fprintf(fd, "%s\n", zt->name); | |
657 } | |
658 } else { | |
659 fprintf(fd, "%s,%s,*\n",triple[0], triple[1]); | |
660 } | |
661 g_free(triple); | |
2086 | 662 s = s->next; |
663 } | |
664 g_free(fname); | |
665 fclose(fd); | |
666 } | |
667 | |
668 static void write_anyone() | |
669 { | |
4785 | 670 GaimBlistNode *gnode,*bnode; |
2086 | 671 struct buddy *b; |
3277 | 672 char *ptr, *fname, *ptr2; |
2086 | 673 FILE *fd; |
674 | |
3630 | 675 fname = g_strdup_printf("%s/.anyone", gaim_home_dir()); |
2086 | 676 fd = fopen(fname, "w"); |
677 if (!fd) { | |
678 g_free(fname); | |
679 return; | |
680 } | |
681 | |
4785 | 682 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
683 if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
684 continue; | |
685 for(bnode = gnode->child; bnode; bnode = bnode->next) { | |
686 if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
687 continue; | |
688 b = (struct buddy *)bnode; | |
4491 | 689 if(b->account->gc == zgc) { |
4349 | 690 if ((ptr = strchr(b->name, '@')) != NULL) { |
691 ptr2 = ptr + 1; | |
692 /* We should only strip the realm name if the principal | |
693 is in the user's realm | |
694 */ | |
4793 | 695 if (!g_ascii_strcasecmp(ptr2,ZGetRealm())) { |
4349 | 696 *ptr = '\0'; |
697 } | |
3277 | 698 } |
4349 | 699 fprintf(fd, "%s\n", b->name); |
700 if (ptr) | |
701 *ptr = '@'; | |
3277 | 702 } |
2086 | 703 } |
704 } | |
705 | |
706 fclose(fd); | |
707 g_free(fname); | |
708 } | |
709 | |
5606 | 710 static void zephyr_close(GaimConnection *gc) |
2086 | 711 { |
712 GList *l; | |
713 GSList *s; | |
714 l = pending_zloc_names; | |
715 while (l) { | |
716 g_free((char*)l->data); | |
717 l = l->next; | |
718 } | |
719 g_list_free(pending_zloc_names); | |
720 | |
721 write_anyone(); | |
722 write_zsubs(); | |
723 | |
724 s = subscrips; | |
725 while (s) { | |
726 free_triple((zephyr_triple*)s->data); | |
727 s = s->next; | |
728 } | |
729 g_slist_free(subscrips); | |
730 | |
731 if (nottimer) | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
732 g_source_remove(nottimer); |
2086 | 733 nottimer = 0; |
734 if (loctimer) | |
2131
acc11216ec5d
[gaim-migrate @ 2141]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
735 g_source_remove(loctimer); |
2086 | 736 loctimer = 0; |
737 zgc = NULL; | |
738 z_call(ZCancelSubscriptions(0)); | |
739 z_call(ZUnsetLocation()); | |
740 z_call(ZClosePort()); | |
741 } | |
742 | |
5606 | 743 static void zephyr_add_buddy(GaimConnection *gc, const char *buddy) { } |
6059 | 744 static void zephyr_remove_buddy(GaimConnection *gc, const char *buddy, const char *group) { } |
2086 | 745 |
6059 | 746 static int zephyr_chat_send(GaimConnection *gc, int id, const char *im) |
2086 | 747 { |
748 ZNotice_t notice; | |
749 zephyr_triple *zt; | |
750 char *buf; | |
751 const char *sig; | |
752 | |
753 zt = find_sub_by_id(id); | |
754 if (!zt) | |
755 /* this should never happen. */ | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
756 return -EINVAL; |
2086 | 757 |
758 sig = ZGetVariable("zwrite-signature"); | |
759 if (!sig) { | |
760 sig = g_get_real_name(); | |
761 } | |
762 buf = g_strdup_printf("%s%c%s", sig, '\0', im); | |
763 | |
764 bzero((char *)¬ice, sizeof(notice)); | |
765 notice.z_kind = ACKED; | |
766 notice.z_port = 0; | |
767 notice.z_opcode = ""; | |
768 notice.z_class = zt->class; | |
769 notice.z_class_inst = zt->instance; | |
4793 | 770 if (!g_ascii_strcasecmp(zt->recipient, "*")) |
2086 | 771 notice.z_recipient = zephyr_normalize(""); |
772 else | |
773 notice.z_recipient = zephyr_normalize(zt->recipient); | |
774 notice.z_sender = 0; | |
775 notice.z_default_format = | |
776 "Class $class, Instance $instance:\n" | |
777 "To: @bold($recipient) at $time $date\n" | |
778 "From: @bold($1) <$sender>\n\n$2"; | |
779 notice.z_message_len = strlen(im) + strlen(sig) + 4; | |
780 notice.z_message = buf; | |
781 ZSendNotice(¬ice, ZAUTH); | |
782 g_free(buf); | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
783 return 0; |
2086 | 784 } |
785 | |
5606 | 786 static int zephyr_send_im(GaimConnection *gc, const char *who, const char *im, int len, int flags) { |
2086 | 787 ZNotice_t notice; |
788 char *buf; | |
789 const char *sig; | |
790 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
791 if (flags & IM_FLAG_AWAY) |
2086 | 792 sig = "Automated reply:"; |
793 else { | |
794 sig = ZGetVariable("zwrite-signature"); | |
795 if (!sig) { | |
796 sig = g_get_real_name(); | |
797 } | |
798 } | |
799 buf = g_strdup_printf("%s%c%s", sig, '\0', im); | |
800 | |
801 bzero((char *)¬ice, sizeof(notice)); | |
802 notice.z_kind = ACKED; | |
803 notice.z_port = 0; | |
804 notice.z_opcode = ""; | |
805 notice.z_class = "MESSAGE"; | |
806 notice.z_class_inst = "PERSONAL"; | |
807 notice.z_sender = 0; | |
808 notice.z_recipient = who; | |
809 notice.z_default_format = | |
810 "Class $class, Instance $instance:\n" | |
811 "To: @bold($recipient) at $time $date\n" | |
812 "From: @bold($1) <$sender>\n\n$2"; | |
813 notice.z_message_len = strlen(im) + strlen(sig) + 4; | |
814 notice.z_message = buf; | |
815 g_free(buf); | |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2231
diff
changeset
|
816 return 1; |
2086 | 817 } |
818 | |
819 static char *zephyr_normalize(const char *orig) | |
820 { | |
821 static char buf[80]; | |
822 if (strchr(orig, '@')) { | |
823 g_snprintf(buf, 80, "%s", orig); | |
824 } else { | |
825 g_snprintf(buf, 80, "%s@%s", orig, ZGetRealm()); | |
826 } | |
827 return buf; | |
828 } | |
829 | |
5606 | 830 static void zephyr_zloc(GaimConnection *gc, const char *who) |
2086 | 831 { |
832 ZAsyncLocateData_t ald; | |
833 | |
834 if (ZRequestLocations(zephyr_normalize(who), &ald, UNACKED, ZAUTH) | |
835 != ZERR_NONE) { | |
836 return; | |
837 } | |
838 pending_zloc_names = g_list_append(pending_zloc_names, | |
839 g_strdup(zephyr_normalize(who))); | |
840 } | |
841 | |
5606 | 842 static GList *zephyr_buddy_menu(GaimConnection *gc, const char *who) |
2086 | 843 { |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
844 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
845 struct proto_buddy_menu *pbm; |
2086 | 846 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
847 pbm = g_new0(struct proto_buddy_menu, 1); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
848 pbm->label = _("ZLocate"); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
849 pbm->callback = zephyr_zloc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
850 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
851 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
852 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2167
diff
changeset
|
853 return m; |
2086 | 854 } |
855 | |
6059 | 856 static void zephyr_set_away(GaimConnection *gc, const char *state, const char *msg) |
2086 | 857 { |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
858 if (gc->away) { |
2086 | 859 g_free(gc->away); |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
860 gc->away = NULL; |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
861 } |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
862 |
5132 | 863 if (!g_ascii_strcasecmp(state, _("Hidden"))) { |
2086 | 864 ZSetLocation(EXPOSE_OPSTAFF); |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
865 gc->away = g_strdup(""); |
5132 | 866 } else if (!g_ascii_strcasecmp(state, _("Online"))) |
2086 | 867 ZSetLocation(get_exposure_level()); |
868 else /* state is GAIM_AWAY_CUSTOM */ if (msg) | |
869 gc->away = g_strdup(msg); | |
870 } | |
871 | |
5606 | 872 static GList *zephyr_away_states(GaimConnection *gc) |
2086 | 873 { |
874 GList *m = NULL; | |
875 | |
5132 | 876 m = g_list_append(m, _("Online")); |
2086 | 877 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
5132 | 878 m = g_list_append(m, _("Hidden")); |
2086 | 879 |
880 return m; | |
881 } | |
882 | |
5606 | 883 static GList *zephyr_chat_info(GaimConnection *gc) { |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
884 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
885 struct proto_chat_entry *pce; |
2086 | 886 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
887 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
888 pce->label = _("Class:"); |
5234 | 889 pce->identifier = "class"; |
3158 | 890 m = g_list_append(m, pce); |
2086 | 891 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
892 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
893 pce->label = _("Instance:"); |
5234 | 894 pce->identifier = "instance"; |
3158 | 895 m = g_list_append(m, pce); |
2086 | 896 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
897 pce = g_new0(struct proto_chat_entry, 1); |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
898 pce->label = _("Recipient:"); |
5234 | 899 pce->identifier = "recipient"; |
3158 | 900 m = g_list_append(m, pce); |
2086 | 901 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
902 return m; |
2086 | 903 } |
904 | |
5606 | 905 static void zephyr_join_chat(GaimConnection *gc, GHashTable *data) |
2086 | 906 { |
907 ZSubscription_t sub; | |
908 zephyr_triple *zt1, *zt2; | |
909 const char *classname; | |
910 const char *instname; | |
911 const char *recip; | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
912 |
5234 | 913 classname = g_hash_table_lookup(data, "class"); |
914 instname = g_hash_table_lookup(data, "instance"); | |
915 recip = g_hash_table_lookup(data, "recipient"); | |
916 | |
917 if (!classname || !instname || !recip) | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
918 return; |
2086 | 919 |
4793 | 920 if (!g_ascii_strcasecmp(recip, "%me%")) |
4588 | 921 recip = ZGetSender(); |
2086 | 922 |
923 zt1 = new_triple(classname, instname, recip); | |
924 zt2 = find_sub_by_triple(zt1); | |
925 if (zt2) { | |
926 free_triple(zt1); | |
927 if (!zt2->open) | |
928 serv_got_joined_chat(gc, zt2->id, zt2->name); | |
929 return; | |
930 } | |
931 | |
932 sub.zsub_class = zt1->class; | |
933 sub.zsub_classinst = zt1->instance; | |
934 sub.zsub_recipient = zt1->recipient; | |
935 | |
936 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
937 free_triple(zt1); | |
938 return; | |
939 } | |
940 | |
941 subscrips = g_slist_append(subscrips, zt1); | |
942 zt1->open = TRUE; | |
943 serv_got_joined_chat(gc, zt1->id, zt1->name); | |
944 } | |
945 | |
5606 | 946 static void zephyr_chat_leave(GaimConnection *gc, int id) |
2086 | 947 { |
948 zephyr_triple *zt; | |
949 zt = find_sub_by_id(id); | |
950 if (zt) { | |
951 zt->open = FALSE; | |
952 zt->id = ++last_id; | |
953 } | |
954 } | |
955 | |
5606 | 956 static const char *zephyr_list_icon(GaimAccount *a, struct buddy *b) |
5202 | 957 { |
958 return "zephyr"; | |
959 } | |
960 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
961 static GaimPlugin *my_protocol = NULL; |
2086 | 962 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
963 static GaimPluginProtocolInfo prpl_info = |
2086 | 964 { |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
965 GAIM_PROTO_ZEPHYR, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
966 OPT_PROTO_NO_PASSWORD, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
967 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
968 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
969 zephyr_list_icon, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
970 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
971 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
972 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
973 zephyr_away_states, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
974 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
975 zephyr_buddy_menu, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
976 zephyr_chat_info, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
977 zephyr_login, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
978 zephyr_close, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
979 zephyr_send_im, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
980 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
981 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
982 zephyr_zloc, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
983 zephyr_set_away, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
984 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
985 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
986 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
987 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
988 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
989 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
990 zephyr_add_buddy, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
991 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
992 zephyr_remove_buddy, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
993 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
994 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
995 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
996 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
997 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
998 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
999 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1000 zephyr_join_chat, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1001 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1002 zephyr_chat_leave, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1003 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1004 zephyr_chat_send, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1005 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1006 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1007 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1008 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1009 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1010 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1011 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1012 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1013 NULL, |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1014 zephyr_normalize |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1015 }; |
2086 | 1016 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1017 static GaimPluginInfo info = |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1018 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1019 2, /**< api_version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1020 GAIM_PLUGIN_PROTOCOL, /**< type */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1021 NULL, /**< ui_requirement */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1022 0, /**< flags */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1023 NULL, /**< dependencies */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1024 GAIM_PRIORITY_DEFAULT, /**< priority */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1025 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1026 "prpl-zephyr", /**< id */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1027 "Zephyr", /**< name */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1028 VERSION, /**< version */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1029 /** summary */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1030 N_("Zephyr Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1031 /** description */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1032 N_("Zephyr Protocol Plugin"), |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1033 NULL, /**< author */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1034 WEBSITE, /**< homepage */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1035 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1036 NULL, /**< load */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1037 NULL, /**< unload */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1038 NULL, /**< destroy */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1039 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1040 NULL, /**< ui_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1041 &prpl_info /**< extra_info */ |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1042 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1043 |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1044 static void |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1045 init_plugin(GaimPlugin *plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1046 { |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1047 my_protocol = plugin; |
2086 | 1048 } |
1049 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1050 GAIM_INIT_PLUGIN(zephyr, init_plugin, info); |