Braden McDaniel | 1 Jan 01:55 2007

Crash in curl_easy_cleanup

I have the following loop to see what transfers are complete:

        while ((msg = curl_multi_info_read(curl_source->multi_handle,
                                           &msgs_in_queue))) {
            if (msg->msg == CURLMSG_DONE) {
                curl_multi_remove_handle(curl_source->multi_handle,
                                         msg->easy_handle);
                const stream_data_map_t::size_type num_erased =
                    callback_data->stream_data_map.erase(msg->easy_handle);
                g_assert(num_erased == 1);
                g_assert(curl_source->outstanding_handles > 0);
                --curl_source->outstanding_handles;
                std::ostringstream command;
                command << "destroy-stream " << ptrdiff_t(msg->easy_handle) << '\n';
                const ssize_t bytes_written = ::write_command(command.str());
                g_return_val_if_fail(
                    bytes_written == ssize_t(command.str().length()),
                    false);
                curl_easy_cleanup(msg->easy_handle);
            }
        }

I get a crash in response to the call to curl_easy_cleanup at the end of
the loop. Clearly I'm Doing It Wrong; however, the Right way to do this
isn't clear to me. The documentation indicates that the easy handle is
usable on its own after being removed from the multi handle; so
presumably I need to call curl_easy_cleanup on it (right?). But if it's
not safe to do that at this point, when is it safe to do?

--

-- 
(Continue reading)

Daniel Stenberg | 2 Jan 00:27 2007
Picon

Re: Crash in curl_easy_cleanup

On Sun, 31 Dec 2006, Braden McDaniel wrote:

> I have the following loop to see what transfers are complete:
>
>        while ((msg = curl_multi_info_read(curl_source->multi_handle,
>                                           &msgs_in_queue))) {
>            if (msg->msg == CURLMSG_DONE) {
>                curl_multi_remove_handle(curl_source->multi_handle,
>                                         msg->easy_handle);

>                const stream_data_map_t::size_type num_erased =
>                    callback_data->stream_data_map.erase(msg->easy_handle);

This is not done properly. The man page for curl_multi_info_read() explains 
that the data it returns will not survive a call to 
curl_multi_remove_handle().

You thus need to copy the data you need from the 'msg' struct before you call 
curl_multi_remove_handle or curl_easy_cleanup.

> The documentation indicates that the easy handle is usable on its own after 
> being removed from the multi handle;

It is.

> so presumably I need to call curl_easy_cleanup on it (right?). But if it's 
> not safe to do that at this point, when is it safe to do?

It is safe to do, but with this setup you most likely passed in junk to 
curl_easy_cleanup...
(Continue reading)

Braden McDaniel | 1 Jan 18:07 2007

Re: Crash in curl_easy_cleanup

On Sun, 2006-12-31 at 19:55 -0500, Braden McDaniel wrote:
> I have the following loop to see what transfers are complete:

[snip]

> I get a crash in response to the call to curl_easy_cleanup at the end of
> the loop. Clearly I'm Doing It Wrong; however, the Right way to do this
> isn't clear to me. The documentation indicates that the easy handle is
> usable on its own after being removed from the multi handle; so
> presumably I need to call curl_easy_cleanup on it (right?). But if it's
> not safe to do that at this point, when is it safe to do?

Nevermind. I realize now that my call to curl_multi_remove_handle
invalidates the data msg points to; assigning msg->easy_handle to a
temporary variable before doing so (and calling curl_easy_cleanup using
that) appears to solve the problem.

--

-- 
Braden McDaniel                           e-mail: <braden <at> endoframe.com>
<http://endoframe.com>                    Jabber: <braden <at> jabber.org>

Daniel Stenberg | 2 Jan 23:47 2007
Picon

Re: Patch to allow base64 encoding/decoding on non-ASCII platforms.

On Sun, 31 Dec 2006, David McCreedy wrote:

> This patch allows Base64 encoding/decoding to work on non-ASCII platforms 
> and mainly affects base64.c and base64.h.

Can you verify how you made/attached this patch?

$ patch -p1 < patches/base64_nonascii_patch1.txt
patching file lib/base64.c
patch: **** malformed patch at line 13: /* include memdebug.h last */

--

-- 
  Commercial curl and libcurl Technical Support: http://haxx.se/curl.html

kuriakose | 3 Jan 07:56 2007

getting header information

 

 

How do I get the information like size of the file and date time of file in the server

without downloading.

One way is set CURLOPT_NOBODY  and give a call back function so that the header information is written to a file

And then read from the file. Is there some other way to get these info directly in code.

 

 

 

 

 

 


Regards

Kuriakose

 

 

 

Ralph Mitchell | 3 Jan 12:14 2007
Picon

Re: getting header information

On 1/3/07, kuriakose <kuriakose <at> huawei.com> wrote:
>
> How do I get the information like size of the file and date time of file in
> the server
>
> without downloading.
>
> One way is set CURLOPT_NOBODY  and give a call back function so that the
> header information is written to a file
>
> And then read from the file. Is there some other way to get these info
> directly in code.

Why not use CURLOPT_HEADERFUNCTION and set your own callback to
process the headers??  Man page says:

              Function pointer that  should  match  the  following  prototype:
              size_t  function(  void  *ptr,  size_t  size, size_t
nmemb, void *stream);
              This function gets called by libcurl as  soon  as  it
has  received  header
              data.  The header callback will be called once for each
header and only
              complete header lines  are  passed on  to the callback.

Ralph Mitchell

atul | 3 Jan 12:07 2007

LibCURL error codes

hii all.. I m using following code snippet for my project. I am facing
the problems in getting proper error code.

//Code Snippet
  CURLcode res;
  char *error;
  if (handle)
    return;             // already running

  handle = curl_easy_init();

  curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ::write_cb);
  curl_easy_setopt(handle, CURLOPT_WRITEDATA, this);

  curl_easy_setopt(handle, CURLOPT_HEADERFUNCTION, ::header_cb);
  curl_easy_setopt(handle, CURLOPT_WRITEHEADER, this);

  curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1);
  curl_easy_setopt(handle, CURLOPT_MAXREDIRS, 10);

  res=curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, TRUE);
  curl_easy_setopt(handle, CURLOPT_ERRORBUFFER, error);
  printf("\n%d\n", res);
  printf ("\n%s\n", error);
  if(res)
     curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, FALSE);

