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