Skip to contentSkip to conversation

net/lwip: wget: put server_name and port into wget_ctx

PATCH Superseded Adriano Cordova 3 participants 3 messages Nov 6, 2024 – Nov 8, 2024 Networking

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 6/7 net/lwip: wget: put server_name and port into wget_ctx

Currently server_name and port are local variables in wget_loop. This commit puts them inside ctx, so that they are accessible from the http callbacks.

---
 net/lwip/wget.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/lwip/wget.c +4 -4
index b495ebd1aa..4add520045 100644
@@ -23,6 +23,8 @@ enum done_state {
 };
 
 struct wget_ctx {
+	char server_name[SERVER_NAME_SIZE];
+	u16 port;
 	char *path;
 	ulong daddr;
 	ulong saved_daddr;
@@ -209,13 +211,11 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
 
 static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
 {
-	char server_name[SERVER_NAME_SIZE];
 	httpc_connection_t conn;
 	httpc_state_t *state;
 	struct netif *netif;
 	struct wget_ctx ctx;
 	char *path;
-	u16 port;
 
 	ctx.daddr = dst_addr;
 	ctx.saved_daddr = dst_addr;
@@ -224,7 +224,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
 	ctx.prevsize = 0;
 	ctx.start_time = 0;
 
-	if (parse_url(uri, server_name, &port, &path))
+	if (parse_url(uri, ctx.server_name, &ctx.port, &path))
 		return CMD_RET_USAGE;
 
 	netif = net_lwip_new_netif(udev);
@@ -234,7 +234,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
 	memset(&conn, 0, sizeof(conn));
 	conn.result_fn = httpc_result_cb;
 	ctx.path = path;
-	if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
+	if (httpc_get_file_dns(ctx.server_name, ctx.port, path, &conn, httpc_recv_cb,
 			       &ctx, &state)) {
 		net_lwip_remove_netif(netif);
 		return CMD_RET_FAILURE;
Signature · 1 line
2.43.0
Reviewed-by on v1 6/7
#1 lore raw
Quoted 46 lines · Adriano Cordova

Currently server_name and port are local variables in wget_loop. This commit puts them inside ctx, so that they are accessible from the http callbacks.

---
 net/lwip/wget.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/lwip/wget.c +3 -3
index b495ebd1aa..4add520045 100644
@@ -23,6 +23,8 @@ enum done_state {
 };
 
 struct wget_ctx {
+	char server_name[SERVER_NAME_SIZE];
+	u16 port;
 	char *path;
 	ulong daddr;
 	ulong saved_daddr;
@@ -209,13 +211,11 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
 
 static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
 {
-	char server_name[SERVER_NAME_SIZE];
 	httpc_connection_t conn;
 	httpc_state_t *state;
 	struct netif *netif;
 	struct wget_ctx ctx;
 	char *path;
-	u16 port;
 
 	ctx.daddr = dst_addr;
 	ctx.saved_daddr = dst_addr;
@@ -224,7 +224,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
 	ctx.prevsize = 0;
 	ctx.start_time = 0;
 
-	if (parse_url(uri, server_name, &port, &path))
+	if (parse_url(uri, ctx.server_name, &ctx.port, &path))
 		return CMD_RET_USAGE;
 
 	netif = net_lwip_new_netif(udev);

net/lwip/wget.c static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) · line 240

Quoted 8 lines
net/lwip/wget.c +1 -1
@@ -234,7 +234,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
 	memset(&conn, 0, sizeof(conn));
 	conn.result_fn = httpc_result_cb;
 	ctx.path = path;
-	if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
+	if (httpc_get_file_dns(ctx.server_name, ctx.port, path, &conn, httpc_recv_cb,
 			       &ctx, &state)) {
 		net_lwip_remove_netif(netif);
 		return CMD_RET_FAILURE;

Thanks,

Signature · 1 line
Jerome
#2 lore raw
Quoted 17 lines · Jerome Forissier
Quoted 16 lines · Adriano Cordova

Currently server_name and port are local variables in wget_loop. This commit puts them inside ctx, so that they are accessible from the http callbacks.

---
  net/lwip/wget.c | 8 ++++----
  1 file changed, 4 insertions(+), 4 deletions(-)
net/lwip/wget.c +0 -0
index b495ebd1aa..4add520045 100644
@@ -23,6 +23,8 @@ enum done_state {
  };
 
Quoted 2 lines

net/lwip/wget.c enum done_state { · line 26

Quoted 2 lines
net/lwip/wget.c +1 -0
  struct wget_ctx {
+	char server_name[SERVER_NAME_SIZE];

cf.
[PATCH 1/1] net: lwip/wget: correct SERVER_NAME_SIZE
https://lists.denx.de/pipermail/u-boot/2024-November/571167.html

Quoted 40 lines
Quoted 28 lines
net/lwip/wget.c +2 -3
+	u16 port;
  	char *path;
  	ulong daddr;
  	ulong saved_daddr;
@@ -209,13 +211,11 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result,
 
  static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
  {
-	char server_name[SERVER_NAME_SIZE];
  	httpc_connection_t conn;
  	httpc_state_t *state;
  	struct netif *netif;
  	struct wget_ctx ctx;
  	char *path;
-	u16 port;
 
  	ctx.daddr = dst_addr;
  	ctx.saved_daddr = dst_addr;
@@ -224,7 +224,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
  	ctx.prevsize = 0;
  	ctx.start_time = 0;
 
-	if (parse_url(uri, server_name, &port, &path))
+	if (parse_url(uri, ctx.server_name, &ctx.port, &path))
  		return CMD_RET_USAGE;
 
  	netif = net_lwip_new_netif(udev);

net/lwip/wget.c static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) · line 240

Quoted 8 lines
net/lwip/wget.c +1 -1
@@ -234,7 +234,7 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri)
  	memset(&conn, 0, sizeof(conn));
  	conn.result_fn = httpc_result_cb;
  	ctx.path = path;
-	if (httpc_get_file_dns(server_name, port, path, &conn, httpc_recv_cb,
+	if (httpc_get_file_dns(ctx.server_name, ctx.port, path, &conn, httpc_recv_cb,
  			       &ctx, &state)) {
  		net_lwip_remove_netif(netif);
  		return CMD_RET_FAILURE;

Thanks,