Commit 41ae97e7 authored by Daniel Stenberg's avatar Daniel Stenberg
Browse files

Dirk Manske's patch that introduces cookie support to the share interface.

parent f72ba7f7
Loading
Loading
Loading
Loading
+15 −9
Original line number Diff line number Diff line
@@ -76,6 +76,7 @@
#include "url.h"
#include "getinfo.h"
#include "hostip.h"
#include "share.h"

#define _MPRINTF_REPLACE /* use our functions only */
#include <curl/mprintf.h>
@@ -233,15 +234,18 @@ CURLcode curl_easy_perform(CURL *curl)
{
  struct SessionHandle *data = (struct SessionHandle *)curl;

  if (Curl_global_host_cache_use(data) && data->hostcache != Curl_global_host_cache_get()) {
    if (data->hostcache) {
  if ( ! (data->share && data->share->hostcache) ) {

    if (Curl_global_host_cache_use(data) &&
        data->hostcache != Curl_global_host_cache_get()) {
      if (data->hostcache)
        Curl_hash_destroy(data->hostcache);
    }
      data->hostcache = Curl_global_host_cache_get();
    }

  if (!data->hostcache) {
    if (!data->hostcache)
      data->hostcache = Curl_hash_alloc(7, Curl_freednsinfo);

  }
  
  return Curl_perform(data);
@@ -250,9 +254,11 @@ CURLcode curl_easy_perform(CURL *curl)
void curl_easy_cleanup(CURL *curl)
{
  struct SessionHandle *data = (struct SessionHandle *)curl;
  if ( ! (data->share && data->share->hostcache) ) {
    if ( !Curl_global_host_cache_use(data)) {
      Curl_hash_destroy(data->hostcache);
    }
  }
  Curl_close(data);
}

+2 −0
Original line number Diff line number Diff line
@@ -853,10 +853,12 @@ CURLcode Curl_http(struct connectdata *conn)
  }

  if(data->cookies) {
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
    co = Curl_cookie_getlist(data->cookies,
                             conn->allocptr.cookiehost?
                             conn->allocptr.cookiehost:host, ppath,
                             (bool)(conn->protocol&PROT_HTTPS?TRUE:FALSE));
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
  }

  if (conn->bits.httpproxy &&
+15 −1
Original line number Diff line number Diff line
@@ -76,6 +76,9 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
        break;

      case CURL_LOCK_DATA_COOKIE:
        if (!share->cookies) {
          share->cookies = Curl_cookie_init( NULL, NULL, TRUE );
        }
        break;

      case CURL_LOCK_DATA_SSL_SESSION:
@@ -103,6 +106,10 @@ curl_share_setopt(CURLSH *sh, CURLSHoption option, ...)
        break;

      case CURL_LOCK_DATA_COOKIE:
        if (share->cookies) {
          Curl_cookie_cleanup(share->cookies);
          share->cookies = NULL;
        }
        break;

      case CURL_LOCK_DATA_SSL_SESSION:
@@ -144,6 +151,12 @@ CURLSHcode curl_share_cleanup(CURLSH *sh)
  if (share->dirty)
    return CURLSHE_IN_USE;

  if(share->hostcache)
    Curl_hash_destroy(share->hostcache);

  if(share->cookies)
    Curl_cookie_cleanup(share->cookies);

  free (share);
  
  return CURLSHE_OK;
@@ -151,7 +164,8 @@ CURLSHcode curl_share_cleanup(CURLSH *sh)


CURLSHcode
Curl_share_lock(struct SessionHandle *data, curl_lock_data type, curl_lock_access access)
Curl_share_lock(struct SessionHandle *data, curl_lock_data type,
                curl_lock_access access)
{
  struct Curl_share *share = data->share;

+2 −0
Original line number Diff line number Diff line
@@ -26,6 +26,7 @@

#include "setup.h"
#include <curl/curl.h>
#include "cookie.h"

/* this struct is libcurl-private, don't export details */
struct Curl_share {
@@ -37,6 +38,7 @@ struct Curl_share {
  void *clientdata;

  curl_hash *hostcache;
  struct CookieInfo *cookies;
};

CURLSHcode Curl_share_lock (
+4 −0
Original line number Diff line number Diff line
@@ -707,12 +707,14 @@ CURLcode Curl_readwrite(struct connectdata *conn,
            }
            else if(data->cookies &&
                    checkprefix("Set-Cookie:", k->p)) {
              Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
              Curl_cookie_add(data->cookies, TRUE, k->p+11,
                              /* If there is a custom-set Host: name, use it
                                 here, or else use real peer host name. */
                              conn->allocptr.cookiehost?
                              conn->allocptr.cookiehost:conn->name,
                              conn->ppath);
              Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
            }
            else if(checkprefix("Last-Modified:", k->p) &&
                    (data->set.timecondition || data->set.get_filetime) ) {
@@ -1509,12 +1511,14 @@ CURLcode Curl_pretransfer(struct SessionHandle *data)
     do it now! */
  if(data->change.cookielist) {
    struct curl_slist *list = data->change.cookielist;
    Curl_share_lock(data, CURL_LOCK_DATA_COOKIE, CURL_LOCK_ACCESS_SINGLE);
    while(list) {
      data->cookies = Curl_cookie_init(list->data,
                                       data->cookies,
                                       data->set.cookiesession);
      list = list->next;
    }
    Curl_share_unlock(data, CURL_LOCK_DATA_COOKIE);
    curl_slist_free_all(data->change.cookielist); /* clean up list */
    data->change.cookielist = NULL; /* don't do this again! */
  }
Loading