Hi, I've been playing a bit with msilo.c code and changed some things to make 
it more flexible. The changes are made from SVN rev 3632.


This is my changelog:

- Notification "From" is now the original destination ("registrar" parameter 
deleted). I think this is better since the sender won't see a new IM window 
from a strange user when OpenSer dens back the notification. Instead it will 
see it in the same IM window.

- Added "offline_message" parameter allowing HTML. So the admin could set him 
own notification message in openser.cfg. If not set, the default value is:
  "<em>I'm offline. The message will be delivered when I'm online.</em>"

- Deleted "Contact" header in notification (not necessary in MESSAGE since 
MESSAGE doesn't establish a dialog).

- Deleted CONTACT* and OFFLINE_MESSAGE* #defines and buf1[1024] (not necessary 
now)

- Added HEADERS #define to set "Content-Type" header as "text/html".


I've tested it and seems to work correctly, what do you think about those 
changes? could they be submitted (with updated doc of course)?


Regards.




-- 
Iñaki Baz Castillo
[EMAIL PROTECTED]
--- msilo.c.original	2008-02-06 10:32:28.000000000 +0100
+++ msilo.c	2008-02-06 12:25:33.000000000 +0100
@@ -38,6 +38,11 @@
  * 2004-06-07 updated to the new DB api (andrei)
  * 2006-09-10 m_dump now checks if registering UA supports MESSAGE method (jh)
  * 2006-10-05 added max_messages module variable (jh)
+ * 2008-02-08: notification "From" is now the original destination ("registrar" parameter deleted) (ibc)
+               deleted "Contact" header in notification (not necessary in MESSAGE) (ibc)
+               added "offline_message" parameter allowing HTML (ibc)
+               deleted CONTACT* and OFFLINE_MESSAGE* #defines and buf1[1024] (not necessary now) (ibc)
+               added HEADERS #define to set "Content-Type" header as "text/html" (ibc)
  */
 
 #include <stdio.h>
@@ -66,12 +71,8 @@
 
 #include "../tm/tm_load.h"
 
-#define CONTACT_PREFIX "Content-Type: text/plain"CRLF"Contact: <"
-#define CONTACT_SUFFIX  ">;msilo=yes"CRLF
-#define CONTACT_PREFIX_LEN (sizeof(CONTACT_PREFIX)-1)
-#define CONTACT_SUFFIX_LEN  (sizeof(CONTACT_SUFFIX)-1)
-#define OFFLINE_MESSAGE	"] is offline. The message will be delivered when user goes online."
-#define OFFLINE_MESSAGE_LEN	(sizeof(OFFLINE_MESSAGE)-1)
+#define HEADERS "Content-Type: text/html"CRLF""
+#define HEADERS_LEN (sizeof(HEADERS)-1)
 
 #include "ms_msg_list.h"
 #include "msfuncs.h"
@@ -131,7 +132,7 @@
 
 static str ms_db_url = str_init(DEFAULT_DB_URL);
 static str ms_db_table = str_init("silo");
-str  ms_registrar = {NULL, 0}; /*"sip:[EMAIL PROTECTED]";*/
+str  ms_offline_message = str_init("<em>I'm offline. The message will be delivered when I'm online.</em>");
 str  ms_reminder = {NULL, 0};
 str  ms_outbound_proxy = {NULL, 0};
 
