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

283 commits

Author SHA1 Message Date
Andy Green
310abddf5e coverity: ss: mqtt: remove needless wsi check
881     	case LWS_CALLBACK_MQTT_UNSUBSCRIBE_TIMEOUT:
>>>     CID 392688:    (REVERSE_INULL)
>>>     Null-checking "wsi" suggests that it may be null, but it has already been dereferenced on all paths leading to the check.
882     		if (!wsi || !wsi->mqtt)
883     			return -1;

wsi can't be NULL for a callback specific to a wsi.
2022-05-17 15:53:53 +01:00
Andy Green
71db363fe4 ss: mqtt: remove c99isms and fix types
Blows on Centos 7 / 8 in Sai with

/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c: In function âexpand_metadataâ:
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:304:2: error: missing braces around initializer [-Werror=missing-braces]
lws_strexp_t exp = {0};
^
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:304:2: error: (near initialization for âexp.nameâ) [-Werror=missing-braces]
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:304:2: error: missing initializer for field âcbâ of âlws_strexp_tâ [-Werror=missing-field-initializers]
In file included from /home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/include/libwebsockets.h:737:0,
from /home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/core/./private-lib-core.h:146,
from /home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:25:
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/include/libwebsockets/lws-tokenize.h:196:23: note: âcbâ declared here
lws_strexp_expand_cb cb;
^
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c: In function âsecstream_mqtt_shadow_subscribeâ:
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:441:2: error: âforâ loop initial declarations are only allowed in C99 mode
for (unsigned int i = 0; i < suffixes_len; i++) {
^
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:441:2: note: use option -std=c99 or -std=gnu99 to compile your code
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c: In function âsecstream_mqttâ:
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:481:2: error: missing braces around initializer [-Werror=missing-braces]
lws_strexp_t exp = {0};
^
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:481:2: error: (near initialization for âexp.nameâ) [-Werror=missing-braces]
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:481:2: error: missing initializer for field âcbâ of âlws_strexp_tâ [-Werror=missing-field-initializers]
In file included from /home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/include/libwebsockets.h:737:0,
from /home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/core/./private-lib-core.h:146,
from /home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:25:
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/include/libwebsockets/lws-tokenize.h:196:23: note: âcbâ declared here
lws_strexp_expand_cb cb;
^
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:677:27: error: conversion to âuint32_tâ from âsize_tâ may alter its value [-Werror=conversion]
uint32_t acc_n = strlen(LWS_MQTT_SHADOW_RESP_ACCEPTED_STR);
^
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:678:27: error: conversion to âuint32_tâ from âsize_tâ may alter its value [-Werror=conversion]
uint32_t rej_n = strlen(LWS_MQTT_SHADOW_RESP_REJECTED_STR);
^
/home/sai/big-long-dir-to-make-rpm-happy-o/jobs/0-0.0/libwebsockets/lib/secure-streams/protocols/ss-mqtt.c:680:4: error: âforâ loop initial declarations are only allowed in C99 mode
for (uint32_t i = 0; i < h->u.mqtt.shadow_sub.num_topics; i++) {

little additional cleaning and conversion to modern lwsl_xxx_yyy(xxx, ...)
2022-05-17 15:53:53 +01:00
Chunho Lee
8b1693a05e ss: mqtt: add support for AWS IoT Shadow topic
This introduces AWS IoT Shadow topic support. This subscribes and
unsubscribes shadow response topics before and after shadow topic
is transmitted.
2022-05-17 15:53:53 +01:00
Chunho Lee
21baf47aed ss: mqtt: add QOS_NACK_REMOTE state on PUBLISH failure
This adds setting QOS_NACK_REMOTE state when QoS 1/2 PUBLISH
transmissions and all retries are unacked and failed. Also this
allows state transitions between QOS_ACK_REMOTE and QOS_NACK_REMOTE.
2022-05-17 15:37:16 +01:00
Chunho Lee
a51d3564a2 ss: mqtt: set the CONNECTED state after Birth
This sets the CONNECTED state after Birth topic is processed if
the stream has defined a Birth topic to avoid any confict when
the connection is not stable and the Birth is delayed.
2022-05-17 15:37:16 +01:00
Andy Green
8d560a562f ss: POLL to all retries failed is possible
It's possible we started POLL, but no connection could happen for some
reason, and we end in the window between POLL and trying the connection.
2022-02-10 08:10:25 +00:00
Andy Green
890766083d ss: avoid POLL-POLL transition 2022-02-10 06:11:50 +00:00
Andy Green
c7e82fb29c ss: http: unreachable superfluous if we did DISCONNECTED 2022-02-09 20:12:31 +00:00
Andy Green
3eae5f8bca ss: reject direct protocol metadata if NULL ss wsi
The ss wsi may be NULL after any time around the event loop.  Make sure we
check that before we start trying to use it.
2022-02-09 20:12:31 +00:00
Andy Green
1027d3a740 ss: http: ensure SS points to wsi when using wsi pointing to SS
If we're going to take a wsi's word for it that it is bound to a particular
SS, make sure the SS is also bound to the same wsi.
2022-02-09 19:41:17 +00:00
Chunho Lee
a80fbeb820 ss: mqtt: add support for retained message 2022-02-07 09:37:34 +00:00
Chunho Lee
eda299bd71 ss: mqtt: fix wrong QoS value on Birth message 2022-02-03 10:20:34 +00:00
Andy Green
b709d50f8f coverity: mark false positive
Coverity doesn't understand the state relationship means that ssi will only
be used to create the proxy-side SS representing the remote client SS,
which happens as the first command in the state flow.

Mark the call up to disable the false error report.
2022-01-28 10:20:29 +00:00
Andy Green
1b77c2ff4c coverity: change ss handle priv style
Coverity is able to misunderstand &h[1] to be a dereference of h, when it
is just (h + 1).

Adapt places where we use this style to get a pointer to the SS priv data
to use (h + 1) so we don't have to see any more of coverity's confusion.
2022-01-28 08:59:52 +00:00
Andy Green
121dd5e8ee ss: revert make ss timeout handle underlying wsi gone 2021-11-09 09:54:08 +00:00
Andy Green
f9fc45bd98 sspc: proxy: coverity: handle unknown metadata name 2021-11-08 11:05:28 +00:00
Andy Green
b415f59bd2 ss-deserialize: add pointless h NULL check
h cannot be NULL since it's set by address offset earlier.
Help coverity understand that.
2021-11-08 11:05:28 +00:00
Andy Green
b0cd8f6703 ss-h1: coverity: add needless header NULL check
Coverity does not understand that once we checked that  the header has
a non-zero length, the associated pointer can never be NULL.  Add a
pointless check to make it happy.
2021-11-08 11:05:28 +00:00
Jin Wang
b43f90a8ed ss: policy: adaptations for dynamic policy 2021-10-21 16:14:02 +01:00
Jin Wang
e9c92ec161 metrics: ss: skip tagging if no ss streamtypename 2021-10-19 10:51:23 +01:00
Yichen Gu
9b56baca8f ss: static policy generator: fix filepath detection 2021-10-13 15:55:56 +01:00
Chunho Lee
bf5744ab07 ss-mqtt: Add support for Birth message
This provides Birth message on SS policy. The Birth message is
a message published just after the MQTT connection has been
established.
2021-10-07 11:22:21 +01:00
Chunho Lee
6decd5a7e7 ss-mqtt: Skip SUBSCRIBE when MQTT session is resumed 2021-10-07 11:22:08 +01:00
Andy Green
6cdaf85b89 ss: allow POLL from CONNECTING
Since CONNECTING is async and may take a while, there's nothing actually
wrong if the application asks to write again in the meanwhile and provokes
POLL.
2021-10-05 07:40:17 +01:00
Andy Green
ad990a61a0 ss: policy: unwind after policy syntax errors cleanly 2021-10-05 07:40:17 +01:00
Andy Green
b6004e08c9 mqtt: allow indicating client_id is not on heap
Not sure why we don't leave any freeing to the caller, but since we don't
allow indicating that the provided client id should not be freed.
2021-10-05 07:09:47 +01:00
Andy Green
1e56dc9642 ss: http: defend against CONNECTED-CONNECTED 2021-10-04 12:55:45 +01:00
Andy Green
a0e60304a4 ss: h1: defeat CCE if told CONNECTED 2021-10-04 12:55:45 +01:00
Andy Green
9ff83d9e75 ss: h1: be sure to go through DISCONNECTING if CCE 2021-10-04 12:55:45 +01:00
Andy Green
65a954a9c4 ss-h1: reset message state for repeated use
This lets one "opportunistic" mode http policy SS be able to be used
multiple times.
2021-10-04 12:55:45 +01:00
Andy Green
81a3ca3e84 ss: port binance example 2021-08-31 05:45:40 +01:00
Yichen Gu
b31c5d6ffe http: cookies: support cookie jar in and out 2021-08-21 17:44:40 +01:00
Andy Green
1b9ef51a95 conmon: make sure we report http specific on close 2021-08-19 10:01:56 +01:00
Andy Green
33d06386ff ss: CREATING to TIMEOUT is possible with sspc and active timeout 2021-08-19 08:10:54 +01:00
Andy Green
5de5ee74bf ss: lws_ss_client_connect also only pass up return
We removed the _lws_ss_handle_state_ret_CAN_DESTROY_HANDLE() from
request_tx, hane to do the same for lws_ss_client_connect()
2021-08-19 05:31:15 +01:00
Andy Green
43f290adbc sspc: add LWSSSCS_UPSTREAM_LINK_RETRY state
Add a transient state that indicates that we are retrying an upstream link
before the sspc creation can proceed.

The state() ack paramemeter shows the number of ms we have been retrying.

This is only issued if proxy mode clients are having difficulty reaching
their proxy, and are retrying.

As a transient state it doesn't affect the ss overall state, which will not
have reached CREATING yet.
2021-08-19 05:31:15 +01:00
Andy Green
37f3244076 conmon: add dns and protocol_specific
This adds an indication of dns disposition to the conmon results,
and for http, if it gets that far a protocol-specific indication
of http response code.
2021-08-19 05:31:04 +01:00
Zhao Lou
2951a92ed8 conmon: fix missing quote in JSON 2021-08-19 05:28:27 +01:00
Yichen Gu
4c99f85a16 conmon: pass userobj to ss rx not handle 2021-08-16 08:07:35 +01:00
Andy Green
387a406f07 ss: conmon: assert if wsi ss handle is stale
Add a way to confirm that the ss handle recovered from a ss wsi is still
valid, by walking the pt ss list and confirming it is on there before using
it with conmon.

If it isn't, it will assert.
2021-08-16 08:07:35 +01:00
Andy Green
9cd8d1f9f3 sspc: enable CCEs on proxy link wsi
Normally we suppress CCEs while still in the client connection loop time,
since we can return failure directly to the caller.

In sspc client case, defeat that, in order to have a convenient place to
put code that cares about ongoing proxy link connection failures.
2021-08-16 08:07:35 +01:00
Andy Green
243c21deac ss: add fault injections in creation
Add 9 fault injection cases in SS creation flow, and 5 of those
instantiate in the minimal examples ctests.  The other 4 relate
to static policy and server, I tested the server ones by hand.

These tests confirm the recent change to unpick create using
lws_ss_destroy.
2021-08-16 08:07:35 +01:00
Jed Lu
ca16a07a9b ss: unpick failed create using destroy
The late_bail discrete unpick flow is missing some pieces compared
to lws_ss_destroy.  Unify the creation fail flow to also use
lws_ss_destroy so everything in one place.

Make lws_ss_destroy() not issue any states if the creation flow
didn't get as far as issuing CREATING.
2021-08-16 08:07:35 +01:00
Andy Green
406b79e440 ss: handle DESTROY_ME from inside ss creation
Normally when doing a Client Connection Error handling,
we can action any ss relationship straight away since
we are in a wsi callback without any ss-aware parents
in the call stack.

But in the specific case we're doing the initial onward
wsi connection part on behalf of a ss, in fact the call
stack does have earlier  parents holding references on
the related ss.

For example

  secstream_h1 (ss-h1.c:470)                          CCE
  lws_inform_client_conn_fail (close.c:319)           fails early
  lws_client_connect_2_dnsreq (connect2.c:349)
  lws_http_client_connect_via_info2 (connect.c:71)
  lws_header_table_attach (parsers.c:291)
  rops_client_bind_h1 (ops-h1.c:1001)
  lws_client_connect_via_info (connect.c:429)         start onward connect
  _lws_ss_client_connect (secure-streams.c:859)
  _lws_ss_request_tx (secure-streams.c:1577)
  lws_ss_request_tx (secure-streams.c:1515)           request tx
  ss_cpd_state (captive-portal-detect.c:50)
  lws_ss_event_helper (secure-streams.c:408)
  lws_ss_create (secure-streams.c:1256)                SS Create

Under these conditions, we can't action the DESTROY_ME that
is coming when the CCE exhausts the retries.

This patch adds a flag that is set during the SS's onward wsi
connection attempt and causes it to stash rather than action
the result code.

The result code is brought out from the stash when we return to
_lws_ss_client_connect level, and passed up in the SS flow until
it is actioned, cleanly aborting the ss create.
2021-08-16 08:07:35 +01:00
Andy Green
e644bb4a6e cpd: pass up lws_ss_request_tx ret 2021-08-16 08:07:32 +01:00
Andy Green
f3d5b9b99a service: assert on thread shenanigans 2021-08-13 05:25:01 +01:00
Yichen Gu
9365490ef0 conmon: only build if WITH_CONMON 2021-08-09 17:31:16 +01:00
Jed Lu
62b915c879 ss: increase set_metadata length type to size_t 2021-08-09 17:31:16 +01:00
Andy Green
3073655759 ss: zero on destroy 2021-08-09 17:31:16 +01:00
Andy Green
48541efcc2 mqtt: handle NULL mqtt publish metadata 2021-07-08 10:16:06 +01:00