Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
arm_uc_http_socket.c
00001 // ---------------------------------------------------------------------------- 00002 // Copyright 2016-2017 ARM Ltd. 00003 // 00004 // SPDX-License-Identifier: Apache-2.0 00005 // 00006 // Licensed under the Apache License, Version 2.0 (the "License"); 00007 // you may not use this file except in compliance with the License. 00008 // You may obtain a copy of the License at 00009 // 00010 // http://www.apache.org/licenses/LICENSE-2.0 00011 // 00012 // Unless required by applicable law or agreed to in writing, software 00013 // distributed under the License is distributed on an "AS IS" BASIS, 00014 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 // See the License for the specific language governing permissions and 00016 // limitations under the License. 00017 // ---------------------------------------------------------------------------- 00018 00019 #include "update-client-common/arm_uc_config.h" 00020 00021 #if defined(ARM_UC_FEATURE_FW_SOURCE_HTTP) && (ARM_UC_FEATURE_FW_SOURCE_HTTP == 1) 00022 00023 #include "arm_uc_http_socket_private.h" 00024 00025 #include "update-client-source-http-socket/arm_uc_http_socket.h" 00026 #include "update-client-common/arm_uc_common.h" 00027 00028 00029 /*****************************************************************************/ 00030 /* Public Function */ 00031 /*****************************************************************************/ 00032 00033 /** 00034 * @brief Initialize Http module. 00035 * @details Function pointer to event handler is passed as argument. 00036 * 00037 * @param context Struct holding all global variables. 00038 * @param handler Event handler for signaling when each operation is complete. 00039 * @return Error code. 00040 */ 00041 arm_uc_error_t ARM_UCS_HttpSocket_Initialize(arm_uc_http_socket_context_t *context, 00042 ARM_UCS_HttpEvent_t handler) 00043 { 00044 return arm_uc_http_socket_initialize(context, handler); 00045 } 00046 00047 /** 00048 * @brief Resets HTTP socket to uninitialized state and clears memory struct. 00049 * @details HTTP sockets must be initialized again before use. 00050 * @return Error code. 00051 */ 00052 arm_uc_error_t ARM_UCS_HttpSocket_Terminate(void) 00053 { 00054 return arm_uc_http_socket_terminate(); 00055 } 00056 00057 /** 00058 * @brief Get hash for resource at URI. 00059 * @details Store hash in provided buffer. Enclosing "" and '\0' are removed. 00060 * 00061 * Event generated: EVENT_HASH 00062 * 00063 * @param uri Pointer to struct with resource location. 00064 * @param buffer Pointer to structure with buffer location, maxSize, and size. 00065 * @return Error code. 00066 */ 00067 arm_uc_error_t ARM_UCS_HttpSocket_GetHash(arm_uc_uri_t *uri, 00068 arm_uc_buffer_t *buffer) 00069 { 00070 return arm_uc_http_socket_get(uri, buffer, UINT32_MAX, RQST_TYPE_HASH_ETAG); 00071 } 00072 00073 /** 00074 * @brief Get date for resource at URI. 00075 * @details Store Last-Modified data in provided buffer. Enclosing "" and '\0' are removed. 00076 * 00077 * Event generated: EVENT_DATE 00078 * 00079 * @param uri Pointer to struct with resource location. 00080 * @param buffer Pointer to structure with buffer location, maxSize, and size. 00081 * @return Error code. 00082 */ 00083 arm_uc_error_t ARM_UCS_HttpSocket_GetDate(arm_uc_uri_t *uri, 00084 arm_uc_buffer_t *buffer) 00085 { 00086 return arm_uc_http_socket_get(uri, buffer, UINT32_MAX, RQST_TYPE_HASH_DATE); 00087 } 00088 00089 /** 00090 * @brief Get full resource at URI. 00091 * @details Download resource at URI and store in provided buffer. 00092 * If the provided buffer is not big enough to contain the whole resource 00093 * what can fit in the buffer will be downloaded. 00094 * The user can then use GetFragment to download the rest. 00095 00096 * Events generated: EVENT_DOWNLOAD_PENDING if there is still data to 00097 * download and EVENT_DOWNLOAD_DONE if the file is completely downloaded. 00098 * 00099 * @param uri Pointer to structure with resource location. 00100 * @param buffer Pointer to structure with buffer location, maxSize, and size. 00101 * @return Error code. 00102 */ 00103 arm_uc_error_t ARM_UCS_HttpSocket_GetFile(arm_uc_uri_t *uri, 00104 arm_uc_buffer_t *buffer) 00105 { 00106 return arm_uc_http_socket_get(uri, buffer, UINT32_MAX, RQST_TYPE_GET_FILE); 00107 } 00108 00109 /** 00110 * @brief Get partial resource at URI. 00111 * @details Download resource at URI from given offset and store in buffer. 00112 * 00113 * The buffer maxSize determines how big a fragment to download. If the 00114 * buffer is larger than the requested fragment (offset to end-of-file) 00115 * the buffer size is set to indicate the number of available bytes. 00116 * 00117 * Events generated: EVENT_DOWNLOAD_PENDING if there is still data to 00118 * download and EVENT_DOWNLOAD_DONE if the file is completely downloaded. 00119 * 00120 * @param uri Pointer to structure with resource location. 00121 * @param buffer Pointer to structure with buffer location, maxSize, and size. 00122 * @param offset Offset in resource to begin download from. 00123 * @return Error code. 00124 */ 00125 arm_uc_error_t ARM_UCS_HttpSocket_GetFragment(arm_uc_uri_t *uri, 00126 arm_uc_buffer_t *buffer, 00127 uint32_t offset) 00128 { 00129 return arm_uc_http_socket_get(uri, buffer, offset, RQST_TYPE_GET_FRAG); 00130 } 00131 00132 #endif // ARM_UC_FEATURE_FW_SOURCE_HTTP 00133
Generated on Mon Aug 29 2022 19:53:38 by