@@ -185,7 +186,7 @@
 static param_export_t params[]={
 	{ "db_url",       STR_PARAM, &ms_db_url.s             },
 	{ "db_table",     STR_PARAM, &ms_db_table.s           },
-	{ "registrar",    STR_PARAM, &ms_registrar.s          },
+	{ "offline_message",    STR_PARAM, &ms_offline_message.s          },
 	{ "reminder",     STR_PARAM, &ms_reminder.s           },
 	{ "outbound_proxy",STR_PARAM, &ms_outbound_proxy.s    },
 	{ "expire_time",  INT_PARAM, &ms_expire_time          },
@@ -341,8 +342,8 @@
 	if(ms_send_time>0 && ms_reminder.s!=NULL)
 		register_timer(m_send_ontimer, 0, ms_send_time);
 
-	if(ms_registrar.s!=NULL)
-		ms_registrar.len = strlen(ms_registrar.s);
+	if(ms_offline_message.s!=NULL)
+		ms_offline_message.len = strlen(ms_offline_message.s);
 	if(ms_reminder.s!=NULL)
 		ms_reminder.len = strlen(ms_reminder.s);
 	if(ms_outbound_proxy.s!=NULL)
@@ -401,7 +402,6 @@
 	int nr_keys = 0, val, lexpire;
 	content_type_t ctype;
 	static char buf[512];
-	static char buf1[1024];
 	int mime;
 	int printbuf_len;
 
@@ -463,13 +463,6 @@
 		}
 	}
 	
-	if(pto->uri.len == ms_registrar.len && 
-			!strncasecmp(pto->uri.s, ms_registrar.s, ms_registrar.len))
-	{
-		LM_DBG("message to MSILO REGISTRAR!\n");
-		goto error;
-	}
-
 	/* get the owner */
 	memset(&puri, 0, sizeof(struct sip_uri));
 	if(owner)
@@ -582,13 +575,6 @@
 	pfrom = (struct to_body*)msg->from->parsed;
 	LM_DBG("'From' header: <%.*s>\n", pfrom->uri.len, pfrom->uri.s);	
 	
-	if(ms_registrar.s && pfrom->uri.len == ms_registrar.len && 
-			!strncasecmp(pfrom->uri.s, ms_registrar.s, ms_registrar.len))
-	{
-		LM_DBG("message from MSILO REGISTRAR!\n");
-		goto error;
-	}
-
 	db_keys[nr_keys] = &sc_from;
 	
 	db_vals[nr_keys].type = DB_STR;
@@ -693,26 +679,12 @@
 	update_stat(ms_stored_msgs, 1);
 #endif
 
-	if(ms_registrar.len <= 0
-			|| ms_registrar.len+CONTACT_PREFIX_LEN+CONTACT_SUFFIX_LEN+1>=1024)
-		goto done;
-
 	LM_DBG("sending info message.\n");
-	strcpy(buf1, CONTACT_PREFIX);
-	strncat(buf1, ms_registrar.s, ms_registrar.len);
-	strncat(buf1, CONTACT_SUFFIX, CONTACT_SUFFIX_LEN);
-	str_hdr.len = CONTACT_PREFIX_LEN+ms_registrar.len+CONTACT_SUFFIX_LEN;
-	str_hdr.s = buf1;
-
-	strncpy(buf, "User [", 6);
-	body.len = 6;
-	if(pto->uri.len+OFFLINE_MESSAGE_LEN+7/*6+1*/ < 512)
-	{
-		strncpy(buf+body.len, pto->uri.s, pto->uri.len);
-		body.len += pto->uri.len;
-	}
-	strncpy(buf+body.len, OFFLINE_MESSAGE, OFFLINE_MESSAGE_LEN);
-	body.len += OFFLINE_MESSAGE_LEN;
+	str_hdr.s = HEADERS;
+	str_hdr.len = HEADERS_LEN;
+
+	strncpy(buf, ms_offline_message.s, ms_offline_message.len);
+	body.len = ms_offline_message.len;
 	body.s = buf;
 	/* look for Contact header -- must be parsed by now*/
 	ctaddr.s = NULL;
@@ -743,7 +715,7 @@
 	tmb.t_request(&msg_type,  /* Type of the message */
 			(ctaddr.s)?&ctaddr:&pfrom->uri,    /* Request-URI */
 			&pfrom->uri,      /* To */
-			&ms_registrar,    /* From */
+			&pto->uri,    /* From is the destination uri*/
 			&str_hdr,         /* Optional headers including CRLF */
 			&body,            /* Message body */
 			(ms_outbound_proxy.s)?&ms_outbound_proxy:0, /* outbound uri */
_______________________________________________
Devel mailing list
Devel@lists.openser.org
http://lists.openser.org/cgi-bin/mailman/listinfo/devel

Reply via email to