00001
00029
00030
00031
00032
00033 #include <SUM.h>
00034 #include <soi_key.h>
00035 #include <rpc/rpc.h>
00036 #include <rpc/pmap_clnt.h>
00037 #include <sys/time.h>
00038 #include <sys/errno.h>
00039 #include <pwd.h>
00040 #include <sum_rpc.h>
00041 #include <printk.h>
00042 #include "serverdefs.h"
00043 #include "cJSON.h"
00044 #include "hcontainer.h"
00045
00046 #if defined(SUMS_USEMTSUMS) && SUMS_USEMTSUMS
00047 #include <sys/types.h>
00048 #include <sys/socket.h>
00049 #include <netdb.h>
00050
00051 static HContainer_t *gMTCallMap = NULL;
00052
00053
00054 enum MTSums_CallType_enum
00055 { kMTSums_CallType_None = 0,
00056 kMTSums_CallType_Open = 1,
00057 kMTSums_CallType_Close = 2,
00058 kMTSums_CallType_Rollback = 3,
00059 kMTSums_CallType_Info = 4,
00060 kMTSums_CallType_Get = 5,
00061 kMTSums_CallType_Alloc = 6,
00062 kMTSums_CallType_Alloc2 = 7,
00063 kMTSums_CallType_Put = 8,
00064 kMTSums_CallType_Deleteseries = 9,
00065 kMTSums_CallType_Ping = 10,
00066 kMTSums_CallType_Poll = 11,
00067 kMTSums_CallType_END = 12,
00068 };
00069 typedef enum MTSums_CallType_enum MTSums_CallType_t;
00070
00071 char *MTSums_CallType_strings[] =
00072 {
00073 "none",
00074 "open",
00075 "close",
00076 "rollback",
00077 "info",
00078 "get",
00079 "alloc",
00080 "alloc2",
00081 "put",
00082 "deleteseries",
00083 "ping",
00084 "poll"
00085 };
00086
00087 static MTSums_CallType_t CallTypeFromString(const char *str)
00088 {
00089 MTSums_CallType_t rv = kMTSums_CallType_None;
00090 void **node = NULL;
00091 int iCall = 0;
00092
00093 if (!gMTCallMap)
00094 {
00095 gMTCallMap = hcon_create(sizeof(int), 64, NULL, NULL, NULL, NULL, 0);
00096
00097 if (gMTCallMap)
00098 {
00099 for (iCall = 0; iCall < kMTSums_CallType_END; iCall++)
00100 {
00101 hcon_insert(gMTCallMap, MTSums_CallType_strings[iCall], &iCall);
00102 }
00103 }
00104 }
00105
00106 if (gMTCallMap)
00107 {
00108 node = hcon_lookup(gMTCallMap, str);
00109 if (node && *node)
00110 {
00111 rv = *(int *)node;
00112 }
00113 }
00114
00115 return rv;
00116 }
00117
00118
00119 struct JSONIZER_DATA_struct;
00120 typedef struct JSONIZER_DATA_struct JSONIZER_DATA_t;
00121
00122
00123
00124 struct JSONIZER_DATA_INFO_struct
00125 {
00126 uint64_t *sunums;
00127 size_t nSus;
00128 };
00129 typedef struct JSONIZER_DATA_INFO_struct JSONIZER_DATA_INFO_t;
00130
00131 struct JSONIZER_DATA_GET_struct
00132 {
00133 int touch;
00134 int retrieve;
00135 int retention;
00136 uint64_t *sunums;
00137 size_t nSus;
00138 };
00139 typedef struct JSONIZER_DATA_GET_struct JSONIZER_DATA_GET_t;
00140
00141 struct JSONIZER_DATA_ALLOC_struct
00142 {
00143 int sugroup;
00144 double numBytes;
00145 };
00146 typedef struct JSONIZER_DATA_ALLOC_struct JSONIZER_DATA_ALLOC_t;
00147
00148 struct JSONIZER_DATA_ALLOC2_struct
00149 {
00150 uint64_t sunum;
00151 int sugroup;
00152 double numBytes;
00153 };
00154 typedef struct JSONIZER_DATA_ALLOC2_struct JSONIZER_DATA_ALLOC2_t;
00155
00156 struct JSONIZER_DATA_PUT_struct
00157 {
00158 uint64_t *sunums;
00159 char **sudirs;
00160 size_t nSus;
00161 char *series;
00162 int retention;
00163 char *archiveType;
00164 };
00165 typedef struct JSONIZER_DATA_PUT_struct JSONIZER_DATA_PUT_t;
00166
00167 struct JSONIZER_DATA_DELETESERIES_struct
00168 {
00169 char *series;
00170 };
00171 typedef struct JSONIZER_DATA_DELETESERIES_struct JSONIZER_DATA_DELETESERIES_t;
00172
00173 struct JSONIZER_DATA_POLL_struct
00174 {
00175 char *requestID;
00176 };
00177 typedef struct JSONIZER_DATA_POLL_struct JSONIZER_DATA_POLL_t;
00178
00179 static int callMTSums(SUM_t *sums, MTSums_CallType_t callType, JSONIZER_DATA_t *data, int (*history)(const char *fmt, ...));
00180 static int jsonizeRequest(SUM_t *sums, MTSums_CallType_t type, JSONIZER_DATA_t *data, char **json, int (*history)(const char *fmt, ...));
00181 static int unjsonizeResponse(SUM_t *sums, MTSums_CallType_t type, const char *msg, int (*history)(const char *fmt, ...));
00182
00183 #endif
00184
00185
00186 SUMID_t sumrpcopen_1(KEY *argp, CLIENT *clnt, int (*history)(const char *fmt, ...));
00187 static void respd(struct svc_req *rqstp, SVCXPRT *transp);
00188 static KEY *respdoarray_1(KEY *params);
00189
00190 int getanymsg(int block);
00191 static int getmsgimmed(void);
00192 static char *datestring(void);
00193
00194
00195 extern void printkey (KEY *key);
00196
00197
00198 static struct timeval TIMEOUT = { 3600, 0 };
00199 static int RESPDO_called;
00200 static SUMOPENED *sumopened_hdr = NULL;
00201
00202 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
00203
00204
00205
00206 static CLIENT *cl = NULL;
00207 static CLIENT *clalloc = NULL;
00208 static CLIENT *clget = NULL;
00209 static CLIENT *clput = NULL;
00210 static CLIENT *clinfo = NULL;
00211 static CLIENT *cldelser = NULL;
00212 static CLIENT *clopen = NULL;
00213 static CLIENT *clopen1 = NULL;
00214 static CLIENT *clopen2 = NULL;
00215 static CLIENT *clopen3 = NULL;
00216 static CLIENT *clopen4 = NULL;
00217 static CLIENT *clopen5 = NULL;
00218 static CLIENT *clopen6 = NULL;
00219 static CLIENT *clopen7 = NULL;
00220
00221 static CLIENT *clclose = NULL;
00222
00223
00224 static SVCXPRT *transp[MAXSUMOPEN];
00225 static SUMID_t transpid[MAXSUMOPEN];
00226 #endif
00227
00228
00229
00230
00231
00232 static CLIENT *clprev = NULL;
00233 static int numopened = 0;
00234 static int numSUM = 0;
00235 static int taperdon_cleared = 0;
00236
00237
00238 int rr_random(int min, int max)
00239 {
00240 return rand() % (max - min + 1) + min;
00241 }
00242
00243
00244 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
00245
00246
00247
00248
00249
00250 int SUM_shutdown(int query, int (*history)(const char *fmt, ...))
00251 {
00252 KEY *klist;
00253 char *server_name, *cptr, *username;
00254 char *call_err;
00255 int response;
00256 enum clnt_stat status;
00257
00258 if (!(server_name = getenv("SUMSERVER")))
00259 {
00260 server_name = alloca(sizeof(SUMSERVER)+1);
00261 strcpy(server_name, SUMSERVER);
00262 }
00263 cptr = index(server_name, '.');
00264 if(cptr) *cptr = '\0';
00265
00266 cl = clnt_create(server_name, SUMPROG, SUMVERS, "tcp");
00267 if(!cl) {
00268 clnt_pcreateerror("Can't get client handle to sum_svc");
00269 (*history)("sum_svc timeout or not there on %s\n", server_name);
00270 (*history)("Going to retry in 1 sec\n");
00271 sleep(1);
00272 cl = clnt_create(server_name, SUMPROG, SUMVERS, "tcp");
00273 if(!cl) {
00274 clnt_pcreateerror("Can't get client handle to sum_svc");
00275 (*history)("sum_svc timeout or not there on %s\n", server_name);
00276 return(1);
00277 }
00278 }
00279 clprev = cl;
00280 if(!(username = (char *)getenv("USER"))) username = "nouser";
00281 klist = newkeylist();
00282 setkey_str(&klist, "USER", username);
00283 setkey_int(&klist, "QUERY", query);
00284 status = clnt_call(cl, SHUTDO, (xdrproc_t)xdr_Rkey, (char *)klist,
00285 (xdrproc_t)xdr_uint32_t, (char *)&response, TIMEOUT);
00286
00287
00288 if(status != RPC_SUCCESS) {
00289 call_err = clnt_sperror(cl, "Err clnt_call for SHUTDO");
00290 (*history)("%s %s status=%d\n", datestring(), call_err, status);
00291 return (1);
00292 }
00293 return(response);
00294 }
00295 #endif
00296
00297 #if defined(SUMS_USEMTSUMS) && SUMS_USEMTSUMS
00298
00299 #define MSGLEN_NUMBYTES 8
00300 #define MAX_MSG_BUFSIZE 4096
00301 #ifdef MIN
00302 #undef MIN
00303 #endif
00304 #define MIN(a,b) ((a) < (b) ? (a) : (b))
00305
00306
00307 static int sendMsg(SUM_t *sums, const char *msg, uint32_t msgLen, int (*history)(const char *fmt, ...))
00308 {
00309 size_t bytesSentTotal;
00310 size_t bytesSent;
00311 char numBytesMesssage[MSGLEN_NUMBYTES + 1];
00312 const char *pBuf = NULL;
00313 int sockfd = -1;
00314 int err = 0;
00315
00316 if (msg && *msg && sums)
00317 {
00318
00319 sockfd = (int)sums->mSumsClient;
00320
00321 if (sockfd != -1)
00322 {
00323
00324 bytesSentTotal = 0;
00325 snprintf(numBytesMesssage, sizeof(numBytesMesssage), "%08x", msgLen);
00326
00327 while (bytesSentTotal < MSGLEN_NUMBYTES)
00328 {
00329 pBuf = numBytesMesssage + bytesSentTotal;
00330 bytesSent = send(sockfd, pBuf, strlen(pBuf), 0);
00331
00332 if (!bytesSent)
00333 {
00334 (*history)("Socket to MT SUMS broken.\n");
00335 err = 1;
00336 break;
00337 }
00338
00339 bytesSentTotal += bytesSent;
00340 }
00341
00342 if (!err)
00343 {
00344
00345 bytesSentTotal = 0;
00346
00347 while (bytesSentTotal < msgLen)
00348 {
00349 pBuf = msg + bytesSentTotal;
00350 bytesSent = send(sockfd, pBuf, msgLen - bytesSentTotal, 0);
00351
00352 if (!bytesSent)
00353 {
00354 (*history)("Socket to MT SUMS broken.\n");
00355 err = 1;
00356 break;
00357 }
00358
00359 bytesSentTotal += bytesSent;
00360 }
00361 }
00362 }
00363 else
00364 {
00365 err = 1;
00366 (*history)("Not connected to MT SUMS.\n");
00367 }
00368 }
00369 else
00370 {
00371 (*history)("Invalid arguments to sendMsg().\n");
00372 }
00373
00374 return err;
00375 }
00376
00377 static int receiveMsg(SUM_t *sums, char **out, size_t *outLen, int (*history)(const char *fmt, ...))
00378 {
00379 size_t bytesReceivedTotal;
00380 ssize_t sizeTextRecvd;
00381 char recvBuffer[MAX_MSG_BUFSIZE];
00382 char numBytesMessage[MSGLEN_NUMBYTES + 1];
00383 unsigned int sizeMessage;
00384 char *allTextReceived = NULL;
00385 int sockfd = -1;
00386 struct timeval tv;
00387 fd_set readfds;
00388 int nReady;
00389 int err = 0;
00390
00391 if (!out)
00392 {
00393 err = 1;
00394 (*history)("'out' must not be NULL in receiveMsg().\n");
00395 }
00396
00397 if (!err)
00398 {
00399 if (!sums || sums->mSumsClient == -1)
00400 {
00401 err = 1;
00402 (*history)("Not connected to sumsd.py.\n");
00403 }
00404 }
00405
00406 if (!err)
00407 {
00408 sockfd = (int)sums->mSumsClient;
00409
00410
00411 bytesReceivedTotal = 0;
00412
00413
00414
00415 *recvBuffer = '\0';
00416
00417 FD_ZERO(&readfds);
00418 FD_SET(sockfd, &readfds);
00419
00420 while (bytesReceivedTotal < MSGLEN_NUMBYTES && bytesReceivedTotal < MAX_MSG_BUFSIZE)
00421 {
00422 tv.tv_sec = 10;
00423 tv.tv_usec = 0;
00424 nReady = select(sockfd + 1, &readfds, NULL, NULL, &tv);
00425
00426 if (nReady == 0)
00427 {
00428 (*history)("Timeout receiving data from sumsd.py.\n");
00429 err = 2;
00430 break;
00431 }
00432
00433 sizeTextRecvd = recv(sockfd, recvBuffer + bytesReceivedTotal, MIN(MSGLEN_NUMBYTES - bytesReceivedTotal, MAX_MSG_BUFSIZE - bytesReceivedTotal), 0);
00434
00435 if (sizeTextRecvd <= 0)
00436 {
00437 (*history)("Socket to sumsd.py broken.\n");
00438 err = 1;
00439 break;
00440 }
00441
00442 bytesReceivedTotal += sizeTextRecvd;
00443 }
00444 }
00445
00446 if (!err)
00447 {
00448
00449 *numBytesMessage = '\0';
00450 snprintf(numBytesMessage, sizeof(numBytesMessage), "%s", recvBuffer);
00451 sscanf(numBytesMessage, "%08x", &sizeMessage);
00452
00453 allTextReceived = calloc(1, sizeMessage + 1);
00454
00455 if (!allTextReceived)
00456 {
00457 (*history)("Out of memory in receiveMsg().\n");
00458 err = 1;
00459 }
00460 else
00461 {
00462
00463 bytesReceivedTotal = 0;
00464
00465 *recvBuffer = '\0';
00466 while (bytesReceivedTotal < sizeMessage)
00467 {
00468 tv.tv_sec = 10;
00469 tv.tv_usec = 0;
00470 nReady = select(sockfd + 1, &readfds, NULL, NULL, &tv);
00471
00472 if (nReady == 0)
00473 {
00474 (*history)("Timeout receiving data from sumsd.py.\n");
00475 err = 2;
00476 break;
00477 }
00478
00479 sizeTextRecvd = recv(sockfd, recvBuffer, MIN(sizeMessage - bytesReceivedTotal, MAX_MSG_BUFSIZE), 0);
00480
00481 if (sizeTextRecvd <= 0)
00482 {
00483 (*history)("Socket to sumsd.py broken.\n");
00484 err = 1;
00485 break;
00486 }
00487
00488
00489
00490
00491 memcpy(allTextReceived + bytesReceivedTotal, recvBuffer, sizeTextRecvd);
00492 bytesReceivedTotal += sizeTextRecvd;
00493 }
00494 }
00495 }
00496
00497 if (err)
00498 {
00499 if (allTextReceived)
00500 {
00501 free(allTextReceived);
00502 allTextReceived = NULL;
00503 }
00504 }
00505 else
00506 {
00507 *out = allTextReceived;
00508 *outLen = bytesReceivedTotal;
00509 }
00510
00511 return err;
00512 }
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522 static int jsonizeClientInfo(SUM_t *sums, pid_t pid, const char *username, char **json, int (*history)(const char *fmt, ...))
00523 {
00524 int err = 1;
00525
00526 if (json)
00527 {
00528 cJSON *root = NULL;
00529
00530 root = cJSON_CreateObject();
00531 if (!root)
00532 {
00533 (*history)("Out of memory calling cJSON_CreateObject().\n");
00534 }
00535 else
00536 {
00537
00538 cJSON_AddNumberToObject(root, "pid", (double)pid);
00539 cJSON_AddStringToObject(root, "user", username);
00540
00541 *json = cJSON_Print(root);
00542
00543 if (*json)
00544 {
00545 err = 0;
00546 }
00547
00548 cJSON_Delete(root);
00549 }
00550 }
00551
00552 return err;
00553 }
00554
00555 static MSUMSCLIENT_t ConnectToMtSums(SUM_t *sums, int (*history)(const char *fmt, ...))
00556 {
00557 MSUMSCLIENT_t msums = -1;
00558 int sockfd = -1;
00559 struct addrinfo hints;
00560 struct addrinfo *result = NULL;
00561 char service[16];
00562 struct sockaddr_in server;
00563
00564 if (sums && sums->mSumsClient == -1)
00565 {
00566 memset(&hints, 0, sizeof(struct addrinfo));
00567 hints.ai_flags = 0;
00568 hints.ai_family = AF_UNSPEC;
00569 hints.ai_socktype = SOCK_STREAM;
00570 hints.ai_protocol = 0;
00571
00572 snprintf(service, sizeof(service), "%d", SUMSD_LISTENPORT);
00573
00574
00575 if (getaddrinfo(SUMSERVER, service, &hints, &result) != 0)
00576 {
00577 (*history)("Unable to get SUMS server address.\n");
00578 }
00579 else
00580 {
00581 struct addrinfo *address = NULL;
00582
00583 for (address = result; address != NULL; address = address->ai_next)
00584 {
00585 if ((sockfd = socket(address->ai_family, address->ai_socktype, address->ai_protocol)) == -1)
00586 {
00587 (*history)("Unable to create socket to sumsd.py with address.\n");
00588 continue;
00589 }
00590 else
00591 {
00592
00593 if (connect(sockfd, result->ai_addr, result->ai_addrlen) == -1)
00594 {
00595 (*history)("Unable to connect to SUMS server with address (errno = %d).\n", errno);
00596 close(sockfd);
00597 sockfd = -1;
00598 }
00599 else
00600 {
00601 msums = (MSUMSCLIENT_t)sockfd;
00602 break;
00603 }
00604 }
00605 }
00606 }
00607
00608 freeaddrinfo(result);
00609
00610
00611 if (msums != -1)
00612 {
00613 pid_t pid;
00614 struct passwd *pwd = NULL;
00615 char *json = NULL;
00616
00617
00618 sums->mSumsClient = msums;
00619
00620 pid = getpid();
00621 pwd = getpwuid(geteuid());
00622
00623 if (jsonizeClientInfo(sums, pid, pwd->pw_name, &json, history))
00624 {
00625 (*history)("Unable to collect client info.\n");
00626 shutdown(msums, SHUT_RDWR);
00627 close(msums);
00628 msums = -1;
00629 sums->mSumsClient = -1;
00630 }
00631 else
00632 {
00633
00634 if (sendMsg(sums, json, strlen(json), history))
00635 {
00636 shutdown(msums, SHUT_RDWR);
00637 close(msums);
00638 msums = -1;
00639 sums->mSumsClient = -1;
00640 }
00641 }
00642
00643 if (json)
00644 {
00645 free(json);
00646 json = NULL;
00647 }
00648 }
00649 }
00650 else
00651 {
00652 (*history)("Unable to connect to MT SUMS.\n");
00653 }
00654
00655 return sums->mSumsClient;
00656 }
00657
00658 static void DisconnectFromMtSums(SUM_t *sums)
00659 {
00660 if (sums && sums->mSumsClient != -1)
00661 {
00662 shutdown(sums->mSumsClient, SHUT_RDWR);
00663 close(sums->mSumsClient);
00664 sums->mSumsClient = -1;
00665 }
00666 }
00667 #endif
00668
00669
00670
00671
00672
00673
00674
00675
00676
00677
00678
00679
00680
00681
00682
00683
00684
00685
00686
00687
00688
00689
00690
00691
00692
00693
00694
00695
00696
00697
00698
00699
00700
00701
00702
00703
00704 SUM_t *sumsopenOpen(const char *server, const char *db, int (*history)(const char *fmt, ...))
00705 {
00706 CLIENT *clopx = NULL;
00707 KEY *klist = NULL;
00708 SUM_t *sumptr;
00709 SUMID_t configback;
00710 SUMID_t sumid;
00711 enum clnt_stat status;
00712 struct timeval tval;
00713 unsigned int stime;
00714 char *server_name, *cptr, *username;
00715 char *call_err;
00716 int i, j, rr;
00717
00718 #if defined(SUMS_USEMTSUMS) && SUMS_USEMTSUMS
00719 MSUMSCLIENT_t msums = -1;
00720 #endif
00721
00722 if(numopened >= MAXSUMOPEN) {
00723 (*history)("Exceeded max=%d SUM_open() for a client\n", MAXSUMOPEN);
00724 return(NULL);
00725 }
00726
00727 if (server)
00728 {
00729 server_name = alloca(strlen(server)+1);
00730 strcpy(server_name, server);
00731 }
00732 else
00733 {
00734 if (!(server_name = getenv("SUMSERVER")))
00735 {
00736 server_name = alloca(sizeof(SUMSERVER)+1);
00737 strcpy(server_name, SUMSERVER);
00738 }
00739 }
00740 cptr = index(server_name, '.');
00741 if(cptr) *cptr = '\0';
00742 gettimeofday(&tval, NULL);
00743 stime = (unsigned int)tval.tv_usec;
00744 srand(stime);
00745 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
00746
00747 cl = clnt_create(server_name, SUMPROG, SUMVERS, "tcp");
00748 if(!cl) {
00749 clnt_pcreateerror("Can't get client handle to sum_svc");
00750 (*history)("sum_svc timeout or not there on %s\n", server_name);
00751 (*history)("Going to retry in 1 sec\n");
00752 sleep(1);
00753 cl = clnt_create(server_name, SUMPROG, SUMVERS, "tcp");
00754 if(!cl) {
00755 clnt_pcreateerror("Can't get client handle to sum_svc");
00756 (*history)("sum_svc timeout or not there on %s\n", server_name);
00757 return(NULL);
00758 }
00759 }
00760 clprev = cl;
00761
00762 if(!(username = (char *)getenv("USER"))) username = "nouser";
00763 klist = newkeylist();
00764 setkey_str(&klist, "db_name", db);
00765 setkey_str(&klist, "USER", username);
00766 status = clnt_call(cl, CONFIGDO, (xdrproc_t)xdr_Rkey, (char *)klist,
00767 (xdrproc_t)xdr_uint32_t, (char *)&configback, TIMEOUT);
00768 configback = (SUMID_t)configback;
00769
00770
00771
00772 if(status != RPC_SUCCESS) {
00773 call_err = clnt_sperror(cl, "Err clnt_call for CONFIGDO");
00774 (*history)("%s %s status=%d\n", datestring(), call_err, status);
00775 freekeylist(&klist);
00776 return (0);
00777 }
00778 freekeylist(&klist);
00779 numSUM = (int)configback;
00780 if(numSUM == 0) {
00781 (*history)("numSUM = 0 on call to CONFIGDO in SUM_open(). Can't config\n");
00782 (*history)("(sum_svc may have been manually shutdown. No new open allowed)\n");
00783 return(0);
00784 }
00785 #else // sum_svc SUM_open() was called (branch above)
00786 numSUM = SUM_NUMSUM;
00787 clprev = NULL;
00788 #endif
00789
00790 if(numSUM > SUM_MAXNUMSUM)
00791 {
00792 (*history)("**ERROR: #of sum_svc > SUM_MAXNUMSUM (%d)\n", SUM_MAXNUMSUM);
00793 (*history)("This is a fatal sum_svc configuration error\n");
00794 return(0);
00795 }
00796
00797 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
00798 for(i=0; i < numSUM; i++) {
00799 switch(i) {
00800 case 0:
00801 clopen = cl;
00802 break;
00803 case 1:
00804 clopen = clnt_create(server_name, SUMOPEN, SUMOPENV, "tcp");
00805 if(!clopen) {
00806 clnt_pcreateerror("Can't get client handle for OPEN to sum_svc");
00807 (*history)("sum_svc OPEN timeout or not there on %s\n", server_name);
00808 (*history)("Going to retry in 1 sec\n");
00809 sleep(1);
00810 clopen = clnt_create(server_name, SUMOPEN, SUMOPENV, "tcp");
00811 if(!clopen) {
00812 clnt_pcreateerror("Can't get client handle for OPEN to sum_svc");
00813 (*history)("sum_svc OPEN1 timeout or not there on %s\n", server_name);
00814 return(NULL);
00815 }
00816 }
00817 clopen1 = clnt_create(server_name, SUMOPEN1, SUMOPENV, "tcp");
00818 if(!clopen1) {
00819 clnt_pcreateerror("Can't get client handle for OPEN1 to sum_svc");
00820 (*history)("sum_svc OPEN1 timeout or not there on %s\n", server_name);
00821 (*history)("Going to retry in 1 sec\n");
00822 sleep(1);
00823 clopen1 = clnt_create(server_name, SUMOPEN1, SUMOPENV, "tcp");
00824 if(!clopen1) {
00825 clnt_pcreateerror("Can't get client handle for OPEN1 to sum_svc");
00826 (*history)("sum_svc OPEN1 timeout or not there on %s\n", server_name);
00827 return(NULL);
00828 }
00829 }
00830 break;
00831 case 2:
00832 clopen2 = clnt_create(server_name, SUMOPEN2, SUMOPENV, "tcp");
00833 if(!clopen2) {
00834 clnt_pcreateerror("Can't get client handle for OPEN2 to sum_svc");
00835 (*history)("sum_svc OPEN2 timeout or not there on %s\n", server_name);
00836 (*history)("Going to retry in 1 sec\n");
00837 sleep(1);
00838 clopen2 = clnt_create(server_name, SUMOPEN2, SUMOPENV, "tcp");
00839 if(!clopen2) {
00840 clnt_pcreateerror("Can't get client handle for OPEN2 to sum_svc");
00841 (*history)("sum_svc OPEN2 timeout or not there on %s\n", server_name);
00842 return(NULL);
00843 }
00844 }
00845 break;
00846 case 3:
00847 clopen3 = clnt_create(server_name, SUMOPEN3, SUMOPENV, "tcp");
00848 if(!clopen3) {
00849 clnt_pcreateerror("Can't get client handle for OPEN3 to sum_svc");
00850 (*history)("sum_svc OPEN3 timeout or not there on %s\n", server_name);
00851 (*history)("Going to retry in 1 sec\n");
00852 sleep(1);
00853 clopen3 = clnt_create(server_name, SUMOPEN3, SUMOPENV, "tcp");
00854 if(!clopen3) {
00855 clnt_pcreateerror("Can't get client handle for OPEN3 to sum_svc");
00856 (*history)("sum_svc OPEN3 timeout or not there on %s\n", server_name);
00857 return(NULL);
00858 }
00859 }
00860 break;
00861 case 4:
00862 clopen4 = clnt_create(server_name, SUMOPEN4, SUMOPENV, "tcp");
00863 if(!clopen4) {
00864 clnt_pcreateerror("Can't get client handle for OPEN4 to sum_svc");
00865 (*history)("sum_svc OPEN4 timeout or not there on %s\n", server_name);
00866 (*history)("Going to retry in 1 sec\n");
00867 sleep(1);
00868 clopen4 = clnt_create(server_name, SUMOPEN4, SUMOPENV, "tcp");
00869 if(!clopen4) {
00870 clnt_pcreateerror("Can't get client handle for OPEN4 to sum_svc");
00871 (*history)("sum_svc OPEN4 timeout or not there on %s\n", server_name);
00872 return(NULL);
00873 }
00874 }
00875 break;
00876 case 5:
00877 clopen5 = clnt_create(server_name, SUMOPEN5, SUMOPENV, "tcp");
00878 if(!clopen5) {
00879 clnt_pcreateerror("Can't get client handle for OPEN5 to sum_svc");
00880 (*history)("sum_svc OPEN5 timeout or not there on %s\n", server_name);
00881 (*history)("Going to retry in 1 sec\n");
00882 sleep(1);
00883 clopen5 = clnt_create(server_name, SUMOPEN5, SUMOPENV, "tcp");
00884 if(!clopen5) {
00885 clnt_pcreateerror("Can't get client handle for OPEN5 to sum_svc");
00886 (*history)("sum_svc OPEN5 timeout or not there on %s\n", server_name);
00887 return(NULL);
00888 }
00889 }
00890 break;
00891 case 6:
00892 clopen6 = clnt_create(server_name, SUMOPEN6, SUMOPENV, "tcp");
00893 if(!clopen6) {
00894 clnt_pcreateerror("Can't get client handle for OPEN6 to sum_svc");
00895 (*history)("sum_svc OPEN6 timeout or not there on %s\n", server_name);
00896 (*history)("Going to retry in 1 sec\n");
00897 sleep(1);
00898 clopen6 = clnt_create(server_name, SUMOPEN6, SUMOPENV, "tcp");
00899 if(!clopen6) {
00900 clnt_pcreateerror("Can't get client handle for OPEN6 to sum_svc");
00901 (*history)("sum_svc OPEN6 timeout or not there on %s\n", server_name);
00902 return(NULL);
00903 }
00904 }
00905 break;
00906 case 7:
00907 clopen7 = clnt_create(server_name, SUMOPEN7, SUMOPENV, "tcp");
00908 if(!clopen7) {
00909 clnt_pcreateerror("Can't get client handle for OPEN7 to sum_svc");
00910 (*history)("sum_svc OPEN7 timeout or not there on %s\n", server_name);
00911 (*history)("Going to retry in 1 sec\n");
00912 sleep(1);
00913 clopen7 = clnt_create(server_name, SUMOPEN7, SUMOPENV, "tcp");
00914 if(!clopen7) {
00915 clnt_pcreateerror("Can't get client handle for OPEN7 to sum_svc");
00916 (*history)("sum_svc OPEN7 timeout or not there on %s\n", server_name);
00917 return(NULL);
00918 }
00919 }
00920 break;
00921 }
00922 }
00923 #endif // Not using MT SUMS SUM_open()
00924
00925 if (!db)
00926 {
00927 if (!(db = getenv("SUMDB")))
00928 {
00929 char *dbInternal = alloca(sizeof(SUMS_DB_HOST)+1);
00930 strcpy(dbInternal, SUMS_DB_HOST);
00931 db = dbInternal;
00932 }
00933 }
00934
00935 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
00936 klist = newkeylist();
00937 setkey_str(&klist, "db_name", db);
00938 setkey_str(&klist, "USER", username);
00939
00940 rr = rr_random(0, numSUM-1);
00941
00942 switch(rr)
00943 {
00944 case 0:
00945 clopx = clopen;
00946 break;
00947 case 1:
00948 clopx = clopen1;
00949 break;
00950 case 2:
00951 clopx = clopen2;
00952 break;
00953 case 3:
00954 clopx = clopen3;
00955 break;
00956 case 4:
00957 clopx = clopen4;
00958 break;
00959 case 5:
00960 clopx = clopen5;
00961 break;
00962 case 6:
00963 clopx = clopen6;
00964 break;
00965 case 7:
00966 clopx = clopen7;
00967 break;
00968 }
00969
00970
00971
00972 if((sumid = sumrpcopen_1(klist, clopx, history)) == 0)
00973 {
00974 (*history)("Failed to get SUMID from sum_svc\n");
00975 clnt_destroy(cl);
00976 freekeylist(&klist);
00977 return(NULL);
00978 }
00979
00980 sumptr = (SUM_t *)calloc(1, sizeof(SUM_t));
00981
00982 #if defined(SUMS_USEMTSUMS) && SUMS_USEMTSUMS
00983 sumptr->mSumsClient = msums;
00984 #endif
00985 #else
00986
00987 SUM_t *sums = NULL;
00988 int err;
00989
00990 err = ((sums = (SUM_t *)calloc(1, sizeof(SUM_t))) == NULL);
00991
00992 if (err)
00993 {
00994 (*history)("Cannot alloc SUM_t - out of memory.\n");
00995 }
00996 else
00997 {
00998 sums->mSumsClient = msums;
00999
01000 err = callMTSums(sums, kMTSums_CallType_Open, NULL, history);
01001 }
01002
01003 if (err)
01004 {
01005 (*history)("Cannot connect to MT SUMS.\n");
01006 return NULL;
01007 }
01008
01009
01010 sumid = sums->uid;
01011 sumptr = sums;
01012 clprev = NULL;
01013 #endif
01014
01015 numopened++;
01016
01017
01018
01019
01020 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01021 sumptr->clclose = clopx;
01022 #endif
01023 sumptr->sinfo = NULL;
01024
01025 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01026 sumptr->cl = cl;
01027 #endif
01028
01029 for(j=0; j < numSUM; j++) {
01030 switch(j) {
01031 case 0:
01032 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01033 sumptr->clopen = cl;
01034 #endif
01035 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01036 sumptr->clalloc = cl;
01037 #endif
01038 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01039 sumptr->clget = cl;
01040 #endif
01041 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01042 sumptr->clput = cl;
01043 #endif
01044 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01045 sumptr->clinfo = cl;
01046 #endif
01047 break;
01048 case 1:
01049 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01050 sumptr->clopen = clopen;
01051 sumptr->clopen1 = clopen1;
01052 #endif
01053 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01054 clalloc = clnt_create(server_name, SUMALLOC, SUMALLOCV, "tcp");
01055 if(!clalloc) {
01056 for(i=0; i < 4; i++) {
01057 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC. Retry..");
01058 (*history)("Going to retry in 1 sec. i=%d\n", i);
01059 sleep(1);
01060 clalloc = clnt_create(server_name, SUMALLOC, SUMALLOCV, "tcp");
01061 if(clalloc) { break; }
01062 }
01063 if(!clalloc) {
01064 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC");
01065 (*history)("sum_svc error on handle to SUMALLOC on %s\n", server_name);
01066 return(NULL);
01067 }
01068 }
01069 sumptr->clalloc = clalloc;
01070 clalloc = clnt_create(server_name, SUMALLOC1, SUMALLOCV, "tcp");
01071 if(!clalloc) {
01072 for(i=0; i < 4; i++) {
01073 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC1. Retry..");
01074 (*history)("Going to retry in 1 sec. i=%d\n", i);
01075 sleep(1);
01076 clalloc = clnt_create(server_name, SUMALLOC1, SUMALLOCV, "tcp");
01077 if(clalloc) { break; }
01078 }
01079 if(!clalloc) {
01080 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC1");
01081 (*history)("sum_svc error on handle to SUMALLOC1 on %s\n", server_name);
01082 return(NULL);
01083 }
01084 }
01085 sumptr->clalloc1 = clalloc;
01086 #endif
01087 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01088 clget = clnt_create(server_name, SUMGET, SUMGETV, "tcp");
01089 if(!clget) {
01090 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET");
01091 (*history)("sum_svc error on handle to SUMGET on %s\n", server_name);
01092 sleep(1);
01093 clget = clnt_create(server_name, SUMGET, SUMGETV, "tcp");
01094 if(!clget) {
01095 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET");
01096 (*history)("sum_svc error on handle to SUMGET on %s\n", server_name);
01097 return(NULL);
01098 }
01099 }
01100 sumptr->clget = clget;
01101 clget = clnt_create(server_name, SUMGET1, SUMGETV, "tcp");
01102 if(!clget) {
01103 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET1");
01104 (*history)("sum_svc error on handle to SUMGET1 on %s\n", server_name);
01105 sleep(1);
01106 clget = clnt_create(server_name, SUMGET1, SUMGETV, "tcp");
01107 if(!clget) {
01108 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET1");
01109 (*history)("sum_svc error on handle to SUMGET1 on %s\n", server_name);
01110 return(NULL);
01111 }
01112 }
01113 sumptr->clget1 = clget;
01114 #endif
01115 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01116 clput = clnt_create(server_name, SUMPUT, SUMPUTV, "tcp");
01117 if(!clput) {
01118 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT");
01119 (*history)("sum_svc error on handle to SUMPUT on %s\n", server_name);
01120 sleep(1);
01121 clput = clnt_create(server_name, SUMPUT, SUMPUTV, "tcp");
01122 if(!clput) {
01123 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT");
01124 (*history)("sum_svc error on handle to SUMPUT on %s\n", server_name);
01125 return(NULL);
01126 }
01127 }
01128 sumptr->clput = clput;
01129 clput = clnt_create(server_name, SUMPUT1, SUMPUTV, "tcp");
01130 if(!clput) {
01131 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT1");
01132 (*history)("sum_svc error on handle to SUMPUT1 on %s\n", server_name);
01133 sleep(1);
01134 clput = clnt_create(server_name, SUMPUT1, SUMPUTV, "tcp");
01135 if(!clput) {
01136 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT1");
01137 (*history)("sum_svc error on handle to SUMPUT1 on %s\n", server_name);
01138 return(NULL);
01139 }
01140 }
01141 sumptr->clput1 = clput;
01142 #endif
01143 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01144 clinfo = clnt_create(server_name, SUMINFO, SUMINFOV, "tcp");
01145 if(!clinfo) {
01146 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO");
01147 (*history)("sum_svc error on handle to SUMINFO on %s\n", server_name);
01148 sleep(1);
01149 clinfo = clnt_create(server_name, SUMINFO, SUMINFOV, "tcp");
01150 if(!clinfo) {
01151 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO");
01152 (*history)("sum_svc error on handle to SUMINFO on %s\n", server_name);
01153 return(NULL);
01154 }
01155 }
01156 sumptr->clinfo = clinfo;
01157
01158 clinfo = clnt_create(server_name, SUMINFO1, SUMINFOV, "tcp");
01159 if(!clinfo) {
01160 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO1");
01161 (*history)("sum_svc error on handle to SUMINFO1 on %s\n", server_name);
01162 sleep(1);
01163 clinfo = clnt_create(server_name, SUMINFO1, SUMINFOV, "tcp");
01164 if(!clinfo) {
01165 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO1");
01166 (*history)("sum_svc error on handle to SUMINFO1 on %s\n", server_name);
01167 return(NULL);
01168 }
01169 }
01170 sumptr->clinfo1 = clinfo;
01171 #endif
01172
01173 break;
01174 case 2:
01175 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01176 sumptr->clopen2 = clopen2;
01177 #endif
01178 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01179 clalloc = clnt_create(server_name, SUMALLOC2, SUMALLOCV, "tcp");
01180 if(!clalloc) {
01181 for(i=0; i < 4; i++) {
01182 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC2. Retry..");
01183 (*history)("Going to retry in 1 sec. i=%d\n", i);
01184 sleep(1);
01185 clalloc = clnt_create(server_name, SUMALLOC2, SUMALLOCV, "tcp");
01186 if(clalloc) { break; }
01187 }
01188 if(!clalloc) {
01189 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC2");
01190 (*history)("sum_svc error on handle to SUMALLOC2 on %s\n", server_name);
01191 return(NULL);
01192 }
01193 }
01194 sumptr->clalloc2 = clalloc;
01195 #endif
01196 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01197 clget = clnt_create(server_name, SUMGET2, SUMGETV, "tcp");
01198 if(!clget) {
01199 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET2");
01200 (*history)("sum_svc error on handle to SUMGET2 on %s\n", server_name);
01201 sleep(1);
01202 clget = clnt_create(server_name, SUMGET2, SUMGETV, "tcp");
01203 if(!clget) {
01204 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET2");
01205 (*history)("sum_svc error on handle to SUMGET2 on %s\n", server_name);
01206 return(NULL);
01207 }
01208 }
01209 sumptr->clget2 = clget;
01210 #endif
01211 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01212 clput = clnt_create(server_name, SUMPUT2, SUMPUTV, "tcp");
01213 if(!clput) {
01214 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT2");
01215 (*history)("sum_svc error on handle to SUMPUT2 on %s\n", server_name);
01216 sleep(1);
01217 clput = clnt_create(server_name, SUMPUT2, SUMPUTV, "tcp");
01218 if(!clput) {
01219 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT2");
01220 (*history)("sum_svc error on handle to SUMPUT2 on %s\n", server_name);
01221 return(NULL);
01222 }
01223 }
01224 sumptr->clput2 = clput;
01225 #endif
01226 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01227 clinfo = clnt_create(server_name, SUMINFO2, SUMINFOV, "tcp");
01228 if(!clinfo) {
01229 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO2");
01230 (*history)("sum_svc error on handle to SUMINFO2 on %s\n", server_name);
01231 sleep(1);
01232 clinfo = clnt_create(server_name, SUMINFO2, SUMINFOV, "tcp");
01233 if(!clinfo) {
01234 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO2");
01235 (*history)("sum_svc error on handle to SUMINFO2 on %s\n", server_name);
01236 return(NULL);
01237 }
01238 }
01239 sumptr->clinfo2 = clinfo;
01240 #endif
01241 break;
01242 case 3:
01243 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01244 sumptr->clopen3 = clopen3;
01245 #endif
01246 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01247 clalloc = clnt_create(server_name, SUMALLOC3, SUMALLOCV, "tcp");
01248 if(!clalloc) {
01249 for(i=0; i < 4; i++) {
01250 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC3. Retry..");
01251 (*history)("Going to retry in 1 sec. i=%d\n", i);
01252 sleep(1);
01253 clalloc = clnt_create(server_name, SUMALLOC3, SUMALLOCV, "tcp");
01254 if(clalloc) { break; }
01255 }
01256 if(!clalloc) {
01257 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC3");
01258 (*history)("sum_svc error on handle to SUMALLOC3 on %s\n", server_name);
01259 return(NULL);
01260 }
01261 }
01262 sumptr->clalloc3 = clalloc;
01263 #endif
01264 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01265 clget = clnt_create(server_name, SUMGET3, SUMGETV, "tcp");
01266 if(!clget) {
01267 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET3");
01268 (*history)("sum_svc error on handle to SUMGET3 on %s\n", server_name);
01269 sleep(1);
01270 clget = clnt_create(server_name, SUMGET3, SUMGETV, "tcp");
01271 if(!clget) {
01272 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET3");
01273 (*history)("sum_svc error on handle to SUMGET3 on %s\n", server_name);
01274 return(NULL);
01275 }
01276 }
01277 sumptr->clget3 = clget;
01278 #endif
01279 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01280 clput = clnt_create(server_name, SUMPUT3, SUMPUTV, "tcp");
01281 if(!clput) {
01282 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT3");
01283 (*history)("sum_svc error on handle to SUMPUT3 on %s\n", server_name);
01284 sleep(1);
01285 clput = clnt_create(server_name, SUMPUT3, SUMPUTV, "tcp");
01286 if(!clput) {
01287 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT3");
01288 (*history)("sum_svc error on handle to SUMPUT3 on %s\n", server_name);
01289 return(NULL);
01290 }
01291 }
01292 sumptr->clput3 = clput;
01293 #endif
01294 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01295 clinfo = clnt_create(server_name, SUMINFO3, SUMINFOV, "tcp");
01296 if(!clinfo) {
01297 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO3");
01298 (*history)("sum_svc error on handle to SUMINFO3 on %s\n", server_name);
01299 sleep(1);
01300 clinfo = clnt_create(server_name, SUMINFO3, SUMINFOV, "tcp");
01301 if(!clinfo) {
01302 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO3");
01303 (*history)("sum_svc error on handle to SUMINFO3 on %s\n", server_name);
01304 return(NULL);
01305 }
01306 }
01307 sumptr->clinfo3 = clinfo;
01308 #endif
01309 break;
01310 case 4:
01311 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01312 sumptr->clopen4 = clopen4;
01313 #endif
01314 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01315 clalloc = clnt_create(server_name, SUMALLOC4, SUMALLOCV, "tcp");
01316 if(!clalloc) {
01317 for(i=0; i < 4; i++) {
01318 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC4. Retry..");
01319 (*history)("Going to retry in 1 sec. i=%d\n", i);
01320 sleep(1);
01321 clalloc = clnt_create(server_name, SUMALLOC4, SUMALLOCV, "tcp");
01322 if(clalloc) { break; }
01323 }
01324 if(!clalloc) {
01325 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC4");
01326 (*history)("sum_svc error on handle to SUMALLOC4 on %s\n", server_name);
01327 return(NULL);
01328 }
01329 }
01330 sumptr->clalloc4 = clalloc;
01331 #endif
01332 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01333 clget = clnt_create(server_name, SUMGET4, SUMGETV, "tcp");
01334 if(!clget) {
01335 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET4");
01336 (*history)("sum_svc error on handle to SUMGET4 on %s\n", server_name);
01337 sleep(1);
01338 clget = clnt_create(server_name, SUMGET4, SUMGETV, "tcp");
01339 if(!clget) {
01340 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET4");
01341 (*history)("sum_svc error on handle to SUMGET4 on %s\n", server_name);
01342 return(NULL);
01343 }
01344 }
01345 sumptr->clget4 = clget;
01346 #endif
01347 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01348 clput = clnt_create(server_name, SUMPUT4, SUMPUTV, "tcp");
01349 if(!clput) {
01350 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT4");
01351 (*history)("sum_svc error on handle to SUMPUT4 on %s\n", server_name);
01352 sleep(1);
01353 clput = clnt_create(server_name, SUMPUT4, SUMPUTV, "tcp");
01354 if(!clput) {
01355 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT4");
01356 (*history)("sum_svc error on handle to SUMPUT4 on %s\n", server_name);
01357 return(NULL);
01358 }
01359 }
01360 sumptr->clput4 = clput;
01361 #endif
01362 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01363 clinfo = clnt_create(server_name, SUMINFO4, SUMINFOV, "tcp");
01364 if(!clinfo) {
01365 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO4");
01366 (*history)("sum_svc error on handle to SUMINFO4 on %s\n", server_name);
01367 sleep(1);
01368 clinfo = clnt_create(server_name, SUMINFO4, SUMINFOV, "tcp");
01369 if(!clinfo) {
01370 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO4");
01371 (*history)("sum_svc error on handle to SUMINFO4 on %s\n", server_name);
01372 return(NULL);
01373 }
01374 }
01375 sumptr->clinfo4 = clinfo;
01376 #endif
01377 break;
01378 case 5:
01379 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01380 sumptr->clopen5 = clopen5;
01381 #endif
01382 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01383 clalloc = clnt_create(server_name, SUMALLOC5, SUMALLOCV, "tcp");
01384 if(!clalloc) {
01385 for(i=0; i < 4; i++) {
01386 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC5. Retry..");
01387 (*history)("Going to retry in 1 sec. i=%d\n", i);
01388 sleep(1);
01389 clalloc = clnt_create(server_name, SUMALLOC5, SUMALLOCV, "tcp");
01390 if(clalloc) { break; }
01391 }
01392 if(!clalloc) {
01393 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC5");
01394 (*history)("sum_svc error on handle to SUMALLOC5 on %s\n", server_name);
01395 return(NULL);
01396 }
01397 }
01398 sumptr->clalloc5 = clalloc;
01399 #endif
01400 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01401 clget = clnt_create(server_name, SUMGET5, SUMGETV, "tcp");
01402 if(!clget) {
01403 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET5");
01404 (*history)("sum_svc error on handle to SUMGET5 on %s\n", server_name);
01405 sleep(1);
01406 clget = clnt_create(server_name, SUMGET5, SUMGETV, "tcp");
01407 if(!clget) {
01408 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET5");
01409 (*history)("sum_svc error on handle to SUMGET5 on %s\n", server_name);
01410 return(NULL);
01411 }
01412 }
01413 sumptr->clget5 = clget;
01414 #endif
01415 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01416 clput = clnt_create(server_name, SUMPUT5, SUMPUTV, "tcp");
01417 if(!clput) {
01418 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT5");
01419 (*history)("sum_svc error on handle to SUMPUT5 on %s\n", server_name);
01420 sleep(1);
01421 clput = clnt_create(server_name, SUMPUT5, SUMPUTV, "tcp");
01422 if(!clput) {
01423 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT5");
01424 (*history)("sum_svc error on handle to SUMPUT5 on %s\n", server_name);
01425 return(NULL);
01426 }
01427 }
01428 sumptr->clput5 = clput;
01429 #endif
01430 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01431 clinfo = clnt_create(server_name, SUMINFO5, SUMINFOV, "tcp");
01432 if(!clinfo) {
01433 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO5");
01434 (*history)("sum_svc error on handle to SUMINFO5 on %s\n", server_name);
01435 sleep(1);
01436 clinfo = clnt_create(server_name, SUMINFO5, SUMINFOV, "tcp");
01437 if(!clinfo) {
01438 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO5");
01439 (*history)("sum_svc error on handle to SUMINFO5 on %s\n", server_name);
01440 return(NULL);
01441 }
01442 }
01443 sumptr->clinfo5 = clinfo;
01444 #endif
01445 break;
01446 case 6:
01447 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01448 sumptr->clopen6 = clopen6;
01449 #endif
01450 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01451 clalloc = clnt_create(server_name, SUMALLOC6, SUMALLOCV, "tcp");
01452 if(!clalloc) {
01453 for(i=0; i < 4; i++) {
01454 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC6. Retry..");
01455 (*history)("Going to retry in 1 sec. i=%d\n", i);
01456 sleep(1);
01457 clalloc = clnt_create(server_name, SUMALLOC6, SUMALLOCV, "tcp");
01458 if(clalloc) { break; }
01459 }
01460 if(!clalloc) {
01461 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC6");
01462 (*history)("sum_svc error on handle to SUMALLOC6 on %s\n", server_name);
01463 return(NULL);
01464 }
01465 }
01466 sumptr->clalloc6 = clalloc;
01467 #endif
01468 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01469 clget = clnt_create(server_name, SUMGET6, SUMGETV, "tcp");
01470 if(!clget) {
01471 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET6");
01472 (*history)("sum_svc error on handle to SUMGET6 on %s\n", server_name);
01473 sleep(1);
01474 clget = clnt_create(server_name, SUMGET6, SUMGETV, "tcp");
01475 if(!clget) {
01476 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET6");
01477 (*history)("sum_svc error on handle to SUMGET6 on %s\n", server_name);
01478 return(NULL);
01479 }
01480 }
01481 sumptr->clget6 = clget;
01482 #endif
01483 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01484 clput = clnt_create(server_name, SUMPUT6, SUMPUTV, "tcp");
01485 if(!clput) {
01486 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT6");
01487 (*history)("sum_svc error on handle to SUMPUT6 on %s\n", server_name);
01488 sleep(1);
01489 clput = clnt_create(server_name, SUMPUT6, SUMPUTV, "tcp");
01490 if(!clput) {
01491 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT6");
01492 (*history)("sum_svc error on handle to SUMPUT6 on %s\n", server_name);
01493 return(NULL);
01494 }
01495 }
01496 sumptr->clput6 = clput;
01497 #endif
01498 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01499 clinfo = clnt_create(server_name, SUMINFO6, SUMINFOV, "tcp");
01500 if(!clinfo) {
01501 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO6");
01502 (*history)("sum_svc error on handle to SUMINFO6 on %s\n", server_name);
01503 sleep(1);
01504 clinfo = clnt_create(server_name, SUMINFO6, SUMINFOV, "tcp");
01505 if(!clinfo) {
01506 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO6");
01507 (*history)("sum_svc error on handle to SUMINFO6 on %s\n", server_name);
01508 return(NULL);
01509 }
01510 }
01511 sumptr->clinfo6 = clinfo;
01512 #endif
01513 break;
01514 case 7:
01515 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01516 sumptr->clopen7 = clopen7;
01517 #endif
01518 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01519 clalloc = clnt_create(server_name, SUMALLOC7, SUMALLOCV, "tcp");
01520 if(!clalloc) {
01521 for(i=0; i < 4; i++) {
01522 clnt_pcreateerror("Can't get client handle to sum_svc SUMALLOC7. Retry..");
01523 (*history)("Going to retry in 1 sec. i=%d\n", i);
01524 sleep(1);
01525 clalloc = clnt_create(server_name, SUMALLOC7, SUMALLOCV, "tcp");
01526 if(clalloc) { break; }
01527 }
01528 if(!clalloc) {
01529 clnt_pcreateerror("Can't get retry client handle to sum_svc SUMALLOC7");
01530 (*history)("sum_svc error on handle to SUMALLOC7 on %s\n", server_name);
01531 return(NULL);
01532 }
01533 }
01534 sumptr->clalloc7 = clalloc;
01535 #endif
01536 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01537 clget = clnt_create(server_name, SUMGET7, SUMGETV, "tcp");
01538 if(!clget) {
01539 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET7");
01540 (*history)("sum_svc error on handle to SUMGET7 on %s\n", server_name);
01541 sleep(1);
01542 clget = clnt_create(server_name, SUMGET7, SUMGETV, "tcp");
01543 if(!clget) {
01544 clnt_pcreateerror("Can't get client handle to sum_svc SUMGET7");
01545 (*history)("sum_svc error on handle to SUMGET7 on %s\n", server_name);
01546 return(NULL);
01547 }
01548 }
01549 sumptr->clget7 = clget;
01550 #endif
01551 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01552 clput = clnt_create(server_name, SUMPUT7, SUMPUTV, "tcp");
01553 if(!clput) {
01554 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT7");
01555 (*history)("sum_svc error on handle to SUMPUT7 on %s\n", server_name);
01556 sleep(1);
01557 clput = clnt_create(server_name, SUMPUT7, SUMPUTV, "tcp");
01558 if(!clput) {
01559 clnt_pcreateerror("Can't get client handle to sum_svc SUMPUT7");
01560 (*history)("sum_svc error on handle to SUMPUT7 on %s\n", server_name);
01561 return(NULL);
01562 }
01563 }
01564 sumptr->clput7 = clput;
01565 #endif
01566 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01567 clinfo = clnt_create(server_name, SUMINFO7, SUMINFOV, "tcp");
01568 if(!clinfo) {
01569 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO7");
01570 (*history)("sum_svc error on handle to SUMINFO7 on %s\n", server_name);
01571 sleep(1);
01572 clinfo = clnt_create(server_name, SUMINFO7, SUMINFOV, "tcp");
01573 if(!clinfo) {
01574 clnt_pcreateerror("Can't get client handle to sum_svc SUMINFO7");
01575 (*history)("sum_svc error on handle to SUMINFO7 on %s\n", server_name);
01576 return(NULL);
01577 }
01578 }
01579 sumptr->clinfo7 = clinfo;
01580 #endif
01581 break;
01582 }
01583 }
01584
01585 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_DELETESUS) || !SUMS_USEMTSUMS_DELETESUS)
01586 if(numSUM == 1)
01587 {
01588 cldelser = cl;
01589 }
01590 else
01591 {
01592 cldelser = clnt_create(server_name, SUMDELSER, SUMDELSERV, "tcp");
01593 if(!cldelser)
01594 {
01595 clnt_pcreateerror("Can't get client handle to sum_svc SUMDELSER");
01596 (*history)("sum_svc error on handle to SUMDELSER on %s\n", server_name);
01597 sleep(1);
01598 cldelser = clnt_create(server_name, SUMDELSER, SUMDELSERV, "tcp");
01599 if(!cldelser)
01600 {
01601 clnt_pcreateerror("Can't get client handle to sum_svc SUMDELSER");
01602 (*history)("sum_svc error on handle to SUMDELSER on %s\n", server_name);
01603 return(NULL);
01604 }
01605 }
01606 }
01607
01608 sumptr->cldelser = cldelser;
01609 #endif
01610
01611 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01612 sumptr->uid = sumid;
01613 #endif
01614 sumptr->username = username;
01615 sumptr->tdays = 0;
01616 sumptr->debugflg = 0;
01617 sumptr->storeset = JSOC;
01618 sumptr->numSUM = numSUM;
01619 sumptr->dsname = "<none>";
01620 sumptr->history_comment = NULL;
01621
01622
01623 sumptr->dsix_ptr = (uint64_t *)malloc(sizeof(uint64_t) * SUMARRAYSZ);
01624 sumptr->wd = (char **)calloc(SUMARRAYSZ, sizeof(char *));
01625
01626 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01627 setsumopened(&sumopened_hdr, sumid, sumptr, username);
01628 #endif
01629 if (klist)
01630 {
01631 freekeylist(&klist);
01632 klist = NULL;
01633 }
01634 return(sumptr);
01635 }
01636
01637
01638
01639
01640
01641 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01642 int sumsopenClose(SUM_t *sums, int (*history)(const char *fmt, ...))
01643 #else
01644 int sumsopenClose(SUM_t *sums, MTSums_CallType_t callType, int (*history)(const char *fmt, ...))
01645 #endif
01646 {
01647 KEY *klist = NULL;
01648 char *call_err;
01649 static char res;
01650 enum clnt_stat status;
01651 int i, stat;
01652 int errflg = 0;
01653
01654 if(sums->debugflg) {
01655 (*history)("SUM_close() call: uid = %lu\n", sums->uid);
01656 }
01657
01658 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01659 klist = newkeylist();
01660 setkey_uint64(&klist, "uid", sums->uid);
01661 setkey_int(&klist, "DEBUGFLG", sums->debugflg);
01662 setkey_int(&klist, "REQCODE", CLOSEDO);
01663 setkey_str(&klist, "USER", sums->username);
01664
01665 if(sums->mode & TAPERDON) {
01666 if(!taperdon_cleared) {
01667 setkey_int(&klist, "TAPERDACTIVE", 1);
01668 }
01669 }
01670 bzero((char *)&res, sizeof(res));
01671
01672 clprev = sums->clclose;
01673 status = clnt_call(sums->clclose, CLOSEDO, (xdrproc_t)xdr_Rkey, (char *)klist,
01674 (xdrproc_t)xdr_void, &res, TIMEOUT);
01675
01676
01677
01678
01679
01680 if(status != RPC_SUCCESS) {
01681 if(status != RPC_TIMEDOUT) {
01682 call_err = clnt_sperror(sums->clopen, "Err clnt_call for CLOSEDO");
01683 (*history)("%s %d %s\n", datestring(), status, call_err);
01684 errflg = 1;
01685 }
01686 }
01687
01688 stat = getmsgimmed();
01689
01690 (void)pmap_unset(RESPPROG, sums->uid);
01691 remsumopened(&sumopened_hdr, sums->uid);
01692
01693
01694 #else
01695
01696 int err;
01697
01698
01699 err = callMTSums(sums, callType, (JSONIZER_DATA_t *)NULL, history);
01700
01701 errflg = (err == 1);
01702
01703 if (gMTCallMap)
01704 {
01705 hcon_destroy(&gMTCallMap);
01706 }
01707 #endif
01708
01709 if(numSUM == 1) {
01710 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
01711 clnt_destroy(sums->cl);
01712 #endif
01713 }
01714 else {
01715 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
01716 clnt_destroy(sums->cl);
01717 #endif
01718 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01719 if(sums->clopen) clnt_destroy(sums->clopen);
01720 if(sums->clopen1) clnt_destroy(sums->clopen1);
01721 if(sums->clopen2) clnt_destroy(sums->clopen2);
01722 if(sums->clopen3) clnt_destroy(sums->clopen3);
01723 if(sums->clopen4) clnt_destroy(sums->clopen4);
01724 if(sums->clopen5) clnt_destroy(sums->clopen5);
01725 if(sums->clopen6) clnt_destroy(sums->clopen6);
01726 if(sums->clopen7) clnt_destroy(sums->clopen7);
01727 #endif
01728 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
01729 if(sums->clalloc) clnt_destroy(sums->clalloc);
01730 if(sums->clalloc1) clnt_destroy(sums->clalloc1);
01731 if(sums->clalloc2) clnt_destroy(sums->clalloc2);
01732 if(sums->clalloc3) clnt_destroy(sums->clalloc3);
01733 if(sums->clalloc4) clnt_destroy(sums->clalloc4);
01734 if(sums->clalloc5) clnt_destroy(sums->clalloc5);
01735 if(sums->clalloc6) clnt_destroy(sums->clalloc6);
01736 if(sums->clalloc7) clnt_destroy(sums->clalloc7);
01737 #endif
01738 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
01739 if(sums->clget) clnt_destroy(sums->clget);
01740 if(sums->clget1) clnt_destroy(sums->clget1);
01741 if(sums->clget2) clnt_destroy(sums->clget2);
01742 if(sums->clget3) clnt_destroy(sums->clget3);
01743 if(sums->clget4) clnt_destroy(sums->clget4);
01744 if(sums->clget5) clnt_destroy(sums->clget5);
01745 if(sums->clget6) clnt_destroy(sums->clget6);
01746 if(sums->clget7) clnt_destroy(sums->clget7);
01747 #endif
01748 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
01749 if(sums->clput) clnt_destroy(sums->clput);
01750 if(sums->clput1) clnt_destroy(sums->clput1);
01751 if(sums->clput2) clnt_destroy(sums->clput2);
01752 if(sums->clput3) clnt_destroy(sums->clput3);
01753 if(sums->clput4) clnt_destroy(sums->clput4);
01754 if(sums->clput5) clnt_destroy(sums->clput5);
01755 if(sums->clput6) clnt_destroy(sums->clput6);
01756 if(sums->clput7) clnt_destroy(sums->clput7);
01757 #endif
01758 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
01759 if(sums->clinfo) clnt_destroy(sums->clinfo);
01760 if(sums->clinfo1) clnt_destroy(sums->clinfo1);
01761 if(sums->clinfo2) clnt_destroy(sums->clinfo2);
01762 if(sums->clinfo3) clnt_destroy(sums->clinfo3);
01763 if(sums->clinfo4) clnt_destroy(sums->clinfo4);
01764 if(sums->clinfo5) clnt_destroy(sums->clinfo5);
01765 if(sums->clinfo6) clnt_destroy(sums->clinfo6);
01766 if(sums->clinfo7) clnt_destroy(sums->clinfo7);
01767 #endif
01768 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_DELETESUS) || !SUMS_USEMTSUMS_DELETESUS)
01769 if(sums->cldelser) clnt_destroy(sums->cldelser);
01770 #endif
01771 }
01772
01773 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
01774 for(i=0; i < MAXSUMOPEN; i++) {
01775 if(transpid[i] == sums->uid) {
01776 svc_destroy(transp[i]);
01777 --numopened;
01778 break;
01779 }
01780 }
01781 #endif
01782
01783 if (sums->dsix_ptr)
01784 {
01785 free(sums->dsix_ptr);
01786 sums->dsix_ptr = NULL;
01787 }
01788
01789 if (sums->wd)
01790 {
01791 free(sums->wd);
01792 sums->wd = NULL;
01793 }
01794
01795 if(sums->sinfo) free(sums->sinfo);
01796 free(sums);
01797 if (klist)
01798 {
01799 freekeylist(&klist);
01800 klist = NULL;
01801 }
01802 if(errflg) return(4);
01803 return(0);
01804 }
01805
01806
01807 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
01808
01809
01810
01811
01812
01813
01814
01815
01816
01817
01818
01819
01820
01821 static int sumsopenNopRPC(SUM_t *sum, int (*history)(const char *fmt, ...))
01822 {
01823
01824 struct timeval NOPTIMEOUT = { 10, 0 };
01825 KEY *klist;
01826 char *call_err;
01827 int ans;
01828 enum clnt_stat status;
01829 int i, stat;
01830 int errflg = 0;
01831
01832 if(sum->debugflg) {
01833 (*history)("SUM_nop() call: uid = %lu\n", sum->uid);
01834 }
01835 klist = newkeylist();
01836 setkey_uint64(&klist, "uid", sum->uid);
01837 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
01838 setkey_int(&klist, "REQCODE", CLOSEDO);
01839 setkey_str(&klist, "USER", sum->username);
01840 status = clnt_call(clprev, NOPDO, (xdrproc_t)xdr_Rkey, (char *)klist,
01841 (xdrproc_t)xdr_void, (char *)&ans, NOPTIMEOUT);
01842 ans = (int)ans;
01843 if(ans == 5) {
01844 return(ans);
01845 }
01846
01847
01848
01849 if(status != RPC_SUCCESS) {
01850 call_err = clnt_sperror(clprev, "Err clnt_call for NOPDO");
01851 (*history)("%s %s status=%d\n", datestring(), call_err, status);
01852 freekeylist(&klist);
01853 if(status != RPC_TIMEDOUT) return (4);
01854 else return (1);
01855 }
01856
01857 stat = getmsgimmed();
01858 freekeylist(&klist);
01859 return(ans);
01860 }
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870
01871
01872
01873
01874
01875
01876
01877
01878
01879
01880
01881
01882 static int sumsopenPollRPC(SUM_t *sum)
01883 {
01884 int stat, xmode;
01885
01886 stat = getanymsg(0);
01887 if(stat == RPCMSG) {
01888
01889
01890
01891 taperdon_cleared = 1;
01892 return(0);
01893 }
01894 else return(stat);
01895 }
01896 #endif
01897
01898 #if defined(SUMS_USEMTSUMS) && SUMS_USEMTSUMS
01899
01900
01901
01902
01903
01904
01905 static int sumsopenNopMT(SUM_t *sums, int (*history)(const char *fmt, ...))
01906 {
01907 int err;
01908
01909
01910 err = callMTSums(sums, kMTSums_CallType_Ping, NULL, history);
01911
01912 if (err == 0)
01913 {
01914 return 0;
01915 }
01916 else if (err == 1)
01917 {
01918 return 4;
01919 }
01920 else if (err == 2)
01921 {
01922 return 1;
01923 }
01924 else
01925 {
01926 (*history)("Unknown SUMS return code %d.\n", err);
01927 return 4;
01928 }
01929 }
01930
01931
01932
01933
01934
01935
01936 static int sumsopenPollMT(SUM_t *sums)
01937 {
01938 int err;
01939
01940
01941 err = callMTSums(sums, kMTSums_CallType_Poll, NULL, printkerr);
01942
01943 if (err == 0)
01944 {
01945
01946 return 0;
01947 }
01948 else if (err == 1)
01949 {
01950
01951 return ERRMESS;
01952 }
01953 else if (err == 2)
01954 {
01955
01956 return TIMEOUTMSG;
01957 }
01958 else if (err == RESULT_PEND)
01959 {
01960
01961 return TIMEOUTMSG;
01962 }
01963 else
01964 {
01965 printkerr("Unknown SUMS return code %d.\n", err);
01966 return ERRMESS;
01967 }
01968 }
01969 #endif
01970
01971 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
01972
01973
01974 SUMID_t sumrpcopen_1(KEY *argp, CLIENT *clnt, int (*history)(const char *fmt, ...))
01975 {
01976 char *call_err;
01977 enum clnt_stat status;
01978 SUMID_t suidback;
01979 SVCXPRT *xtp;
01980
01981 clprev = clnt;
01982 clclose = clnt;
01983 status = clnt_call(clnt, OPENDO, (xdrproc_t)xdr_Rkey, (char *)argp,
01984 (xdrproc_t)xdr_uint32_t, (char *)&suidback, TIMEOUT);
01985 suidback = (SUMID_t)suidback;
01986
01987
01988
01989 if(status != RPC_SUCCESS) {
01990 call_err = clnt_sperror(clnt, "Err clnt_call for OPENDO");
01991 (*history)("%s %s status=%d\n", datestring(), call_err, status);
01992 return (0);
01993 }
01994
01995
01996
01997
01998 if(suidback) {
01999 (void)pmap_unset(RESPPROG, suidback);
02000 xtp = (SVCXPRT *)svctcp_create(RPC_ANYSOCK, 0, 0);
02001 if (xtp == NULL) {
02002 (*history)("cannot create tcp service in sumrpcopen_1() for responses\n");
02003 return(0);
02004 }
02005
02006
02007
02008
02009
02010
02011
02012 if (!svc_register(xtp, RESPPROG, suidback, respd, IPPROTO_TCP)) {
02013 (*history)("unable to register RESPPROG in sumrpcopen_1()\n");
02014 return(0);
02015 }
02016 transp[numopened] = xtp;
02017 transpid[numopened] = suidback;
02018 }
02019 return (suidback);
02020 }
02021 #endif
02022
02023
02024 #if defined(SUMS_USEMTSUMS) && SUMS_USEMTSUMS
02025 static cJSON *unjsonizeResponseParse(const char *msg, int (*history)(const char *fmt, ...))
02026 {
02027 cJSON *response = NULL;
02028
02029 response = cJSON_Parse(msg);
02030
02031 if (!response)
02032 {
02033 (*history)("The SUMINFO response is not valid JSON.");
02034 }
02035
02036 return response;
02037 }
02038
02039 static int unjsonizeResponseCheckStatus(cJSON *response, int (*history)(const char *fmt, ...))
02040 {
02041 int err = 0;
02042 cJSON *value = NULL;
02043
02044 err = ((value = cJSON_GetObjectItem(response, "status")) == NULL);
02045 if (!err)
02046 {
02047 err = (value->type != cJSON_String);
02048 }
02049
02050 if (err)
02051 {
02052 (*history)("Invalid 'status' attribute.\n");
02053 }
02054 else
02055 {
02056 err = (strcasecmp(value->valuestring, "ok") != 0);
02057 if (err)
02058 {
02059 (*history)("The SUMS service failed with status %s.\n", value->valuestring);
02060
02061 if ((value = cJSON_GetObjectItem(response, "errmsg")) != NULL)
02062 {
02063 if (value->type == cJSON_String)
02064 {
02065 (*history)("Error message: %s.\n", value->valuestring);
02066 }
02067 }
02068 }
02069 }
02070
02071 return err;
02072 }
02073
02074 #if defined(SUMS_USEMTSUMS_CONNECTION) && SUMS_USEMTSUMS_CONNECTION
02075
02076
02077
02078
02079
02080
02081
02082 static int jsonizeSumopenRequest(char **json, int (*history)(const char *fmt, ...))
02083 {
02084 cJSON *root = NULL;
02085 cJSON *jsonValue = NULL;
02086 int err;
02087
02088 root = NULL;
02089 err = 0;
02090
02091 if (!json)
02092 {
02093 (*history)("Invalid argument(s) to 'jsonizeSumopenRequest'.\n");
02094 err = 1;
02095 }
02096
02097 if (!err)
02098 {
02099 err = ((root = cJSON_CreateObject()) == NULL);
02100
02101 if (err)
02102 {
02103 (*history)("Out of memory calling cJSON_CreateObject().\n");
02104 }
02105 }
02106
02107 if (!err)
02108 {
02109
02110 err = ((jsonValue = cJSON_CreateString("open")) == NULL);
02111
02112 if (err)
02113 {
02114 (*history)("Out of memory calling cJSON_CreateString().\n");
02115 }
02116 }
02117
02118 if (!err)
02119 {
02120 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
02121 }
02122
02123 if (!err)
02124 {
02125 *json = cJSON_Print(root);
02126 }
02127
02128 if (root)
02129 {
02130 cJSON_Delete(root);
02131 }
02132
02133 return err;
02134 }
02135
02136
02137
02138
02139
02140
02141
02142
02143
02144
02145
02146
02147
02148
02149
02150
02151
02152
02153
02154
02155
02156
02157
02158
02159
02160
02161
02162
02163
02164 static int unjsonizeSumopenResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
02165 {
02166 cJSON *response = NULL;
02167 cJSON *jsonValue = NULL;
02168 SUMID_t sumsid;
02169 int err;
02170
02171 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
02172
02173 if (!err)
02174 {
02175 err = unjsonizeResponseCheckStatus(response, history);
02176 }
02177
02178 if (!err)
02179 {
02180 err = ((jsonValue = cJSON_GetObjectItem(response, "sessionid")) == NULL);
02181 if (err)
02182 {
02183 (*history)("Unable to unjsonize sessionid.\n");
02184 }
02185 }
02186
02187 if (!err)
02188 {
02189 err = (jsonValue->type != cJSON_String);
02190 if (err)
02191 {
02192 (*history)("Unexpected data type for sessionid.");
02193 }
02194 }
02195
02196 if (!err)
02197 {
02198
02199
02200
02201
02202
02203 uint64_t uid;
02204
02205 err = (sscanf(jsonValue->valuestring, "%llx", &uid) != 1);
02206
02207
02208 sums->uid = (uint32_t)uid;
02209 }
02210
02211 if (response)
02212 {
02213 cJSON_Delete(response);
02214 }
02215
02216 return err;
02217 }
02218
02219
02220
02221
02222
02223
02224
02225 static int jsonizeSumcloseRequest(SUM_t *sums, SUMID_t sessionid, char **json, int (*history)(const char *fmt, ...))
02226 {
02227 cJSON *root = NULL;
02228 cJSON *jsonValue = NULL;
02229 int err;
02230 char numBuf[64];
02231
02232 root = NULL;
02233 err = (json == NULL);
02234
02235 if (err)
02236 {
02237 (*history)("Invalid argument(s) to 'jsonizeSumcloseRequest'.\n");
02238 }
02239 else
02240 {
02241 err = ((root = cJSON_CreateObject()) == NULL);
02242 if (err)
02243 {
02244 (*history)("Out of memory calling cJSON_CreateObject().\n");
02245 }
02246 }
02247
02248 if (!err)
02249 {
02250
02251 err = ((jsonValue = cJSON_CreateString("close")) == NULL);
02252
02253 if (err)
02254 {
02255 (*history)("Out of memory calling cJSON_CreateString().\n");
02256 }
02257 }
02258
02259 if (!err)
02260 {
02261 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
02262 }
02263
02264 if (!err)
02265 {
02266
02267
02268
02269
02270
02271
02272 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
02273 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
02274
02275 if (err)
02276 {
02277 (*history)("Out of memory calling cJSON_CreateNumber().\n");
02278 }
02279 }
02280
02281 if (!err)
02282 {
02283 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
02284 }
02285
02286 if (!err)
02287 {
02288 *json = cJSON_Print(root);
02289 }
02290
02291 if (root)
02292 {
02293 cJSON_Delete(root);
02294 }
02295
02296 return err;
02297 }
02298
02299
02300
02301
02302
02303
02304
02305 static int unjsonizeSumcloseResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
02306 {
02307
02308
02309
02310 int err;
02311 cJSON *response = NULL;
02312
02313 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
02314
02315 if (!err)
02316 {
02317 err = unjsonizeResponseCheckStatus(response, history);
02318 }
02319
02320 if (response)
02321 {
02322 cJSON_Delete(response);
02323 }
02324
02325 return err;
02326 }
02327
02328
02329
02330
02331
02332
02333
02334 static int jsonizeSumrollbackRequest(SUM_t *sums, SUMID_t sessionid, char **json, int (*history)(const char *fmt, ...))
02335 {
02336 cJSON *root = NULL;
02337 cJSON *jsonValue = NULL;
02338 int err;
02339 char numBuf[64];
02340
02341 root = NULL;
02342 err = (json == NULL);
02343
02344 if (err)
02345 {
02346 (*history)("Invalid argument(s) to 'jsonizeSumrollbackRequest'.\n");
02347 }
02348 else
02349 {
02350 err = ((root = cJSON_CreateObject()) == NULL);
02351 if (err)
02352 {
02353 (*history)("Out of memory calling cJSON_CreateObject().\n");
02354 }
02355 }
02356
02357 if (!err)
02358 {
02359
02360 err = ((jsonValue = cJSON_CreateString("rollback")) == NULL);
02361
02362 if (err)
02363 {
02364 (*history)("Out of memory calling cJSON_CreateString().\n");
02365 }
02366 }
02367
02368 if (!err)
02369 {
02370 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
02371 }
02372
02373 if (!err)
02374 {
02375
02376
02377
02378
02379
02380
02381 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
02382 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
02383
02384 if (err)
02385 {
02386 (*history)("Out of memory calling cJSON_CreateNumber().\n");
02387 }
02388 }
02389
02390 if (!err)
02391 {
02392 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
02393 }
02394
02395 if (!err)
02396 {
02397 *json = cJSON_Print(root);
02398 }
02399
02400 if (root)
02401 {
02402 cJSON_Delete(root);
02403 }
02404
02405 return err;
02406 }
02407
02408
02409
02410
02411
02412
02413 static int unjsonizeSumrollbackResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
02414 {
02415
02416
02417
02418 int err;
02419 cJSON *response = NULL;
02420
02421 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
02422
02423 if (!err)
02424 {
02425 err = unjsonizeResponseCheckStatus(response, history);
02426 }
02427
02428 if (response)
02429 {
02430 cJSON_Delete(response);
02431 }
02432
02433 return err;
02434 }
02435 #endif
02436
02437 #if defined(SUMS_USEMTSUMS_INFO) && SUMS_USEMTSUMS_INFO
02438
02439
02440
02441
02442
02443
02444
02445 static int jsonizeSuminfoRequest(SUM_t *sums, SUMID_t sessionid, uint64_t *sunums, size_t nSus, char **json, int (*history)(const char *fmt, ...))
02446 {
02447 int isu;
02448 uint64_t sunum;
02449 char numBuf[64];
02450 cJSON *root = NULL;
02451 cJSON *jsonValue = NULL;
02452 cJSON *jsonArrayElement = NULL;
02453 int err;
02454
02455 err = (!sums || !sunums || nSus == 0 || !json);
02456
02457 if (err)
02458 {
02459 (*history)("Invalid argument(s) to 'jsonizeRequest'.\n");
02460 }
02461 else
02462 {
02463 err = ((root = cJSON_CreateObject()) == NULL);
02464 }
02465
02466 if (err)
02467 {
02468 (*history)("Out of memory calling cJSON_CreateObject().\n");
02469 }
02470 else
02471 {
02472 err = ((jsonValue = cJSON_CreateString("info")) == NULL);
02473 }
02474
02475 if (err)
02476 {
02477 (*history)("Out of memory calling cJSON_CreateString().\n");
02478 }
02479 else
02480 {
02481
02482 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
02483
02484 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
02485 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
02486 }
02487
02488 if (err)
02489 {
02490 (*history)("Out of memory calling cJSON_CreateNumber().\n");
02491 }
02492 else
02493 {
02494 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
02495 err = ((jsonValue = cJSON_CreateArray()) == NULL);
02496 }
02497
02498 if (err)
02499 {
02500 (*history)("Out of memory calling cJSON_CreateArray().\n");
02501 }
02502 else
02503 {
02504 for (isu = 0; isu < nSus; isu++)
02505 {
02506 sunum = sunums[isu];
02507
02508
02509
02510
02511
02512 snprintf(numBuf, sizeof(numBuf), "%llx", sunum);
02513
02514 err = ((jsonArrayElement = cJSON_CreateString(numBuf)) == NULL);
02515 if (err)
02516 {
02517 (*history)("Out of memory calling cJSON_CreateString().\n");
02518 break;
02519 }
02520
02521 cJSON_AddItemToArray(jsonValue, jsonArrayElement);
02522 }
02523 }
02524
02525 if (!err)
02526 {
02527
02528 cJSON_AddItemToObjectCS(root, "sus", jsonValue);
02529
02530 *json = cJSON_Print(root);
02531 }
02532
02533 if (root)
02534 {
02535 cJSON_Delete(root);
02536 }
02537
02538 return err;
02539 }
02540
02541
02542
02543
02544
02545
02546
02547
02548
02549
02550
02551
02552
02553
02554
02555
02556
02557
02558
02559
02560
02561
02562
02563
02564
02565
02566
02567
02568
02569
02570
02571
02572
02573
02574
02575
02576
02577
02578
02579
02580
02581
02582
02583
02584
02585
02586
02587
02588
02589
02590
02591
02592
02593
02594 static int unjsonizeSuminfoResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
02595 {
02596 int err;
02597 cJSON *response = NULL;
02598 cJSON *jsonArray = NULL;
02599 cJSON *jsonArrayElement = NULL;
02600 cJSON *jsonValue = NULL;
02601 SUM_info_t *elem = NULL;
02602 int64_t numBytes;
02603 int nElems;
02604 int iElem;
02605
02606 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
02607
02608 if (!err)
02609 {
02610 err = unjsonizeResponseCheckStatus(response, history);
02611 }
02612
02613 if (!err)
02614 {
02615 err = ((jsonArray = cJSON_GetObjectItem(response, "suinfo")) == NULL);
02616 if (err)
02617 {
02618 (*history)("Invalid 'suinfo' attribute.\n");
02619 }
02620 }
02621
02622 if (!err)
02623 {
02624 nElems = cJSON_GetArraySize(jsonArray);
02625 sums->sinfo = (SUM_info_t *)calloc(nElems, sizeof(SUM_info_t));
02626
02627 err = (sums->sinfo == NULL);
02628
02629 if (err)
02630 {
02631 (*history)("Out of memory calling calloc().\n");
02632 }
02633 else
02634 {
02635 for (iElem = 0; iElem < nElems; iElem++)
02636 {
02637 elem = &(sums->sinfo[iElem]);
02638 jsonArrayElement = cJSON_GetArrayItem(jsonArray, iElem);
02639
02640 if (iElem < nElems - 1)
02641 {
02642 elem->next = sums->sinfo + iElem + 1;
02643 }
02644
02645
02646 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "sunum")) == NULL) || jsonValue->type != cJSON_String);
02647
02648 if (err)
02649 {
02650 (*history)("Unable to unjsonize sunum.\n");
02651 break;
02652 }
02653 else
02654 {
02655
02656 err = (sscanf(jsonValue->valuestring, "%llx", &(elem->sunum)) != 1);
02657 }
02658
02659 if (err)
02660 {
02661 (*history)("Unable to parse sunum.\n");
02662 break;
02663 }
02664 else
02665 {
02666
02667 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "onlineLoc")) == NULL) ||jsonValue->type != cJSON_String);
02668 }
02669
02670 if (err)
02671 {
02672 (*history)("Unable to unjsonize onlineLoc.\n");
02673 break;
02674 }
02675 else
02676 {
02677 snprintf(elem->online_loc, sizeof(elem->online_loc), "%s", jsonValue->valuestring);
02678
02679
02680 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "onlineStatus")) == NULL) || jsonValue->type != cJSON_String);
02681 }
02682
02683 if (err)
02684 {
02685 (*history)("Unable to unjsonize onlineStatus.\n");
02686 break;
02687 }
02688 else
02689 {
02690 snprintf(elem->online_status, sizeof(elem->online_status), "%s", jsonValue->valuestring);
02691
02692
02693 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "archiveStatus")) == NULL) || jsonValue->type != cJSON_String);
02694
02695 }
02696
02697 if (err)
02698 {
02699 (*history)("Unable to unjsonize archiveStatus.\n");
02700 break;
02701 }
02702 else
02703 {
02704 snprintf(elem->archive_status, sizeof(elem->archive_status), "%s",jsonValue->valuestring);
02705
02706
02707 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "offsiteAck")) == NULL) || jsonValue->type != cJSON_String);
02708 }
02709
02710 if (err)
02711 {
02712 (*history)("Unable to unjsonize offsiteAck.\n");
02713 break;
02714 }
02715 else
02716 {
02717 snprintf(elem->offsite_ack, sizeof(elem->offsite_ack), "%s", jsonValue->valuestring);
02718
02719
02720 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "historyComment")) == NULL) || jsonValue->type != cJSON_String);
02721 }
02722
02723 if (err)
02724 {
02725 (*history)("Unable to unjsonize historyComment.\n");
02726 break;
02727 }
02728 else
02729 {
02730 snprintf(elem->history_comment, sizeof(elem->history_comment), "%s", jsonValue->valuestring);
02731
02732
02733 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "owningSeries")) == NULL) || jsonValue->type != cJSON_String);
02734 }
02735
02736 if (err)
02737 {
02738 (*history)("Unable to unjsonize owningSeries.\n");
02739 break;
02740 }
02741 else
02742 {
02743 snprintf(elem->owning_series, sizeof(elem->owning_series), "%s", jsonValue->valuestring);
02744
02745
02746 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "storageGroup")) == NULL) || jsonValue->type != cJSON_Number);
02747 }
02748
02749 if (err)
02750 {
02751 (*history)("Unable to unjsonize storageGroup.\n");
02752 break;
02753 }
02754 else
02755 {
02756 elem->storage_group = jsonValue->valueint;
02757
02758
02759
02760
02761 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "bytes")) == NULL) || jsonValue->type != cJSON_String);
02762 }
02763
02764 if (err)
02765 {
02766 (*history)("Unable to unjsonize bytes.\n");
02767 break;
02768 }
02769 else
02770 {
02771
02772 err = (sscanf(jsonValue->valuestring, "%llx", &numBytes) != 1);
02773 }
02774
02775 if (err)
02776 {
02777 (*history)("Unable to parse bytes string.");
02778 break;
02779 }
02780 else
02781 {
02782
02783 elem->bytes = (double)numBytes;
02784
02785
02786
02787
02788 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "creatDate")) == NULL) || jsonValue->type != cJSON_String);
02789 }
02790
02791 if (err)
02792 {
02793 (*history)("Unable to unjsonize creatDate.\n");
02794 break;
02795 }
02796 else
02797 {
02798 snprintf(elem->creat_date, sizeof(elem->creat_date), "%s", jsonValue->valuestring);
02799
02800
02801 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "username")) == NULL) || jsonValue->type != cJSON_String);
02802 }
02803
02804 if (err)
02805 {
02806 (*history)("Unable to unjsonize username.\n");
02807 break;
02808 }
02809 else
02810 {
02811 snprintf(elem->username, sizeof(elem->username), "%s", jsonValue->valuestring);
02812
02813
02814 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "archTape")) == NULL) || jsonValue->type != cJSON_String);
02815 }
02816
02817 if (err)
02818 {
02819 (*history)("Unable to unjsonize archTape.\n");
02820 break;
02821 }
02822 else
02823 {
02824 snprintf(elem->arch_tape, sizeof(elem->arch_tape), "%s", jsonValue->valuestring);
02825
02826
02827 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "archTapeFn")) == NULL) || jsonValue->type != cJSON_Number);
02828 }
02829
02830 if (err)
02831 {
02832 (*history)("Unable to unjsonize archTapeFn.\n");
02833 break;
02834 }
02835 else
02836 {
02837 elem->arch_tape_fn = jsonValue->valueint;
02838
02839
02840 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "archTapeDate")) == NULL) || jsonValue->type != cJSON_String);
02841 }
02842
02843 if (err)
02844 {
02845 (*history)("Unable to unjsonize archTapeDate.\n");
02846 break;
02847 }
02848 else
02849 {
02850 snprintf(elem->arch_tape_date, sizeof(elem->arch_tape_date), "%s", jsonValue->valuestring);
02851
02852
02853 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "safeTape")) == NULL) || jsonValue->type != cJSON_String);
02854 }
02855
02856 if (err)
02857 {
02858 (*history)("Unable to unjsonize safeTape.\n");
02859 break;
02860 }
02861 else
02862 {
02863 snprintf(elem->safe_tape, sizeof(elem->safe_tape), "%s", jsonValue->valuestring);
02864
02865
02866 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "safeTapeFn")) == NULL) || jsonValue->type != cJSON_Number);
02867 }
02868
02869 if (err)
02870 {
02871 (*history)("Unable to unjsonize safeTapeFn.\n");
02872 break;
02873 }
02874 else
02875 {
02876 elem->safe_tape_fn = jsonValue->valueint;
02877
02878
02879 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "safeTapeDate")) == NULL) || jsonValue->type != cJSON_String);
02880 }
02881
02882 if (err)
02883 {
02884 (*history)("Unable to unjsonize safeTapeDate.\n");
02885 break;
02886 }
02887 else
02888 {
02889 snprintf(elem->safe_tape_date, sizeof(elem->safe_tape_date), "%s", jsonValue->valuestring);
02890
02891
02892 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "effectiveDate")) == NULL) || jsonValue->type != cJSON_String);
02893 }
02894
02895 if (err)
02896 {
02897 (*history)("Unable to unjsonize effectiveDate.\n");
02898 break;
02899 }
02900 else
02901 {
02902 snprintf(elem->effective_date, sizeof(elem->effective_date), "%s", jsonValue->valuestring);
02903
02904
02905 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "paStatus")) == NULL) || jsonValue->type != cJSON_Number);
02906 }
02907
02908 if (err)
02909 {
02910 (*history)("Unable to unjsonize paStatus.\n");
02911 break;
02912 }
02913 else
02914 {
02915 elem->pa_status = jsonValue->valueint;
02916
02917
02918 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "paSubstatus")) == NULL) || jsonValue->type != cJSON_Number);
02919 }
02920
02921 if (err)
02922 {
02923 (*history)("Unable to unjsonize paSubstatus.\n");
02924 break;
02925 }
02926 else
02927 {
02928 elem->pa_substatus = jsonValue->valueint;
02929 }
02930 }
02931 }
02932 }
02933
02934 if (response)
02935 {
02936 cJSON_Delete(response);
02937 }
02938
02939 return err;
02940 }
02941
02942 #endif
02943
02944 #if defined(SUMS_USEMTSUMS_GET) && SUMS_USEMTSUMS_GET
02945
02946
02947
02948
02949
02950
02951
02952
02953
02954
02955
02956
02957
02958
02959
02960
02961
02962
02963
02964
02965
02966
02967
02968
02969
02970 static int jsonizeSumgetRequest(SUM_t *sums, SUMID_t sessionid, int touch, int retrieve, int retention, uint64_t *sunums, size_t nSus, char **json, int (*history)(const char *fmt, ...))
02971 {
02972 int isu;
02973 uint64_t sunum;
02974 char numBuf[64];
02975 cJSON *root = NULL;
02976 cJSON *jsonArray = NULL;
02977 cJSON *jsonArrayElement = NULL;
02978 cJSON *jsonValue = NULL;
02979 int err;
02980
02981 err = (!sums || !sunums || nSus == 0 || !json);
02982
02983 if (err)
02984 {
02985 (*history)("Invalid argument(s) to 'jsonizeRequest'.\n");
02986 }
02987 else
02988 {
02989 err = ((root = cJSON_CreateObject()) == NULL);
02990 }
02991
02992 if (err)
02993 {
02994 (*history)("Out of memory calling cJSON_CreateObject().\n");
02995 }
02996 else
02997 {
02998 err = ((jsonValue = cJSON_CreateString("get")) == NULL);
02999 }
03000
03001 if (err)
03002 {
03003 (*history)("Out of memory calling cJSON_CreateString().\n");
03004 }
03005 else
03006 {
03007
03008 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
03009
03010 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
03011 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
03012 }
03013
03014 if (err)
03015 {
03016 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03017 }
03018 else
03019 {
03020 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
03021
03022 err = ((jsonValue = cJSON_CreateBool(touch)) == NULL);
03023 }
03024
03025 if (err)
03026 {
03027 (*history)("Out of memory calling cJSON_CreateBool().\n");
03028 }
03029 else
03030 {
03031 cJSON_AddItemToObjectCS(root, "touch", jsonValue);
03032 }
03033
03034 if (!err)
03035 {
03036 err = ((jsonValue = cJSON_CreateBool(retrieve)) == NULL);
03037 }
03038
03039 if (err)
03040 {
03041 (*history)("Out of memory calling cJSON_CreateBool().\n");
03042 }
03043 else
03044 {
03045 cJSON_AddItemToObjectCS(root, "retrieve", jsonValue);
03046 }
03047
03048 if (!err)
03049 {
03050 err = ((jsonValue = cJSON_CreateNumber((double)retention)) == NULL);
03051 }
03052
03053 if (err)
03054 {
03055 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03056 }
03057 else
03058 {
03059 cJSON_AddItemToObjectCS(root, "retention", jsonValue);
03060 }
03061
03062 if (!err)
03063 {
03064 err = ((jsonArray = cJSON_CreateArray()) == NULL);
03065 }
03066
03067 if (err)
03068 {
03069 (*history)("Out of memory calling cJSON_CreateArray().\n");
03070 }
03071 else
03072 {
03073 for (isu = 0; isu < nSus; isu++)
03074 {
03075 sunum = sunums[isu];
03076
03077
03078
03079
03080
03081 snprintf(numBuf, sizeof(numBuf), "%llx", sunum);
03082
03083 err = ((jsonArrayElement = cJSON_CreateString(numBuf)) == NULL);
03084 if (err)
03085 {
03086 (*history)("Out of memory calling cJSON_CreateString().\n");
03087 break;
03088 }
03089 else
03090 {
03091 cJSON_AddItemToArray(jsonArray, jsonArrayElement);
03092 }
03093 }
03094 }
03095
03096 if (!err)
03097 {
03098
03099 cJSON_AddItemToObjectCS(root, "sus", jsonArray);
03100
03101 *json = cJSON_Print(root);
03102 }
03103
03104 if (root)
03105 {
03106 cJSON_Delete(root);
03107 }
03108
03109 return err;
03110 }
03111
03112
03113
03114
03115
03116
03117
03118
03119
03120
03121
03122
03123
03124
03125
03126
03127
03128
03129
03130
03131
03132
03133
03134
03135
03136
03137
03138
03139 static int unjsonizeSumgetResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
03140 {
03141 int err;
03142 cJSON *response = NULL;
03143 cJSON *jsonArray = NULL;
03144 cJSON *jsonArrayElement = NULL;
03145 cJSON *jsonValue = NULL;
03146 SUM_info_t *elem = NULL;
03147 int doingTapeRead = 0;
03148 int64_t numBytes;
03149 int nElems;
03150 int iElem;
03151
03152 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
03153
03154 if (!err)
03155 {
03156 err = unjsonizeResponseCheckStatus(response, history);
03157 }
03158
03159 if (!err)
03160 {
03161 jsonValue = cJSON_GetObjectItem(response, "taperead-requestid");
03162 if (jsonValue)
03163 {
03164 doingTapeRead = 1;
03165 err = (jsonValue->type != cJSON_String);
03166 if (err)
03167 {
03168 (*history)("Invalid 'taperead-requestid' attribute.\n");
03169 }
03170 else
03171 {
03172
03173
03174
03175
03176 if (sums->dsname)
03177 {
03178 free(sums->dsname);
03179 sums->dsname = NULL;
03180 }
03181
03182 sums->dsname = strdup(jsonValue->valuestring);
03183 sums->reqcnt = kMTSums_CallType_Get;
03184
03185
03186 return RESULT_PEND;
03187 }
03188 }
03189 }
03190
03191
03192 if (!err)
03193 {
03194 err = ((jsonArray = cJSON_GetObjectItem(response, "supaths")) == NULL);
03195 if (err)
03196 {
03197 (*history)("Invalid 'supaths' attribute.\n");
03198 }
03199 }
03200
03201 if (!err)
03202 {
03203 nElems = cJSON_GetArraySize(jsonArray);
03204 if (nElems != sums->reqcnt)
03205 {
03206 (*history)("Invalid number of paths (%d) returned from server; expecting %d paths.\n", nElems, sums->reqcnt);
03207 err = 1;
03208 }
03209
03210 if (sums->wd)
03211 {
03212
03213 free(sums->wd);
03214 sums->wd = NULL;
03215 }
03216
03217 sums->wd = (char **)calloc(nElems, sizeof(char *));
03218
03219 err = (sums->wd == NULL);
03220
03221 if (err)
03222 {
03223 (*history)("Out of memory calling calloc().\n");
03224 }
03225
03226 if (!err)
03227 {
03228 for (iElem = 0; iElem < nElems; iElem++)
03229 {
03230 jsonArrayElement = cJSON_GetArrayItem(jsonArray, iElem);
03231
03232
03233
03234
03235
03236 err = (((jsonValue = cJSON_GetObjectItem(jsonArrayElement, "path")) == NULL));
03237 if (err)
03238 {
03239 (*history)("Unable to unjsonize path - path attribute is missing.\n");
03240 break;
03241 }
03242 else
03243 {
03244 if (jsonValue->type == cJSON_NULL)
03245 {
03246 sums->wd[iElem] = strdup("");
03247 }
03248 else if (jsonValue->type == cJSON_String)
03249 {
03250 sums->wd[iElem] = strdup(jsonValue->valuestring);
03251 }
03252 else
03253 {
03254 err = 1;
03255 (*history)("Unable to unjsonize path - invalid data type for path-attribute.\n");
03256 break;
03257 }
03258 }
03259 }
03260 }
03261 }
03262
03263 if (response)
03264 {
03265 cJSON_Delete(response);
03266 }
03267
03268 return err;
03269 }
03270
03271 #endif
03272
03273 #if defined(SUMS_USEMTSUMS_ALLOC) && SUMS_USEMTSUMS_ALLOC
03274
03275
03276
03277
03278
03279
03280
03281
03282
03283 static int jsonizeSumallocSumalloc2Request(SUM_t *sums, SUMID_t sessionid, uint64_t *sunum, int sugroup, double numBytes, char **json, int (*history)(const char *fmt, ...))
03284 {
03285 char numBuf[64];
03286 cJSON *root = NULL;
03287 cJSON *jsonValue = NULL;
03288 int err;
03289
03290 err = (!sums || !json);
03291
03292 if (err)
03293 {
03294 (*history)("Invalid argument(s) to 'jsonizeRequest'.\n");
03295 }
03296 else
03297 {
03298 err = ((root = cJSON_CreateObject()) == NULL);
03299 }
03300
03301 if (err)
03302 {
03303 (*history)("Out of memory calling cJSON_CreateObject().\n");
03304 }
03305 else
03306 {
03307
03308
03309
03310 cJSON_AddItemToObjectCS(root, "reqtype", cJSON_CreateString("alloc"));
03311
03312
03313 if (!err)
03314 {
03315 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
03316 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
03317 }
03318
03319 if (err)
03320 {
03321 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03322 }
03323 else
03324 {
03325 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
03326 }
03327
03328
03329 if (sunum)
03330 {
03331
03332 snprintf(numBuf, sizeof(numBuf), "%llx", *sunum);
03333
03334 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
03335 if (err)
03336 {
03337 (*history)("Out of memory calling cJSON_CreateString().\n");
03338 }
03339 else
03340 {
03341 cJSON_AddItemToObjectCS(root, "sunum", jsonValue);
03342 }
03343 }
03344 else
03345 {
03346
03347 cJSON_AddItemToObjectCS(root, "sunum", cJSON_CreateNull());
03348 }
03349
03350
03351 if (!err)
03352 {
03353 err = ((jsonValue = cJSON_CreateNumber((double)sugroup)) == NULL);
03354 }
03355
03356 if (err)
03357 {
03358 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03359 }
03360 else
03361 {
03362 cJSON_AddItemToObjectCS(root, "sugroup", jsonValue);
03363 }
03364
03365
03366 if (!err)
03367 {
03368 err = ((jsonValue = cJSON_CreateNumber(numBytes)) == NULL);
03369 }
03370
03371 if (err)
03372 {
03373 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03374 }
03375 else
03376 {
03377 cJSON_AddItemToObjectCS(root, "numbytes", jsonValue);
03378 }
03379 }
03380
03381 if (!err)
03382 {
03383 *json = cJSON_Print(root);
03384 }
03385
03386 if (root)
03387 {
03388 cJSON_Delete(root);
03389 }
03390
03391 return err;
03392 }
03393
03394
03395
03396
03397
03398
03399
03400
03401
03402
03403 static int unjsonizeSumallocSumalloc2Response(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
03404 {
03405 int err = 0;
03406 cJSON *response = NULL;
03407 cJSON *value = NULL;
03408
03409 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
03410
03411 if (!err)
03412 {
03413 err = unjsonizeResponseCheckStatus(response, history);
03414 }
03415
03416 if (!err)
03417 {
03418 err = ((value = cJSON_GetObjectItem(response, "sunum")) == NULL);
03419 if (err)
03420 {
03421 (*history)("Missing 'sunum' attribute.\n");
03422 }
03423 }
03424
03425 if (!err)
03426 {
03427 err = (value->type != cJSON_String);
03428 if (err)
03429 {
03430 (*history)("Unexpected data type for sunum.");
03431 }
03432 }
03433
03434 if (!err)
03435 {
03436 if (sums->dsix_ptr)
03437 {
03438 free(sums->dsix_ptr);
03439 sums->dsix_ptr = NULL;
03440 }
03441
03442 err = ((sums->dsix_ptr = calloc(1, sizeof(uint64_t))) == NULL);
03443
03444 if (err)
03445 {
03446 (*history)("out of memory");
03447 }
03448 else
03449 {
03450
03451 err = (sscanf(value->valuestring, "%llx", &(sums->dsix_ptr[0])) != 1);
03452 if (err)
03453 {
03454 (*history)("Invalid sunum string.");
03455 }
03456 }
03457 }
03458
03459 if (!err)
03460 {
03461 err = ((value = cJSON_GetObjectItem(response, "sudir")) == NULL);
03462 if (err)
03463 {
03464 (*history)("Missing 'sudir' attribute.\n");
03465 }
03466 }
03467
03468 if (!err)
03469 {
03470 err = (value->type != cJSON_String);
03471 if (err)
03472 {
03473 (*history)("Unexpected data type for sudir.");
03474 }
03475 }
03476
03477 if (!err)
03478 {
03479 if (sums->wd)
03480 {
03481
03482 free(sums->wd);
03483 sums->wd = NULL;
03484 }
03485
03486 err = ((sums->wd = (char **)calloc(1, sizeof(char *))) == NULL);
03487
03488 if (err)
03489 {
03490 (*history)("Out of memory.");
03491 }
03492 else
03493 {
03494 err = ((sums->wd[0] = strdup(value->valuestring)) == NULL);
03495 if (err)
03496 {
03497 (*history)("Out of memory.");
03498 }
03499 }
03500 }
03501
03502 if (response)
03503 {
03504 cJSON_Delete(response);
03505 }
03506
03507 return err;
03508 }
03509
03510 static int jsonizeSumallocRequest(SUM_t *sums, SUMID_t sessionid, int sugroup, double numBytes, char **json, int (*history)(const char *fmt, ...))
03511 {
03512 return jsonizeSumallocSumalloc2Request(sums, sessionid, NULL, sugroup, numBytes, json, history);
03513 }
03514
03515 static int unjsonizeSumallocResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
03516 {
03517 return unjsonizeSumallocSumalloc2Response(sums, msg, history);
03518 }
03519
03520
03521 static int jsonizeSumalloc2Request(SUM_t *sums, SUMID_t sessionid, uint64_t sunum, int sugroup, double numBytes, char **json, int (*history)(const char *fmt, ...))
03522 {
03523 return jsonizeSumallocSumalloc2Request(sums, sessionid, &sunum, sugroup, numBytes, json, history);
03524 }
03525 static int unjsonizeSumalloc2Response(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
03526 {
03527 return unjsonizeSumallocSumalloc2Response(sums, msg, history);
03528 }
03529 #endif
03530
03531 #if defined(SUMS_USEMTSUMS_PUT) && SUMS_USEMTSUMS_PUT
03532
03533
03534
03535
03536
03537
03538
03539
03540
03541
03542 static int jsonizeSumputRequest(SUM_t *sums, SUMID_t sessionid, uint64_t *sunums, char **sudirs, size_t nSus, const char *series, int retention, const char *archiveType, char **json, int (*history)(const char *fmt, ...))
03543 {
03544 char numBuf[64];
03545 cJSON *root = NULL;
03546 cJSON *jsonArray = NULL;
03547 cJSON *jsonArrayElement = NULL;
03548 cJSON *jsonValue = NULL;
03549 int isu;
03550 int err;
03551
03552 err = (!sums || !sunums || !sudirs || nSus < 1 || !series || series[0] == '\0' || !json);
03553
03554 if (err)
03555 {
03556 (*history)("Invalid argument(s) to 'jsonizeRequest'.\n");
03557 }
03558 else
03559 {
03560 err = ((root = cJSON_CreateObject()) == NULL);
03561 }
03562
03563 if (err)
03564 {
03565 (*history)("Out of memory calling cJSON_CreateObject().\n");
03566 }
03567 else
03568 {
03569 err = ((jsonValue = cJSON_CreateString("put")) == NULL);
03570 }
03571
03572 if (err)
03573 {
03574 (*history)("Out of memory calling cJSON_CreateString().\n");
03575 }
03576 else
03577 {
03578 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
03579
03580 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
03581 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
03582 }
03583
03584 if (err)
03585 {
03586 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03587 }
03588 else
03589 {
03590 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
03591
03592 err = ((jsonArray = cJSON_CreateArray()) == NULL);
03593 }
03594
03595 if (err)
03596 {
03597 (*history)("out of memory calling cJSON_CreateArray()\n");
03598 }
03599 else
03600 {
03601
03602 for (isu = 0; isu < nSus; isu++)
03603 {
03604 err = ((jsonArrayElement = cJSON_CreateObject()) == NULL);
03605
03606 if (err)
03607 {
03608 (*history)("out of memory calling cJSON_CreateObject()\n");
03609 break;
03610 }
03611 else
03612 {
03613 char *sunumStr = NULL;
03614
03615 snprintf(numBuf, sizeof(numBuf), "%llx", sunums[isu]);
03616 err = ((sunumStr = strdup(numBuf)) == NULL);
03617
03618 if (err)
03619 {
03620 (*history)("out of memory calling strdup()\n");
03621 break;
03622 }
03623 else
03624 {
03625 err = ((jsonValue = cJSON_CreateString(sudirs[isu])) == NULL);
03626
03627 if (err)
03628 {
03629 (*history)("out of memory calling cJSON_CreateString()\n");
03630 break;
03631 }
03632 else
03633 {
03634
03635
03636
03637
03638
03639 cJSON_AddItemToObject(jsonArrayElement, sunumStr, jsonValue);
03640 }
03641
03642 cJSON_AddItemToArray(jsonArray, jsonArrayElement);
03643 }
03644 }
03645 }
03646 }
03647
03648 if (!err)
03649 {
03650 cJSON_AddItemToObjectCS(root, "sudirs", jsonArray);
03651 }
03652
03653
03654 if (!err)
03655 {
03656 err = ((jsonValue = cJSON_CreateString(series)) == NULL);
03657 }
03658
03659 if (err)
03660 {
03661 (*history)("Out of memory calling cJSON_CreateString().\n");
03662 }
03663 else
03664 {
03665 cJSON_AddItemToObjectCS(root, "series", jsonValue);
03666 }
03667
03668
03669 if (!err)
03670 {
03671 err = ((jsonValue = cJSON_CreateNumber(retention)) == NULL);
03672 }
03673
03674 if (err)
03675 {
03676 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03677 }
03678 else
03679 {
03680 cJSON_AddItemToObjectCS(root, "retention", jsonValue);
03681 }
03682
03683 if (!err)
03684 {
03685 err = ((jsonValue = cJSON_CreateString(archiveType)) == NULL);
03686 }
03687
03688 if (err)
03689 {
03690 (*history)("Out of memory calling cJSON_CreateString().\n");
03691 }
03692 else
03693 {
03694 cJSON_AddItemToObjectCS(root, "archivetype", jsonValue);
03695 }
03696
03697 if (!err)
03698 {
03699 *json = cJSON_Print(root);
03700 }
03701
03702 if (root)
03703 {
03704 cJSON_Delete(root);
03705 }
03706
03707 return err;
03708 }
03709
03710
03711
03712
03713
03714
03715 static int unjsonizeSumputResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
03716 {
03717 int err = 0;
03718 cJSON *response = NULL;
03719
03720 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
03721
03722 if (!err)
03723 {
03724 err = unjsonizeResponseCheckStatus(response, history);
03725 }
03726
03727 if (response)
03728 {
03729 cJSON_Delete(response);
03730 }
03731
03732 return err;
03733 }
03734 #endif
03735
03736 #if defined(SUMS_USEMTSUMS_DELETESUS) && SUMS_USEMTSUMS_DELETESUS
03737
03738
03739
03740
03741
03742
03743
03744 static int jsonizeSumdeleteseriesRequest(SUM_t *sums, SUMID_t sessionid, const char *series, char **json, int (*history)(const char *fmt, ...))
03745 {
03746 cJSON *root = NULL;
03747 cJSON *jsonValue = NULL;
03748 char numBuf[64];
03749 int err;
03750
03751 err = (!sums || !series || series[0] == '\0');
03752
03753 if (err)
03754 {
03755 (*history)("Invalid argument(s) to 'jsonizeRequest'.\n");
03756 }
03757 else
03758 {
03759 err = ((root = cJSON_CreateObject()) == NULL);
03760
03761 if (err)
03762 {
03763 (*history)("Out of memory calling cJSON_CreateObject().\n");
03764 }
03765 }
03766
03767 if (!err)
03768 {
03769 err = ((jsonValue = cJSON_CreateString("deleteseries")) == NULL);
03770
03771 if (err)
03772 {
03773 (*history)("Out of memory calling cJSON_CreateString().\n");
03774 }
03775 }
03776
03777 if (!err)
03778 {
03779 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
03780
03781 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
03782 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
03783
03784 if (err)
03785 {
03786 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03787 }
03788 }
03789
03790 if (!err)
03791 {
03792 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
03793
03794 err = ((jsonValue = cJSON_CreateString(series)) == NULL);
03795
03796 if (err)
03797 {
03798 (*history)("Out of memory calling cJSON_CreateString().\n");
03799 }
03800 }
03801
03802 if (!err)
03803 {
03804 cJSON_AddItemToObjectCS(root, "series", jsonValue);
03805 }
03806
03807 if (!err)
03808 {
03809 *json = cJSON_Print(root);
03810 }
03811
03812 if (root)
03813 {
03814 cJSON_Delete(root);
03815 }
03816
03817 return err;
03818 }
03819
03820
03821
03822
03823
03824
03825 static int unjsonizeSumdeleteseriesResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
03826 {
03827 int err = 0;
03828 cJSON *response = NULL;
03829
03830 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
03831
03832 if (!err)
03833 {
03834 err = unjsonizeResponseCheckStatus(response, history);
03835 }
03836
03837 if (response)
03838 {
03839 cJSON_Delete(response);
03840 }
03841
03842 return err;
03843 }
03844 #endif
03845
03846
03847
03848
03849
03850
03851
03852
03853
03854 static int jsonizeSumnopRequest(SUM_t *sums, SUMID_t sessionid, char **json, int (*history)(const char *fmt, ...))
03855 {
03856 cJSON *root = NULL;
03857 cJSON *jsonValue = NULL;
03858 char numBuf[64];
03859 int err;
03860
03861 err = (!sums || !json);
03862
03863 if (err)
03864 {
03865 (*history)("Invalid argument(s) to 'jsonizeRequest'.\n");
03866 }
03867 else
03868 {
03869 err = ((root = cJSON_CreateObject()) == NULL);
03870 }
03871
03872 if (err)
03873 {
03874 (*history)("Out of memory calling cJSON_CreateObject().\n");
03875 }
03876 else
03877 {
03878 err = ((jsonValue = cJSON_CreateString("ping")) == NULL);
03879 }
03880
03881 if (err)
03882 {
03883 (*history)("Out of memory calling cJSON_CreateString().\n");
03884 }
03885 else
03886 {
03887 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
03888
03889 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
03890 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
03891 }
03892
03893 if (err)
03894 {
03895 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03896 }
03897 else
03898 {
03899 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
03900 }
03901
03902 if (!err)
03903 {
03904 *json = cJSON_Print(root);
03905 }
03906
03907 if (root)
03908 {
03909 cJSON_Delete(root);
03910 }
03911
03912 return err;
03913 }
03914
03915
03916
03917
03918
03919
03920
03921
03922 static int unjsonizeSumnopResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
03923 {
03924 int err = 0;
03925 cJSON *response = NULL;
03926
03927 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
03928
03929 if (!err)
03930 {
03931 err = unjsonizeResponseCheckStatus(response, history);
03932 }
03933
03934 if (response)
03935 {
03936 cJSON_Delete(response);
03937 }
03938
03939 return err;
03940 }
03941
03942
03943
03944
03945
03946
03947
03948
03949
03950
03951 static int jsonizeSumpollRequest(SUM_t *sums, SUMID_t sessionid, const char *requestID, char **json, int (*history)(const char *fmt, ...))
03952 {
03953 cJSON *root = NULL;
03954 cJSON *jsonValue = NULL;
03955 char numBuf[64];
03956 int err;
03957
03958 err = (!sums || !requestID || requestID[0] == '\0');
03959
03960 if (err)
03961 {
03962 (*history)("Invalid argument(s) to 'jsonizeRequest'.\n");
03963 }
03964 else
03965 {
03966 err = ((root = cJSON_CreateObject()) == NULL);
03967 }
03968
03969 if (err)
03970 {
03971 (*history)("Out of memory calling cJSON_CreateObject().\n");
03972 }
03973 else
03974 {
03975 err = ((jsonValue = cJSON_CreateString("poll")) == NULL);
03976 }
03977
03978 if (err)
03979 {
03980 (*history)("Out of memory calling cJSON_CreateString().\n");
03981 }
03982 else
03983 {
03984 cJSON_AddItemToObjectCS(root, "reqtype", jsonValue);
03985
03986 snprintf(numBuf, sizeof(numBuf), "%llx", (uint64_t)sessionid);
03987 err = ((jsonValue = cJSON_CreateString(numBuf)) == NULL);
03988 }
03989
03990 if (err)
03991 {
03992 (*history)("Out of memory calling cJSON_CreateNumber().\n");
03993 }
03994 else
03995 {
03996 cJSON_AddItemToObjectCS(root, "sessionid", jsonValue);
03997
03998 err = ((jsonValue = cJSON_CreateString(requestID)) == NULL);
03999 }
04000
04001 if (err)
04002 {
04003 (*history)("Out of memory calling cJSON_CreateString().\n");
04004 }
04005 else
04006 {
04007 cJSON_AddItemToObjectCS(root, "requestid", jsonValue);
04008 }
04009
04010 if (!err)
04011 {
04012 *json = cJSON_Print(root);
04013 }
04014
04015 if (root)
04016 {
04017 cJSON_Delete(root);
04018 }
04019
04020 return err;
04021 }
04022
04023
04024
04025
04026
04027
04028
04029
04030
04031
04032
04033
04034
04035
04036
04037
04038
04039
04040
04041
04042
04043
04044
04045
04046 static int unjsonizeSumpollResponse(SUM_t *sums, const char *msg, int (*history)(const char *fmt, ...))
04047 {
04048
04049
04050 int err = 0;
04051 cJSON *response = NULL;
04052 cJSON *value = NULL;
04053 MTSums_CallType_t origType;
04054
04055 err = ((response = unjsonizeResponseParse(msg, history)) == NULL);
04056
04057 if (!err)
04058 {
04059 err = unjsonizeResponseCheckStatus(response, history);
04060 }
04061
04062 if (!err)
04063 {
04064 err = ((value = cJSON_GetObjectItem(response, "reqtype")) == NULL);
04065 if (err)
04066 {
04067 (*history)("Missing 'reqtype' attribute.\n");
04068 }
04069 }
04070
04071 if (!err)
04072 {
04073 err = (value->type != cJSON_String);
04074 if (err)
04075 {
04076 (*history)("Unexpected data type for reqtype.\n");
04077 }
04078 }
04079
04080 if (!err)
04081 {
04082
04083 err = ((origType = CallTypeFromString(value->valuestring)) == kMTSums_CallType_None);
04084 if (err)
04085 {
04086 (*history)("Unknown MT SUMS call type %s.\n", value->valuestring);
04087 }
04088 }
04089
04090 if (response)
04091 {
04092 cJSON_Delete(response);
04093 }
04094
04095 if (!err)
04096 {
04097 return unjsonizeResponse(sums, origType, msg, history);
04098 }
04099
04100 return err;
04101 }
04102
04103 int jsonizeRequest(SUM_t *sums, MTSums_CallType_t type, JSONIZER_DATA_t *data, char **json, int (*history)(const char *fmt, ...))
04104 {
04105 int err;
04106
04107 err = 0;
04108
04109 if (0)
04110 {
04111 err = 1;
04112 }
04113 #if defined(SUMS_USEMTSUMS_CONNECTION) && SUMS_USEMTSUMS_CONNECTION
04114 else if (type == kMTSums_CallType_Open)
04115 {
04116 err = jsonizeSumopenRequest(json, history);
04117 }
04118 else if (type == kMTSums_CallType_Close)
04119 {
04120 SUMID_t sessionid = 0;
04121
04122 sessionid = sums->uid;
04123 err = jsonizeSumcloseRequest(sums, sessionid, json, history);
04124 }
04125 else if (type == kMTSums_CallType_Rollback)
04126 {
04127 SUMID_t sessionid = 0;
04128
04129 sessionid = sums->uid;
04130 err = jsonizeSumrollbackRequest(sums, sessionid, json, history);
04131 }
04132 #endif
04133 #if defined(SUMS_USEMTSUMS_INFO) && SUMS_USEMTSUMS_INFO
04134 else if (type == kMTSums_CallType_Info)
04135 {
04136 JSONIZER_DATA_INFO_t *infoData = NULL;
04137 SUMID_t sessionid = 0;
04138 uint64_t *sunums = NULL;
04139 size_t nSus = 0;
04140
04141 infoData = (JSONIZER_DATA_INFO_t *)data;
04142 sessionid = sums->uid;
04143 sunums = infoData->sunums;
04144 nSus = infoData->nSus;
04145 err = jsonizeSuminfoRequest(sums, sessionid, sunums, nSus, json, history);
04146 }
04147 #endif
04148 #if defined(SUMS_USEMTSUMS_GET) && SUMS_USEMTSUMS_GET
04149 else if (type == kMTSums_CallType_Get)
04150 {
04151 JSONIZER_DATA_GET_t *getData = NULL;
04152 SUMID_t sessionid = 0;
04153 int touch = 0;
04154 int retrieve = 0;
04155 int retention = 0;
04156 uint64_t *sunums = NULL;
04157 size_t nSus = 0;
04158
04159 getData = (JSONIZER_DATA_GET_t *)data;
04160 sessionid = sums->uid;
04161 touch = getData->touch;
04162 retrieve = getData->retrieve;
04163 retention = getData->retention;
04164 sunums = getData->sunums;
04165 nSus = getData->nSus;
04166 err = jsonizeSumgetRequest(sums, sessionid, touch, retrieve, retention, sunums, nSus, json, history);
04167 }
04168 #endif
04169 #if defined(SUMS_USEMTSUMS_ALLOC) && SUMS_USEMTSUMS_ALLOC
04170 else if (type == kMTSums_CallType_Alloc)
04171 {
04172 JSONIZER_DATA_ALLOC_t *allocData = NULL;
04173 SUMID_t sessionid = 0;
04174 int sugroup = -1;
04175 double numBytes = 0;
04176
04177 allocData = (JSONIZER_DATA_ALLOC_t *)data;
04178 sessionid = sums->uid;
04179 sugroup = allocData->sugroup;
04180 numBytes = allocData->numBytes;
04181 err = jsonizeSumallocRequest(sums, sessionid, sugroup, numBytes, json, history);
04182 }
04183 else if (type == kMTSums_CallType_Alloc2)
04184 {
04185 JSONIZER_DATA_ALLOC2_t *alloc2Data = NULL;
04186 SUMID_t sessionid = 0;
04187 uint64_t sunum = 0;
04188 int sugroup = -1;
04189 double numBytes = 0;
04190
04191 alloc2Data = (JSONIZER_DATA_ALLOC2_t *)data;
04192 sessionid = sums->uid;
04193 sunum = alloc2Data->sunum;
04194 sugroup = alloc2Data->sugroup;
04195 numBytes = alloc2Data->numBytes;
04196 err = jsonizeSumalloc2Request(sums, sessionid, sunum, sugroup, numBytes, json, history);
04197 }
04198 #endif
04199 #if defined(SUMS_USEMTSUMS_PUT) && SUMS_USEMTSUMS_PUT
04200 else if (type == kMTSums_CallType_Put)
04201 {
04202 JSONIZER_DATA_PUT_t *putData = NULL;
04203 SUMID_t sessionid = 0;
04204 uint64_t *sunums;
04205 char **sudirs;
04206 size_t nSus;
04207 char *series;
04208 int retention;
04209 const char *archiveType;
04210
04211 putData = (JSONIZER_DATA_PUT_t *)data;
04212 sessionid = sums->uid;
04213 sunums = putData->sunums;
04214 sudirs = putData->sudirs;
04215 nSus = putData->nSus;
04216 series = putData->series;
04217 retention = putData->retention;
04218 archiveType = putData->archiveType;
04219 err = jsonizeSumputRequest(sums, sessionid, sunums, sudirs, nSus, series, retention, archiveType, json, history);
04220 }
04221 #endif
04222 #if defined(SUMS_USEMTSUMS_DELETESUS) && SUMS_USEMTSUMS_DELETESUS
04223 else if (type == kMTSums_CallType_Deleteseries)
04224 {
04225 JSONIZER_DATA_DELETESERIES_t *deleteseriesData = NULL;
04226 SUMID_t sessionid = 0;
04227 char *series = NULL;
04228
04229 deleteseriesData = (JSONIZER_DATA_DELETESERIES_t *)data;
04230 sessionid = sums->uid;
04231 series = deleteseriesData->series;
04232 err = jsonizeSumdeleteseriesRequest(sums, sessionid, series, json, history);
04233 }
04234 #endif
04235 else if (type == kMTSums_CallType_Ping)
04236 {
04237 SUMID_t sessionid = 0;
04238
04239 sessionid = sums->uid;
04240 err = jsonizeSumnopRequest(sums, sessionid, json, history);
04241 }
04242 else if (type == kMTSums_CallType_Poll)
04243 {
04244 JSONIZER_DATA_POLL_t *pollData = NULL;
04245 SUMID_t sessionid = 0;
04246 char *requestID = NULL;
04247
04248 pollData = (JSONIZER_DATA_POLL_t *)data;
04249 sessionid = sums->uid;
04250 requestID = pollData->requestID;
04251 err = jsonizeSumpollRequest(sums, sessionid, requestID, json, history);
04252 }
04253 else
04254 {
04255 (*history)("Unsupported MT SUMS request %d.\n", type);
04256 err = 1;
04257 }
04258
04259 return err;
04260 }
04261
04262 int unjsonizeResponse(SUM_t *sums, MTSums_CallType_t type, const char *msg, int (*history)(const char *fmt, ...))
04263 {
04264 int err;
04265
04266 err = 0;
04267
04268 if (0)
04269 {
04270 err = 1;
04271 }
04272 #if defined(SUMS_USEMTSUMS_CONNECTION) && SUMS_USEMTSUMS_CONNECTION
04273 else if (type == kMTSums_CallType_Open)
04274 {
04275 err = unjsonizeSumopenResponse(sums, msg, history);
04276 }
04277 else if (type == kMTSums_CallType_Close)
04278 {
04279 err = unjsonizeSumcloseResponse(sums, msg, history);
04280 }
04281 else if (type == kMTSums_CallType_Rollback)
04282 {
04283 err = unjsonizeSumrollbackResponse(sums, msg, history);
04284 }
04285 #endif
04286 #if defined(SUMS_USEMTSUMS_INFO) && SUMS_USEMTSUMS_INFO
04287 else if (type == kMTSums_CallType_Info)
04288 {
04289 err = unjsonizeSuminfoResponse(sums, msg, history);
04290 }
04291 #endif
04292 #if defined(SUMS_USEMTSUMS_GET) && SUMS_USEMTSUMS_GET
04293 else if (type == kMTSums_CallType_Get)
04294 {
04295 err = unjsonizeSumgetResponse(sums, msg, history);
04296 }
04297 #endif
04298 #if defined(SUMS_USEMTSUMS_ALLOC) && SUMS_USEMTSUMS_ALLOC
04299 else if (type == kMTSums_CallType_Alloc)
04300 {
04301 err = unjsonizeSumallocResponse(sums, msg, history);
04302 }
04303 else if (type == kMTSums_CallType_Alloc2)
04304 {
04305 err = unjsonizeSumalloc2Response(sums, msg, history);
04306 }
04307 #endif
04308 #if defined(SUMS_USEMTSUMS_PUT) && SUMS_USEMTSUMS_PUT
04309 else if (type == kMTSums_CallType_Put)
04310 {
04311 err = unjsonizeSumputResponse(sums, msg, history);
04312 }
04313 #endif
04314 #if defined(SUMS_USEMTSUMS_DELETESUS) && SUMS_USEMTSUMS_DELETESUS
04315 else if (type == kMTSums_CallType_Deleteseries)
04316 {
04317 err = unjsonizeSumdeleteseriesResponse(sums, msg, history);
04318 }
04319 #endif
04320
04321 else if (type == kMTSums_CallType_Ping)
04322 {
04323 err = unjsonizeSumnopResponse(sums, msg, history);
04324 }
04325 else if (type == kMTSums_CallType_Poll)
04326 {
04327 err = unjsonizeSumpollResponse(sums, msg, history);
04328 }
04329 else
04330 {
04331 (*history)("Unsupported MT SUMS request %d.\n", type);
04332 err = 1;
04333 }
04334
04335 return err;
04336 }
04337
04338 int callMTSums(SUM_t *sums, MTSums_CallType_t callType, JSONIZER_DATA_t *data, int (*history)(const char *fmt, ...))
04339 {
04340 char *request = NULL;
04341 char *response = NULL;
04342 size_t rspLen = 0;
04343 int err;
04344
04345 clprev = NULL;
04346
04347 err = jsonizeRequest(sums, callType, data, &request, history);
04348
04349 if (!err)
04350 {
04351 #if (defined(SUMS_USEMTSUMS_ALL) && SUMS_USEMTSUMS_ALL)
04352
04353 if (callType == kMTSums_CallType_Open)
04354 #else
04355
04356 #endif
04357 {
04358 if (!sums || sums->mSumsClient != -1 || ConnectToMtSums(sums, history) == -1)
04359 {
04360
04361 err = 4;
04362 }
04363 }
04364 }
04365
04366 if (!err)
04367 {
04368
04369
04370
04371
04372 if (sendMsg(sums, request, strlen(request), history))
04373 {
04374 err = 4;
04375 }
04376 }
04377
04378 if (!err)
04379 {
04380
04381
04382 err = receiveMsg(sums, &response, &rspLen, history);
04383 }
04384
04385
04386 if (!err)
04387 {
04388 err = unjsonizeResponse(sums, callType, response, history);
04389 }
04390
04391 #if (defined(SUMS_USEMTSUMS_ALL) && SUMS_USEMTSUMS_ALL)
04392
04393 if (callType == kMTSums_CallType_Close || callType == kMTSums_CallType_Rollback)
04394 #else
04395
04396 #endif
04397 {
04398 DisconnectFromMtSums(sums);
04399 }
04400
04401 if (response)
04402 {
04403 free(response);
04404 response = NULL;
04405 }
04406
04407 if (request)
04408 {
04409 free(request);
04410 request = NULL;
04411 }
04412
04413 return err;
04414 }
04415
04416
04417 #if defined(SUMS_USEMTSUMS_CONNECTION) && SUMS_USEMTSUMS_CONNECTION
04418
04419
04420
04421
04422
04423
04424
04425
04426
04427 SUM_t *SUM_open(char *server, char *db, int (*history)(const char *fmt, ...))
04428 {
04429
04430
04431
04432
04433 SUM_t *sums = NULL;
04434
04435
04436
04437 sums = sumsopenOpen(server, db, history);
04438
04439 return sums;
04440 }
04441
04442
04443
04444
04445 int SUM_close(SUM_t *sums, int (*history)(const char *fmt, ...))
04446 {
04447 return sumsopenClose(sums, kMTSums_CallType_Close, history);
04448 }
04449
04450 int SUM_rollback(SUM_t *sums, int (*history)(const char *fmt, ...))
04451 {
04452 return sumsopenClose(sums, kMTSums_CallType_Rollback, history);
04453 }
04454
04455 #else
04456
04457
04458
04459 #endif
04460
04461 #if defined(SUMS_USEMTSUMS_INFO) && SUMS_USEMTSUMS_INFO
04462
04463
04464 void SUM_infoArray_free(SUM_t *sums)
04465 {
04466 if(sums->sinfo)
04467 {
04468 free(sums->sinfo);
04469 sums->sinfo = NULL;
04470 }
04471 }
04472
04473
04474
04475
04476 int SUM_infoArray(SUM_t *sums, uint64_t *sunums, int reqcnt, int (*history)(const char *fmt, ...))
04477 {
04478 JSONIZER_DATA_INFO_t data;
04479
04480 if (reqcnt > MAX_MTSUMS_NSUS)
04481 {
04482 (*history)("Too many SUs in request (maximum of %d allowed).\n", reqcnt, MAX_MTSUMS_NSUS);
04483 return 1;
04484 }
04485
04486
04487 data.sunums = sunums;
04488 data.nSus = reqcnt;
04489
04490 return callMTSums(sums, kMTSums_CallType_Info, (JSONIZER_DATA_t *)(&data), history);
04491 }
04492 #else
04493
04494
04495 #endif
04496
04497 #if defined(SUMS_USEMTSUMS_GET) && SUMS_USEMTSUMS_GET
04498
04499
04500
04501
04502
04503
04504
04505
04506
04507
04508
04509
04510
04511
04512
04513 int SUM_get(SUM_t *sums, int (*history)(const char *fmt, ...))
04514 {
04515 JSONIZER_DATA_GET_t data;
04516 int rv = 0;
04517
04518 if (sums->reqcnt > MAX_MTSUMS_NSUS)
04519 {
04520 (*history)("Too many SUs in request (maximum of %d allowed).\n", sums->reqcnt, MAX_MTSUMS_NSUS);
04521 return 1;
04522 }
04523
04524
04525 data.touch = sums->mode & TOUCH;
04526 data.retrieve = sums->mode & RETRIEVE;
04527 data.retention = sums->tdays;
04528 data.sunums = sums->dsix_ptr;
04529 data.nSus = sums->reqcnt;
04530
04531
04532
04533 sums->dsname = NULL;
04534
04535
04536 return callMTSums(sums, kMTSums_CallType_Get, (JSONIZER_DATA_t *)(&data), history);
04537 }
04538 #else
04539
04540 #endif
04541
04542 #if defined(SUMS_USEMTSUMS_ALLOC) && SUMS_USEMTSUMS_ALLOC
04543
04544
04545
04546
04547
04548
04549
04550
04551
04552
04553
04554
04555
04556
04557
04558
04559
04560
04561
04562
04563
04564
04565 int SUM_alloc(SUM_t *sums, int (*history)(const char *fmt, ...))
04566 {
04567 JSONIZER_DATA_ALLOC_t data;
04568
04569 data.sugroup = sums->group;
04570 data.numBytes = sums->bytes;
04571
04572 return callMTSums(sums, kMTSums_CallType_Alloc, (JSONIZER_DATA_t *)(&data), history);
04573 }
04574
04575 int SUM_alloc2(SUM_t *sums, uint64_t sunum, int (*history)(const char *fmt, ...))
04576 {
04577 JSONIZER_DATA_ALLOC2_t data;
04578
04579 data.sunum = sunum;
04580 data.sugroup = sums->group;
04581 data.numBytes = sums->bytes;
04582
04583 return callMTSums(sums, kMTSums_CallType_Alloc2, (JSONIZER_DATA_t *)(&data), history);
04584 }
04585 #else
04586
04587 #endif
04588
04589 #if defined(SUMS_USEMTSUMS_PUT) && SUMS_USEMTSUMS_PUT
04590
04591
04592
04593
04594
04595
04596
04597
04598
04599
04600
04601
04602
04603
04604
04605
04606
04607
04608
04609
04610
04611
04612
04613
04614
04615
04616
04617
04618
04619
04620
04621
04622 int SUM_put(SUM_t *sums, int (*history)(const char *fmt, ...))
04623 {
04624 JSONIZER_DATA_PUT_t data;
04625 int err;
04626
04627 data.sunums = sums->dsix_ptr;
04628 data.sudirs = sums->wd;
04629 data.nSus = sums->reqcnt;
04630 data.series = sums->dsname;
04631 data.retention = sums->tdays;
04632
04633 data.archiveType = (sums->mode & PERM) ? "permanent+archive" : ((sums->mode & TEMP) ? "temporary+noarchive" : ((sums->mode & ARCH) ? "temporary+archive" : "temporary+noarchive"));
04634
04635 err = callMTSums(sums, kMTSums_CallType_Put, (JSONIZER_DATA_t *)(&data), history);
04636
04637 return err;
04638 }
04639
04640 #else
04641
04642 #endif
04643
04644 #if defined(SUMS_USEMTSUMS_DELETESUS) && SUMS_USEMTSUMS_DELETESUS
04645
04646
04647
04648
04649
04650
04651
04652
04653
04654
04655
04656
04657
04658
04659
04660
04661
04662
04663
04664
04665
04666
04667 int SUM_delete_series(SUM_t *sums, char *filename, char *seriesname, int (*history)(const char *fmt, ...))
04668 {
04669 JSONIZER_DATA_DELETESERIES_t data;
04670
04671 data.series = seriesname;
04672
04673 return callMTSums(sums, kMTSums_CallType_Deleteseries, (JSONIZER_DATA_t *)(&data), history);
04674 }
04675 #else
04676
04677 #endif
04678
04679 #if defined(SUMS_USEMTSUMS_ALL) && SUMS_USEMTSUMS_ALL
04680 int SUM_nop(SUM_t *sum, int (*history)(const char *fmt, ...))
04681 {
04682 return sumsopenNopMT(sum, history);
04683 }
04684
04685 int SUM_poll(SUM_t *sum)
04686 {
04687 return sumsopenPollMT(sum);
04688 }
04689 #else
04690 int SUM_nop(SUM_t *sum, int (*history)(const char *fmt, ...))
04691 {
04692 if (clprev != NULL)
04693 {
04694 return sumsopenNopRPC(sum, history);
04695 }
04696 else
04697 {
04698 return sumsopenNopMT(sum, history);
04699 }
04700 }
04701
04702 int SUM_poll(SUM_t *sum)
04703 {
04704 if (clprev != NULL)
04705 {
04706 return sumsopenPollRPC(sum);
04707 }
04708 else
04709 {
04710 return sumsopenPollMT(sum);
04711 }
04712 }
04713
04714 #endif
04715
04716
04717
04718
04719
04720
04721
04722
04723
04724
04725
04726
04727
04728 #endif
04729
04730
04731 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_CONNECTION) || !SUMS_USEMTSUMS_CONNECTION)
04732 SUM_t *SUM_open(char *server, char *db, int (*history)(const char *fmt, ...))
04733 {
04734 return sumsopenOpen(server, db, history);
04735 }
04736
04737 int SUM_close(SUM_t *sum, int (*history)(const char *fmt, ...))
04738 {
04739 return sumsopenClose(sum, history);
04740 }
04741 #endif
04742
04743
04744 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
04745
04746
04747
04748
04749
04750 int SUM_info(SUM_t *sum, uint64_t sunum, int (*history)(const char *fmt, ...))
04751 {
04752 KEY *klist;
04753 char *call_err;
04754 uint32_t retstat;
04755 int msgstat;
04756 enum clnt_stat status;
04757
04758 klist = newkeylist();
04759 setkey_uint64(&klist, "SUNUM", sunum);
04760 setkey_str(&klist, "username", sum->username);
04761 setkey_uint64(&klist, "uid", sum->uid);
04762 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
04763 setkey_int(&klist, "REQCODE", INFODO);
04764 clprev = sum->clinfo;
04765
04766
04767 status = clnt_call(sum->clinfo, INFODO, (xdrproc_t)xdr_Rkey, (char *)klist,
04768 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
04769
04770
04771
04772
04773
04774 if(status != RPC_SUCCESS) {
04775 if(status != RPC_TIMEDOUT) {
04776 call_err = clnt_sperror(sum->clinfo, "Err clnt_call for INFODO");
04777 if(history)
04778 (*history)("%s %d %s\n", datestring(), status, call_err);
04779 freekeylist(&klist);
04780 return (4);
04781 }
04782 }
04783 if(retstat) {
04784 if(retstat != SUM_SUNUM_NOT_LOCAL)
04785 if(history)
04786 (*history)("Error in SUM_info()\n");
04787 return(retstat);
04788 }
04789 else {
04790 if(sum->sinfo == NULL)
04791 sum->sinfo = (SUM_info_t *)malloc(sizeof(SUM_info_t));
04792 msgstat = getanymsg(1);
04793 freekeylist(&klist);
04794 if(msgstat == ERRMESS) return(ERRMESS);
04795
04796
04797 return(0);
04798 }
04799 }
04800
04801
04802
04803
04804 void SUM_infoEx_free(SUM_t *sum)
04805 {
04806 SUM_info_t *sinfowalk, *next;
04807
04808 sinfowalk = sum->sinfo;
04809 sum->sinfo = NULL;
04810 while(sinfowalk) {
04811 next = sinfowalk->next;
04812 free(sinfowalk);
04813 sinfowalk = next;
04814 }
04815 }
04816
04817
04818
04819
04820
04821
04822
04823
04824 int SUM_infoEx(SUM_t *sum, int (*history)(const char *fmt, ...))
04825 {
04826 int rr;
04827 KEY *klist;
04828 SUM_info_t *sinfowalk;
04829 char *call_err;
04830 char dsix_name[64];
04831 uint32_t retstat;
04832 uint64_t *dxlong;
04833 int i,msgstat;
04834 enum clnt_stat status;
04835
04836 if(sum->reqcnt > MAXSUMREQCNT) {
04837 (*history)("Requent count of %d > max of %d\n", sum->reqcnt, MAXSUMREQCNT);
04838 return(1);
04839 }
04840 klist = newkeylist();
04841 setkey_str(&klist, "username", sum->username);
04842 setkey_uint64(&klist, "uid", sum->uid);
04843 setkey_int(&klist, "reqcnt", sum->reqcnt);
04844 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
04845 setkey_int(&klist, "REQCODE", INFODOX);
04846 dxlong = sum->dsix_ptr;
04847 for(i = 0; i < sum->reqcnt; i++) {
04848 sprintf(dsix_name, "dsix_%d", i);
04849 setkey_uint64(&klist, dsix_name, *dxlong++);
04850 }
04851 rr = rr_random(0, numSUM-1);
04852 switch(rr) {
04853 case 0:
04854 clinfo = sum->clinfo;
04855 break;
04856 case 1:
04857 clinfo = sum->clinfo1;
04858 break;
04859 case 2:
04860 clinfo = sum->clinfo2;
04861 break;
04862 case 3:
04863 clinfo = sum->clinfo3;
04864 break;
04865 case 4:
04866 clinfo = sum->clinfo4;
04867 break;
04868 case 5:
04869 clinfo = sum->clinfo5;
04870 break;
04871 case 6:
04872 clinfo = sum->clinfo6;
04873 break;
04874 case 7:
04875 clinfo = sum->clinfo7;
04876 break;
04877 }
04878 clprev = clinfo;
04879 status = clnt_call(clinfo, INFODOX, (xdrproc_t)xdr_Rkey, (char *)klist,
04880 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
04881
04882
04883
04884
04885
04886 if(status != RPC_SUCCESS) {
04887 if(status != RPC_TIMEDOUT) {
04888 call_err = clnt_sperror(clinfo, "Err clnt_call for INFODOX");
04889 if(history)
04890 (*history)("%s %d %s\n", datestring(), status, call_err);
04891 freekeylist(&klist);
04892 return (4);
04893 }
04894 }
04895 if(retstat) {
04896 if(retstat != SUM_SUNUM_NOT_LOCAL)
04897 if(history)
04898 (*history)("Error in SUM_infoEx()\n");
04899 return(retstat);
04900 }
04901 else {
04902 if(sum->sinfo == NULL) {
04903 sum->sinfo = (SUM_info_t *)malloc(sizeof(SUM_info_t));
04904 sinfowalk = sum->sinfo;
04905 sinfowalk->next = NULL;
04906 for(i = 1; i < sum->reqcnt; i++) {
04907 sinfowalk->next = (SUM_info_t *)malloc(sizeof(SUM_info_t));
04908 sinfowalk = sinfowalk->next;
04909 sinfowalk->next = NULL;
04910 }
04911 }
04912 else {
04913 (*history)("\nAssumes user has malloc'd linked list of (SUM_info_t *)\n");
04914 (*history)("Else set sum->sinfo = NULL before SUM_infoEx() call\n");
04915 }
04916 msgstat = getanymsg(1);
04917 freekeylist(&klist);
04918 if(msgstat == ERRMESS) return(ERRMESS);
04919
04920
04921 return(0);
04922 }
04923 }
04924
04925
04926
04927
04928 void SUM_infoArray_free(SUM_t *sum)
04929 {
04930 if(sum->sinfo) free(sum->sinfo);
04931 sum->sinfo = NULL;
04932 }
04933
04934
04935
04936
04937
04938
04939
04940
04941
04942
04943
04944
04945 int SUM_infoArray(SUM_t *sum, uint64_t *dxarray, int reqcnt, int (*history)(const char *fmt, ...))
04946 {
04947 int rr;
04948 Sunumarray suarray;
04949 SUM_info_t *sinfowalk;
04950 char *call_err, *jsoc_machine;
04951 uint32_t retstat;
04952 int i,msgstat;
04953 enum clnt_stat status;
04954
04955 if(reqcnt > MAXSUNUMARRAY) {
04956 (*history)("Requent count of %d > max of %d\n", reqcnt, MAXSUNUMARRAY);
04957 return(1);
04958 }
04959 suarray.reqcnt = reqcnt;
04960 suarray.mode = sum->mode;
04961 suarray.tdays = sum->tdays;
04962 suarray.reqcode = INFODOARRAY;
04963 suarray.uid = sum->uid;
04964 suarray.username = sum->username;
04965 if(!(jsoc_machine = (char *)getenv("JSOC_MACHINE"))) {
04966
04967
04968 jsoc_machine = "linux_x86_64";
04969 }
04970 suarray.machinetype = jsoc_machine;
04971 suarray.sunums = dxarray;
04972
04973 rr = rr_random(0, numSUM-1);
04974 switch(rr) {
04975 case 0:
04976 clinfo = sum->clinfo;
04977 break;
04978 case 1:
04979 clinfo = sum->clinfo1;
04980 break;
04981 case 2:
04982 clinfo = sum->clinfo2;
04983 break;
04984 case 3:
04985 clinfo = sum->clinfo3;
04986 break;
04987 case 4:
04988 clinfo = sum->clinfo4;
04989 break;
04990 case 5:
04991 clinfo = sum->clinfo5;
04992 break;
04993 case 6:
04994 clinfo = sum->clinfo6;
04995 break;
04996 case 7:
04997 clinfo = sum->clinfo7;
04998 break;
04999 }
05000 clprev = clinfo;
05001 status = clnt_call(clinfo, INFODOARRAY, (xdrproc_t)xdr_Sunumarray, (char *)&suarray,
05002 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05003
05004
05005
05006
05007
05008 if(status != RPC_SUCCESS) {
05009 if(status != RPC_TIMEDOUT) {
05010 call_err = clnt_sperror(clinfo, "Err clnt_call for INFODOX");
05011 if(history)
05012 (*history)("%s %d %s\n", datestring(), status, call_err);
05013
05014 return (4);
05015 }
05016 }
05017 if(retstat) {
05018 if(retstat != SUM_SUNUM_NOT_LOCAL)
05019 if(history)
05020 (*history)("Error in SUM_infoArray()\n");
05021 return(retstat);
05022 }
05023 else {
05024
05025
05027
05028
05029
05030
05031
05032
05033
05034
05035
05036 msgstat = getanymsg(1);
05037
05038 if(msgstat == ERRMESS) return(ERRMESS);
05039
05040
05041 return(0);
05042 }
05043 }
05044 #endif
05045
05046
05047 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_GET) || !SUMS_USEMTSUMS_GET)
05048
05049
05050
05051
05052
05053
05054
05055
05056
05057
05058 int SUM_get(SUM_t *sum, int (*history)(const char *fmt, ...))
05059 {
05060 int rr;
05061 KEY *klist;
05062 char *call_err, *dptr;
05063 char **cptr;
05064 int i, cnt, msgstat, stat, xmode, pid;
05065 char dsix_name[64], thishost[80];
05066 uint64_t *dxlong;
05067 uint32_t retstat;
05068 enum clnt_stat status;
05069
05070 if(sum->debugflg) {
05071 (*history)("SUM_get() call:\n");
05072 }
05073 if(sum->reqcnt > MAXSUMREQCNT) {
05074 (*history)("Requent count of %d > max of %d\n", sum->reqcnt, MAXSUMREQCNT);
05075 return(1);
05076 }
05077 gethostname(thishost, 80);
05078 dptr = index(thishost, '.');
05079 if(dptr) *dptr = '\0';
05080 pid = getpid();
05081 klist = newkeylist();
05082 setkey_uint64(&klist, "uid", sum->uid);
05083 setkey_int(&klist, "mode", sum->mode);
05084 setkey_int(&klist, "tdays", sum->tdays);
05085 setkey_int(&klist, "reqcnt", sum->reqcnt);
05086 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
05087 setkey_int(&klist, "REQCODE", GETDO);
05088 setkey_str(&klist, "username", sum->username);
05089 setkey_int(&klist, "newflg", GET_FIX_VER);
05090 setkey_int(&klist, "pidcaller", pid);
05091 setkey_str(&klist, "hostcaller", thishost);
05092
05093 dxlong = sum->dsix_ptr;
05094 for(i = 0; i < sum->reqcnt; i++) {
05095 sprintf(dsix_name, "dsix_%d", i);
05096 setkey_uint64(&klist, dsix_name, *dxlong++);
05097 }
05098 rr = rr_random(0, numSUM-1);
05099 switch(rr) {
05100 case 0:
05101 clget = sum->clget;
05102 break;
05103 case 1:
05104 clget = sum->clget1;
05105 break;
05106 case 2:
05107 clget = sum->clget2;
05108 break;
05109 case 3:
05110 clget = sum->clget3;
05111 break;
05112 case 4:
05113 clget = sum->clget4;
05114 break;
05115 case 5:
05116 clget = sum->clget5;
05117 break;
05118 case 6:
05119 clget = sum->clget6;
05120 break;
05121 case 7:
05122 clget = sum->clget7;
05123 break;
05124 }
05125 sum->mode = sum->mode + TAPERDON;
05126 stat = TAPERDON;
05127 xmode = -stat-1;
05128 clprev = clget;
05129 status = clnt_call(clget, GETDO, (xdrproc_t)xdr_Rkey, (char *)klist,
05130 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05131
05132
05133
05134
05135
05136 if(status != RPC_SUCCESS) {
05137 if(status != RPC_TIMEDOUT) {
05138 sum->mode = sum->mode & xmode;
05139 call_err = clnt_sperror(clget, "Err clnt_call for GETDO");
05140 (*history)("%s %d %s\n", datestring(), status, call_err);
05141 freekeylist(&klist);
05142 return (4);
05143 } else {
05144 (*history)("%s Ignore timeout in SUM_get()\n", datestring());
05145 }
05146 }
05147 freekeylist(&klist);
05148 if(sum->debugflg) {
05149 (*history)("retstat in SUM_get = %ld\n", retstat);
05150 }
05151 if(retstat == 1) {
05152 sum->mode = sum->mode & xmode;
05153 return(1);
05154 }
05155 if(retstat == RESULT_PEND) {
05156
05157 return((int)retstat);
05158 }
05159 sum->mode = sum->mode & xmode;
05160 msgstat = getanymsg(1);
05161 if(msgstat == ERRMESS) return(ERRMESS);
05162 if(sum->debugflg) {
05163
05164 (*history)("In SUM_get() the wd's found are:\n");
05165 cnt = sum->reqcnt;
05166 cptr = sum->wd;
05167 for(i = 0; i < cnt; i++) {
05168 printf("wd = %s\n", *cptr++);
05169 }
05170 }
05171 return(sum->status);
05172 }
05173 #endif
05174
05175
05176 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALLOC) || !SUMS_USEMTSUMS_ALLOC)
05177
05178
05179
05180
05181 int SUM_alloc(SUM_t *sum, int (*history)(const char *fmt, ...))
05182 {
05183 int rr;
05184 KEY *klist;
05185 char *call_err;
05186 uint32_t retstat;
05187 int msgstat;
05188 enum clnt_stat status;
05189
05190 if(sum->reqcnt != 1) {
05191 (*history)("Invalid reqcnt = %d for SUM_alloc(). Can only alloc 1.\n",
05192 sum->reqcnt);
05193 return(1);
05194 }
05195 klist = newkeylist();
05196 setkey_double(&klist, "bytes", sum->bytes);
05197 setkey_int(&klist, "storeset", sum->storeset);
05198 setkey_int(&klist, "group", sum->group);
05199 setkey_int(&klist, "reqcnt", sum->reqcnt);
05200 setkey_uint64(&klist, "uid", sum->uid);
05201 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
05202 setkey_int(&klist, "REQCODE", ALLOCDO);
05203 setkey_str(&klist, "USER", sum->username);
05204 if(sum->debugflg) {
05205 (*history)("In SUM_alloc() the keylist is:\n");
05206 keyiterate(printkey, klist);
05207 }
05208 rr = rr_random(0, numSUM-1);
05209 switch(rr) {
05210 case 0:
05211 clalloc = sum->clalloc;
05212 break;
05213 case 1:
05214 clalloc = sum->clalloc1;
05215 break;
05216 case 2:
05217 clalloc = sum->clalloc2;
05218 break;
05219 case 3:
05220 clalloc = sum->clalloc3;
05221 break;
05222 case 4:
05223 clalloc = sum->clalloc4;
05224 break;
05225 case 5:
05226 clalloc = sum->clalloc5;
05227 break;
05228 case 6:
05229 clalloc = sum->clalloc6;
05230 break;
05231 case 7:
05232 clalloc = sum->clalloc7;
05233 break;
05234 }
05235 clprev = clalloc;
05236 status = clnt_call(clalloc, ALLOCDO, (xdrproc_t)xdr_Rkey, (char *)klist,
05237 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05238
05239
05240
05241
05242
05243 if(status != RPC_SUCCESS) {
05244 if(status != RPC_TIMEDOUT) {
05245 call_err = clnt_sperror(clalloc, "Err clnt_call for ALLOCDO");
05246 (*history)("%s %d %s\n", datestring(), status, call_err);
05247 freekeylist(&klist);
05248 return (4);
05249 }
05250 }
05251 if(retstat) {
05252 (*history)("Error in SUM_alloc()\n");
05253 freekeylist(&klist);
05254 return(retstat);
05255 }
05256 else {
05257 msgstat = getanymsg(1);
05258 freekeylist(&klist);
05259 if(msgstat == ERRMESS) return(ERRMESS);
05260 return(sum->status);
05261 }
05262 }
05263
05264
05265
05266
05267
05268 int SUM_alloc2(SUM_t *sum, uint64_t sunum, int (*history)(const char *fmt, ...))
05269 {
05270 KEY *klist;
05271 char *call_err;
05272 uint32_t retstat;
05273 int msgstat;
05274 enum clnt_stat status;
05275
05277
05278
05279
05280 if(sum->reqcnt != 1) {
05281 (*history)("Invalid reqcnt = %d for SUM_alloc2(). Can only alloc 1.\n",
05282 sum->reqcnt);
05283 return(1);
05284 }
05285 klist = newkeylist();
05286 setkey_double(&klist, "bytes", sum->bytes);
05287 setkey_int(&klist, "storeset", sum->storeset);
05288 setkey_int(&klist, "group", sum->group);
05289 setkey_int(&klist, "reqcnt", sum->reqcnt);
05290 setkey_uint64(&klist, "uid", sum->uid);
05291 setkey_uint64(&klist, "SUNUM", sunum);
05292 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
05293 setkey_int(&klist, "REQCODE", ALLOCDO);
05294 setkey_str(&klist, "USER", sum->username);
05295 if(sum->debugflg) {
05296 (*history)("In SUM_alloc2() the keylist is:\n");
05297 keyiterate(printkey, klist);
05298 }
05299 clprev = sum->clalloc;
05300
05301 status = clnt_call(sum->clalloc, ALLOCDO, (xdrproc_t)xdr_Rkey, (char *)klist,
05302 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05303
05304
05305
05306
05307
05308 if(status != RPC_SUCCESS) {
05309 if(status != RPC_TIMEDOUT) {
05310 call_err = clnt_sperror(sum->clalloc, "Err clnt_call for ALLOCDO");
05311 (*history)("%s %d %s\n", datestring(), status, call_err);
05312 freekeylist(&klist);
05313 return (4);
05314 }
05315 }
05316 if(retstat) {
05317 (*history)("Error in SUM_alloc2()\n");
05318 return(retstat);
05319 }
05320 else {
05321 msgstat = getanymsg(1);
05322 freekeylist(&klist);
05323 if(msgstat == ERRMESS) return(ERRMESS);
05324 return(sum->status);
05325 }
05326 }
05327 #endif
05328
05329
05330 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_PUT) || !SUMS_USEMTSUMS_PUT)
05331
05332
05333
05334
05335
05336
05337 int SUM_put(SUM_t *sum, int (*history)(const char *fmt, ...))
05338 {
05339 int rr;
05340 KEY *klist;
05341 char dsix_name[64];
05342 char *call_err;
05343 char **cptr;
05344 uint64_t *dsixpt;
05345 int i, cnt, msgstat;
05346 uint32_t retstat;
05347 enum clnt_stat status;
05348
05349 cptr = sum->wd;
05350 dsixpt = sum->dsix_ptr;
05351 if(sum->debugflg) {
05352 (*history)("Going to PUT reqcnt=%d with 1st wd=%s, ix=%lu\n",
05353 sum->reqcnt, *cptr, *dsixpt);
05354 }
05355 klist = newkeylist();
05356
05357 setkey_uint64(&klist, "uid", sum->uid);
05358 setkey_int(&klist, "mode", sum->mode);
05359 setkey_int(&klist, "tdays", sum->tdays);
05360 setkey_int(&klist, "reqcnt", sum->reqcnt);
05361 setkey_str(&klist, "dsname", sum->dsname);
05362 setkey_str(&klist, "history_comment", sum->history_comment);
05363 setkey_str(&klist, "username", sum->username);
05364 setkey_int(&klist, "group", sum->group);
05365
05366
05367
05368 setkey_int(&klist, "storage_set", sum->storeset);
05369
05370 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
05371 setkey_int(&klist, "REQCODE", PUTDO);
05372 for(i = 0; i < sum->reqcnt; i++) {
05373 sprintf(dsix_name, "dsix_%d", i);
05374 setkey_uint64(&klist, dsix_name, *dsixpt++);
05375 sprintf(dsix_name, "wd_%d", i);
05376 setkey_str(&klist, dsix_name, *cptr++);
05377 }
05378 rr = rr_random(0, numSUM-1);
05379 switch(rr) {
05380 case 0:
05381 clput = sum->clput;
05382 break;
05383 case 1:
05384 clput = sum->clput1;
05385 break;
05386 case 2:
05387 clput = sum->clput2;
05388 break;
05389 case 3:
05390 clput = sum->clput3;
05391 break;
05392 case 4:
05393 clput = sum->clput4;
05394 break;
05395 case 5:
05396 clput = sum->clput5;
05397 break;
05398 case 6:
05399 clput = sum->clput6;
05400 break;
05401 case 7:
05402 clput = sum->clput7;
05403 break;
05404 }
05405 clprev = clput;
05406 status = clnt_call(clput, PUTDO, (xdrproc_t)xdr_Rkey, (char *)klist,
05407 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05408
05409
05410
05411
05412
05413 if(status != RPC_SUCCESS) {
05414 if(status != RPC_TIMEDOUT) {
05415 call_err = clnt_sperror(clput, "Err clnt_call for PUTDO");
05416 (*history)("%s %d %s\n", datestring(), status, call_err);
05417 freekeylist(&klist);
05418 return (4);
05419 }
05420 }
05421 freekeylist(&klist);
05422 if(retstat == 1) return(1);
05423
05424
05425 msgstat = getanymsg(1);
05426 if(msgstat == ERRMESS) return(ERRMESS);
05427 if(sum->debugflg) {
05428 (*history)("In SUM_put() print out wd's \n");
05429 cnt = sum->reqcnt;
05430 cptr = sum->wd;
05431 for(i = 0; i < cnt; i++) {
05432 printf("wd = %s\n", *cptr++);
05433 }
05434 }
05435 return(sum->status);
05436 }
05437 #endif
05438
05439
05440 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_DELETESUS) || !SUMS_USEMTSUMS_DELETESUS)
05441
05442
05443
05444
05445
05446
05447
05448 int SUM_delete_series(SUM_t *sum, char *filename, char *seriesname, int (*history)(const char *fmt, ...))
05449 {
05450 KEY *klist;
05451 CLIENT *cl;
05452 char *call_err;
05453 char *cptr, *server_name, *username;
05454 uint32_t retstat;
05455 enum clnt_stat status;
05456
05457 klist = newkeylist();
05458 if(!(username = (char *)getenv("USER"))) username = "nouser";
05459 setkey_str(&klist, "USER", username);
05460 setkey_int(&klist, "DEBUGFLG", 1);
05461 setkey_str(&klist, "FILE", filename);
05462 setkey_str(&klist, "SERIESNAME", seriesname);
05463 if (!(server_name = getenv("SUMSERVER"))) {
05464 server_name = (char *)alloca(sizeof(SUMSERVER)+1);
05465 strcpy(server_name, SUMSERVER);
05466 }
05467 cptr = (char *)index(server_name, '.');
05468 if(cptr) *cptr = '\0';
05469
05470 clprev = sum->cldelser;
05471 status = clnt_call(sum->cldelser, DELSERIESDO, (xdrproc_t)xdr_Rkey, (char *)klist,
05472 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05473
05474
05475
05476
05477
05478 if(status != RPC_SUCCESS) {
05479 if(status != RPC_TIMEDOUT) {
05480 call_err = clnt_sperror(cldelser, "Err clnt_call for DELSERIESDO");
05481 (*history)("%s %d %s\n", datestring(), status, call_err);
05482 freekeylist(&klist);
05483 return (4);
05484 }
05485 }
05486 freekeylist(&klist);
05487
05488 if(retstat == 1) return(1);
05489 return(0);
05490 }
05491 #endif
05492
05493
05494 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
05495
05496
05497
05498
05499
05500
05501 int SUM_wait(SUM_t *sum)
05502 {
05503 int stat, xmode;
05504
05505 while(1) {
05506 stat = getanymsg(0);
05507 if(stat == TIMEOUTMSG) {
05508 usleep(1000);
05509 continue;
05510 }
05511 else break;
05512 }
05513 if(stat == RPCMSG) {
05514
05515
05516
05517 taperdon_cleared = 1;
05518 return(0);
05519 }
05520 else return(stat);
05521 }
05522 #endif
05523
05524
05525
05526
05527
05528
05529
05530
05531 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS)
05532 int SUM_nop(SUM_t *sum, int (*history)(const char *fmt, ...))
05533 {
05534 return sumsopenNopRPC(sum, history);
05535 }
05536
05537 int SUM_poll(SUM_t *sum)
05538 {
05539 return sumsopenPollRPC(sum);
05540 }
05541 #endif
05542
05543 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
05544
05545
05546
05547
05548
05549
05550 int SUM_repartn_ck_error(int stat, uint32_t rstat, CLIENT *rcl, int (*history)(const char *fmt, ...))
05551 {
05552 char *call_err;
05553
05554 if(stat != RPC_SUCCESS) {
05555 if(stat != RPC_TIMEDOUT) {
05556 call_err = clnt_sperror(rcl, "Err clnt_call for SUMREPARTN");
05557 (*history)("%s %d %s\n", datestring(), stat, call_err);
05558 return (1);
05559 }
05560 }
05561 if(rstat) {
05562 return(1);
05563 }
05564 return(0);
05565 }
05566
05567
05568
05569
05570
05571
05572
05573 int SUM_repartn(SUM_t *sum, int (*history)(const char *fmt, ...))
05574 {
05575 KEY *klist;
05576 char *call_err;
05577 uint32_t retstat;
05578 enum clnt_stat status;
05579 int stat;
05580 int failflg = 0;
05581
05582 if(sum->debugflg) {
05583 (*history)("SUM_repartn() call: uid = %lu\n", sum->uid);
05584 }
05585 klist = newkeylist();
05586 setkey_uint64(&klist, "uid", sum->uid);
05587 setkey_int(&klist, "DEBUGFLG", sum->debugflg);
05588 setkey_str(&klist, "USER", sum->username);
05589 if(numSUM == 1) {
05590 status = clnt_call(sum->cl, SUMREPARTN, (xdrproc_t)xdr_Rkey, (char *)klist,
05591 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05592 if(status = SUM_repartn_ck_error(status, retstat, sum->cl, history)) {
05593 (*history)("SUM_repartn() failed on call to sum_svc\n");
05594 freekeylist(&klist);
05595 return (1);
05596 }
05597 }
05598 else {
05599 status = clnt_call(sum->cl, SUMREPARTN, (xdrproc_t)xdr_Rkey, (char *)klist,
05600 (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05601 if(status = SUM_repartn_ck_error(status, retstat, sum->cl, history)) {
05602 (*history)("SUM_repartn() failed on call to sum_svc\n");
05603 failflg = 1;
05604 }
05605 if(sum->clalloc) {
05606 status = clnt_call(sum->clalloc, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05607 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05608 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc,history)) {
05609 (*history)("SUM_repartn() failed on call to Salloc\n");
05610 failflg = 1;
05611 }
05612 }
05613 if(sum->clalloc1) {
05614 status = clnt_call(sum->clalloc1, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05615 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05616 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc1,history)) {
05617 (*history)("SUM_repartn() failed on call to Salloc1\n");
05618 failflg = 1;
05619 }
05620 }
05621 if(sum->clalloc2) {
05622 status = clnt_call(sum->clalloc2, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05623 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05624 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc2,history)) {
05625 (*history)("SUM_repartn() failed on call to Salloc2\n");
05626 failflg = 1;
05627 }
05628 }
05629 if(sum->clalloc3) {
05630 status = clnt_call(sum->clalloc3, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05631 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05632 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc3,history)) {
05633 (*history)("SUM_repartn() failed on call to Salloc3\n");
05634 failflg = 1;
05635 }
05636 }
05637 if(sum->clalloc4) {
05638 status = clnt_call(sum->clalloc4, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05639 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05640 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc4,history)) {
05641 (*history)("SUM_repartn() failed on call to Salloc4\n");
05642 failflg = 1;
05643 }
05644 }
05645 if(sum->clalloc5) {
05646 status = clnt_call(sum->clalloc5, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05647 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05648 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc5,history)) {
05649 (*history)("SUM_repartn() failed on call to Salloc5\n");
05650 failflg = 1;
05651 }
05652 }
05653 if(sum->clalloc6) {
05654 status = clnt_call(sum->clalloc6, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05655 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05656 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc6,history)) {
05657 (*history)("SUM_repartn() failed on call to Salloc6\n");
05658 failflg = 1;
05659 }
05660 }
05661 if(sum->clalloc7) {
05662 status = clnt_call(sum->clalloc7, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05663 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05664 if(status = SUM_repartn_ck_error(status,retstat,sum->clalloc7,history)) {
05665 (*history)("SUM_repartn() failed on call to Salloc7\n");
05666 failflg = 1;
05667 }
05668 }
05669 if(sum->clget) {
05670 status = clnt_call(sum->clget, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05671 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05672 if(status = SUM_repartn_ck_error(status,retstat,sum->clget,history)) {
05673 (*history)("SUM_repartn() failed on call to Sget\n");
05674 failflg = 1;
05675 }
05676 }
05677 if(sum->clget1) {
05678 status = clnt_call(sum->clget1, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05679 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05680 if(status = SUM_repartn_ck_error(status,retstat,sum->clget1,history)) {
05681 (*history)("SUM_repartn() failed on call to Sget1\n");
05682 failflg = 1;
05683 }
05684 }
05685 if(sum->clget2) {
05686 status = clnt_call(sum->clget2, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05687 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05688 if(status = SUM_repartn_ck_error(status,retstat,sum->clget2,history)) {
05689 (*history)("SUM_repartn() failed on call to Sget2\n");
05690 failflg = 1;
05691 }
05692 }
05693 if(sum->clget3) {
05694 status = clnt_call(sum->clget3, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05695 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05696 if(status = SUM_repartn_ck_error(status,retstat,sum->clget3,history)) {
05697 (*history)("SUM_repartn() failed on call to Sget3\n");
05698 failflg = 1;
05699 }
05700 }
05701 if(sum->clget4) {
05702 status = clnt_call(sum->clget4, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05703 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05704 if(status = SUM_repartn_ck_error(status,retstat,sum->clget4,history)) {
05705 (*history)("SUM_repartn() failed on call to Sget4\n");
05706 failflg = 1;
05707 }
05708 }
05709 if(sum->clget5) {
05710 status = clnt_call(sum->clget5, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05711 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05712 if(status = SUM_repartn_ck_error(status,retstat,sum->clget5,history)) {
05713 (*history)("SUM_repartn() failed on call to Sget5\n");
05714 failflg = 1;
05715 }
05716 }
05717 if(sum->clget6) {
05718 status = clnt_call(sum->clget6, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05719 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05720 if(status = SUM_repartn_ck_error(status,retstat,sum->clget6,history)) {
05721 (*history)("SUM_repartn() failed on call to Sget6\n");
05722 failflg = 1;
05723 }
05724 }
05725 if(sum->clget7) {
05726 status = clnt_call(sum->clget7, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05727 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05728 if(status = SUM_repartn_ck_error(status,retstat,sum->clget7,history)) {
05729 (*history)("SUM_repartn() failed on call to Sget7\n");
05730 failflg = 1;
05731 }
05732 }
05733
05734 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_INFO) || !SUMS_USEMTSUMS_INFO)
05735 if(sum->clinfo) {
05736 status = clnt_call(sum->clinfo, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05737 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05738 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo,history)) {
05739 (*history)("SUM_repartn() failed on call to Sinfo\n");
05740 failflg = 1;
05741 }
05742 }
05743 if(sum->clinfo1) {
05744 status = clnt_call(sum->clinfo1, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05745 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05746 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo1,history)) {
05747 (*history)("SUM_repartn() failed on call to Sinfo1\n");
05748 failflg = 1;
05749 }
05750 }
05751 if(sum->clinfo2) {
05752 status = clnt_call(sum->clinfo2, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05753 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05754 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo2,history)) {
05755 (*history)("SUM_repartn() failed on call to Sinfo2\n");
05756 failflg = 1;
05757 }
05758 }
05759 if(sum->clinfo3) {
05760 status = clnt_call(sum->clinfo3, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05761 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05762 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo3,history)) {
05763 (*history)("SUM_repartn() failed on call to Sinfo3\n");
05764 failflg = 1;
05765 }
05766 }
05767 if(sum->clinfo4) {
05768 status = clnt_call(sum->clinfo4, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05769 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05770 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo4,history)) {
05771 (*history)("SUM_repartn() failed on call to Sinfo4\n");
05772 failflg = 1;
05773 }
05774 }
05775 if(sum->clinfo5) {
05776 status = clnt_call(sum->clinfo5, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05777 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05778 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo5,history)) {
05779 (*history)("SUM_repartn() failed on call to Sinfo5\n");
05780 failflg = 1;
05781 }
05782 }
05783 if(sum->clinfo6) {
05784 status = clnt_call(sum->clinfo6, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05785 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05786 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo6,history)) {
05787 (*history)("SUM_repartn() failed on call to Sinfo6\n");
05788 failflg = 1;
05789 }
05790 }
05791 if(sum->clinfo7) {
05792 status = clnt_call(sum->clinfo7, SUMREPARTN, (xdrproc_t)xdr_Rkey,
05793 (char *)klist, (xdrproc_t)xdr_uint32_t, (char *)&retstat, TIMEOUT);
05794 if(status = SUM_repartn_ck_error(status,retstat,sum->clinfo7,history)) {
05795 (*history)("SUM_repartn() failed on call to Sinfo7\n");
05796 failflg = 1;
05797 }
05798 }
05799 #endif
05800 }
05801 return(0);
05802 }
05803 #endif
05804
05805 #if (!defined(SUMS_USEMTSUMS) || !SUMS_USEMTSUMS) || (!defined(SUMS_USEMTSUMS_ALL) || !SUMS_USEMTSUMS_ALL)
05806
05807
05808
05809
05810
05811
05812
05813
05814
05815
05816
05817
05818
05819
05820
05821
05822 int getanymsg(int block)
05823 {
05824 fd_set readfds;
05825 struct timeval timeout;
05826 int wait, retcode = ERRMESS, srdy, info;
05827 static int ts=0;
05828
05829 wait = 1;
05830
05831
05832 if(!ts) ts = FD_SETSIZE;
05833
05834 while(wait) {
05835 readfds=svc_fdset;
05836 timeout.tv_sec=0;
05837 timeout.tv_usec=500000;
05838 srdy=select(ts,&readfds,(fd_set *)0,(fd_set *)0,&timeout);
05839 switch(srdy) {
05840 case -1:
05841 if(errno==EINTR) {
05842 continue;
05843 }
05844 fprintf(stderr, "%s\n", datestring());
05845 perror("getanymsg: select failed");
05846 retcode = ERRMESS;
05847 wait = 0;
05848 break;
05849 case 0:
05850 if(block) continue;
05851 retcode = TIMEOUTMSG;
05852 wait = 0;
05853 break;
05854 default:
05855
05856 RESPDO_called = 0;
05857 svc_getreqset(&readfds);
05858 retcode = RPCMSG;
05859 if(RESPDO_called) wait = 0;
05860 break;
05861 }
05862 }
05863 return(retcode);
05864 }
05865
05866
05867 int getmsgimmed()
05868 {
05869 fd_set readfds;
05870 struct timeval timeout;
05871 int wait, retcode = ERRMESS, srdy, info;
05872 static int ts=0;
05873
05874 wait = 1;
05875 timeout.tv_sec=0;
05876 timeout.tv_usec=0;
05877
05878 if(!ts) ts = FD_SETSIZE;
05879 while(wait) {
05880 readfds=svc_fdset;
05881 srdy=select(ts,&readfds,(fd_set *)0,(fd_set *)0,&timeout);
05882 switch(srdy) {
05883 case -1:
05884 if(errno==EINTR) {
05885 continue;
05886 }
05887 fprintf(stderr, "%s\n", datestring());
05888 perror("getanymsg: select failed");
05889 retcode = ERRMESS;
05890 wait = 0;
05891 break;
05892 case 0:
05893 retcode = TIMEOUTMSG;
05894 wait = 0;
05895 break;
05896 default:
05897
05898 RESPDO_called = 0;
05899 svc_getreqset(&readfds);
05900 retcode = RPCMSG;
05901 if(RESPDO_called) wait = 0;
05902 break;
05903 }
05904 }
05905 return(retcode);
05906 }
05907
05908
05909
05910
05911
05912
05913
05914
05915
05916 KEY *respdoarray_1(KEY *params)
05917 {
05918 SUM_t *sum;
05919 SUM_info_t *sinfod, *sinf;
05920 SUMOPENED *sumopened;
05921 FILE *rfp;
05922 int reqcnt, i, filemode;
05923 char *file, *cptr;
05924 char name[128], str1[128], str2[128], line[128];
05925
05926 sumopened = getsumopened(sumopened_hdr, getkey_uint64(params, "uid"));
05927 sum = (SUM_t *)sumopened->sum;
05928 if(sum == NULL) {
05929 printf("**Response from sum_svc does not have an opened SUM_t *sum\n");
05930 printf("**Don't know what this will do to the caller, but this is a logic bug\n");
05931 return((KEY *)NULL);
05932 }
05933 reqcnt = getkey_int(params, "reqcnt");
05934 file = getkey_str(params, "FILE");
05935 filemode = getkey_int(params, "filemode");
05936
05937 if((rfp=fopen(file, "r")) == NULL) {
05938 printf("**Can't open %s from sum_svc ret from SUM_infoArray() call\n", file);
05939 free(file);
05940 return((KEY *)NULL);
05941 }
05942 free(file);
05943
05944
05945
05946
05947
05948
05949 sum->sinfo = (SUM_info_t *)calloc(reqcnt, sizeof(SUM_info_t));
05950 sinfod = sum->sinfo;
05951 if(filemode == 0)
05952 fread(sinfod, sizeof(SUM_info_t), reqcnt, rfp);
05953 sinfod->next = NULL;
05954 sinf = sinfod;
05955
05956 for(i = 1; i < reqcnt; i++) {
05957 sinf++;
05958 sinfod->next = sinf;
05959 sinfod = sinf;
05960 sinfod->next = NULL;
05961 }
05962 if(filemode == 1) {
05963 sinfod = sum->sinfo;
05964 for(i = 0; i < reqcnt; i++) {
05965 fgets(line, 128, rfp);
05966 if(!strcmp(line, "\n")) {
05967 fgets(line, 128, rfp);
05968 }
05969 sscanf(line, "%s %lu", name, &sinfod->sunum);
05970 fgets(line, 128, rfp);
05971 sscanf(line, "%s %s", name, sinfod->online_loc);
05972
05973
05974
05975
05976
05977 if(!strcmp(name, "pa_status=")) {
05978 strcpy(sinfod->online_loc, "");
05979 goto SKIPENTRY;
05980 }
05981 fgets(line, 128, rfp);
05982 sscanf(line, "%s %s", name, sinfod->online_status);
05983 fgets(line, 128, rfp);
05984 sscanf(line, "%s %s", name, sinfod->archive_status);
05985 fgets(line, 128, rfp);
05986 sscanf(line, "%s %s", name, sinfod->offsite_ack);
05987 fgets(line, 128, rfp);
05988 sscanf(line, "%s %80[^;]", name, sinfod->history_comment);
05989 fgets(line, 128, rfp);
05990 sscanf(line, "%s %s", name, sinfod->owning_series);
05991 fgets(line, 128, rfp);
05992 sscanf(line, "%s %d", name, &sinfod->storage_group);
05993 fgets(line, 128, rfp);
05994 sscanf(line, "%s %lf", name, &sinfod->bytes);
05995 fgets(line, 128, rfp);
05996 sscanf(line, "%s %s %s", name, str1, str2);
05997 sprintf(sinfod->creat_date, "%s %s", str1, str2);
05998 fgets(line, 128, rfp);
05999 sscanf(line, "%s %s", name, sinfod->username);
06000 fgets(line, 128, rfp);
06001 sscanf(line, "%s %s", name, sinfod->arch_tape);
06002 fgets(line, 128, rfp);
06003 sscanf(line, "%s %d", name, &sinfod->arch_tape_fn);
06004 fgets(line, 128, rfp);
06005 sscanf(line, "%s %s %s", name, str1, str2);
06006 sprintf(sinfod->arch_tape_date, "%s %s", str1, str2);
06007 fgets(line, 128, rfp);
06008 sscanf(line, "%s %s", name, sinfod->safe_tape);
06009 fgets(line, 128, rfp);
06010 sscanf(line, "%s %d", name, &sinfod->safe_tape_fn);
06011 fgets(line, 128, rfp);
06012 sscanf(line, "%s %s %s", name, str1, str2);
06013 sprintf(sinfod->safe_tape_date, "%s %s", str1, str2);
06014 fgets(line, 128, rfp);
06015 sscanf(line, "%s %d", name, &sinfod->pa_status);
06016 SKIPENTRY:
06017 fgets(line, 128, rfp);
06018 sscanf(line, "%s %d", name, &sinfod->pa_substatus);
06019 fgets(line, 128, rfp);
06020 sscanf(line, "%s %s", name, sinfod->effective_date);
06021 sinfod = sinfod->next;
06022 }
06023 }
06024 fclose(rfp);
06025 return((KEY *)NULL);
06026 }
06027
06028
06029
06030
06031 KEY *respdo_1(KEY *params)
06032 {
06033 SUM_t *sum;
06034 SUM_info_t *sinfo;
06035 SUMOPENED *sumopened;
06036 char *wd;
06037 char **cptr;
06038 uint64_t *dsixpt;
06039 uint64_t dsindex;
06040 int i, reqcnt, reqcode;
06041 char name[128];
06042
06043 sumopened = getsumopened(sumopened_hdr, getkey_uint64(params, "uid"));
06044 sum = (SUM_t *)sumopened->sum;
06045 if(sum == NULL) {
06046 printf("**Response from sum_svc does not have an opened SUM_t *sum\n");
06047 printf("**Don't know what this will do to the caller, but this is a logic bug\n");
06048 return((KEY *)NULL);
06049 }
06050 if(sum->debugflg) {
06051 printf("\nIn respdo_1() the keylist is:\n");
06052 keyiterate(printkey, params);
06053 }
06054 reqcnt = getkey_int(params, "reqcnt");
06055 reqcode = getkey_int(params, "REQCODE");
06056 sum->status = getkey_int(params, "STATUS");
06057
06058 if (reqcode == ALLOCDO || reqcode == GETDO)
06059 {
06060
06061 if (sum->wd)
06062 {
06063
06064 free(sum->wd);
06065 sum->wd = NULL;
06066 }
06067
06068 sum->wd = (char **)calloc(reqcnt, sizeof(char *));
06069 }
06070
06071 if (reqcode == ALLOCDO)
06072 {
06073
06074 if (sum->dsix_ptr)
06075 {
06076
06077 free(sum->dsix_ptr);
06078 sum->dsix_ptr = NULL;
06079 }
06080
06081 sum->dsix_ptr = (uint64_t *)calloc(reqcnt, sizeof(uint64_t));
06082 }
06083
06084 cptr = sum->wd;
06085 dsixpt = sum->dsix_ptr;
06086 switch(reqcode) {
06087 case ALLOCDO:
06088
06089 wd = getkey_str(params, "partn_name");
06090 dsindex = getkey_uint64(params, "ds_index");
06091 *cptr = wd;
06092 *dsixpt = dsindex;
06093 if(findkey(params, "ERRSTR")) {
06094 printf("%s\n", GETKEY_str(params, "ERRSTR"));
06095 }
06096 break;
06097 case GETDO:
06098 for(i = 0; i < reqcnt; i++) {
06099 sprintf(name, "wd_%d", i);
06100 wd = getkey_str(params, name);
06101 *cptr++ = wd;
06102 if(findkey(params, "ERRSTR")) {
06103 printf("%s\n", GETKEY_str(params, "ERRSTR"));
06104 }
06105 }
06106 break;
06107 case INFODOX:
06108 if(findkey(params, "ERRSTR")) {
06109 printf("%s\n", GETKEY_str(params, "ERRSTR"));
06110 }
06111 sinfo = sum->sinfo;
06112 for(i = 0; i < reqcnt; i++) {
06113 sprintf(name, "ds_index_%d", i);
06114 sinfo->sunum = getkey_uint64(params, name);
06115 sprintf(name, "online_loc_%d", i);
06116 strcpy(sinfo->online_loc, GETKEY_str(params, name));
06117 sprintf(name, "online_status_%d", i);
06118 strcpy(sinfo->online_status, GETKEY_str(params, name));
06119 sprintf(name, "archive_status_%d", i);
06120 strcpy(sinfo->archive_status, GETKEY_str(params, name));
06121 sprintf(name, "offsite_ack_%d", i);
06122 strcpy(sinfo->offsite_ack, GETKEY_str(params, name));
06123 sprintf(name, "history_comment_%d", i);
06124 strcpy(sinfo->history_comment, GETKEY_str(params, name));
06125 sprintf(name, "owning_series_%d", i);
06126 strcpy(sinfo->owning_series, GETKEY_str(params, name));
06127 sprintf(name, "storage_group_%d", i);
06128 sinfo->storage_group = getkey_int(params, name);
06129 sprintf(name, "bytes_%d", i);
06130 sinfo->bytes = getkey_double(params, name);
06131 sprintf(name, "creat_date_%d", i);
06132 strcpy(sinfo->creat_date, GETKEY_str(params, name));
06133 sprintf(name, "username_%d", i);
06134 strcpy(sinfo->username, GETKEY_str(params, name));
06135 sprintf(name, "arch_tape_%d", i);
06136 strcpy(sinfo->arch_tape, GETKEY_str(params, name));
06137 sprintf(name, "arch_tape_fn_%d", i);
06138 sinfo->arch_tape_fn = getkey_int(params, name);
06139 sprintf(name, "arch_tape_date_%d", i);
06140 strcpy(sinfo->arch_tape_date, GETKEY_str(params, name));
06141 sprintf(name, "safe_tape_%d", i);
06142 strcpy(sinfo->safe_tape, GETKEY_str(params, name));
06143 sprintf(name, "safe_tape_fn_%d", i);
06144 sinfo->safe_tape_fn = getkey_int(params, name);
06145 sprintf(name, "safe_tape_date_%d", i);
06146 strcpy(sinfo->safe_tape_date, GETKEY_str(params, name));
06147 sprintf(name, "pa_status_%d", i);
06148 sinfo->pa_status = getkey_int(params, name);
06149 sprintf(name, "pa_substatus_%d", i);
06150 sinfo->pa_substatus = getkey_int(params, name);
06151 sprintf(name, "effective_date_%d", i);
06152 strcpy(sinfo->effective_date, GETKEY_str(params, name));
06153 if(!(sinfo = sinfo->next)) {
06154 if(i+1 != reqcnt) {
06155 printf("ALERT: #of info requests received differs from reqcnt\n");
06156 break;
06157 }
06158 }
06159 }
06160 break;
06161 case INFODO:
06162
06163 sinfo = sum->sinfo;
06164 sinfo->sunum = getkey_uint64(params, "SUNUM");
06165 strcpy(sinfo->online_loc, GETKEY_str(params, "online_loc"));
06166 strcpy(sinfo->online_status, GETKEY_str(params, "online_status"));
06167 strcpy(sinfo->archive_status, GETKEY_str(params, "archive_status"));
06168 strcpy(sinfo->offsite_ack, GETKEY_str(params, "offsite_ack"));
06169 strcpy(sinfo->history_comment, GETKEY_str(params, "history_comment"));
06170 strcpy(sinfo->owning_series, GETKEY_str(params, "owning_series"));
06171 sinfo->storage_group = getkey_int(params, "storage_group");
06172 sinfo->bytes = getkey_double(params, "bytes");
06173 strcpy(sinfo->creat_date, GETKEY_str(params, "creat_date"));
06174 strcpy(sinfo->username, GETKEY_str(params, "username"));
06175 strcpy(sinfo->arch_tape, GETKEY_str(params, "arch_tape"));
06176 sinfo->arch_tape_fn = getkey_int(params, "arch_tape_fn");
06177 strcpy(sinfo->arch_tape_date, GETKEY_str(params, "arch_tape_date"));
06178 strcpy(sinfo->safe_tape, GETKEY_str(params, "safe_tape"));
06179 sinfo->safe_tape_fn = getkey_int(params, "safe_tape_fn");
06180 strcpy(sinfo->safe_tape_date, GETKEY_str(params, "safe_tape_date"));
06181 sinfo->pa_status = getkey_int(params, "pa_status");
06182 sinfo->pa_substatus = getkey_int(params, "pa_substatus");
06183 strcpy(sinfo->effective_date, GETKEY_str(params, "effective_date"));
06184 break;
06185 case PUTDO:
06186 break;
06187 default:
06188 printf("**Unexpected REQCODE in respdo_1()\n");
06189 break;
06190 }
06191 return((KEY *)NULL);
06192 }
06193
06194
06195
06196
06197
06198
06199
06200 static void respd(rqstp, transp)
06201 struct svc_req *rqstp;
06202 SVCXPRT *transp;
06203 {
06204 union __svcargun {
06205 Rkey respdo_1_arg;
06206 } argument;
06207 char *result;
06208 bool_t (*xdr_argument)(void), (*xdr_result)(void);
06209 char *(*local)(void *, void *);
06210
06211 switch (rqstp->rq_proc) {
06212 case NULLPROC:
06213 (void) svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL);
06214 return;
06215 case RESPDO:
06216 xdr_argument = xdr_Rkey;
06217 xdr_result = xdr_void;
06218 local = (char *(*)(void *, void *)) respdo_1;
06219 RESPDO_called = 1;
06220 break;
06221 case RESPDOARRAY:
06222 xdr_argument = xdr_Rkey;
06223 xdr_result = xdr_void;
06224 local = (char *(*)(void *, void *)) respdoarray_1;
06225 RESPDO_called = 1;
06226 break;
06227 default:
06228 svcerr_noproc(transp);
06229 return;
06230 }
06231 bzero((char *)&argument, sizeof(argument));
06232 if(!svc_getargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
06233 svcerr_decode(transp);
06234 return;
06235 }
06236
06237 if(!svc_sendreply(transp, (xdrproc_t)xdr_void, (char *)NULL)) {
06238 svcerr_systemerr(transp);
06239 return;
06240 }
06241 result = (*local)(&argument, rqstp);
06242
06243 if(!svc_freeargs(transp, (xdrproc_t)xdr_argument, (char *)&argument)) {
06244 printf("unable to free arguments in respd()\n");
06245
06246 }
06247 }
06248 #endif
06249
06250
06251
06252 char *datestring(void)
06253 {
06254 time_t t;
06255 char *str;
06256
06257 t = time(NULL);
06258 str = ctime(&t);
06259 str[19] = 0;
06260 return str+4;
06261 }
06262