|
Lines 2133-2146
parse_redirect(const char *data, size_t
Link Here
|
| 2133 |
static size_t |
2133 |
static size_t |
| 2134 |
parse_content_len(const char *data, size_t data_len) |
2134 |
parse_content_len(const char *data, size_t data_len) |
| 2135 |
{ |
2135 |
{ |
| 2136 |
int content_len = 0; |
2136 |
size_t content_len = 0; |
| 2137 |
char *tmp; |
2137 |
const char *p = NULL; |
| 2138 |
|
2138 |
|
| 2139 |
tmp = g_malloc(data_len + 1); |
2139 |
/* This is still technically wrong, since headers are case-insensitive |
| 2140 |
memcpy(tmp, data, data_len); |
2140 |
* [RFC 2616, section 4.2], though this ought to catch the normal case. |
| 2141 |
tmp[data_len] = '\0'; |
2141 |
* Note: data is _not_ nul-terminated. |
| 2142 |
sscanf(tmp, "Content-Length: %d", &content_len); |
2142 |
*/ |
| 2143 |
g_free(tmp); |
2143 |
if (data_len > 16) { |
|
|
2144 |
p = strncmp(data, "Content-Length: ", 16) == 0? data: NULL; |
| 2145 |
if (!p) { |
| 2146 |
p = g_strstr_len(data, data_len, "\nContent-Length: "); |
| 2147 |
if (p) |
| 2148 |
p += 1; |
| 2149 |
} |
| 2150 |
} |
| 2151 |
|
| 2152 |
/* If we can find a Content-Length header at all, try to sscanf it. |
| 2153 |
* Response headers should end with at least \r\n, so sscanf is safe, |
| 2154 |
* if we make sure that there is indeed a \n in our header. |
| 2155 |
*/ |
| 2156 |
if (p && g_strstr_len(p, data_len - (p - data), "\n")) { |
| 2157 |
sscanf(p, "Content-Length: %u", (int *)&content_len); |
| 2158 |
gaim_debug_misc("parse_content_len", "parsed %u\n", content_len); |
| 2159 |
} |
| 2144 |
|
2160 |
|
| 2145 |
return content_len; |
2161 |
return content_len; |
| 2146 |
} |
2162 |
} |
|
Lines 2271-2277
url_fetched_cb(gpointer url_data, gint s
Link Here
|
| 2271 |
|
2287 |
|
| 2272 |
/* In with the new. */ |
2288 |
/* In with the new. */ |
| 2273 |
gfud->data_len = content_len; |
2289 |
gfud->data_len = content_len; |
| 2274 |
gfud->webdata = g_malloc(gfud->data_len); |
2290 |
gfud->webdata = g_try_malloc(gfud->data_len); |
|
|
2291 |
if (gfud->webdata == NULL) { |
| 2292 |
gaim_debug_error("gaim_url_fetch", "Failed to allocate %u bytes: %s\n", gfud->data_len, strerror(errno)); |
| 2293 |
gaim_input_remove(gfud->inpa); |
| 2294 |
close(sock); |
| 2295 |
gfud->callback(gfud->user_data, NULL, 0); |
| 2296 |
destroy_fetch_url_data(gfud); |
| 2297 |
} |
| 2298 |
|
| 2275 |
} |
2299 |
} |
| 2276 |
else |
2300 |
else |
| 2277 |
gfud->newline = TRUE; |
2301 |
gfud->newline = TRUE; |
|
Lines 2349-2355
gaim_url_decode(const char *str)
Link Here
|
| 2349 |
|
2373 |
|
| 2350 |
g_return_val_if_fail(str != NULL, NULL); |
2374 |
g_return_val_if_fail(str != NULL, NULL); |
| 2351 |
|
2375 |
|
| 2352 |
for (i = 0; i < strlen(str); i++) { |
2376 |
for (i = 0; i < strlen(str) && j < sizeof(buf)-2; i++) { |
| 2353 |
char hex[3]; |
2377 |
char hex[3]; |
| 2354 |
|
2378 |
|
| 2355 |
if (str[i] != '%') |
2379 |
if (str[i] != '%') |
|
Lines 2386-2394
gaim_url_encode(const char *str)
Link Here
|
| 2386 |
g_return_val_if_fail(str != NULL, NULL); |
2410 |
g_return_val_if_fail(str != NULL, NULL); |
| 2387 |
|
2411 |
|
| 2388 |
for (i = 0; i < strlen(str); i++) { |
2412 |
for (i = 0; i < strlen(str); i++) { |
| 2389 |
if (isalnum(str[i])) |
2413 |
if (isalnum(str[i])) { |
|
|
2414 |
if(j+1 >= sizeof(buf)-1) break; |
| 2390 |
buf[j++] = str[i]; |
2415 |
buf[j++] = str[i]; |
|
|
2416 |
} |
| 2391 |
else { |
2417 |
else { |
|
|
2418 |
if(j+3 >= sizeof(buf)-1) break; |
| 2392 |
sprintf(buf + j, "%%%02x", (unsigned char)str[i]); |
2419 |
sprintf(buf + j, "%%%02x", (unsigned char)str[i]); |
| 2393 |
j += 3; |
2420 |
j += 3; |
| 2394 |
} |
2421 |
} |