Explorar o código

modules/sipt refactor get functions into pvars

return value of 0 in a function causes the script to exit, so
pvars are used instead to safely get the values

also getting screening and presentation information added
Torrey Searle %!s(int64=12) %!d(string=hai) anos
pai
achega
781b0a68cb
Modificáronse 4 ficheiros con 163 adicións e 55 borrados
  1. 66 19
      modules/sipt/doc/sipt_admin.xml
  2. 73 36
      modules/sipt/sipt.c
  3. 2 0
      modules/sipt/ss7.h
  4. 22 0
      modules/sipt/ss7_parser.c

+ 66 - 19
modules/sipt/doc/sipt_admin.xml

@@ -74,18 +74,67 @@ sipt_set_calling($fU, 4, 0, 3);
 </programlisting>
 		</example>
 	</section>
-	<section id="sipt.f.sipt_get_hop_counter">
-		<title><function moreinfo="none">sipt_get_hop_counter()</function></title>
+</section>
+<section>
+        <title>Exported pseudo-variables</title>
+	<section>
+		<title><varname>$sipt_presentation</varname></title>
+		<para>
+			Returns the value of the Address presentation restricted indicator contains in the
+			Calling Party Number header of the IAM message if it exists.
+			Returns -1 if there isn't a Calling Party Number header.
+		</para>
+		<example>
+			<title><function moreinfo="none">sipt_presentation pseudo-variable</function> usage</title>
+			<programlisting format="linespecific">
+...
+# add privacy header if restriction is requested 
+if($sipt_presentation == 1)
+{
+	append_hf("Privacy: id\r\n");
+	$fn = "Anonymous";
+}
+
+...
+</programlisting>
+		</example>
+	</section>
+	<section>
+		<title><varname>$sipt_screening</varname></title>
+		<para>
+			Returns the value of the Screening Indicator contained in the
+			Calling Party Number header of the IAM message if it exists.
+			Returns -1 if there isn't a Calling Party Number header.
+		</para>
+		<example>
+			<title><function moreinfo="none">sipt_screening pseudo-variable</function> usage</title>
+			<programlisting format="linespecific">
+...
+
+# remove P-Asserted-Identity header if the screening isn't verified 
+# or network provided
+$avp(s:screening) = $sipt_screening;
+if($avp(s:screening) != 1 &amp;&amp; $avp(s:screening) != 3)
+{
+	remove_hf("P-Asserted-Id");
+}
+
+...
+</programlisting>
+		</example>
+	</section>
+	<section>
+		<title><varname>$sipt_hop_counter</varname></title>
 		<para>
 			Returns the value of the Hop Counter for the IAM message if it exists.
 			Returns -1 if there isn't a hop counter.
 		</para>
 		<example>
-			<title><function moreinfo="none">sipt_get_hop_counter()</function> usage</title>
+			<title><function moreinfo="none">sipt_hop_counter pseudo-variable</function> usage</title>
 			<programlisting format="linespecific">
 ...
 # get the hop counter and update the Max-Forwards header if it exists
