summaryrefslogtreecommitdiffstats
path: root/lib/include
diff options
context:
space:
mode:
authorLibravatar bigfoot547 <bigfoot@figboot.dev>2026-01-12 16:30:37 -0600
committerLibravatar bigfoot547 <bigfoot@figboot.dev>2026-01-12 16:30:37 -0600
commit2016dceaa9cfc65ee80ee7e433331390f4263744 (patch)
treed0c97b2ab5fc1933298a050f167b6a68fff08c89 /lib/include
parentadd support for verified files (diff)
download jobs
Diffstat (limited to 'lib/include')
-rw-r--r--lib/include/log.h7
-rw-r--r--lib/include/net.h29
-rw-r--r--lib/include/util.h8
-rw-r--r--lib/include/vector.h27
4 files changed, 71 insertions, 0 deletions
diff --git a/lib/include/log.h b/lib/include/log.h
index a8549e0..1483559 100644
--- a/lib/include/log.h
+++ b/lib/include/log.h
@@ -1,3 +1,6 @@
+#ifndef VL_LOG_H_INCLUDED
+#define VL_LOG_H_INCLUDED
+
#include <stdio.h>
#include <stdarg.h>
@@ -7,6 +10,8 @@
#define LOG_WARN 3u
#define LOG_ERROR 4u
+/* Log functions MUST leave errno untouched */
+
void vl_log_setlevel(unsigned level);
void vl_logv(unsigned level, const char *fmt, va_list args);
@@ -50,3 +55,5 @@ void vl_log(unsigned level, const char *fmt, ...) __attribute__((format(printf,
#define LOG_ERROR_ENABLED
#define vl_error(...) vl_log(LOG_ERROR, __VA_ARGS__)
#define vl_errorv(...) vl_logv(LOG_ERROR, __VA_ARGS__)
+
+#endif
diff --git a/lib/include/net.h b/lib/include/net.h
index 5ee7fc6..610ed77 100644
--- a/lib/include/net.h
+++ b/lib/include/net.h
@@ -2,6 +2,7 @@
#define VL_NET_H_INCLUDED
#include "arena.h"
+#include "sha1.h"
enum {
/* The operation completed successfully */
@@ -61,4 +62,32 @@ int vl_net_ensure_verified(const char *url, const char *target_path, unsigned fl
* Returns NET_EIO if the downloaded file is not readable or could not be verified due to an I/O issue. */
int vl_net_verify(const char *target_path, unsigned flags, ...);
+enum {
+ /* The job hasn't been started yet. */
+ STATUS_WAITING = 0u,
+
+ /* The job is in flight. */
+ STATUS_RUNNING = 1u,
+
+ /* The job is finished without errors. */
+ STATUS_COMPLETE = 2u,
+
+ /* The job is finished with errors. */
+ STATUS_ERROR = 3u,
+
+ /* The job finished successfully, but the downloaded file failed integrity checks. */
+ STATUS_INTEGRITY = 4u
+};
+
+struct vl_download_job {
+ const char *url;
+ const char *opath;
+ size_t expect_len;
+ vl_sha1 expect_hash;
+ unsigned verify_flags;
+ unsigned status;
+};
+
+int vl_net_download_all(struct vl_download_job *jobs, size_t njobs, size_t simult);
+
#endif
diff --git a/lib/include/util.h b/lib/include/util.h
new file mode 100644
index 0000000..5ef3c8b
--- /dev/null
+++ b/lib/include/util.h
@@ -0,0 +1,8 @@
+#ifndef VL_UTIL_H_INCLUDED
+#define VL_UTIL_H_INCLUDED
+
+#include <sys/stat.h>
+
+int vl_mkdir_parents(int fd, char *path, mode_t mode);
+
+#endif
diff --git a/lib/include/vector.h b/lib/include/vector.h
new file mode 100644
index 0000000..02ed84e
--- /dev/null
+++ b/lib/include/vector.h
@@ -0,0 +1,27 @@
+#ifndef VL_VECTOR_H_INCLUDED
+#define VL_VECTOR_H_INCLUDED
+
+#include <stddef.h>
+
+/* implements a vector type (array of same-sized values) */
+
+typedef struct vl__vector_tag vl_vector;
+
+vl_vector *vl_vector_new(size_t sz);
+vl_vector *vl_vector_new_ex(size_t sz, size_t init_cap);
+void vl_vector_free(vl_vector *vec);
+
+/* will abort if realloc fails to shrink the allocation (should never happen) */
+void vl_vector_shrink_to_size(vl_vector *vec);
+
+#define vl_newvec(_t) vl_vector_new(sizeof(_t))
+#define vl_newvec_ex(_t, _ic) vl_vector_new_ex(sizeof(_t), _ic)
+
+int vl_vector_push(vl_vector *vec, void *data);
+int vl_vector_push_vec(vl_vector *vec, void *data, size_t n);
+int vl_vector_push_2d(vl_vector *vec, void **data, size_t n);
+
+size_t vl_vector_size(const vl_vector *vec);
+void *vl_vector_values(const vl_vector *vec, size_t *psz);
+
+#endif