void freeEnvUninterpretedStructs(Env *e) { Hashtable *ht = e->current; int i; for(i=0;i<ht->size;i++) { struct bucket *b = ht->buckets[i]; while(b!=NULL) { Res *res = (Res *) b->value; if(TYPE(res) == T_IRODS) { if(RES_UNINTER_STRUCT(res)!=NULL) { free(RES_UNINTER_STRUCT(res)); } if(RES_UNINTER_BUFFER(res)!=NULL) { free(RES_UNINTER_BUFFER(res)); } } b=b->next; } } if(e->previous!=NULL) { freeEnvUninterpretedStructs(e->previous); } }
/************* Res to String *********************/ char* convertResToString(Res *res0) { char *res; char *type; int j; switch (getNodeType(res0)) { case N_ERROR: res = (char *)malloc(sizeof(char)*1024); snprintf(res, 1024, "error %d", RES_ERR_CODE(res0)); return res; case N_VAL: switch(TYPE(res0)) { case T_INT: case T_DOUBLE: res = (char *)malloc(sizeof(char)*1024); if(res0->dval==(int)res0->dval) { snprintf(res, 1024, "%d", (int)res0->dval); } else { snprintf(res, 1024, "%f", res0->dval); } return res; case T_STRING: if(res0->text == NULL) { res = strdup("<null>"); } else { res = strdup(res0->text); } return res; case T_PATH: if(res0->text == NULL) { res = strdup("<null>"); } else { res = strdup(res0->text); } return res; case T_IRODS: res = (char *)malloc(sizeof(char)*1024); res[0] = 0; type = res0->exprType->text; if(strcmp(type, KeyValPair_MS_T)==0) { keyValPair_t *kvp = (keyValPair_t *) RES_UNINTER_STRUCT(res0); snprintf(res, 1024, "KeyValue[%d]:", kvp->len); int i; for(i=0;i<kvp->len;i++) { snprintf(res + strlen(res), 1024 - strlen(res), "%s=%s;", kvp->keyWord[i],kvp->value[i]); } } else if (strcmp(type, BUF_LEN_MS_T) == 0 ) { snprintf(res + strlen(res), 1024 - strlen(res),"%d",*(int*)res0->param->inOutStruct); } else if (strcmp(type, DataObjInp_MS_T) == 0) { dataObjInp_t dataObjInp, *myDataObjInp; j = parseMspForDataObjInp (res0->param, &dataObjInp, &myDataObjInp, 0); if (j < 0) snprintf(res + strlen(res), 1024 - strlen(res), "<error>"); else snprintf(res + strlen(res), 1024 - strlen(res), "%s",(char *) myDataObjInp->objPath); } else if (strcmp(type, CollInp_MS_T ) == 0) { collInp_t collCreateInp, *myCollCreateInp; j = parseMspForCollInp (res0->param, &collCreateInp, &myCollCreateInp, 0); if (j < 0) snprintf(res + strlen(res), 1024 - strlen(res), "<error>"); else snprintf(res + strlen(res), 1024 - strlen(res), "%s", myCollCreateInp->collName); } else if (strcmp(type, DataObjCopyInp_MS_T) == 0) { dataObjCopyInp_t dataObjCopyInp, *myDataObjCopyInp; j = parseMspForDataObjCopyInp (res0->param, &dataObjCopyInp, &myDataObjCopyInp); if (j < 0) snprintf(res + strlen(res), 1024 - strlen(res), "<error>"); else snprintf (res + strlen(res), 1024 - strlen(res), "COPY(%s,%s)", myDataObjCopyInp->srcDataObjInp.objPath, myDataObjCopyInp->destDataObjInp.objPath); } else if (strcmp(type, DataObjReadInp_MS_T) == 0 || strcmp(type, DataObjCloseInp_MS_T) == 0 || strcmp(type, DataObjWriteInp_MS_T) == 0 ) { openedDataObjInp_t *myDataObjReadInp; myDataObjReadInp = (openedDataObjInp_t *) res0->param->inOutStruct; snprintf (res + strlen(res), 1024 - strlen(res), "OPEN(%d)",myDataObjReadInp->len); } else if (strcmp(type, ExecCmd_MS_T ) == 0) { execCmd_t *execCmd; execCmd = (execCmd_t *) res0->param->inOutStruct; snprintf(res + strlen(res), 1024 - strlen(res), "%s", execCmd->cmd); } else { snprintf(res, 1024, "<value>"); } return res; case T_BOOL: res = strdup(RES_BOOL_VAL(res0)?"true":"false"); return res; case T_CONS: res = (char *)malloc(sizeof(char)*1024); sprintf(res, "["); int i; for(i=0;i<res0->degree;i++) { char *resElem = convertResToString(res0->subtrees[i]); if(resElem == NULL) { free(res); return NULL; } else { snprintf(res+strlen(res), 1024-strlen(res), "%s%s", i==0?"":",",resElem); free(resElem); } } snprintf(res+strlen(res), 1024-strlen(res), "]"); return res; case T_DATETIME: res = (char *)malloc(sizeof(char)*1024); ttimestr(res, 1024-1, "", &RES_TIME_VAL(res0)); return res; case T_UNSPECED: res = strdup("<undefined>"); return res; default: /*sprintf(res, "error: unsupported type %d", TYPE(res0)); */ return NULL; } break; default: res = (char *)malloc(sizeof(char)*128); return typeToString(res0, NULL, res, 128); } }
/************************ Res to Microservice parameter ***********************/ int convertResToMsParam(msParam_t *var, Res *res, rError_t *errmsg) { strArray_t *arr = NULL; intArray_t *arr2 = NULL; int i = 0; int maxlen = 0; var->inpOutBuf = NULL; var->label = NULL; switch(TYPE(res)) { case T_ERROR: /* error message */ var->inOutStruct = (int *)malloc(sizeof(int)); *((int *)var->inOutStruct) = RES_ERR_CODE(res); var->type = strdup(INT_MS_T); break; case T_DOUBLE: /* number */ var->inOutStruct = (double *)malloc(sizeof(double)); *((double *)var->inOutStruct) = RES_DOUBLE_VAL(res); var->type = strdup(DOUBLE_MS_T); break; case T_INT: /* number */ var->inOutStruct = (int *)malloc(sizeof(int)); *((int *)var->inOutStruct) = RES_INT_VAL(res); var->type = strdup(INT_MS_T); break; case T_STRING: /* string */ var->inOutStruct = res->text == NULL? NULL : strdup(res->text); var->type = strdup(STR_MS_T); break; case T_PATH: /* path */ var->inOutStruct = res->text == NULL? NULL : strdup(res->text); var->type = strdup(STR_MS_T); break; case T_DATETIME: /* date time */ /*var->inOutStruct = (time_t *)malloc(sizeof(time_t)); */ /**((time_t *)var->inOutStruct) = res->value.t; */ /*var->type = strdup(DATETIME_MS_T); */ /* Here we pass datatime as an integer to reuse exiting packing instructions. Need to change to long int. */ var->inOutStruct = (rodsLong_t *)malloc(sizeof(int)); *((rodsLong_t *)var->inOutStruct) = RES_TIME_VAL(res); var->type = strdup(INT_MS_T); break; case T_CONS: if(strcmp(T_CONS_TYPE_NAME(res->exprType), LIST) == 0) { switch(getNodeType(T_CONS_TYPE_ARG(res->exprType, 0))) { case T_STRING: arr = (strArray_t *)malloc(sizeof(strArray_t)); arr->len = res->degree; maxlen = 0; for(i=0;i<res->degree;i++) { int slen = RES_STRING_STR_LEN(res->subtrees[i]); maxlen = maxlen < slen? slen: maxlen; } arr->size = maxlen; arr->value = (char *)malloc(sizeof(char)*maxlen*(arr->len)); for(i=0;i<res->degree;i++) { strcpy(arr->value + maxlen*i, res->subtrees[i]->text); } var->inOutStruct = arr; var->type = strdup(StrArray_MS_T); break; case T_INT: arr2 = (intArray_t *)malloc(sizeof(intArray_t)); arr2->len = res->degree; arr2->value = (int *)malloc(sizeof(int)*(arr2->len)); for(i=0;i<res->degree;i++) { arr2->value[i] = RES_INT_VAL(res); } var->inOutStruct = arr2; var->type = strdup(IntArray_MS_T); break; /*case T_IRODS: var->inOutStruct = res->value.uninterpreted.inOutStruct; var->inpOutBuf = res->value.uninterpreted.inOutBuffer; var->type = strdup(KeyValPair_MS_T); break;*/ default: /* current there is no existing packing instructions for arbitrary collection */ /* report error */ addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary collection type"); return RE_PACKING_ERROR; } } else { addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary constructed type"); return RE_PACKING_ERROR; } break; case T_IRODS: var->inOutStruct = RES_UNINTER_STRUCT(res); var->inpOutBuf = RES_UNINTER_BUFFER(res); var->type = strdup(res->exprType->text); break; case T_UNSPECED: var->inOutStruct = NULL; var->type = NULL; break; default: /*error */ addRErrorMsg(errmsg, RE_PACKING_ERROR, "no packing instruction for arbitrary type"); return RE_PACKING_ERROR; } return 0; }
int convertMsParamToResAndFreeNonIRODSType(msParam_t *mP, Res *res, rError_t *errmsg, Region *r) { #ifdef DEBUG writeToTmp("relog.txt", "type: "); writeToTmp("relog.txt", mP->type); writeToTmp("relog.txt", "\n"); #endif if(mP->type == NULL) { res->exprType = newSimpType(T_UNSPECED, r); return 0; } else if (strcmp(mP->type, DOUBLE_MS_T) == 0) { /* if the parameter is an integer */ convertDoubleValue(res, *(double *)mP->inOutStruct,r); free(mP->inOutStruct); mP->inOutStruct = NULL; return 0; } else if (strcmp(mP->type, INT_MS_T) == 0) { /* if the parameter is an integer */ /* this could be int, bool, or datatime */ if(res->exprType == NULL) { /* output parameter */ RES_INT_VAL_LVAL(res) = *(int *)mP->inOutStruct; res->exprType = newSimpType(T_INT, r); } else switch(TYPE(res)) { case T_INT: RES_INT_VAL_LVAL(res) = *(int *)mP->inOutStruct; break; case T_BOOL: RES_BOOL_VAL_LVAL(res) = *(int *)mP->inOutStruct; break; case T_DATETIME: RES_TIME_VAL(res) = *(rodsLong_t *)mP->inOutStruct; break; default: convertIntValue(res, *(int *)mP->inOutStruct,r); } free(mP->inOutStruct); mP->inOutStruct = NULL; return 0; } else if (strcmp(mP->type, STR_MS_T) == 0) { /* if the parameter is a string */ convertStrValue(res, (char *)mP->inOutStruct,r); free(mP->inOutStruct); mP->inOutStruct = NULL; return 0; } else if(strcmp(mP->type, DATETIME_MS_T) == 0) { RES_TIME_VAL(res) = *(rodsLong_t *)mP->inOutStruct; TYPE(res) = T_DATETIME; free(mP->inOutStruct); mP->inOutStruct = NULL; return 0; /* } else if(strcmp(mP->type, StrArray_MS_T) == 0) { convertCollectionToRes(mP, res); return 1; } else if(strcmp(mP->type, IntArray_MS_T) == 0) { convertCollectionToRes(mP, res); return 1; } else if(strcmp(mP->type, GenQueryOut_MS_T) == 0) { convertCollectionToRes(mP, res); return 1; */ } else { if(res->param==NULL) { res->param = newMsParam(mP->type, mP->inOutStruct, mP->inpOutBuf, r); } else { res->param->type = cpStringExt(mP->type, r); RES_UNINTER_STRUCT(res) = mP->inOutStruct; RES_UNINTER_BUFFER(res) = mP->inpOutBuf; } res->exprType = newIRODSType(mP->type,r); return 0; } }
int setStructPtrLeafValue( void **leafPtr, Res *newVarValue ) { *leafPtr = RES_UNINTER_STRUCT( newVarValue ); return 0; }