libzypp: zypp/media/UrlResolverPlugin.cc Source File

libzypp 17.38.6

UrlResolverPlugin.cc
Go to the documentation of this file.
1/*---------------------------------------------------------------------\
2| ____ _ __ __ ___ |
3| |__ / \ / / . \ . \ |
4| / / \ V /| _/ _/ |
5| / /__ | | | | | | |
6| /_____||_| |_| |_| |
7| |
8\---------------------------------------------------------------------*/
12#include <iostream>
13#include <zypp-core/base/Logger.h>
14#include <zypp/media/UrlResolverPlugin.h>
15#include <zypp-media/MediaException>
16#include <zypp/PluginScript.h>
17#include <zypp/ZConfig.h>
18
19using std::endl;
20
22namespace zypp
23{
25 namespace media
26 {
27
29 struct UrlResolverPlugin::Impl
30 {
31
32
33 };
34
35
36 Url UrlResolverPlugin::resolveUrl(const Url & o_url, HeaderList &headers)
37 {
38 if (o_url.getScheme() != "plugin")
39 return o_url;
40
41 Url url(o_url);
42 std::string name = url.getPathName();
43 Pathname plugin_path = (ZConfig::instance().pluginsPath()/"urlresolver")/name;
44 if (PathInfo(plugin_path).isExist()) {
45 PluginScript scr;
46 scr.open(plugin_path);
47 // send frame to plugin
48 PluginFrame f("RESOLVEURL");
49
50 url::ParamMap params = url.getQueryStringMap();
51 url::ParamMap::const_iterator param_it;
52 for( param_it = params.begin();
53 param_it != params.end();
54 ++param_it)
55 f.setHeader(param_it->first, param_it->second);
56
57 scr.send(f);
58
59 PluginFrame r(scr.receive());
60 if (r.command() == "RESOLVEDURL") {
61 // now set
62 url = Url(r.body().asString());
63 PluginFrame::HeaderListIterator it;
64
65 for (it = r.headerBegin();
66 it != r.headerEnd();
67 ++it) {
68 std::pair<std::string, std::string> values(*it);
69 // curl resets headers that are empty, so we use a workaround
70 if (values.second.empty()) {
71 values.second = "\r\nX-libcurl-Empty-Header-Workaround: *";
72 }
73 headers.insert(values);
74 }
75 }
76 else if (r.command() == "ERROR") {
77 ZYPP_THROW(MediaException(r.body().asString()));
78 }
79 }
80 return url;
81 }
82
84 inline std::ostream & operator<<( std::ostream & str, const UrlResolverPlugin::Impl & obj )
85 {
86 return str << "UrlResolverPlugin::Impl";
87 }
88
89 UrlResolverPlugin::~UrlResolverPlugin()
90 {}
91
92 std::ostream & operator<<( std::ostream & str, const UrlResolverPlugin & obj )
93 {
94 return str << *obj._pimpl;
95 }
96
98 } // namespace media
101} // namespace zypp
ZYPP_THROW
#define ZYPP_THROW(EXCPT)
Drops a logline and throws the Exception.
Definition Exception.h:459
Logger.h
PluginScript.h
UrlResolverPlugin.h
ZConfig.h
zypp::ByteArray::asString
std::string asString() const
Definition ByteArray.h:24
zypp::PluginFrame
Command frame for communication with PluginScript.
Definition PluginFrame.h:42
zypp::PluginFrame::HeaderListIterator
HeaderList::const_iterator HeaderListIterator
Header list iterator.
Definition PluginFrame.h:152
zypp::PluginFrame::body
const ByteArray & body() const
Return the frame body.
Definition PluginFrame.cc:445
zypp::PluginFrame::command
const std::string & command() const
Return the frame command.
Definition PluginFrame.cc:439
zypp::PluginFrame::headerEnd
HeaderListIterator headerEnd() const
Return iterator pointing behind the last header.
Definition PluginFrame.h:175
zypp::PluginFrame::setHeader
void setHeader(const std::string &key_r, const std::string &value_r=std::string())
Set header for key_r removing all other occurrences of key_r.
Definition PluginFrame.cc:478
zypp::PluginFrame::headerBegin
HeaderListIterator headerBegin() const
Return iterator pointing to the 1st header (or headerEnd).
Definition PluginFrame.h:171
zypp::PluginScript
Interface to plugin scripts using a Stomp inspired communication protocol.
Definition PluginScript.h:63
zypp::PluginScript::receive
PluginFrame receive() const
Receive a PluginFrame.
Definition PluginScript.cc:522
zypp::PluginScript::send
void send(const PluginFrame &frame_r) const
Send a PluginFrame.
Definition PluginScript.cc:519
zypp::PluginScript::open
void open()
Setup connection and execute script.
Definition PluginScript.cc:507
zypp::Url
Url manipulation class.
Definition Url.h:93
zypp::Url::getScheme
std::string getScheme() const
Returns the scheme name of the URL.
Definition Url.cc:560
zypp::ZConfig::pluginsPath
Pathname pluginsPath() const
Defaults to /usr/lib/zypp/plugins.
Definition ZConfig.cc:1173
zypp::ZConfig::instance
static ZConfig & instance()
Singleton ctor.
Definition ZConfig.cc:756
zypp::filesystem::PathInfo
Wrapper class for stat/lstat.
Definition PathInfo.h:226
zypp::filesystem::Pathname
Pathname.
Definition Pathname.h:48
zypp::media::MediaException
Just inherits Exception to separate media exceptions.
Definition mediaexception.h:37
zypp::media::UrlResolverPlugin::~UrlResolverPlugin
~UrlResolverPlugin()
Dtor.
Definition UrlResolverPlugin.cc:89
zypp::media::UrlResolverPlugin::_pimpl
RW_pointer< Impl > _pimpl
Pointer to implementation.
Definition UrlResolverPlugin.h:60
zypp::media::UrlResolverPlugin::UrlResolverPlugin
UrlResolverPlugin()
Default ctor.
zypp::media::UrlResolverPlugin::HeaderList
std::multimap< std::string, std::string > HeaderList
Definition UrlResolverPlugin.h:39
zypp::media::UrlResolverPlugin::resolveUrl
static Url resolveUrl(const Url &url, HeaderList &headers)
Resolves an url using the installed plugins If no plugin is found the url is resolved as its current ...
Definition UrlResolverPlugin.cc:36
str
String related utilities and Regular expression matching.
zypp::media
Definition MediaNetworkRequestExecutor.h:22
zypp::media::operator<<
std::ostream & operator<<(std::ostream &str, const MediaHandler &obj)
Definition MediaHandler.cc:1181
zypp::url
Url details namespace.
Definition UrlBase.cc:58
zypp::url::ParamMap
std::map< std::string, std::string > ParamMap
A parameter map container.
Definition UrlUtils.h:47
zypp
Easy-to use interface to the ZYPP dependency resolver.
Definition CodePitfalls.doc:2
zypp::media::UrlResolverPlugin::Impl
UrlResolverPlugin implementation.
Definition UrlResolverPlugin.cc:30