MsnSession * msn_session_new (const gchar *username, const gchar *password, gboolean http_method) { MsnSession *session; session = g_new0 (MsnSession, 1); session->username = pn_normalize (username); session->password = g_strndup (password, 16); #ifdef INTERNAL_MAINLOOP session->g_main_loop = g_main_loop_new (NULL, FALSE); session->g_main_loop_timer = purple_timeout_add (1000, g_main_context_iteration_timer, NULL); #endif session->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); /** @todo sb and ns need this here but should be updated on-the-fly. */ msn_session_set_bool (session, "use_http_method", http_method); #if 0 if (session->http_method) { PnNode *foo; foo = PN_NODE (pn_http_server_new ("foo server")); foo->session = session; session->http_conn = foo; } #endif session->dp_manager = pn_dp_manager_new (session); session->notification = msn_notification_new (session); pn_node_set_id(session->notification->cmdproc->conn, session->conn_count++, "ns"); session->contactlist = pn_contactlist_new (session); session->user = pn_contact_new (NULL); pn_contact_set_passport (session->user, session->username); session->conv_seq = 1; session->oim_session = pn_oim_session_new (session); session->conversations = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) msn_switchboard_unref); session->chats = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) msn_switchboard_unref); #if defined(PECAN_CVR) session->links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) pn_peer_link_unref); #endif /* defined(PECAN_CVR) */ purple_signal_connect (purple_conversations_get_handle(), "conversation-created", session, PURPLE_CALLBACK (conversation_created_cb), session); return session; }
static void lst_cmd (MsnCmdProc *cmdproc, MsnCommand *cmd) { MsnSession *session = cmdproc->session; const gchar *passport = NULL; struct pn_contact *user; gchar *friendly = NULL; const gchar *user_guid = NULL; int list_op = -1; gint type; guint i; for (i = 0; i < cmd->param_count; i++) { const char *chopped_str; chopped_str = cmd->params[i] + 2; /* Check for Name/email. */ if (strncmp (cmd->params[i], "N=", 2) == 0) passport = chopped_str; /* Check for Friendlyname. */ else if (strncmp (cmd->params[i], "F=", 2) == 0) friendly = pn_url_decode (chopped_str); /* Check for Contact GUID. */ else if (strncmp (cmd->params[i], "C=", 2) == 0) user_guid = chopped_str; else break; } list_op = g_ascii_strtod (cmd->params[i++], NULL); type = g_ascii_strtod (cmd->params[i++], NULL); user = pn_contact_new (session->contactlist); pn_contact_set_passport (user, passport); pn_contact_set_guid (user, user_guid); session->sync->last_user = user; /* TODO: This can be improved */ if (list_op & MSN_LIST_FL_OP) { if (cmd->params[i]) { gchar **c; gchar **tokens; const gchar *group_guids; GSList *group_ids; group_guids = cmd->params[i]; group_ids = NULL; tokens = g_strsplit (group_guids, ",", -1); for (c = tokens; *c; c++) { group_ids = g_slist_append (group_ids, g_strdup (*c)); } g_strfreev (tokens); msn_got_lst_contact (session, user, friendly, list_op, group_ids); g_slist_foreach (group_ids, (GFunc) g_free, NULL); g_slist_free (group_ids); } else { msn_got_lst_contact (session, user, friendly, list_op, NULL); } } else { msn_got_lst_contact (session, user, friendly, list_op, NULL); } g_free (friendly); session->sync->num_users++; if (session->sync->num_users == session->sync->total_users) { cmdproc->cbs_table = session->sync->old_cbs_table; msn_session_finish_login (session); msn_sync_destroy (session->sync); session->sync = NULL; } }
MsnSession * msn_session_new (const gchar *username, const gchar *password, gboolean http_method) { MsnSession *session; PnClientCaps caps; session = g_new0 (MsnSession, 1); session->username = pn_normalize (username); session->password = g_strndup (password, 16); #ifdef INTERNAL_MAINLOOP session->g_main_loop = g_main_loop_new (NULL, FALSE); session->g_main_loop_timer = purple_timeout_add (1000, g_main_context_iteration_timer, NULL); #endif session->config = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, NULL); /** @todo sb and ns need this here but should be updated on-the-fly. */ msn_session_set_bool (session, "use_http_method", http_method); #if 0 if (session->http_method) { PnNode *foo; foo = PN_NODE (pn_http_server_new ("foo server")); foo->session = session; session->http_conn = foo; } #endif session->dp_manager = pn_dp_manager_new (session); session->notification = msn_notification_new (session); pn_node_set_id(session->notification->cmdproc->conn, session->conn_count++, "ns"); session->contactlist = pn_contactlist_new (session); session->user = pn_contact_new (NULL); pn_contact_set_passport (session->user, session->username); session->conv_seq = 1; session->machineguid = pn_rand_guid (); session->oim_session = pn_oim_session_new (session); session->service_session = pn_service_session_new (session); session->roaming_session = pn_roaming_session_new (session); session->conversations = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) msn_switchboard_unref); session->chats = g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL, (GDestroyNotify) msn_switchboard_unref); #if defined(PECAN_CVR) session->links = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, (GDestroyNotify) pn_peer_link_unref); #endif /* defined(PECAN_CVR) */ caps = PN_CLIENT_CAP_BASE; #if defined(PECAN_CVR) caps |= PN_CLIENT_CAP_INK_GIF; #if defined(PECAN_LIBSIREN) caps |= PN_CLIENT_CAP_VOICE_CLIP; #endif #if defined(PECAN_LIBMSPACK) caps |= PN_CLIENT_CAP_WINKS; #endif #endif session->client_id = caps | PN_CLIENT_VER_2009; return session; }