00001 #include "reGlobalsExtern.h"
00002 #include "execMyRule.h"
00003 #include "miscServerFunct.h"
00004
00005 int
00006 rsExecMyRule (rsComm_t *rsComm, execMyRuleInp_t *execMyRuleInp,
00007 msParamArray_t **outParamArray)
00008 {
00009 int status;
00010 ruleExecInfo_t rei;
00011 char *iFlag;
00012 int oldReTestFlag, oldReLoopBackFlag;
00013 rodsServerHost_t *rodsServerHost;
00014 int remoteFlag;
00015
00016 if (execMyRuleInp == NULL) {
00017 rodsLog(LOG_NOTICE,
00018 "rsExecMyRule error. NULL input");
00019 return (SYS_INTERNAL_NULL_INPUT_ERR);
00020 }
00021
00022 remoteFlag = resolveHost (&execMyRuleInp->addr, &rodsServerHost);
00023
00024 if (remoteFlag == REMOTE_HOST) {
00025 status = remoteExecMyRule (rsComm, execMyRuleInp,
00026 outParamArray, rodsServerHost);
00027 return status;
00028 }
00029
00030 initReiWithDataObjInp (&rei, rsComm, NULL);
00031 rei.condInputData = &execMyRuleInp->condInput;
00032
00033 if (execMyRuleInp->inpParamArray == NULL) {
00034 execMyRuleInp->inpParamArray =
00035 (msParamArray_t *) malloc (sizeof (msParamArray_t));
00036 memset (execMyRuleInp->inpParamArray, 0, sizeof (msParamArray_t));
00037 }
00038 rei.msParamArray = execMyRuleInp->inpParamArray;
00039
00040 if ((iFlag = getValByKey (rei.condInputData,"looptest")) != NULL &&
00041 !strcmp(iFlag,"true")) {
00042 oldReTestFlag = reTestFlag;
00043 oldReLoopBackFlag = reLoopBackFlag;
00044 reTestFlag = LOG_TEST_2;
00045 reLoopBackFlag = LOOP_BACK_1;
00046 }
00047
00048 rstrcpy (rei.ruleName, EXEC_MY_RULE_KW, NAME_LEN);
00049
00050 status = execMyRule( execMyRuleInp->myRule, execMyRuleInp->inpParamArray,
00051 execMyRuleInp->outParamDesc, &rei);
00052
00053 if (iFlag != NULL) {
00054 reTestFlag = oldReTestFlag;
00055 reLoopBackFlag = oldReLoopBackFlag;
00056 }
00057
00058 trimMsParamArray (rei.msParamArray, execMyRuleInp->outParamDesc);
00059
00060 *outParamArray = rei.msParamArray;
00061 rei.msParamArray = NULL;
00062
00063 if (status < 0) {
00064 rodsLog (LOG_ERROR,
00065 "rsExecMyRule : execMyRule error for %s, status = %d",
00066 execMyRuleInp->myRule, status);
00067 return (status);
00068 }
00069
00070 return (status);
00071 }
00072
00073 int
00074 remoteExecMyRule (rsComm_t *rsComm, execMyRuleInp_t *execMyRuleInp,
00075 msParamArray_t **outParamArray, rodsServerHost_t *rodsServerHost)
00076 {
00077 int status;
00078
00079 if (rodsServerHost == NULL) {
00080 rodsLog (LOG_ERROR,
00081 "remoteExecMyRule: Invalid rodsServerHost");
00082 return SYS_INVALID_SERVER_HOST;
00083 }
00084
00085 if ((status = svrToSvrConnect (rsComm, rodsServerHost)) < 0) {
00086 return status;
00087 }
00088
00089 status = rcExecMyRule (rodsServerHost->conn, execMyRuleInp, outParamArray);
00090
00091 return (status);
00092 }
00093