no more warnings
This commit is contained in:
commit
a1ac332032
1
credentials.txt
Normal file
1
credentials.txt
Normal file
@ -0,0 +1 @@
|
||||
probotic
|
@ -8,6 +8,7 @@
|
||||
|
||||
#define DB_ERROR 100
|
||||
#define IRC_ERROR 200
|
||||
#define CREDS_ERROR 300
|
||||
|
||||
#define ERROR_H_
|
||||
#endif
|
||||
|
@ -2,6 +2,8 @@
|
||||
|
||||
#include <libircclient.h>
|
||||
|
||||
#include "parse.h"
|
||||
|
||||
extern irc_session_t * session;
|
||||
extern irc_callbacks_t callbacks;
|
||||
|
||||
@ -9,7 +11,7 @@ extern char const * channel;
|
||||
|
||||
extern char * current_username;
|
||||
|
||||
DELC int init(char const * username, char const * server, int port);
|
||||
DELC int init(creds_t const * creds, char const * server, int port);
|
||||
|
||||
#define IRC_H_
|
||||
#endif
|
||||
|
@ -1,16 +1,16 @@
|
||||
#define IRC_COLOR_WHITE "\x0300"
|
||||
#define IRC_COLOR_BLACK "\x0301"
|
||||
#define IRC_COLOR_BLUE "\x0302"
|
||||
#define IRC_COLOR_GREEN "\x0303"
|
||||
#define IRC_COLOR_RED "\x0304"
|
||||
#define IRC_COLOR_BROWN "\x0305"
|
||||
#define IRC_COLOR_PURPLE "\x0306"
|
||||
#define IRC_COLOR_ORANGE "\x0307"
|
||||
#define IRC_COLOR_YELLOW "\x0308"
|
||||
#define IRC_COLOR_LIGHT_GREEN "\x0309"
|
||||
#define IRC_COLOR_TEAL "\x0310"
|
||||
#define IRC_COLOR_LIGHT_CYAN "\x0311"
|
||||
#define IRC_COLOR_LIGHT_BLUE "\x0312"
|
||||
#define IRC_COLOR_PINK "\x0313"
|
||||
#define IRC_COLOR_GREY "\x0314"
|
||||
#define IRC_COLOR_LIGHT_GREY "\x0315"
|
||||
#define IRC_COLOR_WHITE "\x03\x00"
|
||||
#define IRC_COLOR_BLACK "\x03\x01"
|
||||
#define IRC_COLOR_BLUE "\x03\x02"
|
||||
#define IRC_COLOR_GREEN "\x03\x03"
|
||||
#define IRC_COLOR_RED "\x03\x04"
|
||||
#define IRC_COLOR_BROWN "\x03\x05"
|
||||
#define IRC_COLOR_PURPLE "\x03\x06"
|
||||
#define IRC_COLOR_ORANGE "\x03\x07"
|
||||
#define IRC_COLOR_YELLOW "\x03\x08"
|
||||
#define IRC_COLOR_LIGHT_GREEN "\x03\x09"
|
||||
#define IRC_COLOR_TEAL "\x03\x10"
|
||||
#define IRC_COLOR_LIGHT_CYAN "\x03\x11"
|
||||
#define IRC_COLOR_LIGHT_BLUE "\x03\x12"
|
||||
#define IRC_COLOR_PINK "\x03\x13"
|
||||
#define IRC_COLOR_GREY "\x03\x14"
|
||||
#define IRC_COLOR_LIGHT_GREY "\x03\x15"
|
||||
|
@ -113,7 +113,7 @@ event_channel(irc_session_t * session,
|
||||
}
|
||||
|
||||
int
|
||||
init(char const * username, char const * server, int port)
|
||||
init(creds_t const * credentials, char const * server, int port)
|
||||
{
|
||||
if(api_init())
|
||||
{ ERR(DB_ERROR, "Error initializing database."); }
|
||||
@ -123,6 +123,6 @@ init(char const * username, char const * server, int port)
|
||||
session = irc_create_session(&callbacks);
|
||||
if (!session)
|
||||
{ ERR(1, "Error creating IRC session"); }
|
||||
irc_connect(session, server, port, 0, username, username, username);
|
||||
irc_connect(session, server, port, credentials->password, credentials->username, credentials->username, credentials->username);
|
||||
return 0;
|
||||
}
|
||||
|
16
src/main.c
16
src/main.c
@ -25,6 +25,8 @@
|
||||
#include "irc.h"
|
||||
#include "api.h"
|
||||
|
||||
#define CREDS_FILE "./credentials.txt"
|
||||
|
||||
/* args: server port channel [username] - defaults to probotic */
|
||||
|
||||
int
|
||||
@ -33,23 +35,23 @@ main(int argc,
|
||||
{
|
||||
|
||||
/* Usage */
|
||||
if (argc > 5 || argc < 4)
|
||||
{ ERR(1, "server port channel [username]"); }
|
||||
if (argc != 4)
|
||||
{ ERR(1, "server port channel"); }
|
||||
/* Arguments */
|
||||
char const * username = "probotic";
|
||||
creds_t credentials;
|
||||
char const * server = argv[1];
|
||||
int const port = atoi(argv[2]);
|
||||
channel = argv[3];
|
||||
|
||||
if (argc > 4)
|
||||
{ username = argv[4]; }
|
||||
if (parse_creds(&credentials, CREDS_FILE))
|
||||
{ ERR(CREDS_ERROR, "Cannot parse credentials"); }
|
||||
|
||||
#ifdef NDEBUG
|
||||
fprintf(stderr, "-- %s:%d %s %s --\n", server, port, channel, username);
|
||||
fprintf(stderr, "-- %s:%d %s %s %s --\n", server, port, channel, credentials.username, credentials.password ? credentials.password : "NULL");
|
||||
#endif /* NDEBUG */
|
||||
|
||||
/* initialization (1 means bad , 0 mean good > ; ) */
|
||||
if (init(username, server, port))
|
||||
if (init(&credentials, server, port))
|
||||
{ return 1; }
|
||||
atexit(rope);
|
||||
/* We should figure out how the failure happens so we can tell the user that. */
|
||||
|
@ -79,8 +79,13 @@ parse_creds(creds_t * creds,
|
||||
|
||||
if (getline(&(creds->password), &nread, stream) < 1)
|
||||
{
|
||||
ERRMSG("Cannot get password");
|
||||
goto fail;
|
||||
/* Bot credentials file with an empty password is a valid case.
|
||||
* Considering irc_connect api the pointer to the password should be NULL in that case.
|
||||
*/
|
||||
|
||||
/* Theoretically it can be allocated with an empty string */
|
||||
free(creds->password);
|
||||
creds->password = NULL;
|
||||
}
|
||||
|
||||
fclose(stream);
|
||||
|
Reference in New Issue
Block a user