Commit 61f8dc58e1507ee37c81818098b98a294cd9b62f

Authored by Georg Hopp
1 parent f6de9dee

add latest stuff from parent project yabrog. Essentially some request variable h…

…andling and authentication interface with ldap implementation. Additionally add docBlocks to all C source and header files and make a real copyright sign from the (C).
Showing 100 changed files with 1749 additions and 315 deletions

Too many changes to show.

To preserve performance only 100 of 100+ files are displayed.

... ... @@ -4,10 +4,9 @@
4 4 .deps/
5 5 Makefile
6 6 Makefile.in
  7 +/config*
7 8 m4/
8 9 /docs/
9   -/config.*
10   -/configure
11 10 /INSTALL
12 11 *.m4
13 12 /autom4te.cache/
... ...
  1 +VERY BIG TODO:
  2 +- right now i will use long polling ajax calls when feedback from to the client
  3 + is needed. In the long term this should be changed to websockets (ws). But
  4 + right now ws specification is not final anyway. :)
  5 +
  6 +- handle errors after all system call...especially open, close, etc.
  7 +
  8 +- IPV6 support
... ...
  1 +<?xml version="1.0" encoding="iso-8859-1"?>
  2 +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  3 +"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  4 +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
  5 + <head>
  6 + <title>My own little Web-App</title>
  7 + <link rel="stylesheet" type="text/css" href="/assets/style/common">
  8 + <script type="text/javascript" src="/assets/js/jquery"></script>
  9 + <script type="text/javascript" src="/assets/js/serverval"></script>
  10 + <script type="text/javascript" src="/assets/js/session"></script>
  11 + <script type="text/javascript" src="/assets/js/init"></script>
  12 + </head>
  13 + <body>
  14 + <ul id="menu">
  15 + <li>random Value</li>
  16 + <li>start session</li>
  17 + <li>login</li>
  18 + </ul>
  19 + <div id="sessinfo" class="x-small">
  20 + Session: <span></span><br />
  21 + <canvas width="100px" height="3px"></canvas>
  22 + </div>
  23 + <div id="login" class="hide">
  24 + <form>
  25 + <label for="username">username</label>
  26 + <input type="text" name="username" /><br />
  27 + <label for="password">password</label>
  28 + <input type="password" name="password" /><br />
  29 + <input type="submit" />
  30 + </form>
  31 + </div>
  32 + <div id="randval" class="hide">
  33 + <span class=\"small">
  34 + Value created at: <br />
  35 + <span></span><br>
  36 + Next value in: <span></span><br />
  37 + </span>
  38 + Value: <span></span>
  39 + </div>
  40 + <div id="main">
  41 + <h1>Testpage</h1>
  42 + Welcome<span></span>!!!<br />
  43 + <img src="/image/me" />
  44 + </div>
  45 + <hr />
  46 + <div id="msg"></div>
  47 + </body>
  48 +</html>
  49 +
  50 +<!-- vim: set ts=4 sw=4: -->
... ...
  1 +var sess = null;
  2 +
  3 +$(document).ready(function() {
  4 + var sval = new ServerVal("#randval");
  5 +
  6 + sess = new Session("#sessinfo");
  7 +
  8 + $(window).focus(function() {
  9 + $.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
  10 + });
  11 +
  12 + $("ul#menu li:eq(0)").click(function() {
  13 + sval.start();
  14 + });
  15 +
  16 + $("ul#menu li:eq(1)").click(function() {
  17 + $.getJSON("/sess/", $.proxy(sess.loadJSON, sess));
  18 + });
  19 +
  20 + $("ul#menu li:eq(2)").click(function() {
  21 + $("#login").removeClass("hide");
  22 + });
  23 +
  24 + $("#randval").click(function() {
  25 + sval.stop();
  26 + });
  27 +
  28 + $("#login form").submit(function(event) {
  29 + event.preventDefault();
  30 + $.post("/login/",
  31 + $("#login form").serialize(),
  32 + $.proxy(sess.loadJSON, sess));
  33 + $("#login").addClass("hide");
  34 + });
  35 +});
  36 +
  37 +// vim: set ts=4 sw=4:
... ...
  1 +function ServerVal(eId)
  2 +{
  3 + this.eId = eId;
  4 + this.eCtime = eId + " span:eq(1)";
  5 + this.eVnext = eId + " span:eq(2)";
  6 + this.eValue = eId + " span:eq(3)";
  7 +
  8 + this.interval = null;
  9 + this.ctime = null;
  10 + this.vnext = 0;
  11 + this.value = null;
  12 +}
  13 +
  14 +ServerVal.prototype.loadJSON = function(data)
  15 +{
  16 + this.ctime = new Date(data.ctime * 1000);
  17 + this.vnext = data.vnext;
  18 + this.value = data.value;
  19 +
  20 + $.getJSON("/sessinfo/", $.proxy(sess.loadJSON, sess));
  21 + this.show();
  22 +}
  23 +
  24 +ServerVal.prototype.show = function()
  25 +{
  26 + $(this.eCtime).empty().append(this.ctime.toString());
  27 + $(this.eVnext).empty().append(this.vnext);
  28 + $(this.eValue).empty().append(this.value);
  29 +
  30 + if ($(this.eId).hasClass("hide")) {
  31 + $(this.eId).removeClass("hide");
  32 + }
  33 +}
  34 +
  35 +ServerVal.prototype.start = function()
  36 +{
  37 + if (null === this.interval) {
  38 + this.interval = setInterval($.proxy(this.process, this), 1000);
  39 + }
  40 +}
  41 +
  42 +ServerVal.prototype.process = function()
  43 +{
  44 + if (0 >= this.vnext) {
  45 + $.getJSON("/randval/", $.proxy(this.loadJSON, this))
  46 + .error($.proxy(function(xhr) {
  47 + this.stop();
  48 + $("#msg").append("AJAX error (" + xhr.status + "): ");
  49 + switch(xhr.status) {
  50 + case 403:
  51 + $("#msg").append(
  52 + "Please log in to access this function.<br />");
  53 + break;
  54 +
  55 + default:
  56 + $("#msg").append(
  57 + "Unhandled - " + xhr.responseText + "<br />");
  58 + break;
  59 + }
  60 + }, this));
  61 + }
  62 +
  63 + else {
  64 + this.vnext--;
  65 + $(this.eVnext).empty().append(this.vnext);
  66 + }
  67 +}
  68 +
  69 +ServerVal.prototype.stop = function()
  70 +{
  71 + $(this.eId).addClass("hide");
  72 +
  73 + clearInterval(this.interval);
  74 + this.interval = null;
  75 + this.vnext = 0;
  76 +}
  77 +
  78 +// vim: set ts=4 sw=4:
... ...
  1 +function Session(sId)
  2 +{
  3 + this.eSid = $(sId + " span");
  4 + this.canvas = $(sId + " canvas").get(0);
  5 + this.context = this.canvas.getContext("2d");
  6 +
  7 + this.id = "none"
  8 + this.timeout = 0;
  9 + this.timeleft = 0;
  10 + this.username = "";
  11 + this.interval = null;
  12 +
  13 + this.draw();
  14 +}
  15 +
  16 +Session.prototype.loadJSON = function(data)
  17 +{
  18 + this.stop();
  19 +
  20 + this.id = ("0" == data.id)? "none" : data.id;
  21 + this.timeout = data.timeout * 10;
  22 + this.timeleft = data.timeleft * 10;
  23 + this.username = data.username;
  24 +
  25 + this.eSid.empty().append(this.id);
  26 + $("#main span:eq(0)").empty().append(" " + this.username);
  27 +
  28 + this.draw();
  29 + if (0 < this.timeleft)
  30 + this.start();
  31 +}
  32 +
  33 +Session.prototype.draw = function()
  34 +{
  35 + this.context.fillStyle = "rgb(255, 0, 0)";
  36 + this.context.fillRect(0, 0, this.canvas.width, this.canvas.height);
  37 +
  38 + this.context.fillStyle = "rgb(0, 255, 0)";
  39 + this.context.fillRect(0, 0,
  40 + this.canvas.width / this.timeout * this.timeleft,
  41 + this.canvas.height);
  42 +}
  43 +
  44 +Session.prototype.start = function()
  45 +{
  46 + if (null === this.interval) {
  47 + this.interval = setInterval($.proxy(this.process, this), 100);
  48 + }
  49 +}
  50 +
  51 +Session.prototype.process = function()
  52 +{
  53 + if (0 >= this.timeleft) {
  54 + this.stop();
  55 + }
  56 +
  57 + else {
  58 + this.timeleft--;
  59 + this.draw();
  60 + }
  61 +}
  62 +
  63 +Session.prototype.stop = function()
  64 +{
  65 + clearInterval(this.interval);
  66 + this.interval = null;
  67 + this.id = "none";
  68 + this.timeout = 0;
  69 + this.timeleft = 0;
  70 + this.username = "";
  71 +
  72 + this.eSid.empty().append(this.id);
  73 + $("#main span:eq(0)").empty().append(" " + this.username);
  74 +
  75 + this.draw();
  76 +}
  77 +
  78 +// vim: set ts=4 sw=4:
