Переглянути джерело

siputils: exported several functions to kemi

- has_totag(), is_request(), is_reply(), is_first_hop()
Daniel-Constantin Mierla 9 роки тому
батько
коміт
912c27f68f

+ 28 - 1
modules/siputils/checks.c

@@ -62,6 +62,17 @@ int w_is_request(struct sip_msg* msg, char *foo, char *bar)
 	return -1;
 }
 
+int is_request(struct sip_msg* msg)
+{
+	if(msg==NULL)
+		return -1;
+
+	if(msg->first_line.type == SIP_REQUEST)
+		return 1;
+
+	return -1;
+}
+
 /**
  * return 1 (true) if the SIP message type is reply
  */
@@ -76,11 +87,23 @@ int w_is_reply(struct sip_msg* msg, char *foo, char *bar)
 	return -1;
 }
 
+int is_reply(struct sip_msg* msg)
+{
+	if(msg==NULL)
+		return -1;
+
+	if(msg->first_line.type == SIP_REPLY)
+		return 1;
+
+	return -1;
+}
+
+
 /*
  * Checks if From includes a To-tag -- good to identify
  * if a request creates a new dialog
  */
-int has_totag(struct sip_msg* _m, char* _foo, char* _bar)
+int has_totag(struct sip_msg* _m)
 {
 	str tag;
 
@@ -101,6 +124,10 @@ int has_totag(struct sip_msg* _m, char* _foo, char* _bar)
 	return 1;
 }
 
+int w_has_totag(struct sip_msg* _m, char* _foo, char* _bar)
+{
+	return has_totag(_m);
+}
 
 /*
  * Check if the username matches the username in credentials

+ 4 - 1
modules/siputils/checks.h

@@ -45,7 +45,8 @@ int is_user(struct sip_msg* _msg, char* _user, char* _str2);
 /*
  * Check if message includes a to-tag
  */
-int has_totag(struct sip_msg* _m, char* _foo, char* _bar);
+int has_totag(struct sip_msg* _m);
+int w_has_totag(struct sip_msg* _m, char* _foo, char* _bar);
 
 
 /*
@@ -100,11 +101,13 @@ int set_uri_host(struct sip_msg* _m, char* _uri, char* _value);
  * Return true (1) if SIP message is request, otherwise false (-1)
  */
 int w_is_request(struct sip_msg* msg, char *foo, char *bar);
+int is_request(struct sip_msg* msg);
 
 /*
  * Return true (1) if SIP message is reply, otherwise false (-1)
  */
 int w_is_reply(struct sip_msg* msg, char *foo, char *bar);
+int is_reply(struct sip_msg* msg);
 
 /*
  * Find if Request URI has a given parameter with matching value

+ 6 - 1
modules/siputils/sipops.c

@@ -140,7 +140,7 @@ int w_is_supported(sip_msg_t *msg, char *_option, char *p2)
 }
 
 
-int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2)
+int is_first_hop(sip_msg_t *msg)
 {
 	int ret;
 	rr_t* r = NULL;
@@ -205,3 +205,8 @@ int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2)
 		return -1;
 	}
 }
+
+int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2)
+{
+	return is_first_hop(msg);
+}

+ 2 - 1
modules/siputils/sipops.h

@@ -38,6 +38,7 @@ int w_cmp_uri(struct sip_msg *msg, char *uri1, char *uri2);
 int w_cmp_aor(struct sip_msg *msg, char *uri1, char *uri2);
 int w_is_gruu(sip_msg_t *msg, char *uri1, char *p2);
 int w_is_supported(sip_msg_t *msg, char *_option, char *p2);
-int w_is_first_hop(sip_msg_t *msg, char *uri1, char *p2);
+int w_is_first_hop(sip_msg_t *msg, char *p1, char *p2);
+int is_first_hop(sip_msg_t *msg);
 
 #endif

+ 40 - 2
modules/siputils/siputils.c

@@ -63,6 +63,7 @@
 #include "../../ut.h"
 #include "../../mod_fix.h"
 #include "../../error.h"
+#include "../../kemi.h"
 #include "../../parser/parse_option_tags.h"
 
 #include "ring.h"
@@ -124,7 +125,7 @@ static cmd_export_t cmds[]={
 		0, REQUEST_ROUTE},
 	{"is_user",            (cmd_function)is_user,           1, fixup_str_null,
 		0, REQUEST_ROUTE|LOCAL_ROUTE},
-	{"has_totag", 	       (cmd_function)has_totag,         0, 0,
+	{"has_totag", 	       (cmd_function)w_has_totag,         0, 0,
 		0, ANY_ROUTE},
 	{"uri_param",          (cmd_function)uri_param_1,       1, fixup_str_null,
 		0, REQUEST_ROUTE|LOCAL_ROUTE},
@@ -282,7 +283,7 @@ int bind_siputils(siputils_api_t* api)
 	}
 
 	get_rpid_avp( &api->rpid_avp, &api->rpid_avp_type );
-	api->has_totag = has_totag;
+	api->has_totag = w_has_totag;
 	api->is_uri_user_e164 = is_uri_user_e164;
 
 	return 0;
@@ -451,3 +452,40 @@ static int fixup_option(void** param, int param_no) {
 	*param = (void *)(long)res;
 	return 0;
 }
+
+/**
+ *
+ */
+static sr_kemi_t sr_kemi_siputils_exports[] = {
+	{ str_init("siputils"), str_init("has_totag"),
+		SR_KEMIP_INT, has_totag,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("siputils"), str_init("is_request"),
+		SR_KEMIP_INT, is_request,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("siputils"), str_init("is_reply"),
+		SR_KEMIP_INT, is_reply,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+	{ str_init("siputils"), str_init("is_first_hop"),
+		SR_KEMIP_INT, is_first_hop,
+		{ SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
+			SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
+	},
+
+	{ {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
+};
+
+/**
+ *
+ */
+int mod_register(char *path, int *dlflags, void *p1, void *p2)
+{
+	sr_kemi_modules_add(sr_kemi_siputils_exports);
+	return 0;
+}