Note that there are some explanatory texts on larger screens.

plurals
  1. POImporting Firefox and Chrome cookies to libcurl
    primarykey
    data
    text
    <p>I'm using Code::Blocks with MinGW, under Windows 7. I'm writing a multithreaded web crawler with libcurl, using a <a href="http://curl.haxx.se/libcurl/c/curl_share_setopt.html" rel="nofollow">CURLSH</a> object with CURL_LOCK_DATA_COOKIE enabled to share cookies among different threads. Once a handle receives a cookie, it is successfully shared among every other handle. However, I need to copy the initial set of cookies from Firefox or Chrome. I found that they store cookies using sqlite, and I've been able to read cookies from both of them from within my program. The problem is, how do I give these cookies to libcurl? Ideally, there should be some way to feed these cookies to my CURLSH object, so that they get distributed to every handle. I have found no such thing.</p> <p>Following <a href="http://www.cookiecentral.com/faq/#3.5" rel="nofollow">this document</a>, I can try to save the cookies I read from my browser to a <em>cookies.txt</em> file, which reduces to finding a correspondence between the fields in the database used by Firefox/Chrome and the Netscape format. Netscape uses the following format:</p> <blockquote> <p>domain flag path secure expiration name value</p> </blockquote> <p>The problem comes with the flag field. I don't know what to write there. Firefox uses the following fields (file <em>cookies.sqlite</em>, table *moz_cookies*), which correspond with the Netscape format as follows (is this correct?):</p> <blockquote> <p>host ??? path isSecure expiry name value</p> </blockquote> <p>Chrome uses the following fields (file <em>Cookies</em>, table <em>cookies</em>):</p> <blockquote> <p>host_key ??? path secure expires_utc name value</p> </blockquote> <p>So, to create this <em>cookies.txt</em> file, I'm only missing that flag field. The document linked above says:</p> <blockquote> <p>flag - A TRUE/FALSE value indicating if all machines within a given domain can access the variable. This value is set automatically by the browser, depending on the value you set for domain.</p> </blockquote> <p>Which doesn't really tell me what to write there. However, writting a file and then reading it seems like unnecessary work, given that I'll first load the cookies from Firefox/Chrome in RAM, and I should be able to give them to libcurl directly without going through the hard drive. I've found the <a href="http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTCOOKIE" rel="nofollow">CURLOPT_COOKIE</a> option, but it is missing some fields (namely, domain). Also, that option doesn't seem to save the cookies for posterior use. It looks like I would need to call it for every transaction with only the cookies of the corresponding domain (and what if these cookies get changed? I would not want to check for changes manually, given that libcurl can do that).</p> <p>So, given that I have all my cookies from Firefox/Chrome in memory, how do I give them to libcurl? If the only option is to use a <em>cookies.txt</em> file, what should I write in the flag field?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload