00001
00002
00003
00004 #include "reGlobalsExtern.h"
00005 #include "rcMisc.h"
00006 #include "objMetaOpr.h"
00007 #include "resource.h"
00008
00009 void *mallocAndZero(int s)
00010 {
00011 void *t;
00012 t = malloc(s);
00013 memset(t,0,s);
00014 return(t);
00015 }
00016
00017 int
00018 copyRuleExecInfo(ruleExecInfo_t *from, ruleExecInfo_t *to)
00019 {
00020
00021 (*to) = (*from);
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 if (from->doi != NULL) {
00036 to->doi = (dataObjInfo_t *) mallocAndZero(sizeof(dataObjInfo_t));
00037 copyDataObjInfo(from->doi, to->doi);
00038 }
00039 else
00040 to->doi = NULL;
00041
00042 if (from->rgi != NULL) {
00043 to->rgi = (rescGrpInfo_t*)mallocAndZero(sizeof(rescGrpInfo_t));
00044 copyRescGrpInfo(from->rgi, to->rgi);
00045 }
00046 else
00047 to->rgi = NULL;
00048
00049 if (from->uoic != NULL) {
00050 to->uoic = (userInfo_t*)mallocAndZero(sizeof(userInfo_t));
00051 copyUserInfo(from->uoic, to->uoic);
00052 }
00053 else
00054 to->uoic = NULL;
00055
00056 if (from->uoip != NULL) {
00057 to->uoip = (userInfo_t*)mallocAndZero(sizeof(userInfo_t));
00058 copyUserInfo(from->uoip, to->uoip);
00059 }
00060 else
00061 to->uoip = NULL;
00062
00063 if (from->coi != NULL) {
00064 to->coi = (collInfo_t*)mallocAndZero(sizeof(collInfo_t));
00065 copyCollInfo(from->coi, to->coi);
00066 }
00067 else
00068 to->coi = NULL;
00069
00070 #if 0
00071 if (from->rgio != NULL) {
00072 to->rgio = mallocAndZero(sizeof(rescGrpInfo_t));
00073 copyRescGrpInfo(from->rgio, to->rgio);
00074 }
00075 else
00076 to->rgi = NULL;
00077 #endif
00078
00079 if (from->uoio != NULL) {
00080 to->uoio= (userInfo_t*)mallocAndZero(sizeof(userInfo_t));
00081 copyUserInfo(from->uoio, to->uoio);
00082 }
00083 else
00084 to->uoio = NULL;
00085
00086 if (from->condInputData != NULL) {
00087 to->condInputData = (keyValPair_t*)mallocAndZero(sizeof(keyValPair_t));
00088 copyKeyValPairStruct(from->condInputData, to->condInputData);
00089 }
00090 else
00091 to->condInputData = NULL;
00092
00093 if (from->next != NULL) {
00094 to->next = (ruleExecInfo_t*)mallocAndZero(sizeof(ruleExecInfo_t));
00095 copyRuleExecInfo(from->next,to->next);
00096 }
00097 else
00098 to->next = NULL;
00099 return(0);
00100 }
00101
00102 int
00103 freeRuleExecInfoStruct(ruleExecInfo_t *rs, int freeSpeialStructFlag)
00104 {
00105 freeRuleExecInfoInternals(rs, freeSpeialStructFlag);
00106 free(rs);
00107 return(0);
00108 }
00109 int
00110 freeRuleExecInfoInternals(ruleExecInfo_t *rs, int freeSpeialStructFlag)
00111 {
00112 if (rs->msParamArray != NULL && (freeSpeialStructFlag & FREE_MS_PARAM) > 0) {
00113 clearMsParamArray (rs->msParamArray, 1);
00114 free (rs->msParamArray);
00115 }
00116
00117 if (rs->doinp != NULL && (freeSpeialStructFlag & FREE_DOINP) > 0) {
00118 clearDataObjInp (rs->doinp);
00119 free (rs->doinp);
00120 }
00121
00122 if (rs->doi != NULL)
00123 freeAllDataObjInfo(rs->doi);
00124 if (rs->rgi != NULL)
00125 freeRescGrpInfo(rs->rgi);
00126 if (rs->uoic != NULL)
00127 freeUserInfo(rs->uoic);
00128 if (rs->uoip != NULL)
00129 freeUserInfo(rs->uoip);
00130 if (rs->coi != NULL)
00131 freeCollInfo(rs->coi);
00132 #if 0
00133 if (rs->rgio != NULL)
00134 freeRescGrpInfo(rs->rgio);
00135 #endif
00136 if (rs->uoio != NULL)
00137 freeUserInfo(rs->uoio);
00138 if (rs->condInputData != NULL)
00139 freeKeyValPairStruct(rs->condInputData);
00140 if (rs->next != NULL)
00141 freeRuleExecInfoStruct(rs->next, freeSpeialStructFlag);
00142 return(0);
00143 }
00144
00145 int
00146 copyDataObjInfo(dataObjInfo_t *from, dataObjInfo_t *to)
00147 {
00148 *to = *from;
00149 if (from->next != NULL) {
00150 to->next = (dataObjInfo_t*)mallocAndZero(sizeof(dataObjInfo_t));
00151 copyDataObjInfo(from->next,to->next);
00152 }
00153 else
00154 to->next = NULL;
00155 return(0);
00156 }
00157
00158
00159 int
00160 copyCollInfo(collInfo_t *from, collInfo_t *to)
00161 {
00162 *to = *from;
00163 if (from->next != NULL) {
00164 to->next = (collInfo_t*)mallocAndZero(sizeof(collInfo_t));
00165 copyCollInfo(from->next,to->next);
00166 }
00167 else
00168 to->next = NULL;
00169 return(0);
00170 }
00171
00172
00173 int
00174 copyRescGrpInfo(rescGrpInfo_t *from, rescGrpInfo_t *to)
00175 {
00176 *to = *from;
00177 if (from->next != NULL) {
00178 to->next = (rescGrpInfo_t*)mallocAndZero(sizeof(rescGrpInfo_t));
00179 copyRescGrpInfo(from->next,to->next);
00180 }
00181 else
00182 to->next = NULL;
00183 return(0);
00184 }
00185
00186
00187
00188 int
00189 freeCollInfo(collInfo_t *rs)
00190 {
00191 if (rs->next != NULL)
00192 freeCollInfo(rs->next);
00193 free(rs);
00194 return(0);
00195 }
00196
00197 int
00198 freeRescGrpInfo( rescGrpInfo_t *rs)
00199 {
00200 if (rs->next != NULL)
00201 freeRescGrpInfo(rs->next);
00202 free(rs);
00203 return(0);
00204 }
00205
00206 int
00207 copyUserInfo(userInfo_t *from, userInfo_t *to)
00208 {
00209 *to = *from;
00210 to->authInfo = from->authInfo;
00211 to->userOtherInfo = from->userOtherInfo;
00212 return(0);
00213 }
00214
00215
00216 int
00217 freeUserInfo(userInfo_t *rs)
00218 {
00219 free(rs);
00220 return(0);
00221 }
00222
00223
00224
00225 int
00226 copyRescInfo(rescInfo_t *from, rescInfo_t *to)
00227 {
00228 *to = *from;
00229 return(0);
00230 }
00231
00232
00233 int
00234 freeRescInfo(rescInfo_t *rs)
00235 {
00236 free(rs);
00237 return(0);
00238 }
00239
00240
00241
00242 int
00243 copyKeyValPairStruct(keyValPair_t *from, keyValPair_t *to)
00244 {
00245 *to = *from;
00246 return(0);
00247 }
00248
00249 int
00250 freeKeyValPairStruct(keyValPair_t *rs)
00251 {
00252 free(rs);
00253 return(0);
00254 }
00255
00256
00257
00258 int
00259 zeroRuleExecInfoStruct(ruleExecInfo_t *rei)
00260 {
00261
00262 memset (rei, 0, sizeof (ruleExecInfo_t));
00263 return(0);
00264 }
00265
00266 int
00267 initReiWithDataObjInp (ruleExecInfo_t *rei, rsComm_t *rsComm,
00268 dataObjInp_t *dataObjInp)
00269 {
00270 memset (rei, 0, sizeof (ruleExecInfo_t));
00271 rei->doinp = dataObjInp;
00272 rei->rsComm = rsComm;
00273 if (rsComm != NULL) {
00274 rei->uoic = &rsComm->clientUser;
00275 rei->uoip = &rsComm->proxyUser;
00276 }
00277
00278 return (0);
00279 }
00280
00281 int
00282 initReiWithCollInp (ruleExecInfo_t *rei, rsComm_t *rsComm,
00283 collInp_t *collCreateInp, collInfo_t *collInfo)
00284 {
00285 int status;
00286
00287 memset (rei, 0, sizeof (ruleExecInfo_t));
00288 memset (collInfo, 0, sizeof (collInfo_t));
00289 rei->coi = collInfo;
00290
00291 if ((status = splitPathByKey (collCreateInp->collName,
00292 collInfo->collParentName, collInfo->collName, '/')) < 0) {
00293 rodsLog (LOG_ERROR,
00294 "initReiWithCollInp: splitPathByKey for %s error, status = %d",
00295 collCreateInp->collName, status);
00296 return status;
00297 } else {
00298 rstrcpy (collInfo->collName, collCreateInp->collName, MAX_NAME_LEN);
00299 }
00300 rei->rsComm = rsComm;
00301 if (rsComm != NULL) {
00302 rei->uoic = &rsComm->clientUser;
00303 rei->uoip = &rsComm->proxyUser;
00304 }
00305
00306 return (0);
00307 }
00308
00309 int
00310 packRei (rsComm_t *rsComm, ruleExecInfo_t *rei,
00311 bytesBuf_t **packedReiBBuf)
00312 {
00313 int status;
00314
00315 if (packedReiBBuf == NULL) {
00316 return (SYS_INTERNAL_NULL_INPUT_ERR);
00317 }
00318
00319
00320
00321 status = packStruct ((void *) rei, packedReiBBuf,
00322 "Rei_PI", RodsPackTable, 0, NATIVE_PROT);
00323
00324 if (status < 0) {
00325 rodsLog (LOG_ERROR,
00326 "packRei: packStruct error. status = %d", status);
00327 return (status);
00328 }
00329
00330 return (status);
00331 }
00332
00333 int
00334 unpackRei (rsComm_t *rsComm, ruleExecInfo_t **rei,
00335 bytesBuf_t *packedReiBBuf)
00336 {
00337 int status;
00338
00339 if (packedReiBBuf == NULL || rei == NULL) {
00340 return (SYS_INTERNAL_NULL_INPUT_ERR);
00341 }
00342
00343
00344
00345
00346 status = unpackStruct (packedReiBBuf->buf, (void **) rei,
00347 "Rei_PI", RodsPackTable, NATIVE_PROT);
00348
00349 if (status < 0) {
00350 rodsLog (LOG_ERROR,
00351 "unpackRei: unpackStruct error. status = %d", status);
00352 return (status);
00353 }
00354
00355
00356
00357 status = touchupPackedRei (rsComm, *rei);
00358
00359 return (status);
00360 }
00361
00362 int
00363 packReiAndArg (rsComm_t *rsComm, ruleExecInfo_t *rei, char *myArgv[],
00364 int myArgc, bytesBuf_t **packedReiAndArgBBuf)
00365 {
00366 int status;
00367 ruleExecInfoAndArg_t reiAndArg;
00368
00369 if (packedReiAndArgBBuf == NULL) {
00370 rodsLog (LOG_ERROR,
00371 "packReiAndArg: NULL packedReiAndArgBBuf input");
00372 return (SYS_INTERNAL_NULL_INPUT_ERR);
00373 }
00374
00375 if (myArgc > 0 && (myArgv == NULL || *myArgv == NULL)) {
00376 rodsLog (LOG_ERROR,
00377 "packReiAndArg: NULL myArgv input");
00378 return (SYS_INTERNAL_NULL_INPUT_ERR);
00379 }
00380
00381 memset (&reiAndArg, 0, sizeof (reiAndArg));
00382
00383 reiAndArg.rei = rei;
00384
00385 reiAndArg.reArg.myArgc = myArgc;
00386 reiAndArg.reArg.myArgv = myArgv;
00387
00388
00389
00390 status = packStruct ((void *) &reiAndArg, packedReiAndArgBBuf,
00391 "ReiAndArg_PI", RodsPackTable, 0, NATIVE_PROT);
00392
00393 if (status < 0) {
00394 rodsLog (LOG_ERROR,
00395 "packReiAndArg: packStruct error. status = %d", status);
00396 return (status);
00397 }
00398
00399 return (status);
00400 }
00401
00402 int
00403 unpackReiAndArg (rsComm_t *rsComm, ruleExecInfoAndArg_t **reiAndArg,
00404 bytesBuf_t *packedReiAndArgBBuf)
00405 {
00406 int status;
00407
00408
00409 if (packedReiAndArgBBuf == NULL || reiAndArg == NULL) {
00410 return (SYS_INTERNAL_NULL_INPUT_ERR);
00411 }
00412
00413
00414
00415 status = unpackStruct (packedReiAndArgBBuf->buf, (void **) reiAndArg,
00416 "ReiAndArg_PI", RodsPackTable, NATIVE_PROT);
00417
00418 if (status < 0) {
00419 rodsLog (LOG_ERROR,
00420 "unpackReiAndArg: unpackStruct error. status = %d", status);
00421 return (status);
00422 }
00423
00424
00425
00426 status = touchupPackedRei (rsComm, (*reiAndArg)->rei);
00427
00428 return (status);
00429 }
00430
00431 int
00432 touchupPackedRei (rsComm_t *rsComm, ruleExecInfo_t *myRei)
00433 {
00434 int savedStatus = 0;
00435 int status;
00436 rescInfo_t *rescInfo;
00437
00438 if (myRei == NULL || rsComm == NULL) {
00439 return (SYS_INTERNAL_NULL_INPUT_ERR);
00440 }
00441
00442 if (myRei->rsComm != NULL) {
00443 free (myRei->rsComm);
00444 }
00445
00446 myRei->rsComm = rsComm;
00447
00448 rsComm->clientUser = *(myRei->uoic);
00449
00450 if (myRei->doi != NULL) {
00451 if (myRei->doi->next != NULL) {
00452 free (myRei->doi->next);
00453 myRei->doi->next = NULL;
00454 }
00455 rescInfo = NULL;
00456
00457
00458 status = resolveResc ((char *) myRei->doi->rescInfo, &rescInfo);
00459 free (myRei->doi->rescInfo);
00460 if (status >= 0) {
00461 myRei->doi->rescInfo = rescInfo;
00462 } else {
00463 savedStatus = status;
00464 myRei->doi->rescInfo = NULL;
00465 }
00466 }
00467
00468 if (myRei->rgi != NULL) {
00469 rescGrpInfo_t *rescGrpInfo = myRei->rgi;
00470 while (rescGrpInfo != NULL) {
00471
00472 rescInfo = NULL;
00473
00474 status = resolveResc ((char *) rescGrpInfo->rescInfo,
00475 &rescInfo);
00476 free (rescGrpInfo->rescInfo);
00477 if (status >= 0) {
00478 rescGrpInfo->rescInfo = rescInfo;
00479 } else {
00480 savedStatus = status;
00481 rescGrpInfo->rescInfo = NULL;
00482 }
00483 rescGrpInfo = rescGrpInfo->next;
00484 }
00485
00486 if (myRei->next != NULL) {
00487 free (myRei->next);
00488 myRei->next = NULL;
00489 }
00490 }
00491 return (savedStatus);
00492 }
00493
00494
00495 int
00496 copyTaggedValue(char *str, char *tag, char *buf, int bufLen)
00497 {
00498
00499 char tVal[NAME_LEN];
00500 char *t,*s, *u;
00501
00502 snprintf(tVal, NAME_LEN, "<%s>", tag );
00503 if ((t = strstr(str,tVal)) == NULL) {
00504 if (strcmp(tag,"KVALPR"))
00505 return(UNMATCHED_KEY_OR_INDEX);
00506 else {
00507 while ((t = strstr(str,"<_____X>")) != NULL) {
00508 memcpy(t+1,tag,6);
00509 }
00510 }
00511 return(-1);
00512 }
00513 s = t + strlen(tVal);
00514 snprintf(tVal, NAME_LEN,"</%s>", tag);
00515 if ((u = strstr(str,tVal)) == NULL) {
00516 return(INPUT_ARG_NOT_WELL_FORMED_ERR);
00517 }
00518 *u = '\0';
00519 strncpy(buf,s,bufLen);
00520 *u = '<';
00521 if (!strcmp(tag,"KVALPR"))
00522 memcpy(t+1,"_____X",6);
00523 return(0);
00524
00525 }
00526 int
00527 fillSubmitConditions (char *action, char *inDelayCondition,
00528 bytesBuf_t *packedReiAndArgBBuf, ruleExecSubmitInp_t *ruleSubmitInfo,
00529 ruleExecInfo_t *rei )
00530 {
00531 int i;
00532 int j = 0;
00533 char kwp[NAME_LEN * 2];
00534 char *t, *s;
00535 char *delayCondition;
00536
00537 delayCondition = strdup(inDelayCondition);
00538 strncpy(ruleSubmitInfo->ruleName, action, META_STR_LEN);
00539
00540
00541
00542
00543 i= copyTaggedValue(delayCondition,"EA", ruleSubmitInfo->exeAddress,NAME_LEN);
00544 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) {
00545 free( delayCondition );
00546 return(i);
00547 }
00548 i= copyTaggedValue(delayCondition,"ET", ruleSubmitInfo->exeTime,NAME_LEN);
00549 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) {
00550 free( delayCondition );
00551 return(i);
00552 }
00553 else if (i == 0) {
00554 i = checkDateFormat(ruleSubmitInfo->exeTime);
00555 if (i != 0) {
00556 free( delayCondition );
00557 return(i);
00558 }
00559
00560 }
00561 i= copyTaggedValue(delayCondition,"EF", ruleSubmitInfo->exeFrequency,NAME_LEN);
00562 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) {
00563 free( delayCondition );
00564 return(i);
00565 }
00566 i= copyTaggedValue(delayCondition,"PRI",ruleSubmitInfo->priority,NAME_LEN);
00567 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) {
00568 free( delayCondition );
00569 return(i);
00570 }
00571 i= copyTaggedValue(delayCondition,"EET",ruleSubmitInfo->estimateExeTime,NAME_LEN);
00572 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) {
00573 free( delayCondition );
00574 return(i);
00575 }
00576 i= copyTaggedValue(delayCondition,"NA", ruleSubmitInfo->notificationAddr,NAME_LEN);
00577 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) {
00578 free( delayCondition );
00579 return(i);
00580 }
00581 i= copyTaggedValue(delayCondition,"PLUSET", kwp,NAME_LEN * 2);
00582 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) {
00583 free( delayCondition );
00584 return(i);
00585 }
00586 else if (i == 0) {
00587 i = checkDateFormat(kwp);
00588 if (i != 0)
00589 return(i);
00590 getOffsetTimeStr(ruleSubmitInfo->exeTime,kwp);
00591 }
00592 if (i != 0 && i != UNMATCHED_KEY_OR_INDEX) return(i);
00593 i= copyTaggedValue(delayCondition,"KVALPR",kwp,NAME_LEN * 2);
00594 while (i >= 0) {
00595 if ((t = strstr(kwp,"=")) == NULL) {
00596 free(delayCondition);
00597 return(INPUT_ARG_NOT_WELL_FORMED_ERR);
00598 }
00599 *t = '\0';
00600 s = t-1;
00601 while (*s == ' ') s--;
00602 *(s+1) = '\0';
00603 ruleSubmitInfo->condInput.keyWord[j] = strdup(kwp);
00604 t++;
00605 while (*t == ' ') t++;
00606 ruleSubmitInfo->condInput.value[j] = t;
00607 j++;
00608 i= copyTaggedValue(delayCondition,"KWVAL",kwp,NAME_LEN * 2);
00609 }
00610 ruleSubmitInfo->condInput.len = j;
00611 ruleSubmitInfo->packedReiAndArgBBuf = packedReiAndArgBBuf;
00612 if (ruleSubmitInfo->userName == NULL || strlen(ruleSubmitInfo->userName) == 0) {
00613 if (rei->uoic->userName != NULL)
00614 strncpy(ruleSubmitInfo->userName, rei->uoic->userName,NAME_LEN);
00615 else if (rei->rsComm->clientUser.userName != NULL)
00616 strncpy(rei->rsComm->clientUser.userName,rei->uoic->userName,NAME_LEN);
00617 }
00618 free(delayCondition);
00619 return(0);
00620 }
00621
00622
00623 int
00624 pushStack(strArray_t *strArray, char *value)
00625 {
00626
00627 return(addStrArray (strArray, value));
00628
00629 }
00630
00631 int
00632 popStack(strArray_t *strArray, char *value)
00633 {
00634
00635 if (strArray->len <= 0 || strArray->size == 0) {
00636 rodsLog (LOG_ERROR,
00637 "popStack: Stack is empty: invalid size %d, len %d",
00638 strArray->size, strArray->len);
00639 return(SYS_INTERNAL_NULL_INPUT_ERR);
00640 }
00641 rstrcpy (value, &strArray->value[(strArray->len - 1) * strArray->size], strArray->size);
00642 strArray->len--;
00643 return(0);
00644
00645 }
00646
00647 int
00648 clearMsparamInRei (ruleExecInfo_t *rei)
00649 {
00650 if (rei == NULL || rei->msParamArray == NULL) {
00651 return (0);
00652 }
00653
00654
00655 clearMsParamArray (rei->msParamArray, 0);
00656 free (rei->msParamArray);
00657
00658 rei->msParamArray = NULL;
00659
00660 return (0);
00661 }
00662