All of lore.kernel.org
 help / color / mirror / Atom feed
From: Ilias Apalodimas <ilias.apalodimas@linaro.org>
To: Maxim Uvarov <maxim.uvarov@linaro.org>
Cc: u-boot@lists.denx.de, pbrobinson@gmail.com,
	joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com,
	goldsimon@gmx.de
Subject: Re: [PATCHv8 06/15] net/lwip: implement wget cmd
Date: Wed, 13 Sep 2023 09:25:56 +0300	[thread overview]
Message-ID: <ZQFV9DcSKIDAwx4I@hera> (raw)
In-Reply-To: <20230908135320.7066-7-maxim.uvarov@linaro.org>

>  4 files changed, 128 insertions(+)
>  create mode 100644 net/lwip/apps/http/Makefile
>  create mode 100644 net/lwip/apps/http/lwip-wget.c
>
> diff --git a/include/net/lwip.h b/include/net/lwip.h
> index c9e2982a78..85f08343fd 100644
> --- a/include/net/lwip.h
> +++ b/include/net/lwip.h
> @@ -28,6 +28,7 @@ int ulwip_dns(char *name, char *varname);
>   * Returns: 0 if success
>   *         Other value < 0, if error
>  */
> +int ulwip_dhcp(void);

This seems unrelated to wget changes

[...]

> +// SPDX-License-Identifier: GPL-2.0
> +
> +/*
> + * (C) Copyright 2023 Linaro Ltd. <maxim.uvarov@linaro.org>
> + */
> +
> +#include <common.h>
> +#include <command.h>
> +#include <console.h>
> +#include <vsprintf.h>
> +
> +#include "http_client.h"
> +#include <net/ulwip.h>
> +
> +static ulong daddr;
> +static httpc_connection_t settings;
> +
> +#define SERVER_NAME_SIZE 200
> +#define HTTP_PORT_DEFAULT 80
> +
> +static err_t httpc_recv(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf,
> +			err_t unused_err)
> +{
> +	struct pbuf *buf;
> +
> +	if (!pbuf)
> +		return ERR_BUF;
> +
> +	for (buf = pbuf; buf != NULL; buf = buf->next) {
> +		memcpy((void *)daddr, buf->payload, buf->len);
> +		log_debug("downloaded chunk size %d, to addr 0x%lx\n",
> +			  buf->len, daddr);
> +		daddr += buf->len;
> +	}
> +
> +	altcp_recved(pcb, pbuf->tot_len);
> +	pbuf_free(pbuf);
> +	return ERR_OK;
> +}
> +
> +static void httpc_result(void *arg, httpc_result_t httpc_result, u32_t rx_content_len,
> +			 u32_t srv_res, err_t err)
> +{
> +	if (httpc_result == HTTPC_RESULT_OK) {
> +		log_info("\n%d bytes successfully downloaded.\n", rx_content_len);
> +		env_set_hex("filesize", rx_content_len);
> +		ulwip_exit(0);
> +	} else {
> +		log_err("\nhttp eroror: %d\n", httpc_result);
> +		ulwip_exit(-1);
> +	}
> +}
> +
> +/* http://hostname:port/url */

The format doesn't expect a port (for now we can change that once we add
https)

