[sr-dev] git:master: msilo(k): parameter to control contact header

Daniel-Constantin Mierla miconda at gmail.com
Thu Jul 1 21:04:27 CEST 2010


Module: sip-router
Branch: master
Commit: 8ffb09ce908088af89e70a5acd87a318baf5a029
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=8ffb09ce908088af89e70a5acd87a318baf5a029

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Jul  1 20:56:23 2010 +0200

msilo(k): parameter to control contact header

- add_contact parameter controls whether contact header is added to
  msilo generated messages
- default is off (no contact added, as per RFC3428), reported by Juha
  Heinanen

---

 modules_k/msilo/msfuncs.c |   32 ++++++++++++++++++++++++++------
 modules_k/msilo/msfuncs.h |    2 +-
 modules_k/msilo/msilo.c   |    6 ++++--
 3 files changed, 31 insertions(+), 9 deletions(-)

diff --git a/modules_k/msilo/msfuncs.c b/modules_k/msilo/msfuncs.c
index 735b8d6..eed73bd 100644
--- a/modules_k/msilo/msfuncs.c
+++ b/modules_k/msilo/msfuncs.c
@@ -36,7 +36,13 @@
 #include "../../udp_server.h"
 #include "../../pt.h"
 
+#define CONTACT_PREFIX "Contact: <"
+#define CONTACT_SUFFIX  ">;msilo=yes"CRLF
+#define CONTACT_PREFIX_LEN (sizeof(CONTACT_PREFIX)-1)
+#define CONTACT_SUFFIX_LEN  (sizeof(CONTACT_SUFFIX)-1)
+
 extern int ms_add_date;
+extern int ms_add_contact;
 
 /**
  * apostrophes escaping
@@ -181,21 +187,26 @@ error:
 
 /** build MESSAGE headers 
  *
- * Add Content-Type, Date, and extra headers if they exist
+ * Add Content-Type, Contact, Date, and extra headers if they exist
  * expects - max buf len of the resulted body in body->len
  *         - body->s MUST be allocated
  * return: 0 OK ; -1 error
  * */
-int m_build_headers(str *buf, str ctype, time_t date, str extra)
+int m_build_headers(str *buf, str ctype, str contact, time_t date, str extra)
 {
 	char *p;
 	char strDate[48];
 	int lenDate = 0;
+	int newLen = 0;
+
+	if(!buf || !buf->s || buf->len <= 0 || ctype.len < 0)
+		goto error;
 
-	if(!buf || !buf->s || buf->len <= 0 || ctype.len < 0 
-			|| buf->len <= ctype.len+extra.len+14
-	   /*Content-Type: */
-				+CRLF_LEN)
+	newLen = 14 + ctype.len + CRLF_LEN + extra.len;
+	if(contact.len > 0 && ms_add_contact)
+		newLen += CONTACT_PREFIX_LEN + contact.len + CONTACT_SUFFIX_LEN;
+
+	if(buf->len <= newLen)
 		goto error;
 
 	p = buf->s;
@@ -215,6 +226,15 @@ int m_build_headers(str *buf, str ctype, time_t date, str extra)
 		p += CRLF_LEN;
 	
 	}
+	if(contact.len > 0 && ms_add_contact)
+	{
+		strncpy(p, CONTACT_PREFIX, CONTACT_PREFIX_LEN);
+		p += CONTACT_PREFIX_LEN;
+		strncpy(p, contact.s, contact.len);
+		p += contact.len;
+		strncpy(p, CONTACT_SUFFIX, CONTACT_SUFFIX_LEN);
+		p += CONTACT_SUFFIX_LEN;
+	}
 	if (extra.len > 0) {
 	    strncpy(p, extra.s, extra.len);
 	    p += extra.len;
diff --git a/modules_k/msilo/msfuncs.h b/modules_k/msilo/msfuncs.h
index 79a8fdd..8a70fc4 100644
--- a/modules_k/msilo/msfuncs.h
+++ b/modules_k/msilo/msfuncs.h
@@ -49,7 +49,7 @@ int m_apo_escape(char*, int, char*, int);
 int m_extract_content_type(char*, int, content_type_t*, int);
 
 /** build MESSAGE headers */
-int m_build_headers(str *buf, str ctype, time_t date, str extra);
+int m_build_headers(str *buf, str ctype, str contact, time_t date, str extra);
 
 /** build MESSAGE body */
 int m_build_body(str *body, time_t date, str msg, time_t sdate);
diff --git a/modules_k/msilo/msilo.c b/modules_k/msilo/msilo.c
index 1c59073..b7ffd6a 100644
--- a/modules_k/msilo/msilo.c
+++ b/modules_k/msilo/msilo.c
@@ -144,6 +144,7 @@ int  ms_send_time = 0;
 int  ms_clean_period = 10;
 int  ms_use_contact = 1;
 int  ms_add_date = 1;
+int  ms_add_contact = 0;
 int  ms_max_messages = 0;
 
 static str ms_snd_time_avp_param = {NULL, 0};
@@ -210,6 +211,7 @@ static param_export_t params[]={
 	{ "snd_time_avp",     STR_PARAM, &ms_snd_time_avp_param.s },
 	{ "add_date",         INT_PARAM, &ms_add_date             },
 	{ "max_messages",     INT_PARAM, &ms_max_messages         },
+	{ "add_contact",      INT_PARAM, &ms_add_contact          },
 	{ 0,0,0 }
 };
 
@@ -1030,7 +1032,7 @@ static int m_dump(struct sip_msg* msg, char* owner, char* str2)
 		
 		hdr_str.len = 1024;
 		if(m_build_headers(&hdr_str, str_vals[3] /*ctype*/,
-				   rtime /*Date*/,
+				   str_vals[0]/*from*/, rtime /*Date*/,
 				   extra_hdrs_str /*extra_hdrs*/) < 0)
 		{
 			LM_ERR("headers building failed [%d]\n", mid);
@@ -1297,7 +1299,7 @@ void m_send_ontimer(unsigned int ticks, void *param)
 		extra_hdrs_str.len = 0;
 		hdr_str.len = 1024;
 		if(m_build_headers(&hdr_str, str_vals[3] /*ctype*/,
-				   0/*Date*/,
+				   ms_reminder/*from*/,0/*Date*/,
 				   extra_hdrs_str/*extra*/)
 		   < 0)
 		{




More information about the sr-dev mailing list