Mercurial > pidgin.yaz
annotate src/protocols/msn/httpmethod.c @ 9085:9885420f049f
[gaim-migrate @ 9862]
Fixed a bug in MSN's HTTP connect method. It would sometimes enter a state
where it would send no new data, but would keep queueing data indefinitely.
Patch by Andrew Wellington.
committer: Tailor Script <tailor@pidgin.im>
author | Christian Hammond <chipx86@chipx86.com> |
---|---|
date | Thu, 27 May 2004 05:51:01 +0000 |
parents | 06f57183e29f |
children | c30d81b4dd22 |
rev | line source |
---|---|
7288 | 1 /** |
2 * @file httpmethod.c HTTP connection method | |
3 * | |
4 * gaim | |
5 * | |
8475
06f57183e29f
[gaim-migrate @ 9208]
Christian Hammond <chipx86@chipx86.com>
parents:
8299
diff
changeset
|
6 * Copyright (C) 2003-2004 Christian Hammond <chipx86@gnupdate.org> |
7288 | 7 * |
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 "debug.h" | |
23 #include "httpmethod.h" | |
24 | |
25 #define GET_NEXT(tmp) \ | |
26 while (*(tmp) && *(tmp) != ' ' && *(tmp) != '\r') \ | |
27 (tmp)++; \ | |
28 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
29 if (*(tmp) == '\n') (tmp)++; \ | |
30 while (*(tmp) && *(tmp) == ' ') \ | |
31 (tmp)++ | |
32 | |
33 #define GET_NEXT_LINE(tmp) \ | |
34 while (*(tmp) && *(tmp) != '\r') \ | |
35 (tmp)++; \ | |
36 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
37 if (*(tmp) == '\n') (tmp)++ | |
38 | |
39 typedef struct | |
40 { | |
41 MsnServConn *servconn; | |
42 char *buffer; | |
43 size_t size; | |
44 const char *server_type; | |
45 | |
46 } MsnHttpQueueData; | |
47 | |
48 static gboolean | |
49 http_poll(gpointer data) | |
50 { | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
51 MsnSession *session = data; |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
52 MsnServConn *servconn; |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
53 GList *l; |
7288 | 54 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
55 for (l = session->servconns; l != NULL; l = l->next) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
56 { |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
57 servconn = (MsnServConn *)l->data; |
7288 | 58 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
59 if (servconn->http_data->dirty) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
60 { |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
61 #if 0 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
62 gaim_debug_info("msn", "Polling server %s.\n", |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
63 servconn->http_data->gateway_ip); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
64 #endif |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
65 msn_http_servconn_poll(servconn); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
66 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
67 } |
7288 | 68 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
69 return TRUE; |
7288 | 70 } |
71 | |
72 static void | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
73 stop_timer(MsnSession *session) |
7288 | 74 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
75 if (session->http_poll_timer) |
7288 | 76 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
77 gaim_timeout_remove(session->http_poll_timer); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
78 session->http_poll_timer = 0; |
7288 | 79 } |
80 } | |
81 | |
82 static void | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
83 start_timer(MsnSession *session) |
7288 | 84 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
85 stop_timer(session); |
7288 | 86 |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
87 session->http_poll_timer = gaim_timeout_add(2000, http_poll, session); |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
88 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
89 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
90 void |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
91 msn_http_session_init(MsnSession *session) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
92 { |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
93 g_return_if_fail(session != NULL); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
94 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
95 start_timer(session); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
96 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
97 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
98 void |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
99 msn_http_session_uninit(MsnSession *session) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
100 { |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
101 g_return_if_fail(session != NULL); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
102 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
103 stop_timer(session); |
7288 | 104 } |
105 | |
106 size_t | |
107 msn_http_servconn_write(MsnServConn *servconn, const char *buf, size_t size, | |
108 const char *server_type) | |
109 { | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
110 size_t s, needed; |
7288 | 111 char *params; |
112 char *temp; | |
113 gboolean first; | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
114 int res; /* result of the write operation */ |
7288 | 115 |
116 g_return_val_if_fail(servconn != NULL, 0); | |
117 g_return_val_if_fail(buf != NULL, 0); | |
118 g_return_val_if_fail(size > 0, 0); | |
119 g_return_val_if_fail(servconn->http_data != NULL, 0); | |
120 | |
9085
9885420f049f
[gaim-migrate @ 9862]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
121 if (servconn->http_data->waiting_response) |
7288 | 122 { |
123 MsnHttpQueueData *queue_data = g_new0(MsnHttpQueueData, 1); | |
124 | |
125 queue_data->servconn = servconn; | |
126 queue_data->buffer = g_strdup(buf); | |
127 queue_data->size = size; | |
128 queue_data->server_type = server_type; | |
129 | |
130 servconn->http_data->queue = | |
131 g_list_append(servconn->http_data->queue, queue_data); | |
132 | |
133 return size; | |
134 } | |
135 | |
136 first = servconn->http_data->virgin; | |
137 | |
138 if (first) | |
139 { | |
140 if (server_type) | |
141 { | |
142 params = g_strdup_printf("Action=open&Server=%s&IP=%s", | |
143 server_type, | |
144 servconn->http_data->gateway_ip); | |
145 } | |
146 else | |
147 { | |
148 params = g_strdup_printf("Action=open&IP=%s", | |
149 servconn->http_data->gateway_ip); | |
150 } | |
151 } | |
152 else | |
153 { | |
154 params = g_strdup_printf("SessionID=%s", | |
155 servconn->http_data->session_id); | |
156 } | |
157 | |
158 temp = g_strdup_printf( | |
159 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n" | |
160 "Accept: */*\r\n" | |
161 "Accept-Language: en-us\r\n" | |
162 "User-Agent: MSMSGS\r\n" | |
163 "Host: %s\r\n" | |
164 "Proxy-Connection: Keep-Alive\r\n" | |
165 "Connection: Keep-Alive\r\n" | |
166 "Pragma: no-cache\r\n" | |
167 "Content-Type: application/x-msn-messenger\r\n" | |
168 "Content-Length: %d\r\n" | |
169 "\r\n" | |
170 "%s", | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
171 ((strcmp(server_type, "SB") == 0) && first |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
172 ? "gateway.messenger.hotmail.com" |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
173 : servconn->http_data->gateway_ip), |
7288 | 174 params, |
175 servconn->http_data->gateway_ip, | |
7386 | 176 (int)size, |
7288 | 177 buf); |
178 | |
179 g_free(params); | |
180 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
181 #if 0 |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
182 gaim_debug_misc("msn", "Writing HTTP to fd %d: {%s}\n", |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
183 servconn->fd, temp); |
7288 | 184 #endif |
185 | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
186 s = 0; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
187 needed = strlen(temp); |
8207
aa44049e8891
[gaim-migrate @ 8930]
Christian Hammond <chipx86@chipx86.com>
parents:
7834
diff
changeset
|
188 |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
189 do { |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
190 res = write(servconn->fd, temp, needed); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
191 if (res >= 0) |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
192 s += res; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
193 else if (errno != EAGAIN) { |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
194 char *msg = g_strdup_printf("Unable to write to MSN server via HTTP (error %d)", errno); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
195 gaim_connection_error(servconn->session->account->gc, msg); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
196 g_free(msg); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
197 return -1; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
198 } |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
199 } while (s < needed); |
8207
aa44049e8891
[gaim-migrate @ 8930]
Christian Hammond <chipx86@chipx86.com>
parents:
7834
diff
changeset
|
200 |
7288 | 201 g_free(temp); |
202 | |
203 servconn->http_data->waiting_response = TRUE; | |
204 servconn->http_data->virgin = FALSE; | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
205 servconn->http_data->dirty = FALSE; |
7288 | 206 |
207 return s; | |
208 } | |
209 | |
210 void | |
211 msn_http_servconn_poll(MsnServConn *servconn) | |
212 { | |
213 size_t s; | |
214 char *temp; | |
215 | |
216 g_return_if_fail(servconn != NULL); | |
217 g_return_if_fail(servconn->http_data != NULL); | |
218 | |
219 if (servconn->http_data->waiting_response || | |
220 servconn->http_data->queue != NULL) | |
221 { | |
222 return; | |
223 } | |
224 | |
225 temp = g_strdup_printf( | |
226 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n" | |
227 "Accept: */*\r\n" | |
228 "Accept-Language: en-us\r\n" | |
229 "User-Agent: MSMSGS\r\n" | |
230 "Host: %s\r\n" | |
231 "Proxy-Connection: Keep-Alive\r\n" | |
232 "Connection: Keep-Alive\r\n" | |
233 "Pragma: no-cache\r\n" | |
234 "Content-Type: application/x-msn-messenger\r\n" | |
235 "Content-Length: 0\r\n" | |
236 "\r\n", | |
237 servconn->http_data->gateway_ip, | |
238 servconn->http_data->session_id, | |
239 servconn->http_data->gateway_ip); | |
240 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
241 #if 0 |
7288 | 242 gaim_debug_misc("msn", "Writing to HTTP: {%s}\n", temp); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
243 #endif |
7288 | 244 |
245 s = write(servconn->fd, temp, strlen(temp)); | |
246 | |
247 g_free(temp); | |
248 | |
249 servconn->http_data->waiting_response = TRUE; | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
250 servconn->http_data->dirty = FALSE; |
7288 | 251 |
252 if (s <= 0) | |
253 gaim_connection_error(servconn->session->account->gc, | |
254 _("Write error")); | |
255 } | |
256 | |
257 gboolean | |
258 msn_http_servconn_parse_data(MsnServConn *servconn, const char *buf, | |
259 size_t size, char **ret_buf, size_t *ret_size, | |
260 gboolean *error) | |
261 { | |
262 GaimConnection *gc; | |
263 const char *s, *c; | |
264 char *headers, *body; | |
265 char *tmp; | |
266 size_t len = 0; | |
267 | |
268 g_return_val_if_fail(servconn != NULL, FALSE); | |
269 g_return_val_if_fail(buf != NULL, FALSE); | |
270 g_return_val_if_fail(size > 0, FALSE); | |
271 g_return_val_if_fail(ret_buf != NULL, FALSE); | |
272 g_return_val_if_fail(ret_size != NULL, FALSE); | |
273 g_return_val_if_fail(error != NULL, FALSE); | |
274 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
275 #if 0 |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
276 gaim_debug_info("msn", "parsing data {%s} from fd %d\n", buf, servconn->fd); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
277 #endif |
7288 | 278 servconn->http_data->waiting_response = FALSE; |
279 | |
280 gc = gaim_account_get_connection(servconn->session->account); | |
281 | |
282 /* Healthy defaults. */ | |
283 *ret_buf = NULL; | |
284 *ret_size = 0; | |
285 *error = FALSE; | |
286 | |
287 /* First, some tests to see if we have a full block of stuff. */ | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
288 if (((strncmp(buf, "HTTP/1.1 200 OK\r\n", 17) != 0) && |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
289 (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) != 0)) && |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
290 ((strncmp(buf, "HTTP/1.0 200 OK\r\n", 17) != 0) && |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
291 (strncmp(buf, "HTTP/1.0 100 Continue\r\n", 23) != 0))) |
7288 | 292 { |
293 *error = TRUE; | |
294 return FALSE; | |
295 } | |
296 | |
297 if (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) == 0) | |
298 { | |
299 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
300 return FALSE; | |
301 | |
302 s += 4; | |
303 | |
304 if (*s == '\0') | |
305 { | |
306 *ret_buf = g_strdup(""); | |
307 *ret_size = 0; | |
308 | |
309 return TRUE; | |
310 } | |
311 | |
312 buf = s; | |
313 size -= (s - buf); | |
314 } | |
315 | |
316 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
317 return FALSE; | |
318 | |
319 headers = g_strndup(buf, s - buf); | |
320 s += 4; /* Skip \r\n */ | |
321 body = g_strndup(s, size - (s - buf)); | |
322 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
323 #if 0 |
7288 | 324 gaim_debug_misc("msn", "Incoming HTTP buffer: {%s\r\n%s}", headers, body); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
325 #endif |
7288 | 326 |
327 if ((s = strstr(headers, "Content-Length: ")) != NULL) | |
328 { | |
329 s += strlen("Content-Length: "); | |
330 | |
331 if ((c = strchr(s, '\r')) == NULL) | |
332 { | |
333 g_free(headers); | |
334 g_free(body); | |
335 | |
336 return FALSE; | |
337 } | |
338 | |
339 tmp = g_strndup(s, c - s); | |
340 len = atoi(tmp); | |
341 g_free(tmp); | |
342 | |
343 if (strlen(body) != len) | |
344 { | |
345 g_free(headers); | |
346 g_free(body); | |
347 | |
348 gaim_debug_warning("msn", | |
349 "body length (%d) != content length (%d)\n", | |
350 strlen(body), len); | |
351 return FALSE; | |
352 } | |
353 } | |
354 | |
355 /* Now we should be able to process the data. */ | |
356 if ((s = strstr(headers, "X-MSN-Messenger: ")) != NULL) | |
357 { | |
358 char *session_id, *gw_ip; | |
359 char *c2, *s2; | |
360 | |
361 s += strlen("X-MSN-Messenger: "); | |
362 | |
363 if ((c = strchr(s, '\r')) == NULL) | |
364 { | |
365 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
366 return FALSE; | |
367 } | |
368 | |
369 tmp = g_strndup(s, c - s); | |
370 | |
371 /* Find the value for the Session ID */ | |
372 if ((s2 = strchr(tmp, '=')) == NULL) | |
373 { | |
374 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
375 return FALSE; | |
376 } | |
377 | |
378 s2++; | |
379 | |
380 /* Terminate the ; so we can g_strdup it. */ | |
381 if ((c2 = strchr(s2, ';')) == NULL) | |
382 { | |
383 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
384 return FALSE; | |
385 } | |
386 | |
387 *c2 = '\0'; | |
388 c2++; | |
389 | |
390 /* Now grab that session ID. */ | |
391 session_id = g_strdup(s2); | |
392 | |
393 /* Continue to the gateway IP */ | |
394 if ((s2 = strchr(c2, '=')) == NULL) | |
395 { | |
396 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
397 return FALSE; | |
398 } | |
399 | |
400 s2++; | |
401 | |
402 /* Grab the gateway IP */ | |
403 gw_ip = g_strdup(s2); | |
404 | |
405 g_free(tmp); | |
406 | |
407 /* Set the new data. */ | |
408 if (servconn->http_data->session_id != NULL) | |
409 g_free(servconn->http_data->session_id); | |
410 | |
411 if (servconn->http_data->old_gateway_ip != NULL) | |
412 g_free(servconn->http_data->old_gateway_ip); | |
413 | |
414 servconn->http_data->old_gateway_ip = servconn->http_data->gateway_ip; | |
415 | |
416 servconn->http_data->session_id = session_id; | |
417 servconn->http_data->gateway_ip = gw_ip; | |
418 } | |
419 | |
420 g_free(headers); | |
421 | |
422 *ret_buf = body; | |
423 *ret_size = len; | |
424 | |
425 if (servconn->http_data->queue != NULL) | |
426 { | |
427 MsnHttpQueueData *queue_data; | |
428 | |
429 queue_data = (MsnHttpQueueData *)servconn->http_data->queue->data; | |
430 | |
431 servconn->http_data->queue = | |
432 g_list_remove(servconn->http_data->queue, queue_data); | |
433 | |
434 msn_http_servconn_write(queue_data->servconn, | |
435 queue_data->buffer, | |
436 queue_data->size, | |
437 queue_data->server_type); | |
438 | |
439 g_free(queue_data->buffer); | |
440 g_free(queue_data); | |
441 } | |
442 else | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
443 servconn->http_data->dirty = TRUE; |
7288 | 444 |
445 return TRUE; | |
446 } | |
447 |