Parcourir la source

sipt: KEMI support

- GH #3264
Boris Korzun il y a 6 mois
Parent
commit
522fa2fabe
1 fichiers modifiés avec 112 ajouts et 6 suppressions
  1. 112 6
      src/modules/sipt/sipt.c

+ 112 - 6
src/modules/sipt/sipt.c

@@ -20,21 +20,22 @@
  *
  *
  */
  */
 
 
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
 
 
 #include "../../core/sr_module.h"
 #include "../../core/sr_module.h"
 #include "../../core/parser/parse_param.h"
 #include "../../core/parser/parse_param.h"
 #include "../../core/data_lump.h"
 #include "../../core/data_lump.h"
+#include "../../core/kemi.h"
 #include "../../core/mem/mem.h"
 #include "../../core/mem/mem.h"
 #include "../../core/mod_fix.h"
 #include "../../core/mod_fix.h"
 #include "../../core/parser/parse_content.h"
 #include "../../core/parser/parse_content.h"
 #include "../../core/parser/parse_body.h"
 #include "../../core/parser/parse_body.h"
 #include "../../core/parser/parser_f.h"
 #include "../../core/parser/parser_f.h"
 #include "../../core/trim.h"
 #include "../../core/trim.h"
-#include "ss7.h"
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
 
 
+#include "ss7.h"
 
 
 MODULE_VERSION
 MODULE_VERSION
 
 
