summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlfred E. Heggestad <aeh@db.org>2014-11-15 21:44:00 +0100
committerAlfred E. Heggestad <aeh@db.org>2014-11-15 21:44:00 +0100
commit0edf1df8783b8b8d407f972666a7108c2bbee220 (patch)
tree36228d82337dc09464f483e47ba08fa12e759bc4
parent5510f077f6e79ff7cc5c3581036773f5f98a9c16 (diff)
uuid: generate UUID internally in module
-rw-r--r--mk/modules.mk7
-rw-r--r--modules/uuid/module.mk3
-rw-r--r--modules/uuid/uuid.c30
-rw-r--r--src/config.c2
4 files changed, 24 insertions, 18 deletions
diff --git a/mk/modules.mk b/mk/modules.mk
index ae1d12a..aad0690 100644
--- a/mk/modules.mk
+++ b/mk/modules.mk
@@ -38,7 +38,6 @@
# USE_SRTP Secure RTP module using libre
# USE_STDIO stdio input driver
# USE_SYSLOG Syslog module
-# USE_UUID UUID module
# USE_V4L Video4Linux module
# USE_V4L2 Video4Linux2 module
# USE_WINWAVE Windows audio driver
@@ -154,7 +153,6 @@ USE_LIBSRTP := $(shell [ -f $(SYSROOT)/include/srtp/srtp.h ] || \
USE_SYSLOG := $(shell [ -f $(SYSROOT)/include/syslog.h ] || \
[ -f $(SYSROOT_ALT)/include/syslog.h ] || \
[ -f $(SYSROOT)/local/include/syslog.h ] && echo "yes")
-USE_UUID := $(shell [ -f $(SYSROOT)/include/uuid/uuid.h ] && echo "yes")
USE_V4L := $(shell [ -f $(SYSROOT)/include/libv4l1.h ] || \
[ -f $(SYSROOT)/local/include/libv4l1.h ] \
&& echo "yes")
@@ -221,6 +219,8 @@ MODULES += stun turn ice natbd auloop presence
MODULES += menu contact vumeter mwi account natpmp httpd
MODULES += selftest
MODULES += srtp
+MODULES += uuid
+
ifneq ($(HAVE_PTHREAD),)
MODULES += aubridge
endif
@@ -353,9 +353,6 @@ endif
ifneq ($(USE_SYSLOG),)
MODULES += syslog
endif
-ifneq ($(USE_UUID),)
-MODULES += uuid
-endif
ifneq ($(USE_V4L),)
MODULES += v4l
endif
diff --git a/modules/uuid/module.mk b/modules/uuid/module.mk
index 64a3909..d82836b 100644
--- a/modules/uuid/module.mk
+++ b/modules/uuid/module.mk
@@ -6,8 +6,5 @@
MOD := uuid
$(MOD)_SRCS += uuid.c
-ifneq ($(OS),darwin)
-$(MOD)_LFLAGS += -luuid
-endif
include mk/mod.mk
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)
diff --git a/src/config.c b/src/config.c
index f882e39..9cee3c6 100644
--- a/src/config.c
+++ b/src/config.c
@@ -650,7 +650,7 @@ int config_write_template(const char *file, const struct config *cfg)
"------------------------------------------\n");
(void)re_fprintf(f, "# Temporary Modules (loaded then unloaded)\n");
(void)re_fprintf(f, "\n");
- (void)re_fprintf(f, "#module_tmp\t\t" MOD_PRE "uuid" MOD_EXT "\n");
+ (void)re_fprintf(f, "module_tmp\t\t" MOD_PRE "uuid" MOD_EXT "\n");
(void)re_fprintf(f, "module_tmp\t\t" MOD_PRE "account" MOD_EXT "\n");
(void)re_fprintf(f, "\n");