From: Axel Wagner Date: Thu, 28 Apr 2011 18:23:12 +0000 (+0200) Subject: Apply ugly yajl-compatibility-fix (thx sECuRE) X-Git-Tag: 4.0.1~7^2~7 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=08d454b25e073e0a8f3b2d3fc1104ba24c3d64ac;p=i3%2Fi3 Apply ugly yajl-compatibility-fix (thx sECuRE) --- 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 3577d82b..9ffe259e 100644 --- a/i3bar/src/outputs.c +++ b/i3bar/src/outputs.c @@ -13,6 +13,7 @@ #include #include #include +#include #include "common.h" @@ -59,7 +60,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")) { @@ -99,7 +104,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, "name")) { @@ -169,7 +178,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); @@ -216,10 +229,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)); @@ -228,7 +245,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);