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)  

extractAvuMS.cpp
Go to the documentation of this file.
1 
6 
9 //#include "reGlobalsExtern.hpp"
10 #include "rcMisc.h"
11 //#include "reFuncDefs.hpp"
12 #include "objMetaOpr.hpp"
13 #include "miscServerFunct.hpp"
14 
15 #if defined(solaris_platform)
16 #include <libgen.h>
17 #endif
18 
19 
20 #include <algorithm> // for std::find
21 #include <vector>
22 #include <string>
23 #include <regex.h>
24 
25 #include "irods_re_structs.hpp"
26 #include "rsModAVUMetadata.hpp"
27 
28 extern char *__loc1;
29 
30 
68 int
70 
71  bytesBuf_t *tmplObjBuf;
72  tagStruct_t *tagValues;
73 
74  char *t, *t1, *t2, *t3, *t4, *t5, *t6, *t7, *t8;
75  int i, j;
76  regex_t preg[4];
77  regmatch_t pm[4];
78  char errbuff[100];
79 
80  RE_TEST_MACRO( "Loopback on msiReadMDTemplateIntoTagStruct" );
81 
82  if ( strcmp( bufParam->type, BUF_LEN_MS_T ) != 0 ||
83  bufParam->inpOutBuf == NULL ) {
84  return USER_PARAM_TYPE_ERR;
85  }
86  tmplObjBuf = ( bytesBuf_t * ) bufParam->inpOutBuf;
87  j = regcomp( &preg[0], "<PRETAG>", REG_EXTENDED );
88  if ( j != 0 ) {
89  regerror( j, &preg[0], errbuff, sizeof( errbuff ) );
90  rodsLog( LOG_NOTICE, "msiReadMDTemplateIntoTagStruct: Error in regcomp: %s\n", errbuff );
91  return INVALID_REGEXP;
92  }
93  j = regcomp( &preg[1], "</PRETAG>", REG_EXTENDED );
94  if ( j != 0 ) {
95  regerror( j, &preg[1], errbuff, sizeof( errbuff ) );
96  rodsLog( LOG_NOTICE, "msiReadMDTemplateIntoTagStruct: Error in regcomp: %s\n", errbuff );
97  return INVALID_REGEXP;
98  }
99  j = regcomp( &preg[2], "<POSTTAG>", REG_EXTENDED );
100  if ( j != 0 ) {
101  regerror( j, &preg[2], errbuff, sizeof( errbuff ) );
102  rodsLog( LOG_NOTICE, "msiReadMDTemplateIntoTagStruct: Error in regcomp: %s\n", errbuff );
103  return INVALID_REGEXP;
104  }
105  j = regcomp( &preg[3], "</POSTTAG>", REG_EXTENDED );
106  if ( j != 0 ) {
107  regerror( j, &preg[3], errbuff, sizeof( errbuff ) );
108  rodsLog( LOG_NOTICE, "msiReadMDTemplateIntoTagStruct: Error in regcomp: %s\n", errbuff );
109  return INVALID_REGEXP;
110  }
111 
112  t = ( char* )malloc( tmplObjBuf->len + 1 );
113  t[tmplObjBuf->len] = '\0';
114  memcpy( t, tmplObjBuf->buf, tmplObjBuf->len );
115  tagValues = ( tagStruct_t* )malloc( sizeof( tagStruct_t ) );
116  memset(tagValues,0,sizeof(tagStruct_t));
117  tagValues->len = 0;
118  t1 = t;
119  while ( regexec( &preg[0], t1, 1, &pm[0], 0 ) == 0 ) {
120  t2 = t1 + pm[0].rm_eo ; /* t2 starts preTag */
121  if ( regexec( &preg[1], t2, 1, &pm[1], 0 ) != 0 ) {
122  break;
123  }
124  t3 = t2 + pm[1].rm_eo ; /* t3 starts keyValue */
125  t6 = t2 + pm[1].rm_so; /* t6 ends preTag */
126  *t6 = '\0';
127  if ( regexec( &preg[2], t3, 1, &pm[2], 0 ) != 0 ) {
128  break;
129  }
130  t5 = t3 + pm[2].rm_eo ; /* t5 starts postTag */
131  t4 = t3 + pm[2].rm_so; /* t4 ends keyValue */
132  *t4 = '\0';
133  if ( regexec( &preg[3], t5, 1, &pm[3], 0 ) != 0 ) {
134  break;
135  }
136  t7 = t5 + pm[3].rm_eo; /* t7 ends the line */
137  t8 = t5 + pm[3].rm_so; /* t8 ends postTag */
138  *t8 = '\0';
139 
140  i = addTagStruct( tagValues, t2, t5, t3 );
141  if ( i != 0 ) {
142  return i;
143  }
144  t1 = t7;
145  if ( *t1 == '\0' ) {
146  break;
147  }
148  }
149 
150  /*
151  free(preg[0]);
152  free(preg[1]);
153  free(preg[2]);
154  free(preg[3]);
155  */
156  regfree( &preg[0] );
157  regfree( &preg[1] );
158  regfree( &preg[2] );
159  regfree( &preg[3] );
160  free( t );
161 
162  if ( tagValues->len == 0 ) {
163  free( tagValues );
164  return NO_VALUES_FOUND;
165  }
166 
167  tagParam->inOutStruct = ( void * ) tagValues;
168  tagParam->type = strdup( TagStruct_MS_T );
169 
170  return 0;
171 
172 }
173 
209 int msiGetTaggedValueFromString( msParam_t *inTagParam, msParam_t *inStrParam,
210  msParam_t *outValueParam, ruleExecInfo_t* ) {
211 
212  int j;
213  regex_t preg[2];
214  regmatch_t pm[2];
215  char errbuff[100];
216  char *pstr[2];
217  char *t1, *t2, *t3;
218  char c;
219 
220  t1 = ( char * ) inStrParam->inOutStruct;
221  pstr[0] = ( char * ) malloc( strlen( ( char* )inTagParam->inOutStruct ) + 6 );
222  sprintf( pstr[0], "<%s>", ( char * ) inTagParam->inOutStruct );
223  j = regcomp( &preg[0], pstr[0], REG_EXTENDED );
224  if ( j != 0 ) {
225  regerror( j, &preg[0], errbuff, sizeof( errbuff ) );
226  rodsLog( LOG_NOTICE, "msiGetTaggedValueFromString: Error in regcomp: %s\n", errbuff );
227  regfree( &preg[0] );
228  free( pstr[0] );
229  return INVALID_REGEXP;
230  }
231  pstr[1] = ( char * ) malloc( strlen( ( char* )inTagParam->inOutStruct ) + 6 );
232  sprintf( pstr[1], "</%s>", ( char * ) inTagParam->inOutStruct );
233  j = regcomp( &preg[1], pstr[1], REG_EXTENDED );
234  if ( j != 0 ) {
235  regerror( j, &preg[1], errbuff, sizeof( errbuff ) );
236  rodsLog( LOG_NOTICE, "msiGetTaggedValueFromString: Error in regcomp: %s\n", errbuff );
237  regfree( &preg[0] );
238  regfree( &preg[1] );
239  free( pstr[0] );
240  free( pstr[1] );
241  return INVALID_REGEXP;
242  }
243  /* rodsLog (LOG_NOTICE,"TTTTT:%s",t1);*/
244  if ( regexec( &preg[0], t1, 1, &pm[0], 0 ) == 0 ) {
245  t2 = t1 + pm[0].rm_eo ; /* t2 starts value */
246  if ( regexec( &preg[1], t2, 1, &pm[1], 0 ) != 0 ) {
247  fillMsParam( outValueParam, NULL, STR_MS_T, 0, NULL );
248  }
249  else {
250  t3 = t2 + pm[1].rm_so; /* t3 ends value */
251  c = *t3;
252  *t3 = '\0';
253  fillMsParam( outValueParam, NULL, STR_MS_T, t2, NULL );
254  *t3 = c;
255  }
256  }
257  else {
258  fillMsParam( outValueParam, NULL, STR_MS_T, 0, NULL );
259  }
260  regfree( &preg[0] );
261  regfree( &preg[1] );
262  free( pstr[0] );
263  free( pstr[1] );
264  return 0;
265 }
266 
310 int
312  msParam_t *metadataParam, ruleExecInfo_t *rei ) {
313 
314 
315  bytesBuf_t *metaObjBuf;
316  tagStruct_t *tagValues;
317  keyValPair_t *metaDataPairs;
318  /* int l1, l2; */
319  int i, j;
320  /*char *preg[2]; */
321  regex_t preg[2];
322  regmatch_t pm[2];
323  char errbuff[100];
324  char *t, *t1, *t2, *t3, *t4;
325  char c;
326 
327  RE_TEST_MACRO( "Loopback on msiExtractTemplateMetadata" );
328 
329  if ( strcmp( bufParam->type, BUF_LEN_MS_T ) != 0 ||
330  bufParam->inpOutBuf == NULL ) {
331  return USER_PARAM_TYPE_ERR;
332  }
333  if ( strcmp( tagParam->type, TagStruct_MS_T ) != 0 ) {
334  return USER_PARAM_TYPE_ERR;
335  }
336  tagValues = ( tagStruct_t * ) tagParam->inOutStruct;
337  metaObjBuf = ( bytesBuf_t * ) bufParam->inpOutBuf;
338  t = ( char* )malloc( metaObjBuf->len + 1 );
339  t[metaObjBuf->len] = '\0';
340  memcpy( t, metaObjBuf->buf, metaObjBuf->len );
341  metaDataPairs = ( keyValPair_t* )malloc( sizeof( keyValPair_t ) );
342  memset(metaDataPairs,0,sizeof(keyValPair_t));
343  t1 = t;
344  for ( i = 0; i < tagValues->len ; i++ ) {
345  t1 = t;
346  j = regcomp( &preg[0], tagValues->preTag[i], REG_EXTENDED );
347  if ( j != 0 ) {
348  regerror( j, &preg[0], errbuff, sizeof( errbuff ) );
349  rodsLog( LOG_NOTICE, "msiExtractTemplateMDFromBuf: Error in regcomp: %s\n", errbuff );
350  clearKeyVal( metaDataPairs );
351  free( metaDataPairs );
352  free( t );
353  return INVALID_REGEXP;
354  }
355  j = regcomp( &preg[1], tagValues->postTag[i], REG_EXTENDED );
356  if ( j != 0 ) {
357  regerror( j, &preg[1], errbuff, sizeof( errbuff ) );
358  rodsLog( LOG_NOTICE, "msiExtractTemplateMDFromBuf: Error in regcomp: %s\n", errbuff );
359  clearKeyVal( metaDataPairs );
360  free( metaDataPairs );
361  free( t );
362  return INVALID_REGEXP;
363  }
364  while ( regexec( &preg[0], t1, 1, &pm[0], 0 ) == 0 ) {
365  t2 = t1 + pm[0].rm_eo ; /* t2 starts value */
366  if ( regexec( &preg[1], t2, 1, &pm[1], 0 ) != 0 ) {
367  break;
368  }
369  t4 = t2 + pm[1].rm_so; /* t4 ends value */
370  t3 = t2 + pm[1].rm_eo;
371  c = *t4;
372  *t4 = '\0';
373 
374  j = addKeyVal( metaDataPairs, tagValues->keyWord[i], t2 );
375  *t4 = c;
376  if ( j != 0 ) {
377  free( t );
378  return j;
379  }
380  t1 = t3;
381  if ( *t1 == '\0' ) {
382  break;
383  }
384  }
385  regfree( &preg[0] );
386  regfree( &preg[1] );
387 
388  continue;
389  }
390 
391  free( t );
392 
393  metadataParam->inOutStruct = ( void * ) metaDataPairs;
394  metadataParam->type = strdup( KeyValPair_MS_T );
395 
396  return 0;
397 }
398 
440 int
442  msParam_t* typeParam,
443  ruleExecInfo_t *rei ) {
444 
445 
446  char *objName;
447  char *objType;
448  /* int id, i;*/
449  int i;
450 
451  RE_TEST_MACRO( "Loopback on msiAssociateKeyValuePairsToObj" );
452 
453  if ( strcmp( metadataParam->type, KeyValPair_MS_T ) != 0 ) {
454  return USER_PARAM_TYPE_ERR;
455  }
456  if ( strcmp( objParam->type, STR_MS_T ) != 0 ) {
457  return USER_PARAM_TYPE_ERR;
458  }
459  if ( strcmp( typeParam->type, STR_MS_T ) != 0 ) {
460  return USER_PARAM_TYPE_ERR;
461  }
462  objName = ( char * ) objParam->inOutStruct;
463  objType = ( char * ) typeParam->inOutStruct;
464  i = addAVUMetadataFromKVPairs( rei->rsComm, objName, objType,
465  ( keyValPair_t * ) metadataParam->inOutStruct );
466  return i;
467 
468 }
469 
470 // =-=-=-=-=-=-=-
471 // JMC - backport 4836
513 int
514 msiSetKeyValuePairsToObj( msParam_t *metadataParam, msParam_t* objParam,
515  msParam_t* typeParam,
516  ruleExecInfo_t *rei ) {
517  char *objName;
518  char *objType;
519  int ret;
520 
521  RE_TEST_MACRO( "Loopback on msiSetKeyValuePairsToObj" );
522 
523  if ( strcmp( metadataParam->type, KeyValPair_MS_T ) != 0 ) {
524  return USER_PARAM_TYPE_ERR;
525  }
526  if ( strcmp( objParam->type, STR_MS_T ) != 0 ) {
527  return USER_PARAM_TYPE_ERR;
528  }
529  if ( strcmp( typeParam->type, STR_MS_T ) != 0 ) {
530  return USER_PARAM_TYPE_ERR;
531  }
532  objName = ( char * ) objParam->inOutStruct;
533  objType = ( char * ) typeParam->inOutStruct;
534  ret = setAVUMetadataFromKVPairs( rei->rsComm, objName, objType,
535  ( keyValPair_t * ) metadataParam->inOutStruct );
536  return ret;
537 
538 }
539 // =-=-=-=-=-=-=-
540 
573 int
574 msiGetObjType( msParam_t *objParam, msParam_t *typeParam,
575  ruleExecInfo_t *rei ) {
576 
577 
578  char *objName;
579  char objType[MAX_NAME_LEN];
580  int i;
581 
582  RE_TEST_MACRO( "Loopback on msiGetObjType" );
583 
584  if ( strcmp( objParam->type, STR_MS_T ) != 0 ) {
585  return USER_PARAM_TYPE_ERR;
586  }
587  objName = ( char * ) objParam->inOutStruct;
588 
589  i = getObjType( rei->rsComm, objName, objType );
590  if ( i < 0 ) {
591  return i;
592  }
593  typeParam->inOutStruct = ( char * ) strdup( objType );
594  typeParam->type = strdup( STR_MS_T );
595  return 0;
596 }
597 
598 
642 int
644  msParam_t* typeParam,
645  ruleExecInfo_t *rei ) {
646 
647  char *objName;
648  char *objType;
649  /* int id, i;*/
650  int i;
651 
652  RE_TEST_MACRO( "Loopback on msiRemoveKeyValuePairsFromObj" );
653 
654  if ( strcmp( metadataParam->type, KeyValPair_MS_T ) != 0 ) {
655  return USER_PARAM_TYPE_ERR;
656  }
657  if ( strcmp( objParam->type, STR_MS_T ) != 0 ) {
658  return USER_PARAM_TYPE_ERR;
659  }
660  if ( strcmp( typeParam->type, STR_MS_T ) != 0 ) {
661  return USER_PARAM_TYPE_ERR;
662  }
663  objName = ( char * ) objParam->inOutStruct;
664  objType = ( char * ) typeParam->inOutStruct;
665  i = removeAVUMetadataFromKVPairs( rei->rsComm, objName, objType,
666  ( keyValPair_t * ) metadataParam->inOutStruct );
667  return i;
668 
669 }
670 
727 int
729  msParam_t* _item_type,
730  msParam_t* _item_name,
731  msParam_t* _avu_op,
732  msParam_t* _attr_name,
733  msParam_t* _attr_val,
734  msParam_t* _attr_unit,
735  ruleExecInfo_t* _rei )
736 {
737  char *it_str = parseMspForStr( _item_type );
738  if( !it_str ) {
740  }
741 
742  char *in_str = parseMspForStr( _item_name );
743  if( !in_str ) {
745  }
746 
747  static const std::vector<std::string> v { "add", "set", "rm", "rmw" };
748  char *op_str = parseMspForStr( _avu_op );
749  if( !op_str || std::find(v.begin(), v.end(), op_str) == v.end()) {
751  }
752 
753  char *an_str = parseMspForStr( _attr_name );
754  if( !an_str ) {
756  }
757 
758  char *av_str = parseMspForStr( _attr_val );
759  if( !av_str ) {
761  }
762 
763  char *au_str = parseMspForStr( _attr_unit );
764  if( !au_str ) {
766  }
767 
768  modAVUMetadataInp_t avuOp;
769  memset(&avuOp, 0, sizeof(avuOp));
770  avuOp.arg0 = op_str;
771  avuOp.arg1 = it_str;
772  avuOp.arg2 = in_str;
773  avuOp.arg3 = an_str;
774  avuOp.arg4 = av_str;
775  avuOp.arg5 = au_str;
776 
777  _rei->status = rsModAVUMetadata(_rei->rsComm, &avuOp);
778 
779  return _rei->status;
780 }
rodsLog
void rodsLog(int level, const char *formatStr,...)
Definition: rodsLog.cpp:86
NULL
#define NULL
Definition: rodsDef.h:70
__loc1
char * __loc1
Definition: miscServerFunct.cpp:45
NO_VALUES_FOUND
@ NO_VALUES_FOUND
Definition: rodsErrorTable.h:680
TagStruct_MS_T
#define TagStruct_MS_T
Definition: msParam.h:38
addKeyVal
int addKeyVal(keyValPair_t *condInput, const char *keyWord, const char *value)
Definition: rcMisc.cpp:789
TagStruct::len
int len
Definition: objInfo.h:310
TagStruct
Definition: objInfo.h:309
modAVUMetadataInp_t::arg0
char * arg0
Definition: modAVUMetadata.h:7
BytesBuf::buf
void * buf
Definition: rodsDef.h:199
RuleExecInfo::status
int status
Definition: irods_re_structs.hpp:19
removeAVUMetadataFromKVPairs
int removeAVUMetadataFromKVPairs(rsComm_t *rsComm, char *objName, char *inObjType, keyValPair_t *kVP)
Definition: objMetaOpr.cpp:400
modAVUMetadataInp_t::arg2
char * arg2
Definition: modAVUMetadata.h:9
rcMisc.h
msiGetTaggedValueFromString
int msiGetTaggedValueFromString(msParam_t *inTagParam, msParam_t *inStrParam, msParam_t *outValueParam, ruleExecInfo_t *)
Definition: extractAvuMS.cpp:209
BUF_LEN_MS_T
#define BUF_LEN_MS_T
Definition: msParam.h:25
parseMspForStr
char * parseMspForStr(msParam_t *inpParam)
Definition: msParam.cpp:893
msiExtractTemplateMDFromBuf
int msiExtractTemplateMDFromBuf(msParam_t *bufParam, msParam_t *tagParam, msParam_t *metadataParam, ruleExecInfo_t *rei)
Definition: extractAvuMS.cpp:311
fillMsParam
int fillMsParam(msParam_t *msParam, const char *label, const char *type, void *inOutStruct, bytesBuf_t *inpOutBuf)
Definition: msParam.cpp:222
msiGetObjType
int msiGetObjType(msParam_t *objParam, msParam_t *typeParam, ruleExecInfo_t *rei)
Definition: extractAvuMS.cpp:574
modAVUMetadataInp_t::arg4
char * arg4
Definition: modAVUMetadata.h:11
msiSetKeyValuePairsToObj
int msiSetKeyValuePairsToObj(msParam_t *metadataParam, msParam_t *objParam, msParam_t *typeParam, ruleExecInfo_t *rei)
Definition: extractAvuMS.cpp:514
msiModAVUMetadata
int msiModAVUMetadata(msParam_t *_item_type, msParam_t *_item_name, msParam_t *_avu_op, msParam_t *_attr_name, msParam_t *_attr_val, msParam_t *_attr_unit, ruleExecInfo_t *_rei)
Definition: extractAvuMS.cpp:728
SYS_INVALID_INPUT_PARAM
@ SYS_INVALID_INPUT_PARAM
Definition: rodsErrorTable.h:195
msiAssociateKeyValuePairsToObj
int msiAssociateKeyValuePairsToObj(msParam_t *metadataParam, msParam_t *objParam, msParam_t *typeParam, ruleExecInfo_t *rei)
Definition: extractAvuMS.cpp:441
MsParam::type
char * type
Definition: msParam.h:78
STR_MS_T
#define STR_MS_T
Definition: msParam.h:21
rsModAVUMetadata.hpp
RuleExecInfo::rsComm
rsComm_t * rsComm
Definition: irods_re_structs.hpp:22
BytesBuf::len
int len
Definition: rodsDef.h:198
setAVUMetadataFromKVPairs
int setAVUMetadataFromKVPairs(rsComm_t *rsComm, char *objName, char *inObjType, keyValPair_t *kVP)
Definition: objMetaOpr.cpp:351
addTagStruct
int addTagStruct(tagStruct_t *condInput, char *preTag, char *postTag, char *keyWord)
Definition: rcMisc.cpp:831
addAVUMetadataFromKVPairs
int addAVUMetadataFromKVPairs(rsComm_t *rsComm, char *objName, char *inObjType, keyValPair_t *kVP)
Definition: objMetaOpr.cpp:311
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
modAVUMetadataInp_t::arg3
char * arg3
Definition: modAVUMetadata.h:10
getObjType
int getObjType(rsComm_t *rsComm, char *objName, char *objType)
Definition: objMetaOpr.cpp:285
MsParam
Definition: msParam.h:76
rsModAVUMetadata
int rsModAVUMetadata(rsComm_t *rsComm, modAVUMetadataInp_t *modAVUMetadataInp)
Definition: rsModAVUMetadata.cpp:13
LOG_NOTICE
#define LOG_NOTICE
Definition: rodsLog.h:33
modAVUMetadataInp_t
Definition: modAVUMetadata.h:6
msiReadMDTemplateIntoTagStruct
int msiReadMDTemplateIntoTagStruct(msParam_t *bufParam, msParam_t *tagParam, ruleExecInfo_t *rei)
Definition: extractAvuMS.cpp:69
BytesBuf
Definition: rodsDef.h:197
MsParam::inpOutBuf
bytesBuf_t * inpOutBuf
Definition: msParam.h:81
miscServerFunct.hpp
USER_PARAM_TYPE_ERR
@ USER_PARAM_TYPE_ERR
Definition: rodsErrorTable.h:254
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
INVALID_REGEXP
@ INVALID_REGEXP
Definition: rodsErrorTable.h:677
TagStruct::keyWord
char ** keyWord
Definition: objInfo.h:313
MsParam::inOutStruct
void * inOutStruct
Definition: msParam.h:80
modAVUMetadataInp_t::arg5
char * arg5
Definition: modAVUMetadata.h:12
KeyValPair
Definition: objInfo.h:120
TagStruct::postTag
char ** postTag
Definition: objInfo.h:312
clearKeyVal
int clearKeyVal(keyValPair_t *condInput)
Definition: rcMisc.cpp:1047
msiRemoveKeyValuePairsFromObj
int msiRemoveKeyValuePairsFromObj(msParam_t *metadataParam, msParam_t *objParam, msParam_t *typeParam, ruleExecInfo_t *rei)
Definition: extractAvuMS.cpp:643
objMetaOpr.hpp
modAVUMetadataInp_t::arg1
char * arg1
Definition: modAVUMetadata.h:8
TagStruct::preTag
char ** preTag
Definition: objInfo.h:311