summaryrefslogtreecommitdiffstats
path: root/src/internal.h
diff options
context:
space:
mode:
authorMurilo Ijanc <[email protected]>2026-07-26 12:25:48 -0300
committerMurilo Ijanc <[email protected]>2026-07-26 12:25:48 -0300
commite2c6ae13af335b311da2429c903032124f926df2 (patch)
tree73776fab7f3e52124a217e2768968fc9a8a76c34 /src/internal.h
downloadc-e2c6ae13af335b311da2429c903032124f926df2.tar.gz
Initial importv0.1.0
Diffstat (limited to 'src/internal.h')
-rw-r--r--src/internal.h74
1 files changed, 74 insertions, 0 deletions
diff --git a/src/internal.h b/src/internal.h
new file mode 100644
index 0000000..57487c2
--- /dev/null
+++ b/src/internal.h
@@ -0,0 +1,74 @@
+/**
+ * @file internal.h
+ * @brief Helpers shared between the translation units of this library.
+ *
+ * Nothing here is part of the public ABI.
+ */
+#ifndef CEPIS_INTERNAL_H
+#define CEPIS_INTERNAL_H
+
+#include <stdarg.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+#include "cepis.h"
+#include "csv.h"
+#include "json.h"
+
+/** A growable, always NUL-terminated byte buffer. */
+typedef struct cepis_buf {
+ char *data;
+ size_t len;
+ size_t cap;
+} cepis_buf_t;
+
+/** @brief Put @p buf into the empty state. Allocates nothing. */
+void cepis_buf_init(cepis_buf_t *buf);
+
+/** @brief Append @p len bytes. @return `false` on allocation failure. */
+bool cepis_buf_append(cepis_buf_t *buf, const char *data, size_t len);
+
+/** @brief Append a NUL-terminated string. */
+bool cepis_buf_append_str(cepis_buf_t *buf, const char *text);
+
+/** @brief Release the buffer and return it to the empty state. */
+void cepis_buf_free(cepis_buf_t *buf);
+
+/** @brief `strdup`, tolerating a `NULL` argument by copying `""`. */
+char *cepis_strdup(const char *text);
+
+/**
+ * @brief Fill @p err, tolerating `NULL`.
+ * @return @p status, so callers can `return cepis_set_error(...)`.
+ */
+cepis_status_t cepis_set_error(cepis_error_t *err, cepis_status_t status,
+ long http_status, double retry_after,
+ const char *fmt, ...);
+
+/**
+ * @brief Build an address from a parsed JSON object.
+ * @param object The decoded body.
+ * @param raw The body as it arrived, copied into
+ * ::cepis_address_t::raw. May be `NULL`.
+ * @param raw_len Length of @p raw.
+ * @return An owned address, or `NULL` on allocation failure.
+ *
+ * Unknown members are ignored but preserved in `raw`, so a field the API grows
+ * cannot break this client. A malformed `geo` block yields `geo == NULL` rather
+ * than failing the whole address: the rest of the response is still useful.
+ */
+cepis_address_t *cepis_address_from_json(const json_value_t *object,
+ const char *raw, size_t raw_len);
+
+/**
+ * @brief Build an address from one CSV record and the header record.
+ * @return An owned address, or `NULL` on allocation failure. The result never
+ * carries a coordinate: the CSV has no `geo` column.
+ */
+cepis_address_t *cepis_address_from_csv(const csv_row_t *header,
+ const csv_row_t *record);
+
+/** @brief Build a health report from a parsed JSON object. */
+cepis_health_t *cepis_health_from_json(const json_value_t *object);
+
+#endif