Main Page | Alphabetical List | Data Structures | Directories | File List | Data Fields | Globals

cookies.h File Reference

This graph shows which files directly or indirectly include this file:

Included by dependency graph

Go to the source code of this file.

Data Structures

struct  _cookie

Defines

#define MAX_HTTP_DATE_LENGTH   128

Typedefs

typedef _cookie Cookie

Functions

Cookiecookie_create (void)
void cookies_destroy (List *)
int get_cookies (List *, const WSPMachine *)
int set_cookies (List *, WSPMachine *)


Define Documentation

#define MAX_HTTP_DATE_LENGTH   128
 

Definition at line 106 of file cookies.h.

Referenced by parse_http_date().


Typedef Documentation

typedef struct _cookie Cookie
 

Referenced by add_cookie_to_cache(), cookie_create(), cookie_destroy(), expire_cookies(), get_cookies(), have_cookie(), parse_cookie(), and set_cookies().


Function Documentation

Cookie* cookie_create void   ) 
 

Definition at line 88 of file cookies.c.

References Cookie.

Referenced by parse_cookie().

00089 {
00090     Cookie *p;
00091 
00092     p = gw_malloc(sizeof(Cookie));  /* Never returns NULL */
00093 
00094     *p = emptyCookie;
00095     p -> max_age = -1;
00096     time (&p -> birth);
00097     return p;
00098 }

void cookies_destroy List  ) 
 

Definition at line 100 of file cookies.c.

References cookie_destroy(), gwlib_assert_init(), and gwlist_destroy().

00101 {
00102     gwlib_assert_init();
00103 
00104     if (cookies == NULL)
00105         return;
00106 
00107     gwlist_destroy(cookies, cookie_destroy);
00108 }

Here is the call graph for this function:

int get_cookies List ,
const WSPMachine
 

Definition at line 111 of file cookies.c.

References add_cookie_to_cache(), Cookie, cookie_destroy(), debug(), error(), get_header_value(), gwlist_get(), gwlist_len(), have_cookie(), info(), name, octstr_get_cstr, parse_cookie(), and sm.

Referenced by return_reply().

00112 {
00113     Octstr *header = NULL;
00114     Octstr *value = NULL;
00115     Cookie *cookie = NULL;
00116     long pos = 0;
00117 
00118     /* 
00119      * This can happen if the user aborts while the HTTP request is pending from the server.
00120      * In that case, the session machine is destroyed and is not available to this function
00121      * for cookie caching.
00122      */
00123 
00124     if (sm == NULL) {
00125         info (0, "No session machine for cookie retrieval");
00126         return 0;
00127     }
00128 
00129     for (pos = 0; pos < gwlist_len(headers); pos++) {
00130         header = gwlist_get(headers, pos);
00131         /* debug ("wap.wsp.http", 0, "get_cookies: Examining header (%s)", octstr_get_cstr (header)); */
00132         if (strncasecmp ("set-cookie", octstr_get_cstr (header),10) == 0) {     
00133             debug ("wap.wsp.http", 0, "Caching cookie (%s)", octstr_get_cstr (header));
00134 
00135             if ((value = get_header_value (header)) == NULL) {
00136                 error (0, "get_cookies: No value in (%s)", octstr_get_cstr(header));
00137                 continue;
00138             }
00139 
00140             /* Parse the received cookie */
00141             if ((cookie = parse_cookie(value)) != NULL) {
00142 
00143                 /* Check to see if this cookie is already present */
00144                 if (have_cookie(sm->cookies, cookie) == 1) {
00145                     debug("wap.wsp.http", 0, "parse_cookie: Cookie present");
00146                           cookie_destroy(cookie);
00147                     continue;
00148                 } else {
00149                     add_cookie_to_cache(sm, cookie);
00150                     debug("wap.wsp.http", 0, "get_cookies: Added (%s)", 
00151                           octstr_get_cstr(cookie -> name));
00152                 }
00153             }
00154         }
00155     }
00156 
00157     debug("wap.wsp.http", 0, "get_cookies: End");
00158     return 0;
00159 }

Here is the call graph for this function:

int set_cookies List ,
WSPMachine
 

Definition at line 162 of file cookies.c.

References Cookie, debug(), _cookie::domain, error(), expire_cookies(), gwlist_append(), gwlist_get(), gwlist_len(), _cookie::name, octstr_append(), octstr_append_char(), octstr_create, octstr_get_cstr, _cookie::path, sm, _cookie::value, and _cookie::version.

Referenced by start_fetch().

00163 {
00164     Cookie *value = NULL;
00165     Octstr *cookie = NULL;
00166     long pos = 0;
00167 
00168     if (headers == NULL || sm == NULL) {
00169         error (0, "set_cookies: Null argument(s) - no headers, WSPMachine or both");
00170         return -1;
00171     }
00172 
00173     /* Expire cookies that have timed out */
00174     expire_cookies(sm->cookies);
00175 
00176     /* Walk through the cookie cache, adding the cookie to the request headers */
00177     if (gwlist_len(sm->cookies) > 0) {
00178         debug("wap.wsp.http", 0, "set_cookies: Cookies in cache");
00179 
00180         for (pos = 0; pos < gwlist_len(sm->cookies); pos++) {
00181             value = gwlist_get(sm->cookies, pos);
00182 
00183             cookie = octstr_create("Cookie: ");
00184             if (value->version) 
00185                 octstr_append(cookie, value->version);
00186             octstr_append(cookie, value->name);
00187             octstr_append_char(cookie, '=');
00188             octstr_append(cookie, value->value);
00189 
00190             if (value->path) {
00191                 octstr_append_char(cookie, ';');
00192                 octstr_append(cookie, value->path);
00193             }
00194             if (value->domain) {
00195                 octstr_append_char(cookie, ';');
00196                 octstr_append(cookie, value->domain);
00197             }
00198 
00199             gwlist_append(headers, cookie);
00200             debug("wap.wsp.http", 0, "set_cookies: Added (%s)", octstr_get_cstr (cookie));
00201         }
00202     } else
00203         debug("wap.wsp.http", 0, "set_cookies: No cookies in cache");
00204 
00205     return 0;
00206 }

Here is the call graph for this function:

See file LICENSE for details about the license agreement for using, modifying, copying or deriving work from this software.