// SPDX-License-Identifier: WTFPL // cc -Wall -O2 -I/usr/local/include -L/usr/local/lib -ljansson iris2flu.c -o iris2flu #include #include static void build_relay_list(json_t *content) { printf("# relays: %s\x0d\x0a", json_string_value(content)); } static void build_follow_list(json_t *tags) { int index; json_t *value; json_array_foreach (tags, index, value) { if (*json_string_value(json_array_get(value, 0)) == 'p' && json_string_length(json_array_get(value, 1))) { printf("%s\x0d\x0a", json_string_value(json_array_get(value, 1))); } } } int main(int argc, char *argv[]) { json_t *root, *object, *tags, *content; json_error_t error; size_t index; if (argc < 2) { printf("usage: %s [filename]\n", argv[0]); goto fin0; } if ((root = json_load_file(argv[1], 0, &error)) == NULL) { printf("file open error\n"); goto fin0; } // event object is inside array json_array_foreach (root, index, object) { if (json_integer_value(json_object_get(object, "kind")) == 3 && (content = json_object_get(object, "content")) != NULL && (tags = json_object_get(object, "tags")) != NULL) { build_relay_list(content); build_follow_list(tags); break; } } //fin1: json_decref(root); fin0: return 0; }