A low-key HTTP micro-framework for people who hate web bloat
git clone git://soophie.de/tpee
411
// @desc Get tpee method string.412
const char *_tpee_method_str(tpee_method_t method);414
#ifdef TPEE_IMPL416
#include <stdio.h>417
#include <stdlib.h>418
#include <string.h>419
#include <ctype.h>420
#include <time.h>421
#include <unistd.h>422
#include <pthread.h>423
#include <netdb.h>424
#include <poll.h>425
#include <errno.h>426
#include <signal.h>428
// @macro TPEE_VERSION429
// @internal430
#define TPEE_VERSION "HTTP/1.1"432
// @macro TPEE_MAX_REQUEST_HEAD_SIZE433
// @internal434
#define TPEE_MAX_REQUEST_HEAD_SIZE 1000000414
// @macro TPEE_RESP_HANDLED415
// @group tpee_resp_t416
// @desc Handled {tpee_resp_t}.
480
} \481
static void fn_name(tpee_req_t *req)505
// @global _tpee_routes483
#ifdef TPEE_IMPL485
#include <stdio.h>486
#include <stdlib.h>487
#include <string.h>488
#include <ctype.h>489
#include <time.h>490
#include <unistd.h>491
#include <pthread.h>492
#include <netdb.h>493
#include <poll.h>494
#include <errno.h>495
#include <signal.h>497
// @macro TPEE_VERSION498
// @internal499
#define TPEE_VERSION "HTTP/1.1"501
// @macro TPEE_MAX_REQUEST_HEAD_SIZE502
// @internal507
tpee_route_t *_tpee_routes = NULL;503
#define TPEE_MAX_REQUEST_HEAD_SIZE 1000000509
// @global _tpee_routes_len505
// @global _tpee_route_list506
// @internal511
size_t _tpee_routes_len = 0;507
tpee_route_t *_tpee_route_list = NULL;509
// @global _tpee_route_list_len510
// @internal511
size_t _tpee_route_list_len = 0;513
// @global _tpee_default_route514
// @internal
535
if (_tpee_pre_route != NULL) {536
_tpee_pre_route(req);537
}538
for (size_t i = 0; i < _tpee_routes_len; i++) {539
tpee_route_t *route = &_tpee_routes[i];538
for (size_t i = 0; i < _tpee_route_list_len; i++) {539
tpee_route_t *route = &_tpee_route_list[i];540
const char *method = _tpee_method_str(route->method);541
char *path = tpee_req_path(req);542
if (strcmp(method, req->method) == 0) {
610
if (self->sock != NULL) {611
sock_cleanup(self->sock);612
}613
if (_tpee_routes != NULL && _tpee_routes_len > 0) {614
free(_tpee_routes);615
_tpee_routes = NULL;616
_tpee_routes_len = 0;613
if (_tpee_route_list != NULL && _tpee_route_list_len > 0) {614
for (size_t i = 0; i < _tpee_route_list_len; i++) {615
tpee_route_t *route = &_tpee_route_list[i];616
if (route->path) free(route->path);617
}618
free(_tpee_route_list);619
_tpee_route_list = NULL;620
_tpee_route_list_len = 0;621
}622
free(self);623
}
630
// @impl tpee_on_route631
void tpee_on_route(tpee_method_t method, char *path, tpee_handle_fn_t fn) {628
_tpee_routes = realloc(_tpee_routes, sizeof(tpee_route_t) * (_tpee_routes_len + 1));629
_tpee_routes[_tpee_routes_len] = (tpee_route_t) {632
_tpee_route_list = realloc(_tpee_route_list, sizeof(tpee_route_t) * (_tpee_route_list_len + 1));633
_tpee_route_list[_tpee_route_list_len] = (tpee_route_t) {634
.method = method,631
.path = path,635
.path = strdup(path),636
.fn = fn,637
};634
_tpee_routes_len++;638
_tpee_route_list_len++;639
}641
// @impl tpee_on_default
813
}814
}812
// @func _tpee_method_str813
// @internal816
// @impl _tpee_method_str817
const char *_tpee_method_str(tpee_method_t method) {818
switch (method) {819
case TPEE_METHOD_GET: