Commit Graph

408 Commits

Author SHA1 Message Date
Petri Lehtinen
30a4c88843 Fix an off-by-one error 2013-10-15 08:49:40 +03:00
Petri Lehtinen
08be94e8e6 Don't call strlen twice
Oops.
2013-10-15 08:46:17 +03:00
Petri Lehtinen
d544852ff6 Avoid integer overflows with very long strings 2013-10-15 08:44:04 +03:00
Chip Salzenberg
a76dc45512 paper bag bug: json_string_set* functions should set the length too 2013-10-03 19:07:20 -07:00
Chip Salzenberg
6ebd0bc7a6 fix type mismatch anywhere int != int32 (Vorne) 2013-09-30 16:56:01 -07:00
Petri Lehtinen
1bfc33362e Add JSON_ALLOW_NUL decoding flag for enabling NUL byte support 2013-09-30 10:45:02 +03:00
Petri Lehtinen
4d5aead31c Fix NUL byte check for object keys 2013-09-30 10:45:02 +03:00
Petri Lehtinen
78a80b8899 load.c: Change an error message 2013-09-30 09:24:36 +03:00
Chip Salzenberg
6c1ce27095 add new public functions to jansson.def 2013-09-29 16:57:23 -07:00
Chip Salzenberg
dcaa90d21e dump \u sequences as upper case for readability (just like error messages) 2013-09-27 17:32:25 -07:00
Chip Salzenberg
9c259c07aa Support \u0000 - add size_t string lengths to API, load and dump \u000, etc.
Also:
  Steal strings during parsing for half the mallocs!
  Change all input-caused assertions to errors.  No crashes please, we're programmers.
2013-09-27 17:32:06 -07:00
Petri Lehtinen
641002da37 jansson 2.5 2013-09-19 21:26:46 +03:00
Olivier Langlois
21599b95f8 Replace strcpy with memcpy
Since len is known, the copy function does not need to check byte by byte
the end of the string.

Signed-off-by: Olivier Langlois <olivier@olivierlanglois.net>
2013-08-27 22:47:18 -04:00
Petri Lehtinen
3196ad48ed pack: Add format specifiers s#, + and +# 2013-08-14 21:54:11 +03:00
Petri Lehtinen
2489ea90b1 Update copyrights for 2013 2013-07-23 13:20:06 +03:00
Petri Lehtinen
11d45b0090 Fix integer overflow in jsonp_strdup()
Fixes #129.
2013-07-21 13:00:32 +03:00
Petri Lehtinen
8490e377c0 Make the argument of json_deep_copy() const
Fixes #126.
2013-07-08 12:36:56 +03:00
Joakim Soderberg
6fe231757e BUGFIX: Compilation error with -DNDEBUG defined.
When building a "MinSizeRel" with CMake I get a compilation error in lex_unget_unsave. This is because assertions are turned off using -DNDEBUG:

```
/usr/bin/gcc  -DHAVE_CONFIG_H -fPIC -Os -DNDEBUG -Ijansson/build/include -Ijansson/build/private_include    -Wall -Wextra -Wdeclaration-after-statement -Werror -o CMakeFiles/jansson.dir/src/load.c.o   -c jansson/src/load.c
jansson/src/load.c: In function âx_unget_unsaveâjansson/src/load.c:256:14: error: variable â set but not used [-Werror=unused-but-set-variable]
cc1: all warnings being treated as errors
```

