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

context: option to disable system state management

This commit is contained in:
Andy Green 2020-06-23 13:19:30 +01:00
parent ceb4e53174
commit 30f3606b0e
26 changed files with 95 additions and 14 deletions

View file

@ -114,6 +114,7 @@ option(LWS_WITH_SYS_NTPCLIENT "Build in tiny ntpclient good for tls date validat
option(LWS_WITH_SYS_DHCP_CLIENT "Build in tiny DHCP client" OFF)
option(LWS_WITH_HTTP_BASIC_AUTH "Support Basic Auth" ON)
option(LWS_WITH_HTTP_UNCOMMON_HEADERS "Include less common http header support" ON)
option(LWS_WITH_SYS_STATE "lws_system state support" ON)
#
# Secure Streams

View file

@ -179,6 +179,7 @@
#cmakedefine LWS_WITH_SQLITE3
#cmakedefine LWS_WITH_SYS_NTPCLIENT
#cmakedefine LWS_WITH_SYS_DHCP_CLIENT
#cmakedefine LWS_WITH_SYS_STATE
#cmakedefine LWS_WITH_THREADPOOL
#cmakedefine LWS_WITH_TLS
#cmakedefine LWS_WITH_UDP

View file

@ -221,11 +221,15 @@
#define LWS_SERVER_OPTION_GLIB (1ll << 33)
/**< (CTX) Use glib event loop */
#define LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE (1ll << 34)
#define LWS_SERVER_OPTION_H2_PRIOR_KNOWLEDGE (1ll << 34)
/**< (VH) Tell the vhost to treat plain text http connections as
* H2 with prior knowledge (no upgrade request involved)
*/
#define LWS_SERVER_OPTION_NO_LWS_SYSTEM_STATES (1ll << 35)
/**< (CTX) Disable lws_system state, eg, because we are a secure streams
* proxy client that is not trying to track system state by itself. */
/****** add new things just above ---^ ******/
@ -725,10 +729,12 @@ struct lws_context_creation_info {
/**< VHOST: optional retry and idle policy to apply to this vhost.
* Currently only the idle parts are applied to the connections.
*/
#if defined(LWS_WITH_SYS_STATE)
lws_state_notify_link_t * const *register_notifier_list;
/**< CONTEXT: NULL, or pointer to an array of notifiers that should
* be registered during context creation, so they can see state change
* events from very early on. The array should end with a NULL. */
#endif
#if defined(LWS_WITH_SECURE_STREAMS)
#if defined(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY)
const struct lws_ss_policy *pss_policies; /**< CONTEXT: point to first

View file

@ -25,6 +25,8 @@
struct lws_state_notify_link;
struct lws_state_manager;
#if defined(LWS_WITH_SYS_STATE)
typedef int (*lws_state_notify_t)(struct lws_state_manager *mgr,
struct lws_state_notify_link *link,
int current, int target);
@ -107,3 +109,7 @@ lws_state_transition_steps(lws_state_manager_t *mgr, int target);
*/
LWS_EXTERN LWS_VISIBLE int
lws_state_transition(lws_state_manager_t *mgr, int target);
#else
#endif

View file

@ -175,6 +175,8 @@ typedef struct lws_system_ops {
*/
} lws_system_ops_t;
#if defined(LWS_WITH_SYS_STATE)
/**
* lws_system_get_state_manager() - return the state mgr object for system state
*
@ -186,7 +188,7 @@ typedef struct lws_system_ops {
LWS_EXTERN LWS_VISIBLE lws_state_manager_t *
lws_system_get_state_manager(struct lws_context *context);
#endif
/* wrappers handle NULL members or no ops struct set at all cleanly */
@ -203,6 +205,8 @@ lws_system_get_state_manager(struct lws_context *context);
LWS_EXTERN LWS_VISIBLE const lws_system_ops_t *
lws_system_get_ops(struct lws_context *context);
#if defined(LWS_WITH_SYS_STATE)
/**
* lws_system_context_from_system_mgr() - return context from system state mgr
*
@ -214,6 +218,7 @@ lws_system_get_ops(struct lws_context *context);
LWS_EXTERN LWS_VISIBLE struct lws_context *
lws_system_context_from_system_mgr(lws_state_manager_t *mgr);
#endif
/**
* __lws_system_attach() - get and set items on context attach list

View file

@ -33,13 +33,18 @@ list(APPEND SOURCES
core-net/pollfd.c
core-net/service.c
core-net/sorted-usec-list.c
core-net/state.c
core-net/wsi.c
core-net/wsi-timeout.c
core-net/adopt.c
roles/pipe/ops-pipe.c
)
if (LWS_WITH_SYS_STATE)
list(APPEND SOURCES
core-net/state.c
)
endif()
if (LWS_WITH_DETAILED_LATENCY)
list(APPEND SOURCES
core-net/detailed-latency.c)

View file

@ -851,8 +851,10 @@ lws_sa46_compare_ads(const lws_sockaddr46 *sa46a, const lws_sockaddr46 *sa46b)
return sa46a->sa4.sin_addr.s_addr != sa46b->sa4.sin_addr.s_addr;
}
#if defined(LWS_WITH_SYS_STATE)
lws_state_manager_t *
lws_system_get_state_manager(struct lws_context *context)
{
return &context->mgr_system;
}
#endif

View file

@ -1,7 +1,7 @@
/*
* libwebsockets - small server side websockets and web server implementation
*
* Copyright (C) 2010 - 2019 Andy Green <andy@warmcat.com>
* Copyright (C) 2010 - 2020 Andy Green <andy@warmcat.com>
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to

View file

@ -82,6 +82,8 @@ lws_sul_peer_limits_cb(lws_sorted_usec_list_t *sul)
#if defined(LWS_WITH_NETWORK)
#if defined(LWS_WITH_SYS_STATE)
#if defined(_DEBUG)
static const char * system_state_names[] = {
"undef",
@ -101,6 +103,7 @@ static const char * system_state_names[] = {
};
#endif
/*
* Handle provoking protocol init when we pass through the right system state
*/
@ -213,6 +216,7 @@ lws_context_creation_completion_cb(lws_sorted_usec_list_t *sul)
lws_state_transition_steps(&context->mgr_system,
LWS_SYSTATE_OPERATIONAL);
}
#endif /* WITH_SYS_STATE */
#endif
struct lws_context *
@ -824,6 +828,7 @@ lws_create_context(const struct lws_context_creation_info *info)
}
#endif
#if defined(LWS_WITH_SYS_STATE)
/*
* init the lws_state mgr for the system state
*/
@ -847,6 +852,7 @@ lws_create_context(const struct lws_context_creation_info *info)
lws_state_reg_notifier_list(&context->mgr_system,
info->register_notifier_list);
#endif
/*
* if he's not saying he'll make his own vhosts later then act
@ -914,6 +920,7 @@ lws_create_context(const struct lws_context_creation_info *info)
if (lws_plat_drop_app_privileges(context, 1))
goto bail;
#if defined(LWS_WITH_SYS_STATE)
/*
* We want to move on the syste, state as far as it can go towards
* OPERATIONAL now. But we have to return from here first so the user
@ -925,6 +932,7 @@ lws_create_context(const struct lws_context_creation_info *info)
lws_sul_schedule(context, 0, &context->sul_system_state,
lws_context_creation_completion_cb, 1);
#endif
/* expedite post-context init (eg, protocols) */
lws_cancel_service(context);
@ -1002,11 +1010,12 @@ lws_system_cpd_set(struct lws_context *cx, lws_cpd_result_t result)
lwsl_notice("%s: setting CPD result %s\n", __func__, cname[result]);
cx->captive_portal_detect = (uint8_t)result;
#if defined(LWS_WITH_SYS_STATE)
/* if nothing is there to intercept anything, go all the way */
if (cx->mgr_system.state != LWS_SYSTATE_POLICY_INVALID)
lws_state_transition_steps(&cx->mgr_system,
LWS_SYSTATE_OPERATIONAL);
#endif
}
lws_cpd_result_t
@ -1345,7 +1354,9 @@ lws_context_destroy(struct lws_context *context)
context->being_destroyed = 1;
#if defined(LWS_WITH_NETWORK)
#if defined(LWS_WITH_SYS_STATE)
lws_state_transition(&context->mgr_system, LWS_SYSTATE_POLICY_INVALID);
#endif
m = context->count_threads;
while (m--) {
@ -1434,6 +1445,7 @@ out:
#endif
}
#if defined(LWS_WITH_SYS_STATE)
struct lws_context *
lws_system_context_from_system_mgr(lws_state_manager_t *mgr)
{
@ -1443,3 +1455,4 @@ lws_system_context_from_system_mgr(lws_state_manager_t *mgr)
return NULL;
#endif
}
#endif

