source: azure_iot_hub_f767zi/trunk/azure_iot_sdk/iothub_client/inc/iothub_message.h

Last change on this file was 464, checked in by coas-nagasima, 3 years ago

WolfSSLとAzure IoT SDKを更新

  • Property svn:eol-style set to native
  • Property svn:mime-type set to text/x-chdr;charset=UTF-8
File size: 18.7 KB
Line 
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_message.h
5* @brief The @c IoTHub_Message component encapsulates one message that
6* can be transferred by an IoT hub client.
7*/
8
9#ifndef IOTHUB_MESSAGE_H
10#define IOTHUB_MESSAGE_H
11
12#include "azure_macro_utils/macro_utils.h"
13#include "azure_c_shared_utility/map.h"
14#include "umock_c/umock_c_prod.h"
15
16#ifdef __cplusplus
17#include <cstddef>
18extern "C"
19{
20#else
21#include <stddef.h>
22#endif
23
24#define IOTHUB_MESSAGE_RESULT_VALUES \
25 IOTHUB_MESSAGE_OK, \
26 IOTHUB_MESSAGE_INVALID_ARG, \
27 IOTHUB_MESSAGE_INVALID_TYPE, \
28 IOTHUB_MESSAGE_ERROR \
29
30/** @brief Enumeration specifying the status of calls to various
31* APIs in this module.
32*/
33MU_DEFINE_ENUM_WITHOUT_INVALID(IOTHUB_MESSAGE_RESULT, IOTHUB_MESSAGE_RESULT_VALUES);
34
35#define IOTHUBMESSAGE_CONTENT_TYPE_VALUES \
36IOTHUBMESSAGE_BYTEARRAY, \
37IOTHUBMESSAGE_STRING, \
38IOTHUBMESSAGE_UNKNOWN \
39
40/** @brief Enumeration specifying the content type of the a given
41* message.
42*/
43MU_DEFINE_ENUM_WITHOUT_INVALID(IOTHUBMESSAGE_CONTENT_TYPE, IOTHUBMESSAGE_CONTENT_TYPE_VALUES);
44
45typedef struct IOTHUB_MESSAGE_HANDLE_DATA_TAG* IOTHUB_MESSAGE_HANDLE;
46
47/** @brief diagnostic related data*/
48typedef struct IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_TAG
49{
50 char* diagnosticId;
51 char* diagnosticCreationTimeUtc;
52}IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA, *IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE;
53
54static const char DIAG_CREATION_TIME_UTC_PROPERTY_NAME[] = "diag_creation_time_utc";
55
56/**
57* @brief Creates a new IoT hub message from a byte array. The type of the
58* message will be set to @c IOTHUBMESSAGE_BYTEARRAY.
59*
60* @param byteArray The byte array from which the message is to be created.
61* @param size The size of the byte array.
62*
63* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
64* created or @c NULL in case an error occurs.
65*/
66MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_CreateFromByteArray, const unsigned char*, byteArray, size_t, size);
67
68/**
69* @brief Creates a new IoT hub message from a null terminated string. The
70* type of the message will be set to @c IOTHUBMESSAGE_STRING.
71*
72* @param source The null terminated string from which the message is to be
73* created.
74*
75* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
76* created or @c NULL in case an error occurs.
77*/
78MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_CreateFromString, const char*, source);
79
80/**
81* @brief Creates a new IoT hub message with the content identical to that
82* of the @p iotHubMessageHandle parameter.
83*
84* @param iotHubMessageHandle Handle to the message that is to be cloned.
85*
86* @return A valid @c IOTHUB_MESSAGE_HANDLE if the message was successfully
87* cloned or @c NULL in case an error occurs.
88*/
89MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_HANDLE, IoTHubMessage_Clone, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
90
91/**
92* @brief Fetches a pointer and size for the data associated with the IoT
93* hub message handle. If the content type of the message is not
94* @c IOTHUBMESSAGE_BYTEARRAY then the function returns
95* @c IOTHUB_MESSAGE_INVALID_ARG.
96*
97* @param iotHubMessageHandle Handle to the message.
98* @param buffer Pointer to the memory location where the
99* pointer to the buffer will be written.
100* @param size The size of the buffer will be written to
101* this address.
102*
103* @return Returns IOTHUB_MESSAGE_OK if the byte array was fetched successfully
104* or an error code otherwise.
105*/
106MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_GetByteArray, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const unsigned char**, buffer, size_t*, size);
107
108/**
109* @brief Returns the null terminated string stored in the message.
110* If the content type of the message is not @c IOTHUBMESSAGE_STRING
111* then the function returns @c NULL. No new memory is allocated,
112* the caller is not responsible for freeing the memory. The memory
113* is valid until IoTHubMessage_Destroy is called on the message.
114*
115* @param iotHubMessageHandle Handle to the message.
116*
117* @return @c NULL if an error occurs or a pointer to the stored null
118* terminated string otherwise.
119*/
120MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetString, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
121
122/**
123* @brief Returns the content type of the message given by parameter
124* @c iotHubMessageHandle.
125*
126* @param iotHubMessageHandle Handle to the message.
127*
128* @remarks This function retrieves the standardized type of the payload, which indicates if @c iotHubMessageHandle was created using a String or a Byte Array.
129*
130* @return An @c IOTHUBMESSAGE_CONTENT_TYPE value.
131*/
132MOCKABLE_FUNCTION(, IOTHUBMESSAGE_CONTENT_TYPE, IoTHubMessage_GetContentType, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
133
134/**
135* @brief Sets the content-type of the message payload, as per supported values on RFC 2046.
136*
137* @param iotHubMessageHandle Handle to the message.
138*
139* @param contentType String defining the type of the payload (e.g., text/plain).
140*
141* @return An @c IOTHUB_MESSAGE_RESULT value.
142*/
143MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetContentTypeSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, contentType);
144
145/**
146* @brief Returns the content-type of the message payload, if defined. No new memory is allocated,
147* the caller is not responsible for freeing the memory. The memory
148* is valid until IoTHubMessage_Destroy is called on the message.
149*
150* @param iotHubMessageHandle Handle to the message.
151*
152* @return A string with the content-type value if defined (or NULL otherwise).
153*/
154MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetContentTypeSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
155
156/**
157* @brief Sets the content-encoding of the message payload, as per supported values on RFC 2616.
158*
159* @param iotHubMessageHandle Handle to the message.
160*
161* @param contentEncoding String defining the encoding of the payload (e.g., utf-8).
162*
163* @return An @c IOTHUB_MESSAGE_RESULT value.
164*/
165MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetContentEncodingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, contentEncoding);
166
167/**
168* @brief Returns the content-encoding of the message payload, if defined. No new memory is allocated,
169* the caller is not responsible for freeing the memory. The memory
170* is valid until IoTHubMessage_Destroy is called on the message.
171*
172* @param iotHubMessageHandle Handle to the message.
173*
174* @return A string with the content-encoding value if defined (or NULL otherwise).
175*/
176MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetContentEncodingSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
177
178/**
179** DEPRECATED: Use IoTHubMessage_SetProperty and IoTHubMessage_GetProperty instead. **
180* @brief Gets a handle to the message's properties map.
181* Note that when sending messages via the HTTP transport, the key names in the map must not contain spaces.
182*
183* @param iotHubMessageHandle Handle to the message.
184*
185* @return A @c MAP_HANDLE pointing to the properties map for this message.
186*/
187MOCKABLE_FUNCTION(, MAP_HANDLE, IoTHubMessage_Properties, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
188
189/**
190* @brief Sets a property on a Iothub Message.
191*
192* @param iotHubMessageHandle Handle to the message.
193*
194* @param key name of the property to set. Note that when sending messages via the HTTP transport, this value must not contain spaces.
195*
196* @param value of the property to set.
197*
198* @b NOTE: The accepted character sets for the key name and value parameters are dependent on different factors, such as the protocol
199* being used. For more information on the character sets accepted by Azure IoT Hub, see
200* <a href="https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messages-construct">Create and read IoT Hub messages</a>.
201*
202* @return An @c IOTHUB_MESSAGE_RESULT value indicating the result of setting the property.
203*/
204MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, key, const char*, value);
205
206/**
207* @brief Gets a IotHub Message's properties item. No new memory is allocated,
208* the caller is not responsible for freeing the memory. The memory
209* is valid until IoTHubMessage_Destroy is called on the message.
210*
211* @param iotHubMessageHandle Handle to the message.
212*
213* @param key name of the property to retrieve.
214*
215* @return A string with the property's value, or NULL if it does not exist in the properties list.
216*/
217MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, key);
218
219/**
220* @brief Gets the MessageId from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
221* the caller is not responsible for freeing the memory. The memory
222* is valid until IoTHubMessage_Destroy is called on the message.
223*
224* @param iotHubMessageHandle Handle to the message.
225*
226* @return A const char* pointing to the Message Id.
227*/
228MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
229
230/**
231* @brief Sets the MessageId for the IOTHUB_MESSAGE_HANDLE.
232*
233* @param iotHubMessageHandle Handle to the message.
234* @param messageId Pointer to the memory location of the messageId
235*
236* @return Returns IOTHUB_MESSAGE_OK if the messageId was set successfully
237* or an error code otherwise.
238*/
239MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetMessageId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, messageId);
240
241/**
242* @brief Gets the CorrelationId from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
243* the caller is not responsible for freeing the memory. The memory
244* is valid until IoTHubMessage_Destroy is called on the message.
245*
246* @param iotHubMessageHandle Handle to the message.
247*
248* @return A const char* pointing to the Correlation Id.
249*/
250MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
251
252/**
253* @brief Sets the CorrelationId for the IOTHUB_MESSAGE_HANDLE.
254*
255* @param iotHubMessageHandle Handle to the message.
256* @param correlationId Pointer to the memory location of the messageId
257*
258* @return Returns IOTHUB_MESSAGE_OK if the CorrelationId was set successfully
259* or an error code otherwise.
260*/
261MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetCorrelationId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, correlationId);
262
263/**
264* @brief Gets the DiagnosticData from the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
265*
266* @param iotHubMessageHandle Handle to the message.
267*
268* @return A const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA* pointing to the diagnostic property data.
269*/
270MOCKABLE_FUNCTION(, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, IoTHubMessage_GetDiagnosticPropertyData, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
271
272/**
273* @brief Sets the DiagnosticData for the IOTHUB_MESSAGE_HANDLE. CAUTION: SDK user should not call it directly, it is for internal use only.
274*
275* @param iotHubMessageHandle Handle to the message.
276* @param diagnosticData Pointer to the memory location of the diagnosticData
277*
278* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
279* or an error code otherwise.
280*/
281MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetDiagnosticPropertyData, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA*, diagnosticData);
282
283/**
284* @brief Gets the output name from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
285* the caller is not responsible for freeing the memory. The memory
286* is valid until IoTHubMessage_Destroy is called on the message.
287*
288* @param iotHubMessageHandle Handle to the message.
289*
290* @return A const char* pointing to the Output Id.
291*/
292MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetOutputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
293
294
295/**
296* @brief Sets output for named queues. CAUTION: SDK user should not call it directly, it is for internal use only.
297*
298* @param iotHubMessageHandle Handle to the message.
299* @param outputName Pointer to the queue to output message to
300*
301* @return Returns IOTHUB_MESSAGE_OK if the outputName was set successfully
302* or an error code otherwise.
303*/
304MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetOutputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, outputName);
305
306
307/**
308* @brief Gets the input name from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
309* the caller is not responsible for freeing the memory. The memory
310* is valid until IoTHubMessage_Destroy is called on the message.
311*
312* @param iotHubMessageHandle Handle to the message.
313*
314* @return A const char* pointing to the Input Id.
315*/
316MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetInputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
317
318/**
319* @brief Sets input for named queues. CAUTION: SDK user should not call it directly, it is for internal use only.
320*
321* @param iotHubMessageHandle Handle to the message.
322* @param inputName Pointer to the queue to input message to
323*
324* @return Returns IOTHUB_MESSAGE_OK if the inputName was set successfully
325* or an error code otherwise.
326*/
327MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetInputName, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, inputName);
328
329/**
330* @brief Gets the module name from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
331* the caller is not responsible for freeing the memory. The memory
332* is valid until IoTHubMessage_Destroy is called on the message.
333*
334* @param iotHubMessageHandle Handle to the message.
335*
336* @return A const char* pointing to the connection module Id.
337*/
338MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetConnectionModuleId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
339
340/**
341* @brief Sets connection module ID. CAUTION: SDK user should not call it directly, it is for internal use only.
342*
343* @param iotHubMessageHandle Handle to the message.
344* @param connectionModuleId Pointer to the module ID of connector
345*
346* @return Returns IOTHUB_MESSAGE_OK if the connectionModuleId was set successfully
347* or an error code otherwise.
348*/
349MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetConnectionModuleId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, connectionModuleId);
350
351/**
352* @brief Gets the connection device ID from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
353* the caller is not responsible for freeing the memory. The memory
354* is valid until IoTHubMessage_Destroy is called on the message.
355*
356* @param iotHubMessageHandle Handle to the message.
357*
358* @return A const char* pointing to the connection device Id.
359*/
360MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetConnectionDeviceId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
361
362/**
363* @brief Sets the message creation time in UTC.
364*
365* @param iotHubMessageHandle Handle to the message.
366* @param messageCreationTimeUtc Pointer to the message creation time as null-terminated string
367*
368* @return Returns IOTHUB_MESSAGE_OK if the messageCreationTimeUtc was set successfully
369* or an error code otherwise.
370*/
371MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetMessageCreationTimeUtcSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, messageCreationTimeUtc);
372
373/**
374* @brief Gets the message creation time in UTC from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
375* the caller is not responsible for freeing the memory. The memory
376* is valid until IoTHubMessage_Destroy is called on the message.
377*
378* @param iotHubMessageHandle Handle to the message.
379*
380* @return A const char* pointing to the message creation time in UTC.
381*/
382MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetMessageCreationTimeUtcSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
383
384/**
385* @brief Sets the message user id. CAUTION: SDK user should not call it directly, it is for internal use only.
386*
387* @param iotHubMessageHandle Handle to the message.
388* @param userId Pointer to the message user id as null-terminated string
389*
390* @return Returns IOTHUB_MESSAGE_OK if the userId was set successfully or an error code otherwise.
391*/
392MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetMessageUserIdSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, userId);
393
394/**
395* @brief Gets the message user id from the IOTHUB_MESSAGE_HANDLE. No new memory is allocated,
396* the caller is not responsible for freeing the memory. The memory
397* is valid until IoTHubMessage_Destroy is called on the message.
398*
399* @param iotHubMessageHandle Handle to the message.
400*
401* @return A const char* pointing to the message user id.
402*/
403MOCKABLE_FUNCTION(, const char*, IoTHubMessage_GetMessageUserIdSystemProperty, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
404
405/**
406* @brief Sets connection device Id. CAUTION: SDK user should not call it directly, it is for internal use only.
407*
408* @param iotHubMessageHandle Handle to the message.
409* @param connectionDeviceId Pointer to the device ID of connector
410*
411* @return Returns IOTHUB_MESSAGE_OK if the DiagnosticData was set successfully
412* or an error code otherwise.
413*/
414MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetConnectionDeviceId, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle, const char*, connectionDeviceId);
415
416
417/**
418* @brief Marks a IoTHub message as a security message. CAUTION: Security messages are special messages not easily accessable by the user.
419*
420* @param iotHubMessageHandle Handle to the message.
421*
422* @return Returns IOTHUB_MESSAGE_OK if the Security Message was set successfully
423* or an error code otherwise.
424*/
425MOCKABLE_FUNCTION(, IOTHUB_MESSAGE_RESULT, IoTHubMessage_SetAsSecurityMessage, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
426
427/**
428* @brief returns if this message is a IoTHub security message or not
429*
430* @param iotHubMessageHandle Handle to the message.
431*
432* @return Returns true if the Message is a security message false otherwise.
433*/
434MOCKABLE_FUNCTION(, bool, IoTHubMessage_IsSecurityMessage, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
435
436/**
437* @brief Frees all resources associated with the given message handle.
438*
439* @param iotHubMessageHandle Handle to the message.
440*/
441MOCKABLE_FUNCTION(, void, IoTHubMessage_Destroy, IOTHUB_MESSAGE_HANDLE, iotHubMessageHandle);
442
443#ifdef __cplusplus
444}
445#endif
446
447#endif /* IOTHUB_MESSAGE_H */
Note: See TracBrowser for help on using the repository browser.