0
0
Fork 0
mirror of https://github.com/matrix-construct/construct synced 2024-12-28 00:14:07 +01:00
construct/include/ircd/json
2018-01-18 06:05:56 -08:00
..
array.h ircd::json: Add recursion depth checking. 2018-01-18 06:05:56 -08:00
iov.h ircd::json: Add additional commentary. 2017-11-30 11:23:40 -08:00
json.h ircd::json: Add recursion depth checking. 2018-01-18 06:05:56 -08:00
member.h ircd::json: Towards uniform defined(). 2017-10-11 20:54:02 -07:00
object.h ircd::json: Add recursion depth checking. 2018-01-18 06:05:56 -08:00
property.h ircd::json: Add support for tuple indexing by hash; add c++11 literal hasher. 2017-10-11 18:18:18 -07:00
README.md ircd: Various comments added/modified. 2017-10-11 18:18:20 -07:00
tuple.h ircd: Add some abstract (non json::) tuple related. 2017-12-24 19:26:05 -07:00
value.h ircd::json: Add more value ctor template specializations. 2017-11-30 11:23:47 -08:00
vector.h ircd::json: Add support for parsing a vector of objects (non-standard). 2017-11-30 11:23:42 -08:00

JavaScript Object Notation

formal grammars & tools

The IRCd JSON subsystem is meant to be a fast, safe, and extremely lightweight interface. We have taken a somewhat non-traditional approach and it's important for the developer to understand a few things.

Most JSON interfaces are functions to convert some JSON input to and from text into native-machine state like JSON.parse() for JS, boost::ptree, etc. For a parsing operation, they make a pass recursing over the entire text, allocating native structures, copying data into them, indexing their keys, and perhaps performing native-type conversions and checks to present the user with a final tree of machine-state usable in their language. The original input is then discarded.

Instead, we are interested in having the ability to compute directly over JSON text itself, and perform the allocating, indexing, copying and converting entirely at the time and place of our discretion -- if ever.

The core of this system is a robust and efficient abstract formal grammar built with boost::spirit. The formal grammar provides a proof of robust- ness: security vulnerabilities are more easily spotted by vetting this grammar rather than laboriously tracing the program flow of an informal handwritten parser.

Next we have taught boost::spirit how to parse into std::string_view rather than std::string. Parsing is now a composition of pointers into the original string of JSON. No dynamic allocation ever takes place. No copying of data ever takes place. IRCd can service an entire request from the original network input with absolutely minimal requisite cost.

The output side is also ambitious but probably a little more friendly to the developer. We leverage boost::spirit here also providing formally proven output safety. In other words, the grammar prevents exploits like injecting and terminating JSON as it composes the output.