Mercurial > pidgin.yaz
annotate src/protocols/msn/session.c @ 5343:2e5462a322b8
[gaim-migrate @ 5719]
David Brigada (jsi) uses the todo. so should you!
committer: Tailor Script <tailor@pidgin.im>
author | Luke Schierer <lschiere@pidgin.im> |
---|---|
date | Sat, 10 May 2003 02:38:29 +0000 |
parents | bd98232872a3 |
children | 2aa7e4237142 |
rev | line source |
---|---|
5309 | 1 /** |
2 * @file session.c MSN session functions | |
3 * | |
4 * gaim | |
5 * | |
6 * Copyright (C) 2003 Christian Hammond <chipx86@gnupdate.org> | |
7 * | |
8 * This program is free software; you can redistribute it and/or modify | |
9 * it under the terms of the GNU General Public License as published by | |
10 * the Free Software Foundation; either version 2 of the License, or | |
11 * (at your option) any later version. | |
12 * | |
13 * This program is distributed in the hope that it will be useful, | |
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
16 * GNU General Public License for more details. | |
17 * | |
18 * You should have received a copy of the GNU General Public License | |
19 * along with this program; if not, write to the Free Software | |
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
21 */ | |
22 #include "msn.h" | |
23 #include "session.h" | |
24 #include "dispatch.h" | |
25 | |
26 MsnSession * | |
27 msn_session_new(struct gaim_account *account, const char *server, int port) | |
28 { | |
29 MsnSession *session; | |
30 | |
31 g_return_val_if_fail(account != NULL, NULL); | |
32 | |
33 session = g_new0(MsnSession, 1); | |
34 | |
35 session->account = account; | |
36 session->dispatch_server = g_strdup(server); | |
37 session->dispatch_port = port; | |
38 | |
39 session->users = msn_users_new(); | |
40 | |
41 return session; | |
42 } | |
43 | |
44 void | |
45 msn_session_destroy(MsnSession *session) | |
46 { | |
47 g_return_if_fail(session != NULL); | |
48 | |
49 if (session->connected) | |
50 msn_session_disconnect(session); | |
51 | |
52 if (session->dispatch_server != NULL) | |
53 g_free(session->dispatch_server); | |
54 | |
55 while (session->switches != NULL) | |
56 msn_switchboard_destroy(session->switches->data); | |
57 | |
58 while (session->lists.forward) | |
59 msn_user_destroy(session->lists.forward->data); | |
60 | |
5318
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
61 if (session->group_ids) g_hash_table_destroy(session->group_ids); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
62 if (session->group_names) g_hash_table_destroy(session->group_names); |
bd98232872a3
[gaim-migrate @ 5690]
Christian Hammond <chipx86@chipx86.com>
parents:
5309
diff
changeset
|
63 |
5309 | 64 g_slist_free(session->lists.allow); |
65 g_slist_free(session->lists.block); | |
66 | |
67 msn_users_destroy(session->users); | |
68 | |
69 g_free(session); | |
70 } | |
71 | |
72 gboolean | |
73 msn_session_connect(MsnSession *session) | |
74 { | |
75 g_return_val_if_fail(session != NULL, FALSE); | |
76 g_return_val_if_fail(!session->connected, TRUE); | |
77 | |
78 session->connected = TRUE; | |
79 | |
80 session->dispatch_conn = msn_dispatch_new(session, | |
81 session->dispatch_server, | |
82 session->dispatch_port); | |
83 | |
84 if (msn_servconn_connect(session->dispatch_conn)) | |
85 return TRUE; | |
86 | |
87 return FALSE; | |
88 } | |
89 | |
90 void | |
91 msn_session_disconnect(MsnSession *session) | |
92 { | |
93 g_return_if_fail(session != NULL); | |
94 g_return_if_fail(session->connected); | |
95 | |
96 if (session->dispatch_conn != NULL) { | |
97 msn_servconn_destroy(session->dispatch_conn); | |
98 session->dispatch_conn = NULL; | |
99 } | |
100 | |
101 while (session->switches != NULL) { | |
102 MsnSwitchBoard *board = (MsnSwitchBoard *)session->switches->data; | |
103 | |
104 msn_switchboard_destroy(board); | |
105 } | |
106 | |
107 if (session->notification_conn != NULL) { | |
108 msn_servconn_destroy(session->notification_conn); | |
109 session->notification_conn = NULL; | |
110 } | |
111 } | |
112 | |
113 MsnSwitchBoard * | |
114 msn_session_open_switchboard(MsnSession *session) | |
115 { | |
116 MsnSwitchBoard *swboard; | |
117 | |
118 g_return_val_if_fail(session != NULL, NULL); | |
119 | |
120 if (msn_servconn_send_command(session->notification_conn, | |
121 "XFR", "SB") < 0) { | |
122 return NULL; | |
123 } | |
124 | |
125 swboard = msn_switchboard_new(session); | |
126 | |
127 return swboard; | |
128 } | |
129 | |
130 MsnSwitchBoard * | |
131 msn_session_find_switch_with_passport(const MsnSession *session, | |
132 const char *passport) | |
133 { | |
134 GList *l; | |
135 MsnSwitchBoard *swboard; | |
136 | |
137 g_return_val_if_fail(session != NULL, NULL); | |
138 g_return_val_if_fail(passport != NULL, NULL); | |
139 | |
140 for (l = session->switches; l != NULL; l = l->next) { | |
141 swboard = (MsnSwitchBoard *)l->data; | |
142 | |
143 if (!g_ascii_strcasecmp(passport, | |
144 msn_user_get_passport(swboard->user))) { | |
145 return swboard; | |
146 } | |
147 } | |
148 | |
149 return NULL; | |
150 } | |
151 | |
152 MsnSwitchBoard * | |
153 msn_session_find_switch_with_id(const MsnSession *session, int chat_id) | |
154 { | |
155 GList *l; | |
156 MsnSwitchBoard *swboard; | |
157 | |
158 g_return_val_if_fail(session != NULL, NULL); | |
159 g_return_val_if_fail(chat_id > 0, NULL); | |
160 | |
161 for (l = session->switches; l != NULL; l = l->next) { | |
162 swboard = (MsnSwitchBoard *)l->data; | |
163 | |
164 if (swboard->chat_id == chat_id) | |
165 return swboard; | |
166 } | |
167 | |
168 return NULL; | |
169 } | |
170 | |
171 MsnSwitchBoard * | |
172 msn_session_find_unused_switch(const MsnSession *session) | |
173 { | |
174 GList *l; | |
175 MsnSwitchBoard *swboard; | |
176 | |
177 g_return_val_if_fail(session != NULL, NULL); | |
178 | |
179 for (l = session->switches; l != NULL; l = l->next) { | |
180 swboard = (MsnSwitchBoard *)l->data; | |
181 | |
182 if (!swboard->in_use) | |
183 return swboard; | |
184 } | |
185 | |
186 return NULL; | |
187 } | |
188 |