changeset 999:c50f954d8c67

irccd: support password
author David Demelier <markand@malikania.fr>
date Fri, 12 Feb 2021 19:31:00 +0100
parents 474a46e240ff
children c2cb87b19307
files irccd/conf.y irccd/lex.l lib/irccd/server.c man/irccd.conf.5
diffstat 4 files changed, 29 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/irccd/conf.y	Fri Feb 12 10:09:46 2021 +0100
+++ b/irccd/conf.y	Fri Feb 12 19:31:00 2021 +0100
@@ -57,6 +57,7 @@
 
 struct server_params {
 	char *hostname;
+	char *password;
 	int port;
 	int flags;
 	char *nickname;
@@ -145,6 +146,7 @@
 %token T_LOGS
 %token T_OPTIONS
 %token T_ORIGINS
+%token T_PASSWORD
 %token T_PATHS
 %token T_PLUGIN
 %token T_PLUGINS
@@ -384,6 +386,11 @@
 		$$ = $3;
 		$$->flags |= IRC_SERVER_FLAGS_SSL;
 	}
+	| T_PASSWORD T_STRING T_SEMICOLON server_params
+	{
+		$$ = $4;
+		$$->password = $2;
+	}
 	| T_PREFIX T_STRING server_params
 	{
 		$$ = $3;
@@ -447,6 +454,8 @@
 
 		if ($4->prefix)
 			strlcpy(s->prefix, $4->prefix, sizeof (s->prefix));
+		if ($4->password)
+			strlcpy(s->ident.password, $4->password, sizeof (s->ident.password));
 
 		s->flags = $4->flags;
 		irc_bot_server_add(s);
@@ -457,6 +466,7 @@
 		free($4->username);
 		free($4->realname);
 		free($4->prefix);
+		free($4->password);
 		free($4);
 	}
 	;
--- a/irccd/lex.l	Fri Feb 12 10:09:46 2021 +0100
+++ b/irccd/lex.l	Fri Feb 12 19:31:00 2021 +0100
@@ -41,6 +41,7 @@
 logs            logs
 options         options
 origins         origins
+password        password
 paths           paths
 plugin          plugin
 plugins         plugins
@@ -84,6 +85,7 @@
 {logs}                  return T_LOGS;
 {options}               return T_OPTIONS;
 {origins}               return T_ORIGINS;
+{password}              return T_PASSWORD;
 {paths}                 return T_PATHS;
 {plugins}               return T_PLUGINS;
 {plugin}                return T_PLUGIN;
--- a/lib/irccd/server.c	Fri Feb 12 10:09:46 2021 +0100
+++ b/lib/irccd/server.c	Fri Feb 12 19:31:00 2021 +0100
@@ -508,6 +508,17 @@
 }
 
 static void
+handle_error(struct irc_server *s, struct irc_event *ev, struct irc_conn_msg *msg)
+{
+	ev->type = IRC_EVENT_DISCONNECT;
+
+	if (msg->args[0])
+		irc_log_warn("server %s: %s", s->name, msg->args[0]);
+
+	fail(s);
+}
+
+static void
 handle_whoisuser(struct irc_server *s, struct irc_event *ev, struct irc_conn_msg *msg)
 {
 	(void)s;
@@ -570,6 +581,7 @@
 	{ "319",        handle_whoischannels    },
 	{ "353",        handle_names            },
 	{ "366",        handle_endofnames       },
+	{ "ERROR",      handle_error            },
 	{ "INVITE",     handle_invite           },
 	{ "JOIN",       handle_join             },
 	{ "KICK",       handle_kick             },
@@ -623,9 +635,9 @@
 	if (s->ident.password[0])
 		irc_server_send(s, "PASS %s", s->ident.password);
 
+	irc_server_send(s, "NICK %s", s->ident.nickname);
 	irc_server_send(s, "USER %s %s %s :%s", s->ident.username,
 	    s->ident.username, s->ident.username, s->ident.realname);
-	irc_server_send(s, "NICK %s", s->ident.nickname);
 }
 
 struct irc_server *
--- a/man/irccd.conf.5	Fri Feb 12 10:09:46 2021 +0100
+++ b/man/irccd.conf.5	Fri Feb 12 19:31:00 2021 +0100
@@ -136,6 +136,10 @@
 Use
 .Ar value
 number as IP port to connect to.
+.It Ar password value
+Add the password
+.Ar value
+if the IRC server requires it.
 .It Ar ident nick user realname
 Specify the IRC identity to use by using the three arguments
 .Ar nick , user