Mercurial > pidgin.yaz
annotate src/protocols/yahoo/yay.c @ 2234:2abf9cc183a0
[gaim-migrate @ 2244]
don't need these anymore
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Fri, 07 Sep 2001 09:02:57 +0000 |
parents | 8c4ff1a368bd |
children | f5bf315e6104 |
rev | line source |
---|---|
2086 | 1 /* |
2 * gaim | |
3 * | |
4 * Some code copyright (C) 1998-1999, Mark Spencer <markster@marko.net> | |
5 * libfaim code copyright 1998, 1999 Adam Fritzler <afritz@auk.cx> | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 * | |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include "config.h" | |
25 #endif | |
26 | |
27 | |
28 #include <netdb.h> | |
29 #include <unistd.h> | |
30 #include <errno.h> | |
31 #include <netinet/in.h> | |
32 #include <arpa/inet.h> | |
33 #include <string.h> | |
34 #include <stdlib.h> | |
35 #include <stdio.h> | |
36 #include <time.h> | |
37 #include <sys/socket.h> | |
38 #include <sys/stat.h> | |
39 #include "multi.h" | |
40 #include "prpl.h" | |
41 #include "gaim.h" | |
42 #include "yay.h" | |
43 #include "proxy.h" | |
44 | |
45 #include "pixmaps/status-away.xpm" | |
46 #include "pixmaps/status-here.xpm" | |
47 #include "pixmaps/status-idle.xpm" | |
48 | |
49 #define USEROPT_MAIL 0 | |
50 | |
51 #define USEROPT_AUTHHOST 1 | |
52 #define USEROPT_AUTHPORT 2 | |
53 #define USEROPT_PAGERHOST 3 | |
54 #define USEROPT_PAGERPORT 4 | |
55 | |
56 struct conn { | |
57 int socket; | |
58 int type; | |
59 int inpa; | |
60 }; | |
61 | |
62 struct connect { | |
63 struct yahoo_session *sess; | |
64 gpointer data; | |
65 }; | |
66 | |
67 struct yahoo_data { | |
68 struct yahoo_session *sess; | |
69 int current_status; | |
70 GHashTable *hash; | |
71 char *active_id; | |
72 GList *conns; | |
73 gboolean logged_in; | |
74 }; | |
75 | |
76 static char *yahoo_name() { | |
77 return "Yahoo"; | |
78 } | |
79 | |
80 static int yahoo_status(struct yahoo_session *sess, ...) { | |
81 struct gaim_connection *gc = sess->user_data; | |
82 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
83 time_t tmptime; | |
84 struct buddy *b; | |
85 gboolean online; | |
86 | |
87 va_list ap; | |
88 char *who; | |
89 int status; | |
90 char *msg; | |
91 int in_pager, in_chat, in_game; | |
92 | |
93 va_start(ap, sess); | |
94 who = va_arg(ap, char *); | |
95 status = va_arg(ap, int); | |
96 msg = va_arg(ap, char *); | |
97 in_pager = va_arg(ap, int); | |
98 in_chat = va_arg(ap, int); | |
99 in_game = va_arg(ap, int); | |
100 va_end(ap); | |
101 | |
102 online = in_pager || in_chat || in_game; | |
103 | |
104 b = find_buddy(gc, who); | |
105 if (!b) return 0; | |
106 if (!online) | |
107 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); | |
108 else { | |
109 if (status == YAHOO_STATUS_AVAILABLE) | |
110 serv_got_update(gc, b->name, 1, 0, 0, 0, UC_NORMAL, 0); | |
111 else if (status == YAHOO_STATUS_IDLE) { | |
112 time(&tmptime); | |
113 serv_got_update(gc, b->name, 1, 0, 0, tmptime - 600, | |
114 (status << 5) | UC_NORMAL, 0); | |
115 } else | |
116 serv_got_update(gc, b->name, 1, 0, 0, 0, | |
117 (status << 5) | UC_UNAVAILABLE, 0); | |
118 if (status == YAHOO_STATUS_CUSTOM) { | |
119 gpointer val = g_hash_table_lookup(yd->hash, b->name); | |
120 if (val) | |
121 g_free(val); | |
122 g_hash_table_insert(yd->hash, g_strdup(b->name), g_strdup(msg)); | |
123 } | |
124 } | |
125 | |
126 return 1; | |
127 } | |
128 | |
129 static int yahoo_message(struct yahoo_session *sess, ...) { | |
130 struct gaim_connection *gc = sess->user_data; | |
131 char buf[BUF_LEN * 4]; | |
132 char *tmp, *c, *e; | |
133 time_t tm; | |
134 int at = 0; | |
135 | |
136 va_list ap; | |
137 char *id, *nick, *msg; | |
138 | |
139 va_start(ap, sess); | |
140 id = va_arg(ap, char *); | |
141 nick = va_arg(ap, char *); | |
142 tm = va_arg(ap, time_t); | |
143 msg = va_arg(ap, char *); | |
144 va_end(ap); | |
145 | |
146 if (msg) | |
147 e = tmp = g_strdup(msg); | |
148 else | |
149 return 1; | |
150 | |
151 while ((c = strchr(e, '\033')) != NULL) { | |
152 *c++ = '\0'; | |
153 at += g_snprintf(buf + at, sizeof(buf) - at, "%s", e); | |
154 e = ++c; | |
155 while (*e && (*e++ != 'm')); | |
156 } | |
157 | |
158 if (*e) | |
159 g_snprintf(buf + at, sizeof(buf) - at, "%s", e); | |
160 | |
161 g_free(tmp); | |
162 | |
163 serv_got_im(gc, nick, buf, 0, tm ? tm : time((time_t)NULL)); | |
164 | |
165 return 1; | |
166 } | |
167 | |
168 static int yahoo_bounce(struct yahoo_session *sess, ...) { | |
169 do_error_dialog(_("Your message did not get sent."), _("Gaim - Error")); | |
170 | |
171 return 1; | |
172 } | |
173 | |
174 static int yahoo_buddyadded(struct yahoo_session *sess, ...) { | |
175 va_list ap; | |
176 char *id; | |
177 char *who; | |
178 char *msg; | |
179 char buf[2048]; | |
180 | |
181 va_start(ap, sess); | |
182 id = va_arg(ap, char *); | |
183 who = va_arg(ap, char *); | |
184 msg = va_arg(ap, char *); | |
185 va_end(ap); | |
186 | |
187 g_snprintf(buf, sizeof(buf), _("%s has made %s their buddy%s%s"), who, id, | |
188 msg ? ": " : "", msg ? msg : ""); | |
189 do_error_dialog(buf, _("Gaim - Buddy")); | |
190 | |
191 return 1; | |
192 } | |
193 | |
194 static int yahoo_newmail(struct yahoo_session *sess, ...) { | |
195 struct gaim_connection *gc = sess->user_data; | |
196 | |
197 va_list ap; | |
198 int count; | |
199 | |
200 va_start(ap, sess); | |
201 count = va_arg(ap, int); | |
202 va_end(ap); | |
203 | |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2145
diff
changeset
|
204 connection_has_mail(gc, count, NULL, NULL); |
2086 | 205 |
206 return 1; | |
207 } | |
208 | |
209 static int yahoo_disconn(struct yahoo_session *sess, ...) { | |
210 struct gaim_connection *gc = sess->user_data; | |
211 hide_login_progress(gc, "Disconnected"); | |
212 signoff(gc); | |
213 return 1; | |
214 } | |
215 | |
216 static int yahoo_authconnect(struct yahoo_session *sess, ...) { | |
217 struct gaim_connection *gc = sess->user_data; | |
218 | |
219 set_login_progress(gc, 2, "Connected to Auth"); | |
220 if (yahoo_send_login(sess, gc->username, gc->password) < 1) { | |
221 hide_login_progress(gc, "Authorizer error"); | |
222 signoff(gc); | |
2145
91223be78b70
[gaim-migrate @ 2155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
223 return 0; |
2086 | 224 } |
225 | |
226 return 1; | |
227 } | |
228 | |
229 static int yahoo_badpassword(struct yahoo_session *sess, ...) { | |
230 struct gaim_connection *gc = sess->user_data; | |
231 hide_login_progress(gc, "Bad Password"); | |
232 signoff(gc); | |
233 return 1; | |
234 } | |
235 | |
236 static int yahoo_logincookie(struct yahoo_session *sess, ...) { | |
237 struct gaim_connection *gc = sess->user_data; | |
238 | |
239 set_login_progress(gc, 3, "Got login cookie"); | |
240 if (yahoo_major_connect(sess, gc->user->proto_opt[USEROPT_PAGERHOST], | |
241 atoi(gc->user->proto_opt[USEROPT_PAGERPORT])) < 1) { | |
242 hide_login_progress(gc, "Login error"); | |
243 signoff(gc); | |
244 } | |
245 | |
246 return 1; | |
247 } | |
248 | |
249 static int yahoo_mainconnect(struct yahoo_session *sess, ...) { | |
250 struct gaim_connection *gc = sess->user_data; | |
251 struct yahoo_data *yd = gc->proto_data; | |
252 GList *grps; | |
253 | |
254 set_login_progress(gc, 4, "Connected to service"); | |
255 if (yahoo_finish_logon(sess, YAHOO_STATUS_AVAILABLE) < 1) { | |
256 hide_login_progress(gc, "Login error"); | |
257 signoff(gc); | |
2145
91223be78b70
[gaim-migrate @ 2155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
258 return 0; |
2086 | 259 } |
260 | |
261 if (bud_list_cache_exists(gc)) | |
262 do_import(NULL, gc); | |
263 | |
264 grps = yd->sess->groups; | |
265 while (grps) { | |
266 struct yahoo_group *grp = grps->data; | |
267 int i; | |
268 | |
269 for (i = 0; grp->buddies[i]; i++) | |
270 add_buddy(gc, grp->name, grp->buddies[i], NULL); | |
271 | |
272 grps = grps->next; | |
273 } | |
274 | |
275 return 1; | |
276 } | |
277 | |
278 static int yahoo_online(struct yahoo_session *sess, ...) { | |
279 struct gaim_connection *gc = sess->user_data; | |
280 struct yahoo_data *yd = gc->proto_data; | |
281 | |
282 account_online(gc); | |
283 serv_finish_login(gc); | |
284 yd->active_id = g_strdup(gc->username); | |
285 yd->logged_in = TRUE; | |
286 | |
287 return 1; | |
288 } | |
289 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
290 static void yahoo_pending(gpointer data, gint source, GaimInputCondition condition) { |
2086 | 291 struct gaim_connection *gc = (struct gaim_connection *)data; |
292 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
293 | |
294 yahoo_socket_handler(yd->sess, source, condition); | |
295 } | |
296 | |
297 static void yahoo_notify(struct yahoo_session *sess, int socket, int type, int cont) { | |
298 struct gaim_connection *gc = sess->user_data; | |
299 struct yahoo_data *yd = gc->proto_data; | |
300 | |
301 if (cont) { | |
302 struct conn *c = g_new0(struct conn, 1); | |
303 c->socket = socket; | |
304 c->type = type; | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
305 c->inpa = gaim_input_add(socket, type, yahoo_pending, gc); |
2086 | 306 yd->conns = g_list_append(yd->conns, c); |
307 } else { | |
308 GList *c = yd->conns; | |
309 while (c) { | |
310 struct conn *m = c->data; | |
311 if ((m->socket == socket) && (m->type == type)) { | |
312 yd->conns = g_list_remove(yd->conns, m); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
313 gaim_input_remove(m->inpa); |
2086 | 314 g_free(m); |
315 return; | |
316 } | |
317 c = g_list_next(c); | |
318 } | |
319 } | |
320 } | |
321 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
322 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) { |
2086 | 323 struct connect *con = data; |
324 | |
325 debug_printf("got connected (possibly)\n"); | |
326 yahoo_connected(con->sess, con->data, source); | |
327 | |
328 g_free(con); | |
329 } | |
330 | |
331 static int yahoo_connect_to(struct yahoo_session *sess, const char *host, int port, gpointer data) { | |
332 struct connect *con = g_new0(struct connect, 1); | |
333 int fd; | |
334 | |
335 con->sess = sess; | |
336 con->data = data; | |
337 fd = proxy_connect((char *)host, port, yahoo_got_connected, con); | |
338 if (fd < 0) { | |
339 g_free(con); | |
340 return -1; | |
341 } | |
342 | |
343 return fd; | |
344 } | |
345 | |
346 static void yahoo_debug(struct yahoo_session *sess, int level, const char *string) { | |
347 debug_printf("Level %d: %s\n", level, string); | |
348 } | |
349 | |
350 static void yahoo_login(struct aim_user *user) { | |
351 struct gaim_connection *gc = new_gaim_conn(user); | |
352 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); | |
353 | |
354 yd->sess = yahoo_new(); | |
355 yd->sess->user_data = gc; | |
356 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
357 yd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
358 | |
359 set_login_progress(gc, 1, "Connecting"); | |
360 | |
361 if (!yahoo_connect(yd->sess, user->proto_opt[USEROPT_AUTHHOST], | |
362 atoi(user->proto_opt[USEROPT_AUTHPORT]))) { | |
363 hide_login_progress(gc, "Connection problem"); | |
364 signoff(gc); | |
365 return; | |
366 } | |
367 | |
368 yahoo_add_handler(yd->sess, YAHOO_HANDLE_DISCONNECT, yahoo_disconn); | |
369 yahoo_add_handler(yd->sess, YAHOO_HANDLE_AUTHCONNECT, yahoo_authconnect); | |
370 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BADPASSWORD, yahoo_badpassword); | |
371 yahoo_add_handler(yd->sess, YAHOO_HANDLE_LOGINCOOKIE, yahoo_logincookie); | |
372 yahoo_add_handler(yd->sess, YAHOO_HANDLE_MAINCONNECT, yahoo_mainconnect); | |
373 yahoo_add_handler(yd->sess, YAHOO_HANDLE_ONLINE, yahoo_online); | |
374 yahoo_add_handler(yd->sess, YAHOO_HANDLE_NEWMAIL, yahoo_newmail); | |
375 yahoo_add_handler(yd->sess, YAHOO_HANDLE_MESSAGE, yahoo_message); | |
376 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BOUNCE, yahoo_bounce); | |
377 yahoo_add_handler(yd->sess, YAHOO_HANDLE_STATUS, yahoo_status); | |
378 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BUDDYADDED, yahoo_buddyadded); | |
379 } | |
380 | |
381 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
382 g_free(key); | |
383 g_free(val); | |
384 return TRUE; | |
385 } | |
386 | |
387 static void yahoo_close(struct gaim_connection *gc) { | |
388 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
389 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL); | |
390 g_hash_table_destroy(yd->hash); | |
391 yahoo_disconnect(yd->sess); | |
392 yahoo_delete(yd->sess); | |
393 g_free(yd); | |
394 } | |
395 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
396 static int yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int flags) { |
2086 | 397 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
398 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
399 if ((flags & IM_FLAG_AWAY)|| !strlen(message)) return 0; |
2086 | 400 |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
401 if (flags & IM_FLAG_CHECKBOX) |
2086 | 402 yahoo_send_message(yd->sess, yd->active_id, who, message); |
403 else | |
404 yahoo_send_message_offline(yd->sess, yd->active_id, who, message); | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
405 return 0; |
2086 | 406 } |
407 | |
408 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
409 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
410 | |
411 gc->away = NULL; | |
412 | |
413 if (msg) { | |
414 yahoo_away(yd->sess, YAHOO_STATUS_CUSTOM, msg); | |
415 yd->current_status = YAHOO_STATUS_CUSTOM; | |
416 gc->away = ""; | |
417 } else if (state) { | |
418 gc->away = ""; | |
419 if (!strcmp(state, "Available")) { | |
420 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, msg); | |
421 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
422 } else if (!strcmp(state, "Be Right Back")) { | |
423 yahoo_away(yd->sess, YAHOO_STATUS_BRB, msg); | |
424 yd->current_status = YAHOO_STATUS_BRB; | |
425 } else if (!strcmp(state, "Busy")) { | |
426 yahoo_away(yd->sess, YAHOO_STATUS_BUSY, msg); | |
427 yd->current_status = YAHOO_STATUS_BUSY; | |
428 } else if (!strcmp(state, "Not At Home")) { | |
429 yahoo_away(yd->sess, YAHOO_STATUS_NOTATHOME, msg); | |
430 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
431 } else if (!strcmp(state, "Not At Desk")) { | |
432 yahoo_away(yd->sess, YAHOO_STATUS_NOTATDESK, msg); | |
433 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
434 } else if (!strcmp(state, "Not In Office")) { | |
435 yahoo_away(yd->sess, YAHOO_STATUS_NOTINOFFICE, msg); | |
436 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
437 } else if (!strcmp(state, "On Phone")) { | |
438 yahoo_away(yd->sess, YAHOO_STATUS_ONPHONE, msg); | |
439 yd->current_status = YAHOO_STATUS_ONPHONE; | |
440 } else if (!strcmp(state, "On Vacation")) { | |
441 yahoo_away(yd->sess, YAHOO_STATUS_ONVACATION, msg); | |
442 yd->current_status = YAHOO_STATUS_ONVACATION; | |
443 } else if (!strcmp(state, "Out To Lunch")) { | |
444 yahoo_away(yd->sess, YAHOO_STATUS_OUTTOLUNCH, msg); | |
445 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
446 } else if (!strcmp(state, "Stepped Out")) { | |
447 yahoo_away(yd->sess, YAHOO_STATUS_STEPPEDOUT, msg); | |
448 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
449 } else if (!strcmp(state, "Invisible")) { | |
450 yahoo_away(yd->sess, YAHOO_STATUS_INVISIBLE, msg); | |
451 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
452 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
453 if (gc->is_idle) { | |
454 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
455 yd->current_status = YAHOO_STATUS_IDLE; | |
456 } else { | |
457 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
458 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
459 } | |
460 gc->away = NULL; | |
461 } | |
462 } else if (gc->is_idle) { | |
463 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
464 yd->current_status = YAHOO_STATUS_IDLE; | |
465 } else { | |
466 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
467 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
468 } | |
469 } | |
470 | |
471 static void yahoo_set_idle(struct gaim_connection *gc, int idle) { | |
472 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
473 | |
474 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
475 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
476 yd->current_status = YAHOO_STATUS_IDLE; | |
477 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
478 yahoo_back(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
479 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
480 } | |
481 } | |
482 | |
483 static void yahoo_keepalive(struct gaim_connection *gc) { | |
484 yahoo_ping(((struct yahoo_data *)gc->proto_data)->sess); | |
485 } | |
486 | |
487 static void gyahoo_add_buddy(struct gaim_connection *gc, char *name) { | |
488 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
489 struct yahoo_group *tmpgroup; | |
490 struct group *g = find_group_by_buddy(gc, name); | |
491 char *group = NULL; | |
492 | |
493 if (!yd->logged_in) | |
494 return; | |
495 | |
496 if (g) { | |
497 group = g->name; | |
498 } else if (yd->sess && yd->sess->groups) { | |
499 tmpgroup = yd->sess->groups->data; | |
500 group = tmpgroup->name; | |
501 } else { | |
502 group = "Buddies"; | |
503 } | |
504 | |
505 if (group) | |
506 yahoo_add_buddy(yd->sess, yd->active_id, group, name, ""); | |
507 } | |
508 | |
509 static void yahoo_add_buddies(struct gaim_connection *gc, GList *buddies) { | |
510 while (buddies) { | |
511 gyahoo_add_buddy(gc, buddies->data); | |
512 buddies = buddies->next; | |
513 } | |
514 } | |
515 | |
516 static void gyahoo_remove_buddy(struct gaim_connection *gc, char *name) { | |
517 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
518 struct group *g = find_group_by_buddy(gc, name); | |
519 char *group = NULL; | |
520 | |
521 if (g) { | |
522 group = g->name; | |
523 } else if (yd->sess && yd->sess->groups) { | |
524 GList *x = yd->sess->groups; | |
525 while (x) { | |
526 struct yahoo_group *tmpgroup = x->data; | |
527 char **bds = tmpgroup->buddies; | |
528 while (*bds) { | |
529 if (!strcmp(*bds, name)) | |
530 break; | |
531 bds++; | |
532 } | |
533 if (*bds) { | |
534 group = tmpgroup->name; | |
535 break; | |
536 } | |
537 x = x->next; | |
538 } | |
539 } else { | |
540 group = "Buddies"; | |
541 } | |
542 | |
543 if (group) | |
544 yahoo_remove_buddy(yd->sess, yd->active_id, group, name, ""); | |
545 } | |
546 | |
547 static char **yahoo_list_icon(int uc) { | |
548 if ((uc >> 5) == YAHOO_STATUS_IDLE) | |
549 return status_idle_xpm; | |
550 else if (uc == UC_NORMAL) | |
551 return status_here_xpm; | |
552 return status_away_xpm; | |
553 } | |
554 | |
555 static char *yahoo_get_status_string(enum yahoo_status a) { | |
556 switch (a) { | |
557 case YAHOO_STATUS_BRB: | |
558 return "Be Right Back"; | |
559 case YAHOO_STATUS_BUSY: | |
560 return "Busy"; | |
561 case YAHOO_STATUS_NOTATHOME: | |
562 return "Not At Home"; | |
563 case YAHOO_STATUS_NOTATDESK: | |
564 return "Not At Desk"; | |
565 case YAHOO_STATUS_NOTINOFFICE: | |
566 return "Not In Office"; | |
567 case YAHOO_STATUS_ONPHONE: | |
568 return "On Phone"; | |
569 case YAHOO_STATUS_ONVACATION: | |
570 return "On Vacation"; | |
571 case YAHOO_STATUS_OUTTOLUNCH: | |
572 return "Out To Lunch"; | |
573 case YAHOO_STATUS_STEPPEDOUT: | |
574 return "Stepped Out"; | |
575 default: | |
576 return NULL; | |
577 } | |
578 } | |
579 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
580 static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
581 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
582 struct proto_buddy_menu *pbm; |
2086 | 583 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
584 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
585 segfault and get the bug report. */ | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
586 static char buf[1024]; |
2086 | 587 |
588 if (b->uc & UC_NORMAL) | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
589 return NULL; |
2086 | 590 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
591 pbm = g_new0(struct proto_buddy_menu, 1); |
2086 | 592 if ((b->uc >> 5) != YAHOO_STATUS_CUSTOM) |
593 g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 5)); | |
594 else | |
595 g_snprintf(buf, sizeof buf, "Custom Status: %s", | |
596 (char *)g_hash_table_lookup(yd->hash, b->name)); | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
597 pbm->label = buf; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
598 pbm->callback = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
599 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
600 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
601 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
602 return m; |
2086 | 603 } |
604 | |
605 static GList *yahoo_away_states() { | |
606 GList *m = NULL; | |
607 | |
608 m = g_list_append(m, "Available"); | |
609 m = g_list_append(m, "Be Right Back"); | |
610 m = g_list_append(m, "Busy"); | |
611 m = g_list_append(m, "Not At Home"); | |
612 m = g_list_append(m, "Not At Desk"); | |
613 m = g_list_append(m, "Not In Office"); | |
614 m = g_list_append(m, "On Phone"); | |
615 m = g_list_append(m, "On Vacation"); | |
616 m = g_list_append(m, "Out To Lunch"); | |
617 m = g_list_append(m, "Stepped Out"); | |
618 m = g_list_append(m, "Invisible"); | |
619 m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
620 | |
621 return m; | |
622 } | |
623 | |
624 static void yahoo_act_id(gpointer data, char *entry) { | |
625 struct gaim_connection *gc = data; | |
626 struct yahoo_data *yd = gc->proto_data; | |
627 | |
628 yahoo_activate_id(yd->sess, entry); | |
629 if (yd->active_id) | |
630 g_free(yd->active_id); | |
631 yd->active_id = g_strdup(entry); | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
632 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", yd->active_id); |
2086 | 633 } |
634 | |
635 static void yahoo_do_action(struct gaim_connection *gc, char *act) { | |
636 if (!strcmp(act, "Activate ID")) { | |
637 do_prompt_dialog("Activate which ID:", gc, yahoo_act_id, NULL); | |
638 } | |
639 } | |
640 | |
641 static GList *yahoo_actions() { | |
642 GList *m = NULL; | |
643 | |
644 m = g_list_append(m, "Activate ID"); | |
645 | |
646 return m; | |
647 } | |
648 | |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
649 static GList *yahoo_user_opts() |
2086 | 650 { |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
651 GList *m = NULL; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
652 struct proto_user_opt *puo; |
2086 | 653 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
654 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
655 puo->label = "Auth Host:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
656 puo->def = YAHOO_AUTH_HOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
657 puo->pos = USEROPT_AUTHHOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
658 m = g_list_append(m, puo); |
2086 | 659 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
660 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
661 puo->label = "Auth Port:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
662 puo->def = "80"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
663 puo->pos = USEROPT_AUTHPORT; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
664 m = g_list_append(m, puo); |
2086 | 665 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
666 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
667 puo->label = "Pager Host:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
668 puo->def = YAHOO_PAGER_HOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
669 puo->pos = USEROPT_PAGERHOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
670 m = g_list_append(m, puo); |
2086 | 671 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
672 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
673 puo->label = "Pager Port:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
674 puo->def = "5050"; |
2201
bc53b057732f
[gaim-migrate @ 2211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
675 puo->pos = USEROPT_PAGERPORT; |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
676 m = g_list_append(m, puo); |
2086 | 677 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
678 return m; |
2086 | 679 } |
680 | |
681 static struct prpl *my_protocol = NULL; | |
682 | |
683 void yahoo_init(struct prpl *ret) { | |
684 /* the NULL's aren't required but they're nice to have */ | |
685 ret->protocol = PROTO_YAHOO; | |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2145
diff
changeset
|
686 ret->options = OPT_PROTO_MAIL_CHECK; |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
687 ret->checkbox = _("Send offline message"); |
2086 | 688 ret->name = yahoo_name; |
689 ret->list_icon = yahoo_list_icon; | |
690 ret->away_states = yahoo_away_states; | |
691 ret->actions = yahoo_actions; | |
692 ret->do_action = yahoo_do_action; | |
693 ret->buddy_menu = yahoo_buddy_menu; | |
694 ret->user_opts = yahoo_user_opts; | |
695 ret->login = yahoo_login; | |
696 ret->close = yahoo_close; | |
697 ret->send_im = yahoo_send_im; | |
698 ret->set_info = NULL; | |
699 ret->get_info = NULL; | |
700 ret->set_away = yahoo_set_away; | |
701 ret->get_away_msg = NULL; | |
702 ret->set_dir = NULL; | |
703 ret->get_dir = NULL; | |
704 ret->dir_search = NULL; | |
705 ret->set_idle = yahoo_set_idle; | |
706 ret->change_passwd = NULL; | |
707 ret->add_buddy = gyahoo_add_buddy; | |
708 ret->add_buddies = yahoo_add_buddies; | |
709 ret->remove_buddy = gyahoo_remove_buddy; | |
710 ret->add_permit = NULL; | |
711 ret->add_deny = NULL; | |
712 ret->rem_permit = NULL; | |
713 ret->rem_deny = NULL; | |
714 ret->set_permit_deny = NULL; | |
715 ret->warn = NULL; | |
716 ret->keepalive = yahoo_keepalive; | |
717 | |
718 my_protocol = ret; | |
719 | |
720 yahoo_socket_notify = yahoo_notify; | |
721 yahoo_print = yahoo_debug; | |
722 yahoo_connector = yahoo_connect_to; | |
723 } | |
724 | |
725 #ifndef STATIC | |
726 | |
727 char *gaim_plugin_init(GModule *handle) | |
728 { | |
729 load_protocol(yahoo_init, sizeof(struct prpl)); | |
730 return NULL; | |
731 } | |
732 | |
733 void gaim_plugin_remove() | |
734 { | |
735 struct prpl *p = find_prpl(PROTO_YAHOO); | |
736 if (p == my_protocol) | |
737 unload_protocol(p); | |
738 } | |
739 | |
740 char *name() | |
741 { | |
742 return "Yahoo"; | |
743 } | |
744 | |
745 char *description() | |
746 { | |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2154
diff
changeset
|
747 return PRPL_DESC("Yahoo"); |
2086 | 748 } |
749 | |
750 #endif |