Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // SPDX-License-Identifier: WTFPL
- // cc -Wall -O2 -I/usr/local/include -L/usr/local/lib -ljansson iris2flu.c -o iris2flu
- #include <stdio.h>
- #include <jansson.h>
- 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;
- 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
- if ((object = json_array_get(root, 0)) == NULL) {
- printf("invalid JSON array\n");
- goto fin1;
- }
- if (json_integer_value(json_object_get(object, "kind")) != 3 ||
- (content = json_object_get(object, "content")) == NULL ||
- (tags = json_object_get(object, "tags")) == NULL) {
- printf("invalid JSON content\n");
- goto fin1;
- }
- build_relay_list(content);
- build_follow_list(tags);
- fin1:
- json_decref(root);
- fin0:
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement