summary refs log tree commit diff stats
path: root/src/common
diff options
context:
space:
mode:
authorBerke Viktor <bviktor@hexchat.org>2013-05-11 20:06:22 +0200
committerBerke Viktor <bviktor@hexchat.org>2013-05-11 20:06:22 +0200
commitaf03fa3c7c78ce51017c9e71369e637d91f95208 (patch)
tree7e51e8f069dc5c2e4411069e5f921df1c99fec78 /src/common
parent4d30512e057f8f078e64542941fa1f9b4a24d470 (diff)
Fix connect commands
Diffstat (limited to 'src/common')
-rw-r--r--src/common/inbound.c10
-rw-r--r--src/common/servlist.c88
-rw-r--r--src/common/servlist.h14
3 files changed, 87 insertions, 25 deletions
diff --git a/src/common/inbound.c b/src/common/inbound.c
index 2383955e..4f23403f 100644
--- a/src/common/inbound.c
+++ b/src/common/inbound.c
@@ -1384,6 +1384,8 @@ inbound_nickserv_login (server *serv)
 void
 inbound_login_end (session *sess, char *text)
 {
+	GSList *cmdlist;
+	commandentry *cmd;
 	server *serv = sess->server;
 
 	if (!serv->end_of_motd)
@@ -1398,9 +1400,13 @@ inbound_login_end (session *sess, char *text)
 		if (serv->network)
 		{
 			/* there may be more than 1, separated by \n */
-			if (((ircnet *)serv->network)->command)
+
+			cmdlist = ((ircnet *)serv->network)->commandlist;
+			while (cmdlist)
 			{
-				token_foreach (((ircnet *)serv->network)->command, '\n', inbound_exec_eom_cmd, sess);
+				cmd = cmdlist->data;
+				inbound_exec_eom_cmd (cmd->command, sess);
+				cmdlist = cmdlist->next;
 			}
 
 			/* send nickserv password */
diff --git a/src/common/servlist.c b/src/common/servlist.c
index f30dcf48..ed822925 100644
--- a/src/common/servlist.c
+++ b/src/common/servlist.c
@@ -814,6 +814,29 @@ servlist_server_find (ircnet *net, char *name, int *pos)
 	return NULL;
 }
 
+commandentry *
+servlist_command_find (ircnet *net, char *cmd, int *pos)
+{
+	GSList *list = net->commandlist;
+	commandentry *entry;
+	int i = 0;
+
+	while (list)
+	{
+		entry = list->data;
+		if (strcmp (entry->command, cmd) == 0)
+		{
+			if (pos)
+				*pos = i;
+			return entry;
+		}
+		i++;
+		list = list->next;
+	}
+
+	return NULL;
+}
+
 /* find a network (e.g. (ircnet *) to "FreeNode") from a hostname
    (e.g. "irc.eu.freenode.net") */
 
@@ -881,6 +904,20 @@ servlist_server_add (ircnet *net, char *name)
 	return serv;
 }
 
+commandentry *
+servlist_command_add (ircnet *net, char *cmd)
+{
+	commandentry *entry;
+
+	entry = malloc (sizeof (commandentry));
+	memset (entry, 0, sizeof (commandentry));
+	entry->command = strdup (cmd);
+
+	net->commandlist = g_slist_append (net->commandlist, entry);
+
+	return entry;
+}
+
 void
 servlist_server_remove (ircnet *net, ircserver *serv)
 {
@@ -901,6 +938,14 @@ servlist_server_remove_all (ircnet *net)
 	}
 }
 
+void
+servlist_command_remove (ircnet *net, commandentry *entry)
+{
+	free (entry->command);
+	free (entry);
+	net->commandlist = g_slist_remove (net->commandlist, entry);
+}
+
 static void
 free_and_clear (char *str)
 {
@@ -948,8 +993,8 @@ servlist_net_remove (ircnet *net)
 	free_and_clear (net->pass);
 	if (net->autojoin)
 		free (net->autojoin);
-	if (net->command)
-		free (net->command);
+	if (net->commandlist)
+		g_slist_free_full (net->commandlist, (GDestroyNotify) g_free);
 	if (net->comment)
 		free (net->comment);
 	if (net->encoding)
@@ -963,7 +1008,9 @@ servlist_net_remove (ircnet *net)
 	{
 		serv = list->data;
 		if (serv->network == net)
+		{
 			serv->network = NULL;
+		}
 		list = list->next;
 	}
 }
