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

From:
Stefan Sperling <stsp@stsp.name>
Subject:
Re: use got_pkt_readlen in a few more places
To:
Tobias Heider <tobias.heider@stusta.de>
Cc:
gameoftrees@openbsd.org
Date:
Mon, 22 Apr 2024 18:07:01 +0200

Download raw body.

Thread
On Mon, Apr 22, 2024 at 05:53:02PM +0200, Tobias Heider wrote:
> -----------------------------------------------
> commit 21679dc5afe28d00d3188bb529f3cefffdb06b64 (main)
> from: Tobias Heider <me@tobhe.de>
> date: Mon Apr 22 15:50:40 2024 UTC
>  
>  Use got_pkt_readlen() to parse pkt-lens.
>  
>  M  libexec/got-fetch-http/Makefile          |   1+   1-
>  M  libexec/got-fetch-http/got-fetch-http.c  |  27+  25-
> 
> 2 files changed, 28 insertions(+), 26 deletions(-)

ok stsp

> 
> diff 3bafd8d444040e4f41be33562f63e5d2eb201447 21679dc5afe28d00d3188bb529f3cefffdb06b64
> commit - 3bafd8d444040e4f41be33562f63e5d2eb201447
> commit + 21679dc5afe28d00d3188bb529f3cefffdb06b64
> blob - b0bc7c7d83c8479fd1d9b762eaf78551f430d1a4
> blob + e6d3950b1c2fa7616f6a5e4df7e81874347259fe
> --- libexec/got-fetch-http/Makefile
> +++ libexec/got-fetch-http/Makefile
> @@ -3,7 +3,7 @@
>  .include "../../got-version.mk"
>  
>  PROG=		got-fetch-http
> -SRCS=		got-fetch-http.c bufio.c hash.c error.c inflate.c pollfd.c
> +SRCS=		got-fetch-http.c bufio.c hash.c error.c inflate.c pkt.c pollfd.c
>  
>  CPPFLAGS= -I${.CURDIR}/../../include -I${.CURDIR}/../../lib
>  
> blob - f59556fe906b0a5f6b8f565d12b387c701f2f4c7
> blob + b9e126395c419d439c968c0b1b113ab6e1a26b37
> --- libexec/got-fetch-http/got-fetch-http.c
> +++ libexec/got-fetch-http/got-fetch-http.c
> @@ -29,6 +29,7 @@
>  #include <tls.h>
>  #include <unistd.h>
>  
> +#include "got_error.h"
>  #include "got_version.h"
>  
>  #include "got_lib_pkt.h"
> @@ -346,14 +347,16 @@ http_chunk(struct bufio *bio, const void *buf, size_t 
>  static int
>  get_refs(int https, const char *host, const char *port, const char *path)
>  {
> -	struct bufio	 bio;
> -	char		 buf[GOT_PKT_MAX];
> -	const char	*errstr, *sufx = "/info/refs";
> -	size_t		 skip, chunksz = 0;
> -	ssize_t		 r;
> -	int		 chunked;
> -	int		 sock;
> -	int		 ret = -1;
> +	struct bufio		 bio;
> +	char			 buf[GOT_PKT_MAX];
> +	const struct got_error	*e;
> +	const char		*sufx = "/info/refs";
> +	size_t			 chunksz = 0;
> +	ssize_t			 r;
> +	int			 skip;
> +	int			 chunked;
> +	int			 sock;
> +	int			 ret = -1;
>  
>  	if ((sock = dial(https, host, port)) == -1)
>  		return -1;
> @@ -380,10 +383,10 @@ get_refs(int https, const char *host, const char *port
>  	r = http_read(&bio, chunked, &chunksz, buf, 4);
>  	if (r <= 0)
>  		goto err;
> -	buf[4] = '\0';
> -	skip = hexstrtonum(buf, 0, INT_MAX, &errstr);
> -	if (errstr != NULL) {
> -		warnx("pktlen is %s", errstr);
> +
> +	e = got_pkt_readlen(&skip, buf, verbose);
> +	if (e) {
> +		warnx("%s", e->msg);
>  		goto err;
>  	}
>  
> @@ -419,15 +422,15 @@ static int
>  upload_request(int https, const char *host, const char *port, const char *path,
>      FILE *in)
>  {
> -	struct bufio	 bio;
> -	const char	*errstr;
> -	char		 buf[GOT_PKT_MAX];
> -	ssize_t		 r;
> -	size_t		 chunksz = 0;
> -	long long	 t;
> -	int		 chunked;
> -	int		 sock;
> -	int		 ret = -1;
> +	struct bufio		 bio;
> +	char			 buf[GOT_PKT_MAX];
> +	const struct got_error	*e;
> +	ssize_t			 r;
> +	size_t			 chunksz = 0;
> +	int			 t;
> +	int			 chunked;
> +	int			 sock;
> +	int			 ret = -1;
>  
>  	if ((sock = dial(https, host, port)) == -1)
>  		return -1;
> @@ -459,10 +462,9 @@ upload_request(int https, const char *host, const char
>  		if (r != 4)
>  			goto err;
>  
> -		buf[4] = '\0';
> -		t = hexstrtonum(buf, 0, sizeof(buf), &errstr);
> -		if (errstr != NULL) {
> -			warnx("pktline len is %s", errstr);
> +		e = got_pkt_readlen(&t, buf, verbose);
> +		if (e) {
> +			warnx("%s", e->msg);
>  			goto err;
>  		}
>  
> 
>