mirror of
https://github.com/warmcat/libwebsockets.git
synced 2025-03-09 00:00:04 +01:00
ss: mqtt: add will and other sundries to policy
Replace the hacked-in constants with policy entries for sundry MQTT features, and add to the policy readme.
This commit is contained in:
parent
28ce32af64
commit
9695e23c00
4 changed files with 100 additions and 6 deletions
|
@ -211,7 +211,16 @@ typedef struct lws_ss_policy {
|
|||
struct {
|
||||
const char *topic; /* stream sends on this topic */
|
||||
const char *subscribe; /* stream subscribes to this topic */
|
||||
|
||||
const char *will_topic;
|
||||
const char *will_message;
|
||||
|
||||
uint16_t keep_alive;
|
||||
uint8_t qos;
|
||||
uint8_t clean_start;
|
||||
uint8_t will_qos;
|
||||
uint8_t will_retain;
|
||||
|
||||
} mqtt;
|
||||
|
||||
/* details for non-http related protocols... */
|
||||
|
|
|
@ -292,6 +292,55 @@ Set the topic this streamtype subscribes to
|
|||
|
||||
Set the QOS level for this streamtype
|
||||
|
||||
### `mqtt_keep_alive`
|
||||
|
||||
16-bit number representing MQTT keep alive for the stream.
|
||||
|
||||
This is applied at connection time... where different streams may bind to the
|
||||
same underlying MQTT connection, all the streams should have an identical
|
||||
setting for this.
|
||||
|
||||
### `mqtt_clean_start`
|
||||
|
||||
Set to true if the connection should use MQTT's "clean start" feature.
|
||||
|
||||
This is applied at connection time... where different streams may bind to the
|
||||
same underlying MQTT connection, all the streams should have an identical
|
||||
setting for this.
|
||||
|
||||
### `mqtt_will_topic`
|
||||
|
||||
Set the topic of the connection's will message, if any (there is none by default).
|
||||
|
||||
This is applied at connection time... where different streams may bind to the
|
||||
same underlying MQTT connection, all the streams should have an identical
|
||||
setting for this.
|
||||
|
||||
### `mqtt_will_message`
|
||||
|
||||
Set the content of the connect's will message, if any (there is none by default).
|
||||
|
||||
This is applied at connection time... where different streams may bind to the
|
||||
same underlying MQTT connection, all the streams should have an identical
|
||||
setting for this.
|
||||
|
||||
### `mqtt_will_qos`
|
||||
|
||||
Set the QoS of the will message, if any (there is none by default).
|
||||
|
||||
This is applied at connection time... where different streams may bind to the
|
||||
same underlying MQTT connection, all the streams should have an identical
|
||||
setting for this.
|
||||
|
||||
### `mqtt_will_retain`
|
||||
|
||||
Set to true if the connection should use MQTT's "will retain" feature, if there
|
||||
is a will message (there is none by default).
|
||||
|
||||
This is applied at connection time... where different streams may bind to the
|
||||
same underlying MQTT connection, all the streams should have an identical
|
||||
setting for this.
|
||||
|
||||
## Loading and using updated remote policy
|
||||
|
||||
If the default, hardcoded policy includes a streamtype `fetch_policy`,
|
||||
|
|
|
@ -85,6 +85,12 @@ static const char * const lejp_tokens_policy[] = {
|
|||
"s[].*.mqtt_topic",
|
||||
"s[].*.mqtt_subscribe",
|
||||
"s[].*.mqtt_qos",
|
||||
"s[].*.mqtt_keep_alive",
|
||||
"s[].*.mqtt_clean_start",
|
||||
"s[].*.mqtt_will_topic",
|
||||
"s[].*.mqtt_will_message",
|
||||
"s[].*.mqtt_will_qos",
|
||||
"s[].*.mqtt_will_retain",
|
||||
"s[].*",
|
||||
};
|
||||
|
||||
|
@ -142,6 +148,12 @@ typedef enum {
|
|||
LSSPPT_MQTT_TOPIC,
|
||||
LSSPPT_MQTT_SUBSCRIBE,
|
||||
LSSPPT_MQTT_QOS,
|
||||
LSSPPT_MQTT_KEEPALIVE,
|
||||
LSSPPT_MQTT_CLEAN_START,
|
||||
LSSPPT_MQTT_WILL_TOPIC,
|
||||
LSSPPT_MQTT_WILL_MESSAGE,
|
||||
LSSPPT_MQTT_WILL_QOS,
|
||||
LSSPPT_MQTT_WILL_RETAIN,
|
||||
LSSPPT_STREAMTYPES
|
||||
} policy_token_t;
|
||||
|
||||
|
@ -657,6 +669,30 @@ lws_ss_policy_parser_cb(struct lejp_ctx *ctx, char reason)
|
|||
a->curr[LTY_POLICY].p->u.mqtt.qos = atoi(ctx->buf);
|
||||
break;
|
||||
|
||||
case LSSPPT_MQTT_KEEPALIVE:
|
||||
a->curr[LTY_POLICY].p->u.mqtt.keep_alive = atoi(ctx->buf);
|
||||
break;
|
||||
|
||||
case LSSPPT_MQTT_CLEAN_START:
|
||||
a->curr[LTY_POLICY].p->u.mqtt.clean_start =
|
||||
reason == LEJPCB_VAL_TRUE;
|
||||
break;
|
||||
case LSSPPT_MQTT_WILL_TOPIC:
|
||||
pp = (char **)&a->curr[LTY_POLICY].p->u.mqtt.will_topic;
|
||||
goto string2;
|
||||
|
||||
case LSSPPT_MQTT_WILL_MESSAGE:
|
||||
pp = (char **)&a->curr[LTY_POLICY].p->u.mqtt.will_message;
|
||||
goto string2;
|
||||
|
||||
case LSSPPT_MQTT_WILL_QOS:
|
||||
a->curr[LTY_POLICY].p->u.mqtt.will_qos = atoi(ctx->buf);
|
||||
break;
|
||||
case LSSPPT_MQTT_WILL_RETAIN:
|
||||
a->curr[LTY_POLICY].p->u.mqtt.will_retain =
|
||||
reason == LEJPCB_VAL_TRUE;
|
||||
break;
|
||||
|
||||
case LSSPPT_PROTOCOL:
|
||||
a->curr[LTY_POLICY].p->protocol = 0xff;
|
||||
for (n = 0; n < (int)LWS_ARRAY_SIZE(protonames); n++)
|
||||
|
|
|
@ -204,12 +204,12 @@ secstream_connect_munge_mqtt(lws_ss_handle_t *h, char *buf, size_t len,
|
|||
memset(&ct->ccp, 0, sizeof(ct->ccp));
|
||||
|
||||
ct->ccp.client_id = "lwsMqttClient";
|
||||
ct->ccp.keep_alive = 60;
|
||||
ct->ccp.clean_start = 1;
|
||||
ct->ccp.will_param.topic = "good/bye";
|
||||
ct->ccp.will_param.message = "sign-off";
|
||||
ct->ccp.will_param.qos = 0;
|
||||
ct->ccp.will_param.retain = 0;
|
||||
ct->ccp.keep_alive = h->policy->u.mqtt.keep_alive;
|
||||
ct->ccp.clean_start = h->policy->u.mqtt.clean_start;
|
||||
ct->ccp.will_param.topic = h->policy->u.mqtt.will_topic;
|
||||
ct->ccp.will_param.message = h->policy->u.mqtt.will_message;
|
||||
ct->ccp.will_param.qos = h->policy->u.mqtt.will_qos;
|
||||
ct->ccp.will_param.retain = h->policy->u.mqtt.will_retain;
|
||||
|
||||
lwsl_notice("%s\n", __func__);
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue