From e69a4962bb4bbe7ffb5d3186ec8c4e69a961ad6d Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Thu, 12 Sep 2013 16:22:08 +0100 Subject: [PATCH] most stuff works...the session timeout will not be reset correctly within some answers, anyway it mostly works. refs #24 --- src/application/adapter/http/update.c | 6 ++- src/application/session_update.c | 10 ++-- src/http/worker/process.c | 68 ++++++++++++++------------- 3 files changed, 45 insertions(+), 39 deletions(-) diff --git a/src/application/adapter/http/update.c b/src/application/adapter/http/update.c index 7ca06cd..fa1cb11 100644 --- a/src/application/adapter/http/update.c +++ b/src/application/adapter/http/update.c @@ -85,7 +85,8 @@ loginAdapter(Application application, HttpWorker worker, unsigned long sid) char buffer[200]; size_t nbuf; - if (NO_SESSION_SID == sid) { + if (NO_SESSION_SID == sid + || NULL == applicationSessionGet(application, sid)) { sid = applicationSessionStart( application, (char *)(username->value), @@ -139,7 +140,8 @@ applicationAdapterHttpUpdate(void * _this, void * subject) } if (0 == strcmp("/sess/", worker->current_request->path)) { - if (NO_SESSION_SID == sid) { + if (NO_SESSION_SID == sid + || NULL == applicationSessionGet(this->application, sid)) { sid = applicationSessionStart(this->application, NULL, 0); } diff --git a/src/application/session_update.c b/src/application/session_update.c index cc85032..eaa144f 100644 --- a/src/application/session_update.c +++ b/src/application/session_update.c @@ -42,11 +42,13 @@ applicationSessionUpdate( { Session session = hashGetByVal(this->active_sessions, sid); - MEM_FREE(session->username); + if (NULL != session) { + MEM_FREE(session->username); - session->username = memMalloc(nname + 1); - session->username[nname] = 0; - memcpy(session->username, name, nname); + session->username = memMalloc(nname + 1); + session->username[nname] = 0; + memcpy(session->username, name, nname); + } } // vim: set ts=4 sw=4: diff --git a/src/http/worker/process.c b/src/http/worker/process.c index e3c5780..26ccf07 100644 --- a/src/http/worker/process.c +++ b/src/http/worker/process.c @@ -72,42 +72,44 @@ httpWorkerProcess(HttpWorker this, Stream st) */ subjectNotify(this); - if (0 == strcmp("POST", this->current_request->method)) { - /* - * we can't do post requests on our own... - */ - this->current_response = (HttpMessage)httpResponse500(); - } - - if (0 == strcmp("GET", this->current_request->method)) { - char html_asset[2048] = "./assets/html"; - char base_asset[2048] = "./assets"; - char main_asset[] = "/main.html"; - - char * asset_path = base_asset; - char * asset; - char * mime_type; - - if (0 == strcmp("/", this->current_request->path)) { - asset = main_asset; - } else { - asset = this->current_request->path; - } - - mime_type = strrchr(asset, '.'); - if (NULL != mime_type) { - mime_type++; - mime_type = getMimeType(mime_type, strlen(mime_type)); + if (NULL == this->current_response) { + if (0 == strcmp("POST", this->current_request->method)) { + /* + * we can't do post requests on our own... + */ + this->current_response = (HttpMessage)httpResponse500(); } - if (NULL != mime_type && - 0 == memcmp(mime_type, CSTRA("text/html"))) { - asset_path = html_asset; + if (0 == strcmp("GET", this->current_request->method)) { + char html_asset[2048] = "./assets/html"; + char base_asset[2048] = "./assets"; + char main_asset[] = "/main.html"; + + char * asset_path = base_asset; + char * asset; + char * mime_type; + + if (0 == strcmp("/", this->current_request->path)) { + asset = main_asset; + } else { + asset = this->current_request->path; + } + + mime_type = strrchr(asset, '.'); + if (NULL != mime_type) { + mime_type++; + mime_type = getMimeType(mime_type, strlen(mime_type)); + } + + if (NULL != mime_type && + 0 == memcmp(mime_type, CSTRA("text/html"))) { + asset_path = html_asset; + } + + strcat(asset_path, asset); + this->current_response = + httpWorkerGetAsset(this, asset_path); } - - strcat(asset_path, asset); - this->current_response = - httpWorkerGetAsset(this, asset_path); } if (NULL == this->current_response) {