Browse Source

moved the class and memory management into a separate project libtrbase / prefix all of the public interface of libtrbase with TR_

next
Georg Hopp 12 years ago
parent
commit
1307358fbd
  1. 6
      configure.ac
  2. 4
      include/application/adapter/http.h
  3. 4
      include/application/application.h
  4. 5
      include/asset.h
  5. 4
      include/auth/auth.h
  6. 4
      include/auth/credential.h
  7. 12
      include/auth/interface/auth.h
  8. 4
      include/auth/ldap.h
  9. 4
      include/auth/storage.h
  10. 7
      include/cbuf.h
  11. 10
      include/class.h
  12. 143
      include/class/class.h
  13. 59
      include/class/interface.h
  14. 64
      include/class/interface/class.h
  15. 48
      include/commons.h
  16. 4
      include/config/config.h
  17. 4
      include/config/value.h
  18. 4
      include/hash/hash.h
  19. 12
      include/hash/interface/hashable.h
  20. 4
      include/hash/value.h
  21. 4
      include/http/cookie.h
  22. 4
      include/http/header.h
  23. 12
      include/http/interface/http_intro.h
  24. 4
      include/http/message.h
  25. 5
      include/http/parser.h
  26. 6
      include/http/request.h
  27. 6
      include/http/response.h
  28. 5
      include/http/worker.h
  29. 6
      include/http/writer.h
  30. 49
      include/interface/indexable.h
  31. 40
      include/interface/observer.h
  32. 42
      include/interface/serializable.h
  33. 46
      include/interface/subject.h
  34. 10
      include/logger/interface/logger.h
  35. 12
      include/logger/logger.h
  36. 4
      include/permission.h
  37. 5
      include/queue.h
  38. 4
      include/rbac/object.h
  39. 4
      include/rbac/operation.h
  40. 4
      include/rbac/user.h
  41. 4
      include/role.h
  42. 4
      include/router.h
  43. 4
      include/server.h
  44. 4
      include/session.h
  45. 4
      include/socket.h
  46. 4
      include/storage/storage.h
  47. 9
      include/stream/interface/reader.h
  48. 9
      include/stream/interface/writer.h
  49. 4
      include/stream/stream.h
  50. 4
      include/tree.h
  51. 5
      include/user.h
  52. 40
      include/utils/memory.h
  53. 5
      include/uuid.h
  54. 33
      src/Makefile.am
  55. 16
      src/application/adapter/http/http.c
  56. 3
      src/application/adapter/http/update.c
  57. 19
      src/application/application.c
  58. 5
      src/application/controller/_get_credential_from_args.c
  59. 6
      src/application/controller/_get_user_from_args.c
  60. 7
      src/application/controller/_process_user_create_args.c
  61. 8
      src/application/controller/_update_user_from_args.c
  62. 4
      src/application/controller/_validate_email.c
  63. 3
      src/application/controller/_validate_password.c
  64. 4
      src/application/controller/_validate_password_repeat.c
  65. 7
      src/application/controller/authenticate/create.c
  66. 2
      src/application/controller/authenticate/delete.c
  67. 6
      src/application/controller/currentuser/read.c
  68. 5
      src/application/controller/loc/read.c
  69. 6
      src/application/controller/randval/read.c
  70. 5
      src/application/controller/sessinfo/read.c
  71. 8
      src/application/controller/signup/create.c
  72. 8
      src/application/controller/user/create.c
  73. 6
      src/application/controller/user/read.c
  74. 5
      src/application/controller/user/update.c
  75. 5
      src/application/controller/version/read.c
  76. 14
      src/application/create_user.c
  77. 12
      src/application/get_user.c
  78. 27
      src/application/login.c
  79. 5
      src/application/logout.c
  80. 7
      src/application/session_cleanup.c
  81. 3
      src/application/session_get.c
  82. 5
      src/application/session_start.c
  83. 3
      src/application/session_stop.c
  84. 12
      src/application/update_password.c
  85. 13
      src/application/update_user.c
  86. 8
      src/asset/asset.c
  87. 16
      src/asset/pool.c
  88. 12
      src/auth/auth.c
  89. 9
      src/auth/create.c
  90. 16
      src/auth/credential.c
  91. 7
      src/auth/interface/auth.c
  92. 18
      src/auth/ldap.c
  93. 10
      src/auth/storage/hash_pw.c
  94. 16
      src/auth/storage/storage.c
  95. 16
      src/cbuf/cbuf.c
  96. 2
      src/cbuf/is_locked.c
  97. 9
      src/class/Makefile.am
  98. 64
      src/class/interface.c
  99. 99
      src/class/interface/i_class.c
  100. 22
      src/config/config.c

6
configure.ac

