combined patch SMPP things

Benjamin Lee <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Combined diff attached. Including:

1.  SMPP handling (simple debug printing) of GENERIC NACK packets.

2.  SMPP message priority, set via conf file (0..5 -- see SMPP 3.4 spec)

3.  SMPP throughput, set via conf file (n per second/minute)

4.  SMPP unbind when bearerbox is actioned with 'shutdown?password='

5.  Makefile.in changes to allow nicer builds by non-root and temporary
    install dir DESTDIR, e.g. for RPMS /var/tmp/...

Cheers,
Ben.

-- 
Benjamin Lee

71-75 City Rd, South Melbourne, VIC 3006 Australia  http://www.dotwap.com/
Phone +61 3 9698 1840  Mobile +61 414 717 573  Fax +61 3 9698 1841
gateway-20020506.diff (text/plain, 7.1 KB)
Index: Makefile.in
===================================================================
RCS file: /home/cvs/gateway/Makefile.in,v
retrieving revision 1.58
diff -b -u -r1.58 Makefile.in
--- Makefile.in	2 May 2002 22:35:07 -0000	1.58
+++ Makefile.in	5 May 2002 22:11:14 -0000
@@ -229,12 +229,12 @@
 dummy:
 
 install: all
-	$(INSTALL) -d $(bindir)
+	$(INSTALL) -d $(DESTDIR)$(bindir)
 	for prog in $(binprogs); do \
 		$(INSTALL) $$prog \
 		    $(DESTDIR)$(bindir)/`basename $$prog`$(suffix); \
 	done
-	$(INSTALL) -d $(sbindir)
+	$(INSTALL) -d $(DESTDIR)$(sbindir)
 	for prog in $(sbinprogs); do \
 		$(INSTALL) $$prog \
 		    $(DESTDIR)$(sbindir)/`basename $$prog`$(suffix); \
Index: gw/smpp_pdu.def
===================================================================
RCS file: /home/cvs/gateway/gw/smpp_pdu.def,v
retrieving revision 1.4
diff -b -u -r1.4 smpp_pdu.def
--- gw/smpp_pdu.def	24 Apr 2002 08:09:34 -0000	1.4
+++ gw/smpp_pdu.def	5 May 2002 22:11:15 -0000
@@ -179,6 +179,10 @@
     HEADER
 )
 
+PDU(generic_nack_resp,
+    0x80000000,
+    HEADER
+)
 
 #undef PDU
 #undef INTEGER
Index: gw/smsc_smpp.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_smpp.c,v
retrieving revision 1.57
diff -b -u -r1.57 smsc_smpp.c
--- gw/smsc_smpp.c	1 May 2002 18:23:39 -0000	1.57
+++ gw/smsc_smpp.c	5 May 2002 22:11:15 -0000
@@ -76,6 +76,8 @@
     int source_addr_npi;
     int dest_addr_ton;
     int dest_addr_npi;
+    int throughput;     /* limit sending rate */
+    int priority;       /* set default priority for messages */
     int transmit_port;
     int receive_port;
     int quitting;
@@ -89,7 +91,8 @@
     	    	    	 Octstr *address_range, Octstr *our_host, 
                          int source_addr_ton, int source_addr_npi, 
                          int dest_addr_ton, int dest_addr_npi,
-			 Octstr *my_number)
+						 Octstr *my_number,
+						int throughput, int priority)
 {
     SMPP *smpp;
     
@@ -111,6 +114,8 @@
     smpp->dest_addr_ton = dest_addr_ton;
     smpp->dest_addr_npi = dest_addr_npi;
     smpp->our_host = octstr_duplicate(our_host);
+    smpp->throughput = throughput;
+    smpp->priority = priority;
     smpp->my_number = octstr_duplicate(my_number);
     smpp->transmit_port = transmit_port;
     smpp->receive_port = receive_port;
@@ -294,6 +299,17 @@
     if (msg->sms.dlr_mask & (DLR_SUCCESS|DLR_FAIL))
         pdu->u.submit_sm.registered_delivery = 1; 
 
+   
+    if ( smpp->priority >= 0 && smpp->priority <= 5 ) {
+	    
+	    pdu->u.submit_sm.priority_flag = smpp->priority;
+		
+    } else {
+		/* default priority is 0 */
+		pdu->u.submit_sm.priority_flag = 0;
+		
+	}	
+    
     return pdu;
 }
 
@@ -317,6 +333,21 @@
 }
 
 
