libzypp 8.13.6
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00009 00010 #include <iostream> 00011 #include <map> 00012 #include <algorithm> 00013 #include "zypp/base/String.h" 00014 #include "zypp/repo/RepoException.h" 00015 #include "zypp/ZConfig.h" 00016 #include "zypp/ZYppFactory.h" 00017 #include "RepoVariables.h" 00018 00019 using namespace std; 00020 00021 namespace zypp 00022 { 00023 namespace repo 00024 { 00025 00026 RepoVariablesStringReplacer::RepoVariablesStringReplacer() 00027 { 00028 sysarch = Arch_empty; 00029 basearch = Arch_empty; 00030 } 00031 00032 RepoVariablesStringReplacer::~RepoVariablesStringReplacer() 00033 {} 00034 00035 void RepoVariablesStringReplacer::resetVarCache( void ) 00036 { 00037 sysarch = Arch_empty; 00038 basearch = Arch_empty; 00039 releasever = ""; 00040 } 00041 00042 std::string RepoVariablesStringReplacer::operator()( const std::string &value ) const 00043 { 00044 string newvalue(value); 00045 00046 // $arch 00047 if( sysarch.empty() ) 00048 sysarch = ZConfig::instance().systemArchitecture(); 00049 00050 newvalue = str::gsub( newvalue, "$arch", sysarch.asString() ); 00051 00052 // $basearch 00053 if( basearch.empty() ) 00054 basearch = sysarch.baseArch(); 00055 00056 newvalue = str::gsub( newvalue, "$basearch", basearch.asString() ); 00057 00058 // $releasever (Target::distributionVersion assumes root=/ if target not initialized) 00059 if( releasever.empty() ) 00060 releasever = Target::distributionVersion(Pathname()/*guess*/); 00061 00062 newvalue = str::gsub( newvalue, "$releasever", releasever ); 00063 00064 return newvalue; 00065 } 00066 00068 00069 RepoVariablesUrlReplacer::RepoVariablesUrlReplacer() 00070 {} 00071 00072 RepoVariablesUrlReplacer::~RepoVariablesUrlReplacer() 00073 {} 00074 00075 void RepoVariablesUrlReplacer::resetVarCache( void ) 00076 { 00077 replacer.resetVarCache(); 00078 } 00079 00080 /* 00081 * Replaces '$arch' and '$basearch' in the path and query part of the URL 00082 * with the global ZYpp values. Examples: 00083 * 00084 * ftp://user:secret@site.net/$arch/ -> ftp://user:secret@site.net/i686/ 00085 * http://site.net/?basearch=$basearch -> http://site.net/?basearch=i386 00086 */ 00087 Url RepoVariablesUrlReplacer::operator()( const Url &value ) const 00088 { 00089 Url newurl = value; 00090 newurl.setPathData(replacer(value.getPathData())); 00091 newurl.setQueryString(replacer(value.getQueryString())); 00092 00093 return newurl; 00094 } 00095 00096 } // ns repo 00097 } // ns zypp 00098 00099 // vim: set ts=2 sts=2 sw=2 et ai: