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