-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathckvs_rpc.h
66 lines (59 loc) · 2.16 KB
/
ckvs_rpc.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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/**
* @file ckvs_rpc.h
* @brief client-side RPC using CURL
* @author E Bugnion
*/
#pragma once
#include <curl/curl.h>
/**
* @brief maximal size of the encrypted value. hex-encoded is 2x
*/
#define CKVS_MAX_VALUE_LEN_HTTP_QUERY (14 * 32)
/**
* @brief Holds the client state that represents a connection to a remote CKVS
* server
*/
typedef struct ckvs_connection {
CURL *curl; /**< CURL instance used for the connection */
const char *url; /**< url to the remote server */
char *resp_buf; /**< buffer that will hold the response of the server */
size_t resp_size; /**< size of resp_buf */
} ckvs_connection_t;
/**
* @brief Initializes connection to the remote server at url.
* @param conn (struct ckvs_connection*) the connection to initialize
* @param url (const char*) target URL (string is not copied)
* @return int, error code
*/
int ckvs_rpc_init(struct ckvs_connection *conn, const char *url);
/**
* @brief Cleans up connection to remote server.
* @param conn (struct ckvs_connection*) the connection to cleanup
*/
void ckvs_rpc_close(struct ckvs_connection *conn);
/* *************************************************** *
* TODO WEEK 11 *
* *************************************************** */
/**
* @brief Sends an HTTP GET request to the connected server,
* using the url and GET payload.
*
* @param conn (struct ckvs_connection*) the connection to the server
* @param GET (const char*) the GET payload
* @return int, error code
*/
int ckvs_rpc(struct ckvs_connection *conn, const char *GET);
/* *************************************************** *
* TODO WEEK 13 *
* *************************************************** */
/**
* @brief Sends an HTTP POST request to the connected server,
* using its url, and the GET and POST payloads.
*
* @param conn (struct ckvs_connection*) the connection to the server
* @param GET (const char*) the GET payload. Should already contain the fields
* "name" and "offset".
* @param POST (const char*) the POST payload
* @return int, error code
*/
int ckvs_post(struct ckvs_connection *conn, const char *GET, const char *POST);