|
Packit |
90a5c9 |
/* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
Packit |
90a5c9 |
* contributor license agreements. See the NOTICE file distributed with
|
|
Packit |
90a5c9 |
* this work for additional information regarding copyright ownership.
|
|
Packit |
90a5c9 |
* The ASF licenses this file to You under the Apache License, Version 2.0
|
|
Packit |
90a5c9 |
* (the "License"); you may not use this file except in compliance with
|
|
Packit |
90a5c9 |
* the License. You may obtain a copy of the License at
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Unless required by applicable law or agreed to in writing, software
|
|
Packit |
90a5c9 |
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
Packit |
90a5c9 |
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
Packit |
90a5c9 |
* See the License for the specific language governing permissions and
|
|
Packit |
90a5c9 |
* limitations under the License.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* @file util_cookies.h
|
|
Packit |
90a5c9 |
* @brief Apache cookie library
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifndef UTIL_COOKIES_H
|
|
Packit |
90a5c9 |
#define UTIL_COOKIES_H
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef __cplusplus
|
|
Packit |
90a5c9 |
extern "C" {
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* @defgroup APACHE_CORE_COOKIE Cookies
|
|
Packit |
90a5c9 |
* @ingroup APACHE_CORE
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* RFC2109 and RFC2965 compliant HTTP cookies can be read from and written
|
|
Packit |
90a5c9 |
* to using this set of functions.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @{
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#include "apr_errno.h"
|
|
Packit |
90a5c9 |
#include "httpd.h"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#define SET_COOKIE "Set-Cookie"
|
|
Packit |
90a5c9 |
#define SET_COOKIE2 "Set-Cookie2"
|
|
Packit |
90a5c9 |
#define DEFAULT_ATTRS "HttpOnly;Secure;Version=1"
|
|
Packit |
90a5c9 |
#define CLEAR_ATTRS "Version=1"
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
typedef struct {
|
|
Packit |
90a5c9 |
request_rec *r;
|
|
Packit |
90a5c9 |
const char *name;
|
|
Packit |
90a5c9 |
const char *encoded;
|
|
Packit |
90a5c9 |
apr_table_t *new_cookies;
|
|
Packit |
90a5c9 |
int duplicated;
|
|
Packit |
90a5c9 |
} ap_cookie_do;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Write an RFC2109 compliant cookie.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @param r The request
|
|
Packit |
90a5c9 |
* @param name The name of the cookie.
|
|
Packit |
90a5c9 |
* @param val The value to place in the cookie.
|
|
Packit |
90a5c9 |
* @param attrs The string containing additional cookie attributes. If NULL, the
|
|
Packit |
90a5c9 |
* DEFAULT_ATTRS will be used.
|
|
Packit |
90a5c9 |
* @param maxage If non zero, a Max-Age header will be added to the cookie.
|
|
Packit |
90a5c9 |
* @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL
|
|
Packit |
90a5c9 |
* to which the cookies should be added.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
AP_DECLARE(apr_status_t) ap_cookie_write(request_rec * r, const char *name,
|
|
Packit |
90a5c9 |
const char *val, const char *attrs,
|
|
Packit |
90a5c9 |
long maxage, ...)
|
|
Packit |
90a5c9 |
AP_FN_ATTR_SENTINEL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Write an RFC2965 compliant cookie.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @param r The request
|
|
Packit |
90a5c9 |
* @param name2 The name of the cookie.
|
|
Packit |
90a5c9 |
* @param val The value to place in the cookie.
|
|
Packit |
90a5c9 |
* @param attrs2 The string containing additional cookie attributes. If NULL, the
|
|
Packit |
90a5c9 |
* DEFAULT_ATTRS will be used.
|
|
Packit |
90a5c9 |
* @param maxage If non zero, a Max-Age header will be added to the cookie.
|
|
Packit |
90a5c9 |
* @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL
|
|
Packit |
90a5c9 |
* to which the cookies should be added.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
AP_DECLARE(apr_status_t) ap_cookie_write2(request_rec * r, const char *name2,
|
|
Packit |
90a5c9 |
const char *val, const char *attrs2,
|
|
Packit |
90a5c9 |
long maxage, ...)
|
|
Packit |
90a5c9 |
AP_FN_ATTR_SENTINEL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Remove an RFC2109 compliant cookie.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @param r The request
|
|
Packit |
90a5c9 |
* @param name The name of the cookie.
|
|
Packit |
90a5c9 |
* @param attrs The string containing additional cookie attributes. If NULL, the
|
|
Packit |
90a5c9 |
* CLEAR_ATTRS will be used.
|
|
Packit |
90a5c9 |
* @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL
|
|
Packit |
90a5c9 |
* to which the cookies should be added.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
AP_DECLARE(apr_status_t) ap_cookie_remove(request_rec * r, const char *name,
|
|
Packit |
90a5c9 |
const char *attrs, ...)
|
|
Packit |
90a5c9 |
AP_FN_ATTR_SENTINEL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Remove an RFC2965 compliant cookie.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* @param r The request
|
|
Packit |
90a5c9 |
* @param name2 The name of the cookie.
|
|
Packit |
90a5c9 |
* @param attrs2 The string containing additional cookie attributes. If NULL, the
|
|
Packit |
90a5c9 |
* CLEAR_ATTRS will be used.
|
|
Packit |
90a5c9 |
* @param ... A varargs array of zero or more (apr_table_t *) tables followed by NULL
|
|
Packit |
90a5c9 |
* to which the cookies should be added.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
AP_DECLARE(apr_status_t) ap_cookie_remove2(request_rec * r, const char *name2,
|
|
Packit |
90a5c9 |
const char *attrs2, ...)
|
|
Packit |
90a5c9 |
AP_FN_ATTR_SENTINEL;
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Read a cookie called name, placing its value in val.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* Both the Cookie and Cookie2 headers are scanned for the cookie.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* If the cookie is duplicated, this function returns APR_EGENERAL. If found,
|
|
Packit |
90a5c9 |
* and if remove is non zero, the cookie will be removed from the headers, and
|
|
Packit |
90a5c9 |
* thus kept private from the backend.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
AP_DECLARE(apr_status_t) ap_cookie_read(request_rec * r, const char *name, const char **val,
|
|
Packit |
90a5c9 |
int remove);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* Sanity check a given string that it exists, is not empty,
|
|
Packit |
90a5c9 |
* and does not contain the special characters '=', ';' and '&'.
|
|
Packit |
90a5c9 |
*
|
|
Packit |
90a5c9 |
* It is used to sanity check the cookie names.
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
AP_DECLARE(apr_status_t) ap_cookie_check_string(const char *string);
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
/**
|
|
Packit |
90a5c9 |
* @}
|
|
Packit |
90a5c9 |
*/
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#ifdef __cplusplus
|
|
Packit |
90a5c9 |
}
|
|
Packit |
90a5c9 |
#endif
|
|
Packit |
90a5c9 |
|
|
Packit |
90a5c9 |
#endif /* !UTIL_COOKIES_H */
|