Make code compatible with yajl 2.0 *and* 1.0
This commit is contained in:
parent
31da1eb0c1
commit
646fcc3dbc
@ -72,6 +72,10 @@ ifeq ($(UNAME),FreeBSD)
|
|||||||
LDFLAGS += -liconv
|
LDFLAGS += -liconv
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# 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
|
||||||
|
|
||||||
ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
|
ifneq (,$(filter Linux GNU GNU/%, $(UNAME)))
|
||||||
CFLAGS += -D_GNU_SOURCE
|
CFLAGS += -D_GNU_SOURCE
|
||||||
endif
|
endif
|
||||||
|
23
src/ipc.c
23
src/ipc.c
@ -3,7 +3,7 @@
|
|||||||
*
|
*
|
||||||
* i3 - an improved dynamic tiling window manager
|
* i3 - an improved dynamic tiling window manager
|
||||||
*
|
*
|
||||||
* © 2009-2010 Michael Stapelberg and contributors
|
* © 2009-2011 Michael Stapelberg and contributors
|
||||||
*
|
*
|
||||||
* See file LICENSE for license information.
|
* See file LICENSE for license information.
|
||||||
*
|
*
|
||||||
@ -26,6 +26,7 @@
|
|||||||
#include <ev.h>
|
#include <ev.h>
|
||||||
#include <yajl/yajl_gen.h>
|
#include <yajl/yajl_gen.h>
|
||||||
#include <yajl/yajl_parse.h>
|
#include <yajl/yajl_parse.h>
|
||||||
|
#include <yajl/yajl_version.h>
|
||||||
|
|
||||||
#include "queue.h"
|
#include "queue.h"
|
||||||
#include "ipc.h"
|
#include "ipc.h"
|
||||||
@ -182,7 +183,11 @@ IPC_HANDLER(get_workspaces) {
|
|||||||
if (last_focused == SLIST_END(&(c_ws->focus_stack)))
|
if (last_focused == SLIST_END(&(c_ws->focus_stack)))
|
||||||
last_focused = NULL;
|
last_focused = NULL;
|
||||||
|
|
||||||
|
#if YAJL_MAJOR >= 2
|
||||||
|
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||||
|
#else
|
||||||
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
|
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
|
||||||
|
#endif
|
||||||
y(array_open);
|
y(array_open);
|
||||||
|
|
||||||
TAILQ_FOREACH(ws, workspaces, workspaces) {
|
TAILQ_FOREACH(ws, workspaces, workspaces) {
|
||||||
@ -226,7 +231,11 @@ IPC_HANDLER(get_workspaces) {
|
|||||||
y(array_close);
|
y(array_close);
|
||||||
|
|
||||||
const unsigned char *payload;
|
const unsigned char *payload;
|
||||||
|
#if YAJL_MAJOR >= 2
|
||||||
|
size_t length;
|
||||||
|
#else
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
|
#endif
|
||||||
y(get_buf, &payload, &length);
|
y(get_buf, &payload, &length);
|
||||||
|
|
||||||
ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_WORKSPACES, length);
|
ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_WORKSPACES, length);
|
||||||
@ -241,7 +250,11 @@ IPC_HANDLER(get_workspaces) {
|
|||||||
IPC_HANDLER(get_outputs) {
|
IPC_HANDLER(get_outputs) {
|
||||||
Output *output;
|
Output *output;
|
||||||
|
|
||||||
|
#if YAJL_MAJOR >= 2
|
||||||
|
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||||
|
#else
|
||||||
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
|
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
|
||||||
|
#endif
|
||||||
y(array_open);
|
y(array_open);
|
||||||
|
|
||||||
TAILQ_FOREACH(output, &outputs, outputs) {
|
TAILQ_FOREACH(output, &outputs, outputs) {
|
||||||
@ -276,7 +289,11 @@ IPC_HANDLER(get_outputs) {
|
|||||||
y(array_close);
|
y(array_close);
|
||||||
|
|
||||||
const unsigned char *payload;
|
const unsigned char *payload;
|
||||||
|
#if YAJL_MAJOR >= 2
|
||||||
|
size_t length;
|
||||||
|
#else
|
||||||
unsigned int length;
|
unsigned int length;
|
||||||
|
#endif
|
||||||
y(get_buf, &payload, &length);
|
y(get_buf, &payload, &length);
|
||||||
|
|
||||||
ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_OUTPUTS, length);
|
ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_OUTPUTS, length);
|
||||||
@ -338,7 +355,11 @@ IPC_HANDLER(subscribe) {
|
|||||||
memset(&callbacks, 0, sizeof(yajl_callbacks));
|
memset(&callbacks, 0, sizeof(yajl_callbacks));
|
||||||
callbacks.yajl_string = add_subscription;
|
callbacks.yajl_string = add_subscription;
|
||||||
|
|
||||||
|
#if YAJL_MAJOR >= 2
|
||||||
|
p = yajl_alloc(&callbacks, NULL, (void*)client);
|
||||||
|
#else
|
||||||
p = yajl_alloc(&callbacks, NULL, NULL, (void*)client);
|
p = yajl_alloc(&callbacks, NULL, NULL, (void*)client);
|
||||||
|
#endif
|
||||||
stat = yajl_parse(p, (const unsigned char*)message, message_size);
|
stat = yajl_parse(p, (const unsigned char*)message, message_size);
|
||||||
if (stat != yajl_status_ok) {
|
if (stat != yajl_status_ok) {
|
||||||
unsigned char *err;
|
unsigned char *err;
|
||||||
|
7
yajl-fallback/yajl/yajl_version.h
Normal file
7
yajl-fallback/yajl/yajl_version.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef YAJL_VERSION_H_
|
||||||
|
#define YAJL_VERSION_H_
|
||||||
|
/* Fallback for libyajl 1 which does not provide yajl_version.h */
|
||||||
|
#define YAJL_MAJOR 1
|
||||||
|
#define YAJL_MINOR 0
|
||||||
|
#define YAJL_MICRO 0
|
||||||
|
#endif
|
Loading…
Reference in New Issue
Block a user