Make code compatible with yajl 2.0 *and* 1.0
This commit is contained in:
40
src/ipc.c
40
src/ipc.c
@ -3,7 +3,7 @@
|
||||
*
|
||||
* 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.
|
||||
*
|
||||
@ -17,6 +17,7 @@
|
||||
#include <ev.h>
|
||||
#include <yajl/yajl_gen.h>
|
||||
#include <yajl/yajl_parse.h>
|
||||
#include <yajl/yajl_version.h>
|
||||
|
||||
#include "all.h"
|
||||
|
||||
@ -282,12 +283,20 @@ void dump_node(yajl_gen gen, struct Con *con, bool inplace_restart) {
|
||||
|
||||
IPC_HANDLER(tree) {
|
||||
setlocale(LC_NUMERIC, "C");
|
||||
#if YAJL_MAJOR >= 2
|
||||
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||
#else
|
||||
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
|
||||
#endif
|
||||
dump_node(gen, croot, false);
|
||||
setlocale(LC_NUMERIC, "");
|
||||
|
||||
const unsigned char *payload;
|
||||
#if YAJL_MAJOR >= 2
|
||||
size_t length;
|
||||
#else
|
||||
unsigned int length;
|
||||
#endif
|
||||
y(get_buf, &payload, &length);
|
||||
|
||||
ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_TREE, length);
|
||||
@ -300,7 +309,11 @@ IPC_HANDLER(tree) {
|
||||
*
|
||||
*/
|
||||
IPC_HANDLER(get_workspaces) {
|
||||
#if YAJL_MAJOR >= 2
|
||||
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||
#else
|
||||
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
|
||||
#endif
|
||||
y(array_open);
|
||||
|
||||
Con *focused_ws = con_get_workspace(focused);
|
||||
@ -351,7 +364,11 @@ IPC_HANDLER(get_workspaces) {
|
||||
y(array_close);
|
||||
|
||||
const unsigned char *payload;
|
||||
#if YAJL_MAJOR >= 2
|
||||
size_t length;
|
||||
#else
|
||||
unsigned int length;
|
||||
#endif
|
||||
y(get_buf, &payload, &length);
|
||||
|
||||
ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_WORKSPACES, length);
|
||||
@ -364,7 +381,11 @@ IPC_HANDLER(get_workspaces) {
|
||||
*
|
||||
*/
|
||||
IPC_HANDLER(get_outputs) {
|
||||
#if YAJL_MAJOR >= 2
|
||||
yajl_gen gen = yajl_gen_alloc(NULL);
|
||||
#else
|
||||
yajl_gen gen = yajl_gen_alloc(NULL, NULL);
|
||||
#endif
|
||||
y(array_open);
|
||||
|
||||
Output *output;
|
||||
@ -401,7 +422,11 @@ IPC_HANDLER(get_outputs) {
|
||||
y(array_close);
|
||||
|
||||
const unsigned char *payload;
|
||||
#if YAJL_MAJOR >= 2
|
||||
size_t length;
|
||||
#else
|
||||
unsigned int length;
|
||||
#endif
|
||||
y(get_buf, &payload, &length);
|
||||
|
||||
ipc_send_message(fd, payload, I3_IPC_REPLY_TYPE_OUTPUTS, length);
|
||||
@ -412,8 +437,17 @@ IPC_HANDLER(get_outputs) {
|
||||
* Callback for the YAJL parser (will be called when a string is parsed).
|
||||
*
|
||||
*/
|
||||
#if YAJL_MAJOR < 2
|
||||
static int add_subscription(void *extra, const unsigned char *s,
|
||||
unsigned int len) {
|
||||
#else
|
||||
static int add_subscription(void *extra, const unsigned char *s,
|
||||
size_t len) {
|
||||
if (len < 0) {
|
||||
DLOG("Invalid subscription with len %zd\n", len);
|
||||
return 1;
|
||||
}
|
||||
#endif
|
||||
ipc_client *client = extra;
|
||||
|
||||
DLOG("should add subscription to extra %p, sub %.*s\n", client, len, s);
|
||||
@ -463,7 +497,11 @@ IPC_HANDLER(subscribe) {
|
||||
memset(&callbacks, 0, sizeof(yajl_callbacks));
|
||||
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);
|
||||
#endif
|
||||
stat = yajl_parse(p, (const unsigned char*)message, message_size);
|
||||
if (stat != yajl_status_ok) {
|
||||
unsigned char *err;
|
||||
|
Reference in New Issue
Block a user