summaryrefslogtreecommitdiff
path: root/src/plugins/irc
diff options
context:
space:
mode:
authorSebastien Helleu <flashcode@flashtux.org>2010-06-02 15:17:54 +0200
committerSebastien Helleu <flashcode@flashtux.org>2010-06-02 15:17:54 +0200
commit4a61dc96338ef9af1ca677ff35ed813eebd6794a (patch)
tree95382a844aa7716b344be0428f0e67bcac9dac3c /src/plugins/irc
parente46fc211296922d40bc4de6f637e235d2722320b (diff)
downloadweechat-4a61dc96338ef9af1ca677ff35ed813eebd6794a.zip
Fix bug with command-line option "irc://" (bug #29990), new format for port and channels
Diffstat (limited to 'src/plugins/irc')
-rw-r--r--src/plugins/irc/irc-server.c205
1 files changed, 121 insertions, 84 deletions
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;
}