struct watchman_watch_list * watchman_watch_list(struct watchman_connection *conn, struct watchman_error *error) { struct watchman_watch_list *res = NULL; struct watchman_watch_list *result = NULL; if (watchman_send_simple_command(conn, error, "watch-list", NULL)) { return NULL; } json_t *obj = watchman_read(conn, error); if (!obj) { return NULL; } JSON_ASSERT(json_is_object, obj, "Got bogus value from watch-list %s"); json_t *roots = json_object_get(obj, "roots"); JSON_ASSERT(json_is_array, roots, "Got bogus value from watch-list %s"); res = malloc(sizeof(*res)); int nr = json_array_size(roots); res->nr = 0; res->roots = calloc(nr, sizeof(*res->roots)); int i; for (i = 0; i < nr; ++i) { json_t *root = json_array_get(roots, i); JSON_ASSERT(json_is_string, root, "Got non-string root from watch-list %s"); res->nr++; res->roots[i] = strdup(json_string_value(root)); } result = res; res = NULL; done: if (res) { watchman_free_watch_list(res); } json_decref(obj); return result; }
struct watchman_watch_list * watchman_watch_list(struct watchman_connection *conn, struct watchman_error *error) { struct watchman_watch_list *res = NULL; struct watchman_watch_list *result = NULL; if (watchman_send_simple_command(conn, error, "watch-list", NULL)) { return NULL; } proto_t obj = watchman_read(conn, error); if (proto_is_null(obj)) { return NULL; } PROTO_ASSERT(proto_is_object, obj, "Got bogus value from watch-list %s"); proto_t roots = proto_object_get(obj, "roots"); PROTO_ASSERT(proto_is_array, roots, "Got bogus value from watch-list %s"); res = malloc(sizeof(*res)); int nr = proto_array_size(roots); res->nr = 0; res->roots = calloc(nr, sizeof(*res->roots)); int i; for (i = 0; i < nr; ++i) { proto_t root = proto_array_get(roots, i); PROTO_ASSERT(proto_is_string, root, "Got non-string root from watch-list %s"); res->nr++; res->roots[i] = proto_strdup(root); } result = res; res = NULL; done: if (res) { watchman_free_watch_list(res); } proto_free(obj); return result; }