int mqttmessage_getTopicLevels()

in src/mqtt_message.c [217:261]


int mqttmessage_getTopicLevels(MQTT_MESSAGE_HANDLE handle, char*** levels, size_t* count)
{
    int result;

    // Codes_SRS_MQTTMESSAGE_09_001: [ If `handle`, `levels` or `count` are NULL the function shall return a non-zero value. ]
    if (handle == NULL || levels == NULL || count == NULL)
    {
        LogError("Invalid Parameter handle: %p, levels: %p, count: %p", handle, levels, count);
        result = MU_FAILURE;
    }
    else
    {
        MQTT_MESSAGE* msgInfo = (MQTT_MESSAGE*)handle;

        const char* topic_name = msgInfo->topicName != NULL ? msgInfo->topicName : msgInfo->const_topic_name;

        if (topic_name == NULL)
        {
            LogError("Topic name is NULL");
            result = MU_FAILURE;
        }
        else
        {
            const char* delimiters[1];

            delimiters[0] = "/";

            // Codes_SRS_MQTTMESSAGE_09_002: [ The topic name, excluding the property bag, shall be split into individual tokens using "/" as separator ]
            // Codes_SRS_MQTTMESSAGE_09_004: [ The split tokens shall be stored in `levels` and its count in `count` ]
            if (StringToken_Split(topic_name, strlen(topic_name), delimiters, 1, false, levels, count) != 0)
            {
                // Codes_SRS_MQTTMESSAGE_09_003: [ If splitting fails the function shall return a non-zero value. ]
                LogError("Failed splitting topic levels");
                result = MU_FAILURE;
            }
            else
            {
                // Codes_SRS_MQTTMESSAGE_09_005: [ If no failures occur the function shall return zero. ]
                result = 0;
            }
        }
    }

    return result;
}