irods  4.2.8
About: iRODS (the integrated Rule Oriented Data System) is a distributed data-management system for creating data grids, digital libraries, persistent archives, and real-time data systems.
  Fossies Dox: irods-4.2.8.tar.gz  ("unofficial" and yet experimental doxygen-generated source code documentation)  

apiHandler.cpp
Go to the documentation of this file.
1 // =-=-=-=-=-=-=-
2 // irods includes
3 #include "apiHandler.hpp"
4 #include "irods_load_plugin.hpp"
6 #include "irods_pack_table.hpp"
8 
9 #include <boost/filesystem.hpp>
10 
11 #include <algorithm>
12 
13 namespace irods
14 {
15  // =-=-=-=-=-=-=-
16  // public - ctor
18  : plugin_base( "api_instance", "api_context" )
19  , apiNumber( _def.apiNumber )
20  , apiVersion( _def.apiVersion )
21  , clientUserAuth( _def.clientUserAuth )
22  , proxyUserAuth( _def.proxyUserAuth )
23  , inPackInstruct( _def.inPackInstruct )
24  , inBsFlag( _def.inBsFlag )
25  , outPackInstruct( _def.outPackInstruct )
26  , outBsFlag( _def.outBsFlag )
27  , call_wrapper(_def.call_wrapper)
28  , operation_name(_def.operation_name)
29  , clearInStruct( _def.clearInStruct )
30  {
31  operations_[ _def.operation_name ] = _def.svrHandler;
32  } // ctor
33 
34  // =-=-=-=-=-=-=-
35  // public - copy ctor
37  : plugin_base( _rhs )
38  , apiNumber( _rhs.apiNumber )
39  , apiVersion( _rhs.apiVersion )
40  , clientUserAuth( _rhs.clientUserAuth )
41  , proxyUserAuth( _rhs.proxyUserAuth )
42  , inPackInstruct( _rhs.inPackInstruct )
43  , inBsFlag( _rhs.inBsFlag )
44  , outPackInstruct( _rhs.outPackInstruct )
45  , outBsFlag( _rhs.outBsFlag )
46  , call_wrapper(_rhs.call_wrapper)
47  , in_pack_key(_rhs.in_pack_key)
48  , out_pack_key(_rhs.out_pack_key)
49  , in_pack_value(_rhs.in_pack_value)
50  , out_pack_value(_rhs.out_pack_value)
51  , operation_name(_rhs.operation_name)
52  , extra_pack_struct(_rhs.extra_pack_struct)
53  , clearInStruct( _rhs.clearInStruct )
54  {
55  } // cctor
56 
57  // =-=-=-=-=-=-=-
58  // public - assignment operator
60  {
61  if ( this == &_rhs ) {
62  return *this;
63  }
64 
66  apiNumber = _rhs.apiNumber;
67  apiVersion = _rhs.apiVersion;
71  inBsFlag = _rhs.inBsFlag;
73  outBsFlag = _rhs.outBsFlag;
74 
75  return *this;
76  } // assignment op
77 
78  // =-=-=-=-=-=-=-
79  // public - ctor for api entry table
81  : loaded_plugins_{}
82  {
83  for (size_t i = 0; i < num; ++i) {
84  table_[defs[i].apiNumber] = api_entry_ptr(new api_entry(defs[i]));
85  }
86  } // ctor
87 
88  auto api_entry_table::is_plugin_loaded(std::string_view plugin_name) -> bool
89  {
90  const auto end = std::cend(loaded_plugins_);
91  return std::find(std::cbegin(loaded_plugins_), end, plugin_name) != end;
92  }
93 
94  auto api_entry_table::mark_plugin_as_loaded(std::string_view plugin_name) -> void
95  {
96  if (!is_plugin_loaded(plugin_name)) {
97  loaded_plugins_.push_back(plugin_name.data());
98  }
99  }
100 
101  // =-=-=-=-=-=-=-
102  // public - load api plugins
104  pack_entry_table& _pack_tbl,
105  bool _cli_flg)
106  {
107  // =-=-=-=-=-=-=-
108  // resolve plugin directory
109  std::string plugin_home;
110  error ret = resolve_plugin_path( irods::PLUGIN_TYPE_API, plugin_home );
111  if ( !ret.ok() ) {
112  return PASS( ret );
113  }
114 
115  namespace fs = boost::filesystem;
116 
117  // =-=-=-=-=-=-=-
118  // iterate over the API_HOME directory entries
119  if (const fs::path so_dir(plugin_home); fs::exists(so_dir)) {
120  for (fs::directory_iterator it(so_dir); it != fs::directory_iterator(); ++it) {
121  const auto path = it->path();
122 
123  // Skip the API plugin if it was loaded before.
124  if (_api_tbl.is_plugin_loaded(path.c_str())) {
125  const auto* msg = "init_api_table :: API plugin [%s] has already been loaded. Skipping ...";
126  rodsLog(LOG_DEBUG, msg, path.stem().c_str());
127  continue;
128  }
129 
130  // =-=-=-=-=-=-=-
131  // given a shared object, load the plugin from it
132  std::string name = path.stem().string();
133 
134  // =-=-=-=-=-=-=-
135  // if client side, skip server plugins, etc.
136  if (std::string::npos != name.find(_cli_flg ? "_server" : "_client")) {
137  continue;
138  }
139 
140  // =-=-=-=-=-=-=-
141  // clip off the lib to remain compliant with
142  // load_plugin's expected behavior
143  size_t pos = name.find( "lib" );
144  if ( std::string::npos == pos ) {
145  continue;
146  }
147  name = name.substr( 3 );
148 
149  api_entry* entry = nullptr;
150  error ret = load_plugin<api_entry>(
151  entry,
152  name,
154  "api_instance",
155  "api_context");
156  if (ret.ok() && entry) {
157  rodsLog(
158  LOG_DEBUG,
159  "init_api_table :: adding %d - [%s] - [%s]",
160  entry->apiNumber,
161  entry->operation_name.c_str(),
162  name.c_str() );
163 
164  // =-=-=-=-=-=-=-
165  // ask the plugin to fill in the api and pack
166  // tables with its appropriate values
167  _api_tbl[ entry->apiNumber ] = api_entry_ptr( entry );
168 
169  // =-=-=-=-=-=-=-
170  // add the in struct
171  if ( !entry->in_pack_key.empty() ) {
172  _pack_tbl[ entry->in_pack_key ].packInstruct = entry->in_pack_value;
173  entry->inPackInstruct = entry->in_pack_key.c_str();
174  }
175 
176  // =-=-=-=-=-=-=-
177  // add the out struct
178  if ( !entry->out_pack_key.empty() ) {
179  _pack_tbl[ entry->out_pack_key ].packInstruct = entry->out_pack_value;
180  entry->outPackInstruct = entry->out_pack_key.c_str();
181  }
182 
183  // =-=-=-=-=-=-=-
184  // some plugins may define additional packinstructions
185  // which are composites of the in or out structs
186  if (!entry->extra_pack_struct.empty()) {
187  for (auto&& [key, value] : entry->extra_pack_struct) {
188  _pack_tbl[key].packInstruct = value;
189  }
190  }
191 
192  // Remember that the current plugin has been loaded.
193  // This keeps the server from wasting resources loading the same
194  // plugin multiple times.
195  _api_tbl.mark_plugin_as_loaded(path.c_str());
196  }
197  else {
198  irods::log( PASS( ret ) );
199  }
200  } // for itr
201  } // if exists
202 
203  return SUCCESS();
204  } // init_api_table
205 } // namespace irods
206 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
irods::apidef_t::svrHandler
boost::any svrHandler
Definition: apiHandler.hpp:59
irods::api_entry::outPackInstruct
const char * outPackInstruct
Definition: apiHandler.hpp:277
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
apiHandler.hpp
irods::api_entry::outBsFlag
int outBsFlag
Definition: apiHandler.hpp:279
irods::init_api_table
error init_api_table(api_entry_table &_api_tbl, pack_entry_table &_pack_tbl, bool _cli_flg=true)
Definition: apiHandler.cpp:103
irods::experimental::administration::client::v1::exists
auto exists(rcComm_t &conn, const user &user) -> bool
Definition: user_administration.cpp:359
irods::api_entry::apiNumber
int apiNumber
Definition: apiHandler.hpp:265
irods::api_entry_table::is_plugin_loaded
auto is_plugin_loaded(std::string_view plugin_name) -> bool
Definition: apiHandler.cpp:88
irods::api_entry::proxyUserAuth
int proxyUserAuth
Definition: apiHandler.hpp:271
irods::api_entry::api_entry
api_entry(apidef_t &)
Definition: apiHandler.cpp:17
irods::apidef_t
Definition: apiHandler.hpp:39
generate_iadmin_commands_for_41_to_42_upgrade.name
name
Definition: generate_iadmin_commands_for_41_to_42_upgrade.py:23
irods_pack_table.hpp
irods::api_entry_ptr
boost::shared_ptr< api_entry > api_entry_ptr
Definition: apiHandler.hpp:347
irods::experimental::filesystem::client::end
auto end(const collection_iterator &) noexcept -> const collection_iterator
Definition: collection_iterator.hpp:88
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods::plugin_base::operator=
plugin_base & operator=(const plugin_base &_rhs)
Definition: irods_plugin_base.hpp:75
irods::apidef_t::operation_name
const char * operation_name
Definition: apiHandler.hpp:62
irods::resolve_plugin_path
static error resolve_plugin_path(const std::string &_type, std::string &_path)
Definition: irods_load_plugin.hpp:33
LOG_DEBUG
#define LOG_DEBUG
Definition: rodsLog.h:23
irods::api_entry::inBsFlag
int inBsFlag
Definition: apiHandler.hpp:274
irods
Definition: apiHandler.hpp:35
irods_load_plugin.hpp
irods::plugin_base
Definition: irods_plugin_base.hpp:48
get_irods_version.value
dictionary value
Definition: get_irods_version.py:27
irods::log
void log(const error &)
Definition: irods_log.cpp:13
irods::api_entry_table::mark_plugin_as_loaded
auto mark_plugin_as_loaded(std::string_view plugin_name) -> void
Definition: apiHandler.cpp:94
irods::error
Definition: irods_error.hpp:23
irods_client_api_table.hpp
irods::api_entry_table
Definition: apiHandler.hpp:353
irods::api_entry::inPackInstruct
const char * inPackInstruct
Definition: apiHandler.hpp:272
irods_plugin_name_generator.hpp
entry
Definition: ruleAdmin.cpp:22
irods::PLUGIN_TYPE_API
const std::string PLUGIN_TYPE_API("api")
irods::api_entry::apiVersion
char * apiVersion
Definition: apiHandler.hpp:266
irods::api_entry_table::api_entry_table
api_entry_table(apidef_t defs[], size_t size)
Definition: apiHandler.cpp:80
irods::api_entry::operator=
api_entry & operator=(const api_entry &)
Definition: apiHandler.cpp:59
irods::pack_entry_table
Definition: irods_pack_table.hpp:13
irods::api_entry::clientUserAuth
int clientUserAuth
Definition: apiHandler.hpp:267
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods::api_entry
Definition: apiHandler.hpp:104
irods::plugin_base::operations_
lookup_table< boost::any > operations_
Definition: irods_plugin_base.hpp:340