@ -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
@ -89,7 +90,6 @@ AC_CONFIG_FILES([Makefile
src/asset/Makefile
src/auth/Makefile
src/cbuf/Makefile
src/class/Makefile
src/hash/Makefile
src/queue/Makefile
src/http/Makefile

4
include/application/adapter/http.h

@ -23,12 +23,12 @@
#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;
};

4
include/application/application.h

@ -25,7 +25,7 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "session.h"
#include "hash.h"
@ -42,7 +42,7 @@ struct randval {
int value;
};
CLASS(Application) {
TR_CLASS(Application) {
Hash * active_sessions;
time_t session_time_ofs;

5
include/asset.h

@ -26,12 +26,11 @@
#include <sys/types.h>
#include "class.h"
#include "commons.h"
#include "trbase.h"
#include "hash.h"
CLASS(Asset) {
TR_CLASS(Asset) {
unsigned long hash;
char fname[2049];

4
include/auth/auth.h

@ -42,7 +42,7 @@
#ifndef __AUTH_AUTH_H__
#define __AUTH_AUTH_H__
#include "class.h"
#include "trbase.h"
#include "uuid.h"
#include "auth.h"
#include "auth/credential.h"
@ -55,7 +55,7 @@ typedef enum e_AuthModule {
#define MAX_AUTH AUTH_STORAGE
CLASS(Auth) {
TR_CLASS(Auth) {
void * auth[MAX_AUTH + 1];
};

4
include/auth/credential.h

@ -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 {

12
include/auth/interface/auth.h

@ -28,19 +28,15 @@
#ifndef __AUTH_INTERFACE_AUTH_H__
#define __AUTH_INTERFACE_AUTH_H__
#include <stdarg.h>
#include "class.h"
#include "trbase.h"
#include "uuid.h"
#include "auth/credential.h"
typedef int (* fptr_authenticate)(void *, Credential, 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);

4
include/auth/ldap.h

@ -26,9 +26,9 @@
#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;

4
include/auth/storage.h

@ -27,7 +27,7 @@
#include <openssl/sha.h>
#include "class.h"
#include "trbase.h"
#include "storage/storage.h"
@ -35,7 +35,7 @@
#define HASH_SIZE SHA512_DIGEST_LENGTH
CLASS(AuthStorage) {
TR_CLASS(AuthStorage) {
Storage store;
};

7
include/cbuf.h

@ -34,16 +34,13 @@
#include <string.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "stream.h"
#include "commons.h"
#include "utils/memory.h"
#define ECBUFOVFL 100
CLASS(Cbuf) {
TR_CLASS(Cbuf) {
char * shm_name; // shared memory identifier
char * data;

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:

4
include/config/config.h

@ -23,14 +23,14 @@
#ifndef __CONFIG_H__
#define __CONFIG_H__
#include "trbase.h"
#include "hash.h"
#include "class.h"
#include "config/value.h"
#define MAX_CONFIG_LINE 256
CLASS(Config) {
TR_CLASS(Config) {
char * cnf_file;
Hash config;
};

4
include/config/value.h

@ -25,8 +25,8 @@
#include <sys/types.h>
#include "trbase.h"
#include "hash.h"
#include "class.h"
#define MAX_CONFIG_LINE 256
@ -38,7 +38,7 @@ typedef enum e_ConfigValueType {
CONFIG_VALUE_STRING = 1
} ConfigValueType;
CLASS(ConfigValue) {
TR_CLASS(ConfigValue) {
union {
char * string;
long long number;

4
include/hash/hash.h

@ -25,12 +25,12 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "tree.h"
#define HASH_IS_EMPTY(h) ((h)->root)
CLASS(Hash) {
TR_CLASS(Hash) {
Tree root;
};

12
include/hash/interface/hashable.h

@ -24,17 +24,15 @@
#ifndef __HASH_INTERFACE_HASHABLE_H__
#define __HASH_INTERFACE_HASHABLE_H__
#include "class.h"
#include "trbase.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;
TR_INTERFACE(Hashable) {
TR_IFID;
fptr_hashableGetHash getHash;
fptr_hashableHandleDouble handleDouble;
};
extern unsigned long hashableGetHash(void *);

4
include/hash/value.h

@ -25,9 +25,9 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
CLASS(HashValue) {
TR_CLASS(HashValue) {
unsigned long hash;
char * key;

4
include/http/cookie.h

@ -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;

4
include/http/header.h

@ -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];

12
include/http/interface/http_intro.h

@ -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 *);

4
include/http/message.h

@ -24,12 +24,12 @@
#ifndef __HTTP_MESSAGE__
#define __HTTP_MESSAGE__
#include "class.h"
#include "trbase.h"
#include "hash.h"
#include "stream.h"
#include "asset.h"
CLASS(HttpMessage) {
TR_CLASS(HttpMessage) {
char * version;
Hash header;

5
include/http/parser.h

@ -24,13 +24,12 @@
#ifndef __HTTP_PARSER_H__
#define __HTTP_PARSER_H__
#include "class.h"
#include "trbase.h"
#include "http/message.h"
#include "queue.h"
#include "cbuf.h"
#include "stream.h"
#include "commons.h"
#define PARSER_MAX_BUF 131072
@ -44,7 +43,7 @@ typedef enum e_HttpMessageState {
} HttpMessageState;
CLASS(HttpParser) {
TR_CLASS(HttpParser) {
Cbuf buffer;
Bool ourLock;

6
include/http/request.h

@ -24,7 +24,7 @@
#ifndef __HTTP_REQUEST_H__
#define __HTTP_REQUEST_H__
#include "class.h"
#include "trbase.h"
#include "http/message.h"
#include "hash.h"
@ -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;

6
include/http/response.h

@ -27,15 +27,15 @@
#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(HttpResponse) {
TR_EXTENDS(HttpMessage);
unsigned int status;
char * reason;

5
include/http/worker.h

@ -27,7 +27,7 @@
#include <sys/types.h>
#include <time.h>
#include "class.h"
#include "trbase.h"
#include "hash.h"
#include "http/parser.h"
#include "http/writer.h"
@ -37,10 +37,9 @@
#include "http/request.h"
#include "http/response.h"
#include "queue.h"
#include "commons.h"
CLASS(HttpWorker) {
TR_CLASS(HttpWorker) {
char * id;
Cbuf pbuf;

6
include/http/writer.h

@ -26,13 +26,11 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "http/message.h"
#include "queue.h"
#include "stream.h"
#include "commons.h"
/*
* the buffer that will be written back to an http client.
@ -78,7 +76,7 @@ typedef enum e_HttpWriterState {
HTTP_WRITER_DONE
} HttpWriterState;
CLASS(HttpWriter) {
TR_CLASS(HttpWriter) {
char * buffer;
Queue queue;

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:

10
include/logger/interface/logger.h

@ -26,16 +26,14 @@
#include <stdarg.h>
#include "class.h"
#include "trbase.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;
TR_INTERFACE(Logger) {
TR_IFID;
fptr_log log;
};
extern void loggerLog(void *, logger_level, const char * const, ...);

12
include/logger/logger.h

@ -25,7 +25,7 @@
#ifndef __LOGGER_LOGGER_H__
#define __LOGGER_LOGGER_H__
#include "class.h"
#include "trbase.h"
typedef enum logger_level {
LOGGER_DEBUG=0,
@ -40,16 +40,16 @@ typedef enum logger_level {
extern const char * const logger_level_str[];
CLASS(Logger) {
TR_CLASS(Logger) {
logger_level min_level;
};
CLASS(LoggerStderr) {
EXTENDS(Logger);
TR_CLASS(LoggerStderr) {
TR_EXTENDS(Logger);
};
CLASS(LoggerSyslog) {
EXTENDS(Logger);
TR_CLASS(LoggerSyslog) {
TR_EXTENDS(Logger);
};
#endif // __LOGGER_LOGGER_H__

4
include/permission.h

@ -25,7 +25,7 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "storage/storage.h"
/**
@ -45,7 +45,7 @@ typedef enum e_ResourceActions {
} ResourceAction;
CLASS(Permission) {
TR_CLASS(Permission) {
char id[37];
unsigned long hash;

5
include/queue.h

@ -28,11 +28,10 @@
#include <sys/types.h>
#include "class.h"
#include "commons.h"
#include "trbase.h"
CLASS(Queue) {
TR_CLASS(Queue) {
void * msg;
Queue next;

4
include/rbac/object.h

@ -25,11 +25,11 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "storage/storage.h"
CLASS(RbacObject) {
TR_CLASS(RbacObject) {
char * name;
size_t nname;
};

4
include/rbac/operation.h

@ -25,10 +25,10 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
CLASS(RbacOperation) {
TR_CLASS(RbacOperation) {
char * name;
size_t nname;
};

4
include/rbac/user.h

@ -25,7 +25,7 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
/**
@ -37,7 +37,7 @@
* tricky to find the correct interface when we want to
* be flexible in future.
*/
CLASS(RbacUser) {
TR_CLASS(RbacUser) {
char * name;
size_t nname;
};

4
include/role.h

@ -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;

4
include/router.h

@ -33,7 +33,7 @@
#include <dlfcn.h>
#include "class.h"
#include "trbase.h"
#include "hash.h"
#include "session.h"
#include "http/request.h"
@ -42,7 +42,7 @@
typedef char * (* fptr_routable)(Application, Session, Hash);
CLASS(Router) {
TR_CLASS(Router) {
Hash functions;
Application application;

4
include/server.h

@ -31,7 +31,7 @@
#include <openssl/ssl.h>
#include "class.h"
#include "trbase.h"
#include "socket.h"
#include "logger.h"
#include "stream.h"
@ -42,7 +42,7 @@ struct conns {
void * worker;
};
CLASS(Server) {
TR_CLASS(Server) {
Logger logger;
Sock sock;
Sock sockSSL;

4
include/session.h

@ -27,13 +27,13 @@
#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
CLASS(Session) {
TR_CLASS(Session) {
char id[37];
unsigned long hash;

4
include/socket.h

@ -27,10 +27,10 @@
#include <arpa/inet.h> // for in_port_t
#include "class.h"
#include "trbase.h"
#include "logger.h"
CLASS(Sock) {
TR_CLASS(Sock) {
Logger log;
in_port_t port;
struct sockaddr_in addr;

4
include/storage/storage.h

@ -26,7 +26,7 @@
#include <gdbm.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
typedef enum e_StoragePutResults {
@ -37,7 +37,7 @@ typedef enum e_StoragePutResults {
} StoragePutResult;
CLASS(Storage) {
TR_CLASS(Storage) {
GDBM_FILE gdbm;
char * db_name;
};

9
include/stream/interface/reader.h

@ -27,15 +27,14 @@
#include <sys/types.h>
#include "trbase.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;
TR_INTERFACE(StreamReader) {
TR_IFID;
fptr_streamReaderRead read;
};
extern ssize_t streamReaderRead(void *, Stream);

9
include/stream/interface/writer.h

@ -27,15 +27,14 @@
#include <sys/types.h>
#include "trbase.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;
TR_INTERFACE(StreamWriter) {
TR_IFID;
fptr_streamWriterWrite write;
};
extern ssize_t streamWriterWrite(void *, Stream);

4
include/stream/stream.h

@ -26,14 +26,14 @@
#include <sys/types.h>
#include <openssl/ssl.h>
#include "class.h"
#include "trbase.h"
typedef enum e_StreamHandleType {
STREAM_FD = 0,
STREAM_SSL
} StreamHandleType;
CLASS(Stream) {
TR_CLASS(Stream) {
StreamHandleType type;
union {
int fd;

4
include/tree.h

@ -23,7 +23,7 @@
#ifndef __TREE_H__
#define __TREE_H__
#include "class.h"
#include "trbase.h"
#define TREE_RIGHT(node) (NULL!=(node)?(node)->right:NULL)
#define TREE_LEFT(node) (NULL!=(node)?(node)->left:NULL)
@ -114,7 +114,7 @@
enum rbColor {rbBlack=1, rbRed=2};
CLASS(Tree) {
TR_CLASS(Tree) {
void * data;
enum rbColor color;

5
include/user.h

@ -25,12 +25,11 @@
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "uuid.h"
#include "auth.h"
#include "storage/storage.h"
CLASS(User) {
TR_CLASS(User) {
unsigned long hash;
AuthModule auth_type;

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:

5
include/uuid.h

@ -33,13 +33,12 @@
#include <sys/types.h>
#include <uuid/uuid.h>
#include "class.h"
#include "commons.h"
#include "trbase.h"
typedef char UuidString[37];
CLASS(Uuid) {
TR_CLASS(Uuid) {
union {
uuid_t value;
struct {

33
src/Makefile.am

@ -3,25 +3,18 @@ AUTOMAKE_OPTIONS = subdir-objects
TRUTILS = utils/hash.c \
utils/memory.c \
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
TRCOMMONLIBS = 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 \
@ -36,21 +29,21 @@ TR = ./application/.libs/libapplication.a \
./config/.libs/libconfig.a \
./router/.libs/librouter.a
TRLIBS = -ltrutils -ltrhttpserver -ltrbase
TRLIBS = -ltrutils -ltrhttpserver -ltrcommon
USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid -ldl
AM_CFLAGS += -I../include/
bin_PROGRAMS = taskrambler
lib_LTLIBRARIES = libtrutils.la libtrbase.la libtrhttpserver.la
lib_LTLIBRARIES = libtrutils.la libtrcommon.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)
libtrcommon_la_SOURCES =
libtrcommon_la_CFLAGS = $(AM_CFLAGS)
libtrcommon_la_LIBADD = $(TRCOMMONLIBS)
libtrhttpserver_la_SOURCES =
libtrhttpserver_la_CFLAGS = $(AM_CFLAGS)
@ -62,6 +55,6 @@ 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 \
SUBDIRS = asset auth cbuf hash queue http \
logger server session socket stream tree application \
storage user config router uuid

16
src/application/adapter/http/http.c

@ -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,16 @@ 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));
TR_IF(TR_Class),
TR_IF(TR_Observer));
// vim: set ts=4 sw=4:

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

@ -25,6 +25,7 @@
#include <stdio.h>
#include <sys/types.h>
#include "trbase.h"
#include "application/application.h"
#include "application/adapter/http.h"
#include "hash.h"
@ -74,7 +75,7 @@ applicationAdapterHttpUpdate(void * _this, void * subject)
nbuf = sprintf(buf, "sid=%s;Path=/", session->id);
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,

19
src/application/application.c

@ -24,13 +24,12 @@
#include <stdarg.h>
#include "class.h"
#include "trbase.h"
#include "hash.h"
#include "uuid.h"
#include "application/application.h"
#include "storage/storage.h"
#include "utils/memory.h"
#include "config.h"
static
@ -57,9 +56,9 @@ applicationCtor(void * _this, va_list * params)
this->auth = va_arg(*params, void *);
this->active_sessions = memCalloc(SESSION_LIVETIME, sizeof(Hash));
this->active_sessions = TR_calloc(SESSION_LIVETIME, sizeof(Hash));
for (i=0; i<SESSION_LIVETIME; i++) {
this->active_sessions[i] = new(Hash);
this->active_sessions[i] = TR_new(Hash);
}
this->version = VERSION;
@ -75,18 +74,18 @@ applicationDtor(void * _this)
Application this = _this;
size_t i;
delete(this->user_namespace);
TR_delete(this->user_namespace);
for (i=0; i<SESSION_LIVETIME; i++) {
delete(this->active_sessions[i]);
TR_delete(this->active_sessions[i]);
}
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, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

5
src/application/controller/_get_credential_from_args.c

@ -22,11 +22,10 @@
#define _GNU_SOURCE
#include "trbase.h"
#include "hash.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
int _controllerValidatePasswordRepeat(char *, size_t, char *, size_t);
@ -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);

6
src/application/controller/_get_user_from_args.c

@ -22,12 +22,10 @@
#define _GNU_SOURCE
#include "trbase.h"
#include "hash.h"
#include "user.h"
#include "utils/memory.h"
#include "commons.h"
User
_controllerGetUserFromArgs(Hash args)
@ -44,7 +42,7 @@ _controllerGetUserFromArgs(Hash args)
return FALSE;
}
return new(User,
return TR_new(User,
(char *)(email->value), email->nvalue,
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,

7
src/application/controller/_process_user_create_args.c

@ -22,12 +22,11 @@
#define _GNU_SOURCE
#include "trbase.h"
#include "hash.h"
#include "user.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
User _controllerGetUserFromArgs(Hash args);
Credential _controllerGetCredentialFromArgs(Hash args);
@ -39,8 +38,8 @@ _controllerProcessUserCreateArgs(Hash args, User * user, Credential * cred)
*cred = _controllerGetCredentialFromArgs(args);
if (NULL == *user || NULL == *cred) {
delete(*user);
delete(*cred);
TR_delete(*user);
TR_delete(*cred);
return FALSE;
}

8
src/application/controller/_update_user_from_args.c

@ -22,12 +22,10 @@
#define _GNU_SOURCE
#include "trbase.h"
#include "hash.h"
#include "user.h"
#include "utils/memory.h"
#include "commons.h"
int
_controllerUpdateUserFromArgs(Hash args, User * user)
@ -45,13 +43,13 @@ _controllerUpdateUserFromArgs(Hash args, User * user)
return FALSE;
}
new_user = new(User,
new_user = TR_new(User,
(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;

4
src/application/controller/_validate_email.c

@ -22,13 +22,13 @@
#define _GNU_SOURCE
#include "trbase.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 +49,7 @@ _controllerCreateUserFromArgs(Hash args)
return NULL;
}
return new(User,
return TR_new(User,
(char *)(email->value), email->nvalue,
(char *)(firstname->value), firstname->nvalue,
(char *)(surname->value), surname->nvalue);

3
src/application/controller/_validate_password.c

@ -20,11 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trbase.h"
#include "hash.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
int
_controllerValidatePassword(

4
src/application/controller/_validate_password_repeat.c

@ -20,12 +20,10 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "trbase.h"
#include "hash.h"
#include "auth/credential.h"
#include "utils/memory.h"
#include "commons.h"
int
_controllerValidatePasswordRepeat(
char * password,

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

@ -22,14 +22,13 @@
#define _GNU_SOURCE
#include "class.h"
#include "trbase.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);
@ -56,7 +55,7 @@ controllerAuthenticateCreate(
return NULL;
}
credential = new(Credential,
credential = TR_new(Credential,
CRED_PASSWORD,
(char *)(username->value), username->nvalue,
(char *)(password->value), password->nvalue);
@ -67,7 +66,7 @@ controllerAuthenticateCreate(
response_data = controllerCurrentuserRead(application, session, NULL);
}
delete(credential);
TR_delete(credential);
return response_data;
}

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

@ -22,12 +22,10 @@
#define _GNU_SOURCE
#include "class.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
char * controllerCurrentuserRead(Application, Session, Hash);

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

@ -25,13 +25,11 @@
#include <sys/types.h>
#include <stdio.h>
#include "class.h"
#include "trbase.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\"}"
@ -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 : "",

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

@ -25,12 +25,11 @@
#include <sys/types.h>
#include <stdio.h>
#include "trbase.h"
#include "application/application.h"
#include "hash.h"
#include "session.h"
#include "utils/memory.h"
#define LOC_JSON "{\"loc\":\"%s\"}"
char *
@ -40,7 +39,7 @@ controllerLocRead(Application app, Session sess, Hash args)
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;

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

@ -25,14 +25,14 @@
#include <sys/types.h>
#include <stdio.h>
#include "trbase.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)
{
@ -49,7 +49,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,

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

@ -25,12 +25,11 @@
#include <stdio.h>
#include <sys/types.h>
#include "trbase.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
#define SESSION_JSON "{\"id\":\"%s\",\"timeout\":%d,\"timeleft\":%ld}"
@ -47,7 +46,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,

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

@ -22,13 +22,13 @@
#define _GNU_SOURCE
#include "trbase.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 *);
@ -55,9 +55,9 @@ controllerSignupCreate(
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;

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

@ -22,13 +22,13 @@
#define _GNU_SOURCE
#include "trbase.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 *);
@ -53,9 +53,9 @@ controllerUserCreate(
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;
}

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

@ -25,13 +25,11 @@
#include <sys/types.h>
#include <stdio.h>
#include "class.h"
#include "trbase.h"
#include "application/application.h"
#include "session.h"
#include "hash.h"
#include "utils/memory.h"
#define USER_JSON \
"{\"email\":\"%s\",\"firstname\":\"%s\",\"surname\":\"%s\"}"
@ -49,7 +47,7 @@ controllerUserRead(Application app, Session sess, Hash args)
user->email,
user->firstname,
user->surname);
buffer = memMalloc(nbuffer);
buffer = TR_malloc(nbuffer);
nbuffer = sprintf(buffer, USER_JSON,
user->email,
user->firstname,

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

@ -22,13 +22,12 @@
#define _GNU_SOURCE
#include "trbase.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 *);
@ -49,7 +48,7 @@ controllerUserUpdate(
if (0 == uuidCompare(uuidZero, user_id)) {
return NULL;
}
delete(user_id);
TR_delete(user_id);
return controllerCurrentuserRead(application, session, NULL);
}

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

@ -25,12 +25,11 @@
#include <sys/types.h>
#include <stdio.h>
#include "trbase.h"
#include "application/application.h"
#include "hash.h"
#include "session.h"
#include "utils/memory.h"
#define VERSION_JSON "{\"version\":\"%s\"}"
char *
@ -40,7 +39,7 @@ controllerVersionRead(Application app, Session sess, Hash args)
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;

14
src/application/create_user.c

@ -26,19 +26,13 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.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
applicationCreateUser(
Application this,
@ -49,8 +43,8 @@ applicationCreateUser(
size_t nuser_serialized;
Uuid index;
index = indexUuid(user, this->user_namespace);
serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
index = TR_indexUuid(user, this->user_namespace);
TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
if (SPR_OK != storagePut(
this->users,
@ -62,7 +56,7 @@ applicationCreateUser(
return uuidZero;
}
MEM_FREE(user_serialized);
TR_MEM_FREE(user_serialized);
if (! applicationUpdatePassword(this, cred, user)) {
/**

12
src/application/get_user.c

@ -24,19 +24,13 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.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)
{
@ -52,11 +46,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;

27
src/application/login.c

@ -26,15 +26,10 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.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"
@ -47,11 +42,11 @@ applicationLogin(
Uuid search;
AuthModule auth_module;
User user = new(User, NULL);
User user = TR_new(User, NULL);
user->username = CRED_PWD(credential).user;
user->nusername = &CRED_PWD(credential).nuser;
search = indexUuid(user, this->user_namespace);
search = TR_indexUuid(user, this->user_namespace);
auth_module = authenticate(this->auth, credential, search);
@ -71,11 +66,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 +82,15 @@ 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,
CRED_PWD(credential).user,
CRED_PWD(credential).nuser,
CSTRA(""),
CSTRA(""),
CSTRA(""));
serialize(
TR_serialize(
session->user,
(unsigned char **)&user_serialized,
&nuser_serialized);
@ -110,7 +105,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 +115,11 @@ applicationLogin(
break;
}
delete(search);
TR_delete(search);
return TRUE;
}
delete(search);
TR_delete(search);
return FALSE;
}

5
src/application/logout.c

@ -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:

7
src/application/session_cleanup.c

@ -25,12 +25,11 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.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,7 +42,7 @@ applicationSessionCleanup(Application this, time_t now)
}
if (0 < expired && SESSION_LIVETIME > expired) {
Hash * tmp_buf = memCalloc(SESSION_LIVETIME, sizeof(Hash));
Hash * tmp_buf = TR_calloc(SESSION_LIVETIME, sizeof(Hash));
memcpy(
&(tmp_buf[expired]),
@ -54,7 +53,7 @@ applicationSessionCleanup(Application this, time_t now)
&(this->active_sessions[SESSION_LIVETIME - expired]),
expired * sizeof(Hash));
MEM_FREE(this->active_sessions);
TR_MEM_FREE(this->active_sessions);
this->active_sessions = tmp_buf;
}

3
src/application/session_get.c

@ -24,13 +24,10 @@
#include <sys/types.h>
#include "class.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
Session
applicationSessionGet(Application this, const char * sid)

5
src/application/session_start.c

@ -25,17 +25,16 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "session.h"
#include "hash.h"
#include "application/application.h"
#include "utils/memory.h"
Session
applicationSessionStart(Application this)
{
Session sess = new(Session);
Session sess = TR_new(Session);
hashAdd((this->active_sessions)[0], sess);

3
src/application/session_stop.c

@ -24,12 +24,9 @@
#include <sys/types.h>
#include "class.h"
#include "session.h"
#include "application/application.h"
#include "utils/memory.h"
void
applicationSessionStop(Application this, Session session)

12
src/application/update_password.c

@ -26,16 +26,12 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.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(
@ -57,16 +53,16 @@ applicationUpdatePassword(
}
memcpy(hash_data, salt, SALT_SIZE);
MEM_FREE(salt);
TR_MEM_FREE(salt);
index = indexUuid(user, this->user_namespace);
index = TR_indexUuid(user, this->user_namespace);
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;
}

13
src/application/update_user.c

@ -26,18 +26,13 @@
#include <stdlib.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.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
applicationUpdateUser(
@ -48,8 +43,8 @@ applicationUpdateUser(
size_t nuser_serialized;
Uuid index;
index = indexUuid(user, this->user_namespace);
serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
index = TR_indexUuid(user, this->user_namespace);
TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
if (SPR_OK != storageUpdate(
this->users,
@ -61,7 +56,7 @@ applicationUpdateUser(
return uuidZero;
}
MEM_FREE(user_serialized);
TR_MEM_FREE(user_serialized);
return index;
}

8
src/asset/asset.c

@ -37,7 +37,7 @@
#include <time.h>
#include "class.h"
#include "trbase.h"
#include "asset.h"
#include "hash.h"
@ -138,8 +138,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(Hashable, assetGetHash, assetHandleDouble);
TR_CREATE_CLASS(Asset, NULL, TR_IF(TR_Class), TR_IF(Hashable));
// vim: set ts=4 sw=4:

16
src/asset/pool.c

@ -25,7 +25,7 @@
// for strlen
#include "class.h"
#include "trbase.h"
#include "asset.h"
#include "hash.h"
@ -36,7 +36,7 @@ inline
void
freeAsset(const void * _node)
{
delete(_node);
TR_delete(_node);
}
Asset
@ -45,13 +45,13 @@ assetPoolGet(const char * path, size_t npath)
Asset asset = NULL;
if (NULL == asset_pool) {
asset_pool = new(Hash);
asset_pool = TR_new(Hash);
} else {
asset = 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);
}
@ -75,9 +75,11 @@ assetPoolRelease(Asset asset)
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...
*/
}
}
@ -89,7 +91,7 @@ assetPoolCleanup(void)
{
if (NULL != asset_pool) {
hashEach(asset_pool, freeAsset);
delete(asset_pool);
TR_delete(asset_pool);
}
}

12
src/auth/auth.c

@ -26,10 +26,8 @@
#include <stdio.h>
#include <ldap.h>
#include "class.h"
#include "trbase.h"
#include "uuid.h"
#include "utils/memory.h"
#include "commons.h"
#include "auth.h"
#include "auth/credential.h"
@ -57,7 +55,7 @@ authDtor(void * _this)
int i;
for (i=1; i<=MAX_AUTH; i++) {
delete(this->auth[i]);
TR_delete(this->auth[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, TR_IF(TR_Class), TR_IF(Auth));
// vim: set ts=4 sw=4:

9
src/auth/create.c

@ -23,11 +23,10 @@
#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 +34,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;
}

16
src/auth/credential.c

@ -25,9 +25,7 @@
#include <stdlib.h>
#include <string.h>
#include "class.h"
#include "utils/memory.h"
#include "trbase.h"
#include "auth/credential.h"
static
@ -48,11 +46,11 @@ credentialCtor(void * _this, va_list * params)
pass = va_arg(* params, char*);
CRED_PWD(this).npass = va_arg(* params, size_t);
CRED_PWD(this).user = memMalloc(CRED_PWD(this).nuser + 1);
CRED_PWD(this).user = TR_malloc(CRED_PWD(this).nuser + 1);
CRED_PWD(this).user[CRED_PWD(this).nuser] = 0;
memcpy(CRED_PWD(this).user, user, CRED_PWD(this).nuser);
CRED_PWD(this).pass = memMalloc(CRED_PWD(this).npass + 1);
CRED_PWD(this).pass = TR_malloc(CRED_PWD(this).npass + 1);
CRED_PWD(this).pass[CRED_PWD(this).npass] = 0;
memcpy(CRED_PWD(this).pass, pass, CRED_PWD(this).npass);
}
@ -73,13 +71,13 @@ credentialDtor(void * _this)
switch(this->type) {
case CRED_PASSWORD:
MEM_FREE(CRED_PWD(this).user);
MEM_FREE(CRED_PWD(this).pass);
TR_MEM_FREE(CRED_PWD(this).user);
TR_MEM_FREE(CRED_PWD(this).pass);
break;
}
}
INIT_IFACE(Class, credentialCtor, credentialDtor, NULL);
CREATE_CLASS(Credential, NULL, IFACE(Class));
TR_INIT_IFACE(TR_Class, credentialCtor, credentialDtor, NULL);
TR_CREATE_CLASS(Credential, NULL, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

7
src/auth/interface/auth.c

@ -25,17 +25,14 @@
#include "auth/credential.h"
#include "auth/interface/auth.h"
const struct interface i_Auth = {
"auth",
1
};
TR_CREATE_INTERFACE(Auth, 1);
int
authenticate(void * auth, Credential cred, Uuid user_index)
{
int ret;
RETCALL(auth, Auth, authenticate, ret, cred, user_index);
TR_RETCALL(auth, Auth, authenticate, ret, cred, user_index);
return ret;
}

18
src/auth/ldap.c

@ -26,10 +26,8 @@
#include <stdio.h>
#include <ldap.h>
#include "class.h"
#include "trbase.h"
#include "uuid.h"
#include "utils/memory.h"
#include "commons.h"
#include "auth/ldap.h"
#include "auth/credential.h"
@ -43,7 +41,7 @@ authLdapCtor(void * _this, va_list * params)
char * url = va_arg(*params, char*);
char * base_dn;
this->url = memMalloc(strlen(url) + 1);
this->url = TR_malloc(strlen(url) + 1);
strcpy(this->url, url);
this->version = 3;
@ -51,7 +49,7 @@ authLdapCtor(void * _this, va_list * params)
base_dn = va_arg(* params, char *);
this->nbase_dn = va_arg(* params, size_t);
this->base_dn = memMalloc(this->nbase_dn + 1);
this->base_dn = TR_malloc(this->nbase_dn + 1);
this->base_dn[this->nbase_dn] = 0;
memcpy(this->base_dn, base_dn, this->nbase_dn);
@ -64,8 +62,8 @@ authLdapDtor(void * _this)
{
AuthLdap this = _this;
MEM_FREE(this->base_dn);
MEM_FREE(this->url);
TR_MEM_FREE(this->base_dn);
TR_MEM_FREE(this->url);
}
static
@ -118,8 +116,8 @@ authLdapAuthenticate(void * _this, Credential cred, Uuid user_index)
return FALSE;
}
INIT_IFACE(Class, authLdapCtor, authLdapDtor, NULL);
INIT_IFACE(Auth, authLdapAuthenticate);
CREATE_CLASS(AuthLdap, NULL, IFACE(Class), IFACE(Auth));
TR_INIT_IFACE(TR_Class, authLdapCtor, authLdapDtor, NULL);
TR_INIT_IFACE(Auth, authLdapAuthenticate);
TR_CREATE_CLASS(AuthLdap, NULL, TR_IF(TR_Class), TR_IF(Auth));
// vim: set ts=4 sw=4:

10
src/auth/storage/hash_pw.c

@ -25,10 +25,8 @@
#include <openssl/evp.h>
#include <openssl/rand.h>
#include "class.h"
#include "trbase.h"
#include "auth/storage.h"
#include "utils/memory.h"
#include "commons.h"
/*
* I have to hash the passwords, maybe this will move in
@ -78,9 +76,9 @@ hash_pw(
unsigned char ** salt)
{
if (NULL == *salt) {
*salt = memCalloc(SALT_SIZE, sizeof(unsigned char));
*salt = TR_calloc(SALT_SIZE, sizeof(unsigned char));
if (0 > RAND_pseudo_bytes(*salt, SALT_SIZE)) {
MEM_FREE(*salt);
TR_MEM_FREE(*salt);
return FALSE;
}
}
@ -94,7 +92,7 @@ hash_pw(
EVP_sha512(),
HASH_SIZE,
hash)) {
MEM_FREE(*salt);
TR_MEM_FREE(*salt);
return FALSE;
}

16
src/auth/storage/storage.c

@ -20,13 +20,11 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "class.h"
#include "trbase.h"
#include "storage/storage.h"
#include "auth.h"
#include "uuid.h"
#include "user.h"
#include "commons.h"
#include "utils/memory.h"
static
int
@ -77,21 +75,21 @@ authStorageAuthenticate(void * _this, Credential cred, Uuid user_index)
CRED_PWD(cred).npass,
current_hash,
&found_hash)) {
MEM_FREE(found_hash);
TR_MEM_FREE(found_hash);
return FALSE;
}
if (0 != memcmp(current_hash, found_hash+SALT_SIZE, HASH_SIZE)) {
MEM_FREE(found_hash);
TR_MEM_FREE(found_hash);
return FALSE;
}
MEM_FREE(found_hash);
TR_MEM_FREE(found_hash);
return TRUE;
}
INIT_IFACE(Class, authStorageCtor, authStorageDtor, NULL);
INIT_IFACE(Auth, authStorageAuthenticate);
CREATE_CLASS(AuthStorage, NULL, IFACE(Class), IFACE(Auth));
TR_INIT_IFACE(TR_Class, authStorageCtor, authStorageDtor, NULL);
TR_INIT_IFACE(Auth, authStorageAuthenticate);
TR_CREATE_CLASS(AuthStorage, NULL, TR_IF(TR_Class), TR_IF(Auth));
// vim: set ts=4 sw=4:

16
src/cbuf/cbuf.c

@ -33,9 +33,7 @@
#include <unistd.h>
#include <fcntl.h>
#include "class.h"
#include "utils/memory.h"
#include "trbase.h"
#include "cbuf.h"
@ -53,15 +51,15 @@ cbufCtor(void * _this, va_list * params)
int shm;
char * data;
this->shm_name = memMalloc(strlen(shm_name) + 7 + 2);
this->shm_name = TR_malloc(strlen(shm_name) + 7 + 2);
sprintf(this->shm_name, "/%06d_%s", getpid(), shm_name);
/**
* align size at page boundary.
* increase as neccessary
*/
size = va_arg(*params, size_t);
size = (0 >= size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize;
size = va_arg(*params, size_t);
size = (0 >= size)? 1 : (0 != size%psize)? (size/psize)+1 : size/psize;
this->bsize = psize * size;
while (-1 == state) {
@ -110,7 +108,7 @@ cbufDtor(void * _this)
{
Cbuf this = _this;
MEM_FREE(this->shm_name);
TR_MEM_FREE(this->shm_name);
if (NULL != this->data && MAP_FAILED != this->data) {
munmap(this->data, this->bsize << 1);
@ -119,7 +117,7 @@ cbufDtor(void * _this)
this->data = NULL;
}
INIT_IFACE(Class, cbufCtor, cbufDtor, NULL);
CREATE_CLASS(Cbuf, NULL, IFACE(Class));
TR_INIT_IFACE(TR_Class, cbufCtor, cbufDtor, NULL);
TR_CREATE_CLASS(Cbuf, NULL, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

2
src/cbuf/is_locked.c

@ -22,8 +22,6 @@
#include "cbuf.h"
#include "commons.h"
Bool
cbufIsLocked(Cbuf this)
{

9
src/class/Makefile.am

@ -1,9 +0,0 @@
ACLOCAL_AMFLAGS = -I m4
AUTOMAKE_OPTIONS = subdir-objects
AM_CFLAGS += -I../../include/
noinst_LTLIBRARIES = libclass.la
libclass_la_SOURCES = interface.c interface/i_class.c
libclass_la_CFLAGS = $(AM_CFLAGS)

64
src/class/interface.c

@ -1,64 +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/>.
*/
#include <sys/types.h>
#include <stdlib.h>
#include "class/interface.h"
#include "commons.h"
static
inline
int
comp(const void * _a, const void * _b)
{
const struct interface * a = **(const struct interface ***)_a;
const struct interface * b = **(const struct interface ***)_b;
return ((a)<(b))? -1 : ((a)>(b))? 1 : 0;
}
/**
* this one is important in selector functions to get the correct interface
* implementation of a class.
*/
iface_ptr
interfaceGet(iface_impl_ptr iface_impl, const iface_ptr _iface)
{
const iface_ptr * iface = &_iface;
iface_ptr * found;
if (! iface_impl->simpl) {
qsort((void**)(iface_impl->impl), iface_impl->nimpl, sizeof(iface_ptr), comp);
iface_impl->simpl=TRUE;
}
found = bsearch(
&iface,
iface_impl->impl,
iface_impl->nimpl,
sizeof(iface_ptr),
comp);
return found? *found : (iface_ptr)NULL;
}
// vim: set ts=4 sw=4:

99
src/class/interface/i_class.c

@ -1,99 +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/>.
*/
#include <stdarg.h>
#include <stdlib.h>
#include <assert.h>
#include "class/class.h"
#include "class/interface/class.h"
#include "utils/memory.h"
const
struct interface i_Class = {
"class",
3
};
void *
classNewParams(class_ptr class, va_list * params)
{
void * object = memCalloc(1, class->object_size + sizeof(void*));
int ret;
* (class_ptr *)object = class;
object += sizeof(void*);
RETCALL(object, Class, ctor, ret, params);
if (-1 == ret) {
classDelete(&object);
}
return object;
}
void *
classNew(class_ptr class, ...)
{
va_list params;
void * object;
va_start(params, class);
object = classNewParams(class, &params);
va_end(params);
return object;
}
void
classDelete(void ** object)
{
if (NULL != *object) {
void * mem;
CALL(*object, Class, dtor);
mem = *object - sizeof(void*);
MEM_FREE(mem);
*object = NULL;
}
}
void *
classClone(void * _object)
{
class_ptr class = GET_CLASS(_object);
void * object = memCalloc(1, class->object_size + sizeof(void*));
* (class_ptr *)object = class;
object += sizeof(void*);
#undef clone
CALL(object, Class, clone, _object);
return object;
}
// vim: set ts=4 sw=4:

22
src/config/config.c

@ -26,10 +26,9 @@
#include <ctype.h>
#include <sys/types.h>
#include "class.h"
#include "trbase.h"
#include "config/config.h"
#include "config/value.h"
#include "utils/memory.h"
static
int
@ -42,17 +41,17 @@ configCtor(void * _this, va_list * params)
char * cnf_file = va_arg(*params, char *);
size_t ncnf_file = strlen(cnf_file);
this->cnf_file = memMalloc(ncnf_file + 1);
this->cnf_file = TR_malloc(ncnf_file + 1);
memcpy(this->cnf_file, cnf_file, ncnf_file);
this->cnf_file[ncnf_file] = '\0';
handle = fopen(this->cnf_file, "r");
if (NULL == handle) {
MEM_FREE(this->cnf_file);
TR_MEM_FREE(this->cnf_file);
return -1;
}
this->config = new(Hash);
this->config = TR_new(Hash);
line[MAX_CONFIG_LINE] = '\0';
@ -99,7 +98,7 @@ configCtor(void * _this, va_list * params)
if (0 != nkey && 0 != nvalue) {
hashAdd(
this->config,
new(ConfigValue, key, nkey, value, nvalue));
TR_new(ConfigValue, key, nkey, value, nvalue));
}
}
@ -108,15 +107,16 @@ configCtor(void * _this, va_list * params)
return 0;
}
static void configDtor(void * _this)
static
void configDtor(void * _this)
{
Config this = _this;
MEM_FREE(this->cnf_file);
delete(this->config);
TR_MEM_FREE(this->cnf_file);
TR_delete(this->config);
}
INIT_IFACE(Class, configCtor, configDtor, NULL);
CREATE_CLASS(Config, NULL, IFACE(Class));
TR_INIT_IFACE(TR_Class, configCtor, configDtor, NULL);
TR_CREATE_CLASS(Config, NULL, TR_IF(TR_Class));
// vim: set ts=4 sw=4:

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

Loading…
Cancel
Save