-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcli.c
More file actions
75 lines (53 loc) · 1.43 KB
/
cli.c
File metadata and controls
75 lines (53 loc) · 1.43 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <string.h>
#include <re.h>
#include "http.h"
static void signal_handler(int sig)
{
re_printf("terminating on signal %d...\n", sig);
re_cancel();
}
static void http_done(struct request *req, int code, void *arg) {
if(code==200)
re_printf("%r\n", http_data(req));
else
re_printf("HTTP %d\n", code); // XXX: STDERR
re_cancel();
// Event loop already stopped so CLOSE event
// would not fire and request not freed.
// Don`t do so in non-cli programms
mem_deref(req);
}
static void http_err(int err, void *arg) {
re_printf("Connection error %d\n", err);
re_cancel();
}
int main(int argc, char *argv[])
{
int err;
struct httpc app;
err = libre_init();
char k[] = "user.cert";
err = tls_alloc(&app.tls, TLS_METHOD_SSLV23, k, NULL);
tls_add_ca(app.tls, "ca.cert");
re_printf("enter loop\n");
struct sa nsv[16];
uint32_t nsc = ARRAY_SIZE(nsv);
err = dns_srv_get(NULL, 0, nsv, &nsc);
err = dnsc_alloc(&app.dnsc, NULL, nsv, nsc);
struct request *request;
http_init(&app, &request, "https://texr.enodev.org/api/contacts");
http_cb(request, NULL, http_done, http_err);
http_send(request);
err = re_main(signal_handler);
goto out;
fail:
re_printf("failed\n");
out:
re_printf("exit\n");
mem_deref(app.dnsc);
mem_deref(app.tls);
libre_close();
/* check for memory leaks */
tmr_debug();
mem_debug();
}