2 * Copyright (C) 2010-2012 jeanfi@gmail.com
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
24 #include <json/json.h>
28 char *task_exec(char *opts)
32 char *str, *tmp, *cmd, buf[1024];
36 cmd = malloc(strlen("task rc.json.array=on ") + strlen(opts) + 1);
37 strcpy(cmd, "task rc.json.array=on ");
40 printf("execute: %s\n", cmd);
51 while ((s = fread(buf, 1, 1024, f))) {
52 tmp = malloc(strlen(str) + s + 1);
53 memcpy(tmp, str, strlen(str));
54 memcpy(tmp + strlen(str), buf, s);
55 tmp[strlen(str) + s] = '\0';
63 printf("pclose fails\n");
73 static struct json_object *task_exec_json(char *opts)
75 struct json_object *o;
78 str = task_exec(opts);
81 o = json_tokener_parse(str);
89 struct task **get_all_tasks()
92 struct json_object *jtasks, *jtask, *json;
95 jtasks = task_exec_json("export");
100 n = json_object_array_length(jtasks);
102 tasks = malloc((n + 1) * sizeof(struct task *));
104 for (i = 0; i < n; i++) {
105 jtask = json_object_array_get_idx(jtasks, i);
107 tasks[i] = malloc(sizeof(struct task));
109 json = json_object_object_get(jtask, "id");
110 tasks[i]->id = json_object_get_int(json);
112 json = json_object_object_get(jtask, "description");
113 tasks[i]->description = strdup(json_object_get_string(json));
115 json = json_object_object_get(jtask, "status");
116 tasks[i]->status = strdup(json_object_get_string(json));
118 json = json_object_object_get(jtask, "project");
121 = strdup(json_object_get_string(json));
123 tasks[i]->project = NULL;
125 json = json_object_object_get(jtask, "uuid");
126 tasks[i]->uuid = strdup(json_object_get_string(json));
128 tasks[i]->note = NULL;
133 json_object_put(jtasks);
138 char *escape(const char *txt)
143 result = malloc(2*strlen(txt)+1);