123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201 |
- #ifndef ZEPHYR_INCLUDE_NET_WEBSOCKET_H_
- #define ZEPHYR_INCLUDE_NET_WEBSOCKET_H_
- #include <kernel.h>
- #include <net/net_ip.h>
- #include <net/http_parser.h>
- #include <net/http_client.h>
- #ifdef __cplusplus
- extern "C" {
- #endif
- #define WEBSOCKET_FLAG_FINAL 0x00000001
- #define WEBSOCKET_FLAG_TEXT 0x00000002
- #define WEBSOCKET_FLAG_BINARY 0x00000004
- #define WEBSOCKET_FLAG_CLOSE 0x00000008
- #define WEBSOCKET_FLAG_PING 0x00000010
- #define WEBSOCKET_FLAG_PONG 0x00000020
- enum websocket_opcode {
- WEBSOCKET_OPCODE_CONTINUE = 0x00,
- WEBSOCKET_OPCODE_DATA_TEXT = 0x01,
- WEBSOCKET_OPCODE_DATA_BINARY = 0x02,
- WEBSOCKET_OPCODE_CLOSE = 0x08,
- WEBSOCKET_OPCODE_PING = 0x09,
- WEBSOCKET_OPCODE_PONG = 0x0A,
- };
- typedef int (*websocket_connect_cb_t)(int ws_sock, struct http_request *req,
- void *user_data);
- struct websocket_request {
-
- const char *host;
-
- const char *url;
-
- http_header_cb_t optional_headers_cb;
-
- const char **optional_headers;
-
- websocket_connect_cb_t cb;
-
- const struct http_parser_settings *http_cb;
-
- uint8_t *tmp_buf;
-
- size_t tmp_buf_len;
- };
- int websocket_connect(int http_sock, struct websocket_request *req,
- int32_t timeout, void *user_data);
- int websocket_send_msg(int ws_sock, const uint8_t *payload, size_t payload_len,
- enum websocket_opcode opcode, bool mask, bool final,
- int32_t timeout);
- int websocket_recv_msg(int ws_sock, uint8_t *buf, size_t buf_len,
- uint32_t *message_type, uint64_t *remaining,
- int32_t timeout);
- int websocket_disconnect(int ws_sock);
- #if defined(CONFIG_WEBSOCKET_CLIENT)
- void websocket_init(void);
- #else
- static inline void websocket_init(void)
- {
- }
- #endif
- #ifdef __cplusplus
- }
- #endif
- #endif
|