forked from aarond10/https_dns_proxy
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhttps_client.h
More file actions
59 lines (42 loc) · 1.42 KB
/
https_client.h
File metadata and controls
59 lines (42 loc) · 1.42 KB
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
#ifndef _HTTPS_CLIENT_H_
#define _HTTPS_CLIENT_H_
#include <curl/curl.h>
#include "options.h"
#include "stat.h"
#define MAX_TOTAL_CONNECTIONS 8
// Callback type for receiving data when a transfer finishes.
typedef void (*https_response_cb)(void *data, char *buf, size_t buflen);
// Internal: Holds state on an individual transfer.
struct https_fetch_ctx {
CURL *curl;
char curl_errbuf[CURL_ERROR_SIZE];
uint16_t id;
https_response_cb cb;
void *cb_data;
char *buf;
size_t buflen;
struct https_fetch_ctx *next;
};
// Holds state on the whole multiplexed CURL machine.
typedef struct {
struct ev_loop *loop;
CURLM *curlm;
struct curl_slist *header_list;
struct https_fetch_ctx *fetches;
ev_timer timer;
ev_io io_events[MAX_TOTAL_CONNECTIONS];
int still_running;
options_t *opt;
stat_t *stat;
} https_client_t;
void https_client_init(https_client_t *c, options_t *opt,
stat_t *stat, struct ev_loop *loop);
void https_client_fetch(https_client_t *c, const char *url,
const char* postdata, size_t postdata_len,
struct curl_slist *resolv, uint16_t id,
https_response_cb cb, void *data);
// Used to reset state of libcurl because streaming connections + IP changes
// seem to cause curl to flip out.
void https_client_reset(https_client_t *c);
void https_client_cleanup(https_client_t *c);
#endif // _HTTPS_CLIENT_H_