diff options
author | Wolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de> | 2013-03-06 21:58:47 +0100 |
---|---|---|
committer | Wolfgang Draxinger <Wolfgang.Draxinger@physik.uni-muenchen.de> | 2013-03-06 21:58:47 +0100 |
commit | dfb3c1ca13a828405503d6ec2ee3979ae825326b (patch) | |
tree | 7f6197650df3f86401eb3e12d23b9266745c5ae9 /picohttp.h | |
download | litheweb-dfb3c1ca13a828405503d6ec2ee3979ae825326b.tar.gz litheweb-dfb3c1ca13a828405503d6ec2ee3979ae825326b.tar.bz2 |
Wed Mar 6 21:58:47 CET 2013
Diffstat (limited to 'picohttp.h')
-rw-r--r-- | picohttp.h | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/picohttp.h b/picohttp.h new file mode 100644 index 0000000..cceee44 --- /dev/null +++ b/picohttp.h @@ -0,0 +1,79 @@ +#pragma once +#ifndef PICOHTTP_H_HEADERGUARD +#define PICOHTTP_H_HEADERGUARD + +#include <stdlib.h> +#include <stdint.h> + +#define PICOHTTP_MAJORVERSION(x) ( (x & 0x7f00) >> 8 ) +#define PICOHTTP_MINORVERSION(x) ( (x & 0x007f) ) + +#define PICOHTTP_METHOD_GET 1 +#define PICOHTTP_METHOD_HEAD 2 +#define PICOHTTP_METHOD_POST 3 + +struct picohttpIoOps { + int (*read)(size_t /*count*/, char* /*buf*/, void*); + int (*write)(size_t /*count*/, char* /*buf*/, void*); + int16_t (*getch)(void*); // returns -1 on error + int (*putch)(char, void*); + void *data; +}; + +#define picohttpIoWrite(ioops,size,buf) (ioops->write(size, buf, ioops->data)) +#define picohttpIoRead(ioops,size,buf) (ioops->read(size, buf, ioops->data)) +#define picohttpIoGetch(ioops) (ioops->getch(ioops->data)) +#define picohttpIoPutch(ioops,c) (ioops->putch(c, ioops->data)) + +enum picohttpVarType { + PICOHTTP_TYPE_UNDEFINED = 0, + PICOHTTP_TYPE_INTEGER = 1, + PICOHTTP_TYPE_REAL = 2, + PICOHTTP_TYPE_BOOLEAN = 3, + PICOHTTP_TYPE_TEXT = 4 +}; + +struct picohttpVarSpec { + char const * const name; + enum picohttpVarType type; + size_t max_len; +}; + +struct picohttpVar { + struct picohttpVarSpec const *spec; + union { + char *text; + float real; + int integer; + uint8_t boolean; + } value; + struct picohttpVar *next; +}; + +struct picohttpRequest; + +typedef void (*picohttpHandler) (struct picohttpRequest *ctx); + +struct picohttpURLRoute { + char const * urlhead; + struct picohttpVarSpec const * get_vars; + picohttpHandler handler; + uint16_t max_urltail_len; + uint8_t allowed_methods; +}; + +struct picohttpRequest { + struct picohttpIoOps const * ioops; + struct picohttpURLRoute *route; + struct picohttpVar *get_vars; + char const *url; + char const *urltail; + int16_t httpversion; + uint8_t method; +}; + +void picohttpProcessRequest( + struct picohttpIoOps const * const ioops, + struct picohttpURLRoute const * const routes ); + +#endif/*PICOHTTP_H_HEADERGUARD*/ |