curl-users
problems with CURLOPT_READFUNCTION
Date: Thu, 10 Jul 2003 12:07:59 +0530
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
Received on 2003-07-10