... ...
  1 +div#randval {
  2 + left: 200px;
  3 + top: 100px;
  4 + padding: 10px;
  5 + position: fixed;
  6 + background-color: white;
  7 + border: 1px solid black;
  8 + border-radius: 10px;
  9 +}
  10 +
  11 +div#login {
  12 + padding: 5px;
  13 + position: fixed;
  14 + background-color: white;
  15 + border: 1px solid black;
  16 + border-radius: 10px;
  17 +}
  18 +
  19 +div.hide {
  20 + top: -500px !important;
  21 +}
  22 +
  23 +.small {
  24 + font-size: small;
  25 +}
  26 +
  27 +.x-small {
  28 + font-size: x-small;
  29 +}
  30 +
  31 +ul#menu {
  32 + list-style: none inside;
  33 + margin: 0px;
  34 + padding: 1px 0px 0px;
  35 + border-bottom: 1px solid #7b0b2b;
  36 + display: inline-block;
  37 + width: 100%;
  38 +}
  39 +
  40 +ul#menu li {
  41 + padding: 2px;
  42 + border-top-left-radius: 10px;
  43 + border-top-right-radius: 10px;
  44 + border-top: 1px solid #7b0b2b;
  45 + border-left: 1px solid #7b0b2b;
  46 + border-right: 1px solid #7b0b2b;
  47 + text-align: center;
  48 + cursor: pointer;
  49 +
  50 + float: left;
  51 + margin-right: 1px;
  52 +}
  53 +
  54 +div#sessinfo canvas {
  55 + border: 1px solid black;
  56 +}
  57 +
  58 +/* vim: set st=4 sw=4: */
... ...
  1 +/**
  2 + * \file
  3 + * Authenticatio module factory
  4 + *
  5 + * A factory to get a specific authentication module.
  6 + * An authentication module is a class that implement the Auth interface.
  7 + *
  8 + * \author Georg Hopp
  9 + *
  10 + * \copyright
  11 + * Copyright © 2012 Georg Hopp
  12 + *
  13 + * This program is free software: you can redistribute it and/or modify
  14 + * it under the terms of the GNU General Public License as published by
  15 + * the Free Software Foundation, either version 3 of the License, or
  16 + * (at your option) any later version.
  17 + *
  18 + * This program is distributed in the hope that it will be useful,
  19 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21 + * GNU General Public License for more details.
  22 + *
  23 + * You should have received a copy of the GNU General Public License
  24 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25 + */
  26 +
  27 +#ifndef __AUTH_H__
  28 +#define __AUTH_H__
  29 +
  30 +#include "class.h"
  31 +#include "auth/ldap.h"
  32 +
  33 +typedef enum e_AuthModule {
  34 + AUTH_LDAP = 0
  35 +} AuthModule;
  36 +
  37 +CLASS(Auth) {
  38 +};
  39 +
  40 +void * authCreateById(Auth, int);
  41 +AuthLdap authCreateLdap(Auth);
  42 +
  43 +#endif // __AUTH_H__
  44 +
  45 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#ifndef __AUTH_LDAP_H__
  24 +#define __AUTH_LDAP_H__
  25 +
  26 +#include <ldap.h>
  27 +#include <sys/types.h>
  28 +
  29 +#include "class.h"
  30 +
  31 +CLASS(AuthLdap) {
  32 + LDAP * ldap;
  33 + char * url;
  34 + char * base_dn;
  35 + int version;
  36 + size_t nbase_dn;
  37 +};
  38 +
  39 +#endif // __AUTH_LDAP_H__
  40 +
  41 +// vim: set ts=4 sw=4:
... ...
... ... @@ -11,7 +11,7 @@
11 11 * \author Georg Hopp
12 12 *
13 13 * \copyright
14   - * Copyright (C) 2012 Georg Hopp
  14 + * Copyright © 2012 Georg Hopp
15 15 *
16 16 * This program is free software: you can redistribute it and/or modify
17 17 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -8,7 +8,7 @@
8 8 * \author Georg Hopp
9 9 *
10 10 * \copyright
11   - * Copyright (C) 2012 Georg Hopp
  11 + * Copyright © 2012 Georg Hopp
12 12 *
13 13 * This program is free software: you can redistribute it and/or modify
14 14 * it under the terms of the GNU General Public License as published by
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
1 23 #ifndef __COMMONS_H__
2 24 #define __COMMONS_H__
3 25
... ... @@ -5,6 +27,22 @@
5 27 #define TRUE 1
6 28 #define FALSE 0
7 29
  30 +#ifndef MAX
  31 +# define MAX(a,b) ((a)>(b)? (a) : (b))
  32 +#endif
  33 +
  34 +#ifndef MIN
  35 +# define MIN(a,b) ((a)<(b)? (a) : (b))
  36 +#endif
  37 +
  38 +#define SWAP_FUN(a, b) ((a)^=(b),(b)^=(a),(a)^=(b))
  39 +
  40 +#define SWAP(type, a, b) do { \
  41 + type tmp = (a); \
  42 + (a) = (b); \
  43 + (b) = tmp; \
  44 +} while(0);
  45 +
8 46 #endif // __COMMONS_H__
9 47
10 48 // vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#ifndef __CREDENTIAL_H__
  24 +#define __CREDENTIAL_H__
  25 +
  26 +#include <sys/types.h>
  27 +
  28 +#include "class.h"
  29 +
  30 +#define CRED_PWD(c) (((c)->cred).pwd)
  31 +
  32 +typedef enum e_CredentialType {
  33 + CRED_PASSWORD = 0
  34 +} CredentialType;
  35 +
  36 +
  37 +CLASS(Credential) {
  38 + CredentialType type;
  39 +
  40 + union {
  41 +
  42 + struct {
  43 + char * user;
  44 + size_t nuser;
  45 + char * pass;
  46 + size_t npass;
  47 + } pwd;
  48 +
  49 + } cred;
  50 +};
  51 +
  52 +#endif // __CREDENTIAL_H__
  53 +
  54 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#ifndef __HASH_H__
  24 +#define __HASH_H__
  25 +
  26 +#include <sys/types.h>
  27 +
  28 +#include "class.h"
  29 +
  30 +
  31 +CLASS(Hash) {
  32 + void * root;
  33 +};
  34 +
  35 +void * hashAdd(Hash, void *);
  36 +void * hashDelete(Hash, const char *, size_t);
  37 +void * hashGet(Hash, const char *, size_t);
  38 +void hashEach(Hash, void (*)(const void*));
  39 +
  40 +#endif // __HASH_H__
  41 +
  42 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#ifndef __HASH_VALUE_H__
  24 +#define __HASH_VALUE_H__
  25 +
  26 +#include <sys/types.h>
  27 +
  28 +#include "class.h"
  29 +
  30 +CLASS(HashValue) {
  31 + unsigned long hash;
  32 +
  33 + char * key;
  34 + void * value;
  35 +
  36 + size_t nkey;
  37 + size_t nvalue;
  38 +};
  39 +
  40 +#endif // __HASH_VALUE_H__
  41 +
  42 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * - Copyright © 2012 Georg Hopp
  8 + * -
  9 + * - This program is free software: you can redistribute it and/or modify
  10 + * - it under the terms of the GNU General Public License as published by
  11 + * - the Free Software Foundation, either version 3 of the License, or
  12 + * - (at your option) any later version.
  13 + * -
  14 + * - This program is distributed in the hope that it will be useful,
  15 + * - but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * - GNU General Public License for more details.
  18 + * -
  19 + * - You should have received a copy of the GNU General Public License
  20 + * - along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#ifndef __HTTP_COOKIE_H__
  24 +#define __HTTP_COOKIE_H__
  25 +
  26 +#include <time.h>
  27 +#include <sys/types.h>
  28 +
  29 +#include "class.h"
  30 +
  31 +CLASS(HttpCookie) {
  32 + unsigned long hash;
  33 +
  34 + char * key;
  35 + char * value;
  36 + char * domain;
  37 + char * path;
  38 +
  39 + time_t expires;
  40 + time_t max_age;
  41 +
  42 + size_t nkey;
  43 + size_t nvalue;
  44 +};
  45 +
  46 +char * httpCookieToString(HttpCookie);
  47 +HttpCookie httpStringToCookie(const char *);
  48 +
  49 +#endif // __HTTP_COOKIE_H__
  50 +
  51 +// vim: set ts=4 sw=4:
... ...
... ... @@ -6,7 +6,7 @@
6 6 * \author Georg Hopp
7 7 *
8 8 * \copyright
9   - * Copyright (C) 2012 Georg Hopp
  9 + * Copyright © 2012 Georg Hopp
