00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #include "rsApiHandler.h"
00011 #include "modDataObjMeta.h"
00012 #include "rcMisc.h"
00013 #include "miscServerFunct.h"
00014 #include "regReplica.h"
00015 #include "unregDataObj.h"
00016 #include "modAVUMetadata.h"
00017
00018 #ifdef USE_BOOST
00019 #include <boost/thread.hpp>
00020 #include <boost/thread/mutex.hpp>
00021 #include <boost/thread/condition.hpp>
00022 #include <setjmp.h>
00023 jmp_buf Jenv;
00024 #else
00025 #ifndef windows_platform
00026 #include <pthread.h>
00027 #include <setjmp.h>
00028 jmp_buf Jenv;
00029 #endif
00030 #endif
00031
00032 int
00033 rsApiHandler (rsComm_t *rsComm, int apiNumber, bytesBuf_t *inputStructBBuf,
00034 bytesBuf_t *bsBBuf)
00035 {
00036 int apiInx;
00037 int status = 0;
00038 char *myInStruct = NULL;
00039 funcPtr myHandler = NULL;
00040 void *myOutStruct = NULL;
00041 bytesBuf_t myOutBsBBuf;
00042 int retVal = 0;
00043 int numArg = 0;
00044 void *myArgv[4];
00045
00046 memset (&myOutBsBBuf, 0, sizeof (bytesBuf_t));
00047 memset (&rsComm->rError, 0, sizeof (rError_t));
00048
00049 apiInx = apiTableLookup (apiNumber);
00050 if (apiInx < 0) {
00051 rodsLog (LOG_ERROR,
00052 "rsApiHandler: apiTableLookup of apiNumber %d failed", apiNumber);
00053
00054 #ifdef USE_SSL
00055 if (rsComm->ssl_on)
00056 sslSendRodsMsg (rsComm->sock, RODS_API_REPLY_T, NULL, NULL, NULL,
00057 apiInx, rsComm->irodsProt, rsComm->ssl);
00058 else
00059 #endif
00060 sendRodsMsg( rsComm->sock, RODS_API_REPLY_T, NULL, NULL, NULL,
00061 apiInx, rsComm->irodsProt );
00062 return (apiInx);
00063 }
00064
00065 rsComm->apiInx = apiInx;
00066
00067 status = chkApiVersion (rsComm, apiInx);
00068 if (status < 0) {
00069 sendApiReply (rsComm, apiInx, status, myOutStruct, &myOutBsBBuf);
00070 return (status);
00071 }
00072
00073 status = chkApiPermission (rsComm, apiInx);
00074 if (status < 0) {
00075 rodsLog (LOG_NOTICE,
00076 "rsApiHandler: User has no permission for apiNumber %d", apiNumber);
00077 sendApiReply (rsComm, apiInx, status, myOutStruct, &myOutBsBBuf);
00078 return (status);
00079 }
00080
00081
00082
00083 if (inputStructBBuf->len > 0 && RsApiTable[apiInx].inPackInstruct == NULL) {
00084 rodsLog (LOG_NOTICE,
00085 "rsApiHandler: input struct error for apiNumber %d", apiNumber);
00086 sendApiReply (rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
00087 &myOutBsBBuf);
00088 return (SYS_API_INPUT_ERR);
00089 }
00090
00091 if (inputStructBBuf->len <= 0 && RsApiTable[apiInx].inPackInstruct != NULL){
00092 rodsLog (LOG_NOTICE,
00093 "rsApiHandler: input struct error for apiNumber %d", apiNumber);
00094 sendApiReply (rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
00095 &myOutBsBBuf);
00096 return (SYS_API_INPUT_ERR);
00097 }
00098
00099 if (bsBBuf->len > 0 && RsApiTable[apiInx].inBsFlag <= 0) {
00100 rodsLog (LOG_NOTICE,
00101 "rsApiHandler: input byte stream error for apiNumber %d", apiNumber);
00102 sendApiReply (rsComm, apiInx, SYS_API_INPUT_ERR, myOutStruct,
00103 &myOutBsBBuf);
00104 return (SYS_API_INPUT_ERR);
00105 }
00106
00107 if (inputStructBBuf->len > 0) {
00108 status = unpackStruct (inputStructBBuf->buf, (void **) &myInStruct,
00109 RsApiTable[apiInx].inPackInstruct, RodsPackTable, rsComm->irodsProt);
00110 if (status < 0) {
00111 rodsLog (LOG_NOTICE,
00112 "rsApiHandler: unpackStruct error for apiNumber %d, status = %d",
00113 apiNumber, status);
00114 sendApiReply (rsComm, apiInx, status, myOutStruct,
00115 &myOutBsBBuf);
00116 return (status);
00117 }
00118 }
00119
00120
00121
00122 myHandler = RsApiTable[apiInx].svrHandler;
00123
00124 if (RsApiTable[apiInx].inPackInstruct != NULL) {
00125 myArgv[numArg] = myInStruct;
00126 numArg++;
00127 };
00128
00129 if (RsApiTable[apiInx].inBsFlag != 0) {
00130 myArgv[numArg] = bsBBuf;
00131 numArg++;
00132 };
00133
00134 if (RsApiTable[apiInx].outPackInstruct != NULL) {
00135 myArgv[numArg] = (void *) &myOutStruct;
00136 numArg++;
00137 };
00138
00139 if (RsApiTable[apiInx].outBsFlag != 0) {
00140 myArgv[numArg] = (void *) &myOutBsBBuf;
00141 numArg++;
00142 };
00143
00144 if (numArg == 0) {
00145 retVal = (*myHandler) (rsComm);
00146 } else if (numArg == 1) {
00147 retVal = (*myHandler) (rsComm, myArgv[0]);
00148 } else if (numArg == 2) {
00149 retVal = (*myHandler) (rsComm, myArgv[0], myArgv[1]);
00150 } else if (numArg == 3) {
00151 retVal = (*myHandler) (rsComm, myArgv[0], myArgv[1], myArgv[2]);
00152 } else if (numArg == 4) {
00153 retVal = (*myHandler) (rsComm, myArgv[0], myArgv[1], myArgv[2],
00154 myArgv[3]);
00155 }
00156
00157 if (myInStruct != NULL) {
00158
00159
00160 if (strcmp (RsApiTable[apiInx].inPackInstruct, "GenQueryInp_PI") == 0) {
00161 clearGenQueryInp ((genQueryInp_t *) myInStruct);
00162 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00163 "ModDataObjMeta_PI") == 0) {
00164 clearModDataObjMetaInp ((modDataObjMeta_t *) myInStruct);
00165 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00166 "RegReplica_PI") == 0) {
00167 clearRegReplicaInp ((regReplica_t *) myInStruct);
00168 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00169 "UnregDataObj_PI") == 0) {
00170 clearUnregDataObj ((unregDataObj_t *) myInStruct);
00171 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00172 "DataObjInp_PI") == 0) {
00173 #if 0
00174 if (apiNumber == QUERY_SPEC_COLL_AN &&
00175 ((dataObjInp_t *) myInStruct)->specColl != NULL) {
00176 #endif
00177 clearDataObjInp ((dataObjInp_t *) myInStruct);
00178 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00179 "DataObjCopyInp_PI") == 0) {
00180 clearDataObjCopyInp ((dataObjCopyInp_t *) myInStruct);
00181 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00182 "GenQueryOut_PI") == 0) {
00183 clearGenQueryOut ((genQueryOut_t *) myInStruct);
00184 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00185 "CollInpNew_PI") == 0) {
00186 clearCollInp ((collInp_t *) myInStruct);
00187 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00188 "BulkOprInp_PI") == 0) {
00189 clearBulkOprInp ((bulkOprInp_t *) myInStruct);
00190 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00191 "ModAVUMetadataInp_PI") == 0) {
00192 clearModAVUMetadataInp ((modAVUMetadataInp_t *) myInStruct);
00193 } else if (strcmp (RsApiTable[apiInx].inPackInstruct,
00194 "authResponseInp_PI") == 0) {
00195
00196 clearAuthResponseInp ((void *) myInStruct);
00197 }
00198 free (myInStruct);
00199 myInStruct = NULL;
00200 }
00201
00202 if (apiNumber == GSI_AUTH_REQUEST_AN && retVal >= 0) {
00203
00204
00205
00206 logAgentProc (rsComm);
00207 }
00208
00209 if (retVal != SYS_NO_HANDLER_REPLY_MSG) {
00210 status = sendAndProcApiReply
00211 (rsComm, apiInx, retVal, myOutStruct, &myOutBsBBuf);
00212 }
00213
00214 if (retVal >= 0 && status < 0) {
00215 return (status);
00216 } else {
00217 return (retVal);
00218 }
00219 }
00220
00221 int
00222 sendAndProcApiReply ( rsComm_t *rsComm, int apiInx, int status,
00223 void *myOutStruct, bytesBuf_t *myOutBsBBuf)
00224 {
00225 int retval;
00226
00227 retval = sendApiReply (rsComm, apiInx, status, myOutStruct, myOutBsBBuf);
00228
00229 clearBBuf (myOutBsBBuf);
00230 if (myOutStruct != NULL) {
00231 free (myOutStruct);
00232 }
00233 freeRErrorContent (&rsComm->rError);
00234
00235
00236
00237 if (rsComm->portalOpr != NULL) {
00238 handlePortalOpr (rsComm);
00239 clearKeyVal (&rsComm->portalOpr->dataOprInp.condInput);
00240 free (rsComm->portalOpr);
00241 rsComm->portalOpr = NULL;
00242 }
00243
00244 return (retval);
00245 }
00246
00247 int
00248 sendApiReply (rsComm_t *rsComm, int apiInx, int retVal,
00249 void *myOutStruct, bytesBuf_t *myOutBsBBuf)
00250 {
00251 int status;
00252 bytesBuf_t *outStructBBuf = NULL;
00253 bytesBuf_t *myOutStructBBuf;
00254 bytesBuf_t *rErrorBBuf = NULL;
00255 bytesBuf_t *myRErrorBBuf;
00256
00257
00258 svrChkReconnAtSendStart (rsComm);
00259
00260
00261 if (retVal == SYS_HANDLER_DONE_NO_ERROR) {
00262
00263 retVal = 0;
00264 }
00265
00266 if (RsApiTable[apiInx].outPackInstruct != NULL && myOutStruct != NULL) {
00267
00268 status = packStruct ((char *) myOutStruct, &outStructBBuf,
00269 RsApiTable[apiInx].outPackInstruct, RodsPackTable, FREE_POINTER,
00270 rsComm->irodsProt);
00271
00272 if (status < 0) {
00273 rodsLog (LOG_NOTICE,
00274 "sendApiReply: packStruct error, status = %d", status);
00275 #ifdef USE_SSL
00276 if (rsComm->ssl_on)
00277 sslSendRodsMsg (rsComm->sock, RODS_API_REPLY_T, NULL,
00278 NULL, NULL, status, rsComm->irodsProt, rsComm->ssl);
00279 else
00280 #endif
00281 sendRodsMsg( rsComm->sock, RODS_API_REPLY_T, NULL,
00282 NULL, NULL, status, rsComm->irodsProt);
00283
00284 svrChkReconnAtSendEnd (rsComm);
00285
00286 return status;
00287 }
00288
00289 myOutStructBBuf = outStructBBuf;
00290 } else {
00291 myOutStructBBuf = NULL;
00292 }
00293
00294 if (RsApiTable[apiInx].outBsFlag == 0) {
00295 myOutBsBBuf = NULL;
00296 }
00297
00298 if (rsComm->rError.len > 0) {
00299 status = packStruct ((char *) &rsComm->rError, &rErrorBBuf,
00300 "RError_PI", RodsPackTable, 0, rsComm->irodsProt);
00301
00302 if (status < 0) {
00303 rodsLog (LOG_NOTICE,
00304 "sendApiReply: packStruct error, status = %d", status);
00305 #ifdef USE_SSL
00306 if (rsComm->ssl_on)
00307 sslSendRodsMsg (rsComm->sock, RODS_API_REPLY_T, NULL,
00308 NULL, NULL, status, rsComm->irodsProt, rsComm->ssl);
00309 else
00310 #endif
00311 sendRodsMsg( rsComm->sock, RODS_API_REPLY_T, NULL,
00312 NULL, NULL, status, rsComm->irodsProt);
00313
00314 svrChkReconnAtSendEnd (rsComm);
00315
00316 return status;
00317 }
00318
00319 myRErrorBBuf = rErrorBBuf;
00320 } else {
00321 myRErrorBBuf = NULL;
00322 }
00323
00324 #ifdef USE_SSL
00325 if (rsComm->ssl_on)
00326 status = sslSendRodsMsg (rsComm->sock, RODS_API_REPLY_T, myOutStructBBuf,
00327 myOutBsBBuf, myRErrorBBuf, retVal, rsComm->irodsProt, rsComm->ssl);
00328 else
00329 #endif
00330 status = sendRodsMsg( rsComm->sock, RODS_API_REPLY_T, myOutStructBBuf,
00331 myOutBsBBuf, myRErrorBBuf, retVal, rsComm->irodsProt);
00332
00333 if (status < 0) {
00334 int status1;
00335 rodsLog (LOG_NOTICE,
00336 "sendApiReply: sendRodsMsg error, status = %d", status);
00337
00338 if (rsComm->reconnSock > 0) {
00339 int savedStatus = status;
00340 #ifdef USE_BOOST
00341 boost::unique_lock< boost::mutex > boost_lock( *rsComm->lock );
00342 rodsLog (LOG_DEBUG,
00343 "sendApiReply: svrSwitchConnect. cliState = %d,agState=%d",
00344 rsComm->clientState, rsComm->agentState);
00345 status1 = svrSwitchConnect (rsComm);
00346 boost_lock.unlock();
00347 #else
00348 pthread_mutex_lock (&rsComm->lock);
00349 rodsLog (LOG_DEBUG,
00350 "sendApiReply: svrSwitchConnect. cliState = %d,agState=%d",
00351 rsComm->clientState, rsComm->agentState);
00352 status1 = svrSwitchConnect (rsComm);
00353 pthread_mutex_unlock (&rsComm->lock);
00354 #endif
00355 if (status1 > 0) {
00356
00357 rodsLog (LOG_NOTICE,
00358 "sendApiReply: Switch connection and retry sendRodsMsg");
00359 #ifdef USE_SSL
00360 if (rsComm->ssl_on)
00361 status = sslSendRodsMsg (rsComm->sock, RODS_API_REPLY_T,
00362 myOutStructBBuf, myOutBsBBuf, myRErrorBBuf, retVal,
00363 rsComm->irodsProt, rsComm->ssl);
00364 else
00365 #endif
00366 status = sendRodsMsg( rsComm->sock, RODS_API_REPLY_T,
00367 myOutStructBBuf, myOutBsBBuf, myRErrorBBuf, retVal,
00368 rsComm->irodsProt);
00369 if (status >= 0) {
00370 rodsLog (LOG_NOTICE,
00371 "sendApiReply: retry sendRodsMsg succeeded");
00372 } else {
00373 status = savedStatus;
00374 }
00375 }
00376 }
00377
00378 }
00379
00380
00381 svrChkReconnAtSendEnd (rsComm);
00382
00383
00384 freeBBuf (outStructBBuf);
00385 freeBBuf (rErrorBBuf);
00386
00387 return (status);
00388 }
00389
00390 int
00391 chkApiVersion (rsComm_t *rsComm, int apiInx)
00392 {
00393 char *cliApiVersion;
00394
00395 if ((cliApiVersion = getenv (SP_API_VERSION)) != NULL) {
00396 if (strcmp (cliApiVersion, RsApiTable[apiInx].apiVersion) != 0) {
00397 rodsLog (LOG_ERROR,
00398 "chkApiVersion:Client's API Version %s does not match Server's %s",
00399 cliApiVersion, RsApiTable[apiInx].apiVersion);
00400 return (USER_API_VERSION_MISMATCH);
00401 }
00402 }
00403 return (0);
00404 }
00405
00406 int
00407 chkApiPermission (rsComm_t *rsComm, int apiInx)
00408 {
00409 int clientUserAuth;
00410 int proxyUserAuth;
00411 int xmsgSvrOnly;
00412 int xmsgSvrAlso;
00413
00414 clientUserAuth = RsApiTable[apiInx].clientUserAuth;
00415
00416 xmsgSvrOnly = clientUserAuth & XMSG_SVR_ONLY;
00417 xmsgSvrAlso = clientUserAuth & XMSG_SVR_ALSO;
00418
00419 if (ProcessType == XMSG_SERVER_PT) {
00420 if ((xmsgSvrOnly + xmsgSvrAlso) == 0) {
00421 rodsLog (LOG_ERROR,
00422 "chkApiPermission: xmsgServer not allowed to handle api %d",
00423 RsApiTable[apiInx].apiNumber);
00424 return (SYS_NO_API_PRIV);
00425 }
00426 } else if (xmsgSvrOnly != 0) {
00427 rodsLog (LOG_ERROR,
00428 "chkApiPermission: non xmsgServer not allowed to handle api %d",
00429 RsApiTable[apiInx].apiNumber);
00430 return (SYS_NO_API_PRIV);
00431 }
00432
00433 clientUserAuth = clientUserAuth & 0xfff;
00434
00435 if (clientUserAuth > rsComm->clientUser.authInfo.authFlag) {
00436 return (SYS_NO_API_PRIV);
00437 }
00438
00439 proxyUserAuth = RsApiTable[apiInx].proxyUserAuth & 0xfff;
00440 if (proxyUserAuth > rsComm->proxyUser.authInfo.authFlag) {
00441 return (SYS_NO_API_PRIV);
00442 }
00443 return (0);
00444 }
00445
00446 int
00447 handlePortalOpr (rsComm_t *rsComm)
00448 {
00449 int oprType;
00450 int status;
00451
00452 if (rsComm == NULL || rsComm->portalOpr == NULL)
00453 return (0);
00454
00455 oprType = rsComm->portalOpr->oprType;
00456
00457 switch (oprType) {
00458 case PUT_OPR:
00459 case GET_OPR:
00460 status = svrPortalPutGet (rsComm);
00461 break;
00462 default:
00463 rodsLog (LOG_NOTICE,
00464 "handlePortalOpr: Invalid portal oprType: %d", oprType);
00465 status = SYS_INVALID_PORTAL_OPR;
00466 break;
00467 }
00468 return (status);
00469 }
00470
00471 int
00472 readAndProcClientMsg (rsComm_t *rsComm, int flags)
00473 {
00474 int status = 0;
00475 msgHeader_t myHeader;
00476 bytesBuf_t inputStructBBuf, bsBBuf, errorBBuf;
00477
00478
00479 svrChkReconnAtReadStart (rsComm);
00480
00481
00482
00483 memset (&bsBBuf, 0, sizeof (bsBBuf));
00484
00485
00486
00487
00488
00489
00490 if ((flags & READ_HEADER_TIMEOUT) != 0) {
00491 int retryCnt = 0;
00492 #if 0
00493 int retVal = 0;
00494 while (1) {
00495 signal (SIGALRM, readTimeoutHandler);
00496 if ((retVal = setjmp (Jenv)) == 0) {
00497 alarm(READ_HEADER_TIMEOUT_IN_SEC);
00498 status = readMsgHeader (rsComm->sock, &myHeader, NULL);
00499 alarm(0);
00500 break;
00501 } else {
00502 if (retVal == L1DESC_INUSE &&
00503 retryCnt < MAX_READ_HEADER_RETRY) {
00504 retryCnt++;
00505 continue;
00506 }
00507 rodsLog (LOG_ERROR,
00508 "readAndProcClientMsg: readMsgHeader by pid %d hs timedout.",
00509 getpid ());
00510 return USER_SOCK_CONNECT_TIMEDOUT;
00511 }
00512 }
00513 #else
00514 struct timeval tv;
00515 tv.tv_sec = READ_HEADER_TIMEOUT_IN_SEC;
00516 tv.tv_usec = 0;
00517 while (1) {
00518 #ifdef USE_SSL
00519 if (rsComm->ssl_on)
00520 status = sslReadMsgHeader (rsComm->sock, &myHeader, &tv, rsComm->ssl);
00521 else
00522 #endif
00523 status = readMsgHeader (rsComm->sock, &myHeader, &tv);
00524 if (status < 0) {
00525 if (isL1descInuse () && retryCnt < MAX_READ_HEADER_RETRY) {
00526 rodsLogError (LOG_ERROR, status,
00527 "readAndProcClientMsg:readMsgHeader error. status = %d",
00528 status);
00529 retryCnt++;
00530 continue;
00531 }
00532 if (status == USER_SOCK_CONNECT_TIMEDOUT) {
00533 rodsLog (LOG_ERROR,
00534 "readAndProcClientMsg: readMsgHeader by pid %d timedout",
00535 getpid ());
00536 return status;
00537 }
00538 }
00539 break;
00540 }
00541 #endif
00542 } else {
00543 #ifdef USE_SSL
00544 if (rsComm->ssl_on)
00545 status = sslReadMsgHeader (rsComm->sock, &myHeader, NULL, rsComm->ssl);
00546 else
00547 #endif
00548 status = readMsgHeader (rsComm->sock, &myHeader, NULL);
00549 }
00550
00551
00552 if (status < 0) {
00553
00554 rodsLog (LOG_DEBUG,
00555 "readAndProcClientMsg: readMsgHeader error. status = %d", status);
00556
00557
00558 if (rsComm->reconnSock > 0) {
00559 int savedStatus = status;
00560
00561 #ifdef USE_BOOST
00562 boost::unique_lock< boost::mutex > boost_lock( *rsComm->lock );
00563 rodsLog (LOG_DEBUG,
00564 "readAndProcClientMsg: svrSwitchConnect. cliState = %d,agState=%d",
00565 rsComm->clientState, rsComm->agentState);
00566 svrSwitchConnect (rsComm);
00567 boost_lock.unlock();
00568 #else
00569 pthread_mutex_lock (&rsComm->lock);
00570 rodsLog (LOG_DEBUG,
00571 "readAndProcClientMsg: svrSwitchConnect. cliState = %d,agState=%d",
00572 rsComm->clientState, rsComm->agentState);
00573 svrSwitchConnect (rsComm);
00574 pthread_mutex_unlock (&rsComm->lock);
00575 #endif
00576 #ifdef USE_SSL
00577 if (rsComm->ssl_on)
00578 status = sslReadMsgHeader (rsComm->sock, &myHeader, NULL, rsComm->ssl);
00579 else
00580 #endif
00581 status = readMsgHeader (rsComm->sock, &myHeader, NULL);
00582 if (status < 0) {
00583 svrChkReconnAtReadEnd (rsComm);
00584 return (savedStatus);
00585 }
00586 } else {
00587 svrChkReconnAtReadEnd (rsComm);
00588 return (status);
00589 }
00590
00591
00592
00593 }
00594
00595 #ifdef SYS_TIMING
00596 if (strcmp (myHeader.type, RODS_API_REQ_T) == 0) {
00597
00598 if (myHeader.intInfo != AUTH_RESPONSE_AN)
00599 initSysTiming ("irodsAgent", "recv request", 0);
00600 }
00601 #endif
00602 #ifdef USE_SSL
00603 if (rsComm->ssl_on)
00604 status = sslReadMsgBody (rsComm->sock, &myHeader, &inputStructBBuf,
00605 &bsBBuf, &errorBBuf, rsComm->irodsProt, NULL, rsComm->ssl);
00606 else
00607 #endif
00608 status = readMsgBody( rsComm->sock, &myHeader, &inputStructBBuf,
00609 &bsBBuf, &errorBBuf, rsComm->irodsProt, NULL);
00610 if (status < 0) {
00611 rodsLog (LOG_NOTICE,
00612 "agentMain: readMsgBody error. status = %d", status);
00613
00614 svrChkReconnAtReadEnd (rsComm);
00615
00616 return (status);
00617 }
00618
00619
00620 svrChkReconnAtReadEnd (rsComm);
00621
00622
00623
00624
00625 if (strcmp (myHeader.type, RODS_API_REQ_T) == 0) {
00626 status = rsApiHandler (rsComm, myHeader.intInfo, &inputStructBBuf,
00627 &bsBBuf);
00628 #ifdef SYS_TIMING
00629 char tmpStr[NAME_LEN];
00630 snprintf (tmpStr, NAME_LEN, "handle API %d", myHeader.intInfo);
00631 printSysTiming ("irodsAgent", tmpStr, 0);
00632 #endif
00633 clearBBuf (&inputStructBBuf);
00634 clearBBuf (&bsBBuf);
00635 clearBBuf (&errorBBuf);
00636
00637 if ((flags & RET_API_STATUS) != 0) {
00638 return (status);
00639 } else {
00640 return (0);
00641 }
00642 } else if (strcmp (myHeader.type, RODS_DISCONNECT_T) == 0) {
00643 rodsLog (LOG_NOTICE,
00644 "readAndProcClientMsg: received disconnect msg from client");
00645
00646 return (DISCONN_STATUS);
00647 } else if (strcmp (myHeader.type, RODS_RECONNECT_T) == 0) {
00648 rodsLog (LOG_NOTICE,
00649 "readAndProcClientMsg: received reconnect msg from client");
00650
00651 status = readAndProcClientMsg (rsComm, flags);
00652 return status;
00653 } else {
00654 rodsLog (LOG_NOTICE,
00655 "agentMain: msg type %s not support by server",
00656 myHeader.type);
00657 return (USER_MSG_TYPE_NO_SUPPORT);
00658 }
00659 }
00660
00661
00662
00663
00664
00665
00666
00667
00668
00669
00670
00671
00672
00673
00674
00675 int
00676 sendAndRecvBranchMsg (rsComm_t *rsComm, int apiInx, int status,
00677 void *myOutStruct, bytesBuf_t *myOutBsBBuf)
00678 {
00679 int retval;
00680 int savedApiInx;
00681
00682 savedApiInx = rsComm->apiInx;
00683 retval = sendAndProcApiReply (rsComm, apiInx, status,
00684 myOutStruct, myOutBsBBuf);
00685 if (retval < 0) {
00686 rodsLog (LOG_ERROR,
00687 "sendAndRecvBranchMsg: sendAndProcApiReply error. status = %d", retval);
00688 rsComm->apiInx = savedApiInx;
00689 return (retval);
00690 }
00691
00692 while (1) {
00693 retval = readAndProcClientMsg (rsComm, RET_API_STATUS);
00694 if (retval >= 0 || retval == SYS_NO_HANDLER_REPLY_MSG) {
00695
00696 continue;
00697 } else {
00698 rsComm->apiInx = savedApiInx;
00699 if (retval == SYS_HANDLER_DONE_NO_ERROR) {
00700 return 0;
00701 } else {
00702 return (retval);
00703 }
00704 }
00705 }
00706 }
00707
00708 int
00709 svrSendCollOprStat (rsComm_t *rsComm, collOprStat_t *collOprStat)
00710 {
00711 int status;
00712
00713 status = _svrSendCollOprStat (rsComm, collOprStat);
00714
00715 if (status != SYS_CLI_TO_SVR_COLL_STAT_REPLY) {
00716 rodsLog (LOG_ERROR,
00717 "svrSendCollOprStat: client reply %d != %d.",
00718 status, SYS_CLI_TO_SVR_COLL_STAT_REPLY);
00719 return (UNMATCHED_KEY_OR_INDEX);
00720 } else {
00721 return (0);
00722 }
00723 }
00724
00725 int
00726 _svrSendCollOprStat (rsComm_t *rsComm, collOprStat_t *collOprStat)
00727 {
00728 int myBuf;
00729 int status;
00730
00731 status = sendAndProcApiReply (rsComm, rsComm->apiInx,
00732 SYS_SVR_TO_CLI_COLL_STAT, collOprStat, NULL);
00733 if (status < 0) {
00734 rodsLogError (LOG_ERROR, status,
00735 "svrSendCollOprStat: sendAndProcApiReply failed. status = %d",
00736 status);
00737 return status;
00738 }
00739
00740
00741 status = myRead (rsComm->sock, &myBuf, sizeof (myBuf), SOCK_TYPE, NULL,
00742 NULL);
00743 if (status < 0) {
00744 rodsLogError (LOG_ERROR, status,
00745 "svrSendCollOprStat: read handshake failed. status = %d", status);
00746 }
00747 return (ntohl (myBuf));
00748 }
00749
00750 int
00751 svrSendZoneCollOprStat (rsComm_t *rsComm, rcComm_t *conn,
00752 collOprStat_t *collOprStat, int retval)
00753 {
00754 int status = retval;
00755
00756 while (status == SYS_SVR_TO_CLI_COLL_STAT) {
00757 status = _svrSendCollOprStat (rsComm, collOprStat);
00758 if (status == SYS_CLI_TO_SVR_COLL_STAT_REPLY) {
00759 status = _cliGetCollOprStat (conn, &collOprStat);
00760 } else {
00761 int myBuf = htonl (status);
00762 myWrite (conn->sock, (void *) &myBuf, 4, SOCK_TYPE, NULL);
00763 break;
00764 }
00765 }
00766 return (status);
00767 }
00768
00769
00770 void
00771 readTimeoutHandler (int sig)
00772 {
00773 alarm(0);
00774 if (isL1descInuse ()) {
00775 rodsLog (LOG_ERROR,
00776 "readTimeoutHandler: read header by %d timed out. Lidesc is busy.",
00777 getpid ());
00778 longjmp (Jenv, L1DESC_INUSE);
00779 } else {
00780 rodsLog (LOG_ERROR,
00781 "readTimeoutHandler: read header by %d has timed out.",
00782 getpid ());
00783 longjmp (Jenv, READ_HEADER_TIMED_OUT);
00784 }
00785 }
00786
00787