pollen_sys/
lib.rs

1/* Copyright (C) 2023 Mateus de Lima Oliveira */
2
3#![no_std]
4
5pub mod templatizer {
6    type OnElementCallback = fn();
7    type CodegenTagStart = fn();
8    type CodegenTagEnd = fn();
9
10    #[repr(C)]
11    pub struct Context;
12
13    #[repr(C)]
14    pub struct Txn;
15
16    #[repr(C)]
17    pub struct Sql;
18
19    #[repr(C)]
20    pub struct TemplatizerCallbacks {
21        /* Templatizer will manage the memory for the plugin. */
22        /* This avoids memory leaks. */
23        /* This is useful especially if Templatizer is run as a web server module. */
24        pub malloc:
25            extern "C"
26            fn(data: *mut Context, size: usize) -> *mut u8,
27        pub free:
28            extern "C"
29            fn(data: *mut Context, ptr: *mut u8),
30
31        /* array functions */
32        pub strndup:
33            extern "C"
34            fn(data: *mut Context, ptr: *const u8, length: usize) -> *mut u8,
35
36        pub set_compression:
37            extern "C"
38            fn(data: *mut Context, opt: isize),
39        pub set_keep_alive:
40            extern "C"
41            fn(data: *mut Context),
42        pub send_header:
43            extern "C"
44            fn(data: *mut Context, key: *const u8, value: *const u8),
45        pub send_default_headers:
46            extern "C"
47            fn(data: *mut Context),
48        pub set_output_format:
49            extern "C"
50            fn(data: *mut Context, fmt: isize),
51
52        pub add_filler_text:
53            extern "C"
54            fn(data: *mut Context, text: *const u8) -> isize,
55        pub add_control_flow:
56            extern "C"
57            fn(data: *mut Context, b: isize) -> isize, /* for conditionals */
58
59        pub register_element_tag:
60            extern "C"
61            fn(ctx: *mut Context, s: *const u8, cb: OnElementCallback),
62        /*pub register_codegen_start_tag:
63            extern "C"
64            fn(ctx: *mut Context, cb: CodegenTagStart),
65        pub register_codegen_end_tag:
66            extern "C"
67            fn(ctx: *mut Context, cb: CodegenTagEnd),*/
68
69	pub new_if_node:
70            extern "C"
71            fn(ctx: *mut Context) -> isize,
72        pub new_swhile_node:
73            extern "C"
74            fn(ctx: *mut Context) -> isize,
75        pub new_ewhile_node:
76            extern "C"
77            fn(ctx: *mut Context) -> isize,
78        pub new_call_special_node:
79            extern "C"
80            fn(ctx: *mut Context, symbol: *const u8) -> isize,
81
82        pub exit:
83            extern "C"
84            fn(ctx: *mut Context, status: isize),
85        pub get_num_plugin_parameters:
86            extern "C"
87            fn(ctx: *mut Context) -> isize,
88        pub get_plugin_parameter:
89            extern "C"
90            fn(ctx: *mut Context, index: isize, param_ptr: *mut *const u8, param_length: *mut usize) -> isize,
91
92        /* Library agnostic API for accessing
93         * a key-value data store.
94         * This API can be used to make plugin
95         * code portable among different
96         * operatimg systems and plugin
97         * languages. The only system dependent
98         * code being the Templatizer plugin host
99         * executable and the language runtime
100         * of the plugin, if any. */
101        pub storage_open:
102          extern "C"
103          fn(path: *const u8),
104        pub storage_begin_transaction:
105          extern "C"
106          fn(txn: *mut *mut Txn),
107        pub storage_commit_transaction:
108          extern "C"
109          fn(txn: *mut Txn),
110        pub storage_open_database:
111          extern "C"
112          fn(txn: *mut Txn, dbi: *const isize),
113        pub storage_close_database:
114          extern "C"
115          fn(dbi: isize) -> isize,
116        pub storage_get_string:
117          extern "C"
118          fn(txn: *mut Txn,
119           dbi: isize,
120           key_id: isize,
121           value: *mut *mut u8) -> isize,
122        pub storage_get_integer:
123          extern "C"
124          fn(txn: *mut Txn,
125           dbi: isize,
126           key_id: isize,
127           value: *mut isize) -> isize,
128        pub sql_connect:
129            extern "C" fn(connection: *mut Sql, s: *const u8) -> isize,
130        pub sql_disconnect:
131            extern "C" fn(connection: *mut Sql) -> isize,
132        pub sql_execute:
133            extern "C" fn(connection: *mut Sql) -> isize,
134        pub sql_prepare:
135            extern "C" fn() -> isize,
136        pub vm_define:
137            extern "C" fn() -> isize,
138        pub vm_start:
139            extern "C" fn(name: *const u8) -> isize,
140        pub vm_destroy:
141            extern "C" fn(name: *const u8) -> isize,
142    }
143
144    #[repr(C)]
145    pub struct TemplatizerPlugin {
146        pub init:
147            extern "C"
148            fn(data: *mut Context, cb: *const TemplatizerCallbacks) -> isize,
149        pub quit:
150            extern "C"
151            fn(),
152    }
153}
154
155#[cfg(test)]
156mod tests {
157    #[test]
158    fn it_works() {
159        assert_eq!(2 + 2, 4);
160    }
161}