Mercurial > pidgin
comparison libpurple/util.c @ 31281:0e9b252f1769
propagate from branch 'im.pidgin.pidgin' (head b51a9f598d90ec0520c1d605d2335b29ed1ef64d)
to branch 'im.pidgin.pidgin.mxit' (head a6e78a0638ffbf99efaa856cb181db5e0cea3797)
author | andrew.victor@mxit.com |
---|---|
date | Tue, 23 Nov 2010 07:50:25 +0000 |
parents | 65ef833303b0 |
children | a8cc50c2279f |
comparison
equal
deleted
inserted
replaced
31280:7c5a78a2cc0d | 31281:0e9b252f1769 |
---|---|
3796 memcpy(data_cursor, buf, len); | 3796 memcpy(data_cursor, buf, len); |
3797 | 3797 |
3798 gfud->webdata[gfud->len] = '\0'; | 3798 gfud->webdata[gfud->len] = '\0'; |
3799 | 3799 |
3800 if(!gfud->got_headers) { | 3800 if(!gfud->got_headers) { |
3801 char *tmp; | 3801 char *end_of_headers; |
3802 | 3802 |
3803 /* See if we've reached the end of the headers yet */ | 3803 /* See if we've reached the end of the headers yet */ |
3804 if((tmp = strstr(gfud->webdata, "\r\n\r\n"))) { | 3804 end_of_headers = strstr(gfud->webdata, "\r\n\r\n"); |
3805 char * new_data; | 3805 if (end_of_headers) { |
3806 guint header_len = (tmp + 4 - gfud->webdata); | 3806 char *new_data; |
3807 guint header_len = (end_of_headers + 4 - gfud->webdata); | |
3807 size_t content_len; | 3808 size_t content_len; |
3808 | 3809 |
3809 purple_debug_misc("util", "Response headers: '%.*s'\n", | 3810 purple_debug_misc("util", "Response headers: '%.*s'\n", |
3810 header_len, gfud->webdata); | 3811 header_len, gfud->webdata); |
3811 | 3812 |
3817 | 3818 |
3818 /* No redirect. See if we can find a content length. */ | 3819 /* No redirect. See if we can find a content length. */ |
3819 content_len = parse_content_len(gfud->webdata, header_len); | 3820 content_len = parse_content_len(gfud->webdata, header_len); |
3820 gfud->chunked = content_is_chunked(gfud->webdata, header_len); | 3821 gfud->chunked = content_is_chunked(gfud->webdata, header_len); |
3821 | 3822 |
3822 if(content_len == 0) { | 3823 if (content_len == 0) { |
3823 /* We'll stick with an initial 8192 */ | 3824 /* We'll stick with an initial 8192 */ |
3824 content_len = 8192; | 3825 content_len = 8192; |
3825 } else { | 3826 } else { |
3826 gfud->has_explicit_data_len = TRUE; | 3827 gfud->has_explicit_data_len = TRUE; |
3827 } | 3828 } |
3828 | 3829 |
3829 | 3830 |
3830 /* If we're returning the headers too, we don't need to clean them out */ | 3831 /* If we're returning the headers too, we don't need to clean them out */ |
3831 if(gfud->include_headers) { | 3832 if (gfud->include_headers) { |
3832 gfud->data_len = content_len + header_len; | 3833 gfud->data_len = content_len + header_len; |
3833 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len); | 3834 gfud->webdata = g_realloc(gfud->webdata, gfud->data_len); |
3834 } else { | 3835 } else { |
3835 size_t body_len = 0; | 3836 size_t body_len = gfud->len - header_len; |
3836 | |
3837 if(gfud->len > (header_len + 1)) | |
3838 body_len = (gfud->len - header_len); | |
3839 | 3837 |
3840 content_len = MAX(content_len, body_len); | 3838 content_len = MAX(content_len, body_len); |
3841 | 3839 |
3842 new_data = g_try_malloc(content_len); | 3840 new_data = g_try_malloc(content_len); |
3843 if(new_data == NULL) { | 3841 if (new_data == NULL) { |
3844 purple_debug_error("util", | 3842 purple_debug_error("util", |
3845 "Failed to allocate %" G_GSIZE_FORMAT " bytes: %s\n", | 3843 "Failed to allocate %" G_GSIZE_FORMAT " bytes: %s\n", |
3846 content_len, g_strerror(errno)); | 3844 content_len, g_strerror(errno)); |
3847 purple_util_fetch_url_error(gfud, | 3845 purple_util_fetch_url_error(gfud, |
3848 _("Unable to allocate enough memory to hold " | 3846 _("Unable to allocate enough memory to hold " |
3852 | 3850 |
3853 return; | 3851 return; |
3854 } | 3852 } |
3855 | 3853 |
3856 /* We may have read part of the body when reading the headers, don't lose it */ | 3854 /* We may have read part of the body when reading the headers, don't lose it */ |
3857 if(body_len > 0) { | 3855 if (body_len > 0) { |
3858 tmp += 4; | 3856 memcpy(new_data, end_of_headers + 4, body_len); |
3859 memcpy(new_data, tmp, body_len); | |
3860 } | 3857 } |
3861 | 3858 |
3862 /* Out with the old... */ | 3859 /* Out with the old... */ |
3863 g_free(gfud->webdata); | 3860 g_free(gfud->webdata); |
3864 | 3861 |