1 /* sh-exectool.h - Utility functions to execute a helper tool 2 * Copyright (C) 2015 g10 Code GmbH 3 * 4 * This file is part of GnuPG. 5 * 6 * This file is free software; you can redistribute it and/or modify 7 * it under the terms of either 8 * 9 * - the GNU Lesser General Public License as published by the Free 10 * Software Foundation; either version 3 of the License, or (at 11 * your option) any later version. 12 * 13 * or 14 * 15 * - the GNU General Public License as published by the Free 16 * Software Foundation; either version 2 of the License, or (at 17 * your option) any later version. 18 * 19 * or both in parallel, as here. 20 * 21 * This file is distributed in the hope that it will be useful, 22 * but WITHOUT ANY WARRANTY; without even the implied warranty of 23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 24 * GNU General Public License for more details. 25 * 26 * You should have received a copy of the GNU General Public License 27 * along with this program; if not, see <https://www.gnu.org/licenses/>. 28 */ 29 30 #ifndef GNUPG_COMMON_EXECTOOL_H 31 #define GNUPG_COMMON_EXECTOOL_H 32 33 #include <gpg-error.h> 34 35 /* This callback can be used to process --status-fd outputs of GnuPG 36 * tools. OPAQUE can be used to communicate between the caller of the 37 * function and the callback. KEYWORD is the status keyword (see 38 * doc/DETAILS); it is never NULL. ARGS are the arguments of the 39 * status line and will also never be NULL; the caller may modify this 40 * string. */ 41 typedef void (*exec_tool_status_cb_t) (void *opaque, 42 const char *keyword, 43 char *args); 44 45 46 /* Run the program PGMNAME with the command line arguments given in 47 the NULL terminates array ARGV. If INPUT_STRING is not NULL it 48 will be fed to stdin of the process. stderr is logged using 49 log_info and the process's stdout is returned in a newly malloced 50 buffer RESULT with the length stored at RESULTLEN if not given as 51 NULL. A hidden Nul is appended to the output. On error NULL is 52 stored at RESULT, a diagnostic is printed, and an error code 53 returned. */ 54 gpg_error_t gnupg_exec_tool (const char *pgmname, const char *argv[], 55 const char *input_string, 56 char **result, size_t *resultlen); 57 58 /* Run the program PGMNAME with the command line arguments given in 59 the NULL terminates array ARGV. If INPUT is not NULL it will be 60 fed to stdin of the process. stderr is logged using log_info and 61 the process's stdout is written to OUTPUT. On error a diagnostic is 62 printed, and an error code returned. INEXTRA is reserved. */ 63 gpg_error_t gnupg_exec_tool_stream (const char *pgmname, const char *argv[], 64 estream_t input, estream_t inextra, 65 estream_t output, 66 exec_tool_status_cb_t status_cb, 67 void *status_cb_value); 68 69 #endif /* GNUPG_COMMON_EXECTOOL_H */ 70