path: root/src/dbrw.h
authorSergey Poznyakoff <>2016-04-21 13:23:35 (GMT)
committer Sergey Poznyakoff <>2016-04-21 13:47:22 (GMT)
commitb5f2337ad45d26941bf533741d8bff1238d59b5d (patch) (side-by-side diff)
tree878a65c333272ceb198ec0d8e871e431f8015f7a /src/dbrw.h
parent5ee1409fc878cd65dd224ec5f709507e37e9ed5d (diff)
Rewrite SQL configuration support.
Multiple configurations can be provided, by calling dbrw.config from branches of a conditional VCL statement. The only requirement is that exactly one dbrw.config is executed within a single HTTP session. This allows the user to select rewrite data from various databases depending on some conditions. Open SQL connections are stored in a pool and reused as needed. So far no limit on the number of connections is imposed. This is a TODO. Connections remain open during the lifetime of the module (i.e. for as long as varnish is not restarted). * src/dbrw.h (dbrw_config): New members: param_str, magic and list. (dbrw_connection): New members: magic, busy, list. * src/vmod_dbrw.c (dbrw_connection_get) (dbrw_connection_release): New functions. (dbrw_event): Install atexit function. (vmod_config): Keep a pool of configurations. (dbrw_sethdr) [VARNISHVERSION]: Remove leftover code. (vmod_rewrite): Rewrite. * src/vmod_dbrw.vcc (config, rewrite): Mark as PRIV_TASK. * doc/vmod-dbrw.3: Update docs. * doc/vmod-dbrw.texi: Update docs. * Raise version number
Diffstat (limited to 'src/dbrw.h') (more/less context) (ignore whitespace changes)
1 files changed, 14 insertions, 0 deletions
diff --git a/src/dbrw.h b/src/dbrw.h
index 855720a..2156e0b 100644
--- a/src/dbrw.h
+++ b/src/dbrw.h
@@ -21,6 +21,12 @@
#include <syslog.h>
#include <regex.h>
+#include "vcl.h"
+#include "vrt.h"
+#include "vcc_if.h"
+#include "bin/varnishd/cache/cache.h"
+#define WSPTR(s) ((s)->ws)
struct dbrw_connection;
struct dbrw_backend {
@@ -50,21 +56,29 @@ enum {
struct dbrw_config {
+ unsigned magic;
+#define DBRW_CONFIG_MAGIC 0x67636667
int debug_level;
struct dbrw_backend *backend;
char **param;
+ char *param_str;
char *query;
int qdisp;
int regflags;
char status[HTTP_STATUS_LEN+1];
+ VTAILQ_ENTRY(dbrw_config) list;
struct dbrw_connection {
+ unsigned magic;
+#define DBRW_CONNECTION_MAGIC 0x6773716c
int state; /* Connection state */
+ int busy:1;
struct dbrw_config *conf; /* Pointer to the configuration data */
regmatch_t *matches; /* Match map */
size_t matchsize; /* Total number of entries in match map */
void *data; /* Backend-specific data */
+ VTAILQ_ENTRY(dbrw_connection) list;
void dbrw_debug(const char *fmt, ...);

Return to:

Send suggestions and report system problems to the System administrator.