LCOV - code coverage report
Current view: top level - testing - testing_api_cmd_exec_wget.c (source / functions) Hit Total Coverage
Test: coverage.info Lines: 0 27 0.0 %
Date: 2025-06-05 21:03:14 Functions: 0 4 0.0 %

          Line data    Source code
       1             : /*
       2             :   This file is part of TALER
       3             :   Copyright (C) 2023 Taler Systems SA
       4             : 
       5             :   TALER is free software; you can redistribute it and/or modify
       6             :   it under the terms of the GNU General Public License as
       7             :   published by the Free Software Foundation; either version 3,
       8             :   or (at your option) any later version.
       9             : 
      10             :   TALER is distributed in the hope that it will be useful,
      11             :   but 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, see
      17             :   <http://www.gnu.org/licenses/>
      18             : */
      19             : /**
      20             :  * @file testing/testing_api_cmd_exec_wget.c
      21             :  * @brief run a wget command
      22             :  * @author Christian Grothoff
      23             :  */
      24             : #include "platform.h"
      25             : #include "taler_json_lib.h"
      26             : #include <gnunet/gnunet_curl_lib.h>
      27             : #include "taler_signatures.h"
      28             : #include "taler_testing_lib.h"
      29             : 
      30             : 
      31             : /**
      32             :  * State for a "wget" CMD.
      33             :  */
      34             : struct WgetState
      35             : {
      36             :   /**
      37             :    * Process for the wgeter.
      38             :    */
      39             :   struct GNUNET_OS_Process *wget_proc;
      40             : 
      41             :   /**
      42             :    * URL to used by the wget.
      43             :    */
      44             :   const char *url;
      45             : };
      46             : 
      47             : 
      48             : /**
      49             :  * Run the command; use the `wget' program.
      50             :  *
      51             :  * @param cls closure.
      52             :  * @param cmd command currently being executed.
      53             :  * @param is interpreter state.
      54             :  */
      55             : static void
      56           0 : wget_run (void *cls,
      57             :           const struct TALER_TESTING_Command *cmd,
      58             :           struct TALER_TESTING_Interpreter *is)
      59             : {
      60           0 :   struct WgetState *ws = cls;
      61             : 
      62             :   (void) cmd;
      63             :   ws->wget_proc
      64           0 :     = GNUNET_OS_start_process (GNUNET_OS_INHERIT_STD_ALL,
      65             :                                NULL, NULL, NULL,
      66             :                                "wget",
      67             :                                "wget",
      68             :                                ws->url,
      69             :                                NULL);
      70           0 :   if (NULL == ws->wget_proc)
      71             :   {
      72           0 :     GNUNET_break (0);
      73           0 :     TALER_TESTING_interpreter_fail (is);
      74           0 :     return;
      75             :   }
      76           0 :   TALER_TESTING_wait_for_sigchld (is);
      77             : }
      78             : 
      79             : 
      80             : /**
      81             :  * Free the state of a "wget" CMD, and possibly
      82             :  * kills its process if it did not terminate regularly.
      83             :  *
      84             :  * @param cls closure.
      85             :  * @param cmd the command being freed.
      86             :  */
      87             : static void
      88           0 : wget_cleanup (void *cls,
      89             :               const struct TALER_TESTING_Command *cmd)
      90             : {
      91           0 :   struct WgetState *ws = cls;
      92             : 
      93             :   (void) cmd;
      94           0 :   if (NULL != ws->wget_proc)
      95             :   {
      96           0 :     GNUNET_break (0 ==
      97             :                   GNUNET_OS_process_kill (ws->wget_proc,
      98             :                                           SIGKILL));
      99           0 :     GNUNET_OS_process_wait (ws->wget_proc);
     100           0 :     GNUNET_OS_process_destroy (ws->wget_proc);
     101           0 :     ws->wget_proc = NULL;
     102             :   }
     103           0 :   GNUNET_free (ws);
     104           0 : }
     105             : 
     106             : 
     107             : /**
     108             :  * Offer "wget" CMD internal data to other commands.
     109             :  *
     110             :  * @param cls closure.
     111             :  * @param[out] ret result.
     112             :  * @param trait name of the trait.
     113             :  * @param index index number of the object to offer.
     114             :  * @return #GNUNET_OK on success.
     115             :  */
     116             : static enum GNUNET_GenericReturnValue
     117           0 : wget_traits (void *cls,
     118             :              const void **ret,
     119             :              const char *trait,
     120             :              unsigned int index)
     121             : {
     122           0 :   struct WgetState *ws = cls;
     123             :   struct TALER_TESTING_Trait traits[] = {
     124           0 :     TALER_TESTING_make_trait_process (&ws->wget_proc),
     125           0 :     TALER_TESTING_trait_end ()
     126             :   };
     127             : 
     128           0 :   return TALER_TESTING_get_trait (traits,
     129             :                                   ret,
     130             :                                   trait,
     131             :                                   index);
     132             : }
     133             : 
     134             : 
     135             : struct TALER_TESTING_Command
     136           0 : TALER_TESTING_cmd_exec_wget (const char *label,
     137             :                              const char *url)
     138             : {
     139             :   struct WgetState *ws;
     140             : 
     141           0 :   ws = GNUNET_new (struct WgetState);
     142           0 :   ws->url = url;
     143             : 
     144             :   {
     145           0 :     struct TALER_TESTING_Command cmd = {
     146             :       .cls = ws,
     147             :       .label = label,
     148             :       .run = &wget_run,
     149             :       .cleanup = &wget_cleanup,
     150             :       .traits = &wget_traits
     151             :     };
     152             : 
     153           0 :     return cmd;
     154             :   }
     155             : }
     156             : 
     157             : 
     158             : /* end of testing_api_cmd_exec_wget.c */

Generated by: LCOV version 1.16