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

From:
Mark Jamsek <mark@jamsek.com>
Subject:
Re: gotwebd: delete now unused code
To:
Omar Polo <op@omarpolo.com>
Cc:
gameoftrees@openbsd.org
Date:
Sun, 15 Jan 2023 22:21:44 +1100

Download raw body.

Thread
On 23-01-15 09:56AM, Omar Polo wrote:
> With the move to the template, some functions that were previously
> used are now completely unused or almost.  gotweb_escape_html and
> gotweb_link are now completely unused.
> 
> (gotweb_get_time_str is the next on the list, now can be rewritten
> using the template api only and the instance in got_operations.c
> adapted to return the time_t.)
> 
> The diff is based on the previous, the one about the refactoring of
> gotweb_render_content_type, but should apply nevertheless on top of
> the main branch.
> 
> ok?

ok

> diffstat /home/op/w/got
>  M  gotwebd/gotweb.c   |  0+  90-
>  M  gotwebd/gotwebd.h  |  2+   6-
> 
> 2 files changed, 2 insertions(+), 96 deletions(-)
> 
> diff /home/op/w/got
> commit - a5155be00a47787bc9b3fcbfc41eb761bf03559e
> path + /home/op/w/got
> blob - a7105e53d7ad053fa0fcdd9dcfa7c202f39ec3fb
> file + gotwebd/gotweb.c
> --- gotwebd/gotweb.c
> +++ gotwebd/gotweb.c
> @@ -1006,70 +1006,6 @@ const struct got_error *
>  	return error;
>  }
>  
> -const struct got_error *
> -gotweb_escape_html(char **escaped_html, const char *orig_html)
> -{
> -	const struct got_error *error = NULL;
> -	struct escape_pair {
> -		char c;
> -		const char *s;
> -	} esc[] = {
> -		{ '>', "&gt;" },
> -		{ '<', "&lt;" },
> -		{ '&', "&amp;" },
> -		{ '"', "&quot;" },
> -		{ '\'', "&apos;" },
> -		{ '\n', "<br />" },
> -	};
> -	size_t orig_len, len;
> -	int i, j, x;
> -
> -	orig_len = strlen(orig_html);
> -	len = orig_len;
> -	for (i = 0; i < orig_len; i++) {
> -		for (j = 0; j < nitems(esc); j++) {
> -			if (orig_html[i] != esc[j].c)
> -				continue;
> -			len += strlen(esc[j].s) - 1 /* escaped char */;
> -		}
> -	}
> -
> -	*escaped_html = calloc(len + 1 /* NUL */, sizeof(**escaped_html));
> -	if (*escaped_html == NULL)
> -		return got_error_from_errno("calloc");
> -
> -	x = 0;
> -	for (i = 0; i < orig_len; i++) {
> -		int escaped = 0;
> -		for (j = 0; j < nitems(esc); j++) {
> -			if (orig_html[i] != esc[j].c)
> -				continue;
> -
> -			if (strlcat(*escaped_html, esc[j].s, len + 1)
> -			    >= len + 1) {
> -				error = got_error(GOT_ERR_NO_SPACE);
> -				goto done;
> -			}
> -			x += strlen(esc[j].s);
> -			escaped = 1;
> -			break;
> -		}
> -		if (!escaped) {
> -			(*escaped_html)[x] = orig_html[i];
> -			x++;
> -		}
> -	}
> -done:
> -	if (error) {
> -		free(*escaped_html);
> -		*escaped_html = NULL;
> -	} else {
> -		(*escaped_html)[x] = '\0';
> -	}
> -
> -	return error;
> -}
> -
>  static inline int
>  should_urlencode(int c)
>  {
> @@ -1282,32 +1218,6 @@ int
>  	return gotweb_render_url(c, url);
>  }
>  
> -int
> -gotweb_link(struct request *c, struct gotweb_url *url, const char *fmt, ...)
> -{
> -	va_list ap;
> -	int r;
> -
> -	if (fcgi_printf(c, "<a href='") == -1)
> -		return -1;
> -
> -	if (gotweb_render_url(c, url) == -1)
> -		return -1;
> -
> -	if (fcgi_printf(c, "'>") == -1)
> -		return -1;
> -
> -	va_start(ap, fmt);
> -	r = fcgi_vprintf(c, fmt, ap);
> -	va_end(ap);
> -	if (r == -1)
> -		return -1;
> -
> -	if (fcgi_printf(c, "</a>"))
> -		return -1;
> -	return 0;
> -}
> -
>  static struct got_repository *
>  find_cached_repo(struct server *srv, const char *path)
>  {
> blob - 66a28ad4b968ae378a24ea55deb2ea6001240067
> file + gotwebd/gotwebd.h
> --- gotwebd/gotwebd.h
> +++ gotwebd/gotwebd.h
> @@ -361,8 +361,8 @@ struct gotwebd {
>  };
>  
>  /*
> - * URL parameter for gotweb_link.  NULL values and int set to -1 are
> - * implicitly ignored, and string are properly escaped.
> + * URL parameter for gotweb_render_url.  NULL values and int set to -1
> + * are implicitly ignored, and string are properly escaped.
>   */
>  struct gotweb_url {
>  	int		 action;
> @@ -453,13 +453,9 @@ const struct got_error *gotweb_escape_html(char **, co
>      struct gotweb_url *, int *);
>  const struct got_error *gotweb_get_time_str(char **, time_t, int);
>  const struct got_error *gotweb_init_transport(struct transport **);
> -const struct got_error *gotweb_escape_html(char **, const char *);
>  const char *gotweb_action_name(int);
>  int gotweb_render_url(struct request *, struct gotweb_url *);
>  int gotweb_render_absolute_url(struct request *, struct gotweb_url *);
> -int gotweb_link(struct request *, struct gotweb_url *, const char *, ...)
> -	__attribute__((__format__(printf, 3, 4)))
> -	__attribute__((__nonnull__(3)));
>  void gotweb_free_repo_commit(struct repo_commit *);
>  void gotweb_free_repo_tag(struct repo_tag *);
>  void gotweb_process_request(struct request *);
> 

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