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.
 
PlugInFactoryGetFactory (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)
 

Detailed Description

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

Definition at line 41 of file XrdClPlugInManager.hh.

Constructor & Destructor Documentation

◆ PlugInManager()

XrdCl::PlugInManager::PlugInManager ( )

Constructor.

Definition at line 51 of file XrdClPlugInManager.cc.

51 :
52 pDefaultFactory(0)
53 {
54 }

◆ ~PlugInManager()

XrdCl::PlugInManager::~PlugInManager ( )

Destructor.

Definition at line 59 of file XrdClPlugInManager.cc.

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

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 145 of file XrdClPlugInManager.cc.

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

References XrdCl::URL::GetProtocol().

Referenced by XrdCl::FileSystem::FileSystem(), and XrdCl::File::Open().

+ 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) system directory: /etc/xrootd/client.plugins.d/ 2) user direvtory: ~/.xrootd/client.plugins.d/ 3) directory pointed to by XRD_PLUGINCONFDIR envvar

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 enabled - determines whether the plug-in should be enabled or not

You may use any other keys for your own purposes.

The config files are processed in alphabetic order, any satteing found later superseeds the previous one. Any setting applied via environment or config files superseeds any setting done programatically.

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

extern "C"
{
void *XrdClGetPlugIn( const void *arg )
{
return __your_plug_in_factory__;
}
}
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 186 of file XrdClPlugInManager.cc.

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

+ Here is the call 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 119 of file XrdClPlugInManager.cc.

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

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

+ Here is the call 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 75 of file XrdClPlugInManager.cc.

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

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

+ Here is the call graph for this function:

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