diff -uNr /home/ja/work/gnokii/gnokii/smsd/ChangeLog gnokii/smsd/ChangeLog --- /home/ja/work/gnokii/gnokii/smsd/ChangeLog 2006-01-29 23:57:28.742790887 +0100 +++ gnokii/smsd/ChangeLog 2006-01-30 00:34:05.943957496 +0100 @@ -1,3 +1,7 @@ +* Mon Jan 30 2006 Jan Derfinak +- Added schema support for PostgreSQL. + + * Sat Jan 21 2006 Jan Derfinak - Fix gcc 4 type check warnings. diff -uNr /home/ja/work/gnokii/gnokii/smsd/man/smsd.8 gnokii/smsd/man/smsd.8 --- /home/ja/work/gnokii/gnokii/smsd/man/smsd.8 2005-12-11 22:11:15.797349982 +0100 +++ gnokii/smsd/man/smsd.8 2006-01-30 00:21:02.136196111 +0100 @@ -163,6 +163,10 @@ Specify database server host name. .TP +.BR -s,\ --schema\ db_hostname +Specify database schema. + +.TP .BR -m,\ --module\ db_module Specify which module to use for connection to DB server. Currently supported are pq for PostgreSQL and mysql for MySQL. @@ -254,7 +258,7 @@ Polling interval for incoming sms's in seconds. Default is 1 second. .TP -.BR -s,\ --maxsms\ number +.BR -S,\ --maxsms\ number When phone driver doesn't support sms status it is possible to specify number of sms's supported by phone. Default is 10. If driver support sms status this option is ignored. diff -uNr /home/ja/work/gnokii/gnokii/smsd/pq.c gnokii/smsd/pq.c --- /home/ja/work/gnokii/gnokii/smsd/pq.c 2006-01-29 23:57:28.766791109 +0100 +++ gnokii/smsd/pq.c 2006-01-30 00:48:34.624736786 +0100 @@ -39,6 +39,7 @@ static PGconn *connIn = NULL; static PGconn *connOut = NULL; +static gchar *schema = NULL; /* database schema */ void DB_Bye (void) { @@ -68,6 +69,9 @@ return (1); } + if (schema == NULL) + g_strdup (connect.schema); + return (0); } @@ -90,6 +94,9 @@ return (1); } + if (schema == NULL) + g_strdup (connect.schema); + return (0); } @@ -111,9 +118,10 @@ text = strEscape ((gchar *) data->user_data[0].u.text); buf = g_string_sized_new (256); - g_string_sprintf (buf, "INSERT INTO inbox (\"number\", \"smsdate\", \"insertdate\",\ + g_string_sprintf (buf, "INSERT INTO %s.inbox (\"number\", \"smsdate\", \"insertdate\",\ \"text\", %s \"processed\") VALUES ('%s', \ '%02d-%02d-%02d %02d:%02d:%02d+01', 'now', '%s', %s 'f')", + schema, phone[0] != '\0' ? "\"phone\"," : "", data->remote.number, data->smsc_time.year, data->smsc_time.month, data->smsc_time.day, data->smsc_time.hour, @@ -125,7 +133,7 @@ g_string_free(buf, TRUE); if (!res || PQresultStatus(res) != PGRES_COMMAND_OK) { - g_print (_("%d: INSERT INTO inbox failed.\n"), __LINE__); + g_print (_("%d: INSERT INTO %s.inbox failed.\n"), __LINE__, schema); g_print (_("Error: %s\n"), PQerrorMessage (connIn)); PQclear (res); return (1); @@ -157,15 +165,16 @@ res1 = PQexec (connOut, "BEGIN"); PQclear (res1); - g_string_sprintf (buf, "SELECT id, number, text, dreport FROM outbox \ + g_string_sprintf (buf, "SELECT id, number, text, dreport FROM %s.outbox \ WHERE processed='f' AND localtime(0) >= not_before \ - AND localtime(0) <= not_after %s FOR UPDATE", phnStr->str); + AND localtime(0) <= not_after %s FOR UPDATE", + schema, phnStr->str); g_string_free (phnStr, TRUE); res1 = PQexec (connOut, buf->str); if (!res1 || PQresultStatus (res1) != PGRES_TUPLES_OK) { - g_print (_("%d: SELECT FROM outbox command failed.\n"), __LINE__); + g_print (_("%d: SELECT FROM %s.outbox command failed.\n"), __LINE__, schema); g_print (_("Error: %s\n"), PQerrorMessage (connOut)); PQclear (res1); res1 = PQexec (connOut, "ROLLBACK TRANSACTION"); @@ -207,9 +216,9 @@ } while ((error == GN_ERR_TIMEOUT || error == GN_ERR_FAILED) && numError++ < 3); - g_string_sprintf (buf, "UPDATE outbox SET processed='t', error='%d', \ + g_string_sprintf (buf, "UPDATE %s.outbox SET processed='t', error='%d', \ processed_date='now' WHERE id='%s'", - error, PQgetvalue (res1, i, 0)); + schema, error, PQgetvalue (res1, i, 0)); res2 = PQexec (connOut, buf->str); if (!res2 || PQresultStatus (res2) != PGRES_COMMAND_OK) diff -uNr /home/ja/work/gnokii/gnokii/smsd/README gnokii/smsd/README --- /home/ja/work/gnokii/gnokii/smsd/README 2005-12-11 22:11:15.221352305 +0100 +++ gnokii/smsd/README 2006-01-30 00:19:45.315444807 +0100 @@ -104,6 +104,9 @@ -c, --host db_hostname Specify database server host name. +-s, --schema db_schema + Specify database schema. + -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 @@ -165,7 +168,7 @@ -i, --interval interval Polling interval for incoming sms's in seconds. Default is 1 second. --s, --maxsms number +-S, --maxsms number When phone driver doesn't support sms status it is possible to specify number of sms's supported by phone. Default is 10. If driver support sms status this option is ignored. diff -uNr /home/ja/work/gnokii/gnokii/smsd/smsd.c gnokii/smsd/smsd.c --- /home/ja/work/gnokii/gnokii/smsd/smsd.c 2006-01-29 23:57:28.770791146 +0100 +++ gnokii/smsd/smsd.c 2006-01-30 00:08:32.516990072 +0100 @@ -169,12 +169,13 @@ " -p, --password db_password\n" " -d, --db db_name\n" " -c, --host db_hostname OR spool directory if -m file\n" + " -s, --schema db_schema\n" " -m, --module db_module (pq, mysql, file)\n" " -l, --libdir path_to_db_module\n" " -f, --logfile file\n" " -t, --phone phone_number\n" " -i, --interval polling_interval_for_incoming_sms's_in_seconds\n" - " -s, --maxsms number_of_sms's (only in dumb mode)\n" + " -S, --maxsms number_of_sms's (only in dumb mode)\n" " -v, --version\n" " -h, --help\n"), p); } @@ -219,6 +220,7 @@ connection.password = g_strdup (""); connection.db = g_strdup ("sms"); connection.host = g_strdup (""); + connection.schema = g_strdup ("public"); smsdConfig.dbMod = g_strdup ("pq"); smsdConfig.libDir = g_strdup (MODULES_DIR); smsdConfig.logFile = NULL; @@ -238,19 +240,20 @@ {"password", 1, 0, 'p'}, {"db", 1, 0, 'd'}, {"host", 1, 0, 'c'}, + {"schema", 1, 0, 's'}, {"module", 1, 0, 'm'}, {"libdir", 1, 0, 'l'}, {"logfile", 1, 0, 'f'}, {"phone", 1, 0, 't'}, {"version", 0, 0, 'v'}, {"interval", 1, 0, 'i'}, - {"maxsms", 1, 0, 's'}, + {"maxsms", 1, 0, 'S'}, {"inbox", 1, 0, 'b'}, {"help", 0, 0, 'h'}, {0, 0, 0, 0} }; - c = getopt_long (argc, argv, "u:p:d:c:m:l:f:t:vi:s:b:h", longOptions, &optionIndex); + c = getopt_long (argc, argv, "u:p:d:c:s:m:l:f:t:vi:S:b:h", longOptions, &optionIndex); if (c == EOF) break; switch (c) @@ -278,6 +281,12 @@ connection.host = g_strdup (optarg); memset (optarg, 'x', strlen (optarg)); break; + + case 's': + g_free (connection.schema); + connection.schema = g_strdup (optarg); + memset (optarg, 'x', strlen (optarg)); + break; case 'm': g_free (smsdConfig.dbMod); @@ -305,7 +314,7 @@ smsdConfig.refreshInt = atoi (optarg); break; - case 's': + case 'S': smsdConfig.maxSMS = atoi (optarg); break; diff -uNr /home/ja/work/gnokii/gnokii/smsd/smsd.h gnokii/smsd/smsd.h --- /home/ja/work/gnokii/gnokii/smsd/smsd.h 2005-12-11 22:11:15.673350482 +0100 +++ gnokii/smsd/smsd.h 2006-01-29 23:58:56.111600103 +0100 @@ -54,6 +54,7 @@ gchar *password; gchar *db; gchar *host; + gchar *schema; } DBConfig; extern gchar *strEscape (const gchar *const);