00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "msiHelper.h"
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043 int
00044 msiGetStdoutInExecCmdOut (msParam_t *inpExecCmdOut, msParam_t *outStr,
00045 ruleExecInfo_t *rei)
00046 {
00047 char *strPtr;
00048
00049 rei->status = getStdoutInExecCmdOut (inpExecCmdOut, &strPtr);
00050
00051 if (rei->status < 0) return rei->status;
00052
00053 fillStrInMsParam (outStr, strPtr);
00054
00055 return rei->status;
00056 }
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090 int
00091 msiGetStderrInExecCmdOut (msParam_t *inpExecCmdOut, msParam_t *outStr,
00092 ruleExecInfo_t *rei)
00093 {
00094 char *strPtr = NULL;
00095
00096 rei->status = getStderrInExecCmdOut (inpExecCmdOut, &strPtr);
00097
00098 if (rei->status < 0) {
00099 if (rei->status != SYS_INTERNAL_NULL_INPUT_ERR)
00100 return rei->status;
00101 else {
00102 strPtr = "";
00103 rei->status = 0;
00104 }
00105 }
00106
00107 if (strPtr == NULL)
00108 strPtr="";
00109 fillStrInMsParam (outStr, strPtr);
00110
00111 return rei->status;
00112 }
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151 int
00152 msiWriteRodsLog (msParam_t *inpParam1, msParam_t *outParam, ruleExecInfo_t *rei)
00153 {
00154 rsComm_t *rsComm;
00155
00156 RE_TEST_MACRO (" Calling msiWriteRodsLog")
00157
00158 if (rei == NULL || rei->rsComm == NULL) {
00159 rodsLog (LOG_ERROR,
00160 "msiWriteRodsLog: input rei or rsComm is NULL");
00161 return (SYS_INTERNAL_NULL_INPUT_ERR);
00162 }
00163
00164 rsComm = rei->rsComm;
00165
00166 if ( inpParam1 == NULL ) {
00167 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
00168 "msiWriteRodsLog: input Param1 is NULL");
00169 rei->status = USER__NULL_INPUT_ERR;
00170 return (rei->status);
00171 }
00172
00173 if (strcmp (inpParam1->type, STR_MS_T) == 0) {
00174 rodsLog(LOG_NOTICE,
00175 "msiWriteRodsLog message: %s", inpParam1->inOutStruct);
00176 } else {
00177 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
00178 "msiWriteRodsLog: Unsupported input Param1 types %s",
00179 inpParam1->type);
00180 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00181 return (rei->status);
00182 }
00183
00184 rei->status = 0;
00185
00186 fillIntInMsParam (outParam, rei->status);
00187
00188 return (rei->status);
00189 }
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219
00220
00221
00222
00223
00224
00225
00226 int
00227 msiAddKeyValToMspStr (msParam_t *keyStr, msParam_t *valStr,
00228 msParam_t *msKeyValStr, ruleExecInfo_t *rei)
00229 {
00230 RE_TEST_MACRO (" Calling msiAddKeyValToMspStr")
00231
00232 if (rei == NULL) {
00233 rodsLog (LOG_ERROR,
00234 "msiAddKeyValToMspStr: input rei is NULL");
00235
00236 return SYS_INTERNAL_NULL_INPUT_ERR;
00237 }
00238
00239 rei->status = addKeyValToMspStr (keyStr, valStr, msKeyValStr);
00240
00241
00242 return rei->status;
00243 }
00244
00245
00246
00247
00248
00249
00250
00251
00252
00253
00254
00255
00256
00257
00258
00259
00260
00261
00262
00263
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273
00274
00275
00276
00277
00278 int
00279 msiSplitPath (msParam_t *inpPath, msParam_t *outParentColl,
00280 msParam_t *outChildName, ruleExecInfo_t *rei)
00281 {
00282 char parent[MAX_NAME_LEN], child[MAX_NAME_LEN];
00283
00284 RE_TEST_MACRO (" Calling msiSplitPath")
00285
00286 if (rei == NULL) {
00287 rodsLog (LOG_ERROR,
00288 "msiSplitPath: input rei is NULL");
00289
00290 return SYS_INTERNAL_NULL_INPUT_ERR;
00291 }
00292
00293 if ( inpPath == NULL ) {
00294 rodsLog (LOG_ERROR,
00295 "msiSplitPath: input inpPath is NULL");
00296 rei->status = USER__NULL_INPUT_ERR;
00297 return (rei->status);
00298 }
00299
00300 if (strcmp (inpPath->type, STR_MS_T) == 0) {
00301 if ((rei->status = splitPathByKey ((char *) inpPath->inOutStruct,
00302 parent, child, '/')) < 0) {
00303 rodsLog (LOG_ERROR,
00304 "msiSplitPath: splitPathByKey for %s error, status = %d",
00305 (char *) inpPath->inOutStruct, rei->status);
00306 } else {
00307 fillStrInMsParam (outParentColl, parent);
00308 fillStrInMsParam (outChildName, child);
00309 }
00310 } else {
00311 rodsLog (LOG_ERROR,
00312 "msiSplitPath: Unsupported input inpPath types %s",
00313 inpPath->type);
00314 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00315 }
00316 return (rei->status);
00317 }
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344
00345
00346
00347
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357 int
00358 msiGetSessionVarValue (msParam_t *inpVar, msParam_t *outputMode, ruleExecInfo_t *rei)
00359 {
00360 char *inpVarStr, *outputModeStr;
00361 char errMsg[ERR_MSG_LEN];
00362 rsComm_t *rsComm;
00363
00364 RE_TEST_MACRO (" Calling msiGetSessionVarValue")
00365
00366 if (rei == NULL || rei->rsComm == NULL) {
00367 rodsLog (LOG_ERROR,
00368 "msiGetSessionVar: input rei or rei->rsComm is NULL");
00369
00370 return SYS_INTERNAL_NULL_INPUT_ERR;
00371 }
00372
00373 if (inpVar == NULL || outputMode == NULL) {
00374 rodsLog (LOG_ERROR,
00375 "msiGetSessionVarValue: input inpVar or outputMode is NULL");
00376 rei->status = USER__NULL_INPUT_ERR;
00377 return (rei->status);
00378 }
00379
00380 if (strcmp (inpVar->type, STR_MS_T) != 0 ||
00381 strcmp (outputMode->type, STR_MS_T) != 0) {
00382 rodsLog (LOG_ERROR,
00383 "msiGetSessionVarValue: Unsupported *inpVar or outputMode type");
00384 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00385 return (rei->status);
00386 }
00387 rsComm = rei->rsComm;
00388 inpVarStr = (char *) inpVar->inOutStruct;
00389 outputModeStr = (char *) outputMode->inOutStruct;
00390
00391 if (inpVarStr == NULL || outputModeStr == NULL) {
00392 rodsLog (LOG_ERROR,
00393 "msiGetSessionVarValue: input inpVar or outputMode is NULL");
00394 rei->status = USER__NULL_INPUT_ERR;
00395 return (rei->status);
00396 }
00397
00398 if (strcmp (inpVarStr, "all") == 0) {
00399 keyValPair_t varKeyVal;
00400 int i;
00401 bzero (&varKeyVal, sizeof (varKeyVal));
00402 rei->status = getAllSessionVarValue ("", rei, &varKeyVal);
00403 if (rei->status >= 0) {
00404 if (strcmp (outputModeStr, "server") == 0 ||
00405 strcmp (outputModeStr, "all") == 0) {
00406 for (i = 0; i < varKeyVal.len; i++) {
00407 printf ("msiGetSessionVar: %s=%s\n",
00408 varKeyVal.keyWord[i], varKeyVal.value[i]);
00409 }
00410 }
00411 if (strcmp (outputModeStr, "client") == 0 ||
00412 strcmp (outputModeStr, "all") == 0) {
00413 for (i = 0; i < varKeyVal.len; i++) {
00414 snprintf (errMsg, ERR_MSG_LEN,
00415 "msiGetSessionVarValue: %s=%s\n",
00416 varKeyVal.keyWord[i], varKeyVal.value[i]);
00417 addRErrorMsg (&rsComm->rError, 0, errMsg);
00418 }
00419 }
00420 clearKeyVal (&varKeyVal);
00421 }
00422 } else {
00423 char *outStr = NULL;
00424 rei->status = getSessionVarValue ("", inpVarStr, rei, &outStr);
00425 if (rei->status >= 0) {
00426 if (strcmp (outputModeStr, "server") == 0 ||
00427 strcmp (outputModeStr, "all") == 0) {
00428 if( NULL != outStr )
00429 printf ("msiGetSessionVarValue: %s=%s\n", inpVarStr, outStr);
00430 }
00431 if (strcmp (outputModeStr, "client") == 0 ||
00432 strcmp (outputModeStr, "all") == 0) {
00433 snprintf (errMsg, ERR_MSG_LEN,
00434 "msiGetSessionVarValue: %s=%s\n", inpVarStr, outStr);
00435 addRErrorMsg (&rsComm->rError, 0, errMsg);
00436 }
00437 }
00438 if (outStr != NULL) free (outStr);
00439 }
00440 return (rei->status);
00441 }
00442
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460
00461
00462
00463
00464
00465
00466
00467
00468
00469
00470
00471
00472
00473
00474
00475 int
00476 msiStrlen (msParam_t *stringIn, msParam_t *lengthOut, ruleExecInfo_t *rei)
00477 {
00478 char len[NAME_LEN];
00479
00480 RE_TEST_MACRO (" Calling msiStrlen")
00481
00482 if (rei == NULL) {
00483 rodsLog (LOG_ERROR,
00484 "msiStrlen: input rei is NULL");
00485
00486 return SYS_INTERNAL_NULL_INPUT_ERR;
00487 }
00488
00489 if (stringIn == NULL) {
00490 rodsLog (LOG_ERROR,
00491 "msiStrlen: input stringIn is NULL");
00492 rei->status = USER__NULL_INPUT_ERR;
00493 return (rei->status);
00494 }
00495
00496 if (strcmp (stringIn->type, STR_MS_T) == 0) {
00497 if ( stringIn->inOutStruct != NULL) {
00498 rei->status = strlen ((char *) stringIn->inOutStruct);
00499 } else {
00500 rei->status = 0;
00501 }
00502 } else {
00503 rodsLog (LOG_ERROR,
00504 "msiStrlen: Unsupported input stringIn types %s",
00505 stringIn->type);
00506 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00507 }
00508 snprintf (len, NAME_LEN, "%d", rei->status);
00509 fillStrInMsParam (lengthOut, len);
00510 return (rei->status);
00511 }
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545 int
00546 msiStrchop (msParam_t *stringIn, msParam_t *stringOut, ruleExecInfo_t *rei)
00547 {
00548 RE_TEST_MACRO (" Calling msiStrchop")
00549
00550 if (rei == NULL) {
00551 rodsLog (LOG_ERROR,
00552 "msiStrchop: input rei is NULL");
00553
00554 return SYS_INTERNAL_NULL_INPUT_ERR;
00555 }
00556
00557 if (stringIn == NULL) {
00558 rodsLog (LOG_ERROR,
00559 "msiStrchop: input stringIn is NULL");
00560 rei->status = USER__NULL_INPUT_ERR;
00561 return (rei->status);
00562 }
00563
00564 if (strcmp (stringIn->type, STR_MS_T) == 0) {
00565 if ( stringIn->inOutStruct != NULL) {
00566 fillStrInMsParam (stringOut, (char *) stringIn->inOutStruct);
00567 rei->status = strlen ((char *) stringIn->inOutStruct);
00568 if (rei->status > 0) {
00569 rei->status --;
00570 *((char *) stringOut->inOutStruct + rei->status) = '\0';
00571 }
00572 } else {
00573 fillStrInMsParam (stringOut, "");
00574 rei->status = 0;
00575 }
00576 } else {
00577 rodsLog (LOG_ERROR,
00578 "msiStrchop: Unsupported input stringIn types %s",
00579 stringIn->type);
00580 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00581 }
00582 return (rei->status);
00583 }
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617
00618
00619
00620
00621
00622
00623
00624 int
00625 msiSubstr (msParam_t *stringIn, msParam_t *offset, msParam_t *length,
00626 msParam_t *stringOut, ruleExecInfo_t *rei)
00627 {
00628 char *origStr, *strPtr;
00629 int intLength, intOffset;
00630 int origLen;
00631 char savedChar;
00632 char *savedPtr = NULL;
00633
00634 RE_TEST_MACRO (" Calling msiSubstr")
00635
00636 if (rei == NULL) {
00637 rodsLog (LOG_ERROR,
00638 "msiSubstr: input rei is NULL");
00639
00640 return SYS_INTERNAL_NULL_INPUT_ERR;
00641 }
00642
00643 if (stringIn == NULL || offset == NULL) {
00644 rodsLog (LOG_ERROR,
00645 "msiSubstr: input stringIn or offset is NULL");
00646 rei->status = USER__NULL_INPUT_ERR;
00647 return (rei->status);
00648 }
00649
00650 if (strcmp (stringIn->type, STR_MS_T) != 0) {
00651 rodsLog (LOG_ERROR,
00652 "msiSubstr: Unsupported input stringIn types %s",
00653 stringIn->type);
00654 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00655 return rei->status;
00656 } else {
00657 origStr = (char *) stringIn->inOutStruct;
00658 }
00659
00660 if (strcmp (offset->type, STR_MS_T) != 0) {
00661 rodsLog (LOG_ERROR,
00662 "msiSubstr: Unsupported input offset types %s",
00663 offset->type);
00664 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00665 return rei->status;
00666 } else {
00667 intOffset = atoi ((char *) offset->inOutStruct);
00668 }
00669
00670 if (length == NULL) {
00671
00672 intLength = -1;
00673 } else if (strcmp (length->type, STR_MS_T) != 0) {
00674 rodsLog (LOG_ERROR,
00675 "msiSubstr: Unsupported input length types %s",
00676 length->type);
00677 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00678 return rei->status;
00679 } else if (strcmp ((char *) length->inOutStruct, "null") == 0) {
00680 intLength = -1;
00681 } else {
00682 intLength = atoi ((char *) length->inOutStruct);
00683 }
00684
00685 if (intOffset >= 0) {
00686 strPtr = origStr + intOffset;
00687 } else {
00688
00689 origLen = strlen (origStr);
00690 strPtr = origStr + origLen + intOffset;
00691 }
00692
00693 if (intLength >= 0 && ((int) strlen (strPtr)) > intLength) {
00694
00695 savedPtr = strPtr + intLength;
00696 savedChar = *savedPtr;
00697 *savedPtr = '\0';
00698 }
00699
00700 fillStrInMsParam (stringOut, strPtr);
00701 if (savedPtr != NULL) {
00702
00703 *savedPtr = savedChar;
00704 }
00705
00706 rei->status = strlen ((char *) stringOut->inOutStruct);
00707 return rei->status;
00708 }
00709
00710
00711
00712
00713
00714
00715
00716
00717
00718
00719
00720
00721
00722
00723
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747 int
00748 msiExit (msParam_t *inpParam1, msParam_t *inpParam2, ruleExecInfo_t *rei)
00749 {
00750 char errMsg[ERR_MSG_LEN];
00751 int status;
00752 rsComm_t *rsComm;
00753
00754 RE_TEST_MACRO (" Calling msiExit")
00755
00756 if (rei == NULL || rei->rsComm == NULL) {
00757 rodsLog (LOG_ERROR,
00758 "msiExit: input rei or rsComm is NULL");
00759 return (SYS_INTERNAL_NULL_INPUT_ERR);
00760 }
00761
00762 rsComm = rei->rsComm;
00763
00764 if ( inpParam1 == NULL ) {
00765 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
00766 "msiExit: input Param1 is NULL");
00767 rei->status = USER__NULL_INPUT_ERR;
00768 return (rei->status);
00769 }
00770
00771 if ( inpParam2 == NULL ) {
00772 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
00773 "msiExit: input Param2 is NULL");
00774 rei->status = USER__NULL_INPUT_ERR;
00775 return (rei->status);
00776 }
00777
00778 if (strcmp (inpParam1->type, STR_MS_T) == 0 && strcmp (inpParam2->type, STR_MS_T) == 0) {
00779 snprintf (errMsg, ERR_MSG_LEN, "%s\n", (char *) inpParam2->inOutStruct);
00780 status = atoi( (char *) inpParam1->inOutStruct);
00781 addRErrorMsg (&rsComm->rError, status, errMsg);
00782 return (status);
00783 } else {
00784 rodsLogAndErrorMsg (LOG_ERROR, &rsComm->rError, rei->status,
00785 "msiExit: Unsupported input Param1 types %s",
00786 inpParam1->type);
00787 rei->status = UNKNOWN_PARAM_IN_RULE_ERR;
00788 return (rei->status);
00789 }
00790
00791
00792 }
00793