From: Thierry FOURNIER Date: Wed, 19 Aug 2015 07:00:18 +0000 (+0200) Subject: MEDIUM: samples: Use the "struct sample_data" in the "struct sample" X-Git-Tag: v1.6-dev4~58 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=8c542cac07781f8793ea8aaf5eaece789d064fe8;p=thirdparty%2Fhaproxy.git MEDIUM: samples: Use the "struct sample_data" in the "struct sample" This patch remove the struct information stored both in the struct sample_data and in the striuct sample. Now, only thestruct sample_data contains data, and the struct sample use the struct sample_data for storing his own data. --- diff --git a/include/proto/sample.h b/include/proto/sample.h index 6a01ed3307..bcdd23baac 100644 --- a/include/proto/sample.h +++ b/include/proto/sample.h @@ -56,11 +56,11 @@ int smp_dup(struct sample *smp); static inline int sample_convert(struct sample *sample, int req_type) { - if (!sample_casts[sample->type][req_type]) + if (!sample_casts[sample->data.type][req_type]) return 0; - if (sample_casts[sample->type][req_type] == c_none) + if (sample_casts[sample->data.type][req_type] == c_none) return 1; - return sample_casts[sample->type][req_type](sample); + return sample_casts[sample->data.type][req_type](sample); } #endif /* _PROTO_SAMPLE_H */ diff --git a/include/types/sample.h b/include/types/sample.h index f34cf17157..10b941b009 100644 --- a/include/types/sample.h +++ b/include/types/sample.h @@ -242,11 +242,8 @@ struct meth { struct chunk str; }; -/* a sample is a typed data extracted from a stream. It has a type, contents, - * validity constraints, a context for use in iterative calls. - */ -struct sample { - unsigned int flags; /* SMP_F_* */ +/* Used to store sample constant */ +struct sample_data { int type; /* SMP_T_* */ union { long long int sint; /* used for signed 64bits integers */ @@ -255,6 +252,14 @@ struct sample { struct chunk str; /* used for char strings or buffers */ struct meth meth; /* used for http method */ } data; /* sample data */ +}; + +/* a sample is a typed data extracted from a stream. It has a type, contents, + * validity constraints, a context for use in iterative calls. + */ +struct sample { + unsigned int flags; /* SMP_F_* */ + struct sample_data data; union smp_ctx ctx; /* Some sample analyzer (sample-fetch or converters) needs to @@ -268,18 +273,6 @@ struct sample { unsigned int opt; /* fetch options (SMP_OPT_*) */ }; -/* Used to store sample constant */ -struct sample_data { - int type; /* SMP_T_* */ - union { - long long int sint; /* used for signed 64bits integers */ - struct in_addr ipv4; /* used for ipv4 addresses */ - struct in6_addr ipv6; /* used for ipv6 addresses */ - struct chunk str; /* used for char strings or buffers */ - struct meth meth; /* used for http method */ - } data; /* sample data */ -}; - /* Descriptor for a sample conversion */ struct sample_conv { const char *kw; /* configuration keyword */ diff --git a/src/auth.c b/src/auth.c index 8b7d268a52..7f6ad0aa1c 100644 --- a/src/auth.c +++ b/src/auth.c @@ -276,7 +276,7 @@ pat_match_auth(struct sample *smp, struct pattern_expr *expr, int fill) /* Browse the userlist for searching user. */ for (u = ul->users; u; u = u->next) { - if (strcmp(smp->data.str.str, u->user) == 0) + if (strcmp(smp->data.data.str.str, u->user) == 0) break; } if (!u) diff --git a/src/backend.c b/src/backend.c index 9e8e9b6968..adfd38824e 100644 --- a/src/backend.c +++ b/src/backend.c @@ -476,7 +476,7 @@ struct server *get_server_rch(struct stream *s) b_rew(s->req.buf, rewind = s->req.buf->o); ret = fetch_rdp_cookie_name(s, &smp, px->hh_name, px->hh_len); - len = smp.data.str.len; + len = smp.data.data.str.len; b_adv(s->req.buf, rewind); @@ -490,7 +490,7 @@ struct server *get_server_rch(struct stream *s) /* Found a the hh_name in the headers. * we will compute the hash based on this value ctx.val. */ - hash = gen_hash(px, smp.data.str.str, len); + hash = gen_hash(px, smp.data.data.str.str, len); if ((px->lbprm.algo & BE_LB_HASH_MOD) == BE_LB_HMOD_AVAL) hash = full_hash(hash); @@ -1218,10 +1218,10 @@ int connect_server(struct stream *s) if (smp) { /* get write access to terminate with a zero */ smp_dup(smp); - if (smp->data.str.len >= smp->data.str.size) - smp->data.str.len = smp->data.str.size - 1; - smp->data.str.str[smp->data.str.len] = 0; - ssl_sock_set_servername(srv_conn, smp->data.str.str); + if (smp->data.data.str.len >= smp->data.data.str.size) + smp->data.data.str.len = smp->data.data.str.size - 1; + smp->data.data.str.str[smp->data.data.str.len] = 0; + ssl_sock_set_servername(srv_conn, smp->data.data.str.str); srv_conn->flags |= CO_FL_PRIVATE; } } @@ -1361,14 +1361,14 @@ int tcp_persist_rdp_cookie(struct stream *s, struct channel *req, int an_bit) memset(&smp, 0, sizeof(smp)); 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) + if (ret == 0 || (smp.flags & SMP_F_MAY_CHANGE) || smp.data.data.str.len == 0) goto no_cookie; memset(&addr, 0, sizeof(addr)); addr.sin_family = AF_INET; /* Considering an rdp cookie detected using acl, str ended with and should return */ - addr.sin_addr.s_addr = strtoul(smp.data.str.str, &p, 10); + addr.sin_addr.s_addr = strtoul(smp.data.data.str.str, &p, 10); if (*p != '.') goto no_cookie; p++; @@ -1602,15 +1602,15 @@ smp_fetch_nbsrv(const struct arg *args, struct sample *smp, const char *kw, void struct proxy *px; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; + smp->data.type = SMP_T_SINT; px = args->data.prx; if (px->srv_act) - smp->data.sint = px->srv_act; + smp->data.data.sint = px->srv_act; else if (px->lbprm.fbck) - smp->data.sint = 1; + smp->data.data.sint = 1; else - smp->data.sint = px->srv_bck; + smp->data.data.sint = px->srv_bck; return 1; } @@ -1626,12 +1626,12 @@ smp_fetch_srv_is_up(const struct arg *args, struct sample *smp, const char *kw, struct server *srv = args->data.srv; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_BOOL; + smp->data.type = SMP_T_BOOL; if (!(srv->admin & SRV_ADMF_MAINT) && (!(srv->check.state & CHK_ST_CONFIGURED) || (srv->state != SRV_ST_STOPPED))) - smp->data.sint = 1; + smp->data.data.sint = 1; else - smp->data.sint = 0; + smp->data.data.sint = 0; return 1; } @@ -1645,8 +1645,8 @@ smp_fetch_connslots(const struct arg *args, struct sample *smp, const char *kw, struct server *iterator; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; for (iterator = args->data.prx->srv; iterator; iterator = iterator->next) { if (iterator->state == SRV_ST_STOPPED) @@ -1654,11 +1654,11 @@ smp_fetch_connslots(const struct arg *args, struct sample *smp, const char *kw, if (iterator->maxconn == 0 || iterator->maxqueue == 0) { /* configuration is stupid */ - smp->data.sint = -1; /* FIXME: stupid value! */ + smp->data.data.sint = -1; /* FIXME: stupid value! */ return 1; } - smp->data.sint += (iterator->maxconn - iterator->cur_sess) + smp->data.data.sint += (iterator->maxconn - iterator->cur_sess) + (iterator->maxqueue - iterator->nbpend); } @@ -1670,8 +1670,8 @@ static int smp_fetch_be_id(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TXN; - smp->type = SMP_T_SINT; - smp->data.sint = smp->strm->be->uuid; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = smp->strm->be->uuid; return 1; } @@ -1682,8 +1682,8 @@ smp_fetch_srv_id(const struct arg *args, struct sample *smp, const char *kw, voi if (!objt_server(smp->strm->target)) return 0; - smp->type = SMP_T_SINT; - smp->data.sint = objt_server(smp->strm->target)->puid; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = objt_server(smp->strm->target)->puid; return 1; } @@ -1696,8 +1696,8 @@ static int smp_fetch_be_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = read_freq_ctr(&args->data.prx->be_sess_per_sec); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = read_freq_ctr(&args->data.prx->be_sess_per_sec); return 1; } @@ -1709,8 +1709,8 @@ static int smp_fetch_be_conn(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = args->data.prx->beconn; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = args->data.prx->beconn; return 1; } @@ -1722,8 +1722,8 @@ static int smp_fetch_queue_size(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = args->data.prx->totpend; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = args->data.prx->totpend; return 1; } @@ -1742,7 +1742,7 @@ smp_fetch_avg_queue_size(const struct arg *args, struct sample *smp, const char struct proxy *px; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; + smp->data.type = SMP_T_SINT; px = args->data.prx; if (px->srv_act) @@ -1753,9 +1753,9 @@ smp_fetch_avg_queue_size(const struct arg *args, struct sample *smp, const char nbsrv = px->srv_bck; if (nbsrv > 0) - smp->data.sint = (px->totpend + nbsrv - 1) / nbsrv; + smp->data.data.sint = (px->totpend + nbsrv - 1) / nbsrv; else - smp->data.sint = px->totpend * 2; + smp->data.data.sint = px->totpend * 2; return 1; } @@ -1768,8 +1768,8 @@ static int smp_fetch_srv_conn(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = args->data.srv->cur_sess; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = args->data.srv->cur_sess; return 1; } @@ -1781,8 +1781,8 @@ static int smp_fetch_srv_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = read_freq_ctr(&args->data.srv->sess_per_sec); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = read_freq_ctr(&args->data.srv->sess_per_sec); return 1; } diff --git a/src/compression.c b/src/compression.c index ec5ab33b95..eddf944c40 100644 --- a/src/compression.c +++ b/src/compression.c @@ -840,8 +840,8 @@ static int deflate_end(struct comp_ctx **comp_ctx) static int smp_fetch_res_comp(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_BOOL; - smp->data.sint = (smp->strm->comp_algo != NULL); + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = (smp->strm->comp_algo != NULL); return 1; } @@ -852,10 +852,10 @@ smp_fetch_res_comp_algo(const struct arg *args, struct sample *smp, const char * if (!smp->strm->comp_algo) return 0; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; - smp->data.str.str = smp->strm->comp_algo->cfg_name; - smp->data.str.len = smp->strm->comp_algo->cfg_name_len; + smp->data.data.str.str = smp->strm->comp_algo->cfg_name; + smp->data.data.str.len = smp->strm->comp_algo->cfg_name_len; return 1; } diff --git a/src/da.c b/src/da.c index 2b809e4434..a2e78c6d8f 100644 --- a/src/da.c +++ b/src/da.c @@ -147,8 +147,8 @@ static int da_haproxy(const struct arg *args, struct sample *smp, void *private) tmp = get_trash_chunk(); chunk_reset(tmp); - i = smp->data.str.len > sizeof(useragentbuf) ? sizeof(useragentbuf) : smp->data.str.len; - memcpy(useragentbuf, smp->data.str.str, i - 1); + i = smp->data.data.str.len > sizeof(useragentbuf) ? sizeof(useragentbuf) : smp->data.data.str.len; + memcpy(useragentbuf, smp->data.data.str.str, i - 1); useragentbuf[i - 1] = 0; useragent = (const char *)useragentbuf; @@ -211,8 +211,8 @@ static int da_haproxy(const struct arg *args, struct sample *smp, void *private) tmp->str[tmp->len] = 0; } - smp->data.str.str = tmp->str; - smp->data.str.len = strlen(tmp->str); + smp->data.data.str.str = tmp->str; + smp->data.data.str.len = strlen(tmp->str); return 1; } diff --git a/src/dumpstats.c b/src/dumpstats.c index ea53d25c9d..2d091af8c5 100644 --- a/src/dumpstats.c +++ b/src/dumpstats.c @@ -5633,10 +5633,10 @@ static int stats_map_lookup(struct stream_interface *si) chunk_reset(&trash); /* execute pattern matching */ - sample.type = SMP_T_STR; + sample.data.type = SMP_T_STR; sample.flags |= SMP_F_CONST; - sample.data.str.len = appctx->ctx.map.chunk.len; - sample.data.str.str = appctx->ctx.map.chunk.str; + sample.data.data.str.len = appctx->ctx.map.chunk.len; + sample.data.data.str.str = appctx->ctx.map.chunk.str; if (appctx->ctx.map.expr->pat_head->match && sample_convert(&sample, appctx->ctx.map.expr->pat_head->expect_type)) pat = appctx->ctx.map.expr->pat_head->match(&sample, appctx->ctx.map.expr, 1); diff --git a/src/frontend.c b/src/frontend.c index 83e8425641..9e64b38222 100644 --- a/src/frontend.c +++ b/src/frontend.c @@ -162,8 +162,8 @@ static int smp_fetch_fe_id(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_SESS; - smp->type = SMP_T_SINT; - smp->data.sint = smp->sess->fe->uuid; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = smp->sess->fe->uuid; return 1; } @@ -175,8 +175,8 @@ static int smp_fetch_fe_sess_rate(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = read_freq_ctr(&args->data.prx->fe_sess_per_sec); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = read_freq_ctr(&args->data.prx->fe_sess_per_sec); return 1; } @@ -188,8 +188,8 @@ static int smp_fetch_fe_conn(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = args->data.prx->feconn; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = args->data.prx->feconn; return 1; } diff --git a/src/hlua.c b/src/hlua.c index d3c968d1bf..c38e582d0d 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -382,19 +382,19 @@ static int hlua_lua2arg(lua_State *L, int ud, struct arg *arg) */ static int hlua_smp2lua(lua_State *L, struct sample *smp) { - switch (smp->type) { + switch (smp->data.type) { case SMP_T_SINT: case SMP_T_BOOL: - lua_pushinteger(L, smp->data.sint); + lua_pushinteger(L, smp->data.data.sint); break; case SMP_T_BIN: case SMP_T_STR: - lua_pushlstring(L, smp->data.str.str, smp->data.str.len); + lua_pushlstring(L, smp->data.data.str.str, smp->data.data.str.len); break; case SMP_T_METH: - switch (smp->data.meth.meth) { + switch (smp->data.data.meth.meth) { case HTTP_METH_OPTIONS: lua_pushstring(L, "OPTIONS"); break; case HTTP_METH_GET: lua_pushstring(L, "GET"); break; case HTTP_METH_HEAD: lua_pushstring(L, "HEAD"); break; @@ -404,7 +404,7 @@ static int hlua_smp2lua(lua_State *L, struct sample *smp) case HTTP_METH_TRACE: lua_pushstring(L, "TRACE"); break; case HTTP_METH_CONNECT: lua_pushstring(L, "CONNECT"); break; case HTTP_METH_OTHER: - lua_pushlstring(L, smp->data.meth.str.str, smp->data.meth.str.len); + lua_pushlstring(L, smp->data.data.meth.str.str, smp->data.data.meth.str.len); break; default: lua_pushnil(L); @@ -415,9 +415,9 @@ static int hlua_smp2lua(lua_State *L, struct sample *smp) case SMP_T_IPV4: case SMP_T_IPV6: case SMP_T_ADDR: /* This type is never used to qualify a sample. */ - if (sample_casts[smp->type][SMP_T_STR] && - sample_casts[smp->type][SMP_T_STR](smp)) - lua_pushlstring(L, smp->data.str.str, smp->data.str.len); + if (sample_casts[smp->data.type][SMP_T_STR] && + sample_casts[smp->data.type][SMP_T_STR](smp)) + lua_pushlstring(L, smp->data.data.str.str, smp->data.data.str.len); else lua_pushnil(L); break; @@ -434,15 +434,15 @@ static int hlua_smp2lua(lua_State *L, struct sample *smp) */ static int hlua_smp2lua_str(lua_State *L, struct sample *smp) { - switch (smp->type) { + switch (smp->data.type) { case SMP_T_BIN: case SMP_T_STR: - lua_pushlstring(L, smp->data.str.str, smp->data.str.len); + lua_pushlstring(L, smp->data.data.str.str, smp->data.data.str.len); break; case SMP_T_METH: - switch (smp->data.meth.meth) { + switch (smp->data.data.meth.meth) { case HTTP_METH_OPTIONS: lua_pushstring(L, "OPTIONS"); break; case HTTP_METH_GET: lua_pushstring(L, "GET"); break; case HTTP_METH_HEAD: lua_pushstring(L, "HEAD"); break; @@ -452,7 +452,7 @@ static int hlua_smp2lua_str(lua_State *L, struct sample *smp) case HTTP_METH_TRACE: lua_pushstring(L, "TRACE"); break; case HTTP_METH_CONNECT: lua_pushstring(L, "CONNECT"); break; case HTTP_METH_OTHER: - lua_pushlstring(L, smp->data.meth.str.str, smp->data.meth.str.len); + lua_pushlstring(L, smp->data.data.meth.str.str, smp->data.data.meth.str.len); break; default: lua_pushstring(L, ""); @@ -465,9 +465,9 @@ static int hlua_smp2lua_str(lua_State *L, struct sample *smp) case SMP_T_IPV4: case SMP_T_IPV6: case SMP_T_ADDR: /* This type is never used to qualify a sample. */ - if (sample_casts[smp->type][SMP_T_STR] && - sample_casts[smp->type][SMP_T_STR](smp)) - lua_pushlstring(L, smp->data.str.str, smp->data.str.len); + if (sample_casts[smp->data.type][SMP_T_STR] && + sample_casts[smp->data.type][SMP_T_STR](smp)) + lua_pushlstring(L, smp->data.data.str.str, smp->data.data.str.len); else lua_pushstring(L, ""); break; @@ -487,20 +487,20 @@ static int hlua_lua2smp(lua_State *L, int ud, struct sample *smp) switch (lua_type(L, ud)) { case LUA_TNUMBER: - smp->type = SMP_T_SINT; - smp->data.sint = lua_tointeger(L, ud); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = lua_tointeger(L, ud); break; case LUA_TBOOLEAN: - smp->type = SMP_T_BOOL; - smp->data.sint = lua_toboolean(L, ud); + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = lua_toboolean(L, ud); break; case LUA_TSTRING: - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; - smp->data.str.str = (char *)lua_tolstring(L, ud, (size_t *)&smp->data.str.len); + smp->data.data.str.str = (char *)lua_tolstring(L, ud, (size_t *)&smp->data.data.str.len); break; case LUA_TUSERDATA: @@ -509,8 +509,8 @@ static int hlua_lua2smp(lua_State *L, int ud, struct sample *smp) case LUA_TFUNCTION: case LUA_TTHREAD: case LUA_TLIGHTUSERDATA: - smp->type = SMP_T_BOOL; - smp->data.sint = 0; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = 0; break; } return 1; @@ -1369,13 +1369,13 @@ __LJMP static inline int _hlua_map_lookup(struct lua_State *L, int str) MAY_LJMP(check_args(L, 2, "lookup")); desc = MAY_LJMP(hlua_checkmap(L, 1)); if (desc->pat.expect_type == SMP_T_SINT) { - smp.type = SMP_T_SINT; - smp.data.sint = MAY_LJMP(luaL_checkinteger(L, 2)); + smp.data.type = SMP_T_SINT; + smp.data.data.sint = MAY_LJMP(luaL_checkinteger(L, 2)); } else { - smp.type = SMP_T_STR; + smp.data.type = SMP_T_STR; smp.flags = SMP_F_CONST; - smp.data.str.str = (char *)MAY_LJMP(luaL_checklstring(L, 2, (size_t *)&smp.data.str.len)); + smp.data.data.str.str = (char *)MAY_LJMP(luaL_checklstring(L, 2, (size_t *)&smp.data.data.str.len)); } pat = pattern_exec_match(&desc->pat, &smp, 1); @@ -2867,13 +2867,13 @@ __LJMP static int hlua_run_sample_conv(lua_State *L) } /* Apply expected cast. */ - if (!sample_casts[smp.type][conv->in_type]) { + if (!sample_casts[smp.data.type][conv->in_type]) { hlua_pusherror(L, "invalid input argument: cannot cast '%s' to '%s'", - smp_to_type[smp.type], smp_to_type[conv->in_type]); + smp_to_type[smp.data.type], smp_to_type[conv->in_type]); WILL_LJMP(lua_error(L)); } - if (sample_casts[smp.type][conv->in_type] != c_none && - !sample_casts[smp.type][conv->in_type](&smp)) { + if (sample_casts[smp.data.type][conv->in_type] != c_none && + !sample_casts[smp.data.type][conv->in_type](&smp)) { hlua_pusherror(L, "error during the input argument casting"); WILL_LJMP(lua_error(L)); } diff --git a/src/listener.c b/src/listener.c index 254907c95b..a2d1890e1e 100644 --- a/src/listener.c +++ b/src/listener.c @@ -593,8 +593,8 @@ void bind_dump_kws(char **out) static int smp_fetch_dconn(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_SINT; - smp->data.sint = smp->sess->listener->nbconn; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = smp->sess->listener->nbconn; return 1; } @@ -602,8 +602,8 @@ smp_fetch_dconn(const struct arg *args, struct sample *smp, const char *kw, void static int smp_fetch_so_id(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_SINT; - smp->data.sint = smp->sess->listener->luid; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = smp->sess->listener->luid; return 1; } diff --git a/src/log.c b/src/log.c index f80de2e75d..2a2d09ba21 100644 --- a/src/log.c +++ b/src/log.c @@ -993,9 +993,9 @@ int build_logline(struct stream *s, char *dst, size_t maxsize, struct list *list key = sample_fetch_as_type(be, sess, s, SMP_OPT_DIR_RES|SMP_OPT_FINAL, tmp->expr, SMP_T_STR); if (tmp->options & LOG_OPT_HTTP) ret = encode_chunk(tmplog, dst + maxsize, - '%', http_encode_map, key ? &key->data.str : &empty); + '%', http_encode_map, key ? &key->data.data.str : &empty); else - ret = lf_text_len(tmplog, key ? key->data.str.str : NULL, key ? key->data.str.len : 0, dst + maxsize - tmplog, tmp); + ret = lf_text_len(tmplog, key ? key->data.data.str.str : NULL, key ? key->data.data.str.len : 0, dst + maxsize - tmplog, tmp); if (ret == 0) goto out; tmplog = ret; diff --git a/src/map.c b/src/map.c index a03853d521..2a8f95c73e 100644 --- a/src/map.c +++ b/src/map.c @@ -161,15 +161,15 @@ static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *pr if (pat) { /* Copy sample. */ if (pat->data) { - smp->type = pat->data->type; + smp->data.type = pat->data->type; smp->flags |= SMP_F_CONST; - memcpy(&smp->data, &pat->data->data, sizeof(smp->data)); + memcpy(&smp->data.data, &pat->data->data, sizeof(smp->data.data)); return 1; } /* Return just int sample containing 1. */ - smp->type = SMP_T_SINT; - smp->data.sint = 1; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 1; return 1; } @@ -181,24 +181,24 @@ static int sample_conv_map(const struct arg *arg_p, struct sample *smp, void *pr switch (desc->conv->out_type) { case SMP_T_STR: - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; - smp->data.str = arg_p[1].data.str; + smp->data.data.str = arg_p[1].data.str; break; case SMP_T_SINT: - smp->type = SMP_T_SINT; - smp->data.sint = arg_p[1].data.sint; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = arg_p[1].data.sint; break; case SMP_T_IPV4: - smp->type = SMP_T_IPV4; - smp->data.ipv4 = arg_p[1].data.ipv4; + smp->data.type = SMP_T_IPV4; + smp->data.data.ipv4 = arg_p[1].data.ipv4; break; case SMP_T_IPV6: - smp->type = SMP_T_IPV6; - smp->data.ipv6 = arg_p[1].data.ipv6; + smp->data.type = SMP_T_IPV6; + smp->data.data.ipv6 = arg_p[1].data.ipv6; break; } diff --git a/src/pattern.c b/src/pattern.c index 297f45ff68..d91286e5d9 100644 --- a/src/pattern.c +++ b/src/pattern.c @@ -425,7 +425,7 @@ int pat_parse_ip(const char *text, struct pattern *pattern, int mflags, char **e /* always return false */ struct pattern *pat_match_nothing(struct sample *smp, struct pattern_expr *expr, int fill) { - if (smp->data.sint) { + if (smp->data.data.sint) { if (fill) { static_pattern.data = NULL; static_pattern.ref = NULL; @@ -454,12 +454,12 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int /* Lookup a string in the expression's pattern tree. */ if (!eb_is_empty(&expr->pattern_tree)) { /* we may have to force a trailing zero on the test pattern */ - prev = smp->data.str.str[smp->data.str.len]; + prev = smp->data.data.str.str[smp->data.data.str.len]; if (prev) - smp->data.str.str[smp->data.str.len] = '\0'; - node = ebst_lookup(&expr->pattern_tree, smp->data.str.str); + smp->data.data.str.str[smp->data.data.str.len] = '\0'; + node = ebst_lookup(&expr->pattern_tree, smp->data.data.str.str); if (prev) - smp->data.str.str[smp->data.str.len] = prev; + smp->data.data.str.str[smp->data.data.str.len] = prev; if (node) { if (fill) { @@ -478,7 +478,7 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int if (pat_lru_tree) { unsigned long long seed = pat_lru_seed ^ (long)expr; - lru = lru64_get(XXH64(smp->data.str.str, smp->data.str.len, seed), + lru = lru64_get(XXH64(smp->data.data.str.str, smp->data.data.str.len, seed), pat_lru_tree, expr, expr->revision); if (lru && lru->domain) return lru->data; @@ -487,12 +487,12 @@ struct pattern *pat_match_str(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if (pattern->len != smp->data.str.len) + if (pattern->len != smp->data.data.str.len) continue; icase = expr->mflags & PAT_MF_IGNORE_CASE; - if ((icase && strncasecmp(pattern->ptr.str, smp->data.str.str, smp->data.str.len) == 0) || - (!icase && strncmp(pattern->ptr.str, smp->data.str.str, smp->data.str.len) == 0)) { + if ((icase && strncasecmp(pattern->ptr.str, smp->data.data.str.str, smp->data.data.str.len) == 0) || + (!icase && strncmp(pattern->ptr.str, smp->data.data.str.str, smp->data.data.str.len) == 0)) { ret = pattern; break; } @@ -515,7 +515,7 @@ struct pattern *pat_match_bin(struct sample *smp, struct pattern_expr *expr, int if (pat_lru_tree) { unsigned long long seed = pat_lru_seed ^ (long)expr; - lru = lru64_get(XXH64(smp->data.str.str, smp->data.str.len, seed), + lru = lru64_get(XXH64(smp->data.data.str.str, smp->data.data.str.len, seed), pat_lru_tree, expr, expr->revision); if (lru && lru->domain) return lru->data; @@ -524,10 +524,10 @@ struct pattern *pat_match_bin(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if (pattern->len != smp->data.str.len) + if (pattern->len != smp->data.data.str.len) continue; - if (memcmp(pattern->ptr.str, smp->data.str.str, smp->data.str.len) == 0) { + if (memcmp(pattern->ptr.str, smp->data.data.str.str, smp->data.data.str.len) == 0) { ret = pattern; break; } @@ -552,7 +552,7 @@ struct pattern *pat_match_reg(struct sample *smp, struct pattern_expr *expr, int if (pat_lru_tree) { unsigned long long seed = pat_lru_seed ^ (long)expr; - lru = lru64_get(XXH64(smp->data.str.str, smp->data.str.len, seed), + lru = lru64_get(XXH64(smp->data.data.str.str, smp->data.data.str.len, seed), pat_lru_tree, expr, expr->revision); if (lru && lru->domain) return lru->data; @@ -561,7 +561,7 @@ struct pattern *pat_match_reg(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if (regex_exec2(pattern->ptr.reg, smp->data.str.str, smp->data.str.len)) { + if (regex_exec2(pattern->ptr.reg, smp->data.data.str.str, smp->data.data.str.len)) { ret = pattern; break; } @@ -588,12 +588,12 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int /* Lookup a string in the expression's pattern tree. */ if (!eb_is_empty(&expr->pattern_tree)) { /* we may have to force a trailing zero on the test pattern */ - prev = smp->data.str.str[smp->data.str.len]; + prev = smp->data.data.str.str[smp->data.data.str.len]; if (prev) - smp->data.str.str[smp->data.str.len] = '\0'; - node = ebmb_lookup_longest(&expr->pattern_tree, smp->data.str.str); + smp->data.data.str.str[smp->data.data.str.len] = '\0'; + node = ebmb_lookup_longest(&expr->pattern_tree, smp->data.data.str.str); if (prev) - smp->data.str.str[smp->data.str.len] = prev; + smp->data.data.str.str[smp->data.data.str.len] = prev; if (node) { if (fill) { @@ -612,7 +612,7 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int if (pat_lru_tree) { unsigned long long seed = pat_lru_seed ^ (long)expr; - lru = lru64_get(XXH64(smp->data.str.str, smp->data.str.len, seed), + lru = lru64_get(XXH64(smp->data.data.str.str, smp->data.data.str.len, seed), pat_lru_tree, expr, expr->revision); if (lru && lru->domain) return lru->data; @@ -621,12 +621,12 @@ struct pattern *pat_match_beg(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if (pattern->len > smp->data.str.len) + if (pattern->len > smp->data.data.str.len) continue; icase = expr->mflags & PAT_MF_IGNORE_CASE; - if ((icase && strncasecmp(pattern->ptr.str, smp->data.str.str, pattern->len) != 0) || - (!icase && strncmp(pattern->ptr.str, smp->data.str.str, pattern->len) != 0)) + if ((icase && strncasecmp(pattern->ptr.str, smp->data.data.str.str, pattern->len) != 0) || + (!icase && strncmp(pattern->ptr.str, smp->data.data.str.str, pattern->len) != 0)) continue; ret = pattern; @@ -651,7 +651,7 @@ struct pattern *pat_match_end(struct sample *smp, struct pattern_expr *expr, int if (pat_lru_tree) { unsigned long long seed = pat_lru_seed ^ (long)expr; - lru = lru64_get(XXH64(smp->data.str.str, smp->data.str.len, seed), + lru = lru64_get(XXH64(smp->data.data.str.str, smp->data.data.str.len, seed), pat_lru_tree, expr, expr->revision); if (lru && lru->domain) return lru->data; @@ -660,12 +660,12 @@ struct pattern *pat_match_end(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if (pattern->len > smp->data.str.len) + if (pattern->len > smp->data.data.str.len) continue; icase = expr->mflags & PAT_MF_IGNORE_CASE; - if ((icase && strncasecmp(pattern->ptr.str, smp->data.str.str + smp->data.str.len - pattern->len, pattern->len) != 0) || - (!icase && strncmp(pattern->ptr.str, smp->data.str.str + smp->data.str.len - pattern->len, pattern->len) != 0)) + if ((icase && strncasecmp(pattern->ptr.str, smp->data.data.str.str + smp->data.data.str.len - pattern->len, pattern->len) != 0) || + (!icase && strncmp(pattern->ptr.str, smp->data.data.str.str + smp->data.data.str.len - pattern->len, pattern->len) != 0)) continue; ret = pattern; @@ -694,7 +694,7 @@ struct pattern *pat_match_sub(struct sample *smp, struct pattern_expr *expr, int if (pat_lru_tree) { unsigned long long seed = pat_lru_seed ^ (long)expr; - lru = lru64_get(XXH64(smp->data.str.str, smp->data.str.len, seed), + lru = lru64_get(XXH64(smp->data.data.str.str, smp->data.data.str.len, seed), pat_lru_tree, expr, expr->revision); if (lru && lru->domain) return lru->data; @@ -703,13 +703,13 @@ struct pattern *pat_match_sub(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if (pattern->len > smp->data.str.len) + if (pattern->len > smp->data.data.str.len) continue; - end = smp->data.str.str + smp->data.str.len - pattern->len; + end = smp->data.data.str.str + smp->data.data.str.len - pattern->len; icase = expr->mflags & PAT_MF_IGNORE_CASE; if (icase) { - for (c = smp->data.str.str; c <= end; c++) { + for (c = smp->data.data.str.str; c <= end; c++) { if (tolower(*c) != tolower(*pattern->ptr.str)) continue; if (strncasecmp(pattern->ptr.str, c, pattern->len) == 0) { @@ -718,7 +718,7 @@ struct pattern *pat_match_sub(struct sample *smp, struct pattern_expr *expr, int } } } else { - for (c = smp->data.str.str; c <= end; c++) { + for (c = smp->data.data.str.str; c <= end; c++) { if (*c != *pattern->ptr.str) continue; if (strncmp(pattern->ptr.str, c, pattern->len) == 0) { @@ -759,13 +759,13 @@ static int match_word(struct sample *smp, struct pattern *pattern, int mflags, u while (pl > 0 && is_delimiter(ps[pl - 1], delimiters)) pl--; - if (pl > smp->data.str.len) + if (pl > smp->data.data.str.len) return PAT_NOMATCH; may_match = 1; icase = mflags & PAT_MF_IGNORE_CASE; - end = smp->data.str.str + smp->data.str.len - pl; - for (c = smp->data.str.str; c <= end; c++) { + end = smp->data.data.str.str + smp->data.data.str.len - pl; + for (c = smp->data.data.str.str; c <= end; c++) { if (is_delimiter(*c, delimiters)) { may_match = 1; continue; @@ -832,8 +832,8 @@ struct pattern *pat_match_int(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if ((!pattern->val.range.min_set || pattern->val.range.min <= smp->data.sint) && - (!pattern->val.range.max_set || smp->data.sint <= pattern->val.range.max)) + if ((!pattern->val.range.min_set || pattern->val.range.min <= smp->data.data.sint) && + (!pattern->val.range.max_set || smp->data.data.sint <= pattern->val.range.max)) return pattern; } return NULL; @@ -847,8 +847,8 @@ struct pattern *pat_match_len(struct sample *smp, struct pattern_expr *expr, int list_for_each_entry(lst, &expr->patterns, list) { pattern = &lst->pat; - if ((!pattern->val.range.min_set || pattern->val.range.min <= smp->data.str.len) && - (!pattern->val.range.max_set || smp->data.str.len <= pattern->val.range.max)) + if ((!pattern->val.range.min_set || pattern->val.range.min <= smp->data.data.str.len) && + (!pattern->val.range.max_set || smp->data.data.str.len <= pattern->val.range.max)) return pattern; } return NULL; @@ -865,11 +865,11 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int struct pattern *pattern; /* The input sample is IPv4. Try to match in the trees. */ - if (smp->type == SMP_T_IPV4) { + if (smp->data.type == SMP_T_IPV4) { /* Lookup an IPv4 address in the expression's pattern tree using * the longest match method. */ - s = &smp->data.ipv4; + s = &smp->data.data.ipv4; node = ebmb_lookup_longest(&expr->pattern_tree, &s->s_addr); if (node) { if (fill) { @@ -891,7 +891,7 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int */ memset(&tmp6, 0, 10); *(uint16_t*)&tmp6.s6_addr[10] = htons(0xffff); - *(uint32_t*)&tmp6.s6_addr[12] = smp->data.ipv4.s_addr; + *(uint32_t*)&tmp6.s6_addr[12] = smp->data.data.ipv4.s_addr; node = ebmb_lookup_longest(&expr->pattern_tree_2, &tmp6); if (node) { if (fill) { @@ -908,11 +908,11 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int } /* The input sample is IPv6. Try to match in the trees. */ - if (smp->type == SMP_T_IPV6) { + if (smp->data.type == SMP_T_IPV6) { /* Lookup an IPv6 address in the expression's pattern tree using * the longest match method. */ - node = ebmb_lookup_longest(&expr->pattern_tree_2, &smp->data.ipv6); + node = ebmb_lookup_longest(&expr->pattern_tree_2, &smp->data.data.ipv6); if (node) { if (fill) { elt = ebmb_entry(node, struct pattern_tree, node); @@ -932,16 +932,16 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int * - ::0000:ip:v4 (old ipv4 mapped) * - 2002:ip:v4:: (6to4) */ - if ((*(uint32_t*)&smp->data.ipv6.s6_addr[0] == 0 && - *(uint32_t*)&smp->data.ipv6.s6_addr[4] == 0 && - (*(uint32_t*)&smp->data.ipv6.s6_addr[8] == 0 || - *(uint32_t*)&smp->data.ipv6.s6_addr[8] == htonl(0xFFFF))) || - *(uint16_t*)&smp->data.ipv6.s6_addr[0] == htons(0x2002)) { - if (*(uint32_t*)&smp->data.ipv6.s6_addr[0] == 0) - v4 = *(uint32_t*)&smp->data.ipv6.s6_addr[12]; + if ((*(uint32_t*)&smp->data.data.ipv6.s6_addr[0] == 0 && + *(uint32_t*)&smp->data.data.ipv6.s6_addr[4] == 0 && + (*(uint32_t*)&smp->data.data.ipv6.s6_addr[8] == 0 || + *(uint32_t*)&smp->data.data.ipv6.s6_addr[8] == htonl(0xFFFF))) || + *(uint16_t*)&smp->data.data.ipv6.s6_addr[0] == htons(0x2002)) { + if (*(uint32_t*)&smp->data.data.ipv6.s6_addr[0] == 0) + v4 = *(uint32_t*)&smp->data.data.ipv6.s6_addr[12]; else - v4 = htonl((ntohs(*(uint16_t*)&smp->data.ipv6.s6_addr[2]) << 16) + - ntohs(*(uint16_t*)&smp->data.ipv6.s6_addr[4])); + v4 = htonl((ntohs(*(uint16_t*)&smp->data.data.ipv6.s6_addr[2]) << 16) + + ntohs(*(uint16_t*)&smp->data.data.ipv6.s6_addr[4])); /* Lookup an IPv4 address in the expression's pattern tree using the longest * match method. @@ -968,25 +968,25 @@ struct pattern *pat_match_ip(struct sample *smp, struct pattern_expr *expr, int pattern = &lst->pat; /* The input sample is IPv4, use it as is. */ - if (smp->type == SMP_T_IPV4) { - v4 = smp->data.ipv4.s_addr; + if (smp->data.type == SMP_T_IPV4) { + v4 = smp->data.data.ipv4.s_addr; } - else if (smp->type == SMP_T_IPV6) { + else if (smp->data.type == SMP_T_IPV6) { /* v4 match on a V6 sample. We want to check at least for * the following forms : * - ::ffff:ip:v4 (ipv4 mapped) * - ::0000:ip:v4 (old ipv4 mapped) * - 2002:ip:v4:: (6to4) */ - if (*(uint32_t*)&smp->data.ipv6.s6_addr[0] == 0 && - *(uint32_t*)&smp->data.ipv6.s6_addr[4] == 0 && - (*(uint32_t*)&smp->data.ipv6.s6_addr[8] == 0 || - *(uint32_t*)&smp->data.ipv6.s6_addr[8] == htonl(0xFFFF))) { - v4 = *(uint32_t*)&smp->data.ipv6.s6_addr[12]; + if (*(uint32_t*)&smp->data.data.ipv6.s6_addr[0] == 0 && + *(uint32_t*)&smp->data.data.ipv6.s6_addr[4] == 0 && + (*(uint32_t*)&smp->data.data.ipv6.s6_addr[8] == 0 || + *(uint32_t*)&smp->data.data.ipv6.s6_addr[8] == htonl(0xFFFF))) { + v4 = *(uint32_t*)&smp->data.data.ipv6.s6_addr[12]; } - else if (*(uint16_t*)&smp->data.ipv6.s6_addr[0] == htons(0x2002)) { - v4 = htonl((ntohs(*(uint16_t*)&smp->data.ipv6.s6_addr[2]) << 16) + - ntohs(*(uint16_t*)&smp->data.ipv6.s6_addr[4])); + else if (*(uint16_t*)&smp->data.data.ipv6.s6_addr[0] == htons(0x2002)) { + v4 = htonl((ntohs(*(uint16_t*)&smp->data.data.ipv6.s6_addr[2]) << 16) + + ntohs(*(uint16_t*)&smp->data.data.ipv6.s6_addr[4])); } else continue; diff --git a/src/payload.c b/src/payload.c index 32c530c9a2..4c140d05d0 100644 --- a/src/payload.c +++ b/src/payload.c @@ -35,8 +35,8 @@ smp_fetch_wait_end(const struct arg *args, struct sample *smp, const char *kw, v smp->flags |= SMP_F_MAY_CHANGE; return 0; } - smp->type = SMP_T_BOOL; - smp->data.sint = 1; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = 1; return 1; } @@ -50,8 +50,8 @@ smp_fetch_len(const struct arg *args, struct sample *smp, const char *kw, void * if (!chn->buf) return 0; - smp->type = SMP_T_SINT; - smp->data.sint = chn->buf->i; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = chn->buf->i; smp->flags = SMP_F_VOLATILE | SMP_F_MAY_CHANGE; return 1; } @@ -159,8 +159,8 @@ smp_fetch_req_ssl_ec_ext(const struct arg *args, struct sample *smp, const char /* Elliptic curves extension */ if (ext_type == 10) { - smp->type = SMP_T_BOOL; - smp->data.sint = 1; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = 1; smp->flags = SMP_F_VOLATILE; return 1; } @@ -224,8 +224,8 @@ smp_fetch_ssl_hello_type(const struct arg *args, struct sample *smp, const char goto not_ssl_hello; } - smp->type = SMP_T_SINT; - smp->data.sint = hs_type; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = hs_type; smp->flags = SMP_F_VOLATILE; return 1; @@ -338,8 +338,8 @@ smp_fetch_req_ssl_ver(const struct arg *args, struct sample *smp, const char *kw /* OK that's enough. We have at least the whole message, and we have * the protocol version. */ - smp->type = SMP_T_SINT; - smp->data.sint = version; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = version; smp->flags = SMP_F_VOLATILE; return 1; @@ -492,9 +492,9 @@ smp_fetch_ssl_hello_sni(const struct arg *args, struct sample *smp, const char * name_len = (data[7] << 8) + data[8]; if (name_type == 0) { /* hostname */ - smp->type = SMP_T_STR; - smp->data.str.str = (char *)data + 9; - smp->data.str.len = name_len; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = (char *)data + 9; + smp->data.data.str.len = name_len; smp->flags = SMP_F_VOLATILE | SMP_F_CONST; return 1; } @@ -528,7 +528,7 @@ fetch_rdp_cookie_name(struct stream *s, struct sample *smp, const char *cname, i return 0; smp->flags = SMP_F_CONST; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; bleft = s->req.buf->i; if (bleft <= 11) @@ -580,8 +580,8 @@ fetch_rdp_cookie_name(struct stream *s, struct sample *smp, const char *cname, i } /* data points to cookie value */ - smp->data.str.str = (char *)data; - smp->data.str.len = 0; + smp->data.data.str.str = (char *)data; + smp->data.data.str.len = 0; while (bleft > 0 && *data != '\r') { data++; @@ -594,7 +594,7 @@ fetch_rdp_cookie_name(struct stream *s, struct sample *smp, const char *cname, i if (data[0] != '\r' || data[1] != '\n') goto not_cookie; - smp->data.str.len = (char *)data - smp->data.str.str; + smp->data.data.str.len = (char *)data - smp->data.data.str.str; smp->flags = SMP_F_VOLATILE | SMP_F_CONST; return 1; @@ -628,8 +628,8 @@ smp_fetch_rdp_cookie_cnt(const struct arg *args, struct sample *smp, const char return 0; smp->flags = SMP_F_VOLATILE; - smp->type = SMP_T_SINT; - smp->data.sint = ret; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = ret; return 1; } @@ -680,9 +680,9 @@ smp_fetch_payload_lv(const struct arg *arg_p, struct sample *smp, const char *kw goto too_short; /* init chunk as read only */ - smp->type = SMP_T_BIN; + smp->data.type = SMP_T_BIN; smp->flags = SMP_F_VOLATILE | SMP_F_CONST; - chunk_initlen(&smp->data.str, chn->buf->p + buf_offset, 0, buf_size); + chunk_initlen(&smp->data.data.str, chn->buf->p + buf_offset, 0, buf_size); return 1; too_short: @@ -712,9 +712,9 @@ smp_fetch_payload(const struct arg *arg_p, struct sample *smp, const char *kw, v goto too_short; /* init chunk as read only */ - smp->type = SMP_T_BIN; + smp->data.type = SMP_T_BIN; smp->flags = SMP_F_VOLATILE | SMP_F_CONST; - chunk_initlen(&smp->data.str, chn->buf->p + buf_offset, 0, buf_size ? buf_size : (chn->buf->i - buf_offset)); + chunk_initlen(&smp->data.data.str, chn->buf->p + buf_offset, 0, buf_size ? buf_size : (chn->buf->i - buf_offset)); if (!buf_size && channel_may_recv(chn) && !channel_input_closed(chn)) smp->flags |= SMP_F_MAY_CHANGE; diff --git a/src/proto_http.c b/src/proto_http.c index 093594055f..848e870f64 100644 --- a/src/proto_http.c +++ b/src/proto_http.c @@ -3682,13 +3682,13 @@ resume_execution: smp = sample_fetch_as_type(px, sess, s, SMP_OPT_DIR_REQ|SMP_OPT_FINAL, rule->arg.act.p[0], SMP_T_ADDR); if (smp) { - if (smp->type == SMP_T_IPV4) { + if (smp->data.type == SMP_T_IPV4) { ((struct sockaddr_in *)&cli_conn->addr.from)->sin_family = AF_INET; - ((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr.s_addr = smp->data.ipv4.s_addr; + ((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr.s_addr = smp->data.data.ipv4.s_addr; ((struct sockaddr_in *)&cli_conn->addr.from)->sin_port = 0; - } else if (smp->type == SMP_T_IPV6) { + } else if (smp->data.type == SMP_T_IPV6) { ((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_family = AF_INET6; - memcpy(&((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_addr, &smp->data.ipv6, sizeof(struct in6_addr)); + memcpy(&((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_addr, &smp->data.data.ipv6, sizeof(struct in6_addr)); ((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_port = 0; } } @@ -9945,7 +9945,7 @@ smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt, msg = &txn->req; /* Check for a dependency on a request */ - smp->type = SMP_T_BOOL; + smp->data.type = SMP_T_BOOL; if ((opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ) { /* If the buffer does not leave enough free space at the end, @@ -9987,7 +9987,7 @@ smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt, if (unlikely(s->req.buf->i + s->req.buf->p > s->req.buf->data + s->req.buf->size - global.tune.maxrewrite)) { msg->msg_state = HTTP_MSG_ERROR; - smp->data.sint = 1; + smp->data.data.sint = 1; return 1; } @@ -10014,7 +10014,7 @@ smp_prefetch_http(struct proxy *px, struct stream *s, unsigned int opt, } /* everything's OK */ - smp->data.sint = 1; + smp->data.data.sint = 1; return 1; } @@ -10068,15 +10068,15 @@ smp_fetch_meth(const struct arg *args, struct sample *smp, const char *kw, void CHECK_HTTP_MESSAGE_FIRST_PERM(); meth = txn->meth; - smp->type = SMP_T_METH; - smp->data.meth.meth = meth; + smp->data.type = SMP_T_METH; + smp->data.data.meth.meth = meth; if (meth == HTTP_METH_OTHER) { if (txn->rsp.msg_state != HTTP_MSG_RPBEFORE) /* ensure the indexes are not affected */ return 0; smp->flags |= SMP_F_CONST; - smp->data.meth.str.len = txn->req.sl.rq.m_l; - smp->data.meth.str.str = txn->req.chn->buf->p; + smp->data.data.meth.str.len = txn->req.sl.rq.m_l; + smp->data.data.meth.str.str = txn->req.chn->buf->p; } smp->flags |= SMP_F_VOL_1ST; return 1; @@ -10094,19 +10094,19 @@ static struct pattern *pat_match_meth(struct sample *smp, struct pattern_expr *e /* well-known method */ if (pattern->val.i != HTTP_METH_OTHER) { - if (smp->data.meth.meth == pattern->val.i) + if (smp->data.data.meth.meth == pattern->val.i) return pattern; else continue; } /* Other method, we must compare the strings */ - if (pattern->len != smp->data.meth.str.len) + if (pattern->len != smp->data.data.meth.str.len) continue; icase = expr->mflags & PAT_MF_IGNORE_CASE; - if ((icase && strncasecmp(pattern->ptr.str, smp->data.meth.str.str, smp->data.meth.str.len) == 0) || - (!icase && strncmp(pattern->ptr.str, smp->data.meth.str.str, smp->data.meth.str.len) == 0)) + if ((icase && strncasecmp(pattern->ptr.str, smp->data.data.meth.str.str, smp->data.data.meth.str.len) == 0) || + (!icase && strncmp(pattern->ptr.str, smp->data.data.meth.str.str, smp->data.data.meth.str.len) == 0)) return pattern; } return NULL; @@ -10128,9 +10128,9 @@ smp_fetch_rqver(const struct arg *args, struct sample *smp, const char *kw, void if (len <= 0) return 0; - smp->type = SMP_T_STR; - smp->data.str.str = ptr; - smp->data.str.len = len; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = ptr; + smp->data.data.str.len = len; smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; return 1; @@ -10156,9 +10156,9 @@ smp_fetch_stver(const struct arg *args, struct sample *smp, const char *kw, void if (len <= 0) return 0; - smp->type = SMP_T_STR; - smp->data.str.str = ptr; - smp->data.str.len = len; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = ptr; + smp->data.data.str.len = len; smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; return 1; @@ -10181,8 +10181,8 @@ smp_fetch_stcode(const struct arg *args, struct sample *smp, const char *kw, voi len = txn->rsp.sl.st.c_l; ptr = txn->rsp.chn->buf->p + txn->rsp.sl.st.c; - smp->type = SMP_T_SINT; - smp->data.sint = __strl2ui(ptr, len); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = __strl2ui(ptr, len); smp->flags = SMP_F_VOL_1ST; return 1; } @@ -10216,9 +10216,9 @@ smp_fetch_body(const struct arg *args, struct sample *smp, const char *kw, void if (block1 == len) { /* buffer is not wrapped (or empty) */ - smp->type = SMP_T_BIN; - smp->data.str.str = body; - smp->data.str.len = len; + smp->data.type = SMP_T_BIN; + smp->data.data.str.str = body; + smp->data.data.str.len = len; smp->flags = SMP_F_VOL_TEST | SMP_F_CONST; } else { @@ -10226,9 +10226,9 @@ smp_fetch_body(const struct arg *args, struct sample *smp, const char *kw, void temp = get_trash_chunk(); memcpy(temp->str, body, block1); memcpy(temp->str + block1, msg->chn->buf->data, len - block1); - smp->type = SMP_T_BIN; - smp->data.str.str = temp->str; - smp->data.str.len = len; + smp->data.type = SMP_T_BIN; + smp->data.data.str.str = temp->str; + smp->data.data.str.len = len; smp->flags = SMP_F_VOL_TEST; } return 1; @@ -10251,8 +10251,8 @@ smp_fetch_body_len(const struct arg *args, struct sample *smp, const char *kw, v else msg = &txn->rsp; - smp->type = SMP_T_SINT; - smp->data.sint = http_body_bytes(msg); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = http_body_bytes(msg); smp->flags = SMP_F_VOL_TEST; return 1; @@ -10276,8 +10276,8 @@ smp_fetch_body_size(const struct arg *args, struct sample *smp, const char *kw, else msg = &txn->rsp; - smp->type = SMP_T_SINT; - smp->data.sint = msg->body_len; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = msg->body_len; smp->flags = SMP_F_VOL_TEST; return 1; @@ -10293,9 +10293,9 @@ smp_fetch_url(const struct arg *args, struct sample *smp, const char *kw, void * CHECK_HTTP_MESSAGE_FIRST(); txn = smp->strm->txn; - smp->type = SMP_T_STR; - smp->data.str.len = txn->req.sl.rq.u_l; - smp->data.str.str = txn->req.chn->buf->p + txn->req.sl.rq.u; + smp->data.type = SMP_T_STR; + smp->data.data.str.len = txn->req.sl.rq.u_l; + smp->data.data.str.str = txn->req.chn->buf->p + txn->req.sl.rq.u; smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; return 1; } @@ -10313,8 +10313,8 @@ smp_fetch_url_ip(const struct arg *args, struct sample *smp, const char *kw, voi if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) return 0; - smp->type = SMP_T_IPV4; - smp->data.ipv4 = ((struct sockaddr_in *)&addr)->sin_addr; + smp->data.type = SMP_T_IPV4; + smp->data.data.ipv4 = ((struct sockaddr_in *)&addr)->sin_addr; smp->flags = 0; return 1; } @@ -10332,8 +10332,8 @@ smp_fetch_url_port(const struct arg *args, struct sample *smp, const char *kw, v if (((struct sockaddr_in *)&addr)->sin_family != AF_INET) return 0; - smp->type = SMP_T_SINT; - smp->data.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = ntohs(((struct sockaddr_in *)&addr)->sin_port); smp->flags = 0; return 1; } @@ -10389,9 +10389,9 @@ smp_fetch_fhdr(const struct arg *args, struct sample *smp, const char *kw, void /* prepare to report multiple occurrences for ACL fetches */ smp->flags |= SMP_F_NOT_LAST; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; - if (http_get_fhdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.str.str, &smp->data.str.len)) + if (http_get_fhdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.data.str.str, &smp->data.data.str.len)) return 1; smp->flags &= ~SMP_F_NOT_LAST; @@ -10427,8 +10427,8 @@ smp_fetch_fhdr_cnt(const struct arg *args, struct sample *smp, const char *kw, v while (http_find_full_header2(name, len, msg->chn->buf->p, idx, &ctx)) cnt++; - smp->type = SMP_T_SINT; - smp->data.sint = cnt; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = cnt; smp->flags = SMP_F_VOL_HDR; return 1; } @@ -10460,9 +10460,9 @@ smp_fetch_hdr_names(const struct arg *args, struct sample *smp, const char *kw, temp->len += ctx.del; } - smp->type = SMP_T_STR; - smp->data.str.str = temp->str; - smp->data.str.len = temp->len; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = temp->str; + smp->data.data.str.len = temp->len; smp->flags = SMP_F_VOL_HDR; return 1; } @@ -10517,9 +10517,9 @@ smp_fetch_hdr(const struct arg *args, struct sample *smp, const char *kw, void * /* prepare to report multiple occurrences for ACL fetches */ smp->flags |= SMP_F_NOT_LAST; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_VOL_HDR | SMP_F_CONST; - if (http_get_hdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.str.str, &smp->data.str.len)) + if (http_get_hdr(msg, name_str, name_len, idx, occ, ctx, &smp->data.data.str.str, &smp->data.data.str.len)) return 1; smp->flags &= ~SMP_F_NOT_LAST; @@ -10554,8 +10554,8 @@ smp_fetch_hdr_cnt(const struct arg *args, struct sample *smp, const char *kw, vo while (http_find_header2(name, len, msg->chn->buf->p, idx, &ctx)) cnt++; - smp->type = SMP_T_SINT; - smp->data.sint = cnt; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = cnt; smp->flags = SMP_F_VOL_HDR; return 1; } @@ -10571,8 +10571,8 @@ smp_fetch_hdr_val(const struct arg *args, struct sample *smp, const char *kw, vo int ret = smp_fetch_hdr(args, smp, kw, private); if (ret > 0) { - smp->type = SMP_T_SINT; - smp->data.sint = strl2ic(smp->data.str.str, smp->data.str.len); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = strl2ic(smp->data.data.str.str, smp->data.data.str.len); } return ret; @@ -10588,16 +10588,16 @@ smp_fetch_hdr_ip(const struct arg *args, struct sample *smp, const char *kw, voi int ret; while ((ret = smp_fetch_hdr(args, smp, kw, private)) > 0) { - if (url2ipv4((char *)smp->data.str.str, &smp->data.ipv4)) { - smp->type = SMP_T_IPV4; + if (url2ipv4((char *)smp->data.data.str.str, &smp->data.data.ipv4)) { + smp->data.type = SMP_T_IPV4; break; } else { struct chunk *temp = get_trash_chunk(); - if (smp->data.str.len < temp->size - 1) { - memcpy(temp->str, smp->data.str.str, smp->data.str.len); - temp->str[smp->data.str.len] = '\0'; - if (inet_pton(AF_INET6, temp->str, &smp->data.ipv6)) { - smp->type = SMP_T_IPV6; + if (smp->data.data.str.len < temp->size - 1) { + memcpy(temp->str, smp->data.data.str.str, smp->data.data.str.len); + temp->str[smp->data.data.str.len] = '\0'; + if (inet_pton(AF_INET6, temp->str, &smp->data.data.ipv6)) { + smp->data.type = SMP_T_IPV6; break; } } @@ -10628,13 +10628,13 @@ smp_fetch_path(const struct arg *args, struct sample *smp, const char *kw, void return 0; /* OK, we got the '/' ! */ - smp->type = SMP_T_STR; - smp->data.str.str = ptr; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = ptr; while (ptr < end && *ptr != '?') ptr++; - smp->data.str.len = ptr - smp->data.str.str; + smp->data.data.str.len = ptr - smp->data.data.str.str; smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; return 1; } @@ -10664,9 +10664,9 @@ smp_fetch_base(const struct arg *args, struct sample *smp, const char *kw, void /* OK we have the header value in ctx.line+ctx.val for ctx.vlen bytes */ temp = get_trash_chunk(); memcpy(temp->str, ctx.line + ctx.val, ctx.vlen); - smp->type = SMP_T_STR; - smp->data.str.str = temp->str; - smp->data.str.len = ctx.vlen; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = temp->str; + smp->data.data.str.len = ctx.vlen; /* now retrieve the path */ end = txn->req.chn->buf->p + txn->req.sl.rq.u + txn->req.sl.rq.u_l; @@ -10677,8 +10677,8 @@ smp_fetch_base(const struct arg *args, struct sample *smp, const char *kw, void for (ptr = beg; ptr < end && *ptr != '?'; ptr++); if (beg < ptr && *beg == '/') { - memcpy(smp->data.str.str + smp->data.str.len, beg, ptr - beg); - smp->data.str.len += ptr - beg; + memcpy(smp->data.data.str.str + smp->data.data.str.len, beg, ptr - beg); + smp->data.data.str.len += ptr - beg; } smp->flags = SMP_F_VOL_1ST; @@ -10728,8 +10728,8 @@ smp_fetch_base32(const struct arg *args, struct sample *smp, const char *kw, voi } hash = full_hash(hash); - smp->type = SMP_T_SINT; - smp->data.sint = hash; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = hash; smp->flags = SMP_F_VOL_1ST; return 1; } @@ -10754,7 +10754,7 @@ smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, return 0; temp = get_trash_chunk(); - *(unsigned int *)temp->str = htonl(smp->data.sint); + *(unsigned int *)temp->str = htonl(smp->data.data.sint); temp->len += sizeof(unsigned int); switch (cli_conn->addr.from.ss_family) { @@ -10770,8 +10770,8 @@ smp_fetch_base32_src(const struct arg *args, struct sample *smp, const char *kw, return 0; } - smp->data.str = *temp; - smp->type = SMP_T_BIN; + smp->data.data.str = *temp; + smp->data.type = SMP_T_BIN; return 1; } @@ -10797,9 +10797,9 @@ smp_fetch_query(const struct arg *args, struct sample *smp, const char *kw, void return 0; } while (*ptr++ != '?'); - smp->type = SMP_T_STR; - smp->data.str.str = ptr; - smp->data.str.len = end - ptr; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = ptr; + smp->data.data.str.len = end - ptr; smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; return 1; } @@ -10813,8 +10813,8 @@ smp_fetch_proto_http(const struct arg *args, struct sample *smp, const char *kw, CHECK_HTTP_MESSAGE_FIRST_PERM(); - smp->type = SMP_T_BOOL; - smp->data.sint = 1; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = 1; return 1; } @@ -10822,8 +10822,8 @@ smp_fetch_proto_http(const struct arg *args, struct sample *smp, const char *kw, static int smp_fetch_http_first_req(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_BOOL; - smp->data.sint = !(smp->strm->txn->flags & TX_NOT_FIRST); + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = !(smp->strm->txn->flags & TX_NOT_FIRST); return 1; } @@ -10840,8 +10840,8 @@ smp_fetch_http_auth(const struct arg *args, struct sample *smp, const char *kw, if (!get_http_auth(smp->strm)) return 0; - smp->type = SMP_T_BOOL; - smp->data.sint = check_user(args->data.usr, smp->strm->txn->auth.user, + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = check_user(args->data.usr, smp->strm->txn->auth.user, smp->strm->txn->auth.pass); return 1; } @@ -10869,10 +10869,10 @@ smp_fetch_http_auth_grp(const struct arg *args, struct sample *smp, const char * /* pat_match_auth() will need the user list */ smp->ctx.a[0] = args->data.usr; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; - smp->data.str.str = smp->strm->txn->auth.user; - smp->data.str.len = strlen(smp->strm->txn->auth.user); + smp->data.data.str.str = smp->strm->txn->auth.user; + smp->data.data.str.len = strlen(smp->strm->txn->auth.user); return 1; } @@ -10989,10 +10989,10 @@ smp_fetch_capture_header_req(const struct arg *args, struct sample *smp, const c if (idx > (fe->nb_req_cap - 1) || smp->strm->req_cap == NULL || smp->strm->req_cap[idx] == NULL) return 0; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; - smp->data.str.str = smp->strm->req_cap[idx]; - smp->data.str.len = strlen(smp->strm->req_cap[idx]); + smp->data.data.str.str = smp->strm->req_cap[idx]; + smp->data.data.str.len = strlen(smp->strm->req_cap[idx]); return 1; } @@ -11014,10 +11014,10 @@ smp_fetch_capture_header_res(const struct arg *args, struct sample *smp, const c if (idx > (fe->nb_rsp_cap - 1) || smp->strm->res_cap == NULL || smp->strm->res_cap[idx] == NULL) return 0; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; - smp->data.str.str = smp->strm->res_cap[idx]; - smp->data.str.len = strlen(smp->strm->res_cap[idx]); + smp->data.data.str.str = smp->strm->res_cap[idx]; + smp->data.data.str.len = strlen(smp->strm->res_cap[idx]); return 1; } @@ -11041,8 +11041,8 @@ smp_fetch_capture_req_method(const struct arg *args, struct sample *smp, const c temp = get_trash_chunk(); temp->str = txn->uri; temp->len = ptr - txn->uri; - smp->data.str = *temp; - smp->type = SMP_T_STR; + smp->data.data.str = *temp; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; return 1; @@ -11077,9 +11077,9 @@ smp_fetch_capture_req_uri(const struct arg *args, struct sample *smp, const char while (*ptr != ' ' && *ptr != '\0') /* find space after URI */ ptr++; - smp->data.str = *temp; - smp->data.str.len = ptr - temp->str; - smp->type = SMP_T_STR; + smp->data.data.str = *temp; + smp->data.data.str.len = ptr - temp->str; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; return 1; @@ -11097,12 +11097,12 @@ smp_fetch_capture_req_ver(const struct arg *args, struct sample *smp, const char return 0; if (txn->req.flags & HTTP_MSGF_VER_11) - smp->data.str.str = "HTTP/1.1"; + smp->data.data.str.str = "HTTP/1.1"; else - smp->data.str.str = "HTTP/1.0"; + smp->data.data.str.str = "HTTP/1.0"; - smp->data.str.len = 8; - smp->type = SMP_T_STR; + smp->data.data.str.len = 8; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; return 1; @@ -11120,12 +11120,12 @@ smp_fetch_capture_res_ver(const struct arg *args, struct sample *smp, const char return 0; if (txn->rsp.flags & HTTP_MSGF_VER_11) - smp->data.str.str = "HTTP/1.1"; + smp->data.data.str.str = "HTTP/1.1"; else - smp->data.str.str = "HTTP/1.0"; + smp->data.data.str.str = "HTTP/1.0"; - smp->data.str.len = 8; - smp->type = SMP_T_STR; + smp->data.data.str.len = 8; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; return 1; @@ -11212,17 +11212,17 @@ int smp_fetch_cookie(const struct arg *args, struct sample *smp, const char *kw, smp->ctx.a[1] = smp->ctx.a[0] + ctx->vlen; } - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; smp->ctx.a[0] = extract_cookie_value(smp->ctx.a[0], smp->ctx.a[1], args->data.str.str, args->data.str.len, (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, - &smp->data.str.str, - &smp->data.str.len); + &smp->data.data.str.str, + &smp->data.data.str.len); if (smp->ctx.a[0]) { found = 1; if (occ >= 0) { - /* one value was returned into smp->data.str.{str,len} */ + /* one value was returned into smp->data.data.str.{str,len} */ smp->flags |= SMP_F_NOT_LAST; return 1; } @@ -11291,19 +11291,19 @@ smp_fetch_cookie_cnt(const struct arg *args, struct sample *smp, const char *kw, val_end = val_beg + ctx.vlen; } - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; while ((val_beg = extract_cookie_value(val_beg, val_end, args->data.str.str, args->data.str.len, (smp->opt & SMP_OPT_DIR) == SMP_OPT_DIR_REQ, - &smp->data.str.str, - &smp->data.str.len))) { + &smp->data.data.str.str, + &smp->data.data.str.len))) { cnt++; } } - smp->type = SMP_T_SINT; - smp->data.sint = cnt; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = cnt; smp->flags |= SMP_F_VOL_HDR; return 1; } @@ -11317,8 +11317,8 @@ smp_fetch_cookie_val(const struct arg *args, struct sample *smp, const char *kw, int ret = smp_fetch_cookie(args, smp, kw, private); if (ret > 0) { - smp->type = SMP_T_SINT; - smp->data.sint = strl2ic(smp->data.str.str, smp->data.str.len); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = strl2ic(smp->data.data.str.str, smp->data.data.str.len); } return ret; @@ -11563,7 +11563,7 @@ smp_fetch_param(char delim, const char *name, int name_len, const struct arg *ar /* Create sample. If the value is contiguous, return the pointer as CONST, * if the value is wrapped, copy-it in a buffer. */ - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; if (chunks[2] && vstart >= chunks[0] && vstart <= chunks[1] && vend >= chunks[2] && vend <= chunks[3]) { @@ -11571,12 +11571,12 @@ smp_fetch_param(char delim, const char *name, int name_len, const struct arg *ar temp = get_trash_chunk(); memcpy(temp->str, vstart, chunks[1] - vstart); memcpy(temp->str + ( chunks[1] - vstart ), chunks[2], vend - chunks[2]); - smp->data.str.str = temp->str; - smp->data.str.len = ( chunks[1] - vstart ) + ( vend - chunks[2] ); + smp->data.data.str.str = temp->str; + smp->data.data.str.len = ( chunks[1] - vstart ) + ( vend - chunks[2] ); } else { /* Contiguous case. */ - smp->data.str.str = (char *)vstart; - smp->data.str.len = vend - vstart; + smp->data.data.str.str = (char *)vstart; + smp->data.data.str.len = vend - vstart; smp->flags = SMP_F_VOL_1ST | SMP_F_CONST; } @@ -11719,8 +11719,8 @@ smp_fetch_url_param_val(const struct arg *args, struct sample *smp, const char * int ret = smp_fetch_url_param(args, smp, kw, private); if (ret > 0) { - smp->type = SMP_T_SINT; - smp->data.sint = strl2ic(smp->data.str.str, smp->data.str.len); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = strl2ic(smp->data.data.str.str, smp->data.data.str.len); } return ret; @@ -11771,8 +11771,8 @@ smp_fetch_url32(const struct arg *args, struct sample *smp, const char *kw, void } hash = full_hash(hash); - smp->type = SMP_T_SINT; - smp->data.sint = hash; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = hash; smp->flags = SMP_F_VOL_1ST; return 1; } @@ -11795,7 +11795,7 @@ smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, return 0; /* The returned hash is a 32 bytes integer. */ - hash = smp->data.sint; + hash = smp->data.data.sint; temp = get_trash_chunk(); memcpy(temp->str + temp->len, &hash, sizeof(hash)); @@ -11814,8 +11814,8 @@ smp_fetch_url32_src(const struct arg *args, struct sample *smp, const char *kw, return 0; } - smp->data.str = *temp; - smp->type = SMP_T_BIN; + smp->data.data.str = *temp; + smp->data.type = SMP_T_BIN; return 1; } @@ -11847,7 +11847,7 @@ static int sample_conv_http_date(const struct arg *args, struct sample *smp, voi struct chunk *temp; struct tm *tm; /* With high numbers, the date returned can be negative, the 55 bits mask prevent this. */ - time_t curr_date = smp->data.sint & 0x007fffffffffffffLL; + time_t curr_date = smp->data.data.sint & 0x007fffffffffffffLL; /* add offset */ if (args && (args[0].type == ARGT_SINT)) @@ -11863,8 +11863,8 @@ static int sample_conv_http_date(const struct arg *args, struct sample *smp, voi day[tm->tm_wday], tm->tm_mday, mon[tm->tm_mon], 1900+tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec); - smp->data.str = *temp; - smp->type = SMP_T_STR; + smp->data.data.str = *temp; + smp->data.type = SMP_T_STR; return 1; } @@ -11896,8 +11896,8 @@ static inline int language_range_match(const char *range, int range_len, /* Arguments: The list of expected value, the number of parts returned and the separator */ static int sample_conv_q_prefered(const struct arg *args, struct sample *smp, void *private) { - const char *al = smp->data.str.str; - const char *end = al + smp->data.str.len; + const char *al = smp->data.data.str.str; + const char *end = al + smp->data.data.str.len; const char *token; int toklen; int qvalue; @@ -11909,9 +11909,9 @@ static int sample_conv_q_prefered(const struct arg *args, struct sample *smp, vo * function will be peek in the constant configuration string. */ smp->flags |= SMP_F_CONST; - smp->data.str.size = 0; - smp->data.str.str = ""; - smp->data.str.len = 0; + smp->data.data.str.size = 0; + smp->data.data.str.str = ""; + smp->data.data.str.len = 0; /* Parse the accept language */ while (1) { @@ -12011,8 +12011,8 @@ process_value: * break the process. */ if (qvalue > best_q) { - smp->data.str.str = (char *)w; - smp->data.str.len = str - w; + smp->data.data.str.str = (char *)w; + smp->data.data.str.len = str - w; if (qvalue >= 1000) break; best_q = qvalue; @@ -12031,13 +12031,13 @@ expect_comma: } /* Set default value if required. */ - if (smp->data.str.len == 0 && args[1].type == ARGT_STR) { - smp->data.str.str = args[1].data.str.str; - smp->data.str.len = args[1].data.str.len; + if (smp->data.data.str.len == 0 && args[1].type == ARGT_STR) { + smp->data.data.str.str = args[1].data.str.str; + smp->data.data.str.len = args[1].data.str.len; } /* Return true only if a matching language was found. */ - return smp->data.str.len != 0; + return smp->data.data.str.len != 0; } /* This fetch url-decode any input string. */ @@ -12047,17 +12047,17 @@ static int sample_conv_url_dec(const struct arg *args, struct sample *smp, void * the end of the buffer, copy the string in other buffer * before decoding. */ - if (smp->flags & SMP_F_CONST || smp->data.str.size <= smp->data.str.len) { + if (smp->flags & SMP_F_CONST || smp->data.data.str.size <= smp->data.data.str.len) { struct chunk *str = get_trash_chunk(); - memcpy(str->str, smp->data.str.str, smp->data.str.len); - smp->data.str.str = str->str; - smp->data.str.size = str->size; + memcpy(str->str, smp->data.data.str.str, smp->data.data.str.len); + smp->data.data.str.str = str->str; + smp->data.data.str.size = str->size; smp->flags &= ~SMP_F_CONST; } /* Add final \0 required by url_decode(), and convert the input string. */ - smp->data.str.str[smp->data.str.len] = '\0'; - smp->data.str.len = url_decode(smp->data.str.str); + smp->data.data.str.str[smp->data.data.str.len] = '\0'; + smp->data.data.str.len = url_decode(smp->data.data.str.str); return 1; } @@ -12091,12 +12091,12 @@ static int smp_conv_req_capture(const struct arg *args, struct sample *smp, void return 0; /* Check length. */ - len = smp->data.str.len; + len = smp->data.data.str.len; if (len > hdr->len) len = hdr->len; /* Capture input data. */ - memcpy(smp->strm->req_cap[idx], smp->data.str.str, len); + memcpy(smp->strm->req_cap[idx], smp->data.data.str.str, len); smp->strm->req_cap[idx][len] = '\0'; return 1; @@ -12132,12 +12132,12 @@ static int smp_conv_res_capture(const struct arg *args, struct sample *smp, void return 0; /* Check length. */ - len = smp->data.str.len; + len = smp->data.data.str.len; if (len > hdr->len) len = hdr->len; /* Capture input data. */ - memcpy(smp->strm->res_cap[idx], smp->data.str.str, len); + memcpy(smp->strm->res_cap[idx], smp->data.data.str.str, len); smp->strm->res_cap[idx][len] = '\0'; return 1; @@ -12334,11 +12334,11 @@ int http_action_req_capture(struct http_req_rule *rule, struct proxy *px, struct if (cap[h->index] == NULL) /* no more capture memory */ return 1; - len = key->data.str.len; + len = key->data.data.str.len; if (len > h->len) len = h->len; - memcpy(cap[h->index], key->data.str.str, len); + memcpy(cap[h->index], key->data.data.str.str, len); cap[h->index][len] = 0; return 1; } @@ -12377,11 +12377,11 @@ int http_action_req_capture_by_id(struct http_req_rule *rule, struct proxy *px, if (cap[h->index] == NULL) /* no more capture memory */ return 1; - len = key->data.str.len; + len = key->data.data.str.len; if (len > h->len) len = h->len; - memcpy(cap[h->index], key->data.str.str, len); + memcpy(cap[h->index], key->data.data.str.str, len); cap[h->index][len] = 0; return 1; } @@ -12546,11 +12546,11 @@ int http_action_res_capture_by_id(struct http_res_rule *rule, struct proxy *px, if (cap[h->index] == NULL) /* no more capture memory */ return 1; - len = key->data.str.len; + len = key->data.data.str.len; if (len > h->len) len = h->len; - memcpy(cap[h->index], key->data.str.str, len); + memcpy(cap[h->index], key->data.data.str.str, len); cap[h->index][len] = 0; return 1; } diff --git a/src/proto_tcp.c b/src/proto_tcp.c index 077bc13dff..29d68c3657 100644 --- a/src/proto_tcp.c +++ b/src/proto_tcp.c @@ -1222,11 +1222,11 @@ resume_execution: if (cap[h->index] == NULL) /* no more capture memory */ continue; - len = key->data.str.len; + len = key->data.data.str.len; if (len > h->len) len = h->len; - memcpy(cap[h->index], key->data.str.str, len); + memcpy(cap[h->index], key->data.data.str.str, len); cap[h->index][len] = 0; } else { @@ -1999,12 +1999,12 @@ int smp_fetch_src(const struct arg *args, struct sample *smp, const char *kw, vo switch (cli_conn->addr.from.ss_family) { case AF_INET: - smp->data.ipv4 = ((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr; - smp->type = SMP_T_IPV4; + smp->data.data.ipv4 = ((struct sockaddr_in *)&cli_conn->addr.from)->sin_addr; + smp->data.type = SMP_T_IPV4; break; case AF_INET6: - smp->data.ipv6 = ((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_addr; - smp->type = SMP_T_IPV6; + smp->data.data.ipv6 = ((struct sockaddr_in6 *)&cli_conn->addr.from)->sin6_addr; + smp->data.type = SMP_T_IPV6; break; default: return 0; @@ -2023,8 +2023,8 @@ smp_fetch_sport(const struct arg *args, struct sample *smp, const char *k, void if (!cli_conn) return 0; - smp->type = SMP_T_SINT; - if (!(smp->data.sint = get_host_port(&cli_conn->addr.from))) + smp->data.type = SMP_T_SINT; + if (!(smp->data.data.sint = get_host_port(&cli_conn->addr.from))) return 0; smp->flags = 0; @@ -2044,12 +2044,12 @@ smp_fetch_dst(const struct arg *args, struct sample *smp, const char *kw, void * switch (cli_conn->addr.to.ss_family) { case AF_INET: - smp->data.ipv4 = ((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr; - smp->type = SMP_T_IPV4; + smp->data.data.ipv4 = ((struct sockaddr_in *)&cli_conn->addr.to)->sin_addr; + smp->data.type = SMP_T_IPV4; break; case AF_INET6: - smp->data.ipv6 = ((struct sockaddr_in6 *)&cli_conn->addr.to)->sin6_addr; - smp->type = SMP_T_IPV6; + smp->data.data.ipv6 = ((struct sockaddr_in6 *)&cli_conn->addr.to)->sin6_addr; + smp->data.type = SMP_T_IPV6; break; default: return 0; @@ -2070,8 +2070,8 @@ smp_fetch_dport(const struct arg *args, struct sample *smp, const char *kw, void conn_get_to_addr(cli_conn); - smp->type = SMP_T_SINT; - if (!(smp->data.sint = get_host_port(&cli_conn->addr.to))) + smp->data.type = SMP_T_SINT; + if (!(smp->data.data.sint = get_host_port(&cli_conn->addr.to))) return 0; smp->flags = 0; diff --git a/src/sample.c b/src/sample.c index 6bb2dfd908..9a57376198 100644 --- a/src/sample.c +++ b/src/sample.c @@ -499,8 +499,8 @@ struct sample_conv *find_sample_conv(const char *kw, int len) static int c_ip2int(struct sample *smp) { - smp->data.sint = ntohl(smp->data.ipv4.s_addr); - smp->type = SMP_T_SINT; + smp->data.data.sint = ntohl(smp->data.data.ipv4.s_addr); + smp->data.type = SMP_T_SINT; return 1; } @@ -508,12 +508,12 @@ static int c_ip2str(struct sample *smp) { struct chunk *trash = get_trash_chunk(); - if (!inet_ntop(AF_INET, (void *)&smp->data.ipv4, trash->str, trash->size)) + if (!inet_ntop(AF_INET, (void *)&smp->data.data.ipv4, trash->str, trash->size)) return 0; trash->len = strlen(trash->str); - smp->data.str = *trash; - smp->type = SMP_T_STR; + smp->data.data.str = *trash; + smp->data.type = SMP_T_STR; smp->flags &= ~SMP_F_CONST; return 1; @@ -521,16 +521,16 @@ static int c_ip2str(struct sample *smp) static int c_ip2ipv6(struct sample *smp) { - v4tov6(&smp->data.ipv6, &smp->data.ipv4); - smp->type = SMP_T_IPV6; + v4tov6(&smp->data.data.ipv6, &smp->data.data.ipv4); + smp->data.type = SMP_T_IPV6; return 1; } static int c_ipv62ip(struct sample *smp) { - if (!v6tov4(&smp->data.ipv4, &smp->data.ipv6)) + if (!v6tov4(&smp->data.data.ipv4, &smp->data.data.ipv6)) return 0; - smp->type = SMP_T_IPV6; + smp->data.type = SMP_T_IPV6; return 1; } @@ -538,12 +538,12 @@ static int c_ipv62str(struct sample *smp) { struct chunk *trash = get_trash_chunk(); - if (!inet_ntop(AF_INET6, (void *)&smp->data.ipv6, trash->str, trash->size)) + if (!inet_ntop(AF_INET6, (void *)&smp->data.data.ipv6, trash->str, trash->size)) return 0; trash->len = strlen(trash->str); - smp->data.str = *trash; - smp->type = SMP_T_STR; + smp->data.data.str = *trash; + smp->data.type = SMP_T_STR; smp->flags &= ~SMP_F_CONST; return 1; } @@ -551,53 +551,53 @@ static int c_ipv62str(struct sample *smp) /* static int c_ipv62ip(struct sample *smp) { - return v6tov4(&smp->data.ipv4, &smp->data.ipv6); + return v6tov4(&smp->data.data.ipv4, &smp->data.data.ipv6); } */ static int c_int2ip(struct sample *smp) { - smp->data.ipv4.s_addr = htonl((unsigned int)smp->data.sint); - smp->type = SMP_T_IPV4; + smp->data.data.ipv4.s_addr = htonl((unsigned int)smp->data.data.sint); + smp->data.type = SMP_T_IPV4; return 1; } static int c_int2ipv6(struct sample *smp) { - smp->data.ipv4.s_addr = htonl((unsigned int)smp->data.sint); - v4tov6(&smp->data.ipv6, &smp->data.ipv4); - smp->type = SMP_T_IPV6; + smp->data.data.ipv4.s_addr = htonl((unsigned int)smp->data.data.sint); + v4tov6(&smp->data.data.ipv6, &smp->data.data.ipv4); + smp->data.type = SMP_T_IPV6; return 1; } static int c_str2addr(struct sample *smp) { - if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4)) { - if (!buf2ip6(smp->data.str.str, smp->data.str.len, &smp->data.ipv6)) + if (!buf2ip(smp->data.data.str.str, smp->data.data.str.len, &smp->data.data.ipv4)) { + if (!buf2ip6(smp->data.data.str.str, smp->data.data.str.len, &smp->data.data.ipv6)) return 0; - smp->type = SMP_T_IPV6; + smp->data.type = SMP_T_IPV6; smp->flags &= ~SMP_F_CONST; return 1; } - smp->type = SMP_T_IPV4; + smp->data.type = SMP_T_IPV4; smp->flags &= ~SMP_F_CONST; return 1; } static int c_str2ip(struct sample *smp) { - if (!buf2ip(smp->data.str.str, smp->data.str.len, &smp->data.ipv4)) + if (!buf2ip(smp->data.data.str.str, smp->data.data.str.len, &smp->data.data.ipv4)) return 0; - smp->type = SMP_T_IPV4; + smp->data.type = SMP_T_IPV4; smp->flags &= ~SMP_F_CONST; return 1; } static int c_str2ipv6(struct sample *smp) { - if (!buf2ip6(smp->data.str.str, smp->data.str.len, &smp->data.ipv6)) + if (!buf2ip6(smp->data.data.str.str, smp->data.data.str.len, &smp->data.data.ipv6)) return 0; - smp->type = SMP_T_IPV6; + smp->data.type = SMP_T_IPV6; smp->flags &= ~SMP_F_CONST; return 1; } @@ -610,9 +610,9 @@ static int c_bin2str(struct sample *smp) { int i; - for (i = 0; i < smp->data.str.len; i++) { - if (!smp->data.str.str[i]) { - smp->data.str.len = i; + for (i = 0; i < smp->data.data.str.len; i++) { + if (!smp->data.data.str.str[i]) { + smp->data.data.str.len = i; break; } } @@ -624,15 +624,15 @@ static int c_int2str(struct sample *smp) struct chunk *trash = get_trash_chunk(); char *pos; - pos = lltoa_r(smp->data.sint, trash->str, trash->size); + pos = lltoa_r(smp->data.data.sint, trash->str, trash->size); if (!pos) return 0; trash->size = trash->size - (pos - trash->str); trash->str = pos; trash->len = strlen(pos); - smp->data.str = *trash; - smp->type = SMP_T_STR; + smp->data.data.str = *trash; + smp->data.type = SMP_T_STR; smp->flags &= ~SMP_F_CONST; return 1; } @@ -648,7 +648,7 @@ int smp_dup(struct sample *smp) if (!(smp->flags & SMP_F_CONST)) return 1; - switch (smp->type) { + switch (smp->data.type) { case SMP_T_BOOL: case SMP_T_SINT: case SMP_T_ADDR: @@ -660,9 +660,9 @@ int smp_dup(struct sample *smp) case SMP_T_BIN: /* Duplicate data. */ trash = get_trash_chunk(); - trash->len = smp->data.str.len < trash->size ? smp->data.str.len : trash->size; - memcpy(trash->str, smp->data.str.str, trash->len); - smp->data.str = *trash; + trash->len = smp->data.data.str.len < trash->size ? smp->data.data.str.len : trash->size; + memcpy(trash->str, smp->data.data.str.str, trash->len); + smp->data.data.str = *trash; break; default: /* Other cases are unexpected. */ @@ -684,14 +684,14 @@ static int c_str2int(struct sample *smp) const char *str; const char *end; - if (smp->data.str.len == 0) + if (smp->data.data.str.len == 0) return 0; - str = smp->data.str.str; - end = smp->data.str.str + smp->data.str.len; + str = smp->data.data.str.str; + end = smp->data.data.str.str + smp->data.data.str.len; - smp->data.sint = read_int64(&str, end); - smp->type = SMP_T_SINT; + smp->data.data.sint = read_int64(&str, end); + smp->data.type = SMP_T_SINT; smp->flags &= ~SMP_F_CONST; return 1; } @@ -701,16 +701,16 @@ static int c_str2meth(struct sample *smp) enum http_meth_t meth; int len; - meth = find_http_meth(smp->data.str.str, smp->data.str.len); + meth = find_http_meth(smp->data.data.str.str, smp->data.data.str.len); if (meth == HTTP_METH_OTHER) { - len = smp->data.str.len; - smp->data.meth.str.str = smp->data.str.str; - smp->data.meth.str.len = len; + len = smp->data.data.str.len; + smp->data.data.meth.str.str = smp->data.data.str.str; + smp->data.data.meth.str.len = len; } else smp->flags &= ~SMP_F_CONST; - smp->data.meth.meth = meth; - smp->type = SMP_T_METH; + smp->data.data.meth.meth = meth; + smp->data.type = SMP_T_METH; return 1; } @@ -719,20 +719,20 @@ static int c_meth2str(struct sample *smp) int len; enum http_meth_t meth; - if (smp->data.meth.meth == HTTP_METH_OTHER) { + if (smp->data.data.meth.meth == HTTP_METH_OTHER) { /* The method is unknown. Copy the original pointer. */ - len = smp->data.meth.str.len; - smp->data.str.str = smp->data.meth.str.str; - smp->data.str.len = len; - smp->type = SMP_T_STR; + len = smp->data.data.meth.str.len; + smp->data.data.str.str = smp->data.data.meth.str.str; + smp->data.data.str.len = len; + smp->data.type = SMP_T_STR; } - else if (smp->data.meth.meth < HTTP_METH_OTHER) { + else if (smp->data.data.meth.meth < HTTP_METH_OTHER) { /* The method is known, copy the pointer containing the string. */ - meth = smp->data.meth.meth; - smp->data.str.str = http_known_methods[meth].name; - smp->data.str.len = http_known_methods[meth].len; + meth = smp->data.data.meth.meth; + smp->data.data.str.str = http_known_methods[meth].name; + smp->data.data.str.len = http_known_methods[meth].len; smp->flags |= SMP_F_CONST; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; } else { /* Unknown method */ @@ -745,19 +745,19 @@ static int c_addr2bin(struct sample *smp) { struct chunk *chk = get_trash_chunk(); - if (smp->type == SMP_T_IPV4) { + if (smp->data.type == SMP_T_IPV4) { chk->len = 4; - memcpy(chk->str, &smp->data.ipv4, chk->len); + memcpy(chk->str, &smp->data.data.ipv4, chk->len); } - else if (smp->type == SMP_T_IPV6) { + else if (smp->data.type == SMP_T_IPV6) { chk->len = 16; - memcpy(chk->str, &smp->data.ipv6, chk->len); + memcpy(chk->str, &smp->data.data.ipv6, chk->len); } else return 0; - smp->data.str = *chk; - smp->type = SMP_T_BIN; + smp->data.data.str = *chk; + smp->data.type = SMP_T_BIN; return 1; } @@ -765,11 +765,11 @@ static int c_int2bin(struct sample *smp) { struct chunk *chk = get_trash_chunk(); - *(unsigned long long int *)chk->str = htonll(smp->data.sint); + *(unsigned long long int *)chk->str = htonll(smp->data.data.sint); chk->len = 8; - smp->data.str = *chk; - smp->type = SMP_T_BIN; + smp->data.data.str = *chk; + smp->data.type = SMP_T_BIN; return 1; } @@ -1054,11 +1054,11 @@ struct sample *sample_process(struct proxy *px, struct session *sess, * - c_none => nothing to do (let's optimize it) * - other => apply cast and prepare to fail */ - if (!sample_casts[p->type][conv_expr->conv->in_type]) + if (!sample_casts[p->data.type][conv_expr->conv->in_type]) return NULL; - if (sample_casts[p->type][conv_expr->conv->in_type] != c_none && - !sample_casts[p->type][conv_expr->conv->in_type](p)) + if (sample_casts[p->data.type][conv_expr->conv->in_type] != c_none && + !sample_casts[p->data.type][conv_expr->conv->in_type](p)) return NULL; /* OK cast succeeded */ @@ -1358,10 +1358,10 @@ struct sample *sample_fetch_as_type(struct proxy *px, struct session *sess, return NULL; } - if (!sample_casts[smp->type][smp_type]) + if (!sample_casts[smp->data.type][smp_type]) return NULL; - if (!sample_casts[smp->type][smp_type](smp)) + if (!sample_casts[smp->data.type][smp_type](smp)) return NULL; smp->flags &= ~SMP_F_MAY_CHANGE; @@ -1380,8 +1380,8 @@ static int sample_conv_debug(const struct arg *arg_p, struct sample *smp, void * struct sample tmp; if (!(global.mode & MODE_QUIET) || (global.mode & (MODE_VERBOSE | MODE_STARTING))) { - fprintf(stderr, "[debug converter] type: %s ", smp_to_type[smp->type]); - if (!sample_casts[smp->type][SMP_T_STR]) { + fprintf(stderr, "[debug converter] type: %s ", smp_to_type[smp->data.type]); + if (!sample_casts[smp->data.type][SMP_T_STR]) { fprintf(stderr, "(undisplayable)"); } else { @@ -1391,15 +1391,15 @@ static int sample_conv_debug(const struct arg *arg_p, struct sample *smp, void * memcpy(&tmp, smp, sizeof(struct sample)); tmp.flags = SMP_F_CONST; - if (!sample_casts[smp->type][SMP_T_STR](&tmp)) + if (!sample_casts[smp->data.type][SMP_T_STR](&tmp)) fprintf(stderr, "(undisplayable)"); else { /* Display the displayable chars*. */ fprintf(stderr, "<"); - for (i = 0; i < tmp.data.str.len; i++) { - if (isprint(tmp.data.str.str[i])) - fputc(tmp.data.str.str[i], stderr); + for (i = 0; i < tmp.data.data.str.len; i++) { + if (isprint(tmp.data.data.str.str[i])) + fputc(tmp.data.data.str.str[i], stderr); else fputc('.', stderr); } @@ -1417,13 +1417,13 @@ static int sample_conv_bin2base64(const struct arg *arg_p, struct sample *smp, v int b64_len; trash->len = 0; - b64_len = a2base64(smp->data.str.str, smp->data.str.len, trash->str, trash->size); + b64_len = a2base64(smp->data.data.str.str, smp->data.data.str.len, trash->str, trash->size); if (b64_len < 0) return 0; trash->len = b64_len; - smp->data.str = *trash; - smp->type = SMP_T_STR; + smp->data.data.str = *trash; + smp->data.type = SMP_T_STR; smp->flags &= ~SMP_F_CONST; return 1; } @@ -1435,13 +1435,13 @@ static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp, void int ptr = 0; trash->len = 0; - while (ptr < smp->data.str.len && trash->len <= trash->size - 2) { - c = smp->data.str.str[ptr++]; + while (ptr < smp->data.data.str.len && trash->len <= trash->size - 2) { + c = smp->data.data.str.str[ptr++]; trash->str[trash->len++] = hextab[(c >> 4) & 0xF]; trash->str[trash->len++] = hextab[c & 0xF]; } - smp->data.str = *trash; - smp->type = SMP_T_STR; + smp->data.data.str = *trash; + smp->data.type = SMP_T_STR; smp->flags &= ~SMP_F_CONST; return 1; } @@ -1449,10 +1449,10 @@ static int sample_conv_bin2hex(const struct arg *arg_p, struct sample *smp, void /* hashes the binary input into a 32-bit unsigned int */ static int sample_conv_djb2(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = hash_djb2(smp->data.str.str, smp->data.str.len); + smp->data.data.sint = hash_djb2(smp->data.data.str.str, smp->data.data.str.len); if (arg_p && arg_p->data.sint) - smp->data.sint = full_hash(smp->data.sint); - smp->type = SMP_T_SINT; + smp->data.data.sint = full_hash(smp->data.data.sint); + smp->data.type = SMP_T_SINT; return 1; } @@ -1463,12 +1463,12 @@ static int sample_conv_str2lower(const struct arg *arg_p, struct sample *smp, vo if (!smp_dup(smp)) return 0; - if (!smp->data.str.size) + if (!smp->data.data.str.size) return 0; - for (i = 0; i < smp->data.str.len; i++) { - if ((smp->data.str.str[i] >= 'A') && (smp->data.str.str[i] <= 'Z')) - smp->data.str.str[i] += 'a' - 'A'; + for (i = 0; i < smp->data.data.str.len; i++) { + if ((smp->data.data.str.str[i] >= 'A') && (smp->data.data.str.str[i] <= 'Z')) + smp->data.data.str.str[i] += 'a' - 'A'; } return 1; } @@ -1480,12 +1480,12 @@ static int sample_conv_str2upper(const struct arg *arg_p, struct sample *smp, vo if (!smp_dup(smp)) return 0; - if (!smp->data.str.size) + if (!smp->data.data.str.size) return 0; - for (i = 0; i < smp->data.str.len; i++) { - if ((smp->data.str.str[i] >= 'a') && (smp->data.str.str[i] <= 'z')) - smp->data.str.str[i] += 'A' - 'a'; + for (i = 0; i < smp->data.data.str.len; i++) { + if ((smp->data.data.str.str[i] >= 'a') && (smp->data.data.str.str[i] <= 'z')) + smp->data.data.str.str[i] += 'A' - 'a'; } return 1; } @@ -1493,8 +1493,8 @@ static int sample_conv_str2upper(const struct arg *arg_p, struct sample *smp, vo /* takes the netmask in arg_p */ static int sample_conv_ipmask(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.ipv4.s_addr &= arg_p->data.ipv4.s_addr; - smp->type = SMP_T_IPV4; + smp->data.data.ipv4.s_addr &= arg_p->data.ipv4.s_addr; + smp->data.type = SMP_T_IPV4; return 1; } @@ -1506,7 +1506,7 @@ static int sample_conv_ltime(const struct arg *args, struct sample *smp, void *p { struct chunk *temp; /* With high numbers, the date returned can be negative, the 55 bits mask prevent this. */ - time_t curr_date = smp->data.sint & 0x007fffffffffffffLL; + time_t curr_date = smp->data.data.sint & 0x007fffffffffffffLL; struct tm *tm; /* add offset */ @@ -1518,18 +1518,18 @@ static int sample_conv_ltime(const struct arg *args, struct sample *smp, void *p return 0; temp = get_trash_chunk(); temp->len = strftime(temp->str, temp->size, args[0].data.str.str, tm); - smp->data.str = *temp; - smp->type = SMP_T_STR; + smp->data.data.str = *temp; + smp->data.type = SMP_T_STR; return 1; } /* hashes the binary input into a 32-bit unsigned int */ static int sample_conv_sdbm(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = hash_sdbm(smp->data.str.str, smp->data.str.len); + smp->data.data.sint = hash_sdbm(smp->data.data.str.str, smp->data.data.str.len); if (arg_p && arg_p->data.sint) - smp->data.sint = full_hash(smp->data.sint); - smp->type = SMP_T_SINT; + smp->data.data.sint = full_hash(smp->data.data.sint); + smp->data.type = SMP_T_SINT; return 1; } @@ -1541,7 +1541,7 @@ static int sample_conv_utime(const struct arg *args, struct sample *smp, void *p { struct chunk *temp; /* With high numbers, the date returned can be negative, the 55 bits mask prevent this. */ - time_t curr_date = smp->data.sint & 0x007fffffffffffffLL; + time_t curr_date = smp->data.data.sint & 0x007fffffffffffffLL; struct tm *tm; /* add offset */ @@ -1553,28 +1553,28 @@ static int sample_conv_utime(const struct arg *args, struct sample *smp, void *p return 0; temp = get_trash_chunk(); temp->len = strftime(temp->str, temp->size, args[0].data.str.str, tm); - smp->data.str = *temp; - smp->type = SMP_T_STR; + smp->data.data.str = *temp; + smp->data.type = SMP_T_STR; return 1; } /* hashes the binary input into a 32-bit unsigned int */ static int sample_conv_wt6(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = hash_wt6(smp->data.str.str, smp->data.str.len); + smp->data.data.sint = hash_wt6(smp->data.data.str.str, smp->data.data.str.len); if (arg_p && arg_p->data.sint) - smp->data.sint = full_hash(smp->data.sint); - smp->type = SMP_T_SINT; + smp->data.data.sint = full_hash(smp->data.data.sint); + smp->data.type = SMP_T_SINT; return 1; } /* hashes the binary input into a 32-bit unsigned int */ static int sample_conv_crc32(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = hash_crc32(smp->data.str.str, smp->data.str.len); + smp->data.data.sint = hash_crc32(smp->data.data.str.str, smp->data.data.str.len); if (arg_p && arg_p->data.sint) - smp->data.sint = full_hash(smp->data.sint); - smp->type = SMP_T_SINT; + smp->data.data.sint = full_hash(smp->data.data.sint); + smp->data.type = SMP_T_SINT; return 1; } @@ -1666,8 +1666,8 @@ static int sample_conv_json(const struct arg *arg_p, struct sample *smp, void *p temp = get_trash_chunk(); temp->len = 0; - p = smp->data.str.str; - while (p < smp->data.str.str + smp->data.str.len) { + p = smp->data.data.str.str; + while (p < smp->data.data.str.str + smp->data.data.str.len) { if (input_type == IT_ASCII) { /* Read input as ASCII. */ @@ -1676,7 +1676,7 @@ static int sample_conv_json(const struct arg *arg_p, struct sample *smp, void *p } else { /* Read input as UTF8. */ - ret = utf8_next(p, smp->data.str.len - ( p - smp->data.str.str ), &c); + ret = utf8_next(p, smp->data.data.str.len - ( p - smp->data.data.str.str ), &c); p += utf8_return_length(ret); if (input_type == IT_UTF8 && utf8_return_code(ret) != UTF8_CODE_OK) @@ -1754,8 +1754,8 @@ static int sample_conv_json(const struct arg *arg_p, struct sample *smp, void *p } smp->flags &= ~SMP_F_CONST; - smp->data.str = *temp; - smp->type = SMP_T_STR; + smp->data.data.str = *temp; + smp->data.type = SMP_T_STR; return 1; } @@ -1765,18 +1765,18 @@ static int sample_conv_json(const struct arg *arg_p, struct sample *smp, void *p * Optional second arg is the length to truncate */ static int sample_conv_bytes(const struct arg *arg_p, struct sample *smp, void *private) { - if (smp->data.str.len <= arg_p[0].data.sint) { - smp->data.str.len = 0; + if (smp->data.data.str.len <= arg_p[0].data.sint) { + smp->data.data.str.len = 0; return 1; } - if (smp->data.str.size) - smp->data.str.size -= arg_p[0].data.sint; - smp->data.str.len -= arg_p[0].data.sint; - smp->data.str.str += arg_p[0].data.sint; + if (smp->data.data.str.size) + smp->data.data.str.size -= arg_p[0].data.sint; + smp->data.data.str.len -= arg_p[0].data.sint; + smp->data.data.str.str += arg_p[0].data.sint; - if ((arg_p[1].type == ARGT_SINT) && (arg_p[1].data.sint < smp->data.str.len)) - smp->data.str.len = arg_p[1].data.sint; + if ((arg_p[1].type == ARGT_SINT) && (arg_p[1].data.sint < smp->data.data.str.len)) + smp->data.data.str.len = arg_p[1].data.sint; return 1; } @@ -1830,8 +1830,8 @@ static int sample_conv_field(const struct arg *arg_p, struct sample *smp, void * return 0; field = 1; - end = start = smp->data.str.str; - while (end - smp->data.str.str < smp->data.str.len) { + end = start = smp->data.data.str.str; + while (end - smp->data.data.str.str < smp->data.data.str.len) { for (i = 0 ; i < arg_p[1].data.str.len ; i++) { if (*end == arg_p[1].data.str.str[i]) { @@ -1847,22 +1847,22 @@ static int sample_conv_field(const struct arg *arg_p, struct sample *smp, void * /* Field not found */ if (field != arg_p[0].data.sint) { - smp->data.str.len = 0; + smp->data.data.str.len = 0; return 1; } found: - smp->data.str.len = end - start; + smp->data.data.str.len = end - start; /* If ret string is len 0, no need to change pointers or to update size */ - if (!smp->data.str.len) + if (!smp->data.data.str.len) return 1; - smp->data.str.str = start; + smp->data.data.str.str = start; /* Compute remaining size if needed - Note: smp->data.str.size cannot be set to 0 */ - if (smp->data.str.size) - smp->data.str.size -= start - smp->data.str.str; + Note: smp->data.data.str.size cannot be set to 0 */ + if (smp->data.data.str.size) + smp->data.data.str.size -= start - smp->data.data.str.str; return 1; } @@ -1882,8 +1882,8 @@ static int sample_conv_word(const struct arg *arg_p, struct sample *smp, void *p word = 0; inword = 0; - end = start = smp->data.str.str; - while (end - smp->data.str.str < smp->data.str.len) { + end = start = smp->data.data.str.str; + while (end - smp->data.data.str.str < smp->data.data.str.len) { issep = 0; for (i = 0 ; i < arg_p[1].data.str.len ; i++) { if (*end == arg_p[1].data.str.str[i]) { @@ -1908,22 +1908,22 @@ static int sample_conv_word(const struct arg *arg_p, struct sample *smp, void *p /* Field not found */ if (word != arg_p[0].data.sint) { - smp->data.str.len = 0; + smp->data.data.str.len = 0; return 1; } found: - smp->data.str.len = end - start; + smp->data.data.str.len = end - start; /* If ret string is len 0, no need to change pointers or to update size */ - if (!smp->data.str.len) + if (!smp->data.data.str.len) return 1; - smp->data.str.str = start; + smp->data.data.str.str = start; /* Compute remaining size if needed - Note: smp->data.str.size cannot be set to 0 */ - if (smp->data.str.size) - smp->data.str.size -= start - smp->data.str.str; + Note: smp->data.data.str.size cannot be set to 0 */ + if (smp->data.data.str.size) + smp->data.data.str.size -= start - smp->data.data.str.str; return 1; } @@ -1974,8 +1974,8 @@ static int sample_conv_regsub(const struct arg *arg_p, struct sample *smp, void int flag, max; int found; - start = smp->data.str.str; - end = start + smp->data.str.len; + start = smp->data.data.str.str; + end = start + smp->data.data.str.len; flag = 0; while (1) { @@ -2030,7 +2030,7 @@ static int sample_conv_regsub(const struct arg *arg_p, struct sample *smp, void flag |= REG_NOTBOL; } - smp->data.str = *trash; + smp->data.data.str = *trash; return 1; } @@ -2070,15 +2070,15 @@ static inline int sample_conv_var2smp(const struct arg *arg, struct stream *strm { switch (arg->type) { case ARGT_SINT: - smp->type = SMP_T_SINT; - smp->data.sint = arg->data.sint; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = arg->data.sint; return 1; case ARGT_VAR: if (!vars_get_by_desc(&arg->data.var, strm, smp)) return 0; - if (!sample_casts[smp->type][SMP_T_SINT]) + if (!sample_casts[smp->data.type][SMP_T_SINT]) return 0; - if (!sample_casts[smp->type][SMP_T_SINT](smp)) + if (!sample_casts[smp->data.type][SMP_T_SINT](smp)) return 0; return 1; default: @@ -2091,7 +2091,7 @@ static inline int sample_conv_var2smp(const struct arg *arg, struct stream *strm */ static int sample_conv_binary_cpl(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = ~smp->data.sint; + smp->data.data.sint = ~smp->data.data.sint; return 1; } @@ -2104,7 +2104,7 @@ static int sample_conv_binary_and(const struct arg *arg_p, struct sample *smp, v if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; - smp->data.sint &= tmp.data.sint; + smp->data.data.sint &= tmp.data.data.sint; return 1; } @@ -2117,7 +2117,7 @@ static int sample_conv_binary_or(const struct arg *arg_p, struct sample *smp, vo if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; - smp->data.sint |= tmp.data.sint; + smp->data.data.sint |= tmp.data.data.sint; return 1; } @@ -2130,7 +2130,7 @@ static int sample_conv_binary_xor(const struct arg *arg_p, struct sample *smp, v if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; - smp->data.sint ^= tmp.data.sint; + smp->data.data.sint ^= tmp.data.data.sint; return 1; } @@ -2169,7 +2169,7 @@ static int sample_conv_arith_add(const struct arg *arg_p, struct sample *smp, vo if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; - smp->data.sint = arith_add(smp->data.sint, tmp.data.sint); + smp->data.data.sint = arith_add(smp->data.data.sint, tmp.data.data.sint); return 1; } @@ -2188,17 +2188,17 @@ static int sample_conv_arith_sub(const struct arg *arg_p, * than abs(LLONG_MAX). So, the following code use LLONG_MAX in place * of -LLONG_MIN and correct the result. */ - if (tmp.data.sint == LLONG_MIN) { - smp->data.sint = arith_add(smp->data.sint, LLONG_MAX); - if (smp->data.sint < LLONG_MAX) - smp->data.sint++; + if (tmp.data.data.sint == LLONG_MIN) { + smp->data.data.sint = arith_add(smp->data.data.sint, LLONG_MAX); + if (smp->data.data.sint < LLONG_MAX) + smp->data.data.sint++; return 1; } /* standard substraction: we use the "add" function and negate * the second operand. */ - smp->data.sint = arith_add(smp->data.sint, -tmp.data.sint); + smp->data.data.sint = arith_add(smp->data.data.sint, -tmp.data.data.sint); return 1; } @@ -2217,32 +2217,32 @@ static int sample_conv_arith_mul(const struct arg *arg_p, return 0; /* prevent divide by 0 during the check */ - if (!smp->data.sint || !tmp.data.sint) { - smp->data.sint = 0; + if (!smp->data.data.sint || !tmp.data.data.sint) { + smp->data.data.sint = 0; return 1; } /* The multiply between LLONG_MIN and -1 returns a * "floting point exception". */ - if (smp->data.sint == LLONG_MIN && tmp.data.sint == -1) { - smp->data.sint = LLONG_MAX; + if (smp->data.data.sint == LLONG_MIN && tmp.data.data.sint == -1) { + smp->data.data.sint = LLONG_MAX; return 1; } /* execute standard multiplication. */ - c = smp->data.sint * tmp.data.sint; + c = smp->data.data.sint * tmp.data.data.sint; /* check for overflow and makes capped multiply. */ - if (smp->data.sint != c / tmp.data.sint) { - if ((smp->data.sint < 0) == (tmp.data.sint < 0)) { - smp->data.sint = LLONG_MAX; + if (smp->data.data.sint != c / tmp.data.data.sint) { + if ((smp->data.data.sint < 0) == (tmp.data.data.sint < 0)) { + smp->data.data.sint = LLONG_MAX; return 1; } - smp->data.sint = LLONG_MIN; + smp->data.data.sint = LLONG_MIN; return 1; } - smp->data.sint = c; + smp->data.data.sint = c; return 1; } @@ -2259,18 +2259,18 @@ static int sample_conv_arith_div(const struct arg *arg_p, if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; - if (tmp.data.sint) { + if (tmp.data.data.sint) { /* The divide between LLONG_MIN and -1 returns a * "floting point exception". */ - if (smp->data.sint == LLONG_MIN && tmp.data.sint == -1) { - smp->data.sint = LLONG_MAX; + if (smp->data.data.sint == LLONG_MIN && tmp.data.data.sint == -1) { + smp->data.data.sint = LLONG_MAX; return 1; } - smp->data.sint /= tmp.data.sint; + smp->data.data.sint /= tmp.data.data.sint; return 1; } - smp->data.sint = LLONG_MAX; + smp->data.data.sint = LLONG_MAX; return 1; } @@ -2286,18 +2286,18 @@ static int sample_conv_arith_mod(const struct arg *arg_p, if (!sample_conv_var2smp(arg_p, smp->strm, &tmp)) return 0; - if (tmp.data.sint) { + if (tmp.data.data.sint) { /* The divide between LLONG_MIN and -1 returns a * "floting point exception". */ - if (smp->data.sint == LLONG_MIN && tmp.data.sint == -1) { - smp->data.sint = 0; + if (smp->data.data.sint == LLONG_MIN && tmp.data.data.sint == -1) { + smp->data.data.sint = 0; return 1; } - smp->data.sint %= tmp.data.sint; + smp->data.data.sint %= tmp.data.data.sint; return 1; } - smp->data.sint = 0; + smp->data.data.sint = 0; return 1; } @@ -2307,10 +2307,10 @@ static int sample_conv_arith_mod(const struct arg *arg_p, static int sample_conv_arith_neg(const struct arg *arg_p, struct sample *smp, void *private) { - if (smp->data.sint == LLONG_MIN) - smp->data.sint = LLONG_MAX; + if (smp->data.data.sint == LLONG_MIN) + smp->data.data.sint = LLONG_MAX; else - smp->data.sint = -smp->data.sint; + smp->data.data.sint = -smp->data.data.sint; return 1; } @@ -2320,8 +2320,8 @@ static int sample_conv_arith_neg(const struct arg *arg_p, static int sample_conv_arith_bool(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = !!smp->data.sint; - smp->type = SMP_T_BOOL; + smp->data.data.sint = !!smp->data.data.sint; + smp->data.type = SMP_T_BOOL; return 1; } @@ -2331,8 +2331,8 @@ static int sample_conv_arith_bool(const struct arg *arg_p, static int sample_conv_arith_not(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = !smp->data.sint; - smp->type = SMP_T_BOOL; + smp->data.data.sint = !smp->data.data.sint; + smp->data.type = SMP_T_BOOL; return 1; } @@ -2342,8 +2342,8 @@ static int sample_conv_arith_not(const struct arg *arg_p, static int sample_conv_arith_odd(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = smp->data.sint & 1; - smp->type = SMP_T_BOOL; + smp->data.data.sint = smp->data.data.sint & 1; + smp->data.type = SMP_T_BOOL; return 1; } @@ -2353,8 +2353,8 @@ static int sample_conv_arith_odd(const struct arg *arg_p, static int sample_conv_arith_even(const struct arg *arg_p, struct sample *smp, void *private) { - smp->data.sint = !(smp->data.sint & 1); - smp->type = SMP_T_BOOL; + smp->data.data.sint = !(smp->data.data.sint & 1); + smp->data.type = SMP_T_BOOL; return 1; } @@ -2366,8 +2366,8 @@ static int sample_conv_arith_even(const struct arg *arg_p, static int smp_fetch_true(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_BOOL; - smp->data.sint = 1; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = 1; return 1; } @@ -2375,8 +2375,8 @@ smp_fetch_true(const struct arg *args, struct sample *smp, const char *kw, void static int smp_fetch_false(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_BOOL; - smp->data.sint = 0; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = 0; return 1; } @@ -2393,10 +2393,10 @@ smp_fetch_env(const struct arg *args, struct sample *smp, const char *kw, void * if (!env) return 0; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; - smp->data.str.str = env; - smp->data.str.len = strlen(env); + smp->data.data.str.str = env; + smp->data.data.str.len = strlen(env); return 1; } @@ -2406,13 +2406,13 @@ smp_fetch_env(const struct arg *args, struct sample *smp, const char *kw, void * static int smp_fetch_date(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->data.sint = date.tv_sec; + smp->data.data.sint = date.tv_sec; /* add offset */ if (args && args[0].type == ARGT_SINT) - smp->data.sint += args[0].data.sint; + smp->data.data.sint += args[0].data.sint; - smp->type = SMP_T_SINT; + smp->data.type = SMP_T_SINT; smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE; return 1; } @@ -2421,8 +2421,8 @@ smp_fetch_date(const struct arg *args, struct sample *smp, const char *kw, void static int smp_fetch_nbproc(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_SINT; - smp->data.sint = global.nbproc; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = global.nbproc; return 1; } @@ -2430,8 +2430,8 @@ smp_fetch_nbproc(const struct arg *args, struct sample *smp, const char *kw, voi static int smp_fetch_proc(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_SINT; - smp->data.sint = relative_pid; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = relative_pid; return 1; } @@ -2441,13 +2441,13 @@ smp_fetch_proc(const struct arg *args, struct sample *smp, const char *kw, void static int smp_fetch_rand(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->data.sint = random(); + smp->data.data.sint = random(); /* reduce if needed. Don't do a modulo, use all bits! */ if (args && args[0].type == ARGT_SINT) - smp->data.sint = (smp->data.sint * args[0].data.sint) / ((u64)RAND_MAX+1); + smp->data.data.sint = (smp->data.data.sint * args[0].data.sint) / ((u64)RAND_MAX+1); - smp->type = SMP_T_SINT; + smp->data.type = SMP_T_SINT; smp->flags |= SMP_F_VOL_TEST | SMP_F_MAY_CHANGE; return 1; } @@ -2456,17 +2456,17 @@ smp_fetch_rand(const struct arg *args, struct sample *smp, const char *kw, void static int smp_fetch_stopping(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_BOOL; - smp->data.sint = stopping; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = stopping; return 1; } static int smp_fetch_const_str(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags |= SMP_F_CONST; - smp->type = SMP_T_STR; - smp->data.str.str = args[0].data.str.str; - smp->data.str.len = args[0].data.str.len; + smp->data.type = SMP_T_STR; + smp->data.data.str.str = args[0].data.str.str; + smp->data.data.str.len = args[0].data.str.len; return 1; } @@ -2490,29 +2490,29 @@ static int smp_check_const_bool(struct arg *args, char **err) static int smp_fetch_const_bool(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_BOOL; - smp->data.sint = args[0].data.sint; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = args[0].data.sint; return 1; } static int smp_fetch_const_int(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_SINT; - smp->data.sint = args[0].data.sint; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = args[0].data.sint; return 1; } static int smp_fetch_const_ipv4(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_IPV4; - smp->data.ipv4 = args[0].data.ipv4; + smp->data.type = SMP_T_IPV4; + smp->data.data.ipv4 = args[0].data.ipv4; return 1; } static int smp_fetch_const_ipv6(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_IPV6; - smp->data.ipv6 = args[0].data.ipv6; + smp->data.type = SMP_T_IPV6; + smp->data.data.ipv6 = args[0].data.ipv6; return 1; } @@ -2532,9 +2532,9 @@ static int smp_check_const_bin(struct arg *args, char **err) static int smp_fetch_const_bin(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags |= SMP_F_CONST; - smp->type = SMP_T_BIN; - smp->data.str.str = args[0].data.str.str; - smp->data.str.len = args[0].data.str.len; + smp->data.type = SMP_T_BIN; + smp->data.data.str.str = args[0].data.str.str; + smp->data.data.str.len = args[0].data.str.len; return 1; } @@ -2565,17 +2565,17 @@ static int smp_check_const_meth(struct arg *args, char **err) static int smp_fetch_const_meth(const struct arg *args, struct sample *smp, const char *kw, void *private) { - smp->type = SMP_T_METH; + smp->data.type = SMP_T_METH; if (args[0].type == ARGT_SINT) { smp->flags &= ~SMP_F_CONST; - smp->data.meth.meth = args[0].data.sint; - smp->data.meth.str.str = ""; - smp->data.meth.str.len = 0; + smp->data.data.meth.meth = args[0].data.sint; + smp->data.data.meth.str.str = ""; + smp->data.data.meth.str.len = 0; } else { smp->flags |= SMP_F_CONST; - smp->data.meth.meth = HTTP_METH_OTHER; - smp->data.meth.str.str = args[0].data.str.str; - smp->data.meth.str.len = args[0].data.str.len; + smp->data.data.meth.meth = HTTP_METH_OTHER; + smp->data.data.meth.str.str = args[0].data.str.str; + smp->data.data.meth.str.len = args[0].data.str.len; } return 1; } diff --git a/src/ssl_sock.c b/src/ssl_sock.c index 85ffd5fb77..120ea3d82e 100644 --- a/src/ssl_sock.c +++ b/src/ssl_sock.c @@ -3404,8 +3404,8 @@ smp_fetch_ssl_fc_has_crt(const struct arg *args, struct sample *smp, const char } smp->flags = 0; - smp->type = SMP_T_BOOL; - smp->data.sint = SSL_SOCK_ST_FL_VERIFY_DONE & conn->xprt_st ? 1 : 0; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = SSL_SOCK_ST_FL_VERIFY_DONE & conn->xprt_st ? 1 : 0; return 1; } @@ -3444,8 +3444,8 @@ smp_fetch_ssl_x_der(const struct arg *args, struct sample *smp, const char *kw, if (ssl_sock_crt2der(crt, smp_trash) <= 0) goto out; - smp->data.str = *smp_trash; - smp->type = SMP_T_BIN; + smp->data.data.str = *smp_trash; + smp->data.type = SMP_T_BIN; ret = 1; out: /* SSL_get_peer_certificate, it increase X509 * ref count */ @@ -3488,8 +3488,8 @@ smp_fetch_ssl_x_serial(const struct arg *args, struct sample *smp, const char *k if (ssl_sock_get_serial(crt, smp_trash) <= 0) goto out; - smp->data.str = *smp_trash; - smp->type = SMP_T_BIN; + smp->data.data.str = *smp_trash; + smp->data.type = SMP_T_BIN; ret = 1; out: /* SSL_get_peer_certificate, it increase X509 * ref count */ @@ -3532,8 +3532,8 @@ smp_fetch_ssl_x_sha1(const struct arg *args, struct sample *smp, const char *kw, digest = EVP_sha1(); X509_digest(crt, digest, (unsigned char *)smp_trash->str, (unsigned int *)&smp_trash->len); - smp->data.str = *smp_trash; - smp->type = SMP_T_BIN; + smp->data.data.str = *smp_trash; + smp->data.type = SMP_T_BIN; ret = 1; out: /* SSL_get_peer_certificate, it increase X509 * ref count */ @@ -3575,8 +3575,8 @@ smp_fetch_ssl_x_notafter(const struct arg *args, struct sample *smp, const char if (ssl_sock_get_time(X509_get_notAfter(crt), smp_trash) <= 0) goto out; - smp->data.str = *smp_trash; - smp->type = SMP_T_STR; + smp->data.data.str = *smp_trash; + smp->data.type = SMP_T_STR; ret = 1; out: /* SSL_get_peer_certificate, it increase X509 * ref count */ @@ -3632,8 +3632,8 @@ smp_fetch_ssl_x_i_dn(const struct arg *args, struct sample *smp, const char *kw, else if (ssl_sock_get_dn_oneline(name, smp_trash) <= 0) goto out; - smp->type = SMP_T_STR; - smp->data.str = *smp_trash; + smp->data.type = SMP_T_STR; + smp->data.data.str = *smp_trash; ret = 1; out: /* SSL_get_peer_certificate, it increase X509 * ref count */ @@ -3675,8 +3675,8 @@ smp_fetch_ssl_x_notbefore(const struct arg *args, struct sample *smp, const char if (ssl_sock_get_time(X509_get_notBefore(crt), smp_trash) <= 0) goto out; - smp->data.str = *smp_trash; - smp->type = SMP_T_STR; + smp->data.data.str = *smp_trash; + smp->data.type = SMP_T_STR; ret = 1; out: /* SSL_get_peer_certificate, it increase X509 * ref count */ @@ -3732,8 +3732,8 @@ smp_fetch_ssl_x_s_dn(const struct arg *args, struct sample *smp, const char *kw, else if (ssl_sock_get_dn_oneline(name, smp_trash) <= 0) goto out; - smp->type = SMP_T_STR; - smp->data.str = *smp_trash; + smp->data.type = SMP_T_STR; + smp->data.data.str = *smp_trash; ret = 1; out: /* SSL_get_peer_certificate, it increase X509 * ref count */ @@ -3764,8 +3764,8 @@ smp_fetch_ssl_c_used(const struct arg *args, struct sample *smp, const char *kw, X509_free(crt); } - smp->type = SMP_T_BOOL; - smp->data.sint = (crt != NULL); + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = (crt != NULL); return 1; } @@ -3796,11 +3796,11 @@ smp_fetch_ssl_x_version(const struct arg *args, struct sample *smp, const char * if (!crt) return 0; - smp->data.sint = (unsigned int)(1 + X509_get_version(crt)); + smp->data.data.sint = (unsigned int)(1 + X509_get_version(crt)); /* SSL_get_peer_certificate increase X509 * ref count */ if (cert_peer) X509_free(crt); - smp->type = SMP_T_SINT; + smp->data.type = SMP_T_SINT; return 1; } @@ -3835,17 +3835,17 @@ smp_fetch_ssl_x_sig_alg(const struct arg *args, struct sample *smp, const char * nid = OBJ_obj2nid((ASN1_OBJECT *)(crt->cert_info->signature->algorithm)); - smp->data.str.str = (char *)OBJ_nid2sn(nid); - if (!smp->data.str.str) { + smp->data.data.str.str = (char *)OBJ_nid2sn(nid); + if (!smp->data.data.str.str) { /* SSL_get_peer_certificate increase X509 * ref count */ if (cert_peer) X509_free(crt); return 0; } - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; - smp->data.str.len = strlen(smp->data.str.str); + smp->data.data.str.len = strlen(smp->data.data.str.str); /* SSL_get_peer_certificate increase X509 * ref count */ if (cert_peer) X509_free(crt); @@ -3883,17 +3883,17 @@ smp_fetch_ssl_x_key_alg(const struct arg *args, struct sample *smp, const char * nid = OBJ_obj2nid((ASN1_OBJECT *)(crt->cert_info->key->algor->algorithm)); - smp->data.str.str = (char *)OBJ_nid2sn(nid); - if (!smp->data.str.str) { + smp->data.data.str.str = (char *)OBJ_nid2sn(nid); + if (!smp->data.data.str.str) { /* SSL_get_peer_certificate increase X509 * ref count */ if (cert_peer) X509_free(crt); return 0; } - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; - smp->data.str.len = strlen(smp->data.str.str); + smp->data.data.str.len = strlen(smp->data.data.str.str); if (cert_peer) X509_free(crt); @@ -3910,8 +3910,8 @@ smp_fetch_ssl_fc(const struct arg *args, struct sample *smp, const char *kw, voi int back_conn = (kw[4] == 'b') ? 1 : 0; struct connection *conn = objt_conn(smp->strm->si[back_conn].end); - smp->type = SMP_T_BOOL; - smp->data.sint = (conn && conn->xprt == &ssl_sock); + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = (conn && conn->xprt == &ssl_sock); return 1; } @@ -3922,8 +3922,8 @@ smp_fetch_ssl_fc_has_sni(const struct arg *args, struct sample *smp, const char #ifdef SSL_CTRL_SET_TLSEXT_HOSTNAME struct connection *conn = objt_conn(smp->sess->origin); - smp->type = SMP_T_BOOL; - smp->data.sint = (conn && conn->xprt == &ssl_sock) && + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = (conn && conn->xprt == &ssl_sock) && conn->xprt_ctx && SSL_get_servername(conn->xprt_ctx, TLSEXT_NAMETYPE_host_name) != NULL; return 1; @@ -3938,8 +3938,8 @@ smp_fetch_ssl_fc_is_resumed(const struct arg *args, struct sample *smp, const ch { struct connection *conn = objt_conn(smp->sess->origin); - smp->type = SMP_T_BOOL; - smp->data.sint = (conn && conn->xprt == &ssl_sock) && + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = (conn && conn->xprt == &ssl_sock) && conn->xprt_ctx && SSL_session_reused(conn->xprt_ctx); return 1; @@ -3961,13 +3961,13 @@ smp_fetch_ssl_fc_cipher(const struct arg *args, struct sample *smp, const char * if (!conn || !conn->xprt_ctx || conn->xprt != &ssl_sock) return 0; - smp->data.str.str = (char *)SSL_get_cipher_name(conn->xprt_ctx); - if (!smp->data.str.str) + smp->data.data.str.str = (char *)SSL_get_cipher_name(conn->xprt_ctx); + if (!smp->data.data.str.str) return 0; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags |= SMP_F_CONST; - smp->data.str.len = strlen(smp->data.str.str); + smp->data.data.str.len = strlen(smp->data.data.str.str); return 1; } @@ -3993,8 +3993,8 @@ smp_fetch_ssl_fc_alg_keysize(const struct arg *args, struct sample *smp, const c if (!SSL_get_cipher_bits(conn->xprt_ctx, &sint)) return 0; - smp->data.sint = sint; - smp->type = SMP_T_SINT; + smp->data.data.sint = sint; + smp->data.type = SMP_T_SINT; return 1; } @@ -4015,11 +4015,11 @@ smp_fetch_ssl_fc_use_keysize(const struct arg *args, struct sample *smp, const c if (!conn || !conn->xprt_ctx || conn->xprt != &ssl_sock) return 0; - smp->data.sint = (unsigned int)SSL_get_cipher_bits(conn->xprt_ctx, NULL); - if (!smp->data.sint) + smp->data.data.sint = (unsigned int)SSL_get_cipher_bits(conn->xprt_ctx, NULL); + if (!smp->data.data.sint) return 0; - smp->type = SMP_T_SINT; + smp->data.type = SMP_T_SINT; return 1; } @@ -4031,17 +4031,17 @@ smp_fetch_ssl_fc_npn(const struct arg *args, struct sample *smp, const char *kw, struct connection *conn; smp->flags = SMP_F_CONST; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; conn = objt_conn(smp->sess->origin); if (!conn || !conn->xprt_ctx || conn->xprt != &ssl_sock) return 0; - smp->data.str.str = NULL; + smp->data.data.str.str = NULL; SSL_get0_next_proto_negotiated(conn->xprt_ctx, - (const unsigned char **)&smp->data.str.str, (unsigned *)&smp->data.str.len); + (const unsigned char **)&smp->data.data.str.str, (unsigned *)&smp->data.data.str.len); - if (!smp->data.str.str) + if (!smp->data.data.str.str) return 0; return 1; @@ -4055,17 +4055,17 @@ smp_fetch_ssl_fc_alpn(const struct arg *args, struct sample *smp, const char *kw struct connection *conn; smp->flags = SMP_F_CONST; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; conn = objt_conn(smp->sess->origin); if (!conn || !conn->xprt_ctx || conn->xprt != &ssl_sock) return 0; - smp->data.str.str = NULL; + smp->data.data.str.str = NULL; SSL_get0_alpn_selected(conn->xprt_ctx, - (const unsigned char **)&smp->data.str.str, (unsigned *)&smp->data.str.len); + (const unsigned char **)&smp->data.data.str.str, (unsigned *)&smp->data.data.str.len); - if (!smp->data.str.str) + if (!smp->data.data.str.str) return 0; return 1; @@ -4088,13 +4088,13 @@ smp_fetch_ssl_fc_protocol(const struct arg *args, struct sample *smp, const char if (!conn || !conn->xprt_ctx || conn->xprt != &ssl_sock) return 0; - smp->data.str.str = (char *)SSL_get_version(conn->xprt_ctx); - if (!smp->data.str.str) + smp->data.data.str.str = (char *)SSL_get_version(conn->xprt_ctx); + if (!smp->data.data.str.str) return 0; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; smp->flags = SMP_F_CONST; - smp->data.str.len = strlen(smp->data.str.str); + smp->data.data.str.len = strlen(smp->data.data.str.str); return 1; } @@ -4112,7 +4112,7 @@ smp_fetch_ssl_fc_session_id(const struct arg *args, struct sample *smp, const ch struct connection *conn; smp->flags = SMP_F_CONST; - smp->type = SMP_T_BIN; + smp->data.type = SMP_T_BIN; conn = objt_conn(smp->strm->si[back_conn].end); if (!conn || !conn->xprt_ctx || conn->xprt != &ssl_sock) @@ -4122,8 +4122,8 @@ smp_fetch_ssl_fc_session_id(const struct arg *args, struct sample *smp, const ch if (!ssl_sess) return 0; - smp->data.str.str = (char *)SSL_SESSION_get_id(ssl_sess, (unsigned int *)&smp->data.str.len); - if (!smp->data.str.str || !smp->data.str.len) + smp->data.data.str.str = (char *)SSL_SESSION_get_id(ssl_sess, (unsigned int *)&smp->data.data.str.len); + if (!smp->data.data.str.str || !smp->data.data.str.len) return 0; return 1; @@ -4139,17 +4139,17 @@ smp_fetch_ssl_fc_sni(const struct arg *args, struct sample *smp, const char *kw, struct connection *conn; smp->flags = SMP_F_CONST; - smp->type = SMP_T_STR; + smp->data.type = SMP_T_STR; conn = objt_conn(smp->sess->origin); if (!conn || !conn->xprt_ctx || conn->xprt != &ssl_sock) return 0; - smp->data.str.str = (char *)SSL_get_servername(conn->xprt_ctx, TLSEXT_NAMETYPE_host_name); - if (!smp->data.str.str) + smp->data.data.str.str = (char *)SSL_get_servername(conn->xprt_ctx, TLSEXT_NAMETYPE_host_name); + if (!smp->data.data.str.str) return 0; - smp->data.str.len = strlen(smp->data.str.str); + smp->data.data.str.len = strlen(smp->data.data.str.str); return 1; #else return 0; @@ -4186,8 +4186,8 @@ smp_fetch_ssl_fc_unique_id(const struct arg *args, struct sample *smp, const cha return 0; finished_trash->len = finished_len; - smp->data.str = *finished_trash; - smp->type = SMP_T_BIN; + smp->data.data.str = *finished_trash; + smp->data.type = SMP_T_BIN; return 1; #else @@ -4210,8 +4210,8 @@ smp_fetch_ssl_c_ca_err(const struct arg *args, struct sample *smp, const char *k return 0; } - smp->type = SMP_T_SINT; - smp->data.sint = (unsigned long long int)SSL_SOCK_ST_TO_CA_ERROR(conn->xprt_st); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = (unsigned long long int)SSL_SOCK_ST_TO_CA_ERROR(conn->xprt_st); smp->flags = 0; return 1; @@ -4232,8 +4232,8 @@ smp_fetch_ssl_c_ca_err_depth(const struct arg *args, struct sample *smp, const c return 0; } - smp->type = SMP_T_SINT; - smp->data.sint = (long long int)SSL_SOCK_ST_TO_CAEDEPTH(conn->xprt_st); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = (long long int)SSL_SOCK_ST_TO_CAEDEPTH(conn->xprt_st); smp->flags = 0; return 1; @@ -4254,8 +4254,8 @@ smp_fetch_ssl_c_err(const struct arg *args, struct sample *smp, const char *kw, return 0; } - smp->type = SMP_T_SINT; - smp->data.sint = (long long int)SSL_SOCK_ST_TO_CRTERROR(conn->xprt_st); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = (long long int)SSL_SOCK_ST_TO_CRTERROR(conn->xprt_st); smp->flags = 0; return 1; @@ -4279,8 +4279,8 @@ smp_fetch_ssl_c_verify(const struct arg *args, struct sample *smp, const char *k if (!conn->xprt_ctx) return 0; - smp->type = SMP_T_SINT; - smp->data.sint = (long long int)SSL_get_verify_result(conn->xprt_ctx); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = (long long int)SSL_get_verify_result(conn->xprt_ctx); smp->flags = 0; return 1; diff --git a/src/stick_table.c b/src/stick_table.c index 243066e59b..7559bc6d97 100644 --- a/src/stick_table.c +++ b/src/stick_table.c @@ -458,65 +458,65 @@ int stktable_parse_type(char **args, int *myidx, unsigned long *type, size_t *ke static void *k_int2int(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - kdata->integer = smp->data.sint; + kdata->integer = smp->data.data.sint; return (void *)&kdata->integer; } static void *k_ip2ip(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - if (smp->type == SMP_T_IPV6) { - v6tov4(&kdata->ip, &smp->data.ipv6); + if (smp->data.type == SMP_T_IPV6) { + v6tov4(&kdata->ip, &smp->data.data.ipv6); return (void *)&kdata->ip.s_addr; } else { - return (void *)&smp->data.ipv4.s_addr; + return (void *)&smp->data.data.ipv4.s_addr; } } static void *k_ip2ipv6(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - if (smp->type == SMP_T_IPV6) { - return (void *)&smp->data.ipv6.s6_addr; + if (smp->data.type == SMP_T_IPV6) { + return (void *)&smp->data.data.ipv6.s6_addr; } else { - v4tov6(&kdata->ipv6, &smp->data.ipv4); + v4tov6(&kdata->ipv6, &smp->data.data.ipv4); return (void *)&kdata->ipv6.s6_addr; } } static void *k_ip2int(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - if (smp->type == SMP_T_IPV6) { - if (!v6tov4(&kdata->ip, &smp->data.ipv6)) + if (smp->data.type == SMP_T_IPV6) { + if (!v6tov4(&kdata->ip, &smp->data.data.ipv6)) return NULL; kdata->integer = ntohl(kdata->ip.s_addr); } else { - kdata->integer = ntohl(smp->data.ipv4.s_addr); + kdata->integer = ntohl(smp->data.data.ipv4.s_addr); } return (void *)&kdata->integer; } static void *k_int2ip(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - kdata->ip.s_addr = htonl((unsigned int)smp->data.sint); + kdata->ip.s_addr = htonl((unsigned int)smp->data.data.sint); return (void *)&kdata->ip.s_addr; } static void *k_str2str(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - *len = smp->data.str.len; - return (void *)smp->data.str.str; + *len = smp->data.data.str.len; + return (void *)smp->data.data.str.str; } static void *k_ip2str(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - if (smp->type == SMP_T_IPV6) { - if (!inet_ntop(AF_INET6, &smp->data.ipv6, kdata->buf, *len)) + if (smp->data.type == SMP_T_IPV6) { + if (!inet_ntop(AF_INET6, &smp->data.data.ipv6, kdata->buf, *len)) return NULL; } else { - if (!inet_ntop(AF_INET, &smp->data.ipv4, kdata->buf, *len)) + if (!inet_ntop(AF_INET, &smp->data.data.ipv4, kdata->buf, *len)) return NULL; } @@ -526,15 +526,15 @@ static void *k_ip2str(struct sample *smp, union stktable_key_data *kdata, size_t static void *k_ip2bin(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - if (smp->type == SMP_T_IPV4) { + if (smp->data.type == SMP_T_IPV4) { if (*len > 4) *len = 4; - memcpy(kdata->buf, &smp->data.ipv4, *len); + memcpy(kdata->buf, &smp->data.data.ipv4, *len); } - else if (smp->type == SMP_T_IPV6) { + else if (smp->data.type == SMP_T_IPV6) { if (*len > 16) *len = 16; - memcpy(kdata->buf, &smp->data.ipv6, *len); + memcpy(kdata->buf, &smp->data.data.ipv6, *len); } else *len = 0; @@ -548,8 +548,8 @@ static void *k_bin2str(struct sample *smp, union stktable_key_data *kdata, size_ int max = *len; int size = 0; - while (ptr < smp->data.str.len && size <= max - 2) { - c = smp->data.str.str[ptr++]; + while (ptr < smp->data.data.str.len && size <= max - 2) { + c = smp->data.data.str.str[ptr++]; kdata->buf[size++] = hextab[(c >> 4) & 0xF]; kdata->buf[size++] = hextab[c & 0xF]; } @@ -561,7 +561,7 @@ static void *k_int2str(struct sample *smp, union stktable_key_data *kdata, size_ { void *key; - key = (void *)lltoa_r(smp->data.sint, kdata->buf, *len); + key = (void *)lltoa_r(smp->data.data.sint, kdata->buf, *len); if (!key) return NULL; @@ -571,7 +571,7 @@ static void *k_int2str(struct sample *smp, union stktable_key_data *kdata, size_ static void *k_str2ip(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - if (!buf2ip(smp->data.str.str, smp->data.str.len, &kdata->ip)) + if (!buf2ip(smp->data.data.str.str, smp->data.data.str.len, &kdata->ip)) return NULL; return (void *)&kdata->ip.s_addr; @@ -579,7 +579,7 @@ static void *k_str2ip(struct sample *smp, union stktable_key_data *kdata, size_t static void *k_str2ipv6(struct sample *smp, union stktable_key_data *kdata, size_t *len) { - if (!inet_pton(AF_INET6, smp->data.str.str, &kdata->ipv6)) + if (!inet_pton(AF_INET6, smp->data.data.str.str, &kdata->ipv6)) return NULL; return (void *)&kdata->ipv6.s6_addr; @@ -590,8 +590,8 @@ static void *k_str2int(struct sample *smp, union stktable_key_data *kdata, size_ int i; kdata->integer = 0; - for (i = 0; i < smp->data.str.len; i++) { - uint32_t val = smp->data.str.str[i] - '0'; + for (i = 0; i < smp->data.data.str.len; i++) { + uint32_t val = smp->data.data.str.str[i] - '0'; if (val > 9) break; @@ -628,11 +628,11 @@ static sample_to_key_fct sample_to_key[SMP_TYPES][STKTABLE_TYPES] = { */ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) { - if (!sample_to_key[smp->type][t->type]) + if (!sample_to_key[smp->data.type][t->type]) return NULL; static_table_key->key_len = t->key_size; - static_table_key->key = sample_to_key[smp->type][t->type](smp, &static_table_key->data, &static_table_key->key_len); + static_table_key->key = sample_to_key[smp->data.type][t->type](smp, &static_table_key->data, &static_table_key->key_len); if (!static_table_key->key) return NULL; @@ -643,7 +643,7 @@ struct stktable_key *smp_to_stkey(struct sample *smp, struct stktable *t) if ((static_table_key->key_len < t->key_size) && (t->type != STKTABLE_TYPE_STRING)) { /* need padding with null */ - /* assume static_table_key.key_len is less than sizeof(static_table_key.data.buf) + /* assume static_table_key.key_len is less than sizeof(static_table_key.data.data.buf) cause t->key_size is necessary less than sizeof(static_table_key.data) */ if ((char *)static_table_key->key > (char *)&static_table_key->data && @@ -811,8 +811,8 @@ static int sample_conv_in_table(const struct arg *arg_p, struct sample *smp, voi ts = stktable_lookup_key(t, key); - smp->type = SMP_T_BOOL; - smp->data.sint = !!ts; + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = !!ts; smp->flags = SMP_F_VOL_TEST; return 1; } @@ -837,8 +837,8 @@ static int sample_conv_table_bytes_in_rate(const struct arg *arg_p, struct sampl return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -848,7 +848,7 @@ static int sample_conv_table_bytes_in_rate(const struct arg *arg_p, struct sampl if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), t->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); return 1; } @@ -873,8 +873,8 @@ static int sample_conv_table_conn_cnt(const struct arg *arg_p, struct sample *sm return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -884,7 +884,7 @@ static int sample_conv_table_conn_cnt(const struct arg *arg_p, struct sample *sm if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, conn_cnt); + smp->data.data.sint = stktable_data_cast(ptr, conn_cnt); return 1; } @@ -908,8 +908,8 @@ static int sample_conv_table_conn_cur(const struct arg *arg_p, struct sample *sm return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -919,7 +919,7 @@ static int sample_conv_table_conn_cur(const struct arg *arg_p, struct sample *sm if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, conn_cur); + smp->data.data.sint = stktable_data_cast(ptr, conn_cur); return 1; } @@ -943,8 +943,8 @@ static int sample_conv_table_conn_rate(const struct arg *arg_p, struct sample *s return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -954,7 +954,7 @@ static int sample_conv_table_conn_rate(const struct arg *arg_p, struct sample *s if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), t->data_arg[STKTABLE_DT_CONN_RATE].u); return 1; } @@ -979,8 +979,8 @@ static int sample_conv_table_bytes_out_rate(const struct arg *arg_p, struct samp return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -990,7 +990,7 @@ static int sample_conv_table_bytes_out_rate(const struct arg *arg_p, struct samp if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), t->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); return 1; } @@ -1015,8 +1015,8 @@ static int sample_conv_table_gpc0(const struct arg *arg_p, struct sample *smp, v return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1026,7 +1026,7 @@ static int sample_conv_table_gpc0(const struct arg *arg_p, struct sample *smp, v if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, gpc0); + smp->data.data.sint = stktable_data_cast(ptr, gpc0); return 1; } @@ -1050,8 +1050,8 @@ static int sample_conv_table_gpc0_rate(const struct arg *arg_p, struct sample *s return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1061,7 +1061,7 @@ static int sample_conv_table_gpc0_rate(const struct arg *arg_p, struct sample *s if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), t->data_arg[STKTABLE_DT_GPC0_RATE].u); return 1; } @@ -1086,8 +1086,8 @@ static int sample_conv_table_http_err_cnt(const struct arg *arg_p, struct sample return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1097,7 +1097,7 @@ static int sample_conv_table_http_err_cnt(const struct arg *arg_p, struct sample if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, http_err_cnt); + smp->data.data.sint = stktable_data_cast(ptr, http_err_cnt); return 1; } @@ -1121,8 +1121,8 @@ static int sample_conv_table_http_err_rate(const struct arg *arg_p, struct sampl return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1132,7 +1132,7 @@ static int sample_conv_table_http_err_rate(const struct arg *arg_p, struct sampl if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), t->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); return 1; } @@ -1157,8 +1157,8 @@ static int sample_conv_table_http_req_cnt(const struct arg *arg_p, struct sample return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1168,7 +1168,7 @@ static int sample_conv_table_http_req_cnt(const struct arg *arg_p, struct sample if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, http_req_cnt); + smp->data.data.sint = stktable_data_cast(ptr, http_req_cnt); return 1; } @@ -1192,8 +1192,8 @@ static int sample_conv_table_http_req_rate(const struct arg *arg_p, struct sampl return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1203,7 +1203,7 @@ static int sample_conv_table_http_req_rate(const struct arg *arg_p, struct sampl if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), t->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); return 1; } @@ -1228,8 +1228,8 @@ static int sample_conv_table_kbytes_in(const struct arg *arg_p, struct sample *s return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1239,7 +1239,7 @@ static int sample_conv_table_kbytes_in(const struct arg *arg_p, struct sample *s if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; + smp->data.data.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; return 1; } @@ -1263,8 +1263,8 @@ static int sample_conv_table_kbytes_out(const struct arg *arg_p, struct sample * return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1274,7 +1274,7 @@ static int sample_conv_table_kbytes_out(const struct arg *arg_p, struct sample * if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; + smp->data.data.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; return 1; } @@ -1298,8 +1298,8 @@ static int sample_conv_table_server_id(const struct arg *arg_p, struct sample *s return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1309,7 +1309,7 @@ static int sample_conv_table_server_id(const struct arg *arg_p, struct sample *s if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, server_id); + smp->data.data.sint = stktable_data_cast(ptr, server_id); return 1; } @@ -1333,8 +1333,8 @@ static int sample_conv_table_sess_cnt(const struct arg *arg_p, struct sample *sm return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1344,7 +1344,7 @@ static int sample_conv_table_sess_cnt(const struct arg *arg_p, struct sample *sm if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, sess_cnt); + smp->data.data.sint = stktable_data_cast(ptr, sess_cnt); return 1; } @@ -1368,8 +1368,8 @@ static int sample_conv_table_sess_rate(const struct arg *arg_p, struct sample *s return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (!ts) /* key not present */ @@ -1379,7 +1379,7 @@ static int sample_conv_table_sess_rate(const struct arg *arg_p, struct sample *s if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), t->data_arg[STKTABLE_DT_SESS_RATE].u); return 1; } @@ -1403,12 +1403,12 @@ static int sample_conv_table_trackers(const struct arg *arg_p, struct sample *sm return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; ts = stktable_lookup_key(t, key); if (ts) - smp->data.sint = ts->ref_cnt; + smp->data.data.sint = ts->ref_cnt; return 1; } diff --git a/src/stream.c b/src/stream.c index 82b07439aa..acb602af11 100644 --- a/src/stream.c +++ b/src/stream.c @@ -2671,8 +2671,8 @@ static int smp_fetch_sc_tracked(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_BOOL; - smp->data.sint = !!smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); + smp->data.type = SMP_T_BOOL; + smp->data.data.sint = !!smp_fetch_sc_stkctr(smp->sess, smp->strm, args, kw); return 1; } @@ -2690,14 +2690,14 @@ smp_fetch_sc_get_gpc0(const struct arg *args, struct sample *smp, const char *kw return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, gpc0); + smp->data.data.sint = stktable_data_cast(ptr, gpc0); } return 1; } @@ -2716,13 +2716,13 @@ smp_fetch_sc_gpc0_rate(const struct arg *args, struct sample *smp, const char *k return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0_RATE); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, gpc0_rate), stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u); } return 1; @@ -2741,8 +2741,8 @@ smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) == NULL) stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw); @@ -2757,12 +2757,12 @@ smp_fetch_sc_inc_gpc0(const struct arg *args, struct sample *smp, const char *kw if (ptr1) { update_freq_ctr_period(&stktable_data_cast(ptr1, gpc0_rate), stkctr->table->data_arg[STKTABLE_DT_GPC0_RATE].u, 1); - smp->data.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr; + smp->data.data.sint = (&stktable_data_cast(ptr1, gpc0_rate))->curr_ctr; } ptr2 = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); if (ptr2) - smp->data.sint = ++stktable_data_cast(ptr2, gpc0); + smp->data.data.sint = ++stktable_data_cast(ptr2, gpc0); /* If data was modified, we need to touch to re-schedule sync */ if (ptr1 || ptr2) @@ -2784,8 +2784,8 @@ smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) == NULL) stkctr = smp_create_src_stkctr(smp->sess, smp->strm, args, kw); @@ -2794,7 +2794,7 @@ smp_fetch_sc_clr_gpc0(const struct arg *args, struct sample *smp, const char *kw void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_GPC0); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, gpc0); + smp->data.data.sint = stktable_data_cast(ptr, gpc0); stktable_data_cast(ptr, gpc0) = 0; /* If data was modified, we need to touch to re-schedule sync */ stktable_touch(stkctr->table, stkctr_entry(stkctr), 1); @@ -2815,13 +2815,13 @@ smp_fetch_sc_conn_cnt(const struct arg *args, struct sample *smp, const char *kw return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CNT); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, conn_cnt); + smp->data.data.sint = stktable_data_cast(ptr, conn_cnt); } return 1; } @@ -2839,13 +2839,13 @@ smp_fetch_sc_conn_rate(const struct arg *args, struct sample *smp, const char *k return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_RATE); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, conn_rate), stkctr->table->data_arg[STKTABLE_DT_CONN_RATE].u); } return 1; @@ -2881,8 +2881,8 @@ smp_fetch_src_updt_conn_cnt(const struct arg *args, struct sample *smp, const ch if (!ptr) return 0; /* parameter not stored in this table */ - smp->type = SMP_T_SINT; - smp->data.sint = ++stktable_data_cast(ptr, conn_cnt); + smp->data.type = SMP_T_SINT; + smp->data.data.sint = ++stktable_data_cast(ptr, conn_cnt); /* Touch was previously performed by stktable_update_key */ smp->flags = SMP_F_VOL_TEST; return 1; @@ -2901,13 +2901,13 @@ smp_fetch_sc_conn_cur(const struct arg *args, struct sample *smp, const char *kw return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_CONN_CUR); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, conn_cur); + smp->data.data.sint = stktable_data_cast(ptr, conn_cur); } return 1; } @@ -2925,13 +2925,13 @@ smp_fetch_sc_sess_cnt(const struct arg *args, struct sample *smp, const char *kw return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_CNT); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, sess_cnt); + smp->data.data.sint = stktable_data_cast(ptr, sess_cnt); } return 1; } @@ -2948,13 +2948,13 @@ smp_fetch_sc_sess_rate(const struct arg *args, struct sample *smp, const char *k return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_SESS_RATE); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, sess_rate), stkctr->table->data_arg[STKTABLE_DT_SESS_RATE].u); } return 1; @@ -2973,13 +2973,13 @@ smp_fetch_sc_http_req_cnt(const struct arg *args, struct sample *smp, const char return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_CNT); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, http_req_cnt); + smp->data.data.sint = stktable_data_cast(ptr, http_req_cnt); } return 1; } @@ -2997,13 +2997,13 @@ smp_fetch_sc_http_req_rate(const struct arg *args, struct sample *smp, const cha return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_REQ_RATE); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_req_rate), stkctr->table->data_arg[STKTABLE_DT_HTTP_REQ_RATE].u); } return 1; @@ -3022,13 +3022,13 @@ smp_fetch_sc_http_err_cnt(const struct arg *args, struct sample *smp, const char return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_CNT); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, http_err_cnt); + smp->data.data.sint = stktable_data_cast(ptr, http_err_cnt); } return 1; } @@ -3046,13 +3046,13 @@ smp_fetch_sc_http_err_rate(const struct arg *args, struct sample *smp, const cha return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_HTTP_ERR_RATE); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, http_err_rate), stkctr->table->data_arg[STKTABLE_DT_HTTP_ERR_RATE].u); } return 1; @@ -3071,13 +3071,13 @@ smp_fetch_sc_kbytes_in(const struct arg *args, struct sample *smp, const char *k return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_CNT); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; + smp->data.data.sint = stktable_data_cast(ptr, bytes_in_cnt) >> 10; } return 1; } @@ -3095,13 +3095,13 @@ smp_fetch_sc_bytes_in_rate(const struct arg *args, struct sample *smp, const cha return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_IN_RATE); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_in_rate), stkctr->table->data_arg[STKTABLE_DT_BYTES_IN_RATE].u); } return 1; @@ -3120,13 +3120,13 @@ smp_fetch_sc_kbytes_out(const struct arg *args, struct sample *smp, const char * return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_CNT); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; + smp->data.data.sint = stktable_data_cast(ptr, bytes_out_cnt) >> 10; } return 1; } @@ -3144,13 +3144,13 @@ smp_fetch_sc_bytes_out_rate(const struct arg *args, struct sample *smp, const ch return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = 0; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = 0; if (stkctr_entry(stkctr) != NULL) { void *ptr = stktable_data_ptr(stkctr->table, stkctr_entry(stkctr), STKTABLE_DT_BYTES_OUT_RATE); if (!ptr) return 0; /* parameter not stored */ - smp->data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), + smp->data.data.sint = read_freq_ctr_period(&stktable_data_cast(ptr, bytes_out_rate), stkctr->table->data_arg[STKTABLE_DT_BYTES_OUT_RATE].u); } return 1; @@ -3168,8 +3168,8 @@ smp_fetch_sc_trackers(const struct arg *args, struct sample *smp, const char *kw return 0; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = stkctr_entry(stkctr)->ref_cnt; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = stkctr_entry(stkctr)->ref_cnt; return 1; } @@ -3180,8 +3180,8 @@ static int smp_fetch_table_cnt(const struct arg *args, struct sample *smp, const char *kw, void *private) { smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = args->data.prx->table.current; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = args->data.prx->table.current; return 1; } @@ -3195,8 +3195,8 @@ smp_fetch_table_avl(const struct arg *args, struct sample *smp, const char *kw, px = args->data.prx; smp->flags = SMP_F_VOL_TEST; - smp->type = SMP_T_SINT; - smp->data.sint = px->table.size - px->table.current; + smp->data.type = SMP_T_SINT; + smp->data.data.sint = px->table.size - px->table.current; return 1; } diff --git a/src/vars.c b/src/vars.c index adacd2f949..a09de37068 100644 --- a/src/vars.c +++ b/src/vars.c @@ -249,9 +249,9 @@ static int smp_fetch_var(const struct arg *args, struct sample *smp, const char return 0; /* Copy sample. */ - smp->type = var->data.type; + smp->data.type = var->data.type; smp->flags |= SMP_F_CONST; - memcpy(&smp->data, &var->data.data, sizeof(smp->data)); + memcpy(&smp->data.data, &var->data.data, sizeof(smp->data.data)); return 1; } @@ -293,50 +293,50 @@ static int sample_store(struct vars *vars, const char *name, struct stream *strm } /* Set type. */ - var->data.type = smp->type; + var->data.type = smp->data.type; /* Copy data. If the data needs memory, the function can fail. */ switch (var->data.type) { case SMP_T_BOOL: case SMP_T_SINT: - var->data.data.sint = smp->data.sint; + var->data.data.sint = smp->data.data.sint; break; case SMP_T_IPV4: - var->data.data.ipv4 = smp->data.ipv4; + var->data.data.ipv4 = smp->data.data.ipv4; break; case SMP_T_IPV6: - var->data.data.ipv6 = smp->data.ipv6; + var->data.data.ipv6 = smp->data.data.ipv6; break; case SMP_T_STR: case SMP_T_BIN: - if (!var_accounting_add(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, smp->data.str.len)) { + if (!var_accounting_add(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, smp->data.data.str.len)) { var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ return 0; } - var->data.data.str.str = malloc(smp->data.str.len); + var->data.data.str.str = malloc(smp->data.data.str.len); if (!var->data.data.str.str) { - var_accounting_diff(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, -smp->data.str.len); + var_accounting_diff(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, -smp->data.data.str.len); var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ return 0; } - var->data.data.str.len = smp->data.str.len; - memcpy(var->data.data.str.str, smp->data.str.str, var->data.data.str.len); + var->data.data.str.len = smp->data.data.str.len; + memcpy(var->data.data.str.str, smp->data.data.str.str, var->data.data.str.len); break; case SMP_T_METH: - if (!var_accounting_add(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, smp->data.meth.str.len)) { + if (!var_accounting_add(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, smp->data.data.meth.str.len)) { var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ return 0; } - var->data.data.meth.str.str = malloc(smp->data.meth.str.len); + var->data.data.meth.str.str = malloc(smp->data.data.meth.str.len); if (!var->data.data.meth.str.str) { - var_accounting_diff(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, -smp->data.meth.str.len); + var_accounting_diff(vars, &strm->sess->vars, &strm->vars_txn, &strm->vars_reqres, -smp->data.data.meth.str.len); var->data.type = SMP_T_BOOL; /* This type doesn't use additional memory. */ return 0; } - var->data.data.meth.meth = smp->data.meth.meth; - var->data.data.meth.str.len = smp->data.meth.str.len; - var->data.data.meth.str.size = smp->data.meth.str.len; - memcpy(var->data.data.meth.str.str, smp->data.meth.str.str, var->data.data.meth.str.len); + var->data.data.meth.meth = smp->data.data.meth.meth; + var->data.data.meth.str.len = smp->data.data.meth.str.len; + var->data.data.meth.str.size = smp->data.data.meth.str.len; + memcpy(var->data.data.meth.str.str, smp->data.data.meth.str.str, var->data.data.meth.str.len); break; } return 1; @@ -442,9 +442,9 @@ int vars_get_by_name(const char *name, size_t len, struct stream *strm, struct s return 0; /* Copy sample. */ - smp->type = var->data.type; + smp->data.type = var->data.type; smp->flags = SMP_F_CONST; - memcpy(&smp->data, &var->data.data, sizeof(smp->data)); + memcpy(&smp->data.data, &var->data.data, sizeof(smp->data.data)); return 1; } @@ -476,9 +476,9 @@ int vars_get_by_desc(const struct var_desc *var_desc, struct stream *strm, struc return 0; /* Copy sample. */ - smp->type = var->data.type; + smp->data.type = var->data.type; smp->flags = SMP_F_CONST; - memcpy(&smp->data, &var->data.data, sizeof(smp->data)); + memcpy(&smp->data.data, &var->data.data, sizeof(smp->data.data)); return 1; }