10 10 *
11 11 * This program is free software: you can redistribute it and/or modify
12 12 * it under the terms of the GNU General Public License as published by
... ... @@ -41,8 +41,6 @@ CLASS(HttpHeader) {
41 41 size_t size; //!< full size of this header
42 42 };
43 43
44   -HttpHeader httpHeaderAdd(const HttpHeader *, HttpHeader);
45   -HttpHeader httpHeaderGet(const HttpHeader *, const char *, size_t);
46 44 size_t httpHeaderToString(HttpHeader, char *);
47 45
48 46 #endif // __HTTP_HEADER_H__
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ... @@ -25,7 +25,7 @@
25 25 #define __HTTP_MESSAGE__
26 26
27 27 #include "class.h"
28   -#include "http/header.h"
  28 +#include "hash.h"
29 29 #include "stream.h"
30 30
31 31 typedef enum e_HttpMessageType {
... ... @@ -37,7 +37,8 @@ typedef enum e_HttpMessageType {
37 37 CLASS(HttpMessage) {
38 38 char * version;
39 39
40   - HttpHeader header;
  40 + Hash header;
  41 + Hash cookies;
41 42
42 43 HttpMessageType type;
43 44 Stream handle;
... ...
... ... @@ -7,7 +7,7 @@
7 7 * \author Georg Hopp
8 8 *
9 9 * \copyright
10   - * Copyright (C) 2012 Georg Hopp
  10 + * Copyright © 2012 Georg Hopp
11 11 *
12 12 * This program is free software: you can redistribute it and/or modify
13 13 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ... @@ -58,9 +58,12 @@ CLASS(HttpParser) {
58 58 };
59 59
60 60 ssize_t httpParserParse(void *, Stream);
  61 +void httpParserRequestVars(HttpParser);
61 62 void httpParserHeader(HttpParser, const char *, const char *);
62 63 void httpParserNewMessage(HttpParser, const char *, const char * lend);
63 64 size_t httpParserBody(HttpParser, const char *, size_t);
  65 +void httpParserRequestVars(HttpParser);
  66 +void httpParserPostVars(HttpParser);
64 67
65 68 #endif // __HTTP_PARSER_H__
66 69
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ... @@ -26,6 +26,7 @@
26 26
27 27 #include "class.h"
28 28 #include "http/message.h"
  29 +#include "hash.h"
29 30
30 31 #define N_HTTP_METHOD 8
31 32
... ... @@ -36,6 +37,11 @@ CLASS(HttpRequest) {
36 37
37 38 char * method;
38 39 char * uri;
  40 + char * path;
  41 +
  42 + Hash get;
  43 + Hash post;
  44 + Hash cookies;
39 45 };
40 46
41 47 int httpRequestHasValidMethod(HttpRequest);
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ... @@ -29,6 +29,7 @@
29 29
30 30 #include "class.h"
31 31 #include "http/message.h"
  32 +#include "session.h"
32 33
33 34
34 35 CLASS(HttpResponse) {
... ... @@ -47,6 +48,7 @@ HttpResponse httpResponse403();
47 48 HttpResponse httpResponseMe();
48 49 HttpResponse httpResponseLoginForm();
49 50 HttpResponse httpResponseRandval(time_t, int);
  51 +HttpResponse httpResponseSession(Session);
50 52 HttpResponse httpResponseAsset(
51 53 const char *,
52 54 const char *, size_t,
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ... @@ -52,6 +52,8 @@ CLASS(HttpWorker) {
52 52 HttpWriter writer;
53 53 Session session;
54 54 Session * sroot;
  55 +
  56 + void * auth;
55 57 };
56 58
57 59 #endif // __HTTP_WORKER_H__
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * - Copyright (C) 2012 Georg Hopp
  8 + * - Copyright © 2012 Georg Hopp
9 9 * -
10 10 * - This program is free software: you can redistribute it and/or modify
11 11 * - it under the terms of the GNU General Public License as published by
... ...
... ... @@ -8,7 +8,7 @@
8 8 * \author Georg Hopp
9 9 *
10 10 * \copyright
11   - * Copyright (C) 2012 Georg Hopp
  11 + * Copyright © 2012 Georg Hopp
12 12 *
13 13 * This program is free software: you can redistribute it and/or modify
14 14 * it under the terms of the GNU General Public License as published by
... ...
  1 +/**
  2 + * \file
  3 + * The authentication interface.
  4 + *
  5 + * This is the authentication interface. It's only pupose is to
  6 + * authenticate someone or somewhat. It is called AUTH.
  7 + * The concrete access rights are managed within a class called ACL.
  8 + *
  9 + * \author Georg Hopp
  10 + *
  11 + * \copyright
  12 + * Copyright © 2012 Georg Hopp
  13 + *
  14 + * This program is free software: you can redistribute it and/or modify
  15 + * it under the terms of the GNU General Public License as published by
  16 + * the Free Software Foundation, either version 3 of the License, or
  17 + * (at your option) any later version.
  18 + *
  19 + * This program is distributed in the hope that it will be useful,
  20 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  22 + * GNU General Public License for more details.
  23 + *
  24 + * You should have received a copy of the GNU General Public License
  25 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  26 + */
  27 +
  28 +#ifndef __INTERFACE_AUTH_H__
  29 +#define __INTERFACE_AUTH_H__
  30 +
  31 +#include <stdarg.h>
  32 +
  33 +#include "interface.h"
  34 +#include "credential.h"
  35 +
  36 +typedef int (* fptr_authenticate)(void *, Credential);
  37 +
  38 +extern const struct interface i_Auth;
  39 +
  40 +struct i_Auth {
  41 + const struct interface * const _;
  42 + fptr_authenticate authenticate;
  43 +};
  44 +
  45 +extern int authenticate(void *, Credential);
  46 +
  47 +#endif // __INTERFACE_AUTH_H__
  48 +
  49 +// vim: set ts=4 sw=4:
... ...
... ... @@ -7,7 +7,7 @@
7 7 * \author Georg Hopp
8 8 *
9 9 * \copyright
10   - * Copyright (C) 2012 Georg Hopp
  10 + * Copyright © 2012 Georg Hopp
11 11 *
12 12 * This program is free software: you can redistribute it and/or modify
13 13 * it under the terms of the GNU General Public License as published by
... ...
  1 +/**
  2 + * \file
  3 + * The logger interface.
  4 + *
  5 + * \author Georg Hopp
  6 + *
  7 + * \copyright
  8 + * Copyright © 2012 Georg Hopp
  9 + *
  10 + * This program is free software: you can redistribute it and/or modify
  11 + * it under the terms of the GNU General Public License as published by
  12 + * the Free Software Foundation, either version 3 of the License, or
  13 + * (at your option) any later version.
  14 + *
  15 + * This program is distributed in the hope that it will be useful,
  16 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18 + * GNU General Public License for more details.
  19 + *
  20 + * You should have received a copy of the GNU General Public License
  21 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22 + */
  23 +
  24 +#ifndef __INTERFACE_HASHABLE_H__
  25 +#define __INTERFACE_HASHABLE_H__
  26 +
  27 +#include "interface.h"
  28 +
  29 +typedef unsigned long (* fptr_hashableGetHash)(void *);
  30 +typedef void (* fptr_hashableHandleDouble)(void *, void *);
  31 +
  32 +extern const struct interface i_Hashable;
  33 +
  34 +struct i_Hashable {
  35 + const struct interface * const _;
  36 + fptr_hashableGetHash getHash;
  37 + fptr_hashableHandleDouble handleDouble;
  38 +};
  39 +
  40 +extern unsigned long hashableGetHash(void *);
  41 +extern void hashableHandleDouble(void *, void *);
  42 +
  43 +#endif // __INTERFACE_HASHABLE_H__
  44 +
  45 +// vim: set ts=4 sw=4:
... ...
... ... @@ -7,7 +7,7 @@
7 7 * \author Georg Hopp
8 8 *
9 9 * \copyright
10   - * Copyright (C) 2012 Georg Hopp
  10 + * Copyright © 2012 Georg Hopp
11 11 *
12 12 * This program is free software: you can redistribute it and/or modify
13 13 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -6,7 +6,7 @@
6 6 * \author Georg Hopp
7 7 *
8 8 * \copyright
9   - * Copyright (C) 2012 Georg Hopp
  9 + * Copyright © 2012 Georg Hopp
10 10 *
11 11 * This program is free software: you can redistribute it and/or modify
12 12 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -6,7 +6,7 @@
6 6 * \author Georg Hopp
7 7 *
8 8 * \copyright
9   - * Copyright (C) 2012 Georg Hopp
  9 + * Copyright © 2012 Georg Hopp
10 10 *
11 11 * This program is free software: you can redistribute it and/or modify
12 12 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -6,7 +6,7 @@
6 6 * \author Georg Hopp
7 7 *
8 8 * \copyright
9   - * Copyright (C) 2012 Georg Hopp
  9 + * Copyright © 2012 Georg Hopp
10 10 *
11 11 * This program is free software: you can redistribute it and/or modify
12 12 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -7,7 +7,7 @@
7 7 * \author Georg Hopp
8 8 *
9 9 * \copyright
10   - * Copyright (C) 2012 Georg Hopp
  10 + * Copyright © 2012 Georg Hopp
11 11 *
12 12 * This program is free software: you can redistribute it and/or modify
13 13 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -6,7 +6,7 @@
6 6 * \author Georg Hopp
7 7 *
8 8 * \copyright
9   - * Copyright (C) 2012 Georg Hopp
  9 + * Copyright © 2012 Georg Hopp
10 10 *
11 11 * This program is free software: you can redistribute it and/or modify
12 12 * it under the terms of the GNU General Public License as published by
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
1 23 #ifndef __STREAM_H__
2 24 #define __STREAM_H__
3 25
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
1 23 #ifndef __UTILS_HTTP_H__
2 24 #define __UTILS_HTTP_H__
3 25
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -6,6 +6,8 @@ IFACE = interface/class.c interface/stream_reader.c interface/logger.c \
6 6 interface/subject.c interface/observer.c interface.c
7 7 SOCKET = socket.c socket/accept.c socket/connect.c socket/listen.c
8 8 STREAM = stream.c stream/read.c stream/write.c
  9 +HASH = hash.c hash/add.c hash/get.c hash/delete.c \
  10 + hash/each.c interface/hashable.c hash_value.c
9 11 SERVER = server.c server/run.c server/close_conn.c server/poll.c \
10 12 server/handle_accept.c server/read.c server/write.c
11 13 LOGGER = logger.c logger/stderr.c logger/syslog.c
... ... @@ -30,13 +32,15 @@ RESP = http/response.c \
30 32 http/response/403.c \
31 33 http/response/login_form.c \
32 34 http/response/asset.c \
33   - http/response/me.c \
34   - http/response/randval.c
  35 + http/response/randval.c \
  36 + http/response/session.c
35 37 PARSER = http/parser.c \
36 38 http/parser/parse.c \
37 39 http/parser/new_message.c \
38 40 http/parser/header.c \
39   - http/parser/body.c
  41 + http/parser/body.c \
  42 + http/parser/request_vars.c \
  43 + http/parser/post_vars.c
40 44 WRITER = http/writer.c \
41 45 http/writer/write.c
42 46 WORKER = http/worker.c \
... ... @@ -44,7 +48,7 @@ WORKER = http/worker.c \
44 48 http/worker/write.c \
45 49 http/worker/get_asset.c \
46 50 http/worker/add_common_header.c
47   -HEADER = http/header.c http/header/get.c http/header/add.c \
  51 +HEADER = http/header.c \
48 52 http/header/to_string.c
49 53 SESSION = session.c session/add.c session/get.c session/delete.c
50 54 UTILS = utils/hash.c \
... ... @@ -52,15 +56,16 @@ UTILS = utils/hash.c \
52 56 utils/http.c \
53 57 utils/daemonize.c \
54 58 utils/signalHandling.c
  59 +AUTH = interface/auth.c auth/ldap.c credential.c
55 60
56 61
57 62 AM_CFLAGS = -Wall -I ../include/
58 63
59   -bin_PROGRAMS = taskrambler
  64 +bin_PROGRAMS = webgameserver
60 65
61   -taskrambler_SOURCES = taskrambler.c \
  66 +webgameserver_SOURCES = webgameserver.c \
62 67 $(IFACE) $(SOCKET) $(SERVER) $(LOGGER) $(MSG) $(REQ) \
63 68 $(WRITER) $(RESP) $(HEADER) $(PARSER) $(WORKER) $(CB) \
64   - $(UTILS) $(MSGQ) $(SESSION) $(STREAM)
65   -taskrambler_CFLAGS = -Wall -I ../include/
66   -taskrambler_LDFLAGS = -lrt -lssl
  69 + $(UTILS) $(MSGQ) $(SESSION) $(STREAM) $(HASH) $(AUTH)
  70 +webgameserver_CFLAGS = -Wall -I ../include/
  71 +webgameserver_LDFLAGS = -lrt -lssl -lldap
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdarg.h>
  24 +#include <stdlib.h>
  25 +#include <string.h>
  26 +#include <stdio.h>
  27 +#include <ldap.h>
  28 +
  29 +#include "auth/ldap.h"
  30 +#include "class.h"
  31 +#include "credential.h"
  32 +#include "interface/class.h"
  33 +#include "interface/auth.h"
  34 +
  35 +#include "utils/memory.h"
  36 +#include "commons.h"
  37 +
  38 +static
  39 +int
  40 +authLdapCtor(void * _this, va_list * params)
  41 +{
  42 + AuthLdap this = _this;
  43 + char * url = va_arg(*params, char*);
  44 + char * base_dn;
  45 +
  46 + this->url = malloc(strlen(url) + 1);
  47 + strcpy(this->url, url);
  48 +
  49 + this->version = 3;
  50 +
  51 + base_dn = va_arg(* params, char *);
  52 + this->nbase_dn = va_arg(* params, size_t);
  53 +
  54 + this->base_dn = malloc(this->nbase_dn + 1);
  55 + this->base_dn[this->nbase_dn] = 0;
  56 + memcpy(this->base_dn, base_dn, this->nbase_dn);
  57 +
  58 + return 0;
  59 +}
  60 +
  61 +static
  62 +void
  63 +authLdapDtor(void * _this)
  64 +{
  65 + AuthLdap this = _this;
  66 +
  67 + FREE(this->base_dn);
  68 + FREE(this->url);
  69 +}
  70 +
  71 +static
  72 +int
  73 +authLdapAuthenticate(void * _this, Credential cred)
  74 +{
  75 + AuthLdap this = _this;
  76 + char who[256];
  77 + char * who_ptr = who;
  78 + int ldap_err;
  79 +
  80 + if (CRED_PASSWORD != cred->type) {
  81 + return FALSE;
  82 + }
  83 +
  84 + ldap_initialize(&(this->ldap), this->url);
  85 + ldap_set_option(this->ldap, LDAP_OPT_PROTOCOL_VERSION, &(this->version));
  86 +
  87 + memcpy(who_ptr, "cn=", sizeof("cn=") - 1);
  88 + who_ptr += sizeof("cn=") - 1;
  89 + memcpy(who_ptr, CRED_PWD(cred).user, CRED_PWD(cred).nuser);
  90 + who_ptr += CRED_PWD(cred).nuser;
  91 + *who_ptr++ = ',';
  92 + memcpy(who_ptr, this->base_dn, this->nbase_dn);
  93 + who_ptr[this->nbase_dn] = 0;
  94 +
  95 + ldap_err = ldap_simple_bind_s(this->ldap, who, CRED_PWD(cred).pass);
  96 + if (0 == ldap_err) {
  97 + ldap_unbind_s(this->ldap);
  98 + //! \todo here we need to get and return the user id
  99 + return TRUE;
  100 + }
  101 +
  102 + fprintf(stderr, "%s\n", ldap_err2string(ldap_err));
  103 + return FALSE;
  104 +}
  105 +
  106 +INIT_IFACE(Class, authLdapCtor, authLdapDtor, NULL);
  107 +INIT_IFACE(Auth, authLdapAuthenticate);
  108 +CREATE_CLASS(AuthLdap, NULL, IFACE(Class), IFACE(Auth));
  109 +
  110 +// vim: set ts=4 sw=4:
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdarg.h>
  24 +#include <sys/types.h>
  25 +#include <stdlib.h>
  26 +#include <string.h>
  27 +
  28 +#include "credential.h"
  29 +#include "class.h"
  30 +#include "interface/class.h"
  31 +
  32 +#include "utils/memory.h"
  33 +
  34 +static
  35 +int
  36 +credentialCtor(void * _this, va_list * params)
  37 +{
  38 + Credential this = _this;
  39 +
  40 + this->type = va_arg(* params, CredentialType);
  41 +
  42 + switch(this->type) {
  43 + case CRED_PASSWORD:
  44 + {
  45 + char * user, *pass;
  46 +
  47 + user = va_arg(* params, char*);
  48 + CRED_PWD(this).nuser = va_arg(* params, size_t);
  49 + pass = va_arg(* params, char*);
  50 + CRED_PWD(this).npass = va_arg(* params, size_t);
  51 +
  52 + CRED_PWD(this).user = malloc(CRED_PWD(this).nuser + 1);
  53 + CRED_PWD(this).user[CRED_PWD(this).nuser] = 0;
  54 + memcpy(CRED_PWD(this).user, user, CRED_PWD(this).nuser);
  55 +
  56 + CRED_PWD(this).pass = malloc(CRED_PWD(this).npass + 1);
  57 + CRED_PWD(this).pass[CRED_PWD(this).npass] = 0;
  58 + memcpy(CRED_PWD(this).pass, pass, CRED_PWD(this).npass);
  59 + }
  60 + break;
  61 +
  62 + default:
  63 + return -1;
  64 + }
  65 +
  66 + return 0;
  67 +}
  68 +
  69 +static
  70 +void
  71 +credentialDtor(void * _this)
  72 +{
  73 + Credential this = _this;
  74 +
  75 + switch(this->type) {
  76 + case CRED_PASSWORD:
  77 + FREE(CRED_PWD(this).user);
  78 + FREE(CRED_PWD(this).pass);
  79 + break;
  80 + }
  81 +}
  82 +
  83 +INIT_IFACE(Class, credentialCtor, credentialDtor, NULL);
  84 +CREATE_CLASS(Credential, NULL, IFACE(Class));
  85 +
  86 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#define _GNU_SOURCE
  24 +
  25 +#include <search.h>
  26 +#include <stdarg.h>
  27 +
  28 +#include "hash.h"
  29 +#include "class.h"
  30 +#include "interface/class.h"
  31 +
  32 +static
  33 +int
  34 +hashCtor(void * _this, va_list * params)
  35 +{
  36 + return 0;
  37 +}
  38 +
  39 +static
  40 +inline
  41 +void
  42 +tDelete(void * node)
  43 +{
  44 + delete(node);
  45 +}
  46 +
  47 +static
  48 +void
  49 +hashDtor(void * _this)
  50 +{
  51 + Hash this = _this;
  52 +
  53 + /**
  54 + * this is a GNU extension...anyway on most non
  55 + * GNUish systems i would not use tsearch anyway
  56 + * as the trees will be unbalanced.
  57 + */
  58 + tdestroy(this->root, tDelete);
  59 +}
  60 +
  61 +INIT_IFACE(Class, hashCtor, hashDtor, NULL);
  62 +CREATE_CLASS(Hash, NULL, IFACE(Class));
  63 +
  64 +// vim: set ts=4 sw=4:
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -21,49 +21,34 @@
21 21 */
22 22
23 23 #include <search.h>
24   -#include <stdio.h>
25   -#include <stdlib.h>
26   -#include <string.h>
27 24
28   -#include "class.h"
  25 +#include "hash.h"
  26 +#include "interface/hashable.h"
29 27 #include "interface/class.h"
30   -#include "http/header.h"
31   -#include "utils/hash.h"
32 28
33 29 static
34 30 inline
35 31 int
36   -comp(const void * _a, const void * _b)
  32 +hashAddComp(const void * a, const void * b)
37 33 {
38   - HttpHeader a = (HttpHeader)_a;
39   - HttpHeader b = (HttpHeader)_b;
40   - return (a->hash < b->hash)? -1 : (a->hash > b->hash)? 1 : 0;
  34 + return hashableGetHash((void*)b) - hashableGetHash((void*)a);
41 35 }
42 36
43   -HttpHeader
44   -httpHeaderAdd(const HttpHeader * root, HttpHeader header)
  37 +void *
  38 +hashAdd(Hash this, void * operand)
45 39 {
46   - HttpHeader * _found = tsearch(header, (void **)root, comp);
47   - HttpHeader found;
  40 + void * found = tsearch(operand, &(this->root), hashAddComp);
48 41
49   - if (NULL == _found) {
  42 + if (NULL == found) {
50 43 return NULL;
51 44 }
52 45
53   - found = *_found;
54   -
55   - if (found != header) {
56   - if (found->cvalue >= N_VALUES) {
57   - return NULL;
58   - }
59   - (found->nvalue)[found->cvalue] = (header->nvalue)[0];
60   - (found->value)[(found->cvalue)++] = (header->value)[0];
61   - found->size += header->size;
62   - (header->value)[0] = NULL;
63   - delete(header);
  46 + if (operand != *(void**)found) {
  47 + hashableHandleDouble(*(void**)found, operand);
  48 + delete(operand);
64 49 }
65 50
66   - return found;
  51 + return *(void**)found;
67 52 }
68 53
69 54 // vim: set ts=4 sw=4:
... ...
1 1 /**
2 2 * \file
3   - * Get a header from a tree containing headers by its name.
4   - * The key for the tree is the hased lowercase header identifier.
5 3 *
6 4 * \author Georg Hopp
7 5 *
8 6 * \copyright
9   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
10 8 *
11 9 * This program is free software: you can redistribute it and/or modify
12 10 * it under the terms of the GNU General Public License as published by
... ... @@ -23,29 +21,27 @@
23 21 */
24 22
25 23 #include <search.h>
26   -#include <stdlib.h>
  24 +#include <sys/types.h>
27 25
28   -#include "http/header.h"
  26 +#include "hash.h"
  27 +#include "interface/hashable.h"
29 28 #include "utils/hash.h"
30 29
31 30 static
32 31 inline
33 32 int
34   -comp(const void * _a, const void * _b)
  33 +hashDeleteComp(const void * a, const void * b)
35 34 {
36   - const unsigned long * a = _a;
37   - HttpHeader b = (HttpHeader)_b;
38   - return (*a < b->hash)? -1 : (*a > b->hash)? 1 : 0;
  35 + return hashableGetHash((void*)b) - *(const unsigned long*)a;
39 36 }
40 37
41   -HttpHeader
42   -httpHeaderGet(const HttpHeader * root, const char * name, size_t nname)
  38 +void *
  39 +hashDelete(Hash this, const char * search, size_t nsearch)
43 40 {
44   - unsigned long hash = sdbm((const unsigned char*)name, nname);
  41 + unsigned long hash = sdbm((const unsigned char *)search, nsearch);
  42 + void * found = tfind(&hash, &(this->root), hashDeleteComp);
45 43
46   - HttpHeader * found = tfind(&hash, (void**)root, comp);
47   -
48   - return (NULL != found)? *found : NULL;
  44 + return (NULL != found)? *(void**)found : NULL;
49 45 }
50 46
51 47 // vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <search.h>
  24 +
  25 +#include "hash.h"
  26 +
  27 +static void (*cb)(void*);
  28 +
  29 +static
  30 +inline
  31 +void
  32 +walk(const void * node, const VISIT which, const int depth)
  33 +{
  34 + if (endorder == which || leaf == which) {
  35 + cb(*(void**)node);
  36 + }
  37 +}
  38 +
  39 +void
  40 +hashEach(Hash this, void (*callback)(const void*))
  41 +{
  42 + cb = callback;
  43 +
  44 + twalk(this->root, walk);
  45 +}
  46 +
  47 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <search.h>
  24 +#include <sys/types.h>
  25 +
  26 +#include "hash.h"
  27 +#include "interface/hashable.h"
  28 +#include "utils/hash.h"
  29 +
  30 +static
  31 +inline
  32 +int
  33 +hashGetComp(const void * a, const void * b)
  34 +{
  35 + return hashableGetHash((void*)b) - *(const unsigned long*)a;
  36 +}
  37 +
  38 +void *
  39 +hashGet(Hash this, const char * search, size_t nsearch)
  40 +{
  41 + unsigned long hash = sdbm((const unsigned char *)search, nsearch);
  42 + void * found = tfind(&hash, &(this->root), hashGetComp);
  43 +
  44 + return (NULL != found)? *(void**)found : NULL;
  45 +}
  46 +
  47 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdarg.h>
  24 +#include <stdlib.h>
  25 +#include <string.h>
  26 +#include <sys/types.h>
  27 +
  28 +#include "hash_value.h"
  29 +#include "utils/hash.h"
  30 +#include "utils/memory.h"
  31 +#include "commons.h"
  32 +#include "interface/class.h"
  33 +#include "interface/hashable.h"
  34 +
  35 +static
  36 +int
  37 +hashValueCtor(void * _this, va_list * params)
  38 +{
  39 + HashValue this = _this;
  40 + char * key = va_arg(* params, char*);
  41 + void * value;
  42 +
  43 + this->nkey = va_arg(* params, size_t);
  44 + value = va_arg(* params, void*);
  45 + this->nvalue = va_arg(* params, size_t);
  46 +
  47 + this->key = malloc(this->nkey + 1);
  48 + this->key[this->nkey] = 0;
  49 + memcpy(this->key, key, this->nkey);
  50 +
  51 + this->hash = sdbm((unsigned char *)this->key, this->nkey);
  52 +
  53 + if (NULL != value) {
  54 + this->value = malloc(this->nvalue + 1);
  55 + ((char*)this->value)[this->nvalue] = 0;
  56 + memcpy(this->value, value, this->nvalue);
  57 + }
  58 +
  59 + return 0;
  60 +}
  61 +
  62 +static
  63 +void
  64 +hashValueDtor(void * _this)
  65 +{
  66 + HashValue this = _this;
  67 +
  68 + FREE(this->key);
  69 + FREE(this->value);
  70 +}
  71 +
  72 +static
  73 +unsigned long
  74 +hashValueGetHash(void * _this)
  75 +{
  76 + HashValue this = _this;
  77 +
  78 + return this->hash;
  79 +}
  80 +
  81 +static
  82 +void
  83 +hashValueHandleDouble(void * _this, void * _double)
  84 +{
  85 + HashValue this = _this;
  86 + HashValue doub = _double;
  87 + void * tmp_value;
  88 + size_t tmp_nvalue;
  89 +
  90 + /**
  91 + * here we swap the internal data of both objects,
  92 + * effectively overwriting the old entry. We need not
  93 + * to free anything here as _double will be deleted
  94 + * afterwards anyway (\see hash/add.c).
  95 + */
  96 + tmp_value = this->value;
  97 + this->value = doub->value;
  98 + doub->value = tmp_value;
  99 +
  100 + tmp_nvalue = this->nvalue;
  101 + this->nvalue = doub->nvalue;
  102 + doub->nvalue = tmp_nvalue;
  103 +}
  104 +
  105 +INIT_IFACE(Class, hashValueCtor, hashValueDtor, NULL);
  106 +INIT_IFACE(Hashable, hashValueGetHash, hashValueHandleDouble);
  107 +CREATE_CLASS(HashValue, NULL, IFACE(Class), IFACE(Hashable));
  108 +
  109 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdlib.h>
  24 +#include <string.h>
  25 +#include <stdarg.h>
  26 +#include <sys/types.h>
  27 +
  28 +#include "cookie.h"
  29 +#include "interface/class.h"
  30 +#include "interface/hashable"
  31 +
  32 +#include "utils/hash.h"
  33 +#include "utils/memory.h"
  34 +#include "commons.h"
  35 +
  36 +
  37 +static
  38 +int
  39 +httpCookieCtor(void * _this, va_list * params)
  40 +{
  41 + HttpCookie this = _this;
  42 + char * key = va_arg(* params, char*);
  43 + char * value;
  44 +
  45 + this->nkey = va_arg(* params, size_t);
  46 + value = va_arg(* params, char*);
  47 + this->nvalue = va_arg(* params, size_t);
  48 +
  49 + this->key = malloc(this->nkey + 1);
  50 + this->key[this->nkey] = 0;
  51 + memcpy(this->key, key, this->nkey);
  52 +
  53 + this->value = malloc(this->nvalue + 1);
  54 + this->value[this->nvalue] = 0;
  55 + memcpy(this->value, value, this->nvalue);
  56 +
  57 + this->hash = sdbm((unsigned char *)key, nkey);
  58 +
  59 + return 0;
  60 +}
  61 +
  62 +static
  63 +void
  64 +httpCookieDtor(void * _this, va_list * params)
  65 +{
  66 + HttpCookie this = _this;
  67 +
  68 + FREE(this->key);
  69 + FREE(this->value);
  70 + FREE(this->domain);
  71 + FREE(this->path);
  72 +}
  73 +
  74 +static
  75 +unsigned long
  76 +httpCookieGetHash(void * _this)
  77 +{
  78 + HttpCookie this = _this;
  79 +
  80 + return this->hash;
  81 +}
  82 +
  83 +static
  84 +void
  85 +httpCookieHandleDouble(void * _this, void * _double)
  86 +{
  87 + HttpCookie this = _this;
  88 + HttpCookie doub = _double;
  89 +
  90 + SWAP(char*, this->key, doub->key);
  91 + SWAP(char*, this->value, doub->value);
  92 + SWAP(char*, this->domain, doub->domain);
  93 + SWAP(char*, this->path, doub->path);
  94 +
  95 + SWAP(char*, this->nkey, doub->nkey);
  96 + SWAP(char*, this->nvalue, doub->nvalue);
  97 +}
  98 +
  99 +
  100 +INIT_IFACE(Class, httpCookieCtor, httpCookieDtor, NULL);
  101 +INIT_IFACE(Hashable, httpCookieGetHash, httpCookieHandleDouble);
  102 +CREATE_CLASS(HttpCookie, NULL, IFACE(Class), IFACE(Hashable));
  103 +
  104 +// vim: set ts=4 sw=4:
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ... @@ -27,6 +27,7 @@
27 27 #include "class.h"
28 28 #include "interface/class.h"
29 29 #include "http/header.h"
  30 +#include "interface/hashable.h"
30 31
31 32 #include "utils/hash.h"
32 33 #include "utils/memory.h"
... ... @@ -72,7 +73,35 @@ httpHeaderDtor(void * _this)
72 73 }
73 74 }
74 75
  76 +static
  77 +unsigned long
  78 +httpHeaderGetHash(void * _this)
  79 +{
  80 + HttpHeader this = _this;
  81 +
  82 + return this->hash;
  83 +}
  84 +
  85 +static
  86 +void
  87 +httpHeaderHandleDouble(void * _this, void * _double)
  88 +{
  89 + HttpHeader this = _this;
  90 + HttpHeader doub = _double;
  91 +
  92 + if (this->cvalue >= N_VALUES) {
  93 + //! \todo do dome error logging...or change to HEAP
  94 + return;
  95 + }
  96 +
  97 + (this->nvalue)[this->cvalue] = (doub->nvalue)[0];
  98 + (this->value)[(this->cvalue)++] = (doub->value)[0];
  99 + this->size += doub->size;
  100 + (doub->value)[0] = NULL;
  101 +}
  102 +
75 103 INIT_IFACE(Class, httpHeaderCtor, httpHeaderDtor, NULL);
76   -CREATE_CLASS(HttpHeader, NULL, IFACE(Class));
  104 +INIT_IFACE(Hashable, httpHeaderGetHash, httpHeaderHandleDouble);
  105 +CREATE_CLASS(HttpHeader, NULL, IFACE(Class), IFACE(Hashable));
77 106
78 107 // vim: set ts=4 sw=4:
... ...
... ... @@ -5,7 +5,7 @@
5 5 * \author Georg Hopp
6 6 *
7 7 * \copyright
8   - * Copyright (C) 2012 Georg Hopp
  8 + * Copyright © 2012 Georg Hopp
9 9 *
10 10 * This program is free software: you can redistribute it and/or modify
11 11 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -32,20 +32,12 @@
32 32
33 33 #include "class.h"
34 34 #include "interface/class.h"
35   -
  35 +#include "hash.h"
36 36 #include "http/message.h"
37 37 #include "utils/memory.h"
38 38
39 39
40 40 static
41   -inline
42   -void
43   -tDelete(void * node)
44   -{
45   - delete(node);
46   -}
47   -
48   -static
49 41 int
50 42 httpMessageCtor(void * _this, va_list * params)
51 43 {
... ... @@ -55,6 +47,9 @@ httpMessageCtor(void * _this, va_list * params)
55 47 this->version = calloc(1, strlen(version)+1);
56 48 strcpy(this->version, version);
57 49
  50 + this->header = new(Hash);
  51 + this->cookies = new(Hash);
  52 +
58 53 return 0;
59 54 }
60 55
... ... @@ -64,14 +59,10 @@ httpMessageDtor(void * _this)
64 59 {
65 60 HttpMessage this = _this;
66 61
67   - FREE(this->version);
  62 + delete(this->header);
  63 + delete(this->cookies);
68 64
69   - /**
70   - * this is a GNU extension...anyway on most non
71   - * GNUish systems i would not use tsearch anyway
72   - * as the trees will be unbalanced.
73   - */
74   - tdestroy(this->header, tDelete);
  65 + FREE(this->version);
75 66
76 67 switch (this->type) {
77 68 case HTTP_MESSAGE_BUFFERED:
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -31,6 +31,7 @@
31 31 #include "utils/memory.h"
32 32
33 33 #include "commons.h"
  34 +#include "hash.h"
34 35
35 36 char
36 37 httpMessageHasKeepAlive(HttpMessage message)
... ... @@ -39,7 +40,7 @@ httpMessageHasKeepAlive(HttpMessage message)
39 40 size_t size;
40 41 char * value;
41 42
42   - header = httpHeaderGet(&(message->header), CSTRA("connection"));
  43 + header = hashGet(message->header, CSTRA("connection"));
43 44
44 45 if (NULL == header) {
45 46 return 0;
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -28,17 +28,16 @@
28 28 #include "http/response.h"
29 29 #include "http/header.h"
30 30 #include "interface/http_intro.h"
  31 +#include "hash.h"
31 32
32 33 static size_t size;
33 34
34 35 static
35 36 inline
36 37 void
37   -addHeaderSize(const void * node, const VISIT which, const int depth)
  38 +addHeaderSize(const void * node)
38 39 {
39   - if (endorder == which || leaf == which) {
40   - size += (*(HttpHeader *)node)->size;
41   - }
  40 + size += ((HttpHeader)node)->size;
42 41 }
43 42
44 43 size_t
... ... @@ -46,7 +45,7 @@ httpMessageHeaderSizeGet(HttpMessage message)
46 45 {
47 46 size = httpIntroSizeGet(message);
48 47
49   - twalk(message->header, addHeaderSize);
  48 + hashEach(message->header, addHeaderSize);
50 49 size += 2;
51 50
52 51 return size;
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -27,15 +27,16 @@
27 27 #include "http/response.h"
28 28 #include "http/header.h"
29 29 #include "interface/http_intro.h"
  30 +#include "hash.h"
30 31
31 32 static char * string;
32 33
  34 +static
  35 +inline
33 36 void
34   -addHeaderString(const void * node, const VISIT which, const int depth)
  37 +addHeaderString(const void * node)
35 38 {
36   - if (endorder == which || leaf == which) {
37   - string += httpHeaderToString(*(HttpHeader *)node, string);
38   - }
  39 + string += httpHeaderToString((HttpHeader)node, string);
39 40 }
40 41
41 42 char *
... ... @@ -45,7 +46,7 @@ httpMessageHeaderToString(HttpMessage response, char * _string)
45 46
46 47 string = httpIntroToString(response, _string);
47 48
48   - twalk(message->header, addHeaderString);
  49 + hashEach(message->header, addHeaderString);
49 50
50 51 *string++ = '\r';
51 52 *string++ = '\n';
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -28,7 +28,7 @@
28 28 #include "http/parser.h"
29 29 #include "cbuf.h"
30 30
31   -#define MIN(a,b) (((a) < (b))? (a) : (b))
  31 +#include "commons.h"
32 32
33 33 size_t
34 34 httpParserBody(HttpParser this, const char * buf, size_t nbuf)
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -29,6 +29,9 @@
29 29 #include "http/header.h"
30 30 #include "http/parser.h"
31 31 #include "http/message.h"
  32 +#include "http/request.h"
  33 +#include "hash.h"
  34 +#include "hash_value.h"
32 35
33 36 void
34 37 httpParserHeader(
... ... @@ -59,8 +62,43 @@ httpParserHeader(
59 62 current->dbody = 0;
60 63 }
61 64
62   - httpHeaderAdd(
63   - &(current->header),
  65 + if (0 == strncasecmp("cookie", name, nname-1)) {
  66 + HttpRequest request = (HttpRequest)this->current;
  67 + char * pair = value;
  68 + ssize_t togo = lend - value;
  69 +
  70 + while(NULL != pair && 0 < togo) {
  71 + char * key = pair;
  72 + char * eqsign;
  73 + char * val;
  74 + size_t nval;
  75 +
  76 + for (; *key == ' ' && key < lend; key++, togo--);
  77 + eqsign = memchr(key, '=', togo);
  78 +
  79 + if (NULL == eqsign) {
  80 + break;
  81 + }
  82 +
  83 + togo -= (eqsign - key);
  84 + pair = memchr(eqsign, ';', togo);
  85 +
  86 + if (NULL == pair) {
  87 + pair = (char *)lend;
  88 + }
  89 +
  90 + nval = pair-eqsign-1;
  91 + val = (0 != nval)? eqsign+1 : NULL;
  92 +
  93 + hashAdd(request->cookies,
  94 + new(HashValue, key, eqsign-key, val, nval));
  95 +
  96 + pair++;
  97 + togo -= (pair - eqsign);
  98 + }
  99 + }
  100 +
  101 + hashAdd(current->header,
64 102 new(HttpHeader, name, nname, value, lend - value));
65 103 }
66 104
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
1 23 #include "http/parser.h"
2 24
3 25 #include "utils/http.h"
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -23,11 +23,18 @@
23 23 #include <stdlib.h>
24 24
25 25 #include "http/parser.h"
  26 +#include "http/header.h"
26 27 #include "interface/class.h"
27 28 #include "interface/http_intro.h"
28 29 #include "cbuf.h"
29 30 #include "stream.h"
30 31
  32 +#include "utils/memory.h"
  33 +#include "commons.h"
  34 +
  35 +#define MIN(a,b) ((a)<(b)? (a) : (b))
  36 +
  37 +
31 38 ssize_t
32 39 httpParserParse(void * _this, Stream st)
33 40 {
... ... @@ -92,6 +99,7 @@ httpParserParse(void * _this, Stream st)
92 99 this->ourLock = FALSE;
93 100 return -1;
94 101 }
  102 + httpParserRequestVars(this);
95 103
96 104 this->state = HTTP_MESSAGE_INTRO_DONE;
97 105 break;
... ... @@ -141,6 +149,23 @@ httpParserParse(void * _this, Stream st)
141 149 break;
142 150
143 151 case HTTP_MESSAGE_DONE:
  152 + {
  153 + HttpHeader enc = hashGet(
  154 + this->current->header,
  155 + CSTRA("content-type"));
  156 +
  157 + /**
  158 + * do we have form data??
  159 + */
  160 + if (NULL != enc && 0 == strncasecmp(
  161 + "application/x-www-form-urlencoded",
  162 + enc->value[0],
  163 + MIN(sizeof("application/x-www-form-urlencoded")-1,
  164 + enc->nvalue[0]))) {
  165 + //!> then parse them...
  166 + httpParserPostVars(this);
  167 + }
  168 +
144 169 /**
145 170 * enqueue current request
146 171 */
... ... @@ -151,7 +176,7 @@ httpParserParse(void * _this, Stream st)
151 176 * prepare for next request
152 177 */
153 178 this->state = HTTP_MESSAGE_GARBAGE;
154   -
  179 + }
155 180 break;
156 181
157 182 default:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <string.h>
  24 +#include <sys/types.h>
  25 +
  26 +#include "http/parser.h"
  27 +#include "http/request.h"
  28 +#include "hash_value.h"
  29 +#include "hash.h"
  30 +#include "interface/class.h"
  31 +
  32 +/**
  33 + * \todo this is very similar to other pair parsing
  34 + * things... key1=val1<delim>key2=val2<delim>...keyn=valn
  35 + * Generalize this!!!!
  36 + */
  37 +void
  38 +httpParserPostVars(HttpParser this)
  39 +{
  40 + HttpRequest request = (HttpRequest)this->current;
  41 + char * pair = this->current->body;
  42 + ssize_t togo = this->current->nbody;
  43 +
  44 + while(NULL != pair && 0 < togo) {
  45 + char * key = pair;
  46 + char * eqsign = memchr(key, '=', togo);
  47 + char * value;
  48 + size_t nvalue;
  49 +
  50 + if (NULL == eqsign) {
  51 + return;
  52 + }
  53 +
  54 + togo -= (eqsign - key);
  55 + pair = memchr(eqsign, '&', togo);
  56 +
  57 + if (NULL == pair) {
  58 + pair = &(this->current->body[this->current->nbody]);
  59 + }
  60 +
  61 + nvalue = pair-eqsign-1;
  62 + value = (0 != nvalue)? eqsign+1 : NULL;
  63 +
  64 + hashAdd(request->post,
  65 + new(HashValue, key, eqsign-key, value, nvalue));
  66 +
  67 + pair++;
  68 + togo -= (pair - eqsign);
  69 + }
  70 +}
  71 +
  72 +// vim: set ts=4 sw=4:
... ...
  1 +/**
  2 + * \file
  3 + *
  4 + * \author Georg Hopp
  5 + *
  6 + * \copyright
  7 + * Copyright © 2012 Georg Hopp
  8 + *
  9 + * This program is free software: you can redistribute it and/or modify
  10 + * it under the terms of the GNU General Public License as published by
  11 + * the Free Software Foundation, either version 3 of the License, or
  12 + * (at your option) any later version.
  13 + *
  14 + * This program is distributed in the hope that it will be useful,
  15 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17 + * GNU General Public License for more details.
  18 + *
  19 + * You should have received a copy of the GNU General Public License
  20 + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  21 + */
  22 +
  23 +#include <stdlib.h>
  24 +#include <string.h>
  25 +#include <sys/types.h>
  26 +
  27 +#include "http/parser.h"
  28 +#include "http/request.h"
  29 +#include "hash_value.h"
  30 +#include "hash.h"
  31 +#include "interface/class.h"
  32 +
  33 +void
  34 +httpParserRequestVars(HttpParser this)
  35 +{
  36 + HttpRequest request = (HttpRequest)this->current;
  37 + char * delim = strchr(request->uri, '?');
  38 +
  39 + if (NULL == delim) {
  40 + delim = request->uri + strlen(request->uri);
  41 + }
  42 +
  43 + request->path = malloc(delim - request->uri + 1);
  44 + request->path[delim - request->uri] = 0;
  45 + memcpy(request->path, request->uri, delim - request->uri);
  46 +
  47 + while(NULL != delim && 0 != *delim) {
  48 + char * key = delim + 1;
  49 + char * eqsign = strchr(key, '=');
  50 + char * value;
  51 + size_t nvalue;
  52 +
  53 + if (NULL == eqsign) {
  54 + return;
  55 + }
  56 +
  57 + delim = strchr(eqsign, '&');
  58 +
  59 + if (NULL == delim) {
  60 + delim = key + strlen(key);
  61 + }
  62 +
  63 + nvalue = delim-eqsign-1;
  64 + value = (0 != nvalue)? eqsign+1 : NULL;
  65 +
  66 + hashAdd(request->get,
  67 + new(HashValue, key, eqsign-key, value, nvalue));
  68 + }
  69 +}
  70 +
  71 +// vim: set ts=4 sw=4:
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -56,6 +56,10 @@ httpRequestCtor(void * _this, va_list * params)
56 56 this->uri[ulen] = 0;
57 57 memcpy(this->uri, uri, ulen);
58 58
  59 + this->get = new(Hash);
  60 + this->post = new(Hash);
  61 + this->cookies = new(Hash);
  62 +
59 63 return 0;
60 64 }
61 65
... ... @@ -65,8 +69,13 @@ httpRequestDtor(void * _this)
65 69 {
66 70 HttpRequest this = _this;
67 71
  72 + delete(this->get);
  73 + delete(this->post);
  74 + delete(this->cookies);
  75 +
68 76 FREE(this->uri);
69 77 FREE(this->method);
  78 + FREE(this->path);
70 79
71 80 PARENTCALL(_this, Class, dtor);
72 81 }
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -30,6 +30,7 @@
30 30 #include "http/header.h"
31 31
32 32 #include "utils/memory.h"
  33 +#include "hash.h"
33 34
34 35 HttpResponse
35 36 httpResponse304(
... ... @@ -47,11 +48,11 @@ httpResponse304(
47 48 message->nbody = 0;
48 49 message->body = NULL;
49 50
50   - httpHeaderAdd(&(message->header),
  51 + hashAdd(message->header,
51 52 new(HttpHeader, CSTRA("Content-Type"), mime, nmime));
52   - httpHeaderAdd(&(message->header),
  53 + hashAdd(message->header,
53 54 new(HttpHeader, CSTRA("ETag"), etag, netag));
54   - httpHeaderAdd(&(message->header),
  55 + hashAdd(message->header,
55 56 new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime));
56 57
57 58 return response;
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -33,6 +33,7 @@
33 33 #include "http/header.h"
34 34
35 35 #include "utils/memory.h"
  36 +#include "hash.h"
36 37
37 38 #define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \
38 39 "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \
... ... @@ -52,7 +53,7 @@ httpResponse404()
52 53 response = new(HttpResponse, "HTTP/1.1", 404, "Not Found");
53 54 message = (HttpMessage)response;
54 55
55   - httpHeaderAdd(&(message->header),
  56 + hashAdd(message->header,
56 57 new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
57 58
58 59 message->type = HTTP_MESSAGE_BUFFERED;
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -36,7 +36,7 @@
36 36 #include "http/header.h"
37 37
38 38 #include "utils/memory.h"
39   -
  39 +#include "hash.h"
40 40
41 41 HttpResponse
42 42 httpResponseAsset(
... ... @@ -74,11 +74,11 @@ httpResponseAsset(
74 74 message->handle = new(Stream, STREAM_FD, handle);
75 75 message->nbody = st.st_size;
76 76
77   - httpHeaderAdd(&(message->header),
  77 + hashAdd(message->header,
78 78 new(HttpHeader, CSTRA("Content-Type"), mime, nmime));
79   - httpHeaderAdd(&(message->header),
  79 + hashAdd(message->header,
80 80 new(HttpHeader, CSTRA("ETag"), etag, netag));
81   - httpHeaderAdd(&(message->header),
  81 + hashAdd(message->header,
82 82 new(HttpHeader, CSTRA("Last-Modified"), mtime, nmtime));
83 83
84 84 return response;
... ...
... ... @@ -4,7 +4,7 @@
4 4 * \author Georg Hopp
5 5 *
6 6 * \copyright
7   - * Copyright (C) 2012 Georg Hopp
  7 + * Copyright © 2012 Georg Hopp
8 8 *
9 9 * This program is free software: you can redistribute it and/or modify
10 10 * it under the terms of the GNU General Public License as published by
... ... @@ -34,6 +34,7 @@
34 34 #include "http/header.h"
35 35
36 36 #include "utils/memory.h"
  37 +#include "hash.h"
37 38
38 39 #define RESP_DATA "<form action=\"/me/\" method=\"POST\">" \
39 40 "<input name=\"username\" type=\"text\" />" \
... ... @@ -49,7 +50,7 @@ httpResponseLoginForm()
49 50 response = new(HttpResponse, "HTTP/1.1", 200, "OK");
50 51 message = (HttpMessage)response;
51 52
52   - httpHeaderAdd(&(message->header),
  53 + hashAdd(message->header,
53 54 new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
54 55
55 56 message->type = HTTP_MESSAGE_BUFFERED;
... ...
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright (C) 2012 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -#include <stdlib.h>
24   -#include <string.h>
25   -#include <stdio.h>
26   -#include <time.h>
27   -#include <sys/types.h>
28   -
29   -#include "class.h"
30   -#include "interface/class.h"
31   -
32   -#include "http/response.h"
33   -#include "http/message.h"
34   -#include "http/header.h"
35   -
36   -#include "utils/memory.h"
37   -
38   -
39   -#define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \
40   - "<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \
41   - " \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \
42   - "<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" \
43   - "<head>" \
44   - "<title>My own little Web-App</title>" \
45   - "<style type=\"text/css\">" \
46   - "div#randval {" \
47   - "left: 200px;" \
48   - "top: 100px;" \
49   - "position: fixed;" \
50   - "background-color: white;" \
51   - "border: 1px solid black;" \
52   - "}" \
53   - "div.hide#randval {" \
54   - "top: -500px;" \
55   - "}" \
56   - ".small {" \
57   - "font-size: small;" \
58   - "}" \
59   - "</style>" \
60   - "<script type=\"text/javascript\" src=\"/jquery/\"></script>" \
61   - "<script>" \
62   - "$(document).ready(function() {" \
63   - "var intervalId;" \
64   - "var vnext = 0;" \
65   - "var clickclose = function() {" \
66   - "clearInterval(intervalId);" \
67   - "vnext = 0;" \
68   - "$(\"#randval\").addClass(\"hide\");" \
69   - "};" \
70   - "var counter = function() {" \
71   - "if (0 >= vnext) {" \
72   - "$.getJSON(\"/randval/\", function(data, xhr) {" \
73   - "var date = new Date(data.ctime * 1000);" \
74   - "$(\"#ctime\").empty().append(date.toString());" \
75   - "vnext = data.vnext;" \
76   - "$(\"#value\").empty().append(data.value);" \
77   - "$(\"#vnext\").empty().append(vnext);" \
78   - "$(\"#randval\").on(\"click\", clickclose);" \
79   - "}).error(function(event, request, settings) {" \
80   - "clearInterval(intervalId);" \
81   - "$.get(\"/login/\", function(data) {" \
82   - "$(\"#randval\")" \
83   - ".off(\"click\", clickclose)" \
84   - ".empty().append(data);" \
85   - "});" \
86   - "});" \
87   - "if ($(\"#randval\").hasClass(\"hide\")) {" \
88   - "$(\"#randval\").removeClass(\"hide\");" \
89   - "}" \
90   - "} else {" \
91   - "vnext--;" \
92   - "$(\"#vnext\").empty().append(vnext);" \
93   - "}" \
94   - "};" \
95   - "$(\"#msg\").ajaxError(function(event, request, settings) {" \
96   - "$(this).append(" \
97   - "\"<li>Error requesting page \" + " \
98   - "settings.url + " \
99   - "\"</li>\");" \
100   - "vnext = 0;" \
101   - "});" \
102   - "$(\"a\").click(function() {" \
103   - "intervalId = setInterval(counter, 1000);" \
104   - "});" \
105   - "});" \
106   - "</script>" \
107   - "</head>" \
108   - "<body>" \
109   - "<div id=\"randval\" class=\"hide\">" \
110   - "<span class=\"small\">" \
111   - "Value created at: <br /><span id=\"ctime\"></span><br>" \
112   - "Next value in: <span id=\"vnext\"></span><br />" \
113   - "</span>" \
114   - "Value: <span id=\"value\"></span>" \
115   - "</div>" \
116   - "<div id=\"main\">" \
117   - "<h1>Testpage</h1>" \
118   - "Welcome %s<br />" \
119   - "<img src=\"/image/\" />" \
120   - "<br /><a href=\"#\">Link</a>" \
121   - "</div>" \
122   - "<hr /><div id=\"msg\"></div>" \
123   - "</body>" \
124   - "</html>"
125   -
126   -HttpResponse
127   -httpResponseMe(char * uname)
128   -{
129   - HttpResponse response;
130   - HttpMessage message;
131   -
132   - response = new(HttpResponse, "HTTP/1.1", 200, "OK");
133   - message = (HttpMessage)response;
134   -
135   - httpHeaderAdd(&(message->header),
136   - new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html")));
137   - httpHeaderAdd(&(message->header),
138   - new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("name=Georg+Hopp")));
139   - httpHeaderAdd(&(message->header),
140   - new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("profession=coder")));
141   -
142   - message->type = HTTP_MESSAGE_BUFFERED;
143   - message->nbody = sizeof(RESP_DATA)-1-2+strlen(uname); //!< the two are the %s
144   - message->body = malloc(message->nbody+1);
145   - sprintf(message->body, RESP_DATA, uname);
146   - //memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)-1);
147   -
148   - return response;
149   -}
150   -
151   -// vim: set ts=4 sw=4:
Please register or login to post a comment