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