Make the pgsql connstring programmatically configurable

This commit is contained in:
Joris Vink 2014-04-14 08:41:41 +02:00
parent 4b7a458de6
commit 6cabe00740
3 changed files with 20 additions and 2 deletions

View File

@ -20,8 +20,21 @@
#include "static.h"
void pgsql_load(int);
int serve_pgsql_test(struct http_request *);
void
pgsql_load(int state)
{
switch (state) {
case KORE_MODULE_LOAD:
pgsql_conn_string = "Your connection string";
break;
default:
break;
}
}
int
serve_pgsql_test(struct http_request *req)
{

View File

@ -51,10 +51,14 @@ static void pgsql_read_result(struct http_request *, int,
static TAILQ_HEAD(, pgsql_conn) pgsql_conn_free;
static u_int16_t pgsql_conn_count;
char *pgsql_conn_string = NULL;
void
kore_pgsql_init(void)
{
if (pgsql_conn_string == NULL)
fatal("No pgsql connection string set");
pgsql_conn_count = 0;
TAILQ_INIT(&pgsql_conn_free);
}
@ -248,8 +252,7 @@ pgsql_conn_create(struct http_request *req, int idx)
kore_debug("pgsql_conn_create(): %p", conn);
memset(conn, 0, sizeof(*conn));
/* XXX don't forget to make this configurable. */
conn->db = PQconnectdb("host=/tmp/ user=joris");
conn->db = PQconnectdb(pgsql_conn_string);
if (conn->db == NULL || (PQstatus(conn->db) != CONNECTION_OK)) {
req->pgsql[idx]->state = KORE_PGSQL_STATE_ERROR;
req->pgsql[idx]->error = kore_strdup(PQerrorMessage(conn->db));

View File

@ -26,6 +26,8 @@ struct kore_pgsql {
void *conn;
};
extern char *pgsql_conn_string;
void kore_pgsql_init(void);
void kore_pgsql_handle(void *, int);
void kore_pgsql_cleanup(struct http_request *);