Prepare the Integration with systemd
[src/app-framework-main.git] / src / mustach.h
1 /*
2  Author: José Bollo <jobol@nonadev.net>
3  Author: José Bollo <jose.bollo@iot.bzh>
4
5  https://gitlab.com/jobol/mustach
6
7  Licensed under the Apache License, Version 2.0 (the "License");
8  you may not use this file except in compliance with the License.
9  You may obtain a copy of the License at
10
11      http://www.apache.org/licenses/LICENSE-2.0
12
13  Unless required by applicable law or agreed to in writing, software
14  distributed under the License is distributed on an "AS IS" BASIS,
15  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  See the License for the specific language governing permissions and
17  limitations under the License.
18 */
19
20 #ifndef _mustach_h_included_
21 #define _mustach_h_included_
22
23 /**
24  * mustach_itf - interface for callbacks
25  *
26  * All of this function should return a negative value to stop
27  * the mustache processing. The returned negative value will be
28  * then returned to the caller of mustach as is.
29  *
30  * The functions enter and next should return 0 or 1.
31  *
32  * All other functions should normally return 0.
33  *
34  * @start: Starts the mustach processing of the closure
35  *         'start' is optional (can be NULL)
36  *
37  * @put: Writes the value of 'name' to 'file' with 'escape' or not
38  *
39  * @enter: Enters the section of 'name' if possible.
40  *         Musts return 1 if entered or 0 if not entered.
41  *         When 1 is returned, the function 'leave' will always be called.
42  *         Conversely 'leave' is never called when enter returns 0 or
43  *         a negative value.
44  *         When 1 is returned, the function must activate the first
45  *         item of the section.
46  *
47  * @next: Activates the next item of the section if it exists.
48  *        Musts return 1 when the next item is activated.
49  *        Musts return 0 when there is no item to activate.
50  *
51  * @leave: Leaves the last entered section
52  */
53 struct mustach_itf {
54         int (*start)(void *closure);
55         int (*put)(void *closure, const char *name, int escape, FILE *file);
56         int (*enter)(void *closure, const char *name);
57         int (*next)(void *closure);
58         int (*leave)(void *closure);
59 };
60
61 #define MUSTACH_OK                       0
62 #define MUSTACH_ERROR_SYSTEM            -1
63 #define MUSTACH_ERROR_UNEXPECTED_END    -2
64 #define MUSTACH_ERROR_EMPTY_TAG         -3
65 #define MUSTACH_ERROR_TAG_TOO_LONG      -4
66 #define MUSTACH_ERROR_BAD_SEPARATORS    -5
67 #define MUSTACH_ERROR_TOO_DEPTH         -6
68 #define MUSTACH_ERROR_CLOSING           -7
69 #define MUSTACH_ERROR_BAD_UNESCAPE_TAG  -8
70
71 /**
72  * fmustach - Renders the mustache 'template' in 'file' for 'itf' and 'closure'.
73  *
74  * @template: the template string to instanciate
75  * @itf:      the interface to the functions that mustach calls
76  * @closure:  the closure to pass to functions called
77  * @file:     the file where to write the result
78  *
79  * Returns 0 in case of success, -1 with errno set in case of system error
80  * a other negative value in case of error.
81  */
82 extern int fmustach(const char *template, struct mustach_itf *itf, void *closure, FILE *file);
83
84 /**
85  * fmustach - Renders the mustache 'template' in 'fd' for 'itf' and 'closure'.
86  *
87  * @template: the template string to instanciate
88  * @itf:      the interface to the functions that mustach calls
89  * @closure:  the closure to pass to functions called
90  * @fd:       the file descriptor number where to write the result
91  *
92  * Returns 0 in case of success, -1 with errno set in case of system error
93  * a other negative value in case of error.
94  */
95 extern int fdmustach(const char *template, struct mustach_itf *itf, void *closure, int fd);
96
97 /**
98  * fmustach - Renders the mustache 'template' in 'result' for 'itf' and 'closure'.
99  *
100  * @template: the template string to instanciate
101  * @itf:      the interface to the functions that mustach calls
102  * @closure:  the closure to pass to functions called
103  * @result:   the pointer receiving the result when 0 is returned
104  * @size:     the size of the returned result
105  *
106  * Returns 0 in case of success, -1 with errno set in case of system error
107  * a other negative value in case of error.
108  */
109 extern int mustach(const char *template, struct mustach_itf *itf, void *closure, char **result, size_t *size);
110
111 #endif
112