|
|
@@ -1,47 +1,5 @@ |
|
|
|
#include "IZ_wsserver.h" |
|
|
|
|
|
|
|
static struct lws_protocols protocols[] = { |
|
|
|
{ |
|
|
|
.name = NETWORK_PROTOCOL, |
|
|
|
.callback = IZ_WSServerCallback, |
|
|
|
.per_session_data_size = sizeof(IZ_WSServerSessionData), |
|
|
|
.rx_buffer_size = 0, |
|
|
|
.id = 0, |
|
|
|
.user = NULL, |
|
|
|
.tx_packet_size = 0, |
|
|
|
}, |
|
|
|
{ |
|
|
|
.name = "http", |
|
|
|
.callback = lws_callback_http_dummy, |
|
|
|
.per_session_data_size = 0, |
|
|
|
.rx_buffer_size = 0, |
|
|
|
.id = 0, |
|
|
|
.user = NULL, |
|
|
|
.tx_packet_size = 0, |
|
|
|
}, |
|
|
|
LWS_PROTOCOL_LIST_TERM, |
|
|
|
}; |
|
|
|
|
|
|
|
static const struct lws_http_mount mount = { |
|
|
|
.mount_next = NULL, /* linked-list "next" */ |
|
|
|
.mountpoint = "/", /* mountpoint URL */ |
|
|
|
.origin = "./mount-origin", /* serve from dir */ |
|
|
|
.def = "index.html", /* default filename */ |
|
|
|
.protocol = NULL, |
|
|
|
.cgienv = NULL, |
|
|
|
.extra_mimetypes = NULL, |
|
|
|
.interpret = NULL, |
|
|
|
.cgi_timeout = 0, |
|
|
|
.cache_max_age = 0, |
|
|
|
.auth_mask = 0, |
|
|
|
.cache_reusable = 0, |
|
|
|
.cache_revalidate = 0, |
|
|
|
.cache_intermediaries = 0, |
|
|
|
.origin_protocol = LWSMPRO_FILE, /* files in a dir */ |
|
|
|
.mountpoint_len = 1, /* char count */ |
|
|
|
.basic_auth_login_file = NULL, |
|
|
|
}; |
|
|
|
|
|
|
|
static void IZ_ProtocolCullLaggingClients(IZ_WSServerVHostData *vhd) { |
|
|
|
u32 oldest_tail = lws_ring_get_oldest_tail(vhd->ring); |
|
|
|
IZ_WSServerSessionData *old_pss = NULL; |
|
|
@@ -135,8 +93,8 @@ static void IZ_ProtocolCullLaggingClients(IZ_WSServerVHostData *vhd) { |
|
|
|
|
|
|
|
/* destroys the message when everyone has had a copy of it */ |
|
|
|
|
|
|
|
void IZ_ProtocolDestroyMessage(void *_msg) { |
|
|
|
IZ_WSServerMessage *msg = _msg; |
|
|
|
void IZ_ProtocolDestroyMessage(void* msg_raw) { |
|
|
|
IZ_WSServerMessage *msg = msg_raw; |
|
|
|
|
|
|
|
free(msg->payload); |
|
|
|
msg->payload = NULL; |
|
|
@@ -324,13 +282,66 @@ i32 IZ_WSServerCallback( |
|
|
|
return 0; |
|
|
|
} |
|
|
|
|
|
|
|
IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context** context, u16 port) { |
|
|
|
IZ_ProcedureResult IZ_WSServerCreateContext(struct lws_context** context, IZ_WSServerCreateContextParams params) { |
|
|
|
struct lws_context_creation_info info; |
|
|
|
memset(&info, 0, sizeof info); |
|
|
|
info.port = port; |
|
|
|
info.port = params.port; |
|
|
|
|
|
|
|
static struct lws_http_mount mount = { |
|
|
|
.mount_next = NULL, /* linked-list "next" */ |
|
|
|
.mountpoint = "/", /* mountpoint URL */ |
|
|
|
.origin = "./public", /* serve from dir */ |
|
|
|
.def = "index.html", /* default filename */ |
|
|
|
.protocol = "http", |
|
|
|
.cgienv = NULL, |
|
|
|
.extra_mimetypes = NULL, |
|
|
|
.interpret = NULL, |
|
|
|
.cgi_timeout = 0, |
|
|
|
.cache_max_age = 0, |
|
|
|
.auth_mask = 0, |
|
|
|
.cache_reusable = 0, |
|
|
|
.cache_revalidate = 0, |
|
|
|
.cache_intermediaries = 0, |
|
|
|
.origin_protocol = LWSMPRO_FILE, /* files in a dir */ |
|
|
|
.mountpoint_len = 1, /* char count */ |
|
|
|
.basic_auth_login_file = NULL, |
|
|
|
}; |
|
|
|
|
|
|
|
if (params.origin) { |
|
|
|
mount.origin = params.origin; |
|
|
|
} |
|
|
|
|
|
|
|
if (params.default_filename) { |
|
|
|
mount.def = params.default_filename; |
|
|
|
} |
|
|
|
|
|
|
|
if (params.protocol) { |
|
|
|
mount.protocol = params.protocol; |
|
|
|
} |
|
|
|
info.mounts = &mount; |
|
|
|
|
|
|
|
static const struct lws_protocols protocols[] = { |
|
|
|
{ |
|
|
|
.name = NETWORK_PROTOCOL, |
|
|
|
.callback = IZ_WSServerCallback, |
|
|
|
.per_session_data_size = sizeof(IZ_WSServerSessionData), |
|
|
|
.rx_buffer_size = 0, |
|
|
|
.id = 0, |
|
|
|
.user = NULL, |
|
|
|
.tx_packet_size = 0, |
|
|
|
}, |
|
|
|
{ |
|
|
|
.name = "http", |
|
|
|
.callback = lws_callback_http_dummy, |
|
|
|
.per_session_data_size = 0, |
|
|
|
.rx_buffer_size = 0, |
|
|
|
.id = 0, |
|
|
|
.user = NULL, |
|
|
|
.tx_packet_size = 0, |
|
|
|
}, |
|
|
|
LWS_PROTOCOL_LIST_TERM, |
|
|
|
}; |
|
|
|
info.protocols = protocols; |
|
|
|
// TODO initialize protocols |
|
|
|
info.options = ( |
|
|
|
LWS_SERVER_OPTION_VALIDATE_UTF8 |
|
|
|
| LWS_SERVER_OPTION_HTTP_HEADERS_SECURITY_BEST_PRACTICES_ENFORCE |
|
|
|