cURL / Mailing Lists / curl-library / Single Mail

curl-library

Re: Problem in receiving the compressed data

From: Daniel Stenberg <daniel_at_haxx.se>
Date: Mon, 12 Nov 2001 08:57:48 +0100 (MET)

On Thu, 8 Nov 2001, Shailesh Mittal wrote:

> I am have the same old problem in receiving the compressed data from a
> Servlet running on tomcat.

> Initially, I was trying to receive the body data in memory (used the
> sample getinmemory.c) and coded the callback function as
>
> size_t WriteMemoryCallback(void *ptr, size_t size,
> size_t nmemb, void *data)
> {
> register int realsize = size * nmemb;
> struct MemoryStruct *mem = (struct MemoryStruct
> *)data;
>
> mem->memory = (char *)realloc(mem->memory,
> mem->size + realsize + 1);
> if (mem->memory) {
> memcpy(&(mem->memory[mem->size]), ptr,
> realsize);
> mem->size += realsize;
> mem->memory[mem->size] = 0;
> }
> return realsize;
> }

> I was getting NO data other than "||||" in the "void *ptr". Interestingly
> the value of (size * nmemb) is around 270.

I find this very odd and I can't explain any such behavior. It seems wrong
somewhere.

The getinmemory.c example source code should work pretty much as-is.

Did you set the VERBOSE to 1 and had a look at the output? How much data were
you supposed to get? Is this really compiled as C and not C++?

> Where is the data to be uncompressed? I have to pass the compressed data
> to a function so than I can uncompress it.

libcurl doesn't uncompress anything (in the current incarnation, I hope that
it will one day), it gets the data just as passed to us by the server. You
should get compressed data if the server sends compressed data.

The intention here is of course that this callback is called by libcurl as
soon as it has received data from the remote server.

> I then switched to dumping the data into a file (code listing below)
> instead of capturing it in memory. This time I get the compressed data
> but it is not complete.

Well, libcurl can't possibly know what you do with the data so I can't see
how libcurl can behave differently when you decide to do different things
with the data.

> On uncompressing the file, I get only half of the XML document. Why I am
> not getting the complete data?

Unfortunately, I can't explain that.

Can you single-step into the Transfer() (lib/transfer.c) function and just
follow it when it fetches data from the server and calls the callback to see
what it does and why?

> 1. I used curl.exe and able to see the compressed data.

This indicates that libcurl works fine, if only used correctly.

> 2. I accessed the URL thru IE. It uncompressed the data and displayed the
> actual XML.

Yeps, IE and other browsers will decompress it automatically.

-- 
    Daniel Stenberg -- curl groks URLs -- http://curl.haxx.se/
Received on 2001-11-12