irctk

libircclient binding for scripts
git clone https://a3nm.net/git/irctk/
Log | Files | Refs | README

commit 681c7d1bcd2bae0b953e78027d96a86a2c2a8c8a
parent 8c9ec49aa34c0ece54d08050ebbfd60f040e51af
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Thu, 26 Apr 2012 18:44:10 +0200

start thinking about connection passwords and ssl

Diffstat:
TODO | 2++
irctk.c | 37+++++++++++++++++++++++++++++--------
2 files changed, 31 insertions(+), 8 deletions(-)

diff --git a/TODO b/TODO @@ -4,3 +4,5 @@ handle nick following wait for nick to be free, or fail, or suffix as many as needed ssl support password support +channel password support +exit when killed diff --git a/irctk.c b/irctk.c @@ -58,7 +58,7 @@ static char doc[] = "irctk -- an IRC toolkit"; /* A description of the arguments we accept. */ -static char args_doc[] = "[NICK@]SERVER[:PORT] [CHANNEL]..."; +static char args_doc[] = "[NICK[:PASSWORD]@]SERVER[:PORT] [CHANNEL]..."; #define STANDARD 0 #define MISC 1 @@ -161,6 +161,7 @@ struct arguments char *nick; char *server; int port; + char *password; char **channels; int n_channels; @@ -203,6 +204,7 @@ void initialize_args() { args.nick = "irctk"; args.server = NULL; + args.password = NULL; args.port = 6667; args.channels = (char**) NULL; args.n_channels = 0; @@ -240,6 +242,8 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) { struct arguments *arguments = state->input; int i; + int saw_pass = 0; + int saw_login = 0; if (key != ARGP_KEY_ARG && key != ARGP_KEY_END && (! arguments->channels)) { @@ -323,17 +327,32 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) i = -1; arguments->raw_dest = arg; arguments->server = arg; + // TODO more robust parsing while (arguments->raw_dest[++i]) { - if (arguments->raw_dest[i] == '@') - { + if (arguments->raw_dest[i] == ':' && !saw_pass) { arguments->raw_dest[i] = 0; arguments->nick = arguments->raw_dest; if (!arguments->username_set) arguments->username = arguments->raw_dest; + arguments->password = arguments->raw_dest + i + 1; + saw_pass = i; + } + if (arguments->raw_dest[i] == '@') + { + arguments->raw_dest[i] = 0; + if (saw_pass) { + // nick was already set + } else { + arguments->nick = arguments->raw_dest; + if (!arguments->username_set) + arguments->username = arguments->raw_dest; + saw_pass = i; + } + saw_login = i; arguments->server = arguments->raw_dest + i + 1; } - if (arguments->raw_dest[i] == ':') + if (arguments->raw_dest[i] == ':' && (!saw_pass || saw_login)) { arguments->raw_dest[i] = 0; arguments->port = atoi(arguments->raw_dest + i + 1); @@ -402,8 +421,8 @@ void die(int val, const char *err, ...) void debug_args() { - debug("n_channels = %d\ninterval = %d\nnick = %s\nserver = %s\nport = %d\n", - args.n_channels, args.interval, args.nick, args.server, args.port); + debug("n_channels = %d\ninterval = %d\nnick = %s\nserver = %s\nport = %d\npw = %s\n", + args.n_channels, args.interval, args.nick, args.server, args.port, args.password); } @@ -486,7 +505,6 @@ int cmd_msg_chan(irc_session_t *s, char *target, const char* line) int cont = 1; char tmp; char *one_target; - //char *msg[MAX_LEN]; /* TODO TODO TODO !! */ int rsl; one_target = target; @@ -562,6 +580,8 @@ int cmd_msg(irc_session_t *s, char* target, const char* line) THREAD_FUNCTION(irc_listen) { irc_session_t * sp = (irc_session_t *) arg; + // TODO, also do you need '#' or not? + irc_option_set( sp, LIBIRC_OPTION_SSL_NO_VERIFY ); irc_run(sp); return 0; } @@ -912,7 +932,7 @@ irc_session_t* do_connect() args.server, args.port, args.nick); - if (irc_connect (s, args.server, args.port, 0, args.nick, args.username, args.realname)) + if (irc_connect (s, args.server, args.port, args.password, args.nick, args.username, args.realname)) die(E_CONNECT, "Could not connect: %s\n", irc_strerror (irc_errno(s))); return s; @@ -1038,6 +1058,7 @@ int main (int argc, char **argv) strncpy(args.last_chans_out, first_chan(), MAX_LEN-1); //debug_args(); + return start(INITIAL_RETRY); }