diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/common/weechat.c | 4 | ||||
-rw-r--r-- | src/common/weechat.h | 3 | ||||
-rw-r--r-- | src/irc/irc-server.c | 79 |
3 files changed, 62 insertions, 24 deletions
diff --git a/src/common/weechat.c b/src/common/weechat.c index 976dd3edb..39bb39a82 100644 --- a/src/common/weechat.c +++ b/src/common/weechat.c @@ -203,7 +203,7 @@ wee_parse_args (int argc, char *argv[]) else if ((strcmp (argv[i], "-h") == 0) || (strcmp (argv[i], "--help") == 0)) { - printf ("\n" WEE_USAGE1, argv[0]); + printf ("\n" WEE_USAGE1, argv[0], argv[0]); printf ("%s", WEE_USAGE2); exit (EXIT_SUCCESS); } @@ -232,7 +232,7 @@ wee_parse_args (int argc, char *argv[]) server_tmp.address, server_tmp.port, server_tmp.password, server_tmp.nick1, server_tmp.nick2, server_tmp.nick3, - NULL, NULL, NULL, NULL)) + NULL, NULL, NULL, server_tmp.autojoin)) fprintf (stderr, _("%s unable to create server ('%s'), ignored\n"), WEECHAT_WARNING, argv[i]); server_destroy (&server_tmp); diff --git a/src/common/weechat.h b/src/common/weechat.h index 8fcf09efe..51b0cf9e9 100644 --- a/src/common/weechat.h +++ b/src/common/weechat.h @@ -79,7 +79,8 @@ #define WEE_USAGE1 \ PACKAGE_STRING " (c) Copyright 2004, compiled on " __DATE__ " " __TIME__ \ "\nDeveloped by FlashCode, Bounga and Xahlexx - " WEECHAT_WEBSITE "\n\n" \ - "Usage: %s [options ...] [irc://nick[:passwd]@irc.example.org[:port] ...]\n\n" + "Usage: %s [options ...]\n" \ + " or: %s [irc://[nickname[:password]@]irc.example.org[:port][/channel] ...]\n\n" #define WEE_USAGE2 \ " -c, --config config file help (list of options)\n" \ diff --git a/src/irc/irc-server.c b/src/irc/irc-server.c index 289d98ffb..7354adcd2 100644 --- a/src/irc/irc-server.c +++ b/src/irc/irc-server.c @@ -26,9 +26,11 @@ #include <stdlib.h> #include <unistd.h> +#include <errno.h> #include <stdio.h> #include <stdarg.h> #include <string.h> +#include <pwd.h> #include <sys/types.h> #include <sys/socket.h> #include <netinet/in.h> @@ -91,42 +93,77 @@ server_init (t_irc_server *server) int server_init_with_url (char *irc_url, t_irc_server *server) { - char *url, *pos_address, *pos, *pos2; + char *url, *pos_server, *pos_channel, *pos, *pos2; + struct passwd *my_passwd; server_init (server); if (strncasecmp (irc_url, "irc://", 6) != 0) return -1; url = strdup (irc_url); - pos_address = strchr (url, '@'); - if (!pos_address || !pos_address[1]) + pos_server = strchr (url, '@'); + if (pos_server) { - free (url); - return -1; + pos_server[0] = '\0'; + pos_server++; + pos = url + 6; + if (!pos[0]) + { + free (url); + return -1; + } + pos2 = strchr (pos, ':'); + if (pos2) + { + pos2[0] = '\0'; + server->password = strdup (pos2 + 1); + } + server->nick1 = strdup (pos); + } + else + { + if ((my_passwd = getpwuid (geteuid ())) != NULL) + server->nick1 = strdup (my_passwd->pw_name); + else + { + fprintf (stderr, "%s: %s (%s).", + WEECHAT_WARNING, + _("Unable to get user's name"), + strerror (errno)); + free (url); + return -1; + } + pos_server = url + 6; } - pos_address[0] = '\0'; - pos_address++; - pos = url + 6; - if (!pos[0]) + if (!pos_server[0]) { free (url); return -1; } - pos2 = strchr (pos, ':'); - if (pos2) + pos_channel = strchr (pos_server, '/'); + if (pos_channel) { - pos2[0] = '\0'; - server->password = strdup (pos2 + 1); + pos_channel[0] = '\0'; + pos_channel++; } - server->nick1 = strdup (pos); - - pos2 = strchr (pos_address, ':'); - if (pos2) + pos = strchr (pos_server, ':'); + if (pos) { - pos2[0] = '\0'; - server->port = atoi (pos2 + 1); + pos[0] = '\0'; + server->port = atoi (pos + 1); + } + server->name = strdup (pos_server); + server->address = strdup (pos_server); + if (pos_channel && pos_channel[0]) + { + if (string_is_channel (pos_channel)) + server->autojoin = strdup (pos_channel); + else + { + server->autojoin = (char *) malloc (strlen (pos_channel) + 2); + strcpy (server->autojoin, "#"); + strcat (server->autojoin, pos_channel); + } } - server->name = strdup (pos_address); - server->address = strdup (pos_address); free (url); |