Mercurial > pidgin.yaz
annotate src/protocols/yahoo/yay.c @ 2153:0befa2d2e540
[gaim-migrate @ 2163]
moving mail notifications to the core. this makes things much easier on the protocols. next steps: make buddy right-click menu stuff generated by the core (based on information provided by the protocols, similar to the away menu stuff); make entry-widget protocol-specific user options generated by the core based on what the protocols tell it (in a similar way).
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 22 Aug 2001 21:11:58 +0000 |
parents | 91223be78b70 |
children | cff133e0ec0c |
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 <gtk/gtk.h> | |
30 #include <unistd.h> | |
31 #include <errno.h> | |
32 #include <netinet/in.h> | |
33 #include <arpa/inet.h> | |
34 #include <string.h> | |
35 #include <stdlib.h> | |
36 #include <stdio.h> | |
37 #include <time.h> | |
38 #include <sys/socket.h> | |
39 #include <sys/stat.h> | |
40 #include "multi.h" | |
41 #include "prpl.h" | |
42 #include "gaim.h" | |
43 #include "yay.h" | |
44 #include "proxy.h" | |
45 | |
46 #include "pixmaps/status-away.xpm" | |
47 #include "pixmaps/status-here.xpm" | |
48 #include "pixmaps/status-idle.xpm" | |
49 | |
50 #include "pixmaps/cancel.xpm" | |
51 | |
52 #define USEROPT_MAIL 0 | |
53 | |
54 #define USEROPT_AUTHHOST 1 | |
55 #define USEROPT_AUTHPORT 2 | |
56 #define USEROPT_PAGERHOST 3 | |
57 #define USEROPT_PAGERPORT 4 | |
58 | |
59 struct conn { | |
60 int socket; | |
61 int type; | |
62 int inpa; | |
63 }; | |
64 | |
65 struct connect { | |
66 struct yahoo_session *sess; | |
67 gpointer data; | |
68 }; | |
69 | |
70 struct yahoo_data { | |
71 struct yahoo_session *sess; | |
72 int current_status; | |
73 GHashTable *hash; | |
74 GtkWidget *email_win; | |
75 GtkWidget *email_label; | |
76 char *active_id; | |
77 GList *conns; | |
78 gboolean logged_in; | |
79 GSList *offline; | |
80 }; | |
81 | |
82 static char *yahoo_name() { | |
83 return "Yahoo"; | |
84 } | |
85 | |
86 static int yahoo_status(struct yahoo_session *sess, ...) { | |
87 struct gaim_connection *gc = sess->user_data; | |
88 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
89 time_t tmptime; | |
90 struct buddy *b; | |
91 gboolean online; | |
92 | |
93 va_list ap; | |
94 char *who; | |
95 int status; | |
96 char *msg; | |
97 int in_pager, in_chat, in_game; | |
98 | |
99 va_start(ap, sess); | |
100 who = va_arg(ap, char *); | |
101 status = va_arg(ap, int); | |
102 msg = va_arg(ap, char *); | |
103 in_pager = va_arg(ap, int); | |
104 in_chat = va_arg(ap, int); | |
105 in_game = va_arg(ap, int); | |
106 va_end(ap); | |
107 | |
108 online = in_pager || in_chat || in_game; | |
109 | |
110 b = find_buddy(gc, who); | |
111 if (!b) return 0; | |
112 if (!online) | |
113 serv_got_update(gc, b->name, 0, 0, 0, 0, 0, 0); | |
114 else { | |
115 if (status == YAHOO_STATUS_AVAILABLE) | |
116 serv_got_update(gc, b->name, 1, 0, 0, 0, UC_NORMAL, 0); | |
117 else if (status == YAHOO_STATUS_IDLE) { | |
118 time(&tmptime); | |
119 serv_got_update(gc, b->name, 1, 0, 0, tmptime - 600, | |
120 (status << 5) | UC_NORMAL, 0); | |
121 } else | |
122 serv_got_update(gc, b->name, 1, 0, 0, 0, | |
123 (status << 5) | UC_UNAVAILABLE, 0); | |
124 if (status == YAHOO_STATUS_CUSTOM) { | |
125 gpointer val = g_hash_table_lookup(yd->hash, b->name); | |
126 if (val) | |
127 g_free(val); | |
128 g_hash_table_insert(yd->hash, g_strdup(b->name), g_strdup(msg)); | |
129 } | |
130 } | |
131 | |
132 return 1; | |
133 } | |
134 | |
135 static int yahoo_message(struct yahoo_session *sess, ...) { | |
136 struct gaim_connection *gc = sess->user_data; | |
137 char buf[BUF_LEN * 4]; | |
138 char *tmp, *c, *e; | |
139 time_t tm; | |
140 int at = 0; | |
141 | |
142 va_list ap; | |
143 char *id, *nick, *msg; | |
144 | |
145 va_start(ap, sess); | |
146 id = va_arg(ap, char *); | |
147 nick = va_arg(ap, char *); | |
148 tm = va_arg(ap, time_t); | |
149 msg = va_arg(ap, char *); | |
150 va_end(ap); | |
151 | |
152 if (msg) | |
153 e = tmp = g_strdup(msg); | |
154 else | |
155 return 1; | |
156 | |
157 while ((c = strchr(e, '\033')) != NULL) { | |
158 *c++ = '\0'; | |
159 at += g_snprintf(buf + at, sizeof(buf) - at, "%s", e); | |
160 e = ++c; | |
161 while (*e && (*e++ != 'm')); | |
162 } | |
163 | |
164 if (*e) | |
165 g_snprintf(buf + at, sizeof(buf) - at, "%s", e); | |
166 | |
167 g_free(tmp); | |
168 | |
169 serv_got_im(gc, nick, buf, 0, tm ? tm : time((time_t)NULL)); | |
170 | |
171 return 1; | |
172 } | |
173 | |
174 static int yahoo_bounce(struct yahoo_session *sess, ...) { | |
175 do_error_dialog(_("Your message did not get sent."), _("Gaim - Error")); | |
176 | |
177 return 1; | |
178 } | |
179 | |
180 static int yahoo_buddyadded(struct yahoo_session *sess, ...) { | |
181 va_list ap; | |
182 char *id; | |
183 char *who; | |
184 char *msg; | |
185 char buf[2048]; | |
186 | |
187 va_start(ap, sess); | |
188 id = va_arg(ap, char *); | |
189 who = va_arg(ap, char *); | |
190 msg = va_arg(ap, char *); | |
191 va_end(ap); | |
192 | |
193 g_snprintf(buf, sizeof(buf), _("%s has made %s their buddy%s%s"), who, id, | |
194 msg ? ": " : "", msg ? msg : ""); | |
195 do_error_dialog(buf, _("Gaim - Buddy")); | |
196 | |
197 return 1; | |
198 } | |
199 | |
200 static int yahoo_newmail(struct yahoo_session *sess, ...) { | |
201 struct gaim_connection *gc = sess->user_data; | |
202 | |
203 va_list ap; | |
204 int count; | |
205 | |
206 va_start(ap, sess); | |
207 count = va_arg(ap, int); | |
208 va_end(ap); | |
209 | |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2145
diff
changeset
|
210 connection_has_mail(gc, count, NULL, NULL); |
2086 | 211 |
212 return 1; | |
213 } | |
214 | |
215 static int yahoo_disconn(struct yahoo_session *sess, ...) { | |
216 struct gaim_connection *gc = sess->user_data; | |
217 hide_login_progress(gc, "Disconnected"); | |
218 signoff(gc); | |
219 return 1; | |
220 } | |
221 | |
222 static int yahoo_authconnect(struct yahoo_session *sess, ...) { | |
223 struct gaim_connection *gc = sess->user_data; | |
224 | |
225 set_login_progress(gc, 2, "Connected to Auth"); | |
226 if (yahoo_send_login(sess, gc->username, gc->password) < 1) { | |
227 hide_login_progress(gc, "Authorizer error"); | |
228 signoff(gc); | |
2145
91223be78b70
[gaim-migrate @ 2155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
229 return 0; |
2086 | 230 } |
231 | |
232 return 1; | |
233 } | |
234 | |
235 static int yahoo_badpassword(struct yahoo_session *sess, ...) { | |
236 struct gaim_connection *gc = sess->user_data; | |
237 hide_login_progress(gc, "Bad Password"); | |
238 signoff(gc); | |
239 return 1; | |
240 } | |
241 | |
242 static int yahoo_logincookie(struct yahoo_session *sess, ...) { | |
243 struct gaim_connection *gc = sess->user_data; | |
244 | |
245 set_login_progress(gc, 3, "Got login cookie"); | |
246 if (yahoo_major_connect(sess, gc->user->proto_opt[USEROPT_PAGERHOST], | |
247 atoi(gc->user->proto_opt[USEROPT_PAGERPORT])) < 1) { | |
248 hide_login_progress(gc, "Login error"); | |
249 signoff(gc); | |
250 } | |
251 | |
252 return 1; | |
253 } | |
254 | |
255 static int yahoo_mainconnect(struct yahoo_session *sess, ...) { | |
256 struct gaim_connection *gc = sess->user_data; | |
257 struct yahoo_data *yd = gc->proto_data; | |
258 GList *grps; | |
259 | |
260 set_login_progress(gc, 4, "Connected to service"); | |
261 if (yahoo_finish_logon(sess, YAHOO_STATUS_AVAILABLE) < 1) { | |
262 hide_login_progress(gc, "Login error"); | |
263 signoff(gc); | |
2145
91223be78b70
[gaim-migrate @ 2155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
264 return 0; |
2086 | 265 } |
266 | |
267 if (bud_list_cache_exists(gc)) | |
268 do_import(NULL, gc); | |
269 | |
270 grps = yd->sess->groups; | |
271 while (grps) { | |
272 struct yahoo_group *grp = grps->data; | |
273 int i; | |
274 | |
275 for (i = 0; grp->buddies[i]; i++) | |
276 add_buddy(gc, grp->name, grp->buddies[i], NULL); | |
277 | |
278 grps = grps->next; | |
279 } | |
280 | |
281 return 1; | |
282 } | |
283 | |
284 static int yahoo_online(struct yahoo_session *sess, ...) { | |
285 struct gaim_connection *gc = sess->user_data; | |
286 struct yahoo_data *yd = gc->proto_data; | |
287 | |
288 account_online(gc); | |
289 serv_finish_login(gc); | |
290 yd->active_id = g_strdup(gc->username); | |
291 yd->logged_in = TRUE; | |
292 | |
293 return 1; | |
294 } | |
295 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
296 static void yahoo_pending(gpointer data, gint source, GaimInputCondition condition) { |
2086 | 297 struct gaim_connection *gc = (struct gaim_connection *)data; |
298 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
299 | |
300 yahoo_socket_handler(yd->sess, source, condition); | |
301 } | |
302 | |
303 static void yahoo_notify(struct yahoo_session *sess, int socket, int type, int cont) { | |
304 struct gaim_connection *gc = sess->user_data; | |
305 struct yahoo_data *yd = gc->proto_data; | |
306 | |
307 if (cont) { | |
308 struct conn *c = g_new0(struct conn, 1); | |
309 c->socket = socket; | |
310 c->type = type; | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
311 c->inpa = gaim_input_add(socket, type, yahoo_pending, gc); |
2086 | 312 yd->conns = g_list_append(yd->conns, c); |
313 } else { | |
314 GList *c = yd->conns; | |
315 while (c) { | |
316 struct conn *m = c->data; | |
317 if ((m->socket == socket) && (m->type == type)) { | |
318 yd->conns = g_list_remove(yd->conns, m); | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
319 gaim_input_remove(m->inpa); |
2086 | 320 g_free(m); |
321 return; | |
322 } | |
323 c = g_list_next(c); | |
324 } | |
325 } | |
326 } | |
327 | |
2090
b66aca8e8dce
[gaim-migrate @ 2100]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2086
diff
changeset
|
328 static void yahoo_got_connected(gpointer data, gint source, GaimInputCondition cond) { |
2086 | 329 struct connect *con = data; |
330 | |
331 debug_printf("got connected (possibly)\n"); | |
332 yahoo_connected(con->sess, con->data, source); | |
333 | |
334 g_free(con); | |
335 } | |
336 | |
337 static int yahoo_connect_to(struct yahoo_session *sess, const char *host, int port, gpointer data) { | |
338 struct connect *con = g_new0(struct connect, 1); | |
339 int fd; | |
340 | |
341 con->sess = sess; | |
342 con->data = data; | |
343 fd = proxy_connect((char *)host, port, yahoo_got_connected, con); | |
344 if (fd < 0) { | |
345 g_free(con); | |
346 return -1; | |
347 } | |
348 | |
349 return fd; | |
350 } | |
351 | |
352 static void yahoo_debug(struct yahoo_session *sess, int level, const char *string) { | |
353 debug_printf("Level %d: %s\n", level, string); | |
354 } | |
355 | |
356 static void yahoo_login(struct aim_user *user) { | |
357 struct gaim_connection *gc = new_gaim_conn(user); | |
358 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1); | |
359 | |
360 yd->sess = yahoo_new(); | |
361 yd->sess->user_data = gc; | |
362 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
363 yd->hash = g_hash_table_new(g_str_hash, g_str_equal); | |
364 | |
365 set_login_progress(gc, 1, "Connecting"); | |
366 | |
367 if (!yahoo_connect(yd->sess, user->proto_opt[USEROPT_AUTHHOST], | |
368 atoi(user->proto_opt[USEROPT_AUTHPORT]))) { | |
369 hide_login_progress(gc, "Connection problem"); | |
370 signoff(gc); | |
371 return; | |
372 } | |
373 | |
374 yahoo_add_handler(yd->sess, YAHOO_HANDLE_DISCONNECT, yahoo_disconn); | |
375 yahoo_add_handler(yd->sess, YAHOO_HANDLE_AUTHCONNECT, yahoo_authconnect); | |
376 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BADPASSWORD, yahoo_badpassword); | |
377 yahoo_add_handler(yd->sess, YAHOO_HANDLE_LOGINCOOKIE, yahoo_logincookie); | |
378 yahoo_add_handler(yd->sess, YAHOO_HANDLE_MAINCONNECT, yahoo_mainconnect); | |
379 yahoo_add_handler(yd->sess, YAHOO_HANDLE_ONLINE, yahoo_online); | |
380 yahoo_add_handler(yd->sess, YAHOO_HANDLE_NEWMAIL, yahoo_newmail); | |
381 yahoo_add_handler(yd->sess, YAHOO_HANDLE_MESSAGE, yahoo_message); | |
382 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BOUNCE, yahoo_bounce); | |
383 yahoo_add_handler(yd->sess, YAHOO_HANDLE_STATUS, yahoo_status); | |
384 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BUDDYADDED, yahoo_buddyadded); | |
385 } | |
386 | |
387 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) { | |
388 g_free(key); | |
389 g_free(val); | |
390 return TRUE; | |
391 } | |
392 | |
393 static void yahoo_close(struct gaim_connection *gc) { | |
394 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
395 while (yd->offline) { | |
396 g_free(yd->offline->data); | |
397 yd->offline = g_slist_remove(yd->offline, yd->offline->data); | |
398 } | |
399 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL); | |
400 g_hash_table_destroy(yd->hash); | |
401 yahoo_disconnect(yd->sess); | |
402 yahoo_delete(yd->sess); | |
403 g_free(yd); | |
404 } | |
405 | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
406 static int yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) { |
2086 | 407 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
408 GSList *l = yd->offline; | |
409 | |
2123
56c4382f2909
[gaim-migrate @ 2133]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2090
diff
changeset
|
410 if (away || !strlen(message)) return 0; |
2086 | 411 |
412 while (l) { | |
413 if (!strcmp(who, l->data)) | |
414 break; | |
415 l = l->next; | |
416 } | |
417 | |
418 if (l) | |
419 yahoo_send_message(yd->sess, yd->active_id, who, message); | |
420 else | |
421 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
|
422 return 0; |
2086 | 423 } |
424 | |
425 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
426 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
427 | |
428 gc->away = NULL; | |
429 | |
430 if (msg) { | |
431 yahoo_away(yd->sess, YAHOO_STATUS_CUSTOM, msg); | |
432 yd->current_status = YAHOO_STATUS_CUSTOM; | |
433 gc->away = ""; | |
434 } else if (state) { | |
435 gc->away = ""; | |
436 if (!strcmp(state, "Available")) { | |
437 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, msg); | |
438 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
439 } else if (!strcmp(state, "Be Right Back")) { | |
440 yahoo_away(yd->sess, YAHOO_STATUS_BRB, msg); | |
441 yd->current_status = YAHOO_STATUS_BRB; | |
442 } else if (!strcmp(state, "Busy")) { | |
443 yahoo_away(yd->sess, YAHOO_STATUS_BUSY, msg); | |
444 yd->current_status = YAHOO_STATUS_BUSY; | |
445 } else if (!strcmp(state, "Not At Home")) { | |
446 yahoo_away(yd->sess, YAHOO_STATUS_NOTATHOME, msg); | |
447 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
448 } else if (!strcmp(state, "Not At Desk")) { | |
449 yahoo_away(yd->sess, YAHOO_STATUS_NOTATDESK, msg); | |
450 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
451 } else if (!strcmp(state, "Not In Office")) { | |
452 yahoo_away(yd->sess, YAHOO_STATUS_NOTINOFFICE, msg); | |
453 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
454 } else if (!strcmp(state, "On Phone")) { | |
455 yahoo_away(yd->sess, YAHOO_STATUS_ONPHONE, msg); | |
456 yd->current_status = YAHOO_STATUS_ONPHONE; | |
457 } else if (!strcmp(state, "On Vacation")) { | |
458 yahoo_away(yd->sess, YAHOO_STATUS_ONVACATION, msg); | |
459 yd->current_status = YAHOO_STATUS_ONVACATION; | |
460 } else if (!strcmp(state, "Out To Lunch")) { | |
461 yahoo_away(yd->sess, YAHOO_STATUS_OUTTOLUNCH, msg); | |
462 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
463 } else if (!strcmp(state, "Stepped Out")) { | |
464 yahoo_away(yd->sess, YAHOO_STATUS_STEPPEDOUT, msg); | |
465 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
466 } else if (!strcmp(state, "Invisible")) { | |
467 yahoo_away(yd->sess, YAHOO_STATUS_INVISIBLE, msg); | |
468 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
469 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
470 if (gc->is_idle) { | |
471 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
472 yd->current_status = YAHOO_STATUS_IDLE; | |
473 } else { | |
474 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
475 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
476 } | |
477 gc->away = NULL; | |
478 } | |
479 } else if (gc->is_idle) { | |
480 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
481 yd->current_status = YAHOO_STATUS_IDLE; | |
482 } else { | |
483 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
484 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
485 } | |
486 } | |
487 | |
488 static void yahoo_set_idle(struct gaim_connection *gc, int idle) { | |
489 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
490 | |
491 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
492 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
493 yd->current_status = YAHOO_STATUS_IDLE; | |
494 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
495 yahoo_back(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
496 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
497 } | |
498 } | |
499 | |
500 static void yahoo_keepalive(struct gaim_connection *gc) { | |
501 yahoo_ping(((struct yahoo_data *)gc->proto_data)->sess); | |
502 } | |
503 | |
504 static void gyahoo_add_buddy(struct gaim_connection *gc, char *name) { | |
505 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
506 struct yahoo_group *tmpgroup; | |
507 struct group *g = find_group_by_buddy(gc, name); | |
508 char *group = NULL; | |
509 | |
510 if (!yd->logged_in) | |
511 return; | |
512 | |
513 if (g) { | |
514 group = g->name; | |
515 } else if (yd->sess && yd->sess->groups) { | |
516 tmpgroup = yd->sess->groups->data; | |
517 group = tmpgroup->name; | |
518 } else { | |
519 group = "Buddies"; | |
520 } | |
521 | |
522 if (group) | |
523 yahoo_add_buddy(yd->sess, yd->active_id, group, name, ""); | |
524 } | |
525 | |
526 static void yahoo_add_buddies(struct gaim_connection *gc, GList *buddies) { | |
527 while (buddies) { | |
528 gyahoo_add_buddy(gc, buddies->data); | |
529 buddies = buddies->next; | |
530 } | |
531 } | |
532 | |
533 static void gyahoo_remove_buddy(struct gaim_connection *gc, char *name) { | |
534 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
535 struct group *g = find_group_by_buddy(gc, name); | |
536 char *group = NULL; | |
537 | |
538 if (g) { | |
539 group = g->name; | |
540 } else if (yd->sess && yd->sess->groups) { | |
541 GList *x = yd->sess->groups; | |
542 while (x) { | |
543 struct yahoo_group *tmpgroup = x->data; | |
544 char **bds = tmpgroup->buddies; | |
545 while (*bds) { | |
546 if (!strcmp(*bds, name)) | |
547 break; | |
548 bds++; | |
549 } | |
550 if (*bds) { | |
551 group = tmpgroup->name; | |
552 break; | |
553 } | |
554 x = x->next; | |
555 } | |
556 } else { | |
557 group = "Buddies"; | |
558 } | |
559 | |
560 if (group) | |
561 yahoo_remove_buddy(yd->sess, yd->active_id, group, name, ""); | |
562 } | |
563 | |
564 static char **yahoo_list_icon(int uc) { | |
565 if ((uc >> 5) == YAHOO_STATUS_IDLE) | |
566 return status_idle_xpm; | |
567 else if (uc == UC_NORMAL) | |
568 return status_here_xpm; | |
569 return status_away_xpm; | |
570 } | |
571 | |
572 static char *yahoo_get_status_string(enum yahoo_status a) { | |
573 switch (a) { | |
574 case YAHOO_STATUS_BRB: | |
575 return "Be Right Back"; | |
576 case YAHOO_STATUS_BUSY: | |
577 return "Busy"; | |
578 case YAHOO_STATUS_NOTATHOME: | |
579 return "Not At Home"; | |
580 case YAHOO_STATUS_NOTATDESK: | |
581 return "Not At Desk"; | |
582 case YAHOO_STATUS_NOTINOFFICE: | |
583 return "Not In Office"; | |
584 case YAHOO_STATUS_ONPHONE: | |
585 return "On Phone"; | |
586 case YAHOO_STATUS_ONVACATION: | |
587 return "On Vacation"; | |
588 case YAHOO_STATUS_OUTTOLUNCH: | |
589 return "Out To Lunch"; | |
590 case YAHOO_STATUS_STEPPEDOUT: | |
591 return "Stepped Out"; | |
592 default: | |
593 return NULL; | |
594 } | |
595 } | |
596 | |
597 static void yahoo_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) { | |
598 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
599 GtkWidget *button; | |
600 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
601 segfault and get the bug report. */ | |
602 char buf[1024]; | |
603 | |
604 if (b->uc & UC_NORMAL) | |
605 return; | |
606 | |
607 if ((b->uc >> 5) != YAHOO_STATUS_CUSTOM) | |
608 g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 5)); | |
609 else | |
610 g_snprintf(buf, sizeof buf, "Custom Status: %s", | |
611 (char *)g_hash_table_lookup(yd->hash, b->name)); | |
612 button = gtk_menu_item_new_with_label(buf); | |
613 gtk_menu_append(GTK_MENU(menu), button); | |
614 gtk_widget_show(button); | |
615 } | |
616 | |
617 static GList *yahoo_away_states() { | |
618 GList *m = NULL; | |
619 | |
620 m = g_list_append(m, "Available"); | |
621 m = g_list_append(m, "Be Right Back"); | |
622 m = g_list_append(m, "Busy"); | |
623 m = g_list_append(m, "Not At Home"); | |
624 m = g_list_append(m, "Not At Desk"); | |
625 m = g_list_append(m, "Not In Office"); | |
626 m = g_list_append(m, "On Phone"); | |
627 m = g_list_append(m, "On Vacation"); | |
628 m = g_list_append(m, "Out To Lunch"); | |
629 m = g_list_append(m, "Stepped Out"); | |
630 m = g_list_append(m, "Invisible"); | |
631 m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
632 | |
633 return m; | |
634 } | |
635 | |
636 static void yahoo_act_id(gpointer data, char *entry) { | |
637 struct gaim_connection *gc = data; | |
638 struct yahoo_data *yd = gc->proto_data; | |
639 | |
640 yahoo_activate_id(yd->sess, entry); | |
641 if (yd->active_id) | |
642 g_free(yd->active_id); | |
643 yd->active_id = g_strdup(entry); | |
644 } | |
645 | |
646 static void yahoo_do_action(struct gaim_connection *gc, char *act) { | |
647 if (!strcmp(act, "Activate ID")) { | |
648 do_prompt_dialog("Activate which ID:", gc, yahoo_act_id, NULL); | |
649 } | |
650 } | |
651 | |
652 static GList *yahoo_actions() { | |
653 GList *m = NULL; | |
654 | |
655 m = g_list_append(m, "Activate ID"); | |
656 | |
657 return m; | |
658 } | |
659 | |
660 static void yahoo_print_option(GtkEntry *entry, struct aim_user *user) { | |
661 int entrynum; | |
662 | |
663 entrynum = (int) gtk_object_get_user_data(GTK_OBJECT(entry)); | |
664 | |
665 if (entrynum == USEROPT_AUTHHOST) { | |
666 g_snprintf(user->proto_opt[USEROPT_AUTHHOST], | |
667 sizeof(user->proto_opt[USEROPT_AUTHHOST]), | |
668 "%s", gtk_entry_get_text(entry)); | |
669 } else if (entrynum == USEROPT_AUTHPORT) { | |
670 g_snprintf(user->proto_opt[USEROPT_AUTHPORT], | |
671 sizeof(user->proto_opt[USEROPT_AUTHPORT]), | |
672 "%s", gtk_entry_get_text(entry)); | |
673 } else if (entrynum == USEROPT_PAGERHOST) { | |
674 g_snprintf(user->proto_opt[USEROPT_PAGERHOST], | |
675 sizeof(user->proto_opt[USEROPT_PAGERHOST]), | |
676 "%s", gtk_entry_get_text(entry)); | |
677 } else if (entrynum == USEROPT_PAGERPORT) { | |
678 g_snprintf(user->proto_opt[USEROPT_PAGERPORT], | |
679 sizeof(user->proto_opt[USEROPT_PAGERPORT]), | |
680 "%s", gtk_entry_get_text(entry)); | |
681 } | |
682 } | |
683 | |
684 static void yahoo_user_opts(GtkWidget *book, struct aim_user *user) | |
685 { | |
686 GtkWidget *vbox; | |
687 GtkWidget *hbox; | |
688 GtkWidget *label; | |
689 GtkWidget *entry; | |
690 | |
691 vbox = gtk_vbox_new(FALSE, 5); | |
692 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5); | |
693 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("Yahoo Options")); | |
694 gtk_widget_show(vbox); | |
695 | |
696 hbox = gtk_hbox_new(FALSE, 5); | |
697 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
698 gtk_widget_show(hbox); | |
699 | |
700 label = gtk_label_new("Yahoo Auth Host:"); | |
701 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
702 gtk_widget_show(label); | |
703 | |
704 entry = gtk_entry_new(); | |
705 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
706 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_AUTHHOST); | |
707 gtk_signal_connect(GTK_OBJECT(entry), "changed", | |
708 GTK_SIGNAL_FUNC(yahoo_print_option), user); | |
709 if (user->proto_opt[USEROPT_AUTHHOST][0]) { | |
710 debug_printf("setting text %s\n", user->proto_opt[USEROPT_AUTHHOST]); | |
711 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTHHOST]); | |
712 } else { | |
713 gtk_entry_set_text(GTK_ENTRY(entry), YAHOO_AUTH_HOST); | |
714 } | |
715 gtk_widget_show(entry); | |
716 | |
717 hbox = gtk_hbox_new(FALSE, 5); | |
718 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
719 gtk_widget_show(hbox); | |
720 | |
721 label = gtk_label_new("Yahoo Auth Port:"); | |
722 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
723 gtk_widget_show(label); | |
724 | |
725 entry = gtk_entry_new(); | |
726 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
727 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_AUTHPORT); | |
728 gtk_signal_connect(GTK_OBJECT(entry), "changed", | |
729 GTK_SIGNAL_FUNC(yahoo_print_option), user); | |
730 if (user->proto_opt[USEROPT_AUTHPORT][0]) { | |
731 debug_printf("setting text %s\n", user->proto_opt[USEROPT_AUTHPORT]); | |
732 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTHPORT]); | |
733 } else { | |
734 g_snprintf(user->proto_opt[USEROPT_AUTHPORT], sizeof(user->proto_opt[USEROPT_AUTHPORT]), | |
735 "%d", YAHOO_AUTH_PORT); | |
736 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTHPORT]); | |
737 } | |
738 gtk_widget_show(entry); | |
739 | |
740 hbox = gtk_hbox_new(FALSE, 5); | |
741 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
742 gtk_widget_show(hbox); | |
743 | |
744 label = gtk_label_new("Yahoo Pager Host:"); | |
745 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
746 gtk_widget_show(label); | |
747 | |
748 entry = gtk_entry_new(); | |
749 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
750 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PAGERHOST); | |
751 gtk_signal_connect(GTK_OBJECT(entry), "changed", | |
752 GTK_SIGNAL_FUNC(yahoo_print_option), user); | |
753 if (user->proto_opt[USEROPT_PAGERHOST][0]) { | |
754 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PAGERHOST]); | |
755 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PAGERHOST]); | |
756 } else { | |
757 gtk_entry_set_text(GTK_ENTRY(entry), YAHOO_PAGER_HOST); | |
758 } | |
759 gtk_widget_show(entry); | |
760 | |
761 hbox = gtk_hbox_new(FALSE, 5); | |
762 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0); | |
763 gtk_widget_show(hbox); | |
764 | |
765 label = gtk_label_new("Yahoo Pager Port:"); | |
766 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
767 gtk_widget_show(label); | |
768 | |
769 entry = gtk_entry_new(); | |
770 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0); | |
771 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PAGERPORT); | |
772 gtk_signal_connect(GTK_OBJECT(entry), "changed", | |
773 GTK_SIGNAL_FUNC(yahoo_print_option), user); | |
774 if (user->proto_opt[USEROPT_PAGERPORT][0]) { | |
775 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PAGERPORT]); | |
776 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PAGERPORT]); | |
777 } else { | |
778 g_snprintf(user->proto_opt[USEROPT_PAGERPORT], sizeof(user->proto_opt[USEROPT_PAGERPORT]), | |
779 "%d", YAHOO_PAGER_PORT); | |
780 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PAGERPORT]); | |
781 } | |
782 gtk_widget_show(entry); | |
783 } | |
784 | |
785 static void toggle_offline(GtkToggleButton *button, struct conversation *c) | |
786 { | |
787 struct gaim_connection *gc = gtk_object_get_user_data(GTK_OBJECT(button)); | |
788 struct yahoo_data *yd = gc->proto_data; | |
789 GSList *l = yd->offline; | |
790 | |
791 while (l) { | |
792 if (!strcmp(c->name, l->data)) | |
793 break; | |
794 l = l->next; | |
795 } | |
796 if (l) { | |
797 g_free(l->data); | |
798 yd->offline = g_slist_remove(yd->offline, l->data); | |
799 } else | |
800 yd->offline = g_slist_append(yd->offline, g_strdup(c->name)); | |
801 } | |
802 | |
803 static void yahoo_insert_convo(struct gaim_connection *gc, struct conversation *c) | |
804 { | |
805 GtkWidget *button; | |
806 struct yahoo_data *yd = gc->proto_data; | |
807 GSList *l = yd->offline; | |
808 struct buddy *b = find_buddy(gc, c->name); | |
809 | |
810 button = gtk_check_button_new_with_label("Send offline message"); | |
811 gtk_box_pack_start(GTK_BOX(c->lbox), button, FALSE, FALSE, 5); | |
812 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_offline), c); | |
813 gtk_object_set_user_data(GTK_OBJECT(button), gc); | |
814 while (l) { | |
815 if (!strcmp(c->name, l->data)) | |
816 break; | |
817 l = l->next; | |
818 } | |
819 if (l || (b && !b->present)) | |
820 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE); | |
821 gtk_widget_show(button); | |
822 } | |
823 | |
824 static void yahoo_remove_convo(struct gaim_connection *gc, struct conversation *c) | |
825 { | |
826 while (GTK_BOX(c->lbox)->children) | |
827 gtk_container_remove(GTK_CONTAINER(c->lbox), | |
828 ((GtkBoxChild *)GTK_BOX(c->lbox)->children->data)->widget); | |
829 } | |
830 | |
831 static struct prpl *my_protocol = NULL; | |
832 | |
833 void yahoo_init(struct prpl *ret) { | |
834 /* the NULL's aren't required but they're nice to have */ | |
835 ret->protocol = PROTO_YAHOO; | |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2145
diff
changeset
|
836 ret->options = OPT_PROTO_MAIL_CHECK; |
2086 | 837 ret->name = yahoo_name; |
838 ret->list_icon = yahoo_list_icon; | |
839 ret->away_states = yahoo_away_states; | |
840 ret->actions = yahoo_actions; | |
841 ret->do_action = yahoo_do_action; | |
842 ret->buddy_menu = yahoo_buddy_menu; | |
843 ret->user_opts = yahoo_user_opts; | |
844 ret->insert_convo = yahoo_insert_convo; | |
845 ret->remove_convo = yahoo_remove_convo; | |
846 ret->login = yahoo_login; | |
847 ret->close = yahoo_close; | |
848 ret->send_im = yahoo_send_im; | |
849 ret->set_info = NULL; | |
850 ret->get_info = NULL; | |
851 ret->set_away = yahoo_set_away; | |
852 ret->get_away_msg = NULL; | |
853 ret->set_dir = NULL; | |
854 ret->get_dir = NULL; | |
855 ret->dir_search = NULL; | |
856 ret->set_idle = yahoo_set_idle; | |
857 ret->change_passwd = NULL; | |
858 ret->add_buddy = gyahoo_add_buddy; | |
859 ret->add_buddies = yahoo_add_buddies; | |
860 ret->remove_buddy = gyahoo_remove_buddy; | |
861 ret->add_permit = NULL; | |
862 ret->add_deny = NULL; | |
863 ret->rem_permit = NULL; | |
864 ret->rem_deny = NULL; | |
865 ret->set_permit_deny = NULL; | |
866 ret->warn = NULL; | |
867 ret->accept_chat = NULL; | |
868 ret->join_chat = NULL; | |
869 ret->chat_invite = NULL; | |
870 ret->chat_leave = NULL; | |
871 ret->chat_whisper = NULL; | |
872 ret->chat_send = NULL; | |
873 ret->keepalive = yahoo_keepalive; | |
874 | |
875 my_protocol = ret; | |
876 | |
877 yahoo_socket_notify = yahoo_notify; | |
878 yahoo_print = yahoo_debug; | |
879 yahoo_connector = yahoo_connect_to; | |
880 } | |
881 | |
882 #ifndef STATIC | |
883 | |
884 char *gaim_plugin_init(GModule *handle) | |
885 { | |
886 load_protocol(yahoo_init, sizeof(struct prpl)); | |
887 return NULL; | |
888 } | |
889 | |
890 void gaim_plugin_remove() | |
891 { | |
892 struct prpl *p = find_prpl(PROTO_YAHOO); | |
893 if (p == my_protocol) | |
894 unload_protocol(p); | |
895 } | |
896 | |
897 char *name() | |
898 { | |
899 return "Yahoo"; | |
900 } | |
901 | |
902 char *description() | |
903 { | |
904 return "Allows gaim to use the Yahoo protocol"; | |
905 } | |
906 | |
907 #endif |