117 lines
3.3 KiB
C
117 lines
3.3 KiB
C
|
|
#ifndef AMDUATD_HTTP_H
|
||
|
|
#define AMDUATD_HTTP_H
|
||
|
|
|
||
|
|
#include "amduat/asl/core.h"
|
||
|
|
|
||
|
|
#include <stdbool.h>
|
||
|
|
#include <stddef.h>
|
||
|
|
#include <stdint.h>
|
||
|
|
#include <sys/types.h>
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
extern "C" {
|
||
|
|
#endif
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
char method[8];
|
||
|
|
char path[1024];
|
||
|
|
char content_type[128];
|
||
|
|
char accept[128];
|
||
|
|
char x_type_tag[64];
|
||
|
|
char x_capability[2048];
|
||
|
|
size_t content_length;
|
||
|
|
bool has_actor;
|
||
|
|
amduat_octets_t actor;
|
||
|
|
bool has_uid;
|
||
|
|
uid_t uid;
|
||
|
|
} amduatd_http_req_t;
|
||
|
|
|
||
|
|
typedef struct {
|
||
|
|
int fd;
|
||
|
|
int status;
|
||
|
|
const char *reason;
|
||
|
|
const char *content_type;
|
||
|
|
const uint8_t *body;
|
||
|
|
size_t body_len;
|
||
|
|
bool head_only;
|
||
|
|
bool ok;
|
||
|
|
} amduatd_http_resp_t;
|
||
|
|
|
||
|
|
bool amduatd_write_all(int fd, const uint8_t *buf, size_t len);
|
||
|
|
|
||
|
|
bool amduatd_read_exact(int fd, uint8_t *buf, size_t len);
|
||
|
|
|
||
|
|
bool amduatd_read_urandom(uint8_t *out, size_t len);
|
||
|
|
|
||
|
|
bool amduatd_http_parse_request(int fd, amduatd_http_req_t *out_req);
|
||
|
|
|
||
|
|
void amduatd_http_req_free(amduatd_http_req_t *req);
|
||
|
|
|
||
|
|
bool amduatd_http_send_response(int fd, const amduatd_http_resp_t *resp);
|
||
|
|
|
||
|
|
bool amduatd_http_send_status(int fd,
|
||
|
|
int code,
|
||
|
|
const char *reason,
|
||
|
|
const char *content_type,
|
||
|
|
const uint8_t *body,
|
||
|
|
size_t body_len,
|
||
|
|
bool head_only);
|
||
|
|
|
||
|
|
bool amduatd_http_send_text(int fd,
|
||
|
|
int code,
|
||
|
|
const char *reason,
|
||
|
|
const char *text,
|
||
|
|
bool head_only);
|
||
|
|
|
||
|
|
bool amduatd_http_send_json(int fd,
|
||
|
|
int code,
|
||
|
|
const char *reason,
|
||
|
|
const char *json,
|
||
|
|
bool head_only);
|
||
|
|
|
||
|
|
bool amduatd_http_send_not_found(int fd, const amduatd_http_req_t *req);
|
||
|
|
|
||
|
|
bool amduatd_send_json_error(int fd,
|
||
|
|
int code,
|
||
|
|
const char *reason,
|
||
|
|
const char *msg);
|
||
|
|
|
||
|
|
const char *amduatd_query_param(const char *path,
|
||
|
|
const char *key,
|
||
|
|
char *out_value,
|
||
|
|
size_t out_cap);
|
||
|
|
|
||
|
|
bool amduatd_path_without_query(const char *path,
|
||
|
|
char *out,
|
||
|
|
size_t cap);
|
||
|
|
|
||
|
|
bool amduatd_path_extract_name(const char *path,
|
||
|
|
const char *prefix,
|
||
|
|
char *out,
|
||
|
|
size_t cap);
|
||
|
|
|
||
|
|
const char *amduatd_json_skip_ws(const char *p, const char *end);
|
||
|
|
|
||
|
|
bool amduatd_json_expect(const char **p,
|
||
|
|
const char *end,
|
||
|
|
char expected);
|
||
|
|
|
||
|
|
bool amduatd_json_parse_string_noesc(const char **p,
|
||
|
|
const char *end,
|
||
|
|
const char **out_start,
|
||
|
|
size_t *out_len);
|
||
|
|
|
||
|
|
bool amduatd_json_parse_u64(const char **p, const char *end, uint64_t *out);
|
||
|
|
|
||
|
|
bool amduatd_json_skip_value(const char **p,
|
||
|
|
const char *end,
|
||
|
|
int depth);
|
||
|
|
|
||
|
|
bool amduatd_copy_json_str(const char *s, size_t len, char **out);
|
||
|
|
|
||
|
|
#ifdef __cplusplus
|
||
|
|
} /* extern "C" */
|
||
|
|
#endif
|
||
|
|
|
||
|
|
#endif /* AMDUATD_HTTP_H */
|