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