Commit cc0f22a6 authored by Geoff Simmons's avatar Geoff Simmons

Compile with -Werror, and some stylistic changes

parent eb556851
...@@ -46,10 +46,11 @@ ...@@ -46,10 +46,11 @@
/* pcreapi(3): /* pcreapi(3):
* *
* The first two-thirds of the vector is used to pass back captured substrings, * The first two-thirds of the vector is used to pass back captured
* each substring using a pair of integers. The remaining third of the vector is * substrings, each substring using a pair of integers. The remaining
* used as workspace by pcre_exec() while matching capturing subpatterns, and is * third of the vector is used as workspace by pcre_exec() while matching
* not available for passing back information. * capturing subpatterns, and is not available for passing back
* information.
*/ */
#define MAX_MATCHES 11 #define MAX_MATCHES 11
...@@ -150,13 +151,13 @@ get_ov(struct sess *sp, struct vmod_priv *priv_vcl, const int init) ...@@ -150,13 +151,13 @@ get_ov(struct sess *sp, struct vmod_priv *priv_vcl, const int init)
ov = tbl->sess[sp->id]; ov = tbl->sess[sp->id];
/* /*
* we need to make sure that we do not back-ref matches from a previous * we need to make sure that we do not back-ref matches from a
* session on the same sp->id, so check the xid and the worker ws just * previous session on the same sp->id, so check the xid and the
* in case we have non-unique xids (some versions of varnish3) * worker ws just in case we have non-unique xids (some versions
* of varnish3)
*/ */
if ((ov->xid != sp->xid) || if ((ov->xid != sp->xid) || (ov->ws != sp->wrk->ws))
(ov->ws != sp->wrk->ws))
init_ov(ov, sp); init_ov(ov, sp);
return (ov); return (ov);
...@@ -205,8 +206,8 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call, ...@@ -205,8 +206,8 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call,
{ {
vre_t *vre; vre_t *vre;
sess_ov *ov; sess_ov *ov;
int nov[MAX_OV]; int s, nov[MAX_OV];
int s; unsigned result;
size_t cp; size_t cp;
AN(pattern); AN(pattern);
...@@ -219,12 +220,15 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call, ...@@ -219,12 +220,15 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call,
/* /*
* should we cache here? * should we cache here?
* *
* if we wanted to use priv_call, we would need to run the match * if we wanted to use priv_call, we would need to run the
* under the lock or would need refcounting with delayed free. * match under the lock or would need refcounting with
* delayed free.
* *
* A real LRU/MFU pattern -> vre cache probably would be a better idea * A real LRU/MFU pattern -> vre cache probably would be a
* better idea
* *
* also, as long as we don't cache, we will always recompile a bad re * also, as long as we don't cache, we will always
* recompile a bad re
*/ */
int erroffset = 0; int erroffset = 0;
const char *error = NULL; const char *error = NULL;
...@@ -235,12 +239,14 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call, ...@@ -235,12 +239,14 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call,
"vmod re: error compiling dynamic regex \"%s\": " "vmod re: error compiling dynamic regex \"%s\": "
"%s (position %d)", pattern, error, "%s (position %d)", pattern, error,
erroffset); erroffset);
} else if (priv_call->priv) { }
else if (priv_call->priv) {
re_t *re; re_t *re;
CAST_OBJ(re, priv_call->priv, RE_MAGIC); CAST_OBJ(re, priv_call->priv, RE_MAGIC);
vre = re->vre; vre = re->vre;
} else { }
else {
re_t *re; re_t *re;
int erroffset = 0; int erroffset = 0;
const char *error = NULL; const char *error = NULL;
...@@ -250,27 +256,26 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call, ...@@ -250,27 +256,26 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call,
if (priv_call->priv) { if (priv_call->priv) {
CAST_OBJ(re, priv_call->priv, RE_MAGIC); CAST_OBJ(re, priv_call->priv, RE_MAGIC);
vre = re->vre; vre = re->vre;
goto unlock;
} }
else {
ALLOC_OBJ(re, RE_MAGIC); ALLOC_OBJ(re, RE_MAGIC);
XXXAN(re); XXXAN(re);
vre = VRE_compile(pattern, 0, &error, &erroffset); vre = VRE_compile(pattern, 0, &error, &erroffset);
if (vre == NULL) if (vre == NULL)
WSP(sp, SLT_VCL_error, WSP(sp, SLT_VCL_error,
"vmod re: error compiling regex \"%s\": " "vmod re: error compiling regex \"%s\": "
"%s (position %d)", pattern, error, "%s (position %d)", pattern, error,
erroffset); erroffset);
re->vre = vre; re->vre = vre;
/* /*
* make sure the re obj is complete before we commit * make sure the re obj is complete before we commit
* the pointer * the pointer
*/ */
VMB(); VMB();
priv_call->priv = re; priv_call->priv = re;
priv_call->free = free_re; priv_call->free = free_re;
unlock: }
AZ(pthread_mutex_unlock(&re_mutex)); AZ(pthread_mutex_unlock(&re_mutex));
} }
...@@ -294,35 +299,31 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call, ...@@ -294,35 +299,31 @@ match(struct sess *sp, struct vmod_priv *priv_vcl, struct vmod_priv *priv_call,
assert(sizeof(nov) == (sizeof(nov[0]) * MAX_OV)); assert(sizeof(nov) == (sizeof(nov[0]) * MAX_OV));
s = VRE_exec(vre, str, strlen(str), 0, 0, nov, s = VRE_exec(vre, str, strlen(str), 0, 0, nov,
MAX_OV, &params->vre_limits); MAX_OV, &params->vre_limits);
if (s < VRE_ERROR_NOMATCH) { if (s > VRE_ERROR_NOMATCH) {
WSP(sp, SLT_VCL_error, "vmod re: regex match returned %d", s); if (s == 0)
goto err; cp = sizeof(nov); /* ov overflow */
} else
if (s == VRE_ERROR_NOMATCH) cp = s * 2 * sizeof(*nov);
goto err;
ok:
if (s == 0)
cp = sizeof(nov); /* ov overflow */
else
cp = s * 2 * sizeof(*nov);
assert(cp <= sizeof(nov));
ov->subject = str; assert(cp <= sizeof(nov));
memcpy(ov->ovector, nov, cp);
ov->count = s;
if (dynamic) ov->subject = str;
VRE_free(&vre); memcpy(ov->ovector, nov, cp);
return 1; ov->count = s;
result = 1;
}
else {
if (s < VRE_ERROR_NOMATCH)
WSP(sp, SLT_VCL_error,
"vmod re: regex match returned %d", s);
result = 0;
}
err:
if (dynamic) if (dynamic)
VRE_free(&vre); VRE_free(&vre);
return 0; return result;
} }
unsigned __match_proto__() unsigned __match_proto__()
...@@ -343,7 +344,6 @@ const char * __match_proto__() ...@@ -343,7 +344,6 @@ const char * __match_proto__()
vmod_backref(struct sess *sp, struct vmod_priv *priv_vcl, int refnum, vmod_backref(struct sess *sp, struct vmod_priv *priv_vcl, int refnum,
const char *fallback) const char *fallback)
{ {
struct sess_tbl *tbl;
struct sess_ov *ov; struct sess_ov *ov;
char *substr; char *substr;
unsigned l; unsigned l;
...@@ -354,9 +354,12 @@ vmod_backref(struct sess *sp, struct vmod_priv *priv_vcl, int refnum, ...@@ -354,9 +354,12 @@ vmod_backref(struct sess *sp, struct vmod_priv *priv_vcl, int refnum,
ov = get_ov(sp, priv_vcl, 0); ov = get_ov(sp, priv_vcl, 0);
if ((ov == NULL) || if ((ov == NULL) || (ov->count < 0)) {
(ov->count < 0)) WSP(sp, SLT_VCL_error,
goto notinit; "vmod re: backref called without prior match in the "
"session");
return fallback;
}
AN(ov->subject); AN(ov->subject);
...@@ -372,12 +375,6 @@ vmod_backref(struct sess *sp, struct vmod_priv *priv_vcl, int refnum, ...@@ -372,12 +375,6 @@ vmod_backref(struct sess *sp, struct vmod_priv *priv_vcl, int refnum,
} }
WS_Release(sp->wrk->ws, s + 1); WS_Release(sp->wrk->ws, s + 1);
return substr; return substr;
notinit:
WSP(sp, SLT_VCL_error,
"vmod re: backref called without prior match in the "
"session");
return fallback;
} }
const char * __match_proto__() const char * __match_proto__()
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment