#include <mstcpip.h>
#include <io.h>
+#if !defined(LWS_HAVE_ATOLL)
+#if defined(LWS_HAVE__ATOI64)
+#define atoll _atoi64
+#else
+#warning No atoll or _atoi64 available, using atoi
+#define atoll atoi
+#endif
+#endif
+
#ifndef __func__
#define __func__ __FUNCTION__
#endif
LWSCM_WSCL_WAITING_SERVER_REPLY,
LWSCM_WSCL_WAITING_EXTENSION_CONNECT,
LWSCM_WSCL_PENDING_CANDIDATE_CHILD,
+ LWSCM_WSCL_WAITING_SOCKS_GREETING_REPLY,
+ LWSCM_WSCL_WAITING_SOCKS_CONNECT_REPLY,
+ LWSCM_WSCL_WAITING_SOCKS_AUTH_REPLY,
/****** add new things just above ---^ ******/
};
+/* enums of socks version */
+enum socks_version {
+ SOCKS_VERSION_4 = 4,
+ SOCKS_VERSION_5 = 5
+};
+
+/* enums of subnegotiation version */
+enum socks_subnegotiation_version {
+ SOCKS_SUBNEGOTIATION_VERSION_1 = 1,
+};
+
+/* enums of socks commands */
+enum socks_command {
+ SOCKS_COMMAND_CONNECT = 1,
+ SOCKS_COMMAND_BIND = 2,
+ SOCKS_COMMAND_UDP_ASSOCIATE = 3
+};
+
+/* enums of socks address type */
+enum socks_atyp {
+ SOCKS_ATYP_IPV4 = 1,
+ SOCKS_ATYP_DOMAINNAME = 3,
+ SOCKS_ATYP_IPV6 = 4
+};
+
+/* enums of socks authentication methods */
+enum socks_auth_method {
+ SOCKS_AUTH_NO_AUTH = 0,
+ SOCKS_AUTH_GSSAPI = 1,
+ SOCKS_AUTH_USERNAME_PASSWORD = 2
+};
+
+/* enums of subnegotiation status */
+enum socks_subnegotiation_status {
+ SOCKS_SUBNEGOTIATION_STATUS_SUCCESS = 0,
+};
+
+/* enums of socks request reply */
+enum socks_request_reply {
+ SOCKS_REQUEST_REPLY_SUCCESS = 0,
+ SOCKS_REQUEST_REPLY_FAILURE_GENERAL = 1,
+ SOCKS_REQUEST_REPLY_CONNECTION_NOT_ALLOWED = 2,
+ SOCKS_REQUEST_REPLY_NETWORK_UNREACHABLE = 3,
+ SOCKS_REQUEST_REPLY_HOST_UNREACHABLE = 4,
+ SOCKS_REQUEST_REPLY_CONNECTION_REFUSED = 5,
+ SOCKS_REQUEST_REPLY_TTL_EXPIRED = 6,
+ SOCKS_REQUEST_REPLY_COMMAND_NOT_SUPPORTED = 7,
+ SOCKS_REQUEST_REPLY_ATYP_NOT_SUPPORTED = 8
+};
+
+/* enums used to generate socks messages */
+enum socks_msg_type {
+ /* greeting */
+ SOCKS_MSG_GREETING,
+ /* credential, user name and password */
+ SOCKS_MSG_USERNAME_PASSWORD,
+ /* connect command */
+ SOCKS_MSG_CONNECT
+};
+
enum {
LWS_RXFLOW_ALLOW = (1 << 0),
LWS_RXFLOW_PENDING_CHANGE = (1 << 1),
#if !defined(LWS_WITH_ESP8266)
char http_proxy_address[128];
char proxy_basic_auth_token[128];
+#if defined(LWS_WITH_SOCKS5)
+ char socks_proxy_address[128];
+ char socks_user[96];
+ char socks_password[96];
+#endif
#endif
#if defined(LWS_WITH_ESP8266)
/* listen sockets need a place to hang their hat */
struct lws *lserv_wsi;
const char *name;
const char *iface;
+#if !defined(LWS_WITH_ESP8266) && !defined(LWS_WITH_ESP32) && !defined(OPTEE_TA) && !defined(WIN32)
+ int bind_iface;
+#endif
const struct lws_protocols *protocols;
void **protocol_vh_privs;
const struct lws_protocol_vhost_options *pvo;
int listen_port;
unsigned int http_proxy_port;
+#if defined(LWS_WITH_SOCKS5)
+ unsigned int socks_proxy_port;
+#endif
unsigned int options;
int count_protocols;
int ka_time;
int ka_probes;
int ka_interval;
int keepalive_timeout;
+ int ssl_info_event_mask;
#ifdef LWS_WITH_ACCESS_LOG
int log_fd;
#endif
const struct lws_protocol_vhost_options *reject_service_keywords;
lws_reload_func deprecation_cb;
+#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
+ cap_value_t caps[4];
+ char count_caps;
+#endif
+
#if defined(LWS_USE_LIBEV)
lws_ev_signal_cb_t * lws_ev_sigint_cb;
#endif
char worst_latency_info[256];
#endif
+#if defined(LWS_WITH_STATS)
+ uint64_t lws_stats[LWSSTATS_SIZE];
+ uint64_t last_dump;
+ int updated;
+#endif
+
int max_fds;
#if defined(LWS_USE_LIBEV) || defined(LWS_USE_LIBUV) || defined(LWS_USE_LIBEVENT)
int use_ev_sigint;
unsigned int timeout_secs;
unsigned int pt_serv_buf_size;
int max_http_header_data;
+ int simultaneous_ssl_restriction;
+ int simultaneous_ssl;
unsigned int deprecated:1;
unsigned int being_destroyed:1;
unsigned int being_destroyed1:1;
unsigned int requested_kill:1;
unsigned int protocol_init_done:1;
-
+ unsigned int ssl_gate_accepts:1;
/*
* set to the Thread ID that's doing the service loop just before entry
* to poll indicates service thread likely idling in poll()
#else
#define LWS_UNIX_SOCK_ENABLED(vhost) (0)
#endif
+
enum uri_path_states {
URIPS_IDLE,
URIPS_SEEN_SLASH,
char origin[256];
char protocol[256];
char method[16];
+ char iface[16];
};
#endif
enum http_version request_version;
enum http_connection_type connection_type;
- unsigned int content_length;
- unsigned int content_remain;
+ lws_filepos_t content_length;
+ lws_filepos_t content_remain;
};
#ifdef LWS_USE_HTTP2
#ifdef LWS_WITH_CGI
+enum {
+ SIGNIFICANT_HDR_CONTENT_LENGTH,
+ SIGNIFICANT_HDR_LOCATION,
+ SIGNIFICANT_HDR_STATUS,
+ SIGNIFICANT_HDR_TRANSFER_ENCODING,
+
+ SIGNIFICANT_HDR_COUNT
+};
+
/* wsi who is master of the cgi points to an lws_cgi */
struct lws_cgi {
struct lws_cgi *cgi_list;
struct lws *stdwsi[3]; /* points to the associated stdin/out/err wsis */
struct lws *wsi; /* owner */
- unsigned long content_length;
- unsigned long content_length_seen;
+ unsigned char *headers_buf;
+ unsigned char *headers_pos;
+ unsigned char *headers_dumped;
+ unsigned char *headers_end;
+ lws_filepos_t content_length;
+ lws_filepos_t content_length_seen;
int pipe_fds[3][2];
+ int match[SIGNIFICANT_HDR_COUNT];
int pid;
+ int response_code;
+ int lp;
+ char l[12];
unsigned int being_closed:1;
+ unsigned int explicitly_chunked:1;
unsigned char chunked_grace;
};
SSL *ssl;
BIO *client_bio;
struct lws *pending_read_list_prev, *pending_read_list_next;
+#if defined(LWS_WITH_STATS)
+ uint64_t accept_start_us;
+ char seen_rx;
+#endif
#endif
#ifdef LWS_WITH_HTTP_PROXY
struct lws_rewrite *rw;
unsigned long latency_start;
#endif
lws_sock_file_fd_type desc; /* .filefd / .sockfd */
-
+#if defined(LWS_WITH_STATS)
+ uint64_t active_writable_req_us;
+#endif
/* ints */
int position_in_fds_table;
int rxflow_len;
unsigned int sending_chunked:1;
unsigned int already_did_cce:1;
unsigned int told_user_closed:1;
- unsigned int :1;
+
#if defined(LWS_WITH_ESP8266)
unsigned int pending_send_completion:3;
unsigned int close_is_pending_send_completion:1;
unsigned int redirect_to_https:1;
#endif
+ /* volatile to make sure code is aware other thread can change */
+ volatile unsigned int handling_pollout:1;
+ volatile unsigned int leave_pollout_active:1;
+
#ifndef LWS_NO_CLIENT
unsigned short c_port;
#endif
lws_socket_bind(struct lws_vhost *vhost, lws_sockfd_type sockfd, int port,
const char *iface);
+#if defined(LWS_USE_IPV6)
+LWS_EXTERN unsigned long
+lws_get_addr_scope(const char *ipaddr);
+#endif
+
LWS_EXTERN void
lws_close_free_wsi(struct lws *wsi, enum lws_close_status);
#endif
LWS_EXTERN void
lws_ssl_destroy(struct lws_vhost *vhost);
-
/* HTTP2-related */
#ifdef LWS_USE_HTTP2
LWS_EXTERN int
lws_context_init_client_ssl(struct lws_context_creation_info *info,
struct lws_vhost *vhost);
+
+LWS_EXTERN void
+lws_ssl_info_callback(const SSL *ssl, int where, int ret);
+
#else
#define lws_context_init_client_ssl(_a, _b) (0)
#endif
lws_plat_change_pollfd(struct lws_context *context, struct lws *wsi,
struct lws_pollfd *pfd);
LWS_EXTERN void
+lws_add_wsi_to_draining_ext_list(struct lws *wsi);
+LWS_EXTERN void
lws_remove_wsi_from_draining_ext_list(struct lws *wsi);
LWS_EXTERN int
lws_plat_context_early_init(void);
time_in_microseconds(void);
LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT
lws_plat_inet_ntop(int af, const void *src, char *dst, int cnt);
+LWS_EXTERN int LWS_WARN_UNUSED_RESULT
+lws_plat_inet_pton(int af, const char *src, void *dst);
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
lws_check_utf8(unsigned char *state, unsigned char *buf, size_t len);
LWS_EXTERN int alloc_file(struct lws_context *context, const char *filename, uint8_t **buf,
lws_filepos_t *amount);
+LWS_EXTERN int alloc_pem_to_der_file(struct lws_context *context, const char *filename, uint8_t **buf,
+ lws_filepos_t *amount);
+
+LWS_EXTERN void
+lws_same_vh_protocol_remove(struct lws *wsi);
+LWS_EXTERN void
+lws_same_vh_protocol_insert(struct lws *wsi, int n);
+
+#if defined(LWS_WITH_STATS)
+void
+lws_stats_atomic_bump(struct lws_context * context,
+ struct lws_context_per_thread *pt, int index, uint64_t bump);
+void
+lws_stats_atomic_max(struct lws_context * context,
+ struct lws_context_per_thread *pt, int index, uint64_t val);
+#else
+static inline uint64_t lws_stats_atomic_bump(struct lws_context * context,
+ struct lws_context_per_thread *pt, int index, uint64_t bump) {
+ (void)context; (void)pt; (void)index; (void)bump; return 0; }
+static inline uint64_t lws_stats_atomic_max(struct lws_context * context,
+ struct lws_context_per_thread *pt, int index, uint64_t val) {
+ (void)context; (void)pt; (void)index; (void)val; return 0; }
+#endif
+
+/* socks */
+void socks_generate_msg(struct lws *wsi, enum socks_msg_type type,
+ size_t *msg_len);
#ifdef __cplusplus
};