Files
najdek 2189ee962d refactor: decompose main.c and payload_mgr.c into focused modules
Split two monolithic files (main.c 1538→233 lines, payload_mgr.c
2355→467 lines) into 8 single-responsibility modules:

- http_server.c: MHD request router and all route handlers
- repository.c: repo cache, download, install/commit, self-update
- sources.c: multi-source repository management
- config.c: PldmgrConfig struct, read/write, JSON config handler
- log_server.c: ring buffer, SSE streaming, pldmgr_log()
- json_helpers.c: JsonListBuilder, JSON parser, file I/O utilities
- sha256.c: SHA256 hash implementation
- process_mgr.c: process listing and kill

Introduces PldmgrConfig struct to replace the 8-out-param
read_next_config_values() pattern. Renames extracted functions to
match their new modules (e.g. repository_install_download,
sources_add, process_kill). No HTTP route changes — frontend
is unaffected.
2026-06-03 18:22:26 +02:00

36 lines
1.2 KiB
C

#ifndef JSON_HELPERS_H
#define JSON_HELPERS_H
#include <stddef.h>
/* Incremental JSON array/object builder */
typedef struct JsonListBuilder {
char *buf;
size_t size;
size_t pos;
int first;
} JsonListBuilder;
/* Append formatted text to the builder. Returns 0 on success, -1 on overflow. */
int json_append(JsonListBuilder *jb, const char *fmt, ...);
/* Extract a quoted string value for a given key from a JSON object bounded by
* [obj_start, obj_end). Returns 0 on success, -1 if key not found. */
int json_extract_string(const char *obj_start, const char *obj_end,
const char *key, char *out, size_t out_size);
/* Read an entire file into a malloc'd buffer. Caller must free *out_buf.
* Returns 0 on success, -1 on failure. */
int read_file_text(const char *path, char **out_buf, size_t *out_size);
/* Write data to a file atomically. Returns 0 on success, -1 on failure. */
int write_file_text(const char *path, const char *data, size_t size);
/* Create a directory if it doesn't exist. Returns 0 on success. */
int mkdir_if_missing(const char *path);
/* Recursively create all directories in path. Returns 0 on success. */
int ensure_dir_recursive(const char *path);
#endif