Mercurial > pidgin
annotate src/protocols/msn/nexus.c @ 12662:eb4841fa697c
[gaim-migrate @ 15005]
sf bug #1385691, Text field visible even when status set to "online"
Don't allow available messages for ICQ. The server doesn't support them.
committer: Tailor Script <tailor@pidgin.im>
| author | Mark Doliner <mark@kingant.net> |
|---|---|
| date | Mon, 26 Dec 2005 07:43:41 +0000 |
| parents | e585695bc16b |
| children | 33bef17125c2 |
| 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; | |
| 12457 | 115 char *request_str, *head, *tail; |
| 8171 | 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 | |
| 12457 | 136 head = g_strdup_printf( |
| 8171 | 137 "GET %s HTTP/1.1\r\n" |
| 12457 | 138 "Authorization: Passport1.4 OrgVerb=GET,OrgURL=%s,sign-in=%s", |
| 139 nexus->login_path, | |
| 140 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
| 141 username); | |
| 142 | |
| 143 tail = g_strdup_printf( | |
| 9966 | 144 "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 | 145 "User-Agent: MSMSGS\r\n" |
| 146 "Host: %s\r\n" | |
| 147 "Connection: Keep-Alive\r\n" | |
| 12457 | 148 "Cache-Control: no-cache\r\n", |
| 8171 | 149 (char *)g_hash_table_lookup(nexus->challenge_data, "lc"), |
| 150 (char *)g_hash_table_lookup(nexus->challenge_data, "id"), | |
| 151 (char *)g_hash_table_lookup(nexus->challenge_data, "tw"), | |
| 152 (char *)g_hash_table_lookup(nexus->challenge_data, "fs"), | |
| 153 (char *)g_hash_table_lookup(nexus->challenge_data, "ru"), | |
| 9966 | 154 ctint, |
| 8171 | 155 (char *)g_hash_table_lookup(nexus->challenge_data, "kpp"), |
| 156 (char *)g_hash_table_lookup(nexus->challenge_data, "kv"), | |
| 157 (char *)g_hash_table_lookup(nexus->challenge_data, "ver"), | |
| 158 (char *)g_hash_table_lookup(nexus->challenge_data, "tpf"), | |
| 159 nexus->login_host); | |
| 160 | |
| 12457 | 161 buffer = g_strdup_printf("%s,pwd=XXXXXXXX,%s\r\n", head, tail); |
| 162 request_str = g_strdup_printf("%s,pwd=%s,%s\r\n", head, password, tail); | |
| 8171 | 163 |
| 12457 | 164 gaim_debug_misc("msn", "Sending: {%s}\n", buffer); |
| 165 | |
| 166 g_free(buffer); | |
| 167 g_free(head); | |
| 168 g_free(tail); | |
| 8171 | 169 g_free(username); |
| 170 g_free(password); | |
| 171 | |
| 172 if ((s = gaim_ssl_write(gsc, request_str, strlen(request_str))) <= 0) | |
| 173 { | |
| 174 g_free(request_str); | |
| 175 | |
| 176 return; | |
| 177 } | |
| 178 | |
| 179 g_free(request_str); | |
| 180 | |
| 181 if ((s = msn_ssl_read(gsc, &buffer)) <= 0) | |
| 182 return; | |
| 183 | |
| 184 gaim_ssl_close(gsc); | |
| 185 | |
| 10345 | 186 gaim_debug_misc("msn", "ssl buffer: {%s}", buffer); |
| 8171 | 187 |
| 188 if (strstr(buffer, "HTTP/1.1 302") != NULL) | |
| 189 { | |
| 190 /* Redirect. */ | |
| 191 char *location, *c; | |
| 192 | |
| 193 location = strstr(buffer, "Location: "); | |
| 194 if (location == NULL) | |
| 195 { | |
| 196 g_free(buffer); | |
| 197 | |
| 198 return; | |
| 199 } | |
| 200 location = strchr(location, ' ') + 1; | |
| 201 | |
| 202 if ((c = strchr(location, '\r')) != NULL) | |
| 203 *c = '\0'; | |
| 204 | |
| 205 /* Skip the http:// */ | |
| 206 if ((c = strchr(location, '/')) != NULL) | |
| 207 location = c + 2; | |
| 208 | |
| 209 if ((c = strchr(location, '/')) != NULL) | |
| 210 { | |
| 211 g_free(nexus->login_path); | |
| 212 nexus->login_path = g_strdup(c); | |
| 213 | |
| 214 *c = '\0'; | |
| 215 } | |
| 216 | |
| 217 g_free(nexus->login_host); | |
| 218 nexus->login_host = g_strdup(location); | |
| 219 | |
| 220 gaim_ssl_connect(session->account, nexus->login_host, | |
| 221 GAIM_SSL_DEFAULT_PORT, login_connect_cb, | |
| 222 login_error_cb, nexus); | |
| 223 } | |
| 224 else if (strstr(buffer, "HTTP/1.1 401 Unauthorized") != NULL) | |
| 225 { | |
| 10481 | 226 const char *error; |
| 8171 | 227 |
| 228 if ((error = strstr(buffer, "WWW-Authenticate")) != NULL) | |
| 229 { | |
| 230 if ((error = strstr(error, "cbtxt=")) != NULL) | |
| 231 { | |
| 10481 | 232 const char *c; |
| 233 char *temp; | |
| 234 | |
| 8171 | 235 error += strlen("cbtxt="); |
| 236 | |
| 237 if ((c = strchr(error, '\n')) == NULL) | |
| 238 c = error + strlen(error); | |
| 239 | |
| 240 temp = g_strndup(error, c - error); | |
| 241 error = gaim_url_decode(temp); | |
| 242 g_free(temp); | |
| 243 } | |
| 244 } | |
| 245 | |
| 10481 | 246 msn_session_set_error(session, MSN_ERROR_AUTH, error); |
| 8171 | 247 } |
| 248 else if (strstr(buffer, "HTTP/1.1 200 OK")) | |
| 249 { | |
| 250 char *base, *c; | |
| 251 char *login_params; | |
| 252 | |
| 253 #if 0 | |
| 254 /* All your base are belong to us. */ | |
| 255 base = buffer; | |
| 256 | |
| 257 /* For great cookie! */ | |
| 258 while ((base = strstr(base, "Set-Cookie: ")) != NULL) | |
| 259 { | |
| 260 base += strlen("Set-Cookie: "); | |
| 261 | |
| 262 c = strchr(base, ';'); | |
| 263 | |
| 264 session->login_cookies = | |
| 265 g_list_append(session->login_cookies, | |
| 266 g_strndup(base, c - base)); | |
| 267 } | |
| 268 #endif | |
| 269 | |
| 270 base = strstr(buffer, "Authentication-Info: "); | |
| 271 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8925
diff
changeset
|
272 g_return_if_fail(base != NULL); |
| 8171 | 273 |
| 274 base = strstr(base, "from-PP='"); | |
| 275 base += strlen("from-PP='"); | |
| 276 c = strchr(base, '\''); | |
| 277 | |
| 278 login_params = g_strndup(base, c - base); | |
| 279 | |
|
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
8925
diff
changeset
|
280 msn_got_login_params(session, login_params); |
| 8171 | 281 |
| 282 g_free(login_params); | |
| 283 | |
| 284 msn_nexus_destroy(nexus); | |
| 285 session->nexus = NULL; | |
| 286 } | |
| 287 | |
| 288 g_free(buffer); | |
| 289 } | |
| 290 | |
| 10481 | 291 /************************************************************************** |
| 292 * Connect | |
| 293 **************************************************************************/ | |
| 294 | |
| 8171 | 295 static void |
| 296 nexus_connect_cb(gpointer data, GaimSslConnection *gsc, | |
| 297 GaimInputCondition cond) | |
| 298 { | |
| 299 MsnNexus *nexus; | |
| 300 MsnSession *session; | |
| 301 char *request_str; | |
| 302 char *da_login; | |
| 303 char *base, *c; | |
| 304 char *buffer = NULL; | |
| 305 size_t s; | |
| 306 | |
| 307 nexus = data; | |
| 308 g_return_if_fail(nexus != NULL); | |
| 309 | |
| 310 session = nexus->session; | |
| 311 g_return_if_fail(session != NULL); | |
| 312 | |
| 10519 | 313 msn_session_set_login_step(session, MSN_LOGIN_STEP_AUTH); |
| 10481 | 314 |
| 8171 | 315 request_str = g_strdup_printf("GET /rdr/pprdr.asp\r\n\r\n"); |
| 316 | |
| 317 if ((s = gaim_ssl_write(gsc, request_str, strlen(request_str))) <= 0) | |
| 318 { | |
| 319 g_free(request_str); | |
| 320 return; | |
| 321 } | |
| 322 | |
| 323 g_free(request_str); | |
| 324 | |
| 325 /* Get the PassportURLs line. */ | |
| 326 if ((s = msn_ssl_read(gsc, &buffer)) <= 0) | |
| 327 return; | |
| 328 | |
| 329 base = strstr(buffer, "PassportURLs"); | |
| 330 | |
| 331 if (base == NULL) | |
| 332 { | |
| 333 g_free(buffer); | |
| 334 return; | |
| 335 } | |
| 336 | |
| 337 if ((da_login = strstr(base, "DALogin=")) != NULL) | |
| 338 { | |
| 339 if ((da_login = strchr(da_login, '=')) != NULL) | |
| 340 da_login++; | |
| 341 | |
| 342 if ((c = strchr(da_login, ',')) != NULL) | |
| 343 *c = '\0'; | |
| 344 | |
| 345 if ((c = strchr(da_login, '/')) != NULL) | |
| 346 { | |
| 347 nexus->login_path = g_strdup(c); | |
| 348 | |
| 349 *c = '\0'; | |
| 350 } | |
| 351 | |
| 352 nexus->login_host = g_strdup(da_login); | |
| 353 } | |
| 354 | |
| 355 g_free(buffer); | |
| 356 | |
| 357 gaim_ssl_close(gsc); | |
| 358 | |
| 359 /* Now begin the connection to the login server. */ | |
| 360 gaim_ssl_connect(session->account, nexus->login_host, | |
| 361 GAIM_SSL_DEFAULT_PORT, login_connect_cb, | |
| 362 login_error_cb, nexus); | |
| 363 } | |
| 364 | |
| 365 void | |
| 366 msn_nexus_connect(MsnNexus *nexus) | |
| 367 { | |
| 368 gaim_ssl_connect(nexus->session->account, "nexus.passport.com", | |
| 369 GAIM_SSL_DEFAULT_PORT, nexus_connect_cb, | |
| 370 login_error_cb, nexus); | |
| 371 } |
