Module: kamailio Branch: master Commit: e721e9262c4b48c3c2f5107f5f5d6195243662db URL: https://github.com/kamailio/kamailio/commit/e721e9262c4b48c3c2f5107f5f5d6195243662db
Author: Daniel-Constantin Mierla <mico...@gmail.com> Committer: Daniel-Constantin Mierla <mico...@gmail.com> Date: 2022-02-16T13:34:05+01:00 core: sruid - functions to get sruid with suffix from hasing a string --- Modified: src/core/utils/sruid.c Modified: src/core/utils/sruid.h --- Diff: https://github.com/kamailio/kamailio/commit/e721e9262c4b48c3c2f5107f5f5d6195243662db.diff Patch: https://github.com/kamailio/kamailio/commit/e721e9262c4b48c3c2f5107f5f5d6195243662db.patch --- diff --git a/src/core/utils/sruid.c b/src/core/utils/sruid.c index d9f089e685..510da8bb81 100644 --- a/src/core/utils/sruid.c +++ b/src/core/utils/sruid.c @@ -36,6 +36,9 @@ #include "../../core/dprint.h" #include "../../core/globals.h" #include "../../core/pt.h" +#include "../../core/ut.h" +#include "../../core/trim.h" +#include "../../core/hashes.h" #include "sruid.h" @@ -211,6 +214,25 @@ int sruid_nextx(sruid_t *sid, str *x) return 0; } +/** + * + */ +int sruid_nexthid(sruid_t *sid, str *sval) +{ + char buf_int[INT2STR_MAX_LEN]; + str hval = str_init("0"); + unsigned int hid = 0; + + if(sval==NULL || sval->s==NULL || sval->len<=0) { + return sruid_nextx(sid, &hval); + } + hval = *sval; + trim(&hval); + hid = get_hash1_raw(hval.s, hval.len); + hval.s = int2strbuf(hid, buf_int, INT2STR_MAX_LEN, &hval.len); + return sruid_nextx(sid, &hval); +} + /** * */ @@ -228,6 +250,15 @@ int sruid_nextx_safe(sruid_t *sid, str *x) return sruid_nextx(sid, x); } +/** + * + */ +int sruid_nexthid_safe(sruid_t *sid, str *sval) +{ + if(unlikely(sid->pid!=my_pid())) sruid_reinit(sid, sid->mode); + return sruid_nexthid(sid, sval); +} + /** * */ diff --git a/src/core/utils/sruid.h b/src/core/utils/sruid.h index 7fdde96a95..8d44635619 100644 --- a/src/core/utils/sruid.h +++ b/src/core/utils/sruid.h @@ -51,4 +51,7 @@ int sruid_next_safe(sruid_t *sid); int sruid_nextx(sruid_t *sid, str *x); 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); + #endif _______________________________________________ Kamailio (SER) - Development Mailing List sr-dev@lists.kamailio.org https://lists.kamailio.org/cgi-bin/mailman/listinfo/sr-dev