XRootD
ProxyPrefixPlugin.cc
Go to the documentation of this file.
1 //------------------------------------------------------------------------------
2 // Copyright (c) 2011-2017 by European Organization for Nuclear Research (CERN)
3 // Author: Elvin Sindrilaru <esindril@cern.ch>
4 //------------------------------------------------------------------------------
5 // This file is part of the XRootD software suite.
6 //
7 // XRootD is free software: you can redistribute it and/or modify
8 // it under the terms of the GNU Lesser General Public License as published by
9 // the Free Software Foundation, either version 3 of the License, or
10 // (at your option) any later version.
11 //
12 // XRootD is distributed in the hope that it will be useful,
13 // but WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 // GNU General Public License for more details.
16 //
17 // You should have received a copy of the GNU Lesser General Public License
18 // along with XRootD. If not, see <http://www.gnu.org/licenses/>.
19 //
20 // In applying this licence, CERN does not waive the privileges and immunities
21 // granted to it by virtue of its status as an Intergovernmental Organization
22 // or submit itself to any jurisdiction.
23 //------------------------------------------------------------------------------
24 
25 #include "ProxyPrefixPlugin.hh"
26 #include "ProxyPrefixFile.hh"
27 #include "XrdVersion.hh"
28 #include "XrdCl/XrdClDefaultEnv.hh"
29 #include "XrdCl/XrdClLog.hh"
30 #include <cstdlib>
31 #include <cstdio>
32 
34 
35 extern "C"
36 {
37  void* XrdClGetPlugIn(const void* arg)
38  {
39  const std::map<std::string, std::string>* config =
40  static_cast< const std::map<std::string, std::string>* >(arg);
41  return static_cast<void*>(new xrdcl_proxy::ProxyFactory(config));
42  }
43 }
44 
45 namespace xrdcl_proxy
46 {
47 //------------------------------------------------------------------------------
48 // Construtor
49 //------------------------------------------------------------------------------
50 ProxyFactory::ProxyFactory(const std::map<std::string, std::string>* config)
51 {
53  // If any of the parameters specific to this plugin are present then export
54  // them as env variables to be used later on if not already set.
55  if (config) {
56  // When C++11 is here:
57  // std::list<std::string> lst_envs {"XROOT_PROXY", "xroot_proxy",
58  // "XROOT_PROXY_EXCL_DOMAINS",
59  // "xroot_proxy_excl_domains};
60  std::list<std::string> lst_envs;
61  lst_envs.push_back("XROOT_PROXY");
62  lst_envs.push_back("xroot_proxy");
63  lst_envs.push_back("XROOT_PROXY_EXCL_DOMAINS");
64  lst_envs.push_back("xroot_proxy_excl_domains");
65 
66  for (std::list<std::string>::iterator it_env = lst_envs.begin();
67  it_env != lst_envs.end(); ++it_env) {
68  std::map<std::string, std::string>::const_iterator it_map =
69  config->find(*it_env);
70 
71  if (it_map != config->end() && !it_map->second.empty()) {
72  if (setenv(it_map->first.c_str(), it_map->second.c_str(), 0)) {
73  log->Error(1, "Failed to set env variable %s from the configuration"
74  " file", it_map->first.c_str());
75  }
76  }
77  }
78  }
79 }
80 
81 //------------------------------------------------------------------------------
82 // Destructor
83 //------------------------------------------------------------------------------
85 
86 //------------------------------------------------------------------------------
87 // Create a file plug-in for the given URL
88 //------------------------------------------------------------------------------
90 ProxyFactory::CreateFile(const std::string& url)
91 {
92  return static_cast<XrdCl::FilePlugIn*>(new ProxyPrefixFile());
93 }
94 
95 //------------------------------------------------------------------------------
96 // Create a file system plug-in for the given URL
97 //------------------------------------------------------------------------------
99 ProxyFactory::CreateFileSystem(const std::string& url)
100 {
102  log->Error(1, "FileSystem plugin implementation not supported");
103  return static_cast<XrdCl::FileSystemPlugIn*>(0);
104 }
105 } // namespace xrdcl_proxy
XrdVERSIONINFO(XrdClGetPlugIn, XrdClGetPlugIn) extern "C"
void * XrdClGetPlugIn(const void *)
static Log * GetLog()
Get default log.
An interface for file plug-ins.
An interface for file plug-ins.
Handle diagnostics.
Definition: XrdClLog.hh:101
void Error(uint64_t topic, const char *format,...)
Report an error.
Definition: XrdClLog.cc:231
XrdCl proxy prefix plugin factory.
ProxyFactory(const std::map< std::string, std::string > *config)
virtual ~ProxyFactory()
Destructor.
virtual XrdCl::FilePlugIn * CreateFile(const std::string &url)
Create a file plug-in for the given URL.
virtual XrdCl::FileSystemPlugIn * CreateFileSystem(const std::string &url)
Create a file system plug-in for the given URL.