Module: kamailio
Branch: master
Commit: ac96b585a5ed5a93fef65bcdbdb077fe6a75de22
URL:
https://github.com/kamailio/kamailio/commit/ac96b585a5ed5a93fef65bcdbdb077f…
Author: Daniel-Constantin Mierla <miconda(a)gmail.com>
Committer: Daniel-Constantin Mierla <miconda(a)gmail.com>
Date: 2022-02-18T09:04:27+01:00
uuid: set sruid uuid api hooks on module load
---
Modified: src/modules/uuid/uuid_mod.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ac96b585a5ed5a93fef65bcdbdb077f…
Patch:
https://github.com/kamailio/kamailio/commit/ac96b585a5ed5a93fef65bcdbdb077f…
---
diff --git a/src/modules/uuid/uuid_mod.c b/src/modules/uuid/uuid_mod.c
index 690d322b61..3bbee8bf6d 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/kemi.h"
#include "../../core/utils/sruid.h"
MODULE_VERSION
@@ -235,6 +236,95 @@ static int ksr_uuid_generate_random(char *out, int *len)
return 0;
}
+/**
+ *
+ */
+static sr_kemi_xval_t _ksr_kemi_uuid_xval = {0};
+
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_ksr_uuid_get(sip_msg_t *msg)
+{
+ int len = KSR_UUID_BSIZE;
+
+ memset(&_ksr_kemi_uuid_xval, 0, sizeof(sr_kemi_xval_t));
+
+ if(ksr_uuid_generate(_k_uuid_str, &len)) {
+ sr_kemi_xval_null(&_ksr_kemi_uuid_xval, SR_KEMI_XVAL_NULL_EMPTY);
+ return &_ksr_kemi_uuid_xval;
+ }
+ _ksr_kemi_uuid_xval.vtype = SR_KEMIP_STR;
+ _ksr_kemi_uuid_xval.v.s.s = _k_uuid_str;
+ _ksr_kemi_uuid_xval.v.s.len = len;
+ return &_ksr_kemi_uuid_xval;
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_ksr_uuid_rget(sip_msg_t *msg)
+{
+ int len = KSR_UUID_BSIZE;
+
+ memset(&_ksr_kemi_uuid_xval, 0, sizeof(sr_kemi_xval_t));
+
+ if(ksr_uuid_generate_random(_k_uuid_str, &len)) {
+ sr_kemi_xval_null(&_ksr_kemi_uuid_xval, SR_KEMI_XVAL_NULL_EMPTY);
+ return &_ksr_kemi_uuid_xval;
+ }
+ _ksr_kemi_uuid_xval.vtype = SR_KEMIP_STR;
+ _ksr_kemi_uuid_xval.v.s.s = _k_uuid_str;
+ _ksr_kemi_uuid_xval.v.s.len = len;
+ return &_ksr_kemi_uuid_xval;
+}
+
+/**
+ *
+ */
+static sr_kemi_xval_t* ki_ksr_uuid_tget(sip_msg_t *msg)
+{
+ int len = KSR_UUID_BSIZE;
+
+ memset(&_ksr_kemi_uuid_xval, 0, sizeof(sr_kemi_xval_t));
+
+ if(ksr_uuid_generate_time(_k_uuid_str, &len)) {
+ sr_kemi_xval_null(&_ksr_kemi_uuid_xval, SR_KEMI_XVAL_NULL_EMPTY);
+ return &_ksr_kemi_uuid_xval;
+ }
+ _ksr_kemi_uuid_xval.vtype = SR_KEMIP_STR;
+ _ksr_kemi_uuid_xval.v.s.s = _k_uuid_str;
+ _ksr_kemi_uuid_xval.v.s.len = len;
+ return &_ksr_kemi_uuid_xval;
+}
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_uuid_exports[] = {
+ { str_init("uuid"), str_init("get"),
+ SR_KEMIP_XVAL, ki_ksr_uuid_get,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("uuid"), str_init("rget"),
+ SR_KEMIP_XVAL, ki_ksr_uuid_rget,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+ { str_init("uuid"), str_init("tget"),
+ SR_KEMIP_XVAL, ki_ksr_uuid_tget,
+ { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+ },
+
+ { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+/* clang-format on */
+
+
/**
*
*/
@@ -248,5 +338,6 @@ int mod_register(char *path, int *dlflags, void *p1, void *p2)
if(sruid_uuid_api_set(&sapi) < 0) {
return -1;
}
+ sr_kemi_modules_add(sr_kemi_uuid_exports);
return 0;
}