Module: sip-router
Branch: janakj/postgres
Commit: c65b0d937609e7752b1e63daac7ea0cc0dd0ec0a
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=c65b0d9…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Wed May 7 17:36:36 2008 +0000
- fixed wrong parameter value passed to PQexecPrepared
- few minor bugs fixed
---
modules/db_postgres/pg_cmd.c | 27 +++++++++++++++++----------
modules/db_postgres/pg_cmd.h | 1 +
modules/db_postgres/pg_mod.c | 10 +++++-----
3 files changed, 23 insertions(+), 15 deletions(-)
diff --git a/modules/db_postgres/pg_cmd.c b/modules/db_postgres/pg_cmd.c
index b0615f4..f09014c 100644
--- a/modules/db_postgres/pg_cmd.c
+++ b/modules/db_postgres/pg_cmd.c
@@ -78,7 +78,9 @@ static void pg_cmd_free(db_cmd_t* cmd, struct pg_cmd* payload)
/** Generate a unique name for a server-side PostgreSQL command.
* This function generates a unique name for each command that will be used to
- * identify the prepared statement on the server.
+ * identify the prepared statement on the server. The name has only has to be
+ * unique within a connection to the server so we just keep a global counter
+ * and the name will be that number converted to text.
*
* @param cmd A command whose name is to be generated
* @return A string allocated using pkg_malloc containing the name or NULL on
@@ -128,7 +130,8 @@ static int create_pg_params(db_cmd_t* cmd)
pcmd->params.len = (int*)pkg_malloc(sizeof(int) * num);
pcmd->params.fmt = (int*)pkg_malloc(sizeof(int) * num);
- if (!pcmd->params.val || !pcmd->params.len || !pcmd->params.fmt) {
+ if (!pcmd->params.val ||
+ !pcmd->params.len || !pcmd->params.fmt) {
ERR("postgres: No memory left\n");
goto error;
}
@@ -136,6 +139,7 @@ static int create_pg_params(db_cmd_t* cmd)
memset(pcmd->params.val, '\0', sizeof(const char*) * num);
memset(pcmd->params.len, '\0', sizeof(int) * num);
memset(pcmd->params.fmt, '\0', sizeof(int) * num);
+ pcmd->params.n = num;
return 0;
error:
@@ -240,24 +244,28 @@ int pg_cmd(db_cmd_t* cmd)
break;
case DB_SQL:
- pcmd->sql_cmd.s = (char*)pkg_malloc(cmd->table.len);
+ pcmd->sql_cmd.s = (char*)pkg_malloc(cmd->table.len + 1);
if (pcmd->sql_cmd.s == NULL) {
ERR("postgres: Out of private memory\n");
goto error;
}
memcpy(pcmd->sql_cmd.s,cmd->table.s, cmd->table.len);
+ pcmd->sql_cmd.s[cmd->table.len] = '\0';
pcmd->sql_cmd.len = cmd->table.len;
break;
}
DB_SET_PAYLOAD(cmd, pcmd);
+ /* Create parameter arrays for PostgreSQL API functions */
+ if (create_pg_params(cmd) < 0) goto error;
+
/* Generate a unique name for the command on the server */
if (gen_cmd_name(cmd) != 0) goto error;
/* Upload the command to the server */
if (upload_cmd(cmd) != 0) goto error;
-
+
/* Obtain the description of the uploaded command, this includes
* information about result and parameter fields */
if (get_types(cmd) != 0) goto error;
@@ -272,8 +280,6 @@ int pg_cmd(db_cmd_t* cmd)
if (check_types(cmd)) goto error;
- /* Create parameter arrays for PostgreSQL API functions */
- if (create_pg_params(cmd) < 0) goto error;
return 0;
error:
@@ -343,22 +349,23 @@ static int upload_cmd(db_cmd_t* cmd)
/* FIXME: The function should take the connection as one of parameters */
pcon = DB_GET_PAYLOAD(cmd->ctx->con[db_payload_idx]);
- DBG("postgres: Uploading query '%s'='%s'\n", pcmd->name,
+ DBG("postgres: Uploading comand '%s': '%s'\n", pcmd->name,
pcmd->sql_cmd.s);
res = PQprepare(pcon->con, pcmd->name, pcmd->sql_cmd.s, 0, NULL);
st = PQresultStatus(res);
- PQclear(res);
if (st != PGRES_COMMAND_OK && st != PGRES_NONFATAL_ERROR &&
st != PGRES_TUPLES_OK) {
ERR("postgres: Error while uploading command to server: %d, %s",
st, PQresultErrorMessage(res));
ERR("postgres: Command: '%s'\n", pcmd->sql_cmd.s);
+ PQclear(res);
return -1;
}
+ PQclear(res);
return 0;
}
@@ -392,9 +399,9 @@ int pg_cmd_exec(db_res_t* res, db_cmd_t* cmd)
/* Execute the statement */
tmp = PQexecPrepared(pcon->con, pcmd->name,
- cmd->match_count + cmd->vals_count,
+ pcmd->params.n,
pcmd->params.val, pcmd->params.len,
- NULL, 1);
+ pcmd->params.fmt, 1);
if (!tmp) {
ERR("postgres: PQexecPrepared returned no result\n");
continue;
diff --git a/modules/db_postgres/pg_cmd.h b/modules/db_postgres/pg_cmd.h
index 47be941..41914e9 100644
--- a/modules/db_postgres/pg_cmd.h
+++ b/modules/db_postgres/pg_cmd.h
@@ -51,6 +51,7 @@
#include <libpq-fe.h>
struct pg_params {
+ int n;
const char** val;
int* len;
int* fmt;
diff --git a/modules/db_postgres/pg_mod.c b/modules/db_postgres/pg_mod.c
index 1ed3c09..027e4af 100644
--- a/modules/db_postgres/pg_mod.c
+++ b/modules/db_postgres/pg_mod.c
@@ -359,15 +359,15 @@ int pg_test(void)
goto error;
}
- put->vals[0].v.lstr.s = "abc";
+ put->vals[0].v.lstr.s = "abc should not be there";
put->vals[0].v.lstr.len = 3;
- put->vals[1].v.lstr.s = "abc";
+ put->vals[1].v.lstr.s = "abc should not be there";
put->vals[1].v.lstr.len = 3;
- put->vals[2].v.lstr.s = "abc";
+ put->vals[2].v.lstr.s = "abc should not be there";
put->vals[2].v.lstr.len = 3;
- put->vals[3].v.lstr.s = "abc";
+ put->vals[3].v.lstr.s = "abc should not be there";
put->vals[3].v.lstr.len = 3;
- put->vals[4].v.lstr.s = "a";
+ put->vals[4].v.lstr.s = "a should not be there";
put->vals[4].v.lstr.len = 1;
if (db_exec(NULL, put)) {
ERR("Error while executing database command\n");
Module: sip-router
Branch: janakj/postgres
Commit: 9550df5a016e1729356104851eae8e476364dda1
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=9550df5…
Author: Maxim Sobolev <sobomax(a)sippysoft.com>
Committer: Maxim Sobolev <sobomax(a)sippysoft.com>
Date: Tue May 20 23:13:20 2008 +0000
We also need <sys/types.h> and <sys/socket.h> to get AF_INET on FreeBSD.
---
modules/db_postgres/pg_fld.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/modules/db_postgres/pg_fld.c b/modules/db_postgres/pg_fld.c
index c3bd09a..a9690a5 100644
--- a/modules/db_postgres/pg_fld.c
+++ b/modules/db_postgres/pg_fld.c
@@ -44,9 +44,11 @@
#include "../../mem/mem.h"
#include "../../dprint.h"
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
#include <stdint.h>
#include <string.h>
-#include <netinet/in.h>
/**
* This is the epoch time in time_t format, this value is used to convert
Module: sip-router
Branch: janakj/postgres
Commit: e39877fe6b11335e47719791bdda74f73b62bbf4
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=e39877f…
Author: Maxim Sobolev <sobomax(a)sippysoft.com>
Committer: Maxim Sobolev <sobomax(a)sippysoft.com>
Date: Mon Dec 6 13:02:10 2004 +0000
Change DSN parser a bit, so that it's possible to specify path to the unix
domain socket for communication with DB server. Consider everything after '@'
but before the last '/' to be host name (currently everything after '@' but
before first '/' is considered hostname), so that in the case of the socket
in the /foo/bar directory, one can specify DSN as follows:
postgres://username:password@/foo/bar/name_of_table
No response from: lgfausak(a)august.net
---
modules/db_postgres/db_utils.c | 4 +++-
1 files changed, 3 insertions(+), 1 deletions(-)
diff --git a/modules/db_postgres/db_utils.c b/modules/db_postgres/db_utils.c
index d5febbb..69e722e 100644
--- a/modules/db_postgres/db_utils.c
+++ b/modules/db_postgres/db_utils.c
@@ -77,7 +77,9 @@ int parse_sql_url(char* _url, char** _user, char** _pass,
at = strchr(slash, '@');
- db_slash = strchr(slash, '/');
+ db_slash = strrchr(slash, '/');
+ if (db_slash <= at)
+ db_slash = NULL;
if (db_slash) {
*db_slash++ = '\0';
*_db = trim(db_slash);
Module: sip-router
Branch: janakj/postgres
Commit: dbbb5df46a36f04cddd2b108dc200761117cb2c4
URL: http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=dbbb5df…
Author: Jan Janak <jan(a)iptel.org>
Committer: Jan Janak <jan(a)iptel.org>
Date: Tue Aug 24 08:58:23 2004 +0000
- Spelling checked
- READMEs updated
---
modules/db_postgres/README | 175 +++++++++++++++++++++++++++++---------
modules/db_postgres/aug_sysdep.h | 4 +-
modules/db_postgres/db_mod.c | 4 +-
modules/db_postgres/db_utils.c | 4 +-
modules/db_postgres/db_val.c | 2 +-
5 files changed, 143 insertions(+), 46 deletions(-)
diff --git a/modules/db_postgres/README b/modules/db_postgres/README
index 5ced10b..6e2bd9c 100644
--- a/modules/db_postgres/README
+++ b/modules/db_postgres/README
@@ -1,39 +1,136 @@
-# $Id$
-#
-# README
-#
-# History:
-# --------
-# 2003-04-07 this is a hack, from serctl, to make work with postgres
-#
-# DISCLAIMER:
-# I have yet to get this software working in my production environment.
-# Everything compiles and runs, but not for long. It may or may not be a
-# good starting point for the ser postgres driver.
-#
-# I had a hard time with memory while developing this.
-# So, I decided to incorporate some memory routines that
-# I have been using for years. This didn't fix the problem,
-# but it did make memory management easier.
-#
-# The postgres driver requires that you have postgres installed
-# on your system. You can download this from: www.postgresql.org.
-# For this I used postgres version 7.3.2, but I imagine almost any
-# recent version should work.
-#
-# You will then need to have a postgres database somewhere, and it
-# needs to have the tables created in it. Currently I am supporting
-# 2 tables, location and subscriber. The file createtables.txt contains
-# the table definitions and index definitions.
-#
-# You may wish to load the tables from a 0.8.10 database. The script
-# copy_to_psql can be modified to open your mysql database and it outputs
-# the necessary commands to populate the tables of the postgres database.
-#
-# To use the postgres module in your ser.cfg file is just like using the
-# mysql module. Ie:
-# loadmodule "/usr/local/lib/ser/modules/postgres.so"
-#
-# That's it. Good luck.
-# ---greg
-# Greg Fausak, August.Net Services, greg(a)august.net
+
+postgres Module
+
+Greg Fausak
+
+ August.net
+
+Edited by
+
+Greg Fausak
+
+ Copyright � 2003 Greg Fausak
+ _________________________________________________________
+
+ Table of Contents
+ 1. User's Guide
+
+ 1.1. Overview
+ 1.2. Dependencies
+
+ 1.2.1. SER Modules
+ 1.2.2. External Libraries or Applications
+
+ 1.3. Exported Parameters
+
+ 1.3.1. param_name (param_type)
+
+ 1.4. Exported Functions
+
+ 1.4.1. function_name(param1, param2)
+
+ 1.5. Installation & Running
+
+ 2. Developer's Guide
+ 3. Frequently Asked Questions
+
+ List of Examples
+ 1-1. Set param_name parameter
+ 1-2. function_name usage
+ _________________________________________________________
+
+Chapter 1. User's Guide
+
+1.1. Overview
+
+ Module description
+ _________________________________________________________
+
+1.2. Dependencies
+
+1.2.1. SER Modules
+
+ The following modules must be loaded before this module:
+
+ * No dependencies on other SER modules.
+ _________________________________________________________
+
+1.2.2. External Libraries or Applications
+
+ The following libraries or applications must be installed
+ before running SER with this module loaded:
+
+ * None.
+ _________________________________________________________
+
+1.3. Exported Parameters
+
+1.3.1. param_name (param_type)
+
+ Param description.
+
+ Default value is "value".
+
+ Example 1-1. Set param_name parameter
+...
+modparam("module", "param_name", "param_value")
+...
+ _________________________________________________________
+
+1.4. Exported Functions
+
+1.4.1. function_name(param1, param2)
+
+ Description
+
+ Meaning of the parameters is as follows:
+
+ * param1 - description.
+ * param2 - description.
+
+ Example 1-2. function_name usage
+...
+function_name("sample_param1", "sample_param2");
+...
+ _________________________________________________________
+
+1.5. Installation & Running
+
+ Notes about installation and running.
+ _________________________________________________________
+
+Chapter 2. Developer's Guide
+
+ The module does not provide any sort of API to use in other
+ SER modules.
+ _________________________________________________________
+
+Chapter 3. Frequently Asked Questions
+
+ 3.1. Where can I find more about SER?
+ 3.2. Where can I post a question about this module?
+ 3.3. How can I report a bug?
+
+ 3.1. Where can I find more about SER?
+
+ Take a look at http://iptel.org/ser.
+
+ 3.2. Where can I post a question about this module?
+
+ First at all check if your question was already answered on
+ one of our mailing lists:
+
+ * http://mail.iptel.org/mailman/listinfo/serusers
+ * http://mail.iptel.org/mailman/listinfo/serdev
+
+ E-mails regarding any stable version should be sent to
+ <serusers(a)iptel.org> and e-mail regarding development versions
+ or CVS snapshots should be send to <serdev(a)iptel.org>.
+
+ If you want to keep the mail private, send it to
+ <serhelp(a)iptel.org>.
+
+ 3.3. How can I report a bug?
+
+ Please follow the guidelines provided at:
+ http://iptel.org/ser/bugs
diff --git a/modules/db_postgres/aug_sysdep.h b/modules/db_postgres/aug_sysdep.h
index 78b594a..42936c2 100644
--- a/modules/db_postgres/aug_sysdep.h
+++ b/modules/db_postgres/aug_sysdep.h
@@ -60,7 +60,7 @@
#define AUG_SYSDEP_H
/*
-** As necessary, detect operating system, cpu, and compiler
+** As necessary, detect operating system, CPU, and compiler
** combinations, and establish defines that describe the
** characteristics and requirements for the combination.
**
@@ -73,7 +73,7 @@
** AUG_NO_xxxx System doesn't have capability xxxx
** AUG_BAD_xxxx System has xxxx, but it's broken
**
-** Every system gets AUG_CONFIGURATION so we can reject unconfigured
+** Every system gets AUG_CONFIGURATION so we can reject misconfigured
** compiles. This should be set to an os/cpu/compiler description.
*/
#undef AUG_CONFIGURATION
diff --git a/modules/db_postgres/db_mod.c b/modules/db_postgres/db_mod.c
index 435b8eb..7f8dd59 100644
--- a/modules/db_postgres/db_mod.c
+++ b/modules/db_postgres/db_mod.c
@@ -3,7 +3,7 @@
*
* Postgres module interface
*
- * Copyright (C) 2001-2003 Fhg Fokus
+ * Copyright (C) 2001-2003 FhG Fokus
*
* This file is part of ser, a free SIP server.
*
@@ -66,7 +66,7 @@ static cmd_export_t cmds[]={
struct module_exports exports = {
"postgres",
cmds,
- 0, /* module paramers */
+ 0, /* module parameters */
mod_init, /* module initialization function */
0, /* response function*/
diff --git a/modules/db_postgres/db_utils.c b/modules/db_postgres/db_utils.c
index e7f8fca..d5febbb 100644
--- a/modules/db_postgres/db_utils.c
+++ b/modules/db_postgres/db_utils.c
@@ -115,7 +115,7 @@ int parse_sql_url(char* _url, char** _user, char** _pass,
/*
- * Remove any tabs and spaces from the begining and the end of
+ * Remove any tabs and spaces from the beginning and the end of
* a string
*/
char* trim(char* _s)
@@ -126,7 +126,7 @@ char* trim(char* _s)
/* Null pointer, there is nothing to do */
if (!_s) return _s;
- /* Remove spaces and tabs from the begining of string */
+ /* Remove spaces and tabs from the beginning of string */
while ((*_s == ' ') || (*_s == '\t')) _s++;
len = strlen(_s);
diff --git a/modules/db_postgres/db_val.c b/modules/db_postgres/db_val.c
index d80ec04..b885341 100644
--- a/modules/db_postgres/db_val.c
+++ b/modules/db_postgres/db_val.c
@@ -351,7 +351,7 @@ int val2str(db_val_t* _v, char* _s, int* _len)
break;
default:
- DBG("val2str(): Unknow data type\n");
+ DBG("val2str(): Unknown data type\n");
return -7;
}
return -8;