1 #ifndef __COOKIE_H
2 #define __COOKIE_H
3 /***************************************************************************
4  *                                  _   _ ____  _
5  *  Project                     ___| | | |  _ \| |
6  *                             / __| | | | |_) | |
7  *                            | (__| |_| |  _ <| |___
8  *                             \___|\___/|_| \_\_____|
9  *
10  * Copyright (C) 1998 - 2008, Daniel Stenberg, <daniel@haxx.se>, et al.
11  *
12  * This software is licensed as described in the file COPYING, which
13  * you should have received as part of this distribution. The terms
14  * are also available at http://curl.haxx.se/docs/copyright.html.
15  *
16  * You may opt to use, copy, modify, merge, publish, distribute and/or sell
17  * copies of the Software, and permit persons to whom the Software is
18  * furnished to do so, under the terms of the COPYING file.
19  *
20  * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
21  * KIND, either express or implied.
22  *
23  * $Id: cookie.h,v 1.28 2009-02-27 08:53:10 bagder Exp $
24  ***************************************************************************/
25 
26 #include <stdio.h>
27 #if defined(WIN32)
28 #include <time.h>
29 #else
30 #ifdef HAVE_SYS_TIME_H
31 #include <sys/time.h>
32 #endif
33 #endif
34 
35 #include <curl/curl.h>
36 
37 struct Cookie {
38   struct Cookie *next; /* next in the chain */
39   char *name;        /* <this> = value */
40   char *value;       /* name = <this> */
41   char *path;         /* path = <this> */
42   char *domain;      /* domain = <this> */
43   curl_off_t expires;  /* expires = <this> */
44   char *expirestr;   /* the plain text version */
45   bool tailmatch;    /* weather we do tail-matchning of the domain name */
46 
47   /* RFC 2109 keywords. Version=1 means 2109-compliant cookie sending */
48   char *version;     /* Version = <value> */
49   char *maxage;      /* Max-Age = <value> */
50 
51   bool secure;       /* whether the 'secure' keyword was used */
52   bool livecookie;   /* updated from a server, not a stored file */
53   bool httponly;     /* true if the httponly directive is present */
54 };
55 
56 struct CookieInfo {
57   /* linked list of cookies we know of */
58   struct Cookie *cookies;
59 
60   char *filename;  /* file we read from/write to */
61   bool running;    /* state info, for cookie adding information */
62   long numcookies; /* number of cookies in the "jar" */
63   bool newsession; /* new session, discard session cookies on load */
64 };
65 
66 /* This is the maximum line length we accept for a cookie line. RFC 2109
67    section 6.3 says:
68 
69    "at least 4096 bytes per cookie (as measured by the size of the characters
70    that comprise the cookie non-terminal in the syntax description of the
71    Set-Cookie header)"
72 
73 */
74 #define MAX_COOKIE_LINE 5000
75 #define MAX_COOKIE_LINE_TXT "4999"
76 
77 /* This is the maximum length of a cookie name we deal with: */
78 #define MAX_NAME 1024
79 #define MAX_NAME_TXT "1023"
80 
81 struct SessionHandle;
82 /*
83  * Add a cookie to the internal list of cookies. The domain and path arguments
84  * are only used if the header boolean is TRUE.
85  */
86 
87 struct Cookie *Curl_cookie_add(struct SessionHandle *data,
88                                struct CookieInfo *, bool header, char *lineptr,
89                                const char *domain, const char *path);
90 
91 struct CookieInfo *Curl_cookie_init(struct SessionHandle *data,
92                                     const char *, struct CookieInfo *, bool);
93 struct Cookie *Curl_cookie_getlist(struct CookieInfo *, const char *,
94                                    const char *, bool);
95 void Curl_cookie_freelist(struct Cookie *cookies, bool cookiestoo);
96 void Curl_cookie_clearall(struct CookieInfo *cookies);
97 void Curl_cookie_clearsess(struct CookieInfo *cookies);
98 void Curl_cookie_cleanup(struct CookieInfo *);
99 int Curl_cookie_output(struct CookieInfo *, const char *);
100 
101 #if defined(CURL_DISABLE_HTTP) || defined(CURL_DISABLE_COOKIES)
102 #define Curl_cookie_list(x) NULL
103 #define Curl_cookie_loadfiles(x) do { } while (0)
104 #else
105 struct curl_slist *Curl_cookie_list(struct SessionHandle *data);
106 void Curl_cookie_loadfiles(struct SessionHandle *data);
107 #endif
108 
109 #endif
110