diff options
| author | Bryce Kwon <bryce@brycekwon.com> | |
|---|---|---|
| committer | Bryce Kwon <bryce@brycekwon.com> | |
| commit | ||
| parent | ||
| tree | ||
| download | ||
Restyle the sources and fix the audit's findings
Diffstat (limited to 'source/filter.h')
| -rw-r--r-- | source/filter.h | 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
1 file changed, 54 insertions, 0 deletions
diff --git a/source/filter.h b/source/filter.h new file mode 100644 index 0000000..861578c --- /dev/null +++ b/source/filter.h @@ -0,0 +1,54 @@ +/* + * Output filters, the hook that lets a site pass page fragments through an + * external program or an embedded Lua script on their way to the browser. A + * filter takes over stdout between an open and a close call, so at most one + * can be active at a time. The exec and Lua backends both hide behind the + * struct cgit_filter call table, so callers never learn which is in use. + */ + +#ifndef CGIT_FILTER_H +#define CGIT_FILTER_H + +#include <stdarg.h> +#include <stdio.h> + +typedef enum { + ABOUT, COMMIT, SOURCE, EMAIL, AUTH +} filter_type; + +struct cgit_filter { + int (*open)(struct cgit_filter *, va_list ap); + int (*close)(struct cgit_filter *); + void (*fprintfp)(struct cgit_filter *, FILE *, const char *prefix); + void (*cleanup)(struct cgit_filter *); + int argument_count; +}; + +struct cgit_exec_filter { + struct cgit_filter base; + char *cmd; + char **argv; + int old_stdout; + int pid; +}; + +extern struct cgit_filter *cgit_new_filter(const char *cmd, + filter_type filtertype); +extern void cgit_exec_filter_init(struct cgit_exec_filter *filter, char *cmd, + char **argv); + +/* + * Redirect stdout into the filter and pass it the variadic arguments its type + * expects, then hand stdout back and return the filter's exit status. + */ +extern int cgit_open_filter(struct cgit_filter *filter, ...); +extern int cgit_close_filter(struct cgit_filter *filter); + +// Describe the filter the way cgitrc would have configured it. +extern void cgit_fprintf_filter(struct cgit_filter *filter, FILE *f, + const char *prefix); + +extern void cgit_init_filters(void); +extern void cgit_cleanup_filters(void); + +#endif // CGIT_FILTER_H |
