better command check
This commit is contained in:
parent
fe11e2f4dc
commit
da0b72311f
@ -24,8 +24,6 @@
|
||||
#include "gauger.h"
|
||||
|
||||
|
||||
#define FIND_TEST(cmd, string, arg) \
|
||||
|
||||
/**
|
||||
* Represents the state of the interpreter
|
||||
*/
|
||||
@ -169,8 +167,11 @@ cmd_find (const struct PERF_TALER_MINTDB_Cmd *cmd, const char *search)
|
||||
|
||||
/**
|
||||
* Initialization of a command array
|
||||
* and check for the type of the label
|
||||
*
|
||||
* @param cmd the comand array initialized
|
||||
* @return #GNUNET_OK if the initialization was sucessful
|
||||
* #GNUNET_SYSERR if there was a probleb. See the log for details
|
||||
*/
|
||||
static int
|
||||
cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
||||
@ -181,34 +182,412 @@ cmd_init (struct PERF_TALER_MINTDB_Cmd cmd[])
|
||||
{
|
||||
switch (cmd[i].command)
|
||||
{
|
||||
case PERF_TALER_MINTDB_CMD_END_LOOP:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.end_loop.label_loop);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.end_loop.label_loop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
if (PERF_TALER_MINTDB_CMD_LOOP != cmd[ret].command)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.end_loop.label_loop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.end_loop.index_loop = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
||||
{
|
||||
int save_label;
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.save_array.label_save);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.save_array.label_save);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_NONE == cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.save_array.label_save);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.save_array.index_save = ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.save_array.label_loop);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.save_array.label_loop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_CMD_LOOP != cmd[ret].command)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.save_array.label_loop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.save_array.index_loop = ret;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(save_label = cmd_find (cmd,
|
||||
cmd[i].details.save_array.label_save)));
|
||||
/* Allocation of memory for saving data */
|
||||
cmd[i].details.save_array.data_saved =
|
||||
GNUNET_new_array (cmd[i].details.save_array.nb_saved,
|
||||
struct PERF_TALER_MINTDB_Data);
|
||||
GNUNET_assert (NULL != cmd[i].details.save_array.data_saved);
|
||||
cmd[i].details.save_array.data_saved->type =
|
||||
cmd[cmd[i].details.save_array.index_save].exposed.type;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
||||
/* Creating the permutation array to randomize the data order */
|
||||
{
|
||||
int save_index;
|
||||
int ret;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(save_index = cmd_find (
|
||||
cmd,
|
||||
cmd[i].details.load_array.label_save)));
|
||||
GNUNET_assert (NULL !=
|
||||
(cmd[i].details.load_array.permutation =
|
||||
GNUNET_CRYPTO_random_permute (
|
||||
GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
cmd[save_index].details.save_array.nb_saved)));
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.load_array.label_save);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.load_array.label_save);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_CMD_SAVE_ARRAY != cmd[ret].command)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.load_array.label_save);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.load_array.index_save = ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.load_array.label_loop);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.load_array.label_loop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_CMD_LOOP != cmd[ret].command)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.load_array.label_loop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.load_array.index_loop = ret;
|
||||
|
||||
cmd[i].details.load_array.permutation =
|
||||
GNUNET_CRYPTO_random_permute (
|
||||
GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
cmd[cmd[i].details.load_array.index_loop].details.save_array.nb_saved);
|
||||
GNUNET_assert (NULL != cmd[i].details.load_array.permutation);
|
||||
|
||||
cmd[i].exposed.type = cmd[cmd[i].details.load_array.index_save].details.save_array.data_saved->type;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_LOAD_RANDOM:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.load_random.label_save);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.load_random.label_save);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
|
||||
if (PERF_TALER_MINTDB_CMD_SAVE_ARRAY != cmd[ret].command)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.load_random.label_save);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.load_random.index_save = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GAUGER:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.gauger.label_start);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.gauger.label_start);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_TIME != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.gauger.label_start);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.gauger.index_start = ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.gauger.label_stop);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.gauger.label_stop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_TIME != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.gauger.label_stop);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.gauger.index_stop = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find( cmd,
|
||||
cmd[i].details.insert_deposit.label_coin);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.insert_deposit.label_coin);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_COIN != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.insert_deposit.label_coin);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.insert_deposit.index_coin = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DEPOSIT:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.get_deposit.label_deposit);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_deposit.label_deposit);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_DEPOSIT != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_deposit.label_deposit);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.get_deposit.index_deposit = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_RESERVE:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.get_reserve.label_reserve);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_reserve.label_reserve);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_RESERVE != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_reserve.label_reserve);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.get_reserve.index_reserve = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_RESERVE_HISTORY:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.get_reserve_history.label_reserve);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_reserve_history.label_reserve);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_RESERVE != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_reserve_history.label_reserve);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.get_reserve_history.index_reserve = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DENOMINATION:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.get_denomination.label_denom);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_denomination.label_denom);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_DENOMINATION_INFO != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_denomination.label_denom);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.get_denomination.index_denom = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.insert_withdraw.label_dki);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.insert_withdraw.label_dki);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_DENOMINATION_INFO != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.insert_withdraw.label_dki);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.insert_withdraw.index_dki = ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.insert_withdraw.label_reserve);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.insert_withdraw.label_reserve);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_RESERVE != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.insert_withdraw.label_reserve);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.insert_withdraw.index_reserve = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_WITHDRAW:
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd,
|
||||
cmd[i].details.get_withdraw.label_coin);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Undefined reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_withdraw.label_coin);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
if (PERF_TALER_MINTDB_COIN != cmd[ret].exposed.type)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"%d:Wrong type reference to %s",
|
||||
i,
|
||||
cmd[i].details.get_withdraw.label_coin);
|
||||
return GNUNET_SYSERR;
|
||||
}
|
||||
cmd[i].details.get_withdraw.index_coin = ret;
|
||||
}
|
||||
break;
|
||||
|
||||
@ -270,10 +649,7 @@ interpret_end_loop (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
unsigned int i;
|
||||
int jump;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(jump = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.end_loop.label_loop)));
|
||||
jump = state->cmd[state->i].details.end_loop.index_loop;
|
||||
// Cleaning up the memory in the loop
|
||||
for (i = jump; i < state->i; i++)
|
||||
{
|
||||
@ -312,13 +688,9 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
int save_index;
|
||||
unsigned int selection_chance;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(loop_index = cmd_find (state->cmd,
|
||||
cmd->details.save_array.label_loop)));
|
||||
loop_index = cmd->details.save_array.index_loop;
|
||||
save_index = cmd->details.save_array.index_save;
|
||||
loop_ref = &state->cmd[loop_index];
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(save_index = cmd_find (state->cmd,
|
||||
cmd->details.save_array.label_save)));
|
||||
save_ref = &state->cmd[save_index];
|
||||
/* Array initialization on first loop iteration
|
||||
Alows for nested loops */
|
||||
@ -364,19 +736,14 @@ interpret_save_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
static void
|
||||
interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
{
|
||||
struct PERF_TALER_MINTDB_Cmd *cmd = &state->cmd[state->i];
|
||||
unsigned int loop_iter;
|
||||
int loop_index;
|
||||
int save_index;
|
||||
struct PERF_TALER_MINTDB_Data *loaded_data;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(loop_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.load_array.label_loop)));
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(save_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.load_array.label_save)));
|
||||
loop_index = cmd->details.load_array.index_loop;
|
||||
save_index = cmd->details.load_array.index_save;
|
||||
loop_iter = state->cmd[loop_index].details.loop.curr_iteration;
|
||||
{
|
||||
int i, quotient;
|
||||
@ -386,13 +753,13 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
quotient = loop_iter / state->cmd[save_index].details.save_array.nb_saved;
|
||||
loop_iter = loop_iter % state->cmd[save_index].details.save_array.nb_saved;
|
||||
for (i=0; i<=quotient; i++)
|
||||
loop_iter = state->cmd[state->i].details.load_array.permutation[loop_iter];
|
||||
loop_iter = cmd->details.load_array.permutation[loop_iter];
|
||||
}
|
||||
/* Extracting the data from the loop_indexth indice in save_index
|
||||
* array.
|
||||
*/
|
||||
loaded_data = &state->cmd[save_index].details.save_array.data_saved[loop_iter];
|
||||
data_copy (loaded_data, &state->cmd[state->i].exposed);
|
||||
data_copy (loaded_data, &cmd->exposed);
|
||||
}
|
||||
|
||||
|
||||
@ -404,16 +771,15 @@ interpret_load_array (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
static void
|
||||
interprete_load_random (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
{
|
||||
struct PERF_TALER_MINTDB_Cmd *cmd = &state->cmd[state->i];
|
||||
unsigned int index;
|
||||
int save_index;
|
||||
|
||||
GNUNET_assert (0 <=
|
||||
(save_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i].details.load_random.label_save)));
|
||||
index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
state->cmd[save_index].details.save_array.nb_saved);
|
||||
data_copy (&state->cmd[save_index].details.save_array.data_saved[index],
|
||||
&state->cmd[state->i].exposed);
|
||||
save_index = cmd->details.load_random.index_save;
|
||||
index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
|
||||
state->cmd[save_index].details.save_array.nb_saved);
|
||||
data_copy (&state->cmd[save_index].details.save_array.data_saved[index],
|
||||
&cmd->exposed);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -457,14 +823,9 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
float ips;
|
||||
struct GNUNET_TIME_Absolute start, stop;
|
||||
struct GNUNET_TIME_Relative elapsed;
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(start_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.gauger.label_start)));
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(stop_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i]
|
||||
.details.gauger.label_stop)));
|
||||
|
||||
start_index = state->cmd[state->i].details.gauger.index_start;
|
||||
stop_index = state->cmd[state->i].details.gauger.index_stop;
|
||||
start = *state->cmd[start_index].exposed.data.time;
|
||||
stop = *state->cmd[stop_index].exposed.data.time;
|
||||
elapsed = GNUNET_TIME_absolute_get_difference (start,
|
||||
@ -511,12 +872,9 @@ interpret (struct PERF_TALER_MINTDB_interpreter_state *state)
|
||||
int coin_index;
|
||||
struct TALER_MINTDB_Deposit *deposit;
|
||||
|
||||
GNUNET_assert (GNUNET_SYSERR !=
|
||||
(coin_index = cmd_find (state->cmd,
|
||||
state->cmd[state->i].details.insert_deposit.label_coin)));
|
||||
GNUNET_assert (NULL !=
|
||||
(deposit = PERF_TALER_MINTDB_deposit_init (state->cmd[coin_index].exposed.data.coin)));
|
||||
|
||||
coin_index = state->cmd[state->i].details.insert_deposit.index_coin;
|
||||
deposit = PERF_TALER_MINTDB_deposit_init (state->cmd[coin_index].exposed.data.coin);
|
||||
GNUNET_assert (NULL != deposit);
|
||||
GNUNET_assert (GNUNET_OK ==
|
||||
state->plugin->insert_deposit (state->plugin->cls,
|
||||
state->session,
|
||||
@ -1018,9 +1376,6 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
{
|
||||
init = init_def;
|
||||
}
|
||||
if (GNUNET_SYSERR == PERF_TALER_MINTDB_check (init))
|
||||
return GNUNET_SYSERR;
|
||||
|
||||
ret = PERF_TALER_MINTDB_interpret (plugin,
|
||||
init);
|
||||
if (GNUNET_OK != ret)
|
||||
@ -1032,8 +1387,6 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
/*
|
||||
* Running the benchmark
|
||||
*/
|
||||
if (GNUNET_SYSERR == PERF_TALER_MINTDB_check (benchmark))
|
||||
return GNUNET_SYSERR;
|
||||
ret = PERF_TALER_MINTDB_interpret (plugin,
|
||||
benchmark);
|
||||
if (GNUNET_OK != ret)
|
||||
@ -1062,140 +1415,3 @@ PERF_TALER_MINTDB_run_benchmark (const char *benchmark_name,
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Tests if @a label is reference to a command of @a cmd
|
||||
* Prints an error containing @a desc if a problem occurs
|
||||
*
|
||||
* @param cmd the cmd array checked
|
||||
* @param label the label checked
|
||||
* @param i the index of the command beeing checked (used for error reporting
|
||||
* @param desc a description of the label checked
|
||||
*/
|
||||
static int
|
||||
find_test (const struct PERF_TALER_MINTDB_Cmd *cmd,
|
||||
const char *label,
|
||||
const unsigned int i,
|
||||
const char *desc)
|
||||
{
|
||||
int ret;
|
||||
|
||||
ret = cmd_find (cmd, label);
|
||||
if (GNUNET_SYSERR == ret)
|
||||
{
|
||||
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
|
||||
"Error at %s:index %d wrong label for %s",
|
||||
cmd[i].label,
|
||||
i,
|
||||
desc);
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if the given command array is syntaxicly correct
|
||||
* This will check if the label are corrects but will not check if
|
||||
* they are pointing to an apropriate command.
|
||||
*
|
||||
* @param cmd the command array to check
|
||||
* @return #GNUNET_OK is @a cmd is correct; #GNUNET_SYSERR if it is'nt
|
||||
*/
|
||||
int
|
||||
PERF_TALER_MINTDB_check (const struct PERF_TALER_MINTDB_Cmd *cmd)
|
||||
{
|
||||
unsigned int i;
|
||||
int ret = GNUNET_OK;
|
||||
|
||||
for (i = 0; PERF_TALER_MINTDB_CMD_END != cmd[i].command; i++)
|
||||
{
|
||||
int ret_loc = GNUNET_OK;
|
||||
switch (cmd[i].command)
|
||||
{
|
||||
case PERF_TALER_MINTDB_CMD_END_LOOP:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.end_loop.label_loop,
|
||||
i,
|
||||
"label_loop");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GAUGER:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.gauger.label_start,
|
||||
i,
|
||||
"label_start");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_SAVE_ARRAY:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.save_array.label_loop,
|
||||
i,
|
||||
"label_loop");
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.save_array.label_save,
|
||||
i,
|
||||
"label_save");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_LOAD_ARRAY:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.load_array.label_loop,
|
||||
i,
|
||||
"label_loop");
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.load_array.label_save,
|
||||
i,
|
||||
"label_save");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DENOMINATION:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_denomination.label_denom,
|
||||
i,
|
||||
"label_denom");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_RESERVE:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_reserve.label_reserve,
|
||||
i,
|
||||
"label_reserve");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_DEPOSIT:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.insert_deposit.label_coin,
|
||||
i,
|
||||
"label_dki");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_DEPOSIT:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_deposit.label_deposit,
|
||||
i,
|
||||
"label_deposit");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_INSERT_WITHDRAW:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.insert_withdraw.label_dki,
|
||||
i,
|
||||
"label_dki");
|
||||
break;
|
||||
|
||||
case PERF_TALER_MINTDB_CMD_GET_WITHDRAW:
|
||||
ret_loc = find_test (cmd,
|
||||
cmd[i].details.get_withdraw.label_coin,
|
||||
i,
|
||||
"label_coin");
|
||||
break;
|
||||
|
||||
default :
|
||||
break;
|
||||
}
|
||||
if (GNUNET_OK == ret)
|
||||
ret = (GNUNET_SYSERR == ret_loc)?GNUNET_SYSERR:GNUNET_OK;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
@ -112,7 +112,7 @@
|
||||
{ \
|
||||
.command = PERF_TALER_MINTDB_CMD_GET_TIME, \
|
||||
.label = _label, \
|
||||
.exposed.type = PERF_TALER_MINTDB_NONE \
|
||||
.exposed.type = PERF_TALER_MINTDB_TIME \
|
||||
}
|
||||
|
||||
/**
|
||||
@ -657,6 +657,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* Maximum number of iteration in the loop
|
||||
*/
|
||||
const unsigned int max_iterations;
|
||||
|
||||
/**
|
||||
* The current iteration of the loop
|
||||
*/
|
||||
@ -673,6 +674,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* Label of the loop closed by the command
|
||||
*/
|
||||
const char *label_loop;
|
||||
unsigned int index_loop;
|
||||
} end_loop;
|
||||
|
||||
|
||||
@ -685,11 +687,13 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* Label of the starting timestamp
|
||||
*/
|
||||
const char *label_start;
|
||||
unsigned int index_start;
|
||||
|
||||
/**
|
||||
* Label of the ending timestamp
|
||||
*/
|
||||
const char *label_stop;
|
||||
unsigned int index_stop;
|
||||
|
||||
/**
|
||||
* The category of the measurment
|
||||
@ -723,18 +727,24 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* Number of items to save
|
||||
*/
|
||||
unsigned int nb_saved;
|
||||
|
||||
/**
|
||||
* Number of items already saved
|
||||
*/
|
||||
unsigned int index;
|
||||
|
||||
/**
|
||||
* Label of the loop it is attached to
|
||||
*/
|
||||
const char *label_loop;
|
||||
unsigned int index_loop;
|
||||
|
||||
/**
|
||||
* Label of the command exposing the item
|
||||
*/
|
||||
const char *label_save;
|
||||
unsigned int index_save;
|
||||
|
||||
/**
|
||||
* Array of data saved
|
||||
*/
|
||||
@ -751,11 +761,13 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The loop in which the command is located
|
||||
*/
|
||||
const char *label_loop;
|
||||
unsigned int index_loop;
|
||||
|
||||
/**
|
||||
* Label of the command where the items were saved
|
||||
*/
|
||||
const char *label_save;
|
||||
unsigned int index_save;
|
||||
|
||||
/**
|
||||
* A permutation array used to randomize the order the items are loaded in
|
||||
@ -773,6 +785,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The label of the #PERF_TALER_MINTDB_CMD_SAVE_ARRAY the items will be extracted from
|
||||
*/
|
||||
const char *label_save;
|
||||
unsigned int index_save;
|
||||
} load_random;
|
||||
|
||||
/**
|
||||
@ -784,6 +797,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* Label of the source where the reserve used to create the coin is
|
||||
*/
|
||||
const char *label_coin;
|
||||
unsigned int index_coin;
|
||||
} insert_deposit;
|
||||
|
||||
|
||||
@ -796,6 +810,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The label of the source of the deposit to check
|
||||
*/
|
||||
const char *label_deposit;
|
||||
unsigned int index_deposit;
|
||||
} get_deposit;
|
||||
|
||||
|
||||
@ -808,6 +823,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The label of the source of the reserve to check
|
||||
*/
|
||||
const char *label_reserve;
|
||||
unsigned int index_reserve;
|
||||
} get_reserve;
|
||||
|
||||
|
||||
@ -820,6 +836,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The label of the source of the reserve to check
|
||||
*/
|
||||
const char *label_reserve;
|
||||
unsigned int index_reserve;
|
||||
} get_reserve_history;
|
||||
|
||||
|
||||
@ -832,6 +849,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The label of the source of the denomination to check
|
||||
*/
|
||||
const char *label_denom;
|
||||
unsigned int index_denom;
|
||||
} get_denomination;
|
||||
|
||||
|
||||
@ -844,11 +862,13 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* label of the denomination key used to sign the coin
|
||||
*/
|
||||
const char *label_dki;
|
||||
unsigned int index_dki;
|
||||
|
||||
/**
|
||||
* label of the reserve the money to mint the coin comes from
|
||||
*/
|
||||
const char *label_reserve;
|
||||
unsigned int index_reserve;
|
||||
} insert_withdraw;
|
||||
|
||||
/**
|
||||
@ -860,6 +880,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* label of the source for the coin information
|
||||
*/
|
||||
const char *label_coin;
|
||||
unsigned int index_coin;
|
||||
} get_withdraw;
|
||||
|
||||
/**
|
||||
@ -871,6 +892,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The coin which history is checked
|
||||
*/
|
||||
const char *label_coin;
|
||||
unsigned int index_coin;
|
||||
} get_coin_transaction;
|
||||
|
||||
/**
|
||||
@ -882,6 +904,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* label of the source of the hash of the session
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
} get_refresh_session;
|
||||
|
||||
/**
|
||||
@ -893,11 +916,13 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The label of the hash of the refresh session
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
|
||||
/**
|
||||
* The label of the coin to melt
|
||||
*/
|
||||
const char *label_coin;
|
||||
const char coin;
|
||||
} insert_refresh_melt;
|
||||
|
||||
/**
|
||||
@ -909,6 +934,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The label of the hash of the session
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
} get_refresh_melt;
|
||||
|
||||
/**
|
||||
@ -920,11 +946,13 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
|
||||
/**
|
||||
* The new coin denomination
|
||||
*/
|
||||
const char *label_denom;
|
||||
unsigned int index_denom;
|
||||
} insert_refresh_order;
|
||||
|
||||
/**
|
||||
@ -936,6 +964,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
|
||||
} get_refresh_order;
|
||||
|
||||
@ -948,6 +977,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
|
||||
} insert_refresh_commit_coin;
|
||||
|
||||
@ -960,6 +990,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
|
||||
} insert_refresh_commit_link;
|
||||
|
||||
@ -972,6 +1003,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
} get_refresh_commit_link;
|
||||
|
||||
/**
|
||||
@ -983,6 +1015,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
} get_melt_commitment;
|
||||
|
||||
/**
|
||||
@ -994,6 +1027,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
} insert_refresh_out;
|
||||
|
||||
/**
|
||||
@ -1005,6 +1039,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
} get_link_datat_list;
|
||||
|
||||
/**
|
||||
@ -1016,6 +1051,7 @@ union PERF_TALER_MINTDB_CMD_Details
|
||||
* The refresh session hash
|
||||
*/
|
||||
const char *label_hash;
|
||||
unsigned int index_hash;
|
||||
} get_transfer;
|
||||
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user