New free.h
This commit is contained in:
parent
ae3bbf2a91
commit
2b02e93462
@ -17,7 +17,7 @@ See doc/api.md for detailed information about this interface.
|
|||||||
|
|
||||||
First, you'll want specify your server and channel as well as bot username
|
First, you'll want specify your server and channel as well as bot username
|
||||||
and a password. This can be done either with command-line options or in a
|
and a password. This can be done either with command-line options or in a
|
||||||
specified credentials file.
|
specified credentials file. See docs/cli.txt for more information on that.
|
||||||
|
|
||||||
This'll require a few libraries:
|
This'll require a few libraries:
|
||||||
libircclient-dev libsqlite3-dev build-essentials
|
libircclient-dev libsqlite3-dev build-essentials
|
||||||
|
9
docs/cli.txt
Normal file
9
docs/cli.txt
Normal file
@ -0,0 +1,9 @@
|
|||||||
|
-server SERVER - The desired server.
|
||||||
|
-port PORT - Places port number.
|
||||||
|
-username USERNAME - Specifies the username.
|
||||||
|
-password PASSW0RD - Sets a password.
|
||||||
|
-auth FILE - Uses an authorization file.
|
||||||
|
-help - A message likewise.
|
||||||
|
-version - Currently nothing.
|
||||||
|
|
||||||
|
options before are overwritten, and after take precedence.
|
22
include/free.h
Normal file
22
include/free.h
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#ifndef FREE_H_
|
||||||
|
|
||||||
|
#define FREE(obj) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
free(obj); \
|
||||||
|
(obj) = NULL; \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
#define FULL_FREE(obj) \
|
||||||
|
do \
|
||||||
|
{ \
|
||||||
|
if ((obj)) \
|
||||||
|
{ \
|
||||||
|
memset((obj), '\0', strlen((obj))); \
|
||||||
|
FREE((obj)); \
|
||||||
|
} \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
|
#define FREE_H_
|
||||||
|
#endif
|
@ -3,10 +3,10 @@
|
|||||||
|
|
||||||
#include <sqlite3.h>
|
#include <sqlite3.h>
|
||||||
|
|
||||||
#include "stmt.h"
|
|
||||||
#include "irccolors.h"
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
#include "irc.h"
|
#include "irc.h"
|
||||||
|
#include "irccolors.h"
|
||||||
|
#include "stmt.h"
|
||||||
|
|
||||||
#define DBFILE "test.sqlite"
|
#define DBFILE "test.sqlite"
|
||||||
|
|
||||||
|
36
src/main.c
36
src/main.c
@ -21,11 +21,12 @@
|
|||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "error.h"
|
|
||||||
#include "irc.h"
|
|
||||||
#include "api.h"
|
#include "api.h"
|
||||||
|
#include "error.h"
|
||||||
|
#include "free.h"
|
||||||
|
#include "irc.h"
|
||||||
|
|
||||||
#define CREDS_FILE "./creds.txt"
|
#define VERSION_STRING "0.0"
|
||||||
|
|
||||||
#define EQOP(var,val,off) \
|
#define EQOP(var,val,off) \
|
||||||
do \
|
do \
|
||||||
@ -42,20 +43,25 @@
|
|||||||
void
|
void
|
||||||
help(void)
|
help(void)
|
||||||
{
|
{
|
||||||
fprintf(stderr,
|
ERRMSG(PROGN ": usage\n"
|
||||||
PROGN ": usage\n"
|
"-server SERVER - Sets server\n"
|
||||||
"-server SERVER\n"
|
"-port PORT - Sets port\n"
|
||||||
"-port PORT\n"
|
"-username USERNAME - Sets username\n"
|
||||||
"-username USERNAME\n"
|
"-password PASSW0RD - Sets password\n"
|
||||||
"-password PASSW0RD\n"
|
"-auth FILE - Use auth file");
|
||||||
"-auth FILE\n");
|
}
|
||||||
|
|
||||||
|
void
|
||||||
|
version(void)
|
||||||
|
{
|
||||||
|
ERRMSG(PROGN ": " VERSION_STRING);
|
||||||
}
|
}
|
||||||
|
|
||||||
int
|
int
|
||||||
main (int argc,
|
main (int argc,
|
||||||
char ** argv)
|
char ** argv)
|
||||||
{
|
{
|
||||||
char const * authfile = CREDS_FILE;
|
char const * authfile = NULL;
|
||||||
if (argc > 1)
|
if (argc > 1)
|
||||||
{
|
{
|
||||||
char * arg;
|
char * arg;
|
||||||
@ -73,15 +79,15 @@ main (int argc,
|
|||||||
if (argc < 2)
|
if (argc < 2)
|
||||||
{ goto nop; }
|
{ goto nop; }
|
||||||
if (strcmp(arg, "server") == 0)
|
if (strcmp(arg, "server") == 0)
|
||||||
{ creds.server = argv[1]; }
|
{ FREE(creds.server); creds.server = argv[1]; }
|
||||||
else if (strcmp(arg, "port") == 0)
|
else if (strcmp(arg, "port") == 0)
|
||||||
{ creds.port = atoi(argv[1]); }
|
{ creds.port = atoi(argv[1]); }
|
||||||
else if (strcmp(arg, "channel") == 0)
|
else if (strcmp(arg, "channel") == 0)
|
||||||
{ creds.channel = argv[1]; }
|
{ FREE(creds.channel);creds.channel = argv[1]; }
|
||||||
else if (strcmp(arg, "username") == 0)
|
else if (strcmp(arg, "username") == 0)
|
||||||
{ creds.username = argv[1]; }
|
{ FREE(creds.username); creds.username = argv[1]; }
|
||||||
else if (strcmp(arg, "password") == 0)
|
else if (strcmp(arg, "password") == 0)
|
||||||
{ creds.password = argv[1]; }
|
{ FREE(creds.password); creds.password = argv[1]; }
|
||||||
else if (strcmp(arg, "auth") == 0)
|
else if (strcmp(arg, "auth") == 0)
|
||||||
{
|
{
|
||||||
authfile = argv[1];
|
authfile = argv[1];
|
||||||
|
23
src/parse.c
23
src/parse.c
@ -21,9 +21,10 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "parse.h"
|
|
||||||
#include "error.h"
|
#include "error.h"
|
||||||
|
#include "free.h"
|
||||||
#include "help.h"
|
#include "help.h"
|
||||||
|
#include "parse.h"
|
||||||
|
|
||||||
#define PARAMS_COUNT 5
|
#define PARAMS_COUNT 5
|
||||||
|
|
||||||
@ -262,23 +263,6 @@ is_admin(char const * user)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#define FREE(obj) \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
free(obj); \
|
|
||||||
(obj) = NULL; \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
#define FULL_FREE(obj) \
|
|
||||||
do \
|
|
||||||
{ \
|
|
||||||
if ((obj)) \
|
|
||||||
{ \
|
|
||||||
memset((obj), '\0', strlen((obj))); \
|
|
||||||
FREE((obj)); \
|
|
||||||
} \
|
|
||||||
} while (0)
|
|
||||||
|
|
||||||
DECL void
|
DECL void
|
||||||
clean_admin_list()
|
clean_admin_list()
|
||||||
{
|
{
|
||||||
@ -305,6 +289,3 @@ creds_free_rest(void)
|
|||||||
FULL_FREE(creds.channel);
|
FULL_FREE(creds.channel);
|
||||||
FULL_FREE(creds.server);
|
FULL_FREE(creds.server);
|
||||||
}
|
}
|
||||||
|
|
||||||
#undef FREE
|
|
||||||
#undef FULL_FREE
|
|
||||||
|
Reference in New Issue
Block a user