static void netsoul_add_buddy (PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) { NetsoulData *ns= gc->proto_data; NetsoulBuddy *nb; gchar *photo = NULL; purple_debug_info("netsoul", "netsoul_add_buddy %s\n", buddy->name); nb = g_new0(NetsoulBuddy, 1); buddy->proto_data = nb; nb->login = g_strdup(buddy->name); // Get photo photo = g_strdup_printf("%s%s", NETSOUL_PHOTO_URL, buddy->name); purple_util_fetch_url(photo, TRUE, NULL, FALSE, netsoul_got_photo, buddy); // if contact is not already is watch list, add it ns_watch_buddy(gc, buddy); // watch_log_user ns_watch_log_user(gc); ns_list_users(gc, ns->watchlist); }
/* ns_get_buddies Add buddies to watchlist */ void netsoul_get_buddies (PurpleConnection* gc) { PurpleBlistNode *gnode, *cnode, *bnode; purple_debug_info("netsoul", "ns_get_buddies\n"); for(gnode = purple_get_blist()->root; gnode; gnode = gnode->next) { if(!PURPLE_BLIST_NODE_IS_GROUP(gnode)) continue; for(cnode = gnode->child; cnode; cnode = cnode->next) { if(!PURPLE_BLIST_NODE_IS_CONTACT(cnode)) continue; for(bnode = cnode->child; bnode; bnode = bnode->next) { if(!PURPLE_BLIST_NODE_IS_BUDDY(bnode)) continue; if(((PurpleBuddy*)bnode)->account == gc->account) { PurpleBuddy *buddy = (PurpleBuddy*)bnode; gchar *photo = NULL; purple_debug_info("netsoul", "netsoul_add_buddy %s\n", buddy->name); NetsoulBuddy *nb = g_new0(NetsoulBuddy, 1); buddy->proto_data = nb; nb->login = g_strdup(buddy->name); // Get photo photo = g_strdup_printf("%s%s", NETSOUL_PHOTO_URL, buddy->name); purple_util_fetch_url(photo, TRUE, NULL, FALSE, netsoul_got_photo, buddy); // if contact is not already is watch list, add it ns_watch_buddy(gc, buddy); } } } } // watch_log_user NetsoulData *ns = gc->proto_data; ns_watch_log_user(gc); ns_list_users(gc, ns->watchlist); }
static void send_start_oscar_session(OscarData *od, const char *token, const char *session_key, time_t hosttime) { char *query_string, *signature, *url; gboolean use_tls = purple_account_get_bool(purple_connection_get_account(od->gc), "use_ssl", OSCAR_DEFAULT_USE_SSL); /* Construct the GET parameters */ query_string = g_strdup_printf("a=%s" "&f=xml" "&k=%s" "&ts=%" PURPLE_TIME_T_MODIFIER "&useTLS=%d", purple_url_encode(token), get_client_key(od), hosttime, use_tls); signature = generate_signature("GET", URL_START_OSCAR_SESSION, query_string, session_key); url = g_strdup_printf(URL_START_OSCAR_SESSION "?%s&sig_sha256=%s", query_string, signature); g_free(query_string); g_free(signature); /* Make the request */ od->url_data = purple_util_fetch_url(url, TRUE, NULL, FALSE, start_oscar_session_cb, od); g_free(url); }
void yahoo_process_picture(PurpleConnection *gc, struct yahoo_packet *pkt) { YahooData *yd; GSList *l = pkt->hash; char *who = NULL; gboolean got_icon_info = FALSE, send_icon_info = FALSE; char *url = NULL; int checksum = 0; while (l) { struct yahoo_pair *pair = l->data; switch (pair->key) { case 1: case 4: if (g_utf8_validate(pair->value, -1, NULL)) { who = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_picture " "got non-UTF-8 string for key %d\n", pair->key); } break; case 5: /* us */ break; case 13: { int tmp; tmp = strtol(pair->value, NULL, 10); if (tmp == 1) { send_icon_info = TRUE; } else if (tmp == 2) { got_icon_info = TRUE; } break; } case 20: if (g_utf8_validate(pair->value, -1, NULL)) { url = pair->value; } else { purple_debug_warning("yahoo", "yahoo_process_picture " "got non-UTF-8 string for key %d\n", pair->key); } break; case 192: checksum = strtol(pair->value, NULL, 10); break; } l = l->next; } if (!who) return; if (!purple_privacy_check(purple_connection_get_account(gc), who)) { purple_debug_info("yahoo", "Picture packet from %s dropped.\n", who); return; } /* Yahoo IM 6 spits out 0.png as the URL if the buddy icon is not set */ if (who && got_icon_info && url && !g_ascii_strncasecmp(url, "http://", 7)) { /* TODO: make this work p2p, try p2p before the url */ PurpleUtilFetchUrlData *url_data; struct yahoo_fetch_picture_data *data; /* use whole URL if using HTTP Proxy */ gboolean use_whole_url = yahoo_account_use_http_proxy(gc); data = g_new0(struct yahoo_fetch_picture_data, 1); data->gc = gc; data->who = g_strdup(who); data->checksum = checksum; /* TODO: Does this need to be MSIE 5.0? */ url_data = purple_util_fetch_url(url, use_whole_url, "Mozilla/4.0 (compatible; MSIE 5.5)", FALSE, yahoo_fetch_picture_cb, data); if (url_data != NULL) { yd = gc->proto_data; yd->url_datas = g_slist_prepend(yd->url_datas, url_data); } } else if (who && send_icon_info) {
void gaym_buddy_status(struct gaym_conn *gaym, char *name, gboolean online, char *info, gboolean fetch_thumbnail) { char *bio = NULL; char *thumbnail = NULL; char *stats = NULL; char *url = NULL; struct gaym_fetch_thumbnail_data *data; gboolean gaymuser = FALSE; if (!gaym || !gaym->account || !gaym->buddies || !name) { return; } if (info) { bio = gaym_bio_strdup(info); if (bio) { bio = g_strstrip(bio); } thumbnail = gaym_thumbnail_strdup(info); if (thumbnail) { thumbnail = g_strstrip(thumbnail); } stats = gaym_stats_strdup(info); if (stats) { stats = g_strstrip(stats); } } PurpleConnection *gc = purple_account_get_connection(gaym->account); if (!gc) { return; } struct gaym_buddy *ib = g_hash_table_lookup(gaym->buddies, name); if (!ib) ib = g_hash_table_lookup(gaym->channel_members, name); char *normalized = g_strdup(purple_normalize(gaym->account, name)); if (thumbnail && fetch_thumbnail) { if (!ib || purple_utf8_strcasecmp(thumbnail, ib->thumbnail)) { char *hashurl = NULL; hashurl = g_hash_table_lookup(gaym->confighash, "mini-profile-panel.thumbnail-prefix"); g_return_if_fail(hashurl != NULL); data = g_new0(struct gaym_fetch_thumbnail_data, 1); data->gc = purple_account_get_connection(gaym->account); data->who = g_strdup(purple_normalize(gaym->account, name)); data->filename = g_strdup(g_strrstr(thumbnail, "/")); purple_debug_misc("gayminfo", "Found filename: %s\n", data->filename); url = g_strdup_printf("%s%s", hashurl, thumbnail); purple_util_fetch_url(url, FALSE, "Mozilla/4.0", FALSE, gaym_fetch_thumbnail_cb, data); g_free(url); } }
/** * Store a field of information about a buddy. * * @param key_str Key to store. * @param value_str Value string, either user takes ownership of this string * or it is freed if MsimUser doesn't store the string. * @param user User to store data in. Existing data will be replaced. */ static void msim_store_user_info_each(const gchar *key_str, gchar *value_str, MsimUser *user) { if (g_str_equal(key_str, "UserID") || g_str_equal(key_str, "ContactID")) { /* Save to buddy list, if it exists, for quick cached uid lookup with msim_uid2username_from_blist(). */ user->id = atol(value_str); g_free(value_str); if (user->buddy) { purple_debug_info("msim", "associating uid %s with username %s\n", key_str, user->buddy->name); purple_blist_node_set_int(&user->buddy->node, "UserID", user->id); } /* Need to store in MsimUser, too? What if not on blist? */ } else if (g_str_equal(key_str, "Age")) { user->age = atol(value_str); g_free(value_str); } else if (g_str_equal(key_str, "Gender")) { g_free(user->gender); user->gender = value_str; } else if (g_str_equal(key_str, "Location")) { g_free(user->location); user->location = value_str; } else if (g_str_equal(key_str, "TotalFriends")) { user->total_friends = atol(value_str); g_free(value_str); } else if (g_str_equal(key_str, "DisplayName")) { g_free(user->display_name); user->display_name = value_str; } else if (g_str_equal(key_str, "BandName")) { msim_set_artist_or_title(user, value_str, NULL); g_free(value_str); } else if (g_str_equal(key_str, "SongName")) { msim_set_artist_or_title(user, NULL, value_str); g_free(value_str); } else if (g_str_equal(key_str, "UserName") || g_str_equal(key_str, "IMName") || g_str_equal(key_str, "NickName")) { /* Ignore because PurpleBuddy knows this already */ g_free(value_str); } else if (g_str_equal(key_str, "ImageURL") || g_str_equal(key_str, "AvatarURL")) { const gchar *previous_url; if (user->temporary_user) { /* This user will be destroyed soon; don't try to look up its image or avatar, * since that won't return immediately and we will end up accessing freed data. */ g_free(value_str); return; } if (user->temporary_user) { /* This user will be destroyed soon; don't try to look up its image or avatar, * since that won't return immediately and we will end up accessing freed data. */ g_free(value_str); return; } g_free(user->image_url); user->image_url = value_str; /* Instead of showing 'no photo' picture, show nothing. */ if (g_str_equal(user->image_url, "http://x.myspace.com/images/no_pic.gif")) { purple_buddy_icons_set_for_user(user->buddy->account, user->buddy->name, NULL, 0, NULL); return; } /* TODO: use ETag for checksum */ previous_url = purple_buddy_icons_get_checksum_for_user(user->buddy); /* Only download if URL changed */ if (!previous_url || !g_str_equal(previous_url, user->image_url)) { purple_util_fetch_url(user->image_url, TRUE, NULL, TRUE, msim_downloaded_buddy_icon, (gpointer)user); } } else if (g_str_equal(key_str, "LastImageUpdated")) { /* TODO: use somewhere */ user->last_image_updated = atol(value_str); g_free(value_str); } else if (g_str_equal(key_str, "Headline")) { g_free(user->headline); user->headline = value_str; } else { /* TODO: other fields in MsimUser */ gchar *msg; msg = g_strdup_printf("msim_store_user_info_each: unknown field %s=%s", key_str, value_str); g_free(value_str); msim_unrecognized(NULL, NULL, msg); g_free(msg); } }