void v1_3::Request::HandleContent(const std::string & url, const mf::http::Headers & headers, const std::string & content) { assert(callback_); if (!callback_) return; ResponseType response; response.InitializeWithContent(url, "", headers, content); // These could possibly be available when an error occurs or on success. GetIfExists(response.pt, "response.pkey", &response.pkey); GetIfExists(response.pt, "response.secret_key", &response.secret_key); GetIfExists(response.pt, "response.time", &response.time); if (!response.error_code) { if (!GetIfExists(response.pt, "response.session_token", &response.session_token)) { response.error_code = make_error_code(mf::api::api_code::ContentInvalidData); response.error_string = "missing session token"; } if (!GetIfExists(response.pt, "response.ekey", &response.ekey)) { response.error_code = make_error_code(mf::api::api_code::ContentInvalidData); response.error_string = "missing \"response.ekey\""; } } callback_(response); }
void v0::Request::HandleContent( const std::string & url, const mf::http::Headers & headers, const std::string & content) { assert( callback_ ); if ( ! callback_ ) return; ResponseType response; response.InitializeWithContent(url, "", headers, content); # ifdef OUTPUT_DEBUG // Debug code std::cout << "Got content:\n" << content << std::endl; std::wostringstream ss; boost::property_tree::write_json( ss, response.pt ); std::cout << "Got JSON:\n" << mf::utils::wide_to_bytes(ss.str()) << std::endl; # endif if ( ! response.error_code ) { GetIfExists( response.pt, "response.pkey", &response.pkey ); if ( ! GetIfExists( response.pt, "response.login_token", &response.login_token ) ) { response.error_code = make_error_code( mf::api::api_code::ContentInvalidData ); response.error_string = "missing session token"; } } callback_(response); }
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; \ } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.patch_link", &response->patch_link ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.patch_link\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.patch_hash", &response->patch_hash ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.patch_hash\""); # undef return_error }
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; { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.async_jobs_in_progress", &optval) ) { if ( optval == "no" ) response_data_ptr->async_jobs_in_progress = AsyncJobs::Stopped; else if ( optval == "yes" ) response_data_ptr->async_jobs_in_progress = AsyncJobs::Running; else return_error( mf::api::api_code::ContentInvalidData, "invalid value in response.async_jobs_in_progress"); } else return_error( mf::api::api_code::ContentInvalidData, "no value in response.async_jobs_in_progress"); } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.device_revision", &response_data_ptr->device_revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.device_revision\""); // Only on success, return parsed data structure with response response->response_data = std::move(response_data); # undef return_error }
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->one_time_download_request_count = 0; response->direct_download_free_bandwidth = 0; // create_content_struct_parse TArray try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.links"); response->links.reserve( response->pt.size() ); for ( auto & it : branch ) { Response::Links optarg; if ( LinksFromPropertyBranch( response, &optarg, it.second) ) response->links.push_back(std::move(optarg)); else return; // error set already } } catch(boost::property_tree::ptree_bad_path & err) { // JSON response still has element if no files were returned. // This is really an error. return_error( mf::api::api_code::ContentInvalidData, "missing \"response.links\""); } // create_content_parse_single optional with default GetIfExists( response->pt, "response.one_time_download_request_count", &response->one_time_download_request_count); // create_content_parse_single optional with default GetIfExists( response->pt, "response.direct_download_free_bandwidth", &response->direct_download_free_bandwidth); # undef return_error }
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; // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.current_api_version", &response_data_ptr->current_api_version ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.current_api_version\""); // Only on success, return parsed data structure with response response->response_data = std::move(response_data); # undef return_error }
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; \ } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.device_revision", &response->device_revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.device_revision\""); // create_content_parse_array_front required if ( ! GetIfExistsArrayFront( response->pt, "response.new_quickkeys", &response->quickkey ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.new_quickkeys\""); # undef return_error }
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->asynchronous = Asynchronous::Synchronous; { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.asynchronous", &optval) ) { if ( optval == "no" ) response_data_ptr->asynchronous = Asynchronous::Synchronous; else if ( optval == "yes" ) response_data_ptr->asynchronous = Asynchronous::Asynchronous; } } // Only on success, return parsed data structure with response response->response_data = std::move(response_data); # undef return_error }
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->asynchronous = Asynchronous::Synchronous; { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.asynchronous", &optval) ) { if ( optval == "no" ) response->asynchronous = Asynchronous::Synchronous; else if ( optval == "yes" ) response->asynchronous = Asynchronous::Asynchronous; } } // create_content_parse_single optional no default { uint32_t optarg; if ( GetIfExists( response->pt, "response.device_revision", &optarg) ) { response->device_revision = optarg; } } # undef return_error }
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; \ } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.current_revision", &response->current_revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.current_revision\""); // create_content_struct_parse TArray try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.updates"); response->updates.reserve( response->pt.size() ); for ( auto & it : branch ) { Response::Update optarg; if ( UpdateFromPropertyBranch( response, &optarg, it.second) ) response->updates.push_back(std::move(optarg)); } } catch(boost::property_tree::ptree_bad_path & err) { // Is optional } # undef return_error }
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; \ } // create_content_parse_single optional no default { uint32_t optarg; if ( GetIfExists( response->pt, "response.new_device_revision", &optarg) ) { response->new_device_revision = optarg; } } # undef return_error }
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 }
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; \ } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.folder_key", &response->folderkey ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.folder_key\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.upload_key", &response->uploadkey ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.upload_key\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.name", &response->name ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.name\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.created", &response->created_datetime ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.created\""); { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.privacy", &optval) ) { if ( optval == "public" ) response->privacy = Privacy::Public; else if ( optval == "private" ) response->privacy = Privacy::Private; else return_error( mf::api::api_code::ContentInvalidData, "invalid value in response.privacy"); } else return_error( mf::api::api_code::ContentInvalidData, "no value in response.privacy"); } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.revision", &response->revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.revision\""); # undef return_error }
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->description = ""; response_data_ptr->mimetype = ""; // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.created", &response_data_ptr->created_datetime ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.created\""); // create_content_parse_single optional with default GetIfExists( response->pt, "response.fileinfo.description", &response_data_ptr->description); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.device_revision", &response_data_ptr->device_revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.device_revision\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.downloads", &response_data_ptr->downloads ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.downloads\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.hash", &response_data_ptr->filehash ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.hash\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.filename", &response_data_ptr->filename ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.filename\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.size", &response_data_ptr->filesize ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.size\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.filetype", &response_data_ptr->filetype ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.filetype\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.revision", &response_data_ptr->file_revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.revision\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.flag", &response_data_ptr->flag ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.flag\""); // create_content_struct_parse TSingle try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.fileinfo.links"); ResponseData::Links optarg; if ( LinksFromPropertyBranch( response, &optarg, branch) ) { response_data_ptr->links = std::move(optarg); } else { // JSON response still has element if expected. // This is really an error. return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.links\""); } } catch(boost::property_tree::ptree_bad_path & err) { // JSON response still has element if no files were returned. // This is really an error. return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.links\""); } // create_content_parse_single optional with default GetIfExists( response->pt, "response.fileinfo.mimetype", &response_data_ptr->mimetype); { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.fileinfo.password_protected", &optval) ) { if ( optval == "no" ) response_data_ptr->password_protected = PasswordProtected::Unprotected; else if ( optval == "yes" ) response_data_ptr->password_protected = PasswordProtected::Protected; else return_error( mf::api::api_code::ContentInvalidData, "invalid value in response.fileinfo.password_protected"); } else return_error( mf::api::api_code::ContentInvalidData, "no value in response.fileinfo.password_protected"); } { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.fileinfo.privacy", &optval) ) { if ( optval == "public" ) response_data_ptr->privacy = Privacy::Public; else if ( optval == "private" ) response_data_ptr->privacy = Privacy::Private; else return_error( mf::api::api_code::ContentInvalidData, "invalid value in response.fileinfo.privacy"); } else return_error( mf::api::api_code::ContentInvalidData, "no value in response.fileinfo.privacy"); } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.fileinfo.quickkey", &response_data_ptr->quickkey ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.fileinfo.quickkey\""); // Only on success, return parsed data structure with response response->response_data = std::move(response_data); # undef return_error }
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->deleted_datetime = boost::posix_time::not_a_date_time; response->mimetype = ""; response->shared_by_user = SharedByUser::Unshared; // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.quickkey", &response->quickkey ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.quickkey\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.filename", &response->filename ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.filename\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.created", &response->created_datetime ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.created\""); // create_content_parse_single optional with default GetIfExists( response->pt, "response.file_info.delete_date", &response->deleted_datetime); // create_content_parse_single optional no default { uint32_t optarg; if ( GetIfExists( response->pt, "response.file_info.downloads", &optarg) ) { response->download_count = optarg; } } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.size", &response->filesize ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.size\""); { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.file_info.privacy", &optval) ) { if ( optval == "public" ) response->privacy = Privacy::Public; else if ( optval == "private" ) response->privacy = Privacy::Private; else return_error( mf::api::api_code::ContentInvalidData, "invalid value in response.file_info.privacy"); } else return_error( mf::api::api_code::ContentInvalidData, "no value in response.file_info.privacy"); } { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.file_info.password_protected", &optval) ) { if ( optval == "no" ) response->password_protected = PasswordProtected::Unprotected; else if ( optval == "yes" ) response->password_protected = PasswordProtected::Protected; else return_error( mf::api::api_code::ContentInvalidData, "invalid value in response.file_info.password_protected"); } else return_error( mf::api::api_code::ContentInvalidData, "no value in response.file_info.password_protected"); } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.hash", &response->hash ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.hash\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.filetype", &response->filetype ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.filetype\""); // create_content_parse_single optional with default GetIfExists( response->pt, "response.file_info.mimetype", &response->mimetype); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.owner_name", &response->owner_name ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.owner_name\""); { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.file_info.shared_by_user", &optval) ) { if ( optval == "" ) response->shared_by_user = SharedByUser::Unshared; else if ( optval == "1" ) response->shared_by_user = SharedByUser::Shared; } } // create_content_struct_parse TSingle try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.file_info.permissions"); Response::Permissions optarg; if ( PermissionsFromPropertyBranch( response, &optarg, branch) ) { response->permissions = std::move(optarg); } } catch(boost::property_tree::ptree_bad_path & err) { // Is optional } // create_content_parse_single optional no default { std::string optarg; if ( GetIfExists( response->pt, "response.file_info.parent_folderkey", &optarg) ) { response->parent_folderkey = optarg; } } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.revision", &response->revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.revision\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.file_info.flag", &response->flag ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.file_info.flag\""); # undef return_error }
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->created_datetime = boost::posix_time::not_a_date_time; response->previous_invoice_datetime = boost::posix_time::not_a_date_time; // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.invoice", &response->invoice ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.invoice\""); // create_content_parse_single optional with default GetIfExists( response->pt, "created", &response->created_datetime); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.total", &response->total ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.total\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.product", &response->product_id ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.product\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.premium", &response->premium ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.premium\""); // create_content_parse_single optional with default GetIfExists( response->pt, "lastpremium", &response->previous_invoice_datetime); # undef return_error }
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; // create_content_parse_single optional no default { std::string optarg; if ( GetIfExists( response->pt, "response.folderkey", &optarg) ) { response_data_ptr->folderkey = optarg; } } // create_content_parse_single optional no default { std::string optarg; if ( GetIfExists( response->pt, "response.folder_key", &optarg) ) { response_data_ptr->folder_key = optarg; } } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.upload_key", &response_data_ptr->uploadkey ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.upload_key\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.name", &response_data_ptr->name ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.name\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.created", &response_data_ptr->created_datetime ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.created\""); { std::string optval; // create_content_enum_parse TSingle if ( GetIfExists( response->pt, "response.privacy", &optval) ) { if ( optval == "public" ) response_data_ptr->privacy = Privacy::Public; else if ( optval == "private" ) response_data_ptr->privacy = Privacy::Private; else return_error( mf::api::api_code::ContentInvalidData, "invalid value in response.privacy"); } else return_error( mf::api::api_code::ContentInvalidData, "no value in response.privacy"); } // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.revision", &response_data_ptr->revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.revision\""); // Only on success, return parsed data structure with response response->response_data = std::move(response_data); # undef return_error }
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; // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.device_revision", &response_data_ptr->device_revision ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.device_revision\""); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.changes_list_block", &response_data_ptr->changes_list_block ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.changes_list_block\""); // create_content_struct_parse TArray try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.updated.files"); response_data_ptr->updated_files.reserve( response->pt.size() ); for ( auto & it : branch ) { ResponseData::File optarg; if ( FileFromPropertyBranch( response, &optarg, it.second) ) response_data_ptr->updated_files.push_back(std::move(optarg)); } } catch(boost::property_tree::ptree_bad_path & err) { // Is optional } // create_content_struct_parse TArray try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.deleted.files"); response_data_ptr->deleted_files.reserve( response->pt.size() ); for ( auto & it : branch ) { ResponseData::File optarg; if ( FileFromPropertyBranch( response, &optarg, it.second) ) response_data_ptr->deleted_files.push_back(std::move(optarg)); } } catch(boost::property_tree::ptree_bad_path & err) { // Is optional } // create_content_struct_parse TArray try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.updated.folders"); response_data_ptr->updated_folders.reserve( response->pt.size() ); for ( auto & it : branch ) { ResponseData::Folder optarg; if ( FolderFromPropertyBranch( response, &optarg, it.second) ) response_data_ptr->updated_folders.push_back(std::move(optarg)); } } catch(boost::property_tree::ptree_bad_path & err) { // Is optional } // create_content_struct_parse TArray try { const boost::property_tree::wptree & branch = response->pt.get_child(L"response.deleted.folders"); response_data_ptr->deleted_folders.reserve( response->pt.size() ); for ( auto & it : branch ) { ResponseData::Folder optarg; if ( FolderFromPropertyBranch( response, &optarg, it.second) ) response_data_ptr->deleted_folders.push_back(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 }
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 }
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->one_time_key_request_count = 0; response_data_ptr->one_time_key_request_max_count = 0; // create_content_parse_single optional with default GetIfExists( response->pt, "response.one_time_key_request_count", &response_data_ptr->one_time_key_request_count); // create_content_parse_single optional with default GetIfExists( response->pt, "response.one_time_key_request_max_count", &response_data_ptr->one_time_key_request_max_count); // create_content_parse_single required if ( ! GetIfExists( response->pt, "response.token", &response_data_ptr->token ) ) return_error( mf::api::api_code::ContentInvalidData, "missing \"response.token\""); // create_content_parse_single optional no default { std::string optarg; if ( GetIfExists( response->pt, "response.links.download", &optarg) ) { response_data_ptr->download_link = optarg; } } // create_content_parse_single optional no default { std::string optarg; if ( GetIfExists( response->pt, "response.links.view", &optarg) ) { response_data_ptr->view_link = optarg; } } // create_content_parse_single optional no default { std::string optarg; if ( GetIfExists( response->pt, "response.links.watch", &optarg) ) { response_data_ptr->watch_link = optarg; } } // create_content_parse_single optional no default { std::string optarg; if ( GetIfExists( response->pt, "response.links.listen", &optarg) ) { response_data_ptr->listen_link = optarg; } } // Only on success, return parsed data structure with response response->response_data = std::move(response_data); # undef return_error }