Mercurial > pidgin.yaz
comparison src/protocols/msn/httpconn.c @ 10568:fed2a7c2471d
[gaim-migrate @ 11954]
Some MSN bits:
- Fix HTTP Method works when using an HTTP proxy that require authentication
(Bastien Durel)
- Better error reporting when the MSN servers are temporarily unavailable
- Prevent zombie failed switchboard connections swallowing up messages
- Fix win32 crashes receiving messages from aMSN with no formatting info
- Fix a crash when the connection to the nexus server fails
- maybe some other stuff, I forgot how much had piled up
committer: Tailor Script <tailor@pidgin.im>
author | Stu Tomlinson <stu@nosnilmot.com> |
---|---|
date | Thu, 03 Feb 2005 19:47:52 +0000 |
parents | 052ef28a0695 |
children | 56f1c92b943f |
comparison
equal
deleted
inserted
replaced
10567:54f7939df8e3 | 10568:fed2a7c2471d |
---|---|
78 g_free(httpconn->host); | 78 g_free(httpconn->host); |
79 | 79 |
80 g_free(httpconn); | 80 g_free(httpconn); |
81 } | 81 } |
82 | 82 |
83 static char * | |
84 msn_httpconn_proxy_auth(MsnHttpConn *httpconn) | |
85 { | |
86 GaimAccount *account; | |
87 GaimProxyInfo *gpi; | |
88 const char *username, *password; | |
89 char *auth = NULL; | |
90 | |
91 account = httpconn->session->account; | |
92 | |
93 if (gaim_account_get_proxy_info(account) == NULL) | |
94 gpi = gaim_global_proxy_get_info(); | |
95 else | |
96 gpi = gaim_account_get_proxy_info(account); | |
97 | |
98 if (gpi == NULL || !(gaim_proxy_info_get_type(gpi) == GAIM_PROXY_HTTP || | |
99 gaim_proxy_info_get_type(gpi) == GAIM_PROXY_USE_ENVVAR)) | |
100 return NULL; | |
101 | |
102 username = gaim_proxy_info_get_username(gpi); | |
103 password = gaim_proxy_info_get_password(gpi); | |
104 | |
105 if (username != NULL) { | |
106 char *tmp; | |
107 auth = g_strdup_printf("%s:%s", username, password ? password : ""); | |
108 tmp = gaim_base64_encode(auth, strlen(auth)); | |
109 g_free(auth); | |
110 auth = g_strdup_printf("Proxy-Authorization: Basic %s\r\n", tmp); | |
111 g_free(tmp); | |
112 } | |
113 | |
114 return auth; | |
115 } | |
116 | |
83 static ssize_t | 117 static ssize_t |
84 write_raw(MsnHttpConn *httpconn, const char *header, | 118 write_raw(MsnHttpConn *httpconn, const char *header, |
85 const char *body, size_t body_len) | 119 const char *body, size_t body_len) |
86 { | 120 { |
87 char *buf; | 121 char *buf; |
127 | 161 |
128 void | 162 void |
129 msn_httpconn_poll(MsnHttpConn *httpconn) | 163 msn_httpconn_poll(MsnHttpConn *httpconn) |
130 { | 164 { |
131 char *header; | 165 char *header; |
166 char *auth; | |
132 int r; | 167 int r; |
133 | 168 |
134 g_return_if_fail(httpconn != NULL); | 169 g_return_if_fail(httpconn != NULL); |
135 | 170 |
136 if (httpconn->waiting_response || | 171 if (httpconn->waiting_response || |
137 httpconn->queue != NULL) | 172 httpconn->queue != NULL) |
138 { | 173 { |
139 return; | 174 return; |
140 } | 175 } |
176 | |
177 auth = msn_httpconn_proxy_auth(httpconn); | |
141 | 178 |
142 header = g_strdup_printf( | 179 header = g_strdup_printf( |
143 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n" | 180 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n" |
144 "Accept: */*\r\n" | 181 "Accept: */*\r\n" |
145 "Accept-Language: en-us\r\n" | 182 "Accept-Language: en-us\r\n" |
146 "User-Agent: MSMSGS\r\n" | 183 "User-Agent: MSMSGS\r\n" |
147 "Host: %s\r\n" | 184 "Host: %s\r\n" |
148 "Proxy-Connection: Keep-Alive\r\n" | 185 "Proxy-Connection: Keep-Alive\r\n" |
186 "%s" /* Proxy auth */ | |
149 "Connection: Keep-Alive\r\n" | 187 "Connection: Keep-Alive\r\n" |
150 "Pragma: no-cache\r\n" | 188 "Pragma: no-cache\r\n" |
151 "Content-Type: application/x-msn-messenger\r\n" | 189 "Content-Type: application/x-msn-messenger\r\n" |
152 "Content-Length: 0\r\n", | 190 "Content-Length: 0\r\n", |
153 httpconn->host, | 191 httpconn->host, |
154 httpconn->full_session_id, | 192 httpconn->full_session_id, |
155 httpconn->host); | 193 httpconn->host, |
194 auth ? auth : ""); | |
195 | |
196 if (auth != NULL) | |
197 g_free(auth); | |
156 | 198 |
157 r = write_raw(httpconn, header, NULL, -1); | 199 r = write_raw(httpconn, header, NULL, -1); |
158 | 200 |
159 g_free(header); | 201 g_free(header); |
160 | 202 |
169 do_poll(gpointer data) | 211 do_poll(gpointer data) |
170 { | 212 { |
171 MsnHttpConn *httpconn; | 213 MsnHttpConn *httpconn; |
172 | 214 |
173 httpconn = data; | 215 httpconn = data; |
216 | |
217 g_return_val_if_fail(httpconn != NULL, TRUE); | |
174 | 218 |
175 #if 0 | 219 #if 0 |
176 gaim_debug_info("msn", "polling from %s\n", httpconn->session_id); | 220 gaim_debug_info("msn", "polling from %s\n", httpconn->session_id); |
177 #endif | 221 #endif |
222 | |
223 if ((httpconn->host == NULL) || (httpconn->full_session_id == NULL)) | |
224 { | |
225 gaim_debug_warning("msn", "Attempted HTTP poll before session is established\n"); | |
226 return TRUE; | |
227 } | |
178 | 228 |
179 if (httpconn->dirty) | 229 if (httpconn->dirty) |
180 msn_httpconn_poll(httpconn); | 230 msn_httpconn_poll(httpconn); |
181 | 231 |
182 return TRUE; | 232 return TRUE; |
294 httpconn->rx_len += len; | 344 httpconn->rx_len += len; |
295 | 345 |
296 if (!msn_httpconn_parse_data(httpconn, httpconn->rx_buf, httpconn->rx_len, | 346 if (!msn_httpconn_parse_data(httpconn, httpconn->rx_buf, httpconn->rx_len, |
297 &result_msg, &result_len, &error)) | 347 &result_msg, &result_len, &error)) |
298 { | 348 { |
299 /* We must wait for more input */ | 349 /* We must wait for more input, or something went wrong */ |
350 if (error) | |
351 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); | |
300 | 352 |
301 return; | 353 return; |
302 } | 354 } |
303 | 355 |
304 httpconn->servconn->processing = FALSE; | 356 httpconn->servconn->processing = FALSE; |
419 size_t | 471 size_t |
420 msn_httpconn_write(MsnHttpConn *httpconn, const char *data, size_t size) | 472 msn_httpconn_write(MsnHttpConn *httpconn, const char *data, size_t size) |
421 { | 473 { |
422 char *params; | 474 char *params; |
423 char *header; | 475 char *header; |
476 char *auth; | |
424 gboolean first; | 477 gboolean first; |
425 const char *server_types[] = { "NS", "SB" }; | 478 const char *server_types[] = { "NS", "SB" }; |
426 const char *server_type; | 479 const char *server_type; |
427 size_t r; /* result of the write operation */ | 480 size_t r; /* result of the write operation */ |
428 char *host; | 481 char *host; |
467 else | 520 else |
468 { | 521 { |
469 /* The rest of the times servconn->host is the gateway host. */ | 522 /* The rest of the times servconn->host is the gateway host. */ |
470 host = httpconn->host; | 523 host = httpconn->host; |
471 | 524 |
525 if (host == NULL || httpconn->full_session_id == NULL) | |
526 { | |
527 gaim_debug_warning("msn", "Attempted HTTP write before session is established\n"); | |
528 return -1; | |
529 } | |
530 | |
472 params = g_strdup_printf("SessionID=%s", | 531 params = g_strdup_printf("SessionID=%s", |
473 httpconn->full_session_id); | 532 httpconn->full_session_id); |
474 } | 533 } |
534 | |
535 auth = msn_httpconn_proxy_auth(httpconn); | |
475 | 536 |
476 header = g_strdup_printf( | 537 header = g_strdup_printf( |
477 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n" | 538 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n" |
478 "Accept: */*\r\n" | 539 "Accept: */*\r\n" |
479 "Accept-Language: en-us\r\n" | 540 "Accept-Language: en-us\r\n" |
480 "User-Agent: MSMSGS\r\n" | 541 "User-Agent: MSMSGS\r\n" |
481 "Host: %s\r\n" | 542 "Host: %s\r\n" |
482 "Proxy-Connection: Keep-Alive\r\n" | 543 "Proxy-Connection: Keep-Alive\r\n" |
544 "%s" /* Proxy auth */ | |
483 "Connection: Keep-Alive\r\n" | 545 "Connection: Keep-Alive\r\n" |
484 "Pragma: no-cache\r\n" | 546 "Pragma: no-cache\r\n" |
485 "Content-Type: application/x-msn-messenger\r\n" | 547 "Content-Type: application/x-msn-messenger\r\n" |
486 "Content-Length: %d\r\n", | 548 "Content-Length: %d\r\n", |
487 host, | 549 host, |
488 params, | 550 params, |
489 host, | 551 host, |
552 auth ? auth : "", | |
490 (int)size); | 553 (int)size); |
491 | 554 |
492 g_free(params); | 555 g_free(params); |
556 | |
557 if (auth != NULL) | |
558 g_free(auth); | |
493 | 559 |
494 r = write_raw(httpconn, header, data, size); | 560 r = write_raw(httpconn, header, data, size); |
495 | 561 |
496 g_free(header); | 562 g_free(header); |
497 | 563 |