summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2010-07-11 12:18:29 (UTC)
committer Michael Krelin <hacker@klever.net>2010-07-11 12:18:29 (UTC)
commitf2a426f8b215c396f2430a98b2929668398f3a51 (patch) (side-by-side diff)
treeabc8795c9480429e0ca381ea49ff4bb04aafee12
parent82ebada6676dcea2d08e14b81365da3ca30c3dd0 (diff)
downloadkingate-f2a426f8b215c396f2430a98b2929668398f3a51.zip
kingate-f2a426f8b215c396f2430a98b2929668398f3a51.tar.gz
kingate-f2a426f8b215c396f2430a98b2929668398f3a51.tar.bz2
cookie: time-based set_expires variants
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/kingate/cookies.h2
-rw-r--r--src/cookies.cc10
2 files changed, 12 insertions, 0 deletions
diff --git a/include/kingate/cookies.h b/include/kingate/cookies.h
index a1e813c..cba5aff 100644
--- a/include/kingate/cookies.h
+++ b/include/kingate/cookies.h
@@ -87,24 +87,26 @@ namespace kingate {
* @see get_secure()
* @see is_secure()
*/
void set_secure(bool s);
/**
* @param e expiration time.
* @see get_expires()
* @see has_expires()
* @see unset_expires()
*/
void set_expires(const string& e);
+ void set_expires_time(time_t etime);
+ void set_expires_in(time_t esecs);
/**
* get cookie parameter.
* @param p parameter name.
* @return parameter value.
* @see _set_string()
*/
const string& _get_string(const string& p) const;
/**
* @return cookie name.
* @see set_name()
diff --git a/src/cookies.cc b/src/cookies.cc
index 1ee4f7c..3215271 100644
--- a/src/cookies.cc
+++ b/src/cookies.cc
@@ -87,24 +87,34 @@ namespace kingate {
_set_string("path",p);
}
void cookie::set_secure(bool s) {
if(s)
_set_string("secure","");
else
erase("secure");
}
void cookie::set_expires(const string& e) {
(*this)["expires"] = e;
}
+ void cookie::set_expires_time(time_t etime) {
+ struct tm etm;
+ char e[64];
+ if(strftime(e,sizeof(e)-1,"%a, %d %b %Y:%M:%S GMT",gmtime_r(&etime,&etm)))
+ set_expires(e);
+ /* TODO: handle error */
+ }
+ void cookie::set_expires_in(time_t esecs) {
+ set_expires_time(time(0)+esecs);
+ }
const string& cookie::_get_string(const string& s) const {
const_iterator i = find(s);
if(i==end())
throw exception_notfound(CODEPOINT,"No parameter set");
return i->second;
}
const string& cookie::get_comment() const {
return _get_string("comment");
}
const string& cookie::get_domain() const {