diff options
author | Alfred E. Heggestad <aeh@db.org> | 2014-11-15 21:44:00 +0100 |
---|---|---|
committer | Alfred E. Heggestad <aeh@db.org> | 2014-11-15 21:44:00 +0100 |
commit | 0edf1df8783b8b8d407f972666a7108c2bbee220 (patch) | |
tree | 36228d82337dc09464f483e47ba08fa12e759bc4 /modules/uuid/uuid.c | |
parent | 5510f077f6e79ff7cc5c3581036773f5f98a9c16 (diff) |
uuid: generate UUID internally in module
Diffstat (limited to 'modules/uuid/uuid.c')
-rw-r--r-- | modules/uuid/uuid.c | 30 |
1 files changed, 21 insertions, 9 deletions
diff --git a/modules/uuid/uuid.c b/modules/uuid/uuid.c index 6426a6e..b213128 100644 --- a/modules/uuid/uuid.c +++ b/modules/uuid/uuid.c @@ -5,15 +5,27 @@ */ #include <stdlib.h> #include <string.h> -#include <uuid/uuid.h> +#include <stdio.h> #include <re.h> #include <baresip.h> +enum { UUID_LEN = 36 }; + + +static int generate_random_uuid(FILE *f) +{ + if (re_fprintf(f, "%08x-%04x-%04x-%04x-%08x%04x", + rand_u32(), rand_u16(), rand_u16(), rand_u16(), + rand_u32(), rand_u16()) != UUID_LEN) + return ENOMEM; + + return 0; +} + + static int uuid_init(const char *file) { - char uuid[37]; - uuid_t uu; FILE *f = NULL; int err = 0; @@ -30,13 +42,13 @@ static int uuid_init(const char *file) goto out; } - uuid_generate(uu); - - uuid_unparse(uu, uuid); - - re_fprintf(f, "%s", uuid); + err = generate_random_uuid(f); + if (err) { + warning("uuid: generate random UUID failed (%m)\n", err); + goto out; + } - info("uuid: generated new UUID (%s)\n", uuid); + info("uuid: generated new UUID in %s\n", file); out: if (f) |