View file

@ -375,8 +375,10 @@ struct lws_context {
lws_sorted_usec_list_t sul_api_amazon_com_kick;
#endif
#if defined(LWS_WITH_SYS_STATE)
lws_state_manager_t mgr_system;
lws_state_notify_link_t protocols_notify;
#endif
#if defined (LWS_WITH_SYS_DHCP_CLIENT)
lws_dll2_owner_t dhcpc_owner;
/**< list of ifaces with dhcpc */

View file

@ -73,7 +73,8 @@ if (LWS_WITH_CLIENT)
)
endif()
if (LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM)
if (LWS_WITH_SECURE_STREAMS_SYS_AUTH_API_AMAZON_COM AND
LWS_WITH_SYS_STATE)
list(APPEND SOURCES
secure-streams/system/auth-api.amazon.com/auth.c
)

View file

@ -385,15 +385,17 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
* first 4 bytes or the create result, comma-separated
*/
rsp = conn->ss->policy;
if (conn->ss) {
rsp = conn->ss->policy;
while (rsp) {
if (n != 4 && n < (int)sizeof(s) - 2)
s[n++] = ',';
n += lws_snprintf(&s[n], sizeof(s) - n,
"%s", rsp->streamtype);
rsp = lws_ss_policy_lookup(wsi->context,
rsp->rideshare_streamtype);
while (rsp) {
if (n != 4 && n < (int)sizeof(s) - 2)
s[n++] = ',';
n += lws_snprintf(&s[n], sizeof(s) - n,
"%s", rsp->streamtype);
rsp = lws_ss_policy_lookup(wsi->context,
rsp->rideshare_streamtype);
}
}
s[2] = n - 3;
conn->state = LPCS_OPERATIONAL;

View file

@ -83,8 +83,10 @@ policy_set(lws_sorted_usec_list_t *sul)
lwsl_err("%s: policy set failed\n", __func__);
else {
context->policy_updated = 1;
#if defined(LWS_WITH_SYS_STATE)
lws_state_transition_steps(&context->mgr_system,
LWS_SYSTATE_OPERATIONAL);
#endif
}
}

