aboutsummaryrefslogtreecommitdiff
path: root/src/scriptbase.h
blob: f7694f7447f176b371cc265a83fb65db175df6f1 (about) (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
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 */