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