diff --git a/example.conf b/example.conf index 1bc6c1e..35b766f 100644 --- a/example.conf +++ b/example.conf @@ -4,9 +4,9 @@ bind 10.211.55.3 443 # Load our site module now (containing all the goodies). -load ../betrippin/betrippin.module +load example/example.module # Declare page handlers below. # handler path module_callback -static /css/main.css betrippin_serve_style_css +static /css/style.css betrippin_serve_style_css static / betrippin_serve_index diff --git a/example/Makefile b/example/Makefile new file mode 100644 index 0000000..fe31d1d --- /dev/null +++ b/example/Makefile @@ -0,0 +1,49 @@ +# Example Kore module + +.SUFFIXES: .html .css + +CC=gcc +BIN=example.module + +HTML= html/index.html +H_SRCS= $(HTML:.html=.c) + +CSS= css/style.css +C_SRCS= $(CSS:.css=.c) + +S_SRC= src/example.c $(H_SRCS) $(C_SRCS) +S_OBJS= $(S_SRC:.c=.o) + +CFLAGS+=-I. -I../includes +CFLAGS+=-Wall -Wstrict-prototypes -Wmissing-prototypes +CFLAGS+=-Wmissing-declarations -Wshadow -Wpointer-arith -Wcast-qual +CFLAGS+=-Wsign-compare -g +LDFLAGS+=-shared + +all: + make clean + make example.module + +example.module: html_inject $(H_SRCS) $(C_SRCS) $(S_OBJS) + $(CC) $(LDFLAGS) $(S_OBJS) -o $(BIN) + make clean_o + +html_inject: tools/html_inject.c + $(CC) $(CFLAGS) tools/html_inject.c -o tools/html_inject + +.html.c: + tools/html_inject $< `basename $<` > $@ + +.css.c: + tools/html_inject $< `basename $<` > $@ + +.c.o: $< + $(CC) -fPIC $(CFLAGS) -c $< -o $@ + +clean: + make clean_o + rm -f css/*.c html/*.c tools/html_inject $(BIN) + rm -f static.h + +clean_o: + rm -f css/*.o html/*.o src/*.o diff --git a/example/css/style.css b/example/css/style.css new file mode 100644 index 0000000..f8b3425 --- /dev/null +++ b/example/css/style.css @@ -0,0 +1,16 @@ +body { + width: 100%; + margin: 0px; + color: #000; + overflow: hidden; + background-color: #fff; +} + +.content { + width: 800px; + margin-left: auto; + margin-right: auto; + margin-top: 100px; + font-size: 60px; + text-align: center; +} diff --git a/example/html/index.html b/example/html/index.html new file mode 100644 index 0000000..bf8b7d7 --- /dev/null +++ b/example/html/index.html @@ -0,0 +1,14 @@ + + + + Your KORE module worked! + + + + +
+

Your first Kore module worked.

+
+ + + diff --git a/example/src/example.c b/example/src/example.c new file mode 100644 index 0000000..166c02c --- /dev/null +++ b/example/src/example.c @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2013 Joris Vink + * + * 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 +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#include "spdy.h" +#include "kore.h" +#include "http.h" + +#include "static.h" + +int betrippin_serve_style_css(struct http_request *); +int betrippin_serve_index(struct http_request *); + +int +betrippin_serve_style_css(struct http_request *req) +{ + int ret; + + ret = http_response(req, 200, static_css_style, + static_len_css_style, "text/css"); + + return (ret); +} + +int +betrippin_serve_index(struct http_request *req) +{ + int ret; + + ret = http_response(req, 200, static_html_index, + static_len_html_index, "text/html"); + + return (ret); +} diff --git a/example/tools/html_inject.c b/example/tools/html_inject.c new file mode 100755 index 0000000..da8188f --- /dev/null +++ b/example/tools/html_inject.c @@ -0,0 +1,74 @@ +/* + * Copyright (c) 2013 Joris Vink + * + * 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 + +#include +#include +#include +#include +#include +#include +#include + +int +main(int argc, char *argv[]) +{ + size_t len; + FILE *fp, *hdr; + char *ext, *p, *c, buf[1024]; + + if (argc != 3) + err(1, "arguments"); + if ((fp = fopen(argv[1], "r")) == NULL) + err(1, "fopen() %d", errno); + if ((hdr = fopen("static.h", "a+")) == NULL) + err(1, "fopen() %d", errno); + if ((ext = strchr(argv[2], '.')) != NULL) + *(ext)++ = '\0'; + + printf("/**** AUTO GENERATED BY MAKEFILE - DO NOT TOUCH ****/\n"); + printf("#include \n\n"); + printf("u_int8_t *static_%s_%s = (u_int8_t *)", ext, argv[2]); + + len = 0; + while (fgets(buf, sizeof(buf), fp)) { + if ((p = strchr(buf, '\n')) != NULL) + *p = '\0'; + + printf("\n\t\""); + for (c = buf; *c != '\0'; c++) { + if (*c == '"' || *c == '\\') + printf("\\"); + printf("%c", *c); + len++; + } + + printf("\\n\""); + len++; + } + + fclose(fp); + + printf(";\n\n"); + printf("u_int32_t static_len_%s_%s = %ld;", ext, argv[2], len); + + 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]); + fclose(hdr); + + return (0); +}