Mercurial > pidgin
annotate src/protocols/msn/nexus.c @ 11435:1a2eaba2bc13
[gaim-migrate @ 13672]
Some autotools tweak from Kevin Stange to let autogen.sh pass with automake 1.9
committer: Tailor Script <tailor@pidgin.im>
author | Gary Kramlich <grim@reaperworld.com> |
---|---|
date | Sun, 04 Sep 2005 02:03:48 +0000 |
parents | 94cc67130789 |
children | e585695bc16b |
rev | line source |
---|---|
9198
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
1 /** |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
2 * @file nexus.c MSN Nexus functions |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
3 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
4 * gaim |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
5 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
6 * Gaim is the legal property of its developers, whose names are too numerous |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
7 * to list here. Please refer to the COPYRIGHT file distributed with this |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
8 * source distribution. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
9 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
10 * This program is free software; you can redistribute it and/or modify |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
11 * it under the terms of the GNU General Public License as published by |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
12 * the Free Software Foundation; either version 2 of the License, or |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
13 * (at your option) any later version. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
14 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
15 * This program is distributed in the hope that it will be useful, |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
18 * GNU General Public License for more details. |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
19 * |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
20 * You should have received a copy of the GNU General Public License |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
21 * along with this program; if not, write to the Free Software |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
ab6636c5a136
[gaim-migrate @ 9993]
Christian Hammond <chipx86@chipx86.com>
parents:
9193
diff
changeset
|
23 */ |
8171 | 24 #include "msn.h" |
25 #include "nexus.h" | |
26 #include "notification.h" | |
27 | |
28 /************************************************************************** | |
10481 | 29 * Main |
30 **************************************************************************/ | |
31 | |
32 MsnNexus * | |
33 msn_nexus_new(MsnSession *session) | |
34 { | |
35 MsnNexus *nexus; | |
36 | |
37 nexus = g_new0(MsnNexus, 1); | |
38 nexus->session = session; | |
39 nexus->challenge_data = g_hash_table_new_full(g_str_hash, g_str_equal, | |
40 g_free, g_free); | |
41 | |
42 return nexus; | |
43 } | |
44 | |
45 void | |
46 msn_nexus_destroy(MsnNexus *nexus) | |
47 { | |
48 if (nexus->login_host != NULL) | |
49 g_free(nexus->login_host); | |
50 | |
51 if (nexus->login_path != NULL) | |
52 g_free(nexus->login_path); | |
53 | |
54 if (nexus->challenge_data != NULL) | |
55 g_hash_table_destroy(nexus->challenge_data); | |
56 | |
57 g_free(nexus); | |
58 } | |
59 | |
60 /************************************************************************** | |
8171 | 61 * Util |
62 **************************************************************************/ | |
63 | |
64 static size_t | |
65 msn_ssl_read(GaimSslConnection *gsc, char **dest_buffer) | |
66 { | |
8925 | 67 gssize size = 0, s; |
8171 | 68 char *buffer = NULL; |
69 char temp_buf[4096]; | |
70 | |
71 while ((s = gaim_ssl_read(gsc, temp_buf, sizeof(temp_buf))) > 0) | |
72 { | |
73 buffer = g_realloc(buffer, size + s + 1); | |
74 | |
75 strncpy(buffer + size, temp_buf, s); | |
76 | |
77 buffer[size + s] = '\0'; | |
78 | |
79 size += s; | |
80 } | |
81 | |
82 *dest_buffer = buffer; | |
83 | |
84 return size; | |
85 } | |
86 | |
87 /************************************************************************** | |
88 * Login | |
89 **************************************************************************/ | |
90 | |
91 static void | |
92 login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) | |
93 { | |
94 MsnNexus *nexus; | |
95 MsnSession *session; | |
96 | |
97 nexus = data; | |
98 g_return_if_fail(nexus != NULL); | |
99 | |
100 session = nexus->session; | |
101 g_return_if_fail(session != NULL); | |
102 | |
10481 | 103 msn_session_set_error(session, MSN_ERROR_AUTH, _("Unable to connect")); |
10568 | 104 /* the above line will result in nexus being destroyed, so we don't want |
105 * to destroy it here, or we'd crash */ | |
8171 | 106 } |
107 | |
108 static void | |
109 login_connect_cb(gpointer data, GaimSslConnection *gsc, | |
110 GaimInputCondition cond) | |
111 { | |
112 MsnNexus *nexus; | |
113 MsnSession *session; | |
114 char *username, *password; | |
115 char *request_str; | |
116 char *buffer = NULL; | |
9966 | 117 guint32 ctint; |
8171 | 118 size_t s; |
119 | |
120 nexus = data; | |
121 g_return_if_fail(nexus != NULL); | |
122 | |
123 session = nexus->session; | |
124 g_return_if_fail(session != NULL); | |
125 | |
10519 | 126 msn_session_set_login_step(session, MSN_LOGIN_STEP_GET_COOKIE); |
10481 | 127 |
8171 | 128 username = |
129 g_strdup(gaim_url_encode(gaim_account_get_username(session->account))); | |
130 | |
131 password = | |
10740 | 132 g_strdup(gaim_url_encode(gaim_connection_get_password(session->account->gc))); |
8171 | 133 |
9966 | 134 ctint = strtoul((char *)g_hash_table_lookup(nexus->challenge_data, "ct"), NULL, 10) + 200; |
135 | |
8171 | 136 request_str = g_strdup_printf( |
137 "GET %s HTTP/1.1\r\n" | |
138 "Authorization: Passport1.4 OrgVerb=GET,OrgURL=%s,sign-in=%s,pwd=%s," | |
9966 | 139 "lc=%s,id=%s,tw=%s,fs=%s,ru=%s,ct=%" G_GUINT32_FORMAT ",kpp=%s,kv=%s,ver=%s,tpf=%s\r\n" |
8171 | 140 "User-Agent: MSMSGS\r\n" |
141 "Host: %s\r\n" | |
142 "Connection: Keep-Alive\r\n" | |
143 "Cache-Control: no-cache\r\n" | |
144 "\r\n", | |
145 nexus->login_path, | |
146 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
147 username, password, | |
148 (char *)g_hash_table_lookup(nexus->challenge_data, "lc"), | |
149 (char *)g_hash_table_lookup(nexus->challenge_data, "id"), | |
150 (char *)g_hash_table_lookup(nexus->challenge_data, "tw"), | |
151 (char *)g_hash_table_lookup(nexus->challenge_data, "fs"), | |
152 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
9966 | 153 ctint, |
8171 | 154 (char *)g_hash_table_lookup(nexus->challenge_data, "kpp"), |
155 (char *)g_hash_table_lookup(nexus->challenge_data, "kv"), | |
156 (char *)g_hash_table_lookup(nexus->challenge_data, "ver"), | |
157 (char *)g_hash_table_lookup(nexus->challenge_data, "tpf"), | |
158 nexus->login_host); | |
159 | |
10345 | 160 gaim_debug_misc("msn", "Sending: {%s}\n", request_str); |
8171 | 161 |
162 g_free(username); | |
163 g_free(password); | |
164 | |
165 if ((s = gaim_ssl_write(gsc, request_str, strlen(request_str))) <= 0) | |
166 { | |
167 g_free(request_str); | |
168 | |
169 return; | |
170 } | |
171 | |
172 g_free(request_str); | |
173 | |
174 if ((s = msn_ssl_read(gsc, &buffer)) <= 0) | |
175 return; | |
176 | |
177 gaim_ssl_close(gsc); | |
178 | |
10345 | 179 gaim_debug_misc("msn", "ssl buffer: {%s}", buffer); |
8171 | 180 |
181 if (strstr(buffer, "HTTP/1.1 302") != NULL) | |
182 { | |
183 /* Redirect. */ | |
184 char *location, *c; | |
185 | |
186 location = strstr(buffer, "Location: "); | |
187 if (location == NULL) | |
188 { | |
189 g_free(buffer); | |
190 | |
191 return; | |
192 } | |
193 location = strchr(location, ' ') + 1; | |
194 | |
195 if ((c = strchr(location, '\r')) != NULL) | |
196 *c = '\0'; | |
197 | |
198 /* Skip the http:// */ | |
199 if ((c = strchr(location, '/')) != NULL) | |
200 location = c + 2; | |
201 | |
202 if ((c = strchr(location, '/')) != NULL) | |
203 { | |
204 g_free(nexus->login_path); | |
205 nexus->login_path = g_strdup(c); | |
206 | |
207 *c = '\0'; | |
208 } | |
209 | |
210 g_free(nexus->login_host); | |
211 nexus->login_host = g_strdup(location); | |
212 | |
213 gaim_ssl_connect(session->account, nexus->login_host, | |
214 GAIM_SSL_DEFAULT_PORT, login_connect_cb, | |
215 login_error_cb, nexus); | |
216 } | |
217 else if (strstr(buffer, "HTTP/1.1 401 Unauthorized") != NULL) | |
218 { | |
10481 | 219 const char *error; |
8171 | 220 |
221 if ((error = strstr(buffer, "WWW-Authenticate")) != NULL) | |
222 { | |
223 if ((error = strstr(error, "cbtxt=")) != NULL) | |
224 { | |
10481 | 225 const char *c; |
226 char *temp; | |
227 | |
8171 | 228 error += strlen("cbtxt="); |
229 | |
230 if ((c = strchr(error, '\n')) == NULL) | |
231 c = error + strlen(error); | |
232 | |
233 temp = g_strndup(error, c - error); | |
234 error = gaim_url_decode(temp); | |
235 g_free(temp); | |
236 } | |
237 } | |
238 | |
10481 | 239 msn_session_set_error(session, MSN_ERROR_AUTH, error); |
8171 | 240 } |
241 else if (strstr(buffer, "HTTP/1.1 200 OK")) | |
242 { | |
243 char *base, *c; | |
244 char *login_params; | |
245 | |
246 #if 0 | |
247 /* All your base are belong to us. */ | |
248 base = buffer; | |
249 | |
250 /* For great cookie! */ | |
251 while ((base = strstr(base, "Set-Cookie: ")) != NULL) | |
252 { | |
253 base += strlen("Set-Cookie: "); | |
254 | |
255 c = strchr(base, ';'); | |
256 | |
257 session->login_cookies = | |
258 g_list_append(session->login_cookies, | |
259 g_strndup(base, c - base)); | |
260 } | |
261 #endif | |
262 | |
263 base = strstr(buffer, "Authentication-Info: "); | |
264 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8925
diff
changeset
|
265 g_return_if_fail(base != NULL); |
8171 | 266 |
267 base = strstr(base, "from-PP='"); | |
268 base += strlen("from-PP='"); | |
269 c = strchr(base, '\''); | |
270 | |
271 login_params = g_strndup(base, c - base); | |
272 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8925
diff
changeset
|
273 msn_got_login_params(session, login_params); |
8171 | 274 |
275 g_free(login_params); | |
276 | |
277 msn_nexus_destroy(nexus); | |
278 session->nexus = NULL; | |
279 } | |
280 | |
281 g_free(buffer); | |
282 } | |
283 | |
10481 | 284 /************************************************************************** |
285 * Connect | |
286 **************************************************************************/ | |
287 | |
8171 | 288 static void |
289 nexus_connect_cb(gpointer data, GaimSslConnection *gsc, | |
290 GaimInputCondition cond) | |
291 { | |
292 MsnNexus *nexus; | |
293 MsnSession *session; | |
294 char *request_str; | |
295 char *da_login; | |
296 char *base, *c; | |
297 char *buffer = NULL; | |
298 size_t s; | |
299 | |
300 nexus = data; | |
301 g_return_if_fail(nexus != NULL); | |
302 | |
303 session = nexus->session; | |
304 g_return_if_fail(session != NULL); | |
305 | |
10519 | 306 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH); |
10481 | 307 |
8171 | 308 request_str = g_strdup_printf("GET /rdr/pprdr.asp\r\n\r\n"); |
309 | |
310 if ((s = gaim_ssl_write(gsc, request_str, strlen(request_str))) <= 0) | |
311 { | |
312 g_free(request_str); | |
313 return; | |
314 } | |
315 | |
316 g_free(request_str); | |
317 | |
318 /* Get the PassportURLs line. */ | |
319 if ((s = msn_ssl_read(gsc, &buffer)) <= 0) | |
320 return; | |
321 | |
322 base = strstr(buffer, "PassportURLs"); | |
323 | |
324 if (base == NULL) | |
325 { | |
326 g_free(buffer); | |
327 return; | |
328 } | |
329 | |
330 if ((da_login = strstr(base, "DALogin=")) != NULL) | |
331 { | |
332 if ((da_login = strchr(da_login, '=')) != NULL) | |
333 da_login++; | |
334 | |
335 if ((c = strchr(da_login, ',')) != NULL) | |
336 *c = '\0'; | |
337 | |
338 if ((c = strchr(da_login, '/')) != NULL) | |
339 { | |
340 nexus->login_path = g_strdup(c); | |
341 | |
342 *c = '\0'; | |
343 } | |
344 | |
345 nexus->login_host = g_strdup(da_login); | |
346 } | |
347 | |
348 g_free(buffer); | |
349 | |
350 gaim_ssl_close(gsc); | |
351 | |
352 /* Now begin the connection to the login server. */ | |
353 gaim_ssl_connect(session->account, nexus->login_host, | |
354 GAIM_SSL_DEFAULT_PORT, login_connect_cb, | |
355 login_error_cb, nexus); | |
356 } | |
357 | |
358 void | |
359 msn_nexus_connect(MsnNexus *nexus) | |
360 { | |
361 gaim_ssl_connect(nexus->session->account, "nexus.passport.com", | |
362 GAIM_SSL_DEFAULT_PORT, nexus_connect_cb, | |
363 login_error_cb, nexus); | |
364 } |