int configuration_reader_get_thandle_rc_string()

in src/configuration_reader.c [487:555]


int configuration_reader_get_thandle_rc_string(IFabricCodePackageActivationContext* activation_context, const wchar_t* config_package_name, const wchar_t* section_name, const wchar_t* parameter_name, THANDLE(RC_STRING)* value)
{
    int result;

    if (
        /*Codes_SRS_CONFIGURATION_READER_42_043: [ If activation_context is NULL then configuration_reader_get_thandle_rc_string shall fail and return a non-zero value. ]*/
        activation_context == NULL ||
        /*Codes_SRS_CONFIGURATION_READER_42_044: [ If config_package_name is NULL or empty then configuration_reader_get_thandle_rc_string shall fail and return a non-zero value. ]*/
        (config_package_name == NULL || config_package_name[0] == L'\0') ||
        /*Codes_SRS_CONFIGURATION_READER_42_045: [ If section_name is NULL or empty then configuration_reader_get_thandle_rc_string shall fail and return a non-zero value. ]*/
        (section_name == NULL || section_name[0] == L'\0') ||
        /*Codes_SRS_CONFIGURATION_READER_42_046: [ If parameter_name is NULL or empty then configuration_reader_get_thandle_rc_string shall fail and return a non-zero value. ]*/
        (parameter_name == NULL || parameter_name[0] == L'\0') ||
        /*Codes_SRS_CONFIGURATION_READER_42_047: [ If value is NULL then configuration_reader_get_thandle_rc_string shall fail and return a non-zero value. ]*/
        (value == NULL)
        )
    {
        LogError("Invalid args: IFabricCodePackageActivationContext* activation_context = %p, const wchar_t* config_package_name = %ls, const wchar_t* section_name = %ls, const wchar_t* parameter_name = %ls, THANDLE(RC_STRING)* value = %p",
            activation_context, MU_WP_OR_NULL(config_package_name), MU_WP_OR_NULL(section_name), MU_WP_OR_NULL(parameter_name), value);
        result = MU_FAILURE;
    }
    else
    {
        IFabricConfigurationPackage* fabric_configuration_package;
        const wchar_t* wchar_value;
        if (get_string_value_from_package(activation_context, config_package_name, section_name, parameter_name, &fabric_configuration_package, &wchar_value) != 0)
        {
            // already logged error
            result = MU_FAILURE;
        }
        else
        {
            /*Codes_SRS_CONFIGURATION_READER_42_050: [ configuration_reader_get_thandle_rc_string shall convert the value from a wide-character string to narrow-character string. ]*/
            char* temp = sprintf_char("%ls", wchar_value);

            if (temp == NULL)
            {
                /*Codes_SRS_CONFIGURATION_READER_42_052: [ If there are any other failures then configuration_reader_get_thandle_rc_string shall fail and return a non-zero value. ]*/
                LogError("Failed to copy string %ls (config_package_name:%ls, section_name:%ls, parameter_name:%ls)",
                    wchar_value, config_package_name, section_name, parameter_name);
                result = MU_FAILURE;
            }
            else
            {
                /*Codes_SRS_CONFIGURATION_READER_42_051: [ configuration_reader_get_thandle_rc_string shall store the converted string in a THANDLE(RC_STRING). ]*/
                THANDLE(RC_STRING) temp_rc = rc_string_create_with_move_memory(temp);

                if (temp_rc == NULL)
                {
                    /*Codes_SRS_CONFIGURATION_READER_42_052: [ If there are any other failures then configuration_reader_get_thandle_rc_string shall fail and return a non-zero value. ]*/
                    LogError("Failed to wrap string %s in RC_STRING (config_package_name:%ls, section_name:%ls, parameter_name:%ls)",
                        temp, config_package_name, section_name, parameter_name);
                    result = MU_FAILURE;
                    free(temp);
                }
                else
                {
                    THANDLE_INITIALIZE_MOVE(RC_STRING)(value, &temp_rc);

                    /*Codes_SRS_CONFIGURATION_READER_42_053: [ configuration_reader_get_thandle_rc_string shall succeed and return 0. ]*/
                    result = 0;
                }
            }
            (void)fabric_configuration_package->lpVtbl->Release(fabric_configuration_package);
        }
    }

    return result;
}