├── LICENSE ├── README.md ├── examples ├── GetStarted │ └── GetStarted.ino └── SimpleMQTT │ └── SimpleMQTT.ino ├── library.properties └── src ├── AzureIotHub.cpp ├── AzureIotHub.h ├── Esp32MQTTClient.cpp ├── Esp32MQTTClient.h └── az_iot ├── azureiotcerts.c ├── azureiotcerts.h ├── c-utility ├── inc │ └── azure_c_shared_utility │ │ ├── agenttime.h │ │ ├── base64.h │ │ ├── buffer_.h │ │ ├── condition.h │ │ ├── connection_string_parser.h │ │ ├── consolelogger.h │ │ ├── constbuffer.h │ │ ├── constmap.h │ │ ├── crt_abstractions.h │ │ ├── doublylinkedlist.h │ │ ├── gb_stdio.h │ │ ├── gb_time.h │ │ ├── gballoc.h │ │ ├── hmac.h │ │ ├── hmacsha256.h │ │ ├── http_proxy_io.h │ │ ├── httpapi.h │ │ ├── httpapiex.h │ │ ├── httpapiexsas.h │ │ ├── httpheaders.h │ │ ├── list.h │ │ ├── lock.h │ │ ├── macro_utils.h │ │ ├── map.h │ │ ├── optimize_size.h │ │ ├── optionhandler.h │ │ ├── platform.h │ │ ├── refcount.h │ │ ├── sastoken.h │ │ ├── sha-private.h │ │ ├── sha.h │ │ ├── shared_util_options.h │ │ ├── singlylinkedlist.h │ │ ├── socketio.h │ │ ├── string_tokenizer.h │ │ ├── string_tokenizer_types.h │ │ ├── strings.h │ │ ├── strings_types.h │ │ ├── tcpsocketconnection_c.h │ │ ├── threadapi.h │ │ ├── tickcounter.h │ │ ├── tls_config.h │ │ ├── tlsio.h │ │ ├── tlsio_mbedtls.h │ │ ├── tlsio_openssl.h │ │ ├── tlsio_options.h │ │ ├── umock_c_prod.h │ │ ├── uniqueid.h │ │ ├── urlencode.h │ │ ├── vector.h │ │ ├── vector_types.h │ │ ├── vector_types_internal.h │ │ ├── xio.h │ │ └── xlogging.h ├── pal │ ├── agenttime.c │ ├── dns_async.c │ ├── freertos │ │ ├── lock.c │ │ ├── threadapi.c │ │ └── tickcounter.c │ ├── generic │ │ └── refcount_os.h │ ├── inc │ │ ├── dns_async.h │ │ ├── sntp.h │ │ ├── sntp_os.h │ │ ├── socket_async.h │ │ ├── socket_async_os.h │ │ └── tlsio_pal.h │ ├── lwip │ │ ├── sntp_lwip.c │ │ └── sntp_os.h │ ├── socket_async.c │ ├── src │ │ ├── platform_openssl_compact.c │ │ └── tlsio_openssl_compact.c │ └── tlsio_options.c └── src │ ├── base64.c │ ├── buffer.c │ ├── connection_string_parser.c │ ├── consolelogger.c │ ├── constbuffer.c │ ├── constmap.c │ ├── crt_abstractions.c │ ├── doublylinkedlist.c │ ├── gb_stdio.c │ ├── gb_time.c │ ├── gballoc.c │ ├── hmac.c │ ├── hmacsha256.c │ ├── http_proxy_io.c │ ├── httpapiex.c │ ├── httpapiexsas.c │ ├── httpheaders.c │ ├── map.c │ ├── optionhandler.c │ ├── sastoken.c │ ├── sha1.c │ ├── sha224.c │ ├── sha384-512.c │ ├── singlylinkedlist.c │ ├── string_tokenizer.c │ ├── strings.c │ ├── urlencode.c │ ├── usha.c │ ├── vector.c │ ├── xio.c │ └── xlogging.c ├── iothub_client ├── inc │ ├── blob.h │ ├── iothub_client.h │ ├── iothub_client_authorization.h │ ├── iothub_client_dps_ll.h │ ├── iothub_client_ll.h │ ├── iothub_client_options.h │ ├── iothub_client_private.h │ ├── iothub_client_retry_control.h │ ├── iothub_client_version.h │ ├── iothub_message.h │ ├── iothub_transport_ll.h │ ├── iothubtransport.h │ ├── iothubtransport_mqtt_common.h │ └── iothubtransportmqtt.h └── src │ ├── blob.c │ ├── iothub_client.c │ ├── iothub_client_authorization.c │ ├── iothub_client_ll.c │ ├── iothub_client_retry_control.c │ ├── iothub_message.c │ ├── iothubtransport.c │ ├── iothubtransport_mqtt_common.c │ ├── iothubtransportmqtt.c │ └── version.c └── umqtt ├── inc └── azure_umqtt_c │ ├── mqtt_client.h │ ├── mqtt_codec.h │ ├── mqtt_message.h │ └── mqttconst.h └── src ├── mqtt_client.c ├── mqtt_codec.c └── mqtt_message.c /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 Visual Studio China 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | > ### Stop! Before you proceed: 2 | > 3 | > _This Get Started Guide is an **older version** and it is neither maintained nor supported anymore._ 4 | > 5 | > _It is kept here for **reference only** and should not be used for any new development._ 6 | > 7 | > _If you’re looking for a Get Started guide to the Espressif ESP32 there are two alternatives available:_ 8 | > 9 | > 1. _[Azure IoT SDK for C](https://github.com/Azure/azure-sdk-for-c-arduino/blob/main/examples/Azure_IoT_Hub_ESP32/readme.md) which uses a bare metal approach (no RTOS) and support for Arduino IDE._ 10 | > 2. _[Azure IoT middleware for FreeRTOS](https://github.com/Azure-Samples/iot-middleware-freertos-samples) which uses ESP-IDF._ 11 |
12 | 13 | # ESP32_AzureIoT - Azure IoT Hub library for esp32 devices in Arduino 14 | 15 | This library is a port of the 16 | [Microsoft Azure IoT device SDK for C](https://github.com/Azure/azure-iot-sdks/blob/master/c/readme.md) 17 | to Arduino for esp32 devices. It allows you to use several Arduino compatible ESP32 boards with Azure IoT Hub. 18 | 19 | ## Currently supported hardware 20 | - ESP32 based boards with [esp32/arduino](https://github.com/espressif/arduino-esp32) 21 | - [M5Stack](http://www.M5Stack.com) 22 | 23 | It should also work for other esp32 boards. 24 | 25 | ## Prerequisites 26 | 27 | You should have the following ready before beginning with any board: 28 | - [Setup your IoT hub](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md) 29 | - [Provision your device and get its credentials](https://github.com/Azure/azure-iot-device-ecosystem/blob/master/setup_iothub.md#create-new-device-in-the-iot-hub-device-identity-registry) 30 | - [Arduino IDE 1.8.5](https://www.arduino.cc/en/Main/Software) 31 | 32 | 33 | ## SimpleMQTT and GetStarted Instructions 34 | 35 | 1. Install esp32 board support into your Arduino IDE. 36 | * Start Arduino and open Preferences window. 37 | * Enter esp32 package URL https://dl.espressif.com/dl/package_esp32_index.json into Additional Board Manager URLs field. You can add multiple URLs, separating them with commas. 38 | * Open Boards Manager from Tools > Board menu and install esp32 platform. 39 | * Select your esp32 board from Tools > Board menu after installation 40 | 41 | 1. Open the `SimpleMQTT` or `GetStarted`example from the Arduino IDE File->Examples->ESP32 Azure IoT Arduino. 42 | 1. Update Wifi SSID/Password and IoT Hub Connection string in ino file 43 | * Ensure you are using a wifi network that does not require additional manual steps after connection, such as opening a web browser. 44 | 1. Access the [Get Started](https://docs.microsoft.com/en-us/azure/iot-hub/iot-hub-get-started-physical/) tutorial to learn more about how to get started with physical devices. 45 | 46 | ## Contributing 47 | There are a couple of ways you can contribute to this repo: 48 | 49 | - **Ideas, feature requests and bugs**: We are open to all ideas and we want to get rid of bugs! Use the Issues section to either report a new issue, provide your ideas or contribute to existing threads. 50 | - **Documentation**: Found a typo or strangely worded sentences? Submit a PR! 51 | - **Code**: Contribute bug fixes, features or design changes. 52 | 53 | Contributions for code that is not esp32 Arduino-specific can be made to the 54 | [Azure IoT C SDK](https://github.com/azure/azure-iot-sdk-c) 55 | 56 | ## Code of Conduct 57 | 58 | This project has adopted the 59 | [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). 60 | For more information see the 61 | [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or contact 62 | [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments. 63 | 64 | ## License 65 | 66 | See [LICENSE](LICENSE) file. 67 | 68 | 69 | -------------------------------------------------------------------------------- /examples/GetStarted/GetStarted.ino: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | #include 5 | #include "AzureIotHub.h" 6 | #include "Esp32MQTTClient.h" 7 | 8 | #define INTERVAL 10000 9 | #define DEVICE_ID "Esp32Device" 10 | #define MESSAGE_MAX_LEN 256 11 | 12 | // Please input the SSID and password of WiFi 13 | const char* ssid = ""; 14 | const char* password = ""; 15 | 16 | /*String containing Hostname, Device Id & Device Key in the format: */ 17 | /* "HostName=;DeviceId=;SharedAccessKey=" */ 18 | /* "HostName=;DeviceId=;SharedAccessSignature=" */ 19 | static const char* connectionString = ""; 20 | 21 | const char *messageData = "{\"deviceId\":\"%s\", \"messageId\":%d, \"Temperature\":%f, \"Humidity\":%f}"; 22 | 23 | int messageCount = 1; 24 | static bool hasWifi = false; 25 | static bool messageSending = true; 26 | static uint64_t send_interval_ms; 27 | 28 | ////////////////////////////////////////////////////////////////////////////////////////////////////////// 29 | // Utilities 30 | static void InitWifi() 31 | { 32 | Serial.println("Connecting..."); 33 | WiFi.begin(ssid, password); 34 | while (WiFi.status() != WL_CONNECTED) { 35 | delay(500); 36 | Serial.print("."); 37 | } 38 | hasWifi = true; 39 | Serial.println("WiFi connected"); 40 | Serial.println("IP address: "); 41 | Serial.println(WiFi.localIP()); 42 | } 43 | 44 | static void SendConfirmationCallback(IOTHUB_CLIENT_CONFIRMATION_RESULT result) 45 | { 46 | if (result == IOTHUB_CLIENT_CONFIRMATION_OK) 47 | { 48 | Serial.println("Send Confirmation Callback finished."); 49 | } 50 | } 51 | 52 | static void MessageCallback(const char* payLoad, int size) 53 | { 54 | Serial.println("Message callback:"); 55 | Serial.println(payLoad); 56 | } 57 | 58 | static void DeviceTwinCallback(DEVICE_TWIN_UPDATE_STATE updateState, const unsigned char *payLoad, int size) 59 | { 60 | char *temp = (char *)malloc(size + 1); 61 | if (temp == NULL) 62 | { 63 | return; 64 | } 65 | memcpy(temp, payLoad, size); 66 | temp[size] = '\0'; 67 | // Display Twin message. 68 | Serial.println(temp); 69 | free(temp); 70 | } 71 | 72 | static int DeviceMethodCallback(const char *methodName, const unsigned char *payload, int size, unsigned char **response, int *response_size) 73 | { 74 | LogInfo("Try to invoke method %s", methodName); 75 | const char *responseMessage = "\"Successfully invoke device method\""; 76 | int result = 200; 77 | 78 | if (strcmp(methodName, "start") == 0) 79 | { 80 | LogInfo("Start sending temperature and humidity data"); 81 | messageSending = true; 82 | } 83 | else if (strcmp(methodName, "stop") == 0) 84 | { 85 | LogInfo("Stop sending temperature and humidity data"); 86 | messageSending = false; 87 | } 88 | else 89 | { 90 | LogInfo("No method %s found", methodName); 91 | responseMessage = "\"No method found\""; 92 | result = 404; 93 | } 94 | 95 | *response_size = strlen(responseMessage) + 1; 96 | *response = (unsigned char *)strdup(responseMessage); 97 | 98 | return result; 99 | } 100 | 101 | ////////////////////////////////////////////////////////////////////////////////////////////////////////// 102 | // Arduino sketch 103 | void setup() 104 | { 105 | Serial.begin(115200); 106 | Serial.println("ESP32 Device"); 107 | Serial.println("Initializing..."); 108 | 109 | // Initialize the WiFi module 110 | Serial.println(" > WiFi"); 111 | hasWifi = false; 112 | InitWifi(); 113 | if (!hasWifi) 114 | { 115 | return; 116 | } 117 | randomSeed(analogRead(0)); 118 | 119 | Serial.println(" > IoT Hub"); 120 | Esp32MQTTClient_SetOption(OPTION_MINI_SOLUTION_NAME, "GetStarted"); 121 | Esp32MQTTClient_Init((const uint8_t*)connectionString, true); 122 | 123 | Esp32MQTTClient_SetSendConfirmationCallback(SendConfirmationCallback); 124 | Esp32MQTTClient_SetMessageCallback(MessageCallback); 125 | Esp32MQTTClient_SetDeviceTwinCallback(DeviceTwinCallback); 126 | Esp32MQTTClient_SetDeviceMethodCallback(DeviceMethodCallback); 127 | 128 | send_interval_ms = millis(); 129 | } 130 | 131 | void loop() 132 | { 133 | if (hasWifi) 134 | { 135 | if (messageSending && 136 | (int)(millis() - send_interval_ms) >= INTERVAL) 137 | { 138 | // Send teperature data 139 | char messagePayload[MESSAGE_MAX_LEN]; 140 | float temperature = (float)random(0,50); 141 | float humidity = (float)random(0, 1000)/10; 142 | snprintf(messagePayload,MESSAGE_MAX_LEN, messageData, DEVICE_ID, messageCount++, temperature,humidity); 143 | Serial.println(messagePayload); 144 | EVENT_INSTANCE* message = Esp32MQTTClient_Event_Generate(messagePayload, MESSAGE); 145 | Esp32MQTTClient_Event_AddProp(message, "temperatureAlert", "true"); 146 | Esp32MQTTClient_SendEventInstance(message); 147 | 148 | send_interval_ms = millis(); 149 | } 150 | else 151 | { 152 | Esp32MQTTClient_Check(); 153 | } 154 | } 155 | delay(10); 156 | } 157 | 158 | -------------------------------------------------------------------------------- /examples/SimpleMQTT/SimpleMQTT.ino: -------------------------------------------------------------------------------- 1 | /** 2 | * A simple Azure IoT example for sending telemetry. 3 | */ 4 | 5 | #include 6 | #include "Esp32MQTTClient.h" 7 | 8 | // Please input the SSID and password of WiFi 9 | const char* ssid = ""; 10 | const char* password = ""; 11 | 12 | /*String containing Hostname, Device Id & Device Key in the format: */ 13 | /* "HostName=;DeviceId=;SharedAccessKey=" */ 14 | /* "HostName=;DeviceId=;SharedAccessSignature=" */ 15 | static const char* connectionString = ""; 16 | 17 | static bool hasIoTHub = false; 18 | 19 | void setup() { 20 | Serial.begin(115200); 21 | Serial.println("Starting connecting WiFi."); 22 | delay(10); 23 | WiFi.begin(ssid, password); 24 | while (WiFi.status() != WL_CONNECTED) { 25 | delay(500); 26 | Serial.print("."); 27 | } 28 | Serial.println("WiFi connected"); 29 | Serial.println("IP address: "); 30 | Serial.println(WiFi.localIP()); 31 | 32 | if (!Esp32MQTTClient_Init((const uint8_t*)connectionString)) 33 | { 34 | hasIoTHub = false; 35 | Serial.println("Initializing IoT hub failed."); 36 | return; 37 | } 38 | hasIoTHub = true; 39 | } 40 | 41 | void loop() { 42 | Serial.println("start sending events."); 43 | if (hasIoTHub) 44 | { 45 | char buff[128]; 46 | 47 | // replace the following line with your data sent to Azure IoTHub 48 | snprintf(buff, 128, "{\"topic\":\"iot\"}"); 49 | 50 | if (Esp32MQTTClient_SendEvent(buff)) 51 | { 52 | Serial.println("Sending data succeed"); 53 | } 54 | else 55 | { 56 | Serial.println("Failure..."); 57 | } 58 | delay(5000); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /library.properties: -------------------------------------------------------------------------------- 1 | name=ESP32 Azure IoT Arduino 2 | version=0.1.0 3 | author=Microsoft 4 | maintainer=Microsoft 5 | sentence=Azure IoT library for ESP32 6 | paragraph=This library provides an implementation of Azure IoT library. 7 | category=Communication 8 | url=https://github.com/VSChina/ESP32_AzureIoT_Arduino 9 | architectures=esp32 -------------------------------------------------------------------------------- /src/AzureIotHub.cpp: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. -------------------------------------------------------------------------------- /src/AzureIotHub.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | #ifndef __AZURE_IOTHUB_H__ 4 | #define __AZURE_IOTHUB_H__ 5 | 6 | #include "az_iot/iothub_client/inc/iothub_client.h" 7 | #include "az_iot/iothub_client/inc/iothub_message.h" 8 | #include "az_iot/c-utility/inc/azure_c_shared_utility/threadapi.h" 9 | #include "az_iot/c-utility/inc/azure_c_shared_utility/crt_abstractions.h" 10 | #include "az_iot/c-utility/inc/azure_c_shared_utility/platform.h" 11 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 12 | #include "az_iot/iothub_client/inc/iothubtransportmqtt.h" 13 | #include "az_iot/azureiotcerts.h" 14 | 15 | typedef void (*CONNECTION_STATUS_CALLBACK)(IOTHUB_CLIENT_CONNECTION_STATUS result, IOTHUB_CLIENT_CONNECTION_STATUS_REASON reason); 16 | typedef void (*SEND_CONFIRMATION_CALLBACK)(IOTHUB_CLIENT_CONFIRMATION_RESULT result); 17 | typedef void (*MESSAGE_CALLBACK)(const char* message, int length); 18 | typedef void (*DEVICE_TWIN_CALLBACK)(DEVICE_TWIN_UPDATE_STATE updateState, const unsigned char *payLoad, int length); 19 | typedef int (*DEVICE_METHOD_CALLBACK)(const char *methodName, const unsigned char *payload, int length, unsigned char **response, int *responseLength); 20 | typedef void (*REPORT_CONFIRMATION_CALLBACK)(int status_code); 21 | #endif // __AZURE_IOTHUB_H__ -------------------------------------------------------------------------------- /src/Esp32MQTTClient.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. 3 | 4 | #ifndef __IOTHUB_MQTT_CLIENT_H__ 5 | #define __IOTHUB_MQTT_CLIENT_H__ 6 | 7 | #include 8 | #include "AzureIotHub.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | #define OPTION_MINI_SOLUTION_NAME "MiniSolution" 16 | 17 | enum EVENT_TYPE 18 | { 19 | MESSAGE, STATE 20 | }; 21 | 22 | typedef struct EVENT_INSTANCE_TAG 23 | { 24 | EVENT_TYPE type; 25 | IOTHUB_MESSAGE_HANDLE messageHandle; 26 | const char* stateString; 27 | int trackingId; // For tracking the events within the user callback. 28 | } EVENT_INSTANCE; 29 | 30 | /** 31 | * @brief Generate an event with the event string specified by @p eventString. 32 | * 33 | * @param eventString The string of event. 34 | * 35 | * @return EVENT_INSTANCE upon success or an error code upon failure. 36 | */ 37 | EVENT_INSTANCE* Esp32MQTTClient_Event_Generate(const char *eventString, EVENT_TYPE type); 38 | 39 | /** 40 | * @brief Add new property value for message. 41 | * 42 | * @param message The message need to be modified. 43 | * @param key The property name. 44 | * @param value The property value. 45 | */ 46 | void Esp32MQTTClient_Event_AddProp(EVENT_INSTANCE *message, const char * key, const char * value); 47 | 48 | /** 49 | * @brief Initialize a IoT Hub MQTT client for communication with an existing IoT hub. 50 | * The connection string is load from the EEPROM. 51 | * @param deviceConnString Device connection string. 52 | * @param hasDeviceTwin Enable / disable device twin, default is disable. 53 | * @param traceOn Enable / disable IoT Hub trace, default is disable. 54 | * 55 | * @return Return true if initialize successfully, or false if fails. 56 | */ 57 | bool Esp32MQTTClient_Init(const uint8_t* deviceConnString, bool hasDeviceTwin = false, bool traceOn = false); 58 | 59 | /** 60 | * @brief This API sets a runtime option identified by parameter @p optionName 61 | * to a value pointed to by @p value. @p optionName and the data type 62 | * @p value is pointing to are specific for every option. 63 | * 64 | * @param optionName Name of the option. 65 | * 66 | * @param value The value. 67 | * 68 | * @return Return true if set option successfully, or false if fails. 69 | */ 70 | bool Esp32MQTTClient_SetOption(const char* optionName, const void* value); 71 | 72 | /** 73 | * @brief Asynchronous call to send the message specified by @p text. 74 | * 75 | * @param text The text message. 76 | * 77 | * @return Return true if send successfully, or false if fails. 78 | */ 79 | bool Esp32MQTTClient_SendEvent(const char *text); 80 | 81 | /** 82 | * @brief Synchronous call to report the state specified by @p stateString. 83 | * 84 | * @param stateString The JSON string of reported state. 85 | * 86 | * @return Return true if send successfully, or false if fails. 87 | */ 88 | bool Esp32MQTTClient_ReportState(const char *stateString); 89 | 90 | /** 91 | * @brief Synchronous call to report the event specified by @p event. 92 | * 93 | * @param event The event instance. 94 | * 95 | * @return Return true if send successfully, or false if fails. 96 | */ 97 | bool Esp32MQTTClient_SendEventInstance(EVENT_INSTANCE *event); 98 | 99 | /** 100 | * @brief Retrieve a message from IoT hub 101 | * 102 | * @return Return true if get a message successfully, or false if there is no message returns. 103 | */ 104 | bool Esp32MQTTClient_ReceiveEvent(); 105 | 106 | /** 107 | * @brief The function is called to try receiving message from IoT hub. 108 | * 109 | * @param hasDelay Indicate whether check with IoT hub immediately or has delay, default is delay check (true). 110 | */ 111 | void Esp32MQTTClient_Check(bool hasDelay = true); 112 | 113 | /** 114 | * @brief Disposes of resources allocated by the IoT Hub client. 115 | */ 116 | void Esp32MQTTClient_Close(void); 117 | 118 | /** 119 | * @brief Sets up connection status callback to be invoked representing the status of the connection to IOT Hub. 120 | */ 121 | void Esp32MQTTClient_SetConnectionStatusCallback(CONNECTION_STATUS_CALLBACK connection_status_callback); 122 | 123 | /** 124 | * @brief Sets up send confirmation status callback to be invoked representing the status of sending message to IOT Hub. 125 | */ 126 | void Esp32MQTTClient_SetSendConfirmationCallback(SEND_CONFIRMATION_CALLBACK send_confirmation_callback); 127 | 128 | /** 129 | * @brief Sets up the message callback to be invoked when IoT Hub issues a message to the device. 130 | */ 131 | void Esp32MQTTClient_SetMessageCallback(MESSAGE_CALLBACK message_callback); 132 | 133 | /** 134 | * @brief Sets up the device twin callback to be invoked when IoT Hub update device twin of the device. 135 | */ 136 | void Esp32MQTTClient_SetDeviceTwinCallback(DEVICE_TWIN_CALLBACK device_twin_callback); 137 | 138 | /** 139 | * @brief Sets up the device method callback to be invoked when IoT Hub call method on the device. 140 | */ 141 | void Esp32MQTTClient_SetDeviceMethodCallback(DEVICE_METHOD_CALLBACK device_method_callback); 142 | 143 | /** 144 | * @brief Sets up the report confirmation callback to be invoked when report of the device's properties. 145 | */ 146 | void Esp32MQTTClient_SetReportConfirmationCallback(REPORT_CONFIRMATION_CALLBACK report_confirmation_callback); 147 | 148 | /** 149 | * @brief Force reset the connection. 150 | */ 151 | void Esp32MQTTClient_Reset(void); 152 | 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | 158 | #endif /* __IOTHUB_MQTT_CLIENT_H__ */ 159 | -------------------------------------------------------------------------------- /src/az_iot/azureiotcerts.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /* This file contains certs needed to communicate with Azure (IoT) */ 5 | 6 | #include "azureiotcerts.h" 7 | 8 | const char certificates[] = 9 | /* Baltimore */ 10 | "-----BEGIN CERTIFICATE-----\r\n" 11 | "MIIDdzCCAl+gAwIBAgIEAgAAuTANBgkqhkiG9w0BAQUFADBaMQswCQYDVQQGEwJJ\r\n" 12 | "RTESMBAGA1UEChMJQmFsdGltb3JlMRMwEQYDVQQLEwpDeWJlclRydXN0MSIwIAYD\r\n" 13 | "VQQDExlCYWx0aW1vcmUgQ3liZXJUcnVzdCBSb290MB4XDTAwMDUxMjE4NDYwMFoX\r\n" 14 | "DTI1MDUxMjIzNTkwMFowWjELMAkGA1UEBhMCSUUxEjAQBgNVBAoTCUJhbHRpbW9y\r\n" 15 | "ZTETMBEGA1UECxMKQ3liZXJUcnVzdDEiMCAGA1UEAxMZQmFsdGltb3JlIEN5YmVy\r\n" 16 | "VHJ1c3QgUm9vdDCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBAKMEuyKr\r\n" 17 | "mD1X6CZymrV51Cni4eiVgLGw41uOKymaZN+hXe2wCQVt2yguzmKiYv60iNoS6zjr\r\n" 18 | "IZ3AQSsBUnuId9Mcj8e6uYi1agnnc+gRQKfRzMpijS3ljwumUNKoUMMo6vWrJYeK\r\n" 19 | "mpYcqWe4PwzV9/lSEy/CG9VwcPCPwBLKBsua4dnKM3p31vjsufFoREJIE9LAwqSu\r\n" 20 | "XmD+tqYF/LTdB1kC1FkYmGP1pWPgkAx9XbIGevOF6uvUA65ehD5f/xXtabz5OTZy\r\n" 21 | "dc93Uk3zyZAsuT3lySNTPx8kmCFcB5kpvcY67Oduhjprl3RjM71oGDHweI12v/ye\r\n" 22 | "jl0qhqdNkNwnGjkCAwEAAaNFMEMwHQYDVR0OBBYEFOWdWTCCR1jMrPoIVDaGezq1\r\n" 23 | "BE3wMBIGA1UdEwEB/wQIMAYBAf8CAQMwDgYDVR0PAQH/BAQDAgEGMA0GCSqGSIb3\r\n" 24 | "DQEBBQUAA4IBAQCFDF2O5G9RaEIFoN27TyclhAO992T9Ldcw46QQF+vaKSm2eT92\r\n" 25 | "9hkTI7gQCvlYpNRhcL0EYWoSihfVCr3FvDB81ukMJY2GQE/szKN+OMY3EU/t3Wgx\r\n" 26 | "jkzSswF07r51XgdIGn9w/xZchMB5hbgF/X++ZRGjD8ACtPhSNzkE1akxehi/oCr0\r\n" 27 | "Epn3o0WC4zxe9Z2etciefC7IpJ5OCBRLbf1wbWsaY71k5h+3zvDyny67G7fyUIhz\r\n" 28 | "ksLi4xaNmjICq44Y3ekQEe5+NauQrz4wlHrQMz2nZQ/1/I6eYs9HRCwBXbsdtTLS\r\n" 29 | "R9I4LtD+gdwyah617jzV/OeBHRnDJELqYzmp\r\n" 30 | "-----END CERTIFICATE-----\r\n"; 31 | -------------------------------------------------------------------------------- /src/az_iot/azureiotcerts.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CERTS_H 5 | #define CERTS_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | extern const char certificates[]; 13 | 14 | #ifdef __cplusplus 15 | } 16 | #endif 17 | 18 | #endif /* CERTS_H */ 19 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/agenttime.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file agenttime.h 5 | * @brief Function prototypes for time related functions. 6 | * 7 | * @details These functions are implemented with C standard functions, 8 | * and therefore they are platform independent. But then a platform 9 | * can replace these functions with its own implementation as necessary. 10 | */ 11 | 12 | #ifndef AGENTTIME_H 13 | #define AGENTTIME_H 14 | 15 | #include 16 | #include "umock_c_prod.h" 17 | 18 | #ifdef __cplusplus 19 | extern "C" 20 | { 21 | #endif 22 | 23 | /** @brief Get current calendar time. 24 | * 25 | * @details This function provides the same functionality as the 26 | * standard C @c time() function. 27 | */ 28 | MOCKABLE_FUNCTION(, time_t, get_time, time_t*, currentTime); 29 | 30 | /** @brief Get UTC in @c tm struct. 31 | * 32 | * @details This function provides the same functionality as the 33 | * standard C @c gmtime() function. 34 | */ 35 | MOCKABLE_FUNCTION(, struct tm*, get_gmtime, time_t*, currentTime); 36 | 37 | /** @brief Get current time representation of the given calendar time. 38 | * 39 | * @details This function provides the same functionality as the 40 | * standard C @c mktime() function. 41 | */ 42 | MOCKABLE_FUNCTION(, time_t, get_mktime, struct tm*, cal_time); 43 | 44 | /** @brief Gets a C-string representation of the given time. 45 | * 46 | * @details This function provides the same functionality as the 47 | * standard C @c ctime() function. 48 | */ 49 | MOCKABLE_FUNCTION(, char*, get_ctime, time_t*, timeToGet); 50 | 51 | /** @brief Gets the difference in seconds between @c stopTime and 52 | * @c startTime. 53 | * 54 | * @details This function provides the same functionality as the 55 | * standard C @c difftime() function. 56 | */ 57 | MOCKABLE_FUNCTION(, double, get_difftime, time_t, stopTime, time_t, startTime); 58 | 59 | #ifdef __cplusplus 60 | } 61 | #endif 62 | 63 | #endif // AGENTTIME_H 64 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/base64.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file base64.h 5 | * @brief Prototypes for functions related to encoding/decoding 6 | * a @c buffer using standard base64 encoding. 7 | */ 8 | 9 | #ifndef BASE64_H 10 | #define BASE64_H 11 | 12 | #include "strings.h" 13 | #include "buffer_.h" 14 | 15 | #ifdef __cplusplus 16 | #include 17 | extern "C" { 18 | #else 19 | #include 20 | #endif 21 | 22 | #include "umock_c_prod.h" 23 | 24 | 25 | /** 26 | * @brief Base64 encodes a buffer and returns the resulting string. 27 | * 28 | * @param input The buffer that needs to be base64 encoded. 29 | * 30 | * Base64_Encoder takes as a parameter a pointer to a BUFFER. If @p input is @c NULL then 31 | * @c Base64_Encoder returns @c NULL. The size of the BUFFER pointed to by @p input may 32 | * be zero. If when allocating memory to produce the encoding a failure occurs, then @c 33 | * Base64_Encoder returns @c NULL. Otherwise 34 | * @c Base64_Encoder returns a pointer to a STRING. That string contains the 35 | * base 64 encoding of the @p input. This encoding of @p input will not contain embedded 36 | * line feeds. 37 | * 38 | * @return A @c STRING_HANDLE containing the base64 encoding of @p input. 39 | */ 40 | MOCKABLE_FUNCTION(, STRING_HANDLE, Base64_Encoder, BUFFER_HANDLE, input); 41 | 42 | /** 43 | * @brief Base64 encodes the buffer pointed to by @p source and returns the resulting string. 44 | * 45 | * @param source The buffer that needs to be base64 encoded. 46 | * @param size The size. 47 | * 48 | * This function produces a @c STRING_HANDLE containing the base64 encoding of the 49 | * buffer pointed to by @p source, having the size as given by 50 | * @p size. If @p source is @c NULL then @c Base64_Encode_Bytes returns @c NULL 51 | * If @p source is not @c NULL and @p size is zero, then @c Base64_Encode_Bytes produces 52 | * an empty @c STRING_HANDLE. Otherwise, @c Base64_Encode_Bytes produces a 53 | * @c STRING_HANDLE containing the Base64 representation of the buffer. In case of 54 | * any errors, @c Base64_Encode_Bytes returns @c NULL.]. 55 | * 56 | * @return @c NULL in case an error occurs or a @c STRING_HANDLE containing the base64 encoding 57 | * of @p input. 58 | * 59 | */ 60 | MOCKABLE_FUNCTION(, STRING_HANDLE, Base64_Encode_Bytes, const unsigned char*, source, size_t, size); 61 | 62 | /** 63 | * @brief Base64 decodes the buffer pointed to by @p source and returns the resulting buffer. 64 | * 65 | * @param source A base64 encoded string buffer. 66 | * 67 | * This function decodes the string pointed at by @p source using base64 decoding and 68 | * returns the resulting buffer. If @p source is @c NULL then 69 | * @c Base64_Decoder returns NULL. If the string pointed to by @p source is zero 70 | * length then the handle returned refers to a zero length buffer. If there is any 71 | * memory allocation failure during the decode or if the source string has an invalid 72 | * length for a base 64 encoded string then @c Base64_Decoder returns @c NULL. 73 | * 74 | * @return A @c BUFFER_HANDLE pointing to a buffer containing the result of base64 decoding @p 75 | * source. 76 | */ 77 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, Base64_Decoder, const char*, source); 78 | 79 | #ifdef __cplusplus 80 | } 81 | #endif 82 | 83 | #endif /* BASE64_H */ 84 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/buffer_.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef BUFFER_H 5 | #define BUFFER_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | extern "C" 10 | { 11 | #else 12 | #include 13 | #include 14 | #endif 15 | 16 | #include "umock_c_prod.h" 17 | 18 | typedef struct BUFFER_TAG* BUFFER_HANDLE; 19 | 20 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_new); 21 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_create, const unsigned char*, source, size_t, size); 22 | MOCKABLE_FUNCTION(, void, BUFFER_delete, BUFFER_HANDLE, handle); 23 | MOCKABLE_FUNCTION(, int, BUFFER_pre_build, BUFFER_HANDLE, handle, size_t, size); 24 | MOCKABLE_FUNCTION(, int, BUFFER_build, BUFFER_HANDLE, handle, const unsigned char*, source, size_t, size); 25 | MOCKABLE_FUNCTION(, int, BUFFER_append_build, BUFFER_HANDLE, handle, const unsigned char*, source, size_t, size); 26 | MOCKABLE_FUNCTION(, int, BUFFER_unbuild, BUFFER_HANDLE, handle); 27 | MOCKABLE_FUNCTION(, int, BUFFER_enlarge, BUFFER_HANDLE, handle, size_t, enlargeSize); 28 | MOCKABLE_FUNCTION(, int, BUFFER_shrink, BUFFER_HANDLE, handle, size_t, decreaseSize, bool, fromEnd); 29 | MOCKABLE_FUNCTION(, int, BUFFER_content, BUFFER_HANDLE, handle, const unsigned char**, content); 30 | MOCKABLE_FUNCTION(, int, BUFFER_size, BUFFER_HANDLE, handle, size_t*, size); 31 | MOCKABLE_FUNCTION(, int, BUFFER_append, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2); 32 | MOCKABLE_FUNCTION(, int, BUFFER_prepend, BUFFER_HANDLE, handle1, BUFFER_HANDLE, handle2); 33 | MOCKABLE_FUNCTION(, int, BUFFER_fill, BUFFER_HANDLE, handle, unsigned char, fill_char); 34 | MOCKABLE_FUNCTION(, unsigned char*, BUFFER_u_char, BUFFER_HANDLE, handle); 35 | MOCKABLE_FUNCTION(, size_t, BUFFER_length, BUFFER_HANDLE, handle); 36 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, BUFFER_clone, BUFFER_HANDLE, handle); 37 | 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | 43 | #endif /* BUFFER_H */ 44 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/condition.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CONDITION_H 5 | #define CONDITION_H 6 | 7 | #include "macro_utils.h" 8 | #include "lock.h" 9 | #include "umock_c_prod.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | typedef void* COND_HANDLE; 16 | 17 | #define COND_RESULT_VALUES \ 18 | COND_OK, \ 19 | COND_INVALID_ARG, \ 20 | COND_ERROR, \ 21 | COND_TIMEOUT \ 22 | 23 | /** 24 | * @brief Enumeration specifying the lock status. 25 | */ 26 | DEFINE_ENUM(COND_RESULT, COND_RESULT_VALUES); 27 | 28 | /** 29 | * @brief This API creates and returns a valid condition handle. 30 | * 31 | * @return A valid @c COND_HANDLE when successful or @c NULL otherwise. 32 | */ 33 | MOCKABLE_FUNCTION(, COND_HANDLE, Condition_Init); 34 | 35 | /** 36 | * @brief unblock all currently working condition. 37 | * 38 | * @param handle A valid handle to the lock. 39 | * 40 | * @return Returns @c COND_OK when the condition object has been 41 | * destroyed and @c COND_ERROR when an error occurs 42 | * and @c COND_TIMEOUT when the handle times out. 43 | */ 44 | MOCKABLE_FUNCTION(, COND_RESULT, Condition_Post, COND_HANDLE, handle); 45 | 46 | /** 47 | * @brief block on the condition handle unti the thread is signalled 48 | * or until the timeout_milliseconds is reached. 49 | * 50 | * @param handle A valid handle to the lock. 51 | * 52 | * @return Returns @c COND_OK when the condition object has been 53 | * destroyed and @c COND_ERROR when an error occurs 54 | * and @c COND_TIMEOUT when the handle times out. 55 | */ 56 | MOCKABLE_FUNCTION(, COND_RESULT, Condition_Wait, COND_HANDLE, handle, LOCK_HANDLE, lock, int, timeout_milliseconds); 57 | 58 | /** 59 | * @brief The condition instance is deinitialized. 60 | * 61 | * @param handle A valid handle to the condition. 62 | * 63 | * @return Returns @c COND_OK when the condition object has been 64 | * destroyed and @c COND_ERROR when an error occurs. 65 | */ 66 | MOCKABLE_FUNCTION(, void, Condition_Deinit, COND_HANDLE, handle); 67 | 68 | #ifdef __cplusplus 69 | } 70 | #endif 71 | 72 | #endif /* CONDITION_H */ 73 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/connection_string_parser.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CONNECTION_STRING_PARSER_H 5 | #define CONNECTION_STRING_PARSER_H 6 | 7 | #include "umock_c_prod.h" 8 | #include "map.h" 9 | #include "strings.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #endif 15 | 16 | MOCKABLE_FUNCTION(, MAP_HANDLE, connectionstringparser_parse_from_char, const char*, connection_string); 17 | MOCKABLE_FUNCTION(, MAP_HANDLE, connectionstringparser_parse, STRING_HANDLE, connection_string); 18 | MOCKABLE_FUNCTION(, int, connectionstringparser_splitHostName_from_char, const char*, hostName, STRING_HANDLE, nameString, STRING_HANDLE, suffixString); 19 | MOCKABLE_FUNCTION(, int, connectionstringparser_splitHostName, STRING_HANDLE, hostNameString, STRING_HANDLE, nameString, STRING_HANDLE, suffixString); 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif 24 | 25 | #endif /* CONNECTION_STRING_PARSER_H */ 26 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/consolelogger.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CONSOLELOGGER_H 5 | #define CONSOLELOGGER_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /* __cplusplus */ 10 | 11 | #include "xlogging.h" 12 | 13 | extern void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* func, int line, unsigned int options, const char* format, ...); 14 | 15 | #if (defined(_MSC_VER)) && (!(defined WINCE)) 16 | extern void consolelogger_log_with_GetLastError(const char* file, const char* func, int line, const char* format, ...); 17 | #endif 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif /* __cplusplus */ 22 | 23 | #endif /* CONSOLELOGGER_H */ 24 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/constbuffer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CONSTBUFFER_H 5 | #define CONSTBUFFER_H 6 | 7 | #include "buffer_.h" 8 | 9 | #ifdef __cplusplus 10 | #include 11 | extern "C" 12 | { 13 | #else 14 | #include 15 | #endif 16 | 17 | #include "umock_c_prod.h" 18 | 19 | /*this is the handle*/ 20 | typedef struct CONSTBUFFER_HANDLE_DATA_TAG* CONSTBUFFER_HANDLE; 21 | 22 | /*this is what is returned when the content of the buffer needs access*/ 23 | typedef struct CONSTBUFFER_TAG 24 | { 25 | const unsigned char* buffer; 26 | size_t size; 27 | } CONSTBUFFER; 28 | 29 | /*this creates a new constbuffer from a memory area*/ 30 | MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Create, const unsigned char*, source, size_t, size); 31 | 32 | /*this creates a new constbuffer from an existing BUFFER_HANDLE*/ 33 | MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_CreateFromBuffer, BUFFER_HANDLE, buffer); 34 | 35 | MOCKABLE_FUNCTION(, CONSTBUFFER_HANDLE, CONSTBUFFER_Clone, CONSTBUFFER_HANDLE, constbufferHandle); 36 | 37 | MOCKABLE_FUNCTION(, const CONSTBUFFER*, CONSTBUFFER_GetContent, CONSTBUFFER_HANDLE, constbufferHandle); 38 | 39 | MOCKABLE_FUNCTION(, void, CONSTBUFFER_Destroy, CONSTBUFFER_HANDLE, constbufferHandle); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /* CONSTBUFFER_H */ 46 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/constmap.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file constmap.h 5 | * @brief ConstMap is a module that implements a read-only dictionary 6 | * of @c const char* keys to @c const char* values. 7 | */ 8 | 9 | #ifndef CONSTMAP_H 10 | #define CONSTMAP_H 11 | 12 | #ifdef __cplusplus 13 | #include 14 | extern "C" 15 | { 16 | #else 17 | #include 18 | #endif 19 | 20 | 21 | #include "macro_utils.h" 22 | #include "crt_abstractions.h" 23 | #include "map.h" 24 | #include "umock_c_prod.h" 25 | 26 | #define CONSTMAP_RESULT_VALUES \ 27 | CONSTMAP_OK, \ 28 | CONSTMAP_ERROR, \ 29 | CONSTMAP_INVALIDARG, \ 30 | CONSTMAP_KEYNOTFOUND 31 | 32 | /** @brief Enumeration specifying the status of calls to various APIs in this 33 | * module. 34 | */ 35 | DEFINE_ENUM(CONSTMAP_RESULT, CONSTMAP_RESULT_VALUES); 36 | 37 | typedef struct CONSTMAP_HANDLE_DATA_TAG* CONSTMAP_HANDLE; 38 | 39 | 40 | /** 41 | * @brief Creates a new read-only map from a map handle. 42 | * 43 | * @param sourceMap The map from which we will populate key,value 44 | * into the read-only map. 45 | * 46 | * @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs. 47 | */ 48 | MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Create, MAP_HANDLE, sourceMap); 49 | 50 | /** 51 | * @brief Destroy a read-only map. Deallocate memory associated with handle. 52 | * @param handle Handle to a read-only map. 53 | */ 54 | MOCKABLE_FUNCTION(, void, ConstMap_Destroy, CONSTMAP_HANDLE, handle); 55 | 56 | /** 57 | * @brief Clone a read-only map from another read-only map. 58 | * @param handle Handle to a read-only map. 59 | * @return A valid @c CONSTMAP_HANDLE or @c NULL in case an error occurs. 60 | */ 61 | MOCKABLE_FUNCTION(, CONSTMAP_HANDLE, ConstMap_Clone, CONSTMAP_HANDLE, handle); 62 | 63 | /** 64 | * @brief Create a map handle populated from the read-only map. 65 | * @param handle Handle to a read-only map. 66 | * @return A valid @c MAP_HANDLE or @c NULL in case an error occurs. 67 | * 68 | * The new MAP_HANDLE needs to be destroyed when it is no longer needed. 69 | */ 70 | MOCKABLE_FUNCTION(, MAP_HANDLE, ConstMap_CloneWriteable, CONSTMAP_HANDLE, handle); 71 | 72 | /** 73 | * @brief This function returns a true if the map contains a key 74 | * with the same value the parameter @p key. 75 | * 76 | * @param handle The handle to an existing map. 77 | * @param key The key that the caller wants checked. 78 | * 79 | * @return The function returns @c true if the key exists 80 | * in the map and @c false if key is not found or 81 | * parameters are invalid. 82 | */ 83 | MOCKABLE_FUNCTION(, bool, ConstMap_ContainsKey, CONSTMAP_HANDLE, handle, const char*, key); 84 | 85 | /** 86 | * @brief This function returns @c true if at least one pair 87 | * exists in the map where the entry's value is equal to the 88 | * parameter @c value. 89 | * 90 | * @param handle The handle to an existing map. 91 | * @param value The value that the caller wants checked. 92 | * 93 | * @return The function returns @c true if the value exists 94 | * in the map and @c false if value is not found or 95 | * parameters are invalid. 96 | */ 97 | MOCKABLE_FUNCTION(, bool, ConstMap_ContainsValue, CONSTMAP_HANDLE, handle, const char*, value); 98 | 99 | /** 100 | * @brief Retrieves the value of a stored key. 101 | * 102 | * @param handle The handle to an existing map. 103 | * @param key The key to be looked up in the map. 104 | * 105 | * @return Returns @c NULL in case the input arguments are @c NULL or if the 106 | * requested key is not found in the map. Returns a pointer to the 107 | * key's value otherwise. 108 | */ 109 | MOCKABLE_FUNCTION(, const char*, ConstMap_GetValue, CONSTMAP_HANDLE, handle, const char*, key); 110 | 111 | /** 112 | * @brief Retrieves the complete list of keys and values from the map 113 | * in @p values and @p keys. Also writes the size of the list 114 | * in @p count. 115 | * 116 | * @param handle The handle to an existing map. 117 | * @param keys The location where the list of keys is to be written. 118 | * @param values The location where the list of values is to be written. 119 | * @param count The number of stored keys and values is written at the 120 | * location indicated by this pointer. 121 | * 122 | * @return Returns @c CONSTMAP_OK if the keys and values are retrieved 123 | * and written successfully or an error code otherwise. 124 | */ 125 | MOCKABLE_FUNCTION(, CONSTMAP_RESULT, ConstMap_GetInternals, CONSTMAP_HANDLE, handle, const char*const**, keys, const char*const**, values, size_t*, count); 126 | 127 | 128 | #ifdef __cplusplus 129 | } 130 | #endif 131 | 132 | #endif /* CONSTMAP_H */ 133 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/crt_abstractions.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef CRT_ABSTRACTIONS_H 5 | #define CRT_ABSTRACTIONS_H 6 | 7 | #include "umock_c_prod.h" 8 | 9 | #ifdef __cplusplus 10 | #include 11 | #include 12 | #include 13 | #include 14 | extern "C" { 15 | #else 16 | #include 17 | #include 18 | #include 19 | #endif 20 | 21 | #ifdef _MSC_VER 22 | 23 | #ifdef QUARKGALILEO 24 | #define HAS_STDBOOL 25 | #ifdef __cplusplus 26 | typedef bool _Bool; 27 | #else 28 | /*galileo apparently has _Bool and bool as built in types*/ 29 | #endif 30 | #endif 31 | 32 | #ifndef _WIN32_WCE 33 | #define HAS_STDBOOL 34 | #ifdef __cplusplus 35 | #include 36 | /*because C++ doesn't do anything about _Bool... */ 37 | #define _Bool bool 38 | #else 39 | #include 40 | #endif 41 | #else 42 | /* WINCE does not support bool as C datatype */ 43 | #define __bool_true_false_are_defined 1 44 | 45 | #define HAS_STDBOOL 46 | 47 | #define _Bool bool 48 | 49 | #ifdef __cplusplus 50 | #define _CSTDBOOL_ 51 | #else 52 | typedef unsigned char bool; 53 | 54 | #define false 0 55 | #define true 1 56 | #endif 57 | #endif 58 | #else 59 | #if defined __STDC_VERSION__ 60 | #if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L)) 61 | /*C99 compiler or C11*/ 62 | #define HAS_STDBOOL 63 | #include 64 | #endif 65 | #endif 66 | #endif 67 | 68 | #ifndef HAS_STDBOOL 69 | #ifdef __cplusplus 70 | #define _Bool bool 71 | #else 72 | typedef unsigned char _Bool; 73 | typedef unsigned char bool; 74 | #define false 0 75 | #define true 1 76 | #endif 77 | #endif 78 | 79 | 80 | /* Codes_SRS_CRT_ABSTRACTIONS_99_001:[The module shall not redefine the secure functions implemented by Microsoft CRT.] */ 81 | /* Codes_SRS_CRT_ABSTRACTIONS_99_040 : [The module shall still compile when building on a Microsoft platform.] */ 82 | /* Codes_SRS_CRT_ABSTRACTIONS_99_002: [CRTAbstractions module shall expose the following API]*/ 83 | #ifdef _MSC_VER 84 | #else 85 | #include "inttypes.h" 86 | 87 | /* Adding definitions from errno.h & crtdefs.h */ 88 | #if !defined (_TRUNCATE) 89 | #define _TRUNCATE ((size_t)-1) 90 | #endif /* !defined (_TRUNCATE) */ 91 | 92 | #if !defined STRUNCATE 93 | #define STRUNCATE 80 94 | #endif /* !defined (STRUNCATE) */ 95 | 96 | extern int strcpy_s(char* dst, size_t dstSizeInBytes, const char* src); 97 | extern int strcat_s(char* dst, size_t dstSizeInBytes, const char* src); 98 | extern int strncpy_s(char* dst, size_t dstSizeInBytes, const char* src, size_t maxCount); 99 | extern int sprintf_s(char* dst, size_t dstSizeInBytes, const char* format, ...); 100 | #endif 101 | 102 | extern unsigned long long strtoull_s(const char* nptr, char** endPtr, int base); 103 | extern float strtof_s(const char* nptr, char** endPtr); 104 | extern long double strtold_s(const char* nptr, char** endPtr); 105 | 106 | #ifdef _MSC_VER 107 | #define stricmp _stricmp 108 | #endif 109 | 110 | MOCKABLE_FUNCTION(, int, mallocAndStrcpy_s, char**, destination, const char*, source); 111 | MOCKABLE_FUNCTION(, int, unsignedIntToString, char*, destination, size_t, destinationSize, unsigned int, value); 112 | MOCKABLE_FUNCTION(, int, size_tToString, char*, destination, size_t, destinationSize, size_t, value); 113 | 114 | /*following logic shall define the TOUPPER and ISDIGIT, we do that because the SDK is not happy with some Arduino implementation of it.*/ 115 | #define TOUPPER(c) ((((c)>='a') && ((c)<='z'))?(c)-'a'+'A':c) 116 | #define ISDIGIT(c) ((((c)>='0') && ((c)<='9'))?1:0) 117 | 118 | /*following logic shall define the ISNAN macro*/ 119 | /*if runing on Microsoft Visual C compiler, than ISNAN shall be _isnan*/ 120 | /*else if running on C99 or C11, ISNAN shall be isnan*/ 121 | /*else if running on C89 ... #error and inform user*/ 122 | 123 | #ifdef _MSC_VER 124 | #define ISNAN _isnan 125 | #else 126 | #if defined __STDC_VERSION__ 127 | #if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L)) 128 | /*C99 compiler or C11*/ 129 | #define ISNAN isnan 130 | #else 131 | #error update this file to contain the latest C standard. 132 | #endif 133 | #else 134 | #ifdef __cplusplus 135 | /*C++ defines isnan... in C11*/ 136 | extern "C++" { 137 | #define ISNAN std::isnan 138 | } 139 | #else 140 | #error unknown (or C89) compiler, provide ISNAN with the same meaning as isnan in C99 standard 141 | #endif 142 | 143 | #endif 144 | #endif 145 | 146 | #ifdef _MSC_VER 147 | #define INT64_PRINTF "%I64d" 148 | #else 149 | #if defined __STDC_VERSION__ 150 | #if ((__STDC_VERSION__ == 199901L) || (__STDC_VERSION__ == 201000L) || (__STDC_VERSION__ == 201112L)) 151 | /*C99 compiler or C11*/ 152 | #define INT64_PRINTF "%" PRId64 "" 153 | #else 154 | #error update this file to contain the latest C standard. 155 | #endif 156 | #else 157 | #ifdef __cplusplus 158 | #define INT64_PRINTF "%" PRId64 "" 159 | #else 160 | #error unknown (or C89) compiler, provide INT64_PRINTF with the same meaning as PRIdN in C99 standard 161 | #endif 162 | #endif 163 | #endif 164 | 165 | #ifdef __cplusplus 166 | } 167 | #endif 168 | 169 | #endif /* CRT_ABSTRACTIONS_H */ 170 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/doublylinkedlist.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef DOUBLYLINKEDLIST_H 5 | #define DOUBLYLINKEDLIST_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | extern "C" 10 | { 11 | #else 12 | #include 13 | #endif 14 | 15 | #include 16 | #include "umock_c_prod.h" 17 | 18 | typedef struct DLIST_ENTRY_TAG 19 | { 20 | struct DLIST_ENTRY_TAG *Flink; 21 | struct DLIST_ENTRY_TAG *Blink; 22 | } DLIST_ENTRY, *PDLIST_ENTRY; 23 | 24 | MOCKABLE_FUNCTION(, void, DList_InitializeListHead, PDLIST_ENTRY, listHead); 25 | MOCKABLE_FUNCTION(, int, DList_IsListEmpty, const PDLIST_ENTRY, listHead); 26 | MOCKABLE_FUNCTION(, void, DList_InsertTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry); 27 | MOCKABLE_FUNCTION(, void, DList_InsertHeadList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, listEntry); 28 | MOCKABLE_FUNCTION(, void, DList_AppendTailList, PDLIST_ENTRY, listHead, PDLIST_ENTRY, ListToAppend); 29 | MOCKABLE_FUNCTION(, int, DList_RemoveEntryList, PDLIST_ENTRY, listEntry); 30 | MOCKABLE_FUNCTION(, PDLIST_ENTRY, DList_RemoveHeadList, PDLIST_ENTRY, listHead); 31 | 32 | // 33 | // Calculate the address of the base of the structure given its type, and an 34 | // address of a field within the structure. 35 | // 36 | #define containingRecord(address, type, field) ((type *)((uintptr_t)(address) - offsetof(type,field))) 37 | 38 | #ifdef __cplusplus 39 | } 40 | #else 41 | #endif 42 | 43 | #endif /* DOUBLYLINKEDLIST_H */ 44 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/gb_stdio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef GB_STDIO_H 5 | #define GB_STDIO_H 6 | 7 | /*this file, if included instead of has the following functionality: 8 | 1) if GB_STDIO_INTERCEPT is defined then 9 | a) some of the stdio.h symbols shall be redefined, for example: fopen => gb_fopen 10 | b) all "code" using the fopen will actually (because of the preprocessor) call to gb_fopen 11 | c) gb_fopen shall blindly call into fopen, thus realizing a passthrough 12 | 13 | reason is: unittesting. fopen is comes with the C Run Time and cannot be mocked (that is, in the global namespace cannot exist a function called fopen 14 | 15 | 2) if GB_STDIO_INTERCEPT is not defined then 16 | a) it shall include => no passthrough, just direct linking. 17 | */ 18 | 19 | #ifndef GB_STDIO_INTERCEPT 20 | #include 21 | #else 22 | 23 | /*source level intercepting of function calls*/ 24 | #define fopen fopen_never_called_never_implemented_always_forgotten 25 | #define fclose fclose_never_called_never_implemented_always_forgotten 26 | #define fseek fseek_never_called_never_implemented_always_forgotten 27 | #define ftell ftell_never_called_never_implemented_always_forgotten 28 | #define fprintf fprintf_never_called_never_implemented_always_forgotten 29 | 30 | #include "umock_c_prod.h" 31 | 32 | 33 | #ifdef __cplusplus 34 | #include 35 | extern "C" 36 | { 37 | #else 38 | #include 39 | #endif 40 | 41 | #undef fopen 42 | #define fopen gb_fopen 43 | MOCKABLE_FUNCTION(, FILE*, gb_fopen, const char*, filename, const char*, mode); 44 | 45 | 46 | #undef fclose 47 | #define fclose gb_fclose 48 | MOCKABLE_FUNCTION(, int, fclose, FILE *, stream); 49 | 50 | #undef fseek 51 | #define fseek gb_fseek 52 | MOCKABLE_FUNCTION(, int, fseek, FILE *,stream, long int, offset, int, whence); 53 | 54 | #undef ftell 55 | #define ftell gb_ftell 56 | MOCKABLE_FUNCTION(, long int, ftell, FILE *, stream); 57 | 58 | #undef fprintf 59 | #define fprintf gb_fprintf 60 | extern int fprintf(FILE * stream, const char * format, ...); 61 | 62 | 63 | #ifdef __cplusplus 64 | } 65 | #endif 66 | 67 | #endif /*GB_STDIO_INTERCEPT*/ 68 | 69 | #endif /* GB_STDIO_H */ 70 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/gb_time.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef GB_TIME_H 5 | #define GB_TIME_H 6 | 7 | /*this file, if included instead of has the following functionality: 8 | 1) if GB_TIME_INTERCEPT is defined then 9 | a) some of the time.h symbols shall be redefined, for example: time => gb_time 10 | b) all "code" using the time will actually (because of the preprocessor) call to gb_time 11 | c) gb_time shall blindly call into time, thus realizing a passthrough 12 | 13 | reason is: unittesting. time comes with the C Run Time and cannot be mocked (that is, in the global namespace cannot exist a function called time 14 | 15 | 2) if GB_TIME_INTERCEPT is not defined then 16 | a) it shall include => no passthrough, just direct linking. 17 | */ 18 | 19 | #ifndef GB_TIME_INTERCEPT 20 | #include 21 | #else 22 | 23 | /*source level intercepting of function calls*/ 24 | #define time time_never_called_never_implemented_always_forgotten 25 | #define localtime localtime_never_called_never_implemented_always_forgotten 26 | #define strftime strftime_never_called_never_implemented_always_forgotten 27 | 28 | #ifdef __cplusplus 29 | #include 30 | extern "C" 31 | { 32 | #else 33 | #include 34 | #endif 35 | 36 | #include "umock_c_prod.h" 37 | 38 | #undef time 39 | #define time gb_time 40 | MOCKABLE_FUNCTION(, time_t, time, time_t *, timer); 41 | 42 | #undef localtime 43 | #define localtime gb_localtime 44 | MOCKABLE_FUNCTION(, struct tm *, localtime, const time_t *, timer); 45 | 46 | #undef strftime 47 | #define strftime gb_strftime 48 | MOCKABLE_FUNCTION(, size_t, strftime, char *, s, size_t, maxsize, const char *, format, const struct tm *, timeptr); 49 | 50 | 51 | #ifdef __cplusplus 52 | } 53 | #endif 54 | 55 | #endif /*GB_TIME_INTERCEPT*/ 56 | 57 | #endif /* GB_TIME_H */ 58 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/gballoc.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef GBALLOC_H 5 | #define GBALLOC_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | extern "C" 10 | { 11 | #else 12 | #include 13 | #endif 14 | 15 | #include "umock_c_prod.h" 16 | 17 | /* all translation units that need memory measurement need to have GB_MEASURE_MEMORY_FOR_THIS defined */ 18 | /* GB_DEBUG_ALLOC is the switch that turns the measurement on/off, so that it is not on always */ 19 | #if defined(GB_DEBUG_ALLOC) 20 | 21 | MOCKABLE_FUNCTION(, int, gballoc_init); 22 | MOCKABLE_FUNCTION(, void, gballoc_deinit); 23 | MOCKABLE_FUNCTION(, void*, gballoc_malloc, size_t, size); 24 | MOCKABLE_FUNCTION(, void*, gballoc_calloc, size_t, nmemb, size_t, size); 25 | MOCKABLE_FUNCTION(, void*, gballoc_realloc, void*, ptr, size_t, size); 26 | MOCKABLE_FUNCTION(, void, gballoc_free, void*, ptr); 27 | 28 | MOCKABLE_FUNCTION(, size_t, gballoc_getMaximumMemoryUsed); 29 | MOCKABLE_FUNCTION(, size_t, gballoc_getCurrentMemoryUsed); 30 | 31 | /* if GB_MEASURE_MEMORY_FOR_THIS is defined then we want to redirect memory allocation functions to gballoc_xxx functions */ 32 | #ifdef GB_MEASURE_MEMORY_FOR_THIS 33 | /* Unfortunately this is still needed here for things to still compile when using _CRTDBG_MAP_ALLOC. 34 | That is because there is a rogue component (most likely CppUnitTest) including crtdbg. */ 35 | #if defined(_CRTDBG_MAP_ALLOC) && defined(_DEBUG) 36 | #undef _malloc_dbg 37 | #undef _calloc_dbg 38 | #undef _realloc_dbg 39 | #undef _free_dbg 40 | #define _malloc_dbg(size, ...) gballoc_malloc(size) 41 | #define _calloc_dbg(nmemb, size, ...) gballoc_calloc(nmemb, size) 42 | #define _realloc_dbg(ptr, size, ...) gballoc_realloc(ptr, size) 43 | #define _free_dbg(ptr, ...) gballoc_free(ptr) 44 | #else 45 | #define malloc gballoc_malloc 46 | #define calloc gballoc_calloc 47 | #define realloc gballoc_realloc 48 | #define free gballoc_free 49 | #endif 50 | #endif 51 | 52 | #else /* GB_DEBUG_ALLOC */ 53 | 54 | #define gballoc_init() 0 55 | #define gballoc_deinit() ((void)0) 56 | 57 | #define gballoc_getMaximumMemoryUsed() SIZE_MAX 58 | #define gballoc_getCurrentMemoryUsed() SIZE_MAX 59 | 60 | #endif /* GB_DEBUG_ALLOC */ 61 | 62 | #ifdef __cplusplus 63 | } 64 | #endif 65 | 66 | #endif /* GBALLOC_H */ 67 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/hmac.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef HMAC_H 5 | #define HMAC_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #include "sha.h" 12 | #include "umock_c_prod.h" 13 | 14 | MOCKABLE_FUNCTION(, int, hmac, SHAversion, whichSha, const unsigned char *, text, int, text_len, 15 | const unsigned char *, key, int, key_len, 16 | uint8_t, digest[USHAMaxHashSize]); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* HMAC_H */ 23 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/hmacsha256.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef HMACSHA256_H 5 | #define HMACSHA256_H 6 | 7 | #include "macro_utils.h" 8 | #include "buffer_.h" 9 | #include "umock_c_prod.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #define HMACSHA256_RESULT_VALUES \ 16 | HMACSHA256_OK, \ 17 | HMACSHA256_INVALID_ARG, \ 18 | HMACSHA256_ERROR 19 | 20 | DEFINE_ENUM(HMACSHA256_RESULT, HMACSHA256_RESULT_VALUES) 21 | 22 | MOCKABLE_FUNCTION(, HMACSHA256_RESULT, HMACSHA256_ComputeHash, const unsigned char*, key, size_t, keyLen, const unsigned char*, payload, size_t, payloadLen, BUFFER_HANDLE, hash); 23 | 24 | #ifdef __cplusplus 25 | } 26 | #endif 27 | 28 | #endif /* HMACSHA256_H */ 29 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/http_proxy_io.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef HTTP_PROXY_IO_H 5 | #define HTTP_PROXY_IO_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /* __cplusplus */ 10 | 11 | #include "xio.h" 12 | #include "umock_c_prod.h" 13 | 14 | typedef struct HTTP_PROXY_IO_CONFIG_TAG 15 | { 16 | const char* hostname; 17 | int port; 18 | const char* proxy_hostname; 19 | int proxy_port; 20 | const char* username; 21 | const char* password; 22 | } HTTP_PROXY_IO_CONFIG; 23 | 24 | MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, http_proxy_io_get_interface_description); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif /* __cplusplus */ 29 | 30 | #endif /* HTTP_PROXY_IO_H */ 31 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/httpapiex.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file httpapiex.h 5 | * @brief This is a utility module that provides HTTP requests with 6 | * build-in retry capabilities. 7 | * 8 | * @details HTTAPIEX is a utility module that provides HTTP requests with build-in 9 | * retry capability to an HTTP server. Features over "regular" HTTPAPI include: 10 | * - Optional parameters 11 | * - Implementation independent 12 | * - Retry mechanism 13 | * - Persistent options 14 | */ 15 | 16 | #ifndef HTTPAPIEX_H 17 | #define HTTPAPIEX_H 18 | 19 | #include "macro_utils.h" 20 | #include "httpapi.h" 21 | #include "umock_c_prod.h" 22 | 23 | #ifdef __cplusplus 24 | #include 25 | extern "C" { 26 | #else 27 | #include 28 | #endif 29 | 30 | typedef struct HTTPAPIEX_HANDLE_DATA_TAG* HTTPAPIEX_HANDLE; 31 | 32 | #define HTTPAPIEX_RESULT_VALUES \ 33 | HTTPAPIEX_OK, \ 34 | HTTPAPIEX_ERROR, \ 35 | HTTPAPIEX_INVALID_ARG, \ 36 | HTTPAPIEX_RECOVERYFAILED 37 | /*to be continued*/ 38 | 39 | /** @brief Enumeration specifying the status of calls to various APIs in this module. 40 | */ 41 | DEFINE_ENUM(HTTPAPIEX_RESULT, HTTPAPIEX_RESULT_VALUES); 42 | 43 | /** 44 | * @brief Creates an @c HTTPAPIEX_HANDLE that can be used in further calls. 45 | * 46 | * @param hostName Pointer to a null-terminated string that contains the host name 47 | * of an HTTP server. 48 | * 49 | * If @p hostName is @c NULL then @c HTTPAPIEX_Create returns @c NULL. The @p 50 | * hostName value is saved and associated with the returned handle. If creating 51 | * the handle fails for any reason, then @c HTTAPIEX_Create returns @c NULL. 52 | * Otherwise, @c HTTPAPIEX_Create returns an @c HTTAPIEX_HANDLE suitable for 53 | * further calls to the module. 54 | * 55 | * @return An @c HTTAPIEX_HANDLE suitable for further calls to the module. 56 | */ 57 | MOCKABLE_FUNCTION(, HTTPAPIEX_HANDLE, HTTPAPIEX_Create, const char*, hostName); 58 | 59 | /** 60 | * @brief Tries to execute an HTTP request. 61 | * 62 | * @param handle A valid @c HTTPAPIEX_HANDLE value. 63 | * @param requestType A value from the ::HTTPAPI_REQUEST_TYPE enum. 64 | * @param relativePath Relative path to send the request to on the server. 65 | * @param requestHttpHeadersHandle Handle to the request HTTP headers. 66 | * @param requestContent The request content. 67 | * @param statusCode If non-null, the HTTP status code is written to this 68 | * pointer. 69 | * @param responseHttpHeadersHandle Handle to the response HTTP headers. 70 | * @param responseContent The response content. 71 | * 72 | * @c HTTPAPIEX_ExecuteRequest tries to execute an HTTP request of type @p 73 | * requestType, on the server's @p relativePath, pushing the request HTTP 74 | * headers @p requestHttpHeadersHandle, having the content of the request 75 | * as pointed to by @p requestContent. If successful, @c HTTAPIEX_ExecuteRequest 76 | * writes in the out @p parameter statusCode the HTTP status, populates the @p 77 | * responseHeadersHandle with the response headers and copies the response body 78 | * to @p responseContent. 79 | * 80 | * @return An @c HTTAPIEX_HANDLE suitable for further calls to the module. 81 | */ 82 | MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_ExecuteRequest, HTTPAPIEX_HANDLE, handle, HTTPAPI_REQUEST_TYPE, requestType, const char*, relativePath, HTTP_HEADERS_HANDLE, requestHttpHeadersHandle, BUFFER_HANDLE, requestContent, unsigned int*, statusCode, HTTP_HEADERS_HANDLE, responseHttpHeadersHandle, BUFFER_HANDLE, responseContent); 83 | 84 | /** 85 | * @brief Frees all resources used by the @c HTTPAPIEX_HANDLE object. 86 | * 87 | * @param handle The @c HTTPAPIEX_HANDLE object to be freed. 88 | */ 89 | MOCKABLE_FUNCTION(, void, HTTPAPIEX_Destroy, HTTPAPIEX_HANDLE, handle); 90 | 91 | /** 92 | * @brief Sets the option @p optionName to the value pointed to by @p value. 93 | * 94 | * @param handle The @c HTTPAPIEX_HANDLE representing this session. 95 | * @param optionName Name of the option. 96 | * @param value The value to be set for the option. 97 | * 98 | * @return An @c HTTPAPIEX_RESULT indicating the status of the call. 99 | */ 100 | MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_SetOption, HTTPAPIEX_HANDLE, handle, const char*, optionName, const void*, value); 101 | 102 | #ifdef __cplusplus 103 | } 104 | #endif 105 | 106 | #endif /* HTTPAPIEX_H */ 107 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/httpapiexsas.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef HTTPAPIEX_SAS_H 5 | #define HTTPAPIEX_SAS_H 6 | 7 | #include "strings.h" 8 | #include "buffer_.h" 9 | #include "httpheaders.h" 10 | #include "httpapiex.h" 11 | #include "umock_c_prod.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif 16 | 17 | 18 | typedef struct HTTPAPIEX_SAS_STATE_TAG* HTTPAPIEX_SAS_HANDLE; 19 | 20 | MOCKABLE_FUNCTION(, HTTPAPIEX_SAS_HANDLE, HTTPAPIEX_SAS_Create, STRING_HANDLE, key, STRING_HANDLE, uriResource, STRING_HANDLE, keyName); 21 | 22 | MOCKABLE_FUNCTION(, void, HTTPAPIEX_SAS_Destroy, HTTPAPIEX_SAS_HANDLE, handle); 23 | 24 | MOCKABLE_FUNCTION(, HTTPAPIEX_RESULT, HTTPAPIEX_SAS_ExecuteRequest, HTTPAPIEX_SAS_HANDLE, sasHandle, HTTPAPIEX_HANDLE, handle, HTTPAPI_REQUEST_TYPE, requestType, const char*, relativePath, HTTP_HEADERS_HANDLE, requestHttpHeadersHandle, BUFFER_HANDLE, requestContent, unsigned int*, statusCode, HTTP_HEADERS_HANDLE, responseHeadersHandle, BUFFER_HANDLE, responseContent); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* HTTPAPIEX_SAS_H */ 31 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/httpheaders.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file httpheaders.h 5 | * @brief This is a utility module that handles HTTP message-headers. 6 | * 7 | * @details An application would use ::HTTPHeaders_Alloc to create a new set of HTTP headers. 8 | * After getting the handle, the application would build in several headers by 9 | * consecutive calls to ::HTTPHeaders_AddHeaderNameValuePair. When the headers are 10 | * constructed, the application can retrieve the stored data by calling one of the 11 | * following functions: 12 | * - ::HTTPHeaders_FindHeaderValue - when the name of the header is known and it 13 | * wants to know the value of that header 14 | * - ::HTTPHeaders_GetHeaderCount - when the application needs to know the count 15 | * of all the headers 16 | * - ::HTTPHeaders_GetHeader - when the application needs to retrieve the 17 | * name + ": " + value string based on an index. 18 | */ 19 | 20 | #ifndef HTTPHEADERS_H 21 | #define HTTPHEADERS_H 22 | 23 | #include "macro_utils.h" 24 | #include "umock_c_prod.h" 25 | 26 | #ifdef __cplusplus 27 | #include 28 | extern "C" { 29 | #else 30 | #include 31 | #endif 32 | 33 | /*Codes_SRS_HTTP_HEADERS_99_001:[ HttpHeaders shall have the following interface]*/ 34 | 35 | #define HTTP_HEADERS_RESULT_VALUES \ 36 | HTTP_HEADERS_OK, \ 37 | HTTP_HEADERS_INVALID_ARG, \ 38 | HTTP_HEADERS_ALLOC_FAILED, \ 39 | HTTP_HEADERS_INSUFFICIENT_BUFFER, \ 40 | HTTP_HEADERS_ERROR \ 41 | 42 | /** @brief Enumeration specifying the status of calls to various APIs in this module. 43 | */ 44 | DEFINE_ENUM(HTTP_HEADERS_RESULT, HTTP_HEADERS_RESULT_VALUES); 45 | typedef struct HTTP_HEADERS_HANDLE_DATA_TAG* HTTP_HEADERS_HANDLE; 46 | 47 | /** 48 | * @brief Produces a @c HTTP_HANDLE that can later be used in subsequent calls to the module. 49 | * 50 | * This function returns @c NULL in case an error occurs. After successful execution 51 | * ::HTTPHeaders_GetHeaderCount will report @c 0 existing headers. 52 | * 53 | * @return A HTTP_HEADERS_HANDLE representing the newly created collection of HTTP headers. 54 | */ 55 | MOCKABLE_FUNCTION(, HTTP_HEADERS_HANDLE, HTTPHeaders_Alloc); 56 | 57 | /** 58 | * @brief De-allocates the data structures allocated by previous API calls to the same handle. 59 | * 60 | * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value. 61 | */ 62 | MOCKABLE_FUNCTION(, void, HTTPHeaders_Free, HTTP_HEADERS_HANDLE, httpHeadersHandle); 63 | 64 | /** 65 | * @brief Adds a header record from the @p name and @p value parameters. 66 | * 67 | * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value. 68 | * @param name The name of the HTTP header to add. It is invalid for 69 | * the name to include the ':' character or character codes 70 | * outside the range 33-126. 71 | * @param value The value to be assigned to the header. 72 | * 73 | * The function stores the @c name:value pair in such a way that when later 74 | * retrieved by a call to ::HTTPHeaders_GetHeader it will return a string 75 | * that is @c strcmp equal to @c name+": "+value. If the name already exists 76 | * in the collection of headers, the function concatenates the new value 77 | * after the existing value, separated by a comma and a space as in: 78 | * old-value+", "+new-value. 79 | * 80 | * @return Returns @c HTTP_HEADERS_OK when execution is successful or an error code from 81 | * the ::HTTPAPIEX_RESULT enum. 82 | */ 83 | MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_AddHeaderNameValuePair, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name, const char*, value); 84 | 85 | /** 86 | * @brief This API performs exactly the same as ::HTTPHeaders_AddHeaderNameValuePair 87 | * except that if the header name already exists then the already existing value 88 | * will be replaced as opposed to being concatenated to. 89 | * 90 | * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value. 91 | * @param name The name of the HTTP header to add/replace. It is invalid for 92 | * the name to include the ':' character or character codes 93 | * outside the range 33-126. 94 | * @param value The value to be assigned to the header. 95 | * 96 | * @return Returns @c HTTP_HEADERS_OK when execution is successful or an error code from 97 | * the ::HTTPAPIEX_RESULT enum. 98 | */ 99 | MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_ReplaceHeaderNameValuePair, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name, const char*, value); 100 | 101 | /** 102 | * @brief Retrieves the value for a previously stored name. 103 | * 104 | * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value. 105 | * @param name The name of the HTTP header to find. 106 | * 107 | * @return The return value points to a string that shall be @c strcmp equal 108 | * to the original stored string. 109 | */ 110 | MOCKABLE_FUNCTION(, const char*, HTTPHeaders_FindHeaderValue, HTTP_HEADERS_HANDLE, httpHeadersHandle, const char*, name); 111 | 112 | /** 113 | * @brief This API retrieves the number of stored headers. 114 | * 115 | * @param httpHeadersHandle A valid @c HTTP_HEADERS_HANDLE value. 116 | * @param headersCount If non-null, the API writes the number of 117 | * into the memory pointed at by this parameter. 118 | * 119 | * @return Returns @c HTTP_HEADERS_OK when execution is successful or 120 | * @c HTTP_HEADERS_ERROR when an error occurs. 121 | */ 122 | MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_GetHeaderCount, HTTP_HEADERS_HANDLE, httpHeadersHandle, size_t*, headersCount); 123 | 124 | /** 125 | * @brief This API retrieves the string name+": "+value for the header 126 | * element at the given @p index. 127 | * 128 | * @param handle A valid @c HTTP_HEADERS_HANDLE value. 129 | * @param index Zero-based index of the item in the 130 | * headers collection. 131 | * @param destination If non-null, the header value is written into a 132 | * new string a pointer to which is written into this 133 | * parameters. It is the caller's responsibility to free 134 | * this memory. 135 | * 136 | * @return Returns @c HTTP_HEADERS_OK when execution is successful or 137 | * @c HTTP_HEADERS_ERROR when an error occurs. 138 | */ 139 | MOCKABLE_FUNCTION(, HTTP_HEADERS_RESULT, HTTPHeaders_GetHeader, HTTP_HEADERS_HANDLE, handle, size_t, index, char**, destination); 140 | 141 | /** 142 | * @brief This API produces a clone of the @p handle parameter. 143 | * 144 | * @param handle A valid @c HTTP_HEADERS_HANDLE value. 145 | * 146 | * If @p handle is not @c NULL this function clones the content 147 | * of the handle to a new handle and returns it. 148 | * 149 | * @return A @c HTTP_HEADERS_HANDLE containing a cloned copy of the 150 | * contents of @p handle. 151 | */ 152 | MOCKABLE_FUNCTION(, HTTP_HEADERS_HANDLE, HTTPHeaders_Clone, HTTP_HEADERS_HANDLE, handle); 153 | 154 | #ifdef __cplusplus 155 | } 156 | #endif 157 | 158 | #endif /* HTTPHEADERS_H */ 159 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/list.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef LIST_H 5 | #define LIST_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #include 10 | #else 11 | #include "stdbool.h" 12 | #endif /* __cplusplus */ 13 | 14 | #include "umock_c_prod.h" 15 | 16 | typedef struct LIST_INSTANCE_TAG* LIST_HANDLE; 17 | typedef struct LIST_ITEM_INSTANCE_TAG* LIST_ITEM_HANDLE; 18 | typedef bool (*LIST_MATCH_FUNCTION)(LIST_ITEM_HANDLE list_item, const void* match_context); 19 | 20 | MOCKABLE_FUNCTION(, LIST_HANDLE, list_create); 21 | MOCKABLE_FUNCTION(, void, list_destroy, LIST_HANDLE, list); 22 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_add, LIST_HANDLE, list, const void*, item); 23 | MOCKABLE_FUNCTION(, int, list_remove, LIST_HANDLE, list, LIST_ITEM_HANDLE, item_handle); 24 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_get_head_item, LIST_HANDLE, list); 25 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_get_next_item, LIST_ITEM_HANDLE, item_handle); 26 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, list_find, LIST_HANDLE, list, LIST_MATCH_FUNCTION, match_function, const void*, match_context); 27 | MOCKABLE_FUNCTION(, const void*, list_item_get_value, LIST_ITEM_HANDLE, item_handle); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif /* __cplusplus */ 32 | 33 | #endif /* LIST_H */ 34 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/lock.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file lock.h 5 | * @brief A minimalistic platform agnostic lock abstraction for thread 6 | * synchronization. 7 | * @details The Lock component is implemented in order to achieve thread 8 | * synchronization, as we may have a requirement to consume locks 9 | * across different platforms. This component exposes some generic 10 | * APIs so that it can be extended for platform specific 11 | * implementations. 12 | */ 13 | 14 | #ifndef LOCK_H 15 | #define LOCK_H 16 | 17 | #include "macro_utils.h" 18 | #include "umock_c_prod.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" { 22 | #endif 23 | 24 | typedef void* LOCK_HANDLE; 25 | 26 | #define LOCK_RESULT_VALUES \ 27 | LOCK_OK, \ 28 | LOCK_ERROR \ 29 | 30 | /** @brief Enumeration specifying the lock status. 31 | */ 32 | DEFINE_ENUM(LOCK_RESULT, LOCK_RESULT_VALUES); 33 | 34 | /** 35 | * @brief This API creates and returns a valid lock handle. 36 | * 37 | * @return A valid @c LOCK_HANDLE when successful or @c NULL otherwise. 38 | */ 39 | MOCKABLE_FUNCTION(, LOCK_HANDLE, Lock_Init); 40 | 41 | /** 42 | * @brief Acquires a lock on the given lock handle. Uses platform 43 | * specific mutex primitives in its implementation. 44 | * 45 | * @param handle A valid handle to the lock. 46 | * 47 | * @return Returns @c LOCK_OK when a lock has been acquired and 48 | * @c LOCK_ERROR when an error occurs. 49 | */ 50 | MOCKABLE_FUNCTION(, LOCK_RESULT, Lock, LOCK_HANDLE, handle); 51 | 52 | /** 53 | * @brief Releases the lock on the given lock handle. Uses platform 54 | * specific mutex primitives in its implementation. 55 | * 56 | * @param handle A valid handle to the lock. 57 | * 58 | * @return Returns @c LOCK_OK when the lock has been released and 59 | * @c LOCK_ERROR when an error occurs. 60 | */ 61 | MOCKABLE_FUNCTION(, LOCK_RESULT, Unlock, LOCK_HANDLE, handle); 62 | 63 | /** 64 | * @brief The lock instance is destroyed. 65 | * 66 | * @param handle A valid handle to the lock. 67 | * 68 | * @return Returns @c LOCK_OK when the lock object has been 69 | * destroyed and @c LOCK_ERROR when an error occurs. 70 | */ 71 | MOCKABLE_FUNCTION(, LOCK_RESULT, Lock_Deinit, LOCK_HANDLE, handle); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif 76 | 77 | #endif /* LOCK_H */ 78 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/optimize_size.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef OPTIMIZE_SIZE_H 5 | #define OPTIMIZE_SIZE_H 6 | 7 | #if (defined __MSP430FR5969__) 8 | #define OPTIMIZE_RETURN_CODES 9 | #define NO_VERBOSE_OUTPUT 10 | #ifdef DEBUG 11 | #define MINIMAL_LOGERROR 12 | #else 13 | #define NO_LOGGING 14 | #endif 15 | #endif 16 | 17 | #if (defined OPTIMIZE_RETURN_CODES) 18 | #define __FAILURE__ 1 19 | #else 20 | #define __FAILURE__ __LINE__ 21 | #endif 22 | 23 | #endif // OPTIMIZE_SIZE_H 24 | 25 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/optionhandler.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef OPTIONHANDLER_H 5 | #define OPTIONHANDLER_H 6 | 7 | #include "macro_utils.h" 8 | 9 | #define OPTIONHANDLER_RESULT_VALUES \ 10 | OPTIONHANDLER_OK, \ 11 | OPTIONHANDLER_ERROR, \ 12 | OPTIONHANDLER_INVALIDARG 13 | 14 | DEFINE_ENUM(OPTIONHANDLER_RESULT, OPTIONHANDLER_RESULT_VALUES) 15 | 16 | #ifdef __cplusplus 17 | extern "C" { 18 | #endif /* __cplusplus */ 19 | 20 | #include "umock_c_prod.h" 21 | 22 | typedef struct OPTIONHANDLER_HANDLE_DATA_TAG* OPTIONHANDLER_HANDLE; 23 | 24 | /*the following function pointer points to a function that produces a clone of the option specified by name and value (that is, a clone of void* value)*/ 25 | /*returns NULL if it failed to produce a clone, otherwise returns a non-NULL value*/ 26 | /*to be implemented by every module*/ 27 | typedef void* (*pfCloneOption)(const char* name, const void* value); 28 | 29 | /*the following function pointer points to a function that frees resources allocated for an option*/ 30 | /*to be implemented by every module*/ 31 | typedef void (*pfDestroyOption)(const char* name, const void* value); 32 | 33 | /*the following function pointer points to a function that sets an option for a module*/ 34 | /*to be implemented by every module*/ 35 | /*returns 0 if _SetOption succeeded, any other value is error, if the option is not intended for that module, returns 0*/ 36 | typedef int (*pfSetOption)(void* handle, const char* name, const void* value); 37 | 38 | MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, OptionHandler_Create, pfCloneOption, cloneOption, pfDestroyOption, destroyOption, pfSetOption, setOption); 39 | MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, OptionHandler_Clone, OPTIONHANDLER_HANDLE, handler); 40 | MOCKABLE_FUNCTION(, OPTIONHANDLER_RESULT, OptionHandler_AddOption, OPTIONHANDLER_HANDLE, handle, const char*, name, const void*, value); 41 | MOCKABLE_FUNCTION(, OPTIONHANDLER_RESULT, OptionHandler_FeedOptions, OPTIONHANDLER_HANDLE, handle, void*, destinationHandle); 42 | MOCKABLE_FUNCTION(, void, OptionHandler_Destroy, OPTIONHANDLER_HANDLE, handle); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif /* __cplusplus */ 47 | 48 | #endif /*OPTIONHANDLER*/ 49 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/platform.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef PLATFORM_H 5 | #define PLATFORM_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /* __cplusplus */ 10 | 11 | #include "strings.h" 12 | #include "xio.h" 13 | #include "umock_c_prod.h" 14 | 15 | MOCKABLE_FUNCTION(, int, platform_init); 16 | MOCKABLE_FUNCTION(, void, platform_deinit); 17 | MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, platform_get_default_tlsio); 18 | MOCKABLE_FUNCTION(, STRING_HANDLE, platform_get_platform_info); 19 | 20 | #ifdef __cplusplus 21 | } 22 | #endif /* __cplusplus */ 23 | 24 | #endif /* PLATFORM_H */ 25 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/refcount.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | 5 | /*this header contains macros for ref_counting a variable. 6 | 7 | There are no upper bound checks related to uint32_t overflow because we expect that bigger issues are in 8 | the system when more than 4 billion references exist to the same variable. In the case when such an overflow 9 | occurs, the object's ref count will reach zero (while still having 0xFFFFFFFF references) and likely the 10 | controlling code will take the decision to free the object's resources. Then, any of the 0xFFFFFFFF references 11 | will interact with deallocated memory / resources resulting in an undefined behavior. 12 | */ 13 | 14 | #ifndef REFCOUNT_H 15 | #define REFCOUNT_H 16 | 17 | #ifdef __cplusplus 18 | #include 19 | #include 20 | extern "C" 21 | { 22 | #else 23 | #include 24 | #include 25 | #endif 26 | 27 | #include "gballoc.h" 28 | #include "macro_utils.h" 29 | 30 | #if defined(__STDC_VERSION__) && (__STDC_VERSION__ == 201112) && (__STDC_NO_ATOMICS__!=1) 31 | #define REFCOUNT_USE_STD_ATOMIC 1 32 | #endif 33 | 34 | #if defined(ARDUINO_ARCH_SAMD) 35 | #undef REFCOUNT_USE_STD_ATOMIC 36 | #endif 37 | 38 | #if defined(FREERTOS_ARCH_ESP8266) 39 | #undef REFCOUNT_USE_STD_ATOMIC 40 | #define REFCOUNT_ATOMIC_DONTCARE 1 41 | #undef __GNUC__ 42 | #endif 43 | 44 | #define REFCOUNT_TYPE(type) \ 45 | struct C2(C2(REFCOUNT_, type), _TAG) 46 | 47 | #define REFCOUNT_SHORT_TYPE(type) \ 48 | C2(REFCOUNT_, type) 49 | 50 | #define REFCOUNT_TYPE_DECLARE_CREATE(type) C2(REFCOUNT_SHORT_TYPE(type), _Create) 51 | #define REFCOUNT_TYPE_CREATE(type) C2(REFCOUNT_SHORT_TYPE(type), _Create)() 52 | 53 | /*this introduces a new refcount'd type based on another type */ 54 | /*and an initializer for that new type that also sets the ref count to 1. The type must not have a flexible array*/ 55 | /*the newly allocated memory shall be free'd by free()*/ 56 | /*and the ref counting is handled internally by the type in the _Create/ _Clone /_Destroy functions */ 57 | 58 | #if defined(REFCOUNT_USE_STD_ATOMIC) 59 | #define COUNT_TYPE _Atomic uint32_t 60 | #elif defined(WIN32) 61 | #define COUNT_TYPE LONG 62 | #else 63 | #define COUNT_TYPE uint32_t 64 | #endif 65 | 66 | #define DEFINE_REFCOUNT_TYPE(type) \ 67 | REFCOUNT_TYPE(type) \ 68 | { \ 69 | type counted; \ 70 | COUNT_TYPE count; \ 71 | }; \ 72 | static type* REFCOUNT_TYPE_DECLARE_CREATE(type) (void) \ 73 | { \ 74 | REFCOUNT_TYPE(type)* result = (REFCOUNT_TYPE(type)*)malloc(sizeof(REFCOUNT_TYPE(type))); \ 75 | if (result != NULL) \ 76 | { \ 77 | result->count = 1; \ 78 | } \ 79 | return (type*)result; \ 80 | } \ 81 | 82 | /*the following macros increment/decrement a ref count in an atomic way, depending on the platform*/ 83 | /*The following mechanisms are considered in this order 84 | C11 85 | - will result in #include 86 | - will use atomic_fetch_add/sub; 87 | - about the return value: "Atomically, the value pointed to by object immediately before the effects" 88 | windows 89 | - will result in #include "windows.h" 90 | - will use InterlockedIncrement/InterlockedDecrement; 91 | - about the return value: https://msdn.microsoft.com/en-us/library/windows/desktop/ms683580(v=vs.85).aspx "The function returns the resulting decremented value" 92 | gcc 93 | - will result in no include (for gcc these are intrinsics build in) 94 | - will use __sync_fetch_and_add/sub 95 | - about the return value: "... returns the value that had previously been in memory." (https://gcc.gnu.org/onlinedocs/gcc-4.4.3/gcc/Atomic-Builtins.html#Atomic-Builtins) 96 | other cases 97 | - if REFCOUNT_ATOMIC_DONTCARE is defined, then 98 | will result in ++/-- used for increment/decrement. 99 | - if it is not defined, then error out 100 | 101 | It seems windows is "one off" because it returns the value "after" the decrement, as opposed to C11 standard and gcc that return the value "before". 102 | The macro DEC_RETURN_ZERO will be "0" on windows, and "1" on the other cases. 103 | */ 104 | 105 | /*if macro DEC_REF returns DEC_RETURN_ZERO that means the ref count has reached zero.*/ 106 | #if defined(REFCOUNT_USE_STD_ATOMIC) 107 | #include 108 | #define DEC_RETURN_ZERO (1) 109 | #define INC_REF(type, var) atomic_fetch_add((&((REFCOUNT_TYPE(type)*)var)->count), 1) 110 | #define DEC_REF(type, var) atomic_fetch_sub((&((REFCOUNT_TYPE(type)*)var)->count), 1) 111 | 112 | #elif defined(WIN32) 113 | #include "windows.h" 114 | #define DEC_RETURN_ZERO (0) 115 | #define INC_REF(type, var) InterlockedIncrement(&(((REFCOUNT_TYPE(type)*)var)->count)) 116 | #define DEC_REF(type, var) InterlockedDecrement(&(((REFCOUNT_TYPE(type)*)var)->count)) 117 | 118 | #elif defined(__GNUC__) 119 | #define DEC_RETURN_ZERO (0) 120 | #define INC_REF(type, var) __sync_add_and_fetch((&((REFCOUNT_TYPE(type)*)var)->count), 1) 121 | #define DEC_REF(type, var) __sync_sub_and_fetch((&((REFCOUNT_TYPE(type)*)var)->count), 1) 122 | 123 | #else 124 | #if defined(REFCOUNT_ATOMIC_DONTCARE) 125 | #define DEC_RETURN_ZERO (0) 126 | #define INC_REF(type, var) ++((((REFCOUNT_TYPE(type)*)var)->count)) 127 | #define DEC_REF(type, var) --((((REFCOUNT_TYPE(type)*)var)->count)) 128 | #else 129 | #error do not know how to atomically increment and decrement a uint32_t :(. Platform support needs to be extended to your platform. 130 | #endif /*defined(REFCOUNT_ATOMIC_DONTCARE)*/ 131 | #endif 132 | 133 | 134 | 135 | #ifdef __cplusplus 136 | } 137 | #endif 138 | 139 | #endif /*REFCOUNT_H*/ 140 | 141 | 142 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/sastoken.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SASTOKEN_H 5 | #define SASTOKEN_H 6 | 7 | #include "strings.h" 8 | #include 9 | #include "umock_c_prod.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | MOCKABLE_FUNCTION(, bool, SASToken_Validate, STRING_HANDLE, sasToken); 16 | MOCKABLE_FUNCTION(, STRING_HANDLE, SASToken_Create, STRING_HANDLE, key, STRING_HANDLE, scope, STRING_HANDLE, keyName, size_t, expiry); 17 | MOCKABLE_FUNCTION(, STRING_HANDLE, SASToken_CreateString, const char*, key, const char*, scope, const char*, keyName, size_t, expiry); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* SASTOKEN_H */ 24 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/sha-private.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /*************************** sha-private.h ***************************/ 5 | /********************** See RFC 4634 for details *********************/ 6 | #ifndef _SHA_PRIVATE__H 7 | #define _SHA_PRIVATE__H 8 | /* 9 | * These definitions are defined in FIPS-180-2, section 4.1. 10 | * Ch() and Maj() are defined identically in sections 4.1.1, 11 | * 4.1.2 and 4.1.3. 12 | * 13 | * The definitions used in FIPS-180-2 are as follows: 14 | */ 15 | 16 | #ifndef USE_MODIFIED_MACROS 17 | #define SHA_Ch(x,y,z) (((x) & (y)) ^ ((~(x)) & (z))) 18 | #define SHA_Maj(x,y,z) (((x) & (y)) ^ ((x) & (z)) ^ ((y) & (z))) 19 | 20 | #else /* USE_MODIFIED_MACROS */ 21 | /* 22 | * The following definitions are equivalent and potentially faster. 23 | */ 24 | 25 | #define SHA_Ch(x, y, z) (((x) & ((y) ^ (z))) ^ (z)) 26 | #define SHA_Maj(x, y, z) (((x) & ((y) | (z))) | ((y) & (z))) 27 | 28 | #endif /* USE_MODIFIED_MACROS */ 29 | 30 | #define SHA_Parity(x, y, z) ((x) ^ (y) ^ (z)) 31 | 32 | #endif /* _SHA_PRIVATE__H */ 33 | 34 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/shared_util_options.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SHARED_UTIL_OPTIONS_H 5 | #define SHARED_UTIL_OPTIONS_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | typedef struct HTTP_PROXY_OPTIONS_TAG 13 | { 14 | const char* host_address; 15 | int port; 16 | const char* username; 17 | const char* password; 18 | } HTTP_PROXY_OPTIONS; 19 | 20 | static const char* OPTION_HTTP_PROXY = "proxy_data"; 21 | static const char* OPTION_HTTP_TIMEOUT = "timeout"; 22 | 23 | static const char* OPTION_TRUSTED_CERT = "TrustedCerts"; 24 | 25 | static const char* SU_OPTION_X509_CERT = "x509certificate"; 26 | static const char* SU_OPTION_X509_PRIVATE_KEY = "x509privatekey"; 27 | 28 | static const char* OPTION_X509_ECC_CERT = "x509EccCertificate"; 29 | static const char* OPTION_X509_ECC_KEY = "x509EccAliasKey"; 30 | 31 | static const char* OPTION_CURL_LOW_SPEED_LIMIT = "CURLOPT_LOW_SPEED_LIMIT"; 32 | static const char* OPTION_CURL_LOW_SPEED_TIME = "CURLOPT_LOW_SPEED_TIME"; 33 | static const char* OPTION_CURL_FRESH_CONNECT = "CURLOPT_FRESH_CONNECT"; 34 | static const char* OPTION_CURL_FORBID_REUSE = "CURLOPT_FORBID_REUSE"; 35 | static const char* OPTION_CURL_VERBOSE = "CURLOPT_VERBOSE"; 36 | 37 | static const char* OPTION_NET_INT_MAC_ADDRESS = "net_interface_mac_address"; 38 | #ifdef __cplusplus 39 | } 40 | #endif 41 | 42 | #endif /* SHARED_UTIL_OPTIONS_H */ 43 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/singlylinkedlist.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SINGLYLINKEDLIST_H 5 | #define SINGLYLINKEDLIST_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #include 10 | #else 11 | #include "stdbool.h" 12 | #endif /* __cplusplus */ 13 | 14 | #include "umock_c_prod.h" 15 | 16 | typedef struct SINGLYLINKEDLIST_INSTANCE_TAG* SINGLYLINKEDLIST_HANDLE; 17 | typedef struct LIST_ITEM_INSTANCE_TAG* LIST_ITEM_HANDLE; 18 | 19 | /** 20 | * @brief Function passed to singlylinkedlist_find, which returns whichever first list item that matches it. 21 | * @param list_item Current list node being evaluated. 22 | * @param match_context Context passed to singlylinkedlist_find. 23 | * @returns True to indicate that the current list node is the one to be returned, or false to continue traversing the list. 24 | */ 25 | typedef bool (*LIST_MATCH_FUNCTION)(LIST_ITEM_HANDLE list_item, const void* match_context); 26 | /** 27 | * @brief Function passed to singlylinkedlist_remove_if, which is used to define if an item of the list should be removed or not. 28 | * @param item Value of the current list node being evaluated for removal. 29 | * @param match_context Context passed to singlylinkedlist_remove_if. 30 | * @param continue_processing Indicates if singlylinkedlist_remove_if shall continue iterating through the next nodes of the list or stop. 31 | * @returns True to indicate that the current list node shall be removed, or false to not to. 32 | */ 33 | typedef bool (*LIST_CONDITION_FUNCTION)(const void* item, const void* match_context, bool* continue_processing); 34 | /** 35 | * @brief Function passed to singlylinkedlist_foreach, which is called for the value of each node of the list. 36 | * @param item Value of the current list node being processed. 37 | * @param action_context Context passed to singlylinkedlist_foreach. 38 | * @param continue_processing Indicates if singlylinkedlist_foreach shall continue iterating through the next nodes of the list or stop. 39 | */ 40 | typedef void (*LIST_ACTION_FUNCTION)(const void* item, const void* action_context, bool* continue_processing); 41 | 42 | MOCKABLE_FUNCTION(, SINGLYLINKEDLIST_HANDLE, singlylinkedlist_create); 43 | MOCKABLE_FUNCTION(, void, singlylinkedlist_destroy, SINGLYLINKEDLIST_HANDLE, list); 44 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_add, SINGLYLINKEDLIST_HANDLE, list, const void*, item); 45 | MOCKABLE_FUNCTION(, int, singlylinkedlist_remove, SINGLYLINKEDLIST_HANDLE, list, LIST_ITEM_HANDLE, item_handle); 46 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_get_head_item, SINGLYLINKEDLIST_HANDLE, list); 47 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_get_next_item, LIST_ITEM_HANDLE, item_handle); 48 | MOCKABLE_FUNCTION(, LIST_ITEM_HANDLE, singlylinkedlist_find, SINGLYLINKEDLIST_HANDLE, list, LIST_MATCH_FUNCTION, match_function, const void*, match_context); 49 | MOCKABLE_FUNCTION(, const void*, singlylinkedlist_item_get_value, LIST_ITEM_HANDLE, item_handle); 50 | MOCKABLE_FUNCTION(, int, singlylinkedlist_remove_if, SINGLYLINKEDLIST_HANDLE, list, LIST_CONDITION_FUNCTION, condition_function, const void*, match_context); 51 | MOCKABLE_FUNCTION(, int, singlylinkedlist_foreach, SINGLYLINKEDLIST_HANDLE, list, LIST_ACTION_FUNCTION, action_function, const void*, action_context); 52 | 53 | #ifdef __cplusplus 54 | } 55 | #endif /* __cplusplus */ 56 | 57 | #endif /* SINGLYLINKEDLIST_H */ 58 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/socketio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef SOCKETIO_H 5 | #define SOCKETIO_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #include 10 | #else 11 | #include 12 | #endif /* __cplusplus */ 13 | 14 | #include "xio.h" 15 | #include "xlogging.h" 16 | #include "umock_c_prod.h" 17 | 18 | typedef struct SOCKETIO_CONFIG_TAG 19 | { 20 | const char* hostname; 21 | int port; 22 | void* accepted_socket; 23 | } SOCKETIO_CONFIG; 24 | 25 | #define RECEIVE_BYTES_VALUE 64 26 | 27 | MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, socketio_create, void*, io_create_parameters); 28 | MOCKABLE_FUNCTION(, void, socketio_destroy, CONCRETE_IO_HANDLE, socket_io); 29 | MOCKABLE_FUNCTION(, int, socketio_open, CONCRETE_IO_HANDLE, socket_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context); 30 | MOCKABLE_FUNCTION(, int, socketio_close, CONCRETE_IO_HANDLE, socket_io, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context); 31 | MOCKABLE_FUNCTION(, int, socketio_send, CONCRETE_IO_HANDLE, socket_io, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context); 32 | MOCKABLE_FUNCTION(, void, socketio_dowork, CONCRETE_IO_HANDLE, socket_io); 33 | MOCKABLE_FUNCTION(, int, socketio_setoption, CONCRETE_IO_HANDLE, socket_io, const char*, optionName, const void*, value); 34 | 35 | MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, socketio_get_interface_description); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif /* __cplusplus */ 40 | 41 | #endif /* SOCKETIO_H */ 42 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/string_tokenizer.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef STRING_TOKENIZER_H 5 | #define STRING_TOKENIZER_H 6 | 7 | #include "strings.h" 8 | #include "umock_c_prod.h" 9 | #include "string_tokenizer_types.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" 13 | { 14 | #else 15 | #endif 16 | 17 | MOCKABLE_FUNCTION(, STRING_TOKENIZER_HANDLE, STRING_TOKENIZER_create, STRING_HANDLE, handle); 18 | MOCKABLE_FUNCTION(, STRING_TOKENIZER_HANDLE, STRING_TOKENIZER_create_from_char, const char*, input); 19 | MOCKABLE_FUNCTION(, int, STRING_TOKENIZER_get_next_token, STRING_TOKENIZER_HANDLE, t, STRING_HANDLE, output, const char*, delimiters); 20 | MOCKABLE_FUNCTION(, void, STRING_TOKENIZER_destroy, STRING_TOKENIZER_HANDLE, t); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #else 25 | #endif 26 | 27 | #endif /*STRING_TOKENIZER_H*/ 28 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/string_tokenizer_types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef STRING_TOKENIZER_TYPES_H 5 | #define STRING_TOKENIZER_TYPES_H 6 | 7 | typedef struct STRING_TOKEN_TAG* STRING_TOKENIZER_HANDLE; 8 | 9 | #endif /*STRING_TOKENIZER_TYPES_H*/ 10 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/strings.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef STRINGS_H 5 | #define STRINGS_H 6 | 7 | #include "umock_c_prod.h" 8 | #include "strings_types.h" 9 | 10 | #ifdef __cplusplus 11 | #include 12 | extern "C" 13 | { 14 | #else 15 | #include 16 | #endif 17 | 18 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new); 19 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_clone, STRING_HANDLE, handle); 20 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_construct, const char*, psz); 21 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_construct_n, const char*, psz, size_t, n); 22 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_with_memory, const char*, memory); 23 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_quoted, const char*, source); 24 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_new_JSON, const char*, source); 25 | MOCKABLE_FUNCTION(, STRING_HANDLE, STRING_from_byte_array, const unsigned char*, source, size_t, size); 26 | MOCKABLE_FUNCTION(, void, STRING_delete, STRING_HANDLE, handle); 27 | MOCKABLE_FUNCTION(, int, STRING_concat, STRING_HANDLE, handle, const char*, s2); 28 | MOCKABLE_FUNCTION(, int, STRING_concat_with_STRING, STRING_HANDLE, s1, STRING_HANDLE, s2); 29 | MOCKABLE_FUNCTION(, int, STRING_quote, STRING_HANDLE, handle); 30 | MOCKABLE_FUNCTION(, int, STRING_copy, STRING_HANDLE, s1, const char*, s2); 31 | MOCKABLE_FUNCTION(, int, STRING_copy_n, STRING_HANDLE, s1, const char*, s2, size_t, n); 32 | MOCKABLE_FUNCTION(, const char*, STRING_c_str, STRING_HANDLE, handle); 33 | MOCKABLE_FUNCTION(, int, STRING_empty, STRING_HANDLE, handle); 34 | MOCKABLE_FUNCTION(, size_t, STRING_length, STRING_HANDLE, handle); 35 | MOCKABLE_FUNCTION(, int, STRING_compare, STRING_HANDLE, s1, STRING_HANDLE, s2); 36 | MOCKABLE_FUNCTION(, int, STRING_replace, STRING_HANDLE, handle, char, target, char, replace); 37 | 38 | extern STRING_HANDLE STRING_construct_sprintf(const char* format, ...); 39 | extern int STRING_sprintf(STRING_HANDLE s1, const char* format, ...); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif /*STRINGS_H*/ 46 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/strings_types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef STRINGS_TYPES_H 5 | #define STRINGS_TYPES_H 6 | 7 | typedef struct STRING_TAG* STRING_HANDLE; 8 | 9 | #endif /*STRINGS_TYPES_H*/ 10 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/tcpsocketconnection_c.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TCPSOCKETCONNECTION_C_H 5 | #define TCPSOCKETCONNECTION_C_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif 10 | 11 | #include "umock_c_prod.h" 12 | 13 | typedef void* TCPSOCKETCONNECTION_HANDLE; 14 | 15 | MOCKABLE_FUNCTION(, TCPSOCKETCONNECTION_HANDLE, tcpsocketconnection_create); 16 | MOCKABLE_FUNCTION(, void, tcpsocketconnection_set_blocking, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle, bool, blocking, unsigned int, timeout); 17 | MOCKABLE_FUNCTION(, void, tcpsocketconnection_destroy, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle); 18 | MOCKABLE_FUNCTION(, int, tcpsocketconnection_connect, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle, const char*, host, const int, port); 19 | MOCKABLE_FUNCTION(, bool, tcpsocketconnection_is_connected, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle); 20 | MOCKABLE_FUNCTION(, void, tcpsocketconnection_close, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle); 21 | MOCKABLE_FUNCTION(, int, tcpsocketconnection_send, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle, const char*, data, int, length); 22 | MOCKABLE_FUNCTION(, int, tcpsocketconnection_send_all, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle, const char*, data, int, length); 23 | MOCKABLE_FUNCTION(, int, tcpsocketconnection_receive, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle, char*, data, int, length); 24 | MOCKABLE_FUNCTION(, int, tcpsocketconnection_receive_all, TCPSOCKETCONNECTION_HANDLE, tcpSocketConnectionHandle, char*, data, int, length); 25 | 26 | #ifdef __cplusplus 27 | } 28 | #endif 29 | 30 | #endif /* TCPSOCKETCONNECTION_C_H */ 31 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/threadapi.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file threadapi.h 5 | * @brief This module implements support for creating new threads, 6 | * terminating threads and sleeping threads. 7 | */ 8 | 9 | #ifndef THREADAPI_H 10 | #define THREADAPI_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "macro_utils.h" 17 | #include "umock_c_prod.h" 18 | 19 | typedef int(*THREAD_START_FUNC)(void *); 20 | 21 | #define THREADAPI_RESULT_VALUES \ 22 | THREADAPI_OK, \ 23 | THREADAPI_INVALID_ARG, \ 24 | THREADAPI_NO_MEMORY, \ 25 | THREADAPI_ERROR 26 | 27 | /** @brief Enumeration specifying the possible return values for the APIs in 28 | * this module. 29 | */ 30 | DEFINE_ENUM(THREADAPI_RESULT, THREADAPI_RESULT_VALUES); 31 | 32 | typedef void* THREAD_HANDLE; 33 | 34 | /** 35 | * @brief Creates a thread with the entry point specified by the @p func 36 | * argument. 37 | * 38 | * @param threadHandle The handle to the new thread is returned in this 39 | * pointer. 40 | * @param func A function pointer that indicates the entry point 41 | * to the new thread. 42 | * @param arg A void pointer that must be passed to the function 43 | * pointed to by @p func. 44 | * 45 | * @return @c THREADAPI_OK if the API call is successful or an error 46 | * code in case it fails. 47 | */ 48 | MOCKABLE_FUNCTION(, THREADAPI_RESULT, ThreadAPI_Create, THREAD_HANDLE*, threadHandle, THREAD_START_FUNC, func, void*, arg); 49 | 50 | /** 51 | * @brief Blocks the calling thread by waiting on the thread identified by 52 | * the @p threadHandle argument to complete. 53 | * 54 | * @param threadHandle The handle of the thread to wait for completion. 55 | * @param res The result returned by the thread which is passed 56 | * to the ::ThreadAPI_Exit function. 57 | * 58 | * When the @p threadHandle thread completes, all resources associated 59 | * with the thread must be released and the thread handle will no 60 | * longer be valid. 61 | * 62 | * @return @c THREADAPI_OK if the API call is successful or an error 63 | * code in case it fails. 64 | */ 65 | MOCKABLE_FUNCTION(, THREADAPI_RESULT, ThreadAPI_Join, THREAD_HANDLE, threadHandle, int*, res); 66 | 67 | /** 68 | * @brief This function is called by a thread when the thread exits. 69 | * 70 | * @param res An integer that represents the exit status of the thread. 71 | * 72 | * This function is called by a thread when the thread exits in order 73 | * to return a result value to the caller of the ::ThreadAPI_Join 74 | * function. The @p res value must be copied into the @p res out 75 | * argument passed to the ::ThreadAPI_Join function. 76 | */ 77 | MOCKABLE_FUNCTION(, void, ThreadAPI_Exit, int, res); 78 | 79 | /** 80 | * @brief Sleeps the current thread for the given number of milliseconds. 81 | * 82 | * @param milliseconds The number of milliseconds to sleep. 83 | */ 84 | MOCKABLE_FUNCTION(, void, ThreadAPI_Sleep, unsigned int, milliseconds); 85 | 86 | #ifdef __cplusplus 87 | } 88 | #endif 89 | 90 | #endif /* THREADAPI_H */ 91 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/tickcounter.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TICKCOUNTER_H 5 | #define TICKCOUNTER_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /* __cplusplus */ 10 | 11 | #include 12 | 13 | #include "umock_c_prod.h" 14 | 15 | typedef uint_fast32_t tickcounter_ms_t; 16 | typedef struct TICK_COUNTER_INSTANCE_TAG* TICK_COUNTER_HANDLE; 17 | 18 | MOCKABLE_FUNCTION(, TICK_COUNTER_HANDLE, tickcounter_create); 19 | MOCKABLE_FUNCTION(, void, tickcounter_destroy, TICK_COUNTER_HANDLE, tick_counter); 20 | MOCKABLE_FUNCTION(, int, tickcounter_get_current_ms, TICK_COUNTER_HANDLE, tick_counter, tickcounter_ms_t*, current_ms); 21 | 22 | #ifdef __cplusplus 23 | } 24 | #endif /* __cplusplus */ 25 | 26 | #endif /* TICKCOUNTER_H */ 27 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/tls_config.h: -------------------------------------------------------------------------------- 1 | #ifndef __TLS_CONFIG_H__ 2 | #define __TLS_CONFIG_H__ 3 | 4 | // WolfSSL or mbedTLS 5 | //#define USE_WOLF_SSL 6 | #define USE_MBED_TLS 7 | 8 | #endif // __TLS_CONFIG_H__ -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/tlsio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TLSIO_H 5 | #define TLSIO_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #endif /* __cplusplus */ 10 | 11 | #include "xio.h" 12 | 13 | typedef struct TLSIO_CONFIG_TAG 14 | { 15 | const char* hostname; 16 | int port; 17 | const IO_INTERFACE_DESCRIPTION* underlying_io_interface; 18 | void* underlying_io_parameters; 19 | } TLSIO_CONFIG; 20 | 21 | #ifdef __cplusplus 22 | } 23 | #endif /* __cplusplus */ 24 | 25 | #endif /* TLSIO_H */ 26 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/tlsio_mbedtls.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TLSIO_MBEDTLS_H 5 | #define TLSIO_MBEDTLS_H 6 | 7 | #include "azure_c_shared_utility/tls_config.h" 8 | 9 | #ifdef USE_MBED_TLS 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #include 14 | #else 15 | #include 16 | #endif /* __cplusplus */ 17 | 18 | #include "xio.h" 19 | #include "xlogging.h" 20 | #include "optionhandler.h" 21 | 22 | extern CONCRETE_IO_HANDLE tlsio_mbedtls_create(void* io_create_parameters); 23 | extern void tlsio_mbedtls_destroy(CONCRETE_IO_HANDLE tls_io); 24 | extern int tlsio_mbedtls_open(CONCRETE_IO_HANDLE tls_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context); 25 | extern int tlsio_mbedtls_close(CONCRETE_IO_HANDLE tls_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context); 26 | extern int tlsio_mbedtls_send(CONCRETE_IO_HANDLE tls_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context); 27 | extern void tlsio_mbedtls_dowork(CONCRETE_IO_HANDLE tls_io); 28 | extern int tlsio_mbedtls_setoption(CONCRETE_IO_HANDLE tls_io, const char* optionName, const void* value); 29 | extern OPTIONHANDLER_HANDLE tlsio_mbedtls_retrieveoptions(CONCRETE_IO_HANDLE handle); 30 | 31 | extern const IO_INTERFACE_DESCRIPTION* tlsio_mbedtls_get_interface_description(void); 32 | 33 | #ifdef __cplusplus 34 | } 35 | #endif /* __cplusplus */ 36 | 37 | #endif /* USE_MBED_TLS */ 38 | 39 | #endif /* TLSIO_MBEDTLS_H */ 40 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/tlsio_openssl.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TLSIO_OPENSSL_H 5 | #define TLSIO_OPENSSL_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #include 10 | #else 11 | #include 12 | #endif /* __cplusplus */ 13 | 14 | #include "xio.h" 15 | #include "umock_c_prod.h" 16 | 17 | MOCKABLE_FUNCTION(, int, tlsio_openssl_init); 18 | MOCKABLE_FUNCTION(, void, tlsio_openssl_deinit); 19 | 20 | MOCKABLE_FUNCTION(, CONCRETE_IO_HANDLE, tlsio_openssl_create, void*, io_create_parameters); 21 | MOCKABLE_FUNCTION(, void, tlsio_openssl_destroy, CONCRETE_IO_HANDLE, tls_io); 22 | MOCKABLE_FUNCTION(, int, tlsio_openssl_open, CONCRETE_IO_HANDLE, tls_io, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context); 23 | MOCKABLE_FUNCTION(, int, tlsio_openssl_close, CONCRETE_IO_HANDLE, tls_io, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context); 24 | MOCKABLE_FUNCTION(, int, tlsio_openssl_send, CONCRETE_IO_HANDLE, tls_io, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context); 25 | MOCKABLE_FUNCTION(, void, tlsio_openssl_dowork, CONCRETE_IO_HANDLE, tls_io); 26 | MOCKABLE_FUNCTION(, int, tlsio_openssl_setoption, CONCRETE_IO_HANDLE, tls_io, const char*, optionName, const void*, value); 27 | 28 | MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_openssl_get_interface_description); 29 | 30 | #ifdef __cplusplus 31 | } 32 | #endif /* __cplusplus */ 33 | 34 | #endif /* TLSIO_OPENSSL_H */ -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/tlsio_options.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // tlsio_options handles only the most commonly-used options for tlsio adapters. Options 5 | // not supported by this component may be handled in the tlsio adapter instead. 6 | 7 | #ifndef TLSIO_OPTIONS_H 8 | #define TLSIO_OPTIONS_H 9 | 10 | #include "xio.h" 11 | #include "umock_c_prod.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" { 15 | #endif /* __cplusplus */ 16 | 17 | // This enum identifies individual options 18 | typedef enum TLSIO_OPTION_BIT_TAG 19 | { 20 | TLSIO_OPTION_BIT_NONE = 0x00, 21 | TLSIO_OPTION_BIT_TRUSTED_CERTS = 0x01, 22 | TLSIO_OPTION_BIT_x509_RSA_CERT = 0x02, 23 | TLSIO_OPTION_BIT_x509_ECC_CERT = 0x04, 24 | } TLSIO_OPTION_BIT; 25 | 26 | typedef enum TLSIO_OPTIONS_x509_TYPE_TAG 27 | { 28 | TLSIO_OPTIONS_x509_TYPE_UNSPECIFIED = TLSIO_OPTION_BIT_NONE, 29 | TLSIO_OPTIONS_x509_TYPE_RSA = TLSIO_OPTION_BIT_x509_RSA_CERT, 30 | TLSIO_OPTIONS_x509_TYPE_ECC = TLSIO_OPTION_BIT_x509_ECC_CERT 31 | } TLSIO_OPTIONS_x509_TYPE; 32 | 33 | typedef enum TLSIO_OPTIONS_RESULT_TAG 34 | { 35 | TLSIO_OPTIONS_RESULT_SUCCESS, 36 | TLSIO_OPTIONS_RESULT_NOT_HANDLED, 37 | TLSIO_OPTIONS_RESULT_ERROR 38 | } TLSIO_OPTIONS_RESULT; 39 | 40 | 41 | // This struct contains the commonly-used options which 42 | // are supported by tlsio_options. 43 | typedef struct TLSIO_OPTIONS_TAG 44 | { 45 | int supported_options; 46 | const char* trusted_certs; 47 | TLSIO_OPTIONS_x509_TYPE x509_type; 48 | const char* x509_cert; 49 | const char* x509_key; 50 | } TLSIO_OPTIONS; 51 | 52 | // Initialize the TLSIO_OPTIONS struct and specify which options are supported as a bit-or'ed 53 | // set of TLSIO_OPTION_BIT. For the x509 certs, only the *_CERT bit need be specified; the *_KEY 54 | // is understood to go with the cert. 55 | void tlsio_options_initialize(TLSIO_OPTIONS* options, int option_caps); 56 | 57 | // This should be called in the tlsio destructor 58 | void tlsio_options_release_resources(TLSIO_OPTIONS* options); 59 | 60 | // xio requires the implementation of four functions: xio_setoption, xio_retrieveoptions, 61 | // an anonymous clone_option, and an anonymous destroy_option. 62 | 63 | // The helper for xio_setoption 64 | TLSIO_OPTIONS_RESULT tlsio_options_set(TLSIO_OPTIONS* options, 65 | const char* optionName, const void* value); 66 | 67 | // Use this helper for xio_retrieveoptions if this helper covers all your tlsio options 68 | OPTIONHANDLER_HANDLE tlsio_options_retrieve_options(TLSIO_OPTIONS* options, pfSetOption setOption); 69 | 70 | // Use this helper for xio_retrieveoptions if your tlsio supports more options than this helper does 71 | OPTIONHANDLER_HANDLE tlsio_options_retrieve_options_ex(TLSIO_OPTIONS* options, 72 | pfCloneOption cloneOption, pfDestroyOption destroyOption, pfSetOption setOption); 73 | 74 | // The helper for the anonymous clone_option -- needed only to support extra options 75 | TLSIO_OPTIONS_RESULT tlsio_options_clone_option(const char* name, const void* value, void** out_value); 76 | 77 | // The helper for the anonymous destroy_option -- needed only to support extra options 78 | TLSIO_OPTIONS_RESULT tlsio_options_destroy_option(const char* name, const void* value); 79 | 80 | 81 | #ifdef __cplusplus 82 | } 83 | #endif /* __cplusplus */ 84 | 85 | #endif /* TLSIO_OPTIONS_H */ 86 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #undef MOCKABLE_FUNCTION 5 | 6 | /* This header is meant to be included by production code headers, so that the MOCKABLE_FUNCTION gets enabled. */ 7 | /* 8 | If you are porting to a new platform and do not want to build the tests, but only the production code, 9 | simply make sure that this file is in the include path (either by copying it to your inc folder or 10 | by adjusting the include paths). 11 | */ 12 | 13 | #ifdef ENABLE_MOCKS 14 | 15 | /* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/ 16 | #define MOCKABLE_FUNCTION(modifiers, result, function, ...) \ 17 | MOCKABLE_FUNCTION_UMOCK_INTERNAL_WITH_MOCK(modifiers, result, function, __VA_ARGS__) 18 | 19 | #include "umock_c.h" 20 | 21 | #else 22 | 23 | #include "macro_utils.h" 24 | 25 | #define UMOCK_C_PROD_ARG_IN_SIGNATURE(count, arg_type, arg_name) arg_type arg_name IFCOMMA(count) 26 | 27 | /* Codes_SRS_UMOCK_C_LIB_01_002: [The macro shall generate a function signature in case ENABLE_MOCKS is not defined.] */ 28 | /* Codes_SRS_UMOCK_C_LIB_01_005: [**If ENABLE_MOCKS is not defined, MOCKABLE_FUNCTION shall only generate a declaration for the function.] */ 29 | /* Codes_SRS_UMOCK_C_LIB_01_001: [MOCKABLE_FUNCTION shall be used to wrap function definition allowing the user to declare a function that can be mocked.]*/ 30 | #define MOCKABLE_FUNCTION(modifiers, result, function, ...) \ 31 | result modifiers function(IF(COUNT_ARG(__VA_ARGS__),,void) FOR_EACH_2_COUNTED(UMOCK_C_PROD_ARG_IN_SIGNATURE, __VA_ARGS__)); 32 | 33 | #endif 34 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/uniqueid.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef UNIQUEID_H 5 | #define UNIQUEID_H 6 | 7 | #include "macro_utils.h" 8 | 9 | #ifdef __cplusplus 10 | #include 11 | extern "C" { 12 | #else 13 | #include 14 | #endif 15 | 16 | #include "umock_c_prod.h" 17 | 18 | #define UNIQUEID_RESULT_VALUES \ 19 | UNIQUEID_OK, \ 20 | UNIQUEID_INVALID_ARG, \ 21 | UNIQUEID_ERROR 22 | 23 | DEFINE_ENUM(UNIQUEID_RESULT, UNIQUEID_RESULT_VALUES) 24 | 25 | MOCKABLE_FUNCTION(, UNIQUEID_RESULT, UniqueId_Generate, char*, uid, size_t, bufferSize); 26 | 27 | /* 28 | * @brief Gets the string representation of the UUID bytes. 29 | * @param uid_bytes Sequence of bytes representing an UUID. 30 | * @param uid_size Number of bytes representing the UUID (default is 16). 31 | * @param output_string Pre-allocated buffer where the UUID will be stored as string (e.g., "7f907d75-5e13-44cf-a1a3-19a01a2b4528"). 32 | * @returns UNIQUEID_OK if no errors occur, UNIQUEID_INVALID_ARG otherwise. 33 | */ 34 | MOCKABLE_FUNCTION(, UNIQUEID_RESULT, UniqueId_GetStringFromBytes, unsigned char*, uid, size_t, uid_size, char*, output_string); 35 | 36 | #ifdef __cplusplus 37 | } 38 | #endif 39 | 40 | #endif /* UNIQUEID_H */ 41 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/urlencode.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef URLENCODE_H 5 | #define URLENCODE_H 6 | 7 | #include "strings.h" 8 | 9 | #include "umock_c_prod.h" 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | MOCKABLE_FUNCTION(, STRING_HANDLE, URL_EncodeString, const char*, textEncode); 16 | MOCKABLE_FUNCTION(, STRING_HANDLE, URL_Encode, STRING_HANDLE, input); 17 | 18 | #ifdef __cplusplus 19 | } 20 | #endif 21 | 22 | #endif /* URLENCODE_H */ 23 | 24 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/vector.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef VECTOR_H 5 | #define VECTOR_H 6 | 7 | #include "crt_abstractions.h" 8 | #include "umock_c_prod.h" 9 | 10 | #ifdef __cplusplus 11 | #include 12 | #include 13 | extern "C" 14 | { 15 | #else 16 | #include 17 | #include 18 | #endif 19 | 20 | #include "vector_types.h" 21 | 22 | /* creation */ 23 | MOCKABLE_FUNCTION(, VECTOR_HANDLE, VECTOR_create, size_t, elementSize); 24 | MOCKABLE_FUNCTION(, VECTOR_HANDLE, VECTOR_move, VECTOR_HANDLE, handle); 25 | MOCKABLE_FUNCTION(, void, VECTOR_destroy, VECTOR_HANDLE, handle); 26 | 27 | /* insertion */ 28 | MOCKABLE_FUNCTION(, int, VECTOR_push_back, VECTOR_HANDLE, handle, const void*, elements, size_t, numElements); 29 | 30 | /* removal */ 31 | MOCKABLE_FUNCTION(, void, VECTOR_erase, VECTOR_HANDLE, handle, void*, elements, size_t, numElements); 32 | MOCKABLE_FUNCTION(, void, VECTOR_clear, VECTOR_HANDLE, handle); 33 | 34 | /* access */ 35 | MOCKABLE_FUNCTION(, void*, VECTOR_element, VECTOR_HANDLE, handle, size_t, index); 36 | MOCKABLE_FUNCTION(, void*, VECTOR_front, VECTOR_HANDLE, handle); 37 | MOCKABLE_FUNCTION(, void*, VECTOR_back, VECTOR_HANDLE, handle); 38 | MOCKABLE_FUNCTION(, void*, VECTOR_find_if, VECTOR_HANDLE, handle, PREDICATE_FUNCTION, pred, const void*, value); 39 | 40 | /* capacity */ 41 | MOCKABLE_FUNCTION(, size_t, VECTOR_size, VECTOR_HANDLE, handle); 42 | 43 | #ifdef __cplusplus 44 | } 45 | #endif 46 | 47 | #endif /* VECTOR_H */ 48 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/vector_types.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef VECTOR_TYPES_H 5 | #define VECTOR_TYPES_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | extern "C" 10 | { 11 | #else 12 | #include 13 | #endif 14 | 15 | typedef struct VECTOR_TAG* VECTOR_HANDLE; 16 | 17 | typedef bool(*PREDICATE_FUNCTION)(const void* element, const void* value); 18 | 19 | #ifdef __cplusplus 20 | } 21 | #endif 22 | 23 | #endif /* VECTOR_TYPES_H */ 24 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/vector_types_internal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef VECTOR_TYPES_INTERNAL_H 5 | #define VECTOR_TYPES_INTERNAL_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #else 10 | #include 11 | #endif 12 | 13 | typedef struct VECTOR_TAG 14 | { 15 | void* storage; 16 | size_t count; 17 | size_t elementSize; 18 | } VECTOR; 19 | 20 | #endif /* VECTOR_TYPES_INTERNAL_H */ 21 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/inc/azure_c_shared_utility/xio.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef XIO_H 5 | #define XIO_H 6 | 7 | #include "optionhandler.h" 8 | 9 | #include "umock_c_prod.h" 10 | #include "macro_utils.h" 11 | 12 | #ifdef __cplusplus 13 | #include 14 | extern "C" { 15 | #else 16 | #include 17 | #endif /* __cplusplus */ 18 | 19 | typedef struct XIO_INSTANCE_TAG* XIO_HANDLE; 20 | typedef void* CONCRETE_IO_HANDLE; 21 | 22 | #define IO_SEND_RESULT_VALUES \ 23 | IO_SEND_OK, \ 24 | IO_SEND_ERROR, \ 25 | IO_SEND_CANCELLED 26 | 27 | DEFINE_ENUM(IO_SEND_RESULT, IO_SEND_RESULT_VALUES); 28 | 29 | #define IO_OPEN_RESULT_VALUES \ 30 | IO_OPEN_OK, \ 31 | IO_OPEN_ERROR, \ 32 | IO_OPEN_CANCELLED 33 | 34 | DEFINE_ENUM(IO_OPEN_RESULT, IO_OPEN_RESULT_VALUES); 35 | 36 | typedef void(*ON_BYTES_RECEIVED)(void* context, const unsigned char* buffer, size_t size); 37 | typedef void(*ON_SEND_COMPLETE)(void* context, IO_SEND_RESULT send_result); 38 | typedef void(*ON_IO_OPEN_COMPLETE)(void* context, IO_OPEN_RESULT open_result); 39 | typedef void(*ON_IO_CLOSE_COMPLETE)(void* context); 40 | typedef void(*ON_IO_ERROR)(void* context); 41 | 42 | typedef OPTIONHANDLER_HANDLE (*IO_RETRIEVEOPTIONS)(CONCRETE_IO_HANDLE concrete_io); 43 | typedef CONCRETE_IO_HANDLE(*IO_CREATE)(void* io_create_parameters); 44 | typedef void(*IO_DESTROY)(CONCRETE_IO_HANDLE concrete_io); 45 | typedef int(*IO_OPEN)(CONCRETE_IO_HANDLE concrete_io, ON_IO_OPEN_COMPLETE on_io_open_complete, void* on_io_open_complete_context, ON_BYTES_RECEIVED on_bytes_received, void* on_bytes_received_context, ON_IO_ERROR on_io_error, void* on_io_error_context); 46 | typedef int(*IO_CLOSE)(CONCRETE_IO_HANDLE concrete_io, ON_IO_CLOSE_COMPLETE on_io_close_complete, void* callback_context); 47 | typedef int(*IO_SEND)(CONCRETE_IO_HANDLE concrete_io, const void* buffer, size_t size, ON_SEND_COMPLETE on_send_complete, void* callback_context); 48 | typedef void(*IO_DOWORK)(CONCRETE_IO_HANDLE concrete_io); 49 | typedef int(*IO_SETOPTION)(CONCRETE_IO_HANDLE concrete_io, const char* optionName, const void* value); 50 | 51 | 52 | typedef struct IO_INTERFACE_DESCRIPTION_TAG 53 | { 54 | IO_RETRIEVEOPTIONS concrete_io_retrieveoptions; 55 | IO_CREATE concrete_io_create; 56 | IO_DESTROY concrete_io_destroy; 57 | IO_OPEN concrete_io_open; 58 | IO_CLOSE concrete_io_close; 59 | IO_SEND concrete_io_send; 60 | IO_DOWORK concrete_io_dowork; 61 | IO_SETOPTION concrete_io_setoption; 62 | } IO_INTERFACE_DESCRIPTION; 63 | 64 | MOCKABLE_FUNCTION(, XIO_HANDLE, xio_create, const IO_INTERFACE_DESCRIPTION*, io_interface_description, const void*, io_create_parameters); 65 | MOCKABLE_FUNCTION(, void, xio_destroy, XIO_HANDLE, xio); 66 | MOCKABLE_FUNCTION(, int, xio_open, XIO_HANDLE, xio, ON_IO_OPEN_COMPLETE, on_io_open_complete, void*, on_io_open_complete_context, ON_BYTES_RECEIVED, on_bytes_received, void*, on_bytes_received_context, ON_IO_ERROR, on_io_error, void*, on_io_error_context); 67 | MOCKABLE_FUNCTION(, int, xio_close, XIO_HANDLE, xio, ON_IO_CLOSE_COMPLETE, on_io_close_complete, void*, callback_context); 68 | MOCKABLE_FUNCTION(, int, xio_send, XIO_HANDLE, xio, const void*, buffer, size_t, size, ON_SEND_COMPLETE, on_send_complete, void*, callback_context); 69 | MOCKABLE_FUNCTION(, void, xio_dowork, XIO_HANDLE, xio); 70 | MOCKABLE_FUNCTION(, int, xio_setoption, XIO_HANDLE, xio, const char*, optionName, const void*, value); 71 | MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, xio_retrieveoptions, XIO_HANDLE, xio); 72 | 73 | #ifdef __cplusplus 74 | } 75 | #endif /* __cplusplus */ 76 | 77 | #endif /* XIO_H */ 78 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/agenttime.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "az_iot/c-utility/inc/azure_c_shared_utility/gballoc.h" 5 | 6 | #include 7 | #include "az_iot/c-utility/inc/azure_c_shared_utility/agenttime.h" 8 | 9 | time_t get_time(time_t* p) 10 | { 11 | return time(p); 12 | } 13 | 14 | struct tm* get_gmtime(time_t* currentTime) 15 | { 16 | return gmtime(currentTime); 17 | } 18 | 19 | time_t get_mktime(struct tm* cal_time) 20 | { 21 | return mktime(cal_time); 22 | } 23 | 24 | char* get_ctime(time_t* timeToGet) 25 | { 26 | return ctime(timeToGet); 27 | } 28 | 29 | double get_difftime(time_t stopTime, time_t startTime) 30 | { 31 | return difftime(stopTime, startTime); 32 | } 33 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/freertos/lock.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "az_iot/c-utility/inc/azure_c_shared_utility/lock.h" 5 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 6 | 7 | 8 | #include "freertos/FreeRTOS.h" 9 | #include "freertos/semphr.h" 10 | 11 | LOCK_HANDLE Lock_Init(void) 12 | { 13 | /* Codes_SRS_LOCK_10_002: [Lock_Init on success shall return a valid lock handle which should be a non NULL value] */ 14 | /* Codes_SRS_LOCK_10_003: [Lock_Init on error shall return NULL ] */ 15 | // xSemaphoreCreateMutex is the obvious choice, but it returns a recursive 16 | // sync object, which we do not want for the lock adapter. 17 | SemaphoreHandle_t result = xSemaphoreCreateBinary(); 18 | if (result != NULL) 19 | { 20 | int gv = xSemaphoreGive(result); 21 | if (gv != pdTRUE) 22 | { 23 | LogError("xSemaphoreGive failed after create."); 24 | vSemaphoreDelete(result); 25 | result = NULL; 26 | } 27 | } 28 | else 29 | { 30 | LogError("xSemaphoreCreateBinary failed."); 31 | } 32 | 33 | return (LOCK_HANDLE)result; 34 | } 35 | 36 | LOCK_RESULT Lock_Deinit(LOCK_HANDLE handle) 37 | { 38 | LOCK_RESULT result; 39 | if (handle == NULL) 40 | { 41 | /* Codes_SRS_LOCK_10_007: [Lock_Deinit on NULL handle passed returns LOCK_ERROR] */ 42 | LogError("Invalid argument; handle is NULL."); 43 | result = LOCK_ERROR; 44 | } 45 | else 46 | { 47 | /* Codes_SRS_LOCK_10_012: [Lock_Deinit frees the memory pointed by handle] */ 48 | vSemaphoreDelete((SemaphoreHandle_t)handle); 49 | result = LOCK_OK; 50 | } 51 | 52 | return result; 53 | } 54 | 55 | LOCK_RESULT Lock(LOCK_HANDLE handle) 56 | { 57 | LOCK_RESULT result; 58 | if (handle == NULL) 59 | { 60 | /* Codes_SRS_LOCK_10_007: [Lock on NULL handle passed returns LOCK_ERROR] */ 61 | LogError("Invalid argument; handle is NULL."); 62 | result = LOCK_ERROR; 63 | } 64 | else 65 | { 66 | int rv = xSemaphoreTake((SemaphoreHandle_t)handle, portMAX_DELAY); 67 | switch (rv) 68 | { 69 | case pdTRUE: 70 | /* Codes_SRS_LOCK_10_005: [Lock on success shall return LOCK_OK] */ 71 | result = LOCK_OK; 72 | break; 73 | default: 74 | LogError("xSemaphoreTake failed."); 75 | /* Codes_SRS_LOCK_10_006: [Lock on error shall return LOCK_ERROR] */ 76 | result = LOCK_ERROR; 77 | break; 78 | } 79 | } 80 | 81 | return result; 82 | } 83 | 84 | LOCK_RESULT Unlock(LOCK_HANDLE handle) 85 | { 86 | LOCK_RESULT result; 87 | if (handle == NULL) 88 | { 89 | /* Codes_SRS_LOCK_10_007: [Unlock on NULL handle passed returns LOCK_ERROR] */ 90 | LogError("Invalid argument; handle is NULL."); 91 | result = LOCK_ERROR; 92 | } 93 | else 94 | { 95 | int rv = xSemaphoreGive((SemaphoreHandle_t)handle); 96 | switch (rv) 97 | { 98 | case pdTRUE: 99 | /* Codes_SRS_LOCK_10_005: [Lock on success shall return LOCK_OK] */ 100 | result = LOCK_OK; 101 | break; 102 | default: 103 | LogError("xSemaphoreGive failed."); 104 | /* Codes_SRS_LOCK_10_006: [Lock on error shall return LOCK_ERROR] */ 105 | result = LOCK_ERROR; 106 | break; 107 | } 108 | } 109 | 110 | return result; 111 | } 112 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/freertos/threadapi.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 5 | 6 | /*Codes_SRS_THREADAPI_FREERTOS_30_001: [ The threadapi_freertos shall implement the method ThreadAPI_Sleep defined in threadapi.h ]*/ 7 | #include "az_iot/c-utility/inc/azure_c_shared_utility/threadapi.h" 8 | 9 | #include "freertos/FreeRTOS.h" 10 | #include "freertos/task.h" 11 | 12 | /*Codes_SRS_THREADAPI_FREERTOS_30_002: [ The ThreadAPI_Sleep shall receive a time in milliseconds. ]*/ 13 | /*Codes_SRS_THREADAPI_FREERTOS_30_003: [ The ThreadAPI_Sleep shall stop the thread for the specified time. ]*/ 14 | void ThreadAPI_Sleep(unsigned int milliseconds) 15 | { 16 | vTaskDelay((milliseconds * CONFIG_FREERTOS_HZ) / 1000); 17 | } 18 | 19 | /*Codes_SRS_THREADAPI_FREERTOS_30_004: [ FreeRTOS is not guaranteed to support threading, so ThreadAPI_Create shall return THREADAPI_ERROR. ]*/ 20 | THREADAPI_RESULT ThreadAPI_Create(THREAD_HANDLE* threadHandle, THREAD_START_FUNC func, void* arg) 21 | { 22 | (void)threadHandle; 23 | (void)func; 24 | (void)arg; 25 | LogError("FreeRTOS does not support multi-threading."); 26 | return THREADAPI_ERROR; 27 | } 28 | 29 | /*Codes_SRS_THREADAPI_FREERTOS_30_005: [ FreeRTOS is not guaranteed to support threading, so ThreadAPI_Join shall return THREADAPI_ERROR. ]*/ 30 | THREADAPI_RESULT ThreadAPI_Join(THREAD_HANDLE threadHandle, int* res) 31 | { 32 | (void)threadHandle; 33 | (void)res; 34 | LogError("FreeRTOS does not support multi-threading."); 35 | return THREADAPI_ERROR; 36 | } 37 | 38 | /*Codes_SRS_THREADAPI_FREERTOS_30_006: [ FreeRTOS is not guaranteed to support threading, so ThreadAPI_Exit shall do nothing. ]*/ 39 | void ThreadAPI_Exit(int res) 40 | { 41 | (void)res; 42 | LogError("FreeRTOS does not support multi-threading."); 43 | } 44 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/freertos/tickcounter.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include "az_iot/c-utility/inc/azure_c_shared_utility/gballoc.h" 6 | #include 7 | #include 8 | 9 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_001: [ The tickcounter_freertos adapter shall use the following data types as defined in tickcounter.h. */ 10 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_002: [ The tickcounter_freertos adapter shall implement the API calls defined in tickcounter.h */ 11 | #include "az_iot/c-utility/inc/azure_c_shared_utility/tickcounter.h" 12 | #include "az_iot/c-utility/inc/azure_c_shared_utility/optimize_size.h" 13 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 14 | 15 | #include "freertos/FreeRTOS.h" 16 | #include "freertos/task.h" 17 | 18 | typedef struct TICK_COUNTER_INSTANCE_TAG 19 | { 20 | uint32_t original_tick_count; 21 | } TICK_COUNTER_INSTANCE; 22 | 23 | TICK_COUNTER_HANDLE tickcounter_create(void) 24 | { 25 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_003: [ `tickcounter_create` shall allocate and initialize an internally-defined TICK_COUNTER_INSTANCE structure and return its pointer on success.] */ 26 | TICK_COUNTER_INSTANCE* result = (TICK_COUNTER_INSTANCE*)malloc(sizeof(TICK_COUNTER_INSTANCE)); 27 | if (result == NULL) 28 | { 29 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_004: [ If allocation of the internally-defined TICK_COUNTER_INSTANCE structure fails, `tickcounter_create` shall return NULL.] */ 30 | LogError("Failed creating tick counter"); 31 | } 32 | else 33 | { 34 | // The FreeRTOS call xTaskGetTickCount has no failure path 35 | // Store the initial tick count in order to meet these two requirements: 36 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_009: [ tickcounter_get_current_ms shall set *current_ms to the number of milliseconds elapsed since the tickcounter_create call for the specified tick_counter and return 0 to indicate success in situations where the FreeRTOS call xTaskGetTickCount has not experienced overflow between the calls to tickcounter_create and tickcounter_get_current_ms. (In FreeRTOS this call has no failure case.) ] */ 37 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_010: [ tickcounter_get_current_ms shall set *current_ms to the number of milliseconds elapsed since the tickcounter_create call for the specified tick_counter and return 0 to indicate success in situations where the FreeRTOS call xTaskGetTickCount has experienced overflow between the calls to tickcounter_create and tickcounter_get_current_ms. (In FreeRTOS this call has no failure case.) ] */ 38 | result->original_tick_count = xTaskGetTickCount(); 39 | } 40 | return result; 41 | } 42 | 43 | void tickcounter_destroy(TICK_COUNTER_HANDLE tick_counter) 44 | { 45 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_006: [ If the tick_counter parameter is NULL, tickcounter_destroy shall do nothing. ] */ 46 | if (tick_counter != NULL) 47 | { 48 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_005: [ tickcounter_destroy shall delete the internally-defined TICK_COUNTER_INSTANCE structure specified by the tick_counter parameter. (This call has no failure case.) ] */ 49 | free(tick_counter); 50 | } 51 | } 52 | 53 | int tickcounter_get_current_ms(TICK_COUNTER_HANDLE tick_counter, tickcounter_ms_t * current_ms) 54 | { 55 | int result; 56 | 57 | if (tick_counter == NULL || current_ms == NULL) 58 | { 59 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_007: [ If the tick_counter parameter is NULL, tickcounter_get_current_ms shall return a non-zero value to indicate error. ] */ 60 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_008: [ If the current_ms parameter is NULL, tickcounter_get_current_ms shall return a non-zero value to indicate error. ] */ 61 | LogError("Invalid Arguments."); 62 | result = __FAILURE__; 63 | } 64 | else 65 | { 66 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_009: [ tickcounter_get_current_ms shall set *current_ms to the number of milliseconds elapsed since the tickcounter_create call for the specified tick_counter and return 0 to indicate success (In FreeRTOS this call has no failure case.) ] */ 67 | /* Codes_SRS_TICKCOUNTER_FREERTOS_30_010: [ If the FreeRTOS call xTaskGetTickCount experiences a single overflow between the calls to tickcounter_create and tickcounter_get_current_ms, the tickcounter_get_current_ms call shall still return the correct interval. ] */ 68 | *current_ms = (tickcounter_ms_t)( 69 | // Subtraction of two uint32_t's followed by a cast to uint32_t 70 | // ensures that the result remains valid until the real difference exceeds 32 bits. 71 | ((uint32_t)(xTaskGetTickCount() - tick_counter->original_tick_count)) 72 | // Now that overflow behavior is ensured it is safe to scale. CONFIG_FREERTOS_HZ is typically 73 | // equal to 1000 or less, so overflow won't happen until the 49.7 day limit 74 | // of this call's effective uint32_t return value. 75 | * 1000.0 / CONFIG_FREERTOS_HZ 76 | ); 77 | result = 0; 78 | } 79 | 80 | return result; 81 | } 82 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/generic/refcount_os.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // This file gets included into refcount.h as a means of extending the behavior of 5 | // atomic increment, decrement, and test. 6 | // 7 | // The Azure IoT C SDK does not require thread-safe refcount operations, so 8 | // this file is appropriate for any device when using the Azure IoT C SDK. 9 | 10 | #ifndef REFCOUNT_OS_H__GENERIC 11 | #define REFCOUNT_OS_H__GENERIC 12 | 13 | #define COUNT_TYPE uint32_t 14 | 15 | #define DEC_RETURN_ZERO (0) 16 | #define INC_REF(type, var) ++((((REFCOUNT_TYPE(type)*)var)->count)) 17 | #define DEC_REF(type, var) --((((REFCOUNT_TYPE(type)*)var)->count)) 18 | 19 | #endif // REFCOUNT_OS_H__GENERIC 20 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/inc/dns_async.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file ssl_socket.h 5 | * @brief Implements socket creation for TLSIO adapters. 6 | */ 7 | 8 | #ifndef AZURE_IOT_DNS_H 9 | #define AZURE_IOT_DNS_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 16 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 17 | 18 | typedef void* DNS_ASYNC_HANDLE; 19 | 20 | // If options are added in future, DNS_ASYNC_OPTIONS will become a struct containing the options 21 | typedef void DNS_ASYNC_OPTIONS; 22 | 23 | /** 24 | * @brief Begin the process of an asynchronous DNS lookup. 25 | * 26 | * @param hostname The url of the host to look up. 27 | * 28 | * @return @c The newly created DNS_ASYNC_HANDLE. 29 | */ 30 | MOCKABLE_FUNCTION(, DNS_ASYNC_HANDLE, dns_async_create, const char*, hostname, DNS_ASYNC_OPTIONS*, options); 31 | 32 | /** 33 | * @brief Continue the lookup process and report its completion state. Must be polled repeatedly for completion. 34 | * 35 | * @param dns The DNS_ASYNC_HANDLE. 36 | * 37 | * @return @c A bool to indicate completion. 38 | */ 39 | MOCKABLE_FUNCTION(, bool, dns_async_is_lookup_complete, DNS_ASYNC_HANDLE, dns); 40 | 41 | /** 42 | * @brief Return the IPv4 of a completed lookup process. Call only after dns_async_is_lookup_complete indicates completion. 43 | * 44 | * @param dns The DNS_ASYNC_HANDLE. 45 | * 46 | * @return @c A uint32_t IPv4 address. 0 indicates failure or not finished. 47 | */ 48 | MOCKABLE_FUNCTION(, uint32_t, dns_async_get_ipv4, DNS_ASYNC_HANDLE, dns); 49 | 50 | /** 51 | * @brief Destroy the module. 52 | * 53 | * @param dns The DNS_ASYNC_HANDLE. 54 | */ 55 | MOCKABLE_FUNCTION(, void, dns_async_destroy, DNS_ASYNC_HANDLE, dns); 56 | 57 | 58 | #ifdef __cplusplus 59 | } 60 | #endif 61 | 62 | #endif /* AZURE_IOT_DNS_H */ 63 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/inc/sntp.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file threadapi.h 5 | * @brief This module implements support for creating new threads, 6 | * terminating threads and sleeping threads. 7 | */ 8 | 9 | #ifndef AZURE_IOT_SNTP_H 10 | #define AZURE_IOT_SNTP_H 11 | 12 | #ifdef __cplusplus 13 | extern "C" { 14 | #endif 15 | 16 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 17 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 18 | 19 | 20 | /** 21 | * @brief Set the url for the ntp server to be used. Must be called before 22 | * SNTP_Init. 23 | * 24 | * @param serverName The url of the ntp server to be used. The char array 25 | * passed in must remain valid between the SNTP_SetServerName and 26 | * the SNTP_Deinit calls. 27 | * 28 | * @return @c 0 if the API call is successful or an error 29 | * code in case it fails. 30 | */ 31 | MOCKABLE_FUNCTION(, int, SNTP_SetServerName, const char*, serverName); 32 | 33 | /** 34 | * @brief Performs platform-specific sntp initialization, then loops until 35 | * system time has been set from the ntp server. 36 | * 37 | * 38 | * @return @c 0 if the API call is successful or an error 39 | * code in case it fails. 40 | */ 41 | MOCKABLE_FUNCTION(, int, SNTP_Init); 42 | 43 | /** 44 | * @brief This function is called by a thread when the thread exits. 45 | */ 46 | MOCKABLE_FUNCTION(, void, SNTP_Deinit); 47 | 48 | 49 | #ifdef __cplusplus 50 | } 51 | #endif 52 | 53 | #endif /* AZURE_IOT_SNTP_H */ 54 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/inc/sntp_os.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | //This file pulls in OS-specific header files to allow compilation of socket_async.c under 5 | // most OS's except for Windows. 6 | 7 | // For ESP32 lwIP systems which use the ESP-IDF's non-standard lwIP include structure 8 | // Tested with: 9 | // ESP32 10 | 11 | #ifndef LWIP_SNTP_OS_H 12 | #define LWIP_SNTP_OS_H 13 | 14 | #include "apps/sntp/sntp.h" 15 | 16 | #endif // LWIP_SNTP_OS_H -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/inc/socket_async.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file socket_async.h 5 | * @brief Abstracts non-blocking sockets. 6 | */ 7 | 8 | #ifndef AZURE_SOCKET_ASYNC_H 9 | #define AZURE_SOCKET_ASYNC_H 10 | 11 | #ifdef __cplusplus 12 | extern "C" { 13 | #endif 14 | 15 | #include 16 | #include 17 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 18 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 19 | 20 | // socket_async exposes asynchronous socket operations while hiding OS-specifics. Committing to 21 | // asynchronous operation also simplifies the interface compared to generic sockets. 22 | 23 | #define SOCKET_ASYNC_INVALID_SOCKET -1 24 | 25 | typedef struct 26 | { 27 | // Keepalive is disabled by default at the TCP level. If keepalive is desired, it 28 | // is strongly recommended to use one of the higher level keepalive (ping) options rather 29 | // than the TCP level because the higher level options provide server connection status 30 | // in addition to keeping the connection open. 31 | int keep_alive; // < 0 for system defaults, >= 0 to use supplied keep_alive, idle, interval, and count 32 | int keep_idle; // seconds before first keepalive packet (ignored if keep_alive <= 0) 33 | int keep_interval; // seconds between keepalive packets (ignored if keep_alive <= 0) 34 | int keep_count; // number of times to try before declaring failure (ignored if keep_alive <= 0) 35 | // It is acceptable to extend this struct by adding members for future enhancement, 36 | // but existing members must not be altered to ensure back-compatibility. 37 | } SOCKET_ASYNC_OPTIONS; 38 | typedef SOCKET_ASYNC_OPTIONS* SOCKET_ASYNC_OPTIONS_HANDLE; 39 | 40 | typedef int SOCKET_ASYNC_HANDLE; 41 | 42 | /** 43 | * @brief Create a non-blocking socket that is correctly configured for asynchronous use. 44 | * 45 | * @param sock Receives the created SOCKET_ASYNC_HANDLE. 46 | * 47 | * @param host_ipv4 The IPv4 of the SSL server to be contacted. 48 | * 49 | * @param port The port of the SSL server to use. 50 | * 51 | * @param is_UDP True for UDP, false for TCP. 52 | * 53 | * @param options A pointer to SOCKET_ASYNC_OPTIONS used during socket_async_create 54 | * for TCP connections only. May be NULL. Ignored for UDP sockets. 55 | * Need only exist for the duration of the socket_async_create call. 56 | * 57 | * @return @c The created and configured SOCKET_ASYNC_HANDLE if the API call is successful 58 | * or SOCKET_ASYNC_INVALID_SOCKET in case it fails. Error logging is 59 | * performed by the underlying concrete implementation, so no 60 | * further error logging is necessary. 61 | */ 62 | MOCKABLE_FUNCTION(, SOCKET_ASYNC_HANDLE, socket_async_create, uint32_t, host_ipv4, uint16_t, port, bool, is_UDP, SOCKET_ASYNC_OPTIONS_HANDLE, options); 63 | 64 | /** 65 | * @brief Check whether a newly-created socket_async has completed its initial connection. 66 | * 67 | * @param sock The created SOCKET_ASYNC_HANDLE to check for connection completion. 68 | * 69 | * @param is_created Receives the completion state if successful, set to false on failure. 70 | * 71 | * @return @c 0 if the API call is successful. 72 | * __FAILURE__ means an unexpected error has occurred and the socket must be destroyed. 73 | */ 74 | MOCKABLE_FUNCTION(, int, socket_async_is_create_complete, SOCKET_ASYNC_HANDLE, sock, bool*, is_complete); 75 | 76 | /** 77 | * @brief Send a message on the specified socket. 78 | * 79 | * @param sock The socket to be used. 80 | * 81 | * @param buffer The buffer containing the message to transmit. 82 | * 83 | * @param size The number of bytes to transmit. 84 | * 85 | * @param sent_count Receives the number of bytes transmitted. The N == 0 86 | * case means normal operation but the socket's outgoing buffer was full. 87 | * 88 | * @return @c 0 if successful. 89 | * __FAILURE__ means an unexpected error has occurred and the socket must be destroyed. 90 | */ 91 | MOCKABLE_FUNCTION(, int, socket_async_send, SOCKET_ASYNC_HANDLE, sock, const void*, buffer, size_t, size, size_t*, sent_count); 92 | 93 | /** 94 | * @brief Receive a message on the specified socket. 95 | * 96 | * @param sock The socket to be used. 97 | * 98 | * @param buffer The buffer containing the message to receive. 99 | * 100 | * @param size The buffer size in bytes. 101 | * 102 | * @param received_count Receives the number of bytes received into the buffer. 103 | * 104 | * @return @c 0 if successful. 105 | * __FAILURE__ means an unexpected error has occurred and the socket must be destroyed. 106 | */ 107 | MOCKABLE_FUNCTION(, int, socket_async_receive, SOCKET_ASYNC_HANDLE, sock, void*, buffer, size_t, size, size_t*, received_count); 108 | 109 | 110 | /** 111 | * @brief Close the socket returned by socket_async_create. 112 | * 113 | * @param sock The socket to be destroyed (closed, in standard socket terms). 114 | */ 115 | MOCKABLE_FUNCTION(, void, socket_async_destroy, SOCKET_ASYNC_HANDLE, sock); 116 | 117 | 118 | #ifdef __cplusplus 119 | } 120 | #endif 121 | 122 | #endif /* AZURE_SOCKET_ASYNC_H */ 123 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/inc/socket_async_os.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | //This file pulls in OS-specific header files to allow compilation of socket_async.c under 5 | // most OS's except for Windows. 6 | 7 | // For lwIP systems 8 | // Tested with: 9 | // ESP32 10 | 11 | #ifndef SOCKET_ASYNC_OS_H 12 | #define SOCKET_ASYNC_OS_H 13 | 14 | #include "lwip/sockets.h" 15 | #include "lwip/netdb.h" 16 | 17 | #endif // SOCKET_ASYNC_OS_H -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/inc/tlsio_pal.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef TLSIO_PAL_H 5 | #define TLSIO_PAL_H 6 | 7 | #include "az_iot/c-utility/inc/azure_c_shared_utility/tlsio.h" 8 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" { 12 | #endif /* __cplusplus */ 13 | 14 | MOCKABLE_FUNCTION(, const IO_INTERFACE_DESCRIPTION*, tlsio_pal_get_interface_description); 15 | 16 | #ifdef __cplusplus 17 | } 18 | #endif /* __cplusplus */ 19 | 20 | #endif /* TLSIO_PAL_H */ 21 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/lwip/sntp_lwip.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 5 | 6 | /*Codes_SRS_SNTP_LWIP_30_001: [ The ntp_lwip shall implement the methods defined in sntp.h. ]*/ 7 | #include "../inc/sntp.h" 8 | #include "az_iot/c-utility/inc/azure_c_shared_utility/threadapi.h" 9 | #include "az_iot/c-utility/inc/azure_c_shared_utility/agenttime.h" 10 | #include "sntp_os.h" 11 | 12 | 13 | /*Codes_SRS_SNTP_LWIP_30_002: [ The serverName parameter shall be an NTP server URL which shall not be validated. ]*/ 14 | /*Codes_SRS_SNTP_LWIP_30_003: [ The SNTP_SetServerName shall set the NTP server to be used by ntp_lwip and return 0 to indicate success.]*/ 15 | // 16 | // SNTP_SetServerName must be called before `SNTP_Init`. 17 | // The character array pointed to by `serverName` parameter must persist 18 | // between calls to `SNTP_SetServerName` and `SNTP_Deinit` because the 19 | // char* is stored and no copy of the string is made. 20 | // 21 | // SNTP_SetServerName is a wrapper for the lwIP call `sntp_setservername` 22 | // and defers parameter validation to the lwIP library. 23 | // 24 | // Future implementations of this adapter may allow multiple calls to 25 | // SNTP_SetServerName in order to support multiple servers. 26 | // 27 | int SNTP_SetServerName(const char* serverName) 28 | { 29 | // Future implementations could easily allow multiple calls to SNTP_SetServerName 30 | // by incrementing the index supplied to sntp_setservername 31 | sntp_setservername(0, (char*)serverName); 32 | return 0; 33 | } 34 | 35 | /*Codes_SRS_SNTP_LWIP_30_004: [ SNTP_Init shall initialize the SNTP client, contact the NTP server to set system time, then return 0 to indicate success (lwIP has no failure path). ]*/ 36 | int SNTP_Init() 37 | { 38 | LogInfo("Initializing SNTP"); 39 | sntp_setoperatingmode(SNTP_OPMODE_POLL); 40 | sntp_init(); 41 | time_t ts = 0; 42 | // Before 1980 is uninitialized 43 | while (ts < 10 * 365 * 24 * 3600) 44 | { 45 | ThreadAPI_Sleep(1000); 46 | ts = get_time(NULL); 47 | 48 | } 49 | LogInfo("SNTP initialization complete"); 50 | return 0; 51 | } 52 | 53 | /*Codes_SRS_SNTP_LWIP_30_005: [ SNTP_Denit shall deinitialize the SNTP client. ]*/ 54 | void SNTP_Deinit() 55 | { 56 | sntp_stop(); 57 | } 58 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/lwip/sntp_os.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | //This file pulls in OS-specific header files to allow compilation of socket_async.c under 5 | // most OS's except for Windows. 6 | 7 | // For ESP32 lwIP systems which use the ESP-IDF's non-standard lwIP include structure 8 | // Tested with: 9 | // ESP32 10 | 11 | #ifndef LWIP_SNTP_OS_H 12 | #define LWIP_SNTP_OS_H 13 | 14 | #include "apps/sntp/sntp.h" 15 | 16 | #endif // LWIP_SNTP_OS_H -------------------------------------------------------------------------------- /src/az_iot/c-utility/pal/src/platform_openssl_compact.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "az_iot/c-utility/inc/azure_c_shared_utility/platform.h" 5 | #include "../inc/sntp.h" 6 | #include "../inc/tlsio_pal.h" 7 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 8 | 9 | static const char* const ntpServer = "pool.ntp.org"; 10 | 11 | /* Codes_SRS_PLATFORM_OPENSSL_COMPACT_30_004: [ The platform_init shall initialize the tlsio adapter. ] */ 12 | /* Codes_SRS_PLATFORM_OPENSSL_COMPACT_30_005: [ The platform_init shall initialize the sntp client. ] */ 13 | int platform_init(void) 14 | { 15 | // SNTP_SetServerName logs any necessary errors 16 | int result; 17 | if (SNTP_SetServerName(ntpServer) != 0) 18 | { 19 | LogError("Failed SNTP_SetServerName"); 20 | result = __FAILURE__; 21 | } 22 | else 23 | { 24 | } 25 | if (SNTP_Init() != 0) 26 | { 27 | LogError("Failed SNTP_Init"); 28 | result = __FAILURE__; 29 | } 30 | else 31 | { 32 | result = 0; 33 | } 34 | return result; 35 | } 36 | 37 | /* Codes_SRS_PLATFORM_OPENSSL_COMPACT_30_008: [ The platform_get_default_tlsio shall return a set of tlsio functions provided by the OpenSSL micro tlsio implementation. ] */ 38 | const IO_INTERFACE_DESCRIPTION* platform_get_default_tlsio(void) 39 | { 40 | return tlsio_pal_get_interface_description(); 41 | } 42 | 43 | STRING_HANDLE platform_get_platform_info(void) 44 | { 45 | return STRING_construct("(openssl_compact)"); 46 | } 47 | 48 | /* Codes_SRS_PLATFORM_OPENSSL_COMPACT_30_006: [ The platform_deinit shall deinitialize the sntp client. ] */ 49 | /* Codes_SRS_PLATFORM_OPENSSL_COMPACT_30_007: [ The platform_deinit shall deinitialize the tlsio adapter. ] */ 50 | void platform_deinit(void) 51 | { 52 | SNTP_Deinit(); 53 | 54 | // The tlsio adapter for this platform does not need (or support) deinitialization 55 | } 56 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/consolelogger.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | #include 7 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 8 | #include "az_iot/c-utility/inc/azure_c_shared_utility/consolelogger.h" 9 | 10 | #if (defined(_MSC_VER)) && (!(defined WINCE)) 11 | #include "windows.h" 12 | 13 | /*returns a string as if printed by vprintf*/ 14 | static char* vprintf_alloc(const char* format, va_list va) 15 | { 16 | char* result; 17 | int neededSize = vsnprintf(NULL, 0, format, va); 18 | if (neededSize < 0) 19 | { 20 | result = NULL; 21 | } 22 | else 23 | { 24 | result = (char*)malloc(neededSize + 1); 25 | if (result == NULL) 26 | { 27 | /*return as is*/ 28 | } 29 | else 30 | { 31 | if (vsnprintf(result, neededSize + 1, format, va) != neededSize) 32 | { 33 | free(result); 34 | result = NULL; 35 | } 36 | } 37 | } 38 | return result; 39 | } 40 | 41 | /*returns a string as if printed by printf*/ 42 | static char* printf_alloc(const char* format, ...) 43 | { 44 | char* result; 45 | va_list va; 46 | va_start(va, format); 47 | result = vprintf_alloc(format, va); 48 | va_end(va); 49 | return result; 50 | } 51 | 52 | /*returns NULL if it fails*/ 53 | static char* lastErrorToString(DWORD lastError) 54 | { 55 | char* result; 56 | if (lastError == 0) 57 | { 58 | result = printf_alloc(""); /*no error should appear*/ 59 | if (result == NULL) 60 | { 61 | (void)printf("failure in printf_alloc"); 62 | } 63 | else 64 | { 65 | /*return as is*/ 66 | } 67 | } 68 | else 69 | { 70 | char temp[MESSAGE_BUFFER_SIZE]; 71 | if (FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM | FORMAT_MESSAGE_IGNORE_INSERTS, NULL, lastError, MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), temp, MESSAGE_BUFFER_SIZE, NULL) == 0) 72 | { 73 | result = printf_alloc("GetLastError()=0X%x", lastError); 74 | if (result == NULL) 75 | { 76 | (void)printf("failure in printf_alloc\n"); 77 | /*return as is*/ 78 | } 79 | else 80 | { 81 | /*return as is*/ 82 | } 83 | } 84 | else 85 | { 86 | /*eliminate the \r or \n from the string*/ 87 | /*one replace of each is enough*/ 88 | char* whereAreThey; 89 | if ((whereAreThey = strchr(temp, '\r')) != NULL) 90 | { 91 | *whereAreThey = '\0'; 92 | } 93 | if ((whereAreThey = strchr(temp, '\n')) != NULL) 94 | { 95 | *whereAreThey = '\0'; 96 | } 97 | 98 | result = printf_alloc("GetLastError()==0X%x (%s)", lastError, temp); 99 | 100 | if (result == NULL) 101 | { 102 | (void)printf("failure in printf_alloc\n"); 103 | /*return as is*/ 104 | } 105 | else 106 | { 107 | /*return as is*/ 108 | } 109 | } 110 | } 111 | return result; 112 | } 113 | /*this function will use 1x printf (in the happy case) .*/ 114 | /*more than 1x printf / function call can mean intermingled LogErrors in a multithreaded env*/ 115 | /*the function will also attempt to produce some human readable strings for GetLastError*/ 116 | void consolelogger_log_with_GetLastError(const char* file, const char* func, int line, const char* format, ...) 117 | { 118 | DWORD lastError; 119 | char* lastErrorAsString; 120 | int lastErrorAsString_should_be_freed; 121 | time_t t; 122 | int systemMessage_should_be_freed; 123 | char* systemMessage; 124 | int userMessage_should_be_freed; 125 | char* userMessage; 126 | 127 | va_list args; 128 | va_start(args, format); 129 | 130 | /*this is what this case will do: 131 | 1. snip the last error 132 | 2. create a string with what that last error means 133 | 3. printf the system message (__FILE__, __LINE__ etc) + the last error + whatever the user wanted 134 | */ 135 | /*1. snip the last error*/ 136 | lastError = GetLastError(); 137 | 138 | /*2. create a string with what that last error means*/ 139 | lastErrorAsString = lastErrorToString(lastError); 140 | if (lastErrorAsString == NULL) 141 | { 142 | (void)printf("failure in lastErrorToString"); 143 | lastErrorAsString = ""; 144 | lastErrorAsString_should_be_freed = 0; 145 | } 146 | else 147 | { 148 | lastErrorAsString_should_be_freed = 1; 149 | } 150 | 151 | t = time(NULL); 152 | systemMessage = printf_alloc("Error: Time:%.24s File:%s Func:%s Line:%d %s", ctime(&t), file, func, line, lastErrorAsString); 153 | 154 | if (systemMessage == NULL) 155 | { 156 | systemMessage = ""; 157 | (void)printf("Error: [FAILED] Time:%.24s File : %s Func : %s Line : %d %s", ctime(&t), file, func, line, lastErrorAsString); 158 | systemMessage_should_be_freed = 0; 159 | } 160 | else 161 | { 162 | systemMessage_should_be_freed = 1; 163 | } 164 | 165 | userMessage = vprintf_alloc(format, args); 166 | if (userMessage == NULL) 167 | { 168 | (void)printf("[FAILED] "); 169 | (void)vprintf(format, args); 170 | (void)printf("\n"); 171 | userMessage_should_be_freed = 0; 172 | } 173 | else 174 | { 175 | /*3. printf the system message(__FILE__, __LINE__ etc) + the last error + whatever the user wanted*/ 176 | (void)printf("%s %s\n", systemMessage, userMessage); 177 | userMessage_should_be_freed = 1; 178 | } 179 | 180 | if (userMessage_should_be_freed == 1) 181 | { 182 | free(userMessage); 183 | } 184 | 185 | if (systemMessage_should_be_freed == 1) 186 | { 187 | free(systemMessage); 188 | } 189 | 190 | if (lastErrorAsString_should_be_freed == 1) 191 | { 192 | free(lastErrorAsString); 193 | } 194 | va_end(args); 195 | } 196 | #endif 197 | 198 | #if defined(__GNUC__) 199 | __attribute__ ((format (printf, 6, 7))) 200 | #endif 201 | void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* func, int line, unsigned int options, const char* format, ...) 202 | { 203 | time_t t; 204 | va_list args; 205 | va_start(args, format); 206 | 207 | t = time(NULL); 208 | 209 | switch (log_category) 210 | { 211 | case AZ_LOG_INFO: 212 | (void)printf("Info: "); 213 | break; 214 | case AZ_LOG_ERROR: 215 | (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), file, func, line); 216 | break; 217 | default: 218 | break; 219 | } 220 | 221 | (void)vprintf(format, args); 222 | va_end(args); 223 | 224 | (void)log_category; 225 | if (options & LOG_LINE) 226 | { 227 | (void)printf("\r\n"); 228 | } 229 | } 230 | 231 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/constbuffer.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | // 5 | // PUT NO INCLUDES BEFORE HERE 6 | // 7 | #include 8 | #include 9 | #include "az_iot/c-utility/inc/azure_c_shared_utility/gballoc.h" 10 | #include "az_iot/c-utility/inc/azure_c_shared_utility/constbuffer.h" 11 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 12 | #include "az_iot/c-utility/inc/azure_c_shared_utility/refcount.h" 13 | 14 | typedef struct CONSTBUFFER_HANDLE_DATA_TAG 15 | { 16 | CONSTBUFFER alias; 17 | }CONSTBUFFER_HANDLE_DATA; 18 | 19 | DEFINE_REFCOUNT_TYPE(CONSTBUFFER_HANDLE_DATA); 20 | 21 | static CONSTBUFFER_HANDLE CONSTBUFFER_Create_Internal(const unsigned char* source, size_t size) 22 | { 23 | CONSTBUFFER_HANDLE_DATA* result; 24 | /*Codes_SRS_CONSTBUFFER_02_005: [The non-NULL handle returned by CONSTBUFFER_Create shall have its ref count set to "1".]*/ 25 | /*Codes_SRS_CONSTBUFFER_02_010: [The non-NULL handle returned by CONSTBUFFER_CreateFromBuffer shall have its ref count set to "1".]*/ 26 | result = REFCOUNT_TYPE_CREATE(CONSTBUFFER_HANDLE_DATA); 27 | if (result == NULL) 28 | { 29 | /*Codes_SRS_CONSTBUFFER_02_003: [If creating the copy fails then CONSTBUFFER_Create shall return NULL.]*/ 30 | /*Codes_SRS_CONSTBUFFER_02_008: [If copying the content fails, then CONSTBUFFER_CreateFromBuffer shall fail and return NULL.] */ 31 | LogError("unable to malloc"); 32 | /*return as is*/ 33 | } 34 | else 35 | { 36 | /*Codes_SRS_CONSTBUFFER_02_002: [Otherwise, CONSTBUFFER_Create shall create a copy of the memory area pointed to by source having size bytes.]*/ 37 | result->alias.size = size; 38 | if (size == 0) 39 | { 40 | result->alias.buffer = NULL; 41 | } 42 | else 43 | { 44 | unsigned char* temp = (unsigned char*)malloc(size); 45 | if (temp == NULL) 46 | { 47 | /*Codes_SRS_CONSTBUFFER_02_003: [If creating the copy fails then CONSTBUFFER_Create shall return NULL.]*/ 48 | /*Codes_SRS_CONSTBUFFER_02_008: [If copying the content fails, then CONSTBUFFER_CreateFromBuffer shall fail and return NULL.] */ 49 | LogError("unable to malloc"); 50 | free(result); 51 | result = NULL; 52 | } 53 | else 54 | { 55 | 56 | /*Codes_SRS_CONSTBUFFER_02_004: [Otherwise CONSTBUFFER_Create shall return a non-NULL handle.]*/ 57 | /*Codes_SRS_CONSTBUFFER_02_007: [Otherwise, CONSTBUFFER_CreateFromBuffer shall copy the content of buffer.]*/ 58 | /*Codes_SRS_CONSTBUFFER_02_009: [Otherwise, CONSTBUFFER_CreateFromBuffer shall return a non-NULL handle.]*/ 59 | (void)memcpy(temp, source, size); 60 | result->alias.buffer = temp; 61 | } 62 | } 63 | } 64 | return (CONSTBUFFER_HANDLE)result; 65 | } 66 | 67 | CONSTBUFFER_HANDLE CONSTBUFFER_Create(const unsigned char* source, size_t size) 68 | { 69 | CONSTBUFFER_HANDLE_DATA* result; 70 | /*Codes_SRS_CONSTBUFFER_02_001: [If source is NULL and size is different than 0 then CONSTBUFFER_Create shall fail and return NULL.]*/ 71 | if ( 72 | (source == NULL) && 73 | (size != 0) 74 | ) 75 | { 76 | LogError("invalid arguments passes to CONSTBUFFER_Create"); 77 | result = NULL; 78 | } 79 | else 80 | { 81 | result = (CONSTBUFFER_HANDLE_DATA*)CONSTBUFFER_Create_Internal(source, size); 82 | } 83 | return (CONSTBUFFER_HANDLE)result; 84 | } 85 | 86 | /*this creates a new constbuffer from an existing BUFFER_HANDLE*/ 87 | CONSTBUFFER_HANDLE CONSTBUFFER_CreateFromBuffer(BUFFER_HANDLE buffer) 88 | { 89 | CONSTBUFFER_HANDLE_DATA* result; 90 | /*Codes_SRS_CONSTBUFFER_02_006: [If buffer is NULL then CONSTBUFFER_CreateFromBuffer shall fail and return NULL.]*/ 91 | if (buffer == NULL) 92 | { 93 | LogError("invalid arg passed to CONSTBUFFER_CreateFromBuffer"); 94 | result = NULL; 95 | } 96 | else 97 | { 98 | size_t length = BUFFER_length(buffer); 99 | unsigned char* rawBuffer = BUFFER_u_char(buffer); 100 | result = (CONSTBUFFER_HANDLE_DATA*)CONSTBUFFER_Create_Internal(rawBuffer, length); 101 | } 102 | return (CONSTBUFFER_HANDLE)result; 103 | } 104 | 105 | CONSTBUFFER_HANDLE CONSTBUFFER_Clone(CONSTBUFFER_HANDLE constbufferHandle) 106 | { 107 | if (constbufferHandle == NULL) 108 | { 109 | /*Codes_SRS_CONSTBUFFER_02_013: [If constbufferHandle is NULL then CONSTBUFFER_Clone shall fail and return NULL.]*/ 110 | LogError("invalid arg"); 111 | } 112 | else 113 | { 114 | /*Codes_SRS_CONSTBUFFER_02_014: [Otherwise, CONSTBUFFER_Clone shall increment the reference count and return constbufferHandle.]*/ 115 | INC_REF(CONSTBUFFER_HANDLE_DATA, constbufferHandle); 116 | } 117 | return constbufferHandle; 118 | } 119 | 120 | const CONSTBUFFER* CONSTBUFFER_GetContent(CONSTBUFFER_HANDLE constbufferHandle) 121 | { 122 | const CONSTBUFFER* result; 123 | if (constbufferHandle == NULL) 124 | { 125 | /*Codes_SRS_CONSTBUFFER_02_011: [If constbufferHandle is NULL then CONSTBUFFER_GetContent shall return NULL.]*/ 126 | result = NULL; 127 | LogError("invalid arg"); 128 | } 129 | else 130 | { 131 | /*Codes_SRS_CONSTBUFFER_02_012: [Otherwise, CONSTBUFFER_GetContent shall return a const CONSTBUFFER* that matches byte by byte the original bytes used to created the const buffer and has the same length.]*/ 132 | result = &(((CONSTBUFFER_HANDLE_DATA*)constbufferHandle)->alias); 133 | } 134 | return result; 135 | } 136 | 137 | void CONSTBUFFER_Destroy(CONSTBUFFER_HANDLE constbufferHandle) 138 | { 139 | /*Codes_SRS_CONSTBUFFER_02_015: [If constbufferHandle is NULL then CONSTBUFFER_Destroy shall do nothing.]*/ 140 | if (constbufferHandle != NULL) 141 | { 142 | /*Codes_SRS_CONSTBUFFER_02_016: [Otherwise, CONSTBUFFER_Destroy shall decrement the refcount on the constbufferHandle handle.]*/ 143 | if (DEC_REF(CONSTBUFFER_HANDLE_DATA, constbufferHandle) == DEC_RETURN_ZERO) 144 | { 145 | /*Codes_SRS_CONSTBUFFER_02_017: [If the refcount reaches zero, then CONSTBUFFER_Destroy shall deallocate all resources used by the CONSTBUFFER_HANDLE.]*/ 146 | CONSTBUFFER_HANDLE_DATA* constbufferHandleData = (CONSTBUFFER_HANDLE_DATA*)constbufferHandle; 147 | free((void*)constbufferHandleData->alias.buffer); 148 | free(constbufferHandleData); 149 | } 150 | } 151 | } 152 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/doublylinkedlist.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "az_iot/c-utility/inc/azure_c_shared_utility/doublylinkedlist.h" 5 | 6 | void 7 | DList_InitializeListHead( 8 | PDLIST_ENTRY ListHead 9 | ) 10 | { 11 | /* Codes_SRS_DLIST_06_005: [DList_InitializeListHead will initialize the Flink & Blink to the address of the DLIST_ENTRY.] */ 12 | ListHead->Flink = ListHead->Blink = ListHead; 13 | return; 14 | } 15 | 16 | int 17 | DList_IsListEmpty( 18 | const PDLIST_ENTRY ListHead 19 | ) 20 | { 21 | /* Codes_SRS_DLIST_06_003: [DList_IsListEmpty shall return a non-zero value if there are no DLIST_ENTRY's on this list other than the list head.] */ 22 | /* Codes_SRS_DLIST_06_004: [DList_IsListEmpty shall return 0 if there is one or more items in the list.] */ 23 | return (ListHead->Flink == ListHead); 24 | } 25 | 26 | int 27 | DList_RemoveEntryList( 28 | PDLIST_ENTRY Entry 29 | ) 30 | { 31 | /* Codes_SRS_DLIST_06_008: [DList_RemoveEntryList shall remove a listEntry from whatever list it is properly part of.] */ 32 | /* Codes_SRS_DLIST_06_009: [The remaining list is properly formed.] */ 33 | /* Codes_SRS_DLIST_06_010: [DList_RemoveEntryList shall return non-zero if the remaining list is empty.] */ 34 | /* Codes_SRS_DLIST_06_011: [DList_RemoveEntryList shall return zero if the remaining list is NOT empty.] */ 35 | PDLIST_ENTRY Blink; 36 | PDLIST_ENTRY Flink; 37 | 38 | Flink = Entry->Flink; 39 | Blink = Entry->Blink; 40 | Blink->Flink = Flink; 41 | Flink->Blink = Blink; 42 | return (Flink == Blink); 43 | } 44 | 45 | PDLIST_ENTRY 46 | DList_RemoveHeadList( 47 | PDLIST_ENTRY ListHead 48 | ) 49 | { 50 | /* Codes_SRS_DLIST_06_012: [DList_RemoveHeadList removes the oldest entry from the list defined by the listHead parameter and returns a pointer to that entry.] */ 51 | /* Codes_SRS_DLIST_06_013: [DList_RemoveHeadList shall return listHead if that's the only item in the list.] */ 52 | 53 | PDLIST_ENTRY Flink; 54 | PDLIST_ENTRY Entry; 55 | 56 | Entry = ListHead->Flink; 57 | Flink = Entry->Flink; 58 | ListHead->Flink = Flink; 59 | Flink->Blink = ListHead; 60 | return Entry; 61 | } 62 | 63 | 64 | 65 | void 66 | DList_InsertTailList( 67 | PDLIST_ENTRY ListHead, 68 | PDLIST_ENTRY Entry 69 | ) 70 | { 71 | PDLIST_ENTRY Blink; 72 | 73 | /* Codes_SRS_DLIST_06_006: [DListInsertTailList shall place the DLIST_ENTRY at the end of the list defined by the listHead parameter.] */ 74 | Blink = ListHead->Blink; 75 | Entry->Flink = ListHead; 76 | Entry->Blink = Blink; 77 | Blink->Flink = Entry; 78 | ListHead->Blink = Entry; 79 | return; 80 | } 81 | 82 | 83 | void 84 | DList_AppendTailList( 85 | PDLIST_ENTRY ListHead, 86 | PDLIST_ENTRY ListToAppend 87 | ) 88 | { 89 | /* Codes_SRS_DLIST_06_007: [DList_AppendTailList shall place the list defined by listToAppend at the end of the list defined by the listHead parameter.] */ 90 | PDLIST_ENTRY ListEnd = ListHead->Blink; 91 | 92 | ListHead->Blink->Flink = ListToAppend; 93 | ListHead->Blink = ListToAppend->Blink; 94 | ListToAppend->Blink->Flink = ListHead; 95 | ListToAppend->Blink = ListEnd; 96 | return; 97 | } 98 | 99 | 100 | /*Codes_SRS_DLIST_02_002: [DList_InsertHeadList inserts a singular entry in the list having as head listHead after "head".]*/ 101 | void DList_InsertHeadList(PDLIST_ENTRY listHead, PDLIST_ENTRY entry) 102 | { 103 | entry->Blink = listHead; 104 | entry->Flink = listHead->Flink; 105 | listHead->Flink->Blink = entry; 106 | listHead->Flink = entry; 107 | } 108 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/gb_stdio.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /*depending if the symbol GB_STDIO_INTERCEPT is defined, this file does the following 5 | 6 | a) if GB_STDIO_INTERCEPT is NOT defined, then the file shall be empty (almost:) 7 | b) if GB_STDIO_INTERCEPT is defined, then the file shall call to the 'real' stdio.h functions from their gb_* synonyms*/ 8 | #ifdef _MSC_VER 9 | static const int avoid_a_warning_C4206 = 0; /* warning C4206: nonstandard extension used: translation unit is empty*/ 10 | #endif 11 | #ifdef GB_STDIO_INTERCEPT 12 | 13 | #ifdef __cplusplus 14 | #include 15 | #include 16 | #else 17 | #include 18 | #include 19 | #endif 20 | 21 | #include "az_iot/c-utility/inc/azure_c_shared_utility/gb_stdio.h" 22 | 23 | /*this is fopen*/ 24 | FILE *gb_fopen(const char * filename, const char * mode) 25 | { 26 | return fopen(filename, mode); 27 | } 28 | 29 | int gb_fclose(FILE *stream) 30 | { 31 | return fclose(stream); 32 | } 33 | 34 | int gb_fseek(FILE *stream, long int offset, int whence) 35 | { 36 | return fseek(stream, offset, whence); 37 | } 38 | 39 | long int gb_ftell(FILE *stream) 40 | { 41 | return ftell(stream); 42 | } 43 | 44 | int fprintf(FILE * stream, const char * format, ...) 45 | { 46 | va_list args; 47 | va_start(args, format); 48 | vfprintf(stream, format, args); 49 | va_end(args); 50 | } 51 | 52 | #endif 53 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/gb_time.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /*depending if the symbol GB_TIME_INTERCEPT is defined, this file does the following 5 | 6 | a) if GB_TIME_INTERCEPT is NOT defined, then the file shall be empty (almost:) 7 | b) if GB_TIME_INTERCEPT is defined, then the file shall call to the 'real' time.h functions from their gb_* synonyms*/ 8 | #ifdef _MSC_VER 9 | static const int avoid_a_warning_C4206 = 0; /* warning C4206: nonstandard extension used: translation unit is empty*/ 10 | #endif 11 | #ifdef GB_TIME_INTERCEPT 12 | 13 | #ifdef __cplusplus 14 | #include 15 | #else 16 | #include 17 | #endif 18 | 19 | #include "az_iot/c-utility/inc/azure_c_shared_utility/gb_time.h" 20 | 21 | /*this is time*/ 22 | time_t gb_time(time_t *timer); 23 | { 24 | return time(timer); 25 | } 26 | 27 | /*this is localtime*/ 28 | struct tm *gb_localtime(const time_t *timer) 29 | { 30 | return gb_localtime(timer); 31 | } 32 | 33 | size_t gb_strftime(char * s, size_t maxsize, const char * format, const struct tm * timeptr) 34 | { 35 | return strftime(s, maxsize, format, timeptr); 36 | } 37 | 38 | #endif 39 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/hmacsha256.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include "az_iot/c-utility/inc/azure_c_shared_utility/hmacsha256.h" 6 | #include "az_iot/c-utility/inc/azure_c_shared_utility/hmac.h" 7 | #include "az_iot/c-utility/inc/azure_c_shared_utility/buffer_.h" 8 | 9 | HMACSHA256_RESULT HMACSHA256_ComputeHash(const unsigned char* key, size_t keyLen, const unsigned char* payload, size_t payloadLen, BUFFER_HANDLE hash) 10 | { 11 | HMACSHA256_RESULT result; 12 | 13 | if (key == NULL || 14 | keyLen == 0 || 15 | payload == NULL || 16 | payloadLen == 0 || 17 | hash == NULL) 18 | { 19 | result = HMACSHA256_INVALID_ARG; 20 | } 21 | else 22 | { 23 | if ((BUFFER_enlarge(hash, 32) != 0) || 24 | (hmac(SHA256, payload, (int)payloadLen, key, (int)keyLen, BUFFER_u_char(hash) ) != 0)) 25 | { 26 | result = HMACSHA256_ERROR; 27 | } 28 | else 29 | { 30 | result = HMACSHA256_OK; 31 | } 32 | } 33 | 34 | return result; 35 | } 36 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/urlencode.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include 5 | #include 6 | #include 7 | #include "az_iot/c-utility/inc/azure_c_shared_utility/gballoc.h" 8 | #include "az_iot/c-utility/inc/azure_c_shared_utility/urlencode.h" 9 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 10 | #include "az_iot/c-utility/inc/azure_c_shared_utility/strings.h" 11 | 12 | #define NIBBLE_STR(c) (char)(c < 10 ? c + '0' : c - 10 + 'a') 13 | #define IS_PRINTABLE(c) ( \ 14 | (c == 0) || \ 15 | (c == '!') || \ 16 | (c == '(') || (c == ')') || (c == '*') || \ 17 | (c == '-') || (c == '.') || \ 18 | ((c >= '0') && (c <= '9')) || \ 19 | ((c >= 'A') && (c <= 'Z')) || \ 20 | (c == '_') || \ 21 | ((c >= 'a') && (c <= 'z')) \ 22 | ) 23 | 24 | static size_t URL_PrintableChar(unsigned char charVal, char* buffer) 25 | { 26 | size_t size; 27 | if (IS_PRINTABLE(charVal)) 28 | { 29 | buffer[0] = (char)charVal; 30 | size = 1; 31 | } 32 | else 33 | { 34 | char bigNibbleStr; 35 | char littleNibbleStr; 36 | unsigned char bigNibbleVal = charVal >> 4; 37 | unsigned char littleNibbleVal = charVal & 0x0F; 38 | 39 | if (bigNibbleVal >= 0x0C) 40 | { 41 | bigNibbleVal -= 0x04; 42 | } 43 | 44 | bigNibbleStr = NIBBLE_STR(bigNibbleVal); 45 | littleNibbleStr = NIBBLE_STR(littleNibbleVal); 46 | 47 | buffer[0] = '%'; 48 | 49 | if (charVal < 0x80) 50 | { 51 | buffer[1] = bigNibbleStr; 52 | buffer[2] = littleNibbleStr; 53 | size = 3; 54 | } 55 | else 56 | { 57 | buffer[1] = 'c'; 58 | buffer[3] = '%'; 59 | buffer[4] = bigNibbleStr; 60 | buffer[5] = littleNibbleStr; 61 | if (charVal < 0xC0) 62 | { 63 | buffer[2] = '2'; 64 | } 65 | else 66 | { 67 | buffer[2] = '3'; 68 | } 69 | size = 6; 70 | } 71 | } 72 | 73 | return size; 74 | } 75 | 76 | static size_t URL_PrintableCharSize(unsigned char charVal) 77 | { 78 | size_t size; 79 | if (IS_PRINTABLE(charVal)) 80 | { 81 | size = 1; 82 | } 83 | else 84 | { 85 | if (charVal < 0x80) 86 | { 87 | size = 3; 88 | } 89 | else 90 | { 91 | size = 6; 92 | } 93 | } 94 | return size; 95 | } 96 | 97 | STRING_HANDLE URL_EncodeString(const char* textEncode) 98 | { 99 | STRING_HANDLE result; 100 | if (textEncode == NULL) 101 | { 102 | result = NULL; 103 | } 104 | else 105 | { 106 | STRING_HANDLE tempString = STRING_construct(textEncode); 107 | if (tempString == NULL) 108 | { 109 | result = NULL; 110 | } 111 | else 112 | { 113 | result = URL_Encode(tempString); 114 | STRING_delete(tempString); 115 | } 116 | } 117 | return result; 118 | } 119 | 120 | STRING_HANDLE URL_Encode(STRING_HANDLE input) 121 | { 122 | STRING_HANDLE result; 123 | if (input == NULL) 124 | { 125 | /*Codes_SRS_URL_ENCODE_06_001: [If input is NULL then URL_Encode will return NULL.]*/ 126 | result = NULL; 127 | LogError("URL_Encode:: NULL input"); 128 | } 129 | else 130 | { 131 | size_t lengthOfResult = 0; 132 | char* encodedURL; 133 | const char* currentInput; 134 | unsigned char currentUnsignedChar; 135 | currentInput = STRING_c_str(input); 136 | /*Codes_SRS_URL_ENCODE_06_003: [If input is a zero length string then URL_Encode will return a zero length string.]*/ 137 | do 138 | { 139 | currentUnsignedChar = (unsigned char)(*currentInput++); 140 | lengthOfResult += URL_PrintableCharSize(currentUnsignedChar); 141 | } while (currentUnsignedChar != 0); 142 | if ((encodedURL = (char*)malloc(lengthOfResult)) == NULL) 143 | { 144 | /*Codes_SRS_URL_ENCODE_06_002: [If an error occurs during the encoding of input then URL_Encode will return NULL.]*/ 145 | result = NULL; 146 | LogError("URL_Encode:: MALLOC failure on encode."); 147 | } 148 | else 149 | { 150 | size_t currentEncodePosition = 0; 151 | currentInput = STRING_c_str(input); 152 | do 153 | { 154 | currentUnsignedChar = (unsigned char)(*currentInput++); 155 | currentEncodePosition += URL_PrintableChar(currentUnsignedChar, &encodedURL[currentEncodePosition]); 156 | } while (currentUnsignedChar != 0); 157 | 158 | result = STRING_new_with_memory(encodedURL); 159 | if (result == NULL) 160 | { 161 | LogError("URL_Encode:: MALLOC failure on encode."); 162 | free(encodedURL); 163 | } 164 | } 165 | } 166 | return result; 167 | } 168 | -------------------------------------------------------------------------------- /src/az_iot/c-utility/src/xlogging.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xlogging.h" 5 | #include "az_iot/c-utility/inc/azure_c_shared_utility/consolelogger.h" 6 | 7 | #ifndef NO_LOGGING 8 | 9 | 10 | #ifdef WINCE 11 | #include 12 | 13 | void consolelogger_log(LOG_CATEGORY log_category, const char* file, const char* func, int line, unsigned int options, const char* format, ...) 14 | { 15 | va_list args; 16 | va_start(args, format); 17 | 18 | time_t t = time(NULL); 19 | 20 | switch (log_category) 21 | { 22 | case AZ_LOG_INFO: 23 | (void)printf("Info: "); 24 | break; 25 | case AZ_LOG_ERROR: 26 | (void)printf("Error: Time:%.24s File:%s Func:%s Line:%d ", ctime(&t), file, func, line); 27 | break; 28 | default: 29 | break; 30 | } 31 | 32 | (void)vprintf(format, args); 33 | va_end(args); 34 | 35 | (void)log_category; 36 | if (options & LOG_LINE) 37 | { 38 | (void)printf("\r\n"); 39 | } 40 | } 41 | #endif 42 | 43 | LOGGER_LOG global_log_function = consolelogger_log; 44 | 45 | void xlogging_set_log_function(LOGGER_LOG log_function) 46 | { 47 | global_log_function = log_function; 48 | } 49 | 50 | LOGGER_LOG xlogging_get_log_function(void) 51 | { 52 | return global_log_function; 53 | } 54 | 55 | #if (defined(_MSC_VER)) && (!(defined WINCE)) 56 | 57 | LOGGER_LOG_GETLASTERROR global_log_function_GetLastError = consolelogger_log_with_GetLastError; 58 | 59 | void xlogging_set_log_function_GetLastError(LOGGER_LOG_GETLASTERROR log_function_GetLastError) 60 | { 61 | global_log_function_GetLastError = log_function_GetLastError; 62 | } 63 | 64 | LOGGER_LOG_GETLASTERROR xlogging_get_log_function_GetLastError(void) 65 | { 66 | return global_log_function_GetLastError; 67 | } 68 | #endif 69 | 70 | /* Print up to 16 bytes per line. */ 71 | #define LINE_SIZE 16 72 | 73 | /* Return the printable char for the provided value. */ 74 | #define PRINTABLE(c) ((c >= ' ') && (c <= '~')) ? (char)c : '.' 75 | 76 | /* Convert the lower nibble of the provided byte to a hexadecimal printable char. */ 77 | #define HEX_STR(c) (((c) & 0xF) < 0xA) ? (char)(((c) & 0xF) + '0') : (char)(((c) & 0xF) - 0xA + 'A') 78 | 79 | void xlogging_dump_buffer(const void* buf, size_t size) 80 | { 81 | char charBuf[LINE_SIZE + 1]; 82 | char hexBuf[LINE_SIZE * 3 + 1]; 83 | size_t countbuf = 0; 84 | const unsigned char* bufAsChar = (const unsigned char*)buf; 85 | const unsigned char* startPos = bufAsChar; 86 | 87 | /* Print the whole buffer. */ 88 | size_t i = 0; 89 | for (i = 0; i < size; i++) 90 | { 91 | /* Store the printable value of the char in the charBuf to print. */ 92 | charBuf[countbuf] = PRINTABLE(*bufAsChar); 93 | 94 | /* Convert the high nibble to a printable hexadecimal value. */ 95 | hexBuf[countbuf * 3] = HEX_STR(*bufAsChar >> 4); 96 | 97 | /* Convert the low nibble to a printable hexadecimal value. */ 98 | hexBuf[countbuf * 3 + 1] = HEX_STR(*bufAsChar); 99 | 100 | hexBuf[countbuf * 3 + 2] = ' '; 101 | 102 | countbuf++; 103 | bufAsChar++; 104 | /* If the line is full, print it to start another one. */ 105 | if (countbuf == LINE_SIZE) 106 | { 107 | charBuf[countbuf] = '\0'; 108 | hexBuf[countbuf * 3] = '\0'; 109 | LOG(AZ_LOG_TRACE, 0, "%p: %s %s", startPos, hexBuf, charBuf); 110 | countbuf = 0; 111 | startPos = bufAsChar; 112 | } 113 | } 114 | 115 | /* If the last line does not fit the line size. */ 116 | if (countbuf > 0) 117 | { 118 | /* Close the charBuf string. */ 119 | charBuf[countbuf] = '\0'; 120 | 121 | /* Fill the hexBuf with spaces to keep the charBuf alignment. */ 122 | while ((countbuf++) < LINE_SIZE - 1) 123 | { 124 | hexBuf[countbuf * 3] = ' '; 125 | hexBuf[countbuf * 3 + 1] = ' '; 126 | hexBuf[countbuf * 3 + 2] = ' '; 127 | } 128 | hexBuf[countbuf * 3] = '\0'; 129 | 130 | /* Print the last line. */ 131 | LOG(AZ_LOG_TRACE, 0, "%p: %s %s", startPos, hexBuf, charBuf); 132 | } 133 | } 134 | 135 | #endif 136 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/blob.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file blob.h 5 | * @brief Contains blob APIs needed for File Upload feature of IoTHub client. 6 | * 7 | * @details IoTHub client needs to upload a byte array by using blob storage API 8 | * IoTHub service provides the complete SAS URI to execute a PUT request 9 | * that will upload the data. 10 | * 11 | */ 12 | 13 | #ifndef BLOB_H 14 | #define BLOB_H 15 | 16 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 17 | #include "az_iot/c-utility/inc/azure_c_shared_utility/buffer_.h" 18 | 19 | #ifdef __cplusplus 20 | #include 21 | extern "C" 22 | { 23 | #else 24 | #include 25 | #endif 26 | 27 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 28 | 29 | #define BLOB_RESULT_VALUES \ 30 | BLOB_OK, \ 31 | BLOB_ERROR, \ 32 | BLOB_NOT_IMPLEMENTED, \ 33 | BLOB_HTTP_ERROR, \ 34 | BLOB_INVALID_ARG 35 | 36 | DEFINE_ENUM(BLOB_RESULT, BLOB_RESULT_VALUES) 37 | 38 | /** 39 | * @brief Synchronously uploads a byte array to blob storage 40 | * 41 | * @param SASURI The URI to use to upload data 42 | * @param size The size of the data to be uploaded (can be 0) 43 | * @param source A pointer to the byte array to be uploaded (can be NULL, but then size needs to be zero) 44 | * @param httpStatus A pointer to an out argument receiving the HTTP status (available only when the return value is BLOB_OK) 45 | * @param httpResponse A BUFFER_HANDLE that receives the HTTP response from the server (available only when the return value is BLOB_OK) 46 | * @param certificates A null terminated string containing CA certificates to be used 47 | * 48 | * @return A @c BLOB_RESULT. BLOB_OK means the blob has been uploaded successfully. Any other value indicates an error 49 | */ 50 | MOCKABLE_FUNCTION(, BLOB_RESULT, Blob_UploadFromSasUri,const char*, SASURI, const unsigned char*, source, size_t, size, unsigned int*, httpStatus, BUFFER_HANDLE, httpResponse, const char*, certificates) 51 | 52 | #ifdef __cplusplus 53 | } 54 | #endif 55 | 56 | #endif /* BLOB_H */ 57 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothub_client_authorization.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUB_CLIENT_AUTHORIZATION_H 5 | #define IOTHUB_CLIENT_AUTHORIZATION_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" { 9 | #else 10 | #include 11 | #endif /* __cplusplus */ 12 | 13 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 14 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 15 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xio.h" 16 | 17 | typedef struct IOTHUB_AUTHORIZATION_DATA_TAG* IOTHUB_AUTHORIZATION_HANDLE; 18 | 19 | #define IOTHUB_CREDENTIAL_TYPE_VALUES \ 20 | IOTHUB_CREDENTIAL_TYPE_UNKNOWN, \ 21 | IOTHUB_CREDENTIAL_TYPE_DEVICE_KEY, \ 22 | IOTHUB_CREDENTIAL_TYPE_X509, \ 23 | IOTHUB_CREDENTIAL_TYPE_X509_ECC, \ 24 | IOTHUB_CREDENTIAL_TYPE_SAS_TOKEN, \ 25 | IOTHUB_CREDENTIAL_TYPE_DEVICE_AUTH 26 | 27 | 28 | DEFINE_ENUM(IOTHUB_CREDENTIAL_TYPE, IOTHUB_CREDENTIAL_TYPE_VALUES); 29 | 30 | #define SAS_TOKEN_STATUS_VALUES \ 31 | SAS_TOKEN_STATUS_FAILED, \ 32 | SAS_TOKEN_STATUS_VALID, \ 33 | SAS_TOKEN_STATUS_INVALID 34 | 35 | DEFINE_ENUM(SAS_TOKEN_STATUS, SAS_TOKEN_STATUS_VALUES); 36 | 37 | MOCKABLE_FUNCTION(, IOTHUB_AUTHORIZATION_HANDLE, IoTHubClient_Auth_Create, const char*, device_key, const char*, device_id, const char*, device_sas_token); 38 | MOCKABLE_FUNCTION(, IOTHUB_AUTHORIZATION_HANDLE, IoTHubClient_Auth_CreateFromDeviceAuth, const char*, device_id); 39 | MOCKABLE_FUNCTION(, void, IoTHubClient_Auth_Destroy, IOTHUB_AUTHORIZATION_HANDLE, handle); 40 | MOCKABLE_FUNCTION(, IOTHUB_CREDENTIAL_TYPE, IoTHubClient_Auth_Set_x509_Type, IOTHUB_AUTHORIZATION_HANDLE, handle, bool, enable_x509); 41 | MOCKABLE_FUNCTION(, IOTHUB_CREDENTIAL_TYPE, IoTHubClient_Auth_Get_Credential_Type, IOTHUB_AUTHORIZATION_HANDLE, handle); 42 | MOCKABLE_FUNCTION(, char*, IoTHubClient_Auth_Get_SasToken, IOTHUB_AUTHORIZATION_HANDLE, handle, const char*, scope, size_t, expire_time); 43 | MOCKABLE_FUNCTION(, int, IoTHubClient_Auth_Set_xio_Certificate, IOTHUB_AUTHORIZATION_HANDLE, handle, XIO_HANDLE, xio); 44 | MOCKABLE_FUNCTION(, const char*, IoTHubClient_Auth_Get_DeviceId, IOTHUB_AUTHORIZATION_HANDLE, handle); 45 | MOCKABLE_FUNCTION(, const char*, IoTHubClient_Auth_Get_DeviceKey, IOTHUB_AUTHORIZATION_HANDLE, handle); 46 | MOCKABLE_FUNCTION(, SAS_TOKEN_STATUS, IoTHubClient_Auth_Is_SasToken_Valid, IOTHUB_AUTHORIZATION_HANDLE, handle); 47 | 48 | #ifdef __cplusplus 49 | } 50 | #endif 51 | 52 | #endif /* IOTHUB_CLIENT_AUTHORIZATION_H */ 53 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothub_client_dps_ll.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file iothub_client_version.h 5 | * @brief Functions for managing the client SDK version. 6 | */ 7 | 8 | #ifndef IOTHUB_CLIENT_DPS_CONN_H 9 | #define IOTHUB_CLIENT_DPS_CONN_H 10 | 11 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 12 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 13 | 14 | #ifdef USE_DPS_MODULE 15 | #include "az_iot/c-utility/inc/azure_hub_modules/iothub_device_auth.h" 16 | #endif 17 | 18 | #include "iothub_client_ll.h" 19 | 20 | #ifdef __cplusplus 21 | extern "C" 22 | { 23 | #endif 24 | 25 | /** 26 | * @brief Creates a IoT Hub client for communication with an existing IoT 27 | * Hub using the device auth module. 28 | * 29 | * @param iothub_uri Pointer to an ioThub hostname received in the DPS process 30 | * @param device_id Pointer to the device Id of the device 31 | * @param device_auth_handle a device auth handle used to generate the connection string 32 | * @param protocol Function pointer for protocol implementation 33 | * 34 | * @return A non-NULL @c IOTHUB_CLIENT_LL_HANDLE value that is used when 35 | * invoking other functions for IoT Hub client and @c NULL on failure. 36 | */ 37 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_LL_HANDLE, IoTHubClient_LL_CreateFromDeviceAuth, const char*, iothub_uri, const char*, device_id, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif // IOTHUB_CLIENT_DPS_CONN_H 44 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothub_client_options.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUB_CLIENT_OPTIONS_H 5 | #define IOTHUB_CLIENT_OPTIONS_H 6 | 7 | #ifdef __cplusplus 8 | extern "C" 9 | { 10 | #endif 11 | 12 | typedef struct IOTHUB_PROXY_OPTIONS_TAG 13 | { 14 | const char* host_address; 15 | const char* username; 16 | const char* password; 17 | } IOTHUB_PROXY_OPTIONS; 18 | 19 | static const char* OPTION_LOG_TRACE = "logtrace"; 20 | static const char* OPTION_X509_CERT = "x509certificate"; 21 | static const char* OPTION_X509_PRIVATE_KEY = "x509privatekey"; 22 | static const char* OPTION_KEEP_ALIVE = "keepalive"; 23 | 24 | static const char* OPTION_PROXY_HOST = "proxy_address"; 25 | static const char* OPTION_PROXY_USERNAME = "proxy_username"; 26 | static const char* OPTION_PROXY_PASSWORD = "proxy_password"; 27 | 28 | static const char* OPTION_SAS_TOKEN_LIFETIME = "sas_token_lifetime"; 29 | static const char* OPTION_SAS_TOKEN_REFRESH_TIME = "sas_token_refresh_time"; 30 | static const char* OPTION_CBS_REQUEST_TIMEOUT = "cbs_request_timeout"; 31 | 32 | static const char* OPTION_MIN_POLLING_TIME = "MinimumPollingTime"; 33 | static const char* OPTION_BATCHING = "Batching"; 34 | 35 | static const char* OPTION_MESSAGE_TIMEOUT = "messageTimeout"; 36 | static const char* OPTION_PRODUCT_INFO = "product_info"; 37 | static const char* OPTION_C2D_KEEP_ALIVE_FREQ_SECS = "c2d_keep_alive_freq_secs"; 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* IOTHUB_CLIENT_OPTIONS_H */ 44 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothub_client_private.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUB_CLIENT_PRIVATE_H 5 | #define IOTHUB_CLIENT_PRIVATE_H 6 | 7 | #include 8 | 9 | #include "az_iot/c-utility/inc/azure_c_shared_utility/constbuffer.h" 10 | #include "az_iot/c-utility/inc/azure_c_shared_utility/crt_abstractions.h" 11 | #include "az_iot/c-utility/inc/azure_c_shared_utility/doublylinkedlist.h" 12 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 13 | #include "az_iot/c-utility/inc/azure_c_shared_utility/tickcounter.h" 14 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 15 | 16 | #include "iothub_message.h" 17 | #include "iothub_client_ll.h" 18 | 19 | #ifdef __cplusplus 20 | extern "C" 21 | { 22 | #endif 23 | 24 | #define EVENT_ENDPOINT "/messages/events" 25 | #define MESSAGE_ENDPOINT "/messages/devicebound" 26 | #define MESSAGE_ENDPOINT_HTTP "/messages/devicebound" 27 | #define MESSAGE_ENDPOINT_HTTP_ETAG "/messages/devicebound/" 28 | #define CLIENT_DEVICE_TYPE_PREFIX "iothubclient" 29 | #define CLIENT_DEVICE_BACKSLASH "/" 30 | #define CBS_REPLY_TO "cbs" 31 | #define CBS_ENDPOINT "/$" CBS_REPLY_TO 32 | #define API_VERSION "?api-version=2016-11-14" 33 | #define REJECT_QUERY_PARAMETER "&reject" 34 | 35 | typedef bool(*IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC_EX)(MESSAGE_CALLBACK_INFO* messageData, void* userContextCallback); 36 | 37 | MOCKABLE_FUNCTION(, void, IoTHubClient_LL_SendComplete, IOTHUB_CLIENT_LL_HANDLE, handle, PDLIST_ENTRY, completed, IOTHUB_CLIENT_CONFIRMATION_RESULT, result); 38 | MOCKABLE_FUNCTION(, void, IoTHubClient_LL_ReportedStateComplete, IOTHUB_CLIENT_LL_HANDLE, handle, uint32_t, item_id, int, status_code); 39 | MOCKABLE_FUNCTION(, bool, IoTHubClient_LL_MessageCallback, IOTHUB_CLIENT_LL_HANDLE, handle, MESSAGE_CALLBACK_INFO*, message_data); 40 | MOCKABLE_FUNCTION(, void, IoTHubClient_LL_RetrievePropertyComplete, IOTHUB_CLIENT_LL_HANDLE, handle, DEVICE_TWIN_UPDATE_STATE, update_state, const unsigned char*, payLoad, size_t, size); 41 | MOCKABLE_FUNCTION(, int, IoTHubClient_LL_DeviceMethodComplete, IOTHUB_CLIENT_LL_HANDLE, handle, const char*, method_name, const unsigned char*, payLoad, size_t, size, METHOD_HANDLE, response_id); 42 | MOCKABLE_FUNCTION(, void, IoTHubClient_LL_ConnectionStatusCallBack, IOTHUB_CLIENT_LL_HANDLE, handle, IOTHUB_CLIENT_CONNECTION_STATUS, status, IOTHUB_CLIENT_CONNECTION_STATUS_REASON, reason); 43 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SetMessageCallback_Ex, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, IOTHUB_CLIENT_MESSAGE_CALLBACK_ASYNC_EX, messageCallback, void*, userContextCallback); 44 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_SendMessageDisposition, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, MESSAGE_CALLBACK_INFO*, messageData, IOTHUBMESSAGE_DISPOSITION_RESULT, disposition); 45 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubClient_LL_GetOption, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, const char*, optionName, void**, value); 46 | 47 | typedef struct IOTHUB_MESSAGE_LIST_TAG 48 | { 49 | IOTHUB_MESSAGE_HANDLE messageHandle; 50 | IOTHUB_CLIENT_EVENT_CONFIRMATION_CALLBACK callback; 51 | void* context; 52 | DLIST_ENTRY entry; 53 | tickcounter_ms_t ms_timesOutAfter; /* a value of "0" means "no timeout", if the IOTHUBCLIENT_LL's handle tickcounter > msTimesOutAfer then the message shall timeout*/ 54 | }IOTHUB_MESSAGE_LIST; 55 | 56 | typedef struct IOTHUB_DEVICE_TWIN_TAG 57 | { 58 | uint32_t item_id; 59 | tickcounter_ms_t ms_timesOutAfter; /* a value of "0" means "no timeout", if the IOTHUBCLIENT_LL's handle tickcounter > msTimesOutAfer then the message shall timeout*/ 60 | IOTHUB_CLIENT_REPORTED_STATE_CALLBACK reported_state_callback; 61 | CONSTBUFFER_HANDLE report_data_handle; 62 | void* context; 63 | DLIST_ENTRY entry; 64 | IOTHUB_CLIENT_LL_HANDLE client_handle; 65 | IOTHUB_DEVICE_HANDLE device_handle; 66 | } IOTHUB_DEVICE_TWIN; 67 | 68 | union IOTHUB_IDENTITY_INFO_TAG 69 | { 70 | IOTHUB_DEVICE_TWIN* device_twin; 71 | IOTHUB_MESSAGE_LIST* iothub_message; 72 | }; 73 | 74 | #ifdef __cplusplus 75 | } 76 | #endif 77 | 78 | #endif /* IOTHUB_CLIENT_PRIVATE_H */ 79 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothub_client_retry_control.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUB_CLIENT_RETRY_CONTROL 5 | #define IOTHUB_CLIENT_RETRY_CONTROL 6 | 7 | #include 8 | #include 9 | #include "az_iot/c-utility/inc/azure_c_shared_utility/optionhandler.h" 10 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 11 | #include "iothub_client_ll.h" 12 | 13 | #ifdef __cplusplus 14 | extern "C" 15 | { 16 | #endif 17 | 18 | static const char* RETRY_CONTROL_OPTION_INITIAL_WAIT_TIME_IN_SECS = "initial_wait_time_in_secs"; 19 | static const char* RETRY_CONTROL_OPTION_MAX_JITTER_PERCENT = "max_jitter_percent"; 20 | static const char* RETRY_CONTROL_OPTION_SAVED_OPTIONS = "retry_control_saved_options"; 21 | 22 | typedef enum RETRY_ACTION_TAG 23 | { 24 | RETRY_ACTION_RETRY_NOW, 25 | RETRY_ACTION_RETRY_LATER, 26 | RETRY_ACTION_STOP_RETRYING 27 | } RETRY_ACTION; 28 | 29 | struct RETRY_CONTROL_INSTANCE_TAG; 30 | typedef struct RETRY_CONTROL_INSTANCE_TAG* RETRY_CONTROL_HANDLE; 31 | 32 | MOCKABLE_FUNCTION(, RETRY_CONTROL_HANDLE, retry_control_create, IOTHUB_CLIENT_RETRY_POLICY, policy, unsigned int, max_retry_time_in_secs); 33 | MOCKABLE_FUNCTION(, int, retry_control_should_retry, RETRY_CONTROL_HANDLE, retry_control_handle, RETRY_ACTION*, retry_action); 34 | MOCKABLE_FUNCTION(, void, retry_control_reset, RETRY_CONTROL_HANDLE, retry_control_handle); 35 | MOCKABLE_FUNCTION(, int, retry_control_set_option, RETRY_CONTROL_HANDLE, retry_control_handle, const char*, name, const void*, value); 36 | MOCKABLE_FUNCTION(, OPTIONHANDLER_HANDLE, retry_control_retrieve_options, RETRY_CONTROL_HANDLE, retry_control_handle); 37 | MOCKABLE_FUNCTION(, void, retry_control_destroy, RETRY_CONTROL_HANDLE, retry_control_handle); 38 | 39 | MOCKABLE_FUNCTION(, int, is_timeout_reached, time_t, start_time, unsigned int, timeout_in_secs, bool*, is_timed_out); 40 | 41 | #ifdef __cplusplus 42 | } 43 | #endif 44 | 45 | #endif // IOTHUB_CLIENT_RETRY_CONTROL -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothub_client_version.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | /** @file iothub_client_version.h 5 | * @brief Functions for managing the client SDK version. 6 | */ 7 | 8 | #ifndef IOTHUB_CLIENT_VERSION_H 9 | #define IOTHUB_CLIENT_VERSION_H 10 | 11 | #define IOTHUB_SDK_VERSION "1.1.23" 12 | 13 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 14 | 15 | #ifdef __cplusplus 16 | extern "C" 17 | { 18 | #endif 19 | 20 | /** 21 | * @brief Returns a pointer to a null terminated string containing the 22 | * current IoT Hub Client SDK version. 23 | * 24 | * @return Pointer to a null terminated string containing the 25 | * current IoT Hub Client SDK version. 26 | */ 27 | MOCKABLE_FUNCTION(, const char*, IoTHubClient_GetVersionString); 28 | 29 | #ifdef __cplusplus 30 | } 31 | #endif 32 | 33 | #endif // IOTHUB_CLIENT_VERSION_H 34 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothub_transport_ll.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUB_TRANSPORT_LL_H 5 | #define IOTHUB_TRANSPORT_LL_H 6 | 7 | 8 | typedef void* TRANSPORT_LL_HANDLE; 9 | typedef void* IOTHUB_DEVICE_HANDLE; 10 | 11 | struct TRANSPORT_PROVIDER_TAG; 12 | typedef struct TRANSPORT_PROVIDER_TAG TRANSPORT_PROVIDER; 13 | 14 | union IOTHUB_IDENTITY_INFO_TAG; 15 | typedef union IOTHUB_IDENTITY_INFO_TAG IOTHUB_IDENTITY_INFO; 16 | 17 | typedef void* METHOD_HANDLE; 18 | 19 | #include "az_iot/c-utility/inc/azure_c_shared_utility/doublylinkedlist.h" 20 | #include "az_iot/c-utility/inc/azure_c_shared_utility/strings.h" 21 | #include "iothub_message.h" 22 | #include "iothub_client_authorization.h" 23 | 24 | struct MESSAGE_DISPOSITION_CONTEXT_TAG; 25 | typedef struct MESSAGE_DISPOSITION_CONTEXT_TAG* MESSAGE_DISPOSITION_CONTEXT_HANDLE; 26 | typedef struct MESSAGE_CALLBACK_INFO_TAG 27 | { 28 | IOTHUB_MESSAGE_HANDLE messageHandle; 29 | MESSAGE_DISPOSITION_CONTEXT_HANDLE transportContext; 30 | }MESSAGE_CALLBACK_INFO; 31 | 32 | #include "iothub_client_ll.h" 33 | 34 | #ifdef __cplusplus 35 | extern "C" 36 | { 37 | #endif 38 | 39 | /** @brief This struct captures device configuration. */ 40 | typedef struct IOTHUB_DEVICE_CONFIG_TAG 41 | { 42 | /** @brief A string that identifies the device. */ 43 | const char* deviceId; 44 | 45 | /** @brief The device key used to authenticate the device. */ 46 | const char* deviceKey; 47 | 48 | /** @brief The device SAS used to authenticate the device in place of using the device key. */ 49 | const char* deviceSasToken; 50 | 51 | IOTHUB_AUTHORIZATION_HANDLE authorization_module; // with either SAS Token, x509 Certs, and Device SAS Token 52 | } IOTHUB_DEVICE_CONFIG; 53 | 54 | typedef STRING_HANDLE (*pfIoTHubTransport_GetHostname)(TRANSPORT_LL_HANDLE handle); 55 | typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_SetOption)(TRANSPORT_LL_HANDLE handle, const char *optionName, const void* value); 56 | typedef TRANSPORT_LL_HANDLE(*pfIoTHubTransport_Create)(const IOTHUBTRANSPORT_CONFIG* config); 57 | typedef void (*pfIoTHubTransport_Destroy)(TRANSPORT_LL_HANDLE handle); 58 | typedef IOTHUB_DEVICE_HANDLE(*pfIotHubTransport_Register)(TRANSPORT_LL_HANDLE handle, const IOTHUB_DEVICE_CONFIG* device, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle, PDLIST_ENTRY waitingToSend); 59 | typedef void(*pfIotHubTransport_Unregister)(IOTHUB_DEVICE_HANDLE deviceHandle); 60 | typedef int (*pfIoTHubTransport_Subscribe)(IOTHUB_DEVICE_HANDLE handle); 61 | typedef void (*pfIoTHubTransport_Unsubscribe)(IOTHUB_DEVICE_HANDLE handle); 62 | typedef void (*pfIoTHubTransport_DoWork)(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_LL_HANDLE iotHubClientHandle); 63 | typedef int(*pfIoTHubTransport_SetRetryPolicy)(TRANSPORT_LL_HANDLE handle, IOTHUB_CLIENT_RETRY_POLICY retryPolicy, size_t retryTimeoutLimitInSeconds); 64 | typedef IOTHUB_CLIENT_RESULT(*pfIoTHubTransport_GetSendStatus)(IOTHUB_DEVICE_HANDLE handle, IOTHUB_CLIENT_STATUS *iotHubClientStatus); 65 | typedef int (*pfIoTHubTransport_Subscribe_DeviceTwin)(IOTHUB_DEVICE_HANDLE handle); 66 | typedef void (*pfIoTHubTransport_Unsubscribe_DeviceTwin)(IOTHUB_DEVICE_HANDLE handle); 67 | typedef IOTHUB_CLIENT_RESULT(*pfIotHubTransport_SendMessageDisposition)(MESSAGE_CALLBACK_INFO* messageData, IOTHUBMESSAGE_DISPOSITION_RESULT disposition); 68 | typedef IOTHUB_PROCESS_ITEM_RESULT(*pfIoTHubTransport_ProcessItem)(TRANSPORT_LL_HANDLE handle, IOTHUB_IDENTITY_TYPE item_type, IOTHUB_IDENTITY_INFO* iothub_item); 69 | typedef int(*pfIoTHubTransport_Subscribe_DeviceMethod)(IOTHUB_DEVICE_HANDLE handle); 70 | typedef void(*pfIoTHubTransport_Unsubscribe_DeviceMethod)(IOTHUB_DEVICE_HANDLE handle); 71 | typedef int(*pfIoTHubTransport_DeviceMethod_Response)(IOTHUB_DEVICE_HANDLE handle, METHOD_HANDLE methodId, const unsigned char* response, size_t response_size, int status_response); 72 | 73 | #define TRANSPORT_PROVIDER_FIELDS \ 74 | pfIotHubTransport_SendMessageDisposition IoTHubTransport_SendMessageDisposition; \ 75 | pfIoTHubTransport_Subscribe_DeviceMethod IoTHubTransport_Subscribe_DeviceMethod; \ 76 | pfIoTHubTransport_Unsubscribe_DeviceMethod IoTHubTransport_Unsubscribe_DeviceMethod;\ 77 | pfIoTHubTransport_DeviceMethod_Response IoTHubTransport_DeviceMethod_Response; \ 78 | pfIoTHubTransport_Subscribe_DeviceTwin IoTHubTransport_Subscribe_DeviceTwin; \ 79 | pfIoTHubTransport_Unsubscribe_DeviceTwin IoTHubTransport_Unsubscribe_DeviceTwin; \ 80 | pfIoTHubTransport_ProcessItem IoTHubTransport_ProcessItem; \ 81 | pfIoTHubTransport_GetHostname IoTHubTransport_GetHostname; \ 82 | pfIoTHubTransport_SetOption IoTHubTransport_SetOption; \ 83 | pfIoTHubTransport_Create IoTHubTransport_Create; \ 84 | pfIoTHubTransport_Destroy IoTHubTransport_Destroy; \ 85 | pfIotHubTransport_Register IoTHubTransport_Register; \ 86 | pfIotHubTransport_Unregister IoTHubTransport_Unregister; \ 87 | pfIoTHubTransport_Subscribe IoTHubTransport_Subscribe; \ 88 | pfIoTHubTransport_Unsubscribe IoTHubTransport_Unsubscribe; \ 89 | pfIoTHubTransport_DoWork IoTHubTransport_DoWork; \ 90 | pfIoTHubTransport_SetRetryPolicy IoTHubTransport_SetRetryPolicy; \ 91 | pfIoTHubTransport_GetSendStatus IoTHubTransport_GetSendStatus /*there's an intentional missing ; on this line*/ 92 | 93 | struct TRANSPORT_PROVIDER_TAG 94 | { 95 | TRANSPORT_PROVIDER_FIELDS; 96 | }; 97 | 98 | #ifdef __cplusplus 99 | } 100 | #endif 101 | 102 | #endif /* IOTHUB_TRANSPORT_LL_H */ 103 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothubtransport.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUB_TRANSPORT_H 5 | #define IOTHUB_TRANSPORT_H 6 | 7 | typedef struct TRANSPORT_HANDLE_DATA_TAG* TRANSPORT_HANDLE; 8 | 9 | 10 | #include "az_iot/c-utility/inc/azure_c_shared_utility/lock.h" 11 | #include "az_iot/c-utility/inc/azure_c_shared_utility/crt_abstractions.h" 12 | 13 | #include "iothub_client_ll.h" 14 | #include "iothub_client_private.h" 15 | #include "iothub_transport_ll.h" 16 | 17 | #ifndef IOTHUB_CLIENT_INSTANCE_TYPE 18 | typedef struct IOTHUB_CLIENT_INSTANCE_TAG* IOTHUB_CLIENT_HANDLE; 19 | #define IOTHUB_CLIENT_INSTANCE_TYPE 20 | #endif // IOTHUB_CLIENT_INSTANCE 21 | 22 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 23 | 24 | typedef void(*IOTHUB_CLIENT_MULTIPLEXED_DO_WORK)(void* iotHubClientInstance); 25 | 26 | #ifdef __cplusplus 27 | extern "C" 28 | { 29 | #endif 30 | 31 | MOCKABLE_FUNCTION(, TRANSPORT_HANDLE, IoTHubTransport_Create, IOTHUB_CLIENT_TRANSPORT_PROVIDER, protocol, const char*, iotHubName, const char*, iotHubSuffix); 32 | MOCKABLE_FUNCTION(, void, IoTHubTransport_Destroy, TRANSPORT_HANDLE, transportHandle); 33 | MOCKABLE_FUNCTION(, LOCK_HANDLE, IoTHubTransport_GetLock, TRANSPORT_HANDLE, transportHandle); 34 | MOCKABLE_FUNCTION(, TRANSPORT_LL_HANDLE, IoTHubTransport_GetLLTransport, TRANSPORT_HANDLE, transportHandle); 35 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubTransport_StartWorkerThread, TRANSPORT_HANDLE, transportHandle, IOTHUB_CLIENT_HANDLE, clientHandle, IOTHUB_CLIENT_MULTIPLEXED_DO_WORK, muxDoWork); 36 | MOCKABLE_FUNCTION(, bool, IoTHubTransport_SignalEndWorkerThread, TRANSPORT_HANDLE, transportHandle, IOTHUB_CLIENT_HANDLE, clientHandle); 37 | MOCKABLE_FUNCTION(, void, IoTHubTransport_JoinWorkerThread, TRANSPORT_HANDLE, transportHandle, IOTHUB_CLIENT_HANDLE, clientHandle); 38 | 39 | #ifdef __cplusplus 40 | } 41 | #endif 42 | 43 | #endif /* IOTHUB_TRANSPORT_H */ 44 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothubtransport_mqtt_common.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUBTRANSPORT_MQTT_COMMON_H 5 | #define IOTHUBTRANSPORT_MQTT_COMMON_H 6 | 7 | #include "../inc/iothub_transport_ll.h" 8 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 9 | 10 | #ifdef __cplusplus 11 | extern "C" 12 | { 13 | #endif 14 | 15 | typedef struct MQTT_TRANSPORT_PROXY_OPTIONS_TAG 16 | { 17 | const char* host_address; 18 | int port; 19 | const char* username; 20 | const char* password; 21 | } MQTT_TRANSPORT_PROXY_OPTIONS; 22 | 23 | typedef XIO_HANDLE(*MQTT_GET_IO_TRANSPORT)(const char* fully_qualified_name, const MQTT_TRANSPORT_PROXY_OPTIONS* mqtt_transport_proxy_options); 24 | 25 | MOCKABLE_FUNCTION(, TRANSPORT_LL_HANDLE, IoTHubTransport_MQTT_Common_Create, const IOTHUBTRANSPORT_CONFIG*, config, MQTT_GET_IO_TRANSPORT, get_io_transport); 26 | MOCKABLE_FUNCTION(, void, IoTHubTransport_MQTT_Common_Destroy, TRANSPORT_LL_HANDLE, handle); 27 | MOCKABLE_FUNCTION(, int, IoTHubTransport_MQTT_Common_Subscribe, IOTHUB_DEVICE_HANDLE, handle); 28 | MOCKABLE_FUNCTION(, void, IoTHubTransport_MQTT_Common_Unsubscribe, IOTHUB_DEVICE_HANDLE, handle); 29 | MOCKABLE_FUNCTION(, int, IoTHubTransport_MQTT_Common_Subscribe_DeviceTwin, IOTHUB_DEVICE_HANDLE, handle); 30 | MOCKABLE_FUNCTION(, void, IoTHubTransport_MQTT_Common_Unsubscribe_DeviceTwin, IOTHUB_DEVICE_HANDLE, handle); 31 | MOCKABLE_FUNCTION(, int, IoTHubTransport_MQTT_Common_Subscribe_DeviceMethod, IOTHUB_DEVICE_HANDLE, handle); 32 | MOCKABLE_FUNCTION(, void, IoTHubTransport_MQTT_Common_Unsubscribe_DeviceMethod, IOTHUB_DEVICE_HANDLE, handle); 33 | MOCKABLE_FUNCTION(, int, IoTHubTransport_MQTT_Common_DeviceMethod_Response, IOTHUB_DEVICE_HANDLE, handle, METHOD_HANDLE, methodId, const unsigned char*, response, size_t, response_size, int, status_response); 34 | MOCKABLE_FUNCTION(, IOTHUB_PROCESS_ITEM_RESULT, IoTHubTransport_MQTT_Common_ProcessItem, TRANSPORT_LL_HANDLE, handle, IOTHUB_IDENTITY_TYPE, item_type, IOTHUB_IDENTITY_INFO*, iothub_item); 35 | MOCKABLE_FUNCTION(, void, IoTHubTransport_MQTT_Common_DoWork, TRANSPORT_LL_HANDLE, handle, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle); 36 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubTransport_MQTT_Common_GetSendStatus, IOTHUB_DEVICE_HANDLE, handle, IOTHUB_CLIENT_STATUS*, iotHubClientStatus); 37 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubTransport_MQTT_Common_SetOption, TRANSPORT_LL_HANDLE, handle, const char*, option, const void*, value); 38 | MOCKABLE_FUNCTION(, IOTHUB_DEVICE_HANDLE, IoTHubTransport_MQTT_Common_Register, TRANSPORT_LL_HANDLE, handle, const IOTHUB_DEVICE_CONFIG*, device, IOTHUB_CLIENT_LL_HANDLE, iotHubClientHandle, PDLIST_ENTRY, waitingToSend); 39 | MOCKABLE_FUNCTION(, void, IoTHubTransport_MQTT_Common_Unregister, IOTHUB_DEVICE_HANDLE, deviceHandle); 40 | MOCKABLE_FUNCTION(, int, IoTHubTransport_MQTT_Common_SetRetryPolicy, TRANSPORT_LL_HANDLE, handle, IOTHUB_CLIENT_RETRY_POLICY, retryPolicy, size_t, retryTimeoutLimitInSeconds); 41 | MOCKABLE_FUNCTION(, STRING_HANDLE, IoTHubTransport_MQTT_Common_GetHostname, TRANSPORT_LL_HANDLE, handle); 42 | MOCKABLE_FUNCTION(, IOTHUB_CLIENT_RESULT, IoTHubTransport_MQTT_Common_SendMessageDisposition, MESSAGE_CALLBACK_INFO*, message_data, IOTHUBMESSAGE_DISPOSITION_RESULT, disposition) 43 | 44 | 45 | #ifdef __cplusplus 46 | } 47 | #endif 48 | 49 | #endif /* IOTHUBTRANSPORT_MQTT_COMMON_H */ 50 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/inc/iothubtransportmqtt.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef IOTHUBTRANSPORTMQTT_H 5 | #define IOTHUBTRANSPORTMQTT_H 6 | 7 | #include "iothub_transport_ll.h" 8 | 9 | #ifdef __cplusplus 10 | extern "C" 11 | { 12 | #endif 13 | extern const TRANSPORT_PROVIDER* MQTT_Protocol(void); 14 | 15 | #ifdef __cplusplus 16 | } 17 | #endif 18 | 19 | #endif /*IOTHUBTRANSPORTMQTT_H*/ 20 | -------------------------------------------------------------------------------- /src/az_iot/iothub_client/src/version.c: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #include "../inc/iothub_client_version.h" 5 | 6 | const char* IoTHubClient_GetVersionString(void) 7 | { 8 | /*Codes_SRS_IOTHUBCLIENT_05_001: [IoTHubClient_GetVersionString shall return a pointer to a constant string which indicates the version of IoTHubClient API.]*/ 9 | return IOTHUB_SDK_VERSION; 10 | } 11 | -------------------------------------------------------------------------------- /src/az_iot/umqtt/inc/azure_umqtt_c/mqtt_client.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef MQTT_CLIENT_H 5 | #define MQTT_CLIENT_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | extern "C" { 10 | #else 11 | #include 12 | #endif // __cplusplus 13 | 14 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xio.h" 15 | #include "az_iot/c-utility/inc/azure_c_shared_utility/macro_utils.h" 16 | #include "mqttconst.h" 17 | #include "mqtt_message.h" 18 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 19 | 20 | typedef struct MQTT_CLIENT_TAG* MQTT_CLIENT_HANDLE; 21 | 22 | #define MQTT_CLIENT_EVENT_VALUES \ 23 | MQTT_CLIENT_ON_CONNACK, \ 24 | MQTT_CLIENT_ON_PUBLISH_ACK, \ 25 | MQTT_CLIENT_ON_PUBLISH_RECV, \ 26 | MQTT_CLIENT_ON_PUBLISH_REL, \ 27 | MQTT_CLIENT_ON_PUBLISH_COMP, \ 28 | MQTT_CLIENT_ON_SUBSCRIBE_ACK, \ 29 | MQTT_CLIENT_ON_UNSUBSCRIBE_ACK, \ 30 | MQTT_CLIENT_ON_PING_RESPONSE, \ 31 | MQTT_CLIENT_ON_DISCONNECT 32 | 33 | DEFINE_ENUM(MQTT_CLIENT_EVENT_RESULT, MQTT_CLIENT_EVENT_VALUES); 34 | 35 | #define MQTT_CLIENT_EVENT_ERROR_VALUES \ 36 | MQTT_CLIENT_CONNECTION_ERROR, \ 37 | MQTT_CLIENT_PARSE_ERROR, \ 38 | MQTT_CLIENT_MEMORY_ERROR, \ 39 | MQTT_CLIENT_COMMUNICATION_ERROR, \ 40 | MQTT_CLIENT_NO_PING_RESPONSE, \ 41 | MQTT_CLIENT_UNKNOWN_ERROR 42 | 43 | DEFINE_ENUM(MQTT_CLIENT_EVENT_ERROR, MQTT_CLIENT_EVENT_ERROR_VALUES); 44 | 45 | typedef void(*ON_MQTT_OPERATION_CALLBACK)(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_RESULT actionResult, const void* msgInfo, void* callbackCtx); 46 | typedef void(*ON_MQTT_ERROR_CALLBACK)(MQTT_CLIENT_HANDLE handle, MQTT_CLIENT_EVENT_ERROR error, void* callbackCtx); 47 | typedef void(*ON_MQTT_MESSAGE_RECV_CALLBACK)(MQTT_MESSAGE_HANDLE msgHandle, void* callbackCtx); 48 | typedef void(*ON_MQTT_DISCONNECTED_CALLBACK)(void* callbackCtx); 49 | 50 | MOCKABLE_FUNCTION(, MQTT_CLIENT_HANDLE, mqtt_client_init, ON_MQTT_MESSAGE_RECV_CALLBACK, msgRecv, ON_MQTT_OPERATION_CALLBACK, opCallback, void*, opCallbackCtx, ON_MQTT_ERROR_CALLBACK, onErrorCallBack, void*, errorCBCtx); 51 | MOCKABLE_FUNCTION(, void, mqtt_client_deinit, MQTT_CLIENT_HANDLE, handle); 52 | 53 | MOCKABLE_FUNCTION(, int, mqtt_client_connect, MQTT_CLIENT_HANDLE, handle, XIO_HANDLE, xioHandle, MQTT_CLIENT_OPTIONS*, mqttOptions); 54 | MOCKABLE_FUNCTION(, int, mqtt_client_disconnect, MQTT_CLIENT_HANDLE, handle, ON_MQTT_DISCONNECTED_CALLBACK, callback, void*, ctx); 55 | 56 | MOCKABLE_FUNCTION(, int, mqtt_client_subscribe, MQTT_CLIENT_HANDLE, handle, uint16_t, packetId, SUBSCRIBE_PAYLOAD*, subscribeList, size_t, count); 57 | MOCKABLE_FUNCTION(, int, mqtt_client_unsubscribe, MQTT_CLIENT_HANDLE, handle, uint16_t, packetId, const char**, unsubscribeList, size_t, count); 58 | 59 | MOCKABLE_FUNCTION(, int, mqtt_client_publish, MQTT_CLIENT_HANDLE, handle, MQTT_MESSAGE_HANDLE, msgHandle); 60 | 61 | MOCKABLE_FUNCTION(, void, mqtt_client_dowork, MQTT_CLIENT_HANDLE, handle); 62 | 63 | MOCKABLE_FUNCTION(, void, mqtt_client_set_trace, MQTT_CLIENT_HANDLE, handle, bool, traceOn, bool, rawBytesOn); 64 | 65 | #ifdef __cplusplus 66 | } 67 | #endif // __cplusplus 68 | 69 | #endif // MQTTCLIENT_H 70 | -------------------------------------------------------------------------------- /src/az_iot/umqtt/inc/azure_umqtt_c/mqtt_codec.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef MQTT_CODEC_H 5 | #define MQTT_CODEC_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #include 10 | #include 11 | extern "C" { 12 | #else 13 | #include 14 | #include 15 | #include 16 | #endif // __cplusplus 17 | 18 | #include "az_iot/c-utility/inc/azure_c_shared_utility/xio.h" 19 | #include "az_iot/c-utility/inc/azure_c_shared_utility/buffer_.h" 20 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 21 | #include "mqttconst.h" 22 | #include "az_iot/c-utility/inc/azure_c_shared_utility/strings.h" 23 | 24 | typedef struct MQTTCODEC_INSTANCE_TAG* MQTTCODEC_HANDLE; 25 | 26 | typedef void(*ON_PACKET_COMPLETE_CALLBACK)(void* context, CONTROL_PACKET_TYPE packet, int flags, BUFFER_HANDLE headerData); 27 | 28 | MOCKABLE_FUNCTION(, MQTTCODEC_HANDLE, mqtt_codec_create, ON_PACKET_COMPLETE_CALLBACK, packetComplete, void*, callbackCtx); 29 | MOCKABLE_FUNCTION(, void, mqtt_codec_destroy, MQTTCODEC_HANDLE, handle); 30 | 31 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_connect, const MQTT_CLIENT_OPTIONS*, mqttOptions, STRING_HANDLE, trace_log); 32 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_disconnect); 33 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_publish, QOS_VALUE, qosValue, bool, duplicateMsg, bool, serverRetain, uint16_t, packetId, const char*, topicName, const uint8_t*, msgBuffer, size_t, buffLen, STRING_HANDLE, trace_log); 34 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_publishAck, uint16_t, packetId); 35 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_publishReceived, uint16_t, packetId); 36 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_publishRelease, uint16_t, packetId); 37 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_publishComplete, uint16_t, packetId); 38 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_ping); 39 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_subscribe, uint16_t, packetId, SUBSCRIBE_PAYLOAD*, subscribeList, size_t, count, STRING_HANDLE, trace_log); 40 | MOCKABLE_FUNCTION(, BUFFER_HANDLE, mqtt_codec_unsubscribe, uint16_t, packetId, const char**, unsubscribeList, size_t, count, STRING_HANDLE, trace_log); 41 | 42 | MOCKABLE_FUNCTION(, int, mqtt_codec_bytesReceived, MQTTCODEC_HANDLE, handle, const unsigned char*, buffer, size_t, size); 43 | 44 | #ifdef __cplusplus 45 | } 46 | #endif // __cplusplus 47 | 48 | #endif // MQTT_CODEC_H 49 | -------------------------------------------------------------------------------- /src/az_iot/umqtt/inc/azure_umqtt_c/mqtt_message.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef MQTT_MESSAGE_H 5 | #define MQTT_MESSAGE_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #include 10 | #include 11 | extern "C" { 12 | #else 13 | #include 14 | #include 15 | #include 16 | #endif // __cplusplus 17 | 18 | #include "mqttconst.h" 19 | #include "az_iot/c-utility/inc/azure_c_shared_utility/umock_c_prod.h" 20 | 21 | typedef struct MQTT_MESSAGE_TAG* MQTT_MESSAGE_HANDLE; 22 | 23 | MOCKABLE_FUNCTION(, MQTT_MESSAGE_HANDLE, mqttmessage_create_in_place, uint16_t, packetId, const char*, topicName, QOS_VALUE, qosValue, const uint8_t*, appMsg, size_t, appMsgLength); 24 | MOCKABLE_FUNCTION(, MQTT_MESSAGE_HANDLE, mqttmessage_create, uint16_t, packetId, const char*, topicName, QOS_VALUE, qosValue, const uint8_t*, appMsg, size_t, appMsgLength); 25 | MOCKABLE_FUNCTION(,void, mqttmessage_destroy, MQTT_MESSAGE_HANDLE, handle); 26 | MOCKABLE_FUNCTION(,MQTT_MESSAGE_HANDLE, mqttmessage_clone, MQTT_MESSAGE_HANDLE, handle); 27 | 28 | MOCKABLE_FUNCTION(, uint16_t, mqttmessage_getPacketId, MQTT_MESSAGE_HANDLE, handle); 29 | MOCKABLE_FUNCTION(, const char*, mqttmessage_getTopicName, MQTT_MESSAGE_HANDLE, handle); 30 | MOCKABLE_FUNCTION(, QOS_VALUE, mqttmessage_getQosType, MQTT_MESSAGE_HANDLE, handle); 31 | MOCKABLE_FUNCTION(, bool, mqttmessage_getIsDuplicateMsg, MQTT_MESSAGE_HANDLE, handle); 32 | MOCKABLE_FUNCTION(, bool, mqttmessage_getIsRetained, MQTT_MESSAGE_HANDLE, handle); 33 | MOCKABLE_FUNCTION(, int, mqttmessage_setIsDuplicateMsg, MQTT_MESSAGE_HANDLE, handle, bool, duplicateMsg); 34 | MOCKABLE_FUNCTION(, int, mqttmessage_setIsRetained, MQTT_MESSAGE_HANDLE, handle, bool, retainMsg); 35 | MOCKABLE_FUNCTION(, const APP_PAYLOAD*, mqttmessage_getApplicationMsg, MQTT_MESSAGE_HANDLE, handle); 36 | 37 | #ifdef __cplusplus 38 | } 39 | #endif // __cplusplus 40 | 41 | #endif // MQTT_MESSAGE_H 42 | -------------------------------------------------------------------------------- /src/az_iot/umqtt/inc/azure_umqtt_c/mqttconst.h: -------------------------------------------------------------------------------- 1 | // Copyright (c) Microsoft. All rights reserved. 2 | // Licensed under the MIT license. See LICENSE file in the project root for full license information. 3 | 4 | #ifndef MQTTCONST_H 5 | #define MQTTCONST_H 6 | 7 | #ifdef __cplusplus 8 | #include 9 | #include 10 | extern "C" { 11 | #else 12 | #include 13 | #include 14 | #endif /* __cplusplus */ 15 | 16 | #include "az_iot/c-utility/inc/azure_c_shared_utility/crt_abstractions.h" 17 | 18 | #define CONTROL_PACKET_TYPE_VALUES \ 19 | CONNECT_TYPE = 0x10, \ 20 | CONNACK_TYPE = 0x20, \ 21 | PUBLISH_TYPE = 0x30, \ 22 | PUBACK_TYPE = 0x40, \ 23 | PUBREC_TYPE = 0x50, \ 24 | PUBREL_TYPE = 0x60, \ 25 | PUBCOMP_TYPE = 0x70, \ 26 | SUBSCRIBE_TYPE = 0x80, \ 27 | SUBACK_TYPE = 0x90, \ 28 | UNSUBSCRIBE_TYPE = 0xA0, \ 29 | UNSUBACK_TYPE = 0xB0, \ 30 | PINGREQ_TYPE = 0xC0, \ 31 | PINGRESP_TYPE = 0xD0, \ 32 | DISCONNECT_TYPE = 0xE0, \ 33 | PACKET_TYPE_ERROR, \ 34 | UNKNOWN_TYPE 35 | 36 | DEFINE_ENUM(CONTROL_PACKET_TYPE, CONTROL_PACKET_TYPE_VALUES) 37 | 38 | #define QOS_VALUE_VALUES \ 39 | DELIVER_AT_MOST_ONCE = 0x00, \ 40 | DELIVER_AT_LEAST_ONCE = 0x01, \ 41 | DELIVER_EXACTLY_ONCE = 0x02, \ 42 | DELIVER_FAILURE = 0x80 43 | 44 | DEFINE_ENUM(QOS_VALUE, QOS_VALUE_VALUES) 45 | 46 | typedef struct APP_PAYLOAD_TAG 47 | { 48 | uint8_t* message; 49 | size_t length; 50 | } APP_PAYLOAD; 51 | 52 | typedef struct MQTT_CLIENT_OPTIONS_TAG 53 | { 54 | char* clientId; 55 | char* willTopic; 56 | char* willMessage; 57 | char* username; 58 | char* password; 59 | uint16_t keepAliveInterval; 60 | bool messageRetain; 61 | bool useCleanSession; 62 | QOS_VALUE qualityOfServiceValue; 63 | bool log_trace; 64 | } MQTT_CLIENT_OPTIONS; 65 | 66 | typedef enum CONNECT_RETURN_CODE_TAG 67 | { 68 | CONNECTION_ACCEPTED = 0x00, 69 | CONN_REFUSED_UNACCEPTABLE_VERSION = 0x01, 70 | CONN_REFUSED_ID_REJECTED = 0x02, 71 | CONN_REFUSED_SERVER_UNAVAIL = 0x03, 72 | CONN_REFUSED_BAD_USERNAME_PASSWORD = 0x04, 73 | CONN_REFUSED_NOT_AUTHORIZED = 0x05, 74 | CONN_REFUSED_UNKNOWN 75 | } CONNECT_RETURN_CODE; 76 | 77 | typedef struct CONNECT_ACK_TAG 78 | { 79 | bool isSessionPresent; 80 | CONNECT_RETURN_CODE returnCode; 81 | } CONNECT_ACK; 82 | 83 | typedef struct SUBSCRIBE_PAYLOAD_TAG 84 | { 85 | const char* subscribeTopic; 86 | QOS_VALUE qosReturn; 87 | } SUBSCRIBE_PAYLOAD; 88 | 89 | typedef struct SUBSCRIBE_ACK_TAG 90 | { 91 | uint16_t packetId; 92 | QOS_VALUE* qosReturn; 93 | size_t qosCount; 94 | } SUBSCRIBE_ACK; 95 | 96 | typedef struct UNSUBSCRIBE_ACK_TAG 97 | { 98 | uint16_t packetId; 99 | } UNSUBSCRIBE_ACK; 100 | 101 | typedef struct PUBLISH_ACK_TAG 102 | { 103 | uint16_t packetId; 104 | } PUBLISH_ACK; 105 | 106 | #ifdef __cplusplus 107 | } 108 | #endif /* __cplusplus */ 109 | 110 | #endif // MQTTCONST_H --------------------------------------------------------------------------------