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