Module: kamailio
Branch: master
Commit: ea699419df555b4453e1eb96659cfec8912ac3bc
URL:
https://github.com/kamailio/kamailio/commit/ea699419df555b4453e1eb96659cfec…
Author: Thomas Weber <thomas.weber(a)pascom.net>
Committer: Thomas Weber <thomas.weber(a)pascom.net>
Date: 2020-01-03T17:31:34+01:00
mqtt: expose received message qos level via pv
---
Modified: src/modules/mqtt/doc/mqtt_admin.xml
Modified: src/modules/mqtt/mqtt_dispatch.c
---
Diff:
https://github.com/kamailio/kamailio/commit/ea699419df555b4453e1eb96659cfec…
Patch:
https://github.com/kamailio/kamailio/commit/ea699419df555b4453e1eb96659cfec…
---
diff --git a/src/modules/mqtt/doc/mqtt_admin.xml b/src/modules/mqtt/doc/mqtt_admin.xml
index 791daa5920..20277ff289 100644
--- a/src/modules/mqtt/doc/mqtt_admin.xml
+++ b/src/modules/mqtt/doc/mqtt_admin.xml
@@ -563,6 +563,9 @@ event_route[mqtt:message] {
<listitem><para>
<emphasis>$mqtt(msg)</emphasis> - Received message (only in
mqtt:message)
</para></listitem>
+ <listitem><para>
+ <emphasis>$mqtt(qos)</emphasis> - The received message QOS level: 0, 1 ,2
(only in mqtt:message)
+ </para></listitem>
</itemizedlist>
<para>
Exported pseudo-variables are documented at &kamwikilink;.
diff --git a/src/modules/mqtt/mqtt_dispatch.c b/src/modules/mqtt/mqtt_dispatch.c
index 7a39ede29b..a32d8c312d 100644
--- a/src/modules/mqtt/mqtt_dispatch.c
+++ b/src/modules/mqtt/mqtt_dispatch.c
@@ -354,11 +354,13 @@ void mqtt_on_message(struct mosquitto *mosquitto, void *userdata,
const struct m
sip_msg_t tmsg;
str topic, payload;
+ int qos;
topic.s = message->topic;
topic.len = strlen(message->topic);
payload.s = (char*) message->payload;
payload.len = message->payloadlen;
- LM_DBG("mqtt message [%s] -> [%s]\n", topic.s, payload.s);
+ qos = message->qos;
+ LM_DBG("mqtt message [%s] -> [%s] (qos %d)\n", topic.s, payload.s, qos);
cfg_update();
@@ -425,6 +427,8 @@ int pv_parse_mqtt_name(pv_spec_t *sp, str *in)
case 3:
if(strncmp(in->s, "msg", 3)==0)
sp->pvp.pvn.u.isname.name.n = 1;
+ else if(strncmp(in->s, "qos", 3)==0)
+ sp->pvp.pvn.u.isname.name.n = 2;
else goto error;
break;
case 5:
@@ -452,6 +456,7 @@ int pv_get_mqtt(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
{
struct mosquitto_message* message;
str topic, payload;
+ int qos;
if(param==NULL || res==NULL)
return -1;
@@ -467,6 +472,7 @@ int pv_get_mqtt(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
topic.len = strlen(message->topic);
payload.s = (char*) message->payload;
payload.len = message->payloadlen;
+ qos = message->qos;
}
// populate value depeding on the param name
@@ -477,6 +483,8 @@ int pv_get_mqtt(sip_msg_t *msg, pv_param_t *param, pv_value_t *res)
return pv_get_strval(msg, param, res, &topic);
case 1:
return pv_get_strval(msg, param, res, &payload);
+ case 2:
+ return pv_get_sintval(msg, param, res, qos);
default:
return pv_get_null(msg, param, res);
}