Skip to content

Commit

Permalink
clean: internally use LWS_WITH_CLIENT and _SERVER
Browse files Browse the repository at this point in the history
Remove some more things in LWS_WITH_SERVER=0 case
  • Loading branch information
lws-team committed Aug 18, 2019
1 parent 788b852 commit ec54a1d
Show file tree
Hide file tree
Showing 88 changed files with 185 additions and 174 deletions.
21 changes: 15 additions & 6 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -379,13 +379,13 @@ if (LWS_WITH_PLUGINS)
endif()

if (LWS_ROLE_RAW_PROXY)
set (LWS_WITHOUT_CLIENT 0)
set (LWS_WITHOUT_SERVER 0)
set (LWS_WITH_CLIENT 1)
set (LWS_WITH_SERVER 1)
endif()

if (LWS_WITH_ACME)
set (LWS_WITHOUT_CLIENT 0)
set (LWS_WITHOUT_SERVER 0)
set (LWS_WITH_CLIENT 1)
set (LWS_WITH_SERVER 1)
set (LWS_WITH_JOSE 1)
endif()

Expand Down Expand Up @@ -677,11 +677,11 @@ if (LWS_WITHOUT_DAEMONIZE OR WIN32)
endif()

if (LWS_WITHOUT_SERVER)
set(LWS_NO_SERVER 1)
set(LWS_WITHOUT_SERVER 1)
endif()

if (LWS_WITHOUT_CLIENT)
set(LWS_NO_CLIENT 1)
set(LWS_WITHOUT_CLIENT 1)
endif()

if (LWS_WITH_LIBEV)
Expand Down Expand Up @@ -712,6 +712,15 @@ if ("${LWS_MAX_SMP}" STREQUAL "")
set(LWS_MAX_SMP 1)
endif()

set(LWS_WITH_CLIENT 1)
if (LWS_WITHOUT_CLIENT)
set(LWS_WITH_CLIENT 0)
endif()
set(LWS_WITH_SERVER 1)
if (LWS_WITHOUT_SERVER)
set(LWS_WITH_SERVER 0)
endif()

# using any abstract protocol enables LWS_WITH_ABSTRACT

if (LWS_WITH_SMTP)
Expand Down
5 changes: 2 additions & 3 deletions cmake/lws_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,6 @@
#cmakedefine LWS_MINGW_SUPPORT
#cmakedefine LWS_NO_CLIENT
#cmakedefine LWS_NO_DAEMONIZE
#cmakedefine LWS_NO_SERVER
#cmakedefine LWS_OPENSSL_CLIENT_CERTS "${LWS_OPENSSL_CLIENT_CERTS}"
#cmakedefine LWS_OPENSSL_SUPPORT
#cmakedefine LWS_PLAT_OPTEE
Expand Down Expand Up @@ -120,9 +119,9 @@
#cmakedefine LWS_WITH_MINIZ
#cmakedefine LWS_WITH_NETWORK
#cmakedefine LWS_WITH_NO_LOGS
#cmakedefine LWS_WITHOUT_CLIENT
#cmakedefine LWS_WITH_CLIENT
#cmakedefine LWS_WITHOUT_EXTENSIONS
#cmakedefine LWS_WITHOUT_SERVER
#cmakedefine LWS_WITH_SERVER
#cmakedefine LWS_WITH_PEER_LIMITS
#cmakedefine LWS_WITH_PLUGINS
#cmakedefine LWS_WITH_POLARSSL
Expand Down
4 changes: 2 additions & 2 deletions lib/abstract/transports/raw-skt.c
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ lws_atcrs_tx(lws_abs_transport_inst_t *ati, uint8_t *buf, size_t len)
return 0;
}

