Hi!

Here in Denmark, the law dictates that the mobile operators must allow
the mobile subscribers to move between operators, but take their MSISDN
with them. In other words, we can't use prefixes to determine whether or
not the user is local, and if not, to which other MMSC to send the
message. For this reason, I've devised a patch that implements a
technique similar to the billing plugin system.

I've added a directive to the configuration file for defining an
external resolver module. This module is responsible for resolving an
MSISDN to a hostname to which the MMS should be sent. If this hostname
matches our own hostname, the user is considered local.

I've implemented the default built-in plugin so that it should work out
of the box for current configurations. Because of this, I had to add
both an MmsBoxSettings and the List *ProxyRelays to the list of
arguments to the resolve function. I have yet to decide if this is a
good or bad thing. :-)


-- 
SÃren Hansen <[EMAIL PROTECTED]>
Index: configure.ac
===================================================================
RCS file: /home/sh/src/cvs/mbuni/configure.ac,v
retrieving revision 1.1.1.1
diff -u -w -r1.1.1.1 configure.ac
--- configure.ac	2 Mar 2005 08:29:42 -0000	1.1.1.1
+++ configure.ac	2 Mar 2005 21:41:09 -0000
@@ -9,7 +9,7 @@
 
 # Checks for programs.
 AC_PROG_CC
-AC_PROG_RANLIB
+AC_PROG_LIBTOOL
 
 # Checks for libraries.
 # FIXME: Replace `main' with a function in `-lcrypto':
@@ -52,7 +52,6 @@
 
 # Change a few things (a la kannel config)
 EXE_EXT=""
-LIBTOOL="ar rc"
 case "$host" in
   *-sun-solaris*) 
     CFLAGS="$CFLAGS -DSunOS=1"
Index: mbuni-kannel-patch-full
===================================================================
RCS file: /home/sh/src/cvs/mbuni/mbuni-kannel-patch-full,v
retrieving revision 1.1
diff -u -w -r1.1 mbuni-kannel-patch-full
--- mbuni-kannel-patch-full	2 Mar 2005 08:54:14 -0000	1.1
+++ mbuni-kannel-patch-full	2 Mar 2005 13:43:04 -0000
@@ -718,7 +718,7 @@
 diff -Naur gateway-1.4.0/gwlib/cfg.def gateway-1.4.0-mbuni/gwlib/cfg.def
 --- gateway-1.4.0/gwlib/cfg.def	Mon Jun 28 18:18:35 2004
 +++ gateway-1.4.0-mbuni/gwlib/cfg.def	Tue Feb  8 11:27:18 2005
-@@ -544,6 +544,53 @@
+@@ -544,6 +544,55 @@
      OCTSTR(unified-prefix)
  )
  
@@ -747,6 +747,8 @@
 +	OCTSTR(deny-ip)
 +	OCTSTR(email2mms-relay-prefixes)
 +	OCTSTR(ua-profile-cache-directory)
++	OCTSTR(resolver-module-parameters)
++	OCTSTR(resolver-library)
 +	OCTSTR(billing-module-parameters)
 +	OCTSTR(billing-library)
 +	OCTSTR(prov-server-notify-script)
Index: mmlib/Makefile.am
===================================================================
RCS file: /home/sh/src/cvs/mbuni/mmlib/Makefile.am,v
retrieving revision 1.1.1.1
diff -u -w -r1.1.1.1 Makefile.am
--- mmlib/Makefile.am	2 Mar 2005 08:29:42 -0000	1.1.1.1
+++ mmlib/Makefile.am	2 Mar 2005 11:54:16 -0000
@@ -1,3 +1,2 @@
 noinst_LIBRARIES = libmms.a
