aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2013-07-27 06:43:44 +0300
committerSergey Poznyakoff <gray@gnu.org.ua>2013-07-27 06:43:44 +0300
commit4912a0408aa773dc80e84e19d0d437795acfa043 (patch)
tree7ce4221787afc9e31b5ef80e6da371d30cd34a32
parent9045c4dca5a4ca866dc5563a9aa7d6dd6c5350b7 (diff)
downloadvmod-dbrw-4912a0408aa773dc80e84e19d0d437795acfa043.tar.gz
vmod-dbrw-4912a0408aa773dc80e84e19d0d437795acfa043.tar.bz2
Improve manpage.
-rw-r--r--doc/vmod-dbrw.3227
1 files changed, 90 insertions, 137 deletions
diff --git a/doc/vmod-dbrw.3 b/doc/vmod-dbrw.3
index 9b6d9f5..9496270 100644
--- a/doc/vmod-dbrw.3
+++ b/doc/vmod-dbrw.3
@@ -13,138 +13,37 @@
13.\" 13.\"
14.\" You should have received a copy of the GNU General Public License 14.\" You should have received a copy of the GNU General Public License
15.\" along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>. 15.\" along with vmod-dbrw. If not, see <http://www.gnu.org/licenses/>.
16.TH VMOD_DBRW 1 "July 26, 2013" "VMOD_DBRW" "User Reference" 16.TH VMOD_DBRW 1 "July 27, 2013" "VMOD_DBRW" "User Reference"
17.SH NAME 17.SH NAME
18vmod-dbrw \- Database-driven rewrite rules for Varnish Cache 18vmod-dbrw \- Database-driven rewrite rules for Varnish Cache
19.SH SYNOPSIS 19.SH SYNOPSIS
20.sp 20.B import dbrw;
21.nf 21.br
22import dbrw; 22.BI "VOID dbrw.config(STRING " dbtype ", STRING " params ", STRING " query ");"
23 23.br
24sub vcl_init { 24.BI "STRING dbrw.rewrite(STRING " args ");"
25 dbrw.config("\fIDBTYPE\fR", "\fIPARAMS\fR", "\fIQUERY\fR");
26}
27
28sub vcl_recv {
29 set req.http.\fIXHEADER\fR = dbrw.rewrite(\fIARGS\fR);
30 if (req.http.\fIXHEADER\fR) {
31 error(750, "Redirect");
32 }
33}
34
35sub vcl_error {
36 if (obj.status == 750) {
37 set obj.http.Location = req.http.\fIXHEADER\fR;
38 set obj.status = 301;
39 return (deliver);
40 }
41}
42.fi
43.SH DESCRIPTION 25.SH DESCRIPTION
44.B Vmod-dbrw 26.B Vmod-dbrw
45is a Varnish Cache module implementing database-driven rewrite procedures. 27is a Varnish Cache module implementing database-driven rewrite procedures.
46Its intended use is for web sites that need an exceedingly big number 28Its intended use is for web sites that need an exceedingly big number
47of redirect and/or rewrite rules. 29of redirect and/or rewrite rules.
48.PP 30.PP
49Upon startup, the \fBconfig\fR function should be called. This call 31The \fBconfig\fR function should be called upon startup, in \fBsub
50configures the module and supplies it the information necessary for 32vcl_init\fR. It configures the module and supplies it the information
51accessing the database and interpreting the data obtained from it. 33necessary for accessing the database and interpreting the data
34obtained from it.
52.PP 35.PP
53Two database types are supported: \fBMySQL\fR or \fBPostgreSQL\fR. 36The \fIdbtype\fR argument specifies the database type to use.
54The first argument \fBconfig\fR instructs the module which type to 37Valid values are \fBmysql\fR (for \fBMySQL\fR) and \fBpgsql\fR (for
55use. 38\fBPostgreSQL\fR).
56.PP 39.PP
57.B Vmod-dbrw 40.B Vmod-dbrw
58does not impose any requirements on the structure of the database, 41does not impose any requirements on the structure of the database,
59therefore the connection arguments and access credentials may vary 42therefore the connection arguments and access credentials may vary
60depending on the flavor of the database used. This information is 43depending on the flavor of the database used. This information is
61supplied in the \fIPARAMS\fR argument, which is a list of parameter 44supplied in the \fIparams\fR argument, which is a list of
62assignments separated with semicolons. 45\fINAME\fB=\fIVALUE\fR assignments separated with semicolons.
63.PP 46The
64Once configured, the \fBrewrite\fR function can be called in the
65appropriate place of the Varnish configuration file. Its argument
66\fIARGS\fR is a list of variable assignments separated with
67semicolons, similarly to the \fIPARAMS\fR argument described above.
68Each assignment has the form \fINAME\fB=\fIVALUE\fR. When called
69the function expands the \fBSQL\fR query, supplied with the \fIQUERY\fR
70argument to the \fBconfig\fR call, by replacing each \fB$\fINAME\fR
71construct (a \fBvariable reference\fR) with the corresponding
72\fIVALUE\fR from its argument. Similarly to the shell syntax, the
73variable reference can be written as \fB${\fINAME\fB}\fR. This latter
74form can be used in contexts where the variable name is immediately
75followed by another letter, to prevent it from being counted as a part
76of the name.
77.PP
78The expanded query is then sent to the database server. The handling
79of the return value depends on the number of fields it contains.
80.SS Strict matches
81If the returned set consists of one or two columns, only the
82first tuple is used and the value of its first column is returned.
83The second column (if present) is ignored.
84.SS Regexp matches
85Otherwise, if the returned set consists of three or four columns, the
86columns are interpreted as follows: \fBresult\fR, \fBregexp\fR,
87\fBvalue\fR and optional \fBflags\fR. For each returned tuple, the
88\fBvalue\fR column undergoes variable expansion, using the same
89algorithm as when preparing the query, and the resulting string is
90matched with the \fBregexp\fR column, which is treated as an extended
91\fBPOSIX\fR regular expression. If the match occurs, the \fBresult\fR
92column is expanded by replacing \fBbackreferences\fR. Each occurrence
93of \fB$\fIDIGIT\fR (where \fIDIGIT\fR stands for a decimal digit from
94\fB0\fR through \fB9\fR) is replaced with the contents of the
95\fIDIGIT\fR's parenthesized subexpression in \fBregexp\fR. For
96compatibility with the traditional usage, the \fB\\\fIDIGIT\fR
97notation is also allowed. The resulting value is returned.
98.PP
99Optional \fBflags\fR column is a comma-separated list of flags that
100modify regular expression handling. The following flags are defined:
101.TP
102.BR NC " or " nocase
103Treat \fBregexp\fR as case-insensitive.
104.TP
105.B case
106Treat \fBregexp\fR as case-sensitive (default).
107.TP
108.BR QSA " or " qsappend
109Treat the resulting value as URL; append any query string from the
110original \fBvalue\fR to it.
111.TP
112.BR QSD " or " qsdiscard
113Treat the resulting value as URL; discard any query string attached to
114the original \fBvalue\fR.
115.TP
116\fBredirect=\fICODE\fR or \fBR=\fICODE\fR
117On success, set the \fBX\-VMOD\-DBRW\-Status\fR header to \fICODE\fR,
118which must be a valid HTTP status code.
119.PP
120If \fBregexp\fR or \fBvalue\fR is NULL, the tuple is handled as
121described in
122.BR "Strict matches" .
123.PP
124If \fBflags\fR is NULL, it is ignored.
125.SH FUNCTIONS
126.SS config
127.TP
128.B Prototype
129config(STRING \fIDBTYPE\fR, STRING \fIPARAMS\fR, STRING \fIQUERY\fR)
130.TP
131.B Return value
132VOID
133.TP
134.B Description
135This function configures the module and supplies the data necessary to
136connect and use the database.
137.TP
138.B Arguments
139.RS 4
140.TP
141.I DBTYPE
142Type of the database. Valid values are \fBmysql\fR (for \fBMySQL\fR)
143and \fBpgsql\fR (for \fBPostgreSQL\fR).
144.TP
145.I PARAMS
146Database connection parameters. This is a list of
147\fINAME\fB=\fIVALUE\fR assignments separated with semicolons. The
148\fIVALUE\fR can be any sequence of characters, excepting white space 47\fIVALUE\fR can be any sequence of characters, excepting white space
149and semicolon. If any of these have to appear in it, they must either 48and semicolon. If any of these have to appear in it, they must either
150be escaped by prepending them with a backslash, or entire \fIVALUE\fR 49be escaped by prepending them with a backslash, or entire \fIVALUE\fR
@@ -169,7 +68,6 @@ enclosed in a pair of (single or double) quotes. The following
169Any other character following a backslash is output verbatim. 68Any other character following a backslash is output verbatim.
170.sp 69.sp
171The valid parameters are: 70The valid parameters are:
172.RS 8
173.TP 71.TP
174\fBdebug\fR=\fIN\fR 72\fBdebug\fR=\fIN\fR
175Set debugging level. \fIN\fR is a decimal number. 73Set debugging level. \fIN\fR is a decimal number.
@@ -208,30 +106,71 @@ Database user name.
208.TP 106.TP
209\fBpassword\fR=\fISTRING\fR 107\fBpassword\fR=\fISTRING\fR
210Password to access the database. 108Password to access the database.
211.RE 109.PP
110Once configured, the \fBrewrite\fR function can be called in the
111appropriate place of the Varnish configuration file. Its argument
112\fIargs\fR is a list of variable assignments separated with
113semicolons, similarly to the \fIparams\fR argument described above.
114Each assignment has the form \fINAME\fB=\fIVALUE\fR. When called
115the function expands the \fBSQL\fR query, supplied with the \fIquery\fR
116argument to the \fBconfig\fR call, by replacing each \fB$\fINAME\fR
117construct (a \fBvariable reference\fR) with the corresponding
118\fIVALUE\fR from its argument. Similarly to the shell syntax, the
119variable reference can be written as \fB${\fINAME\fB}\fR. This latter
120form can be used in contexts where the variable name is immediately
121followed by another letter, to prevent it from being counted as a part
122of the name.
123.PP
124The expanded query is then sent to the database server. The handling
125of the return value depends on the number of fields it contains.
126.SS Strict matches
127If the returned set consists of one or two columns, only the
128first tuple is used and the value of its first column is returned.
129The second column (if present) is ignored.
130.SS Regexp matches
131Otherwise, if the returned set consists of three or four columns, the
132columns are interpreted as follows: \fBresult\fR, \fBregexp\fR,
133\fBvalue\fR and optional \fBflags\fR. For each returned tuple, the
134\fBvalue\fR column undergoes variable expansion, using the same
135algorithm as when preparing the query, and the resulting string is
136matched with the \fBregexp\fR column, which is treated as an extended
137\fBPOSIX\fR regular expression. If the match occurs, the \fBresult\fR
138column is expanded by replacing \fBbackreferences\fR. Each occurrence
139of \fB$\fIDIGIT\fR (where \fIDIGIT\fR stands for a decimal digit from
140\fB0\fR through \fB9\fR) is replaced with the contents of the
141\fIDIGIT\fR's parenthesized subexpression in \fBregexp\fR. For
142compatibility with the traditional usage, the \fB\\\fIDIGIT\fR
143notation is also allowed. The resulting value is returned.
144.PP
145Optional \fBflags\fR column is a comma-separated list of flags that
146modify regular expression handling. The following flags are defined:
212.TP 147.TP
213.I QUERY 148.BR NC " or " nocase
214\fBSQL\fR query to use. It can contain variable references in the 149Trea