26 #include <boost/shared_array.hpp>
27 #include <boost/scoped_array.hpp>
28 #include <boost/date_time/posix_time/posix_time.hpp>
58 template<
class charT>
struct Post
108 template<
class charT,
class Traits>
inline std::basic_ostream<charT, Traits>& operator<<(std::basic_ostream<charT, Traits>& os,
const RequestMethod requestMethod) {
return os <<
requestMethodLabels[requestMethod]; }
161 void assign(
const char* start,
const char* end);
168 operator bool()
const;
186 template<
class charT,
class Traits> std::basic_ostream<charT, Traits>& operator<<(std::basic_ostream<charT, Traits>& os,
const Address& address);
193 template<
class charT,
class Traits> std::basic_istream<charT, Traits>&
operator>>(std::basic_istream<charT, Traits>& is,
Address& address);
227 typedef std::vector<std::basic_string<charT> >
PathInfo;
246 typedef std::map<std::basic_string<charT>, std::basic_string<charT> >
Cookies;
250 const std::basic_string<charT>&
findCookie(
const charT* key)
const;
252 typedef std::map<std::basic_string<charT>, std::basic_string<charT> >
Gets;
262 const std::basic_string<charT>&
findGet(
const charT* key)
const;
299 void fill(
const char* data,
size_t size);
343 void charToString(
const char* data,
size_t size, std::wstring&
string);
352 inline void charToString(
const char* data,
size_t size, std::string&
string) {
string.assign(data, size); }
365 int atoi(
const char* start,
const char* end);
375 template<
class charT>
void decodeUrlEncoded(
const char* data,
size_t size, std::map<std::basic_string<charT>, std::basic_string<charT> >& output,
const char fieldSeperator=
'&');
407 template<
class In,
class Out>
void base64Encode(In start, In end, Out destination);
425 template<
class In,
class Out> Out
base64Decode(In start, In end, Out destination);
435 public:
static const int size=12;
479 template<
class charT>
SessionId(charT* data_) { *
this=data_; }
481 template<
class charT,
class Traits>
friend std::basic_ostream<charT, Traits>& operator<<(std::basic_ostream<charT, Traits>& os,
const SessionId& x);
489 void refresh()
const { *
const_cast<boost::posix_time::ptime*
>(&
timestamp)=boost::posix_time::second_clock::universal_time(); }
497 template<
class charT,
class Traits> std::basic_ostream<charT, Traits>& operator<<(std::basic_ostream<charT, Traits>& os,
const SessionId& x) {
base64Encode(x.data, x.data+
SessionId::size, std::ostream_iterator<charT, charT, Traits>(os));
return os; }
509 template<
class T>
class Sessions:
public std::map<SessionId, T>
527 typedef typename std::map<SessionId, T>::iterator
iterator;
560 if(boost::posix_time::second_clock::universal_time() < cleanupTime)
562 boost::posix_time::ptime oldest(boost::posix_time::second_clock::universal_time()-keepAlive);
564 while(it!=this->end())
566 if(it->first.timestamp < oldest)
571 cleanupTime=boost::posix_time::second_clock::universal_time()+cleanupFrequency;
576 Out dest=destination;
578 for(
int buffer, bitPos=-8, padStart; start!=end || bitPos>-6; ++dest)
587 if(start==end)
return destination;
589 if(value >=
'A' &&
'Z' >= value) value -=
'A';
590 else if(value >=
'a' &&
'z' >= value) value -=
'a' - 26;
591 else if(value >=
'0' &&
'9' >= value) value -=
'0' - 52;
592 else if(value ==
'+') value = 62;
593 else if(value ==
'/') value = 63;
594 else if(value ==
'=') { padStart=bitPos;
break; }
595 else return destination;
597 buffer |= value << bitPos;
603 *dest = (buffer >> bitPos) & 0xff;
607 if( (padStart-bitPos)/6 )
619 for(
int buffer, bitPos=-6, padded; start!=end || bitPos>-6; ++destination)
629 buffer |= (uint32_t)*(
unsigned char*)start++ << bitPos;
648 std::pair<iterator,bool> retVal;
650 while(!retVal.second)
651 retVal=insert(std::pair<SessionId, T>(
SessionId(), value_));