Compare commits

...

39 Commits
master ... next

Author SHA1 Message Date
Georg Hopp 77bcc77c28 fix build system 10 years ago
Georg Hopp 20cbe7f43c Fix conflicts from upstream merge 10 years ago
Georg Hopp 7a3343c8c8 Make the whole thing build again, anyway no guarantee that it works 10 years ago
Georg Hopp 8786d47892 adapt to fixed PARENTCALL 11 years ago
Georg Hopp fa63e7d5fe reflect changes in trdata... hashEach now requires an additional data argument. 12 years ago
Georg Hopp 8c2de51c57 Use new class interface and update copyright information 12 years ago
Georg Hopp b305285b85 use new ipv6 support of trio 12 years ago
Georg Hopp 6e080940fe reflect makro name change in trio 12 years ago
Georg Hopp a3ddcebff9 last few fixes to make the new socket code work. 12 years ago
Georg Hopp 8d41a5707b compile with latest library versions, escpecialy the new socket code. 12 years ago
Georg Hopp a9b2338655 add session removal by ip 12 years ago
Georg Hopp 666813e942 add m4 for trlibs 12 years ago
Georg Hopp cd02695058 add todo for session memory overflow 12 years ago
Georg Hopp 1dfefcbf0c don't do tests for the moment. 12 years ago
Georg Hopp 97f0b7db8f removed double delete 12 years ago
Georg Hopp cc03d4ef52 remove wrong delete. The get arguments will be deleted when the request is deleted. 12 years ago
Georg Hopp 5849bb7274 utilize libtrdata 12 years ago
Georg Hopp 151a4ebf00 now use libtrio for all io operations. 12 years ago
Georg Hopp b6df620190 add -ldl linker flag only if libdl is available, thus prepare the code to compile on platforms where the dynamic linker code is included within the C library (FreeBSD) 12 years ago
Georg Hopp 527b9e2d38 move all hashing helper code in separate library 12 years ago
Georg Hopp 1307358fbd moved the class and memory management into a separate project libtrbase / prefix all of the public interface of libtrbase with TR_ 12 years ago
Georg Hopp 7272bb6c7e adapt to fixed PARENTCALL 11 years ago
Georg Hopp fb4812ed94 reflect changes in trdata... hashEach now requires an additional data argument. 12 years ago
Georg Hopp 70e4fce1a0 Use new class interface and update copyright information 12 years ago
Georg Hopp 78ad7fa14a use new ipv6 support of trio 12 years ago
Georg Hopp 686f7841bc reflect makro name change in trio 12 years ago
Georg Hopp 30e0805b05 last few fixes to make the new socket code work. 12 years ago
Georg Hopp a62879f735 compile with latest library versions, escpecialy the new socket code. 12 years ago
Georg Hopp 1e6a855038 add session removal by ip 12 years ago
Georg Hopp 0c80c746b7 add m4 for trlibs 12 years ago
Georg Hopp 6a837618b5 add todo for session memory overflow 12 years ago
Georg Hopp fa179af677 don't do tests for the moment. 12 years ago
Georg Hopp b8b8152514 removed double delete 12 years ago
Georg Hopp f68825caa5 remove wrong delete. The get arguments will be deleted when the request is deleted. 12 years ago
Georg Hopp 01dc476775 utilize libtrdata 12 years ago
Georg Hopp 562407c88e now use libtrio for all io operations. 12 years ago
Georg Hopp ecd326b9f4 add -ldl linker flag only if libdl is available, thus prepare the code to compile on platforms where the dynamic linker code is included within the C library (FreeBSD) 12 years ago
Georg Hopp cf7f338bb2 move all hashing helper code in separate library 12 years ago
Georg Hopp 67b37a057b moved the class and memory management into a separate project libtrbase / prefix all of the public interface of libtrbase with TR_ 12 years ago
  1. 3
      Makefile.am
  2. 19
      configure.ac
  3. 8
      include/application/adapter/http.h
  4. 49
      include/application/application.h
  5. 10
      include/asset.h
  6. 2
      include/auth.h
  7. 10
      include/auth/auth.h
  8. 8
      include/auth/credential.h
  9. 19
      include/auth/interface/auth.h
  10. 8
      include/auth/ldap.h
  11. 8
      include/auth/storage.h
  12. 82
      include/cbuf.h
  13. 10
      include/class.h
  14. 143
      include/class/class.h
  15. 59
      include/class/interface.h
  16. 64
      include/class/interface/class.h
  17. 48
      include/commons.h
  18. 14
      include/config/config.h
  19. 9
      include/config/value.h
  20. 10
      include/hash.h
  21. 48
      include/hash/hash.h
  22. 45
      include/hash/interface/hashable.h
  23. 42
      include/hash/value.h
  24. 21
      include/http.h
  25. 8
      include/http/cookie.h
  26. 8
      include/http/header.h
  27. 14
      include/http/interface/http_intro.h
  28. 23
      include/http/message.h
  29. 20
      include/http/parser.h
  30. 18
      include/http/request.h
  31. 22
      include/http/response.h
  32. 33
      include/http/worker.h
  33. 18
      include/http/writer.h
  34. 49
      include/interface/indexable.h
  35. 40
      include/interface/observer.h
  36. 42
      include/interface/serializable.h
  37. 46
      include/interface/subject.h
  38. 9
      include/logger.h
  39. 45
      include/logger/interface/logger.h
  40. 57
      include/logger/logger.h
  41. 8
      include/permission.h
  42. 59
      include/queue.h
  43. 8
      include/rbac/object.h
  44. 8
      include/rbac/operation.h
  45. 8
      include/rbac/user.h
  46. 9
      include/role.h
  47. 18
      include/router.h
  48. 28
      include/server.h
  49. 38
      include/session.h
  50. 48
      include/socket.h
  51. 8
      include/storage/storage.h
  52. 10
      include/stream.h
  53. 45
      include/stream/interface/reader.h
  54. 45
      include/stream/interface/writer.h
  55. 49
      include/stream/stream.h
  56. 138
      include/tree.h
  57. 13
      include/user.h
  58. 33
      include/utils/hash.h
  59. 2
      include/utils/http.h
  60. 40
      include/utils/memory.h
  61. 2
      include/utils/mime_type.h
  62. 2
      include/utils/signalHandling.h
  63. 73
      include/uuid.h
  64. 24
      m4/trlibs.m4
  65. 47
      src/Makefile.am
  66. 21
      src/application/adapter/http/http.c
  67. 31
      src/application/adapter/http/update.c
  68. 31
      src/application/application.c
  69. 17
      src/application/controller/_get_credential_from_args.c
  70. 29
      src/application/controller/_get_user_from_args.c
  71. 17
      src/application/controller/_process_user_create_args.c
  72. 23
      src/application/controller/_update_user_from_args.c
  73. 9
      src/application/controller/_validate_email.c
  74. 6
      src/application/controller/_validate_password.c
  75. 7
      src/application/controller/_validate_password_repeat.c
  76. 28
      src/application/controller/authenticate/create.c
  77. 10
      src/application/controller/authenticate/delete.c
  78. 10
      src/application/controller/currentuser/read.c
  79. 10
      src/application/controller/loc/read.c
  80. 11
      src/application/controller/randval/read.c
  81. 10
      src/application/controller/sessinfo/read.c
  82. 22
      src/application/controller/signup/create.c
  83. 22
      src/application/controller/user/create.c
  84. 22
      src/application/controller/user/read.c
  85. 19
      src/application/controller/user/update.c
  86. 9
      src/application/controller/version/read.c
  87. 27
      src/application/create_user.c
  88. 19
      src/application/get_user.c
  89. 35
      src/application/login.c
  90. 7
      src/application/logout.c
  91. 24
      src/application/session_cleanup.c
  92. 75
      src/application/session_get.c
  93. 38
      src/application/session_start.c
  94. 32
      src/application/session_stop.c
  95. 18
      src/application/update_password.c
  96. 24
      src/application/update_user.c
  97. 15
      src/asset/asset.c
  98. 32
      src/asset/pool.c
  99. 18
      src/auth/auth.c
  100. 12
      src/auth/create.c

3
Makefile.am

@ -69,7 +69,8 @@ nobase_trdata_DATA = assets/html/example.html \
assets/style/images/ui-icons_cd0a0a_256x240.png \
assets/favicon.ico
SUBDIRS = src tests docs config
#SUBDIRS = src tests docs config
SUBDIRS = src docs config
.PHONY: docs coverage-html

19
configure.ac

