Mercurial > pidgin.yaz
annotate src/protocols/msn/session.c @ 8175:f347c8d25cf5
[gaim-migrate @ 8889]
Make privacy stuff use an enum for different privacy options. This
started with a fix to make the box for "allow the users below" show
up when opening the privacy dialog when that option was selected.
It might be a good idea for a few people to check their privacy settings
after using this to make sure it's the same as what it used to be.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 28 Jan 2004 05:43:04 +0000 |
parents | d0ba2f7b40e7 |
children | 06f57183e29f |
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" | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
25 #include "notification.h" |
5309 | 26 |
27 MsnSession * | |
5564
187c740f2a4e
[gaim-migrate @ 5966]
Christian Hammond <chipx86@chipx86.com>
parents:
5518
diff
changeset
|
28 msn_session_new(GaimAccount *account, const char *server, int port) |
5309 | 29 { |
30 MsnSession *session; | |
31 | |
32 g_return_val_if_fail(account != NULL, NULL); | |
33 | |
34 session = g_new0(MsnSession, 1); | |
35 | |
36 session->account = account; | |
37 session->dispatch_server = g_strdup(server); | |
38 session->dispatch_port = port; | |
39 | |
7590
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
40 session->away_state = NULL; |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
41 |
5518
bf2a7a7b739d
[gaim-migrate @ 5918]
Christian Hammond <chipx86@chipx86.com>
parents:
5427
diff
changeset
|
42 session->users = msn_users_new(); |
bf2a7a7b739d
[gaim-migrate @ 5918]
Christian Hammond <chipx86@chipx86.com>
parents:
5427
diff
changeset
|
43 session->groups = msn_groups_new(); |
5309 | 44 |
6738
6c95f01aaf49
[gaim-migrate @ 7270]
Christian Hammond <chipx86@chipx86.com>
parents:
6726
diff
changeset
|
45 #ifdef HAVE_SSL |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
46 session->protocol_ver = 9; |
6726
3c234b619685
[gaim-migrate @ 7253]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
47 #else |
3c234b619685
[gaim-migrate @ 7253]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
48 session->protocol_ver = 7; |
3c234b619685
[gaim-migrate @ 7253]
Christian Hammond <chipx86@chipx86.com>
parents:
6701
diff
changeset
|
49 #endif |
6701
b7e113a59b51
[gaim-migrate @ 7227]
Christian Hammond <chipx86@chipx86.com>
parents:
5564
diff
changeset
|
50 |
5309 | 51 return session; |
52 } | |
53 | |
54 void | |
55 msn_session_destroy(MsnSession *session) | |
56 { | |
57 g_return_if_fail(session != NULL); | |
58 | |
59 if (session->connected) | |
60 msn_session_disconnect(session); | |
61 | |
62 if (session->dispatch_server != NULL) | |
63 g_free(session->dispatch_server); | |
64 | |
65 while (session->switches != NULL) | |
66 msn_switchboard_destroy(session->switches->data); | |
67 | |
68 while (session->lists.forward) | |
69 msn_user_destroy(session->lists.forward->data); | |
70 | |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
71 if (session->lists.allow != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
72 g_slist_free(session->lists.allow); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
73 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
74 if (session->lists.block != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
75 g_slist_free(session->lists.block); |
5309 | 76 |
5518
bf2a7a7b739d
[gaim-migrate @ 5918]
Christian Hammond <chipx86@chipx86.com>
parents:
5427
diff
changeset
|
77 msn_groups_destroy(session->groups); |
5309 | 78 msn_users_destroy(session->users); |
79 | |
6827
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
80 if (session->passport_info.kv != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
81 g_free(session->passport_info.kv); |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
82 |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
83 if (session->passport_info.sid != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
84 g_free(session->passport_info.sid); |
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.mspauth != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
87 g_free(session->passport_info.mspauth); |
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.file != NULL) |
1cfbb731aa1f
[gaim-migrate @ 7372]
Christian Hammond <chipx86@chipx86.com>
parents:
6779
diff
changeset
|
90 g_free(session->passport_info.file); |
5427 | 91 |
7590
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
92 if (session->away_state != NULL) |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
93 g_free(session->away_state); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
94 |
8171
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
95 if (session->nexus != NULL) |
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
96 msn_nexus_destroy(session->nexus); |
d0ba2f7b40e7
[gaim-migrate @ 8884]
Christian Hammond <chipx86@chipx86.com>
parents:
7590
diff
changeset
|
97 |
5309 | 98 g_free(session); |
99 } | |
100 | |
101 gboolean | |
102 msn_session_connect(MsnSession *session) | |
103 { | |
104 g_return_val_if_fail(session != NULL, FALSE); | |
105 g_return_val_if_fail(!session->connected, TRUE); | |
106 | |
107 session->connected = TRUE; | |
108 | |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
109 if (session->http_method) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
110 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
111 session->notification_conn = |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
112 msn_notification_new(session, "gateway.messenger.hotmail.com", 80); |
5309 | 113 |
7288
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
114 if (msn_servconn_connect(session->notification_conn)) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
115 return TRUE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
116 } |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
117 else |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
118 { |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
119 session->dispatch_conn = msn_dispatch_new(session, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
120 session->dispatch_server, |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
121 session->dispatch_port); |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
122 |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
123 if (msn_servconn_connect(session->dispatch_conn)) |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
124 return TRUE; |
ff9127038a5a
[gaim-migrate @ 7869]
Christian Hammond <chipx86@chipx86.com>
parents:
6827
diff
changeset
|
125 } |
5309 | 126 |
127 return FALSE; | |
128 } | |
129 | |
130 void | |
131 msn_session_disconnect(MsnSession *session) | |
132 { | |
133 g_return_if_fail(session != NULL); | |
134 g_return_if_fail(session->connected); | |
135 | |
136 if (session->dispatch_conn != NULL) { | |
137 msn_servconn_destroy(session->dispatch_conn); | |
138 session->dispatch_conn = NULL; | |
139 } | |
140 | |
141 while (session->switches != NULL) { | |
142 MsnSwitchBoard *board = (MsnSwitchBoard *)session->switches->data; | |
143 | |
144 msn_switchboard_destroy(board); | |
145 } | |
146 | |
147 if (session->notification_conn != NULL) { | |
148 msn_servconn_destroy(session->notification_conn); | |
149 session->notification_conn = NULL; | |
150 } | |
151 } | |
152 | |
153 MsnSwitchBoard * | |
154 msn_session_open_switchboard(MsnSession *session) | |
155 { | |
156 MsnSwitchBoard *swboard; | |
157 | |
158 g_return_val_if_fail(session != NULL, NULL); | |
159 | |
7590
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
160 if (msn_servconn_send_command(session->notification_conn, "XFR", "SB") < 0) |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
161 { |
5309 | 162 return NULL; |
163 } | |
164 | |
165 swboard = msn_switchboard_new(session); | |
166 | |
167 return swboard; | |
168 } | |
169 | |
7590
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
170 gboolean |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
171 msn_session_change_status(MsnSession *session, const char *state) |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
172 { |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
173 MsnUser *user = session->user; |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
174 MsnObject *msnobj; |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
175 char buf[MSN_BUF_LEN]; |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
176 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
177 g_return_val_if_fail(session != NULL, FALSE); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
178 g_return_val_if_fail(state != NULL, FALSE); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
179 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
180 msnobj = msn_user_get_object(user); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
181 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
182 if (state != session->away_state) |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
183 { |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
184 if (session->away_state != NULL) |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
185 g_free(session->away_state); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
186 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
187 session->away_state = g_strdup(state); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
188 } |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
189 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
190 if (msnobj == NULL) |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
191 g_snprintf(buf, sizeof(buf), "%s %d", state, MSN_CLIENT_ID); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
192 else |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
193 { |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
194 char *msnobj_str = msn_object_to_string(msnobj); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
195 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
196 g_snprintf(buf, sizeof(buf), "%s %d %s", state, MSN_CLIENT_ID, |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
197 gaim_url_encode(msnobj_str)); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
198 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
199 g_free(msnobj_str); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
200 } |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
201 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
202 if (!msn_servconn_send_command(session->notification_conn, "CHG", buf)) |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
203 { |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
204 gaim_connection_error(gaim_account_get_connection(session->account), |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
205 _("Write error")); |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
206 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
207 return FALSE; |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
208 } |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
209 |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
210 return TRUE; |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
211 } |
3a48ade4f510
[gaim-migrate @ 8208]
Christian Hammond <chipx86@chipx86.com>
parents:
7288
diff
changeset
|
212 |
5309 | 213 MsnSwitchBoard * |
214 msn_session_find_switch_with_passport(const MsnSession *session, | |
215 const char *passport) | |
216 { | |
217 GList *l; | |
218 MsnSwitchBoard *swboard; | |
219 | |
220 g_return_val_if_fail(session != NULL, NULL); | |
221 g_return_val_if_fail(passport != NULL, NULL); | |
222 | |
223 for (l = session->switches; l != NULL; l = l->next) { | |
224 swboard = (MsnSwitchBoard *)l->data; | |
225 | |
5351
2aa7e4237142
[gaim-migrate @ 5727]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
226 if (!swboard->hidden && |
2aa7e4237142
[gaim-migrate @ 5727]
Christian Hammond <chipx86@chipx86.com>
parents:
5318
diff
changeset
|
227 !g_ascii_strcasecmp(passport, |
5309 | 228 msn_user_get_passport(swboard->user))) { |
229 return swboard; | |
230 } | |
231 } | |
232 | |
233 return NULL; | |
234 } | |
235 | |
236 MsnSwitchBoard * | |
237 msn_session_find_switch_with_id(const MsnSession *session, int chat_id) | |
238 { | |
239 GList *l; | |
240 MsnSwitchBoard *swboard; | |
241 | |
242 g_return_val_if_fail(session != NULL, NULL); | |
243 g_return_val_if_fail(chat_id > 0, NULL); | |
244 | |
245 for (l = session->switches; l != NULL; l = l->next) { | |
246 swboard = (MsnSwitchBoard *)l->data; | |
247 | |
248 if (swboard->chat_id == chat_id) | |
249 return swboard; | |
250 } | |
251 | |
252 return NULL; | |
253 } | |
254 | |
255 MsnSwitchBoard * | |
256 msn_session_find_unused_switch(const MsnSession *session) | |
257 { | |
258 GList *l; | |
259 MsnSwitchBoard *swboard; | |
260 | |
261 g_return_val_if_fail(session != NULL, NULL); | |
262 | |
263 for (l = session->switches; l != NULL; l = l->next) { | |
264 swboard = (MsnSwitchBoard *)l->data; | |
265 | |
5354
8a74fbcb7bcb
[gaim-migrate @ 5730]
Christian Hammond <chipx86@chipx86.com>
parents:
5351
diff
changeset
|
266 if (!swboard->in_use) |
5309 | 267 return swboard; |
268 } | |
269 | |
270 return NULL; | |
271 } |