This will then remove the insert, which makes the "d" variable unused, which is treated as an error since we have -Wall set. We can't simply get rid of the variable either and put the strbuffer_pop call in the assert call, since it's a macro and would remove the call entirely. So I simply added a check for NDEBUG to fix it.
2013-06-26 09:50:46 +00:00
Petri Lehtinen
8d439710cd Merge pull request #123 from jjwchoy/decode-ignore-int
Implemented a decode option to only decode numbers to reals
2013-06-11 22:23:40 -07:00
Jason Choy
120a90a155 Using jsonp_strtod instead of casting to double to catch double overflow 2013-06-11 15:09:08 +01:00
Jason Choy
02a3829363 Renamed flag to JSON_DECODE_INT_AS_REAL and added documentation 2013-06-11 12:24:28 +01:00
Jason Choy
9e7f11a847 Implemented a decode option to only decode numbers to reals and never integers 2013-06-09 15:14:47 +01:00
Paul Harris
2fd66fab1a Adjust CMakeLists.txt and .def: add _d postfix onto jansson_d.lib/dll
Had to remove the "LIBRARY" line from jansson.def, which was optional,
and was overriding CMake's desire for a specific name.
2013-06-02 22:00:32 +08:00
Petri Lehtinen
5cc594c9e8 Don't shadow the stdlib function index() with arg names
Fixes #119.
2013-05-21 08:54:27 +03:00
Daniel Griscom
6950cd203b Add json_array_foreach() #define, parallelling json_object_foreach() 2013-05-12 15:03:26 -04:00
Petri Lehtinen
61cba2ae50 Merge branch '2.4' 2013-04-15 08:49:47 +03:00
Petri Lehtinen
867079c820 json_dump*(): Don't crash if json is NULL and JSON_ENCODE_ANY is set 2013-04-15 08:49:09 +03:00
Petri Lehtinen
6281d1c549 Merge pull request #108 from Zillode/1edff47af38a2335f88300ee6dc437118f5a20ff
Fixes redefined warnings ("_GNU_SOURCE")
2013-04-02 05:40:49 -07:00
Lode Hoste
1edff47af3 Do not define _GNU_SOURCE is already defined 2013-03-14 21:34:11 +01:00
Joakim Soderberg
650707fccc Moved *config.h.cmake to the cmake directory. 2013-03-07 18:38:47 +01:00
Joakim Soderberg
e40d52c550 Consolidated the CMake project.
- Moved everything to one CMakeLists.txt
- Added support for the json_process test suites (instead of just the API
  tests).
- Changed to use the modified json_process version that does away with the
  environment variables (originally written by DanielT).
- Had to exclude "test_memory_funcs" on MSVC, since void pointer
  arithmetics are not allowed as it is done in secure_malloc and
  secure_free.
- Had to add a check for "ssize_t". This is not available on Windows and
  maybe on some other platforms (used in test_pack.c)
- Result from running ctest (The failure seems unrelated to CMake, it's
  just that the expected result is in a different order):
99% tests passed, 1 tests failed out of 121

Total Test time (real) =   1.31 sec

The following tests FAILED:
         24 - valid__complex-array (Failed)
2013-03-07 16:11:07 +01:00
Paul Harris
3e03b07831 Add CMake build system.
Added multiple CMake-related files to project.
Supports building the library and the tests.
See CMakeLists.txt for notes on how it works.

I had to adjust 3 existing files in order to disable some configuration
that should be taken care of by cmake/automake anyway.

I also added jansson.def from a future jansson version,
to test cmake's support for .def files (which works fine).
2013-03-07 16:06:01 +01:00
Petri Lehtinen
b9967fdbcf Merge branch '2.4' 2013-02-04 09:52:31 +02:00
Petri Lehtinen
93a3c7f663 Enable gcc specific flags in tests correctly
... and fix issues found.
2013-02-04 09:49:58 +02:00
Petri Lehtinen
40c2e532b9 Merge branch '2.4' 2013-01-03 10:46:46 +02:00
Petri Lehtinen
02beb90db3 Make it possible to forward declare struct json_t
This allows e.g. to use json_t in a header file that doesn't include
jansson.h:

    struct json_t;
    typedef struct json_t json_t;

    json_t *foo(json_t *bar);
