<p> Attention is currently required from: Kevin Harwell. </p>
<p><a href="https://gerrit.asterisk.org/c/asterisk/+/18012">View Change</a></p><p>1 comment:</p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0;"><p><a href="null">File funcs/func_json.c:</a></p><ul style="list-style: none; padding: 0;"><li style="margin: 0; padding: 0 0 0 16px;"><p style="margin-bottom: 4px;"><a href="https://gerrit.asterisk.org/c/asterisk/+/18012/comment/cd877ee7_bc21f377">Patch Set #4, Line 90:</a> </p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;"><pre style="font-family: monospace,monospace; white-space: pre-wrap;">static int parse_node(char **key, char *currentkey, char *nestchar, int count, struct ast_json *json, char *buf, size_t len)<br>{<br>     const char *result = NULL;<br>    char *previouskey;<br>    struct ast_json *jsonval = json;<br><br>    snprintf(buf, len, "%s", ""); /* clear the buffer from previous round if necessary */<br>     if (!json) { /* no error or warning should be thrown */<br>               ast_debug(1, "Could not find key '%s' in parsed JSON\n", currentkey);<br>               return -1;<br>    }<br><br>   switch(ast_json_typeof(jsonval)) {<br>            unsigned long int size;<br>               int r;<br>                char *result2;<br><br>              case AST_JSON_STRING:<br>                 ast_debug(1, "Got JSON string\n");<br>                  result = ast_json_string_get(jsonval);<br>                        snprintf(buf, len, "%s", result);<br>                   break;<br>                case AST_JSON_INTEGER:<br>                        ast_debug(1, "Got JSON integer\n");<br>                 r = ast_json_integer_get(jsonval);<br>                    snprintf(buf, len, "%d", r); /* the snprintf below is mutually exclusive with this one */<br>                   break;<br>                case AST_JSON_ARRAY:<br>                  ast_debug(1, "Got JSON array\n");<br>                   previouskey = currentkey;<br>                     currentkey = strsep(key, nestchar); /* retrieve the desired index */<br>                  size = ast_json_array_size(jsonval);<br>                  ast_debug(1, "Parsed JSON array of size %lu, key: %s\n", size, currentkey);<br>                 if (!currentkey) { /* this is the end, so just dump the array */<br>                              if (count) {<br>                                  ast_debug(1, "No key on which to index in the array, so returning count: %lu\n", size);<br>                                     snprintf(buf, len, "%lu", size);<br>                                    return 0;<br>                             } else {<br>                                      char *jsonarray;<br>                                      ast_debug(1, "No key on which to index in the array, so dumping '%s' array\n", previouskey);<br>                                        jsonarray = ast_json_dump_string(jsonval);<br>                                    ast_copy_string(buf, jsonarray, len);<br>                                 ast_json_free(jsonarray);<br>                             }<br>                     } else if (ast_str_to_int(currentkey, &r) || r < 0) {<br>                          ast_debug(1, "Requested index '%s' is not numeric or is invalid\n", currentkey);<br>                    } else if (r >= size) {<br>                            ast_debug(1, "Requested index '%d' does not exist in parsed array\n", r);<br>                   } else {<br>                              struct ast_json *json2 = ast_json_array_get(jsonval, r);<br>                              if (!json2) {<br>                                 ast_debug(1, "Array index %d contains empty item\n", r);<br>                                    return -1;<br>                            }<br>                             previouskey = currentkey;<br>                             currentkey = strsep(key, nestchar); /* get the next subkey */<br>                         ast_debug(1, "Recursing on index %d in array (key was '%s' and is now '%s')\n", r, previouskey, currentkey);<br>                                /* json2 is a borrowed ref. That's fine, since json won't get freed until recursing is over */<br>                                /* If there are keys remaining, then parse the next object we can get. Otherwise, just dump the child */<br>                              if (parse_node(key, currentkey, nestchar, count, currentkey ? ast_json_object_get(json2, currentkey) : json2, buf, len)) { /* recurse on this node */<br>                                 return -1;<br>                            }<br>                     }<br>                     break;<br>                default:<br>                      ast_debug(1, "Got generic JSON object\n");<br>                  result2 = ast_json_dump_string(jsonval);<br>                      snprintf(buf, len, "%s", result2);<br>                  ast_json_free(result2);<br>       }<br>     return 0;<br>}<br></pre></blockquote></p><p><blockquote style="border-left: 1px solid #aaa; margin: 10px 0; padding: 0 10px;">I think this function can be simplified, made more generic, and then moved into json.c. […]</blockquote></p><p style="white-space: pre-wrap; word-wrap: break-word;">Sorry it took so long to get back to this.<br>I'm wondering, is there a reason that AST_JSON_INTEGER is not handled in your ast_json_find_by_key example? Right now that case is handled in parse_node. It seems like here, it would fall through to the generic ast_json_dump_string, which wouldn't work on an integer value. Or have I missed something here?</p></li></ul></li></ul><p>To view, visit <a href="https://gerrit.asterisk.org/c/asterisk/+/18012">change 18012</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/+/18012"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-Change-Id: I603940b216a3911b498fc6583b18934011ef5d5b </div>
<div style="display:none"> Gerrit-Change-Number: 18012 </div>
<div style="display:none"> Gerrit-PatchSet: 4 </div>
<div style="display:none"> Gerrit-Owner: N A <mail@interlinked.x10host.com> </div>
<div style="display:none"> Gerrit-Reviewer: Friendly Automation </div>
<div style="display:none"> Gerrit-Reviewer: Kevin Harwell <default.enum@gmail.com> </div>
<div style="display:none"> Gerrit-CC: Joshua Colp <jcolp@sangoma.com> </div>
<div style="display:none"> Gerrit-Attention: Kevin Harwell <default.enum@gmail.com> </div>
<div style="display:none"> Gerrit-Comment-Date: Sat, 06 Aug 2022 21:01:34 +0000 </div>
<div style="display:none"> Gerrit-HasComments: Yes </div>
<div style="display:none"> Gerrit-Has-Labels: No </div>
<div style="display:none"> Comment-In-Reply-To: Kevin Harwell <default.enum@gmail.com> </div>
<div style="display:none"> Gerrit-MessageType: comment </div>