gnokii-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-47


From: Pawel Kot
Subject: [SCM] libgnokii and core programs branch, master, updated. rel_0_6_29-47-g838f1ee
Date: Fri, 20 Aug 2010 16:24:06 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "libgnokii and core programs".

The branch, master has been updated
       via  838f1ee4dee4483939e9f3ba52913e5230910f34 (commit)
      from  1e79ccb15dd9f15e10bfa93011120ef56723c1c1 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/gnokii.git/commit/?id=838f1ee4dee4483939e9f3ba52913e5230910f34


commit 838f1ee4dee4483939e9f3ba52913e5230910f34
Author: Pawel Kot <address@hidden>
Date:   Fri Aug 20 18:22:17 2010 +0200

    Add SQLite3 support for smsd backend.
    From: Santeri Toikka <address@hidden>
    Date: Thu, 19 Aug 2010 16:16:17 +0300

diff --git a/ChangeLog b/ChangeLog
index ca98493..26c9ad2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -32,6 +32,8 @@
  * xgnokii updates
     o support UTF-8 text when editing SMS and when showing details.
       Fixes https://bugs.launchpad.net/bugs/604947  (Daniele Forsi)
+ * smsd updates
+    o add SQLite3 backend module                   (Santeri Toikka)
 
 0.6.29
 ======
diff --git a/configure.in b/configure.in
index c837c14..c527a97 100644
--- a/configure.in
+++ b/configure.in
@@ -35,7 +35,7 @@ dnl xgnokii version
 XVERSION=1.0
 
 dnl smsd version
-SVERSION=1.4.4
+SVERSION=1.4.5
 
 AC_CANONICAL_SYSTEM
 AC_GNU_SOURCE
@@ -699,6 +699,7 @@ AM_CONDITIONAL(SMSD, test "x$enable_smsd" = "xyes")
 
 dnl ======================== Checks for databases support for smsd
 
