-
Notifications
You must be signed in to change notification settings - Fork 39
/
http.h
50 lines (37 loc) · 1.8 KB
/
http.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
#ifndef __HTTP_H__
#define __HTTP_H__
#include <sodium.h>
#include "merkle_tree.h"
#include "network.h"
typedef struct {
uint8_t signature[crypto_sign_BYTES];
char sign[sizeof("sign") - 1];
char timestamp[sizeof("2011-10-08T07:07:09Z") - 1];
uint8_t content_hash[crypto_generichash_BYTES];
} PACKED content_sig;
typedef struct evkeyval evkeyval;
typedef struct evkeyvalq evkeyvalq;
typedef struct evhttp_uri evhttp_uri;
typedef struct evhttp_request evhttp_request;
typedef struct evhttp_connection evhttp_connection;
typedef enum evhttp_cmd_type evhttp_cmd_type;
typedef enum evhttp_request_error evhttp_request_error;
DEFINE_TRIVIAL_CLEANUP_FUNC(evhttp_uri*, evhttp_uri_free)
#define evhttp_uri_auto_free __attribute__((__cleanup__(evhttp_uri_freep)))
bool http_setup(network *n);
void join_url_swarm(network *n, const char *url);
void fetch_url_swarm(network *n, const char *url);
const char* evhttp_method(evhttp_cmd_type type);
const char* evhttp_request_error_str(evhttp_request_error error);
int get_port_for_scheme(const char *scheme);
void overwrite_kv_header(evkeyvalq *out, const char *key, const char *value);
void overwrite_header(evhttp_request *to, const char *key, const char *value);
void copy_header(evhttp_request *from, evhttp_request *to, const char *key);
void copy_all_headers(evhttp_request *from, evhttp_request *to);
void hash_headers(evkeyvalq *in, crypto_generichash_state *content_state);
void hash_request(evhttp_request *req, evkeyvalq *hdrs, crypto_generichash_state *content_state);
void merkle_tree_hash_request(merkle_tree *m, evhttp_request *req, evkeyvalq *hdrs);
evbuffer* build_request_buffer(int response_code, evkeyvalq *hdrs);
evhttp_connection *make_connection(network *n, const evhttp_uri *uri);
void return_connection(evhttp_connection *evcon);
#endif // __HTTP_H__