Back to index

avfs  1.0.1
Functions | Variables
http_cookies.c File Reference
#include "config.h"
#include <time.h>
#include "http_request.h"
#include "string_utils.h"
#include "http_cookies.h"
#include "ne_alloc.h"

Go to the source code of this file.

Functions

static void set_cookie_hdl (void *userdata, const char *value)
static void * create (void *session, http_req *req, const char *method, const char *uri)
static void pre_send (void *private, sbuffer request)
static void destroy (void *private)

Variables

http_request_hooks http_cookie_hooks

Function Documentation

static void* create ( void *  session,
http_req *  req,
const char *  method,
const char *  uri 
) [static]

Definition at line 99 of file http_cookies.c.

{
    http_cookie_cache *cache = session;
    http_add_response_header_handler(req, "Set-Cookie", set_cookie_hdl, cache);
    return cache;
}

Here is the call graph for this function:

static void destroy ( void *  private) [static]

Definition at line 129 of file http_cookies.c.

{
    /* FIXME */
    return;
}
static void pre_send ( void *  private,
sbuffer  request 
) [static]

Definition at line 107 of file http_cookies.c.

{
    http_cookie_cache *cache = private;
    http_cookie *cook;
    
    if (cache->cookies == NULL) {
       return;
    }
    
    sbuffer_zappend(request, "Cookie: ");

    for (cook = cache->cookies; cook != NULL; cook=cook->next) {
       sbuffer_concat(request, cook->name, "=", cook->value, NULL);
       if (cook->next != NULL) {
           sbuffer_zappend(request, "; ");
       }
    }
    
    sbuffer_zappend(request, EOL);
    
}
static void set_cookie_hdl ( void *  userdata,
const char *  value 
) [static]

Definition at line 43 of file http_cookies.c.

{
    char **pairs = pair_string(value, ';', '=', HTTP_QUOTES, HTTP_WHITESPACE);
    http_cookie *cook;
    http_cookie_cache *cache = userdata;
    int n;

    /* Check sanity */
    if (pairs[0] == NULL || pairs[1] == NULL) {
       /* yagaboo */
       return;
    }

    DEBUG(DEBUG_HTTP, "Got cookie name=%s\n", pairs[0]);

    /* Search for a cookie of this name */
    DEBUG(DEBUG_HTTP, "Searching for existing cookie...\n");
    for (cook = cache->cookies; cook != NULL; cook = cook->next) {
       if (strcasecmp(cook->name, pairs[0]) == 0) {
           break;
       }
    }
    
    if (cook == NULL) {
       DEBUG(DEBUG_HTTP, "New cookie.\n");
       cook = ne_malloc(sizeof(http_cookie));
       memset(cook, 0, sizeof(http_cookie));
       cook->name = pairs[0];
       cook->next = cache->cookies;
       cache->cookies = cook;
    } else {
       /* Free the old value */
       free(cook->value);
    }

    cook->value = pairs[1];

    for (n = 2; pairs[n] != NULL; n+=2) {
       DEBUG(DEBUG_HTTP, "Cookie parm %s=%s\n", pairs[n], pairs[n+1]);
       if (strcasecmp(pairs[n], "path") == 0) {
           cook->path = pairs[n+1];
           pairs[n+1] = NULL;
       } else if (strcasecmp(pairs[n], "max-age") == 0) {
           int t = atoi(pairs[n+1]);
           cook->expiry = time(NULL) + (time_t)t;
       } else if (strcasecmp(pairs[n], "domain") == 0) {
           cook->domain = pairs[n+1];
           pairs[n+1] = NULL;
       }
    }

    DEBUG(DEBUG_HTTP, "End of parms.\n");

    pair_string_free(pairs);
}

Here is the caller graph for this function:


Variable Documentation

Initial value:
 {
    "http://www.webdav.org/neon/hooks/cookies",
    create,
    NULL,
    pre_send,
    NULL,
    destroy
}

Definition at line 135 of file http_cookies.c.