summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog4
-rw-r--r--doc/weechat-curses.19
-rw-r--r--src/plugins/irc/irc-server.c205
3 files changed, 130 insertions, 88 deletions
diff --git a/ChangeLog b/ChangeLog
index 3e0cc2613..a29732ca1 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,7 @@
WeeChat ChangeLog
=================
FlashCode <flashcode@flashtux.org>
-v0.3.3-dev, 2010-06-01
+v0.3.3-dev, 2010-06-02
Version 0.3.3 (under dev!)
@@ -14,6 +14,8 @@ Version 0.3.3 (under dev!)
process)
* api: add function "string_expand_home", fix bug with replacement of home in
paths
+* irc: fix bug with command-line option "irc://" (bug #29990), new format for
+ port and channels
* irc: add command /wallchops, fix bug with display of notice for ops
(task #10021, bug #29932)
* irc: add isupport value in servers (content of IRC message 005), with new
diff --git a/doc/weechat-curses.1 b/doc/weechat-curses.1
index 0fefaddb6..9ca365a5b 100644
--- a/doc/weechat-curses.1
+++ b/doc/weechat-curses.1
@@ -55,10 +55,13 @@ display WeeChat version
Options for plugins depend on plugins, you can look at plugins documentation on WeeChat website for more information.
.TP
For example, with irc plugin, you can connect to temporary server with an url like:
-.B irc[6][s]://[[nickname][:password]@]server[/port][//#channel1[,#channel2...]]
+.B irc[6][s]://[[nickname][:password]@]server[:port][/#channel1[,#channel2...]]
.TP
-To join WeeChat IRC channel support with nick "MyNick":
-irc://MyNick@irc.freenode.net//#weechat
+To join WeeChat IRC channel support with nick "mynick":
+irc://mynick@irc.freenode.net/#weechat
+.TP
+IPv6 address can be enclosed in brackets to add a port after address, for example:
+irc://mynick@[2001:db8:0:85a3::ac1f:8001]:6668/#test
.SH FILES
.TP
diff --git a/src/plugins/irc/irc-server.c b/src/plugins/irc/irc-server.c
index 704aa9eb4..59491deb6 100644
--- a/src/plugins/irc/irc-server.c
+++ b/src/plugins/irc/irc-server.c
@@ -473,9 +473,9 @@ irc_server_alloc (const char *name)
int
irc_server_alloc_with_url (const char *irc_url)
{
- char *irc_url2, *url, *pos_server, *pos_channel, *pos, *pos2;
- char *password, *nick1, *nicks, *autojoin;
- char *server_name;
+ char *irc_url2, *pos_server, *pos_nick, *pos_password;
+ char *pos_address, *pos_port, *pos_channel, *pos;
+ char *server_address, *server_nicks, *server_autojoin;
int ipv6, ssl, length;
struct t_irc_server *ptr_server;
@@ -483,146 +483,183 @@ irc_server_alloc_with_url (const char *irc_url)
if (!irc_url2)
return 0;
+ pos_server = NULL;
+ pos_nick = NULL;
+ pos_password = NULL;
+ pos_address = NULL;
+ pos_port = NULL;
+ pos_channel = NULL;
+
ipv6 = 0;
ssl = 0;
- password = NULL;
- nick1 = NULL;
- autojoin = NULL;
- if (weechat_strncasecmp (irc_url2, "irc6://", 7) == 0)
+ pos_server = strstr (irc_url2, "://");
+ if (!pos_server)
+ {
+ free (irc_url2);
+ return 0;
+ }
+ pos_server[0] = '\0';
+ pos_server += 3;
+
+ pos_channel = strstr (pos_server, "/");
+ if (pos_channel)
+ {
+ pos_channel[0] = '\0';
+ pos_channel++;
+ while (pos_channel[0] == '/')
+ {
+ pos_channel++;
+ }
+ }
+
+ /* check for SSL / IPv6 */
+ if (weechat_strcasecmp (irc_url2, "irc6") == 0)
{
- pos = irc_url2 + 7;
ipv6 = 1;
}
- else if (weechat_strncasecmp (irc_url2, "ircs://", 7) == 0)
+ else if (weechat_strcasecmp (irc_url2, "ircs") == 0)
{
- pos = irc_url2 + 7;
ssl = 1;
}
- else if ((weechat_strncasecmp (irc_url2, "irc6s://", 8) == 0)
- || (weechat_strncasecmp (irc_url2, "ircs6://", 8) == 0))
+ else if ((weechat_strcasecmp (irc_url2, "irc6s") == 0)
+ || (weechat_strcasecmp (irc_url2, "ircs6") == 0))
{
- pos = irc_url2 + 8;
ipv6 = 1;
ssl = 1;
}
- else if (weechat_strncasecmp (irc_url2, "irc://", 6) == 0)
+
+ /* search for nick, password, address+port */
+ pos_address = strchr (pos_server, '@');
+ if (pos_address)
{
- pos = irc_url2 + 6;
+ pos_address[0] = '\0';
+ pos_address++;
+ pos_nick = pos_server;
+ pos_password = strchr (pos_server, ':');
+ if (pos_password)
+ {
+ pos_password[0] = '\0';
+ pos_password++;
+ }
}
else
- {
- free (irc_url2);
- return 0;
- }
+ pos_address = pos_server;
- free (irc_url2);
-
- url = strdup (pos);
- pos_server = strchr (url, '@');
- if (pos_server)
+ /*
+ * search for port in address, and skip optional [ ] around address
+ * (can be used to indicate IPv6 port, after ']')
+ */
+ if (pos_address[0] == '[')
{
- pos_server[0] = '\0';
- pos_server++;
- if (!pos[0])
+ pos_address++;
+ pos = strchr (pos_address, ']');
+ if (!pos)
{
- free (url);
+ free (irc_url2);
return 0;
}
- pos2 = strchr (url, ':');
- if (pos2)
+ pos[0] = '\0';
+ pos++;
+ pos_port = strchr (pos, ':');
+ if (pos_port)
{
- pos2[0] = '\0';
- password = strdup (pos2 + 1);
+ pos_port[0] = '\0';
+ pos_port++;
}
- nick1 = strdup (url);
}
else
- pos_server = url;
-
- if (!pos_server[0])
- {
- free (url);
- return 0;
- }
- pos_channel = strstr (pos_server, "//");
- if (pos_channel)
{
- pos_channel[0] = '\0';
- pos_channel += 2;
- }
- if (pos_channel && pos_channel[0])
- {
- if (irc_channel_is_channel (pos_channel))
- autojoin = strdup (pos_channel);
- else
+ pos_port = strchr (pos_address, ':');
+ if (pos_port)
{
- autojoin = malloc (strlen (pos_channel) + 2);
- strcpy (autojoin, "#");
- strcat (autojoin, pos_channel);
+ pos_port[0] = '\0';
+ pos_port++;
}
}
-
- /* server name ends before first '/' (if found) */
- server_name = irc_server_get_name_without_port (pos_server);
- ptr_server = irc_server_alloc (server_name);
- if (server_name)
- free (server_name);
+ ptr_server = irc_server_alloc (pos_address);
if (ptr_server)
{
ptr_server->temp_server = 1;
- weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES],
- pos_server,
- 1);
+ if (pos_address && pos_address[0])
+ {
+ length = strlen (pos_address) + 1 +
+ ((pos_port) ? strlen (pos_port) : 0) + 1;
+ server_address = malloc (length);
+ if (server_address)
+ {
+ snprintf (server_address, length,
+ "%s%s%s",
+ pos_address,
+ (pos_port && pos_port[0]) ? "/" : "",
+ (pos_port && pos_port[0]) ? pos_port : "");
+ weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_ADDRESSES],
+ server_address,
+ 1);
+ free (server_address);
+ }
+ }
weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_IPV6],
(ipv6) ? "on" : "off",
1);
weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_SSL],
(ssl) ? "on" : "off",
1);
- if (nick1)
+ if (pos_nick && pos_nick[0])
{
- length = ((strlen (nick1) + 2) * 5) + 1;
- nicks = malloc (length);
- if (nicks)
+ length = ((strlen (pos_nick) + 2) * 5) + 1;
+ server_nicks = malloc (length);
+ if (server_nicks)
{
- snprintf (nicks, length,
+ snprintf (server_nicks, length,
"%s,%s1,%s2,%s3,%s4",
- nick1, nick1, nick1, nick1, nick1);
+ pos_nick, pos_nick, pos_nick, pos_nick, pos_nick);
weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_NICKS],
- nicks,
+ server_nicks,
1);
- free (nicks);
+ free (server_nicks);
}
}
- if (password)
+ if (pos_password && pos_password[0])
weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_PASSWORD],
- password,
- 1);
- if (autojoin)
- weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN],
- autojoin,
+ pos_password,
1);
weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOCONNECT],
"on",
1);
+ /* autojoin */
+ if (pos_channel && pos_channel[0])
+ {
+ if (irc_channel_is_channel (pos_channel))
+ server_autojoin = strdup (pos_channel);
+ else
+ {
+ server_autojoin = malloc (strlen (pos_channel) + 2);
+ if (server_autojoin)
+ {
+ strcpy (server_autojoin, "#");
+ strcat (server_autojoin, pos_channel);
+ }
+ }
+ if (server_autojoin)
+ {
+ weechat_config_option_set (ptr_server->options[IRC_SERVER_OPTION_AUTOJOIN],
+ server_autojoin,
+ 1);
+ free (server_autojoin);
+ }
+ }
}
else
{
weechat_printf (NULL,
_("%s%s: error creating new server \"%s\""),
weechat_prefix ("error"), IRC_PLUGIN_NAME,
- pos_server);
+ pos_address);
}
- if (password)
- free (password);
- if (nick1)
- free (nick1);
- if (autojoin)
- free (autojoin);
- free (url);
+ free (irc_url2);
return (ptr_server) ? 1 : 0;
}