Module: kamailio
Branch: master
Commit: f54788b5ac1109a2113592871c1494704523d527
URL:
https://github.com/kamailio/kamailio/commit/f54788b5ac1109a2113592871c14947…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-02-17T10:06:29+01:00
core: sruid - api hooks for setting uuid generation callbacks
- allow modules to set funtions for generating uuid strings following
the api from libuuid
---
Modified: src/core/utils/sruid.c
Modified: src/core/utils/sruid.h
---
Diff:
https://github.com/kamailio/kamailio/commit/f54788b5ac1109a2113592871c14947…
Patch:
https://github.com/kamailio/kamailio/commit/f54788b5ac1109a2113592871c14947…
---
diff --git a/src/core/utils/sruid.c b/src/core/utils/sruid.c
index 510da8bb81..e7a49f2a62 100644
--- a/src/core/utils/sruid.c
+++ b/src/core/utils/sruid.c
@@ -49,6 +49,8 @@
static unsigned int sruid_lfsr32 = 0;
static unsigned int sruid_lfsr31 = 0;
+static sruid_uuid_api_t _sruid_uuid_api = {0};
+
static int sruid_shift_lfsr(unsigned int *lfsr, unsigned int mask)
{
int feedback;
@@ -267,3 +269,54 @@ int sruid_next_safe(sruid_t *sid)
if(unlikely(sid->pid!=my_pid())) sruid_reinit(sid, sid->mode);
return sruid_nextx(sid, NULL);
}
+
+/**
+ *
+ */
+int sruid_uuid_api_set(sruid_uuid_api_t *sapi)
+{
+ if(_sruid_uuid_api.fgenerate!=NULL) {
+ LM_ERR("sruid uuid api already set\n");
+ return -1;
+ }
+
+ memcpy(&_sruid_uuid_api, sapi, sizeof(sruid_uuid_api_t));
+ return 0;
+}
+
+/**
+ *
+ */
+int sruid_uuid_generate(char *out, int *len)
+{
+ if(_sruid_uuid_api.fgenerate == NULL) {
+ *len = 0;
+ return -1;
+ }
+ return _sruid_uuid_api.fgenerate(out, len);
+}
+
+/**
+ *
+ */
+int sruid_uuid_generate_time(char *out, int *len)
+{
+ if(_sruid_uuid_api.fgenerate_time == NULL) {
+ *len = 0;
+ return -1;
+ }
+ return _sruid_uuid_api.fgenerate_time(out, len);
+}
+
+/**
+ *
+ */
+int sruid_uuid_generate_random(char *out, int *len)
+{
+ if(_sruid_uuid_api.fgenerate_random == NULL) {
+ *len = 0;
+ return -1;
+ }
+ return _sruid_uuid_api.fgenerate_random(out, len);
+}
+
diff --git a/src/core/utils/sruid.h b/src/core/utils/sruid.h
index 8d44635619..a97675167f 100644
--- a/src/core/utils/sruid.h
+++ b/src/core/utils/sruid.h
@@ -54,4 +54,17 @@ int sruid_nextx_safe(sruid_t *sid, str *x);
int sruid_nexthid(sruid_t *sid, str *sval);
int sruid_nexthid_safe(sruid_t *sid, str *sval);
+typedef int (*sruid_uuid_generate_f)(char *out, int *len);
+
+typedef struct sruid_uuid_api {
+ sruid_uuid_generate_f fgenerate;
+ sruid_uuid_generate_f fgenerate_time;
+ sruid_uuid_generate_f fgenerate_random;
+} sruid_uuid_api_t;
+
+int sruid_uuid_api_set(sruid_uuid_api_t *sapi);
+int sruid_uuid_generate(char *out, int *len);
+int sruid_uuid_generate_time(char *out, int *len);
+int sruid_uuid_generate_random(char *out, int *len);
+
#endif