From 91d4ce9f14668a5a04b51158b1921e83d51ba9a0 Mon Sep 17 00:00:00 2001 From: Wojtek Kosior Date: Thu, 22 Jul 2021 10:12:58 +0200 Subject: initial codebase --- scriptbase.h | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 scriptbase.h (limited to 'scriptbase.h') diff --git a/scriptbase.h b/scriptbase.h new file mode 100644 index 0000000..f7694f7 --- /dev/null +++ b/scriptbase.h @@ -0,0 +1,77 @@ +/** + * part of Hydrilla + * Scriptbase struct and functions operating on it. + * + * Copyright (C) 2021 Wojtek Kosior + * Redistribution terms are gathered in the `copyright' file. + */ + +#ifndef SCRIPTBASE_H +#define SCRIPTBASE_H + +#include + +#include + +#include "hashtable.h" + +union component { + struct script *script; + struct bag *bag; + void *any; +}; + +struct component_ref { + struct component_ref *next; + union component component; + const char *component_type; +}; + +struct script { + char *name; + char *location; + char *sha256; + bool filled; +}; + +struct bag { + char *name; + struct component_ref *components, *last_component; + bool filled; +}; + +struct page { + char *pattern; + union component payload; + const char *payload_type; +}; + +struct scriptbase { + char *repo_url; + hashtable_t scripts; + hashtable_t bags; + hashtable_t pages; +}; + +int catalogue_component(const char *path, cJSON *index_json, + struct scriptbase *base); + +int scriptbase_init(struct scriptbase *base, const char *repo_url); + +void scriptbase_destroy(struct scriptbase *base); + +const struct script *get_script(const char *name, struct scriptbase *base); +const struct bag *get_bag(const char *name, struct scriptbase *base); +const struct page *get_pattern(const char *pattern, struct scriptbase *base); + +char *get_script_json(const char *name, struct scriptbase *base); +char *get_bag_json(const char *name, struct scriptbase *base); +char *get_pattern_json(const char *name, struct scriptbase *base); +char *get_page_query_json(const char *name, struct scriptbase *base); + +int init_url_lookup_regex(void); +void destroy_url_lookup_regex(void); +int lookup_url(const char *url, struct scriptbase *base, + int (*callback)(struct page*, void*), void *data); + +#endif /* SCRIPTBASE_H */ -- cgit v1.2.3