2013-01-03 10:45:38 +02:00
Petri Lehtinen
08c5ec8f01 Merge branch '2.4' 2012-12-28 14:11:59 +02:00
Petri Lehtinen
e9cb9dbf60 Fix // -> /* */ 2012-12-28 14:11:43 +02:00
Petri Lehtinen
b98be1f18d Merge branch '2.4' 2012-12-10 08:47:11 +02:00
Jacob Potter
872f847655 Change const pointer to array
Closes #95.
2012-12-10 08:47:00 +02:00
Jacob Potter
f86bb0377f Mark some constant data as const.
Issue #95.
2012-12-10 08:47:00 +02:00
Attie Grande
c82cea9d32 fixed l_isxdigit() macro
Closes #97.
2012-12-10 08:47:00 +02:00
Petri Lehtinen
67c002f7c9 Merge branch '2.4' 2012-12-04 21:23:33 +02:00
Petri Lehtinen
e0a7f81b39 Really fix the off-by-one error in json_array_remove()
It didn't affect only the last element but all of them. One item too
much was always moved.
2012-12-04 21:20:59 +02:00
Petri Lehtinen
7b35a18ac0 Merge branch '2.4' 2012-12-04 09:33:48 +02:00
Petri Lehtinen
54d59c743c Fix an off-by-one error in json_array_remove()
Uninitialized memory was read when the last item of a "full" array was
removed.
2012-12-04 09:32:45 +02:00
Petri Lehtinen
5804e9de9b Set master for 2.5 development mode 2012-09-23 13:41:40 +03:00
Petri Lehtinen
3279aacdee jansson 2.4 2012-09-23 12:52:41 +03:00
Petri Lehtinen
2158670177 Distribute win32 files 2012-09-23 12:52:40 +03:00
Petri Lehtinen
c3fc1d7382 Merge pull request #90 from luke-jr/patch-1
Add -no-undefined to LDFLAGS
2012-09-18 21:11:26 -07:00
Luke Dashjr
c922354076 Add -no-undefined to LDFLAGS
This tells libtool that jansson does not require any external symbols, and allows building it as a shared library (DLL) on Windows.
2012-09-15 08:45:29 +00:00
Petri Lehtinen
4118315afa Disallow NaN or Inf real values 2012-09-13 21:30:19 +03:00
Petri Lehtinen
ee13c667f1 Fix json_real_set() to return -1 on error 2012-09-13 08:46:56 +03:00
Petri Lehtinen
b6a1d8cfd4 Add json_boolean() macro
Mostly for symmetry reasons. Makes it easier e.g. to:

  int ok = 0;
  if(something)
      ok = 1;

  json_object_set_new(obj, "ok", json_boolean(ok));

Fixes #86.
2012-07-30 07:20:37 +03:00
Petri Lehtinen
37bc3bbf4b Tweak slash escaping 2012-06-29 13:25:02 +03:00
Petri Lehtinen
2d46ea069b Merge branch 'fix-slash' of git://github.com/jrbasso/jansson
Fixes #81.
2012-06-29 13:24:55 +03:00
Juan Basso
b217cd6689 Created flag to dump escaping slash 2012-06-28 22:04:36 -04:00
Juan Basso
a0c262d08b Escaping the slash when dump 2012-06-27 23:54:08 -04:00
Rogerz Zhang
a79f64e155 Fix build warnings under MinGW 2012-05-01 08:02:12 +08:00
Rogerz Zhang
7ca783c3bc Add vs2010 solution and project 2012-04-30 21:51:07 +08:00
Petri Lehtinen
ff0c05b8f1 Support building on Windows
Jansson now builds correctly with Visual C++ Express 2010.
2012-04-29 22:09:29 +03:00
Petri Lehtinen
abdb8d99d7 Merge branch '2.3'
Conflicts:
	configure.ac
	doc/conf.py
	src/jansson.h
2012-04-20 21:41:25 +03:00
Petri Lehtinen
ff6e6ee293 jansson 2.3.1 2012-04-20 21:35:00 +03:00
Petri Lehtinen
1581f26a7f Merge branch '2.3'
Closes #70.
2012-04-18 21:27:26 +03:00
Janne Kulmala
aabfd493d3 load: Change buffer_pos to be a size_t
buffer_pos should be type size_t, because it's used to store the
current position in the read buffer. Also, it never can be negative.
2012-04-18 21:21:17 +03:00
Janne Kulmala
bd72efbd80 load: Avoid unexpected behaviour in macro expansion
Macros can be dangerous if the inserted arguments are not properly
parenthesised. As macro expansion does a simple replacement, inserting
a certain expression can cause the evaluation order of the macro expression
to change.
2012-04-18 21:21:17 +03:00
Petri Lehtinen
e8fd3e3085 Document and tweak json_load_callback()
Change the return value of json_load_callback_t to size_t, as it's
feels more correct. The callback should return (size_t)-1 on failure.

