소스 검색

topoh: added inter-module api function for masking call-id

Daniel-Constantin Mierla 2 년 전
부모
커밋
bca9c55874
4개의 변경된 파일44개의 추가작업 그리고 0개의 파일을 삭제
  1. 2 0
      src/modules/topoh/api.h
  2. 40 0
      src/modules/topoh/th_msg.c
  3. 1 0
      src/modules/topoh/th_msg.h
  4. 1 0
      src/modules/topoh/topoh_mod.c

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

+ 40 - 0
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];

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

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