irctk

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

commit 839210cbb387a66eb3b06143923be6e283ddca0b
parent 9817c66e4ea6f7673c36099e4669e1fc8c6bdf1d
Author: Antoine Amarilli <a3nm@a3nm.net>
Date:   Sat, 16 Jun 2012 19:10:22 +0200

fix cli parsing

Diffstat:
irctk.c | 40++++++++++++++++++----------------------
1 file changed, 18 insertions(+), 22 deletions(-)

diff --git a/irctk.c b/irctk.c @@ -246,7 +246,7 @@ void initialize_args() /* set our nick, and names if not already set */ void set_nick_and_names(struct arguments *arguments) { - strncat(arguments->nick, arguments->raw_dest, MAX_NICK_LEN-1); + strncpy(arguments->nick, arguments->raw_dest, MAX_NICK_LEN-1); if (!arguments->username_set) arguments->username = arguments->raw_dest; if (!arguments->realname_set) @@ -259,8 +259,6 @@ 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)) { @@ -351,36 +349,34 @@ static error_t parse_opt (int key, char *arg, struct argp_state *state) i = -1; arguments->raw_dest = arg; arguments->server = arg; + + int saw_colon = 0; + int saw_at = 0; + // TODO more robust parsing while (arguments->raw_dest[++i]) { - if (arguments->raw_dest[i] == ':' && !saw_pass) { + if (arguments->raw_dest[i] == ':' && !saw_colon) { arguments->raw_dest[i] = 0; - set_nick_and_names(arguments); - arguments->password = arguments->raw_dest + i + 1; - saw_pass = i; + saw_colon = i; } if (arguments->raw_dest[i] == '@') { arguments->raw_dest[i] = 0; - if (!saw_pass) { - // nick wasn't already set - strncat(arguments->nick, arguments->raw_dest, MAX_NICK_LEN-1); - if (!arguments->username_set) - arguments->username = arguments->raw_dest; - if (!arguments->realname_set) - arguments->realname = arguments->raw_dest; - saw_pass = i; + saw_at = i; + arguments->server = arguments->raw_dest + saw_at + 1; + set_nick_and_names(arguments); + if (saw_colon) { + arguments->password = arguments->raw_dest + saw_colon + 1; + saw_colon = 0; } - saw_login = i; - arguments->server = arguments->raw_dest + i + 1; - } - if (arguments->raw_dest[i] == ':' && (!saw_pass || saw_login)) - { - arguments->raw_dest[i] = 0; - arguments->port = atoi(arguments->raw_dest + i + 1); } } + if (saw_colon) { + // we must have a server, so the last thing seen behind an initial + // colon must be the port + arguments->port = atoi(arguments->raw_dest + saw_colon + 1); + } } else { if (arguments->channels == NULL)