CPPSERV


Home Projects Jobs Clientele Contact
CPPSERV Documentation Download TODO Mailing lists Bug tracker News RSS Feed Browse source

Cookie.h

Go to the documentation of this file.
00001 /*
00002  * ====================================================================
00003  *
00004  * The Apache Software License, Version 1.1
00005  *
00006  * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights
00007  * reserved.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  *
00013  * 1. Redistributions of source code must retain the above copyright
00014  *    notice, this list of conditions and the following disclaimer.
00015  *
00016  * 2. Redistributions in binary form must reproduce the above copyright
00017  *    notice, this list of conditions and the following disclaimer in
00018  *    the documentation and/or other materials provided with the
00019  *    distribution.
00020  *
00021  * 3. The end-user documentation included with the redistribution, if
00022  *    any, must include the following acknowlegement:
00023  *       "This product includes software developed by the
00024  *        Apache Software Foundation (http://www.apache.org/)."
00025  *    Alternately, this acknowlegement may appear in the software itself,
00026  *    if and wherever such third-party acknowlegements normally appear.
00027  *
00028  * 4. The names "The Jakarta Project", "Tomcat", and "Apache Software
00029  *    Foundation" must not be used to endorse or promote products derived
00030  *    from this software without prior written permission. For written
00031  *    permission, please contact apache@apache.org.
00032  *
00033  * 5. Products derived from this software may not be called "Apache"
00034  *    nor may "Apache" appear in their names without prior written
00035  *    permission of the Apache Group.
00036  *
00037  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
00038  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
00039  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00040  * DISCLAIMED.  IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
00041  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
00042  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00043  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
00044  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
00045  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00046  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
00047  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00048  * SUCH DAMAGE.
00049  * ====================================================================
00050  *
00051  */
00052 
00053 #ifndef COOKIE_H
00054 #define COOKIE_H
00055 
00056 #include <ctype.h> //tolower
00057 #include <string>
00058 #include <algorithm>
00059 
00060 namespace servlet {
00061 
00102 class Cookie {
00103     //
00104     // The value of the cookie itself.
00105     //
00106     std::string name;         // NAME= ... "$Name" style is reserved
00107     std::string value;        // value of NAME
00108 
00109     //
00110     // Attributes encoded in the header's cookie fields.
00111     //
00112     std::string comment;     // ;Comment=VALUE ... describes cookie's use
00113                              // ;Discard ... implied by maxAge < 0
00114     std::string domain;      // ;Domain=VALUE ... domain that sees cookie
00115     int maxAge;              // ;Max-Age=VALUE ... cookies auto-expire
00116     std::string path;        // ;Path=VALUE ... URLs that see the cookie
00117     bool secure;             // ;Secure ... e.g. use SSL
00118     int version;             // ;Version=1 ... means RFC 2109++ style
00119 public:
00120 
00121 
00122 
00153     Cookie(const std::string& name, const std::string& value);
00154 
00155 
00156 
00170     void  setComment(const std::string& purpose)
00171         { comment = purpose; }
00172 
00173 
00184     std::string  getComment() const
00185         { return comment; }
00186 
00187 
00188 
00208     void  setDomain(const std::string& pattern) {
00209         domain.resize(pattern.size());
00210         std::transform(pattern.begin(), pattern.end(), domain.begin(), tolower); // IE allegedly needs this
00211     }
00212 
00213 
00214 
00224     std::string  getDomain() const
00225         { return domain; }
00226 
00227 
00250     void  setMaxAge(int expiry)
00251         { maxAge = expiry; }
00252 
00253 
00268     int  getMaxAge() const
00269         { return maxAge; }
00270 
00271 
00272 
00293     void  setPath(const std::string& uri)
00294         { path = uri; }
00295 
00296 
00297 
00310     std::string  getPath() const
00311         { return path; }
00312 
00313 
00314 
00328     void  setSecure(bool flag)
00329         { secure = flag; }
00330 
00331 
00343     bool  getSecure() const
00344         { return secure; }
00345 
00346 
00347 
00355     std::string  getName() const
00356         { return name; }
00357 
00358 
00359 
00378     void  setValue(const std::string& newValue)
00379         { value = newValue; }
00380 
00381 
00382 
00393     std::string  getValue() const
00394         { return value; }
00395 
00396 
00412     int  getVersion() const
00413         { return version; }
00414 
00415 
00416 
00417 
00434     void  setVersion(int v)
00435         { version = v; }
00436 
00437 private:
00438 
00439 
00440     /*
00441      * Tests a string and returns true if the string counts as a
00442      * reserved token in the Java language.
00443      *
00444      * @param value             the <code>String</code> to be tested
00445      *
00446      * @return                  <code>true</code> if the <code>String</code> is
00447      *                          a reserved token; <code>false</code>
00448      *                          if it is not
00449      */
00450     bool  isValidName(const std::string& value) const;
00451 };
00452 
00453 }//namespace
00454 
00455 #endif/*COOKIE_H*/

SourceForge.net Logo