1 #define _XOPEN_SOURCE 700
6 char credentials_pwd_file
[] = "../../test_credentials";
7 char credentials_mep_file
[] = "../../test_credentials_mep";
9 static int read_config(const char *credentials_file
, char **line
, int order
) {
14 if (NULL
== credentials_file
) {
22 file
= fopen(credentials_file
, "r");
24 fprintf(stderr
, "Could not open %s\n", credentials_file
);
28 for (int i
= 0; i
< order
; i
++) {
29 if (-1 == getline(line
, &length
, file
)) {
30 fprintf(stderr
, "Could not read line #%d from %s: ",
31 i
+ 1, credentials_file
);
33 fprintf(stderr
, "error occured\n");
35 fprintf(stderr
, "end of file reached\n");
37 fprintf(stderr
, "I don't know why\n");
47 eol
= strpbrk(*line
, "\r\n");
53 const char *username(void) {
54 static char *username
= NULL
;
56 if (NULL
== username
) {
57 username
= getenv("ISDS_USERNAME");
59 read_config(credentials_pwd_file
, &username
, 1);
64 const char *password(void) {
65 static char *password
= NULL
;
67 if (NULL
== password
) {
68 password
= getenv("ISDS_PASSWORD");
70 read_config(credentials_pwd_file
, &password
, 2);
75 const char *username_mep(void) {
76 static char *username
= NULL
;
78 if (NULL
== username
) {
79 username
= getenv("ISDS_USERNAME");
80 if (NULL
== username
) {
81 read_config(credentials_mep_file
, &username
, 1);
87 const char *code_mep(void) {
88 static char *code
= NULL
;
91 code
= getenv("ISDS_CODE_MEP");
93 read_config(credentials_mep_file
, &code
, 2);