Commit Graph

353 Commits

Author SHA1 Message Date
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
269e86b725 Emphasize the constness of the return value of json_string_value()
Closes GH-7.
2010-12-20 21:08:11 +02:00
Petri Lehtinen
bf32f6cd75 Document the version info constants 2010-12-19 21:55:00 +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
818baf5fdb Move and enhance documentation on json_error_t 2010-10-26 21:20:34 +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
Graeme Smecher
198d537be7 Adds json_pack / json_unpack variadic functions. 2010-10-26 08:59:06 +03:00
Petri Lehtinen
1acd1a7b56 Remove all "Added in version 1.x" info from documentation
As 2.0 will be backwards incompatible anyway, there's no need to
record which features were new in which 1.x releases.
2010-10-14 21:05:22 +03:00
Petri Lehtinen
23dd078c8d Make json_error_t opaque
All decoding functions now accept a json_error_t** parameter and set
it to point to a heap-allocated json_error_t structure if an error
occurs. The contents of json_error_t are no longer exposed directly, a
few functions to do it have been added instead. If an error occurs,
the user must free the json_error_t value.

This makes it possible to enhance the error reporting facilities in
the future without breaking ABI compatibility with older versions.

This is a backwards incompatible change.
2010-10-14 21:02:37 +03:00
Petri Lehtinen
781bda1404 Merge branch '1.3' 2010-09-06 20:48:25 +03:00
Petri Lehtinen
3d5c0f46f1 Run Sphinx without the -W flag when building documentation
In "make html", don't use the -W flag with Sphinx. This makes it
possible to create the documentation with Sphinx 1.0 without errors,
as the warning about using old-style C markup isn't turned to an
error.

Don't build documentation in "make check". Instead, add a new make
target "check-doc" to build the documentation with the -W flag.
2010-09-06 20:46:15 +03:00
Petri Lehtinen
8567816542 Use Sphinx 1.0, change the HTML theme 2010-09-05 22:00:47 +03:00
Petri Lehtinen
664c88ca97 Add a section describing how to build on Windows 2010-09-05 21:38:06 +03:00
Petri Lehtinen
cbb3855d97 On Windows, typedef int to int32_t
There's no inttypes.h or stdint.h in the stdlib on Windows.
2010-09-05 21:30:02 +03:00
Petri Lehtinen
3c4cf31a01 Add jansson_config.h.win32
As the configure script cannot be run on Windows, give the users a
jansson_config.h that they can use directly.
2010-09-05 21:21:37 +03:00
Petri Lehtinen
06eb436008 Move max() to jansson_private.h, define only if not already defined
On some platforms (Visual C++ for one) the standard library already
defines max() as a macro.
2010-09-05 21:18:46 +03:00
Petri Lehtinen
e3654c2245 Don't use designated struct initializers
It's a C99 feature and not available on all compilers (Visual C++, for
example).
2010-09-05 21:18:46 +03:00
Petri Lehtinen
a112563214 Use config.h only if it exists
This makes it easier to compile without the configure script (e.g. on
Windows).
2010-09-05 21:18:46 +03:00
Petri Lehtinen
976fc2279f Replace all occurences of inline with JSON_INLINE
This makes it easier to compile without the configure script (e.g. on
Windows).
2010-09-05 21:18:46 +03:00
Petri Lehtinen
56643d4311 Merge branch '1.3'
Conflicts:
	doc/apiref.rst
	src/jansson_private.h
2010-08-14 21:02:08 +03:00
Petri Lehtinen
cb8fcc7808 Set the version number to 2.0pre 2010-08-14 20:47:08 +03:00
Petri Lehtinen
b76c69de1b Clarify and document the integer type configuration 2010-08-14 20:42:15 +03:00
Petri Lehtinen
bfac1972e2 Add a flags parameter to all decoding functions for future needs
As of now, the parameter is unused, but may be needed in the future.
I'm adding it now so that in the future both API and ABI remain
backwards compatible as long as possible.

This is a backwards incompatible change.
2010-08-14 17:28:09 +03:00
Petri Lehtinen
f8d0e01e46 Change the maximum indentation size to 32 spaces in encoder
This is to free up bits from the flags parameter of json_dump
functions. I'm pretty sure no-one needs 256 spaces of indentation when
pretty-printing JSON values...

This is a backwards incompatible change.
2010-08-13 22:12:36 +03:00
Petri Lehtinen
ffbab6fedd Change the underlying type of JSON integer from long to json_int_t
json_int_t is typedef'd to long long if it's supported, or long
otherwise. There's also some supporting things, like the
JSON_INTEGER_FORMAT macro that expands to the printf() conversion
specifier that corresponds to json_int_t's actual type.

This is a backwards incompatible change.
2010-08-13 22:07:20 +03:00
Petri Lehtinen
145032a57f Make object_key_t portable
A flexible array member is unportable. Use a table of length 1
instead. This needs some adjustment to the memory allocatio, too.
2010-08-12 21:35:23 +03:00
Petri Lehtinen
519d52e2bb Beautify the container_of macro
Use offsetof instead of zero pointer dereference trickery.
2010-08-12 21:34:51 +03:00
Petri Lehtinen
94182a5acc Replace inline with JSON_INLINE in json_object_iter_set() declaration 2010-08-12 21:10:12 +03:00
Petri Lehtinen
f71eb7fe17 Check for gcc before setting gcc specific CFLAGS 2010-08-12 21:00:09 +03:00
Petri Lehtinen
7ce70533c9 Move site configuration to jansson_config.h
This way, more site configuration can be more easily added later.
2010-08-10 22:16:55 +03:00
Petri Lehtinen
014c49c285 Change JSON integer's underlying type from int to long
This is a backwards incompatible change.
2010-08-10 21:45:18 +03:00
Petri Lehtinen
6e3ca5c45c Clarify the documentation
Couple some string and number information from the RFC conformance
chapter in the API reference, and refer to the RFC conformance chapter
from API reference for more information.

Also, state more clearly that a JSON text must have an array or object
as the top-level value, and better document the string comparison
performed by json_equal().
2010-06-16 21:34:10 +03:00
Petri Lehtinen
68f2861e92 Unify unsigned integer usage in the API
Replace all occurences of unsigned int and unsigned long with size_t.

This is a backwards incompatible change, as the signature of many API
functions changes.
2010-06-15 15:38:59 +03:00
Petri Lehtinen
b354f8a35a configure.ac: Remove unneeded AC_PROG_CXX 2010-06-14 22:30:15 +03:00
Petri Lehtinen
b461c652b4 Add a few missing changes to CHANGES for v1.3
These were forgotten when releasing.
2010-06-14 14:35:38 +03:00
Petri Lehtinen
2caac965d4 jansson 1.3 2010-06-13 20:37:33 +03:00
Petri Lehtinen
1347686dbf Remove the C++ interface 2010-06-12 22:45:49 +03:00