about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2019-09-16 16:57:50 -0400
committerJune McEnroe <june@causal.agency>2019-09-16 16:57:50 -0400
commitc5718dd82fca4fb633846ae232838b477d95d16e (patch)
treee7d1e314584c56469a609005212523fa9c24ba15
parentUse braces in Makefile (diff)
downloadcatgirl-c5718dd82fca4fb633846ae232838b477d95d16e.tar.gz
catgirl-c5718dd82fca4fb633846ae232838b477d95d16e.zip
Add restricted mode
Diffstat (limited to '')
-rw-r--r--catgirl.112
-rw-r--r--chat.c3
-rw-r--r--chat.h1
-rw-r--r--input.c47
4 files changed, 39 insertions, 24 deletions
diff --git a/catgirl.1 b/catgirl.1
index 0dbed23..51f1c4f 100644
--- a/catgirl.1
+++ b/catgirl.1
@@ -1,4 +1,4 @@
-.Dd July 2, 2019
+.Dd September 16, 2019
 .Dt CATGIRL 1
 .Os
 .
@@ -8,7 +8,7 @@
 .
 .Sh SYNOPSIS
 .Nm
-.Op Fl Nv
+.Op Fl NRv
 .Op Fl W Ar pass
 .Op Fl a Ar auth
 .Op Fl h Ar host
@@ -33,6 +33,14 @@ The arguments are as follows:
 Send notifications with
 .Xr notify-send 1 .
 .
+.It Fl R
+Restrict the use of the
+.Ic /join ,
+.Ic /query ,
+.Ic /quote ,
+.Ic /raw
+commands.
+.
 .It Fl W Ar pass
 Send
 .Cm WEBIRC
diff --git a/chat.c b/chat.c
index 13f3c76..021ac77 100644
--- a/chat.c
+++ b/chat.c
@@ -53,9 +53,10 @@ int main(int argc, char *argv[]) {
 	setlocale(LC_CTYPE, "");
 
 	int opt;
-	while (0 < (opt = getopt(argc, argv, "NW:a:h:j:k:l:n:p:r:u:vw:"))) {
+	while (0 < (opt = getopt(argc, argv, "NRW:a:h:j:k:l:n:p:r:u:vw:"))) {
 		switch (opt) {
 			break; case 'N': self.notify = true;
+			break; case 'R': self.limit = true;
 			break; case 'W': self.webp = dupe(optarg);
 			break; case 'a': self.auth = dupe(optarg);
 			break; case 'h': self.host = dupe(optarg);
diff --git a/chat.h b/chat.h
index bd7158b..9cec917 100644
--- a/chat.h
+++ b/chat.h
@@ -44,6 +44,7 @@ struct {
 	char *real;
 	char *join;
 	char *keys;
+	bool limit;
 	bool raw;
 	bool notify;
 	bool quit;
diff --git a/input.c b/input.c
index c4f707e..8be8eaf 100644
--- a/input.c
+++ b/input.c
@@ -195,28 +195,29 @@ static void inputWindow(struct Tag tag, char *params) {
 static const struct {
 	const char *command;
 	Handler *handler;
+	bool limit;
 } Commands[] = {
-	{ "/close", inputClose },
-	{ "/help", inputMan },
-	{ "/join", inputJoin },
-	{ "/list", inputList },
-	{ "/man", inputMan },
-	{ "/me", inputMe },
-	{ "/move", inputMove },
-	{ "/names", inputWho },
-	{ "/nick", inputNick },
-	{ "/open", inputOpen },
-	{ "/part", inputPart },
-	{ "/query", inputQuery },
-	{ "/quit", inputQuit },
-	{ "/quote", inputQuote },
-	{ "/raw", inputRaw },
-	{ "/topic", inputTopic },
-	{ "/url", inputURL },
-	{ "/who", inputWho },
-	{ "/whois", inputWhois },
-	{ "/window", inputWindow },
-	{ "/znc", inputZNC },
+	{ "/close", .handler = inputClose },
+	{ "/help", .handler = inputMan },
+	{ "/join", .handler = inputJoin, .limit = true },
+	{ "/list", .handler = inputList },
+	{ "/man", .handler = inputMan },
+	{ "/me", .handler = inputMe },
+	{ "/move", .handler = inputMove },
+	{ "/names", .handler = inputWho },
+	{ "/nick", .handler = inputNick },
+	{ "/open", .handler = inputOpen },
+	{ "/part", .handler = inputPart },
+	{ "/query", .handler = inputQuery, .limit = true },
+	{ "/quit", .handler = inputQuit },
+	{ "/quote", .handler = inputQuote, .limit = true },
+	{ "/raw", .handler = inputRaw, .limit = true },
+	{ "/topic", .handler = inputTopic },
+	{ "/url", .handler = inputURL },
+	{ "/who", .handler = inputWho },
+	{ "/whois", .handler = inputWhois },
+	{ "/window", .handler = inputWindow },
+	{ "/znc", .handler = inputZNC },
 };
 static const size_t CommandsLen = sizeof(Commands) / sizeof(Commands[0]);
 
@@ -264,6 +265,10 @@ void input(struct Tag tag, char *input) {
 
 	for (size_t i = 0; i < CommandsLen; ++i) {
 		if (strcasecmp(command, Commands[i].command)) continue;
+		if (self.limit && Commands[i].limit) {
+			uiFmt(tag, UIHot, "%s isn't available in restricted mode", command);
+			return;
+		}
 		Commands[i].handler(tag, input);
 		return;
 	}