Concord - C Discord API library
A Discord API wrapper library written in C
curl-websocket.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2016 Gustavo Sverzut Barbieri
3 *
4 * Permission is hereby granted, free of charge, to any person
5 * obtaining a copy of this software and associated documentation
6 * files (the "Software"), to deal in the Software without
7 * restriction, including without limitation the rights to use, copy,
8 * modify, merge, publish, distribute, sublicense, and/or sell copies
9 * of the Software, and to permit persons to whom the Software is
10 * furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19 * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20 * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 * SOFTWARE.
23 */
24/* c-mode: linux-4 */
25
26#ifndef _CURL_WEBSOCKET_H_
27#define _CURL_WEBSOCKET_H_ 1
28
29#include <curl/curl.h>
30#include <string.h>
31#include <stdbool.h>
32
33#ifdef __cplusplus
34extern "C" {
35#endif
36
37/* see https://tools.ietf.org/html/rfc6455#section-7.4.1 */
54};
55
63 void (*on_connect)(void *data, CURL *easy, const char *websocket_protocols);
71 void (*on_text)(void *data, CURL *easy, const char *text, size_t len);
75 void (*on_binary)(void *data, CURL *easy, const void *mem, size_t len);
82 void (*on_ping)(void *data, CURL *easy, const char *reason, size_t len);
86 void (*on_pong)(void *data, CURL *easy, const char *reason, size_t len);
93 void (*on_close)(void *data, CURL *easy, enum cws_close_reason reason, const char *reason_text, size_t reason_text_len);
94 const void *data;
95};
96
121CURL *cws_new(const char *url, const char *websocket_protocols, const struct cws_callbacks *callbacks);
122
126void cws_free(CURL *easy);
127
145bool cws_send(CURL *easy, bool text, const void *msg, size_t msglen);
146
150static inline bool cws_send_binary(CURL *easy, const void *msg, size_t msglen) {
151 return cws_send(easy, false, msg, msglen);
152}
153
158static inline bool cws_send_text(CURL *easy, const char *string) {
159 return cws_send(easy, true, string, strlen(string));
160}
161
171bool cws_ping(CURL *easy, const char *reason, size_t len);
172
185bool cws_pong(CURL *easy, const char *reason, size_t len);
186
198bool cws_close(CURL *easy, enum cws_close_reason reason, const char *reason_text, size_t reason_text_len);
199
207void cws_add_header(CURL *easy, const char field[], const char value[]);
208
209#ifdef __cplusplus
210}
211#endif
212
213#endif
void cws_add_header(CURL *easy, const char field[], const char value[])
void cws_free(CURL *easy)
CURL * cws_new(const char *url, const char *websocket_protocols, const struct cws_callbacks *callbacks)
bool cws_close(CURL *easy, enum cws_close_reason reason, const char *reason_text, size_t reason_text_len)
bool cws_ping(CURL *easy, const char *reason, size_t len)
bool cws_pong(CURL *easy, const char *reason, size_t len)
bool cws_send(CURL *easy, bool text, const void *msg, size_t msglen)
cws_close_reason
Definition: curl-websocket.h:38
@ CWS_CLOSE_REASON_NORMAL
Definition: curl-websocket.h:39
@ CWS_CLOSE_REASON_PROTOCOL_ERROR
Definition: curl-websocket.h:41
@ CWS_CLOSE_REASON_MISSING_EXTENSION
Definition: curl-websocket.h:48
@ CWS_CLOSE_REASON_GOING_AWAY
Definition: curl-websocket.h:40
@ CWS_CLOSE_REASON_POLICY_VIOLATION
Definition: curl-websocket.h:46
@ CWS_CLOSE_REASON_TOO_BIG
Definition: curl-websocket.h:47
@ CWS_CLOSE_REASON_SERVER_ERROR
Definition: curl-websocket.h:49
@ CWS_CLOSE_REASON_INCONSISTENT_DATA
Definition: curl-websocket.h:45
@ CWS_CLOSE_REASON_IANA_REGISTRY_END
Definition: curl-websocket.h:51
@ CWS_CLOSE_REASON_IANA_REGISTRY_START
Definition: curl-websocket.h:50
@ CWS_CLOSE_REASON_NO_REASON
Definition: curl-websocket.h:43
@ CWS_CLOSE_REASON_ABRUPTLY
Definition: curl-websocket.h:44
@ CWS_CLOSE_REASON_PRIVATE_END
Definition: curl-websocket.h:53
@ CWS_CLOSE_REASON_UNEXPECTED_DATA
Definition: curl-websocket.h:42
@ CWS_CLOSE_REASON_PRIVATE_START
Definition: curl-websocket.h:52
Definition: curl-websocket.h:56
void(* on_close)(void *data, CURL *easy, enum cws_close_reason reason, const char *reason_text, size_t reason_text_len)
Definition: curl-websocket.h:93
void(* on_ping)(void *data, CURL *easy, const char *reason, size_t len)
Definition: curl-websocket.h:82
void(* on_connect)(void *data, CURL *easy, const char *websocket_protocols)
Definition: curl-websocket.h:63
void(* on_text)(void *data, CURL *easy, const char *text, size_t len)
Definition: curl-websocket.h:71
const void * data
Definition: curl-websocket.h:94
void(* on_binary)(void *data, CURL *easy, const void *mem, size_t len)
Definition: curl-websocket.h:75
void(* on_pong)(void *data, CURL *easy, const char *reason, size_t len)
Definition: curl-websocket.h:86