diff options
Diffstat (limited to 'scriptbase.h')
-rw-r--r-- | scriptbase.h | 77 |
1 files changed, 77 insertions, 0 deletions
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 <stdbool.h> + +#include <cjson/cJSON.h> + +#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 */ |