CLEANUP: applet/table: add an "action" entry in ->table context

Just like previous patch, this was the only other user of the "private"
field of the applet. It used to store a copy of the keyword's action.
Let's just put it into ->table->action and use it from there. It also
slightly simplifies the code by removing a few pointer to integer casts.
This commit is contained in:
Willy Tarreau 2016-12-14 15:50:35 +01:00
parent 8ae4f7533d
commit a24bc78ad4
2 changed files with 8 additions and 13 deletions

View File

@ -95,6 +95,7 @@ struct appctx {
long long value; /* value to compare against */ long long value; /* value to compare against */
signed char data_type; /* type of data to compare, or -1 if none */ signed char data_type; /* type of data to compare, or -1 if none */
signed char data_op; /* operator (STD_OP_*) when data_type set */ signed char data_op; /* operator (STD_OP_*) when data_type set */
char action; /* action on the table : one of STK_CLI_ACT_* */
} table; } table;
struct { struct {
const char *msg; /* pointer to a persistent message to be returned in PRINT state */ const char *msg; /* pointer to a persistent message to be returned in PRINT state */

View File

@ -2344,7 +2344,6 @@ static int table_dump_entry_to_buffer(struct chunk *msg, struct stream_interface
static int table_process_entry_per_key(struct appctx *appctx, char **args) static int table_process_entry_per_key(struct appctx *appctx, char **args)
{ {
struct stream_interface *si = appctx->owner; struct stream_interface *si = appctx->owner;
int action = (long)appctx->private;
struct proxy *px = appctx->ctx.table.target; struct proxy *px = appctx->ctx.table.target;
struct stksess *ts; struct stksess *ts;
uint32_t uint32_key; uint32_t uint32_key;
@ -2393,7 +2392,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
static_table_key->key_len = strlen(args[4]); static_table_key->key_len = strlen(args[4]);
break; break;
default: default:
switch (action) { switch (appctx->ctx.table.action) {
case STK_CLI_ACT_SHOW: case STK_CLI_ACT_SHOW:
appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n"; appctx->ctx.cli.msg = "Showing keys from tables of type other than ip, ipv6, string and integer is not supported\n";
break; break;
@ -2417,7 +2416,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
ts = stktable_lookup_key(&px->table, static_table_key); ts = stktable_lookup_key(&px->table, static_table_key);
switch (action) { switch (appctx->ctx.table.action) {
case STK_CLI_ACT_SHOW: case STK_CLI_ACT_SHOW:
if (!ts) if (!ts)
return 1; return 1;
@ -2520,9 +2519,7 @@ static int table_process_entry_per_key(struct appctx *appctx, char **args)
*/ */
static int table_prepare_data_request(struct appctx *appctx, char **args) static int table_prepare_data_request(struct appctx *appctx, char **args)
{ {
int action = (long)appctx->private; if (appctx->ctx.table.action != STK_CLI_ACT_SHOW && appctx->ctx.table.action != STK_CLI_ACT_CLR) {
if (action != STK_CLI_ACT_SHOW && action != STK_CLI_ACT_CLR) {
appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions"; appctx->ctx.cli.msg = "content-based lookup is only supported with the \"show\" and \"clear\" actions";
appctx->st0 = CLI_ST_PRINT; appctx->st0 = CLI_ST_PRINT;
return 1; return 1;
@ -2562,13 +2559,11 @@ static int table_prepare_data_request(struct appctx *appctx, char **args)
/* returns 0 if wants to be called, 1 if has ended processing */ /* returns 0 if wants to be called, 1 if has ended processing */
static int cli_parse_table_req(char **args, struct appctx *appctx, void *private) static int cli_parse_table_req(char **args, struct appctx *appctx, void *private)
{ {
int action = (long)private;
appctx->private = private;
appctx->ctx.table.data_type = -1; appctx->ctx.table.data_type = -1;
appctx->ctx.table.target = NULL; appctx->ctx.table.target = NULL;
appctx->ctx.table.proxy = NULL; appctx->ctx.table.proxy = NULL;
appctx->ctx.table.entry = NULL; appctx->ctx.table.entry = NULL;
appctx->ctx.table.action = (long)private; // keyword argument, one of STK_CLI_ACT_*
if (*args[2]) { if (*args[2]) {
appctx->ctx.table.target = proxy_tbl_by_name(args[2]); appctx->ctx.table.target = proxy_tbl_by_name(args[2]);
@ -2579,7 +2574,7 @@ static int cli_parse_table_req(char **args, struct appctx *appctx, void *private
} }
} }
else { else {
if (action != STK_CLI_ACT_SHOW) if (appctx->ctx.table.action != STK_CLI_ACT_SHOW)
goto err_args; goto err_args;
return 0; return 0;
} }
@ -2594,7 +2589,7 @@ static int cli_parse_table_req(char **args, struct appctx *appctx, void *private
return 0; return 0;
err_args: err_args:
switch (action) { switch (appctx->ctx.table.action) {
case STK_CLI_ACT_SHOW: case STK_CLI_ACT_SHOW:
appctx->ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n"; appctx->ctx.cli.msg = "Optional argument only supports \"data.<store_data_type>\" <operator> <value> and key <key>\n";
break; break;
@ -2619,12 +2614,11 @@ err_args:
static int cli_io_handler_table(struct appctx *appctx) static int cli_io_handler_table(struct appctx *appctx)
{ {
struct stream_interface *si = appctx->owner; struct stream_interface *si = appctx->owner;
int action = (long)appctx->private;
struct stream *s = si_strm(si); struct stream *s = si_strm(si);
struct ebmb_node *eb; struct ebmb_node *eb;
int dt; int dt;
int skip_entry; int skip_entry;
int show = action == STK_CLI_ACT_SHOW; int show = appctx->ctx.table.action == STK_CLI_ACT_SHOW;
/* /*
* We have 3 possible states in appctx->st2 : * We have 3 possible states in appctx->st2 :