Issue #57.
2012-03-26 21:53:21 +03:00
Rogerz Zhang
040bd7b0fa Add json_load_callback() 2012-03-22 14:52:57 +08:00
Petri Lehtinen
d286e7b753 Merge branch '2.3' 2012-03-20 20:56:00 +02:00
Petri Lehtinen
3c6e36ba2d Update copyright notices for 2012 2012-03-20 20:55:55 +02:00
Petri Lehtinen
9af64480e1 Merge branch '2.3' 2012-03-20 20:48:36 +02:00
Petri Lehtinen
4ae5736bd0 Make sure strtoll() is available when using long long 2012-03-20 20:47:57 +02:00
Petri Lehtinen
56039ed596 Merge branch '2.3' 2012-03-11 21:16:41 +02:00
Petri Lehtinen
02b915af54 Remove unused declarations 2012-03-11 21:12:52 +02:00
Petri Lehtinen
a894980258 Set master to 2.4 development mode 2012-01-30 20:59:32 +02:00
Petri Lehtinen
f227483846 jansson 2.3 2012-01-27 21:02:12 +02:00
Petri Lehtinen
6cb14dd337 Add support for optional object keys for json_unpack() and friends
Initial patch by Andrew Thompson.
2012-01-26 21:16:36 +02:00
Petri Lehtinen
fa268b5017 Add json_object_update_{existing,missing}
Closes #37.
2012-01-24 21:03:36 +02:00
Petri Lehtinen
a307974731 Implement json_object_foreach()
Also change many places to use it internally to replace hand-crafted
iteration.

Closes #45, #46.
2012-01-24 21:01:24 +02:00
Petri Lehtinen
a2381948bb Make hashtable less generic
This will make it possible to implement json_object_foreach(). It
should also have some (positive) effect on speed.
2012-01-24 21:01:23 +02:00
Petri Lehtinen
5eb2c442a9 Fix a potential memory leak 2012-01-24 20:35:59 +02:00
Petri Lehtinen
f471e63bb3 Write number of bytes read to error position on successful decode
Closes #49.
2012-01-23 21:18:04 +02:00
Petri Lehtinen
bb24697d9b Merge branch '2.2' 2011-11-14 21:16:42 +02:00
Petri Lehtinen
c4a7bf90cf Revert "json_dump_file: Open the output file in wb mode"
JSON is read as text, so line endings should be preserved.

This reverts commit 32cd821273.
2011-11-14 21:16:36 +02:00
Petri Lehtinen
bef87fc258 Merge branch '2.2'
Closes GH-43.
2011-11-14 21:11:18 +02:00
Andrea Marchesini
1e36667193 JSON_DECODE_ANY
Closes GH-4.
2011-11-14 21:10:09 +02:00
Petri Lehtinen
0f2cdd70ff Avoid problems with object's serial number growing too big
Transform serial key comparison from substraction to real comparison.
Reset serial to zero in json_object_clear() to avoid it growing out of
bounds when reusing objects.

Closes GH-40.
Closes GH-41.
2011-11-14 21:01:13 +02:00
Andrea Marchesini
5ec101ec21 json_load* return NULL if the first argument is NULL 2011-11-14 20:57:41 +02:00
Petri Lehtinen
6799c8e4c9 Distribute jansson_config.h.win32 2011-11-02 07:57:19 +02:00
Petri Lehtinen
8484ea3fb2 Remove '+' and leading zeros from exponents in the encoder
Fixes GH-39.
2011-11-01 20:50:16 +02:00
Petri Lehtinen
bc98ab6a69 Use %I64d format for printing long longs on Windows
Fixes GH-38.
2011-11-01 20:49:28 +02:00
Petri Lehtinen
32cd821273 json_dump_file: Open the output file in wb mode
For maximum compatibility.
2011-10-07 20:52:54 +03:00
Petri Lehtinen
9c6cb42f17 jansson 2.2.1 2011-10-06 21:23:09 +03:00
Petri Lehtinen
6362032513 json_load_file: Open the input file in rb mode
For maximum compatibility.
2011-10-04 21:11:31 +03:00
Petri Lehtinen
f0d5c04734 Make identifier decoding work under all locales
Replace isxxx() functions from ctype.h with locale-independent macros.

