"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Mark Jamsek <mark@jamsek.com>
Subject:
Re: gotwebd request logging
To:
Stefan Sperling <stsp@stsp.name>
Cc:
gameoftrees@openbsd.org
Date:
Fri, 06 Dec 2024 16:11:05 +1100

Download raw body.

Thread
Stefan Sperling <stsp@stsp.name> wrote:
> Make gotwebd log requests at -v verbosity.
> 
> ok?

ok for the change but three lines exceed 80 columns; suggested reflow
annotated inline (although wrapping at the comparison operator always
looks awkward to me so whichever way you like is ok for me :)


> M  gotwebd/gotweb.c  |  36+  0-
> 
> 1 file changed, 36 insertions(+), 0 deletions(-)
> 
> commit - 2180e60f1be3368525310f44260dab7eeaa7912a
> commit + d3abf8cdfa36f35529245a90a832321533ee21c7
> blob - 6b604d8770a647fa45b6f3996abc29622426583b
> blob + 3f70bd7c5da6dfaa38c12d043c1cb2619c2bf8ca
> --- gotwebd/gotweb.c
> +++ gotwebd/gotweb.c
> @@ -36,6 +36,7 @@
>  #include <stdlib.h>
>  #include <string.h>
>  #include <unistd.h>
> +#include <vis.h>
>  
>  #include "got_error.h"
>  #include "got_object.h"
> @@ -179,6 +180,41 @@ gotweb_process_request(struct request *c)
>  		goto err;
>  	}
>  
> +	/* Log the request. */
> +	if (gotwebd_env->gotwebd_verbose > 0) {
> +		char *server_name = NULL;
> +		char *querystring = NULL;
> +		char *document_uri = NULL;
> +
> +		if (c->server_name[0]) {
> +			if (stravis(&server_name, c->server_name, VIS_SAFE) == -1) {

			if (stravis(&server_name, c->server_name, VIS_SAFE)
			    == -1) {

> +				log_warn("stravis");
> +				server_name = NULL;
> +			}
> +		}
> +		if (c->querystring[0]) {
> +			if (stravis(&querystring, c->querystring, VIS_SAFE) == -1) {

			if (stravis(&querystring, c->querystring, VIS_SAFE)
			    == -1) {

> +				log_warn("stravis");
> +				querystring = NULL;
> +			}
> +		}
> +		if (c->document_uri[0]) {
> +			if (stravis(&document_uri, c->document_uri, VIS_SAFE) == -1) {

			if (stravis(&document_uri, c->document_uri, VIS_SAFE)
			    == -1) {

> +				log_warn("stravis");
> +				document_uri = NULL;
> +			}
> +		}
> +
> +		log_info("processing request: server='%s' query='%s' "
> +		    "document_uri='%s'\n",
> +		    server_name ? server_name : "",
> +		    querystring ? querystring : "",
> +		    document_uri ? document_uri : "");
> +		free(server_name);
> +		free(querystring);
> +		free(document_uri);
> +	}
> +
>  	/*
>  	 * certain actions require a commit id in the querystring. this stops
>  	 * bad actors from exploiting this by manually manipulating the


-- 
Mark Jamsek <https://bsdbox.org>
GPG: F2FF 13DE 6A06 C471 CA80  E6E2 2930 DC66 86EE CF68