int toc_login(char *username, char *password) { char *config; struct in_addr *sin; char buf[80]; char buf2[2048]; toc_debug_printf("looking up host! %s", aim_host); sin = (struct in_addr *)get_address(aim_host); if (!sin) { set_state(STATE_OFFLINE); toc_msg_printf(TOC_CONNECT_MSGS,"Unable to lookup %s", aim_host); return -1; } snprintf(toc_addy, sizeof(toc_addy), "%s", inet_ntoa(*sin)); snprintf(buf, sizeof(buf), "Connecting to %s", inet_ntoa(*sin)); toc_msg_printf(TOC_CONNECT_MSGS,"%s",buf); toc_fd = connect_address(sin->s_addr, aim_port); if (toc_fd < 0) { set_state(STATE_OFFLINE); toc_msg_printf(TOC_CONNECT_MSGS,"Connect to %s failed", inet_ntoa(*sin)); return -1; } free(sin); toc_msg_printf(TOC_CONNECT_MSGS,"Signon: %s",username); if (toc_signon(username, password) < 0) { set_state(STATE_OFFLINE); toc_msg_printf(TOC_CONNECT_MSGS,"Disconnected."); return -1; } toc_msg_printf(TOC_CONNECT_MSGS,"Waiting for reply..."); if (toc_wait_signon() < 0) { set_state(STATE_OFFLINE); toc_msg_printf(TOC_CONNECT_MSGS,"Authentication Failed"); return -1; } snprintf(aim_username, sizeof(aim_username), "%s", username); snprintf(aim_password, sizeof(aim_password), "%s", password); save_prefs(); toc_msg_printf(TOC_CONNECT_MSGS,"Retrieving config..."); if ((config=toc_wait_config()) == NULL) { toc_msg_printf(TOC_CONNECT_MSGS,"No Configuration\n"); set_state(STATE_OFFLINE); return -1; } init_lists(); /* gtk_widget_hide(mainwindow); show_buddy_list(); */ parse_toc_buddy_list(config); /* refresh_buddy_window(); */ snprintf(buf2, sizeof(buf2), "toc_init_done"); sflap_send(buf2, -1, TYPE_DATA); serv_finish_login(); return 0; }
static gboolean _parse_data(TrepiaSession *session, char *buf) { GHashTable *info; GaimAccount *account; TrepiaMessageType type = 0; TrepiaProfile *profile = NULL; int ret; char *buffer; GaimBuddy *b; int id = 0; const char *value; char *username; int *int_p; GMainContext *ctx; account = gaim_connection_get_account(session->gc); ret = __parse_message(buf, &type, &info); if (ret == 1) return TRUE; if (info != NULL) { switch (type) { case TREPIA_USER_LIST: gaim_connection_update_progress(session->gc, _("Retrieving buddy list"), 2, TREPIA_CONNECT_STEPS); gaim_connection_set_state(session->gc, GAIM_CONNECTED); serv_finish_login(session->gc); break; case TREPIA_MSG_INCOMING: /* Incoming Message */ id = atoi(g_hash_table_lookup(info, "a")); profile = g_hash_table_lookup(session->user_profiles, &id); serv_got_im(session->gc, trepia_profile_get_login(profile), (char *)g_hash_table_lookup(info, "b"), 0, time(NULL)); break; case TREPIA_MEMBER_UPDATE: profile = trepia_profile_new(); if ((value = g_hash_table_lookup(info, "a")) != NULL) { id = atoi(value); trepia_profile_set_id(profile, id); } if ((value = g_hash_table_lookup(info, "b")) != NULL) trepia_profile_set_login_time(profile, atoi(value)); if ((value = g_hash_table_lookup(info, "c")) != NULL) trepia_profile_set_type(profile, atoi(value)); else trepia_profile_set_type(profile, 2); session->pending_users = g_list_append(session->pending_users, profile); #if 0 if (trepia_profile_get_type(profile) == 1) { buffer = g_strdup_printf( "<D>" "<a>%d</a>" "<b>1</b>" "</D>", id); } else { #endif buffer = g_strdup_printf( "<D>" "<a>%d</a>" "<b>1</b>" "</D>" "<D>" "<a>%d</a>" "<b>2</b>" "</D>", id, id); #if 0 } #endif if (trepia_write(session->fd, buffer, strlen(buffer)) < 0) { gaim_connection_error(session->gc, _("Write error")); g_free(buffer); return 1; } g_free(buffer); break; case TREPIA_MEMBER_PROFILE: if ((value = g_hash_table_lookup(info, "a")) != NULL) { GList *l; id = atoi(value); for (l = session->pending_users; l != NULL; l = l->next) { profile = l->data; if (trepia_profile_get_id(profile) == id) break; profile = NULL; } } else break; if (profile == NULL) { profile = g_hash_table_lookup(session->user_profiles, &id); if (profile == NULL) break; } /* Age */ if ((value = g_hash_table_lookup(info, "m")) != NULL) trepia_profile_set_age(profile, atoi(value)); /* ICQ */ if ((value = g_hash_table_lookup(info, "i")) != NULL) trepia_profile_set_icq(profile, atoi(value)); /* Sex */ if ((value = g_hash_table_lookup(info, "n")) != NULL) trepia_profile_set_sex(profile, *value); /* Location */ if ((value = g_hash_table_lookup(info, "p")) != NULL) trepia_profile_set_location(profile, value); /* First Name */ if ((value = g_hash_table_lookup(info, "g")) != NULL) trepia_profile_set_first_name(profile, value); /* Last Name */ if ((value = g_hash_table_lookup(info, "h")) != NULL) trepia_profile_set_last_name(profile, value); /* Profile */ if ((value = g_hash_table_lookup(info, "o")) != NULL) trepia_profile_set_profile(profile, value); /* E-mail */ if ((value = g_hash_table_lookup(info, "e")) != NULL) trepia_profile_set_email(profile, value); /* AIM */ if ((value = g_hash_table_lookup(info, "j")) != NULL) trepia_profile_set_aim(profile, value); /* MSN */ if ((value = g_hash_table_lookup(info, "k")) != NULL) trepia_profile_set_msn(profile, value); /* Yahoo */ if ((value = g_hash_table_lookup(info, "l")) != NULL) trepia_profile_set_yahoo(profile, value); /* Homepage */ if ((value = g_hash_table_lookup(info, "f")) != NULL) trepia_profile_set_homepage(profile, value); /* Country */ if ((value = g_hash_table_lookup(info, "r")) != NULL) trepia_profile_set_country(profile, value); /* State */ if ((value = g_hash_table_lookup(info, "s")) != NULL) trepia_profile_set_state(profile, value); /* City */ if ((value = g_hash_table_lookup(info, "t")) != NULL) trepia_profile_set_city(profile, value); /* Languages */ if ((value = g_hash_table_lookup(info, "u")) != NULL) trepia_profile_set_languages(profile, value); /* School */ if ((value = g_hash_table_lookup(info, "v")) != NULL) trepia_profile_set_school(profile, value); /* Company */ if ((value = g_hash_table_lookup(info, "w")) != NULL) trepia_profile_set_company(profile, value); /* Login Name */ if ((value = g_hash_table_lookup(info, "d")) != NULL) { trepia_profile_set_login(profile, value); username = g_strdup(value); } else if ((value = trepia_profile_get_login(profile)) != NULL) { username = g_strdup(value); } else { username = g_strdup_printf("%d", id); trepia_profile_set_login(profile, username); } b = gaim_find_buddy(account, username); if (b == NULL) { GaimGroup *g; g = gaim_find_group(_("Local Users")); if (g == NULL) { g = gaim_group_new(_("Local Users")); gaim_blist_add_group(g, NULL); } b = gaim_buddy_new(account, username, NULL); gaim_blist_add_buddy(b, NULL, g, NULL); } profile->buddy = b; b->proto_data = profile; session->pending_users = g_list_remove(session->pending_users, profile); int_p = g_new0(int, 1); *int_p = id; g_hash_table_insert(session->user_profiles, int_p, profile); serv_got_update(session->gc, username, TRUE, 0, trepia_profile_get_login_time(profile), 0, 0); /* Buddy Icon */ if ((value = g_hash_table_lookup(info, "q")) != NULL) { char *icon; int icon_len; gaim_base64_decode(value, &icon, &icon_len); gaim_buddy_icons_set_for_user(session->gc->account, username, icon, icon_len); g_free(icon); serv_got_update(session->gc, username, TRUE, 0, 0, 0, 0); } /* * XXX * This does nothing when using a non-gtk event loop. * What is it supposed to accomplish anyway? */ ctx = g_main_context_default(); while (g_main_context_pending(ctx)) g_main_context_iteration(ctx, FALSE); g_free(username); break; case TREPIA_MEMBER_OFFLINE: if ((value = g_hash_table_lookup(info, "a")) != NULL) id = atoi(value); else break; profile = g_hash_table_lookup(session->user_profiles, &id); if (profile == NULL) break; g_hash_table_remove(session->user_profiles, &id); b = profile->buddy; if (b != NULL) serv_got_update(session->gc, trepia_profile_get_login(profile), FALSE, 0, 0, 0, 0); gaim_blist_remove_buddy(b); break; default: break; } g_hash_table_destroy(info); } else {