commit 9cba130c4bf0a996b698631040a62ce2fd1971f6
parent d39246e0e2988d6febed49d2291790fc707710e6
Author: Joris Vink <joris@coders.se>
Date: Sun, 3 Aug 2014 20:29:24 +0200
Add integers example
Diffstat:
4 files changed, 79 insertions(+), 0 deletions(-)
diff --git a/examples/integers/.gitignore b/examples/integers/.gitignore
@@ -0,0 +1,5 @@
+*.o
+.objs
+hello-world.so
+static.h
+cert
diff --git a/examples/integers/README.md b/examples/integers/README.md
@@ -0,0 +1,10 @@
+Test the http_argument_get_*() integer functions.
+
+Run:
+ # kore run
+
+Test:
+ # curl -i -k https://127.0.0.1:8888/?id=123123
+ # curl -i -k https://127.0.0.1:8888/?id=-123123
+
+The correct integer types should only be represented in the output.
diff --git a/examples/integers/conf/integers.conf b/examples/integers/conf/integers.conf
@@ -0,0 +1,17 @@
+# Placeholder configuration
+
+bind 127.0.0.1 8888
+pidfile kore.pid
+load ./integers.so
+
+validator v_id regex ^-?[0-9]*$
+
+domain 127.0.0.1 {
+ certfile cert/server.crt
+ certkey cert/server.key
+ static / page
+
+ params get / {
+ validate id v_id
+ }
+}
diff --git a/examples/integers/src/check_integers.c b/examples/integers/src/check_integers.c
@@ -0,0 +1,47 @@
+#include <kore/kore.h>
+#include <kore/http.h>
+
+int page(struct http_request *);
+
+int
+page(struct http_request *req)
+{
+ int16_t s16;
+ u_int16_t u16;
+ int32_t s32;
+ int64_t s64;
+ u_int64_t u64;
+ struct kore_buf *buf;
+ u_int32_t u32, len;
+ u_int8_t c, *data;
+
+ http_populate_arguments(req);
+ buf = kore_buf_create(128);
+
+ if (http_argument_get_byte("id", &c))
+ kore_buf_appendf(buf, "byte\t%c\n", c);
+
+ if (http_argument_get_int16("id", &s16))
+ kore_buf_appendf(buf, "int16\t%d\n", s16);
+
+ if (http_argument_get_uint16("id", &u16))
+ kore_buf_appendf(buf, "uint16\t%d\n", u16);
+
+ if (http_argument_get_int32("id", &s32))
+ kore_buf_appendf(buf, "int32\t%d\n", s32);
+
+ if (http_argument_get_uint32("id", &u32))
+ kore_buf_appendf(buf, "uint32\t%d\n", u32);
+
+ if (http_argument_get_int64("id", &s64))
+ kore_buf_appendf(buf, "int64\t%ld\n", s64);
+
+ if (http_argument_get_uint64("id", &u64))
+ kore_buf_appendf(buf, "uint64\t%lu\n", u64);
+
+ data = kore_buf_release(buf, &len);
+ http_response(req, 200, data, len);
+ kore_mem_free(data);
+
+ return (KORE_RESULT_OK);
+}