Mercurial > pidgin.yaz
annotate src/protocols/msn/nexus.c @ 9193:502707ca1836
[gaim-migrate @ 9988]
Patch by Felipe Contreras to add MSN file transfer and buddy icons. Please
test and report any bugs!
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Sun, 06 Jun 2004 02:39:08 +0000 |
parents | 577c76e1442d |
children | ab6636c5a136 |
rev | line source |
---|---|
8171 | 1 #include "msn.h" |
2 #include "nexus.h" | |
3 #include "notification.h" | |
4 | |
5 /************************************************************************** | |
6 * Util | |
7 **************************************************************************/ | |
8 | |
9 static size_t | |
10 msn_ssl_read(GaimSslConnection *gsc, char **dest_buffer) | |
11 { | |
8925 | 12 gssize size = 0, s; |
8171 | 13 char *buffer = NULL; |
14 char temp_buf[4096]; | |
15 | |
16 while ((s = gaim_ssl_read(gsc, temp_buf, sizeof(temp_buf))) > 0) | |
17 { | |
18 buffer = g_realloc(buffer, size + s + 1); | |
19 | |
20 strncpy(buffer + size, temp_buf, s); | |
21 | |
22 buffer[size + s] = '\0'; | |
23 | |
24 size += s; | |
25 } | |
26 | |
27 *dest_buffer = buffer; | |
28 | |
29 return size; | |
30 } | |
31 | |
32 /************************************************************************** | |
33 * Login | |
34 **************************************************************************/ | |
35 | |
36 static void | |
37 login_error_cb(GaimSslConnection *gsc, GaimSslErrorType error, void *data) | |
38 { | |
39 MsnNexus *nexus; | |
40 MsnSession *session; | |
41 GaimAccount *account; | |
42 GaimConnection *gc; | |
43 | |
44 nexus = data; | |
45 g_return_if_fail(nexus != NULL); | |
46 | |
47 session = nexus->session; | |
48 g_return_if_fail(session != NULL); | |
49 | |
50 account = session->account; | |
51 g_return_if_fail(account != NULL); | |
52 | |
53 gc = gaim_account_get_connection(account); | |
54 g_return_if_fail(gc != NULL); | |
55 | |
56 gaim_connection_error(gc, _("Unable to connect to server")); | |
57 | |
58 msn_nexus_destroy(nexus); | |
59 session->nexus = NULL; | |
60 } | |
61 | |
62 static void | |
63 login_connect_cb(gpointer data, GaimSslConnection *gsc, | |
64 GaimInputCondition cond) | |
65 { | |
66 MsnNexus *nexus; | |
67 MsnSession *session; | |
68 char *username, *password; | |
69 char *request_str; | |
70 char *buffer = NULL; | |
71 size_t s; | |
72 | |
73 nexus = data; | |
74 g_return_if_fail(nexus != NULL); | |
75 | |
76 session = nexus->session; | |
77 g_return_if_fail(session != NULL); | |
78 | |
79 username = | |
80 g_strdup(gaim_url_encode(gaim_account_get_username(session->account))); | |
81 | |
82 password = | |
83 g_strdup(gaim_url_encode(gaim_account_get_password(session->account))); | |
84 | |
85 request_str = g_strdup_printf( | |
86 "GET %s HTTP/1.1\r\n" | |
87 "Authorization: Passport1.4 OrgVerb=GET,OrgURL=%s,sign-in=%s,pwd=%s," | |
88 "lc=%s,id=%s,tw=%s,fs=%s,ru=%s,ct=%s,kpp=%s,kv=%s,ver=%s,tpf=%s\r\n" | |
89 "User-Agent: MSMSGS\r\n" | |
90 "Host: %s\r\n" | |
91 "Connection: Keep-Alive\r\n" | |
92 "Cache-Control: no-cache\r\n" | |
93 "\r\n", | |
94 nexus->login_path, | |
95 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
96 username, password, | |
97 (char *)g_hash_table_lookup(nexus->challenge_data, "lc"), | |
98 (char *)g_hash_table_lookup(nexus->challenge_data, "id"), | |
99 (char *)g_hash_table_lookup(nexus->challenge_data, "tw"), | |
100 (char *)g_hash_table_lookup(nexus->challenge_data, "fs"), | |
101 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
102 (char *)g_hash_table_lookup(nexus->challenge_data, "ct"), | |
103 (char *)g_hash_table_lookup(nexus->challenge_data, "kpp"), | |
104 (char *)g_hash_table_lookup(nexus->challenge_data, "kv"), | |
105 (char *)g_hash_table_lookup(nexus->challenge_data, "ver"), | |
106 (char *)g_hash_table_lookup(nexus->challenge_data, "tpf"), | |
107 nexus->login_host); | |
108 | |
109 gaim_debug(GAIM_DEBUG_MISC, "msn", "Sending: {%s}\n", request_str); | |
110 | |
111 g_free(username); | |
112 g_free(password); | |
113 | |
114 if ((s = gaim_ssl_write(gsc, request_str, strlen(request_str))) <= 0) | |
115 { | |
116 g_free(request_str); | |
117 | |
118 return; | |
119 } | |
120 | |
121 g_free(request_str); | |
122 | |
123 if ((s = msn_ssl_read(gsc, &buffer)) <= 0) | |
124 return; | |
125 | |
126 gaim_ssl_close(gsc); | |
127 | |
128 gaim_debug(GAIM_DEBUG_MISC, "msn", "ssl buffer: {%s}", buffer); | |
129 | |
130 if (strstr(buffer, "HTTP/1.1 302") != NULL) | |
131 { | |
132 /* Redirect. */ | |
133 char *location, *c; | |
134 | |
135 location = strstr(buffer, "Location: "); | |
136 if (location == NULL) | |
137 { | |
138 g_free(buffer); | |
139 | |
140 return; | |
141 } | |
142 location = strchr(location, ' ') + 1; | |
143 | |
144 if ((c = strchr(location, '\r')) != NULL) | |
145 *c = '\0'; | |
146 | |
147 /* Skip the http:// */ | |
148 if ((c = strchr(location, '/')) != NULL) | |
149 location = c + 2; | |
150 | |
151 if ((c = strchr(location, '/')) != NULL) | |
152 { | |
153 g_free(nexus->login_path); | |
154 nexus->login_path = g_strdup(c); | |
155 | |
156 *c = '\0'; | |
157 } | |
158 | |
159 g_free(nexus->login_host); | |
160 nexus->login_host = g_strdup(location); | |
161 | |
162 gaim_ssl_connect(session->account, nexus->login_host, | |
163 GAIM_SSL_DEFAULT_PORT, login_connect_cb, | |
164 login_error_cb, nexus); | |
165 } | |
166 else if (strstr(buffer, "HTTP/1.1 401 Unauthorized") != NULL) | |
167 { | |
168 GaimConnection *gc; | |
169 const char *error, *c; | |
170 char *temp; | |
171 | |
172 if ((error = strstr(buffer, "WWW-Authenticate")) != NULL) | |
173 { | |
174 if ((error = strstr(error, "cbtxt=")) != NULL) | |
175 { | |
176 error += strlen("cbtxt="); | |
177 | |
178 if ((c = strchr(error, '\n')) == NULL) | |
179 c = error + strlen(error); | |
180 | |
181 temp = g_strndup(error, c - error); | |
182 error = gaim_url_decode(temp); | |
183 g_free(temp); | |
184 } | |
185 } | |
186 | |
187 gc = gaim_account_get_connection(session->account); | |
188 | |
189 if (error == NULL) | |
190 { | |
191 gaim_connection_error(gc, | |
192 _("Unknown error when attempting to authorize with " | |
193 "MSN login server.")); | |
194 } | |
195 else | |
196 gaim_connection_error(gc, error); | |
197 } | |
198 else if (strstr(buffer, "HTTP/1.1 200 OK")) | |
199 { | |
200 char *base, *c; | |
201 char *login_params; | |
202 | |
203 #if 0 | |
204 /* All your base are belong to us. */ | |
205 base = buffer; | |
206 | |
207 /* For great cookie! */ | |
208 while ((base = strstr(base, "Set-Cookie: ")) != NULL) | |
209 { | |
210 base += strlen("Set-Cookie: "); | |
211 | |
212 c = strchr(base, ';'); | |
213 | |
214 session->login_cookies = | |
215 g_list_append(session->login_cookies, | |
216 g_strndup(base, c - base)); | |
217 } | |
218 #endif | |
219 | |
220 base = strstr(buffer, "Authentication-Info: "); | |
221 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8925
diff
changeset
|
222 g_return_if_fail(base != NULL); |
8171 | 223 |
224 base = strstr(base, "from-PP='"); | |
225 base += strlen("from-PP='"); | |
226 c = strchr(base, '\''); | |
227 | |
228 login_params = g_strndup(base, c - base); | |
229 | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8925
diff
changeset
|
230 msn_got_login_params(session, login_params); |
8171 | 231 |
232 g_free(login_params); | |
233 | |
234 msn_nexus_destroy(nexus); | |
235 session->nexus = NULL; | |
236 } | |
237 | |
238 g_free(buffer); | |
239 } | |
240 | |
241 static void | |
242 nexus_connect_cb(gpointer data, GaimSslConnection *gsc, | |
243 GaimInputCondition cond) | |
244 { | |
245 MsnNexus *nexus; | |
246 MsnSession *session; | |
247 char *request_str; | |
248 char *da_login; | |
249 char *base, *c; | |
250 char *buffer = NULL; | |
251 size_t s; | |
252 | |
253 nexus = data; | |
254 g_return_if_fail(nexus != NULL); | |
255 | |
256 session = nexus->session; | |
257 g_return_if_fail(session != NULL); | |
258 | |
259 request_str = g_strdup_printf("GET /rdr/pprdr.asp\r\n\r\n"); | |
260 | |
261 if ((s = gaim_ssl_write(gsc, request_str, strlen(request_str))) <= 0) | |
262 { | |
263 g_free(request_str); | |
264 return; | |
265 } | |
266 | |
267 g_free(request_str); | |
268 | |
269 /* Get the PassportURLs line. */ | |
270 if ((s = msn_ssl_read(gsc, &buffer)) <= 0) | |
271 return; | |
272 | |
273 base = strstr(buffer, "PassportURLs"); | |
274 | |
275 if (base == NULL) | |
276 { | |
277 g_free(buffer); | |
278 return; | |
279 } | |
280 | |
281 if ((da_login = strstr(base, "DALogin=")) != NULL) | |
282 { | |
283 if ((da_login = strchr(da_login, '=')) != NULL) | |
284 da_login++; | |
285 | |
286 if ((c = strchr(da_login, ',')) != NULL) | |
287 *c = '\0'; | |
288 | |
289 if ((c = strchr(da_login, '/')) != NULL) | |
290 { | |
291 nexus->login_path = g_strdup(c); | |
292 | |
293 *c = '\0'; | |
294 } | |
295 | |
296 nexus->login_host = g_strdup(da_login); | |
297 } | |
298 | |
299 g_free(buffer); | |
300 | |
301 gaim_ssl_close(gsc); | |
302 | |
303 /* Now begin the connection to the login server. */ | |
304 gaim_ssl_connect(session->account, nexus->login_host, | |
305 GAIM_SSL_DEFAULT_PORT, login_connect_cb, | |
306 login_error_cb, nexus); | |
307 } | |
308 | |
309 /************************************************************************** | |
310 * Nexus | |
311 **************************************************************************/ | |
312 | |
313 MsnNexus * | |
314 msn_nexus_new(MsnSession *session) | |
315 { | |
316 MsnNexus *nexus; | |
317 | |
318 nexus = g_new0(MsnNexus, 1); | |
319 nexus->session = session; | |
320 nexus->challenge_data = g_hash_table_new_full(g_str_hash, g_str_equal, | |
321 g_free, g_free); | |
322 | |
323 return nexus; | |
324 } | |
325 | |
326 void | |
327 msn_nexus_destroy(MsnNexus *nexus) | |
328 { | |
329 if (nexus->login_host != NULL) | |
330 g_free(nexus->login_host); | |
331 | |
332 if (nexus->login_path != NULL) | |
333 g_free(nexus->login_path); | |
334 | |
335 if (nexus->challenge_data != NULL) | |
336 g_hash_table_destroy(nexus->challenge_data); | |
337 | |
338 g_free(nexus); | |
339 } | |
340 | |
341 void | |
342 msn_nexus_connect(MsnNexus *nexus) | |
343 { | |
344 gaim_ssl_connect(nexus->session->account, "nexus.passport.com", | |
345 GAIM_SSL_DEFAULT_PORT, nexus_connect_cb, | |
346 login_error_cb, nexus); | |
347 } |