aboutsummaryrefslogtreecommitdiff
path: root/src/vmod_dbrw.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/vmod_dbrw.c')
-rw-r--r--src/vmod_dbrw.c41
1 files changed, 21 insertions, 20 deletions
diff --git a/src/vmod_dbrw.c b/src/vmod_dbrw.c
index f7723a2..284376f 100644
--- a/src/vmod_dbrw.c
+++ b/src/vmod_dbrw.c
@@ -19,7 +19,8 @@
#include "wordsplit.h"
#include "vrt.h"
#include "vcc_if.h"
-#include "bin/varnishd/cache.h"
+#include "pthread.h"
+#include "bin/varnishd/cache/cache.h"
static pthread_once_t thread_once = PTHREAD_ONCE_INIT;
static pthread_key_t thread_key;
@@ -202,9 +203,9 @@ parse_flags(const char *arg, int *qdisp, int *flags, char status[])
debug=N
QUERY - Query to obtain the redirection target
*/
-void
-vmod_config(struct sess *sp, struct vmod_priv *priv, const char *bkname,
- const char *param, const char *query)
+VCL_VOID
+vmod_config(const struct vrt_ctx *ctx, struct vmod_priv *priv,
+ VCL_STRING bkname, VCL_STRING param, VCL_STRING query)
{
char *s;
struct wordsplit ws;
@@ -260,18 +261,18 @@ vmod_config(struct sess *sp, struct vmod_priv *priv, const char *bkname,
}
static char *
-expand_backref(struct sess *sp, const char *str, const char *val,
+expand_backref(const struct vrt_ctx *ctx, const char *str, const char *val,
size_t matchcount, regmatch_t *matches, char *qry)
{
unsigned u;
char *b, *p;
- u = WS_Reserve(sp->wrk->ws, 0);
- p = b = sp->wrk->ws->f;
+ u = WS_Reserve(ctx->ws, 0);
+ p = b = ctx->ws->f;
while (*val) {
if (u == 0) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
}
if (*val == '\\' || *val == '$') {
@@ -284,7 +285,7 @@ expand_backref(struct sess *sp, const char *str, const char *val,
matches[n].rm_so;
if (len > u) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
}
@@ -310,7 +311,7 @@ expand_backref(struct sess *sp, const char *str, const char *val,
if (qry) {
size_t len = strlen(qry);
if (len + 1 >= u) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
}
if (strchr(b, '?'))
@@ -323,12 +324,12 @@ expand_backref(struct sess *sp, const char *str, const char *val,
}
if (u == 0) {
- WS_Release(sp->wrk->ws, 0);
+ WS_Release(ctx->ws, 0);
return NULL;
}
*p = 0;
- WS_ReleaseP(sp->wrk->ws, p);
+ WS_ReleaseP(ctx->ws, p);
return b;
}
@@ -336,7 +337,7 @@ expand_backref(struct sess *sp, const char *str, const char *val,
#define ISEMPTY(s) ((s) == NULL || (s)[0] == 0)
static char *
-findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
+findmatch(const struct vrt_ctx *ctx, struct dbrw_connection *conn, char **param)
{
unsigned i;
unsigned nt, nf;
@@ -353,7 +354,7 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
debug(conn->conf, 2, ("query returned %u tuples, %u columns", nt, nf));
if (nf < 3)
- return WS_Dup(sp->ws, sql_get_column(conn, 0, 0));
+ return WS_Copy(ctx->ws, sql_get_column(conn, 0, 0), -1);
/* Three or four fields:
result
@@ -375,7 +376,7 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
char *qry = NULL;
if (ISEMPTY(pat)) {
- res = WS_Dup(sp->ws, sql_get_column(conn, i, 0));
+ res = WS_Copy(ctx->ws, sql_get_column(conn, i, 0), -1);
break;
}
@@ -442,7 +443,7 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
rc = regexec(&re, val, matchcount, conn->matches, 0);
if (rc == 0)
- res = expand_backref(sp, val,
+ res = expand_backref(ctx, val,
sql_get_column(conn, i, 0),
matchcount, conn->matches, qry);
@@ -452,7 +453,7 @@ findmatch(struct sess *sp, struct dbrw_connection *conn, char **param)
if (status[0]) {
debug(conn->conf, 1,
("setting status %s", status));
- VRT_SetHdr(sp, HDR_REQ,
+ VRT_SetHdr(ctx, HDR_REQ,
"\023X-VMOD-DBRW-Status:",
status,
vrt_magic_string_end);
@@ -496,8 +497,8 @@ get_connection(struct dbrw_config *conf)
return cp;
}
-const char *
-vmod_rewrite(struct sess *sp, struct vmod_priv *priv, const char *arg)
+VCL_STRING
+vmod_rewrite(const struct vrt_ctx *ctx, struct vmod_priv *priv, VCL_STRING arg)
{
struct dbrw_config *conf = priv->priv;
struct dbrw_connection *cp;
@@ -564,7 +565,7 @@ vmod_rewrite(struct sess *sp, struct vmod_priv *priv, const char *arg)
return NULL;
}
- res = findmatch(sp, cp, wsenv.ws_wordv);
+ res = findmatch(ctx, cp, wsenv.ws_wordv);
wordsplit_free(&wsenv);
sql_free_result(cp);

Return to:

Send suggestions and report system problems to the System administrator.