Commit 93e1d2a16727d61cc9ed8306e8ffd85ca5915749

Authored by Georg Hopp
1 parent 9e1ab779

some changes on session handlings.

... ... @@ -173,31 +173,25 @@ void
173 173 applicationAdapterHttpUpdate(void * _this, void * subject)
174 174 {
175 175 ApplicationAdapterHttp this = _this;
176   - HttpWorker worker = (HttpWorker)subject;
  176 + HttpWorker worker = (HttpWorker)subject;
177 177 char * sid;
178 178 Session session;
179 179 char buf[200];
180 180 size_t nbuf;
  181 + time_t now = time(NULL);
181 182
182 183 sid = getSessionId(worker->current_request->cookies);
183 184
184 185 session = applicationSessionGet(this->application, sid);
185 186 if (NULL == session) {
186 187 session = applicationSessionStart(this->application);
187   - }
188   -
189   - nbuf = sprintf(buf, SESS_HEADER,
190   - session->id,
191   - SESSION_LIVETIME,
192   - session->livetime - time(NULL));
193   - queuePut(
194   - worker->additional_headers,
195   - new(HttpHeader, CSTRA("X-TaskramblerSession"), buf, nbuf));
196 188
197   - nbuf = sprintf(buf, "sid=%s;Path=/", session->id);
198   - queuePut(
199   - worker->additional_headers,
200   - new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf));
  189 + // send session cookie
  190 + nbuf = sprintf(buf, "sid=%s;Path=/", session->id);
  191 + queuePut(
  192 + worker->additional_headers,
  193 + new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf));
  194 + }
201 195
202 196 if (0 == strcmp("POST", worker->current_request->method)) {
203 197 if (0 == strcmp("/login/", worker->current_request->path)) {
... ... @@ -224,17 +218,27 @@ applicationAdapterHttpUpdate(void * _this, void * subject)
224 218 return;
225 219 }
226 220
227   -// if (0 == strcmp("/sess/", worker->current_request->path)) {
228   -// if (NO_SESSION_SID == sid
229   -// || NULL == applicationSessionGet(this->application, sid)) {
230   -// sid = applicationSessionStart(this->application, NULL, 0);
231   -// }
232   -//
233   -// worker->current_response =
234   -// (HttpMessage)httpResponseSession(
235   -// applicationSessionGet(this->application, sid));
236   -// return;
237   -// }
  221 + if (0 == strcmp("/logout/", worker->current_request->path)) {
  222 + applicationSessionStop(
  223 + this->application,
  224 + session);
  225 +
  226 + // remove session cookie
  227 + nbuf = sprintf(buf, "sid=%s;Path=/;Max-Age=-3600", session->id);
  228 + queuePut(
  229 + worker->additional_headers,
  230 + new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf));
  231 +
  232 + worker->current_response =
  233 + (HttpMessage)httpResponseUser(session->user);
  234 + return;
  235 + }
  236 +
  237 + if (0 == strcmp("/sessinfo/", worker->current_request->path)) {
  238 + worker->current_response =
  239 + (HttpMessage)httpResponseSession(session);
  240 + return;
  241 + }
238 242
239 243 if (0 == strcmp("/randval/", worker->current_request->path)) {
240 244 if (NULL != session->user) {
... ... @@ -247,6 +251,20 @@ applicationAdapterHttpUpdate(void * _this, void * subject)
247 251 }
248 252 }
249 253 }
  254 +
  255 + // if (0 < session->livetime - now) {
  256 + // nbuf = sprintf(buf, SESS_HEADER,
  257 + // session->id,
  258 + // SESSION_LIVETIME,
  259 + // session->livetime - now);
  260 +
  261 + // queuePut(
  262 + // worker->additional_headers,
  263 + // new(HttpHeader, CSTRA("X-TaskramblerSession"), buf, nbuf));
  264 +
  265 + // } else {
  266 + // nbuf = sprintf(buf, "sid=%s;Path=/;Max-Age=-3600", session->id);
  267 + // }
250 268 }
251 269
252 270 // vim: set ts=4 sw=4:
... ...
Please register or login to post a comment