Mercurial > pidgin.yaz
annotate src/protocols/msn/httpmethod.c @ 9657:51464cbbdc1a
[gaim-migrate @ 10505]
I fixed my bug from an hour ago, cleaned up a few more things, and
separated the code for the dns lookup child into a function. You know,
functions? The things that make code suck less?
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Wed, 04 Aug 2004 01:51:22 +0000 |
parents | ab6636c5a136 |
children |
rev | line source |
---|---|
7288 | 1 /** |
2 * @file httpmethod.c HTTP connection method | |
3 * | |
4 * gaim | |
5 * | |
9198
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. |
7288 | 9 * |
10 * This program is free software; you can redistribute it and/or modify | |
11 * it under the terms of the GNU General Public License as published by | |
12 * the Free Software Foundation; either version 2 of the License, or | |
13 * (at your option) any later version. | |
14 * | |
15 * This program is distributed in the hope that it will be useful, | |
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 * GNU General Public License for more details. | |
19 * | |
20 * You should have received a copy of the GNU General Public License | |
21 * along with this program; if not, write to the Free Software | |
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
23 */ | |
24 #include "debug.h" | |
25 #include "httpmethod.h" | |
26 | |
27 #define GET_NEXT(tmp) \ | |
28 while (*(tmp) && *(tmp) != ' ' && *(tmp) != '\r') \ | |
29 (tmp)++; \ | |
30 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
31 if (*(tmp) == '\n') (tmp)++; \ | |
32 while (*(tmp) && *(tmp) == ' ') \ | |
33 (tmp)++ | |
34 | |
35 #define GET_NEXT_LINE(tmp) \ | |
36 while (*(tmp) && *(tmp) != '\r') \ | |
37 (tmp)++; \ | |
38 if (*(tmp) != '\0') *(tmp)++ = '\0'; \ | |
39 if (*(tmp) == '\n') (tmp)++ | |
40 | |
41 typedef struct | |
42 { | |
43 MsnServConn *servconn; | |
44 char *buffer; | |
45 size_t size; | |
46 const char *server_type; | |
47 | |
48 } MsnHttpQueueData; | |
49 | |
50 static gboolean | |
51 http_poll(gpointer data) | |
52 { | |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
53 MsnSession *session; |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
54 GList *l; |
7288 | 55 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
56 session = data; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
57 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
58 for (l = session->switches; l != NULL; l = l->next) |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
59 { |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
60 MsnSwitchBoard *swboard; |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
61 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
62 swboard = l->data; |
7288 | 63 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
64 g_return_val_if_fail(swboard->servconn->http_data != NULL, FALSE); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
65 |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
66 if (swboard->servconn->http_data->dirty) |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
67 { |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
68 #if 0 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
69 gaim_debug_info("msn", "Polling server %s.\n", |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
70 servconn->http_data->gateway_host); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
71 #endif |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
72 msn_http_servconn_poll(swboard->servconn); |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
73 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
74 } |
7288 | 75 |
9193
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
76 if (session->notification->servconn->http_data->dirty) |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
77 msn_http_servconn_poll(session->notification->servconn); |
502707ca1836
[gaim-migrate @ 9988]
Christian Hammond <chipx86@chipx86.com>
parents:
9158
diff
changeset
|
78 |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
79 return TRUE; |
7288 | 80 } |
81 | |
82 static void | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
83 stop_timer(MsnSession *session) |
7288 | 84 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
85 if (session->http_poll_timer) |
7288 | 86 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
87 gaim_timeout_remove(session->http_poll_timer); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
88 session->http_poll_timer = 0; |
7288 | 89 } |
90 } | |
91 | |
92 static void | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
93 start_timer(MsnSession *session) |
7288 | 94 { |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
95 stop_timer(session); |
7288 | 96 |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
97 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
|
98 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
99 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
100 void |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
101 msn_http_session_init(MsnSession *session) |
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 g_return_if_fail(session != NULL); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
104 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
105 start_timer(session); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
106 } |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
107 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
108 void |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
109 msn_http_session_uninit(MsnSession *session) |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
110 { |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
111 g_return_if_fail(session != NULL); |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
112 |
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
113 stop_timer(session); |
7288 | 114 } |
115 | |
116 size_t | |
117 msn_http_servconn_write(MsnServConn *servconn, const char *buf, size_t size, | |
118 const char *server_type) | |
119 { | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
120 size_t s, needed; |
7288 | 121 char *params; |
122 char *temp; | |
123 gboolean first; | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
124 int res; /* result of the write operation */ |
7288 | 125 |
126 g_return_val_if_fail(servconn != NULL, 0); | |
127 g_return_val_if_fail(buf != NULL, 0); | |
128 g_return_val_if_fail(size > 0, 0); | |
129 g_return_val_if_fail(servconn->http_data != NULL, 0); | |
130 | |
9085
9885420f049f
[gaim-migrate @ 9862]
Christian Hammond <chipx86@chipx86.com>
parents:
8475
diff
changeset
|
131 if (servconn->http_data->waiting_response) |
7288 | 132 { |
133 MsnHttpQueueData *queue_data = g_new0(MsnHttpQueueData, 1); | |
134 | |
135 queue_data->servconn = servconn; | |
136 queue_data->buffer = g_strdup(buf); | |
137 queue_data->size = size; | |
138 queue_data->server_type = server_type; | |
139 | |
140 servconn->http_data->queue = | |
141 g_list_append(servconn->http_data->queue, queue_data); | |
142 | |
143 return size; | |
144 } | |
145 | |
146 first = servconn->http_data->virgin; | |
147 | |
148 if (first) | |
149 { | |
150 if (server_type) | |
151 { | |
152 params = g_strdup_printf("Action=open&Server=%s&IP=%s", | |
153 server_type, | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
154 servconn->http_data->gateway_host); |
7288 | 155 } |
156 else | |
157 { | |
158 params = g_strdup_printf("Action=open&IP=%s", | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
159 servconn->http_data->gateway_host); |
7288 | 160 } |
161 } | |
162 else | |
163 { | |
164 params = g_strdup_printf("SessionID=%s", | |
165 servconn->http_data->session_id); | |
166 } | |
167 | |
168 temp = g_strdup_printf( | |
169 "POST http://%s/gateway/gateway.dll?%s HTTP/1.1\r\n" | |
170 "Accept: */*\r\n" | |
171 "Accept-Language: en-us\r\n" | |
172 "User-Agent: MSMSGS\r\n" | |
173 "Host: %s\r\n" | |
174 "Proxy-Connection: Keep-Alive\r\n" | |
175 "Connection: Keep-Alive\r\n" | |
176 "Pragma: no-cache\r\n" | |
177 "Content-Type: application/x-msn-messenger\r\n" | |
178 "Content-Length: %d\r\n" | |
179 "\r\n" | |
180 "%s", | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
181 ((strcmp(server_type, "SB") == 0) && first |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
182 ? "gateway.messenger.hotmail.com" |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
183 : servconn->http_data->gateway_host), |
7288 | 184 params, |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
185 servconn->http_data->gateway_host, |
7386 | 186 (int)size, |
7288 | 187 buf); |
188 | |
189 g_free(params); | |
190 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
191 #if 0 |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
192 gaim_debug_misc("msn", "Writing HTTP to fd %d: {%s}\n", |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
193 servconn->fd, temp); |
7288 | 194 #endif |
195 | |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
196 s = 0; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
197 needed = strlen(temp); |
8207
aa44049e8891
[gaim-migrate @ 8930]
Christian Hammond <chipx86@chipx86.com>
parents:
7834
diff
changeset
|
198 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
199 do |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
200 { |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
201 res = write(servconn->fd, temp, needed); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
202 if (res >= 0) |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
203 s += res; |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
204 else if (errno != EAGAIN) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
205 { |
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
206 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
|
207 gaim_connection_error(servconn->session->account->gc, msg); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
208 g_free(msg); |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
209 return -1; |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
210 } |
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
211 } while (s < needed); |
8207
aa44049e8891
[gaim-migrate @ 8930]
Christian Hammond <chipx86@chipx86.com>
parents:
7834
diff
changeset
|
212 |
7288 | 213 g_free(temp); |
214 | |
215 servconn->http_data->waiting_response = TRUE; | |
216 servconn->http_data->virgin = FALSE; | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
217 servconn->http_data->dirty = FALSE; |
7288 | 218 |
219 return s; | |
220 } | |
221 | |
222 void | |
223 msn_http_servconn_poll(MsnServConn *servconn) | |
224 { | |
225 size_t s; | |
226 char *temp; | |
227 | |
228 g_return_if_fail(servconn != NULL); | |
229 g_return_if_fail(servconn->http_data != NULL); | |
230 | |
231 if (servconn->http_data->waiting_response || | |
232 servconn->http_data->queue != NULL) | |
233 { | |
234 return; | |
235 } | |
236 | |
237 temp = g_strdup_printf( | |
238 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n" | |
239 "Accept: */*\r\n" | |
240 "Accept-Language: en-us\r\n" | |
241 "User-Agent: MSMSGS\r\n" | |
242 "Host: %s\r\n" | |
243 "Proxy-Connection: Keep-Alive\r\n" | |
244 "Connection: Keep-Alive\r\n" | |
245 "Pragma: no-cache\r\n" | |
246 "Content-Type: application/x-msn-messenger\r\n" | |
247 "Content-Length: 0\r\n" | |
248 "\r\n", | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
249 servconn->http_data->gateway_host, |
7288 | 250 servconn->http_data->session_id, |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
251 servconn->http_data->gateway_host); |
7288 | 252 |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
253 #if 0 |
7288 | 254 gaim_debug_misc("msn", "Writing to HTTP: {%s}\n", temp); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
255 #endif |
7288 | 256 |
257 s = write(servconn->fd, temp, strlen(temp)); | |
258 | |
259 g_free(temp); | |
260 | |
261 servconn->http_data->waiting_response = TRUE; | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
262 servconn->http_data->dirty = FALSE; |
7288 | 263 |
264 if (s <= 0) | |
265 gaim_connection_error(servconn->session->account->gc, | |
266 _("Write error")); | |
267 } | |
268 | |
269 gboolean | |
270 msn_http_servconn_parse_data(MsnServConn *servconn, const char *buf, | |
271 size_t size, char **ret_buf, size_t *ret_size, | |
272 gboolean *error) | |
273 { | |
274 GaimConnection *gc; | |
275 const char *s, *c; | |
276 char *headers, *body; | |
277 char *tmp; | |
278 size_t len = 0; | |
279 | |
280 g_return_val_if_fail(servconn != NULL, FALSE); | |
281 g_return_val_if_fail(buf != NULL, FALSE); | |
282 g_return_val_if_fail(size > 0, FALSE); | |
283 g_return_val_if_fail(ret_buf != NULL, FALSE); | |
284 g_return_val_if_fail(ret_size != NULL, FALSE); | |
285 g_return_val_if_fail(error != NULL, FALSE); | |
286 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
287 #if 0 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
288 gaim_debug_info("msn", "parsing data {%s} from fd %d\n", |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
289 buf, servconn->fd); |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
290 #endif |
7288 | 291 servconn->http_data->waiting_response = FALSE; |
292 | |
293 gc = gaim_account_get_connection(servconn->session->account); | |
294 | |
295 /* Healthy defaults. */ | |
296 *ret_buf = NULL; | |
297 *ret_size = 0; | |
298 *error = FALSE; | |
299 | |
300 /* 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
|
301 if (((strncmp(buf, "HTTP/1.1 200 OK\r\n", 17) != 0) && |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
302 (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) != 0)) && |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
303 ((strncmp(buf, "HTTP/1.0 200 OK\r\n", 17) != 0) && |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
304 (strncmp(buf, "HTTP/1.0 100 Continue\r\n", 23) != 0))) |
7288 | 305 { |
306 *error = TRUE; | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
307 |
7288 | 308 return FALSE; |
309 } | |
310 | |
311 if (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) == 0) | |
312 { | |
313 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
314 return FALSE; | |
315 | |
316 s += 4; | |
317 | |
318 if (*s == '\0') | |
319 { | |
320 *ret_buf = g_strdup(""); | |
321 *ret_size = 0; | |
322 | |
323 return TRUE; | |
324 } | |
325 | |
326 buf = s; | |
327 size -= (s - buf); | |
328 } | |
329 | |
330 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
331 return FALSE; | |
332 | |
333 headers = g_strndup(buf, s - buf); | |
334 s += 4; /* Skip \r\n */ | |
335 body = g_strndup(s, size - (s - buf)); | |
336 | |
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
337 #if 0 |
7288 | 338 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
|
339 #endif |
7288 | 340 |
341 if ((s = strstr(headers, "Content-Length: ")) != NULL) | |
342 { | |
343 s += strlen("Content-Length: "); | |
344 | |
345 if ((c = strchr(s, '\r')) == NULL) | |
346 { | |
347 g_free(headers); | |
348 g_free(body); | |
349 | |
350 return FALSE; | |
351 } | |
352 | |
353 tmp = g_strndup(s, c - s); | |
354 len = atoi(tmp); | |
355 g_free(tmp); | |
356 | |
357 if (strlen(body) != len) | |
358 { | |
359 g_free(headers); | |
360 g_free(body); | |
361 | |
362 gaim_debug_warning("msn", | |
363 "body length (%d) != content length (%d)\n", | |
364 strlen(body), len); | |
365 return FALSE; | |
366 } | |
367 } | |
368 | |
369 /* Now we should be able to process the data. */ | |
370 if ((s = strstr(headers, "X-MSN-Messenger: ")) != NULL) | |
371 { | |
372 char *session_id, *gw_ip; | |
373 char *c2, *s2; | |
374 | |
375 s += strlen("X-MSN-Messenger: "); | |
376 | |
377 if ((c = strchr(s, '\r')) == NULL) | |
378 { | |
379 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
380 return FALSE; | |
381 } | |
382 | |
383 tmp = g_strndup(s, c - s); | |
384 | |
385 /* Find the value for the Session ID */ | |
386 if ((s2 = strchr(tmp, '=')) == NULL) | |
387 { | |
388 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
389 return FALSE; | |
390 } | |
391 | |
392 s2++; | |
393 | |
394 /* Terminate the ; so we can g_strdup it. */ | |
395 if ((c2 = strchr(s2, ';')) == NULL) | |
396 { | |
397 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
398 return FALSE; | |
399 } | |
400 | |
401 *c2 = '\0'; | |
402 c2++; | |
403 | |
404 /* Now grab that session ID. */ | |
405 session_id = g_strdup(s2); | |
406 | |
407 /* Continue to the gateway IP */ | |
408 if ((s2 = strchr(c2, '=')) == NULL) | |
409 { | |
410 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
411 return FALSE; | |
412 } | |
413 | |
414 s2++; | |
415 | |
416 /* Grab the gateway IP */ | |
417 gw_ip = g_strdup(s2); | |
418 | |
419 g_free(tmp); | |
420 | |
421 /* Set the new data. */ | |
422 if (servconn->http_data->session_id != NULL) | |
423 g_free(servconn->http_data->session_id); | |
424 | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
425 if (servconn->http_data->old_gateway_host != NULL) |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
426 g_free(servconn->http_data->old_gateway_host); |
7288 | 427 |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
428 servconn->http_data->old_gateway_host = |
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
429 servconn->http_data->gateway_host; |
7288 | 430 |
431 servconn->http_data->session_id = session_id; | |
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
432 servconn->http_data->gateway_host = gw_ip; |
7288 | 433 } |
434 | |
435 g_free(headers); | |
436 | |
437 *ret_buf = body; | |
438 *ret_size = len; | |
439 | |
440 if (servconn->http_data->queue != NULL) | |
441 { | |
442 MsnHttpQueueData *queue_data; | |
443 | |
444 queue_data = (MsnHttpQueueData *)servconn->http_data->queue->data; | |
445 | |
446 servconn->http_data->queue = | |
447 g_list_remove(servconn->http_data->queue, queue_data); | |
448 | |
449 msn_http_servconn_write(queue_data->servconn, | |
450 queue_data->buffer, | |
451 queue_data->size, | |
452 queue_data->server_type); | |
453 | |
454 g_free(queue_data->buffer); | |
455 g_free(queue_data); | |
456 } | |
457 else | |
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
458 servconn->http_data->dirty = TRUE; |
7288 | 459 |
460 return TRUE; | |
461 } | |
462 |