about summary refs log tree commit diff
path: root/smalldog/README.md
blob: 87d341633e6d08d37d17245469a4485439a4cea6 (plain)
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
smalldog

a crate for safely working with corgi's cgi module system.

module's are loaded in a new thread at the time of request.

if you want to build a module in C, these structs will be of use:
```c
// In Rust this is interpreted as a fixed size, 2-element array of char*
// but i cannot get C to like that kind of at all. sorry.
struct pair {
	char *name;
	char *value;
};

// The request from corgi. body may be null if one was not sent.
struct request {
	u64_t headers_len;
	struct pair *headers;
	u64_t body_len;
	u8_t *body;
};

// The request your module should return to corgi
struct response {
	u16_t status;
	u64_t headers_len;
	struct pair *headers;
	u64_t body_len;
	u8_t *body;
};
```

as well as that, there are two functions that corgi expects to exist and will call.

`struct response *handle(struct request*);`  
this function is called after the module is loaded. here you should process the
request and send back a response. be sure to keep track of any allocations so
you can clean them up later.

`void cleanup(struct response*);`  
this is where you clean up, later. function is called after corgi copies all
required data to an internal structure. free memory here.