📄 yahoochat.c
字号:
/* * purple * * Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * source distribution. * * Some code copyright 2003 Tim Ringenbach <omarvo@hotmail.com> * (marv on irc.freenode.net) * Some code borrowed from libyahoo2, copyright (C) 2002, Philip * S Tellis <philip . tellis AT gmx . net> * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * */#ifdef HAVE_CONFIG_H#include "config.h"#endif#include "debug.h"#include "privacy.h"#include "prpl.h"#include "conversation.h"#include "notify.h"#include "util.h"#include "internal.h"#include "yahoo.h"#include "yahoo_packet.h"#include "yahoochat.h"#include "ycht.h"#define YAHOO_CHAT_ID (1)/* prototype(s) */static void yahoo_chat_leave(PurpleConnection *gc, const char *room, const char *dn, gboolean logout);/* special function to log us on to the yahoo chat service */static void yahoo_chat_online(PurpleConnection *gc){ struct yahoo_data *yd = gc->proto_data; struct yahoo_packet *pkt; if (yd->wm) { ycht_connection_open(gc); return; } pkt = yahoo_packet_new(YAHOO_SERVICE_CHATONLINE, YAHOO_STATUS_AVAILABLE,0); yahoo_packet_hash(pkt, "sss", 1, purple_connection_get_display_name(gc), 109, purple_connection_get_display_name(gc), 6, "abcde"); yahoo_packet_send_and_free(pkt, yd);}/* this is slow, and different from the purple_* version in that it (hopefully) won't add a user twice */void yahoo_chat_add_users(PurpleConvChat *chat, GList *newusers){ GList *i; for (i = newusers; i; i = i->next) { if (purple_conv_chat_find_user(chat, i->data)) continue; purple_conv_chat_add_user(chat, i->data, NULL, PURPLE_CBFLAGS_NONE, TRUE); }}void yahoo_chat_add_user(PurpleConvChat *chat, const char *user, const char *reason){ if (purple_conv_chat_find_user(chat, user)) return; purple_conv_chat_add_user(chat, user, reason, PURPLE_CBFLAGS_NONE, TRUE);}static PurpleConversation *yahoo_find_conference(PurpleConnection *gc, const char *name){ struct yahoo_data *yd; GSList *l; yd = gc->proto_data; for (l = yd->confs; l; l = l->next) { PurpleConversation *c = l->data; if (!purple_utf8_strcasecmp(purple_conversation_get_name(c), name)) return c; } return NULL;}void yahoo_process_conference_invite(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; GString *members = NULL; GHashTable *components; if (pkt->status == 2) return; /* XXX */ members = g_string_sized_new(512); for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 1: /* us, but we already know who we are */ break; case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 50: /* inviter */ who = pair->value; g_string_append_printf(members, "%s\n", who); break; case 52: /* invitee (me) */ case 53: /* members */ g_string_append_printf(members, "%s\n", pair->value); break; case 58: msg = yahoo_string_decode(gc, pair->value, FALSE); break; case 13: /* ? */ break; } } if (!room) { g_string_free(members, TRUE); return; } components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); g_hash_table_replace(components, g_strdup("room"), room); if (msg) g_hash_table_replace(components, g_strdup("topic"), msg); g_hash_table_replace(components, g_strdup("type"), g_strdup("Conference")); if (members) { g_hash_table_replace(components, g_strdup("members"), g_strdup(members->str)); } if (!yahoo_privacy_check(gc, who) || (purple_account_get_bool(purple_connection_get_account(gc), "ignore_invites", FALSE))) { purple_debug_info("yahoo", "Invite to conference %s from %s has been dropped.\n", room, who); g_string_free(members, TRUE); return; } serv_got_chat_invite(gc, room, who, msg, components); g_string_free(members, TRUE);}void yahoo_process_conference_decline(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 54: who = pair->value; break; case 14: msg = yahoo_string_decode(gc, pair->value, FALSE); break; } } if (!yahoo_privacy_check(gc, who)) { g_free(room); if (msg != NULL) g_free(msg); return; } if (who && room) { /* make sure we're in the room before we process a decline message for it */ if(yahoo_find_conference(gc, room)) { char *tmp; tmp = g_strdup_printf(_("%s declined your conference invitation to room \"%s\" because \"%s\"."), who, room, msg?msg:""); purple_notify_info(gc, NULL, _("Invitation Rejected"), tmp); g_free(tmp); } g_free(room); if (msg) g_free(msg); }}void yahoo_process_conference_logon(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; PurpleConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 53: who = pair->value; break; } } if (who && room) { c = yahoo_find_conference(gc, room); if (c) yahoo_chat_add_user(PURPLE_CONV_CHAT(c), who, NULL); g_free(room); }}void yahoo_process_conference_logoff(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; PurpleConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 56: who = pair->value; break; } } if (who && room) { c = yahoo_find_conference(gc, room); if (c) purple_conv_chat_remove_user(PURPLE_CONV_CHAT(c), who, NULL); g_free(room); }}void yahoo_process_conference_message(PurpleConnection *gc, struct yahoo_packet *pkt){ GSList *l; char *room = NULL; char *who = NULL; char *msg = NULL; char *msg2; int utf8 = 0; PurpleConversation *c; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 57: room = yahoo_string_decode(gc, pair->value, FALSE); break; case 3: who = pair->value; break; case 14: msg = pair->value; break; case 97: utf8 = strtol(pair->value, NULL, 10); break; } } if (room && who && msg) { msg2 = yahoo_string_decode(gc, msg, utf8); c = yahoo_find_conference(gc, room); if (!c) return; msg = yahoo_codes_to_html(msg2); serv_got_chat_in(gc, purple_conv_chat_get_id(PURPLE_CONV_CHAT(c)), who, 0, msg, time(NULL)); g_free(msg); g_free(msg2); } if (room) g_free(room);}/* this is a confirmation of yahoo_chat_online(); */void yahoo_process_chat_online(PurpleConnection *gc, struct yahoo_packet *pkt){ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; if (pkt->status == 1) yd->chat_online = 1;}/* this is basicly the opposite of chat_online */void yahoo_process_chat_logout(PurpleConnection *gc, struct yahoo_packet *pkt){ struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; GSList *l; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; if (pair->key == 1) if (g_ascii_strcasecmp(pair->value, purple_connection_get_display_name(gc))) return; } if (pkt->status == 1) { yd->chat_online = 0; if (yd->in_chat) yahoo_c_leave(gc, YAHOO_CHAT_ID); }}void yahoo_process_chat_join(PurpleConnection *gc, struct yahoo_packet *pkt){ PurpleAccount *account = purple_connection_get_account(gc); struct yahoo_data *yd = (struct yahoo_data *) gc->proto_data; PurpleConversation *c = NULL; GSList *l; GList *members = NULL; GList *roomies = NULL; char *room = NULL; char *topic = NULL; char *someid, *someotherid, *somebase64orhashosomething, *somenegativenumber; if (pkt->status == -1) { /* We can't join */ struct yahoo_pair *pair = pkt->hash->data; gchar const *failed_to_join = _("Failed to join chat"); switch (atoi(pair->value)) { case 0xFFFFFFFA: /* -6 */ purple_notify_error(gc, NULL, failed_to_join, _("Unknown room")); break; case 0xFFFFFFF1: /* -15 */ purple_notify_error(gc, NULL, failed_to_join, _("Maybe the room is full")); break; case 0xFFFFFFDD: /* -35 */ purple_notify_error(gc, NULL, failed_to_join, _("Not available")); break; default: purple_notify_error(gc, NULL, failed_to_join, _("Unknown error. You may need to logout and wait five minutes before being able to rejoin a chatroom")); } return; } for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 104: room = yahoo_string_decode(gc, pair->value, TRUE); break; case 105: topic = yahoo_string_decode(gc, pair->value, TRUE); break; case 128: someid = pair->value; break; case 108: /* number of joiners */ break; case 129: someotherid = pair->value; break; case 130: somebase64orhashosomething = pair->value; break; case 126: somenegativenumber = pair->value; break; case 13: /* this is 1. maybe its the type of room? (normal, user created, private, etc?) */ break; case 61: /*this looks similar to 130 */ break; /* the previous section was just room info. this next section is info about individual room members, (including us) */ case 109: /* the yahoo id */ members = g_list_append(members, pair->value); break; case 110: /* age */ break; case 141: /* nickname */ break; case 142: /* location */ break; case 113: /* bitmask */ break; } } if (room && yd->chat_name && purple_utf8_strcasecmp(room, yd->chat_name)) yahoo_chat_leave(gc, room, purple_connection_get_display_name(gc), FALSE); c = purple_find_chat(gc, YAHOO_CHAT_ID); if (room && (!c || purple_conv_chat_has_left(PURPLE_CONV_CHAT(c))) && members && ((g_list_length(members) > 1) || !g_ascii_strcasecmp(members->data, purple_connection_get_display_name(gc)))) { int i; GList *flags = NULL; for (i = 0; i < g_list_length(members); i++) flags = g_list_append(flags, GINT_TO_POINTER(PURPLE_CBFLAGS_NONE)); if (c && purple_conv_chat_has_left(PURPLE_CONV_CHAT(c))) { /* this might be a hack, but oh well, it should nicely */ char *tmpmsg; purple_conversation_set_name(c, room); c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), NULL, topic); yd->in_chat = 1; yd->chat_name = g_strdup(room); purple_conv_chat_add_users(PURPLE_CONV_CHAT(c), members, NULL, flags, FALSE); tmpmsg = g_strdup_printf(_("You are now chatting in %s."), room); purple_conv_chat_write(PURPLE_CONV_CHAT(c), "", tmpmsg, PURPLE_MESSAGE_SYSTEM, time(NULL)); g_free(tmpmsg); } else { c = serv_got_joined_chat(gc, YAHOO_CHAT_ID, room); if (topic) purple_conv_chat_set_topic(PURPLE_CONV_CHAT(c), NULL, topic); yd->in_chat = 1; yd->chat_name = g_strdup(room); purple_conv_chat_add_users(PURPLE_CONV_CHAT(c), members, NULL, flags, FALSE); } g_list_free(flags); } else if (c) { yahoo_chat_add_users(PURPLE_CONV_CHAT(c), members); } if (account->deny && c) { PurpleConversationUiOps *ops = purple_conversation_get_ui_ops(c); for (l = account->deny; l != NULL; l = l->next) { for (roomies = members; roomies; roomies = roomies->next) { if (!purple_utf8_strcasecmp((char *)l->data, roomies->data)) { purple_debug_info("yahoo", "Ignoring room member %s in room %s\n" , roomies->data, room ? room : ""); purple_conv_chat_ignore(PURPLE_CONV_CHAT(c),roomies->data); ops->chat_update_user(c, roomies->data); } } } } g_list_free(roomies); g_list_free(members); g_free(room); g_free(topic);}void yahoo_process_chat_exit(PurpleConnection *gc, struct yahoo_packet *pkt){ char *who = NULL; char *room = NULL; GSList *l; struct yahoo_data *yd; yd = gc->proto_data; for (l = pkt->hash; l; l = l->next) { struct yahoo_pair *pair = l->data; if (pair->key == 104) room = yahoo_string_decode(gc, pair->value, TRUE); if (pair->key == 109) who = pair->value; } if (who && room) { PurpleConversation *c = purple_find_chat(gc, YAHOO_CHAT_ID); if (c && !purple_utf8_strcasecmp(purple_conversation_get_name(c), room)) purple_conv_chat_remove_user(PURPLE_CONV_CHAT(c), who, NULL); } if (room) g_free(room);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -