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 void des_win(GtkWidget *w, struct yahoo_data *yd) {
|
|
201 gtk_widget_destroy(yd->email_win);
|
|
202 if (yd->email_win == w)
|
|
203 yd->email_win = NULL;
|
|
204 yd->email_label = NULL;
|
|
205 }
|
|
206
|
|
207 static int yahoo_newmail(struct yahoo_session *sess, ...) {
|
|
208 struct gaim_connection *gc = sess->user_data;
|
|
209 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
210 char buf[2048];
|
|
211
|
|
212 va_list ap;
|
|
213 int count;
|
|
214
|
|
215 va_start(ap, sess);
|
|
216 count = va_arg(ap, int);
|
|
217 va_end(ap);
|
|
218
|
|
219 if (gc->user->proto_opt[USEROPT_MAIL][0] != '1')
|
|
220 return 1;
|
|
221
|
|
222 if (count) {
|
|
223 g_snprintf(buf, sizeof buf, "%s has %d new message%s on Yahoo Mail.",
|
|
224 gc->username, count, count == 1 ? "" : "s");
|
|
225 if (!yd->email_win) {
|
|
226 GtkWidget *close;
|
|
227
|
|
228 yd->email_win = gtk_dialog_new();
|
|
229 gtk_window_set_policy(GTK_WINDOW(yd->email_win), 0, 0, 1);
|
|
230 gtk_container_set_border_width(GTK_CONTAINER(yd->email_win), 5);
|
|
231 gtk_window_set_title(GTK_WINDOW(yd->email_win), "New Mail");
|
|
232 gtk_signal_connect(GTK_OBJECT(yd->email_win), "destroy",
|
|
233 GTK_SIGNAL_FUNC(des_win), yd);
|
|
234 gtk_widget_realize(yd->email_win);
|
|
235 aol_icon(yd->email_win->window);
|
|
236
|
|
237 yd->email_label = gtk_label_new(buf);
|
|
238 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(yd->email_win)->vbox),
|
|
239 yd->email_label, 0, 0, 5);
|
|
240 gtk_widget_show(yd->email_label);
|
|
241
|
|
242 close = picture_button(yd->email_win, _("Close"), cancel_xpm);
|
|
243 gtk_box_pack_start(GTK_BOX(GTK_DIALOG(yd->email_win)->action_area),
|
|
244 close, 0, 0, 5);
|
|
245 gtk_signal_connect(GTK_OBJECT(close), "clicked", GTK_SIGNAL_FUNC(des_win), yd);
|
|
246
|
|
247 gtk_widget_show(yd->email_win);
|
|
248 }
|
|
249 gtk_label_set_text(GTK_LABEL(yd->email_label), buf);
|
|
250 } else if (yd->email_win)
|
|
251 gtk_widget_destroy(yd->email_win);
|
|
252
|
|
253 return 1;
|
|
254 }
|
|
255
|
|
256 static int yahoo_disconn(struct yahoo_session *sess, ...) {
|
|
257 struct gaim_connection *gc = sess->user_data;
|
|
258 hide_login_progress(gc, "Disconnected");
|
|
259 signoff(gc);
|
|
260 return 1;
|
|
261 }
|
|
262
|
|
263 static int yahoo_authconnect(struct yahoo_session *sess, ...) {
|
|
264 struct gaim_connection *gc = sess->user_data;
|
|
265
|
|
266 set_login_progress(gc, 2, "Connected to Auth");
|
|
267 if (yahoo_send_login(sess, gc->username, gc->password) < 1) {
|
|
268 hide_login_progress(gc, "Authorizer error");
|
|
269 signoff(gc);
|
|
270 }
|
|
271
|
|
272 return 1;
|
|
273 }
|
|
274
|
|
275 static int yahoo_badpassword(struct yahoo_session *sess, ...) {
|
|
276 struct gaim_connection *gc = sess->user_data;
|
|
277 hide_login_progress(gc, "Bad Password");
|
|
278 signoff(gc);
|
|
279 return 1;
|
|
280 }
|
|
281
|
|
282 static int yahoo_logincookie(struct yahoo_session *sess, ...) {
|
|
283 struct gaim_connection *gc = sess->user_data;
|
|
284
|
|
285 set_login_progress(gc, 3, "Got login cookie");
|
|
286 if (yahoo_major_connect(sess, gc->user->proto_opt[USEROPT_PAGERHOST],
|
|
287 atoi(gc->user->proto_opt[USEROPT_PAGERPORT])) < 1) {
|
|
288 hide_login_progress(gc, "Login error");
|
|
289 signoff(gc);
|
|
290 }
|
|
291
|
|
292 return 1;
|
|
293 }
|
|
294
|
|
295 static int yahoo_mainconnect(struct yahoo_session *sess, ...) {
|
|
296 struct gaim_connection *gc = sess->user_data;
|
|
297 struct yahoo_data *yd = gc->proto_data;
|
|
298 GList *grps;
|
|
299
|
|
300 set_login_progress(gc, 4, "Connected to service");
|
|
301 if (yahoo_finish_logon(sess, YAHOO_STATUS_AVAILABLE) < 1) {
|
|
302 hide_login_progress(gc, "Login error");
|
|
303 signoff(gc);
|
|
304 }
|
|
305
|
|
306 if (bud_list_cache_exists(gc))
|
|
307 do_import(NULL, gc);
|
|
308
|
|
309 grps = yd->sess->groups;
|
|
310 while (grps) {
|
|
311 struct yahoo_group *grp = grps->data;
|
|
312 int i;
|
|
313
|
|
314 for (i = 0; grp->buddies[i]; i++)
|
|
315 add_buddy(gc, grp->name, grp->buddies[i], NULL);
|
|
316
|
|
317 grps = grps->next;
|
|
318 }
|
|
319
|
|
320 return 1;
|
|
321 }
|
|
322
|
|
323 static int yahoo_online(struct yahoo_session *sess, ...) {
|
|
324 struct gaim_connection *gc = sess->user_data;
|
|
325 struct yahoo_data *yd = gc->proto_data;
|
|
326
|
|
327 account_online(gc);
|
|
328 serv_finish_login(gc);
|
|
329 yd->active_id = g_strdup(gc->username);
|
|
330 yd->logged_in = TRUE;
|
|
331
|
|
332 return 1;
|
|
333 }
|
|
334
|
|
335 static void yahoo_pending(gpointer data, gint source, GdkInputCondition condition) {
|
|
336 struct gaim_connection *gc = (struct gaim_connection *)data;
|
|
337 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
338
|
|
339 yahoo_socket_handler(yd->sess, source, condition);
|
|
340 }
|
|
341
|
|
342 static void yahoo_notify(struct yahoo_session *sess, int socket, int type, int cont) {
|
|
343 struct gaim_connection *gc = sess->user_data;
|
|
344 struct yahoo_data *yd = gc->proto_data;
|
|
345
|
|
346 if (cont) {
|
|
347 struct conn *c = g_new0(struct conn, 1);
|
|
348 c->socket = socket;
|
|
349 c->type = type;
|
|
350 c->inpa = gdk_input_add(socket, type, yahoo_pending, gc);
|
|
351 yd->conns = g_list_append(yd->conns, c);
|
|
352 } else {
|
|
353 GList *c = yd->conns;
|
|
354 while (c) {
|
|
355 struct conn *m = c->data;
|
|
356 if ((m->socket == socket) && (m->type == type)) {
|
|
357 yd->conns = g_list_remove(yd->conns, m);
|
|
358 gdk_input_remove(m->inpa);
|
|
359 g_free(m);
|
|
360 return;
|
|
361 }
|
|
362 c = g_list_next(c);
|
|
363 }
|
|
364 }
|
|
365 }
|
|
366
|
|
367 static void yahoo_got_connected(gpointer data, gint source, GdkInputCondition cond) {
|
|
368 struct connect *con = data;
|
|
369
|
|
370 debug_printf("got connected (possibly)\n");
|
|
371 yahoo_connected(con->sess, con->data, source);
|
|
372
|
|
373 g_free(con);
|
|
374 }
|
|
375
|
|
376 static int yahoo_connect_to(struct yahoo_session *sess, const char *host, int port, gpointer data) {
|
|
377 struct connect *con = g_new0(struct connect, 1);
|
|
378 int fd;
|
|
379
|
|
380 con->sess = sess;
|
|
381 con->data = data;
|
|
382 fd = proxy_connect((char *)host, port, yahoo_got_connected, con);
|
|
383 if (fd < 0) {
|
|
384 g_free(con);
|
|
385 return -1;
|
|
386 }
|
|
387
|
|
388 return fd;
|
|
389 }
|
|
390
|
|
391 static void yahoo_debug(struct yahoo_session *sess, int level, const char *string) {
|
|
392 debug_printf("Level %d: %s\n", level, string);
|
|
393 }
|
|
394
|
|
395 static void yahoo_login(struct aim_user *user) {
|
|
396 struct gaim_connection *gc = new_gaim_conn(user);
|
|
397 struct yahoo_data *yd = gc->proto_data = g_new0(struct yahoo_data, 1);
|
|
398
|
|
399 yd->sess = yahoo_new();
|
|
400 yd->sess->user_data = gc;
|
|
401 yd->current_status = YAHOO_STATUS_AVAILABLE;
|
|
402 yd->hash = g_hash_table_new(g_str_hash, g_str_equal);
|
|
403
|
|
404 set_login_progress(gc, 1, "Connecting");
|
|
405
|
|
406 if (!yahoo_connect(yd->sess, user->proto_opt[USEROPT_AUTHHOST],
|
|
407 atoi(user->proto_opt[USEROPT_AUTHPORT]))) {
|
|
408 hide_login_progress(gc, "Connection problem");
|
|
409 signoff(gc);
|
|
410 return;
|
|
411 }
|
|
412
|
|
413 yahoo_add_handler(yd->sess, YAHOO_HANDLE_DISCONNECT, yahoo_disconn);
|
|
414 yahoo_add_handler(yd->sess, YAHOO_HANDLE_AUTHCONNECT, yahoo_authconnect);
|
|
415 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BADPASSWORD, yahoo_badpassword);
|
|
416 yahoo_add_handler(yd->sess, YAHOO_HANDLE_LOGINCOOKIE, yahoo_logincookie);
|
|
417 yahoo_add_handler(yd->sess, YAHOO_HANDLE_MAINCONNECT, yahoo_mainconnect);
|
|
418 yahoo_add_handler(yd->sess, YAHOO_HANDLE_ONLINE, yahoo_online);
|
|
419 yahoo_add_handler(yd->sess, YAHOO_HANDLE_NEWMAIL, yahoo_newmail);
|
|
420 yahoo_add_handler(yd->sess, YAHOO_HANDLE_MESSAGE, yahoo_message);
|
|
421 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BOUNCE, yahoo_bounce);
|
|
422 yahoo_add_handler(yd->sess, YAHOO_HANDLE_STATUS, yahoo_status);
|
|
423 yahoo_add_handler(yd->sess, YAHOO_HANDLE_BUDDYADDED, yahoo_buddyadded);
|
|
424 }
|
|
425
|
|
426 static gboolean yahoo_destroy_hash(gpointer key, gpointer val, gpointer data) {
|
|
427 g_free(key);
|
|
428 g_free(val);
|
|
429 return TRUE;
|
|
430 }
|
|
431
|
|
432 static void yahoo_close(struct gaim_connection *gc) {
|
|
433 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
434 while (yd->offline) {
|
|
435 g_free(yd->offline->data);
|
|
436 yd->offline = g_slist_remove(yd->offline, yd->offline->data);
|
|
437 }
|
|
438 g_hash_table_foreach_remove(yd->hash, yahoo_destroy_hash, NULL);
|
|
439 g_hash_table_destroy(yd->hash);
|
|
440 yahoo_disconnect(yd->sess);
|
|
441 yahoo_delete(yd->sess);
|
|
442 g_free(yd);
|
|
443 }
|
|
444
|
|
445 static void yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int away) {
|
|
446 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
447 GSList *l = yd->offline;
|
|
448
|
|
449 if (away || !strlen(message)) return;
|
|
450
|
|
451 while (l) {
|
|
452 if (!strcmp(who, l->data))
|
|
453 break;
|
|
454 l = l->next;
|
|
455 }
|
|
456
|
|
457 if (l)
|
|
458 yahoo_send_message(yd->sess, yd->active_id, who, message);
|
|
459 else
|
|
460 yahoo_send_message_offline(yd->sess, yd->active_id, who, message);
|
|
461 }
|
|
462
|
|
463 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) {
|
|
464 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
465
|
|
466 gc->away = NULL;
|
|
467
|
|
468 if (msg) {
|
|
469 yahoo_away(yd->sess, YAHOO_STATUS_CUSTOM, msg);
|
|
470 yd->current_status = YAHOO_STATUS_CUSTOM;
|
|
471 gc->away = "";
|
|
472 } else if (state) {
|
|
473 gc->away = "";
|
|
474 if (!strcmp(state, "Available")) {
|
|
475 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, msg);
|
|
476 yd->current_status = YAHOO_STATUS_AVAILABLE;
|
|
477 } else if (!strcmp(state, "Be Right Back")) {
|
|
478 yahoo_away(yd->sess, YAHOO_STATUS_BRB, msg);
|
|
479 yd->current_status = YAHOO_STATUS_BRB;
|
|
480 } else if (!strcmp(state, "Busy")) {
|
|
481 yahoo_away(yd->sess, YAHOO_STATUS_BUSY, msg);
|
|
482 yd->current_status = YAHOO_STATUS_BUSY;
|
|
483 } else if (!strcmp(state, "Not At Home")) {
|
|
484 yahoo_away(yd->sess, YAHOO_STATUS_NOTATHOME, msg);
|
|
485 yd->current_status = YAHOO_STATUS_NOTATHOME;
|
|
486 } else if (!strcmp(state, "Not At Desk")) {
|
|
487 yahoo_away(yd->sess, YAHOO_STATUS_NOTATDESK, msg);
|
|
488 yd->current_status = YAHOO_STATUS_NOTATDESK;
|
|
489 } else if (!strcmp(state, "Not In Office")) {
|
|
490 yahoo_away(yd->sess, YAHOO_STATUS_NOTINOFFICE, msg);
|
|
491 yd->current_status = YAHOO_STATUS_NOTINOFFICE;
|
|
492 } else if (!strcmp(state, "On Phone")) {
|
|
493 yahoo_away(yd->sess, YAHOO_STATUS_ONPHONE, msg);
|
|
494 yd->current_status = YAHOO_STATUS_ONPHONE;
|
|
495 } else if (!strcmp(state, "On Vacation")) {
|
|
496 yahoo_away(yd->sess, YAHOO_STATUS_ONVACATION, msg);
|
|
497 yd->current_status = YAHOO_STATUS_ONVACATION;
|
|
498 } else if (!strcmp(state, "Out To Lunch")) {
|
|
499 yahoo_away(yd->sess, YAHOO_STATUS_OUTTOLUNCH, msg);
|
|
500 yd->current_status = YAHOO_STATUS_OUTTOLUNCH;
|
|
501 } else if (!strcmp(state, "Stepped Out")) {
|
|
502 yahoo_away(yd->sess, YAHOO_STATUS_STEPPEDOUT, msg);
|
|
503 yd->current_status = YAHOO_STATUS_STEPPEDOUT;
|
|
504 } else if (!strcmp(state, "Invisible")) {
|
|
505 yahoo_away(yd->sess, YAHOO_STATUS_INVISIBLE, msg);
|
|
506 yd->current_status = YAHOO_STATUS_INVISIBLE;
|
|
507 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) {
|
|
508 if (gc->is_idle) {
|
|
509 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL);
|
|
510 yd->current_status = YAHOO_STATUS_IDLE;
|
|
511 } else {
|
|
512 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL);
|
|
513 yd->current_status = YAHOO_STATUS_AVAILABLE;
|
|
514 }
|
|
515 gc->away = NULL;
|
|
516 }
|
|
517 } else if (gc->is_idle) {
|
|
518 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL);
|
|
519 yd->current_status = YAHOO_STATUS_IDLE;
|
|
520 } else {
|
|
521 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL);
|
|
522 yd->current_status = YAHOO_STATUS_AVAILABLE;
|
|
523 }
|
|
524 }
|
|
525
|
|
526 static void yahoo_set_idle(struct gaim_connection *gc, int idle) {
|
|
527 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
528
|
|
529 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) {
|
|
530 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL);
|
|
531 yd->current_status = YAHOO_STATUS_IDLE;
|
|
532 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) {
|
|
533 yahoo_back(yd->sess, YAHOO_STATUS_AVAILABLE, NULL);
|
|
534 yd->current_status = YAHOO_STATUS_AVAILABLE;
|
|
535 }
|
|
536 }
|
|
537
|
|
538 static void yahoo_keepalive(struct gaim_connection *gc) {
|
|
539 yahoo_ping(((struct yahoo_data *)gc->proto_data)->sess);
|
|
540 }
|
|
541
|
|
542 static void gyahoo_add_buddy(struct gaim_connection *gc, char *name) {
|
|
543 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
544 struct yahoo_group *tmpgroup;
|
|
545 struct group *g = find_group_by_buddy(gc, name);
|
|
546 char *group = NULL;
|
|
547
|
|
548 if (!yd->logged_in)
|
|
549 return;
|
|
550
|
|
551 if (g) {
|
|
552 group = g->name;
|
|
553 } else if (yd->sess && yd->sess->groups) {
|
|
554 tmpgroup = yd->sess->groups->data;
|
|
555 group = tmpgroup->name;
|
|
556 } else {
|
|
557 group = "Buddies";
|
|
558 }
|
|
559
|
|
560 if (group)
|
|
561 yahoo_add_buddy(yd->sess, yd->active_id, group, name, "");
|
|
562 }
|
|
563
|
|
564 static void yahoo_add_buddies(struct gaim_connection *gc, GList *buddies) {
|
|
565 while (buddies) {
|
|
566 gyahoo_add_buddy(gc, buddies->data);
|
|
567 buddies = buddies->next;
|
|
568 }
|
|
569 }
|
|
570
|
|
571 static void gyahoo_remove_buddy(struct gaim_connection *gc, char *name) {
|
|
572 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
573 struct group *g = find_group_by_buddy(gc, name);
|
|
574 char *group = NULL;
|
|
575
|
|
576 if (g) {
|
|
577 group = g->name;
|
|
578 } else if (yd->sess && yd->sess->groups) {
|
|
579 GList *x = yd->sess->groups;
|
|
580 while (x) {
|
|
581 struct yahoo_group *tmpgroup = x->data;
|
|
582 char **bds = tmpgroup->buddies;
|
|
583 while (*bds) {
|
|
584 if (!strcmp(*bds, name))
|
|
585 break;
|
|
586 bds++;
|
|
587 }
|
|
588 if (*bds) {
|
|
589 group = tmpgroup->name;
|
|
590 break;
|
|
591 }
|
|
592 x = x->next;
|
|
593 }
|
|
594 } else {
|
|
595 group = "Buddies";
|
|
596 }
|
|
597
|
|
598 if (group)
|
|
599 yahoo_remove_buddy(yd->sess, yd->active_id, group, name, "");
|
|
600 }
|
|
601
|
|
602 static char **yahoo_list_icon(int uc) {
|
|
603 if ((uc >> 5) == YAHOO_STATUS_IDLE)
|
|
604 return status_idle_xpm;
|
|
605 else if (uc == UC_NORMAL)
|
|
606 return status_here_xpm;
|
|
607 return status_away_xpm;
|
|
608 }
|
|
609
|
|
610 static char *yahoo_get_status_string(enum yahoo_status a) {
|
|
611 switch (a) {
|
|
612 case YAHOO_STATUS_BRB:
|
|
613 return "Be Right Back";
|
|
614 case YAHOO_STATUS_BUSY:
|
|
615 return "Busy";
|
|
616 case YAHOO_STATUS_NOTATHOME:
|
|
617 return "Not At Home";
|
|
618 case YAHOO_STATUS_NOTATDESK:
|
|
619 return "Not At Desk";
|
|
620 case YAHOO_STATUS_NOTINOFFICE:
|
|
621 return "Not In Office";
|
|
622 case YAHOO_STATUS_ONPHONE:
|
|
623 return "On Phone";
|
|
624 case YAHOO_STATUS_ONVACATION:
|
|
625 return "On Vacation";
|
|
626 case YAHOO_STATUS_OUTTOLUNCH:
|
|
627 return "Out To Lunch";
|
|
628 case YAHOO_STATUS_STEPPEDOUT:
|
|
629 return "Stepped Out";
|
|
630 default:
|
|
631 return NULL;
|
|
632 }
|
|
633 }
|
|
634
|
|
635 static void yahoo_buddy_menu(GtkWidget *menu, struct gaim_connection *gc, char *who) {
|
|
636 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data;
|
|
637 GtkWidget *button;
|
|
638 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is,
|
|
639 segfault and get the bug report. */
|
|
640 char buf[1024];
|
|
641
|
|
642 if (b->uc & UC_NORMAL)
|
|
643 return;
|
|
644
|
|
645 if ((b->uc >> 5) != YAHOO_STATUS_CUSTOM)
|
|
646 g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 5));
|
|
647 else
|
|
648 g_snprintf(buf, sizeof buf, "Custom Status: %s",
|
|
649 (char *)g_hash_table_lookup(yd->hash, b->name));
|
|
650 button = gtk_menu_item_new_with_label(buf);
|
|
651 gtk_menu_append(GTK_MENU(menu), button);
|
|
652 gtk_widget_show(button);
|
|
653 }
|
|
654
|
|
655 static GList *yahoo_away_states() {
|
|
656 GList *m = NULL;
|
|
657
|
|
658 m = g_list_append(m, "Available");
|
|
659 m = g_list_append(m, "Be Right Back");
|
|
660 m = g_list_append(m, "Busy");
|
|
661 m = g_list_append(m, "Not At Home");
|
|
662 m = g_list_append(m, "Not At Desk");
|
|
663 m = g_list_append(m, "Not In Office");
|
|
664 m = g_list_append(m, "On Phone");
|
|
665 m = g_list_append(m, "On Vacation");
|
|
666 m = g_list_append(m, "Out To Lunch");
|
|
667 m = g_list_append(m, "Stepped Out");
|
|
668 m = g_list_append(m, "Invisible");
|
|
669 m = g_list_append(m, GAIM_AWAY_CUSTOM);
|
|
670
|
|
671 return m;
|
|
672 }
|
|
673
|
|
674 static void yahoo_act_id(gpointer data, char *entry) {
|
|
675 struct gaim_connection *gc = data;
|
|
676 struct yahoo_data *yd = gc->proto_data;
|
|
677
|
|
678 yahoo_activate_id(yd->sess, entry);
|
|
679 if (yd->active_id)
|
|
680 g_free(yd->active_id);
|
|
681 yd->active_id = g_strdup(entry);
|
|
682 }
|
|
683
|
|
684 static void yahoo_do_action(struct gaim_connection *gc, char *act) {
|
|
685 if (!strcmp(act, "Activate ID")) {
|
|
686 do_prompt_dialog("Activate which ID:", gc, yahoo_act_id, NULL);
|
|
687 }
|
|
688 }
|
|
689
|
|
690 static GList *yahoo_actions() {
|
|
691 GList *m = NULL;
|
|
692
|
|
693 m = g_list_append(m, "Activate ID");
|
|
694
|
|
695 return m;
|
|
696 }
|
|
697
|
|
698 struct mod_usr_opt {
|
|
699 struct aim_user *user;
|
|
700 int opt;
|
|
701 };
|
|
702
|
|
703 static void mod_opt(GtkWidget *b, struct mod_usr_opt *m)
|
|
704 {
|
|
705 if (m->user->proto_opt[m->opt][0] == '1')
|
|
706 m->user->proto_opt[m->opt][0] = '\0';
|
|
707 else
|
|
708 strcpy(m->user->proto_opt[m->opt],"1");
|
|
709 }
|
|
710
|
|
711 static void free_muo(GtkWidget *b, struct mod_usr_opt *m)
|
|
712 {
|
|
713 g_free(m);
|
|
714 }
|
|
715
|
|
716 static GtkWidget *yahoo_protoopt_button(const char *text, struct aim_user *u, int option, GtkWidget *box)
|
|
717 {
|
|
718 GtkWidget *button;
|
|
719 struct mod_usr_opt *muo = g_new0(struct mod_usr_opt, 1);
|
|
720 button = gtk_check_button_new_with_label(text);
|
|
721 gtk_toggle_button_set_state(GTK_TOGGLE_BUTTON(button), (u->proto_opt[option][0] == '1'));
|
|
722 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
|
|
723 muo->user = u;
|
|
724 muo->opt = option;
|
|
725 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(mod_opt), muo);
|
|
726 gtk_signal_connect(GTK_OBJECT(button), "destroy", GTK_SIGNAL_FUNC(free_muo), muo);
|
|
727 gtk_widget_show(button);
|
|
728 return button;
|
|
729 }
|
|
730
|
|
731 static void yahoo_print_option(GtkEntry *entry, struct aim_user *user) {
|
|
732 int entrynum;
|
|
733
|
|
734 entrynum = (int) gtk_object_get_user_data(GTK_OBJECT(entry));
|
|
735
|
|
736 if (entrynum == USEROPT_AUTHHOST) {
|
|
737 g_snprintf(user->proto_opt[USEROPT_AUTHHOST],
|
|
738 sizeof(user->proto_opt[USEROPT_AUTHHOST]),
|
|
739 "%s", gtk_entry_get_text(entry));
|
|
740 } else if (entrynum == USEROPT_AUTHPORT) {
|
|
741 g_snprintf(user->proto_opt[USEROPT_AUTHPORT],
|
|
742 sizeof(user->proto_opt[USEROPT_AUTHPORT]),
|
|
743 "%s", gtk_entry_get_text(entry));
|
|
744 } else if (entrynum == USEROPT_PAGERHOST) {
|
|
745 g_snprintf(user->proto_opt[USEROPT_PAGERHOST],
|
|
746 sizeof(user->proto_opt[USEROPT_PAGERHOST]),
|
|
747 "%s", gtk_entry_get_text(entry));
|
|
748 } else if (entrynum == USEROPT_PAGERPORT) {
|
|
749 g_snprintf(user->proto_opt[USEROPT_PAGERPORT],
|
|
750 sizeof(user->proto_opt[USEROPT_PAGERPORT]),
|
|
751 "%s", gtk_entry_get_text(entry));
|
|
752 }
|
|
753 }
|
|
754
|
|
755 static void yahoo_user_opts(GtkWidget *book, struct aim_user *user)
|
|
756 {
|
|
757 GtkWidget *vbox;
|
|
758 GtkWidget *hbox;
|
|
759 GtkWidget *label;
|
|
760 GtkWidget *entry;
|
|
761
|
|
762 vbox = gtk_vbox_new(FALSE, 5);
|
|
763 gtk_container_set_border_width(GTK_CONTAINER(vbox), 5);
|
|
764 gtk_notebook_append_page(GTK_NOTEBOOK(book), vbox, gtk_label_new("Yahoo Options"));
|
|
765 gtk_widget_show(vbox);
|
|
766
|
|
767 yahoo_protoopt_button("Notify me of new Yahoo! Mail", user, USEROPT_MAIL, vbox);
|
|
768 hbox = gtk_hbox_new(FALSE, 5);
|
|
769 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
770 gtk_widget_show(hbox);
|
|
771
|
|
772 label = gtk_label_new("Yahoo Auth Host:");
|
|
773 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
774 gtk_widget_show(label);
|
|
775
|
|
776 entry = gtk_entry_new();
|
|
777 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
778 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_AUTHHOST);
|
|
779 gtk_signal_connect(GTK_OBJECT(entry), "changed",
|
|
780 GTK_SIGNAL_FUNC(yahoo_print_option), user);
|
|
781 if (user->proto_opt[USEROPT_AUTHHOST][0]) {
|
|
782 debug_printf("setting text %s\n", user->proto_opt[USEROPT_AUTHHOST]);
|
|
783 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTHHOST]);
|
|
784 } else {
|
|
785 gtk_entry_set_text(GTK_ENTRY(entry), YAHOO_AUTH_HOST);
|
|
786 }
|
|
787 gtk_widget_show(entry);
|
|
788
|
|
789 hbox = gtk_hbox_new(FALSE, 5);
|
|
790 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
791 gtk_widget_show(hbox);
|
|
792
|
|
793 label = gtk_label_new("Yahoo Auth Port:");
|
|
794 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
795 gtk_widget_show(label);
|
|
796
|
|
797 entry = gtk_entry_new();
|
|
798 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
799 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_AUTHPORT);
|
|
800 gtk_signal_connect(GTK_OBJECT(entry), "changed",
|
|
801 GTK_SIGNAL_FUNC(yahoo_print_option), user);
|
|
802 if (user->proto_opt[USEROPT_AUTHPORT][0]) {
|
|
803 debug_printf("setting text %s\n", user->proto_opt[USEROPT_AUTHPORT]);
|
|
804 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTHPORT]);
|
|
805 } else {
|
|
806 g_snprintf(user->proto_opt[USEROPT_AUTHPORT], sizeof(user->proto_opt[USEROPT_AUTHPORT]),
|
|
807 "%d", YAHOO_AUTH_PORT);
|
|
808 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_AUTHPORT]);
|
|
809 }
|
|
810 gtk_widget_show(entry);
|
|
811
|
|
812 hbox = gtk_hbox_new(FALSE, 5);
|
|
813 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
814 gtk_widget_show(hbox);
|
|
815
|
|
816 label = gtk_label_new("Yahoo Pager Host:");
|
|
817 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
818 gtk_widget_show(label);
|
|
819
|
|
820 entry = gtk_entry_new();
|
|
821 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
822 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PAGERHOST);
|
|
823 gtk_signal_connect(GTK_OBJECT(entry), "changed",
|
|
824 GTK_SIGNAL_FUNC(yahoo_print_option), user);
|
|
825 if (user->proto_opt[USEROPT_PAGERHOST][0]) {
|
|
826 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PAGERHOST]);
|
|
827 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PAGERHOST]);
|
|
828 } else {
|
|
829 gtk_entry_set_text(GTK_ENTRY(entry), YAHOO_PAGER_HOST);
|
|
830 }
|
|
831 gtk_widget_show(entry);
|
|
832
|
|
833 hbox = gtk_hbox_new(FALSE, 5);
|
|
834 gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 0);
|
|
835 gtk_widget_show(hbox);
|
|
836
|
|
837 label = gtk_label_new("Yahoo Pager Port:");
|
|
838 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
|
|
839 gtk_widget_show(label);
|
|
840
|
|
841 entry = gtk_entry_new();
|
|
842 gtk_box_pack_end(GTK_BOX(hbox), entry, FALSE, FALSE, 0);
|
|
843 gtk_object_set_user_data(GTK_OBJECT(entry), (void *)USEROPT_PAGERPORT);
|
|
844 gtk_signal_connect(GTK_OBJECT(entry), "changed",
|
|
845 GTK_SIGNAL_FUNC(yahoo_print_option), user);
|
|
846 if (user->proto_opt[USEROPT_PAGERPORT][0]) {
|
|
847 debug_printf("setting text %s\n", user->proto_opt[USEROPT_PAGERPORT]);
|
|
848 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PAGERPORT]);
|
|
849 } else {
|
|
850 g_snprintf(user->proto_opt[USEROPT_PAGERPORT], sizeof(user->proto_opt[USEROPT_PAGERPORT]),
|
|
851 "%d", YAHOO_PAGER_PORT);
|
|
852 gtk_entry_set_text(GTK_ENTRY(entry), user->proto_opt[USEROPT_PAGERPORT]);
|
|
853 }
|
|
854 gtk_widget_show(entry);
|
|
855 }
|
|
856
|
|
857 static void toggle_offline(GtkToggleButton *button, struct conversation *c)
|
|
858 {
|
|
859 struct gaim_connection *gc = gtk_object_get_user_data(GTK_OBJECT(button));
|
|
860 struct yahoo_data *yd = gc->proto_data;
|
|
861 GSList *l = yd->offline;
|
|
862
|
|
863 while (l) {
|
|
864 if (!strcmp(c->name, l->data))
|
|
865 break;
|
|
866 l = l->next;
|
|
867 }
|
|
868 if (l) {
|
|
869 g_free(l->data);
|
|
870 yd->offline = g_slist_remove(yd->offline, l->data);
|
|
871 } else
|
|
872 yd->offline = g_slist_append(yd->offline, g_strdup(c->name));
|
|
873 }
|
|
874
|
|
875 static void yahoo_insert_convo(struct gaim_connection *gc, struct conversation *c)
|
|
876 {
|
|
877 GtkWidget *button;
|
|
878 struct yahoo_data *yd = gc->proto_data;
|
|
879 GSList *l = yd->offline;
|
|
880 struct buddy *b = find_buddy(gc, c->name);
|
|
881
|
|
882 button = gtk_check_button_new_with_label("Send offline message");
|
|
883 gtk_box_pack_start(GTK_BOX(c->lbox), button, FALSE, FALSE, 5);
|
|
884 gtk_signal_connect(GTK_OBJECT(button), "clicked", GTK_SIGNAL_FUNC(toggle_offline), c);
|
|
885 gtk_object_set_user_data(GTK_OBJECT(button), gc);
|
|
886 while (l) {
|
|
887 if (!strcmp(c->name, l->data))
|
|
888 break;
|
|
889 l = l->next;
|
|
890 }
|
|
891 if (l || (b && !b->present))
|
|
892 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
|
|
893 gtk_widget_show(button);
|
|
894 }
|
|
895
|
|
896 static void yahoo_remove_convo(struct gaim_connection *gc, struct conversation *c)
|
|
897 {
|
|
898 while (GTK_BOX(c->lbox)->children)
|
|
899 gtk_container_remove(GTK_CONTAINER(c->lbox),
|
|
900 ((GtkBoxChild *)GTK_BOX(c->lbox)->children->data)->widget);
|
|
901 }
|
|
902
|
|
903 static struct prpl *my_protocol = NULL;
|
|
904
|
|
905 void yahoo_init(struct prpl *ret) {
|
|
906 /* the NULL's aren't required but they're nice to have */
|
|
907 ret->protocol = PROTO_YAHOO;
|
|
908 ret->name = yahoo_name;
|
|
909 ret->list_icon = yahoo_list_icon;
|
|
910 ret->away_states = yahoo_away_states;
|
|
911 ret->actions = yahoo_actions;
|
|
912 ret->do_action = yahoo_do_action;
|
|
913 ret->buddy_menu = yahoo_buddy_menu;
|
|
914 ret->user_opts = yahoo_user_opts;
|
|
915 ret->insert_convo = yahoo_insert_convo;
|
|
916 ret->remove_convo = yahoo_remove_convo;
|
|
917 ret->login = yahoo_login;
|
|
918 ret->close = yahoo_close;
|
|
919 ret->send_im = yahoo_send_im;
|
|
920 ret->set_info = NULL;
|
|
921 ret->get_info = NULL;
|
|
922 ret->set_away = yahoo_set_away;
|
|
923 ret->get_away_msg = NULL;
|
|
924 ret->set_dir = NULL;
|
|
925 ret->get_dir = NULL;
|
|
926 ret->dir_search = NULL;
|
|
927 ret->set_idle = yahoo_set_idle;
|
|
928 ret->change_passwd = NULL;
|
|
929 ret->add_buddy = gyahoo_add_buddy;
|
|
930 ret->add_buddies = yahoo_add_buddies;
|
|
931 ret->remove_buddy = gyahoo_remove_buddy;
|
|
932 ret->add_permit = NULL;
|
|
933 ret->add_deny = NULL;
|
|
934 ret->rem_permit = NULL;
|
|
935 ret->rem_deny = NULL;
|
|
936 ret->set_permit_deny = NULL;
|
|
937 ret->warn = NULL;
|
|
938 ret->accept_chat = NULL;
|
|
939 ret->join_chat = NULL;
|
|
940 ret->chat_invite = NULL;
|
|
941 ret->chat_leave = NULL;
|
|
942 ret->chat_whisper = NULL;
|
|
943 ret->chat_send = NULL;
|
|
944 ret->keepalive = yahoo_keepalive;
|
|
945
|
|
946 my_protocol = ret;
|
|
947
|
|
948 yahoo_socket_notify = yahoo_notify;
|
|
949 yahoo_print = yahoo_debug;
|
|
950 yahoo_connector = yahoo_connect_to;
|
|
951 }
|
|
952
|
|
953 #ifndef STATIC
|
|
954
|
|
955 char *gaim_plugin_init(GModule *handle)
|
|
956 {
|
|
957 load_protocol(yahoo_init, sizeof(struct prpl));
|
|
958 return NULL;
|
|
959 }
|
|
960
|
|
961 void gaim_plugin_remove()
|
|
962 {
|
|
963 struct prpl *p = find_prpl(PROTO_YAHOO);
|
|
964 if (p == my_protocol)
|
|
965 unload_protocol(p);
|
|
966 }
|
|
967
|
|
968 char *name()
|
|
969 {
|
|
970 return "Yahoo";
|
|
971 }
|
|
972
|
|
973 char *description()
|
|
974 {
|
|
975 return "Allows gaim to use the Yahoo protocol";
|
|
976 }
|
|
977
|
|
978 #endif
|