1 /* Licensed to the Apache Software Foundation (ASF) under one or more
2 * contributor license agreements. See the NOTICE file distributed with
3 * this work for additional information regarding copyright ownership.
4 * The ASF licenses this file to You under the Apache License, Version 2.0
5 * (the "License"); you may not use this file except in compliance with
6 * the License. You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
18 * @file util_cookies.h
19 * @brief Apache cookie library
22 #ifndef UTIL_COOKIES_H
23 #define UTIL_COOKIES_H
30 * @defgroup APACHE_CORE_COOKIE Cookies
31 * @ingroup APACHE_CORE
33 * RFC2109 and RFC2965 compliant HTTP cookies can be read from and written
34 * to using this set of functions.
38 #include "apr_errno.h"
41 #define SET_COOKIE "Set-Cookie"
42 #define SET_COOKIE2 "Set-Cookie2"
43 #define DEFAULT_ATTRS "HttpOnly;Secure;Version=1"
44 #define CLEAR_ATTRS "Max-Age=0;Version=1"
50 apr_table_t *new_cookies;
55 * Write an RFC2109 compliant cookie.
57 * @param r The request
58 * @param name The name of the cookie.
59 * @param val The value to place in the cookie.
60 * @param attrs The string containing additional cookie attributes. If NULL, the
61 * DEFAULT_ATTRS will be used.
62 * @param maxage If non zero, a Max-Age header will be added to the cookie.
64 AP_DECLARE(apr_status_t) ap_cookie_write(request_rec * r, const char *name, const char *val,
65 const char *attrs, long maxage);
68 * Write an RFC2965 compliant cookie.
70 * @param r The request
71 * @param name2 The name of the cookie.
72 * @param val The value to place in the cookie.
73 * @param attrs2 The string containing additional cookie attributes. If NULL, the
74 * DEFAULT_ATTRS will be used.
75 * @param maxage If non zero, a Max-Age header will be added to the cookie.
77 AP_DECLARE(apr_status_t) ap_cookie_write2(request_rec * r, const char *name2, const char *val,
78 const char *attrs2, long maxage);
81 * Remove an RFC2109 compliant cookie.
83 * @param r The request
84 * @param name The name of the cookie.
86 AP_DECLARE(apr_status_t) ap_cookie_remove(request_rec * r, const char *name);
89 * Remove an RFC2965 compliant cookie.
91 * @param r The request
92 * @param name2 The name of the cookie.
94 AP_DECLARE(apr_status_t) ap_cookie_remove2(request_rec * r, const char *name2);
97 * Read a cookie called name, placing its value in val.
99 * Both the Cookie and Cookie2 headers are scanned for the cookie.
101 * If the cookie is duplicated, this function returns APR_EGENERAL. If found,
102 * and if remove is non zero, the cookie will be removed from the headers, and
103 * thus kept private from the backend.
105 AP_DECLARE(apr_status_t) ap_cookie_read(request_rec * r, const char *name, const char **val,
109 * Sanity check a given string that it exists, is not empty,
110 * and does not contain the special characters '=', ';' and '&'.
112 * It is used to sanity check the cookie names.
114 AP_DECLARE(apr_status_t) ap_cookie_check_string(const char *string);
120 #endif /* !UTIL_COOKIES_H */