2023-08-02 10:44:10 -04:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
2023-08-02 11:48:30 -04:00
|
|
|
#include <string.h>
|
2023-08-02 10:44:10 -04:00
|
|
|
|
2023-08-02 11:48:30 -04:00
|
|
|
#include "parse.h"
|
2023-08-02 11:09:34 -04:00
|
|
|
#include "utils.h"
|
|
|
|
|
|
|
|
/* possibly globalize creds so that we can ensure by using
|
|
|
|
atexit that it is always cleansed? */
|
|
|
|
|
2023-08-02 11:48:30 -04:00
|
|
|
/* these are closer described as 'setters', no? */
|
|
|
|
|
|
|
|
int parse_remind(char const * arg)
|
|
|
|
{
|
|
|
|
(void) arg;
|
|
|
|
ERRMSG("not implemented");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int parse_repo(char const * arg)
|
|
|
|
{
|
|
|
|
(void) arg;
|
|
|
|
ERRMSG("not implemented");
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
parse_command(char const * command,
|
|
|
|
const char * arg /* NULLABLE */)
|
|
|
|
{
|
|
|
|
/* I know. */
|
|
|
|
#define COMMAND(cmd,fn) if (strcmp(command,cmd) == 0) { return fn(arg); } else
|
|
|
|
COMMAND("remind", parse_remind)
|
|
|
|
COMMAND("repo", parse_repo)
|
|
|
|
/* COMMAND("raw", sql_execute?) */
|
|
|
|
/* COMMAND("post", parse_post) */
|
|
|
|
/* COMMAND("prune", parse_prune) */
|
|
|
|
/* COMMAND("search", parse_search) */
|
|
|
|
/* COMMAND("list", parse_list) */
|
|
|
|
{ ERR(1,"No such command.\n"); }
|
|
|
|
#undef COMMAND
|
|
|
|
}
|
|
|
|
|
2023-08-02 10:44:10 -04:00
|
|
|
int
|
|
|
|
parse_creds(creds_t * creds,
|
|
|
|
char const * creds_file)
|
|
|
|
{
|
2023-08-02 11:09:34 -04:00
|
|
|
FILE * stream;
|
|
|
|
size_t nread = 0;
|
|
|
|
|
|
|
|
creds->username = NULL;
|
|
|
|
creds->password = NULL;
|
|
|
|
|
|
|
|
stream = fopen(creds_file, "r");
|
|
|
|
if (stream == NULL)
|
|
|
|
{ PERROR(PROGN); }
|
|
|
|
|
|
|
|
if (getline(&(creds->username), &nread, stream) < 1)
|
|
|
|
{
|
|
|
|
ERRMSG("Cannot get username");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getline(&(creds->password), &nread, stream) < 1)
|
|
|
|
{
|
|
|
|
ERRMSG("Cannot get password");
|
|
|
|
goto fail;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(stream);
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
// Releasing everything in cause of a failure
|
2023-08-02 10:44:10 -04:00
|
|
|
fail:
|
2023-08-02 11:09:34 -04:00
|
|
|
fclose(stream);
|
|
|
|
clean_creds(creds);
|
|
|
|
return 1;
|
2023-08-02 10:44:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
clean_creds(creds_t * creds)
|
|
|
|
{
|
2023-08-02 11:09:34 -04:00
|
|
|
/* Should we memset these? */
|
|
|
|
free(creds->username);
|
|
|
|
creds->username = NULL;
|
2023-08-02 10:44:10 -04:00
|
|
|
|
2023-08-02 11:09:34 -04:00
|
|
|
free(creds->password);
|
|
|
|
creds->password = NULL;
|
|
|
|
}
|