commit 6cabe00740910c212a7bb4e996630b6717c0ef9c
parent 4b7a458de6f5932c16f6b3eda8337d631aa4924c
Author: Joris Vink <joris@coders.se>
Date:   Mon, 14 Apr 2014 08:41:41 +0200
Make the pgsql connstring programmatically configurable
Diffstat:
3 files changed, 20 insertions(+), 2 deletions(-)
diff --git a/contrib/modules/pgsql_test/src/pgsql_test.c b/contrib/modules/pgsql_test/src/pgsql_test.c
@@ -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)
 {
diff --git a/contrib/postgres/kore_pgsql.c b/contrib/postgres/kore_pgsql.c
@@ -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));
diff --git a/includes/contrib/postgres/kore_pgsql.h b/includes/contrib/postgres/kore_pgsql.h
@@ -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 *);