mirror of
https://git.haproxy.org/git/haproxy.git/
synced 2025-09-22 06:11:32 +02:00
MINOR: payload: split smp_fetch_rdp_cookie()
This function is also called directly from backend.c, so let's stop building fake args to call it as a sample fetch, and have a lower layer more generic function instead.
This commit is contained in:
parent
ef38c39287
commit
cadd8c9ec3
@ -23,12 +23,10 @@
|
||||
#define _PROTO_PROTO_PAYLOAD_H
|
||||
|
||||
#include <common/config.h>
|
||||
#include <types/arg.h>
|
||||
#include <types/proxy.h>
|
||||
#include <types/sample.h>
|
||||
#include <types/session.h>
|
||||
|
||||
int smp_fetch_rdp_cookie(struct proxy *px, struct session *s, void *l7, unsigned int opt, const struct arg *args, struct sample *smp, const char *kw);
|
||||
int fetch_rdp_cookie_name(struct session *s, struct sample *smp, const char *cname, int clen);
|
||||
|
||||
#endif /* _PROTO_PROTO_PAYLOAD_H */
|
||||
|
||||
|
@ -408,7 +408,6 @@ struct server *get_server_rch(struct session *s)
|
||||
const char *p;
|
||||
int ret;
|
||||
struct sample smp;
|
||||
struct arg args[2];
|
||||
int rewind;
|
||||
|
||||
/* tot_weight appears to mean srv_count */
|
||||
@ -417,14 +416,9 @@ struct server *get_server_rch(struct session *s)
|
||||
|
||||
memset(&smp, 0, sizeof(smp));
|
||||
|
||||
args[0].type = ARGT_STR;
|
||||
args[0].data.str.str = px->hh_name;
|
||||
args[0].data.str.len = px->hh_len;
|
||||
args[1].type = ARGT_STOP;
|
||||
|
||||
b_rew(s->req->buf, rewind = s->req->buf->o);
|
||||
|
||||
ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp, NULL);
|
||||
ret = fetch_rdp_cookie_name(s, &smp, px->hh_name, px->hh_len);
|
||||
len = smp.data.str.len;
|
||||
|
||||
b_adv(s->req->buf, rewind);
|
||||
@ -1111,7 +1105,6 @@ int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit)
|
||||
struct server *srv = px->srv;
|
||||
struct sockaddr_in addr;
|
||||
char *p;
|
||||
struct arg args[2];
|
||||
|
||||
DPRINTF(stderr,"[%u] %s: session=%p b=%p, exp(r,w)=%u,%u bf=%08x bh=%d analysers=%02x\n",
|
||||
now_ms, __FUNCTION__,
|
||||
@ -1127,12 +1120,7 @@ int tcp_persist_rdp_cookie(struct session *s, struct channel *req, int an_bit)
|
||||
|
||||
memset(&smp, 0, sizeof(smp));
|
||||
|
||||
args[0].type = ARGT_STR;
|
||||
args[0].data.str.str = s->be->rdp_cookie_name;
|
||||
args[0].data.str.len = s->be->rdp_cookie_len;
|
||||
args[1].type = ARGT_STOP;
|
||||
|
||||
ret = smp_fetch_rdp_cookie(px, s, NULL, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, args, &smp, NULL);
|
||||
ret = fetch_rdp_cookie_name(s, &smp, s->be->rdp_cookie_name, s->be->rdp_cookie_len);
|
||||
if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || smp.data.str.len == 0)
|
||||
goto no_cookie;
|
||||
|
||||
|
@ -394,14 +394,12 @@ smp_fetch_ssl_hello_sni(struct proxy *px, struct session *s, void *l7, unsigned
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fetch the request RDP cookie identified in the args, or any cookie if no arg
|
||||
* is passed. It is usable both for ACL and for samples. Note: this decoder
|
||||
* only works with non-wrapping data. Accepts either 0 or 1 argument. Argument
|
||||
* is a string (cookie name), other types will lead to undefined behaviour.
|
||||
/* Fetch the request RDP cookie identified in <cname>:<clen>, or any cookie if
|
||||
* <clen> is empty (cname is then ignored). It returns the data into sample <smp>.
|
||||
* Note: this decoder only works with non-wrapping data.
|
||||
*/
|
||||
int
|
||||
smp_fetch_rdp_cookie(struct proxy *px, struct session *s, void *l7, unsigned int opt,
|
||||
const struct arg *args, struct sample *smp, const char *kw)
|
||||
fetch_rdp_cookie_name(struct session *s, struct sample *smp, const char *cname, int clen)
|
||||
{
|
||||
int bleft;
|
||||
const unsigned char *data;
|
||||
@ -433,17 +431,16 @@ smp_fetch_rdp_cookie(struct proxy *px, struct session *s, void *l7, unsigned int
|
||||
bleft--;
|
||||
}
|
||||
|
||||
if (args) {
|
||||
|
||||
if (bleft <= args->data.str.len)
|
||||
if (clen) {
|
||||
if (bleft <= clen)
|
||||
goto too_short;
|
||||
|
||||
if ((data[args->data.str.len] != '=') ||
|
||||
strncasecmp(args->data.str.str, (const char *)data, args->data.str.len) != 0)
|
||||
if ((data[clen] != '=') ||
|
||||
strncasecmp(cname, (const char *)data, clen) != 0)
|
||||
goto not_cookie;
|
||||
|
||||
data += args->data.str.len + 1;
|
||||
bleft -= args->data.str.len + 1;
|
||||
data += clen + 1;
|
||||
bleft -= clen + 1;
|
||||
} else {
|
||||
while (bleft > 0 && *data != '=') {
|
||||
if (*data == '\r' || *data == '\n')
|
||||
@ -487,6 +484,18 @@ smp_fetch_rdp_cookie(struct proxy *px, struct session *s, void *l7, unsigned int
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Fetch the request RDP cookie identified in the args, or any cookie if no arg
|
||||
* is passed. It is usable both for ACL and for samples. Note: this decoder
|
||||
* only works with non-wrapping data. Accepts either 0 or 1 argument. Argument
|
||||
* is a string (cookie name), other types will lead to undefined behaviour.
|
||||
*/
|
||||
int
|
||||
smp_fetch_rdp_cookie(struct proxy *px, struct session *s, void *l7, unsigned int opt,
|
||||
const struct arg *args, struct sample *smp, const char *kw)
|
||||
{
|
||||
return fetch_rdp_cookie_name(s, smp, args ? args->data.str.str : NULL, args ? args->data.str.len : 0);
|
||||
}
|
||||
|
||||
/* returns either 1 or 0 depending on whether an RDP cookie is found or not */
|
||||
static int
|
||||
smp_fetch_rdp_cookie_cnt(struct proxy *px, struct session *s, void *l7, unsigned int opt,
|
||||
|
Loading…
x
Reference in New Issue
Block a user