-
Notifications
You must be signed in to change notification settings - Fork 3
/
socket_utils.h
52 lines (39 loc) · 1.26 KB
/
socket_utils.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
51
52
#ifndef SOCKET_UTILS_H
#define SOCKET_UTILS_H
#ifdef _WIN32
#include <winsock2.h>
#endif
#include <inttypes.h>
#include "BearSSL/inc/bearssl_ssl.h"
#include "rman.h"
#ifndef _WIN32
#define closesocket(socket) close(socket)
typedef int SOCKET;
#endif
typedef struct http_response {
int status_code;
uint32_t length;
uint8_t* data;
} HttpResponse;
typedef struct host_port {
char* host;
const char* port;
int path_offset;
} HostPort;
struct ssl_data {
SOCKET socket;
HostPort* host_port;
br_ssl_client_context ssl_client_context;
uint8_t* io_buffer;
br_sslio_context ssl_io_context;
br_x509_minimal_context x509_client_context;
};
SOCKET __attribute__((warn_unused_result)) open_connection_s(const char* ip, const char* port);
SOCKET __attribute__((warn_unused_result)) open_connection(uint32_t ip, uint16_t port);
uint8_t** get_ranges(const char* path, const ChunkList* chunks);
uint8_t** download_ranges(struct ssl_data* ssl_structs, const char* url, const ChunkList* chunks);
HostPort* get_host_port(const char* url);
HttpResponse* download_url(const char* url);
int send_wrapper(void* client_context, const uint8_t* data, size_t length);
int recv_wrapper(void* client_context, uint8_t* buffer, size_t length);
#endif