summary refs log tree commit diff
diff options
context:
space:
mode:
authorJune McEnroe <june@causal.agency>2021-10-02 18:40:19 -0400
committerJune McEnroe <june@causal.agency>2021-10-02 19:51:40 -0400
commitc63c1683414c044a16722e9f1e738dd6ea63ec69 (patch)
tree847a9cca0368e0a5b673c65cf54e2a9f3f6ef59a
parentExplain what pounce does and some of how it works in README (diff)
downloadpounce-c63c1683414c044a16722e9f1e738dd6ea63ec69.tar.gz
pounce-c63c1683414c044a16722e9f1e738dd6ea63ec69.zip
Log IRC to standard output with -v
So that it can actually be logged to a file separate from any errors
or status messages. Also make sure only LF is used when logging.
-rw-r--r--bounce.c2
-rw-r--r--bounce.h7
-rw-r--r--client.c4
-rw-r--r--pounce.14
-rw-r--r--server.c4
5 files changed, 14 insertions, 7 deletions
diff --git a/bounce.c b/bounce.c
index 515f7d7..ef256bc 100644
--- a/bounce.c
+++ b/bounce.c
@@ -289,7 +289,7 @@ int main(int argc, char *argv[]) {
 			break; case 's': ringSize = parseSize(optarg);
 			break; case 't': trust = optarg;
 			break; case 'u': user = optarg;
-			break; case 'v': verbose = true;
+			break; case 'v': verbose = true; setlinebuf(stdout);
 			break; case 'w': pass = optarg;
 			break; case 'x': hashPass(); return EX_OK;
 			break; case 'y': clientAway = optarg;
diff --git a/bounce.h b/bounce.h
index 4144324..af3bcc3 100644
--- a/bounce.h
+++ b/bounce.h
@@ -167,6 +167,13 @@ static inline const char *capList(enum Cap caps, const char *values[CapBits]) {
 }
 
 extern bool verbose;
+static inline void
+verboseLog(const char *prefix, const char *line, size_t len) {
+	if (!verbose) return;
+	if (len && line[len - 1] == '\n') len--;
+	if (len && line[len - 1] == '\r') len--;
+	printf("%s %.*s\n", prefix, (int)len, line);
+}
 
 void ringAlloc(size_t len);
 void ringProduce(const char *line);
diff --git a/client.c b/client.c
index bad8c11..de7b2c9 100644
--- a/client.c
+++ b/client.c
@@ -86,7 +86,7 @@ void clientFree(struct Client *client) {
 }
 
 void clientSend(struct Client *client, const char *ptr, size_t len) {
-	if (verbose) fprintf(stderr, "<- %.*s", (int)len, ptr);
+	verboseLog("<-", ptr, len);
 	fcntl(client->sock, F_SETFL, 0);
 	while (len) {
 		ssize_t ret = tls_write(client->tls, ptr, len);
@@ -409,7 +409,7 @@ void clientRecv(struct Client *client) {
 	for (;;) {
 		lf = memchr(line, '\n', &client->buf[client->len] - line);
 		if (!lf) break;
-		if (verbose) fprintf(stderr, "-> %.*s\n", (int)(lf - line), line);
+		verboseLog("->", line, lf - line);
 		if (client->need || intercept(line, lf - line)) {
 			lf[0] = '\0';
 			if (lf - line && lf[-1] == '\r') lf[-1] = '\0';
diff --git a/pounce.1 b/pounce.1
index 0a6cf03..e92bc98 100644
--- a/pounce.1
+++ b/pounce.1
@@ -1,4 +1,4 @@
-.Dd August 20, 2021
+.Dd October  2, 2021
 .Dt POUNCE 1
 .Os
 .
@@ -375,7 +375,7 @@ Set username to
 The default username is the same as the nickname.
 .
 .It Fl v | Cm verbose
-Write IRC messages to standard error:
+Log IRC messages to standard output:
 .Pp
 .Bl -tag -width "<<" -compact
 .It <<
diff --git a/server.c b/server.c
index 6640f8f..552f521 100644
--- a/server.c
+++ b/server.c
@@ -168,7 +168,7 @@ void serverPrintCert(void) {
 }
 
 void serverSend(const char *ptr, size_t len) {
-	if (verbose) fprintf(stderr, "<< %.*s", (int)len, ptr);
+	verboseLog("<<", ptr, len);
 	while (len) {
 		ssize_t ret = tls_write(client, ptr, len);
 		if (ret == TLS_WANT_POLLIN || ret == TLS_WANT_POLLOUT) continue;
@@ -244,7 +244,7 @@ void serverRecv(void) {
 		crlf = memmem(line, &buf[len] - line, "\r\n", 2);
 		if (!crlf) break;
 		crlf[0] = '\0';
-		if (verbose) fprintf(stderr, ">> %s\n", line);
+		verboseLog(">>", line, crlf - line);
 		const char *ping = line;
 		if (ping[0] == '@') {
 			ping += strcspn(ping, " ");