summaryrefslogtreecommitdiff
path: root/json-glib/json-parser.c
Commit message (Collapse)AuthorAgeFilesLines
* parser: Detect missing commas in arraysEmmanuele Bassi2016-02-251-1/+14
| | | | | Just like we detect trailing commas, we should also detect missing ones to avoid parsing invalid JSON successfully.
* parser: Correctly increment the array index counterEmmanuele Bassi2016-02-251-1/+2
| | | | | We pass the counter to the JsonParser::array-element signal, but we never really increment it.
* Drop unnecessary '_' prefix from json_marshalEmmanuele Bassi2014-12-301-9/+9
| | | | | It's not public API anyway, and we use annotations instead of the '_' prefix.
* json-parser: use length parameter when validating utf-8djcb2014-04-171-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=727755
* parser: Use the right length for parsing the stream contentsEmmanuele Bassi2014-04-171-2/+2
| | | | | | | The ByteArray we use to buffer the contents of a stream in order to pass them to the parser may have a bigger length. We should use the cursor position that we use to put a '\0' in the buffer instead. We could also use -1, but this saves us a strlen() later on.
* Remove conditional inclusion of config.hEmmanuele Bassi2014-03-181-2/+0
| | | | All the platforms and build system we support have a config.h header.
* parser: Always perform UTF-8 validationEmmanuele Bassi2013-10-271-0/+9
| | | | | | JSON is defined to be encoded using UTF-8, so we should not rely on the documentation saying so when parsing, but validate the input and eventually provide a recoverable parsing error.
* parser: Always use a valid GError internallyEmmanuele Bassi2013-10-261-2/+15
| | | | | Do not just pass the GError through from the public-facing arguments: we may want to perform error checking internally at any later date.
* parser: Drop a pointless macroEmmanuele Bassi2013-08-221-4/+2
| | | | | The JSON_PARSER_GET_PRIVATE macro is pointless, now that we use the new version of GLib.
* Remove compile time GLib version checkEmmanuele Bassi2013-08-211-13/+1
| | | | | We depend on a new version of GLib, so we can remove a bunch of old version checks.
* Use new macros when compiling against new GLibEmmanuele Bassi2013-07-201-1/+11
| | | | | | | | If we're being compiled against a newer version of GLib, we should use the new macros that add instance private data. Since this is a stable branch, we cannot bump the GLib requirement; so we use version checks to conditionally compile the new code.
* Use G_DEFINE_QUARK macroEmmanuele Bassi2013-05-161-7/+3
| | | | Instead of hand-writing the error domain function ourselves.
* Use typed initializers for JsonNodeEmmanuele Bassi2012-10-271-16/+21
|
* scanner: Remove unused functionsEmmanuele Bassi2012-10-261-29/+23
| | | | | | | | JsonScanner is an internal, modified copy of GScanner; we don't need a bunch of the provided functions, as the type and its related API are meant for internal use only. Fewer functions == better coverage == less code to maintain.
* parser: Empty member names are not validEmmanuele Bassi2012-10-261-0/+13
| | | | | When parsing a JSON object, a member name has to be a valid string, not an empty one.
* parser: Use error codes for invalid assignmentsEmmanuele Bassi2012-10-251-1/+3
| | | | | In case we're parsing an assignment we should use the 'invalid bareword' error code.
* parser: Consolidate value parsingEmmanuele Bassi2012-10-251-25/+12
| | | | | | | Instead of doing a preliminary check when parsing arrays and objects, we should just call json_parse_value() and let it handle all the valid values and eventual error cases. This simplifies error handling and makes it more reliable.
* parser: Show the column in the error messageEmmanuele Bassi2012-10-251-2/+3
| | | | | For JSON parsed from data (which tends to be in a single line) the column holds more information than the line.
* parser: Fix small leak in json_parse_statementMiguel Angel Cabrera Moya2012-10-251-1/+4
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=686096
* Mark GError messages for translationsEmmanuele Bassi2011-06-011-1/+4
| | | | These errors might find their way into a UI.
* Add i18n machineryEmmanuele Bassi2011-06-011-0/+2
| | | | We need to translate the GError messages.
* Add missing introspection annotations.Luca Bruno2011-01-101-1/+1
| | | | https://bugzilla.gnome.org/show_bug.cgi?id=638932
* parser: Add loading from a GInputStreamEmmanuele Bassi2010-08-021-0/+258
| | | | | JsonParser should be able to use a GInputStream (both synchronously and asynchronously) to retrieve the JSON data and parse it.
* parser: Do not access GScanner:tokenEmmanuele Bassi2010-05-261-3/+6
| | | | | | | | | The GScanner:token member is declared as GTokenType instead of being an unsigned int. This means that comparing it to any other enumeration is going to generate a warning in GCC >= 4.5. Unfortunately, extending the GTokenType enumeration is the idiomatic way of handling new tokens. EPIC. FAIL.
* docs: Fix typoEmmanuele Bassi2010-04-141-1/+1
| | | | There is no such thing as a 'JsonArrary' type.
* parser: Do not increment the index variableEmmanuele Bassi2010-04-031-1/+1
| | | | | | | | When parsing an array with a JsonParser with the debugging notes enabled, we get an erroneous increment of the idx variable - which is then passed to the JsonParser::array-element signal. Thanks to: Michael Stapelberg <michael@stapelberg.de>
* parser: Add MISSING_COLON errorEmmanuele Bassi2010-03-191-2/+1
| | | | | | We identify a missing ':' separator between an object member name and its value, so it would be a good thing to actually have an error code for that.
* parser: Refactor the JsonParser logicEmmanuele Bassi2010-03-191-288/+200
| | | | | | | | | | | | | | | | | | The array and object parsing logic in JsonParser has clearly exploded beyond control: a simple tightening of the JSON validation almost broke the parser in two. It it is time to... <cue Christopher Lee voice-over> REFACTOR THE CODE! </cue Christopher Lee voice-over> This time, we should be following the JSON state machine and try to do more prediction of the next state based on peeking the next token. The code is fairly cleaner, now; and, most of all, still passes the validation test suite - which is, you know... nice.
* parser: Return specific error codesEmmanuele Bassi2010-03-191-10/+39
| | | | | | | | | The JsonScanner error reporting mechanism, which is basically GScanner's, sucks beyond belief. In order to report an error code we need to store it inside the JsonParser private structure and then use it when creating the GError inside the error handler. This, frankly, is quite stupid.
* parser: Re-use json_parse_value()Emmanuele Bassi2010-03-181-55/+2
| | | | | | The main switch inside json_parse_statement() is re-implementing the bare value parsing that is also provided by json_parse_value(). We should kill it off to avoid redundant code.
* parser: Add debug annotations for json_parse_value()Emmanuele Bassi2010-03-181-0/+8
| | | | Print out the values we are parsing, for debug purposes.
* parser: Clean up array and object parsingEmmanuele Bassi2010-03-181-20/+24
| | | | | | We are doing some of the work twice, especially when dealing with the trailing commas detection and the unknown tokens after an array element or an object member definition.
* parser: Improve strictnessEmmanuele Bassi2010-03-011-39/+78
| | | | | | Apparently, some breakage crept in JsonParser which allowed invalid JSON to actually pass. For instance: trailing and missing commas, invalid barewords and wrong array and object closing braces.
* Update Introspection annotationsEmmanuele Bassi2009-11-121-2/+3
| | | | | | | • Fix the transfer rules for JsonNode, JsonObject and JsonArray getters. • Annotate the methods returning lists
* parser: Advance when parsing bare valuesEmmanuele Bassi2009-10-291-0/+1
| | | | | A missing get_next_token() prevents getting the contents of the tokenizer in order to place them into the JsonNode.
* [parser] Return the right expected tokenEmmanuele Bassi2009-09-221-2/+14
| | | | | | When parsing a value embedded in a Json Object or Array we need to return the right expected token so that the generated syntax error will be correct.
* [parser] Whitespace clean upEmmanuele Bassi2009-09-221-5/+6
|
* [node] Add JsonNode.set_parent()Emmanuele Bassi2009-09-061-7/+7
| | | | | Add the setter for JsonNode:parent, to be used in JsonParser instead of directly accessing the JsonNode structure.
* [parser] Clean up value parsingEmmanuele Bassi2009-09-061-118/+81
| | | | | The code that parses a value within an object and an array should be moved to its own function to avoid duplication.
* [docs] Small documentation fixesEmmanuele Bassi2009-09-021-1/+2
| | | | Clean up some notes, and add introspection annotations where needed.
* Actually use the int64 support in the ScannerEmmanuele Bassi2009-08-121-6/+6
| | | | | | | | We switched everything to 64 bit integers but then I forgot to enable the support for actually making the tokenizer store the parsed integers into a 64 bit value. Bad Emmanuele, no cookie for you.
* [parser] Advance the tokenizer to avoid an infinite loopEmmanuele Bassi2009-06-281-5/+11
| | | | | | | | The tokenizer is not advanced when we peek a base value and return. This causes an endless loop which terminates only if the OOM killer in the kernel gets the right process. Thanks to Thomas Weidner for catching and reporting the issue.
* Fix license and copyright noticesEmmanuele Bassi2009-06-091-2/+6
| | | | | | | | THere is no such thing as the "Lesser General Public License version 2": the LGPL v2 is the "Library GPL", and has been superceded by v2.1 with the new "Lesser GPL" name. Also, the copyright is now Intel Corp.
* [node] Make JsonNode completely privateEmmanuele Bassi2009-06-091-0/+2
| | | | | | | | | | The JsonNode structure has always been meant to be completely opaque; we indirectly exposed the :type member, but only for access through the JSON_NODE_TYPE() macro. Since that macro has become a proxy for the json_node_get_node_type() function we can safely move everything into a private, uninstalled header file and let JsonNode be completely opaque to the developer.
* Update after the json_object_add_member() deprecationEmmanuele Bassi2009-04-171-3/+3
| | | | | | | Since json_object_add_member() has been deprecated and it's using a gcc compiler attribute to loudly complain while compiling the library, we should restore the sanity and use json_object_set_member() instead.
* [parser] Prevent leaks on error codepathsEmmanuele Bassi2009-04-131-5/+33
| | | | | | | Static analysis of the code showed some potential leaks inside error paths for JsonParser. Thanks to: Gordon Williams <gordon.williams@collabora.co.uk>
* [docs] Show an example of assignmentEmmanuele Bassi2009-04-131-5/+12
| | | | | Since I decided to rant about assignments in JSON definitions, I also need to show what an assignment looks like.
* Whitespace fixesEmmanuele Bassi2009-04-131-6/+12
| | | | Add more spaces and remove the ` from the error message.
* Abstract the loading code into its own functionerror-locationEmmanuele Bassi2008-11-281-72/+103
| | | | | | | | | | | | | | | | | | The load_from_file() method must set the is_filename/filename fields of the JsonParserPrivate structure, so that the error handler can use them to print out the file, as well as the line in case of error. Since load_from_data() needs to unset those two fields, to avoid printing invalid/stale information, we need to have a generic "load" function that can be invoked by both load_from_data() and load_from_file(), and leave the JsonParser object set up to those two methods. Hence, a private json_parser_load() has been added, moving most of the code out of json_parser_load_from_data(). This function does not perform type checks and requires that the length of the memory buffer containing the JSON data stream is already a positive integer.
* Display the filename inside error messagesEmmanuele Bassi2008-11-281-2/+26
| | | | | | | | | | | | | | | | | | | | Instead of just relaying the line number both when parsing files and memory buffers, JsonParser should also print out the file name in case it is available. The error message format should be make-like and emacs-friendly, that is: filename:line_number: error message so that editors and development environments can parse the errors easily. This commit adds the filename string, and a boolean flag for checking whether the filename is set, inside the JsonParser private data structure. The boolean flag is checked inside the JsonScanner error handler when populating the GError or when printing the warning directly on stderr.