+dnl === PostgreSQL
 AC_ARG_ENABLE(postgres,
        AC_HELP_STRING([--disable-postgres],
        [disable PostgreSQL support (default is autodetected)]),
@@ -718,6 +719,23 @@ fi
 
 AM_CONDITIONAL(HAVE_POSTGRES, test "x$have_postgres" = "xyes")
 
+dnl === SQLite
+AC_ARG_ENABLE(sqlite,
+       AC_HELP_STRING([--disable-sqlite],
+       [disable SQLite support (default is autodetected)]),
+       [enable_sqlite=$enableval],
+       [enable_sqlite=yes])
+have_sqlite=no
+PKG_CHECK_MODULES(SQLITE3, sqlite3, have_sqlite=yes)
+if test x$enable_sqlite != xno && test x$PKGCONF != xno ; then
+       SQLITE_LIBS=SQLITE3_LIBS
+       dnl SQLITE_CFLAGS=SQLITE3_CFLAGS
+       AC_SUBST(SQLITE_LIBS)
+       AC_SUBST(SQLITE_CFLAGS)
+fi
+AM_CONDITIONAL(HAVE_SQLITE, test "x$have_sqlite" = "xyes")
+
+dnl === MySQL
 AC_ARG_ENABLE(mysql,
        AC_HELP_STRING([--disable-mysql],
        [disable MySQL support (default is autodetected)]),
@@ -1079,6 +1097,7 @@ echo "
     X (GTK+) support:   $x_support
     smsd support:       $enable_smsd
     Postgres support:   $have_postgres
+    SQLite support:     $have_sqlite
     MySQL support:      $have_mysql
     Debug:              $debug
     XDebug:             $xdebug
diff --git a/smsd/ChangeLog b/smsd/ChangeLog
index e7fd1f7..93a1b53 100644
--- a/smsd/ChangeLog
+++ b/smsd/ChangeLog
@@ -1,3 +1,8 @@
+* Fri 20 Aug 2010 Paweł Kot
+- Add SQLite3 backend module by Santeri Toikka.
+- Version changed to 1.4.5
+
+
 * Thu 24 Dec 2009 Daniele Forsi
 - Add quoting around phone number to mysql code that handles multipart
   messages. Patch by Paulius Bulotas.
diff --git a/smsd/Makefile.am b/smsd/Makefile.am
index 3643f62..3aec45c 100644
--- a/smsd/Makefile.am
+++ b/smsd/Makefile.am
@@ -19,6 +19,13 @@ libsmsd_mysql_la_LDFLAGS = $(modules_flags)
 libsmsd_mysql_la_LIBADD = $(MYSQL_LIBS)
 endif
 
+if HAVE_SQLITE
+plugin_LTLIBRARIES += libsmsd_sqlite.la
+libsmsd_sqlite_la_SOURCES = sqlite.c db.h utils.h utils.c
+libsmsd_sqlite_la_LDFLAGS = $(modules_flags)
+libsmsd_sqlite_la_LIBADD = $(SQLITE_LIBS)
+endif
+
 libsmsd_file_la_SOURCES = file.c db.h utils.h utils.c
 libsmsd_file_la_LDFLAGS = $(modules_flags)
 libsmsd_file_la_LIBADD = $(GLIB_LIBS)
@@ -31,6 +38,7 @@ AM_CFLAGS =                           \
        -I$(srcdir)/                    \
        $(GLIB_CFLAGS)                  \
        $(POSTGRES_CFLAGS)              \
+       $(SQLITE_CFLAGS)                \
        $(MYSQL_CFLAGS)                 \
        -DMODULES_DIR=\"${plugindir}\"  \
        -DLOCALEDIR=\"$(localedir)\"    \
@@ -38,4 +46,4 @@ AM_CFLAGS =                           \
 
 man_MANS = man/smsd.8
 
-EXTRA_DIST = pq.c mysql.c README ChangeLog action README.MySQL 
sms.tables.mysql.sql sms.tables.pq.sql README.Tru64 $(man_MANS)
+EXTRA_DIST = sqlite.c pq.c mysql.c README ChangeLog action README.MySQL 
sms.tables.mysql.sql sms.tables.pq.sql README.Tru64 $(man_MANS)
diff --git a/smsd/README b/smsd/README
index b9a0a23..4055631 100644
--- a/smsd/README
+++ b/smsd/README
@@ -123,9 +123,9 @@ Options:
 
 -m, --module db_module
        Specify which module to use for connection to DB server.
-       Currently supported are pq for PostgreSQL, mysql for MySQL and file
-       for the text file (see THE FILE MODULE section). Default is file
-       module.
+       Currently supported are pq for PostgreSQL, mysql for MySQL, sqlite for 
+       SQLite3 and file for the text file (see THE FILE MODULE section).
+       Default is file module. 
 
 -l, --libdir path_to_db_module
        Specify path to DB modules. If you specify pq module, smsd searches
@@ -217,6 +217,8 @@ The configure script autodetects the plugins to build:
    (plugin file is libsmsd_pq.so)
  - the MySQL module is built if mysql_config is present
    (plugin file is libsmsd_mysql.so)
+ - the SQLIte module is built if sqlite3 libraries are detected
+   (plugin file is libsmsd_sqlite.so)
  - the file module is built if glib is present
    (plugin file is libsmsd_file.so)
 
diff --git a/smsd/man/smsd.8 b/smsd/man/smsd.8
index a0f0be6..1fb4f7e 100644
--- a/smsd/man/smsd.8
+++ b/smsd/man/smsd.8
@@ -156,7 +156,7 @@ Specify user password.
 
 .TP
 .BR -d,\ --db\ db_name
-Specify database name.
+Specify database name or full path to database file (sqlite).
 
 .TP
 .BR -c,\ --host\ db_hostname
@@ -168,7 +168,7 @@ Specify database schema.
 
 .TP
 .BR -m,\ --module\ db_module
-Specify which module to use for connection to DB server. Currently supported 
values are 'pq' for PostgreSQL, 'mysql' for MySQL and 'file'.
+Specify which module to use for connection to DB server. Currently supported 
values are 'pq' for PostgreSQL, 'mysql' for MySQL, 'sqlite' for SQLite3 and 
'file'. File module is not supported in Windows.
 
 .TP
 .BR -l,\ --libdir\ path_to_db_module
diff --git a/smsd/sms.tables.sqlite.sql b/smsd/sms.tables.sqlite.sql
new file mode 100644
index 0000000..85a2b0f
--- /dev/null
+++ b/smsd/sms.tables.sqlite.sql
@@ -0,0 +1,23 @@
+-- $ sqlite3 -init ./sms.tables.sqlite.sql smsd.db
+create table inbox (
+    "id" integer primary key,
+    "number" text not null,
+    "smsdate" text not null,
+    "insertdate" text not null,
+    "text" text,
+    "phone" integer,
+    "processed" integer default 0
+);
+create table outbox (
+    "id" integer primary key,
+    "number" text not null,
+    "processed_date" text not null,
+    "insertdate" text not null,
+    "text" text,
+    "phone" integer,
+    "processed" integer default 0,
+    "error" integer default -1 not null,
+    "dreport" integer default 0 not null,
+    "not_before" text default '00:00:00' not null,
+    "not_after" text default '23:59:59' not null
+);
diff --git a/smsd/smsd.c b/smsd/smsd.c
index 35b5a6d..1eeff7c 100644
--- a/smsd/smsd.c
+++ b/smsd/smsd.c
@@ -69,7 +69,7 @@ bool GTerminateThread;
 
 /* Local variables */
 static DBConfig connection;
-void (*DB_Bye) (void) = NULL;;
+void (*DB_Bye) (void) = NULL;
 gint (*DB_ConnectInbox) (const DBConfig) = NULL;
 gint (*DB_ConnectOutbox) (const DBConfig) = NULL;
 gint (*DB_InsertSMS) (const gn_sms * const, const gchar * const) = NULL;
@@ -516,6 +516,8 @@ static void GetSMS (void)
 
 static void Run (void)
 {
+    /* Windows doesn't support signaling */
+#ifndef WIN32
   struct sigaction act;
   
   act.sa_flags = 0;
@@ -531,6 +533,7 @@ static void Run (void)
   sigemptyset (&(act.sa_mask));
   sigaction (SIGALRM, &act, NULL);
 #endif
+#endif
 
   InitPhoneMonitor ();
   if ((*DB_ConnectInbox) (connection))
diff --git a/smsd/sqlite.c b/smsd/sqlite.c
new file mode 100644
index 0000000..10ebebf
--- /dev/null
+++ b/smsd/sqlite.c
@@ -0,0 +1,251 @@
+/*
+
+  S M S D
+
+  A Linux/Unix tool for the mobile phones.
+
+  This file is part of gnokii.
+
+  Gnokii is free software; you can redistribute it and/or modify
+  it under the terms of the GNU General Public License as published by
+  the Free Software Foundation; either version 2 of the License, or
+  (at your option) any later version.
+
+  Gnokii is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+  GNU General Public License for more details.
+
+  You should have received a copy of the GNU General Public License
+  along with gnokii; if not, write to the Free Software
+  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+  Copyright (C) 1999 Pavel Janik ml., Hugh Blemings
+  Copyright (C) 1999-2005 Jan Derfinak
+  
+  This file is a module to smsd for SQLite db server.
+
+ */
+
+#include "config.h"
+#include <string.h>
+#include <stdlib.h>
+#include <sqlite3.h>
+#include <glib.h>
+#include "smsd.h"
+#include "gnokii.h"
+#include "compat.h"
+#include "utils.h"
+
+static sqlite3 *ppDbInbox;
+static sqlite3 *ppDbOutbox;
+
+GNOKII_API void DB_Bye(void)
+{
+    if (ppDbInbox)
+        sqlite3_close(ppDbInbox);
+
+    if (ppDbOutbox)
+        sqlite3_close(ppDbOutbox);
+}
+
+GNOKII_API gint DB_ConnectInbox(DBConfig connect)
+{
+    int rc;
+    rc = sqlite3_open(connect.db, &ppDbInbox);
+    if (rc != SQLITE_OK) {
+        g_print(_("Connection to database '%s' on failed.\n"), connect.db);
+        g_print(_("Error: %s\n"), sqlite3_errmsg(ppDbInbox));
+        return 1;
+    }
+    return 0;
+}
+
+GNOKII_API gint DB_ConnectOutbox(DBConfig connect)
+{
+    int rc;
+    rc = sqlite3_open(connect.db, &ppDbOutbox);
+    if (rc != SQLITE_OK) {
+        g_print(_("Connection to database '%s' on failed.\n"), connect.db);
+        g_print(_("Error: %s\n"), sqlite3_errmsg(ppDbOutbox));
+        return 1;
+    }
+    return 0;
+}
+
+GNOKII_API gint DB_InsertSMS(const gn_sms * const data, const gchar * const 
phone)
+{
+    GString *buf, *phnStr, *text;
+    time_t rawtime;
+    struct tm * timeinfo;
+    int error, i;
+    sqlite3_stmt *stmt;
+
+    if (phone[0] == '\0')
+        phnStr = g_string_new("");
+    else {
+        phnStr = g_string_sized_new(32);
+        g_string_printf(phnStr, "'%s',", phone);
+    }
+
+    text = g_string_sized_new(480);
+    g_string_append(text, strEscape((gchar *) data->user_data[0].u.text));
+
+    time(&rawtime);
+    timeinfo = localtime(&rawtime);
+
+    buf = g_string_sized_new(1024);
+    g_string_printf(buf, "INSERT INTO inbox (\"number\", \"smsdate\", 
\"insertdate\",\
+                         \"text\", %s \"processed\") VALUES ('%s', \
+                         '%02d-%02d-%02d %02d:%02d:%02d',\
+                         '%02d-%02d-%02d %02d:%02d:%02d', '%s', %s 0)",
+            phone[0] != '\0' ? "\"phone\"," : "", data->remote.number,
+            data->smsc_time.year, data->smsc_time.month,
+            data->smsc_time.day, data->smsc_time.hour,
+            data->smsc_time.minute, data->smsc_time.second,
+            timeinfo->tm_year + 1900, timeinfo->tm_mon,
+            timeinfo->tm_mday, timeinfo->tm_hour,
+            timeinfo->tm_min, timeinfo->tm_sec,
+            text->str, phnStr->str);
+
+    g_string_free(text, TRUE);
+    g_string_free(phnStr, TRUE);
+
+    error = sqlite3_prepare_v2(ppDbInbox, buf->str, -1, &stmt, NULL);
+    if (error != SQLITE_OK) {
+        g_print(_("%d: Parsing query %s failed!"), __LINE__, buf->str);
+        g_print(_("Error: %s"), sqlite3_errmsg(ppDbInbox));
+        return SMSD_NOK;
+    }
+
+    /* run query */
+    for (i = 0; i < 6; i++) {
+        error = sqlite3_step(stmt);
+        if (error == SQLITE_DONE)
+            break;
+
+        sleep(1);
+        sqlite3_reset(stmt);
+    }
+
+    if (error != SQLITE_DONE) {
+        sqlite3_finalize(stmt);
+        g_print(_("%d: INSERT INTO inbox failed.\n"), __LINE__);
+        g_print(_("Error %d: %s\n"), error, sqlite3_errmsg(ppDbInbox));
+        g_print(_("Query: %s\n"), buf->str);
+        g_string_free(buf, TRUE);
+        return SMSD_NOK;
+    }
+
+    sqlite3_finalize(stmt);
+    g_string_free(buf, TRUE);
+    return SMSD_OK;
+}
+
+GNOKII_API void DB_Look(const gchar * const phone)
+{
+    GString *buf, *phnStr, *timebuf;
+    gint ret1, numError, error;
+    time_t rawtime;
+    struct tm * timeinfo;
+    sqlite3_stmt * stmt;
+
+    if (phone[0] == '\0')
+        phnStr = g_string_new("");
+    else {
+        phnStr = g_string_sized_new(32);
+        g_string_printf(phnStr, "AND phone = '%s'", phone);
+    }
+
+    time(&rawtime);
+    timeinfo = localtime(&rawtime);
+
+    timebuf = g_string_sized_new(25);
+    g_string_printf(timebuf, "'%02d:%02d:%02d'",
+            timeinfo->tm_hour, timeinfo->tm_min, timeinfo->tm_sec);
+
+    sqlite3_exec(ppDbOutbox, "BEGIN TRANSACTION;", NULL, NULL, NULL);
+
+    /* poll for outgoing messages */
+    buf = g_string_sized_new(256);
+    g_string_printf(buf, "SELECT id, number, text, dreport FROM outbox \
+                        WHERE processed=0 \
+                        AND %s >= not_before \
+                        AND %s <= not_after \
+                        %s", timebuf->str, timebuf->str, phnStr->str);
+
+    g_string_free(phnStr, TRUE);
+
+    ret1 = sqlite3_prepare_v2(ppDbOutbox, buf->str, -1, &stmt, NULL);
+    if (ret1 != SQLITE_OK) {
+        g_print(_("%d: Parsing query %s failed!"), __LINE__, buf->str);
+        g_print(_("Error: %s"), sqlite3_errmsg(ppDbInbox));
+        return;
+    }
+
+    g_string_printf(timebuf, "'%02d-%02d-%02d %02d:%02d:%02d'",
+            timeinfo->tm_year, timeinfo->tm_mon,
+            timeinfo->tm_mday, timeinfo->tm_hour,
+            timeinfo->tm_min, timeinfo->tm_sec
+            );
+
+    ret1 = sqlite3_step(stmt);
+    while (ret1 == SQLITE_ROW) {
+        int gerror = 0;
+        gn_sms sms;
+
+        gn_sms_default_submit(&sms);
+        memset(&sms.remote.number, 0, sizeof (sms.remote.number));
+        sms.delivery_report = sqlite3_column_int(stmt, 3);
+
+        strncpy(sms.remote.number, sqlite3_column_text(stmt, 1), sizeof 
(sms.remote.number) - 1);
+        sms.remote.number[sizeof (sms.remote.number) - 1] = '\0';
+        if (sms.remote.number[0] == '+')
+            sms.remote.type = GN_GSM_NUMBER_International;
+        else
+            sms.remote.type = GN_GSM_NUMBER_Unknown;
+
+        strncpy((gchar *) sms.user_data[0].u.text, sqlite3_column_text(stmt, 
2), 10 * GN_SMS_MAX_LENGTH + 1);
+        sms.user_data[0].u.text[10 * GN_SMS_MAX_LENGTH] = '\0';
+        sms.user_data[0].length = strlen((gchar *) sms.user_data[0].u.text);
+        sms.user_data[0].type = GN_SMS_DATA_Text;
+        sms.user_data[1].type = GN_SMS_DATA_None;
+        if (!gn_char_def_alphabet(sms.user_data[0].u.text))
+            sms.dcs.u.general.alphabet = GN_SMS_DCS_UCS2;
+
+        gn_log_xdebug("Sending SMS: %s, %s\n", sms.remote.number, 
sms.user_data[0].u.text);
+
+        numError = 0;
+        do {
+            error = WriteSMS(&sms);
+            sleep(1);
+        } while ((error == GN_ERR_TIMEOUT || error == GN_ERR_FAILED) && 
numError++ < 3);
+
+        /* mark sended */
+        g_string_printf(buf, "UPDATE outbox SET processed=1, error='%d', \
+                        processed_date=%s \
+                        WHERE id=%d",
+                gerror, timebuf->str, sqlite3_column_int(stmt, 0)
+                );
+
+        sqlite3_exec(ppDbOutbox, buf->str, NULL, NULL, NULL);
+        ret1 = sqlite3_step(stmt);
+    }
+
+    /* rollback if found any errors */
+    if (ret1 != SQLITE_DONE) {
+        g_print(_("%d: SELECT FROM outbox command failed.\n"), __LINE__);
+        g_print(_("Error: %s\n"), sqlite3_errmsg(ppDbOutbox));
+        sqlite3_finalize(stmt);
+        sqlite3_exec(ppDbOutbox, "ROLLBACK TRANSACTION;", NULL, NULL, NULL);
+
+        g_string_free(timebuf, TRUE);
+        g_string_free(buf, TRUE);
+        return;
+    }
+    sqlite3_finalize(stmt);
+    sqlite3_exec(ppDbOutbox, "COMMIT;", NULL, NULL, NULL);
+
+    g_string_free(timebuf, TRUE);
+    g_string_free(buf, TRUE);
+}

-----------------------------------------------------------------------

Summary of changes:
 ChangeLog                  |    2 +
 configure.in               |   21 ++++-
 smsd/ChangeLog             |    5 +
 smsd/Makefile.am           |   10 ++-
 smsd/README                |    8 +-
 smsd/man/smsd.8            |    4 +-
 smsd/sms.tables.sqlite.sql |   23 ++++
 smsd/smsd.c                |    5 +-
 smsd/sqlite.c              |  251 ++++++++++++++++++++++++++++++++++++++++++++
 9 files changed, 321 insertions(+), 8 deletions(-)
 create mode 100644 smsd/sms.tables.sqlite.sql
 create mode 100644 smsd/sqlite.c


hooks/post-receive
-- 
libgnokii and core programs



reply via email to

[Prev in Thread] Current Thread [Next in Thread]