Commit Graph

134 Commits

Author SHA1 Message Date
simbit18
85988dc77f Fix nuttx coding style
Remove TABs
2023-08-01 23:10:32 -07:00
chao an
4d79a5cbaf add initial cmake build system
Co-authored-by: Daniel Agar <daniel@agar.ca>
Signed-off-by: chao an <anchao@xiaomi.com>
2023-07-08 13:52:02 +08:00
Xiang Xiao
73701cd7cd Replace all strncpy with strlcpy
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 21:35:16 +03:00
Xiang Xiao
7c37421266 Replace all sprintf with snprintf
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2023-05-08 21:35:16 +03:00
simbit18
79b72c0302 apps/netutils/webclient/Make.defs: fix nxstyle
Add missing first line header
2023-03-20 14:17:07 +01:00
Andrés Sánchez Pascual
03909627b9 add symbols in webclient kconfig
Signed-off-by: Andrés Sánchez Pascual <tito97_sp@hotmail.com>
2022-11-12 20:27:53 +08:00
Fotis Panagiotopoulos
390f1e2c60 Fixed compiler warning in webclient. 2022-10-27 21:20:01 +08:00
Fotis Panagiotopoulos
d251d12f6f Fixed compiler warnings. 2022-10-24 12:03:44 +08:00
Xiang Xiao
893387b2c5 Fix the minor style issue
Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-16 19:07:16 +02:00
Xiang Xiao
4941182cc6 Make.defs: Change "ifeq ($(XXX),y)" to "ifneq ($(XXX),)
to support the tristate option correctly and unify the usage

Signed-off-by: Xiang Xiao <xiaoxiang@xiaomi.com>
2022-10-16 14:59:08 +02:00
weizihan
9dd3055014 apps: Fix the bug that setsockopt didn't check return value
Signed-off-by: weizihan <weizihan@xiaomi.com>
2022-08-17 22:50:56 +08:00
YAMAMOTO Takashi
fe109998c9 webclient_get_tunnel: A comment about how to dispose the returned "conn" 2022-06-20 13:56:53 +08:00
YAMAMOTO Takashi
d435858c53 webclient: Export a few ops on webclient_conn_s
* Make webclient_conn_s self-contained so that it can be
  used without webclient_context.

* Add missing FAR.
2022-06-20 13:56:53 +08:00
YAMAMOTO Takashi
fca5b186b1 webclient: Make webclient_get_tunnel returns void
As it does never fail.
2022-06-20 13:56:53 +08:00
YAMAMOTO Takashi
eece4a5ca0 webclient_abort: Fix a resource leak for the tunneling case 2022-06-17 08:35:59 +03:00
YAMAMOTO Takashi
159ca00752 webclient: Allow users to specify extra headers for proxy
My primary motivation at this point is to use it for basic proxy auth.
(specify "Proxy-Authorization" header)
But there can be other use cases for proxy-specific extra headers.

If/when we want to support other non-trivial auth methods, probably
a callback-based mechanism will be necessary. But at this point,
this serves my purpose well.
2022-06-15 20:40:53 +08:00
YAMAMOTO Takashi
610b04fa97 webclient: Clear WGET_FLAG_GOT_CONTENT_LENGTH for each request
Otherwise, a stale value might be used after a redirection.
2022-06-07 15:09:11 +03:00
YAMAMOTO Takashi
065a130bc8 webclient: Be a bit strict on Location header
* Record Location header explicitly

* Bail out / warn on unexpected cases
2022-06-07 15:09:11 +03:00
YAMAMOTO Takashi
0c4c811434 webcilent: Fix a buffer overrun on a malformed status line 2022-06-07 15:09:11 +03:00
YAMAMOTO Takashi
a563014646 webclient: make webclient_get_tunnel assert http_status 2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
a696c8945e webclient: Don't forget to check http status before webclient_get_tunnel 2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
3f4e723ff7 webclient: dispose the response body by default
Instead of a NULL dereference.

This fixes a crash on CONNECT failure when trying to proxy https.
2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
dbee240869 webclient.c: Fix the placement of "Public Function" banner 2022-06-03 16:33:09 +08:00
YAMAMOTO Takashi
c116f8b673 webclient: Add https proxy (https over http) support
Use a separate webclient_context for tunnel establishment.

I chose this way (instead of having tunnelling steps in
the state machine of a single webclient_context) because
I want to allow tunnelling of non-HTTP protocols sooner or later.
2022-06-02 12:45:41 +08:00
YAMAMOTO Takashi
a95dd30f0e webclient: Add tunneling support
Add a primitive API for tunnel establishment.
(WEBCLIENT_FLAG_TUNNEL and webclient_get_tunnel)

I plan to use this to implement https proxy support.
That is, the primary user will be webclient itself.
2022-06-02 12:45:41 +08:00
YAMAMOTO Takashi
a46b144ab1 webclient: Remove an extra slash for proxy 2022-06-01 22:42:12 +08:00
YAMAMOTO Takashi
f7b0ad4b74 webclient: Require a port in proxy string 2022-05-24 22:42:54 +08:00
YAMAMOTO Takashi
4798f01449 webclient: Implement proxy
Only the very basic case (http over http) for now.
2022-05-24 22:42:54 +08:00
YAMAMOTO Takashi
4f4f4da526 webclient: Separate wget_target_s from wget_s
I plan to use the former for proxy settings.
2022-05-24 22:42:54 +08:00
YAMAMOTO Takashi
f2737a208c webclient: Remove a duplicated "Connection:" header
When making the following change, I haven't noticed that
g_httpuseragentfields contains a "Connection" header.