View file

@ -179,6 +179,7 @@ __lws_system_attach(struct lws_context *context, int tsi, lws_attach_cb_t cb,
}
*get = NULL;
#if defined(LWS_WITH_SYS_STATE)
if (!pt->attach_owner.count)
return 0;
@ -202,6 +203,7 @@ __lws_system_attach(struct lws_context *context, int tsi, lws_attach_cb_t cb,
return 0;
}
} lws_end_foreach_dll(d);
#endif
/* nobody ready to go... leave *get as NULL and return cleanly */

View file

@ -6,6 +6,7 @@ include(LwsCheckRequirements)
set(requirements 1)
require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements)
require_lws_config(LWS_WITH_TLS 1 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)

View file

@ -13,6 +13,7 @@ set(requirements 1)
require_lws_config(LWS_ROLE_H1 1 requirements)
require_lws_config(LWS_WITH_TLS 1 requirements)
require_lws_config(LWS_WITH_CLIENT 1 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (NOT WIN32 AND requirements)
add_executable(${SAMP} ${SRCS})

View file

@ -11,6 +11,7 @@ set(SRCS minimal-http-client.c)
set(requirements 1)
require_lws_config(LWS_ROLE_H2 1 requirements)
require_lws_config(LWS_WITH_CLIENT 1 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} ${SRCS})

View file