#if !defined(LWS_WITHOUT_CLIENT)
#if defined(LWS_WITH_CLIENT)
static int
lws_atcrs_client_conn(const lws_abs_t *abs)
{
Expand Down Expand Up @@ -347,7 +347,7 @@ const lws_abs_transport_t lws_abs_transport_cli_raw_skt = {
.destroy = lws_atcrs_destroy,

.tx = lws_atcrs_tx,
#if defined(LWS_WITHOUT_CLIENT)
#if !defined(LWS_WITH_CLIENT)
.client_conn = NULL,
#else
.client_conn = lws_atcrs_client_conn,
Expand Down
4 changes: 2 additions & 2 deletions lib/abstract/transports/unit-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ lws_atcut_tx(lws_abs_transport_inst_t *ati, uint8_t *buf, size_t len)
return 0;
}

#if !defined(LWS_WITHOUT_CLIENT)
#if defined(LWS_WITH_CLIENT)
static int
lws_atcut_client_conn(const lws_abs_t *abs)
{
Expand Down Expand Up @@ -521,7 +521,7 @@ const lws_abs_transport_t lws_abs_transport_cli_unit_test = {
.destroy = lws_atcut_destroy,

.tx = lws_atcut_tx,
#if defined(LWS_WITHOUT_CLIENT)
#if !defined(LWS_WITH_CLIENT)
.client_conn = NULL,
#else
.client_conn = lws_atcut_client_conn,
Expand Down
2 changes: 1 addition & 1 deletion lib/core-net/adopt.c
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ lws_adopt_descriptor_vhost(struct lws_vhost *vh, lws_adoption_type type,
}
lws_pt_unlock(pt);
}
#if !defined(LWS_WITHOUT_SERVER)
#if defined(LWS_WITH_SERVER)
else
if (lws_server_socket_service_ssl(new_wsi, fd.sockfd)) {
lwsl_info("%s: fail ssl negotiation\n", __func__);
Expand Down
14 changes: 7 additions & 7 deletions lib/core-net/close.c
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ __lws_free_wsi(struct lws *wsi)

if (wsi->vhost && wsi->vhost->lserv_wsi == wsi)
wsi->vhost->lserv_wsi = NULL;
#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
if (wsi->vhost)
lws_dll2_remove(&wsi->dll_cli_active_conns);
#endif
Expand All @@ -54,7 +54,7 @@ __lws_free_wsi(struct lws *wsi)
__lws_header_table_detach(wsi, 0);
#endif
__lws_same_vh_protocol_remove(wsi);
#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
lws_free_set_NULL(wsi->stash);
lws_free_set_NULL(wsi->cli_hostname_copy);
#endif
Expand Down Expand Up @@ -119,7 +119,7 @@ lws_remove_child_from_any_parent(struct lws *wsi)
wsi->parent = NULL;
}

#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
static int
lws_close_trans_q_leader(struct lws_dll2 *d, void *user)
{
Expand Down Expand Up @@ -156,7 +156,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
struct lws_context_per_thread *pt;
struct lws *wsi1, *wsi2;
struct lws_context *context;
#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
long rl = (long)(int)reason;
#endif
int n;
Expand All @@ -172,7 +172,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
pt = &context->pt[(int)wsi->tsi];
lws_stats_bump(pt, LWSSTATS_C_API_CLOSE, 1);

#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)

lws_free_set_NULL(wsi->cli_hostname_copy);

Expand Down Expand Up @@ -256,7 +256,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
lws_cgi_remove_and_kill(wsi);
#endif

#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
lws_free_set_NULL(wsi->stash);
#endif

Expand Down Expand Up @@ -369,7 +369,7 @@ __lws_close_free_wsi(struct lws *wsi, enum lws_close_status reason,
wsi->protocol_bind_balance = 0;
}

#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
if ((lwsi_state(wsi) == LRS_WAITING_SERVER_REPLY ||
lwsi_state(wsi) == LRS_WAITING_CONNECT) &&
!wsi->already_did_cce && wsi->protocol)
Expand Down
4 changes: 2 additions & 2 deletions lib/core-net/dummy-callback.c
Original file line number Diff line number Diff line change
Expand Up @@ -274,15 +274,15 @@ lws_callback_http_dummy(struct lws *wsi, enum lws_callback_reasons reason,
switch (reason) {
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
case LWS_CALLBACK_HTTP:
#ifndef LWS_NO_SERVER
#if defined(LWS_WITH_SERVER)
if (lws_return_http_status(wsi, HTTP_STATUS_NOT_FOUND, NULL))
return -1;

if (lws_http_transaction_completed(wsi))
#endif
return -1;
break;
#if !defined(LWS_NO_SERVER)
#if defined(LWS_WITH_SERVER)
case LWS_CALLBACK_HTTP_BODY_COMPLETION:
#if defined(LWS_WITH_HTTP_PROXY)
if (wsi->child_list) {
Expand Down
2 changes: 1 addition & 1 deletion lib/core-net/output.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ int lws_issue_raw(struct lws *wsi, unsigned char *buf, size_t len)
}

#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
#if !defined(LWS_WITHOUT_SERVER)
#if defined(LWS_WITH_SERVER)
if (wsi->http.deferred_transaction_completed) {
lwsl_notice("%s: partial completed, doing "
"deferred transaction completed\n",
Expand Down
8 changes: 4 additions & 4 deletions lib/core-net/pollfd.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ _lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa)
return ret;
}

#ifndef LWS_NO_SERVER
#if defined(LWS_WITH_SERVER)
/*
* Enable or disable listen sockets on this pt globally...
* it's modulated according to the pt having space for a new accept.
Expand Down Expand Up @@ -320,8 +320,8 @@ __insert_wsi_socket_into_fds(struct lws_context *context, struct lws *wsi)
wsi->user_space, (void *) &pa, 0))
ret = -1;
#endif
#ifndef LWS_NO_SERVER
/* if no more room, defeat accepts on this thread */
#if defined(LWS_WITH_SERVER)
/* if no more room, defeat accepts on this service thread */
if ((unsigned int)pt->fds_count == context->fd_limit_per_thread - 1)
lws_accept_modulation(context, pt, 0);
#endif
Expand Down Expand Up @@ -430,7 +430,7 @@ __remove_wsi_socket_from_fds(struct lws *wsi)
ret = -1;
#endif

#ifndef LWS_NO_SERVER
#if defined(LWS_WITH_SERVER)
if (!context->being_destroyed &&
/* if this made some room, accept connects on this thread */
(unsigned int)pt->fds_count < context->fd_limit_per_thread - 1)
Expand Down
28 changes: 14 additions & 14 deletions lib/core-net/private-lib-core-net.h
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ enum uri_esc_states {
URIES_SEEN_PERCENT_H1,
};

#ifndef LWS_NO_CLIENT
#if defined(LWS_WITH_CLIENT)

enum {
CIS_ADDRESS,
Expand Down Expand Up @@ -325,10 +325,10 @@ struct lws_context_per_thread {
#if defined (LWS_WITH_SEQUENCER)
lws_sorted_usec_list_t sul_seq_heartbeat;
#endif
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
#if (defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)) && defined(LWS_WITH_SERVER)
lws_sorted_usec_list_t sul_ah_lifecheck;
#endif
#if defined(LWS_WITH_TLS) && !defined(LWS_NO_SERVER)
#if defined(LWS_WITH_TLS) && defined(LWS_WITH_SERVER)
lws_sorted_usec_list_t sul_tls;
#endif
#if defined(LWS_PLAT_UNIX)
Expand Down Expand Up @@ -448,7 +448,7 @@ struct lws_conn_stats {


struct lws_vhost {
#if !defined(LWS_WITHOUT_CLIENT)
#if defined(LWS_WITH_CLIENT)
char proxy_basic_auth_token[128];
#endif
#if LWS_MAX_SMP > 1
Expand Down Expand Up @@ -499,7 +499,7 @@ struct lws_vhost {
struct lws_vhost *no_listener_vhost_list;
struct lws_dll2_owner abstract_instances_owner;

#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
struct lws_dll2_owner dll_cli_active_conns_owner;
#endif

Expand Down Expand Up @@ -599,7 +599,7 @@ struct lws {
#endif

struct lws_udp *udp;
#ifndef LWS_NO_CLIENT
#if defined(LWS_WITH_CLIENT)
struct client_info_stash *stash;
char *cli_hostname_copy;
struct lws_dll2 dll_cli_active_conns;
Expand Down Expand Up @@ -634,7 +634,7 @@ struct lws {
#define LWS_NO_FDS_POS (-1)
int position_in_fds_table;

#ifndef LWS_NO_CLIENT
#if defined(LWS_WITH_CLIENT)
int chunk_remaining;
#endif
unsigned int cache_secs;
Expand Down Expand Up @@ -681,7 +681,7 @@ struct lws {
#ifdef LWS_WITH_ACCESS_LOG
unsigned int access_log_pending:1;
#endif
#ifndef LWS_NO_CLIENT
#if defined(LWS_WITH_CLIENT)
unsigned int do_ws:1; /* whether we are doing http or ws flow */
unsigned int chunked:1; /* if the clientside connection is chunked */
unsigned int client_rx_avail:1;
Expand All @@ -698,7 +698,7 @@ struct lws {
unsigned int sock_send_blocking:1;
#endif

#ifndef LWS_NO_CLIENT
#if defined(LWS_WITH_CLIENT)
unsigned short c_port;
#endif

Expand All @@ -716,10 +716,10 @@ struct lws {
char cgi_channel; /* which of stdin/out/err */
char hdr_state;
#endif
#ifndef LWS_NO_CLIENT
#if defined(LWS_WITH_CLIENT)
char chunk_parser; /* enum lws_chunk_parser */
#endif
#if defined(LWS_WITH_CGI) || !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CGI) || defined(LWS_WITH_CLIENT)
char reason_bf; /* internal writeable callback reason bitfield */
#endif
#if defined(LWS_WITH_STATS) && defined(LWS_WITH_TLS)
Expand Down Expand Up @@ -861,7 +861,7 @@ lws_ensure_user_space(struct lws *wsi);
LWS_EXTERN int LWS_WARN_UNUSED_RESULT
lws_change_pollfd(struct lws *wsi, int _and, int _or);

#ifndef LWS_NO_SERVER
#if defined(LWS_WITH_SERVER)
int _lws_vhost_init_server(const struct lws_context_creation_info *info,
struct lws_vhost *vhost);
LWS_EXTERN struct lws_vhost *
Expand Down Expand Up @@ -1006,7 +1006,7 @@ LWS_EXTERN struct lws *
lws_http_client_connect_via_info2(struct lws *wsi);


#ifndef LWS_NO_CLIENT
#if defined(LWS_WITH_CLIENT)
LWS_EXTERN int lws_client_socket_service(struct lws *wsi,
struct lws_pollfd *pollfd,
struct lws *wsi_conn);
Expand All @@ -1029,7 +1029,7 @@ __lws_rx_flow_control(struct lws *wsi);
LWS_EXTERN int
_lws_change_pollfd(struct lws *wsi, int _and, int _or, struct lws_pollargs *pa);

#ifndef LWS_NO_SERVER
#if defined(LWS_WITH_SERVER)
LWS_EXTERN int
lws_handshake_server(struct lws *wsi, unsigned char **buf, size_t len);
#else
Expand Down
8 changes: 3 additions & 5 deletions lib/core-net/vhost.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,6 @@ lws_role_call_alpn_negotiated(struct lws *wsi, const char *alpn)
return 0;
}

//#if !defined(LWS_WITHOUT_SERVER)
int
lws_role_call_adoption_bind(struct lws *wsi, int type, const char *prot)
{
Expand Down Expand Up @@ -179,9 +178,8 @@ lws_role_call_adoption_bind(struct lws *wsi, int type, const char *prot)

return 1;
}
//#endif

#if !defined(LWS_WITHOUT_CLIENT)
#if defined(LWS_WITH_CLIENT)
int
lws_role_call_client_bind(struct lws *wsi,
const struct lws_client_connect_info *i)
Expand Down Expand Up @@ -441,7 +439,7 @@ lws_create_vhost(struct lws_context *context,
int m, f = !info->pvo, fx = 0, abs_pcol_count = 0;
char buf[96];
#if defined(LWS_CLIENT_HTTP_PROXYING) && \
!defined(LWS_WITHOUT_CLIENT) && defined(LWS_HAVE_GETENV)
defined(LWS_WITH_CLIENT) && defined(LWS_HAVE_GETENV)
char *p;
#endif
int n;
Expand Down Expand Up @@ -681,7 +679,7 @@ lws_create_vhost(struct lws_context *context,
vh->socks_proxy_address[0] = '\0';
#endif

#if !defined(LWS_WITHOUT_CLIENT) && defined(LWS_CLIENT_HTTP_PROXYING)
#if defined(LWS_WITH_CLIENT) && defined(LWS_CLIENT_HTTP_PROXYING)
/* either use proxy from info, or try get it from env var */
#if defined(LWS_ROLE_H1) || defined(LWS_ROLE_H2)
vh->http.http_proxy_port = 0;
Expand Down
2 changes: 1 addition & 1 deletion lib/core-net/wsi-timeout.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ lws_sul_wsitimeout_cb(lws_sorted_usec_list_t *sul)
* don't try to do protocol cleanup like flush partials.
*/
wsi->socket_is_permanently_unusable = 1;
#if !defined(LWS_NO_CLIENT)
#if defined(LWS_WITH_CLIENT)
if (lwsi_state(wsi) == LRS_WAITING_SSL)
lws_inform_client_conn_fail(wsi,
(void *)"Timed out waiting SSL", 21);
Expand Down
Loading

0 comments on commit ec54a1d

Please sign in to comment.