@@ -92,7 +93,7 @@ static int sipt_get_generic_number_nai(
 static int sipt_get_generic_number(
 static int sipt_get_generic_number(
 		struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
 		struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
 
 
-static int sipt_has_isup_body(struct sip_msg *msg, char *type, char *str2);
+static int sipt_has_isup_body(struct sip_msg *msg);
 
 
 /* New API */
 /* New API */
 int sipt_parse_pv_name(pv_spec_p sp, str *in);
 int sipt_parse_pv_name(pv_spec_p sp, str *in);
@@ -612,13 +613,21 @@ static int sipt_get_called_party(
 	return 0;
 	return 0;
 }
 }
 
 
-static int sipt_has_isup_body(struct sip_msg *msg, char *foo, char *bar)
+static int sipt_has_isup_body(struct sip_msg *msg)
 {
 {
 	str body;
 	str body;
 	body.s = get_body_part(msg, TYPE_APPLICATION, SUBTYPE_ISUP, &body.len);
 	body.s = get_body_part(msg, TYPE_APPLICATION, SUBTYPE_ISUP, &body.len);
 	return (body.s == NULL) ? -1 : 1;
 	return (body.s == NULL) ? -1 : 1;
 }
 }
 
 
+/**
+ *
+ */
+static int ki_has_isup_body(sip_msg_t *msg)
+{
+	return (sipt_has_isup_body(msg) == 1) ? SR_KEMI_TRUE : SR_KEMI_FALSE;
+}
+
 int sipt_parse_pv_name(pv_spec_p sp, str *in)
 int sipt_parse_pv_name(pv_spec_p sp, str *in)
 {
 {
 	sipt_pv_t *spv = NULL;
 	sipt_pv_t *spv = NULL;
@@ -870,6 +879,19 @@ static int sipt_set_bci_1(struct sip_msg *msg, char *_charge_indicator,
 	return 1;
 	return 1;
 }
 }
 
 
+/**
+ *
+ */
+static int ki_set_bci_1(sip_msg_t *msg, str *_charge_indicator,
+		str *_called_status, str *_called_category, str *_e2e_indicator)
+{
+	return (sipt_set_bci_1(msg, _charge_indicator->s, _called_status->s,
+					_called_category->s, _e2e_indicator->s)
+				   == 1)
+				   ? SR_KEMI_TRUE
+				   : SR_KEMI_FALSE;
+}
+
 static int sipt_destination(
 static int sipt_destination(
 		struct sip_msg *msg, char *_destination, char *_hops, char *_nai)
 		struct sip_msg *msg, char *_destination, char *_hops, char *_nai)
 {
 {
@@ -878,6 +900,17 @@ static int sipt_destination(
 			msg, _destination, _hops, _nai, (char *)&terminator);
 			msg, _destination, _hops, _nai, (char *)&terminator);
 }
 }
 
 
+/**
+ *
+ */
+static int ki_destination(
+		sip_msg_t *msg, str *_destination, str *_hops, str *_nai)
+{
+	return (sipt_destination(msg, _destination->s, _hops->s, _nai->s) == 1)
+				   ? SR_KEMI_TRUE
+				   : SR_KEMI_FALSE;
+}
+
 static int sipt_destination2(struct sip_msg *msg, char *_destination,
 static int sipt_destination2(struct sip_msg *msg, char *_destination,
 		char *_hops, char *_nai, char *_terminator)
 		char *_hops, char *_nai, char *_terminator)
 {
 {
@@ -943,6 +976,16 @@ static int sipt_destination2(struct sip_msg *msg, char *_destination,
 	return 1;
 	return 1;
 }
 }
 
 
+static int ki_destination_terminator(sip_msg_t *msg, str *_destination,
+		str *_hops, str *_nai, str *_terminator)
+{
+	return (sipt_destination2(
+					msg, _destination->s, _hops->s, _nai->s, _terminator->s)
+				   == 1)
+				   ? SR_KEMI_TRUE
+				   : SR_KEMI_FALSE;
+}
+
 static int sipt_set_calling(struct sip_msg *msg, char *_origin, char *_nai,
 static int sipt_set_calling(struct sip_msg *msg, char *_origin, char *_nai,
 		char *_pres, char *_screen)
 		char *_pres, char *_screen)
 {
 {
@@ -1000,6 +1043,18 @@ static int sipt_set_calling(struct sip_msg *msg, char *_origin, char *_nai,
 	return 1;
 	return 1;
 }
 }
 
 
+/**
+ *
+ */
+static int ki_set_calling(
+		sip_msg_t *msg, str *_origin, str *_nai, str *_pres, str *_screen)
+{
+	return (sipt_set_calling(msg, _origin->s, _nai->s, _pres->s, _screen->s)
+				   == 1)
+				   ? SR_KEMI_TRUE
+				   : SR_KEMI_FALSE;
+}
+
 static int sipt_forwarding(struct sip_msg *msg, char *_fwdnumber, char *_nai)
 static int sipt_forwarding(struct sip_msg *msg, char *_fwdnumber, char *_nai)
 {
 {
 	str *nai = (str *)_nai;
 	str *nai = (str *)_nai;
@@ -1053,6 +1108,14 @@ static int sipt_forwarding(struct sip_msg *msg, char *_fwdnumber, char *_nai)
 	return 1;
 	return 1;
 }
 }
 
 
+/**
+ *
+ */
+static int ki_forwarding(sip_msg_t *msg, str *_fwdnumber, str *_nai)
+{
+	return (sipt_forwarding(msg, _fwdnumber->s, _nai->s) == 1) ? SR_KEMI_TRUE
+															   : SR_KEMI_FALSE;
+}
 
 
 static int mod_init(void)
 static int mod_init(void)
 {
 {
@@ -1063,3 +1126,46 @@ static int mod_init(void)
 static void mod_destroy(void)
 static void mod_destroy(void)
 {
 {
 }
 }
+
+/**
+ *
+ */
+/* clang-format off */
+static sr_kemi_t sr_kemi_sipt_exports[] = {
+	{ str_init("sipt"), str_init("destination"),
+		SR_KEMIP_BOOL, ki_destination,
+			{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+				SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }},
+	{ str_init("sipt"), str_init("destination_terminator"),
+		SR_KEMIP_BOOL, ki_destination_terminator,
+			{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+				SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }},
+	{ str_init("sipt"), str_init("forwarding"),
+		SR_KEMIP_BOOL, ki_forwarding,
+			{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
+				SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }},
+	{ str_init("sipt"), str_init("has_isup_body"),
+		SR_KEMIP_BOOL, ki_has_isup_body,
+			{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+				SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }},
+	{ str_init("sipt"), str_init("set_bci_1"),
+		SR_KEMIP_BOOL, ki_set_bci_1,
+			{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+				SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }},
+	{ str_init("sipt"), str_init("set_calling"),
+		SR_KEMIP_BOOL, ki_set_calling,
+			{ SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_STR,
+				SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE }},
+
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+/* clang-format on */
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+	sr_kemi_modules_add(sr_kemi_sipt_exports);
+	return 0;
+}