Browse Source
add latest stuff from parent project yabrog. Essentially some request variable handling 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).
release0.1.5
add latest stuff from parent project yabrog. Essentially some request variable handling 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).
release0.1.5
146 changed files with 2372 additions and 418 deletions
-
3.gitignore
-
8TODO
-
50assets/html/main.html
-
0assets/image/waldschrat.jpg
-
37assets/js/init.js
-
0assets/js/jquery-1.7.1.js
-
0assets/js/jquery-1.7.1.min.js
-
78assets/js/serverval.js
-
78assets/js/session.js
-
58assets/style/common.css
-
45include/auth.h
-
41include/auth/ldap.h
-
2include/cbuf.h
-
2include/class.h
-
38include/commons.h
-
54include/credential.h
-
42include/hash.h
-
42include/hash_value.h
-
51include/http/cookie.h
-
4include/http/header.h
-
7include/http/message.h
-
2include/http/message/queue.h
-
5include/http/parser.h
-
8include/http/request.h
-
4include/http/response.h
-
4include/http/worker.h
-
2include/http/writer.h
-
2include/interface.h
-
49include/interface/auth.h
-
2include/interface/class.h
-
45include/interface/hashable.h
-
2include/interface/http_intro.h
-
2include/interface/logger.h
-
2include/interface/observer.h
-
2include/interface/stream_reader.h
-
2include/interface/stream_writer.h
-
2include/interface/subject.h
-
2include/logger.h
-
2include/server.h
-
2include/session.h
-
2include/socket.h
-
22include/stream.h
-
2include/utils/hash.h
-
22include/utils/http.h
-
2include/utils/memory.h
-
2include/utils/signalHandling.h
-
23src/Makefile.am
-
110src/auth/ldap.c
-
2src/cbuf.c
-
2src/cbuf/addr_index.c
-
2src/cbuf/empty.c
-
2src/cbuf/get_data.c
-
2src/cbuf/get_free.c
-
2src/cbuf/get_line.c
-
2src/cbuf/get_read.c
-
2src/cbuf/get_write.c
-
2src/cbuf/inc_read.c
-
2src/cbuf/inc_write.c
-
2src/cbuf/is_empty.c
-
2src/cbuf/is_locked.c
-
2src/cbuf/lock.c
-
2src/cbuf/memchr.c
-
2src/cbuf/read.c
-
2src/cbuf/release.c
-
2src/cbuf/set_data.c
-
2src/cbuf/skip_non_alpha.c
-
2src/cbuf/write.c
-
86src/credential.c
-
64src/hash.c
-
41src/hash/add.c
-
47src/hash/delete.c
-
47src/hash/each.c
-
26src/hash/get.c
-
109src/hash_value.c
-
104src/http/cookie.c
-
33src/http/header.c
-
2src/http/header/to_string.c
-
25src/http/message.c
-
2src/http/message/get_version.c
-
5src/http/message/has_keep_alive.c
-
2src/http/message/has_valid_version.c
-
11src/http/message/header_size_get.c
-
13src/http/message/header_to_string.c
-
2src/http/message/queue.c
-
2src/http/parser.c
-
4src/http/parser/body.c
-
44src/http/parser/header.c
-
22src/http/parser/new_message.c
-
29src/http/parser/parse.c
-
72src/http/parser/post_vars.c
-
71src/http/parser/request_vars.c
-
11src/http/request.c
-
2src/http/request/has_valid_method.c
-
2src/http/response.c
-
9src/http/response/304.c
-
2src/http/response/403.c
-
5src/http/response/404.c
-
10src/http/response/asset.c
-
5src/http/response/login_form.c
-
151src/http/response/me.c
@ -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 |
||||
@ -0,0 +1,50 @@ |
|||||
|
<?xml version="1.0" encoding="iso-8859-1"?> |
||||
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" |
||||
|
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
||||
|
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> |
||||
|
<head> |
||||
|
<title>My own little Web-App</title> |
||||
|
<link rel="stylesheet" type="text/css" href="/assets/style/common"> |
||||
|
<script type="text/javascript" src="/assets/js/jquery"></script> |
||||
|
<script type="text/javascript" src="/assets/js/serverval"></script> |
||||
|
<script type="text/javascript" src="/assets/js/session"></script> |
||||
|
<script type="text/javascript" src="/assets/js/init"></script> |
||||
|
</head> |
||||
|
<body> |
||||
|
<ul id="menu"> |
||||
|
<li>random Value</li> |
||||
|
<li>start session</li> |
||||
|
<li>login</li> |
||||
|
</ul> |
||||
|
<div id="sessinfo" class="x-small"> |
||||
|
Session: <span></span><br /> |
||||
|
<canvas width="100px" height="3px"></canvas> |
||||
|
</div> |
||||
|
<div id="login" class="hide"> |
||||
|
<form> |
||||
|
<label for="username">username</label> |
||||
|
<input type="text" name="username" /><br /> |
||||
|
<label for="password">password</label> |
||||
|
<input type="password" name="password" /><br /> |
||||
|
<input type="submit" /> |
||||
|
</form> |
||||
|
</div> |
||||
|
<div id="randval" class="hide"> |
||||
|
<span class=\"small"> |
||||
|
Value created at: <br /> |
||||
|
<span></span><br> |
||||
|
Next value in: <span></span><br /> |
||||
|
</span> |
||||
|
Value: <span></span> |
||||
|
</div> |
||||
|
<div id="main"> |
||||
|
<h1>Testpage</h1> |
||||
|
Welcome<span></span>!!!<br /> |
||||
|
<img src="/image/me" /> |
||||
|
</div> |
||||
|
<hr /> |
||||
|
<div id="msg"></div> |
||||
|
</body> |
||||
|
</html> |
||||
|
|
||||
|
<!-- vim: set ts=4 sw=4: --> |
||||
|
Before Width: 250 | Height: 250 | Size: 78 KiB After Width: 250 | Height: 250 | Size: 78 KiB |
@ -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:
|
||||
@ -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.<br />"); |
||||
|
break; |
||||
|
|
||||
|
default: |
||||
|
$("#msg").append( |
||||
|
"Unhandled - " + xhr.responseText + "<br />"); |
||||
|
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:
|
||||
@ -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:
|
||||
@ -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: */ |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef __AUTH_LDAP_H__ |
||||
|
#define __AUTH_LDAP_H__ |
||||
|
|
||||
|
#include <ldap.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef __CREDENTIAL_H__ |
||||
|
#define __CREDENTIAL_H__ |
||||
|
|
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef __HASH_H__ |
||||
|
#define __HASH_H__ |
||||
|
|
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef __HASH_VALUE_H__ |
||||
|
#define __HASH_VALUE_H__ |
||||
|
|
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef __HTTP_COOKIE_H__ |
||||
|
#define __HTTP_COOKIE_H__ |
||||
|
|
||||
|
#include <time.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#ifndef __INTERFACE_AUTH_H__ |
||||
|
#define __INTERFACE_AUTH_H__ |
||||
|
|
||||
|
#include <stdarg.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <stdarg.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
#include <stdio.h> |
||||
|
#include <ldap.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <stdarg.h> |
||||
|
#include <sys/types.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#define _GNU_SOURCE |
||||
|
|
||||
|
#include <search.h> |
||||
|
#include <stdarg.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <search.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <search.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <stdarg.h> |
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
#include <stdarg.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <string.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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=val1<delim>key2=val2<delim>...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: |
||||
@ -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 <http://www.gnu.org/licenses/>. |
||||
|
*/ |
||||
|
|
||||
|
#include <stdlib.h> |
||||
|
#include <string.h> |
||||
|
#include <sys/types.h> |
||||
|
|
||||
|
#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: |
||||
@ -1,151 +0,0 @@ |
|||||
/** |
|
||||
* \file |
|
||||
* |
|
||||
* \author Georg Hopp |
|
||||
* |
|
||||
* \copyright |
|
||||
* Copyright (C) 2012 Georg Hopp |
|
||||
* |
|
||||
* This program is free software: you can redistribute it and/or modify |
|
||||
* it under the terms of the GNU General Public License as published by |
|
||||
* the Free Software Foundation, either version 3 of the License, or |
|
||||
* (at your option) any later version. |
|
||||
* |
|
||||
* This program is distributed in the hope that it will be useful, |
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
||||
* GNU General Public License for more details. |
|
||||
* |
|
||||
* You should have received a copy of the GNU General Public License |
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
||||
*/ |
|
||||
|
|
||||
#include <stdlib.h> |
|
||||
#include <string.h> |
|
||||
#include <stdio.h> |
|
||||
#include <time.h> |
|
||||
#include <sys/types.h> |
|
||||
|
|
||||
#include "class.h" |
|
||||
#include "interface/class.h" |
|
||||
|
|
||||
#include "http/response.h" |
|
||||
#include "http/message.h" |
|
||||
#include "http/header.h" |
|
||||
|
|
||||
#include "utils/memory.h" |
|
||||
|
|
||||
|
|
||||
#define RESP_DATA "<?xml version=\"1.0\" encoding=\"iso-8859-1\"?>\n" \ |
|
||||
"<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\"\n" \ |
|
||||
" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\">\n" \ |
|
||||
"<html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\">" \ |
|
||||
"<head>" \ |
|
||||
"<title>My own little Web-App</title>" \ |
|
||||
"<style type=\"text/css\">" \ |
|
||||
"div#randval {" \ |
|
||||
"left: 200px;" \ |
|
||||
"top: 100px;" \ |
|
||||
"position: fixed;" \ |
|
||||
"background-color: white;" \ |
|
||||
"border: 1px solid black;" \ |
|
||||
"}" \ |
|
||||
"div.hide#randval {" \ |
|
||||
"top: -500px;" \ |
|
||||
"}" \ |
|
||||
".small {" \ |
|
||||
"font-size: small;" \ |
|
||||
"}" \ |
|
||||
"</style>" \ |
|
||||
"<script type=\"text/javascript\" src=\"/jquery/\"></script>" \ |
|
||||
"<script>" \ |
|
||||
"$(document).ready(function() {" \ |
|
||||
"var intervalId;" \ |
|
||||
"var vnext = 0;" \ |
|
||||
"var clickclose = function() {" \ |
|
||||
"clearInterval(intervalId);" \ |
|
||||
"vnext = 0;" \ |
|
||||
"$(\"#randval\").addClass(\"hide\");" \ |
|
||||
"};" \ |
|
||||
"var counter = function() {" \ |
|
||||
"if (0 >= vnext) {" \ |
|
||||
"$.getJSON(\"/randval/\", function(data, xhr) {" \ |
|
||||
"var date = new Date(data.ctime * 1000);" \ |
|
||||
"$(\"#ctime\").empty().append(date.toString());" \ |
|
||||
"vnext = data.vnext;" \ |
|
||||
"$(\"#value\").empty().append(data.value);" \ |
|
||||
"$(\"#vnext\").empty().append(vnext);" \ |
|
||||
"$(\"#randval\").on(\"click\", clickclose);" \ |
|
||||
"}).error(function(event, request, settings) {" \ |
|
||||
"clearInterval(intervalId);" \ |
|
||||
"$.get(\"/login/\", function(data) {" \ |
|
||||
"$(\"#randval\")" \ |
|
||||
".off(\"click\", clickclose)" \ |
|
||||
".empty().append(data);" \ |
|
||||
"});" \ |
|
||||
"});" \ |
|
||||
"if ($(\"#randval\").hasClass(\"hide\")) {" \ |
|
||||
"$(\"#randval\").removeClass(\"hide\");" \ |
|
||||
"}" \ |
|
||||
"} else {" \ |
|
||||
"vnext--;" \ |
|
||||
"$(\"#vnext\").empty().append(vnext);" \ |
|
||||
"}" \ |
|
||||
"};" \ |
|
||||
"$(\"#msg\").ajaxError(function(event, request, settings) {" \ |
|
||||
"$(this).append(" \ |
|
||||
"\"<li>Error requesting page \" + " \ |
|
||||
"settings.url + " \ |
|
||||
"\"</li>\");" \ |
|
||||
"vnext = 0;" \ |
|
||||
"});" \ |
|
||||
"$(\"a\").click(function() {" \ |
|
||||
"intervalId = setInterval(counter, 1000);" \ |
|
||||
"});" \ |
|
||||
"});" \ |
|
||||
"</script>" \ |
|
||||
"</head>" \ |
|
||||
"<body>" \ |
|
||||
"<div id=\"randval\" class=\"hide\">" \ |
|
||||
"<span class=\"small\">" \ |
|
||||
"Value created at: <br /><span id=\"ctime\"></span><br>" \ |
|
||||
"Next value in: <span id=\"vnext\"></span><br />" \ |
|
||||
"</span>" \ |
|
||||
"Value: <span id=\"value\"></span>" \ |
|
||||
"</div>" \ |
|
||||
"<div id=\"main\">" \ |
|
||||
"<h1>Testpage</h1>" \ |
|
||||
"Welcome %s<br />" \ |
|
||||
"<img src=\"/image/\" />" \ |
|
||||
"<br /><a href=\"#\">Link</a>" \ |
|
||||
"</div>" \ |
|
||||
"<hr /><div id=\"msg\"></div>" \ |
|
||||
"</body>" \ |
|
||||
"</html>" |
|
||||
|
|
||||
HttpResponse |
|
||||
httpResponseMe(char * uname) |
|
||||
{ |
|
||||
HttpResponse response; |
|
||||
HttpMessage message; |
|
||||
|
|
||||
response = new(HttpResponse, "HTTP/1.1", 200, "OK"); |
|
||||
message = (HttpMessage)response; |
|
||||
|
|
||||
httpHeaderAdd(&(message->header), |
|
||||
new(HttpHeader, CSTRA("Content-Type"), CSTRA("text/html"))); |
|
||||
httpHeaderAdd(&(message->header), |
|
||||
new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("name=Georg+Hopp"))); |
|
||||
httpHeaderAdd(&(message->header), |
|
||||
new(HttpHeader, CSTRA("Set-Cookie"), CSTRA("profession=coder"))); |
|
||||
|
|
||||
message->type = HTTP_MESSAGE_BUFFERED; |
|
||||
message->nbody = sizeof(RESP_DATA)-1-2+strlen(uname); //!< the two are the %s |
|
||||
message->body = malloc(message->nbody+1); |
|
||||
sprintf(message->body, RESP_DATA, uname); |
|
||||
//memcpy(message->body, RESP_DATA, sizeof(RESP_DATA)-1); |
|
||||
|
|
||||
return response; |
|
||||
} |
|
||||
|
|
||||
// vim: set ts=4 sw=4: |
|
||||
Some files were not shown because too many files changed in this diff
Write
Preview
Loading…
Cancel
Save
Reference in new issue