Module: kamailio
Branch: master
Commit: c3ffbce540d8a2fb58f193dcffebc2ed57cb802f
URL:
https://github.com/kamailio/kamailio/commit/c3ffbce540d8a2fb58f193dcffebc2e…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-02-17T13:00:48+01:00
uuid: set sruid hooks for uuid generation on mod register
---
Modified: src/modules/uuid/uuid_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/c3ffbce540d8a2fb58f193dcffebc2e…
Patch:
https://github.com/kamailio/kamailio/commit/c3ffbce540d8a2fb58f193dcffebc2e…
---
diff --git a/src/modules/uuid/uuid_mod.c b/src/modules/uuid/uuid_mod.c
index 247d5830ab..690d322b61 100644
--- a/src/modules/uuid/uuid_mod.c
+++ b/src/modules/uuid/uuid_mod.c
@@ -31,6 +31,7 @@
#include "../../core/dprint.h"
#include "../../core/ut.h"
#include "../../core/pvar.h"
+#include "../../core/utils/sruid.h"
MODULE_VERSION
@@ -182,3 +183,70 @@ int pv_get_uuid(sip_msg_t *msg, pv_param_t *param,
uuid_unparse_lower(_k_uuid_val, _k_uuid_str);
return pv_get_strzval(msg, param, res, _k_uuid_str);
}
+
+
+/**
+ * generate uuid value
+ */
+static int ksr_uuid_generate(char *out, int *len)
+{
+ if(out==NULL || len==NULL || *len<KSR_UUID_BSIZE) {
+ return -1;
+ }
+ uuid_generate(_k_uuid_val);
+ uuid_unparse_lower(_k_uuid_val, out);
+ *len = strlen(out);
+ return 0;
+}
+
+/**
+ * generate uuid time value
+ */
+static int ksr_uuid_generate_time(char *out, int *len)
+{
+ if(out==NULL || len==NULL || *len<KSR_UUID_BSIZE) {
+ return -1;
+ }
+#ifndef __OS_darwin
+ if(uuid_generate_time_safe(_k_uuid_val)!=0) {
+ LM_ERR("uuid not generated in a safe mode\n");
+ return -1;
+ }
+#else
+ uuid_generate_time(_k_uuid_val);
+#endif
+
+ uuid_unparse_lower(_k_uuid_val, out);
+ *len = strlen(out);
+ return 0;
+}
+
+/**
+ * generate uuid random value
+ */
+static int ksr_uuid_generate_random(char *out, int *len)
+{
+ if(out==NULL || len==NULL || *len<KSR_UUID_BSIZE) {
+ return -1;
+ }
+ uuid_generate_random(_k_uuid_val);
+ uuid_unparse_lower(_k_uuid_val, out);
+ *len = strlen(out);
+ return 0;
+}
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+ sruid_uuid_api_t sapi;
+ memset(&sapi, 0, sizeof(sruid_uuid_api_t));
+ sapi.fgenerate = ksr_uuid_generate;
+ sapi.fgenerate_time = ksr_uuid_generate_time;
+ sapi.fgenerate_random = ksr_uuid_generate_random;
+ if(sruid_uuid_api_set(&sapi) < 0) {
+ return -1;
+ }
+ return 0;
+}