<p>George Joseph <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/10977">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve; Approved for Submit
Joshua C. Colp: Looks good to me, but someone else must approve
Matthew Fredrickson: Looks good to me, approved
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">json.c/strings.c - Add a couple of utility functions<br><br>Added 'ast_json_object_string_get' to the JSON wrapper in order to make it a<br>little easier to retrieve a string field from the JSON object.<br><br>Also added an 'ast_strings_equal' function that safely checks (checks for NULLs)<br>for equality between two strings.<br><br>Change-Id: I26f0a16d61537505eb41b4b05ef2e6d67fc2541b<br>---<br>M include/asterisk/json.h<br>M include/asterisk/strings.h<br>M main/strings.c<br>3 files changed, 35 insertions(+), 0 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;"><span>diff --git a/include/asterisk/json.h b/include/asterisk/json.h</span><br><span>index 011359b..02b617e 100644</span><br><span>--- a/include/asterisk/json.h</span><br><span>+++ b/include/asterisk/json.h</span><br><span>@@ -591,6 +591,17 @@</span><br><span> struct ast_json *ast_json_object_get(struct ast_json *object, const char *key);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Get a string field from a JSON object.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.26.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param object JSON object.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param key Key of string field to look up.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return String value of given \a key.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return \c NULL on error, or key value is not a string.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+#define ast_json_object_string_get(object, key) ast_json_string_get(ast_json_object_get(object, key))</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Set a field in a JSON object.</span><br><span> * \since 12.0.0</span><br><span> *</span><br><span>diff --git a/include/asterisk/strings.h b/include/asterisk/strings.h</span><br><span>index 85393b4..0f0e891 100644</span><br><span>--- a/include/asterisk/strings.h</span><br><span>+++ b/include/asterisk/strings.h</span><br><span>@@ -1355,6 +1355,21 @@</span><br><span> char *ast_generate_random_string(char *buf, size_t size);</span><br><span> </span><br><span> /*!</span><br><span style="color: hsl(120, 100%, 40%);">+ * \brief Compare strings for equality checking for NULL.</span><br><span style="color: hsl(120, 100%, 40%);">+ * \since 13.26.0</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * This function considers NULL values as non-strings, thus a false condition.</span><br><span style="color: hsl(120, 100%, 40%);">+ * This means that it will return false if one, or both of the given values are</span><br><span style="color: hsl(120, 100%, 40%);">+ * NULL (i.e. two NULLs are not equal strings).</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param str1 The string to compare to str2</span><br><span style="color: hsl(120, 100%, 40%);">+ * \param str2 The string to compare to str1</span><br><span style="color: hsl(120, 100%, 40%);">+ *</span><br><span style="color: hsl(120, 100%, 40%);">+ * \return true if valid strings and equal, false otherwise.</span><br><span style="color: hsl(120, 100%, 40%);">+ */</span><br><span style="color: hsl(120, 100%, 40%);">+int ast_strings_equal(const char *str1, const char *str2);</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span style="color: hsl(120, 100%, 40%);">+/*!</span><br><span> * \brief Compares 2 strings using realtime-style operators</span><br><span> * \since 13.9.0</span><br><span> *</span><br><span>diff --git a/main/strings.c b/main/strings.c</span><br><span>index 8102c3e..cdb1984 100644</span><br><span>--- a/main/strings.c</span><br><span>+++ b/main/strings.c</span><br><span>@@ -247,6 +247,15 @@</span><br><span> return buf;</span><br><span> }</span><br><span> </span><br><span style="color: hsl(120, 100%, 40%);">+int ast_strings_equal(const char *str1, const char *str2)</span><br><span style="color: hsl(120, 100%, 40%);">+{</span><br><span style="color: hsl(120, 100%, 40%);">+ if (!str1 || !str2) {</span><br><span style="color: hsl(120, 100%, 40%);">+ return 0;</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%);">+ return str1 == str2 || !strcmp(str1, str2);</span><br><span style="color: hsl(120, 100%, 40%);">+}</span><br><span style="color: hsl(120, 100%, 40%);">+</span><br><span> int ast_strings_match(const char *left, const char *op, const char *right)</span><br><span> {</span><br><span> char *internal_op = (char *)op;</span><br><span></span><br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/10977">change 10977</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/10977"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I26f0a16d61537505eb41b4b05ef2e6d67fc2541b </div>
<div style="display:none"> Gerrit-Change-Number: 10977 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation (1000185) </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Joshua C. Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <kharwell@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Matthew Fredrickson <creslin@digium.com> </div>