Mercurial > pidgin
annotate src/protocols/msn/session.c @ 7162:d14e026611c0
[gaim-migrate @ 7729]
constificating the countryside
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Sun, 05 Oct 2003 18:32:43 +0000 |
parents | 1cfbb731aa1f |
children | ff9127038a5a |
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> | |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
7 * |
5309 | 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 * | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5518
diff
changeset
|
27 msn_session_new(GaimAccount *account, const char *server, int port) |
5309 | 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 | |
5518
bf2a7a7b739d
[gaim-migrate @ 5918]
Christian Hammond <chipx86@chipx86.com>
parents:
5427
diff
changeset
|
39 session->users = msn_users_new(); |
bf2a7a7b739d
[gaim-migrate @ 5918]
Christian Hammond <chipx86@chipx86.com>
parents:
5427
diff
changeset
|
40 session->groups = msn_groups_new(); |
5309 | 41 |
6738
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6726
diff
changeset
|
42 #ifdef HAVE_SSL |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
43 session->protocol_ver = 9; |
6726
3c234b619685
[gaim-migrate @ 7253]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
44 #else |
3c234b619685
[gaim-migrate @ 7253]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
45 session->protocol_ver = 7; |
3c234b619685
[gaim-migrate @ 7253]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
46 #endif |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
47 |
5309 | 48 return session; |
49 } | |
50 | |
51 void | |
52 msn_session_destroy(MsnSession *session) | |
53 { | |
54 g_return_if_fail(session != NULL); | |
55 | |
56 if (session->connected) | |
57 msn_session_disconnect(session); | |
58 | |
59 if (session->dispatch_server != NULL) | |
60 g_free(session->dispatch_server); | |
61 | |
6779 | 62 if (session->ssl_login_path != NULL) |
63 g_free(session->ssl_login_path); | |
64 | |
65 if (session->ssl_login_host != NULL) | |
66 g_free(session->ssl_login_host); | |
67 | |
5309 | 68 while (session->switches != NULL) |
69 msn_switchboard_destroy(session->switches->data); | |
70 | |
71 while (session->lists.forward) | |
72 msn_user_destroy(session->lists.forward->data); | |
73 | |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
74 if (session->lists.allow != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
75 g_slist_free(session->lists.allow); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
76 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
77 if (session->lists.block != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
78 g_slist_free(session->lists.block); |
5309 | 79 |
5518
bf2a7a7b739d
[gaim-migrate @ 5918]
Christian Hammond <chipx86@chipx86.com>
parents:
5427
diff
changeset
|
80 msn_groups_destroy(session->groups); |
5309 | 81 msn_users_destroy(session->users); |
82 | |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
83 if (session->passport_info.kv != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
84 g_free(session->passport_info.kv); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
85 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
86 if (session->passport_info.sid != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
87 g_free(session->passport_info.sid); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
88 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
89 if (session->passport_info.mspauth != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
90 g_free(session->passport_info.mspauth); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
91 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
92 if (session->passport_info.file != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
93 g_free(session->passport_info.file); |
5427 | 94 |
5309 | 95 g_free(session); |
96 } | |
97 | |
98 gboolean | |
99 msn_session_connect(MsnSession *session) | |
100 { | |
101 g_return_val_if_fail(session != NULL, FALSE); | |
102 g_return_val_if_fail(!session->connected, TRUE); | |
103 | |
104 session->connected = TRUE; | |
105 | |
106 session->dispatch_conn = msn_dispatch_new(session, | |
107 session->dispatch_server, | |
108 session->dispatch_port); | |
109 | |
110 if (msn_servconn_connect(session->dispatch_conn)) | |
111 return TRUE; | |
112 | |
113 return FALSE; | |
114 } | |
115 | |
116 void | |
117 msn_session_disconnect(MsnSession *session) | |
118 { | |
119 g_return_if_fail(session != NULL); | |
120 g_return_if_fail(session->connected); | |
121 | |
122 if (session->dispatch_conn != NULL) { | |
123 msn_servconn_destroy(session->dispatch_conn); | |
124 session->dispatch_conn = NULL; | |
125 } | |
126 | |
127 while (session->switches != NULL) { | |
128 MsnSwitchBoard *board = (MsnSwitchBoard *)session->switches->data; | |
129 | |
130 msn_switchboard_destroy(board); | |
131 } | |
132 | |
133 if (session->notification_conn != NULL) { | |
134 msn_servconn_destroy(session->notification_conn); | |
135 session->notification_conn = NULL; | |
136 } | |
137 } | |
138 | |
139 MsnSwitchBoard * | |
140 msn_session_open_switchboard(MsnSession *session) | |
141 { | |
142 MsnSwitchBoard *swboard; | |
143 | |
144 g_return_val_if_fail(session != NULL, NULL); | |
145 | |
146 if (msn_servconn_send_command(session->notification_conn, | |
147 "XFR", "SB") < 0) { | |
148 return NULL; | |
149 } | |
150 | |
151 swboard = msn_switchboard_new(session); | |
152 | |
153 return swboard; | |
154 } | |
155 | |
156 MsnSwitchBoard * | |
157 msn_session_find_switch_with_passport(const MsnSession *session, | |
158 const char *passport) | |
159 { | |
160 GList *l; | |
161 MsnSwitchBoard *swboard; | |
162 | |
163 g_return_val_if_fail(session != NULL, NULL); | |
164 g_return_val_if_fail(passport != NULL, NULL); | |
165 | |
166 for (l = session->switches; l != NULL; l = l->next) { | |
167 swboard = (MsnSwitchBoard *)l->data; | |
168 | |
5351
2aa7e4237142
[gaim-migrate @ 5727]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
169 if (!swboard->hidden && |
2aa7e4237142
[gaim-migrate @ 5727]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
170 !g_ascii_strcasecmp(passport, |
5309 | 171 msn_user_get_passport(swboard->user))) { |
172 return swboard; | |
173 } | |
174 } | |
175 | |
176 return NULL; | |
177 } | |
178 | |
179 MsnSwitchBoard * | |
180 msn_session_find_switch_with_id(const MsnSession *session, int chat_id) | |
181 { | |
182 GList *l; | |
183 MsnSwitchBoard *swboard; | |
184 | |
185 g_return_val_if_fail(session != NULL, NULL); | |
186 g_return_val_if_fail(chat_id > 0, NULL); | |
187 | |
188 for (l = session->switches; l != NULL; l = l->next) { | |
189 swboard = (MsnSwitchBoard *)l->data; | |
190 | |
191 if (swboard->chat_id == chat_id) | |
192 return swboard; | |
193 } | |
194 | |
195 return NULL; | |
196 } | |
197 | |
198 MsnSwitchBoard * | |
199 msn_session_find_unused_switch(const MsnSession *session) | |
200 { | |
201 GList *l; | |
202 MsnSwitchBoard *swboard; | |
203 | |
204 g_return_val_if_fail(session != NULL, NULL); | |
205 | |
206 for (l = session->switches; l != NULL; l = l->next) { | |
207 swboard = (MsnSwitchBoard *)l->data; | |
208 | |
5354
8a74fbcb7bcb
[gaim-migrate @ 5730]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
209 if (!swboard->in_use) |
5309 | 210 return swboard; |
211 } | |
212 | |
213 return NULL; | |
214 } | |
215 |