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

ss: allow NULL cbs

Some streamtypes do not pass or receive payload meaningfully.  Allow them
to just leave their related cb NULL.  Ditto for state, although I'm not sure
how useful such a streamtype can be.
This commit is contained in:
Andy Green 2020-06-01 07:17:48 +01:00
parent ca3380fd56
commit e4ab18342a
6 changed files with 14 additions and 27 deletions

View file

@ -401,7 +401,7 @@ malformed:
case LWS_CALLBACK_RECEIVE_CLIENT_HTTP_READ:
lwsl_debug("%s: RECEIVE_CLIENT_HTTP_READ: read %d\n",
__func__, (int)len);
if (!h)
if (!h || !h->info.rx)
return 0;
#if defined(LWS_WITH_SS_RIDESHARE)
@ -456,7 +456,7 @@ malformed:
case LWS_CALLBACK_CLIENT_HTTP_WRITEABLE:
lwsl_info("%s: LWS_CALLBACK_CLIENT_HTTP_WRITEABLE\n", __func__);
if (!h)
if (!h || !h->info.tx)
return 0;
if (!h->rideshare)

View file

@ -80,7 +80,7 @@ secstream_mqtt(struct lws *wsi, enum lws_callback_reasons reason, void *user,
case LWS_CALLBACK_MQTT_CLIENT_RX:
// lwsl_user("LWS_CALLBACK_CLIENT_RECEIVE: read %d\n", (int)len);
if (!h)
if (!h || !h->info.rx)
return 0;
pmqpp = (lws_mqtt_publish_param_t *)in;
@ -109,7 +109,7 @@ secstream_mqtt(struct lws *wsi, enum lws_callback_reasons reason, void *user,
break;
case LWS_CALLBACK_MQTT_CLIENT_WRITEABLE:
if (!h)
if (!h || !h->info.tx)
return 0;
lwsl_notice("%s: ss %p: WRITEABLE\n", __func__, h);

View file

@ -75,7 +75,7 @@ secstream_raw(struct lws *wsi, enum lws_callback_reasons reason, void *user,
/* chunks of chunked content, with header removed */
case LWS_CALLBACK_RAW_RX:
if (!h)
if (!h || !h->info.rx)
return 0;
if (h->info.rx(ss_to_userobj(h), (const uint8_t *)in, len, 0) < 0)
@ -85,7 +85,7 @@ secstream_raw(struct lws *wsi, enum lws_callback_reasons reason, void *user,
case LWS_CALLBACK_RAW_WRITEABLE:
lwsl_info("%s: RAW_WRITEABLE\n", __func__);
if (!h)
if (!h || !h->info.tx)
return 0;
buflen = lws_ptr_diff(end, p);

View file

@ -74,7 +74,7 @@ secstream_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
case LWS_CALLBACK_CLIENT_RECEIVE:
// lwsl_user("LWS_CALLBACK_CLIENT_RECEIVE: read %d\n", (int)len);
if (!h)
if (!h || !h->info.rx)
return 0;
if (lws_is_first_fragment(wsi))
f |= LWSSS_FLAG_SOM;
@ -90,7 +90,7 @@ secstream_ws(struct lws *wsi, enum lws_callback_reasons reason, void *user,
return 0; /* don't passthru */
case LWS_CALLBACK_CLIENT_WRITEABLE:
if (!h)
if (!h || !h->info.tx)
return 0;
// lwsl_notice("%s: ss %p: WRITEABLE\n", __func__, h);

View file

@ -90,10 +90,14 @@ lws_ss_event_helper(lws_ss_handle_t *h, lws_ss_constate_t cs)
(void *)h, NULL);
#endif
if (h->h_sink &&h->h_sink->info.state(h->sink_obj, h->h_sink, cs, 0))
if (h->h_sink && h->h_sink->info.state &&
h->h_sink->info.state(h->sink_obj, h->h_sink, cs, 0))
return 1;
return h->info.state(ss_to_userobj(h), NULL, cs, 0);
if (h->info.state)
return h->info.state(ss_to_userobj(h), NULL, cs, 0);
return 0;
}
static void

View file

@ -36,21 +36,6 @@ typedef struct ss_cpd {
uint8_t partway;
} ss_cpd_t;
/* secure streams payload interface */
static int
ss_cpd_rx(void *userobj, const uint8_t *buf, size_t len, int flags)
{
return 0;
}
static int
ss_cpd_tx(void *userobj, lws_ss_tx_ordinal_t ord, uint8_t *buf,
size_t *len, int *flags)
{
return 1;
}
static int
ss_cpd_state(void *userobj, void *sh, lws_ss_constate_t state,
lws_ss_tx_ordinal_t ack)
@ -95,8 +80,6 @@ lws_ss_sys_cpd(struct lws_context *cx)
memset(&ssi, 0, sizeof(ssi));
ssi.handle_offset = offsetof(ss_cpd_t, ss);
ssi.opaque_user_data_offset = offsetof(ss_cpd_t, opaque_data);
ssi.rx = ss_cpd_rx;
ssi.tx = ss_cpd_tx;
ssi.state = ss_cpd_state;
ssi.user_alloc = sizeof(ss_cpd_t);
ssi.streamtype = "captive_portal_detect";