Selaa lähdekoodia

topoh: exported inter-module api

- contains function to unmask callid
Daniel-Constantin Mierla 9 vuotta sitten
vanhempi
commit
309e5fc885
4 muutettua tiedostoa jossa 126 lisäystä ja 1 poistoa
  1. 62 0
      modules/topoh/api.h
  2. 41 0
      modules/topoh/th_msg.c
  3. 1 0
      modules/topoh/th_msg.h
  4. 22 1
      modules/topoh/topoh_mod.c

+ 62 - 0
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

+ 41 - 0
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;

+ 1 - 0
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);

+ 22 - 1
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 @@ done:
 	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;
+}