Thu, 13 Mar 2003 06:08:56 +0000
[gaim-migrate @ 5047]
hopefully this doesn't break anything.
- Capabilities are back in the tooltips
- Jabber does the neat status thing in the buddy list
- jabber "broken" buddies are gone! woohoo!
- most of the right-click menu items moved back to where they used to live,
but Get Info remains at the top, because that's where it should be.
| 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 | |
| 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 <string.h> | |
| 31 | #include <stdlib.h> | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
32 | #include <errno.h> |
| 2086 | 33 | #include "gaim.h" |
| 34 | #include "prpl.h" | |
| 35 | #include "zephyr/zephyr.h" | |
| 36 | ||
| 37 | extern Code_t ZGetLocations(ZLocations_t *, int *); | |
| 38 | extern Code_t ZSetLocation(char *); | |
| 39 | extern Code_t ZUnsetLocation(); | |
| 40 | ||
| 41 | typedef struct _zframe zframe; | |
| 42 | typedef struct _zephyr_triple zephyr_triple; | |
| 43 | ||
| 44 | /* struct I need for zephyr_to_html */ | |
| 45 | struct _zframe { | |
| 46 | /* true for everything but @color, since inside the parens of that one is | |
| 47 | * the color. */ | |
| 48 | gboolean has_closer; | |
| 49 | /* </i>, </font>, </b>, etc. */ | |
| 50 | char *closing; | |
| 51 | /* text including the opening html thingie. */ | |
| 52 | GString *text; | |
| 53 | struct _zframe *enclosing; | |
| 54 | }; | |
| 55 | ||
| 56 | struct _zephyr_triple { | |
| 57 | char *class; | |
| 58 | char *instance; | |
| 59 | char *recipient; | |
| 60 | char *name; | |
| 61 | gboolean open; | |
| 62 | int id; | |
| 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 | ||
| 75 | static char *zephyr_normalize(const char *); | |
| 76 | ||
| 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; | |
| 82 | static GList *pending_zloc_names = NULL; | |
| 83 | static GSList *subscrips = NULL; | |
| 84 | static int last_id = 0; | |
| 85 | ||
| 86 | /* just for debugging | |
| 87 | static void handle_unknown(ZNotice_t notice) | |
| 88 | { | |
| 3630 | 89 | debug_printf("z_packet: %s\n", notice.z_packet); |
| 90 | debug_printf("z_version: %s\n", notice.z_version); | |
| 91 | debug_printf("z_kind: %d\n", notice.z_kind); | |
| 92 | debug_printf("z_class: %s\n", notice.z_class); | |
| 93 | debug_printf("z_class_inst: %s\n", notice.z_class_inst); | |
| 94 | debug_printf("z_opcode: %s\n", notice.z_opcode); | |
| 95 | debug_printf("z_sender: %s\n", notice.z_sender); | |
| 96 | debug_printf("z_recipient: %s\n", notice.z_recipient); | |
| 97 | debug_printf("z_message: %s\n", notice.z_message); | |
| 98 | debug_printf("z_message_len: %d\n", notice.z_message_len); | |
| 99 | debug_printf("\n"); | |
| 2086 | 100 | } |
| 101 | */ | |
| 102 | ||
| 103 | static zephyr_triple *new_triple(const char *c, const char *i, const char *r) | |
| 104 | { | |
| 105 | zephyr_triple *zt; | |
| 106 | zt = g_new0(zephyr_triple, 1); | |
| 107 | zt->class = g_strdup(c); | |
| 108 | zt->instance = g_strdup(i); | |
| 109 | zt->recipient = g_strdup(r); | |
| 110 | zt->name = g_strdup_printf("%s,%s,%s", c, i, r); | |
| 111 | zt->id = ++last_id; | |
| 112 | zt->open = FALSE; | |
| 113 | return zt; | |
| 114 | } | |
| 115 | ||
| 116 | static void free_triple(zephyr_triple *zt) | |
| 117 | { | |
| 118 | g_free(zt->class); | |
| 119 | g_free(zt->instance); | |
| 120 | g_free(zt->recipient); | |
| 121 | g_free(zt->name); | |
| 122 | g_free(zt); | |
| 123 | } | |
| 124 | ||
| 125 | /* returns true if zt1 is a subset of zt2, i.e. zt2 has the same thing or | |
| 126 | * wildcards in each field of zt1. */ | |
| 127 | static gboolean triple_subset(zephyr_triple *zt1, zephyr_triple *zt2) | |
| 128 | { | |
| 129 | if (g_strcasecmp(zt2->class, zt1->class) && | |
| 130 | g_strcasecmp(zt2->class, "*")) { | |
| 131 | return FALSE; | |
| 132 | } | |
| 133 | if (g_strcasecmp(zt2->instance, zt1->instance) && | |
| 134 | g_strcasecmp(zt2->instance, "*")) { | |
| 135 | return FALSE; | |
| 136 | } | |
| 137 | if (g_strcasecmp(zt2->recipient, zt1->recipient) && | |
| 138 | g_strcasecmp(zt2->recipient, "*")) { | |
| 139 | return FALSE; | |
| 140 | } | |
| 141 | return TRUE; | |
| 142 | } | |
| 143 | ||
| 144 | static zephyr_triple *find_sub_by_triple(zephyr_triple *zt) | |
| 145 | { | |
| 146 | zephyr_triple *curr_t; | |
| 147 | GSList *curr = subscrips; | |
| 148 | while (curr) { | |
| 149 | curr_t = curr->data; | |
| 150 | if (triple_subset(zt, curr_t)) | |
| 151 | return curr_t; | |
| 152 | curr = curr->next; | |
| 153 | } | |
| 154 | return NULL; | |
| 155 | } | |
| 156 | ||
| 157 | static zephyr_triple *find_sub_by_id(int id) | |
| 158 | { | |
| 159 | zephyr_triple *zt; | |
| 160 | GSList *curr = subscrips; | |
| 161 | while (curr) { | |
| 162 | zt = curr->data; | |
| 163 | if (zt->id == id) | |
| 164 | return zt; | |
| 165 | curr = curr->next; | |
| 166 | } | |
| 167 | return NULL; | |
| 168 | } | |
| 169 | ||
| 170 | /* utility macros that are useful for zephyr_to_html */ | |
| 171 | ||
| 172 | #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) | |
| 173 | #define IS_CLOSER(c) ((c == '}') || (c == ']') || (c == ')') || (c == '>')) | |
| 174 | ||
| 175 | /* this parses zephyr formatting and converts it to html. For example, if | |
| 176 | * you pass in "@{@color(blue)@i(hello)}" you should get out | |
| 177 | * "<font color=blue><i>hello</i></font>". */ | |
| 178 | static char *zephyr_to_html(char *message) | |
| 179 | { | |
| 180 | int len, cnt; | |
| 181 | zframe *frames, *curr; | |
| 182 | char *ret; | |
| 183 | ||
| 184 | frames = g_new(zframe, 1); | |
| 185 | frames->text = g_string_new(""); | |
| 186 | frames->enclosing = NULL; | |
| 187 | frames->closing = ""; | |
| 188 | frames->has_closer = FALSE; | |
| 189 | ||
| 190 | len = strlen(message); | |
| 191 | cnt = 0; | |
| 192 | while (cnt <= len) { | |
| 193 | if (message[cnt] == '@') { | |
| 194 | zframe *new_f; | |
| 195 | char *buf; | |
| 196 | int end; | |
| 197 | for (end=1; (cnt+end) <= len && | |
| 198 | !IS_OPENER(message[cnt+end]); end++); | |
| 199 | buf = g_new0(char, end); | |
| 200 | if (end) { | |
| 201 | g_snprintf(buf, end, "%s", message+cnt+1); | |
| 202 | } | |
| 203 | if (!g_strcasecmp(buf, "italic") || | |
| 204 | !g_strcasecmp(buf, "i")) { | |
| 205 | new_f = g_new(zframe, 1); | |
| 206 | new_f->enclosing = frames; | |
| 207 | new_f->text = g_string_new("<i>"); | |
| 208 | new_f->closing = "</i>"; | |
| 209 | new_f->has_closer = TRUE; | |
| 210 | frames = new_f; | |
| 211 | cnt += end+1; /* cnt points to char after opener */ | |
| 212 | } else if (!g_strcasecmp(buf, "bold") | |
| 213 | || !g_strcasecmp(buf, "b")) { | |
| 214 | new_f = g_new(zframe, 1); | |
| 215 | new_f->enclosing = frames; | |
| 216 | new_f->text = g_string_new("<b>"); | |
| 217 | new_f->closing = "</b>"; | |
| 218 | new_f->has_closer = TRUE; | |
| 219 | frames = new_f; | |
| 220 | cnt += end+1; | |
| 221 | } else if (!g_strcasecmp(buf, "color")) { | |
| 222 | cnt += end+1; | |
| 223 | new_f = g_new(zframe, 1); | |
| 224 | new_f->enclosing = frames; | |
| 225 | new_f->text = g_string_new("<font color="); | |
| 226 | for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
| 227 | g_string_append_c(new_f->text, message[cnt]); | |
| 228 | } | |
| 229 | cnt++; /* point to char after closer */ | |
| 230 | g_string_append_c(new_f->text, '>'); | |
| 231 | new_f->closing = "</font>"; | |
| 232 | new_f->has_closer = FALSE; | |
| 233 | frames = new_f; | |
| 234 | } else if (!g_strcasecmp(buf, "")) { | |
| 235 | new_f = g_new(zframe, 1); | |
| 236 | new_f->enclosing = frames; | |
| 237 | new_f->text = g_string_new(""); | |
| 238 | new_f->closing = ""; | |
| 239 | new_f->has_closer = TRUE; | |
| 240 | frames = new_f; | |
| 241 | cnt += end+1; /* cnt points to char after opener */ | |
| 242 | } else { | |
| 243 | if ((cnt+end) > len) { | |
| 244 | g_string_append_c(frames->text, '@'); | |
| 245 | cnt++; | |
| 246 | } else { | |
| 247 | /* unrecognized thingie. act like it's not there, but we | |
| 248 | * still need to take care of the corresponding closer, | |
| 249 | * make a frame that does nothing. */ | |
| 250 | new_f = g_new(zframe, 1); | |
| 251 | new_f->enclosing = frames; | |
| 252 | new_f->text = g_string_new(""); | |
| 253 | new_f->closing = ""; | |
| 254 | new_f->has_closer = TRUE; | |
| 255 | frames = new_f; | |
| 256 | cnt += end+1; /* cnt points to char after opener */ | |
| 257 | } | |
| 258 | } | |
| 259 | } else if (IS_CLOSER(message[cnt])) { | |
| 260 | zframe *popped; | |
| 261 | gboolean last_had_closer; | |
| 262 | if (frames->enclosing) { | |
| 263 | do { | |
| 264 | popped = frames; | |
| 265 | frames = frames->enclosing; | |
| 266 | g_string_append(frames->text, popped->text->str); | |
| 267 | g_string_append(frames->text, popped->closing); | |
| 268 | g_string_free(popped->text, TRUE); | |
| 269 | last_had_closer = popped->has_closer; | |
| 270 | g_free(popped); | |
| 271 | } while (frames && frames->enclosing && !last_had_closer); | |
| 272 | } else { | |
| 273 | g_string_append_c(frames->text, message[cnt]); | |
| 274 | } | |
| 275 | cnt++; | |
| 276 | } else if (message[cnt] == '\n') { | |
| 277 | g_string_append(frames->text, "<br>"); | |
| 278 | cnt++; | |
| 279 | } else { | |
| 280 | g_string_append_c(frames->text, message[cnt++]); | |
| 281 | } | |
| 282 | } | |
| 283 | /* go through all the stuff that they didn't close */ | |
| 284 | while (frames->enclosing) { | |
| 285 | curr = frames; | |
| 286 | g_string_append(frames->enclosing->text, frames->text->str); | |
| 287 | g_string_append(frames->enclosing->text, frames->closing); | |
| 288 | g_string_free(frames->text, TRUE); | |
| 289 | frames = frames->enclosing; | |
| 290 | g_free(curr); | |
| 291 | } | |
| 292 | ret = frames->text->str; | |
| 293 | g_string_free(frames->text, FALSE); | |
| 294 | g_free(frames); | |
| 295 | return ret; | |
| 296 | } | |
| 297 | ||
| 298 | static gboolean pending_zloc(char *who) | |
| 299 | { | |
| 300 | GList *curr; | |
| 301 | for (curr = pending_zloc_names; curr != NULL; curr = curr->next) { | |
| 302 | if (!g_strcasecmp(who, (char*)curr->data)) { | |
| 303 | g_free((char*)curr->data); | |
| 304 | pending_zloc_names = g_list_remove(pending_zloc_names, curr->data); | |
| 305 | return TRUE; | |
| 306 | } | |
| 307 | } | |
| 308 | return FALSE; | |
| 309 | } | |
| 310 | ||
| 311 | static void handle_message(ZNotice_t notice, struct sockaddr_in from) | |
| 312 | { | |
| 313 | if (!g_strcasecmp(notice.z_class, LOGIN_CLASS)) { | |
| 3277 | 314 | /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */ |
| 2086 | 315 | } else if (!g_strcasecmp(notice.z_class, LOCATE_CLASS)) { |
| 316 | if (!g_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
| 317 | int nlocs; | |
| 318 | char *user; | |
| 319 | struct buddy *b; | |
| 320 | ||
| 321 | if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) | |
| 322 | return; | |
| 4687 | 323 | if ((b = gaim_find_buddy(zgc->account, user)) == NULL) { |
| 2086 | 324 | char *e = strchr(user, '@'); |
| 325 | if (e) *e = '\0'; | |
| 4687 | 326 | b = gaim_find_buddy(zgc->account, user); |
| 2086 | 327 | } |
| 328 | if (!b) { | |
| 329 | free(user); | |
| 330 | return; | |
| 331 | } | |
| 332 | if (pending_zloc(b->name)) { | |
| 333 | ZLocations_t locs; | |
| 334 | int one = 1; | |
| 335 | GString *str = g_string_new(""); | |
| 336 | g_string_sprintfa(str, "<b>User:</b> %s<br>" | |
| 337 | "<b>Alias:</b> %s<br>", | |
| 4227 | 338 | b->name, b->alias); |
| 2086 | 339 | if (!nlocs) { |
| 340 | g_string_sprintfa(str, "<br>Hidden or not logged-in"); | |
| 341 | } | |
| 342 | for (; nlocs > 0; nlocs--) { | |
| 343 | ZGetLocations(&locs, &one); | |
| 344 | g_string_sprintfa(str, "<br>At %s since %s", locs.host, | |
| 345 | locs.time); | |
| 346 | } | |
|
2791
26bdc3e83257
[gaim-migrate @ 2804]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2773
diff
changeset
|
347 | g_show_info_text(NULL, NULL, 2, str->str, NULL); |
| 2086 | 348 | g_string_free(str, TRUE); |
| 349 | } else | |
| 4732 | 350 | serv_got_update(zgc, b->name, nlocs, 0, 0, 0, 0); |
| 2086 | 351 | |
| 352 | free(user); | |
| 353 | } | |
| 354 | } else { | |
| 355 | char *buf, *buf2; | |
| 2804 | 356 | char *send_inst; |
| 3277 | 357 | char *realmptr; |
| 358 | char *sendertmp; | |
| 2086 | 359 | char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
| 360 | int len = notice.z_message_len - (ptr - notice.z_message); | |
| 361 | int away; | |
| 362 | if (len > 0) { | |
| 363 | buf = g_malloc(len + 1); | |
| 364 | g_snprintf(buf, len + 1, "%s", ptr); | |
| 365 | g_strchomp(buf); | |
| 366 | buf2 = zephyr_to_html(buf); | |
| 367 | g_free(buf); | |
| 368 | if (!g_strcasecmp(notice.z_class, "MESSAGE") && | |
| 4687 | 369 | !g_strcasecmp(notice.z_class_inst, "PERSONAL")) { |
| 2086 | 370 | if (!g_strcasecmp(notice.z_message, "Automated reply:")) |
| 371 | away = TRUE; | |
| 372 | else | |
| 373 | away = FALSE; | |
|
2856
046ed5e89321
[gaim-migrate @ 2869]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2804
diff
changeset
|
374 | serv_got_im(zgc, notice.z_sender, buf2, 0, time(NULL), -1); |
| 2086 | 375 | } else { |
| 376 | zephyr_triple *zt1, *zt2; | |
| 377 | zt1 = new_triple(notice.z_class, notice.z_class_inst, | |
| 4687 | 378 | notice.z_recipient); |
| 2086 | 379 | zt2 = find_sub_by_triple(zt1); |
| 380 | if (!zt2) { | |
| 381 | /* we shouldn't be subscribed to this message. ignore. */ | |
| 382 | } else { | |
| 383 | if (!zt2->open) { | |
| 384 | zt2->open = TRUE; | |
| 385 | serv_got_joined_chat(zgc, zt2->id, zt2->name); | |
| 386 | } | |
| 3277 | 387 | /* If the person is in the default Realm, then strip the |
| 388 | Realm from the sender field */ | |
| 389 | sendertmp = g_strdup_printf("%s",notice.z_sender); | |
| 4682 | 390 | if ((realmptr = strchr(sendertmp,'@')) != NULL) { |
| 4588 | 391 | realmptr++; |
| 392 | if (!g_strcasecmp(realmptr,ZGetRealm())) { | |
| 393 | realmptr--; | |
| 394 | sprintf(realmptr,"%c",'\0'); | |
| 395 | send_inst = g_strdup_printf("%s %s",sendertmp, | |
| 396 | notice.z_class_inst); | |
| 397 | } else { | |
| 398 | send_inst = g_strdup_printf("%s %s",notice.z_sender, | |
| 399 | notice.z_class_inst); | |
| 400 | } | |
| 3277 | 401 | } else { |
| 4588 | 402 | send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); |
| 3277 | 403 | } |
| 2804 | 404 | serv_got_chat_in(zgc, zt2->id, send_inst, FALSE, |
| 4687 | 405 | buf2, time(NULL)); |
| 3277 | 406 | g_free(sendertmp); |
| 2804 | 407 | g_free(send_inst); |
| 2086 | 408 | } |
| 409 | free_triple(zt1); | |
| 410 | } | |
| 411 | g_free(buf2); | |
| 412 | } | |
| 413 | } | |
| 414 | } | |
| 415 | ||
| 416 | static gint check_notify(gpointer data) | |
| 417 | { | |
| 418 | while (ZPending()) { | |
| 419 | ZNotice_t notice; | |
| 420 | struct sockaddr_in from; | |
| 421 | z_call_r(ZReceiveNotice(¬ice, &from)); | |
| 422 | ||
| 423 | switch (notice.z_kind) { | |
| 424 | case UNSAFE: | |
| 425 | case UNACKED: | |
| 426 | case ACKED: | |
| 427 | handle_message(notice, from); | |
| 428 | break; | |
| 429 | default: | |
| 430 | /* we'll just ignore things for now */ | |
| 431 | debug_printf("ZEPHYR: Unhandled Notice\n"); | |
| 432 | break; | |
| 433 | } | |
| 434 | ||
| 435 | ZFreeNotice(¬ice); | |
| 436 | } | |
| 437 | ||
| 438 | return TRUE; | |
| 439 | } | |
| 440 | ||
| 441 | static gint check_loc(gpointer data) | |
| 442 | { | |
| 443 | GSList *gr, *m; | |
| 444 | ZAsyncLocateData_t ald; | |
| 445 | ||
| 446 | ald.user = NULL; | |
| 447 | memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
| 448 | ald.version = NULL; | |
| 449 | ||
| 4349 | 450 | gr = groups; |
| 2086 | 451 | while (gr) { |
| 452 | struct group *g = gr->data; | |
| 453 | m = g->members; | |
| 454 | while (m) { | |
| 455 | struct buddy *b = m->data; | |
| 4491 | 456 | if(b->account->gc == zgc) { |
| 4349 | 457 | char *chk; |
| 458 | chk = zephyr_normalize(b->name); | |
| 459 | /* doesn't matter if this fails or not; we'll just move on to the next one */ | |
| 460 | ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
| 461 | free(ald.user); | |
| 462 | free(ald.version); | |
| 463 | } | |
| 2086 | 464 | m = m->next; |
| 465 | } | |
| 466 | gr = gr->next; | |
| 467 | } | |
| 468 | ||
| 469 | return TRUE; | |
| 470 | } | |
| 471 | ||
| 472 | static char *get_exposure_level() | |
| 473 | { | |
| 474 | char *exposure = ZGetVariable("exposure"); | |
| 475 | ||
| 476 | if (!exposure) | |
| 477 | return EXPOSE_REALMVIS; | |
| 478 | if (!g_strcasecmp(exposure, EXPOSE_NONE)) | |
| 479 | return EXPOSE_NONE; | |
| 480 | if (!g_strcasecmp(exposure, EXPOSE_OPSTAFF)) | |
| 481 | return EXPOSE_OPSTAFF; | |
| 482 | if (!g_strcasecmp(exposure, EXPOSE_REALMANN)) | |
| 483 | return EXPOSE_REALMANN; | |
| 484 | if (!g_strcasecmp(exposure, EXPOSE_NETVIS)) | |
| 485 | return EXPOSE_NETVIS; | |
| 486 | if (!g_strcasecmp(exposure, EXPOSE_NETANN)) | |
| 487 | return EXPOSE_NETANN; | |
| 488 | return EXPOSE_REALMVIS; | |
| 489 | } | |
| 490 | ||
| 491 | static void strip_comments(char *str) | |
| 492 | { | |
| 493 | char *tmp = strchr(str, '#'); | |
| 494 | if (tmp) | |
| 495 | *tmp = '\0'; | |
| 496 | g_strchug(str); | |
| 497 | g_strchomp(str); | |
| 498 | } | |
| 499 | ||
| 500 | static void process_zsubs() | |
| 501 | { | |
| 502 | FILE *f; | |
| 503 | gchar *fname; | |
| 504 | gchar buff[BUFSIZ]; | |
| 505 | ||
| 3630 | 506 | fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
| 2086 | 507 | f = fopen(fname, "r"); |
| 508 | if (f) { | |
| 509 | char **triple; | |
| 510 | ZSubscription_t sub; | |
| 511 | char *recip; | |
| 512 | while (fgets(buff, BUFSIZ, f)) { | |
| 513 | strip_comments(buff); | |
| 514 | if (buff[0]) { | |
| 515 | triple = g_strsplit(buff, ",", 3); | |
| 3277 | 516 | if (triple[0] && triple[1] ) { |
| 4588 | 517 | /* char *tmp = g_strdup_printf("%s@%s", g_getenv("USER"), |
| 518 | ZGetRealm());*/ | |
| 519 | char *tmp = g_strdup_printf("%s",ZGetSender()); | |
| 2804 | 520 | char *atptr; |
| 2086 | 521 | sub.zsub_class = triple[0]; |
| 522 | sub.zsub_classinst = triple[1]; | |
| 3277 | 523 | if(triple[2] == NULL) { |
| 524 | recip = g_malloc0(1); | |
| 525 | } else if (!g_strcasecmp(triple[2], "%me%")) { | |
| 4588 | 526 | recip = g_strdup_printf("%s",ZGetSender()); |
| 2086 | 527 | } else if (!g_strcasecmp(triple[2], "*")) { |
| 2804 | 528 | /* wildcard |
| 529 | * form of class,instance,* */ | |
| 530 | recip = g_malloc0(1); | |
| 531 | } else if (!g_strcasecmp(triple[2], tmp)) { | |
| 532 | /* form of class,instance,aatharuv@ATHENA.MIT.EDU */ | |
| 533 | recip = g_strdup(triple[2]); | |
| 534 | } else if ((atptr = strchr(triple[2], '@')) != NULL) { | |
| 535 | /* form of class,instance,*@ANDREW.CMU.EDU | |
| 536 | * class,instance,@ANDREW.CMU.EDU | |
| 537 | * If realm is local realm, blank recipient, else | |
| 538 | * @REALM-NAME | |
| 539 | */ | |
| 540 | char *realmat = g_strdup_printf("@%s", ZGetRealm()); | |
| 541 | if (!g_strcasecmp(atptr, realmat)) | |
| 542 | recip = g_malloc0(1); | |
| 543 | else | |
| 544 | recip = g_strdup(atptr); | |
| 545 | g_free(realmat); | |
| 2086 | 546 | } else { |
| 547 | recip = g_strdup(triple[2]); | |
| 548 | } | |
| 2804 | 549 | g_free(tmp); |
| 2086 | 550 | sub.zsub_recipient = recip; |
| 551 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
| 552 | debug_printf("Zephyr: Couldn't subscribe to %s, %s, " | |
| 553 | "%s\n", | |
| 554 | sub.zsub_class, | |
| 555 | sub.zsub_classinst, | |
| 556 | sub.zsub_recipient); | |
| 557 | } | |
| 558 | subscrips = g_slist_append(subscrips, | |
| 559 | new_triple(triple[0], triple[1], recip)); | |
| 560 | g_free(recip); | |
| 561 | } | |
| 562 | g_strfreev(triple); | |
| 563 | } | |
| 564 | } | |
| 565 | } | |
| 566 | } | |
| 567 | ||
| 568 | static void process_anyone() | |
| 569 | { | |
| 570 | FILE *fd; | |
| 571 | gchar buff[BUFSIZ], *filename; | |
| 4687 | 572 | struct group *g = gaim_group_new("Anyone"); |
| 573 | struct buddy *b; | |
| 574 | ||
| 3630 | 575 | filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); |
| 2086 | 576 | if ((fd = fopen(filename, "r")) != NULL) { |
| 577 | while (fgets(buff, BUFSIZ, fd)) { | |
| 578 | strip_comments(buff); | |
| 4687 | 579 | if (buff[0]) { |
| 580 | b = gaim_buddy_new(zgc->account, buff, NULL); | |
| 581 | gaim_blist_add_buddy(b, g, NULL); | |
| 582 | } | |
| 2086 | 583 | } |
| 584 | fclose(fd); | |
| 585 | } | |
| 586 | g_free(filename); | |
| 587 | } | |
| 588 | ||
| 4491 | 589 | static void zephyr_login(struct gaim_account *account) |
| 2086 | 590 | { |
| 591 | ZSubscription_t sub; | |
| 592 | ||
| 593 | if (zgc) { | |
| 3427 | 594 | do_error_dialog("Already logged in with Zephyr", "Because Zephyr uses your system username, you are unable to " |
| 4588 | 595 | "have multiple accounts on it when logged in as the same user.", GAIM_ERROR); |
| 2086 | 596 | return; |
| 597 | } | |
| 598 | ||
| 4491 | 599 | zgc = new_gaim_conn(account); |
| 2086 | 600 | |
| 601 | z_call_s(ZInitialize(), "Couldn't initialize zephyr"); | |
| 602 | z_call_s(ZOpenPort(NULL), "Couldn't open port"); | |
| 603 | z_call_s(ZSetLocation(get_exposure_level()), "Couldn't set location"); | |
| 604 | ||
| 605 | sub.zsub_class = "MESSAGE"; | |
| 606 | sub.zsub_classinst = "PERSONAL"; | |
| 607 | sub.zsub_recipient = ZGetSender(); | |
| 608 | ||
| 609 | /* we don't care if this fails. i'm lying right now. */ | |
| 610 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
| 611 | debug_printf("Zephyr: Couldn't subscribe to messages!\n"); | |
| 612 | } | |
| 613 | ||
| 614 | account_online(zgc); | |
| 615 | serv_finish_login(zgc); | |
| 616 | ||
| 617 | process_anyone(); | |
| 618 | process_zsubs(); | |
| 619 | ||
|
2131
ef072ae1b2b8
[gaim-migrate @ 2141]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2123
diff
changeset
|
620 | nottimer = g_timeout_add(100, check_notify, NULL); |
| 2804 | 621 | loctimer = g_timeout_add(20000, check_loc, NULL); |
| 2086 | 622 | } |
| 623 | ||
| 624 | static void write_zsubs() | |
| 625 | { | |
| 626 | GSList *s = subscrips; | |
| 627 | zephyr_triple *zt; | |
| 628 | FILE *fd; | |
| 629 | char *fname; | |
| 630 | ||
| 3277 | 631 | char** triple; |
| 3630 | 632 | fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
| 2086 | 633 | fd = fopen(fname, "w"); |
| 634 | ||
| 635 | if (!fd) { | |
| 636 | g_free(fname); | |
| 637 | return; | |
| 638 | } | |
| 639 | ||
| 640 | while (s) { | |
| 641 | zt = s->data; | |
| 3277 | 642 | triple = g_strsplit(zt->name,",",3); |
| 643 | if (triple[2] != NULL) { | |
| 644 | if (!g_strcasecmp(triple[2], "")) { | |
| 645 | fprintf(fd, "%s,%s,*\n", triple[0], triple[1]); | |
| 646 | } else if (!g_strcasecmp(triple[2], ZGetSender())) { | |
| 647 | fprintf(fd, "%s,%s,%%me%%\n",triple[0],triple[1]); | |
| 648 | } else { | |
| 649 | fprintf(fd, "%s\n", zt->name); | |
| 650 | } | |
| 651 | } else { | |
| 652 | fprintf(fd, "%s,%s,*\n",triple[0], triple[1]); | |
| 653 | } | |
| 654 | g_free(triple); | |
| 2086 | 655 | s = s->next; |
| 656 | } | |
| 657 | g_free(fname); | |
| 658 | fclose(fd); | |
| 659 | } | |
| 660 | ||
| 661 | static void write_anyone() | |
| 662 | { | |
| 663 | GSList *gr, *m; | |
| 664 | struct group *g; | |
| 665 | struct buddy *b; | |
| 3277 | 666 | char *ptr, *fname, *ptr2; |
| 2086 | 667 | FILE *fd; |
| 668 | ||
| 3630 | 669 | fname = g_strdup_printf("%s/.anyone", gaim_home_dir()); |
| 2086 | 670 | fd = fopen(fname, "w"); |
| 671 | if (!fd) { | |
| 672 | g_free(fname); | |
| 673 | return; | |
| 674 | } | |
| 675 | ||
| 4349 | 676 | gr = groups; |
| 2086 | 677 | while (gr) { |
| 678 | g = gr->data; | |
| 679 | m = g->members; | |
| 680 | while (m) { | |
| 681 | b = m->data; | |
| 4491 | 682 | if(b->account->gc == zgc) { |
| 4349 | 683 | if ((ptr = strchr(b->name, '@')) != NULL) { |
| 684 | ptr2 = ptr + 1; | |
| 685 | /* We should only strip the realm name if the principal | |
| 686 | is in the user's realm | |
| 687 | */ | |
| 688 | if (!g_strcasecmp(ptr2,ZGetRealm())) { | |
| 689 | *ptr = '\0'; | |
| 690 | } | |
| 3277 | 691 | } |
| 4349 | 692 | fprintf(fd, "%s\n", b->name); |
| 693 | if (ptr) | |
| 694 | *ptr = '@'; | |
| 3277 | 695 | } |
| 2086 | 696 | m = m->next; |
| 697 | } | |
| 698 | gr = gr->next; | |
| 699 | } | |
| 700 | ||
| 701 | fclose(fd); | |
| 702 | g_free(fname); | |
| 703 | } | |
| 704 | ||
| 705 | static void zephyr_close(struct gaim_connection *gc) | |
| 706 | { | |
| 707 | GList *l; | |
| 708 | GSList *s; | |
| 709 | l = pending_zloc_names; | |
| 710 | while (l) { | |
| 711 | g_free((char*)l->data); | |
| 712 | l = l->next; | |
| 713 | } | |
| 714 | g_list_free(pending_zloc_names); | |
| 715 | ||
| 716 | write_anyone(); | |
| 717 | write_zsubs(); | |
| 718 | ||
| 719 | s = subscrips; | |
| 720 | while (s) { | |
| 721 | free_triple((zephyr_triple*)s->data); | |
| 722 | s = s->next; | |
| 723 | } | |
| 724 | g_slist_free(subscrips); | |
| 725 | ||
| 726 | if (nottimer) | |
|
2131
ef072ae1b2b8
[gaim-migrate @ 2141]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2123
diff
changeset
|
727 | g_source_remove(nottimer); |
| 2086 | 728 | nottimer = 0; |
| 729 | if (loctimer) | |
|
2131
ef072ae1b2b8
[gaim-migrate @ 2141]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2123
diff
changeset
|
730 | g_source_remove(loctimer); |
| 2086 | 731 | loctimer = 0; |
| 732 | zgc = NULL; | |
| 733 | z_call(ZCancelSubscriptions(0)); | |
| 734 | z_call(ZUnsetLocation()); | |
| 735 | z_call(ZClosePort()); | |
| 736 | } | |
| 737 | ||
| 3466 | 738 | static void zephyr_add_buddy(struct gaim_connection *gc, const char *buddy) { } |
|
2681
73cd94b9e78e
[gaim-migrate @ 2694]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2501
diff
changeset
|
739 | static void zephyr_remove_buddy(struct gaim_connection *gc, char *buddy, char *group) { } |
| 2086 | 740 | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
741 | static int zephyr_chat_send(struct gaim_connection *gc, int id, char *im) |
| 2086 | 742 | { |
| 743 | ZNotice_t notice; | |
| 744 | zephyr_triple *zt; | |
| 745 | char *buf; | |
| 746 | const char *sig; | |
| 747 | ||
| 748 | zt = find_sub_by_id(id); | |
| 749 | if (!zt) | |
| 750 | /* this should never happen. */ | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
751 | return -EINVAL; |
| 2086 | 752 | |
| 753 | sig = ZGetVariable("zwrite-signature"); | |
| 754 | if (!sig) { | |
| 755 | sig = g_get_real_name(); | |
| 756 | } | |
| 757 | buf = g_strdup_printf("%s%c%s", sig, '\0', im); | |
| 758 | ||
| 759 | bzero((char *)¬ice, sizeof(notice)); | |
| 760 | notice.z_kind = ACKED; | |
| 761 | notice.z_port = 0; | |
| 762 | notice.z_opcode = ""; | |
| 763 | notice.z_class = zt->class; | |
| 764 | notice.z_class_inst = zt->instance; | |
| 765 | if (!g_strcasecmp(zt->recipient, "*")) | |
| 766 | notice.z_recipient = zephyr_normalize(""); | |
| 767 | else | |
| 768 | notice.z_recipient = zephyr_normalize(zt->recipient); | |
| 769 | notice.z_sender = 0; | |
| 770 | notice.z_default_format = | |
| 771 | "Class $class, Instance $instance:\n" | |
| 772 | "To: @bold($recipient) at $time $date\n" | |
| 773 | "From: @bold($1) <$sender>\n\n$2"; | |
| 774 | notice.z_message_len = strlen(im) + strlen(sig) + 4; | |
| 775 | notice.z_message = buf; | |
| 776 | ZSendNotice(¬ice, ZAUTH); | |
| 777 | g_free(buf); | |
|
2167
cbb558585911
[gaim-migrate @ 2177]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2162
diff
changeset
|
778 | return 0; |
| 2086 | 779 | } |
| 780 | ||
| 3033 | 781 | static int zephyr_send_im(struct gaim_connection *gc, char *who, char *im, int len, int flags) { |
| 2086 | 782 | ZNotice_t notice; |
| 783 | char *buf; | |
| 784 | const char *sig; | |
| 785 | ||
|
2231
9d8593ab093e
[gaim-migrate @ 2241]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2205
diff
changeset
|
786 | if (flags & IM_FLAG_AWAY) |
| 2086 | 787 | sig = "Automated reply:"; |
| 788 | else { | |
| 789 | sig = ZGetVariable("zwrite-signature"); | |
| 790 | if (!sig) { | |
| 791 | sig = g_get_real_name(); | |
| 792 | } | |
| 793 | } | |
| 794 | buf = g_strdup_printf("%s%c%s", sig, '\0', im); | |
| 795 | ||
| 796 | bzero((char *)¬ice, sizeof(notice)); | |
| 797 | notice.z_kind = ACKED; | |
| 798 | notice.z_port = 0; | |
| 799 | notice.z_opcode = ""; | |
| 800 | notice.z_class = "MESSAGE"; | |
| 801 | notice.z_class_inst = "PERSONAL"; | |
| 802 | notice.z_sender = 0; | |
| 803 | notice.z_recipient = who; | |
| 804 | notice.z_default_format = | |
| 805 | "Class $class, Instance $instance:\n" | |
| 806 | "To: @bold($recipient) at $time $date\n" | |
| 807 | "From: @bold($1) <$sender>\n\n$2"; | |
| 808 | notice.z_message_len = strlen(im) + strlen(sig) + 4; | |
| 809 | notice.z_message = buf; | |
| 810 | ZSendNotice(¬ice, ZAUTH); | |
| 811 | g_free(buf); | |
|
2303
18171aa8cd37
[gaim-migrate @ 2313]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2231
diff
changeset
|
812 | return 1; |
| 2086 | 813 | } |
| 814 | ||
| 815 | static char *zephyr_normalize(const char *orig) | |
| 816 | { | |
| 817 | static char buf[80]; | |
| 818 | if (strchr(orig, '@')) { | |
| 819 | g_snprintf(buf, 80, "%s", orig); | |
| 820 | } else { | |
| 821 | g_snprintf(buf, 80, "%s@%s", orig, ZGetRealm()); | |
| 822 | } | |
| 823 | return buf; | |
| 824 | } | |
| 825 | ||
| 826 | static void zephyr_zloc(struct gaim_connection *gc, char *who) | |
| 827 | { | |
| 828 | ZAsyncLocateData_t ald; | |
| 829 | ||
| 830 | if (ZRequestLocations(zephyr_normalize(who), &ald, UNACKED, ZAUTH) | |
| 831 | != ZERR_NONE) { | |
| 832 | return; | |
| 833 | } | |
| 834 | pending_zloc_names = g_list_append(pending_zloc_names, | |
| 835 | g_strdup(zephyr_normalize(who))); | |
| 836 | } | |
| 837 | ||
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
838 | static GList *zephyr_buddy_menu(struct gaim_connection *gc, char *who) |
| 2086 | 839 | { |
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
840 | GList *m = NULL; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
841 | struct proto_buddy_menu *pbm; |
| 2086 | 842 | |
|
2170
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
843 | pbm = g_new0(struct proto_buddy_menu, 1); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
844 | pbm->label = _("ZLocate"); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
845 | pbm->callback = zephyr_zloc; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
846 | pbm->gc = gc; |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
847 | m = g_list_append(m, pbm); |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
848 | |
|
5c93594ff522
[gaim-migrate @ 2180]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2167
diff
changeset
|
849 | return m; |
| 2086 | 850 | } |
| 851 | ||
| 852 | static void zephyr_set_away(struct gaim_connection *gc, char *state, char *msg) | |
| 853 | { | |
|
4111
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
854 | if (gc->away) { |
| 2086 | 855 | g_free(gc->away); |
|
4111
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
856 | gc->away = NULL; |
|
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
857 | } |
|
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
858 | |
|
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
859 | if (!g_strcasecmp(state, "Hidden")) { |
| 2086 | 860 | ZSetLocation(EXPOSE_OPSTAFF); |
|
4111
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
861 | gc->away = g_strdup(""); |
|
93b27900416e
[gaim-migrate @ 4326]
Robert McQueen <robot101@debian.org>
parents:
3867
diff
changeset
|
862 | } else if (!g_strcasecmp(state, "Online")) |
| 2086 | 863 | ZSetLocation(get_exposure_level()); |
| 864 | else /* state is GAIM_AWAY_CUSTOM */ if (msg) | |
| 865 | gc->away = g_strdup(msg); | |
| 866 | } | |
| 867 | ||
|
2501
5e1fa4926c93
[gaim-migrate @ 2514]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2417
diff
changeset
|
868 | static GList *zephyr_away_states(struct gaim_connection *gc) |
| 2086 | 869 | { |
| 870 | GList *m = NULL; | |
| 871 | ||
| 872 | m = g_list_append(m, "Online"); | |
| 873 | m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
| 874 | m = g_list_append(m, "Hidden"); | |
| 875 | ||
| 876 | return m; | |
| 877 | } | |
| 878 | ||
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
879 | static GList *zephyr_chat_info(struct gaim_connection *gc) { |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
880 | GList *m = NULL; |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
881 | struct proto_chat_entry *pce; |
| 2086 | 882 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
883 | pce = g_new0(struct proto_chat_entry, 1); |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
884 | pce->label = _("Class:"); |
| 3158 | 885 | m = g_list_append(m, pce); |
| 2086 | 886 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
887 | pce = g_new0(struct proto_chat_entry, 1); |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
888 | pce->label = _("Instance:"); |
| 3158 | 889 | m = g_list_append(m, pce); |
| 2086 | 890 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
891 | pce = g_new0(struct proto_chat_entry, 1); |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
892 | pce->label = _("Recipient:"); |
| 3158 | 893 | m = g_list_append(m, pce); |
| 2086 | 894 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
895 | return m; |
| 2086 | 896 | } |
| 897 | ||
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
898 | static void zephyr_join_chat(struct gaim_connection *gc, GList *data) |
| 2086 | 899 | { |
| 900 | ZSubscription_t sub; | |
| 901 | zephyr_triple *zt1, *zt2; | |
| 902 | const char *classname; | |
| 903 | const char *instname; | |
| 904 | const char *recip; | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
905 | |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
906 | if (!data || !data->next || !data->next->next) |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
907 | return; |
| 2086 | 908 | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
909 | classname = data->data; |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
910 | instname = data->next->data; |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
911 | recip = data->next->next->data; |
|
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
912 | if (!g_strcasecmp(recip, "%me%")) |
| 4588 | 913 | recip = ZGetSender(); |
| 2086 | 914 | |
| 915 | zt1 = new_triple(classname, instname, recip); | |
| 916 | zt2 = find_sub_by_triple(zt1); | |
| 917 | if (zt2) { | |
| 918 | free_triple(zt1); | |
| 919 | if (!zt2->open) | |
| 920 | serv_got_joined_chat(gc, zt2->id, zt2->name); | |
| 921 | return; | |
| 922 | } | |
| 923 | ||
| 924 | sub.zsub_class = zt1->class; | |
| 925 | sub.zsub_classinst = zt1->instance; | |
| 926 | sub.zsub_recipient = zt1->recipient; | |
| 927 | ||
| 928 | if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { | |
| 929 | free_triple(zt1); | |
| 930 | return; | |
| 931 | } | |
| 932 | ||
| 933 | subscrips = g_slist_append(subscrips, zt1); | |
| 934 | zt1->open = TRUE; | |
| 935 | serv_got_joined_chat(gc, zt1->id, zt1->name); | |
| 936 | } | |
| 937 | ||
| 938 | static void zephyr_chat_leave(struct gaim_connection *gc, int id) | |
| 939 | { | |
| 940 | zephyr_triple *zt; | |
| 941 | zt = find_sub_by_id(id); | |
| 942 | if (zt) { | |
| 943 | zt->open = FALSE; | |
| 944 | zt->id = ++last_id; | |
| 945 | } | |
| 946 | } | |
| 947 | ||
| 948 | static struct prpl *my_protocol = NULL; | |
| 949 | ||
| 950 | void zephyr_init(struct prpl *ret) | |
| 951 | { | |
| 952 | ret->protocol = PROTO_ZEPHYR; | |
|
2100
58ebaa769cb2
[gaim-migrate @ 2110]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2086
diff
changeset
|
953 | ret->options = OPT_PROTO_NO_PASSWORD; |
| 3572 | 954 | ret->name = g_strdup("Zephyr"); |
| 2086 | 955 | ret->login = zephyr_login; |
| 956 | ret->close = zephyr_close; | |
| 957 | ret->add_buddy = zephyr_add_buddy; | |
| 958 | ret->remove_buddy = zephyr_remove_buddy; | |
| 959 | ret->send_im = zephyr_send_im; | |
| 960 | ret->get_info = zephyr_zloc; | |
| 961 | ret->normalize = zephyr_normalize; | |
| 962 | ret->buddy_menu = zephyr_buddy_menu; | |
| 963 | ret->away_states = zephyr_away_states; | |
| 964 | ret->set_away = zephyr_set_away; | |
|
2205
68c42ce8eba6
[gaim-migrate @ 2215]
Eric Warmenhoven <warmenhoven@yahoo.com>
parents:
2170
diff
changeset
|
965 | ret->chat_info = zephyr_chat_info; |
| 2086 | 966 | ret->join_chat = zephyr_join_chat; |
| 967 | ret->chat_send = zephyr_chat_send; | |
| 968 | ret->chat_leave = zephyr_chat_leave; | |
| 969 | ||
| 970 | my_protocol = ret; | |
| 971 | } | |
| 972 | ||
| 973 | #ifndef STATIC | |
| 974 | ||
| 3867 | 975 | G_MODULE_EXPORT void gaim_prpl_init(struct prpl *prpl) |
| 2086 | 976 | { |
| 3572 | 977 | zephyr_init(prpl); |
| 978 | prpl->plug->desc.api_version = PLUGIN_API_VERSION; | |
| 2086 | 979 | } |
| 980 | ||
| 981 | ||
| 982 | #endif |