00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 #include "Cookie.h"
00039
00040 #include <string.h>
00041 #include <boost/date_time/posix_time/posix_time.hpp>
00042
00043 using namespace std;
00044 using namespace boost;
00045 using namespace ClearSilver;
00046
00047 static string convert (const posix_time::ptime& t);
00048
00049
00050
00051 Cookie::Cookie () : name_(), value_(), credentials_() {}
00052 Cookie::Cookie (const char * name) : name_(name), value_(), credentials_() {}
00053 Cookie::Cookie (const char * name, const Credentials& credentials)
00054 : name_(name), value_(), credentials_(credentials_) {}
00055 Cookie::Cookie (const char * name, const char * value)
00056 : name_(name), value_(value), credentials_() {}
00057 Cookie::Cookie (const char * name, const char * value,
00058 const Credentials& credentials)
00059 : name_(name), value_(value), credentials_(credentials) {}
00060 Cookie::Cookie (const string& name) : name_(name), value_(), credentials_() {}
00061 Cookie::Cookie (const string& name, const Credentials& credentials)
00062 : name_(name), value_(), credentials_(credentials_) {}
00063 Cookie::Cookie (const string& name, const string& value)
00064 : name_(name), value_(value), credentials_() {}
00065 Cookie::Cookie (const string& name, const string& value,
00066 const Credentials& credentials)
00067 : name_(name), value_(value), credentials_(credentials) {}
00068 Cookie::Cookie (const Cookie& c)
00069 : name_(c.name_), value_(c.value_), credentials_(c.credentials_) {}
00070 Cookie::~Cookie () throw() {}
00071
00072
00073 Cookie&
00074 Cookie::operator = (const Cookie& c)
00075 {
00076 Cookie c_(c);
00077 swap (c_);
00078 return *this;
00079 }
00080
00082 void
00083 Cookie::swap (Cookie& c) throw()
00084 {
00085 ::swap(name_, c.name_);
00086 ::swap(value_, c.value_);
00087 ::swap(credentials_, c.credentials_);
00088 }
00089
00090
00091 string
00092 Cookie::name () const { return name_; }
00093 string
00094 Cookie::value () const { return value_; }
00095 Cookie::Credentials
00096 Cookie::credentials () const { return credentials_; }
00097 Cookie::Credentials&
00098 Cookie::credentials () { return credentials_; }
00099
00100
00101
00102 Cookie::Credentials::Credentials ()
00103 : authority_(), path_(), expires_(), persist_(false), secure_(false) {}
00104 Cookie::Credentials::Credentials (const Authority& a)
00105 : authority_(a), path_(), expires_(), persist_(false), secure_(false) {}
00106 Cookie::Credentials::Credentials (const Path& p)
00107 : authority_(), path_(p), expires_(), persist_(false), secure_(false) {}
00108 Cookie::Credentials::Credentials (const Expires& e)
00109 : authority_(), path_(), expires_(e), persist_(true), secure_(false) {}
00110 Cookie::Credentials::Credentials (const Authority& a, const Path& p)
00111 : authority_(a), path_(p), expires_(), persist_(false), secure_(false) {}
00112 Cookie::Credentials::Credentials (const Authority& a, const Path& p,
00113 const Expires& e)
00114 : authority_(a), path_(p), expires_(e), persist_(true), secure_(false) {}
00115 Cookie::Credentials::Credentials (const Credentials& c)
00116 : authority_(c.authority_), path_(c.path_), expires_(c.expires_),
00117 persist_(c.persist_), secure_(c.secure_) {}
00118 Cookie::Credentials::~Credentials () throw() {}
00119
00120
00121 Cookie::Credentials&
00122 Cookie::Credentials::operator = (const Credentials& c)
00123 {
00124 Credentials c_(c);
00125 swap (c_);
00126 return *this;
00127 }
00128
00129
00130 void
00131 Cookie::Credentials::swap (Credentials& c) throw()
00132 {
00133 ::swap (authority_, c.authority_);
00134 ::swap (path_, c.path_);
00135 ::swap (expires_, c.expires_);
00136 ::swap (persist_, c.persist_);
00137 ::swap (secure_, c.secure_);
00138 }
00139
00140
00141
00142 Cookie::Authority
00143 Cookie::Credentials::authority () const { return authority_; }
00144
00145 Cookie::Authority&
00146 Cookie::Credentials::authority () { return authority_; }
00147
00148 Cookie::Path
00149 Cookie::Credentials::path () const { return path_; }
00150
00151 Cookie::Path&
00152 Cookie::Credentials::path () { return path_; }
00153
00154 Cookie::Expires
00155 Cookie::Credentials::expires () const { return expires_; }
00156
00157 Cookie::Expires&
00158 Cookie::Credentials::expires ()
00159 {
00160 persist_ = true;
00161 return expires_;
00162 }
00163
00164 bool
00165 Cookie::Credentials::persist () const { return persist_; }
00166
00167 bool
00168 Cookie::Credentials::secure () const { return secure_; }
00169
00170 bool&
00171 Cookie::Credentials::secure () { return secure_; }
00172
00173
00174
00175 Cookie::Authority::Authority () : authority_() {}
00176 Cookie::Authority::Authority (const char * a) : authority_(a?string(a):"") {}
00177 Cookie::Authority::Authority (const string& a) : authority_(a) {}
00178 Cookie::Authority::Authority (const Authority& a) : authority_(a.authority_) {}
00179 Cookie::Authority::~Authority () throw() {}
00180
00181
00182 Cookie::Authority&
00183 Cookie::Authority::operator = (const Authority& a)
00184 {
00185 Authority a_ (a);
00186 swap (a_);
00187 return *this;
00188 }
00189
00190
00191 void
00192 Cookie::Authority::swap (Authority& a) throw()
00193 {
00194 ::swap(authority_, a.authority_);
00195 }
00196
00197
00198 bool
00199 Cookie::Authority::empty () const { return authority_.empty(); }
00200
00201
00202 string
00203 Cookie::Authority::operator () () const { return authority_; }
00204
00205
00206
00207 Cookie::Path::Path () : path_() {}
00208 Cookie::Path::Path (const char * p) : path_(p?string(p):"") {}
00209 Cookie::Path::Path (const string& p) : path_(p) {}
00210 Cookie::Path::Path (const Path& p) : path_(p.path_) {}
00211 Cookie::Path::~Path () throw() {}
00212
00213
00214 Cookie::Path&
00215 Cookie::Path::operator = (const Path& p)
00216 {
00217 Path p_(p);
00218 swap (p_);
00219 return *this;
00220 }
00221
00222
00224 void
00225 Cookie::Path::swap (Path& p) throw()
00226 {
00227 ::swap(path_, p.path_);
00228 }
00229
00230 bool
00231 Cookie::Path::empty () const { return path_.empty(); }
00232
00233
00234 string
00235 Cookie::Path::operator () () const { return path_; }
00236
00237
00238
00239 Cookie::Expires::Expires () : expires_() {}
00240 Cookie::Expires::Expires (const char* e)
00241 : expires_(convert(posix_time::time_from_string(e))) {}
00242 Cookie::Expires::Expires (const string& e)
00243 : expires_(convert(posix_time::time_from_string(e))) {}
00244 Cookie::Expires::Expires (time_t t)
00245 : expires_(convert(posix_time::from_time_t(t))) {}
00246 Cookie::Expires::Expires (struct tm tm)
00247 : expires_(convert
00248 (posix_time::ptime
00249 (gregorian::date(tm.tm_year, tm.tm_mon, tm.tm_mday),
00250 posix_time::time_duration(tm.tm_hour, tm.tm_min, tm.tm_sec)))) {}
00251 Cookie::Expires::Expires (const boost::posix_time::ptime& expires)
00252 : expires_(convert(expires)) {}
00253 Cookie::Expires::Expires (const Expires& e) : expires_(e.expires_) {}
00254 Cookie::Expires::~Expires () throw() {}
00255
00256
00257 Cookie::Expires&
00258 Cookie::Expires::operator = (const Expires& e)
00259 {
00260 expires_ = e.expires_;
00261 return *this;
00262 }
00263
00264
00265 void
00266 Cookie::Expires::swap (Expires& e) throw()
00267 {
00268 std::swap(expires_, e.expires_);
00269 }
00270
00271
00272 Cookie::Expires::operator bool () const { return !expires_.empty(); }
00273
00274 bool
00275 Cookie::Expires::empty () const { return expires_.empty(); }
00276
00277
00278 string
00279 Cookie::Expires::operator () () const { return expires_; }
00280
00281 string
00282 convert (const posix_time::ptime& t)
00283 {
00284 ostringstream ss;
00285 ss.exceptions(ios_base::failbit);
00286
00287 date_time::time_facet<posix_time::ptime, char>* facet
00288 = new date_time::time_facet<posix_time::ptime, char>;
00289 ss.imbue(locale(locale::classic(), facet));
00290
00291 facet->format("%a, %d-%b-%Y %T GMT");
00292 ss.str("");
00293 ss << t;
00294 return ss.str();
00295 }