-$avp(s:hop) = sipt_get_hop_counter();
+$avp(s:hop) = $sipt_hop_counter;
 if($avp(s:hop) > 0)
 {
 	remove_hf("Max-Forwards");
@@ -96,26 +145,25 @@ if($avp(s:hop) > 0)
 </programlisting>
 		</example>
 	</section>
-	<section id="sipt.f.sipt_get_cpc">
-		<title><function moreinfo="none">sipt_get_cpc()</function></title>
+	<section>
+		<title><varname>$sipt_cpc</varname></title>
 		<para>
 			Returns the value of the Calling Party Category for the IAM message.
 			Returns -1 if there is a parsing error.
 		</para>
 		<example>
-			<title><function moreinfo="none">sipt_get_cpc()</function> usage</title>
+			<title><function moreinfo="none">sipt_cpc pseudo-variable</function> usage</title>
 			<programlisting format="linespecific">
 ...
 # get the Cpc code and set put it in a custom sip header
-$avp(s:cpc) = sipt_get_cpc();
-append_hf("X-CPC: $avp(s:cpc)\r\n");
+append_hf("X-CPC: $sipt_cpc\r\n");
 
 ...
 </programlisting>
 		</example>
 	</section>
-	<section id="sipt.f.sipt_get_calling_party_nai">
-		<title><function moreinfo="none">sipt_get_calling_party_nai()</function></title>
+	<section>
+		<title><varname>$sipt_calling_party_nai</varname></title>
 		<para>
 			Returns the value of the Nature of Address Indicator
 			of the Calling Party for the IAM message.
@@ -123,12 +171,11 @@ append_hf("X-CPC: $avp(s:cpc)\r\n");
 			the Calling Party Number is not present.
 		</para>
 		<example>
-			<title><function moreinfo="none">sipt_get_calling_party_nai()</function> usage</title>
+			<title><function moreinfo="none">sipt_calling_party_nai pseudo-variable</function> usage</title>
 			<programlisting format="linespecific">
 ...
 # get the Calling Nai and add country code if national
-$avp(s:from_nai) = sipt_get_calling_party_nai();
-if($avp(s:from_nai) == 3)
+if($sipt_calling_party_nai == 3)
 {
 	$fU = "32" + "$fU";
 }
@@ -137,20 +184,19 @@ if($avp(s:from_nai) == 3)
 </programlisting>
 		</example>
 	</section>
-	<section id="sipt.f.sipt_get_called_party_nai">
-		<title><function moreinfo="none">sipt_get_called_party_nai()</function></title>
+	<section>
+		<title><varname>$sipt_called_party_nai</varname></title>
 		<para>
 			Returns the value of the Nature of Address Indicator
 			of the Called Party for the IAM message.
 			Returns -1 if there is a parsing error.
 		</para>
 		<example>
-			<title><function moreinfo="none">sipt_get_called_party_nai()</function> usage</title>
+			<title><function moreinfo="none">sipt_called_party_nai pseudo-variable</function> usage</title>
 			<programlisting format="linespecific">
 ...
 # get the Called Nai and add country code if national
-$avp(s:to_nai) = sipt_get_called_party_nai();
-if($avp(s:to_nai) == 3)
+if($sipt_called_party_nai == 3)
 {
 	$rU = "32" + "$rU";
 }
@@ -159,6 +205,7 @@ if($avp(s:to_nai) == 3)
 </programlisting>
 		</example>
 	</section>
+
 </section>
 </chapter>
 

+ 73 - 36
modules/sipt/sipt.c

@@ -41,10 +41,12 @@ MODULE_VERSION
 
 static int sipt_destination(struct sip_msg *msg, char *_destination, char *_hops, char * _nai);
 static int sipt_set_calling(struct sip_msg *msg, char *_origin, char *_nai, char *_pres, char * _screen);
-static int sipt_get_hop_counter(struct sip_msg *msg, char *x, char *y);
-static int sipt_get_cpc(struct sip_msg *msg, char *x, char *y);
-static int sipt_get_calling_party_nai(struct sip_msg *msg, char *x, char *y);
-static int sipt_get_called_party_nai(struct sip_msg *msg, char *x, char *y);
+static int sipt_get_hop_counter(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+static int sipt_get_cpc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+static int sipt_get_calling_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+static int sipt_get_presentation(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+static int sipt_get_screening(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
+static int sipt_get_called_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res);
 
 static int mod_init(void);
 static void mod_destroy(void);
@@ -83,30 +85,6 @@ static cmd_export_t cmds[]={
 		fixup_str_str_str, fixup_free_str_str_str,         /* */
 		/* can be applied to original requests */
 		REQUEST_ROUTE|BRANCH_ROUTE}, 
-	{"sipt_get_hop_counter", /* action name as in scripts */
-		(cmd_function)sipt_get_hop_counter,  /* C function name */
-		0,          /* number of parameters */
-		0, 0,         /* */
-		/* can be applied to original requests */
-		REQUEST_ROUTE|BRANCH_ROUTE}, 
-	{"sipt_get_cpc", /* action name as in scripts */
-		(cmd_function)sipt_get_cpc,  /* C function name */
-		0,          /* number of parameters */
-		0, 0,         /* */
-		/* can be applied to original requests */
-		REQUEST_ROUTE|BRANCH_ROUTE}, 
-	{"sipt_get_calling_party_nai", /* action name as in scripts */
-		(cmd_function)sipt_get_calling_party_nai,  /* C function name */
-		0,          /* number of parameters */
-		0, 0,         /* */
-		/* can be applied to original requests */
-		REQUEST_ROUTE|BRANCH_ROUTE}, 
-	{"sipt_get_called_party_nai", /* action name as in scripts */
-		(cmd_function)sipt_get_called_party_nai,  /* C function name */
-		0,          /* number of parameters */
-		0, 0,         /* */
-		/* can be applied to original requests */
-		REQUEST_ROUTE|BRANCH_ROUTE}, 
 	{0, 0, 0, 0, 0, 0}
 };
 
@@ -119,6 +97,18 @@ static mi_export_t mi_cmds[] = {
 };
 
 static pv_export_t mod_items[] = {
+        { {"sipt_presentation",  sizeof("sipt_presentation")-1}, PVT_OTHER,  sipt_get_presentation,    0,
+                0, 0, 0, 0 },
+        { {"sipt_screening",  sizeof("sipt_screening")-1}, PVT_OTHER,  sipt_get_screening,    0,
+                0, 0, 0, 0 },
+        { {"sipt_hop_counter",  sizeof("sipt_hop_counter")-1}, PVT_OTHER,  sipt_get_hop_counter,    0,
+                0, 0, 0, 0 },
+        { {"sipt_cpc",  sizeof("sipt_cpc")-1}, PVT_OTHER,  sipt_get_cpc,    0,
+                0, 0, 0, 0 },
+        { {"sipt_calling_party_nai",  sizeof("sipt_calling_party_nai")-1}, PVT_OTHER,  sipt_get_calling_party_nai,    0,
+                0, 0, 0, 0 },
+        { {"sipt_called_party_nai",  sizeof("sipt_called_party_nai")-1}, PVT_OTHER,  sipt_get_called_party_nai,    0,
+                0, 0, 0, 0 },
 	{ {0, 0}, 0, 0, 0, 0, 0, 0, 0 }
 };
 
@@ -286,7 +276,49 @@ static int replace_body(struct sip_msg *msg, str * nb)
 	return 0;
 }
 
-static int sipt_get_hop_counter(struct sip_msg *msg, char *x, char *y)
+static int sipt_get_hop_counter(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
+{
+	str body;
+	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
+
+	if(body.s == NULL)
+	{
+		LM_ERR("No ISUP Message Found");
+		return -1;
+	}
+
+	if(body.s[0] != ISUP_IAM)
+	{
+		LM_DBG("message not an IAM\n");
+		return -1;
+	}
+	
+	pv_get_sintval(msg, param, res, isup_get_hop_counter((unsigned char*)body.s, body.len));
+	return 0;
+}
+
+static int sipt_get_cpc(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
+{
+	str body;
+	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
+
+	if(body.s == NULL)
+	{
+		LM_ERR("No ISUP Message Found");
+		return -1;
+	}
+
+	if(body.s[0] != ISUP_IAM)
+	{
+		LM_DBG("message not an IAM\n");
+		return -1;
+	}
+	
+	pv_get_sintval(msg, param, res, isup_get_cpc((unsigned char*)body.s, body.len));
+	return 0;
+}
+
+static int sipt_get_calling_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
 	str body;
 	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
@@ -303,10 +335,11 @@ static int sipt_get_hop_counter(struct sip_msg *msg, char *x, char *y)
 		return -1;
 	}
 	
-	return isup_get_hop_counter((unsigned char*)body.s, body.len);
+	pv_get_sintval(msg, param, res, isup_get_calling_party_nai((unsigned char*)body.s, body.len));
+	return 0;
 }
 
-static int sipt_get_cpc(struct sip_msg *msg, char *x, char *y)
+static int sipt_get_presentation(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
 	str body;
 	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
@@ -323,10 +356,11 @@ static int sipt_get_cpc(struct sip_msg *msg, char *x, char *y)
 		return -1;
 	}
 	
-	return isup_get_cpc((unsigned char*)body.s, body.len);
+	pv_get_sintval(msg, param, res, isup_get_presentation((unsigned char*)body.s, body.len));
+	return 0;
 }
 
