From 309e5fc8859f624b866e285fba004613ef3b92b1 Mon Sep 17 00:00:00 2001 From: Daniel-Constantin Mierla Date: Wed, 3 Feb 2016 22:35:29 +0100 Subject: [PATCH] topoh: exported inter-module api - contains function to unmask callid --- modules/topoh/api.h | 62 +++++++++++++++++++++++++++++++++++++++ modules/topoh/th_msg.c | 41 ++++++++++++++++++++++++++ modules/topoh/th_msg.h | 1 + modules/topoh/topoh_mod.c | 23 ++++++++++++++- 4 files changed, 126 insertions(+), 1 deletion(-) create mode 100644 modules/topoh/api.h diff --git a/modules/topoh/api.h b/modules/topoh/api.h new file mode 100644 index 00000000000..5b36bca764a --- /dev/null +++ b/modules/topoh/api.h @@ -0,0 +1,62 @@ +/** + * + * Copyright (C) 2016 kamailio.org + * + * This file is part of Kamailio, a free SIP server. + * + * Permission to use, copy, modify, and distribute this software for any + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. + * + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. + */ + +/*! + * \file + * \brief Kamailio topoh :: + * \ingroup topoh + * Module: \ref topoh + */ + +#ifndef _TH_API_H_ +#define _TH_API_H_ + +#include "../../sr_module.h" + +typedef int (*topoh_unmask_callid_f)(str *icallid, str *ocallid); + + +typedef struct topoh_api { + topoh_unmask_callid_f unmask_callid; +} topoh_api_t; + +typedef int (*bind_topoh_f)(topoh_api_t* api); +int bind_topoh(topoh_api_t* api); + +/** + * @brief Load the topoh API + */ +static inline int topoh_load_api(topoh_api_t *api) +{ + bind_topoh_f bindtopoh; + + bindtopoh = (bind_topoh_f)find_export("bind_topoh", 0, 0); + if(bindtopoh == 0) { + LM_ERR("cannot find bind_topoh\n"); + return -1; + } + if(bindtopoh(api)<0) + { + LM_ERR("cannot bind topoh api\n"); + return -1; + } + return 0; +} + +#endif diff --git a/modules/topoh/th_msg.c b/modules/topoh/th_msg.c index 4fd60706cdb..40a956e81be 100644 --- a/modules/topoh/th_msg.c +++ b/modules/topoh/th_msg.c @@ -500,6 +500,47 @@ int th_unmask_callid(sip_msg_t *msg) return 0; } +#define TH_CALLID_SIZE 256 +int th_unmask_callid_str(str *icallid, str *ocallid) +{ + static char th_callid_buf[TH_CALLID_SIZE]; + str out; + + if(th_param_mask_callid==0) + return 0; + + if(icallid->s==NULL) { + LM_ERR("invalid Call-Id value\n"); + return -1; + } + + if(th_callid_prefix.len>0) { + if(th_callid_prefix.len >= icallid->len) { + return 1; + } + if(strncmp(icallid->s, th_callid_prefix.s, th_callid_prefix.len)!=0) { + return 1; + } + } + out.s = th_mask_decode(icallid->s, icallid->len, + &th_callid_prefix, 0, &out.len); + 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_buf, out.s, out.len); + th_callid_buf[out.len] = '\0'; + + pkg_free(out.s); + + ocallid->s = th_callid_buf; + ocallid->len = out.len; + + return 0; +} + int th_flip_record_route(sip_msg_t *msg, int mode) { hdr_field_t *hdr; diff --git a/modules/topoh/th_msg.h b/modules/topoh/th_msg.h index 314e026072f..bb95023d74d 100644 --- a/modules/topoh/th_msg.h +++ b/modules/topoh/th_msg.h @@ -35,6 +35,7 @@ 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); int th_unmask_callid(sip_msg_t *msg); +int th_unmask_callid_str(str *icallid, str *ocallid); int th_flip_record_route(sip_msg_t *msg, int mode); int th_unmask_ruri(sip_msg_t *msg); int th_unmask_route(sip_msg_t *msg); diff --git a/modules/topoh/topoh_mod.c b/modules/topoh/topoh_mod.c index fcdcc8c3a5c..266cc465a8e 100644 --- a/modules/topoh/topoh_mod.c +++ b/modules/topoh/topoh_mod.c @@ -52,6 +52,7 @@ #include "th_mask.h" #include "th_msg.h" +#include "api.h" MODULE_VERSION @@ -95,12 +96,17 @@ static param_export_t params[]={ {0,0,0} }; +static cmd_export_t cmds[]={ + {"bind_topoh", (cmd_function)bind_topoh, 0, + 0, 0, 0}, + {0, 0, 0, 0, 0, 0} +}; /** module exports */ struct module_exports exports= { "topoh", DEFAULT_DLFLAGS, /* dlopen flags */ - 0, + cmds, params, 0, /* exported statistics */ 0, /* exported MI functions */ @@ -476,3 +482,18 @@ int th_msg_sent(void *data) return 0; } +/** + * + */ +int bind_topoh(topoh_api_t* api) +{ + if (!api) { + ERR("Invalid parameter value\n"); + return -1; + } + + memset(api, 0, sizeof(topoh_api_t)); + api->unmask_callid = th_unmask_callid_str; + + return 0; +}