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)  

irods_plugin_name_generator.cpp
Go to the documentation of this file.
2 #include "irods_log.hpp"
3 
4 #include "rodsErrorTable.h"
5 #include <sstream>
6 
7 #include <boost/assert.hpp>
8 
9 
10 #include <boost/filesystem.hpp>
11 
12 namespace irods {
13 
14 // =-=-=-=-=-=-=-
15 // predicate to determine if a char is not alphanumeric
16  static bool not_allowed_char( char _c ) {
17  return !std::isalnum( _c ) && !( '_' == _c ) && !( '-' == _c );
18  } // not_allowed_char
19 
20  std::string normalize_resource_type(const std::string& resource_type) {
21  std::string normalized_resource_type = resource_type;
22  normalized_resource_type.erase(std::remove_if(normalized_resource_type.begin(),
23  normalized_resource_type.end(),
25  normalized_resource_type.end());
26  return normalized_resource_type;
27  }
28 
30  // TODO - stub
31  }
32 
34  // TODO - stub
35  }
36 
38  const std::string& _base_name,
39  const std::string& _dir_name,
40  std::string& _rtn_soname ) {
41  error result = SUCCESS();
42 
43  // =-=-=-=-=-=-=-
44  // strip out all non alphanumeric characters like spaces or such
45  std::string clean_plugin_name = _base_name;
46  clean_plugin_name.erase( std::remove_if( clean_plugin_name.begin(),
47  clean_plugin_name.end(),
49  clean_plugin_name.end() );
50 
51  // =-=-=-=-=-=-=-
52  // quick parameter check
53  if ( clean_plugin_name.empty() ) {
54  std::stringstream msg;
55  msg << __FUNCTION__;
56  msg << " - Clean plugin name is empty.";
57  result = ERROR( SYS_INVALID_INPUT_PARAM, msg.str() );
58  }
59  else {
60 
61  // construct the actual .so name
62  _rtn_soname = _dir_name + std::string( "lib" ) + clean_plugin_name + std::string( ".so" );
63  }
64 
65  return result;
66  }
67 
69  const std::string& _base_name,
70  const std::string& _dir_name ) {
71  bool result = true;
72  std::string so_name;
73  error ret = ( *this )( _base_name, _dir_name, so_name );
74  if ( !ret.ok() ) {
75  result = false;
76  }
77  else {
78  boost::filesystem::path lib_path( so_name );
79  if ( !boost::filesystem::exists( lib_path ) ) {
80  result = false;
81  }
82  }
83 
84  return result;
85  }
86 
88  const std::string& _dir_name,
89  plugin_list_t& _list ) {
90  error result = SUCCESS();
91  if ( _dir_name.empty() ) {
92  std::stringstream msg;
93  msg << __FUNCTION__;
94  msg << " - Directory name is empty.";
95  result = ERROR( -1, msg.str() );
96  }
97  else {
98  boost::filesystem::path so_dir( _dir_name );
99  if ( boost::filesystem::exists( so_dir ) ) {
100  _list.clear();
101  for ( boost::filesystem::directory_iterator it( so_dir );
102  result.ok() && it != boost::filesystem::directory_iterator();
103  ++it ) {
104  boost::filesystem::path entry = it->path();
105  std::string plugin_name;
106  error ret = generate_plugin_name( entry.filename().string(), plugin_name );
107  if ( ret.ok() ) {
108  // plugin_name is empty if the dir entry was not a proper .so
109  if ( !plugin_name.empty() ) {
110  _list.push_back( plugin_name );
111  }
112  }
113  else {
114  std::stringstream msg;
115  msg << __FUNCTION__;
116  msg << " - An error occurred while generating plugin name from filename \"";
117  msg << entry.filename();
118  msg << "\"";
119  result = PASSMSG( msg.str(), ret );
120  }
121  }
122  }
123  else {
124  std::stringstream msg;
125  msg << __FUNCTION__;
126  msg << " - Plugin directory \"";
127  msg << _dir_name;
128  msg << "\" does not exist.";
129  result = ERROR( -1, msg.str() );
130  }
131  }
132  return result;
133  }
134 
136  const std::string& filename,
137  std::string& _rtn_name ) {
138  error result = SUCCESS();
139  _rtn_name.clear();
140  int sub_length = filename.length() - 6;
141  if ( sub_length > 0 &&
142  filename.find( "lib" ) == 0 &&
143  filename.find( ".so" ) == ( filename.length() - 3 ) ) {
144  _rtn_name = filename.substr( 3, sub_length );
145  }
146  return result;
147  }
148 
149 }; // namespace irods
irods::normalize_resource_type
std::string normalize_resource_type(const std::string &resource_type)
Definition: irods_plugin_name_generator.cpp:20
irods::not_allowed_char
static bool not_allowed_char(char _c)
Definition: irods_plugin_name_generator.cpp:16
irods::plugin_name_generator::exists
bool exists(const std::string &_base_name, const std::string &_dir_name)
Definition: irods_plugin_name_generator.cpp:68
irods::plugin_name_generator::plugin_list_t
std::vector< std::string > plugin_list_t
Definition: irods_plugin_name_generator.hpp:19
irods::experimental::administration::client::v1::exists
auto exists(rcComm_t &conn, const user &user) -> bool
Definition: user_administration.cpp:359
PASSMSG
#define PASSMSG(message_, prev_error_)
Definition: irods_error.hpp:119
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
irods
Definition: apiHandler.hpp:35
irods::plugin_name_generator::operator()
virtual error operator()(const std::string &_base_name, const std::string &_dir_name, std::string &_rtn_soname)
Definition: irods_plugin_name_generator.cpp:37
irods::plugin_name_generator::~plugin_name_generator
virtual ~plugin_name_generator(void)
Definition: irods_plugin_name_generator.cpp:33
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
irods::error
Definition: irods_error.hpp:23
irods::plugin_name_generator::list_plugins
error list_plugins(const std::string &_dir_name, plugin_list_t &_list)
Definition: irods_plugin_name_generator.cpp:87
irods::plugin_name_generator::plugin_name_generator
plugin_name_generator(void)
Definition: irods_plugin_name_generator.cpp:29
irods_plugin_name_generator.hpp
irods::plugin_name_generator::generate_plugin_name
error generate_plugin_name(const std::string &filename, std::string &_rtn_name)
Definition: irods_plugin_name_generator.cpp:135
entry
Definition: ruleAdmin.cpp:22
rodsErrorTable.h
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_log.hpp