Adding Filter Types to cgit [was: RFE: .so filters]

Jason A. Donenfeld Jason at
Sun Jan 12 23:26:59 CET 2014

On Fri, Jan 10, 2014 at 6:20 PM, John Keeping <john at> wrote:
> I would have no problem including LuaJIT for this sort of thing.
> I might have a look at the Lua case over the weekend if no one beats me
> to it.

John, Florian --

The infrastructure should be just about complete now, if either of you
want to have a stab at adding Lua (or any other type) of plugin.

The steps are basically as follows:

1) Add documentation in the FILTER API section of cgitrc.5.txt
2) Add a prefix and a new_${type}_filter function in filter_specs in filter.c
3) Add a struct to filter.c called ${type}_filter whose first member
is "struct cgit_filter base".
4) Implement open_${type}_filter(), close_${type}_filter(), and
fprintf_${type}_filter(), and optionally cleanup_${type}_filter(), and
optionally call hook_write() and unhook_write(), depending on needs,
in filter.c.

The basic design of a long-lived filter, that needs to do things over
the course of several opens and closes should be:

1) In new_${type}_filter, make any allocations and setup of the
initial struct, but nothing too heavy weight, in case the filter is
never actually used on that cgit.cgi invocation.
2) In open_${type}_filter, construct any long lived processes or
allocations, if they have not already been done so. Call hook_write()
to a write_${type}_filter function. Then pass on a "filter_open(argv)"
event to the underlying filter engine.
3) In write_${type}_filter, pass on the written buffer and the length
to the underlying filter engine in a "filter_write(data, len)" event.
4) In close_${type}_filter, pass on a "filter_close()" event to the
underlying filter engine. Then call unhook_write().
5) In cleanup_${type}_filter(), deallocate and deconstruct whatever
was initialized on the first invocation to open_${type}_filter, and on
the initial construction of the object in new_${type}_filter.
6) In fprintf_${type}_filter(), reconstruct whatever deconstructed
information might have been originally taken from the configuration

How does this general setup sound?


More information about the CGit mailing list