#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include "contiki-net.h"
#include "websocket-http-client.h"
#include "cfs/cfs.h"
#include "lib/petsciiconv.h"
#include "mdns.h"
#include "websocket.h"
#include "net/ip/uip-debug.h"
Data Structures | |
struct | websocket_frame_hdr |
struct | websocket_frame_mask |
Macros | |
#define | _DEBUG_ DEBUG_NONE |
#define | MAX_HOSTLEN 16 |
#define | MAX_PATHLEN 100 |
#define | MIN(a, b) ((a) < (b)? (a): (b)) |
#define | WEBSOCKET_FIN_BIT 0x80 |
#define | WEBSOCKET_LEN_MASK 0x7f |
#define | WEBSOCKET_MASK_BIT 0x80 |
#define | WEBSOCKET_OPCODE_BIN 0x02 |
#define | WEBSOCKET_OPCODE_CLOSE 0x08 |
#define | WEBSOCKET_OPCODE_CONT 0x00 |
#define | WEBSOCKET_OPCODE_MASK 0x0f |
#define | WEBSOCKET_OPCODE_PING 0x09 |
#define | WEBSOCKET_OPCODE_PONG 0x0a |
#define | WEBSOCKET_OPCODE_TEXT 0x01 |
Functions | |
static void | call (struct websocket *s, websocket_result r, uint8_t *data, uint16_t datalen) |
LIST (websocketlist) | |
static int | parse_url (const char *url, char *host, uint16_t *portptr, char *path) |
PROCESS (websocket_process,"Websockets process") | |
PROCESS_THREAD (websocket_process, ev, data) | |
static int | receive_header_byte (struct websocket *s, uint8_t byte) |
static int | send_data (struct websocket *s, const void *data, uint16_t datalen, uint8_t data_type_opcode) |
static int | start_get (struct websocket *s) |
void | websocket_close (struct websocket *s) |
void | websocket_http_client_aborted (struct websocket_http_client_state *client_state) |
void | websocket_http_client_closed (struct websocket_http_client_state *client_state) |
void | websocket_http_client_connected (struct websocket_http_client_state *client_state) |
void | websocket_http_client_datahandler (struct websocket_http_client_state *client_state, uint8_t *data, uint16_t datalen) |
void | websocket_http_client_timedout (struct websocket_http_client_state *client_state) |
void | websocket_init (void) |
websocket_result | websocket_open (struct websocket *s, const char *url, const char *subprotocol, websocket_callback c) |
int | websocket_ping (struct websocket *s) |
int | websocket_send (struct websocket *s, const uint8_t *data, uint16_t datalen) |
int | websocket_send_str (struct websocket *s, const char *str) |
Variables | |
static uint8_t | inited = 0 |
#define _DEBUG_ DEBUG_NONE |
#define MAX_HOSTLEN 16 |
Referenced by parse_url(), PROCESS_THREAD(), and start_get().
#define MAX_PATHLEN 100 |
Referenced by parse_url(), and start_get().
#define MIN | ( | a, | |
b | |||
) | ((a) < (b)? (a): (b)) |
Referenced by websocket_http_client_datahandler().
#define WEBSOCKET_FIN_BIT 0x80 |
Referenced by send_data(), and websocket_ping().
#define WEBSOCKET_LEN_MASK 0x7f |
Referenced by receive_header_byte(), and websocket_http_client_datahandler().
#define WEBSOCKET_MASK_BIT 0x80 |
Referenced by receive_header_byte(), send_data(), websocket_http_client_datahandler(), and websocket_ping().
#define WEBSOCKET_OPCODE_BIN 0x02 |
Referenced by websocket_http_client_datahandler(), and websocket_send().
#define WEBSOCKET_OPCODE_CLOSE 0x08 |
Referenced by websocket_http_client_datahandler().
#define WEBSOCKET_OPCODE_CONT 0x00 |
#define WEBSOCKET_OPCODE_MASK 0x0f |
Referenced by websocket_http_client_datahandler().
#define WEBSOCKET_OPCODE_PING 0x09 |
Referenced by websocket_http_client_datahandler(), and websocket_ping().
#define WEBSOCKET_OPCODE_PONG 0x0a |
Referenced by websocket_http_client_datahandler().
#define WEBSOCKET_OPCODE_TEXT 0x01 |
Referenced by websocket_http_client_datahandler(), and websocket_send_str().
|
static |
LIST | ( | websocketlist | ) |
|
static |
References http_http, http_ws, i, MAX_HOSTLEN, MAX_PATHLEN, NULL, port, and strncpy().
Referenced by PROCESS_THREAD(), and start_get().
PROCESS | ( | websocket_process | , |
"Websockets process" | |||
) |
PROCESS_THREAD | ( | websocket_process | , |
ev | , | ||
data | |||
) |
References call(), data, list_head(), list_item_next(), MAX_HOSTLEN, mdns_event_found, mdns_lookup(), NULL, parse_url(), PRINTF, PROCESS_BEGIN, PROCESS_END, PROCESS_WAIT_EVENT, s, start_get(), websocket::state, tcpip_event, websocket::url, WEBSOCKET_HOSTNAME_NOT_FOUND, websocket_http_client_appcall(), and WEBSOCKET_STATE_DNS_REQUEST_SENT.
|
static |
|
static |
References websocket_frame_hdr::extlen, websocket_frame_hdr::len, websocket_frame_mask::mask, websocket_frame_hdr::opcode, PRINTF, websocket::s, websocket::state, WEBSOCKET_FIN_BIT, websocket_http_client_send(), websocket_http_client_sendbuflen(), WEBSOCKET_MASK_BIT, WEBSOCKET_STATE_CLOSED, WEBSOCKET_STATE_DNS_REQUEST_SENT, and WEBSOCKET_STATE_HTTP_REQUEST_SENT.
|
static |
References addr, MAX_HOSTLEN, MAX_PATHLEN, mdns_lookup(), mdns_query(), NULL, parse_url(), port, PRINTF, websocket::s, websocket::state, websocket::subprotocol, uiplib_ip4addrconv(), uiplib_ip6addrconv(), websocket::url, WEBSOCKET_ERR, websocket_http_client_get(), WEBSOCKET_OK, WEBSOCKET_STATE_CLOSED, WEBSOCKET_STATE_DNS_REQUEST_SENT, and WEBSOCKET_STATE_HTTP_REQUEST_SENT.
Referenced by PROCESS_THREAD(), and websocket_open().
void websocket_close | ( | struct websocket * | s | ) |
References websocket::s, websocket::state, WEBSOCKET_CLOSED, and websocket_http_client_close().
Referenced by receive_header_byte(), and websocket_open().
void websocket_http_client_aborted | ( | struct websocket_http_client_state * | client_state | ) |
References call(), NULL, PRINTF, s, websocket::state, WEBSOCKET_RESET, and WEBSOCKET_STATE_CLOSED.
Referenced by parse_statusline(), and websocket_http_client_appcall().
void websocket_http_client_closed | ( | struct websocket_http_client_state * | client_state | ) |
References call(), NULL, PRINTF, s, websocket::state, WEBSOCKET_CLOSED, and WEBSOCKET_STATE_CLOSED.
Referenced by websocket_http_client_appcall().
void websocket_http_client_connected | ( | struct websocket_http_client_state * | client_state | ) |
References call(), NULL, PRINTF, s, websocket::state, WEBSOCKET_CONNECTED, and WEBSOCKET_STATE_WAITING_FOR_HEADER.
Referenced by acked().
void websocket_http_client_datahandler | ( | struct websocket_http_client_state * | client_state, |
uint8_t * | data, | ||
uint16_t | datalen | ||
) |
References call(), websocket_frame_hdr::extlen, websocket::headercache, websocket::headercacheptr, websocket_frame_hdr::len, websocket::len, len, websocket_frame_mask::mask, websocket::mask, MIN, NULL, websocket_frame_hdr::opcode, websocket::opcode, PRINTF, receive_header_byte(), websocket::s, s, websocket::state, WEBSOCKET_CLOSED, WEBSOCKET_DATA, WEBSOCKET_DATA_RECEIVED, websocket_http_client_close(), websocket_http_client_datahandler(), websocket_http_client_send(), WEBSOCKET_LEN_MASK, WEBSOCKET_MASK_BIT, WEBSOCKET_OPCODE_BIN, WEBSOCKET_OPCODE_CLOSE, WEBSOCKET_OPCODE_MASK, WEBSOCKET_OPCODE_PING, WEBSOCKET_OPCODE_PONG, WEBSOCKET_OPCODE_TEXT, WEBSOCKET_PINGED, WEBSOCKET_PONG_RECEIVED, WEBSOCKET_STATE_HEADER_RECEIVED, WEBSOCKET_STATE_RECEIVING_DATA, WEBSOCKET_STATE_RECEIVING_HEADER, and WEBSOCKET_STATE_WAITING_FOR_HEADER.
Referenced by newdata(), websocket_http_client_appcall(), and websocket_http_client_datahandler().
void websocket_http_client_timedout | ( | struct websocket_http_client_state * | client_state | ) |
References call(), NULL, PRINTF, s, websocket::state, WEBSOCKET_STATE_CLOSED, and WEBSOCKET_TIMEDOUT.
Referenced by websocket_http_client_appcall().
void websocket_init | ( | void | ) |
References inited, list_init(), NULL, and process_start().
Referenced by websocket_open().
websocket_result websocket_open | ( | struct websocket * | s, |
const char * | url, | ||
const char * | subprotocol, | ||
websocket_callback | c | ||
) |
References c, websocket::callback, inited, list_add(), NULL, PRINTF, PROCESS_CONTEXT_BEGIN, PROCESS_CONTEXT_END, ret, start_get(), websocket::state, strncpy(), websocket::subprotocol, websocket::url, websocket_close(), WEBSOCKET_CONF_MAX_SUBPROTOLEN, WEBSOCKET_ERR, websocket_init(), WEBSOCKET_MAX_URLLEN, and WEBSOCKET_STATE_CLOSED.
int websocket_ping | ( | struct websocket * | s | ) |
int websocket_send | ( | struct websocket * | s, |
const uint8_t * | data, | ||
uint16_t | datalen | ||
) |
References send_data, and WEBSOCKET_OPCODE_BIN.
int websocket_send_str | ( | struct websocket * | s, |
const char * | str | ||
) |
References send_data, and WEBSOCKET_OPCODE_TEXT.
|
static |
Referenced by init(), websocket_init(), and websocket_open().