-libmms_a_SOURCES = mms_billing.c mms_billing.h mms_msg.c mms_msg.h mms_queue.c mms_queue.h mms_strings.c mms_strings.h mms_uaprof.c mms_uaprof.h mms_util.c mms_util.h
-
+libmms_a_SOURCES = mms_billing.c mms_billing.h mms_msg.c mms_msg.h mms_queue.c mms_queue.h mms_strings.c mms_strings.h mms_uaprof.c mms_uaprof.h mms_util.c mms_util.h mms_resolve.c mms_resolve.h
Index: mmlib/mms_resolve.c
===================================================================
RCS file: mmlib/mms_resolve.c
diff -N mmlib/mms_resolve.c
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mmlib/mms_resolve.c	2 Mar 2005 21:28:05 -0000
@@ -0,0 +1,44 @@
+#include <stdio.h>
+#include <stdlib.h>
+#include "mms_resolve.h"
+#include "mms_util.h"
+
+static void *mms_resolvermodule_init(char *settings)
+{
+	return NULL;
+}
+
+static int mms_resolvermodule_fini(void *module_data)
+{
+	return 0;
+}
+
+static Octstr *mms_resolve(Octstr * phonenum, void *module_data, void *settings_p, void *proxyrelays_p)
+{
+	/* Most custom implementations of this library will probably just ignore the two last arguments,
+	 * but this one needs them
+	 */
+
+	MmsBoxSettings *settings = (MmsBoxSettings *) settings_p;
+	List *proxyrelays = (List *) proxyrelays_p;
+	int j, m;
+
+	if (does_prefix_match(settings->local_prefix, phonenum)) {
+		return (settings->hostname);
+	} else if (proxyrelays && list_len(proxyrelays) > 0)	/* Step through proxies. */
+		for (j = 0, m = list_len(proxyrelays); j < m; j++) {
+			MmsProxyRelay *mp = list_get(proxyrelays, j);
+			if (does_prefix_match(mp->allowed_prefix, phonenum) && !does_prefix_match(mp->denied_prefix, phonenum)) {
+				return (mp->host);
+			}
+		}
+
+	return 0;
+}
+
+/* The function itself. */
+MmsResolverFuncStruct mms_resolvefuncs = {
+	mms_resolvermodule_init,
+	mms_resolve,
+	mms_resolvermodule_fini
+};
Index: mmlib/mms_resolve.h
===================================================================
RCS file: mmlib/mms_resolve.h
diff -N mmlib/mms_resolve.h
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ mmlib/mms_resolve.h	2 Mar 2005 13:17:05 -0000
@@ -0,0 +1,31 @@
+#ifndef __MMS_RESOLVE_INCLUDED__
+#define __MMS_RESOLVE_INCLUDED__
+
+#include <time.h>
+#include "gwlib/gwlib.h"
+
+/* Resolver module. This file provides prototypes for all resolver functions.
+ * The idea is that for each site a DSO will be created that the mmsglobalsender loads and gets
+ * functions to resolve msisdn's to mmsc addresses. If the string returned is the same as our
+ * hostname, the msisdn is considered local.
+ */
+
+typedef struct MmsRevolverFuncStruct {
+/* This function is called once to initialise the resolver module. Return a generic object,
+ * which is passed with each resolution request..
+ */
+      void *(*mms_resolvermodule_init)(char *settings);
+     
+/* Looks up the msisdn and returns the hostname of the msisdn's mmsc. If returned mmsc matches
+ * our hostname, the user is considered local.
+ *
+ * Return NULL on error, otherwise an Octstr
+ */
+      Octstr *(*mms_resolve)(Octstr * phonenum, void *module_data, void *settings, void *proxyrelays);
+
+      int (*mms_resolvermodule_fini)(void *module_data);
+} MmsResolverFuncStruct;
+
+extern MmsResolverFuncStruct mms_resolvefuncs; /* The module must expose this symbol. */
+
+#endif
Index: mmlib/mms_util.c
===================================================================
RCS file: /home/sh/src/cvs/mbuni/mmlib/mms_util.c,v
retrieving revision 1.1.1.1
diff -u -w -r1.1.1.1 mms_util.c
--- mmlib/mms_util.c	2 Mar 2005 08:29:42 -0000	1.1.1.1
+++ mmlib/mms_util.c	2 Mar 2005 16:15:23 -0000
@@ -20,6 +20,31 @@
      return v ? v : octstr_imm("");
 }
 
