#include <Cookies.h>
Collaboration diagram for Cgi::Cookies:
Public Member Functions | |
Cookies (void) | |
Default constructor (used in POST operations). | |
Cookies (char *query_string) | |
Another constructor (used in GET operations). | |
~Cookies (void) | |
Destructor. | |
int | getvalue (char *, char *, short) |
void | replacevalue (char *, char *) |
void | replacevalue (char *, long) |
void | replacevalue (char *, int) |
int | getlength (char *) |
void | setcookie (char *, char *, char *, char *) |
void | setcookie (char *, char *, char *, long) |
void | setcookie (char *, char *, char *, int) |
void | expiredatetime (char *) |
cookie_v & | GetCookies () |
Private Attributes | |
cookie_v | m_cookies |
Definition at line 44 of file Cookies.h.
Cgi::Cookies::Cookies | ( | void | ) |
Default constructor (used in POST operations).
Input is read from stdin.
Definition at line 40 of file Cookies.cpp.
Cgi::Cookies::Cookies | ( | char * | query_string | ) |
Another constructor (used in GET operations).
Input is read from the environment variable QUERY_STRING with a length of CONTENT_LENGTH.
query_string | The httpd server provided QUERY_STRING |
Definition at line 45 of file Cookies.cpp.
References m_cookies.
00046 { 00047 COOKIE *c = NULL; 00048 Cgi::Parse *pa = new Cgi::Parse(s,";"); 00049 Cgi::Parse *pa2; 00050 char slask[500]; 00051 char name[500]; 00052 char value[500]; 00053 00054 // cookiebase = NULL; 00055 00056 pa -> getword(slask); 00057 while (*slask) 00058 { 00059 pa2 = new Cgi::Parse(slask,"="); 00060 pa2 -> getword(name); 00061 pa2 -> getword(value); 00062 delete pa2; 00063 c = new COOKIE; 00064 c -> name = new char[strlen(name) + 1]; 00065 strcpy(c -> name,name); 00066 c -> value = new char[strlen(value) + 1]; 00067 strcpy(c -> value,value); 00068 // addlist(&cookiebase,c); 00069 m_cookies.push_back(c); 00070 // 00071 pa -> getword(slask); 00072 } 00073 delete pa; 00074 }
Cgi::Cookies::~Cookies | ( | void | ) |
Destructor.
Definition at line 76 of file Cookies.cpp.
References m_cookies.
00077 { 00078 COOKIE *c = NULL; //,*tmp; 00079 00080 // for (c = cookiebase; c; c = tmp) 00081 for (cookie_v::iterator it = m_cookies.begin(); it != m_cookies.end(); it++) 00082 { 00083 c = *it; 00084 delete[] c -> name; 00085 delete[] c -> value; 00086 // tmp = c -> next; 00087 delete c; 00088 } 00089 }
int Cgi::Cookies::getvalue | ( | char * | , | |
char * | , | |||
short | ||||
) |
Definition at line 91 of file Cookies.cpp.
References m_cookies.
00092 { 00093 COOKIE *c = NULL; 00094 00095 // for (c = cookiebase; c; c = c -> next) 00096 for (cookie_v::iterator it = m_cookies.begin(); it != m_cookies.end(); it++) 00097 { 00098 c = *it; 00099 if (!strcasecmp(c -> name,name)) 00100 break; 00101 c = NULL; 00102 } 00103 if (c) 00104 { 00105 if ((short)strlen(c -> value) >= length) 00106 { 00107 strncpy(buffer,c -> value,length - 1); 00108 buffer[length - 1] = 0; 00109 } else 00110 strcpy(buffer,c -> value); 00111 return 1; 00112 } else 00113 { 00114 *buffer = 0; 00115 return 0; 00116 } 00117 }
void Cgi::Cookies::replacevalue | ( | char * | , | |
char * | ||||
) |
Definition at line 119 of file Cookies.cpp.
References m_cookies.
Referenced by replacevalue(), and setcookie().
00120 { 00121 COOKIE *c = NULL; 00122 00123 // for (c = cookiebase; c; c = c -> next) 00124 for (cookie_v::iterator it = m_cookies.begin(); it != m_cookies.end(); it++) 00125 { 00126 c = *it; 00127 if (!strcasecmp(c -> name,name)) 00128 break; 00129 c = NULL; 00130 } 00131 00132 if (c) 00133 { 00134 if (strlen(value) > strlen(c -> value)) 00135 { 00136 delete[] c -> value; 00137 c -> value = new char[strlen(value) + 1]; 00138 } 00139 strcpy(c -> value,value); 00140 } else 00141 { 00142 c = new COOKIE; 00143 c -> name = new char[strlen(name) + 1]; 00144 strcpy(c -> name,name); 00145 c -> value = new char[strlen(value) + 1]; 00146 strcpy(c -> value,value); 00147 // addlist(&cookiebase,c); 00148 m_cookies.push_back(c); 00149 } 00150 }
void Cgi::Cookies::replacevalue | ( | char * | , | |
long | ||||
) |
Definition at line 152 of file Cookies.cpp.
References replacevalue().
00153 { 00154 char slask[100]; 00155 00156 sprintf(slask,"%ld",l); 00157 replacevalue(name,slask); 00158 }
void Cgi::Cookies::replacevalue | ( | char * | , | |
int | ||||
) |
Definition at line 160 of file Cookies.cpp.
References replacevalue().
00161 { 00162 char slask[100]; 00163 00164 sprintf(slask,"%d",i); 00165 replacevalue(name,slask); 00166 }
int Cgi::Cookies::getlength | ( | char * | ) |
Definition at line 168 of file Cookies.cpp.
References m_cookies.
00169 { 00170 COOKIE *c = NULL; 00171 00172 // for (c = cookiebase; c; c = c -> next) 00173 for (cookie_v::iterator it = m_cookies.begin(); it != m_cookies.end(); it++) 00174 { 00175 c = *it; 00176 if (!strcasecmp(c -> name,name)) 00177 break; 00178 c = NULL; 00179 } 00180 return c ? strlen(c -> value) : 0; 00181 }
void Cgi::Cookies::setcookie | ( | char * | , | |
char * | , | |||
char * | , | |||
char * | ||||
) |
Definition at line 183 of file Cookies.cpp.
References expiredatetime(), and replacevalue().
00184 { 00185 char dt[80]; 00186 00187 Cookies::expiredatetime(dt); 00188 00189 // set-cookie response 00190 printf("Set-Cookie: %s=%s; domain=%s; path=%s; expires=%s\n", 00191 name,value, 00192 domain, 00193 path, 00194 dt); 00195 Cookies::replacevalue(name,value); 00196 }
void Cgi::Cookies::setcookie | ( | char * | , | |
char * | , | |||
char * | , | |||
long | ||||
) |
Definition at line 198 of file Cookies.cpp.
References expiredatetime(), and replacevalue().
00199 { 00200 char dt[80]; 00201 00202 Cookies::expiredatetime(dt); 00203 00204 // set-cookie response 00205 printf("Set-Cookie: %s=%ld; domain=%s; path=%s; expires=%s\n", 00206 name,value, 00207 domain, 00208 path, 00209 dt); 00210 sprintf(dt,"%ld",value); 00211 Cookies::replacevalue(name,dt); 00212 }
void Cgi::Cookies::setcookie | ( | char * | , | |
char * | , | |||
char * | , | |||
int | ||||
) |
Definition at line 214 of file Cookies.cpp.
References expiredatetime(), and replacevalue().
00215 { 00216 char dt[80]; 00217 00218 Cookies::expiredatetime(dt); 00219 00220 // set-cookie response 00221 printf("Set-Cookie: %s=%d; domain=%s; path=%s; expires=%s\n", 00222 name,value, 00223 domain, 00224 path, 00225 dt); 00226 sprintf(dt,"%d",value); 00227 Cookies::replacevalue(name,dt); 00228 }
void Cgi::Cookies::expiredatetime | ( | char * | ) |
Definition at line 230 of file Cookies.cpp.
Referenced by setcookie().
00231 { 00232 time_t t = time(NULL); 00233 struct tm * tp = gmtime(&t); 00234 00235 sprintf(dt,"%s, %02d-%s-%04d %02d:%02d:%02d GMT", 00236 days[tp -> tm_wday], 00237 tp -> tm_mday, 00238 months[tp -> tm_mon], 00239 tp -> tm_year + 1910, 00240 tp -> tm_hour, 00241 tp -> tm_min, 00242 tp -> tm_sec); 00243 }
cookie_v& Cgi::Cookies::GetCookies | ( | ) | [inline] |
cookie_v Cgi::Cookies::m_cookies [private] |
Definition at line 76 of file Cookies.h.
Referenced by Cookies(), GetCookies(), getlength(), getvalue(), replacevalue(), and ~Cookies().