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 0ebcbe4f185e0fc201f7d7179365549a1187af4e
parent 36d603ea67332fff2a0aed5c7a2dea37ac77f660
Author: Joris Vink <joris@coders.se>
Date:   Wed, 10 Jul 2013 10:38:52 +0200

Merge remote branch 'origin/master'

Diffstat:
modules/skeleton/build.sh | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
modules/skeleton/media/.gitignore | 0
modules/skeleton/src/.gitignore | 0
modules/skeleton/tools/inject.c | 99+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 180 insertions(+), 0 deletions(-)

diff --git a/modules/skeleton/build.sh b/modules/skeleton/build.sh @@ -0,0 +1,81 @@ +#!/bin/bash +# +# Copyright (c) 2013 Joris Vink <joris@coders.se> +# +# Kore module build script, use this as a base for building +# your own modules for kore. + +# The name of the module you will be building +MODULE=site.module + +# The directory containing all your media files (HTML, CSS, ...). +# These files will be compiled into the module and symbols will +# be exported for you to use in your code. +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 \ + -Wmissing-prototypes -Wmissing-declarations -Wshadow \ + -Wpointer-arith -Wcast-qual -Wsign-compare -g" +LDFLAGS=-shared +MODULE_BUILD_DATE=`date +"%Y-%m-%d %H:%M:%S"` + +# Functions used in the build process. +function create_and_empty_dir { + if [ ! -d $1 ]; then + mkdir $1; + fi + + rm -f $1/* +} + +### Begin building #### +echo "Building module ${MODULE}..." +rm -f ${MODULE} + +${CC} ${CFLAGS} tools/inject.c -o tools/inject + +create_and_empty_dir ${SOURCE_DIR}/${MEDIA_DIR} +create_and_empty_dir .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 + 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 ${SOURCE_DIR}/${MEDIA_DIR} +rm -rf .objs +rm -f tools/inject +rm -f static.h diff --git a/modules/skeleton/media/.gitignore b/modules/skeleton/media/.gitignore diff --git a/modules/skeleton/src/.gitignore b/modules/skeleton/src/.gitignore diff --git a/modules/skeleton/tools/inject.c b/modules/skeleton/tools/inject.c @@ -0,0 +1,99 @@ +/* + * 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 <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +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 = %ld;\n", ext, argv[2], st.st_size); + printf("time_t static_mtime_%s_%s = %ld;\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); +}