1. 05 10月, 2016 1 次提交
    • J
      util: Introduce virJSONValueObjectStealArray · ebf8b783
      John Ferlan 提交于
      Provide the Steal API for any code paths that will desire to grab the
      object array and then free it afterwards rather than relying to freeing
      the whole chain from the reply.
      ebf8b783
  2. 27 7月, 2016 2 次提交
  3. 05 5月, 2016 1 次提交
  4. 09 10月, 2015 1 次提交
    • M
      virJSONValueArraySize: return ssize_t · 4f77c48c
      Michal Privoznik 提交于
      The internal representation of a JSON array counts the items in
      size_t. However, for some reason, when asking for the count it's
      reported as int. Firstly, we need the function to return a signed
      type as it's returning -1 on an error. But, not every system has
      integer the same size as size_t. Therefore, lets return ssize_t.
      Signed-off-by: NMichal Privoznik <mprivozn@redhat.com>
      4f77c48c
  5. 25 6月, 2015 5 次提交
    • E
      json: enhance parser test · cb005533
      Eric Blake 提交于
      We already enable the parser option to detect invalid UTF-8, but
      didn't test it.  Also, JSON states that behavior of an object
      with a duplicated key is undefined; we chose to reject it, but
      were not testing it.
      
      With the enhanced tests in place, we can simplify yajl2
      initialization by relying on parser defaults being sane.
      
      * src/util/virjson.c (virJSONValueFromString): Simplify.
      * tests/jsontest.c (mymain): Test more bad usage.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      cb005533
    • E
      json: even stricter trailing garbage detection · 7e191fd9
      Eric Blake 提交于
      Since older yajl ignores trailing garbage, a client can cause
      problems by intentionally ending the wrapper array early. Since
      we already track nesting, it's not too much harder to reject
      invalid nesting pops.
      
      * src/util/virjson. (_virJSONParser): Add field.
      (virJSONValueFromString): Set witness.
      (virJSONParserHandleEndArray): Use it to catch abuse.
      * tests/jsontest.c (mymain): Test it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      7e191fd9
    • E
      json: reject trailing garbage · 7cd991b7
      Eric Blake 提交于
      Yajl 2 has a nice feature that it can be configured whether to
      allow multiple JSON objects parsed from a single stream, defaulting
      to off.  And yajl 1.0.12 at least provided a way to tell if all
      input bytes were parsed, or if trailing bytes remained after a
      valid JSON object was parsed.  But we target RHEL 6 yajl 1.0.7,
      which has neither of these.  So fake it by always parsing '[...]'
      instead, so that trailing garbage either trips up the array parse,
      or is easily detected when unwrapping the result.
      
      * src/util/virjson.c (virJSONValueFromString): With older json,
      wrap text to avoid trailing garbage.
      * tests/jsontest.c (mymain): Add tests for this.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      7cd991b7
    • E
      json: reject javascript comments · 54dbba5b
      Eric Blake 提交于
      We have been allowing javascript style comments in JSON ever
      since commit 9428f2ce (v0.7.5), but qemu doesn't send them, and
      they are not strict JSON.  Reject them for now; if we can later
      prove that it is worthwhile, we can reinstate it at that point
      (or even make it conditional, by adding a bool parameter to
      the libvirt entry point).
      
      * src/util/virjson.c (virJSONValueFromString): Don't enable
      comment parsing.
      * tests/jsontest.c (mymain): Test it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      54dbba5b
    • E
      json: cope with older yajl semantics · f2acaebd
      Eric Blake 提交于
      Commit ceb496e5 fails on RHEL 6, with yajl 1.0.7, because that
      version of yajl returns yajl_status_insufficient_data when the
      parser is waiting for the rest of a token (this enum value was
      dropped in yajl 2, so we have to wrap it).  It also exposes a
      problem where older yajl silently ignores trailing garbage after
      a successful parse, so this patch works around that by changing
      the testsuite.  Another more invasive patch can add tighter
      semantics to json parsing, but this is sufficient for a minimal
      clean backport.
      
      While touching this, fix up our error message cleanup. Yajl
      documents that error messages produced by yajl_get_error()
      MUST be cleaned with yajl_free_error(); this is certainly
      true if we were to pass non-NULL allocator callbacks during
      yajl_alloc(), but probably harmless in our usage of passing
      NULL.  But better safe than sorry.
      
      * src/util/virjson.c (virJSONValueFromString): Allow different
      error code.  Use canonical cleanup of error message.
      (VIR_YAJL_STATUS_OK): New helper macro.
      * tests/jsontest.c (mymain): Wrap text to avoid difference in
      trailing garbage handling
      Signed-off-by: NEric Blake <eblake@redhat.com>
      f2acaebd
  6. 23 6月, 2015 2 次提交
    • E
      json: make it easier to type-check when getting from object · 58fd6703
      Eric Blake 提交于
      While working in qemu_monitor_json, I repeatedly found myself
      getting a value then checking if it was an object.  Add some
      wrappers to make this task easier.
      
      * src/util/virjson.c (virJSONValueObjectGetByType)
      (virJSONValueObjectGetObject, virJSONValueObjectGetArray): New
      functions.
      (virJSONValueObjectGetString, virJSONValueObjectGetNumberInt)
      (virJSONValueObjectGetNumberUint)
      (virJSONValueObjectGetNumberLong)
      (virJSONValueObjectGetNumberUlong)
      (virJSONValueObjectGetNumberDouble)
      (virJSONValueObjectGetBoolean): Simplify.
      (virJSONValueIsNull): Change return type.
      * src/util/virjson.h: Reflect changes.
      * src/libvirt_private.syms (virjson.h): Export them.
      * tests/jsontest.c (testJSONLookup): New test.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      58fd6703
    • E
      json: fully parse input string · ceb496e5
      Eric Blake 提交于
      I was adding a JSON test, and was shocked to find out our parser
      treated the input string of "1" as invalid JSON.  It turns out
      that YAJL specifically documents that it buffers input, and that
      if the last input read could be a prefix to a longer token, then
      you have to explicitly tell the parser that the buffer has ended
      before that token will be processed.
      
      It doesn't help that yajl 2 renamed the function from what it was
      in yajl 1.
      
      * src/util/virjson.c (virJSONValueFromString): Complete parse, in
      case buffer ends in possible token prefix.
      * tests/jsontest.c (mymain): Expose the problem.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      ceb496e5
  7. 11 6月, 2015 1 次提交
  8. 31 1月, 2015 3 次提交
  9. 23 1月, 2015 1 次提交
  10. 15 10月, 2014 3 次提交
  11. 17 6月, 2014 2 次提交
  12. 25 3月, 2014 1 次提交
  13. 18 3月, 2014 1 次提交
  14. 10 3月, 2014 1 次提交
  15. 20 11月, 2013 2 次提交
  16. 26 9月, 2013 2 次提交
  17. 11 7月, 2013 1 次提交
  18. 24 5月, 2013 1 次提交
  19. 21 5月, 2013 1 次提交
  20. 14 5月, 2013 1 次提交
    • E
      json: support removing a value from an object · 547a7c77
      Eric Blake 提交于
      In an upcoming patch, I need the way to safely transfer a nested
      virJSON object out of its parent container for independent use,
      even after the parent is freed.
      
      * src/util/virjson.h (virJSONValueObjectRemoveKey): New function.
      (_virJSONObject, _virJSONArray): Use correct type.
      * src/util/virjson.c (virJSONValueObjectRemoveKey): Implement it.
      * src/libvirt_private.syms (virjson.h): Export it.
      * tests/jsontest.c (mymain): Test it.
      Signed-off-by: NEric Blake <eblake@redhat.com>
      547a7c77
  21. 02 5月, 2013 1 次提交
    • M
      virutil: Move string related functions to virstring.c · 7c9a2d88
      Michal Privoznik 提交于
      The source code base needs to be adapted as well. Some files
      include virutil.h just for the string related functions (here,
      the include is substituted to match the new file), some include
      virutil.h without any need (here, the include is removed), and
      some require both.
      7c9a2d88
  22. 11 1月, 2013 1 次提交
  23. 21 12月, 2012 5 次提交