-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdolphin.c
78 lines (61 loc) · 2.15 KB
/
dolphin.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
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <stddef.h>
#include <inttypes.h>
#include <ctype.h>
#include "curl-websocket.h"
#include "debug.h"
#include "dolphin.h"
#define DOLPHIN_MAX_HEADER_PAIRS 100
struct dolphin_request_url {
char *buf; ///< request url buffer
size_t length; ///< request url string length
size_t bufsize; ///< real size occupied in memory by buffer
};
struct dolphin_response_header {
char *buf; ///< response header buffer
size_t length; ///< response header string length
size_t bufsize; ///< real size occupied in memory by buffer
struct { ///< array of header field/value pairs
struct {
uintptr_t idx; ///< offset index of 'buf' for the start of field or value
size_t size; ///< length of individual field or value
} field, value;
} pairs[DOLPHIN_MAX_HEADER_PAIRS];
int size; ///< number of elements initialized in `pairs`
};
struct dolphin_response_body {
char *buf; ///< response body buffer
size_t length; ///< response body string length
size_t bufsize; ///< real size occupied in memory by buffer
};
struct dolphin {
char token[256]; ///< the bot token
/* REST FIELDS */
struct curl_slist *req_header; ///< the request header
CURL *ehandle; ///< the curl's easy handle used to perform requests
CURLM *mhandle; ///< the curl's multiplexer for performing non-blocking requests
CURL *cwshandle; ///< the curl's web socket handler
char errbuf[CURL_ERROR_SIZE]; ///< capture curl error messages
struct dolphin_request_url url; ///< the request url
int httpcode; ///< the response httpcode
struct dolphin_response_header header; ///< the response header
struct dolphin_response_body body; ///< the response body
};
#include "dolphin_dev1.c"
#include "dolphin_dev2.c"
struct dolphin*
dolphin_init(const char token[])
{
struct dolphin *new_client; ///< the client to be created
new_client = calloc(1, sizeof *new_client);
dolphin_adapter_init(new_client, token);
return new_client;
}
void
dolphin_cleanup(struct dolphin *client)
{
dolphin_adapter_cleanup(client);
free(client);
}