cURL / Mailing Lists / curl-users / Single Mail

curl-users

Re: problems with CURLOPT_READFUNCTION

From: Dhanvi Kapila <kapiladhanvi_at_hotmail.com>
Date: Mon, 14 Jul 2003 16:03:42 +0530

Hi
Thanks for the reply. Yeah the "size" in the structure is actually the size
of the binary data. I already have a custom built webserver that accepts the
encrypted string.

I finally managed to get solve the problem..though I cannot figure out
anything wrong in the function logic that I have used below.. The change I
did in my new code is as shown
> > if( xfer >= (in->cbs.size - in->offset) )
changed to
         if( in->offset + xfer >= in->cbs.size )

This change and Curl works like a song .. Any ideas as to what went wrong ?

with regards,
Dhanvi Kapila

----- Original Message -----
From: "Ralph Mitchell" <rmitchell_at_eds.com>
To: <curl-users_at_lists.sourceforge.net>
Sent: Thursday, July 10, 2003 12:31 PM
Subject: Re: problems with CURLOPT_READFUNCTION

> This is just a wild guess, you understand... If you're trying to post
> encrypted data to a web server, you probably need to encode it so that
> it's more-or-less pure alphanumeric ASCII, otherwise the web server
> might do something silly with it. Curl doesn't do this for you, so
> you'll need to find something (or write something) to do it for you.
>
> Or it might be a different problem altogether... You could check it out
> by temporarily passing a simple ASCII string, such as "ABCDEFGH12345678"
> and see if it makes it though intact.
>
> BTW, even if your encrypted data is all alphanumeric, if you're sending
> a struct that holds a 'size' int you're sending binary...
>
> Ralph Mitchell
>
>
> Dhanvi Kapila wrote:
>
> >Hi Friends ,
> >
> >I am new to the list..
> >
> >I am using cURL here at my work place for sending and reading data
between a
> >client and server. All the data interaction between is encrypted.
> >
> >I am using the CURLOPT_READFUNCTION option of cURL api to send data to
the
> >server.
> >I am provding below a snippet of my code for reference.. I am not sure
where
> >I am goin wrong in ... when the server reads the data .. I get a "could
not
> >decrypt packet" error
> >
> >-- code snippet -----
> >
> >typedef struct CBIGSTRING_T
> >{
> > CBigString cbs; /* this contains 2 fields.. 1) char *inputString, 2)
> >long size.. The "inputString" contains the actual encrypted data and
"size"
> >is the size of the payload */
> > long offset;
> > pool *p; /* Apache resource pool */
> >}CBigString_t;
> >
> >CBigString_t cbst_in ;
> >
> >/* filling in the variale with the encrypted content. */
> >cbst_in.cbs.inputString = (char *)malloc( totalRead +1); /* allocating
> >storage */
> >cbst_in.cbs.inputString = (char *)memcpy( cbst_in.cbs.inputString ,
> >actualStr , totalRead ); /*copying the encrypted data as is from the
> >tempBuffer given to me by Apache*/
> >cbst_in.cbs.inputString[totalRead] = '\0'; /* terminating the encrypted
> >String*/
> >cbst_in.cbs.size = totalRead;
> >cbst_in.offset = 0;
> >cbst_in.p = p;
> >
> >curl_easy_setopt( realmHandle , CURLOPT_READFUNCTION ,
> >Curl_SendDataToServer ); /* function to send data to the server*/
> >curl_easy_setopt( realmHandle , CURLOPT_READDATA , &cbst_in );
/*
> >variable contains the encrypted packet */
> >
> >static int Curl_SendDataToServer(void *buffer, size_t size, size_t nmemb,
> >CBigString_t *in)
> >{
> > LogTrace( in->p , " ----------> Entering Curl_SendDataToServer
> ><----------");
> > if (in == NULL) {
> > return -1;
> > }
> >
> > long xfer = nmemb * size ;
> > /* Check if the size presented by CURL is greated than that actually
> >needs to be copied */
> > LogDebug( in->p , " [ OFFSET, SIZE ] => [ %d , %d ] ", in->offset ,
> >in->cbs.size);
> >
> > if( xfer >= (in->cbs.size - in->offset) )
> > {
> > xfer = (in->cbs.size - in->offset) ;
> > }
> > if( in->offset < in->cbs.size )
> > {
> > buffer = memcpy( (char *)buff, in->cbs.inputString + in->offset,
> >xfer );
> > in->offset += xfer; /* reflect the updated offset value.. which
says
> >stores how much has been read from the encrypted payload. */
> > }
> > else
> > {
> > xfer = -1;
> > }
> > LogDebug( in->p , " BUFFER SIZE : %d, %d , |%s| ", size*nmemb, xfer,
> >buffer);
> > LogTrace( in->p , " ----------> Leaving Curl_SendDataToServer
> ><----------");
> > return xfer;
> >}
> >---- end of code -----
> >
> >when I do a tcpdump of the arrived packet and the dispatched packet.. the
> >packet data dont match.. hence the error is when I am sending the data
using
> >this piece of code.. please help me.. I am at a loss to find out the
> >error....
> >
> >Awaiting your replies.. Thank you for your help and time.
> >
> >-Dhanvi Kapila
> >
> >
> >-------------------------------------------------------
> >This SF.Net email sponsored by: Parasoft
> >Error proof Web apps, automate testing & more.
> >Download & eval WebKing and get a free book.
> >www.parasoft.com/bulletproofapps
> >
> >
>
>
>
>
> -------------------------------------------------------
> This SF.Net email sponsored by: Parasoft
> Error proof Web apps, automate testing & more.
> Download & eval WebKing and get a free book.
> www.parasoft.com/bulletproofapps
>

-------------------------------------------------------
This SF.Net email sponsored by: Parasoft
Error proof Web apps, automate testing & more.
Download & eval WebKing and get a free book.
www.parasoft.com/bulletproofapps1
Received on 2003-07-14