3 #include "zypp/base/Logger.h"
4 #include "zypp/repo/ServiceRepos.h"
5 #include "zypp/media/MediaException.h"
6 #include "zypp/parser/RepoFileReader.h"
7 #include "zypp/media/MediaManager.h"
8 #include "zypp/parser/RepoindexFileReader.h"
9 #include "zypp/ExternalProgram.h"
11 using std::stringstream;
18 class ServiceRepos::Impl
30 class RIMServiceRepos : public ServiceRepos::Impl
33 ServiceRepos::ProcessRepo _callback;
35 RIMServiceRepos(const ServiceInfo &service,
36 const ServiceRepos::ProcessRepo & callback,
37 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
40 // repoindex.xml must be fetched always without using cookies (bnc #573897)
41 Url serviceUrl( service.url() );
42 serviceUrl.setQueryParam( "cookies", "0" );
44 // download the repo index file
45 media::MediaManager mediamanager;
46 media::MediaAccessId mid = mediamanager.open( serviceUrl );
47 mediamanager.attach( mid );
48 mediamanager.provideFile( mid, "repo/repoindex.xml" );
49 Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
50 parser::RepoindexFileReader reader(path, _callback);
51 mediamanager.release( mid );
52 mediamanager.close( mid );
61 class PluginServiceRepos : public ServiceRepos::Impl
64 ServiceRepos::ProcessRepo _callback;
66 PluginServiceRepos(const ServiceInfo &service,
67 const ServiceRepos::ProcessRepo & callback,
68 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
71 Url serviceUrl( service.url() );
74 ExternalProgram prog(serviceUrl.getPathName(), ExternalProgram::Stderr_To_Stdout, false, -1, true);
77 // Services code in zypper is not ready to handle other
78 // types of exceptions yet
79 if ( prog.close() != 0 )
80 ZYPP_THROW(media::MediaException(buffer.str()));
82 parser::RepoFileReader parser(buffer, _callback);
92 ServiceRepos::ServiceRepos(const ServiceInfo &service,
93 const ServiceRepos::ProcessRepo & callback,
94 const ProgressData::ReceiverFnc &progress)
95 : _impl( (service.type() == ServiceType::PLUGIN) ? (ServiceRepos::Impl *)(new PluginServiceRepos(service, callback, progress)) : (ServiceRepos::Impl *)(new RIMServiceRepos(service, callback, progress)))
99 ServiceRepos::~ServiceRepos()