Open an explorer.exe window at the location of the file when clicking
[pidgin-git.git] / libpurple / protocols / myspace / session.c
blob2d6e6c98d467800b86fa7b2fbee456950943f72a
1 /* MySpaceIM Protocol Plugin, session
3 * Copyright (C) 2007, Jeff Connelly <jeff2@soc.pidgin.im>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
20 #include "myspace.h"
22 /* Session methods */
24 /**
25 * Create a new MSIM session.
27 * @param acct The account to create the session from.
29 * @return Pointer to a new session. Free with msim_session_destroy.
31 MsimSession *
32 msim_session_new(PurpleAccount *acct)
34 MsimSession *session;
36 g_return_val_if_fail(acct != NULL, NULL);
38 session = g_new0(MsimSession, 1);
40 session->magic = MSIM_SESSION_STRUCT_MAGIC;
41 session->account = acct;
42 session->gc = purple_account_get_connection(acct);
43 session->sesskey = 0;
44 session->userid = 0;
45 session->username = NULL;
46 session->fd = -1;
48 /* TODO: Remove. */
49 session->user_lookup_cb = g_hash_table_new_full(g_direct_hash,
50 g_direct_equal, NULL, NULL); /* do NOT free function pointers! (values) */
51 session->user_lookup_cb_data = g_hash_table_new_full(g_direct_hash,
52 g_direct_equal, NULL, NULL);/* TODO: we don't know what the values are,
53 they could be integers inside gpointers
54 or strings, so I don't freed them.
55 Figure this out, once free cache. */
57 /* Created in msim_process_server_info() */
58 session->server_info = NULL;
60 session->rxoff = 0;
61 session->rxsize = MSIM_READ_BUF_SIZE;
62 session->rxbuf = g_new0(gchar, session->rxsize);
63 session->next_rid = 1;
64 session->last_comm = time(NULL);
65 session->inbox_status = 0;
66 session->inbox_handle = 0;
68 return session;
71 /**
72 * Free a session.
74 * @param session The session to destroy.
76 void
77 msim_session_destroy(MsimSession *session)
79 session->magic = -1;
81 g_free(session->rxbuf);
82 g_free(session->username);
84 /* TODO: Remove. */
85 g_hash_table_destroy(session->user_lookup_cb);
86 g_hash_table_destroy(session->user_lookup_cb_data);
88 if (session->server_info) {
89 msim_msg_free(session->server_info);
92 /* Stop checking the inbox at the end of the session. */
93 if (session->inbox_handle) {
94 purple_timeout_remove(session->inbox_handle);
97 g_free(session);