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)  

reVariableMap.cpp
Go to the documentation of this file.
1 
4 #include "reFuncDefs.hpp"
5 #include "reGlobalsExtern.hpp"
6 #include "conversion.hpp"
7 #include "reVariableMap.gen.hpp"
8 #include "reVariables.hpp"
9 #include "rcMisc.h"
10 #ifdef DEBUG
11 #include "re.hpp"
12 #endif
13 
14 int getIntLeafValue( Res **varValue, int leaf, Region *r ) {
15  *varValue = newIntRes( r, leaf );
16  return 0;
17 }
18 int getStrLeafValue( Res **varValue, char *leaf, Region *r ) {
19  *varValue = newStringRes( r, leaf );
20  return 0;
21 }
22 int getLongLeafValue( Res **varValue, rodsLong_t leaf, Region *r ) {
23  *varValue = newDoubleRes( r, leaf );
24  return 0;
25 }
26 int getPtrLeafValue( Res **varValue, void *leaf, bytesBuf_t *buf, char *irodsType, Region *r ) {
27  *varValue = newUninterpretedRes( r, irodsType, leaf, buf );
28  return 0;
29 }
30 int setBufferPtrLeafValue( bytesBuf_t **leafPtr, Res *newVarValue ) {
31  *leafPtr = RES_UNINTER_BUFFER( newVarValue );
32  return 0;
33 }
34 int setIntLeafValue( int *leafPtr, Res *newVarValue ) {
35  *leafPtr = RES_INT_VAL( newVarValue );
36  return 0;
37 }
38 int setStrLeafValue( char *leafPtr, size_t len, Res *newVarValue ) {
39  rstrcpy( leafPtr, newVarValue->text, len );
40  return 0;
41 }
42 int setStrDupLeafValue( char **leafPtr, Res *newVarValue ) {
43  if ( *leafPtr != NULL ) {
44  free( *leafPtr );
45  }
46  *leafPtr = strdup( newVarValue->text );
47  return 0;
48 }
49 int setLongLeafValue( rodsLong_t *leafPtr, Res *newVarValue ) {
50  *leafPtr = ( long )RES_DOUBLE_VAL( newVarValue );
51  return 0;
52 }
53 int setStructPtrLeafValue( void **leafPtr, Res *newVarValue ) {
54  *leafPtr = RES_UNINTER_STRUCT( newVarValue );
55  return 0;
56 }
57 int
58 mapExternalFuncToInternalProc( char *funcName ) {
59  int i;
60 
61  for ( i = 0; i < appRuleFuncMapDef.MaxNumOfFMaps; i++ ) {
62  if ( strstr( appRuleFuncMapDef.funcName[i], funcName ) != NULL ) {
63  strcpy( funcName, appRuleFuncMapDef.func2CMap[i] );
64  return 1;
65  }
66  }
67  for ( i = 0; i < coreRuleFuncMapDef.MaxNumOfFMaps; i++ ) {
68  if ( strstr( coreRuleFuncMapDef.funcName[i], funcName ) != NULL ) {
69  strcpy( funcName, coreRuleFuncMapDef.func2CMap[i] );
70  return 1;
71  }
72  }
73  return 0;
74 }
75 
76 int
77 getVarMap( char *action, char *inVarName, char **varMap, int index ) {
78  int i;
79  char *varName;
80 
81  if ( inVarName[0] == '$' ) {
82  varName = inVarName + 1;
83  }
84  else {
85  varName = inVarName;
86  }
87  if ( index < 1000 ) {
88  for ( i = index; i < appRuleVarDef.MaxNumOfDVars; i++ ) {
89  if ( !strcmp( appRuleVarDef.varName[i], varName ) ) {
90  if ( strlen( appRuleVarDef.action[i] ) == 0 ||
91  strstr( appRuleVarDef.action[i], action ) != NULL ) {
92  *varMap = strdup( appRuleVarDef.var2CMap[i] );
93  return i;
94  }
95  }
96  }
97  index = 1000;
98  }
99  i = index - 1000;
100  for ( ; i < coreRuleVarDef.MaxNumOfDVars; i++ ) {
101  if ( !strcmp( coreRuleVarDef.varName[i], varName ) ) {
102  if ( strlen( coreRuleVarDef.action[i] ) == 0 ||
103  strstr( coreRuleVarDef.action[i], action ) != NULL ) {
104  *varMap = strdup( coreRuleVarDef.var2CMap[i] );
105  return i + 1000;
106  }
107  }
108  }
110 }
111 
112 
113 
114 int
115 getVarNameFromVarMap( char *varMap, char *varName, char **varMapCPtr ) {
116 
117  char *p;
118 
119  if ( ( p = strstr( varMap, "->" ) ) == NULL ) {
120  rstrcpy( varName, varMap, NAME_LEN );
121  *varMapCPtr = NULL;
122  }
123  else {
124  *p = '\0';
125  rstrcpy( varName, varMap, NAME_LEN );
126  *p = '-';
127  p++;
128  p++;
129  *varMapCPtr = p;
130  }
131  trimWS( varName );
132  return 0;
133 
134 }
135 
136 ExprType *getVarType( char *varMap, Region *r ) {
137  char varName[NAME_LEN];
138  char *varMapCPtr;
139  int i;
140 
141  i = getVarNameFromVarMap( varMap, varName, &varMapCPtr );
142  if ( i != 0 ) {
143  return newErrorRes( r, i );
144  }
145 
146  if ( strcmp( varName, "rei" ) == 0 ) {
147  return getVarTypeFromRuleExecInfo( varMapCPtr, r );
148  }
149  else {
151  }
152 
153 }
154 int
155 getVarValue( char *varMap, ruleExecInfo_t *rei, Res **varValue, Region *r ) {
156 
157  char varName[NAME_LEN];
158  char *varMapCPtr;
159  int i;
160 
161  i = getVarNameFromVarMap( varMap, varName, &varMapCPtr );
162  if ( i != 0 ) {
163  return i;
164  }
165 
166  if ( !strcmp( varName, "rei" ) ) {
167  i = getValFromRuleExecInfo( varMapCPtr, rei, varValue, r );
168  return i;
169  }
170  else {
172  }
173 }
174 
175 int
176 setVarValue( char *varMap, ruleExecInfo_t *rei, Res *newVarValue ) {
177  char varName[NAME_LEN];
178  char *varMapCPtr;
179  int status = getVarNameFromVarMap( varMap, varName, &varMapCPtr );
180  if ( status != 0 ) {
181  return status;
182  }
183  if ( !strcmp( varName, "rei" ) ) {
184  return setValFromRuleExecInfo( varMapCPtr, &rei, newVarValue );
185  }
186  else {
188  }
189 }
190 
191 
192 
193 
194 
378 int
380  int i, status;
381  char *varValue;
382  char *lastVar = NULL; /* last var that has data */
383 
384  if ( varKeyVal == NULL || rei == NULL ) {
386  "getAllSessionVarValue: input rei or varKeyVal is NULL" );
388  }
389 
390  for ( i = 0; i < coreRuleVarDef.MaxNumOfDVars; i++ ) {
391  if ( lastVar == NULL || strcmp( lastVar, coreRuleVarDef.varName[i] ) != 0 ) {
393  &varValue );
394  if ( status >= 0 && varValue != NULL ) {
395  lastVar = coreRuleVarDef.varName[i];
396  addKeyVal( varKeyVal, lastVar, varValue );
397  free( varValue );
398  }
399  }
400  }
401  return 0;
402 }
403 
404 int
405 getSessionVarValue( char *action, char *varName, ruleExecInfo_t *rei,
406  char **varValue ) {
407  Region *r = make_region( 0, NULL );
408  char *varMap = NULL;
409  int vinx = getVarMap( action, varName, &varMap, 0 );
410  while ( vinx >= 0 ) {
411  Res *res;
412  int i = getVarValue( varMap, rei, &res, r );
413  free( varMap );
414  varMap = NULL;
415  if ( i != NULL_VALUE_ERR ) {
416  if ( i >= 0 ) {
417  *varValue = convertResToString( res );
418  }
419  region_free( r );
420  return i;
421  }
422  vinx = getVarMap( action, varName, &varMap, vinx + 1 );
423  }
424  free( varMap );
425  region_free( r );
426  return vinx;
427 }
428 
429 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getLongLeafValue
int getLongLeafValue(Res **varValue, rodsLong_t leaf, Region *r)
Definition: reVariableMap.cpp:22
NULL
#define NULL
Definition: rodsDef.h:70
reVariables.hpp
getVarValue
int getVarValue(char *varMap, ruleExecInfo_t *rei, Res **varValue, Region *r)
Definition: reVariableMap.cpp:155
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
convertResToString
char * convertResToString(Res *res0)
Definition: conversion.cpp:556
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
appRuleVarDef
rulevardef_t appRuleVarDef
Definition: libirods_rule_engine_plugin-irods_rule_language.cpp:51
getVarTypeFromRuleExecInfo
ExprType * getVarTypeFromRuleExecInfo(char *varMap, Region *r)
Definition: reVariableMap.gen.cpp:2046
coreRuleFuncMapDef
rulefmapdef_t coreRuleFuncMapDef
Definition: libirods_rule_engine_plugin-irods_rule_language.cpp:49
setValFromRuleExecInfo
int setValFromRuleExecInfo(char *varMap, ruleExecInfo_t **inrei, Res *newVarValue)
Definition: reVariableMap.gen.cpp:1906
getValFromRuleExecInfo
int getValFromRuleExecInfo(char *varMap, ruleExecInfo_t *inrei, Res **varValue, Region *r)
Definition: reVariableMap.gen.cpp:1753
getStrLeafValue
int getStrLeafValue(Res **varValue, char *leaf, Region *r)
Definition: reVariableMap.cpp:18
rulefmapdef_t::MaxNumOfFMaps
int MaxNumOfFMaps
Definition: reGlobalsExtern.hpp:113
getVarNameFromVarMap
int getVarNameFromVarMap(char *varMap, char *varName, char **varMapCPtr)
Definition: reVariableMap.cpp:115
UNDEFINED_VARIABLE_MAP_ERR
@ UNDEFINED_VARIABLE_MAP_ERR
Definition: rodsErrorTable.h:668
rcMisc.h
pid_age.p
p
Definition: pid_age.py:13
setVarValue
int setVarValue(char *varMap, ruleExecInfo_t *rei, Res *newVarValue)
Definition: reVariableMap.cpp:176
make_region
Region * make_region(size_t is, jmp_buf *label)
Definition: region.cpp:85
RES_DOUBLE_VAL
#define RES_DOUBLE_VAL(x)
Definition: restructs.hpp:57
node
Definition: restructs.hpp:244
getPtrLeafValue
int getPtrLeafValue(Res **varValue, void *leaf, bytesBuf_t *buf, char *irodsType, Region *r)
Definition: reVariableMap.cpp:26
reGlobalsExtern.hpp
coreRuleVarDef
rulevardef_t coreRuleVarDef
Definition: libirods_rule_engine_plugin-irods_rule_language.cpp:48
setLongLeafValue
int setLongLeafValue(rodsLong_t *leafPtr, Res *newVarValue)
Definition: reVariableMap.cpp:49
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
RES_UNINTER_BUFFER
#define RES_UNINTER_BUFFER(x)
Definition: restructs.hpp:66
run_tests.action
action
Definition: run_tests.py:114
conversion.hpp
setBufferPtrLeafValue
int setBufferPtrLeafValue(bytesBuf_t **leafPtr, Res *newVarValue)
Definition: reVariableMap.cpp:30
setStrDupLeafValue
int setStrDupLeafValue(char **leafPtr, Res *newVarValue)
Definition: reVariableMap.cpp:42
node::text
char * text
Definition: restructs.hpp:252
newIntRes
Res * newIntRes(Region *r, int n)
Definition: restructs.cpp:204
newUninterpretedRes
Res * newUninterpretedRes(Region *r, const char *typeName, void *ioStruct, bytesBuf_t *ioBuf)
Definition: restructs.cpp:183
newErrorRes
Res * newErrorRes(Region *r, int errcode)
Definition: restructs.cpp:259
irods.pypyodbc.long
long
Definition: pypyodbc.py:43
newDoubleRes
Res * newDoubleRes(Region *r, double a)
Definition: restructs.cpp:210
rulefmapdef_t::funcName
char * funcName[2048]
Definition: reGlobalsExtern.hpp:114
getSessionVarValue
int getSessionVarValue(char *action, char *varName, ruleExecInfo_t *rei, char **varValue)
Definition: reVariableMap.cpp:405
NULL_VALUE_ERR
@ NULL_VALUE_ERR
Definition: rodsErrorTable.h:669
getVarMap
int getVarMap(char *action, char *inVarName, char **varMap, int index)
Definition: reVariableMap.cpp:77
irods.pypyodbc.status
status
Definition: pypyodbc.py:467
mapExternalFuncToInternalProc
int mapExternalFuncToInternalProc(char *funcName)
Definition: reVariableMap.cpp:58
BytesBuf
Definition: rodsDef.h:197
region
Definition: region.h:45
trimWS
int trimWS(char *s)
Definition: stringOpr.cpp:260
RES_UNINTER_STRUCT
#define RES_UNINTER_STRUCT(x)
Definition: restructs.hpp:65
RES_INT_VAL
#define RES_INT_VAL(x)
Definition: restructs.hpp:58
getAllSessionVarValue
int getAllSessionVarValue(ruleExecInfo_t *rei, keyValPair_t *varKeyVal)
Definition: reVariableMap.cpp:379
rulevardef_t::MaxNumOfDVars
int MaxNumOfDVars
Definition: reGlobalsExtern.hpp:103
getIntLeafValue
int getIntLeafValue(Res **varValue, int leaf, Region *r)
Definition: reVariableMap.cpp:14
setStructPtrLeafValue
int setStructPtrLeafValue(void **leafPtr, Res *newVarValue)
Definition: reVariableMap.cpp:53
reVariableMap.gen.hpp
RuleExecInfo
Definition: irods_re_structs.hpp:18
UNKNOWN_VARIABLE_MAP_ERR
@ UNKNOWN_VARIABLE_MAP_ERR
Definition: rodsErrorTable.h:667
rulevardef_t::action
char * action[2048]
Definition: reGlobalsExtern.hpp:105
region_free
void region_free(Region *r)
Definition: region.cpp:146
appRuleFuncMapDef
rulefmapdef_t appRuleFuncMapDef
Definition: libirods_rule_engine_plugin-irods_rule_language.cpp:52
setStrLeafValue
int setStrLeafValue(char *leafPtr, size_t len, Res *newVarValue)
Definition: reVariableMap.cpp:38
setIntLeafValue
int setIntLeafValue(int *leafPtr, Res *newVarValue)
Definition: reVariableMap.cpp:34
rulevardef_t::varName
char * varName[2048]
Definition: reGlobalsExtern.hpp:104
rulevardef_t::var2CMap
char * var2CMap[2048]
Definition: reGlobalsExtern.hpp:106
rstrcpy
char * rstrcpy(char *dest, const char *src, int maxLen)
Definition: stringOpr.cpp:51
NAME_LEN
#define NAME_LEN
Definition: rodsDef.h:55
rulefmapdef_t::func2CMap
char * func2CMap[2048]
Definition: reGlobalsExtern.hpp:115
KeyValPair
Definition: objInfo.h:120
reFuncDefs.hpp
newStringRes
Res * newStringRes(Region *r, const char *s)
Definition: restructs.cpp:235
buf
static char buf[64+50+1]
Definition: rsAuthRequest.cpp:21
getVarType
ExprType * getVarType(char *varMap, Region *r)
Definition: reVariableMap.cpp:136
rodsLong_t
long long rodsLong_t
Definition: rodsType.h:32