Apply ugly yajl-compatibility-fix (thx sECuRE)

This commit is contained in:
Axel Wagner 2011-04-28 20:23:12 +02:00
parent a5a9afcf2e
commit 08d454b25e
3 changed files with 45 additions and 4 deletions

View File

@ -7,6 +7,10 @@ PREFIX=/usr
# The escaping is absurd, but we need to escape for shell, sed, make, define # 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'))" 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 += -Wall
CFLAGS += -pipe CFLAGS += -pipe
CFLAGS += -Iinclude CFLAGS += -Iinclude

View File

@ -13,6 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <i3/ipc.h> #include <i3/ipc.h>
#include <yajl/yajl_parse.h> #include <yajl/yajl_parse.h>
#include <yajl/yajl_version.h>
#include "common.h" #include "common.h"
@ -59,7 +60,11 @@ static int outputs_boolean_cb(void *params_, bool val) {
* Parse an integer (current_workspace or the rect) * 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) { static int outputs_integer_cb(void *params_, long val) {
#endif
struct outputs_json_params *params = (struct outputs_json_params*) params_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (!strcmp(params->cur_key, "current_workspace")) { if (!strcmp(params->cur_key, "current_workspace")) {
@ -99,7 +104,11 @@ static int outputs_integer_cb(void *params_, long val) {
* Parse a string (name) * 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) { 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_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
if (strcmp(params->cur_key, "name")) { 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 * 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_; struct outputs_json_params *params = (struct outputs_json_params*) params_;
FREE(params->cur_key); FREE(params->cur_key);
@ -216,10 +229,14 @@ void parse_outputs_json(char *json) {
params.json = json; params.json = json;
yajl_handle handle; yajl_handle handle;
yajl_parser_config parse_conf = { 0, 0 };
yajl_status state; yajl_status state;
#if YAJL_MAJOR < 2
yajl_parser_config parse_conf = { 0, 0 };
handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) &params); handle = yajl_alloc(&outputs_callbacks, &parse_conf, NULL, (void*) &params);
#else
handle = yajl_alloc(&outputs_callbacks, NULL, (void*) &params);
#endif
state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
@ -228,7 +245,9 @@ void parse_outputs_json(char *json) {
case yajl_status_ok: case yajl_status_ok:
break; break;
case yajl_status_client_canceled: case yajl_status_client_canceled:
#if YAJL_MAJOR < 2
case yajl_status_insufficient_data: case yajl_status_insufficient_data:
#endif
case yajl_status_error: case yajl_status_error:
ELOG("Could not parse outputs-reply!\n"); ELOG("Could not parse outputs-reply!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);

View File

@ -13,6 +13,7 @@
#include <stdio.h> #include <stdio.h>
#include <errno.h> #include <errno.h>
#include <yajl/yajl_parse.h> #include <yajl/yajl_parse.h>
#include <yajl/yajl_version.h>
#include "common.h" #include "common.h"
@ -58,7 +59,11 @@ static int workspaces_boolean_cb(void *params_, bool val) {
* Parse an integer (num or the rect) * 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) { static int workspaces_integer_cb(void *params_, long val) {
#endif
struct workspaces_json_params *params = (struct workspaces_json_params*) params_; struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
if (!strcmp(params->cur_key, "num")) { if (!strcmp(params->cur_key, "num")) {
@ -99,8 +104,11 @@ static int workspaces_integer_cb(void *params_, long val) {
* Parse a string (name, output) * 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) { 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_; struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
char *output_name; char *output_name;
@ -179,7 +187,11 @@ static int workspaces_start_map_cb(void *params_) {
* Essentially we just save it in the parsing-state * 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) { 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_; struct workspaces_json_params *params = (struct workspaces_json_params*) params_;
FREE(params->cur_key); FREE(params->cur_key);
@ -225,10 +237,14 @@ void parse_workspaces_json(char *json) {
params.json = json; params.json = json;
yajl_handle handle; yajl_handle handle;
yajl_parser_config parse_conf = { 0, 0 };
yajl_status state; yajl_status state;
#if YAJL_MAJOR < 2
yajl_parser_config parse_conf = { 0, 0 };
handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) &params); handle = yajl_alloc(&workspaces_callbacks, &parse_conf, NULL, (void*) &params);
#else
handle = yajl_alloc(&workspaces_callbacks, NULL, (void*) &params);
#endif
state = yajl_parse(handle, (const unsigned char*) json, strlen(json)); state = yajl_parse(handle, (const unsigned char*) json, strlen(json));
@ -237,7 +253,9 @@ void parse_workspaces_json(char *json) {
case yajl_status_ok: case yajl_status_ok:
break; break;
case yajl_status_client_canceled: case yajl_status_client_canceled:
#if YAJL_MAJOR < 2
case yajl_status_insufficient_data: case yajl_status_insufficient_data:
#endif
case yajl_status_error: case yajl_status_error:
ELOG("Could not parse workspaces-reply!\n"); ELOG("Could not parse workspaces-reply!\n");
exit(EXIT_FAILURE); exit(EXIT_FAILURE);