libzypp
10.5.0
|
00001 /*---------------------------------------------------------------------\ 00002 | ____ _ __ __ ___ | 00003 | |__ / \ / / . \ . \ | 00004 | / / \ V /| _/ _/ | 00005 | / /__ | | | | | | | 00006 | /_____||_| |_| |_| | 00007 | | 00008 \---------------------------------------------------------------------*/ 00012 #include <iostream> 00013 #include "zypp/base/Logger.h" 00014 #include "zypp/media/UrlResolverPlugin.h" 00015 #include "zypp/media/MediaException.h" 00016 #include "zypp/PluginScript.h" 00017 #include "zypp/ZConfig.h" 00018 00019 using std::endl; 00020 00022 namespace zypp 00023 { 00024 00025 namespace media 00026 { 00027 00029 struct UrlResolverPlugin::Impl 00030 { 00031 00032 00033 }; 00035 00036 Url UrlResolverPlugin::resolveUrl(const Url & o_url, HeaderList &headers) 00037 { 00038 if (o_url.getScheme() != "plugin") 00039 return o_url; 00040 00041 Url url(o_url); 00042 std::string name = url.getPathName(); 00043 Pathname plugin_path = (ZConfig::instance().pluginsPath()/"urlresolver")/name; 00044 if (PathInfo(plugin_path).isExist()) { 00045 PluginScript scr; 00046 scr.open(plugin_path); 00047 // send frame to plugin 00048 PluginFrame f("RESOLVEURL"); 00049 00050 url::ParamMap params = url.getQueryStringMap(); 00051 url::ParamMap::const_iterator param_it; 00052 for( param_it = params.begin(); 00053 param_it != params.end(); 00054 ++param_it) 00055 f.setHeader(param_it->first, param_it->second); 00056 00057 scr.send(f); 00058 00059 PluginFrame r(scr.receive()); 00060 if (r.command() == "RESOLVEDURL") { 00061 // now set 00062 url = Url(r.body()); 00063 PluginFrame::HeaderListIterator it; 00064 00065 for (it = r.headerBegin(); 00066 it != r.headerEnd(); 00067 ++it) { 00068 std::pair<std::string, std::string> values(*it); 00069 // curl resets headers that are empty, so we use a workaround 00070 if (values.second.empty()) { 00071 values.second = "\nX-libcurl-Empty-Header-Workaround: *"; 00072 } 00073 headers.insert(values); 00074 } 00075 } 00076 else if (r.command() == "ERROR") { 00077 ZYPP_THROW(MediaException(r.body())); 00078 } 00079 } 00080 return url; 00081 } 00082 00084 inline std::ostream & operator<<( std::ostream & str, const UrlResolverPlugin::Impl & obj ) 00085 { 00086 return str << "UrlResolverPlugin::Impl"; 00087 } 00088 00089 UrlResolverPlugin::~UrlResolverPlugin() 00090 {} 00091 00092 std::ostream & operator<<( std::ostream & str, const UrlResolverPlugin & obj ) 00093 { 00094 return str << *obj._pimpl; 00095 } 00096 00098 } // namespace media 00101 } // namespace zypp