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