@ -11,6 +11,7 @@ set(SRCS minimal-http-client.c)
set(requirements 1)
require_lws_config(LWS_ROLE_H1 1 requirements)
require_lws_config(LWS_WITH_CLIENT 1 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} ${SRCS})

View file

@ -11,6 +11,7 @@ set(SRCS minimal-mqtt-client-multi.c)
set(requirements 1)
require_lws_config(LWS_ROLE_MQTT 1 requirements)
require_lws_config(LWS_WITH_CLIENT 1 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} ${SRCS})

View file

@ -9,6 +9,7 @@ set(SRCS minimal-mqtt-client.c)
set(requirements 1)
require_lws_config(LWS_ROLE_MQTT 1 requirements)
require_lws_config(LWS_WITH_CLIENT 1 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} ${SRCS})

View file

@ -14,6 +14,7 @@ require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements)
require_lws_config(LWS_WITH_ALSA 1 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} ${SRCS})

View file

@ -12,6 +12,7 @@ require_lws_config(LWS_ROLE_H1 1 requirements)
require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} main.c avs.c)

View file

@ -12,6 +12,7 @@ require_lws_config(LWS_ROLE_H1 1 requirements)
require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} minimal-secure-streams.c)

View file

@ -14,6 +14,7 @@ require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS_PROXY_API 1 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} ${SRCS})

View file

@ -12,6 +12,7 @@ require_lws_config(LWS_ROLE_H1 1 requirements)
require_lws_config(LWS_WITHOUT_CLIENT 0 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS 1 requirements)
require_lws_config(LWS_WITH_SECURE_STREAMS_STATIC_POLICY_ONLY 0 requirements)
require_lws_config(LWS_WITH_SYS_STATE 1 requirements)
if (requirements)
add_executable(${SAMP} minimal-secure-streams.c)

View file

@ -206,6 +206,8 @@ typedef struct myss {
lws_sorted_usec_list_t sul;
} myss_t;
#if !defined(LWS_SS_USE_SSPC)
static const char *canned_root_token_payload =
"grant_type=refresh_token"
"&refresh_token=Atzr|IwEBIJedGXjDqsU_vMxykqOMg"
@ -220,6 +222,8 @@ static const char *canned_root_token_payload =
"&client_id="
"amzn1.application-oa2-client.4823334c434b4190a2b5a42c07938a2d";
#endif
/* secure streams payload interface */
static int
@ -285,9 +289,12 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
int current, int target)
{
struct lws_context *context = lws_system_context_from_system_mgr(mgr);
#if !defined(LWS_SS_USE_SSPC)
lws_system_blob_t *ab = lws_system_get_blob(context,
LWS_SYSBLOB_TYPE_AUTH, 1 /* AUTH_IDX_ROOT */);
size_t size;
#endif
/*
* For the things we care about, let's notice if we are trying to get
@ -296,6 +303,13 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
*/
switch (target) {
#if !defined(LWS_SS_USE_SSPC)
/*
* The proxy takes responsibility for this stuff if we get things
* done through that
*/
case LWS_SYSTATE_INITIALIZED: /* overlay on the hardcoded policy */
case LWS_SYSTATE_POLICY_VALID: /* overlay on the loaded policy */
@ -338,6 +352,8 @@ app_system_state_nf(lws_state_manager_t *mgr, lws_state_notify_link_t *link,
strlen(canned_root_token_payload));
break;
#endif
case LWS_SYSTATE_OPERATIONAL:
if (current == LWS_SYSTATE_OPERATIONAL) {
lws_ss_info_t ssi;
@ -444,6 +460,11 @@ int main(int argc, const char **argv)
return 1;
}
#if !defined(LWS_SS_USE_SSPC)
/*
* If we're being a proxied client, the proxy does all this
*/
/*
* Set the related lws_system blobs
*
@ -472,6 +493,7 @@ int main(int argc, const char **argv)
lws_system_blob_heap_append(lws_system_get_blob(context,
LWS_SYSBLOB_TYPE_DEVICE_TYPE, 0),
(const uint8_t *)"spacerocket", 11);
#endif
/* the event loop */