summaryrefslogtreecommitdiff
path: root/src/shared/json.h
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2014-12-15 22:26:56 +0100
committerLennart Poettering <lennart@poettering.net>2014-12-15 22:27:15 +0100
commite7eebcfc42f00aa481ef31abc8e7e243c16f5b2c (patch)
treeb2d7e393fc5252877c15f46eab95c0450f02d52a /src/shared/json.h
parentc532d8a00cacacc6775effb7aadca680b1d39ccd (diff)
shared: add minimal JSON tokenizer
Diffstat (limited to 'src/shared/json.h')
-rw-r--r--src/shared/json.h50
1 files changed, 50 insertions, 0 deletions
diff --git a/src/shared/json.h b/src/shared/json.h
new file mode 100644
index 000000000..a8457132e
--- /dev/null
+++ b/src/shared/json.h
@@ -0,0 +1,50 @@
+/*-*- Mode: C; c-basic-offset: 8; indent-tabs-mode: nil -*-*/
+
+#pragma once
+
+/***
+ This file is part of systemd.
+
+ Copyright 2014 Lennart Poettering
+
+ systemd is free software; you can redistribute it and/or modify it
+ under the terms of the GNU Lesser General Public License as published by
+ the Free Software Foundation; either version 2.1 of the License, or
+ (at your option) any later version.
+
+ systemd is distributed in the hope that it will be useful, but
+ WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public License
+ along with systemd; If not, see <http://www.gnu.org/licenses/>.
+***/
+
+#include <stdbool.h>
+#include <inttypes.h>
+
+enum {
+ JSON_END,
+ JSON_COLON,
+ JSON_COMMA,
+ JSON_OBJECT_OPEN,
+ JSON_OBJECT_CLOSE,
+ JSON_ARRAY_OPEN,
+ JSON_ARRAY_CLOSE,
+ JSON_STRING,
+ JSON_REAL,
+ JSON_INTEGER,
+ JSON_BOOLEAN,
+ JSON_NULL,
+};
+
+union json_value {
+ bool boolean;
+ double real;
+ intmax_t integer;
+};
+
+#define JSON_VALUE_NULL ((union json_value) {})
+
+int json_tokenize(const char **p, char **ret_string, union json_value *ret_value, void **state, unsigned *line);