return NULL;
failed:
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return NULL;
}
#include "private-libwebsockets.h"
-int libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
+int lws_client_rx_sm(struct libwebsocket *wsi, unsigned char c)
{
int callback_action = LWS_CALLBACK_CLIENT_RECEIVE;
int handled;
case LWS_CONNMODE_WS_CLIENT_WAITING_EXTENSION_CONNECT:
case LWS_CONNMODE_WS_CLIENT:
for (n = 0; n < len; n++)
- if (libwebsocket_client_rx_sm(wsi, *(*buf)++)) {
+ if (lws_client_rx_sm(wsi, *(*buf)++)) {
lwsl_debug("client_rx_sm failed\n");
return 1;
}
lwsl_warn("Proxy connection %p (fd=%d) dead\n",
(void *)wsi, pollfd->fd);
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return 0;
}
return 0;
}
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
lwsl_err("ERROR reading from proxy socket\n");
return 0;
if (strcmp((char *)context->service_buffer, "HTTP/1.0 200 ") &&
strcmp((char *)context->service_buffer, "HTTP/1.1 200 ")
) {
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
lwsl_err("ERROR proxy: %s\n", context->service_buffer);
return 0;
} else {
lwsl_err("server's cert didn't look good, X509_V_ERR = %d: %s\n",
n, ERR_error_string(n, (char *)context->service_buffer));
- libwebsocket_close_and_free_session(context,
+ lws_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS);
return 0;
}
/* fallthru */
case LWS_CONNMODE_WS_CLIENT_ISSUE_HANDSHAKE2:
- p = libwebsockets_generate_client_handshake(context, wsi, p);
+ p = lws_generate_client_handshake(context, wsi, p);
if (p == NULL) {
lwsl_err("Failed to generate handshake for client\n");
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return 0;
}
switch (n) {
case LWS_SSL_CAPABLE_ERROR:
lwsl_debug("ERROR writing to client socket\n");
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return 0;
case LWS_SSL_CAPABLE_MORE_SERVICE:
return 0;
}
- if (libwebsocket_parse(context, wsi, c)) {
+ if (lws_parse(context, wsi, c)) {
lwsl_warn("problems parsing header\n");
goto bail3;
}
bail3:
lwsl_info(
"closing connection at LWS_CONNMODE...SERVER_REPLY\n");
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return -1;
}
/* allocate the per-connection user memory (if any) */
- if (libwebsocket_ensure_user_space(wsi)) {
+ if (lws_ensure_user_space(wsi)) {
lwsl_err("Problem allocating wsi user mem\n");
goto bail2;
}
lws_free2(wsi->u.hdr.ah);
- libwebsocket_close_and_free_session(context, wsi, close_reason);
+ lws_close_and_free_session(context, wsi, close_reason);
return 1;
}
char *
-libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
+lws_generate_client_handshake(struct libwebsocket_context *context,
struct libwebsocket *wsi, char *pkt)
{
char buf[128];
if (n != 16) {
lwsl_err("Unable to read from random dev %s\n",
SYSTEM_RANDOM_FILEPATH);
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return NULL;
}
wsi_from_fd(context, context->fds[n].fd);
if (!wsi)
continue;
- libwebsocket_close_and_free_session(context,
+ lws_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS_CONTEXT_DESTROY /* no protocol close */);
n--;
}
switch (wsi->mode) {
case LWS_CONNMODE_WS_SERVING:
- if (libwebsocket_interpret_incoming_packet(wsi, buf, len) < 0) {
+ if (lws_interpret_incoming_packet(wsi, buf, len) < 0) {
lwsl_info("interpret_incoming_packet has bailed\n");
goto bail;
}
bail:
lwsl_debug("closing connection at lws_read bail:\n");
- libwebsocket_close_and_free_session(context, wsi,
- LWS_CLOSE_STATUS_NOSTATUS);
+ lws_close_and_free_session(context, wsi, LWS_CLOSE_STATUS_NOSTATUS);
return -1;
}
if (lws_frag_append(wsi, c1))
return 1;
} else { /* name */
- if (libwebsocket_parse(context, wsi, c1))
+ if (lws_parse(context, wsi, c1))
return 1;
}
struct libwebsocket *
lws_create_server_child_wsi(struct libwebsocket_context *context, struct libwebsocket *parent_wsi, unsigned int sid)
{
- struct libwebsocket *wsi = libwebsocket_create_new_server_wsi(context);
+ struct libwebsocket *wsi = lws_create_new_server_wsi(context);
if (!wsi)
return NULL;
wsi->mode = parent_wsi->mode;
wsi->protocol = &context->protocols[0];
- libwebsocket_ensure_user_space(wsi);
+ lws_ensure_user_space(wsi);
lwsl_info("%s: %p new child %p, sid %d, user_space=%p\n", __func__, parent_wsi, wsi, sid, wsi->user_space);
}
static void
-libwebsocket_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
+lws_accept_cb(struct ev_loop *loop, struct ev_io *watcher, int revents)
{
struct libwebsocket_pollfd eventfd;
struct lws_io_watcher *lws_io = container_of(watcher, struct lws_io_watcher, watcher);
* Initialize the accept w_accept with the listening socket
* and register a callback for read operations:
*/
- ev_io_init(w_accept, libwebsocket_accept_cb,
+ ev_io_init(w_accept, lws_accept_cb,
context->listen_service_fd, EV_READ);
ev_io_start(context->io_loop,w_accept);
new_wsi->w_read.context = context;
new_wsi->w_write.context = context;
- ev_io_init(r, libwebsocket_accept_cb, accept_fd, EV_READ);
- ev_io_init(w, libwebsocket_accept_cb, accept_fd, EV_WRITE);
+ ev_io_init(r, lws_accept_cb, accept_fd, EV_READ);
+ ev_io_init(w, lws_accept_cb, accept_fd, EV_WRITE);
}
LWS_VISIBLE void
}
void
-libwebsocket_close_and_free_session(struct libwebsocket_context *context,
+lws_close_and_free_session(struct libwebsocket_context *context,
struct libwebsocket *wsi, enum lws_close_status reason)
{
int n, m, ret;
}
LWS_VISIBLE int
-libwebsockets_get_addresses(struct libwebsocket_context *context,
+lws_get_addresses(struct libwebsocket_context *context,
void *ads, char *name, int name_len,
char *rip, int rip_len)
{
goto bail;
}
- ret = libwebsockets_get_addresses(context, p, name, name_len, rip, rip_len);
+ ret = lws_get_addresses(context, p, name, name_len, rip, rip_len);
bail:
lws_latency(context, wsi, "lws_get_peer_addresses", ret, 1);
}
int
-libwebsocket_ensure_user_space(struct libwebsocket *wsi)
+lws_ensure_user_space(struct libwebsocket *wsi)
{
lwsl_info("%s: %p protocol %p\n", __func__, wsi, wsi->protocol);
if (!wsi->protocol)
void lws_conn::onDisconnect(TCPStream *s)
{
(void)s;
- libwebsocket_close_and_free_session(wsi->protocol->owning_server, wsi,
+ lws_close_and_free_session(wsi->protocol->owning_server, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
}
#include "private-libwebsockets.h"
static int
-libwebsocket_0405_frame_mask_generate(struct libwebsocket *wsi)
+lws_0405_frame_mask_generate(struct libwebsocket *wsi)
{
int n;
if (wsi->mode == LWS_CONNMODE_WS_CLIENT) {
if (!wsi->u.ws.inside_frame)
- if (libwebsocket_0405_frame_mask_generate(wsi)) {
+ if (lws_0405_frame_mask_generate(wsi)) {
lwsl_err("frame mask generation failed\n");
return -1;
}
return 1;
}
-int libwebsocket_parse(
+int lws_parse(
struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned char c)
{
issue_char(wsi, '%');
wsi->u.hdr.ues = URIES_IDLE;
/* regurgitate + assess */
- if (libwebsocket_parse(context, wsi, wsi->u.hdr.esc_stash) < 0)
+ if (lws_parse(context, wsi, wsi->u.hdr.esc_stash) < 0)
return -1;
/* continue on to assess c */
break;
}
int
-libwebsocket_rx_sm(struct libwebsocket *wsi, unsigned char c)
+lws_rx_sm(struct libwebsocket *wsi, unsigned char c)
{
struct lws_tokens eff_buf;
int ret = 0;
#ifdef _WIN32
#define LWS_FD_HASH(fd) ((fd ^ (fd >> 8) ^ (fd >> 16)) % FD_HASHTABLE_MODULUS)
-struct libwebsocket_fd_hashtable {
+struct lws_fd_hashtable {
struct libwebsocket **wsi;
int length;
};
struct libwebsocket_pollfd *fds;
#ifdef _WIN32
/* different implementation between unix and windows */
- struct libwebsocket_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
+ struct lws_fd_hashtable fd_hashtable[FD_HASHTABLE_MODULUS];
#else
struct libwebsocket **lws_lookup; /* fd to wsi */
#endif
LWS_EXTERN int log_level;
LWS_EXTERN void
-libwebsocket_close_and_free_session(struct libwebsocket_context *context,
+lws_close_and_free_session(struct libwebsocket_context *context,
struct libwebsocket *wsi, enum lws_close_status);
LWS_EXTERN int
struct libwebsocket *wsi,
enum lws_pending_protocol_send pend);
LWS_EXTERN int
-libwebsocket_client_rx_sm(struct libwebsocket *wsi, unsigned char c);
+lws_client_rx_sm(struct libwebsocket *wsi, unsigned char c);
LWS_EXTERN int
-libwebsocket_parse(struct libwebsocket_context *context,
+lws_parse(struct libwebsocket_context *context,
struct libwebsocket *wsi, unsigned char c);
LWS_EXTERN int
struct libwebsocket *wsi);
LWS_EXTERN struct libwebsocket *
-libwebsocket_create_new_server_wsi(struct libwebsocket_context *context);
+lws_create_new_server_wsi(struct libwebsocket_context *context);
LWS_EXTERN char *
-libwebsockets_generate_client_handshake(struct libwebsocket_context *context,
+lws_generate_client_handshake(struct libwebsocket_context *context,
struct libwebsocket *wsi, char *pkt);
LWS_EXTERN int
struct libwebsocket *wsi);
LWS_EXTERN int
-libwebsocket_rx_sm(struct libwebsocket *wsi, unsigned char c);
+lws_rx_sm(struct libwebsocket *wsi, unsigned char c);
LWS_EXTERN int
lws_issue_raw_ext_access(struct libwebsocket *wsi,
enum lws_token_indexes h, const char *s);
LWS_EXTERN int
-libwebsocket_ensure_user_space(struct libwebsocket *wsi);
+lws_ensure_user_space(struct libwebsocket *wsi);
LWS_EXTERN int
lws_change_pollfd(struct libwebsocket *wsi, int _and, int _or);
LWS_EXTERN int handshake_0405(struct libwebsocket_context *context,
struct libwebsocket *wsi);
LWS_EXTERN int
-libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
+lws_interpret_incoming_packet(struct libwebsocket *wsi,
unsigned char *buf, size_t len);
LWS_EXTERN void
lws_server_get_canonical_hostname(struct libwebsocket_context *context,
struct lws_context_creation_info *info);
#else
#define lws_context_init_server(_a, _b) (0)
-#define libwebsocket_interpret_incoming_packet(_a, _b, _c) (0)
+#define lws_interpret_incoming_packet(_a, _b, _c) (0)
#define lws_server_get_canonical_hostname(_a, _b)
#endif
#endif
LWS_EXTERN int lws_handshake_client(struct libwebsocket *wsi, unsigned char **buf, size_t len);
LWS_EXTERN void
- libwebsockets_decode_ssl_error(void);
+ lws_decode_ssl_error(void);
#else
#define lws_context_init_client_ssl(_a, _b) (0)
#define lws_handshake_client(_a, _b, _c) (0)
#define lws_handshake_server(_a, _b, _c, _d) (0)
#endif
-LWS_EXTERN int libwebsockets_get_addresses(struct libwebsocket_context *context,
+LWS_EXTERN int lws_get_addresses(struct libwebsocket_context *context,
void *ads, char *name, int name_len,
char *rip, int rip_len);
}
/* allocate the per-connection user memory (if any) */
- if (libwebsocket_ensure_user_space(wsi))
+ if (lws_ensure_user_space(wsi))
goto bail;
/* create the response packet */
goto bail_nuke_ah;
}
- if (libwebsocket_ensure_user_space(wsi))
+ if (lws_ensure_user_space(wsi))
goto bail_nuke_ah;
for (n = 0; n < ARRAY_SIZE(methods); n++)
/* LWS_CONNMODE_WS_SERVING */
while (len--) {
- if (libwebsocket_parse(context, wsi, *(*buf)++)) {
- lwsl_info("libwebsocket_parse failed\n");
+ if (lws_parse(context, wsi, *(*buf)++)) {
+ lwsl_info("lws_parse failed\n");
goto bail_nuke_ah;
}
if (wsi->u.hdr.parser_state != WSI_PARSING_COMPLETE)
continue;
- lwsl_parser("libwebsocket_parse sees parsing complete\n");
+ lwsl_parser("lws_parse sees parsing complete\n");
wsi->mode = LWS_CONNMODE_PRE_WS_SERVING_ACCEPT;
lws_set_timeout(wsi, NO_PENDING_TIMEOUT, 0);
}
/* allocate wsi->user storage */
- if (libwebsocket_ensure_user_space(wsi))
+ if (lws_ensure_user_space(wsi))
goto bail_nuke_ah;
/*
}
struct libwebsocket *
-libwebsocket_create_new_server_wsi(struct libwebsocket_context *context)
+lws_create_new_server_wsi(struct libwebsocket_context *context)
{
struct libwebsocket *new_wsi;
lws_free_header_table(wsi);
/* fallthru */
case LWS_SSL_CAPABLE_ERROR:
- libwebsocket_close_and_free_session(
+ lws_close_and_free_session(
context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return 0;
break;
}
- new_wsi = libwebsocket_create_new_server_wsi(context);
+ new_wsi = lws_create_new_server_wsi(context);
if (new_wsi == NULL) {
compatible_close(accept_fd);
break;
return 0;
fail:
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
}
-int libwebsocket_interpret_incoming_packet(struct libwebsocket *wsi,
+int lws_interpret_incoming_packet(struct libwebsocket *wsi,
unsigned char *buf, size_t len)
{
size_t n = 0;
wsi->rxflow_pos++;
/* process the byte */
- m = libwebsocket_rx_sm(wsi, buf[n++]);
+ m = lws_rx_sm(wsi, buf[n++]);
if (m < 0)
return -1;
}
wsi2->u.http2.requested_POLLOUT = 0;
if (lws_calllback_as_writeable(context, wsi2)) {
lwsl_debug("Closing POLLOUT child\n");
- libwebsocket_close_and_free_session(context, wsi2,
+ lws_close_and_free_session(context, wsi2,
LWS_CLOSE_STATUS_NOSTATUS);
}
wsi2 = wsi;
* cleanup like flush partials.
*/
wsi->socket_is_permanently_unusable = 1;
- libwebsocket_close_and_free_session(context,
+ lws_close_and_free_session(context,
wsi, LWS_CLOSE_STATUS_NOSTATUS);
return 1;
}
close_and_handled:
lwsl_debug("Close and handled\n");
- libwebsocket_close_and_free_session(context, wsi,
+ lws_close_and_free_session(context, wsi,
LWS_CLOSE_STATUS_NOSTATUS);
// pollfd points to something else after the close
return 1;
}
LWS_VISIBLE void
-libwebsockets_decode_ssl_error(void)
+lws_decode_ssl_error(void)
{
char buf[256];
u_long err;
if (new_wsi->ssl == NULL) {
lwsl_err("SSL_new failed: %s\n",
ERR_error_string(SSL_get_error(new_wsi->ssl, 0), NULL));
- libwebsockets_decode_ssl_error();
+ lws_decode_ssl_error();
// TODO: Shouldn't the caller handle this?
compatible_close(accept_fd);