Module: kamailio Branch: master Commit: bca9c5587472df76e61a374d99b7a8dcefd63b2e URL: https://github.com/kamailio/kamailio/commit/bca9c5587472df76e61a374d99b7a8dc...
Author: Daniel-Constantin Mierla miconda@gmail.com Committer: Daniel-Constantin Mierla miconda@gmail.com Date: 2023-01-20T12:22:55+01:00
topoh: added inter-module api function for masking call-id
---
Modified: src/modules/topoh/api.h Modified: src/modules/topoh/th_msg.c Modified: src/modules/topoh/th_msg.h Modified: src/modules/topoh/topoh_mod.c
---
Diff: https://github.com/kamailio/kamailio/commit/bca9c5587472df76e61a374d99b7a8dc... Patch: https://github.com/kamailio/kamailio/commit/bca9c5587472df76e61a374d99b7a8dc...
---
diff --git a/src/modules/topoh/api.h b/src/modules/topoh/api.h index 7cdf224c149..f499214c238 100644 --- a/src/modules/topoh/api.h +++ b/src/modules/topoh/api.h @@ -29,10 +29,12 @@
#include "../../core/sr_module.h"
+typedef int (*topoh_mask_callid_f)(str *icallid, str *ocallid); typedef int (*topoh_unmask_callid_f)(str *icallid, str *ocallid);
typedef struct topoh_api { + topoh_mask_callid_f mask_callid; topoh_unmask_callid_f unmask_callid; } topoh_api_t;
diff --git a/src/modules/topoh/th_msg.c b/src/modules/topoh/th_msg.c index 46fecb184a0..4762691845a 100644 --- a/src/modules/topoh/th_msg.c +++ b/src/modules/topoh/th_msg.c @@ -543,6 +543,46 @@ int th_unmask_callid(sip_msg_t *msg) }
#define TH_CALLID_SIZE 256 + +int th_mask_callid_str(str *icallid, str *ocallid) +{ + static char th_callid_mbuf[TH_CALLID_SIZE]; + str out; + + if(th_param_mask_callid==0) + return 0; + + if(th_param_mask_callid==0) + return 0; + + if(icallid->s==NULL) { + LM_ERR("invalid call-id value\n"); + return -1; + } + + out.s = th_mask_encode(icallid->s, icallid->len, &th_callid_prefix, &out.len); + if(out.s==NULL) { + LM_ERR("cannot encode call-id\n"); + return -1; + } + + if(out.len>=TH_CALLID_SIZE) { + pkg_free(out.s); + LM_ERR("not enough callid buf size (needed %d)\n", out.len); + return -2; + } + + memcpy(th_callid_mbuf, out.s, out.len); + th_callid_mbuf[out.len] = '\0'; + + pkg_free(out.s); + + ocallid->s = th_callid_mbuf; + ocallid->len = out.len; + + return 0; +} + int th_unmask_callid_str(str *icallid, str *ocallid) { static char th_callid_buf[TH_CALLID_SIZE]; diff --git a/src/modules/topoh/th_msg.h b/src/modules/topoh/th_msg.h index 0616e70617e..5fa6623fc3a 100644 --- a/src/modules/topoh/th_msg.h +++ b/src/modules/topoh/th_msg.h @@ -31,6 +31,7 @@
int th_mask_via(sip_msg_t *msg); int th_mask_callid(sip_msg_t *msg); +int th_mask_callid_str(str *icallid, str *ocallid); int th_mask_contact(sip_msg_t *msg); int th_mask_record_route(sip_msg_t *msg); int th_unmask_via(sip_msg_t *msg, str *cookie); diff --git a/src/modules/topoh/topoh_mod.c b/src/modules/topoh/topoh_mod.c index 55bb18145b0..8f244d62120 100644 --- a/src/modules/topoh/topoh_mod.c +++ b/src/modules/topoh/topoh_mod.c @@ -632,6 +632,7 @@ int bind_topoh(topoh_api_t* api) }
memset(api, 0, sizeof(topoh_api_t)); + api->mask_callid = th_mask_callid_str; api->unmask_callid = th_unmask_callid_str;
return 0;