Exemple #1
0
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);
    }
}
Exemple #2
0
/************************ 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;
}
Exemple #3
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 setBufferPtrLeafValue( bytesBuf_t **leafPtr, Res *newVarValue ) {
    *leafPtr = RES_UNINTER_BUFFER( newVarValue );
    return 0;
}