1#ifndef JSON_H
2#define JSON_H
3
4#include <stddef.h>
5#include <stdint.h>
6
7#include "scan.h"
8
9struct json {
10 char* buf;
11 size_t len;
12 size_t cap;
13};
14
15/**
16 * @brief Free memory owned by JSON buffer
17 *
18 * @note Safe to call on NULL or already freed buffers
19 *
20 * @param j JSON object to free
21 */
22void json_free(struct json* j);
23
24/**
25 * @brief Encode library to JSON
26 *
27 * @note On failure, j is freed/emptied
28 *
29 * @param j Output JSON buffer (initialised by in function)
30 * @param l Input library
31 *
32 * @return 0=Success, -1=Failure
33 */
34int json_library(struct json* j, const struct library* l);
35
36/**
37 * @brief Encode item metadata to JSON
38 *
39 * @note On failure, j is freed/emptied
40 *
41 * @param j Output JSON buffer (initialised by this function)
42 * @param it Item (id + relative path)
43 * @param size File size in bytes
44 * @param mtime File modification time in epoch seconds
45 * @param type MIME type string
46 *
47 * @return 0=Success, -1=Failure
48 */
49int json_meta(struct json* j, const struct item* it, size_t size, long mtime, const char* type);
50
51#endif /* JSON_H */
52