Main Page | Namespace List | Class Hierarchy | Class List | Directories | File List | Namespace Members | Class Members | File Members

HTTPCookie.cpp

Go to the documentation of this file.
00001 /* -*-mode:c++; c-file-style: "gnu";-*- */
00002 /*
00003  *  $Id: HTTPCookie.cpp,v 1.10 2007/07/02 18:48:18 sebdiaz Exp $
00004  *
00005  *  Copyright (C) 1996 - 2004 Stephen F. Booth <sbooth@gnu.org>
00006  *                       2007 Sebastien DIAZ <sebastien.diaz@gmail.com>
00007  *  Part of the GNU cgicc library, http://www.gnu.org/software/cgicc
00008  *
00009  *  This library is free software; you can redistribute it and/or
00010  *  modify it under the terms of the GNU Lesser General Public
00011  *  License as published by the Free Software Foundation; either
00012  *  version 3 of the License, or (at your option) any later version.
00013  *
00014  *  This library is distributed in the hope that it will be useful,
00015  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
00016  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00017  *  Lesser General Public License for more details.
00018  *
00019  *  You should have received a copy of the GNU Lesser General Public
00020  *  License along with this library; if not, write to the Free Software
00021  *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA 
00022  */
00023 
00024 #ifdef __GNUG__
00025 #  pragma implementation
00026 #endif
00027 
00028 #include "cgicc/HTTPCookie.h"
00029 #include "cgicc/CgiUtils.h"
00030 
00031 // ============================================================
00032 // Class HTTPCookie
00033 // ============================================================
00034 cgicc::HTTPCookie::HTTPCookie()
00035   : fMaxAge(0),
00036     fSecure(false)
00037 {}
00038 
00039 cgicc::HTTPCookie::HTTPCookie(const std::string& name, 
00040                               const std::string& value)
00041   : fName(name),
00042     fValue(value),
00043     fMaxAge(0),
00044     fSecure(false)
00045 {}
00046 
00047 cgicc::HTTPCookie::HTTPCookie(const std::string& name, 
00048                               const std::string& value, 
00049                               const std::string& comment, 
00050                               const std::string& domain, 
00051                               unsigned long maxAge, 
00052                               const std::string& path,
00053                               bool secure)
00054   : fName(name),
00055     fValue(value), 
00056     fComment(comment), 
00057     fDomain(domain), 
00058     fMaxAge(maxAge),
00059     fPath(path), 
00060     fSecure(secure)
00061 {}
00062 
00063 cgicc::HTTPCookie::HTTPCookie(const HTTPCookie& cookie)
00064   : MStreamable(),
00065     fName(cookie.fName), 
00066     fValue(cookie.fValue), 
00067     fComment(cookie.fComment),
00068     fDomain(cookie.fDomain), 
00069     fMaxAge(cookie.fMaxAge),
00070     fPath(cookie.fPath), 
00071     fSecure(cookie.fSecure)
00072 {}
00073 
00074 cgicc::HTTPCookie::~HTTPCookie()
00075 {}
00076 
00077 bool 
00078 cgicc::HTTPCookie::operator== (const HTTPCookie& cookie) const
00079 {
00080   return (stringsAreEqual(fName, cookie.fName)
00081           && stringsAreEqual(fValue, cookie.fValue)
00082           && stringsAreEqual(fComment, cookie.fComment)
00083           && stringsAreEqual(fDomain, cookie.fDomain)
00084           && fMaxAge == cookie.fMaxAge
00085           && stringsAreEqual(fPath, cookie.fPath)
00086           && fSecure == cookie.fSecure);
00087 }
00088 
00089 void 
00090 cgicc::HTTPCookie::render(std::ostream& out)    const
00091 {
00092   out << "Set-Cookie:" << fName << '=' << fValue;
00093   if(false == fComment.empty())
00094     out << "; Comment=" << fComment;
00095   if(false == fDomain.empty())
00096     out << "; Domain=" << fDomain;
00097   if(0 != fMaxAge)
00098     out << "; Max-Age=" << fMaxAge;
00099   if(false == fPath.empty())
00100     out << "; Path=" << fPath;
00101   if(true == fSecure)
00102     out << "; Secure";
00103   
00104   out << "; Version=1";
00105 }

© sourcejam.com 2005-2008