XRootD
Loading...
Searching...
No Matches
XrdCl::PlugInManager Class Reference

Manage client-side plug-ins and match them agains URLs. More...

#include <XrdClPlugInManager.hh>

Collaboration diagram for XrdCl::PlugInManager:

Public Member Functions

 PlugInManager ()
 Constructor.
 ~PlugInManager ()
 Destructor.
PlugInFactory * GetFactory (const std::string url)
void ProcessEnvironmentSettings ()
bool RegisterDefaultFactory (PlugInFactory *factory)
 Register a plug-in factory applying to all URLs.
bool RegisterFactory (const std::string &url, PlugInFactory *factory)

Friends

class ::PlugInManagerFixture

Detailed Description

Manage client-side plug-ins and match them agains URLs.

Definition at line 45 of file XrdClPlugInManager.hh.

Constructor & Destructor Documentation

◆ PlugInManager()

XrdCl::PlugInManager::PlugInManager ( )

Constructor.

Definition at line 52 of file XrdClPlugInManager.cc.

52 :
53 pDefaultFactory(0)
54 {
55 }

Referenced by ::PlugInManagerFixture.

Here is the caller graph for this function:

◆ ~PlugInManager()

XrdCl::PlugInManager::~PlugInManager ( )

Destructor.

Definition at line 60 of file XrdClPlugInManager.cc.

61 {
62 std::map<std::string, FactoryHelper*>::iterator it;
63 for( it = pFactoryMap.begin(); it != pFactoryMap.end(); ++it )
64 {
65 it->second->counter--;
66 if( it->second->counter == 0 )
67 delete it->second;
68 }
69
70 delete pDefaultFactory;
71 }

Member Function Documentation

◆ GetFactory()

PlugInFactory * XrdCl::PlugInManager::GetFactory ( const std::string url)

Retrieve the plug-in factory for the given URL

Returns
you do not own the returned memory

Definition at line 146 of file XrdClPlugInManager.cc.

147 {
148 XrdSysMutexHelper scopedLock( pMutex );
149
150 if( pDefaultFactory && pDefaultFactory->isEnv )
151 return pDefaultFactory->factory;
152
153 std::string normUrl = NormalizeURL( url );
154 if( normUrl.empty() )
155 {
156 if( pDefaultFactory )
157 return pDefaultFactory->factory;
158 return 0;
159 }
160
161 std::map<std::string, FactoryHelper*>::iterator it;
162 it = pFactoryMap.find( normUrl );
163 if( it != pFactoryMap.end() && it->second->isEnv )
164 return it->second->factory;
165
166 std::string protocol = URL( url ).GetProtocol();
167 std::map<std::string, FactoryHelper*>::iterator itProt;
168 itProt = pFactoryMap.find( protocol );
169 if( itProt != pFactoryMap.end() && itProt->second->isEnv )
170 return itProt->second->factory;
171
172 if( pDefaultFactory )
173 return pDefaultFactory->factory;
174
175 if( it != pFactoryMap.end() )
176 return it->second->factory;
177
178 if( itProt != pFactoryMap.end() )
179 return itProt->second->factory;
180
181 return 0;
182 }
URL()
Default constructor.
Definition XrdClURL.cc:36

References XrdCl::URL::URL().

Referenced by XrdCl::FileSystem::FileSystem(), ::PlugInManagerFixture, and XrdCl::ThirdPartyCopy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ProcessEnvironmentSettings()

void XrdCl::PlugInManager::ProcessEnvironmentSettings ( )

Process user environment to load plug-in settings.

This will try to load a default plug-in from a library pointed to by the XRD_PLUGIN envvar. If this fails it will scan the configuration files located in:

1) directory pointed to by XRD_PLUGINCONFDIR envvar 2) user directory: ~/.xrootd/client.plugins.d/ 3) system directory: /etc/xrootd/client.plugins.d/

In that order.

The configuration files contain lines with key-value pairs in the form of 'key=value'.

Mandatory keys are: url - a semicolon separated list of URLs the plug-in applies to lib - plugin library to be loaded enable - determines whether the plug-in should be enabled or not

You may use any other keys for your own purposes.

The first directory with a setting for a URL decides it, and the directories after it cannot change it. This applies to disabled plug-ins as well. Within one directory, the config files are processed in alphabetic order, and a setting for a URL found later supersedes the previous one. However, only the first enabled plug-in for all URLs ('url = *') is loaded. Any setting applied via environment or config files supersedes any setting done programmatically.

The plug-in library must implement the following C function:

extern "C"
{
void *XrdClGetPlugIn( const void *arg )
{
return __your_plug_in_factory__;
}
}
XrdEXPORT void * XrdClGetPlugIn(const void *)

where arg is a const pointer to std::map<std::string, std::string> containing the plug-in configuration.

Definition at line 187 of file XrdClPlugInManager.cc.

