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