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