X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=i3bar%2Fsrc%2Fparse_json_header.c;h=3d4c2a67f2490652129d361197eeb7535e3849ed;hb=66d504f3cda8fce9dc420ca4ec704910594d5b37;hp=c09e0f499aaf107bedc0f531dd391483b0dd2622;hpb=6582da993948c392daeaf4be018546e9186effb0;p=i3%2Fi3 diff --git a/i3bar/src/parse_json_header.c b/i3bar/src/parse_json_header.c index c09e0f49..3d4c2a67 100644 --- a/i3bar/src/parse_json_header.c +++ b/i3bar/src/parse_json_header.c @@ -2,12 +2,14 @@ * vim:ts=4:sw=4:expandtab * * i3bar - an xcb-based status- and ws-bar for i3 - * © 2010-2012 Axel Wagner and contributors (see also: LICENSE) + * © 2010 Axel Wagner and contributors (see also: LICENSE) * * parse_json_header.c: Parse the JSON protocol header to determine * protocol version and features. * */ +#include "common.h" + #include #include #include @@ -25,8 +27,6 @@ #include #include -#include "common.h" - static enum { KEY_VERSION, KEY_STOP_SIGNAL, @@ -35,11 +35,7 @@ static enum { NO_KEY } current_key; -#if YAJL_MAJOR >= 2 static int header_integer(void *ctx, long long val) { -#else -static int header_integer(void *ctx, long val) { -#endif i3bar_child *child = ctx; switch (current_key) { @@ -74,13 +70,9 @@ static int header_boolean(void *ctx, int val) { } #define CHECK_KEY(name) (stringlen == strlen(name) && \ - STARTS_WITH((const char*)stringval, stringlen, name)) + STARTS_WITH((const char *)stringval, stringlen, name)) -#if YAJL_MAJOR >= 2 static int header_map_key(void *ctx, const unsigned char *stringval, size_t stringlen) { -#else -static int header_map_key(void *ctx, const unsigned char *stringval, unsigned int stringlen) { -#endif if (CHECK_KEY("version")) { current_key = KEY_VERSION; } else if (CHECK_KEY("stop_signal")) { @@ -93,20 +85,6 @@ static int header_map_key(void *ctx, const unsigned char *stringval, unsigned in return 1; } -static yajl_callbacks version_callbacks = { - NULL, /* null */ - &header_boolean, /* boolean */ - &header_integer, - NULL, /* double */ - NULL, /* number */ - NULL, /* string */ - NULL, /* start_map */ - &header_map_key, - NULL, /* end_map */ - NULL, /* start_array */ - NULL /* end_array */ -}; - static void child_init(i3bar_child *child) { child->version = 0; child->stop_signal = SIGSTOP; @@ -122,20 +100,20 @@ static void child_init(i3bar_child *child) { * */ void parse_json_header(i3bar_child *child, const unsigned char *buffer, int length, unsigned int *consumed) { + static yajl_callbacks version_callbacks = { + .yajl_boolean = header_boolean, + .yajl_integer = header_integer, + .yajl_map_key = &header_map_key, + }; + child_init(child); current_key = NO_KEY; -#if YAJL_MAJOR >= 2 yajl_handle handle = yajl_alloc(&version_callbacks, NULL, child); /* Allow trailing garbage. yajl 1 always behaves that way anyways, but for * yajl 2, we need to be explicit. */ yajl_config(handle, yajl_allow_trailing_garbage, 1); -#else - yajl_parser_config parse_conf = { 0, 0 }; - - yajl_handle handle = yajl_alloc(&version_callbacks, &parse_conf, NULL, child); -#endif yajl_status state = yajl_parse(handle, buffer, length); if (state != yajl_status_ok) {