Apache HTTP Server Request Library

apreq_cookie.h
Go to the documentation of this file.
1 /*
2 ** Licensed to the Apache Software Foundation (ASF) under one or more
3 ** contributor license agreements. See the NOTICE file distributed with
4 ** this work for additional information regarding copyright ownership.
5 ** The ASF licenses this file to You under the Apache License, Version 2.0
6 ** (the "License"); you may not use this file except in compliance with
7 ** the License. You may obtain a copy of the License at
8 **
9 ** http://www.apache.org/licenses/LICENSE-2.0
10 **
11 ** Unless required by applicable law or agreed to in writing, software
12 ** distributed under the License is distributed on an "AS IS" BASIS,
13 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 ** See the License for the specific language governing permissions and
15 ** limitations under the License.
16 */
17
18 #ifndef APREQ_COOKIE_H
19 #define APREQ_COOKIE_H
20
21 #include "apreq.h"
22 #include "apr_time.h"
23
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27
48 #define APREQ_COOKIE_MAX_LENGTH 4096
49
53 typedef struct apreq_cookie_t {
54
55 char *path;
56 char *domain;
57 char *port;
58 char *comment;
59 char *commentURL;
60 apr_time_t max_age;
61 unsigned flags;
62 const apreq_value_t v;
64 } apreq_cookie_t;
65
66
68 static APR_INLINE
69 apreq_cookie_t *apreq_value_to_cookie(const char *val)
70 {
71 union { const char *in; char *out; } deconst;
72
73 deconst.in = val;
74 return apreq_attr_to_type(apreq_cookie_t, v,
75 apreq_attr_to_type(apreq_value_t, data, deconst.out));
76 }
77
79 static APR_INLINE
80 unsigned apreq_cookie_version(const apreq_cookie_t *c) {
81 return APREQ_FLAGS_GET(c->flags, APREQ_COOKIE_VERSION);
82 }
83
85 static APR_INLINE
86 void apreq_cookie_version_set(apreq_cookie_t *c, unsigned v) {
87 APREQ_FLAGS_SET(c->flags, APREQ_COOKIE_VERSION, v);
88 }
89
91 static APR_INLINE
92 unsigned apreq_cookie_is_secure(const apreq_cookie_t *c) {
93 return APREQ_FLAGS_GET(c->flags, APREQ_COOKIE_SECURE);
94 }
95
99 static APR_INLINE
100 void apreq_cookie_secure_on(apreq_cookie_t *c) {
101 APREQ_FLAGS_ON(c->flags, APREQ_COOKIE_SECURE);
102 }
103
105 static APR_INLINE
106 void apreq_cookie_secure_off(apreq_cookie_t *c) {
107 APREQ_FLAGS_OFF(c->flags, APREQ_COOKIE_SECURE);
108 }
109
111 static APR_INLINE
112 unsigned apreq_cookie_is_httponly(const apreq_cookie_t *c) {
113 return APREQ_FLAGS_GET(c->flags, APREQ_COOKIE_HTTPONLY);
114 }
115
120 static APR_INLINE
121 void apreq_cookie_httponly_on(apreq_cookie_t *c) {
122 APREQ_FLAGS_ON(c->flags, APREQ_COOKIE_HTTPONLY);
123 }
124
126 static APR_INLINE
127 void apreq_cookie_httponly_off(apreq_cookie_t *c) {
128 APREQ_FLAGS_OFF(c->flags, APREQ_COOKIE_HTTPONLY);
129 }
130
131
133 static APR_INLINE
134 unsigned apreq_cookie_is_tainted(const apreq_cookie_t *c) {
135 return APREQ_FLAGS_GET(c->flags, APREQ_TAINTED);
136 }
137
139 static APR_INLINE
140 void apreq_cookie_tainted_on(apreq_cookie_t *c) {
141 APREQ_FLAGS_ON(c->flags, APREQ_TAINTED);
142 }
143
145 static APR_INLINE
146 void apreq_cookie_tainted_off(apreq_cookie_t *c) {
147 APREQ_FLAGS_OFF(c->flags, APREQ_TAINTED);
148 }
149
165 APREQ_DECLARE(apr_status_t) apreq_parse_cookie_header(apr_pool_t *pool,
166 apr_table_t *jar,
167 const char *header);
168
180 APREQ_DECLARE(apreq_cookie_t *) apreq_cookie_make(apr_pool_t *pool,
181 const char *name,
182 const apr_size_t nlen,
183 const char *value,
184 const apr_size_t vlen);
185
195 APREQ_DECLARE(char*) apreq_cookie_as_string(const apreq_cookie_t *c,
196 apr_pool_t *p);
197
198
211 APREQ_DECLARE(int) apreq_cookie_serialize(const apreq_cookie_t *c,
212 char *buf, apr_size_t len);
213
228 APREQ_DECLARE(void) apreq_cookie_expires(apreq_cookie_t *c,
229 const char *time_str);
230
231 #ifdef __cplusplus
232 }
233 #endif
234
235 #endif /*APREQ_COOKIE_H*/
236
237
apreq.h
Main header file...
APREQ_DECLARE
#define APREQ_DECLARE(d)
Definition: apreq.h:50
APREQ_FLAGS_GET
#define APREQ_FLAGS_GET(f, name)
Definition: apreq.h:126
APREQ_FLAGS_OFF
#define APREQ_FLAGS_OFF(f, name)
Definition: apreq.h:118
apreq_attr_to_type
#define apreq_attr_to_type(T, A, P)
Definition: apreq.h:265
APREQ_FLAGS_SET
#define APREQ_FLAGS_SET(f, name, value)
Definition: apreq.h:133
APREQ_FLAGS_ON
#define APREQ_FLAGS_ON(f, name)
Definition: apreq.h:122
apreq_cookie_version
static APR_INLINE unsigned apreq_cookie_version(const apreq_cookie_t *c)
Definition: apreq_cookie.h:80
apreq_cookie_is_tainted
static APR_INLINE unsigned apreq_cookie_is_tainted(const apreq_cookie_t *c)
Definition: apreq_cookie.h:134
apreq_cookie_as_string
char * apreq_cookie_as_string(const apreq_cookie_t *c, apr_pool_t *p)
apreq_parse_cookie_header
apr_status_t apreq_parse_cookie_header(apr_pool_t *pool, apr_table_t *jar, const char *header)
apreq_cookie_secure_on
static APR_INLINE void apreq_cookie_secure_on(apreq_cookie_t *c)
Definition: apreq_cookie.h:100
apreq_cookie_t
struct apreq_cookie_t apreq_cookie_t
Cookie type, supporting both Netscape and RFC cookie specifications.
apreq_cookie_make
apreq_cookie_t * apreq_cookie_make(apr_pool_t *pool, const char *name, const apr_size_t nlen, const char *value, const apr_size_t vlen)
apreq_cookie_httponly_off
static APR_INLINE void apreq_cookie_httponly_off(apreq_cookie_t *c)
Definition: apreq_cookie.h:127
apreq_cookie_is_httponly
static APR_INLINE unsigned apreq_cookie_is_httponly(const apreq_cookie_t *c)
Definition: apreq_cookie.h:112
apreq_cookie_is_secure
static APR_INLINE unsigned apreq_cookie_is_secure(const apreq_cookie_t *c)
Definition: apreq_cookie.h:92
apreq_cookie_expires
void apreq_cookie_expires(apreq_cookie_t *c, const char *time_str)
apreq_cookie_httponly_on
static APR_INLINE void apreq_cookie_httponly_on(apreq_cookie_t *c)
Definition: apreq_cookie.h:121
apreq_value_to_cookie
static APR_INLINE apreq_cookie_t * apreq_value_to_cookie(const char *val)
Definition: apreq_cookie.h:69
apreq_cookie_tainted_off
static APR_INLINE void apreq_cookie_tainted_off(apreq_cookie_t *c)
Definition: apreq_cookie.h:146
apreq_cookie_secure_off
static APR_INLINE void apreq_cookie_secure_off(apreq_cookie_t *c)
Definition: apreq_cookie.h:106
apreq_cookie_version_set
static APR_INLINE void apreq_cookie_version_set(apreq_cookie_t *c, unsigned v)
Definition: apreq_cookie.h:86
apreq_cookie_serialize
int apreq_cookie_serialize(const apreq_cookie_t *c, char *buf, apr_size_t len)
apreq_cookie_tainted_on
static APR_INLINE void apreq_cookie_tainted_on(apreq_cookie_t *c)
Definition: apreq_cookie.h:140
apreq_cookie_t
Cookie type, supporting both Netscape and RFC cookie specifications.
Definition: apreq_cookie.h:53
apreq_cookie_t::commentURL
char * commentURL
Definition: apreq_cookie.h:59
apreq_cookie_t::port
char * port
Definition: apreq_cookie.h:57
apreq_cookie_t::v
const apreq_value_t v
Definition: apreq_cookie.h:62
apreq_cookie_t::path
char * path
Definition: apreq_cookie.h:55
apreq_cookie_t::flags
unsigned flags
Definition: apreq_cookie.h:61
apreq_cookie_t::domain
char * domain
Definition: apreq_cookie.h:56
apreq_cookie_t::max_age
apr_time_t max_age
Definition: apreq_cookie.h:60
apreq_cookie_t::comment
char * comment
Definition: apreq_cookie.h:58
apreq_value_t
libapreq's pre-extensible string type
Definition: apreq.h:235