From b150ec1c47cc8e02acc0a309bda762615d0efa70 Mon Sep 17 00:00:00 2001 From: Axel Wagner Date: Thu, 28 Apr 2011 20:23:12 +0200 Subject: [PATCH] Apply ugly yajl-compatibility-fix (thx sECuRE) --- i3bar/common.mk | 4 ++++ i3bar/src/outputs.c | 23 +++++++++++++++++++++-- i3bar/src/workspaces.c | 22 ++++++++++++++++++++-- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/i3bar/common.mk b/i3bar/common.mk index db0e549d..1db1558a 100644 --- a/i3bar/common.mk +++ b/i3bar/common.mk @@ -7,6 +7,10 @@ PREFIX=/usr # The escaping is absurd, but we need to escape for shell, sed, make, define GIT_VERSION:="$(shell git describe --tags --always) ($(shell git log --pretty=format:%cd --date=short -n1), branch $(shell [ -f .git/HEAD ] && sed 's/ref: refs\/heads\/\(.*\)/\\\\\\"\1\\\\\\"/g' .git/HEAD || echo 'unknown'))" +# Fallback for libyajl 1 which did not include yajl_version.h. We need +# YAJL_MAJOR from that file to decide which code path should be used. +CFLAGS += -idirafter yajl-fallback + CFLAGS += -Wall CFLAGS += -pipe CFLAGS += -Iinclude diff --git a/i3bar/src/outputs.c b/i3bar/src/outputs.c index 20ff8276..0619d8b0 100644 --- a/i3bar/src/outputs.c +++ b/i3bar/src/outputs.c @@ -14,6 +14,7 @@ #include #include #include +#include #include "common.h" @@ -60,7 +61,11 @@ static int outputs_boolean_cb(void *params_, bool val) { * Parse an integer (current_workspace or the rect) * */ +#if YAJL_MAJOR >= 2 +static int outputs_integer_cb(void *params_, long long val) { +#else static int outputs_integer_cb(void *params_, long val) { +#endif struct outputs_json_params *params = (struct outputs_json_params*) params_; if (!strcmp(params->cur_key, "current_workspace")) { @@ -100,7 +105,11 @@ static int outputs_integer_cb(void *params_, long val) { * Parse a string (name) * */ +#if YAJL_MAJOR >= 2 +static int outputs_string_cb(void *params_, const unsigned char *val, size_t len) { +#else static int outputs_string_cb(void *params_, const unsigned char *val, unsigned int len) { +#endif struct outputs_json_params *params = (struct outputs_json_params*) params_; if (!strcmp(params->cur_key, "current_workspace")) { @@ -186,7 +195,11 @@ static int outputs_end_map_cb(void *params_) { * Essentially we just save it in the parsing-state * */ -static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) { +#if YAJL_MAJOR >= 2 +static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) { +#else +static int outputs_map_key_cb(void *params_, const unsigned char *keyVal, unsigned keyLen) { +#endif struct outputs_json_params *params = (struct outputs_json_params*) params_; FREE(params->cur_key); @@ -233,10 +246,14 @@ void parse_outputs_json(char *json) { params.json = json; yajl_handle handle; - yajl_parser_config parse_conf = { 0, 0 }; yajl_status state; +#if YAJL_MAJOR < 2 + yajl_parser_config parse_conf = { 0, 0 }; handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) ¶ms); +#else + handle = yajl_alloc(&outputs_callbacks, NULL, (void*) ¶ms); +#endif state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); @@ -245,7 +262,9 @@ void parse_outputs_json(char *json) { case yajl_status_ok: break; case yajl_status_client_canceled: +#if YAJL_MAJOR < 2 case yajl_status_insufficient_data: +#endif case yajl_status_error: ELOG("Could not parse outputs-reply!\n"); exit(EXIT_FAILURE); diff --git a/i3bar/src/workspaces.c b/i3bar/src/workspaces.c index 89f7757d..50f7f754 100644 --- a/i3bar/src/workspaces.c +++ b/i3bar/src/workspaces.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "common.h" @@ -58,7 +59,11 @@ static int workspaces_boolean_cb(void *params_, bool val) { * Parse an integer (num or the rect) * */ +#if YAJL_MAJOR >= 2 +static int workspaces_integer_cb(void *params_, long long val) { +#else static int workspaces_integer_cb(void *params_, long val) { +#endif struct workspaces_json_params *params = (struct workspaces_json_params*) params_; if (!strcmp(params->cur_key, "num")) { @@ -99,8 +104,11 @@ static int workspaces_integer_cb(void *params_, long val) { * Parse a string (name, output) * */ +#if YAJL_MAJOR >= 2 +static int workspaces_string_cb(void *params_, const unsigned char *val, size_t len) { +#else static int workspaces_string_cb(void *params_, const unsigned char *val, unsigned int len) { - +#endif struct workspaces_json_params *params = (struct workspaces_json_params*) params_; char *output_name; @@ -179,7 +187,11 @@ static int workspaces_start_map_cb(void *params_) { * Essentially we just save it in the parsing-state * */ +#if YAJL_MAJOR >= 2 +static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, size_t keyLen) { +#else static int workspaces_map_key_cb(void *params_, const unsigned char *keyVal, unsigned int keyLen) { +#endif struct workspaces_json_params *params = (struct workspaces_json_params*) params_; FREE(params->cur_key); @@ -225,10 +237,14 @@ void parse_workspaces_json(char *json) { params.json = json; yajl_handle handle; - yajl_parser_config parse_conf = { 0, 0 }; yajl_status state; +#if YAJL_MAJOR < 2 + yajl_parser_config parse_conf = { 0, 0 }; handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) ¶ms); +#else + handle = yajl_alloc(&workspaces_callbacks, NULL, (void*) ¶ms); +#endif state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); @@ -237,7 +253,9 @@ void parse_workspaces_json(char *json) { case yajl_status_ok: break; case yajl_status_client_canceled: +#if YAJL_MAJOR < 2 case yajl_status_insufficient_data: +#endif case yajl_status_error: ELOG("Could not parse workspaces-reply!\n"); exit(EXIT_FAILURE); -- 2.39.5