ServiceRepos.cc
Go to the documentation of this file.00001 #include <iostream>
00002 #include <sstream>
00003 #include "zypp/base/Logger.h"
00004 #include "zypp/repo/ServiceRepos.h"
00005 #include "zypp/repo/RepoException.h"
00006 #include "zypp/media/MediaException.h"
00007 #include "zypp/parser/RepoFileReader.h"
00008 #include "zypp/media/MediaManager.h"
00009 #include "zypp/parser/RepoindexFileReader.h"
00010 #include "zypp/ExternalProgram.h"
00011
00012 using std::stringstream;
00013 using std::endl;
00014
00015 namespace zypp
00016 {
00017 namespace repo
00018 {
00019
00020 class ServiceRepos::Impl
00021 {
00022 public:
00023 Impl()
00024 {
00025 }
00026
00027 virtual ~Impl()
00028 {
00029 }
00030 };
00031
00032 class RIMServiceRepos : public ServiceRepos::Impl
00033 {
00034 public:
00035 ServiceRepos::ProcessRepo _callback;
00036
00037 RIMServiceRepos(const ServiceInfo &service,
00038 const ServiceRepos::ProcessRepo & callback,
00039 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
00040 : _callback(callback)
00041 {
00042
00043 Url serviceUrl( service.url() );
00044 serviceUrl.setQueryParam( "cookies", "0" );
00045
00046
00047 media::MediaManager mediamanager;
00048 media::MediaAccessId mid = mediamanager.open( serviceUrl );
00049 mediamanager.attach( mid );
00050 mediamanager.provideFile( mid, "repo/repoindex.xml" );
00051 Pathname path = mediamanager.localPath(mid, "repo/repoindex.xml" );
00052 parser::RepoindexFileReader reader(path, _callback);
00053 mediamanager.release( mid );
00054 mediamanager.close( mid );
00055 }
00056
00057 ~RIMServiceRepos()
00058 {
00059
00060 }
00061 };
00062
00063 class PluginServiceRepos : public ServiceRepos::Impl
00064 {
00065 public:
00066 ServiceRepos::ProcessRepo _callback;
00067
00068 PluginServiceRepos(const ServiceInfo &service,
00069 const ServiceRepos::ProcessRepo & callback,
00070 const ProgressData::ReceiverFnc &progress = ProgressData::ReceiverFnc() )
00071 : _callback(callback)
00072 {
00073 Url serviceUrl( service.url() );
00074 stringstream buffer;
00075
00076 ExternalProgram::Arguments args;
00077 args.reserve( 3 );
00078 args.push_back( "/bin/sh" );
00079 args.push_back( "-c" );
00080 args.push_back( serviceUrl.getPathName() );
00081 ExternalProgramWithStderr prog( args );
00082 prog >> buffer;
00083
00084 if ( prog.close() != 0 )
00085 {
00086
00087
00088 std::string errbuffer;
00089 prog.stderrGetUpTo( errbuffer, '\0' );
00090 ERR << "Capture plugin error:[" << endl << errbuffer << endl << ']' << endl;
00091 ZYPP_THROW( repo::ServicePluginInformalException(errbuffer));
00092 }
00093
00094 parser::RepoFileReader parser(buffer, _callback);
00095 }
00096
00097 ~PluginServiceRepos()
00098 {}
00099 };
00100
00101
00102 ServiceRepos::ServiceRepos(const ServiceInfo &service,
00103 const ServiceRepos::ProcessRepo & callback,
00104 const ProgressData::ReceiverFnc &progress)
00105 : _impl( (service.type() == ServiceType::PLUGIN) ? (ServiceRepos::Impl *)(new PluginServiceRepos(service, callback, progress)) : (ServiceRepos::Impl *)(new RIMServiceRepos(service, callback, progress)))
00106 {
00107 }
00108
00109 ServiceRepos::~ServiceRepos()
00110 {
00111 }
00112
00113
00114 }
00115 }