[Asterisk-code-review] message & stasis/messaging: make text message variables work in ARI (asterisk[16])
Kevin Harwell
asteriskteam at digium.com
Mon Feb 24 17:26:21 CST 2020
Kevin Harwell has uploaded this change for review. ( https://gerrit.asterisk.org/c/asterisk/+/13843 )
Change subject: message & stasis/messaging: make text message variables work in ARI
......................................................................
message & stasis/messaging: make text message variables work in ARI
When a text message was received any associated variable was not written to
the ARI TextMessageReceived event. So that event's variable list was always
empty. This was because when iterating over the message variable list Asterisk
only processes variables marked for sending.
This patch adds a new function that allows iterating over variables set upon
receiving a message. And now TextMessageReceived uses that when building the
event data.
As well, in ARI text message variables are defined by a key/value pair named
as such (key=<blah> value=<blah>. However, Asterisk was just setting the name,
and value directly causing TextMessageVariable validation to fail.
This patch makes it so the properly formatted json is produced to in order to
pass validation.
ASTERISK-28755 #close
Change-Id: Ia6051c01a53b30cf7edef84c27df4ed4479b8b6f
---
M include/asterisk/message.h
M main/message.c
M res/stasis/messaging.c
3 files changed, 32 insertions(+), 7 deletions(-)
git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/43/13843/1
diff --git a/include/asterisk/message.h b/include/asterisk/message.h
index 826fa0a..f5b7a75 100644
--- a/include/asterisk/message.h
+++ b/include/asterisk/message.h
@@ -397,6 +397,19 @@
int ast_msg_var_iterator_next(const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value);
/*!
+ * \brief Get the next variable name and value that was set on a received message
+ * \param msg The message with the variables
+ * \param iter An iterator created with ast_msg_var_iterator_init
+ * \param name A pointer to the name result pointer
+ * \param value A pointer to the value result pointer
+ *
+ * \retval 0 No more entries
+ * \retval 1 Valid entry
+ */
+int ast_msg_var_iterator_next_received(const struct ast_msg *msg,
+ struct ast_msg_var_iterator *iter, const char **name, const char **value);
+
+/*!
* \brief Destroy a message variable iterator
* \param iter Iterator to be destroyed
*/
diff --git a/main/message.c b/main/message.c
index 39b8d87..dc81b4e 100644
--- a/main/message.c
+++ b/main/message.c
@@ -627,7 +627,9 @@
return iter;
}
-int ast_msg_var_iterator_next(const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value)
+static int ast_msg_var_iterator_get_next(const struct ast_msg *msg,
+ struct ast_msg_var_iterator *iter, const char **name, const char **value,
+ unsigned int send)
{
struct msg_data *data;
@@ -635,8 +637,8 @@
return 0;
}
- /* Skip any that aren't marked for sending out */
- while ((data = ao2_iterator_next(&iter->iter)) && !data->send) {
+ /* Skip any that we're told to */
+ while ((data = ao2_iterator_next(&iter->iter)) && (data->send != send)) {
ao2_ref(data, -1);
}
@@ -644,7 +646,7 @@
return 0;
}
- if (data->send) {
+ if (data->send == send) {
*name = data->name;
*value = data->value;
}
@@ -656,6 +658,17 @@
return 1;
}
+int ast_msg_var_iterator_next(const struct ast_msg *msg, struct ast_msg_var_iterator *iter, const char **name, const char **value)
+{
+ return ast_msg_var_iterator_get_next(msg, iter, name, value, 1);
+}
+
+int ast_msg_var_iterator_next_received(const struct ast_msg *msg,
+ struct ast_msg_var_iterator *iter, const char **name, const char **value)
+{
+ return ast_msg_var_iterator_get_next(msg, iter, name, value, 0);
+}
+
void ast_msg_var_unref_current(struct ast_msg_var_iterator *iter)
{
ao2_cleanup(iter->current_used);
diff --git a/res/stasis/messaging.c b/res/stasis/messaging.c
index a7716b8..d2b22c6 100644
--- a/res/stasis/messaging.c
+++ b/res/stasis/messaging.c
@@ -268,10 +268,9 @@
return NULL;
}
- while (ast_msg_var_iterator_next(msg, it_vars, &name, &value)) {
+ while (ast_msg_var_iterator_next_received(msg, it_vars, &name, &value)) {
struct ast_json *json_tuple;
-
- json_tuple = ast_json_pack("{s: s}", name, value);
+ json_tuple = ast_json_pack("{s: s, s: s}", "key", name, "value", value);
if (!json_tuple) {
ast_json_unref(json_vars);
ast_msg_var_iterator_destroy(it_vars);
--
To view, visit https://gerrit.asterisk.org/c/asterisk/+/13843
To unsubscribe, or for help writing mail filters, visit https://gerrit.asterisk.org/settings
Gerrit-Project: asterisk
Gerrit-Branch: 16
Gerrit-Change-Id: Ia6051c01a53b30cf7edef84c27df4ed4479b8b6f
Gerrit-Change-Number: 13843
Gerrit-PatchSet: 1
Gerrit-Owner: Kevin Harwell <kharwell at digium.com>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.digium.com/pipermail/asterisk-code-review/attachments/20200224/27d11ba1/attachment.html>
More information about the asterisk-code-review
mailing list