@ -8,7 +8,7 @@ AC_INIT([taskrambler],
LT_INIT
AM_INIT_AUTOMAKE
#AM_INIT_AUTOMAKE([subdir-objects])
AM_SILENT_RULES([yes])
AM_SILENT_RULES([no])
AC_COPYRIGHT([Copyright © 2013 Georg Hopp])
AC_REVISION([m4_esyscmd_s([git describe --always])])
AC_CONFIG_SRCDIR([src/taskrambler.c])
@ -18,8 +18,9 @@ AC_CONFIG_MACRO_DIR([m4])
m4_include([m4/gcov.m4])
AC_TDD_GCOV
m4_include([m4/memopt.m4])
AC_MEM_OPT
m4_include([m4/trlibs.m4])
AC_TRLIBS_ROOT
AC_NEED_TRBASE
m4_include([m4/chkamd.m4])
AC_CHK_AMD
@ -50,6 +51,9 @@ AM_COND_IF([HAVE_DOXYGEN],
# [AC_MSG_ERROR([json-c library not found], [1])])
AC_CHECK_LIB([ssl], [SSL_library_init], [],
[AC_MSG_ERROR([openssl not found], [1])])
AC_CHECK_LIB([dl], [dlopen], [LIBS="-ldl"],
[AC_MSG_ERROR([openssl not found], [1])])
# Checks for header files.
AC_CHECK_HEADERS([stdarg.h string.h stdlib.h stdio.h unistd.h syslog.h sys/types.h json/json.h])
@ -88,23 +92,14 @@ AC_CONFIG_FILES([Makefile
src/Makefile
src/asset/Makefile
src/auth/Makefile
src/cbuf/Makefile
src/class/Makefile
src/hash/Makefile
src/queue/Makefile
src/http/Makefile
src/logger/Makefile
src/server/Makefile
src/session/Makefile
src/socket/Makefile
src/stream/Makefile
src/tree/Makefile
src/application/Makefile
src/storage/Makefile
src/user/Makefile
src/config/Makefile
src/router/Makefile
src/uuid/Makefile
docs/Makefile
config/Makefile
tests/Makefile])

8
include/application/adapter/http.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,15 +23,17 @@
#ifndef __APPLICATION_ADAPTER_HTTP_H__
#define __APPLICATION_ADAPTER_HTTP_H__
#include "class.h"
#include "trbase.h"
#include "router.h"
#include "application/application.h"
CLASS(ApplicationAdapterHttp) {
TR_CLASS(ApplicationAdapterHttp) {
Application application;
Router router;
};
TR_INSTANCE_INIT(ApplicationAdapterHttp);
TR_CLASSVARS_DECL(ApplicationAdapterHttp) {};
#endif // __APPLICATION_ADAPTER_HTTP_H__

49
include/application/application.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,16 +25,16 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "trhash.h"
#include "trdata.h"
#include "session.h"
#include "hash.h"
#include "auth.h"
#include "auth/credential.h"
#include "storage/storage.h"
#include "session.h"
#include "user.h"
#include "uuid.h"
struct randval {
@ -42,8 +42,13 @@ struct randval {
int value;
};
CLASS(Application) {
Hash * active_sessions;
struct sessinfo {
TR_Hash sessions;
TR_Tree ip_index;
};
TR_CLASS(Application) {
struct sessinfo * active_sessions;
time_t session_time_ofs;
Auth auth;
@ -54,24 +59,26 @@ CLASS(Application) {
Storage passwords;
Storage roles;
Uuid user_namespace;
TR_Uuid user_namespace;
Hash roles_user_index;
Hash roles_resource_index;
TR_Hash roles_user_index;
TR_Hash roles_resource_index;
const char * version;
const char * loc;
const char * version;
const char * loc;
};
int applicationLogin(Application, Credential, Session);
void applicationLogout(Application, Session);
Uuid applicationCreateUser(Application, Credential, User);
Uuid applicationUpdateUser(Application, User);
User applicationGetUser(Application, Uuid);
int applicationUpdatePassword(Application, Credential, User);
Session applicationSessionStart(Application);
Session applicationSessionGet(Application, const char *);
TR_INSTANCE_INIT(Application);
TR_CLASSVARS_DECL(Application) {};
int applicationLogin(Application, Credential, Session);
void applicationLogout(Application, Session);
TR_Uuid applicationCreateUser(Application, Credential, User);
TR_Uuid applicationUpdateUser(Application, User);
User applicationGetUser(Application, TR_Uuid);
int applicationUpdatePassword(Application, Credential, User);
Session applicationSessionStart(Application, uint32_t);
Session applicationSessionGet(Application, const char *, uint32_t);
void applicationSessionStop(Application, Session);
void applicationSessionCleanup(Application, time_t);

10
include/asset.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,12 +26,10 @@
#include <sys/types.h>
#include "class.h"
#include "commons.h"
#include "hash.h"
#include "trbase.h"
CLASS(Asset) {
TR_CLASS(Asset) {
unsigned long hash;
char fname[2049];
@ -51,6 +49,8 @@ CLASS(Asset) {
size_t ref_count;
};
TR_INSTANCE_INIT(Asset);
TR_CLASSVARS_DECL(Asset) {};
Asset assetPoolGet(const char *, size_t);
size_t assetPoolRelease(Asset);

2
include/auth.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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

10
include/auth/auth.h

@ -23,7 +23,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -42,8 +42,8 @@
#ifndef __AUTH_AUTH_H__
#define __AUTH_AUTH_H__
#include "class.h"
#include "uuid.h"
#include <trbase.h>
#include "auth.h"
#include "auth/credential.h"
@ -55,9 +55,11 @@ typedef enum e_AuthModule {
#define MAX_AUTH AUTH_STORAGE
CLASS(Auth) {
TR_CLASS(Auth) {
void * auth[MAX_AUTH + 1];
};
TR_INSTANCE_INIT(Auth);
TR_CLASSVARS_DECL(Auth) {};
int authCreate(Auth, AuthModule, ...);

8
include/auth/credential.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,7 +25,7 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#define CRED_PWD(c) (((c)->cred).pwd)
@ -34,7 +34,7 @@ typedef enum e_CredentialType {
} CredentialType;
CLASS(Credential) {
TR_CLASS(Credential) {
CredentialType type;
union {
@ -48,6 +48,8 @@ CLASS(Credential) {
} cred;
};
TR_INSTANCE_INIT(Credential);
TR_CLASSVARS_DECL(Credential) {};
#endif // __AUTH_CREDENTIAL_H__

19
include/auth/interface/auth.h

@ -9,7 +9,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,22 +28,19 @@
#ifndef __AUTH_INTERFACE_AUTH_H__
#define __AUTH_INTERFACE_AUTH_H__
#include <stdarg.h>
#include <trbase.h>
#include <trhash.h>
#include "class.h"
#include "uuid.h"
#include "auth/credential.h"
typedef int (* fptr_authenticate)(void *, Credential, Uuid);
typedef int (* fptr_authenticate)(void *, Credential, TR_Uuid);
extern const struct interface i_Auth;
struct i_Auth {
const struct interface * const _;
fptr_authenticate authenticate;
TR_INTERFACE(Auth) {
TR_IFID;
fptr_authenticate authenticate;
};
extern int authenticate(void *, Credential, Uuid);
extern int authenticate(void *, Credential, TR_Uuid);
#endif // __AUTH_INTERFACE_AUTH_H__

8
include/auth/ldap.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,15 +26,17 @@
#include <ldap.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
CLASS(AuthLdap) {
TR_CLASS(AuthLdap) {
LDAP * ldap;
char * url;
char * base_dn;
int version;
size_t nbase_dn;
};
TR_INSTANCE_INIT(AuthLdap);
TR_CLASSVARS_DECL(AuthLdap) {};
#endif // __AUTH_LDAP_H__

8
include/auth/storage.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,7 +27,7 @@
#include <openssl/sha.h>
#include "class.h"
#include "trbase.h"
#include "storage/storage.h"
@ -35,9 +35,11 @@
#define HASH_SIZE SHA512_DIGEST_LENGTH
CLASS(AuthStorage) {
TR_CLASS(AuthStorage) {
Storage store;
};
TR_INSTANCE_INIT(AuthStorage);
TR_CLASSVARS_DECL(AuthStorage) {};
/**
* \todo In future this should use a more general purpose hash

82
include/cbuf.h

@ -1,82 +0,0 @@
/**
* \file
* My implementation of a ringbuffer.
* It maps a shared memory object twice directly following
* thus make it possible to read and write from any
* position within the buffer without the nasty wrap
* calculations.
* This is achived because the same memory region is mapped
* at the two addresses.
*
* \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 __CBUF_H__
#define __CBUF_H__
#include <ctype.h>
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "stream.h"
#include "commons.h"
#include "utils/memory.h"
#define ECBUFOVFL 100
CLASS(Cbuf) {
char * shm_name; // shared memory identifier
char * data;
Bool lock;
size_t bsize;
size_t bused;
size_t write;
size_t read;
};
ssize_t cbufRead(Cbuf, Stream);
ssize_t cbufWrite(Cbuf, Stream);
char * cbufGetLine(Cbuf, char **);
char * cbufGetData(Cbuf, size_t);
char * cbufSetData(Cbuf, const void *, size_t);
void cbufEmpty(Cbuf);
char * cbufGetRead(Cbuf this);
char * cbufGetWrite(Cbuf this);
char * cbufMemchr(Cbuf this, int c);
size_t cbufAddrIndex(Cbuf this, const void * c);
void cbufIncRead(Cbuf this, size_t n);
void cbufIncWrite(Cbuf this, size_t n);
size_t cbufGetFree(Cbuf this);
char cbufIsEmpty(Cbuf this);
void cbufSkipNonAlpha(Cbuf this);
Bool cbufIsLocked(Cbuf this);
void cbufLock(Cbuf this);
void cbufRelease(Cbuf this);
#endif // __CBUF_H__
// vim: set ts=4 sw=4:

10
include/class.h

@ -1,10 +0,0 @@
#ifndef __CLASS_H__
#define __CLASS_H__
#include "class/class.h"
#include "class/interface.h"
#include "class/interface/class.h"
#endif // __CLASS_H__
// vim: set ts=4 sw=4:

143
include/class/class.h

@ -1,143 +0,0 @@
/**
* \file
* My own class implementation for C. It combines a data structure
* with a set of dynamically linked methods defined by an interface. A
* dynamically linked method will be called via a selector method which in
* turn gets the implementation stored in the class.
*
* \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 __CLASS_CLASS_H__
#define __CLASS_CLASS_H__
#include <stdarg.h>
#include <sys/types.h>
#include <string.h>
#include <assert.h>
#include "class/interface.h"
#ifndef _ISOC99_SOURCE
#define _ISOC99_SOURCE
#endif
#define CLASS_MAGIC 0xFEFE
#define CLASS(name) \
struct c_##name; \
typedef struct c_##name * name; \
extern struct class * const _##name; \
struct c_##name
#define EXTENDS(parent) \
const char _[sizeof(struct c_##parent)]
#define _NULL NULL
#define CREATE_CLASS(name,_parent,...) \
static struct class c_##name; \
static class_ptr _classInit##name##_(void) { \
c_##name.parent = _##_parent; \
c_##name.init = NULL; \
return &c_##name; \
} \
static struct class c_##name = { \
CLASS_MAGIC, \
NULL, \
sizeof(struct c_##name), \
_classInit##name##_, \
INIT_IFACE_IMPL(__VA_ARGS__) \
}; struct class * const _##name = &c_##name; \
struct c_##name##_object { void * class; struct c_##name data; }
/**
* create a static instance of a class.
* \todo
* this macro requires to close the initializer
* with an extra curly brancket. This is not nice...find a
* way to prevent this.
*/
#define INSTANCE(class, name) \
struct c_##class##_object _##name; \
class name = &(_##name.data); \
struct c_##class##_object _##name = { \
&c_##class,
#define INIT_CLASS(class) ((class)->init? (class)->init() : (class))
#define GET_CLASS(object) (INIT_CLASS(*(class_ptr *)((void*)(object) - sizeof(void*))))
#define IFACE_GET(class,iface) (interfaceGet(&((class)->impl),(iface)))
#define HAS_PARENT(class) (NULL != ((class)->parent) && INIT_CLASS((class)->parent))
#define IS_OBJECT(obj) ((GET_CLASS((obj)))->magic == CLASS_MAGIC)
#define INSTANCE_OF(class,obj) ((GET_CLASS((obj))) == _##class)
/**
* \todo actually i use gcc feature ## for variadoc... think about
* a way to make this standard.
*/
#define _CALL(_class,_iface,method,...) \
do { \
class_ptr class = _class; \
iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \
while ((NULL == iface || NULL == iface->method) && HAS_PARENT(class)) { \
class = class->parent; \
iface = (struct i_##_iface *)IFACE_GET(class, &i_##_iface); \
} \
assert(NULL != iface->method); \
} while(0)
#define CALL(object,_iface,method,...) \
do { \
struct i_##_iface * iface; \
_CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \
iface->method(object, ##__VA_ARGS__); \
} while(0)
#define RETCALL(object,_iface,method,ret,...) \
do { \
struct i_##_iface * iface; \
_CALL(GET_CLASS(object), _iface, method, ##__VA_ARGS__); \
ret = iface->method(object, ##__VA_ARGS__); \
} while(0)
#define PARENTCALL(object,_iface,method,...) \
do { \
struct i_##_iface * iface; \
class_ptr pc_class = GET_CLASS((object)); \
assert(HAS_PARENT(pc_class)); \
_CALL(pc_class->parent, _iface, method, ##__VA_ARGS__); \
iface->method(object, ##__VA_ARGS__); \
} while(0)
struct class;
typedef struct class * class_ptr;
typedef class_ptr (* fptr_classInit)(void);
struct class {
const int magic;
class_ptr parent;
size_t object_size;
fptr_classInit init;
struct iface_impl impl;
};
#endif // __CLASS_CLASS_H__
// vim: set ts=4 sw=4:

59
include/class/interface.h

@ -1,59 +0,0 @@
/**
* \file
* Interface definition code. Each interface is a set of selector functions
* as well as a data structure where the concrete implementation will be stored.
* This structure is the intergrated in the class that implements the
* 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 __CLASS_INTERFACE_H__
#define __CLASS_INTERFACE_H__
#include <sys/types.h>
#define MAX_IFACE 32 // ATTENTION: every iface_impl will use MAX_IFACE * sizeof(void*)
#define IFACE(name) ((const struct i_##name const*)&i_##name##_impl)
#define INIT_IFACE(name,...) \
static const struct i_##name i_##name##_impl = {&i_##name,__VA_ARGS__}
#define NUMARGS(...) (sizeof((const void*[]){__VA_ARGS__})/sizeof(void*))
#define INIT_IFACE_IMPL(...) {NUMARGS(__VA_ARGS__), 0, {__VA_ARGS__}}
struct interface {
const char * name;
const size_t nmethods;
};
typedef const struct interface * iface_ptr;
struct iface_impl {
const size_t nimpl; // number of interface implementations
char simpl; // implementations sorted??
const void * impl[MAX_IFACE]; // implementations
};
typedef struct iface_impl * iface_impl_ptr;
extern iface_ptr interfaceGet(iface_impl_ptr, const iface_ptr);
#endif // __CLASS_INTERFACE_H__
// vim: set ts=4 sw=4:

64
include/class/interface/class.h

@ -1,64 +0,0 @@
/**
* \file
* Interface for class handling. Defines new, delete and clone selectors
* which in turn use the ctor, dtor and clone implementation from the
* class implementation.
*
* \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 __CLASS_INTERFACE_CLASS_H__
#define __CLASS_INTERFACE_CLASS_H__
#include <stdarg.h>
#include "class/class.h"
#include "class/interface.h"
typedef int (* fptr_ctor)(void *, va_list *);
typedef void (* fptr_dtor)(void *);
typedef void (* fptr_clone)(void *, void * const);
extern const struct interface i_Class;
struct i_Class {
const struct interface * const _;
fptr_ctor ctor;
fptr_dtor dtor;
fptr_clone clone;
};
extern void * classNew(class_ptr, ...);
extern void classDelete(void **);
extern void * classClone(void *);
#define new(class,...) classNew(_##class, ##__VA_ARGS__)
#define delete(object) classDelete((void **)&(object))
#define clone(object) classClone((void *)(object))
/**
* With this one we can create a new instance via a
* intermidiary that gets the arguments.
*/
extern void * classNewParams(class_ptr, va_list *);
#define newParams(class,args) classNewParams(_##class, args)
#endif // __CLASS_INTERFACE_CLASS_H__
// vim: set ts=4 sw=4:

48
include/commons.h

@ -1,48 +0,0 @@
/**
* \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 __COMMONS_H__
#define __COMMONS_H__
#define Bool char
#define TRUE 1
#define FALSE 0
#ifndef MAX
# define MAX(a,b) ((a)>(b)? (a) : (b))
#endif
#ifndef MIN
# define MIN(a,b) ((a)<(b)? (a) : (b))
#endif
#define SWAP_FUN(a, b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define SWAP(type, a, b) do { \
type tmp = (a); \
(a) = (b); \
(b) = tmp; \
} while(0);
#endif // __COMMONS_H__
// vim: set ts=4 sw=4:

14
include/config/config.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,17 +23,19 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__
#include "hash.h"
#include "class.h"
#include "trbase.h"
#include "trdata.h"
#include "config/value.h"
#define MAX_CONFIG_LINE 256
CLASS(Config) {
char * cnf_file;
Hash config;
TR_CLASS(Config) {
char * cnf_file;
TR_Hash config;
};
TR_INSTANCE_INIT(Config);
TR_CLASSVARS_DECL(Config) {};
ConfigValue configGet(Config, const char *, size_t);

9
include/config/value.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,8 +25,7 @@
#include <sys/types.h>
#include "hash.h"
#include "class.h"
#include "trbase.h"
#define MAX_CONFIG_LINE 256
@ -38,7 +37,7 @@ typedef enum e_ConfigValueType {
CONFIG_VALUE_STRING = 1
} ConfigValueType;
CLASS(ConfigValue) {
TR_CLASS(ConfigValue) {
union {
char * string;
long long number;
@ -49,6 +48,8 @@ CLASS(ConfigValue) {
unsigned long hash;
};
TR_INSTANCE_INIT(ConfigValue);
TR_CLASSVARS_DECL(ConfigValue) {};
#endif // __CONFIG_VALUE_H__

10
include/hash.h

@ -1,10 +0,0 @@
#ifndef __HASH_H__
#define __HASH_H__
#include "hash/hash.h"
#include "hash/value.h"
#include "hash/interface/hashable.h"
#endif // __HASH_H__
// vim: set ts=4 sw=4:

48
include/hash/hash.h

@ -1,48 +0,0 @@
/**
* \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_HASH_H__
#define __HASH_HASH_H__
#include <sys/types.h>
#include "class.h"
#include "tree.h"
#define HASH_IS_EMPTY(h) ((h)->root)
CLASS(Hash) {
Tree root;
};
void * hashAdd(Hash, void *);
void * hashDelete(Hash, const char *, size_t);
void * hashGet(Hash, const char *, size_t);
void * hashGetFirst(Hash);
void * hashDeleteByVal(Hash, unsigned long);
void * hashGetByVal(Hash, unsigned long);
void hashEach(Hash, void (*)(const void*));
void hashCleanup(Hash);
#endif // __HASH_HASH_H__
// vim: set ts=4 sw=4:

45
include/hash/interface/hashable.h

@ -1,45 +0,0 @@
/**
* \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 __HASH_INTERFACE_HASHABLE_H__
#define __HASH_INTERFACE_HASHABLE_H__
#include "class.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 // __HASH_INTERFACE_HASHABLE_H__
// vim: set ts=4 sw=4:

42
include/hash/value.h

@ -1,42 +0,0 @@
/**
* \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:

21
include/http.h

@ -1,3 +1,24 @@
/**
* \file
*
* \author Georg Hopp
*
* \copyright
* Copyright © 2014 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_H__
#define __HTTP_H__

8
include/http/cookie.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,9 +26,9 @@
#include <time.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
CLASS(HttpCookie) {
TR_CLASS(HttpCookie) {
unsigned long hash;
char * key;
@ -42,6 +42,8 @@ CLASS(HttpCookie) {
size_t nkey;
size_t nvalue;
};
TR_INSTANCE_INIT(HttpCookie);
TR_CLASSVARS_DECL(HttpCookie) {};
char * httpCookieToString(HttpCookie);
HttpCookie httpStringToCookie(const char *);

8
include/http/header.h

@ -6,7 +6,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,11 +27,11 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#define N_VALUES 128
CLASS(HttpHeader) {
TR_CLASS(HttpHeader) {
unsigned long hash;
char * name;
char * value[N_VALUES];
@ -40,6 +40,8 @@ CLASS(HttpHeader) {
size_t cvalue; //!< count of values up to N_VALUE
size_t size; //!< full size of this header
};
TR_INSTANCE_INIT(HttpHeader);
TR_CLASSVARS_DECL(HttpHeader) {};
size_t httpHeaderToString(HttpHeader, char *);

14
include/http/interface/http_intro.h

@ -7,7 +7,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -28,15 +28,15 @@
#include <sys/types.h>
#include "trbase.h"
typedef size_t (* fptr_httpIntroSizeGet)(void *);
typedef char * (* fptr_httpIntroToString)(void *, char *);
extern const struct interface i_HttpIntro;
struct i_HttpIntro {
const struct interface * const _;
fptr_httpIntroSizeGet sizeGet;
fptr_httpIntroToString toString;
TR_INTERFACE(HttpIntro) {
TR_IFID;
fptr_httpIntroSizeGet sizeGet;
fptr_httpIntroToString toString;
};
extern size_t httpIntroSizeGet(void *);

23
include/http/message.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,22 +24,23 @@
#ifndef __HTTP_MESSAGE__
#define __HTTP_MESSAGE__
#include "class.h"
#include "hash.h"
#include "stream.h"
#include "trbase.h"
#include "trdata.h"
#include "asset.h"
CLASS(HttpMessage) {
char * version;
TR_CLASS(HttpMessage) {
char * version;
Hash header;
TR_Hash header;
Asset asset;
char * body;
Asset asset;
char * body;
int nbody;
int dbody;
int nbody;
int dbody;
};
TR_INSTANCE_INIT(HttpMessage);
TR_CLASSVARS_DECL(HttpMessage) {};
char httpMessageHasKeepAlive(HttpMessage);
size_t httpMessageHeaderSizeGet(HttpMessage);

20
include/http/parser.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,13 +24,11 @@
#ifndef __HTTP_PARSER_H__
#define __HTTP_PARSER_H__
#include "class.h"
#include "trbase.h"
#include "trio.h"
#include "trdata.h"
#include "http/message.h"
#include "queue.h"
#include "cbuf.h"
#include "stream.h"
#include "commons.h"
#define PARSER_MAX_BUF 131072
@ -44,20 +42,22 @@ typedef enum e_HttpMessageState {
} HttpMessageState;
CLASS(HttpParser) {
Cbuf buffer;
TR_CLASS(HttpParser) {
TR_Cbuf buffer;
Bool ourLock;
char * incomplete;
size_t isize;
Queue queue;
TR_Queue queue;
HttpMessage current;
HttpMessageState state;
};
TR_INSTANCE_INIT(HttpParser);
TR_CLASSVARS_DECL(HttpParser) {};
ssize_t httpParserParse(void *, Stream);
ssize_t httpParserParse(void *, TR_Stream);
void httpParserRequestVars(HttpParser);
void httpParserHeader(HttpParser, const char *, const char *);
void httpParserNewMessage(HttpParser, const char *, const char * lend);

18
include/http/request.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,9 +24,9 @@
#ifndef __HTTP_REQUEST_H__
#define __HTTP_REQUEST_H__
#include "class.h"
#include "trbase.h"
#include "trdata.h"
#include "http/message.h"
#include "hash.h"
#define N_HTTP_METHOD 8
@ -43,8 +43,8 @@ typedef enum e_HttpMethod {
HTTP_CONNECT
} HttpMethod;
CLASS(HttpRequest) {
EXTENDS(HttpMessage);
TR_CLASS(HttpRequest) {
TR_EXTENDS(HttpMessage);
char * method;
char * uri;
@ -52,10 +52,12 @@ CLASS(HttpRequest) {
HttpMethod method_id;
Hash get;
Hash post;
Hash cookies;
TR_Hash get;
TR_Hash post;
TR_Hash cookies;
};
TR_INSTANCE_INIT(HttpRequest);
TR_CLASSVARS_DECL(HttpRequest) {};
HttpMethod httpRequestGetMethodId(HttpRequest);

22
include/http/response.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,29 +27,31 @@
#include <time.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "http/message.h"
#include "session.h"
#include "user.h"
#include "asset.h"
CLASS(HttpResponse) {
EXTENDS(HttpMessage);
TR_CLASS(TR_HttpResponse) {
TR_EXTENDS(HttpMessage);
unsigned int status;
char * reason;
};
TR_INSTANCE_INIT(TR_HttpResponse);
TR_CLASSVARS_DECL(TR_HttpResponse) {};
HttpResponse httpResponse304(
TR_HttpResponse httpResponse304(
const char *, size_t,
const char *, size_t,
const char *, size_t);
HttpResponse httpResponse403();
HttpResponse httpResponse404();
HttpResponse httpResponse500();
HttpResponse httpResponseJson(const char *, size_t);
HttpResponse httpResponseAsset(const char *, size_t, time_t);
TR_HttpResponse httpResponse403();
TR_HttpResponse httpResponse404();
TR_HttpResponse httpResponse500();
TR_HttpResponse httpResponseJson(const char *, size_t);
TR_HttpResponse httpResponseAsset(const char *, size_t, time_t);
#endif // __HTTP_RESPONSE_H__

33
include/http/worker.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -27,35 +27,36 @@
#include <sys/types.h>
#include <time.h>
#include "class.h"
#include "hash.h"
#include "trbase.h"
#include "trdata.h"
#include "trio.h"
#include "http/parser.h"
#include "http/writer.h"
#include "cbuf.h"
#include "session.h"
#include "http/request.h"
#include "http/response.h"
#include "queue.h"
#include "commons.h"
CLASS(HttpWorker) {
char * id;
TR_CLASS(HttpWorker) {
char * id;
TR_Socket socket;
Cbuf pbuf;
Hash asset_pool;
TR_Cbuf pbuf;
TR_Hash asset_pool;
void * application_adapter;
void * application_adapter;
HttpRequest current_request;
HttpMessage current_response;
HttpRequest current_request;
HttpMessage current_response;
Queue additional_headers;
TR_Queue additional_headers;
HttpParser parser;
HttpWriter writer;
HttpParser parser;
HttpWriter writer;
};
TR_INSTANCE_INIT(HttpWorker);
TR_CLASSVARS_DECL(HttpWorker) {};
#endif // __HTTP_WORKER_H__

18
include/http/writer.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,12 +26,10 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "trio.h"
#include "trdata.h"
#include "http/message.h"
#include "queue.h"
#include "stream.h"
#include "commons.h"
/*
@ -78,10 +76,10 @@ typedef enum e_HttpWriterState {
HTTP_WRITER_DONE
} HttpWriterState;
CLASS(HttpWriter) {
TR_CLASS(HttpWriter) {
char * buffer;
Queue queue;
TR_Queue queue;
HttpMessage current;
size_t nbuffer; // size of buffer
@ -91,8 +89,10 @@ CLASS(HttpWriter) {
HttpWriterState state;
};
TR_INSTANCE_INIT(HttpWriter);
TR_CLASSVARS_DECL(HttpWriter) {};
ssize_t httpWriterWrite(void *, Stream);
ssize_t httpWriterWrite(void *, TR_Stream);
#endif // __HTTP_WRITER_H__

49
include/interface/indexable.h

@ -1,49 +0,0 @@
/**
* \file
* This interface provides only one function at all.
* indexUuid will generate a uuid to the current object.
*
* \todo
* Maybe merge hashable and indexable. Thus we might get an
* easy way to exchange the hashing mechanism used for my
* associative arrays.
*
* \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 __INDEXABLE_H__
#define __INDEXABLE_H__
#include "uuid.h"
typedef Uuid (* fptr_indexUuid)(void *, Uuid);
extern const struct interface i_Indexable;
struct i_Indexable {
const struct interface * const _;
fptr_indexUuid uuid;
};
extern Uuid indexUuid(void *, Uuid);
#endif // __INDEXABLE_H__
// vim: set ts=4 sw=4:

40
include/interface/observer.h

@ -1,40 +0,0 @@
/**
* \file
* Definition of the observer pattern implementation.
*
* \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 __OBSERVER_H__
#define __OBSERVER_H__
typedef void (* fptr_observerUpdate)(void *, void*);
extern const struct interface i_Observer;
struct i_Observer {
const struct interface * const _;
fptr_observerUpdate update;
};
extern void observerUpdate(void *, void *);
#endif // __OBSERVER_H__
// vim: set ts=4 sw=4:

42
include/interface/serializable.h

@ -1,42 +0,0 @@
/**
* \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 __SERIALIZABLE_H__
#define __SERIALIZABLE_H__
typedef void (* fptr_serialize)(void *, unsigned char **, size_t *);
typedef void (* fptr_unserialize)(void *, const unsigned char *, size_t);
extern const struct interface i_Serializable;
struct i_Serializable {
const struct interface * const _;
fptr_serialize serialize;
fptr_unserialize unserialize;
};
extern void serialize(void *, unsigned char **, size_t *);
extern void unserialize(void *, const unsigned char *, size_t);
#endif // __SERIALIZABLE_H__
// vim: set ts=4 sw=4:

46
include/interface/subject.h

@ -1,46 +0,0 @@
/**
* \file
* Definition of the subject pattern implementation.
*
* \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 __SUBJECT_H__
#define __SUBJECT_H__
typedef void (* fptr_subjectAttach)(void *, void *);
typedef void (* fptr_subjectDetach)(void *, void *);
typedef void (* fptr_subjectNotify)(void *);
extern const struct interface i_Subject;
struct i_Subject {
const struct interface * const _;
fptr_subjectAttach attach;
fptr_subjectDetach detach;
fptr_subjectNotify notify;
};
extern void subjectAttach(void *, void *);
extern void subjectDetach(void *, void *);
extern void subjectNotify(void *);
#endif // __SUBJECT_H__
// vim: set ts=4 sw=4:

9
include/logger.h

@ -1,9 +0,0 @@
#ifndef __LOGGER_H__
#define __LOGGER_H__
#include "logger/logger.h"
#include "logger/interface/logger.h"
#endif // __LOGGER_H__
// vim: set ts=4 sw=4:

45
include/logger/interface/logger.h

@ -1,45 +0,0 @@
/**
* \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 __LOGGER_INTERFACE_LOGGER_H__
#define __LOGGER_INTERFACE_LOGGER_H__
#include <stdarg.h>
#include "class.h"
#include "logger.h"
typedef void (* fptr_log)(void *, logger_level, const char * const);
extern const struct interface i_Logger;
struct i_Logger {
const struct interface * const _;
fptr_log log;
};
extern void loggerLog(void *, logger_level, const char * const, ...);
#endif // __LOGGER_INTERFACE_LOGGER_H__
// vim: set ts=4 sw=4:

57
include/logger/logger.h

@ -1,57 +0,0 @@
/**
* \file
* A generic logger class and two extended classes, One that logs to
* stderr and one that logs to the system syslog.
*
* \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 __LOGGER_LOGGER_H__
#define __LOGGER_LOGGER_H__
#include "class.h"
typedef enum logger_level {
LOGGER_DEBUG=0,
LOGGER_INFO,
LOGGER_NOTICE,
LOGGER_WARNING,
LOGGER_ERR,
LOGGER_CRIT,
LOGGER_ALERT,
LOGGER_EMERG
} logger_level;
extern const char * const logger_level_str[];
CLASS(Logger) {
logger_level min_level;
};
CLASS(LoggerStderr) {
EXTENDS(Logger);
};
CLASS(LoggerSyslog) {
EXTENDS(Logger);
};
#endif // __LOGGER_LOGGER_H__
// vim: set ts=4 sw=4:

8
include/permission.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,7 +25,7 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "storage/storage.h"
/**
@ -45,13 +45,15 @@ typedef enum e_ResourceActions {
} ResourceAction;
CLASS(Permission) {
TR_CLASS(Permission) {
char id[37];
unsigned long hash;
char * resource;
ResourceAction action;
};
TR_INSTANCE_INIT(Permission);
TR_CLASSVARS_DECL(Permission);
#endif // __PERMISSION_H__

59
include/queue.h

@ -1,59 +0,0 @@
/**
* \file
* Holds requests ready for processing.
*
* \todo change this to a real queue.
*
* \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 __QUEUE_H__
#define __QUEUE_H__
#include <sys/types.h>
#include "class.h"
#include "commons.h"
CLASS(Queue) {
void * msg;
Queue next;
/**
* first and last are only available in the initial queue
* element (the root). This elelment does not contain any message
* and exists only for organizational purpose.
*
* \todo next and first always have to be the same...so get rid
* of first.
*/
Queue first;
Queue last;
size_t nmsg;
};
void queuePut(Queue, void *);
void * queueGet(Queue);
#define queueEmpty(this) (0 >= (this)->nmsg)
#endif // __QUEUE_H__
// vim: set ts=4 sw=4:

8
include/rbac/object.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,14 +25,16 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "storage/storage.h"
CLASS(RbacObject) {
TR_CLASS(RbacObject) {
char * name;
size_t nname;
};
TR_INSTANCE_INIT(RbacObject);
TR_CLASSVARS_DECL(RbacObject) {};
#endif // __RBAC_OBJECT_H__

8
include/rbac/operation.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,13 +25,15 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
CLASS(RbacOperation) {
TR_CLASS(RbacOperation) {
char * name;
size_t nname;
};
TR_INSTANCE_INIT(RbacOperation);
TR_CLASSVARS_DECL(RbacOperation) {};
#endif // __RBAC_OPERATION_H__

8
include/rbac/user.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,7 +25,7 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
/**
@ -37,10 +37,12 @@
* tricky to find the correct interface when we want to
* be flexible in future.
*/
CLASS(RbacUser) {
TR_CLASS(RbacUser) {
char * name;
size_t nname;
};
TR_INSTANCE_INIT(RbacUser);
TR_CLASSVARS_DECL(RbacUser) {};
// void userSerialize(User, void **, size_t *);
// void userDeserialize(User, void *, size_t);

9
include/role.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,12 +25,12 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "ebac/permission.h"
#include "storage/storage.h"
CLASS(Role) {
TR_CLASS(Role) {
char id[37];
unsigned long hash;
@ -95,7 +95,10 @@ CLASS(Role) {
User * users;
Hash users_idx;
// end og ROLE definition.
};
TR_INSTANCE_INIT(Role);
TR_CLASSVARS_DECL(Role) {};
#endif // __ROLE_H__

18
include/router.h

@ -12,7 +12,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -33,26 +33,28 @@
#include <dlfcn.h>
#include "class.h"
#include "hash.h"
#include "trbase.h"
#include "trdata.h"
#include "session.h"
#include "http/request.h"
#include "http/response.h"
#include "application/application.h"
typedef char * (* fptr_routable)(Application, Session, Hash);
typedef char * (* fptr_routable)(Application, Session, TR_Hash);
CLASS(Router) {
Hash functions;
TR_CLASS(Router) {
TR_Hash functions;
Application application;
void * handle;
char * prefix;
size_t nprefix;
};
TR_INSTANCE_INIT(Router);
TR_CLASSVARS_DECL(Router) {};
HttpResponse routerRoute(Router, HttpRequest, Session);
TR_HttpResponse routerRoute(Router, HttpRequest, Session);
#endif // __ROUTER_H__

28
include/server.h

@ -7,7 +7,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -31,23 +31,21 @@
#include <openssl/ssl.h>
#include "class.h"
#include "socket.h"
#include "logger.h"
#include "stream.h"
#include "trbase.h"
#include "trio.h"
struct conns {
Sock sock;
Stream stream;
void * worker;
TR_Socket sock;
TR_Stream stream;
void * worker;
};
CLASS(Server) {
Logger logger;
Sock sock;
Sock sockSSL;
SSL_CTX * ctx;
void * worker;
TR_CLASS(Server) {
TR_Logger logger;
TR_Socket sock;
TR_Socket sockSSL;
SSL_CTX * ctx;
void * worker;
nfds_t nfds;
struct pollfd * fds;
@ -55,6 +53,8 @@ CLASS(Server) {
struct conns * conns;
};
TR_INSTANCE_INIT(Server);
TR_CLASSVARS_DECL(Server) {};
void serverRun(Server this);

38
include/session.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,22 +24,54 @@
#define __SESSION_H__
#include <time.h>
#include <stdint.h>
#include <sys/types.h>
#include <user.h>
#include "class.h"
#include "trbase.h"
// livetime of a session in seconds
#define SESSION_LIVETIME 300 // 5 minutes
/**
* Having only a session livetime is not enough.
* An attacker might create a client that never sends a session id
* back and continuously sends requests. This will then result
* in newly created sessions.
* The session class uses 57 bytes
* But there is also a user object created all the time.
* This uses 80 bytes.
* Each user in turn contains a uuid which is 37 bytes.
* Each of these are a class which adds another 221 bytes to each.
* So the following is allocated for these three objects:
* Session: 57 + 221 = 278
* User: 80 + 221 = 301
* Uuid: 37 + 221 = 258
* My allocater only allocates power of 2 sizes to optimize
* memory management so we end up with 512 bytes per object which is
* 1536 bytes per created session.
* The current code is able to handle more than 25000 request per
* second if there is no session id provided on my hardware.
* This sums up to 10GB of used memory within the 5 minutes
* session livetime.
*
* To prevent this I associate the session with the ip it was
* created on. If there then is a subsequent request from the same ip
* without a sessionid, the old session can be removed and a new one
* can be created. This might give a small but acceptable performance
* hit.
*/
CLASS(Session) {
TR_CLASS(Session) {
char id[37];
unsigned long hash;
uint32_t ip;
time_t livetime;
User user;
};
TR_INSTANCE_INIT(Session);
TR_CLASSVARS_DECL(Session) {};
#endif // __SESSION_H__

48
include/socket.h

@ -1,48 +0,0 @@
/**
* \file
* Abstraction layer above BSD sockets. Capsules and simplifies connect
* accept and listen.
*
* \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 __SOCKET_H__
#define __SOCKET_H__
#include <arpa/inet.h> // for in_port_t
#include "class.h"
#include "logger.h"
CLASS(Sock) {
Logger log;
in_port_t port;
struct sockaddr_in addr;
int handle;
};
void socketConnect(Sock this, const char * addr, char (*)[16]);
void socketListen(Sock this, int backlog);
Sock socketAccept(Sock this, char (*remoteAddr)[16]);
void socketNonblock(Sock this);
#endif // __SOCKET_H__
// vim: set ts=4 sw=4:

8
include/storage/storage.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,7 +26,7 @@
#include <gdbm.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
typedef enum e_StoragePutResults {
@ -37,10 +37,12 @@ typedef enum e_StoragePutResults {
} StoragePutResult;
CLASS(Storage) {
TR_CLASS(Storage) {
GDBM_FILE gdbm;
char * db_name;
};
TR_INSTANCE_INIT(Storage);
TR_CLASSVARS_DECL(Storage) {};
StoragePutResult storagePut(Storage, char *, size_t, char *, size_t);
StoragePutResult storageUpdate(Storage, char *, size_t, char *, size_t);

10
include/stream.h

@ -1,10 +0,0 @@
#ifndef __STREAM_H__
#define __STREAM_H__
#include "stream/stream.h"
#include "stream/interface/reader.h"
#include "stream/interface/writer.h"
#endif // __STREAM_H__
// vim: set ts=4 sw=4:

45
include/stream/interface/reader.h

@ -1,45 +0,0 @@
/**
* \file
* Interface whose implementations can read from a stream given as
* a handle.
*
* \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 __STREAM_INTERFACE_READER_H__
#define __STREAM_INTERFACE_READER_H__
#include <sys/types.h>
#include "stream/stream.h"
typedef ssize_t (* fptr_streamReaderRead)(void *, Stream);
extern const struct interface i_StreamReader;
struct i_StreamReader {
const struct interface * const _;
fptr_streamReaderRead read;
};
extern ssize_t streamReaderRead(void *, Stream);
#endif // __STREAM_INTERFACE_READER_H__
// vim: set ts=4 sw=4:

45
include/stream/interface/writer.h

@ -1,45 +0,0 @@
/**
* \file
* Interface whose implementations can write from a stream given as
* a handle.
*
* \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 __STREAM_INTERFACE_WRITER_H__
#define __STREAM_INTERFACE_WRITER_H__
#include <sys/types.h>
#include "stream/stream.h"
typedef ssize_t (* fptr_streamWriterWrite)(void *, Stream);
extern const struct interface i_StreamWriter;
struct i_StreamWriter {
const struct interface * const _;
fptr_streamWriterWrite write;
};
extern ssize_t streamWriterWrite(void *, Stream);
#endif // __STREAM_INTERFACE_WRITER_H__
// vim: set ts=4 sw=4:

49
include/stream/stream.h

@ -1,49 +0,0 @@
/**
* \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 __STREAM_STREAM_H__
#define __STREAM_STREAM_H__
#include <sys/types.h>
#include <openssl/ssl.h>
#include "class.h"
typedef enum e_StreamHandleType {
STREAM_FD = 0,
STREAM_SSL
} StreamHandleType;
CLASS(Stream) {
StreamHandleType type;
union {
int fd;
SSL * ssl;
} handle;
};
ssize_t streamRead(Stream, void *, size_t);
ssize_t streamWrite(Stream, void *, size_t);
#endif // __STREAM_STREAM_H__
// vim: set ts=4 sw=4:

138
include/tree.h

@ -1,138 +0,0 @@
/**
* \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 __TREE_H__
#define __TREE_H__
#include "class.h"
#define TREE_RIGHT(node) (NULL!=(node)?(node)->right:NULL)
#define TREE_LEFT(node) (NULL!=(node)?(node)->left:NULL)
#define TREE_PARENT(node) (NULL!=(node)?(node)->parent:NULL)
#define TREE_CHILD(node) \
(NULL==TREE_RIGHT((node))?TREE_LEFT((node)):TREE_RIGHT((node)))
#define TREE_RIGHT_LEFT(node) \
(NULL!=TREE_RIGHT((node))?TREE_LEFT(TREE_RIGHT((node))):NULL)
#define TREE_LEFT_RIGHT(node) \
(NULL!=TREE_LEFT((node))?TREE_RIGHT(TREE_LEFT((node))):NULL)
#define TREE_SIBLING(node) \
(NULL!=TREE_PARENT((node))? \
((node)==TREE_PARENT((node))->left? \
TREE_PARENT((node))->right: \
TREE_PARENT((node))->left): \
NULL)
#define TREE_GRANDPARENT(node) \
(NULL!=TREE_PARENT((node))?TREE_PARENT((node))->parent:NULL)
#define TREE_UNCLE(node) \
(NULL!=TREE_GRANDPARENT((node))? \
(TREE_PARENT((node))==TREE_GRANDPARENT((node))->left? \
TREE_GRANDPARENT((node))->right: \
TREE_GRANDPARENT((node))->left): \
NULL)
#define TREE_ROTATE_LEFT(root, node) \
do { \
if (NULL != TREE_RIGHT_LEFT((node))) { \
TREE_RIGHT_LEFT((node))->parent = (node); \
} \
TREE_RIGHT((node))->left = (node); \
if (NULL != TREE_PARENT((node))) { \
if (TREE_PARENT((node))->left==(node)) { \
TREE_PARENT((node))->left = (node)->right; \
} else { \
TREE_PARENT((node))->right = (node)->right; \
} \
} else { \
*(root) = (node)->right; \
} \
(node)->right = TREE_RIGHT_LEFT((node)); \
(node)->parent = (node)->right; \
TREE_RIGHT((node))->parent = (node)->parent; \
} while(0)
#define TREE_ROTATE_RIGHT(root, node) \
do { \
if (NULL != TREE_LEFT_RIGHT((node))) { \
TREE_LEFT_RIGHT((node))->parent = (node); \
} \
TREE_LEFT((node))->right = (node); \
if (NULL != TREE_PARENT((node))) { \
if (TREE_PARENT((node))->left==(node)) { \
TREE_PARENT((node))->left = (node)->left; \
} else { \
TREE_PARENT((node))->right = (node)->left; \
} \
} else { \
*(root) = (node)->left; \
} \
TREE_LEFT((node))->parent = (node)->parent; \
(node)->left = TREE_LEFT_RIGHT((node)); \
(node)->parent = (node)->right; \
} while(0)
#define TREE_REPLACE_NODE(root, node1, node2) \
do { \
if (NULL != TREE_PARENT((node1))) { \
if ((node1) == TREE_PARENT((node1))->left) { \
TREE_PARENT((node1))->left = (node2); \
} else { \
TREE_PARENT((node1))->right = (node2); \
} \
} else { \
*(root) = (node2); \
} \
if (NULL != (node2)) { \
(node2)->parent = (node1)->parent; \
} \
} while(0)
enum rbColor {rbBlack=1, rbRed=2};
CLASS(Tree) {
void * data;
enum rbColor color;
Tree parent;
Tree left;
Tree right;
};
typedef int (*TreeComp)(const void *, const void *);
typedef void (*TreeAction)(const void *, const int);
void * treeFind(Tree, const void *, TreeComp);
void * treeInsert(Tree *, const void *, TreeComp);
void * treeDelete(Tree *, const void *, TreeComp);
void treeWalk(Tree, TreeAction);
void treeDestroy(Tree *, TreeAction);
#endif // __TREE_H__
// vim: set ts=4 sw=4:

13
include/user.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,15 +25,16 @@
#include <sys/types.h>
#include "class.h"
#include "uuid.h"
#include <trbase.h>
#include <trhash.h>
#include "auth.h"
#include "storage/storage.h"
CLASS(User) {
TR_CLASS(User) {
unsigned long hash;
AuthModule auth_type;
TR_Uuid namespace;
/**
* username holds the identifier of the user.
* For ldap users this is the common name.
@ -52,6 +53,8 @@ CLASS(User) {
size_t * nfirstname;
size_t * nsurname;
};
TR_INSTANCE_INIT(User);
TR_CLASSVARS_DECL(User) {};
#endif // __USER_H__

33
include/utils/hash.h

@ -1,33 +0,0 @@
/**
* \file
* Functions to handle varios signals send to the application.
*
* \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 __UTILS_HASH_H__
#define __UTILS_HASH_H__
#include <sys/types.h>
unsigned long sdbm(const unsigned char *, size_t);
#endif // __UTILS_HASH_H__
// vim: set ts=4 sw=4:

2
include/utils/http.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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

40
include/utils/memory.h

@ -1,40 +0,0 @@
/**
* \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 __UTILS_MEMORY_H__
#define __UTILS_MEMORY_H__
#define CSTRA(val) val, sizeof(val)-1 //!< Const STRing Argument
#define MEM_FREE(seg) (memFree((void **)&(seg)))
#include <sys/types.h>
void * memMalloc(size_t);
void * memCalloc(size_t, size_t);
void memFree(void **);
size_t memGetSize(void *);
void memCleanup();
#endif // __UTILS_MEMORY_H__
// vim: set ts=4 sw=4:

2
include/utils/mime_type.h

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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

2
include/utils/signalHandling.h

@ -5,7 +5,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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

73
include/uuid.h

@ -1,73 +0,0 @@
/**
* \file
* ways to create uuid variant 5. For uuid of variant 1 I use
* the implementation delivered with the core utils.
* But this is wrapped in here, so that the rest of the code
* can use only this implementation...this additionally has the
* advantage that we can implement version 1 here too for systems
* where the coreutils implementation is not available.
*
* \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 __UUID_H__
#define __UUID_H__
#include <stdint.h>
#include <sys/types.h>
#include <uuid/uuid.h>
#include "class.h"
#include "commons.h"
typedef char UuidString[37];
CLASS(Uuid) {
union {
uuid_t value;
struct {
uint32_t time_low;
uint16_t time_mid;
uint16_t time_hi_version;
uint8_t clk_seq_hi_res;
uint8_t clk_seq_low;
unsigned char node[6];
} elements;
} uuid;
};
extern Uuid uuidZero;
/*
* generator functions...these are not really part of the object
* but generate a uuid object.
*/
Uuid uuidVersion1();
Uuid uuidVersion3(const unsigned char *, size_t, Uuid);
Uuid uuidVersion5(const unsigned char *, size_t, Uuid);
void uuidUnparse(Uuid, UuidString);
Uuid uuidParse(const UuidString);
int uuidCompare(Uuid, Uuid);
#endif // __UUID_H__
// vim: set ts=4 sw=4:

24
m4/trlibs.m4

@ -0,0 +1,24 @@
AC_DEFUN([AC_TRLIBS_ROOT],
[
AC_ARG_VAR([TRLIBS_ROOT],
[
The installation root of the taskrambler libraries
])
AS_IF([test "$TRLIBS_ROOT"],
[
AC_MSG_NOTICE("Using ${TRLIBS_ROOT} as installation root for libtrbase")
CFLAGS="${CFLAGS} -I${TRLIBS_ROOT}/include"
LDFLAGS="${LDFLAGS} -L${TRLIBS_ROOT}/lib -lgdbm -luuid"
])
])
AC_DEFUN([AC_NEED_TRBASE],
[
AC_CHECK_LIB([trbase], [TR_classNew], [],
[
AC_MSG_ERROR([Needed trbase library not found may try to set TRLIBS_ROOT])
])
])
# vim: set ft=m4 ts=2 sw=2:

47
src/Makefile.am

@ -2,31 +2,14 @@ ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
TRUTILS = utils/hash.c \
utils/memory.c \
utils/http.c \
TRUTILS = utils/http.c \
utils/daemonize.c \
utils/signalHandling.c \
utils/mime_type.c
TRBASESRC = interface/subject.c \
interface/observer.c \
interface/serializable.c \
interface/indexable.c
TRBASELIBS = class/libclass.la \
cbuf/libcbuf.la \
hash/libhash.la \
queue/libqueue.la \
logger/liblogger.la \
tree/libtree.la \
stream/libstream.la \
uuid/libuuid.la
TRHTTPSERVER = http/libhttp.la \
asset/libasset.la \
server/libserver.la \
socket/libsocket.la
server/libserver.la
TR = ./application/.libs/libapplication.a \
./user/.libs/libuser.a \
@ -36,32 +19,32 @@ TR = ./application/.libs/libapplication.a \
./config/.libs/libconfig.a \
./router/.libs/librouter.a
TRLIBS = -ltrutils -ltrhttpserver -ltrbase
USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid -ldl
TRFLIBS = -ltrbase -ltrhash -ltrio -ltrdata
TRLIBS = $(TRFLIBS) -ltrutils -ltrhttpserver
USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid
AM_CFLAGS += -I../include/
bin_PROGRAMS = taskrambler
lib_LTLIBRARIES = libtrutils.la libtrbase.la libtrhttpserver.la
lib_LTLIBRARIES = libtrutils.la libtrhttpserver.la
libtrutils_la_SOURCES = $(TRUTILS)
libtrutils_la_CFLAGS = $(AM_CFLAGS)
libtrutils_la_LIBADD =
libtrbase_la_SOURCES = $(TRBASESRC)
libtrbase_la_CFLAGS = $(AM_CFLAGS)
libtrbase_la_LIBADD = $(TRBASELIBS)
libtrhttpserver_la_SOURCES =
libtrhttpserver_la_CFLAGS = $(AM_CFLAGS)
libtrhttpserver_la_LIBADD = $(TRHTTPSERVER)
libtrhttpserver_la_LIBADD = $(TRHTTPSERVER) $(TRFLIBS)
taskrambler_SOURCES = taskrambler.c $(IFACE) $(UTILS)
taskrambler_CFLAGS = $(AM_CFLAGS)
taskrambler_LDADD = $(TRLIBS) $(TR) $(USEDLIBS)
taskrambler_LDFLAGS = -Wl,--export-dynamic \
-Wl,--whole-archive,./application/.libs/libapplication.a,--no-whole-archive
SUBDIRS = asset auth cbuf class hash queue http \
logger server session socket stream tree application \
storage user config router uuid
-Wl,--whole-archive \
-Wl,./application/.libs/libapplication.a \
-Wl,--no-whole-archive \
-Wl,--as-needed
SUBDIRS = asset auth http \
server session application \
storage user config router

21
src/application/adapter/http/http.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,13 +24,11 @@
#include <stdarg.h>
#include "class.h"
#include "trbase.h"
#include "router.h"
#include "application/application.h"
#include "application/adapter/http.h"
#include "utils/memory.h"
#include "interface/observer.h"
static
int
@ -54,16 +52,17 @@ applicationAdapterHttpDtor(void * _this)
void applicationAdapterHttpUpdate(void *, void *);
INIT_IFACE(
Class,
TR_INIT_IFACE(
TR_Class,
applicationAdapterHttpCtor,
applicationAdapterHttpDtor,
NULL);
INIT_IFACE(Observer, applicationAdapterHttpUpdate);
CREATE_CLASS(
TR_INIT_IFACE(TR_Observer, applicationAdapterHttpUpdate);
TR_CREATE_CLASS(
ApplicationAdapterHttp,
NULL,
IFACE(Class),
IFACE(Observer));
NULL,
NULL,
TR_IF(TR_Class),
TR_IF(TR_Observer));
// vim: set ts=4 sw=4:

31
src/application/adapter/http/update.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,11 +23,15 @@
#define _GNU_SOURCE
#include <stdio.h>
#include <stdint.h>
#include <sys/types.h>
#include "trbase.h"
#include "trdata.h"
#include "trio.h"
#include "application/application.h"
#include "application/adapter/http.h"
#include "hash.h"
#include "http/worker.h"
#include "http/header.h"
#include "http/message.h"
@ -38,9 +42,9 @@
static
inline
char *
getSessionId(Hash cookies)
getSessionId(TR_Hash cookies)
{
HashValue sidstr = hashGet(cookies, CSTRA("sid"));
TR_HashValue sidstr = TR_hashGet(cookies, CSTRA("sid"));
if (NULL != sidstr) {
return (char*)sidstr->value;
@ -57,24 +61,29 @@ applicationAdapterHttpUpdate(void * _this, void * subject)
Session session = NULL;
time_t now = time(NULL);
char * sid;
char buf[1000];
size_t nbuf;
uint32_t ip;
char * sid;
char buf[1000];
size_t nbuf;
ip = TR_sdbm(
TR_socketAddrIp(worker->socket),
TR_socketAddrIplen(worker->socket));
applicationSessionCleanup(this->application, now);
sid = getSessionId(worker->current_request->cookies);
session = applicationSessionGet(this->application, sid);
session = applicationSessionGet(this->application, sid, ip);
if (NULL == session) {
session = applicationSessionStart(this->application);
session = applicationSessionStart(this->application, ip);
}
// send session cookie
nbuf = sprintf(buf, "sid=%s;Path=/", session->id);
queuePut(
TR_queuePut(
worker->additional_headers,
new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf));
TR_new(HttpHeader, CSTRA("Set-Cookie"), buf, nbuf));
worker->current_response = (HttpMessage)routerRoute(
this->router,

31
src/application/application.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,13 +24,13 @@
#include <stdarg.h>
#include "class.h"
#include "hash.h"
#include "uuid.h"
#include "trbase.h"
#include "trhash.h"
#include "trdata.h"
#include "application/application.h"
#include "storage/storage.h"
#include "utils/memory.h"
#include "config.h"
static
@ -53,13 +53,15 @@ applicationCtor(void * _this, va_list * params)
this->passwords = va_arg(*params, Storage);
//this->roles = va_arg(*params, Storage);
this->user_namespace = uuidParse(va_arg(*params, char *));
this->user_namespace = va_arg(*params, TR_Uuid);
this->auth = va_arg(*params, void *);
this->active_sessions = memCalloc(SESSION_LIVETIME, sizeof(Hash));
this->active_sessions = TR_calloc(
SESSION_LIVETIME,
sizeof(struct sessinfo));
for (i=0; i<SESSION_LIVETIME; i++) {
this->active_sessions[i] = new(Hash);
this->active_sessions[i].sessions = TR_new(TR_Hash);
}
this->version = VERSION;
@ -75,18 +77,17 @@ applicationDtor(void * _this)
Application this = _this;
size_t i;
delete(this->user_namespace);
for (i=0; i<SESSION_LIVETIME; i++) {
delete(this->active_sessions[i]);
TR_delete(this->active_sessions[i].sessions);
TR_delete(this->active_sessions[i].ip_index);
}
MEM_FREE(this->active_sessions);
MEM_FREE(this->auth);
TR_MEM_FREE(this->active_sessions);
TR_MEM_FREE(this->auth);
}
INIT_IFACE(Class, applicationCtor, applicationDtor, NULL);
CREATE_CLASS(Application, NULL, IFACE(Class));
TR_INIT_IFACE(TR_Class, applicationCtor, applicationDtor, NULL);
TR_CREATE_CLASS(Application, NULL, NULL, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

17
src/application/controller/_get_credential_from_args.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 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
@ -22,20 +22,19 @@
#define _GNU_SOURCE
#include "hash.h"
#include "trbase.h"
#include "trdata.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t);
Credential
_controllerGetCredentialFromArgs(Hash args)
_controllerGetCredentialFromArgs(TR_Hash args)
{
HashValue email = hashGet(args, CSTRA("email"));
HashValue password = hashGet(args, CSTRA("password"));
HashValue pwrepeat = hashGet(args, CSTRA("pwrepeat"));
TR_HashValue email = TR_hashGet(args, CSTRA("email"));
TR_HashValue password = TR_hashGet(args, CSTRA("password"));
TR_HashValue pwrepeat = TR_hashGet(args, CSTRA("pwrepeat"));
if (
NULL == email ||
@ -54,7 +53,7 @@ _controllerGetCredentialFromArgs(Hash args)
return FALSE;
}
return new(Credential,
return TR_new(Credential,
CRED_PASSWORD,
(char *)(email->value), email->nvalue,
(char *)(password->value), password->nvalue);

29
src/application/controller/_get_user_from_args.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 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
@ -22,19 +22,19 @@
#define _GNU_SOURCE
#include "hash.h"
#include "user.h"
#include <trbase.h>
#include <trhash.h>
#include "utils/memory.h"
#include "commons.h"
#include "trdata.h"
#include "user.h"
User
_controllerGetUserFromArgs(Hash args)
_controllerGetUserFromArgs(TR_Hash args)
{
HashValue email = hashGet(args, CSTRA("email"));
HashValue firstname = hashGet(args, CSTRA("firstname"));
HashValue surname = hashGet(args, CSTRA("surname"));
TR_HashValue email = TR_hashGet(args, CSTRA("email"));
TR_HashValue firstname = TR_hashGet(args, CSTRA("firstname"));
TR_HashValue surname = TR_hashGet(args, CSTRA("surname"));
if (
NULL == email ||
@ -44,7 +44,16 @@ _controllerGetUserFromArgs(Hash args)
return FALSE;
}
return new(User,
/**
* \todo how should we inject the user namespace here...
* or better, how to handle it at all...
* at least this is true for every controller...
* Additionally, this and the other controller functions
* that create a user in this way will leak memory.
* !!!IMPORTANT!!!
*/
return TR_new(User,
TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc"),
(char *)(email->value), email->nvalue,
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,

17
src/application/controller/_process_user_create_args.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 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
@ -22,25 +22,24 @@
#define _GNU_SOURCE
#include "hash.h"
#include "trbase.h"
#include "trdata.h"
#include "user.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
User _controllerGetUserFromArgs(Hash args);
Credential _controllerGetCredentialFromArgs(Hash args);
User _controllerGetUserFromArgs(TR_Hash args);
Credential _controllerGetCredentialFromArgs(TR_Hash args);
int
_controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred)
_controllerProcessUserCreateArgs(TR_Hash args, User * user, Credential * cred)
{
*user = _controllerGetUserFromArgs(args);
*cred = _controllerGetCredentialFromArgs(args);
if (NULL == *user || NULL == *cred) {
delete(*user);
delete(*cred);
TR_delete(*user);
TR_delete(*cred);
return FALSE;
}

23
src/application/controller/_update_user_from_args.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 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
@ -22,19 +22,19 @@
#define _GNU_SOURCE
#include "hash.h"
#include "user.h"
#include <trbase.h>
#include <trhash.h>
#include <trdata.h>
#include "utils/memory.h"
#include "commons.h"
#include "user.h"
int
_controllerUpdateUserFromArgs(Hash args, User * user)
_controllerUpdateUserFromArgs(TR_Hash args, User * user)
{
HashValue email = hashGet(args, CSTRA("email"));
HashValue firstname = hashGet(args, CSTRA("firstname"));
HashValue surname = hashGet(args, CSTRA("surname"));
TR_HashValue email = TR_hashGet(args, CSTRA("email"));
TR_HashValue firstname = TR_hashGet(args, CSTRA("firstname"));
TR_HashValue surname = TR_hashGet(args, CSTRA("surname"));
User new_user;
if (
@ -45,13 +45,14 @@ _controllerUpdateUserFromArgs(Hash args, User * user)
return FALSE;
}
new_user = new(User,
new_user = TR_new(User,
TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc"),
(char *)((*user)->username), *(*user)->nusername,
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,
(char *)(surname->value), surname->nvalue);
delete(*user);
TR_delete(*user);
*user = new_user;
return TRUE;

9
src/application/controller/_validate_email.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 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
@ -22,13 +22,15 @@
#define _GNU_SOURCE
#include <trbase.h>
#include <trhash.h>
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "auth/credential.h"
#include "user.h"
#include "utils/memory.h"
User
_controllerCreateUserFromArgs(Hash args)
@ -49,7 +51,8 @@ _controllerCreateUserFromArgs(Hash args)
return NULL;
}
return new(User,
return TR_new(User,
TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc"),
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,
(char *)(surname->value), surname->nvalue);

6
src/application/controller/_validate_password.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 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
@ -20,11 +20,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "hash.h"
#include "trbase.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
int
_controllerValidatePassword(

7
src/application/controller/_validate_password_repeat.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 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
@ -20,12 +20,9 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "hash.h"
#include "trbase.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
int
_controllerValidatePasswordRepeat(
char * password,

28
src/application/controller/authenticate/create.c

@ -22,41 +22,41 @@
#define _GNU_SOURCE
#include "class.h"
#include "trbase.h"
#include "trdata.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "auth/credential.h"
#include "user.h"
#include "utils/memory.h"
char * controllerCurrentuserRead(Application, Session, Hash);
char * controllerCurrentuserRead(Application, Session, TR_Hash);
char *
controllerAuthenticateCreate(
Application application,
Session session,
Hash args)
TR_Hash args)
{
HashValue username;
HashValue password;
Credential credential;
TR_HashValue username;
TR_HashValue password;
Credential credential;
char * response_data;
char * response_data;
username = hashGet(args, CSTRA("username"));
password = hashGet(args, CSTRA("password"));
username = TR_hashGet(args, CSTRA("username"));
password = TR_hashGet(args, CSTRA("password"));
if (NULL == username) {
username = hashGet(args, CSTRA("email"));
username = TR_hashGet(args, CSTRA("email"));
}
if (NULL == username || NULL == password) {
return NULL;
}
credential = new(Credential,
credential = TR_new(Credential,
CRED_PASSWORD,
(char *)(username->value), username->nvalue,
(char *)(password->value), password->nvalue);
@ -67,7 +67,7 @@ controllerAuthenticateCreate(
response_data = controllerCurrentuserRead(application, session, NULL);
}
delete(credential);
TR_delete(credential);
return response_data;
}

10
src/application/controller/authenticate/delete.c

@ -22,20 +22,18 @@
#define _GNU_SOURCE
#include "class.h"
#include "trdata.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
char * controllerCurrentuserRead(Application, Session, Hash);
char * controllerCurrentuserRead(Application, Session, TR_Hash);
char *
controllerAuthenticateDelete(
Application application,
Session session,
Hash args)
TR_Hash args)
{
applicationLogout(application, session);
return controllerCurrentuserRead(application, session, NULL);

10
src/application/controller/currentuser/read.c

@ -25,19 +25,17 @@
#include <sys/types.h>
#include <stdio.h>
#include "class.h"
#include "trbase.h"
#include "trdata.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
#define USER_JSON \
"{\"username\":\"%s\",\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}"
char *
controllerCurrentuserRead(Application app, Session sess, Hash args)
controllerCurrentuserRead(Application app, Session sess, TR_Hash args)
{
char * buffer;
size_t nbuffer;
@ -47,7 +45,7 @@ controllerCurrentuserRead(Application app, Session sess, Hash args)
(NULL != sess->user)? sess->user->email : "",
(NULL != sess->user)? sess->user->firstname : "",
(NULL != sess->user)? sess->user->surname : "");
buffer = memMalloc(nbuffer);
buffer = TR_malloc(nbuffer);
nbuffer = sprintf(buffer, USER_JSON,
(NULL != sess->user)? sess->user->username : "",
(NULL != sess->user)? sess->user->email : "",

10
src/application/controller/loc/read.c

@ -25,22 +25,22 @@
#include <sys/types.h>
#include <stdio.h>
#include "trbase.h"
#include "trdata.h"
#include "application/application.h"
#include "hash.h"
#include "session.h"
#include "utils/memory.h"
#define LOC_JSON "{\"loc\":\"%s\"}"
char *
controllerLocRead(Application app, Session sess, Hash args)
controllerLocRead(Application app, Session sess, TR_Hash args)
{
char * buffer;
size_t nbuffer;
nbuffer = snprintf(NULL, 0, LOC_JSON, app->loc? app->loc : "");
buffer = memMalloc(nbuffer);
buffer = TR_malloc(nbuffer);
sprintf(buffer, LOC_JSON, app->loc? app->loc : "");
return buffer;

11
src/application/controller/randval/read.c

@ -25,16 +25,17 @@
#include <sys/types.h>
#include <stdio.h>
#include "trbase.h"
#include "trdata.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
#define RANDVAL_JSON "{\"ctime\":%ld,\"vnext\":%ld,\"value\":\"%02d\"}"
char *
controllerRandvalRead(Application app, Session sess, Hash args)
controllerRandvalRead(Application app, Session sess, TR_Hash args)
{
char * buffer;
size_t nbuffer;
@ -49,7 +50,7 @@ controllerRandvalRead(Application app, Session sess, Hash args)
app->val->timestamp,
remaining,
app->val->value);
buffer = memMalloc(nbuffer);
buffer = TR_malloc(nbuffer);
sprintf(
buffer,
RANDVAL_JSON,

10
src/application/controller/sessinfo/read.c

@ -25,11 +25,11 @@
#include <stdio.h>
#include <sys/types.h>
#include "trbase.h"
#include "trdata.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
#define SESSION_JSON "{\"id\":\"%s\",\"timeout\":%d,\"timeleft\":%ld}"
@ -38,7 +38,7 @@ char *
controllerSessinfoRead(
Application application,
Session session,
Hash args)
TR_Hash args)
{
char * buffer;
size_t nbuffer;
@ -47,7 +47,7 @@ controllerSessinfoRead(
(NULL != session)? session->id : "",
(NULL != session)? SESSION_LIVETIME : 0,
(NULL != session)? session->livetime - time(NULL) : 0);
buffer = memMalloc(nbuffer);
buffer = TR_malloc(nbuffer);
sprintf(buffer, SESSION_JSON,
(NULL != session)? session->id : "",
(NULL != session)? SESSION_LIVETIME : 0,

22
src/application/controller/signup/create.c

@ -22,42 +22,44 @@
#define _GNU_SOURCE
#include <trbase.h>
#include <trhash.h>
#include <trdata.h>
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "auth/credential.h"
#include "user.h"
#include "utils/memory.h"
char * controllerCurrentuserRead(Application, Session, Hash);
int _controllerProcessUserCreateArgs(Hash, User *, Credential *);
char * controllerCurrentuserRead(Application, Session, TR_Hash);
int _controllerProcessUserCreateArgs(TR_Hash, User *, Credential *);
char *
controllerSignupCreate(
Application application,
Session session,
Hash args)
TR_Hash args)
{
Credential credential;
User user;
Uuid user_id;
TR_Uuid user_id;
char * response_data;
_controllerProcessUserCreateArgs(args, &user, &credential);
user_id = applicationCreateUser(application, credential, user);
if (0 == uuidCompare(uuidZero, user_id)) {
if (0 == TR_uuidCompare(TR_uuidZero, user_id)) {
response_data = NULL;
} else {
applicationLogin(application, credential, session);
response_data = controllerCurrentuserRead(application, session, NULL);
}
delete(credential);
delete(user);
delete(user_id);
TR_delete(credential);
TR_delete(user);
TR_delete(user_id);
return response_data;

22
src/application/controller/user/create.c

@ -22,40 +22,42 @@
#define _GNU_SOURCE
#include <trbase.h>
#include <trhash.h>
#include <trdata.h>
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "auth/credential.h"
#include "user.h"
#include "utils/memory.h"
char * controllerCurrentuserRead(Application, Session, Hash);
int _controllerProcessUserCreateArgs(Hash, User *, Credential *);
char * controllerCurrentuserRead(Application, Session, TR_Hash);
int _controllerProcessUserCreateArgs(TR_Hash, User *, Credential *);
char *
controllerUserCreate(
Application application,
Session session,
Hash args)
TR_Hash args)
{
Credential credential;
User user;
Uuid user_id;
TR_Uuid user_id;
char * response_data;
_controllerProcessUserCreateArgs(args, &user, &credential);
user_id = applicationCreateUser(application, credential, user);
if (0 == uuidCompare(uuidZero, user_id)) {
if (0 == TR_uuidCompare(TR_uuidZero, user_id)) {
response_data = NULL;
} else {
response_data = controllerCurrentuserRead(application, session, NULL);
}
delete(credential);
delete(user);
delete(user_id);
TR_delete(credential);
TR_delete(user);
TR_delete(user_id);
return response_data;
}

22
src/application/controller/user/read.c

@ -25,31 +25,31 @@
#include <sys/types.h>
#include <stdio.h>
#include "class.h"
#include <trbase.h>
#include <trhash.h>
#include <trdata.h>
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
#define USER_JSON \
"{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}"
char *
controllerUserRead(Application app, Session sess, Hash args)
controllerUserRead(Application app, Session sess, TR_Hash args)
{
char * buffer;
size_t nbuffer;
HashValue id = hashGet(args, CSTRA("id"));
Uuid search = uuidParse(id->value);
User user = applicationGetUser(app, search);
char * buffer;
size_t nbuffer;
TR_HashValue id = TR_hashGet(args, CSTRA("id"));
TR_Uuid search = TR_uuidParse(id->value);
User user = applicationGetUser(app, search);
nbuffer = snprintf(NULL, 0, USER_JSON,
user->email,
user->firstname,
user->surname);
buffer = memMalloc(nbuffer);
buffer = TR_malloc(nbuffer);
nbuffer = sprintf(buffer, USER_JSON,
user->email,
user->firstname,

19
src/application/controller/user/update.c

@ -22,34 +22,35 @@
#define _GNU_SOURCE
#include <trbase.h>
#include <trhash.h>
#include <trdata.h>
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "user.h"
#include "utils/memory.h"
#include "commons.h"
char * controllerCurrentuserRead(Application, Session, Hash);
int _controllerUpdateUserFromArgs(Hash, User *);
char * controllerCurrentuserRead(Application, Session, TR_Hash);
int _controllerUpdateUserFromArgs(TR_Hash, User *);
char *
controllerUserUpdate(
Application application,
Session session,
Hash args)
TR_Hash args)
{
Uuid user_id;
TR_Uuid user_id;
if (! _controllerUpdateUserFromArgs(args, &(session->user))) {
return NULL;
}
user_id = applicationUpdateUser(application, session->user);
if (0 == uuidCompare(uuidZero, user_id)) {
if (0 == TR_uuidCompare(TR_uuidZero, user_id)) {
return NULL;
}
delete(user_id);
TR_delete(user_id);
return controllerCurrentuserRead(application, session, NULL);
}

9
src/application/controller/version/read.c

@ -25,22 +25,21 @@
#include <sys/types.h>
#include <stdio.h>
#include "trbase.h"
#include "trdata.h"
#include "application/application.h"
#include "hash.h"
#include "session.h"
#include "utils/memory.h"
#define VERSION_JSON "{\"version\":\"%s\"}"
char *
controllerVersionRead(Application app, Session sess, Hash args)
controllerVersionRead(Application app, Session sess, TR_Hash args)
{
char * buffer;
size_t nbuffer;
nbuffer = snprintf(NULL, 0, VERSION_JSON, app->version? app->version : "");
buffer = memMalloc(nbuffer);
buffer = TR_malloc(nbuffer);
sprintf(buffer, VERSION_JSON, app->version? app->version : "");
return buffer;

27
src/application/create_user.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,20 +26,15 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include <trbase.h>
#include <trhash.h>
#include "auth.h"
#include "user.h"
#include "uuid.h"
#include "storage/storage.h"
#include "application/application.h"
#include "interface/serializable.h"
#include "interface/indexable.h"
#include "utils/memory.h"
#include "commons.h"
Uuid
TR_Uuid
applicationCreateUser(
Application this,
Credential cred,
@ -47,10 +42,10 @@ applicationCreateUser(
{
char * user_serialized;
size_t nuser_serialized;
Uuid index;
TR_Uuid index;
index = indexUuid(user, this->user_namespace);
serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
index = TR_getIndex(user);
TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
if (SPR_OK != storagePut(
this->users,
@ -59,10 +54,10 @@ applicationCreateUser(
user_serialized,
nuser_serialized))
{
return uuidZero;
return TR_uuidZero;
}
MEM_FREE(user_serialized);
TR_MEM_FREE(user_serialized);
if (! applicationUpdatePassword(this, cred, user)) {
/**
@ -74,7 +69,7 @@ applicationCreateUser(
(char *)(index->uuid).value,
sizeof((index->uuid).value));
return uuidZero;
return TR_uuidZero;
}
return index;

19
src/application/get_user.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,21 +24,16 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include <trbase.h>
#include <trhash.h>
#include "auth.h"
#include "user.h"
#include "uuid.h"
#include "storage/storage.h"
#include "application/application.h"
#include "interface/serializable.h"
#include "interface/indexable.h"
#include "utils/memory.h"
#include "commons.h"
User
applicationGetUser(Application this, Uuid uuid)
applicationGetUser(Application this, TR_Uuid uuid)
{
char * user_serialized;
size_t nuser_serialized;
@ -52,11 +47,11 @@ applicationGetUser(Application this, Uuid uuid)
&nuser_serialized);
if (NULL != user_serialized) {
unserialize(
TR_unserialize(
user,
(unsigned char *)user_serialized,
nuser_serialized);
MEM_FREE(user_serialized);
TR_MEM_FREE(user_serialized);
}
return user;

35
src/application/login.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,15 +26,11 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include <trbase.h>
#include <trhash.h>
#include "auth.h"
#include "uuid.h"
#include "storage/storage.h"
#include "interface/serializable.h"
#include "interface/indexable.h"
#include "utils/memory.h"
#include "application/application.h"
@ -44,14 +40,14 @@ applicationLogin(
Credential credential,
Session session)
{
Uuid search;
TR_Uuid search;
AuthModule auth_module;
User user = new(User, NULL);
User user = TR_new(User, this->user_namespace, NULL);
user->username = CRED_PWD(credential).user;
user->nusername = &CRED_PWD(credential).nuser;
search = indexUuid(user, this->user_namespace);
search = TR_getIndex(user);
auth_module = authenticate(this->auth, credential, search);
@ -71,11 +67,11 @@ applicationLogin(
&nuser_serialized);
if (NULL != user_serialized) {
unserialize(
TR_unserialize(
session->user,
(unsigned char *)user_serialized,
nuser_serialized);
MEM_FREE(user_serialized);
TR_MEM_FREE(user_serialized);
} else {
/**
* this is a user authenticated via another method
@ -87,15 +83,16 @@ applicationLogin(
* the delete will not free it.
*/
session->user->username = NULL;
delete(session->user);
session->user = new(User,
TR_delete(session->user);
session->user = TR_new(User,
this->user_namespace,
CRED_PWD(credential).user,
CRED_PWD(credential).nuser,
CSTRA(""),
CSTRA(""),
CSTRA(""));
serialize(
TR_serialize(
session->user,
(unsigned char **)&user_serialized,
&nuser_serialized);
@ -110,7 +107,7 @@ applicationLogin(
sizeof((search->uuid).value),
user_serialized,
nuser_serialized);
MEM_FREE(user_serialized);
TR_MEM_FREE(user_serialized);
}
session->user->auth_type = auth_module;
@ -120,11 +117,11 @@ applicationLogin(
break;
}
delete(search);
TR_delete(search);
return TRUE;
}
delete(search);
TR_delete(search);
return FALSE;
}

7
src/application/logout.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -22,17 +22,16 @@
#define _GNU_SOURCE
#include "class.h"
#include "trbase.h"
#include "auth.h"
#include "utils/memory.h"
#include "application/application.h"
void
applicationLogout(Application this, Session session)
{
delete(session->user);
TR_delete(session->user);
}
// vim: set ts=4 sw=4:

24
src/application/session_cleanup.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,14 +23,15 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include "class.h"
#include "trdata.h"
#include "trbase.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
void
applicationSessionCleanup(Application this, time_t now)
@ -43,23 +44,26 @@ applicationSessionCleanup(Application this, time_t now)
}
if (0 < expired && SESSION_LIVETIME > expired) {
Hash * tmp_buf = memCalloc(SESSION_LIVETIME, sizeof(Hash));
struct sessinfo * tmp_buf = TR_calloc(
SESSION_LIVETIME,
sizeof(struct sessinfo));
memcpy(
&(tmp_buf[expired]),
this->active_sessions,
(SESSION_LIVETIME - expired) * sizeof(Hash));
(SESSION_LIVETIME - expired) * sizeof(struct sessinfo));
memcpy(
tmp_buf,
&(this->active_sessions[SESSION_LIVETIME - expired]),
expired * sizeof(Hash));
MEM_FREE(this->active_sessions);
expired * sizeof(struct sessinfo));
TR_MEM_FREE(this->active_sessions);
this->active_sessions = tmp_buf;
}
for (i=0; i<expired; i++) {
hashCleanup(this->active_sessions[i]);
TR_treeDestroy(this->active_sessions[i].ip_index, NULL);
TR_hashCleanup(this->active_sessions[i].sessions);
}
this->session_time_ofs = now;

75
src/application/session_get.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,39 +23,76 @@
#define _GNU_SOURCE
#include <sys/types.h>
#include <stdint.h>
#include <inttypes.h>
#include <stdio.h>
#include "trdata.h"
#include "class.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
static
inline
int
sessionIpIndexComp(const void * a, const void * b)
{
Session sess_a = (Session)a;
uint32_t ip = *(uint32_t *)b;
if (sess_a->ip < ip) {
return -1;
}
if (sess_a->ip > ip) {
return 1;
}
return 0;
}
Session
applicationSessionGet(Application this, const char * sid)
applicationSessionGet(Application this, const char * sid, uint32_t ip)
{
Session sess = NULL;
int index;
if (NULL != sid) {
/**
* now get the session if not expired
*/
for (index=0; index<SESSION_LIVETIME; index++) {
sess = (Session)hashDelete(
(this->active_sessions)[index], sid, 36);
if (NULL != sess) {
break;
}
/**
* now get the session if not expired
*/
for (index=0; index<SESSION_LIVETIME; index++) {
if (NULL != sid) {
sess = (Session)TR_hashDelete(
(this->active_sessions)[index].sessions, sid, 36);
}
/**
* update livetime of session if found
*/
if (NULL != sess) {
/**
* update livetime of session if found
*/
sess->livetime = this->session_time_ofs + SESSION_LIVETIME;
hashAdd((this->active_sessions)[0], sess);
sess = (Session)TR_treeDelete(
(this->active_sessions)[index].ip_index,
&ip, sessionIpIndexComp);
TR_hashAdd((this->active_sessions)[0].sessions, sess);
TR_treeInsert(
(this->active_sessions)[0].ip_index,
sess,
sessionIpIndexComp);
break;
} else {
sess = (Session)TR_treeDelete(
(this->active_sessions)[index].ip_index,
&ip, sessionIpIndexComp);
if (NULL != sess) {
// we have a previous session from this ip, remove it.
TR_hashDelete(
(this->active_sessions)[index].sessions,
sess->id, 36);
TR_delete(sess);
break;
}
}
}

38
src/application/session_start.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,21 +23,45 @@
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdint.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "trdata.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
static
inline
int
sessionIpIndexComp(const void * a, const void * b)
{
Session sess_a = (Session)a;
Session sess_b = (Session)b;
if (sess_a->ip < sess_b->ip) {
return -1;
}
if (sess_a->ip > sess_b->ip) {
return 1;
}
return 0;
}
Session
applicationSessionStart(Application this)
applicationSessionStart(Application this, uint32_t ip)
{
Session sess = new(Session);
Session sess = TR_new(Session, ip);
hashAdd((this->active_sessions)[0], sess);
TR_hashAdd((this->active_sessions)[0].sessions, sess);
TR_treeInsert(
(this->active_sessions)[0].ip_index,
sess,
sessionIpIndexComp);
return sess;
}

32
src/application/session_stop.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 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
@ -24,21 +24,43 @@
#include <sys/types.h>
#include "class.h"
#include "trdata.h"
#include "session.h"
#include "application/application.h"
#include "utils/memory.h"
static
inline
int
sessionIpIndexComp(const void * a, const void * b)
{
Session sess_a = (Session)a;
Session sess_b = (Session)b;
if (sess_a->ip < sess_b->ip) {
return -1;
}
if (sess_a->ip > sess_b->ip) {
return 1;
}
return 0;
}
void
applicationSessionStop(Application this, Session session)
{
int index = SESSION_LIVETIME -
int index = SESSION_LIVETIME -
(session->livetime - this->session_time_ofs);
if (SESSION_LIVETIME > index) {
hashDeleteByVal((this->active_sessions)[index], session->hash);
TR_hashDeleteByVal(
(this->active_sessions)[index].sessions,
session->hash);
TR_treeDelete(
(this->active_sessions)[index].ip_index,
session, sessionIpIndexComp);
}
}

18
src/application/update_password.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,16 +26,14 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include <trbase.h>
#include <trhash.h>
#include "auth.h"
#include "user.h"
#include "storage/storage.h"
#include "application/application.h"
#include "interface/indexable.h"
#include "utils/memory.h"
#include "commons.h"
int
applicationUpdatePassword(
@ -46,7 +44,7 @@ applicationUpdatePassword(
unsigned char hash_data[SALT_SIZE+HASH_SIZE];
unsigned char * salt = NULL;
unsigned char * hash = hash_data+SALT_SIZE;
Uuid index;
TR_Uuid index;
if (FALSE == hash_pw(
CRED_PWD(cred).pass,
@ -57,16 +55,16 @@ applicationUpdatePassword(
}
memcpy(hash_data, salt, SALT_SIZE);
MEM_FREE(salt);
TR_MEM_FREE(salt);
index = indexUuid(user, this->user_namespace);
index = TR_getIndex(user);
storageUpdate(
this->passwords,
(char *)(index->uuid).value,
sizeof((index->uuid).value),
(char *)hash_data,
SALT_SIZE + HASH_SIZE);
delete(index);
TR_delete(index);
return TRUE;
}

24
src/application/update_user.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,30 +26,26 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include <trbase.h>
#include <trhash.h>
#include "auth.h"
#include "user.h"
#include "uuid.h"
#include "storage/storage.h"
#include "application/application.h"
#include "interface/serializable.h"
#include "interface/indexable.h"
#include "utils/memory.h"
#include "commons.h"
Uuid
TR_Uuid
applicationUpdateUser(
Application this,
User user)
{
char * user_serialized;
size_t nuser_serialized;
Uuid index;
TR_Uuid index;
index = indexUuid(user, this->user_namespace);
serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
index = TR_getIndex(user);
TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
if (SPR_OK != storageUpdate(
this->users,
@ -58,10 +54,10 @@ applicationUpdateUser(
user_serialized,
nuser_serialized))
{
return uuidZero;
return TR_uuidZero;
}
MEM_FREE(user_serialized);
TR_MEM_FREE(user_serialized);
return index;
}

15
src/asset/asset.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -36,13 +36,12 @@
// for localtime
#include <time.h>
#include <trbase.h>
#include <trhash.h>
#include "class.h"
#include "asset.h"
#include "hash.h"
#include "utils/mime_type.h"
#include "utils/hash.h"
#include "utils/http.h"
@ -62,7 +61,7 @@ assetCtor(void * _this, va_list * params)
strncpy(this->fname, fname, 2048);
this->fname[2048] = '\0';
this->hash = sdbm(
this->hash = TR_sdbm(
(unsigned char *)this->fname,
this->nfname);
@ -138,8 +137,8 @@ assetHandleDouble(void * _this, void * _doub)
{
}
INIT_IFACE(Class, assetCtor, assetDtor, NULL);
INIT_IFACE(Hashable, assetGetHash, assetHandleDouble);
CREATE_CLASS(Asset, NULL, IFACE(Class), IFACE(Hashable));
TR_INIT_IFACE(TR_Class, assetCtor, assetDtor, NULL);
TR_INIT_IFACE(TR_Hashable, assetGetHash, assetHandleDouble);
TR_CREATE_CLASS(Asset, NULL, NULL, TR_IF(TR_Class), TR_IF(TR_Hashable));
// vim: set ts=4 sw=4:

32
src/asset/pool.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2012 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -25,18 +25,18 @@
// for strlen
#include "class.h"
#include "trbase.h"
#include "trdata.h"
#include "asset.h"
#include "hash.h"
Hash asset_pool = NULL;
TR_Hash asset_pool = NULL;
static
inline
void
freeAsset(const void * _node)
freeAsset(const void * _node, const void * data)
{
delete(_node);
TR_delete(_node);
}
Asset
@ -45,15 +45,15 @@ assetPoolGet(const char * path, size_t npath)
Asset asset = NULL;
if (NULL == asset_pool) {
asset_pool = new(Hash);
asset_pool = TR_new(TR_Hash);
} else {
asset = hashGet(asset_pool, path, npath);
asset = TR_hashGet(asset_pool, path, npath);
}
if (NULL == asset) {
asset = new(Asset, path, npath);
asset = TR_new(Asset, path, npath);
if (NULL != asset) {
hashAdd(asset_pool, asset);
TR_hashAdd(asset_pool, asset);
}
} else {
asset->ref_count++;
@ -71,13 +71,15 @@ assetPoolRelease(Asset asset)
}
if (NULL != asset) {
Asset found = (Asset)hashDelete(
Asset found = (Asset)TR_hashDelete(
asset_pool, asset->fname, asset->nfname);
if (found == asset) {
delete(found);
TR_delete(found);
} else {
// this should never happen....error log...
/**
* \todo this should never happen....error log...
*/
}
}
@ -88,8 +90,8 @@ void
assetPoolCleanup(void)
{
if (NULL != asset_pool) {
hashEach(asset_pool, freeAsset);
delete(asset_pool);
TR_hashEach(asset_pool, freeAsset, NULL);
TR_delete(asset_pool);
}
}

18
src/auth/auth.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -26,10 +26,8 @@
#include <stdio.h>
#include <ldap.h>
#include "class.h"
#include "uuid.h"
#include "utils/memory.h"
#include "commons.h"
#include <trbase.h>
#include <trhash.h>
#include "auth.h"
#include "auth/credential.h"
@ -57,13 +55,13 @@ authDtor(void * _this)
int i;
for (i=1; i<=MAX_AUTH; i++) {
delete(this->auth[i]);
TR_delete(this->auth[i]);
}
}
static
int
authAuthenticate(void * _this, Credential cred, Uuid user_index)
authAuthenticate(void * _this, Credential cred, TR_Uuid user_index)
{
Auth this = _this;
int i;
@ -77,8 +75,8 @@ authAuthenticate(void * _this, Credential cred, Uuid user_index)
return FALSE;
}
INIT_IFACE(Class, authCtor, authDtor, NULL);
INIT_IFACE(Auth, authAuthenticate);
CREATE_CLASS(Auth, NULL, IFACE(Class), IFACE(Auth));
TR_INIT_IFACE(TR_Class, authCtor, authDtor, NULL);
TR_INIT_IFACE(Auth, authAuthenticate);
TR_CREATE_CLASS(Auth, NULL, NULL, TR_IF(TR_Class), TR_IF(Auth));
// vim: set ts=4 sw=4:

12
src/auth/create.c

@ -4,7 +4,7 @@
* \author Georg Hopp
*
* \copyright
* Copyright © 2013 Georg Hopp
* Copyright © 2014 Georg Hopp
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@ -23,11 +23,11 @@
#include <stdarg.h>
#include <sys/types.h>
#include "class.h"
#include <trbase.h>
#include "auth.h"
#include "auth/ldap.h"
#include "auth/storage.h"
#include "commons.h"
int
authCreate(Auth this, AuthModule module, ...)
@ -35,18 +35,18 @@ authCreate(Auth this, AuthModule module, ...)
va_list params;
if (NULL != this->auth[module]) {
delete(this->auth[module]);
TR_delete(this->auth[module]);
}
va_start(params, module);
switch (module) {
case AUTH_LDAP:
this->auth[module] = newParams(AuthLdap, &params);
this->auth[module] = TR_newv(AuthLdap, &params);
break;
case AUTH_STORAGE:
this->auth[module] = newParams(AuthStorage, &params);
this->auth[module] = TR_newv(AuthStorage, &params);
break;
}

Some files were not shown because too many files changed in this diff

Loading…
Cancel
Save