[Freeswitch-branches] [commit] r2800 - freeswitch/branches/voctel/src/mod/applications/mod_phonecard
Freeswitch SVN
voctel at freeswitch.org
Sat Sep 23 02:15:57 EDT 2006
Author: voctel
Date: Sat Sep 23 02:15:56 2006
New Revision: 2800
Modified:
freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.c
freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.h
Log:
doing some compile fixes
Modified: freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.c
==============================================================================
--- freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.c (original)
+++ freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.c Sat Sep 23 02:15:56 2006
@@ -36,7 +36,7 @@
//-- PostgreSQL
#include <libpq-fe.h>
-static const char modname[] = "mod_voctel";
+static const char modname[] = "mod_phonecard";
static const char global_app_name[] = "phonecard";
static char *global_cf_name = "phonecard.conf";
@@ -50,14 +50,60 @@
static int db_connected = 0;
-/* PostgreSQL declarations */
+//-- PostgreSQL declarations
PGconn *DBConn;
switch_mutex_t *db_lock;
+//-- function used to connect/verify database connection
+int db_connected(void) {
+ PGresult *result;
+
+ //-- check to see if we are already connected
+ if (dbconnected) {
+ result = PQexec(DBConn,"SELECT 1");
+
+ PQclear(result);
+
+ //-- check for connectivity
+ if (PQstatus(DBConn)!= CONNECTION_OK) {
+ dbconnected = 0;
+
+ PQreset(DBConn);
+
+ //-- log the database error
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "FATAL - Database connection lost '%s'\n", db_hostname);
+ }
+ else {
+ db_connected = 1;
+ }
+ }
+ else {
+ //-- we are not connected - so make the initial connection
+ DBConn = PQsetdbLogin(dbhost, dbport, NULL, NULL, dbname, dbuser, dbpass);
+ if (PQstatus(DBConn) != CONNECTION_OK) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "FATAL - Couldn't connect to database server '%s'. \n", db_hostname);
+ db_connected = 0;
+ }
+ else {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Successfully connected to database '%s:%s'.\n", db_hostname, db_name);
+ db_connected = 1;
+ }
+ }
+
+ return db_connected;
+}
+
//-- main application routine
static void phonecard_main(switch_core_session_t *session, char *data)
{
+ //--
+ if (!mydata) {
+ switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_CRIT, "Pool Failure\n");
+ return;
+ }
+
+
switch_log_printf(SWITCH_CHANNEL_LOG, SWITCH_LOG_NOTICE, "Hello World!\n");
}
Modified: freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.h
==============================================================================
--- freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.h (original)
+++ freeswitch/branches/voctel/src/mod/applications/mod_phonecard/mod_phonecard.h Sat Sep 23 02:15:56 2006
@@ -30,11 +30,9 @@
* mod_phonecard.h -- Calling Card Module
*
*/
-/*! \brief Function used to connect to MS SQL */
-extern int mssql_connect(void);
-/*! \brief Function used to connect to MS SQL */
-extern int mssql_disconnect(void);
+/*! \brief Function used to connect to PostgreSQL */
+extern int db_connected(void);
More information about the Freeswitch-branches
mailing list