00001
00002
00003
00004
00005
00006
00007
00008 #include "reGlobalsExtern.h"
00009 #include "icatHighLevelRoutines.h"
00010 #include "apiHeaderAll.h"
00011 #include "rsApiHandler.h"
00012
00013 #ifdef ADDR_64BITS
00014 #define CAST_PTR_INT (long int)
00015 #else
00016 #define CAST_PTR_INT
00017 #endif
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
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058 int writeLine(msParam_t* where, msParam_t* inString, ruleExecInfo_t *rei)
00059 {
00060 int i;
00061 char tmp[3];
00062 char *ptr;
00063 char *writeId = (char *) where->inOutStruct;
00064
00065 if (writeId != NULL && strcmp (writeId, "serverLog") == 0 &&
00066 inString->inOutStruct != NULL) {
00067 rodsLog (LOG_NOTICE, "writeLine: inString = %s\n", inString->inOutStruct);
00068 return 0;
00069 }
00070
00071 i = writeString(where, inString,rei);
00072 if (i < 0)
00073 return(i);
00074 ptr = (char*)inString->inOutStruct;
00075 sprintf(tmp,"%s\n","");
00076 inString->inOutStruct = tmp;
00077 i = writeString(where, inString,rei);
00078 inString->inOutStruct = ptr;
00079 return(i);
00080
00081 }
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122 int writeString(msParam_t* where, msParam_t* inString, ruleExecInfo_t *rei)
00123 {
00124 int i;
00125 char *writeId;
00126 char *writeStr;
00127
00128 if (where->inOutStruct == NULL)
00129 writeId = where->label;
00130 else
00131 writeId = (char*)where->inOutStruct;
00132
00133 if (inString->inOutStruct == NULL) {
00134 writeStr = strdup((char *) inString->label);
00135 }
00136 else {
00137 writeStr = strdup((char *) inString->inOutStruct);
00138 }
00139 i = _writeString(writeId, writeStr, rei);
00140
00141 free(writeStr);
00142 return(i);
00143 }
00144
00145 int _writeString(char *writeId, char *writeStr, ruleExecInfo_t *rei)
00146 {
00147 msParamArray_t *inMsParamArray;
00148 msParam_t *mP;
00149 execCmdOut_t *myExecCmdOut;
00150
00151
00152
00153 dataObjInp_t dataObjInp;
00154 openedDataObjInp_t openedDataObjInp;
00155 bytesBuf_t tmpBBuf;
00156 fileLseekOut_t *dataObjLseekOut = NULL;
00157 int fd,i;
00158
00159
00160 if (writeId != NULL && strcmp (writeId, "serverLog") == 0) {
00161 rodsLog (LOG_NOTICE, "writeString: inString = %s", writeStr);
00162 return 0;
00163 }
00164
00165
00166
00167 if (writeId != NULL && writeId[0] == '/') {
00168
00169
00170 if (rei == NULL || rei->rsComm == NULL) {
00171 rodsLog (LOG_ERROR, "_writeString: input rei or rsComm is NULL");
00172 return (SYS_INTERNAL_NULL_INPUT_ERR);
00173 }
00174
00175 bzero (&dataObjInp, sizeof (dataObjInp));
00176 dataObjInp.openFlags = O_RDWR;
00177 snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s",writeId);
00178 fd = rsDataObjOpen (rei->rsComm, &dataObjInp);
00179 if (fd < 0) {
00180 rodsLog (LOG_ERROR, "_writeString: rsDataObjOpen failed. status = %d", fd);
00181 return(fd);
00182 }
00183
00184 bzero(&openedDataObjInp, sizeof(openedDataObjInp));
00185 openedDataObjInp.l1descInx = fd;
00186 openedDataObjInp.offset = 0;
00187 openedDataObjInp.whence = SEEK_END;
00188 i = rsDataObjLseek (rei->rsComm, &openedDataObjInp, &dataObjLseekOut);
00189 if (i < 0) {
00190 rodsLog (LOG_ERROR, "_writeString: rsDataObjLseek failed. status = %d", i);
00191 return(i);
00192 }
00193
00194 bzero(&openedDataObjInp, sizeof(openedDataObjInp));
00195 openedDataObjInp.l1descInx = fd;
00196 tmpBBuf.len = openedDataObjInp.len = strlen(writeStr) + 1;
00197 tmpBBuf.buf = writeStr;
00198 i = rsDataObjWrite (rei->rsComm, &openedDataObjInp, &tmpBBuf);
00199 if (i < 0) {
00200 rodsLog (LOG_ERROR, "_writeString: rsDataObjWrite failed. status = %d", i);
00201 return(i);
00202 }
00203
00204 bzero(&openedDataObjInp, sizeof(openedDataObjInp));
00205 openedDataObjInp.l1descInx = fd;
00206 i = rsDataObjClose (rei->rsComm, &openedDataObjInp);
00207 return(i);
00208 }
00209
00210
00211
00212 mP = NULL;
00213 inMsParamArray = rei->msParamArray;
00214 if (((mP = getMsParamByLabel (inMsParamArray, "ruleExecOut")) != NULL) &&
00215 (mP->inOutStruct != NULL)) {
00216 if (!strcmp(mP->type,STR_MS_T)) {
00217 myExecCmdOut = (execCmdOut_t*)malloc (sizeof (execCmdOut_t));
00218 memset (myExecCmdOut, 0, sizeof (execCmdOut_t));
00219 mP->inOutStruct = myExecCmdOut;
00220 mP->type = strdup(ExecCmdOut_MS_T);
00221 }
00222 else
00223 myExecCmdOut = (execCmdOut_t*)mP->inOutStruct;
00224 }
00225 else {
00226 myExecCmdOut = (execCmdOut_t*)malloc (sizeof (execCmdOut_t));
00227 memset (myExecCmdOut, 0, sizeof (execCmdOut_t));
00228 if (mP == NULL)
00229 addMsParam(inMsParamArray,"ruleExecOut", ExecCmdOut_MS_T,myExecCmdOut,NULL);
00230 else {
00231 mP->inOutStruct = myExecCmdOut;
00232 mP->type = strdup(ExecCmdOut_MS_T);
00233 }
00234 }
00235
00236
00237
00238
00239
00240
00241
00242 if (!strcmp(writeId,"stdout"))
00243 appendToByteBuf(&(myExecCmdOut->stdoutBuf),(char *) writeStr);
00244 else if (!strcmp(writeId,"stderr"))
00245 appendToByteBuf(&(myExecCmdOut->stderrBuf),(char *) writeStr);
00246
00247
00248
00249 return(0);
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
00279
00280
00281
00282
00283
00284
00285 int writePosInt(msParam_t* where, msParam_t* inInt, ruleExecInfo_t *rei)
00286 {
00287 char *writeId;
00288 char writeStr[LONG_NAME_LEN];
00289 int status;
00290
00291 if (where->inOutStruct != NULL) {
00292 writeId = (char*)where->inOutStruct;
00293 }
00294 else {
00295 writeId = where->label;
00296 }
00297
00298 if (inInt->inOutStruct != NULL) {
00299 sprintf(writeStr, "%d", parseMspForPosInt (inInt));
00300 }
00301 else {
00302 snprintf(writeStr, LONG_NAME_LEN, "%s", inInt->label);
00303 }
00304
00305 status = _writeString(writeId, writeStr, rei);
00306
00307 return (status);
00308 }
00309
00310
00311
00312
00313
00314
00315
00316
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 int writeBytesBuf(msParam_t* where, msParam_t* inBuf, ruleExecInfo_t *rei)
00344 {
00345 char *writeId;
00346 char *writeStr;
00347 int status;
00348
00349 if (where->inOutStruct != NULL) {
00350 writeId = (char*)where->inOutStruct;
00351 }
00352 else {
00353 writeId = where->label;
00354 }
00355
00356 if (inBuf->inpOutBuf != NULL) {
00357 writeStr = (char *) malloc(strlen((const char*)inBuf->inpOutBuf->buf) + MAX_COND_LEN);
00358 strcpy(writeStr , (const char*)inBuf->inpOutBuf->buf);
00359 }
00360 else {
00361 writeStr = (char *) malloc(strlen(inBuf->label) + MAX_COND_LEN);
00362 strcpy(writeStr , inBuf->label);
00363 }
00364
00365 status = _writeString(writeId, writeStr, rei);
00366
00367 if (writeStr != NULL) {
00368 free(writeStr);
00369 }
00370
00371 return (status);
00372 }
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386
00387
00388
00389
00390
00391
00392
00393
00394
00395
00396
00397
00398
00399
00400
00401
00402
00403
00404
00405
00406
00407 int writeKeyValPairs(msParam_t *where, msParam_t *inKVPair, msParam_t *separator, ruleExecInfo_t *rei)
00408 {
00409 keyValPair_t *KVPairs;
00410 char *writeId;
00411 char *writeStr;
00412 char *sepStr;
00413 int i;
00414 size_t size;
00415
00416
00417 RE_TEST_MACRO (" Calling writeKeyValPairs")
00418
00419
00420
00421 if (!rei ) {
00422 rodsLog (LOG_ERROR, "writeKeyValPairs: input rei is NULL.");
00423 return (SYS_INTERNAL_NULL_INPUT_ERR);
00424 }
00425
00426 if (!where) {
00427 rodsLog (LOG_ERROR, "writeKeyValPairs: No destination provided for writing.");
00428 return (USER__NULL_INPUT_ERR);
00429 }
00430
00431
00432 if (!inKVPair || !inKVPair->inOutStruct)
00433 {
00434 return 0;
00435 }
00436
00437
00438 if (inKVPair->type && strcmp(inKVPair->type, KeyValPair_MS_T)) {
00439 rodsLog (LOG_ERROR, "writeKeyValPairs: input parameter is not of KeyValPair_MS_T type.");
00440 return(USER_PARAM_TYPE_ERR);
00441 }
00442 KVPairs = (keyValPair_t *)inKVPair->inOutStruct;
00443
00444
00445
00446 if (where->inOutStruct != NULL) {
00447 writeId = (char*)where->inOutStruct;
00448 }
00449 else {
00450 writeId = where->label;
00451 }
00452
00453
00454
00455 if ((sepStr = parseMspForStr(separator)) == NULL) {
00456 sepStr = "\t|\t";
00457 }
00458
00459
00460
00461 size = 0;
00462 for (i=0; i < KVPairs->len; i++) {
00463 size += strlen(KVPairs->keyWord[i]) + strlen(sepStr) + strlen(KVPairs->value[i]) + strlen("\n");
00464 }
00465
00466
00467 writeStr = (char *)malloc(size + MAX_COND_LEN);
00468 memset(writeStr, '\0', size + MAX_COND_LEN);
00469
00470
00471
00472 for (i=0; i < KVPairs->len; i++) {
00473 strcat(writeStr, KVPairs->keyWord[i]);
00474 strcat(writeStr, sepStr);
00475 strcat(writeStr, KVPairs->value[i]);
00476 strcat(writeStr, "\n");
00477 }
00478
00479
00480
00481 rei->status = _writeString(writeId, writeStr, rei);
00482
00483
00484
00485 if (writeStr != NULL) {
00486 free(writeStr);
00487 }
00488
00489 return (rei->status);
00490 }
00491
00492
00493
00494
00495
00496
00497
00498
00499
00500
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526
00527
00528
00529
00530 int
00531 writeXMsg(msParam_t* inStreamId, msParam_t *inHdr, msParam_t *inMsg, ruleExecInfo_t *rei)
00532 {
00533 int i;
00534 int streamId;
00535 xmsgTicketInfo_t *xmsgTicketInfo;
00536
00537 RE_TEST_MACRO (" Calling writeXMsg")
00538
00539 if (!strcmp(inStreamId->type,XmsgTicketInfo_MS_T)) {
00540 xmsgTicketInfo = (xmsgTicketInfo_t *) inStreamId->inOutStruct;
00541 streamId = (int) xmsgTicketInfo->rcvTicket;
00542 }
00543 else if (!strcmp(inStreamId->type,STR_MS_T)) {
00544 streamId = (int) atoi((char*)inStreamId->inOutStruct);
00545 }
00546 else
00547 streamId = (int) CAST_PTR_INT inStreamId->inOutStruct;
00548
00549 i = _writeXMsg(streamId, (char*)inHdr->inOutStruct, (char*)inMsg->inOutStruct);
00550 return(i);
00551 }
00552
00553
00554
00555
00556
00557
00558
00559
00560
00561
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571
00572
00573
00574
00575
00576
00577
00578
00579
00580
00581
00582
00583
00584
00585
00586
00587
00588
00589
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599 int
00600 readXMsg(msParam_t* inStreamId, msParam_t *inCondRead,
00601 msParam_t *outMsgNum, msParam_t *outSeqNum,
00602 msParam_t *outHdr, msParam_t *outMsg,
00603 msParam_t *outUser, msParam_t *outAddr, ruleExecInfo_t *rei)
00604 {
00605 int i;
00606 int sNum = 0;
00607 int mNum = 0;
00608 char *hdr = NULL;
00609 char *msg = NULL;
00610 char *user = NULL;
00611 char *addr = NULL;
00612 int streamId;
00613 xmsgTicketInfo_t *xmsgTicketInfo;
00614 char *condRead = NULL;
00615 RE_TEST_MACRO (" Calling readXMsg");
00616
00617 if (!strcmp(inStreamId->type,XmsgTicketInfo_MS_T)) {
00618 xmsgTicketInfo = (xmsgTicketInfo_t *) inStreamId->inOutStruct;
00619 streamId = xmsgTicketInfo->rcvTicket;
00620 }
00621 else if (!strcmp(inStreamId->type,STR_MS_T)) {
00622 streamId = (int) atoi((char*)inStreamId->inOutStruct);
00623 }
00624 else
00625 streamId = (int) CAST_PTR_INT inStreamId->inOutStruct;
00626 condRead = (char *) inCondRead->inOutStruct;
00627 i = _readXMsg(streamId, condRead, &mNum, &sNum, &hdr, &msg, &user, &addr);
00628 if (i >= 0) {
00629 outHdr->inOutStruct = (void *) hdr;
00630 outHdr->type = strdup(STR_MS_T);
00631 outMsg->inOutStruct = (void *) msg;
00632 outMsg->type = strdup(STR_MS_T);
00633 fillIntInMsParam(outMsgNum, mNum);
00634 fillIntInMsParam(outSeqNum, sNum);
00635 outUser->inOutStruct = (void *) user;
00636 outUser->type = strdup(STR_MS_T);
00637 outAddr->inOutStruct = (void *) addr;
00638 outAddr->type = strdup(STR_MS_T);
00639
00640 }
00641 return(i);
00642 }
00643