changeset 1030:509bcfb14670

misc: change signature to change mode While here: - Update manual pages, - Add missing bits.
author David Demelier <markand@malikania.fr>
date Tue, 02 Mar 2021 19:34:00 +0100
parents 113e523d999a
children a20060091063
files MIGRATING.md irccd/jsapi-server.c irccd/peer.c irccdctl/main.c lib/irccd/channel.c lib/irccd/channel.h lib/irccd/server.c lib/irccd/server.h man/irccd-api-server.3 man/irccd-ipc.7 man/irccdctl.1
diffstat 11 files changed, 99 insertions(+), 181 deletions(-) [+]
line wrap: on
line diff
--- a/MIGRATING.md	Fri Feb 26 16:32:27 2021 +0100
+++ b/MIGRATING.md	Tue Mar 02 19:34:00 2021 +0100
@@ -25,6 +25,8 @@
   semantic versioning.
 - The command `rule-info` has been removed because it is mostly the same as
   `rule-list`.
+- The command `server-mode` signature has changed because it was mostly unusable
+  before.
 
 Platform support
 ----------------
@@ -80,6 +82,8 @@
   and the `Server.info` returned object has been renamed to `prefix`.
 - The event `onMode` now takes four arguments: server, channel, mode and list
   of arguments to the mode. The previous signature was mostly unusable.
+- The method `Server.mode` has a different signature because it was mostly
+  unusable.
 
 Plugins
 -------
--- a/irccd/jsapi-server.c	Fri Feb 26 16:32:27 2021 +0100
+++ b/irccd/jsapi-server.c	Tue Mar 02 19:34:00 2021 +0100
@@ -135,7 +135,7 @@
 		if (!duk_is_string(ctx, -2))
 			(void)duk_error(ctx, DUK_ERR_ERROR, "invalid channel 'name' property");
 
-		irc_server_join(s, duk_to_string(ctx, -2), duk_opt_string(ctx, -1, NULL));
+		irc_server_join(s, duk_to_string(ctx, -2), duk_get_string_default(ctx, -1, NULL));
 		duk_pop_n(ctx, 4);
 	}
 
@@ -221,13 +221,6 @@
 	const char *target = duk_require_string(ctx, 0);
 	const char *channel = duk_require_string(ctx, 1);
 
-#if 0
-	if (!*target || !*channel)
-		throw server_error(server_error::invalid_nickname);
-	if (channel.empty())
-		throw server_error(server_error::invalid_channel);
-#endif
-
 	duk_push_boolean(ctx, irc_server_invite(s, target, channel));
 
 	return 1;
@@ -249,12 +242,7 @@
 {
 	struct irc_server *s = self(ctx);
 	const char *channel = duk_require_string(ctx, 0);
-	const char *password = duk_opt_string(ctx, 1, NULL);
-
-#if 0
-	if (channel.empty())
-		throw server_error(server_error::invalid_channel);
-#endif
+	const char *password = duk_get_string_default(ctx, 1, NULL);
 
 	duk_push_boolean(ctx, irc_server_join(s, channel, password));
 
@@ -267,14 +255,7 @@
 	struct irc_server *s = self(ctx);
 	const char *target = duk_require_string(ctx, 0);
 	const char *channel = duk_require_string(ctx, 1);
-	const char *reason = duk_opt_string(ctx, 2, NULL);
-
-#if 0
-	if (target.empty())
-		throw server_error(server_error::invalid_nickname);
-	if (channel.empty())
-		throw server_error(server_error::invalid_channel);
-#endif
+	const char *reason = duk_get_string_default(ctx, 2, NULL);
 
 	duk_push_boolean(ctx, irc_server_kick(s, channel, target, reason));
 
@@ -288,11 +269,6 @@
 	const char *target = duk_require_string(ctx, 0);
 	const char *message = duk_require_string(ctx, 1);
 
-#if 0
-	if (target.empty())
-		throw server_error(server_error::invalid_nickname);
-#endif
-
 	duk_push_boolean(ctx, irc_server_me(s, target, message));
 
 	return 1;
@@ -305,11 +281,6 @@
 	const char *target = duk_require_string(ctx, 0);
 	const char *message = duk_require_string(ctx, 1);
 
-#if 0
-	if (target.empty())
-		throw server_error(server_error::invalid_nickname);
-#endif
-
 	duk_push_boolean(ctx, irc_server_message(s, target, message));
 
 	return 1;
@@ -321,18 +292,9 @@
 	struct irc_server *s = self(ctx);
 	const char *channel = duk_require_string(ctx, 0);
 	const char *mode = duk_require_string(ctx, 1);
-	const char *limit = duk_opt_string(ctx, 2, NULL);
-	const char *user = duk_opt_string(ctx, 3, NULL);
-	const char *mask = duk_opt_string(ctx, 4, NULL);
+	const char *args = duk_get_string_default(ctx, 2, NULL);
 
-#if 0
-	if (channel.empty())
-		throw server_error(server_error::invalid_channel);
-	if (mode.empty())
-		throw server_error(server_error::invalid_mode);
-#endif
-
-	duk_push_boolean(ctx, irc_server_mode(s, channel, mode, limit, user, mask));
+	duk_push_boolean(ctx, irc_server_mode(s, channel, mode, args));
 
 	return 1;
 }
