Mercurial > pidgin
annotate src/protocols/msn/httpmethod.c @ 9173:b6051a2d3bb5
[gaim-migrate @ 9962]
Robert T(something) noticed that we're not being a good jabber citizen, and that his server is not XMPP compliant. This fixes our end of that. Thanks Robert!
committer: Tailor Script <tailor@pidgin.im>
| author | Nathan Walp <nwalp@pidgin.im> |
|---|---|
| date | Fri, 04 Jun 2004 00:02:25 +0000 |
| parents | c30d81b4dd22 |
| children | 502707ca1836 |
| 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", |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
63 servconn->http_data->gateway_host); |
|
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, | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
144 servconn->http_data->gateway_host); |
| 7288 | 145 } |
| 146 else | |
| 147 { | |
| 148 params = g_strdup_printf("Action=open&IP=%s", | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
149 servconn->http_data->gateway_host); |
| 7288 | 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" |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
173 : servconn->http_data->gateway_host), |
| 7288 | 174 params, |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
175 servconn->http_data->gateway_host, |
| 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 |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
189 do |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
190 { |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
191 res = write(servconn->fd, temp, needed); |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
192 if (res >= 0) |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
193 s += res; |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
194 else if (errno != EAGAIN) |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
195 { |
|
7834
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
196 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
|
197 gaim_connection_error(servconn->session->account->gc, msg); |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
198 g_free(msg); |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
199 return -1; |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
200 } |
|
99ffabc6ce73
[gaim-migrate @ 8487]
Christian Hammond <chipx86@chipx86.com>
parents:
7386
diff
changeset
|
201 } while (s < needed); |
|
8207
aa44049e8891
[gaim-migrate @ 8930]
Christian Hammond <chipx86@chipx86.com>
parents:
7834
diff
changeset
|
202 |
| 7288 | 203 g_free(temp); |
| 204 | |
| 205 servconn->http_data->waiting_response = TRUE; | |
| 206 servconn->http_data->virgin = FALSE; | |
|
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
207 servconn->http_data->dirty = FALSE; |
| 7288 | 208 |
| 209 return s; | |
| 210 } | |
| 211 | |
| 212 void | |
| 213 msn_http_servconn_poll(MsnServConn *servconn) | |
| 214 { | |
| 215 size_t s; | |
| 216 char *temp; | |
| 217 | |
| 218 g_return_if_fail(servconn != NULL); | |
| 219 g_return_if_fail(servconn->http_data != NULL); | |
| 220 | |
| 221 if (servconn->http_data->waiting_response || | |
| 222 servconn->http_data->queue != NULL) | |
| 223 { | |
| 224 return; | |
| 225 } | |
| 226 | |
| 227 temp = g_strdup_printf( | |
| 228 "POST http://%s/gateway/gateway.dll?Action=poll&SessionID=%s HTTP/1.1\r\n" | |
| 229 "Accept: */*\r\n" | |
| 230 "Accept-Language: en-us\r\n" | |
| 231 "User-Agent: MSMSGS\r\n" | |
| 232 "Host: %s\r\n" | |
| 233 "Proxy-Connection: Keep-Alive\r\n" | |
| 234 "Connection: Keep-Alive\r\n" | |
| 235 "Pragma: no-cache\r\n" | |
| 236 "Content-Type: application/x-msn-messenger\r\n" | |
| 237 "Content-Length: 0\r\n" | |
| 238 "\r\n", | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
239 servconn->http_data->gateway_host, |
| 7288 | 240 servconn->http_data->session_id, |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
241 servconn->http_data->gateway_host); |
| 7288 | 242 |
|
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
243 #if 0 |
| 7288 | 244 gaim_debug_misc("msn", "Writing to HTTP: {%s}\n", temp); |
|
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
245 #endif |
| 7288 | 246 |
| 247 s = write(servconn->fd, temp, strlen(temp)); | |
| 248 | |
| 249 g_free(temp); | |
| 250 | |
| 251 servconn->http_data->waiting_response = TRUE; | |
|
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
252 servconn->http_data->dirty = FALSE; |
| 7288 | 253 |
| 254 if (s <= 0) | |
| 255 gaim_connection_error(servconn->session->account->gc, | |
| 256 _("Write error")); | |
| 257 } | |
| 258 | |
| 259 gboolean | |
| 260 msn_http_servconn_parse_data(MsnServConn *servconn, const char *buf, | |
| 261 size_t size, char **ret_buf, size_t *ret_size, | |
| 262 gboolean *error) | |
| 263 { | |
| 264 GaimConnection *gc; | |
| 265 const char *s, *c; | |
| 266 char *headers, *body; | |
| 267 char *tmp; | |
| 268 size_t len = 0; | |
| 269 | |
| 270 g_return_val_if_fail(servconn != NULL, FALSE); | |
| 271 g_return_val_if_fail(buf != NULL, FALSE); | |
| 272 g_return_val_if_fail(size > 0, FALSE); | |
| 273 g_return_val_if_fail(ret_buf != NULL, FALSE); | |
| 274 g_return_val_if_fail(ret_size != NULL, FALSE); | |
| 275 g_return_val_if_fail(error != NULL, FALSE); | |
| 276 | |
|
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
277 #if 0 |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
278 gaim_debug_info("msn", "parsing data {%s} from fd %d\n", |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
279 buf, servconn->fd); |
|
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
280 #endif |
| 7288 | 281 servconn->http_data->waiting_response = FALSE; |
| 282 | |
| 283 gc = gaim_account_get_connection(servconn->session->account); | |
| 284 | |
| 285 /* Healthy defaults. */ | |
| 286 *ret_buf = NULL; | |
| 287 *ret_size = 0; | |
| 288 *error = FALSE; | |
| 289 | |
| 290 /* 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
|
291 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
|
292 (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) != 0)) && |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
293 ((strncmp(buf, "HTTP/1.0 200 OK\r\n", 17) != 0) && |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
294 (strncmp(buf, "HTTP/1.0 100 Continue\r\n", 23) != 0))) |
| 7288 | 295 { |
| 296 *error = TRUE; | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
297 |
| 7288 | 298 return FALSE; |
| 299 } | |
| 300 | |
| 301 if (strncmp(buf, "HTTP/1.1 100 Continue\r\n", 23) == 0) | |
| 302 { | |
| 303 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
| 304 return FALSE; | |
| 305 | |
| 306 s += 4; | |
| 307 | |
| 308 if (*s == '\0') | |
| 309 { | |
| 310 *ret_buf = g_strdup(""); | |
| 311 *ret_size = 0; | |
| 312 | |
| 313 return TRUE; | |
| 314 } | |
| 315 | |
| 316 buf = s; | |
| 317 size -= (s - buf); | |
| 318 } | |
| 319 | |
| 320 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | |
| 321 return FALSE; | |
| 322 | |
| 323 headers = g_strndup(buf, s - buf); | |
| 324 s += 4; /* Skip \r\n */ | |
| 325 body = g_strndup(s, size - (s - buf)); | |
| 326 | |
|
8299
7402101c0319
[gaim-migrate @ 9023]
Christian Hammond <chipx86@chipx86.com>
parents:
8298
diff
changeset
|
327 #if 0 |
| 7288 | 328 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
|
329 #endif |
| 7288 | 330 |
| 331 if ((s = strstr(headers, "Content-Length: ")) != NULL) | |
| 332 { | |
| 333 s += strlen("Content-Length: "); | |
| 334 | |
| 335 if ((c = strchr(s, '\r')) == NULL) | |
| 336 { | |
| 337 g_free(headers); | |
| 338 g_free(body); | |
| 339 | |
| 340 return FALSE; | |
| 341 } | |
| 342 | |
| 343 tmp = g_strndup(s, c - s); | |
| 344 len = atoi(tmp); | |
| 345 g_free(tmp); | |
| 346 | |
| 347 if (strlen(body) != len) | |
| 348 { | |
| 349 g_free(headers); | |
| 350 g_free(body); | |
| 351 | |
| 352 gaim_debug_warning("msn", | |
| 353 "body length (%d) != content length (%d)\n", | |
| 354 strlen(body), len); | |
| 355 return FALSE; | |
| 356 } | |
| 357 } | |
| 358 | |
| 359 /* Now we should be able to process the data. */ | |
| 360 if ((s = strstr(headers, "X-MSN-Messenger: ")) != NULL) | |
| 361 { | |
| 362 char *session_id, *gw_ip; | |
| 363 char *c2, *s2; | |
| 364 | |
| 365 s += strlen("X-MSN-Messenger: "); | |
| 366 | |
| 367 if ((c = strchr(s, '\r')) == NULL) | |
| 368 { | |
| 369 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
| 370 return FALSE; | |
| 371 } | |
| 372 | |
| 373 tmp = g_strndup(s, c - s); | |
| 374 | |
| 375 /* Find the value for the Session ID */ | |
| 376 if ((s2 = strchr(tmp, '=')) == NULL) | |
| 377 { | |
| 378 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
| 379 return FALSE; | |
| 380 } | |
| 381 | |
| 382 s2++; | |
| 383 | |
| 384 /* Terminate the ; so we can g_strdup it. */ | |
| 385 if ((c2 = strchr(s2, ';')) == NULL) | |
| 386 { | |
| 387 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
| 388 return FALSE; | |
| 389 } | |
| 390 | |
| 391 *c2 = '\0'; | |
| 392 c2++; | |
| 393 | |
| 394 /* Now grab that session ID. */ | |
| 395 session_id = g_strdup(s2); | |
| 396 | |
| 397 /* Continue to the gateway IP */ | |
| 398 if ((s2 = strchr(c2, '=')) == NULL) | |
| 399 { | |
| 400 gaim_connection_error(gc, "Malformed X-MSN-Messenger field."); | |
| 401 return FALSE; | |
| 402 } | |
| 403 | |
| 404 s2++; | |
| 405 | |
| 406 /* Grab the gateway IP */ | |
| 407 gw_ip = g_strdup(s2); | |
| 408 | |
| 409 g_free(tmp); | |
| 410 | |
| 411 /* Set the new data. */ | |
| 412 if (servconn->http_data->session_id != NULL) | |
| 413 g_free(servconn->http_data->session_id); | |
| 414 | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
415 if (servconn->http_data->old_gateway_host != NULL) |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
416 g_free(servconn->http_data->old_gateway_host); |
| 7288 | 417 |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
418 servconn->http_data->old_gateway_host = |
|
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
419 servconn->http_data->gateway_host; |
| 7288 | 420 |
| 421 servconn->http_data->session_id = session_id; | |
|
9158
c30d81b4dd22
[gaim-migrate @ 9942]
Christian Hammond <chipx86@chipx86.com>
parents:
9085
diff
changeset
|
422 servconn->http_data->gateway_host = gw_ip; |
| 7288 | 423 } |
| 424 | |
| 425 g_free(headers); | |
| 426 | |
| 427 *ret_buf = body; | |
| 428 *ret_size = len; | |
| 429 | |
| 430 if (servconn->http_data->queue != NULL) | |
| 431 { | |
| 432 MsnHttpQueueData *queue_data; | |
| 433 | |
| 434 queue_data = (MsnHttpQueueData *)servconn->http_data->queue->data; | |
| 435 | |
| 436 servconn->http_data->queue = | |
| 437 g_list_remove(servconn->http_data->queue, queue_data); | |
| 438 | |
| 439 msn_http_servconn_write(queue_data->servconn, | |
| 440 queue_data->buffer, | |
| 441 queue_data->size, | |
| 442 queue_data->server_type); | |
| 443 | |
| 444 g_free(queue_data->buffer); | |
| 445 g_free(queue_data); | |
| 446 } | |
| 447 else | |
|
8298
c719f9a181d4
[gaim-migrate @ 9022]
Christian Hammond <chipx86@chipx86.com>
parents:
8287
diff
changeset
|
448 servconn->http_data->dirty = TRUE; |
| 7288 | 449 |
| 450 return TRUE; | |
| 451 } | |
| 452 |
