MEDIUM/CLEANUP: http: rewrite and lighten http_transform_header() prototype

The http_transform_header() function prototype uses some parameter
which can be guessed from other parameer. This patch removes
theses parameters.
This commit is contained in:
Thierry FOURNIER 2015-03-16 23:54:35 +01:00 committed by Willy Tarreau
parent 191f9efdc5
commit 5a33ac78ad

View File

@ -3246,12 +3246,16 @@ static inline void inet_set_tos(int fd, struct sockaddr_storage from, int tos)
#endif #endif
} }
static int http_transform_header(struct session* s, struct http_msg *msg, const char* name, uint name_len, static int http_transform_header(struct session* s, struct http_msg *msg,
char* buf, struct hdr_idx* idx, struct list *fmt, struct my_regex *re, const char* name, unsigned int name_len,
struct hdr_ctx* ctx, int action) struct list *fmt, struct my_regex *re,
int action)
{ {
int (*http_find_hdr_func)(const char *name, int len, char *sol, int (*http_find_hdr_func)(const char *name, int len, char *sol,
struct hdr_idx *idx, struct hdr_ctx *ctx); struct hdr_idx *idx, struct hdr_ctx *ctx);
struct hdr_ctx ctx;
char *buf = msg->chn->buf->p;
struct hdr_idx *idx = &s->txn.hdr_idx;
struct chunk *replace = get_trash_chunk(); struct chunk *replace = get_trash_chunk();
struct chunk *output = get_trash_chunk(); struct chunk *output = get_trash_chunk();
@ -3259,7 +3263,7 @@ static int http_transform_header(struct session* s, struct http_msg *msg, const
if (replace->len >= replace->size - 1) if (replace->len >= replace->size - 1)
return -1; return -1;
ctx->idx = 0; ctx.idx = 0;
/* Choose the header browsing function. */ /* Choose the header browsing function. */
switch (action) { switch (action) {
@ -3275,11 +3279,11 @@ static int http_transform_header(struct session* s, struct http_msg *msg, const
return -1; return -1;
} }
while (http_find_hdr_func(name, name_len, buf, idx, ctx)) { while (http_find_hdr_func(name, name_len, buf, idx, &ctx)) {
struct hdr_idx_elem *hdr = idx->v + ctx->idx; struct hdr_idx_elem *hdr = idx->v + ctx.idx;
int delta; int delta;
char *val = ctx->line + ctx->val; char *val = ctx.line + ctx.val;
char* val_end = val + ctx->vlen; char* val_end = val + ctx.vlen;
if (!regex_exec_match2(re, val, val_end-val, MAX_MATCH, pmatch, 0)) if (!regex_exec_match2(re, val, val_end-val, MAX_MATCH, pmatch, 0))
continue; continue;
@ -3294,7 +3298,7 @@ static int http_transform_header(struct session* s, struct http_msg *msg, const
http_msg_move_end(msg, delta); http_msg_move_end(msg, delta);
/* Adjust the length of the current value of the index. */ /* Adjust the length of the current value of the index. */
ctx->vlen += delta; ctx.vlen += delta;
} }
return 0; return 0;
@ -3402,9 +3406,10 @@ resume_execution:
case HTTP_REQ_ACT_REPLACE_HDR: case HTTP_REQ_ACT_REPLACE_HDR:
case HTTP_REQ_ACT_REPLACE_VAL: case HTTP_REQ_ACT_REPLACE_VAL:
if (http_transform_header(s, &txn->req, rule->arg.hdr_add.name, rule->arg.hdr_add.name_len, if (http_transform_header(s, &txn->req, rule->arg.hdr_add.name,
txn->req.chn->buf->p, &txn->hdr_idx, &rule->arg.hdr_add.fmt, rule->arg.hdr_add.name_len,
&rule->arg.hdr_add.re, &ctx, rule->action)) &rule->arg.hdr_add.fmt,
&rule->arg.hdr_add.re, rule->action))
return HTTP_RULE_RES_BADREQ; return HTTP_RULE_RES_BADREQ;
break; break;
@ -3648,9 +3653,10 @@ resume_execution:
case HTTP_RES_ACT_REPLACE_HDR: case HTTP_RES_ACT_REPLACE_HDR:
case HTTP_RES_ACT_REPLACE_VAL: case HTTP_RES_ACT_REPLACE_VAL:
if (http_transform_header(s, &txn->rsp, rule->arg.hdr_add.name, rule->arg.hdr_add.name_len, if (http_transform_header(s, &txn->rsp, rule->arg.hdr_add.name,
txn->rsp.chn->buf->p, &txn->hdr_idx, &rule->arg.hdr_add.fmt, rule->arg.hdr_add.name_len,
&rule->arg.hdr_add.re, &ctx, rule->action)) &rule->arg.hdr_add.fmt,
&rule->arg.hdr_add.re, rule->action))
return HTTP_RULE_RES_STOP; /* note: we should report an error here */ return HTTP_RULE_RES_STOP; /* note: we should report an error here */
break; break;