Index: test/drive_smpp.c
===================================================================
--- test/drive_smpp.c	(revision 4833)
+++ test/drive_smpp.c	(working copy)
@@ -70,7 +70,11 @@
 #include "gw/smsc/smpp_pdu.h"
 #include "gw/msg.h"
 
+#define MAX_SMS_OCTETS 140
+#define CATENATE_UDH_LEN 5
 
+typedef unsigned char uchar;
+
 static int quitting = 0;
 static Octstr *smsc_system_id;
 static Octstr *smsc_source_addr;
@@ -89,6 +93,7 @@
 static time_t first_from_bb = (time_t) -1;
 static time_t last_to_bb = (time_t) -1;
 static long enquire_interval = 1; /* Measured in messages, not time. */
+static Octstr *SMS = NULL;
 
 
 static void quit(void)
@@ -249,11 +254,19 @@
     smpp_pdu_dump(pdu);
 }
 
+void load_deliver_pdu(SMPP_PDU *pdu, Octstr *data, ESME *esme)
+{
+	pdu->u.deliver_sm.source_addr = octstr_create("456");
+	pdu->u.deliver_sm.destination_addr = octstr_create("123");
+	pdu->u.deliver_sm.short_message = data;
+	if (esme->version > 0x33)
+		pdu->u.deliver_sm.receipted_message_id = octstr_create("receipted_message_id\0");
+}
 
 static void send_smpp_thread(void *arg)
 {
     ESME *esme;
-    Octstr *os;
+    Octstr *os, *data;
     SMPP_PDU *pdu;
     unsigned long id;
 
@@ -266,16 +279,59 @@
             gwthread_sleep(1.0);
         if (quitting)
             break;
-        pdu = smpp_pdu_create(deliver_sm, counter_increase(message_id_counter));
-        pdu->u.deliver_sm.source_addr = octstr_create("456");
-        pdu->u.deliver_sm.destination_addr = octstr_create("123");
-        pdu->u.deliver_sm.short_message = octstr_format("%ld", id);
-        if (esme->version > 0x33)
-            pdu->u.deliver_sm.receipted_message_id = octstr_create("receipted_message_id\0");
-        os = smpp_pdu_pack(NULL, pdu);
-        conn_write(esme->conn, os);
-        octstr_destroy(os);
-        smpp_pdu_destroy(pdu);
+			if (SMS)
+			{
+				if (octstr_len(SMS) <= (MAX_SMS_OCTETS * 8)/7)
+				{
+					data = octstr_duplicate(SMS);
+					goto single;
+				}
+				else
+				{
+					uchar	*start = octstr_get_cstr(SMS), *p = start, *end, c;
+					int	len = octstr_len(SMS), part = 0, num_msgs, part_len;
+
+					part_len = (MAX_SMS_OCTETS - CATENATE_UDH_LEN - 1) *8/7;
+					num_msgs = len/part_len;
+					if (len%part_len) num_msgs++;
+					while (start - p < len)
+					{
+						part++;
+						end = start + part_len;
+						if (end < p + len)
+						{
+							c = *end;
+							*end = '\0';
+						}
+						else end = p + len;
+						data = octstr_format("%c%c\3\xAF%c%c", CATENATE_UDH_LEN, 0,
+							num_msgs, part);
+						octstr_append_data(data, start, end - start);
+						if (end < p + len) *end = c;
+						pdu = smpp_pdu_create(deliver_sm, counter_increase
+							(message_id_counter));
+						load_deliver_pdu(pdu, data, esme);
+						pdu->u.deliver_sm.esm_class = pdu->u.deliver_sm.esm_class |
+							ESM_CLASS_DELIVER_UDH_INDICATOR;
+						os = smpp_pdu_pack(NULL, pdu);
+						conn_write(esme->conn, os);
+						octstr_destroy(os);
+						smpp_pdu_destroy(pdu);
+						start = end;
+					}
+				}
+			} // NIKOS!!!
+			else
+			{
+				data = octstr_format("%ld", id);
+single:		pdu = smpp_pdu_create(deliver_sm, counter_increase
+					(message_id_counter));
+				load_deliver_pdu(pdu, data, esme);
+				os = smpp_pdu_pack(NULL, pdu);
+				conn_write(esme->conn, os);
+				octstr_destroy(os);
+				smpp_pdu_destroy(pdu);
+			}
         if (first_to_esme == (time_t) -1)
             time(&first_to_esme);
         debug("test.smpp", 0, "Delivered SMS %ld of %ld to bearerbox via SMPP.",
@@ -459,7 +515,7 @@
 
 static void help(void)
 {
-    info(0, "drive_smpp [-h] [-v level][-l logfile][-p port][-m msgs][-c config]");
+    info(0, "drive_smpp [-h] [-v level][-l logfile][-p port][-P http_port][-M SMS][-m msgs][-c config]");
 }
 
 
@@ -495,7 +551,7 @@
     num_from_bearerbox = counter_create();
     log_file = config_file = NULL;
 
-    while ((opt = getopt(argc, argv, "hv:p:P:m:l:c:")) != EOF) {
+    while ((opt = getopt(argc, argv, "hv:p:P:M:m:l:c:")) != EOF) {
 	switch (opt) {
 	case 'v':
 	    log_set_output_level(atoi(optarg));
@@ -509,6 +565,10 @@
 	    max_to_esme = atoi(optarg);
 	    break;
 
+	case 'M':
+	    SMS = octstr_create(optarg);
+	    break;
+
 	case 'p':
 	    port = atoi(optarg);
 	    break;