+static void send_unbind(SMPP *smpp, Connection *conn)
+{
+    SMPP_PDU *pdu;
+    Octstr *os;
+
+    pdu = smpp_pdu_create(unbind, 
+			  counter_increase(smpp->message_id_counter));
+    dump_pdu("Sending unbind:", pdu);
+    os = smpp_pdu_pack(pdu);
+    conn_write(conn, os); /* Write errors checked by caller. */
+    octstr_destroy(os);
+    smpp_pdu_destroy(pdu);
+}
+
+
 static int send_pdu(Connection *conn, SMPP_PDU *pdu)
 {
     Octstr *os;
@@ -336,10 +367,31 @@
     SMPP_PDU *pdu;
     Octstr *os;
 
+    unsigned long delay = 0; /* sleep delay for throttling */
+
     if (*pending_submits == -1)
     	return;
 
+#ifdef PER_MINUTE
+	/* define this if the kannel conf file specifies throughput rate in messages per minute */
+	#define NUMERATOR 6000000
+#else
+	/* normally specify throughput in messages per second */
+	#define NUMERATOR 1000000
+#endif
+	
+    if (smpp->throughput) {
+		delay = NUMERATOR / smpp->throughput;
+    	debug("bb.sms.smpp", 0, "SMPP: delay: %d", delay);
+	}
+
     while (*pending_submits < SMPP_MAX_PENDING_SUBMITS) {
+		
+		/* sleep between processing of each message. should this use gwthread_sleep? */
+    	if (smpp->throughput) {
+			usleep(delay);
+		}
+    
     	/* Get next message, quit if none to be sent */
     	msg = list_extract_first(smpp->msgs_to_send);
 	if (msg == NULL)
@@ -710,6 +762,18 @@
 	}
 	break;
 
+    case generic_nack_resp:
+        {
+			error(0, "SMPP: NACK PDU type 0x%08lx, "
+				"code 0x%08lx.",
+				pdu->type, pdu->u.generic_nack_resp.command_status);
+
+        }
+    break;
+    
+    case unbind_resp:
+	break;
+    
     default:
 	error(0, "SMPP: Unknown PDU type 0x%08lx, ignored.", 
 		 pdu->type);
@@ -786,6 +850,27 @@
     	for (;;) {
 	    timeout = last_enquire_sent + SMPP_ENQUIRE_LINK_INTERVAL 
 	    	    	    - date_universal_now();
+        
+        /* unbind... */
+            if (smpp->quitting) {
+                /* if we are quitting */
+                
+                send_unbind(smpp, conn);
+                
+                /* handle unbind_resp */
+	            while ((ret = read_pdu(conn, &len, &pdu)) == 1) {
+    	    	        /* Deal with the PDU we just got */
+		            dump_pdu("Got PDU:", pdu);
+		            handle_pdu(smpp, conn, pdu, &pending_submits);
+	    	        smpp_pdu_destroy(pdu);
+                }
+                
+                debug("bb.sms.smpp", 0, "SMPP: %s: break and shutting down", __PRETTY_FUNCTION__);
+                
+                /* the next if statement will do the real quit */
+            }
+        /* end unbind */
+        
     	    if (smpp->quitting || conn_wait(conn, timeout) == -1)
 	    	break;
 
@@ -898,6 +983,8 @@
     long dest_addr_ton;
     long dest_addr_npi;
     Octstr *our_host;
+    long throughput;
+    long priority;
     Octstr *my_number;
     SMPP *smpp;
     int ok;
@@ -958,10 +1045,26 @@
     if (cfg_get_integer(&dest_addr_npi, grp, octstr_imm("dest-addr-npi")) == -1)
        dest_addr_npi = -1;
 
+	/* throughput limits the rate at which messages are sent to the SMPP SMSC  */
+	/* if not specified, set to 0, which means no limit */
+    if ( cfg_get_integer(&throughput, grp, octstr_imm("throughput")) == -1 ) {
+        throughput = 0;
+    }
+
+    debug("bb.sms.smpp", 0, "SMPP: throughtput: %d", throughput);
+    
+    if ( cfg_get_integer(&priority, grp, octstr_imm("priority")) == -1 ) {
+        priority = 0;
+    }
+
+    debug("bb.sms.smpp", 0, "SMPP: priority: %d", priority);
+
+
     smpp = smpp_create(conn, host, port, receive_port, system_type, 
     	    	       username, password, address_range, our_host,
                        source_addr_ton, source_addr_npi, dest_addr_ton, 
-                       dest_addr_npi, my_number);
+                       dest_addr_npi, my_number,
+						throughput, priority);
 
     conn->data = smpp;
     conn->name = octstr_format("SMPP:%S:%d/%d:%S:%S", 
Index: gw/smsc_wrapper.c
===================================================================
RCS file: /home/cvs/gateway/gw/smsc_wrapper.c,v
retrieving revision 1.26
diff -b -u -r1.26 smsc_wrapper.c
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.57
diff -b -u -r1.57 cfg.def
--- gwlib/cfg.def	26 Apr 2002 10:49:27 -0000	1.57
+++ gwlib/cfg.def	5 May 2002 22:11:15 -0000
@@ -209,6 +209,7 @@
     OCTSTR(dest-addr-ton)
     OCTSTR(dest-addr-npi)
     OCTSTR(transceiver-mode)
+    OCTSTR(priority)
 )
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.