Multi record sending patch

"Rene Kluwen" <[email protected]>
Newsgroups gmane.comp.mobile.kannel.devel
Message-ID <[email protected]>
Hello Alejandro,

 

I found this patch and I consider it useful enough to include in sqlbox
trunk.

Is this the latest version? And is it tested well?

 

Maybe you have a diff against current trunk.

 

== Rene
sqlbox-standalone-multi-20080227.patch (application/octet-stream, 5.4 KB)
diff -rbu sqlbox-standalone/gw/sqlbox.c sqlbox-standalone-ajg-1.0/gw/sqlbox.c
--- sqlbox-standalone/gw/sqlbox.c	2007-10-05 13:54:02.000000000 -0300
+++ sqlbox-standalone-ajg-1.0/gw/sqlbox.c	2008-02-27 19:35:23.000000000 -0200
@@ -86,6 +86,7 @@
 static Octstr *box_allow_ip;
 static Octstr *box_deny_ip;
 static Octstr *global_sender;
+static long limit_per_cycle;
 
 #ifndef HAVE_MYSQL
 #ifndef HAVE_PGSQL
@@ -97,6 +98,7 @@
 Octstr *sqlbox_id;
 
 #define SLEEP_BETWEEN_SELECTS 1.0
+#define DEFAULT_LIMIT_PER_CYCLE 10
 
 typedef struct _boxc {
     Connection	*smsbox_connection;
@@ -525,6 +527,7 @@
 	Boxc *boxc;
 	int fd;
 	Msg *msg;
+	List *qlist;
 
 	boxc = gw_malloc(sizeof(Boxc));
 	boxc->bearerbox_connection = connect_to_bearerbox_real(bearerbox_host, bearerbox_port, bearerbox_port_ssl, NULL /* bb_our_host */);
@@ -542,19 +545,24 @@
 
 	identify_to_bearerbox(boxc);
 
+	qlist = gwlist_create();
+	gwlist_add_producer(qlist);
+
 	while (sqlbox_status == SQL_RUNNING) {
-		if ((msg = gw_sql_fetch_msg()) != NULL) {
+		if ( gw_sql_fetch_msg(qlist, limit_per_cycle) > 0 ) {
+			while((gwlist_len(qlist)>0) && ((msg = gwlist_consume(qlist)) != NULL )) {
 			if (global_sender != NULL && (msg->sms.sender == NULL || octstr_len(msg->sms.sender) == 0)) {
 				msg->sms.sender = octstr_duplicate(global_sender);
 			}
 			send_msg(boxc->bearerbox_connection, boxc, msg);
 			gw_sql_save_msg(msg, octstr_imm("MT"));
 		}
-		else {
+		} else {
 			gwthread_sleep(SLEEP_BETWEEN_SELECTS);
 		}
 	}
 
+	gwlist_remove_producer(qlist);
 	boxc_destroy(boxc);
 }
 
@@ -684,6 +692,11 @@
 
 	if (cfg_get_integer(&sqlbox_port, grp, octstr_imm("smsbox-port")) == -1)
 		sqlbox_port = 13005;
+
+	/* setup limit per cycle */
+	if (cfg_get_integer(&limit_per_cycle, grp, octstr_imm("limit-per-cycle")) == -1)
+		limit_per_cycle = DEFAULT_LIMIT_PER_CYCLE;
+
 	/* setup logfile stuff */
 	logfile = cfg_get(grp, octstr_imm("log-file"));
 
diff -rbu sqlbox-standalone/gw/sqlbox-cfg.def sqlbox-standalone-ajg-1.0/gw/sqlbox-cfg.def
--- sqlbox-standalone/gw/sqlbox-cfg.def	2006-07-07 01:03:32.000000000 -0300
+++ sqlbox-standalone-ajg-1.0/gw/sqlbox-cfg.def	2008-02-26 22:20:26.000000000 -0200
@@ -25,5 +25,6 @@
     OCTSTR(ssl-server-key-file)
     OCTSTR(ssl-trusted-ca-file)
     OCTSTR(bearerbox-port)
+    OCTSTR(limit-per-cycle)
 )
 
diff -rbu sqlbox-standalone/gw/sqlbox_mysql.c sqlbox-standalone-ajg-1.0/gw/sqlbox_mysql.c
--- sqlbox-standalone/gw/sqlbox_mysql.c	2006-11-06 14:47:57.000000000 -0200
+++ sqlbox-standalone-ajg-1.0/gw/sqlbox_mysql.c	2008-02-26 23:20:48.000000000 -0200
@@ -102,21 +102,22 @@
 
 #define octstr_null_create(x) ((x != NULL) ? octstr_create(x) : octstr_create(""))
 #define atol_null(x) ((x != NULL) ? atol(x) : -1)
-Msg *mysql_fetch_msg()
+int mysql_fetch_msg(List *qlist, long limit)
 {
 	Msg *msg = NULL;
 	Octstr *sql, *delet, *id;
 	MYSQL_RES *res;
 	MYSQL_ROW row;
-
-	sql = octstr_format("SELECT sql_id, momt, sender, receiver, udhdata, msgdata, time, smsc_id, service, account, id, sms_type, mclass, mwi, coding, compress, validity, deferred, dlr_mask, dlr_url, pid, alt_dcs, rpi, charset, boxc_id, binfo FROM %S LIMIT 0,1", sqlbox_insert_table);
+	int ret;
+	sql = octstr_format("SELECT sql_id, momt, sender, receiver, udhdata, msgdata, time, smsc_id, service, account, id, sms_type, mclass, mwi, coding, compress, validity, deferred, dlr_mask, dlr_url, pid, alt_dcs, rpi, charset, boxc_id, binfo FROM %S LIMIT 0,%d", sqlbox_insert_table, limit);
 	res = mysql_select(sql);
 	if (res == NULL) {
 		debug("sqlbox", 0, "SQL statement failed: %s", octstr_get_cstr(sql));
 	}
 	else {
-		if (mysql_num_rows(res) >= 1) {
-			row = mysql_fetch_row(res);
+		ret = mysql_num_rows(res);
+		if (ret >= 1) {
+			while (row = mysql_fetch_row(res)) {
 			id			= octstr_null_create(row[0]);
 			/* save fields in this row as msg struct */
 			msg = msg_create(sms);
@@ -149,6 +150,7 @@
 			else {
 				msg->sms.boxc_id= octstr_null_create(row[24]);
 			}
+				gwlist_produce(qlist, msg);
 			/* delete current row */
 			delet = octstr_format("DELETE FROM %S WHERE sql_id = %S", sqlbox_insert_table, id);
         		//debug("sqlbox", 0, "sql_fetch_msg: %s", octstr_get_cstr(delet));
@@ -156,11 +158,11 @@
 			octstr_destroy(id);
 			octstr_destroy(delet);
 		}
+		}
 		mysql_free_result(res);
 	}
-	octstr_destroy(sql);
         //debug("sqlbox", 0, "sql_fetch_msg: %s", octstr_get_cstr(sql));
-	return msg;
+	return ret;
 }
 
 static Octstr *get_numeric_value_or_return_null(long int num)
diff -rbu sqlbox-standalone/gw/sqlbox_mysql.h sqlbox-standalone-ajg-1.0/gw/sqlbox_mysql.h
--- sqlbox-standalone/gw/sqlbox_mysql.h	2006-06-28 19:06:07.000000000 -0300
+++ sqlbox-standalone-ajg-1.0/gw/sqlbox_mysql.h	2008-02-26 22:20:12.000000000 -0200
@@ -3,7 +3,7 @@
 #include "gw/msg.h"
 #include "sqlbox_sql.h"
 void sql_save_msg(Msg *msg, Octstr *momt /*, Octstr smsbox_id */);
-Msg *mysql_fetch_msg();
+int mysql_fetch_msg(List *list, long limit);
 void sql_shutdown();
 struct server_type *sql_init_mysql(Cfg *cfg);
 #ifndef sqlbox_mysql_c
diff -rbu sqlbox-standalone/gw/sqlbox_sql.h sqlbox-standalone-ajg-1.0/gw/sqlbox_sql.h
--- sqlbox-standalone/gw/sqlbox_sql.h	2006-06-28 19:06:07.000000000 -0300
+++ sqlbox-standalone-ajg-1.0/gw/sqlbox_sql.h	2008-02-27 19:34:49.000000000 -0200
@@ -10,7 +10,7 @@
 	Octstr *type;
 	void (*sql_enter) (Cfg *cfg);
 	void (*sql_leave) ();
-	Msg *(*sql_fetch_msg) ();
+	int  (*sql_fetch_msg) (List *, long);
 	void (*sql_save_msg) (Msg *, Octstr *);
 };
 
@@ -27,3 +27,4 @@
 #define gw_sql_leave sql_type->sql_leave
 
 #endif
+
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.