Ignore:
Timestamp:
Jun 22, 2021, 9:00:19 PM (3 years ago)
Author:
coas-nagasima
Message:

WolfSSLとAzure IoT SDKを更新

File:
1 edited

Legend:

Unmodified
Added
Removed
  • azure_iot_hub_f767zi/trunk/azure_iot_sdk/iothub_client/src/iothub_message.c

    r457 r464  
    3434    IOTHUB_MESSAGE_DIAGNOSTIC_PROPERTY_DATA_HANDLE diagnosticData;
    3535    bool is_security_message;
     36    char* creationTimeUtc;
     37    char* userId;
    3638}IOTHUB_MESSAGE_HANDLE_DATA;
    3739
    38 static bool ContainsOnlyUsAscii(const char* asciiValue)
     40static bool ContainsValidUsAscii(const char* asciiValue)
    3941{
    4042    bool result = true;
     
    4244    while (iterator != NULL && *iterator != '\0')
    4345    {
    44         // Allow only printable ascii char
     46        // Union of all allowed ASCII characters for the different protocols (HTTPS, MQTT, AMQP) is [dec 32, dec 126].
    4547        if (*iterator < ' ' || *iterator > '~')
    4648        {
     
    5052        iterator++;
    5153    }
    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.*/
    5659static int ValidateAsciiCharactersFilter(const char* mapKey, const char* mapValue)
    5760{
    5861    int result;
    59     if (!ContainsOnlyUsAscii(mapKey) || !ContainsOnlyUsAscii(mapValue))
     62    if (!ContainsValidUsAscii(mapKey) || !ContainsValidUsAscii(mapValue))
    6063    {
    6164        result = MU_FAILURE;
     
    101104    free(handleData->connectionModuleId);
    102105    free(handleData->connectionDeviceId);
     106    free(handleData->creationTimeUtc);
     107    free(handleData->userId);
    103108    free(handleData);
    104109}
     
    123128        }
    124129        handleData->contentEncoding = tmp_encoding;
     130        result = 0;
     131    }
     132    return result;
     133}
     134
     135static 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
     159static 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;
    125178        result = 0;
    126179    }
     
    349402                result = NULL;
    350403            }
     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            }
    351416            else if (source->connectionModuleId != NULL && mallocAndStrcpy_s(&result->connectionModuleId, source->connectionModuleId) != 0)
    352417            {
     
    509574    else
    510575    {
    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)
    512583        {
    513584            LogError("Failure adding property to internal map");
     
    748819        // Codes_SRS_IOTHUBMESSAGE_09_011: [IoTHubMessage_GetContentEncodingSystemProperty shall return the `contentEncoding` as a const char* ]
    749820        result = (const char*)handleData->contentEncoding;
     821    }
     822
     823    return result;
     824}
     825
     826IOTHUB_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
     850const 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
     868IOTHUB_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
     892const 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;
    750905    }
    751906
Note: See TracChangeset for help on using the changeset viewer.