1 /*
2 
3   					W3C Sample Code Library libwww Simple Cookie Handler
4 
5 
6 !
7   Simple Cookie Handler
8 !
9 */
10 
11 /*
12 **	(c) COPYRIGHT MIT 1999.
13 **	Please first read the full copyright statement in the file COPYRIGH.
14 */
15 
16 /*
17 
18 This module provides a simple
19 HTTP Cookie
20 handling mechanism. It really also is an excersize in showing how libwww
21 can be extended with something like cookies in a modular manner. An important
22 thing to note about this implementation is that it does not provide
23 storage for cookies - this is left to the application as normally cookies
24 have to be kept under lock.
25 
26 This module is implemented by HTCookie.c, and it
27 is a part of the  W3C Sample Code
28 Library.
29 */
30 
31 #ifndef HTCOOKIE_H
32 #define HTCOOKIE_H
33 #include "WWWLib.h"
34 
35 #ifdef __cplusplus
36 extern "C" {
37 #endif
38 
39 /*
40 .
41   Initiate and Terminate Cookie Handling
42 .
43 
44 In order to start handling cookies, you need to initiate the module. Likewise,
45 when you are done, you must terminate the module in order to clean up memory
46 etc. Note that this cookie handler doesn't provide storage room for cookies
47 - the application MUST do that by registering cookie
48 callbacks. Initiation does three things:
49 
50   o
51 	     Register a MIME header parser to parse the Set-Cookie
52     header field
53   o
54 	     Register a BEFORE filter to see if a cookie should
55     be added to the request (uses the "set" callback)
56   o
57 	     Register an AFTER filter to handle new cookies (uses
58     the "find" callback)
59 
60 */
61 
62 extern BOOL HTCookie_init (void);
63 extern BOOL HTCookie_terminate (void);
64 
65 /*
66 .
67   The Cookie Class
68 .
69 
70 The cookie class is used to handle cookies in libwww and to hand them off
71 to the application. The creation and deletion of cookie object is handled
72 by this cookie module - the application is handed a cookie and can access
73 the elements using the following methods:
74 */
75 
76 typedef struct _HTCookie HTCookie;
77 
78 /*
79 (
80   Cookie Name
81 )
82 */
83 
84 extern BOOL HTCookie_setName (HTCookie * me, const char * name);
85 extern char * HTCookie_name (HTCookie * me);
86 
87 /*
88 (
89   Cookie Value
90 )
91 */
92 
93 extern BOOL HTCookie_setValue (HTCookie * me, const char * value);
94 extern char * HTCookie_value (HTCookie * me);
95 
96 /*
97 (
98   Cookie Domain
99 )
100 */
101 
102 extern BOOL HTCookie_setDomain (HTCookie * me, const char * domain);
103 extern char * HTCookie_domain (HTCookie * me);
104 
105 /*
106 (
107   Cookie Path
108 )
109 */
110 
111 extern BOOL HTCookie_setPath (HTCookie * me, const char * path);
112 extern char * HTCookie_path (HTCookie * me);
113 
114 /*
115 (
116   Cookie Expiration
117 )
118 */
119 
120 extern time_t HTCookie_setExpiration (HTCookie * me, time_t expiration);
121 extern time_t HTCookie_expiration (HTCookie * me);
122 
123 /*
124 (
125   Is Cookie Secure?
126 )
127 */
128 
129 extern time_t HTCookie_setSecure (HTCookie * me, BOOL secure);
130 extern BOOL HTCookie_isSecure (HTCookie * me);
131 
132 /*
133 .
134   Cookie Callbacks
135 .
136 
137 The cookie callbacks are called before the request is shipped over the wire
138 to see if any cookies should be included and after the response has been
139 recieved if a new cookie is found in a response and before. Cookie callbacks
140 can be registered with a context that is sent along with the callback when
141 called.
142 */
143 
144 typedef BOOL HTCookieSetCallback (HTRequest * request, HTCookie * cookie, void * param);
145 typedef HTAssocList * HTCookieFindCallback (HTRequest * request, void * param);
146 
147 extern BOOL HTCookie_setCallbacks (HTCookieSetCallback *	setCookie,
148 				   void * 			setCookieContext,
149 				   HTCookieFindCallback *	findCookie,
150 				   void * 			findCookieContext);
151 extern BOOL HTCookie_deleteCallbacks (void);
152 
153 /*
154 .
155   Cookie Handling Mode
156 .
157 
158 The application can decide how cookies are to be handled - should they be
159 ignored, should the user be asked, etc.
160 */
161 
162 typedef enum _HTCookieMode {
163     HT_COOKIE_ACCEPT          = 0x1,  /* Accept cookies */
164     HT_COOKIE_SEND            = 0x2,  /* Send cookies when fit */
165     HT_COOKIE_SAME_HOST       = 0x4,  /* Don't accept cookies for other hosts */
166     HT_COOKIE_SAME_DOMAIN     = 0x8,  /* Don't accept cookies for other domains */
167     HT_COOKIE_PROMPT          = 0x10  /* Prompt before accepting cookies */
168 } HTCookieMode;
169 
170 extern BOOL HTCookie_setCookieMode (HTCookieMode mode);
171 extern HTCookieMode HTCookie_cookieMode (void);
172 
173 /*
174 */
175 
176 #ifdef __cplusplus
177 }
178 #endif
179 
180 #endif /* HTCOOKIE_H */
181 
182 /*
183 
184 
185 
186   @(#) $Id$
187 
188 */
189