/* * 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 #include typedef enum { ABOUT, COMMIT, SOURCE, EMAIL, TRAILER, 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