00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024 #ifdef __GNUG__
00025 # pragma implementation
00026 #endif
00027
00028 #include "cgicc/HTTPCookie.h"
00029 #include "cgicc/CgiUtils.h"
00030
00031
00032
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 }