Fixes GH-35.
2011-10-03 21:43:16 +03:00
Petri Lehtinen
fd56deb7dd Use strchr() when searching for a single character 2011-10-03 08:52:30 +03:00
Petri Lehtinen
d7ddbf3661 Make real number encoding and decoding work under all locales
The decimal point '.' is changed to locale's decimal point
before/after JSON conversion to make C standard library's
locale-specific string conversion functions work correctly.

All the tests now call setlocale(LC_ALL, "") on startup to use the
locale set in the environment.

Fixes GH-32.
2011-10-02 21:31:17 +03:00
Petri Lehtinen
b6d0191e51 Implement all other encoding functions using json_dump_callback
This way we can check for JSON_ENCODE_ANY flag in one place only.
2011-09-24 21:10:34 +03:00
Andrea Marchesini
909874b1b9 scope error. result points to a out-of-score variable. 2011-09-20 13:10:32 +02:00
Andrea Marchesini
ff57dee13d unsed static variable removed 2011-09-20 11:46:29 +02:00
Petri Lehtinen
889f295958 jansson 2.2 2011-09-02 21:39:40 +03:00
JKL
c7d543d36c new typedef json_dump_callback_t, function json_dump_callback 2011-06-30 21:47:12 +03:00
JKL
cd9757512d use size_t for strbuffer writes, and avoid integer overflow 2011-06-30 20:45:18 +03:00
Petri Lehtinen
c0193bfb7f Check that target is string and value is not NULL in json_string_set() 2011-06-17 21:42:19 +03:00
Petri Lehtinen
86d17a8dc2 jansson 2.1 2011-06-10 21:30:11 +03:00
Petri Lehtinen
a76ba52f34 Add JSON_DISABLE_EOF_CHECK decoding flag
With this flag enabled, the decoder stops after a valid JSON input and
thus allows extra data after it.

Fixes GH-25.
2011-05-29 21:27:15 +03:00
Petri Lehtinen
9febdf333c Reduce code duplication in the decoder 2011-05-29 12:53:25 +03:00
Petri Lehtinen
013b8b3f60 Clear errno before calling strtod()
Fixes GH-27.
2011-05-24 09:59:41 +03:00
Petri Lehtinen
49fc708d4c Add JSON_REJECT_DUPLICATES decoding flag
With this flag, a decoding error is issued if any JSON object in the
input contains duplicate keys.

Fixes GH-3.
2011-05-15 13:57:49 +03:00
Petri Lehtinen
636d5f60f9 Add JSON_ENCODE_ANY flag to allow encoding any JSON value
Closes GH-19.
2011-05-14 12:57:12 +03:00
Petri Lehtinen
c3492973e1 Merge branch '2.0' 2011-04-21 13:15:58 +03:00
Petri Lehtinen
e20619e071 Fix a leak when memory allocation fails in json_object_set() & friends 2011-04-21 13:15:22 +03:00
Petri Lehtinen
b44e2be032 Add json_loadb() for decoding possibly non null-terminated strings
Thanks to Jonathan Landis for the initial patch.
2011-04-10 21:01:50 +03:00
Petri Lehtinen
4a76900bd7 Merge branch '2.0'
Conflicts:
	doc/conf.py
	src/jansson.h
2011-03-31 21:26:19 +03:00
Petri Lehtinen
1c0a3b2a55 jansson 2.0.1 2011-03-31 16:59:26 +03:00
Petri Lehtinen
056702e541 Merge branch '2.0' 2011-03-31 16:39:33 +03:00
Petri Lehtinen
eab23f05d8 Fix a few malloc() and free() calls
Replace them with jsonp_malloc() and jsonp_free() to support the
custom memory allocation.
2011-03-31 16:37:43 +03:00
Petri Lehtinen
0944ac8d91 Fix invalid object key hashing in json_unpack() strict checking mode
The keys which are stored temporarily to a hashtable to make sure that
all object keys are unpacked, were hashed with the object key hashing
function. It is meant to compute hashes for object_key_t values, and
it works incorrectly for plain strings.

