ncdc/libdc/include/dc/gateway.h

64 lines
1.4 KiB
C
Raw Normal View History

2019-07-08 23:29:08 +02:00
#ifndef DC_GATEWAY_H
#define DC_GATEWAY_H
#include <stdint.h>
#include <stdlib.h>
#include <dc/account.h>
#include <curl/curl.h>
struct dc_gateway_;
typedef struct dc_gateway_ *dc_gateway_t;
typedef enum {
2019-07-09 21:46:17 +02:00
GATEWAY_OPCODE_EVENT = 0,
2019-07-09 21:44:23 +02:00
GATEWAY_OPCODE_PING = 1,
2019-07-08 23:29:08 +02:00
GATEWAY_OPCODE_IDENTIFY = 2,
2019-07-09 21:44:23 +02:00
GATEWAY_OPCODE_UPDATE = 3,
2019-07-08 23:29:08 +02:00
GATEWAY_OPCODE_HELLO = 10,
2019-07-09 21:44:23 +02:00
GATEWAY_OPCODE_PONG = 11,
2019-07-08 23:29:08 +02:00
} dc_gateway_opcode_t;
2019-07-09 21:44:23 +02:00
typedef enum {
GATEWAY_FRAME_TEXT_DATA = 129,
GATEWAY_FRAME_DISCONNECT = 136,
GATEWAY_FRAME_PING = 137,
GATEWAY_FRAME_PONG = 138,
} dc_gateway_frames_t;
2019-07-08 23:29:08 +02:00
dc_gateway_t dc_gateway_new(void);
void dc_gateway_set_login(dc_gateway_t gw, dc_account_t login);
2019-07-09 21:44:23 +02:00
bool dc_gateway_connect(dc_gateway_t gw);
2019-07-08 23:29:08 +02:00
/**
2019-07-09 21:44:23 +02:00
* Cleans up the easy handle, and thus disconnects from the socket handle
* immediately. After this call dc_gateway_connected() will return false.
2019-07-08 23:29:08 +02:00
*/
2019-07-09 21:44:23 +02:00
void dc_gateway_disconnect(dc_gateway_t gw);
2019-07-08 23:29:08 +02:00
/**
2019-07-09 21:44:23 +02:00
* Returns true if the gateway is still connected.
2019-07-08 23:29:08 +02:00
*/
2019-07-09 21:44:23 +02:00
bool dc_gateway_connected(dc_gateway_t gw);
2019-07-08 23:29:08 +02:00
/**
* Process the queue of data that came from the websocket.
*/
void dc_gateway_process(dc_gateway_t gw);
/**
* utility function to make a websocket frame
*/
uint8_t *
dc_gateway_makeframe(uint8_t const *d, size_t data_len,
uint8_t type, size_t *outlen);
2019-07-09 21:44:23 +02:00
size_t
dc_gateway_parseframe(uint8_t const *data, size_t datalen,
uint8_t *type, uint8_t **outdata, size_t *outlen);
2019-07-08 23:29:08 +02:00
#endif