```
commit 092ce81444
Author: YAMAMOTO Takashi <yamamoto@midokura.com>
Date:   Mon Mar 7 09:30:23 2022 +0900

    webclient: Always use "connection: close" for HTTP 1.1 for now

    * This matches the HTTP 1.0 behavior.

    * Persistent connection doesn't make much sense with the current API.
```

It seems that some servers are not happy with the duplicated header
and ignore them. (and do the default keep-alive for HTTP 1.1)
eg. Azure Blob (global)
2022-03-08 11:52:35 +08:00
YAMAMOTO Takashi
8a5dc04be2 webclient: Remove an inappropriate comment (a copy-and-paste botch) 2022-03-08 11:52:28 +08:00
YAMAMOTO Takashi
44e80ac972 webclient: Implement chunked transfer (receiving side)
This is a requirement for HTTP 1.1.

Tested against:

* http://httpbin.org/stream/10

* Docker API
2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
092ce81444 webclient: Always use "connection: close" for HTTP 1.1 for now
* This matches the HTTP 1.0 behavior.

* Persistent connection doesn't make much sense with the current API.
2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
7949059ec2 webclient: Send HTTP 1.1 request if enabled 2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
3759da3d00 webclient: Add a parameter to specifiy protocol version 2022-03-08 09:39:55 +08:00
YAMAMOTO Takashi
78fb3bc240 webclient: handle EINTR in a few places 2021-09-14 14:39:29 +08:00
YAMAMOTO Takashi
23e0325698 webclient: check content-length
While it's better to use a reliable transport like
TLS with working close notify, it isn't always possible.
2021-08-16 09:47:44 -07:00
YAMAMOTO Takashi
bdae564c22 webclient: Add _s suffix to internal structures
To follow our coding standard.

I left the structures which is a part of the API for now.
(E.g. struct webclient_context)
2021-08-11 03:11:14 -07:00
YAMAMOTO Takashi
b8fd862965 webclient: Add some assertions on webclient_context state 2021-08-08 22:34:26 -07:00
YAMAMOTO Takashi
0bae950b63 webclient: Implement non-blocking I/O
* webclient_perform
    * Add a new flag to use non-blocking mode (WEBCLIENT_FLAG_NON_BLOCKING)
    * Implement restarting

* Add a few associated API functions
    * webclient_get_poll_info: get the descriptor info for poll/select
    * webclient_abort: abort the operation (instead of restarting)
2021-08-08 22:34:26 -07:00
Gustavo Henrique Nihei
a1026c9f23 netutils/webclient: Notify HTTP header data via dedicated callback
Signed-off-by: Gustavo Henrique Nihei <gustavo.nihei@espressif.com>
2021-07-23 11:28:26 -07:00
YAMAMOTO Takashi
ce2b9519a7 webclient: Add a way to specify timeout 2021-06-15 05:18:14 -05:00
Alin Jerpelea
ec339bc49a Makefiles: Gregory Nutt: update licenses to Apache
Gregory Nutt is the copyright holder for those files and he has submitted the
SGA as a result we can migrate the licenses to Apache.

Signed-off-by: Alin Jerpelea <alin.jerpelea@sony.com>
2021-06-07 21:35:33 -05:00
YAMAMOTO Takashi
95c9007668 webclient: Fix buffer overrun in wget_parsestatus
Similarly to the fix in wget_parseheaders.
But simply always bail out as i guess it's very rare to see
that long status line.

Tested with an aritifically small CONFIG_WEBCLIENT_MAXHTTPLINE=20,
which is smaller than "HTTP/1.1 301 Moved Permanently".
2021-05-16 11:32:47 -03:00
YAMAMOTO Takashi
b53375074b webclient.c: Fix buffer overrun in HTTP header parsing
* Detect a long header line which doesn't fit the buffer.

* If the header line in question doesn't seem important for us,
  just ignore it.

* Otherwise, bail out with -E2BIG.

The overrun was found by LLVM UBSan on macOS.

The following is an example of a long header line,
which doesn't fit the default CONFIG_WEBCLIENT_MAXHTTPLINE=200.
```
pacetanuki% curl -v https://www.midokura.com
:
:
< HTTP/2 200
< server: nginx
< date: Fri, 14 May 2021 02:16:24 GMT
< content-type: text/html; charset=UTF-8
< content-length: 131313
< x-powered-by: PHP/7.4.18
< link: <https://www.midokura.com/wp-json/>; rel="https://api.w.org/", <https://www.midokura.com/wp-json/wp/v2/pages/7>; rel="alternate"; type="application/json", <https://www.midokura.com/>; rel=shortlink
< x-powered-by: PleskLin
<
```
2021-05-16 11:32:47 -03:00
YAMAMOTO Takashi
eb1a99fdd6 webclient.c: Don't parse the status line as the first header line 2021-05-16 11:32:47 -03:00
YAMAMOTO Takashi
f17af21f9c webclient: Add a few ninfo in header parsing 2021-05-16 11:32:47 -03:00
Atsunori Saito
a12f9d967c netutils/webclient: Fixed socket descriptor leak. 2021-05-03 16:44:28 +09:00
YAMAMOTO Takashi
2d0a174cec webclient: 304 and 305 are not really redirects
Eg. The docker API sometimes returns 304 even for requests without etags.
https://docs.docker.com/engine/api/v1.40/#operation/ContainerStop
2021-04-07 06:44:16 -05:00
YAMAMOTO Takashi
15c65b23c7 netutils/webclient/webclient.c: Appease the latest nxstyle 2021-04-07 06:44:16 -05:00