• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mendersoftware / mender-mcu / 2180234949

26 Nov 2025 08:37AM UTC coverage: 60.837%. Remained the same
2180234949

Pull #209

gitlab-ci

mender-test-bot
chore(main): release 0.10.0

Signed-off-by: mender-test-bot <mender@northern.tech>
Pull Request #209: chore(main): release 0.10.0

2456 of 4037 relevant lines covered (60.84%)

70.49 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

70.83
/src/core/artifact-download.c
1
/**
2
 * @file      artifact-download.c
3
 * @brief     Mender artifact download implementation
4
 *
5
 * Copyright joelguittet and mender-mcu-client contributors
6
 * Copyright Northern.tech AS
7
 *
8
 * Licensed under the Apache License, Version 2.0 (the "License");
9
 * you may not use this file except in compliance with the License.
10
 * You may obtain a copy of the License at
11
 *
12
 *     http://www.apache.org/licenses/LICENSE-2.0
13
 *
14
 * Unless required by applicable law or agreed to in writing, software
15
 * distributed under the License is distributed on an "AS IS" BASIS,
16
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17
 * See the License for the specific language governing permissions and
18
 * limitations under the License.
19
 */
20

21
#include "api.h"
22
#include "artifact.h"
23
#include "artifact-download.h"
24
#include "artifact-download-data.h"
25
#include "error-counters.h"
26
#include "http.h"
27
#include "log.h"
28

29
static mender_err_t mender_download_artifact_callback(mender_http_client_event_t       event,
30
                                                      void                            *data,
31
                                                      size_t                           data_length,
32
                                                      mender_artifact_download_data_t *dl_data);
33

34
mender_err_t
35
mender_download_artifact(const char               *uri,
12✔
36
                         mender_deployment_data_t *deployment_data,
37
                         mender_update_module_t  **update_module,
38
                         mender_artifact_ctx_t   **artifact_ctx) {
39
    assert(NULL != uri);
12✔
40
    assert(NULL != deployment_data);
12✔
41
    assert(NULL != update_module);
12✔
42

43
    mender_err_t ret;
44
    int          status = 0;
12✔
45

46
    mender_artifact_download_data_t dl_data = {
12✔
47
        .deployment                 = deployment_data,
48
        .artifact_download_callback = &mender_download_artifact_callback,
49
        .ret                        = MENDER_OK,
50
    };
51

52
    /* Perform HTTP request */
53
    ret = mender_http_artifact_download(uri, &dl_data, &status);
12✔
54
    if (MENDER_OK == mender_artifact_get_ctx(artifact_ctx)) {
12✔
55
        /* Download done (one way or another), we can drop the auxiliary buffers
56
           from the artifact context. */
57
        assert(NULL != *artifact_ctx);
12✔
58
        mender_artifact_compact_ctx(*artifact_ctx);
12✔
59
    }
60

61
    if (MENDER_OK != ret) {
12✔
62
        mender_log_error("Unable to perform HTTP request");
×
63
        mender_err_count_net_inc();
×
64
        return ret;
×
65
    }
66

67
    /* Treatment depending of the status */
68
    if (200 == status) {
12✔
69
        /* Nothing to do */
70
        *update_module = dl_data.update_module;
11✔
71
        return MENDER_OK;
11✔
72
    } else {
73
        mender_api_print_response_error(NULL, status);
1✔
74
        return MENDER_FAIL;
1✔
75
    }
76
}
77

78
static mender_err_t
79
mender_download_artifact_callback(mender_http_client_event_t event, void *data, size_t data_length, mender_artifact_download_data_t *dl_data) {
282✔
80
    mender_err_t ret = MENDER_OK;
282✔
81

82
    mender_artifact_ctx_t *mender_artifact_ctx = NULL;
282✔
83

84
    /* Treatment depending of the event */
85
    switch (event) {
282✔
86
        case MENDER_HTTP_EVENT_CONNECTED:
12✔
87
            /* Create new artifact context */
88
            if (NULL == (mender_artifact_ctx = mender_artifact_create_ctx(2 * MENDER_ARTIFACT_STREAM_BLOCK_SIZE + mender_http_recv_buf_length))) {
12✔
89
                mender_log_error("Unable to create artifact context");
×
90
                return MENDER_FAIL;
×
91
            }
92
            break;
12✔
93
        case MENDER_HTTP_EVENT_DATA_RECEIVED:
259✔
94
            /* Check input data */
95
            if ((NULL == data) || (0 == data_length)) {
259✔
96
                mender_log_error("Invalid data received");
×
97
                return MENDER_FAIL;
×
98
            }
99

100
            /* Check artifact context */
101
            if (MENDER_OK != mender_artifact_get_ctx(&mender_artifact_ctx)) {
259✔
102
                mender_log_error("Unable to get artifact context");
×
103
                return MENDER_FAIL;
×
104
            }
105
            assert(NULL != mender_artifact_ctx);
259✔
106

107
            /* Parse input data */
108
            if (MENDER_OK != (ret = mender_artifact_process_data(mender_artifact_ctx, data, data_length, dl_data))) {
259✔
109
                mender_log_error("Unable to process data");
1✔
110
                return ret;
1✔
111
            }
112
            break;
258✔
113
        case MENDER_HTTP_EVENT_DISCONNECTED:
11✔
114
            break;
11✔
115
        case MENDER_HTTP_EVENT_ERROR:
×
116
            /* Downloading the artifact fails */
117
            mender_log_error("An error occurred");
×
118
            return MENDER_FAIL;
×
119
        default:
×
120
            /* Should not occur */
121
            return MENDER_FAIL;
×
122
    }
123

124
    return ret;
281✔
125
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc