00001
00002
00003 #include "reGlobals.h"
00004 #include "initServer.h"
00005 #include "reHelpers1.h"
00006 #include "apiHeaderAll.h"
00007 #include "parser.h"
00008 #include "index.h"
00009 #include "rules.h"
00010 #include "cache.h"
00011 #include "locks.h"
00012 #include "functions.h"
00013 #include "configuration.h"
00014 #ifndef USE_EIRODS
00015 #include "reAction.h"
00016 #endif
00017
00018
00019
00020
00021
00022 #ifdef MYMALLOC
00023 # Within reLib1.c here, change back the redefines of malloc back to normal
00024 #define malloc(x) malloc(x)
00025 #define free(x) free(x)
00026 #endif
00027
00028 int processReturnRes(Res *res);
00029
00030 int
00031 applyRuleArg(char *action, char *args[MAX_NUM_OF_ARGS_IN_ACTION], int argc,
00032 ruleExecInfo_t *rei, int reiSaveFlag)
00033 {
00034 #ifdef DEBUG
00035 writeToTmp("entry.log", "applyRuleArg: ");
00036 writeToTmp("entry.log", action);
00037 writeToTmp("entry.log", "(pass on to applyRulePA)\n");
00038 #endif
00039 msParamArray_t *inMsParamArray = NULL;
00040 int i;
00041
00042 i = applyRuleArgPA(action ,args, argc, inMsParamArray, rei, reiSaveFlag);
00043 return(i);
00044 }
00045
00046
00047
00048
00049
00050 int
00051 applyRuleArgPA(char *action, char *args[MAX_NUM_OF_ARGS_IN_ACTION], int argc,
00052 msParamArray_t *inMsParamArray, ruleExecInfo_t *rei, int reiSaveFlag)
00053 {
00054 #ifdef DEBUG
00055 writeToTmp("entry.log", "applyRuleArgPa: ");
00056 writeToTmp("entry.log", action);
00057 writeToTmp("entry.log", "\n");
00058 #endif
00059 int i;
00060
00061 Region *r = make_region(0, NULL);
00062 rError_t errmsgBuf;
00063 errmsgBuf.errMsg = NULL;
00064 errmsgBuf.len = 0;
00065 Res *res = computeExpressionWithParams(action, args, argc, rei, reiSaveFlag, inMsParamArray, &errmsgBuf, r);
00066 i = processReturnRes(res);
00067 region_free(r);
00068
00069 #if 0
00070
00071 if (i == 0) {
00072 for (i = 0; i < argc ; i++) {
00073 if ((mP = getMsParamByLabel (inMsParamArray, args[i])) != NULL)
00074 strcpy(args[i], (char *) mP->inOutStruct);
00075
00076 }
00077 i = 0;
00078 }
00079
00080 #endif
00081 if(i<0) {
00082 logErrMsg(&errmsgBuf, &rei->rsComm->rError);
00083 }
00084 freeRErrorContent(&errmsgBuf);
00085 return(i);
00086
00087 }
00088
00089
00090 int processReturnRes(Res *res) {
00091 int ret;
00092 if(res->nodeType == N_ERROR) {
00093 ret = RES_ERR_CODE(res);
00094 } else {
00095 switch(TYPE(res)) {
00096 case T_INT:
00097 ret = RES_INT_VAL(res);
00098 break;
00099 default:
00100 ret = 0;
00101 break;
00102 }
00103 }
00104
00105 return ret;
00106 }
00107 int computeExpression(char *inAction, msParamArray_t *inMsParamArray, ruleExecInfo_t *rei, int reiSaveFlag, char *res) {
00108 #ifdef DEBUG
00109 writeToTmp("entry.log", "computeExpression: ");
00110 writeToTmp("entry.log", inAction);
00111 writeToTmp("entry.log", "\n");
00112 #endif
00113
00114 Region *r = make_region(0, NULL);
00115
00116 Res *res0 = parseAndComputeExpressionAdapter(inAction, inMsParamArray, 0, rei, reiSaveFlag, r);
00117 int ret;
00118 char *res1 = convertResToString(res0);
00119 snprintf(res, MAX_COND_LEN, "%s", res1);
00120 free(res1);
00121
00122 if(getNodeType(res0) == N_ERROR) {
00123 ret = RES_ERR_CODE(res0);
00124 } else {
00125 switch(TYPE(res0)) {
00126 case T_INT:
00127 ret = RES_INT_VAL(res0);
00128 break;
00129 case T_BOOL:
00130 ret = !RES_BOOL_VAL(res0);
00131 break;
00132 default:
00133 ret = 0;
00134 break;
00135 }
00136 }
00137 region_free(r);
00138
00139 return ret;
00140 }
00141
00142
00143
00144
00145 int
00146 applyRule(char *inAction, msParamArray_t *inMsParamArray,
00147 ruleExecInfo_t *rei, int reiSaveFlag)
00148 {
00149 #if defined(DEBUG) || defined(RE_LOG_RULES_TMP)
00150 writeToTmp("entry.log", "applyRule: ");
00151 writeToTmp("entry.log", inAction);
00152 writeToTmp("entry.log", "\n");
00153 #endif
00154 if (GlobalREAuditFlag > 0)
00155 reDebug("ApplyRule", -1, "", inAction,NULL,NULL,rei);
00156
00157 Region *r = make_region(0, NULL);
00158
00159 int ret;
00160 Res *res;
00161 if(inAction[strlen(inAction)-1]=='|') {
00162 char *inActionCopy = strdup(inAction);
00163 inActionCopy[strlen(inAction) - 1] = '\0';
00164 char *action = (char *) malloc(sizeof(char) * strlen(inAction) + 3);
00165 sprintf(action, "{%s}", inActionCopy);
00166 res = parseAndComputeExpressionAdapter(action, inMsParamArray, 0, rei, reiSaveFlag, r);
00167 free(action);
00168 free(inActionCopy);
00169 } else {
00170 res = parseAndComputeExpressionAdapter(inAction, inMsParamArray, 0, rei, reiSaveFlag, r);
00171 }
00172 ret = processReturnRes(res);
00173 region_free(r);
00174 if (GlobalREAuditFlag > 0)
00175 reDebug("ApplyRule", -1, "Done", inAction,NULL,NULL,rei);
00176
00177 return ret;
00178
00179 }
00180
00181
00182 int
00183 applyRuleUpdateParams(char *inAction, msParamArray_t *inMsParamArray,
00184 ruleExecInfo_t *rei, int reiSaveFlag)
00185 {
00186 #ifdef DEBUG
00187 writeToTmp("entry.log", "applyRule: ");
00188 writeToTmp("entry.log", inAction);
00189 writeToTmp("entry.log", "\n");
00190 #endif
00191 if (GlobalREAuditFlag > 0)
00192 reDebug("ApplyRule", -1, "", inAction,NULL,NULL,rei);
00193
00194 Region *r = make_region(0, NULL);
00195
00196 int ret;
00197 Res *res;
00198 res = parseAndComputeExpressionAdapter(inAction, inMsParamArray, 1, rei, reiSaveFlag, r);
00199 ret = processReturnRes(res);
00200 region_free(r);
00201 if (GlobalREAuditFlag > 0)
00202 reDebug("ApplyRule", -1, "Done", inAction,NULL,NULL,rei);
00203
00204 return ret;
00205
00206 }
00207
00208
00209
00210
00211
00212
00213
00214 int
00215 applyAllRules(char *inAction, msParamArray_t *inMsParamArray,
00216 ruleExecInfo_t *rei, int reiSaveFlag, int allRuleExecFlag)
00217 {
00218 #ifdef DEBUG
00219 writeToTmp("entry.log", "applyAllRules: ");
00220 writeToTmp("entry.log", inAction);
00221 writeToTmp("entry.log", "(set GlobalAllRuleExecFlag and forward to applyRule)\n");
00222 #endif
00223
00224
00225 int tempFlag = GlobalAllRuleExecFlag;
00226
00227 GlobalAllRuleExecFlag = allRuleExecFlag == 1? 2 : 1;
00228
00229 if (GlobalREAuditFlag > 0)
00230 reDebug("ApplyAllRules", -1, "", inAction,NULL, NULL,rei);
00231
00232 int ret = applyRule(inAction, inMsParamArray, rei, reiSaveFlag);
00233 if (GlobalREAuditFlag > 0)
00234 reDebug("ApplyAllRules", -1, "Done", inAction,NULL,NULL,rei);
00235
00236
00237 GlobalAllRuleExecFlag = tempFlag;
00238 return ret;
00239 }
00240
00241 int
00242 execMyRule(char * ruleDef, msParamArray_t *inMsParamArray, char *outParamsDesc,
00243 ruleExecInfo_t *rei)
00244 {
00245
00246 return execMyRuleWithSaveFlag(ruleDef, inMsParamArray, outParamsDesc, rei, 0);
00247 }
00248 void appendOutputToInput(msParamArray_t *inpParamArray, char **outParamNames, int outParamN) {
00249 int i, k, repeat = 0;
00250 for(i=0;i<outParamN;i++) {
00251 if(strcmp(outParamNames[i], ALL_MS_PARAM_KW)==0) {
00252 continue;
00253 }
00254 repeat = 0;
00255 for(k=0;k<inpParamArray->len;k++) {
00256 if(inpParamArray->msParam[k]->label!=NULL && strcmp(outParamNames[i], inpParamArray->msParam[k]->label) == 0) {
00257 repeat = 1;
00258 break;
00259 }
00260 }
00261 if(!repeat) {
00262 addMsParam (inpParamArray, outParamNames[i], NULL, NULL, NULL);
00263 }
00264 }
00265
00266 }
00267 int extractVarNames(char **varNames, char *outBuf) {
00268 int n = 0;
00269 char *p = outBuf;
00270 char *psrc = p;
00271
00272 for(;;) {
00273 if(*psrc == '%') {
00274 *psrc = '\0';
00275 varNames[n++] = strdup(p);
00276 *psrc = '%';
00277 p = psrc+1;
00278 } else if(*psrc == '\0') {
00279 if(strlen(p) != 0) {
00280 varNames[n++] = strdup(p);
00281 }
00282 break;
00283 }
00284 psrc++;
00285 }
00286 return n;
00287 }
00288
00289 int
00290 execMyRuleWithSaveFlag(char * ruleDef, msParamArray_t *inMsParamArray, char *outParamsDesc,
00291 ruleExecInfo_t *rei,int reiSaveFlag)
00292
00293 {
00294 int status;
00295 if (GlobalREAuditFlag)
00296 reDebug("ExecMyRule", -1, "", ruleDef,NULL, NULL,rei);
00297
00298 char *outParamNames[MAX_PARAMS_LEN];
00299 int n = extractVarNames(outParamNames, outParamsDesc);
00300 appendOutputToInput(inMsParamArray, outParamNames, n);
00301 Region *r = make_region(0, NULL);
00302 status =
00303 parseAndComputeRuleAdapter(ruleDef, inMsParamArray, rei, reiSaveFlag, r);
00304 region_free(r);
00305 if (status < 0) {
00306 rodsLog (LOG_NOTICE,"execMyRule %s Failed with status %i",ruleDef, status);
00307 }
00308
00309 if (GlobalREAuditFlag)
00310 reDebug("ExecMyRule", -1, "Done", ruleDef,NULL, NULL,rei);
00311 return(status);
00312 }
00313
00314 int
00315 initRuleStruct(int processType, rsComm_t *svrComm, char *irbSet, char *dvmSet, char *fnmSet)
00316 {
00317 int i;
00318 char r1[NAME_LEN], r2[RULE_SET_DEF_LENGTH], r3[RULE_SET_DEF_LENGTH];
00319
00320
00321 coreRuleStrct.MaxNumOfRules = 0;
00322 appRuleStrct.MaxNumOfRules = 0;
00323 GlobalAllRuleExecFlag = 0;
00324
00325 if(processType == RULE_ENGINE_INIT_CACHE) {
00326 resetMutex(NULL);
00327 }
00328
00329
00330
00331 i = readRuleStructFromFile(processType, irbSet, &coreRuleStrct);
00332 if (i < 0)
00333 return(i);
00334
00335
00336 strcpy(r2,dvmSet);
00337 coreRuleVarDef.MaxNumOfDVars = 0;
00338 appRuleVarDef.MaxNumOfDVars = 0;
00339
00340 while (strlen(r2) > 0) {
00341 i = rSplitStr(r2,r1,NAME_LEN,r3,RULE_SET_DEF_LENGTH,',');
00342 if (i == 0)
00343 i = readDVarStructFromFile(r1, &coreRuleVarDef);
00344 if (i < 0)
00345 return(i);
00346 strcpy(r2,r3);
00347 }
00348 strcpy(r2,fnmSet);
00349 coreRuleFuncMapDef.MaxNumOfFMaps = 0;
00350 appRuleFuncMapDef.MaxNumOfFMaps = 0;
00351
00352 while (strlen(r2) > 0) {
00353 i = rSplitStr(r2,r1,NAME_LEN,r3,RULE_SET_DEF_LENGTH,',');
00354 if (i == 0)
00355 i = readFuncMapStructFromFile(r1, &coreRuleFuncMapDef);
00356 if (i < 0)
00357 return(i);
00358 strcpy(r2,r3);
00359 }
00360
00361 if (getenv(RETESTFLAG) != NULL) {
00362 reTestFlag = atoi(getenv(RETESTFLAG));
00363 if (getenv(RELOOPBACKFLAG) != NULL)
00364 reLoopBackFlag = atoi(getenv(RELOOPBACKFLAG));
00365 else
00366 reLoopBackFlag = 0;
00367 }
00368 else {
00369 reTestFlag = 0;
00370 reLoopBackFlag = 0;
00371 }
00372 if (getenv("GLOBALALLRULEEXECFLAG") != NULL)
00373 GlobalAllRuleExecFlag = 9;
00374
00375 if (getenv(GLOBALREDEBUGFLAG) != NULL) {
00376 GlobalREDebugFlag = atoi(getenv(GLOBALREDEBUGFLAG));
00377 }
00378 if (getenv(GLOBALREAUDITFLAG) != NULL) {
00379 GlobalREAuditFlag = atoi(getenv(GLOBALREAUDITFLAG));
00380 }
00381 if (GlobalREAuditFlag == 0 ) {
00382 GlobalREAuditFlag = GlobalREDebugFlag;
00383 }
00384 delayStack.size = NAME_LEN;
00385 delayStack.len = 0;
00386 delayStack.value = NULL;
00387
00388 msParamStack.size = NAME_LEN;
00389 msParamStack.len = 0;
00390 msParamStack.value = NULL;
00391
00392 initializeReDebug(svrComm, GlobalREDebugFlag);
00393
00394 return(0);
00395 }
00396
00397
00398 int
00399 readRuleSetFromDB(char *ruleBaseName, char *versionStr, RuleSet *ruleSet, ruleExecInfo_t *rei, rError_t *errmsg, Region *region)
00400 {
00401 int i,status;
00402 genQueryInp_t genQueryInp;
00403 genQueryOut_t *genQueryOut = NULL;
00404 char condstr[MAX_NAME_LEN], condstr2[MAX_NAME_LEN];
00405 sqlResult_t *r[8];
00406 memset(&genQueryInp, 0, sizeof(genQueryInp));
00407 genQueryInp.maxRows = MAX_SQL_ROWS;
00408
00409 snprintf(condstr, MAX_NAME_LEN, "= '%s'", ruleBaseName);
00410 addInxVal(&genQueryInp.sqlCondInp, COL_RULE_BASE_MAP_BASE_NAME, condstr);
00411 snprintf(condstr2, MAX_NAME_LEN, "= '%s'", versionStr);
00412 addInxVal(&genQueryInp.sqlCondInp, COL_RULE_BASE_MAP_VERSION, condstr2);
00413
00414 addInxIval(&genQueryInp.selectInp, COL_RULE_BASE_MAP_PRIORITY, ORDER_BY);
00415 addInxIval(&genQueryInp.selectInp, COL_RULE_BASE_MAP_BASE_NAME, 1);
00416 addInxIval(&genQueryInp.selectInp, COL_RULE_NAME, 1);
00417 addInxIval(&genQueryInp.selectInp, COL_RULE_EVENT, 1);
00418 addInxIval(&genQueryInp.selectInp, COL_RULE_CONDITION, 1);
00419 addInxIval(&genQueryInp.selectInp, COL_RULE_BODY, 1);
00420 addInxIval(&genQueryInp.selectInp, COL_RULE_RECOVERY, 1);
00421 addInxIval(&genQueryInp.selectInp, COL_RULE_ID, 1);
00422 Env *env = newEnv(newHashTable2(100, region), NULL, NULL, region);
00423 status = rsGenQuery(rei->rsComm, &genQueryInp, &genQueryOut);
00424 while ( status >= 0 && genQueryOut->rowCnt > 0 ) {
00425 r[0] = getSqlResultByInx (genQueryOut, COL_RULE_BASE_MAP_BASE_NAME);
00426 r[1] = getSqlResultByInx (genQueryOut, COL_RULE_NAME);
00427 r[2] = getSqlResultByInx (genQueryOut, COL_RULE_EVENT);
00428 r[3] = getSqlResultByInx (genQueryOut, COL_RULE_CONDITION);
00429 r[4] = getSqlResultByInx (genQueryOut, COL_RULE_BODY);
00430 r[5] = getSqlResultByInx (genQueryOut, COL_RULE_RECOVERY);
00431 r[6] = getSqlResultByInx (genQueryOut, COL_RULE_ID);
00432 for (i = 0; i<genQueryOut->rowCnt; i++) {
00433 char ruleStr[MAX_RULE_LEN * 4];
00434
00435
00436 char *ruleHead = strdup(&r[2]->value[r[2]->len * i]);
00437 char *ruleCondition = strdup(&r[3]->value[r[3]->len * i]);
00438 char *ruleAction = strdup(&r[4]->value[r[4]->len * i]);
00439 char *ruleRecovery = strdup(&r[5]->value[r[5]->len * i]);
00440 long ruleId = atol(&r[6]->value[r[6]->len * i]);
00441 if(ruleRecovery[0] == '@') {
00442
00443 if(strcmp(ruleRecovery+1, "DATA") == 0) {
00444 snprintf(ruleStr, MAX_RULE_LEN * 4, "data %s", ruleHead);
00445 } else if(strcmp(ruleRecovery+1, "CONSTR") == 0) {
00446 snprintf(ruleStr, MAX_RULE_LEN * 4, "constructor %s : %s", ruleHead, ruleAction);
00447 } else if(strcmp(ruleRecovery+1, "EXTERN") == 0) {
00448 snprintf(ruleStr, MAX_RULE_LEN * 4, "%s : %s", ruleHead, ruleAction);
00449 } else if(strcmp(ruleRecovery+1, "FUNC") == 0) {
00450 snprintf(ruleStr, MAX_RULE_LEN * 4, "%s = %s\n @(\"id\", \"%ld\")", ruleHead, ruleAction, ruleId);
00451 } else {
00452 snprintf(ruleStr, MAX_RULE_LEN * 4, "%s { on %s %s @(\"id\", \"%ld\") }\n", ruleHead, ruleCondition, ruleAction, ruleId);
00453 }
00454 } else {
00455 snprintf(ruleStr, MAX_RULE_LEN * 4, "%s|%s|%s|%s", ruleHead, ruleCondition, ruleAction, ruleRecovery);
00456 }
00457 Pointer *p = newPointer2(ruleStr);
00458 int errloc;
00459 int errcode = parseRuleSet(p, ruleSet, env, &errloc, errmsg, region);
00460 deletePointer(p);
00461 if(errcode<0) {
00462
00463 freeGenQueryOut (&genQueryOut);
00464 free( ruleHead );
00465 free( ruleCondition );
00466 free( ruleAction );
00467 free( ruleRecovery );
00468 return errcode;
00469 }
00470
00471 free( ruleHead );
00472 free( ruleCondition );
00473 free( ruleAction );
00474 free( ruleRecovery );
00475
00476 }
00477 genQueryInp.continueInx = genQueryOut->continueInx;
00478 freeGenQueryOut (&genQueryOut);
00479 if (genQueryInp.continueInx > 0) {
00480
00481 status = rsGenQuery (rei->rsComm, &genQueryInp, &genQueryOut);
00482 }
00483 else
00484 break;
00485 }
00486
00487 return(0);
00488 }
00489
00490 int
00491 readRuleStructFromDB(char *ruleBaseName, char *versionStr, ruleStruct_t *inRuleStrct, ruleExecInfo_t *rei)
00492 {
00493 int i,l,status;
00494 genQueryInp_t genQueryInp;
00495 genQueryOut_t *genQueryOut = NULL;
00496 char condstr[MAX_NAME_LEN], condstr2[MAX_NAME_LEN];
00497 sqlResult_t *r[8];
00498 memset(&genQueryInp, 0, sizeof(genQueryInp));
00499 genQueryInp.maxRows = MAX_SQL_ROWS;
00500
00501 snprintf(condstr, MAX_NAME_LEN, "= '%s'", ruleBaseName);
00502 addInxVal(&genQueryInp.sqlCondInp, COL_RULE_BASE_MAP_BASE_NAME, condstr);
00503 snprintf(condstr2, MAX_NAME_LEN, "= '%s'", versionStr);
00504 addInxVal(&genQueryInp.sqlCondInp, COL_RULE_BASE_MAP_VERSION, condstr2);
00505
00506 addInxIval(&genQueryInp.selectInp, COL_RULE_BASE_MAP_PRIORITY, ORDER_BY);
00507 addInxIval(&genQueryInp.selectInp, COL_RULE_BASE_MAP_BASE_NAME, 1);
00508 addInxIval(&genQueryInp.selectInp, COL_RULE_NAME, 1);
00509 addInxIval(&genQueryInp.selectInp, COL_RULE_EVENT, 1);
00510 addInxIval(&genQueryInp.selectInp, COL_RULE_CONDITION, 1);
00511 addInxIval(&genQueryInp.selectInp, COL_RULE_BODY, 1);
00512 addInxIval(&genQueryInp.selectInp, COL_RULE_RECOVERY, 1);
00513 addInxIval(&genQueryInp.selectInp, COL_RULE_ID, 1);
00514 l = inRuleStrct->MaxNumOfRules;
00515 status = rsGenQuery(rei->rsComm, &genQueryInp, &genQueryOut);
00516 while ( status >= 0 && genQueryOut->rowCnt > 0 ) {
00517 r[0] = getSqlResultByInx (genQueryOut, COL_RULE_BASE_MAP_BASE_NAME);
00518 r[1] = getSqlResultByInx (genQueryOut, COL_RULE_NAME);
00519 r[2] = getSqlResultByInx (genQueryOut, COL_RULE_EVENT);
00520 r[3] = getSqlResultByInx (genQueryOut, COL_RULE_CONDITION);
00521 r[4] = getSqlResultByInx (genQueryOut, COL_RULE_BODY);
00522 r[5] = getSqlResultByInx (genQueryOut, COL_RULE_RECOVERY);
00523 r[6] = getSqlResultByInx (genQueryOut, COL_RULE_ID);
00524 for (i = 0; i<genQueryOut->rowCnt; i++) {
00525 inRuleStrct->ruleBase[l] = strdup(&r[0]->value[r[0]->len * i]);
00526 inRuleStrct->action[l] = strdup(&r[1]->value[r[1]->len * i]);
00527 inRuleStrct->ruleHead[l] = strdup(&r[2]->value[r[2]->len * i]);
00528 inRuleStrct->ruleCondition[l] = strdup(&r[3]->value[r[3]->len * i]);
00529 inRuleStrct->ruleAction[l] = strdup(&r[4]->value[r[4]->len * i]);
00530 inRuleStrct->ruleRecovery[l] = strdup(&r[5]->value[r[5]->len * i]);
00531 inRuleStrct->ruleId[l] = atol(&r[6]->value[r[6]->len * i]);
00532 l++;
00533 }
00534 genQueryInp.continueInx = genQueryOut->continueInx;
00535 freeGenQueryOut (&genQueryOut);
00536 if (genQueryInp.continueInx > 0) {
00537
00538 status = rsGenQuery (rei->rsComm, &genQueryInp, &genQueryOut);
00539 }
00540 else
00541 break;
00542 }
00543 inRuleStrct->MaxNumOfRules = l;
00544 return(0);
00545 }
00546
00547
00548 int
00549 readDVMapStructFromDB(char *dvmBaseName, char *versionStr, rulevardef_t *inDvmStrct, ruleExecInfo_t *rei)
00550 {
00551 int i,l,status;
00552 genQueryInp_t genQueryInp;
00553 genQueryOut_t *genQueryOut = NULL;
00554 char condstr[MAX_NAME_LEN], condstr2[MAX_NAME_LEN];
00555 sqlResult_t *r[5];
00556 memset(&genQueryInp, 0, sizeof(genQueryInp));
00557 genQueryInp.maxRows = MAX_SQL_ROWS;
00558
00559 snprintf(condstr, MAX_NAME_LEN, "= '%s'", dvmBaseName);
00560 addInxVal(&genQueryInp.sqlCondInp, COL_DVM_BASE_MAP_BASE_NAME, condstr);
00561 snprintf(condstr2, MAX_NAME_LEN, "= '%s'", versionStr);
00562 addInxVal(&genQueryInp.sqlCondInp, COL_DVM_BASE_MAP_VERSION, condstr2);
00563
00564 addInxIval(&genQueryInp.selectInp, COL_DVM_EXT_VAR_NAME, 1);
00565 addInxIval(&genQueryInp.selectInp, COL_DVM_CONDITION, 1);
00566 addInxIval(&genQueryInp.selectInp, COL_DVM_INT_MAP_PATH, 1);
00567 addInxIval(&genQueryInp.selectInp, COL_DVM_ID, ORDER_BY);
00568 l = inDvmStrct->MaxNumOfDVars;
00569 status = rsGenQuery(rei->rsComm, &genQueryInp, &genQueryOut);
00570 while ( status >= 0 && genQueryOut->rowCnt > 0 ) {
00571 r[0] = getSqlResultByInx (genQueryOut, COL_DVM_EXT_VAR_NAME);
00572 r[1] = getSqlResultByInx (genQueryOut, COL_DVM_CONDITION);
00573 r[2] = getSqlResultByInx (genQueryOut, COL_DVM_INT_MAP_PATH);
00574 r[3] = getSqlResultByInx (genQueryOut, COL_DVM_ID);
00575 for (i = 0; i<genQueryOut->rowCnt; i++) {
00576 inDvmStrct->varName[l] = strdup(&r[0]->value[r[0]->len * i]);
00577 inDvmStrct->action[l] = strdup(&r[1]->value[r[1]->len * i]);
00578 inDvmStrct->var2CMap[l] = strdup(&r[2]->value[r[2]->len * i]);
00579 inDvmStrct->varId[l] = atol(&r[3]->value[r[3]->len * i]);
00580 l++;
00581 }
00582 genQueryInp.continueInx = genQueryOut->continueInx;
00583 freeGenQueryOut (&genQueryOut);
00584 if (genQueryInp.continueInx > 0) {
00585
00586 status = rsGenQuery (rei->rsComm, &genQueryInp, &genQueryOut);
00587 }
00588 else
00589 break;
00590 }
00591 inDvmStrct->MaxNumOfDVars = l;
00592 return(0);
00593 }
00594
00595
00596
00597 int
00598 readFNMapStructFromDB(char *fnmBaseName, char *versionStr, fnmapStruct_t *inFnmStrct, ruleExecInfo_t *rei)
00599 {
00600 int i,l,status;
00601 genQueryInp_t genQueryInp;
00602 genQueryOut_t *genQueryOut = NULL;
00603 char condstr[MAX_NAME_LEN], condstr2[MAX_NAME_LEN];
00604 sqlResult_t *r[5];
00605 memset(&genQueryInp, 0, sizeof(genQueryInp));
00606 genQueryInp.maxRows = MAX_SQL_ROWS;
00607
00608 snprintf(condstr, MAX_NAME_LEN, "= '%s'", fnmBaseName);
00609 addInxVal(&genQueryInp.sqlCondInp, COL_FNM_BASE_MAP_BASE_NAME, condstr);
00610 snprintf(condstr2, MAX_NAME_LEN, "= '%s'", versionStr);
00611 addInxVal(&genQueryInp.sqlCondInp, COL_FNM_BASE_MAP_VERSION, condstr2);
00612
00613 addInxIval(&genQueryInp.selectInp, COL_FNM_EXT_FUNC_NAME, 1);
00614 addInxIval(&genQueryInp.selectInp, COL_FNM_INT_FUNC_NAME, 1);
00615 addInxIval(&genQueryInp.selectInp, COL_FNM_ID, ORDER_BY);
00616
00617 l = inFnmStrct->MaxNumOfFMaps;
00618 status = rsGenQuery(rei->rsComm, &genQueryInp, &genQueryOut);
00619 while ( status >= 0 && genQueryOut->rowCnt > 0 ) {
00620 r[0] = getSqlResultByInx (genQueryOut, COL_FNM_EXT_FUNC_NAME);
00621 r[1] = getSqlResultByInx (genQueryOut, COL_FNM_INT_FUNC_NAME);
00622 r[2] = getSqlResultByInx (genQueryOut, COL_FNM_ID);
00623 for (i = 0; i<genQueryOut->rowCnt; i++) {
00624 inFnmStrct->funcName[l] = strdup(&r[0]->value[r[0]->len * i]);
00625 inFnmStrct->func2CMap[l] = strdup(&r[1]->value[r[1]->len * i]);
00626 inFnmStrct->fmapId[l] = atol(&r[2]->value[r[2]->len * i]);
00627 l++;
00628 }
00629 genQueryInp.continueInx = genQueryOut->continueInx;
00630 freeGenQueryOut (&genQueryOut);
00631 if (genQueryInp.continueInx > 0) {
00632
00633 status = rsGenQuery (rei->rsComm, &genQueryInp, &genQueryOut);
00634 }
00635 else
00636 break;
00637 }
00638 inFnmStrct->MaxNumOfFMaps = l;
00639 return(0);
00640 }
00641
00642
00643
00644 int
00645 readMsrvcStructFromDB(int inStatus, msrvcStruct_t *inMsrvcStrct, ruleExecInfo_t *rei)
00646 {
00647 int i,l,status;
00648 genQueryInp_t genQueryInp;
00649 genQueryOut_t *genQueryOut = NULL;
00650 sqlResult_t *r[10];
00651 memset(&genQueryInp, 0, sizeof(genQueryInp));
00652 genQueryInp.maxRows = MAX_SQL_ROWS;
00653 char condstr[MAX_NAME_LEN];
00654
00655 snprintf(condstr, MAX_NAME_LEN, "= '%i'", inStatus);
00656 addInxVal(&genQueryInp.sqlCondInp, COL_MSRVC_STATUS, condstr);
00657
00658 addInxIval(&genQueryInp.selectInp, COL_MSRVC_NAME, 1);
00659 addInxIval(&genQueryInp.selectInp, COL_MSRVC_MODULE_NAME, 1);
00660 addInxIval(&genQueryInp.selectInp, COL_MSRVC_SIGNATURE, 1);
00661 addInxIval(&genQueryInp.selectInp, COL_MSRVC_VERSION, 1);
00662 addInxIval(&genQueryInp.selectInp, COL_MSRVC_HOST, 1);
00663 addInxIval(&genQueryInp.selectInp, COL_MSRVC_LOCATION, 1);
00664 addInxIval(&genQueryInp.selectInp, COL_MSRVC_LANGUAGE, 1);
00665 addInxIval(&genQueryInp.selectInp, COL_MSRVC_TYPE_NAME, 1);
00666 addInxIval(&genQueryInp.selectInp, COL_MSRVC_STATUS, 1);
00667 addInxIval(&genQueryInp.selectInp, COL_MSRVC_ID, ORDER_BY);
00668
00669 l = inMsrvcStrct->MaxNumOfMsrvcs;
00670 status = rsGenQuery(rei->rsComm, &genQueryInp, &genQueryOut);
00671 while ( status >= 0 && genQueryOut->rowCnt > 0 ) {
00672 r[0] = getSqlResultByInx (genQueryOut, COL_MSRVC_MODULE_NAME);
00673 r[1] = getSqlResultByInx (genQueryOut, COL_MSRVC_NAME);
00674 r[2] = getSqlResultByInx (genQueryOut, COL_MSRVC_SIGNATURE);
00675 r[3] = getSqlResultByInx (genQueryOut, COL_MSRVC_VERSION);
00676 r[4] = getSqlResultByInx (genQueryOut, COL_MSRVC_HOST);
00677 r[5] = getSqlResultByInx (genQueryOut, COL_MSRVC_LOCATION);
00678 r[6] = getSqlResultByInx (genQueryOut, COL_MSRVC_LANGUAGE);
00679 r[7] = getSqlResultByInx (genQueryOut, COL_MSRVC_TYPE_NAME);
00680 r[8] = getSqlResultByInx (genQueryOut, COL_MSRVC_STATUS);
00681 r[9] = getSqlResultByInx (genQueryOut, COL_MSRVC_ID);
00682 for (i = 0; i<genQueryOut->rowCnt; i++) {
00683 inMsrvcStrct->moduleName[l] = strdup(&r[0]->value[r[0]->len * i]);
00684 inMsrvcStrct->msrvcName[l] = strdup(&r[1]->value[r[1]->len * i]);
00685 inMsrvcStrct->msrvcSignature[l] = strdup(&r[2]->value[r[2]->len * i]);
00686 inMsrvcStrct->msrvcVersion[l] = strdup(&r[3]->value[r[3]->len * i]);
00687 inMsrvcStrct->msrvcHost[l] = strdup(&r[4]->value[r[4]->len * i]);
00688 inMsrvcStrct->msrvcLocation[l] = strdup(&r[5]->value[r[5]->len * i]);
00689 inMsrvcStrct->msrvcLanguage[l] = strdup(&r[6]->value[r[6]->len * i]);
00690 inMsrvcStrct->msrvcTypeName[l] = strdup(&r[7]->value[r[7]->len * i]);
00691 inMsrvcStrct->msrvcStatus[l] = atol(&r[8]->value[r[8]->len * i]);
00692 inMsrvcStrct->msrvcId[l] = atol(&r[9]->value[r[9]->len * i]);
00693 l++;
00694 }
00695 genQueryInp.continueInx = genQueryOut->continueInx;
00696 freeGenQueryOut (&genQueryOut);
00697 if (genQueryInp.continueInx > 0) {
00698
00699 status = rsGenQuery (rei->rsComm, &genQueryInp, &genQueryOut);
00700 }
00701 else
00702 break;
00703 }
00704 inMsrvcStrct->MaxNumOfMsrvcs = l;
00705 return(0);
00706 }
00707
00708 int
00709 readRuleStructFromFile(int processType, char *ruleBaseName, ruleStruct_t *inRuleStrct)
00710 {
00711
00712 return loadRuleFromCacheOrFile(processType, ruleBaseName, inRuleStrct);
00713 }
00714
00715 int
00716 clearRuleStruct(ruleStruct_t *inRuleStrct)
00717 {
00718 int i;
00719 for (i = 0 ; i < inRuleStrct->MaxNumOfRules ; i++) {
00720 if (inRuleStrct->ruleBase[i] != NULL)
00721 free(inRuleStrct->ruleBase[i]);
00722 if (inRuleStrct->ruleHead[i] != NULL)
00723 free(inRuleStrct->ruleHead[i]);
00724 if (inRuleStrct->ruleCondition[i] != NULL)
00725 free(inRuleStrct->ruleCondition[i]);
00726 if (inRuleStrct->ruleAction[i] != NULL)
00727 free(inRuleStrct->ruleAction[i]);
00728 if (inRuleStrct->ruleRecovery[i] != NULL)
00729 free(inRuleStrct->ruleRecovery[i]);
00730
00731 }
00732 inRuleStrct->MaxNumOfRules = 0;
00733 if(inRuleStrct == &coreRuleStrct) {
00734 clearResources(RESC_CORE_RULE_SET | RESC_CORE_FUNC_DESC_INDEX);
00735 } else if(inRuleStrct == &appRuleStrct) {
00736 clearResources(RESC_APP_RULE_SET | RESC_APP_FUNC_DESC_INDEX);
00737 }
00738
00739 return(0);
00740 }
00741
00742 int clearDVarStruct(rulevardef_t *inRuleVarDef)
00743 {
00744 int i;
00745 for (i = 0 ; i < inRuleVarDef->MaxNumOfDVars; i++) {
00746 if (inRuleVarDef->varName[i] != NULL)
00747 free(inRuleVarDef->varName[i]);
00748 if (inRuleVarDef->action[i] != NULL)
00749 free(inRuleVarDef->action[i]);
00750 if (inRuleVarDef->var2CMap[i] != NULL)
00751 free(inRuleVarDef->var2CMap[i]);
00752 }
00753 inRuleVarDef->MaxNumOfDVars = 0;
00754 return(0);
00755 }
00756
00757 int clearFuncMapStruct( rulefmapdef_t* inRuleFuncMapDef)
00758 {
00759 int i;
00760 for (i = 0 ; i < inRuleFuncMapDef->MaxNumOfFMaps; i++) {
00761 if (inRuleFuncMapDef->funcName[i] != NULL)
00762 free(inRuleFuncMapDef->funcName[i]);
00763 if (inRuleFuncMapDef->func2CMap[i] != NULL)
00764 free(inRuleFuncMapDef->func2CMap[i]);
00765 }
00766 inRuleFuncMapDef->MaxNumOfFMaps = 0;
00767 if(inRuleFuncMapDef == &coreRuleFuncMapDef) {
00768 clearIndex(&coreRuleFuncMapDefIndex);
00769 } else if(inRuleFuncMapDef == &appRuleFuncMapDef) {
00770 clearIndex(&appRuleFuncMapDefIndex);
00771 }
00772
00773 return(0);
00774 }
00775
00776
00777 int
00778 readDVarStructFromFile(char *dvarBaseName,rulevardef_t *inRuleVarDef)
00779 {
00780 int i = 0;
00781 char l0[MAX_DVAR_LENGTH];
00782 char l1[MAX_DVAR_LENGTH];
00783 char l2[MAX_DVAR_LENGTH];
00784 char l3[MAX_DVAR_LENGTH];
00785 char dvarsFileName[MAX_NAME_LEN];
00786 FILE *file;
00787 char buf[MAX_DVAR_LENGTH];
00788 char *configDir;
00789
00790 i = inRuleVarDef->MaxNumOfDVars;
00791
00792 if (dvarBaseName[0] == '/' || dvarBaseName[0] == '\\' ||
00793 dvarBaseName[1] == ':') {
00794 snprintf (dvarsFileName,MAX_NAME_LEN, "%s",dvarBaseName);
00795 }
00796 else {
00797 configDir = getConfigDir ();
00798 snprintf (dvarsFileName,MAX_NAME_LEN, "%s/reConfigs/%s.dvm", configDir,dvarBaseName);
00799 }
00800
00801 file = fopen(dvarsFileName, "r");
00802 if (file == NULL) {
00803 rodsLog(LOG_NOTICE,
00804 "readDvarStructFromFile() could not open dvm file %s\n",
00805 dvarsFileName);
00806 return(DVARMAP_FILE_READ_ERROR);
00807 }
00808 buf[MAX_DVAR_LENGTH-1]='\0';
00809 while (fgets (buf, MAX_DVAR_LENGTH-1, file) != NULL) {
00810 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
00811 if (buf[0] == '#' || strlen(buf) < 4)
00812 continue;
00813 rSplitStr(buf, l1, MAX_DVAR_LENGTH, l0, MAX_DVAR_LENGTH, '|');
00814 inRuleVarDef->varName[i] = strdup(l1);
00815
00816 rSplitStr(l0, l1, MAX_DVAR_LENGTH, l3, MAX_DVAR_LENGTH,'|');
00817 inRuleVarDef->action[i] = strdup(l1);
00818 rSplitStr(l3, l1, MAX_DVAR_LENGTH, l2, MAX_DVAR_LENGTH,'|');
00819 inRuleVarDef->var2CMap[i] = strdup(l1);
00820
00821 if (strlen(l2) > 0)
00822 inRuleVarDef->varId[i] = atoll(l2);
00823 else
00824 inRuleVarDef->varId[i] = i;
00825 i++;
00826 }
00827 fclose (file);
00828 inRuleVarDef->MaxNumOfDVars = (long int) i;
00829 return(0);
00830 }
00831
00832 int
00833 readFuncMapStructFromFile(char *fmapBaseName, rulefmapdef_t* inRuleFuncMapDef)
00834 {
00835 int i = 0;
00836 char l0[MAX_FMAP_LENGTH];
00837 char l1[MAX_FMAP_LENGTH];
00838 char l2[MAX_FMAP_LENGTH];
00839
00840 char fmapsFileName[MAX_NAME_LEN];
00841 FILE *file;
00842 char buf[MAX_FMAP_LENGTH];
00843 char *configDir;
00844
00845 i = inRuleFuncMapDef->MaxNumOfFMaps;
00846
00847 if (fmapBaseName[0] == '/' || fmapBaseName[0] == '\\' ||
00848 fmapBaseName[1] == ':') {
00849 snprintf (fmapsFileName,MAX_NAME_LEN, "%s",fmapBaseName);
00850 }
00851 else {
00852 configDir = getConfigDir ();
00853 snprintf (fmapsFileName,MAX_NAME_LEN, "%s/reConfigs/%s.fnm", configDir,fmapBaseName);
00854 }
00855 file = fopen(fmapsFileName, "r");
00856 if (file == NULL) {
00857 rodsLog(LOG_NOTICE,
00858 "readFmapStructFromFile() could not open fnm file %s\n",
00859 fmapsFileName);
00860 return(FMAP_FILE_READ_ERROR);
00861 }
00862 buf[MAX_FMAP_LENGTH-1]='\0';
00863 while (fgets (buf, MAX_FMAP_LENGTH-1, file) != NULL) {
00864 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
00865 if (buf[0] == '#' || strlen(buf) < 4)
00866 continue;
00867 rSplitStr(buf, l1, MAX_FMAP_LENGTH, l0, MAX_FMAP_LENGTH, '|');
00868 inRuleFuncMapDef->funcName[i] = strdup(l1);
00869 rSplitStr(l0,l1, MAX_FMAP_LENGTH, l2, MAX_FMAP_LENGTH,'|');
00870 inRuleFuncMapDef->func2CMap[i] = strdup(l1);
00871 if (strlen(l2) > 0)
00872 inRuleFuncMapDef->fmapId[i] = atoll(l2);
00873 else
00874 inRuleFuncMapDef->fmapId[i] = i;
00875 i++;
00876 }
00877 fclose (file);
00878 inRuleFuncMapDef->MaxNumOfFMaps = (long int) i;
00879 if(inRuleFuncMapDef == &coreRuleFuncMapDef) {
00880 createFuncMapDefIndex(&coreRuleFuncMapDef, &coreRuleFuncMapDefIndex);
00881 } else if(inRuleFuncMapDef == &appRuleFuncMapDef) {
00882 createFuncMapDefIndex(&appRuleFuncMapDef, &appRuleFuncMapDefIndex);
00883 }
00884 return(0);
00885 }
00886
00887 int
00888 readMsrvcStructFromFile(char *msrvcFileName, msrvcStruct_t* inMsrvcStruct)
00889 {
00890 int i = 0;
00891 char l0[MAX_RULE_LENGTH];
00892 char l1[MAX_RULE_LENGTH];
00893 char l2[MAX_RULE_LENGTH];
00894 char mymsrvcFileName[MAX_NAME_LEN];
00895 FILE *file;
00896 char buf[MAX_RULE_LENGTH];
00897 char *configDir;
00898
00899
00900 i = inMsrvcStruct->MaxNumOfMsrvcs;
00901
00902 if (msrvcFileName[0] == '/' || msrvcFileName[0] == '\\' ||
00903 msrvcFileName[1] == ':') {
00904 snprintf (mymsrvcFileName,MAX_NAME_LEN, "%s",msrvcFileName);
00905 }
00906 else {
00907 configDir = getConfigDir ();
00908 snprintf (mymsrvcFileName,MAX_NAME_LEN, "%s/reConfigs/%s.msi", configDir,msrvcFileName);
00909 }
00910 file = fopen(mymsrvcFileName, "r");
00911 if (file == NULL) {
00912 rodsLog(LOG_NOTICE,
00913 "readMservcStructFromFile() could not open msrvc file %s\n",
00914 mymsrvcFileName);
00915 return(MSRVC_FILE_READ_ERROR);
00916 }
00917 buf[MAX_RULE_LENGTH-1]='\0';
00918 while (fgets (buf, MAX_RULE_LENGTH-1, file) != NULL) {
00919 if (buf[strlen(buf)-1] == '\n') buf[strlen(buf)-1] = '\0';
00920 if (buf[0] == '#' || strlen(buf) < 4)
00921 continue;
00922 rSplitStr(buf, l1, MAX_RULE_LENGTH, l0, MAX_RULE_LENGTH, '|');
00923 inMsrvcStruct->moduleName[i] = strdup(l1);
00924
00925 rSplitStr(l0, l1, MAX_RULE_LENGTH, l2, MAX_RULE_LENGTH,'|');
00926 inMsrvcStruct->msrvcName[i] = strdup(l1);
00927 rSplitStr(l2, l1, MAX_RULE_LENGTH, l0, MAX_RULE_LENGTH, '|');
00928 inMsrvcStruct->msrvcSignature[i] = strdup(l1);
00929
00930 rSplitStr(l0, l1, MAX_RULE_LENGTH, l2, MAX_RULE_LENGTH,'|');
00931 inMsrvcStruct->msrvcVersion[i] = strdup(l1);
00932 rSplitStr(l2, l1, MAX_RULE_LENGTH, l0, MAX_RULE_LENGTH, '|');
00933 inMsrvcStruct->msrvcHost[i] = strdup(l1);
00934
00935 rSplitStr(l0, l1, MAX_RULE_LENGTH, l2, MAX_RULE_LENGTH,'|');
00936 inMsrvcStruct->msrvcLocation[i] = strdup(l1);
00937 rSplitStr(l2, l1, MAX_RULE_LENGTH, l0, MAX_RULE_LENGTH, '|');
00938 inMsrvcStruct->msrvcLanguage[i] = strdup(l1);
00939
00940 rSplitStr(l0, l1, MAX_RULE_LENGTH, l2, MAX_RULE_LENGTH,'|');
00941 inMsrvcStruct->msrvcTypeName[i] = strdup(l1);
00942 rSplitStr(l2, l1, MAX_RULE_LENGTH, l0, MAX_RULE_LENGTH, '|');
00943 inMsrvcStruct->msrvcStatus[i] = atol(l1);
00944 if (strlen(l0) > 0)
00945 inMsrvcStruct->msrvcId[i] = atol(l1);
00946 else
00947 inMsrvcStruct->msrvcId[i] = (long int) i;
00948 i++;
00949 }
00950 fclose (file);
00951 inMsrvcStruct->MaxNumOfMsrvcs = i;
00952 return(0);
00953 }
00954
00955 int
00956 findNextRule (char *action, int *ruleInx)
00957 {
00958 int i;
00959 i = *ruleInx;
00960 i++;
00961
00962 if (i < 0)
00963 i = 0;
00964 if (i < APP_RULE_INDEX_OFF) {
00965 for( ; i < appRuleStrct.MaxNumOfRules; i++) {
00966 if (!strcmp( appRuleStrct.action[i],action)) {
00967 *ruleInx = i;
00968 return(0);
00969 }
00970 }
00971 i = APP_RULE_INDEX_OFF;
00972 }
00973 i = i - APP_RULE_INDEX_OFF;
00974 if (i < CORE_RULE_INDEX_OFF) {
00975 for( ; i < appRuleStrct.MaxNumOfRules; i++) {
00976 if (!strcmp( appRuleStrct.action[i],action)) {
00977 *ruleInx = i;
00978 return(0);
00979 }
00980 }
00981 i = CORE_RULE_INDEX_OFF;
00982 }
00983 i = i - CORE_RULE_INDEX_OFF;
00984 for( ; i < coreRuleStrct.MaxNumOfRules; i++) {
00985 if (!strcmp( coreRuleStrct.action[i],action)) {
00986 *ruleInx = i + APP_RULE_INDEX_OFF;
00987 return(0);
00988 }
00989 }
00990 return(NO_MORE_RULES_ERR);
00991 }
00992
00993
00994
00995 int
00996 getRule(int ri, char *ruleBase, char *ruleHead, char *ruleCondition,
00997 char *ruleAction, char *ruleRecovery, int rSize)
00998 {
00999
01000 if (ri < CORE_RULE_INDEX_OFF) {
01001 rstrcpy( ruleBase , appRuleStrct.ruleBase[ri], rSize);
01002 rstrcpy( ruleHead , appRuleStrct.ruleHead[ri], rSize);
01003 rstrcpy( ruleCondition , appRuleStrct.ruleCondition[ri], rSize);
01004 rstrcpy( ruleAction , appRuleStrct.ruleAction[ri], rSize);
01005 rstrcpy( ruleRecovery , appRuleStrct.ruleRecovery[ri], rSize);
01006 }
01007 else {
01008 ri = ri - CORE_RULE_INDEX_OFF;
01009 rstrcpy( ruleBase , coreRuleStrct.ruleBase[ri], rSize);
01010 rstrcpy( ruleHead , coreRuleStrct.ruleHead[ri], rSize);
01011 rstrcpy( ruleCondition , coreRuleStrct.ruleCondition[ri], rSize);
01012 rstrcpy( ruleAction , coreRuleStrct.ruleAction[ri], rSize);
01013 rstrcpy( ruleRecovery , coreRuleStrct.ruleRecovery[ri], rSize);
01014 }
01015 return(0);
01016 }
01017
01018 int
01019 insertRulesIntoDBNew(char * baseName, RuleSet *ruleSet,
01020 ruleExecInfo_t *rei)
01021 {
01022 generalRowInsertInp_t generalRowInsertInp;
01023 char ruleIdStr[MAX_NAME_LEN];
01024 int rc1, i;
01025 int mapPriorityInt = 1;
01026 char mapPriorityStr[50];
01027 endTransactionInp_t endTransactionInp;
01028 char myTime[50];
01029
01030 memset (&endTransactionInp, 0, sizeof (endTransactionInp_t));
01031 getNowStr(myTime);
01032
01033
01034 generalRowInsertInp.tableName = "versionRuleBase";
01035 generalRowInsertInp.arg1 = baseName;
01036 generalRowInsertInp.arg2 = myTime;
01037
01038 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01039 if (rc1 < 0) {
01040 endTransactionInp.arg0 = "rollback";
01041 rsEndTransaction(rei->rsComm, &endTransactionInp);
01042 return(rc1);
01043 }
01044
01045 for (i = 0; i < ruleSet->len; i++) {
01046 RuleDesc *rd = ruleSet->rules[i];
01047 char *ruleType;
01048 Node *ruleNode = rd->node;
01049 char ruleNameStr[MAX_RULE_LEN];
01050 char ruleCondStr[MAX_RULE_LEN];
01051 char ruleActionRecoveryStr[MAX_RULE_LEN];
01052 Node *avu;
01053 int s;
01054 char *p;
01055 switch(rd->ruleType) {
01056 case RK_FUNC:
01057 ruleType = "@FUNC";
01058 p = ruleNameStr;
01059 s = MAX_RULE_LEN;
01060 ruleNameToString(&p, &s, 0, ruleNode->subtrees[0]);
01061 p = ruleCondStr;
01062 s = MAX_RULE_LEN;
01063 termToString(&p, &s, 0, MIN_PREC, ruleNode->subtrees[1], 0 );
01064 p = ruleActionRecoveryStr;
01065 s = MAX_RULE_LEN;
01066 termToString(&p, &s, 0, MIN_PREC, ruleNode->subtrees[2], 0 );
01067 avu = lookupAVUFromMetadata(ruleNode->subtrees[4], "id");
01068 if(avu!=NULL) {
01069 rstrcpy(ruleIdStr, avu->subtrees[1]->text, MAX_NAME_LEN);
01070 } else {
01071 rstrcpy(ruleIdStr, "", MAX_NAME_LEN);
01072 }
01073 break;
01074 case RK_REL:
01075 ruleType = "@REL";
01076 p = ruleNameStr;
01077 s = MAX_RULE_LEN;
01078 ruleNameToString(&p, &s, 0, ruleNode->subtrees[0]);
01079 p = ruleCondStr;
01080 s = MAX_RULE_LEN;
01081 termToString(&p, &s, 0, MIN_PREC, ruleNode->subtrees[1], 0 );
01082 p = ruleActionRecoveryStr;
01083 s = MAX_RULE_LEN;
01084 actionsToString(&p, &s, 0, ruleNode->subtrees[2], ruleNode->subtrees[3]);
01085 avu = lookupAVUFromMetadata(ruleNode->subtrees[4], "id");
01086 if(avu!=NULL) {
01087 rstrcpy(ruleIdStr, avu->subtrees[1]->text, MAX_NAME_LEN);
01088 } else {
01089 rstrcpy(ruleIdStr, "", MAX_NAME_LEN);
01090 }
01091 break;
01092 case RK_DATA:
01093 ruleType = "@DATA";
01094 p = ruleNameStr;
01095 s = MAX_RULE_LEN;
01096 ruleNameToString(&p, &s, 0, ruleNode->subtrees[0]);
01097 rstrcpy(ruleCondStr, "", MAX_RULE_LEN);
01098 rstrcpy(ruleActionRecoveryStr, "", MAX_RULE_LEN);
01099 rstrcpy(ruleIdStr, "", MAX_NAME_LEN);
01100 break;
01101 case RK_CONSTRUCTOR:
01102 ruleType = "@CONSTR";
01103 rstrcpy(ruleNameStr, ruleNode->subtrees[0]->text, MAX_RULE_LEN);
01104 rstrcpy(ruleCondStr, "", MAX_RULE_LEN);
01105 p = ruleActionRecoveryStr;
01106 s = MAX_RULE_LEN;
01107 typeToStringParser(&p, &s, 0, 0, ruleNode->subtrees[1]);
01108 rstrcpy(ruleIdStr, "", MAX_NAME_LEN);
01109 break;
01110 case RK_EXTERN:
01111 ruleType = "@EXTERN";
01112 rstrcpy(ruleNameStr, ruleNode->subtrees[0]->text, MAX_RULE_LEN);
01113 rstrcpy(ruleCondStr, "", MAX_RULE_LEN);
01114 p = ruleActionRecoveryStr;
01115 s = MAX_RULE_LEN;
01116 typeToStringParser(&p, &s, 0, 0, ruleNode->subtrees[1]);
01117 rstrcpy(ruleIdStr, "", MAX_NAME_LEN);
01118 break;
01119 }
01120 generalRowInsertInp.tableName = "ruleTable";
01121 generalRowInsertInp.arg1 = baseName;
01122 sprintf(mapPriorityStr, "%i", mapPriorityInt);
01123 mapPriorityInt++;
01124 generalRowInsertInp.arg2 = mapPriorityStr;
01125 generalRowInsertInp.arg3 = ruleNode->subtrees[0]->text;
01126 generalRowInsertInp.arg4 = ruleNameStr;
01127 generalRowInsertInp.arg5 = ruleCondStr;
01128 generalRowInsertInp.arg6 = ruleActionRecoveryStr;
01129 generalRowInsertInp.arg7 = ruleType;
01130 generalRowInsertInp.arg8 = ruleIdStr;
01131 generalRowInsertInp.arg9 = myTime;
01132
01133 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01134 if (rc1 < 0) {
01135 endTransactionInp.arg0 = "rollback";
01136 rsEndTransaction(rei->rsComm, &endTransactionInp);
01137 return(rc1);
01138 }
01139 }
01140
01141 endTransactionInp.arg0 = "commit";
01142 rc1 = rsEndTransaction(rei->rsComm, &endTransactionInp);
01143 return(rc1);
01144 }
01145
01146 int
01147 insertRulesIntoDB(char * baseName, ruleStruct_t *coreRuleStruct,
01148 ruleExecInfo_t *rei)
01149 {
01150 generalRowInsertInp_t generalRowInsertInp;
01151 char ruleIdStr[MAX_NAME_LEN];
01152 int rc1, i;
01153 int mapPriorityInt = 1;
01154 char mapPriorityStr[50];
01155 endTransactionInp_t endTransactionInp;
01156 char myTime[50];
01157
01158 memset (&endTransactionInp, 0, sizeof (endTransactionInp_t));
01159 getNowStr(myTime);
01160
01161
01162 generalRowInsertInp.tableName = "versionRuleBase";
01163 generalRowInsertInp.arg1 = baseName;
01164 generalRowInsertInp.arg2 = myTime;
01165
01166 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01167 if (rc1 < 0) {
01168 endTransactionInp.arg0 = "rollback";
01169 rsEndTransaction(rei->rsComm, &endTransactionInp);
01170 return(rc1);
01171 }
01172
01173 for (i = 0; i < coreRuleStruct->MaxNumOfRules; i++) {
01174 generalRowInsertInp.tableName = "ruleTable";
01175 generalRowInsertInp.arg1 = baseName;
01176 sprintf(mapPriorityStr, "%i", mapPriorityInt);
01177 mapPriorityInt++;
01178 generalRowInsertInp.arg2 = mapPriorityStr;
01179 generalRowInsertInp.arg3 = coreRuleStruct->action[i];
01180 generalRowInsertInp.arg4 = coreRuleStruct->ruleHead[i];
01181 generalRowInsertInp.arg5 = coreRuleStruct->ruleCondition[i];
01182 generalRowInsertInp.arg6 = coreRuleStruct->ruleAction[i];
01183 generalRowInsertInp.arg7= coreRuleStruct->ruleRecovery[i];
01184 generalRowInsertInp.arg8 = ruleIdStr;
01185 generalRowInsertInp.arg9 = myTime;
01186
01187 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01188 if (rc1 < 0) {
01189 endTransactionInp.arg0 = "rollback";
01190 rsEndTransaction(rei->rsComm, &endTransactionInp);
01191 return(rc1);
01192 }
01193 }
01194
01195 endTransactionInp.arg0 = "commit";
01196 rc1 = rsEndTransaction(rei->rsComm, &endTransactionInp);
01197 return(rc1);
01198 }
01199
01200 int
01201 insertDVMapsIntoDB(char * baseName, dvmStruct_t *coreDVMStruct,
01202 ruleExecInfo_t *rei)
01203 {
01204 generalRowInsertInp_t generalRowInsertInp;
01205 int rc1, i;
01206 endTransactionInp_t endTransactionInp;
01207 char myTime[50];
01208
01209 memset (&endTransactionInp, 0, sizeof (endTransactionInp_t));
01210 getNowStr(myTime);
01211
01212
01213 generalRowInsertInp.tableName = "versionDVMBase";
01214 generalRowInsertInp.arg1 = baseName;
01215 generalRowInsertInp.arg2 = myTime;
01216
01217 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01218 if (rc1 < 0) {
01219 endTransactionInp.arg0 = "rollback";
01220 rsEndTransaction(rei->rsComm, &endTransactionInp);
01221 return(rc1);
01222 }
01223
01224 for (i = 0; i < coreDVMStruct->MaxNumOfDVars; i++) {
01225 generalRowInsertInp.tableName = "dvmTable";
01226 generalRowInsertInp.arg1 = baseName;
01227 generalRowInsertInp.arg2 = coreDVMStruct->varName[i];
01228 generalRowInsertInp.arg3 = coreDVMStruct->action[i];
01229 generalRowInsertInp.arg4 = coreDVMStruct->var2CMap[i];
01230 generalRowInsertInp.arg5 = myTime;
01231
01232 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01233 if (rc1 < 0) {
01234 endTransactionInp.arg0 = "rollback";
01235 rsEndTransaction(rei->rsComm, &endTransactionInp);
01236 return(rc1);
01237 }
01238 }
01239
01240 endTransactionInp.arg0 = "commit";
01241 rc1 = rsEndTransaction(rei->rsComm, &endTransactionInp);
01242 return(rc1);
01243 }
01244
01245 int
01246 insertFNMapsIntoDB(char * baseName, fnmapStruct_t *coreFNMStruct,
01247 ruleExecInfo_t *rei)
01248 {
01249 generalRowInsertInp_t generalRowInsertInp;
01250 int rc1, i;
01251 endTransactionInp_t endTransactionInp;
01252 char myTime[50];
01253
01254 memset (&endTransactionInp, 0, sizeof (endTransactionInp_t));
01255 getNowStr(myTime);
01256
01257
01258 generalRowInsertInp.tableName = "versionFNMBase";
01259 generalRowInsertInp.arg1 = baseName;
01260 generalRowInsertInp.arg2 = myTime;
01261
01262 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01263 if (rc1 < 0) {
01264 endTransactionInp.arg0 = "rollback";
01265 rsEndTransaction(rei->rsComm, &endTransactionInp);
01266 return(rc1);
01267 }
01268
01269 for (i = 0; i < coreFNMStruct->MaxNumOfFMaps; i++) {
01270 generalRowInsertInp.tableName = "fnmTable";
01271 generalRowInsertInp.arg1 = baseName;
01272 generalRowInsertInp.arg2 = coreFNMStruct->funcName[i];
01273 generalRowInsertInp.arg3 = coreFNMStruct->func2CMap[i];
01274 generalRowInsertInp.arg4 = myTime;
01275
01276 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01277 if (rc1 < 0) {
01278 endTransactionInp.arg0 = "rollback";
01279 rsEndTransaction(rei->rsComm, &endTransactionInp);
01280 return(rc1);
01281 }
01282 }
01283
01284 endTransactionInp.arg0 = "commit";
01285 rc1 = rsEndTransaction(rei->rsComm, &endTransactionInp);
01286 return(rc1);
01287 }
01288
01289
01290
01291 int
01292 insertMSrvcsIntoDB(msrvcStruct_t *coreMsrvcStruct,
01293 ruleExecInfo_t *rei)
01294 {
01295
01296 generalRowInsertInp_t generalRowInsertInp;
01297 int rc1, i;
01298 endTransactionInp_t endTransactionInp;
01299 char myTime[100];
01300 char myStatus[100];
01301 memset (&endTransactionInp, 0, sizeof (endTransactionInp_t));
01302 getNowStr(myTime);
01303
01304 for (i = 0; i < coreMsrvcStruct->MaxNumOfMsrvcs; i++) {
01305 generalRowInsertInp.tableName = "msrvcTable";
01306 generalRowInsertInp.arg1 = coreMsrvcStruct->moduleName[i];
01307 generalRowInsertInp.arg2 = coreMsrvcStruct->msrvcName[i];
01308 generalRowInsertInp.arg3 = coreMsrvcStruct->msrvcSignature[i];
01309 generalRowInsertInp.arg4 = coreMsrvcStruct->msrvcVersion[i];
01310 generalRowInsertInp.arg5 = coreMsrvcStruct->msrvcHost[i];
01311 generalRowInsertInp.arg6 = coreMsrvcStruct->msrvcLocation[i];
01312 generalRowInsertInp.arg7 = coreMsrvcStruct->msrvcLanguage[i];
01313 generalRowInsertInp.arg8 = coreMsrvcStruct->msrvcTypeName[i];
01314 snprintf(myStatus,100, "%ld", coreMsrvcStruct->msrvcStatus[i]);
01315 generalRowInsertInp.arg9 = myStatus;
01316 generalRowInsertInp.arg10 = myTime;
01317
01318
01319 rc1 = rsGeneralRowInsert(rei->rsComm, &generalRowInsertInp);
01320 if (rc1 < 0) {
01321 endTransactionInp.arg0 = "rollback";
01322 rsEndTransaction(rei->rsComm, &endTransactionInp);
01323 return(rc1);
01324 }
01325 }
01326
01327 endTransactionInp.arg0 = "commit";
01328 rc1 = rsEndTransaction(rei->rsComm, &endTransactionInp);
01329 return(rc1);
01330
01331 }
01332
01333
01334 int
01335 writeRulesIntoFile(char * inFileName, ruleStruct_t *myRuleStruct,
01336 ruleExecInfo_t *rei)
01337 {
01338
01339 int i;
01340 FILE *file;
01341 char fileName[MAX_NAME_LEN];
01342 char *configDir;
01343
01344 if (inFileName[0] == '/' || inFileName[0] == '\\' ||
01345 inFileName[1] == ':') {
01346 snprintf (fileName,MAX_NAME_LEN, "%s",inFileName);
01347 }
01348 else {
01349 configDir = getConfigDir ();
01350 snprintf (fileName,MAX_NAME_LEN, "%s/reConfigs/%s.irb", configDir,inFileName);
01351 }
01352
01353
01354 file = fopen(fileName, "w");
01355 if (file == NULL) {
01356 rodsLog(LOG_NOTICE,
01357 "writeRulesIntoFile() could not open rules file %s for writing\n",
01358 fileName);
01359 return(FILE_OPEN_ERR);
01360 }
01361 for( i = 0; i < myRuleStruct->MaxNumOfRules; i++) {
01362 fprintf(file, "%s|%s|%s|%s|%ld\n", myRuleStruct->ruleHead[i],
01363 myRuleStruct->ruleCondition[i],
01364 myRuleStruct->ruleAction[i],
01365 myRuleStruct->ruleRecovery[i],
01366 myRuleStruct->ruleId[i]);
01367
01368 }
01369 fclose (file);
01370 return(0);
01371 }
01372
01373 int
01374 writeDVMapsIntoFile(char * inFileName, dvmStruct_t *myDVMapStruct,
01375 ruleExecInfo_t *rei)
01376 {
01377 int i;
01378 FILE *file;
01379 char fileName[MAX_NAME_LEN];
01380 char *configDir;
01381
01382 if (inFileName[0] == '/' || inFileName[0] == '\\' ||
01383 inFileName[1] == ':') {
01384 snprintf (fileName,MAX_NAME_LEN, "%s",inFileName);
01385 }
01386 else {
01387 configDir = getConfigDir ();
01388 snprintf (fileName,MAX_NAME_LEN, "%s/reConfigs/%s.dvm", configDir,inFileName);
01389 }
01390
01391 file = fopen(fileName, "w");
01392 if (file == NULL) {
01393 rodsLog(LOG_NOTICE,
01394 "writeDVMapsIntoFile() could not open rules file %s for writing\n",
01395 fileName);
01396 return(FILE_OPEN_ERR);
01397 }
01398 for( i = 0; i < myDVMapStruct->MaxNumOfDVars; i++) {
01399 fprintf(file, "%s|%s|%s|%ld\n", myDVMapStruct->varName[i],
01400 myDVMapStruct->action[i],
01401 myDVMapStruct->var2CMap[i],
01402 myDVMapStruct->varId[i]);
01403 }
01404 fclose (file);
01405 return(0);
01406 }
01407
01408
01409 int
01410 writeFNMapsIntoFile(char * inFileName, fnmapStruct_t *myFNMapStruct,
01411 ruleExecInfo_t *rei)
01412 {
01413 int i;
01414 FILE *file;
01415 char fileName[MAX_NAME_LEN];
01416 char *configDir;
01417
01418 if (inFileName[0] == '/' || inFileName[0] == '\\' ||
01419 inFileName[1] == ':') {
01420 snprintf (fileName,MAX_NAME_LEN, "%s",inFileName);
01421 }
01422 else {
01423 configDir = getConfigDir ();
01424 snprintf (fileName,MAX_NAME_LEN, "%s/reConfigs/%s.fnm", configDir,inFileName);
01425 }
01426
01427 file = fopen(fileName, "w");
01428 if (file == NULL) {
01429 rodsLog(LOG_NOTICE,
01430 "writeFNMapsIntoFile() could not open rules file %s for writing\n",
01431 fileName);
01432 return(FILE_OPEN_ERR);
01433 }
01434 for( i = 0; i < myFNMapStruct->MaxNumOfFMaps; i++) {
01435 fprintf(file, "%s|%s|%ld\n", myFNMapStruct->funcName[i],
01436 myFNMapStruct->func2CMap[i],
01437 myFNMapStruct->fmapId[i]);
01438 }
01439 fclose (file);
01440 return(0);
01441 }
01442
01443
01444
01445 int
01446 writeMSrvcsIntoFile(char * inFileName, msrvcStruct_t *myMsrvcStruct,
01447 ruleExecInfo_t *rei)
01448 {
01449 int i;
01450 FILE *file;
01451 char fileName[MAX_NAME_LEN];
01452 char *configDir;
01453
01454 if (inFileName[0] == '/' || inFileName[0] == '\\' ||
01455 inFileName[1] == ':') {
01456 snprintf (fileName,MAX_NAME_LEN, "%s",inFileName);
01457 }
01458 else {
01459 configDir = getConfigDir ();
01460 snprintf (fileName,MAX_NAME_LEN, "%s/reConfigs/%s.msi", configDir,inFileName);
01461 }
01462
01463 file = fopen(fileName, "w");
01464 if (file == NULL) {
01465 rodsLog(LOG_NOTICE,
01466 "writeMsrvcsIntoFile() could not open microservics file %s for writing\n",
01467 fileName);
01468 return(FILE_OPEN_ERR);
01469 }
01470 for( i = 0; i < myMsrvcStruct->MaxNumOfMsrvcs; i++) {
01471 fprintf(file, "%s|%s|%s|%s|%s|%s|%s|%s|%ld|%ld\n",
01472 myMsrvcStruct->moduleName[i],
01473 myMsrvcStruct->msrvcName[i],
01474 myMsrvcStruct->msrvcSignature[i],
01475 myMsrvcStruct->msrvcVersion[i],
01476 myMsrvcStruct->msrvcHost[i],
01477 myMsrvcStruct->msrvcLocation[i],
01478 myMsrvcStruct->msrvcLanguage[i],
01479 myMsrvcStruct->msrvcTypeName[i],
01480 myMsrvcStruct->msrvcStatus[i],
01481 myMsrvcStruct->msrvcId[i]);
01482 }
01483 fclose (file);
01484 return(0);
01485 }
01486
01487 int
01488 finalzeRuleEngine(rsComm_t *rsComm)
01489 {
01490 if ( GlobalREDebugFlag > 5 ) {
01491 _writeXMsg(GlobalREDebugFlag, "idbug", "PROCESS END");
01492 }
01493 return(0);
01494 }
01495
01496
01497
01498
01499
01500
01501
01502
01503
01504
01505
01506
01507
01508
01509
01510
01511
01512
01513
01514
01515
01516
01517
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530
01531
01532