- Timestamp:
- Jun 22, 2021, 9:00:19 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
azure_iot_hub_f767zi/trunk/azure_iot_sdk/iothub_client/src/iothub_message.c
r457 r464 34 34 IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticData; 35 35 bool is_security_message; 36 char* creationTimeUtc; 37 char* userId; 36 38 }IOTHUB_MESSAGE_HANDLE_DATA; 37 39 38 static bool Contains OnlyUsAscii(const char* asciiValue)40 static bool ContainsValidUsAscii(const char* asciiValue) 39 41 { 40 42 bool result = true; … … 42 44 while (iterator != NULL && *iterator != '\0') 43 45 { 44 // Allow only printable ascii char46 // Union of all allowed ASCII characters for the different protocols (HTTPS, MQTT, AMQP) is [dec 32, dec 126]. 45 47 if (*iterator < ' ' || *iterator > '~') 46 48 { … … 50 52 iterator++; 51 53 } 52 return result; 53 } 54 55 /* Codes_SRS_IOTHUBMESSAGE_07_008: [ValidateAsciiCharactersFilter shall loop through the mapKey and mapValue strings to ensure that they only contain valid US-Ascii characters Ascii value 32 - 126.] */ 54 55 return result; 56 } 57 58 /* Codes_SRS_IOTHUBMESSAGE_07_008: [ValidateAsciiCharactersFilter shall loop through the mapKey and mapValue strings to ensure that they only contain valid US-Ascii characters.*/ 56 59 static int ValidateAsciiCharactersFilter(const char* mapKey, const char* mapValue) 57 60 { 58 61 int result; 59 if (!Contains OnlyUsAscii(mapKey) || !ContainsOnlyUsAscii(mapValue))62 if (!ContainsValidUsAscii(mapKey) || !ContainsValidUsAscii(mapValue)) 60 63 { 61 64 result = MU_FAILURE; … … 101 104 free(handleData->connectionModuleId); 102 105 free(handleData->connectionDeviceId); 106 free(handleData->creationTimeUtc); 107 free(handleData->userId); 103 108 free(handleData); 104 109 } … … 123 128 } 124 129 handleData->contentEncoding = tmp_encoding; 130 result = 0; 131 } 132 return result; 133 } 134 135 static int set_message_creation_time(IOTHUB_MESSAGE_HANDLE_DATA* handleData, const char* messageCreationTimeUtc) 136 { 137 int result; 138 char* tmp_message_creation_time; 139 140 if (handleData->creationTimeUtc != NULL) 141 { 142 free(handleData->creationTimeUtc); 143 handleData->creationTimeUtc = NULL; 144 } 145 146 if (mallocAndStrcpy_s(&tmp_message_creation_time, messageCreationTimeUtc) != 0) 147 { 148 LogError("Failed saving a copy of messageCreationTimeUtc"); 149 result = MU_FAILURE; 150 } 151 else 152 { 153 handleData->creationTimeUtc = tmp_message_creation_time; 154 result = 0; 155 } 156 return result; 157 } 158 159 static int set_message_user_id(IOTHUB_MESSAGE_HANDLE_DATA* handleData, const char* userId) 160 { 161 int result; 162 char* tmp_message_user_id; 163 164 if (handleData->userId != NULL) 165 { 166 free(handleData->userId); 167 handleData->userId = NULL; 168 } 169 170 if (mallocAndStrcpy_s(&tmp_message_user_id, userId) != 0) 171 { 172 LogError("Failed saving a copy of userId"); 173 result = MU_FAILURE; 174 } 175 else 176 { 177 handleData->userId = tmp_message_user_id; 125 178 result = 0; 126 179 } … … 349 402 result = NULL; 350 403 } 404 else if (source->creationTimeUtc != NULL && mallocAndStrcpy_s(&result->creationTimeUtc, source->creationTimeUtc) != 0) 405 { 406 LogError("unable to copy creationTimeUtc"); 407 DestroyMessageData(result); 408 result = NULL; 409 } 410 else if (source->userId != NULL && mallocAndStrcpy_s(&result->userId, source->userId) != 0) 411 { 412 LogError("unable to copy userId"); 413 DestroyMessageData(result); 414 result = NULL; 415 } 351 416 else if (source->connectionModuleId != NULL && mallocAndStrcpy_s(&result->connectionModuleId, source->connectionModuleId) != 0) 352 417 { … … 509 574 else 510 575 { 511 if (Map_AddOrUpdate(msg_handle->properties, key, value) != MAP_OK) 576 MAP_RESULT map_result = Map_AddOrUpdate(msg_handle->properties, key, value); 577 if (map_result == MAP_FILTER_REJECT) 578 { 579 LogError("Failure validating property as ASCII"); 580 result = IOTHUB_MESSAGE_INVALID_TYPE; 581 } 582 else if (map_result != MAP_OK) 512 583 { 513 584 LogError("Failure adding property to internal map"); … … 748 819 // Codes_SRS_IOTHUBMESSAGE_09_011: [IoTHubMessage_GetContentEncodingSystemProperty shall return the `contentEncoding` as a const char* ] 749 820 result = (const char*)handleData->contentEncoding; 821 } 822 823 return result; 824 } 825 826 IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageCreationTimeUtcSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* creationTimeUtc) 827 { 828 IOTHUB_MESSAGE_RESULT result; 829 830 if (iotHubMessageHandle == NULL || creationTimeUtc == NULL) 831 { 832 LogError("Invalid argument (iotHubMessageHandle=%p, creationTimeUtc=%p)", iotHubMessageHandle, creationTimeUtc); 833 result = IOTHUB_MESSAGE_INVALID_ARG; 834 } 835 else 836 { 837 if (set_message_creation_time(iotHubMessageHandle, creationTimeUtc) != 0) 838 { 839 LogError("Failed saving a copy of creationTimeUtc"); 840 result = IOTHUB_MESSAGE_ERROR; 841 } 842 else 843 { 844 result = IOTHUB_MESSAGE_OK; 845 } 846 } 847 return result; 848 } 849 850 const char* IoTHubMessage_GetMessageCreationTimeUtcSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) 851 { 852 const char* result; 853 854 if (iotHubMessageHandle == NULL) 855 { 856 LogError("Invalid argument (iotHubMessageHandle is NULL)"); 857 result = NULL; 858 } 859 else 860 { 861 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; 862 result = (const char*)handleData->creationTimeUtc; 863 } 864 865 return result; 866 } 867 868 IOTHUB_MESSAGE_RESULT IoTHubMessage_SetMessageUserIdSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle, const char* userId) 869 { 870 IOTHUB_MESSAGE_RESULT result; 871 872 if (iotHubMessageHandle == NULL || userId == NULL) 873 { 874 LogError("Invalid argument (iotHubMessageHandle=%p, userId=%p)", iotHubMessageHandle, userId); 875 result = IOTHUB_MESSAGE_INVALID_ARG; 876 } 877 else 878 { 879 if (set_message_user_id(iotHubMessageHandle, userId) != 0) 880 { 881 LogError("Failed saving a copy of userId"); 882 result = IOTHUB_MESSAGE_ERROR; 883 } 884 else 885 { 886 result = IOTHUB_MESSAGE_OK; 887 } 888 } 889 return result; 890 } 891 892 const char* IoTHubMessage_GetMessageUserIdSystemProperty(IOTHUB_MESSAGE_HANDLE iotHubMessageHandle) 893 { 894 const char* result; 895 896 if (iotHubMessageHandle == NULL) 897 { 898 LogError("Invalid argument (iotHubMessageHandle is NULL)"); 899 result = NULL; 900 } 901 else 902 { 903 IOTHUB_MESSAGE_HANDLE_DATA* handleData = iotHubMessageHandle; 904 result = (const char*)handleData->userId; 750 905 } 751 906
Note:
See TracChangeset
for help on using the changeset viewer.