Skip to content

Commit

Permalink
net: lib: downloader: Formatting and code indentation
Browse files Browse the repository at this point in the history
Cleanup formatting and some code indentation.

Co-authored-by: Andreas Moltumyr <andreas.moltumyr@nordicsemi.no>
Signed-off-by: Eivind Jølsgard <eivind.jolsgard@nordicsemi.no>
  • Loading branch information
eivindj-nordic and anhmolt committed Feb 11, 2025
1 parent 0ee891c commit 2e20e9c
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 28 deletions.
4 changes: 2 additions & 2 deletions include/net/downloader.h
Original file line number Diff line number Diff line change
Expand Up @@ -198,9 +198,9 @@ struct downloader_host_cfg {
const char *proxy_uri;
/**
* Maximum number of HTTP redirects.
* Use 0 to set default value of CONFIG_DOWNLOADER_MAX_REDIRECTS.
* Use 0 to set the value of CONFIG_DOWNLOADER_MAX_REDIRECTS.
*/
int redirects_max;
uint8_t redirects_max;
};

/**
Expand Down
3 changes: 2 additions & 1 deletion subsys/net/lib/downloader/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ config DOWNLOADER_MAX_FILENAME_SIZE
default 255

config DOWNLOADER_MAX_REDIRECTS
int "Default maximum number of redirects before download is aborted"
int "Number of redirects before download is aborted"
range 0 255
default 10
help
The maximum number of redirects can be overwritten in the host config.
Expand Down
44 changes: 20 additions & 24 deletions subsys/net/lib/downloader/src/transports/http.c
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ struct transport_params_http {
/** Request new data */
bool new_data_req;
/** Redirect retries */
uint32_t redirects;

uint8_t redirects;
};

BUILD_ASSERT(CONFIG_DOWNLOADER_TRANSPORT_PARAMS_SIZE >= sizeof(struct transport_params_http));
Expand Down Expand Up @@ -148,22 +147,21 @@ static int http_get_request_send(struct downloader *dl)
/* nRF91 series has a limitation of decoding ~2k of data at once when using TLS */
tls_force_range = (http->sock.proto == IPPROTO_TLS_1_2 && !dl->host_cfg.set_native_tls &&
IS_ENABLED(CONFIG_SOC_SERIES_NRF91X));

if (dl->host_cfg.range_override) {
if (tls_force_range && dl->host_cfg.range_override > (TLS_RANGE_MAX)) {
if (tls_force_range) {
if (dl->host_cfg.range_override > TLS_RANGE_MAX) {
LOG_WRN("Range override > TLS max range, setting to TLS max range");
dl->host_cfg.range_override = (TLS_RANGE_MAX);
dl->host_cfg.range_override = TLS_RANGE_MAX;
} else if (dl->host_cfg.range_override == 0) {
dl->host_cfg.range_override = TLS_RANGE_MAX;
}
} else if (tls_force_range) {
dl->host_cfg.range_override = TLS_RANGE_MAX;
}

if (dl->host_cfg.range_override) {
off = dl->progress + dl->host_cfg.range_override - 1;

if (dl->file_size && (off > dl->file_size - 1)) {
if (dl->file_size) {
/* Don't request bytes past the end of file */
off = dl->file_size - 1;
off = MIN(off, dl->file_size - 1);
}

len = snprintf(dl->cfg.buf, dl->cfg.buf_size, HTTP_GET_RANGE, dl->file,
Expand Down Expand Up @@ -437,24 +435,22 @@ static int http_parse(struct downloader *dl, size_t len)
}
}

/* Have we received a whole fragment or the whole file? */
if (dl->progress + len != dl->file_size) {
if (http->ranged) {
http->ranged_progress += len;
if (http->ranged_progress < (dl->host_cfg.range_override
? dl->host_cfg.range_override
: TLS_RANGE_MAX - 1)) {
/* Ranged query: read until a full fragment */
return len;
}
if (dl->progress + len == dl->file_size) {
/* A full file has been received */
http->new_data_req = true;
return len;
}

if (http->ranged) {
http->ranged_progress += len;
if (http->ranged_progress < dl->host_cfg.range_override) {
/* Ranged query: read until a full fragment is received */
} else {
/* Non-ranged query: just keep on reading, ignore fragment size */
return len;
/* Ranged query: request next fragment */
http->new_data_req = true;
}
}

/* Either we have a full file, or we need to request a next fragment */
http->new_data_req = true;
return len;
}

Expand Down
1 change: 0 additions & 1 deletion tests/subsys/net/lib/downloader/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -962,7 +962,6 @@ static ssize_t z_impl_zsock_recvfrom_http_redirect_and_close(

memcpy(buf, HTTP_HDR_REDIRECT, strlen(HTTP_HDR_REDIRECT));
return strlen(HTTP_HDR_REDIRECT);
return 0;
}

int z_impl_zsock_socket_http_then_https(int family, int type, int proto)
Expand Down

0 comments on commit 2e20e9c

Please sign in to comment.