abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* Licensed to the Apache Software Foundation (ASF) under one or more
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * contributor license agreements. See the NOTICE file distributed with
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * this work for additional information regarding copyright ownership.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * The ASF licenses this file to You under the Apache License, Version 2.0
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * (the "License"); you may not use this file except in compliance with
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * the License. You may obtain a copy of the License at
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Unless required by applicable law or agreed to in writing, software
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * distributed under the License is distributed on an "AS IS" BASIS,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * See the License for the specific language governing permissions and
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * limitations under the License.
7184de27ec1d62a83c41cdeac0953ca9fd661e8csf/* we know core's module_index is 0 */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Write an RFC2109 compliant cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param r The request
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param name The name of the cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param val The value to place in the cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param attrs The string containing additional cookie attributes. If NULL, the
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * DEFAULT_ATTRS will be used.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param maxage If non zero, a Max-Age header will be added to the cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(apr_status_t) ap_cookie_write(request_rec * r, const char *name, const char *val,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* handle expiry */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin buffer = apr_pstrcat(r->pool, "Max-Age=", apr_ltoa(r->pool, maxage), ";", NULL);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* create RFC2109 compliant cookie */
ab364c14d11072380abeab42015e19c3db3336c1sf rfc2109 = apr_pstrcat(r->pool, name, "=", val, ";", buffer,
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00007) LOG_PREFIX
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin /* write the cookie to the header table(s) provided */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Write an RFC2965 compliant cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param r The request
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param name2 The name of the cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param val The value to place in the cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param attrs2 The string containing additional cookie attributes. If NULL, the
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * DEFAULT_ATTRS will be used.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param maxage If non zero, a Max-Age header will be added to the cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(apr_status_t) ap_cookie_write2(request_rec * r, const char *name2, const char *val,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* handle expiry */
562e9ce367eaaf4d3ea0ed4eaf3dbf0a644cf4aajorton buffer = apr_pstrcat(r->pool, "Max-Age=", apr_ltoa(r->pool, maxage), ";", NULL);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* create RFC2965 compliant cookie */
ab364c14d11072380abeab42015e19c3db3336c1sf rfc2965 = apr_pstrcat(r->pool, name2, "=", val, ";", buffer,
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00008) LOG_PREFIX
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin /* write the cookie to the header table(s) provided */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Remove an RFC2109 compliant cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param r The request
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param name The name of the cookie.
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinAP_DECLARE(apr_status_t) ap_cookie_remove(request_rec * r, const char *name, const char *attrs, ...)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* create RFC2109 compliant cookie */
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi const char *rfc2109 = apr_pstrcat(r->pool, name, "=;Max-Age=0;",
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00009) LOG_PREFIX
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin "user '%s' removed cookie: '%s'", r->user, rfc2109);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin /* write the cookie to the header table(s) provided */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Remove an RFC2965 compliant cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param r The request
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * @param name2 The name of the cookie.
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrinAP_DECLARE(apr_status_t) ap_cookie_remove2(request_rec * r, const char *name2, const char *attrs2, ...)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* create RFC2965 compliant cookie */
963f8b44ac95132458ea3b6aaa8ebc135188e473takashi const char *rfc2965 = apr_pstrcat(r->pool, name2, "=;Max-Age=0;",
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_DEBUG, 0, r, APLOGNO(00010) LOG_PREFIX
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin "user '%s' removed cookie2: '%s'", r->user, rfc2965);
41abbbf0cbaef202fe1ba2dd671ea48990d6e012minfrin /* write the cookie to the header table(s) provided */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin/* Iterate through the cookies, isolate our cookie and then remove it.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * If our cookie appears two or more times, but with different values,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * remove it twice and set the duplicated flag to true. Remove any
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * $path or other attributes following our cookie if present. If we end
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * up with an empty cookie, remove the whole header.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinstatic int extract_cookie_line(ap_cookie_do * v, const char *key, const char *val)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin const char *name = apr_pstrcat(v->r->pool, v->name ? v->name : "", "=", NULL);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* find the cookie called name */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin new_cookie = apr_pstrcat(v->r->pool, new_cookie, sep, next2, NULL);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* any cookies left over? */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Read a cookie called name, placing its value in val.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Both the Cookie and Cookie2 headers are scanned for the cookie.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * If the cookie is duplicated, this function returns APR_EGENERAL. If found,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * and if remove is non zero, the cookie will be removed from the headers, and
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * thus kept private from the backend.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(apr_status_t) ap_cookie_read(request_rec * r, const char *name, const char **val,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin apr_table_do((int (*) (void *, const char *, const char *))
185aa71728867671e105178b4c66fbc22b65ae26sf ap_log_rerror(APLOG_MARK, APLOG_ERR, 0, r, APLOGNO(00011) LOG_PREFIX
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin "client submitted cookie '%s' more than once: %s", v.name, r->uri);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin /* remove our cookie(s), and replace them */
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin r->headers_in = apr_table_overlay(r->pool, r->headers_in, v.new_cookies);
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * Sanity check a given string that it exists, is not empty,
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * and does not contain the special characters '=', ';' and '&'.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin * It is used to sanity check the cookie names.
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrinAP_DECLARE(apr_status_t) ap_cookie_check_string(const char *string)
abe0d0e38b9705f21a13ac8748bce1e3ed35e488minfrin if (!string || !*string || ap_strchr_c(string, '=') || ap_strchr_c(string, '&') ||