Fixed_it_guys.jpg

This commit is contained in:
Emil 2023-08-02 09:09:34 -06:00
parent 08097249f9
commit 5fe4539dc1
8 changed files with 76 additions and 50 deletions

View File

@ -14,7 +14,7 @@ OBJ.DIR := $(PREFIX)/obj
INC.DIR := include
OBJ := $(addprefix $(OBJ.DIR)/,fetch.o main.o creds_parser.o)
HDR := creds_parser.h
HDR := config.h utils.h creds_parser.h
VPATH := $(INC.DIR) $(SRC.DIR) $(OBJ.DIR)
@ -36,8 +36,8 @@ $(OBJ.DIR)/%.o: $(SRC.DIR)/%.c
$(PREFIX)/$(PROGN): $(VPATH) $(PREFIX) $(HDR) | $(OBJ)
$(CC) $(CFLAGS) $(CPPFLAGS) -o $@ $| $(LDFLAGS)
# include/config.h: include/config.mk.h
# cp -f $< $@
include/config.h: include/config.mk.h
cp -f $< $@
$(VPATH) $(PREFIX):
mkdir -p $@

View File

@ -12,7 +12,7 @@ INC.DIR := include
SRC := fetch.c main.c creds_parser.c
OBJ := fetch.o main.o creds_parser.o
HDR := creds_parser.h
HDR := config.h utils.h creds_parser.h
VPATH := ${INC.DIR}:${SRC.DIR}:${OBJ.DIR}
@ -34,8 +34,8 @@ CPPFLAGS := ${CPPFLAGS} -DPROGN="\"${PROGN}\""
${PROGN}: ${OBJ.DIR} ${HDR} ${OBJ}
${CC} ${CFLAGS} ${CPPFLAGS} -o $@ ${OBJ} ${LDFLAGS}
# include/config.h: include/config.mk.h
# cp -f $< $@
include/config.h: include/config.mk.h
cp -f $< $@
${OBJ.DIR}:
mkdir -p $@

9
include/config.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef CONFIG_H_
#define SERVER "irc.rizon.net"
#define PORT 6667
#define CHANNEL "#/g/chad"
#define USERNAME "probotic"
#define CONFIG_H_
#endif

9
include/config.mk.h Normal file
View File

@ -0,0 +1,9 @@
#ifndef CONFIG_H_
#define SERVER "irc.rizon.net"
#define PORT 6667
#define CHANNEL "#/g/chad"
#define USERNAME "probotic"
#define CONFIG_H_
#endif

View File

@ -1,13 +1,13 @@
#ifndef CREDS_PARSER_H
#define CREDS_PARSER_H
typedef struct
{
char * username;
char * password;
char * password;
} creds_t;
int parse_creds(creds_t * creds, char const * creds_file);
int parse_creds(creds_t * creds, char const * creds_file);
void clean_creds(creds_t * creds);
#endif
#define CREDS_PARSER_H
#endif

10
include/utils.h Normal file
View File

@ -0,0 +1,10 @@
#ifndef UTILS_H_
#include <stdio.h>
#define ERR(ret,msg) do { fputs(msg "\n", stderr); return (ret); } while (0)
#define ERRMSG(msg) fputs(msg "\n", stderr)
#define PERROR(name) perror(name)
#define UTILS_H_
#endif

View File

@ -1,53 +1,55 @@
#include "creds_parser.h"
#include <stdio.h>
#include <stdlib.h>
#include "creds_parser.h"
#include "utils.h"
/* possibly globalize creds so that we can ensure by using
atexit that it is always cleansed? */
int
parse_creds(creds_t * creds,
char const * creds_file)
{
FILE * stream;
size_t nread = 0;
creds->username = NULL;
creds->password = NULL;
FILE * stream;
size_t nread = 0;
stream = fopen(creds_file, "r");
if (stream == NULL)
{
// TODO: Error macro?
return 1;
}
creds->username = NULL;
creds->password = NULL;
if (getline(&(creds->username), &nread, stream) < 1) {
// Cannot get username
// TODO: error macro?
goto fail;
}
stream = fopen(creds_file, "r");
if (stream == NULL)
{ PERROR(PROGN); }
if (getline(&(creds->password), &nread, stream) < 1) {
// Cannot get password
// TODO: error macro?
goto fail;
}
if (getline(&(creds->username), &nread, stream) < 1)
{
ERRMSG("Cannot get username");
goto fail;
}
fclose(stream);
return 0;
if (getline(&(creds->password), &nread, stream) < 1)
{
ERRMSG("Cannot get password");
goto fail;
}
// Releasing everything in cause of a failure
fclose(stream);
return 0;
// Releasing everything in cause of a failure
fail:
fclose(stream);
clean_creds(creds);
return 1;
fclose(stream);
clean_creds(creds);
return 1;
}
void
clean_creds(creds_t * creds)
{
free(creds->username);
creds->username = NULL;
/* Should we memset these? */
free(creds->username);
creds->username = NULL;
free(creds->password);
creds->password = NULL;
}
free(creds->password);
creds->password = NULL;
}

View File

@ -8,12 +8,8 @@
#include <libircclient.h>
#define SERVER "irc.rizon.net"
#define PORT 6667
#define CHANNEL "#/g/chad"
#define USERNAME "probotic"
#define ERR(ret,msg) do { fputs(msg "\n", stderr); return (ret); } while (0)
#include "utils.h"
#include "config.h"
irc_session_t * session;
irc_callbacks_t callbacks;