shttp

A small http server written in C

git clone git://git.janzachar.dev/shttp.git


0#include "super.h"
1#include <string.h>
2#include <stdlib.h>
3
4void header_push(struct hs *hs, const char *key, const char *value)
5{
6	if (hs->head == hs->size) {
7		hs->size += HEADER_BLOCK;
8		hs->item = (struct header*)realloc(hs->item, sizeof(struct header) * hs->size);
9	}
10
11	hs->item[hs->head].key = key;
12	hs->item[hs->head].value = value;
13	hs->head++;
14}
15
16const char *header_find(struct hs *hs, const char *key)
17{
18	for (int i = 0; i < hs->head; i++)
19		if (!strcmp(hs->item[i].key, key))
20			return hs->item[i].value;
21	
22	return NULL;
23}
24
25
26struct header header_pop(struct hs *hs)
27{
28	if (!hs->head) return (struct header){NULL, NULL};
29	return hs->item[--hs->head];
30}
31
32void header_free(struct hs *hs) {
33	free(hs->item);
34}
35