Sat, 20 Mar 2004 23:46:22 +0000
[gaim-migrate @ 9210]
read and write a size_t, which should work regardless of platform
| 2086 | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*- */ |
| 2 | /* | |
| 3 | * gaim | |
| 4 | * | |
| 5 | * Copyright (C) 1998-2001, Mark Spencer <markster@marko.net> | |
| 6 | * Some code borrowed from GtkZephyr, by | |
|
7084
da83f7ead5c6
[gaim-migrate @ 7649]
Christian Hammond <chipx86@chipx86.com>
parents:
7070
diff
changeset
|
7 | * Jag/Sean Dilda <agrajag@linuxpower.org>/<smdilda@unity.ncsu.edu> |
|
da83f7ead5c6
[gaim-migrate @ 7649]
Christian Hammond <chipx86@chipx86.com>
parents:
7070
diff
changeset
|
8 | * http://gtkzephyr.linuxpower.org/ |
| 2086 | 9 | * |
| 10 | * This program is free software; you can redistribute it and/or modify | |
| 11 | * it under the terms of the GNU General Public License as published by | |
| 12 | * the Free Software Foundation; either version 2 of the License, or | |
| 13 | * (at your option) any later version. | |
| 14 | * | |
| 15 | * This program is distributed in the hope that it will be useful, | |
| 16 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 17 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
| 18 | * GNU General Public License for more details. | |
| 19 | * | |
| 20 | * You should have received a copy of the GNU General Public License | |
| 21 | * along with this program; if not, write to the Free Software | |
| 22 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
| 23 | * | |
| 24 | */ | |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
25 | /* XXX eww */ |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
26 | #include "src/internal.h" |
| 2086 | 27 | |
| 8212 | 28 | #include "accountopt.h" |
|
5872
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 | #include "debug.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
30 | #include "multi.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
31 | #include "notify.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
32 | #include "prpl.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
33 | #include "server.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
34 | #include "util.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
35 | |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
36 | #include "zephyr/zephyr.h" |
|
754c63f29b77
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
37 | |
|
8386
5b9e02f4c03d
[gaim-migrate @ 9114]
Mark Doliner <markdoliner@pidgin.im>
parents:
8354
diff
changeset
|
38 | #include <strings.h> |
|
5b9e02f4c03d
[gaim-migrate @ 9114]
Mark Doliner <markdoliner@pidgin.im>
parents:
8354
diff
changeset
|
39 | |
| 2086 | 40 | extern Code_t ZGetLocations(ZLocations_t *, int *); |
| 41 | extern Code_t ZSetLocation(char *); | |
| 42 | extern Code_t ZUnsetLocation(); | |
| 43 | ||
| 44 | typedef struct _zframe zframe; | |
| 45 | typedef struct _zephyr_triple zephyr_triple; | |
| 46 | ||
| 47 | /* struct I need for zephyr_to_html */ | |
| 48 | struct _zframe { | |
| 49 | /* true for everything but @color, since inside the parens of that one is | |
| 50 | * the color. */ | |
| 51 | gboolean has_closer; | |
| 52 | /* </i>, </font>, </b>, etc. */ | |
| 53 | char *closing; | |
| 54 | /* text including the opening html thingie. */ | |
| 55 | GString *text; | |
| 56 | struct _zframe *enclosing; | |
| 57 | }; | |
| 58 | ||
| 59 | struct _zephyr_triple { | |
| 60 | char *class; | |
| 61 | char *instance; | |
| 62 | char *recipient; | |
| 63 | char *name; | |
| 64 | gboolean open; | |
| 65 | int id; | |
| 66 | }; | |
| 67 | ||
| 68 | #define z_call(func) if (func != ZERR_NONE)\ | |
| 69 | return; | |
| 70 | #define z_call_r(func) if (func != ZERR_NONE)\ | |
| 71 | return TRUE; | |
| 72 | #define z_call_s(func, err) if (func != ZERR_NONE) {\ | |
| 5606 | 73 | gaim_connection_error(zgc, err);\ |
| 2086 | 74 | return;\ |
| 75 | } | |
| 76 | ||
| 8354 | 77 | static const char *local_zephyr_normalize(const char *); |
| 7322 | 78 | static const char *zephyr_normalize(const GaimAccount *, const char *); |
| 2086 | 79 | |
| 80 | /* this is so bad, and if Zephyr weren't so fucked up to begin with I | |
| 81 | * wouldn't do this. but it is so i will. */ | |
| 82 | static guint32 nottimer = 0; | |
| 83 | static guint32 loctimer = 0; | |
| 5606 | 84 | GaimConnection *zgc = NULL; |
| 2086 | 85 | static GList *pending_zloc_names = NULL; |
| 86 | static GSList *subscrips = NULL; | |
| 87 | static int last_id = 0; | |
| 88 | ||
| 89 | /* just for debugging | |
| 90 | static void handle_unknown(ZNotice_t notice) | |
| 91 | { | |
|
6484
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
92 | gaim_debug(GAIM_DEBUG_MISC, "z_packet: %s\n", notice.z_packet); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
93 | gaim_debug(GAIM_DEBUG_MISC, "z_version: %s\n", notice.z_version); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
94 | gaim_debug(GAIM_DEBUG_MISC, "z_kind: %d\n", notice.z_kind); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
95 | gaim_debug(GAIM_DEBUG_MISC, "z_class: %s\n", notice.z_class); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
96 | gaim_debug(GAIM_DEBUG_MISC, "z_class_inst: %s\n", notice.z_class_inst); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
97 | gaim_debug(GAIM_DEBUG_MISC, "z_opcode: %s\n", notice.z_opcode); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
98 | gaim_debug(GAIM_DEBUG_MISC, "z_sender: %s\n", notice.z_sender); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
99 | gaim_debug(GAIM_DEBUG_MISC, "z_recipient: %s\n", notice.z_recipient); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
100 | gaim_debug(GAIM_DEBUG_MISC, "z_message: %s\n", notice.z_message); |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
101 | gaim_debug(GAIM_DEBUG_MISC, "z_message_len: %d\n", notice.z_message_len); |
| 2086 | 102 | } |
| 103 | */ | |
| 104 | ||
| 105 | static zephyr_triple *new_triple(const char *c, const char *i, const char *r) | |
| 106 | { | |
| 107 | zephyr_triple *zt; | |
| 108 | zt = g_new0(zephyr_triple, 1); | |
| 109 | zt->class = g_strdup(c); | |
| 110 | zt->instance = g_strdup(i); | |
| 111 | zt->recipient = g_strdup(r); | |
| 112 | zt->name = g_strdup_printf("%s,%s,%s", c, i, r); | |
| 113 | zt->id = ++last_id; | |
| 114 | zt->open = FALSE; | |
| 115 | return zt; | |
| 116 | } | |
| 117 | ||
| 118 | static void free_triple(zephyr_triple *zt) | |
| 119 | { | |
| 120 | g_free(zt->class); | |
| 121 | g_free(zt->instance); | |
| 122 | g_free(zt->recipient); | |
| 123 | g_free(zt->name); | |
| 124 | g_free(zt); | |
| 125 | } | |
| 126 | ||
| 8354 | 127 | static const char* gaim_zephyr_get_sender() { |
| 128 | /* will be useful once this plugin can use a backend other | |
| 129 | than libzephyr */ | |
| 130 | return ZGetSender(); | |
| 131 | } | |
| 132 | ||
| 133 | static const char* gaim_zephyr_get_realm() { | |
| 134 | /* will be useful once this plugin can use a backend other | |
| 135 | than libzephyr */ | |
| 136 | return ZGetRealm(); | |
| 137 | } | |
| 138 | ||
| 2086 | 139 | /* returns true if zt1 is a subset of zt2, i.e. zt2 has the same thing or |
| 140 | * wildcards in each field of zt1. */ | |
| 141 | static gboolean triple_subset(zephyr_triple *zt1, zephyr_triple *zt2) | |
| 142 | { | |
| 4793 | 143 | if (g_ascii_strcasecmp(zt2->class, zt1->class) && |
| 144 | g_ascii_strcasecmp(zt2->class, "*")) { | |
| 2086 | 145 | return FALSE; |
| 146 | } | |
| 4793 | 147 | if (g_ascii_strcasecmp(zt2->instance, zt1->instance) && |
| 148 | g_ascii_strcasecmp(zt2->instance, "*")) { | |
| 2086 | 149 | return FALSE; |
| 150 | } | |
| 4793 | 151 | if (g_ascii_strcasecmp(zt2->recipient, zt1->recipient) && |
| 152 | g_ascii_strcasecmp(zt2->recipient, "*")) { | |
| 2086 | 153 | return FALSE; |
| 154 | } | |
| 155 | return TRUE; | |
| 156 | } | |
| 157 | ||
| 158 | static zephyr_triple *find_sub_by_triple(zephyr_triple *zt) | |
| 159 | { | |
| 160 | zephyr_triple *curr_t; | |
| 161 | GSList *curr = subscrips; | |
| 162 | while (curr) { | |
| 163 | curr_t = curr->data; | |
| 164 | if (triple_subset(zt, curr_t)) | |
| 165 | return curr_t; | |
| 166 | curr = curr->next; | |
| 167 | } | |
| 168 | return NULL; | |
| 169 | } | |
| 170 | ||
| 171 | static zephyr_triple *find_sub_by_id(int id) | |
| 172 | { | |
| 173 | zephyr_triple *zt; | |
| 174 | GSList *curr = subscrips; | |
| 175 | while (curr) { | |
| 176 | zt = curr->data; | |
| 177 | if (zt->id == id) | |
| 178 | return zt; | |
| 179 | curr = curr->next; | |
| 180 | } | |
| 181 | return NULL; | |
| 182 | } | |
| 183 | ||
| 184 | /* utility macros that are useful for zephyr_to_html */ | |
| 185 | ||
| 186 | #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) | |
| 187 | #define IS_CLOSER(c) ((c == '}') || (c == ']') || (c == ')') || (c == '>')) | |
| 188 | ||
| 8451 | 189 | /* This parses HTML formatting (put out by one of the gtkimhtml widgets |
| 190 | And converts it to zephyr formatting. | |
| 191 | It currently deals properly with <b>, <br>, <i>, <font face=...>, <font color=...>, | |
| 192 | It ignores <font back=...> | |
| 193 | It does | |
| 194 | <font size = "1 or 2" -> @small | |
| 195 | 3 or 4 @medium() | |
| 196 | 5,6, or 7 @large() | |
| 197 | <a href is dealt with by ignoring the description and outputting the link | |
| 198 | */ | |
| 199 | ||
| 200 | static char *html_to_zephyr(const char *message) | |
| 201 | { | |
| 202 | int len,cnt,retcount; | |
| 203 | char *ret; | |
| 204 | len = strlen(message); | |
| 205 | ret = g_new0(char,len*3); | |
| 206 | bzero(ret,len*3); | |
| 207 | retcount=0; | |
| 208 | cnt = 0; | |
| 209 | while (cnt <= len) { | |
| 210 | if (message[cnt] == '<') { | |
| 211 | if (!g_ascii_strncasecmp(message+cnt+1,"i>",2)) { | |
| 212 | strncpy(ret+retcount,"@i(",3); | |
| 213 | cnt+=3; | |
| 214 | retcount+=3; | |
| 215 | } | |
| 216 | else if (!g_ascii_strncasecmp(message+cnt+1,"b>",2)) { | |
| 217 | strncpy(ret+retcount,"@b(",3); | |
| 218 | cnt+=3; | |
| 219 | retcount+=3; | |
| 220 | } | |
| 221 | else if (!g_ascii_strncasecmp(message+cnt+1,"br>",3)) { | |
| 222 | strncpy(ret+retcount,"\n",1); | |
| 223 | cnt+=4; | |
| 224 | retcount+=1; | |
| 225 | } | |
| 226 | else if (!g_ascii_strncasecmp(message+cnt+1,"a href=\"",8)) { | |
| 227 | cnt+=9; | |
| 228 | while(g_ascii_strncasecmp(message+cnt,"\">",2) !=0) { | |
| 229 | ret[retcount]=message[cnt]; | |
| 230 | retcount++; cnt++; | |
| 231 | } | |
| 232 | cnt+=2; | |
| 233 | /* ignore descriptive string */ | |
| 234 | while(g_ascii_strncasecmp(message+cnt,"</a>",4) !=0) { | |
| 235 | cnt++; | |
| 236 | } | |
| 237 | cnt+=4; | |
| 238 | } | |
| 239 | else if (!g_ascii_strncasecmp(message+cnt+1, "font",4)) { | |
| 240 | cnt+=5; | |
| 241 | while(!g_ascii_strncasecmp(message+cnt," ",1)) cnt++; | |
| 242 | if (!g_ascii_strncasecmp(message+cnt,"color=\"",7)) { | |
| 243 | cnt+=7; | |
| 244 | strncpy(ret+retcount,"@color(",7); | |
| 245 | retcount+=7; | |
| 246 | while(g_ascii_strncasecmp(message+cnt,"\">",2) !=0) { | |
| 247 | ret[retcount] = message[cnt]; | |
| 248 | retcount++; | |
| 249 | cnt++; | |
| 250 | } | |
| 251 | ret[retcount]=')'; | |
| 252 | retcount++; | |
| 253 | cnt+=2; | |
| 254 | } | |
| 255 | else if (!g_ascii_strncasecmp(message+cnt,"face=\"",6)) { | |
| 256 | cnt+=6; | |
| 257 | strncpy(ret+retcount,"@font(",6); | |
| 258 | retcount+=6; | |
| 259 | while(g_ascii_strncasecmp(message+cnt,"\">",2) !=0) { | |
| 260 | ret[retcount] = message[cnt]; | |
| 261 | retcount++; | |
| 262 | cnt++; | |
| 263 | } | |
| 264 | ret[retcount]=')'; | |
| 265 | retcount++; | |
| 266 | cnt+=2; | |
| 267 | } | |
| 268 | else if (!g_ascii_strncasecmp(message+cnt,"size=\"",6)) { | |
| 269 | cnt+=6; | |
| 270 | if ( (message[cnt] == '1')|| (message[cnt] == '2')) { | |
| 271 | strncpy(ret+retcount,"@small(",7); | |
| 272 | retcount+=7; | |
| 273 | } | |
| 274 | else if ( (message[cnt] == '3')|| (message[cnt] == '4')) { | |
| 275 | strncpy(ret+retcount,"@medium(",8); | |
| 276 | retcount+=8; | |
| 277 | } | |
| 278 | else if ( (message[cnt] == '5')|| (message[cnt] == '6') || (message[cnt] == '7')) { | |
| 279 | strncpy(ret+retcount,"@large(",7); | |
| 280 | retcount+=7; | |
| 281 | } | |
| 282 | cnt+=3; | |
| 283 | } | |
| 284 | else { | |
| 285 | /* Drop all unrecognized/misparsed font tags */ | |
| 286 | while(g_ascii_strncasecmp(message+cnt,"\">",2) !=0) { | |
| 287 | cnt++; | |
| 288 | } | |
| 289 | cnt+=2; | |
| 290 | } | |
| 291 | } | |
| 292 | else if (!g_ascii_strncasecmp(message+cnt+1,"/i>",3) || !g_ascii_strncasecmp(message+cnt+1,"/b>",3)) { | |
| 293 | cnt+=4; | |
| 294 | ret[retcount]=')'; | |
| 295 | retcount++; | |
| 296 | } | |
| 297 | else if (!g_ascii_strncasecmp(message+cnt+1,"/font>",6)) { | |
| 298 | cnt+=7; | |
| 299 | strncpy(ret+retcount,"@font(fixed)",12); | |
| 300 | retcount+=12; | |
| 301 | } | |
| 302 | else { | |
| 303 | /* Catch all for all unrecognized/misparsed <foo> tage */ | |
| 304 | while(g_ascii_strncasecmp(message+cnt,">",1) != 0) { | |
| 305 | ret[retcount]=message[cnt]; | |
| 306 | retcount++; | |
| 307 | cnt++; | |
| 308 | } | |
| 309 | } | |
| 310 | } else { | |
| 311 | /* Duh */ | |
| 312 | ret[retcount]=message[cnt]; | |
| 313 | retcount++; | |
| 314 | cnt++; | |
| 315 | } | |
| 316 | } | |
| 317 | return ret; | |
| 318 | } | |
| 319 | ||
| 2086 | 320 | /* this parses zephyr formatting and converts it to html. For example, if |
| 321 | * you pass in "@{@color(blue)@i(hello)}" you should get out | |
| 322 | * "<font color=blue><i>hello</i></font>". */ | |
| 323 | static char *zephyr_to_html(char *message) | |
| 324 | { | |
| 325 | int len, cnt; | |
| 326 | zframe *frames, *curr; | |
| 327 | char *ret; | |
| 328 | ||
| 329 | frames = g_new(zframe, 1); | |
| 330 | frames->text = g_string_new(""); | |
| 331 | frames->enclosing = NULL; | |
| 332 | frames->closing = ""; | |
| 333 | frames->has_closer = FALSE; | |
| 334 | ||
| 335 | len = strlen(message); | |
| 336 | cnt = 0; | |
| 337 | while (cnt <= len) { | |
| 338 | if (message[cnt] == '@') { | |
| 339 | zframe *new_f; | |
| 340 | char *buf; | |
| 341 | int end; | |
| 342 | for (end=1; (cnt+end) <= len && | |
| 7070 | 343 | !IS_OPENER(message[cnt+end]) && !IS_CLOSER(message[cnt+end]); end++); |
| 2086 | 344 | buf = g_new0(char, end); |
| 345 | if (end) { | |
| 346 | g_snprintf(buf, end, "%s", message+cnt+1); | |
| 347 | } | |
| 4793 | 348 | if (!g_ascii_strcasecmp(buf, "italic") || |
| 349 | !g_ascii_strcasecmp(buf, "i")) { | |
| 2086 | 350 | new_f = g_new(zframe, 1); |
| 351 | new_f->enclosing = frames; | |
| 352 | new_f->text = g_string_new("<i>"); | |
| 353 | new_f->closing = "</i>"; | |
| 354 | new_f->has_closer = TRUE; | |
| 355 | frames = new_f; | |
| 356 | cnt += end+1; /* cnt points to char after opener */ | |
| 8212 | 357 | } else if (!g_ascii_strcasecmp(buf,"small")) { |
| 358 | new_f = g_new(zframe,1); | |
| 359 | new_f->enclosing = frames; | |
| 360 | new_f->text = g_string_new("<font size=\"1\">"); | |
| 361 | new_f->closing ="</font>"; | |
| 362 | frames = new_f; | |
| 363 | cnt+= end+1; | |
| 8451 | 364 | } else if (!g_ascii_strcasecmp(buf,"medium")) { |
| 8212 | 365 | new_f = g_new(zframe,1); |
| 366 | new_f->enclosing = frames; | |
| 367 | new_f->text = g_string_new("<font size=\"3\">"); | |
| 368 | new_f->closing ="</font>"; | |
| 369 | frames = new_f; | |
| 370 | cnt+= end+1; | |
| 371 | } else if (!g_ascii_strcasecmp(buf,"large")) { | |
| 372 | new_f = g_new(zframe,1); | |
| 373 | new_f->enclosing = frames; | |
| 8451 | 374 | new_f->text = g_string_new("<font size=\"7\">"); |
| 8212 | 375 | new_f->closing ="</font>"; |
| 376 | frames = new_f; | |
| 377 | cnt+= end+1; | |
| 378 | } else if (!g_ascii_strcasecmp(buf, "bold") | |
| 379 | || !g_ascii_strcasecmp(buf, "b")) { | |
| 2086 | 380 | new_f = g_new(zframe, 1); |
| 381 | new_f->enclosing = frames; | |
| 382 | new_f->text = g_string_new("<b>"); | |
| 383 | new_f->closing = "</b>"; | |
| 384 | new_f->has_closer = TRUE; | |
| 385 | frames = new_f; | |
| 386 | cnt += end+1; | |
| 8451 | 387 | } else if (!g_ascii_strcasecmp(buf, "font")) { |
| 388 | cnt += end+1; | |
| 389 | new_f = g_new(zframe, 1); | |
| 390 | new_f->enclosing = frames; | |
| 391 | new_f->text = g_string_new("<font face="); | |
| 392 | for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
| 393 | g_string_append_c(new_f->text, message[cnt]); | |
| 394 | } | |
| 395 | cnt++; /* point to char after closer */ | |
| 396 | g_string_append_c(new_f->text, '>'); | |
| 397 | new_f->closing = "</font>"; | |
| 398 | new_f->has_closer = FALSE; | |
| 399 | frames = new_f; | |
| 400 | ||
| 401 | } else if (!g_ascii_strcasecmp(buf, "color")) { | |
| 2086 | 402 | cnt += end+1; |
| 403 | new_f = g_new(zframe, 1); | |
| 404 | new_f->enclosing = frames; | |
| 405 | new_f->text = g_string_new("<font color="); | |
| 406 | for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
| 407 | g_string_append_c(new_f->text, message[cnt]); | |
| 408 | } | |
| 409 | cnt++; /* point to char after closer */ | |
| 410 | g_string_append_c(new_f->text, '>'); | |
| 411 | new_f->closing = "</font>"; | |
| 412 | new_f->has_closer = FALSE; | |
| 413 | frames = new_f; | |
| 4793 | 414 | } else if (!g_ascii_strcasecmp(buf, "")) { |
| 2086 | 415 | new_f = g_new(zframe, 1); |
| 416 | new_f->enclosing = frames; | |
| 417 | new_f->text = g_string_new(""); | |
| 418 | new_f->closing = ""; | |
| 419 | new_f->has_closer = TRUE; | |
| 420 | frames = new_f; | |
| 421 | cnt += end+1; /* cnt points to char after opener */ | |
| 422 | } else { | |
| 423 | if ((cnt+end) > len) { | |
| 424 | g_string_append_c(frames->text, '@'); | |
| 425 | cnt++; | |
| 7070 | 426 | } else if (IS_CLOSER(message[cnt+end])) { |
| 427 | /* We have @chars..closer . This is | |
| 428 | merely a sequence of chars that isn't a formatting tag | |
| 429 | */ | |
| 430 | int tmp=cnt; | |
| 431 | while (tmp<=cnt+end) { | |
| 432 | g_string_append_c(frames->text,message[tmp]); | |
| 433 | tmp++; | |
| 434 | } | |
| 435 | cnt+=end+1; | |
| 436 | } else { | |
| 2086 | 437 | /* unrecognized thingie. act like it's not there, but we |
| 438 | * still need to take care of the corresponding closer, | |
| 439 | * make a frame that does nothing. */ | |
| 440 | new_f = g_new(zframe, 1); | |
| 441 | new_f->enclosing = frames; | |
| 442 | new_f->text = g_string_new(""); | |
| 443 | new_f->closing = ""; | |
| 444 | new_f->has_closer = TRUE; | |
| 445 | frames = new_f; | |
| 446 | cnt += end+1; /* cnt points to char after opener */ | |
| 447 | } | |
| 448 | } | |
| 449 | } else if (IS_CLOSER(message[cnt])) { | |
| 450 | zframe *popped; | |
| 451 | gboolean last_had_closer; | |
| 452 | if (frames->enclosing) { | |
| 453 | do { | |
| 454 | popped = frames; | |
| 455 | frames = frames->enclosing; | |
| 456 | g_string_append(frames->text, popped->text->str); | |
| 457 | g_string_append(frames->text, popped->closing); | |
| 458 | g_string_free(popped->text, TRUE); | |
| 459 | last_had_closer = popped->has_closer; | |
| 460 | g_free(popped); | |
| 461 | } while (frames && frames->enclosing && !last_had_closer); | |
| 462 | } else { | |
| 463 | g_string_append_c(frames->text, message[cnt]); | |
| 464 | } | |
| 465 | cnt++; | |
| 466 | } else if (message[cnt] == '\n') { | |
| 467 | g_string_append(frames->text, "<br>"); | |
| 468 | cnt++; | |
| 469 | } else { | |
| 470 | g_string_append_c(frames->text, message[cnt++]); | |
| 471 | } | |
| 472 | } | |
| 473 | /* go through all the stuff that they didn't close */ | |
| 474 | while (frames->enclosing) { | |
| 475 | curr = frames; | |
| 476 | g_string_append(frames->enclosing->text, frames->text->str); | |
| 477 | g_string_append(frames->enclosing->text, frames->closing); | |
| 478 | g_string_free(frames->text, TRUE); | |
| 479 | frames = frames->enclosing; | |
| 480 | g_free(curr); | |
| 481 | } | |
| 482 | ret = frames->text->str; | |
| 483 | g_string_free(frames->text, FALSE); | |
| 484 | g_free(frames); | |
| 485 | return ret; | |
| 486 | } | |
| 487 | ||
| 488 | static gboolean pending_zloc(char *who) | |
| 489 | { | |
| 490 | GList *curr; | |
| 491 | for (curr = pending_zloc_names; curr != NULL; curr = curr->next) { | |
| 8354 | 492 | if (!g_ascii_strcasecmp(local_zephyr_normalize(who), (char*)curr->data)) { |
| 2086 | 493 | g_free((char*)curr->data); |
| 494 | pending_zloc_names = g_list_remove(pending_zloc_names, curr->data); | |
| 495 | return TRUE; | |
| 496 | } | |
| 497 | } | |
| 498 | return FALSE; | |
| 499 | } | |
| 500 | ||
| 501 | static void handle_message(ZNotice_t notice, struct sockaddr_in from) | |
| 502 | { | |
| 4793 | 503 | if (!g_ascii_strcasecmp(notice.z_class, LOGIN_CLASS)) { |
| 3277 | 504 | /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */ |
| 4793 | 505 | } else if (!g_ascii_strcasecmp(notice.z_class, LOCATE_CLASS)) { |
| 506 | if (!g_ascii_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
| 2086 | 507 | int nlocs; |
| 508 | char *user; | |
| 6695 | 509 | GaimBuddy *b; |
| 2086 | 510 | |
| 511 | if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) | |
| 512 | return; | |
| 8435 | 513 | |
| 514 | if ((b = gaim_find_buddy(zgc->account, user)) == NULL) { | |
| 2086 | 515 | char *e = strchr(user, '@'); |
| 8435 | 516 | if(e && !g_ascii_strcasecmp(e+1,gaim_zephyr_get_realm()) ) { |
| 517 | *e = '\0'; | |
| 518 | } | |
| 4687 | 519 | b = gaim_find_buddy(zgc->account, user); |
| 8435 | 520 | } |
| 521 | if ((b && pending_zloc(b->name)) || pending_zloc(user) ) { | |
| 2086 | 522 | ZLocations_t locs; |
| 523 | int one = 1; | |
| 524 | GString *str = g_string_new(""); | |
| 8435 | 525 | g_string_append_printf(str, _("<b>User:</b> %s<br>"), b?b->name:user); |
| 526 | if (b && b->alias) | |
|
5132
9b087ef3f525
[gaim-migrate @ 5495]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
527 | g_string_append_printf(str, _("<b>Alias:</b> %s<br>"), b->alias); |
| 2086 | 528 | if (!nlocs) { |
|
5132
9b087ef3f525
[gaim-migrate @ 5495]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
529 | g_string_append_printf(str, _("<br>Hidden or not logged-in")); |
| 2086 | 530 | } |
| 531 | for (; nlocs > 0; nlocs--) { | |
| 532 | ZGetLocations(&locs, &one); | |
|
5132
9b087ef3f525
[gaim-migrate @ 5495]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
533 | g_string_append_printf(str, _("<br>At %s since %s"), locs.host, |
| 2086 | 534 | locs.time); |
| 535 | } | |
|
7062
26abb8b189ce
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
536 | gaim_notify_formatted(zgc, NULL, _("Buddy Information"), |
|
26abb8b189ce
[gaim-migrate @ 7626]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
537 | NULL, str->str, NULL, NULL); |
| 2086 | 538 | g_string_free(str, TRUE); |
| 539 | } else | |
| 4732 | 540 | serv_got_update(zgc, b->name, nlocs, 0, 0, 0, 0); |
| 2086 | 541 | |
| 542 | free(user); | |
| 543 | } | |
| 544 | } else { | |
| 545 | char *buf, *buf2; | |
| 2804 | 546 | char *send_inst; |
| 3277 | 547 | char *realmptr; |
| 8212 | 548 | GaimConversation *gconv1; |
| 549 | GaimConvChat *gcc; | |
| 2086 | 550 | char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
|
7475
987384816492
[gaim-migrate @ 8088]
Mark Doliner <markdoliner@pidgin.im>
parents:
7322
diff
changeset
|
551 | int len = notice.z_message_len - ((int)ptr - (int)notice.z_message); |
| 8354 | 552 | char *sendertmp = g_strdup_printf("%s",gaim_zephyr_get_sender()); |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
553 | GaimConvImFlags flags = 0; |
| 2086 | 554 | if (len > 0) { |
| 8449 | 555 | gchar* tmpescape; |
| 2086 | 556 | buf = g_malloc(len + 1); |
| 557 | g_snprintf(buf, len + 1, "%s", ptr); | |
| 558 | g_strchomp(buf); | |
| 8449 | 559 | tmpescape = gaim_escape_html(buf); |
| 560 | buf2 = zephyr_to_html(tmpescape); | |
| 2086 | 561 | g_free(buf); |
| 8449 | 562 | g_free(tmpescape); |
| 4793 | 563 | if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && |
| 564 | !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL")) { | |
| 565 | if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
566 | flags |= GAIM_CONV_IM_AUTO_RESP; |
|
6982
12f08de92674
[gaim-migrate @ 7538]
Mark Doliner <markdoliner@pidgin.im>
parents:
6935
diff
changeset
|
567 | serv_got_im(zgc, notice.z_sender, buf2, flags, time(NULL)); |
| 2086 | 568 | } else { |
| 569 | zephyr_triple *zt1, *zt2; | |
| 570 | zt1 = new_triple(notice.z_class, notice.z_class_inst, | |
| 4687 | 571 | notice.z_recipient); |
| 2086 | 572 | zt2 = find_sub_by_triple(zt1); |
| 573 | if (!zt2) { | |
| 574 | /* we shouldn't be subscribed to this message. ignore. */ | |
| 575 | } else { | |
| 8212 | 576 | GList *gltmp; |
| 577 | int found=0; | |
| 2086 | 578 | if (!zt2->open) { |
| 579 | zt2->open = TRUE; | |
| 580 | serv_got_joined_chat(zgc, zt2->id, zt2->name); | |
| 8212 | 581 | gconv1 = gaim_find_conversation_with_account(zt2->name,zgc->account); |
| 582 | gcc = gaim_conversation_get_chat_data(gconv1); | |
| 583 | gaim_conv_chat_set_topic(gcc,sendertmp,notice.z_class_inst); | |
| 584 | ||
| 2086 | 585 | } |
| 3277 | 586 | /* If the person is in the default Realm, then strip the |
| 587 | Realm from the sender field */ | |
| 588 | sendertmp = g_strdup_printf("%s",notice.z_sender); | |
| 4682 | 589 | if ((realmptr = strchr(sendertmp,'@')) != NULL) { |
| 4588 | 590 | realmptr++; |
| 8354 | 591 | if (!g_ascii_strcasecmp(realmptr,gaim_zephyr_get_realm())) { |
| 4588 | 592 | realmptr--; |
| 593 | sprintf(realmptr,"%c",'\0'); | |
| 594 | send_inst = g_strdup_printf("%s %s",sendertmp, | |
| 595 | notice.z_class_inst); | |
| 596 | } else { | |
| 597 | send_inst = g_strdup_printf("%s %s",notice.z_sender, | |
| 598 | notice.z_class_inst); | |
| 599 | } | |
| 3277 | 600 | } else { |
| 4588 | 601 | send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); |
| 3277 | 602 | } |
| 2804 | 603 | serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, |
| 4687 | 604 | buf2, time(NULL)); |
| 8212 | 605 | |
| 606 | gconv1 = gaim_find_conversation_with_account(zt2->name,zgc->account); | |
| 607 | gcc = gaim_conversation_get_chat_data(gconv1); | |
| 8354 | 608 | /* gaim_conv_chat_set_topic(gcc,sendertmp,notice.z_class_inst); */ |
| 8212 | 609 | for(gltmp = gaim_conv_chat_get_users(gcc);gltmp;gltmp=gltmp->next) { |
| 610 | if (!g_ascii_strcasecmp(gltmp->data,sendertmp) ) | |
| 611 | found = 1; | |
| 612 | } | |
| 613 | if (!found) { | |
| 614 | /* force interpretation in network byte order */ | |
| 615 | unsigned char* addrs = (unsigned char *)&(notice.z_sender_addr.s_addr); | |
| 616 | gaim_conv_chat_add_user(gcc,sendertmp,g_strdup_printf("%hhd.%hhd.%hhd.%hhd", | |
| 617 | (unsigned char)addrs[0], | |
| 618 | (unsigned char)addrs[1], | |
| 619 | (unsigned char)addrs[2], | |
| 620 | (unsigned char)addrs[3])); | |
| 621 | ||
| 622 | } | |
| 3277 | 623 | g_free(sendertmp); |
| 2804 | 624 | g_free(send_inst); |
| 2086 | 625 | } |
| 626 | free_triple(zt1); | |
| 627 | } | |
| 628 | g_free(buf2); | |
| 629 | } | |
| 630 | } | |
| 631 | } | |
| 632 | ||
| 633 | static gint check_notify(gpointer data) | |
| 634 | { | |
| 635 | while (ZPending()) { | |
| 636 | ZNotice_t notice; | |
| 637 | struct sockaddr_in from; | |
| 638 | z_call_r(ZReceiveNotice(¬ice, &from)); | |
| 639 | ||
| 640 | switch (notice.z_kind) { | |
| 641 | case UNSAFE: | |
| 642 | case UNACKED: | |
| 643 | case ACKED: | |
| 644 | handle_message(notice, from); | |
| 645 | break; | |
| 646 | default: | |
| 647 | /* we'll just ignore things for now */ | |
|
6484
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
648 | gaim_debug(GAIM_DEBUG_WARNING, "zephyr", "Unhandled notice.\n"); |
| 2086 | 649 | break; |
| 650 | } | |
| 651 | ||
| 652 | ZFreeNotice(¬ice); | |
| 653 | } | |
| 654 | ||
| 655 | return TRUE; | |
| 656 | } | |
| 657 | ||
| 658 | static gint check_loc(gpointer data) | |
| 659 | { | |
| 6695 | 660 | GaimBlistNode *gnode, *cnode, *bnode; |
| 2086 | 661 | ZAsyncLocateData_t ald; |
| 662 | ||
| 663 | ald.user = NULL; | |
| 664 | memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
| 665 | ald.version = NULL; | |
| 666 | ||
| 4785 | 667 | for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
| 668 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 669 | continue; | |
| 6695 | 670 | for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 671 | if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
| 4785 | 672 | continue; |
| 6935 | 673 | for(bnode = cnode->child; bnode; bnode = bnode->next) { |
| 6695 | 674 | GaimBuddy *b = (GaimBuddy *)bnode; |
| 675 | if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 676 | continue; | |
| 677 | if(b->account->gc == zgc) { | |
| 7261 | 678 | const char *chk; |
| 8354 | 679 | chk = local_zephyr_normalize(b->name); |
| 6695 | 680 | /* doesn't matter if this fails or not; we'll just move on to the next one */ |
| 681 | ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
| 682 | free(ald.user); | |
| 683 | free(ald.version); | |
| 684 | } | |
| 4349 | 685 | } |
| 2086 | 686 | } |
| 687 | } | |
| 688 | ||
| 689 | return TRUE; | |
| 690 | } | |
| 691 | ||
| 692 | static char *get_exposure_level() | |
| 693 | { | |
| 694 | char *exposure = ZGetVariable("exposure"); | |
| 695 | ||
| 696 | if (!exposure) | |
| 697 | return EXPOSE_REALMVIS; | |
| 4793 | 698 | if (!g_ascii_strcasecmp(exposure, EXPOSE_NONE)) |
| 2086 | 699 | return EXPOSE_NONE; |
| 4793 | 700 | if (!g_ascii_strcasecmp(exposure, EXPOSE_OPSTAFF)) |
| 2086 | 701 | return EXPOSE_OPSTAFF; |
| 4793 | 702 | if (!g_ascii_strcasecmp(exposure, EXPOSE_REALMANN)) |
| 2086 | 703 | return EXPOSE_REALMANN; |
| 4793 | 704 | if (!g_ascii_strcasecmp(exposure, EXPOSE_NETVIS)) |
| 2086 | 705 | return EXPOSE_NETVIS; |
| 4793 | 706 | if (!g_ascii_strcasecmp(exposure, EXPOSE_NETANN)) |
| 2086 | 707 | return EXPOSE_NETANN; |
| 708 | return EXPOSE_REALMVIS; | |
| 709 | } | |
| 710 | ||
| 711 | static void strip_comments(char *str) | |
| 712 | { | |
| 713 | char *tmp = strchr(str, '#'); | |
| 714 | if (tmp) | |
| 715 | *tmp = '\0'; | |
| 716 | g_strchug(str); | |
| 717 | g_strchomp(str); | |
| 718 | } | |
| 719 | ||
| 720 | static void process_zsubs() | |
| 721 | { | |
| 722 | FILE *f; | |
| 723 | gchar *fname; | |
| 724 | gchar buff[BUFSIZ]; | |
| 725 | ||
| 3630 | 726 | fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
| 2086 | 727 | f = fopen(fname, "r"); |
| 728 | if (f) { | |
| 729 | char **triple; | |
| 730 | ZSubscription_t sub; | |
| 731 | char *recip; | |
| 732 | while (fgets(buff, BUFSIZ, f)) { | |
| 733 | strip_comments(buff); | |
| 734 | if (buff[0]) { | |
| 735 | triple = g_strsplit(buff, ",", 3); | |
| 3277 | 736 | if (triple[0] && triple[1] ) { |
| 8354 | 737 | char *tmp = g_strdup_printf("%s",gaim_zephyr_get_sender()); |
| 2804 | 738 | char *atptr; |
| 2086 | 739 | sub.zsub_class = triple[0]; |
| 740 | sub.zsub_classinst = triple[1]; | |
| 3277 | 741 | if(triple[2] == NULL) { |
| 742 | recip = g_malloc0(1); | |
| 4793 | 743 | } else if (!g_ascii_strcasecmp(triple[2], "%me%")) { |
| 8354 | 744 | recip = g_strdup_printf("%s",gaim_zephyr_get_sender()); |
| 4793 | 745 | } else if (!g_ascii_strcasecmp(triple[2], "*")) { |
| 2804 | 746 | /* wildcard |
| 747 | * form of class,instance,* */ | |
| 748 | recip = g_malloc0(1); | |
| 4793 | 749 | } else if (!g_ascii_strcasecmp(triple[2], tmp)) { |
| 2804 | 750 | /* form of class,instance,aatharuv@ATHENA.MIT.EDU */ |
| 751 | recip = g_strdup(triple[2]); | |
| 752 | } else if ((atptr = strchr(triple[2], '@')) != NULL) { | |
| 753 | /* form of class,instance,*@ANDREW.CMU.EDU | |
| 754 | * class,instance,@ANDREW.CMU.EDU | |
| 755 | * If realm is local realm, blank recipient, else | |
| 756 | * @REALM-NAME | |
| 757 | */ | |
| 8354 | 758 | char *realmat = g_strdup_printf("@%s", gaim_zephyr_get_realm()); |
| 4793 | 759 | if (!g_ascii_strcasecmp(atptr, realmat)) |
| 2804 | 760 | recip = g_malloc0(1); |
| 761 | else | |
| 762 | recip = g_strdup(atptr); | |
| 763 | g_free(realmat); | |
| 2086 | 764 | } else { |
| 765 | recip = g_strdup(triple[2]); | |
| 766 | } | |
| 2804 | 767 | g_free(tmp); |
| 2086 | 768 | sub.zsub_recipient = recip; |
| 769 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
|
6484
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
770 | gaim_debug(GAIM_DEBUG_ERROR, "zephyr", |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
771 | "Couldn't subscribe to %s, %s, %s\n", |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
772 | sub.zsub_class, |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
773 | sub.zsub_classinst, |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
774 | sub.zsub_recipient); |
| 2086 | 775 | } |
| 776 | subscrips = g_slist_append(subscrips, | |
| 777 | new_triple(triple[0], triple[1], recip)); | |
| 778 | g_free(recip); | |
| 779 | } | |
| 780 | g_strfreev(triple); | |
| 781 | } | |
| 782 | } | |
| 783 | } | |
| 784 | } | |
| 785 | ||
| 786 | static void process_anyone() | |
| 787 | { | |
| 788 | FILE *fd; | |
| 789 | gchar buff[BUFSIZ], *filename; | |
| 6695 | 790 | GaimGroup *g; |
| 791 | GaimBuddy *b; | |
|
4775
239cb803fb1d
[gaim-migrate @ 5095]
Mark Doliner <markdoliner@pidgin.im>
parents:
4770
diff
changeset
|
792 | |
|
239cb803fb1d
[gaim-migrate @ 5095]
Mark Doliner <markdoliner@pidgin.im>
parents:
4770
diff
changeset
|
793 | if (!(g = gaim_find_group(_("Anyone")))) { |
|
239cb803fb1d
[gaim-migrate @ 5095]
Mark Doliner <markdoliner@pidgin.im>
parents:
4770
diff
changeset
|
794 | g = gaim_group_new(_("Anyone")); |
|
239cb803fb1d
[gaim-migrate @ 5095]
Mark Doliner <markdoliner@pidgin.im>
parents:
4770
diff
changeset
|
795 | gaim_blist_add_group(g, NULL); |
|
239cb803fb1d
[gaim-migrate @ 5095]
Mark Doliner <markdoliner@pidgin.im>
parents:
4770
diff
changeset
|
796 | } |
| 6695 | 797 | |
| 3630 | 798 | filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); |
| 2086 | 799 | if ((fd = fopen(filename, "r")) != NULL) { |
| 800 | while (fgets(buff, BUFSIZ, fd)) { | |
| 801 | strip_comments(buff); | |
| 4687 | 802 | if (buff[0]) { |
| 8212 | 803 | if(! (b=gaim_find_buddy(zgc->account,buff))) { |
| 804 | b = gaim_buddy_new(zgc->account, buff, NULL); | |
| 805 | gaim_blist_add_buddy(b, NULL, g, NULL); | |
| 806 | } | |
| 4687 | 807 | } |
| 2086 | 808 | } |
| 809 | fclose(fd); | |
| 810 | } | |
| 811 | g_free(filename); | |
| 812 | } | |
| 813 | ||
| 5606 | 814 | static void zephyr_login(GaimAccount *account) |
| 2086 | 815 | { |
| 816 | ZSubscription_t sub; | |
| 817 | ||
| 818 | if (zgc) { | |
|
5436
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
819 | gaim_notify_error(account->gc, NULL, |
|
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
820 | _("Already logged in with Zephyr"), |
|
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
821 | _("Because Zephyr uses your system username, you " |
|
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
822 | "are unable to have multiple accounts on it " |
|
a0e0bacaa196
[gaim-migrate @ 5818]
Christian Hammond <chipx86@chipx86.com>
parents:
5234
diff
changeset
|
823 | "when logged in as the same user.")); |
| 2086 | 824 | return; |
| 825 | } | |
| 826 | ||
| 5606 | 827 | zgc = gaim_account_get_connection(account); |
| 8451 | 828 | zgc->flags |= GAIM_CONNECTION_HTML; |
| 2086 | 829 | z_call_s(ZInitialize(), "Couldn't initialize zephyr"); |
| 830 | z_call_s(ZOpenPort(NULL), "Couldn't open port"); | |
| 8354 | 831 | z_call_s(ZSetLocation((char *)gaim_account_get_string(zgc->account,"exposure_level",EXPOSE_REALMVIS)), "Couldn't set location"); |
| 2086 | 832 | |
| 833 | sub.zsub_class = "MESSAGE"; | |
| 834 | sub.zsub_classinst = "PERSONAL"; | |
| 8354 | 835 | sub.zsub_recipient = (char *)gaim_zephyr_get_sender(); |
| 2086 | 836 | |
| 837 | /* we don't care if this fails. i'm lying right now. */ | |
| 838 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
|
6484
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
839 | gaim_debug(GAIM_DEBUG_ERROR, "zephyr", |
|
b8558c29e331
[gaim-migrate @ 6998]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
840 | "Couldn't subscribe to messages!\n"); |
| 2086 | 841 | } |
| 842 | ||
| 5606 | 843 | gaim_connection_set_state(zgc, GAIM_CONNECTED); |
| 2086 | 844 | serv_finish_login(zgc); |
| 845 | ||
| 846 | process_anyone(); | |
| 847 | process_zsubs(); | |
| 848 | ||
| 8273 | 849 | nottimer = gaim_timeout_add(100, check_notify, NULL); |
| 850 | loctimer = gaim_timeout_add(20000, check_loc, NULL); | |
| 2086 | 851 | } |
| 852 | ||
| 853 | static void write_zsubs() | |
| 854 | { | |
| 855 | GSList *s = subscrips; | |
| 856 | zephyr_triple *zt; | |
| 857 | FILE *fd; | |
| 858 | char *fname; | |
| 859 | ||
| 3277 | 860 | char** triple; |
| 3630 | 861 | fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
| 2086 | 862 | fd = fopen(fname, "w"); |
| 863 | ||
| 864 | if (!fd) { | |
| 865 | g_free(fname); | |
| 866 | return; | |
| 867 | } | |
| 868 | ||
| 869 | while (s) { | |
| 870 | zt = s->data; | |
| 3277 | 871 | triple = g_strsplit(zt->name,",",3); |
| 872 | if (triple[2] != NULL) { | |
| 4793 | 873 | if (!g_ascii_strcasecmp(triple[2], "")) { |
| 3277 | 874 | fprintf(fd, "%s,%s,*\n", triple[0], triple[1]); |
| 8354 | 875 | } else if (!g_ascii_strcasecmp(triple[2], gaim_zephyr_get_sender())) { |
| 3277 | 876 | fprintf(fd, "%s,%s,%%me%%\n",triple[0],triple[1]); |
| 877 | } else { | |
| 878 | fprintf(fd, "%s\n", zt->name); | |
| 879 | } | |
| 880 | } else { | |
| 881 | fprintf(fd, "%s,%s,*\n",triple[0], triple[1]); | |
| 882 | } | |
| 883 | g_free(triple); | |
| 2086 | 884 | s = s->next; |
| 885 | } | |
| 886 | g_free(fname); | |
| 887 | fclose(fd); | |
| 888 | } | |
| 889 | ||
| 890 | static void write_anyone() | |
| 891 | { | |
| 6695 | 892 | GaimBlistNode *gnode, *cnode, *bnode; |
| 893 | GaimBuddy *b; | |
| 3277 | 894 | char *ptr, *fname, *ptr2; |
| 2086 | 895 | FILE *fd; |
| 896 | ||
| 3630 | 897 | fname = g_strdup_printf("%s/.anyone", gaim_home_dir()); |
| 2086 | 898 | fd = fopen(fname, "w"); |
| 899 | if (!fd) { | |
| 900 | g_free(fname); | |
| 901 | return; | |
| 902 | } | |
| 903 | ||
| 4785 | 904 | for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
| 905 | if(!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 906 | continue; | |
| 6695 | 907 | for(cnode = gnode->child; cnode; cnode = cnode->next) { |
| 908 | if(!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
| 4785 | 909 | continue; |
| 8212 | 910 | for(bnode = cnode->child; bnode; bnode = bnode->next) { |
| 6695 | 911 | if(!GAIM_BLIST_NODE_IS_BUDDY(bnode)) |
| 912 | continue; | |
| 913 | b = (GaimBuddy *)bnode; | |
| 8212 | 914 | if(b->account == zgc->account) { |
| 6695 | 915 | if ((ptr = strchr(b->name, '@')) != NULL) { |
| 916 | ptr2 = ptr + 1; | |
| 917 | /* We should only strip the realm name if the principal | |
| 918 | is in the user's realm | |
| 919 | */ | |
| 8354 | 920 | if (!g_ascii_strcasecmp(ptr2,gaim_zephyr_get_realm())) { |
| 6695 | 921 | *ptr = '\0'; |
| 922 | } | |
| 4349 | 923 | } |
| 6695 | 924 | fprintf(fd, "%s\n", b->name); |
| 925 | if (ptr) | |
| 926 | *ptr = '@'; | |
| 3277 | 927 | } |
| 928 | } | |
| 2086 | 929 | } |
| 930 | } | |
| 931 | ||
| 932 | fclose(fd); | |
| 933 | g_free(fname); | |
| 934 | } | |
| 935 | ||
| 5606 | 936 | static void zephyr_close(GaimConnection *gc) |
| 2086 | 937 | { |
| 938 | GList *l; | |
| 939 | GSList *s; | |
| 940 | l = pending_zloc_names; | |
| 941 | while (l) { | |
| 942 | g_free((char*)l->data); | |
| 943 | l = l->next; | |
| 944 | } | |
| 945 | g_list_free(pending_zloc_names); | |
| 946 | ||
| 8212 | 947 | if (gaim_account_get_bool(zgc->account,"write_anyone",FALSE)) |
| 948 | write_anyone(); | |
| 949 | ||
| 950 | if (gaim_account_get_bool(zgc->account,"write_zsubs",FALSE)) | |
| 951 | write_zsubs(); | |
| 2086 | 952 | |
| 953 | s = subscrips; | |
| 954 | while (s) { | |
| 955 | free_triple((zephyr_triple*)s->data); | |
| 956 | s = s->next; | |
| 957 | } | |
| 958 | g_slist_free(subscrips); | |
| 959 | ||
| 960 | if (nottimer) | |
| 8287 | 961 | gaim_timeout_remove(nottimer); |
| 2086 | 962 | nottimer = 0; |
| 963 | if (loctimer) | |
| 8287 | 964 | gaim_timeout_remove(loctimer); |
| 2086 | 965 | loctimer = 0; |
| 966 | zgc = NULL; | |
| 967 | z_call(ZCancelSubscriptions(0)); | |
| 968 | z_call(ZUnsetLocation()); | |
| 969 | z_call(ZClosePort()); | |
| 970 | } | |
| 971 | ||
| 8212 | 972 | static void zephyr_add_buddy(GaimConnection *gc, const char *buddy, GaimGroup *group) { |
| 973 | GaimBuddy *b; | |
| 974 | if(! (b=gaim_find_buddy(zgc->account,buddy))) { | |
| 975 | b = gaim_buddy_new(zgc->account, buddy, NULL); | |
| 976 | gaim_blist_add_buddy(b, NULL, group, NULL); | |
| 977 | } | |
| 8354 | 978 | } |
| 979 | ||
| 980 | static void zephyr_add_buddies(GaimConnection *gc, GList* buddies) { | |
| 981 | GaimGroup *group; | |
| 982 | if (!(group = gaim_find_group(_("Anyone")))) { | |
| 983 | group = gaim_group_new(_("Anyone")); | |
| 984 | gaim_blist_add_group(group, NULL); | |
| 985 | } | |
| 986 | while (buddies) { | |
| 987 | zephyr_add_buddy(gc, buddies->data, group); | |
| 988 | buddies = buddies->next; | |
| 989 | } | |
| 8212 | 990 | } |
| 991 | ||
| 992 | static void zephyr_remove_buddy(GaimConnection *gc, const char *buddy, const char *group) { | |
| 993 | GaimBuddy *b; | |
| 994 | fprintf(stderr,"In zephyr_remove_buddy\n"); | |
| 995 | if ((b=gaim_find_buddy(zgc->account,buddy))) | |
| 996 | gaim_blist_remove_buddy(b); | |
| 997 | else | |
| 998 | fprintf(stderr,"attempt to remove non-existent buddy %s\n",buddy); | |
| 999 | } | |
| 2086 | 1000 | |
| 8354 | 1001 | static void zephyr_remove_buddies(GaimConnection *gc, GList *buddies, const char *group) { |
| 1002 | GaimBuddy *b; | |
| 1003 | while(buddies) { | |
| 1004 | if ((b=gaim_find_buddy(zgc->account,buddies->data))) { | |
| 1005 | gaim_blist_remove_buddy(b); | |
| 1006 | } else { | |
| 1007 | fprintf(stderr,"attempt to remove non-existent buddy %s\n",(char *)buddies->data); | |
| 1008 | } | |
| 1009 | } | |
| 1010 | } | |
| 1011 | ||
|
6059
9934c862ca14
[gaim-migrate @ 6509]
John Silvestri <john.silvestri@gmail.com>
parents:
5920
diff
changeset
|
1012 | static int zephyr_chat_send(GaimConnection *gc, int id, const char *im) |
| 2086 | 1013 | { |
| 1014 | ZNotice_t notice; | |
| 1015 | zephyr_triple *zt; | |
| 1016 | char *buf; | |
| 1017 | const char *sig; | |
| 8212 | 1018 | GaimConversation * gconv1; |
| 1019 | GaimConvChat* gcc; | |
| 1020 | char * inst; | |
| 8451 | 1021 | char * html_buf; |
| 1022 | char * html_buf2; | |
| 2086 | 1023 | |
| 1024 | zt = find_sub_by_id(id); | |
| 1025 | if (!zt) | |
| 1026 | /* this should never happen. */ | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
1027 | return -EINVAL; |
| 2086 | 1028 | |
| 1029 | sig = ZGetVariable("zwrite-signature"); | |
| 1030 | if (!sig) { | |
| 1031 | sig = g_get_real_name(); | |
| 1032 | } | |
| 8451 | 1033 | |
| 1034 | html_buf = html_to_zephyr(im); | |
| 1035 | html_buf2 = gaim_unescape_html(html_buf); | |
| 1036 | ||
| 1037 | buf = g_strdup_printf("%s%c%s", sig, '\0', html_buf2); | |
| 2086 | 1038 | |
| 8212 | 1039 | gconv1 = gaim_find_conversation_with_account(zt->name,zgc->account); |
| 1040 | gcc = gaim_conversation_get_chat_data(gconv1); | |
| 1041 | ||
| 8354 | 1042 | if(!(inst = (char *)gaim_conv_chat_get_topic(gcc))) |
| 1043 | inst = (char *)notice.z_class_inst; | |
| 8212 | 1044 | |
| 2086 | 1045 | bzero((char *)¬ice, sizeof(notice)); |
| 1046 | notice.z_kind = ACKED; | |
| 1047 | notice.z_port = 0; | |
| 1048 | notice.z_opcode = ""; | |
| 1049 | notice.z_class = zt->class; | |
| 8212 | 1050 | notice.z_class_inst = inst; |
| 4793 | 1051 | if (!g_ascii_strcasecmp(zt->recipient, "*")) |
| 8354 | 1052 | notice.z_recipient = local_zephyr_normalize(""); |
| 2086 | 1053 | else |
| 8354 | 1054 | notice.z_recipient = local_zephyr_normalize(zt->recipient); |
| 2086 | 1055 | notice.z_sender = 0; |
| 1056 | notice.z_default_format = | |
| 1057 | "Class $class, Instance $instance:\n" | |
| 1058 | "To: @bold($recipient) at $time $date\n" | |
| 1059 | "From: @bold($1) <$sender>\n\n$2"; | |
| 8451 | 1060 | notice.z_message_len = strlen(html_buf2) + strlen(sig) + 2; |
| 2086 | 1061 | notice.z_message = buf; |
| 8451 | 1062 | g_free(html_buf); |
| 1063 | g_free(html_buf2); | |
| 1064 | ||
| 2086 | 1065 | ZSendNotice(¬ice, ZAUTH); |
| 1066 | g_free(buf); | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
1067 | return 0; |
| 2086 | 1068 | } |
| 1069 | ||
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
1070 | static int zephyr_send_im(GaimConnection *gc, const char *who, const char *im, GaimConvImFlags flags) { |
| 2086 | 1071 | ZNotice_t notice; |
| 1072 | char *buf; | |
| 1073 | const char *sig; | |
| 8451 | 1074 | char *html_buf; |
| 1075 | char *html_buf2; | |
|
7118
280b3b85a28a
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
1076 | if (flags & GAIM_CONV_IM_AUTO_RESP) |
| 2086 | 1077 | sig = "Automated reply:"; |
| 1078 | else { | |
| 1079 | sig = ZGetVariable("zwrite-signature"); | |
| 1080 | if (!sig) { | |
| 1081 | sig = g_get_real_name(); | |
| 1082 | } | |
| 1083 | } | |
| 1084 | ||
| 8451 | 1085 | html_buf = html_to_zephyr(im); |
| 1086 | html_buf2 = gaim_unescape_html(html_buf); | |
| 1087 | ||
| 1088 | buf = g_strdup_printf("%s%c%s", sig, '\0', html_buf2); | |
| 2086 | 1089 | bzero((char *)¬ice, sizeof(notice)); |
| 1090 | notice.z_kind = ACKED; | |
| 1091 | notice.z_port = 0; | |
| 1092 | notice.z_opcode = ""; | |
| 1093 | notice.z_class = "MESSAGE"; | |
| 1094 | notice.z_class_inst = "PERSONAL"; | |
| 1095 | notice.z_sender = 0; | |
| 1096 | notice.z_recipient = who; | |
| 1097 | notice.z_default_format = | |
| 1098 | "Class $class, Instance $instance:\n" | |
| 1099 | "To: @bold($recipient) at $time $date\n" | |
| 1100 | "From: @bold($1) <$sender>\n\n$2"; | |
| 8451 | 1101 | notice.z_message_len = strlen(html_buf2) + strlen(sig) + 2; |
| 2086 | 1102 | notice.z_message = buf; |
| 8451 | 1103 | g_free(html_buf2); |
| 1104 | g_free(html_buf); | |
| 1105 | ||
| 6904 | 1106 | ZSendNotice(¬ice, ZAUTH); |
| 2086 | 1107 | g_free(buf); |
|
2303
18171aa8cd37
[gaim-migrate @ 2313]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2231
diff
changeset
|
1108 | return 1; |
| 2086 | 1109 | } |
| 1110 | ||
| 7322 | 1111 | static const char *zephyr_normalize(const GaimAccount *account,const char *orig) |
| 2086 | 1112 | { |
| 1113 | static char buf[80]; | |
| 7126 | 1114 | if (!g_ascii_strcasecmp(orig, "")) { |
| 1115 | buf[0] = '\0'; | |
| 1116 | return buf; | |
| 8354 | 1117 | } else { |
| 1118 | g_snprintf(buf,80,"%s",orig); | |
| 1119 | } | |
| 1120 | return buf; | |
| 1121 | } | |
| 1122 | ||
| 1123 | ||
| 1124 | static const char *local_zephyr_normalize(const char *orig) | |
| 1125 | { | |
| 1126 | static char buf[80]; | |
| 1127 | if (!g_ascii_strcasecmp(orig, "")) { | |
| 1128 | buf[0] = '\0'; | |
| 1129 | return buf; | |
| 7126 | 1130 | } |
| 8354 | 1131 | |
| 2086 | 1132 | if (strchr(orig, '@')) { |
| 1133 | g_snprintf(buf, 80, "%s", orig); | |
| 1134 | } else { | |
| 8354 | 1135 | g_snprintf(buf,80,"%s@%s",orig,gaim_zephyr_get_realm()); |
| 2086 | 1136 | } |
| 1137 | return buf; | |
| 1138 | } | |
| 1139 | ||
| 5606 | 1140 | static void zephyr_zloc(GaimConnection *gc, const char *who) |
| 2086 | 1141 | { |
| 1142 | ZAsyncLocateData_t ald; | |
| 7261 | 1143 | |
| 8354 | 1144 | if (ZRequestLocations(local_zephyr_normalize(who), &ald, UNACKED, ZAUTH) |
| 2086 | 1145 | != ZERR_NONE) { |
| 1146 | return; | |
| 1147 | } | |
| 1148 | pending_zloc_names = g_list_append(pending_zloc_names, | |
| 8354 | 1149 | g_strdup(local_zephyr_normalize(who))); |
| 2086 | 1150 | } |
| 1151 | ||
| 5606 | 1152 | static GList *zephyr_buddy_menu(GaimConnection *gc, const char *who) |
| 2086 | 1153 | { |
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1154 | GList *m = NULL; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1155 | struct proto_buddy_menu *pbm; |
| 2086 | 1156 | |
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1157 | pbm = g_new0(struct proto_buddy_menu, 1); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1158 | pbm->label = _("ZLocate"); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1159 | pbm->callback = zephyr_zloc; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1160 | pbm->gc = gc; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1161 | m = g_list_append(m, pbm); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1162 | |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
1163 | return m; |
| 2086 | 1164 | } |
| 1165 | ||
|
6059
9934c862ca14
[gaim-migrate @ 6509]
John Silvestri <john.silvestri@gmail.com>
parents:
5920
diff
changeset
|
1166 | static void zephyr_set_away(GaimConnection *gc, const char *state, const char *msg) |
| 2086 | 1167 | { |
|
4111
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
1168 | if (gc->away) { |
| 2086 | 1169 | g_free(gc->away); |
|
4111
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
1170 | gc->away = NULL; |
|
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
1171 | } |
|
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
1172 | |
|
5132
9b087ef3f525
[gaim-migrate @ 5495]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
1173 | if (!g_ascii_strcasecmp(state, _("Hidden"))) { |
| 2086 | 1174 | ZSetLocation(EXPOSE_OPSTAFF); |
|
4111
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
1175 | gc->away = g_strdup(""); |
|
5132
9b087ef3f525
[gaim-migrate @ 5495]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
1176 | } else if (!g_ascii_strcasecmp(state, _("Online"))) |
| 2086 | 1177 | ZSetLocation(get_exposure_level()); |
| 1178 | else /* state is GAIM_AWAY_CUSTOM */ if (msg) | |
| 1179 | gc->away = g_strdup(msg); | |
| 1180 | } | |
| 1181 | ||
| 5606 | 1182 | static GList *zephyr_away_states(GaimConnection *gc) |
| 2086 | 1183 | { |
| 1184 | GList *m = NULL; | |
| 1185 | ||
|
5132
9b087ef3f525
[gaim-migrate @ 5495]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
1186 | m = g_list_append(m, _("Online")); |
| 2086 | 1187 | m = g_list_append(m, GAIM_AWAY_CUSTOM); |
|
5132
9b087ef3f525
[gaim-migrate @ 5495]
Mark Doliner <markdoliner@pidgin.im>
parents:
4793
diff
changeset
|
1188 | m = g_list_append(m, _("Hidden")); |
| 2086 | 1189 | |
| 1190 | return m; | |
| 1191 | } | |
| 1192 | ||
| 5606 | 1193 | static GList *zephyr_chat_info(GaimConnection *gc) { |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1194 | GList *m = NULL; |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1195 | struct proto_chat_entry *pce; |
| 2086 | 1196 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1197 | pce = g_new0(struct proto_chat_entry, 1); |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7475
diff
changeset
|
1198 | pce->label = _("_Class:"); |
| 5234 | 1199 | pce->identifier = "class"; |
| 3158 | 1200 | m = g_list_append(m, pce); |
| 2086 | 1201 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1202 | pce = g_new0(struct proto_chat_entry, 1); |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7475
diff
changeset
|
1203 | pce->label = _("_Instance:"); |
| 5234 | 1204 | pce->identifier = "instance"; |
| 3158 | 1205 | m = g_list_append(m, pce); |
| 2086 | 1206 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1207 | pce = g_new0(struct proto_chat_entry, 1); |
|
7841
0000a4c68bf8
[gaim-migrate @ 8494]
Mark Doliner <markdoliner@pidgin.im>
parents:
7475
diff
changeset
|
1208 | pce->label = _("_Recipient:"); |
| 5234 | 1209 | pce->identifier = "recipient"; |
| 3158 | 1210 | m = g_list_append(m, pce); |
| 2086 | 1211 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1212 | return m; |
| 2086 | 1213 | } |
| 1214 | ||
| 5606 | 1215 | static void zephyr_join_chat(GaimConnection *gc, GHashTable *data) |
| 2086 | 1216 | { |
| 1217 | ZSubscription_t sub; | |
| 1218 | zephyr_triple *zt1, *zt2; | |
| 1219 | const char *classname; | |
| 1220 | const char *instname; | |
| 1221 | const char *recip; | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1222 | |
| 5234 | 1223 | classname = g_hash_table_lookup(data, "class"); |
| 1224 | instname = g_hash_table_lookup(data, "instance"); | |
| 1225 | recip = g_hash_table_lookup(data, "recipient"); | |
| 1226 | ||
| 1227 | if (!classname || !instname || !recip) | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
1228 | return; |
| 2086 | 1229 | |
| 4793 | 1230 | if (!g_ascii_strcasecmp(recip, "%me%")) |
| 8354 | 1231 | recip = gaim_zephyr_get_sender(); |
| 2086 | 1232 | |
| 1233 | zt1 = new_triple(classname, instname, recip); | |
| 1234 | zt2 = find_sub_by_triple(zt1); | |
| 1235 | if (zt2) { | |
| 1236 | free_triple(zt1); | |
| 1237 | if (!zt2->open) | |
| 1238 | serv_got_joined_chat(gc, zt2->id, zt2->name); | |
| 1239 | return; | |
| 1240 | } | |
| 1241 | ||
| 1242 | sub.zsub_class = zt1->class; | |
| 1243 | sub.zsub_classinst = zt1->instance; | |
| 1244 | sub.zsub_recipient = zt1->recipient; | |
| 1245 | ||
| 1246 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
| 1247 | free_triple(zt1); | |
| 1248 | return; | |
| 1249 | } | |
| 1250 | ||
| 1251 | subscrips = g_slist_append(subscrips, zt1); | |
| 1252 | zt1->open = TRUE; | |
| 1253 | serv_got_joined_chat(gc, zt1->id, zt1->name); | |
| 1254 | } | |
| 1255 | ||
| 5606 | 1256 | static void zephyr_chat_leave(GaimConnection *gc, int id) |
| 2086 | 1257 | { |
| 1258 | zephyr_triple *zt; | |
| 1259 | zt = find_sub_by_id(id); | |
| 1260 | if (zt) { | |
| 1261 | zt->open = FALSE; | |
| 1262 | zt->id = ++last_id; | |
| 1263 | } | |
| 1264 | } | |
| 1265 | ||
| 6695 | 1266 | static const char *zephyr_list_icon(GaimAccount *a, GaimBuddy *b) |
|
5202
2c78987f497b
[gaim-migrate @ 5568]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
1267 | { |
|
2c78987f497b
[gaim-migrate @ 5568]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
1268 | return "zephyr"; |
|
2c78987f497b
[gaim-migrate @ 5568]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
1269 | } |
|
2c78987f497b
[gaim-migrate @ 5568]
Mark Doliner <markdoliner@pidgin.im>
parents:
5136
diff
changeset
|
1270 | |
| 8212 | 1271 | |
| 1272 | static void zephyr_chat_set_topic(GaimConnection *gc, int id, const char *topic) { | |
| 1273 | zephyr_triple *zt; | |
| 1274 | GaimConversation *gconv; | |
| 1275 | GaimConvChat* gcc; | |
| 8354 | 1276 | char* sender = (char *)gaim_zephyr_get_sender(); |
| 8212 | 1277 | |
| 1278 | zt = find_sub_by_id(id); | |
| 1279 | gconv = gaim_find_conversation_with_account(zt->name,zgc->account); | |
| 1280 | gcc = gaim_conversation_get_chat_data(gconv); | |
| 1281 | gaim_conv_chat_set_topic(gcc,sender,topic); | |
| 1282 | ||
| 1283 | } | |
| 1284 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1285 | static GaimPlugin *my_protocol = NULL; |
| 2086 | 1286 | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1287 | static GaimPluginProtocolInfo prpl_info = |
| 2086 | 1288 | { |
| 8212 | 1289 | OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD, |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1290 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1291 | NULL, |
| 8170 | 1292 | NULL, |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1293 | zephyr_list_icon, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1294 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1295 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1296 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1297 | zephyr_away_states, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1298 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1299 | zephyr_buddy_menu, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1300 | zephyr_chat_info, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1301 | zephyr_login, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1302 | zephyr_close, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1303 | zephyr_send_im, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1304 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1305 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1306 | zephyr_zloc, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1307 | zephyr_set_away, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1308 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1309 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1310 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1311 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1312 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1313 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1314 | zephyr_add_buddy, |
| 8354 | 1315 | zephyr_add_buddies, |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1316 | zephyr_remove_buddy, |
| 8354 | 1317 | zephyr_remove_buddies, |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1318 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1319 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1320 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1321 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1322 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1323 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1324 | zephyr_join_chat, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1325 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1326 | zephyr_chat_leave, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1327 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1328 | zephyr_chat_send, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1329 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1330 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1331 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1332 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1333 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1334 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1335 | NULL, |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1336 | NULL, |
| 8212 | 1337 | NULL, |
| 1338 | zephyr_normalize, | |
| 1339 | NULL, | |
| 1340 | NULL, | |
| 1341 | NULL, | |
| 1342 | zephyr_chat_set_topic | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1343 | }; |
| 2086 | 1344 | |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1345 | static GaimPluginInfo info = |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1346 | { |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1347 | 2, /**< api_version */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1348 | GAIM_PLUGIN_PROTOCOL, /**< type */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1349 | NULL, /**< ui_requirement */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1350 | 0, /**< flags */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1351 | NULL, /**< dependencies */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1352 | GAIM_PRIORITY_DEFAULT, /**< priority */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1353 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1354 | "prpl-zephyr", /**< id */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1355 | "Zephyr", /**< name */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1356 | VERSION, /**< version */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1357 | /** summary */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1358 | N_("Zephyr Protocol Plugin"), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1359 | /** description */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1360 | N_("Zephyr Protocol Plugin"), |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1361 | NULL, /**< author */ |
|
6371
e92b66ee5518
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6059
diff
changeset
|
1362 | GAIM_WEBSITE, /**< homepage */ |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1363 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1364 | NULL, /**< load */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1365 | NULL, /**< unload */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1366 | NULL, /**< destroy */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1367 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1368 | NULL, /**< ui_info */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1369 | &prpl_info /**< extra_info */ |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1370 | }; |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1371 | |
|
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1372 | static void |
|
5920
963bfdefee02
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1373 | init_plugin(GaimPlugin *plugin) |
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1374 | { |
| 8212 | 1375 | GaimAccountOption *option; |
| 1376 | char* tmp = get_exposure_level(); | |
| 1377 | option = gaim_account_option_bool_new(_("Export to .anyone"),"write_anyone",FALSE); | |
| 1378 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); | |
| 1379 | ||
| 1380 | option = gaim_account_option_bool_new(_("Export to .zephyr.subs"),"write_zsubs",FALSE); | |
| 1381 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); | |
| 1382 | ||
| 1383 | option = gaim_account_option_string_new(_("Exposure"),"exposure_level",tmp?tmp:EXPOSE_REALMVIS); | |
| 1384 | prpl_info.protocol_options = g_list_append(prpl_info.protocol_options,option); | |
| 1385 | ||
|
5205
242b8aa81328
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1386 | my_protocol = plugin; |
| 2086 | 1387 | } |
| 1388 | ||
|
5920
963bfdefee02
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1389 | GAIM_INIT_PLUGIN(zephyr, init_plugin, info); |