Fixed by introducing suitable functions for hashing and comparing
strings for string-keyed hashtables.
2011-03-30 12:57:48 +03:00
Petri Lehtinen
5456fc59ab Set JANSSON_MICRO_VERSION to 255 (0xFF) for git master
Also, set documentation release to "2.0+git". This shows up in the
automatically built HTML documentation.

These changes makes it easier for library users to know that this
version is under development.

Closes GH-14.
2011-03-27 21:03:04 +03:00
Petri Lehtinen
279d8bf108 Use the correct number of parens in JANSSON_VERSION_HEX macro 2011-03-27 14:12:40 +03:00
Petri Lehtinen
af18578928 Use the correct number of parens in JANSSON_VERSION_HEX macro 2011-03-23 08:25:50 +02:00
Petri Lehtinen
c30e92603c ANSI C requires struct initializers to be constant expressions
Closes GH-17.
2011-03-21 09:28:14 +02:00
Petri Lehtinen
6ecba84817 Fix json_object_size() return value
Return 0 as documented if the argument is not a JSON object.

Closes GH-18.
2011-03-21 08:22:34 +02:00
Petri Lehtinen
b90ed1accb Enhance portability of va_copy()
va_copy() is a C99 feature. In C89 implementations, it's sometimes
available as __va_copy(). If not, memcpy() should do the trick.
2011-03-20 21:23:37 +02:00
Petri Lehtinen
1111960120 Fix a declaration after statement
While at it, add -Wdeclaration-after-statement to AM_CFLAGS to catch
these in the future.
2011-03-10 21:28:53 +02:00
Petri Lehtinen
cf9b384bcb jansson 2.0 2011-02-28 20:46:14 +02:00
Petri Lehtinen
42b651ef56 Fix packing of invalid UTF-8 strings 2011-02-27 21:34:12 +02:00
Petri Lehtinen
58f9d65535 Add lots of tests for pack/unpack code, fix bugs found
Closes GH-12.
2011-02-22 19:08:51 +02:00
Petri Lehtinen
50dc64a7af Truncate error source from start, not end, if it's too long to fit
It's more helpful to see "...bar/baz.json" instead of "/long/path/to".
2011-02-22 13:34:37 +02:00
Petri Lehtinen
5df7b79397 Refactor decoder input stream
- Add a new field position to the json_error_t structure. This is the
  position in bytes from the beginning of the input.

- Keep track of line, column and input position in the stream level.
  Previously, only line was tracked, and it was in the lexer level, so
  this info was not available for UTF-8 decoding errors.

- While at it, refactor tests so that no separate "stripped" tests are
  required. json_process is now able to strip whitespace from its
  input, and the "valid" and "invalid" test suites now use this to
  test both non-stripped and stripped input.

Closes GH-9.
2011-02-22 12:07:37 +02:00
Petri Lehtinen
4be9e9e7fe Add custom memory allocation
Thanks to Basile Starynkevitch for the suggestion and initial patch.
Thanks to Jonathan Landis and Deron Meranda for showing how this can
be utilized for implementing secure memory operations.
2011-02-17 10:10:53 +02:00
Graeme Smecher
dd7dd414f0 Resolve __va_list_tag ** -> va_list * type errors with clang and future GCCs
Functions taking va_args are munged to receive arguments of type
'__va_list_tag *'. This patch uses va_copy to coerce them to the expected type
so we don't get compiler errors.

Tested on x86_64, both 32-bit and 64-bit compiles.

Reported-By: Basile Starynkevitch <basile@starynkevitch.net>
2011-02-03 20:41:54 +02:00
Petri Lehtinen
ef13fb9189 Tweak the default validation behaviour of the unpack API
Now, by default, unpacking doesn't check that all array and object
items are accessed. The check can be enabled globally by using the
JSON_STRICT flag (formerly JSON_UNPACK_ONLY), or on a per-value basis
by using the new '!' format character. The '*' format character is
still available to disable the global check on a per-value basis.
2011-01-29 21:38:07 +02:00
Petri Lehtinen
908c62f327 Add the 'I' format for both pack and unpack 2011-01-25 21:41:35 +02:00
Petri Lehtinen
a1c185a376 Use 'f' for real and 'F' for number (real or integer) in unpack 2011-01-25 20:42:41 +02:00
Petri Lehtinen
ac96ac13d4 unpack: Unify and enhance error messages
Give the type name instead of its enum index in the error message when
an unexpected value is encountered while unpacking.
2011-01-25 20:37:53 +02:00
Petri Lehtinen
579c291882 Expand the pack/unpack API, implement unpack flags
Expand the pack/unpack API: json_(un)pack is the simple version with
no error output, json_(un)pack_ex has error output and flags,
json_v(un)pack_ex is a va_list version of json_(un)pack_ex.

