exchange

Base system with REST service to issue digital coins, run by the payment service provider
Log | Files | Refs | Submodules | README | LICENSE

testing_api_cmd_exec_auditor-offline.c (4664B)


      1 /*
      2   This file is part of TALER
      3   Copyright (C) 2018 Taler Systems SA
      4 
      5   TALER is free software; you can redistribute it and/or modify it
      6   under the terms of the GNU General Public License as published
      7   by the Free Software Foundation; either version 3, or (at your
      8   option) any later version.
      9 
     10   TALER is distributed in the hope that it will be useful, but
     11   WITHOUT ANY WARRANTY; without even the implied warranty of
     12   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     13   GNU General Public License for more details.
     14 
     15   You should have received a copy of the GNU General Public
     16   License along with TALER; see the file COPYING.  If not,
     17   see <http://www.gnu.org/licenses/>
     18 */
     19 /**
     20  * @file testing/testing_api_cmd_exec_auditor-offline.c
     21  * @brief run the taler-exchange-auditor-offline command
     22  * @author Marcello Stanisci
     23  */
     24 #include "taler/platform.h"
     25 #include "taler/taler_json_lib.h"
     26 #include <gnunet/gnunet_curl_lib.h>
     27 #include "taler/taler_signatures.h"
     28 #include "taler/taler_testing_lib.h"
     29 
     30 
     31 /**
     32  * State for a "auditor-offline" CMD.
     33  */
     34 struct AuditorOfflineState
     35 {
     36 
     37   /**
     38    * AuditorOffline process.
     39    */
     40   struct GNUNET_Process *auditor_offline_proc;
     41 
     42   /**
     43    * Configuration file used by the auditor-offline.
     44    */
     45   const char *config_filename;
     46 
     47 };
     48 
     49 
     50 /**
     51  * Run the command.  Use the `taler-exchange-auditor-offline` program.
     52  *
     53  * @param cls closure.
     54  * @param cmd command being run.
     55  * @param is interpreter state.
     56  */
     57 static void
     58 auditor_offline_run (void *cls,
     59                      const struct TALER_TESTING_Command *cmd,
     60                      struct TALER_TESTING_Interpreter *is)
     61 {
     62   struct AuditorOfflineState *as = cls;
     63 
     64   (void) cmd;
     65   as->auditor_offline_proc = GNUNET_process_create (GNUNET_OS_INHERIT_STD_ERR);
     66   if (GNUNET_OK !=
     67       GNUNET_process_run_command_va (as->auditor_offline_proc,
     68                                      "taler-auditor-offline",
     69                                      "taler-auditor-offline",
     70                                      "-c", as->config_filename,
     71                                      "-L", "INFO",
     72                                      "download",
     73                                      "sign",
     74                                      "upload",
     75                                      NULL))
     76   {
     77     GNUNET_break (0);
     78     GNUNET_process_destroy (as->auditor_offline_proc);
     79     as->auditor_offline_proc = NULL;
     80     TALER_TESTING_interpreter_fail (is);
     81     return;
     82   }
     83   TALER_TESTING_wait_for_sigchld (is);
     84 }
     85 
     86 
     87 /**
     88  * Free the state of a "auditor-offline" CMD, and possibly kill its
     89  * process if it did not terminate correctly.
     90  *
     91  * @param cls closure.
     92  * @param cmd the command being freed.
     93  */
     94 static void
     95 auditor_offline_cleanup (void *cls,
     96                          const struct TALER_TESTING_Command *cmd)
     97 {
     98   struct AuditorOfflineState *as = cls;
     99 
    100   (void) cmd;
    101   if (NULL != as->auditor_offline_proc)
    102   {
    103     GNUNET_break (GNUNET_OK ==
    104                   GNUNET_process_kill (as->auditor_offline_proc,
    105                                        SIGKILL));
    106     GNUNET_process_wait (as->auditor_offline_proc,
    107                          true,
    108                          NULL,
    109                          NULL);
    110     GNUNET_process_destroy (as->auditor_offline_proc);
    111     as->auditor_offline_proc = NULL;
    112   }
    113   GNUNET_free (as);
    114 }
    115 
    116 
    117 /**
    118  * Offer "auditor-offline" CMD internal data to other commands.
    119  *
    120  * @param cls closure.
    121  * @param[out] ret result.
    122  * @param trait name of the trait.
    123  * @param index index number of the object to offer.
    124  * @return #GNUNET_OK on success
    125  */
    126 static enum GNUNET_GenericReturnValue
    127 auditor_offline_traits (void *cls,
    128                         const void **ret,
    129                         const char *trait,
    130                         unsigned int index)
    131 {
    132   struct AuditorOfflineState *as = cls;
    133   struct TALER_TESTING_Trait traits[] = {
    134     TALER_TESTING_make_trait_process (&as->auditor_offline_proc),
    135     TALER_TESTING_trait_end ()
    136   };
    137 
    138   return TALER_TESTING_get_trait (traits,
    139                                   ret,
    140                                   trait,
    141                                   index);
    142 }
    143 
    144 
    145 struct TALER_TESTING_Command
    146 TALER_TESTING_cmd_exec_auditor_offline (const char *label,
    147                                         const char *config_filename)
    148 {
    149   struct AuditorOfflineState *as;
    150 
    151   as = GNUNET_new (struct AuditorOfflineState);
    152   as->config_filename = config_filename;
    153   {
    154     struct TALER_TESTING_Command cmd = {
    155       .cls = as,
    156       .label = label,
    157       .run = &auditor_offline_run,
    158       .cleanup = &auditor_offline_cleanup,
    159       .traits = &auditor_offline_traits
    160     };
    161 
    162     return cmd;
    163   }
    164 }
    165 
    166 
    167 /* end of testing_api_cmd_exec_auditor-offline.c */