ABI
Tracker

(libwebsockets)




Headers diff: 1.5.1 vs 1.6.1



 libwebsockets.h (1.5.1)   libwebsockets.h (1.6.1) 
skipping to change at line 28 skipping to change at line 28
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
* MA 02110-1301 USA * MA 02110-1301 USA
*/ */
#ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C #ifndef LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
#define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C #define LIBWEBSOCKET_H_3060898B846849FF9F88F5DB59B5950C
#ifdef __cplusplus #ifdef __cplusplus
#include <cstddef> #include <cstddef>
#include <cstdarg> #include <cstdarg>
#ifdef MBED_OPERATORS
#include "mbed-drivers/mbed.h"
#include "sal-iface-eth/EthernetInterface.h"
#include "sockets/TCPListener.h"
#include "sal-stack-lwip/lwipv4_init.h"
namespace {
const int SERVER_PORT = 80;
const int BUFFER_SIZE = 4096;
}
using namespace mbed::Sockets::v0;
struct lws;
struct lws_context;
class lws_conn {
public:
lws_conn():
ts(NULL),
wsi(NULL),
writeable(1),
awaiting_on_writeable(0)
{
}
public:
void set_wsi(struct lws *_wsi) { wsi = _wsi; }
int actual_onRX(Socket *s);
void onRX(Socket *s);
void onError(Socket *s, socket_error_t err);
void onDisconnect(TCPStream *s);
void onSent(Socket *s, uint16_t len);
void serialized_writeable(struct lws *wsi);
public:
TCPStream *ts;
public:
struct lws *wsi;
char buffer[BUFFER_SIZE];
char writeable;
char awaiting_on_writeable;
};
class lws_conn_listener : lws_conn {
public:
lws_conn_listener():
srv(SOCKET_STACK_LWIP_IPV4)
{
srv.setOnError(TCPStream::ErrorHandler_t(this, &lws_conn_lis
tener::onError));
}
void start(const uint16_t port);
protected:
void onRX(Socket *s);
void onError(Socket *s, socket_error_t err);
void onIncoming(TCPListener *s, void *impl);
void onDisconnect(TCPStream *s);
public:
TCPListener srv;
};
#endif
extern "C" { extern "C" {
#else #else
#include <stdarg.h> #include <stdarg.h>
#endif #endif
#ifdef MBED_OPERATORS
#define LWS_POSIX 0
#else
#define LWS_POSIX 1
#endif
#include "lws_config.h" #include "lws_config.h"
#if defined(WIN32) || defined(_WIN32) #if defined(WIN32) || defined(_WIN32)
#ifndef WIN32_LEAN_AND_MEAN #ifndef WIN32_LEAN_AND_MEAN
#define WIN32_LEAN_AND_MEAN #define WIN32_LEAN_AND_MEAN
#endif #endif
#include <winsock2.h> #include <winsock2.h>
#include <ws2tcpip.h> #include <ws2tcpip.h>
#include <stddef.h> #include <stddef.h>
#include <stdint.h> #include <stdint.h>
#include <basetsd.h> #include <basetsd.h>
#include <fcntl.h>
#define strcasecmp stricmp #define strcasecmp stricmp
#define getdtablesize() 30000 #define getdtablesize() 30000
#define LWS_INLINE __inline
#define LWS_VISIBLE #define LWS_VISIBLE
#ifdef LWS_DLL #ifdef LWS_DLL
#ifdef LWS_INTERNAL #ifdef LWS_INTERNAL
#define LWS_EXTERN extern __declspec(dllexport) #define LWS_EXTERN extern __declspec(dllexport)
#else #else
#define LWS_EXTERN extern __declspec(dllimport) #define LWS_EXTERN extern __declspec(dllimport)
#endif #endif
#else #else
#define LWS_EXTERN #define LWS_EXTERN
#endif #endif
#else // NOT WIN32 #define LWS_INVALID_FILE INVALID_HANDLE_VALUE
#define LWS_O_RDONLY _O_RDONLY
#include <poll.h> #else /* NOT WIN32 */
#include <unistd.h> #include <unistd.h>
#define LWS_INLINE inline
#define LWS_O_RDONLY O_RDONLY
#ifndef MBED_OPERATORS
#include <poll.h>
#include <netdb.h> #include <netdb.h>
#define LWS_INVALID_FILE -1
#else
#define getdtablesize() (20)
#define LWS_INVALID_FILE NULL
#endif
#if defined(__GNUC__) #if defined(__GNUC__)
#define LWS_VISIBLE __attribute__((visibility("default"))) #define LWS_VISIBLE __attribute__((visibility("default")))
#else #else
#define LWS_VISIBLE #define LWS_VISIBLE
#endif #endif
#if defined(__ANDROID__)
#define getdtablesize() 1024
#endif
#endif #endif
#ifdef LWS_USE_LIBEV #ifdef LWS_USE_LIBEV
#include <ev.h> #include <ev.h>
#endif /* LWS_USE_LIBEV */ #endif /* LWS_USE_LIBEV */
#include <assert.h>
#ifndef LWS_EXTERN #ifndef LWS_EXTERN
#define LWS_EXTERN extern #define LWS_EXTERN extern
#endif #endif
#ifdef _WIN32 #ifdef _WIN32
#define random rand #define random rand
#else #else
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
#endif #endif
skipping to change at line 147 skipping to change at line 235
#define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__) #define lwsl_debug(...) _lws_log(LLL_DEBUG, __VA_ARGS__)
#define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__) #define lwsl_parser(...) _lws_log(LLL_PARSER, __VA_ARGS__)
#define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__) #define lwsl_header(...) _lws_log(LLL_HEADER, __VA_ARGS__)
#define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__) #define lwsl_ext(...) _lws_log(LLL_EXT, __VA_ARGS__)
#define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__) #define lwsl_client(...) _lws_log(LLL_CLIENT, __VA_ARGS__)
#define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__) #define lwsl_latency(...) _lws_log(LLL_LATENCY, __VA_ARGS__)
LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len); LWS_VISIBLE LWS_EXTERN void lwsl_hexdump(void *buf, size_t len);
#else /* no debug */ #else /* no debug */
#define lwsl_info(...) #define lwsl_info(...) {}
#define lwsl_debug(...) #define lwsl_debug(...) {}
#define lwsl_parser(...) #define lwsl_parser(...) {}
#define lwsl_header(...) #define lwsl_header(...) {}
#define lwsl_ext(...) #define lwsl_ext(...) {}
#define lwsl_client(...) #define lwsl_client(...) {}
#define lwsl_latency(...) #define lwsl_latency(...) {}
#define lwsl_hexdump(a, b) #define lwsl_hexdump(a, b)
#endif #endif
struct lws;
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0])) #define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
/* api change list for user code to test against */ /* api change list for user code to test against */
#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_ARG
/* the struct libwebsocket_protocols has the id field present */ /* the struct lws_protocols has the id field present */
#define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD #define LWS_FEATURE_PROTOCOLS_HAS_ID_FIELD
/* you can call lws_get_peer_write_allowance */ /* you can call lws_get_peer_write_allowance */
#define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE #define LWS_FEATURE_PROTOCOLS_HAS_PEER_WRITE_ALLOWANCE
/* extra parameter introduced in 917f43ab821 */ /* extra parameter introduced in 917f43ab821 */
#define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN #define LWS_FEATURE_SERVE_HTTP_FILE_HAS_OTHER_HEADERS_LEN
enum libwebsocket_context_options { /* File operations stuff exists */
#define LWS_FEATURE_FOPS
/*
* NOTE: These public enums are part of the abi. If you want to add one,
* add it at where specified so existing users are unaffected.
*/
enum lws_context_options {
LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2, LWS_SERVER_OPTION_REQUIRE_VALID_OPENSSL_CLIENT_CERT = 2,
LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4, LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME = 4,
LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT = 8, LWS_SERVER_OPTION_ALLOW_NON_SSL_ON_SSL_PORT = 8,
LWS_SERVER_OPTION_LIBEV = 16, LWS_SERVER_OPTION_LIBEV = 16,
LWS_SERVER_OPTION_DISABLE_IPV6 = 32, LWS_SERVER_OPTION_DISABLE_IPV6 = 32,
LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS = 64, LWS_SERVER_OPTION_DISABLE_OS_CA_CERTS = 64,
LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED = 128, LWS_SERVER_OPTION_PEER_CERT_NOT_REQUIRED = 128,
/****** add new things just above ---^ ******/
}; };
enum libwebsocket_callback_reasons { /*
LWS_CALLBACK_ESTABLISHED, * NOTE: These public enums are part of the abi. If you want to add one,
LWS_CALLBACK_CLIENT_CONNECTION_ERROR, * add it at where specified so existing users are unaffected.
LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH, */
LWS_CALLBACK_CLIENT_ESTABLISHED, enum lws_callback_reasons {
LWS_CALLBACK_CLOSED, LWS_CALLBACK_ESTABLISHED = 0,
LWS_CALLBACK_CLOSED_HTTP, LWS_CALLBACK_CLIENT_CONNECTION_ERROR = 1,
LWS_CALLBACK_RECEIVE, LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH = 2,
LWS_CALLBACK_RECEIVE_PONG, LWS_CALLBACK_CLIENT_ESTABLISHED = 3,
LWS_CALLBACK_CLIENT_RECEIVE, LWS_CALLBACK_CLOSED = 4,
LWS_CALLBACK_CLIENT_RECEIVE_PONG, LWS_CALLBACK_CLOSED_HTTP = 5,
LWS_CALLBACK_CLIENT_WRITEABLE, LWS_CALLBACK_RECEIVE = 6,
LWS_CALLBACK_SERVER_WRITEABLE, LWS_CALLBACK_RECEIVE_PONG = 7,
LWS_CALLBACK_HTTP, LWS_CALLBACK_CLIENT_RECEIVE = 8,
LWS_CALLBACK_HTTP_BODY, LWS_CALLBACK_CLIENT_RECEIVE_PONG = 9,
LWS_CALLBACK_HTTP_BODY_COMPLETION, LWS_CALLBACK_CLIENT_WRITEABLE = 10,
LWS_CALLBACK_HTTP_FILE_COMPLETION, LWS_CALLBACK_SERVER_WRITEABLE = 11,
LWS_CALLBACK_HTTP_WRITEABLE, LWS_CALLBACK_HTTP = 12,
LWS_CALLBACK_FILTER_NETWORK_CONNECTION, LWS_CALLBACK_HTTP_BODY = 13,
LWS_CALLBACK_FILTER_HTTP_CONNECTION, LWS_CALLBACK_HTTP_BODY_COMPLETION = 14,
LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED, LWS_CALLBACK_HTTP_FILE_COMPLETION = 15,
LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION, LWS_CALLBACK_HTTP_WRITEABLE = 16,
LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS, LWS_CALLBACK_FILTER_NETWORK_CONNECTION = 17,
LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS, LWS_CALLBACK_FILTER_HTTP_CONNECTION = 18,
LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION, LWS_CALLBACK_SERVER_NEW_CLIENT_INSTANTIATED = 19,
LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER, LWS_CALLBACK_FILTER_PROTOCOL_CONNECTION = 20,
LWS_CALLBACK_CONFIRM_EXTENSION_OKAY, LWS_CALLBACK_OPENSSL_LOAD_EXTRA_CLIENT_VERIFY_CERTS = 21,
LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED, LWS_CALLBACK_OPENSSL_LOAD_EXTRA_SERVER_VERIFY_CERTS = 22,
LWS_CALLBACK_PROTOCOL_INIT, LWS_CALLBACK_OPENSSL_PERFORM_CLIENT_CERT_VERIFICATION = 23,
LWS_CALLBACK_PROTOCOL_DESTROY, LWS_CALLBACK_CLIENT_APPEND_HANDSHAKE_HEADER = 24,
LWS_CALLBACK_WSI_CREATE, /* always protocol[0] */ LWS_CALLBACK_CONFIRM_EXTENSION_OKAY = 25,
LWS_CALLBACK_WSI_DESTROY, /* always protocol[0] */ LWS_CALLBACK_CLIENT_CONFIRM_EXTENSION_SUPPORTED = 26,
LWS_CALLBACK_GET_THREAD_ID, LWS_CALLBACK_PROTOCOL_INIT = 27,
LWS_CALLBACK_PROTOCOL_DESTROY = 28,
LWS_CALLBACK_WSI_CREATE /* always protocol[0] */ = 29,
LWS_CALLBACK_WSI_DESTROY /* always protocol[0] */ = 30,
LWS_CALLBACK_GET_THREAD_ID = 31,
/* external poll() management support */ /* external poll() management support */
LWS_CALLBACK_ADD_POLL_FD, LWS_CALLBACK_ADD_POLL_FD = 32,
LWS_CALLBACK_DEL_POLL_FD, LWS_CALLBACK_DEL_POLL_FD = 33,
LWS_CALLBACK_CHANGE_MODE_POLL_FD, LWS_CALLBACK_CHANGE_MODE_POLL_FD = 34,
LWS_CALLBACK_LOCK_POLL, LWS_CALLBACK_LOCK_POLL = 35,
LWS_CALLBACK_UNLOCK_POLL, LWS_CALLBACK_UNLOCK_POLL = 36,
LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY, LWS_CALLBACK_OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY = 37,
/****** add new things just above ---^ ******/
LWS_CALLBACK_USER = 1000, /* user code can use any including / above */ LWS_CALLBACK_USER = 1000, /* user code can use any including / above */
}; };
// argument structure for all external poll related calls #if defined(_WIN32)
// passed in via 'in' typedef SOCKET lws_sockfd_type;
struct libwebsocket_pollargs { typedef HANDLE lws_filefd_type;
int fd; // applicable file descriptor #define lws_sockfd_valid(sfd) (!!sfd)
int events; // the new event mask struct lws_pollfd {
int prev_events; // the previous event mask lws_sockfd_type fd;
SHORT events;
SHORT revents;
}; };
#else
#ifdef _WIN32 #if defined(MBED_OPERATORS)
struct libwebsocket_pollfd { /* it's a class lws_conn * */
SOCKET fd; typedef void * lws_sockfd_type;
SHORT events; typedef void * lws_filefd_type;
SHORT revents; #define lws_sockfd_valid(sfd) (!!sfd)
struct pollfd {
lws_sockfd_type fd;
short events;
short revents;
}; };
#define POLLIN 0x0001
#define POLLPRI 0x0002
#define POLLOUT 0x0004
#define POLLERR 0x0008
#define POLLHUP 0x0010
#define POLLNVAL 0x0020
struct lws;
void * mbed3_create_tcp_stream_socket(void);
void mbed3_delete_tcp_stream_socket(void *sockfd);
void mbed3_tcp_stream_bind(void *sock, int port, struct lws *);
void mbed3_tcp_stream_accept(void *sock, struct lws *);
#else #else
#define libwebsocket_pollfd pollfd typedef int lws_sockfd_type;
typedef int lws_filefd_type;
#define lws_sockfd_valid(sfd) (sfd >= 0)
#endif #endif
enum libwebsocket_extension_callback_reasons { #define lws_pollfd pollfd
LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT, #endif
LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT,
LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT, /* argument structure for all external poll related calls
LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT, * passed in via 'in'
LWS_EXT_CALLBACK_CONSTRUCT, */
LWS_EXT_CALLBACK_CLIENT_CONSTRUCT, struct lws_pollargs {
LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE, lws_sockfd_type fd; /* applicable socket descriptor */
LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION, int events; /* the new event mask */
LWS_EXT_CALLBACK_DESTROY, int prev_events; /* the previous event mask */
LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING,
LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED,
LWS_EXT_CALLBACK_PACKET_RX_PREPARSE,
LWS_EXT_CALLBACK_PACKET_TX_PRESEND,
LWS_EXT_CALLBACK_PACKET_TX_DO_SEND,
LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX,
LWS_EXT_CALLBACK_FLUSH_PENDING_TX,
LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX,
LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION,
LWS_EXT_CALLBACK_1HZ,
LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE,
LWS_EXT_CALLBACK_IS_WRITEABLE,
LWS_EXT_CALLBACK_PAYLOAD_TX,
LWS_EXT_CALLBACK_PAYLOAD_RX,
}; };
enum libwebsocket_write_protocol { /**
LWS_WRITE_TEXT, * struct lws_plat_file_ops - Platform-specific file operations
LWS_WRITE_BINARY, *
LWS_WRITE_CONTINUATION, * These provide platform-agnostic ways to deal with filesystem access in t
LWS_WRITE_HTTP, he
* library and in the user code.
*
* @open: Open file (always binary access if plat supports it)
* filelen is filled on exit to be the length of the f
ile
* flags should be set to O_RDONLY or O_RDWR
* @close: Close file
* @seek_cur: Seek from current position
* @read: Read fron file *amount is set on exit to amount read
* @write: Write to file *amount is set on exit as amount writt
en
*/
struct lws_plat_file_ops {
lws_filefd_type (*open)(struct lws *wsi, const char *filename,
unsigned long *filelen, int flags);
int (*close)(struct lws *wsi, lws_filefd_type fd);
unsigned long (*seek_cur)(struct lws *wsi, lws_filefd_type fd,
long offset_from_cur_pos);
int (*read)(struct lws *wsi, lws_filefd_type fd, unsigned long *amou
nt,
unsigned char *buf, unsigned long len);
int (*write)(struct lws *wsi, lws_filefd_type fd, unsigned long *amo
unt,
unsigned char *buf, unsigned long len);
/* Add new things just above here ---^
* This is part of the ABI, don't needlessly break compatibilty */
};
/*
* NOTE: These public enums are part of the abi. If you want to add one,
* add it at where specified so existing users are unaffected.
*/
enum lws_extension_callback_reasons {
LWS_EXT_CALLBACK_SERVER_CONTEXT_CONSTRUCT = 0,
LWS_EXT_CALLBACK_CLIENT_CONTEXT_CONSTRUCT = 1,
LWS_EXT_CALLBACK_SERVER_CONTEXT_DESTRUCT = 2,
LWS_EXT_CALLBACK_CLIENT_CONTEXT_DESTRUCT = 3,
LWS_EXT_CALLBACK_CONSTRUCT = 4,
LWS_EXT_CALLBACK_CLIENT_CONSTRUCT = 5,
LWS_EXT_CALLBACK_CHECK_OK_TO_REALLY_CLOSE = 6,
LWS_EXT_CALLBACK_CHECK_OK_TO_PROPOSE_EXTENSION = 7,
LWS_EXT_CALLBACK_DESTROY = 8,
LWS_EXT_CALLBACK_DESTROY_ANY_WSI_CLOSING = 9,
LWS_EXT_CALLBACK_ANY_WSI_ESTABLISHED = 10,
LWS_EXT_CALLBACK_PACKET_RX_PREPARSE = 11,
LWS_EXT_CALLBACK_PACKET_TX_PRESEND = 12,
LWS_EXT_CALLBACK_PACKET_TX_DO_SEND = 13,
LWS_EXT_CALLBACK_HANDSHAKE_REPLY_TX = 14,
LWS_EXT_CALLBACK_FLUSH_PENDING_TX = 15,
LWS_EXT_CALLBACK_EXTENDED_PAYLOAD_RX = 16,
LWS_EXT_CALLBACK_CAN_PROXY_CLIENT_CONNECTION = 17,
LWS_EXT_CALLBACK_1HZ = 18,
LWS_EXT_CALLBACK_REQUEST_ON_WRITEABLE = 19,
LWS_EXT_CALLBACK_IS_WRITEABLE = 20,
LWS_EXT_CALLBACK_PAYLOAD_TX = 21,
LWS_EXT_CALLBACK_PAYLOAD_RX = 22,
/****** add new things just above ---^ ******/
};
/*
* NOTE: These public enums are part of the abi. If you want to add one,
* add it at where specified so existing users are unaffected.
*/
enum lws_write_protocol {
LWS_WRITE_TEXT = 0,
LWS_WRITE_BINARY = 1,
LWS_WRITE_CONTINUATION = 2,
LWS_WRITE_HTTP = 3,
/* special 04+ opcodes */ /* special 04+ opcodes */
LWS_WRITE_CLOSE, LWS_WRITE_CLOSE = 4,
LWS_WRITE_PING, LWS_WRITE_PING = 5,
LWS_WRITE_PONG, LWS_WRITE_PONG = 6,
/* Same as write_http but we know this write ends the transaction */ /* Same as write_http but we know this write ends the transaction */
LWS_WRITE_HTTP_FINAL, LWS_WRITE_HTTP_FINAL = 7,
/* HTTP2 */ /* HTTP2 */
LWS_WRITE_HTTP_HEADERS, LWS_WRITE_HTTP_HEADERS = 8,
/****** add new things just above ---^ ******/
/* flags */ /* flags */
LWS_WRITE_NO_FIN = 0x40, LWS_WRITE_NO_FIN = 0x40,
/* /*
* client packet payload goes out on wire unmunged * client packet payload goes out on wire unmunged
* only useful for security tests since normal servers cannot * only useful for security tests since normal servers cannot
* decode the content if used * decode the content if used
*/ */
LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80 LWS_WRITE_CLIENT_IGNORE_XOR_MASK = 0x80
skipping to change at line 319 skipping to change at line 497
struct lws_tokens { struct lws_tokens {
char *token; char *token;
int token_len; int token_len;
}; };
/* /*
* don't forget to update test server header dump accordingly * don't forget to update test server header dump accordingly
* *
* these have to be kept in sync with lextable.h / minilex.c * these have to be kept in sync with lextable.h / minilex.c
*
* NOTE: These public enums are part of the abi. If you want to add one,
* add it at where specified so existing users are unaffected.
*/ */
enum lws_token_indexes { enum lws_token_indexes {
WSI_TOKEN_GET_URI, WSI_TOKEN_GET_URI = 0,
WSI_TOKEN_POST_URI, WSI_TOKEN_POST_URI = 1,
WSI_TOKEN_OPTIONS_URI, WSI_TOKEN_OPTIONS_URI = 2,
WSI_TOKEN_HOST, WSI_TOKEN_HOST = 3,
WSI_TOKEN_CONNECTION, WSI_TOKEN_CONNECTION = 4,
WSI_TOKEN_UPGRADE, WSI_TOKEN_UPGRADE = 5,
WSI_TOKEN_ORIGIN, WSI_TOKEN_ORIGIN = 6,
WSI_TOKEN_DRAFT, WSI_TOKEN_DRAFT = 7,
WSI_TOKEN_CHALLENGE, WSI_TOKEN_CHALLENGE = 8,
WSI_TOKEN_EXTENSIONS, WSI_TOKEN_EXTENSIONS = 9,
WSI_TOKEN_KEY1, WSI_TOKEN_KEY1 = 10,
WSI_TOKEN_KEY2, WSI_TOKEN_KEY2 = 11,
WSI_TOKEN_PROTOCOL, WSI_TOKEN_PROTOCOL = 12,
WSI_TOKEN_ACCEPT, WSI_TOKEN_ACCEPT = 13,
WSI_TOKEN_NONCE, WSI_TOKEN_NONCE = 14,
WSI_TOKEN_HTTP, WSI_TOKEN_HTTP = 15,
WSI_TOKEN_HTTP2_SETTINGS, WSI_TOKEN_HTTP2_SETTINGS = 16,
WSI_TOKEN_HTTP_ACCEPT, WSI_TOKEN_HTTP_ACCEPT = 17,
WSI_TOKEN_HTTP_AC_REQUEST_HEADERS, WSI_TOKEN_HTTP_AC_REQUEST_HEADERS = 18,
WSI_TOKEN_HTTP_IF_MODIFIED_SINCE, WSI_TOKEN_HTTP_IF_MODIFIED_SINCE = 19,
WSI_TOKEN_HTTP_IF_NONE_MATCH, WSI_TOKEN_HTTP_IF_NONE_MATCH = 20,
WSI_TOKEN_HTTP_ACCEPT_ENCODING, WSI_TOKEN_HTTP_ACCEPT_ENCODING = 21,
WSI_TOKEN_HTTP_ACCEPT_LANGUAGE, WSI_TOKEN_HTTP_ACCEPT_LANGUAGE = 22,
WSI_TOKEN_HTTP_PRAGMA, WSI_TOKEN_HTTP_PRAGMA = 23,
WSI_TOKEN_HTTP_CACHE_CONTROL, WSI_TOKEN_HTTP_CACHE_CONTROL = 24,
WSI_TOKEN_HTTP_AUTHORIZATION, WSI_TOKEN_HTTP_AUTHORIZATION = 25,
WSI_TOKEN_HTTP_COOKIE, WSI_TOKEN_HTTP_COOKIE = 26,
WSI_TOKEN_HTTP_CONTENT_LENGTH, WSI_TOKEN_HTTP_CONTENT_LENGTH = 27,
WSI_TOKEN_HTTP_CONTENT_TYPE, WSI_TOKEN_HTTP_CONTENT_TYPE = 28,
WSI_TOKEN_HTTP_DATE, WSI_TOKEN_HTTP_DATE = 29,
WSI_TOKEN_HTTP_RANGE, WSI_TOKEN_HTTP_RANGE = 30,
WSI_TOKEN_HTTP_REFERER, WSI_TOKEN_HTTP_REFERER = 31,
WSI_TOKEN_KEY, WSI_TOKEN_KEY = 32,
WSI_TOKEN_VERSION, WSI_TOKEN_VERSION = 33,
WSI_TOKEN_SWORIGIN, WSI_TOKEN_SWORIGIN = 34,
WSI_TOKEN_HTTP_COLON_AUTHORITY, WSI_TOKEN_HTTP_COLON_AUTHORITY = 35,
WSI_TOKEN_HTTP_COLON_METHOD, WSI_TOKEN_HTTP_COLON_METHOD = 36,
WSI_TOKEN_HTTP_COLON_PATH, WSI_TOKEN_HTTP_COLON_PATH = 37,
WSI_TOKEN_HTTP_COLON_SCHEME, WSI_TOKEN_HTTP_COLON_SCHEME = 38,
WSI_TOKEN_HTTP_COLON_STATUS, WSI_TOKEN_HTTP_COLON_STATUS = 39,
WSI_TOKEN_HTTP_ACCEPT_CHARSET, WSI_TOKEN_HTTP_ACCEPT_CHARSET = 40,
WSI_TOKEN_HTTP_ACCEPT_RANGES, WSI_TOKEN_HTTP_ACCEPT_RANGES = 41,
WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN, WSI_TOKEN_HTTP_ACCESS_CONTROL_ALLOW_ORIGIN = 42,
WSI_TOKEN_HTTP_AGE, WSI_TOKEN_HTTP_AGE = 43,
WSI_TOKEN_HTTP_ALLOW, WSI_TOKEN_HTTP_ALLOW = 44,
WSI_TOKEN_HTTP_CONTENT_DISPOSITION, WSI_TOKEN_HTTP_CONTENT_DISPOSITION = 45,
WSI_TOKEN_HTTP_CONTENT_ENCODING, WSI_TOKEN_HTTP_CONTENT_ENCODING = 46,
WSI_TOKEN_HTTP_CONTENT_LANGUAGE, WSI_TOKEN_HTTP_CONTENT_LANGUAGE = 47,
WSI_TOKEN_HTTP_CONTENT_LOCATION, WSI_TOKEN_HTTP_CONTENT_LOCATION = 48,
WSI_TOKEN_HTTP_CONTENT_RANGE, WSI_TOKEN_HTTP_CONTENT_RANGE = 49,
WSI_TOKEN_HTTP_ETAG, WSI_TOKEN_HTTP_ETAG = 50,
WSI_TOKEN_HTTP_EXPECT, WSI_TOKEN_HTTP_EXPECT = 51,
WSI_TOKEN_HTTP_EXPIRES, WSI_TOKEN_HTTP_EXPIRES = 52,
WSI_TOKEN_HTTP_FROM, WSI_TOKEN_HTTP_FROM = 53,
WSI_TOKEN_HTTP_IF_MATCH, WSI_TOKEN_HTTP_IF_MATCH = 54,
WSI_TOKEN_HTTP_IF_RANGE, WSI_TOKEN_HTTP_IF_RANGE = 55,
WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE, WSI_TOKEN_HTTP_IF_UNMODIFIED_SINCE = 56,
WSI_TOKEN_HTTP_LAST_MODIFIED, WSI_TOKEN_HTTP_LAST_MODIFIED = 57,
WSI_TOKEN_HTTP_LINK, WSI_TOKEN_HTTP_LINK = 58,
WSI_TOKEN_HTTP_LOCATION, WSI_TOKEN_HTTP_LOCATION = 59,
WSI_TOKEN_HTTP_MAX_FORWARDS, WSI_TOKEN_HTTP_MAX_FORWARDS = 60,
WSI_TOKEN_HTTP_PROXY_AUTHENTICATE, WSI_TOKEN_HTTP_PROXY_AUTHENTICATE = 61,
WSI_TOKEN_HTTP_PROXY_AUTHORIZATION, WSI_TOKEN_HTTP_PROXY_AUTHORIZATION = 62,
WSI_TOKEN_HTTP_REFRESH, WSI_TOKEN_HTTP_REFRESH = 63,
WSI_TOKEN_HTTP_RETRY_AFTER, WSI_TOKEN_HTTP_RETRY_AFTER = 64,
WSI_TOKEN_HTTP_SERVER, WSI_TOKEN_HTTP_SERVER = 65,
WSI_TOKEN_HTTP_SET_COOKIE, WSI_TOKEN_HTTP_SET_COOKIE = 66,
WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY, WSI_TOKEN_HTTP_STRICT_TRANSPORT_SECURITY = 67,
WSI_TOKEN_HTTP_TRANSFER_ENCODING, WSI_TOKEN_HTTP_TRANSFER_ENCODING = 68,
WSI_TOKEN_HTTP_USER_AGENT, WSI_TOKEN_HTTP_USER_AGENT = 69,
WSI_TOKEN_HTTP_VARY, WSI_TOKEN_HTTP_VARY = 70,
WSI_TOKEN_HTTP_VIA, WSI_TOKEN_HTTP_VIA = 71,
WSI_TOKEN_HTTP_WWW_AUTHENTICATE, WSI_TOKEN_HTTP_WWW_AUTHENTICATE = 72,
WSI_TOKEN_PROXY, WSI_TOKEN_PROXY,
WSI_TOKEN_PATCH_URI, WSI_TOKEN_PATCH_URI = 73,
WSI_TOKEN_PUT_URI, WSI_TOKEN_PUT_URI = 74,
WSI_TOKEN_DELETE_URI, WSI_TOKEN_DELETE_URI = 75,
WSI_TOKEN_HTTP_URI_ARGS, WSI_TOKEN_HTTP_URI_ARGS = 76,
/* use token storage to stash these */ /* use token storage to stash these */
_WSI_TOKEN_CLIENT_SENT_PROTOCOLS, _WSI_TOKEN_CLIENT_SENT_PROTOCOLS = 77,
_WSI_TOKEN_CLIENT_PEER_ADDRESS, _WSI_TOKEN_CLIENT_PEER_ADDRESS = 78,
_WSI_TOKEN_CLIENT_URI, _WSI_TOKEN_CLIENT_URI = 79,
_WSI_TOKEN_CLIENT_HOST, _WSI_TOKEN_CLIENT_HOST = 80,
_WSI_TOKEN_CLIENT_ORIGIN, _WSI_TOKEN_CLIENT_ORIGIN = 81,
/****** add new things just above ---^ ******/
/* always last real token index*/ /* always last real token index*/
WSI_TOKEN_COUNT, WSI_TOKEN_COUNT,
/* parser state additions */ /* parser state additions */
WSI_TOKEN_NAME_PART, WSI_TOKEN_NAME_PART,
WSI_TOKEN_SKIPPING, WSI_TOKEN_SKIPPING,
WSI_TOKEN_SKIPPING_SAW_CR, WSI_TOKEN_SKIPPING_SAW_CR,
WSI_PARSING_COMPLETE, WSI_PARSING_COMPLETE,
WSI_INIT_TOKEN_MUXURL, WSI_INIT_TOKEN_MUXURL,
}; };
struct lws_token_limits { struct lws_token_limits {
unsigned short token_limit[WSI_TOKEN_COUNT]; unsigned short token_limit[WSI_TOKEN_COUNT];
}; };
/* /*
* From RFC 6455 * From RFC 6455
1000 1000
1000 indicates a normal closure, meaning that the purpose for 1000 indicates a normal closure, meaning that the purpose for
which the connection was established has been fulfilled. which the connection was established has been fulfilled.
1001 1001
skipping to change at line 516 skipping to change at line 699
1015 1015
1015 is a reserved value and MUST NOT be set as a status code in a 1015 is a reserved value and MUST NOT be set as a status code in a
Close control frame by an endpoint. It is designated for use in Close control frame by an endpoint. It is designated for use in
applications expecting a status code to indicate that the applications expecting a status code to indicate that the
connection was closed due to a failure to perform a TLS handshake connection was closed due to a failure to perform a TLS handshake
(e.g., the server certificate can't be verified). (e.g., the server certificate can't be verified).
*/ */
/*
* NOTE: These public enums are part of the abi. If you want to add one,
* add it at where specified so existing users are unaffected.
*/
enum lws_close_status { enum lws_close_status {
LWS_CLOSE_STATUS_NOSTATUS = 0, LWS_CLOSE_STATUS_NOSTATUS = 0,
LWS_CLOSE_STATUS_NORMAL = 1000, LWS_CLOSE_STATUS_NORMAL = 1000,
LWS_CLOSE_STATUS_GOINGAWAY = 1001, LWS_CLOSE_STATUS_GOINGAWAY = 1001,
LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002, LWS_CLOSE_STATUS_PROTOCOL_ERR = 1002,
LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003, LWS_CLOSE_STATUS_UNACCEPTABLE_OPCODE = 1003,
LWS_CLOSE_STATUS_RESERVED = 1004, LWS_CLOSE_STATUS_RESERVED = 1004,
LWS_CLOSE_STATUS_NO_STATUS = 1005, LWS_CLOSE_STATUS_NO_STATUS = 1005,
LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006, LWS_CLOSE_STATUS_ABNORMAL_CLOSE = 1006,
LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007, LWS_CLOSE_STATUS_INVALID_PAYLOAD = 1007,
LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008, LWS_CLOSE_STATUS_POLICY_VIOLATION = 1008,
LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009, LWS_CLOSE_STATUS_MESSAGE_TOO_LARGE = 1009,
LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010, LWS_CLOSE_STATUS_EXTENSION_REQUIRED = 1010,
LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011, LWS_CLOSE_STATUS_UNEXPECTED_CONDITION = 1011,
LWS_CLOSE_STATUS_TLS_FAILURE = 1015, LWS_CLOSE_STATUS_TLS_FAILURE = 1015,
/****** add new things just above ---^ ******/
LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999, LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY = 9999,
}; };
enum http_status { enum http_status {
HTTP_STATUS_OK = 200, HTTP_STATUS_OK = 200,
HTTP_STATUS_NO_CONTENT = 204, HTTP_STATUS_NO_CONTENT = 204,
HTTP_STATUS_BAD_REQUEST = 400, HTTP_STATUS_BAD_REQUEST = 400,
HTTP_STATUS_UNAUTHORIZED, HTTP_STATUS_UNAUTHORIZED,
HTTP_STATUS_PAYMENT_REQUIRED, HTTP_STATUS_PAYMENT_REQUIRED,
skipping to change at line 566 skipping to change at line 755
HTTP_STATUS_EXPECTATION_FAILED, HTTP_STATUS_EXPECTATION_FAILED,
HTTP_STATUS_INTERNAL_SERVER_ERROR = 500, HTTP_STATUS_INTERNAL_SERVER_ERROR = 500,
HTTP_STATUS_NOT_IMPLEMENTED, HTTP_STATUS_NOT_IMPLEMENTED,
HTTP_STATUS_BAD_GATEWAY, HTTP_STATUS_BAD_GATEWAY,
HTTP_STATUS_SERVICE_UNAVAILABLE, HTTP_STATUS_SERVICE_UNAVAILABLE,
HTTP_STATUS_GATEWAY_TIMEOUT, HTTP_STATUS_GATEWAY_TIMEOUT,
HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED, HTTP_STATUS_HTTP_VERSION_NOT_SUPPORTED,
}; };
struct libwebsocket; struct lws;
struct libwebsocket_context; struct lws_context;
/* needed even with extensions disabled for create context */ /* needed even with extensions disabled for create context */
struct libwebsocket_extension; struct lws_extension;
/** /**
* callback_function() - User server actions * callback_function() - User server actions
* @context: Websockets context
* @wsi: Opaque websocket instance pointer * @wsi: Opaque websocket instance pointer
* @reason: The reason for the call * @reason: The reason for the call
* @user: Pointer to per-session user data allocated by library * @user: Pointer to per-session user data allocated by library
* @in: Pointer used for some callback reasons * @in: Pointer used for some callback reasons
* @len: Length set for some callback reasons * @len: Length set for some callback reasons
* *
* This callback is the way the user controls what is served. All the * This callback is the way the user controls what is served. All the
* protocol detail is hidden and handled by the library. * protocol detail is hidden and handled by the library.
* *
* For each connection / session there is user data allocated that is * For each connection / session there is user data allocated that is
* pointed to by "user". You set the size of this user data area when * pointed to by "user". You set the size of this user data area when
* the library is initialized with libwebsocket_create_server. * the library is initialized with lws_create_server.
* *
* You get an opportunity to initialize user data when called back with * You get an opportunity to initialize user data when called back with
* LWS_CALLBACK_ESTABLISHED reason. * LWS_CALLBACK_ESTABLISHED reason.
* *
* LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with * LWS_CALLBACK_ESTABLISHED: after the server completes a handshake with
* an incoming client * an incoming client. If you built the librar
y
* with ssl support, @in is a pointer to the
* ssl struct associated with the connection or
* NULL.
* *
* LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has * LWS_CALLBACK_CLIENT_CONNECTION_ERROR: the request client connection has
* been unable to complete a handshake with the remote server. If * been unable to complete a handshake with the remote server. If
* in is non-NULL, you can find an error string of length len where * in is non-NULL, you can find an error string of length len where
* it points to. * it points to.
* *
* LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for t he * LWS_CALLBACK_CLIENT_FILTER_PRE_ESTABLISH: this is the last chance for t he
* client user code to examine the http headers * client user code to examine the http headers
* and decide to reject the connection. If the * and decide to reject the connection. If the
* content in the headers is interesting to the * content in the headers is interesting to the
skipping to change at line 631 skipping to change at line 822
* LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for t he * LWS_CALLBACK_CLIENT_RECEIVE: data has appeared from the server for t he
* client connection, it can be found at *in an d * client connection, it can be found at *in an d
* is len bytes long * is len bytes long
* *
* LWS_CALLBACK_HTTP: an http request has come from a client that is no t * LWS_CALLBACK_HTTP: an http request has come from a client that is no t
* asking to upgrade the connection to a websoc ket * asking to upgrade the connection to a websoc ket
* one. This is a chance to serve http content , * one. This is a chance to serve http content ,
* for example, to send a script to the client * for example, to send a script to the client
* which will then open the websockets connecti on. * which will then open the websockets connecti on.
* @in points to the URI path requested and * @in points to the URI path requested and
* libwebsockets_serve_http_file() makes it ver y * lws_serve_http_file() makes it very
* simple to send back a file to the client. * simple to send back a file to the client.
* Normally after sending the file you are done * Normally after sending the file you are done
* with the http connection, since the rest of the * with the http connection, since the rest of the
* activity will come by websockets from the sc ript * activity will come by websockets from the sc ript
* that was delivered by http, so you will want to * that was delivered by http, so you will want to
* return 1; to close and free up the connectio n. * return 1; to close and free up the connectio n.
* That's important because it uses a slot in t he * That's important because it uses a slot in t he
* total number of client connections allowed s et * total number of client connections allowed s et
* by MAX_CLIENTS. * by MAX_CLIENTS.
* *
skipping to change at line 656 skipping to change at line 847
* body has been delivered * body has been delivered
* *
* LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protoc ol * LWS_CALLBACK_HTTP_WRITEABLE: you can write more down the http protoc ol
* link now. * link now.
* *
* LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down * LWS_CALLBACK_HTTP_FILE_COMPLETION: a file requested to be send down
* http link has completed. * http link has completed.
* *
* LWS_CALLBACK_CLIENT_WRITEABLE: * LWS_CALLBACK_CLIENT_WRITEABLE:
* LWS_CALLBACK_SERVER_WRITEABLE: If you call * LWS_CALLBACK_SERVER_WRITEABLE: If you call
* libwebsocket_callback_on_writable() on a connection, you wil l * lws_callback_on_writable() on a connection, you will
* get one of these callbacks coming when the connection socket * get one of these callbacks coming when the connection socket
* is able to accept another write packet without blocking. * is able to accept another write packet without blocking.
* If it already was able to take another packet without blocki ng, * If it already was able to take another packet without blocki ng,
* you'll get this callback at the next call to the service loo p * you'll get this callback at the next call to the service loo p
* function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITE ABLE * function. Notice that CLIENTs get LWS_CALLBACK_CLIENT_WRITE ABLE
* and servers get LWS_CALLBACK_SERVER_WRITEABLE. * and servers get LWS_CALLBACK_SERVER_WRITEABLE.
* *
* LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connect s to * LWS_CALLBACK_FILTER_NETWORK_CONNECTION: called when a client connect s to
* the server at network level; the connection is accepted but then * the server at network level; the connection is accepted but then
* passed to this callback to decide whether to hang up immedia tely * passed to this callback to decide whether to hang up immedia tely
skipping to change at line 808 skipping to change at line 999
* deallocate everything that was allocated by the protocol. * deallocate everything that was allocated by the protocol.
* *
* LWS_CALLBACK_WSI_CREATE: outermost (earliest) wsi create notificatio n * LWS_CALLBACK_WSI_CREATE: outermost (earliest) wsi create notificatio n
* *
* LWS_CALLBACK_WSI_DESTROY: outermost (latest) wsi destroy notificatio n * LWS_CALLBACK_WSI_DESTROY: outermost (latest) wsi destroy notificatio n
* *
* The next five reasons are optional and only need taking care of if y ou * The next five reasons are optional and only need taking care of if y ou
* will be integrating libwebsockets sockets into an external polling * will be integrating libwebsockets sockets into an external polling
* array. * array.
* *
* For these calls, @in points to a struct libwebsocket_pollargs that * For these calls, @in points to a struct lws_pollargs that
* contains @fd, @events and @prev_events members * contains @fd, @events and @prev_events members
* *
* LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop * LWS_CALLBACK_ADD_POLL_FD: libwebsocket deals with its poll() loop
* internally, but in the case you are integrating with another * internally, but in the case you are integrating with another
* server you will need to have libwebsocket sockets share a * server you will need to have libwebsocket sockets share a
* polling array with the other server. This and the other * polling array with the other server. This and the other
* POLL_FD related callbacks let you put your specialized * POLL_FD related callbacks let you put your specialized
* poll array interface code in the callback for protocol 0, th e * poll array interface code in the callback for protocol 0, th e
* first protocol you support, usually the HTTP protocol in the * first protocol you support, usually the HTTP protocol in the
* serving case. * serving case.
* This callback happens when a socket needs to be * This callback happens when a socket needs to be
* added to the polling loop: @in points to a struct * added to the polling loop: @in points to a struct
* libwebsocket_pollargs; the @fd member of the struct is the f ile * lws_pollargs; the @fd member of the struct is the file
* descriptor, and @events contains the active events. * descriptor, and @events contains the active events.
* *
* If you are using the internal polling loop (the "service" * If you are using the internal polling loop (the "service"
* callback), you can just ignore these callbacks. * callback), you can just ignore these callbacks.
* *
* LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descri ptor * LWS_CALLBACK_DEL_POLL_FD: This callback happens when a socket descri ptor
* needs to be removed from an external polling array. @in is * needs to be removed from an external polling array. @in is
* again the struct libwebsocket_pollargs containing the @fd me mber * again the struct lws_pollargs containing the @fd member
* to be removed. If you are using the internal polling * to be removed. If you are using the internal polling
* loop, you can just ignore it. * loop, you can just ignore it.
* *
* LWS_CALLBACK_CHANGE_MODE_POLL_FD: This callback happens when * LWS_CALLBACK_CHANGE_MODE_POLL_FD: This callback happens when
* libwebsockets wants to modify the events for a connectiion. * libwebsockets wants to modify the events for a connectiion.
* @in is the struct libwebsocket_pollargs with the @fd to chan ge. * @in is the struct lws_pollargs with the @fd to change.
* The new event mask is in @events member and the old mask is in * The new event mask is in @events member and the old mask is in
* the @prev_events member. * the @prev_events member.
* If you are using the internal polling loop, you can just ign ore * If you are using the internal polling loop, you can just ign ore
* it. * it.
* *
* LWS_CALLBACK_LOCK_POLL: * LWS_CALLBACK_LOCK_POLL:
* LWS_CALLBACK_UNLOCK_POLL: These allow the external poll changes driv en * LWS_CALLBACK_UNLOCK_POLL: These allow the external poll changes driv en
* by libwebsockets to participate in an external thread lockin g * by libwebsockets to participate in an external thread lockin g
* scheme around the changes, so the whole thing is threadsafe. * scheme around the changes, so the whole thing is threadsafe.
* These are called around three activities in the library,
* - inserting a new wsi in the wsi / fd table (len=1)
* - deleting a wsi from the wsi / fd table (len=1)
* - changing a wsi's POLLIN/OUT state (len=0)
* Locking and unlocking external synchronization objects when
* len == 1 allows external threads to be synchronized against
* wsi lifecycle changes if it acquires the same lock for the
* duration of wsi dereference from the other thread context.
*/ */
LWS_VISIBLE LWS_EXTERN int callback(struct libwebsocket_context *context, LWS_VISIBLE LWS_EXTERN int
struct libwebsocket *wsi, callback(const struct lws *wsi, enum lws_callback_reasons reason, void *use
enum libwebsocket_callback_reasons reason, void *us r,
er, void *in, size_t len);
void *in, size_t l
en);
typedef int (callback_function)(struct libwebsocket_context *context, typedef int (callback_function)(struct lws *wsi,
struct libwebsocket *wsi, enum lws_callback_reasons reason, void *user
enum libwebsocket_callback_reasons reason, void *us ,
er, void *in, size_t len);
void *in, size_t l
en);
#ifndef LWS_NO_EXTENSIONS #ifndef LWS_NO_EXTENSIONS
/** /**
* extension_callback_function() - Hooks to allow extensions to operate * extension_callback_function() - Hooks to allow extensions to operate
* @context: Websockets context * @context: Websockets context
* @ext: This extension * @ext: This extension
* @wsi: Opaque websocket instance pointer * @wsi: Opaque websocket instance pointer
* @reason: The reason for the call * @reason: The reason for the call
* @user: Pointer to per-session user data allocated by library * @user: Pointer to per-session user data allocated by library
* @in: Pointer used for some callback reasons * @in: Pointer used for some callback reasons
skipping to change at line 915 skipping to change at line 1112
* *
* LWS_EXT_CALLBACK_PACKET_TX_PRESEND: this works the same way as * LWS_EXT_CALLBACK_PACKET_TX_PRESEND: this works the same way as
* LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives t he * LWS_EXT_CALLBACK_PACKET_RX_PREPARSE above, except it gives t he
* extension a chance to change websocket data just before it w ill * extension a chance to change websocket data just before it w ill
* be sent out. Using the same lws_token pointer scheme in @in , * be sent out. Using the same lws_token pointer scheme in @in ,
* the extension can change the buffer and the length to be * the extension can change the buffer and the length to be
* transmitted how it likes. Again if it wants to grow the * transmitted how it likes. Again if it wants to grow the
* buffer safely, it should copy the data into its own buffer a nd * buffer safely, it should copy the data into its own buffer a nd
* set the lws_tokens token pointer to it. * set the lws_tokens token pointer to it.
*/ */
LWS_VISIBLE LWS_EXTERN int extension_callback(struct libwebsocket_context * LWS_VISIBLE LWS_EXTERN int
context, extension_callback(struct lws_context *context, const struct lws_extension
struct libwebsocket_extension *ext, *ext,
struct libwebsocket *wsi, struct lws *wsi, enum lws_extension_callback_reasons reas
enum libwebsocket_extension_callback_reasons reason, on,
void *user, void *in, size_t len); void *user, void *in, size_t len);
typedef int (extension_callback_function)(struct libwebsocket_context *cont typedef int (extension_callback_function)(struct lws_context *context,
ext, const struct lws_extension *ext, struct lws *wsi,
struct libwebsocket_extension *ext, enum lws_extension_callback_reasons reason,
struct libwebsocket *wsi,
enum libwebsocket_extension_callback_reasons reason,
void *user, void *in, size_t len); void *user, void *in, size_t len);
#endif #endif
/** /**
* struct libwebsocket_protocols - List of protocols and handlers serve r * struct lws_protocols - List of protocols and handlers server
* supports. * supports.
* @name: Protocol name that must match the one given in the client * @name: Protocol name that must match the one given in the client
* Javascript new WebSocket(url, 'protocol') name. * Javascript new WebSocket(url, 'protocol') name.
* @callback: The service callback used for this protocol. It allows the * @callback: The service callback used for this protocol. It allows the
* service action for an entire protocol to be encapsulated in * service action for an entire protocol to be encapsulated in
* the protocol-specific callback * the protocol-specific callback
* @per_session_data_size: Each new connection using this protocol gets * @per_session_data_size: Each new connection using this protocol gets
* this much memory allocated on connection establishment and * this much memory allocated on connection establishment and
* freed on connection takedown. A pointer to this per-connect ion * freed on connection takedown. A pointer to this per-connect ion
* allocation is passed into the callback in the 'user' paramet er * allocation is passed into the callback in the 'user' paramet er
* @rx_buffer_size: if you want atomic frames delivered to the callback, yo u * @rx_buffer_size: if you want atomic frames delivered to the callback, yo u
* should set this to the size of the biggest legal frame that * should set this to the size of the biggest legal frame that
* you support. If the frame size is exceeded, there is no * you support. If the frame size is exceeded, there is no
* error, but the buffer will spill to the user callback when * error, but the buffer will spill to the user callback when
* full, which you can detect by using * full, which you can detect by using
* libwebsockets_remaining_packet_payload(). Notice that you * lws_remaining_packet_payload(). Notice that you
* just talk about frame size here, the LWS_SEND_BUFFER_PRE_PAD DING * just talk about frame size here, the LWS_SEND_BUFFER_PRE_PAD DING
* and post-padding are automatically also allocated on top. * and post-padding are automatically also allocated on top.
* @id: ignored by lws, but useful to contain user informati on bound * @id: ignored by lws, but useful to contain user informati on bound
* to the selected protocol. For example if this protocol was * to the selected protocol. For example if this protocol was
* called "myprotocol-v2", you might set id to 2, and the user * called "myprotocol-v2", you might set id to 2, and the user
* code that acts differently according to the version can do s o by * code that acts differently according to the version can do s o by
* switch (wsi->protocol->id), user code might use some bits as * switch (wsi->protocol->id), user code might use some bits as
* capability flags based on selected protocol version, etc. * capability flags based on selected protocol version, etc.
* @user: User provided context data at the protocol level. * @user: User provided context data at the protocol level.
* Accessible via libwebsockets_get_protocol(wsi)->user * Accessible via lws_get_protocol(wsi)->user
* This should not be confused with wsi->user, it is not the sa me. * This should not be confused with wsi->user, it is not the sa me.
* The library completely ignores any value in here. * The library completely ignores any value in here.
* @owning_server: the server init call fills in this opaque pointer wh
en
* registering this protocol with the server.
* @protocol_index: which protocol we are starting from zero
* *
* This structure represents one protocol supported by the server. An * This structure represents one protocol supported by the server. An
* array of these structures is passed to libwebsocket_create_server() * array of these structures is passed to lws_create_server()
* allows as many protocols as you like to be handled by one server. * allows as many protocols as you like to be handled by one server.
* *
* The first protocol given has its callback used for user callbacks wh en * The first protocol given has its callback used for user callbacks wh en
* there is no agreed protocol name, that's true during HTTP part of th e * there is no agreed protocol name, that's true during HTTP part of th e
* connection and true if the client did not send a Protocol: header. * connection and true if the client did not send a Protocol: header.
*/ */
struct libwebsocket_protocols { struct lws_protocols {
const char *name; const char *name;
callback_function *callback; callback_function *callback;
size_t per_session_data_size; size_t per_session_data_size;
size_t rx_buffer_size; size_t rx_buffer_size;
unsigned int id; unsigned int id;
void *user; void *user;
/* /* Add new things just above here ---^
* below are filled in on server init and can be left uninitialized, * This is part of the ABI, don't needlessly break compatibilty */
* no need for user to use them directly either
*/
struct libwebsocket_context *owning_server;
int protocol_index;
}; };
#ifndef LWS_NO_EXTENSIONS #ifndef LWS_NO_EXTENSIONS
/** /**
* struct libwebsocket_extension - An extension we know how to cope wit h * struct lws_extension - An extension we know how to cope with
* *
* @name: Formal extension name, eg, "deflate-stream" * @name: Formal extension name, eg, "deflate-stream"
* @callback: Service callback * @callback: Service callback
* @per_session_data_size: Libwebsockets will auto-malloc this much * @per_session_data_size: Libwebsockets will auto-malloc this much
* memory for the use of the extension, a point er * memory for the use of the extension, a point er
* to it comes in the @user callback parameter * to it comes in the @user callback parameter
* @per_context_private_data: Optional storage for this extension that * @per_context_private_data: Optional storage for this extension that
* is per-context, so it can track stuff across * is per-context, so it can track stuff across
* all sessions, etc, if it wants * all sessions, etc, if it wants
*/ */
struct libwebsocket_extension { struct lws_extension {
const char *name; const char *name;
extension_callback_function *callback; extension_callback_function *callback;
size_t per_session_data_size; size_t per_session_data_size;
void *per_context_private_data; void *per_context_private_data;
/* Add new things just above here ---^
* This is part of the ABI, don't needlessly break compatibilty */
}; };
#endif #endif
/** /**
* struct lws_context_creation_info: parameters to create context with * struct lws_context_creation_info: parameters to create context with
* *
* @port: Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to * @port: Port to listen on... you can use CONTEXT_PORT_NO_LISTEN to
* suppress listening on any port, that's what you want if you are * suppress listening on any port, that's what you want if you are
* not running a websocket server at all but just using it as a * not running a websocket server at all but just using it as a
* client * client
* @iface: NULL to bind the listen socket to all interfaces, or the * @iface: NULL to bind the listen socket to all interfaces, or the
* interface name, eg, "eth2" * interface name, eg, "eth2"
* @protocols: Array of structures listing supported protocols and a protoc ol- * @protocols: Array of structures listing supported protocols and a protoc ol-
* specific callback for each one. The list is ended with an * specific callback for each one. The list is ended with an
* entry that has a NULL callback pointer. * entry that has a NULL callback pointer.
* It's not const because we write the owning_server member * It's not const because we write the owning_server member
* @extensions: NULL or array of libwebsocket_extension structs listing the * @extensions: NULL or array of lws_extension structs listing the
* extensions this context supports. If you configured with * extensions this context supports. If you configured with
* --without-extensions, you should give NULL here. * --without-extensions, you should give NULL here.
* @token_limits: NULL or struct lws_token_limits pointer which is initiali zed * @token_limits: NULL or struct lws_token_limits pointer which is initiali zed
* with a token length limit for each possible WSI_TOKEN_*** * with a token length limit for each possible WSI_TOKEN_***
* @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you wa nt * @ssl_cert_filepath: If libwebsockets was compiled to use ssl, and you wa nt
* to listen using SSL, set to the filepath to fetch th e * to listen using SSL, set to the filepath to fetch th e
* server cert from, otherwise NULL for unencrypted * server cert from, otherwise NULL for unencrypted
* @ssl_private_key_filepath: filepath to private key if wanting SSL mode; * @ssl_private_key_filepath: filepath to private key if wanting SSL mode;
* if this is set to NULL but sll_cert_filepath is set, the * if this is set to NULL but sll_cert_filepath is set, the
* OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY callback is cal led to allow * OPENSSL_CONTEXT_REQUIRES_PRIVATE_KEY callback is cal led to allow
* setting of the private key directly via openSSL libr ary calls * setting of the private key directly via openSSL libr ary calls
* @ssl_ca_filepath: CA certificate filepath or NULL * @ssl_ca_filepath: CA certificate filepath or NULL
* @ssl_cipher_list: List of valid ciphers to use (eg, * @ssl_cipher_list: List of valid ciphers to use (eg,
* "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aN ULL" * "RC4-MD5:RC4-SHA:AES128-SHA:AES256-SHA:HIGH:!DSS:!aN ULL"
* or you can leave it as NULL to get "DEFAULT" * or you can leave it as NULL to get "DEFAULT"
* @http_proxy_address: If non-NULL, attempts to proxy via the given addres * @http_proxy_address: If non-NULL, attempts to proxy via the given addres
s s.
* If proxy auth is required, use format
* "username:password@server:port"
* @http_proxy_port: If http_proxy_address was non-NULL, uses this port a t the address * @http_proxy_port: If http_proxy_address was non-NULL, uses this port a t the address
* @gid: group id to change to after setting listen socket, or -1. * @gid: group id to change to after setting listen socket, or -1.
* @uid: user id to change to after setting listen socket, or -1. * @uid: user id to change to after setting listen socket, or -1.
* @options: 0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK * @options: 0, or LWS_SERVER_OPTION_DEFEAT_CLIENT_MASK
* @user: optional user pointer that can be recovered via the context * @user: optional user pointer that can be recovered via the context
* pointer using libwebsocket_context_user * pointer using lws_context_user
* @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout t o * @ka_time: 0 for no keepalive, otherwise apply this keepalive timeout t o
* all libwebsocket sockets, client or server * all libwebsocket sockets, client or server
* @ka_probes: if ka_time was nonzero, after the timeout expires how many * @ka_probes: if ka_time was nonzero, after the timeout expires how many
* times to try to get a response from the peer before giving u p * times to try to get a response from the peer before giving u p
* and killing the connection * and killing the connection
* @ka_interval: if ka_time was nonzero, how long to wait before each ka_pr obes * @ka_interval: if ka_time was nonzero, how long to wait before each ka_pr obes
* attempt * attempt
* @provided_client_ssl_ctx: If non-null, swap out libwebsockets ssl * @provided_client_ssl_ctx: If non-null, swap out libwebsockets ssl
* implementation for the one provided by provided_ssl_ctx. * implementation for the one provided by provided_ssl_ctx.
* Libwebsockets no longer is responsible for freeing the conte xt * Libwebsockets no longer is responsible for freeing the conte xt
* if this option is selected. * if this option is selected.
*/ */
struct lws_context_creation_info { struct lws_context_creation_info {
int port; int port;
const char *iface; const char *iface;
struct libwebsocket_protocols *protocols; const struct lws_protocols *protocols;
struct libwebsocket_extension *extensions; const struct lws_extension *extensions;
struct lws_token_limits *token_limits; const struct lws_token_limits *token_limits;
const char *ssl_private_key_password; const char *ssl_private_key_password;
const char *ssl_cert_filepath; const char *ssl_cert_filepath;
const char *ssl_private_key_filepath; const char *ssl_private_key_filepath;
const char *ssl_ca_filepath; const char *ssl_ca_filepath;
const char *ssl_cipher_list; const char *ssl_cipher_list;
const char *http_proxy_address; const char *http_proxy_address;
unsigned int http_proxy_port; unsigned int http_proxy_port;
int gid; int gid;
int uid; int uid;
unsigned int options; unsigned int options;
void *user; void *user;
int ka_time; int ka_time;
int ka_probes; int ka_probes;
int ka_interval; int ka_interval;
#ifdef LWS_OPENSSL_SUPPORT #ifdef LWS_OPENSSL_SUPPORT
SSL_CTX *provided_client_ssl_ctx; SSL_CTX *provided_client_ssl_ctx;
#else /* maintain structure layout either way */ #else /* maintain structure layout either way */
void *provided_client_ssl_ctx; void *provided_client_ssl_ctx;
#endif #endif
/* Add new things just above here ---^
* This is part of the ABI, don't needlessly break compatibilty */
}; };
LWS_VISIBLE LWS_EXTERN LWS_VISIBLE LWS_EXTERN void
void lws_set_log_level(int level, lws_set_log_level(int level,
void (*log_emit_function)(int level, const char *lin void (*log_emit_function)(int level, const char *line));
e));
LWS_VISIBLE LWS_EXTERN void LWS_VISIBLE LWS_EXTERN void
lwsl_emit_syslog(int level, const char *line); lwsl_emit_syslog(int level, const char *line);
LWS_VISIBLE LWS_EXTERN struct libwebsocket_context * LWS_VISIBLE LWS_EXTERN struct lws_context *
libwebsocket_create_context(struct lws_context_creation_info *info); lws_create_context(struct lws_context_creation_info *info);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_set_proxy(struct libwebsocket_context *context, const char *pr oxy); lws_set_proxy(struct lws_context *context, const char *proxy);
LWS_VISIBLE LWS_EXTERN void LWS_VISIBLE LWS_EXTERN void
libwebsocket_context_destroy(struct libwebsocket_context *context); lws_context_destroy(struct lws_context *context);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_service(struct libwebsocket_context *context, int timeout_ms); lws_service(struct lws_context *context, int timeout_ms);
LWS_VISIBLE LWS_EXTERN void LWS_VISIBLE LWS_EXTERN void
libwebsocket_cancel_service(struct libwebsocket_context *context); lws_cancel_service(struct lws_context *context);
LWS_VISIBLE LWS_EXTERN const unsigned char * LWS_VISIBLE LWS_EXTERN const unsigned char *
lws_token_to_string(enum lws_token_indexes token); lws_token_to_string(enum lws_token_indexes token);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_add_http_header_by_name(struct libwebsocket_context *context, lws_add_http_header_by_name(struct lws *wsi, const unsigned char *name,
struct libwebsocket *wsi, const unsigned char *value, int length,
const unsigned char *name, unsigned char **p, unsigned char *end);
const unsigned char *value,
int length,
unsigned char **p,
unsigned char *end);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_finalize_http_header(struct libwebsocket_context *context, lws_finalize_http_header(struct lws *wsi, unsigned char **p,
struct libwebsocket *wsi, unsigned char *end);
unsigned char **p,
unsigned char *end);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_add_http_header_by_token(struct libwebsocket_context *context, lws_add_http_header_by_token(struct lws *wsi, enum lws_token_indexes token,
struct libwebsocket *wsi, const unsigned char *value, int length,
enum lws_token_indexes token, unsigned char **p, unsigned char *end);
const unsigned char *value,
int length,
unsigned char **p,
unsigned char *end);
LWS_VISIBLE LWS_EXTERN int lws_add_http_header_content_length(struct libweb
socket_context *context,
struct libwebsocket *wsi,
unsigned long content_length,
unsigned char **p,
unsigned char *end);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_add_http_header_status(struct libwebsocket_context *context, lws_add_http_header_content_length(struct lws *wsi,
struct libwebsocket *wsi, unsigned long content_length,
unsigned int code, unsigned char **p, unsigned char *end);
unsigned char **p, LWS_VISIBLE LWS_EXTERN int
unsigned char *end); lws_add_http_header_status(struct lws *wsi,
unsigned int code, unsigned char **p,
unsigned char *end);
LWS_EXTERN int lws_http_transaction_completed(struct libwebsocket *wsi); LWS_EXTERN int
lws_http_transaction_completed(struct lws *wsi);
#ifdef LWS_USE_LIBEV #ifdef LWS_USE_LIBEV
typedef void (lws_ev_signal_cb)(EV_P_ struct ev_signal *w, int revents); typedef void (lws_ev_signal_cb)(EV_P_ struct ev_signal *w, int revents);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_sigint_cfg( lws_sigint_cfg(struct lws_context *context, int use_ev_sigint,
struct libwebsocket_context *context, lws_ev_signal_cb *cb);
int use_ev_sigint,
lws_ev_signal_cb* cb);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_initloop( lws_initloop(struct lws_context *context, struct ev_loop *loop);
struct libwebsocket_context *context, struct ev_loop *loop);
LWS_VISIBLE void LWS_VISIBLE void
libwebsocket_sigint_cb( lws_sigint_cb(struct ev_loop *loop, struct ev_signal *watcher, int revents)
struct ev_loop *loop, struct ev_signal *watcher, int revents); ;
#endif /* LWS_USE_LIBEV */ #endif /* LWS_USE_LIBEV */
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_service_fd(struct libwebsocket_context *context, lws_service_fd(struct lws_context *context, struct lws_pollfd *pollfd);
struct libwebsocket
_pollfd *pollfd);
LWS_VISIBLE LWS_EXTERN void * LWS_VISIBLE LWS_EXTERN void *
libwebsocket_context_user(struct libwebsocket_context *context); lws_context_user(struct lws_context *context);
LWS_VISIBLE LWS_EXTERN void *
lws_wsi_user(struct lws *wsi);
/*
* NOTE: These public enums are part of the abi. If you want to add one,
* add it at where specified so existing users are unaffected.
*/
enum pending_timeout { enum pending_timeout {
NO_PENDING_TIMEOUT = 0, NO_PENDING_TIMEOUT = 0,
PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE, PENDING_TIMEOUT_AWAITING_PROXY_RESPONSE = 1,
PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE, PENDING_TIMEOUT_AWAITING_CONNECT_RESPONSE = 2,
PENDING_TIMEOUT_ESTABLISH_WITH_SERVER, PENDING_TIMEOUT_ESTABLISH_WITH_SERVER = 3,
PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE, PENDING_TIMEOUT_AWAITING_SERVER_RESPONSE = 4,
PENDING_TIMEOUT_AWAITING_PING, PENDING_TIMEOUT_AWAITING_PING = 5,
PENDING_TIMEOUT_CLOSE_ACK, PENDING_TIMEOUT_CLOSE_ACK = 6,
PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE, PENDING_TIMEOUT_AWAITING_EXTENSION_CONNECT_RESPONSE = 7,
PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE, PENDING_TIMEOUT_SENT_CLIENT_HANDSHAKE = 8,
PENDING_TIMEOUT_SSL_ACCEPT, PENDING_TIMEOUT_SSL_ACCEPT = 9,
PENDING_TIMEOUT_HTTP_CONTENT, PENDING_TIMEOUT_HTTP_CONTENT = 10,
PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND, PENDING_TIMEOUT_AWAITING_CLIENT_HS_SEND = 11,
PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE, PENDING_FLUSH_STORED_SEND_BEFORE_CLOSE = 12,
/****** add new things just above ---^ ******/
}; };
LWS_VISIBLE LWS_EXTERN void LWS_VISIBLE LWS_EXTERN void
libwebsocket_set_timeout(struct libwebsocket *wsi, lws_set_timeout(struct lws *wsi, enum pending_timeout reason, int secs);
enum pending_timeout reason, int se
cs);
/* /*
* IMPORTANT NOTICE! * IMPORTANT NOTICE!
* *
* When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY ) * When sending with websocket protocol (LWS_WRITE_TEXT or LWS_WRITE_BINARY )
* the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFO RE * the send buffer has to have LWS_SEND_BUFFER_PRE_PADDING bytes valid BEFO RE
* buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len). * buf, and LWS_SEND_BUFFER_POST_PADDING bytes valid AFTER (buf + len).
* *
* This allows us to add protocol info before and after the data, and send as * This allows us to add protocol info before and after the data, and send as
* one packet on the network without payload copying, for maximum efficienc y. * one packet on the network without payload copying, for maximum efficienc y.
* *
* So for example you need this kind of code to use libwebsocket_write with a * So for example you need this kind of code to use lws_write with a
* 128-byte payload * 128-byte payload
* *
* char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADD ING]; * char buf[LWS_SEND_BUFFER_PRE_PADDING + 128 + LWS_SEND_BUFFER_POST_PADD ING];
* *
* // fill your part of the buffer... for example here it's all zeros * // fill your part of the buffer... for example here it's all zeros
* memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128); * memset(&buf[LWS_SEND_BUFFER_PRE_PADDING], 0, 128);
* *
* libwebsocket_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128, * lws_write(wsi, &buf[LWS_SEND_BUFFER_PRE_PADDING], 128, LWS_WRITE_TEXT)
* LWS_WRITE_TE ;
XT);
* *
* When sending LWS_WRITE_HTTP, there is no protocol addition and you can j ust * When sending LWS_WRITE_HTTP, there is no protocol addition and you can j ust
* use the whole buffer without taking care of the above. * use the whole buffer without taking care of the above.
*/ */
/* /*
* this is the frame nonce plus two header plus 8 length * this is the frame nonce plus two header plus 8 length
* there's an additional two for mux extension per mux nesting level * there's an additional two for mux extension per mux nesting level
* 2 byte prepend on close will already fit because control frames cannot u se * 2 byte prepend on close will already fit because control frames cannot u se
* the big length style * the big length style
*/ */
// Pad LWS_SEND_BUFFER_PRE_PADDING to the CPU word size, so that word refer /*
ences * Pad LWS_SEND_BUFFER_PRE_PADDING to the CPU word size, so that word refer
// to the address immediately after the padding won't cause an unaligned ac ences
cess * to the address immediately after the padding won't cause an unaligned ac
// error. Sometimes the recommended padding is even larger than the size of cess
a void *. * error. Sometimes for performance reasons the recommended padding is even
// For example, for the X86-64 architecture, in Intel's document * larger than sizeof(void *).
// https://software.intel.com/en-us/articles/data-alignment-when-migrating- */
to-64-bit-intel-architecture
// they recommend that structures larger than 16 bytes be aligned to 16-byt #if !defined(LWS_SIZEOFPTR)
e #define LWS_SIZEOFPTR (sizeof (void *))
// boundaries. #endif
// #if !defined(u_int64_t)
#define u_int64_t unsigned long long
#endif
#if __x86_64__ #if __x86_64__
#define _LWS_PAD_SIZE 16 // Intel recommended for best performance. #define _LWS_PAD_SIZE 16 /* Intel recommended for best performance */
#else #else
#define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target ar chitecture */ #define _LWS_PAD_SIZE LWS_SIZEOFPTR /* Size of a pointer on the target ar ch */
#endif #endif
#define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? ((n) + (_LWS_PAD_SIZE - ((n) % #define _LWS_PAD(n) (((n) % _LWS_PAD_SIZE) ? \
_LWS_PAD_SIZE))) : (n)) ((n) + (_LWS_PAD_SIZE - ((n) % _LWS_PAD_SIZE))) : (n))
#define LWS_SEND_BUFFER_PRE_PADDING _LWS_PAD(4 + 10 + (2 * MAX_MUX_RECURSIO N)) #define LWS_SEND_BUFFER_PRE_PADDING _LWS_PAD(4 + 10 + (2 * MAX_MUX_RECURSIO N))
#define LWS_SEND_BUFFER_POST_PADDING 4 #define LWS_SEND_BUFFER_POST_PADDING 4
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_write(struct libwebsocket *wsi, unsigned char *buf, size_t len lws_write(struct lws *wsi, unsigned char *buf, size_t len,
, enum lws_write_protocol protocol);
enum libwebsocket_write_protocol protoc
ol);
/* helper for case where buffer may be const */ /* helper for case where buffer may be const */
#define libwebsocket_write_http(wsi, buf, len) \ #define lws_write_http(wsi, buf, len) \
libwebsocket_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP) lws_write(wsi, (unsigned char *)(buf), len, LWS_WRITE_HTTP)
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsockets_serve_http_file(struct libwebsocket_context *context, lws_serve_http_file(struct lws *wsi, const char *file, const char *content_
struct libwebsocket *wsi, const char *file, type,
const char *content_type, const char *other_headers, const char *other_headers, int other_headers_len);
int other_headers_len);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsockets_serve_http_file_fragment(struct libwebsocket_context *context lws_serve_http_file_fragment(struct lws *wsi);
,
struct libwebsocket *wsi);
LWS_VISIBLE LWS_EXTERN int libwebsockets_return_http_status( LWS_VISIBLE LWS_EXTERN int
struct libwebsocket_context *context, lws_return_http_status(struct lws *wsi, unsigned int code,
struct libwebsocket *wsi, unsigned int code, const char *html_body);
const char *html_bod
y);
LWS_VISIBLE LWS_EXTERN const struct libwebsocket_protocols * LWS_VISIBLE LWS_EXTERN const struct lws_protocols *
libwebsockets_get_protocol(struct libwebsocket *wsi); lws_get_protocol(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_callback_on_writable(struct libwebsocket_context *context, lws_callback_on_writable(struct lws *wsi);
struct libwebsocket *w
si);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_callback_on_writable_all_protocol( lws_callback_on_writable_all_protocol(const struct lws_context *context,
const struct libwebsocket_protocols *protoc const struct lws_protocols *protocol);
ol);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_callback_all_protocol( lws_callback_all_protocol(struct lws_context *context,
const struct libwebsocket_protocols *protocol, int reason); const struct lws_protocols *protocol, int reason);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_get_socket_fd(struct libwebsocket *wsi); lws_get_socket_fd(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_is_final_fragment(struct libwebsocket *wsi); lws_is_final_fragment(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN unsigned char LWS_VISIBLE LWS_EXTERN unsigned char
libwebsocket_get_reserved_bits(struct libwebsocket *wsi); lws_get_reserved_bits(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_rx_flow_control(struct libwebsocket *wsi, int enable); lws_rx_flow_control(struct lws *wsi, int enable);
LWS_VISIBLE LWS_EXTERN void LWS_VISIBLE LWS_EXTERN void
libwebsocket_rx_flow_allow_all_protocol( lws_rx_flow_allow_all_protocol(const struct lws_context *context,
const struct libwebsocket_protocols *protoco const struct lws_protocols *protocol);
l);
LWS_VISIBLE LWS_EXTERN size_t LWS_VISIBLE LWS_EXTERN size_t
libwebsockets_remaining_packet_payload(struct libwebsocket *wsi); lws_remaining_packet_payload(struct lws *wsi);
/* /*
* if the protocol does not have any guidence, returns -1. Currently only * if the protocol does not have any guidance, returns -1. Currently only
* http2 connections get send window information from this API. But your c ode * http2 connections get send window information from this API. But your c ode
* should use it so it can work properly with any protocol. * should use it so it can work properly with any protocol.
* *
* If nonzero return is the amount of payload data the peer or intermediary has * If nonzero return is the amount of payload data the peer or intermediary has
* reported it has buffer space for. That has NO relationship with the amo unt * reported it has buffer space for. That has NO relationship with the amo unt
* of buffer space your OS can accept on this connection for a write action . * of buffer space your OS can accept on this connection for a write action .
* *
* This number represents the maximum you could send to the peer or interme diary * This number represents the maximum you could send to the peer or interme diary
* on this connection right now without it complaining. * on this connection right now without it complaining.
* *
* lws manages accounting for send window updates and payload writes * lws manages accounting for send window updates and payload writes
* automatically, so this number reflects the situation at the peer or * automatically, so this number reflects the situation at the peer or
* intermediary dynamically. * intermediary dynamically.
*/ */
LWS_VISIBLE LWS_EXTERN size_t LWS_VISIBLE LWS_EXTERN size_t
lws_get_peer_write_allowance(struct libwebsocket *wsi); lws_get_peer_write_allowance(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN struct libwebsocket * LWS_VISIBLE LWS_EXTERN struct lws *
libwebsocket_client_connect(struct libwebsocket_context *clients, lws_client_connect(struct lws_context *clients, const char *address,
const char *address, int port, int ssl_connection, const char *path,
int port, const char *host, const char *origin, const char *protoco
int ssl_connection, l,
const char *path, int ietf_version_or_minus_one);
const char *host,
const char *origin,
const char *protocol,
int ietf_version_or_minus_one);
LWS_VISIBLE LWS_EXTERN struct libwebsocket * LWS_VISIBLE LWS_EXTERN struct lws *
libwebsocket_client_connect_extended(struct libwebsocket_context *clients, lws_client_connect_extended(struct lws_context *clients, const char *addres
const char *address, s,
int port, int port, int ssl_connection, const char *path,
int ssl_connection, const char *host, const char *origin,
const char *path, const char *protocol, int ietf_version_or_minus_
const char *host, one,
const char *origin, void *userdata);
const char *protocol,
int ietf_version_or_minus_one,
void *userdata);
LWS_VISIBLE LWS_EXTERN const char * LWS_VISIBLE LWS_EXTERN const char *
libwebsocket_canonical_hostname(struct libwebsocket_context *context); lws_canonical_hostname(struct lws_context *context);
LWS_VISIBLE LWS_EXTERN void LWS_VISIBLE LWS_EXTERN void
libwebsockets_get_peer_addresses(struct libwebsocket_context *context, lws_get_peer_addresses(struct lws *wsi,
struct libwebsocket *wsi, int fd, char *name, int name_len, lws_sockfd_type fd, char *name, int name_len,
char *rip, int rip_len); char *rip, int rip_len);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsockets_get_random(struct libwebsocket_context *context, lws_get_random(struct lws_context *context, void *buf, int len);
void *buf, int l
en);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_daemonize(const char *_lock_path); lws_daemonize(const char *_lock_path);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_send_pipe_choked(struct libwebsocket *wsi); lws_send_pipe_choked(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_partial_buffered(struct libwebsocket *wsi); lws_partial_buffered(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_frame_is_binary(struct libwebsocket *wsi); lws_frame_is_binary(struct lws *wsi);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_is_ssl(struct libwebsocket *wsi); lws_is_ssl(struct lws *wsi);
#ifdef LWS_SHA1_USE_OPENSSL_NAME #ifdef LWS_SHA1_USE_OPENSSL_NAME
#define libwebsockets_SHA1 SHA1 #define lws_SHA1 SHA1
#else #else
LWS_VISIBLE LWS_EXTERN unsigned char * LWS_VISIBLE LWS_EXTERN unsigned char *
libwebsockets_SHA1(const unsigned char *d, size_t n, unsigned char *md); lws_SHA1(const unsigned char *d, size_t n, unsigned char *md);
#endif #endif
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_b64_encode_string(const char *in, int in_len, char *out, int out_size); lws_b64_encode_string(const char *in, int in_len, char *out, int out_size);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_b64_decode_string(const char *in, char *out, int out_size); lws_b64_decode_string(const char *in, char *out, int out_size);
LWS_VISIBLE LWS_EXTERN const char * LWS_VISIBLE LWS_EXTERN const char *
lws_get_library_version(void); lws_get_library_version(void);
/* access to headers... only valid while headers valid */ /*
* Access to http headers
*
* In lws the client http headers are temporarily malloc'd only for the
* duration of the http part of the handshake. It's because in most cases
,
* the header content is ignored for the whole rest of the connection life
time
* and would then just be taking up space needlessly.
*
* During LWS_CALLBACK_HTTP when the URI path is delivered is the last tim
e
* the http headers are still allocated, you can use these apis then to
* look at and copy out interesting header content (cookies, etc)
*/
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_hdr_total_length(struct libwebsocket *wsi, enum lws_token_indexes h); lws_hdr_total_length(struct lws *wsi, enum lws_token_indexes h);
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
lws_hdr_copy(struct libwebsocket *wsi, char *dest, int len, lws_hdr_fragment_length(struct lws *wsi, enum lws_token_indexes h, int frag
enum lws_token_indexes h); _idx);
/*
* copies the whole, aggregated header, even if it was delivered in
* several actual headers piece by piece
*/
LWS_VISIBLE LWS_EXTERN int
lws_hdr_copy(struct lws *wsi, char *dest, int len, enum lws_token_indexes h
);
/*
* copies only fragment frag_idx of a header. Normally this is only useful
* to parse URI arguments like ?x=1&y=2, oken index WSI_TOKEN_HTTP_URI_ARGS
* fragment 0 will contain "x=1" and fragment 1 "y=2"
*/
LWS_VISIBLE LWS_EXTERN int
lws_hdr_copy_fragment(struct lws *wsi, char *dest, int len,
enum lws_token_indexes h, int frag_idx);
/* get the active file operations struct */
LWS_VISIBLE LWS_EXTERN struct lws_plat_file_ops *
lws_get_fops(struct lws_context *context);
LWS_VISIBLE LWS_EXTERN struct lws_context *
lws_get_context(const struct lws *wsi);
/*
* Wsi-associated File Operations access helpers
*
* Use these helper functions if you want to access a file from the perspec
tive
* of a specific wsi, which is usually the case. If you just want contextl
ess
* file access, use the fops callbacks directly with NULL wsi instead of th
ese
* helpers.
*
* If so, then it calls the platform handler or user overrides where presen
t
* (as defined in info->fops)
*
* The advantage from all this is user code can be portable for file operat
ions
* without having to deal with differences between platforms.
*/
static LWS_INLINE lws_filefd_type
lws_plat_file_open(struct lws *wsi, const char *filename,
unsigned long *filelen, int flags)
{
return lws_get_fops(lws_get_context(wsi))->open(wsi, filename,
filelen, flags);
}
static LWS_INLINE int
lws_plat_file_close(struct lws *wsi, lws_filefd_type fd)
{
return lws_get_fops(lws_get_context(wsi))->close(wsi, fd);
}
static LWS_INLINE unsigned long
lws_plat_file_seek_cur(struct lws *wsi, lws_filefd_type fd, long offset)
{
return lws_get_fops(lws_get_context(wsi))->seek_cur(wsi, fd, offset)
;
}
static LWS_INLINE int
lws_plat_file_read(struct lws *wsi, lws_filefd_type fd, unsigned long *amou
nt,
unsigned char *buf, unsigned long len)
{
return lws_get_fops(lws_get_context(wsi))->read(wsi, fd, amount, buf
, len);
}
static LWS_INLINE int
lws_plat_file_write(struct lws *wsi, lws_filefd_type fd, unsigned long *amo
unt,
unsigned char *buf, unsigned long len)
{
return lws_get_fops(lws_get_context(wsi))->write(wsi, fd, amount, bu
f, len);
}
/* /*
* Note: this is not normally needed as a user api. It's provided in case it is * Note: this is not normally needed as a user api. It's provided in case it is
* useful when integrating with other app poll loop service code. * useful when integrating with other app poll loop service code.
*/ */
LWS_VISIBLE LWS_EXTERN int LWS_VISIBLE LWS_EXTERN int
libwebsocket_read(struct libwebsocket_context *context, lws_read(struct lws *wsi, unsigned char *buf, size_t len);
struct libwebsocket *wsi,
unsigned char *buf, size_t le
n);
#ifndef LWS_NO_EXTENSIONS #ifndef LWS_NO_EXTENSIONS
LWS_VISIBLE LWS_EXTERN struct libwebsocket_extension *libwebsocket_get_inte rnal_extensions(); LWS_VISIBLE LWS_EXTERN struct lws_extension *lws_get_internal_extensions();
#endif #endif
/* /*
* custom allocator support * custom allocator support
*/ */
LWS_VISIBLE LWS_EXTERN void LWS_VISIBLE LWS_EXTERN void
lws_set_allocator(void *(*realloc)(void *ptr, size_t size)); lws_set_allocator(void *(*realloc)(void *ptr, size_t size));
#ifdef __cplusplus #ifdef __cplusplus
} }
 End of changes. 131 change blocks. 
414 lines changed or deleted 677 lines changed or added


 lws_config.h (1.5.1)   lws_config.h (1.6.1) 
skipping to change at line 18 skipping to change at line 18
/* Define to 1 to use wolfSSL/CyaSSL as a replacement for OpenSSL. /* Define to 1 to use wolfSSL/CyaSSL as a replacement for OpenSSL.
* LWS_OPENSSL_SUPPORT needs to be set also for this to work. */ * LWS_OPENSSL_SUPPORT needs to be set also for this to work. */
/* #undef USE_WOLFSSL */ /* #undef USE_WOLFSSL */
/* Also define to 1 (in addition to USE_WOLFSSL) when using the /* Also define to 1 (in addition to USE_WOLFSSL) when using the
(older) CyaSSL library */ (older) CyaSSL library */
/* #undef USE_OLD_CYASSL */ /* #undef USE_OLD_CYASSL */
/* The Libwebsocket version */ /* The Libwebsocket version */
#define LWS_LIBRARY_VERSION "1.5" #define LWS_LIBRARY_VERSION "1.6.1"
#define LWS_LIBRARY_VERSION_MAJOR 1
#define LWS_LIBRARY_VERSION_MINOR 6
#define LWS_LIBRARY_VERSION_PATCH 1
/* LWS_LIBRARY_VERSION_NUMBER looks like 1005001 for e.g. version 1.5.1 */
#define LWS_LIBRARY_VERSION_NUMBER (LWS_LIBRARY_VERSION_MAJOR*1000000)+(LWS
_LIBRARY_VERSION_MINOR*1000)+LWS_LIBRARY_VERSION_PATCH
/* The current git commit hash that we're building from */ /* The current git commit hash that we're building from */
/* #undef LWS_BUILD_HASH */ /* #undef LWS_BUILD_HASH */
/* Build with OpenSSL support */ /* Build with OpenSSL support */
#define LWS_OPENSSL_SUPPORT #define LWS_OPENSSL_SUPPORT
/* The client should load and trust CA root certs it finds in the OS */ /* The client should load and trust CA root certs it finds in the OS */
#define LWS_SSL_CLIENT_USE_OS_CA_CERTS #define LWS_SSL_CLIENT_USE_OS_CA_CERTS
skipping to change at line 64 skipping to change at line 70
/* #undef LWS_NO_CLIENT */ /* #undef LWS_NO_CLIENT */
/* If we should compile with MinGW support */ /* If we should compile with MinGW support */
/* #undef LWS_MINGW_SUPPORT */ /* #undef LWS_MINGW_SUPPORT */
/* Use the BSD getifaddrs that comes with libwebsocket, for uclibc support */ /* Use the BSD getifaddrs that comes with libwebsocket, for uclibc support */
/* #undef LWS_BUILTIN_GETIFADDRS */ /* #undef LWS_BUILTIN_GETIFADDRS */
/* use SHA1() not internal libwebsockets_SHA1 */ /* use SHA1() not internal libwebsockets_SHA1 */
/* #undef LWS_SHA1_USE_OPENSSL_NAME */ /* #undef LWS_SHA1_USE_OPENSSL_NAME */
#define LWS_SIZEOFPTR 4
 End of changes. 2 change blocks. 
1 lines changed or deleted 8 lines changed or added

This html diff was produced by rfcdiff 1.41.The latest version is available from http://tools.ietf.org/tools/rfcdiff/