-static int sipt_get_calling_party_nai(struct sip_msg *msg, char *x, char *y)
+static int sipt_get_screening(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
 	str body;
 	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
@@ -342,11 +376,13 @@ static int sipt_get_calling_party_nai(struct sip_msg *msg, char *x, char *y)
 		LM_DBG("message not an IAM\n");
 		return -1;
 	}
+	LM_DBG("about to get screening\n");
 	
-	return isup_get_calling_party_nai((unsigned char*)body.s, body.len);
+	pv_get_sintval(msg, param, res, isup_get_screening((unsigned char*)body.s, body.len));
+	return 0;
 }
 
-static int sipt_get_called_party_nai(struct sip_msg *msg, char *x, char *y)
+static int sipt_get_called_party_nai(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
 {
 	str body;
 	body.s = get_body_part(msg, TYPE_APPLICATION,SUBTYPE_ISUP,&body.len);
@@ -363,7 +399,8 @@ static int sipt_get_called_party_nai(struct sip_msg *msg, char *x, char *y)
 		return -1;
 	}
 	
-	return isup_get_called_party_nai((unsigned char*)body.s, body.len);
+	pv_get_sintval(msg, param, res, isup_get_called_party_nai((unsigned char*)body.s, body.len));
+	return 0;
 }
 
 static int sipt_destination(struct sip_msg *msg, char *_destination, char *_hops, char * _nai)

