diff --git a/include/http/response.h b/include/http/response.h
index a6588b8..67b206e 100644
--- a/include/http/response.h
+++ b/include/http/response.h
@@ -43,7 +43,9 @@ HttpResponse httpResponse304(
const char *, size_t,
const char *, size_t);
HttpResponse httpResponse404();
+HttpResponse httpResponse403();
HttpResponse httpResponseMe();
+HttpResponse httpResponseLoginForm();
HttpResponse httpResponseRandval(time_t, int);
HttpResponse httpResponseAsset(
const char *,
diff --git a/include/http/worker.h b/include/http/worker.h
index 669f9aa..44c412e 100644
--- a/include/http/worker.h
+++ b/include/http/worker.h
@@ -31,6 +31,7 @@
#include "http/parser.h"
#include "http/writer.h"
#include "cbuf.h"
+#include "session.h"
#ifndef TRUE
@@ -56,6 +57,8 @@ CLASS(HttpWorker) {
HttpParser parser;
HttpWriter writer;
+ Session session;
+ Session * sroot;
};
#endif // __HTTP_WORKER_H__
diff --git a/include/session.h b/include/session.h
new file mode 100644
index 0000000..67571f3
--- /dev/null
+++ b/include/session.h
@@ -0,0 +1,47 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright (C) 2012 Georg Hopp
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#ifndef __SESSION_H__
+#define __SESSION_H__
+
+#include
+#include
+
+#include "class.h"
+
+#define SESSION_LIVETIME 30
+
+
+CLASS(Session) {
+ unsigned long id;
+ time_t livetime;
+
+ char * username;
+};
+
+Session sessionAdd(const Session *, Session);
+Session sessionGet(const Session *, const unsigned long id);
+void sessionDelete(const Session *, const unsigned long id);
+
+#endif // __SESSION_H__
+
+// vim: set ts=4 sw=4:
diff --git a/src/Makefile.am b/src/Makefile.am
index 8970af3..884af16 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -26,6 +26,8 @@ REQ = http/request.c \
RESP = http/response.c \
http/response/304.c \
http/response/404.c \
+ http/response/403.c \
+ http/response/login_form.c \
http/response/asset.c \
http/response/me.c \
http/response/randval.c
@@ -43,6 +45,7 @@ WORKER = http/worker.c \
http/worker/add_common_header.c
HEADER = http/header.c http/header/get.c http/header/add.c \
http/header/to_string.c
+SESSION = session.c session/add.c session/get.c session/delete.c
UTILS = utils/hash.c \
utils/memory.c \
utils/http.c \
@@ -57,6 +60,6 @@ bin_PROGRAMS = testserver
testserver_SOURCES = testserver.c \
$(IFACE) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \
$(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \
- $(UTILS) $(MSGQ)
+ $(UTILS) $(MSGQ) $(SESSION)
testserver_CFLAGS = -Wall -I ../include/
testserver_LDFLAGS = -lrt
diff --git a/src/http/response/403.c b/src/http/response/403.c
new file mode 100644
index 0000000..611f271
--- /dev/null
+++ b/src/http/response/403.c
@@ -0,0 +1,63 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright (C) 2012 Georg Hopp
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+#include
+#include
+
+#include "class.h"
+#include "interface/class.h"
+
+#include "http/response.h"
+#include "http/message.h"
+#include "http/header.h"
+
+
+HttpResponse
+httpResponse403()
+{
+ HttpResponse response;
+ HttpMessage message;
+ char buffer[200];
+ size_t nbuf;
+
+ response = new(HttpResponse, "HTTP/1.1", 403, "Forbidden");
+ message = (HttpMessage)response;
+
+ message->type = HTTP_MESSAGE_BUFFERED;
+ message->nbody = 0;
+ message->body = NULL;
+
+ nbuf = sprintf(buffer, "%d", message->nbody);
+
+ httpHeaderAdd(&(message->header),
+ new(HttpHeader,
+ "Content-Length",
+ sizeof("Content-Length")-1,
+ buffer,
+ nbuf));
+
+ return response;
+}
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/response/login_form.c b/src/http/response/login_form.c
new file mode 100644
index 0000000..8e04b1b
--- /dev/null
+++ b/src/http/response/login_form.c
@@ -0,0 +1,77 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright (C) 2012 Georg Hopp
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+
+#include
+#include
+#include
+#include
+#include
+
+#include "class.h"
+#include "interface/class.h"
+
+#include "http/response.h"
+#include "http/message.h"
+#include "http/header.h"
+
+#define RESP_DATA ""
+
+HttpResponse
+httpResponseLoginForm()
+{
+ char buffer[200];
+ HttpResponse response;
+ HttpMessage message;
+ size_t nbuf;
+
+ response = new(HttpResponse, "HTTP/1.1", 200, "OK");
+ message = (HttpMessage)response;
+
+ httpHeaderAdd(&(message->header),
+ new(HttpHeader,
+ "Content-Type",
+ sizeof("Content-Type")-1,
+ "text/html",
+ sizeof("text/html")-1));
+
+ message->type = HTTP_MESSAGE_BUFFERED;
+
+ message->nbody = sizeof(RESP_DATA)-1;
+ message->body = malloc(message->nbody);
+ memcpy(message->body, RESP_DATA, message->nbody);
+
+ nbuf = sprintf(buffer, "%d", message->nbody);
+
+ httpHeaderAdd(&(message->header),
+ new(HttpHeader,
+ "Content-Length",
+ sizeof("Content-Length")-1,
+ buffer,
+ nbuf));
+
+ return response;
+}
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/response/me.c b/src/http/response/me.c
index 6a49dda..3c6a333 100644
--- a/src/http/response/me.c
+++ b/src/http/response/me.c
@@ -60,15 +60,31 @@
"$(document).ready(function() {" \
"var intervalId;" \
"var vnext = 0;" \
+ "var clickclose = function() {" \
+ "clearInterval(intervalId);" \
+ "vnext = 0;" \
+ "$(\"#randval\").addClass(\"hide\");" \
+ "};" \
"var counter = function() {" \
"if (0 >= vnext) {" \
- "$.getJSON(\"/randval/\", function(data) {" \
+ "$.getJSON(\"/randval/\", function(data, xhr) {" \
"var date = new Date(data.ctime * 1000);" \
"$(\"#ctime\").empty().append(date.toString());" \
"vnext = data.vnext;" \
"$(\"#value\").empty().append(data.value);" \
"$(\"#vnext\").empty().append(vnext);" \
+ "$(\"#randval\").on(\"click\", clickclose);" \
+ "}).error(function(event, request, settings) {" \
+ "clearInterval(intervalId);" \
+ "$.get(\"/login/\", function(data) {" \
+ "$(\"#randval\")" \
+ ".off(\"click\", clickclose)" \
+ ".empty().append(data);" \
+ "});" \
"});" \
+ "if ($(\"#randval\").hasClass(\"hide\")) {" \
+ "$(\"#randval\").removeClass(\"hide\");" \
+ "}" \
"} else {" \
"vnext--;" \
"$(\"#vnext\").empty().append(vnext);" \
@@ -83,12 +99,6 @@
"});" \
"$(\"a\").click(function() {" \
"intervalId = setInterval(counter, 1000);" \
- "$(\"#randval\").removeClass(\"hide\");" \
- "});" \
- "$(\"#randval\").click(function() {" \
- "clearInterval(intervalId);" \
- "vnext = 0;" \
- "$(\"#randval\").addClass(\"hide\");" \
"});" \
"});" \
"" \
@@ -103,6 +113,7 @@
"" \
"" \
"
Testpage
" \
+ "Welcome %s
" \
"

" \
"
Link" \
"
" \
@@ -111,7 +122,7 @@
"