Mercurial > pidgin.yaz
annotate src/protocols/yahoo/yay.c @ 2639:4d6a767133e1
[gaim-migrate @ 2652]
hi.
committer: Tailor Script <tailor@pidgin.im>
author | Eric Warmenhoven <eric@warmenhoven.org> |
---|---|
date | Wed, 31 Oct 2001 09:18:11 +0000 |
parents | 8c75e59e4bdf |
children | 511d2af5bcca |
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 | |
2635
8c75e59e4bdf
[gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2582
diff
changeset
|
161 strip_linefeed(buf); |
2086 | 162 serv_got_im(gc, nick, buf, 0, tm ? tm : time((time_t)NULL)); |
163 | |
164 return 1; | |
165 } | |
166 | |
167 static int yahoo_bounce(struct yahoo_session *sess, ...) { | |
168 do_error_dialog(_("Your message did not get sent."), _("Gaim - Error")); | |
169 | |
170 return 1; | |
171 } | |
172 | |
173 static int yahoo_buddyadded(struct yahoo_session *sess, ...) { | |
174 va_list ap; | |
175 char *id; | |
176 char *who; | |
177 char *msg; | |
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 | |
2582
5efa8077107f
[gaim-migrate @ 2595]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2541
diff
changeset
|
185 show_got_added(sess->user_data, id, who, NULL, msg); |
2086 | 186 |
187 return 1; | |
188 } | |
189 | |
190 static int yahoo_newmail(struct yahoo_session *sess, ...) { | |
191 struct gaim_connection *gc = sess->user_data; | |
192 | |
193 va_list ap; | |
194 int count; | |
195 | |
196 va_start(ap, sess); | |
197 count = va_arg(ap, int); | |
198 va_end(ap); | |
199 | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2509
diff
changeset
|
200 connection_has_mail(gc, count, NULL, NULL, "http://mail.yahoo.com/"); |
2086 | 201 |
202 return 1; | |
203 } | |
204 | |
205 static int yahoo_disconn(struct yahoo_session *sess, ...) { | |
206 struct gaim_connection *gc = sess->user_data; | |
207 hide_login_progress(gc, "Disconnected"); | |
208 signoff(gc); | |
209 return 1; | |
210 } | |
211 | |
212 static int yahoo_authconnect(struct yahoo_session *sess, ...) { | |
213 struct gaim_connection *gc = sess->user_data; | |
214 | |
215 set_login_progress(gc, 2, "Connected to Auth"); | |
216 if (yahoo_send_login(sess, gc->username, gc->password) < 1) { | |
217 hide_login_progress(gc, "Authorizer error"); | |
218 signoff(gc); | |
2145
91223be78b70
[gaim-migrate @ 2155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
219 return 0; |
2086 | 220 } |
221 | |
222 return 1; | |
223 } | |
224 | |
225 static int yahoo_badpassword(struct yahoo_session *sess, ...) { | |
226 struct gaim_connection *gc = sess->user_data; | |
227 hide_login_progress(gc, "Bad Password"); | |
228 signoff(gc); | |
229 return 1; | |
230 } | |
231 | |
232 static int yahoo_logincookie(struct yahoo_session *sess, ...) { | |
233 struct gaim_connection *gc = sess->user_data; | |
234 | |
235 set_login_progress(gc, 3, "Got login cookie"); | |
236 if (yahoo_major_connect(sess, gc->user->proto_opt[USEROPT_PAGERHOST], | |
237 atoi(gc->user->proto_opt[USEROPT_PAGERPORT])) < 1) { | |
238 hide_login_progress(gc, "Login error"); | |
239 signoff(gc); | |
240 } | |
241 | |
242 return 1; | |
243 } | |
244 | |
245 static int yahoo_mainconnect(struct yahoo_session *sess, ...) { | |
246 struct gaim_connection *gc = sess->user_data; | |
247 struct yahoo_data *yd = gc->proto_data; | |
248 GList *grps; | |
249 | |
250 set_login_progress(gc, 4, "Connected to service"); | |
251 if (yahoo_finish_logon(sess, YAHOO_STATUS_AVAILABLE) < 1) { | |
252 hide_login_progress(gc, "Login error"); | |
253 signoff(gc); | |
2145
91223be78b70
[gaim-migrate @ 2155]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2123
diff
changeset
|
254 return 0; |
2086 | 255 } |
256 | |
257 if (bud_list_cache_exists(gc)) | |
2382
569ae9f2bb89
[gaim-migrate @ 2395]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2309
diff
changeset
|
258 do_import(gc, NULL); |
2086 | 259 |
260 grps = yd->sess->groups; | |
261 while (grps) { | |
262 struct yahoo_group *grp = grps->data; | |
263 int i; | |
264 | |
265 for (i = 0; grp->buddies[i]; i++) | |
266 add_buddy(gc, grp->name, grp->buddies[i], NULL); | |
267 | |
268 grps = grps->next; | |
269 } | |
270 | |
271 return 1; | |
272 } | |
273 | |
274 static int yahoo_online(struct yahoo_session *sess, ...) { | |
275 struct gaim_connection *gc = sess->user_data; | |
276 struct yahoo_data *yd = gc->proto_data; | |
277 | |
278 account_online(gc); | |
279 serv_finish_login(gc); | |
2635
8c75e59e4bdf
[gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2582
diff
changeset
|
280 if (yd->active_id) |
8c75e59e4bdf
[gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2582
diff
changeset
|
281 g_free(yd->active_id); |
2086 | 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); | |
2635
8c75e59e4bdf
[gaim-migrate @ 2648]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2582
diff
changeset
|
403 g_free(yd->active_id); |
2086 | 404 g_free(yd); |
405 } | |
406 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
407 static int yahoo_send_im(struct gaim_connection *gc, char *who, char *message, int flags) { |
2086 | 408 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
409 | |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
410 if ((flags & IM_FLAG_AWAY)|| !strlen(message)) return 0; |
2086 | 411 |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
412 if (flags & IM_FLAG_CHECKBOX) |
2491
75c62304c489
[gaim-migrate @ 2504]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
413 yahoo_send_message_offline(yd->sess, yd->active_id, who, message); |
2086 | 414 else |
2491
75c62304c489
[gaim-migrate @ 2504]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2382
diff
changeset
|
415 yahoo_send_message(yd->sess, yd->active_id, who, message); |
2303
f5bf315e6104
[gaim-migrate @ 2313]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2234
diff
changeset
|
416 return 1; |
2086 | 417 } |
418 | |
419 static void yahoo_set_away(struct gaim_connection *gc, char *state, char *msg) { | |
420 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
421 | |
422 gc->away = NULL; | |
423 | |
424 if (msg) { | |
425 yahoo_away(yd->sess, YAHOO_STATUS_CUSTOM, msg); | |
426 yd->current_status = YAHOO_STATUS_CUSTOM; | |
427 gc->away = ""; | |
428 } else if (state) { | |
429 gc->away = ""; | |
430 if (!strcmp(state, "Available")) { | |
431 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, msg); | |
432 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
433 } else if (!strcmp(state, "Be Right Back")) { | |
434 yahoo_away(yd->sess, YAHOO_STATUS_BRB, msg); | |
435 yd->current_status = YAHOO_STATUS_BRB; | |
436 } else if (!strcmp(state, "Busy")) { | |
437 yahoo_away(yd->sess, YAHOO_STATUS_BUSY, msg); | |
438 yd->current_status = YAHOO_STATUS_BUSY; | |
439 } else if (!strcmp(state, "Not At Home")) { | |
440 yahoo_away(yd->sess, YAHOO_STATUS_NOTATHOME, msg); | |
441 yd->current_status = YAHOO_STATUS_NOTATHOME; | |
442 } else if (!strcmp(state, "Not At Desk")) { | |
443 yahoo_away(yd->sess, YAHOO_STATUS_NOTATDESK, msg); | |
444 yd->current_status = YAHOO_STATUS_NOTATDESK; | |
445 } else if (!strcmp(state, "Not In Office")) { | |
446 yahoo_away(yd->sess, YAHOO_STATUS_NOTINOFFICE, msg); | |
447 yd->current_status = YAHOO_STATUS_NOTINOFFICE; | |
448 } else if (!strcmp(state, "On Phone")) { | |
449 yahoo_away(yd->sess, YAHOO_STATUS_ONPHONE, msg); | |
450 yd->current_status = YAHOO_STATUS_ONPHONE; | |
451 } else if (!strcmp(state, "On Vacation")) { | |
452 yahoo_away(yd->sess, YAHOO_STATUS_ONVACATION, msg); | |
453 yd->current_status = YAHOO_STATUS_ONVACATION; | |
454 } else if (!strcmp(state, "Out To Lunch")) { | |
455 yahoo_away(yd->sess, YAHOO_STATUS_OUTTOLUNCH, msg); | |
456 yd->current_status = YAHOO_STATUS_OUTTOLUNCH; | |
457 } else if (!strcmp(state, "Stepped Out")) { | |
458 yahoo_away(yd->sess, YAHOO_STATUS_STEPPEDOUT, msg); | |
459 yd->current_status = YAHOO_STATUS_STEPPEDOUT; | |
460 } else if (!strcmp(state, "Invisible")) { | |
461 yahoo_away(yd->sess, YAHOO_STATUS_INVISIBLE, msg); | |
462 yd->current_status = YAHOO_STATUS_INVISIBLE; | |
463 } else if (!strcmp(state, GAIM_AWAY_CUSTOM)) { | |
464 if (gc->is_idle) { | |
465 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
466 yd->current_status = YAHOO_STATUS_IDLE; | |
467 } else { | |
468 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
469 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
470 } | |
471 gc->away = NULL; | |
472 } | |
473 } else if (gc->is_idle) { | |
474 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
475 yd->current_status = YAHOO_STATUS_IDLE; | |
476 } else { | |
477 yahoo_away(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
478 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
479 } | |
480 } | |
481 | |
482 static void yahoo_set_idle(struct gaim_connection *gc, int idle) { | |
483 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
484 | |
485 if (idle && yd->current_status == YAHOO_STATUS_AVAILABLE) { | |
486 yahoo_away(yd->sess, YAHOO_STATUS_IDLE, NULL); | |
487 yd->current_status = YAHOO_STATUS_IDLE; | |
488 } else if (!idle && yd->current_status == YAHOO_STATUS_IDLE) { | |
489 yahoo_back(yd->sess, YAHOO_STATUS_AVAILABLE, NULL); | |
490 yd->current_status = YAHOO_STATUS_AVAILABLE; | |
491 } | |
492 } | |
493 | |
494 static void yahoo_keepalive(struct gaim_connection *gc) { | |
495 yahoo_ping(((struct yahoo_data *)gc->proto_data)->sess); | |
496 } | |
497 | |
498 static void gyahoo_add_buddy(struct gaim_connection *gc, char *name) { | |
499 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
500 struct yahoo_group *tmpgroup; | |
501 struct group *g = find_group_by_buddy(gc, name); | |
502 char *group = NULL; | |
503 | |
504 if (!yd->logged_in) | |
505 return; | |
506 | |
507 if (g) { | |
508 group = g->name; | |
509 } else if (yd->sess && yd->sess->groups) { | |
510 tmpgroup = yd->sess->groups->data; | |
511 group = tmpgroup->name; | |
512 } else { | |
513 group = "Buddies"; | |
514 } | |
515 | |
516 if (group) | |
517 yahoo_add_buddy(yd->sess, yd->active_id, group, name, ""); | |
518 } | |
519 | |
520 static void yahoo_add_buddies(struct gaim_connection *gc, GList *buddies) { | |
521 while (buddies) { | |
522 gyahoo_add_buddy(gc, buddies->data); | |
523 buddies = buddies->next; | |
524 } | |
525 } | |
526 | |
527 static void gyahoo_remove_buddy(struct gaim_connection *gc, char *name) { | |
528 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; | |
529 struct group *g = find_group_by_buddy(gc, name); | |
530 char *group = NULL; | |
531 | |
532 if (g) { | |
533 group = g->name; | |
534 } else if (yd->sess && yd->sess->groups) { | |
535 GList *x = yd->sess->groups; | |
536 while (x) { | |
537 struct yahoo_group *tmpgroup = x->data; | |
538 char **bds = tmpgroup->buddies; | |
539 while (*bds) { | |
540 if (!strcmp(*bds, name)) | |
541 break; | |
542 bds++; | |
543 } | |
544 if (*bds) { | |
545 group = tmpgroup->name; | |
546 break; | |
547 } | |
548 x = x->next; | |
549 } | |
550 } else { | |
551 group = "Buddies"; | |
552 } | |
553 | |
554 if (group) | |
555 yahoo_remove_buddy(yd->sess, yd->active_id, group, name, ""); | |
556 } | |
557 | |
558 static char **yahoo_list_icon(int uc) { | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2491
diff
changeset
|
559 if ((uc >> 1) == YAHOO_STATUS_IDLE) |
2086 | 560 return status_idle_xpm; |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2491
diff
changeset
|
561 else if (uc == 0) |
2086 | 562 return status_here_xpm; |
563 return status_away_xpm; | |
564 } | |
565 | |
566 static char *yahoo_get_status_string(enum yahoo_status a) { | |
567 switch (a) { | |
568 case YAHOO_STATUS_BRB: | |
569 return "Be Right Back"; | |
570 case YAHOO_STATUS_BUSY: | |
571 return "Busy"; | |
572 case YAHOO_STATUS_NOTATHOME: | |
573 return "Not At Home"; | |
574 case YAHOO_STATUS_NOTATDESK: | |
575 return "Not At Desk"; | |
576 case YAHOO_STATUS_NOTINOFFICE: | |
577 return "Not In Office"; | |
578 case YAHOO_STATUS_ONPHONE: | |
579 return "On Phone"; | |
580 case YAHOO_STATUS_ONVACATION: | |
581 return "On Vacation"; | |
582 case YAHOO_STATUS_OUTTOLUNCH: | |
583 return "Out To Lunch"; | |
584 case YAHOO_STATUS_STEPPEDOUT: | |
585 return "Stepped Out"; | |
586 default: | |
587 return NULL; | |
588 } | |
589 } | |
590 | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
591 static GList *yahoo_buddy_menu(struct gaim_connection *gc, char *who) { |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
592 GList *m = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
593 struct proto_buddy_menu *pbm; |
2086 | 594 struct yahoo_data *yd = (struct yahoo_data *)gc->proto_data; |
595 struct buddy *b = find_buddy(gc, who); /* this should never be null. if it is, | |
596 segfault and get the bug report. */ | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
597 static char buf[1024]; |
2086 | 598 |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2491
diff
changeset
|
599 if (!(b->uc & UC_UNAVAILABLE)) |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
600 return NULL; |
2086 | 601 |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
602 pbm = g_new0(struct proto_buddy_menu, 1); |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2491
diff
changeset
|
603 if ((b->uc >> 1) != YAHOO_STATUS_CUSTOM) |
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2491
diff
changeset
|
604 g_snprintf(buf, sizeof buf, "Status: %s", yahoo_get_status_string(b->uc >> 1)); |
2086 | 605 else |
606 g_snprintf(buf, sizeof buf, "Custom Status: %s", | |
607 (char *)g_hash_table_lookup(yd->hash, b->name)); | |
2170
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
608 pbm->label = buf; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
609 pbm->callback = NULL; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
610 pbm->gc = gc; |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
611 m = g_list_append(m, pbm); |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
612 |
c24595d3c364
[gaim-migrate @ 2180]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2162
diff
changeset
|
613 return m; |
2086 | 614 } |
615 | |
2501
227cc42ffa6e
[gaim-migrate @ 2514]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2491
diff
changeset
|
616 static GList *yahoo_away_states(struct gaim_connection *gc) { |
2086 | 617 GList *m = NULL; |
618 | |
619 m = g_list_append(m, "Available"); | |
620 m = g_list_append(m, "Be Right Back"); | |
621 m = g_list_append(m, "Busy"); | |
622 m = g_list_append(m, "Not At Home"); | |
623 m = g_list_append(m, "Not At Desk"); | |
624 m = g_list_append(m, "Not In Office"); | |
625 m = g_list_append(m, "On Phone"); | |
626 m = g_list_append(m, "On Vacation"); | |
627 m = g_list_append(m, "Out To Lunch"); | |
628 m = g_list_append(m, "Stepped Out"); | |
629 m = g_list_append(m, "Invisible"); | |
630 m = g_list_append(m, GAIM_AWAY_CUSTOM); | |
631 | |
632 return m; | |
633 } | |
634 | |
635 static void yahoo_act_id(gpointer data, char *entry) { | |
636 struct gaim_connection *gc = data; | |
637 struct yahoo_data *yd = gc->proto_data; | |
638 | |
639 yahoo_activate_id(yd->sess, entry); | |
640 if (yd->active_id) | |
641 g_free(yd->active_id); | |
642 yd->active_id = g_strdup(entry); | |
2210
3a6fd1e8f00a
[gaim-migrate @ 2220]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2205
diff
changeset
|
643 g_snprintf(gc->displayname, sizeof(gc->displayname), "%s", yd->active_id); |
2086 | 644 } |
645 | |
646 static void yahoo_do_action(struct gaim_connection *gc, char *act) { | |
647 if (!strcmp(act, "Activate ID")) { | |
2541
8229710b343b
[gaim-migrate @ 2554]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2509
diff
changeset
|
648 do_prompt_dialog("Activate which ID:", gc->displayname, gc, yahoo_act_id, NULL); |
2086 | 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 | |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
660 static GList *yahoo_user_opts() |
2086 | 661 { |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
662 GList *m = NULL; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
663 struct proto_user_opt *puo; |
2086 | 664 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
665 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
666 puo->label = "Auth Host:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
667 puo->def = YAHOO_AUTH_HOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
668 puo->pos = USEROPT_AUTHHOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
669 m = g_list_append(m, puo); |
2086 | 670 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
671 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
672 puo->label = "Auth Port:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
673 puo->def = "80"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
674 puo->pos = USEROPT_AUTHPORT; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
675 m = g_list_append(m, puo); |
2086 | 676 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
677 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
678 puo->label = "Pager Host:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
679 puo->def = YAHOO_PAGER_HOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
680 puo->pos = USEROPT_PAGERHOST; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
681 m = g_list_append(m, puo); |
2086 | 682 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
683 puo = g_new0(struct proto_user_opt, 1); |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
684 puo->label = "Pager Port:"; |
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
685 puo->def = "5050"; |
2201
bc53b057732f
[gaim-migrate @ 2211]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2170
diff
changeset
|
686 puo->pos = USEROPT_PAGERPORT; |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
687 m = g_list_append(m, puo); |
2086 | 688 |
2154
cff133e0ec0c
[gaim-migrate @ 2164]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2153
diff
changeset
|
689 return m; |
2086 | 690 } |
691 | |
692 static struct prpl *my_protocol = NULL; | |
693 | |
694 void yahoo_init(struct prpl *ret) { | |
695 /* the NULL's aren't required but they're nice to have */ | |
696 ret->protocol = PROTO_YAHOO; | |
2153
0befa2d2e540
[gaim-migrate @ 2163]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2145
diff
changeset
|
697 ret->options = OPT_PROTO_MAIL_CHECK; |
2231
8c4ff1a368bd
[gaim-migrate @ 2241]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2210
diff
changeset
|
698 ret->checkbox = _("Send offline message"); |
2086 | 699 ret->name = yahoo_name; |
700 ret->list_icon = yahoo_list_icon; | |
701 ret->away_states = yahoo_away_states; | |
702 ret->actions = yahoo_actions; | |
703 ret->do_action = yahoo_do_action; | |
704 ret->buddy_menu = yahoo_buddy_menu; | |
705 ret->user_opts = yahoo_user_opts; | |
706 ret->login = yahoo_login; | |
707 ret->close = yahoo_close; | |
708 ret->send_im = yahoo_send_im; | |
709 ret->set_info = NULL; | |
710 ret->get_info = NULL; | |
711 ret->set_away = yahoo_set_away; | |
712 ret->set_dir = NULL; | |
713 ret->get_dir = NULL; | |
714 ret->dir_search = NULL; | |
715 ret->set_idle = yahoo_set_idle; | |
716 ret->change_passwd = NULL; | |
717 ret->add_buddy = gyahoo_add_buddy; | |
718 ret->add_buddies = yahoo_add_buddies; | |
719 ret->remove_buddy = gyahoo_remove_buddy; | |
720 ret->add_permit = NULL; | |
721 ret->add_deny = NULL; | |
722 ret->rem_permit = NULL; | |
723 ret->rem_deny = NULL; | |
724 ret->set_permit_deny = NULL; | |
725 ret->warn = NULL; | |
726 ret->keepalive = yahoo_keepalive; | |
727 | |
728 my_protocol = ret; | |
729 | |
730 yahoo_socket_notify = yahoo_notify; | |
731 yahoo_print = yahoo_debug; | |
732 yahoo_connector = yahoo_connect_to; | |
733 } | |
734 | |
735 #ifndef STATIC | |
736 | |
737 char *gaim_plugin_init(GModule *handle) | |
738 { | |
739 load_protocol(yahoo_init, sizeof(struct prpl)); | |
740 return NULL; | |
741 } | |
742 | |
743 void gaim_plugin_remove() | |
744 { | |
745 struct prpl *p = find_prpl(PROTO_YAHOO); | |
746 if (p == my_protocol) | |
747 unload_protocol(p); | |
748 } | |
749 | |
750 char *name() | |
751 { | |
752 return "Yahoo"; | |
753 } | |
754 | |
755 char *description() | |
756 { | |
2162
a464da684307
[gaim-migrate @ 2172]
Eric Warmenhoven <eric@warmenhoven.org>
parents:
2154
diff
changeset
|
757 return PRPL_DESC("Yahoo"); |
2086 | 758 } |
759 | |
760 #endif |