commit 2a1aecbaa0c426d22c335e9b1449da1fde2a7b91
parent 2b40672ba1595f16fad105201a434588f3c4e533
Author: Joris Vink <joris@coders.se>
Date: Sun, 3 Aug 2014 17:35:03 +0200
Move pgsql_test into the new build framework
Diffstat:
5 files changed, 90 insertions(+), 140 deletions(-)
diff --git a/contrib/examples/pgsql/conf/pgsql.conf b/contrib/examples/pgsql/conf/pgsql.conf
@@ -0,0 +1,17 @@
+# Kore pgsql_test configuration
+
+bind 127.0.0.1 8888
+pidfile kore.pid
+
+ssl_no_compression
+load ./pgsql.so pgsql_load
+
+pgsql_conn_max 5
+
+domain localhost {
+ certfile cert/server.crt
+ certkey cert/server.key
+
+ accesslog kore_access.log
+ static / serve_pgsql_test
+}
diff --git a/contrib/examples/pgsql/src/pgsql.c b/contrib/examples/pgsql/src/pgsql.c
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2014 Joris Vink <joris@coders.se>
+ *
+ * Permission to use, copy, modify, and distribute this software for any
+ * purpose with or without fee is hereby granted, provided that the above
+ * copyright notice and this permission notice appear in all copies.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
+ * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
+ * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
+ * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+ * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
+ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+ */
+
+#include <kore/kore.h>
+#include <kore/http.h>
+#include <kore/pgsql.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)
+{
+ int r, i;
+ char *col1, *col2;
+
+ KORE_PGSQL(req, "SELECT * FROM test", 0, {
+ if (req->pgsql[0]->state == KORE_PGSQL_STATE_ERROR) {
+ kore_pgsql_logerror(req->pgsql[0]);
+ http_response(req, 500, "fail\n", 5);
+ return (KORE_RESULT_OK);
+ }
+
+ r = kore_pgsql_ntuples(req->pgsql[0]);
+ for (i = 0; i < r; i++) {
+ col1 = kore_pgsql_getvalue(req->pgsql[0], i, 0);
+ col2 = kore_pgsql_getvalue(req->pgsql[0], i, 1);
+
+ kore_log(LOG_NOTICE, "%s and %s", col1, col2);
+ }
+ });
+
+ KORE_PGSQL(req, "SELECT * FROM foobar", 1, {
+ if (req->pgsql[1]->state != KORE_PGSQL_STATE_ERROR) {
+ kore_log(LOG_NOTICE, "expected error, got %d",
+ req->pgsql[1]->state);
+ http_response(req, 500, "fail2\n", 6);
+ return (KORE_RESULT_OK);
+ } else {
+ kore_pgsql_logerror(req->pgsql[1]);
+ }
+ });
+
+ /* Query successfully completed */
+ http_response(req, 200, "ok\n", 3);
+
+ return (KORE_RESULT_OK);
+}
diff --git a/contrib/examples/pgsql_test/build.sh b/contrib/examples/pgsql_test/build.sh
@@ -1,45 +0,0 @@
-#!/bin/sh
-#
-# Kore pgsql test module build directives.
-#
-
-MODULE=pgsql_test.module
-SOURCE_DIR=.
-PGDIR=$(pg_config --includedir)
-CC=gcc
-CFLAGS="-I. -I/usr/local/include -I${PGDIR} \
- -Wall -Wstrict-prototypes -Wmissing-prototypes \
- -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual \
- -Wsign-compare -g"
-
-OSNAME=$(uname -s | sed -e 's/[-_].*//g' | tr A-Z a-z)
-if [ "${OSNAME}" = "darwin" ]; then
- LDFLAGS="-dynamiclib -undefined suppress -flat_namespace"
-else
- LDFLAGS="-shared"
-fi
-
-MODULE_BUILD_DATE=$(date +"%Y-%m-%d %H:%M:%S")
-
-### Begin building ####
-echo "Building module ${MODULE}..."
-rm -f ${MODULE}
-
-if [ ! -d .objs ]; then
- mkdir .objs;
-fi
-rm -f .objs/*
-
-for src in `find ${SOURCE_DIR} -type f -name \*.c`; do
- base=`basename $src`;
- ${CC} ${CFLAGS} -fPIC -c $src -o .objs/${base}.o
- if [ $? -ne 0 ]; then
- echo "Build error, check above messages for clues.";
- exit 1;
- fi
-done
-
-${CC} ${LDFLAGS} `find .objs -name \*.o -type f` -o ${MODULE}
-echo "Building completed!"
-
-rm -rf .objs
diff --git a/contrib/examples/pgsql_test/module.conf b/contrib/examples/pgsql_test/module.conf
@@ -1,22 +0,0 @@
-# Kore pgsql_test configuration
-# see modules/examples/module.conf for a better overview
-# of what a configuration file has to offer and what different
-# settings mean and do.
-
-bind 127.0.0.1 8081
-chroot /home/joris/src/kore
-runas joris
-workers 4
-pidfile kore.pid
-load contrib/examples/pgsql_test/pgsql_test.module pgsql_load
-ssl_no_compression
-
-pgsql_conn_max 5
-
-domain localhost {
- certfile cert/server.crt
- certkey cert/server.key
- accesslog kore_pgsql.log
-
- static / serve_pgsql_test
-}
diff --git a/contrib/examples/pgsql_test/pgsql_test.c b/contrib/examples/pgsql_test/pgsql_test.c
@@ -1,73 +0,0 @@
-/*
- * Copyright (c) 2014 Joris Vink <joris@coders.se>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
- */
-
-#include <kore/kore.h>
-#include <kore/http.h>
-#include <kore/pgsql.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)
-{
- int r, i;
- char *col1, *col2;
-
- KORE_PGSQL(req, "SELECT * FROM test", 0, {
- if (req->pgsql[0]->state == KORE_PGSQL_STATE_ERROR) {
- kore_pgsql_logerror(req->pgsql[0]);
- http_response(req, 500, "fail\n", 5);
- return (KORE_RESULT_OK);
- }
-
- r = kore_pgsql_ntuples(req->pgsql[0]);
- for (i = 0; i < r; i++) {
- col1 = kore_pgsql_getvalue(req->pgsql[0], i, 0);
- col2 = kore_pgsql_getvalue(req->pgsql[0], i, 1);
-
- kore_log(LOG_NOTICE, "%s and %s", col1, col2);
- }
- });
-
- KORE_PGSQL(req, "SELECT * FROM foobar", 1, {
- if (req->pgsql[1]->state != KORE_PGSQL_STATE_ERROR) {
- kore_log(LOG_NOTICE, "expected error, got %d",
- req->pgsql[1]->state);
- http_response(req, 500, "fail2\n", 6);
- return (KORE_RESULT_OK);
- } else {
- kore_pgsql_logerror(req->pgsql[1]);
- }
- });
-
- /* Query successfully completed */
- http_response(req, 200, "ok\n", 3);
-
- return (KORE_RESULT_OK);
-}