Mercurial > pidgin
comparison libpurple/protocols/msn/httpconn.c @ 24446:ae66b7b3086a
Make the two "read_cb()" functions more similar, and fix a rare
memleak in httpconn by adding a call to g_free(header). Only
happens if the server sends us abnormal data.
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Sat, 15 Nov 2008 09:44:05 +0000 |
parents | 892adcbf94c9 |
children | d72c185d0be3 |
comparison
equal
deleted
inserted
replaced
24445:a58d730c85f6 | 24446:ae66b7b3086a |
---|---|
117 | 117 |
118 if ((s = strstr(buf, "\r\n\r\n")) == NULL) | 118 if ((s = strstr(buf, "\r\n\r\n")) == NULL) |
119 /* Need to wait for the full HTTP header to arrive */ | 119 /* Need to wait for the full HTTP header to arrive */ |
120 return FALSE; | 120 return FALSE; |
121 | 121 |
122 s += 4; /* Skip \r\n */ | 122 s += 4; /* Skip \r\n\r\n */ |
123 header = g_strndup(buf, s - buf); | 123 header = g_strndup(buf, s - buf); |
124 body_start = s; | 124 body_start = s; |
125 body_len = size - (body_start - buf); | 125 body_len = size - (body_start - buf); |
126 | 126 |
127 if ((s = purple_strcasestr(header, "Content-Length: ")) != NULL) | 127 if ((s = purple_strcasestr(header, "Content-Length: ")) != NULL) |
160 body = g_malloc(body_len + 1); | 160 body = g_malloc(body_len + 1); |
161 memcpy(body, body_start, body_len); | 161 memcpy(body, body_start, body_len); |
162 body[body_len] = '\0'; | 162 body[body_len] = '\0'; |
163 | 163 |
164 #ifdef MSN_DEBUG_HTTP | 164 #ifdef MSN_DEBUG_HTTP |
165 purple_debug_misc("msn", "Incoming HTTP buffer (header): {%s\r\n}\n", | 165 purple_debug_misc("msn", "Incoming HTTP buffer (header): {%s}\n", |
166 header); | 166 header); |
167 #endif | 167 #endif |
168 | 168 |
169 /* Now we should be able to process the data. */ | 169 /* Now we should be able to process the data. */ |
170 if ((s = purple_strcasestr(header, "X-MSN-Messenger: ")) != NULL) | 170 if ((s = purple_strcasestr(header, "X-MSN-Messenger: ")) != NULL) |
182 msn_session_set_error(httpconn->session, | 182 msn_session_set_error(httpconn->session, |
183 MSN_ERROR_HTTP_MALFORMED, NULL); | 183 MSN_ERROR_HTTP_MALFORMED, NULL); |
184 purple_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}\n", | 184 purple_debug_error("msn", "Malformed X-MSN-Messenger field.\n{%s}\n", |
185 buf); | 185 buf); |
186 | 186 |
187 g_free(header); | |
187 g_free(body); | 188 g_free(body); |
188 return FALSE; | 189 return FALSE; |
189 } | 190 } |
190 | 191 |
191 tmp = g_strndup(s, c - s); | 192 tmp = g_strndup(s, c - s); |
276 char *result_msg = NULL; | 277 char *result_msg = NULL; |
277 size_t result_len = 0; | 278 size_t result_len = 0; |
278 gboolean error = FALSE; | 279 gboolean error = FALSE; |
279 | 280 |
280 httpconn = data; | 281 httpconn = data; |
281 servconn = NULL; | 282 servconn = httpconn->servconn; |
282 session = httpconn->session; | 283 session = httpconn->session; |
283 | 284 |
285 if (servconn->type == MSN_SERVCONN_NS) | |
286 session->account->gc->last_received = time(NULL); | |
287 | |
284 len = read(httpconn->fd, buf, sizeof(buf) - 1); | 288 len = read(httpconn->fd, buf, sizeof(buf) - 1); |
285 | |
286 if (len < 0 && errno == EAGAIN) | 289 if (len < 0 && errno == EAGAIN) |
287 return; | 290 return; |
288 else if (len <= 0) | 291 if (len <= 0) { |
289 { | 292 purple_debug_error("msn", "HTTP: servconn %03d read error, " |
290 purple_debug_error("msn", "HTTP: Read error\n"); | 293 "len: %" G_GSSIZE_FORMAT ", errno: %d, error: %s\n", |
291 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); | 294 servconn->num, len, error, g_strerror(errno)); |
295 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ); | |
292 | 296 |
293 return; | 297 return; |
294 } | 298 } |
295 | 299 |
296 buf[len] = '\0'; | 300 buf[len] = '\0'; |
302 if (!msn_httpconn_parse_data(httpconn, httpconn->rx_buf, httpconn->rx_len, | 306 if (!msn_httpconn_parse_data(httpconn, httpconn->rx_buf, httpconn->rx_len, |
303 &result_msg, &result_len, &error)) | 307 &result_msg, &result_len, &error)) |
304 { | 308 { |
305 /* Either we must wait for more input, or something went wrong */ | 309 /* Either we must wait for more input, or something went wrong */ |
306 if (error) | 310 if (error) |
307 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); | 311 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ); |
308 | 312 |
309 return; | 313 return; |
310 } | 314 } |
311 | 315 |
312 servconn = httpconn->servconn; | |
313 | |
314 if (error) | 316 if (error) |
315 { | 317 { |
316 purple_debug_error("msn", "HTTP: Special error\n"); | 318 purple_debug_error("msn", "HTTP: Special error\n"); |
317 msn_servconn_got_error(httpconn->servconn, MSN_SERVCONN_ERROR_READ); | 319 msn_servconn_got_error(servconn, MSN_SERVCONN_ERROR_READ); |
318 | 320 |
319 return; | 321 return; |
320 } | 322 } |
321 | 323 |
322 g_free(httpconn->rx_buf); | 324 g_free(httpconn->rx_buf); |