This repository has been archived by the owner on Sep 24, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
http.c
85 lines (63 loc) · 1.55 KB
/
http.c
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
/**
* \file
*
* \internal
*/
#include "config.h"
#include <assert.h>
#include <stdlib.h>
#include <nyanttp/ny.h>
#include <nyanttp/expect.h>
#include <nyanttp/http.h>
int ny_http_init(struct ny_http *restrict http,
struct ny *restrict ny) {
assert(http);
assert(ny);
int _;
int status = -1;
http->data = NULL;
status = 0;
exit:
return status;
}
int ny_http_con_init(struct ny_http_con *restrict con,
struct ny_http *restrict http) {
assert(con);
assert(http);
con->data = NULL;
con->http = http;
con->buffer = NULL;
con->offset = 0;
con->length = 0;
}
void ny_http_con_readable(struct ny_http_con *restrict con) {
assert(con);
/* FIXME: Pass body through */
/* Resize buffer if necessary */
if (con->length - con->offset <= con->length / 4) {
size_t length = con->length ? 2 * con->length : 512;
/* FIXME: Error if request too large */
uint8_t *buffer = realloc(con->buffer, length);
if (unlikely(!buffer)) {
/* TODO: Handle error */
}
con->buffer = buffer;
con->length = length;
}
size_t rlen = con->http->recv(con->ctx, con->buffer + con->offset,
con->length - con->offset);
if (unlikely(rlen < 0)) {
/* TODO: Handle error */
}
con->offset += rlen;
/* TODO: Parse data */
}
void ny_http_con_writable(struct ny_http_con *restrict con) {
}
ssize_t ny_http_req_recv(struct ny_http_req *restrict req,
void *restrict buffer, size_t length) {
/* TODO: Get partial body from buffer and pass the rest through */
}
ssize_t ny_http_req_send(struct ny_http_req *restrict req,
void const *restrict buffer, size_t length) {
}