Thu, 19 Apr 2001 00:05:50 +0000
[gaim-migrate @ 1736]
most of nsanch's patch for zephyr (all except the input watcher - i can't understand why it's not working for me. it looks like it should work and i really want to add it).
committer: Eric Warmenhoven <warmenhoven@yahoo.com>
| 1700 | 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 | |
| 7 | * Jag/Sean Dilda <agrajag@linuxpower.org>/<smdilda@unity.ncsu.edu> | |
| 8 | * http://gtkzephyr.linuxpower.org/ | |
| 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 | */ | |
| 25 | ||
| 26 | #ifdef HAVE_CONFIG_H | |
| 27 | #include "config.h" | |
| 28 | #endif | |
| 29 | ||
| 30 | #include <gtk/gtk.h> | |
| 31 | #include <string.h> | |
| 32 | #include "gaim.h" | |
| 33 | #include "prpl.h" | |
| 34 | #include "zephyr/zephyr.h" | |
| 35 | ||
| 1726 | 36 | typedef struct _zframe zframe; |
| 37 | ||
| 38 | /* struct I need for zephyr_to_html */ | |
| 39 | struct _zframe { | |
| 40 | /* true for everything but @color, since inside the parens of that one is | |
| 41 | * the color. */ | |
| 42 | gboolean has_closer; | |
| 43 | /* </i>, </font>, </b>, etc. */ | |
| 44 | char *closing; | |
| 45 | /* text including the opening html thingie. */ | |
| 46 | GString *text; | |
| 47 | struct _zframe *enclosing; | |
| 48 | }; | |
| 49 | ||
| 1700 | 50 | char *name() |
| 51 | { | |
| 52 | return "Zephyr"; | |
| 53 | } | |
| 54 | ||
| 55 | char *description() | |
| 56 | { | |
| 57 | return "Allows gaim to use the Zephyr protocol"; | |
| 58 | } | |
| 59 | ||
| 60 | static char *zephyr_name() | |
| 61 | { | |
| 62 | return "Zephyr"; | |
| 63 | } | |
| 64 | ||
| 65 | #define z_call(func) if (func != ZERR_NONE)\ | |
| 66 | return; | |
| 67 | #define z_call_r(func) if (func != ZERR_NONE)\ | |
| 68 | return TRUE; | |
| 69 | #define z_call_s(func, err) if (func != ZERR_NONE) {\ | |
| 70 | hide_login_progress(zgc, err);\ | |
| 71 | signoff(zgc);\ | |
| 72 | return;\ | |
| 73 | } | |
| 74 | ||
| 1726 | 75 | static char *zephyr_normalize(const char *); |
| 76 | ||
| 1700 | 77 | /* this is so bad, and if Zephyr weren't so fucked up to begin with I |
| 78 | * wouldn't do this. but it is so i will. */ | |
| 79 | static guint32 nottimer = 0; | |
| 80 | static guint32 loctimer = 0; | |
| 81 | struct gaim_connection *zgc = NULL; | |
| 1719 | 82 | static GList *pending_zloc_names = NULL; |
| 1700 | 83 | |
| 84 | /* just for debugging | |
| 85 | static void handle_unknown(ZNotice_t notice) | |
| 86 | { | |
| 87 | g_print("z_packet: %s\n", notice.z_packet); | |
| 88 | g_print("z_version: %s\n", notice.z_version); | |
| 89 | g_print("z_kind: %d\n", notice.z_kind); | |
| 90 | g_print("z_class: %s\n", notice.z_class); | |
| 91 | g_print("z_class_inst: %s\n", notice.z_class_inst); | |
| 92 | g_print("z_opcode: %s\n", notice.z_opcode); | |
| 93 | g_print("z_sender: %s\n", notice.z_sender); | |
| 94 | g_print("z_recipient: %s\n", notice.z_recipient); | |
| 95 | g_print("z_message: %s\n", notice.z_message); | |
| 96 | g_print("z_message_len: %d\n", notice.z_message_len); | |
| 97 | g_print("\n"); | |
| 98 | } | |
| 99 | */ | |
| 100 | ||
| 1726 | 101 | /* utility macros that are useful for zephyr_to_html */ |
| 102 | ||
| 103 | #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) | |
| 104 | #define IS_CLOSER(c) ((c == '}') || (c == ']') || (c == ')') || (c == '>')) | |
| 105 | ||
| 106 | /* this parses zephyr formatting and converts it to html. For example, if | |
| 107 | * you pass in "@{@color(blue)@i(hello)}" you should get out | |
| 108 | * "<font color=blue><i>hello</i></font>". */ | |
| 109 | static char *zephyr_to_html(char *message) | |
| 1719 | 110 | { |
| 1726 | 111 | int len, cnt; |
| 112 | zframe *frames, *curr; | |
| 113 | char *ret; | |
| 114 | ||
| 115 | frames = g_new(zframe, 1); | |
| 116 | frames->text = g_string_new(""); | |
| 117 | frames->enclosing = NULL; | |
| 118 | frames->closing = ""; | |
| 119 | frames->has_closer = FALSE; | |
| 120 | ||
| 121 | len = strlen(message); | |
| 122 | cnt = 0; | |
| 123 | while (cnt <= len) { | |
| 124 | if (message[cnt] == '@') { | |
| 125 | zframe *new_f; | |
| 126 | char *buf; | |
| 127 | int end; | |
| 128 | for (end=1; (cnt+end) <= len && | |
| 129 | !IS_OPENER(message[cnt+end]); end++); | |
| 130 | buf = g_new0(char, end); | |
| 131 | if (end) { | |
| 132 | g_snprintf(buf, end, "%s", message+cnt+1); | |
| 133 | } | |
| 134 | if (!g_strcasecmp(buf, "italic") || | |
| 135 | !g_strcasecmp(buf, "i")) { | |
| 136 | new_f = g_new(zframe, 1); | |
| 137 | new_f->enclosing = frames; | |
| 138 | new_f->text = g_string_new("<i>"); | |
| 139 | new_f->closing = "</i>"; | |
| 140 | new_f->has_closer = TRUE; | |
| 141 | frames = new_f; | |
| 142 | cnt += end+1; /* cnt points to char after opener */ | |
| 143 | } else if (!g_strcasecmp(buf, "bold") | |
| 144 | || !g_strcasecmp(buf, "b")) { | |
| 145 | new_f = g_new(zframe, 1); | |
| 146 | new_f->enclosing = frames; | |
| 147 | new_f->text = g_string_new("<b>"); | |
| 148 | new_f->closing = "</b>"; | |
| 149 | new_f->has_closer = TRUE; | |
| 150 | frames = new_f; | |
| 151 | cnt += end+1; | |
| 152 | } else if (!g_strcasecmp(buf, "color")) { | |
| 153 | cnt += end+1; | |
| 154 | new_f = g_new(zframe, 1); | |
| 155 | new_f->enclosing = frames; | |
| 156 | new_f->text = g_string_new("<font color="); | |
| 157 | for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
| 158 | g_string_append_c(new_f->text, message[cnt]); | |
| 159 | } | |
| 160 | cnt++; /* point to char after closer */ | |
| 161 | g_string_append_c(new_f->text, '>'); | |
| 162 | new_f->closing = "</font>"; | |
| 163 | new_f->has_closer = FALSE; | |
| 164 | frames = new_f; | |
| 165 | } else if (!g_strcasecmp(buf, "")) { | |
| 166 | new_f = g_new(zframe, 1); | |
| 167 | new_f->enclosing = frames; | |
| 168 | new_f->text = g_string_new(""); | |
| 169 | new_f->closing = ""; | |
| 170 | new_f->has_closer = TRUE; | |
| 171 | frames = new_f; | |
| 172 | cnt += end+1; /* cnt points to char after opener */ | |
| 173 | } else { | |
| 174 | if ((cnt+end) > len) { | |
| 175 | g_string_append_c(frames->text, '@'); | |
| 176 | cnt++; | |
| 177 | } else { | |
| 178 | /* unrecognized thingie. act like it's not there, but we | |
| 179 | * still need to take care of the corresponding closer, | |
| 180 | * make a frame that does nothing. */ | |
| 181 | new_f = g_new(zframe, 1); | |
| 182 | new_f->enclosing = frames; | |
| 183 | new_f->text = g_string_new(""); | |
| 184 | new_f->closing = ""; | |
| 185 | new_f->has_closer = TRUE; | |
| 186 | frames = new_f; | |
| 187 | cnt += end+1; /* cnt points to char after opener */ | |
| 188 | } | |
| 189 | } | |
| 190 | } else if (IS_CLOSER(message[cnt])) { | |
| 191 | zframe *popped; | |
| 192 | gboolean last_had_closer; | |
| 193 | if (frames->enclosing) { | |
| 194 | do { | |
| 195 | popped = frames; | |
| 196 | frames = frames->enclosing; | |
| 197 | g_string_append(frames->text, popped->text->str); | |
| 198 | g_string_append(frames->text, popped->closing); | |
| 199 | g_string_free(popped->text, TRUE); | |
| 200 | last_had_closer = popped->has_closer; | |
| 201 | g_free(popped); | |
| 202 | } while (frames && frames->enclosing && !last_had_closer); | |
| 203 | } else { | |
| 204 | g_string_append_c(frames->text, message[cnt]); | |
| 205 | } | |
| 206 | cnt++; | |
| 207 | } else if (message[cnt] == '\n') { | |
| 208 | g_string_append(frames->text, "<br>"); | |
| 209 | cnt++; | |
| 210 | } else { | |
| 211 | g_string_append_c(frames->text, message[cnt++]); | |
| 212 | } | |
| 1719 | 213 | } |
| 1726 | 214 | /* go through all the stuff that they didn't close */ |
| 215 | while (frames->enclosing) { | |
| 216 | curr = frames; | |
| 217 | g_string_append(frames->enclosing->text, frames->text->str); | |
| 218 | g_string_append(frames->enclosing->text, frames->closing); | |
| 219 | g_string_free(frames->text, TRUE); | |
| 220 | frames = frames->enclosing; | |
| 221 | g_free(curr); | |
| 222 | } | |
| 223 | ret = frames->text->str; | |
| 224 | g_string_free(frames->text, FALSE); | |
| 225 | g_free(frames); | |
| 226 | return ret; | |
| 1719 | 227 | } |
| 228 | ||
| 229 | static gboolean pending_zloc(char *who) | |
| 230 | { | |
| 231 | GList *curr; | |
| 232 | for (curr = pending_zloc_names; curr != NULL; curr = curr->next) { | |
| 233 | if (!g_strcasecmp(who, (char*)curr->data)) { | |
| 234 | g_free((char*)curr->data); | |
| 235 | pending_zloc_names = g_list_remove(pending_zloc_names, curr->data); | |
| 236 | return TRUE; | |
| 237 | } | |
| 238 | } | |
| 239 | return FALSE; | |
| 240 | } | |
| 241 | ||
| 1700 | 242 | static void handle_message(ZNotice_t notice, struct sockaddr_in from) |
| 243 | { | |
| 244 | if (!g_strcasecmp(notice.z_class, LOGIN_CLASS)) { | |
| 245 | /* well, we'll be updating in 2 seconds anyway, might as well ignore this. */ | |
| 246 | } else if (!g_strcasecmp(notice.z_class, LOCATE_CLASS)) { | |
| 247 | if (!g_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
| 248 | int nlocs; | |
| 249 | char *user; | |
| 250 | struct buddy *b; | |
| 251 | ||
| 252 | if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) | |
| 253 | return; | |
| 254 | if ((b = find_buddy(zgc, user)) == NULL) { | |
| 255 | char *e = strchr(user, '@'); | |
| 256 | if (e) *e = '\0'; | |
| 257 | b = find_buddy(zgc, user); | |
| 258 | } | |
| 259 | if (!b) { | |
| 260 | free(user); | |
| 261 | return; | |
| 262 | } | |
| 1719 | 263 | if (pending_zloc(b->name)) { |
| 264 | ZLocations_t locs; | |
| 265 | int one = 1; | |
| 266 | GString *str = g_string_new(""); | |
| 267 | g_string_sprintfa(str, "<b>User:</b> %s<br>" | |
| 268 | "<b>Alias:</b> %s<br>", | |
| 269 | b->name, b->show); | |
| 270 | if (!nlocs) { | |
| 271 | g_string_sprintfa(str, "<br>Hidden or not logged-in"); | |
| 272 | } | |
| 273 | for (; nlocs > 0; nlocs--) { | |
| 274 | ZGetLocations(&locs, &one); | |
| 275 | g_string_sprintfa(str, "<br>At %s since %s", locs.host, | |
| 276 | locs.time); | |
| 277 | } | |
| 278 | g_show_info_text(str->str); | |
| 279 | g_string_free(str, TRUE); | |
| 1726 | 280 | } else |
| 281 | serv_got_update(zgc, b->name, nlocs, 0, 0, 0, 0, 0); | |
| 1700 | 282 | |
| 283 | free(user); | |
| 284 | } | |
| 1726 | 285 | } else { |
| 286 | char *buf, *buf2; | |
| 1700 | 287 | char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
| 288 | int len = notice.z_message_len - (ptr - notice.z_message); | |
| 1726 | 289 | int away; |
| 1700 | 290 | if (len > 0) { |
| 1726 | 291 | buf = g_malloc(len + 1); |
| 1700 | 292 | g_snprintf(buf, len + 1, "%s", ptr); |
| 293 | g_strchomp(buf); | |
| 1726 | 294 | buf2 = zephyr_to_html(buf); |
| 295 | g_free(buf); | |
| 296 | if (!g_strcasecmp(notice.z_class, "MESSAGE") && | |
| 297 | !g_strcasecmp(notice.z_class_inst, "PERSONAL")) { | |
| 298 | if (!g_strcasecmp(notice.z_message, "Automated reply:")) | |
| 299 | away = TRUE; | |
| 300 | else | |
| 301 | away = FALSE; | |
| 302 | len = MAX(BUF_LONG, strlen(buf2)); | |
| 303 | buf = g_malloc(len + 1); | |
| 304 | g_snprintf(buf, len + 1, "%s", buf2); | |
| 305 | serv_got_im(zgc, notice.z_sender, buf, 0); | |
| 306 | g_free(buf); | |
| 307 | } | |
| 308 | g_free(buf2); | |
| 1700 | 309 | } |
| 310 | } | |
| 311 | } | |
| 312 | ||
| 313 | static gint check_notify(gpointer data) | |
| 314 | { | |
| 315 | while (ZPending()) { | |
| 316 | ZNotice_t notice; | |
| 317 | struct sockaddr_in from; | |
| 318 | z_call_r(ZReceiveNotice(¬ice, &from)); | |
| 319 | ||
| 320 | switch (notice.z_kind) { | |
| 321 | case UNSAFE: | |
| 322 | case UNACKED: | |
| 323 | case ACKED: | |
| 324 | handle_message(notice, from); | |
| 325 | break; | |
| 326 | default: | |
| 327 | /* we'll just ignore things for now */ | |
| 328 | debug_printf("ZEPHYR: Unhandled Notice\n"); | |
| 329 | break; | |
| 330 | } | |
| 331 | ||
| 332 | ZFreeNotice(¬ice); | |
| 333 | } | |
| 334 | ||
| 335 | return TRUE; | |
| 336 | } | |
| 337 | ||
| 338 | static gint check_loc(gpointer data) | |
| 339 | { | |
| 340 | GSList *gr, *m; | |
| 341 | ZAsyncLocateData_t ald; | |
| 342 | ||
| 343 | ald.user = NULL; | |
| 344 | memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
| 345 | ald.version = NULL; | |
| 346 | ||
| 347 | gr = zgc->groups; | |
| 348 | while (gr) { | |
| 349 | struct group *g = gr->data; | |
| 350 | m = g->members; | |
| 351 | while (m) { | |
| 352 | struct buddy *b = m->data; | |
| 353 | char *chk; | |
| 1726 | 354 | chk = zephyr_normalize(b->name); |
| 1700 | 355 | /* doesn't matter if this fails or not; we'll just move on to the next one */ |
| 356 | ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
| 357 | m = m->next; | |
| 358 | } | |
| 359 | gr = gr->next; | |
| 360 | } | |
| 361 | ||
| 362 | return TRUE; | |
| 363 | } | |
| 364 | ||
| 365 | static char *get_exposure_level() | |
| 366 | { | |
| 367 | char *exposure = ZGetVariable("exposure"); | |
| 368 | ||
| 369 | if (!exposure) | |
| 370 | return EXPOSE_REALMVIS; | |
| 371 | if (!g_strcasecmp(exposure, EXPOSE_NONE)) | |
| 372 | return EXPOSE_NONE; | |
| 373 | if (!g_strcasecmp(exposure, EXPOSE_OPSTAFF)) | |
| 374 | return EXPOSE_OPSTAFF; | |
| 375 | if (!g_strcasecmp(exposure, EXPOSE_REALMANN)) | |
| 376 | return EXPOSE_REALMANN; | |
| 377 | if (!g_strcasecmp(exposure, EXPOSE_NETVIS)) | |
| 378 | return EXPOSE_NETVIS; | |
| 379 | if (!g_strcasecmp(exposure, EXPOSE_NETANN)) | |
| 380 | return EXPOSE_NETANN; | |
| 381 | return EXPOSE_REALMVIS; | |
| 382 | } | |
| 383 | ||
| 384 | static void strip_comments(char *str) | |
| 385 | { | |
| 386 | char *tmp = strchr(str, '#'); | |
| 387 | if (tmp) | |
| 388 | *tmp = '\0'; | |
| 389 | g_strchug(str); | |
| 390 | g_strchomp(str); | |
| 391 | } | |
| 392 | ||
| 1719 | 393 | static void process_zsubs() |
| 394 | { | |
| 395 | FILE *f; | |
| 396 | gchar *fname; | |
| 397 | gchar buff[BUFSIZ]; | |
| 398 | ||
| 399 | fname = g_strdup_printf("%s/.zephyr.subs", g_getenv("HOME")); | |
| 400 | f = fopen(fname, "r"); | |
| 401 | if (f) { | |
| 402 | char **triple; | |
| 403 | ZSubscription_t sub; | |
| 404 | char *recip; | |
| 405 | while (fgets(buff, BUFSIZ, f)) { | |
| 406 | strip_comments(buff); | |
| 407 | if (buff[0]) { | |
| 408 | triple = g_strsplit(buff, ",", 3); | |
| 409 | if (triple[0] && triple[1] && triple[2]) { | |
| 410 | sub.zsub_class = triple[0]; | |
| 411 | sub.zsub_classinst = triple[1]; | |
| 412 | if (!g_strcasecmp(triple[2], "%me%")) { | |
| 413 | recip = g_strdup_printf("%s@%s", g_getenv("USER"), | |
| 414 | ZGetRealm()); | |
| 415 | } else if (!g_strcasecmp(triple[2], "*")) { | |
| 416 | /* wildcard */ | |
| 417 | recip = g_strdup_printf("@%s", ZGetRealm()); | |
| 418 | } else { | |
| 419 | recip = g_strdup(triple[2]); | |
| 420 | } | |
| 421 | sub.zsub_recipient = recip; | |
| 422 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
| 423 | debug_printf("Zephyr: Couldn't subscribe to %s, %s, " | |
| 424 | "%s\n", | |
| 425 | sub.zsub_class, | |
| 426 | sub.zsub_classinst, | |
| 427 | sub.zsub_recipient); | |
| 428 | } | |
| 429 | g_free(recip); | |
| 430 | } | |
| 431 | g_strfreev(triple); | |
| 432 | } | |
| 433 | } | |
| 434 | } | |
| 435 | } | |
| 436 | ||
| 1700 | 437 | static void process_anyone() |
| 438 | { | |
| 439 | FILE *fd; | |
| 440 | gchar buff[BUFSIZ], *filename; | |
| 441 | ||
| 442 | filename = g_strconcat(g_get_home_dir(), "/.anyone", NULL); | |
| 443 | if ((fd = fopen(filename, "r")) != NULL) { | |
| 444 | while (fgets(buff, BUFSIZ, fd)) { | |
| 445 | strip_comments(buff); | |
| 446 | if (buff[0]) | |
| 447 | add_buddy(zgc, "Anyone", buff, buff); | |
| 448 | } | |
| 449 | fclose(fd); | |
| 450 | } | |
| 451 | g_free(filename); | |
| 452 | } | |
| 453 | ||
| 454 | static void zephyr_login(struct aim_user *user) | |
| 455 | { | |
| 456 | ZSubscription_t sub; | |
| 457 | ||
| 458 | if (zgc) { | |
| 459 | do_error_dialog("Already logged in with Zephyr", "Zephyr"); | |
| 460 | return; | |
| 461 | } | |
| 462 | ||
| 463 | zgc = new_gaim_conn(user); | |
| 464 | ||
| 465 | z_call_s(ZInitialize(), "Couldn't initialize zephyr"); | |
| 466 | z_call_s(ZOpenPort(NULL), "Couldn't open port"); | |
| 467 | z_call_s(ZSetLocation(get_exposure_level()), "Couldn't set location"); | |
| 468 | ||
| 469 | sub.zsub_class = "MESSAGE"; | |
| 470 | sub.zsub_classinst = "PERSONAL"; | |
| 471 | sub.zsub_recipient = ZGetSender(); | |
| 472 | ||
| 473 | /* we don't care if this fails. i'm lying right now. */ | |
| 1719 | 474 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { |
| 475 | debug_printf("Zephyr: Couldn't subscribe to messages!\n"); | |
| 476 | } | |
| 1700 | 477 | |
| 478 | account_online(zgc); | |
| 479 | serv_finish_login(zgc); | |
| 480 | ||
| 481 | if (bud_list_cache_exists(zgc)) | |
| 482 | do_import(NULL, zgc); | |
| 483 | process_anyone(); | |
| 1719 | 484 | /* call process_zsubs to subscribe. still commented out since I don't know |
| 485 | * how you want to handle incoming msgs from subs. | |
| 486 | process_zsubs(); */ | |
| 1700 | 487 | |
| 488 | nottimer = gtk_timeout_add(100, check_notify, NULL); | |
| 489 | loctimer = gtk_timeout_add(2000, check_loc, NULL); | |
| 490 | } | |
| 491 | ||
| 1726 | 492 | static void write_anyone() |
| 493 | { | |
| 494 | GSList *gr, *m; | |
| 495 | struct group *g; | |
| 496 | struct buddy *b; | |
| 497 | char *ptr, *fname; | |
| 498 | FILE *fd; | |
| 499 | ||
| 500 | fname = g_strdup_printf("%s/.anyone", g_get_home_dir()); | |
| 501 | fd = fopen(fname, "w"); | |
| 502 | if (!fd) { | |
| 503 | g_free(fname); | |
| 504 | return; | |
| 505 | } | |
| 506 | ||
| 507 | gr = zgc->groups; | |
| 508 | while (gr) { | |
| 509 | g = gr->data; | |
| 510 | m = g->members; | |
| 511 | while (m) { | |
| 512 | b = m->data; | |
| 513 | if ((ptr = strchr(b->name, '@')) != NULL) | |
| 514 | *ptr = '\0'; | |
| 515 | fprintf(fd, "%s\n", b->name); | |
| 516 | if (ptr) | |
| 517 | *ptr = '@'; | |
| 518 | m = m->next; | |
| 519 | } | |
| 520 | gr = gr->next; | |
| 521 | } | |
| 522 | ||
| 523 | fclose(fd); | |
| 524 | g_free(fname); | |
| 525 | } | |
| 526 | ||
| 1700 | 527 | static void zephyr_close(struct gaim_connection *gc) |
| 528 | { | |
| 1719 | 529 | g_list_foreach(pending_zloc_names, (GFunc)g_free, NULL); |
| 530 | g_list_free(pending_zloc_names); | |
| 1726 | 531 | write_anyone(); |
| 1700 | 532 | if (nottimer) |
| 533 | gtk_timeout_remove(nottimer); | |
| 534 | nottimer = 0; | |
| 535 | if (loctimer) | |
| 536 | gtk_timeout_remove(loctimer); | |
| 537 | loctimer = 0; | |
| 538 | zgc = NULL; | |
| 539 | z_call(ZCancelSubscriptions(0)); | |
| 540 | z_call(ZUnsetLocation()); | |
| 541 | z_call(ZClosePort()); | |
| 542 | } | |
| 543 | ||
| 544 | static void zephyr_add_buddy(struct gaim_connection *gc, char *buddy) { } | |
| 545 | static void zephyr_remove_buddy(struct gaim_connection *gc, char *buddy) { } | |
| 546 | ||
| 547 | static void zephyr_send_im(struct gaim_connection *gc, char *who, char *im, int away) { | |
| 548 | ZNotice_t notice; | |
| 1719 | 549 | char *buf; |
| 550 | char *sig; | |
| 551 | ||
| 1726 | 552 | if (away) |
| 553 | sig = "Automated reply:"; | |
| 554 | else { | |
| 555 | sig = ZGetVariable("zwrite-signature"); | |
| 556 | if (!sig) { | |
| 557 | sig = g_get_real_name(); | |
| 558 | } | |
| 1719 | 559 | } |
| 560 | buf = g_strdup_printf("%s%c%s", sig, '\0', im); | |
| 1700 | 561 | |
| 562 | bzero((char *)¬ice, sizeof(notice)); | |
| 563 | notice.z_kind = ACKED; | |
| 564 | notice.z_port = 0; | |
| 565 | notice.z_opcode = ""; | |
| 566 | notice.z_class = "MESSAGE"; | |
| 567 | notice.z_class_inst = "PERSONAL"; | |
| 568 | notice.z_sender = 0; | |
| 569 | notice.z_recipient = who; | |
| 570 | notice.z_default_format = | |
| 1719 | 571 | "Class $class, Instance $instance:\n" |
| 572 | "To: @bold($recipient) at $time $date\n" | |
| 573 | "From: @bold($1) <$sender>\n\n$2"; | |
| 574 | notice.z_message_len = strlen(im) + strlen(sig) + 4; | |
| 575 | notice.z_message = buf; | |
| 1700 | 576 | ZSendNotice(¬ice, ZAUTH); |
| 1719 | 577 | g_free(buf); |
| 1700 | 578 | } |
| 579 | ||
| 1726 | 580 | static char *zephyr_normalize(const char *orig) |
| 581 | { | |
| 582 | static char buf[80]; | |
| 583 | if (strchr(orig, '@')) { | |
| 584 | g_snprintf(buf, 80, "%s", orig); | |
| 585 | } else { | |
| 586 | g_snprintf(buf, 80, "%s@%s", orig, ZGetRealm()); | |
| 587 | } | |
| 588 | return buf; | |
| 589 | } | |
| 590 | ||
| 591 | static void zephyr_zloc(struct gaim_connection *gc, char *who) | |
| 592 | { | |
| 593 | ZAsyncLocateData_t ald; | |
| 594 | ||
| 595 | if (ZRequestLocations(zephyr_normalize(who), &ald, UNACKED, ZAUTH) | |
| 596 | != ZERR_NONE) { | |
| 597 | return; | |
| 598 | } | |
| 599 | pending_zloc_names = g_list_append(pending_zloc_names, | |
| 600 | g_strdup(zephyr_normalize(who))); | |
| 601 | } | |
| 602 | ||
| 603 | static void info_callback(GtkObject *obj, char *who) | |
| 604 | { | |
| 605 | zephyr_zloc(gtk_object_get_user_data(obj), who); | |
| 606 | } | |
| 607 | ||
| 608 | static void zephyr_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) | |
| 609 | { | |
| 610 | GtkWidget *button; | |
| 611 | ||
| 612 | button = gtk_menu_item_new_with_label(_("ZLocate")); | |
| 613 | gtk_signal_connect(GTK_OBJECT(button), "activate", | |
| 614 | GTK_SIGNAL_FUNC(info_callback), who); | |
| 615 | gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
| 616 | gtk_menu_append(GTK_MENU(menu), button); | |
| 617 | gtk_widget_show(button); | |
| 618 | } | |
| 619 | ||
| 620 | static void zephyr_set_away(struct gaim_connection *gc, char *state, char *msg) | |
| 621 | { | |
| 622 | if (gc->away) | |
| 623 | g_free(gc->away); | |
| 624 | gc->away = NULL; | |
| 625 | if (!g_strcasecmp(state, "Hidden")) | |
| 626 | ZSetLocation(EXPOSE_OPSTAFF); | |
| 627 | else if (!g_strcasecmp(state, "Online")) | |
| 628 | ZSetLocation(get_exposure_level()); | |
| 629 | else /* state is GAIM_AWAY_CUSTOM */ if (msg) | |
| 630 | gc->away = g_strdup(msg); | |
| 631 | } | |
| 632 | ||
| 633 | static GList *zephyr_away_states() | |
| 634 | { | |
| 635 | GList *m = NULL; | |
| 636 | ||
| 637 | m = g_list_append(m, "Online"); | |
| 638 | m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
| 639 | m = g_list_append(m, "Hidden"); | |
| 640 | ||
| 641 | return m; | |
| 642 | } | |
| 643 | ||
| 1700 | 644 | static struct prpl *my_protocol = NULL; |
| 645 | ||
| 646 | void zephyr_init(struct prpl *ret) | |
| 647 | { | |
| 648 | ret->protocol = PROTO_ZEPHYR; | |
| 649 | ret->name = zephyr_name; | |
| 650 | ret->login = zephyr_login; | |
| 651 | ret->close = zephyr_close; | |
| 652 | ret->add_buddy = zephyr_add_buddy; | |
| 653 | ret->remove_buddy = zephyr_remove_buddy; | |
| 654 | ret->send_im = zephyr_send_im; | |
| 1719 | 655 | ret->get_info = zephyr_zloc; |
| 656 | ret->normalize = zephyr_normalize; | |
| 657 | ret->buddy_menu = zephyr_buddy_menu; | |
| 1726 | 658 | ret->away_states = zephyr_away_states; |
| 659 | ret->set_away = zephyr_set_away; | |
| 1700 | 660 | |
| 661 | my_protocol = ret; | |
| 662 | } | |
| 663 | ||
| 664 | char *gaim_plugin_init(GModule *handle) | |
| 665 | { | |
| 666 | load_protocol(zephyr_init, sizeof(struct prpl)); | |
| 667 | return NULL; | |
| 668 | } | |
| 669 | ||
| 670 | void gaim_plugin_remove() | |
| 671 | { | |
| 672 | struct prpl *p = find_prpl(PROTO_ZEPHYR); | |
| 673 | if (p == my_protocol) | |
| 674 | unload_protocol(p); | |
| 675 | } |