summary refs log tree commit diff stats
path: root/src/common/outbound.c
diff options
context:
space:
mode:
authorTingPing <tngpng@gmail.com>2013-03-11 01:13:22 -0700
committerTingPing <tngpng@gmail.com>2013-03-11 01:13:22 -0700
commit9f7af7c4e4fc96e20fafb9b74a78c2bdaba812b9 (patch)
tree6a9bbc8e885d1fca4ceff8a302a0371fd8b6dc1f /src/common/outbound.c
parent84f19881a3c313c5c4ef7045988aacc8a6f9306d (diff)
parentab99bf75179b5d7635c2bf919ab506496348eeae (diff)
Merge pull request #439 from TingPing/urlkey
Add channel key support to urls
Diffstat (limited to 'src/common/outbound.c')
-rw-r--r--src/common/outbound.c32
1 files changed, 24 insertions, 8 deletions
diff --git a/src/common/outbound.c b/src/common/outbound.c
index 0c405343..e073ca1d 100644
--- a/src/common/outbound.c
+++ b/src/common/outbound.c
@@ -3066,7 +3066,7 @@ cmd_splay (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 }
 
 static int
-parse_irc_url (char *url, char *server_name[], char *port[], char *channel[], int *use_ssl)
+parse_irc_url (char *url, char *server_name[], char *port[], char *channel[], char *key[], int *use_ssl)
 {
 	char *co;
 #ifdef USE_OPENSSL
@@ -3104,6 +3104,15 @@ urlserv:
 				*channel = co;
 			
 		}
+		/* check for key - mirc style */
+		co = strchr (co + 1, '?');
+		if (co)
+		{
+			*co = 0;
+			co++;
+			*key = co;
+		}
+			
 		return TRUE;
 	}
 	return FALSE;
@@ -3117,6 +3126,7 @@ cmd_server (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 	char *port = NULL;
 	char *pass = NULL;
 	char *channel = NULL;
+	char *key = NULL;
 	int use_ssl = FALSE;
 	int is_url = TRUE;
 	server *serv = sess->server;
@@ -3130,7 +3140,7 @@ cmd_server (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 	}
 #endif
 
-	if (!parse_irc_url (word[2 + offset], &server_name, &port, &channel, &use_ssl))
+	if (!parse_irc_url (word[2 + offset], &server_name, &port, &channel, &key, &use_ssl))
 	{
 		is_url = FALSE;
 		server_name = word[2 + offset];
@@ -3156,6 +3166,8 @@ cmd_server (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 	{
 		sess->willjoinchannel[0] = '#';
 		safe_strcpy ((sess->willjoinchannel + 1), channel, (CHANLEN - 1));
+		if (key)
+			safe_strcpy (sess->channelkey, key, 64);
 	}
 
 	/* support +7000 style ports like mIRC */
@@ -3356,15 +3368,18 @@ find_server_from_net (void *net)
 }
 
 static void
-url_join_only (server *serv, char *tbuf, char *channel)
+url_join_only (server *serv, char *tbuf, char *channel, char *key)
 {
-	/* already connected, JOIN only. FIXME: support keys? */
+	/* already connected, JOIN only. */
 	if (channel == NULL)
 		return;
 	tbuf[0] = '#';
 	/* tbuf is 4kb */
 	safe_strcpy ((tbuf + 1), channel, 256);
-	serv->p_join (serv, tbuf, "");
+	if (key)
+		serv->p_join (serv, tbuf, key);
+	else
+		serv->p_join (serv, tbuf, "");
 }
 
 static int
@@ -3375,12 +3390,13 @@ cmd_url (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 		char *server_name = NULL;
 		char *port = NULL;
 		char *channel = NULL;
+		char *key = NULL;
 		char *url = g_strdup (word[2]);
 		int use_ssl = FALSE;
 		void *net;
 		server *serv;
 
-		if (parse_irc_url (url, &server_name, &port, &channel, &use_ssl))
+		if (parse_irc_url (url, &server_name, &port, &channel, &key, &use_ssl))
 		{
 			/* maybe we're already connected to this net */
 
@@ -3396,7 +3412,7 @@ cmd_url (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 				serv = find_server_from_net (net);
 				if (serv)
 				{
-					url_join_only (serv, tbuf, channel);
+					url_join_only (serv, tbuf, channel, key);
 					g_free (url);
 					return TRUE;
 				}
@@ -3407,7 +3423,7 @@ cmd_url (struct session *sess, char *tbuf, char *word[], char *word_eol[])
 				serv = find_server_from_hostname (server_name);
 				if (serv)
 				{
-					url_join_only (serv, tbuf, channel);
+					url_join_only (serv, tbuf, channel, key);
 					g_free (url);
 					return TRUE;
 				}