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