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

sspc: proxy: extend DESTROY_ME

This commit is contained in:
Andy Green 2020-08-16 05:27:40 +01:00
parent c6e1352e99
commit 83912f40e8
4 changed files with 55 additions and 11 deletions

View file

@ -333,6 +333,14 @@ struct policy_cb_args {
extern const lws_ss_policy_t pol_smd;
#endif
/*
* returns one of
*
* LWSSSSRET_OK
* LWSSSSRET_DISCONNECT_ME
* LWSSSSRET_DESTROY_ME
*/
int
lws_ss_deserialize_parse(struct lws_ss_serialization_parser *par,
struct lws_context *context,

View file

@ -161,6 +161,9 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason,
break;
case LWS_CALLBACK_RAW_RX:
/*
* ie, the proxy has sent us something
*/
lwsl_info("%s: RAW_RX: rx %d\n", __func__, (int)len);
if (!h || !h->cwsi) {
@ -169,10 +172,18 @@ callback_sspc_client(struct lws *wsi, enum lws_callback_reasons reason,
return -1;
}
if (lws_ss_deserialize_parse(&h->parser, lws_get_context(wsi),
n = lws_ss_deserialize_parse(&h->parser, lws_get_context(wsi),
h->dsh, in, len, &h->state, h,
(lws_ss_handle_t **)m, &h->ssi, 1))
(lws_ss_handle_t **)m, &h->ssi, 1);
switch (n) {
case LWSSSSRET_OK:
break;
case LWSSSSRET_DISCONNECT_ME:
return -1;
case LWSSSSRET_DESTROY_ME:
lws_sspc_destroy(&h);
return -1;
}
if (wsi && (h->state == LPCSCLI_LOCAL_CONNECTED ||
h->state == LPCSCLI_ONWARD_CONNECT))

View file

@ -337,6 +337,9 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
break;
case LWS_CALLBACK_RAW_RX:
/*
* ie, the proxy is receiving something from a client
*/
lwsl_info("%s: RX: rx %d\n", __func__, (int)len);
if (!conn || !conn->wsi) {
@ -357,11 +360,19 @@ callback_ss_proxy(struct lws *wsi, enum lws_callback_reasons reason,
ssi.tx = ss_proxy_onward_tx;
}
ssi.state = ss_proxy_onward_state;
ssi.flags = 0;
if (lws_ss_deserialize_parse(&conn->parser,
n = lws_ss_deserialize_parse(&conn->parser,
lws_get_context(wsi), conn->dsh, in, len,
&conn->state, conn, &conn->ss, &ssi, 0)) {
lwsl_err("%s: RAW_RX: deserialize_parse fail\n", __func__);
&conn->state, conn, &conn->ss, &ssi, 0);
switch (n) {
case LWSSSSRET_OK:
break;
case LWSSSSRET_DISCONNECT_ME:
return -1;
case LWSSSSRET_DESTROY_ME:
if (conn->ss)
lws_ss_destroy(&conn->ss);
return -1;
}

View file

@ -307,6 +307,12 @@ lws_ss_serialize_txcr(struct lws_dsh *dsh, int txcr)
* handle
*
* proxy: pss is pointing to &conn->ss, a pointer to the ss handle
*
* Returns one of
*
* LWSSSSRET_OK
* LWSSSSRET_DISCONNECT_ME
* LWSSSSRET_DESTROY_ME
*/
/* convert userdata ptr _pss to handle pointer, allowing for any layout in
@ -636,7 +642,7 @@ payload_ff:
lwsl_err("%s: unable to alloc in dsh 3\n",
__func__);
return 1;
return LWSSSSRET_DISCONNECT_ME;
}
if (proxy_pss_to_ss_h(pss))
@ -1130,20 +1136,28 @@ payload_ff:
lwsl_info("%s: forwarding proxied state %s\n",
__func__, lws_ss_state_name(par->ctr));
#endif
if (ssi->state(client_pss_to_userdata(pss),
NULL, par->ctr, par->flags))
n = ssi->state(client_pss_to_userdata(pss),
NULL, par->ctr, par->flags);
switch (n) {
case LWSSSSRET_OK:
break;
case LWSSSSRET_DISCONNECT_ME:
goto hangup;
case LWSSSSRET_DESTROY_ME:
return LWSSSSRET_DESTROY_ME;
}
swallow:
break;
default:
goto hangup;
}
}
return 0;
return LWSSSSRET_OK;
hangup:
return -1;
return LWSSSSRET_DISCONNECT_ME;
}