/*
 * http_listener.h — minimal HTTP/1.1 parser for n_signer's HTTP listener mode.
 */
#ifndef NSIGNER_HTTP_LISTENER_H
#define NSIGNER_HTTP_LISTENER_H

#include <stddef.h>

#ifdef __cplusplus
extern "C" {
#endif

/*
 * Read an HTTP POST request from fd and return the JSON body.
 * On success returns 0 and sets *out_body to a malloc'd NUL-terminated
 * string (caller frees). Returns -1 on read error, -2 on method not allowed,
 * -3 on missing Content-Length, -4 on body too large.
 */
int http_recv_request(int fd, char **out_body, size_t max_body_size);

/*
 * Send an HTTP 200 response with a JSON body.
 */
int http_send_response(int fd, const char *json_body);

/*
 * Send an HTTP error response.
 */
int http_send_error(int fd, int status, const char *message);

/*
 * Send a CORS preflight response (for OPTIONS requests).
 */
int http_send_cors_preflight(int fd);

#ifdef __cplusplus
}
#endif

#endif /* NSIGNER_HTTP_LISTENER_H */
