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
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.
32 msim_session_new(PurpleAccount
*acct
)
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
);
45 session
->username
= NULL
;
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
;
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;
74 * @param session The session to destroy.
77 msim_session_destroy(MsimSession
*session
)
81 g_free(session
->rxbuf
);
82 g_free(session
->username
);
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
);