From 527b9e2d387f058228d6275c9b5b64e483361262 Mon Sep 17 00:00:00 2001 From: Georg Hopp Date: Thu, 9 Jan 2014 23:41:12 +0000 Subject: [PATCH] move all hashing helper code in separate library --- include/application/application.h | 18 ++--- include/auth/auth.h | 4 +- include/auth/interface/auth.h | 9 +-- include/user.h | 6 +- include/utils/hash.h | 33 --------- include/uuid.h | 72 ------------------- src/Makefile.am | 12 ++-- src/application/application.c | 8 +-- .../controller/_get_user_from_args.c | 13 +++- .../controller/_update_user_from_args.c | 5 +- src/application/controller/_validate_email.c | 5 +- src/application/controller/signup/create.c | 8 ++- src/application/controller/user/create.c | 8 ++- src/application/controller/user/read.c | 6 +- src/application/controller/user/update.c | 8 ++- src/application/create_user.c | 15 ++-- src/application/get_user.c | 7 +- src/application/login.c | 12 ++-- src/application/update_password.c | 8 ++- src/application/update_user.c | 13 ++-- src/asset/asset.c | 6 +- src/auth/auth.c | 6 +- src/auth/create.c | 3 +- src/auth/interface/auth.c | 3 +- src/auth/ldap.c | 6 +- src/auth/storage/storage.c | 7 +- src/config/value.c | 7 +- src/hash/delete.c | 5 +- src/hash/get.c | 5 +- src/hash/get_first.c | 3 +- src/hash/value.c | 7 +- src/http/cookie.c | 7 +- src/http/header.c | 7 +- src/http/writer/write.c | 5 +- src/session/session.c | 7 +- src/storage/storage.c | 3 +- src/taskrambler.c | 12 +++- src/user/user.c | 15 ++-- src/utils/hash.c | 55 -------------- src/uuid/Makefile.am | 12 ---- src/uuid/_format3or5.c | 54 -------------- src/uuid/compare.c | 34 --------- src/uuid/parse.c | 38 ---------- src/uuid/unparse.c | 34 --------- src/uuid/uuid.c | 60 ---------------- src/uuid/version1.c | 38 ---------- src/uuid/version3.c | 71 ------------------ src/uuid/version5.c | 71 ------------------ 48 files changed, 165 insertions(+), 686 deletions(-) delete mode 100644 include/utils/hash.h delete mode 100644 include/uuid.h delete mode 100644 src/utils/hash.c delete mode 100644 src/uuid/Makefile.am delete mode 100644 src/uuid/_format3or5.c delete mode 100644 src/uuid/compare.c delete mode 100644 src/uuid/parse.c delete mode 100644 src/uuid/unparse.c delete mode 100644 src/uuid/uuid.c delete mode 100644 src/uuid/version1.c delete mode 100644 src/uuid/version3.c delete mode 100644 src/uuid/version5.c diff --git a/include/application/application.h b/include/application/application.h index 7f6de49..229f853 100644 --- a/include/application/application.h +++ b/include/application/application.h @@ -25,7 +25,8 @@ #include -#include "trbase.h" +#include +#include #include "session.h" #include "hash.h" @@ -34,7 +35,6 @@ #include "storage/storage.h" #include "session.h" #include "user.h" -#include "uuid.h" struct randval { @@ -54,7 +54,7 @@ TR_CLASS(Application) { Storage passwords; Storage roles; - Uuid user_namespace; + TR_Uuid user_namespace; Hash roles_user_index; Hash roles_resource_index; @@ -63,12 +63,12 @@ TR_CLASS(Application) { 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); +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); Session applicationSessionGet(Application, const char *); diff --git a/include/auth/auth.h b/include/auth/auth.h index 3c6cf10..2a4b37e 100644 --- a/include/auth/auth.h +++ b/include/auth/auth.h @@ -42,8 +42,8 @@ #ifndef __AUTH_AUTH_H__ #define __AUTH_AUTH_H__ -#include "trbase.h" -#include "uuid.h" +#include + #include "auth.h" #include "auth/credential.h" diff --git a/include/auth/interface/auth.h b/include/auth/interface/auth.h index f4cc845..ed65586 100644 --- a/include/auth/interface/auth.h +++ b/include/auth/interface/auth.h @@ -28,18 +28,19 @@ #ifndef __AUTH_INTERFACE_AUTH_H__ #define __AUTH_INTERFACE_AUTH_H__ -#include "trbase.h" -#include "uuid.h" +#include +#include + #include "auth/credential.h" -typedef int (* fptr_authenticate)(void *, Credential, Uuid); +typedef int (* fptr_authenticate)(void *, Credential, TR_Uuid); 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__ diff --git a/include/user.h b/include/user.h index fee02f0..13c9221 100644 --- a/include/user.h +++ b/include/user.h @@ -25,14 +25,16 @@ #include -#include "trbase.h" -#include "uuid.h" +#include +#include + #include "auth.h" 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. diff --git a/include/utils/hash.h b/include/utils/hash.h deleted file mode 100644 index 27c36c5..0000000 --- a/include/utils/hash.h +++ /dev/null @@ -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 . - */ - -#ifndef __UTILS_HASH_H__ -#define __UTILS_HASH_H__ - -#include - -unsigned long sdbm(const unsigned char *, size_t); - -#endif // __UTILS_HASH_H__ - -// vim: set ts=4 sw=4: diff --git a/include/uuid.h b/include/uuid.h deleted file mode 100644 index 23eb2f9..0000000 --- a/include/uuid.h +++ /dev/null @@ -1,72 +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 . - */ - -#ifndef __UUID_H__ -#define __UUID_H__ - -#include -#include -#include - -#include "trbase.h" - - -typedef char UuidString[37]; - -TR_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: diff --git a/src/Makefile.am b/src/Makefile.am index dcc4a8c..f25a65f 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,8 +2,7 @@ ACLOCAL_AMFLAGS = -I m4 AUTOMAKE_OPTIONS = subdir-objects -TRUTILS = utils/hash.c \ - utils/http.c \ +TRUTILS = utils/http.c \ utils/daemonize.c \ utils/signalHandling.c \ utils/mime_type.c @@ -13,8 +12,7 @@ TRCOMMONLIBS = cbuf/libcbuf.la \ queue/libqueue.la \ logger/liblogger.la \ tree/libtree.la \ - stream/libstream.la \ - uuid/libuuid.la + stream/libstream.la TRHTTPSERVER = http/libhttp.la \ asset/libasset.la \ @@ -29,8 +27,8 @@ TR = ./application/.libs/libapplication.a \ ./config/.libs/libconfig.a \ ./router/.libs/librouter.a -TRLIBS = -ltrutils -ltrhttpserver -ltrcommon -USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid -ldl +TRLIBS = -ltrbase -ltrhashing -ltrutils -ltrhttpserver -ltrcommon +USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid AM_CFLAGS += -I../include/ @@ -57,4 +55,4 @@ taskrambler_LDFLAGS = -Wl,--export-dynamic \ SUBDIRS = asset auth cbuf hash queue http \ logger server session socket stream tree application \ - storage user config router uuid + storage user config router diff --git a/src/application/application.c b/src/application/application.c index 97f3356..98ebc34 100644 --- a/src/application/application.c +++ b/src/application/application.c @@ -24,9 +24,9 @@ #include -#include "trbase.h" -#include "hash.h" -#include "uuid.h" +#include +#include + #include "application/application.h" #include "storage/storage.h" @@ -52,7 +52,7 @@ 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 *); diff --git a/src/application/controller/_get_user_from_args.c b/src/application/controller/_get_user_from_args.c index 112b8a7..0dcc168 100644 --- a/src/application/controller/_get_user_from_args.c +++ b/src/application/controller/_get_user_from_args.c @@ -22,7 +22,9 @@ #define _GNU_SOURCE -#include "trbase.h" +#include +#include + #include "hash.h" #include "user.h" @@ -42,7 +44,16 @@ _controllerGetUserFromArgs(Hash args) return FALSE; } + /** + * \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, diff --git a/src/application/controller/_update_user_from_args.c b/src/application/controller/_update_user_from_args.c index a3246bb..81adf2e 100644 --- a/src/application/controller/_update_user_from_args.c +++ b/src/application/controller/_update_user_from_args.c @@ -22,7 +22,9 @@ #define _GNU_SOURCE -#include "trbase.h" +#include +#include + #include "hash.h" #include "user.h" @@ -44,6 +46,7 @@ _controllerUpdateUserFromArgs(Hash args, User * 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, diff --git a/src/application/controller/_validate_email.c b/src/application/controller/_validate_email.c index 1da99a1..04dd0e0 100644 --- a/src/application/controller/_validate_email.c +++ b/src/application/controller/_validate_email.c @@ -22,7 +22,9 @@ #define _GNU_SOURCE -#include "trbase.h" +#include +#include + #include "application/application.h" #include "session.h" #include "hash.h" @@ -50,6 +52,7 @@ _controllerCreateUserFromArgs(Hash args) } 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); diff --git a/src/application/controller/signup/create.c b/src/application/controller/signup/create.c index accdeeb..7e574fc 100644 --- a/src/application/controller/signup/create.c +++ b/src/application/controller/signup/create.c @@ -22,7 +22,9 @@ #define _GNU_SOURCE -#include "trbase.h" +#include +#include + #include "application/application.h" #include "session.h" #include "hash.h" @@ -42,13 +44,13 @@ controllerSignupCreate( { 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); diff --git a/src/application/controller/user/create.c b/src/application/controller/user/create.c index 00bd5b5..ec98acd 100644 --- a/src/application/controller/user/create.c +++ b/src/application/controller/user/create.c @@ -22,7 +22,9 @@ #define _GNU_SOURCE -#include "trbase.h" +#include +#include + #include "application/application.h" #include "session.h" #include "hash.h" @@ -41,13 +43,13 @@ controllerUserCreate( { 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); diff --git a/src/application/controller/user/read.c b/src/application/controller/user/read.c index 6b9f5e4..1baea02 100644 --- a/src/application/controller/user/read.c +++ b/src/application/controller/user/read.c @@ -25,7 +25,9 @@ #include #include -#include "trbase.h" +#include +#include + #include "application/application.h" #include "session.h" #include "hash.h" @@ -40,7 +42,7 @@ controllerUserRead(Application app, Session sess, Hash args) char * buffer; size_t nbuffer; HashValue id = hashGet(args, CSTRA("id")); - Uuid search = uuidParse(id->value); + TR_Uuid search = TR_uuidParse(id->value); User user = applicationGetUser(app, search); nbuffer = snprintf(NULL, 0, USER_JSON, diff --git a/src/application/controller/user/update.c b/src/application/controller/user/update.c index 6fd4b94..35a5d3c 100644 --- a/src/application/controller/user/update.c +++ b/src/application/controller/user/update.c @@ -22,7 +22,9 @@ #define _GNU_SOURCE -#include "trbase.h" +#include +#include + #include "application/application.h" #include "session.h" #include "hash.h" @@ -38,14 +40,14 @@ controllerUserUpdate( Session session, 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; } TR_delete(user_id); diff --git a/src/application/create_user.c b/src/application/create_user.c index 7ee8c81..5df4457 100644 --- a/src/application/create_user.c +++ b/src/application/create_user.c @@ -26,14 +26,15 @@ #include #include -#include "trbase.h" +#include +#include + #include "auth.h" #include "user.h" -#include "uuid.h" #include "storage/storage.h" #include "application/application.h" -Uuid +TR_Uuid applicationCreateUser( Application this, Credential cred, @@ -41,9 +42,9 @@ applicationCreateUser( { char * user_serialized; size_t nuser_serialized; - Uuid index; + TR_Uuid index; - index = TR_indexUuid(user, this->user_namespace); + index = TR_getIndex(user); TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); if (SPR_OK != storagePut( @@ -53,7 +54,7 @@ applicationCreateUser( user_serialized, nuser_serialized)) { - return uuidZero; + return TR_uuidZero; } TR_MEM_FREE(user_serialized); @@ -68,7 +69,7 @@ applicationCreateUser( (char *)(index->uuid).value, sizeof((index->uuid).value)); - return uuidZero; + return TR_uuidZero; } return index; diff --git a/src/application/get_user.c b/src/application/get_user.c index f30368b..77f3245 100644 --- a/src/application/get_user.c +++ b/src/application/get_user.c @@ -24,15 +24,16 @@ #include #include -#include "trbase.h" +#include +#include + #include "auth.h" #include "user.h" -#include "uuid.h" #include "storage/storage.h" #include "application/application.h" User -applicationGetUser(Application this, Uuid uuid) +applicationGetUser(Application this, TR_Uuid uuid) { char * user_serialized; size_t nuser_serialized; diff --git a/src/application/login.c b/src/application/login.c index 4016c64..6ab04ee 100644 --- a/src/application/login.c +++ b/src/application/login.c @@ -26,9 +26,10 @@ #include #include -#include "trbase.h" +#include +#include + #include "auth.h" -#include "uuid.h" #include "storage/storage.h" #include "application/application.h" @@ -39,14 +40,14 @@ applicationLogin( Credential credential, Session session) { - Uuid search; + TR_Uuid search; AuthModule auth_module; - User user = TR_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 = TR_indexUuid(user, this->user_namespace); + search = TR_getIndex(user); auth_module = authenticate(this->auth, credential, search); @@ -84,6 +85,7 @@ applicationLogin( session->user->username = NULL; TR_delete(session->user); session->user = TR_new(User, + this->user_namespace, CRED_PWD(credential).user, CRED_PWD(credential).nuser, CSTRA(""), diff --git a/src/application/update_password.c b/src/application/update_password.c index e8c17f5..45118d6 100644 --- a/src/application/update_password.c +++ b/src/application/update_password.c @@ -26,7 +26,9 @@ #include #include -#include "trbase.h" +#include +#include + #include "auth.h" #include "user.h" #include "storage/storage.h" @@ -42,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, @@ -55,7 +57,7 @@ applicationUpdatePassword( memcpy(hash_data, salt, SALT_SIZE); TR_MEM_FREE(salt); - index = TR_indexUuid(user, this->user_namespace); + index = TR_getIndex(user); storageUpdate( this->passwords, (char *)(index->uuid).value, diff --git a/src/application/update_user.c b/src/application/update_user.c index 41b36a6..11694c6 100644 --- a/src/application/update_user.c +++ b/src/application/update_user.c @@ -26,24 +26,25 @@ #include #include -#include "trbase.h" +#include +#include + #include "auth.h" #include "user.h" -#include "uuid.h" #include "storage/storage.h" #include "application/application.h" -Uuid +TR_Uuid applicationUpdateUser( Application this, User user) { char * user_serialized; size_t nuser_serialized; - Uuid index; + TR_Uuid index; - index = TR_indexUuid(user, this->user_namespace); + index = TR_getIndex(user); TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized); if (SPR_OK != storageUpdate( @@ -53,7 +54,7 @@ applicationUpdateUser( user_serialized, nuser_serialized)) { - return uuidZero; + return TR_uuidZero; } TR_MEM_FREE(user_serialized); diff --git a/src/asset/asset.c b/src/asset/asset.c index 05fb493..f6b7fa0 100644 --- a/src/asset/asset.c +++ b/src/asset/asset.c @@ -36,13 +36,13 @@ // for localtime #include +#include +#include -#include "trbase.h" #include "asset.h" #include "hash.h" #include "utils/mime_type.h" -#include "utils/hash.h" #include "utils/http.h" @@ -62,7 +62,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); diff --git a/src/auth/auth.c b/src/auth/auth.c index c5f3100..e260ca8 100644 --- a/src/auth/auth.c +++ b/src/auth/auth.c @@ -26,8 +26,8 @@ #include #include -#include "trbase.h" -#include "uuid.h" +#include +#include #include "auth.h" #include "auth/credential.h" @@ -61,7 +61,7 @@ authDtor(void * _this) static int -authAuthenticate(void * _this, Credential cred, Uuid user_index) +authAuthenticate(void * _this, Credential cred, TR_Uuid user_index) { Auth this = _this; int i; diff --git a/src/auth/create.c b/src/auth/create.c index 5a57712..0a2aae8 100644 --- a/src/auth/create.c +++ b/src/auth/create.c @@ -23,7 +23,8 @@ #include #include -#include "trbase.h" +#include + #include "auth.h" #include "auth/ldap.h" #include "auth/storage.h" diff --git a/src/auth/interface/auth.c b/src/auth/interface/auth.c index e5156a4..db25bf8 100644 --- a/src/auth/interface/auth.c +++ b/src/auth/interface/auth.c @@ -20,7 +20,6 @@ * along with this program. If not, see . */ -#include "uuid.h" #include "auth/auth.h" #include "auth/credential.h" #include "auth/interface/auth.h" @@ -28,7 +27,7 @@ TR_CREATE_INTERFACE(Auth, 1); int -authenticate(void * auth, Credential cred, Uuid user_index) +authenticate(void * auth, Credential cred, TR_Uuid user_index) { int ret; diff --git a/src/auth/ldap.c b/src/auth/ldap.c index dc64f72..f695ec2 100644 --- a/src/auth/ldap.c +++ b/src/auth/ldap.c @@ -26,8 +26,8 @@ #include #include -#include "trbase.h" -#include "uuid.h" +#include +#include #include "auth/ldap.h" #include "auth/credential.h" @@ -68,7 +68,7 @@ authLdapDtor(void * _this) static int -authLdapAuthenticate(void * _this, Credential cred, Uuid user_index) +authLdapAuthenticate(void * _this, Credential cred, TR_Uuid user_index) { AuthLdap this = _this; char who[256]; diff --git a/src/auth/storage/storage.c b/src/auth/storage/storage.c index 348226a..a2205d5 100644 --- a/src/auth/storage/storage.c +++ b/src/auth/storage/storage.c @@ -20,10 +20,11 @@ * along with this program. If not, see . */ -#include "trbase.h" +#include +#include + #include "storage/storage.h" #include "auth.h" -#include "uuid.h" #include "user.h" static @@ -45,7 +46,7 @@ authStorageDtor(void * _this) static int -authStorageAuthenticate(void * _this, Credential cred, Uuid user_index) +authStorageAuthenticate(void * _this, Credential cred, TR_Uuid user_index) { AuthStorage this = _this; diff --git a/src/config/value.c b/src/config/value.c index 7cd961c..2876b3a 100644 --- a/src/config/value.c +++ b/src/config/value.c @@ -25,9 +25,10 @@ #include #include -#include "trbase.h" +#include +#include + #include "config/value.h" -#include "utils/hash.h" static int @@ -40,7 +41,7 @@ configValueCtor(void * _this, va_list * params) char * value = va_arg(*params, char *); size_t nvalue = va_arg(*params, size_t); - this->hash = sdbm((unsigned char *)key, nkey); + this->hash = TR_sdbm((unsigned char *)key, nkey); /** * if we find the value enclosed by single or double diff --git a/src/hash/delete.c b/src/hash/delete.c index 5c4fdd7..e806f35 100644 --- a/src/hash/delete.c +++ b/src/hash/delete.c @@ -22,9 +22,10 @@ #include +#include + #include "asset.h" #include "hash.h" -#include "utils/hash.h" static inline @@ -47,7 +48,7 @@ hashDeleteComp(const void * a, const void * b) void * hashDelete(Hash this, const char * search, size_t nsearch) { - unsigned long hash = sdbm((const unsigned char *)search, nsearch); + unsigned long hash = TR_sdbm((const unsigned char *)search, nsearch); void * found = NULL; found = treeDelete(&(this->root), &hash, hashDeleteComp); diff --git a/src/hash/get.c b/src/hash/get.c index dd88354..a051a21 100644 --- a/src/hash/get.c +++ b/src/hash/get.c @@ -25,9 +25,10 @@ #include #include +#include + #include "hash.h" #include "tree.h" -#include "utils/hash.h" static inline @@ -50,7 +51,7 @@ hashGetComp(const void * a, const void * b) void * hashGet(Hash this, const char * search, size_t nsearch) { - unsigned long hash = sdbm((const unsigned char *)search, nsearch); + unsigned long hash = TR_sdbm((const unsigned char *)search, nsearch); void * found = treeFind(this->root, &hash, hashGetComp); return found; diff --git a/src/hash/get_first.c b/src/hash/get_first.c index 66f4bdc..d181eaa 100644 --- a/src/hash/get_first.c +++ b/src/hash/get_first.c @@ -25,9 +25,10 @@ #include #include +#include + #include "hash.h" #include "tree.h" -#include "utils/hash.h" void * hashGetFirst(Hash this) diff --git a/src/hash/value.c b/src/hash/value.c index f5b495d..dabbcec 100644 --- a/src/hash/value.c +++ b/src/hash/value.c @@ -25,8 +25,9 @@ #include #include -#include "trbase.h" -#include "utils/hash.h" +#include +#include + #include "hash/value.h" #include "hash/interface/hashable.h" @@ -46,7 +47,7 @@ hashValueCtor(void * _this, va_list * params) this->key[this->nkey] = 0; memcpy(this->key, key, this->nkey); - this->hash = sdbm((unsigned char *)this->key, this->nkey); + this->hash = TR_sdbm((unsigned char *)this->key, this->nkey); if (NULL != value) { this->value = TR_malloc(this->nvalue + 1); diff --git a/src/http/cookie.c b/src/http/cookie.c index 0ed6f5c..ad0ffb2 100644 --- a/src/http/cookie.c +++ b/src/http/cookie.c @@ -25,10 +25,11 @@ #include #include -#include "trbase.h" +#include +#include + #include "hash.h" #include "http/cookie.h" -#include "utils/hash.h" static @@ -51,7 +52,7 @@ httpCookieCtor(void * _this, va_list * params) this->value[this->nvalue] = 0; memcpy(this->value, value, this->nvalue); - this->hash = sdbm((unsigned char *)key, nkey); + this->hash = TR_sdbm((unsigned char *)key, nkey); return 0; } diff --git a/src/http/header.c b/src/http/header.c index e9d4b75..2b65219 100644 --- a/src/http/header.c +++ b/src/http/header.c @@ -24,10 +24,11 @@ #include #include -#include "trbase.h" +#include +#include + #include "hash.h" #include "http/header.h" -#include "utils/hash.h" static int @@ -45,7 +46,7 @@ httpHeaderCtor(void * _this, va_list * params) { this->name[this->nname] = 0; memcpy(this->name, name, this->nname); - this->hash = sdbm((unsigned char *)name, this->nname); + this->hash = TR_sdbm((unsigned char *)name, this->nname); (this->value)[0] = TR_malloc((this->nvalue)[0] + 1); (this->value)[0][(this->nvalue)[0]] = 0; diff --git a/src/http/writer/write.c b/src/http/writer/write.c index fc7b78b..93c005a 100644 --- a/src/http/writer/write.c +++ b/src/http/writer/write.c @@ -23,7 +23,8 @@ #include #include -#include "trbase.h" +#include + #include "http/message.h" #include "queue.h" #include "http/writer.h" @@ -48,7 +49,7 @@ httpWriterWrite(void * _this, Stream st) this->written = 0; this->nheader = httpMessageHeaderSizeGet(this->current); - if (this->nheader > TR_memGetSize(this->buffer)) { + if (this->nheader > TR_getSize(this->buffer)) { ssize_t size = this->nheader; size = (0 != size%WRITER_BUF_CHUNK)? diff --git a/src/session/session.c b/src/session/session.c index 274e8e4..2322499 100644 --- a/src/session/session.c +++ b/src/session/session.c @@ -28,10 +28,11 @@ #include #include -#include "trbase.h" +#include +#include + #include "session.h" #include "hash.h" -#include "utils/hash.h" static @@ -45,7 +46,7 @@ sessionCtor(void * _this, va_list * params) uuid_generate(uuid); uuid_unparse(uuid, this->id); - this->hash = sdbm((unsigned char *)this->id, 36); + this->hash = TR_sdbm((unsigned char *)this->id, 36); return 0; } diff --git a/src/storage/storage.c b/src/storage/storage.c index bfce57d..2665658 100644 --- a/src/storage/storage.c +++ b/src/storage/storage.c @@ -24,7 +24,8 @@ #include #include -#include "trbase.h" +#include + #include "storage/storage.h" diff --git a/src/taskrambler.c b/src/taskrambler.c index fe91346..3170917 100644 --- a/src/taskrambler.c +++ b/src/taskrambler.c @@ -36,6 +36,9 @@ #include #include +#include +#include + #include "server.h" #include "logger.h" #include "http/worker.h" @@ -45,7 +48,6 @@ #include "config/config.h" #include "config/value.h" -#include "trbase.h" #include "logger.h" #include "utils/signalHandling.h" @@ -164,6 +166,7 @@ main() ApplicationAdapterHttp adapterHttp; HttpWorker worker; Server server; + TR_Uuid user_namespace; ConfigValue ldap_base = configGet(config, CSTRA("ldap_base")); @@ -205,12 +208,14 @@ main() authCreate(auth, AUTH_STORAGE, passwords); + user_namespace = TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc"); + application = TR_new( Application, value, users, passwords, - "14de9e60-d497-4754-be72-f3bed52541fc", + user_namespace, auth); router = TR_new(Router, application); @@ -272,6 +277,7 @@ main() TR_delete(adapterHttp); TR_delete(router); TR_delete(application); + TR_delete(user_namespace); TR_delete(passwords); TR_delete(users); TR_delete(auth); @@ -285,7 +291,7 @@ main() TR_delete(config); TR_delete(logger); - TR_memCleanup(); + TR_cleanup(); return 0; } diff --git a/src/user/user.c b/src/user/user.c index 9d9f4f5..3be9341 100644 --- a/src/user/user.c +++ b/src/user/user.c @@ -20,16 +20,18 @@ * along with this program. If not, see . */ -#include "user.h" -#include "uuid.h" -#include "trbase.h" +#include +#include +#include "user.h" static int userCtor(void * _this, va_list * params) { User this = _this; + + this->namespace = va_arg(* params, TR_Uuid); char * username = va_arg(* params, char *); if (NULL != username) { @@ -140,15 +142,14 @@ userUnserialize( static void * -userIndexUuid(void * _this, void * _namespace) +userIndexUuid(void * _this) { User this = _this; - Uuid namespace = _namespace; - return uuidVersion3( + return TR_uuidVersion3( (unsigned char *)this->username, *this->nusername, - namespace); + this->namespace); } diff --git a/src/utils/hash.c b/src/utils/hash.c deleted file mode 100644 index 448b4fb..0000000 --- a/src/utils/hash.c +++ /dev/null @@ -1,55 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * \author Unknown (find out) - * - * \copyright - * Copyright © 2012 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include - -#include "utils/hash.h" - -/** - * SDBM hashing algorithm: - * - * this algorithm was created for sdbm (a public-domain reimplementation of - * ndbm) database library. it was found to do well in scrambling bits, - * causing better distribution of the keys and fewer splits. it also happens - * to be a good general hashing function with good distribution. the actual - * function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below - * is the faster version used in gawk. [there is even a faster, duff-device - * version] the magic constant 65599 was picked out of thin air while - * experimenting with different constants, and turns out to be a prime. this - * is one of the algorithms used in berkeley db (see sleepycat) and elsewhere. - */ -unsigned long -sdbm(const unsigned char * str, size_t len) -{ - unsigned long hash = 0; - - for(; 0 < len; str++, len--) - hash = tolower(*str) + (hash << 6) + (hash << 16) - hash; - - return hash; -} - -// vim: set ts=4 sw=4: diff --git a/src/uuid/Makefile.am b/src/uuid/Makefile.am deleted file mode 100644 index fe48a52..0000000 --- a/src/uuid/Makefile.am +++ /dev/null @@ -1,12 +0,0 @@ -ACLOCAL_AMFLAGS = -I m4 -AUTOMAKE_OPTIONS = subdir-objects - -UUID = uuid.c version1.c version3.c version5.c _format3or5.c \ - parse.c unparse.c compare.c - -AM_CFLAGS += -I../../include/ - -noinst_LTLIBRARIES = libuuid.la - -libuuid_la_SOURCES = $(UUID) -libuuid_la_CFLAGS = $(AM_CFLAGS) diff --git a/src/uuid/_format3or5.c b/src/uuid/_format3or5.c deleted file mode 100644 index 10734bf..0000000 --- a/src/uuid/_format3or5.c +++ /dev/null @@ -1,54 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 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 . - */ - -// for memcpy -#include - -// for ntohl and similar -#include - -// for already available uuid functionality -#include - -#include "uuid.h" - -void -_uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version) -{ - /* convert UUID to local byte order */ - memcpy((uuid->uuid).value, hash, 16); - - (uuid->uuid).elements.time_low = - ntohl((uuid->uuid).elements.time_low); - (uuid->uuid).elements.time_mid = - ntohs((uuid->uuid).elements.time_mid); - (uuid->uuid).elements.time_hi_version = - ntohs((uuid->uuid).elements.time_hi_version); - - /* put in the variant and version bits */ - (uuid->uuid).elements.time_hi_version &= 0x0FFF; - (uuid->uuid).elements.time_hi_version |= (version << 12); - (uuid->uuid).elements.clk_seq_hi_res &= 0x3F; - (uuid->uuid).elements.clk_seq_hi_res |= 0x80; -} - -// vim: set ts=4 sw=4: diff --git a/src/uuid/compare.c b/src/uuid/compare.c deleted file mode 100644 index fa106f4..0000000 --- a/src/uuid/compare.c +++ /dev/null @@ -1,34 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 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 . - */ - -// for already available uuid functionality -#include - -#include "uuid.h" - -int -uuidCompare(Uuid uuid1, Uuid uuid2) -{ - return uuid_compare((uuid1->uuid).value, (uuid2->uuid).value); -} - -// vim: set ts=4 sw=4: diff --git a/src/uuid/parse.c b/src/uuid/parse.c deleted file mode 100644 index c13bb2c..0000000 --- a/src/uuid/parse.c +++ /dev/null @@ -1,38 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 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 . - */ - -// for already available uuid functionality -#include - -#include "trbase.h" -#include "uuid.h" - -Uuid -uuidParse(const UuidString uuid_str) -{ - Uuid uuid = TR_new(Uuid); - uuid_parse(uuid_str, (uuid->uuid).value); - - return uuid; -} - -// vim: set ts=4 sw=4: diff --git a/src/uuid/unparse.c b/src/uuid/unparse.c deleted file mode 100644 index 1663312..0000000 --- a/src/uuid/unparse.c +++ /dev/null @@ -1,34 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 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 . - */ - -// for already available uuid functionality -#include - -#include "uuid.h" - -void -uuidUnparse(Uuid uuid, UuidString uuid_str) -{ - uuid_unparse((uuid->uuid).value, uuid_str); -} - -// vim: set ts=4 sw=4: diff --git a/src/uuid/uuid.c b/src/uuid/uuid.c deleted file mode 100644 index 0796d0a..0000000 --- a/src/uuid/uuid.c +++ /dev/null @@ -1,60 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 Georg Hopp - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - */ - -#include -#include - -#include "trbase.h" -#include "uuid.h" - - -static -int -uuidCtor(void * _this, va_list * params) -{ - return 0; -} - -static -void -uuidDtor(void * _this) -{ -} - -static -void -uuidClone(void * _this, void * _base) -{ - Uuid this = _this; - Uuid base = _base; - - memcpy((this->uuid).value, (base->uuid).value, 16); -} - -TR_INIT_IFACE(TR_Class, uuidCtor, uuidDtor, uuidClone); -TR_CREATE_CLASS(Uuid, NULL, TR_IF(TR_Class)); - -TR_INSTANCE(Uuid, uuidZero) { - .uuid.value = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0} -}}; - -// vim: set ts=4 sw=4: diff --git a/src/uuid/version1.c b/src/uuid/version1.c deleted file mode 100644 index 1b12838..0000000 --- a/src/uuid/version1.c +++ /dev/null @@ -1,38 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 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 . - */ - -// for already available uuid functionality -#include - -#include "trbase.h" -#include "uuid.h" - -Uuid -uuidVersion1() -{ - Uuid uuid = TR_new(Uuid); - uuid_generate((uuid->uuid).value); - - return uuid; -} - -// vim: set ts=4 sw=4: diff --git a/src/uuid/version3.c b/src/uuid/version3.c deleted file mode 100644 index d4a24b9..0000000 --- a/src/uuid/version3.c +++ /dev/null @@ -1,71 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 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 . - */ - -// for size_t -#include - -// for md5 generation -#include - -// for htonl and similar -#include - -// for already available uuid functionality -#include "trbase.h" -#include "uuid.h" - -void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version); - -Uuid -uuidVersion3(const unsigned char * name, size_t nname, Uuid nsid) -{ - MD5_CTX ctx; - unsigned char hash[16]; - Uuid net_nsid = TR_clone(nsid); - Uuid uuid = TR_new(Uuid); - - /* - * put the namespace id into network byte order. - */ - (net_nsid->uuid).elements.time_low = - htonl((net_nsid->uuid).elements.time_low); - (net_nsid->uuid).elements.time_mid = - htons((net_nsid->uuid).elements.time_mid); - (net_nsid->uuid).elements.time_hi_version = - htons((net_nsid->uuid).elements.time_hi_version); - - /* - * generate the MD5 - */ - MD5_Init(&ctx); - MD5_Update(&ctx, (net_nsid->uuid).value, 16); - MD5_Update(&ctx, name, nname); - MD5_Final(hash, &ctx); - - TR_delete(net_nsid); - - _uuidFormat3or5(uuid, hash, 3); - - return uuid; -} - -// vim: set ts=4 sw=4: diff --git a/src/uuid/version5.c b/src/uuid/version5.c deleted file mode 100644 index e1586df..0000000 --- a/src/uuid/version5.c +++ /dev/null @@ -1,71 +0,0 @@ -/** - * \file - * - * \author Georg Hopp - * - * \copyright - * Copyright © 2013 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 . - */ - -// for size_t -#include - -// for sha1 generation -#include - -// for htonl and similar -#include - -// for already available uuid functionality -#include "trbase.h" -#include "uuid.h" - -void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version); - -Uuid -uuidVersion5(const unsigned char * name, size_t nname, Uuid nsid) -{ - SHA_CTX ctx; - unsigned char hash[20]; - Uuid net_nsid = TR_clone(nsid); - Uuid uuid = TR_new(Uuid); - - /* - * put the namespace id into network byte order. - */ - (net_nsid->uuid).elements.time_low = - htonl((net_nsid->uuid).elements.time_low); - (net_nsid->uuid).elements.time_mid = - htons((net_nsid->uuid).elements.time_mid); - (net_nsid->uuid).elements.time_hi_version = - htons((net_nsid->uuid).elements.time_hi_version); - - /* - * generate the MD5 - */ - SHA1_Init(&ctx); - SHA1_Update(&ctx, (net_nsid->uuid).value, 16); - SHA1_Update(&ctx, name, nname); - SHA1_Final(hash, &ctx); - - TR_delete(net_nsid); - - _uuidFormat3or5(uuid, hash, 5); - - return uuid; -} - -// vim: set ts=4 sw=4: