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