Mercurial > pidgin
annotate src/protocols/zephyr/zephyr.c @ 9912:f6a1054e2bdc
[gaim-migrate @ 10804]
" shadow pointed that zephyr_strip_foreign_realm wasn't
being consistently used (searches for foo would fail
when foo@DEFAULTREALM was in the buddy list), and that
this could cause problems.
Also, zephyr_strip_foreign_realm was really badly named
(it should be zephyr_strip_local_realm).
Here's a fix for both those issues, against current cvs." --Arun A Tharuvai
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Mon, 30 Aug 2004 01:52:59 +0000 |
parents | 4f1fcf5efaf9 |
children | e74eb0d11f86 |
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 * |
9896 | 10 * Some code borrowed from kzephyr, by |
11 * Chris Colohan <colohan+@cs.cmu.edu> | |
12 * | |
2086 | 13 * This program is free software; you can redistribute it and/or modify |
14 * it under the terms of the GNU General Public License as published by | |
15 * the Free Software Foundation; either version 2 of the License, or | |
16 * (at your option) any later version. | |
17 * | |
18 * This program is distributed in the hope that it will be useful, | |
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
9896 | 20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2086 | 21 * GNU General Public License for more details. |
22 * | |
23 * You should have received a copy of the GNU General Public License | |
24 * along with this program; if not, write to the Free Software | |
9896 | 25 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
2086 | 26 * |
9896 | 27 |
28 */ | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 /* XXX eww */ |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
30 #include "src/internal.h" |
2086 | 31 |
8212 | 32 #include "accountopt.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
33 #include "debug.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
34 #include "notify.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
35 #include "prpl.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
36 #include "server.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
37 #include "util.h" |
9434 | 38 #include "cmds.h" |
9896 | 39 #include "privacy.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
40 |
9896 | 41 #include "zephyr.h" |
9478 | 42 #include "internal.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
43 |
8386 | 44 #include <strings.h> |
45 | |
8560 | 46 #define ZEPHYR_FALLBACK_CHARSET "ISO-8859-1" |
47 | |
9478 | 48 /* these are deliberately high, since most people don't send multiple "PING"s */ |
49 #define ZEPHYR_TYPING_SEND_TIMEOUT 15 | |
50 #define ZEPHYR_TYPING_RECV_TIMEOUT 10 | |
9896 | 51 #define ZEPHYR_FD_READ 0 |
52 #define ZEPHYR_FD_WRITE 1 | |
9478 | 53 |
2086 | 54 extern Code_t ZGetLocations(ZLocations_t *, int *); |
55 extern Code_t ZSetLocation(char *); | |
56 extern Code_t ZUnsetLocation(); | |
9478 | 57 extern Code_t ZGetSubscriptions(ZSubscription_t *, int*); |
2086 | 58 |
59 typedef struct _zframe zframe; | |
60 typedef struct _zephyr_triple zephyr_triple; | |
9610 | 61 typedef struct _zephyr_account zephyr_account; |
9896 | 62 typedef struct _parse_tree parse_tree; |
2086 | 63 |
9896 | 64 typedef enum { |
65 GAIM_ZEPHYR_NONE, /* Non-kerberized ZEPH0.2 */ | |
66 GAIM_ZEPHYR_KRB4, /* ZEPH0.2 w/ KRB4 support */ | |
67 GAIM_ZEPHYR_TZC, /* tzc executable proxy */ | |
68 GAIM_ZEPHYR_INTERGALACTIC_KRB4, /* Kerberized ZEPH0.3 */ | |
69 } zephyr_connection_type; | |
9610 | 70 |
71 struct _zephyr_account { | |
9896 | 72 GaimAccount* account; |
73 char *username; | |
74 char *realm; | |
75 char *encoding; | |
76 char* galaxy; /* not yet useful */ | |
77 char* krbtkfile; /* not yet useful */ | |
78 guint32 nottimer; | |
79 guint32 loctimer; | |
80 GList *pending_zloc_names; | |
81 GSList *subscrips; | |
82 int last_id; | |
83 unsigned short port; | |
84 char ourhost[HOST_NAME_MAX + 1]; | |
85 char ourhostcanon[HOST_NAME_MAX + 1]; | |
86 zephyr_connection_type connection_type; | |
87 int totzc[2]; | |
88 int fromtzc[2]; | |
89 char *exposure; | |
90 pid_t tzc_pid; | |
9610 | 91 }; |
9478 | 92 |
9896 | 93 #define MAXCHILDREN 20 |
94 | |
95 struct _parse_tree { | |
96 gchar* contents; | |
97 parse_tree *children[MAXCHILDREN]; | |
98 int num_children; | |
99 }; | |
100 | |
101 parse_tree null_parse_tree = { | |
102 "", | |
103 {}, | |
104 0, | |
105 }; | |
106 | |
107 #define use_none(zephyr) ((zephyr->connection_type == GAIM_ZEPHYR_NONE)?1:0) | |
108 #define use_krb4(zephyr) ((zephyr->connection_type == GAIM_ZEPHYR_KRB4)?1:0) | |
109 #define use_tzc(zephyr) ((zephyr->connection_type == GAIM_ZEPHYR_TZC)?1:0) | |
110 | |
111 #define use_zeph02(zephyr) ( (zephyr->connection_type == GAIM_ZEPHYR_NONE)?1: ((zephyr->connection_type == GAIM_ZEPHYR_KRB4)?1:0)) | |
112 | |
2086 | 113 /* struct I need for zephyr_to_html */ |
114 struct _zframe { | |
115 /* true for everything but @color, since inside the parens of that one is | |
8644 | 116 * the color. */ |
2086 | 117 gboolean has_closer; |
118 /* </i>, </font>, </b>, etc. */ | |
119 char *closing; | |
120 /* text including the opening html thingie. */ | |
121 GString *text; | |
122 struct _zframe *enclosing; | |
123 }; | |
124 | |
125 struct _zephyr_triple { | |
126 char *class; | |
127 char *instance; | |
128 char *recipient; | |
129 char *name; | |
130 gboolean open; | |
131 int id; | |
132 }; | |
133 | |
134 #define z_call(func) if (func != ZERR_NONE)\ | |
135 return; | |
136 #define z_call_r(func) if (func != ZERR_NONE)\ | |
137 return TRUE; | |
9896 | 138 |
2086 | 139 #define z_call_s(func, err) if (func != ZERR_NONE) {\ |
9610 | 140 gaim_connection_error(gc, err);\ |
2086 | 141 return;\ |
142 } | |
143 | |
9896 | 144 |
145 Code_t zephyr_subscribe_to(zephyr_account* zephyr, char* class, char *instance, char *recipient, char* galaxy) { | |
9328 | 146 |
9896 | 147 if (use_tzc(zephyr)) { |
148 /* ((tzcfodder . subscribe) ("class" "instance" "recipient")) */ | |
149 gchar *zsubstr = g_strdup_printf("((tzcfodder . subscribe) (\"%s\" \"%s\" \"%s\"))\n",class,instance,recipient); | |
150 write(zephyr->totzc[ZEPHYR_FD_WRITE],zsubstr,strlen(zsubstr)); | |
151 g_free(zsubstr); | |
152 return ZERR_NONE; | |
153 } | |
154 else { | |
155 if (use_zeph02(zephyr)) { | |
156 ZSubscription_t sub; | |
157 sub.zsub_class = class; | |
158 sub.zsub_classinst = instance; | |
159 sub.zsub_recipient = recipient; | |
160 return ZSubscribeTo(&sub,1,0); | |
161 } else { | |
162 /* This should not happen */ | |
163 return -1; | |
164 } | |
165 } | |
166 return -1; | |
167 } | |
168 | |
169 char *local_zephyr_normalize(zephyr_account* zephyr,const char *); | |
170 static const char *zephyr_normalize(const GaimAccount *, const char *); | |
171 static void zephyr_chat_set_topic(GaimConnection * gc, int id, const char *topic); | |
172 char* zephyr_tzc_deescape_str(const char *message); | |
173 | |
9912 | 174 char *zephyr_strip_local_realm(zephyr_account* zephyr,const char* user){ |
9896 | 175 /* |
176 Takes in a username of the form username or username@realm | |
177 and returns: | |
178 username, if there is no realm, or the realm is the local realm | |
179 or: | |
180 username@realm if there is a realm and it is foreign | |
181 */ | |
9328 | 182 char *tmp = g_strdup(user); |
183 char *at = strchr(tmp,'@'); | |
9896 | 184 if (at && !g_ascii_strcasecmp(at+1,zephyr->realm)) { |
9328 | 185 /* We're passed in a username of the form user@users-realm */ |
186 char* tmp2; | |
187 *at = '\0'; | |
188 tmp2 = g_strdup(tmp); | |
189 g_free(tmp); | |
190 return tmp2; | |
191 } | |
192 else { | |
193 /* We're passed in a username of the form user or user@foreign-realm */ | |
194 return tmp; | |
195 } | |
196 } | |
2086 | 197 |
198 /* this is so bad, and if Zephyr weren't so fucked up to begin with I | |
199 * wouldn't do this. but it is so i will. */ | |
9610 | 200 |
9328 | 201 /* just for debugging */ |
2086 | 202 static void handle_unknown(ZNotice_t notice) |
203 { | |
9328 | 204 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_packet: %s\n", notice.z_packet); |
205 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_version: %s\n", notice.z_version); | |
206 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_kind: %d\n", (int)(notice.z_kind)); | |
207 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class: %s\n", notice.z_class); | |
208 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class_inst: %s\n", notice.z_class_inst); | |
209 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_opcode: %s\n", notice.z_opcode); | |
210 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_sender: %s\n", notice.z_sender); | |
211 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_recipient: %s\n", notice.z_recipient); | |
212 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message: %s\n", notice.z_message); | |
213 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message_len: %d\n", notice.z_message_len); | |
2086 | 214 } |
9328 | 215 |
2086 | 216 |
9610 | 217 static zephyr_triple *new_triple(zephyr_account *zephyr,const char *c, const char *i, const char *r) |
2086 | 218 { |
219 zephyr_triple *zt; | |
8644 | 220 |
2086 | 221 zt = g_new0(zephyr_triple, 1); |
222 zt->class = g_strdup(c); | |
223 zt->instance = g_strdup(i); | |
224 zt->recipient = g_strdup(r); | |
9610 | 225 zt->name = g_strdup_printf("%s,%s,%s", c, i?i:"", r?r:""); |
226 zt->id = ++(zephyr->last_id); | |
2086 | 227 zt->open = FALSE; |
228 return zt; | |
229 } | |
230 | |
8644 | 231 static void free_triple(zephyr_triple * zt) |
2086 | 232 { |
233 g_free(zt->class); | |
234 g_free(zt->instance); | |
235 g_free(zt->recipient); | |
236 g_free(zt->name); | |
237 g_free(zt); | |
238 } | |
239 | |
9328 | 240 /* returns true if zt1 is a subset of zt2. This function is used to |
241 determine whether a zephyr sent to zt1 should be placed in the chat | |
242 with triple zt2 | |
243 | |
244 zt1 is a subset of zt2 | |
245 iff. the classnames are identical ignoring case | |
246 AND. the instance names are identical (ignoring case), or zt2->instance is *. | |
247 AND. the recipient names are identical | |
248 */ | |
249 | |
8644 | 250 static gboolean triple_subset(zephyr_triple * zt1, zephyr_triple * zt2) |
2086 | 251 { |
9896 | 252 |
253 if (!zt2) | |
254 gaim_debug_error("zephyr","zt2 doesn't exist\n"); | |
255 if (!zt1) | |
256 gaim_debug_error("zephyr","zt1 doesn't exist\n"); | |
257 if (!(zt1->class)) | |
258 gaim_debug_error("zephyr","zt1c doesn't exist\n"); | |
259 if (!(zt1->instance)) | |
260 gaim_debug_error("zephyr","zt1i doesn't exist\n"); | |
261 if (!(zt1->recipient)) | |
262 gaim_debug_error("zephyr","zt1r doesn't exist\n"); | |
263 if (!(zt2->class)) | |
264 gaim_debug_error("zephyr","zt2c doesn't exist\n"); | |
265 if (!(zt2->recipient)) | |
266 gaim_debug_error("zephyr","zt2r doesn't exist\n"); | |
267 if (!(zt2->instance)) | |
268 gaim_debug_error("zephyr","zt2i doesn't exist\n"); | |
269 | |
270 | |
9328 | 271 if (g_ascii_strcasecmp(zt2->class, zt1->class)) { |
2086 | 272 return FALSE; |
273 } | |
8644 | 274 if (g_ascii_strcasecmp(zt2->instance, zt1->instance) && g_ascii_strcasecmp(zt2->instance, "*")) { |
2086 | 275 return FALSE; |
276 } | |
9328 | 277 if (g_ascii_strcasecmp(zt2->recipient, zt1->recipient)) { |
2086 | 278 return FALSE; |
279 } | |
9896 | 280 gaim_debug_info("zephyr","<%s,%s,%s> is in <%s,%s,%s>\n",zt1->class,zt1->instance,zt1->recipient,zt2->class,zt2->instance,zt2->recipient); |
2086 | 281 return TRUE; |
282 } | |
283 | |
9610 | 284 static zephyr_triple *find_sub_by_triple(zephyr_account *zephyr,zephyr_triple * zt) |
2086 | 285 { |
286 zephyr_triple *curr_t; | |
9610 | 287 GSList *curr = zephyr->subscrips; |
8644 | 288 |
2086 | 289 while (curr) { |
290 curr_t = curr->data; | |
291 if (triple_subset(zt, curr_t)) | |
292 return curr_t; | |
293 curr = curr->next; | |
294 } | |
295 return NULL; | |
296 } | |
297 | |
9610 | 298 static zephyr_triple *find_sub_by_id(zephyr_account *zephyr,int id) |
2086 | 299 { |
300 zephyr_triple *zt; | |
9610 | 301 GSList *curr = zephyr->subscrips; |
8644 | 302 |
2086 | 303 while (curr) { |
304 zt = curr->data; | |
305 if (zt->id == id) | |
306 return zt; | |
307 curr = curr->next; | |
308 } | |
309 return NULL; | |
310 } | |
311 | |
9328 | 312 /* |
9434 | 313 Converts strings to utf-8 if necessary using user specified encoding |
9328 | 314 */ |
315 | |
9610 | 316 static gchar *zephyr_recv_convert(GaimConnection *gc,gchar *string, int len) |
8560 | 317 { |
318 gchar *utf8; | |
319 GError *err = NULL; | |
9896 | 320 zephyr_account *zephyr = gc->proto_data; |
8644 | 321 if (g_utf8_validate(string, len, NULL)) { |
8568 | 322 return g_strdup(string); |
323 } else { | |
9896 | 324 utf8 = g_convert(string, len, "UTF-8", zephyr->encoding, NULL, NULL, &err); |
8568 | 325 if (err) { |
326 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "recv conversion error: %s\n", err->message); | |
9896 | 327 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); |
8954 | 328 g_error_free(err); |
8568 | 329 } |
330 | |
331 return utf8; | |
332 } | |
8560 | 333 } |
334 | |
2086 | 335 /* utility macros that are useful for zephyr_to_html */ |
336 | |
337 #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) | |
338 #define IS_CLOSER(c) ((c == '}') || (c == ']') || (c == ')') || (c == '>')) | |
339 | |
8451 | 340 /* This parses HTML formatting (put out by one of the gtkimhtml widgets |
341 And converts it to zephyr formatting. | |
342 It currently deals properly with <b>, <br>, <i>, <font face=...>, <font color=...>, | |
343 It ignores <font back=...> | |
344 It does | |
345 <font size = "1 or 2" -> @small | |
346 3 or 4 @medium() | |
347 5,6, or 7 @large() | |
348 <a href is dealt with by ignoring the description and outputting the link | |
349 */ | |
350 | |
351 static char *html_to_zephyr(const char *message) | |
352 { | |
8644 | 353 int len, cnt, retcount; |
354 char *ret; | |
355 | |
356 len = strlen(message); | |
9478 | 357 if (!len) |
358 return g_strdup(""); | |
359 | |
8644 | 360 ret = g_new0(char, len * 3); |
361 | |
362 bzero(ret, len * 3); | |
363 retcount = 0; | |
364 cnt = 0; | |
9896 | 365 gaim_debug_info("zephyr","html received %s\n",message); |
8644 | 366 while (cnt <= len) { |
367 if (message[cnt] == '<') { | |
368 if (!g_ascii_strncasecmp(message + cnt + 1, "i>", 2)) { | |
369 strncpy(ret + retcount, "@i(", 3); | |
370 cnt += 3; | |
371 retcount += 3; | |
372 } else if (!g_ascii_strncasecmp(message + cnt + 1, "b>", 2)) { | |
373 strncpy(ret + retcount, "@b(", 3); | |
374 cnt += 3; | |
375 retcount += 3; | |
376 } else if (!g_ascii_strncasecmp(message + cnt + 1, "br>", 3)) { | |
377 strncpy(ret + retcount, "\n", 1); | |
378 cnt += 4; | |
379 retcount += 1; | |
9896 | 380 } else if (!g_ascii_strncasecmp(message + cnt + 1, "a href=\"mailto:", 15)) { |
381 cnt += 16; | |
382 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
383 ret[retcount] = message[cnt]; | |
384 retcount++; | |
385 cnt++; | |
386 } | |
387 cnt += 2; | |
388 /* ignore descriptive string */ | |
389 while (g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) { | |
390 cnt++; | |
391 } | |
392 cnt += 4; | |
8644 | 393 } else if (!g_ascii_strncasecmp(message + cnt + 1, "a href=\"", 8)) { |
394 cnt += 9; | |
395 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
396 ret[retcount] = message[cnt]; | |
397 retcount++; | |
398 cnt++; | |
399 } | |
400 cnt += 2; | |
401 /* ignore descriptive string */ | |
402 while (g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) { | |
403 cnt++; | |
404 } | |
405 cnt += 4; | |
406 } else if (!g_ascii_strncasecmp(message + cnt + 1, "font", 4)) { | |
407 cnt += 5; | |
408 while (!g_ascii_strncasecmp(message + cnt, " ", 1)) | |
409 cnt++; | |
410 if (!g_ascii_strncasecmp(message + cnt, "color=\"", 7)) { | |
411 cnt += 7; | |
412 strncpy(ret + retcount, "@color(", 7); | |
413 retcount += 7; | |
414 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
415 ret[retcount] = message[cnt]; | |
416 retcount++; | |
417 cnt++; | |
418 } | |
419 ret[retcount] = ')'; | |
420 retcount++; | |
421 cnt += 2; | |
422 } else if (!g_ascii_strncasecmp(message + cnt, "face=\"", 6)) { | |
423 cnt += 6; | |
424 strncpy(ret + retcount, "@font(", 6); | |
425 retcount += 6; | |
426 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
427 ret[retcount] = message[cnt]; | |
428 retcount++; | |
429 cnt++; | |
430 } | |
431 ret[retcount] = ')'; | |
432 retcount++; | |
433 cnt += 2; | |
434 } else if (!g_ascii_strncasecmp(message + cnt, "size=\"", 6)) { | |
435 cnt += 6; | |
436 if ((message[cnt] == '1') || (message[cnt] == '2')) { | |
437 strncpy(ret + retcount, "@small(", 7); | |
438 retcount += 7; | |
439 } else if ((message[cnt] == '3') | |
9896 | 440 || (message[cnt] == '4')) { |
8644 | 441 strncpy(ret + retcount, "@medium(", 8); |
442 retcount += 8; | |
443 } else if ((message[cnt] == '5') | |
9896 | 444 || (message[cnt] == '6') |
445 || (message[cnt] == '7')) { | |
8644 | 446 strncpy(ret + retcount, "@large(", 7); |
447 retcount += 7; | |
448 } | |
449 cnt += 3; | |
450 } else { | |
451 /* Drop all unrecognized/misparsed font tags */ | |
452 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
453 cnt++; | |
454 } | |
455 cnt += 2; | |
456 } | |
457 } else if (!g_ascii_strncasecmp(message + cnt + 1, "/i>", 3) | |
9896 | 458 || !g_ascii_strncasecmp(message + cnt + 1, "/b>", 3)) { |
8644 | 459 cnt += 4; |
460 ret[retcount] = ')'; | |
461 retcount++; | |
462 } else if (!g_ascii_strncasecmp(message + cnt + 1, "/font>", 6)) { | |
463 cnt += 7; | |
464 strncpy(ret + retcount, "@font(fixed)", 12); | |
465 retcount += 12; | |
466 } else { | |
467 /* Catch all for all unrecognized/misparsed <foo> tage */ | |
468 while (g_ascii_strncasecmp(message + cnt, ">", 1) != 0) { | |
469 ret[retcount] = message[cnt]; | |
470 retcount++; | |
471 cnt++; | |
472 } | |
473 } | |
474 } else { | |
475 /* Duh */ | |
476 ret[retcount] = message[cnt]; | |
477 retcount++; | |
478 cnt++; | |
479 } | |
480 } | |
9896 | 481 gaim_debug_info("zephyr","zephyr outputted %s\n",ret); |
8644 | 482 return ret; |
8451 | 483 } |
484 | |
2086 | 485 /* this parses zephyr formatting and converts it to html. For example, if |
486 * you pass in "@{@color(blue)@i(hello)}" you should get out | |
487 * "<font color=blue><i>hello</i></font>". */ | |
488 static char *zephyr_to_html(char *message) | |
489 { | |
490 int len, cnt; | |
491 zframe *frames, *curr; | |
492 char *ret; | |
493 | |
494 frames = g_new(zframe, 1); | |
495 frames->text = g_string_new(""); | |
496 frames->enclosing = NULL; | |
497 frames->closing = ""; | |
498 frames->has_closer = FALSE; | |
499 | |
500 len = strlen(message); | |
501 cnt = 0; | |
502 while (cnt <= len) { | |
503 if (message[cnt] == '@') { | |
504 zframe *new_f; | |
505 char *buf; | |
506 int end; | |
8644 | 507 |
508 for (end = 1; (cnt + end) <= len && !IS_OPENER(message[cnt + end]) | |
9896 | 509 && !IS_CLOSER(message[cnt + end]); end++); |
2086 | 510 buf = g_new0(char, end); |
8644 | 511 |
2086 | 512 if (end) { |
8644 | 513 g_snprintf(buf, end, "%s", message + cnt + 1); |
2086 | 514 } |
8644 | 515 if (!g_ascii_strcasecmp(buf, "italic") || !g_ascii_strcasecmp(buf, "i")) { |
2086 | 516 new_f = g_new(zframe, 1); |
517 new_f->enclosing = frames; | |
518 new_f->text = g_string_new("<i>"); | |
519 new_f->closing = "</i>"; | |
520 new_f->has_closer = TRUE; | |
521 frames = new_f; | |
8644 | 522 cnt += end + 1; /* cnt points to char after opener */ |
523 } else if (!g_ascii_strcasecmp(buf, "small")) { | |
524 new_f = g_new(zframe, 1); | |
525 new_f->enclosing = frames; | |
526 new_f->text = g_string_new("<font size=\"1\">"); | |
527 new_f->closing = "</font>"; | |
528 frames = new_f; | |
529 cnt += end + 1; | |
530 } else if (!g_ascii_strcasecmp(buf, "medium")) { | |
531 new_f = g_new(zframe, 1); | |
532 new_f->enclosing = frames; | |
533 new_f->text = g_string_new("<font size=\"3\">"); | |
534 new_f->closing = "</font>"; | |
535 frames = new_f; | |
536 cnt += end + 1; | |
537 } else if (!g_ascii_strcasecmp(buf, "large")) { | |
538 new_f = g_new(zframe, 1); | |
539 new_f->enclosing = frames; | |
540 new_f->text = g_string_new("<font size=\"7\">"); | |
541 new_f->closing = "</font>"; | |
542 frames = new_f; | |
543 cnt += end + 1; | |
544 } else if (!g_ascii_strcasecmp(buf, "bold") | |
9896 | 545 || !g_ascii_strcasecmp(buf, "b")) { |
2086 | 546 new_f = g_new(zframe, 1); |
547 new_f->enclosing = frames; | |
548 new_f->text = g_string_new("<b>"); | |
549 new_f->closing = "</b>"; | |
550 new_f->has_closer = TRUE; | |
551 frames = new_f; | |
8644 | 552 cnt += end + 1; |
553 } else if (!g_ascii_strcasecmp(buf, "font")) { | |
554 cnt += end + 1; | |
8451 | 555 new_f = g_new(zframe, 1); |
556 new_f->enclosing = frames; | |
557 new_f->text = g_string_new("<font face="); | |
558 for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
559 g_string_append_c(new_f->text, message[cnt]); | |
560 } | |
8644 | 561 cnt++; /* point to char after closer */ |
8451 | 562 g_string_append_c(new_f->text, '>'); |
563 new_f->closing = "</font>"; | |
564 new_f->has_closer = FALSE; | |
565 frames = new_f; | |
8568 | 566 } else if (!g_ascii_strcasecmp(buf, "color")) { |
8644 | 567 cnt += end + 1; |
2086 | 568 new_f = g_new(zframe, 1); |
569 new_f->enclosing = frames; | |
570 new_f->text = g_string_new("<font color="); | |
571 for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
572 g_string_append_c(new_f->text, message[cnt]); | |
573 } | |
8644 | 574 cnt++; /* point to char after closer */ |
2086 | 575 g_string_append_c(new_f->text, '>'); |
576 new_f->closing = "</font>"; | |
577 new_f->has_closer = FALSE; | |
578 frames = new_f; | |
4793 | 579 } else if (!g_ascii_strcasecmp(buf, "")) { |
2086 | 580 new_f = g_new(zframe, 1); |
581 new_f->enclosing = frames; | |
582 new_f->text = g_string_new(""); | |
583 new_f->closing = ""; | |
584 new_f->has_closer = TRUE; | |
585 frames = new_f; | |
8644 | 586 cnt += end + 1; /* cnt points to char after opener */ |
2086 | 587 } else { |
8644 | 588 if ((cnt + end) > len) { |
2086 | 589 g_string_append_c(frames->text, '@'); |
590 cnt++; | |
8644 | 591 } else if (IS_CLOSER(message[cnt + end])) { |
592 /* We have @chars..closer . This is | |
593 merely a sequence of chars that isn't a formatting tag | |
9896 | 594 */ |
8644 | 595 int tmp = cnt; |
596 | |
597 while (tmp <= cnt + end) { | |
598 g_string_append_c(frames->text, message[tmp]); | |
599 tmp++; | |
600 } | |
601 cnt += end + 1; | |
602 } else { | |
2086 | 603 /* unrecognized thingie. act like it's not there, but we |
604 * still need to take care of the corresponding closer, | |
605 * make a frame that does nothing. */ | |
606 new_f = g_new(zframe, 1); | |
607 new_f->enclosing = frames; | |
608 new_f->text = g_string_new(""); | |
609 new_f->closing = ""; | |
610 new_f->has_closer = TRUE; | |
611 frames = new_f; | |
8644 | 612 cnt += end + 1; /* cnt points to char after opener */ |
2086 | 613 } |
614 } | |
615 } else if (IS_CLOSER(message[cnt])) { | |
616 zframe *popped; | |
617 gboolean last_had_closer; | |
8644 | 618 |
2086 | 619 if (frames->enclosing) { |
620 do { | |
621 popped = frames; | |
622 frames = frames->enclosing; | |
623 g_string_append(frames->text, popped->text->str); | |
624 g_string_append(frames->text, popped->closing); | |
625 g_string_free(popped->text, TRUE); | |
626 last_had_closer = popped->has_closer; | |
627 g_free(popped); | |
628 } while (frames && frames->enclosing && !last_had_closer); | |
629 } else { | |
630 g_string_append_c(frames->text, message[cnt]); | |
631 } | |
632 cnt++; | |
633 } else if (message[cnt] == '\n') { | |
634 g_string_append(frames->text, "<br>"); | |
635 cnt++; | |
636 } else { | |
637 g_string_append_c(frames->text, message[cnt++]); | |
638 } | |
639 } | |
640 /* go through all the stuff that they didn't close */ | |
641 while (frames->enclosing) { | |
642 curr = frames; | |
643 g_string_append(frames->enclosing->text, frames->text->str); | |
644 g_string_append(frames->enclosing->text, frames->closing); | |
645 g_string_free(frames->text, TRUE); | |
646 frames = frames->enclosing; | |
647 g_free(curr); | |
648 } | |
649 ret = frames->text->str; | |
650 g_string_free(frames->text, FALSE); | |
651 g_free(frames); | |
652 return ret; | |
653 } | |
654 | |
9610 | 655 static gboolean pending_zloc(zephyr_account *zephyr,char *who) |
2086 | 656 { |
657 GList *curr; | |
8644 | 658 |
9610 | 659 for (curr = zephyr->pending_zloc_names; curr != NULL; curr = curr->next) { |
9896 | 660 char* normalized_who = local_zephyr_normalize(zephyr,who); |
9328 | 661 if (!g_ascii_strcasecmp(normalized_who, (char *)curr->data)) { |
8644 | 662 g_free((char *)curr->data); |
9610 | 663 zephyr->pending_zloc_names = g_list_remove(zephyr->pending_zloc_names, curr->data); |
2086 | 664 return TRUE; |
665 } | |
666 } | |
667 return FALSE; | |
668 } | |
669 | |
9328 | 670 /* Called when the server notifies us a message couldn't get sent */ |
671 | |
9610 | 672 static void message_failed(GaimConnection *gc, ZNotice_t notice, struct sockaddr_in from) |
8559 | 673 { |
8644 | 674 if (g_ascii_strcasecmp(notice.z_class, "message")) { |
9328 | 675 gchar* chat_failed = g_strdup_printf(_("Unable send to chat %s,%s,%s"),notice.z_class,notice.z_class_inst,notice.z_recipient); |
9610 | 676 gaim_notify_error(gc,"",chat_failed,NULL); |
9328 | 677 g_free(chat_failed); |
8644 | 678 } else { |
9610 | 679 gaim_notify_error(gc, notice.z_recipient, _("User is offline"), NULL); |
8644 | 680 } |
8559 | 681 } |
682 | |
9610 | 683 static void handle_message(GaimConnection *gc,ZNotice_t notice, struct sockaddr_in from) |
2086 | 684 { |
9896 | 685 zephyr_account* zephyr = gc->proto_data; |
686 | |
4793 | 687 if (!g_ascii_strcasecmp(notice.z_class, LOGIN_CLASS)) { |
3277 | 688 /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */ |
4793 | 689 } else if (!g_ascii_strcasecmp(notice.z_class, LOCATE_CLASS)) { |
690 if (!g_ascii_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
2086 | 691 int nlocs; |
692 char *user; | |
6695 | 693 GaimBuddy *b; |
9478 | 694 /* XXX add real error reporting */ |
2086 | 695 if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) |
696 return; | |
8435 | 697 |
9610 | 698 if ((b = gaim_find_buddy(gc->account, user)) == NULL) { |
9912 | 699 char* stripped_user = zephyr_strip_local_realm(zephyr,user); |
700 b = gaim_find_buddy(gc->account,stripped_user); | |
701 g_free(stripped_user); | |
8644 | 702 } |
9896 | 703 if ((b && pending_zloc(zephyr,b->name)) || pending_zloc(zephyr,user)) { |
2086 | 704 ZLocations_t locs; |
705 int one = 1; | |
706 GString *str = g_string_new(""); | |
8644 | 707 |
708 g_string_append_printf(str, _("<b>User:</b> %s<br>"), b ? b->name : user); | |
8435 | 709 if (b && b->alias) |
5132 | 710 g_string_append_printf(str, _("<b>Alias:</b> %s<br>"), b->alias); |
2086 | 711 if (!nlocs) { |
5132 | 712 g_string_append_printf(str, _("<br>Hidden or not logged-in")); |
2086 | 713 } |
714 for (; nlocs > 0; nlocs--) { | |
9478 | 715 /* XXX add real error reporting */ |
2086 | 716 ZGetLocations(&locs, &one); |
8644 | 717 g_string_append_printf(str, _("<br>At %s since %s"), locs.host, locs.time); |
2086 | 718 } |
9797 | 719 gaim_notify_userinfo(gc, b ? b->name : user, NULL, _("Buddy Information"), NULL, |
9896 | 720 str->str, NULL, NULL); |
2086 | 721 g_string_free(str, TRUE); |
722 } else | |
9610 | 723 serv_got_update(gc, b->name, nlocs, 0, 0, 0, 0); |
2086 | 724 |
9434 | 725 g_free(user); |
2086 | 726 } |
727 } else { | |
8560 | 728 char *buf, *buf2, *buf3; |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
729 char *send_inst; |
8644 | 730 GaimConversation *gconv1; |
731 GaimConvChat *gcc; | |
2086 | 732 char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
9478 | 733 int len; |
9896 | 734 char *sendertmp = g_strdup_printf("%s", zephyr->username); |
9478 | 735 int signature_length = strlen(notice.z_message); |
736 int message_has_no_body = 0; | |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
737 GaimConvImFlags flags = 0; |
9896 | 738 gchar *tmpescape; |
8560 | 739 |
9478 | 740 /* Need to deal with 0 length messages to handle typing notification (OPCODE) ping messages */ |
741 /* One field zephyrs would have caused gaim to crash */ | |
742 if ( (notice.z_message_len == 0) || (signature_length >= notice.z_message_len - 1)) { | |
743 message_has_no_body = 1; | |
744 len = 0; | |
745 gaim_debug_info("zephyr","message_size %d %d %d\n",len,notice.z_message_len,signature_length); | |
746 buf3 = g_strdup(""); | |
747 | |
748 } else { | |
749 len = notice.z_message_len - ( signature_length +1); | |
750 gaim_debug_info("zephyr","message_size %d %d %d\n",len,notice.z_message_len,signature_length); | |
8644 | 751 buf = g_malloc(len + 1); |
752 g_snprintf(buf, len + 1, "%s", ptr); | |
753 g_strchomp(buf); | |
754 tmpescape = gaim_escape_html(buf); | |
9478 | 755 g_free(buf); |
8644 | 756 buf2 = zephyr_to_html(tmpescape); |
9610 | 757 buf3 = zephyr_recv_convert(gc,buf2, strlen(buf2)); |
8644 | 758 g_free(buf2); |
759 g_free(tmpescape); | |
9478 | 760 } |
8644 | 761 |
9896 | 762 if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL") |
763 && !g_ascii_strcasecmp(notice.z_recipient,zephyr->username)) { | |
764 gchar* stripped_sender; | |
765 if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) | |
766 flags |= GAIM_CONV_IM_AUTO_RESP; | |
9912 | 767 stripped_sender = zephyr_strip_local_realm(zephyr,notice.z_sender); |
9896 | 768 |
9478 | 769 if (!g_ascii_strcasecmp(notice.z_opcode,"PING")) |
9610 | 770 serv_got_typing(gc,stripped_sender,ZEPHYR_TYPING_RECV_TIMEOUT, GAIM_TYPING); |
9896 | 771 else { |
772 /* Based on the values of | |
773 account->permit_deny, | |
774 account->permit, account>deny , and | |
775 the buddylist */ | |
776 | |
777 GSList* l; | |
778 gboolean in_deny; | |
9478 | 779 |
9896 | 780 switch (gc->account->perm_deny) { |
781 case GAIM_PRIVACY_ALLOW_ALL: | |
782 in_deny = 0; break; | |
783 case GAIM_PRIVACY_DENY_ALL: | |
784 in_deny = 1; break; | |
785 case GAIM_PRIVACY_ALLOW_USERS: /* See if stripped_sender is in gc->account->permit and allow appropriately */ | |
786 in_deny = 1; | |
787 for(l=gc->account->permit;l!=NULL;l=l->next) { | |
788 if (!gaim_utf8_strcasecmp(stripped_sender, gaim_normalize(gc->account, (char *)l->data))) { | |
789 in_deny=0; | |
790 break; | |
791 } | |
792 } | |
793 break; | |
794 case GAIM_PRIVACY_DENY_USERS: /* See if stripped_sender is in gc->account->deny and deny if so */ | |
795 in_deny = 0; | |
796 for(l=gc->account->deny;l!=NULL;l=l->next) { | |
797 if (!gaim_utf8_strcasecmp(stripped_sender, gaim_normalize(gc->account, (char *)l->data))) { | |
798 in_deny=1; | |
799 break; | |
800 } | |
801 } | |
802 break; | |
803 case GAIM_PRIVACY_ALLOW_BUDDYLIST: | |
804 in_deny = 1; | |
805 if (gaim_find_buddy(gc->account,stripped_sender)!=NULL) { | |
806 in_deny = 0; | |
807 } | |
808 break; | |
809 default: | |
810 in_deny=0; break; | |
811 } | |
812 | |
813 if (!in_deny) { | |
814 serv_got_im(gc, stripped_sender, buf3, flags, time(NULL)); | |
815 } | |
816 } | |
817 | |
818 g_free(stripped_sender); | |
819 } else { | |
820 zephyr_triple *zt1, *zt2; | |
821 gchar *send_inst_utf8; | |
822 zephyr_account *zephyr = gc->proto_data; | |
823 zt1 = new_triple(gc->proto_data,notice.z_class, notice.z_class_inst, notice.z_recipient); | |
824 zt2 = find_sub_by_triple(gc->proto_data,zt1); | |
825 if (!zt2) { | |
826 /* This is a server supplied subscription */ | |
827 zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,zt1->class,zt1->instance,zt1->recipient)); | |
9610 | 828 zt2 = find_sub_by_triple(gc->proto_data,zt1); |
9896 | 829 } |
830 | |
831 if (!zt2->open) { | |
832 zt2->open = TRUE; | |
833 serv_got_joined_chat(gc, zt2->id, zt2->name); | |
834 zephyr_chat_set_topic(gc,zt2->id,notice.z_class_inst); | |
835 } | |
836 g_free(sendertmp); /* fix memory leak? */ | |
837 /* If the person is in the default Realm, then strip the | |
838 Realm from the sender field */ | |
9912 | 839 sendertmp = zephyr_strip_local_realm(zephyr,notice.z_sender); |
9896 | 840 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); |
841 send_inst_utf8 = zephyr_recv_convert(gc,send_inst, strlen(send_inst)); | |
842 if (!send_inst_utf8) { | |
843 gaim_debug(GAIM_DEBUG_ERROR, "zephyr","send_inst %s became null\n", send_inst); | |
844 send_inst_utf8 = "malformed instance"; | |
2086 | 845 } |
9912 | 846 |
9896 | 847 serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL)); |
848 g_free(send_inst); | |
849 gconv1 = gaim_find_conversation_with_account(zt2->name, gc->account); | |
850 gcc = gaim_conversation_get_chat_data(gconv1); | |
9912 | 851 |
9896 | 852 if (!gaim_conv_chat_find_user(gcc, sendertmp)) { |
853 /* force interpretation in network byte order */ | |
854 unsigned char *addrs = (unsigned char *)&(notice.z_sender_addr.s_addr); | |
855 gchar* ipaddr = g_strdup_printf("%hhd.%hhd.%hhd.%hhd", (unsigned char)addrs[0], | |
856 (unsigned char)addrs[1], (unsigned char)addrs[2], | |
857 (unsigned char) addrs[3]); | |
858 | |
859 gaim_conv_chat_add_user(gcc, sendertmp, ipaddr, GAIM_CBFLAGS_NONE, TRUE); | |
860 g_free(ipaddr); /* fix memory leak? */ | |
861 | |
862 } | |
863 g_free(sendertmp); | |
864 g_free(send_inst_utf8); | |
865 | |
866 free_triple(zt1); | |
867 } | |
868 g_free(buf3); | |
9478 | 869 |
2086 | 870 } |
871 } | |
9896 | 872 int free_parse_tree(parse_tree* tree) { |
873 if (!tree) { | |
874 return 0; | |
875 } | |
876 else { | |
877 int i; | |
878 if (tree->children) { | |
879 for(i=0;i<tree->num_children;i++){ | |
880 if (tree->children[i]) { | |
881 free_parse_tree(tree->children[i]); | |
882 g_free(tree->children[i]); | |
883 } | |
884 } | |
885 } | |
886 if ((tree != &null_parse_tree) && (tree->contents != NULL)) | |
887 g_free(tree->contents); | |
2086 | 888 |
9896 | 889 } |
890 return 0; | |
891 } | |
892 | |
893 parse_tree *tree_child(parse_tree* tree,int index) { | |
894 if (index < tree->num_children) { | |
895 return tree->children[index]; | |
896 } else { | |
897 return &null_parse_tree; | |
898 } | |
899 } | |
900 | |
901 parse_tree *find_node(parse_tree* ptree,gchar* key) | |
902 { | |
903 gchar* tc = tree_child(ptree,0)->contents; | |
904 | |
905 if (!ptree || ! key) | |
906 return &null_parse_tree; | |
907 | |
908 if (ptree->num_children > 0 && tc && !strcasecmp(tc, key)) { | |
909 return ptree; | |
910 } else { | |
911 parse_tree *result = &null_parse_tree; | |
912 int i; | |
913 for(i = 0; i < ptree->num_children; i++) { | |
914 result = find_node(ptree->children[i],key); | |
915 if(result != &null_parse_tree) { | |
916 break; | |
917 } | |
918 } | |
919 return result; | |
920 } | |
921 } | |
922 | |
923 parse_tree *parse_buffer(gchar* source, gboolean do_parse) { | |
924 | |
925 parse_tree *ptree = g_new0(parse_tree,1); | |
926 ptree->contents = NULL; | |
927 ptree->num_children=0; | |
928 if (do_parse) { | |
929 unsigned int p = 0; | |
930 while(p < strlen(source)) { | |
931 unsigned int end; | |
932 gchar *newstr; | |
933 | |
934 /* Eat white space: */ | |
935 if(g_ascii_isspace(source[p]) || source[p] == '\001') { | |
936 p++; | |
937 continue; | |
938 } | |
939 | |
940 /* Skip comments */ | |
941 if(source[p] == ';') { | |
942 while(source[p] != '\n' && p < strlen(source)) { | |
943 p++; | |
944 } | |
945 continue; | |
946 } | |
947 | |
948 if(source[p] == '(') { | |
949 int nesting = 0; | |
950 gboolean in_quote = FALSE; | |
951 gboolean escape_next = FALSE; | |
952 p++; | |
953 end = p; | |
954 while(!(source[end] == ')' && nesting == 0 && !in_quote) && end < strlen(source)) { | |
955 if(!escape_next) { | |
956 if(source[end] == '\\') { | |
957 escape_next = TRUE; | |
958 } | |
959 if(!in_quote) { | |
960 if(source[end] == '(') { | |
961 nesting++; | |
962 } | |
963 if(source[end] == ')') { | |
964 nesting--; | |
965 } | |
966 } | |
967 if(source[end] == '"') { | |
968 in_quote = !in_quote; | |
969 } | |
970 } else { | |
971 escape_next = FALSE; | |
972 } | |
973 end++; | |
974 } | |
975 do_parse = TRUE; | |
976 | |
977 } else { | |
978 gchar end_char; | |
979 if(source[p] == '"') { | |
980 end_char = '"'; | |
981 p++; | |
982 } else { | |
983 end_char = ' '; | |
984 } | |
985 do_parse = FALSE; | |
986 | |
987 end = p; | |
988 while(source[end] != end_char && end < strlen(source)) { | |
989 if(source[end] == '\\') | |
990 end++; | |
991 end++; | |
992 } | |
993 } | |
994 newstr = g_new0(gchar, end+1-p); | |
995 strncpy(newstr,source+p,end-p); | |
996 if (ptree->num_children < MAXCHILDREN) { | |
997 /* In case we surpass maxchildren, ignore this */ | |
998 ptree->children[ptree->num_children++] = parse_buffer( newstr, do_parse); | |
999 } else { | |
1000 gaim_debug_error("zephyr","too many children in tzc output. skipping\n"); | |
1001 } | |
1002 g_free(newstr); | |
1003 p = end + 1; | |
1004 } | |
1005 return ptree; | |
1006 } else { | |
1007 /* XXX does this have to be strdup'd */ | |
1008 ptree->contents = g_strdup(source); | |
1009 return ptree; | |
1010 } | |
1011 } | |
1012 | |
1013 parse_tree *read_from_tzc(zephyr_account* zephyr){ | |
1014 struct timeval tv; | |
1015 fd_set rfds; | |
1016 int bufsize = 2048; | |
1017 char *buf = (char *)calloc(bufsize, 1); | |
1018 char *bufcur = buf; | |
1019 int selected = 0; | |
1020 parse_tree *incoming_msg; | |
1021 | |
1022 FD_ZERO(&rfds); | |
1023 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); | |
1024 tv.tv_sec = 0; | |
1025 tv.tv_usec = 0; | |
1026 incoming_msg=NULL; | |
1027 | |
1028 while (select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, &tv)) { | |
1029 selected = 1; | |
1030 read(zephyr->fromtzc[ZEPHYR_FD_READ], bufcur, 1); | |
1031 bufcur++; | |
1032 if ((bufcur - buf) > (bufsize - 1)) { | |
1033 if ((buf = realloc(buf, bufsize * 2)) == NULL) { | |
1034 gaim_debug_error("zephyr","Ran out of memory"); | |
1035 exit(-1); | |
1036 } else { | |
1037 bufcur = buf + bufsize; | |
1038 bufsize *= 2; | |
1039 } | |
1040 } | |
1041 } | |
1042 *bufcur = '\0'; | |
1043 | |
1044 if (selected) { | |
1045 incoming_msg = parse_buffer(buf,TRUE); | |
1046 } | |
1047 free(buf); | |
1048 return incoming_msg; | |
1049 } | |
1050 | |
1051 static gint check_notify_tzc(gpointer data) | |
1052 { | |
1053 GaimConnection *gc = (GaimConnection *)data; | |
1054 zephyr_account* zephyr = gc->proto_data; | |
1055 parse_tree *newparsetree = read_from_tzc(zephyr); | |
1056 struct sockaddr_in from; | |
1057 if (newparsetree != NULL) { | |
1058 gchar *spewtype; | |
1059 if ( (spewtype = tree_child(find_node(newparsetree,"tzcspew"),2)->contents) ) { | |
1060 if (!g_ascii_strncasecmp(spewtype,"message",7)) { | |
1061 ZNotice_t notice; | |
1062 parse_tree *msgnode = tree_child(find_node(newparsetree,"message"),2); | |
1063 parse_tree *bodynode = tree_child(msgnode,1); | |
1064 /* char *zsig = g_strdup(" "); */ /* gaim doesn't care about zsigs */ | |
1065 char *msg = zephyr_tzc_deescape_str(bodynode->contents); | |
1066 size_t bufsize = strlen(msg) + 3; | |
1067 char *buf = g_new0(char,bufsize); | |
1068 g_snprintf(buf,1+strlen(msg)+2," %c%s",'\0',msg); | |
1069 bzero((char *)¬ice, sizeof(notice)); | |
1070 notice.z_kind = ACKED; | |
1071 notice.z_port = 0; | |
1072 notice.z_opcode = tree_child(find_node(newparsetree,"opcode"),2)->contents; | |
1073 notice.z_class = zephyr_tzc_deescape_str(tree_child(find_node(newparsetree,"class"),2)->contents); | |
1074 notice.z_class_inst = tree_child(find_node(newparsetree,"instance"),2)->contents; | |
1075 notice.z_recipient = local_zephyr_normalize(zephyr,tree_child(find_node(newparsetree,"recipient"),2)->contents); | |
1076 notice.z_sender = local_zephyr_normalize(zephyr,tree_child(find_node(newparsetree,"sender"),2)->contents); | |
1077 notice.z_default_format = "Class $class, Instance $instance:\n" "To: @bold($recipient) at $time $date\n" "From: @bold($1) <$sender>\n\n$2"; | |
1078 notice.z_message_len = strlen(msg) + 3; | |
1079 notice.z_message = buf; | |
1080 handle_message(gc,notice,from); | |
1081 g_free(msg); | |
1082 /* g_free(zsig); */ | |
1083 g_free(buf); | |
1084 /* free_parse_tree(msgnode); | |
1085 free_parse_tree(bodynode); | |
1086 g_free(msg); | |
1087 g_free(zsig); | |
1088 g_free(buf); | |
1089 */ | |
1090 } | |
1091 else if (!g_ascii_strncasecmp(spewtype,"zlocation",9)) { | |
1092 /* check_loc or zephyr_zloc respectively */ | |
1093 /* XXX fix */ | |
1094 char *user; | |
1095 GaimBuddy *b; | |
1096 int nlocs = 0; | |
9912 | 1097 parse_tree *locations; |
1098 gchar *locval; | |
9896 | 1099 user = tree_child(find_node(newparsetree,"user"),2)->contents; |
1100 | |
1101 if ((b = gaim_find_buddy(gc->account, user)) == NULL) { | |
9912 | 1102 gchar *stripped_user = zephyr_strip_local_realm(zephyr,user); |
1103 b = gaim_find_buddy(gc->account, stripped_user); | |
1104 g_free(stripped_user); | |
9896 | 1105 } |
1106 locations = find_node(newparsetree,"locations"); | |
1107 locval = tree_child(tree_child(tree_child(tree_child(locations,2),0),0),2)->contents; | |
1108 | |
1109 if (!locval || !g_ascii_strcasecmp(locval," ") || (strlen(locval) == 0)) { | |
1110 nlocs = 0; | |
1111 } else { | |
1112 nlocs = 1; | |
1113 } | |
1114 | |
1115 if ((b && pending_zloc(zephyr,b->name)) || pending_zloc(zephyr,user) || pending_zloc(zephyr,local_zephyr_normalize(zephyr,user))){ | |
1116 GString *str = g_string_new(""); | |
1117 | |
1118 g_string_append_printf(str, _("<b>User:</b> %s<br>"), b ? b->name : user); | |
1119 if (b && b->alias) | |
1120 g_string_append_printf(str, _("<b>Alias:</b> %s<br>"), b->alias); | |
1121 | |
1122 if (!nlocs) { | |
1123 g_string_append_printf(str, _("<br>Hidden or not logged-in")); | |
1124 } else { | |
1125 g_string_append_printf(str, _("<br>At %s since %s"), | |
1126 tree_child(tree_child(tree_child(tree_child(locations,2),0),0),2)->contents, | |
1127 tree_child(tree_child(tree_child(tree_child(locations,2),0),2),2)->contents); | |
1128 } | |
1129 | |
1130 gaim_notify_userinfo(gc, b ? b->name : user, NULL, _("Buddy Information"), NULL, | |
1131 str->str, NULL, NULL); | |
1132 g_string_free(str, TRUE); | |
1133 } else { | |
1134 serv_got_update(gc, b->name, nlocs, 0, 0, 0, 0); | |
1135 } | |
1136 } | |
1137 else if (!g_ascii_strncasecmp(spewtype,"subscribed",10)) { | |
1138 } | |
1139 else if (!g_ascii_strncasecmp(spewtype,"start",5)) { | |
1140 } | |
1141 else if (!g_ascii_strncasecmp(spewtype,"error",5)) { | |
1142 /* XXX handle */ | |
1143 } | |
1144 } else { | |
1145 } | |
1146 } else { | |
1147 } | |
1148 | |
1149 free_parse_tree(newparsetree); | |
1150 return TRUE; | |
1151 } | |
1152 | |
1153 static gint check_notify_zeph02(gpointer data) | |
2086 | 1154 { |
9478 | 1155 /* XXX add real error reporting */ |
9896 | 1156 GaimConnection *gc = (GaimConnection*) data; |
2086 | 1157 while (ZPending()) { |
1158 ZNotice_t notice; | |
1159 struct sockaddr_in from; | |
9478 | 1160 /* XXX add real error reporting */ |
8644 | 1161 |
2086 | 1162 z_call_r(ZReceiveNotice(¬ice, &from)); |
1163 | |
1164 switch (notice.z_kind) { | |
1165 case UNSAFE: | |
1166 case UNACKED: | |
1167 case ACKED: | |
9610 | 1168 handle_message(gc,notice, from); |
2086 | 1169 break; |
8644 | 1170 case SERVACK: |
1171 if (!(g_ascii_strcasecmp(notice.z_message, ZSRVACK_NOTSENT))) { | |
9610 | 1172 message_failed(gc,notice, from); |
8644 | 1173 } |
1174 break; | |
9328 | 1175 case CLIENTACK: |
9478 | 1176 gaim_debug_error("zephyr", "Client ack received\n"); |
2086 | 1177 default: |
1178 /* we'll just ignore things for now */ | |
9328 | 1179 handle_unknown(notice); |
9478 | 1180 gaim_debug_error("zephyr", "Unhandled notice.\n"); |
2086 | 1181 break; |
1182 } | |
9478 | 1183 /* XXX add real error reporting */ |
2086 | 1184 ZFreeNotice(¬ice); |
1185 } | |
1186 | |
1187 return TRUE; | |
1188 } | |
1189 | |
1190 static gint check_loc(gpointer data) | |
1191 { | |
6695 | 1192 GaimBlistNode *gnode, *cnode, *bnode; |
2086 | 1193 ZAsyncLocateData_t ald; |
9896 | 1194 GaimConnection *gc = (GaimConnection *)data; |
1195 zephyr_account *zephyr = gc->proto_data; | |
2086 | 1196 |
9896 | 1197 if (use_zeph02(zephyr)) { |
1198 ald.user = NULL; | |
1199 memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
1200 ald.version = NULL; | |
1201 } | |
2086 | 1202 |
8644 | 1203 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
1204 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4785 | 1205 continue; |
8644 | 1206 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
1207 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
4785 | 1208 continue; |
8644 | 1209 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
1210 GaimBuddy *b = (GaimBuddy *) bnode; | |
1211 | |
1212 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
6695 | 1213 continue; |
9610 | 1214 if (b->account->gc == gc) { |
7261 | 1215 const char *chk; |
8644 | 1216 |
9896 | 1217 chk = local_zephyr_normalize(zephyr,b->name); |
1218 gaim_debug_info("zephyr","chk: %s b->name %s\n",chk,b->name); | |
9478 | 1219 /* XXX add real error reporting */ |
6695 | 1220 /* doesn't matter if this fails or not; we'll just move on to the next one */ |
9896 | 1221 if (use_zeph02(zephyr)) { |
1222 #ifdef WIN32 | |
1223 int numlocs; | |
1224 int one=1; | |
1225 ZLocateUser(chk,&numlocs,ZAUTH); | |
1226 if (numlocs) { | |
1227 int i; | |
1228 for(i=0;i<numlocs;i++) { | |
1229 ZGetLocations(&locations,&one); | |
1230 serv_got_update(gc,b->name,1,0,0,0,0); | |
1231 } | |
1232 } | |
1233 #else | |
1234 ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
1235 g_free(ald.user); | |
1236 g_free(ald.version); | |
1237 #endif /* WIN32 */ | |
1238 } else | |
1239 if (use_tzc(zephyr)) { | |
1240 gchar *zlocstr = g_strdup_printf("((tzcfodder . zlocate) \"%s\")\n",chk); | |
1241 write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,strlen(zlocstr)); | |
1242 g_free(zlocstr); | |
1243 } | |
6695 | 1244 } |
4349 | 1245 } |
2086 | 1246 } |
1247 } | |
9896 | 1248 |
2086 | 1249 return TRUE; |
1250 } | |
1251 | |
1252 static char *get_exposure_level() | |
1253 { | |
9478 | 1254 /* XXX add real error reporting */ |
2086 | 1255 char *exposure = ZGetVariable("exposure"); |
1256 | |
1257 if (!exposure) | |
1258 return EXPOSE_REALMVIS; | |
4793 | 1259 if (!g_ascii_strcasecmp(exposure, EXPOSE_NONE)) |
2086 | 1260 return EXPOSE_NONE; |
4793 | 1261 if (!g_ascii_strcasecmp(exposure, EXPOSE_OPSTAFF)) |
2086 | 1262 return EXPOSE_OPSTAFF; |
4793 | 1263 if (!g_ascii_strcasecmp(exposure, EXPOSE_REALMANN)) |
2086 | 1264 return EXPOSE_REALMANN; |
4793 | 1265 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETVIS)) |
2086 | 1266 return EXPOSE_NETVIS; |
4793 | 1267 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETANN)) |
2086 | 1268 return EXPOSE_NETANN; |
1269 return EXPOSE_REALMVIS; | |
1270 } | |
1271 | |
1272 static void strip_comments(char *str) | |
1273 { | |
1274 char *tmp = strchr(str, '#'); | |
8644 | 1275 |
2086 | 1276 if (tmp) |
1277 *tmp = '\0'; | |
1278 g_strchug(str); | |
1279 g_strchomp(str); | |
1280 } | |
1281 | |
9896 | 1282 static void zephyr_inithosts(zephyr_account *zephyr) |
9478 | 1283 { |
1284 /* XXX This code may not be Win32 clean */ | |
1285 struct hostent *hent; | |
1286 | |
9802 | 1287 if (gethostname(zephyr->ourhost, sizeof(zephyr->ourhost)) == -1) { |
9478 | 1288 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 | 1289 g_strlcpy(zephyr->ourhost, "unknown", sizeof(zephyr->ourhost)); |
9803 | 1290 g_strlcpy(zephyr->ourhostcanon, "unknown", sizeof(zephyr->ourhostcanon)); |
9478 | 1291 return; |
1292 } | |
1293 | |
9610 | 1294 if (!(hent = gethostbyname(zephyr->ourhost))) { |
1295 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); | |
9803 | 1296 g_strlcpy(zephyr->ourhostcanon, zephyr->ourhost, sizeof(zephyr->ourhostcanon)); |
9478 | 1297 return; |
1298 } | |
9802 | 1299 |
1300 g_strlcpy(zephyr->ourhostcanon, hent->h_name, sizeof(zephyr->ourhostcanon)); | |
1301 | |
9478 | 1302 return; |
1303 } | |
1304 | |
9610 | 1305 static void process_zsubs(zephyr_account *zephyr) |
2086 | 1306 { |
9802 | 1307 /* Loads zephyr chats "(subscriptions) from ~/.zephyr.subs, and |
1308 registers (subscribes to) them on the server */ | |
9434 | 1309 |
9802 | 1310 /* XXX deal with unsubscriptions */ |
1311 /* XXX deal with punts */ | |
9434 | 1312 |
2086 | 1313 FILE *f; |
1314 gchar *fname; | |
1315 gchar buff[BUFSIZ]; | |
8644 | 1316 |
3630 | 1317 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
2086 | 1318 f = fopen(fname, "r"); |
1319 if (f) { | |
1320 char **triple; | |
1321 char *recip; | |
9478 | 1322 char *z_class; |
1323 char *z_instance; | |
9896 | 1324 char *z_galaxy = NULL; |
8644 | 1325 |
2086 | 1326 while (fgets(buff, BUFSIZ, f)) { |
1327 strip_comments(buff); | |
1328 if (buff[0]) { | |
1329 triple = g_strsplit(buff, ",", 3); | |
8644 | 1330 if (triple[0] && triple[1]) { |
9896 | 1331 char *tmp = g_strdup_printf("%s", zephyr->username); |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1332 char *atptr; |
8644 | 1333 |
9896 | 1334 z_class = triple[0]; |
1335 z_instance = triple[1]; | |
8644 | 1336 if (triple[2] == NULL) { |
3277 | 1337 recip = g_malloc0(1); |
4793 | 1338 } else if (!g_ascii_strcasecmp(triple[2], "%me%")) { |
9896 | 1339 recip = g_strdup_printf("%s", zephyr->username); |
4793 | 1340 } else if (!g_ascii_strcasecmp(triple[2], "*")) { |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1341 /* wildcard |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1342 * form of class,instance,* */ |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1343 recip = g_malloc0(1); |
4793 | 1344 } else if (!g_ascii_strcasecmp(triple[2], tmp)) { |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1345 /* form of class,instance,aatharuv@ATHENA.MIT.EDU */ |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1346 recip = g_strdup(triple[2]); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1347 } else if ((atptr = strchr(triple[2], '@')) != NULL) { |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1348 /* form of class,instance,*@ANDREW.CMU.EDU |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1349 * class,instance,@ANDREW.CMU.EDU |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1350 * If realm is local realm, blank recipient, else |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1351 * @REALM-NAME |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1352 */ |
9896 | 1353 char *realmat = g_strdup_printf("@%s",zephyr->realm); |
8644 | 1354 |
4793 | 1355 if (!g_ascii_strcasecmp(atptr, realmat)) |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1356 recip = g_malloc0(1); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1357 else |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1358 recip = g_strdup(atptr); |
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1359 g_free(realmat); |
2086 | 1360 } else { |
1361 recip = g_strdup(triple[2]); | |
1362 } | |
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
1363 g_free(tmp); |
9478 | 1364 |
1365 if (!g_ascii_strcasecmp(triple[0],"%host%")) { | |
9610 | 1366 z_class = g_strdup(zephyr->ourhost); |
9478 | 1367 } else if (!g_ascii_strcasecmp(triple[0],"%canon%")) { |
9610 | 1368 z_class = g_strdup(zephyr->ourhostcanon); |
9478 | 1369 } else { |
1370 z_class = g_strdup(triple[0]); | |
1371 } | |
1372 | |
1373 if (!g_ascii_strcasecmp(triple[1],"%host%")) { | |
9610 | 1374 z_instance = g_strdup(zephyr->ourhost); |
9478 | 1375 } else if (!g_ascii_strcasecmp(triple[1],"%canon%")) { |
9610 | 1376 z_instance = g_strdup(zephyr->ourhostcanon); |
9478 | 1377 } else { |
1378 z_instance = g_strdup(triple[1]); | |
1379 } | |
1380 | |
1381 /* There should be some sort of error report listing classes that couldn't be subbed to. | |
1382 Not important right now though */ | |
1383 | |
9896 | 1384 if (zephyr_subscribe_to(zephyr,z_class, z_instance, recip,z_galaxy) != ZERR_NONE) { |
9478 | 1385 |
9896 | 1386 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "Couldn't subscribe to %s, %s, %s\n", z_class,z_instance,recip); |
2086 | 1387 } |
9478 | 1388 |
9896 | 1389 zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,z_class,z_instance,recip)); |
9478 | 1390 /* g_hash_table_destroy(sub_hash_table); */ |
1391 g_free(z_instance); | |
1392 g_free(z_class); | |
2086 | 1393 g_free(recip); |
1394 } | |
1395 g_strfreev(triple); | |
1396 } | |
1397 } | |
1398 } | |
1399 } | |
1400 | |
9610 | 1401 static void process_anyone(GaimConnection *gc) |
2086 | 1402 { |
1403 FILE *fd; | |
1404 gchar buff[BUFSIZ], *filename; | |
6695 | 1405 GaimGroup *g; |
1406 GaimBuddy *b; | |
4775 | 1407 |
1408 if (!(g = gaim_find_group(_("Anyone")))) { | |
1409 g = gaim_group_new(_("Anyone")); | |
1410 gaim_blist_add_group(g, NULL); | |
1411 } | |
6695 | 1412 |
3630 | 1413 filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); |
2086 | 1414 if ((fd = fopen(filename, "r")) != NULL) { |
1415 while (fgets(buff, BUFSIZ, fd)) { | |
1416 strip_comments(buff); | |
4687 | 1417 if (buff[0]) { |
9610 | 1418 if (!(b = gaim_find_buddy(gc->account, buff))) { |
9912 | 1419 char *stripped_user = zephyr_strip_local_realm(gc->proto_data,buff); |
1420 gaim_debug_info("zephyr","stripped_user %s\n",stripped_user); | |
1421 if (!(b = gaim_find_buddy(gc->account,stripped_user))){ | |
1422 b = gaim_buddy_new(gc->account, stripped_user, NULL); | |
1423 gaim_blist_add_buddy(b, NULL, g, NULL); | |
1424 } | |
1425 g_free(stripped_user); | |
8644 | 1426 } |
1427 } | |
2086 | 1428 } |
1429 fclose(fd); | |
1430 } | |
1431 g_free(filename); | |
1432 } | |
1433 | |
8644 | 1434 static void zephyr_login(GaimAccount * account) |
2086 | 1435 { |
9896 | 1436 GaimConnection *gc; |
1437 zephyr_account *zephyr; | |
9427 | 1438 |
9610 | 1439 gc = gaim_account_get_connection(account); |
1440 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC; | |
9896 | 1441 gc->proto_data = zephyr=g_new0(zephyr_account,1); |
1442 zephyr->account = account; | |
1443 zephyr->exposure = g_strdup(gaim_account_get_string(gc->account, "exposure_level", EXPOSE_REALMVIS)); | |
2086 | 1444 |
9896 | 1445 if (gaim_account_get_bool(gc->account,"use_tzc",0)) { |
1446 zephyr->connection_type = GAIM_ZEPHYR_TZC; | |
1447 } else { | |
1448 zephyr->connection_type = GAIM_ZEPHYR_KRB4; | |
1449 } | |
1450 | |
1451 zephyr->encoding = (char *)gaim_account_get_string(gc->account, "encoding", ZEPHYR_FALLBACK_CHARSET); | |
9610 | 1452 gaim_connection_update_progress(gc, _("Connecting"), 0, 8); |
9478 | 1453 |
1454 /* XXX z_call_s should actually try to report the com_err determined error */ | |
9896 | 1455 if (use_tzc(zephyr)) { |
1456 pid_t pid; | |
1457 /* gaim_connection_error(gc,"tzc not supported yet"); */ | |
1458 if ((pipe(zephyr->totzc) != 0) || (pipe(zephyr->fromtzc) != 0)) { | |
1459 gaim_debug_error("zephyr", "pipe creation failed. killing\n"); | |
1460 exit(-1); | |
1461 } | |
1462 | |
1463 pid = fork(); | |
1464 | |
1465 if (pid == -1) { | |
1466 gaim_debug_error("zephyr", "forking failed\n"); | |
1467 exit(-1); | |
1468 } | |
1469 if (pid == 0) { | |
1470 unsigned int i=0; | |
1471 gboolean found_ps = FALSE; | |
1472 gchar ** tzc_cmd_array = g_strsplit(gaim_account_get_string(gc->account,"tzc_command","/usr/bin/tzc -e %s")," ",0); | |
1473 if (close(1) == -1) { | |
1474 gaim_debug_error("zephyr", "stdout couldn't be closed. dying\n"); | |
1475 exit(-1); | |
1476 } | |
1477 if (dup2(zephyr->fromtzc[1], 1) == -1) { | |
1478 gaim_debug_error("zephyr", "dup2 of stdout failed \n"); | |
1479 exit(-1); | |
1480 } | |
1481 if (close(zephyr->fromtzc[1]) == -1) { | |
1482 gaim_debug_error("zephyr", "closing of piped stdout failed\n"); | |
1483 exit(-1); | |
1484 } | |
1485 if (close(0) == -1) { | |
1486 gaim_debug_error("zephyr", "stdin couldn't be closed. dying\n"); | |
1487 exit(-1); | |
1488 } | |
1489 if (dup2(zephyr->totzc[0], 0) == -1) { | |
1490 gaim_debug_error("zephyr", "dup2 of stdin failed \n"); | |
1491 exit(-1); | |
1492 } | |
1493 if (close(zephyr->totzc[0]) == -1) { | |
1494 gaim_debug_error("zephyr", "closing of piped stdin failed\n"); | |
1495 exit(-1); | |
1496 } | |
1497 /* tzc_command should really be of the form | |
1498 path/to/tzc -e %s | |
1499 or | |
1500 ssh username@hostname pathtotzc -e %s | |
1501 -- this should not require a password, and ideally should be kerberized ssh -- | |
1502 or | |
1503 fsh username@hostname pathtotzc -e %s | |
1504 */ | |
1505 while(tzc_cmd_array[i] != NULL){ | |
1506 if (!g_strncasecmp(tzc_cmd_array[i],"%s",2)) { | |
1507 /* fprintf(stderr,"replacing %%s with %s\n",zephyr->exposure); */ | |
1508 tzc_cmd_array[i] = g_strdup(zephyr->exposure); | |
1509 found_ps = TRUE; | |
1510 | |
1511 } else { | |
1512 /* fprintf(stderr,"keeping %s\n",tzc_cmd_array[i]); */ | |
1513 } | |
1514 i++; | |
1515 } | |
8645 | 1516 |
9896 | 1517 if (!found_ps) { |
1518 gaim_connection_error(gc,"Tzc command needs %s to set the exposure\n"); | |
1519 return; | |
1520 } | |
1521 | |
1522 execvp(tzc_cmd_array[0], tzc_cmd_array); | |
1523 } | |
1524 else { | |
1525 fd_set rfds; | |
1526 int bufsize = 2048; | |
1527 char *buf = (char *)calloc(bufsize, 1); | |
1528 char *bufcur = buf; | |
1529 struct timeval tv; | |
1530 char *ptr; | |
1531 int parenlevel=0; | |
1532 char* tempstr; | |
1533 int tempstridx; | |
1534 | |
1535 zephyr->tzc_pid = pid; | |
1536 /* wait till we have data to read from ssh */ | |
1537 FD_ZERO(&rfds); | |
1538 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); | |
1539 | |
1540 tv.tv_sec = 10; | |
1541 tv.tv_usec = 0; | |
1542 | |
1543 gaim_debug_info("zephyr", "about to read from tzc\n"); | |
1544 | |
1545 select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, NULL); | |
1546 | |
1547 FD_ZERO(&rfds); | |
1548 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); | |
1549 while (select(zephyr->fromtzc[ZEPHYR_FD_READ] + 1, &rfds, NULL, NULL, &tv)) { | |
1550 read(zephyr->fromtzc[ZEPHYR_FD_READ], bufcur, 1); | |
1551 bufcur++; | |
1552 if ((bufcur - buf) > (bufsize - 1)) { | |
1553 if ((buf = realloc(buf, bufsize * 2)) == NULL) { | |
1554 exit(-1); | |
1555 } else { | |
1556 bufcur = buf + bufsize; | |
1557 bufsize *= 2; | |
1558 } | |
1559 } | |
1560 FD_ZERO(&rfds); | |
1561 FD_SET(zephyr->fromtzc[ZEPHYR_FD_READ], &rfds); | |
1562 tv.tv_sec = 10; | |
1563 tv.tv_usec = 0; | |
2086 | 1564 |
9896 | 1565 } |
1566 /* fprintf(stderr, "read from tzc\n"); */ | |
1567 *bufcur = '\0'; | |
1568 ptr = buf; | |
1569 | |
1570 /* ignore all tzcoutput till we've received the first (*/ | |
1571 while (ptr < bufcur && (*ptr !='(')) { | |
1572 ptr++; | |
1573 } | |
1574 if (ptr >=bufcur) { | |
1575 gaim_connection_error(gc,"invalid output by tzc (or bad parsing code)"); | |
1576 return; | |
1577 } | |
9427 | 1578 |
9896 | 1579 while(ptr < bufcur) { |
1580 if (*ptr == '(') { | |
1581 parenlevel++; | |
1582 } | |
1583 else if (*ptr == ')') { | |
1584 parenlevel--; | |
1585 } | |
1586 gaim_debug_info("zephyr","tzc parenlevel is %d\n",parenlevel); | |
1587 switch (parenlevel) { | |
1588 case 0: | |
1589 break; | |
1590 case 1: | |
1591 /* Search for next beginning (, or for the ending */ | |
1592 ptr++; | |
1593 while((*ptr != '(') && (*ptr != ')') && (ptr <bufcur)) | |
1594 ptr++; | |
1595 if (ptr >= bufcur) | |
1596 gaim_debug_error("zephyr","tzc parsing error\n"); | |
1597 break; | |
1598 case 2: | |
1599 /* You are probably at | |
1600 (foo . bar ) or (foo . "bar") or (foo . chars) or (foo . numbers) or (foo . () ) | |
1601 Parse all the data between the first and last f, and move past ) | |
1602 */ | |
1603 tempstr = g_malloc0(20000); | |
1604 tempstridx=0; | |
1605 while(parenlevel >1) { | |
1606 ptr++; | |
1607 if (*ptr == '(') | |
1608 parenlevel++; | |
1609 if (*ptr == ')') | |
1610 parenlevel--; | |
1611 if (parenlevel > 1) { | |
1612 tempstr[tempstridx++]=*ptr; | |
1613 } else { | |
1614 ptr++; | |
1615 } | |
1616 } | |
1617 gaim_debug_info("zephyr","tempstr parsed\n"); | |
1618 /* tempstr should now be a tempstridx length string containing all characters | |
1619 from that after the first ( to the one before the last paren ). */ | |
1620 /* We should have the following possible lisp strings but we don't care | |
1621 (tzcspew . start) (version . "something") (pid . number)*/ | |
1622 /* We care about 'zephyrid . "username@REALM.NAME"' and 'exposure . "SOMETHING"' */ | |
1623 tempstridx=0; | |
1624 if (!g_ascii_strncasecmp(tempstr,"zephyrid",8)) { | |
1625 gchar* username = g_malloc0(100); | |
1626 int username_idx=0; | |
1627 char *realm; | |
1628 gaim_debug_info("zephyr","zephyrid found\n"); | |
1629 tempstridx+=8; | |
1630 while(tempstr[tempstridx] !='"' && tempstridx < 20000) | |
1631 tempstridx++; | |
1632 tempstridx++; | |
1633 while(tempstr[tempstridx] !='"' && tempstridx < 20000) | |
1634 username[username_idx++]=tempstr[tempstridx++]; | |
1635 | |
1636 zephyr->username = g_strdup_printf("%s",username); | |
1637 if ((realm = strchr(username,'@'))) | |
1638 zephyr->realm = g_strdup_printf("%s",realm+1); | |
1639 else | |
1640 zephyr->realm = g_strdup("local-realm"); | |
1641 | |
1642 g_free(username); | |
1643 } else { | |
1644 gaim_debug_info("zephyr", "something that's not zephyr id found %s\n",tempstr); | |
1645 } | |
1646 | |
1647 /* We don't care about anything else yet */ | |
1648 g_free(tempstr); | |
1649 break; | |
1650 default: | |
1651 gaim_debug_info("zephyr","parenlevel is not 1 or 2\n"); | |
1652 /* This shouldn't be happening */ | |
1653 break; | |
1654 } | |
1655 if (parenlevel==0) | |
1656 break; | |
1657 } /* while (ptr < bufcur) { */ | |
1658 gaim_debug_info("zephyr", "tzc startup done\n"); | |
1659 } | |
1660 } | |
1661 else if ( use_zeph02(zephyr)) { | |
1662 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); | |
1663 z_call_s(ZOpenPort(&(zephyr->port)), "Couldn't open port"); | |
1664 z_call_s(ZSetLocation((char *)zephyr->exposure), "Couldn't set location"); | |
1665 | |
1666 zephyr->username = g_strdup(ZGetSender()); | |
1667 zephyr->realm = g_strdup(ZGetRealm()); | |
1668 gaim_debug_info("zephyr","realm: %s\n",zephyr->realm); | |
1669 } | |
1670 else { | |
1671 gaim_connection_error(gc,"Only ZEPH0.2 supported currently"); | |
1672 return; | |
1673 } | |
1674 gaim_debug_info("zephyr","does it get here\n"); | |
1675 gaim_debug_info("zephyr"," realm: %s username:%s\n", zephyr->realm, zephyr->username); | |
1676 | |
1677 /* For now */ | |
1678 zephyr->galaxy = NULL; | |
1679 zephyr->krbtkfile = NULL; | |
1680 zephyr_inithosts(zephyr); | |
1681 | |
1682 if (zephyr_subscribe_to(zephyr,"MESSAGE","PERSONAL",zephyr->username,NULL) != ZERR_NONE) { | |
9478 | 1683 /* XXX don't translate this yet. It could be written better */ |
1684 /* XXX error messages could be handled with more detail */ | |
1685 gaim_notify_error(account->gc, NULL, | |
1686 "Unable to subscribe to messages", "Unable to subscribe to initial messages"); | |
1687 return; | |
2086 | 1688 } |
1689 | |
9610 | 1690 gaim_connection_set_state(gc, GAIM_CONNECTED); |
9896 | 1691 process_anyone(gc); |
1692 process_zsubs(zephyr); | |
9610 | 1693 serv_finish_login(gc); |
2086 | 1694 |
9896 | 1695 if (use_zeph02(zephyr)) { |
1696 zephyr->nottimer = gaim_timeout_add(100, check_notify_zeph02, gc); | |
1697 } else if (use_tzc(zephyr)) { | |
1698 zephyr->nottimer = gaim_timeout_add(100, check_notify_tzc, gc); | |
1699 } | |
1700 zephyr->loctimer = gaim_timeout_add(20000, check_loc, gc); | |
2086 | 1701 |
1702 } | |
1703 | |
9610 | 1704 static void write_zsubs(zephyr_account *zephyr) |
2086 | 1705 { |
9896 | 1706 /* Exports subscription (chat) list back to |
1707 * .zephyr.subs | |
1708 * XXX deal with %host%, %canon%, unsubscriptions, and negative subscriptions (punts?) | |
1709 */ | |
9434 | 1710 |
9610 | 1711 GSList *s = zephyr->subscrips; |
2086 | 1712 zephyr_triple *zt; |
1713 FILE *fd; | |
1714 char *fname; | |
1715 | |
8644 | 1716 char **triple; |
1717 | |
3630 | 1718 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
2086 | 1719 fd = fopen(fname, "w"); |
8644 | 1720 |
2086 | 1721 if (!fd) { |
1722 g_free(fname); | |
1723 return; | |
1724 } | |
8644 | 1725 |
2086 | 1726 while (s) { |
9478 | 1727 char *zclass, *zinst, *zrecip; |
2086 | 1728 zt = s->data; |
8644 | 1729 triple = g_strsplit(zt->name, ",", 3); |
9478 | 1730 |
1731 /* deal with classes */ | |
9610 | 1732 if (!g_ascii_strcasecmp(triple[0],zephyr->ourhost)) { |
9775 | 1733 zclass = g_strdup("%host%"); |
9610 | 1734 } else if (!g_ascii_strcasecmp(triple[0],zephyr->ourhostcanon)) { |
9775 | 1735 zclass = g_strdup("%canon%"); |
9478 | 1736 } else { |
1737 zclass = g_strdup(triple[0]); | |
1738 } | |
1739 | |
1740 /* deal with instances */ | |
1741 | |
9610 | 1742 if (!g_ascii_strcasecmp(triple[1],zephyr->ourhost)) { |
9775 | 1743 zinst = g_strdup("%host%"); |
9610 | 1744 } else if (!g_ascii_strcasecmp(triple[1],zephyr->ourhostcanon)) { |
9896 | 1745 zinst = g_strdup("%canon%");; |
1746 } else { | |
9478 | 1747 zinst = g_strdup(triple[1]); |
9896 | 1748 } |
9478 | 1749 |
1750 /* deal with recipients */ | |
1751 if (triple[2] == NULL) { | |
1752 zrecip = g_strdup("*"); | |
1753 } else if (!g_ascii_strcasecmp(triple[2],"")){ | |
1754 zrecip = g_strdup("*"); | |
9896 | 1755 } else if (!g_ascii_strcasecmp(triple[2], zephyr->username)) { |
9478 | 1756 zrecip = g_strdup("%me%"); |
3277 | 1757 } else { |
9478 | 1758 zrecip = g_strdup(triple[2]); |
3277 | 1759 } |
9478 | 1760 |
1761 fprintf(fd, "%s,%s,%s\n",zclass,zinst,zrecip); | |
1762 | |
1763 g_free(zclass); | |
1764 g_free(zinst); | |
1765 g_free(zrecip); | |
3277 | 1766 g_free(triple); |
2086 | 1767 s = s->next; |
1768 } | |
1769 g_free(fname); | |
1770 fclose(fd); | |
1771 } | |
1772 | |
9610 | 1773 static void write_anyone(GaimConnection *gc) |
2086 | 1774 { |
6695 | 1775 GaimBlistNode *gnode, *cnode, *bnode; |
1776 GaimBuddy *b; | |
9912 | 1777 char *fname; |
2086 | 1778 FILE *fd; |
9896 | 1779 zephyr_account* zephyr = gc->proto_data; |
3630 | 1780 fname = g_strdup_printf("%s/.anyone", gaim_home_dir()); |
2086 | 1781 fd = fopen(fname, "w"); |
1782 if (!fd) { | |
1783 g_free(fname); | |
1784 return; | |
1785 } | |
1786 | |
8644 | 1787 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
1788 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
4785 | 1789 continue; |
8644 | 1790 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
1791 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
4785 | 1792 continue; |
8644 | 1793 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
1794 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
6695 | 1795 continue; |
8644 | 1796 b = (GaimBuddy *) bnode; |
9610 | 1797 if (b->account == gc->account) { |
9912 | 1798 gchar *stripped_user = zephyr_strip_local_realm(zephyr,b->name); |
1799 fprintf(fd, "%s\n", stripped_user); | |
1800 g_free(stripped_user); | |
3277 | 1801 } |
1802 } | |
2086 | 1803 } |
1804 } | |
1805 | |
1806 fclose(fd); | |
1807 g_free(fname); | |
1808 } | |
1809 | |
8644 | 1810 static void zephyr_close(GaimConnection * gc) |
2086 | 1811 { |
1812 GList *l; | |
1813 GSList *s; | |
9896 | 1814 zephyr_account *zephyr = gc->proto_data; |
1815 pid_t tzc_pid = zephyr->tzc_pid; | |
8644 | 1816 |
9610 | 1817 l = zephyr->pending_zloc_names; |
2086 | 1818 while (l) { |
8644 | 1819 g_free((char *)l->data); |
2086 | 1820 l = l->next; |
1821 } | |
9610 | 1822 g_list_free(zephyr->pending_zloc_names); |
8644 | 1823 |
9610 | 1824 if (gaim_account_get_bool(gc->account, "write_anyone", FALSE)) |
1825 write_anyone(gc); | |
8644 | 1826 |
9610 | 1827 if (gaim_account_get_bool(gc->account, "write_zsubs", FALSE)) |
1828 write_zsubs(gc->proto_data); | |
8644 | 1829 |
9610 | 1830 s = zephyr->subscrips; |
2086 | 1831 while (s) { |
8644 | 1832 free_triple((zephyr_triple *) s->data); |
2086 | 1833 s = s->next; |
1834 } | |
9610 | 1835 g_slist_free(zephyr->subscrips); |
8644 | 1836 |
9610 | 1837 if (zephyr->nottimer) |
1838 gaim_timeout_remove(zephyr->nottimer); | |
1839 zephyr->nottimer = 0; | |
1840 if (zephyr->loctimer) | |
1841 gaim_timeout_remove(zephyr->loctimer); | |
1842 zephyr->loctimer = 0; | |
1843 gc = NULL; | |
9896 | 1844 if (use_zeph02(zephyr)) { |
1845 z_call(ZCancelSubscriptions(0)); | |
1846 z_call(ZUnsetLocation()); | |
1847 z_call(ZClosePort()); | |
1848 } else { | |
1849 /* assume tzc */ | |
1850 if (kill(tzc_pid,SIGTERM) == -1) { | |
1851 int err=errno; | |
1852 if (err==EINVAL) { | |
1853 gaim_debug_error("zephyr","An invalid signal was specified when killing tzc\n"); | |
1854 } | |
1855 else if (err==ESRCH) { | |
1856 gaim_debug_error("zephyr","Tzc's pid didn't exist while killing tzc\n"); | |
1857 } | |
1858 else if (err==EPERM) { | |
1859 gaim_debug_error("zephyr","gaim didn't have permission to kill tzc\n"); | |
1860 } | |
1861 else { | |
1862 gaim_debug_error("zephyr","miscellaneous error while attempting to close tzc\n"); | |
1863 } | |
1864 } | |
1865 } | |
2086 | 1866 } |
1867 | |
9896 | 1868 static int zephyr_send_message(zephyr_account *zephyr,char* zclass, char* instance, char* recipient, const char *im, |
9478 | 1869 const char *sig, char *opcode) ; |
9434 | 1870 |
1871 const char * zephyr_get_signature() | |
1872 { | |
9478 | 1873 /* XXX add zephyr error reporting */ |
1874 const char * sig =ZGetVariable("zwrite-signature"); | |
9896 | 1875 if (!sig) { |
1876 sig = g_get_real_name(); | |
1877 } | |
1878 return sig; | |
9434 | 1879 } |
1880 | |
8644 | 1881 static int zephyr_chat_send(GaimConnection * gc, int id, const char *im) |
2086 | 1882 { |
1883 zephyr_triple *zt; | |
1884 const char *sig; | |
8644 | 1885 GaimConversation *gconv1; |
1886 GaimConvChat *gcc; | |
1887 char *inst; | |
9896 | 1888 char *recipient; |
1889 zephyr_account *zephyr = gc->proto_data; | |
2086 | 1890 |
9610 | 1891 zt = find_sub_by_id(gc->proto_data,id); |
2086 | 1892 if (!zt) |
1893 /* this should never happen. */ | |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1894 return -EINVAL; |
8644 | 1895 |
9896 | 1896 sig = zephyr_get_signature(); |
2086 | 1897 |
9610 | 1898 gconv1 = gaim_find_conversation_with_account(zt->name, gc->account); |
8644 | 1899 gcc = gaim_conversation_get_chat_data(gconv1); |
8212 | 1900 |
8644 | 1901 if (!(inst = (char *)gaim_conv_chat_get_topic(gcc))) |
9434 | 1902 inst = g_strdup("PERSONAL"); |
8644 | 1903 |
4793 | 1904 if (!g_ascii_strcasecmp(zt->recipient, "*")) |
9896 | 1905 recipient = local_zephyr_normalize(zephyr,""); |
2086 | 1906 else |
9896 | 1907 recipient = local_zephyr_normalize(zephyr,zt->recipient); |
8451 | 1908 |
9896 | 1909 zephyr_send_message(zephyr,zt->class,inst,recipient,im,sig,""); |
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1910 return 0; |
2086 | 1911 } |
1912 | |
9434 | 1913 |
8644 | 1914 static int zephyr_send_im(GaimConnection * gc, const char *who, const char *im, GaimConvImFlags flags) |
1915 { | |
2086 | 1916 const char *sig; |
9896 | 1917 zephyr_account *zephyr = gc->proto_data; |
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
1918 if (flags & GAIM_CONV_IM_AUTO_RESP) |
2086 | 1919 sig = "Automated reply:"; |
1920 else { | |
9434 | 1921 sig = zephyr_get_signature(); |
2086 | 1922 } |
9896 | 1923 zephyr_send_message(zephyr,"MESSAGE","PERSONAL",local_zephyr_normalize(zephyr,who),im,sig,""); |
9434 | 1924 |
1925 return 1; | |
1926 } | |
2086 | 1927 |
9896 | 1928 /* Munge the outgoing zephyr so that any quotes or backslashes are |
1929 escaped and do not confuse tzc: */ | |
1930 | |
1931 char* zephyr_tzc_escape_msg(const char *message) | |
1932 { | |
1933 int pos = 0; | |
1934 int pos2 = 0; | |
1935 char *newmsg; | |
1936 | |
1937 if (message && (strlen(message) > 0)) { | |
1938 newmsg = g_new0(char,1+strlen(message)*2); | |
1939 while(pos < strlen(message)) { | |
1940 if (message[pos]=='\\') { | |
1941 newmsg[pos2]='\\'; | |
1942 newmsg[pos2+1]='\\'; | |
1943 pos2+=2; | |
1944 } | |
1945 else if (message[pos]=='"') { | |
1946 newmsg[pos2]='\\'; | |
1947 newmsg[pos2+1]='"'; | |
1948 pos2+=2; | |
1949 } | |
1950 else { | |
1951 newmsg[pos2] = message[pos]; | |
1952 pos2++; | |
1953 } | |
1954 pos++; | |
1955 } | |
1956 } else { | |
1957 newmsg = g_strdup(""); | |
1958 } | |
1959 /* fprintf(stderr,"newmsg %s message %s\n",newmsg,message); */ | |
1960 return newmsg; | |
1961 } | |
1962 | |
1963 char* zephyr_tzc_deescape_str(const char *message) | |
1964 { | |
1965 int pos = 0; | |
1966 int pos2 = 0; | |
1967 char *newmsg; | |
1968 | |
1969 if (message && (strlen(message) > 0)) { | |
1970 newmsg = g_new0(char,strlen(message)+1); | |
1971 while(pos < strlen(message)) { | |
1972 if (message[pos]=='\\') { | |
1973 pos++; | |
1974 } | |
1975 newmsg[pos2] = message[pos]; | |
1976 pos++;pos2++; | |
1977 } | |
1978 newmsg[pos2]='\0'; | |
1979 } else { | |
1980 newmsg = g_strdup(""); | |
1981 } | |
1982 | |
1983 return newmsg; | |
1984 } | |
1985 | |
1986 static int zephyr_send_message(zephyr_account *zephyr,char* zclass, char* instance, char* recipient, const char *im, | |
9478 | 1987 const char *sig, char *opcode) |
9434 | 1988 { |
8451 | 1989 |
9896 | 1990 /* (From the tzc source) |
1991 * emacs sends something of the form: | |
1992 * ((class . "MESSAGE") | |
1993 * (auth . t) | |
1994 * (recipients ("PERSONAL" . "bovik") ("test" . "")) | |
1995 * (sender . "bovik") | |
1996 * (message . ("Harry Bovik" "my zgram")) | |
1997 * ) | |
1998 */ | |
1999 char *html_buf; | |
2000 char *html_buf2; | |
2001 html_buf = html_to_zephyr(im); | |
2002 html_buf2 = gaim_unescape_html(html_buf); | |
9434 | 2003 |
9896 | 2004 if(use_tzc(zephyr)) { |
2005 char* zsendstr; | |
2006 /* CMU cclub tzc doesn't grok opcodes for now */ | |
2007 char* tzc_sig = zephyr_tzc_escape_msg(sig); | |
2008 char *tzc_body = zephyr_tzc_escape_msg(html_buf2); | |
2009 zsendstr = g_strdup_printf("((tzcfodder . send) (class . \"%s\") (auth . t) (recipients (\"%s\" . \"%s\")) (message . (\"%s\" \"%s\")) ) \n", | |
2010 zclass, instance, recipient, tzc_sig, tzc_body); | |
2011 /* fprintf(stderr,"zsendstr = %s\n",zsendstr); */ | |
2012 write(zephyr->totzc[ZEPHYR_FD_WRITE],zsendstr,strlen(zsendstr)); | |
2013 g_free(zsendstr); | |
2014 } else if (use_zeph02(zephyr)) { | |
2015 ZNotice_t notice; | |
2016 char *buf = g_strdup_printf("%s%c%s", sig, '\0', html_buf2); | |
2017 bzero((char *)¬ice, sizeof(notice)); | |
2018 | |
2019 notice.z_kind = ACKED; | |
2020 notice.z_port = 0; | |
2021 notice.z_opcode = ""; | |
2022 notice.z_class = zclass; | |
2023 notice.z_class_inst = instance; | |
2024 notice.z_recipient = recipient; | |
2025 notice.z_sender = 0; | |
2026 notice.z_default_format = "Class $class, Instance $instance:\n" "To: @bold($recipient) at $time $date\n" "From: @bold($1) <$sender>\n\n$2"; | |
2027 notice.z_message_len = strlen(html_buf2) + strlen(sig) + 2; | |
2028 notice.z_message = buf; | |
2029 notice.z_opcode = g_strdup(opcode); | |
2030 gaim_debug_info("zephyr","About to send notice"); | |
2031 if (! ZSendNotice(¬ice, ZAUTH) == ZERR_NONE) { | |
2032 /* XXX handle errors here */ | |
2033 return 0; | |
2034 } | |
2035 gaim_debug_info("zephyr","notice sent"); | |
2036 g_free(buf); | |
9478 | 2037 } |
2038 | |
8644 | 2039 g_free(html_buf2); |
2040 g_free(html_buf); | |
8451 | 2041 |
9896 | 2042 return 1; |
2086 | 2043 } |
2044 | |
8644 | 2045 static const char *zephyr_normalize(const GaimAccount * account, const char *orig) |
2086 | 2046 { |
9328 | 2047 /* returns the string you gave it. Maybe this function shouldn't be here */ |
9896 | 2048 char * buf = g_malloc0(80); |
2049 /* gaim_debug_error("zephyr","entering zephyr_normalize\n"); */ | |
8644 | 2050 |
7126 | 2051 if (!g_ascii_strcasecmp(orig, "")) { |
2052 buf[0] = '\0'; | |
2053 return buf; | |
8354 | 2054 } else { |
8644 | 2055 g_snprintf(buf, 80, "%s", orig); |
2056 } | |
9896 | 2057 /* gaim_debug_error("zephyr","leaving zephyr_normalize\n"); */ |
2058 | |
8644 | 2059 return buf; |
8354 | 2060 } |
2061 | |
2062 | |
9896 | 2063 char *local_zephyr_normalize(zephyr_account *zephyr,const char *orig) |
8354 | 2064 { |
9328 | 2065 /* |
9912 | 2066 Basically the inverse of zephyr_strip_local_realm |
9896 | 2067 */ |
2068 char* buf; | |
2069 | |
8354 | 2070 if (!g_ascii_strcasecmp(orig, "")) { |
9896 | 2071 return g_strdup(""); |
7126 | 2072 } |
8644 | 2073 |
9896 | 2074 if (strchr(orig,'@')) { |
2075 buf = g_strdup_printf("%s",orig); | |
2086 | 2076 } else { |
9896 | 2077 buf = g_strdup_printf("%s@%s",orig,zephyr->realm); |
2078 } | |
2086 | 2079 return buf; |
2080 } | |
2081 | |
9030 | 2082 static void zephyr_zloc(GaimConnection *gc, const char *who) |
2086 | 2083 { |
2084 ZAsyncLocateData_t ald; | |
9896 | 2085 zephyr_account *zephyr = gc->proto_data; |
2086 gchar* normalized_who = local_zephyr_normalize(zephyr,who); | |
2087 | |
2088 if (use_zeph02(zephyr)) { | |
2089 if (ZRequestLocations(normalized_who, &ald, UNACKED, ZAUTH) == ZERR_NONE) { | |
2090 zephyr->pending_zloc_names = g_list_append(zephyr->pending_zloc_names, | |
2091 g_strdup(normalized_who)); | |
2092 } else { | |
2093 /* XXX deal with errors somehow */ | |
2094 } | |
2095 } else if (use_tzc(zephyr)) { | |
2096 char* zlocstr = g_strdup_printf("((tzcfodder . zlocate) \"%s\")\n",normalized_who); | |
2097 zephyr->pending_zloc_names = g_list_append(zephyr->pending_zloc_names, g_strdup(normalized_who)); | |
2098 write(zephyr->totzc[ZEPHYR_FD_WRITE],zlocstr,strlen(zlocstr)); | |
2099 g_free(zlocstr); | |
2086 | 2100 } |
2101 } | |
2102 | |
8644 | 2103 static void zephyr_set_away(GaimConnection * gc, const char *state, const char *msg) |
2086 | 2104 { |
9896 | 2105 zephyr_account *zephyr = gc->proto_data; |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
2106 if (gc->away) { |
2086 | 2107 g_free(gc->away); |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
2108 gc->away = NULL; |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
2109 } |
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
2110 |
5132 | 2111 if (!g_ascii_strcasecmp(state, _("Hidden"))) { |
9478 | 2112 /* XXX handle errors */ |
9896 | 2113 if (use_zeph02(zephyr)) { |
2114 ZSetLocation(EXPOSE_OPSTAFF); | |
2115 } else { | |
2116 char *zexpstr = g_strdup_printf("((tzcfodder . set-location) (hostname . \"%s\") (exposure . \"%s\"))\n",zephyr->ourhost,EXPOSE_OPSTAFF); | |
2117 write(zephyr->totzc[ZEPHYR_FD_WRITE],zexpstr,strlen(zexpstr)); | |
2118 g_free(zexpstr); | |
2119 } | |
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
2120 gc->away = g_strdup(""); |
9478 | 2121 } |
2122 else if (!g_ascii_strcasecmp(state, _("Online"))) { | |
2123 /* XXX handle errors */ | |
9896 | 2124 if (use_zeph02(zephyr)) { |
2125 ZSetLocation(get_exposure_level()); | |
2126 } | |
2127 else { | |
2128 char *zexpstr = g_strdup_printf("((tzcfodder . set-location) (hostname . \"%s\") (exposure . \"%s\"))\n",zephyr->ourhost,zephyr->exposure); | |
2129 write(zephyr->totzc[ZEPHYR_FD_WRITE],zexpstr,strlen(zexpstr)); | |
2130 g_free(zexpstr); | |
2131 } | |
9478 | 2132 } |
2086 | 2133 else /* state is GAIM_AWAY_CUSTOM */ if (msg) |
2134 gc->away = g_strdup(msg); | |
2135 } | |
2136 | |
8644 | 2137 static GList *zephyr_away_states(GaimConnection * gc) |
2086 | 2138 { |
2139 GList *m = NULL; | |
2140 | |
5132 | 2141 m = g_list_append(m, _("Online")); |
2086 | 2142 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
5132 | 2143 m = g_list_append(m, _("Hidden")); |
2086 | 2144 |
2145 return m; | |
2146 } | |
2147 | |
8644 | 2148 static GList *zephyr_chat_info(GaimConnection * gc) |
2149 { | |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2150 GList *m = NULL; |
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2151 struct proto_chat_entry *pce; |
2086 | 2152 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2153 pce = g_new0(struct proto_chat_entry, 1); |
8644 | 2154 |
7841 | 2155 pce->label = _("_Class:"); |
5234 | 2156 pce->identifier = "class"; |
3158 | 2157 m = g_list_append(m, pce); |
2086 | 2158 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2159 pce = g_new0(struct proto_chat_entry, 1); |
8644 | 2160 |
7841 | 2161 pce->label = _("_Instance:"); |
5234 | 2162 pce->identifier = "instance"; |
3158 | 2163 m = g_list_append(m, pce); |
2086 | 2164 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2165 pce = g_new0(struct proto_chat_entry, 1); |
8644 | 2166 |
7841 | 2167 pce->label = _("_Recipient:"); |
5234 | 2168 pce->identifier = "recipient"; |
3158 | 2169 m = g_list_append(m, pce); |
2086 | 2170 |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2171 return m; |
2086 | 2172 } |
2173 | |
9478 | 2174 /* Called when the server notifies us a message couldn't get sent */ |
2175 | |
9896 | 2176 static void zephyr_subscribe_failed(GaimConnection *gc,char * z_class, char *z_instance, char * z_recipient, char* z_galaxy) |
9478 | 2177 { |
9896 | 2178 gchar* subscribe_failed = g_strdup_printf(_("Attempt to subscribe to %s,%s,%s failed"), z_class, z_instance,z_recipient); |
9610 | 2179 gaim_notify_error(gc,"", subscribe_failed, NULL); |
9478 | 2180 g_free(subscribe_failed); |
2181 } | |
2182 | |
8644 | 2183 static void zephyr_join_chat(GaimConnection * gc, GHashTable * data) |
2086 | 2184 { |
9896 | 2185 /* ZSubscription_t sub; */ |
2086 | 2186 zephyr_triple *zt1, *zt2; |
2187 const char *classname; | |
2188 const char *instname; | |
2189 const char *recip; | |
9896 | 2190 zephyr_account *zephyr=gc->proto_data; |
5234 | 2191 classname = g_hash_table_lookup(data, "class"); |
2192 instname = g_hash_table_lookup(data, "instance"); | |
2193 recip = g_hash_table_lookup(data, "recipient"); | |
2194 | |
9478 | 2195 |
9328 | 2196 if (!classname) |
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
2197 return; |
9478 | 2198 |
2199 if (!g_ascii_strcasecmp(classname,"%host%")) | |
9896 | 2200 classname = g_strdup(zephyr->ourhost); |
9478 | 2201 if (!g_ascii_strcasecmp(classname,"%canon%")) |
9896 | 2202 classname = g_strdup(zephyr->ourhostcanon); |
9478 | 2203 |
9328 | 2204 if (!instname || !strlen(instname)) |
2205 instname = "*"; | |
9478 | 2206 |
2207 if (!g_ascii_strcasecmp(instname,"%host%")) | |
9896 | 2208 instname = g_strdup(zephyr->ourhost); |
9478 | 2209 if (!g_ascii_strcasecmp(instname,"%canon%")) |
9896 | 2210 instname = g_strdup(zephyr->ourhostcanon); |
9478 | 2211 |
9328 | 2212 if (!recip || (*recip == '*')) |
2213 recip = ""; | |
4793 | 2214 if (!g_ascii_strcasecmp(recip, "%me%")) |
9896 | 2215 recip = zephyr->username; |
2086 | 2216 |
9610 | 2217 zt1 = new_triple(gc->proto_data,classname, instname, recip); |
2218 zt2 = find_sub_by_triple(gc->proto_data,zt1); | |
2086 | 2219 if (zt2) { |
2220 free_triple(zt1); | |
9328 | 2221 if (!zt2->open) { |
2222 if (!g_ascii_strcasecmp(instname,"*")) | |
2223 instname = "PERSONAL"; | |
9434 | 2224 serv_got_joined_chat(gc, zt2->id, zt2->name); |
9896 | 2225 zephyr_chat_set_topic(gc,zt2->id,instname); |
9328 | 2226 zt2->open = TRUE; |
2227 } | |
2086 | 2228 return; |
2229 } | |
9896 | 2230 |
2231 /* sub.zsub_class = zt1->class; | |
2232 sub.zsub_classinst = zt1->instance; | |
2233 sub.zsub_recipient = zt1->recipient; */ | |
2234 | |
2235 if (zephyr_subscribe_to(zephyr,zt1->class,zt1->instance,zt1->recipient,NULL) != ZERR_NONE) { | |
9478 | 2236 /* XXX output better subscription information */ |
9896 | 2237 zephyr_subscribe_failed(gc,zt1->class,zt1->instance,zt1->recipient,NULL); |
2086 | 2238 free_triple(zt1); |
2239 return; | |
2240 } | |
2241 | |
9610 | 2242 zephyr->subscrips = g_slist_append(zephyr->subscrips, zt1); |
2086 | 2243 zt1->open = TRUE; |
2244 serv_got_joined_chat(gc, zt1->id, zt1->name); | |
9328 | 2245 if (!g_ascii_strcasecmp(instname,"*")) |
2246 instname = "PERSONAL"; | |
9896 | 2247 zephyr_chat_set_topic(gc,zt1->id,instname); |
2086 | 2248 } |
2249 | |
8644 | 2250 static void zephyr_chat_leave(GaimConnection * gc, int id) |
2086 | 2251 { |
2252 zephyr_triple *zt; | |
9896 | 2253 zephyr_account *zephyr = gc->proto_data; |
9610 | 2254 zt = find_sub_by_id(zephyr,id); |
9896 | 2255 |
2086 | 2256 if (zt) { |
2257 zt->open = FALSE; | |
9610 | 2258 zt->id = ++(zephyr->last_id); |
2086 | 2259 } |
2260 } | |
2261 | |
9478 | 2262 static GaimChat *zephyr_find_blist_chat(GaimAccount *account, const char *name) |
2263 { | |
2264 GaimBlistNode *gnode, *cnode; | |
2265 | |
2266 /* XXX needs to be %host%,%canon%, and %me% clean */ | |
2267 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
2268 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
2269 GaimChat *chat = (GaimChat*)cnode; | |
2270 char *zclass, *inst, *recip; | |
2271 char** triple; | |
2272 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
2273 continue; | |
2274 if(chat->account !=account) | |
2275 continue; | |
2276 if(!(zclass = g_hash_table_lookup(chat->components, "class"))) | |
2277 continue; | |
2278 if(!(inst = g_hash_table_lookup(chat->components, "instance"))) | |
2279 inst = g_strdup(""); | |
2280 if(!(recip = g_hash_table_lookup(chat->components, "recipient"))) | |
2281 recip = g_strdup(""); | |
9896 | 2282 /* gaim_debug_info("zephyr","in zephyr_find_blist_chat name: %s\n",name?name:""); */ |
9478 | 2283 triple = g_strsplit(name,",",3); |
2284 if (!g_ascii_strcasecmp(triple[0],zclass) && !g_ascii_strcasecmp(triple[1],inst) && !g_ascii_strcasecmp(triple[2],recip)) | |
2285 return chat; | |
2286 | |
2287 } | |
2288 } | |
2289 return NULL; | |
2290 } | |
8644 | 2291 static const char *zephyr_list_icon(GaimAccount * a, GaimBuddy * b) |
5202 | 2292 { |
2293 return "zephyr"; | |
2294 } | |
2295 | |
9478 | 2296 static int zephyr_send_typing(GaimConnection *gc, const char *who, int typing) { |
2297 gchar *recipient; | |
9896 | 2298 zephyr_account *zephyr = gc->proto_data; |
2299 if (use_tzc(zephyr)) | |
2300 return 0; | |
2301 | |
9478 | 2302 if (!typing) |
2303 return 0; | |
2304 /* XXX We probably should care if this fails. Or maybe we don't want to */ | |
2305 if (!who) { | |
2306 gaim_debug_info("zephyr", "who is null\n"); | |
9896 | 2307 recipient = local_zephyr_normalize(zephyr,""); |
9478 | 2308 } else { |
9896 | 2309 /* Don't ping broadcast (chat) recipients */ |
2310 /* The strrchr case finds a realm-stripped broadcast subscription | |
2311 e.g. comma is the last character in the string */ | |
2312 if ((strrchr(who, ',') && ((strrchr(who, ',') == (who+strlen(who)-1)) || ((char *)(strrchr(who, ',')[1] == '@'))))) | |
2313 return 0; | |
2314 | |
2315 recipient = local_zephyr_normalize(zephyr,who); | |
9478 | 2316 } |
2317 | |
9896 | 2318 gaim_debug_info("zephyr","about to send typing notification to %s\n",recipient); |
2319 zephyr_send_message(zephyr,"MESSAGE","PERSONAL",recipient,"","","PING"); | |
2320 gaim_debug_info("zephyr","sent typing notification\n"); | |
9478 | 2321 return ZEPHYR_TYPING_SEND_TIMEOUT; |
2322 } | |
8212 | 2323 |
9434 | 2324 |
2325 | |
8644 | 2326 static void zephyr_chat_set_topic(GaimConnection * gc, int id, const char *topic) |
2327 { | |
2328 zephyr_triple *zt; | |
2329 GaimConversation *gconv; | |
2330 GaimConvChat *gcc; | |
9896 | 2331 gchar *topic_utf8; |
2332 zephyr_account* zephyr = gc->proto_data; | |
2333 char *sender = (char *)zephyr->username; | |
8212 | 2334 |
9610 | 2335 zt = find_sub_by_id(gc->proto_data,id); |
9911 | 2336 /* find_sub_by_id can return NULL */ |
2337 if (!zt) | |
2338 return; | |
9610 | 2339 gconv = gaim_find_conversation_with_account(zt->name, gc->account); |
8644 | 2340 gcc = gaim_conversation_get_chat_data(gconv); |
9434 | 2341 |
9896 | 2342 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic,strlen(topic)); |
2343 gaim_conv_chat_set_topic(gcc,sender,topic_utf8); | |
2344 g_free(topic_utf8); | |
2345 return; | |
9434 | 2346 } |
2347 | |
2348 /* commands */ | |
2349 | |
2350 static GaimCmdRet zephyr_gaim_cmd_msg(GaimConversation *conv, | |
9896 | 2351 const char *cmd, char **args, char **error, void *data) |
9434 | 2352 { |
9896 | 2353 char *recipient; |
2354 zephyr_account *zephyr = gaim_conversation_get_gc(conv)->proto_data; | |
2355 if (!g_ascii_strcasecmp(args[0],"*")) | |
2356 return GAIM_CMD_RET_FAILED; /* "*" is not a valid argument */ | |
2357 else | |
2358 recipient = local_zephyr_normalize(zephyr,args[0]); | |
9434 | 2359 |
9896 | 2360 if (strlen(recipient) < 1) |
2361 return GAIM_CMD_RET_FAILED; /* a null recipient is a chat message, not an IM */ | |
9478 | 2362 |
9896 | 2363 if (zephyr_send_message(zephyr,"MESSAGE","PERSONAL",recipient,args[1],zephyr_get_signature(),"")) |
2364 return GAIM_CMD_RET_OK; | |
2365 else | |
2366 return GAIM_CMD_RET_FAILED; | |
9434 | 2367 } |
2368 | |
2369 static GaimCmdRet zephyr_gaim_cmd_zlocate(GaimConversation *conv, | |
9896 | 2370 const char *cmd, char **args, char **error, void *data) |
9434 | 2371 { |
9896 | 2372 zephyr_zloc(gaim_conversation_get_gc(conv),args[0]); |
2373 return GAIM_CMD_RET_OK; | |
9434 | 2374 } |
2375 | |
2376 static GaimCmdRet zephyr_gaim_cmd_instance(GaimConversation *conv, | |
9896 | 2377 const char *cmd, char **args, char **error, void *data) |
9434 | 2378 { |
9896 | 2379 /* Currently it sets the instance with leading spaces and |
2380 * all. This might not be the best thing to do, though having | |
2381 * one word isn't ideal either. */ | |
9434 | 2382 |
9896 | 2383 GaimConvChat *gcc = gaim_conversation_get_chat_data(conv); |
2384 int id = gcc->id; | |
2385 const char* instance = args[0]; | |
2386 zephyr_chat_set_topic(gaim_conversation_get_gc(conv),id,instance); | |
2387 return GAIM_CMD_RET_OK; | |
9434 | 2388 } |
2389 | |
2390 static GaimCmdRet zephyr_gaim_cmd_joinchat_cir(GaimConversation *conv, | |
9896 | 2391 const char *cmd, char **args, char **error, void *data) |
9434 | 2392 { |
9896 | 2393 /* Join a new zephyr chat */ |
2394 GHashTable *triple = g_hash_table_new(NULL,NULL); | |
2395 g_hash_table_insert(triple,"class",args[0]); | |
2396 g_hash_table_insert(triple,"instance",args[1]); | |
2397 g_hash_table_insert(triple,"recipient",args[2]); | |
2398 zephyr_join_chat(gaim_conversation_get_gc(conv),triple); | |
2399 return GAIM_CMD_RET_OK; | |
9434 | 2400 } |
2401 | |
2402 static GaimCmdRet zephyr_gaim_cmd_zi(GaimConversation *conv, | |
9896 | 2403 const char *cmd, char **args, char **error, void *data) |
9434 | 2404 { |
9896 | 2405 /* args = instance, message */ |
2406 zephyr_account *zephyr = gaim_conversation_get_gc(conv)->proto_data; | |
2407 if ( zephyr_send_message(zephyr,"message",args[0],"",args[1],zephyr_get_signature(),"")) | |
2408 return GAIM_CMD_RET_OK; | |
2409 else | |
2410 return GAIM_CMD_RET_FAILED; | |
9434 | 2411 } |
2412 | |
2413 static GaimCmdRet zephyr_gaim_cmd_zci(GaimConversation *conv, | |
9896 | 2414 const char *cmd, char **args, char **error, void *data) |
9434 | 2415 { |
9896 | 2416 /* args = class, instance, message */ |
2417 zephyr_account *zephyr = gaim_conversation_get_gc(conv)->proto_data; | |
2418 if ( zephyr_send_message(zephyr,args[0],args[1],"",args[2],zephyr_get_signature(),"")) | |
2419 return GAIM_CMD_RET_OK; | |
2420 else | |
2421 return GAIM_CMD_RET_FAILED; | |
9434 | 2422 } |
8644 | 2423 |
9434 | 2424 static GaimCmdRet zephyr_gaim_cmd_zcir(GaimConversation *conv, |
9896 | 2425 const char *cmd, char **args, char **error, void *data) |
9434 | 2426 { |
9896 | 2427 /* args = class, instance, recipient, message */ |
2428 zephyr_account *zephyr = gaim_conversation_get_gc(conv)->proto_data; | |
2429 if ( zephyr_send_message(zephyr,args[0],args[1],args[2],args[3],zephyr_get_signature(),"")) | |
2430 return GAIM_CMD_RET_OK; | |
2431 else | |
2432 return GAIM_CMD_RET_FAILED; | |
8212 | 2433 } |
2434 | |
9434 | 2435 static GaimCmdRet zephyr_gaim_cmd_zir(GaimConversation *conv, |
9896 | 2436 const char *cmd, char **args, char **error, void *data) |
9434 | 2437 { |
9896 | 2438 /* args = instance, recipient, message */ |
2439 zephyr_account *zephyr = gaim_conversation_get_gc(conv)->proto_data; | |
2440 if ( zephyr_send_message(zephyr,"message",args[0],args[1],args[2],zephyr_get_signature(),"")) | |
2441 return GAIM_CMD_RET_OK; | |
2442 else | |
2443 return GAIM_CMD_RET_FAILED; | |
9434 | 2444 } |
2445 | |
2446 static GaimCmdRet zephyr_gaim_cmd_zc(GaimConversation *conv, | |
9896 | 2447 const char *cmd, char **args, char **error, void *data) |
9434 | 2448 { |
9896 | 2449 /* args = class, message */ |
2450 zephyr_account *zephyr = gaim_conversation_get_gc(conv)->proto_data; | |
2451 if ( zephyr_send_message(zephyr,args[0],"PERSONAL","",args[1],zephyr_get_signature(),"")) | |
2452 return GAIM_CMD_RET_OK; | |
2453 else | |
2454 return GAIM_CMD_RET_FAILED; | |
9434 | 2455 } |
2456 | |
9597 | 2457 static void zephyr_register_slash_commands() |
9434 | 2458 { |
2459 | |
9896 | 2460 gaim_cmd_register("msg","ws", GAIM_CMD_P_PRPL, |
2461 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2462 "prpl-zephyr", | |
2463 zephyr_gaim_cmd_msg, _("msg <nick> <message>: Send a private message to a user"), NULL); | |
9434 | 2464 |
9896 | 2465 gaim_cmd_register("zlocate","w", GAIM_CMD_P_PRPL, |
2466 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2467 "prpl-zephyr", | |
2468 zephyr_gaim_cmd_zlocate, _("zlocate <nick>: Locate user"), NULL); | |
9434 | 2469 |
9896 | 2470 gaim_cmd_register("zl","w", GAIM_CMD_P_PRPL, |
2471 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2472 "prpl-zephyr", | |
2473 zephyr_gaim_cmd_zlocate, _("zl <nick>: Locate user"), NULL); | |
9434 | 2474 |
9896 | 2475 gaim_cmd_register("instance","s", GAIM_CMD_P_PRPL, |
2476 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2477 "prpl-zephyr", | |
2478 zephyr_gaim_cmd_instance, _("instance <instance>: Set the instance to be used on this class"), NULL); | |
9434 | 2479 |
9896 | 2480 gaim_cmd_register("inst","s", GAIM_CMD_P_PRPL, |
2481 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2482 "prpl-zephyr", | |
2483 zephyr_gaim_cmd_instance, _("inst <instance>: Set the instance to be used on this class"), NULL); | |
9434 | 2484 |
9896 | 2485 gaim_cmd_register("sub", "www", GAIM_CMD_P_PRPL, |
2486 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2487 "prpl-zephyr", | |
2488 zephyr_gaim_cmd_joinchat_cir, | |
2489 _("sub <class> <instance> <recipient>: Join a new chat"), NULL); | |
9434 | 2490 |
9896 | 2491 gaim_cmd_register("zi","ws", GAIM_CMD_P_PRPL, |
2492 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2493 "prpl-zephyr", | |
2494 zephyr_gaim_cmd_zi, _("zi <instance>: Send a message to <message,<i>instance</i>,*>"), NULL); | |
9434 | 2495 |
9896 | 2496 gaim_cmd_register("zci","wws",GAIM_CMD_P_PRPL, |
2497 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2498 "prpl-zephyr", | |
2499 zephyr_gaim_cmd_zci, | |
2500 _("zci <class> <instance>: Send a message to <<i>class</i>,<i>instance</i>,*>"), NULL); | |
9434 | 2501 |
9896 | 2502 gaim_cmd_register("zcir","wwws",GAIM_CMD_P_PRPL, |
2503 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2504 "prpl-zephyr", | |
2505 zephyr_gaim_cmd_zcir, | |
2506 _("zcir <class> <instance> <recipient>: Send a message to <<i>class</i>,<i>instance</i>,<i>recipient</i>>"), NULL); | |
9434 | 2507 |
9896 | 2508 gaim_cmd_register("zir","wws",GAIM_CMD_P_PRPL, |
2509 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2510 "prpl-zephyr", | |
2511 zephyr_gaim_cmd_zir, | |
2512 _("zir <instance> <recipient>: Send a message to <MESSAGE,<i>instance</i>,<i>recipient</i>>"), NULL); | |
9434 | 2513 |
9896 | 2514 gaim_cmd_register("zc","ws", GAIM_CMD_P_PRPL, |
2515 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
2516 "prpl-zephyr", | |
2517 zephyr_gaim_cmd_zc, _("zc <class>: Send a message to <<i>class</i>,PERSONAL,*>"), NULL); | |
9597 | 2518 |
9434 | 2519 } |
2520 | |
2521 | |
9896 | 2522 static void |
2523 zephyr_add_deny(GaimConnection *gc, const char *who) | |
2524 { | |
2525 gaim_privacy_deny_add(gc->account,who,1); | |
2526 } | |
2527 | |
2528 static void | |
2529 zephyr_remove_deny(GaimConnection *gc, const char *who) | |
2530 { | |
2531 gaim_privacy_deny_remove(gc->account,who,1); | |
2532 } | |
2533 | |
2534 static void | |
2535 zephyr_add_permit(GaimConnection *gc, const char *who) | |
2536 { | |
2537 gaim_privacy_permit_add(gc->account,who,1); | |
2538 } | |
2539 | |
2540 static void | |
2541 zephyr_remove_permit(GaimConnection *gc, const char *who) | |
2542 { | |
2543 gaim_privacy_permit_remove(gc->account,who,1); | |
2544 } | |
2545 | |
2546 static void | |
2547 zephyr_set_permit_deny(GaimConnection *gc) | |
2548 { | |
2549 /* This doesn't have to do anything, since really, we can just check account->perm_deny when deciding whether to di */ | |
2550 return; | |
2551 } | |
9427 | 2552 static int zephyr_resubscribe(GaimConnection *gc) |
2553 { | |
9896 | 2554 /* Resubscribe to the in-memory list of subscriptions and also |
2555 unsubscriptions*/ | |
2556 zephyr_account *zephyr = gc->proto_data; | |
2557 GSList *s = zephyr->subscrips; | |
2558 zephyr_triple *zt; | |
2559 while (s) { | |
2560 zt = s->data; | |
2561 /* XXX We really should care if this fails */ | |
2562 zephyr_subscribe_to(zephyr,zt->class,zt->instance,zt->recipient,NULL); | |
2563 s = s->next; | |
2564 } | |
2565 /* XXX handle unsubscriptions */ | |
2566 return 1; | |
9427 | 2567 } |
2568 | |
9434 | 2569 |
9427 | 2570 static void zephyr_action_resubscribe(GaimPluginAction *action) |
2571 { | |
2572 | |
9896 | 2573 GaimConnection *gc = (GaimConnection *) action->context; |
2574 zephyr_resubscribe(gc); | |
9427 | 2575 } |
2576 | |
2577 | |
9478 | 2578 static void zephyr_action_get_subs_from_server(GaimPluginAction *action) |
2579 { | |
2580 GaimConnection *gc = (GaimConnection *) action->context; | |
9896 | 2581 zephyr_account *zephyr = gc->proto_data; |
9478 | 2582 gchar *title; |
2583 int retval, nsubs, one,i; | |
2584 ZSubscription_t subs; | |
9896 | 2585 if (use_zeph02(zephyr)) { |
2586 GString* subout = g_string_new("Subscription list<br>"); | |
2587 | |
2588 title = g_strdup_printf("Server subscriptions for %s", zephyr->username); | |
2589 | |
2590 if (zephyr->port == 0) { | |
2591 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving port"); | |
2592 return; | |
2593 } | |
2594 if ((retval = ZRetrieveSubscriptions(zephyr->port,&nsubs)) != ZERR_NONE) { | |
9478 | 2595 /* XXX better error handling */ |
9896 | 2596 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving subscriptions from server"); |
9478 | 2597 return; |
2598 } | |
9896 | 2599 for(i=0;i<nsubs;i++) { |
2600 one = 1; | |
2601 if ((retval = ZGetSubscriptions(&subs,&one)) != ZERR_NONE) { | |
2602 /* XXX better error handling */ | |
2603 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving individual subscription"); | |
2604 return; | |
2605 } | |
2606 g_string_append_printf(subout, "Class %s Instance %s Recipient %s<br>", | |
2607 subs.zsub_class, subs.zsub_classinst, | |
2608 subs.zsub_recipient); | |
2609 } | |
2610 gaim_notify_formatted(gc, title, title, NULL, subout->str, NULL, NULL); | |
2611 } else { | |
2612 /* XXX fix */ | |
2613 gaim_notify_error(gc,"","tzc doesn't support this action",NULL); | |
9478 | 2614 } |
2615 } | |
2616 | |
2617 | |
9427 | 2618 static GList *zephyr_actions(GaimPlugin *plugin, gpointer context) |
2619 { | |
2620 GList *list = NULL; | |
2621 GaimPluginAction *act = NULL; | |
2622 | |
2623 act = gaim_plugin_action_new(_("Resubscribe"), zephyr_action_resubscribe); | |
2624 list = g_list_append(list, act); | |
2625 | |
9478 | 2626 act = gaim_plugin_action_new(_("Retrieve subscriptions from server"), zephyr_action_get_subs_from_server); |
2627 list = g_list_append(list,act); | |
2628 | |
9427 | 2629 return list; |
2630 } | |
2631 | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2632 static GaimPlugin *my_protocol = NULL; |
2086 | 2633 |
8644 | 2634 static GaimPluginProtocolInfo prpl_info = { |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
2635 GAIM_PRPL_API_VERSION, |
8644 | 2636 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD, |
9478 | 2637 NULL, /* ??? user_splits */ |
2638 NULL, /* ??? protocol_options */ | |
2639 NO_BUDDY_ICONS, | |
2640 zephyr_list_icon, | |
2641 NULL, /* ??? list_emblems */ | |
2642 NULL, /* ??? status_text */ | |
2643 NULL, /* ??? tooltip_text */ | |
9475 | 2644 zephyr_away_states, /* away_states */ |
9478 | 2645 NULL, /* ??? blist_node_menu - probably all useful actions are already handled*/ |
9475 | 2646 zephyr_chat_info, /* chat_info */ |
9754 | 2647 NULL, /* chat_info_defaults */ |
9475 | 2648 zephyr_login, /* login */ |
2649 zephyr_close, /* close */ | |
2650 zephyr_send_im, /* send_im */ | |
9478 | 2651 NULL, /* XXX set info (Location?) */ |
2652 zephyr_send_typing, /* send_typing */ | |
9475 | 2653 zephyr_zloc, /* get_info */ |
9478 | 2654 zephyr_set_away, /* XXX set_away need to fix */ |
2655 NULL, /* ??? set idle */ | |
2656 NULL, /* change password */ | |
9475 | 2657 NULL, /* add_buddy */ |
2658 NULL, /* add_buddies */ | |
2659 NULL, /* remove_buddy */ | |
2660 NULL, /* remove_buddies */ | |
9896 | 2661 zephyr_add_permit, /* add_permit */ |
2662 zephyr_add_deny, /* add_deny */ | |
2663 zephyr_remove_permit, /* remove_permit */ | |
2664 zephyr_remove_deny, /* remove_deny */ | |
2665 zephyr_set_permit_deny, /* set_permit_deny */ | |
2666 NULL, /* warn -- not supported in zephyr */ | |
2667 zephyr_join_chat, /* join_chat */ | |
2668 NULL, /* reject_chat -- No chat invites*/ | |
2669 NULL, /* chat_invite -- No chat invites*/ | |
2670 zephyr_chat_leave, /* chat_leave */ | |
2671 NULL, /* chat_whisper -- No "whispering"*/ | |
2672 zephyr_chat_send, /* chat_send */ | |
2673 NULL, /* keepalive -- Not necessary*/ | |
2674 NULL, /* register_user -- Not supported*/ | |
2675 NULL, /* XXX get_cb_info */ | |
9475 | 2676 NULL, /* get_cb_away */ |
2677 NULL, /* alias_buddy */ | |
2678 NULL, /* group_buddy */ | |
2679 NULL, /* rename_group */ | |
9896 | 2680 NULL, /* buddy_free */ |
9475 | 2681 NULL, /* convo_closed */ |
9896 | 2682 zephyr_normalize, /* normalize */ |
2683 NULL, /* XXX set_buddy_icon */ | |
9475 | 2684 NULL, /* remove_group */ |
9896 | 2685 NULL, /* XXX get_cb_real_name */ |
2686 zephyr_chat_set_topic, /* set_chat_topic */ | |
2687 zephyr_find_blist_chat, /* find_blist_chat */ | |
9475 | 2688 NULL, /* roomlist_get_list */ |
2689 NULL, /* roomlist_cancel */ | |
9896 | 2690 NULL, /* roomlist_expand_category */ |
9475 | 2691 NULL, /* can_receive_file */ |
2692 NULL /* send_file */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2693 }; |
2086 | 2694 |
8644 | 2695 static GaimPluginInfo info = { |
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
2696 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
9896 | 2697 GAIM_PLUGIN_PROTOCOL, /**< type */ |
8644 | 2698 NULL, /**< ui_requirement */ |
9896 | 2699 0, /**< flags */ |
8644 | 2700 NULL, /**< dependencies */ |
9896 | 2701 GAIM_PRIORITY_DEFAULT, /**< priority */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2702 |
9896 | 2703 "prpl-zephyr", /**< id */ |
2704 "Zephyr", /**< name */ | |
2705 VERSION, /**< version */ | |
2706 /** summary */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2707 N_("Zephyr Protocol Plugin"), |
9896 | 2708 /** description */ |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2709 N_("Zephyr Protocol Plugin"), |
9896 | 2710 NULL, /**< author */ |
2711 GAIM_WEBSITE, /**< homepage */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2712 |
9896 | 2713 NULL, /**< load */ |
2714 NULL, /**< unload */ | |
2715 NULL, /**< destroy */ | |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2716 |
9896 | 2717 NULL, /**< ui_info */ |
8993 | 2718 &prpl_info, /**< extra_info */ |
2719 NULL, | |
9427 | 2720 zephyr_actions |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2721 }; |
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2722 |
8644 | 2723 static void init_plugin(GaimPlugin * plugin) |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2724 { |
8212 | 2725 GaimAccountOption *option; |
8644 | 2726 char *tmp = get_exposure_level(); |
2727 | |
9896 | 2728 option = gaim_account_option_bool_new("Use tzc", "use_tzc", FALSE); |
2729 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
2730 | |
2731 option = gaim_account_option_string_new("tzc command", "tzc_command", "/usr/bin/tzc -e %s"); | |
2732 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
2733 | |
8644 | 2734 option = gaim_account_option_bool_new(_("Export to .anyone"), "write_anyone", FALSE); |
2735 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8212 | 2736 |
8644 | 2737 option = gaim_account_option_bool_new(_("Export to .zephyr.subs"), "write_zsubs", FALSE); |
2738 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8212 | 2739 |
8644 | 2740 option = gaim_account_option_string_new(_("Exposure"), "exposure_level", tmp ? tmp : EXPOSE_REALMVIS); |
2741 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8212 | 2742 |
8644 | 2743 option = gaim_account_option_string_new(_("Encoding"), "encoding", ZEPHYR_FALLBACK_CHARSET); |
2744 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
8560 | 2745 |
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
2746 my_protocol = plugin; |
9896 | 2747 zephyr_register_slash_commands(); |
2086 | 2748 } |
2749 | |
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
2750 GAIM_INIT_PLUGIN(zephyr, init_plugin, info); |