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)  

conversion.cpp
Go to the documentation of this file.
1 /* For copyright information please refer to files in the COPYRIGHT directory
2  */
3 #include "arithmetics.hpp"
4 #include "index.hpp"
5 #include "datetime.hpp"
6 #include "rcMisc.h"
7 #ifndef DEBUG
8 #include "rodsType.h"
9 #endif
10 
11 
12 int addKeyVal( keyValPair_t *k, const char * key, const char *val );
13 char * getAttrNameFromAttrId( int id );
14 
15 
16 
20 void convertStrValue( Res *res, char *val, Region *r ) {
21  if ( val == NULL ) {
22  res->text = NULL;
23  }
24  else {
25  int len = ( strlen( val ) + 1 ) * sizeof( char );
26  res->text = ( char* )region_alloc( r, len );
27  memcpy( res->text, val, len );
28  RES_STRING_STR_LEN( res ) = strlen( val );
29  }
30  res->exprType = newSimpType( T_STRING, r );
31 }
35 void convertIntValue( Res *res, int inval, Region *r ) {
36  RES_INT_VAL_LVAL( res ) = inval;
37  res->exprType = newSimpType( T_INT, r );
38 }
42 void convertDoubleValue( Res *res, double inval, Region *r ) {
43  RES_DOUBLE_VAL_LVAL( res ) = inval;
44  res->exprType = newSimpType( T_DOUBLE, r );
45 }
61 Res* getValueFromCollection( char *typ, void *inPtr, int inx, Region *r ) {
62  Res *res;
63  int i, j;
64 
65  if ( !strcmp( typ, StrArray_MS_T ) ) {
66  strArray_t *strA;
67  /* ->size size of an element */
68  /* ->len length of the array */
69  strA = ( strArray_t * ) inPtr;
70  if ( inx >= strA->len ) {
71  return NULL;
72  }
73  res = newStringRes( r, strA->value + inx * strA->size );
74  return res;
75  }
76  else if ( !strcmp( typ, IntArray_MS_T ) ) {
77  res = newRes( r );
78  res->exprType = newSimpType( T_INT, r );
79  intArray_t *intA;
80  intA = ( intArray_t * ) inPtr;
81  if ( inx >= intA->len ) {
82  return NULL;
83  }
84  RES_INT_VAL_LVAL( res ) = intA->value[inx];
85  return res;
86  }
87  else if ( !strcmp( typ, GenQueryOut_MS_T ) ) {
88  keyValPair_t *k; /* element value */
89  genQueryOut_t *g = ( genQueryOut_t * ) inPtr; /* the result set */
90  char *cname, *aval; /* key and value */
91  sqlResult_t *v; /* a result row */
92  if ( g->rowCnt == 0 || inx >= g->rowCnt ) {
93  return NULL;
94  }
95  k = ( keyValPair_t * )malloc( sizeof( keyValPair_t ) );
96  k->len = 0;
97  k->keyWord = NULL;
98  k->value = NULL;
99  for ( i = 0; i < g->attriCnt; i++ ) {
100  v = g->sqlResult + i;
101  cname = ( char * ) getAttrNameFromAttrId( v->attriInx );
102  aval = v->value + v->len * inx;
103  j = addKeyVal( k, cname, aval ); /* addKeyVal duplicates the strings */
104  if ( j < 0 ) {
105  return NULL;
106  }
107  }
108  res = newUninterpretedRes( r, KeyValPair_MS_T, k, NULL );
109  return res;
110  }
111  else if ( strcmp( typ, KeyValPair_MS_T ) == 0 ) {
112  return newStringRes( r, ( ( keyValPair_t * ) inPtr )->keyWord[inx] );
113  }
114  else {
115  return NULL;
116  }
117 }
118 int getCollectionSize( char *typ, void *inPtr ) {
119  if ( !strcmp( typ, StrArray_MS_T ) ) {
120  strArray_t *strA;
121  /* ->size size of an element */
122  /* ->len length of the array */
123  strA = ( strArray_t * ) inPtr;
124  return strA->len;
125  }
126  else if ( !strcmp( typ, IntArray_MS_T ) ) {
127  intArray_t *intA;
128  intA = ( intArray_t * ) inPtr;
129  return intA->len;
130  }
131  else if ( !strcmp( typ, GenQueryOut_MS_T ) ) {
132  genQueryOut_t *g = ( genQueryOut_t * ) inPtr; /* the result set */
133  return g->rowCnt;
134  }
135  else if ( strcmp( typ, KeyValPair_MS_T ) == 0 ) {
136  return ( ( keyValPair_t * ) inPtr ) -> len;
137  }
138  else {
139  return USER_PARAM_TYPE_ERR;
140  }
141 }
142 int convertMsParamToRes( msParam_t *mP, Res *res, Region *r ) {
143 #ifdef DEBUG
144  writeToTmp( "relog.txt", "type: " );
145  writeToTmp( "relog.txt", mP->type );
146  writeToTmp( "relog.txt", "\n" );
147 #endif
148  if ( mP->type == NULL ) {
149  res->exprType = newSimpType( T_UNSPECED, r );
150  return 0;
151 
152  }
153  else if ( strcmp( mP->type, DOUBLE_MS_T ) == 0 ) { /* if the parameter is an integer */
154  convertDoubleValue( res, *( double * )mP->inOutStruct, r );
155  return 0;
156  }
157  else if ( strcmp( mP->type, INT_MS_T ) == 0 ) { /* if the parameter is an integer */
158  /* this could be int, bool, or datatime */
159  if ( res->exprType == NULL ) { /* output parameter */
160  RES_INT_VAL_LVAL( res ) = *( int * )mP->inOutStruct;
161  res->exprType = newSimpType( T_INT, r );
162  }
163  else
164  switch ( TYPE( res ) ) {
165  case T_INT:
166  RES_INT_VAL_LVAL( res ) = *( int * )mP->inOutStruct;
167  break;
168  case T_BOOL:
169  RES_BOOL_VAL_LVAL( res ) = *( int * )mP->inOutStruct;
170  break;
171  case T_DATETIME:
172  RES_TIME_VAL( res ) = *( rodsLong_t * )mP->inOutStruct;
173  break;
174  default:
175  convertIntValue( res, *( int * )mP->inOutStruct, r );
176  }
177  return 0;
178  }
179  else if ( strcmp( mP->type, STR_MS_T ) == 0 ) { /* if the parameter is a string */
180  convertStrValue( res, ( char * )mP->inOutStruct, r );
181  return 0;
182  }
183  else if ( strcmp( mP->type, DATETIME_MS_T ) == 0 ) {
184  RES_TIME_VAL( res ) = *( rodsLong_t * )mP->inOutStruct;
185  TYPE( res ) = T_DATETIME;
186  return 0;
187  /*
188  } else if(strcmp(mP->type, StrArray_MS_T) == 0) {
189  convertCollectionToRes(mP, res);
190  return 1;
191  } else if(strcmp(mP->type, IntArray_MS_T) == 0) {
192  convertCollectionToRes(mP, res);
193  return 1;
194  } else if(strcmp(mP->type, GenQueryOut_MS_T) == 0) {
195  convertCollectionToRes(mP, res);
196  return 1;
197  */
198  }
199  else {
200  if ( res->param == NULL ) {
201  res->param = newMsParam( mP->type, mP->inOutStruct, mP->inpOutBuf, r );
202  }
203  else {
204  res->param->type = mP->type ? strdup( mP->type ) : NULL;
205  RES_UNINTER_STRUCT( res ) = mP->inOutStruct;
206  RES_UNINTER_BUFFER( res ) = mP->inpOutBuf;
207  }
208  res->exprType = newIRODSType( mP->type, r );
209  return 0;
210  }
211 
212 
213 }
215  Res* res = newRes( r ); /* we need to create a new res here to make keep all res'es immutable */
216  int ret = convertMsParamToResAndFreeNonIRODSType( myArgv, res, r );
217  if ( ret != 0 ) {
218  res = newErrorRes( r, ret );
219  }
220  return res;
221 }
223 #ifdef DEBUG
224  writeToTmp( "relog.txt", "type: " );
225  writeToTmp( "relog.txt", mP->type );
226  writeToTmp( "relog.txt", "\n" );
227 #endif
228  if ( mP->type == NULL ) {
229  res->exprType = newSimpType( T_UNSPECED, r );
230  return 0;
231 
232  }
233  else if ( strcmp( mP->type, DOUBLE_MS_T ) == 0 ) { /* if the parameter is an integer */
234  convertDoubleValue( res, *( double * )mP->inOutStruct, r );
235  free( mP->inOutStruct );
236  mP->inOutStruct = NULL;
237  return 0;
238  }
239  else if ( strcmp( mP->type, INT_MS_T ) == 0 ) { /* if the parameter is an integer */
240  /* this could be int, bool, or datatime */
241  if ( res->exprType == NULL ) { /* output parameter */
242  RES_INT_VAL_LVAL( res ) = *( int * )mP->inOutStruct;
243  res->exprType = newSimpType( T_INT, r );
244  }
245  else
246  switch ( TYPE( res ) ) {
247  case T_INT:
248  RES_INT_VAL_LVAL( res ) = *( int * )mP->inOutStruct;
249  break;
250  case T_BOOL:
251  RES_BOOL_VAL_LVAL( res ) = *( int * )mP->inOutStruct;
252  break;
253  case T_DATETIME:
254  RES_TIME_VAL( res ) = *( rodsLong_t * )mP->inOutStruct;
255  break;
256  default:
257  convertIntValue( res, *( int * )mP->inOutStruct, r );
258  }
259  free( mP->inOutStruct );
260  mP->inOutStruct = NULL;
261  return 0;
262  }
263  else if ( strcmp( mP->type, STR_MS_T ) == 0 ) { /* if the parameter is a string */
264  convertStrValue( res, ( char * )mP->inOutStruct, r );
265  free( mP->inOutStruct );
266  mP->inOutStruct = NULL;
267  return 0;
268  }
269  else if ( strcmp( mP->type, DATETIME_MS_T ) == 0 ) {
270  RES_TIME_VAL( res ) = *( rodsLong_t * )mP->inOutStruct;
271  TYPE( res ) = T_DATETIME;
272  free( mP->inOutStruct );
273  mP->inOutStruct = NULL;
274  return 0;
275  /*
276  } else if(strcmp(mP->type, StrArray_MS_T) == 0) {
277  convertCollectionToRes(mP, res);
278  return 1;
279  } else if(strcmp(mP->type, IntArray_MS_T) == 0) {
280  convertCollectionToRes(mP, res);
281  return 1;
282  } else if(strcmp(mP->type, GenQueryOut_MS_T) == 0) {
283  convertCollectionToRes(mP, res);
284  return 1;
285  */
286  }
287  else {
288  if ( res->param == NULL ) {
289  res->param = newMsParam( mP->type, mP->inOutStruct, mP->inpOutBuf, r );
290  }
291  else {
292  res->param->type = mP->type ? strdup( mP->type ) : NULL;
293  RES_UNINTER_STRUCT( res ) = mP->inOutStruct;
294  RES_UNINTER_BUFFER( res ) = mP->inpOutBuf;
295  }
296  res->exprType = newIRODSType( mP->type, r );
297  return 0;
298  }
299 
300 
301 }
302 
304  if ( strcmp( type, DOUBLE_MS_T ) == 0 ) { /* if the parameter is an integer */
305  return newSimpType( T_DOUBLE, r );
306  }
307  else if ( strcmp( type, INT_MS_T ) == 0 ) { /* if the parameter is an integer */
308  return newSimpType( T_INT, r );
309  }
310  else if ( strcmp( type, STR_MS_T ) == 0 ) { /* if the parameter is a string */
311  return newSimpType( T_STRING, r );
312  /*
313  } else if(strcmp(type, DATETIME_MS_T) == 0) {
314  return newSimp(STRING);
315  */
316  }
317  else if ( strcmp( type, StrArray_MS_T ) == 0 ) {
318  return newCollType( newSimpType( T_STRING, r ), r );
319  }
320  else if ( strcmp( type, IntArray_MS_T ) == 0 ) {
321  return newCollType( newSimpType( T_INT, r ), r );
322  }
323  else if ( strcmp( type, GenQueryOut_MS_T ) == 0 ) {
324  return newCollType( newIRODSType( KeyValPair_MS_T, r ), r );
325  }
326  else {
327  return newIRODSType( type, r );
328  }
329 }
330 
331 /*
332 void convertCollectionToRes(msParam_t *mP, Res* res) {
333  int i =0;
334  char *typ = mP->type;
335  void *inPtr = mP->inOutStruct;
336  int len = getCollectionSize(typ, inPtr);
337  char buf[1024];
338  sprintf(buf, "%d\n", len);
339  writeToTmp("relog.txt", buf);
340  ExprType *elemType = convertToExprType(typ);
341  setCollRes(res, len, elemType);
342  freeType(elemType);
343  for(i=0;i<len;i++) {
344  res->value.c.elems[i]=getValueFromCollection(typ, inPtr, i);
345  }
346 }
347 */
348 
349 
350 int convertResToMsParam( msParam_t *var, Res *res, rError_t *errmsg ) {
351  strArray_t *arr = NULL;
352  intArray_t *arr2 = NULL;
353  int i = 0;
354  int maxlen = 0;
355  var->inpOutBuf = NULL;
356  var->label = NULL;
357  switch ( TYPE( res ) ) {
358  case T_ERROR: /* error message */
359  var->inOutStruct = ( int * )malloc( sizeof( int ) );
360  *( ( int * )var->inOutStruct ) = RES_ERR_CODE( res );
361  var->type = strdup( INT_MS_T );
362  break;
363  case T_DOUBLE: /* number */
364  var->inOutStruct = ( double * )malloc( sizeof( double ) );
365  *( ( double * )var->inOutStruct ) = RES_DOUBLE_VAL( res );
366  var->type = strdup( DOUBLE_MS_T );
367  break;
368  case T_INT: /* number */
369  var->inOutStruct = ( int * )malloc( sizeof( int ) );
370  *( ( int * )var->inOutStruct ) = RES_INT_VAL( res );
371  var->type = strdup( INT_MS_T );
372  break;
373  case T_STRING: /* string */
374  var->inOutStruct = res->text == NULL ? NULL : strdup( res->text );
375  var->type = strdup( STR_MS_T );
376  break;
377  case T_PATH: /* path */
378  var->inOutStruct = res->text == NULL ? NULL : strdup( res->text );
379  var->type = strdup( STR_MS_T );
380  break;
381  case T_DATETIME: /* date time */
382  var->inOutStruct = ( int* )malloc( sizeof( int ) );
383  *( ( int* )var->inOutStruct ) = ( int )RES_TIME_VAL( res );
384  var->type = strdup( INT_MS_T );
385  break;
386  case T_CONS:
387  if ( strcmp( T_CONS_TYPE_NAME( res->exprType ), LIST ) == 0 ) {
388  switch ( getNodeType( T_CONS_TYPE_ARG( res->exprType, 0 ) ) ) {
389  case T_STRING:
390  arr = ( strArray_t * )malloc( sizeof( strArray_t ) );
391  arr->len = res->degree;
392  maxlen = 0;
393  for ( i = 0; i < res->degree; i++ ) {
394  int slen = RES_STRING_STR_LEN( res->subtrees[i] );
395  maxlen = maxlen < slen ? slen : maxlen;
396  }
397  arr->size = maxlen + 1;
398  arr->value = ( char * )malloc( sizeof( char ) * (arr->size) * ( arr->len ) );
399  for ( i = 0; i < res->degree; i++ ) {
400  strcpy( arr->value + arr->size * i, res->subtrees[i]->text );
401  }
402  var->inOutStruct = arr;
403  var->type = strdup( StrArray_MS_T );
404  break;
405  case T_INT:
406  arr2 = ( intArray_t * )malloc( sizeof( intArray_t ) );
407  arr2->len = res->degree;
408  arr2->value = ( int * )malloc( sizeof( int ) * ( arr2->len ) );
409  for ( i = 0; i < res->degree; i++ ) {
410  arr2->value[i] = RES_INT_VAL( res );
411  }
412  var->inOutStruct = arr2;
413  var->type = strdup( IntArray_MS_T );
414  break;
415  default:
416  /* current there is no existing packing instructions for arbitrary collection */
417  /* report error */
418  addRErrorMsg( errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary collection type" );
419  return RE_PACKING_ERROR;
420  }
421  }
422  else {
423  addRErrorMsg( errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary constructed type" );
424  return RE_PACKING_ERROR;
425  }
426  break;
427  case T_IRODS:
428  var->inOutStruct = RES_UNINTER_STRUCT( res );
429  var->inpOutBuf = RES_UNINTER_BUFFER( res );
430  var->type = res->exprType->text ? strdup( res->exprType->text ) : NULL;
431  break;
432  case T_UNSPECED:
433  var->inOutStruct = NULL;
434  var->type = NULL;
435  break;
436  default:
437  /*error */
438  addRErrorMsg( errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary type" );
439  return RE_PACKING_ERROR;
440  }
441  return 0;
442 }
443 int updateResToMsParam( msParam_t *var, Res *res, rError_t *errmsg ) {
444  if ( var->type != NULL && ( strcmp( var->type, INT_MS_T ) == 0 ||
445  strcmp( var->type, DOUBLE_MS_T ) == 0 ||
446  strcmp( var->type, STR_MS_T ) == 0 ) ) {
447  /* do not free msParam_t if its inOutStruct and inOutBuf are shared */
448  if ( var->inOutStruct != NULL ) {
449  free( var->inOutStruct );
450  }
451  if ( var->inpOutBuf != NULL ) {
452  free( var->inpOutBuf );
453  }
454  }
455  if ( var->label != NULL ) {
456  free( var->label );
457  }
458  return convertResToMsParam( var, res, errmsg );
459 }
461  int ret;
462  if ( env->previous != NULL ) {
463  if ( ( ret = convertEnvToMsParamArray( var, env->previous, errmsg, r ) ) != 0 ) {
464  return ret;
465  }
466  }
467  return convertHashtableToMsParamArray( var, env->current, errmsg );
468 }
469 
471  int i;
472  for ( i = 0; i < env->size; i++ ) {
473  struct bucket *b = env->buckets[i];
474  while ( b != NULL && !IS_TVAR_NAME( b->key ) ) {
475  Res *res = ( Res * )b->value;
476  msParam_t *v = NULL;
477  int needToFree = 0;
478  int varindex;
479  int ret;
480  for ( varindex = 0; varindex < var->len; varindex++ ) {
481  if ( var->msParam[varindex]->label != NULL && strcmp( var->msParam[varindex]->label, b->key ) == 0 ) {
482  v = var->msParam[varindex];
483  ret = updateResToMsParam( v, res, errmsg );
484  break;
485  }
486  }
487  if ( v == NULL ) {
488  v = ( msParam_t * ) malloc( sizeof( msParam_t ) );
489  needToFree = 1;
490  ret = convertResToMsParam( v, res, errmsg );
491  if ( var->msParam == NULL ) {
492  var->len = 0;
493  var->msParam = ( msParam_t ** ) malloc( sizeof( msParam_t * ) * ( PTR_ARRAY_MALLOC_LEN ) );
494  }
495  else if ( var->len % PTR_ARRAY_MALLOC_LEN == 0 ) {
496  var->msParam = ( msParam_t ** ) realloc( var->msParam, sizeof( msParam_t * ) * ( PTR_ARRAY_MALLOC_LEN + var->len ) );
497  }
498 
499  var->msParam[var->len++] = v;
500  }
501  v->label = strdup( b->key );
502 
503  if ( ret != 0 ) {
504  /* error */
505  /* todo free msParamArray */
506  if ( needToFree ) {
507  free( v );
508  }
509  return ret;
510  }
511 
512  b = b->next;
513  }
514  }
515  return 0;
516 }
518  return updateMsParamArrayToEnv( var, env, r );
519 }
520 
523 }
525  int i;
526  for ( i = 0; i < var->len; i++ ) {
527  Res *res = newRes( r );
528  int ret = convertMsParamToRes( var->msParam[i], res, r );
529  if ( ret != 0 ) {
530  return ret;
531  }
532  char *varName = var->msParam[i]->label;
533  if ( varName != NULL ) {
534  updateInEnv( env, varName, res );
535  }
536  }
537  return 0;
538 }
540  int i;
541  for ( i = 0; i < var->len; i++ ) {
542  Res *res = newRes( r );
543  int ret = convertMsParamToResAndFreeNonIRODSType( var->msParam[i], res, r );
544  if ( ret != 0 ) {
545  return ret;
546  }
547  char *varName = var->msParam[i]->label;
548  if ( varName != NULL ) {
549  updateInEnv( env, varName, res );
550  }
551  }
552  return 0;
553 }
554 
555 
556 char* convertResToString( Res *res0 ) {
557  char *res;
558  char *type;
559  int j;
560  switch ( getNodeType( res0 ) ) {
561 
562  case N_ERROR:
563  res = ( char * )malloc( sizeof( char ) * 1024 );
564  snprintf( res, 1024, "error %d", RES_ERR_CODE( res0 ) );
565  return res;
566  case N_VAL:
567  switch ( TYPE( res0 ) ) {
568  case T_INT:
569  case T_DOUBLE:
570  res = ( char * )malloc( sizeof( char ) * 1024 );
571  if ( res0->dval == ( int )res0->dval ) {
572  snprintf( res, 1024, "%d", ( int )res0->dval );
573  }
574  else {
575  snprintf( res, 1024, "%f", res0->dval );
576  }
577  return res;
578  case T_STRING:
579  if ( res0->text == NULL ) {
580  res = strdup( "<null>" );
581  }
582  else {
583  res = strdup( res0->text );
584  }
585  return res;
586  case T_PATH:
587  if ( res0->text == NULL ) {
588  res = strdup( "<null>" );
589  }
590  else {
591  res = strdup( res0->text );
592  }
593  return res;
594  case T_IRODS:
595  res = ( char * )malloc( sizeof( char ) * 1024 );
596  res[0] = 0;
597  type = res0->exprType->text;
598  if ( strcmp( type, KeyValPair_MS_T ) == 0 ) {
599  int num_pairs = 0;
600  keyValPair_t *kvp = ( keyValPair_t * ) RES_UNINTER_STRUCT( res0 );
601  if ( kvp != NULL ) {
602  num_pairs = kvp->len;
603  }
604  snprintf( res, 1024, "KeyValue[%d]:", num_pairs );
605  int i;
606  for ( i = 0; i < num_pairs; i++ ) {
607  snprintf( res + strlen( res ), 1024 - strlen( res ), "%s=%s;", kvp->keyWord[i], kvp->value[i] );
608  }
609 
610  }
611  else if ( strcmp( type, BUF_LEN_MS_T ) == 0 ) {
612  snprintf( res + strlen( res ), 1024 - strlen( res ), "%d", *( int* )res0->param->inOutStruct );
613  }
614  else if ( strcmp( type, DataObjInp_MS_T ) == 0 ) {
615  dataObjInp_t dataObjInp, *myDataObjInp;
616  j = parseMspForDataObjInp( res0->param, &dataObjInp, &myDataObjInp, 0 );
617  if ( j < 0 ) {
618  snprintf( res + strlen( res ), 1024 - strlen( res ), "<error>" );
619  }
620  else {
621  snprintf( res + strlen( res ), 1024 - strlen( res ), "%s", ( char * ) myDataObjInp->objPath );
622  }
623  }
624  else if ( strcmp( type, CollInp_MS_T ) == 0 ) {
625  collInp_t collCreateInp, *myCollCreateInp;
626  j = parseMspForCollInp( res0->param, &collCreateInp, &myCollCreateInp, 0 );
627  if ( j < 0 ) {
628  snprintf( res + strlen( res ), 1024 - strlen( res ), "<error>" );
629  }
630  else {
631  snprintf( res + strlen( res ), 1024 - strlen( res ), "%s", myCollCreateInp->collName );
632  }
633  }
634  else if ( strcmp( type, DataObjCopyInp_MS_T ) == 0 ) {
635  dataObjCopyInp_t dataObjCopyInp, *myDataObjCopyInp;
636  j = parseMspForDataObjCopyInp( res0->param, &dataObjCopyInp, &myDataObjCopyInp );
637  if ( j < 0 ) {
638  snprintf( res + strlen( res ), 1024 - strlen( res ), "<error>" );
639  }
640  else
641  snprintf( res + strlen( res ), 1024 - strlen( res ), "COPY(%s,%s)",
642  myDataObjCopyInp->srcDataObjInp.objPath, myDataObjCopyInp->destDataObjInp.objPath );
643  }
644  else if ( strcmp( type, DataObjReadInp_MS_T ) == 0
645  || strcmp( type, DataObjCloseInp_MS_T ) == 0
646  || strcmp( type, DataObjWriteInp_MS_T ) == 0 ) {
647  openedDataObjInp_t *myDataObjReadInp;
648  myDataObjReadInp = ( openedDataObjInp_t * ) res0->param->inOutStruct;
649  snprintf( res + strlen( res ), 1024 - strlen( res ), "OPEN(%d)", myDataObjReadInp->len );
650  }
651  else if ( strcmp( type, ExecCmd_MS_T ) == 0 ) {
653  execCmd = ( execCmd_t * ) res0->param->inOutStruct;
654  snprintf( res + strlen( res ), 1024 - strlen( res ), "%s", execCmd->cmd );
655  }
656  else {
657  snprintf( res, 1024, "<value>" );
658  }
659  return res;
660  case T_BOOL:
661  res = strdup( RES_BOOL_VAL( res0 ) ? "true" : "false" );
662  return res;
663  case T_CONS:
664  res = ( char * )malloc( sizeof( char ) * 1024 );
665  sprintf( res, "[" );
666  int i;
667  for ( i = 0; i < res0->degree; i++ ) {
668  char *resElem = convertResToString( res0->subtrees[i] );
669  if ( resElem == NULL ) {
670  free( res );
671  return NULL;
672  }
673  else {
674  snprintf( res + strlen( res ), 1024 - strlen( res ), "%s%s", i == 0 ? "" : ",", resElem );
675  free( resElem );
676  }
677  }
678  snprintf( res + strlen( res ), 1024 - strlen( res ), "]" );
679  return res;
680  case T_DATETIME:
681  res = ( char * )malloc( sizeof( char ) * 1024 );
682  ttimestr( res, 1024 - 1, "", &RES_TIME_VAL( res0 ) );
683  return res;
684  case T_UNSPECED:
685  res = strdup( "<undefined>" );
686  return res;
687  default:
688  /*sprintf(res, "error: unsupported type %d", TYPE(res0)); */
689  return NULL;
690  }
691  break;
692  default:
693  res = ( char * )malloc( sizeof( char ) * 128 );
694  return typeToString( res0, NULL, res, 128 );
695  }
696 }
697 
698 
699 void printMsParamArray( msParamArray_t *msParamArray, char *buf2 ) {
700  char buf3[MAX_NAME_LEN];
701  sprintf( buf2, "len: %d\n", msParamArray->len );
702  int i;
703  for ( i = 0; i < msParamArray->len; i++ ) {
704  msParam_t *mP = msParamArray->msParam[i];
705  if ( i != 0 ) {
706  strncat( buf2, ",", MAX_NAME_LEN - strlen( buf2 ) );
707  }
708  strncat( buf2, mP->label, MAX_NAME_LEN - strlen( buf2 ) );
709  strncat( buf2, "=", MAX_NAME_LEN - strlen( buf2 ) );
710  if ( mP->inOutStruct == NULL ) {
711  strncat( buf2, "<null>", MAX_NAME_LEN - strlen( buf2 ) );
712  }
713  else {
714  if ( strcmp( mP->type, DOUBLE_MS_T ) == 0 ) { /* if the parameter is an integer */
715  snprintf( buf3, MAX_NAME_LEN, "%f:", *( double * )mP->inOutStruct );
716  }
717  else if ( strcmp( mP->type, INT_MS_T ) == 0 ) { /* if the parameter is an integer */
718  snprintf( buf3, MAX_NAME_LEN, "%d:", *( int * )mP->inOutStruct );
719  }
720  else if ( strcmp( mP->type, STR_MS_T ) == 0 ) { /* if the parameter is a string */
721  snprintf( buf3, MAX_NAME_LEN, "%s:", ( char * )mP->inOutStruct );
722  }
723  else if ( strcmp( mP->type, DATETIME_MS_T ) == 0 ) {
724  snprintf( buf3, MAX_NAME_LEN, "%ld:", ( long ) * ( time_t * )mP->inOutStruct );
725  }
726  else {
727  snprintf( buf3, MAX_NAME_LEN, "<value>:" );
728  }
729  strncat( buf2, buf3, MAX_NAME_LEN - strlen( buf2 ) );
730  strncat( buf2, mP->type, MAX_NAME_LEN - strlen( buf2 ) );
731  }
732  }
733  return;
734 }
735 
736 void printHashtable( Hashtable *env, char* buf2 ) {
737  int i;
738  char typeNameBuf[128];
739  sprintf( buf2, "len: %d\n", env->len );
740  int k = 0;
741  for ( i = 0; i < env->size; i++ ) {
742  struct bucket *b = env->buckets[i];
743  while ( b != NULL ) {
744  Res *res = ( Res * ) b->value;
745  if ( k != 0 ) {
746  strncat( buf2, "\n", MAX_NAME_LEN - strlen( buf2 ) );
747  }
748  strncat( buf2, b->key, MAX_NAME_LEN - strlen( buf2 ) );
749  strncat( buf2, "=", MAX_NAME_LEN - strlen( buf2 ) );
750  if ( res == NULL ) {
751  strncat( buf2, "<null>", MAX_NAME_LEN - strlen( buf2 ) );
752  }
753  else {
754  char *buf4 = convertResToString( res );
755  strncat( buf2, buf4, MAX_NAME_LEN - strlen( buf2 ) );
756  strncat( buf2, ":", MAX_NAME_LEN - strlen( buf2 ) );
757  strncat( buf2, res->exprType == NULL ? "<null>" : typeToString( res->exprType, NULL, typeNameBuf, 128 ), MAX_NAME_LEN - strlen( buf2 ) );
758  free( buf4 );
759  }
760  k++;
761  b = b->next;
762  }
763  }
764 }
765 
767  int retVal;
768  if ( getNodeType( res ) == N_ERROR ) {
769  retVal = RES_ERR_CODE( res );
770  }
771  else {
772  retVal = RES_INT_VAL( res );
773  }
774  return retVal;
775 
776 }
DataObjInp::objPath
char objPath[(1024+64)]
Definition: dataObjInpOut.h:66
OpenedDataObjInp
Definition: dataObjInpOut.h:104
getValueFromCollection
Res * getValueFromCollection(char *typ, void *inPtr, int inx, Region *r)
Definition: conversion.cpp:61
NULL
#define NULL
Definition: rodsDef.h:70
IS_TVAR_NAME
#define IS_TVAR_NAME(x)
Definition: utils.hpp:26
DataObjCopyInp::srcDataObjInp
dataObjInp_t srcDataObjInp
Definition: dataObjCopy.h:26
convertResToString
char * convertResToString(Res *res0)
Definition: conversion.cpp:556
DataObjCopyInp_MS_T
#define DataObjCopyInp_MS_T
Definition: msParam.h:32
DataObjCopyInp
Definition: dataObjCopy.h:25
newIRODSType
ExprType * newIRODSType(const char *name, Region *r)
Definition: restructs.cpp:99
parseMspForDataObjCopyInp
int parseMspForDataObjCopyInp(msParam_t *inpParam, dataObjCopyInp_t *dataObjCopyInpCache, dataObjCopyInp_t **outDataObjCopyInp)
Definition: msParam.cpp:727
CollInp
Definition: dataObjInpOut.h:157
DataObjInp_MS_T
#define DataObjInp_MS_T
Definition: msParam.h:30
index.hpp
SqlResult::attriInx
int attriInx
Definition: rodsGenQuery.h:62
region_alloc
void * region_alloc(Region *r, size_t s)
Definition: region.cpp:138
node::dval
double dval
Definition: restructs.hpp:256
env::previous
Env * previous
Definition: restructs.hpp:228
T_UNSPECED
@ T_UNSPECED
Definition: restructs.hpp:156
node::param
msParam_t * param
Definition: restructs.hpp:260
getNodeType
#define getNodeType(x)
Definition: restructs.hpp:69
RES_TIME_VAL
#define RES_TIME_VAL(x)
Definition: restructs.hpp:60
convertMsParamToResAndFreeNonIRODSType
int convertMsParamToResAndFreeNonIRODSType(msParam_t *mP, Res *res, Region *r)
Definition: conversion.cpp:222
convertResToMsParam
int convertResToMsParam(msParam_t *var, Res *res, rError_t *errmsg)
Definition: conversion.cpp:350
bucket
Definition: irods_hashtable.h:11
env
Definition: restructs.hpp:226
convertEnvToMsParamArray
int convertEnvToMsParamArray(msParamArray_t *var, Env *env, rError_t *errmsg, Region *r)
Definition: conversion.cpp:460
typeToString
char * typeToString(ExprType *type, Hashtable *var_types, char *buf, int bufsize)
Definition: utils.cpp:522
rcMisc.h
BUF_LEN_MS_T
#define BUF_LEN_MS_T
Definition: msParam.h:25
newMsParam
msParam_t * newMsParam(const char *typeName, void *ioStruct, bytesBuf_t *ioBuf, Region *r)
Definition: restructs.cpp:189
T_DOUBLE
@ T_DOUBLE
Definition: restructs.hpp:159
T_PATH
@ T_PATH
Definition: restructs.hpp:168
RES_DOUBLE_VAL
#define RES_DOUBLE_VAL(x)
Definition: restructs.hpp:57
node
Definition: restructs.hpp:244
ttimestr
int ttimestr(char *timestr, int n, char *timeformat, rodsLong_t *t)
Definition: datetime.cpp:37
execCmd
int execCmd(execCmd_t *execCmdInp, int stdOutFd, int stdErrFd)
Definition: rsExecCmd.cpp:373
datetime.hpp
TYPE
#define TYPE(x)
Definition: restructs.hpp:23
IntArray::len
int len
Definition: objInfo.h:228
INT_MS_T
#define INT_MS_T
Definition: msParam.h:22
printHashtable
void printHashtable(Hashtable *env, char *buf2)
Definition: conversion.cpp:736
convertStrValue
void convertStrValue(Res *res, char *val, Region *r)
Definition: conversion.cpp:20
RES_UNINTER_BUFFER
#define RES_UNINTER_BUFFER(x)
Definition: restructs.hpp:66
MsParam::type
char * type
Definition: msParam.h:78
RE_PACKING_ERROR
@ RE_PACKING_ERROR
Definition: rodsErrorTable.h:724
updateResToMsParam
int updateResToMsParam(msParam_t *var, Res *res, rError_t *errmsg)
Definition: conversion.cpp:443
GenQueryOut::sqlResult
sqlResult_t sqlResult[50]
Definition: rodsGenQuery.h:72
T_CONS
@ T_CONS
Definition: restructs.hpp:167
STR_MS_T
#define STR_MS_T
Definition: msParam.h:21
updateMsParamArrayToEnvAndFreeNonIRODSType
int updateMsParamArrayToEnvAndFreeNonIRODSType(msParamArray_t *var, Env *env, Region *r)
Definition: conversion.cpp:539
StrArray_MS_T
#define StrArray_MS_T
Definition: msParam.h:44
newCollType
ExprType * newCollType(ExprType *elemType, Region *r)
Definition: restructs.cpp:110
StrArray::len
int len
Definition: objInfo.h:221
ExecCmd_MS_T
#define ExecCmd_MS_T
Definition: msParam.h:40
KeyValPair::value
char ** value
Definition: objInfo.h:123
node::text
char * text
Definition: restructs.hpp:252
GenQueryOut_MS_T
#define GenQueryOut_MS_T
Definition: msParam.h:47
convertToExprType
ExprType * convertToExprType(char *type, Region *r)
Definition: conversion.cpp:303
newUninterpretedRes
Res * newUninterpretedRes(Region *r, const char *typeName, void *ioStruct, bytesBuf_t *ioBuf)
Definition: restructs.cpp:183
rError_t
Definition: rodsError.h:24
parseMspForCollInp
int parseMspForCollInp(msParam_t *inpParam, collInp_t *collInpCache, collInp_t **outCollInp, int writeToCache)
Definition: msParam.cpp:677
T_IRODS
@ T_IRODS
Definition: restructs.hpp:172
newErrorRes
Res * newErrorRes(Region *r, int errcode)
Definition: restructs.cpp:259
node::subtrees
struct node ** subtrees
Definition: restructs.hpp:254
rodsType.h
OpenedDataObjInp::len
int len
Definition: dataObjInpOut.h:106
MsParamArray::msParam
msParam_t ** msParam
Definition: msParam.h:87
T_DATETIME
@ T_DATETIME
Definition: restructs.hpp:162
node::degree
int degree
Definition: restructs.hpp:246
DataObjReadInp_MS_T
#define DataObjReadInp_MS_T
Definition: msParam.h:33
KeyValPair::keyWord
char ** keyWord
Definition: objInfo.h:122
RES_STRING_STR_LEN
#define RES_STRING_STR_LEN(x)
Definition: restructs.hpp:53
DataObjCloseInp_MS_T
#define DataObjCloseInp_MS_T
Definition: msParam.h:31
updateInEnv
void updateInEnv(Env *env, char *varname, Res *res)
Definition: utils.cpp:821
DataObjInp
Definition: dataObjInpOut.h:65
printMsParamArray
void printMsParamArray(msParamArray_t *msParamArray, char *buf2)
Definition: conversion.cpp:699
T_STRING
@ T_STRING
Definition: restructs.hpp:161
MAX_NAME_LEN
#define MAX_NAME_LEN
Definition: rodsDef.h:61
convertMsParamArrayToEnvAndFreeNonIRODSType
int convertMsParamArrayToEnvAndFreeNonIRODSType(msParamArray_t *var, Env *env, Region *r)
Definition: conversion.cpp:521
convertIntValue
void convertIntValue(Res *res, int inval, Region *r)
Definition: conversion.cpp:35
newSimpType
ExprType * newSimpType(NodeType t, Region *r)
Definition: restructs.cpp:70
GenQueryOut
Definition: rodsGenQuery.h:67
addRErrorMsg
int addRErrorMsg(rError_t *myError, int status, const char *msg)
Definition: rcMisc.cpp:121
GenQueryOut::attriCnt
int attriCnt
Definition: rodsGenQuery.h:69
convertDoubleValue
void convertDoubleValue(Res *res, double inval, Region *r)
Definition: conversion.cpp:42
MsParam
Definition: msParam.h:76
GenQueryOut::rowCnt
int rowCnt
Definition: rodsGenQuery.h:68
region
Definition: region.h:45
T_BOOL
@ T_BOOL
Definition: restructs.hpp:163
MsParam::inpOutBuf
bytesBuf_t * inpOutBuf
Definition: msParam.h:81
RES_UNINTER_STRUCT
#define RES_UNINTER_STRUCT(x)
Definition: restructs.hpp:65
int
typedef int((*funcPtr)())
RES_INT_VAL
#define RES_INT_VAL(x)
Definition: restructs.hpp:58
MsParamArray::len
int len
Definition: msParam.h:85
CollInp_MS_T
#define CollInp_MS_T
Definition: msParam.h:39
addKeyVal
int addKeyVal(keyValPair_t *k, const char *key, const char *val)
Definition: rcMisc.cpp:789
arithmetics.hpp
MsParam::label
char * label
Definition: msParam.h:77
parseMspForDataObjInp
int parseMspForDataObjInp(msParam_t *inpParam, dataObjInp_t *dataObjInpCache, dataObjInp_t **outDataObjInp, int writeToCache)
Definition: msParam.cpp:597
SqlResult::value
char * value
Definition: rodsGenQuery.h:64
N_VAL
@ N_VAL
Definition: restructs.hpp:126
USER_PARAM_TYPE_ERR
@ USER_PARAM_TYPE_ERR
Definition: rodsErrorTable.h:254
getCollectionSize
int getCollectionSize(char *typ, void *inPtr)
Definition: conversion.cpp:118
ExecCmd
Definition: execCmd.h:10
DataObjCopyInp::destDataObjInp
dataObjInp_t destDataObjInp
Definition: dataObjCopy.h:27
node::exprType
ExprType * exprType
Definition: restructs.hpp:250
convertResToIntReturnValue
int convertResToIntReturnValue(Res *res)
Definition: conversion.cpp:766
StrArray::size
int size
Definition: objInfo.h:222
newRes
Res * newRes(Region *r)
Definition: restructs.cpp:176
RES_DOUBLE_VAL_LVAL
#define RES_DOUBLE_VAL_LVAL(x)
Definition: restructs.hpp:54
DATETIME_MS_T
#define DATETIME_MS_T
Definition: reconstants.hpp:12
SqlResult
Definition: rodsGenQuery.h:61
KeyValPair_MS_T
#define KeyValPair_MS_T
Definition: msParam.h:37
irods.six.b
def b(s)
Definition: six.py:606
T_INT
@ T_INT
Definition: restructs.hpp:160
N_ERROR
@ N_ERROR
Definition: restructs.hpp:111
KeyValPair::len
int len
Definition: objInfo.h:121
env::current
Hashtable * current
Definition: restructs.hpp:227
PTR_ARRAY_MALLOC_LEN
#define PTR_ARRAY_MALLOC_LEN
Definition: rodsDef.h:73
StrArray::value
char * value
Definition: objInfo.h:223
SqlResult::len
int len
Definition: rodsGenQuery.h:63
CollInp::collName
char collName[(1024+64)]
Definition: dataObjInpOut.h:158
hashtable
Definition: irods_hashtable.h:16
convertHashtableToMsParamArray
int convertHashtableToMsParamArray(msParamArray_t *var, Hashtable *env, rError_t *errmsg)
Definition: conversion.cpp:470
getAttrNameFromAttrId
char * getAttrNameFromAttrId(int id)
Definition: rcMisc.cpp:2826
convertMsParamArrayToEnv
int convertMsParamArrayToEnv(msParamArray_t *var, Env *env, Region *r)
Definition: conversion.cpp:517
writeToTmp
int writeToTmp(char *fileName, char *text)
Definition: utils.cpp:681
RES_ERR_CODE
#define RES_ERR_CODE(x)
Definition: restructs.hpp:50
MsParam::inOutStruct
void * inOutStruct
Definition: msParam.h:80
DOUBLE_MS_T
#define DOUBLE_MS_T
Definition: msParam.h:27
MsParamArray
Definition: msParam.h:84
RES_INT_VAL_LVAL
#define RES_INT_VAL_LVAL(x)
Definition: restructs.hpp:55
DataObjWriteInp_MS_T
#define DataObjWriteInp_MS_T
Definition: msParam.h:34
T_ERROR
@ T_ERROR
Definition: restructs.hpp:157
KeyValPair
Definition: objInfo.h:120
T_CONS_TYPE_ARG
#define T_CONS_TYPE_ARG(x, n)
Definition: restructs.hpp:26
newStringRes
Res * newStringRes(Region *r, const char *s)
Definition: restructs.cpp:235
IntArray::value
int * value
Definition: objInfo.h:229
type
int type
Definition: filesystem.cpp:103
RES_BOOL_VAL
#define RES_BOOL_VAL(x)
Definition: restructs.hpp:59
updateMsParamArrayToEnv
int updateMsParamArrayToEnv(msParamArray_t *var, Env *env, Region *r)
Definition: conversion.cpp:524
rodsLong_t
long long rodsLong_t
Definition: rodsType.h:32
StrArray
Definition: objInfo.h:220
IntArray_MS_T
#define IntArray_MS_T
Definition: msParam.h:45
convertMsParamToRes
int convertMsParamToRes(msParam_t *mP, Res *res, Region *r)
Definition: conversion.cpp:142
T_CONS_TYPE_NAME
#define T_CONS_TYPE_NAME(x)
Definition: restructs.hpp:27
LIST
#define LIST
Definition: reconstants.hpp:14
RES_BOOL_VAL_LVAL
#define RES_BOOL_VAL_LVAL(x)
Definition: restructs.hpp:56
IntArray
Definition: objInfo.h:227