HttpdCookies Class ReferenceHTTP Cookie parse/container class.
More...
| ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Public Member Functions | |
| HttpdCookies () | |
| HttpdCookies (const std::string &query_string) | |
| ~HttpdCookies () | |
| void | add (const std::string &s) |
| bool | getvalue (const std::string &, std::string &) const |
| void | replacevalue (const std::string &, const std::string &) |
| void | replacevalue (const std::string &, long) |
| void | replacevalue (const std::string &, int) |
| size_t | getlength (const std::string &) const |
| void | setcookie (HTTPSocket *, const std::string &d, const std::string &p, const std::string &c, const std::string &v) |
| void | setcookie (HTTPSocket *, const std::string &d, const std::string &p, const std::string &c, long v) |
| void | setcookie (HTTPSocket *, const std::string &d, const std::string &p, const std::string &c, int v) |
| const std::string & | expiredatetime () const |
| cookie_v & | GetHttpdCookies () |
| void | Reset () |
Private Types | |
| typedef std::list< std::pair < std::string, std::string > > | cookie_v |
| list of key/value structs. | |
Private Attributes | |
| cookie_v | m_cookies |
| std::string | m_date |
Definition at line 52 of file HttpdCookies.h.
typedef std::list<std::pair<std::string, std::string> > HttpdCookies::cookie_v [private] |
| HttpdCookies::HttpdCookies | ( | ) |
| HttpdCookies::HttpdCookies | ( | const std::string & | query_string | ) |
Definition at line 52 of file HttpdCookies.cpp.
References m_cookies.
00053 { 00054 Parse *pa = new Parse(s,";"); 00055 00056 std::string slask = pa -> getword(); 00057 while (slask.size()) 00058 { 00059 Parse *pa2 = new Parse(slask,"="); 00060 std::string name = pa2 -> getword(); 00061 std::string value = pa2 -> getword(); 00062 delete pa2; 00063 m_cookies.push_back(std::pair<std::string, std::string>(name, value)); 00064 // 00065 slask = pa -> getword(); 00066 } 00067 delete pa; 00068 }
| HttpdCookies::~HttpdCookies | ( | ) |
| void HttpdCookies::add | ( | const std::string & | s | ) |
Definition at line 70 of file HttpdCookies.cpp.
References DEB, and m_cookies.
Referenced by HttpRequest::AddCookie().
00071 { 00072 Parse *pa = new Parse(s,";"); 00073 DEB(fprintf(stderr, "Parse cookie: %s\n", s.c_str());) 00074 std::string slask = pa -> getword(); 00075 while (slask.size()) 00076 { 00077 Parse *pa2 = new Parse(slask,"="); 00078 std::string name = pa2 -> getword(); 00079 std::string value = pa2 -> getword(); 00080 delete pa2; 00081 m_cookies.push_back(std::pair<std::string, std::string>(name, value)); 00082 // 00083 slask = pa -> getword(); 00084 } 00085 delete pa; 00086 }
| bool HttpdCookies::getvalue | ( | const std::string & | name, | |
| std::string & | buffer | |||
| ) | const |
Definition at line 92 of file HttpdCookies.cpp.
References m_cookies.
00093 { 00094 for (cookie_v::const_iterator it = m_cookies.begin(); it != m_cookies.end(); it++) 00095 { 00096 const std::pair<std::string, std::string>& ref = *it; 00097 if (!strcasecmp(ref.first.c_str(),name.c_str())) 00098 { 00099 buffer = ref.second; 00100 return true; 00101 } 00102 } 00103 buffer = ""; 00104 return false; 00105 }
| void HttpdCookies::replacevalue | ( | const std::string & | name, | |
| const std::string & | value | |||
| ) |
Definition at line 107 of file HttpdCookies.cpp.
References m_cookies.
Referenced by replacevalue(), and setcookie().
00108 { 00109 for (cookie_v::iterator it = m_cookies.begin(); it != m_cookies.end(); it++) 00110 { 00111 std::pair<std::string, std::string>& ref = *it; 00112 if (!strcasecmp(ref.first.c_str(),name.c_str())) 00113 { 00114 ref.second = value; 00115 return; 00116 } 00117 } 00118 m_cookies.push_back(std::pair<std::string, std::string>(name, value)); 00119 00120 }
| void HttpdCookies::replacevalue | ( | const std::string & | name, | |
| long | l | |||
| ) |
Definition at line 122 of file HttpdCookies.cpp.
References Utility::l2string(), and replacevalue().
00123 { 00124 replacevalue(name, Utility::l2string(l)); 00125 }
| void HttpdCookies::replacevalue | ( | const std::string & | name, | |
| int | i | |||
| ) |
Definition at line 127 of file HttpdCookies.cpp.
References Utility::l2string(), and replacevalue().
00128 { 00129 replacevalue(name, Utility::l2string(i)); 00130 }
| size_t HttpdCookies::getlength | ( | const std::string & | name | ) | const |
Definition at line 132 of file HttpdCookies.cpp.
References m_cookies.
00133 { 00134 for (cookie_v::const_iterator it = m_cookies.begin(); it != m_cookies.end(); it++) 00135 { 00136 const std::pair<std::string, std::string>& ref = *it; 00137 if (!strcasecmp(ref.first.c_str(),name.c_str())) 00138 { 00139 return ref.second.size(); 00140 } 00141 } 00142 return 0; 00143 }
| void HttpdCookies::setcookie | ( | HTTPSocket * | sock, | |
| const std::string & | d, | |||
| const std::string & | p, | |||
| const std::string & | c, | |||
| const std::string & | v | |||
| ) |
Definition at line 145 of file HttpdCookies.cpp.
References expiredatetime(), and replacevalue().
00146 { 00147 char *str = new char[name.size() + value.size() + domain.size() + path.size() + 100]; 00148 00149 // set-cookie response 00150 if (domain.size()) 00151 { 00152 sprintf(str, "%s=%s; domain=%s; path=%s; expires=%s", 00153 name.c_str(), value.c_str(), 00154 domain.c_str(), 00155 path.c_str(), 00156 expiredatetime().c_str()); 00157 } 00158 else 00159 { 00160 sprintf(str, "%s=%s; path=%s; expires=%s", 00161 name.c_str(), value.c_str(), 00162 path.c_str(), 00163 expiredatetime().c_str()); 00164 } 00165 sock -> AddResponseHeader("Set-cookie", str); 00166 delete[] str; 00167 00168 replacevalue(name, value); 00169 }
| void HttpdCookies::setcookie | ( | HTTPSocket * | sock, | |
| const std::string & | d, | |||
| const std::string & | p, | |||
| const std::string & | c, | |||
| long | v | |||
| ) |
Definition at line 171 of file HttpdCookies.cpp.
References expiredatetime(), and replacevalue().
00172 { 00173 char *str = new char[name.size() + domain.size() + path.size() + 100]; 00174 char dt[80]; 00175 00176 // set-cookie response 00177 if (domain.size()) 00178 { 00179 sprintf(str, "%s=%ld; domain=%s; path=%s; expires=%s", 00180 name.c_str(), value, 00181 domain.c_str(), 00182 path.c_str(), 00183 expiredatetime().c_str()); 00184 } 00185 else 00186 { 00187 sprintf(str, "%s=%ld; path=%s; expires=%s", 00188 name.c_str(), value, 00189 path.c_str(), 00190 expiredatetime().c_str()); 00191 } 00192 sock -> AddResponseHeader("Set-cookie", str); 00193 delete[] str; 00194 00195 sprintf(dt, "%ld", value); 00196 replacevalue(name, dt); 00197 }
| void HttpdCookies::setcookie | ( | HTTPSocket * | sock, | |
| const std::string & | d, | |||
| const std::string & | p, | |||
| const std::string & | c, | |||
| int | v | |||
| ) |
Definition at line 199 of file HttpdCookies.cpp.
References expiredatetime(), and replacevalue().
00200 { 00201 char *str = new char[name.size() + domain.size() + path.size() + 100]; 00202 char dt[80]; 00203 00204 // set-cookie response 00205 if (domain.size()) 00206 { 00207 sprintf(str, "%s=%d; domain=%s; path=%s; expires=%s", 00208 name.c_str(), value, 00209 domain.c_str(), 00210 path.c_str(), 00211 expiredatetime().c_str()); 00212 } 00213 else 00214 { 00215 sprintf(str, "%s=%d; path=%s; expires=%s", 00216 name.c_str(), value, 00217 path.c_str(), 00218 expiredatetime().c_str()); 00219 } 00220 sock -> AddResponseHeader("Set-cookie", str); 00221 delete[] str; 00222 00223 sprintf(dt, "%d", value); 00224 replacevalue(name, dt); 00225 }
| const std::string & HttpdCookies::expiredatetime | ( | ) | const |
Definition at line 228 of file HttpdCookies.cpp.
References m_date.
Referenced by setcookie().
00229 { 00230 time_t t = time(NULL); 00231 struct tm tp; 00232 #ifdef _WIN32 00233 memcpy(&tp, gmtime(&t), sizeof(tp)); 00234 #else 00235 gmtime_r(&t, &tp); 00236 #endif 00237 const char *days[7] = {"Sunday", "Monday", 00238 "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; 00239 const char *months[12] = {"Jan", "Feb", "Mar", "Apr", "May", 00240 "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; 00241 char dt[100]; 00242 00243 sprintf(dt, "%s, %02d-%s-%04d %02d:%02d:%02d GMT", 00244 days[tp.tm_wday], 00245 tp.tm_mday, 00246 months[tp.tm_mon], 00247 tp.tm_year + 1910, 00248 tp.tm_hour, 00249 tp.tm_min, 00250 tp.tm_sec); 00251 m_date = dt; 00252 return m_date; 00253 }
| cookie_v& HttpdCookies::GetHttpdCookies | ( | ) | [inline] |
| void HttpdCookies::Reset | ( | ) |
Definition at line 256 of file HttpdCookies.cpp.
References m_cookies, and m_date.
Referenced by HttpRequest::Reset().
00257 { 00258 while (!m_cookies.empty()) 00259 { 00260 m_cookies.erase(m_cookies.begin()); 00261 } 00262 m_date = ""; 00263 }
cookie_v HttpdCookies::m_cookies [private] |
Definition at line 79 of file HttpdCookies.h.
Referenced by add(), getlength(), getvalue(), HttpdCookies(), replacevalue(), and Reset().
std::string HttpdCookies::m_date [mutable, private] |
1.4.4