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

70 lines
2.9 KiB
C

#ifndef REPOSITORY_H
#define REPOSITORY_H
#include <stddef.h>
/* Payload entry from a repository JSON */
typedef struct RepoPayload {
char name[128];
char filename[256];
char url[1024];
char source[1024];
char source_direct[1024];
char description[1024];
char last_update[64];
char version[64];
char checksum[65];
char source_name[256];
} RepoPayload;
/* Download a URL to a local file. Returns 0 on success, -1 on failure. */
int download_to_file(const char *url, const char *out_path);
/* Parse a JSON string containing payload objects into a RepoPayload array.
* Caller must free *out_items. Returns 0 on success, -1 on failure. */
int parse_repository_payloads(const char *json, RepoPayload **out_items, size_t *out_count);
/* Write a .json sidecar file with payload metadata.
* Returns 0 on success. */
int write_payload_details_json(const RepoPayload *item, const char *details_path,
const char *install_source, const char *install_source_detail);
/* Write a minimal sidecar file when full RepoPayload info isn't available. */
int write_simple_payload_details_json(const char *filename, const char *details_path,
const char *install_source, const char *install_source_detail);
/* ── Repository cache management ────────────────────────── */
/* Accept a full JSON blob pushed by the browser and replace the cache. */
int repository_push_json(const char *json, size_t len);
/* Ensure the repository cache is up-to-date. If force_refresh, always re-download. */
int repository_ensure_fresh(int force_refresh);
/* Build the /repository_payloads JSON response.
* Returns bytes written. */
size_t repository_list_json(char *json_buf, size_t buf_size, int force_refresh);
/* Download and install a payload from the default repository.
* msg_buf receives a human-readable status message. */
int repository_install_download(const char *filename, const char *install_source_detail,
char *msg_buf, size_t msg_buf_size);
/* Verify a previously-uploaded file against the repository and commit it.
* msg_buf receives a human-readable status message. */
int repository_install_commit(const char *filename, const char *uploaded_temp_path,
const char *install_source, const char *install_source_detail,
char *msg_buf, size_t msg_buf_size);
/* ── Self-update ────────────────────────────────────────── */
/* Read the PLDMGR_VER: signature from an ELF binary.
* Returns 0 on success. */
int get_elf_pldmgr_version(const char *path, char *out_version, size_t out_size);
/* Scan the payload storage for a newer pldmgr.elf.
* If found, writes the path to out_path and returns 0. */
int repository_check_self_update(char *out_path, size_t out_size);
#endif