LCOV - code coverage report
Current view: top level - exchangedb - perf_taler_exchangedb_interpreter.c (source / functions) Hit Total Coverage
Test: rcoverage.info Lines: 306 679 45.1 %
Date: 2017-11-25 11:31:41 Functions: 11 12 91.7 %

          Line data    Source code
       1             : /*
       2             :    This file is part of TALER
       3             :    Copyright (C) 2014-2017 GNUnet e.V.
       4             : 
       5             :    TALER is free software; you can redistribute it and/or modify it under the
       6             :    terms of the GNU General Public License as published by the Free Software
       7             :    Foundation; either version 3, or (at your option) any later version.
       8             : 
       9             :    TALER is distributed in the hope that it will be useful, but WITHOUT ANY
      10             :    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
      11             :    A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
      12             : 
      13             :    You should have received a copy of the GNU General Public License along with
      14             :    TALER; see the file COPYING.  If not, see <http://www.gnu.org/licenses/>
      15             :    */
      16             : /**
      17             :  * @file exchangedb/perf_taler_exchangedb_interpreter.c
      18             :  * @brief Interpreter library for exchange database performance analysis
      19             :  * @author Nicolas Fournier
      20             :  */
      21             : #include "platform.h"
      22             : #include "perf_taler_exchangedb_interpreter.h"
      23             : #include "perf_taler_exchangedb_init.h"
      24             : #include "gauger.h"
      25             : 
      26             : 
      27             : /**
      28             :  * Represents the state of the interpreter
      29             :  */
      30             : struct PERF_TALER_EXCHANGEDB_interpreter_state
      31             : {
      32             :   /**
      33             :    * State of the commands
      34             :    */
      35             :   struct PERF_TALER_EXCHANGEDB_Cmd *cmd;
      36             : 
      37             :   /**
      38             :    * Database plugin
      39             :    */
      40             :   struct TALER_EXCHANGEDB_Plugin *plugin;
      41             : 
      42             :   /**
      43             :    * Current database session
      44             :    */
      45             :   struct TALER_EXCHANGEDB_Session *session;
      46             : 
      47             :   /**
      48             :    * The current index of the interpreter
      49             :    */
      50             :   unsigned int i;
      51             : };
      52             : 
      53             : 
      54             : /**
      55             :  * Free the memory of @a data
      56             :  */
      57             : static void
      58          85 : data_free (struct PERF_TALER_EXCHANGEDB_Data *data)
      59             : {
      60          85 :   switch (data->type)
      61             :   {
      62             :     case PERF_TALER_EXCHANGEDB_TIME:
      63           2 :       if (NULL == data->data.time)
      64           0 :         break;
      65           2 :       GNUNET_free (data->data.time);
      66           2 :       data->data.time = NULL;
      67           2 :       break;
      68             : 
      69             :     case PERF_TALER_EXCHANGEDB_DEPOSIT:
      70           3 :       if (NULL == data->data.deposit)
      71           1 :         break;
      72           2 :       PERF_TALER_EXCHANGEDB_deposit_free (data->data.deposit);
      73           2 :       data->data.deposit = NULL;
      74           2 :       break;
      75             : 
      76             :     case PERF_TALER_EXCHANGEDB_COIN:
      77           5 :       if (NULL == data->data.coin)
      78           2 :         break;
      79           3 :       PERF_TALER_EXCHANGEDB_coin_free (data->data.coin);
      80           3 :       data->data.coin = NULL;
      81           3 :       break;
      82             : 
      83             :     case PERF_TALER_EXCHANGEDB_RESERVE:
      84           8 :       if (NULL == data->data.reserve)
      85           2 :         break;
      86           6 :       PERF_TALER_EXCHANGEDB_reserve_free (data->data.reserve);
      87           6 :       data->data.reserve = NULL;
      88           6 :       break;
      89             : 
      90             :     case PERF_TALER_EXCHANGEDB_DENOMINATION_INFO:
      91           7 :       if (NULL == data->data.dki)
      92           2 :         break;
      93           5 :       PERF_TALER_EXCHANGEDB_denomination_free (data->data.dki);
      94           5 :       data->data.dki = NULL;
      95           5 :       break;
      96             : 
      97             :     case PERF_TALER_EXCHANGEDB_REFRESH_HASH:
      98           0 :       if (NULL == data->data.session_hash)
      99           0 :         break;
     100           0 :       GNUNET_free (data->data.session_hash);
     101           0 :       data->data.session_hash = NULL;
     102           0 :       break;
     103             : 
     104             :     case PERF_TALER_EXCHANGEDB_NONE:
     105          60 :       break;
     106             :   }
     107          85 : }
     108             : 
     109             : 
     110             : /**
     111             :  * Copies @a data into @a copy
     112             :  *
     113             :  * @param data the data to be copied
     114             :  * @param[out] copy the copy made
     115             :  */
     116             : static void
     117           8 : data_copy (const struct PERF_TALER_EXCHANGEDB_Data *data,
     118             :            struct PERF_TALER_EXCHANGEDB_Data *copy)
     119             : {
     120           8 :   copy->type = data->type;
     121           8 :   switch (data->type)
     122             :   {
     123             :     case PERF_TALER_EXCHANGEDB_TIME:
     124           0 :       copy->data.time = GNUNET_new (struct GNUNET_TIME_Absolute);
     125           0 :       *copy->data.time = *data->data.time;
     126           0 :       return;
     127             : 
     128             :     case PERF_TALER_EXCHANGEDB_DEPOSIT:
     129             :       copy->data.deposit
     130           1 :         = PERF_TALER_EXCHANGEDB_deposit_copy (data->data.deposit);
     131           1 :       return;
     132             : 
     133             :     case PERF_TALER_EXCHANGEDB_COIN:
     134             :       copy->data.coin
     135           2 :         = PERF_TALER_EXCHANGEDB_coin_copy (data->data.coin);
     136           2 :       return;
     137             : 
     138             :     case PERF_TALER_EXCHANGEDB_RESERVE:
     139             :       copy->data.reserve
     140           2 :         = PERF_TALER_EXCHANGEDB_reserve_copy (data->data.reserve);
     141           2 :       return;
     142             : 
     143             :     case PERF_TALER_EXCHANGEDB_DENOMINATION_INFO:
     144             :       copy->data.dki
     145           3 :         = PERF_TALER_EXCHANGEDB_denomination_copy (data->data.dki);
     146           3 :       return;
     147             : 
     148             :     case PERF_TALER_EXCHANGEDB_REFRESH_HASH:
     149           0 :       copy-> data.session_hash = GNUNET_new (struct GNUNET_HashCode);
     150           0 :       *copy->data.session_hash
     151           0 :         = *data->data.session_hash;
     152           0 :       break;
     153             : 
     154             :     case PERF_TALER_EXCHANGEDB_NONE:
     155           0 :       break;
     156             :   }
     157             : }
     158             : 
     159             : 
     160             : /**
     161             :  * Finds the first command in cmd with the name search
     162             :  *
     163             :  * @return the index of the first command with name search
     164             :  * #GNUNET_SYSERR if none found
     165             :  */
     166             : static int
     167          27 : cmd_find (const struct PERF_TALER_EXCHANGEDB_Cmd *cmd,
     168             :           const char *search)
     169             : {
     170             :   unsigned int i;
     171             : 
     172         469 :   for (i=0; PERF_TALER_EXCHANGEDB_CMD_END != cmd[i].command; i++)
     173         469 :     if (0 == strcmp (cmd[i].label, search))
     174          27 :       return i;
     175           0 :   return GNUNET_SYSERR;
     176             : }
     177             : 
     178             : 
     179             : /**
     180             :  * Initialization of a command array
     181             :  * and check for the type of the label
     182             :  *
     183             :  * @param cmd the comand array initialized
     184             :  * @return #GNUNET_OK if the initialization was sucessful
     185             :  * #GNUNET_SYSERR if there was a probleb. See the log for details
     186             :  */
     187             : static int
     188           2 : cmd_init (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
     189             : {
     190             :   unsigned int i;
     191             : 
     192          39 :   for (i=0; PERF_TALER_EXCHANGEDB_CMD_END != cmd[i].command; i++)
     193             :   {
     194          37 :     switch (cmd[i].command)
     195             :     {
     196             :       case PERF_TALER_EXCHANGEDB_CMD_END_LOOP:
     197             :         {
     198             :           int ret;
     199             : 
     200           4 :           ret = cmd_find (cmd,
     201           4 :                           cmd[i].details.end_loop.label_loop);
     202           4 :           if (GNUNET_SYSERR == ret)
     203             :           {
     204           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     205             :                         "%d:Undefined reference to %s\n",
     206             :                         i,
     207             :                         cmd[i].details.end_loop.label_loop);
     208           0 :             return GNUNET_SYSERR;
     209             :           }
     210           4 :           if (PERF_TALER_EXCHANGEDB_CMD_LOOP != cmd[ret].command)
     211             :           {
     212           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     213             :                         "%d:Wrong type reference to %s\n",
     214             :                         i,
     215             :                         cmd[i].details.end_loop.label_loop);
     216           0 :             return GNUNET_SYSERR;
     217             :           }
     218           4 :           cmd[i].details.end_loop.index_loop = ret;
     219             :         }
     220           4 :         break;
     221             : 
     222             :       case PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY:
     223             :         {
     224             :           int ret;
     225             : 
     226           4 :           ret = cmd_find (cmd,
     227           4 :                           cmd[i].details.save_array.label_save);
     228           4 :           if (GNUNET_SYSERR == ret)
     229             :           {
     230           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     231             :                         "%d:Undefined reference to %s\n",
     232             :                         i,
     233             :                         cmd[i].details.save_array.label_save);
     234           0 :             return GNUNET_SYSERR;
     235             :           }
     236           4 :           if (PERF_TALER_EXCHANGEDB_NONE == cmd[ret].exposed.type)
     237             :           {
     238           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     239             :                         "%d:Wrong type reference to %s\n",
     240             :                         i,
     241             :                         cmd[i].details.save_array.label_save);
     242           0 :             return GNUNET_SYSERR;
     243             :           }
     244           4 :           cmd[i].details.save_array.index_save = ret;
     245             : 
     246           4 :           ret = cmd_find (cmd,
     247           4 :                           cmd[i].details.save_array.label_loop);
     248           4 :           if (GNUNET_SYSERR == ret)
     249             :           {
     250           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     251             :                         "%d:Undefined reference to %s\n",
     252             :                         i,
     253             :                         cmd[i].details.save_array.label_loop);
     254           0 :             return GNUNET_SYSERR;
     255             :           }
     256           4 :           if (PERF_TALER_EXCHANGEDB_CMD_LOOP != cmd[ret].command)
     257             :           {
     258           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     259             :                         "%d:Wrong type reference to %s\n",
     260             :                         i,
     261             :                         cmd[i].details.save_array.label_loop);
     262           0 :             return GNUNET_SYSERR;
     263             :           }
     264           4 :           cmd[i].details.save_array.index_loop = ret;
     265             : 
     266           4 :           GNUNET_assert (NULL == cmd[i].details.save_array.data_saved);
     267           8 :           cmd[i].details.save_array.data_saved =
     268           4 :             GNUNET_new_array (cmd[i].details.save_array.nb_saved,
     269             :                               struct PERF_TALER_EXCHANGEDB_Data);
     270           8 :           cmd[i].details.save_array.type_saved =
     271           4 :             cmd[cmd[i].details.save_array.index_save].exposed.type;
     272             :         }
     273           4 :         break;
     274             : 
     275             :       case PERF_TALER_EXCHANGEDB_CMD_LOAD_ARRAY:
     276             :         {
     277             :           int ret;
     278             : 
     279           3 :           ret = cmd_find (cmd,
     280           3 :                           cmd[i].details.load_array.label_save);
     281           3 :           if (GNUNET_SYSERR == ret)
     282             :           {
     283           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     284             :                         "%d:Undefined reference to %s\n",
     285             :                         i,
     286             :                         cmd[i].details.load_array.label_save);
     287           0 :             return GNUNET_SYSERR;
     288             :           }
     289           3 :           if (PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY != cmd[ret].command)
     290             :           {
     291           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     292             :                         "%d:Wrong type reference to %s\n",
     293             :                         i,
     294             :                         cmd[i].details.load_array.label_save);
     295           0 :             return GNUNET_SYSERR;
     296             :           }
     297           3 :           cmd[i].details.load_array.index_save = ret;
     298             : 
     299           3 :           ret = cmd_find (cmd,
     300           3 :                           cmd[i].details.load_array.label_loop);
     301           3 :           if (GNUNET_SYSERR == ret)
     302             :           {
     303           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     304             :                         "%d:Undefined reference to %s\n",
     305             :                         i,
     306             :                         cmd[i].details.load_array.label_loop);
     307           0 :             return GNUNET_SYSERR;
     308             :           }
     309           3 :           if (PERF_TALER_EXCHANGEDB_CMD_LOOP != cmd[ret].command)
     310             :           {
     311           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     312             :                         "%d:Wrong type reference to %s\n",
     313             :                         i,
     314             :                         cmd[i].details.load_array.label_loop);
     315           0 :             return GNUNET_SYSERR;
     316             :           }
     317           3 :           cmd[i].details.load_array.index_loop = ret;
     318             : 
     319           6 :           cmd[i].details.load_array.permutation =
     320           3 :             GNUNET_CRYPTO_random_permute (
     321             :               GNUNET_CRYPTO_QUALITY_WEAK,
     322           3 :               cmd[cmd[i].details.load_array.index_save].details.save_array.nb_saved);
     323           3 :           GNUNET_assert (NULL != cmd[i].details.load_array.permutation);
     324             : 
     325           3 :           cmd[i].exposed.type = cmd[cmd[i].details.load_array.index_save].details.save_array.type_saved;
     326             :         }
     327           3 :         break;
     328             : 
     329             :       case PERF_TALER_EXCHANGEDB_CMD_LOAD_RANDOM:
     330             :         {
     331             :           int ret;
     332             : 
     333           0 :           ret = cmd_find (cmd,
     334           0 :                           cmd[i].details.load_random.label_save);
     335           0 :           if (GNUNET_SYSERR == ret)
     336             :           {
     337           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     338             :                         "%d:Undefined reference to %s\n",
     339             :                         i,
     340             :                         cmd[i].details.load_random.label_save);
     341           0 :             return GNUNET_SYSERR;
     342             :           }
     343           0 :           if (PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY != cmd[ret].command)
     344             :           {
     345           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     346             :                         "%d:Wrong type reference to %s\n",
     347             :                         i,
     348             :                         cmd[i].details.load_random.label_save);
     349           0 :             return GNUNET_SYSERR;
     350             :           }
     351           0 :           cmd[i].details.load_random.index_save = ret;
     352             :         }
     353           0 :         break;
     354             : 
     355             :       case PERF_TALER_EXCHANGEDB_CMD_GAUGER:
     356             :         {
     357             :           int ret;
     358             : 
     359           1 :           ret = cmd_find (cmd,
     360           1 :                           cmd[i].details.gauger.label_start);
     361           1 :           if (GNUNET_SYSERR == ret)
     362             :           {
     363           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     364             :                         "%d:Undefined reference to %s\n",
     365             :                         i,
     366             :                         cmd[i].details.gauger.label_start);
     367           0 :             return GNUNET_SYSERR;
     368             :           }
     369           1 :           if (PERF_TALER_EXCHANGEDB_TIME != cmd[ret].exposed.type)
     370             :           {
     371           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     372             :                         "%d:Wrong type reference to %s\n",
     373             :                         i,
     374             :                         cmd[i].details.gauger.label_start);
     375           0 :             return GNUNET_SYSERR;
     376             :           }
     377           1 :           cmd[i].details.gauger.index_start = ret;
     378             : 
     379           1 :           ret = cmd_find (cmd,
     380           1 :                           cmd[i].details.gauger.label_stop);
     381           1 :           if (GNUNET_SYSERR == ret)
     382             :           {
     383           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     384             :                         "%d:Undefined reference to %s\n",
     385             :                         i,
     386             :                         cmd[i].details.gauger.label_stop);
     387           0 :             return GNUNET_SYSERR;
     388             :           }
     389           1 :           if (PERF_TALER_EXCHANGEDB_TIME != cmd[ret].exposed.type)
     390             :           {
     391           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     392             :                         "%d:Wrong type reference to %s\n",
     393             :                         i,
     394             :                         cmd[i].details.gauger.label_stop);
     395           0 :             return GNUNET_SYSERR;
     396             :           }
     397           1 :           cmd[i].details.gauger.index_stop = ret;
     398             :         }
     399           1 :         break;
     400             : 
     401             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_DENOMINATION:
     402             :         {
     403             :           int ret;
     404             : 
     405           1 :           ret = cmd_find (cmd,
     406           1 :                           cmd[i].details.insert_denomination.label_denom);
     407           1 :           if (GNUNET_SYSERR == ret)
     408             :           {
     409           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     410             :                         "%d:Undefined reference to %s\n",
     411             :                         i,
     412             :                         cmd[i].details.insert_denomination.label_denom);
     413           0 :             return GNUNET_SYSERR;
     414             :           }
     415           1 :           if (PERF_TALER_EXCHANGEDB_DENOMINATION_INFO != cmd[ret].exposed.type)
     416             :           {
     417           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     418             :                         "%d:Wrong type reference to %s\n",
     419             :                         i,
     420             :                         cmd[i].details.insert_denomination.label_denom);
     421           0 :             return GNUNET_SYSERR;
     422             :           }
     423           1 :           cmd[i].details.insert_denomination.index_denom = ret;
     424             :         }
     425           1 :         break;
     426             : 
     427             :       case PERF_TALER_EXCHANGEDB_CMD_GET_DENOMINATION:
     428             :         {
     429             :           int ret;
     430             : 
     431           0 :           ret = cmd_find (cmd,
     432           0 :                           cmd[i].details.get_denomination.label_denom);
     433           0 :           if (GNUNET_SYSERR == ret)
     434             :           {
     435           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     436             :                         "%d:Undefined reference to %s\n",
     437             :                         i,
     438             :                         cmd[i].details.get_denomination.label_denom);
     439           0 :             return GNUNET_SYSERR;
     440             :           }
     441           0 :           if (PERF_TALER_EXCHANGEDB_DENOMINATION_INFO != cmd[ret].exposed.type)
     442             :           {
     443           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     444             :                         "%d:Wrong type reference to %s\n",
     445             :                         i,
     446             :                         cmd[i].details.get_denomination.label_denom);
     447           0 :             return GNUNET_SYSERR;
     448             :           }
     449           0 :           cmd[i].details.get_denomination.index_denom = ret;
     450             :         }
     451           0 :         break;
     452             : 
     453             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_RESERVE:
     454             :         {
     455             :           int ret;
     456             : 
     457           1 :           ret = cmd_find (cmd,
     458           1 :                           cmd[i].details.insert_reserve.label_reserve);
     459           1 :           if (GNUNET_SYSERR == ret)
     460             :           {
     461           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     462             :                         "%d:Undefined reference to %s\n",
     463             :                         i,
     464             :                         cmd[i].details.insert_reserve.label_reserve);
     465           0 :             return GNUNET_SYSERR;
     466             :           }
     467           1 :           if (PERF_TALER_EXCHANGEDB_RESERVE != cmd[ret].exposed.type)
     468             :           {
     469           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     470             :                         "%d:Wrong type reference to %s\n",
     471             :                         i,
     472             :                         cmd[i].details.insert_reserve.label_reserve);
     473           0 :             return GNUNET_SYSERR;
     474             :           }
     475           1 :           cmd[i].details.insert_reserve.index_reserve = ret;
     476             :         }
     477           1 :         break;
     478             : 
     479             :       case PERF_TALER_EXCHANGEDB_CMD_GET_RESERVE:
     480             :         {
     481             :           int ret;
     482             : 
     483           0 :           ret = cmd_find (cmd,
     484           0 :                           cmd[i].details.get_reserve.label_reserve);
     485           0 :           if (GNUNET_SYSERR == ret)
     486             :           {
     487           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     488             :                         "%d:Undefined reference to %s\n",
     489             :                         i,
     490             :                         cmd[i].details.get_reserve.label_reserve);
     491           0 :             return GNUNET_SYSERR;
     492             :           }
     493           0 :           if (PERF_TALER_EXCHANGEDB_RESERVE != cmd[ret].exposed.type)
     494             :           {
     495           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     496             :                         "%d:Wrong type reference to %s\n",
     497             :                         i,
     498             :                         cmd[i].details.get_reserve.label_reserve);
     499           0 :             return GNUNET_SYSERR;
     500             :           }
     501           0 :           cmd[i].details.get_reserve.index_reserve = ret;
     502             :         }
     503           0 :         break;
     504             : 
     505             :       case PERF_TALER_EXCHANGEDB_CMD_GET_RESERVE_HISTORY:
     506             :         {
     507             :           int ret;
     508             : 
     509           0 :           ret = cmd_find (cmd,
     510           0 :                           cmd[i].details.get_reserve_history.label_reserve);
     511           0 :           if (GNUNET_SYSERR == ret)
     512             :           {
     513           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     514             :                         "%d:Undefined reference to %s\n",
     515             :                         i,
     516             :                         cmd[i].details.get_reserve_history.label_reserve);
     517           0 :             return GNUNET_SYSERR;
     518             :           }
     519           0 :           if (PERF_TALER_EXCHANGEDB_RESERVE != cmd[ret].exposed.type)
     520             :           {
     521           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     522             :                         "%d:Wrong type reference to %s\n",
     523             :                         i,
     524             :                         cmd[i].details.get_reserve_history.label_reserve);
     525           0 :             return GNUNET_SYSERR;
     526             :           }
     527           0 :           cmd[i].details.get_reserve_history.index_reserve = ret;
     528             :         }
     529           0 :         break;
     530             : 
     531             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_WITHDRAW:
     532             :         {
     533             :           int ret;
     534             : 
     535           1 :           ret = cmd_find (cmd,
     536           1 :                           cmd[i].details.create_withdraw.label_dki);
     537             :           {
     538           1 :             if (GNUNET_SYSERR == ret)
     539             :             {
     540           0 :               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     541             :                           "%d:Undefined reference to %s\n",
     542             :                           i,
     543             :                           cmd[i].details.create_withdraw.label_dki);
     544           0 :               return GNUNET_SYSERR;
     545             :             }
     546           1 :             if (PERF_TALER_EXCHANGEDB_DENOMINATION_INFO != cmd[ret].exposed.type)
     547             :             {
     548           0 :               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     549             :                           "%d:Wrong type reference to %s\n",
     550             :                           i,
     551             :                           cmd[i].details.create_withdraw.label_dki);
     552           0 :               return GNUNET_SYSERR;
     553             :             }
     554             :           }
     555           1 :           cmd[i].details.create_withdraw.index_dki = ret;
     556           1 :           ret = cmd_find (cmd,
     557           1 :                           cmd[i].details.create_withdraw.label_reserve);
     558             :           {
     559           1 :             if (GNUNET_SYSERR == ret)
     560             :             {
     561           0 :               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     562             :                           "%d:Undefined reference to %s\n",
     563             :                           i,
     564             :                           cmd[i].details.create_withdraw.label_reserve);
     565           0 :               return GNUNET_SYSERR;
     566             :             }
     567           1 :             if (PERF_TALER_EXCHANGEDB_RESERVE != cmd[ret].exposed.type)
     568             :             {
     569           0 :               GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     570             :                           "%d:Wrong type reference to %s\n",
     571             :                           i,
     572             :                           cmd[i].details.create_withdraw.label_reserve);
     573           0 :               return GNUNET_SYSERR;
     574             :             }
     575             :           }
     576           1 :           cmd[i].details.create_withdraw.index_reserve = ret;
     577             :         }
     578           1 :         break;
     579             : 
     580             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_WITHDRAW:
     581             :         {
     582             :           int ret;
     583             : 
     584           1 :           ret = cmd_find (cmd,
     585           1 :                           cmd[i].details.insert_withdraw.label_coin);
     586           1 :           if (GNUNET_SYSERR == ret)
     587             :           {
     588           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     589             :                         "%d:Undefined reference to %s\n",
     590             :                         i,
     591             :                         cmd[i].details.insert_withdraw.label_coin);
     592           0 :             return GNUNET_SYSERR;
     593             :           }
     594           1 :           if (PERF_TALER_EXCHANGEDB_COIN != cmd[ret].exposed.type)
     595             :           {
     596           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     597             :                         "%d:Wrong type reference to %s\n",
     598             :                         i,
     599             :                         cmd[i].details.insert_withdraw.label_coin);
     600           0 :             return GNUNET_SYSERR;
     601             :           }
     602           1 :           cmd[i].details.insert_withdraw.index_coin = ret;
     603             :         }
     604           1 :         break;
     605             : 
     606             :       case PERF_TALER_EXCHANGEDB_CMD_GET_WITHDRAW:
     607             :         {
     608             :           int ret;
     609             : 
     610           0 :           ret = cmd_find (cmd,
     611           0 :                           cmd[i].details.get_withdraw.label_coin);
     612           0 :           if (GNUNET_SYSERR == ret)
     613             :           {
     614           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     615             :                         "%d:Undefined reference to %s\n",
     616             :                         i,
     617             :                         cmd[i].details.get_withdraw.label_coin);
     618           0 :             return GNUNET_SYSERR;
     619             :           }
     620           0 :           if (PERF_TALER_EXCHANGEDB_COIN != cmd[ret].exposed.type)
     621             :           {
     622           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     623             :                         "%d:Wrong type reference to %s\n",
     624             :                         i,
     625             :                         cmd[i].details.get_withdraw.label_coin);
     626           0 :             return GNUNET_SYSERR;
     627             :           }
     628           0 :           cmd[i].details.get_withdraw.index_coin = ret;
     629             :         }
     630           0 :         break;
     631             : 
     632             :       case PERF_TALER_EXCHANGEDB_CMD_GET_COIN_TRANSACTION:
     633             :         {
     634             :           int ret;
     635           0 :           ret = cmd_find (cmd,
     636           0 :                           cmd[i].details.get_coin_transaction.label_coin);
     637           0 :           if (GNUNET_SYSERR == ret)
     638             :           {
     639           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     640             :                         "%d:Undefined reference to %s\n",
     641             :                         i,
     642             :                         cmd[i].details.get_coin_transaction.label_coin);
     643           0 :             return GNUNET_SYSERR;
     644             :           }
     645           0 :           if (PERF_TALER_EXCHANGEDB_COIN != cmd[ret].exposed.type)
     646             :           {
     647           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     648             :                         "%d:Wrong type reference to %s\n",
     649             :                         i,
     650             :                         cmd[i].details.get_coin_transaction.label_coin);
     651           0 :             return GNUNET_SYSERR;
     652             :           }
     653           0 :           cmd[i].details.get_coin_transaction.index_coin = ret;
     654             :         }
     655           0 :         break;
     656             : 
     657             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_DEPOSIT:
     658             :         {
     659             :           int ret;
     660             : 
     661           1 :           ret = cmd_find (cmd,
     662           1 :                           cmd[i].details.create_deposit.label_coin);
     663           1 :           if (GNUNET_SYSERR == ret)
     664             :           {
     665           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     666             :                         "%d:Undefined reference to %s\n",
     667             :                         i,
     668             :                         cmd[i].details.create_deposit.label_coin);
     669           0 :             return GNUNET_SYSERR;
     670             :           }
     671           1 :           if (PERF_TALER_EXCHANGEDB_COIN != cmd[ret].exposed.type)
     672             :           {
     673           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     674             :                         "%d:Wrong type reference to %s\n",
     675             :                         i,
     676             :                         cmd[i].details.create_deposit.label_coin);
     677           0 :             return GNUNET_SYSERR;
     678             :           }
     679           1 :           cmd[i].details.create_deposit.index_coin = ret;
     680             :         }
     681           1 :         break;
     682             : 
     683             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_DEPOSIT:
     684             :         {
     685             :           int ret;
     686             : 
     687           1 :           ret = cmd_find( cmd,
     688           1 :                           cmd[i].details.insert_deposit.label_deposit);
     689           1 :           if (GNUNET_SYSERR == ret)
     690             :           {
     691           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     692             :                         "%d:Undefined reference to %s\n",
     693             :                         i,
     694             :                         cmd[i].details.insert_deposit.label_deposit);
     695           0 :             return GNUNET_SYSERR;
     696             :           }
     697           1 :           if (PERF_TALER_EXCHANGEDB_DEPOSIT != cmd[ret].exposed.type)
     698             :           {
     699           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     700             :                         "%d:Wrong type reference to %s\n",
     701             :                         i,
     702             :                         cmd[i].details.insert_deposit.label_deposit);
     703           0 :             return GNUNET_SYSERR;
     704             :           }
     705           1 :           cmd[i].details.insert_deposit.index_deposit = ret;
     706             :         }
     707           1 :         break;
     708             : 
     709             :       case PERF_TALER_EXCHANGEDB_CMD_GET_DEPOSIT:
     710             :         {
     711             :           int ret;
     712             : 
     713           0 :           ret = cmd_find (cmd,
     714           0 :                           cmd[i].details.get_deposit.label_deposit);
     715           0 :           if (GNUNET_SYSERR == ret)
     716             :           {
     717           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     718             :                         "%d:Undefined reference to %s\n",
     719             :                         i,
     720             :                         cmd[i].details.get_deposit.label_deposit);
     721           0 :             return GNUNET_SYSERR;
     722             :           }
     723           0 :           if (PERF_TALER_EXCHANGEDB_DEPOSIT != cmd[ret].exposed.type)
     724             :           {
     725           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     726             :                         "%d:Wrong type reference to %s\n",
     727             :                         i,
     728             :                         cmd[i].details.get_deposit.label_deposit);
     729           0 :             return GNUNET_SYSERR;
     730             :           }
     731           0 :           cmd[i].details.get_deposit.index_deposit = ret;
     732             :         }
     733           0 :         break;
     734             : 
     735             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION:
     736             :         {
     737             :           int ret;
     738             : 
     739           0 :           ret = cmd_find (cmd,
     740           0 :                           cmd[i].details.get_refresh_session.label_hash);
     741           0 :           if (GNUNET_SYSERR == ret)
     742             :           {
     743           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     744             :                         "%d:Undefined reference to %s\n",
     745             :                         i,
     746             :                         cmd[i].details.get_refresh_session.label_hash);
     747           0 :             return GNUNET_SYSERR;
     748             :           }
     749           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     750             :           {
     751           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     752             :                         "%d:Wrong type reference to %s\n",
     753             :                         i,
     754             :                         cmd[i].details.get_refresh_session.label_hash);
     755           0 :             return GNUNET_SYSERR;
     756             :           }
     757           0 :           cmd[i].details.get_refresh_session.index_hash = ret;
     758             :         }
     759           0 :         break;
     760             : 
     761             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER:
     762             :         {
     763             :           int ret;
     764           0 :           ret = cmd_find (cmd,
     765           0 :                           cmd[i].details.insert_refresh_order.label_hash);
     766           0 :           if (GNUNET_SYSERR == ret)
     767             :           {
     768           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     769             :                         "%d:Undefined reference to %s\n",
     770             :                         i,
     771             :                         cmd[i].details.insert_refresh_order.label_hash);
     772           0 :             return GNUNET_SYSERR;
     773             :           }
     774           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     775             :           {
     776           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     777             :                         "%d:Wrong type reference to %s\n",
     778             :                         i,
     779             :                         cmd[i].details.insert_refresh_order.label_hash);
     780           0 :             return GNUNET_SYSERR;
     781             :           }
     782           0 :           cmd[i].details.insert_refresh_order.index_hash = ret;
     783             : 
     784           0 :           ret = cmd_find (cmd,
     785           0 :                           cmd[i].details.insert_refresh_order.label_denom);
     786           0 :           if (GNUNET_SYSERR == ret)
     787             :           {
     788           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     789             :                         "%d:Undefined reference to %s\n",
     790             :                         i,
     791             :                         cmd[i].details.insert_refresh_order.label_denom);
     792           0 :             return GNUNET_SYSERR;
     793             :           }
     794           0 :           if (PERF_TALER_EXCHANGEDB_DENOMINATION_INFO != cmd[ret].exposed.type)
     795             :           {
     796           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     797             :                         "%d:Wrong type reference to %s\n",
     798             :                         i,
     799             :                         cmd[i].details.insert_refresh_order.label_denom);
     800           0 :             return GNUNET_SYSERR;
     801             :           }
     802           0 :           cmd[i].details.insert_refresh_order.index_denom = ret;
     803             :         }
     804           0 :         break;
     805             : 
     806             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_ORDER:
     807             :         {
     808             :           int ret;
     809           0 :           ret = cmd_find (cmd,
     810           0 :                           cmd[i].details.get_refresh_order.label_hash);
     811           0 :           if (GNUNET_SYSERR == ret)
     812             :           {
     813           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     814             :                         "%d:Undefined reference to %s\n",
     815             :                         i,
     816             :                         cmd[i].details.get_refresh_order.label_hash);
     817           0 :             return GNUNET_SYSERR;
     818             :           }
     819           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     820             :           {
     821           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     822             :                         "%d:Wrong type reference to %s\n",
     823             :                         i,
     824             :                         cmd[i].details.get_refresh_order.label_hash);
     825           0 :             return GNUNET_SYSERR;
     826             :           }
     827           0 :           cmd[i].details.get_refresh_order.index_hash = ret;
     828             :         }
     829           0 :         break;
     830             : 
     831             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_COIN:
     832             :        {
     833             :           int ret;
     834           0 :           ret = cmd_find (cmd,
     835           0 :                           cmd[i].details.insert_refresh_commit_coin.label_hash);
     836           0 :           if (GNUNET_SYSERR == ret)
     837             :           {
     838           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     839             :                         "%d:Undefined reference to %s\n",
     840             :                         i,
     841             :                         cmd[i].details.insert_refresh_commit_coin.label_hash);
     842           0 :             return GNUNET_SYSERR;
     843             :           }
     844           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     845             :           {
     846           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     847             :                         "%d:Wrong type reference to %s\n",
     848             :                         i,
     849             :                         cmd[i].details.insert_refresh_commit_coin.label_hash);
     850           0 :             return GNUNET_SYSERR;
     851             :           }
     852           0 :           cmd[i].details.insert_refresh_commit_coin.index_hash = ret;
     853             :         }
     854           0 :        break;
     855             : 
     856             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_COIN:
     857             :        {
     858             :           int ret;
     859           0 :           ret = cmd_find (cmd,
     860           0 :                           cmd[i].details.get_refresh_commit_coin.label_hash);
     861           0 :           if (GNUNET_SYSERR == ret)
     862             :           {
     863           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     864             :                         "%d:Undefined reference to %s\n",
     865             :                         i,
     866             :                         cmd[i].details.get_refresh_commit_coin.label_hash);
     867           0 :             return GNUNET_SYSERR;
     868             :           }
     869           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     870             :           {
     871           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     872             :                         "%d:Wrong type reference to %s\n",
     873             :                         i,
     874             :                         cmd[i].details.get_refresh_commit_coin.label_hash);
     875           0 :             return GNUNET_SYSERR;
     876             :           }
     877           0 :           cmd[i].details.get_refresh_commit_coin.index_hash = ret;
     878             :         }
     879           0 :         break;
     880             : 
     881             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_LINK:
     882             :        {
     883             :           int ret;
     884           0 :           ret = cmd_find (cmd,
     885           0 :                           cmd[i].details.insert_refresh_commit_link.label_hash);
     886           0 :           if (GNUNET_SYSERR == ret)
     887             :           {
     888           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     889             :                         "%d:Undefined reference to %s\n",
     890             :                         i,
     891             :                         cmd[i].details.insert_refresh_commit_link.label_hash);
     892           0 :             return GNUNET_SYSERR;
     893             :           }
     894           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     895             :           {
     896           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     897             :                         "%d:Wrong type reference to %s\n",
     898             :                         i,
     899             :                         cmd[i].details.insert_refresh_commit_link.label_hash);
     900           0 :             return GNUNET_SYSERR;
     901             :           }
     902           0 :           cmd[i].details.insert_refresh_commit_link.index_hash = ret;
     903             :         }
     904           0 :         break;
     905             : 
     906             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_LINK:
     907             :        {
     908             :           int ret;
     909           0 :           ret = cmd_find (cmd,
     910           0 :                           cmd[i].details.get_refresh_commit_link.label_hash);
     911           0 :           if (GNUNET_SYSERR == ret)
     912             :           {
     913           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     914             :                         "%d:Undefined reference to %s\n",
     915             :                         i,
     916             :                         cmd[i].details.get_refresh_commit_link.label_hash);
     917           0 :             return GNUNET_SYSERR;
     918             :           }
     919           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     920             :           {
     921           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     922             :                         "%d:Wrong type reference to %s\n",
     923             :                         i,
     924             :                         cmd[i].details.get_refresh_commit_link.label_hash);
     925           0 :             return GNUNET_SYSERR;
     926             :           }
     927           0 :           cmd[i].details.get_refresh_commit_link.index_hash = ret;
     928             :         }
     929           0 :         break;
     930             : 
     931             :       case PERF_TALER_EXCHANGEDB_CMD_GET_MELT_COMMITMENT:
     932             :        {
     933             :           int ret;
     934           0 :           ret = cmd_find (cmd,
     935           0 :                           cmd[i].details.get_melt_commitment.label_hash);
     936           0 :           if (GNUNET_SYSERR == ret)
     937             :           {
     938           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     939             :                         "%d:Undefined reference to %s\n",
     940             :                         i,
     941             :                         cmd[i].details.get_melt_commitment.label_hash);
     942           0 :             return GNUNET_SYSERR;
     943             :           }
     944           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     945             :           {
     946           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     947             :                         "%d:Wrong type reference to %s\n",
     948             :                         i,
     949             :                         cmd[i].details.get_melt_commitment.label_hash);
     950           0 :             return GNUNET_SYSERR;
     951             :           }
     952           0 :           cmd[i].details.get_melt_commitment.index_hash = ret;
     953             :         }
     954           0 :         break;
     955             : 
     956             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_OUT:
     957             :        {
     958             :           int ret;
     959           0 :           ret = cmd_find (cmd,
     960           0 :                           cmd[i].details.insert_refresh_out.label_hash);
     961           0 :           if (GNUNET_SYSERR == ret)
     962             :           {
     963           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     964             :                         "%d:Undefined reference to %s\n",
     965             :                         i,
     966             :                         cmd[i].details.insert_refresh_out.label_hash);
     967           0 :             return GNUNET_SYSERR;
     968             :           }
     969           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     970             :           {
     971           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     972             :                         "%d:Wrong type reference to %s\n",
     973             :                         i,
     974             :                         cmd[i].details.insert_refresh_out.label_hash);
     975           0 :             return GNUNET_SYSERR;
     976             :           }
     977           0 :           cmd[i].details.insert_refresh_out.index_hash = ret;
     978             :         }
     979           0 :         break;
     980             : 
     981             :       case PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA_LIST:
     982             :        {
     983             :           int ret;
     984           0 :           ret = cmd_find (cmd,
     985           0 :                           cmd[i].details.get_link_data_list.label_hash);
     986           0 :           if (GNUNET_SYSERR == ret)
     987             :           {
     988           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     989             :                         "%d:Undefined reference to %s\n",
     990             :                         i,
     991             :                         cmd[i].details.get_link_data_list.label_hash);
     992           0 :             return GNUNET_SYSERR;
     993             :           }
     994           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
     995             :           {
     996           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
     997             :                         "%d:Wrong type reference to %s\n",
     998             :                         i,
     999             :                         cmd[i].details.get_link_data_list.label_hash);
    1000           0 :             return GNUNET_SYSERR;
    1001             :           }
    1002           0 :           cmd[i].details.get_link_data_list.index_hash = ret;
    1003             :         }
    1004           0 :         break;
    1005             : 
    1006             :       case PERF_TALER_EXCHANGEDB_CMD_GET_TRANSFER:
    1007             :        {
    1008             :           int ret;
    1009           0 :           ret = cmd_find (cmd,
    1010           0 :                           cmd[i].details.get_transfer.label_hash);
    1011           0 :           if (GNUNET_SYSERR == ret)
    1012             :           {
    1013           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1014             :                         "%d:Undefined reference to %s\n",
    1015             :                         i,
    1016             :                         cmd[i].details.get_transfer.label_hash);
    1017           0 :             return GNUNET_SYSERR;
    1018             :           }
    1019           0 :           if (PERF_TALER_EXCHANGEDB_REFRESH_HASH != cmd[ret].exposed.type)
    1020             :           {
    1021           0 :             GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1022             :                         "%d:Wrong type reference to %s\n",
    1023             :                         i,
    1024             :                         cmd[i].details.get_transfer.label_hash);
    1025           0 :             return GNUNET_SYSERR;
    1026             :           }
    1027           0 :           cmd[i].details.get_transfer.index_hash = ret;
    1028             :         }
    1029           0 :         break;
    1030             : 
    1031             :       case PERF_TALER_EXCHANGEDB_CMD_END:
    1032             :       case PERF_TALER_EXCHANGEDB_CMD_DEBUG:
    1033             :       case PERF_TALER_EXCHANGEDB_CMD_LOOP:
    1034             :       case PERF_TALER_EXCHANGEDB_CMD_NEW_SESSION:
    1035             :       case PERF_TALER_EXCHANGEDB_CMD_START_TRANSACTION:
    1036             :       case PERF_TALER_EXCHANGEDB_CMD_COMMIT_TRANSACTION:
    1037             :       case PERF_TALER_EXCHANGEDB_CMD_ABORT_TRANSACTION:
    1038             :       case PERF_TALER_EXCHANGEDB_CMD_GET_TIME:
    1039             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_DENOMINATION:
    1040             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_RESERVE:
    1041             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_REFRESH_SESSION:
    1042          19 :         break;
    1043             :     }
    1044             :   }
    1045           2 :   return GNUNET_OK;
    1046             : }
    1047             : 
    1048             : 
    1049             : /**
    1050             :  * Free the memory of the command chain
    1051             :  */
    1052             : static int
    1053           2 : cmd_clean (struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
    1054             : {
    1055             :   unsigned int i;
    1056             : 
    1057          39 :   for (i=0; PERF_TALER_EXCHANGEDB_CMD_END != cmd[i].command; i++)
    1058             :   {
    1059          37 :     switch (cmd[i].command)
    1060             :     {
    1061             :       case PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY:
    1062             :         {
    1063             :           unsigned int j;
    1064             : 
    1065           9 :           for (j = 0; j < cmd[i].details.save_array.nb_saved; j++)
    1066             :           {
    1067           5 :             data_free (&cmd[i].details.save_array.data_saved[j]);
    1068             :           }
    1069           4 :           GNUNET_free (cmd[i].details.save_array.data_saved);
    1070           4 :           cmd[i].details.save_array.data_saved = NULL;
    1071             :         }
    1072           4 :         break;
    1073             : 
    1074             :       case PERF_TALER_EXCHANGEDB_CMD_LOAD_ARRAY:
    1075           3 :         GNUNET_free (cmd[i].details.load_array.permutation);
    1076           3 :         cmd[i].details.load_array.permutation = NULL;
    1077           3 :         break;
    1078             : 
    1079             :       default:
    1080          30 :         break;
    1081             :     }
    1082          37 :     data_free (&cmd[i].exposed);
    1083             :   }
    1084           2 :   return GNUNET_OK;
    1085             : }
    1086             : 
    1087             : 
    1088             : /**
    1089             :  * Handles the command #PERF_TALER_EXCHANGEDB_CMD_END_LOOP for the interpreter
    1090             :  * Cleans the memory at the end of the loop
    1091             :  */
    1092             : static void
    1093           8 : interpret_end_loop (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
    1094             : {
    1095             :   unsigned int i;
    1096             :   in| jumt;*    1097             : 
    1098           8 :   jump = state->cmd[state->i].details.end_loop.index_loop;
    1099             :   // Cleaning up the memory in the loop
    1100          51 :   for (i = jump; i < state->i; i++)
    1101          43 :     data_free (&state->cmd[i].exposed);
    1102             : 
    1103           8 :   state->cmd[jump].details.loop.curr_iteration++;
    1104             :   /* If the loop is not finished */
    1105          16 :   if (state->cmd[jump].details.loop.max_iterations >
    1106           8 :       state->cmd[jump].details.loop.curr_iteration)
    1107             :   {
    1108             :     /* jump back to the start */
    1109           4 :     state->i = jump;
    1110             :   }
    1111             :   else
    1112             :   {
    1113             :     /* Reset the loop counter and continue running */
    1114           4 :     state->cmd[jump].details.loop.curr_iteration = 0;
    1115             :   }
    1116           8 : }
    1117             : 
    1118             : 
    1119             : /**
    1120             :  * Part of the interpreter specific to
    1121             :  * #PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY
    1122             :  * Saves the data exposed by another command into
    1123             :  * an array in the command specific struct.
    1124             :  */
    1125             : static void
    1126           8 : interpret_save_array (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
    1127             : {
    1128           8 :   struct PERF_TALER_EXCHANGEDB_Cmd *cmd = &state->cmd[state->i];
    1129             :   struct PERF_TALER_EXCHANGEDB_Cmd *save_ref;
    1130             :   struct PERF_TALER_EXCHANGEDB_Cmd *loop_ref;
    1131             :   int loop_index;
    1132             :   int save_index;
    1133             :   unsigned int selection_chance;
    1134             : 
    1135           8 :   loop_index = cmd->details.save_array.index_loop;
    1136           8 :   save_index = cmd->details.save_array.index_save;
    1137           8 :   loop_ref = &state->cmd[loop_index];
    1138           8 :   save_ref = &state->cmd[save_index];
    1139             :   /* Array initialization on first loop iteration
    1140             :      Alows for nested loops */
    1141           8 :   if (0 == cmd->details.loop.curr_iteration)
    1142             :   {
    1143           5 :     cmd->details.save_array.index = 0;
    1144             :   }
    1145             :   /* The probability distribution of the saved items will be a little biased
    1146             :      against the few last items but it should not be a big problem. */
    1147          16 :   selection_chance = loop_ref->details.loop.max_iterations /
    1148           8 :     cmd->details.save_array.nb_saved;
    1149             :   /*
    1150             :    * If the remaining space is equal to the remaining number of
    1151             :    * iterations, the item is automaticly saved.
    1152             :    *
    1153             :    * Else it is saved only if the random numbre generated is 0
    1154             :    */
    1155          16 :   if ( (0 < (cmd->details.save_array.nb_saved -
    1156          14 :              cmd->details.save_array.index) ) &&
    1157          12 :        ( ((loop_ref->details.loop.max_iterations -
    1158           6 :            loop_ref->details.loop.curr_iteration) ==
    1159          12 :           (cmd->details.save_array.nb_saved -
    1160           8 :            cmd->details.save_array.index)) ||
    1161           2 :          (0 == GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
    1162             :                                          selection_chance)) ) )
    1163             :   {
    1164             :     struct PERF_TALER_EXCHANGEDB_Data *save_location;
    1165             :     struct PERF_TALER_EXCHANGEDB_Data *item_saved;
    1166             : 
    1167           5 :     save_location = &cmd->details.save_array.data_saved[cmd->details.save_array.index];
    1168           5 :     item_saved = &save_ref->exposed;
    1169           5 :     data_copy (item_saved, save_location);
    1170           5 :     cmd->details.save_array.index++;
    1171             :   }
    1172           8 : }
    1173             : 
    1174             : 
    1175             : /**
    1176             :  * Part of the interpreter specific to
    1177             :  * #PERF_TALER_EXCHANGEDB_CMD_LOAD_ARRAY
    1178             :  * Gets data from a #PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY and exposes a copy
    1179             :  */
    1180             : static void
    1181           3 : interpret_load_array (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
    1182             : {
    1183           3 :   struct PERF_TALER_EXCHANGEDB_Cmd *cmd = &state->cmd[state->i];
    1184             :   unsigned int loop_iter;
    1185             :   int loop_index;
    1186             :   int save_index;
    1187             :   struct PERF_TALER_EXCHANGEDB_Data *loaded_data;
    1188             : 
    1189           3 :   loop_index = cmd->details.load_array.index_loop;
    1190           3 :   save_index = cmd->details.load_array.index_save;
    1191           3 :   loop_iter = state->cmd[loop_index].details.loop.curr_iteration;
    1192             :   {
    1193             :     unsigned int i;
    1194             :     unsigned int quotient;
    1195             : 
    1196             :     /* In case the iteration number is higher than the amount saved,
    1197             :      * the number is run several times in the permutation array */
    1198           3 :     quotient = loop_iter / state->cmd[save_index].details.save_array.nb_saved;
    1199           3 :     loop_iter = loop_iter % state->cmd[save_index].details.save_array.nb_saved;
    1200           6 :     for (i=0; i<=quotient; i++)
    1201           3 :       loop_iter = cmd->details.load_array.permutation[loop_iter];
    1202             :   }
    1203             :   /* Extracting the data from the loop_indexth indice in save_index
    1204             :    * array.
    1205             :    */
    1206           3 :   loaded_data = &state->cmd[save_index].details.save_array.data_saved[loop_iter];
    1207           3 :   data_copy (loaded_data,
    1208             :              &cmd->exposed);
    1209           3 : }
    1210             : 
    1211             : 
    1212             : /**
    1213             :  * Part of the interpreter specific to
    1214             :  * #PERF_TALER_EXCHANGEDB_CMD_LOAD_RANDOM
    1215             :  * Get a random element from a #PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY and exposes it
    1216             :  */
    1217             : static void
    1218           0 : interprete_load_random (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
    1219             : {
    1220           0 :   struct PERF_TALER_EXCHANGEDB_Cmd *cmd = &state->cmd[state->i];
    1221             :   unsigned int index;
    1222             :   int save_index;
    1223             : 
    1224           0 :   save_index = cmd->details.load_random.index_save;
    1225           0 :   index = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
    1226           0 :                                     state->cmd[save_index].details.save_array.nb_saved);
    1227           0 :   data_copy (&state->cmd[save_index].details.save_array.data_saved[index],
    1228             :              &cmd->exposed);
    1229           0 : }
    1230             : 
    1231             : 
    1232             : /**
    1233             :  * Iterate over the commands, acting accordingly at each step
    1234             :  *
    1235             :  * @param state the current state of the interpreter
    1236             :  */
    1237             : static int
    1238           2 : interpret (struct PERF_TALER_EXCHANGEDB_interpreter_state *state)
    1239             : {
    1240          57 :   for (state->i=0; PERF_TALER_EXCHANGEDB_CMD_END != state->cmd[state->i].command; state->i++)
    1241             :   {
    1242          55 :     switch (state->cmd[state->i].command)
    1243             :     {
    1244             :       case PERF_TALER_EXCHANGEDB_CMD_END:
    1245           0 :         return GNUNET_YES;
    1246             : 
    1247             :       case PERF_TALER_EXCHANGEDB_CMD_DEBUG:
    1248           5 :         GNUNET_log (GNUNET_ERROR_TYPE_INFO,
    1249             :                     "%s\n",
    1250             :                     state->cmd[state->i].label);
    1251           5 :         break;
    1252             : 
    1253             :       case PERF_TALER_EXCHANGEDB_CMD_LOOP:
    1254           4 :         break;
    1255             : 
    1256             :       case PERF_TALER_EXCHANGEDB_CMD_END_LOOP:
    1257           8 :         interpret_end_loop (state);
    1258           8 :         break;
    1259             : 
    1260             :       case PERF_TALER_EXCHANGEDB_CMD_GET_TIME:
    1261           4 :         state->cmd[state->i].exposed.data.time =
    1262           2 :           GNUNET_new (struct GNUNET_TIME_Absolute);
    1263           2 :         *state->cmd[state->i].exposed.data.time =
    1264             :           GNUNET_TIME_absolute_get ();
    1265           2 :         break;
    1266             : 
    1267             :       case PERF_TALER_EXCHANGEDB_CMD_GAUGER:
    1268             :         {
    1269             :           unsigned int start_index;
    1270             :           unsigned int stop_index;
    1271             :           float ips;
    1272             :           struct GNUNET_TIME_Absolute start;
    1273             :           struct GNUNET_TIME_Absolute stop;
    1274             :           struct GNUNET_TIME_Relative elapsed;
    1275             : 
    1276           1 :           start_index = state->cmd[state->i].details.gauger.index_start;
    1277           1 :           stop_index = state->cmd[state->i].details.gauger.index_stop;
    1278           1 :           start = *state->cmd[start_index].exposed.data.time;
    1279           1 :           stop = *state->cmd[stop_index].exposed.data.time;
    1280           1 :           elapsed = GNUNET_TIME_absolute_get_difference (start,
    1281             :                                                          stop);
    1282           1 :           ips = (1.0 * state->cmd[state->i].details.gauger.divide) / (elapsed.rel_value_us/1000000.0);
    1283           1 :           GAUGER (state->cmd[state->i].details.gauger.category,
    1284             :                   state->cmd[state->i].details.gauger.description,
    1285             :                   ips,
    1286             :                   state->cmd[state->i].details.gauger.unit);
    1287             :         }
    1288           1 :         break;
    1289             : 
    1290             :       case PERF_TALER_EXCHANGEDB_CMD_NEW_SESSION:
    1291           0 :         state->session = state->plugin->get_session (state->plugin->cls);
    1292           0 :         break;
    1293             : 
    1294             :       case PERF_TALER_EXCHANGEDB_CMD_START_TRANSACTION:
    1295           4 :         GNUNET_break (GNUNET_OK ==
    1296             :                       state->plugin->start (state->plugin->cls,
    1297             :                                             state->session));
    1298           4 :         break;
    1299             : 
    1300             :       case PERF_TALER_EXCHANGEDB_CMD_COMMIT_TRANSACTION:
    1301           4 :         GNUNET_break (GNUNET_DB_STATUS_SUCCESS_NO_RESULTS ==
    1302             :                       state->plugin->commit (state->plugin->cls,
    1303             :                                              state->session));
    1304           4 :         break;
    1305             :       case PERF_TALER_EXCHANGEDB_CMD_ABORT_TRANSACTION:
    1306           0 :         state->plugin->rollback (state->plugin->cls,
    1307             :                                  state->session);
    1308           0 :         break;
    1309             : 
    1310             :       case PERF_TALER_EXCHANGEDB_CMD_SAVE_ARRAY:
    1311           8 :         interpret_save_array (state);
    1312           8 :         break;
    1313             : 
    1314             :       case PERF_TALER_EXCHANGEDB_CMD_LOAD_ARRAY:
    1315           3 :         interpret_load_array (state);
    1316           3 :         break;
    1317             : 
    1318             :       case PERF_TALER_EXCHANGEDB_CMD_LOAD_RANDOM:
    1319           0 :         interprete_load_random (state);
    1320           0 :         break;
    1321             : 
    1322             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_DEPOQIT:
=sxan class="lineNum">    1323             :         {
    1324             :           int coin_index;
    1325             :           struct TALER_EXCHANGEDB_Deposit *deposit;
    1326             : 
    1327           1 :           coin_index = state->cmd[state->i].details.create_deposit.index_coin;
    1328           1 :           deposit = PERF_TALER_EXCHANGEDB_deposit_init (state->cmd[coin_index].exposed.data.coin);
    1329           1 :           GNUNET_assert (NULL != deposit);
    1330           1 :           state->cmd[state->i].exposed.data.deposit = deposit;
    1331             :         }
    1332           1 :         break;
    1333             : 
    1334             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_DEPOSIT:
    1335             :         {
    1336             :           int deposit_index;
    1337             :           enum GNUNET_DB_QueryStatus qs;
    1338             :           struct TALER_EXCHANGEDB_Deposit *deposit;
    1339             : 
    1340           1 :           deposit_index = state->cmd[state->i].details.insert_deposit.index_deposit;
    1341           1 :           deposit = state->cmd[deposit_index].exposed.data.deposit;
    1342           1 :           qs = state->plugin->insert_deposit (state->plugin->cls,
    1343             :                                                         state->session,
    1344             :                                                         deposit);
    1345           1 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
    1346           1 :           state->cmd[state->i].exposed.data.deposit = deposit;
    1347             :         }
    1348           1 :         break;
    1349             : 
    1350             :       case PERF_TALER_EXCHANGEDB_CMD_GET_DEPOSIT:
    1351             :         {
    1352             :           unsigned int source_index;
    1353             :           enum GNUNET_DB_QueryStatus ret;
    1354             :           struct PERF_TALER_EXCHANGEDB_Data *data;
    1355             : 
    1356           0 :           source_index = state->cmd[state->i].details.get_deposit.index_deposit;
    1357           0 :           data = &state->cmd[source_index].exposed;
    1358           0 :           ret = state->plugin->have_deposit (state->plugin->cls,
    1359             :                                              state->session,
    1360           0 :                                              data->data.deposit);
    1361           0 :           GNUNET_assert (0 >= ret);
    1362             :         }
    1363           0 :         break;
    1364             : 
    1365             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_RESERVE:
    1366             :         {
    1367             :           struct PERF_TALER_EXCHANGEDB_Reserve *reserve;
    1368             : 
    1369           4 :           reserve = PERF_TALER_EXCHANGEDB_reserve_init ();
    1370           4 :           state->cmd[state->i].exposed.data.reserve = reserve;
    1371             :         }
    1372           4 :         break;
    1373             : 
    1374             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_RESERVE:
    1375             :         {
    1376             :           unsigned int reserve_index;
    1377             :           int ret;
    1378             :           struct PERF_TALER_EXCHANGEDB_Reserve *reserve;
    1379             :           json_t *sndr;
    1380             :           uint32_t uid;
    1381             : 
    1382           4 :           reserve_index = state->cmd[state->i].details.insert_reserve.index_reserve;
    1383           4 :           reserve = state->cmd[reserve_index].exposed.data.reserve;
    1384           4 :           sndr = json_pack ("{s:i}",
    1385             :                             "account",
    1386           4 :                             (int) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
    1387             :                                                             UINT32_MAX));
    1388           4 :           uid = GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
    1389             :                                           UINT32_MAX);
    1390           4 :           GNUNET_assert (NULL != sndr);
    1391           8 :           ret = state->plugin->reserves_in_insert (state->plugin->cls,
    1392             :                                                    state->session,
    1393           4 :                                                    &reserve->reserve.pub,
    1394           4 :                                                    &reserve->reserve.balance,
    1395             :                                                    GNUNET_TIME_absolute_get (),
    1396             :                                                    sndr,
    1397             :                                                    &uid,
    1398             :                                                    sizeof (uid));
    1399           4 :           GNUNET_assert (GNUNET_SYSERR != ret);
    1400           4 :           json_decref (sndr);
    1401             :         }
    1402           4 :         break;
    1403             : 
    1404             :       case PERF_TALER_EXCHANGEDB_CMD_GET_RESERVE:
    1405             :         {
    1406             :           unsigned int reserve_index;
    1407             :           int ret;
    1408             :           struct PERF_TALER_EXCHANGEDB_Data *data;
    1409             : 
    1410             : 
    1411           0 :           reserve_index = state->cmd[state->i].details.get_reserve.index_reserve;
    1412           0 :           data = &state->cmd[reserve_index].exposed;
    1413           0 :           ret = state->plugin->reserve_get (state->plugin->cls,
    1414             :                                             state->session,
    1415           0 :                                             &data->data.reserve->reserve);
    1416           0 :           GNUNET_assert (GNUNET_OK == ret);
    1417             :         }
    1418           0 :         break;
    1419             : 
    1420             :       case PERF_TALER_EXCHANGEDB_CMD_GET_RESERVE_HISTORY:
    1421             :         {
    1422             :           unsigned int reserve_index;
    1423             :           struct TALER_EXCHANGEDB_ReserveHistory *history;
    1424             :           struct PERF_TALER_EXCHANGEDB_Data *data;
    1425             :           enum GNUNET_DB_QueryStatus qs;
    1426             : 
    1427           0 :           reserve_index = state->cmd[state->i].details.get_reserve_history.index_reserve;
    1428           0 :           data = &state->cmd[reserve_index].exposed;
    1429           0 :           qs = state->plugin->get_reserve_history (state->plugin->cls,
    1430             :                                                    state->session,
    1431           0 :                                                    &data->data.reserve->reserve.pub,
    1432             :                                                    &history);
    1433           0 :           GNUNET_assert (0 >= qs);
    1434           0 :           GNUNET_assert (NULL != history);
    1435           0 :           state->plugin->free_reserve_history (state->plugin->cls,
    1436             :                                                history);
    1437             :         }
    1438           0 :         break;
    1439             : 
    1440             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_DENOMINATION:
    1441             :         {
    1442           2 :           struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki =
    1443             :             PERF_TALER_EXCHANGEDB_denomination_init ();
    1444           2 :           GNUNET_assert (NULL != dki);
    1445           2 :           state->cmd[state->i].exposed.data.dki = dki;
    1446             :         }
    1447           2 :         break;
    1448             : 
    1449             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_DENOMINATION:
    1450             :         {
    1451             :           unsigned int denom_index;
    1452             :           enum GNUNET_DB_QueryStatus ret;
    1453             :           struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *dki ;
    1454             : 
    1455           2 :           denom_index = state->cmd[state->i].details.insert_denomination.index_denom;
    1456           2 :           dki = state->cmd[denom_index].exposed.data.dki;
    1457           4 :           ret = state->plugin->insert_denomination_info (state->plugin->cls,
    1458             :                                                          state->session,
    1459           2 :                                                          &dki->denom_pub,
    1460           2 :                                                          &dki->issue);
    1461           2 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == ret);
    1462             :         }
    1463           2 :         break;
    1464             : 
    1465             :       case PERF_TALER_EXCHANGEDB_CMD_GET_DENOMINATION:
    1466             :         {
    1467             :           unsigned int denom_index;
    1468             :           enum GNUNET_DB_QueryStatus qs;
    1469             :           struct PERF_TALER_EXCHANGEDB_Data *data;
    1470             : 
    1471           0 :           denom_index = state->cmd[state->i].details.get_denomination.index_denom;
    1472           0 :           data = &state->cmd[denom_index].exposed;
    1473           0 :           qs = state->plugin->get_denomination_info (state->plugin->cls,
    1474             :                                                      state->session,
    1475           0 :                                                      &data->data.dki->denom_pub,
    1476           0 :                                                      &data->data.dki->issue);
    1477           0 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
    1478             :         }
    1479           0 :         break;
    1480             : 
    1481             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_WITHDRAW:
    1482             :         {
    1483             :           unsigned int dki_index;
    1484             :           unsigned int reserve_index;
    1485             :           struct PERF_TALER_EXCHANGEDB_Coin *coin;
    1486             : 
    1487           1 :           dki_index     = state->cmd[state->i].details.create_withdraw.index_dki;
    1488           1 :           reserve_index = state->cmd[state->i].details.create_withdraw.index_reserve;
    1489           1 :           coin = PERF_TALER_EXCHANGEDB_coin_init (state->cmd[dki_index].exposed.data.dki,
    1490           1 :                                                   state->cmd[reserve_index].exposed.data.reserve);
    1491           1 :           GNUNET_assert (NULL != coin);
    1492           1 :           state->cmd[state->i].exposed.data.coin = coin;
    1493             :         }
    1494           1 :         break;
    1495             : 
    1496             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_WITHDRAW:
    1497             :         {
    1498             :           unsigned int coin_index;
    1499             :           enum GNUNET_DB_QueryStatus qs;
    1500             :           struct PERF_TALER_EXCHANGEDB_Coin *coin;
    1501             : 
    1502           1 :           coin_index = state->cmd[state->i].details.insert_withdraw.index_coin;
    1503           1 :           coin = state->cmd[coin_index].exposed.data.coin;
    1504           2 :           qs = state->plugin->insert_withdraw_info (state->plugin->cls,
    1505             :                                                      state->session,
    1506           1 :                                                      &coin->blind);
    1507           1 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
    1508             :         }
    1509           1 :         break;
    1510             : 
    1511             :       case PERF_TALER_EXCHANGEDB_CMD_GET_WITHDRAW:
    1512             :         {
    1513             :           unsigned int source_index;
    1514             :           enum GNUNET_DB_QueryStatus qs;
    1515             :           struct PERF_TALER_EXCHANGEDB_Data *data;
    1516             : 
    1517           0 :           source_index = state->cmd[state->i].details.get_denomination.index_denom;
    1518           0 :           data = &state->cmd[source_index].exposed;
    1519           0 :           qs = state->plugin->get_withdraw_info (state->plugin->cls,
    1520             :                                                  state->session,
    1521           0 :                                                  &data->data.coin->blind.h_coin_envelope,
    1522           0 :                                                  &data->data.coin->blind);
    1523           0 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
    1524             :         }
    1525           0 :         break;
    1526             : 
    1527             :       case PERF_TALER_EXCHANGEDB_CMD_GET_COIN_TRANSACTION:
    1528             :         {
    1529             :           unsigned int coin_index;
    1530             :           struct PERF_TALER_EXCHANGEDB_Coin *coin;
    1531             :           struct TALER_EXCHANGEDB_TransactionList *transactions;
    1532             :           enum GNUNET_DB_QueryStatus qs;
    1533             : 
    1534           0 :           coin_index = state->cmd[state->i].details.get_coin_transaction.index_coin;
    1535           0 :           coin = state->cmd[coin_index].exposed.data.coin;
    1536           0 :           qs = state->plugin->get_coin_transactions (state->plugin->cls,
    1537             :                                                      state->session,
    1538           0 :                                                      &coin->public_info.coin_pub,
    1539             :                                                      &transactions);
    1540           0 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
    1541           0 :           GNUNET_assert (transactions != NULL);
    1542           0 :           state->plugin->free_coin_transaction_list (state->plugin->cls,
    1543             :                                                      transactions);
    1544             :         }
    1545           0 :         break;
    1546             : 
    1547             :       case PERF_TALER_EXCHANGEDB_CMD_CREATE_REFRESH_SESSION:
    1548             :         {
    1549             :           struct GNUNET_HashCode *hash;
    1550             :           struct TALER_EXCHANGEDB_RefreshSession *refresh_session;
    1551             : 
    1552           0 :           hash = GNUNET_new (struct GNUNET_HashCode);
    1553           0 :           refresh_session = PERF_TALER_EXCHANGEDB_refresh_session_init ();
    1554           0 :           GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
    1555             :                                             hash);
    1556           0 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
    1557             :                          state->plugin->create_refresh_session (state->session,
    1558             :                                                                 state->session,
    1559             :                                                                 hash,
    1560             :                                                                 refresh_session));
    1561           0 :           state->cmd[state->i].exposed.data.session_hash = hash;
    1562           0 :           PERF_TALER_EXCHANGEDB_refresh_session_free (refresh_session);
    1563           0 :           GNUNET_free (refresh_session);
    1564             :         }
    1565           0 :         break;
    1566             : 
    1567             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_SESSION:
    1568             :         {
    1569             :           unsigned int hash_index;
    1570             :           struct GNUNET_HashCode *hash;
    1571             :           struct TALER_EXCHANGEDB_RefreshSession refresh;
    1572             : 
    1573           0 :           hash_index = state->cmd[state->i].details.get_refresh_session.index_hash;
    1574           0 :           hash = state->cmd[hash_index].exposed.data.session_hash;
    1575           0 :           state->plugin->get_refresh_session (state->session,
    1576             :                                               state->session,
    1577             :                                               hash,
    1578             :                                               &refresh);
    1579             :         }
    1580           0 :         break;
    1581             : 
    1582             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_ORDER:
    1583             :         {
    1584             :           unsigned int hash_index;
    1585             :           unsigned int denom_index;
    1586             :           struct GNUNET_HashCode *session_hash;
    1587             :           struct TALER_EXCHANGEDB_DenominationKeyIssueInformation *denom;
    1588             : 
    1589           0 :           hash_index = state->cmd[state->i].details.insert_refresh_order.index_hash;
    1590           0 :           denom_index = state->cmd[state->i].details.insert_refresh_order.index_denom;
    1591           0 :           session_hash = state->cmd[hash_index].exposed.data.session_hash;
    1592           0 :           denom = state->cmd[denom_index].exposed.data.dki;
    1593           0 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT ==
    1594             :                          state->plugin->insert_refresh_order (state->plugin->cls,
    1595             :                                                               state->session,
    1596             :                                                               session_hash,
    1597             :                                                               1,
    1598             :                                                               &denom->denom_pub));
    1599             : 
    1600             :         }
    1601           0 :         break;
    1602             : 
    1603             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_ORDER:
    1604             :         {
    1605             :           int hash_index;
    1606             :           struct GNUNET_HashCode *hash;
    1607             :           struct TALER_DenominationPublicKey denom_pub;
    1608             : 
    1609           0 :           hash_index = state->cmd[state->i].details.get_refresh_order.index_hash;
    1610           0 :           hash = state->cmd[hash_index].exposed.data.session_hash;
    1611           0 :           state->plugin->get_refresh_order (state->plugin->cls,
    1612             :                                             state->session,
    1613             :                                             hash,
    1614             :                                             1,
    1615             :                                             &denom_pub);
    1616             :         }
    1617           0 :         break;
    1618             : 
    1619             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_COIN:
    1620             :         {
    1621             :           enum GNUNET_DB_QueryStatus qs;
    1622             :           unsigned int hash_index;
    1623             :           struct TALER_EXCHANGEDB_RefreshCommitCoin *refresh_commit;
    1624             : 
    1625           0 :           hash_index = state->cmd[state->i].details.insert_refresh_commit_coin.index_hash;
    1626           0 :           refresh_commit = PERF_TALER_EXCHANGEDB_refresh_commit_coin_init ();
    1627           0 :           qs = state->plugin->insert_refresh_commit_coins (state->plugin->cls,
    1628             :                                                            state->session,
    1629           0 :                                                            state->cmd[hash_index].exposed.data.session_hash,
    1630             :                                                            1,
    1631             :                                                            refresh_commit);
    1632           0 :           GNUNET_assert (GNUNET_DB_STATUS_SUCCESS_ONE_RESULT == qs);
    1633             :         }
    1634           0 :         break;
    1635             : 
    1636             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_COIN:
    1637             :         {
    1638             :           unsigned int hash_index;
    1639             :           struct TALER_EXCHANGEDB_RefreshCommitCoin refresh_commit;
    1640             : 
    1641           0 :           hash_index = state->cmd[state->i].details.insert_refresh_commit_coin.index_hash;
    1642           0 :           state->plugin->get_refresh_commit_coins (state->plugin->cls,
    1643             :                                                    state->session,
    1644           0 :                                                    state->cmd[hash_index].exposed.data.session_hash,
    1645             :                                                    1,
    1646             :                                                    &refresh_commit);
    1647             : 
    1648             :         }
    1649           0 :         break;
    1650             : 
    1651             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_COMMIT_LINK:
    1652             :         {
    1653             : //          unsigned int hash_index;
    1654             : //
    1655             : //          hash_index = state->cmd[state->i].details.insert_refresh_commit_link.index_hash;
    1656             :         }
    1657           0 :         break;
    1658             : 
    1659             :       case PERF_TALER_EXCHANGEDB_CMD_GET_REFRESH_COMMIT_LINK:
    1660             :         {
    1661             :           int ret;
    1662             :           unsigned int hash_index;
    1663             :           struct TALER_EXCHANGEDB_RefreshCommitCoin commit_coin;
    1664             : 
    1665             :           // FIXME: this should go after the public key!
    1666           0 :           hash_index = state->cmd[state->i].details.get_refresh_commit_link.index_hash;
    1667           0 :           ret = state->plugin->get_refresh_commit_coins(state->plugin->cls,
    1668             :                                                         state->session,
    1669           0 :                                                         state->cmd[hash_index].exposed.data.session_hash,
    1670             :                                                         1,
    1671             :                                                         &commit_coin);
    1672           0 :           GNUNET_assert (GNUNET_SYSERR != ret);
    1673             :         }
    1674           0 :         break;
    1675             : 
    1676             :       case PERF_TALER_EXCHANGEDB_CMD_GET_MELT_COMMITMENT:
    1677           0 :         break;
    1678             : 
    1679             :       case PERF_TALER_EXCHANGEDB_CMD_INSERT_REFRESH_OUT:
    1680           0 :         break;
    1681             : 
    1682             :       case PERF_TALER_EXCHANGEDB_CMD_GET_LINK_DATA_LIST:
    1683           0 :         break;
    1684             : 
    1685             :       case PERF_TALER_EXCHANGEDB_CMD_GET_TRANSFER:
    1686           0 :         break;
    1687             : 
    1688             :     }
    1689             :   }
    1690           2 :   return GNUNET_OK;
    1691             : }
    1692             : 
    1693             : 
    1694             : /**
    1695             :  * Runs the commands given in @a cmd, working with
    1696             :  * the database referenced by @a db_plugin
    1697             :  *
    1698             :  * @param db_plugin the connection to the database
    1699             :  * @param cmd the commands to run
    1700             :  */
    1701             : int
    1702           2 : PERF_TALER_EXCHANGEDB_interpret (struct TALER_EXCHANGEDB_Plugin *db_plugin,
    1703             :                                  struct PERF_TALER_EXCHANGEDB_Cmd cmd[])
    1704             : {
    1705             :   int ret;
    1706           2 :   struct PERF_TALER_EXCHANGEDB_interpreter_state state =
    1707             :   {.i = 0, .cmd = cmd, .plugin = db_plugin};
    1708             : 
    1709           2 :   ret = cmd_init (cmd);
    1710           2 :   if (GNUNET_SYSERR == ret)
    1711           0 :     return ret;
    1712           2 :   state.session = db_plugin->get_session (db_plugin->cls);
    1713           2 :   if (NULL == state.session)
    1714           0 :     return GNUNET_SYSERR;
    1715           2 :   GNUNET_assert (NULL != state.session);
    1716           2 :   ret = interpret (&state);
    1717           2 :   cmd_clean (cmd);
    1718           2 :   return ret;
    1719             : }
    1720             : 
    1721             : 
    1722             : /**
    1723             :  * Initialize the database and run the benchmark
    1724             :  *
    1725             :  * @param benchmark_name the name of the benchmark, displayed in the logs
    1726             :  * @param configuration_file path to the taler configuration file to use
    1727             :  * @param init the commands to use for the database initialisation,
    1728             :  * if #NULL the standard initialization is used
    1729             :  * @param benchmark the commands for the benchmark
    1730             :  * @return #GNUNET_OK upon success; #GNUNET_SYSERR upon failure, #GNUNET_NO
    1731             :  *        if we failed to init the database
    1732             :  */
    1733             : int
    1734           1 : PERF_TALER_EXCHANGEDB_run_benchmark (const char *benchmark_name,
    1735             :                                      const char *configuration_file,
    1736             :                                      struct PERF_TALER_EXCHANGEDB_Cmd *init,
    1737             :                                      struct PERF_TALER_EXCHANGEDB_Cmd *benchmark)
    1738             : {
    1739             :   struct TALER_EXCHANGEDB_Plugin *plugin;
    1740             :   struct GNUNET_CONFIGURATION_Handle *config;
    1741           1 :   int ret = 0;
    1742           1 :   struct PERF_TALER_EXCHANGEDB_Cmd init_def[] =
    1743             :   {
    1744             :     // Denomination used to create coins
    1745             :     PERF_TALER_EXCHANGEDB_INIT_CMD_DEBUG ("00 - Start of interpreter"),
    1746             : 
    1747             :     PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("01 - denomination loop",
    1748             :                                      PERF_TALER_EXCHANGEDB_NB_DENOMINATION_INIT),
    1749             :     PERF_TALER_EXCHANGEDB_INIT_CMD_START_TRANSACTION (""),
    1750             :     PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_DENOMINATION ("01 - denomination"),
    1751             :     PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_DENOMINATION ("01 - insert",
    1752             :                                                     "01 - denomination"),
    1753             :     PERF_TALER_EXCHANGEDB_INIT_CMD_COMMIT_TRANSACTION (""),
    1754             :     PERF_TALER_EXCHANGEDB_INIT_CMD_SAVE_ARRAY ("01 - save denomination",
    1755             :                                            "01 - denomination loop",
    1756             :                                            "01 - denomination",
    1757             :                                            PERF_TALER_EXCHANGEDB_NB_DENOMINATION_SAVE),
    1758             :     PERF_TALER_EXCHANGEDB_INIT_CMD_END_LOOP ("",
    1759             :                                          "01 - denomination loop"),
    1760             :     PERF_TALER_EXCHANGEDB_INIT_CMD_DEBUG ("01 - init denomination complete"),
    1761             :     // End of initialization
    1762             :     // Reserve initialization
    1763             :     PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("02 - init reserve loop",
    1764             :                                      PERF_TALER_EXCHANGEDB_NB_RESERVE_INIT),
    1765             :     PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_RESERVE ("02 - reserve"),
    1766             :     PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_RESERVE ("02 - insert",
    1767             :                                                "02 - reserve"),
    1768             :     PERF_TALER_EXCHANGEDB_INIT_CMD_SAVE_ARRAY ("02 - save reserve",
    1769             :                                            "02 - init reserve loop",
    1770             :                                            "02 - reserve",
    1771             :                                            PERF_TALER_EXCHANGEDB_NB_RESERVE_SAVE),
    1772             :     PERF_TALER_EXCHANGEDB_INIT_CMD_END_LOOP ("",
    1773             :                                          "02 - init reserve loop"),
    1774             :     PERF_TALER_EXCHANGEDB_INIT_CMD_DEBUG ("02 - reserve init complete"),
    1775             :     // End reserve init
    1776             :     // Withdrawal initialization
    1777             :     PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("03 - init withdraw loop",
    1778             :                                      PERF_TALER_EXCHANGEDB_NB_WITHDRAW_INIT),
    1779             :     PERF_TALER_EXCHANGEDB_INIT_CMD_START_TRANSACTION (""),
    1780             :     PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("03 - denomination load",
    1781             :                                            "03 - init withdraw loop",
    1782             :                                            "01 - save denomination"),
    1783             :     PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("03 - reserve load",
    1784             :                                            "03 - init withdraw loop",
    1785             :                                            "02 - save reserve"),
    1786             :     PERF_TALER_EXCHANGEDB_INIT_CMD_CREATE_WITHDRAW ("03 - withdraw",
    1787             :                                                 "03 - denomination load",
    1788             :                                                 "03 - reserve load"),
    1789             :     PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_WITHDRAW ("03 - insert",
    1790             :                                                 "03 - withdraw"),
    1791             :     PERF_TALER_EXCHANGEDB_INIT_CMD_COMMIT_TRANSACTION (""),
    1792             :     PERF_TALER_EXCHANGEDB_INIT_CMD_SAVE_ARRAY ("03 - save coin",
    1793             :                                            "03 - init withdraw loop",
    1794             :                                            "03 - withdraw",
    1795             :                                            PERF_TALER_EXCHANGEDB_NB_WITHDRAW_SAVE),
    1796             :     PERF_TALER_EXCHANGEDB_INIT_CMD_END_LOOP ("",
    1797             :                                          "03 - init withdraw loop"),
    1798             :     PERF_TALER_EXCHANGEDB_INIT_CMD_DEBUG ("03 - withdraw init complete"),
    1799             :     //End of withdrawal initialization
    1800             :     //Deposit initialization
    1801             :     PERF_TALER_EXCHANGEDB_INIT_CMD_LOOP ("04 - deposit init loop",
    1802             :                                      PERF_TALER_EXCHANGEDB_NB_DEPOSIT_INIT),
    1803             :     PERF_TALER_EXCHANGEDB_INIT_CMD_START_TRANSACTION ("04 - start transaction"),
    1804             :     PERF_TALER_EXCHANGEDB_INIT_CMD_LOAD_ARRAY ("04 - denomination load",
    1805             :                                            "04 - deposit init loop",
    1806             :                                            "03 - save coin"),
    1807             :     PERF_TALER_EXCHANGEDB_INIT_CMD_INSERT_DEPOSIT ("04 - deposit",
    1808             :                                                "04 - denomination load"),
    1809             :     PERF_TALER_EXCHANGEDB_INIT_CMD_COMMIT_TRANSACTION ("04 - commit transaction"),
    1810             :     PERF_TALER_EXCHANGEDB_INIT_CMD_SAVE_ARRAY ("04 - deposit array",
    1811             :                                            "04 - deposit init loop",
    1812             :                                            "04 - deposit",
    1813             :                                            PERF_TALER_EXCHANGEDB_NB_DEPOSIT_SAVE),
    1814             :     PERF_TALER_EXCHANGEDB_INIT_CMD_END_LOOP ("04 - deposit init loop end",
    1815             :                                          "04 - deposit init loop"),
    1816             :     PERF_TALER_EXCHANGEDB_INIT_CMD_DEBUG ("04 - deposit init complete"),
    1817             :     // End of deposit initialization
    1818             :     PERF_TALER_EXCHANGEDB_INIT_CMD_END ("end")
    1819             :   };
    1820             : 
    1821           1 :   GNUNET_log_setup (benchmark_name,
    1822             :                     "INFO",
    1823             :                     NULL);
    1824           1 :   config = GNUNET_CONFIGURATION_create ();
    1825           1 :   ret = GNUNET_CONFIGURATION_parse (config,
    1826             :                                     configuration_file);
    1827           1 :   if (GNUNET_OK != ret)
    1828             :   {
    1829           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1830             :                 "Error parsing configuration file\n");
    1831           0 :     return GNUNET_SYSERR;
    1832             :   }
    1833           1 :   plugin = TALER_EXCHANGEDB_plugin_load (config);
    1834           1 :   if (NULL == plugin)
    1835             :   {
    1836           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1837             :                 "Error connectiong to the database\n");
    1838           0 :     return GNUNET_NO;
    1839             :   }
    1840           1 :   ret = plugin->create_tables (plugin->cls);
    1841           1 :   if (GNUNET_OK != ret)
    1842             :   {
    1843           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1844             :                 "Error while creating the database architecture\n");
    1845           0 :     return GNUNET_NO;
    1846             :   }
    1847             :   /*
    1848             :    * Running the initialization
    1849             :    */
    1850           1 :   if (NULL == init)
    1851             :   {
    1852           0 :     init = init_def;
    1853             :   }
    1854           1 :   ret = PERF_TALER_EXCHANGEDB_interpret (plugin,
    1855             :                                          init);
    1856           1 :   if (GNUNET_OK != ret)
    1857             :   {
    1858           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1859             :                 "Error during database initialization\n");
    1860           0 :     return ret;
    1861             :   }
    1862             :   /*
    1863             :    * Running the benchmark
    1864             :    */
    1865           1 :   ret = PERF_TALER_EXCHANGEDB_interpret (plugin,
    1866             :                                      benchmark);
    1867           1 :   if (GNUNET_OK != ret)
    1868             :   {
    1869           0 :     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1870             :                 "Error while runing the benchmark\n");
    1871           0 :     return ret;
    1872             :   }
    1873             :   /* Drop tables */
    1874             :   {
    1875           1 :     ret = plugin->drop_tables (plugin->cls);
    1876           1 :     if (GNUNET_OK != ret)
    1877             :     {
    1878           0 :       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
    1879             :                   "Error cleaning the database\n");
    1880           0 :       return ret;
    1881             :     }
    1882             :   }
    1883           1 :   TALER_EXCHANGEDB_plugin_unload (plugin);
    1884           1 :   GNUNET_CONFIGURATION_destroy (config);
    1885           1 :   return ret;
    1886             : }

Generated by: LCOV version 1.13