List for cgit developers and users
 help / color / mirror / Atom feed
From: Jason at zx2c4.com (Jason A. Donenfeld)
Subject: [PATCH 03/12] filter: introduce "filter type" prefix
Date: Mon, 13 Jan 2014 05:11:10 +0100	[thread overview]
Message-ID: <1389586279-23724-4-git-send-email-Jason@zx2c4.com> (raw)
In-Reply-To: <1389586279-23724-1-git-send-email-Jason@zx2c4.com>

From: John Keeping <john at keeping.me.uk>

This allows different filter implementations to be specified in the
configuration file.  Currently only "exec" is supported, but it may now
be specified either with or without the "exec:" prefix.

Signed-off-by: John Keeping <john at keeping.me.uk>
---
 cgitrc.5.txt |  9 +++++++++
 filter.c     | 33 +++++++++++++++++++++++++++++++--
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/cgitrc.5.txt b/cgitrc.5.txt
index 52caed0..60159f6 100644
--- a/cgitrc.5.txt
+++ b/cgitrc.5.txt
@@ -557,6 +557,15 @@ config files, e.g. "repo.desc" becomes "desc".
 
 FILTER API
 ----------
+By default, filters are separate processes that are executed each time they
+are needed.  Alternative technologies may be used by prefixing the filter
+specification with the relevant string; available values are:
+
+'exec:'::
+	The default "one process per filter" mode.
+
+Parameters are provided to filters as follows.
+
 about filter::
 	This filter is given a single parameter: the filename of the source
 	file to filter. The filter can use the filename to determine (for
diff --git a/filter.c b/filter.c
index 0f3edb0..ba66e46 100644
--- a/filter.c
+++ b/filter.c
@@ -64,7 +64,7 @@ done:
 static void fprintf_exec_filter(struct cgit_filter *base, FILE *f, const char *prefix)
 {
 	struct cgit_exec_filter *filter = (struct cgit_exec_filter *) base;
-	fprintf(f, "%s%s\n", prefix, filter->cmd);
+	fprintf(f, "%sexec:%s\n", prefix, filter->cmd);
 }
 
 int cgit_open_filter(struct cgit_filter *filter, ...)
@@ -125,10 +125,39 @@ static struct cgit_filter *new_exec_filter(const char *cmd, filter_type filterty
 	return &f->base;
 }
 
+static const struct {
+	const char *prefix;
+	struct cgit_filter *(*ctor)(const char *cmd, filter_type filtertype);
+} filter_specs[] = {
+	{ "exec", new_exec_filter },
+};
+
 struct cgit_filter *cgit_new_filter(const char *cmd, filter_type filtertype)
 {
+	char *colon;
+	int i;
+	size_t len;
 	if (!cmd || !cmd[0])
 		return NULL;
 
-	return new_exec_filter(cmd, filtertype);
+	colon = strchr(cmd, ':');
+	len = colon - cmd;
+	/*
+	 * In case we're running on Windows, don't allow a single letter before
+	 * the colon.
+	 */
+	if (len == 1)
+		colon = NULL;
+
+	/* If no prefix is given, exec filter is the default. */
+	if (!colon)
+		return new_exec_filter(cmd, filtertype);
+
+	for (i = 0; i < ARRAY_SIZE(filter_specs); i++) {
+		if (len == strlen(filter_specs[i].prefix) &&
+		    !strncmp(filter_specs[i].prefix, cmd, len))
+			return filter_specs[i].ctor(colon + 1, filtertype);
+	}
+
+	die("Invalid filter type: %.*s", (int) len, cmd);
 }
-- 
1.8.5.2



  parent reply	other threads:[~2014-01-13  4:11 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-13  4:11 [PATCH 00/12] filter framework and lua integration: complete Jason
2014-01-13  4:11 ` [PATCH 01/12] filter: add fprintf_filter function Jason
2014-01-13  4:11 ` [PATCH 02/12] filter: add interface layer Jason
2014-01-13  4:11 ` Jason [this message]
2014-01-13  4:11 ` [PATCH 04/12] filter: allow for cleanup hook for filter types Jason
2014-01-13  4:11 ` [PATCH 05/12] filter: basic write hooking infrastructure Jason
2014-01-13  8:19   ` cgit
2014-01-13  4:11 ` [PATCH 06/12] filter: add preliminary lua support Jason
2014-01-13  8:31   ` cgit
2014-01-13  8:53     ` john
2014-01-13  8:39   ` cgit
2014-01-13  8:55   ` john
2014-01-13  9:41   ` bluewind
2014-01-13  4:11 ` [PATCH 07/12] filter: document lua filter type Jason
2014-01-13  4:11 ` [PATCH 08/12] filter: lua error reporting Jason
2014-01-13  4:11 ` [PATCH 09/12] filter: return on null filter from open and close Jason
2014-01-13  4:11 ` [PATCH 10/12] filter: add support for email filter Jason
2014-01-13  4:11 ` [PATCH 11/12] filter: add simple gravatar " Jason
2014-01-13  4:11 ` [PATCH 12/12] filter: add gravatar lua script Jason

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1389586279-23724-4-git-send-email-Jason@zx2c4.com \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).