Implement unpacking flags:

- JSON_UNPACK_ONLY turns off extra validation, i.e. array and object
  unpacking doesn't check that all items are unpacked. This is really
  just convenience for not adding '*' after each object and array.

- JSON_VALIDATE_ONLY turns off unpacking, i.e. no varargs are expected
  and nothing is unpacked.
2011-01-25 10:02:27 +02:00
Petri Lehtinen
2770dca2c0 Add validation features to json_unpack()
* By default, json_unpack() now checks that all items of arrays and
  objects are unpacked. This is useful for validation.

* Add format specifier '*' to suppress this check for individual
  arrays and objects. '*' must appear as the last format specifier
  before the closing ']' or '}'.
2011-01-25 08:53:55 +02:00
Petri Lehtinen
6825c2c706 Rename variadic.c to pack_unpack.c 2011-01-25 08:53:55 +02:00
Petri Lehtinen
6d1f28f050 Refactor json_unpack()
* Use the format string scanner from the previous commit (with the
  simpler separator skipping semantics)

* Split json_vnunpack() to three separate functions for unpacking
  objects, arrays and "simple" values

* Always return 0 on success, 1 on error

This shaves around 100 more lines from the original implementation.
2011-01-25 08:53:54 +02:00
Petri Lehtinen
7f3018a4fb Refactor json_pack()
* Implement a "scanner" that reads the format string, maintaining state

* Split json_vnpack() to three separate functions for packing objects,
  arrays and simple values. This makes it more clear what is being
  packed, and the object and array structures become more evident.

* Make the skipping of ignored character simpler, i.e. skip ':' and
  ',' independent of their context

This patch shaves around 80 lines of code from the original
implementation.
2011-01-24 21:26:23 +02:00
Petri Lehtinen
53383860e8 Unify style 2011-01-24 21:14:55 +02:00
Petri Lehtinen
fa7c2ea070 Update copyright notices for 2011 2011-01-22 13:43:14 +02:00
Petri Lehtinen
46f91797ec Build cleanly with gcc's -Werror=declaration-after-statement flag 2011-01-17 15:51:40 +02:00
Graeme Smecher
a242381024 Remove debugging printf 2011-01-15 12:45:08 +02:00
Graeme Smecher
3a7512d2b0 Make json_pack/json_unpack() recursive
Note that we pass va_list pointers around instead of just va_lists, which
would seem more intuitive. This is necessary since the behaviour of va_lists
passed as function parameters is finicky. Quoth stdarg(3):

	If ap is passed to a function that uses va_arg(ap,type) then the value
	of ap is undefined after the return of that function.

The pointer-passing strategy is used by Python's Py_BuildValue() for the same
purpose.
2011-01-14 21:43:48 +02:00
Petri Lehtinen
c7611e7a0d Make int32_t available when the configure script is not used 2010-12-18 23:02:54 +02:00
Petri Lehtinen
23bc8e468d Add version info to jansson.h 2010-12-14 20:58:40 +02:00
Petri Lehtinen
5422a862de Enhance error reporting
This patch adds two new fields to the json_error_t struct: column and
source. It also adds functions to populate json_error_t internally.

The column field is not currently used, but it will be utilized in the
decoder and pack/unpack functions.
2010-10-27 21:58:20 +03:00
Petri Lehtinen
bb5d4efb2e Make json_error_t transparent again
After looking at the new code for a few days, I didn't like it
anymore. To prepare for the future, a few fields will be added to the
json_error_t struct later.

This reverts commit 23dd078c8d. Some
adjustments were needed because of newer commits.
2010-10-26 21:20:34 +03:00