I am using CURLOPT_SSL_VERIFYPEER for the url's whose server certificate
can be authenticated with curl's certificate bundle.
   res=curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, TRUE);

In case the server certificate can not be verified i want curl to go
ahead by skipping the server certificate verification.
  if(res)
     curl_easy_setopt(handle, CURLOPT_SSL_VERIFYPEER, FALSE);

But the value of res is always CURLE_OK whether the server certificate
gets validated or not . According to libcurl error codes i expect it to
return error_code CURLE_SSL_PEER_CERTIFICATE (51) if the peer doesnt get
validated.

Can any tell me that where i am goin wrong????

kuriakose | 3 Jan 15:59 2007

reg CURLOPT_FILETIME

 

Hi,

I am trying to use CURLOPT_FILETIME  to get the modification time of file in the server.

           long filetime=1;

          

       curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime);

 

After easy perform ,I am expecting the filetime variable should contain the modification time of the file.

But it is not .

Is there any problem with the way I am using.

 

Is it applicable to both http and ftp

 

Plz help.

 

 

 


Regards

Kuriakose

 

 

man | 3 Jan 16:30 2007
Picon

Re: reg CURLOPT_FILETIME

from the manual:

"Pass a pointer to a long"

try:

curl_easy_getinfo(curl,CURLINFO_FILETIME,&filetime);

allan

On Wed, Jan 3, 2007, kuriakose <kuriakose <at> huawei.com> said:

>  
> 
> Hi,
> 
> I am trying to use CURLOPT_FILETIME  to get the modification time of file in
> the server.
> 
>            long filetime=1;
> 
>            
> 
>        curl_easy_getinfo(curl,CURLINFO_FILETIME,filetime);
> 
>  
> 
> After easy perform ,I am expecting the filetime variable should contain the
> modification time of the file.
> 
> But it is not . 
> 
> Is there any problem with the way I am using. 
> 
>  
> 
> Is it applicable to both http and ftp 
> 
>  
> 
> Plz help.
> 
>  
> 
>  
> 
>  
> 
> 
> Regards
> 
> Kuriakose 
> 
>  
> 
>  
> 
> 

--

-- 
m. allan noah
IT Director, TfHS.net
ph# (804) 355-5489
tf# (866) 724-9722
fx# (804) 355-0477

Daniel Moghaddass | 3 Jan 16:47 2007
Picon

Re: reg CURLOPT_FILETIME

Hi,

i think you have to perform the tasks the following way (but i never tried alternatives):
1.) enable the appropriate option for getting the filetime
2.) perform your request
3.) examine the last requests filetime before requesting another uri

which might look like the following handwritten snippet:
...

long filetime;

curl_easy_setopt(curl_handle, CURLOPT_FILETIME, 1l);

curl_easy_perform(...);

curl_easy_getinfo(handle, CURLINFO_FILETIME, &filetime);

...


Gmane