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)  

keyValPairMS.cpp
Go to the documentation of this file.
1 
6 
8 //#include "reGlobalsExtern.hpp"
9 //#include "reFuncDefs.hpp"
11 #include "rcMisc.h"
12 
13 #include "irods_re_structs.hpp"
14 
46 int msiGetValByKey( msParam_t* inKVPair, msParam_t* inKey, msParam_t* outVal, ruleExecInfo_t *rei ) {
47  keyValPair_t *kvp;
48  char *s, *k;
49 
50  RE_TEST_MACRO( "msiGetValByKey" );
51 
52  kvp = ( keyValPair_t* )inKVPair->inOutStruct;
53  k = ( char* )inKey->inOutStruct;
54  if ( k == NULL ) {
55  k = inKey->label;
56  }
57 
58  s = getValByKey( kvp, k );
59  if ( s == NULL ) {
61  }
62  fillStrInMsParam( outVal, s );
63  return 0;
64 }
65 
100 int msiPrintKeyValPair( msParam_t* where, msParam_t* inkvpair, ruleExecInfo_t *rei ) {
101  int i, l, m, j;
102  keyValPair_t *k;
103  char *s;
104  msParam_t tms;
105 
106  RE_TEST_MACRO( "msiPrintKeyValPair" );
107 
108  m = 0;
109  s = NULL;
110  k = ( keyValPair_t* )inkvpair->inOutStruct;
111 
112  for ( i = 0; i < k->len; i++ ) {
113  l = strlen( k->keyWord[i] ) + strlen( k->value[i] ) + 10;
114  if ( l > m ) {
115  if ( m > 0 ) {
116  free( s );
117  }
118  s = ( char* )malloc( l );
119  m = l;
120  }
121  sprintf( s, "%s = %s\n", k->keyWord[i], k->value[i] );
122  tms.inOutStruct = s;
123  j = writeString( where, &tms, rei );
124  if ( j < 0 ) {
125  free( s );
126  return j;
127  }
128  }
129  if ( m > 0 ) {
130  free( s );
131  }
132  return 0;
133 }
134 
165 int msiString2KeyValPair( msParam_t *inBufferP, msParam_t* outKeyValPairP, ruleExecInfo_t *rei ) {
166  keyValPair_t *kvp;
167  strArray_t strArray;
168  char *buf;
169  char *value;
170  int i, j;
171  char *valPtr;
172  char *tmpPtr;
173 
174  RE_TEST_MACRO( "msiString2KeyValPair" );
175 
176  buf = strdup( ( char * ) inBufferP->inOutStruct );
177  memset( &strArray, 0, sizeof( strArray_t ) );
178  i = parseMultiStr( buf, &strArray );
179  free( buf );
180  if ( i < 0 ) {
181  return i;
182  }
183  value = strArray.value;
184 
185  kvp = ( keyValPair_t* )malloc( sizeof( keyValPair_t ) );
186  memset(kvp, 0, sizeof(keyValPair_t));
187  for ( i = 0; i < strArray.len; i++ ) {
188  valPtr = &value[i * strArray.size];
189  if ( ( tmpPtr = strstr( valPtr, "=" ) ) != NULL ) {
190  *tmpPtr = '\0';
191  tmpPtr++;
192  j = addKeyVal( kvp, valPtr, tmpPtr );
193  if ( j < 0 ) {
194  return j;
195  }
196  *tmpPtr = '=';
197  }
198  }
199  outKeyValPairP->inOutStruct = ( void * ) kvp;
200  outKeyValPairP->type = strdup( KeyValPair_MS_T );
201 
202  return 0;
203 }
204 
235 int msiString2StrArray( msParam_t *inBufferP, msParam_t* outStrArrayP, ruleExecInfo_t *rei ) {
236  strArray_t *strArray;
237  char *buf;
238  int i;
239 
240  RE_TEST_MACRO( "msiString2StrArray" );
241 
242  if ( inBufferP == NULL || inBufferP->inOutStruct == NULL ||
243  inBufferP->type == NULL || strcmp( inBufferP->type, STR_MS_T ) != 0 ) {
244  return USER_PARAM_TYPE_ERR;
245  }
246 
247  buf = strdup( ( char * ) inBufferP->inOutStruct );
248  strArray = ( strArray_t * ) malloc( sizeof( strArray_t ) );
249  memset(strArray, 0, sizeof(strArray_t));
250  i = parseMultiStr( buf, strArray );
251  free( buf );
252  if ( i < 0 ) {
253  free( strArray );
254  return i;
255  }
256  outStrArrayP->inOutStruct = ( void * ) strArray;
257  outStrArrayP->type = strdup( StrArray_MS_T );
258 
259  return 0;
260 }
261 
262 
293 int msiStrArray2String( msParam_t* inSAParam, msParam_t* outStr, ruleExecInfo_t *rei ) {
294  int i;
295  strArray_t *strArr;
296  char *s;
297  char *val;
298 
299  RE_TEST_MACRO( "msiStrArray2String" );
300 
301  strArr = ( strArray_t * ) inSAParam->inOutStruct;
302  val = strArr->value;
303  s = ( char * ) malloc( strArr->len * strArr->size );
304  s[0] = '\0';
305 
306  strcat( s, val );
307  for ( i = 1; i < strArr->len; i++ ) {
308  strcat( s, "%" );
309  strcat( s, &val[i * strArr->size] );
310  }
311  outStr->inOutStruct = ( void * ) strdup( s );
312  outStr->type = strdup( STR_MS_T );
313  free( s );
314  return 0;
315 }
316 
317 
318 
350 int msiAddKeyVal( msParam_t *inKeyValPair, msParam_t *key, msParam_t *value, ruleExecInfo_t *rei ) {
351  char *key_str, *value_str;
352  keyValPair_t *newKVP;
353 
354 
356  /* For testing mode when used with irule --test */
357  RE_TEST_MACRO( " Calling msiAddKeyVal" )
358 
359  /* Sanity checks */
360  if ( rei == NULL || rei->rsComm == NULL ) {
361  rodsLog( LOG_ERROR, "msiAddKeyVal: input rei or rsComm is NULL." );
363  }
364 
365 
366 
368  /* Parse key */
369  if ( ( key_str = parseMspForStr( key ) ) == NULL ) {
370  rodsLog( LOG_ERROR, "msiAddKeyVal: input key is NULL." );
371  return USER__NULL_INPUT_ERR;
372  }
373 
374  /* Parse value */
375  value_str = parseMspForStr( value );
376 
377  /* Check for wrong parameter type */
378  if ( inKeyValPair->type && strcmp( inKeyValPair->type, KeyValPair_MS_T ) ) {
379  rodsLog( LOG_ERROR, "msiAddKeyVal: inKeyValPair is not of type KeyValPair_MS_T." );
380  return USER_PARAM_TYPE_ERR;
381  }
382 
383  /* Parse inKeyValPair. Create new one if empty. */
384  if ( !inKeyValPair->inOutStruct ) {
385  /* Set content */
386  newKVP = ( keyValPair_t* )malloc( sizeof( keyValPair_t ) );
387  memset( newKVP, 0, sizeof( keyValPair_t ) );
388  inKeyValPair->inOutStruct = ( void* )newKVP;
389 
390  /* Set type */
391  if ( !inKeyValPair->type ) {
392  inKeyValPair->type = strdup( KeyValPair_MS_T );
393  }
394  }
395 
396 
397 
399  rei->status = addKeyVal( ( keyValPair_t* )inKeyValPair->inOutStruct, key_str, value_str );
400 
401  /* Done */
402  return rei->status;
403 }
404 
405 
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
getValByKey
char * getValByKey(const keyValPair_t *condInput, const char *keyWord)
Definition: rcMisc.cpp:675
NULL
#define NULL
Definition: rodsDef.h:70
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
SYS_INTERNAL_NULL_INPUT_ERR
@ SYS_INTERNAL_NULL_INPUT_ERR
Definition: rodsErrorTable.h:92
UNMATCHED_KEY_OR_INDEX
@ UNMATCHED_KEY_OR_INDEX
Definition: rodsErrorTable.h:244
msiPrintKeyValPair
int msiPrintKeyValPair(msParam_t *where, msParam_t *inkvpair, ruleExecInfo_t *rei)
Definition: keyValPairMS.cpp:100
RuleExecInfo::status
int status
Definition: irods_re_structs.hpp:19
rcMisc.h
parseMspForStr
char * parseMspForStr(msParam_t *inpParam)
Definition: msParam.cpp:893
parseMultiStr
int parseMultiStr(char *strInput, strArray_t *strArray)
Definition: rcMisc.cpp:1539
LOG_ERROR
#define LOG_ERROR
Definition: rodsLog.h:43
MsParam::type
char * type
Definition: msParam.h:78
STR_MS_T
#define STR_MS_T
Definition: msParam.h:21
StrArray_MS_T
#define StrArray_MS_T
Definition: msParam.h:44
StrArray::len
int len
Definition: objInfo.h:221
RuleExecInfo::rsComm
rsComm_t * rsComm
Definition: irods_re_structs.hpp:22
KeyValPair::value
char ** value
Definition: objInfo.h:123
msiString2StrArray
int msiString2StrArray(msParam_t *inBufferP, msParam_t *outStrArrayP, ruleExecInfo_t *rei)
Definition: keyValPairMS.cpp:235
msiGetValByKey
int msiGetValByKey(msParam_t *inKVPair, msParam_t *inKey, msParam_t *outVal, ruleExecInfo_t *rei)
Definition: keyValPairMS.cpp:46
KeyValPair::keyWord
char ** keyWord
Definition: objInfo.h:122
get_irods_version.value
dictionary value
Definition: get_irods_version.py:27
MsParam
Definition: msParam.h:76
writeString
int writeString(msParam_t *where, msParam_t *inString, ruleExecInfo_t *rei)
Definition: irods_re_structs.cpp:311
MsParam::label
char * label
Definition: msParam.h:77
get_db_schema_version.l
l
Definition: get_db_schema_version.py:19
USER_PARAM_TYPE_ERR
@ USER_PARAM_TYPE_ERR
Definition: rodsErrorTable.h:254
StrArray::size
int size
Definition: objInfo.h:222
fillStrInMsParam
void fillStrInMsParam(msParam_t *msParam, const char *myStr)
Definition: msParam.cpp:278
KeyValPair_MS_T
#define KeyValPair_MS_T
Definition: msParam.h:37
RuleExecInfo
Definition: irods_re_structs.hpp:18
irods_re_structs.hpp
RE_TEST_MACRO
#define RE_TEST_MACRO(msg)
Definition: reDefines.h:58
KeyValPair::len
int len
Definition: objInfo.h:121
StrArray::value
char * value
Definition: objInfo.h:223
icatHighLevelRoutines.hpp
msiStrArray2String
int msiStrArray2String(msParam_t *inSAParam, msParam_t *outStr, ruleExecInfo_t *rei)
Definition: keyValPairMS.cpp:293
msiAddKeyVal
int msiAddKeyVal(msParam_t *inKeyValPair, msParam_t *key, msParam_t *value, ruleExecInfo_t *rei)
Definition: keyValPairMS.cpp:350
MsParam::inOutStruct
void * inOutStruct
Definition: msParam.h:80
KeyValPair
Definition: objInfo.h:120
buf
static char buf[64+50+1]
Definition: rsAuthRequest.cpp:21
msiString2KeyValPair
int msiString2KeyValPair(msParam_t *inBufferP, msParam_t *outKeyValPairP, ruleExecInfo_t *rei)
Definition: keyValPairMS.cpp:165
StrArray
Definition: objInfo.h:220
USER__NULL_INPUT_ERR
@ USER__NULL_INPUT_ERR
Definition: rodsErrorTable.h:247