diff --git a/.gitignore b/.gitignore
index 9c79b2b..6b8107e 100644
--- a/.gitignore
+++ b/.gitignore
@@ -4,10 +4,9 @@
.deps/
Makefile
Makefile.in
+/config*
m4/
/docs/
-/config.*
-/configure
/INSTALL
*.m4
/autom4te.cache/
diff --git a/TODO b/TODO
index e69de29..6bfe265 100644
--- a/TODO
+++ b/TODO
@@ -0,0 +1,8 @@
+VERY BIG TODO:
+- right now i will use long polling ajax calls when feedback from to the client
+ is needed. In the long term this should be changed to websockets (ws). But
+ right now ws specification is not final anyway. :)
+
+- handle errors after all system call...especially open, close, etc.
+
+- IPV6 support
diff --git a/assets/html/main.html b/assets/html/main.html
new file mode 100644
index 0000000..a61e444
--- /dev/null
+++ b/assets/html/main.html
@@ -0,0 +1,50 @@
+
+
+
+
+ My own little Web-App
+
+
+
+
+
+
+
+
+
+ Session:
+
+
+
+
+
+
+
+ Value created at:
+
+ Next value in:
+
+ Value:
+
+
+
Testpage
+ Welcome
!!!
+
+
+
+
+
+
+
+
diff --git a/assets/waldschrat.jpg b/assets/image/waldschrat.jpg
similarity index 100%
rename from assets/waldschrat.jpg
rename to assets/image/waldschrat.jpg
diff --git a/assets/js/init.js b/assets/js/init.js
new file mode 100644
index 0000000..b36c539
--- /dev/null
+++ b/assets/js/init.js
@@ -0,0 +1,37 @@
+var sess = null;
+
+$(document).ready(function() {
+ var sval = new ServerVal("#randval");
+
+ sess = new Session("#sessinfo");
+
+ $(window).focus(function() {
+ $.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
+ });
+
+ $("ul#menu li:eq(0)").click(function() {
+ sval.start();
+ });
+
+ $("ul#menu li:eq(1)").click(function() {
+ $.getJSON("/sess/", $.proxy(sess.loadJSON, sess));
+ });
+
+ $("ul#menu li:eq(2)").click(function() {
+ $("#login").removeClass("hide");
+ });
+
+ $("#randval").click(function() {
+ sval.stop();
+ });
+
+ $("#login form").submit(function(event) {
+ event.preventDefault();
+ $.post("/login/",
+ $("#login form").serialize(),
+ $.proxy(sess.loadJSON, sess));
+ $("#login").addClass("hide");
+ });
+});
+
+// vim: set ts=4 sw=4:
diff --git a/assets/jquery-1.7.1.js b/assets/js/jquery-1.7.1.js
similarity index 100%
rename from assets/jquery-1.7.1.js
rename to assets/js/jquery-1.7.1.js
diff --git a/assets/jquery-1.7.1.min.js b/assets/js/jquery-1.7.1.min.js
similarity index 100%
rename from assets/jquery-1.7.1.min.js
rename to assets/js/jquery-1.7.1.min.js
diff --git a/assets/js/serverval.js b/assets/js/serverval.js
new file mode 100644
index 0000000..bdb848b
--- /dev/null
+++ b/assets/js/serverval.js
@@ -0,0 +1,78 @@
+function ServerVal(eId)
+{
+ this.eId = eId;
+ this.eCtime = eId + " span:eq(1)";
+ this.eVnext = eId + " span:eq(2)";
+ this.eValue = eId + " span:eq(3)";
+
+ this.interval = null;
+ this.ctime = null;
+ this.vnext = 0;
+ this.value = null;
+}
+
+ServerVal.prototype.loadJSON = function(data)
+{
+ this.ctime = new Date(data.ctime * 1000);
+ this.vnext = data.vnext;
+ this.value = data.value;
+
+ $.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
+ this.show();
+}
+
+ServerVal.prototype.show = function()
+{
+ $(this.eCtime).empty().append(this.ctime.toString());
+ $(this.eVnext).empty().append(this.vnext);
+ $(this.eValue).empty().append(this.value);
+
+ if ($(this.eId).hasClass("hide")) {
+ $(this.eId).removeClass("hide");
+ }
+}
+
+ServerVal.prototype.start = function()
+{
+ if (null === this.interval) {
+ this.interval = setInterval($.proxy(this.process, this), 1000);
+ }
+}
+
+ServerVal.prototype.process = function()
+{
+ if (0 >= this.vnext) {
+ $.getJSON("/randval/", $.proxy(this.loadJSON, this))
+ .error($.proxy(function(xhr) {
+ this.stop();
+ $("#msg").append("AJAX error (" + xhr.status + "): ");
+ switch(xhr.status) {
+ case 403:
+ $("#msg").append(
+ "Please log in to access this function. ");
+ break;
+
+ default:
+ $("#msg").append(
+ "Unhandled - " + xhr.responseText + " ");
+ break;
+ }
+ }, this));
+ }
+
+ else {
+ this.vnext--;
+ $(this.eVnext).empty().append(this.vnext);
+ }
+}
+
+ServerVal.prototype.stop = function()
+{
+ $(this.eId).addClass("hide");
+
+ clearInterval(this.interval);
+ this.interval = null;
+ this.vnext = 0;
+}
+
+// vim: set ts=4 sw=4:
diff --git a/assets/js/session.js b/assets/js/session.js
new file mode 100644
index 0000000..0c4350b
--- /dev/null
+++ b/assets/js/session.js
@@ -0,0 +1,78 @@
+function Session(sId)
+{
+ this.eSid = $(sId + " span");
+ this.canvas = $(sId + " canvas").get(0);
+ this.context = this.canvas.getContext("2d");
+
+ this.id = "none"
+ this.timeout = 0;
+ this.timeleft = 0;
+ this.username = "";
+ this.interval = null;
+
+ this.draw();
+}
+
+Session.prototype.loadJSON = function(data)
+{
+ this.stop();
+
+ this.id = ("0" == data.id)? "none" : data.id;
+ this.timeout = data.timeout * 10;
+ this.timeleft = data.timeleft * 10;
+ this.username = data.username;
+
+ this.eSid.empty().append(this.id);
+ $("#main span:eq(0)").empty().append(" " + this.username);
+
+ this.draw();
+ if (0 < this.timeleft)
+ this.start();
+}
+
+Session.prototype.draw = function()
+{
+ this.context.fillStyle = "rgb(255, 0, 0)";
+ this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
+
+ this.context.fillStyle = "rgb(0, 255, 0)";
+ this.context.fillRect(0, 0,
+ this.canvas.width / this.timeout * this.timeleft,
+ this.canvas.height);
+}
+
+Session.prototype.start = function()
+{
+ if (null === this.interval) {
+ this.interval = setInterval($.proxy(this.process, this), 100);
+ }
+}
+
+Session.prototype.process = function()
+{
+ if (0 >= this.timeleft) {
+ this.stop();
+ }
+
+ else {
+ this.timeleft--;
+ this.draw();
+ }
+}
+
+Session.prototype.stop = function()
+{
+ clearInterval(this.interval);
+ this.interval = null;
+ this.id = "none";
+ this.timeout = 0;
+ this.timeleft = 0;
+ this.username = "";
+
+ this.eSid.empty().append(this.id);
+ $("#main span:eq(0)").empty().append(" " + this.username);
+
+ this.draw();
+}
+
+// vim: set ts=4 sw=4:
diff --git a/assets/style/common.css b/assets/style/common.css
new file mode 100644
index 0000000..bd3bab4
--- /dev/null
+++ b/assets/style/common.css
@@ -0,0 +1,58 @@
+div#randval {
+ left: 200px;
+ top: 100px;
+ padding: 10px;
+ position: fixed;
+ background-color: white;
+ border: 1px solid black;
+ border-radius: 10px;
+}
+
+div#login {
+ padding: 5px;
+ position: fixed;
+ background-color: white;
+ border: 1px solid black;
+ border-radius: 10px;
+}
+
+div.hide {
+ top: -500px !important;
+}
+
+.small {
+ font-size: small;
+}
+
+.x-small {
+ font-size: x-small;
+}
+
+ul#menu {
+ list-style: none inside;
+ margin: 0px;
+ padding: 1px 0px 0px;
+ border-bottom: 1px solid #7b0b2b;
+ display: inline-block;
+ width: 100%;
+}
+
+ul#menu li {
+ padding: 2px;
+ border-top-left-radius: 10px;
+ border-top-right-radius: 10px;
+ border-top: 1px solid #7b0b2b;
+ border-left: 1px solid #7b0b2b;
+ border-right: 1px solid #7b0b2b;
+ text-align: center;
+ cursor: pointer;
+
+ float: left;
+ margin-right: 1px;
+}
+
+div#sessinfo canvas {
+ border: 1px solid black;
+}
+
+/* vim: set st=4 sw=4: */
diff --git a/include/auth.h b/include/auth.h
new file mode 100644
index 0000000..a83eb51
--- /dev/null
+++ b/include/auth.h
@@ -0,0 +1,45 @@
+/**
+ * \file
+ * Authenticatio module factory
+ *
+ * A factory to get a specific authentication module.
+ * An authentication module is a class that implement the Auth interface.
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __AUTH_H__
+#define __AUTH_H__
+
+#include "class.h"
+#include "auth/ldap.h"
+
+typedef enum e_AuthModule {
+ AUTH_LDAP = 0
+} AuthModule;
+
+CLASS(Auth) {
+};
+
+void * authCreateById(Auth, int);
+AuthLdap authCreateLdap(Auth);
+
+#endif // __AUTH_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/auth/ldap.h b/include/auth/ldap.h
new file mode 100644
index 0000000..4c6e98c
--- /dev/null
+++ b/include/auth/ldap.h
@@ -0,0 +1,41 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __AUTH_LDAP_H__
+#define __AUTH_LDAP_H__
+
+#include
+#include
+
+#include "class.h"
+
+CLASS(AuthLdap) {
+ LDAP * ldap;
+ char * url;
+ char * base_dn;
+ int version;
+ size_t nbase_dn;
+};
+
+#endif // __AUTH_LDAP_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/cbuf.h b/include/cbuf.h
index 053b836..dd2de94 100644
--- a/include/cbuf.h
+++ b/include/cbuf.h
@@ -11,7 +11,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/class.h b/include/class.h
index efecb79..6f34fe9 100644
--- a/include/class.h
+++ b/include/class.h
@@ -8,7 +8,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/commons.h b/include/commons.h
index 876df6a..7f354f7 100644
--- a/include/commons.h
+++ b/include/commons.h
@@ -1,3 +1,25 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __COMMONS_H__
#define __COMMONS_H__
@@ -5,6 +27,22 @@
#define TRUE 1
#define FALSE 0
+#ifndef MAX
+# define MAX(a,b) ((a)>(b)? (a) : (b))
+#endif
+
+#ifndef MIN
+# define MIN(a,b) ((a)<(b)? (a) : (b))
+#endif
+
+#define SWAP_FUN(a, b) ((a)^=(b),(b)^=(a),(a)^=(b))
+
+#define SWAP(type, a, b) do { \
+ type tmp = (a); \
+ (a) = (b); \
+ (b) = tmp; \
+} while(0);
+
#endif // __COMMONS_H__
// vim: set ts=4 sw=4:
diff --git a/include/credential.h b/include/credential.h
new file mode 100644
index 0000000..945f780
--- /dev/null
+++ b/include/credential.h
@@ -0,0 +1,54 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __CREDENTIAL_H__
+#define __CREDENTIAL_H__
+
+#include
+
+#include "class.h"
+
+#define CRED_PWD(c) (((c)->cred).pwd)
+
+typedef enum e_CredentialType {
+ CRED_PASSWORD = 0
+} CredentialType;
+
+
+CLASS(Credential) {
+ CredentialType type;
+
+ union {
+
+ struct {
+ char * user;
+ size_t nuser;
+ char * pass;
+ size_t npass;
+ } pwd;
+
+ } cred;
+};
+
+#endif // __CREDENTIAL_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/hash.h b/include/hash.h
new file mode 100644
index 0000000..4c6eb92
--- /dev/null
+++ b/include/hash.h
@@ -0,0 +1,42 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __HASH_H__
+#define __HASH_H__
+
+#include
+
+#include "class.h"
+
+
+CLASS(Hash) {
+ void * root;
+};
+
+void * hashAdd(Hash, void *);
+void * hashDelete(Hash, const char *, size_t);
+void * hashGet(Hash, const char *, size_t);
+void hashEach(Hash, void (*)(const void*));
+
+#endif // __HASH_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/hash_value.h b/include/hash_value.h
new file mode 100644
index 0000000..17a4f6c
--- /dev/null
+++ b/include/hash_value.h
@@ -0,0 +1,42 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __HASH_VALUE_H__
+#define __HASH_VALUE_H__
+
+#include
+
+#include "class.h"
+
+CLASS(HashValue) {
+ unsigned long hash;
+
+ char * key;
+ void * value;
+
+ size_t nkey;
+ size_t nvalue;
+};
+
+#endif // __HASH_VALUE_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/http/cookie.h b/include/http/cookie.h
new file mode 100644
index 0000000..358be49
--- /dev/null
+++ b/include/http/cookie.h
@@ -0,0 +1,51 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * - Copyright © 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 __HTTP_COOKIE_H__
+#define __HTTP_COOKIE_H__
+
+#include
+#include
+
+#include "class.h"
+
+CLASS(HttpCookie) {
+ unsigned long hash;
+
+ char * key;
+ char * value;
+ char * domain;
+ char * path;
+
+ time_t expires;
+ time_t max_age;
+
+ size_t nkey;
+ size_t nvalue;
+};
+
+char * httpCookieToString(HttpCookie);
+HttpCookie httpStringToCookie(const char *);
+
+#endif // __HTTP_COOKIE_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/http/header.h b/include/http/header.h
index eac9dd8..865ffd7 100644
--- a/include/http/header.h
+++ b/include/http/header.h
@@ -6,7 +6,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -41,8 +41,6 @@ CLASS(HttpHeader) {
size_t size; //!< full size of this header
};
-HttpHeader httpHeaderAdd(const HttpHeader *, HttpHeader);
-HttpHeader httpHeaderGet(const HttpHeader *, const char *, size_t);
size_t httpHeaderToString(HttpHeader, char *);
#endif // __HTTP_HEADER_H__
diff --git a/include/http/message.h b/include/http/message.h
index 8a51e16..b85ec93 100644
--- a/include/http/message.h
+++ b/include/http/message.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -25,7 +25,7 @@
#define __HTTP_MESSAGE__
#include "class.h"
-#include "http/header.h"
+#include "hash.h"
#include "stream.h"
typedef enum e_HttpMessageType {
@@ -37,7 +37,8 @@ typedef enum e_HttpMessageType {
CLASS(HttpMessage) {
char * version;
- HttpHeader header;
+ Hash header;
+ Hash cookies;
HttpMessageType type;
Stream handle;
diff --git a/include/http/message/queue.h b/include/http/message/queue.h
index b4d6052..7b024e0 100644
--- a/include/http/message/queue.h
+++ b/include/http/message/queue.h
@@ -7,7 +7,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/http/parser.h b/include/http/parser.h
index 81a16c0..7ca76e2 100644
--- a/include/http/parser.h
+++ b/include/http/parser.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -58,9 +58,12 @@ CLASS(HttpParser) {
};
ssize_t httpParserParse(void *, Stream);
+void httpParserRequestVars(HttpParser);
void httpParserHeader(HttpParser, const char *, const char *);
void httpParserNewMessage(HttpParser, const char *, const char * lend);
size_t httpParserBody(HttpParser, const char *, size_t);
+void httpParserRequestVars(HttpParser);
+void httpParserPostVars(HttpParser);
#endif // __HTTP_PARSER_H__
diff --git a/include/http/request.h b/include/http/request.h
index ba1f979..45eac76 100644
--- a/include/http/request.h
+++ b/include/http/request.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -26,6 +26,7 @@
#include "class.h"
#include "http/message.h"
+#include "hash.h"
#define N_HTTP_METHOD 8
@@ -36,6 +37,11 @@ CLASS(HttpRequest) {
char * method;
char * uri;
+ char * path;
+
+ Hash get;
+ Hash post;
+ Hash cookies;
};
int httpRequestHasValidMethod(HttpRequest);
diff --git a/include/http/response.h b/include/http/response.h
index 67b206e..98818ff 100644
--- a/include/http/response.h
+++ b/include/http/response.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -29,6 +29,7 @@
#include "class.h"
#include "http/message.h"
+#include "session.h"
CLASS(HttpResponse) {
@@ -47,6 +48,7 @@ HttpResponse httpResponse403();
HttpResponse httpResponseMe();
HttpResponse httpResponseLoginForm();
HttpResponse httpResponseRandval(time_t, int);
+HttpResponse httpResponseSession(Session);
HttpResponse httpResponseAsset(
const char *,
const char *, size_t,
diff --git a/include/http/worker.h b/include/http/worker.h
index 3ffc348..cfc7255 100644
--- a/include/http/worker.h
+++ b/include/http/worker.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -52,6 +52,8 @@ CLASS(HttpWorker) {
HttpWriter writer;
Session session;
Session * sroot;
+
+ void * auth;
};
#endif // __HTTP_WORKER_H__
diff --git a/include/http/writer.h b/include/http/writer.h
index 9c1d143..3fb91bb 100644
--- a/include/http/writer.h
+++ b/include/http/writer.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * - Copyright (C) 2012 Georg Hopp
+ * - Copyright © 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
diff --git a/include/interface.h b/include/interface.h
index f3e3c56..bebe14c 100644
--- a/include/interface.h
+++ b/include/interface.h
@@ -8,7 +8,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/interface/auth.h b/include/interface/auth.h
new file mode 100644
index 0000000..ed552e7
--- /dev/null
+++ b/include/interface/auth.h
@@ -0,0 +1,49 @@
+/**
+ * \file
+ * The authentication interface.
+ *
+ * This is the authentication interface. It's only pupose is to
+ * authenticate someone or somewhat. It is called AUTH.
+ * The concrete access rights are managed within a class called ACL.
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __INTERFACE_AUTH_H__
+#define __INTERFACE_AUTH_H__
+
+#include
+
+#include "interface.h"
+#include "credential.h"
+
+typedef int (* fptr_authenticate)(void *, Credential);
+
+extern const struct interface i_Auth;
+
+struct i_Auth {
+ const struct interface * const _;
+ fptr_authenticate authenticate;
+};
+
+extern int authenticate(void *, Credential);
+
+#endif // __INTERFACE_AUTH_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/interface/class.h b/include/interface/class.h
index 748b16b..b0fd2ad 100644
--- a/include/interface/class.h
+++ b/include/interface/class.h
@@ -7,7 +7,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/interface/hashable.h b/include/interface/hashable.h
new file mode 100644
index 0000000..18b9ae3
--- /dev/null
+++ b/include/interface/hashable.h
@@ -0,0 +1,45 @@
+/**
+ * \file
+ * The logger interface.
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __INTERFACE_HASHABLE_H__
+#define __INTERFACE_HASHABLE_H__
+
+#include "interface.h"
+
+typedef unsigned long (* fptr_hashableGetHash)(void *);
+typedef void (* fptr_hashableHandleDouble)(void *, void *);
+
+extern const struct interface i_Hashable;
+
+struct i_Hashable {
+ const struct interface * const _;
+ fptr_hashableGetHash getHash;
+ fptr_hashableHandleDouble handleDouble;
+};
+
+extern unsigned long hashableGetHash(void *);
+extern void hashableHandleDouble(void *, void *);
+
+#endif // __INTERFACE_HASHABLE_H__
+
+// vim: set ts=4 sw=4:
diff --git a/include/interface/http_intro.h b/include/interface/http_intro.h
index 81b6afe..60edf93 100644
--- a/include/interface/http_intro.h
+++ b/include/interface/http_intro.h
@@ -7,7 +7,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/interface/logger.h b/include/interface/logger.h
index 769ecb4..c55876c 100644
--- a/include/interface/logger.h
+++ b/include/interface/logger.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/interface/observer.h b/include/interface/observer.h
index ffb1840..077823c 100644
--- a/include/interface/observer.h
+++ b/include/interface/observer.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/interface/stream_reader.h b/include/interface/stream_reader.h
index 1478e5d..e353a12 100644
--- a/include/interface/stream_reader.h
+++ b/include/interface/stream_reader.h
@@ -6,7 +6,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/interface/stream_writer.h b/include/interface/stream_writer.h
index 3229705..bbca388 100644
--- a/include/interface/stream_writer.h
+++ b/include/interface/stream_writer.h
@@ -6,7 +6,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/interface/subject.h b/include/interface/subject.h
index 62c3b3a..16ef044 100644
--- a/include/interface/subject.h
+++ b/include/interface/subject.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/logger.h b/include/logger.h
index 26ee2bf..a9577db 100644
--- a/include/logger.h
+++ b/include/logger.h
@@ -6,7 +6,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/server.h b/include/server.h
index 198aac1..0468e39 100644
--- a/include/server.h
+++ b/include/server.h
@@ -7,7 +7,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/session.h b/include/session.h
index 67571f3..02f7aec 100644
--- a/include/session.h
+++ b/include/session.h
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/socket.h b/include/socket.h
index af68ac9..7e1442f 100644
--- a/include/socket.h
+++ b/include/socket.h
@@ -6,7 +6,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/stream.h b/include/stream.h
index 0bae954..d7cffed 100644
--- a/include/stream.h
+++ b/include/stream.h
@@ -1,3 +1,25 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __STREAM_H__
#define __STREAM_H__
diff --git a/include/utils/hash.h b/include/utils/hash.h
index a247590..27c36c5 100644
--- a/include/utils/hash.h
+++ b/include/utils/hash.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/utils/http.h b/include/utils/http.h
index 38d4511..5e877bb 100644
--- a/include/utils/http.h
+++ b/include/utils/http.h
@@ -1,3 +1,25 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 __UTILS_HTTP_H__
#define __UTILS_HTTP_H__
diff --git a/include/utils/memory.h b/include/utils/memory.h
index 4755cac..2e9b65a 100644
--- a/include/utils/memory.h
+++ b/include/utils/memory.h
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/include/utils/signalHandling.h b/include/utils/signalHandling.h
index 269d1fe..cd1c973 100644
--- a/include/utils/signalHandling.h
+++ b/include/utils/signalHandling.h
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/Makefile.am b/src/Makefile.am
index 7830b46..3abd3d2 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -6,6 +6,8 @@ IFACE = interface/class.c interface/stream_reader.c interface/logger.c \
interface/subject.c interface/observer.c interface.c
SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c
STREAM = stream.c stream/read.c stream/write.c
+HASH = hash.c hash/add.c hash/get.c hash/delete.c \
+ hash/each.c interface/hashable.c hash_value.c
SERVER = server.c server/run.c server/close_conn.c server/poll.c \
server/handle_accept.c server/read.c server/write.c
LOGGER = logger.c logger/stderr.c logger/syslog.c
@@ -30,13 +32,15 @@ RESP = http/response.c \
http/response/403.c \
http/response/login_form.c \
http/response/asset.c \
- http/response/me.c \
- http/response/randval.c
+ http/response/randval.c \
+ http/response/session.c
PARSER = http/parser.c \
http/parser/parse.c \
http/parser/new_message.c \
http/parser/header.c \
- http/parser/body.c
+ http/parser/body.c \
+ http/parser/request_vars.c \
+ http/parser/post_vars.c
WRITER = http/writer.c \
http/writer/write.c
WORKER = http/worker.c \
@@ -44,7 +48,7 @@ WORKER = http/worker.c \
http/worker/write.c \
http/worker/get_asset.c \
http/worker/add_common_header.c
-HEADER = http/header.c http/header/get.c http/header/add.c \
+HEADER = http/header.c \
http/header/to_string.c
SESSION = session.c session/add.c session/get.c session/delete.c
UTILS = utils/hash.c \
@@ -52,15 +56,16 @@ UTILS = utils/hash.c \
utils/http.c \
utils/daemonize.c \
utils/signalHandling.c
+AUTH = interface/auth.c auth/ldap.c credential.c
AM_CFLAGS = -Wall -I ../include/
-bin_PROGRAMS = taskrambler
+bin_PROGRAMS = webgameserver
-taskrambler_SOURCES = taskrambler.c \
+webgameserver_SOURCES = webgameserver.c \
$(IFACE) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \
$(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \
- $(UTILS) $(MSGQ) $(SESSION) $(STREAM)
-taskrambler_CFLAGS = -Wall -I ../include/
-taskrambler_LDFLAGS = -lrt -lssl
+ $(UTILS) $(MSGQ) $(SESSION) $(STREAM) $(HASH) $(AUTH)
+webgameserver_CFLAGS = -Wall -I ../include/
+webgameserver_LDFLAGS = -lrt -lssl -lldap
diff --git a/src/auth/ldap.c b/src/auth/ldap.c
new file mode 100644
index 0000000..fb7bf0e
--- /dev/null
+++ b/src/auth/ldap.c
@@ -0,0 +1,110 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "auth/ldap.h"
+#include "class.h"
+#include "credential.h"
+#include "interface/class.h"
+#include "interface/auth.h"
+
+#include "utils/memory.h"
+#include "commons.h"
+
+static
+int
+authLdapCtor(void * _this, va_list * params)
+{
+ AuthLdap this = _this;
+ char * url = va_arg(*params, char*);
+ char * base_dn;
+
+ this->url = malloc(strlen(url) + 1);
+ strcpy(this->url, url);
+
+ this->version = 3;
+
+ base_dn = va_arg(* params, char *);
+ this->nbase_dn = va_arg(* params, size_t);
+
+ this->base_dn = malloc(this->nbase_dn + 1);
+ this->base_dn[this->nbase_dn] = 0;
+ memcpy(this->base_dn, base_dn, this->nbase_dn);
+
+ return 0;
+}
+
+static
+void
+authLdapDtor(void * _this)
+{
+ AuthLdap this = _this;
+
+ FREE(this->base_dn);
+ FREE(this->url);
+}
+
+static
+int
+authLdapAuthenticate(void * _this, Credential cred)
+{
+ AuthLdap this = _this;
+ char who[256];
+ char * who_ptr = who;
+ int ldap_err;
+
+ if (CRED_PASSWORD != cred->type) {
+ return FALSE;
+ }
+
+ ldap_initialize(&(this->ldap), this->url);
+ ldap_set_option(this->ldap, LDAP_OPT_PROTOCOL_VERSION, &(this->version));
+
+ memcpy(who_ptr, "cn=", sizeof("cn=") - 1);
+ who_ptr += sizeof("cn=") - 1;
+ memcpy(who_ptr, CRED_PWD(cred).user, CRED_PWD(cred).nuser);
+ who_ptr += CRED_PWD(cred).nuser;
+ *who_ptr++ = ',';
+ memcpy(who_ptr, this->base_dn, this->nbase_dn);
+ who_ptr[this->nbase_dn] = 0;
+
+ ldap_err = ldap_simple_bind_s(this->ldap, who, CRED_PWD(cred).pass);
+ if (0 == ldap_err) {
+ ldap_unbind_s(this->ldap);
+ //! \todo here we need to get and return the user id
+ return TRUE;
+ }
+
+ fprintf(stderr, "%s\n", ldap_err2string(ldap_err));
+ return FALSE;
+}
+
+INIT_IFACE(Class, authLdapCtor, authLdapDtor, NULL);
+INIT_IFACE(Auth, authLdapAuthenticate);
+CREATE_CLASS(AuthLdap, NULL, IFACE(Class), IFACE(Auth));
+
+// vim: set ts=4 sw=4:
diff --git a/src/cbuf.c b/src/cbuf.c
index 4d05fa5..fdf77db 100644
--- a/src/cbuf.c
+++ b/src/cbuf.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/addr_index.c b/src/cbuf/addr_index.c
index f66df81..69eb5e6 100644
--- a/src/cbuf/addr_index.c
+++ b/src/cbuf/addr_index.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/empty.c b/src/cbuf/empty.c
index 02196de..b41a6a3 100644
--- a/src/cbuf/empty.c
+++ b/src/cbuf/empty.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/get_data.c b/src/cbuf/get_data.c
index c5191f3..b41f5b8 100644
--- a/src/cbuf/get_data.c
+++ b/src/cbuf/get_data.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/get_free.c b/src/cbuf/get_free.c
index eb747fd..1117081 100644
--- a/src/cbuf/get_free.c
+++ b/src/cbuf/get_free.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/get_line.c b/src/cbuf/get_line.c
index 526c22a..647722f 100644
--- a/src/cbuf/get_line.c
+++ b/src/cbuf/get_line.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/get_read.c b/src/cbuf/get_read.c
index 6464b08..cbbbdc3 100644
--- a/src/cbuf/get_read.c
+++ b/src/cbuf/get_read.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/get_write.c b/src/cbuf/get_write.c
index dbd2dc3..02f1a55 100644
--- a/src/cbuf/get_write.c
+++ b/src/cbuf/get_write.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/inc_read.c b/src/cbuf/inc_read.c
index 869a780..bfd6dab 100644
--- a/src/cbuf/inc_read.c
+++ b/src/cbuf/inc_read.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/inc_write.c b/src/cbuf/inc_write.c
index 1221493..f329813 100644
--- a/src/cbuf/inc_write.c
+++ b/src/cbuf/inc_write.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/is_empty.c b/src/cbuf/is_empty.c
index 799ced6..849c032 100644
--- a/src/cbuf/is_empty.c
+++ b/src/cbuf/is_empty.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/is_locked.c b/src/cbuf/is_locked.c
index fa5a2c3..097bd69 100644
--- a/src/cbuf/is_locked.c
+++ b/src/cbuf/is_locked.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/lock.c b/src/cbuf/lock.c
index e1579e4..df5256f 100644
--- a/src/cbuf/lock.c
+++ b/src/cbuf/lock.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/memchr.c b/src/cbuf/memchr.c
index 58894fa..0183351 100644
--- a/src/cbuf/memchr.c
+++ b/src/cbuf/memchr.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/read.c b/src/cbuf/read.c
index a68eb07..1e49fa0 100644
--- a/src/cbuf/read.c
+++ b/src/cbuf/read.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/release.c b/src/cbuf/release.c
index 8a3edac..eb32a73 100644
--- a/src/cbuf/release.c
+++ b/src/cbuf/release.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/set_data.c b/src/cbuf/set_data.c
index 0e3055e..514d052 100644
--- a/src/cbuf/set_data.c
+++ b/src/cbuf/set_data.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/skip_non_alpha.c b/src/cbuf/skip_non_alpha.c
index 72ef3aa..395c296 100644
--- a/src/cbuf/skip_non_alpha.c
+++ b/src/cbuf/skip_non_alpha.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/cbuf/write.c b/src/cbuf/write.c
index 01c26b1..03820aa 100644
--- a/src/cbuf/write.c
+++ b/src/cbuf/write.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/credential.c b/src/credential.c
new file mode 100644
index 0000000..873877b
--- /dev/null
+++ b/src/credential.c
@@ -0,0 +1,86 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "credential.h"
+#include "class.h"
+#include "interface/class.h"
+
+#include "utils/memory.h"
+
+static
+int
+credentialCtor(void * _this, va_list * params)
+{
+ Credential this = _this;
+
+ this->type = va_arg(* params, CredentialType);
+
+ switch(this->type) {
+ case CRED_PASSWORD:
+ {
+ char * user, *pass;
+
+ user = va_arg(* params, char*);
+ CRED_PWD(this).nuser = va_arg(* params, size_t);
+ pass = va_arg(* params, char*);
+ CRED_PWD(this).npass = va_arg(* params, size_t);
+
+ CRED_PWD(this).user = malloc(CRED_PWD(this).nuser + 1);
+ CRED_PWD(this).user[CRED_PWD(this).nuser] = 0;
+ memcpy(CRED_PWD(this).user, user, CRED_PWD(this).nuser);
+
+ CRED_PWD(this).pass = malloc(CRED_PWD(this).npass + 1);
+ CRED_PWD(this).pass[CRED_PWD(this).npass] = 0;
+ memcpy(CRED_PWD(this).pass, pass, CRED_PWD(this).npass);
+ }
+ break;
+
+ default:
+ return -1;
+ }
+
+ return 0;
+}
+
+static
+void
+credentialDtor(void * _this)
+{
+ Credential this = _this;
+
+ switch(this->type) {
+ case CRED_PASSWORD:
+ FREE(CRED_PWD(this).user);
+ FREE(CRED_PWD(this).pass);
+ break;
+ }
+}
+
+INIT_IFACE(Class, credentialCtor, credentialDtor, NULL);
+CREATE_CLASS(Credential, NULL, IFACE(Class));
+
+// vim: set ts=4 sw=4:
diff --git a/src/hash.c b/src/hash.c
new file mode 100644
index 0000000..8956144
--- /dev/null
+++ b/src/hash.c
@@ -0,0 +1,64 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 .
+ */
+
+#define _GNU_SOURCE
+
+#include
+#include
+
+#include "hash.h"
+#include "class.h"
+#include "interface/class.h"
+
+static
+int
+hashCtor(void * _this, va_list * params)
+{
+ return 0;
+}
+
+static
+inline
+void
+tDelete(void * node)
+{
+ delete(node);
+}
+
+static
+void
+hashDtor(void * _this)
+{
+ Hash this = _this;
+
+ /**
+ * this is a GNU extension...anyway on most non
+ * GNUish systems i would not use tsearch anyway
+ * as the trees will be unbalanced.
+ */
+ tdestroy(this->root, tDelete);
+}
+
+INIT_IFACE(Class, hashCtor, hashDtor, NULL);
+CREATE_CLASS(Hash, NULL, IFACE(Class));
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/header/add.c b/src/hash/add.c
similarity index 50%
rename from src/http/header/add.c
rename to src/hash/add.c
index b8eda6a..5226862 100644
--- a/src/http/header/add.c
+++ b/src/hash/add.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -21,49 +21,34 @@
*/
#include
-#include
-#include
-#include
-#include "class.h"
+#include "hash.h"
+#include "interface/hashable.h"
#include "interface/class.h"
-#include "http/header.h"
-#include "utils/hash.h"
static
inline
int
-comp(const void * _a, const void * _b)
+hashAddComp(const void * a, const void * b)
{
- HttpHeader a = (HttpHeader)_a;
- HttpHeader b = (HttpHeader)_b;
- return (a->hash < b->hash)? -1 : (a->hash > b->hash)? 1 : 0;
+ return hashableGetHash((void*)b) - hashableGetHash((void*)a);
}
-HttpHeader
-httpHeaderAdd(const HttpHeader * root, HttpHeader header)
+void *
+hashAdd(Hash this, void * operand)
{
- HttpHeader * _found = tsearch(header, (void **)root, comp);
- HttpHeader found;
+ void * found = tsearch(operand, &(this->root), hashAddComp);
- if (NULL == _found) {
+ if (NULL == found) {
return NULL;
}
- found = *_found;
-
- if (found != header) {
- if (found->cvalue >= N_VALUES) {
- return NULL;
- }
- (found->nvalue)[found->cvalue] = (header->nvalue)[0];
- (found->value)[(found->cvalue)++] = (header->value)[0];
- found->size += header->size;
- (header->value)[0] = NULL;
- delete(header);
+ if (operand != *(void**)found) {
+ hashableHandleDouble(*(void**)found, operand);
+ delete(operand);
}
- return found;
+ return *(void**)found;
}
// vim: set ts=4 sw=4:
diff --git a/src/hash/delete.c b/src/hash/delete.c
new file mode 100644
index 0000000..76dd374
--- /dev/null
+++ b/src/hash/delete.c
@@ -0,0 +1,47 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "hash.h"
+#include "interface/hashable.h"
+#include "utils/hash.h"
+
+static
+inline
+int
+hashDeleteComp(const void * a, const void * b)
+{
+ return hashableGetHash((void*)b) - *(const unsigned long*)a;
+}
+
+void *
+hashDelete(Hash this, const char * search, size_t nsearch)
+{
+ unsigned long hash = sdbm((const unsigned char *)search, nsearch);
+ void * found = tfind(&hash, &(this->root), hashDeleteComp);
+
+ return (NULL != found)? *(void**)found : NULL;
+}
+
+// vim: set ts=4 sw=4:
diff --git a/src/hash/each.c b/src/hash/each.c
new file mode 100644
index 0000000..4df28d1
--- /dev/null
+++ b/src/hash/each.c
@@ -0,0 +1,47 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "hash.h"
+
+static void (*cb)(void*);
+
+static
+inline
+void
+walk(const void * node, const VISIT which, const int depth)
+{
+ if (endorder == which || leaf == which) {
+ cb(*(void**)node);
+ }
+}
+
+void
+hashEach(Hash this, void (*callback)(const void*))
+{
+ cb = callback;
+
+ twalk(this->root, walk);
+}
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/header/get.c b/src/hash/get.c
similarity index 56%
rename from src/http/header/get.c
rename to src/hash/get.c
index 81c24ba..44240cb 100644
--- a/src/http/header/get.c
+++ b/src/hash/get.c
@@ -1,12 +1,10 @@
/**
* \file
- * Get a header from a tree containing headers by its name.
- * The key for the tree is the hased lowercase header identifier.
*
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -23,29 +21,27 @@
*/
#include
-#include
+#include
-#include "http/header.h"
+#include "hash.h"
+#include "interface/hashable.h"
#include "utils/hash.h"
static
inline
int
-comp(const void * _a, const void * _b)
+hashGetComp(const void * a, const void * b)
{
- const unsigned long * a = _a;
- HttpHeader b = (HttpHeader)_b;
- return (*a < b->hash)? -1 : (*a > b->hash)? 1 : 0;
+ return hashableGetHash((void*)b) - *(const unsigned long*)a;
}
-HttpHeader
-httpHeaderGet(const HttpHeader * root, const char * name, size_t nname)
+void *
+hashGet(Hash this, const char * search, size_t nsearch)
{
- unsigned long hash = sdbm((const unsigned char*)name, nname);
+ unsigned long hash = sdbm((const unsigned char *)search, nsearch);
+ void * found = tfind(&hash, &(this->root), hashGetComp);
- HttpHeader * found = tfind(&hash, (void**)root, comp);
-
- return (NULL != found)? *found : NULL;
+ return (NULL != found)? *(void**)found : NULL;
}
// vim: set ts=4 sw=4:
diff --git a/src/hash_value.c b/src/hash_value.c
new file mode 100644
index 0000000..c69a169
--- /dev/null
+++ b/src/hash_value.c
@@ -0,0 +1,109 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "hash_value.h"
+#include "utils/hash.h"
+#include "utils/memory.h"
+#include "commons.h"
+#include "interface/class.h"
+#include "interface/hashable.h"
+
+static
+int
+hashValueCtor(void * _this, va_list * params)
+{
+ HashValue this = _this;
+ char * key = va_arg(* params, char*);
+ void * value;
+
+ this->nkey = va_arg(* params, size_t);
+ value = va_arg(* params, void*);
+ this->nvalue = va_arg(* params, size_t);
+
+ this->key = malloc(this->nkey + 1);
+ this->key[this->nkey] = 0;
+ memcpy(this->key, key, this->nkey);
+
+ this->hash = sdbm((unsigned char *)this->key, this->nkey);
+
+ if (NULL != value) {
+ this->value = malloc(this->nvalue + 1);
+ ((char*)this->value)[this->nvalue] = 0;
+ memcpy(this->value, value, this->nvalue);
+ }
+
+ return 0;
+}
+
+static
+void
+hashValueDtor(void * _this)
+{
+ HashValue this = _this;
+
+ FREE(this->key);
+ FREE(this->value);
+}
+
+static
+unsigned long
+hashValueGetHash(void * _this)
+{
+ HashValue this = _this;
+
+ return this->hash;
+}
+
+static
+void
+hashValueHandleDouble(void * _this, void * _double)
+{
+ HashValue this = _this;
+ HashValue doub = _double;
+ void * tmp_value;
+ size_t tmp_nvalue;
+
+ /**
+ * here we swap the internal data of both objects,
+ * effectively overwriting the old entry. We need not
+ * to free anything here as _double will be deleted
+ * afterwards anyway (\see hash/add.c).
+ */
+ tmp_value = this->value;
+ this->value = doub->value;
+ doub->value = tmp_value;
+
+ tmp_nvalue = this->nvalue;
+ this->nvalue = doub->nvalue;
+ doub->nvalue = tmp_nvalue;
+}
+
+INIT_IFACE(Class, hashValueCtor, hashValueDtor, NULL);
+INIT_IFACE(Hashable, hashValueGetHash, hashValueHandleDouble);
+CREATE_CLASS(HashValue, NULL, IFACE(Class), IFACE(Hashable));
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/cookie.c b/src/http/cookie.c
new file mode 100644
index 0000000..412f463
--- /dev/null
+++ b/src/http/cookie.c
@@ -0,0 +1,104 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "cookie.h"
+#include "interface/class.h"
+#include "interface/hashable"
+
+#include "utils/hash.h"
+#include "utils/memory.h"
+#include "commons.h"
+
+
+static
+int
+httpCookieCtor(void * _this, va_list * params)
+{
+ HttpCookie this = _this;
+ char * key = va_arg(* params, char*);
+ char * value;
+
+ this->nkey = va_arg(* params, size_t);
+ value = va_arg(* params, char*);
+ this->nvalue = va_arg(* params, size_t);
+
+ this->key = malloc(this->nkey + 1);
+ this->key[this->nkey] = 0;
+ memcpy(this->key, key, this->nkey);
+
+ this->value = malloc(this->nvalue + 1);
+ this->value[this->nvalue] = 0;
+ memcpy(this->value, value, this->nvalue);
+
+ this->hash = sdbm((unsigned char *)key, nkey);
+
+ return 0;
+}
+
+static
+void
+httpCookieDtor(void * _this, va_list * params)
+{
+ HttpCookie this = _this;
+
+ FREE(this->key);
+ FREE(this->value);
+ FREE(this->domain);
+ FREE(this->path);
+}
+
+static
+unsigned long
+httpCookieGetHash(void * _this)
+{
+ HttpCookie this = _this;
+
+ return this->hash;
+}
+
+static
+void
+httpCookieHandleDouble(void * _this, void * _double)
+{
+ HttpCookie this = _this;
+ HttpCookie doub = _double;
+
+ SWAP(char*, this->key, doub->key);
+ SWAP(char*, this->value, doub->value);
+ SWAP(char*, this->domain, doub->domain);
+ SWAP(char*, this->path, doub->path);
+
+ SWAP(char*, this->nkey, doub->nkey);
+ SWAP(char*, this->nvalue, doub->nvalue);
+}
+
+
+INIT_IFACE(Class, httpCookieCtor, httpCookieDtor, NULL);
+INIT_IFACE(Hashable, httpCookieGetHash, httpCookieHandleDouble);
+CREATE_CLASS(HttpCookie, NULL, IFACE(Class), IFACE(Hashable));
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/header.c b/src/http/header.c
index 344ee87..999b878 100644
--- a/src/http/header.c
+++ b/src/http/header.c
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -27,6 +27,7 @@
#include "class.h"
#include "interface/class.h"
#include "http/header.h"
+#include "interface/hashable.h"
#include "utils/hash.h"
#include "utils/memory.h"
@@ -72,7 +73,35 @@ httpHeaderDtor(void * _this)
}
}
+static
+unsigned long
+httpHeaderGetHash(void * _this)
+{
+ HttpHeader this = _this;
+
+ return this->hash;
+}
+
+static
+void
+httpHeaderHandleDouble(void * _this, void * _double)
+{
+ HttpHeader this = _this;
+ HttpHeader doub = _double;
+
+ if (this->cvalue >= N_VALUES) {
+ //! \todo do dome error logging...or change to HEAP
+ return;
+ }
+
+ (this->nvalue)[this->cvalue] = (doub->nvalue)[0];
+ (this->value)[(this->cvalue)++] = (doub->value)[0];
+ this->size += doub->size;
+ (doub->value)[0] = NULL;
+}
+
INIT_IFACE(Class, httpHeaderCtor, httpHeaderDtor, NULL);
-CREATE_CLASS(HttpHeader, NULL, IFACE(Class));
+INIT_IFACE(Hashable, httpHeaderGetHash, httpHeaderHandleDouble);
+CREATE_CLASS(HttpHeader, NULL, IFACE(Class), IFACE(Hashable));
// vim: set ts=4 sw=4:
diff --git a/src/http/header/to_string.c b/src/http/header/to_string.c
index 124e804..089ee51 100644
--- a/src/http/header/to_string.c
+++ b/src/http/header/to_string.c
@@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/message.c b/src/http/message.c
index 3b3c063..611f9de 100644
--- a/src/http/message.c
+++ b/src/http/message.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -32,19 +32,11 @@
#include "class.h"
#include "interface/class.h"
-
+#include "hash.h"
#include "http/message.h"
#include "utils/memory.h"
-static
-inline
-void
-tDelete(void * node)
-{
- delete(node);
-}
-
static
int
httpMessageCtor(void * _this, va_list * params)
@@ -55,6 +47,9 @@ httpMessageCtor(void * _this, va_list * params)
this->version = calloc(1, strlen(version)+1);
strcpy(this->version, version);
+ this->header = new(Hash);
+ this->cookies = new(Hash);
+
return 0;
}
@@ -64,14 +59,10 @@ httpMessageDtor(void * _this)
{
HttpMessage this = _this;
- FREE(this->version);
+ delete(this->header);
+ delete(this->cookies);
- /**
- * this is a GNU extension...anyway on most non
- * GNUish systems i would not use tsearch anyway
- * as the trees will be unbalanced.
- */
- tdestroy(this->header, tDelete);
+ FREE(this->version);
switch (this->type) {
case HTTP_MESSAGE_BUFFERED:
diff --git a/src/http/message/get_version.c b/src/http/message/get_version.c
index be83528..0db7d99 100644
--- a/src/http/message/get_version.c
+++ b/src/http/message/get_version.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/message/has_keep_alive.c b/src/http/message/has_keep_alive.c
index 24623e4..136b673 100644
--- a/src/http/message/has_keep_alive.c
+++ b/src/http/message/has_keep_alive.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -31,6 +31,7 @@
#include "utils/memory.h"
#include "commons.h"
+#include "hash.h"
char
httpMessageHasKeepAlive(HttpMessage message)
@@ -39,7 +40,7 @@ httpMessageHasKeepAlive(HttpMessage message)
size_t size;
char * value;
- header = httpHeaderGet(&(message->header), CSTRA("connection"));
+ header = hashGet(message->header, CSTRA("connection"));
if (NULL == header) {
return 0;
diff --git a/src/http/message/has_valid_version.c b/src/http/message/has_valid_version.c
index 1195995..c72e7b1 100644
--- a/src/http/message/has_valid_version.c
+++ b/src/http/message/has_valid_version.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/message/header_size_get.c b/src/http/message/header_size_get.c
index e46ab25..5388db5 100644
--- a/src/http/message/header_size_get.c
+++ b/src/http/message/header_size_get.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -28,17 +28,16 @@
#include "http/response.h"
#include "http/header.h"
#include "interface/http_intro.h"
+#include "hash.h"
static size_t size;
static
inline
void
-addHeaderSize(const void * node, const VISIT which, const int depth)
+addHeaderSize(const void * node)
{
- if (endorder == which || leaf == which) {
- size += (*(HttpHeader *)node)->size;
- }
+ size += ((HttpHeader)node)->size;
}
size_t
@@ -46,7 +45,7 @@ httpMessageHeaderSizeGet(HttpMessage message)
{
size = httpIntroSizeGet(message);
- twalk(message->header, addHeaderSize);
+ hashEach(message->header, addHeaderSize);
size += 2;
return size;
diff --git a/src/http/message/header_to_string.c b/src/http/message/header_to_string.c
index ba223ab..1b615cb 100644
--- a/src/http/message/header_to_string.c
+++ b/src/http/message/header_to_string.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -27,15 +27,16 @@
#include "http/response.h"
#include "http/header.h"
#include "interface/http_intro.h"
+#include "hash.h"
static char * string;
+static
+inline
void
-addHeaderString(const void * node, const VISIT which, const int depth)
+addHeaderString(const void * node)
{
- if (endorder == which || leaf == which) {
- string += httpHeaderToString(*(HttpHeader *)node, string);
- }
+ string += httpHeaderToString((HttpHeader)node, string);
}
char *
@@ -45,7 +46,7 @@ httpMessageHeaderToString(HttpMessage response, char * _string)
string = httpIntroToString(response, _string);
- twalk(message->header, addHeaderString);
+ hashEach(message->header, addHeaderString);
*string++ = '\r';
*string++ = '\n';
diff --git a/src/http/message/queue.c b/src/http/message/queue.c
index f6c3ff5..ceb4496 100644
--- a/src/http/message/queue.c
+++ b/src/http/message/queue.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/parser.c b/src/http/parser.c
index d294a67..be34cce 100644
--- a/src/http/parser.c
+++ b/src/http/parser.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/parser/body.c b/src/http/parser/body.c
index 6901c8d..07b3162 100644
--- a/src/http/parser/body.c
+++ b/src/http/parser/body.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -28,7 +28,7 @@
#include "http/parser.h"
#include "cbuf.h"
-#define MIN(a,b) (((a) < (b))? (a) : (b))
+#include "commons.h"
size_t
httpParserBody(HttpParser this, const char * buf, size_t nbuf)
diff --git a/src/http/parser/header.c b/src/http/parser/header.c
index 320f1cc..0944305 100644
--- a/src/http/parser/header.c
+++ b/src/http/parser/header.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -29,6 +29,9 @@
#include "http/header.h"
#include "http/parser.h"
#include "http/message.h"
+#include "http/request.h"
+#include "hash.h"
+#include "hash_value.h"
void
httpParserHeader(
@@ -59,8 +62,43 @@ httpParserHeader(
current->dbody = 0;
}
- httpHeaderAdd(
- &(current->header),
+ if (0 == strncasecmp("cookie", name, nname-1)) {
+ HttpRequest request = (HttpRequest)this->current;
+ char * pair = value;
+ ssize_t togo = lend - value;
+
+ while(NULL != pair && 0 < togo) {
+ char * key = pair;
+ char * eqsign;
+ char * val;
+ size_t nval;
+
+ for (; *key == ' ' && key < lend; key++, togo--);
+ eqsign = memchr(key, '=', togo);
+
+ if (NULL == eqsign) {
+ break;
+ }
+
+ togo -= (eqsign - key);
+ pair = memchr(eqsign, ';', togo);
+
+ if (NULL == pair) {
+ pair = (char *)lend;
+ }
+
+ nval = pair-eqsign-1;
+ val = (0 != nval)? eqsign+1 : NULL;
+
+ hashAdd(request->cookies,
+ new(HashValue, key, eqsign-key, val, nval));
+
+ pair++;
+ togo -= (pair - eqsign);
+ }
+ }
+
+ hashAdd(current->header,
new(HttpHeader, name, nname, value, lend - value));
}
diff --git a/src/http/parser/new_message.c b/src/http/parser/new_message.c
index 5c392fc..e265a9c 100644
--- a/src/http/parser/new_message.c
+++ b/src/http/parser/new_message.c
@@ -1,3 +1,25 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "http/parser.h"
#include "utils/http.h"
diff --git a/src/http/parser/parse.c b/src/http/parser/parse.c
index 9bef455..397c352 100644
--- a/src/http/parser/parse.c
+++ b/src/http/parser/parse.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -23,11 +23,18 @@
#include
#include "http/parser.h"
+#include "http/header.h"
#include "interface/class.h"
#include "interface/http_intro.h"
#include "cbuf.h"
#include "stream.h"
+#include "utils/memory.h"
+#include "commons.h"
+
+#define MIN(a,b) ((a)<(b)? (a) : (b))
+
+
ssize_t
httpParserParse(void * _this, Stream st)
{
@@ -92,6 +99,7 @@ httpParserParse(void * _this, Stream st)
this->ourLock = FALSE;
return -1;
}
+ httpParserRequestVars(this);
this->state = HTTP_MESSAGE_INTRO_DONE;
break;
@@ -141,6 +149,23 @@ httpParserParse(void * _this, Stream st)
break;
case HTTP_MESSAGE_DONE:
+ {
+ HttpHeader enc = hashGet(
+ this->current->header,
+ CSTRA("content-type"));
+
+ /**
+ * do we have form data??
+ */
+ if (NULL != enc && 0 == strncasecmp(
+ "application/x-www-form-urlencoded",
+ enc->value[0],
+ MIN(sizeof("application/x-www-form-urlencoded")-1,
+ enc->nvalue[0]))) {
+ //!> then parse them...
+ httpParserPostVars(this);
+ }
+
/**
* enqueue current request
*/
@@ -151,7 +176,7 @@ httpParserParse(void * _this, Stream st)
* prepare for next request
*/
this->state = HTTP_MESSAGE_GARBAGE;
-
+ }
break;
default:
diff --git a/src/http/parser/post_vars.c b/src/http/parser/post_vars.c
new file mode 100644
index 0000000..517133f
--- /dev/null
+++ b/src/http/parser/post_vars.c
@@ -0,0 +1,72 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "http/parser.h"
+#include "http/request.h"
+#include "hash_value.h"
+#include "hash.h"
+#include "interface/class.h"
+
+/**
+ * \todo this is very similar to other pair parsing
+ * things... key1=val1key2=val2...keyn=valn
+ * Generalize this!!!!
+ */
+void
+httpParserPostVars(HttpParser this)
+{
+ HttpRequest request = (HttpRequest)this->current;
+ char * pair = this->current->body;
+ ssize_t togo = this->current->nbody;
+
+ while(NULL != pair && 0 < togo) {
+ char * key = pair;
+ char * eqsign = memchr(key, '=', togo);
+ char * value;
+ size_t nvalue;
+
+ if (NULL == eqsign) {
+ return;
+ }
+
+ togo -= (eqsign - key);
+ pair = memchr(eqsign, '&', togo);
+
+ if (NULL == pair) {
+ pair = &(this->current->body[this->current->nbody]);
+ }
+
+ nvalue = pair-eqsign-1;
+ value = (0 != nvalue)? eqsign+1 : NULL;
+
+ hashAdd(request->post,
+ new(HashValue, key, eqsign-key, value, nvalue));
+
+ pair++;
+ togo -= (pair - eqsign);
+ }
+}
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/parser/request_vars.c b/src/http/parser/request_vars.c
new file mode 100644
index 0000000..d0b47a1
--- /dev/null
+++ b/src/http/parser/request_vars.c
@@ -0,0 +1,71 @@
+/**
+ * \file
+ *
+ * \author Georg Hopp
+ *
+ * \copyright
+ * Copyright © 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 "http/parser.h"
+#include "http/request.h"
+#include "hash_value.h"
+#include "hash.h"
+#include "interface/class.h"
+
+void
+httpParserRequestVars(HttpParser this)
+{
+ HttpRequest request = (HttpRequest)this->current;
+ char * delim = strchr(request->uri, '?');
+
+ if (NULL == delim) {
+ delim = request->uri + strlen(request->uri);
+ }
+
+ request->path = malloc(delim - request->uri + 1);
+ request->path[delim - request->uri] = 0;
+ memcpy(request->path, request->uri, delim - request->uri);
+
+ while(NULL != delim && 0 != *delim) {
+ char * key = delim + 1;
+ char * eqsign = strchr(key, '=');
+ char * value;
+ size_t nvalue;
+
+ if (NULL == eqsign) {
+ return;
+ }
+
+ delim = strchr(eqsign, '&');
+
+ if (NULL == delim) {
+ delim = key + strlen(key);
+ }
+
+ nvalue = delim-eqsign-1;
+ value = (0 != nvalue)? eqsign+1 : NULL;
+
+ hashAdd(request->get,
+ new(HashValue, key, eqsign-key, value, nvalue));
+ }
+}
+
+// vim: set ts=4 sw=4:
diff --git a/src/http/request.c b/src/http/request.c
index 4299a27..4cd4c14 100644
--- a/src/http/request.c
+++ b/src/http/request.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -56,6 +56,10 @@ httpRequestCtor(void * _this, va_list * params)
this->uri[ulen] = 0;
memcpy(this->uri, uri, ulen);
+ this->get = new(Hash);
+ this->post = new(Hash);
+ this->cookies = new(Hash);
+
return 0;
}
@@ -65,8 +69,13 @@ httpRequestDtor(void * _this)
{
HttpRequest this = _this;
+ delete(this->get);
+ delete(this->post);
+ delete(this->cookies);
+
FREE(this->uri);
FREE(this->method);
+ FREE(this->path);
PARENTCALL(_this, Class, dtor);
}
diff --git a/src/http/request/has_valid_method.c b/src/http/request/has_valid_method.c
index 08a02be..c44dcc3 100644
--- a/src/http/request/has_valid_method.c
+++ b/src/http/request/has_valid_method.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/response.c b/src/http/response.c
index b35e7b9..a53cd0d 100644
--- a/src/http/response.c
+++ b/src/http/response.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/response/304.c b/src/http/response/304.c
index 28fa1aa..a5ea639 100644
--- a/src/http/response/304.c
+++ b/src/http/response/304.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -30,6 +30,7 @@
#include "http/header.h"
#include "utils/memory.h"
+#include "hash.h"
HttpResponse
httpResponse304(
@@ -47,11 +48,11 @@ httpResponse304(
message->nbody = 0;
message->body = NULL;
- httpHeaderAdd(&(message->header),
+ hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), mime, nmime));
- httpHeaderAdd(&(message->header),
+ hashAdd(message->header,
new(HttpHeader, CSTRA("ETag"), etag, netag));
- httpHeaderAdd(&(message->header),
+ hashAdd(message->header,
new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime));
return response;
diff --git a/src/http/response/403.c b/src/http/response/403.c
index ded0e4d..7256a3e 100644
--- a/src/http/response/403.c
+++ b/src/http/response/403.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
diff --git a/src/http/response/404.c b/src/http/response/404.c
index eb76df7..fd3fae3 100644
--- a/src/http/response/404.c
+++ b/src/http/response/404.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -33,6 +33,7 @@
#include "http/header.h"
#include "utils/memory.h"
+#include "hash.h"
#define RESP_DATA "\n" \
"header),
+ hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
message->type = HTTP_MESSAGE_BUFFERED;
diff --git a/src/http/response/asset.c b/src/http/response/asset.c
index 3ee1a01..1ab4937 100644
--- a/src/http/response/asset.c
+++ b/src/http/response/asset.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -36,7 +36,7 @@
#include "http/header.h"
#include "utils/memory.h"
-
+#include "hash.h"
HttpResponse
httpResponseAsset(
@@ -74,11 +74,11 @@ httpResponseAsset(
message->handle = new(Stream, STREAM_FD, handle);
message->nbody = st.st_size;
- httpHeaderAdd(&(message->header),
+ hashAdd(message->header,
new(HttpHeader, CSTRA("Content-Type"), mime, nmime));
- httpHeaderAdd(&(message->header),
+ hashAdd(message->header,
new(HttpHeader, CSTRA("ETag"), etag, netag));
- httpHeaderAdd(&(message->header),
+ hashAdd(message->header,
new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime));
return response;
diff --git a/src/http/response/login_form.c b/src/http/response/login_form.c
index c2f790b..e0e6374 100644
--- a/src/http/response/login_form.c
+++ b/src/http/response/login_form.c
@@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
- * Copyright (C) 2012 Georg Hopp
+ * Copyright © 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
@@ -34,6 +34,7 @@
#include "http/header.h"
#include "utils/memory.h"
+#include "hash.h"
#define RESP_DATA "