@@ -343,11 +305,6 @@
 	struct irc_server *s = self(ctx);
 	const char *channel = duk_require_string(ctx, 0);
 
-#if 0
-	if (channel.empty())
-		throw server_error(server_error::invalid_channel);
-#endif
-
 	duk_push_boolean(ctx, irc_server_names(s, channel));
 
 	return 1;
@@ -359,11 +316,6 @@
 	struct irc_server *s = self(ctx);
 	const char *nickname = duk_require_string(ctx, 0);
 
-#if 0
-	if (nickname.empty())
-		throw server_error(server_error::invalid_nickname);
-#endif
-
 	duk_push_boolean(ctx, irc_server_nick(s, nickname));
 
 	return 1;
@@ -374,12 +326,7 @@
 {
 	struct irc_server *s = self(ctx);
 	const char *target = duk_require_string(ctx, 0);
-	const char *message = duk_opt_string(ctx, 1, NULL);
-
-#if 0
-	if (target.empty())
-		throw server_error(server_error::invalid_nickname);
-#endif
+	const char *message = duk_get_string_default(ctx, 1, NULL);
 
 	duk_push_boolean(ctx, irc_server_notice(s, target, message));
 
@@ -391,12 +338,7 @@
 {
 	struct irc_server *s = self(ctx);
 	const char *channel = duk_require_string(ctx, 0);
-	const char *reason = duk_opt_string(ctx, 1, NULL);
-
-#if 0
-	if (channel.empty())
-		throw server_error(server_error::invalid_channel);
-#endif
+	const char *reason = duk_get_string_default(ctx, 1, NULL);
 
 	duk_push_boolean(ctx, irc_server_part(s, channel, reason));
 
@@ -409,11 +351,6 @@
 	struct irc_server *s = self(ctx);
 	const char *raw = duk_require_string(ctx, 0);
 
-#if 0
-	if (raw.empty())
-		throw server_error(server_error::invalid_message);
-#endif
-
 	duk_push_boolean(ctx, irc_server_send(s, raw));
 
 	return 1;
@@ -426,11 +363,6 @@
 	const char *channel = duk_require_string(ctx, 0);
 	const char *topic = duk_require_string(ctx, 1);
 
-#if 0
-	if (channel.empty())
-		throw server_error(server_error::invalid_channel);
-#endif
-
 	duk_push_boolean(ctx, irc_server_topic(s, channel, topic));
 
 	return 1;
@@ -442,11 +374,6 @@
 	struct irc_server *s = self(ctx);
 	const char *target = duk_require_string(ctx, 0);
 
-#if 0
-	if (target.empty())
-		throw server_error(server_error::invalid_nickname);
-#endif
-
 	duk_push_boolean(ctx, irc_server_whois(s, target));
 
 	return 1;
--- a/irccd/peer.c	Fri Feb 26 16:32:27 2021 +0100
+++ b/irccd/peer.c	Tue Mar 02 19:34:00 2021 +0100
@@ -183,14 +183,7 @@
 }
 
 /*
- * HOOK-ADD name path	fprintf(fp, "OK ");
-
- LIST_FOREACH(s, &irc.servers, link) {
-		fprintf(fp, "%s", s->name);
-
-		if (LIST_NEXT(s, link))
-			fputc(' ', fp);
-	}
+ * HOOK-ADD name path
  */
 static int
 cmd_hook_add(struct peer *p, char *line)
@@ -277,7 +270,7 @@
 	if (!(plg = require_plugin(p, args[0])))
 		return 0;
 
-	peer_send(p, "OK %s\n%s\n%s\n%s\n%s", plg->name, plg->description,
+	peer_send(p, "OK 5%s\n%s\n%s\n%s\n%s", plg->name, plg->description,
 	    plg->version, plg->license, plg->author);
 
 	return 0;
@@ -690,24 +683,20 @@
 }
 
 /*
- * SERVER-MODE server channel mode [limit] [user] [mask]
+ * SERVER-MODE server channel mode [args...]
  */
 static int
 cmd_server_mode(struct peer *p, char *line)
 {
-	const char *args[6] = {0};
+	const char *args[4] = {0};
 	struct irc_server *s;
 
-	if (parse(line, args, 6) < 3)
+	if (parse(line, args, 4) < 3)
 		return EINVAL;
 	if (!(s = require_server(p, args[0])))
 		return 0;
 
-	irc_server_mode(s, args[1], args[2],
-	    args[3][0] ? args[3] : NULL,
-	    args[4][0] ? args[4] : NULL,
-	    args[5][0] ? args[5] : NULL
-	);
+	irc_server_mode(s, args[1], args[2], args[3]);
 
 	return ok(p);
 }
@@ -756,7 +745,7 @@
 	fprintf(fp, "%s %s %s\n", s->ident.nickname, s->ident.username, s->ident.realname);
 
 	LIST_FOREACH(c, &s->channels, link) {
-		const struct irc_channel_user *user = irc_channel_find(c, s->ident.nickname);
+		const struct irc_channel_user *user = irc_channel_get(c, s->ident.nickname);
 
 		/* Prefix all our own modes on this channel. */
 		for (size_t i = 0; i < IRC_UTIL_SIZE(s->params.prefixes); ++i)
--- a/irccdctl/main.c	Fri Feb 26 16:32:27 2021 +0100
+++ b/irccdctl/main.c	Tue Mar 02 19:34:00 2021 +0100
@@ -739,15 +739,10 @@
 static void
 cmd_server_mode(int argc, char **argv)
 {
-	(void)argc;
-	(void)argv;
-#if 0
-	req("MODE %s %s %s%c%s%c%s%c%s", argv[0], argv[1], argv[2],
-		argc >= 4 ? ' ', argv[3] : "",
-		argc >= 5 ? ' ', argv[4] : "",
-		argc >= 6 ? ' ', argv[5] : "");
+	req("SERVER-MODE %s %s %s%c%s", argv[0], argv[1], argv[2],
+	    argc >= 4 ? ' '     : '\0',
+	    argc >= 4 ? argv[3] : "");
 	ok();
-#endif
 }
 
 static void
@@ -838,7 +833,7 @@
 	{ "server-list",        0,      0,      cmd_server_list         },
 	{ "server-me",          3,      3,      cmd_server_me           },
 	{ "server-message",     3,      3,      cmd_server_message      },
-	{ "server-mode",        3,      6,      cmd_server_mode         },
+	{ "server-mode",        3,      4,      cmd_server_mode         },
 	{ "server-nick",        2,      2,      cmd_server_nick         },
 	{ "server-notice",      3,      3,      cmd_server_notice       },
 	{ "server-part",        3,      3,      cmd_server_part         },
@@ -910,7 +905,7 @@
 	fprintf(stderr, "       %s server-list\n", getprogname());
 	fprintf(stderr, "       %s server-me server target message\n", getprogname());
 	fprintf(stderr, "       %s server-message server target message\n", getprogname());
-	fprintf(stderr, "       %s server-mode server target mode [limit] [user] [mask]\n", getprogname());
+	fprintf(stderr, "       %s server-mode server target mode [args]\n", getprogname());
 	fprintf(stderr, "       %s server-nick server nickname\n", getprogname());
 	fprintf(stderr, "       %s server-notice server target message\n", getprogname());
 	fprintf(stderr, "       %s server-part server channel [reason]\n", getprogname());
--- a/lib/irccd/channel.c	Fri Feb 26 16:32:27 2021 +0100
+++ b/lib/irccd/channel.c	Tue Mar 02 19:34:00 2021 +0100
@@ -50,7 +50,7 @@
 
 	struct irc_channel_user *user;
 
-	if (irc_channel_find(ch, nickname))
+	if (irc_channel_get(ch, nickname))
 		return;
 
 	user = irc_util_malloc(sizeof (*user));
@@ -61,7 +61,7 @@
 }
 
 struct irc_channel_user *
-irc_channel_find(const struct irc_channel *ch, const char *nickname)
+irc_channel_get(const struct irc_channel *ch, const char *nickname)
 {
 	struct irc_channel_user *u;
 
@@ -92,7 +92,7 @@
 
 	struct irc_channel_user *user;
 
-	if ((user = irc_channel_find(ch, nick))) {
+	if ((user = irc_channel_get(ch, nick))) {
 		LIST_REMOVE(user, link);
 		free(user);
 	}
--- a/lib/irccd/channel.h	Fri Feb 26 16:32:27 2021 +0100
+++ b/lib/irccd/channel.h	Tue Mar 02 19:34:00 2021 +0100
@@ -51,7 +51,7 @@
 irc_channel_add(struct irc_channel *, const char *, int);
 
 struct irc_channel_user *
-irc_channel_find(const struct irc_channel *, const char *);
+irc_channel_get(const struct irc_channel *, const char *);
 
 void
 irc_channel_clear(struct irc_channel *);
--- a/lib/irccd/server.c	Fri Feb 26 16:32:27 2021 +0100
+++ b/lib/irccd/server.c	Tue Mar 02 19:34:00 2021 +0100
@@ -379,7 +379,7 @@
 			++argindex;
 			continue;
 		}
-		if (!msg->args[argindex] || !(u = irc_channel_find(ch, msg->args[argindex]))) {
+		if (!msg->args[argindex] || !(u = irc_channel_get(ch, msg->args[argindex]))) {
 			++argindex;
 			continue;
 		}
@@ -977,21 +977,15 @@
 }
 
 int
-irc_server_mode(struct irc_server *s,
-                const char *channel,
-                const char *mode,
-                const char *limit,
-                const char *user,
-                const char *mask)
+irc_server_mode(struct irc_server *s, const char *channel, const char *mode, const char *args)
 {
 	assert(s);
 	assert(channel);
 	assert(mode);
 
-	return irc_server_send(s, "MODE %s %s %s %s %s", channel, mode,
-	    limit ? limit : "",
-	    user ? user : "",
-	    mask ? mask : "");
+	args = args ? args : "";
+
+	return irc_server_send(s, "MODE %s %s %s", channel, mode, args);
 }
 
 int
--- a/lib/irccd/server.h	Fri Feb 26 16:32:27 2021 +0100
+++ b/lib/irccd/server.h	Tue Mar 02 19:34:00 2021 +0100
@@ -151,12 +151,7 @@
 irc_server_me(struct irc_server *, const char *, const char *);
 
 int
-irc_server_mode(struct irc_server *,
-                const char *,
-                const char *,
-                const char *,
-                const char *,
-                const char *);
+irc_server_mode(struct irc_server *, const char *, const char *, const char *);
 
 int
 irc_server_names(struct irc_server *, const char *);
--- a/man/irccd-api-server.3	Fri Feb 26 16:32:27 2021 +0100
+++ b/man/irccd-api-server.3	Tue Mar 02 19:34:00 2021 +0100
@@ -34,7 +34,7 @@
 .Fn Irccd.Server.prototype.kick "target, channel, reason = undefined"
 .Fn Irccd.Server.prototype.me "target, message"
 .Fn Irccd.Server.prototype.message "target, message"
-.Fn Irccd.Server.prototype.mode "target, mode, limit, user, mode"
+.Fn Irccd.Server.prototype.mode "target, mode, args"
 .Fn Irccd.Server.prototype.names "channel"
 .Fn Irccd.Server.prototype.nick "nickname"
 .Fn Irccd.Server.prototype.notice "target, message"
@@ -205,11 +205,8 @@
 .Fa mode .
 otherwise it changes the channel one.
 The optional argument
-.Fa limit , user
-and
-.Fa mask
-are required depending on the mode mask. See IRC specification for more
-details.
+.Fa args
+contains additional mode arguments.
 .Pp
 .\" Irccd.Server.prototype.names
 The
--- a/man/irccd-ipc.7	Fri Feb 26 16:32:27 2021 +0100
+++ b/man/irccd-ipc.7	Tue Mar 02 19:34:00 2021 +0100
@@ -25,6 +25,8 @@
 .Nm HOOK-ADD
 .Ar name Ar path
 .Nm HOOK-LIST
+.Nm HOOK-REMOVE
+.Ar name
 .Nm PLUGIN-CONFIG
 .Ar name Op Ar variable Op Ar value
 .Nm PLUGIN-INFO
@@ -63,6 +65,11 @@
 .Ar name
 .Ar channel
 .Ar message
+.Nm SERVER-MODE
+.Ar name
+.Ar channel
+.Ar mode
+.Op Ar args
 .Nm SERVER-NOTICE
 .Ar name
 .Ar channel
@@ -167,6 +174,10 @@
 .Bd -literal -offset indent
 OK irc-notify mail-notify
 .Ed
+.\" HOOK-REMOVE
+.It Cm HOOK-REMOVE
+Removes the hook specified by
+.Ar name .
 .\" PLUGIN-CONFIG
 .It Cm PLUGIN-CONFIG
 Set or get
@@ -328,6 +339,14 @@
 .Ar channel
 into the server
 .Ar name .
+.\" SERVER-MODE
+.It Cm SERVER-MODE
+Change
+.Ar channel
+to the new
+.Ar mode
+with optional list of mode arguments specified by
+.Ar args .
 .\" SERVER-NOTICE
 .It Cm SERVER-NOTICE
 Send the
--- a/man/irccdctl.1	Fri Feb 26 16:32:27 2021 +0100
+++ b/man/irccdctl.1	Tue Mar 02 19:34:00 2021 +0100
@@ -50,6 +50,16 @@
 .Nm
 .Cm plugin-load
 .Ar name
+.\" plugin-path
+.Nm
+.Cm plugin-path
+.Ar id
+.Op Ar variable Op Ar value
+.\" plugin-template
+.Nm
+.Cm plugin-template
+.Ar id
+.Op Ar variable Op Ar value
 .\" plugin-reload
 .Nm
 .Cm plugin-reload
@@ -147,11 +157,9 @@
 .Nm
 .Cm server-mode
 .Ar server
-.Ar target
+.Ar channel
 .Ar mode
-.Op Ar limit
-.Op Ar user
-.Op Ar mask
+.Op Ar args
 .\" server-nick
 .Nm
 .Cm server-nick
@@ -182,18 +190,19 @@
 .\" watch
 .Nm
 .Cm watch
-.Op Fl f Ar native|json
 .\" DESCRIPTION
 .Sh DESCRIPTION
 The
 .Nm irccdctl
-is the official utility that let you control a running irccd instance. It uses
-JSON messages over TCP/IP or UNIX sockets with optional SSL layer to send
-requests. For more information see
-.Xr irccd-ipc 7 .
+utility is the official utility that let you control a running irccd instance.
+It connects to the UNIX domain socket opened by
+.Xr irccd 1
+to make requests through the
+.Xr irccd-ipc 7
+protocol.
 .Pp
 The general syntax for running an irccdctl command is:
-.Bd -literal -offset Ds
+.Bd -literal -offset indent
 irccdctl global-options command command-options command-arguments
 .Ed
 .Pp
@@ -204,33 +213,13 @@
 the
 .Ar command
 name:
-.Bl -tag -width 12n
-.It Fl 4
-Try to connect using IPv4. Specifying this option
-unset
-.Fl 6
-option, set it explicitly to enable both families.
-.It Fl 6
-Try to connect using IPv6. Specifying this option will
-unset
-.Fl 4
-option, set it explicitly to enable both families.
-.It Fl h Ar hostname
-Connect to the IP address or hostname.
-.It Fl p Ar port
-Use the
-.Ar port
-number or service name.
-.It Fl P Ar path
+.Bl -tag "path"
+.It Fl s Ar path
 Connect to the UNIX local socket specified by
 .Ar path .
+.It Fl v
+Be more verbose.
 .El
-.Pp
-Note: options
-.Fl h
-and
-.Fl P
-are mutually exclusive.
 .\" COMMANDS
 .Sh COMMANDS
 .Bl -tag -width xxxxxxxx-yyyyyyyyy
@@ -271,6 +260,7 @@
 .\" plugin-list
 .It Cm plugin-list
 Get the list of all loaded plugins.
+.\" plugin-load
 .It Cm plugin-load
 Load a plugin into the irccd instance.
 .Pp
@@ -278,6 +268,16 @@
 .Ar name
 will always be evaluated as plugin name and not as a filesystem path. Therefore,
 the plugin will be searched through the irccd directories.
+.\" plugin-path
+.It Cm plugin-path
+Exactly the same usage as
+.Cm plugin-config
+but for plugin paths.
+.\" plugin-template
+.It Cm plugin-template
+Exactly the same usage as
+.Cm plugin-config
+but for plugin templates.
 .\" plugin-reload
 .It Cm plugin-reload
 Reload a plugin specified by
@@ -431,16 +431,20 @@
 .It Cm server-mode
 Set
 .Ar target
-or irccd's user mode.
+or irccd's user
+.Ar mode .
 .Pp
 When
 .Ar target
 is the bot's nickname, the command change its mode. Otherwise it applies to a
 channel and modes are treated differently.
 .Pp
-The arguments
-.Ar limit , user , mask
-are usually only used with channel modes.
+The optional
+.Ar args
+contains additional mode arguments usually separated by spaces. Make sure to
+quote them in the shell to detect as a single argument, otherwise
+.Nm
+will not understand the command usage.
 .\" server-nick
 .It Cm server-nick
 Change irccd's
@@ -471,14 +475,9 @@
 new
 .Ar topic .
 .\" watch
+.It Cm watch
 Start watching irccd events. This command will indefinitely wait for new events
 to arrive from irccd.
-.Pp
-Available options:
-.Bl -tag -width 14n
-.It Fl f Ar native|json
-use JSON or native (human readable) format.
-.El
 .El
 .\" BUGS
 .Sh BUGS
@@ -494,8 +493,7 @@
 .Ed
 .\" SEE ALSO
 .Sh SEE ALSO
-.Xr irccd 1 ,
-.Xr irccdctl.conf 5
+.Xr irccd 1
 .\" AUTHORS
 .Sh AUTHORS
 .Nm