1
0
Fork 0
mirror of https://github.com/warmcat/libwebsockets.git synced 2025-03-09 00:00:04 +01:00

context info struct: make lws usage all const

This commit is contained in:
Andy Green 2018-04-27 08:27:16 +08:00
parent 800cd40f88
commit 7ff8f023d1
24 changed files with 62 additions and 67 deletions

View file

@ -526,11 +526,12 @@ lws_vhost_destroy2(struct lws_vhost *vh);
LWS_VISIBLE struct lws_vhost *
lws_create_vhost(struct lws_context *context,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
struct lws_vhost *vh = lws_zalloc(sizeof(*vh), "create vhost"),
**vh1 = &context->vhost_list;
const struct lws_http_mount *mounts;
const struct lws_protocols *pcols = info->protocols;
const struct lws_protocol_vhost_options *pvo;
#ifdef LWS_WITH_PLUGINS
struct lws_plugin *plugin = context->plugin_list;
@ -550,8 +551,8 @@ lws_create_vhost(struct lws_context *context,
pthread_mutex_init(&vh->lock, NULL);
#endif
if (!info->protocols)
info->protocols = &protocols_dummy[0];
if (!pcols)
pcols = &protocols_dummy[0];
vh->context = context;
if (!info->vhost_name)
@ -571,7 +572,7 @@ lws_create_vhost(struct lws_context *context,
#endif
for (vh->count_protocols = 0;
info->protocols[vh->count_protocols].callback;
pcols[vh->count_protocols].callback;
vh->count_protocols++)
;
@ -636,7 +637,7 @@ lws_create_vhost(struct lws_context *context,
}
m = vh->count_protocols;
memcpy(lwsp, info->protocols, sizeof(struct lws_protocols) * m);
memcpy(lwsp, pcols, sizeof(struct lws_protocols) * m);
/* for compatibility, all protocols enabled on vhost if only
* the default vhost exists. Otherwise only vhosts who ask
@ -676,7 +677,7 @@ lws_create_vhost(struct lws_context *context,
context->options & LWS_SERVER_OPTION_EXPLICIT_VHOSTS)
vh->protocols = lwsp;
else {
vh->protocols = info->protocols;
vh->protocols = pcols;
lws_free(lwsp);
}
@ -942,7 +943,7 @@ lws_destroy_event_pipe(struct lws *wsi)
}
LWS_VISIBLE struct lws_context *
lws_create_context(struct lws_context_creation_info *info)
lws_create_context(const struct lws_context_creation_info *info)
{
struct lws_context *context = NULL;
struct lws_plat_file_ops *prev;
@ -1246,15 +1247,6 @@ lws_create_context(struct lws_context_creation_info *info)
if (lws_plat_init(context, info))
goto bail;
#if defined(LWS_WITH_HTTP2)
/*
* let the user code see what the platform default SETTINGS were, he
* can modify them when he creates the vhosts.
*/
for (n = 1; n < LWS_H2_SETTINGS_LEN; n++)
info->http2_settings[n] = context->set.s[n];
#endif
lws_context_init_ssl_library(info);
context->user_space = info->user;

View file

@ -23,7 +23,7 @@
#include "private-libwebsockets.h"
void lws_feature_status_libev(struct lws_context_creation_info *info)
void lws_feature_status_libev(const struct lws_context_creation_info *info)
{
if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBEV))
lwsl_info("libev support compiled in and enabled\n");

View file

@ -21,7 +21,7 @@
#include "private-libwebsockets.h"
void lws_feature_status_libevent(struct lws_context_creation_info *info)
void lws_feature_status_libevent(const struct lws_context_creation_info *info)
{
if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBEVENT))
lwsl_info("libevent support compiled in and enabled\n");

View file

@ -22,7 +22,7 @@
#include "private-libwebsockets.h"
void
lws_feature_status_libuv(struct lws_context_creation_info *info)
lws_feature_status_libuv(const struct lws_context_creation_info *info)
{
if (lws_check_opt(info->options, LWS_SERVER_OPTION_LIBUV))
lwsl_info("libuv support compiled in and enabled\n");

View file

@ -2949,9 +2949,7 @@ struct lws_context_creation_info {
* given here.
*/
uint32_t http2_settings[7];
/**< CONTEXT: after context creation http2_settings[1] thru [6] have
* been set to the lws platform default values.
* VHOST: if http2_settings[0] is nonzero, the values given in
/**< VHOST: if http2_settings[0] is nonzero, the values given in
* http2_settings[1]..[6] are used instead of the lws
* platform default values.
* Just leave all at 0 if you don't care.
@ -3014,7 +3012,7 @@ struct lws_context_creation_info {
* one place; they're all handled in the user callback.
*/
LWS_VISIBLE LWS_EXTERN struct lws_context *
lws_create_context(struct lws_context_creation_info *info);
lws_create_context(const struct lws_context_creation_info *info);
/**
* lws_context_destroy() - Destroy the websocket context
@ -3117,7 +3115,7 @@ struct lws_vhost;
*/
LWS_VISIBLE LWS_EXTERN struct lws_vhost *
lws_create_vhost(struct lws_context *context,
struct lws_context_creation_info *info);
const struct lws_context_creation_info *info);
/**
* lws_vhost_destroy() - Destroy a vhost (virtual server context)

View file

@ -335,7 +335,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd)
}
LWS_VISIBLE void
lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
lws_plat_drop_app_privileges(const struct lws_context_creation_info *info)
{
}
@ -600,7 +600,7 @@ const struct http2_settings const lws_h2_defaults_esp32 = { {
LWS_VISIBLE int
lws_plat_init(struct lws_context *context,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
/* master context has the global fd lookup array */
context->lws_lookup = lws_zalloc(sizeof(struct lws *) *

View file

@ -205,7 +205,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, int fd)
}
LWS_VISIBLE void
lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
lws_plat_drop_app_privileges(const struct lws_context_creation_info *info)
{
}
@ -317,7 +317,7 @@ _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
LWS_VISIBLE int
lws_plat_init(struct lws_context *context,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
/* master context has the global fd lookup array */
context->lws_lookup = lws_zalloc(sizeof(struct lws *) *

View file

@ -432,7 +432,7 @@ _lws_plat_apply_caps(int mode, cap_value_t *cv, int count)
#endif
LWS_VISIBLE void
lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
lws_plat_drop_app_privileges(const struct lws_context_creation_info *info)
{
#if defined(LWS_HAVE_SYS_CAPABILITY_H) && defined(LWS_HAVE_LIBCAP)
int n;
@ -891,7 +891,7 @@ _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
LWS_VISIBLE int
lws_plat_init(struct lws_context *context,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
int fd;

View file

@ -362,7 +362,7 @@ lws_plat_set_socket_options(struct lws_vhost *vhost, lws_sockfd_type fd)
}
LWS_VISIBLE void
lws_plat_drop_app_privileges(struct lws_context_creation_info *info)
lws_plat_drop_app_privileges(const struct lws_context_creation_info *info)
{
}
@ -711,7 +711,7 @@ _lws_plat_file_write(lws_fop_fd_t fop_fd, lws_filepos_t *amount,
LWS_VISIBLE int
lws_plat_init(struct lws_context *context,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
struct lws_context_per_thread *pt = &context->pt[0];
int i, n = context->count_threads;

View file

@ -529,10 +529,10 @@ struct lws_role_ops {
int (*check_upgrades)(struct lws *wsi);
/* role-specific context init during context creation */
int (*init_context)(struct lws_context *context,
struct lws_context_creation_info *info);
const struct lws_context_creation_info *info);
/* role-specific per-vhost init during vhost creation */
int (*init_vhost)(struct lws_vhost *vh,
struct lws_context_creation_info *info);
const struct lws_context_creation_info *info);
/* role-specific per-vhost destructor during vhost destroy */
int (*destroy_vhost)(struct lws_vhost *vh);
/* generic 1Hz callback for the role itself */
@ -1231,7 +1231,7 @@ lws_libev_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN void
lws_libev_run(const struct lws_context *context, int tsi);
#define LWS_LIBEV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBEV)
LWS_EXTERN void lws_feature_status_libev(struct lws_context_creation_info *info);
LWS_EXTERN void lws_feature_status_libev(const struct lws_context_creation_info *info);
#else
#define lws_libev_accept(_a, _b) ((void) 0)
#define lws_libev_io(_a, _b) ((void) 0)
@ -1261,7 +1261,7 @@ lws_libuv_destroyloop(struct lws_context *context, int tsi);
LWS_EXTERN int
lws_uv_initvhost(struct lws_vhost* vh, struct lws*);
#define LWS_LIBUV_ENABLED(context) lws_check_opt(context->options, LWS_SERVER_OPTION_LIBUV)
LWS_EXTERN void lws_feature_status_libuv(struct lws_context_creation_info *info);
LWS_EXTERN void lws_feature_status_libuv(const struct lws_context_creation_info *info);
#else
#define lws_libuv_accept(_a, _b) ((void) 0)
#define lws_libuv_io(_a, _b) ((void) 0)
@ -1759,15 +1759,15 @@ LWS_EXTERN int
lws_change_pollfd(struct lws *wsi, int _and, int _or);
#ifndef LWS_NO_SERVER
int _lws_context_init_server(struct lws_context_creation_info *info,
struct lws_vhost *vhost);
int _lws_context_init_server(const struct lws_context_creation_info *info,
struct lws_vhost *vhost);
LWS_EXTERN struct lws_vhost *
lws_select_vhost(struct lws_context *context, int port, const char *servername);
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
lws_parse_ws(struct lws *wsi, unsigned char **buf, size_t len);
LWS_EXTERN void
lws_server_get_canonical_hostname(struct lws_context *context,
struct lws_context_creation_info *info);
const struct lws_context_creation_info *info);
#else
#define _lws_context_init_server(_a, _b) (0)
#define lws_parse_ws(_a, _b, _c) (0)
@ -2055,9 +2055,9 @@ LWS_EXTERN LWS_VISIBLE int
_lws_plat_service_tsi(struct lws_context *context, int timeout_ms, int tsi);
LWS_EXTERN int
lws_plat_init(struct lws_context *context,
struct lws_context_creation_info *info);
const struct lws_context_creation_info *info);
LWS_EXTERN void
lws_plat_drop_app_privileges(struct lws_context_creation_info *info);
lws_plat_drop_app_privileges(const struct lws_context_creation_info *info);
LWS_EXTERN unsigned long long
time_in_microseconds(void);
LWS_EXTERN const char * LWS_WARN_UNUSED_RESULT

View file

@ -465,7 +465,7 @@ rops_check_upgrades_h2(struct lws *wsi)
static int
rops_init_vhost_h2(struct lws_vhost *vh,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
int n;
@ -479,7 +479,7 @@ rops_init_vhost_h2(struct lws_vhost *vh,
static int
rops_init_context_h2(struct lws_context *context,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
context->set = lws_h2_stock_settings;

View file

@ -37,8 +37,8 @@ const char * const method_names[] = {
*/
int
_lws_context_init_server(struct lws_context_creation_info *info,
struct lws_vhost *vhost)
_lws_context_init_server(const struct lws_context_creation_info *info,
struct lws_vhost *vhost)
{
int n, opt = 1, limit = 1;
lws_sockfd_type sockfd;
@ -272,6 +272,8 @@ done_list:
lwsl_info(" Listening on port %d\n", vhost->listen_port);
}
// info->port = vhost->listen_port;
return 0;
bail:
@ -2588,7 +2590,7 @@ file_had_it:
LWS_VISIBLE void
lws_server_get_canonical_hostname(struct lws_context *context,
struct lws_context_creation_info *info)
const struct lws_context_creation_info *info)
{
if (lws_check_opt(info->options,
LWS_SERVER_OPTION_SKIP_SERVER_CANONICAL_NAME))

View file

@ -3,7 +3,7 @@
#include "extension-permessage-deflate.h"
LWS_VISIBLE void
lws_context_init_extensions(struct lws_context_creation_info *info,
lws_context_init_extensions(const struct lws_context_creation_info *info,
struct lws_context *context)
{
lwsl_info(" LWS_MAX_EXTENSIONS_ACTIVE: %u\n", LWS_MAX_EXTENSIONS_ACTIVE);

View file

@ -1894,7 +1894,8 @@ rops_callback_on_writable_ws(struct lws *wsi)
}
static int
rops_init_vhost_ws(struct lws_vhost *vh, struct lws_context_creation_info *info)
rops_init_vhost_ws(struct lws_vhost *vh,
const struct lws_context_creation_info *info)
{
#if !defined(LWS_WITHOUT_EXTENSIONS)
#ifdef LWS_WITH_PLUGINS

View file

@ -143,7 +143,7 @@ lws_ws_handshake_client(struct lws *wsi, unsigned char **buf, size_t len);
#if !defined(LWS_WITHOUT_EXTENSIONS)
LWS_VISIBLE void
lws_context_init_extensions(struct lws_context_creation_info *info,
lws_context_init_extensions(const struct lws_context_creation_info *info,
struct lws_context *context);
LWS_EXTERN int
lws_any_extension_handled(struct lws *wsi, enum lws_extension_callback_reasons r,

View file

@ -185,7 +185,7 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len)
int
lws_tls_client_create_vhost_context(struct lws_vhost *vh,
struct lws_context_creation_info *info,
const struct lws_context_creation_info *info,
const char *cipher_list,
const char *ca_filepath,
const char *cert_filepath,

View file

@ -207,7 +207,7 @@ lws_tls_server_certs_load(struct lws_vhost *vhost, struct lws *wsi,
}
int
lws_tls_server_vhost_backend_init(struct lws_context_creation_info *info,
lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info,
struct lws_vhost *vhost, struct lws *wsi)
{
const SSL_METHOD *method = TLS_server_method();

View file

@ -28,7 +28,7 @@ lws_ssl_elaborate_error(void)
}
int
lws_context_init_ssl_library(struct lws_context_creation_info *info)
lws_context_init_ssl_library(const struct lws_context_creation_info *info)
{
lwsl_info(" Compiled with MbedTLS support\n");

View file

@ -320,7 +320,7 @@ lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len)
int
lws_tls_client_create_vhost_context(struct lws_vhost *vh,
struct lws_context_creation_info *info,
const struct lws_context_creation_info *info,
const char *cipher_list,
const char *ca_filepath,
const char *cert_filepath,

View file

@ -325,7 +325,7 @@ post_ecdh:
}
int
lws_tls_server_vhost_backend_init(struct lws_context_creation_info *info,
lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info,
struct lws_vhost *vhost,
struct lws *wsi)
{

View file

@ -103,7 +103,8 @@ lws_context_init_ssl_pem_passwd_cb(char * buf, int size, int rwflag,
}
void
lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx, struct lws_context_creation_info *info)
lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx,
const struct lws_context_creation_info *info)
{
if (!info->ssl_private_key_password)
return;
@ -117,7 +118,7 @@ lws_ssl_bind_passphrase(SSL_CTX *ssl_ctx, struct lws_context_creation_info *info
}
int
lws_context_init_ssl_library(struct lws_context_creation_info *info)
lws_context_init_ssl_library(const struct lws_context_creation_info *info)
{
#ifdef USE_WOLFSSL
#ifdef USE_OLD_CYASSL

View file

@ -91,7 +91,7 @@ lws_ssl_capable_write(struct lws *wsi, unsigned char *buf, int len);
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
lws_ssl_pending(struct lws *wsi);
LWS_EXTERN int
lws_context_init_ssl_library(struct lws_context_creation_info *info);
lws_context_init_ssl_library(const struct lws_context_creation_info *info);
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
lws_server_socket_service_ssl(struct lws *new_wsi, lws_sockfd_type accept_fd);
LWS_EXTERN int
@ -117,7 +117,8 @@ lws_ssl_anybody_has_buffered_read_tsi(struct lws_context *context, int tsi);
LWS_EXTERN int
lws_gate_accepts(struct lws_context *context, int on);
LWS_EXTERN void
lws_ssl_bind_passphrase(lws_tls_ctx *ssl_ctx, struct lws_context_creation_info *info);
lws_ssl_bind_passphrase(lws_tls_ctx *ssl_ctx,
const struct lws_context_creation_info *info);
LWS_EXTERN void
lws_ssl_info_callback(const lws_tls_conn *ssl, int where, int ret);
LWS_EXTERN int
@ -140,8 +141,8 @@ lws_tls_alloc_pem_to_der_file(struct lws_context *context, const char *filename,
#if !defined(LWS_NO_SERVER)
LWS_EXTERN int
lws_context_init_server_ssl(struct lws_context_creation_info *info,
struct lws_vhost *vhost);
lws_context_init_server_ssl(const struct lws_context_creation_info *info,
struct lws_vhost *vhost);
void
lws_tls_acme_sni_cert_destroy(struct lws_vhost *vhost);
#else
@ -161,7 +162,7 @@ lws_ssl_get_error_string(int status, int ret, char *buf, size_t len);
LWS_EXTERN int
lws_tls_server_client_cert_verify_config(struct lws_vhost *vh);
LWS_EXTERN int
lws_tls_server_vhost_backend_init(struct lws_context_creation_info *info,
lws_tls_server_vhost_backend_init(const struct lws_context_creation_info *info,
struct lws_vhost *vhost, struct lws *wsi);
LWS_EXTERN int
lws_tls_server_new_nonblocking(struct lws *wsi, lws_sockfd_type accept_fd);
@ -181,7 +182,7 @@ LWS_EXTERN int
lws_tls_client_confirm_peer_cert(struct lws *wsi, char *ebuf, int ebuf_len);
LWS_EXTERN int
lws_tls_client_create_vhost_context(struct lws_vhost *vh,
struct lws_context_creation_info *info,
const struct lws_context_creation_info *info,
const char *cipher_list,
const char *ca_filepath,
const char *cert_filepath,
@ -193,7 +194,7 @@ LWS_EXTERN int
lws_ssl_get_error(struct lws *wsi, int n);
LWS_EXTERN int
lws_context_init_client_ssl(struct lws_context_creation_info *info,
lws_context_init_client_ssl(const struct lws_context_creation_info *info,
struct lws_vhost *vhost);
LWS_EXTERN void

View file

@ -86,7 +86,7 @@ lws_ssl_client_connect2(struct lws *wsi, char *errbuf, int len)
}
int lws_context_init_client_ssl(struct lws_context_creation_info *info,
int lws_context_init_client_ssl(const struct lws_context_creation_info *info,
struct lws_vhost *vhost)
{
const char *ca_filepath = info->ssl_ca_filepath;

View file

@ -95,7 +95,7 @@ lws_tls_server_conn_alpn(struct lws *wsi)
}
LWS_VISIBLE int
lws_context_init_server_ssl(struct lws_context_creation_info *info,
lws_context_init_server_ssl(const struct lws_context_creation_info *info,
struct lws_vhost *vhost)
{
struct lws_context *context = vhost->context;
@ -117,11 +117,11 @@ lws_context_init_server_ssl(struct lws_context_creation_info *info,
* provides the vhost SSL_CTX * in the user parameter.
*/
if (info->ssl_cert_filepath)
info->options |= LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX;
vhost->options |= LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX;
if (info->port != CONTEXT_PORT_NO_LISTEN) {
vhost->use_ssl = lws_check_opt(info->options,
vhost->use_ssl = lws_check_opt(vhost->options,
LWS_SERVER_OPTION_CREATE_VHOST_SSL_CTX);
if (vhost->use_ssl && info->ssl_cipher_list)