2 ctrlproxy: A modular IRC proxy
3 (c) 2007 Jelmer Vernooij <jelmer@nl.linux.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 3 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 #include "internals.h"
24 char *irc_create_url(const char *server, const char *port, gboolean ssl)
26 if (ssl && (!strcmp("ircs", port) || !strcmp("994", port)))
27 return g_strdup_printf("ircs://%s", server);
28 if (!ssl && (!strcmp("ircd", port) || !strcmp("6667", port)))
29 return g_strdup_printf("irc://%s", server);
30 return g_strdup_printf("%s://%s:%s", (ssl?"ircs":"irc"), server, port);
33 gboolean irc_parse_url(const char *url, char **server, char **port, gboolean *ssl)
37 if (!strncmp(url, "irc://", strlen("irc://"))) {
39 url += strlen("irc://");
40 } else if (!strncmp(url, "ircs://", strlen("ircs://"))) {
42 url += strlen("ircs://");
43 } else if (strstr(url, "://")) {
54 if (p != NULL && (q == NULL || p < q)) {
55 *port = g_strdup(p+1);
56 *server = g_strndup(url, p-url);
61 *port = g_strdup(IRCS_PORT);
63 *port = g_strdup(IRC_PORT);
67 *server = g_strndup(url, q - url);
69 *server = g_strdup(url);