cURL / Mailing Lists / curl-library / Single Mail

curl-library

Enabling cookies without a file

From: Dave Dribin <dave-ml_at_dribin.org>
Date: Tue, 1 Mar 2005 18:05:44 -0600

Hello,

I'm using libcurl as a cross platform HTTP library (current targets are
Windows, Linux and OS X). We need to use cookies, but do not need to
store them in a file. They are only relevant for logging in, and we
don't need to persist login sessions. The only way I can figure out
how to do this is to use CURLOPT_COOKIEFILE with an empty or
nonexistent file. But there is no good cross platform empty or
nonexistent file. "/dev/null" works on the Unix variants, but isn't so
good for Windows. So my first question: is there a way of enabling
cookies without using CURLOPT_COOKIEFILE? I haven't found a way to do
this, so another alternative I've tried is to set the cookie file to an
empty string, "". And this actually works on all three platforms with
one issue. Windows complains (using a nasty error dialog box) with a
debug assertion (obviously compiled against debug libraries), saying
"*file != _T('\0')" in fopen.c, line 55. It doesn't seem to like
passing "" to fopen() (for good reason).

I was looking through cookie.c from version 7.13.0, and around 650,
there is this code:

   if(file && strequal(file, "-")) {
     fp = stdin;
     fromfile=FALSE;
   }
   else
     fp = file?fopen(file, "r"):NULL;

I think if an explicit check for an empty string is added, then this
will solve my issue. I've tested the following code and it seems to
work:

   if(file && strequal(file, "-")) {
     fp = stdin;
     fromfile=FALSE;
   }
   else if (file && strequal(file, "")
     fp = NULL;
   else
     fp = file?fopen(file, "r"):NULL;

It's worth pointing out that I cannot figure out any possible way for
"file" to be null (you can't pass CURLOPT_COOKIEFILE a NULL).

-Dave
Received on 2005-03-02