Mercurial > pidgin
annotate src/protocols/zephyr/zephyr.c @ 9642:8901ef16f310
[gaim-migrate @ 10490]
Some changes that don't affect anything. Ethan might want to do
something with this function? I'm too lazy to read the gaim-devel
emails in detail.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 02 Aug 2004 03:33:00 +0000 |
| parents | a6362795bf2c |
| children | db62420a53a2 |
| rev | line source |
|---|---|
| 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
0909ebf6fb28
[gaim-migrate @ 7649]
Christian Hammond <chipx86@chipx86.com>
parents:
7070
diff
changeset
|
7 * Jag/Sean Dilda <agrajag@linuxpower.org>/<smdilda@unity.ncsu.edu> |
|
0909ebf6fb28
[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
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
25 /* XXX eww */ |
|
059d95c67cda
[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
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
29 #include "debug.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
30 #include "multi.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
31 #include "notify.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
32 #include "prpl.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
33 #include "server.h" |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
34 #include "util.h" |
| 9434 | 35 #include "cmds.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
36 |
|
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
37 #include "zephyr/zephyr.h" |
| 9478 | 38 #include "internal.h" |
|
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5717
diff
changeset
|
39 |
| 8386 | 40 #include <strings.h> |
| 41 | |
| 8560 | 42 #define ZEPHYR_FALLBACK_CHARSET "ISO-8859-1" |
| 43 | |
| 9478 | 44 /* these are deliberately high, since most people don't send multiple "PING"s */ |
| 45 #define ZEPHYR_TYPING_SEND_TIMEOUT 15 | |
| 46 #define ZEPHYR_TYPING_RECV_TIMEOUT 10 | |
| 47 | |
| 2086 | 48 extern Code_t ZGetLocations(ZLocations_t *, int *); |
| 49 extern Code_t ZSetLocation(char *); | |
| 50 extern Code_t ZUnsetLocation(); | |
| 9478 | 51 extern Code_t ZGetSubscriptions(ZSubscription_t *, int*); |
| 2086 | 52 |
| 53 typedef struct _zframe zframe; | |
| 54 typedef struct _zephyr_triple zephyr_triple; | |
| 9610 | 55 typedef struct _zephyr_account zephyr_account; |
| 2086 | 56 |
| 9610 | 57 |
| 58 struct _zephyr_account { | |
| 59 GaimAccount* account; | |
| 60 char *username; | |
| 61 char* realm; | |
| 62 char* galaxy; | |
| 63 char* krbtkfile; | |
| 64 guint32 nottimer; | |
| 65 guint32 loctimer; | |
| 66 GList *pending_zloc_names; | |
| 67 GSList *subscrips; | |
| 68 int last_id; | |
| 69 unsigned short port; | |
| 70 char ourhost[MAXHOSTNAMELEN]; | |
| 71 char ourhostcanon[MAXHOSTNAMELEN]; | |
| 72 }; | |
| 9478 | 73 |
| 2086 | 74 /* struct I need for zephyr_to_html */ |
| 75 struct _zframe { | |
| 76 /* true for everything but @color, since inside the parens of that one is | |
| 8644 | 77 * the color. */ |
| 2086 | 78 gboolean has_closer; |
| 79 /* </i>, </font>, </b>, etc. */ | |
| 80 char *closing; | |
| 81 /* text including the opening html thingie. */ | |
| 82 GString *text; | |
| 83 struct _zframe *enclosing; | |
| 84 }; | |
| 85 | |
| 86 struct _zephyr_triple { | |
| 87 char *class; | |
| 88 char *instance; | |
| 89 char *recipient; | |
| 90 char *name; | |
| 91 gboolean open; | |
| 92 int id; | |
| 93 }; | |
| 94 | |
| 95 #define z_call(func) if (func != ZERR_NONE)\ | |
| 96 return; | |
| 97 #define z_call_r(func) if (func != ZERR_NONE)\ | |
| 98 return TRUE; | |
| 99 #define z_call_s(func, err) if (func != ZERR_NONE) {\ | |
| 9610 | 100 gaim_connection_error(gc, err);\ |
| 2086 | 101 return;\ |
| 102 } | |
| 103 | |
| 9328 | 104 char *local_zephyr_normalize(const char *); |
| 7322 | 105 static const char *zephyr_normalize(const GaimAccount *, const char *); |
| 9328 | 106 static const char *gaim_zephyr_get_realm(); |
| 9434 | 107 static void zephyr_chat_set_topic(GaimConnection * gc, int id, const char *topic); |
| 9328 | 108 |
| 109 char *zephyr_strip_foreign_realm(const char* user){ | |
| 110 /* | |
| 111 Takes in a username of the form username or username@realm | |
| 112 and returns: | |
| 113 username, if there is no realm, or the realm is the local realm | |
| 114 or: | |
| 115 username@realm if there is a realm and it is foreign | |
| 116 */ | |
| 117 char *tmp = g_strdup(user); | |
| 118 char *at = strchr(tmp,'@'); | |
| 119 if (at && !g_ascii_strcasecmp(at+1,gaim_zephyr_get_realm())) { | |
| 120 /* We're passed in a username of the form user@users-realm */ | |
| 121 char* tmp2; | |
| 122 *at = '\0'; | |
| 123 tmp2 = g_strdup(tmp); | |
| 124 g_free(tmp); | |
| 125 return tmp2; | |
| 126 } | |
| 127 else { | |
| 128 /* We're passed in a username of the form user or user@foreign-realm */ | |
| 129 return tmp; | |
| 130 } | |
| 131 } | |
| 2086 | 132 |
| 133 /* this is so bad, and if Zephyr weren't so fucked up to begin with I | |
| 134 * wouldn't do this. but it is so i will. */ | |
| 9610 | 135 |
| 9328 | 136 /* just for debugging */ |
| 2086 | 137 static void handle_unknown(ZNotice_t notice) |
| 138 { | |
| 9328 | 139 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_packet: %s\n", notice.z_packet); |
| 140 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_version: %s\n", notice.z_version); | |
| 141 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_kind: %d\n", (int)(notice.z_kind)); | |
| 142 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class: %s\n", notice.z_class); | |
| 143 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_class_inst: %s\n", notice.z_class_inst); | |
| 144 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_opcode: %s\n", notice.z_opcode); | |
| 145 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_sender: %s\n", notice.z_sender); | |
| 146 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_recipient: %s\n", notice.z_recipient); | |
| 147 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message: %s\n", notice.z_message); | |
| 148 gaim_debug(GAIM_DEBUG_MISC, "zephyr","z_message_len: %d\n", notice.z_message_len); | |
| 2086 | 149 } |
| 9328 | 150 |
| 2086 | 151 |
| 9610 | 152 static zephyr_triple *new_triple(zephyr_account *zephyr,const char *c, const char *i, const char *r) |
| 2086 | 153 { |
| 154 zephyr_triple *zt; | |
| 8644 | 155 |
| 2086 | 156 zt = g_new0(zephyr_triple, 1); |
| 157 zt->class = g_strdup(c); | |
| 158 zt->instance = g_strdup(i); | |
| 159 zt->recipient = g_strdup(r); | |
| 9610 | 160 zt->name = g_strdup_printf("%s,%s,%s", c, i?i:"", r?r:""); |
| 161 zt->id = ++(zephyr->last_id); | |
| 2086 | 162 zt->open = FALSE; |
| 163 return zt; | |
| 164 } | |
| 165 | |
| 8644 | 166 static void free_triple(zephyr_triple * zt) |
| 2086 | 167 { |
| 168 g_free(zt->class); | |
| 169 g_free(zt->instance); | |
| 170 g_free(zt->recipient); | |
| 171 g_free(zt->name); | |
| 172 g_free(zt); | |
| 173 } | |
| 174 | |
| 9478 | 175 static gchar *gaim_zephyr_get_sender() |
| 8644 | 176 { |
| 8568 | 177 /* will be useful once this plugin can use a backend other |
| 178 than libzephyr */ | |
| 9478 | 179 /* XXX add zephyr error reporting */ |
| 180 gchar *sender; | |
| 181 sender = ZGetSender(); | |
| 182 if (!sender || !g_ascii_strcasecmp(sender,"")) { | |
| 183 sender = ""; | |
| 184 } | |
| 185 return sender; | |
| 8354 | 186 } |
| 187 | |
| 8644 | 188 static const char *gaim_zephyr_get_realm() |
| 189 { | |
| 8568 | 190 /* will be useful once this plugin can use a backend other |
| 191 than libzephyr */ | |
| 9478 | 192 gchar *realm=NULL; |
| 193 /* XXX add zephyr error reporting */ | |
| 194 realm= ZGetRealm(); | |
| 195 return realm; | |
| 8354 | 196 } |
| 197 | |
| 9328 | 198 /* returns true if zt1 is a subset of zt2. This function is used to |
| 199 determine whether a zephyr sent to zt1 should be placed in the chat | |
| 200 with triple zt2 | |
| 201 | |
| 202 zt1 is a subset of zt2 | |
| 203 iff. the classnames are identical ignoring case | |
| 204 AND. the instance names are identical (ignoring case), or zt2->instance is *. | |
| 205 AND. the recipient names are identical | |
| 206 */ | |
| 207 | |
| 8644 | 208 static gboolean triple_subset(zephyr_triple * zt1, zephyr_triple * zt2) |
| 2086 | 209 { |
| 9328 | 210 if (g_ascii_strcasecmp(zt2->class, zt1->class)) { |
| 2086 | 211 return FALSE; |
| 212 } | |
| 8644 | 213 if (g_ascii_strcasecmp(zt2->instance, zt1->instance) && g_ascii_strcasecmp(zt2->instance, "*")) { |
| 2086 | 214 return FALSE; |
| 215 } | |
| 9328 | 216 if (g_ascii_strcasecmp(zt2->recipient, zt1->recipient)) { |
| 2086 | 217 return FALSE; |
| 218 } | |
| 219 return TRUE; | |
| 220 } | |
| 221 | |
| 9610 | 222 static zephyr_triple *find_sub_by_triple(zephyr_account *zephyr,zephyr_triple * zt) |
| 2086 | 223 { |
| 224 zephyr_triple *curr_t; | |
| 9610 | 225 GSList *curr = zephyr->subscrips; |
| 8644 | 226 |
| 2086 | 227 while (curr) { |
| 228 curr_t = curr->data; | |
| 229 if (triple_subset(zt, curr_t)) | |
| 230 return curr_t; | |
| 231 curr = curr->next; | |
| 232 } | |
| 233 return NULL; | |
| 234 } | |
| 235 | |
| 9610 | 236 static zephyr_triple *find_sub_by_id(zephyr_account *zephyr,int id) |
| 2086 | 237 { |
| 238 zephyr_triple *zt; | |
| 9610 | 239 GSList *curr = zephyr->subscrips; |
| 8644 | 240 |
| 2086 | 241 while (curr) { |
| 242 zt = curr->data; | |
| 243 if (zt->id == id) | |
| 244 return zt; | |
| 245 curr = curr->next; | |
| 246 } | |
| 247 return NULL; | |
| 248 } | |
| 249 | |
| 9328 | 250 /* |
| 9434 | 251 Converts strings to utf-8 if necessary using user specified encoding |
| 9328 | 252 */ |
| 253 | |
| 9610 | 254 static gchar *zephyr_recv_convert(GaimConnection *gc,gchar *string, int len) |
| 8560 | 255 { |
| 256 gchar *utf8; | |
| 257 GError *err = NULL; | |
| 8644 | 258 |
| 259 if (g_utf8_validate(string, len, NULL)) { | |
| 8568 | 260 return g_strdup(string); |
| 261 } else { | |
| 9610 | 262 utf8 = g_convert(string, len, "UTF-8", gaim_account_get_string(gc->account, "encoding", ZEPHYR_FALLBACK_CHARSET), NULL, NULL, &err); |
| 8568 | 263 if (err) { |
| 264 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "recv conversion error: %s\n", err->message); | |
| 265 utf8 = g_strdup(_("(There was an error converting this message. Check the 'Encoding' option in the Account Editor)")); | |
| 8954 | 266 g_error_free(err); |
| 8568 | 267 } |
| 268 | |
| 269 return utf8; | |
| 270 } | |
| 8560 | 271 } |
| 272 | |
| 2086 | 273 /* utility macros that are useful for zephyr_to_html */ |
| 274 | |
| 275 #define IS_OPENER(c) ((c == '{') || (c == '[') || (c == '(') || (c == '<')) | |
| 276 #define IS_CLOSER(c) ((c == '}') || (c == ']') || (c == ')') || (c == '>')) | |
| 277 | |
| 8451 | 278 /* This parses HTML formatting (put out by one of the gtkimhtml widgets |
| 279 And converts it to zephyr formatting. | |
| 280 It currently deals properly with <b>, <br>, <i>, <font face=...>, <font color=...>, | |
| 281 It ignores <font back=...> | |
| 282 It does | |
| 283 <font size = "1 or 2" -> @small | |
| 284 3 or 4 @medium() | |
| 285 5,6, or 7 @large() | |
| 286 <a href is dealt with by ignoring the description and outputting the link | |
| 287 */ | |
| 288 | |
| 289 static char *html_to_zephyr(const char *message) | |
| 290 { | |
| 8644 | 291 int len, cnt, retcount; |
| 292 char *ret; | |
| 293 | |
| 294 len = strlen(message); | |
| 9478 | 295 if (!len) |
| 296 return g_strdup(""); | |
| 297 | |
| 8644 | 298 ret = g_new0(char, len * 3); |
| 299 | |
| 300 bzero(ret, len * 3); | |
| 301 retcount = 0; | |
| 302 cnt = 0; | |
| 303 while (cnt <= len) { | |
| 304 if (message[cnt] == '<') { | |
| 305 if (!g_ascii_strncasecmp(message + cnt + 1, "i>", 2)) { | |
| 306 strncpy(ret + retcount, "@i(", 3); | |
| 307 cnt += 3; | |
| 308 retcount += 3; | |
| 309 } else if (!g_ascii_strncasecmp(message + cnt + 1, "b>", 2)) { | |
| 310 strncpy(ret + retcount, "@b(", 3); | |
| 311 cnt += 3; | |
| 312 retcount += 3; | |
| 313 } else if (!g_ascii_strncasecmp(message + cnt + 1, "br>", 3)) { | |
| 314 strncpy(ret + retcount, "\n", 1); | |
| 315 cnt += 4; | |
| 316 retcount += 1; | |
| 317 } else if (!g_ascii_strncasecmp(message + cnt + 1, "a href=\"", 8)) { | |
| 318 cnt += 9; | |
| 319 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
| 320 ret[retcount] = message[cnt]; | |
| 321 retcount++; | |
| 322 cnt++; | |
| 323 } | |
| 324 cnt += 2; | |
| 325 /* ignore descriptive string */ | |
| 326 while (g_ascii_strncasecmp(message + cnt, "</a>", 4) != 0) { | |
| 327 cnt++; | |
| 328 } | |
| 329 cnt += 4; | |
| 330 } else if (!g_ascii_strncasecmp(message + cnt + 1, "font", 4)) { | |
| 331 cnt += 5; | |
| 332 while (!g_ascii_strncasecmp(message + cnt, " ", 1)) | |
| 333 cnt++; | |
| 334 if (!g_ascii_strncasecmp(message + cnt, "color=\"", 7)) { | |
| 335 cnt += 7; | |
| 336 strncpy(ret + retcount, "@color(", 7); | |
| 337 retcount += 7; | |
| 338 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
| 339 ret[retcount] = message[cnt]; | |
| 340 retcount++; | |
| 341 cnt++; | |
| 342 } | |
| 343 ret[retcount] = ')'; | |
| 344 retcount++; | |
| 345 cnt += 2; | |
| 346 } else if (!g_ascii_strncasecmp(message + cnt, "face=\"", 6)) { | |
| 347 cnt += 6; | |
| 348 strncpy(ret + retcount, "@font(", 6); | |
| 349 retcount += 6; | |
| 350 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
| 351 ret[retcount] = message[cnt]; | |
| 352 retcount++; | |
| 353 cnt++; | |
| 354 } | |
| 355 ret[retcount] = ')'; | |
| 356 retcount++; | |
| 357 cnt += 2; | |
| 358 } else if (!g_ascii_strncasecmp(message + cnt, "size=\"", 6)) { | |
| 359 cnt += 6; | |
| 360 if ((message[cnt] == '1') || (message[cnt] == '2')) { | |
| 361 strncpy(ret + retcount, "@small(", 7); | |
| 362 retcount += 7; | |
| 363 } else if ((message[cnt] == '3') | |
| 364 || (message[cnt] == '4')) { | |
| 365 strncpy(ret + retcount, "@medium(", 8); | |
| 366 retcount += 8; | |
| 367 } else if ((message[cnt] == '5') | |
| 368 || (message[cnt] == '6') | |
| 369 || (message[cnt] == '7')) { | |
| 370 strncpy(ret + retcount, "@large(", 7); | |
| 371 retcount += 7; | |
| 372 } | |
| 373 cnt += 3; | |
| 374 } else { | |
| 375 /* Drop all unrecognized/misparsed font tags */ | |
| 376 while (g_ascii_strncasecmp(message + cnt, "\">", 2) != 0) { | |
| 377 cnt++; | |
| 378 } | |
| 379 cnt += 2; | |
| 380 } | |
| 381 } else if (!g_ascii_strncasecmp(message + cnt + 1, "/i>", 3) | |
| 382 || !g_ascii_strncasecmp(message + cnt + 1, "/b>", 3)) { | |
| 383 cnt += 4; | |
| 384 ret[retcount] = ')'; | |
| 385 retcount++; | |
| 386 } else if (!g_ascii_strncasecmp(message + cnt + 1, "/font>", 6)) { | |
| 387 cnt += 7; | |
| 388 strncpy(ret + retcount, "@font(fixed)", 12); | |
| 389 retcount += 12; | |
| 390 } else { | |
| 391 /* Catch all for all unrecognized/misparsed <foo> tage */ | |
| 392 while (g_ascii_strncasecmp(message + cnt, ">", 1) != 0) { | |
| 393 ret[retcount] = message[cnt]; | |
| 394 retcount++; | |
| 395 cnt++; | |
| 396 } | |
| 397 } | |
| 398 } else { | |
| 399 /* Duh */ | |
| 400 ret[retcount] = message[cnt]; | |
| 401 retcount++; | |
| 402 cnt++; | |
| 403 } | |
| 404 } | |
| 405 return ret; | |
| 8451 | 406 } |
| 407 | |
| 2086 | 408 /* this parses zephyr formatting and converts it to html. For example, if |
| 409 * you pass in "@{@color(blue)@i(hello)}" you should get out | |
| 410 * "<font color=blue><i>hello</i></font>". */ | |
| 411 static char *zephyr_to_html(char *message) | |
| 412 { | |
| 413 int len, cnt; | |
| 414 zframe *frames, *curr; | |
| 415 char *ret; | |
| 416 | |
| 417 frames = g_new(zframe, 1); | |
| 418 frames->text = g_string_new(""); | |
| 419 frames->enclosing = NULL; | |
| 420 frames->closing = ""; | |
| 421 frames->has_closer = FALSE; | |
| 422 | |
| 423 len = strlen(message); | |
| 424 cnt = 0; | |
| 425 while (cnt <= len) { | |
| 426 if (message[cnt] == '@') { | |
| 427 zframe *new_f; | |
| 428 char *buf; | |
| 429 int end; | |
| 8644 | 430 |
| 431 for (end = 1; (cnt + end) <= len && !IS_OPENER(message[cnt + end]) | |
| 432 && !IS_CLOSER(message[cnt + end]); end++); | |
| 2086 | 433 buf = g_new0(char, end); |
| 8644 | 434 |
| 2086 | 435 if (end) { |
| 8644 | 436 g_snprintf(buf, end, "%s", message + cnt + 1); |
| 2086 | 437 } |
| 8644 | 438 if (!g_ascii_strcasecmp(buf, "italic") || !g_ascii_strcasecmp(buf, "i")) { |
| 2086 | 439 new_f = g_new(zframe, 1); |
| 440 new_f->enclosing = frames; | |
| 441 new_f->text = g_string_new("<i>"); | |
| 442 new_f->closing = "</i>"; | |
| 443 new_f->has_closer = TRUE; | |
| 444 frames = new_f; | |
| 8644 | 445 cnt += end + 1; /* cnt points to char after opener */ |
| 446 } else if (!g_ascii_strcasecmp(buf, "small")) { | |
| 447 new_f = g_new(zframe, 1); | |
| 448 new_f->enclosing = frames; | |
| 449 new_f->text = g_string_new("<font size=\"1\">"); | |
| 450 new_f->closing = "</font>"; | |
| 451 frames = new_f; | |
| 452 cnt += end + 1; | |
| 453 } else if (!g_ascii_strcasecmp(buf, "medium")) { | |
| 454 new_f = g_new(zframe, 1); | |
| 455 new_f->enclosing = frames; | |
| 456 new_f->text = g_string_new("<font size=\"3\">"); | |
| 457 new_f->closing = "</font>"; | |
| 458 frames = new_f; | |
| 459 cnt += end + 1; | |
| 460 } else if (!g_ascii_strcasecmp(buf, "large")) { | |
| 461 new_f = g_new(zframe, 1); | |
| 462 new_f->enclosing = frames; | |
| 463 new_f->text = g_string_new("<font size=\"7\">"); | |
| 464 new_f->closing = "</font>"; | |
| 465 frames = new_f; | |
| 466 cnt += end + 1; | |
| 467 } else if (!g_ascii_strcasecmp(buf, "bold") | |
| 468 || !g_ascii_strcasecmp(buf, "b")) { | |
| 2086 | 469 new_f = g_new(zframe, 1); |
| 470 new_f->enclosing = frames; | |
| 471 new_f->text = g_string_new("<b>"); | |
| 472 new_f->closing = "</b>"; | |
| 473 new_f->has_closer = TRUE; | |
| 474 frames = new_f; | |
| 8644 | 475 cnt += end + 1; |
| 476 } else if (!g_ascii_strcasecmp(buf, "font")) { | |
| 477 cnt += end + 1; | |
| 8451 | 478 new_f = g_new(zframe, 1); |
| 479 new_f->enclosing = frames; | |
| 480 new_f->text = g_string_new("<font face="); | |
| 481 for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
| 482 g_string_append_c(new_f->text, message[cnt]); | |
| 483 } | |
| 8644 | 484 cnt++; /* point to char after closer */ |
| 8451 | 485 g_string_append_c(new_f->text, '>'); |
| 486 new_f->closing = "</font>"; | |
| 487 new_f->has_closer = FALSE; | |
| 488 frames = new_f; | |
| 8568 | 489 } else if (!g_ascii_strcasecmp(buf, "color")) { |
| 8644 | 490 cnt += end + 1; |
| 2086 | 491 new_f = g_new(zframe, 1); |
| 492 new_f->enclosing = frames; | |
| 493 new_f->text = g_string_new("<font color="); | |
| 494 for (; (cnt <= len) && !IS_CLOSER(message[cnt]); cnt++) { | |
| 495 g_string_append_c(new_f->text, message[cnt]); | |
| 496 } | |
| 8644 | 497 cnt++; /* point to char after closer */ |
| 2086 | 498 g_string_append_c(new_f->text, '>'); |
| 499 new_f->closing = "</font>"; | |
| 500 new_f->has_closer = FALSE; | |
| 501 frames = new_f; | |
| 4793 | 502 } else if (!g_ascii_strcasecmp(buf, "")) { |
| 2086 | 503 new_f = g_new(zframe, 1); |
| 504 new_f->enclosing = frames; | |
| 505 new_f->text = g_string_new(""); | |
| 506 new_f->closing = ""; | |
| 507 new_f->has_closer = TRUE; | |
| 508 frames = new_f; | |
| 8644 | 509 cnt += end + 1; /* cnt points to char after opener */ |
| 2086 | 510 } else { |
| 8644 | 511 if ((cnt + end) > len) { |
| 2086 | 512 g_string_append_c(frames->text, '@'); |
| 513 cnt++; | |
| 8644 | 514 } else if (IS_CLOSER(message[cnt + end])) { |
| 515 /* We have @chars..closer . This is | |
| 516 merely a sequence of chars that isn't a formatting tag | |
| 517 */ | |
| 518 int tmp = cnt; | |
| 519 | |
| 520 while (tmp <= cnt + end) { | |
| 521 g_string_append_c(frames->text, message[tmp]); | |
| 522 tmp++; | |
| 523 } | |
| 524 cnt += end + 1; | |
| 525 } else { | |
| 2086 | 526 /* unrecognized thingie. act like it's not there, but we |
| 527 * still need to take care of the corresponding closer, | |
| 528 * make a frame that does nothing. */ | |
| 529 new_f = g_new(zframe, 1); | |
| 530 new_f->enclosing = frames; | |
| 531 new_f->text = g_string_new(""); | |
| 532 new_f->closing = ""; | |
| 533 new_f->has_closer = TRUE; | |
| 534 frames = new_f; | |
| 8644 | 535 cnt += end + 1; /* cnt points to char after opener */ |
| 2086 | 536 } |
| 537 } | |
| 538 } else if (IS_CLOSER(message[cnt])) { | |
| 539 zframe *popped; | |
| 540 gboolean last_had_closer; | |
| 8644 | 541 |
| 2086 | 542 if (frames->enclosing) { |
| 543 do { | |
| 544 popped = frames; | |
| 545 frames = frames->enclosing; | |
| 546 g_string_append(frames->text, popped->text->str); | |
| 547 g_string_append(frames->text, popped->closing); | |
| 548 g_string_free(popped->text, TRUE); | |
| 549 last_had_closer = popped->has_closer; | |
| 550 g_free(popped); | |
| 551 } while (frames && frames->enclosing && !last_had_closer); | |
| 552 } else { | |
| 553 g_string_append_c(frames->text, message[cnt]); | |
| 554 } | |
| 555 cnt++; | |
| 556 } else if (message[cnt] == '\n') { | |
| 557 g_string_append(frames->text, "<br>"); | |
| 558 cnt++; | |
| 559 } else { | |
| 560 g_string_append_c(frames->text, message[cnt++]); | |
| 561 } | |
| 562 } | |
| 563 /* go through all the stuff that they didn't close */ | |
| 564 while (frames->enclosing) { | |
| 565 curr = frames; | |
| 566 g_string_append(frames->enclosing->text, frames->text->str); | |
| 567 g_string_append(frames->enclosing->text, frames->closing); | |
| 568 g_string_free(frames->text, TRUE); | |
| 569 frames = frames->enclosing; | |
| 570 g_free(curr); | |
| 571 } | |
| 572 ret = frames->text->str; | |
| 573 g_string_free(frames->text, FALSE); | |
| 574 g_free(frames); | |
| 575 return ret; | |
| 576 } | |
| 577 | |
| 9610 | 578 static gboolean pending_zloc(zephyr_account *zephyr,char *who) |
| 2086 | 579 { |
| 580 GList *curr; | |
| 8644 | 581 |
| 9610 | 582 for (curr = zephyr->pending_zloc_names; curr != NULL; curr = curr->next) { |
| 9328 | 583 char* normalized_who = local_zephyr_normalize(who); |
| 584 if (!g_ascii_strcasecmp(normalized_who, (char *)curr->data)) { | |
| 8644 | 585 g_free((char *)curr->data); |
| 9610 | 586 zephyr->pending_zloc_names = g_list_remove(zephyr->pending_zloc_names, curr->data); |
| 2086 | 587 return TRUE; |
| 588 } | |
| 589 } | |
| 590 return FALSE; | |
| 591 } | |
| 592 | |
| 9328 | 593 /* Called when the server notifies us a message couldn't get sent */ |
| 594 | |
| 9610 | 595 static void message_failed(GaimConnection *gc, ZNotice_t notice, struct sockaddr_in from) |
| 8559 | 596 { |
| 8644 | 597 if (g_ascii_strcasecmp(notice.z_class, "message")) { |
| 9328 | 598 gchar* chat_failed = g_strdup_printf(_("Unable send to chat %s,%s,%s"),notice.z_class,notice.z_class_inst,notice.z_recipient); |
| 9610 | 599 gaim_notify_error(gc,"",chat_failed,NULL); |
| 9328 | 600 g_free(chat_failed); |
| 8644 | 601 } else { |
| 9610 | 602 gaim_notify_error(gc, notice.z_recipient, _("User is offline"), NULL); |
| 8644 | 603 } |
| 8559 | 604 } |
| 605 | |
| 9610 | 606 static void handle_message(GaimConnection *gc,ZNotice_t notice, struct sockaddr_in from) |
| 2086 | 607 { |
| 4793 | 608 if (!g_ascii_strcasecmp(notice.z_class, LOGIN_CLASS)) { |
| 3277 | 609 /* well, we'll be updating in 20 seconds anyway, might as well ignore this. */ |
| 4793 | 610 } else if (!g_ascii_strcasecmp(notice.z_class, LOCATE_CLASS)) { |
| 611 if (!g_ascii_strcasecmp(notice.z_opcode, LOCATE_LOCATE)) { | |
| 2086 | 612 int nlocs; |
| 613 char *user; | |
| 6695 | 614 GaimBuddy *b; |
| 2086 | 615 |
| 9478 | 616 /* XXX add real error reporting */ |
| 2086 | 617 if (ZParseLocations(¬ice, NULL, &nlocs, &user) != ZERR_NONE) |
| 618 return; | |
| 8435 | 619 |
| 9610 | 620 if ((b = gaim_find_buddy(gc->account, user)) == NULL) { |
| 2086 | 621 char *e = strchr(user, '@'); |
| 8644 | 622 |
| 623 if (e && !g_ascii_strcasecmp(e + 1, gaim_zephyr_get_realm())) { | |
| 624 *e = '\0'; | |
| 625 } | |
| 9610 | 626 b = gaim_find_buddy(gc->account, user); |
| 8644 | 627 } |
| 9610 | 628 if ((b && pending_zloc(gc->proto_data,b->name)) || pending_zloc(gc->proto_data,user)) { |
| 2086 | 629 ZLocations_t locs; |
| 630 int one = 1; | |
| 631 GString *str = g_string_new(""); | |
| 8644 | 632 |
| 633 g_string_append_printf(str, _("<b>User:</b> %s<br>"), b ? b->name : user); | |
| 8435 | 634 if (b && b->alias) |
| 5132 | 635 g_string_append_printf(str, _("<b>Alias:</b> %s<br>"), b->alias); |
| 2086 | 636 if (!nlocs) { |
| 5132 | 637 g_string_append_printf(str, _("<br>Hidden or not logged-in")); |
| 2086 | 638 } |
| 639 for (; nlocs > 0; nlocs--) { | |
| 9478 | 640 /* XXX add real error reporting */ |
| 2086 | 641 ZGetLocations(&locs, &one); |
| 8644 | 642 g_string_append_printf(str, _("<br>At %s since %s"), locs.host, locs.time); |
| 2086 | 643 } |
| 9610 | 644 gaim_notify_formatted(gc, NULL, _("Buddy Information"), NULL, str->str, NULL, NULL); |
| 2086 | 645 g_string_free(str, TRUE); |
| 646 } else | |
| 9610 | 647 serv_got_update(gc, b->name, nlocs, 0, 0, 0, 0); |
| 2086 | 648 |
| 9434 | 649 g_free(user); |
| 2086 | 650 } |
| 651 } else { | |
| 8560 | 652 char *buf, *buf2, *buf3; |
|
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
653 char *send_inst; |
| 8644 | 654 GaimConversation *gconv1; |
| 655 GaimConvChat *gcc; | |
| 2086 | 656 char *ptr = notice.z_message + strlen(notice.z_message) + 1; |
| 9478 | 657 int len; |
| 8644 | 658 char *sendertmp = g_strdup_printf("%s", gaim_zephyr_get_sender()); |
| 9478 | 659 int signature_length = strlen(notice.z_message); |
| 660 int message_has_no_body = 0; | |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
661 GaimConvImFlags flags = 0; |
| 8644 | 662 gchar *tmpescape; |
| 8560 | 663 |
| 9478 | 664 /* Need to deal with 0 length messages to handle typing notification (OPCODE) ping messages */ |
| 665 /* One field zephyrs would have caused gaim to crash */ | |
| 666 if ( (notice.z_message_len == 0) || (signature_length >= notice.z_message_len - 1)) { | |
| 667 message_has_no_body = 1; | |
| 668 len = 0; | |
| 669 gaim_debug_info("zephyr","message_size %d %d %d\n",len,notice.z_message_len,signature_length); | |
| 670 buf3 = g_strdup(""); | |
| 671 | |
| 672 } else { | |
| 673 len = notice.z_message_len - ( signature_length +1); | |
| 674 gaim_debug_info("zephyr","message_size %d %d %d\n",len,notice.z_message_len,signature_length); | |
| 8644 | 675 buf = g_malloc(len + 1); |
| 676 g_snprintf(buf, len + 1, "%s", ptr); | |
| 677 g_strchomp(buf); | |
| 678 tmpescape = gaim_escape_html(buf); | |
| 9478 | 679 g_free(buf); |
| 8644 | 680 buf2 = zephyr_to_html(tmpescape); |
| 9610 | 681 buf3 = zephyr_recv_convert(gc,buf2, strlen(buf2)); |
| 8644 | 682 g_free(buf2); |
| 683 g_free(tmpescape); | |
| 9478 | 684 } |
| 8644 | 685 |
| 9328 | 686 if (!g_ascii_strcasecmp(notice.z_class, "MESSAGE") && !g_ascii_strcasecmp(notice.z_class_inst, "PERSONAL") |
| 687 && !g_ascii_strcasecmp(notice.z_recipient,gaim_zephyr_get_sender())) { | |
| 688 gchar* stripped_sender; | |
| 4793 | 689 if (!g_ascii_strcasecmp(notice.z_message, "Automated reply:")) |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
690 flags |= GAIM_CONV_IM_AUTO_RESP; |
| 9328 | 691 stripped_sender = zephyr_strip_foreign_realm(notice.z_sender); |
| 9478 | 692 |
| 693 if (!g_ascii_strcasecmp(notice.z_opcode,"PING")) | |
| 9610 | 694 serv_got_typing(gc,stripped_sender,ZEPHYR_TYPING_RECV_TIMEOUT, GAIM_TYPING); |
| 9478 | 695 else |
| 9610 | 696 serv_got_im(gc, stripped_sender, buf3, flags, time(NULL)); |
| 9478 | 697 |
| 9328 | 698 g_free(stripped_sender); |
| 2086 | 699 } else { |
| 700 zephyr_triple *zt1, *zt2; | |
| 9437 | 701 gchar *send_inst_utf8; |
| 9610 | 702 zephyr_account *zephyr = gc->proto_data; |
| 703 zt1 = new_triple(gc->proto_data,notice.z_class, notice.z_class_inst, notice.z_recipient); | |
| 704 zt2 = find_sub_by_triple(gc->proto_data,zt1); | |
| 2086 | 705 if (!zt2) { |
| 9434 | 706 /* This is a server supplied subscription */ |
| 9610 | 707 zephyr->subscrips = g_slist_append(zephyr->subscrips, zt1); |
| 708 zt2 = find_sub_by_triple(gc->proto_data,zt1); | |
| 9434 | 709 } |
| 710 | |
| 9437 | 711 if (!zt2->open) { |
| 712 zt2->open = TRUE; | |
| 9610 | 713 serv_got_joined_chat(gc, zt2->id, zt2->name); |
| 714 zephyr_chat_set_topic(gc,zt2->id,notice.z_class_inst); | |
| 9437 | 715 } |
| 716 g_free(sendertmp); /* fix memory leak? */ | |
| 717 /* If the person is in the default Realm, then strip the | |
| 718 Realm from the sender field */ | |
| 719 sendertmp = zephyr_strip_foreign_realm(notice.z_sender); | |
| 720 send_inst = g_strdup_printf("%s %s",sendertmp,notice.z_class_inst); | |
| 9610 | 721 send_inst_utf8 = zephyr_recv_convert(gc,send_inst, strlen(send_inst)); |
| 9437 | 722 if (!send_inst_utf8) { |
| 723 gaim_debug(GAIM_DEBUG_ERROR, "zephyr","send_inst %s became null\n", send_inst); | |
| 724 send_inst_utf8 = "malformed instance"; | |
| 725 } | |
| 726 | |
| 9610 | 727 serv_got_chat_in(gc, zt2->id, send_inst_utf8, 0, buf3, time(NULL)); |
| 9437 | 728 g_free(send_inst); |
| 9610 | 729 gconv1 = gaim_find_conversation_with_account(zt2->name, gc->account); |
| 9437 | 730 gcc = gaim_conversation_get_chat_data(gconv1); |
| 731 | |
| 9554 | 732 if (!gaim_conv_chat_find_user(gcc, sendertmp)) { |
| 9437 | 733 /* force interpretation in network byte order */ |
| 734 unsigned char *addrs = (unsigned char *)&(notice.z_sender_addr.s_addr); | |
| 735 gchar* ipaddr = g_strdup_printf("%hhd.%hhd.%hhd.%hhd", (unsigned char)addrs[0], | |
| 736 (unsigned char)addrs[1], (unsigned char)addrs[2], | |
| 737 (unsigned char) addrs[3]); | |
| 738 | |
| 9554 | 739 gaim_conv_chat_add_user(gcc, sendertmp, ipaddr, GAIM_CBFLAGS_NONE); |
| 9437 | 740 g_free(ipaddr); /* fix memory leak? */ |
| 741 | |
| 742 } | |
| 743 g_free(sendertmp); | |
| 744 g_free(send_inst_utf8); | |
| 745 | |
| 2086 | 746 free_triple(zt1); |
| 747 } | |
| 8560 | 748 g_free(buf3); |
| 9478 | 749 |
| 2086 | 750 } |
| 751 } | |
| 752 | |
| 753 static gint check_notify(gpointer data) | |
| 754 { | |
| 9478 | 755 /* XXX add real error reporting */ |
| 9610 | 756 GaimConnection *gc = (GaimConnection*) data; |
| 2086 | 757 while (ZPending()) { |
| 758 ZNotice_t notice; | |
| 759 struct sockaddr_in from; | |
| 9478 | 760 /* XXX add real error reporting */ |
| 8644 | 761 |
| 2086 | 762 z_call_r(ZReceiveNotice(¬ice, &from)); |
| 763 | |
| 764 switch (notice.z_kind) { | |
| 765 case UNSAFE: | |
| 766 case UNACKED: | |
| 767 case ACKED: | |
| 9610 | 768 handle_message(gc,notice, from); |
| 2086 | 769 break; |
| 8644 | 770 case SERVACK: |
| 771 if (!(g_ascii_strcasecmp(notice.z_message, ZSRVACK_NOTSENT))) { | |
| 9610 | 772 message_failed(gc,notice, from); |
| 8644 | 773 } |
| 774 break; | |
| 9328 | 775 case CLIENTACK: |
| 9478 | 776 gaim_debug_error("zephyr", "Client ack received\n"); |
| 2086 | 777 default: |
| 778 /* we'll just ignore things for now */ | |
| 9328 | 779 handle_unknown(notice); |
| 9478 | 780 gaim_debug_error("zephyr", "Unhandled notice.\n"); |
| 2086 | 781 break; |
| 782 } | |
| 9478 | 783 /* XXX add real error reporting */ |
| 2086 | 784 ZFreeNotice(¬ice); |
| 785 } | |
| 786 | |
| 787 return TRUE; | |
| 788 } | |
| 789 | |
| 790 static gint check_loc(gpointer data) | |
| 791 { | |
| 6695 | 792 GaimBlistNode *gnode, *cnode, *bnode; |
| 2086 | 793 ZAsyncLocateData_t ald; |
| 9610 | 794 GaimConnection *gc = (GaimConnection*)data; |
| 2086 | 795 |
| 796 ald.user = NULL; | |
| 797 memset(&(ald.uid), 0, sizeof(ZUnique_Id_t)); | |
| 798 ald.version = NULL; | |
| 799 | |
| 8644 | 800 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
| 801 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 4785 | 802 continue; |
| 8644 | 803 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
| 804 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
| 4785 | 805 continue; |
| 8644 | 806 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
| 807 GaimBuddy *b = (GaimBuddy *) bnode; | |
| 808 | |
| 809 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 6695 | 810 continue; |
| 9610 | 811 if (b->account->gc == gc) { |
| 7261 | 812 const char *chk; |
| 8644 | 813 |
| 8354 | 814 chk = local_zephyr_normalize(b->name); |
| 9478 | 815 /* XXX add real error reporting */ |
| 6695 | 816 /* doesn't matter if this fails or not; we'll just move on to the next one */ |
| 817 ZRequestLocations(chk, &ald, UNACKED, ZAUTH); | |
| 9434 | 818 g_free(ald.user); |
| 819 g_free(ald.version); | |
| 6695 | 820 } |
| 4349 | 821 } |
| 2086 | 822 } |
| 823 } | |
| 824 | |
| 825 return TRUE; | |
| 826 } | |
| 827 | |
| 828 static char *get_exposure_level() | |
| 829 { | |
| 9478 | 830 /* XXX add real error reporting */ |
| 2086 | 831 char *exposure = ZGetVariable("exposure"); |
| 832 | |
| 833 if (!exposure) | |
| 834 return EXPOSE_REALMVIS; | |
| 4793 | 835 if (!g_ascii_strcasecmp(exposure, EXPOSE_NONE)) |
| 2086 | 836 return EXPOSE_NONE; |
| 4793 | 837 if (!g_ascii_strcasecmp(exposure, EXPOSE_OPSTAFF)) |
| 2086 | 838 return EXPOSE_OPSTAFF; |
| 4793 | 839 if (!g_ascii_strcasecmp(exposure, EXPOSE_REALMANN)) |
| 2086 | 840 return EXPOSE_REALMANN; |
| 4793 | 841 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETVIS)) |
| 2086 | 842 return EXPOSE_NETVIS; |
| 4793 | 843 if (!g_ascii_strcasecmp(exposure, EXPOSE_NETANN)) |
| 2086 | 844 return EXPOSE_NETANN; |
| 845 return EXPOSE_REALMVIS; | |
| 846 } | |
| 847 | |
| 848 static void strip_comments(char *str) | |
| 849 { | |
| 850 char *tmp = strchr(str, '#'); | |
| 8644 | 851 |
| 2086 | 852 if (tmp) |
| 853 *tmp = '\0'; | |
| 854 g_strchug(str); | |
| 855 g_strchomp(str); | |
| 856 } | |
| 857 | |
| 9610 | 858 static void zephyr_inithosts(zephyr_account* zephyr) |
| 9478 | 859 { |
| 860 /* XXX This code may not be Win32 clean */ | |
| 861 struct hostent *hent; | |
| 862 | |
| 9610 | 863 if (gethostname(zephyr->ourhost, sizeof(zephyr->ourhost)-1) == -1) { |
| 9478 | 864 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "unable to retrieve hostname, %%host%% and %%canon%% will be wrong in subscriptions and have been set to unknown\n"); |
| 9610 | 865 g_stpcpy(zephyr->ourhost,"unknown"); |
| 866 g_stpcpy(zephyr->ourhostcanon,"unknown"); | |
| 9478 | 867 return; |
| 868 } | |
| 869 | |
| 9610 | 870 if (!(hent = gethostbyname(zephyr->ourhost))) { |
| 871 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "unable to resolve hostname, %%canon%% will be wrong in subscriptions.and has been set to the value of %%host%%, %s\n",zephyr->ourhost); | |
| 872 g_stpcpy(zephyr->ourhostcanon,zephyr->ourhost); | |
| 9478 | 873 return; |
| 874 } | |
| 9610 | 875 g_stpcpy(zephyr->ourhostcanon,hent->h_name); |
| 9478 | 876 return; |
| 877 } | |
| 878 | |
| 9610 | 879 static void process_zsubs(zephyr_account *zephyr) |
| 2086 | 880 { |
| 9434 | 881 /* Loads zephyr chats "(subscriptions) from ~/.zephyr.subs, and |
| 882 registers (subscribes to) them on the server */ | |
| 883 | |
| 884 /* XXX deal with unsubscriptions */ | |
| 885 /* XXX deal with punts */ | |
| 886 | |
| 2086 | 887 FILE *f; |
| 888 gchar *fname; | |
| 889 gchar buff[BUFSIZ]; | |
| 8644 | 890 |
| 9610 | 891 zephyr_inithosts(zephyr); |
| 3630 | 892 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
| 2086 | 893 f = fopen(fname, "r"); |
| 894 if (f) { | |
| 895 char **triple; | |
| 896 ZSubscription_t sub; | |
| 897 char *recip; | |
| 9478 | 898 char *z_class; |
| 899 char *z_instance; | |
| 8644 | 900 |
| 2086 | 901 while (fgets(buff, BUFSIZ, f)) { |
| 902 strip_comments(buff); | |
| 903 if (buff[0]) { | |
| 904 triple = g_strsplit(buff, ",", 3); | |
| 8644 | 905 if (triple[0] && triple[1]) { |
| 906 char *tmp = g_strdup_printf("%s", gaim_zephyr_get_sender()); | |
|
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
907 char *atptr; |
| 8644 | 908 |
| 2086 | 909 sub.zsub_class = triple[0]; |
| 910 sub.zsub_classinst = triple[1]; | |
| 8644 | 911 if (triple[2] == NULL) { |
| 3277 | 912 recip = g_malloc0(1); |
| 4793 | 913 } else if (!g_ascii_strcasecmp(triple[2], "%me%")) { |
| 8644 | 914 recip = g_strdup_printf("%s", gaim_zephyr_get_sender()); |
| 4793 | 915 } else if (!g_ascii_strcasecmp(triple[2], "*")) { |
|
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
916 /* wildcard |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
917 * form of class,instance,* */ |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
918 recip = g_malloc0(1); |
| 4793 | 919 } else if (!g_ascii_strcasecmp(triple[2], tmp)) { |
|
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
920 /* form of class,instance,aatharuv@ATHENA.MIT.EDU */ |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
921 recip = g_strdup(triple[2]); |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
922 } else if ((atptr = strchr(triple[2], '@')) != NULL) { |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
923 /* form of class,instance,*@ANDREW.CMU.EDU |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
924 * class,instance,@ANDREW.CMU.EDU |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
925 * If realm is local realm, blank recipient, else |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
926 * @REALM-NAME |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
927 */ |
| 8644 | 928 char *realmat = g_strdup_printf("@%s", |
| 929 gaim_zephyr_get_realm()); | |
| 930 | |
| 4793 | 931 if (!g_ascii_strcasecmp(atptr, realmat)) |
|
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
932 recip = g_malloc0(1); |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
933 else |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
934 recip = g_strdup(atptr); |
|
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
935 g_free(realmat); |
| 2086 | 936 } else { |
| 937 recip = g_strdup(triple[2]); | |
| 938 } | |
|
2804
1648c703ddc2
[gaim-migrate @ 2817]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2791
diff
changeset
|
939 g_free(tmp); |
| 2086 | 940 sub.zsub_recipient = recip; |
| 9478 | 941 |
| 942 if (!g_ascii_strcasecmp(triple[0],"%host%")) { | |
| 9610 | 943 z_class = g_strdup(zephyr->ourhost); |
| 9478 | 944 } else if (!g_ascii_strcasecmp(triple[0],"%canon%")) { |
| 9610 | 945 z_class = g_strdup(zephyr->ourhostcanon); |
| 9478 | 946 } else { |
| 947 z_class = g_strdup(triple[0]); | |
| 948 } | |
| 949 sub.zsub_class = z_class; | |
| 950 | |
| 951 if (!g_ascii_strcasecmp(triple[1],"%host%")) { | |
| 9610 | 952 z_instance = g_strdup(zephyr->ourhost); |
| 9478 | 953 } else if (!g_ascii_strcasecmp(triple[1],"%canon%")) { |
| 9610 | 954 z_instance = g_strdup(zephyr->ourhostcanon); |
| 9478 | 955 } else { |
| 956 z_instance = g_strdup(triple[1]); | |
| 957 } | |
| 958 sub.zsub_classinst = z_instance; | |
| 959 | |
| 960 /* There should be some sort of error report listing classes that couldn't be subbed to. | |
| 961 Not important right now though */ | |
| 962 | |
| 2086 | 963 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { |
| 9478 | 964 |
| 8644 | 965 gaim_debug(GAIM_DEBUG_ERROR, "zephyr", "Couldn't subscribe to %s, %s, %s\n", sub.zsub_class, sub.zsub_classinst, sub.zsub_recipient); |
| 2086 | 966 } |
| 9478 | 967 |
| 9610 | 968 zephyr->subscrips = g_slist_append(zephyr->subscrips, new_triple(zephyr,sub.zsub_class,sub.zsub_classinst,sub.zsub_recipient)); |
| 9478 | 969 /* g_hash_table_destroy(sub_hash_table); */ |
| 970 g_free(z_instance); | |
| 971 g_free(z_class); | |
| 2086 | 972 g_free(recip); |
| 973 } | |
| 974 g_strfreev(triple); | |
| 975 } | |
| 976 } | |
| 977 } | |
| 978 } | |
| 979 | |
| 9610 | 980 static void process_anyone(GaimConnection *gc) |
| 2086 | 981 { |
| 982 FILE *fd; | |
| 983 gchar buff[BUFSIZ], *filename; | |
| 6695 | 984 GaimGroup *g; |
| 985 GaimBuddy *b; | |
| 4775 | 986 |
| 987 if (!(g = gaim_find_group(_("Anyone")))) { | |
| 988 g = gaim_group_new(_("Anyone")); | |
| 989 gaim_blist_add_group(g, NULL); | |
| 990 } | |
| 6695 | 991 |
| 3630 | 992 filename = g_strconcat(gaim_home_dir(), "/.anyone", NULL); |
| 2086 | 993 if ((fd = fopen(filename, "r")) != NULL) { |
| 994 while (fgets(buff, BUFSIZ, fd)) { | |
| 995 strip_comments(buff); | |
| 4687 | 996 if (buff[0]) { |
| 9610 | 997 if (!(b = gaim_find_buddy(gc->account, buff))) { |
| 998 b = gaim_buddy_new(gc->account, buff, NULL); | |
| 8644 | 999 gaim_blist_add_buddy(b, NULL, g, NULL); |
| 1000 } | |
| 1001 } | |
| 2086 | 1002 } |
| 1003 fclose(fd); | |
| 1004 } | |
| 1005 g_free(filename); | |
| 1006 } | |
| 1007 | |
| 8644 | 1008 static void zephyr_login(GaimAccount * account) |
| 2086 | 1009 { |
| 1010 ZSubscription_t sub; | |
| 9610 | 1011 GaimConnection *gc; |
| 1012 zephyr_account *zephyr; | |
| 9427 | 1013 |
| 9610 | 1014 gc = gaim_account_get_connection(account); |
| 1015 gc->flags |= GAIM_CONNECTION_HTML | GAIM_CONNECTION_NO_BGCOLOR | GAIM_CONNECTION_NO_URLDESC; | |
| 1016 gc->proto_data = zephyr=g_new0(zephyr_account,1); | |
| 2086 | 1017 |
| 9610 | 1018 gaim_connection_update_progress(gc, _("Connecting"), 0, 8); |
| 9478 | 1019 |
| 1020 /* XXX z_call_s should actually try to report the com_err determined error */ | |
| 8645 | 1021 |
| 2086 | 1022 z_call_s(ZInitialize(), "Couldn't initialize zephyr"); |
| 9610 | 1023 z_call_s(ZOpenPort(&(zephyr->port)), "Couldn't open port"); |
| 8644 | 1024 z_call_s(ZSetLocation((char *) |
| 9610 | 1025 gaim_account_get_string(gc->account, "exposure_level", EXPOSE_REALMVIS)), "Couldn't set location"); |
| 2086 | 1026 |
| 1027 sub.zsub_class = "MESSAGE"; | |
| 1028 sub.zsub_classinst = "PERSONAL"; | |
| 8354 | 1029 sub.zsub_recipient = (char *)gaim_zephyr_get_sender(); |
| 9427 | 1030 |
| 2086 | 1031 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { |
| 9478 | 1032 /* XXX don't translate this yet. It could be written better */ |
| 1033 /* XXX error messages could be handled with more detail */ | |
| 1034 gaim_notify_error(account->gc, NULL, | |
| 1035 "Unable to subscribe to messages", "Unable to subscribe to initial messages"); | |
| 1036 return; | |
| 2086 | 1037 } |
| 1038 | |
| 9610 | 1039 gaim_connection_set_state(gc, GAIM_CONNECTED); |
| 1040 serv_finish_login(gc); | |
| 2086 | 1041 |
| 9610 | 1042 process_anyone(gc); |
| 1043 process_zsubs(gc->proto_data); | |
| 2086 | 1044 |
| 9610 | 1045 zephyr->nottimer = gaim_timeout_add(100, check_notify, gc); |
| 1046 zephyr->loctimer = gaim_timeout_add(20000, check_loc, gc); | |
| 2086 | 1047 } |
| 1048 | |
| 9610 | 1049 static void write_zsubs(zephyr_account *zephyr) |
| 2086 | 1050 { |
| 9434 | 1051 /* Exports subscription (chat) list back to |
| 1052 * .zephyr.subs | |
| 1053 * XXX deal with %host%, %canon%, unsubscriptions, and negative subscriptions (punts?) | |
| 1054 */ | |
| 1055 | |
| 9610 | 1056 GSList *s = zephyr->subscrips; |
| 2086 | 1057 zephyr_triple *zt; |
| 1058 FILE *fd; | |
| 1059 char *fname; | |
| 1060 | |
| 8644 | 1061 char **triple; |
| 1062 | |
| 3630 | 1063 fname = g_strdup_printf("%s/.zephyr.subs", gaim_home_dir()); |
| 2086 | 1064 fd = fopen(fname, "w"); |
| 8644 | 1065 |
| 2086 | 1066 if (!fd) { |
| 1067 g_free(fname); | |
| 1068 return; | |
| 1069 } | |
| 8644 | 1070 |
| 2086 | 1071 while (s) { |
| 9478 | 1072 char *zclass, *zinst, *zrecip; |
| 2086 | 1073 zt = s->data; |
| 8644 | 1074 triple = g_strsplit(zt->name, ",", 3); |
| 9478 | 1075 |
| 1076 /* deal with classes */ | |
| 9610 | 1077 if (!g_ascii_strcasecmp(triple[0],zephyr->ourhost)) { |
| 9478 | 1078 zclass = g_strdup("%host%");; |
| 9610 | 1079 } else if (!g_ascii_strcasecmp(triple[0],zephyr->ourhostcanon)) { |
| 9478 | 1080 zclass = g_strdup("%canon%");; |
| 1081 } else { | |
| 1082 zclass = g_strdup(triple[0]); | |
| 1083 } | |
| 1084 | |
| 1085 /* deal with instances */ | |
| 1086 | |
| 9610 | 1087 if (!g_ascii_strcasecmp(triple[1],zephyr->ourhost)) { |
| 9478 | 1088 zinst = g_strdup("%host%");; |
| 9610 | 1089 } else if (!g_ascii_strcasecmp(triple[1],zephyr->ourhostcanon)) { |
| 9478 | 1090 zinst = g_strdup("%canon%");; |
| 3277 | 1091 } else { |
| 9478 | 1092 zinst = g_strdup(triple[1]); |
| 3277 | 1093 } |
| 9478 | 1094 |
| 1095 /* deal with recipients */ | |
| 1096 if (triple[2] == NULL) { | |
| 1097 zrecip = g_strdup("*"); | |
| 1098 } else if (!g_ascii_strcasecmp(triple[2],"")){ | |
| 1099 zrecip = g_strdup("*"); | |
| 1100 } else if (!g_ascii_strcasecmp(triple[2], gaim_zephyr_get_sender())) { | |
| 1101 zrecip = g_strdup("%me%"); | |
| 3277 | 1102 } else { |
| 9478 | 1103 zrecip = g_strdup(triple[2]); |
| 3277 | 1104 } |
| 9478 | 1105 |
| 1106 fprintf(fd, "%s,%s,%s\n",zclass,zinst,zrecip); | |
| 1107 | |
| 1108 g_free(zclass); | |
| 1109 g_free(zinst); | |
| 1110 g_free(zrecip); | |
| 3277 | 1111 g_free(triple); |
| 2086 | 1112 s = s->next; |
| 1113 } | |
| 1114 g_free(fname); | |
| 1115 fclose(fd); | |
| 1116 } | |
| 1117 | |
| 9610 | 1118 static void write_anyone(GaimConnection *gc) |
| 2086 | 1119 { |
| 6695 | 1120 GaimBlistNode *gnode, *cnode, *bnode; |
| 1121 GaimBuddy *b; | |
| 3277 | 1122 char *ptr, *fname, *ptr2; |
| 2086 | 1123 FILE *fd; |
| 1124 | |
| 3630 | 1125 fname = g_strdup_printf("%s/.anyone", gaim_home_dir()); |
| 2086 | 1126 fd = fopen(fname, "w"); |
| 1127 if (!fd) { | |
| 1128 g_free(fname); | |
| 1129 return; | |
| 1130 } | |
| 1131 | |
| 8644 | 1132 for (gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { |
| 1133 if (!GAIM_BLIST_NODE_IS_GROUP(gnode)) | |
| 4785 | 1134 continue; |
| 8644 | 1135 for (cnode = gnode->child; cnode; cnode = cnode->next) { |
| 1136 if (!GAIM_BLIST_NODE_IS_CONTACT(cnode)) | |
| 4785 | 1137 continue; |
| 8644 | 1138 for (bnode = cnode->child; bnode; bnode = bnode->next) { |
| 1139 if (!GAIM_BLIST_NODE_IS_BUDDY(bnode)) | |
| 6695 | 1140 continue; |
| 8644 | 1141 b = (GaimBuddy *) bnode; |
| 9610 | 1142 if (b->account == gc->account) { |
| 6695 | 1143 if ((ptr = strchr(b->name, '@')) != NULL) { |
| 1144 ptr2 = ptr + 1; | |
| 1145 /* We should only strip the realm name if the principal | |
| 1146 is in the user's realm | |
| 8644 | 1147 */ |
| 1148 if (!g_ascii_strcasecmp(ptr2, gaim_zephyr_get_realm())) { | |
| 6695 | 1149 *ptr = '\0'; |
| 1150 } | |
| 4349 | 1151 } |
| 6695 | 1152 fprintf(fd, "%s\n", b->name); |
| 1153 if (ptr) | |
| 1154 *ptr = '@'; | |
| 3277 | 1155 } |
| 1156 } | |
| 2086 | 1157 } |
| 1158 } | |
| 1159 | |
| 1160 fclose(fd); | |
| 1161 g_free(fname); | |
| 1162 } | |
| 1163 | |
| 8644 | 1164 static void zephyr_close(GaimConnection * gc) |
| 2086 | 1165 { |
| 1166 GList *l; | |
| 1167 GSList *s; | |
| 9610 | 1168 zephyr_account *zephyr = gc->proto_data; |
| 8644 | 1169 |
| 9610 | 1170 l = zephyr->pending_zloc_names; |
| 2086 | 1171 while (l) { |
| 8644 | 1172 g_free((char *)l->data); |
| 2086 | 1173 l = l->next; |
| 1174 } | |
| 9610 | 1175 g_list_free(zephyr->pending_zloc_names); |
| 8644 | 1176 |
| 9610 | 1177 if (gaim_account_get_bool(gc->account, "write_anyone", FALSE)) |
| 1178 write_anyone(gc); | |
| 8644 | 1179 |
| 9610 | 1180 if (gaim_account_get_bool(gc->account, "write_zsubs", FALSE)) |
| 1181 write_zsubs(gc->proto_data); | |
| 8644 | 1182 |
| 9610 | 1183 s = zephyr->subscrips; |
| 2086 | 1184 while (s) { |
| 8644 | 1185 free_triple((zephyr_triple *) s->data); |
| 2086 | 1186 s = s->next; |
| 1187 } | |
| 9610 | 1188 g_slist_free(zephyr->subscrips); |
| 8644 | 1189 |
| 9610 | 1190 if (zephyr->nottimer) |
| 1191 gaim_timeout_remove(zephyr->nottimer); | |
| 1192 zephyr->nottimer = 0; | |
| 1193 if (zephyr->loctimer) | |
| 1194 gaim_timeout_remove(zephyr->loctimer); | |
| 1195 zephyr->loctimer = 0; | |
| 1196 gc = NULL; | |
| 2086 | 1197 z_call(ZCancelSubscriptions(0)); |
| 1198 z_call(ZUnsetLocation()); | |
| 1199 z_call(ZClosePort()); | |
| 1200 } | |
| 1201 | |
| 9434 | 1202 static int zephyr_send_message(char* zclass, char* instance, char* recipient, const char *im, |
| 9478 | 1203 const char *sig, char *opcode) ; |
| 9434 | 1204 |
| 1205 const char * zephyr_get_signature() | |
| 1206 { | |
| 9478 | 1207 /* XXX add zephyr error reporting */ |
| 1208 const char * sig =ZGetVariable("zwrite-signature"); | |
| 9434 | 1209 if (!sig) { |
| 1210 sig = g_get_real_name(); | |
| 1211 } | |
| 1212 return sig; | |
| 1213 } | |
| 1214 | |
| 8644 | 1215 static int zephyr_chat_send(GaimConnection * gc, int id, const char *im) |
| 2086 | 1216 { |
| 1217 zephyr_triple *zt; | |
| 1218 const char *sig; | |
| 8644 | 1219 GaimConversation *gconv1; |
| 1220 GaimConvChat *gcc; | |
| 1221 char *inst; | |
| 9434 | 1222 char *recipient; |
| 2086 | 1223 |
| 9610 | 1224 zt = find_sub_by_id(gc->proto_data,id); |
| 2086 | 1225 if (!zt) |
| 1226 /* this should never happen. */ | |
|
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1227 return -EINVAL; |
| 8644 | 1228 |
| 9434 | 1229 sig = zephyr_get_signature(); |
| 2086 | 1230 |
| 9610 | 1231 gconv1 = gaim_find_conversation_with_account(zt->name, gc->account); |
| 8644 | 1232 gcc = gaim_conversation_get_chat_data(gconv1); |
| 8212 | 1233 |
| 8644 | 1234 if (!(inst = (char *)gaim_conv_chat_get_topic(gcc))) |
| 9434 | 1235 inst = g_strdup("PERSONAL"); |
| 8644 | 1236 |
| 4793 | 1237 if (!g_ascii_strcasecmp(zt->recipient, "*")) |
| 9434 | 1238 recipient = local_zephyr_normalize(""); |
| 2086 | 1239 else |
| 9434 | 1240 recipient = local_zephyr_normalize(zt->recipient); |
| 8451 | 1241 |
| 9478 | 1242 zephyr_send_message(zt->class,inst,recipient,im,sig,""); |
| 9434 | 1243 /* g_free(inst); */ |
| 1244 /* g_free(recipient); */ | |
|
2167
edf8c5a70e5b
[gaim-migrate @ 2177]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
1245 return 0; |
| 2086 | 1246 } |
| 1247 | |
| 9434 | 1248 |
| 8644 | 1249 static int zephyr_send_im(GaimConnection * gc, const char *who, const char *im, GaimConvImFlags flags) |
| 1250 { | |
| 2086 | 1251 const char *sig; |
| 8644 | 1252 |
|
7118
bf630f7dfdcd
[gaim-migrate @ 7685]
Christian Hammond <chipx86@chipx86.com>
parents:
7084
diff
changeset
|
1253 if (flags & GAIM_CONV_IM_AUTO_RESP) |
| 2086 | 1254 sig = "Automated reply:"; |
| 1255 else { | |
| 9434 | 1256 sig = zephyr_get_signature(); |
| 2086 | 1257 } |
| 9478 | 1258 zephyr_send_message("MESSAGE","PERSONAL",local_zephyr_normalize(who),im,sig,""); |
| 9434 | 1259 |
| 1260 return 1; | |
| 1261 } | |
| 2086 | 1262 |
| 9434 | 1263 static int zephyr_send_message(char* zclass, char* instance, char* recipient, const char *im, |
| 9478 | 1264 const char *sig, char *opcode) |
| 9434 | 1265 { |
| 1266 char *html_buf; | |
| 1267 char *html_buf2; | |
| 1268 char *buf; | |
| 1269 ZNotice_t notice; | |
| 8451 | 1270 |
| 9434 | 1271 html_buf = html_to_zephyr(im); |
| 1272 html_buf2 = gaim_unescape_html(html_buf); | |
| 1273 | |
| 1274 buf = g_strdup_printf("%s%c%s", sig, '\0', html_buf2); | |
| 2086 | 1275 bzero((char *)¬ice, sizeof(notice)); |
| 9434 | 1276 |
| 2086 | 1277 notice.z_kind = ACKED; |
| 1278 notice.z_port = 0; | |
| 1279 notice.z_opcode = ""; | |
| 9434 | 1280 notice.z_class = zclass; |
| 1281 notice.z_class_inst = instance; | |
| 1282 notice.z_recipient = recipient; | |
| 1283 notice.z_sender = 0; | |
| 1284 notice.z_default_format = "Class $class, Instance $instance:\n" "To: @bold($recipient) at $time $date\n" "From: @bold($1) <$sender>\n\n$2"; | |
| 8451 | 1285 notice.z_message_len = strlen(html_buf2) + strlen(sig) + 2; |
| 2086 | 1286 notice.z_message = buf; |
| 9478 | 1287 notice.z_opcode = g_strdup(opcode); |
| 1288 gaim_debug_info("zephyr","About to send notice"); | |
| 1289 if (! ZSendNotice(¬ice, ZAUTH) == ZERR_NONE) { | |
| 1290 /* XXX handle errors here */ | |
| 1291 return 0; | |
| 1292 } | |
| 1293 gaim_debug_info("zephyr","notice sent"); | |
| 1294 g_free(buf); | |
| 1295 | |
| 8644 | 1296 g_free(html_buf2); |
| 1297 g_free(html_buf); | |
| 8451 | 1298 |
| 9434 | 1299 return 1; |
| 2086 | 1300 } |
| 1301 | |
| 8644 | 1302 static const char *zephyr_normalize(const GaimAccount * account, const char *orig) |
| 2086 | 1303 { |
| 9328 | 1304 /* returns the string you gave it. Maybe this function shouldn't be here */ |
| 2086 | 1305 static char buf[80]; |
| 8644 | 1306 |
| 7126 | 1307 if (!g_ascii_strcasecmp(orig, "")) { |
| 1308 buf[0] = '\0'; | |
| 1309 return buf; | |
| 8354 | 1310 } else { |
| 8644 | 1311 g_snprintf(buf, 80, "%s", orig); |
| 1312 } | |
| 1313 return buf; | |
| 8354 | 1314 } |
| 1315 | |
| 1316 | |
| 9328 | 1317 char *local_zephyr_normalize(const char *orig) |
| 8354 | 1318 { |
| 9328 | 1319 /* |
| 1320 Basically the inverse of zephyr_strip_foreign_realm | |
| 1321 */ | |
| 8644 | 1322 static char buf[80]; |
| 1323 | |
| 8354 | 1324 if (!g_ascii_strcasecmp(orig, "")) { |
| 1325 buf[0] = '\0'; | |
| 1326 return buf; | |
| 7126 | 1327 } |
| 8644 | 1328 |
| 2086 | 1329 if (strchr(orig, '@')) { |
| 1330 g_snprintf(buf, 80, "%s", orig); | |
| 1331 } else { | |
| 8644 | 1332 g_snprintf(buf, 80, "%s@%s", orig, gaim_zephyr_get_realm()); |
| 2086 | 1333 } |
| 1334 return buf; | |
| 1335 } | |
| 1336 | |
| 9030 | 1337 static void zephyr_zloc(GaimConnection *gc, const char *who) |
| 2086 | 1338 { |
| 1339 ZAsyncLocateData_t ald; | |
| 9328 | 1340 gchar* normalized_who = local_zephyr_normalize(who); |
| 9610 | 1341 zephyr_account *zephyr = gc->proto_data; |
| 7261 | 1342 |
| 9328 | 1343 if (ZRequestLocations(normalized_who, &ald, UNACKED, ZAUTH) == ZERR_NONE) { |
| 9610 | 1344 zephyr->pending_zloc_names = g_list_append(zephyr->pending_zloc_names, |
| 9328 | 1345 g_strdup(normalized_who)); |
| 9478 | 1346 } else { |
| 1347 /* XXX deal with errors somehow */ | |
| 2086 | 1348 } |
| 1349 } | |
| 1350 | |
| 8644 | 1351 static void zephyr_set_away(GaimConnection * gc, const char *state, const char *msg) |
| 2086 | 1352 { |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1353 if (gc->away) { |
| 2086 | 1354 g_free(gc->away); |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1355 gc->away = NULL; |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1356 } |
|
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1357 |
| 5132 | 1358 if (!g_ascii_strcasecmp(state, _("Hidden"))) { |
| 9478 | 1359 /* XXX handle errors */ |
| 2086 | 1360 ZSetLocation(EXPOSE_OPSTAFF); |
|
4111
ee884f1d7ae3
[gaim-migrate @ 4326]
Christian Hammond <chipx86@chipx86.com>
parents:
3867
diff
changeset
|
1361 gc->away = g_strdup(""); |
| 9478 | 1362 } |
| 1363 else if (!g_ascii_strcasecmp(state, _("Online"))) { | |
| 1364 /* XXX handle errors */ | |
| 2086 | 1365 ZSetLocation(get_exposure_level()); |
| 9478 | 1366 } |
| 2086 | 1367 else /* state is GAIM_AWAY_CUSTOM */ if (msg) |
| 1368 gc->away = g_strdup(msg); | |
| 1369 } | |
| 1370 | |
| 8644 | 1371 static GList *zephyr_away_states(GaimConnection * gc) |
| 2086 | 1372 { |
| 1373 GList *m = NULL; | |
| 1374 | |
| 5132 | 1375 m = g_list_append(m, _("Online")); |
| 2086 | 1376 m = g_list_append(m, GAIM_AWAY_CUSTOM); |
| 5132 | 1377 m = g_list_append(m, _("Hidden")); |
| 2086 | 1378 |
| 1379 return m; | |
| 1380 } | |
| 1381 | |
| 8644 | 1382 static GList *zephyr_chat_info(GaimConnection * gc) |
| 1383 { | |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1384 GList *m = NULL; |
|
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1385 struct proto_chat_entry *pce; |
| 2086 | 1386 |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1387 pce = g_new0(struct proto_chat_entry, 1); |
| 8644 | 1388 |
| 7841 | 1389 pce->label = _("_Class:"); |
| 5234 | 1390 pce->identifier = "class"; |
| 3158 | 1391 m = g_list_append(m, pce); |
| 2086 | 1392 |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1393 pce = g_new0(struct proto_chat_entry, 1); |
| 8644 | 1394 |
| 7841 | 1395 pce->label = _("_Instance:"); |
| 5234 | 1396 pce->identifier = "instance"; |
| 3158 | 1397 m = g_list_append(m, pce); |
| 2086 | 1398 |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1399 pce = g_new0(struct proto_chat_entry, 1); |
| 8644 | 1400 |
| 7841 | 1401 pce->label = _("_Recipient:"); |
| 5234 | 1402 pce->identifier = "recipient"; |
| 3158 | 1403 m = g_list_append(m, pce); |
| 2086 | 1404 |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1405 return m; |
| 2086 | 1406 } |
| 1407 | |
| 9478 | 1408 /* Called when the server notifies us a message couldn't get sent */ |
| 1409 | |
| 9610 | 1410 static void zephyr_subscribe_failed(GaimConnection *gc,ZSubscription_t *sub) |
| 9478 | 1411 { |
| 1412 gchar* subscribe_failed = g_strdup_printf(_("Attempt to subscribe to %s,%s,%s failed"), sub->zsub_class, sub->zsub_classinst,sub->zsub_recipient); | |
| 9610 | 1413 gaim_notify_error(gc,"", subscribe_failed, NULL); |
| 9478 | 1414 g_free(subscribe_failed); |
| 1415 } | |
| 1416 | |
| 8644 | 1417 static void zephyr_join_chat(GaimConnection * gc, GHashTable * data) |
| 2086 | 1418 { |
| 1419 ZSubscription_t sub; | |
| 1420 zephyr_triple *zt1, *zt2; | |
| 1421 const char *classname; | |
| 1422 const char *instname; | |
| 1423 const char *recip; | |
| 9610 | 1424 zephyr_account *zephyr=gc->proto_data; |
| 5234 | 1425 classname = g_hash_table_lookup(data, "class"); |
| 1426 instname = g_hash_table_lookup(data, "instance"); | |
| 1427 recip = g_hash_table_lookup(data, "recipient"); | |
| 1428 | |
| 9478 | 1429 |
| 9328 | 1430 if (!classname) |
|
2205
cff4fbe01c7b
[gaim-migrate @ 2215]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
1431 return; |
| 9478 | 1432 |
| 1433 if (!g_ascii_strcasecmp(classname,"%host%")) | |
| 9610 | 1434 classname = g_strdup(zephyr->ourhost); |
| 9478 | 1435 if (!g_ascii_strcasecmp(classname,"%canon%")) |
| 9610 | 1436 classname = g_strdup(zephyr->ourhostcanon); |
| 9478 | 1437 |
| 9328 | 1438 if (!instname || !strlen(instname)) |
| 1439 instname = "*"; | |
| 9478 | 1440 |
| 1441 if (!g_ascii_strcasecmp(instname,"%host%")) | |
| 9610 | 1442 instname = g_strdup(zephyr->ourhost); |
| 9478 | 1443 if (!g_ascii_strcasecmp(instname,"%canon%")) |
| 9610 | 1444 instname = g_strdup(zephyr->ourhostcanon); |
| 9478 | 1445 |
| 9328 | 1446 if (!recip || (*recip == '*')) |
| 1447 recip = ""; | |
| 4793 | 1448 if (!g_ascii_strcasecmp(recip, "%me%")) |
| 8354 | 1449 recip = gaim_zephyr_get_sender(); |
| 2086 | 1450 |
| 9610 | 1451 zt1 = new_triple(gc->proto_data,classname, instname, recip); |
| 1452 zt2 = find_sub_by_triple(gc->proto_data,zt1); | |
| 2086 | 1453 if (zt2) { |
| 1454 free_triple(zt1); | |
| 9328 | 1455 if (!zt2->open) { |
| 1456 if (!g_ascii_strcasecmp(instname,"*")) | |
| 1457 instname = "PERSONAL"; | |
| 9434 | 1458 serv_got_joined_chat(gc, zt2->id, zt2->name); |
| 9610 | 1459 zephyr_chat_set_topic(gc,zt2->id,instname); |
| 9328 | 1460 zt2->open = TRUE; |
| 1461 } | |
| 2086 | 1462 return; |
| 1463 } | |
| 9434 | 1464 |
| 2086 | 1465 sub.zsub_class = zt1->class; |
| 1466 sub.zsub_classinst = zt1->instance; | |
| 1467 sub.zsub_recipient = zt1->recipient; | |
| 9434 | 1468 |
| 2086 | 1469 if (ZSubscribeTo(&sub, 1, 0) != ZERR_NONE) { |
| 9478 | 1470 /* XXX output better subscription information */ |
| 9610 | 1471 zephyr_subscribe_failed(gc,&sub); |
| 2086 | 1472 free_triple(zt1); |
| 1473 return; | |
| 1474 } | |
| 1475 | |
| 9610 | 1476 zephyr->subscrips = g_slist_append(zephyr->subscrips, zt1); |
| 2086 | 1477 zt1->open = TRUE; |
| 1478 serv_got_joined_chat(gc, zt1->id, zt1->name); | |
| 9328 | 1479 if (!g_ascii_strcasecmp(instname,"*")) |
| 1480 instname = "PERSONAL"; | |
| 9610 | 1481 zephyr_chat_set_topic(gc,zt1->id,instname); |
| 2086 | 1482 } |
| 1483 | |
| 8644 | 1484 static void zephyr_chat_leave(GaimConnection * gc, int id) |
| 2086 | 1485 { |
| 1486 zephyr_triple *zt; | |
| 9610 | 1487 zephyr_account *zephyr = gc->proto_data; |
| 1488 zt = find_sub_by_id(zephyr,id); | |
| 2086 | 1489 if (zt) { |
| 1490 zt->open = FALSE; | |
| 9610 | 1491 zt->id = ++(zephyr->last_id); |
| 2086 | 1492 } |
| 1493 } | |
| 1494 | |
| 9478 | 1495 static GaimChat *zephyr_find_blist_chat(GaimAccount *account, const char *name) |
| 1496 { | |
| 1497 GaimBlistNode *gnode, *cnode; | |
| 1498 | |
| 1499 /* XXX needs to be %host%,%canon%, and %me% clean */ | |
| 1500 for(gnode = gaim_get_blist()->root; gnode; gnode = gnode->next) { | |
| 1501 for(cnode = gnode->child; cnode; cnode = cnode->next) { | |
| 1502 GaimChat *chat = (GaimChat*)cnode; | |
| 1503 char *zclass, *inst, *recip; | |
| 1504 char** triple; | |
| 1505 if(!GAIM_BLIST_NODE_IS_CHAT(cnode)) | |
| 1506 continue; | |
| 1507 if(chat->account !=account) | |
| 1508 continue; | |
| 1509 if(!(zclass = g_hash_table_lookup(chat->components, "class"))) | |
| 1510 continue; | |
| 1511 if(!(inst = g_hash_table_lookup(chat->components, "instance"))) | |
| 1512 inst = g_strdup(""); | |
| 1513 if(!(recip = g_hash_table_lookup(chat->components, "recipient"))) | |
| 1514 recip = g_strdup(""); | |
| 1515 triple = g_strsplit(name,",",3); | |
| 1516 if (!g_ascii_strcasecmp(triple[0],zclass) && !g_ascii_strcasecmp(triple[1],inst) && !g_ascii_strcasecmp(triple[2],recip)) | |
| 1517 return chat; | |
| 1518 | |
| 1519 } | |
| 1520 } | |
| 1521 return NULL; | |
| 1522 } | |
| 8644 | 1523 static const char *zephyr_list_icon(GaimAccount * a, GaimBuddy * b) |
| 5202 | 1524 { |
| 1525 return "zephyr"; | |
| 1526 } | |
| 1527 | |
| 9478 | 1528 static int zephyr_send_typing(GaimConnection *gc, const char *who, int typing) { |
| 1529 gchar *recipient; | |
| 1530 if (!typing) | |
| 1531 return 0; | |
| 1532 /* XXX We probably should care if this fails. Or maybe we don't want to */ | |
| 1533 if (!who) { | |
| 1534 gaim_debug_info("zephyr", "who is null\n"); | |
| 1535 recipient = local_zephyr_normalize(""); | |
| 1536 } else { | |
| 1537 recipient = local_zephyr_normalize(who); | |
| 1538 } | |
| 1539 | |
| 1540 gaim_debug_info("zephyr","about to send typing notification to %s",recipient); | |
| 1541 zephyr_send_message("MESSAGE","PERSONAL",recipient,"","","PING"); | |
| 1542 gaim_debug_info("zephyr","sent typing notification"); | |
| 1543 return ZEPHYR_TYPING_SEND_TIMEOUT; | |
| 1544 } | |
| 8212 | 1545 |
| 9434 | 1546 |
| 1547 | |
| 8644 | 1548 static void zephyr_chat_set_topic(GaimConnection * gc, int id, const char *topic) |
| 1549 { | |
| 1550 zephyr_triple *zt; | |
| 1551 GaimConversation *gconv; | |
| 1552 GaimConvChat *gcc; | |
| 9434 | 1553 gchar *topic_utf8; |
| 8644 | 1554 char *sender = (char *)gaim_zephyr_get_sender(); |
| 8212 | 1555 |
| 9610 | 1556 zt = find_sub_by_id(gc->proto_data,id); |
| 1557 gconv = gaim_find_conversation_with_account(zt->name, gc->account); | |
| 8644 | 1558 gcc = gaim_conversation_get_chat_data(gconv); |
| 9434 | 1559 |
| 9610 | 1560 topic_utf8 = zephyr_recv_convert(gc,(gchar *)topic,strlen(topic)); |
| 9434 | 1561 gaim_conv_chat_set_topic(gcc,sender,topic_utf8); |
| 1562 g_free(topic_utf8); | |
| 1563 return; | |
| 1564 } | |
| 1565 | |
| 1566 /* commands */ | |
| 1567 | |
| 1568 static GaimCmdRet zephyr_gaim_cmd_msg(GaimConversation *conv, | |
| 9597 | 1569 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1570 { |
| 1571 char *recipient; | |
| 9478 | 1572 |
| 9434 | 1573 if (!g_ascii_strcasecmp(args[0],"*")) |
| 9478 | 1574 return GAIM_CMD_RET_FAILED; /* "*" is not a valid argument */ |
| 9434 | 1575 else |
| 1576 recipient = local_zephyr_normalize(args[0]); | |
| 1577 | |
| 9478 | 1578 if (strlen(recipient) < 1) |
| 1579 return GAIM_CMD_RET_FAILED; /* a null recipient is a chat message, not an IM */ | |
| 1580 | |
| 1581 if (zephyr_send_message("MESSAGE","PERSONAL",recipient,args[1],zephyr_get_signature(),"")) | |
| 9434 | 1582 return GAIM_CMD_RET_OK; |
| 1583 else | |
| 1584 return GAIM_CMD_RET_FAILED; | |
| 1585 } | |
| 1586 | |
| 1587 static GaimCmdRet zephyr_gaim_cmd_zlocate(GaimConversation *conv, | |
| 9597 | 1588 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1589 { |
| 9610 | 1590 zephyr_zloc(gaim_conversation_get_gc(conv),args[0]); |
| 9434 | 1591 return GAIM_CMD_RET_OK; |
| 1592 } | |
| 1593 | |
| 1594 static GaimCmdRet zephyr_gaim_cmd_instance(GaimConversation *conv, | |
| 9597 | 1595 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1596 { |
| 1597 /* Currently it sets the instance with leading spaces and | |
| 1598 * all. This might not be the best thing to do, though having | |
| 1599 * one word isn't ideal either. */ | |
| 1600 | |
| 9610 | 1601 GaimConvChat *gcc = gaim_conversation_get_chat_data(conv); |
| 1602 int id = gcc->id; | |
| 9434 | 1603 const char* instance = args[0]; |
| 9610 | 1604 zephyr_chat_set_topic(gaim_conversation_get_gc(conv),id,instance); |
| 9434 | 1605 return GAIM_CMD_RET_OK; |
| 1606 } | |
| 1607 | |
| 1608 static GaimCmdRet zephyr_gaim_cmd_joinchat_cir(GaimConversation *conv, | |
| 9597 | 1609 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1610 { |
| 1611 /* Join a new zephyr chat */ | |
| 1612 GHashTable *triple = g_hash_table_new(NULL,NULL); | |
| 1613 g_hash_table_insert(triple,"class",args[0]); | |
| 1614 g_hash_table_insert(triple,"instance",args[1]); | |
| 1615 g_hash_table_insert(triple,"recipient",args[2]); | |
| 9610 | 1616 zephyr_join_chat(gaim_conversation_get_gc(conv),triple); |
| 9434 | 1617 return GAIM_CMD_RET_OK; |
| 1618 } | |
| 1619 | |
| 1620 static GaimCmdRet zephyr_gaim_cmd_zi(GaimConversation *conv, | |
| 9597 | 1621 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1622 { |
| 1623 /* args = instance, message */ | |
| 9478 | 1624 if ( zephyr_send_message("message",args[0],"",args[1],zephyr_get_signature(),"")) |
| 9434 | 1625 return GAIM_CMD_RET_OK; |
| 1626 else | |
| 1627 return GAIM_CMD_RET_FAILED; | |
| 1628 } | |
| 1629 | |
| 1630 static GaimCmdRet zephyr_gaim_cmd_zci(GaimConversation *conv, | |
| 9597 | 1631 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1632 { |
| 1633 /* args = class, instance, message */ | |
| 9478 | 1634 if ( zephyr_send_message(args[0],args[1],"",args[2],zephyr_get_signature(),"")) |
| 9434 | 1635 return GAIM_CMD_RET_OK; |
| 1636 else | |
| 1637 return GAIM_CMD_RET_FAILED; | |
| 1638 } | |
| 8644 | 1639 |
| 9434 | 1640 static GaimCmdRet zephyr_gaim_cmd_zcir(GaimConversation *conv, |
| 9597 | 1641 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1642 { |
| 1643 /* args = class, instance, recipient, message */ | |
| 9478 | 1644 if ( zephyr_send_message(args[0],args[1],args[2],args[3],zephyr_get_signature(),"")) |
| 9434 | 1645 return GAIM_CMD_RET_OK; |
| 1646 else | |
| 1647 return GAIM_CMD_RET_FAILED; | |
| 8212 | 1648 } |
| 1649 | |
| 9434 | 1650 static GaimCmdRet zephyr_gaim_cmd_zir(GaimConversation *conv, |
| 9597 | 1651 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1652 { |
| 1653 /* args = instance, recipient, message */ | |
| 9478 | 1654 if ( zephyr_send_message("message",args[0],args[1],args[2],zephyr_get_signature(),"")) |
| 9434 | 1655 return GAIM_CMD_RET_OK; |
| 1656 else | |
| 1657 return GAIM_CMD_RET_FAILED; | |
| 1658 } | |
| 1659 | |
| 1660 static GaimCmdRet zephyr_gaim_cmd_zc(GaimConversation *conv, | |
| 9597 | 1661 const char *cmd, char **args, char **error, void *data) |
| 9434 | 1662 { |
| 1663 /* args = class, message */ | |
| 9478 | 1664 if ( zephyr_send_message(args[0],"PERSONAL","",args[1],zephyr_get_signature(),"")) |
| 9434 | 1665 return GAIM_CMD_RET_OK; |
| 9597 | 1666 else |
| 9434 | 1667 return GAIM_CMD_RET_FAILED; |
| 1668 } | |
| 1669 | |
| 9597 | 1670 static void zephyr_register_slash_commands() |
| 9434 | 1671 { |
| 1672 | |
| 1673 gaim_cmd_register("msg","ws", GAIM_CMD_P_PRPL, | |
| 1674 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1675 "prpl-zephyr", | |
| 9597 | 1676 zephyr_gaim_cmd_msg, _("msg <nick> <message>: Send a private message to a user"), NULL); |
| 9434 | 1677 |
| 1678 gaim_cmd_register("zlocate","w", GAIM_CMD_P_PRPL, | |
| 1679 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1680 "prpl-zephyr", | |
| 9597 | 1681 zephyr_gaim_cmd_zlocate, _("zlocate <nick>: Locate user"), NULL); |
| 9434 | 1682 |
| 1683 gaim_cmd_register("zl","w", GAIM_CMD_P_PRPL, | |
| 1684 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1685 "prpl-zephyr", | |
| 9597 | 1686 zephyr_gaim_cmd_zlocate, _("zl <nick>: Locate user"), NULL); |
| 9434 | 1687 |
| 1688 gaim_cmd_register("instance","s", GAIM_CMD_P_PRPL, | |
| 1689 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1690 "prpl-zephyr", | |
| 9597 | 1691 zephyr_gaim_cmd_instance, _("instance <instance>: Set the instance to be used on this class"), NULL); |
| 9434 | 1692 |
| 1693 gaim_cmd_register("inst","s", GAIM_CMD_P_PRPL, | |
| 1694 GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1695 "prpl-zephyr", | |
| 9597 | 1696 zephyr_gaim_cmd_instance, _("inst <instance>: Set the instance to be used on this class"), NULL); |
| 9434 | 1697 |
| 1698 gaim_cmd_register("sub", "www", GAIM_CMD_P_PRPL, | |
| 1699 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1700 "prpl-zephyr", | |
| 9597 | 1701 zephyr_gaim_cmd_joinchat_cir, |
| 1702 _("sub <class> <instance> <recipient>: Join a new chat"), NULL); | |
| 9434 | 1703 |
| 1704 gaim_cmd_register("zi","ws", GAIM_CMD_P_PRPL, | |
| 1705 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1706 "prpl-zephyr", | |
| 9597 | 1707 zephyr_gaim_cmd_zi, _("zi <instance>: Send a message to <message,<i>instance</i>,*>"), NULL); |
| 9434 | 1708 |
| 1709 gaim_cmd_register("zci","wws",GAIM_CMD_P_PRPL, | |
| 1710 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1711 "prpl-zephyr", | |
| 9597 | 1712 zephyr_gaim_cmd_zci, |
| 1713 _("zci <class> <instance>: Send a message to <<i>class</i>,<i>instance</i>,*>"), NULL); | |
| 9434 | 1714 |
| 1715 gaim_cmd_register("zcir","wwws",GAIM_CMD_P_PRPL, | |
| 1716 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1717 "prpl-zephyr", | |
| 9597 | 1718 zephyr_gaim_cmd_zcir, |
| 1719 _("zcir <class> <instance> <recipient>: Send a message to <<i>class</i>,<i>instance</i>,<i>recipient</i>>"), NULL); | |
| 9434 | 1720 |
| 1721 gaim_cmd_register("zir","wws",GAIM_CMD_P_PRPL, | |
| 1722 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1723 "prpl-zephyr", | |
| 9597 | 1724 zephyr_gaim_cmd_zir, |
| 1725 _("zir <instance> <recipient>: Send a message to <MESSAGE,<i>instance</i>,<i>recipient</i>>"), NULL); | |
| 9434 | 1726 |
| 1727 gaim_cmd_register("zc","ws", GAIM_CMD_P_PRPL, | |
| 1728 GAIM_CMD_FLAG_IM | GAIM_CMD_FLAG_CHAT | GAIM_CMD_FLAG_PRPL_ONLY, | |
| 1729 "prpl-zephyr", | |
| 9597 | 1730 zephyr_gaim_cmd_zc, _("zc <class>: Send a message to <<i>class</i>,PERSONAL,*>"), NULL); |
| 1731 | |
| 9434 | 1732 } |
| 1733 | |
| 1734 | |
| 9427 | 1735 static int zephyr_resubscribe(GaimConnection *gc) |
| 1736 { | |
| 1737 /* Resubscribe to the in-memory list of subscriptions and also | |
| 1738 unsubscriptions*/ | |
| 9610 | 1739 zephyr_account *zephyr = gc->proto_data; |
| 1740 GSList *s = zephyr->subscrips; | |
| 9427 | 1741 zephyr_triple *zt; |
| 1742 ZSubscription_t zst; | |
| 1743 while (s) { | |
| 1744 zt = s->data; | |
| 1745 zst.zsub_class = zt->class; | |
| 1746 zst.zsub_classinst = zt->instance; | |
| 1747 zst.zsub_recipient = zt->recipient; | |
| 1748 /* XXX We really should care if this fails */ | |
| 9478 | 1749 ZSubscribeTo(&zst, 1, 0); |
| 9427 | 1750 s = s->next; |
| 1751 } | |
| 1752 /* XXX handle unsubscriptions */ | |
| 1753 return 1; | |
| 1754 } | |
| 1755 | |
| 9434 | 1756 |
| 9427 | 1757 static void zephyr_action_resubscribe(GaimPluginAction *action) |
| 1758 { | |
| 1759 | |
| 1760 GaimConnection *gc = (GaimConnection *) action->context; | |
| 1761 zephyr_resubscribe(gc); | |
| 1762 } | |
| 1763 | |
| 1764 | |
| 9478 | 1765 static void zephyr_action_get_subs_from_server(GaimPluginAction *action) |
| 1766 { | |
| 1767 GaimConnection *gc = (GaimConnection *) action->context; | |
| 9610 | 1768 zephyr_account *zephyr = gc->proto_data; |
| 9478 | 1769 gchar *title; |
| 1770 int retval, nsubs, one,i; | |
| 1771 ZSubscription_t subs; | |
| 1772 GString* subout = g_string_new("Subscription list<br>"); | |
| 1773 | |
| 1774 title = g_strdup_printf("Server subscriptions for %s", gaim_zephyr_get_sender()); | |
| 1775 | |
| 9610 | 1776 if (zephyr->port == 0) { |
| 9478 | 1777 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving port"); |
| 1778 return; | |
| 1779 } | |
| 9610 | 1780 if ((retval = ZRetrieveSubscriptions(zephyr->port,&nsubs)) != ZERR_NONE) { |
| 9478 | 1781 /* XXX better error handling */ |
| 1782 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving subscriptions from server"); | |
| 1783 return; | |
| 1784 } | |
| 1785 g_string_append_printf(subout,"Subscription list <br>"); | |
| 1786 for(i=0;i<nsubs;i++) { | |
| 1787 one = 1; | |
| 1788 if ((retval = ZGetSubscriptions(&subs,&one)) != ZERR_NONE) { | |
| 1789 /* XXX better error handling */ | |
| 1790 gaim_debug(GAIM_DEBUG_ERROR,"zephyr", "error while retrieving individual subscription"); | |
| 1791 return; | |
| 1792 } | |
| 1793 g_string_append_printf(subout, "Class %s Instance %s Recipient %s<br>", | |
| 1794 subs.zsub_class, subs.zsub_classinst, | |
| 1795 subs.zsub_recipient); | |
| 1796 } | |
| 1797 gaim_notify_formatted(gc, title, title, NULL, subout->str, NULL, NULL); | |
| 1798 } | |
| 1799 | |
| 1800 | |
| 9427 | 1801 static GList *zephyr_actions(GaimPlugin *plugin, gpointer context) |
| 1802 { | |
| 1803 GList *list = NULL; | |
| 1804 GaimPluginAction *act = NULL; | |
| 1805 | |
| 1806 act = gaim_plugin_action_new(_("Resubscribe"), zephyr_action_resubscribe); | |
| 1807 list = g_list_append(list, act); | |
| 1808 | |
| 9478 | 1809 act = gaim_plugin_action_new(_("Retrieve subscriptions from server"), zephyr_action_get_subs_from_server); |
| 1810 list = g_list_append(list,act); | |
| 1811 | |
| 9427 | 1812 return list; |
| 1813 } | |
| 1814 | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1815 static GaimPlugin *my_protocol = NULL; |
| 2086 | 1816 |
| 8644 | 1817 static GaimPluginProtocolInfo prpl_info = { |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
1818 GAIM_PRPL_API_VERSION, |
| 8644 | 1819 OPT_PROTO_CHAT_TOPIC | OPT_PROTO_NO_PASSWORD, |
| 9478 | 1820 NULL, /* ??? user_splits */ |
| 1821 NULL, /* ??? protocol_options */ | |
| 1822 NO_BUDDY_ICONS, | |
| 1823 zephyr_list_icon, | |
| 1824 NULL, /* ??? list_emblems */ | |
| 1825 NULL, /* ??? status_text */ | |
| 1826 NULL, /* ??? tooltip_text */ | |
| 9475 | 1827 zephyr_away_states, /* away_states */ |
| 9478 | 1828 NULL, /* ??? blist_node_menu - probably all useful actions are already handled*/ |
| 9475 | 1829 zephyr_chat_info, /* chat_info */ |
| 1830 zephyr_login, /* login */ | |
| 1831 zephyr_close, /* close */ | |
| 1832 zephyr_send_im, /* send_im */ | |
| 9478 | 1833 NULL, /* XXX set info (Location?) */ |
| 1834 zephyr_send_typing, /* send_typing */ | |
| 9475 | 1835 zephyr_zloc, /* get_info */ |
| 9478 | 1836 zephyr_set_away, /* XXX set_away need to fix */ |
| 1837 NULL, /* ??? set idle */ | |
| 1838 NULL, /* change password */ | |
| 9475 | 1839 NULL, /* add_buddy */ |
| 1840 NULL, /* add_buddies */ | |
| 1841 NULL, /* remove_buddy */ | |
| 1842 NULL, /* remove_buddies */ | |
| 9478 | 1843 NULL, /* add_permit -- not useful, since anyone can zephyr you by default*/ |
| 1844 NULL, /* XXX add deny -- maybe put an auto "I'm ignoring your zephyrs*/ | |
| 1845 NULL, /* remove_permit -- not useful, see add permit */ | |
| 1846 NULL, /* XXX remove deny -- remove above deny, */ | |
| 1847 NULL, /* ??? set permit deny */ | |
| 1848 NULL, /* --- warn */ | |
| 9475 | 1849 zephyr_join_chat, /* join_chat */ |
| 1850 NULL, /* reject_chat */ | |
| 1851 NULL, /* chat_invite */ | |
| 1852 zephyr_chat_leave, /* chat_leave */ | |
| 1853 NULL, /* chat_whisper */ | |
| 1854 zephyr_chat_send, /* chat_send */ | |
| 1855 NULL, /* keepalive */ | |
| 1856 NULL, /* register_user */ | |
| 9478 | 1857 NULL, /* XXX get_cb_info get chat buddy info */ |
| 9475 | 1858 NULL, /* get_cb_away */ |
| 1859 NULL, /* alias_buddy */ | |
| 1860 NULL, /* group_buddy */ | |
| 1861 NULL, /* rename_group */ | |
| 9478 | 1862 NULL, /* ??? buddy_free */ |
| 9475 | 1863 NULL, /* convo_closed */ |
| 1864 zephyr_normalize, /* normalize */ | |
| 9478 | 1865 NULL, /* XXX set_buddy_icon */ |
| 9475 | 1866 NULL, /* remove_group */ |
| 9478 | 1867 NULL, /* XXX get_cb_real_name */ |
| 9475 | 1868 zephyr_chat_set_topic, /* set_chat_topic */ |
| 9478 | 1869 zephyr_find_blist_chat, /* find_blist_chat */ |
| 9475 | 1870 NULL, /* roomlist_get_list */ |
| 1871 NULL, /* roomlist_cancel */ | |
| 9478 | 1872 NULL, /* roomlist_expand_category */ |
| 9475 | 1873 NULL, /* can_receive_file */ |
| 1874 NULL /* send_file */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1875 }; |
| 2086 | 1876 |
| 8644 | 1877 static GaimPluginInfo info = { |
|
8749
d7b8eb1f0a18
[gaim-migrate @ 9504]
Christian Hammond <chipx86@chipx86.com>
parents:
8713
diff
changeset
|
1878 GAIM_PLUGIN_API_VERSION, /**< api_version */ |
| 8644 | 1879 GAIM_PLUGIN_PROTOCOL, /**< type */ |
| 1880 NULL, /**< ui_requirement */ | |
| 1881 0, /**< flags */ | |
| 1882 NULL, /**< dependencies */ | |
| 1883 GAIM_PRIORITY_DEFAULT, /**< priority */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1884 |
| 8644 | 1885 "prpl-zephyr", /**< id */ |
| 1886 "Zephyr", /**< name */ | |
| 1887 VERSION, /**< version */ | |
| 1888 /** summary */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1889 N_("Zephyr Protocol Plugin"), |
| 8644 | 1890 /** description */ |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1891 N_("Zephyr Protocol Plugin"), |
| 8644 | 1892 NULL, /**< author */ |
| 1893 GAIM_WEBSITE, /**< homepage */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1894 |
| 8644 | 1895 NULL, /**< load */ |
| 1896 NULL, /**< unload */ | |
| 1897 NULL, /**< destroy */ | |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1898 |
| 8644 | 1899 NULL, /**< ui_info */ |
| 8993 | 1900 &prpl_info, /**< extra_info */ |
| 1901 NULL, | |
| 9427 | 1902 zephyr_actions |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1903 }; |
|
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1904 |
| 8644 | 1905 static void init_plugin(GaimPlugin * plugin) |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1906 { |
| 8212 | 1907 GaimAccountOption *option; |
| 8644 | 1908 char *tmp = get_exposure_level(); |
| 1909 | |
| 1910 option = gaim_account_option_bool_new(_("Export to .anyone"), "write_anyone", FALSE); | |
| 1911 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 8212 | 1912 |
| 8644 | 1913 option = gaim_account_option_bool_new(_("Export to .zephyr.subs"), "write_zsubs", FALSE); |
| 1914 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 8212 | 1915 |
| 8644 | 1916 option = gaim_account_option_string_new(_("Exposure"), "exposure_level", tmp ? tmp : EXPOSE_REALMVIS); |
| 1917 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 8212 | 1918 |
| 8644 | 1919 option = gaim_account_option_string_new(_("Encoding"), "encoding", ZEPHYR_FALLBACK_CHARSET); |
| 1920 prpl_info.protocol_options = g_list_append(prpl_info.protocol_options, option); | |
| 8560 | 1921 |
|
5205
fefad67de2c7
[gaim-migrate @ 5573]
Christian Hammond <chipx86@chipx86.com>
parents:
5202
diff
changeset
|
1922 my_protocol = plugin; |
| 9434 | 1923 zephyr_register_slash_commands(); |
| 2086 | 1924 } |
| 1925 | |
|
5920
7d385de2f9cd
[gaim-migrate @ 6360]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
1926 GAIM_INIT_PLUGIN(zephyr, init_plugin, info); |
