kore

An easy to use, scalable and secure web application framework for writing web APIs in C.
Commits | Files | Refs | README | LICENSE | git clone https://git.kore.io/kore.git

commit beee96cb03557f791afae1f049f390cdd522b7b4
parent b6a778a4a5e3cac1193a938ed91e7720a268a0ea
Author: Joris Vink <joris@coders.se>
Date:   Thu,  3 Jul 2014 22:39:32 +0200

Correct headers now that they are installed

While here, kill some MEDIA things for libs that
don't need it and such and such.

Diffstat:
contrib/examples/generic/build.sh | 5+----
contrib/examples/generic/src/example.c | 4++--
contrib/examples/pgsql_test/build.sh | 30++----------------------------
contrib/examples/pgsql_test/src/pgsql_test.c | 75---------------------------------------------------------------------------
contrib/examples/pgsql_test/tools/inject.c | 119-------------------------------------------------------------------------------
contrib/examples/skeleton/build.sh | 11++---------
contrib/examples/task_curl/build.sh | 5+----
contrib/examples/task_curl/example.c | 6+++---
8 files changed, 11 insertions(+), 244 deletions(-)

diff --git a/contrib/examples/generic/build.sh b/contrib/examples/generic/build.sh @@ -16,12 +16,9 @@ MEDIA_DIR=media # The directory containing your module source. SOURCE_DIR=src -# The directory containing the Kore source code. -KORE_DIR=../../../ - # Compiler settings. CC=gcc -CFLAGS="-I. -I${KORE_DIR}/includes -Wall -Wstrict-prototypes \ +CFLAGS="-I. -I/usr/local/includes -Wall -Wstrict-prototypes \ -Wmissing-prototypes -Wmissing-declarations -Wshadow \ -Wpointer-arith -Wcast-qual -Wsign-compare -g" diff --git a/contrib/examples/generic/src/example.c b/contrib/examples/generic/src/example.c @@ -14,8 +14,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -#include "kore.h" -#include "http.h" +#include <kore/kore.h> +#include <kore/http.h> #include "static.h" diff --git a/contrib/examples/pgsql_test/build.sh b/contrib/examples/pgsql_test/build.sh @@ -4,12 +4,10 @@ # MODULE=pgsql_test.module -MEDIA_DIR=media -SOURCE_DIR=src -KORE_DIR=../../.. +SOURCE_DIR=. PGDIR=$(pg_config --includedir) CC=gcc -CFLAGS="-I. -I${KORE_DIR}/includes -I${PGDIR} \ +CFLAGS="-I. -I/usr/local/includes -I${PGDIR} \ -Wall -Wstrict-prototypes -Wmissing-prototypes \ -Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual \ -Wsign-compare -g" @@ -27,32 +25,11 @@ MODULE_BUILD_DATE=$(date +"%Y-%m-%d %H:%M:%S") echo "Building module ${MODULE}..." rm -f ${MODULE} -${CC} ${CFLAGS} tools/inject.c -o tools/inject - -if [ ! -d ${SOURCE_DIR}/${MEDIA_DIR} ]; then - mkdir ${SOURCE_DIR}/${MEDIA_DIR}; -fi -rm -f ${SOURCE_DIR}/${MEDIA_DIR}/* - if [ ! -d .objs ]; then mkdir .objs; fi rm -f .objs/* -rm -f static.h - -for file in `find ${MEDIA_DIR} -type f \( ! -name \*.swp \)`; do - echo "Injecting $file"; - base=`basename $file`; - ./tools/inject $file $base > ${SOURCE_DIR}/${MEDIA_DIR}/${base}.c; - if [ $? -ne 0 ]; then - echo "Injection error, check above messages for clues."; - exit 1; - fi -done - -echo "#define MODULE_BUILD_DATE \"${MODULE_BUILD_DATE}\"" >> static.h - for src in `find ${SOURCE_DIR} -type f -name \*.c`; do base=`basename $src`; ${CC} ${CFLAGS} -fPIC -c $src -o .objs/${base}.o @@ -65,7 +42,4 @@ done ${CC} ${LDFLAGS} `find .objs -name \*.o -type f` -o ${MODULE} echo "Building completed!" -rm -rf ${SOURCE_DIR}/${MEDIA_DIR} rm -rf .objs -rm -f tools/inject -rm -f static.h diff --git a/contrib/examples/pgsql_test/src/pgsql_test.c b/contrib/examples/pgsql_test/src/pgsql_test.c @@ -1,75 +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.h" -#include "http.h" -#include "pgsql.h" - -#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) -{ - 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/tools/inject.c b/contrib/examples/pgsql_test/tools/inject.c @@ -1,119 +0,0 @@ -/* - * Copyright (c) 2013 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 <sys/param.h> -#include <sys/stat.h> - -#include <ctype.h> -#include <err.h> -#include <errno.h> -#include <inttypes.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#if defined(OpenBSD) -#define PRI_TIME_T "d" -#endif - -#if defined(linux) -#if defined(__x86_64__) -#define PRI_TIME_T PRIu64 -#else -#define PRI_TIME_T "ld" -#endif -#endif - -#if defined(__MACH__) -#define PRI_TIME_T "ld" -#endif - -int -main(int argc, char *argv[]) -{ - struct stat st; - ssize_t len; - FILE *hdr; - char *ext; - unsigned char c[1]; - int fd, newline, count; - - if (argc != 3) - exit(1); - - if ((fd = open(argv[1], O_RDONLY)) == -1) - err(1, "open() %d", errno); - if ((hdr = fopen("static.h", "a+")) == NULL) - err(1, "fopen() %d", errno); - if ((ext = strchr(argv[2], '.')) != NULL) - *(ext)++ = '\0'; - else - ext = ""; - - if (stat(argv[1], &st) == -1) { - printf("stat(%s) failed: %d\n", argv[1], errno); - exit(1); - } - - printf("/**** AUTO GENERATED BY MAKEFILE - DO NOT TOUCH ****/\n"); - printf("#include <sys/param.h>\n\n"); - printf("u_int8_t static_%s_%s[] = {", ext, argv[2]); - - len = 0; - count = 0; - newline = 1; - for (;;) { - if (newline) { - printf("\n\t"); - count = 0; - newline = 0; - } - - len = read(fd, c, 1); - if (len == 0) - break; - - if (len == -1) { - printf("read(): %d\n", errno); - exit(1); - } - - if (len != 1) - exit(1); - - printf("0x%02x, ", c[0]); - if (count++ == 10) - newline = 1; - } - - close(fd); - - printf("};\n\n"); - printf("u_int32_t static_len_%s_%s = %" PRIu32 ";\n", - ext, argv[2], (u_int32_t)st.st_size); - - printf("time_t static_mtime_%s_%s = %" PRI_TIME_T ";\n", - ext, argv[2], st.st_mtime); - - fprintf(hdr, "extern u_int8_t static_%s_%s[];\n", ext, argv[2]); - fprintf(hdr, "extern u_int32_t static_len_%s_%s;\n", ext, argv[2]); - fprintf(hdr, "extern time_t static_mtime_%s_%s;\n", ext, argv[2]); - fclose(hdr); - - return (0); -} diff --git a/contrib/examples/skeleton/build.sh b/contrib/examples/skeleton/build.sh @@ -3,7 +3,7 @@ # Copyright (c) 2013 Joris Vink <joris@coders.se> # # Kore module build script, use this as a base for building -# your own modules for kore. +# your own modules for kore or just roll your own. # The name of the module you will be building MODULE=site.module @@ -16,16 +16,9 @@ MEDIA_DIR=media # The directory containing your module source. SOURCE_DIR=src -# The directory containing the Kore source code. -KORE_DIR="notset" -if [ ${KORE_DIR} = "notset" ]; then - echo "Please edit build.sh and set KORE_DIR properly"; - exit; -fi - # Compiler settings. CC=gcc -CFLAGS="-I. -I${KORE_DIR}/includes -Wall -Wstrict-prototypes \ +CFLAGS="-I. -I/usr/local/includes -Wall -Wstrict-prototypes \ -Wmissing-prototypes -Wmissing-declarations -Wshadow \ -Wpointer-arith -Wcast-qual -Wsign-compare -g" diff --git a/contrib/examples/task_curl/build.sh b/contrib/examples/task_curl/build.sh @@ -11,12 +11,9 @@ MODULE=task_curl.so # The directory containing your module source. SOURCE_DIR=. -# The directory containing the Kore source code. -KORE_DIR=../../../ - # Compiler settings. CC=gcc -CFLAGS="-I. -I${KORE_DIR}/includes -Wall -Wstrict-prototypes \ +CFLAGS="-I. -I/usr/local/includes -Wall -Wstrict-prototypes \ -Wmissing-prototypes -Wmissing-declarations -Wshadow \ -Wpointer-arith -Wcast-qual -Wsign-compare -g" diff --git a/contrib/examples/task_curl/example.c b/contrib/examples/task_curl/example.c @@ -38,9 +38,9 @@ #include <curl/curl.h> -#include "kore.h" -#include "http.h" -#include "tasks.h" +#include <kore/kore.h> +#include <kore/http.h> +#include <kore/tasks.h> int run_curl(struct kore_task *); int post_back(struct http_request *);