+++ /dev/null
-####################################################################
-# SOURCES #
-####################################################################
-
-ADD_DEFINITIONS(-DLOCALEDIR=\\\"${CMAKE_INSTALL_PREFIX}/share/locale\\\" -DTEXTDOMAIN=\\\"zypp\\\" )
-
-INCLUDE_DIRECTORIES(${CMAKE_CURRENT_BINARY_DIR})
-#FILE(WRITE filename "message to write"... )
-
-SET( zypp_SRCS
- Atom.cc
- ByteCount.cc
- Capabilities.cc
- Capability.cc
- CapMatch.cc
- Changelog.cc
- CheckSum.cc
- Date.cc
- Dep.cc
- Dependencies.cc
- Digest.cc
- DiskUsage.cc
- DiskUsageCounter.cc
- dummy.cc
- Edition.cc
- ExternalProgram.cc
- Fetcher.cc
- FileChecker.cc
- IdString.cc
- KeyRing.cc
- Locks.cc
- MediaProducts.cc
- MediaSetAccess.cc
- Message.cc
- NameKindProxy.cc
- NVRA.cc
- NVRAD.cc
- NVR.cc
- OnMediaLocation.cc
- Package.cc
- Patch.cc
- PathInfo.cc
- Pathname.cc
- Pattern.cc
- PoolItem.cc
- PoolQuery.cc
- PoolQueryResult.cc
- ProblemSolution.cc
- Product.cc
- ProgressData.cc
- ProvideFilePolicy.cc
- PublicKey.cc
- Range.cc
- Rel.cc
- RepoInfo.cc
- RepoManager.cc
- RepoStatus.cc
- ResKind.cc
- ResObject.cc
- Resolvable.cc
- Resolver.cc
- ResolverProblem.cc
- ResPool.cc
- ResPoolProxy.cc
- ResStatus.cc
- Script.cc
- Signature.cc
- SrcPackage.cc
- SysContent.cc
- Target.cc
- TmpPath.cc
- TranslatedText.cc
- UpgradeStatistics.cc
- Url.cc
- VendorAttr.cc
- ZYpp.cc
- ZYppCommitPolicy.cc
- ZYppCommitResult.cc
- ZYppFactory.cc
- Repository.cc
-)
-SET( zypp_EARLY_SRCS
- ZConfig.cc
- Arch.cc
- Locale.cc
- CountryCode.cc
- LanguageCode.cc
-)
-
-SET( zypp_HEADERS
- Arch.h
- Atom.h
- AutoDispose.h
- Bit.h
- ByteCount.h
- Callback.h
- Capabilities.h
- Capability.h
- CapMatch.h
- Changelog.h
- CheckSum.h
- CountryCode.h
- Date.h
- Dependencies.h
- Dep.h
- Digest.h
- DiskUsageCounter.h
- DiskUsage.h
- Edition.h
- ExternalProgram.h
- Fetcher.h
- FileChecker.h
- IdString.h
- IdStringType.h
- KeyRing.h
- KVMap.h
- LanguageCode.h
- Locale.h
- Locks.h
- ManagedFile.h
- MediaProducts.h
- MediaSetAccess.h
- Message.h
- NameKindProxy.h
- Vendor.h
- NVRAD.h
- NVRA.h
- NVR.h
- OnMediaLocation.h
- Package.h
- PackageKeyword.h
- Patch.h
- PathInfo.h
- Pathname.h
- Pattern.h
- PoolItem.h
- PoolQuery.h
- PoolQueryUtil.tcc
- PoolQueryResult.h
- ProblemSolution.h
- ProblemTypes.h
- Product.h
- ProgressData.h
- ProvideFilePolicy.h
- PublicKey.h
- Range.h
- RelCompare.h
- Rel.h
- RepoInfo.h
- RepoManager.h
- RepoStatus.h
- Filter.h
- ResFilters.h
- ResKind.h
- ResObject.h
- ResObjects.h
- Resolvable.h
- Resolver.h
- ResolverProblem.h
- ResPool.h
- ResPoolProxy.h
- ResStatus.h
- ResTraits.h
- Script.h
- Signature.h
- SrcPackage.h
- SysContent.h
- Target.h
- TmpPath.h
- TranslatedText.h
- TriBool.h
- UpgradeStatistics.h
- Url.h
- VendorAttr.h
- ZConfig.h
- ZYppCallbacks.h
- ZYppCommit.h
- ZYppCommitPolicy.h
- ZYppCommitResult.h
- ZYppFactory.h
- ZYpp.h
- Repository.h
-)
-
-INSTALL( FILES ${zypp_HEADERS} DESTINATION "${CMAKE_INSTALL_PREFIX}/include/zypp" )
-
-SET( zypp_base_SRCS
- base/InterProcessMutex.cc
- base/SerialNumber.cc
- base/Random.cc
- base/Measure.cc
- base/Fd.cc
- base/Gettext.cc
- base/GzStream.cc
- base/IOStream.cc
- base/InputStream.cc
- base/ReferenceCounted.cc
- base/String.cc
- base/Regex.cc
- base/Unit.cc
- base/ExternalDataSource.cc
- base/Exception.cc
- base/UserRequestException.cc
- base/Sysconfig.cc
- base/ProfilingFormater.cc
- base/LogControl.cc
-)
-
-SET( zypp_base_HEADERS
- base/InterProcessMutex.h
- base/Collector.h
- base/SerialNumber.h
- base/Easy.h
- base/Random.h
- base/Algorithm.h
- base/Counter.h
- base/Debug.h
- base/DefaultFalseBool.h
- base/DefaultIntegral.h
- base/Deprecated.h
- base/DtorReset.h
- base/Exception.h
- base/UserRequestException.h
- base/ExternalDataSource.h
- base/Fd.h
- base/Function.h
- base/Functional.h
- base/Gettext.h
- base/GzStream.h
- base/IOStream.h
- base/InputStream.h
- base/Iterator.h
- base/KindOf.h
- base/LogControl.h
- base/LogTools.h
- base/Logger.h
- base/Measure.h
- base/NonCopyable.h
- base/ProfilingFormater.h
- base/ProvideNumericId.h
- base/PtrTypes.h
- base/ReferenceCounted.h
- base/SafeBool.h
- base/String.h
- base/Regex.h
- base/Sysconfig.h
- base/Tr1hash.h
- base/Unit.h
- base/WatchFile.h
-)
-
-INSTALL( FILES
- ${zypp_base_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/base
-)
-
-SET( zypp_data_SRCS
- data/ResolvableData.cc
- data/RecordId.cc
- data/ResolvableDataConsumer.cc
-)
-
-SET( zypp_data_HEADERS
- data/ResolvableData.h
- data/RecordId.h
- data/ResolvableDataConsumer.h
-)
-
-INSTALL( FILES
- ${zypp_data_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/data
-)
-
-SET( zypp_media_SRCS
- media/MediaException.cc
- media/MediaAccess.cc
- media/MediaHandler.cc
- media/Mount.cc
- media/MediaNFS.cc
- media/MediaCD.cc
- media/MediaDIR.cc
- media/MediaDISK.cc
- media/MediaSMB.cc
- media/MediaCIFS.cc
- media/ProxyInfo.cc
- media/MediaCurl.cc
- media/MediaMetalink.cc
- media/MediaAria2c.cc
- media/MediaISO.cc
- media/MediaManager.cc
- media/MediaUserAuth.cc
- media/CurlConfig.cc
-)
-
-SET( zypp_media_HEADERS
- media/MediaAccess.h
- media/MediaCD.h
- media/MediaCIFS.h
- media/MediaCurl.h
- media/MediaMetalink.h
- media/MediaAria2c.h
- media/MediaDIR.h
- media/MediaDISK.h
- media/MediaException.h
- media/MediaHandler.h
- media/MediaISO.h
- media/MediaManager.h
- media/MediaNFS.h
- media/MediaSMB.h
- media/MediaSource.h
- media/MediaUserAuth.h
- media/Mount.h
- media/ProxyInfo.h
- media/CurlConfig.h
-)
-
-INSTALL( FILES
- ${zypp_media_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/media
-)
-
-SET( zypp_media_proxyinfo_SRCS
- media/proxyinfo/ProxyInfoSysconfig.cc
-)
-
-SET( zypp_media_proxyinfo_HEADERS
- media/proxyinfo/ProxyInfoImpl.h
- media/proxyinfo/ProxyInfoSysconfig.h
- media/proxyinfo/ProxyInfos.h
-)
-
-INSTALL( FILES
- ${zypp_media_proxyinfo_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/media/proxyinfo
-)
-
-SET( zypp_parser_SRCS
- parser/ParseException.cc
- parser/TagParser.cc
- parser/IniParser.cc
- parser/IniDict.cc
- parser/LibXMLHelper.cc
- parser/XMLNodeIterator.cc
- parser/RepoFileReader.cc
- parser/ProductConfReader.cc
- parser/xml_escape_parser.cpp
-)
-
-SET( zypp_parser_HEADERS
- parser/ParseException.h
- parser/TagParser.h
- parser/IniParser.h
- parser/IniDict.h
- parser/LibXMLHelper.h
- parser/ParserProgress.h
- parser/XMLNodeIterator.h
- parser/xml_parser_assert.h
- parser/RepoFileReader.h
- parser/ProductConfReader.h
- parser/xml_escape_parser.hpp
-)
-
-INSTALL( FILES
- ${zypp_parser_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/parser
-)
-
-SET( zypp_parser_susetags_SRCS
- parser/susetags/RepoIndex.cc
- parser/susetags/ContentFileReader.cc
- #parser/susetags/PackagesFileReader.cc
- #parser/susetags/PackagesLangFileReader.cc
- #parser/susetags/PackagesDuFileReader.cc
- #parser/susetags/PatternFileReader.cc
- #parser/susetags/RepoParser.cc
-)
-
-SET( zypp_parser_susetags_HEADERS
- parser/susetags/RepoIndex.h
- parser/susetags/ContentFileReader.h
- parser/susetags/FileReaderBase.h
- parser/susetags/FileReaderBaseImpl.h
- parser/susetags/PackagesFileReader.h
- parser/susetags/PackagesLangFileReader.h
- parser/susetags/PackagesDuFileReader.h
- parser/susetags/PatternFileReader.h
- parser/susetags/RepoParser.h
-)
-
-INSTALL( FILES
- ${zypp_parser_susetags_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/parser/susetags
-)
-
-SET( zypp_parser_plaindir_SRCS
- parser/plaindir/RepoParser.cc
-)
-
-SET( zypp_parser_plaindir_HEADERS
- parser/plaindir/RepoParser.h
-)
-
-INSTALL( FILES
- ${zypp_parser_plaindir_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/parser/plaindir
-)
-
-SET( zypp_parser_xml_SRCS
- parser/xml/Node.cc
- parser/xml/ParseDef.cc
- parser/xml/ParseDefConsume.cc
- parser/xml/ParseDefException.cc
- parser/xml/Reader.cc
- parser/xml/XmlString.cc
- parser/xml/libxmlfwd.cc
-)
-
-SET( zypp_parser_xml_HEADERS
- parser/xml/Node.h
- parser/xml/ParseDef.h
- parser/xml/ParseDefConsume.h
- parser/xml/ParseDefException.h
- parser/xml/ParseDefTraits.h
- parser/xml/Reader.h
- parser/xml/XmlString.h
- parser/xml/libxmlfwd.h
-)
-
-INSTALL( FILES
- ${zypp_parser_xml_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/parser/xml
-)
-
-SET( zypp_parser_yum_SRCS
- #parser/yum/RepoParser.cc
- #parser/yum/FileReaderBaseImpl.cc
- parser/yum/RepomdFileReader.cc
- parser/yum/PatchesFileReader.cc
- #parser/yum/PrimaryFileReader.cc
- #parser/yum/OtherFileReader.cc
- #parser/yum/FilelistsFileReader.cc
- #parser/yum/PatchFileReader.cc
- #parser/yum/PatternFileReader.cc
- #parser/yum/ProductFileReader.cc
-)
-
-SET( zypp_parser_yum_HEADERS
- parser/yum/RepoParser.h
- parser/yum/RepoParserOpts.h
- parser/yum/FileReaderBase.h
- parser/yum/FileReaderBaseImpl.h
- parser/yum/RepomdFileReader.h
- parser/yum/PatchesFileReader.h
- parser/yum/PrimaryFileReader.h
- parser/yum/OtherFileReader.h
- parser/yum/FilelistsFileReader.h
- parser/yum/PatchFileReader.h
- parser/yum/PatternFileReader.h
- parser/yum/ProductFileReader.h
- parser/yum/schemanames.h
-)
-
-INSTALL( FILES
- ${zypp_parser_yum_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/parser/yum
-)
-
-SET( zypp_pool_SRCS
- pool/GetResolvablesToInsDel.cc
- pool/PoolImpl.cc
- pool/PoolStats.cc
-)
-
-SET( zypp_pool_HEADERS
- pool/GetResolvablesToInsDel.h
- pool/PoolImpl.h
- pool/PoolStats.h
- pool/PoolTraits.h
-)
-
-INSTALL( FILES
- ${zypp_pool_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/pool
-)
-
-SET( zypp_solver_detail_SRCS
- solver/detail/Helper.cc
- solver/detail/InstallOrder.cc
- solver/detail/ProblemSolutionIgnore.cc
- solver/detail/ProblemSolutionCombi.cc
- solver/detail/Resolver.cc
- solver/detail/ResolverUpgrade.cc
- solver/detail/Resolver_problems.cc
- solver/detail/SolutionAction.cc
- solver/detail/Testcase.cc
- solver/detail/SolverQueueItem.cc
- solver/detail/SolverQueueItemInstall.cc
- solver/detail/SolverQueueItemDelete.cc
- solver/detail/SolverQueueItemUpdate.cc
- solver/detail/SolverQueueItemInstallOneOf.cc
- solver/detail/SolverQueueItemLock.cc
- solver/detail/SATResolver.cc
-)
-
-SET( zypp_solver_detail_HEADERS
- solver/detail/Helper.h
- solver/detail/InstallOrder.h
- solver/detail/ProblemSolutionIgnore.h
- solver/detail/ProblemSolutionCombi.h
- solver/detail/Resolver.h
- solver/detail/SolutionAction.h
- solver/detail/Testcase.h
- solver/detail/Types.h
- solver/detail/SolverQueueItem.h
- solver/detail/SolverQueueItemInstall.h
- solver/detail/SolverQueueItemDelete.h
- solver/detail/SolverQueueItemUpdate.h
- solver/detail/SolverQueueItemInstallOneOf.h
- solver/detail/SolverQueueItemLock.h
- solver/detail/SATResolver.h
-)
-
-INSTALL( FILES
- ${zypp_solver_detail_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/solver/detail
-)
-
-SET( zypp_sat_SRCS
- sat/Pool.cc
- sat/Solvable.cc
- sat/SolvableSet.cc
- sat/SolvIterMixin.cc
- sat/WhatProvides.cc
- sat/LocaleSupport.cc
- sat/LookupAttr.cc
- sat/SolvAttr.cc
-)
-
-SET( zypp_sat_HEADERS
- sat/Pool.h
- sat/Solvable.h
- sat/SolvableSet.h
- sat/SolvIterMixin.h
- sat/WhatProvides.h
- sat/LocaleSupport.h
- sat/LookupAttr.h
- sat/SolvAttr.h
-)
-
-INSTALL( FILES
- ${zypp_sat_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/sat
-)
-
-SET( zypp_sat_detail_SRCS
- sat/detail/PoolImpl.cc
-)
-
-SET( zypp_sat_detail_HEADERS
- sat/detail/PoolMember.h
- sat/detail/PoolImpl.h
-)
-
-INSTALL( FILES
- ${zypp_sat_detail_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/sat/detail
-)
-
-
-SET( zypp_target_SRCS
- target/RequestedLocalesFile.cc
- target/SoftLocksFile.cc
- target/HardLocksFile.cc
- target/CommitLog.cc
- target/CommitPackageCache.cc
- target/CommitPackageCacheImpl.cc
- target/CommitPackageCacheReadAhead.cc
- target/TargetCallbackReceiver.cc
- target/TargetException.cc
- target/TargetImpl.cc
-)
-
-SET( zypp_target_HEADERS
- target/RequestedLocalesFile.h
- target/SoftLocksFile.h
- target/HardLocksFile.h
- target/CommitLog.h
- target/CommitPackageCache.h
- target/CommitPackageCacheImpl.h
- target/CommitPackageCacheReadAhead.h
- target/TargetCallbackReceiver.h
- target/TargetException.h
- target/TargetImpl.h
-)
-
-INSTALL( FILES
- ${zypp_target_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/target
-)
-
-SET( zypp_target_hal_SRCS
- target/hal/Hal.cc
- target/hal/HalContext.cc
-)
-
-SET( zypp_target_hal_HEADERS
- target/hal/Hal.h
- target/hal/HalContext.h
- target/hal/HalException.h
-)
-
-INSTALL( FILES
- ${zypp_target_hal_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/target/hal
-)
-
-SET( zypp_target_modalias_SRCS
- target/modalias/Modalias.cc
-)
-
-SET( zypp_target_modalias_HEADERS
- target/modalias/Modalias.h
-)
-
-INSTALL( FILES
- ${zypp_target_modalias_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/target/modalias
-)
-
-SET( zypp_target_rpm_SRCS
- target/rpm/BinHeader.cc
- target/rpm/RpmCallbacks.cc
- target/rpm/RpmDb.cc
- target/rpm/RpmException.cc
- target/rpm/RpmHeader.cc
- target/rpm/librpmDb.cc
- target/rpm/librpmDb.cv3.cc
-)
-
-SET( zypp_target_rpm_HEADERS
- target/rpm/BinHeader.h
- target/rpm/RpmCallbacks.h
- target/rpm/RpmDb.h
- target/rpm/RpmException.h
- target/rpm/RpmHeader.h
- target/rpm/librpm.h
- target/rpm/librpmDb.h
-)
-
-INSTALL( FILES
- ${zypp_target_rpm_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/target/rpm
-)
-
-SET( zypp_thread_SRCS
- thread/Mutex.cc
-)
-
-SET( zypp_thread_HEADERS
- thread/Mutex.h
- thread/MutexException.h
- thread/MutexLock.h
- thread/Once.h
-)
-
-INSTALL( FILES
- ${zypp_thread_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/thread
-)
-
-SET( zypp_ui_SRCS
- ui/PatchContents.cc
- ui/PatchContentsImpl.cc
- ui/PatternContents.cc
- ui/PatternContentsImpl.cc
- ui/PatternExpander.cc
- ui/Selectable.cc
- ui/SelectableImpl.cc
- ui/Status.cc
- ui/UserWantedPackages.cc
-)
-
-SET( zypp_ui_HEADERS
- ui/PatchContents.h
- ui/PatchContentsImpl.h
- ui/PatternContents.h
- ui/PatternContentsImpl.h
- ui/PatternExpander.h
- ui/SelFilters.h
- ui/Selectable.h
- ui/SelectableImpl.h
- ui/SelectableTraits.h
- ui/Status.h
- ui/UserWantedPackages.h
-)
-
-INSTALL( FILES
- ${zypp_ui_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/ui
-)
-
-SET( zypp_url_SRCS
- url/UrlUtils.cc
- url/UrlBase.cc
-)
-
-SET( zypp_url_HEADERS
- url/UrlBase.h
- url/UrlException.h
- url/UrlUtils.h
-)
-
-INSTALL( FILES
- ${zypp_url_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/url
-)
-
-SET( zypp_zypp_detail_SRCS
- zypp_detail/ZYppImpl.cc
-)
-
-SET( zypp_zypp_detail_HEADERS
- zypp_detail/ZYppImpl.h
- zypp_detail/ZYppReadOnlyHack.h
-)
-
-INSTALL( FILES
- ${zypp_zypp_detail_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/zypp_detail
-)
-
-SET( zypp_repo_SRCS
- repo/dummy.cc
- repo/RepoException.cc
- repo/RepoType.cc
- repo/PackageProvider.cc
- repo/SrcPackageProvider.cc
- repo/ScriptProvider.cc
- repo/RepoProvideFile.cc
- repo/DeltaCandidates.cc
- repo/Applydeltarpm.cc
- repo/PackageDelta.cc
- repo/SUSEMediaVerifier.cc
- repo/MediaInfoDownloader.cc
- repo/Downloader.cc
- repo/RepoVariables.cc
-)
-
-SET( zypp_repo_HEADERS
- repo/RepoException.h
- repo/RepoType.h
- repo/PackageProvider.h
- repo/SrcPackageProvider.h
- repo/ScriptProvider.h
- repo/RepoProvideFile.h
- repo/DeltaCandidates.h
- repo/Applydeltarpm.h
- repo/PackageDelta.h
- repo/SUSEMediaVerifier.h
- repo/MediaInfoDownloader.h
- repo/Downloader.h
- repo/RepoVariables.h
-)
-
-INSTALL( FILES
- ${zypp_repo_HEADERS}
- DESTINATION ${CMAKE_INSTALL_PREFIX}/include/zypp/repo
-)
-
-SET( zypp_repo_yum_SRCS
- repo/yum/Downloader.cc
- repo/yum/ResourceType.cc
-)
-
-SET( zypp_repo_yum_HEADERS
- repo/yum/Downloader.h
- repo/yum/ResourceType.h
-)
-
-SET( zypp_repo_susetags_SRCS
- repo/susetags/Downloader.cc
-)
-
-SET( zypp_repo_susetags_HEADERS
- repo/susetags/Downloader.h
-)
-
-SET( zypp_lib_SRCS
-${zypp_pool_SRCS}
-${zypp_parser_susetags_SRCS}
-${zypp_parser_xml_SRCS}
-${zypp_parser_yum_SRCS}
-${zypp_parser_plaindir_SRCS}
-${zypp_parser_SRCS}
-${zypp_data_SRCS}
-${zypp_media_proxyinfo_SRCS}
-${zypp_media_SRCS}
-${zypp_url_SRCS}
-${zypp_repo_SRCS}
-${zypp_repo_yum_SRCS}
-${zypp_repo_susetags_SRCS}
-${zypp_repo_data_SRCS}
-${zypp_target_rpm_SRCS}
-${zypp_target_hal_SRCS}
-${zypp_target_modalias_SRCS}
-${zypp_target_SRCS}
-${zypp_solver_detail_SRCS}
-${zypp_ui_SRCS}
-${zypp_thread_SRCS}
-${zypp_SRCS}
-${zypp_zypp_detail_SRCS}
-${zypp_sat_SRCS}
-${zypp_sat_detail_SRCS}
-${zypp_EARLY_SRCS}
-${zypp_base_SRCS}
-)
-
-SET( zypp_lib_HEADERS
-${zypp_target_rpm_HEADERS}
-${zypp_parser_tagfile_HEADERS}
-${zypp_parser_susetags_HEADERS}
-${zypp_parser_yum_HEADERS}
-${zypp_parser_plaindir_HEADERS}
-${zypp_parser_xml_HEADERS}
-${zypp_parser_HEADERS}
-${zypp_data_HEADERS}
-${zypp_ui_HEADERS}
-${zypp_media_HEADERS}
-${zypp_target_hal_HEADERS}
-${zypp_media_proxyinfo_HEADERS}
-${zypp_base_HEADERS}
-${zypp_solver_detail_HEADERS}
-${zypp_sat_HEADERS}
-${zypp_sat_detail_HEADERS}
-${zypp_url_HEADERS}
-${zypp_HEADERS}
-${zypp_zypp_detail_HEADERS}
-${zypp_thread_HEADERS}
-${zypp_repo_HEADERS}
-${zypp_source_susetags_HEADERS}
-${zypp_target_modalias_HEADERS}
-${zypp_target_HEADERS}
-${zypp_pool_HEADERS}
-)
-
-#
-# Macro to set the log group for a list of files
-#
-MACRO( SET_LOGGROUP _group _files )
- SET_SOURCE_FILES_PROPERTIES( ${_files} COMPILE_FLAGS -DZYPP_BASE_LOGGER_LOGGROUP=\\"${_group}\\" )
- FOREACH (_currentFile ${ARGN})
-#MESSAGE( STATUS "setting loggroup to \"${_group}\" for ${_currentFile}" )
- SET_SOURCE_FILES_PROPERTIES( ${_currentFile} COMPILE_FLAGS -DZYPP_BASE_LOGGER_LOGGROUP=\\"${_group}\\" )
- ENDFOREACH (_currentFile ${ARGN})
-ENDMACRO( SET_LOGGROUP )
-
-# Default loggroup for all files
-SET_LOGGROUP( "zypp" ${zypp_lib_SRCS} )
-
-# override some defaults
-SET_LOGGROUP( "satsolver" ${zypp_sat_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_target_rpm_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_parser_yum2_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_capability_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_ui_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_data_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_media_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_target_hal_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_parser_xml_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_media_proxyinfo_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_source_yum_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_base_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_solver_detail_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_sat_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_url_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_source_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_parser_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_zypp_detail_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_thread_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_source_susetags_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_target_modalias_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_target_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_parser_yum_SRCS} )
-#SET_LOGGROUP( "group" ${zypp_pool_SRCS} )
-
-
-ADD_LIBRARY(zypp SHARED ${zypp_lib_SRCS})
-SET_TARGET_PROPERTIES( zypp PROPERTIES VERSION "${LIBZYPP_VERSION_INFO}" )
-SET_TARGET_PROPERTIES( zypp PROPERTIES SOVERSION "${LIBZYPP_SOVERSION_INFO}" )
-ADD_DEPENDENCIES(zypp schema_header)
-# System libraries
-TARGET_LINK_LIBRARIES(zypp util )
-TARGET_LINK_LIBRARIES(zypp ${DBUS_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${RPM_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${GETTEXT_LIBRARIES} )
-TARGET_LINK_LIBRARIES(zypp ${HAL_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${HAL_STORAGE_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${CURL_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${LIBXML_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${ZLIB_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${SATSOLVER_LIBRARY} )
-TARGET_LINK_LIBRARIES(zypp ${OPENSSL_LIBRARIES})
-TARGET_LINK_LIBRARIES(zypp ${METALINK_LIBRARY})
-TARGET_LINK_LIBRARIES(zypp crypto)
-
-INSTALL(TARGETS zypp LIBRARY DESTINATION ${LIB_INSTALL_DIR} )
-
-# install XML schemas
-FILE( GLOB YUM_SCHEMA_FILES ${CMAKE_SOURCE_DIR}/zypp/parser/yum/schema/*.rng )
-INSTALL(FILES ${YUM_SCHEMA_FILES} DESTINATION "${CMAKE_INSTALL_PREFIX}/share/zypp/schema/yum" )
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/media/MediaAccess.cc
- *
-*/
-
-#include <ctype.h>
-
-#include <iostream>
-
-#include "zypp/base/Logger.h"
-
-#include "zypp/media/MediaException.h"
-#include "zypp/media/MediaAccess.h"
-#include "zypp/media/MediaHandler.h"
-
-#include "zypp/media/MediaNFS.h"
-#include "zypp/media/MediaCD.h"
-#include "zypp/media/MediaDIR.h"
-#include "zypp/media/MediaDISK.h"
-#include "zypp/media/MediaSMB.h"
-#include "zypp/media/MediaCIFS.h"
-#include "zypp/media/MediaCurl.h"
-#include "zypp/media/MediaMetalink.h"
-#include "zypp/media/MediaAria2c.h"
-#include "zypp/media/MediaISO.h"
-
-using namespace std;
-
-namespace zypp {
- namespace media {
-
-///////////////////////////////////////////////////////////////////
-//
-// CLASS NAME : MediaAccess
-//
-///////////////////////////////////////////////////////////////////
-
-const Pathname MediaAccess::_noPath; // empty path
-
-///////////////////////////////////////////////////////////////////
-// constructor
-MediaAccess::MediaAccess ()
- : _handler (0)
-{
-}
-
-// destructor
-MediaAccess::~MediaAccess()
-{
- try
- {
- close(); // !!! make sure handler gets properly deleted.
- }
- catch(...) {}
-}
-
-AttachedMedia
-MediaAccess::attachedMedia() const
-{
- return _handler ? _handler->attachedMedia()
- : AttachedMedia();
-}
-
-bool
-MediaAccess::isSharedMedia() const
-{
- return _handler ? _handler->isSharedMedia()
- : false;
-}
-
-void
-MediaAccess::resetParentId()
-{
- if( _handler) _handler->resetParentId();
-}
-
-bool
-MediaAccess::dependsOnParent() const
-{
- return _handler ? _handler->dependsOnParent() : false;
-}
-
-bool
-MediaAccess::dependsOnParent(MediaAccessId parentId,
- bool exactIdMatch) const
-{
- return _handler ? _handler->dependsOnParent(parentId, exactIdMatch)
- : false;
-}
-
-// open URL
-void
-MediaAccess::open (const Url& url, const Pathname & preferred_attach_point)
-{
- if(!url.isValid()) {
- MIL << "Url is not valid" << endl;
- ZYPP_THROW(MediaBadUrlException(url));
- }
-
- close();
-
- std::string scheme = url.getScheme();
-
- MIL << "Trying scheme '" << scheme << "'" << endl;
- /*
- ** WARNING: Don't forget to update MediaAccess::downloads(url)
- ** if you are adding a new url scheme / handler!
- */
- if (scheme == "cd" || scheme == "dvd")
- _handler = new MediaCD (url,preferred_attach_point);
- else if (scheme == "nfs")
- _handler = new MediaNFS (url,preferred_attach_point);
- else if (scheme == "iso")
- _handler = new MediaISO (url,preferred_attach_point);
- else if (scheme == "file" || scheme == "dir")
- _handler = new MediaDIR (url,preferred_attach_point);
- else if (scheme == "hd")
- _handler = new MediaDISK (url,preferred_attach_point);
- else if (scheme == "smb")
- _handler = new MediaSMB (url,preferred_attach_point);
- else if (scheme == "cifs")
- _handler = new MediaCIFS (url,preferred_attach_point);
- else if (scheme == "ftp" || scheme == "http" || scheme == "https")
- //_handler = new MediaCurl (url,preferred_attach_point);
- //_handler = new MediaMetalink (url,preferred_attach_point);
- _handler = new MediaAria2c (url,preferred_attach_point);
- else
- {
- ZYPP_THROW(MediaUnsupportedUrlSchemeException(url));
- }
-
- // check created handler
- if ( !_handler ){
- ERR << "Failed to create media handler" << endl;
- ZYPP_THROW(MediaSystemException(url, "Failed to create media handler"));
- }
-
- MIL << "Opened: " << *this << endl;
-}
-
-// STATIC
-bool
-MediaAccess::downloads(const Url &url)
-{
- std::string scheme( url.getScheme());
- return (scheme == "ftp" || scheme == "http" || scheme == "https");
-}
-
-// STATIC
-bool
-MediaAccess::canBeVolatile(const Url &url)
-{
- std::string scheme( url.getScheme());
- return ! (scheme == "cd" || scheme == "dvd");
-}
-
-// Type of media if open, otherwise NONE.
-std::string
-MediaAccess::protocol() const
-{
- if ( !_handler )
- return "unknown";
-
- return _handler->protocol();
-}
-
-bool
-MediaAccess::downloads() const
-{
- return _handler ? _handler->downloads() : false;
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAccess::url
-// METHOD TYPE : Url
-//
-Url MediaAccess::url() const
-{
- if ( !_handler )
- return Url();
-
- return _handler->url();
-}
-
-// close handler
-void
-MediaAccess::close ()
-{
- ///////////////////////////////////////////////////////////////////
- // !!! make shure handler gets properly deleted.
- // I.e. release attached media before deleting the handler.
- ///////////////////////////////////////////////////////////////////
- if ( _handler ) {
- try {
- _handler->release();
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_CAUGHT(excpt_r);
- WAR << "Close: " << *this << " (" << excpt_r << ")" << endl;
- ZYPP_RETHROW(excpt_r);
- }
- MIL << "Close: " << *this << " (OK)" << endl;
- delete _handler;
- _handler = 0;
- }
-}
-
-
-// attach media
-void MediaAccess::attach (bool next)
-{
- if ( !_handler ) {
- ZYPP_THROW(MediaNotOpenException("attach"));
- }
- _handler->attach(next);
-}
-
-// True if media is open and attached.
-bool
-MediaAccess::isAttached() const
-{
- return( _handler && _handler->isAttached() );
-}
-
-
-bool MediaAccess::hasMoreDevices() const
-{
- return _handler && _handler->hasMoreDevices();
-}
-
-
-void
-MediaAccess::getDetectedDevices(std::vector<std::string> & devices,
- unsigned int & index) const
-{
- if (_handler)
- {
- _handler->getDetectedDevices(devices, index);
- return;
- }
-
- if (!devices.empty())
- devices.clear();
- index = 0;
-}
-
-
-// local directory that corresponds to medias url
-// If media is not open an empty pathname.
-Pathname
-MediaAccess::localRoot() const
-{
- if ( !_handler )
- return _noPath;
-
- return _handler->localRoot();
-}
-
-// Short for 'localRoot() + pathname', but returns an empty
-// * pathname if media is not open.
-Pathname
-MediaAccess::localPath( const Pathname & pathname ) const
-{
- if ( !_handler )
- return _noPath;
-
- return _handler->localPath( pathname );
-}
-
-void
-MediaAccess::disconnect()
-{
- if ( !_handler )
- ZYPP_THROW(MediaNotOpenException("disconnect"));
-
- _handler->disconnect();
-}
-
-
-void
-MediaAccess::release( const std::string & ejectDev )
-{
- if ( !_handler )
- return;
-
- _handler->release( ejectDev );
-}
-
-// provide file denoted by path to attach dir
-//
-// filename is interpreted relative to the attached url
-// and a path prefix is preserved to destination
-void
-MediaAccess::provideFile( const Pathname & filename, bool cached, bool checkonly) const
-{
- if ( cached ) {
- PathInfo pi( localPath( filename ) );
- if ( pi.isExist() )
- return;
- }
-
- if(checkonly)
- ZYPP_THROW(MediaFileNotFoundException(url(), filename));
-
- if ( !_handler ) {
- ZYPP_THROW(MediaNotOpenException("provideFile(" + filename.asString() + ")"));
- }
-
- _handler->provideFile( filename );
-}
-
-void
-MediaAccess::releaseFile( const Pathname & filename ) const
-{
- if ( !_handler )
- return;
-
- _handler->releaseFile( filename );
-}
-
-// provide directory tree denoted by path to attach dir
-//
-// dirname is interpreted relative to the attached url
-// and a path prefix is preserved to destination
-void
-MediaAccess::provideDir( const Pathname & dirname ) const
-{
- if ( !_handler ) {
- ZYPP_THROW(MediaNotOpenException("provideDir(" + dirname.asString() + ")"));
- }
-
- _handler->provideDir( dirname );
-}
-
-void
-MediaAccess::provideDirTree( const Pathname & dirname ) const
-{
- if ( !_handler ) {
- ZYPP_THROW(MediaNotOpenException("provideDirTree(" + dirname.asString() + ")"));
- }
-
- _handler->provideDirTree( dirname );
-}
-
-void
-MediaAccess::releaseDir( const Pathname & dirname ) const
-{
- if ( !_handler )
- return;
-
- _handler->releaseDir( dirname );
-}
-
-void
-MediaAccess::releasePath( const Pathname & pathname ) const
-{
- if ( !_handler )
- return;
-
- _handler->releasePath( pathname );
-}
-
-// Return content of directory on media
-void
-MediaAccess::dirInfo( std::list<std::string> & retlist, const Pathname & dirname, bool dots ) const
-{
- retlist.clear();
-
- if ( !_handler ) {
- ZYPP_THROW(MediaNotOpenException("dirInfo(" + dirname.asString() + ")"));
- }
-
- _handler->dirInfo( retlist, dirname, dots );
-}
-
-// Return content of directory on media
-void
-MediaAccess::dirInfo( filesystem::DirContent & retlist, const Pathname & dirname, bool dots ) const
-{
- retlist.clear();
-
- if ( !_handler ) {
- ZYPP_THROW(MediaNotOpenException("dirInfo(" + dirname.asString() + ")"));
- }
-
- _handler->dirInfo( retlist, dirname, dots );
-}
-
-// return if a file exists
-bool
-MediaAccess::doesFileExist( const Pathname & filename ) const
-{
- if ( !_handler ) {
- ZYPP_THROW(MediaNotOpenException("doesFileExist(" + filename.asString() + ")"));
- }
-
- return _handler->doesFileExist( filename );
-}
-
-std::ostream &
-MediaAccess::dumpOn( std::ostream & str ) const
-{
- if ( !_handler )
- return str << "MediaAccess( closed )";
-
- str << _handler->protocol() << "(" << *_handler << ")";
- return str;
-}
-
-void MediaAccess::getFile( const Url &from, const Pathname &to )
-{
- DBG << "From: " << from << endl << "To: " << to << endl;
-
- Pathname path = from.getPathData();
- Pathname dir = path.dirname();
- string base = path.basename();
-
- Url u = from;
- u.setPathData( dir.asString() );
-
- MediaAccess media;
-
- try {
- media.open( u );
- media.attach();
- media._handler->provideFileCopy( base, to );
- media.release();
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
-}
-
- std::ostream & operator<<( std::ostream & str, const MediaAccess & obj )
- { return obj.dumpOn( str ); }
-
-///////////////////////////////////////////////////////////////////
- } // namespace media
-} // namespace zypp
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/media/MediaAria2c.cc
- *
-*/
-
-#include <iostream>
-#include <list>
-
-#include "zypp/base/Logger.h"
-#include "zypp/ExternalProgram.h"
-#include "zypp/ProgressData.h"
-#include "zypp/base/String.h"
-#include "zypp/base/Gettext.h"
-#include "zypp/base/Sysconfig.h"
-#include "zypp/base/Gettext.h"
-#include "zypp/ZYppCallbacks.h"
-
-#include "zypp/media/MediaAria2c.h"
-#include "zypp/media/proxyinfo/ProxyInfos.h"
-#include "zypp/media/ProxyInfo.h"
-#include "zypp/media/MediaUserAuth.h"
-#include "zypp/media/CurlConfig.h"
-#include "zypp/thread/Once.h"
-#include <cstdlib>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <errno.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <boost/format.hpp>
-
-#define DETECT_DIR_INDEX 0
-#define CONNECT_TIMEOUT 60
-#define TRANSFER_TIMEOUT 60 * 3
-#define TRANSFER_TIMEOUT_MAX 60 * 60
-
-
-using namespace std;
-using namespace zypp::base;
-
-namespace
-{
- //zypp::thread::OnceFlag g_InitOnceFlag = PTHREAD_ONCE_INIT;
- //zypp::thread::OnceFlag g_FreeOnceFlag = PTHREAD_ONCE_INIT;
- /*
- extern "C" void _do_aria2c_free_once()
- {
- curl_global_cleanup();
- }
-
- extern "C" void globalAria2cFreeOnce()
- {
- zypp::thread::callOnce(g_FreeOnceFlag, _do_aria2c_free_once);
- }
-
- extern "C" void _do_aria2c_init_once()
- {
- CURLcode ret = curl_global_init( CURL_GLOBAL_ALL );
- if ( ret != 0 )
- {
- WAR << "curl global init failed" << endl;
- }
-
- //
- // register at exit handler ?
- // this may cause trouble, because we can protect it
- // against ourself only.
- // if the app sets an atexit handler as well, it will
- // cause a double free while the second of them runs.
- //
- //std::atexit( globalFreeOnce);
- }
-
-
- inline void globalInitOnce()
- {
- zypp::thread::callOnce(g_InitOnceFlag, _do_aria2c_init_once);
- }
-*/
-/*
- int log_curl(CURL *curl, curl_infotype info,
- char *ptr, size_t len, void *max_lvl)
- {
- std::string pfx(" ");
- long lvl = 0;
- switch( info)
- {
- case CURLINFO_TEXT: lvl = 1; pfx = "*"; break;
- case CURLINFO_HEADER_IN: lvl = 2; pfx = "<"; break;
- case CURLINFO_HEADER_OUT: lvl = 2; pfx = ">"; break;
- default: break;
- }
- if( lvl > 0 && max_lvl != NULL && lvl <= *((long *)max_lvl))
- {
- std::string msg(ptr, len);
- std::list<std::string> lines;
- std::list<std::string>::const_iterator line;
- zypp::str::split(msg, std::back_inserter(lines), "\r\n");
- for(line = lines.begin(); line != lines.end(); ++line)
- {
- DBG << pfx << " " << *line << endl;
- }
- }
- return 0;
- }
- */
-}
-
-namespace zypp {
- namespace media {
-
- namespace {
- /*
- struct ProgressData
- {
- ProgressData(const long _timeout, const zypp::Url &_url = zypp::Url(),
- callback::SendReport<DownloadProgressReport> *_report=NULL)
- : timeout(_timeout)
- , reached(false)
- , report(_report)
- , drate_period(-1)
- , dload_period(0)
- , secs(0)
- , drate_avg(-1)
- , ltime( time(NULL))
- , dload( 0)
- , uload( 0)
- , url(_url)
- {}
- long timeout;
- bool reached;
- callback::SendReport<DownloadProgressReport> *report;
- // download rate of the last period (cca 1 sec)
- double drate_period;
- // bytes downloaded at the start of the last period
- double dload_period;
- // seconds from the start of the download
- long secs;
- // average download rate
- double drate_avg;
- // last time the progress was reported
- time_t ltime;
- // bytes downloaded at the moment the progress was last reported
- double dload;
- // bytes uploaded at the moment the progress was last reported
- double uload;
- zypp::Url url;
- };
- */
-
- ///////////////////////////////////////////////////////////////////
-
- inline void escape( string & str_r,
- const char char_r, const string & escaped_r ) {
- for ( string::size_type pos = str_r.find( char_r );
- pos != string::npos; pos = str_r.find( char_r, pos ) ) {
- str_r.replace( pos, 1, escaped_r );
- }
- }
-
- inline string escapedPath( string path_r ) {
- escape( path_r, ' ', "%20" );
- return path_r;
- }
-
- inline string unEscape( string text_r ) {
- char * tmp = curl_unescape( text_r.c_str(), 0 );
- string ret( tmp );
- curl_free( tmp );
- return ret;
- }
-
- }
-
-///////////////////////////////////////////////////////////////////
-//
-// CLASS NAME : MediaAria2c
-//
-///////////////////////////////////////////////////////////////////
-
-Pathname MediaAria2c::_cookieFile = "/var/lib/YaST2/cookies";
-Pathname MediaAria2c::_aria2cPath = "/usr/local/bin/aria2c";
-
-const char *const MediaAria2c::agentString()
-{
- //std::string aria2cVersionString = getAria2cVersion();
- //getAria2cVersion();
- static const std::string _value( str::form( "ZYpp %s (with aria2c 0.14.0+1)", VERSION ));
-
- return _value.c_str();
-}
-
-
-MediaAria2c::MediaAria2c( const Url & url_r,
- const Pathname & attach_point_hint_r )
- : MediaHandler( url_r, attach_point_hint_r,
- "/", // urlpath at attachpoint
- true ) // does_download
- //_curl( NULL )
-{
- /*
- _curlError[0] = '\0';
- _curlDebug = 0L;
- */
-
- MIL << "MediaAria2c::MediaAria2c(" << url_r << ", " << attach_point_hint_r << ")" << endl;
-
- //globalInitOnce();
-
- if( !attachPoint().empty())
- {
- PathInfo ainfo(attachPoint());
- Pathname apath(attachPoint() + "XXXXXX");
- char *atemp = ::strdup( apath.asString().c_str());
- char *atest = NULL;
- if( !ainfo.isDir() || !ainfo.userMayRWX() ||
- atemp == NULL || (atest=::mkdtemp(atemp)) == NULL)
- {
- WAR << "attach point " << ainfo.path()
- << " is not useable for " << url_r.getScheme() << endl;
- setAttachPoint("", true);
- }
- else if( atest != NULL)
- ::rmdir(atest);
-
- if( atemp != NULL)
- ::free(atemp);
- }
-}
-
-/*
-void MediaAria2c::setCookieFile( const Pathname &fileName )
-{
- _cookieFile = fileName;
-}*/
-
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::attachTo
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
-//
-void MediaAria2c::attachTo (bool next)
-{
-
- if ( next )
- ZYPP_THROW(MediaNotSupportedException(_url));
-
- if ( !_url.isValid() )
- ZYPP_THROW(MediaBadUrlException(_url));
-
-/*
- CurlConfig curlconf;
- CurlConfig::parseConfig(curlconf); // parse ~/.curlrc
-
- curl_version_info_data *curl_info = NULL;
- curl_info = curl_version_info(CURLVERSION_NOW);
- // curl_info does not need any free (is static)
- if (curl_info->protocols)
- {
- const char * const *proto;
- std::string scheme( _url.getScheme());
- bool found = false;
- for(proto=curl_info->protocols; !found && *proto; ++proto)
- {
- if( scheme == std::string((const char *)*proto))
- found = true;
- }
- if( !found)
- {
- std::string msg("Unsupported protocol '");
- msg += scheme;
- msg += "'";
- ZYPP_THROW(MediaBadUrlException(_url, msg));
- }
- }*/
-
- if( !isUseableAttachPoint(attachPoint()))
- {
- std::string mountpoint = createAttachPoint().asString();
-
- if( mountpoint.empty())
- ZYPP_THROW( MediaBadAttachPointException(url()));
-
- setAttachPoint( mountpoint, true);
- }
-
- disconnectFrom(); // clean _curl if needed
-/*
- _curl = curl_easy_init();
- if ( !_curl ) {
- ZYPP_THROW(MediaAria2cInitException(_url));
- }
-
- {
- char *ptr = getenv("ZYPP_MEDIA_CURL_DEBUG");
- _curlDebug = (ptr && *ptr) ? str::strtonum<long>( ptr) : 0L;
- if( _curlDebug > 0)
- {
- curl_easy_setopt( _curl, CURLOPT_VERBOSE, 1);
- curl_easy_setopt( _curl, CURLOPT_DEBUGFUNCTION, log_curl);
- curl_easy_setopt( _curl, CURLOPT_DEBUGDATA, &_curlDebug);
- }
- }
-
- CURLcode ret = curl_easy_setopt( _curl, CURLOPT_ERRORBUFFER, _curlError );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, "Error setting error buffer"));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_FAILONERROR, true );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_NOSIGNAL, 1 );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
-
- * Transfer timeout
-
- {
- _xfer_timeout = TRANSFER_TIMEOUT;
-
- std::string param(_url.getQueryParam("timeout"));
- if( !param.empty())
- {
- long num = str::strtonum<long>( param);
- if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
- _xfer_timeout = num;
- }
- }
-
-
- ** Connect timeout
-
- ret = curl_easy_setopt( _curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- if ( _url.getScheme() == "http" ) {
- // follow any Location: header that the server sends as part of
- // an HTTP header (#113275)
- ret = curl_easy_setopt ( _curl, CURLOPT_FOLLOWLOCATION, true );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
- ret = curl_easy_setopt ( _curl, CURLOPT_MAXREDIRS, 3L );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt ( _curl, CURLOPT_USERAGENT, agentString() );
-
-
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
- }
-
- if ( _url.getScheme() == "https" )
- {
- bool verify_peer = false;
- bool verify_host = false;
-
- std::string verify( _url.getQueryParam("ssl_verify"));
- if( verify.empty() ||
- verify == "yes")
- {
- verify_peer = true;
- verify_host = true;
- }
- else
- if( verify == "no")
- {
- verify_peer = false;
- verify_host = false;
- }
- else
- {
- std::vector<std::string> flags;
- std::vector<std::string>::const_iterator flag;
- str::split( verify, std::back_inserter(flags), ",");
- for(flag = flags.begin(); flag != flags.end(); ++flag)
- {
- if( *flag == "host")
- {
- verify_host = true;
- }
- else
- if( *flag == "peer")
- {
- verify_peer = true;
- }
- else
- {
- disconnectFrom();
- ZYPP_THROW(MediaBadUrlException(_url, "Unknown ssl_verify flag"));
- }
- }
- }
-
- _ca_path = Pathname(_url.getQueryParam("ssl_capath")).asString();
- if( _ca_path.empty())
- {
- _ca_path = "/etc/ssl/certs/";
- }
- else
- if( !PathInfo(_ca_path).isDir() || !Pathname(_ca_path).absolute())
- {
- disconnectFrom();
- ZYPP_THROW(MediaBadUrlException(_url, "Invalid ssl_capath path"));
- }
-
- if( verify_peer || verify_host)
- {
- ret = curl_easy_setopt( _curl, CURLOPT_CAPATH, _ca_path.c_str());
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYPEER, verify_peer ? 1L : 0L);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
- ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYHOST, verify_host ? 2L : 0L);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt ( _curl, CURLOPT_USERAGENT, agentString() );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
- }
-
-
- ---------------------------------------------------------------*
- CURLOPT_USERPWD: [user name]:[password]
-
- Url::username/password -> CURLOPT_USERPWD
- If not provided, anonymous FTP identification
- *---------------------------------------------------------------
-
- if ( _url.getUsername().empty() ) {
- if ( _url.getScheme() == "ftp" ) {
- string id = "yast2@";
- id += VERSION;
- DBG << "Anonymous FTP identification: '" << id << "'" << endl;
- _userpwd = "anonymous:" + id;
- }
- } else {
- _userpwd = _url.getUsername();
- if ( _url.getPassword().size() ) {
- _userpwd += ":" + _url.getPassword();
- }
- }
-
- if ( _userpwd.size() ) {
- _userpwd = unEscape( _userpwd );
- ret = curl_easy_setopt( _curl, CURLOPT_USERPWD, _userpwd.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- // HTTP authentication type
- if(_url.getScheme() == "http" || _url.getScheme() == "https")
- {
- string use_auth = _url.getQueryParam("auth");
- if( use_auth.empty())
- use_auth = "digest,basic";
-
- try
- {
- long auth = CurlAuthData::auth_type_str2long(use_auth);
- if( auth != CURLAUTH_NONE)
- {
- DBG << "Enabling HTTP authentication methods: " << use_auth
- << " (CURLOPT_HTTPAUTH=" << auth << ")" << std::endl;
-
- ret = curl_easy_setopt( _curl, CURLOPT_HTTPAUTH, auth);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
- }
- }
- catch (MediaException & ex_r)
- {
- string auth_hint = getAuthHint();
-
- DBG << "Rethrowing as MediaUnauthorizedException. auth hint: '"
- << auth_hint << "'" << endl;
-
- ZYPP_THROW(MediaUnauthorizedException(
- _url, ex_r.msg(), _curlError, auth_hint
- ));
- }
- }
- }
-
- ---------------------------------------------------------------*
- CURLOPT_PROXY: host[:port]
-
- Url::option(proxy and proxyport) -> CURLOPT_PROXY
- If not provided, /etc/sysconfig/proxy is evaluated
- *---------------------------------------------------------------*
-
- _proxy = _url.getQueryParam( "proxy" );
-
- if ( ! _proxy.empty() ) {
- string proxyport( _url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- _proxy += ":" + proxyport;
- }
- } else {
-
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
-
- if ( proxy_info.enabled())
- {
- bool useproxy = true;
-
- std::list<std::string> nope = proxy_info.noProxy();
- for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
- it != proxy_info.noProxyEnd();
- it++)
- {
- std::string host( str::toLower(_url.getHost()));
- std::string temp( str::toLower(*it));
-
- // no proxy if it points to a suffix
- // preceeded by a '.', that maches
- // the trailing portion of the host.
- if( temp.size() > 1 && temp.at(0) == '.')
- {
- if(host.size() > temp.size() &&
- host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
- else
- // no proxy if we have an exact match
- if( host == temp)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
-
- if ( useproxy ) {
- _proxy = proxy_info.proxy(_url.getScheme());
- }
- }
- }
-
-
- DBG << "Proxy: " << (_proxy.empty() ? "-none-" : _proxy) << endl;
-
- if ( ! _proxy.empty() ) {
-
- ret = curl_easy_setopt( _curl, CURLOPT_PROXY, _proxy.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- *---------------------------------------------------------------*
- CURLOPT_PROXYUSERPWD: [user name]:[password]
-
- Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
- If not provided, $HOME/.curlrc is evaluated
- *---------------------------------------------------------------*
-
- _proxyuserpwd = _url.getQueryParam( "proxyuser" );
-
- if ( ! _proxyuserpwd.empty() ) {
- string proxypassword( _url.getQueryParam( "proxypassword" ) );
- if ( ! proxypassword.empty() ) {
- _proxyuserpwd += ":" + proxypassword;
- }
- } else {
- if (curlconf.proxyuserpwd.empty())
- DBG << "~/.curlrc does not contain the proxy-user option" << endl;
- else
- {
- _proxyuserpwd = curlconf.proxyuserpwd;
- DBG << "using proxy-user from ~/.curlrc" << endl;
- }
- }
-
- _proxyuserpwd = unEscape( _proxyuserpwd );
- ret = curl_easy_setopt( _curl, CURLOPT_PROXYUSERPWD, _proxyuserpwd.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
- }
-
- *---------------------------------------------------------------*
- *---------------------------------------------------------------*
-
- _currentCookieFile = _cookieFile.asString();
-
- ret = curl_easy_setopt( _curl, CURLOPT_COOKIEFILE,
- _currentCookieFile.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_COOKIEJAR,
- _currentCookieFile.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_PROGRESSFUNCTION,
- &progressCallback );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_NOPROGRESS, false );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-*/
- // FIXME: need a derived class to propelly compare url's
- MediaSourceRef media( new MediaSource(_url.getScheme(), _url.asString()));
- setMediaSource(media);
-
-}
-
-bool
-MediaAria2c::checkAttachPoint(const Pathname &apoint) const
-{
- return MediaHandler::checkAttachPoint( apoint, true, true);
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::disconnectFrom
-// METHOD TYPE : PMError
-//
-void MediaAria2c::disconnectFrom()
-{
- /*
- if ( _curl )
- {
- curl_easy_cleanup( _curl );
- _curl = NULL;
- }*/
-}
-
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::releaseFrom
-// METHOD TYPE : void
-//
-// DESCRIPTION : Asserted that media is attached.
-//
-void MediaAria2c::releaseFrom( const std::string & ejectDev )
-{
- disconnect();
-}
-
-static Url getFileUrl(const Url & url, const Pathname & filename)
-{
- Url newurl(url);
- string path = url.getPathName();
- if ( !path.empty() && path != "/" && *path.rbegin() == '/' &&
- filename.absolute() )
- {
- // If url has a path with trailing slash, remove the leading slash from
- // the absolute file name
- path += filename.asString().substr( 1, filename.asString().size() - 1 );
- }
- else if ( filename.relative() )
- {
- // Add trailing slash to path, if not already there
- if (path.empty()) path = "/";
- else if (*path.rbegin() != '/' ) path += "/";
- // Remove "./" from begin of relative file name
- path += filename.asString().substr( 2, filename.asString().size() - 2 );
- }
- else
- {
- path += filename.asString();
- }
-
- newurl.setPathName(path);
- return newurl;
-}
-
-
-///////////////////////////////////////////////////////////////////
-//
-// METHOD NAME : MediaAria2c::getFile
-// METHOD TYPE : void
-//
-void MediaAria2c::getFile( const Pathname & filename ) const
-{
- // Use absolute file name to prevent access of files outside of the
- // hierarchy below the attach point.
- getFileCopy(filename, localPath(filename).absolutename());
-}
-
-///////////////////////////////////////////////////////////////////
-//
-// METHOD NAME : MediaAria2c::getFileCopy
-// METHOD TYPE : void
-//
-void MediaAria2c::getFileCopy( const Pathname & filename , const Pathname & target) const
-{
- callback::SendReport<DownloadProgressReport> report;
-
- Url fileurl(getFileUrl(_url, filename));
-
- bool retry = false;
- CurlAuthData auth_data;
-
- do
- {
- try
- {
-
- report->start(_url, target.asString() );
-
- std::string ariaCommand = _aria2cPath.asString();
- ariaCommand.append( " --user-agent=\"" );
- ariaCommand.append( agentString() );
- ariaCommand.append("\" --summary-interval=1 --follow-metalink=mem --check-integrity=true --dir=");
- ariaCommand.append(target.dirname().asString() );
- ariaCommand.append(" ");
- ariaCommand.append( fileurl.asString() );
-
- ExternalProgram aria(ariaCommand, ExternalProgram::Stderr_To_Stdout);
-
- int nLine = 0;
- //Process response
- for(std::string ariaResponse( aria.receiveLine()); ariaResponse.length(); ariaResponse = aria.receiveLine())
- {
- //cout << ariaResponse;
- if (!ariaResponse.substr(0,9).compare("[#2 SIZE:")) {
-
- if (!nLine) {
- size_t left_bound = ariaResponse.find('(',0) + 1;
- size_t count = ariaResponse.find('%',left_bound) - left_bound;
- //cout << ariaResponse.substr(left_bound, count) << endl;
- //progressData.toMax();
- report->progress ( std::atoi(ariaResponse.substr(left_bound, count).c_str()), _url, -1, -1 );
- nLine = 1;
- } else {
- nLine = 0;
- }
-
-
- }
-
- }
-
- report->finish( _url , zypp::media::DownloadProgressReport::NO_ERROR, "");
- retry = false;
- }
- // retry with proper authentication data
- catch (MediaUnauthorizedException & ex_r)
- {
- callback::SendReport<AuthenticationReport> auth_report;
-
- /*
-
- Here, we can try using this aria2c options - TODO
-
- --http-user=USER
- Set HTTP user. This affects all URLs.
-
- --http-passwd=PASSWD
- Set HTTP password. This affects all URLs.
- */
-
- //if (!_url.getUsername().empty() && !retry)
- // auth_data.setUserName(_url.getUsername());
-
- //string prompt_msg;
- //if (retry || !_url.getUsername().empty())
- // prompt_msg = _("Invalid user name or password.");
- //else // first prompt
- // prompt_msg = boost::str(boost::format(
- // _("Authentication required for '%s'")) % _url.asString());
-
- // set available authentication types from the exception
- //auth_data.setAuthType(ex_r.hint());
-
- //if (auth_report->prompt(_url, prompt_msg, auth_data))
- //{
- //DBG << "callback answer: retry" << endl
- // << "CurlAuthData: " << auth_data << endl;
-
- //if (auth_data.valid()) {
- //_userpwd = auth_data.getUserPwd();
-
- // set username and password
- //CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str());
- //if ( ret != 0 ) ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
-
- // set auth type
- //ret = curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, auth_data.authType());
- //if ( ret != 0 ) ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- //}
-
- //retry = true;
- //}
- //else
- //{
- // DBG << "callback answer: cancel" << endl;
- // report->finish(fileurl, zypp::media::DownloadProgressReport::ACCESS_DENIED, ex_r.asUserString());
- // ZYPP_RETHROW(ex_r);
- //}
- }
- // unexpected exception
- catch (MediaException & excpt_r)
- {
- // FIXME: error number fix
- report->finish(fileurl, zypp::media::DownloadProgressReport::ERROR, excpt_r.asUserString());
- ZYPP_RETHROW(excpt_r);
- }
- }
- while (retry);
-
- report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
-}
-
-bool MediaAria2c::getDoesFileExist( const Pathname & filename ) const
-{
- return true;
- /*
- bool retry = false;
- CurlAuthData auth_data;
-
- do
- {
- try
- {
- return doGetDoesFileExist( filename );
- }
- // authentication problem, retry with proper authentication data
- catch (MediaUnauthorizedException & ex_r)
- {
- callback::SendReport<AuthenticationReport> auth_report;
-
- if (!_url.getUsername().empty() && !retry)
- auth_data.setUserName(_url.getUsername());
-
- string prompt_msg;
- if (retry || !_url.getUsername().empty())
- prompt_msg = _("Invalid user name or password.");
- else // first prompt
- prompt_msg = boost::str(boost::format(
- _("Authentication required for '%s'")) % _url.asString());
-
- // set available authentication types from the exception
- auth_data.setAuthType(ex_r.hint());
-
- if (auth_report->prompt(_url, prompt_msg, auth_data))
- {
- DBG << "callback answer: retry" << endl
- << "CurlAuthData: " << auth_data << endl;
-
- if (auth_data.valid()) {
- _userpwd = auth_data.getUserPwd();
-
- // set username and password
- //CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str());
- //if ( ret != 0 ) ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
-
- // set auth type
- //ret = curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, auth_data.authType());
- //if ( ret != 0 ) ZYPP_THROW(MediaAria2cSetOptException(_url, _curlError));
- }
-
- retry = true;
- }
- else
- {
- DBG << "callback answer: cancel" << endl;
- ZYPP_RETHROW(ex_r);
- }
- }
- // unexpected exception
- catch (MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
- while (retry);
-
- return false;
-*/
-}
-
-/*
-bool MediaAria2c::doGetDoesFileExist( const Pathname & filename ) const
-{
-
- DBG << filename.asString() << endl;
-
- if(!_url.isValid())
- ZYPP_THROW(MediaBadUrlException(_url));
-
- if(_url.getHost().empty())
- ZYPP_THROW(MediaBadUrlEmptyHostException(_url));
-
- string path = _url.getPathName();
- if ( !path.empty() && path != "/" && *path.rbegin() == '/' &&
- filename.absolute() ) {
- // If url has a path with trailing slash, remove the leading slash from
- // the absolute file name
- path += filename.asString().substr( 1, filename.asString().size() - 1 );
- } else if ( filename.relative() ) {
- // Add trailing slash to path, if not already there
- if ( !path.empty() && *path.rbegin() != '/' ) path += "/";
- // Remove "./" from begin of relative file name
- path += filename.asString().substr( 2, filename.asString().size() - 2 );
- } else {
- path += filename.asString();
- }
-
- Url url( _url );
- url.setPathName( path );
-
- DBG << "URL: " << url.asString() << endl;
- // Use URL without options and without username and passwd
- // (some proxies dislike them in the URL).
- // Curl seems to need the just scheme, hostname and a path;
- // the rest was already passed as curl options (in attachTo).
- Url curlUrl( url );
-
- // Use asString + url::ViewOptions instead?
- curlUrl.setUsername( "" );
- curlUrl.setPassword( "" );
- curlUrl.setPathParams( "" );
- curlUrl.setQueryString( "" );
- curlUrl.setFragment( "" );
-
- //
- // See also Bug #154197 and ftp url definition in RFC 1738:
- // The url "ftp://user@host/foo/bar/file" contains a path,
- // that is relative to the user's home.
- // The url "ftp://user@host//foo/bar/file" (or also with
- // encoded slash as %2f) "ftp://user@host/%2ffoo/bar/file"
- // contains an absolute path.
- //
- string urlBuffer( curlUrl.asString());
- CURLcode ret = curl_easy_setopt( _curl, CURLOPT_URL,
- urlBuffer.c_str() );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaAria2cSetOptException(url, _curlError));
- }
-
- // instead of returning no data with NOBODY, we return
- // little data, that works with broken servers, and
- // works for ftp as well, because retrieving only headers
- // ftp will return always OK code ?
- if ( _url.getScheme() == "http" || _url.getScheme() == "https" )
- ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, 1 );
- else
- ret = curl_easy_setopt( _curl, CURLOPT_RANGE, "0-1" );
-
- if ( ret != 0 ) {
- curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
- yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
-
- curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- ZYPP_THROW(MediaAria2cSetOptException(url, _curlError));
- }
-
-
- FILE *file = ::fopen( "/dev/null", "w" );
- if ( !file ) {
- ::fclose(file);
- ERR << "fopen failed for /dev/null" << endl;
- curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
- yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
-
- curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaAria2cSetOptException(url, _curlError));
- }
- ZYPP_THROW(MediaWriteException("/dev/null"));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
- if ( ret != 0 ) {
- ::fclose(file);
- std::string err( _curlError);
- curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
- curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
-
- curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaAria2cSetOptException(url, _curlError));
- }
- ZYPP_THROW(MediaAria2cSetOptException(url, err));
- }
- // Set callback and perform.
- //ProgressData progressData(_xfer_timeout, url, &report);
- //report->start(url, dest);
- //if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, &progressData ) != 0 ) {
- // WAR << "Can't set CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- //}
-
- CURLcode ok = curl_easy_perform( _curl );
- MIL << "perform code: " << ok << " [ " << curl_easy_strerror(ok) << " ]" << endl;
-
- // reset curl settings
- if ( _url.getScheme() == "http" || _url.getScheme() == "https" )
- {
- ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
-
- ret = curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- }
- else
- ret = curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
-
- if ( ret != 0 )
- {
- ZYPP_THROW(MediaAria2cSetOptException(url, _curlError));
- }
-
- if ( ok != 0 )
- {
- ::fclose( file );
-
- std::string err;
- try
- {
- bool err_file_not_found = false;
- switch ( ok )
- {
- case CURLE_FTP_COULDNT_RETR_FILE:
- case CURLE_FTP_ACCESS_DENIED:
- err_file_not_found = true;
- break;
- case CURLE_HTTP_RETURNED_ERROR:
- {
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo( _curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode );
- if ( infoRet == CURLE_OK )
- {
- string msg = "HTTP response: " +
- str::numstring( httpReturnCode );
- if ( httpReturnCode == 401 )
- {
- std::string auth_hint = getAuthHint();
-
- DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl;
- DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl;
-
- ZYPP_THROW(MediaUnauthorizedException(
- url, "Login failed.", _curlError, auth_hint
- ));
- }
- else
- if ( httpReturnCode == 403)
- {
- ZYPP_THROW(MediaForbiddenException(url));
- }
- else
- if ( httpReturnCode == 404)
- {
- err_file_not_found = true;
- break;
- }
-
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaAria2cException(url, msg, _curlError));
- }
- else
- {
- string msg = "Unable to retrieve HTTP response:";
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaAria2cException(url, msg, _curlError));
- }
- }
- break;
- case CURLE_UNSUPPORTED_PROTOCOL:
- case CURLE_URL_MALFORMAT:
- case CURLE_URL_MALFORMAT_USER:
- case CURLE_BAD_PASSWORD_ENTERED:
- case CURLE_FTP_USER_PASSWORD_INCORRECT:
- err = "Login failed";
- break;
- case CURLE_COULDNT_RESOLVE_PROXY:
- case CURLE_COULDNT_RESOLVE_HOST:
- case CURLE_COULDNT_CONNECT:
- case CURLE_FTP_CANT_GET_HOST:
- err = "Connection failed";
- break;
- case CURLE_WRITE_ERROR:
- err = "Write error";
- break;
- case CURLE_ABORTED_BY_CALLBACK:
- case CURLE_OPERATION_TIMEOUTED:
- err = "Timeout reached";
- ZYPP_THROW(MediaTimeoutException(url));
- break;
- case CURLE_SSL_CACERT:
- ZYPP_THROW(MediaBadCAException(url,_curlError));
- case CURLE_SSL_PEER_CERTIFICATE:
- default:
- err = curl_easy_strerror(ok);
- if (err.empty())
- err = "Unrecognized error";
- break;
- }
-
- if( err_file_not_found)
- {
- // file does not exists
- return false;
- }
- else
- {
- // there was an error
- ZYPP_THROW(MediaAria2cException(url, string(), _curlError));
- }
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
-
- // exists
- return ( ok == CURLE_OK );
- //if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) {
- // WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- //}
-
-}
-*/
-
-/*
-void MediaAria2c::doGetFileCopy( const Pathname & filename , const Pathname & target, callback::SendReport<DownloadProgressReport> & report) const
-{
- DBG << filename.asString() << endl;
-
- if(!_url.isValid())
- ZYPP_THROW(MediaBadUrlException(_url));
-
- if(_url.getHost().empty())
- ZYPP_THROW(MediaBadUrlEmptyHostException(_url));
-
- Url url(getFileUrl(_url, filename));
-
- Pathname dest = target.absolutename();
- if( assert_dir( dest.dirname() ) )
- {
- DBG << "assert_dir " << dest.dirname() << " failed" << endl;
- ZYPP_THROW( MediaSystemException(url, "System error on " + dest.dirname().asString()) );
- }
-
- DBG << "URL: " << url.asString() << endl;
- // Use URL without options and without username and passwd
- // (some proxies dislike them in the URL).
- // Curl seems to need the just scheme, hostname and a path;
- // the rest was already passed as curl options (in attachTo).
- Url curlUrl( url );
-
- // Use asString + url::ViewOptions instead?
- curlUrl.setUsername( "" );
- curlUrl.setPassword( "" );
- curlUrl.setPathParams( "" );
- curlUrl.setQueryString( "" );
- curlUrl.setFragment( "" );
-
- //
- // See also Bug #154197 and ftp url definition in RFC 1738:
- // The url "ftp://user@host/foo/bar/file" contains a path,
- // that is relative to the user's home.
- // The url "ftp://user@host//foo/bar/file" (or also with
- // encoded slash as %2f) "ftp://user@host/%2ffoo/bar/file"
- // contains an absolute path.
- //
- string urlBuffer( curlUrl.asString());
- CURLcode ret = curl_easy_setopt( _curl, CURLOPT_URL,
- urlBuffer.c_str() );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaAria2cSetOptException(url, _curlError));
- }
-
- // set IFMODSINCE time condition (no download if not modified)
- curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
- curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, PathInfo(target).mtime());
-
- string destNew = target.asString() + ".new.zypp.XXXXXX";
- char *buf = ::strdup( destNew.c_str());
- if( !buf)
- {
- ERR << "out of memory for temp file name" << endl;
- ZYPP_THROW(MediaSystemException(
- url, "out of memory for temp file name"
- ));
- }
-
- int tmp_fd = ::mkstemp( buf );
- if( tmp_fd == -1)
- {
- free( buf);
- ERR << "mkstemp failed for file '" << destNew << "'" << endl;
- ZYPP_THROW(MediaWriteException(destNew));
- }
- destNew = buf;
- free( buf);
-
- FILE *file = ::fdopen( tmp_fd, "w" );
- if ( !file ) {
- ::close( tmp_fd);
- filesystem::unlink( destNew );
- ERR << "fopen failed for file '" << destNew << "'" << endl;
- ZYPP_THROW(MediaWriteException(destNew));
- }
-
- DBG << "dest: " << dest << endl;
- DBG << "temp: " << destNew << endl;
-
- ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
- if ( ret != 0 ) {
- ::fclose( file );
- filesystem::unlink( destNew );
- ZYPP_THROW(MediaAria2cSetOptException(url, _curlError));
- }
-
- // Set callback and perform.
- ProgressData progressData(_xfer_timeout, url, &report);
- report->start(url, dest);
- if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, &progressData ) != 0 ) {
- WAR << "Can't set CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- }
-
- ret = curl_easy_perform( _curl );
-
- if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) {
- WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- }
-
- if ( ret != 0 ) {
- ERR << "curl error: " << ret << ": " << _curlError
- << ", temp file size " << PathInfo(destNew).size()
- << " byte." << endl;
-
- ::fclose( file );
- filesystem::unlink( destNew );
-
- std::string err;
- try {
- bool err_file_not_found = false;
- switch ( ret ) {
- case CURLE_UNSUPPORTED_PROTOCOL:
- case CURLE_URL_MALFORMAT:
- case CURLE_URL_MALFORMAT_USER:
- err = " Bad URL";
- case CURLE_HTTP_RETURNED_ERROR:
- {
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo( _curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode );
- if ( infoRet == CURLE_OK ) {
- string msg = "HTTP response: " +
- str::numstring( httpReturnCode );
- if ( httpReturnCode == 401 )
- {
- std::string auth_hint = getAuthHint();
-
- DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl;
- DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl;
-
- ZYPP_THROW(MediaUnauthorizedException(
- url, "Login failed.", _curlError, auth_hint
- ));
- }
- else
- if ( httpReturnCode == 403)
- {
- ZYPP_THROW(MediaForbiddenException(url));
- }
- else
- if ( httpReturnCode == 404)
- {
- ZYPP_THROW(MediaFileNotFoundException(_url, filename));
- }
-
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaAria2cException(url, msg, _curlError));
- }
- else
- {
- string msg = "Unable to retrieve HTTP response:";
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaAria2cException(url, msg, _curlError));
- }
- }
- break;
- case CURLE_FTP_COULDNT_RETR_FILE:
- case CURLE_FTP_ACCESS_DENIED:
- err = "File not found";
- err_file_not_found = true;
- break;
- case CURLE_BAD_PASSWORD_ENTERED:
- case CURLE_FTP_USER_PASSWORD_INCORRECT:
- err = "Login failed";
- break;
- case CURLE_COULDNT_RESOLVE_PROXY:
- case CURLE_COULDNT_RESOLVE_HOST:
- case CURLE_COULDNT_CONNECT:
- case CURLE_FTP_CANT_GET_HOST:
- err = "Connection failed";
- break;
- case CURLE_WRITE_ERROR:
- err = "Write error";
- break;
- case CURLE_ABORTED_BY_CALLBACK:
- case CURLE_OPERATION_TIMEDOUT:
- if( progressData.reached)
- {
- err = "Timeout reached";
- ZYPP_THROW(MediaTimeoutException(url));
- }
- else
- {
- err = "User abort";
- }
- break;
- case CURLE_SSL_PEER_CERTIFICATE:
- default:
- err = "Unrecognized error";
- break;
- }
- if( err_file_not_found)
- {
- ZYPP_THROW(MediaFileNotFoundException(_url, filename));
- }
- else
- {
- ZYPP_THROW(MediaAria2cException(url, err, _curlError));
- }
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
-#if DETECT_DIR_INDEX
- else
- if(curlUrl.getScheme() == "http" ||
- curlUrl.getScheme() == "https")
- {
- //
- // try to check the effective url and set the not_a_file flag
- // if the url path ends with a "/", what usually means, that
- // we've received a directory index (index.html content).
- //
- // Note: This may be dangerous and break file retrieving in
- // case of some server redirections ... ?
- //
- bool not_a_file = false;
- char *ptr = NULL;
- CURLcode ret = curl_easy_getinfo( _curl,
- CURLINFO_EFFECTIVE_URL,
- &ptr);
- if ( ret == CURLE_OK && ptr != NULL)
- {
- try
- {
- Url eurl( ptr);
- std::string path( eurl.getPathName());
- if( !path.empty() && path != "/" && *path.rbegin() == '/')
- {
- DBG << "Effective url ("
- << eurl
- << ") seems to provide the index of a directory"
- << endl;
- not_a_file = true;
- }
- }
- catch( ... )
- {}
- }
-
- if( not_a_file)
- {
- ::fclose( file );
- filesystem::unlink( destNew );
- ZYPP_THROW(MediaNotAFileException(_url, filename));
- }
- }
-#endif // DETECT_DIR_INDEX
-
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo(_curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode);
- bool modified = true;
- if (infoRet == CURLE_OK)
- {
- DBG << "HTTP response: " + str::numstring(httpReturnCode);
- cout << "HTTP response: " + str::numstring(httpReturnCode);
- if ( httpReturnCode == 304 ) // not modified
- {
- DBG << " Not modified.";
- modified = false;
- }
- DBG << endl;
- }
- else
- {
- WAR << "Could not get the reponse code." << endl;
- }
-
- if (modified || infoRet != CURLE_OK)
- {
- // apply umask
- if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
- {
- ERR << "Failed to chmod file " << destNew << endl;
- }
- ::fclose( file );
-
- // move the temp file into dest
- if ( rename( destNew, dest ) != 0 ) {
- ERR << "Rename failed" << endl;
- ZYPP_THROW(MediaWriteException(dest));
- }
- }
- else
- {
- // close and remove the temp file
- ::fclose( file );
- filesystem::unlink( destNew );
- }
-
- DBG << "done: " << PathInfo(dest) << endl;
-}
-*/
-
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::getDir
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that media is attached
-//
-void MediaAria2c::getDir( const Pathname & dirname, bool recurse_r ) const
-{
- filesystem::DirContent content;
- getDirInfo( content, dirname, /*dots*/false );
-
- for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
- Pathname filename = dirname + it->name;
- int res = 0;
-
- switch ( it->type ) {
- case filesystem::FT_NOT_AVAIL: // old directory.yast contains no typeinfo at all
- case filesystem::FT_FILE:
- getFile( filename );
- break;
- case filesystem::FT_DIR: // newer directory.yast contain at least directory info
- if ( recurse_r ) {
- getDir( filename, recurse_r );
- } else {
- res = assert_dir( localPath( filename ) );
- if ( res ) {
- WAR << "Ignore error (" << res << ") on creating local directory '" << localPath( filename ) << "'" << endl;
- }
- }
- break;
- default:
- // don't provide devices, sockets, etc.
- break;
- }
- }
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::getDirInfo
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that media is attached and retlist is empty.
-//
-void MediaAria2c::getDirInfo( std::list<std::string> & retlist,
- const Pathname & dirname, bool dots ) const
-{
- getDirectoryYast( retlist, dirname, dots );
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::getDirInfo
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that media is attached and retlist is empty.
-//
-void MediaAria2c::getDirInfo( filesystem::DirContent & retlist,
- const Pathname & dirname, bool dots ) const
-{
- getDirectoryYast( retlist, dirname, dots );
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::getAria2cVersion
-//
-// DESCRIPTION : We get Aria2c version
-//
-std::string MediaAria2c::getAria2cVersion() {
-
- std::string ariaCommand = _aria2cPath.asString();
- ariaCommand.append( " --version" );
-
- ExternalProgram aria(ariaCommand, ExternalProgram::Stderr_To_Stdout);
-
- std::string vResponse = aria.receiveLine();
- return vResponse;
-
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaAria2c::progressCallback
-// METHOD TYPE : int
-//
-// DESCRIPTION : Progress callback triggered from MediaAria2c::getFile
-//
-/*
-int MediaAria2c::progressCallback( void *clientp,
- double dltotal, double dlnow,
- double ultotal, double ulnow)
-{
- ProgressData *pdata = reinterpret_cast<ProgressData *>(clientp);
- if( pdata)
- {
- time_t now = time(NULL);
- if( now > 0)
- {
- // reset time of last change in case initial time()
- // failed or the time was adjusted (goes backward)
- if( pdata->ltime <= 0 || pdata->ltime > now)
- {
- pdata->ltime = now;
- }
-
- // start time counting as soon as first data arrives
- // (skip the connection / redirection time at begin)
- time_t dif = 0;
- if (dlnow > 0 || ulnow > 0)
- {
- dif = (now - pdata->ltime);
- dif = dif > 0 ? dif : 0;
-
- pdata->secs += dif;
- }
-
- // update the drate_avg and drate_period only after a second has passed
- // (this callback is called much more often than a second)
- // otherwise the values would be far from accurate when measuring
- // the time in seconds
- //! \todo more accurate download rate computationn, e.g. compute average value from last 5 seconds, or work with milliseconds instead of seconds
-
- if ( pdata->secs > 1 && (dif > 0 || dlnow == dltotal ))
- pdata->drate_avg = (dlnow / pdata->secs);
-
- if ( dif > 0 )
- {
- pdata->drate_period = ((dlnow - pdata->dload_period) / dif);
- pdata->dload_period = dlnow;
- }
- }
-
- // send progress report first, abort transfer if requested
- if( pdata->report)
- {
- if (!(*(pdata->report))->progress(int( dlnow * 100 / dltotal ),
- pdata->url,
- pdata->drate_avg,
- pdata->drate_period))
- {
- return 1; // abort transfer
- }
- }
-
- // check if we there is a timeout set
- if( pdata->timeout > 0)
- {
- if( now > 0)
- {
- bool progress = false;
-
- // update download data if changed, mark progress
- if( dlnow != pdata->dload)
- {
- progress = true;
- pdata->dload = dlnow;
- pdata->ltime = now;
- }
- // update upload data if changed, mark progress
- if( ulnow != pdata->uload)
- {
- progress = true;
- pdata->uload = ulnow;
- pdata->ltime = now;
- }
-
- if( !progress && (now >= (pdata->ltime + pdata->timeout)))
- {
- pdata->reached = true;
- return 1; // aborts transfer
- }
- }
- }
- }
- return 0;
-}
-*/
-/*
-string MediaAria2c::getAuthHint() const
-{
- long auth_info = CURLAUTH_NONE;
-
- CURLcode infoRet =
- curl_easy_getinfo(_curl, CURLINFO_HTTPAUTH_AVAIL, &auth_info);
-
- if(infoRet == CURLE_OK)
- {
- return CurlAuthData::auth_type_long2str(auth_info);
- }
-
- return "";
-}*/
-
- } // namespace media
-} // namespace zypp
-//
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/media/MediaAria2c.h
- *
-*/
-#ifndef ZYPP_MEDIA_MEDIAARIA2C_H
-#define ZYPP_MEDIA_MEDIAARIA2C_H
-
-#include "zypp/media/MediaHandler.h"
-#include "zypp/ZYppCallbacks.h"
-
-namespace zypp {
- namespace media {
-
-///////////////////////////////////////////////////////////////////
-//
-// CLASS NAME : MediaAria2c
-/**
- * @short Implementation class for FTP, HTTP and HTTPS MediaHandler using an external program (aria2c) to retrive files
- * @author gfarrasb (gfarrasb@gmail.com)
- * @see MediaHandler
- **/
-class MediaAria2c : public MediaHandler {
-
- protected:
-
- virtual void attachTo (bool next = false);
- virtual void releaseFrom( const std::string & ejectDev );
- virtual void getFile( const Pathname & filename ) const;
- virtual void getDir( const Pathname & dirname, bool recurse_r ) const;
- virtual void getDirInfo( std::list<std::string> & retlist,
- const Pathname & dirname, bool dots = true ) const;
- virtual void getDirInfo( filesystem::DirContent & retlist,
- const Pathname & dirname, bool dots = true ) const;
- /**
- * Repeatedly calls doGetDoesFileExist() until it successfully returns,
- * fails unexpectedly, or user cancels the operation. This is used to
- * handle authentication or similar retry scenarios on media level.
- */
- virtual bool getDoesFileExist( const Pathname & filename ) const;
-
- /**
- * \see MediaHandler::getDoesFileExist
- */
- //virtual bool doGetDoesFileExist( const Pathname & filename ) const;
-
- /**
- *
- * \throws MediaException
- *
- */
- virtual void disconnectFrom();
- /**
- *
- * \throws MediaException
- *
- */
- virtual void getFileCopy( const Pathname & srcFilename, const Pathname & targetFilename) const;
-
- /**
- *
- * \throws MediaException
- *
- */
- //virtual void doGetFileCopy( const Pathname & srcFilename, const Pathname & targetFilename, callback::SendReport<DownloadProgressReport> & _report) const;
-
-
- virtual bool checkAttachPoint(const Pathname &apoint) const;
-
- public:
-
- MediaAria2c( const Url & url_r,
- const Pathname & attach_point_hint_r );
-
- virtual ~MediaAria2c() { try { release(); } catch(...) {} }
-
- //static void setCookieFile( const Pathname & );
-
- /* External process to get aria2c version - TODO */
- std::string getAria2cVersion();
-
- class Callbacks
- {
- public:
- virtual ~Callbacks() {}
- virtual bool progress( int percent ) = 0;
- };
-
- protected:
-
- //static int progressCallback( void *clientp, double dltotal, double dlnow,
- // double ultotal, double ulnow );
-
- /** The user agent string */
- static const char *const agentString();
-
-
- private:
- /**
- * Return a comma separated list of available authentication methods
- * supported by server.
- */
- //std::string getAuthHint() const;
-
-
-
- private:
- //CURL *_curl;
- //char _curlError[ CURL_ERROR_SIZE ];
- //long _curlDebug;
-
- mutable std::string _userpwd;
- std::string _proxy;
- std::string _proxyuserpwd;
- std::string _currentCookieFile;
- std::string _ca_path;
- long _xfer_timeout;
-
- static Pathname _cookieFile;
-
- /** Aria2c path */
- static Pathname _aria2cPath;
-};
-
-///////////////////////////////////////////////////////////////////
-
- } // namespace media
-} // namespace zypp
-
-#endif // ZYPP_MEDIA_MEDIAARIA2C_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/media/MediaException.cc
- *
-*/
-
-#include <iostream>
-
-#include "zypp/base/String.h"
-#include "zypp/base/Gettext.h"
-
-#include "zypp/media/MediaException.h"
-
-using namespace std;
-using zypp::str::form;
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- namespace media {
- /////////////////////////////////////////////////////////////////
-
- std::ostream & MediaMountException::dumpOn( std::ostream & str ) const
- {
- str << form(_("Failed to mount %s on %s"), _source.c_str(), _target.c_str());
- if( !_cmdout.empty())
- str << ": " << _error << " (" << _cmdout << ")" << endl;
- else
- str << ": " << _error << endl;
- return str;
- }
-
- std::ostream & MediaUnmountException::dumpOn( std::ostream & str ) const
- {
- return str << form(_("Failed to unmount %s"), _path.c_str())
- << " : " << _error << endl;
- }
-
- std::ostream & MediaBadFilenameException::dumpOn( std::ostream & str ) const
- {
- return str << form(_("Bad file name: %s"), _filename.c_str()) << endl;
- }
-
- std::ostream & MediaNotOpenException::dumpOn( std::ostream & str ) const
- {
- return str << form(
- _("Medium not opened when trying to perform action '%s'."), _action.c_str())
- << endl;
- }
-
- std::ostream & MediaFileNotFoundException::dumpOn( std::ostream & str) const
- {
- return str << form(
- _("File '%s' not found on medium '%s'"),
- _filename.c_str(), _url.c_str())
- << endl;
- }
-
- std::ostream & MediaWriteException::dumpOn( std::ostream & str) const
- {
- return str << form(_("Cannot write file '%s'."), _filename.c_str()) << endl;
- }
-
- std::ostream & MediaNotAttachedException::dumpOn( std::ostream & str) const
- {
- return str << _("Medium not attached") << ": " << _url << endl;
- }
-
- std::ostream & MediaBadAttachPointException::dumpOn( std::ostream & str) const
- {
- return str << _("Bad media attach point") << ": " << _url << endl;
- }
-
- std::ostream & MediaCurlInitException::dumpOn( std::ostream & str) const
- {
- return str << form(
- // TranslatorExplanation: curl is the name of a library, don't translate
- _("Download (curl) initialization failed for '%s'"), _url.c_str())
- << endl;
- }
-
- std::ostream & MediaMetalinkInitException::dumpOn( std::ostream & str) const
- {
- return str << form(
- // TranslatorExplanation: curl is the name of a library, don't translate
- _("Download (Metalink curl) initialization failed for '%s'"), _url.c_str())
- << endl;
- }
-
- std::ostream & MediaAria2cInitException::dumpOn( std::ostream & str) const
- {
- return str << form(
- // TranslatorExplanation: curl is the name of a library, don't translate
- _("Download (Metalink curl) initialization failed for '%s'"), _url.c_str())
- << endl;
- }
-
- std::ostream & MediaSystemException::dumpOn( std::ostream & str) const
- {
- return str << form(
- _("System exception '%s' on medium '%s'."),
- _message.c_str(), _url.c_str()) << endl;
- }
-
- std::ostream & MediaNotAFileException::dumpOn( std::ostream & str) const
- {
- return str << form(
- _("Path '%s' on medium '%s' is not a file."),
- _path.c_str(), _url.c_str())
- << endl;
- }
-
- std::ostream & MediaNotADirException::dumpOn( std::ostream & str) const
- {
- return str << form(
- _("Path '%s' on medium '%s' is not a directory."),
- _path.c_str(), _url.c_str())
- << endl;
- }
-
- std::ostream & MediaBadUrlException::dumpOn( std::ostream & str) const
- {
- if( _msg.empty())
- {
- return str << _("Malformed URI") << ": " << _url << endl;
- }
- else
- {
- return str << _msg << ": " << _url << endl;
- }
- }
-
- std::ostream & MediaBadUrlEmptyHostException::dumpOn( std::ostream & str) const
- {
- return str << _("Empty host name in URI") << ": " << _url << endl;
- }
-
- std::ostream & MediaBadUrlEmptyFilesystemException::dumpOn( std::ostream & str) const
- {
- return str << _("Empty filesystem in URI") << ": " << _url << endl;
- }
-
- std::ostream & MediaBadUrlEmptyDestinationException::dumpOn( std::ostream & str) const
- {
- return str << _("Empty destination in URI") << ": " << _url << endl;
- }
-
- std::ostream & MediaUnsupportedUrlSchemeException::dumpOn( std::ostream & str) const
- {
- return str << form(_("Unsupported URI scheme in '%s'."), _url.c_str()) << endl;
- }
-
- std::ostream & MediaNotSupportedException::dumpOn( std::ostream & str) const
- {
- return str << _("Operation not supported by medium") << ": " << _url << endl;
- }
-
- std::ostream & MediaCurlException::dumpOn( std::ostream & str) const
- {
- // TranslatorExplanation: curl is the name of a library, don't translate
- return str << form(_(
- "Download (curl) error for '%s':\n"
- "Error code: %s\n"
- "Error message: %s\n"), _url.c_str(), _err.c_str(), _msg.c_str());
- }
-
- std::ostream & MediaCurlSetOptException::dumpOn( std::ostream & str) const
- {
- return str << form(
- // TranslatorExplanation: curl is the name of a library, don't translate
- _("Error occurred while setting download (curl) options for '%s':"),
- _url.c_str())
- << endl << _msg << endl;
- }
-
- std::ostream & MediaMetalinkException::dumpOn( std::ostream & str) const
- {
- // TranslatorExplanation: curl is the name of a library, don't translate
- return str << form(_(
- "Download (metalink curl) error for '%s':\n"
- "Error code: %s\n"
- "Error message: %s\n"), _url.c_str(), _err.c_str(), _msg.c_str());
- }
-
- std::ostream & MediaMetalinkSetOptException::dumpOn( std::ostream & str) const
- {
- return str << form(
- // TranslatorExplanation: curl is the name of a library, don't translate
- _("Error occurred while setting download (metalink curl) options for '%s':"),
- _url.c_str())
- << endl << _msg << endl;
- }
-
- std::ostream & MediaAria2cException::dumpOn( std::ostream & str) const
- {
- // TranslatorExplanation: curl is the name of a library, don't translate
- return str << form(_(
- "Download (metalink curl) error for '%s':\n"
- "Error code: %s\n"
- "Error message: %s\n"), _url.c_str(), _err.c_str(), _msg.c_str());
- }
-
- std::ostream & MediaAria2cSetOptException::dumpOn( std::ostream & str) const
- {
- return str << form(
- // TranslatorExplanation: curl is the name of a library, don't translate
- _("Error occurred while setting download (metalink curl) options for '%s':"),
- _url.c_str())
- << endl << _msg << endl;
- }
-
- std::ostream & MediaNotDesiredException::dumpOn( std::ostream & str ) const
- {
- return str << form(
- _("Media source '%s' does not contain the desired medium"), _url.c_str())
- << endl;
- }
-
- std::ostream & MediaIsSharedException::dumpOn( std::ostream & str ) const
- {
- return str << form(_("Medium '%s' is in use by another instance"), _name.c_str())
- << endl;
- }
-
- std::ostream & MediaNotEjectedException::dumpOn( std::ostream & str ) const
- {
- if( _name.empty())
- return str << _("Cannot eject any media") << endl;
- else
- return str << form(_("Cannot eject media '%s'"), _name.c_str()) << endl;
- }
-
- std::ostream & MediaUnauthorizedException::dumpOn( std::ostream & str ) const
- {
- str << msg();
- if( !_url.asString().empty())
- str << " (" << _url << ")";
- if( !_err.empty())
- str << ": " << _err;
- return str;
- }
-
- std::ostream & MediaForbiddenException::dumpOn( std::ostream & str ) const
- {
- if (_msg.empty())
- return str << form(_("Permission to access '%s' denied."), _url.c_str()) << endl;
- return str << _msg << endl;
- }
-
- std::ostream & MediaTimeoutException::dumpOn( std::ostream & str ) const
- {
- if (_msg.empty())
- return str << form(_("Timeout exceed when access '%s'."), _url.c_str()) << endl;
- return str << _msg << endl;
- }
-
- std::ostream & MediaBadCAException::dumpOn( std::ostream & str ) const
- {
- if (_msg.empty())
- return str << form(_(" SSL certificate problem, verify that the CA cert is OK for '%s'."), _url.c_str()) << endl;
- return str << _msg << endl;
- }
- /////////////////////////////////////////////////////////////////
- } // namespace media
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/media/MediaException.h
- *
-*/
-#ifndef ZYPP_MEDIA_MEDIAEXCEPTION_H
-#define ZYPP_MEDIA_MEDIAEXCEPTION_H
-
-#include <iosfwd>
-
-#include <string>
-#include <vector>
-
-#include "zypp/base/Exception.h"
-#include "zypp/Pathname.h"
-#include "zypp/Url.h"
-
-///////////////////////////////////////////////////////////////////
-namespace zypp
-{ /////////////////////////////////////////////////////////////////
- namespace media {
- ///////////////////////////////////////////////////////////////
- //
- // CLASS NAME : MediaException
- /** Just inherits Exception to separate media exceptions
- *
- **/
- class MediaException : public Exception
- {
- public:
- /** Ctor taking message.
- * Use \ref ZYPP_THROW to throw exceptions.
- */
- MediaException() : Exception( "Media Exception" )
- {}
- /** Ctor taking message.
- * Use \ref ZYPP_THROW to throw exceptions.
- */
- MediaException( const std::string & msg_r )
- : Exception( msg_r )
- {}
-
- /** Dtor. */
- virtual ~MediaException() throw() {};
- };
-
- class MediaMountException : public MediaException
- {
- public:
- MediaMountException()
- : MediaException( "Media Mount Exception" )
- {}
-
- /** Ctor taking message.
- * Use \ref ZYPP_THROW to throw exceptions.
- */
- MediaMountException( const std::string & error_r,
- const std::string & source_r,
- const std::string & target_r,
- const std::string & cmdout_r="")
- : MediaException()
- , _error(error_r)
- , _source(source_r)
- , _target(target_r)
- , _cmdout(cmdout_r)
- {}
- /** Dtor. */
- virtual ~MediaMountException() throw() {};
-
- const std::string & mountError() const
- { return _error; }
- const std::string & mountSource() const
- { return _source; }
- const std::string & mountTarget() const
- { return _target; }
- const std::string & mountOutput() const
- { return _cmdout; }
-
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _error;
- std::string _source;
- std::string _target;
- std::string _cmdout;
- };
-
- class MediaUnmountException : public MediaException
- {
- public:
- /** Ctor taking message.
- * Use \ref ZYPP_THROW to throw exceptions.
- */
- MediaUnmountException( const std::string & error_r,
- const std::string & path_r )
- : MediaException()
- , _error(error_r)
- , _path(path_r)
- {}
- /** Dtor. */
- virtual ~MediaUnmountException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _error;
- std::string _path;
- };
-
- class MediaBadFilenameException : public MediaException
- {
- public:
- MediaBadFilenameException(const std::string & filename_r)
- : MediaException()
- , _filename(filename_r)
- {}
- virtual ~MediaBadFilenameException() throw() {};
- std::string filename() const { return _filename; }
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _filename;
- };
-
- class MediaNotOpenException : public MediaException
- {
- public:
- MediaNotOpenException(const std::string & action_r)
- : MediaException()
- , _action(action_r)
- {}
- virtual ~MediaNotOpenException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _action;
- };
-
- class MediaFileNotFoundException : public MediaException
- {
- public:
- MediaFileNotFoundException(const Url & url_r,
- const Pathname & filename_r)
- : MediaException()
- , _url(url_r.asString())
- , _filename(filename_r.asString())
- {}
- virtual ~MediaFileNotFoundException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- std::string _filename;
- };
-
- class MediaWriteException : public MediaException
- {
- public:
- MediaWriteException(const Pathname & filename_r)
- : MediaException()
- , _filename(filename_r.asString())
- {}
- virtual ~MediaWriteException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _filename;
- };
-
- class MediaNotAttachedException : public MediaException
- {
- public:
- MediaNotAttachedException(const Url & url_r)
- : MediaException()
- , _url(url_r.asString())
- {}
- virtual ~MediaNotAttachedException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- };
-
- class MediaBadAttachPointException : public MediaException
- {
- public:
- MediaBadAttachPointException(const Url & url_r)
- : MediaException()
- , _url(url_r.asString())
- {}
- virtual ~MediaBadAttachPointException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- };
-
- class MediaCurlInitException : public MediaException
- {
- public:
- MediaCurlInitException(const Url & url_r)
- : MediaException()
- , _url(url_r.asString())
- {}
- virtual ~MediaCurlInitException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- };
-
-class MediaMetalinkInitException : public MediaException
- {
- public:
- MediaMetalinkInitException(const Url & url_r)
- : MediaException()
- , _url(url_r.asString())
- {}
- virtual ~MediaMetalinkInitException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- };
-
-class MediaAria2cInitException : public MediaException
- {
- public:
- MediaAria2cInitException(const Url & url_r)
- : MediaException()
- , _url(url_r.asString())
- {}
- virtual ~MediaAria2cInitException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- };
-
- class MediaSystemException : public MediaException
- {
- public:
- MediaSystemException(const Url & url_r,
- const std::string & message_r)
- : MediaException()
- , _url(url_r.asString())
- , _message(message_r)
- {}
- virtual ~MediaSystemException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- std::string _message;
- };
-
- class MediaNotAFileException : public MediaException
- {
- public:
- MediaNotAFileException(const Url & url_r,
- const Pathname & path_r)
- : MediaException()
- , _url(url_r.asString())
- , _path(path_r.asString())
- {}
- virtual ~MediaNotAFileException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- std::string _path;
- };
-
- class MediaNotADirException : public MediaException
- {
- public:
- MediaNotADirException(const Url & url_r,
- const Pathname & path_r)
- : MediaException()
- , _url(url_r.asString())
- , _path(path_r.asString())
- {}
- virtual ~MediaNotADirException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- std::string _path;
- };
-
- class MediaBadUrlException : public MediaException
- {
- public:
- MediaBadUrlException(const Url & url_r,
- const std::string &msg_r = std::string())
- : MediaException()
- , _url(url_r.asString())
- , _msg(msg_r)
- {}
- virtual ~MediaBadUrlException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _msg;
- };
-
- class MediaBadUrlEmptyHostException : public MediaBadUrlException
- {
- public:
- MediaBadUrlEmptyHostException(const Url & url_r)
- : MediaBadUrlException(url_r)
- {}
- virtual ~MediaBadUrlEmptyHostException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- };
-
- class MediaBadUrlEmptyFilesystemException : public MediaBadUrlException
- {
- public:
- MediaBadUrlEmptyFilesystemException(const Url & url_r)
- : MediaBadUrlException(url_r)
- {}
- virtual ~MediaBadUrlEmptyFilesystemException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- };
-
- class MediaBadUrlEmptyDestinationException : public MediaBadUrlException
- {
- public:
- MediaBadUrlEmptyDestinationException(const Url & url_r)
- : MediaBadUrlException(url_r)
- {}
- virtual ~MediaBadUrlEmptyDestinationException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- };
-
- class MediaUnsupportedUrlSchemeException : public MediaBadUrlException
- {
- public:
- MediaUnsupportedUrlSchemeException(const Url & url_r)
- : MediaBadUrlException(url_r)
- {}
- virtual ~MediaUnsupportedUrlSchemeException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- };
-
- class MediaNotSupportedException : public MediaException
- {
- public:
- MediaNotSupportedException(const Url & url_r)
- : MediaException()
- , _url(url_r.asString())
- {}
- virtual ~MediaNotSupportedException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- };
-
- class MediaCurlException : public MediaException
- {
- public:
- MediaCurlException(const Url & url_r,
- const std::string & err_r,
- const std::string & msg_r)
- : MediaException()
- , _url(url_r.asString())
- , _err(err_r)
- , _msg(msg_r)
- {}
- virtual ~MediaCurlException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _err;
- std::string _msg;
- };
-
- class MediaCurlSetOptException : public MediaException
- {
- public:
- MediaCurlSetOptException(const Url & url_r, const std::string & msg_r)
- : MediaException()
- , _url(url_r.asString())
- , _msg(msg_r)
- {}
- virtual ~MediaCurlSetOptException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _msg;
- };
-
- class MediaMetalinkException : public MediaException
- {
- public:
- MediaMetalinkException(const Url & url_r,
- const std::string & err_r,
- const std::string & msg_r)
- : MediaException()
- , _url(url_r.asString())
- , _err(err_r)
- , _msg(msg_r)
- {}
- virtual ~MediaMetalinkException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _err;
- std::string _msg;
- };
-
- class MediaMetalinkSetOptException : public MediaException
- {
- public:
- MediaMetalinkSetOptException(const Url & url_r, const std::string & msg_r)
- : MediaException()
- , _url(url_r.asString())
- , _msg(msg_r)
- {}
- virtual ~MediaMetalinkSetOptException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _msg;
- };
-
- class MediaAria2cException : public MediaException
- {
- public:
- MediaAria2cException(const Url & url_r,
- const std::string & err_r,
- const std::string & msg_r)
- : MediaException()
- , _url(url_r.asString())
- , _err(err_r)
- , _msg(msg_r)
- {}
- virtual ~MediaAria2cException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _err;
- std::string _msg;
- };
-
- class MediaAria2cSetOptException : public MediaException
- {
- public:
- MediaAria2cSetOptException(const Url & url_r, const std::string & msg_r)
- : MediaException()
- , _url(url_r.asString())
- , _msg(msg_r)
- {}
- virtual ~MediaAria2cSetOptException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _msg;
- };
-
- class MediaNotDesiredException : public MediaException
- {
- public:
- MediaNotDesiredException(const Url & url_r)
- : MediaException()
- , _url(url_r.asString())
- {}
- virtual ~MediaNotDesiredException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _url;
- };
-
- class MediaIsSharedException : public MediaException
- {
- public:
- /**
- * \param name A media source as string (see MediaSource class).
- */
- MediaIsSharedException(const std::string &name)
- : MediaException()
- , _name(name)
- {}
- virtual ~MediaIsSharedException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _name;
- };
-
- class MediaNotEjectedException: public MediaException
- {
- public:
- MediaNotEjectedException()
- : MediaException("Can't eject any media")
- , _name("")
- {}
-
- MediaNotEjectedException(const std::string &name)
- : MediaException("Can't eject media")
- , _name(name)
- {}
- virtual ~MediaNotEjectedException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- std::string _name;
- };
-
- class MediaUnauthorizedException: public MediaException
- {
- public:
- MediaUnauthorizedException()
- : MediaException("Unauthorized media access")
- , _url("")
- , _err("")
- , _hint("")
- {}
-
- MediaUnauthorizedException(const Url &url_r,
- const std::string &msg_r,
- const std::string &err_r,
- const std::string &hint_r)
- : MediaException(msg_r)
- , _url(url_r)
- , _err(err_r)
- , _hint(hint_r)
- {}
-
- virtual ~MediaUnauthorizedException() throw() {};
-
- const Url & url() const { return _url; }
- const std::string & err() const { return _err; }
- /** comma separated list of available authentication types */
- const std::string & hint() const { return _hint; }
-
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- private:
- Url _url;
- std::string _err;
- std::string _hint;
- };
-
- class MediaForbiddenException : public MediaException
- {
- public:
- MediaForbiddenException(const Url & url_r, const std::string & msg = "")
- : MediaException(msg)
- , _url(url_r.asString()), _msg(msg)
- {}
- virtual ~MediaForbiddenException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _msg;
- };
-
- class MediaTimeoutException : public MediaException
- {
- public:
- MediaTimeoutException(const Url & url_r, const std::string & msg = "Timeout exceed")
- : MediaException(msg)
- , _url(url_r.asString()), _msg(msg)
- {}
- virtual ~MediaTimeoutException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _msg;
- };
-
- class MediaBadCAException : public MediaException
- {
- public:
- MediaBadCAException(const Url & url_r, const std::string & msg = "Invalid CA")
- : MediaException(msg)
- , _url(url_r.asString()), _msg(msg)
- {}
- virtual ~MediaBadCAException() throw() {};
- protected:
- virtual std::ostream & dumpOn( std::ostream & str ) const;
- std::string _url;
- std::string _msg;
- };
- /////////////////////////////////////////////////////////////////
- } // namespace media
-} // namespace zypp
-///////////////////////////////////////////////////////////////////
-#endif // ZYPP_MEDIA_MEDIAEXCEPTION_H
+++ /dev/null
-/*---------------------------------------------------------------------\
-| ____ _ __ __ ___ |
-| |__ / \ / / . \ . \ |
-| / / \ V /| _/ _/ |
-| / /__ | | | | | | |
-| /_____||_| |_| |_| |
-| |
-\---------------------------------------------------------------------*/
-/** \file zypp/media/MediaMetalink.cc
- *
-*/
-
-#include <iostream>
-#include <list>
-
-#include "zypp/base/Logger.h"
-#include "zypp/ExternalProgram.h"
-#include "zypp/base/String.h"
-#include "zypp/base/Gettext.h"
-#include "zypp/base/Sysconfig.h"
-#include "zypp/base/Gettext.h"
-
-#include "zypp/media/MediaMetalink.h"
-#include "zypp/media/proxyinfo/ProxyInfos.h"
-#include "zypp/media/ProxyInfo.h"
-#include "zypp/media/MediaUserAuth.h"
-#include "zypp/media/CurlConfig.h"
-#include "zypp/thread/Once.h"
-#include <cstdlib>
-#include <sys/types.h>
-#include <sys/stat.h>
-#include <sys/mount.h>
-#include <errno.h>
-#include <dirent.h>
-#include <unistd.h>
-#include <boost/format.hpp>
-
-#define DETECT_DIR_INDEX 0
-#define CONNECT_TIMEOUT 60
-#define TRANSFER_TIMEOUT 60 * 3
-#define TRANSFER_TIMEOUT_MAX 60 * 60
-
-
-using namespace std;
-using namespace zypp::base;
-
-namespace
-{
- zypp::thread::OnceFlag g_InitOnceFlag = PTHREAD_ONCE_INIT;
- zypp::thread::OnceFlag g_FreeOnceFlag = PTHREAD_ONCE_INIT;
-
- extern "C" void _do_free_metalink_once()
- {
- curl_global_cleanup();
- }
-
- extern "C" void globalMetalinkFreeOnce()
- {
- zypp::thread::callOnce(g_FreeOnceFlag, _do_free_metalink_once);
- }
-
- extern "C" void _do_init_metalink_once()
- {
- CURLcode ret = curl_global_init( CURL_GLOBAL_ALL );
- if ( ret != 0 )
- {
- WAR << "curl global init failed" << endl;
- }
-
- //
- // register at exit handler ?
- // this may cause trouble, because we can protect it
- // against ourself only.
- // if the app sets an atexit handler as well, it will
- // cause a double free while the second of them runs.
- //
- //std::atexit( globalFreeOnce);
- }
-
- inline void globalInitOnce()
- {
- zypp::thread::callOnce(g_InitOnceFlag, _do_init_metalink_once);
- }
-
- int log_curl(CURL *curl, curl_infotype info,
- char *ptr, size_t len, void *max_lvl)
- {
- std::string pfx(" ");
- long lvl = 0;
- switch( info)
- {
- case CURLINFO_TEXT: lvl = 1; pfx = "*"; break;
- case CURLINFO_HEADER_IN: lvl = 2; pfx = "<"; break;
- case CURLINFO_HEADER_OUT: lvl = 2; pfx = ">"; break;
- default: break;
- }
- if( lvl > 0 && max_lvl != NULL && lvl <= *((long *)max_lvl))
- {
- std::string msg(ptr, len);
- std::list<std::string> lines;
- std::list<std::string>::const_iterator line;
- zypp::str::split(msg, std::back_inserter(lines), "\r\n");
- for(line = lines.begin(); line != lines.end(); ++line)
- {
- DBG << pfx << " " << *line << endl;
- }
- }
- return 0;
- }
-}
-
-namespace zypp {
- namespace media {
-
- namespace {
- struct ProgressData
- {
- ProgressData(const long _timeout, const zypp::Url &_url = zypp::Url(),
- callback::SendReport<DownloadProgressReport> *_report=NULL)
- : timeout(_timeout)
- , reached(false)
- , report(_report)
- , drate_period(-1)
- , dload_period(0)
- , secs(0)
- , drate_avg(-1)
- , ltime( time(NULL))
- , dload( 0)
- , uload( 0)
- , url(_url)
- {}
- long timeout;
- bool reached;
- callback::SendReport<DownloadProgressReport> *report;
- // download rate of the last period (cca 1 sec)
- double drate_period;
- // bytes downloaded at the start of the last period
- double dload_period;
- // seconds from the start of the download
- long secs;
- // average download rate
- double drate_avg;
- // last time the progress was reported
- time_t ltime;
- // bytes downloaded at the moment the progress was last reported
- double dload;
- // bytes uploaded at the moment the progress was last reported
- double uload;
- zypp::Url url;
- };
-
- ///////////////////////////////////////////////////////////////////
-
- inline void escape( string & str_r,
- const char char_r, const string & escaped_r ) {
- for ( string::size_type pos = str_r.find( char_r );
- pos != string::npos; pos = str_r.find( char_r, pos ) ) {
- str_r.replace( pos, 1, escaped_r );
- }
- }
-
- inline string escapedPath( string path_r ) {
- escape( path_r, ' ', "%20" );
- return path_r;
- }
-
- inline string unEscape( string text_r ) {
- char * tmp = curl_unescape( text_r.c_str(), 0 );
- string ret( tmp );
- curl_free( tmp );
- return ret;
- }
-
- }
-
-///////////////////////////////////////////////////////////////////
-//
-// CLASS NAME : MediaMetalink
-//
-///////////////////////////////////////////////////////////////////
-
-Pathname MediaMetalink::_cookieFile = "/var/lib/YaST2/cookies";
-
-const char *const MediaMetalink::agentString()
-{
- /*
- static const std::string _value( str::form( "ZYpp %s (curl %s)",
- VERSION,
- curl_version_info(CURLVERSION_NOW)->version ) );
- */
- static const std::string _value( str::form( "ZYpp %s (MediaMetalink - with curl %s & libmetalink )",
- VERSION,
- curl_version_info(CURLVERSION_NOW)->version ) );
- return _value.c_str();
-}
-
-
-MediaMetalink::MediaMetalink( const Url & url_r,
- const Pathname & attach_point_hint_r )
- : MediaHandler( url_r, attach_point_hint_r,
- "/", // urlpath at attachpoint
- true ), // does_download
- _curl( NULL )
-{
- _curlError[0] = '\0';
- _curlDebug = 0L;
-
- //GSoC -- Initialize number of mirrors
- numberofmirrors = 0;
-
- globalInitOnce();
-
- if( !attachPoint().empty())
- {
- PathInfo ainfo(attachPoint());
- Pathname apath(attachPoint() + "XXXXXX");
- char *atemp = ::strdup( apath.asString().c_str());
- char *atest = NULL;
- if( !ainfo.isDir() || !ainfo.userMayRWX() ||
- atemp == NULL || (atest=::mkdtemp(atemp)) == NULL)
- {
- WAR << "attach point " << ainfo.path()
- << " is not useable for " << url_r.getScheme() << endl;
- setAttachPoint("", true);
- }
- else if( atest != NULL)
- ::rmdir(atest);
-
- if( atemp != NULL)
- ::free(atemp);
- }
-}
-
-void MediaMetalink::setCookieFile( const Pathname &fileName )
-{
- _cookieFile = fileName;
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaMetalink::attachTo
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that not already attached, and attachPoint is a directory.
-//
-void MediaMetalink::attachTo (bool next)
-{
- if ( next )
- ZYPP_THROW(MediaNotSupportedException(_url));
-
- if ( !_url.isValid() )
- ZYPP_THROW(MediaBadUrlException(_url));
-
- CurlConfig curlconf;
- CurlConfig::parseConfig(curlconf); // parse ~/.curlrc
-
- curl_version_info_data *curl_info = NULL;
- curl_info = curl_version_info(CURLVERSION_NOW);
- // curl_info does not need any free (is static)
- if (curl_info->protocols)
- {
- const char * const *proto;
- std::string scheme( _url.getScheme());
- bool found = false;
- for(proto=curl_info->protocols; !found && *proto; ++proto)
- {
- if( scheme == std::string((const char *)*proto))
- found = true;
- }
- if( !found)
- {
- std::string msg("Unsupported protocol '");
- msg += scheme;
- msg += "'";
- ZYPP_THROW(MediaBadUrlException(_url, msg));
- }
- }
-
- if( !isUseableAttachPoint(attachPoint()))
- {
- std::string mountpoint = createAttachPoint().asString();
-
- if( mountpoint.empty())
- ZYPP_THROW( MediaBadAttachPointException(url()));
-
- setAttachPoint( mountpoint, true);
- }
-
- disconnectFrom(); // clean _curl if needed
- _curl = curl_easy_init();
- if ( !_curl ) {
- ZYPP_THROW(MediaMetalinkInitException(_url));
- }
-
- {
- char *ptr = getenv("ZYPP_MEDIA_CURL_DEBUG");
- _curlDebug = (ptr && *ptr) ? str::strtonum<long>( ptr) : 0L;
- if( _curlDebug > 0)
- {
- curl_easy_setopt( _curl, CURLOPT_VERBOSE, 1);
- curl_easy_setopt( _curl, CURLOPT_DEBUGFUNCTION, log_curl);
- curl_easy_setopt( _curl, CURLOPT_DEBUGDATA, &_curlDebug);
- }
- }
-
- CURLcode ret = curl_easy_setopt( _curl, CURLOPT_ERRORBUFFER, _curlError );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, "Error setting error buffer"));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_FAILONERROR, true );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_NOSIGNAL, 1 );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- /**
- * Transfer timeout
- */
- {
- _xfer_timeout = TRANSFER_TIMEOUT;
-
- std::string param(_url.getQueryParam("timeout"));
- if( !param.empty())
- {
- long num = str::strtonum<long>( param);
- if( num >= 0 && num <= TRANSFER_TIMEOUT_MAX)
- _xfer_timeout = num;
- }
- }
-
- /*
- ** Connect timeout
- */
- ret = curl_easy_setopt( _curl, CURLOPT_CONNECTTIMEOUT, CONNECT_TIMEOUT);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- if ( _url.getScheme() == "http" ) {
- // follow any Location: header that the server sends as part of
- // an HTTP header (#113275)
- ret = curl_easy_setopt ( _curl, CURLOPT_FOLLOWLOCATION, true );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
- ret = curl_easy_setopt ( _curl, CURLOPT_MAXREDIRS, 3L );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt ( _curl, CURLOPT_USERAGENT, agentString() );
-
-
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
- }
-
- if ( _url.getScheme() == "https" )
- {
- bool verify_peer = false;
- bool verify_host = false;
-
- std::string verify( _url.getQueryParam("ssl_verify"));
- if( verify.empty() ||
- verify == "yes")
- {
- verify_peer = true;
- verify_host = true;
- }
- else
- if( verify == "no")
- {
- verify_peer = false;
- verify_host = false;
- }
- else
- {
- std::vector<std::string> flags;
- std::vector<std::string>::const_iterator flag;
- str::split( verify, std::back_inserter(flags), ",");
- for(flag = flags.begin(); flag != flags.end(); ++flag)
- {
- if( *flag == "host")
- {
- verify_host = true;
- }
- else
- if( *flag == "peer")
- {
- verify_peer = true;
- }
- else
- {
- disconnectFrom();
- ZYPP_THROW(MediaBadUrlException(_url, "Unknown ssl_verify flag"));
- }
- }
- }
-
- _ca_path = Pathname(_url.getQueryParam("ssl_capath")).asString();
- if( _ca_path.empty())
- {
- _ca_path = "/etc/ssl/certs/";
- }
- else
- if( !PathInfo(_ca_path).isDir() || !Pathname(_ca_path).absolute())
- {
- disconnectFrom();
- ZYPP_THROW(MediaBadUrlException(_url, "Invalid ssl_capath path"));
- }
-
- if( verify_peer || verify_host)
- {
- ret = curl_easy_setopt( _curl, CURLOPT_CAPATH, _ca_path.c_str());
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYPEER, verify_peer ? 1L : 0L);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
- ret = curl_easy_setopt( _curl, CURLOPT_SSL_VERIFYHOST, verify_host ? 2L : 0L);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt ( _curl, CURLOPT_USERAGENT, agentString() );
- if ( ret != 0) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
- }
-
-
- /*---------------------------------------------------------------*
- CURLOPT_USERPWD: [user name]:[password]
-
- Url::username/password -> CURLOPT_USERPWD
- If not provided, anonymous FTP identification
- *---------------------------------------------------------------*/
-
- if ( _url.getUsername().empty() ) {
- if ( _url.getScheme() == "ftp" ) {
- string id = "yast2@";
- id += VERSION;
- DBG << "Anonymous FTP identification: '" << id << "'" << endl;
- _userpwd = "anonymous:" + id;
- }
- } else {
- _userpwd = _url.getUsername();
- if ( _url.getPassword().size() ) {
- _userpwd += ":" + _url.getPassword();
- }
- }
-
- if ( _userpwd.size() ) {
- _userpwd = unEscape( _userpwd );
- ret = curl_easy_setopt( _curl, CURLOPT_USERPWD, _userpwd.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- // HTTP authentication type
- if(_url.getScheme() == "http" || _url.getScheme() == "https")
- {
- string use_auth = _url.getQueryParam("auth");
- if( use_auth.empty())
- use_auth = "digest,basic";
-
- try
- {
- long auth = CurlAuthData::auth_type_str2long(use_auth);
- if( auth != CURLAUTH_NONE)
- {
- DBG << "Enabling HTTP authentication methods: " << use_auth
- << " (CURLOPT_HTTPAUTH=" << auth << ")" << std::endl;
-
- ret = curl_easy_setopt( _curl, CURLOPT_HTTPAUTH, auth);
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
- }
- }
- catch (MediaException & ex_r)
- {
- string auth_hint = getAuthHint();
-
- DBG << "Rethrowing as MediaUnauthorizedException. auth hint: '"
- << auth_hint << "'" << endl;
-
- ZYPP_THROW(MediaUnauthorizedException(
- _url, ex_r.msg(), _curlError, auth_hint
- ));
- }
- }
- }
-
- /*---------------------------------------------------------------*
- CURLOPT_PROXY: host[:port]
-
- Url::option(proxy and proxyport) -> CURLOPT_PROXY
- If not provided, /etc/sysconfig/proxy is evaluated
- *---------------------------------------------------------------*/
-
- _proxy = _url.getQueryParam( "proxy" );
-
- if ( ! _proxy.empty() ) {
- string proxyport( _url.getQueryParam( "proxyport" ) );
- if ( ! proxyport.empty() ) {
- _proxy += ":" + proxyport;
- }
- } else {
-
- ProxyInfo proxy_info (ProxyInfo::ImplPtr(new ProxyInfoSysconfig("proxy")));
-
- if ( proxy_info.enabled())
- {
- bool useproxy = true;
-
- std::list<std::string> nope = proxy_info.noProxy();
- for (ProxyInfo::NoProxyIterator it = proxy_info.noProxyBegin();
- it != proxy_info.noProxyEnd();
- it++)
- {
- std::string host( str::toLower(_url.getHost()));
- std::string temp( str::toLower(*it));
-
- // no proxy if it points to a suffix
- // preceeded by a '.', that maches
- // the trailing portion of the host.
- if( temp.size() > 1 && temp.at(0) == '.')
- {
- if(host.size() > temp.size() &&
- host.compare(host.size() - temp.size(), temp.size(), temp) == 0)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
- else
- // no proxy if we have an exact match
- if( host == temp)
- {
- DBG << "NO_PROXY: '" << *it << "' matches host '"
- << host << "'" << endl;
- useproxy = false;
- break;
- }
- }
-
- if ( useproxy ) {
- _proxy = proxy_info.proxy(_url.getScheme());
- }
- }
- }
-
-
- DBG << "Proxy: " << (_proxy.empty() ? "-none-" : _proxy) << endl;
-
- if ( ! _proxy.empty() ) {
-
- ret = curl_easy_setopt( _curl, CURLOPT_PROXY, _proxy.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- /*---------------------------------------------------------------*
- CURLOPT_PROXYUSERPWD: [user name]:[password]
-
- Url::option(proxyuser and proxypassword) -> CURLOPT_PROXYUSERPWD
- If not provided, $HOME/.curlrc is evaluated
- *---------------------------------------------------------------*/
-
- _proxyuserpwd = _url.getQueryParam( "proxyuser" );
-
- if ( ! _proxyuserpwd.empty() ) {
- string proxypassword( _url.getQueryParam( "proxypassword" ) );
- if ( ! proxypassword.empty() ) {
- _proxyuserpwd += ":" + proxypassword;
- }
- } else {
- if (curlconf.proxyuserpwd.empty())
- DBG << "~/.curlrc does not contain the proxy-user option" << endl;
- else
- {
- _proxyuserpwd = curlconf.proxyuserpwd;
- DBG << "using proxy-user from ~/.curlrc" << endl;
- }
- }
-
- _proxyuserpwd = unEscape( _proxyuserpwd );
- ret = curl_easy_setopt( _curl, CURLOPT_PROXYUSERPWD, _proxyuserpwd.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
- }
-
- /*---------------------------------------------------------------*
- *---------------------------------------------------------------*/
-
- _currentCookieFile = _cookieFile.asString();
-
- ret = curl_easy_setopt( _curl, CURLOPT_COOKIEFILE,
- _currentCookieFile.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_COOKIEJAR,
- _currentCookieFile.c_str() );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_PROGRESSFUNCTION,
- &progressCallback );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_NOPROGRESS, false );
- if ( ret != 0 ) {
- disconnectFrom();
- ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- // FIXME: need a derived class to propelly compare url's
- MediaSourceRef media( new MediaSource(_url.getScheme(), _url.asString()));
- setMediaSource(media);
-}
-
-bool
-MediaMetalink::checkAttachPoint(const Pathname &apoint) const
-{
- return MediaHandler::checkAttachPoint( apoint, true, true);
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaMetalink::disconnectFrom
-// METHOD TYPE : PMError
-//
-void MediaMetalink::disconnectFrom()
-{
- if ( _curl )
- {
- curl_easy_cleanup( _curl );
- _curl = NULL;
- }
-}
-
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaMetalink::releaseFrom
-// METHOD TYPE : void
-//
-// DESCRIPTION : Asserted that media is attached.
-//
-void MediaMetalink::releaseFrom( const std::string & ejectDev )
-{
- disconnect();
-}
-
-static Url getFileUrl(const Url & url, const Pathname & filename) {
-
- //GSoC -- getFileUrl debug
- //cout << "Metalink::getFileUrl(" << url << " , " << filename << " );" << endl;
-
- Url newurl(url);
- string path = url.getPathName();
- if ( !path.empty() && path != "/" && *path.rbegin() == '/' &&
- filename.absolute() )
- {
- // If url has a path with trailing slash, remove the leading slash from
- // the absolute file name
- path += filename.asString().substr( 1, filename.asString().size() - 1 );
- }
- else if ( filename.relative() )
- {
- // Add trailing slash to path, if not already there
- if (path.empty()) path = "/";
- else if (*path.rbegin() != '/' ) path += "/";
- // Remove "./" from begin of relative file name
- path += filename.asString().substr( 2, filename.asString().size() - 2 );
- }
- else
- {
- path += filename.asString();
- }
-
- newurl.setPathName(path);
- return newurl;
-}
-
-
-///////////////////////////////////////////////////////////////////
-//
-// METHOD NAME : MediaMetalink::getFile
-// METHOD TYPE : void
-//
-void MediaMetalink::getFile( const Pathname & filename ) const
-{
-
- //GSoC -- first, we will try to get .metalink file via getMetalinkFileCopy wich returns a boolean
- cout << endl << endl << "--------------------" << endl << "getFile ( " << filename << " ) " << endl;
- bool exists = getMetalinkFileCopy(filename.extend(".metalink"), localPath(filename).absolutename().extend(".metalink"));
-
- if (exists) {
- cout << "Metalink file exists - We can parse it ;-) " << endl;
- metalink_t* metalink;
- metalink_file_t* file;
- metalink_resource_t** resources;
- //metalink_checksum_t** checksums;
- metalink_parse_file( localPath(filename).absolutename().extend(".metalink").asString().c_str() , &metalink);
- file = metalink->files[0];
-
- //cout << "Name of metalink file " << file->name << endl;
- //cout << "Size of metalink file " << file->size << endl;
-
- numberofmirrors = 0;
- mirrortotry = 0;
- if(file->resources) {
- int count = 0;
- resources = file->resources;
- while(*resources) {
-
- //cout << "type= " << (*resources)->type << ", location= " << (*resources)->location << ", preference= " << (*resources)->preference << " url=" << (*resources)->url << endl;
-
- if (count < 100) {
- std::string a((*resources)->url );
- Url metalinkUrl(a);
- alternativeUrl[count] = metalinkUrl;
- numberofmirrors++;
-
- }
-
- ++resources;
- ++count;
- }
- }
-
- /* delete metalink_t */
- delete_metalink(metalink);
- //GSoC -- process to get .metalink file finished
- }
-
- //Tornem a fer un getFileCopy
- // Use absolute file name to prevent access of files outside of the
- // hierarchy below the attach point.
- getFileCopy(filename, localPath(filename).absolutename());
-
- //GSoC -- we don't have any mirror for this file
- numberofmirrors = 0;
-
-}
-
-
-///////////////////////////////////////////////////////////////////
-//
-// METHOD NAME : MediaMetalink::getFileCopy
-// METHOD TYPE : void
-//
-void MediaMetalink::getFileCopy( const Pathname & filename , const Pathname & target) const
-{
- callback::SendReport<DownloadProgressReport> report;
-
- //Url fileurl(getFileUrl(_url, filename));
- Url fileurl;
- bool retry = false;
- CurlAuthData auth_data;
-
- do
- {
- ////GSoC -- if we have mirrors, fileurl would use 1st mirror
- /*
- if (numberofmirrors > 0) {
- fileurl = (getFileUrl(alternativeUrl[0], filename));
- } else {
- fileurl = (getFileUrl(_url, filename));
- }
-
- cout << "We will use " << fileurl << endl;
- */
-
- try
- {
- doGetFileCopy(filename, target, report);
- retry = false;
- }
- // retry with proper authentication data
- catch (MediaUnauthorizedException & ex_r)
- {
- callback::SendReport<AuthenticationReport> auth_report;
-
- if (!_url.getUsername().empty() && !retry)
- auth_data.setUserName(_url.getUsername());
-
- string prompt_msg;
- if (retry || !_url.getUsername().empty())
- prompt_msg = _("Invalid user name or password.");
- else // first prompt
- prompt_msg = boost::str(boost::format(
- _("Authentication required for '%s'")) % _url.asString());
-
- // set available authentication types from the exception
- auth_data.setAuthType(ex_r.hint());
-
- if (auth_report->prompt(_url, prompt_msg, auth_data))
- {
- DBG << "callback answer: retry" << endl
- << "CurlAuthData: " << auth_data << endl;
-
- if (auth_data.valid()) {
- _userpwd = auth_data.getUserPwd();
-
- // set username and password
- CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str());
- if ( ret != 0 ) ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
-
- // set auth type
- ret = curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, auth_data.authType());
- if ( ret != 0 ) ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- retry = true;
- }
- else
- {
- DBG << "callback answer: cancel" << endl;
- report->finish(fileurl, zypp::media::DownloadProgressReport::ACCESS_DENIED, ex_r.asUserString());
- ZYPP_RETHROW(ex_r);
- }
- }
- // unexpected exception
- catch (MediaException & excpt_r)
- {
- // FIXME: error number fix
- report->finish(fileurl, zypp::media::DownloadProgressReport::ERROR, excpt_r.asUserString());
- ZYPP_RETHROW(excpt_r);
- }
- }
- while (retry);
-
- report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
-}
-
-///////////////////////////////////////////////////////////////////
-//
-// METHOD NAME : MediaMetalink::getMetalinkFileCopy
-// METHOD TYPE : void
-// Comment: Function idem to getFileCopy, but returning boolean if file exists
-//
-bool MediaMetalink::getMetalinkFileCopy( const Pathname & filename , const Pathname & target) const
-{
-
- callback::SendReport<DownloadProgressReport> report;
-
- //Url fileurl(getFileUrl(_url, filename));
- Url fileurl;
- bool retry = false;
- CurlAuthData auth_data;
-
-
- fileurl = (getFileUrl(_url, filename));
- bool l = doGetMetalinkFileCopy(filename, target, report);
- return l;
-
- //retry = false;
- //}
- // retry with proper authentication data
- /*
- catch (MediaUnauthorizedException & ex_r)
- {
- callback::SendReport<AuthenticationReport> auth_report;
-
- if (!_url.getUsername().empty() && !retry)
- auth_data.setUserName(_url.getUsername());
-
- string prompt_msg;
- if (retry || !_url.getUsername().empty())
- prompt_msg = _("Invalid user name or password.");
- else // first prompt
- prompt_msg = boost::str(boost::format(
- _("Authentication required for '%s'")) % _url.asString());
-
- // set available authentication types from the exception
- auth_data.setAuthType(ex_r.hint());
-
- if (auth_report->prompt(_url, prompt_msg, auth_data))
- {
- DBG << "callback answer: retry" << endl
- << "CurlAuthData: " << auth_data << endl;
-
- if (auth_data.valid()) {
- _userpwd = auth_data.getUserPwd();
-
- // set username and password
- CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str());
- if ( ret != 0 ) ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
-
- // set auth type
- ret = curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, auth_data.authType());
- if ( ret != 0 ) ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- retry = true;
- }
- else
- {
- DBG << "callback answer: cancel" << endl;
- report->finish(fileurl, zypp::media::DownloadProgressReport::ACCESS_DENIED, ex_r.asUserString());
- ZYPP_RETHROW(ex_r);
- }
- }
- // unexpected exception
- catch (MediaException & excpt_r)
- {
- // FIXME: error number fix
- report->finish(fileurl, zypp::media::DownloadProgressReport::ERROR, excpt_r.asUserString());
- ZYPP_RETHROW(excpt_r);
- }
- }
- while (retry);
- */
-
- //report->finish(fileurl, zypp::media::DownloadProgressReport::NO_ERROR, "");
-}
-
-
-
-
-bool MediaMetalink::getDoesFileExist( const Pathname & filename ) const
-{
-
- bool retry = false;
- CurlAuthData auth_data;
-
- do
- {
- try
- {
- return doGetDoesFileExist( filename );
- }
- // authentication problem, retry with proper authentication data
- catch (MediaUnauthorizedException & ex_r)
- {
- callback::SendReport<AuthenticationReport> auth_report;
-
- if (!_url.getUsername().empty() && !retry)
- auth_data.setUserName(_url.getUsername());
-
- string prompt_msg;
- if (retry || !_url.getUsername().empty())
- prompt_msg = _("Invalid user name or password.");
- else // first prompt
- prompt_msg = boost::str(boost::format(
- _("Authentication required for '%s'")) % _url.asString());
-
- // set available authentication types from the exception
- auth_data.setAuthType(ex_r.hint());
-
- if (auth_report->prompt(_url, prompt_msg, auth_data))
- {
- DBG << "callback answer: retry" << endl
- << "CurlAuthData: " << auth_data << endl;
-
- if (auth_data.valid()) {
- _userpwd = auth_data.getUserPwd();
-
- // set username and password
- CURLcode ret = curl_easy_setopt(_curl, CURLOPT_USERPWD, _userpwd.c_str());
- if ( ret != 0 ) ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
-
- // set auth type
- ret = curl_easy_setopt(_curl, CURLOPT_HTTPAUTH, auth_data.authType());
- if ( ret != 0 ) ZYPP_THROW(MediaMetalinkSetOptException(_url, _curlError));
- }
-
- retry = true;
- }
- else
- {
- DBG << "callback answer: cancel" << endl;
- ZYPP_RETHROW(ex_r);
- }
- }
- // unexpected exception
- catch (MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
- while (retry);
-
- return false;
-}
-
-bool MediaMetalink::doGetDoesFileExist( const Pathname & filename ) const
-{
- cout << "Metalink::doGetDoesFileExist(" << filename << " ) function;" << endl;
- DBG << filename.asString() << endl;
-
- if(!_url.isValid())
- ZYPP_THROW(MediaBadUrlException(_url));
-
- if(_url.getHost().empty())
- ZYPP_THROW(MediaBadUrlEmptyHostException(_url));
-
- string path = _url.getPathName();
- if ( !path.empty() && path != "/" && *path.rbegin() == '/' &&
- filename.absolute() ) {
- // If url has a path with trailing slash, remove the leading slash from
- // the absolute file name
- path += filename.asString().substr( 1, filename.asString().size() - 1 );
- } else if ( filename.relative() ) {
- // Add trailing slash to path, if not already there
- if ( !path.empty() && *path.rbegin() != '/' ) path += "/";
- // Remove "./" from begin of relative file name
- path += filename.asString().substr( 2, filename.asString().size() - 2 );
- } else {
- path += filename.asString();
- }
-
- Url url( _url );
- url.setPathName( path );
-
- DBG << "URL: " << url.asString() << endl;
- // Use URL without options and without username and passwd
- // (some proxies dislike them in the URL).
- // Curl seems to need the just scheme, hostname and a path;
- // the rest was already passed as curl options (in attachTo).
- Url curlUrl( url );
-
- // Use asString + url::ViewOptions instead?
- curlUrl.setUsername( "" );
- curlUrl.setPassword( "" );
- curlUrl.setPathParams( "" );
- curlUrl.setQueryString( "" );
- curlUrl.setFragment( "" );
-
- //
- // See also Bug #154197 and ftp url definition in RFC 1738:
- // The url "ftp://user@host/foo/bar/file" contains a path,
- // that is relative to the user's home.
- // The url "ftp://user@host//foo/bar/file" (or also with
- // encoded slash as %2f) "ftp://user@host/%2ffoo/bar/file"
- // contains an absolute path.
- //
- string urlBuffer( curlUrl.asString());
- cout << "doGetDoesFileExist - Descarreguem de " << urlBuffer.c_str() << endl;
- CURLcode ret = curl_easy_setopt( _curl, CURLOPT_URL,
- urlBuffer.c_str() );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaMetalinkSetOptException(url, _curlError));
- }
-
- // instead of returning no data with NOBODY, we return
- // little data, that works with broken servers, and
- // works for ftp as well, because retrieving only headers
- // ftp will return always OK code ?
- if ( _url.getScheme() == "http" || _url.getScheme() == "https" )
- ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, 1 );
- else
- ret = curl_easy_setopt( _curl, CURLOPT_RANGE, "0-1" );
-
- if ( ret != 0 ) {
- curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
- /* yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
- */
- curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- ZYPP_THROW(MediaMetalinkSetOptException(url, _curlError));
- }
-
-
- FILE *file = ::fopen( "/dev/null", "w" );
- if ( !file ) {
- ::fclose(file);
- ERR << "fopen failed for /dev/null" << endl;
- curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
- /* yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
- */
- curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaMetalinkSetOptException(url, _curlError));
- }
- ZYPP_THROW(MediaWriteException("/dev/null"));
- }
-
- ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
- if ( ret != 0 ) {
- ::fclose(file);
- std::string err( _curlError);
- curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
- curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- /* yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
- */
- curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaMetalinkSetOptException(url, _curlError));
- }
- ZYPP_THROW(MediaMetalinkSetOptException(url, err));
- }
- // Set callback and perform.
- //ProgressData progressData(_xfer_timeout, url, &report);
- //report->start(url, dest);
- //if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, &progressData ) != 0 ) {
- // WAR << "Can't set CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- //}
-
- CURLcode ok = curl_easy_perform( _curl );
- MIL << "perform code: " << ok << " [ " << curl_easy_strerror(ok) << " ]" << endl;
-
- // reset curl settings
- if ( _url.getScheme() == "http" || _url.getScheme() == "https" )
- {
- ret = curl_easy_setopt( _curl, CURLOPT_NOBODY, NULL );
- /* yes, this is why we never got to get NOBODY working before,
- because setting it changes this option too, and we also
- need to reset it
- See: http://curl.haxx.se/mail/archive-2005-07/0073.html
- */
- ret = curl_easy_setopt( _curl, CURLOPT_HTTPGET, 1 );
- }
- else
- ret = curl_easy_setopt( _curl, CURLOPT_RANGE, NULL );
-
- if ( ret != 0 )
- {
- ZYPP_THROW(MediaMetalinkSetOptException(url, _curlError));
- }
-
- if ( ok != 0 )
- {
- ::fclose( file );
-
- std::string err;
- try
- {
- bool err_file_not_found = false;
- switch ( ok )
- {
- case CURLE_FTP_COULDNT_RETR_FILE:
- case CURLE_FTP_ACCESS_DENIED:
- err_file_not_found = true;
- break;
- case CURLE_HTTP_RETURNED_ERROR:
- {
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo( _curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode );
- if ( infoRet == CURLE_OK )
- {
- string msg = "HTTP response: " +
- str::numstring( httpReturnCode );
- if ( httpReturnCode == 401 )
- {
- std::string auth_hint = getAuthHint();
-
- DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl;
- DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl;
-
- ZYPP_THROW(MediaUnauthorizedException(
- url, "Login failed.", _curlError, auth_hint
- ));
- }
- else
- if ( httpReturnCode == 403)
- {
- ZYPP_THROW(MediaForbiddenException(url));
- }
- else
- if ( httpReturnCode == 404)
- {
- err_file_not_found = true;
- break;
- }
-
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaMetalinkException(url, msg, _curlError));
- }
- else
- {
- string msg = "Unable to retrieve HTTP response:";
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaMetalinkException(url, msg, _curlError));
- }
- }
- break;
- case CURLE_UNSUPPORTED_PROTOCOL:
- case CURLE_URL_MALFORMAT:
- case CURLE_URL_MALFORMAT_USER:
- case CURLE_BAD_PASSWORD_ENTERED:
- case CURLE_FTP_USER_PASSWORD_INCORRECT:
- err = "Login failed";
- break;
- case CURLE_COULDNT_RESOLVE_PROXY:
- case CURLE_COULDNT_RESOLVE_HOST:
- case CURLE_COULDNT_CONNECT:
- case CURLE_FTP_CANT_GET_HOST:
- err = "Connection failed";
- break;
- case CURLE_WRITE_ERROR:
- err = "Write error";
- break;
- case CURLE_ABORTED_BY_CALLBACK:
- case CURLE_OPERATION_TIMEOUTED:
- err = "Timeout reached";
- ZYPP_THROW(MediaTimeoutException(url));
- break;
- case CURLE_SSL_CACERT:
- ZYPP_THROW(MediaBadCAException(url,_curlError));
- case CURLE_SSL_PEER_CERTIFICATE:
- default:
- err = curl_easy_strerror(ok);
- if (err.empty())
- err = "Unrecognized error";
- break;
- }
-
- if( err_file_not_found)
- {
- // file does not exists
- return false;
- }
- else
- {
- // there was an error
- ZYPP_THROW(MediaMetalinkException(url, string(), _curlError));
- }
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
-
- // exists
- return ( ok == CURLE_OK );
- //if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) {
- // WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- //}
-}
-
-void MediaMetalink::doGetFileCopy( const Pathname & filename , const Pathname & target, callback::SendReport<DownloadProgressReport> & report) const
-{
- DBG << filename.asString() << endl;
-
- if(!_url.isValid())
- ZYPP_THROW(MediaBadUrlException(_url));
-
- if(_url.getHost().empty())
- ZYPP_THROW(MediaBadUrlEmptyHostException(_url));
-
- Url url(getFileUrl(_url, filename));
-
- Pathname dest = target.absolutename();
- if( assert_dir( dest.dirname() ) )
- {
- DBG << "assert_dir " << dest.dirname() << " failed" << endl;
- ZYPP_THROW( MediaSystemException(url, "System error on " + dest.dirname().asString()) );
- }
-
- DBG << "URL: " << url.asString() << endl;
- // Use URL without options and without username and passwd
- // (some proxies dislike them in the URL).
- // Curl seems to need the just scheme, hostname and a path;
- // the rest was already passed as curl options (in attachTo).
- Url curlUrl( url );
-
- // Use asString + url::ViewOptions instead?
- curlUrl.setUsername( "" );
- curlUrl.setPassword( "" );
- curlUrl.setPathParams( "" );
- curlUrl.setQueryString( "" );
- curlUrl.setFragment( "" );
-
- //
- // See also Bug #154197 and ftp url definition in RFC 1738:
- // The url "ftp://user@host/foo/bar/file" contains a path,
- // that is relative to the user's home.
- // The url "ftp://user@host//foo/bar/file" (or also with
- // encoded slash as %2f) "ftp://user@host/%2ffoo/bar/file"
- // contains an absolute path.
- //
-
- cout << "We have " << numberofmirrors << " mirrors for this file" << endl;
- if (numberofmirrors > 0 ) {
- curlUrl = alternativeUrl[ mirrortotry ] ;
- //cout << "Ok. Em canviat de mirror " << endl;
- }
-
- string urlBuffer( curlUrl.asString());
- cout << "Downloading from " << urlBuffer.c_str() << endl;
-
- CURLcode ret = curl_easy_setopt( _curl, CURLOPT_URL,
- urlBuffer.c_str() );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
- }
-
- // set IFMODSINCE time condition (no download if not modified)
- //curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
- //curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, PathInfo(target).mtime());
-
- string destNew = target.asString() + ".new.zypp.XXXXXX";
- char *buf = ::strdup( destNew.c_str());
- if( !buf)
- {
- ERR << "out of memory for temp file name" << endl;
- ZYPP_THROW(MediaSystemException(
- url, "out of memory for temp file name"
- ));
- }
-
- int tmp_fd = ::mkstemp( buf );
- if( tmp_fd == -1)
- {
- free( buf);
- ERR << "mkstemp failed for file '" << destNew << "'" << endl;
- ZYPP_THROW(MediaWriteException(destNew));
- }
- destNew = buf;
- free( buf);
-
- FILE *file = ::fdopen( tmp_fd, "w" );
- if ( !file ) {
- ::close( tmp_fd);
- filesystem::unlink( destNew );
- ERR << "fopen failed for file '" << destNew << "'" << endl;
- ZYPP_THROW(MediaWriteException(destNew));
- }
-
- DBG << "dest: " << dest << endl;
- DBG << "temp: " << destNew << endl;
-
- ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
- if ( ret != 0 ) {
- ::fclose( file );
- filesystem::unlink( destNew );
- ZYPP_THROW(MediaCurlSetOptException(url, _curlError));
- }
-
- // Set callback and perform.
- ProgressData progressData(_xfer_timeout, url, &report);
- report->start(url, dest);
- if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, &progressData ) != 0 ) {
- WAR << "Can't set CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- }
-
- ret = curl_easy_perform( _curl );
-
- if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) {
- WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- }
-
- if ( ret != 0 ) {
- ERR << "curl error: " << ret << ": " << _curlError
- << ", temp file size " << PathInfo(destNew).size()
- << " byte." << endl;
-
- ::fclose( file );
- filesystem::unlink( destNew );
-
- std::string err;
- try {
- bool err_file_not_found = false;
- switch ( ret ) {
- case CURLE_UNSUPPORTED_PROTOCOL:
- case CURLE_URL_MALFORMAT:
- case CURLE_URL_MALFORMAT_USER:
- err = " Bad URL";
- case CURLE_HTTP_RETURNED_ERROR:
- {
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo( _curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode );
- if ( infoRet == CURLE_OK ) {
- string msg = "HTTP response: " +
- str::numstring( httpReturnCode );
- if ( httpReturnCode == 401 )
- {
- std::string auth_hint = getAuthHint();
-
- DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl;
- DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl;
-
- ZYPP_THROW(MediaUnauthorizedException(
- url, "Login failed.", _curlError, auth_hint
- ));
- }
- else
- if ( httpReturnCode == 403)
- {
- ZYPP_THROW(MediaForbiddenException(url));
- }
- else
- if ( httpReturnCode == 404)
- {
- ZYPP_THROW(MediaFileNotFoundException(_url, filename));
- }
-
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaCurlException(url, msg, _curlError));
- }
- else
- {
- string msg = "Unable to retrieve HTTP response:";
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaCurlException(url, msg, _curlError));
- }
- }
- break;
- case CURLE_FTP_COULDNT_RETR_FILE:
- case CURLE_FTP_ACCESS_DENIED:
- err = "File not found";
- err_file_not_found = true;
- break;
- case CURLE_BAD_PASSWORD_ENTERED:
- case CURLE_FTP_USER_PASSWORD_INCORRECT:
- err = "Login failed";
- break;
- case CURLE_COULDNT_RESOLVE_PROXY:
- case CURLE_COULDNT_RESOLVE_HOST:
- case CURLE_COULDNT_CONNECT:
- case CURLE_FTP_CANT_GET_HOST:
- err = "Connection failed";
- break;
- case CURLE_WRITE_ERROR:
- err = "Write error";
- break;
- case CURLE_ABORTED_BY_CALLBACK:
- case CURLE_OPERATION_TIMEDOUT:
- if( progressData.reached)
- {
- err = "Timeout reached";
- ZYPP_THROW(MediaTimeoutException(url));
- }
- else
- {
- err = "User abort";
- }
- break;
- case CURLE_SSL_PEER_CERTIFICATE:
- default:
- err = "Unrecognized error";
- break;
- }
- if( err_file_not_found)
- {
- ZYPP_THROW(MediaFileNotFoundException(_url, filename));
- }
- else
- {
- ZYPP_THROW(MediaCurlException(url, err, _curlError));
- }
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
-#if DETECT_DIR_INDEX
- else
- if(curlUrl.getScheme() == "http" ||
- curlUrl.getScheme() == "https")
- {
- //
- // try to check the effective url and set the not_a_file flag
- // if the url path ends with a "/", what usually means, that
- // we've received a directory index (index.html content).
- //
- // Note: This may be dangerous and break file retrieving in
- // case of some server redirections ... ?
- //
- bool not_a_file = false;
- char *ptr = NULL;
- CURLcode ret = curl_easy_getinfo( _curl,
- CURLINFO_EFFECTIVE_URL,
- &ptr);
- if ( ret == CURLE_OK && ptr != NULL)
- {
- try
- {
- Url eurl( ptr);
- std::string path( eurl.getPathName());
- if( !path.empty() && path != "/" && *path.rbegin() == '/')
- {
- DBG << "Effective url ("
- << eurl
- << ") seems to provide the index of a directory"
- << endl;
- not_a_file = true;
- }
- }
- catch( ... )
- {}
- }
-
- if( not_a_file)
- {
- ::fclose( file );
- filesystem::unlink( destNew );
- ZYPP_THROW(MediaNotAFileException(_url, filename));
- }
- }
-#endif // DETECT_DIR_INDEX
-
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo(_curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode);
- bool modified = true;
- if (infoRet == CURLE_OK)
- {
- DBG << "HTTP response: " + str::numstring(httpReturnCode);
- cout << "HTTP response: " + str::numstring(httpReturnCode) << endl;
- if ( httpReturnCode == 304 ) // not modified
- {
- DBG << " Not modified.";
- modified = false;
- }
- DBG << endl;
- }
- else
- {
- WAR << "Could not get the reponse code." << endl;
- }
-
- if (modified || infoRet != CURLE_OK)
- {
- // apply umask
- if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
- {
- ERR << "Failed to chmod file " << destNew << endl;
- }
- ::fclose( file );
-
- // move the temp file into dest
- if ( rename( destNew, dest ) != 0 ) {
- ERR << "Rename failed" << endl;
- ZYPP_THROW(MediaWriteException(dest));
- }
- }
- else
- {
- // close and remove the temp file
- ::fclose( file );
- filesystem::unlink( destNew );
- }
-
- DBG << "done: " << PathInfo(dest) << endl;
- cout << "done: " << PathInfo(dest) << endl;
-}
-
-
-/* We try to get MEtalink file */
-bool MediaMetalink::doGetMetalinkFileCopy( const Pathname & filename , const Pathname & target, callback::SendReport<DownloadProgressReport> & report) const
-{
- if(!_url.isValid())
- ZYPP_THROW(MediaBadUrlException(_url));
-
- if(_url.getHost().empty())
- ZYPP_THROW(MediaBadUrlEmptyHostException(_url));
-
- Url url(getFileUrl(_url, filename));
-
-
- Pathname dest = target.absolutename();
- if( assert_dir( dest.dirname() ) )
- {
- DBG << "assert_dir " << dest.dirname() << " failed" << endl;
- ZYPP_THROW( MediaSystemException(url, "System error on " + dest.dirname().asString()) );
- }
-
- DBG << "URL: " << url.asString() << endl;
- //cout << "URL: " << url.asString() << endl;
- // Use URL without options and without username and passwd
- // (some proxies dislike them in the URL).
- // Curl seems to need the just scheme, hostname and a path;
- // the rest was already passed as curl options (in attachTo).
- Url curlUrl( url );
-
- // Use asString + url::ViewOptions instead?
- curlUrl.setUsername( "" );
- curlUrl.setPassword( "" );
- curlUrl.setPathParams( "" );
- curlUrl.setQueryString( "" );
- curlUrl.setFragment( "" );
-
- //
- // See also Bug #154197 and ftp url definition in RFC 1738:
- // The url "ftp://user@host/foo/bar/file" contains a path,
- // that is relative to the user's home.
- // The url "ftp://user@host//foo/bar/file" (or also with
- // encoded slash as %2f) "ftp://user@host/%2ffoo/bar/file"
- // contains an absolute path.
- //
- string urlBuffer( curlUrl.asString());
- cout << "doGetMetalinkFileCopy - Descarreguem des de " << urlBuffer.c_str() << endl;
- CURLcode ret = curl_easy_setopt( _curl, CURLOPT_URL,
- urlBuffer.c_str() );
- if ( ret != 0 ) {
- ZYPP_THROW(MediaMetalinkSetOptException(url, _curlError));
- }
-
- // set IFMODSINCE time condition (no download if not modified)
- //curl_easy_setopt(_curl, CURLOPT_TIMECONDITION, CURL_TIMECOND_IFMODSINCE);
- //curl_easy_setopt(_curl, CURLOPT_TIMEVALUE, PathInfo(target).mtime());
-
- string destNew = target.asString() + ".new.zypp.XXXXXX";
- //cout << "DestNew " << destNew << endl;
- char *buf = ::strdup( destNew.c_str());
- if( !buf)
- {
- ERR << "out of memory for temp file name" << endl;
- ZYPP_THROW(MediaSystemException(
- url, "out of memory for temp file name"
- ));
- }
-
- int tmp_fd = ::mkstemp( buf );
- if( tmp_fd == -1)
- {
- free( buf);
- ERR << "mkstemp failed for file '" << destNew << "'" << endl;
- ZYPP_THROW(MediaWriteException(destNew));
- }
- destNew = buf;
- free( buf);
-
- FILE *file = ::fdopen( tmp_fd, "w" );
- if ( !file ) {
- ::close( tmp_fd);
- filesystem::unlink( destNew );
- ERR << "fopen failed for file '" << destNew << "'" << endl;
- ZYPP_THROW(MediaWriteException(destNew));
- }
-
- DBG << "dest: " << dest << endl;
- DBG << "temp: " << destNew << endl;
-
- ret = curl_easy_setopt( _curl, CURLOPT_WRITEDATA, file );
- if ( ret != 0 ) {
- ::fclose( file );
- filesystem::unlink( destNew );
- ZYPP_THROW(MediaMetalinkSetOptException(url, _curlError));
- }
-
- // Set callback and perform.
- ProgressData progressData(_xfer_timeout, url, &report);
- report->start(url, dest);
- if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, &progressData ) != 0 ) {
- WAR << "Can't set CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- }
-
- ret = curl_easy_perform( _curl );
-
- if ( curl_easy_setopt( _curl, CURLOPT_PROGRESSDATA, NULL ) != 0 ) {
- WAR << "Can't unset CURLOPT_PROGRESSDATA: " << _curlError << endl;;
- }
-
- if ( ret != 0 ) {
- ERR << "curl error: " << ret << ": " << _curlError
- << ", temp file size " << PathInfo(destNew).size()
- << " byte." << endl;
-
- cout << "curl error: " << ret << ": " << _curlError
- << ", temp file size " << PathInfo(destNew).size()
- << " byte." << endl;
-
- ::fclose( file );
- filesystem::unlink( destNew );
- cout << "Metalink file NOT exists :-(" << endl;
- return false;
- } else {
-
- ::fclose( file );
-
- if ( rename( destNew, dest ) != 0 ) {
- ERR << "Rename failed" << endl;
- ZYPP_THROW(MediaWriteException(dest));
- }
-
- filesystem::unlink( destNew );
- //cout << "Metalink file exists!!" << endl;
- return true;
-
- }
- /*
- std::string err;
- try {
- bool err_file_not_found = false;
- switch ( ret ) {
- case CURLE_UNSUPPORTED_PROTOCOL:
- case CURLE_URL_MALFORMAT:
- case CURLE_URL_MALFORMAT_USER:
- err = " Bad URL";
- case CURLE_HTTP_RETURNED_ERROR:
- {
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo( _curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode );
- if ( infoRet == CURLE_OK ) {
- string msg = "HTTP response: " +
- str::numstring( httpReturnCode );
- if ( httpReturnCode == 401 )
- {
- std::string auth_hint = getAuthHint();
-
- DBG << msg << " Login failed (URL: " << url.asString() << ")" << std::endl;
- DBG << "MediaUnauthorizedException auth hint: '" << auth_hint << "'" << std::endl;
-
- ZYPP_THROW(MediaUnauthorizedException(
- url, "Login failed.", _curlError, auth_hint
- ));
- }
- else
- if ( httpReturnCode == 403)
- {
- ZYPP_THROW(MediaForbiddenException(url));
- //return 403;
- }
- else
- if ( httpReturnCode == 404)
- {
- ZYPP_THROW(MediaFileNotFoundException(_url, filename));
- //return 404;
- }
-
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaMetalinkException(url, msg, _curlError));
- }
- else
- {
- string msg = "Unable to retrieve HTTP response:";
- msg += err;
- DBG << msg << " (URL: " << url.asString() << ")" << std::endl;
- ZYPP_THROW(MediaMetalinkException(url, msg, _curlError));
- }
- }
- break;
- case CURLE_FTP_COULDNT_RETR_FILE:
- case CURLE_FTP_ACCESS_DENIED:
- err = "File not found";
- err_file_not_found = true;
- break;
- case CURLE_BAD_PASSWORD_ENTERED:
- case CURLE_FTP_USER_PASSWORD_INCORRECT:
- err = "Login failed";
- break;
- case CURLE_COULDNT_RESOLVE_PROXY:
- case CURLE_COULDNT_RESOLVE_HOST:
- case CURLE_COULDNT_CONNECT:
- case CURLE_FTP_CANT_GET_HOST:
- err = "Connection failed";
- break;
- case CURLE_WRITE_ERROR:
- err = "Write error";
- break;
- case CURLE_ABORTED_BY_CALLBACK:
- case CURLE_OPERATION_TIMEDOUT:
- if( progressData.reached)
- {
- err = "Timeout reached";
- ZYPP_THROW(MediaTimeoutException(url));
- }
- else
- {
- err = "User abort";
- }
- break;
- case CURLE_SSL_PEER_CERTIFICATE:
- default:
- err = "Unrecognized error";
- break;
- }
- if( err_file_not_found)
- {
- ZYPP_THROW(MediaFileNotFoundException(_url, filename));
- }
- else
- {
- ZYPP_THROW(MediaMetalinkException(url, err, _curlError));
- }
- }
- catch (const MediaException & excpt_r)
- {
- ZYPP_RETHROW(excpt_r);
- }
- }
-#if DETECT_DIR_INDEX
- else
- if(curlUrl.getScheme() == "http" ||
- curlUrl.getScheme() == "https")
- {
- //
- // try to check the effective url and set the not_a_file flag
- // if the url path ends with a "/", what usually means, that
- // we've received a directory index (index.html content).
- //
- // Note: This may be dangerous and break file retrieving in
- // case of some server redirections ... ?
- //
- bool not_a_file = false;
- char *ptr = NULL;
- CURLcode ret = curl_easy_getinfo( _curl,
- CURLINFO_EFFECTIVE_URL,
- &ptr);
- if ( ret == CURLE_OK && ptr != NULL)
- {
- try
- {
- Url eurl( ptr);
- std::string path( eurl.getPathName());
- if( !path.empty() && path != "/" && *path.rbegin() == '/')
- {
- DBG << "Effective url ("
- << eurl
- << ") seems to provide the index of a directory"
- << endl;
- not_a_file = true;
- }
- }
- catch( ... )
- {}
- }*/
-/*
- if( not_a_file)
- {
- ::fclose( file );
- filesystem::unlink( destNew );
- ZYPP_THROW(MediaNotAFileException(_url, filename));
- }
- }
-#endif // DETECT_DIR_INDEX
-*/
-
- /*
- long httpReturnCode = 0;
- CURLcode infoRet = curl_easy_getinfo(_curl,
- CURLINFO_RESPONSE_CODE,
- &httpReturnCode);
- bool modified = true;
- if (infoRet == CURLE_OK)
- {
- DBG << "HTTP response: " + str::numstring(httpReturnCode);
- if ( httpReturnCode == 304 ) // not modified
- {
- DBG << " Not modified.";
- modified = false;
- }
- DBG << endl;
- }
- else
- {
- WAR << "Could not get the reponse code." << endl;
- }
-
- if (modified || infoRet != CURLE_OK)
- {
- // apply umask
- if ( ::fchmod( ::fileno(file), filesystem::applyUmaskTo( 0644 ) ) )
- {
- ERR << "Failed to chmod file " << destNew << endl;
- }
- ::fclose( file );
-
- // move the temp file into dest
- if ( rename( destNew, dest ) != 0 ) {
- ERR << "Rename failed" << endl;
- ZYPP_THROW(MediaWriteException(dest));
- }
- }
-
- // close and remove the temp file
- ::fclose( file );
- filesystem::unlink( destNew );
-
-
-
- DBG << "done: " << PathInfo(dest) << endl;
- cout << "done: " << PathInfo(dest) << endl;
-
- cout << "Retornem true i es que SI existeix el fitxer METALIN " << endl;
- return true;
- */
-}
-
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaMetalink::getDir
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that media is attached
-//
-void MediaMetalink::getDir( const Pathname & dirname, bool recurse_r ) const
-{
- filesystem::DirContent content;
- getDirInfo( content, dirname, /*dots*/false );
-
- for ( filesystem::DirContent::const_iterator it = content.begin(); it != content.end(); ++it ) {
- Pathname filename = dirname + it->name;
- int res = 0;
-
- switch ( it->type ) {
- case filesystem::FT_NOT_AVAIL: // old directory.yast contains no typeinfo at all
- case filesystem::FT_FILE:
- getFile( filename );
- break;
- case filesystem::FT_DIR: // newer directory.yast contain at least directory info
- if ( recurse_r ) {
- getDir( filename, recurse_r );
- } else {
- res = assert_dir( localPath( filename ) );
- if ( res ) {
- WAR << "Ignore error (" << res << ") on creating local directory '" << localPath( filename ) << "'" << endl;
- }
- }
- break;
- default:
- // don't provide devices, sockets, etc.
- break;
- }
- }
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaMetalink::getDirInfo
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that media is attached and retlist is empty.
-//
-void MediaMetalink::getDirInfo( std::list<std::string> & retlist,
- const Pathname & dirname, bool dots ) const
-{
- getDirectoryYast( retlist, dirname, dots );
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaMetalink::getDirInfo
-// METHOD TYPE : PMError
-//
-// DESCRIPTION : Asserted that media is attached and retlist is empty.
-//
-void MediaMetalink::getDirInfo( filesystem::DirContent & retlist,
- const Pathname & dirname, bool dots ) const
-{
- getDirectoryYast( retlist, dirname, dots );
-}
-
-///////////////////////////////////////////////////////////////////
-//
-//
-// METHOD NAME : MediaMetalink::progressCallback
-// METHOD TYPE : int
-//
-// DESCRIPTION : Progress callback triggered from MediaMetalink::getFile
-//
-int MediaMetalink::progressCallback( void *clientp,
- double dltotal, double dlnow,
- double ultotal, double ulnow)
-{
- ProgressData *pdata = reinterpret_cast<ProgressData *>(clientp);
- if( pdata)
- {
- time_t now = time(NULL);
- if( now > 0)
- {
- // reset time of last change in case initial time()
- // failed or the time was adjusted (goes backward)
- if( pdata->ltime <= 0 || pdata->ltime > now)
- {
- pdata->ltime = now;
- }
-
- // start time counting as soon as first data arrives
- // (skip the connection / redirection time at begin)
- time_t dif = 0;
- if (dlnow > 0 || ulnow > 0)
- {
- dif = (now - pdata->ltime);
- dif = dif > 0 ? dif : 0;
-
- pdata->secs += dif;
- }
-
- // update the drate_avg and drate_period only after a second has passed
- // (this callback is called much more often than a second)
- // otherwise the values would be far from accurate when measuring
- // the time in seconds
- //! \todo more accurate download rate computationn, e.g. compute average value from last 5 seconds, or work with milliseconds instead of seconds
-
- if ( pdata->secs > 1 && (dif > 0 || dlnow == dltotal ))
- pdata->drate_avg = (dlnow / pdata->secs);
-
- if ( dif > 0 )
- {
- pdata->drate_period = ((dlnow - pdata->dload_period) / dif);
- pdata->dload_period = dlnow;
- }
- }
-
- // send progress report first, abort transfer if requested
- if( pdata->report)
- {
- if (!(*(pdata->report))->progress(int( dlnow * 100 / dltotal ),
- pdata->url,
- pdata->drate_avg,
- pdata->drate_period))
- {
- return 1; // abort transfer
- }
- }
-
- // check if we there is a timeout set
- if( pdata->timeout > 0)
- {
- if( now > 0)
- {
- bool progress = false;
-
- // update download data if changed, mark progress
- if( dlnow != pdata->dload)
- {
- progress = true;
- pdata->dload = dlnow;
- pdata->ltime = now;
- }
- // update upload data if changed, mark progress
- if( ulnow != pdata->uload)
- {
- progress = true;
- pdata->uload = ulnow;
- pdata->ltime = now;
- }
-
- if( !progress && (now >= (pdata->ltime + pdata->timeout)))
- {
- pdata->reached = true;
- return 1; // aborts transfer
- }
- }
- }
- }
- return 0;
-}
-
-string MediaMetalink::getAuthHint() const
-{
- long auth_info = CURLAUTH_NONE;
-
- CURLcode infoRet =
- curl_easy_getinfo(_curl, CURLINFO_HTTPAUTH_AVAIL, &auth_info);
-
- if(infoRet == CURLE_OK)
- {
- return CurlAuthData::auth_type_long2str(auth_info);
- }
-
- return "";
-}
-
- } // namespace media
-} // namespace zypp
-//