Commit 527b9e2d387f058228d6275c9b5b64e483361262

Authored by Georg Hopp
1 parent 1307358f

move all hashing helper code in separate library

... ... @@ -25,7 +25,8 @@
25 25
26 26 #include <sys/types.h>
27 27
28   -#include "trbase.h"
  28 +#include <trbase.h>
  29 +#include <trhash.h>
29 30
30 31 #include "session.h"
31 32 #include "hash.h"
... ... @@ -34,7 +35,6 @@
34 35 #include "storage/storage.h"
35 36 #include "session.h"
36 37 #include "user.h"
37   -#include "uuid.h"
38 38
39 39
40 40 struct randval {
... ... @@ -54,7 +54,7 @@ TR_CLASS(Application) {
54 54 Storage passwords;
55 55 Storage roles;
56 56
57   - Uuid user_namespace;
  57 + TR_Uuid user_namespace;
58 58
59 59 Hash roles_user_index;
60 60 Hash roles_resource_index;
... ... @@ -63,12 +63,12 @@ TR_CLASS(Application) {
63 63 const char * loc;
64 64 };
65 65
66   -int applicationLogin(Application, Credential, Session);
67   -void applicationLogout(Application, Session);
68   -Uuid applicationCreateUser(Application, Credential, User);
69   -Uuid applicationUpdateUser(Application, User);
70   -User applicationGetUser(Application, Uuid);
71   -int applicationUpdatePassword(Application, Credential, User);
  66 +int applicationLogin(Application, Credential, Session);
  67 +void applicationLogout(Application, Session);
  68 +TR_Uuid applicationCreateUser(Application, Credential, User);
  69 +TR_Uuid applicationUpdateUser(Application, User);
  70 +User applicationGetUser(Application, TR_Uuid);
  71 +int applicationUpdatePassword(Application, Credential, User);
72 72
73 73 Session applicationSessionStart(Application);
74 74 Session applicationSessionGet(Application, const char *);
... ...
... ... @@ -42,8 +42,8 @@
42 42 #ifndef __AUTH_AUTH_H__
43 43 #define __AUTH_AUTH_H__
44 44
45   -#include "trbase.h"
46   -#include "uuid.h"
  45 +#include <trbase.h>
  46 +
47 47 #include "auth.h"
48 48 #include "auth/credential.h"
49 49
... ...
... ... @@ -28,18 +28,19 @@
28 28 #ifndef __AUTH_INTERFACE_AUTH_H__
29 29 #define __AUTH_INTERFACE_AUTH_H__
30 30
31   -#include "trbase.h"
32   -#include "uuid.h"
  31 +#include <trbase.h>
  32 +#include <trhash.h>
  33 +
33 34 #include "auth/credential.h"
34 35
35   -typedef int (* fptr_authenticate)(void *, Credential, Uuid);
  36 +typedef int (* fptr_authenticate)(void *, Credential, TR_Uuid);
36 37
37 38 TR_INTERFACE(Auth) {
38 39 TR_IFID;
39 40 fptr_authenticate authenticate;
40 41 };
41 42
42   -extern int authenticate(void *, Credential, Uuid);
  43 +extern int authenticate(void *, Credential, TR_Uuid);
43 44
44 45 #endif // __AUTH_INTERFACE_AUTH_H__
45 46
... ...
... ... @@ -25,14 +25,16 @@
25 25
26 26 #include <sys/types.h>
27 27
28   -#include "trbase.h"
29   -#include "uuid.h"
  28 +#include <trbase.h>
  29 +#include <trhash.h>
  30 +
30 31 #include "auth.h"
31 32
32 33 TR_CLASS(User) {
33 34 unsigned long hash;
34 35 AuthModule auth_type;
35 36
  37 + TR_Uuid namespace;
36 38 /**
37 39 * username holds the identifier of the user.
38 40 * For ldap users this is the common name.
... ...
1   -/**
2   - * \file
3   - * Functions to handle varios signals send to the application.
4   - *
5   - * \author Georg Hopp
6   - *
7   - * \copyright
8   - * Copyright © 2012 Georg Hopp
9   - *
10   - * This program is free software: you can redistribute it and/or modify
11   - * it under the terms of the GNU General Public License as published by
12   - * the Free Software Foundation, either version 3 of the License, or
13   - * (at your option) any later version.
14   - *
15   - * This program is distributed in the hope that it will be useful,
16   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18   - * GNU General Public License for more details.
19   - *
20   - * You should have received a copy of the GNU General Public License
21   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - */
23   -
24   -#ifndef __UTILS_HASH_H__
25   -#define __UTILS_HASH_H__
26   -
27   -#include <sys/types.h>
28   -
29   -unsigned long sdbm(const unsigned char *, size_t);
30   -
31   -#endif // __UTILS_HASH_H__
32   -
33   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - * ways to create uuid variant 5. For uuid of variant 1 I use
4   - * the implementation delivered with the core utils.
5   - * But this is wrapped in here, so that the rest of the code
6   - * can use only this implementation...this additionally has the
7   - * advantage that we can implement version 1 here too for systems
8   - * where the coreutils implementation is not available.
9   - *
10   - * \author Georg Hopp
11   - *
12   - * \copyright
13   - * Copyright © 2012 Georg Hopp
14   - *
15   - * This program is free software: you can redistribute it and/or modify
16   - * it under the terms of the GNU General Public License as published by
17   - * the Free Software Foundation, either version 3 of the License, or
18   - * (at your option) any later version.
19   - *
20   - * This program is distributed in the hope that it will be useful,
21   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
22   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23   - * GNU General Public License for more details.
24   - *
25   - * You should have received a copy of the GNU General Public License
26   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
27   - */
28   -
29   -#ifndef __UUID_H__
30   -#define __UUID_H__
31   -
32   -#include <stdint.h>
33   -#include <sys/types.h>
34   -#include <uuid/uuid.h>
35   -
36   -#include "trbase.h"
37   -
38   -
39   -typedef char UuidString[37];
40   -
41   -TR_CLASS(Uuid) {
42   - union {
43   - uuid_t value;
44   - struct {
45   - uint32_t time_low;
46   - uint16_t time_mid;
47   - uint16_t time_hi_version;
48   - uint8_t clk_seq_hi_res;
49   - uint8_t clk_seq_low;
50   - unsigned char node[6];
51   - } elements;
52   - } uuid;
53   -};
54   -
55   -extern Uuid uuidZero;
56   -
57   -/*
58   - * generator functions...these are not really part of the object
59   - * but generate a uuid object.
60   - */
61   -Uuid uuidVersion1();
62   -Uuid uuidVersion3(const unsigned char *, size_t, Uuid);
63   -Uuid uuidVersion5(const unsigned char *, size_t, Uuid);
64   -
65   -void uuidUnparse(Uuid, UuidString);
66   -Uuid uuidParse(const UuidString);
67   -
68   -int uuidCompare(Uuid, Uuid);
69   -
70   -#endif // __UUID_H__
71   -
72   -// vim: set ts=4 sw=4:
... ... @@ -2,8 +2,7 @@ ACLOCAL_AMFLAGS = -I m4
2 2 AUTOMAKE_OPTIONS = subdir-objects
3 3
4 4
5   -TRUTILS = utils/hash.c \
6   - utils/http.c \
  5 +TRUTILS = utils/http.c \
7 6 utils/daemonize.c \
8 7 utils/signalHandling.c \
9 8 utils/mime_type.c
... ... @@ -13,8 +12,7 @@ TRCOMMONLIBS = cbuf/libcbuf.la \
13 12 queue/libqueue.la \
14 13 logger/liblogger.la \
15 14 tree/libtree.la \
16   - stream/libstream.la \
17   - uuid/libuuid.la
  15 + stream/libstream.la
18 16
19 17 TRHTTPSERVER = http/libhttp.la \
20 18 asset/libasset.la \
... ... @@ -29,8 +27,8 @@ TR = ./application/.libs/libapplication.a \
29 27 ./config/.libs/libconfig.a \
30 28 ./router/.libs/librouter.a
31 29
32   -TRLIBS = -ltrutils -ltrhttpserver -ltrcommon
33   -USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid -ldl
  30 +TRLIBS = -ltrbase -ltrhashing -ltrutils -ltrhttpserver -ltrcommon
  31 +USEDLIBS = -lrt -lssl -lcrypto -lldap -lgdbm -luuid
34 32
35 33 AM_CFLAGS += -I../include/
36 34
... ... @@ -57,4 +55,4 @@ taskrambler_LDFLAGS = -Wl,--export-dynamic \
57 55
58 56 SUBDIRS = asset auth cbuf hash queue http \
59 57 logger server session socket stream tree application \
60   - storage user config router uuid
  58 + storage user config router
... ...
... ... @@ -24,9 +24,9 @@
24 24
25 25 #include <stdarg.h>
26 26
27   -#include "trbase.h"
28   -#include "hash.h"
29   -#include "uuid.h"
  27 +#include <trbase.h>
  28 +#include <trhash.h>
  29 +
30 30 #include "application/application.h"
31 31 #include "storage/storage.h"
32 32
... ... @@ -52,7 +52,7 @@ applicationCtor(void * _this, va_list * params)
52 52 this->passwords = va_arg(*params, Storage);
53 53 //this->roles = va_arg(*params, Storage);
54 54
55   - this->user_namespace = uuidParse(va_arg(*params, char *));
  55 + this->user_namespace = va_arg(*params, TR_Uuid);
56 56
57 57 this->auth = va_arg(*params, void *);
58 58
... ...
... ... @@ -22,7 +22,9 @@
22 22
23 23 #define _GNU_SOURCE
24 24
25   -#include "trbase.h"
  25 +#include <trbase.h>
  26 +#include <trhash.h>
  27 +
26 28 #include "hash.h"
27 29 #include "user.h"
28 30
... ... @@ -42,7 +44,16 @@ _controllerGetUserFromArgs(Hash args)
42 44 return FALSE;
43 45 }
44 46
  47 + /**
  48 + * \todo how should we inject the user namespace here...
  49 + * or better, how to handle it at all...
  50 + * at least this is true for every controller...
  51 + * Additionally, this and the other controller functions
  52 + * that create a user in this way will leak memory.
  53 + * !!!IMPORTANT!!!
  54 + */
45 55 return TR_new(User,
  56 + TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc"),
46 57 (char *)(email->value), email->nvalue,
47 58 (char *)(email->value), email->nvalue,
48 59 (char *)(firstname->value), firstname->nvalue,
... ...
... ... @@ -22,7 +22,9 @@
22 22
23 23 #define _GNU_SOURCE
24 24
25   -#include "trbase.h"
  25 +#include <trbase.h>
  26 +#include <trhash.h>
  27 +
26 28 #include "hash.h"
27 29 #include "user.h"
28 30
... ... @@ -44,6 +46,7 @@ _controllerUpdateUserFromArgs(Hash args, User * user)
44 46 }
45 47
46 48 new_user = TR_new(User,
  49 + TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc"),
47 50 (char *)((*user)->username), *(*user)->nusername,
48 51 (char *)(email->value), email->nvalue,
49 52 (char *)(firstname->value), firstname->nvalue,
... ...
... ... @@ -22,7 +22,9 @@
22 22
23 23 #define _GNU_SOURCE
24 24
25   -#include "trbase.h"
  25 +#include <trbase.h>
  26 +#include <trhash.h>
  27 +
26 28 #include "application/application.h"
27 29 #include "session.h"
28 30 #include "hash.h"
... ... @@ -50,6 +52,7 @@ _controllerCreateUserFromArgs(Hash args)
50 52 }
51 53
52 54 return TR_new(User,
  55 + TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc"),
53 56 (char *)(email->value), email->nvalue,
54 57 (char *)(firstname->value), firstname->nvalue,
55 58 (char *)(surname->value), surname->nvalue);
... ...
... ... @@ -22,7 +22,9 @@
22 22
23 23 #define _GNU_SOURCE
24 24
25   -#include "trbase.h"
  25 +#include <trbase.h>
  26 +#include <trhash.h>
  27 +
26 28 #include "application/application.h"
27 29 #include "session.h"
28 30 #include "hash.h"
... ... @@ -42,13 +44,13 @@ controllerSignupCreate(
42 44 {
43 45 Credential credential;
44 46 User user;
45   - Uuid user_id;
  47 + TR_Uuid user_id;
46 48 char * response_data;
47 49
48 50 _controllerProcessUserCreateArgs(args, &user, &credential);
49 51
50 52 user_id = applicationCreateUser(application, credential, user);
51   - if (0 == uuidCompare(uuidZero, user_id)) {
  53 + if (0 == TR_uuidCompare(TR_uuidZero, user_id)) {
52 54 response_data = NULL;
53 55 } else {
54 56 applicationLogin(application, credential, session);
... ...
... ... @@ -22,7 +22,9 @@
22 22
23 23 #define _GNU_SOURCE
24 24
25   -#include "trbase.h"
  25 +#include <trbase.h>
  26 +#include <trhash.h>
  27 +
26 28 #include "application/application.h"
27 29 #include "session.h"
28 30 #include "hash.h"
... ... @@ -41,13 +43,13 @@ controllerUserCreate(
41 43 {
42 44 Credential credential;
43 45 User user;
44   - Uuid user_id;
  46 + TR_Uuid user_id;
45 47 char * response_data;
46 48
47 49 _controllerProcessUserCreateArgs(args, &user, &credential);
48 50
49 51 user_id = applicationCreateUser(application, credential, user);
50   - if (0 == uuidCompare(uuidZero, user_id)) {
  52 + if (0 == TR_uuidCompare(TR_uuidZero, user_id)) {
51 53 response_data = NULL;
52 54 } else {
53 55 response_data = controllerCurrentuserRead(application, session, NULL);
... ...
... ... @@ -25,7 +25,9 @@
25 25 #include <sys/types.h>
26 26 #include <stdio.h>
27 27
28   -#include "trbase.h"
  28 +#include <trbase.h>
  29 +#include <trhash.h>
  30 +
29 31 #include "application/application.h"
30 32 #include "session.h"
31 33 #include "hash.h"
... ... @@ -40,7 +42,7 @@ controllerUserRead(Application app, Session sess, Hash args)
40 42 char * buffer;
41 43 size_t nbuffer;
42 44 HashValue id = hashGet(args, CSTRA("id"));
43   - Uuid search = uuidParse(id->value);
  45 + TR_Uuid search = TR_uuidParse(id->value);
44 46 User user = applicationGetUser(app, search);
45 47
46 48 nbuffer = snprintf(NULL, 0, USER_JSON,
... ...
... ... @@ -22,7 +22,9 @@
22 22
23 23 #define _GNU_SOURCE
24 24
25   -#include "trbase.h"
  25 +#include <trbase.h>
  26 +#include <trhash.h>
  27 +
26 28 #include "application/application.h"
27 29 #include "session.h"
28 30 #include "hash.h"
... ... @@ -38,14 +40,14 @@ controllerUserUpdate(
38 40 Session session,
39 41 Hash args)
40 42 {
41   - Uuid user_id;
  43 + TR_Uuid user_id;
42 44
43 45 if (! _controllerUpdateUserFromArgs(args, &(session->user))) {
44 46 return NULL;
45 47 }
46 48
47 49 user_id = applicationUpdateUser(application, session->user);
48   - if (0 == uuidCompare(uuidZero, user_id)) {
  50 + if (0 == TR_uuidCompare(TR_uuidZero, user_id)) {
49 51 return NULL;
50 52 }
51 53 TR_delete(user_id);
... ...
... ... @@ -26,14 +26,15 @@
26 26 #include <stdlib.h>
27 27 #include <sys/types.h>
28 28
29   -#include "trbase.h"
  29 +#include <trbase.h>
  30 +#include <trhash.h>
  31 +
30 32 #include "auth.h"
31 33 #include "user.h"
32   -#include "uuid.h"
33 34 #include "storage/storage.h"
34 35 #include "application/application.h"
35 36
36   -Uuid
  37 +TR_Uuid
37 38 applicationCreateUser(
38 39 Application this,
39 40 Credential cred,
... ... @@ -41,9 +42,9 @@ applicationCreateUser(
41 42 {
42 43 char * user_serialized;
43 44 size_t nuser_serialized;
44   - Uuid index;
  45 + TR_Uuid index;
45 46
46   - index = TR_indexUuid(user, this->user_namespace);
  47 + index = TR_getIndex(user);
47 48 TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
48 49
49 50 if (SPR_OK != storagePut(
... ... @@ -53,7 +54,7 @@ applicationCreateUser(
53 54 user_serialized,
54 55 nuser_serialized))
55 56 {
56   - return uuidZero;
  57 + return TR_uuidZero;
57 58 }
58 59
59 60 TR_MEM_FREE(user_serialized);
... ... @@ -68,7 +69,7 @@ applicationCreateUser(
68 69 (char *)(index->uuid).value,
69 70 sizeof((index->uuid).value));
70 71
71   - return uuidZero;
  72 + return TR_uuidZero;
72 73 }
73 74
74 75 return index;
... ...
... ... @@ -24,15 +24,16 @@
24 24 #include <stdlib.h>
25 25 #include <sys/types.h>
26 26
27   -#include "trbase.h"
  27 +#include <trbase.h>
  28 +#include <trhash.h>
  29 +
28 30 #include "auth.h"
29 31 #include "user.h"
30   -#include "uuid.h"
31 32 #include "storage/storage.h"
32 33 #include "application/application.h"
33 34
34 35 User
35   -applicationGetUser(Application this, Uuid uuid)
  36 +applicationGetUser(Application this, TR_Uuid uuid)
36 37 {
37 38 char * user_serialized;
38 39 size_t nuser_serialized;
... ...
... ... @@ -26,9 +26,10 @@
26 26 #include <stdlib.h>
27 27 #include <sys/types.h>
28 28
29   -#include "trbase.h"
  29 +#include <trbase.h>
  30 +#include <trhash.h>
  31 +
30 32 #include "auth.h"
31   -#include "uuid.h"
32 33 #include "storage/storage.h"
33 34 #include "application/application.h"
34 35
... ... @@ -39,14 +40,14 @@ applicationLogin(
39 40 Credential credential,
40 41 Session session)
41 42 {
42   - Uuid search;
  43 + TR_Uuid search;
43 44 AuthModule auth_module;
44 45
45   - User user = TR_new(User, NULL);
  46 + User user = TR_new(User, this->user_namespace, NULL);
46 47
47 48 user->username = CRED_PWD(credential).user;
48 49 user->nusername = &CRED_PWD(credential).nuser;
49   - search = TR_indexUuid(user, this->user_namespace);
  50 + search = TR_getIndex(user);
50 51
51 52 auth_module = authenticate(this->auth, credential, search);
52 53
... ... @@ -84,6 +85,7 @@ applicationLogin(
84 85 session->user->username = NULL;
85 86 TR_delete(session->user);
86 87 session->user = TR_new(User,
  88 + this->user_namespace,
87 89 CRED_PWD(credential).user,
88 90 CRED_PWD(credential).nuser,
89 91 CSTRA(""),
... ...
... ... @@ -26,7 +26,9 @@
26 26 #include <stdlib.h>
27 27 #include <sys/types.h>
28 28
29   -#include "trbase.h"
  29 +#include <trbase.h>
  30 +#include <trhash.h>
  31 +
30 32 #include "auth.h"
31 33 #include "user.h"
32 34 #include "storage/storage.h"
... ... @@ -42,7 +44,7 @@ applicationUpdatePassword(
42 44 unsigned char hash_data[SALT_SIZE+HASH_SIZE];
43 45 unsigned char * salt = NULL;
44 46 unsigned char * hash = hash_data+SALT_SIZE;
45   - Uuid index;
  47 + TR_Uuid index;
46 48
47 49 if (FALSE == hash_pw(
48 50 CRED_PWD(cred).pass,
... ... @@ -55,7 +57,7 @@ applicationUpdatePassword(
55 57 memcpy(hash_data, salt, SALT_SIZE);
56 58 TR_MEM_FREE(salt);
57 59
58   - index = TR_indexUuid(user, this->user_namespace);
  60 + index = TR_getIndex(user);
59 61 storageUpdate(
60 62 this->passwords,
61 63 (char *)(index->uuid).value,
... ...
... ... @@ -26,24 +26,25 @@
26 26 #include <stdlib.h>
27 27 #include <sys/types.h>
28 28
29   -#include "trbase.h"
  29 +#include <trbase.h>
  30 +#include <trhash.h>
  31 +
30 32 #include "auth.h"
31 33 #include "user.h"
32   -#include "uuid.h"
33 34 #include "storage/storage.h"
34 35 #include "application/application.h"
35 36
36 37
37   -Uuid
  38 +TR_Uuid
38 39 applicationUpdateUser(
39 40 Application this,
40 41 User user)
41 42 {
42 43 char * user_serialized;
43 44 size_t nuser_serialized;
44   - Uuid index;
  45 + TR_Uuid index;
45 46
46   - index = TR_indexUuid(user, this->user_namespace);
  47 + index = TR_getIndex(user);
47 48 TR_serialize(user, (unsigned char **)&user_serialized, &nuser_serialized);
48 49
49 50 if (SPR_OK != storageUpdate(
... ... @@ -53,7 +54,7 @@ applicationUpdateUser(
53 54 user_serialized,
54 55 nuser_serialized))
55 56 {
56   - return uuidZero;
  57 + return TR_uuidZero;
57 58 }
58 59
59 60 TR_MEM_FREE(user_serialized);
... ...
... ... @@ -36,13 +36,13 @@
36 36 // for localtime
37 37 #include <time.h>
38 38
  39 +#include <trbase.h>
  40 +#include <trhash.h>
39 41
40   -#include "trbase.h"
41 42 #include "asset.h"
42 43 #include "hash.h"
43 44
44 45 #include "utils/mime_type.h"
45   -#include "utils/hash.h"
46 46 #include "utils/http.h"
47 47
48 48
... ... @@ -62,7 +62,7 @@ assetCtor(void * _this, va_list * params)
62 62 strncpy(this->fname, fname, 2048);
63 63 this->fname[2048] = '\0';
64 64
65   - this->hash = sdbm(
  65 + this->hash = TR_sdbm(
66 66 (unsigned char *)this->fname,
67 67 this->nfname);
68 68
... ...
... ... @@ -26,8 +26,8 @@
26 26 #include <stdio.h>
27 27 #include <ldap.h>
28 28
29   -#include "trbase.h"
30   -#include "uuid.h"
  29 +#include <trbase.h>
  30 +#include <trhash.h>
31 31
32 32 #include "auth.h"
33 33 #include "auth/credential.h"
... ... @@ -61,7 +61,7 @@ authDtor(void * _this)
61 61
62 62 static
63 63 int
64   -authAuthenticate(void * _this, Credential cred, Uuid user_index)
  64 +authAuthenticate(void * _this, Credential cred, TR_Uuid user_index)
65 65 {
66 66 Auth this = _this;
67 67 int i;
... ...
... ... @@ -23,7 +23,8 @@
23 23 #include <stdarg.h>
24 24 #include <sys/types.h>
25 25
26   -#include "trbase.h"
  26 +#include <trbase.h>
  27 +
27 28 #include "auth.h"
28 29 #include "auth/ldap.h"
29 30 #include "auth/storage.h"
... ...
... ... @@ -20,7 +20,6 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include "uuid.h"
24 23 #include "auth/auth.h"
25 24 #include "auth/credential.h"
26 25 #include "auth/interface/auth.h"
... ... @@ -28,7 +27,7 @@
28 27 TR_CREATE_INTERFACE(Auth, 1);
29 28
30 29 int
31   -authenticate(void * auth, Credential cred, Uuid user_index)
  30 +authenticate(void * auth, Credential cred, TR_Uuid user_index)
32 31 {
33 32 int ret;
34 33
... ...
... ... @@ -26,8 +26,8 @@
26 26 #include <stdio.h>
27 27 #include <ldap.h>
28 28
29   -#include "trbase.h"
30   -#include "uuid.h"
  29 +#include <trbase.h>
  30 +#include <trhash.h>
31 31
32 32 #include "auth/ldap.h"
33 33 #include "auth/credential.h"
... ... @@ -68,7 +68,7 @@ authLdapDtor(void * _this)
68 68
69 69 static
70 70 int
71   -authLdapAuthenticate(void * _this, Credential cred, Uuid user_index)
  71 +authLdapAuthenticate(void * _this, Credential cred, TR_Uuid user_index)
72 72 {
73 73 AuthLdap this = _this;
74 74 char who[256];
... ...
... ... @@ -20,10 +20,11 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include "trbase.h"
  23 +#include <trbase.h>
  24 +#include <trhash.h>
  25 +
24 26 #include "storage/storage.h"
25 27 #include "auth.h"
26   -#include "uuid.h"
27 28 #include "user.h"
28 29
29 30 static
... ... @@ -45,7 +46,7 @@ authStorageDtor(void * _this)
45 46
46 47 static
47 48 int
48   -authStorageAuthenticate(void * _this, Credential cred, Uuid user_index)
  49 +authStorageAuthenticate(void * _this, Credential cred, TR_Uuid user_index)
49 50 {
50 51 AuthStorage this = _this;
51 52
... ...
... ... @@ -25,9 +25,10 @@
25 25 #include <string.h>
26 26 #include <sys/types.h>
27 27
28   -#include "trbase.h"
  28 +#include <trbase.h>
  29 +#include <trhash.h>
  30 +
29 31 #include "config/value.h"
30   -#include "utils/hash.h"
31 32
32 33 static
33 34 int
... ... @@ -40,7 +41,7 @@ configValueCtor(void * _this, va_list * params)
40 41 char * value = va_arg(*params, char *);
41 42 size_t nvalue = va_arg(*params, size_t);
42 43
43   - this->hash = sdbm((unsigned char *)key, nkey);
  44 + this->hash = TR_sdbm((unsigned char *)key, nkey);
44 45
45 46 /**
46 47 * if we find the value enclosed by single or double
... ...
... ... @@ -22,9 +22,10 @@
22 22
23 23 #include <sys/types.h>
24 24
  25 +#include <trhash.h>
  26 +
25 27 #include "asset.h"
26 28 #include "hash.h"
27   -#include "utils/hash.h"
28 29
29 30 static
30 31 inline
... ... @@ -47,7 +48,7 @@ hashDeleteComp(const void * a, const void * b)
47 48 void *
48 49 hashDelete(Hash this, const char * search, size_t nsearch)
49 50 {
50   - unsigned long hash = sdbm((const unsigned char *)search, nsearch);
  51 + unsigned long hash = TR_sdbm((const unsigned char *)search, nsearch);
51 52 void * found = NULL;
52 53
53 54 found = treeDelete(&(this->root), &hash, hashDeleteComp);
... ...
... ... @@ -25,9 +25,10 @@
25 25 #include <search.h>
26 26 #include <sys/types.h>
27 27
  28 +#include <trhash.h>
  29 +
28 30 #include "hash.h"
29 31 #include "tree.h"
30   -#include "utils/hash.h"
31 32
32 33 static
33 34 inline
... ... @@ -50,7 +51,7 @@ hashGetComp(const void * a, const void * b)
50 51 void *
51 52 hashGet(Hash this, const char * search, size_t nsearch)
52 53 {
53   - unsigned long hash = sdbm((const unsigned char *)search, nsearch);
  54 + unsigned long hash = TR_sdbm((const unsigned char *)search, nsearch);
54 55 void * found = treeFind(this->root, &hash, hashGetComp);
55 56
56 57 return found;
... ...
... ... @@ -25,9 +25,10 @@
25 25 #include <search.h>
26 26 #include <sys/types.h>
27 27
  28 +#include <trhash.h>
  29 +
28 30 #include "hash.h"
29 31 #include "tree.h"
30   -#include "utils/hash.h"
31 32
32 33 void *
33 34 hashGetFirst(Hash this)
... ...
... ... @@ -25,8 +25,9 @@
25 25 #include <string.h>
26 26 #include <sys/types.h>
27 27
28   -#include "trbase.h"
29   -#include "utils/hash.h"
  28 +#include <trbase.h>
  29 +#include <trhash.h>
  30 +
30 31 #include "hash/value.h"
31 32 #include "hash/interface/hashable.h"
32 33
... ... @@ -46,7 +47,7 @@ hashValueCtor(void * _this, va_list * params)
46 47 this->key[this->nkey] = 0;
47 48 memcpy(this->key, key, this->nkey);
48 49
49   - this->hash = sdbm((unsigned char *)this->key, this->nkey);
  50 + this->hash = TR_sdbm((unsigned char *)this->key, this->nkey);
50 51
51 52 if (NULL != value) {
52 53 this->value = TR_malloc(this->nvalue + 1);
... ...
... ... @@ -25,10 +25,11 @@
25 25 #include <stdarg.h>
26 26 #include <sys/types.h>
27 27
28   -#include "trbase.h"
  28 +#include <trbase.h>
  29 +#include <trhash.h>
  30 +
29 31 #include "hash.h"
30 32 #include "http/cookie.h"
31   -#include "utils/hash.h"
32 33
33 34
34 35 static
... ... @@ -51,7 +52,7 @@ httpCookieCtor(void * _this, va_list * params)
51 52 this->value[this->nvalue] = 0;
52 53 memcpy(this->value, value, this->nvalue);
53 54
54   - this->hash = sdbm((unsigned char *)key, nkey);
  55 + this->hash = TR_sdbm((unsigned char *)key, nkey);
55 56
56 57 return 0;
57 58 }
... ...
... ... @@ -24,10 +24,11 @@
24 24 #include <stdlib.h>
25 25 #include <string.h>
26 26
27   -#include "trbase.h"
  27 +#include <trbase.h>
  28 +#include <trhash.h>
  29 +
28 30 #include "hash.h"
29 31 #include "http/header.h"
30   -#include "utils/hash.h"
31 32
32 33 static
33 34 int
... ... @@ -45,7 +46,7 @@ httpHeaderCtor(void * _this, va_list * params) {
45 46 this->name[this->nname] = 0;
46 47 memcpy(this->name, name, this->nname);
47 48
48   - this->hash = sdbm((unsigned char *)name, this->nname);
  49 + this->hash = TR_sdbm((unsigned char *)name, this->nname);
49 50
50 51 (this->value)[0] = TR_malloc((this->nvalue)[0] + 1);
51 52 (this->value)[0][(this->nvalue)[0]] = 0;
... ...
... ... @@ -23,7 +23,8 @@
23 23 #include <unistd.h>
24 24 #include <sys/stat.h>
25 25
26   -#include "trbase.h"
  26 +#include <trbase.h>
  27 +
27 28 #include "http/message.h"
28 29 #include "queue.h"
29 30 #include "http/writer.h"
... ... @@ -48,7 +49,7 @@ httpWriterWrite(void * _this, Stream st)
48 49 this->written = 0;
49 50 this->nheader = httpMessageHeaderSizeGet(this->current);
50 51
51   - if (this->nheader > TR_memGetSize(this->buffer)) {
  52 + if (this->nheader > TR_getSize(this->buffer)) {
52 53 ssize_t size = this->nheader;
53 54
54 55 size = (0 != size%WRITER_BUF_CHUNK)?
... ...
... ... @@ -28,10 +28,11 @@
28 28 #include <sys/types.h>
29 29 #include <uuid/uuid.h>
30 30
31   -#include "trbase.h"
  31 +#include <trbase.h>
  32 +#include <trhash.h>
  33 +
32 34 #include "session.h"
33 35 #include "hash.h"
34   -#include "utils/hash.h"
35 36
36 37
37 38 static
... ... @@ -45,7 +46,7 @@ sessionCtor(void * _this, va_list * params)
45 46 uuid_generate(uuid);
46 47 uuid_unparse(uuid, this->id);
47 48
48   - this->hash = sdbm((unsigned char *)this->id, 36);
  49 + this->hash = TR_sdbm((unsigned char *)this->id, 36);
49 50
50 51 return 0;
51 52 }
... ...
... ... @@ -24,7 +24,8 @@
24 24 #include <string.h>
25 25 #include <sys/stat.h>
26 26
27   -#include "trbase.h"
  27 +#include <trbase.h>
  28 +
28 29 #include "storage/storage.h"
29 30
30 31
... ...
... ... @@ -36,6 +36,9 @@
36 36 #include <sys/mman.h>
37 37 #include <errno.h>
38 38
  39 +#include <trbase.h>
  40 +#include <trhash.h>
  41 +
39 42 #include "server.h"
40 43 #include "logger.h"
41 44 #include "http/worker.h"
... ... @@ -45,7 +48,6 @@
45 48 #include "config/config.h"
46 49 #include "config/value.h"
47 50
48   -#include "trbase.h"
49 51 #include "logger.h"
50 52
51 53 #include "utils/signalHandling.h"
... ... @@ -164,6 +166,7 @@ main()
164 166 ApplicationAdapterHttp adapterHttp;
165 167 HttpWorker worker;
166 168 Server server;
  169 + TR_Uuid user_namespace;
167 170
168 171 ConfigValue ldap_base =
169 172 configGet(config, CSTRA("ldap_base"));
... ... @@ -205,12 +208,14 @@ main()
205 208
206 209 authCreate(auth, AUTH_STORAGE, passwords);
207 210
  211 + user_namespace = TR_uuidParse("14de9e60-d497-4754-be72-f3bed52541fc");
  212 +
208 213 application = TR_new(
209 214 Application,
210 215 value,
211 216 users,
212 217 passwords,
213   - "14de9e60-d497-4754-be72-f3bed52541fc",
  218 + user_namespace,
214 219 auth);
215 220
216 221 router = TR_new(Router, application);
... ... @@ -272,6 +277,7 @@ main()
272 277 TR_delete(adapterHttp);
273 278 TR_delete(router);
274 279 TR_delete(application);
  280 + TR_delete(user_namespace);
275 281 TR_delete(passwords);
276 282 TR_delete(users);
277 283 TR_delete(auth);
... ... @@ -285,7 +291,7 @@ main()
285 291
286 292 TR_delete(config);
287 293 TR_delete(logger);
288   - TR_memCleanup();
  294 + TR_cleanup();
289 295
290 296 return 0;
291 297 }
... ...
... ... @@ -20,16 +20,18 @@
20 20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
21 21 */
22 22
23   -#include "user.h"
24   -#include "uuid.h"
25   -#include "trbase.h"
  23 +#include <trbase.h>
  24 +#include <trhash.h>
26 25
  26 +#include "user.h"
27 27
28 28 static
29 29 int
30 30 userCtor(void * _this, va_list * params)
31 31 {
32 32 User this = _this;
  33 +
  34 + this->namespace = va_arg(* params, TR_Uuid);
33 35 char * username = va_arg(* params, char *);
34 36
35 37 if (NULL != username) {
... ... @@ -140,15 +142,14 @@ userUnserialize(
140 142
141 143 static
142 144 void *
143   -userIndexUuid(void * _this, void * _namespace)
  145 +userIndexUuid(void * _this)
144 146 {
145 147 User this = _this;
146   - Uuid namespace = _namespace;
147 148
148   - return uuidVersion3(
  149 + return TR_uuidVersion3(
149 150 (unsigned char *)this->username,
150 151 *this->nusername,
151   - namespace);
  152 + this->namespace);
152 153 }
153 154
154 155
... ...
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - * \author Unknown (find out)
6   - *
7   - * \copyright
8   - * Copyright © 2012 Georg Hopp
9   - *
10   - * This program is free software: you can redistribute it and/or modify
11   - * it under the terms of the GNU General Public License as published by
12   - * the Free Software Foundation, either version 3 of the License, or
13   - * (at your option) any later version.
14   - *
15   - * This program is distributed in the hope that it will be useful,
16   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
17   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18   - * GNU General Public License for more details.
19   - *
20   - * You should have received a copy of the GNU General Public License
21   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
22   - */
23   -
24   -#include <ctype.h>
25   -#include <sys/types.h>
26   -
27   -#include <openssl/rand.h>
28   -
29   -#include "utils/hash.h"
30   -
31   -/**
32   - * SDBM hashing algorithm:
33   - *
34   - * this algorithm was created for sdbm (a public-domain reimplementation of
35   - * ndbm) database library. it was found to do well in scrambling bits,
36   - * causing better distribution of the keys and fewer splits. it also happens
37   - * to be a good general hashing function with good distribution. the actual
38   - * function is hash(i) = hash(i - 1) * 65599 + str[i]; what is included below
39   - * is the faster version used in gawk. [there is even a faster, duff-device
40   - * version] the magic constant 65599 was picked out of thin air while
41   - * experimenting with different constants, and turns out to be a prime. this
42   - * is one of the algorithms used in berkeley db (see sleepycat) and elsewhere.
43   - */
44   -unsigned long
45   -sdbm(const unsigned char * str, size_t len)
46   -{
47   - unsigned long hash = 0;
48   -
49   - for(; 0 < len; str++, len--)
50   - hash = tolower(*str) + (hash << 6) + (hash << 16) - hash;
51   -
52   - return hash;
53   -}
54   -
55   -// vim: set ts=4 sw=4:
1   -ACLOCAL_AMFLAGS = -I m4
2   -AUTOMAKE_OPTIONS = subdir-objects
3   -
4   -UUID = uuid.c version1.c version3.c version5.c _format3or5.c \
5   - parse.c unparse.c compare.c
6   -
7   -AM_CFLAGS += -I../../include/
8   -
9   -noinst_LTLIBRARIES = libuuid.la
10   -
11   -libuuid_la_SOURCES = $(UUID)
12   -libuuid_la_CFLAGS = $(AM_CFLAGS)
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -// for memcpy
24   -#include <string.h>
25   -
26   -// for ntohl and similar
27   -#include <arpa/inet.h>
28   -
29   -// for already available uuid functionality
30   -#include <uuid/uuid.h>
31   -
32   -#include "uuid.h"
33   -
34   -void
35   -_uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version)
36   -{
37   - /* convert UUID to local byte order */
38   - memcpy((uuid->uuid).value, hash, 16);
39   -
40   - (uuid->uuid).elements.time_low =
41   - ntohl((uuid->uuid).elements.time_low);
42   - (uuid->uuid).elements.time_mid =
43   - ntohs((uuid->uuid).elements.time_mid);
44   - (uuid->uuid).elements.time_hi_version =
45   - ntohs((uuid->uuid).elements.time_hi_version);
46   -
47   - /* put in the variant and version bits */
48   - (uuid->uuid).elements.time_hi_version &= 0x0FFF;
49   - (uuid->uuid).elements.time_hi_version |= (version << 12);
50   - (uuid->uuid).elements.clk_seq_hi_res &= 0x3F;
51   - (uuid->uuid).elements.clk_seq_hi_res |= 0x80;
52   -}
53   -
54   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -// for already available uuid functionality
24   -#include <uuid/uuid.h>
25   -
26   -#include "uuid.h"
27   -
28   -int
29   -uuidCompare(Uuid uuid1, Uuid uuid2)
30   -{
31   - return uuid_compare((uuid1->uuid).value, (uuid2->uuid).value);
32   -}
33   -
34   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -// for already available uuid functionality
24   -#include <uuid/uuid.h>
25   -
26   -#include "trbase.h"
27   -#include "uuid.h"
28   -
29   -Uuid
30   -uuidParse(const UuidString uuid_str)
31   -{
32   - Uuid uuid = TR_new(Uuid);
33   - uuid_parse(uuid_str, (uuid->uuid).value);
34   -
35   - return uuid;
36   -}
37   -
38   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -// for already available uuid functionality
24   -#include <uuid/uuid.h>
25   -
26   -#include "uuid.h"
27   -
28   -void
29   -uuidUnparse(Uuid uuid, UuidString uuid_str)
30   -{
31   - uuid_unparse((uuid->uuid).value, uuid_str);
32   -}
33   -
34   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -#include <stdarg.h>
24   -#include <string.h>
25   -
26   -#include "trbase.h"
27   -#include "uuid.h"
28   -
29   -
30   -static
31   -int
32   -uuidCtor(void * _this, va_list * params)
33   -{
34   - return 0;
35   -}
36   -
37   -static
38   -void
39   -uuidDtor(void * _this)
40   -{
41   -}
42   -
43   -static
44   -void
45   -uuidClone(void * _this, void * _base)
46   -{
47   - Uuid this = _this;
48   - Uuid base = _base;
49   -
50   - memcpy((this->uuid).value, (base->uuid).value, 16);
51   -}
52   -
53   -TR_INIT_IFACE(TR_Class, uuidCtor, uuidDtor, uuidClone);
54   -TR_CREATE_CLASS(Uuid, NULL, TR_IF(TR_Class));
55   -
56   -TR_INSTANCE(Uuid, uuidZero) {
57   - .uuid.value = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
58   -}};
59   -
60   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -// for already available uuid functionality
24   -#include <uuid/uuid.h>
25   -
26   -#include "trbase.h"
27   -#include "uuid.h"
28   -
29   -Uuid
30   -uuidVersion1()
31   -{
32   - Uuid uuid = TR_new(Uuid);
33   - uuid_generate((uuid->uuid).value);
34   -
35   - return uuid;
36   -}
37   -
38   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -// for size_t
24   -#include <sys/types.h>
25   -
26   -// for md5 generation
27   -#include <openssl/md5.h>
28   -
29   -// for htonl and similar
30   -#include <arpa/inet.h>
31   -
32   -// for already available uuid functionality
33   -#include "trbase.h"
34   -#include "uuid.h"
35   -
36   -void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version);
37   -
38   -Uuid
39   -uuidVersion3(const unsigned char * name, size_t nname, Uuid nsid)
40   -{
41   - MD5_CTX ctx;
42   - unsigned char hash[16];
43   - Uuid net_nsid = TR_clone(nsid);
44   - Uuid uuid = TR_new(Uuid);
45   -
46   - /*
47   - * put the namespace id into network byte order.
48   - */
49   - (net_nsid->uuid).elements.time_low =
50   - htonl((net_nsid->uuid).elements.time_low);
51   - (net_nsid->uuid).elements.time_mid =
52   - htons((net_nsid->uuid).elements.time_mid);
53   - (net_nsid->uuid).elements.time_hi_version =
54   - htons((net_nsid->uuid).elements.time_hi_version);
55   -
56   - /*
57   - * generate the MD5
58   - */
59   - MD5_Init(&ctx);
60   - MD5_Update(&ctx, (net_nsid->uuid).value, 16);
61   - MD5_Update(&ctx, name, nname);
62   - MD5_Final(hash, &ctx);
63   -
64   - TR_delete(net_nsid);
65   -
66   - _uuidFormat3or5(uuid, hash, 3);
67   -
68   - return uuid;
69   -}
70   -
71   -// vim: set ts=4 sw=4:
1   -/**
2   - * \file
3   - *
4   - * \author Georg Hopp
5   - *
6   - * \copyright
7   - * Copyright © 2013 Georg Hopp
8   - *
9   - * This program is free software: you can redistribute it and/or modify
10   - * it under the terms of the GNU General Public License as published by
11   - * the Free Software Foundation, either version 3 of the License, or
12   - * (at your option) any later version.
13   - *
14   - * This program is distributed in the hope that it will be useful,
15   - * but WITHOUT ANY WARRANTY; without even the implied warranty of
16   - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17   - * GNU General Public License for more details.
18   - *
19   - * You should have received a copy of the GNU General Public License
20   - * along with this program. If not, see <http://www.gnu.org/licenses/>.
21   - */
22   -
23   -// for size_t
24   -#include <sys/types.h>
25   -
26   -// for sha1 generation
27   -#include <openssl/sha.h>
28   -
29   -// for htonl and similar
30   -#include <arpa/inet.h>
31   -
32   -// for already available uuid functionality
33   -#include "trbase.h"
34   -#include "uuid.h"
35   -
36   -void _uuidFormat3or5(Uuid uuid, unsigned char hash[16], int version);
37   -
38   -Uuid
39   -uuidVersion5(const unsigned char * name, size_t nname, Uuid nsid)
40   -{
41   - SHA_CTX ctx;
42   - unsigned char hash[20];
43   - Uuid net_nsid = TR_clone(nsid);
44   - Uuid uuid = TR_new(Uuid);
45   -
46   - /*
47   - * put the namespace id into network byte order.
48   - */
49   - (net_nsid->uuid).elements.time_low =
50   - htonl((net_nsid->uuid).elements.time_low);
51   - (net_nsid->uuid).elements.time_mid =
52   - htons((net_nsid->uuid).elements.time_mid);
53   - (net_nsid->uuid).elements.time_hi_version =
54   - htons((net_nsid->uuid).elements.time_hi_version);
55   -
56   - /*
57   - * generate the MD5
58   - */
59   - SHA1_Init(&ctx);
60   - SHA1_Update(&ctx, (net_nsid->uuid).value, 16);
61   - SHA1_Update(&ctx, name, nname);
62   - SHA1_Final(hash, &ctx);
63   -
64   - TR_delete(net_nsid);
65   -
66   - _uuidFormat3or5(uuid, hash, 5);
67   -
68   - return uuid;
69   -}
70   -
71   -// vim: set ts=4 sw=4:
Please register or login to post a comment