00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "reGlobalsExtern.h"
00011 #include "icatHighLevelRoutines.h"
00012 #include "apiHeaderAll.h"
00013 #include "rsApiHandler.h"
00014
00015 #ifdef ADDR_64BITS
00016 #define CAST_PTR_INT (long int)
00017 #else
00018 #define CAST_PTR_INT
00019 #endif
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
00059
00060 int writeLine(msParam_t* where, msParam_t* inString, ruleExecInfo_t *rei)
00061 {
00062 int i;
00063 char tmp[3];
00064 char *ptr;
00065 char *writeId = (char *) where->inOutStruct;
00066
00067 if (writeId != NULL && strcmp (writeId, "serverLog") == 0 &&
00068 inString->inOutStruct != NULL) {
00069 rodsLog (LOG_NOTICE, "writeLine: inString = %s\n", inString->inOutStruct);
00070 return 0;
00071 }
00072
00073 i = writeString(where, inString,rei);
00074 if (i < 0)
00075 return(i);
00076 ptr = (char*)inString->inOutStruct;
00077 sprintf(tmp,"%s\n","");
00078 inString->inOutStruct = tmp;
00079 i = writeString(where, inString,rei);
00080 inString->inOutStruct = ptr;
00081 return(i);
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
00123
00124 int writeString(msParam_t* where, msParam_t* inString, ruleExecInfo_t *rei)
00125 {
00126 int i;
00127 char *writeId;
00128 char *writeStr;
00129
00130 if (where->inOutStruct == NULL)
00131 writeId = where->label;
00132 else
00133 writeId = (char*)where->inOutStruct;
00134
00135 if (inString->inOutStruct == NULL) {
00136 writeStr = strdup((char *) inString->label);
00137 }
00138 else {
00139 writeStr = strdup((char *) inString->inOutStruct);
00140 }
00141 i = _writeString(writeId, writeStr, rei);
00142
00143 free(writeStr);
00144 return(i);
00145 }
00146
00147 int _writeString(char *writeId, char *writeStr, ruleExecInfo_t *rei)
00148 {
00149 msParamArray_t *inMsParamArray;
00150 msParam_t *mP;
00151 execCmdOut_t *myExecCmdOut;
00152
00153
00154
00155 dataObjInp_t dataObjInp;
00156 openedDataObjInp_t openedDataObjInp;
00157 bytesBuf_t tmpBBuf;
00158 fileLseekOut_t *dataObjLseekOut = NULL;
00159 int fd,i;
00160
00161
00162 if (writeId != NULL && strcmp (writeId, "serverLog") == 0) {
00163 rodsLog (LOG_NOTICE, "writeString: inString = %s", writeStr);
00164 return 0;
00165 }
00166
00167
00168
00169 if (writeId != NULL && writeId[0] == '/') {
00170
00171
00172 if (rei == NULL || rei->rsComm == NULL) {
00173 rodsLog (LOG_ERROR, "_writeString: input rei or rsComm is NULL");
00174 return (SYS_INTERNAL_NULL_INPUT_ERR);
00175 }
00176
00177 bzero (&dataObjInp, sizeof (dataObjInp));
00178 dataObjInp.openFlags = O_RDWR;
00179 snprintf (dataObjInp.objPath, MAX_NAME_LEN, "%s",writeId);
00180 fd = rsDataObjOpen (rei->rsComm, &dataObjInp);
00181 if (fd < 0) {
00182 rodsLog (LOG_ERROR, "_writeString: rsDataObjOpen failed. status = %d", fd);
00183 return(fd);
00184 }
00185
00186 bzero(&openedDataObjInp, sizeof(openedDataObjInp));
00187 openedDataObjInp.l1descInx = fd;
00188 openedDataObjInp.offset = 0;
00189 openedDataObjInp.whence = SEEK_END;
00190 i = rsDataObjLseek (rei->rsComm, &openedDataObjInp, &dataObjLseekOut);
00191 if (i < 0) {
00192 rodsLog (LOG_ERROR, "_writeString: rsDataObjLseek failed. status = %d", i);
00193 return(i);
00194 }
00195
00196 bzero(&openedDataObjInp, sizeof(openedDataObjInp));
00197 openedDataObjInp.l1descInx = fd;
00198 tmpBBuf.len = openedDataObjInp.len = strlen(writeStr) + 1;
00199 tmpBBuf.buf = writeStr;
00200 i = rsDataObjWrite (rei->rsComm, &openedDataObjInp, &tmpBBuf);
00201 if (i < 0) {
00202 rodsLog (LOG_ERROR, "_writeString: rsDataObjWrite failed. status = %d", i);
00203 return(i);
00204 }
00205
00206 bzero(&openedDataObjInp, sizeof(openedDataObjInp));
00207 openedDataObjInp.l1descInx = fd;
00208 i = rsDataObjClose (rei->rsComm, &openedDataObjInp);
00209 return(i);
00210 }
00211
00212
00213
00214 mP = NULL;
00215 inMsParamArray = rei->msParamArray;
00216 if (((mP = getMsParamByLabel (inMsParamArray, "ruleExecOut")) != NULL) &&
00217 (mP->inOutStruct != NULL)) {
00218 if (!strcmp(mP->type,STR_MS_T)) {
00219 myExecCmdOut = (execCmdOut_t*)malloc (sizeof (execCmdOut_t));
00220 memset (myExecCmdOut, 0, sizeof (execCmdOut_t));
00221 mP->inOutStruct = myExecCmdOut;
00222 mP->type = strdup(ExecCmdOut_MS_T);
00223 }
00224 else
00225 myExecCmdOut = (execCmdOut_t*)mP->inOutStruct;
00226 }
00227 else {
00228 myExecCmdOut = (execCmdOut_t*)malloc (sizeof (execCmdOut_t));
00229 memset (myExecCmdOut, 0, sizeof (execCmdOut_t));
00230 if (mP == NULL)
00231 addMsParam(inMsParamArray,"ruleExecOut", ExecCmdOut_MS_T,myExecCmdOut,NULL);
00232 else {
00233 mP->inOutStruct = myExecCmdOut;
00234 mP->type = strdup(ExecCmdOut_MS_T);
00235 }
00236 }
00237
00238
00239
00240
00241
00242
00243
00244 if(writeId != NULL) {
00245 if (!strcmp(writeId,"stdout"))
00246 appendToByteBuf(&(myExecCmdOut->stdoutBuf),(char *) writeStr);
00247 else if (!strcmp(writeId,"stderr"))
00248 appendToByteBuf(&(myExecCmdOut->stderrBuf),(char *) writeStr);
00249 }
00250
00251 return(0);
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
00286
00287 int writePosInt(msParam_t* where, msParam_t* inInt, ruleExecInfo_t *rei)
00288 {
00289 char *writeId;
00290 char writeStr[LONG_NAME_LEN];
00291 int status;
00292
00293 if (where->inOutStruct != NULL) {
00294 writeId = (char*)where->inOutStruct;
00295 }
00296 else {
00297 writeId = where->label;
00298 }
00299
00300 if (inInt->inOutStruct != NULL) {
00301 sprintf(writeStr, "%d", parseMspForPosInt (inInt));
00302 }
00303 else {
00304 snprintf(writeStr, LONG_NAME_LEN, "%s", inInt->label);
00305 }
00306
00307 status = _writeString(writeId, writeStr, rei);
00308
00309 return (status);
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
00344
00345 int writeBytesBuf(msParam_t* where, msParam_t* inBuf, ruleExecInfo_t *rei)
00346 {
00347 char *writeId;
00348 char *writeStr;
00349 int status;
00350
00351 if (where->inOutStruct != NULL) {
00352 writeId = (char*)where->inOutStruct;
00353 }
00354 else {
00355 writeId = where->label;
00356 }
00357
00358 if (inBuf->inpOutBuf != NULL) {
00359 writeStr = (char *) malloc(strlen((const char*)inBuf->inpOutBuf->buf) + MAX_COND_LEN);
00360 strcpy(writeStr , (const char*)inBuf->inpOutBuf->buf);
00361 }
00362 else {
00363 writeStr = (char *) malloc(strlen(inBuf->label) + MAX_COND_LEN);
00364 strcpy(writeStr , inBuf->label);
00365 }
00366
00367 status = _writeString(writeId, writeStr, rei);
00368
00369 if (writeStr != NULL) {
00370 free(writeStr);
00371 }
00372
00373 return (status);
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
00408
00409 int writeKeyValPairs(msParam_t *where, msParam_t *inKVPair, msParam_t *separator, ruleExecInfo_t *rei)
00410 {
00411 keyValPair_t *KVPairs;
00412 char *writeId;
00413 char *writeStr;
00414 char *sepStr;
00415 int i;
00416 size_t size;
00417
00418
00419 RE_TEST_MACRO (" Calling writeKeyValPairs")
00420
00421
00422
00423 if (!rei ) {
00424 rodsLog (LOG_ERROR, "writeKeyValPairs: input rei is NULL.");
00425 return (SYS_INTERNAL_NULL_INPUT_ERR);
00426 }
00427
00428 if (!where) {
00429 rodsLog (LOG_ERROR, "writeKeyValPairs: No destination provided for writing.");
00430 return (USER__NULL_INPUT_ERR);
00431 }
00432
00433
00434 if (!inKVPair || !inKVPair->inOutStruct)
00435 {
00436 return 0;
00437 }
00438
00439
00440 if (inKVPair->type && strcmp(inKVPair->type, KeyValPair_MS_T)) {
00441 rodsLog (LOG_ERROR, "writeKeyValPairs: input parameter is not of KeyValPair_MS_T type.");
00442 return(USER_PARAM_TYPE_ERR);
00443 }
00444 KVPairs = (keyValPair_t *)inKVPair->inOutStruct;
00445
00446
00447
00448 if (where->inOutStruct != NULL) {
00449 writeId = (char*)where->inOutStruct;
00450 }
00451 else {
00452 writeId = where->label;
00453 }
00454
00455
00456
00457 if ((sepStr = parseMspForStr(separator)) == NULL) {
00458 sepStr = "\t|\t";
00459 }
00460
00461
00462
00463 size = 0;
00464 for (i=0; i < KVPairs->len; i++) {
00465 size += strlen(KVPairs->keyWord[i]) + strlen(sepStr) + strlen(KVPairs->value[i]) + strlen("\n");
00466 }
00467
00468
00469 writeStr = (char *)malloc(size + MAX_COND_LEN);
00470 memset(writeStr, '\0', size + MAX_COND_LEN);
00471
00472
00473
00474 for (i=0; i < KVPairs->len; i++) {
00475 strcat(writeStr, KVPairs->keyWord[i]);
00476 strcat(writeStr, sepStr);
00477 strcat(writeStr, KVPairs->value[i]);
00478 strcat(writeStr, "\n");
00479 }
00480
00481
00482
00483 rei->status = _writeString(writeId, writeStr, rei);
00484
00485
00486
00487 if (writeStr != NULL) {
00488 free(writeStr);
00489 }
00490
00491 return (rei->status);
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
00531
00532 int
00533 writeXMsg(msParam_t* inStreamId, msParam_t *inHdr, msParam_t *inMsg, ruleExecInfo_t *rei)
00534 {
00535 int i;
00536 int streamId;
00537 xmsgTicketInfo_t *xmsgTicketInfo;
00538
00539 RE_TEST_MACRO (" Calling writeXMsg")
00540
00541 if (!strcmp(inStreamId->type,XmsgTicketInfo_MS_T)) {
00542 xmsgTicketInfo = (xmsgTicketInfo_t *) inStreamId->inOutStruct;
00543 streamId = (int) xmsgTicketInfo->rcvTicket;
00544 }
00545 else if (!strcmp(inStreamId->type,STR_MS_T)) {
00546 streamId = (int) atoi((char*)inStreamId->inOutStruct);
00547 }
00548 else
00549 streamId = (int) CAST_PTR_INT inStreamId->inOutStruct;
00550
00551 i = _writeXMsg(streamId, (char*)inHdr->inOutStruct, (char*)inMsg->inOutStruct);
00552 return(i);
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
00600
00601 int
00602 readXMsg(msParam_t* inStreamId, msParam_t *inCondRead,
00603 msParam_t *outMsgNum, msParam_t *outSeqNum,
00604 msParam_t *outHdr, msParam_t *outMsg,
00605 msParam_t *outUser, msParam_t *outAddr, ruleExecInfo_t *rei)
00606 {
00607 int i;
00608 int sNum = 0;
00609 int mNum = 0;
00610 char *hdr = NULL;
00611 char *msg = NULL;
00612 char *user = NULL;
00613 char *addr = NULL;
00614 int streamId;
00615 xmsgTicketInfo_t *xmsgTicketInfo;
00616 char *condRead = NULL;
00617 RE_TEST_MACRO (" Calling readXMsg");
00618
00619 if (!strcmp(inStreamId->type,XmsgTicketInfo_MS_T)) {
00620 xmsgTicketInfo = (xmsgTicketInfo_t *) inStreamId->inOutStruct;
00621 streamId = xmsgTicketInfo->rcvTicket;
00622 }
00623 else if (!strcmp(inStreamId->type,STR_MS_T)) {
00624 streamId = (int) atoi((char*)inStreamId->inOutStruct);
00625 }
00626 else
00627 streamId = (int) CAST_PTR_INT inStreamId->inOutStruct;
00628 condRead = (char *) inCondRead->inOutStruct;
00629 i = _readXMsg(streamId, condRead, &mNum, &sNum, &hdr, &msg, &user, &addr);
00630 if (i >= 0) {
00631 outHdr->inOutStruct = (void *) hdr;
00632 outHdr->type = strdup(STR_MS_T);
00633 outMsg->inOutStruct = (void *) msg;
00634 outMsg->type = strdup(STR_MS_T);
00635 fillIntInMsParam(outMsgNum, mNum);
00636 fillIntInMsParam(outSeqNum, sNum);
00637 outUser->inOutStruct = (void *) user;
00638 outUser->type = strdup(STR_MS_T);
00639 outAddr->inOutStruct = (void *) addr;
00640 outAddr->type = strdup(STR_MS_T);
00641
00642 }
00643 return(i);
00644 }
00645