@@ -1037,7 +1084,6 @@ servlist_load (void)
 	FILE *fp;
 	char buf[2048];
 	int len;
-	char *tmp;
 	ircnet *net = NULL;
 
 	/* simple migration we will keep for a short while */
@@ -1084,9 +1130,9 @@ servlist_load (void)
 				net->autojoin = strdup (buf + 2);
 				break;
 			case 'C':
-				if (net->command)
+				/*if (net->command)
 				{
-					/* concat extra commands with a \n separator */
+					// concat extra commands with a \n separator
 					tmp = net->command;
 					net->command = malloc (strlen (tmp) + strlen (buf + 2) + 2);
 					strcpy (net->command, tmp);
@@ -1095,6 +1141,8 @@ servlist_load (void)
 					free (tmp);
 				} else
 					net->command = strdup (buf + 2);
+					*/
+				servlist_command_add (net, buf + 2);
 				break;
 			case 'F':
 				net->flags = atoi (buf + 2);
@@ -1161,13 +1209,6 @@ servlist_check_encoding (char *charset)
 	return FALSE;
 }
 
-static int
-servlist_write_ccmd (char *str, void *fp)
-{
-	return fprintf (fp, "C=%s\n", (str[0] == '/') ? str + 1 : str);
-}
-
-
 int
 servlist_save (void)
 {
@@ -1175,8 +1216,10 @@ servlist_save (void)
 	char *buf;
 	ircnet *net;
 	ircserver *serv;
+	commandentry *cmd;
 	GSList *list;
-	GSList *hlist;
+	GSList *netlist;
+	GSList *cmdlist;
 #ifndef WIN32
 	int first = FALSE;
 
@@ -1235,17 +1278,22 @@ servlist_save (void)
 			}
 		}
 
-		if (net->command)
-			token_foreach (net->command, '\n', servlist_write_ccmd, fp);
-
 		fprintf (fp, "F=%d\nD=%d\n", net->flags, net->selected);
 
-		hlist = net->servlist;
-		while (hlist)
+		netlist = net->servlist;
+		while (netlist)
 		{
-			serv = hlist->data;
+			serv = netlist->data;
 			fprintf (fp, "S=%s\n", serv->hostname);
-			hlist = hlist->next;
+			netlist = netlist->next;
+		}
+
+		cmdlist = net->commandlist;
+		while (cmdlist)
+		{
+			cmd = cmdlist->data;
+			fprintf (fp, "C=%s\n", cmd->command);
+			cmdlist = cmdlist->next;
 		}
 
 		if (fprintf (fp, "\n") < 1)
diff --git a/src/common/servlist.h b/src/common/servlist.h
index c38c5129..141df127 100644
--- a/src/common/servlist.h
+++ b/src/common/servlist.h
@@ -25,6 +25,11 @@ typedef struct ircserver
 	char *hostname;
 } ircserver;
 
+typedef struct commandentry
+{
+	char *command;
+} commandentry;
+
 typedef struct ircnet
 {
 	char *name;
@@ -34,11 +39,11 @@ typedef struct ircnet
 	char *real;
 	char *pass;
 	char *autojoin;
-	char *command;
 	int logintype;
 	char *comment;
 	char *encoding;
 	GSList *servlist;
+	GSList *commandlist;
 	int selected;
 	guint32 flags;
 } ircnet;
@@ -72,9 +77,12 @@ void servlist_net_remove (ircnet *net);
 ircnet *servlist_net_find (char *name, int *pos, int (*cmpfunc) (const char *, const char *));
 ircnet *servlist_net_find_from_server (char *server_name);
 
-void servlist_server_remove (ircnet *net, ircserver *serv);
-ircserver *servlist_server_add (ircnet *net, char *name);
 ircserver *servlist_server_find (ircnet *net, char *name, int *pos);
+commandentry *servlist_command_find (ircnet *net, char *cmd, int *pos);
+ircserver *servlist_server_add (ircnet *net, char *name);
+commandentry *servlist_command_add (ircnet *net, char *command);
+void servlist_server_remove (ircnet *net, ircserver *serv);
+void servlist_command_remove (ircnet *net, commandentry *entry);
 
 void joinlist_split (char *autojoin, GSList **channels, GSList **keys);
 gboolean joinlist_is_in_list (server *serv, char *channel);