Makefile.in
Reply-To: 

For what it's worth, find attached a repost of a combined patch consisting
of:

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

2.  SMPP message priority, set via configuration option (0..5)

3.  SMPP throughput, set via configuration option.

4.  SMPP unbind when bearerbox is shutdown?password=

5.  Makefile.in changes to allow nicer builds by non-root and temporary
    install dir, e.g. for RPMS /var/tmp/...
    
-   $(INSTALL) -d $(bindir)
+   $(INSTALL) -d $(DESTDIR)$(bindir)


-- 
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
Index: Makefile.in
===================================================================
RCS file: /home/cvs/gateway/Makefile.in,v
retrieving revision 1.56
diff -u -r1.56 Makefile.in
--- Makefile.in 23 Jan 2002 18:33:00 -0000      1.56
+++ Makefile.in 8 Apr 2002 09:43:12 -0000
@@ -228,12 +228,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.3
diff -u -r1.3 smpp_pdu.def
--- gw/smpp_pdu.def     8 Nov 2001 08:41:23 -0000       1.3
+++ gw/smpp_pdu.def     8 Apr 2002 09:43:12 -0000
@@ -162,6 +162,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.53
diff -u -r1.53 smsc_smpp.c
--- gw/smsc_smpp.c      22 Mar 2002 11:57:41 -0000      1.53
+++ gw/smsc_smpp.c      8 Apr 2002 09:43:12 -0000
@@ -75,6 +75,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;
@@ -85,9 +87,10 @@
 static SMPP *smpp_create(SMSCConn *conn, Octstr *host, int transmit_port, 
                         int receive_port, Octstr *system_type, 
                          Octstr *username, Octstr *password,
-                        Octstr *address_range, Octstr *our_host, 
-                         int source_addr_ton, int source_addr_npi, 
-                         int dest_addr_ton, int dest_addr_npi)
+                        Octstr *address_range, Octstr *our_host,
+                                               int source_addr_ton, int 
+source_addr_npi, 
+                                               int dest_addr_ton, int dest_addr_npi,
+                                               int throughput, int priority)
 {
     SMPP *smpp;
     
@@ -109,6 +112,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->transmit_port = transmit_port;
     smpp->receive_port = receive_port;
     smpp->quitting = 0;
@@ -222,7 +227,7 @@
                   
     pdu->u.submit_sm.source_addr = octstr_duplicate(msg->sms.sender);
     pdu->u.submit_sm.destination_addr = octstr_duplicate(msg->sms.receiver);
- 
+
     /* Check for manual override of source ton and npi values */
     if(smpp->source_addr_ton > -1 && smpp->source_addr_npi > -1) {
         pdu->u.submit_sm.source_addr_ton = smpp->source_addr_ton;
@@ -287,6 +292,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;
 }
 
@@ -310,6 +326,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;
@@ -328,11 +359,32 @@
     Msg *msg;
     SMPP_PDU *pdu;
     Octstr *os;
+    
+    unsigned long delay = 0; /* sleep delay for throttling */
+//    double delay = 0; /* sleep delay for throttling */
 
     if (*pending_submits == -1)
        return;
+       
+//     if (smpp->throughput) {
+//             delay = 1.0 / smpp->throughput;
+//             debug("bb.sms.smpp", 0, "SMPP: delay: %f", delay);
+//     }
+
+    if (smpp->throughput) {
+               delay = 1000000 / smpp->throughput;
+       debug("bb.sms.smpp", 0, "SMPP: delay: %d", delay);
+       }
 
     while (*pending_submits < SMPP_MAX_PENDING_SUBMITS) {
+
+       if (smpp->throughput) {
+                       usleep(delay);
+               }
+//             if (smpp->throughput) {
+//                     gwthread_sleep(delay);
+//             }
+    
        /* Get next message, quit if none to be sent */
        msg = list_extract_first(smpp->msgs_to_send);
        if (msg == NULL)
@@ -651,6 +703,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);
@@ -725,6 +789,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;
 
@@ -837,6 +922,8 @@
     long dest_addr_ton;
     long dest_addr_npi;
     Octstr *our_host;
+    long throughput;
+    long priority;
     SMPP *smpp;
     int ok;
     
@@ -889,10 +976,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);
+                       dest_addr_npi,
+                                               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 -u -r1.26 smsc_wrapper.c
--- gw/smsc_wrapper.c   28 Jul 2001 03:18:23 -0000      1.26
+++ gw/smsc_wrapper.c   8 Apr 2002 09:43:12 -0000
@@ -181,7 +181,7 @@
 
     debug("bb.sms", 0, "smscconn_sender (%s): sending message",
          octstr_get_cstr(conn->name));
-        
+
     ret = smscenter_submit_msg(wrap->smsc, msg);
     if (ret == -1) {
        bb_smscconn_send_failed(conn, msg, SMSCCONN_FAILED_REJECTED);
Index: gwlib/cfg.def
===================================================================
RCS file: /home/cvs/gateway/gwlib/cfg.def,v
retrieving revision 1.49
diff -u -r1.49 cfg.def
--- gwlib/cfg.def       24 Mar 2002 15:44:07 -0000      1.49
+++ gwlib/cfg.def       8 Apr 2002 09:43:12 -0000
@@ -196,6 +196,7 @@
     OCTSTR(source-addr-npi)
     OCTSTR(dest-addr-ton)
     OCTSTR(dest-addr-npi)
+    OCTSTR(priority)
 )
 
 

Reply via email to