forked from riolet/WAFer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnopeutils.h
95 lines (75 loc) · 3.23 KB
/
nopeutils.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#ifndef NOPEUTILS_H_
#define NOPEUTILS_H_
/* ENTL */
#define STR(X) #X
#define WSPC " "
#define CRLF "\r\n"
#define ATTR(key,value) STR(key) STR(=) STR(value)
#define LT(tag) STR(<) STR(tag) WSPC /*<tag */
#define LTA(tag,attributes) LT(tag) STR(attributes) WSPC /*<tag */
#define GT STR(>) /*<*/
#define OTAG(tag) LT(tag) GT /*<tag>*/
#define OTAGA(tag,attributes) LTA(tag,attributes) GT /*<tag attributes>*/
#define CTAG(tag) STR(</) STR(tag) GT /*</tag>*/
#define ESTAG(tag) LT(tag) WSPC STR(/) GT /*<tag attributes /> */
#define STAG(tag,attributes) LTA(tag,attributes) WSPC STR(/) GT /*<tag attributes /> */
#define QTAG(tag,text) OTAG(tag) text CTAG(tag) /*<tag> text </tag>*/
#define QTAGA(tag,attributes,text) OTAGA(tag,attributes) text CTAG(tag) /*<tag attributes> text </tag>*/
/* Extensions */
#define QLINK(url,text) QTAGA(a,href=url,text)
#define QLINKA(url,attributes,text) QTAGA(a,href=url attributes,text)
#define QIMG(srcurl) STAG(img,src=srcurl)
#define QIMGA(srcurl) STAG(img,src=srcurl attributes)
#define QBR ESTAG(br)
/* End ENTL */
#define MVHP_OPEN(l,c,t,h) LT(!DOCTYPE html) GT CRLF\
LT(html) STR(lang=l) GT CRLF\
OTAG(head)\
STAG(meta, charset=c) CRLF\
QTAG(title,t) CRLF\
h CRLF\
CTAG(head) CRLF\
OTAG(body) CRLF
#define MVHPEN8(t,h) MVHP_OPEN("en","utf-8",t,h)
#define HP_CLOSE CRLF CTAG(body) CRLF CTAG(html)
#include <stdarg.h>
char ** readHeaders(int);
void freeHeaders(char **);
int getLine(int, char *, int);
void notFound(int);
void docwrite(int,const char*);
long nprintf (int, const char *, ...);
char ** sendAndReceiveHeaders(int);
char * getQueryPath(const char *);
char * getQueryParam(const char *, const char *);
void writeStandardHeaders(int);
long writeLongString(int,const char*);
void serveFile(int, const char *, const char *);
char * dupstr (const char *);
char * _hscan(int client, const char * reqStr, const char *msg,const char *inputstr);
char * _hscanIfEmpty(int client, const char * reqStr, const char *msg,const char * inputstr);
#define STAGPARAMQ(tag,attributes) LTA(tag,attributes) ATTR(name,STR(q)) WSPC STR(/) GT /*<tag attributes name="q" /> */
#define QTAGAPARAMQ(tag,attributes,text) OTAGA(tag,attributes name=STR(q)) text CTAG(tag) /*<tag attributes> text </tag>*/
#define HSCANIT(client,reqStr,msg) _hscan(client,reqStr,msg,STAGPARAMQ(input,type="text"))
#define HSCANITIE(client,reqStr,msg) _hscanIfEmpty(client,reqStr,msg,STAGPARAMQ(input,type="text"))
#define HSCAN(client,reqStr,msg,tag,attributes,text) _hscan(client,reqStr,msg,QTAGAPARAMQ(tag,attributes,text))
#define SERVER_STRING "Server: nope.chttpd/0.1.0\r\n"
#define ToHex(Y) (Y>='0'&&Y<='9'?Y-'0':Y-'A'+10)
#define UNDEFINED "VALUE_UNDEFINED"
#define MAX_HEADERS 1024
#define MAX_BUFFER_SIZE 1024
#define MAX_DPRINTF_SIZE 64
#define true 1
#define false 0
typedef int bool;
typedef struct struct_request Request;
struct struct_request {
int client;
const char * reqStr;
const char * method;
};
bool route(Request request, const char * path);
bool routef(Request request, const char * path, void (* function)(int,char *, char*));
bool routeh(Request request, const char * path);
bool routefh(Request request, const char * path, void (* function)(int,char *, char*));
#endif /* NOPEUTILS_H_ */