188 {
189 XrdSysMutexHelper scopedLock( pMutex );
190 Log *log = DefaultEnv::GetLog();
191 Env *env = DefaultEnv::GetEnv();
192
193 log->Debug( PlugInMgrMsg, "Initializing plug-in manager..." );
194
195 //--------------------------------------------------------------------------
196 // Check if a default plug-in has been specified in the environment
197 //--------------------------------------------------------------------------
198 bool loadConfigs = true;
199 std::string defaultPlugIn = DefaultPlugIn;
200 env->GetString( "PlugIn", defaultPlugIn );
201 if( !defaultPlugIn.empty() )
202 {
203 loadConfigs = false;
204 log->Debug( PlugInMgrMsg, "Loading default plug-in from %s...",
205 defaultPlugIn.c_str());
206
207 std::pair<XrdOucPinLoader*, PlugInFactory *> pg = LoadFactory(
208 defaultPlugIn, std::map<std::string, std::string>() );
209
210 if( !pg.first )
211 {
212 log->Debug( PlugInMgrMsg, "Failed to load default plug-in from %s",
213 defaultPlugIn.c_str());
214 loadConfigs = false;
215 }
216
217 pDefaultFactory = new FactoryHelper();
218 pDefaultFactory->factory = pg.second;
219 pDefaultFactory->plugin = pg.first;
220 pDefaultFactory->isEnv = true;
221 }
222
223 //--------------------------------------------------------------------------
224 // If there is no default plug-in or it is invalid then load plug-in config
225 // files
226 //--------------------------------------------------------------------------
227 if( loadConfigs )
228 {
229 log->Debug( PlugInMgrMsg,
230 "No default plug-in, loading plug-in configs..." );
231
232 std::vector<std::string> dirs;
233
234 std::string customPlugIns = DefaultPlugInConfDir;
235 env->GetString( "PlugInConfDir", customPlugIns );
236 if( !customPlugIns.empty() )
237 dirs.push_back( customPlugIns );
238
239 XrdSysPwd pwdHandler;
240 passwd *pwd = pwdHandler.Get( getuid() );
241 if( pwd )
242 dirs.push_back( std::string( pwd->pw_dir ) + "/.xrootd/client.plugins.d" );
243
244 dirs.push_back( "/etc/xrootd/client.plugins.d" );
245
246 ProcessConfigDirs( dirs );
247 }
248 }
static Log * GetLog()
Get default log.
static Env * GetEnv()
Get default client environment.
struct passwd * Get(const char *Usr)
Definition XrdSysPwd.hh:42
const char *const DefaultPlugIn
const char *const DefaultPlugInConfDir
const uint64_t PlugInMgrMsg
XrdSysError Log
Definition XrdConfig.cc:113

References XrdCl::Log::Debug(), XrdCl::DefaultPlugIn, XrdCl::DefaultPlugInConfDir, XrdSysPwd::Get(), XrdCl::DefaultEnv::GetEnv(), XrdCl::DefaultEnv::GetLog(), XrdCl::Env::GetString(), and XrdCl::PlugInMgrMsg.

Referenced by ::PlugInManagerFixture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterDefaultFactory()

bool XrdCl::PlugInManager::RegisterDefaultFactory ( PlugInFactory * factory)

Register a plug-in factory applying to all URLs.

Register a plug-in factory applying to all URLs, registering a 0 pointer removes the factory

Definition at line 120 of file XrdClPlugInManager.cc.

121 {
122 Log *log = DefaultEnv::GetLog();
123 XrdSysMutexHelper scopedLock( pMutex );
124
125 if( pDefaultFactory && pDefaultFactory->isEnv )
126 return false;
127
128 delete pDefaultFactory;
129 pDefaultFactory = 0;
130
131 if( factory )
132 {
133 log->Debug( PlugInMgrMsg, "Registering a default factory" );
134 pDefaultFactory = new FactoryHelper;
135 pDefaultFactory->factory = factory;
136 }
137 else
138 log->Debug( PlugInMgrMsg, "Removing the default factory" );
139
140 return true;
141 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::PlugInMgrMsg.

Referenced by ::PlugInManagerFixture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ RegisterFactory()

bool XrdCl::PlugInManager::RegisterFactory ( const std::string & url,
PlugInFactory * factory )

Register a plug-in factory for the given url, registering a 0 pointer removes the factory for the url

Definition at line 76 of file XrdClPlugInManager.cc.

78 {
79 Log *log = DefaultEnv::GetLog();
80 XrdSysMutexHelper scopedLock( pMutex );
81
82 std::string normUrl = NormalizeURL( url );
83 if( normUrl == "" )
84 return false;
85
86 std::map<std::string, FactoryHelper*>::iterator it;
87 it = pFactoryMap.find( normUrl );
88 if( it != pFactoryMap.end() )
89 {
90 if( it->second->isEnv )
91 return false;
92
93 // we don't need to check the counter because it's valid only
94 // for environment plugins which cannot be replaced via
95 // this method
96 delete it->second;
97 }
98
99 if( !factory )
100 {
101 log->Debug( PlugInMgrMsg, "Removing the factory for %s",
102 normUrl.c_str() );
103 pFactoryMap.erase( it );
104 return true;
105 }
106
107 log->Debug( PlugInMgrMsg, "Registering a factory for %s",
108 normUrl.c_str() );
109
110 FactoryHelper *h = new FactoryHelper();
111 h->factory = factory;
112 h->counter = 1;
113 pFactoryMap[normUrl] = h;
114 return true;
115 }

References XrdCl::Log::Debug(), XrdCl::DefaultEnv::GetLog(), and XrdCl::PlugInMgrMsg.

Referenced by ::PlugInManagerFixture.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ::PlugInManagerFixture

friend class ::PlugInManagerFixture
friend

The documentation for this class was generated from the following files: