* 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 * 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., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #include "yahoo_friend.h" #include "yahoo_aliases.h" static YahooFriend *yahoo_friend_new(void) ret = g_new0(YahooFriend, 1); ret->status = YAHOO_STATUS_OFFLINE; ret->presence = YAHOO_PRESENCE_DEFAULT; YahooFriend *yahoo_friend_find(PurpleConnection *gc, const char *name) g_return_val_if_fail(gc != NULL, NULL); g_return_val_if_fail(gc->proto_data != NULL, NULL); norm = purple_normalize(purple_connection_get_account(gc), name); return g_hash_table_lookup(yd->friends, norm); YahooFriend *yahoo_friend_find_or_new(PurpleConnection *gc, const char *name) g_return_val_if_fail(gc != NULL, NULL); g_return_val_if_fail(gc->proto_data != NULL, NULL); norm = purple_normalize(purple_connection_get_account(gc), name); f = g_hash_table_lookup(yd->friends, norm); g_hash_table_insert(yd->friends, g_strdup(norm), f); void yahoo_friend_set_ip(YahooFriend *f, const char *ip) const char *yahoo_friend_get_ip(YahooFriend *f) void yahoo_friend_set_game(YahooFriend *f, const char *game) f->game = g_strdup(game); const char *yahoo_friend_get_game(YahooFriend *f) void yahoo_friend_set_status_message(YahooFriend *f, char *msg) const char *yahoo_friend_get_status_message(YahooFriend *f) void yahoo_friend_set_buddy_icon_need_request(YahooFriend *f, gboolean needs) f->bicon_sent_request = !needs; gboolean yahoo_friend_get_buddy_icon_need_request(YahooFriend *f) return !f->bicon_sent_request; void yahoo_friend_set_alias_id(YahooFriend *f, const char *alias_id) f->ypd.id = g_strdup(alias_id); const char *yahoo_friend_get_alias_id(YahooFriend *f) void yahoo_friend_free(gpointer p) yahoo_personal_details_reset(&f->ypd, TRUE); void yahoo_process_presence(PurpleConnection *gc, struct yahoo_packet *pkt) YahooFederation fed = YAHOO_FEDERATION_NONE; struct yahoo_pair *pair = l->data; if (g_utf8_validate(pair->value, -1, NULL)) { purple_debug_warning("yahoo", "yahoo_process_presence " "got non-UTF-8 string for key %d\n", pair->key); value = strtol(pair->value, NULL, 10); fed = strtol(pair->value, NULL, 10); if (value != 1 && value != 2) { purple_debug_error("yahoo", "Received unknown value for presence key: %d\n", value); case YAHOO_FEDERATION_MSN: who = g_strconcat("msn/", temp, NULL); case YAHOO_FEDERATION_OCS: who = g_strconcat("ocs/", temp, NULL); case YAHOO_FEDERATION_IBM: who = g_strconcat("ibm/", temp, NULL); case YAHOO_FEDERATION_PBX: who = g_strconcat("pbx/", temp, NULL); case YAHOO_FEDERATION_NONE: g_return_if_fail(who != NULL); f = yahoo_friend_find(gc, who); if (pkt->service == YAHOO_SERVICE_PRESENCE_PERM) { purple_debug_info("yahoo", "Setting permanent presence for %s to %d.\n", who, (value == 1)); /* If setting from perm offline to online when in invisible status, * this has already been taken care of (when the temp status changed) */ if (value == 2 && f->presence == YAHOO_PRESENCE_ONLINE) { if (value == 1) /* Setting Perm offline */ f->presence = YAHOO_PRESENCE_PERM_OFFLINE; f->presence = YAHOO_PRESENCE_DEFAULT; purple_debug_info("yahoo", "Setting session presence for %s to %d.\n", who, (value == 1)); f->presence = YAHOO_PRESENCE_ONLINE; f->presence = YAHOO_PRESENCE_DEFAULT; void yahoo_friend_update_presence(PurpleConnection *gc, const char *name, YahooPresenceVisibility presence) YahooData *yd = gc->proto_data; struct yahoo_packet *pkt = NULL; const char *thirtyone, *thirteen; f = yahoo_friend_find(gc, name); if(f->fed != YAHOO_FEDERATION_NONE) /* No need to change the value if it is already correct */ if (f->presence == presence) { purple_debug_info("yahoo", "Not setting presence because there are no changes.\n"); if (presence == YAHOO_PRESENCE_PERM_OFFLINE) { service = YAHOO_SERVICE_PRESENCE_PERM; } else if (presence == YAHOO_PRESENCE_DEFAULT) { if (f->presence == YAHOO_PRESENCE_PERM_OFFLINE) { service = YAHOO_SERVICE_PRESENCE_PERM; } else if (yd->current_status == YAHOO_STATUS_INVISIBLE) { service = YAHOO_SERVICE_PRESENCE_SESSION; } else if (presence == YAHOO_PRESENCE_ONLINE) { if (f->presence == YAHOO_PRESENCE_PERM_OFFLINE) { pkt = yahoo_packet_new(YAHOO_SERVICE_PRESENCE_PERM, YAHOO_STATUS_AVAILABLE, yd->session_id); yahoo_packet_hash(pkt, "ssssssiss", 1, purple_connection_get_display_name(gc), yahoo_packet_hash(pkt, "ssssssss", 1, purple_connection_get_display_name(gc), yahoo_packet_send_and_free(pkt, yd); service = YAHOO_SERVICE_PRESENCE_SESSION; pkt = yahoo_packet_new(service, YAHOO_STATUS_AVAILABLE, yd->session_id); yahoo_packet_hash(pkt, "ssssssiss", 1, purple_connection_get_display_name(gc), 31, thirtyone, 13, thirteen, yahoo_packet_hash(pkt, "ssssssss", 1, purple_connection_get_display_name(gc), 31, thirtyone, 13, thirteen, yahoo_packet_send_and_free(pkt, yd); void yahoo_friend_set_p2p_status(YahooFriend *f, YahooP2PStatus p2p_status) f->p2p_status = p2p_status; YahooP2PStatus yahoo_friend_get_p2p_status(YahooFriend *f)