Example #1
0
void flist_get_profile(PurpleConnection *pc, const char *who) {
    FListAccount *fla;
    FListProfiles *flp;
    GString *link_str;
    gchar *link;
    FListCharacter *character;

    g_return_if_fail((fla = pc->proto_data));
    flp = _flist_profiles(fla);

    if(flp->character) g_free(flp->character);
    flp->character = NULL;
    if(flp->profile_info) purple_notify_user_info_destroy(flp->profile_info);
    flp->profile_info = NULL;
    if(flp->table) g_hash_table_destroy(flp->table);
    flp->table = NULL;
    if(flp->profile_request) {
        flist_web_request_cancel(flp->profile_request);
        flp->profile_request = NULL;
    }

    flp->character = g_strdup(who);
    flp->profile_info = purple_notify_user_info_new();

    link_str = g_string_new(NULL);
    g_string_append_printf(link_str, "http://www.f-list.net/c/%s", purple_url_encode(who));
    link = g_string_free(link_str, FALSE);

    character = flist_get_character(fla, who);
    if(!character) {
        purple_notify_user_info_add_pair(flp->profile_info, "Status", "Offline");
    } else {
        gchar *clean_message = flist_html_unescape_utf8(character->status_message);
        gchar *parsed_message = flist_bbcode_to_html(fla, NULL, clean_message);
        purple_notify_user_info_add_pair(flp->profile_info, "Status", flist_format_status(character->status));
        purple_notify_user_info_add_pair(flp->profile_info, "Gender", flist_format_gender(character->gender));
        purple_notify_user_info_add_pair(flp->profile_info, "Message", parsed_message);
        g_free(parsed_message);
        g_free(clean_message);
    }
    purple_notify_user_info_add_pair(flp->profile_info, "Link", link);
    purple_notify_userinfo(pc, flp->character, flp->profile_info, NULL, NULL);

    if(!character) {
        //The character is offline. There's nothing more we should do.
        g_free(flp->character); flp->character = NULL;
        purple_notify_user_info_destroy(flp->profile_info); flp->profile_info = NULL;
    } else if(flp->category_table) { /* Try to get the profile through the website API first. */
        GHashTable *args = flist_web_request_args(fla);
        g_hash_table_insert(args, "name", g_strdup(flp->character));
        flp->profile_request = flist_web_request(JSON_CHARACTER_INFO, args, NULL, TRUE, fla->secure, flist_get_profile_cb, fla);
        g_hash_table_destroy(args);
    } else { /* Try to get the profile through F-Chat. */
        JsonObject *json = json_object_new();
        json_object_set_string_member(json, "character", flp->character);
        flist_request(pc, "PRO", json);
        json_object_unref(json);
    }
    g_free(link);
}
Example #2
0
void flist_profile_unload(PurpleConnection *pc) {
    FListAccount *fla = pc->proto_data;
    FListProfiles *flp = _flist_profiles(fla);

    if(flp->global_profile_request) {
        flist_web_request_cancel(flp->global_profile_request);
        flp->global_profile_request = NULL;
    }
    
    if(flp->priority_profile_fields) {
        g_slist_free(flp->priority_profile_fields);
        flp->priority_profile_fields = NULL;
    }

    if(flp->category_list) {
        g_slist_free(flp->category_list);
        flp->category_list = NULL;
    }
    if(flp->category_table) {
        g_hash_table_destroy(flp->category_table);
        flp->category_table = NULL;
    }
    
    if(flp->profile_request) {
        flist_web_request_cancel(flp->profile_request);
        flp->profile_request = NULL;
    }
    if(flp->character) {
        g_free(flp->character);
        flp->character = NULL;
    }
    if(flp->profile_info) {
        purple_notify_user_info_destroy(flp->profile_info);
        flp->profile_info = NULL;
    }
    if(flp->table) {
        g_hash_table_destroy(flp->table);
        flp->table = NULL;
    }
    if(flp->profile_request) flp->profile_request = NULL;
    
    g_free(flp);
    //TODO: lots of memory leaks here to cleanup?
}
Example #3
0
void flist_close(PurpleConnection *pc) {
    FListAccount *fla = pc->proto_data;
    if(!fla) return;
    if(fla->gsc) purple_ssl_close(fla->gsc);
    
    if(fla->username) g_free(fla->username);
    if(fla->character) g_free(fla->character);
    if(fla->password) g_free(fla->password);
    if(fla->proper_character) g_free(fla->proper_character);

    if(fla->ticket_request) flist_web_request_cancel(fla->ticket_request);
    if(fla->ticket_timer) purple_timeout_remove(fla->ticket_timer);
    
    if(fla->fls_cookie) g_free(fla->fls_cookie);
    g_free(fla->rx_buf);

    if(fla->ping_timeout_handle) purple_timeout_remove(fla->ping_timeout_handle);
    
    g_hash_table_destroy(fla->all_characters);
    if(fla->global_ops) g_hash_table_destroy(fla->global_ops);

    /* login options */
    if(fla->server_address) g_free(fla->server_address);

    if(fla->input_request) purple_request_close_with_handle((void*) pc);
    
    flist_friends_unload(fla);
    flist_fetch_icon_cancel_all(fla);
    flist_global_kinks_unload(pc);
    flist_profile_unload(pc);
    flist_channel_subsystem_unload(fla);
    
    g_free(fla);

    pc->proto_data = NULL;
}