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