+ 2 - 0
modules/sipt/ss7.h

@@ -177,6 +177,8 @@ int isup_get_hop_counter(unsigned char *buf, int len);
 int isup_get_cpc(unsigned char *buf, int len);
 int isup_get_calling_party_nai(unsigned char *buf, int len);
 int isup_get_called_party_nai(unsigned char *buf, int len);
+int isup_get_screening(unsigned char *buf, int len);
+int isup_get_presentation(unsigned char *buf, int len);
 int isup_update_destination(char * dest, int hops, int nai, unsigned char *buf, int len, unsigned char * obuf, int olen);
 int isup_update_calling(char * origin, int nai, int presentation, int screening, unsigned char * buf, int len, unsigned char * obuf, int olen);
 

+ 22 - 0
modules/sipt/ss7_parser.c

@@ -227,6 +227,28 @@ int isup_get_calling_party_nai(unsigned char *buf, int len)
 	return -1;
 }
 
+int isup_get_screening(unsigned char *buf, int len)
+{
+	int  offset = get_optional_header(ISUP_PARM_CALLING_PARTY_NUM, buf, len);
+
+	if(offset != -1 && len-offset-3 > 0)
+	{
+		return buf[offset+3] & 0x03;
+	}
+	return -1;
+}
+
+int isup_get_presentation(unsigned char *buf, int len)
+{
+	int  offset = get_optional_header(ISUP_PARM_CALLING_PARTY_NUM, buf, len);
+
+	if(offset != -1 && len-offset-3 > 0)
+	{
+		return (buf[offset+3]>>2) & 0x03;
+	}
+	return -1;
+}
+
 int isup_get_called_party_nai(unsigned char *buf, int len)
 {
 	struct isup_iam_fixed * message = (struct isup_iam_fixed*)buf;