> +static int parse_url(char *url, char *host, u16 *port)
> +{
> +	char *p, *pp;
> +
> +	p = strstr(url, "http://");
> +	if (!p)
> +		return -1;
> +
> +	p += strlen("http://");
> +
> +	/* parse hostname */
> +	pp = strchr(p, '/');
> +	if (!pp) {
> +		return -2;

-1, -2 -3 etc should be mapped to proper ERRNOs

> +	}
> +
> +	if (pp - p >= SERVER_NAME_SIZE)

Can you change this to p + SERVER_NAME_SIZE >= pp ?

> +		return -3;
> +
> +	memcpy(host, p, pp - p);
> +	host[pp - p + 1] = '\0';
> +	*port = HTTP_PORT_DEFAULT;
> +
> +	return 0;
> +}
> +
> +int ulwip_wget(ulong addr, char *url)
> +{
> +	err_t err;
> +	u16 port;
> +	char server_name[SERVER_NAME_SIZE];
> +	httpc_state_t *connection;
> +
> +	daddr = addr;
> +
> +	err = parse_url(url, server_name, &port);
> +	if (err)
> +		return -ENOENT;
> +
> +	log_info("downloading %s to addr 0x%lx\n", url, addr);
> +	memset(&settings, 0, sizeof(settings));
> +	settings.result_fn = httpc_result;
> +	err = httpc_get_file_dns(server_name, port, url, &settings,
> +				 httpc_recv, NULL,  &connection);
> +	if (err != ERR_OK)
> +		return -EPERM;
> +
> +	if (env_set_hex("fileaddr", addr))
> +		return -EACCES;
> +
> +	return 0;
> +}
> --
> 2.30.2
>

Thanks
/Ilias

  reply	other threads:[~2023-09-13  6:26 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-09-08 13:53 [PATCHv8 00/15] net/lwip: add lwip library for the network stack Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 01/15] net/lwip: add doc/develop/net_lwip.rst Maxim Uvarov
2023-09-12  7:40   ` Ilias Apalodimas
2023-09-08 13:53 ` [PATCHv8 02/15] net/lwip: integrate lwIP library Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 03/15] net/lwip: implement dns cmd Maxim Uvarov
2023-09-13  5:56   ` Ilias Apalodimas
2023-09-13  8:32     ` Simon Goldschmidt
2023-09-13 13:46       ` Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 04/15] net/lwip: implement dhcp cmd Maxim Uvarov
2023-09-13  6:07   ` Ilias Apalodimas
2023-09-13  8:35     ` Simon Goldschmidt
2023-09-08 13:53 ` [PATCHv8 05/15] net/lwip: implement tftp cmd Maxim Uvarov
2023-09-13  6:15   ` Ilias Apalodimas
2023-09-13  8:38     ` Simon Goldschmidt
2023-09-13 13:38       ` Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 06/15] net/lwip: implement wget cmd Maxim Uvarov
2023-09-13  6:25   ` Ilias Apalodimas [this message]
2023-09-08 13:53 ` [PATCHv8 07/15] net/lwip: implement ping cmd Maxim Uvarov
2023-09-13  6:28   ` Ilias Apalodimas
2023-09-08 13:53 ` [PATCHv8 08/15] net/lwip: add lwIP configuration Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 09/15] net/lwip: implement lwIP port to U-Boot Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 10/15] net/lwip: update .gitignore with lwIP Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 11/15] net/lwip: connection between cmd and lwip apps Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 12/15] net/lwip: replace original net commands with lwip Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 13/15] net/lwip: split net.h to net.h, arp.h and eth.h Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 14/15] net/lwip: drop old net/wget Maxim Uvarov
2023-09-08 13:53 ` [PATCHv8 15/15] net/lwip/wget add port selection Maxim Uvarov
2023-09-13  6:30   ` Ilias Apalodimas
2023-09-08 13:59 ` [PATCHv8 00/15] net/lwip: add lwip library for the network stack Tom Rini
2023-09-12 11:41   ` Maxim Uvarov
2023-09-12 19:26     ` Simon Glass
2023-09-13  7:31       ` Maxim Uvarov
2023-09-13  7:53         ` Ilias Apalodimas
2023-09-13  8:43           ` Simon Goldschmidt
2023-09-13 10:06             ` Peter Robinson
2023-09-13 13:14               ` Tom Rini
2023-09-13 13:34                 ` Maxim Uvarov
2023-09-21 16:29                   ` Simon Glass
2023-09-22 10:56                     ` Simon Goldschmidt
2023-09-22 16:13                       ` Tom Rini

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ZQFV9DcSKIDAwx4I@hera \
    --to=ilias.apalodimas@linaro.org \
    --cc=goldsimon@gmx.de \
    --cc=joe.hershberger@ni.com \
    --cc=maxim.uvarov@linaro.org \
    --cc=pbrobinson@gmail.com \
    --cc=rfried.dev@gmail.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.