diff options
Diffstat (limited to 'modules/postgres/postgres.c')
-rw-r--r-- | modules/postgres/postgres.c | 32 |
1 files changed, 6 insertions, 26 deletions
diff --git a/modules/postgres/postgres.c b/modules/postgres/postgres.c index 3e696ca..1218564 100644 --- a/modules/postgres/postgres.c +++ b/modules/postgres/postgres.c @@ -29,15 +29,14 @@ #include <smap/diag.h> #include <smap/module.h> #include <smap/parseopt.h> #include <smap/stream.h> #include <smap/wordsplit.h> -#define MDB_INIT 0x01 -#define MDB_OPEN 0x02 -#define MDB_DEFDB 0x04 +#define MDB_OPEN 0x01 +#define MDB_DEFDB 0x02 struct modpg_db { int flags; unsigned refcnt; const char *name; PGconn *pgconn; @@ -80,18 +79,12 @@ opendb(struct modpg_db *db) { if (db->flags & MDB_OPEN) { db->refcnt++; return 0; } - if (!(db->flags & MDB_INIT)) { - smap_error("%s: module settings do not include opendb flag", - db->name); - return 1; - } - db->pgconn = PQconnectdb(db->conninfo); if (!db->pgconn) { smap_error("%s: out of memory", db->name); return 1; } @@ -199,18 +192,15 @@ create_conninfo(int argc, char **argv) static int modpg_init(int argc, char **argv) { int i; int rc; - int opendb = 0; dbgid = smap_debug_alloc("postgres"); struct smap_option init_option[] = { - { SMAP_OPTSTR(open), smap_opt_bool, - &opendb }, { SMAP_OPTSTR(query), smap_opt_string, &def_db.template }, { SMAP_OPTSTR(positive-reply), smap_opt_string, &def_db.positive_reply }, { SMAP_OPTSTR(negative-reply), smap_opt_string, &def_db.negative_reply }, @@ -224,19 +214,13 @@ modpg_init(int argc, char **argv) if (i < argc) { def_db.conninfo = create_conninfo(argc - i, argv + i); if (!def_db.conninfo) { smap_error("out of memory"); return 1; } - } - if (opendb) { - if (!def_db.conninfo) { - smap_error("no connection info given"); - return 1; - } - def_db.flags = MDB_INIT; + def_db.flags = 0; def_db.name = "postgres"; } return 0; } static smap_database_t @@ -248,14 +232,12 @@ modpg_init_db(const char *dbid, int argc, char **argv) char *onerror_reply = NULL; char *query = NULL; int flags = 0; int i; struct smap_option init_option[] = { - { SMAP_OPTSTR(defaultdb), smap_opt_bitmask, - &flags, { MDB_DEFDB } }, { SMAP_OPTSTR(query), smap_opt_string, &query }, { SMAP_OPTSTR(positive-reply), smap_opt_string, &positive_reply }, { SMAP_OPTSTR(negative-reply), smap_opt_string, &negative_reply }, @@ -276,18 +258,16 @@ modpg_init_db(const char *dbid, int argc, char **argv) db->conninfo = create_conninfo(argc - i, argv + i); if (!db->conninfo) { smap_error("out of memory"); free(db); return NULL; } - } else if (!(flags & MDB_DEFDB)) { - smap_error("%s: no connection info given", dbid); - return NULL; - } + } else + flags |= MDB_DEFDB; - db->flags = MDB_INIT | flags; + db->flags = flags; db->name = dbid; db->template = query; db->positive_reply = positive_reply; db->negative_reply = negative_reply; db->onerror_reply = onerror_reply; |