--- /dev/null
+/*
+ * vim:ts=4:sw=4:expandtab
+ *
+ * i3 - an improved dynamic tiling window manager
+ * © 2009-2011 Michael Stapelberg and contributors (see also: LICENSE)
+ *
+ * yajl_utils.h
+ *
+ */
+#ifndef I3_YAJL_UTILS_H
+#define I3_YAJL_UTILS_H
+
+#include <yajl/yajl_gen.h>
+#include <yajl/yajl_parse.h>
+#include <yajl/yajl_version.h>
+
+/* Shorter names for all those yajl_gen_* functions */
+#define y(x, ...) yajl_gen_ ## x (gen, ##__VA_ARGS__)
+#define ystr(str) yajl_gen_string(gen, (unsigned char*)str, strlen(str))
+
+#if YAJL_MAJOR >= 2
+#define ygenalloc() yajl_gen_alloc(NULL)
+#define yalloc(callbacks, client) yajl_alloc(callbacks, NULL, client)
+typedef size_t ylength;
+#else
+#define ygenalloc() yajl_gen_alloc(NULL, NULL);
+#define yalloc(callbacks, client) yajl_alloc(callbacks, NULL, NULL, client)
+typedef unsigned int ylength;
+#endif
+
+#endif
*
*/
#include "all.h"
+#include "yajl_utils.h"
#include <sys/socket.h>
#include <sys/un.h>
#include <ev.h>
#include <yajl/yajl_gen.h>
#include <yajl/yajl_parse.h>
-#include <yajl/yajl_version.h>
char *current_socketpath = NULL;
-/* Shorter names for all those yajl_gen_* functions */
-#define y(x, ...) yajl_gen_ ## x (gen, ##__VA_ARGS__)
-#define ystr(str) yajl_gen_string(gen, (unsigned char*)str, strlen(str))
-
TAILQ_HEAD(ipc_client_head, ipc_client) all_clients = TAILQ_HEAD_INITIALIZER(all_clients);
/*
tree_render();
const unsigned char *reply;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
yajl_gen_get_buf(command_output->json_gen, &reply, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_COMMAND,
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
+ yajl_gen gen = ygenalloc();
dump_node(gen, croot, false);
setlocale(LC_NUMERIC, "");
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_TREE, payload);
*
*/
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
+ yajl_gen gen = ygenalloc();
y(array_open);
Con *focused_ws = con_get_workspace(focused);
y(array_close);
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_WORKSPACES, payload);
*
*/
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
+ yajl_gen gen = ygenalloc();
y(array_open);
Output *output;
y(array_close);
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_OUTPUTS, payload);
*
*/
IPC_HANDLER(get_marks) {
-#if YAJL_MAJOR >= 2
- yajl_gen gen = yajl_gen_alloc(NULL);
-#else
- yajl_gen gen = yajl_gen_alloc(NULL, NULL);
-#endif
+ yajl_gen gen = ygenalloc();
y(array_open);
Con *con;
y(array_close);
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_MARKS, payload);
*
*/
IPC_HANDLER(get_version) {
-#if YAJL_MAJOR >= 2
- yajl_gen gen = yajl_gen_alloc(NULL);
-#else
- yajl_gen gen = yajl_gen_alloc(NULL, NULL);
-#endif
+ yajl_gen gen = ygenalloc();
y(map_open);
ystr("major");
y(map_close);
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_VERSION, payload);
*
*/
IPC_HANDLER(get_bar_config) {
-#if YAJL_MAJOR >= 2
- yajl_gen gen = yajl_gen_alloc(NULL);
-#else
- yajl_gen gen = yajl_gen_alloc(NULL, NULL);
-#endif
+ yajl_gen gen = ygenalloc();
/* If no ID was passed, we return a JSON array with all IDs */
if (message_size == 0) {
y(array_close);
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_BAR_CONFIG, payload);
y(map_close);
const unsigned char *payload;
-#if YAJL_MAJOR >= 2
- size_t length;
-#else
- unsigned int length;
-#endif
+ ylength length;
y(get_buf, &payload, &length);
ipc_send_message(fd, length, I3_IPC_REPLY_TYPE_BAR_CONFIG, payload);
* 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) {
-#endif
+ ylength len) {
ipc_client *client = extra;
DLOG("should add subscription to extra %p, sub %.*s\n", client, (int)len, s);
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
+ p = yalloc(&callbacks, (void*)client);
stat = yajl_parse(p, (const unsigned char*)message, message_size);
if (stat != yajl_status_ok) {
unsigned char *err;