Debian Codegraph @

src/oidc-gen/promptAndSet/_helper.c

raw
1 #include "_helper.h"
2
3 #include "utils/listUtils.h"
4 #include "utils/logger.h"
5 #include "utils/memory.h"
6 #include "utils/prompt.h"
7 #include "utils/string/stringUtils.h"
8
9 char* _gen_prompt(char* label, const char* init, int passPrompt, int optional) {
10 char* input = NULL;
11 promptFnc prompter = prompt;
12 if (passPrompt) {
13 prompter = promptPassword;
14 }
15 do {
16 char* text = oidc_sprintf("Please enter %s:", label);
17 input = prompter(text, label, init, CLI_PROMPT_NOT_VERBOSE);
18 secFree(text);
19 if (strValid(input)) {
20 return input;
21 }
22 secFree(input);
23 if (optional) {
24 return NULL;
25 }
26 } while (1);
27 }
28
29 char* _gen_promptMultipleSpaceSeparated(char* label, const char* init_str,
30 int optional) {
31 list_t* init = delimitedStringToList(init_str, ' ');
32 list_t* input = NULL;
33 do {
34 char* text = oidc_sprintf("Please enter %s:", label);
35 input = promptMultiple(text, label, init, CLI_PROMPT_NOT_VERBOSE);
36 secFree(text);
37 if (listValid(input)) {
38 char* output = listToDelimitedString(input, " ");
39 logger(DEBUG,
40 "In %s produced output '%s' for label '%s' with %lu elements",
41 __func__, output, label, input->len);
42 secFreeList(input);
43 secFreeList(init);
44 return output;
45 }
46 secFreeList(input);
47 if (optional) {
48 secFreeList(init);
49 return NULL;
50 }
51 } while (1);
52 }