Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
parsing.h File Reference
#include <stdbool.h>
#include <stdlib.h>
Include dependency graph for parsing.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Macros

#define READ_STR_PROMPT_BASE   "Enter %s: "
 
#define YH_INTERNAL   __attribute__((visibility("hidden")))
 

Functions

bool YH_INTERNAL parse_pw (const char *prompt, char *pw, char *parsed, size_t *parsed_len)
 
bool YH_INTERNAL read_string (const char *name, char *str_buf, size_t str_buf_len, bool hidden)
 

Macro Definition Documentation

◆ READ_STR_PROMPT_BASE

#define READ_STR_PROMPT_BASE   "Enter %s: "

Definition at line 25 of file parsing.h.

◆ YH_INTERNAL

#define YH_INTERNAL   __attribute__((visibility("hidden")))

Definition at line 27 of file parsing.h.

Function Documentation

◆ parse_pw()

bool YH_INTERNAL parse_pw ( const char * prompt,
char * pw,
char * parsed,
size_t * parsed_len )

Definition at line 61 of file parsing.c.

61 {
62 if (strlen(pw) > *parsed_len) {
63 fprintf(stderr, "Unable to read name, buffer too small\n");
64 return false;
65 }
66
67 if (strlen(pw) == 0) {
68 if (read_string(prompt, parsed, *parsed_len, true) == false) {
69 return false;
70 }
71 } else {
72 strncpy(parsed, pw, *parsed_len);
73 }
74
75 *parsed_len = strlen(parsed);
76
77 return true;
78}
bool read_string(const char *name, char *str_buf, size_t str_buf_len, bool hidden)
Definition parsing.c:26
Here is the call graph for this function:

◆ read_string()

bool YH_INTERNAL read_string ( const char * name,
char * str_buf,
size_t str_buf_len,
bool hidden )

Definition at line 26 of file parsing.c.

27 {
28
29 char prompt[sizeof(READ_STR_PROMPT_BASE) + 32] = {0};
30 int ret;
31
32 if (str_buf_len < 1) {
33 fprintf(stderr, "Unable to read %s: buffer too small\n", name);
34 return false;
35 }
36
37 ret = snprintf(prompt, sizeof(prompt), READ_STR_PROMPT_BASE, name);
38 if (ret < 0 || ((unsigned int) ret) > (sizeof(prompt) - 1)) {
39 fprintf(stderr, "Unable to read %s: snprintf failed\n", name);
40 return false;
41 }
42
43 if (hidden == true) {
44 ret = EVP_read_pw_string(str_buf, str_buf_len, prompt, true);
45 if (ret != 0) {
46 fprintf(stderr, "Retrieving %s failed (%d)\n", name, ret);
47 return false;
48 }
49 } else {
50 fprintf(stdout, "%s", prompt);
51 str_buf = fgets(str_buf, str_buf_len, stdin);
52 if (str_buf == NULL) {
53 return false;
54 }
55 str_buf[strlen(str_buf) - 1] = '\0';
56 }
57
58 return true;
59}
std::string name
#define READ_STR_PROMPT_BASE
Definition parsing.c:24
CK_RV ret
Here is the caller graph for this function: