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)  

rsIESClientHints.cpp
Go to the documentation of this file.
1 #include "rcMisc.h"
2 #include "rsGlobalExtern.hpp"
3 #include "rodsErrorTable.h"
4 #include "miscServerFunct.hpp"
5 #include "specificQuery.h"
6 #include "miscServerFunct.hpp"
7 #include "rsIESClientHints.hpp"
8 #include "rsSpecificQuery.hpp"
9 
10 #include "irods_log.hpp"
11 #include "zone_report.h"
12 #include "ies_client_hints.h"
16 
17 #include "json.hpp"
18 
20 
21 int _rsIESClientHints( rsComm_t* _comm, bytesBuf_t** _bbuf );
22 
23 int rsIESClientHints( rsComm_t* _comm, bytesBuf_t** _bbuf )
24 {
25  rodsServerHost_t* rods_host;
26  int status = getAndConnRcatHost( _comm, MASTER_RCAT, nullptr, &rods_host );
27  if ( status < 0 ) {
28  return status;
29  }
30 
31  if ( rods_host->localFlag == LOCAL_HOST ) {
32  std::string svc_role;
33  irods::error ret = get_catalog_service_role(svc_role);
34  if(!ret.ok()) {
35  irods::log(PASS(ret));
36  return ret.code();
37  }
38 
39  if ( irods::CFG_SERVICE_ROLE_PROVIDER == svc_role ) {
40  status = _rsIESClientHints( _comm, _bbuf );
41  }
42  else if ( irods::CFG_SERVICE_ROLE_CONSUMER == svc_role ) {
44  }
45  else {
46  rodsLog( LOG_ERROR, "role not supported [%s]", svc_role.c_str() );
48  }
49  }
50  else {
51  status = rcIESClientHints( rods_host->conn, _bbuf );
52  }
53 
54  if ( status < 0 ) {
55  rodsLog( LOG_ERROR, "rsIESClientHints: rcIESClientHints failed, status = %d", status );
56  }
57 
58  return status;
59 } // rsIESClientHints
60 
61 irods::error get_strict_acls( rsComm_t* _comm, std::string& _acls )
62 {
63  if ( ! _comm ) {
64  return ERROR( SYS_INVALID_INPUT_PARAM, "comm is null" );
65  }
66 
67  try {
68  _acls = irods::get_server_property<const std::string>(irods::STRICT_ACL_KW);
69  }
70  catch ( const irods::exception& e ) {
71  return irods::error(e);
72  }
73 
74  return SUCCESS();
75 } // get_strict_acls
76 
78 {
79  if ( !_comm ) {
80  return ERROR( SYS_INVALID_INPUT_PARAM, "comm is null" );
81  }
82 
83  _queries = json::array();
84 
85  specificQueryInp_t spec_inp;
86  memset( &spec_inp, 0, sizeof( specificQueryInp_t ) );
87 
88  spec_inp.maxRows = MAX_SQL_ROWS;
89  spec_inp.continueInx = 0;
90  spec_inp.sql = "ls";
91 
92  genQueryOut_t* gen_out = 0;
93  int status = rsSpecificQuery( _comm, &spec_inp, &gen_out );
94  if ( status < 0 ) {
95  return ERROR( status, "rsSpecificQuery for 'ls' failed" );
96  }
97 
98  // first attribute is the alias of the specific query
99  int len = gen_out->sqlResult[ 0 ].len;
100  char* values = gen_out->sqlResult[ 0 ].value;
101 
102  for ( int i = 0 ; i < gen_out->rowCnt ; ++i ) {
103  char* alias = &values[ len * i ];
104  _queries.push_back(alias);
105  } // for i
106 
107  freeGenQueryOut( &gen_out );
108 
109  return SUCCESS();
110 } // get_query_array
111 
112 int _rsIESClientHints( rsComm_t* _comm, bytesBuf_t** _bbuf )
113 {
114  if ( ! _comm ) {
116  }
117 
118  auto ies_hints = json::object();
119 
120  std::string acls;
121  irods::error ret = get_strict_acls( _comm, acls );
122  if ( !ret.ok() ) {
123  irods::log( PASS( ret ) );
124  }
125 
126  ies_hints["strict_acls"] = acls;
127 
128  auto query_arr = json::array();
129  ret = get_query_array( _comm, query_arr );
130  if ( !ret.ok() ) {
131  irods::log( PASS( ret ) );
132  }
133  ies_hints["specific_queries"] = query_arr;
134 
135  const auto hints = ies_hints.dump(4);
136  char* tmp_buf = new char[hints.length() + 1]{};
137  std::strncpy(tmp_buf, hints.c_str(), hints.length());
138 
139  *_bbuf = (bytesBuf_t*) malloc(sizeof(bytesBuf_t));
140  if (!*_bbuf) {
141  delete [] tmp_buf;
142  rodsLog( LOG_ERROR, "_rsIESClientHints: failed to allocate _bbuf" );
143  return SYS_MALLOC_ERR;
144  }
145 
146  ( *_bbuf )->buf = tmp_buf;
147  ( *_bbuf )->len = hints.length();
148 
149  return 0;
150 } // _rsIESClientHints
151 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
specificQueryInp_t::maxRows
int maxRows
Definition: specificQuery.h:13
MAX_SQL_ROWS
#define MAX_SQL_ROWS
Definition: rodsGenQuery.h:16
rsComm_t
Definition: rcConnect.h:145
irods::CFG_SERVICE_ROLE_CONSUMER
const std::string CFG_SERVICE_ROLE_CONSUMER("consumer")
rodsServerHost::localFlag
int localFlag
Definition: rodsConnect.h:68
SYS_SERVICE_ROLE_NOT_SUPPORTED
@ SYS_SERVICE_ROLE_NOT_SUPPORTED
Definition: rodsErrorTable.h:217
irods_server_properties.hpp
SYS_MALLOC_ERR
@ SYS_MALLOC_ERR
Definition: rodsErrorTable.h:84
rodsServerHost::conn
rcComm_t * conn
Definition: rodsConnect.h:64
rsIESClientHints
int rsIESClientHints(rsComm_t *_comm, bytesBuf_t **_bbuf)
Definition: rsIESClientHints.cpp:23
PASS
#define PASS(prev_error_)
Definition: irods_error.hpp:118
specificQueryInp_t::continueInx
int continueInx
Definition: specificQuery.h:14
rcMisc.h
LOCAL_HOST
#define LOCAL_HOST
Definition: rodsConnect.h:44
irods_resource_backport.hpp
json
nlohmann::json json
Definition: group.cpp:5
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
json
nlohmann::json json
Definition: rsIESClientHints.cpp:19
GenQueryOut::sqlResult
sqlResult_t sqlResult[50]
Definition: rodsGenQuery.h:72
specificQueryInp_t
Definition: specificQuery.h:8
rsIESClientHints.hpp
rsSpecificQuery
int rsSpecificQuery(rsComm_t *rsComm, specificQueryInp_t *specificQueryInp, genQueryOut_t **genQueryOut)
Definition: rsSpecificQuery.cpp:16
SUCCESS
#define SUCCESS()
Definition: irods_error.hpp:121
rsGlobalExtern.hpp
irods::error::code
long long code() const
Definition: irods_error.cpp:194
rsSpecificQuery.hpp
specificQueryInp_t::sql
char * sql
Definition: specificQuery.h:9
irods::CFG_SERVICE_ROLE_PROVIDER
const std::string CFG_SERVICE_ROLE_PROVIDER("provider")
irods::STRICT_ACL_KW
const std::string STRICT_ACL_KW("strict_acls")
terminate_irods_processes.e
e
Definition: terminate_irods_processes.py:19
SYS_NO_RCAT_SERVER_ERR
@ SYS_NO_RCAT_SERVER_ERR
Definition: rodsErrorTable.h:110
get_strict_acls
irods::error get_strict_acls(rsComm_t *_comm, std::string &_acls)
Definition: rsIESClientHints.cpp:61
GenQueryOut
Definition: rodsGenQuery.h:67
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
GenQueryOut::rowCnt
int rowCnt
Definition: rodsGenQuery.h:68
irods::log
void log(const error &)
Definition: irods_log.cpp:13
ERROR
#define ERROR(code_, message_)
Definition: irods_error.hpp:117
BytesBuf
Definition: rodsDef.h:197
irods::error
Definition: irods_error.hpp:23
miscServerFunct.hpp
getAndConnRcatHost
int getAndConnRcatHost(rsComm_t *rsComm, int rcatType, const char *rcatZoneHint, rodsServerHost_t **rodsServerHost)
Definition: rodsConnect.cpp:26
rcIESClientHints
int rcIESClientHints(rcComm_t *server_comm_ptr, bytesBuf_t **json_response)
Definition: rcIESClientHints.cpp:6
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
specificQuery.h
_rsIESClientHints
int _rsIESClientHints(rsComm_t *_comm, bytesBuf_t **_bbuf)
Definition: rsIESClientHints.cpp:112
MASTER_RCAT
#define MASTER_RCAT
Definition: rodsDef.h:85
get_catalog_service_role
irods::error get_catalog_service_role(std::string &_role)
Definition: miscServerFunct.cpp:3153
rodsServerHost
Definition: rodsConnect.h:62
zone_report.h
error
int error
Definition: filesystem.cpp:101
irods_resource_manager.hpp
get_query_array
irods::error get_query_array(rsComm_t *_comm, json &_queries)
Definition: rsIESClientHints.cpp:77
irods::exception
Definition: irods_exception.hpp:15
SqlResult::len
int len
Definition: rodsGenQuery.h:63
rodsErrorTable.h
freeGenQueryOut
int freeGenQueryOut(genQueryOut_t **genQueryOut)
Definition: rcMisc.cpp:1133
irods::error::ok
bool ok()
Definition: irods_error.cpp:258
irods_log.hpp
ies_client_hints.h