void Impl::ParseResponse( Response * response )
{
    // This function uses return defines for readability and maintainability.
#   define return_error(error_type, error_message)                             \
    {                                                                          \
        SetError(response, error_type, error_message);                         \
        return;                                                                \
    }
    response->fileerror = 0;

    // create_content_parse_single required
    if ( ! GetIfExists(
            response->pt,
            "response.doupload.result",
            &response->result ) )
        return_error(
            mf::api::api_code::ContentInvalidData,
            "missing \"response.doupload.result\"");

    // create_content_parse_single optional with default
    GetIfExists(
            response->pt,
            "response.doupload.fileerror",
            &response->fileerror);

    // create_content_parse_single optional no default
    {
        boost::posix_time::ptime optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.created",
                &optarg) )
        {
            response->created = optarg;
        }
    }

    // create_content_parse_single optional no default
    {
        std::string optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.description",
                &optarg) )
        {
            response->description = optarg;
        }
    }

    // create_content_parse_single optional no default
    {
        std::string optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.filename",
                &optarg) )
        {
            response->filename = optarg;
        }
    }

    // create_content_parse_single optional no default
    {
        std::string optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.hash",
                &optarg) )
        {
            response->hash = optarg;
        }
    }

    // create_content_parse_single optional no default
    {
        std::string optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.quickkey",
                &optarg) )
        {
            response->quickkey = optarg;
        }
    }

    // create_content_struct_parse TSingle
    try {
        const boost::property_tree::wptree & branch =
            response->pt.get_child(L"response.doupload.resumable_upload");

        Response::ResumableData optarg;
        if ( ResumableDataFromPropertyBranch(
                response, &optarg, branch) )
        {
            response->resumable = std::move(optarg);
        }
    }
    catch(boost::property_tree::ptree_bad_path & err)
    {
        // Is optional
    }

    // create_content_parse_single optional no default
    {
        uint32_t optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.revision",
                &optarg) )
        {
            response->revision = optarg;
        }
    }

    // create_content_parse_single optional no default
    {
        uint64_t optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.size",
                &optarg) )
        {
            response->filesize = optarg;
        }
    }

    // create_content_parse_single optional no default
    {
        int32_t optarg;
        if ( GetIfExists(
                response->pt,
                "response.doupload.status",
                &optarg) )
        {
            response->status = optarg;
        }
    }

#   undef return_error
}
Beispiel #2
0
void Impl::ParseResponse( Response * response )
{
    // This function uses return defines for readability and maintainability.
#   define return_error(error_type, error_message)                             \
    {                                                                          \
        SetError(response, error_type, error_message);                         \
        return;                                                                \
    }

    ResponseData response_data;

    // For uniformity for code generation with the other content parsers.
    ResponseData * response_data_ptr = &response_data;
    response_data_ptr->hash_exists = HashAlreadyInSystem::No;
    response_data_ptr->hash_in_account = HashAlreadyInAccount::HashNewToAccount;
    response_data_ptr->hash_in_folder = HashAlreadyInFolder::HashNewToFolder;
    response_data_ptr->file_exists = FilenameInFolder::No;
    response_data_ptr->hash_different = FileExistsWithDifferentHash::No;
    response_data_ptr->available_space = 0;
    response_data_ptr->used_storage_size = 0;
    response_data_ptr->storage_limit = 0;
    response_data_ptr->storage_limit_exceeded = StorageLimitExceeded::No;

    {
        std::string optval;
        // create_content_enum_parse TSingle
        if ( GetIfExists(
                response->pt,
                "response.hash_exists",
                &optval) )
        {
            if ( optval == "no" )
                response_data_ptr->hash_exists = HashAlreadyInSystem::No;
            else if ( optval == "yes" )
                response_data_ptr->hash_exists = HashAlreadyInSystem::Yes;
        }
    }

    {
        std::string optval;
        // create_content_enum_parse TSingle
        if ( GetIfExists(
                response->pt,
                "response.in_account",
                &optval) )
        {
            if ( optval == "no" )
                response_data_ptr->hash_in_account = HashAlreadyInAccount::HashNewToAccount;
            else if ( optval == "yes" )
                response_data_ptr->hash_in_account = HashAlreadyInAccount::HashExistsInAccount;
        }
    }

    {
        std::string optval;
        // create_content_enum_parse TSingle
        if ( GetIfExists(
                response->pt,
                "response.in_folder",
                &optval) )
        {
            if ( optval == "no" )
                response_data_ptr->hash_in_folder = HashAlreadyInFolder::HashNewToFolder;
            else if ( optval == "yes" )
                response_data_ptr->hash_in_folder = HashAlreadyInFolder::HashExistsInFolder;
        }
    }

    {
        std::string optval;
        // create_content_enum_parse TSingle
        if ( GetIfExists(
                response->pt,
                "response.file_exists",
                &optval) )
        {
            if ( optval == "no" )
                response_data_ptr->file_exists = FilenameInFolder::No;
            else if ( optval == "yes" )
                response_data_ptr->file_exists = FilenameInFolder::Yes;
        }
    }

    {
        std::string optval;
        // create_content_enum_parse TSingle
        if ( GetIfExists(
                response->pt,
                "response.different_hash",
                &optval) )
        {
            if ( optval == "no" )
                response_data_ptr->hash_different = FileExistsWithDifferentHash::No;
            else if ( optval == "yes" )
                response_data_ptr->hash_different = FileExistsWithDifferentHash::Yes;
        }
    }

    // create_content_parse_single optional no default
    {
        std::string optarg;
        if ( GetIfExists(
                response->pt,
                "response.duplicate_quickkey",
                &optarg) )
        {
            response_data_ptr->duplicate_quickkey = optarg;
        }
    }

    // create_content_parse_single optional with default
    GetIfExists(
            response->pt,
            "response.available_space",
            &response_data_ptr->available_space);

    // create_content_parse_single optional with default
    GetIfExists(
            response->pt,
            "response.used_storage_size",
            &response_data_ptr->used_storage_size);

    // create_content_parse_single optional with default
    GetIfExists(
            response->pt,
            "response.storage_limit",
            &response_data_ptr->storage_limit);

    {
        std::string optval;
        // create_content_enum_parse TSingle
        if ( GetIfExists(
                response->pt,
                "response.storage_limit_exceeded",
                &optval) )
        {
            if ( optval == "no" )
                response_data_ptr->storage_limit_exceeded = StorageLimitExceeded::No;
            else if ( optval == "yes" )
                response_data_ptr->storage_limit_exceeded = StorageLimitExceeded::Yes;
        }
    }

    // create_content_struct_parse TSingle
    try {
        const boost::property_tree::wptree & branch =
            response->pt.get_child(L"response.resumable_upload");

        ResponseData::ResumableData optarg;
        if ( ResumableDataFromPropertyBranch(
                response, &optarg, branch) )
        {
            response_data_ptr->resumable = std::move(optarg);
        }
    }
    catch(boost::property_tree::ptree_bad_path & err)
    {
        // Is optional
    }

    // Only on success, return parsed data structure with response
    response->response_data = std::move(response_data);

#   undef return_error
}