From patchwork Tue Aug 22 09:36:14 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxim Uvarov X-Patchwork-Id: 715736 Delivered-To: patch@linaro.org Received: by 2002:adf:f747:0:b0:317:ecd7:513f with SMTP id z7csp164560wrp; Tue, 22 Aug 2023 02:41:08 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFq5LVQxVKL6du7b0A6d8L/Hy2qlsCrLe0xDXUHeVzkbMHfKngAh1iwJmRWJ5cQvEx3UJ6Z X-Received: by 2002:adf:e710:0:b0:317:5849:c2e0 with SMTP id c16-20020adfe710000000b003175849c2e0mr8568020wrm.9.1692697268644; Tue, 22 Aug 2023 02:41:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1692697268; cv=none; d=google.com; s=arc-20160816; b=SS9BYRA8UMREHLoWTmgw/08eEaSfjmaaXRJNnU1bfLrvZlKOvuR4GyECF7cU4kFqkM 4JrhGPf1Uuv7xvDHf024R2D27/prNHa0UKjhVxf30fa0VZOXR2cZeeqFIJQUC4L4oXoQ kTANz8ct0puZAja4bJltMZ/7pK3QFliJIinSsTu1RXsWOl9hTFR8kTHC82eQDMjpwLkq Ui4nlTPC7EzFTj8kGQcLAWHMpDEwy0sABqgG19BBGHLnhl8zuoCZduhde6dFkVWux3kM zCRBIWGY7BLjkyFApaU70LWJFnJHH8J61Lrf9zpBXsqNnDUaIfHu1+MN4ZC1hX6aJrkq Da8g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=dyVVhq97bTFV5m7BUfxOEu9H57jzS8dXbBxMhu+QAU0=; fh=7lWG6Sv/Sng5Xrn4qLGn/rvsS3kka2hgHZWjTWRbkb8=; b=Xrmi+Q38SoLrMbizAOar3kiju2ds6ENpODeKNupQZvF9/Fhj+HFl0eZAz59z8wPp8P fW4XtReTXvDiqLUK71bzZ6es0WKvqo2Oqo+GeTdGnoC4qZDOZogkbLV6OHCdt+jtyvE0 omNKBwfTBuE6eMMKQiWFV1b3ntsNsTXWHPH71/DfOrqncNUtP4WlEZFQCYt0O2q3XMSh /G6l5nSdctWgkL/gNul/6t8tz3fQ1geKjheSUKQJ2ZwCgKH0DTmy61tPuZBGvq5lAWS7 Py18I4rBkPaZfNbptL7kwgWRN85R8Zo6koXk3q/ND/o6rTSzwoTxPxCskPV89C59tTqe N/oA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ft1egoKL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id j3-20020a5d4483000000b00317dba828b3si4552659wrq.112.2023.08.22.02.41.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 02:41:08 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ft1egoKL; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5C8CE864C9; Tue, 22 Aug 2023 11:39:01 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="ft1egoKL"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id C302C86484; Tue, 22 Aug 2023 11:39:00 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-lj1-x232.google.com (mail-lj1-x232.google.com [IPv6:2a00:1450:4864:20::232]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 3206F864C2 for ; Tue, 22 Aug 2023 11:38:58 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=maxim.uvarov@linaro.org Received: by mail-lj1-x232.google.com with SMTP id 38308e7fff4ca-2bcb0b973a5so40105071fa.3 for ; Tue, 22 Aug 2023 02:38:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1692697137; x=1693301937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=dyVVhq97bTFV5m7BUfxOEu9H57jzS8dXbBxMhu+QAU0=; b=ft1egoKLQ05pYHtPt/hysUUaUvsITAfHIFKxACJcnAug+4edw7wMy2O09O46DecDW8 X5PpyoeJX9SsHO7LkMprEVoQ1K6uhAqwbkJuMy7v4u8ijeZ33ROoft2X+BReD98ojJHH kk7E7XOueQDLiIl0h8PILbdsa0uGD4W1+g6DWN7oro550/uXsGiXu33Djiu8A0ZI2egK KdP8i1KZAoKTFYmbmt1dTp6GTr04woH+8qjHYcMDp0ezPXpB8sFPa6Jn14I7HWW8x+aE KWSc2l8nv6vsnHDISp0iGljblyIwX2Ln1eJgq6HVY0HZGB7ArentM05ba+lDa2SH0Bmj nj8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692697137; x=1693301937; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=dyVVhq97bTFV5m7BUfxOEu9H57jzS8dXbBxMhu+QAU0=; b=JWXI4S2ce+Ae8GFH/1X9Tsg6IB4VXXcx3+h+cWGF56AaoWg4Xl5RpTn24rtXcjg4GP qmz6w0DBpaDk1EnJORGiYy+KYoO5jqQ2MYQfs2npXFRFvu/CC5/dRm+uoEHBlQOfVCbI qFC8Amwx3SWkApHqoPIZe2HEaiJy2K4+OjRxrBYc4T4Dm/ngO04srDjJ7fTGjDQl+YCC iTQukcHlqbyinmqqfYvmKMijCT/d8+eH5j07XtQHfCmIuBKgzOfsP946JYl9RU1hvXPc jjxWTLcW+06Htg4duYqtY/+V802cfRYsW9Sl6JIw72t2vlEMKrcjRSDEGIxFfP7JHIt6 QMWg== X-Gm-Message-State: AOJu0YygKA4aBX1hUQzQF/CpYcylVOUaGaXp5i6ZLCWBSePR3/1e0bz8 bk5UEcR/IX1hJLw7jxmAYtJFHYMxj4ddL1doTT0X6Q== X-Received: by 2002:a2e:8059:0:b0:2b6:ed80:15d1 with SMTP id p25-20020a2e8059000000b002b6ed8015d1mr6595090ljg.24.1692697137425; Tue, 22 Aug 2023 02:38:57 -0700 (PDT) Received: from localhost.localdomain ([45.82.14.220]) by smtp.gmail.com with ESMTPSA id i9-20020a2e8089000000b002b724063010sm2649637ljg.47.2023.08.22.02.38.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 22 Aug 2023 02:38:57 -0700 (PDT) From: Maxim Uvarov To: u-boot@lists.denx.de Cc: pbrobinson@gmail.com, ilias.apalodimas@linaro.org, joe.hershberger@ni.com, rfried.dev@gmail.com, trini@konsulko.com, goldsimon@gmx.de, Maxim Uvarov Subject: [PATCHv7 15/15] net/lwip/wget add port selection Date: Tue, 22 Aug 2023 15:36:14 +0600 Message-Id: <20230822093614.4717-16-maxim.uvarov@linaro.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20230822093614.4717-1-maxim.uvarov@linaro.org> References: <20230822093614.4717-1-maxim.uvarov@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean Allow to specify HTTP port instead of just using default for wget command. Signed-off-by: Maxim Uvarov --- include/net/lwip.h | 2 +- net/lwip/apps/http/lwip-wget.c | 45 +++++++++++++++++++++++++--------- 2 files changed, 35 insertions(+), 12 deletions(-) diff --git a/include/net/lwip.h b/include/net/lwip.h index aa82d71715..c66551a14c 100644 --- a/include/net/lwip.h +++ b/include/net/lwip.h @@ -54,7 +54,7 @@ int ulwip_tftp(ulong addr, const char *filename); * * * @addr: start address to download result - * @url: url in format http://host/url + * @url: url in format http://host[:port]/url * Returns: 0 for success, !0 if error */ int ulwip_wget(ulong addr, char *url); diff --git a/net/lwip/apps/http/lwip-wget.c b/net/lwip/apps/http/lwip-wget.c index a9bb29e156..01aa146b13 100644 --- a/net/lwip/apps/http/lwip-wget.c +++ b/net/lwip/apps/http/lwip-wget.c @@ -65,19 +65,42 @@ static int parse_url(char *url, char *host, u16 *port) p += strlen("http://"); /* parse hostname */ - pp = strchr(p, '/'); - if (!pp) { - printf("wrong url\n"); - return -2; + pp = strchr(p, ':'); + if (pp) { +#define PORT_STR_SIZE 5 + char portstr[PORT_STR_SIZE]; + + if (pp - p >= SERVER_NAME_SIZE) + return -2; + memcpy(host, p, pp - p); + host[pp - p + 1] = '\0'; + + p = pp + 1; + pp = strchr(p, '/'); + if (!pp) { + printf("wrong url\n"); + return -3; + } + + if (pp - p >= PORT_STR_SIZE) + return -4; + memcpy(portstr, p, pp - p); + portstr[pp - p] = '\0'; + *port = (u16)dectoul(portstr, NULL); + } else { + pp = strchr(p, '/'); + if (!pp) { + printf("wrong url\n"); + return -5; + } + + if (pp - p >= SERVER_NAME_SIZE) + return -6; + memcpy(host, p, pp - p); + host[pp - p + 1] = '\0'; + *port = HTTP_PORT_DEFAULT; } - if (pp - p >= SERVER_NAME_SIZE) - return -3; - - memcpy(host, p, pp - p); - host[pp - p + 1] = '\0'; - *port = HTTP_PORT_DEFAULT; - return 0; }