int parseAndComputeRuleAdapter( char *rule, msParamArray_t *msParamArray, ruleExecInfo_t *rei, int reiSaveFlag, Region *r ) { /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; rError_t errmsgBuf; errmsgBuf.errMsg = NULL; errmsgBuf.len = 0; Env *env = defaultEnv( r ); rei->status = 0; int rescode = 0; if ( msParamArray != NULL ) { if ( strncmp( rule, "@external\n", 10 ) == 0 ) { rescode = parseAndComputeMsParamArrayToEnv( msParamArray, globalEnv( env ), rei, reiSaveFlag, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); rule = rule + 10; } else { rescode = convertMsParamArrayToEnv( msParamArray, globalEnv( env ), r ); RE_ERROR( rescode < 0 ); } } deleteFromHashTable(globalEnv(env)->current, "ruleExecOut"); rei->msParamArray = msParamArray; rescode = parseAndComputeRule( rule, env, rei, reiSaveFlag, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); if ( NULL == rei->msParamArray ) { rei->msParamArray = newMsParamArray(); } rescode = convertEnvToMsParamArray( rei->msParamArray, env, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ return rescode; error: logErrMsg( &errmsgBuf, &rei->rsComm->rError ); rei->status = rescode; freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return rescode; }
/* * Set retOutParam to 1 if you need to retrieve the output parameters from inMsParamArray and 0 if not */ Res *parseAndComputeExpressionAdapter( char *inAction, msParamArray_t *inMsParamArray, int retOutParams, ruleExecInfo_t *rei, int reiSaveFlag, Region *r ) { // JMC - backport 4540 /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; int freeRei = 0; if ( rei == NULL ) { rei = ( ruleExecInfo_t * ) malloc( sizeof( ruleExecInfo_t ) ); memset( rei, 0, sizeof( ruleExecInfo_t ) ); freeRei = 1; } rei->status = 0; Env *env = defaultEnv( r ); /* retrieve generated data here as it may be overridden by convertMsParamArrayToEnv */ Res *res; rError_t errmsgBuf; errmsgBuf.errMsg = NULL; errmsgBuf.len = 0; if ( inMsParamArray != NULL ) { convertMsParamArrayToEnv( inMsParamArray, env, r ); deleteFromHashTable(env->current, "ruleExecOut"); } res = parseAndComputeExpression( inAction, env, rei, reiSaveFlag, &errmsgBuf, r ); if ( retOutParams ) { // JMC - backport 4540 if ( inMsParamArray != NULL ) { clearMsParamArray( inMsParamArray, 0 ); convertEnvToMsParamArray( inMsParamArray, env, &errmsgBuf, r ); } } /* deleteEnv(env, 3); */ if ( getNodeType( res ) == N_ERROR && !freeRei ) { logErrMsg( &errmsgBuf, &rei->rsComm->rError ); rei->status = RES_ERR_CODE( res ); } freeRErrorContent( &errmsgBuf ); if ( freeRei ) { free( rei ); } if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return res; }
void removeRuleFromExtIndex(char *ruleName, int i) { if(isComponentInitialized(ruleEngineConfig.extFuncDescIndexStatus)) { FunctionDesc *fd = (FunctionDesc *)lookupFromHashTable(ruleEngineConfig.extFuncDescIndex->current, ruleName); RuleIndexList *rd = FD_RULE_INDEX_LIST(fd); removeNodeFromRuleIndexList2(rd, i); if(rd->head == NULL) { deleteFromHashTable(ruleEngineConfig.extFuncDescIndex->current, ruleName); } } }
int deleteGlobalLight(const int id){ int lightindex = (id & 0xFFFF); globallight_t * ent = &globallightlist[lightindex]; if(ent->myid != id) return FALSE; if(!ent->name) return FALSE; deleteFromHashTable(ent->name, id, globallighthashtable); free(ent->name); memset(ent, 0, sizeof(globallight_t)); if(lightindex < globallightArrayFirstOpen) globallightArrayFirstOpen = lightindex; for(; globallightArrayLastTaken > 0 && !lightlist[globallightArrayLastTaken].type; globallightArrayLastTaken--); return TRUE; }
/************************************************************************** * private functions **************************************************************************/ static void *_preloadThread(void *arg) { int status; preloadThreadData_t *threadData = (preloadThreadData_t *)arg; preloadThreadInfo_t *threadInfo = NULL; if(threadData == NULL) { rodsLog (LOG_DEBUG, "_preloadThread: given thread argument is null"); pthread_exit(NULL); } threadInfo = threadData->threadInfo; rodsLog (LOG_DEBUG, "_preloadThread: preload - %s", threadData->path); status = _download(threadData->path, &threadData->stbuf); if(status != 0) { rodsLog (LOG_DEBUG, "_preloadThread: download error - %d", status); } // downloading is done LOCK(PreloadLock); // change thread status LOCK_STRUCT(*threadInfo); threadInfo->running = PRELOAD_THREAD_IDLE; UNLOCK_STRUCT(*threadInfo); // release threadData rodsLog (LOG_DEBUG, "_preloadThread: thread finished - %s", threadData->path); if(threadData->path != NULL) { free(threadData->path); threadData->path = NULL; } free(threadData); // remove from hash table removeFromConcurrentList2(PreloadThreadList, threadInfo); deleteFromHashTable(PreloadThreadTable, threadInfo->path); if(threadInfo != NULL) { if(threadInfo->path != NULL) { free(threadInfo->path); threadInfo->path = NULL; } free(threadInfo); } UNLOCK(PreloadLock); pthread_exit(NULL); }
int closeLazyUploadBufferedFile (const char *path) { int status; char iRODSPath[MAX_NAME_LEN]; char bufferPath[MAX_NAME_LEN]; lazyUploadFileInfo_t *lazyUploadFileInfo = NULL; // convert input path to iRODSPath status = _getiRODSPath(path, iRODSPath); if(status < 0) { rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: failed to get iRODS path - %s", path); return status; } status = _getBufferPath(iRODSPath, bufferPath); if(status < 0) { rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: failed to get Buffered lazy upload file path - %s", iRODSPath); return status; } LOCK(LazyUploadLock); // remove buffered file unlink(bufferPath); lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath); if(lazyUploadFileInfo != NULL) { // has lazy-upload file handle opened if(lazyUploadFileInfo->localHandle > 0) { close(lazyUploadFileInfo->localHandle); lazyUploadFileInfo->localHandle = -1; rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: close lazy-upload Buffered file handle - %s", iRODSPath); } deleteFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath); if(lazyUploadFileInfo->path != NULL) { free(lazyUploadFileInfo->path); lazyUploadFileInfo->path = NULL; } free(lazyUploadFileInfo); } UNLOCK(LazyUploadLock); rodsLog (LOG_DEBUG, "closeLazyUploadBufferedFile: closed lazy-upload cache handle - %s", iRODSPath); return status; }
int entity_delete(const int id){ int entityindex = (id & 0xFFFF); entity_t * ent = &entity_list[entityindex]; if(ent->myid != id) return FALSE; if(!ent->name) return FALSE; deleteFromHashTable(ent->name, id, entityhashtable); free(ent->name); memset(ent, 0, sizeof(entity_t)); // ent->type = 0; // ent->model = 0; // ent->name = 0; // ent->myid = 0; if(entityindex < entity_arrayfirstopen) entity_arrayfirstopen = entityindex; for(; entity_arraylasttaken > 0 && !entity_list[entity_arraylasttaken].type; entity_arraylasttaken--); return TRUE; }
int closePreloadedFile (const char *path) { int status; char iRODSPath[MAX_NAME_LEN]; preloadFileHandleInfo_t *preloadFileHandleInfo = NULL; preloadFileHandleInfo_t *tmpPreloadFileHandleInfo = NULL; status = _getiRODSPath(path, iRODSPath); if(status < 0) { rodsLogError(LOG_ERROR, status, "closePreloadedFile: _getiRODSPath error."); rodsLog (LOG_ERROR, "closePreloadedFile: failed to get iRODS path - %s", path); return status; } LOCK(PreloadLock); preloadFileHandleInfo = (preloadFileHandleInfo_t *)lookupFromHashTable(PreloadFileHandleTable, iRODSPath); if(preloadFileHandleInfo != NULL) { // has preload file handle opened if(preloadFileHandleInfo->handle > 0) { close(preloadFileHandleInfo->handle); preloadFileHandleInfo->handle = -1; rodsLog (LOG_DEBUG, "closePreloadedFile: close preloaded cache handle - %s", iRODSPath); } if(preloadFileHandleInfo->path != NULL) { free(preloadFileHandleInfo->path); preloadFileHandleInfo->path = NULL; } // remove from hash table tmpPreloadFileHandleInfo = (preloadFileHandleInfo_t *)deleteFromHashTable(PreloadFileHandleTable, iRODSPath); if(tmpPreloadFileHandleInfo != NULL) { free(tmpPreloadFileHandleInfo); } } UNLOCK(PreloadLock); return status; }
int parseAndComputeRuleNewEnv( char *rule, ruleExecInfo_t *rei, int reiSaveFlag, msParamArray_t *msParamArray, rError_t *errmsg, Region *r ) { Env *env = defaultEnv( r ); int rescode = 0; if ( msParamArray != NULL ) { rescode = convertMsParamArrayToEnv( msParamArray, env->previous, r ); RE_ERROR( rescode < 0 ); deleteFromHashTable(env->previous->current, "ruleExecOut"); } rescode = parseAndComputeRule( rule, env, rei, reiSaveFlag, errmsg, r ); RE_ERROR( rescode < 0 ); rescode = convertEnvToMsParamArray( rei->msParamArray, env, errmsg, r ); RE_ERROR( rescode < 0 ); /* deleteEnv(env, 3); */ return rescode; error: /* deleteEnv(env, 3); */ return rescode; }
/* call an action with actionName and string parameters */ Res *computeExpressionWithParams( const char *actionName, const char **params, int paramsCount, ruleExecInfo_t *rei, int reiSaveFlag, msParamArray_t *msParamArray, rError_t *errmsg, Region *r ) { #ifdef DEBUG char buf[ERR_MSG_LEN > 1024 ? ERR_MSG_LEN : 1024]; snprintf( buf, 1024, "computExpressionWithParams: %s\n", actionName ); writeToTmp( "entry.log", buf ); #endif /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; if ( overflow( actionName, MAX_NAME_LEN ) ) { addRErrorMsg( errmsg, RE_BUFFER_OVERFLOW, "error: potential buffer overflow" ); return newErrorRes( r, RE_BUFFER_OVERFLOW ); } int k; for ( k = 0; k < paramsCount; k++ ) { if ( overflow( params[k], MAX_RULE_LEN ) ) { addRErrorMsg( errmsg, RE_BUFFER_OVERFLOW, "error: potential buffer overflow" ); return newErrorRes( r, RE_BUFFER_OVERFLOW ); } } Node** paramNodes = ( Node ** )region_alloc( r, sizeof( Node * ) * paramsCount ); int i; for ( i = 0; i < paramsCount; i++ ) { Node *node; /*Pointer *e = newPointer2(params[i]); if(e == NULL) { addRErrorMsg(errmsg, -1, "error: can not create Pointer."); return newErrorRes(r, -1); } node = parseTermRuleGen(e, 1, errmsg, r);*/ node = newNode( TK_STRING, params[i], 0, r ); /*if(node==NULL) { addRErrorMsg(errmsg, OUT_OF_MEMORY, "error: out of memory."); return newErrorRes(r, OUT_OF_MEMORY); } else if (getNodeType(node) == N_ERROR) { return newErrorRes(r, RES_ERR_CODE(node)); }*/ paramNodes[i] = node; } Node *node = createFunctionNode( actionName, paramNodes, paramsCount, NULL, r ); Env *global = newEnv( newHashTable2( 10, r ), NULL, NULL, r ); Env *env = newEnv( newHashTable2( 10, r ), global, NULL, r ); if ( msParamArray != NULL ) { convertMsParamArrayToEnv( msParamArray, global, r ); deleteFromHashTable(global->current, "ruleExecOut"); } Res *res = computeNode( node, NULL, env, rei, reiSaveFlag, errmsg, r ); /* deleteEnv(env, 3); */ if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return res; }
int parseAndComputeRuleAdapter( char *rule, msParamArray_t *msParamArray, ruleExecInfo_t *rei, int reiSaveFlag, Region *r ) { /* set clearDelayed to 0 so that nested calls to this function do not call clearDelay() */ int recclearDelayed = ruleEngineConfig.clearDelayed; ruleEngineConfig.clearDelayed = 0; rError_t errmsgBuf; errmsgBuf.errMsg = NULL; errmsgBuf.len = 0; Env *env = defaultEnv( r ); rei->status = 0; msParamArray_t *orig = NULL; Res *execOutRes; int rescode = 0; if ( msParamArray != NULL ) { if ( strncmp( rule, "@external\n", 10 ) == 0 ) { rescode = parseAndComputeMsParamArrayToEnv( msParamArray, globalEnv( env ), rei, reiSaveFlag, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); rule = rule + 10; } else { rescode = convertMsParamArrayToEnv( msParamArray, globalEnv( env ), r ); RE_ERROR( rescode < 0 ); } } if ( ( execOutRes = ( Res * )lookupFromEnv( env, "ruleExecOut" ) ) == NULL || TYPE( execOutRes ) == T_UNSPECED ) { /* add cmdExecOut only if ruleExecOut is an output parameter */ deleteFromHashTable( globalEnv( env )->current, "ruleExecOut" ); addCmdExecOutToEnv( globalEnv( env ), r ); } orig = rei->msParamArray; rei->msParamArray = NULL; rescode = parseAndComputeRule( rule, env, rei, reiSaveFlag, &errmsgBuf, r ); if ( orig == NULL ) { rei->msParamArray = newMsParamArray(); } else { rei->msParamArray = orig; } convertEnvToMsParamArray( rei->msParamArray, env, &errmsgBuf, r ); RE_ERROR( rescode < 0 ); freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ return rescode; error: logErrMsg( &errmsgBuf, &rei->rsComm->rError ); rei->status = rescode; freeRErrorContent( &errmsgBuf ); /* deleteEnv(env, 3); */ if ( recclearDelayed ) { clearDelayed(); } ruleEngineConfig.clearDelayed = recclearDelayed; return rescode; }
int openLazyUploadBufferedFile(const char *path, int accmode) { int status; lazyUploadFileInfo_t *lazyUploadFileInfo = NULL; char iRODSPath[MAX_NAME_LEN]; char bufferPath[MAX_NAME_LEN]; int desc; // convert input path to iRODSPath status = _getiRODSPath(path, iRODSPath); if(status < 0) { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: failed to get iRODS path - %s", path); return status; } status = _getBufferPath(iRODSPath, bufferPath); if(status < 0) { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: failed to get buffer path - %s", iRODSPath); return status; } LOCK(LazyUploadLock); desc = -1; // check the given file is Buffered lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath); if(lazyUploadFileInfo != NULL) { // has lazy upload file opened rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: same file is already opened for lazy-upload - %s", iRODSPath); UNLOCK(LazyUploadLock); return -EMFILE; } lazyUploadFileInfo = (lazyUploadFileInfo_t *)lookupFromHashTable(LazyUploadBufferedFileTable_Created, iRODSPath); if(lazyUploadFileInfo != NULL) { // has lazy upload file handle opened if(lazyUploadFileInfo->localHandle > 0) { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: same file is already opened for lazy-upload - %s", iRODSPath); UNLOCK(LazyUploadLock); return -EMFILE; } else { // update file handle and access mode desc = open (bufferPath, O_RDWR|O_CREAT|O_TRUNC, 0755); if(desc > 0) { lazyUploadFileInfo->accmode = accmode; lazyUploadFileInfo->localHandle = desc; rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: opens a file handle - %s", iRODSPath); // move to opened hashtable deleteFromHashTable(LazyUploadBufferedFileTable_Created, iRODSPath); insertIntoHashTable(LazyUploadBufferedFileTable_Opened, iRODSPath, lazyUploadFileInfo); } } } else { rodsLog (LOG_DEBUG, "openLazyUploadBufferedFile: mknod is not called before opening - %s", iRODSPath); UNLOCK(LazyUploadLock); return -EBADF; } UNLOCK(LazyUploadLock); return desc; }