+static void *load_module(CfgGroup *grp, char *config_key, char *symbolname)
+{
+	Octstr *s;
+	void *retval = NULL;
+
+	s = cfg_get(grp, octstr_imm(config_key));
+	if (s) {
+		void *x = dlopen(octstr_get_cstr(s), RTLD_LAZY);
+		void *y = NULL;
+
+		if (x == NULL || (y = dlsym(x, symbolname)) == NULL)
+
+			panic(0,
+				  "Error, unable to load dynamic libary (%s) for billing: "
+				  "libhandle is %s, billing funcs is %s, err=%s",
+				  octstr_get_cstr(s),
+				  x ? "OK" : "Not OK", y ? "OK" : "Not OK", dlerror());
+		else
+			retval = y;
+
+		octstr_destroy(s);
+	}
+	return retval;
+}
+
 MmsBoxSettings *mms_load_mmsbox_settings(Cfg *cfg)
 {
      Octstr *s;
@@ -129,36 +154,31 @@
      m->billing_params = cfg_getx(grp, 
 				  octstr_imm("billing-module-parameters"));
      /* Get and load the billing lib if any. */
-     s = cfg_get(grp, 
-		  octstr_imm("billing-library"));
-     if (s) {
-	  void *x = dlopen(octstr_get_cstr(s), RTLD_LAZY);
-	  void *y = NULL;
-	  
-	  if (x == NULL || 
-	      (y = dlsym(x, "mms_billfuncs")) == NULL)
-	       
-	       panic(0, 
-		     "Error, unable to load dynamic libary (%s) for billing: "
-		     "libhandle is %s, billing funcs is %s, err=%s",
-		     octstr_get_cstr(s),
-		     x ? "OK" : "Not OK", 
-		     y ? "OK" : "Not OK", dlerror());
-	  else
-	       m->mms_billfuncs = y;
-
+     if ((m->mms_billfuncs = load_module(grp, "billing-library", "mms_billfuncs"))) {
 	  if (m->mms_billfuncs->mms_billingmodule_init == NULL ||
 	      m->mms_billfuncs->mms_billmsg == NULL ||
 	      m->mms_billfuncs->mms_billingmodule_fini == NULL ||
 	      m->mms_billfuncs->mms_logcdr == NULL) 
 	       panic(0, "Missing or NULL functions in billing module!");
-
-	  octstr_destroy(s);
      } else 
 	  m->mms_billfuncs = &mms_billfuncs; /* The default one. */	  
      
      m->mms_bill_module_data = m->mms_billfuncs->mms_billingmodule_init(octstr_get_cstr(m->billing_params));
      
+	 m->resolver_params = cfg_getx(grp, 
+				  octstr_imm("billing-module-parameters"));
+
+     /* Get and load the resolver lib if any. */
+     if ((m->mms_resolvefuncs = load_module(grp, "billing-library", "mms_billfuncs"))) {
+		if (m->mms_resolvefuncs->mms_resolvermodule_init == NULL ||
+			m->mms_resolvefuncs->mms_resolve == NULL ||
+			m->mms_resolvefuncs->mms_resolvermodule_fini == NULL)
+			panic(0, "Missing or NULL functions in resolver module!");
+	 } else 
+		m->mms_resolvefuncs = &mms_resolvefuncs;	/* The default one. */
+
+     m->mms_resolver_module_data = m->mms_resolvefuncs->mms_resolvermodule_init(octstr_get_cstr(m->resolver_params));
+     
      return m;
 }
 
Index: mmlib/mms_util.h
===================================================================
RCS file: /home/sh/src/cvs/mbuni/mmlib/mms_util.h,v
retrieving revision 1.1.1.1
diff -u -w -r1.1.1.1 mms_util.h
--- mmlib/mms_util.h	2 Mar 2005 08:29:42 -0000	1.1.1.1
+++ mmlib/mms_util.h	2 Mar 2005 12:01:29 -0000
@@ -8,6 +8,7 @@
 #include "mms_strings.h"
 #include "mms_msg.h"
 #include "mms_billing.h"
+#include "mms_resolve.h"
 /* Send errors */
 #define MMS_SEND_OK 0
 #define MMS_SEND_ERROR_TRANSIENT -1
@@ -51,10 +52,15 @@
 #if 0
      Octstr *sendsms_user, *sendsms_pass, *sendsms_globalsender;
 #endif
-     Octstr *billing_params;
 
+     Octstr *billing_params;
      MmsBillingFuncStruct *mms_billfuncs; /* Link to billing funcs. */
      void *mms_bill_module_data;
+
+     Octstr *resolver_params;
+     MmsResolverFuncStruct *mms_resolvefuncs; /* Link to resolver funcs. */
+     void *mms_resolver_module_data;
+
      Octstr *prov_notify;
      Octstr *prov_notify_arg;
      Octstr *prov_getstatus;
Index: mmsc/mmsglobalsender.c
===================================================================
RCS file: /home/sh/src/cvs/mbuni/mmsc/mmsglobalsender.c,v
retrieving revision 1.1.1.1
diff -u -w -r1.1.1.1 mmsglobalsender.c
--- mmsc/mmsglobalsender.c	2 Mar 2005 08:29:42 -0000	1.1.1.1
+++ mmsc/mmsglobalsender.c	2 Mar 2005 21:43:15 -0000
@@ -152,6 +152,7 @@
 	       int j = octstr_case_search(to->rcpt, octstr_imm("/TYPE=PLMN"), 0);
 	       int len = octstr_len(to->rcpt);
 	       Octstr *phonenum = NULL;
+		   Octstr *mmsc;
 	       int sent = 0;
 	       
 	       if (j > 0 && j - 1 +  sizeof "/TYPE=PLMN" == len) /* A proper number. */
@@ -167,25 +168,28 @@
 	       /* Normalise the number, then match against local prefixes. */
 	       normalize_number(octstr_get_cstr(settings->unified_prefix), &phonenum);
 
-	       if (does_prefix_match(settings->local_prefix, phonenum)) {
-		    res = mms_sendtomobile(e->from, 
-					   to->rcpt, e->subject, e->fromproxy, 
-					   e->msgId, e->expiryt, msg, e->dlr, &err);
-		    sent = 1;
-	       } else if (proxyrelays && list_len(proxyrelays) > 0)/* Step through proxies. */
+		   if ((mmsc = settings->mms_resolvefuncs->mms_resolve(phonenum, settings->mms_resolver_module_data, settings, proxyrelays))) {
+				info(0, "mmsc for \"%s\" resolved to: \"%s\"", octstr_get_cstr(phonenum), octstr_get_cstr(mmsc));
 		    
+				if (!octstr_compare(mmsc, settings->hostname)) {
+					res =
+						mms_sendtomobile(e->from, to->rcpt, e->subject, e->fromproxy, e->msgId, e->expiryt, msg, e->dlr,
+										 &err);
+					sent = 1;
+				} else if (proxyrelays && list_len(proxyrelays) > 0)
+					/* Step through proxies. */
 		    for (j = 0, m = list_len(proxyrelays); j<m; j++) {
 			 MmsProxyRelay *mp = list_get(proxyrelays, j);
 			 
-			 if (does_prefix_match(mp->allowed_prefix, phonenum) && 
-			     !does_prefix_match(mp->denied_prefix, phonenum)) {
-			      res =  mms_sendtoproxy(e->from, 
-						     to->rcpt, e->subject, mp->host, 
-						     e->msgId, e->expiryt, msg, e->dlr, &err);
+						if (!octstr_compare(mp->host, mmsc)) {
+							res =
+								mms_sendtoproxy(e->from, to->rcpt, e->subject, mp->host, e->msgId, e->expiryt, msg,
+												e->dlr, &err);
 			      sent = 1;
 			      break;
 			 }
 		    }
+			}
 	       if (!sent) {
 		    res = MMS_SEND_ERROR_FATAL;
 		    err = octstr_format("MMSC error: Don't know how to deliver to %S !", to->rcpt);

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________
Devel mailing list
[email protected]
http://mbuni.org/mailman/listinfo/devel_mbuni.org

Reply via email to