changeset 984:2e4b29ab8e9c

irccd: add prefix support in configuration
author David Demelier <markand@malikania.fr>
date Tue, 09 Feb 2021 22:40:29 +0100
parents d5aa6aba8959
children 6da542806ed3
files MIGRATING.md irccd/conf.y irccd/jsapi-server.c irccd/lex.l lib/irccd/irccd.c lib/irccd/limits.h lib/irccd/server.c lib/irccd/server.h
diffstat 8 files changed, 22 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/MIGRATING.md	Tue Feb 09 22:31:53 2021 +0100
+++ b/MIGRATING.md	Tue Feb 09 22:40:29 2021 +0100
@@ -71,6 +71,8 @@
 - The property `channels` in the object for the `Server` constructor now takes
   an array of objects containing two properties each: `name` and `password`
   which must be string (password is optional).
+- The property `commandChar` which is provided in both the `Server` constructor
+  and the `Server.info` returned object has been renamed to `prefix`.
 
 Migrating from 2.x to 3.x
 =========================
--- a/irccd/conf.y	Tue Feb 09 22:31:53 2021 +0100
+++ b/irccd/conf.y	Tue Feb 09 22:40:29 2021 +0100
@@ -62,6 +62,7 @@
 	char *nickname;
 	char *username;
 	char *realname;
+	char *prefix;
 	struct string_list *channels;
 };
 
@@ -147,6 +148,7 @@
 %token T_PATHS
 %token T_PLUGIN
 %token T_PLUGINS
+%token T_PREFIX
 %token T_PORT
 %token T_RULE
 %token T_SEMICOLON
@@ -382,6 +384,11 @@
 		$$ = $3;
 		$$->flags |= IRC_SERVER_FLAGS_SSL;
 	}
+	| T_PREFIX T_STRING server_params
+	{
+		$$ = $3;
+		$$->prefix = $2;
+	}
 	| T_OPTIONS string_list T_SEMICOLON server_params
 	{
 		struct string *s;
@@ -438,6 +445,9 @@
 			string_list_finish($4->channels);
 		}
 
+		if ($4->prefix)
+			strlcpy(s->prefix, $4->prefix, sizeof (s->prefix));
+
 		s->flags = $4->flags;
 		irc_bot_server_add(s);
 
@@ -446,6 +456,7 @@
 		free($4->nickname);
 		free($4->username);
 		free($4->realname);
+		free($4->prefix);
 		free($4);
 	}
 	;
--- a/irccd/jsapi-server.c	Tue Feb 09 22:31:53 2021 +0100
+++ b/irccd/jsapi-server.c	Tue Feb 09 22:40:29 2021 +0100
@@ -158,8 +158,8 @@
 	duk_put_prop_string(ctx, -2, "port");
 	duk_push_boolean(ctx, s->flags & IRC_SERVER_FLAGS_SSL);
 	duk_put_prop_string(ctx, -2, "ssl");
-	duk_push_string(ctx, s->commandchar);
-	duk_put_prop_string(ctx, -2, "commandChar");
+	duk_push_string(ctx, s->prefix);
+	duk_put_prop_string(ctx, -2, "prefix");
 	duk_push_string(ctx, s->ident.realname);
 	duk_put_prop_string(ctx, -2, "realname");
 	duk_push_string(ctx, s->ident.nickname);
--- a/irccd/lex.l	Tue Feb 09 22:31:53 2021 +0100
+++ b/irccd/lex.l	Tue Feb 09 22:40:29 2021 +0100
@@ -44,6 +44,7 @@
 paths           paths
 plugin          plugin
 plugins         plugins
+prefix          prefix
 port            port
 rule            rule
 rule_action     accept|drop
@@ -86,6 +87,7 @@
 {paths}                 return T_PATHS;
 {plugins}               return T_PLUGINS;
 {plugin}                return T_PLUGIN;
+{prefix}                return T_PREFIX;
 {port}                  return T_PORT;
 {semicolon}             return T_SEMICOLON;
 {servers}               return T_SERVERS;
--- a/lib/irccd/irccd.c	Tue Feb 09 22:31:53 2021 +0100
+++ b/lib/irccd/irccd.c	Tue Feb 09 22:40:29 2021 +0100
@@ -60,7 +60,7 @@
 		return 0;
 
 	/* Get the command prefix (e.g !)*/
-	cc = ev->server->commandchar;
+	cc = ev->server->prefix;
 	ccsz = strlen(cc);
 
 	return strncmp(ev->message.message, cc, ccsz) == 0 &&
@@ -75,7 +75,7 @@
 	/* Convert "!test foo bar" to "foo bar" */
 	memcpy(&cev, ev, sizeof (*ev));
 	cev.type = IRC_EVENT_COMMAND;
-	cev.message.message += strlen(cev.server->commandchar) + strlen(p->name);
+	cev.message.message += strlen(cev.server->prefix) + strlen(p->name);
 
 	while (*cev.message.message && isspace(*cev.message.message))
 		++cev.message.message;
--- a/lib/irccd/limits.h	Tue Feb 09 22:31:53 2021 +0100
+++ b/lib/irccd/limits.h	Tue Feb 09 22:40:29 2021 +0100
@@ -30,7 +30,7 @@
 #define IRC_CTCPVERSION_LEN     64              /* Custom CTCP version answer. */
 #define IRC_USERMODES_LEN       8               /* Number of modes (e.g. ohv). */
 #define IRC_CHANTYPES_LEN       8               /* Channel types. */
-#define IRC_CMDCHAR_LEN         4               /* Prefix for plugin commands (e.g. !). */
+#define IRC_PREFIX_LEN          4               /* Prefix for plugin commands (e.g. !). */
 #define IRC_CHARSET_LEN         16              /* Charset name max. */
 #define IRC_CASEMAPPING_LEN     16              /* Maximum case mapping length. */
 #define IRC_MESSAGE_LEN         512             /* Official length per message. */
--- a/lib/irccd/server.c	Tue Feb 09 22:31:53 2021 +0100
+++ b/lib/irccd/server.c	Tue Feb 09 22:40:29 2021 +0100
@@ -659,7 +659,7 @@
 	LIST_INIT(&s->channels);
 
 	/* Default options. */
-	strlcpy(s->commandchar, "!", sizeof (s->commandchar));
+	strlcpy(s->prefix, "!", sizeof (s->prefix));
 
 	return s;
 }
--- a/lib/irccd/server.h	Tue Feb 09 22:31:53 2021 +0100
+++ b/lib/irccd/server.h	Tue Feb 09 22:40:29 2021 +0100
@@ -81,7 +81,7 @@
 
 struct irc_server {
 	char name[IRC_ID_LEN];
-	char commandchar[IRC_CMDCHAR_LEN];
+	char prefix[IRC_PREFIX_LEN];
 	struct irc_server_ident ident;
 	struct irc_server_params params;
 	enum irc_server_state state;