00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126 #include <stdio.h>
00127 #include <string.h>
00128 #include <errno.h>
00129
00130 #ifdef WIN32
00131 #include <sys\types.h>
00132 #include <winsock.h>
00133 #include <windows.h>
00134 #include <process.h>
00135 #include <sys\stat.h>
00136 #else
00137 #include <sys/stat.h>
00138 #include <ctype.h>
00139 #include <stdlib.h>
00140 #include <unistd.h>
00141 #include <netinet/in.h>
00142
00143 #ifdef Lynx
00144 #include <sys/types.h>
00145 #include <socket.h>
00146 #elif Linux
00147 #include <sys/socket.h>
00148 #else
00149 #include <sys/socket.h>
00150 #endif
00151
00152 #endif
00153
00154 #include "rawapitd.h"
00155 #include "rawapitd-gsin.h"
00156 #include "rawcommn.h"
00157 #include "rawdefn.h"
00158 #include "rawentn.h"
00159 #include "rawapplcli.h"
00160
00161 extern FILE *fLogFile;
00162
00163 static char cPath[MAX_FULL_FILE] = "";
00164 static char cNamefs[MAX_OBJ_FS] = "";
00165 static char cNamehl[MAX_OBJ_HL] = "";
00166 static char *pcNull = (char *) "";
00167
00168
00169 static int iObjAttr = sizeof(srawObjAttr);
00170
00171
00172
00173
00174
00175
00176
00177
00178 int rawAddStrings(char *pcMsg1,
00179 int iMaxLength1,
00180 char *pcMsg2,
00181 int iMaxLength2,
00182 int iErrno,
00183
00184 char *pcMsgE,
00185 int iMaxLengthE)
00186 {
00187 char cModule[32]="rawAddStrings";
00188 int iDebug = 0;
00189
00190 int iRC = 0;
00191
00192
00193
00194
00195
00196
00197
00198 int iString1 = 0;
00199 int iString2 = 0;
00200 int iStringE = 0;
00201 int iString = 0;
00202 int iMinLen = STATUS_LEN;
00203 char cMsg[STATUS_LEN] = "";
00204 char *pcc;
00205
00206 iString1 = strlen(pcMsg1);
00207 iString2 = strlen(pcMsg2);
00208 iString = iString1 + iString2;
00209
00210 if (iDebug)
00211 {
00212 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00213 fprintf(fLogFile, " string1 (%d byte, max %d byte):\n %s",
00214 iString1, iMaxLength1, pcMsg1);
00215 if (iErrno)
00216 fprintf(fLogFile, " add msg for errno=%d\n", errno);
00217 else
00218 fprintf(fLogFile, " add string2 (%d byte, max %d byte):\n %s",
00219 iString2, iMaxLength2, pcMsg2);
00220 }
00221
00222 if ( (iString1 <= iMaxLength1) &&
00223 (iString2 <= iMaxLength2) )
00224 {
00225 if (iErrno)
00226 {
00227 if (iMaxLength2 >= iMinLen)
00228 {
00229 sprintf(pcMsg2, " %s\n", strerror(errno));
00230 iString2 = strlen(pcMsg2);
00231 iString = iString1 + iString2;
00232 }
00233 else
00234 {
00235 iRC = -4;
00236 sprintf(cMsg,
00237 "-E- %s: 2nd string (%d byte) possibly too small for system error: requ. %d byte\n",
00238 cModule, iMaxLength2, iMinLen);
00239
00240 goto gErrorMsg;
00241 }
00242 }
00243
00244 if (iString < iMaxLength1)
00245 {
00246 strcat(pcMsg1, pcMsg2);
00247 if (iDebug) fprintf(fLogFile,
00248 " returned msg (%d byte):\n %s", iString, pcMsg1);
00249 }
00250 else
00251 {
00252 strncat(pcMsg1, pcMsg2, iMaxLength1-iString1-1);
00253 strncat(pcMsg1, "\n", 1);
00254 iRC = iString -iMaxLength1;
00255 if (iDebug)
00256 {
00257 fprintf(fLogFile, " returned msg:\n %s", pcMsg1);
00258 pcc = pcMsg2;
00259 pcc+= iMaxLength1-iString1-1;
00260 fprintf(fLogFile, " skipped msg part:\n %s", pcc);
00261 }
00262 }
00263 }
00264 else
00265 {
00266 if (iMaxLength1 <= 0)
00267 {
00268 iRC = -3;
00269 sprintf(cMsg, "-E- %s: 1st string length (%d byte) invalid\n",
00270 cModule, iMaxLength1);
00271 }
00272 if (iMaxLength2 <= 0)
00273 {
00274 iRC = -3;
00275 sprintf(cMsg, "-E- %s: 2nd string length (%d byte) invalid\n",
00276 cModule, iMaxLength2);
00277 }
00278 else if (iString == 0)
00279 {
00280 iRC = -2;
00281 sprintf(cMsg, "-E- %s: empty strings provided\n", cModule);
00282 }
00283 else if (iString1 > iMaxLength1)
00284 {
00285 iRC = -1;
00286 sprintf(cMsg, "-E- %s: 1st string longer (%d byte) than length provided (%d)\n",
00287 cModule, iString1, iMaxLength1);
00288 }
00289 else if ( (iString2 > iMaxLength2) && (iErrno == 0) )
00290 {
00291 iRC = -1;
00292 sprintf(cMsg, "-E- %s: 2nd string longer (%d byte) than length provided (%d)\n",
00293 cModule, iString2, iMaxLength2);
00294 }
00295 }
00296
00297 if (iRC >= 0)
00298 {
00299 strcpy(pcMsgE, "");
00300 goto gEndAddStrings;
00301 }
00302
00303 gErrorMsg:
00304 iStringE = strlen(cMsg);
00305 if (iDebug) fprintf(fLogFile,
00306 " error string (%d byte, max %d byte):\n %s\n",
00307 iStringE, iMaxLengthE, cMsg);
00308
00309 if (iMaxLengthE < iStringE)
00310 {
00311 iRC = -5;
00312 fprintf(fLogFile, "-E- %s: size error string too small: max %d byte (needed %d)",
00313 cModule, iMaxLengthE, iStringE);
00314 strncat(pcMsgE, cMsg, iMaxLengthE);
00315 fprintf(fLogFile, ", provided: %s\n", pcMsgE);
00316 }
00317 else
00318 {
00319 if (iDebug)
00320 fprintf(fLogFile, cMsg);
00321 strcpy(pcMsgE, cMsg);
00322 }
00323
00324 gEndAddStrings:
00325 if (iDebug)
00326 fprintf(fLogFile, "-D- end %s: rc=%d\n\n", cModule, iRC);
00327
00328 return iRC;
00329
00330 }
00331
00332
00333
00334
00335
00336
00337
00338
00339
00340
00341
00342
00343
00344 int rawCheckClientFile( char *pcFile0, char **pcFile, char **pcTape)
00345 {
00346
00347 char cModule[32]="rawCheckClientFile";
00348 int iDebug = 0;
00349
00350 int iloc, iRC, ii;
00351 int iDevType = 1;
00352
00353 bool_t bup = bFalse;
00354
00355 char cText[12] = "";
00356 char cTemp[MAX_FULL_FILE] = "";
00357 char *plocd = NULL, *plocs = NULL;
00358 char *pdelim = NULL, *pgen = NULL;
00359 const char *pcSemi = ";";
00360 char *pcc = NULL, *pBufTape, *pBufFile;
00361
00362 if (iDebug) fprintf(fLogFile,
00363 "\n-D- begin %s: test file %s\n", cModule, pcFile0);
00364
00365 pBufTape = *pcTape;
00366 pBufFile = *pcFile;
00367 strcpy(cTemp, pcFile0);
00368
00369
00370 plocd = strchr(cTemp, *pcDevDelim);
00371 if (plocd != NULL)
00372 {
00373 iRC = strncmp(cTemp, "/dev", 4);
00374 {
00375 fprintf(fLogFile,
00376 "-E- invalid file name: %s\n path names must not contain '%s'\n",
00377 pcFile0, pcDevDelim);
00378 return(-2);
00379 }
00380
00381 if (iRC)
00382 pdelim = strrchr(cTemp, *pcFileDelim);
00383 if ( (pdelim == NULL) || (pdelim > plocd) )
00384 {
00385 fprintf(fLogFile,
00386 "-E- invalid disk file name: %s\n path names must not contain '%s'\n",
00387 pcFile0, pcDevDelim);
00388 return(-2);
00389 }
00390
00391 pcc = plocd;
00392 pcc++;
00393 if (strlen(pcc) > MAX_TAPE_FILE)
00394 {
00395 ii = MAX_TAPE_FILE;
00396 fprintf(fLogFile,
00397 "-E- invalid tape file name: %s\n name too long: max %d byte after dev name\n",
00398 pcFile0, ii);
00399 return(-2);
00400 }
00401
00402 iDevType = 2;
00403 iRC = strncmp(++pcc, "\0", 1);
00404 if (iRC == 0)
00405 {
00406 #ifdef VMS
00407 fprintf(fLogFile,
00408 "-E- file name must be specified explicitly\n");
00409 #else
00410 fprintf(fLogFile, "-E- file name missing in %s\n", pcFile0);
00411 #endif
00412 return(-2);
00413 }
00414 }
00415
00416 #ifdef VMS
00417
00418 plocs = strchr(cTemp, *pcSemi);
00419 if (plocs)
00420 {
00421 ++plocs;
00422 iRC = isalnum(*plocs);
00423 if (iRC)
00424 {
00425 iRC = isalpha(*plocs);
00426 if (iRC == 0)
00427 fprintf(fLogFile,
00428 "-W- version number in file specification removed\n");
00429 else
00430 fprintf(fLogFile,
00431 "-W- invalid version in file specification removed\n");
00432 }
00433 else
00434 fprintf(fLogFile,
00435 "-W- semicolon in file specification removed\n");
00436 strncpy(--plocs, "\0", 1);
00437 strcpy(pcFile0, cTemp);
00438 }
00439
00440 iDevType = rawCheckDevice(cTemp, pcFile, pcTape);
00441 switch(iDevType)
00442 {
00443 case 0:
00444 if (iDebug) fprintf(fLogFile,
00445 " no device name specified\n");
00446 break;
00447 case 1:
00448 if (iDebug)
00449 {
00450 if (strlen(*pcFile) == 0)
00451 fprintf(fLogFile, " disk device %s\n", *pcTape);
00452 else
00453 fprintf(fLogFile,
00454 " file %s on disk %s\n", *pcFile, *pcTape);
00455 }
00456 break;
00457 case 2:
00458 if (iDebug)
00459 {
00460 if (strlen(*pcFile) == 0)
00461 fprintf(fLogFile, " tape device %s\n", *pcTape);
00462 else
00463 fprintf(fLogFile, " file %s on tape %s\n", *pcFile, *pcTape);
00464 }
00465 break;
00466 default:
00467 fprintf(fLogFile, "-E- invalid file name %s\n", pcFile0);
00468 return(-1);
00469
00470 }
00471 #endif
00472
00473 if (iDevType == 2)
00474 {
00475 #ifndef VMS
00476
00477 iRC = strncmp(pcc, pcDevDelim, 1);
00478 if (iRC == 0)
00479 {
00480 fprintf(fLogFile,
00481 "-E- node specification not allowed in file name: %s\n",
00482 pcFile0);
00483 return(-2);
00484 }
00485 #endif
00486
00487 strncpy(plocd++, "\0", 1);
00488 strcpy(pBufTape, cTemp);
00489 #ifdef VMS
00490 strncat(pBufTape, pcDevDelim, 1);
00491
00492 #else
00493 pgen = strchr(pBufTape, *pcStar);
00494 if (pgen != NULL)
00495 {
00496 fprintf(fLogFile,
00497 "-E- specified device %s has generic path\n", pBufTape);
00498 fprintf(fLogFile,
00499 " only the relative file name may be generic\n");
00500 return(-1);
00501 }
00502 #endif
00503
00504 strcpy(pBufFile, plocd);
00505 if (iDebug) fprintf(fLogFile,
00506 " file %s on tape %s\n", pBufFile, pBufTape);
00507 strcpy(cText, "tape");
00508 iRC = 1;
00509
00510 }
00511 else
00512 {
00513 strcpy(pBufFile, cTemp);
00514 strcpy(cText, "disk");
00515 iRC = 0;
00516 }
00517
00518 if (iDebug) fprintf(fLogFile,
00519 " %s file %s\n", cText, pBufFile);
00520
00521 pdelim = strrchr(pBufFile, *pcFileDelim);
00522 if (pdelim != NULL)
00523 {
00524 #ifndef VMS
00525 if (iDevType == 2)
00526 {
00527 fprintf(fLogFile,
00528 "-E- path in tape file name not allowed: %s\n", pBufFile);
00529 return(-1);
00530 }
00531 #endif
00532
00533
00534 pgen = strchr(pBufFile, *pcStar);
00535 if (pgen == NULL)
00536 pgen = strchr(pBufFile, *pcQM);
00537 if ( (pgen != NULL) && (pgen < pdelim) )
00538 {
00539 fprintf(fLogFile,
00540 "-E- specified %s file %s has wildcard chars in path name\n",
00541 cText, pBufFile);
00542 fprintf(fLogFile,
00543 " only the relative file name may contain wildcard chars\n");
00544 return(-1);
00545 }
00546
00547 pdelim++;
00548
00549 }
00550 else pdelim = pBufFile;
00551
00552 ii = MAX_OBJ_LL - 2;
00553 if (strlen(pdelim) > ii)
00554 {
00555 fprintf(fLogFile,
00556 "-E- rel file name %s too long:\n has %d chars, max allowed %d\n",
00557 pdelim, strlen(pdelim), ii);
00558 return(-1);
00559 }
00560
00561 #ifndef VMS
00562
00563 if (iDevType == 2)
00564 {
00565 pcc = pdelim;
00566 while (*pcc != '\0')
00567 {
00568 iloc = isupper(*pcc);
00569 if (iloc != 0)
00570 {
00571 if (!bup) fprintf(fLogFile,
00572 "-W- upper case in (relative) file name not supported: %s\n",
00573 pdelim);
00574 bup = bTrue;
00575 *pcc = tolower(*pcc);
00576 }
00577 pcc++;
00578 }
00579 }
00580
00581 if (bup)
00582 fprintf(fLogFile, " instead assumed: %s\n", pdelim);
00583 #endif
00584
00585 if (iDebug) fprintf(fLogFile,
00586 "\n end %s: file name %s okay\n", cModule, pcFile0);
00587
00588 return(iRC);
00589
00590 }
00591
00592
00593
00594
00595
00596
00597
00598
00599 char *rawGetFSpName( char *pcUser )
00600 {
00601 char cModule[32]="rawGetFSpName";
00602 int iDebug = 0;
00603
00604 char *pc;
00605
00606 if (iDebug)
00607 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00608
00609 pc = pcUser;
00610 if ( (strchr(pcUser, *pcStar) != NULL) ||
00611 (strchr(pcUser, *pcQM) != NULL) )
00612 {
00613 fprintf(fLogFile,
00614 "-E- %s: generic archive name '%s' not allowed\n",
00615 cModule, pcUser);
00616 return(pcNull);
00617 }
00618
00619 strcpy(cNamefs, "");
00620 if (iDebug)
00621 fprintf(fLogFile, "-D- %s: FS %s, in %s-%s, delim %s\n",
00622 cModule, cNamefs, pcUser, pc, pcObjDelim);
00623 if (strncmp(pc, pcObjDelim, 1) == 0)
00624 pc++;
00625 else
00626
00627
00628
00629 strcpy(cNamefs, pcObjDelim);
00630
00631 if (isalpha(*pc) == 0)
00632 {
00633 fprintf(fLogFile,
00634 "-E- archive name '%s' must start with a letter\n", pc);
00635 return(pcNull);
00636 }
00637
00638 strcat(cNamefs, pcUser);
00639 if (iDebug) fprintf(fLogFile,
00640 "-D- end %s: FS %s\n", cNamefs, cModule);
00641
00642 return( (char *) cNamefs);
00643
00644 }
00645
00646
00647
00648
00649
00650
00651
00652
00653
00654
00655
00656 char *rawGetHLName( char *pcPath)
00657 {
00658 char cModule[32]="rawGetHLName";
00659 int iDebug = 0;
00660
00661 char *pcc;
00662 char *pdelim;
00663 char cNameTemp[MAX_OBJ_HL] = "";
00664 int ii = 0, ii1 = 0;
00665
00666 if (iDebug) fprintf(fLogFile,
00667 "\n-D- begin %s\n path specified: %s\n", cModule, pcPath);
00668
00669 pdelim = strchr(pcPath, *pcObjDelim);
00670 if (pdelim != pcPath)
00671 {
00672 strcpy(cNamehl, pcObjDelim);
00673 if (iDebug) fprintf(fLogFile,
00674 " delimiter '%s' inserted at begin of archive path\n",
00675 pcObjDelim);
00676 strcat(cNamehl, pcPath);
00677 }
00678 else strcpy(cNamehl, pcPath);
00679
00680 pdelim = strstr(cNamehl, "/./");
00681 if (pdelim != NULL)
00682 {
00683 strcpy(cNameTemp, cNamehl);
00684 pdelim = strstr(cNameTemp, "/./");
00685
00686 while (pdelim != NULL)
00687 {
00688 ii++;
00689 strncpy(pdelim, "\0", 1);
00690 strcpy(cNamehl, cNameTemp);
00691 pdelim++;
00692 pdelim++;
00693 strcat(cNamehl, pdelim);
00694
00695 strcpy(cNameTemp, cNamehl);
00696 pdelim = strstr(cNameTemp, "/./");
00697 }
00698 if (iDebug) fprintf(fLogFile,
00699 " %d unnecessary './' removed\n", ii);
00700 }
00701
00702 pdelim = strstr(cNamehl, "/.");
00703 if (pdelim != NULL)
00704 {
00705 pcc= cNamehl;
00706 ii = strlen(cNamehl);
00707 ii1 = pdelim - pcc;
00708 if (ii1 < 0)
00709 ii1 = -ii1;
00710 if (ii1+2 == ii)
00711 {
00712 strncpy(pdelim, "\0", 1);
00713 if (iDebug) fprintf(fLogFile,
00714 " trailing '/.' removed\n");
00715 }
00716 }
00717
00718 if (iDebug) fprintf(fLogFile,
00719 " hl name: %s\n-D- end %s\n\n", cNamehl, cModule);
00720
00721 return(cNamehl);
00722
00723 }
00724
00725
00726
00727
00728
00729
00730
00731
00732
00733
00734
00735 int rawGetLLName( char *pcFile, const char *pcDelimiter,
00736 char *pcObject)
00737 {
00738 char cModule[32] = "rawGetLLName";
00739 int iDebug = 0;
00740
00741 char cNamell[MAX_OBJ_LL] = "";
00742 char *ploc = NULL;
00743
00744 if (iDebug) fprintf(fLogFile,
00745 "\n-D- begin %s\n file %s, object delimiter %s\n",
00746 cModule, pcFile, pcDelimiter);
00747
00748 strcpy(cNamell, pcDelimiter);
00749
00750 ploc = strrchr(pcFile, *pcFileDelim);
00751 if (ploc != NULL)
00752 strcat(cNamell, ++ploc);
00753 else
00754 {
00755 ploc = strrchr(pcFile, *pcObjDelimAlt);
00756 if (ploc != NULL)
00757 strcat(cNamell, ++ploc);
00758 else
00759 {
00760 #ifdef VMS
00761 ploc = strrchr(pcFile, *pcDevDelim);
00762 if (ploc != NULL)
00763 strcat(cNamell, ++ploc);
00764
00765 else
00766 #endif
00767 strcat(cNamell, pcFile);
00768 }
00769 }
00770 strcpy(pcObject, cNamell);
00771
00772 if (iDebug) fprintf(fLogFile,
00773 " ll name %s\n-D- end %s\n\n", pcObject, cModule);
00774
00775 return 0;
00776
00777 }
00778
00779
00780
00781
00782
00783
00784
00785
00786 int rawGetFileSize(char *pcFile,
00787 unsigned long *piSize,
00788 unsigned int *piRecl)
00789 {
00790 char cModule[32] = "rawGetFileSize";
00791 int iDebug = 0;
00792
00793 int iRC;
00794 int iRecl = 0;
00795 unsigned long iSize = 0;
00796
00797 #ifdef WIN32
00798 struct _stat sFileStatus, *pFileStatus;
00799 #else
00800 struct stat sFileStatus, *pFileStatus;
00801 #endif
00802
00803 if (iDebug) fprintf(fLogFile,
00804 "\n-D- begin %s: file %s\n", cModule, pcFile);
00805
00806 pFileStatus = &sFileStatus;
00807
00808 #ifdef WIN32
00809 iRC = _stat(pcFile, pFileStatus);
00810 #else
00811 iRC = stat(pcFile, pFileStatus);
00812 #endif
00813 if (iRC)
00814 {
00815 fprintf(fLogFile,
00816 "-E- %s: file %s unavailable (stat)\n", cModule, pcFile);
00817 if (errno)
00818 {
00819 fprintf(fLogFile, " %s\n", strerror(errno));
00820
00821
00822 if (strcmp(strerror(errno),
00823 "Value too large for defined data type") == 0)
00824 {
00825 fprintf(fLogFile,
00826 "-E- %s: file size of %s > 2 GByte: use 64 bit gStore client\n",
00827 cModule, pcFile);
00828
00829 errno = 0;
00830 return -99;
00831 }
00832 errno = 0;
00833 }
00834
00835 return -1;
00836 }
00837
00838 #ifdef VMS
00839 iRecl = pFileStatus->st_fab_mrs;
00840 #else
00841 #ifdef WIN32
00842 iRecl = 0;
00843 #else
00844 iRecl = pFileStatus->st_blksize;
00845 #endif
00846 #endif
00847 iSize = pFileStatus->st_size;
00848 if (pFileStatus->st_mode & S_IFREG)
00849 {
00850 iRC = 0;
00851 if (iDebug) fprintf(fLogFile,
00852 " file %s: size %u, recl %d (byte)\n",
00853 pcFile, iSize, iRecl);
00854 }
00855 else
00856 {
00857 if (pFileStatus->st_mode & S_IFDIR)
00858 {
00859 iRC = 1;
00860 if (iDebug) fprintf(fLogFile,
00861 "-W- %s is a directory, size %u\n", pcFile, iSize);
00862 }
00863 #ifndef WIN32
00864 #ifndef VMS
00865 else if (pFileStatus->st_mode & S_IFLNK)
00866 {
00867 iRC = 2;
00868 if (iDebug) fprintf(fLogFile,
00869 "-W- %s is a symbolic link, size %u\n", pcFile, iSize);
00870 }
00871 #endif
00872 #endif
00873 else
00874 {
00875 iRC = 3;
00876 if (iDebug) fprintf(fLogFile,
00877 "-W- unexpected item %s, size %u\n", pcFile, iSize);
00878 }
00879 }
00880
00881 *piRecl = iRecl;
00882 *piSize = iSize;
00883 if (iDebug)
00884 fprintf(fLogFile, "-D- end %s\n\n", cModule);
00885
00886 return iRC;
00887
00888 }
00889
00890
00891
00892
00893
00894
00895
00896
00897
00898
00899
00900 char *rawGetPathName( char *pcNamehl)
00901 {
00902 char cModule[32] = "rawGetPathName";
00903 int iDebug = 0;
00904
00905 char *ploc = NULL, *ploc1 = NULL;
00906 char *pcc;
00907
00908 if (iDebug)
00909 fprintf(fLogFile, "-D- begin %s: hl: %s\n", cModule, pcNamehl);
00910
00911 if (strlen(pcNamehl) == 0)
00912 {
00913 fprintf(fLogFile, "-E- %s: high level name empty\n", cModule);
00914 return(pcNull);
00915 }
00916
00917 pcc = pcNamehl;
00918 ploc = strchr(pcNamehl, *pcObjDelim);
00919 ploc1 = strchr(pcNamehl, *pcObjDelimAlt);
00920 if ( (ploc != pcc) && (ploc1 != pcc) )
00921 {
00922 fprintf(fLogFile,
00923 "-E- %s: invalid prefix in high level name %s\n",
00924 cModule, pcNamehl);
00925 return(pcNull);
00926 }
00927
00928 strcpy(cPath, pcc);
00929 if (iDebug) fprintf(fLogFile,
00930 "-D- end %s: path %s\n\n", cModule, cPath);
00931
00932 return cPath;
00933
00934 }
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945 int rawQueryFile(
00946 int iSocket,
00947 int iAltMaster,
00948 srawComm *pCommBuf,
00949 void **pQueryBuf)
00950 {
00951 char cModule[32] = "rawQueryFile";
00952 int iDebug = 0;
00953
00954 int iATLServer = -1;
00955 int iNameWC = -1;
00956 int iRC;
00957 int iAction;
00958 int iIdent, iQuery = -1, iAttrLen;
00959 int iQueryAll = 0;
00960 int iStatus, iStatusLen;
00961 int iBuf, iBufComm;
00962 int ii, jj;
00963 char *pcc;
00964
00965 int iVersionObjAttr = 0;
00966
00967
00968
00969
00970 int iPoolId = 0;
00971 int iObjLow = 0;
00972 int iFS = 0;
00973
00974 srawComm *pComm;
00975 srawQueryResult *pQuery;
00976 srawObjAttr *pObjAttr;
00977
00978 pComm = pCommBuf;
00979 iAction = ntohl(pComm->iAction);
00980 iATLServer = ntohl(pComm->iATLServer);
00981 pQuery = (srawQueryResult *) (*pQueryBuf);
00982
00983 iBufComm = ntohl(pComm->iCommLen) + HEAD_LEN;
00984 if (iDebug) fprintf(fLogFile,
00985 "\n-D- begin %s: query file %s in ATL Server %d (action %d)\n",
00986 cModule, pComm->cNamell, iATLServer, iAction);
00987
00988 switch(iAction)
00989 {
00990 case QUERY:
00991 case QUERY_ARCHIVE:
00992 case QUERY_ARCHIVE_RECORD:
00993 case QUERY_ARCHIVE_TO_CACHE:
00994 case QUERY_ARCHIVE_MGR:
00995 case QUERY_REMOVE:
00996 case QUERY_REMOVE_MGR:
00997 case QUERY_RETRIEVE:
00998 case QUERY_RETRIEVE_RECORD:
00999 case QUERY_STAGE:
01000 ;
01001 break;
01002 default:
01003 fprintf(fLogFile,
01004 "-E- %s: invalid action %d\n", cModule, iAction);
01005 iQuery = -1;
01006 goto gEndQueryFile;
01007 }
01008
01009 pcc = (char *) pComm;
01010 iRC = send(iSocket, pcc, (unsigned) iBufComm, 0);
01011 if (iRC < iBufComm)
01012 {
01013 if (iRC < 0) fprintf(fLogFile,
01014 "-E- %s: sending command buffer for query file %s\n",
01015 cModule, pComm->cNamell);
01016 else fprintf(fLogFile,
01017 "-E- %s: query command buffer incompletely sent (%d of %d byte)\n",
01018 cModule, iRC, iBufComm);
01019
01020 if (errno)
01021 {
01022 fprintf(fLogFile, " %s\n", strerror(errno));
01023 errno = 0;
01024 }
01025
01026 iQuery = -1;
01027 goto gEndQueryFile;
01028 }
01029
01030 if (iDebug) fprintf(fLogFile,
01031 " query command sent to entry server (%d bytes), look for reply\n",
01032 iBufComm);
01033
01034
01035
01036 gNextReply:
01037 pcc = (char *) pQuery;
01038 iRC = rawRecvHead(iSocket, pcc);
01039 if (iRC <= 0)
01040 {
01041 fprintf(fLogFile,
01042 "-E- %s: receiving buffer header with query information\n",
01043 cModule);
01044 iQuery = -1;
01045 goto gEndQueryFile;
01046 }
01047
01048 pcc += HEAD_LEN;
01049 iIdent = ntohl(pQuery->iIdent);
01050 iQuery = ntohl(pQuery->iObjCount);
01051 iAttrLen = ntohl(pQuery->iAttrLen);
01052
01053 if (iDebug) fprintf(fLogFile,
01054 " %d bytes received: iIdent %d, iQuery %d, iAttrLen %d\n",
01055 iRC, iIdent, iQuery, iAttrLen);
01056
01057 if ( (iIdent != IDENT_QUERY) && (iIdent != IDENT_QUERY_DONE) &&
01058 (iIdent != IDENT_QUERY_ARCHDB) )
01059 {
01060 iStatus = iQuery;
01061 iQuery = -1;
01062
01063 if (iIdent == IDENT_STATUS)
01064 {
01065 iStatusLen = iAttrLen;
01066 if ( (iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF) ||
01067 (iStatus == STA_ARCHIVE_NOT_AVAIL) ||
01068 (iStatus == STA_NO_ACCESS) )
01069 {
01070 if ( (iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF) )
01071 fprintf(fLogFile,
01072 "-E- %s: error status from entry server instead of query data:\n",
01073 cModule);
01074
01075 if (iStatusLen > 0)
01076 {
01077 iRC = rawRecvError(iSocket, iStatusLen, pcc);
01078 if (iRC < 0) fprintf(fLogFile,
01079 "-E- receiving error msg from server, rc = %d\n",
01080 iRC);
01081 else if ( (iDebug) || (iStatus == STA_ERROR) ||
01082 (iStatus == STA_ERROR_EOF) )
01083 fprintf(fLogFile, "%s", pcc);
01084 }
01085 else
01086 fprintf(fLogFile," no error message available\n");
01087
01088 if (iStatus == STA_ARCHIVE_NOT_AVAIL)
01089 iQuery = -1000;
01090 else if (iStatus == STA_NO_ACCESS)
01091 iQuery = -1001;
01092
01093 }
01094
01095 else fprintf(fLogFile,
01096 "-E- %s: unexpected status (type %d) received from server\n",
01097 cModule, iStatus);
01098
01099 }
01100 else fprintf(fLogFile,
01101 "-E- %s: unexpected header (type %d) received from server\n",
01102 cModule, iIdent);
01103
01104 iQueryAll = iQuery;
01105 goto gEndQueryFile;
01106
01107 }
01108
01109
01110 iQueryAll += iQuery;
01111 if (iQuery > 0)
01112 {
01113 pcc = (char *) pQuery + HEAD_LEN;
01114 pObjAttr = (srawObjAttr *) pcc;
01115
01116
01117 for (ii=1; ii<=iQuery; ii++)
01118 {
01119 iBuf = iAttrLen;
01120 while(iBuf > 0)
01121 {
01122 if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
01123 {
01124 if (iRC < 0)
01125 {
01126 fprintf(fLogFile,
01127 "-E- %s: receiving buffer %d with query results\n",
01128 cModule, ii);
01129
01130 iQuery = -1;
01131 iQueryAll -= iQuery;
01132 }
01133 else
01134 {
01135 jj = iAttrLen - iBuf;
01136 fprintf(fLogFile,
01137 "-E- %s: connection to server broken, only %d bytes of query object %d (%d byte) received\n",
01138 cModule, jj, ii, iAttrLen);
01139
01140 if (ii == 1)
01141 {
01142 iQuery = -1;
01143 iQueryAll -= iQuery;
01144 }
01145 else
01146 {
01147 fprintf(fLogFile,
01148 "-E- %s: only %d of %d objects received\n",
01149 cModule, --ii, iQuery);
01150 iQueryAll -= iQuery - ii;
01151 iQuery = ii;
01152 }
01153 }
01154
01155 if (errno)
01156 {
01157 fprintf(fLogFile, " %s\n", strerror(errno));
01158 errno = 0;
01159 }
01160
01161 goto gEndQueryFile;
01162 }
01163
01164 iBuf -= iRC;
01165 pcc += iRC;
01166
01167 }
01168
01169 iVersionObjAttr = ntohl(pObjAttr->iVersion);
01170 if ( (iVersionObjAttr != VERSION_SRAWOBJATTR) &&
01171 (iVersionObjAttr != VERSION_SRAWOBJATTR-1) )
01172 {
01173 fprintf(fLogFile,
01174 "-E- %s: invalid cacheDB entry version %d\n",
01175 cModule, iVersionObjAttr);
01176
01177 iQuery = -1;
01178 goto gEndQueryFile;
01179 }
01180
01181 iPoolId = ntohl(pObjAttr->iPoolId);
01182 if (iDebug)
01183 {
01184 if (ii == 1) fprintf(fLogFile,
01185 " query buffer received (%d bytes, objAttr data V%d)\n",
01186 iAttrLen, iVersionObjAttr);
01187 else fprintf(fLogFile,
01188 " query buffer overlaid (%d bytes)\n", iAttrLen);
01189
01190 fprintf(fLogFile, " %s%s%s: poolId %d",
01191 pObjAttr->cNamefs, pObjAttr->cNamehl,
01192 pObjAttr->cNamell, iPoolId);
01193 if (iPoolId == 1)
01194 fprintf(fLogFile, " (RetrievePool)\n");
01195 else if (iPoolId == 2)
01196 fprintf(fLogFile, " (StagePool)\n");
01197 else if (iPoolId == 3)
01198 fprintf(fLogFile, " (ArchivePool)\n");
01199 else if (iPoolId == 4)
01200 fprintf(fLogFile, " (DAQPool)\n");
01201 else
01202 fprintf(fLogFile, " (TSM DB)\n");
01203 }
01204 }
01205 }
01206 else if ( (iQuery == 0) && (iDebug) )
01207 fprintf(fLogFile,
01208 " no more objects found in ATL server %d\n", iATLServer);
01209
01210
01211 if ( (strchr(pComm->cNamell, *pcStar) == NULL) &&
01212 (strchr(pComm->cNamell, *pcQM) == NULL) &&
01213 (strchr(pComm->cNamell, *pcPerc) == NULL) &&
01214 (strchr(pComm->cNamehl, *pcStar) == NULL) &&
01215 (strchr(pComm->cNamehl, *pcQM) == NULL) &&
01216 (strchr(pComm->cNamehl, *pcPerc) == NULL) )
01217 iNameWC = 0;
01218 else
01219 iNameWC = 1;
01220
01221 if ( (iNameWC == 0) && (iQuery > 0) )
01222 goto gEndQueryFile;
01223
01224 if ( (iIdent == IDENT_QUERY) || (iIdent == IDENT_QUERY_ARCHDB) )
01225 goto gNextReply;
01226
01227 gEndQueryFile:
01228 switch (iQueryAll)
01229 {
01230 case 0:
01231 if (iDebug) fprintf(fLogFile,
01232 " no matching object %s in gStore found\n",
01233 pComm->cNamell);
01234 break;
01235 case 1:
01236 if (iDebug) fprintf(fLogFile,
01237 " file %s available in gStore\n", pComm->cNamell);
01238 break;
01239 case -1:
01240 fprintf(fLogFile,
01241 "-E- %s: query in gStore could not be executed\n",
01242 cModule);
01243 iQuery = -1;
01244 break;
01245 case -1000:
01246 if (iDebug) fprintf(fLogFile,
01247 " requested archive %s not existing in gStore\n",
01248 pComm->cNamefs);
01249 break;
01250 case -1001:
01251 if (iDebug) fprintf(fLogFile,
01252 " requested access to file %s not allowed\n",
01253 pComm->cNamell);
01254 break;
01255 default:
01256 if (iQueryAll > 1)
01257 {
01258 if (strcmp(pComm->cOwner, "goeri") == 0)
01259 fprintf(fLogFile, "-W- %d versions of %s exist!\n",
01260 iQuery, pComm->cNamell);
01261 }
01262 else
01263 {
01264 fprintf(fLogFile,
01265 "-E- %s: invalid number %d of objects %s found\n",
01266 cModule, iQuery, pComm->cNamell);
01267 iQuery = -1;
01268 }
01269 }
01270
01271 if (iDebug) fprintf(fLogFile,
01272 "-D- end %s\n\n", cModule);
01273
01274 return iQuery;
01275
01276 }
01277
01278
01279
01280
01281
01282
01283
01284
01285 int rawRecvError(int iSocket, int iLen, char *pcMsg)
01286 {
01287 char cModule[32]="rawRecvError";
01288 int iDebug = 0;
01289
01290 int iRC = 0, ii;
01291 int iBuf, iBufs;
01292 char *pcc;
01293
01294 if (iDebug)
01295 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
01296
01297 strcpy(pcMsg, "");
01298 pcc = pcMsg;
01299
01300 iBuf = iLen;
01301 iBufs = iBuf;
01302 while(iBuf > 0)
01303 {
01304 if ( (iRC = recv(iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
01305 {
01306 if (iRC < 0)
01307 {
01308 fprintf(fLogFile,
01309 "-E- %s: receiving error message\n", cModule);
01310
01311 if (errno)
01312 {
01313 fprintf(fLogFile, " %s\n", strerror(errno));
01314 errno = 0;
01315 }
01316
01317 iRC = -9;
01318 break;
01319 }
01320 else
01321 {
01322 ii = iLen - iBuf;
01323 if (ii)
01324 {
01325 *pcc = '\0';
01326 pcc++;
01327 *pcc = '\n';
01328 pcc++;
01329 if (iDebug) fprintf(fLogFile,
01330 "-E- incomplete error message received:\n %s", pcMsg);
01331 }
01332 fprintf(fLogFile,
01333 "-E- %s: connection to sender broken, %d byte of error message (%d byte) received\n",
01334 cModule, ii, iLen);
01335
01336 if (errno)
01337 {
01338 fprintf(fLogFile, " %s\n", strerror(errno));
01339 errno = 0;
01340 }
01341
01342 iRC = -8;
01343 break;
01344 }
01345 }
01346
01347 iBuf -= iRC;
01348 pcc += iRC;
01349
01350 }
01351
01352 if (iBuf < 0)
01353 {
01354 fprintf(fLogFile,
01355 "-E- %s: more error data received than expected:\n %s",
01356 pcMsg, cModule);
01357 iRC = -2;
01358 }
01359
01360 if (iRC == -9)
01361 {
01362 if (iDebug)
01363 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01364
01365 return iRC;
01366 }
01367 else
01368 {
01369
01370 *pcc = '\0';
01371
01372
01373 if (iRC == -8)
01374 iBufs = ii;
01375
01376 if (iDebug)
01377 {
01378 fprintf(fLogFile,
01379 " error message received (%d bytes):\n %s",
01380 iBufs, pcMsg);
01381 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01382 }
01383
01384 return iBufs;
01385 }
01386
01387 }
01388
01389
01390
01391
01392
01393
01394
01395
01396
01397 int rawRecvHead( int iSocket, char *pcBuf)
01398 {
01399 char cModule[32]="rawRecvHead";
01400 int iDebug = 0;
01401
01402 int iBuf, iBufs;
01403 int iRC, ii;
01404 int iIdent;
01405 int iStatus;
01406 int iDataLen;
01407 char *pcc;
01408 int *pint;
01409
01410 if (iDebug)
01411 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
01412
01413 strcpy(pcBuf, "");
01414 pcc = pcBuf;
01415 pint = (int *) pcc;
01416
01417 iBuf = HEAD_LEN;
01418 iBufs = iBuf;
01419 while(iBuf > 0)
01420 {
01421 iRC = recv(iSocket, pcc, (unsigned) iBuf, 0);
01422 if (iRC <= 0)
01423 {
01424 if (iRC < 0) fprintf(fLogFile,
01425 "-E- %s: receiving buffer header\n", cModule);
01426 else
01427 {
01428 ii = iBufs - iBuf;
01429 fprintf(fLogFile,
01430 "-E- %s: connection to sender broken, %d byte of buffer header (%d byte) received\n",
01431 cModule, ii, iBufs);
01432 }
01433
01434 if (errno)
01435 {
01436 fprintf(fLogFile, " %s\n", strerror(errno));
01437 errno = 0;
01438 }
01439
01440 return -1;
01441 }
01442
01443 iBuf -= iRC;
01444 pcc += iRC;
01445
01446 }
01447
01448 iIdent = ntohl(*pint);
01449 pint++;
01450 iStatus = ntohl(*pint);
01451 pint++;
01452 iDataLen = ntohl(*pint);
01453 if (iDebug) fprintf(fLogFile,
01454 " ident %d, status %d, datalen %d\n",
01455 iIdent, iStatus, iDataLen);
01456
01457 if ( (iIdent == IDENT_STATUS) &&
01458 ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF)) &&
01459 (iDataLen > 0) )
01460 {
01461 if (iDebug) fprintf(fLogFile,
01462 "-W- %s: error message available for receive (%d byte)\n",
01463 cModule, iDataLen);
01464 return iDataLen;
01465 }
01466
01467 if (iDebug) fprintf(fLogFile,
01468 "-D- end %s: buffer header received (%d bytes)\n\n",
01469 cModule, iBufs);
01470
01471 return iBufs;
01472
01473 }
01474
01475
01476
01477
01478
01479
01480
01481
01482
01483
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494 int rawRecvHeadC(int iSocket,
01495 char *pcBuf,
01496 int iIdentReq,
01497 int iStatusReq,
01498 char *pcMsg)
01499 {
01500 char cModule[32] = "rawRecvHeadC";
01501 int iDebug = 0;
01502
01503
01504 int iIdent;
01505 int iStatus;
01506 int iDataLen;
01507
01508 char cMsg1[STATUS_LEN] = "";
01509
01510 int iRC, ii;
01511 int iBuf, iBufs;
01512 char *pcc;
01513 int *pint;
01514
01515 if (iDebug)
01516 {
01517 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
01518
01519 if (iIdentReq < 0) fprintf(fLogFile,
01520 " check Ident, expect %d\n", iIdentReq);
01521 else
01522 fprintf(fLogFile, " no check of Ident\n");
01523 if (iStatusReq >= 0) fprintf(fLogFile,
01524 " check Status, expect %d\n", iStatusReq);
01525 else
01526 fprintf(fLogFile, " no check of Status\n");
01527 }
01528
01529 strcpy(pcMsg, "");
01530 strcpy(pcBuf, "");
01531 pcc = pcBuf;
01532
01533 iBuf = HEAD_LEN;
01534 iBufs = iBuf;
01535 while(iBuf > 0)
01536 {
01537 if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
01538 {
01539 if (iRC < 0)
01540 {
01541 sprintf(pcMsg, "-E- %s: receiving buffer header\n",
01542 cModule);
01543 iRC = -1;
01544 }
01545 else
01546 {
01547 ii = iBufs - iBuf;
01548 sprintf(pcMsg,
01549 "-E- %s: connection to sender broken, %d byte of buffer header (%d byte) received\n",
01550 cModule, ii, iBufs);
01551 iRC = -2;
01552 }
01553
01554 if (errno)
01555 {
01556 sprintf(cMsg1, " %s\n", strerror(errno));
01557 strcat(pcMsg, cMsg1);
01558 errno = 0;
01559 }
01560
01561 if (iDebug)
01562 fprintf(fLogFile, pcMsg);
01563
01564 goto gEndRecvHeadC;
01565 }
01566
01567 iBuf -= iRC;
01568 pcc += iRC;
01569
01570 }
01571
01572 if (iDebug) fprintf(fLogFile,
01573 " buffer header received (%d bytes)\n", iBufs);
01574
01575 pint = (int *) pcBuf;
01576 iIdent = ntohl(*pint);
01577 pint++;
01578 iStatus = ntohl(*pint);
01579 pint++;
01580 iDataLen = ntohl(*pint);
01581
01582 if (iDebug) fprintf(fLogFile,
01583 " ident %d, status %d, datalen %d\n",
01584 iIdent, iStatus, iDataLen);
01585
01586 if (iIdent == IDENT_STATUS)
01587 {
01588 if (iDebug)
01589 {
01590 fprintf(fLogFile, " status received");
01591 if ( (iDataLen) &&
01592 ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF)) )
01593 fprintf(fLogFile, " with error message\n");
01594 else
01595 fprintf(fLogFile, "\n");
01596 }
01597
01598 if ( (iDataLen) &&
01599 ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF) ||
01600 (iStatus == STA_CACHE_FULL)) )
01601 {
01602 pcc = cMsg1;
01603 iRC = rawRecvError(iSocket, iDataLen, pcc);
01604 if (iRC < 0)
01605 {
01606 sprintf(pcMsg, "-E- %s: receiving error msg, rc=%d\n",
01607 cModule, iRC);
01608 if (iDebug)
01609 fprintf(fLogFile, pcMsg);
01610
01611 iRC = -3;
01612 goto gEndRecvHeadC;
01613 }
01614
01615 if (iDebug) fprintf(fLogFile,
01616 " msg (%d byte): %s\n", iDataLen, pcc);
01617 strcat(pcMsg, pcc);
01618 iRC = strlen(pcMsg);
01619 goto gEndRecvHeadC;
01620 }
01621
01622 if ( (iDataLen == 0) &&
01623 ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF)) )
01624 {
01625 strcat(pcMsg,
01626 "-W- error status received, but no error message\n");
01627 iRC = 0;
01628 goto gEndRecvHeadC;
01629 }
01630 }
01631
01632 if (iIdentReq < 0)
01633 {
01634 if (iDebug)
01635 fprintf(fLogFile, " check identifier\n");
01636
01637 if (iIdent != iIdentReq)
01638 {
01639 sprintf(pcMsg,
01640 "-E- %s: unexpected header (ident %d) received\n",
01641 cModule, iIdent);
01642 if (iDebug)
01643 fprintf(fLogFile, pcMsg);
01644
01645 iRC = -4;
01646 goto gEndRecvHeadC;
01647
01648 }
01649 else
01650 {
01651 if (iStatusReq >= 0)
01652 {
01653 if (iDebug)
01654 fprintf(fLogFile, " check status\n");
01655
01656 if (iStatusReq != iStatus)
01657 {
01658 sprintf(pcMsg,
01659 "-E- %s: unexpected header (status %d) received\n",
01660 cModule, iStatus);
01661 if (iDebug)
01662 fprintf(fLogFile, pcMsg);
01663
01664 iRC = -5;
01665 goto gEndRecvHeadC;
01666 }
01667 }
01668 }
01669 }
01670
01671 iRC = HEAD_LEN;
01672
01673 gEndRecvHeadC:
01674 if (iDebug)
01675 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01676
01677 return iRC;
01678
01679 }
01680
01681
01682
01683
01684
01685
01686
01687
01688
01689
01690
01691
01692
01693
01694 int rawRecvRequest(int iSocket,
01695 int *piSeekMode,
01696 int *piOffset,
01697 int *piBufferSize)
01698 {
01699 char cModule[32]="rawRecvRequest";
01700 int iDebug = 0;
01701
01702 int iRC;
01703 int iError = 0;
01704 int iRequSize = sizeof(srawRequest);
01705 int iBuf, iBuf0;
01706 int ii, iimax;
01707 char *pcc;
01708 char cMsg[STATUS_LEN] = "";
01709
01710 srawRequest sRequest, *pRequest;
01711
01712 if (iDebug) fprintf(fLogFile,
01713 "\n-D- begin %s: receive request buffer\n", cModule);
01714
01715 pRequest = &sRequest;
01716 pcc = (char *) pRequest;
01717 iBuf = HEAD_LEN;
01718 iimax = HEAD_LEN;
01719 while(iBuf > 0)
01720 {
01721 if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
01722 {
01723 if (iRC < 0)
01724 {
01725 fprintf(fLogFile,
01726 "-E- %s: receiving buffer header\n", cModule);
01727 iError = -1;
01728 }
01729 else
01730 {
01731 ii = iimax - iBuf;
01732 fprintf(fLogFile,
01733 "-W- %s: connection to sender broken, %d byte of buffer header (%d byte) received\n",
01734 cModule, ii, iimax);
01735 iError = -5;
01736 }
01737
01738 goto gErrorRecvRequest;
01739 }
01740
01741 iBuf -= iRC;
01742 pcc += iRC;
01743
01744 }
01745
01746 if (iBuf < 0)
01747 {
01748 fprintf(fLogFile,
01749 "-E- %s: more buffer header data received than expected\n",
01750 cModule);
01751
01752 iError = -2;
01753 goto gErrorRecvRequest;
01754 }
01755
01756 pRequest->iIdent = ntohl(pRequest->iIdent);
01757 if (iDebug) fprintf(fLogFile,
01758 " buffer header received (%d bytes, id %d)\n",
01759 iimax, pRequest->iIdent);
01760
01761 if ( (pRequest->iIdent != IDENT_NEXT_BUFFER) &&
01762 (pRequest->iIdent != IDENT_STATUS) )
01763 {
01764 fprintf(fLogFile, "-E- %s: invalid buffer received (id %d)\n",
01765 cModule, pRequest->iIdent);
01766 iError = -3;
01767 goto gErrorRecvRequest;
01768 }
01769
01770 pRequest->iStatus = ntohl(pRequest->iStatus);
01771 pRequest->iStatusLen = ntohl(pRequest->iStatusLen);
01772 iBuf0 = pRequest->iStatusLen;
01773 iBuf = iBuf0;
01774 if (pRequest->iIdent != IDENT_NEXT_BUFFER)
01775 pcc = cMsg;
01776
01777 while(iBuf > 0)
01778 {
01779 if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
01780 {
01781 if (iRC < 0)
01782 {
01783 fprintf(fLogFile,
01784 "-E- %s: receiving buffer data\n", cModule);
01785 iError = -1;
01786 }
01787 else
01788 {
01789 ii = iBuf0 - iBuf;
01790 fprintf(fLogFile,
01791 "-W- %s: connection to sender broken, %d byte of data (%d byte) received\n",
01792 cModule, ii, iBuf0);
01793 iError = -5;
01794 }
01795
01796 if (errno)
01797 {
01798 fprintf(fLogFile, " %s\n", strerror(errno));
01799 errno = 0;
01800 }
01801
01802 goto gErrorRecvRequest;
01803 }
01804
01805 iBuf -= iRC;
01806 pcc += iRC;
01807
01808 }
01809
01810 if (iBuf < 0)
01811 {
01812 fprintf(fLogFile, "-E- %s: more data received than expected\n",
01813 cModule);
01814 iError = -2;
01815 goto gErrorRecvRequest;
01816 }
01817
01818 if (pRequest->iIdent == IDENT_NEXT_BUFFER)
01819 {
01820 if (iDebug) fprintf(fLogFile,
01821 " %s: request data received (%d bytes)\n", cModule, iBuf0);
01822
01823 if (iBuf0 + HEAD_LEN != iRequSize)
01824 {
01825 fprintf(fLogFile,
01826 "-E- %s: invalid data size (%d) in request buffer (expected %d byte)\n",
01827 cModule, iBuf0, iRequSize-HEAD_LEN);
01828 iError = -4;
01829 goto gErrorRecvRequest;
01830 }
01831
01832 *piSeekMode = ntohl(pRequest->iSeekMode);
01833 *piOffset = ntohl(pRequest->iOffset);
01834 *piBufferSize = ntohl(pRequest->iBufferSize);
01835
01836 if (iDebug)
01837 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01838
01839 return 0;
01840
01841 }
01842 else if (pRequest->iIdent == IDENT_STATUS)
01843 {
01844 if ( (pRequest->iStatus == STA_END_OF_FILE) ||
01845 (pRequest->iStatus == STA_END_OF_SESSION) )
01846 {
01847 if (iDebug) fprintf(fLogFile,
01848 " %s: status info received: end session\n", cModule);
01849 }
01850 else if ( (pRequest->iStatus == STA_ERROR) ||
01851 (pRequest->iStatus == STA_ERROR_EOF) )
01852
01853 {
01854 if (iDebug) fprintf(fLogFile,
01855 "-W- %s: error status received: end session\n", cModule);
01856 if (iBuf0 > 0) fprintf(fLogFile,
01857 "-W- %s: error message from client:\n %s\n",
01858 cModule, cMsg);
01859 iError = -4;
01860 goto gErrorRecvRequest;
01861 }
01862 else
01863 {
01864 fprintf(fLogFile,
01865 "-E- %s: invalid status buffer received (id %d)\n",
01866 cModule, pRequest->iStatus);
01867 iError = -3;
01868 goto gErrorRecvRequest;
01869 }
01870
01871 iError = pRequest->iStatus;
01872 goto gErrorRecvRequest;
01873
01874 }
01875 else
01876 {
01877 fprintf(fLogFile, "-E- %s: invalid buffer received (ident %d)\n",
01878 cModule, pRequest->iIdent);
01879 iError = -2;
01880 goto gErrorRecvRequest;
01881 }
01882
01883 gErrorRecvRequest:
01884 if (iDebug)
01885 fprintf(fLogFile, "-D- end %s\n\n", cModule);
01886
01887 if (iError)
01888 return iError;
01889
01890 return 0;
01891
01892 }
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903 int rawRecvStatus( int iSocket, char *pcBuf)
01904 {
01905 char cModule[32]="rawRecvStatus";
01906 int iDebug = 0;
01907
01908 int iRC, ii;
01909 int iBuf, iBufs;
01910 int iLen;
01911 char *pcc;
01912 srawStatus *pStatus;
01913
01914 if (iDebug)
01915 fprintf(fLogFile, "\n-D- begin %s\n", cModule);
01916
01917 pcc = pcBuf;
01918 pStatus = (srawStatus *) pcc;
01919 memset(pcc, 0x00, sizeof(HEAD_LEN));
01920 iBuf = HEAD_LEN;
01921 iBufs = iBuf;
01922
01923 while(iBuf > 0)
01924 {
01925 if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
01926 {
01927 if (iRC < 0) fprintf(fLogFile,
01928 "-E- %s: receiving status header\n", cModule);
01929 else
01930 {
01931 ii = iBufs - iBuf;
01932 fprintf(fLogFile,
01933 "-E- %s: connection to sender broken, %d byte of status header (%d byte) received\n",
01934 cModule, ii, iBufs);
01935 }
01936
01937 if (errno)
01938 {
01939 fprintf(fLogFile, " %s\n", strerror(errno));
01940 errno = 0;
01941 }
01942
01943 return -1;
01944 }
01945
01946 iBuf -= iRC;
01947 pcc += iRC;
01948
01949 }
01950
01951 if (iBuf < 0)
01952 {
01953 fprintf(fLogFile,
01954 "-E- %s: more status header data received than expected\n",
01955 cModule);
01956 return -2;
01957 }
01958
01959 pStatus->iIdent = ntohl(pStatus->iIdent);
01960 pStatus->iStatus = ntohl(pStatus->iStatus);
01961 pStatus->iStatusLen = ntohl(pStatus->iStatusLen);
01962
01963 if (iDebug)
01964 {
01965 fprintf(fLogFile, " status header received (%d bytes)\n",
01966 iBufs);
01967 fprintf(fLogFile, " ident %d, status %d, status len %d\n",
01968 pStatus->iIdent, pStatus->iStatus, pStatus->iStatusLen);
01969 }
01970
01971 if (pStatus->iIdent != IDENT_STATUS)
01972 {
01973 fprintf(fLogFile, "-E- %s: invalid status header received (%d)\n",
01974 cModule, pStatus->iIdent);
01975 return -3;
01976 }
01977
01978 iLen = pStatus->iStatusLen;
01979 if (iLen > 0)
01980 {
01981 memset(pcc, 0x00, (unsigned) iLen);
01982 iBuf = iLen;
01983 iBufs += iBuf;
01984 while(iBuf > 0)
01985 {
01986 if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
01987 {
01988 if (iRC < 0) fprintf(fLogFile,
01989 "-E- %s: receiving status message\n", cModule);
01990 else
01991 {
01992 ii = iLen - iBuf;
01993 fprintf(fLogFile,
01994 "-E- %s: connection to sender broken, %d byte of status message (%d byte) received\n",
01995 cModule, ii, iLen);
01996 }
01997
01998 if (errno)
01999 {
02000 fprintf(fLogFile, " %s\n", strerror(errno));
02001 errno = 0;
02002 }
02003
02004 return -4;
02005 }
02006
02007 iBuf -= iRC;
02008 pcc += iRC;
02009
02010 }
02011
02012 if (iBuf < 0)
02013 {
02014 fprintf(fLogFile,
02015 "-E- %s: more status data received than expected\n",
02016 cModule);
02017 return -5;
02018 }
02019
02020 if (iDebug) fprintf(fLogFile,
02021 " status message received (%d bytes):\n%s\n",
02022 iLen, pStatus->cStatus);
02023
02024 }
02025
02026 if (iDebug)
02027 fprintf(fLogFile, "-D- end %s\n\n", cModule);
02028
02029 return iBufs;
02030
02031 }
02032
02033
02034
02035
02036
02037
02038
02039
02040
02041
02042 int rawSendRequest(int iSocket,
02043 int iSeekMode,
02044 int iOffset,
02045 int iBufferSize)
02046 {
02047 char cModule[32]="rawSendRequest";
02048 int iDebug = 0;
02049
02050 int iBuf, iRC;
02051 char *pcc;
02052
02053 srawRequest sRequest;
02054 int iRequSize = sizeof(srawRequest);
02055
02056 if (iDebug) fprintf(fLogFile,
02057 "\n-D- begin %s: send request buffer\n", cModule);
02058
02059 sRequest.iIdent = htonl((unsigned int) IDENT_NEXT_BUFFER);
02060 if (iSeekMode < 0)
02061 sRequest.iStatus = htonl(STA_NEXT_BUFFER);
02062 else
02063 sRequest.iStatus = htonl(STA_SEEK_BUFFER);
02064 sRequest.iStatusLen = htonl(iRequSize - HEAD_LEN);
02065
02066 sRequest.iSeekMode = htonl(iSeekMode);
02067 sRequest.iOffset = htonl(iOffset);
02068 if (iBufferSize < 0)
02069 {
02070 fprintf(fLogFile,
02071 "-E- %s: invalid buffer size %d\n", cModule, iBufferSize);
02072 return -1;
02073 }
02074 sRequest.iBufferSize = htonl(iBufferSize);
02075
02076 iBuf = iRequSize;
02077 pcc = (char *) &sRequest;
02078 iRC = send(iSocket, pcc, (unsigned) iBuf, 0);
02079 if (iRC < iBuf)
02080 {
02081 if (iRC < 0) fprintf(fLogFile,
02082 "-E- %s: sending request buffer\n", cModule);
02083 else fprintf(fLogFile,
02084 "-E- %s: request buffer incompletely sent (%d of %d byte)\n",
02085 cModule, iRC, iBuf);
02086
02087 if (errno)
02088 {
02089 fprintf(fLogFile, " %s\n", strerror(errno));
02090 errno = 0;
02091 }
02092
02093 return -1;
02094 }
02095
02096 if (iDebug) fprintf(fLogFile,
02097 "-D- end %s: request buffer sent\n\n", cModule);
02098
02099 return 0;
02100
02101 }
02102
02103
02104
02105
02106
02107
02108
02109
02110
02111
02112 int rawSendStatus( int iSocket, int iStatus, char *pcMsg)
02113 {
02114 char cModule[32]="rawSendStatus";
02115 int iDebug = 0;
02116
02117 int iBuf = HEAD_LEN;
02118 int iRC, iMsgLen;
02119 char *pcc;
02120 srawStatus sStatus;
02121
02122 if (iDebug) fprintf(fLogFile,
02123 "\n-D- begin %s: send status buffer (%d) to socket %d\n",
02124 cModule, iStatus, iSocket);
02125
02126 sStatus.iIdent = htonl((unsigned int) IDENT_STATUS);
02127 sStatus.iStatus = htonl(iStatus);
02128 sStatus.iStatusLen = htonl(0);
02129
02130 if (pcMsg == NULL)
02131 iMsgLen = 0;
02132 else
02133 iMsgLen = strlen(pcMsg);
02134 if (iMsgLen)
02135 {
02136 iBuf += iMsgLen;
02137 sStatus.iStatusLen = htonl(iMsgLen);
02138 strcpy(sStatus.cStatus, pcMsg);
02139 if (iDebug) fprintf(fLogFile,
02140 " %s: error message (%d bytes):\n %s\n",
02141 cModule, iMsgLen, pcMsg);
02142 }
02143
02144 pcc = (char *) &sStatus;
02145 if (iDebug)
02146 {
02147 fprintf(fLogFile,
02148 " now send (iIdent %d, iStatus %d, iStatusLen %d), %d byte:\n",
02149 ntohl(sStatus.iIdent), ntohl(sStatus.iStatus),
02150 ntohl(sStatus.iStatusLen), iBuf);
02151 fflush(fLogFile);
02152 }
02153
02154 iRC = send(iSocket, pcc, (unsigned) iBuf, 0);
02155 if (iRC < iBuf)
02156 {
02157 if (iRC < 0) fprintf(fLogFile,
02158 "-E- %s: sending status buffer\n", cModule);
02159 else fprintf(fLogFile,
02160 "-E- %s: status buffer incompletely sent (%d of %d byte)\n",
02161 cModule, iRC, iBuf);
02162
02163 if (errno)
02164 {
02165 fprintf(fLogFile, " %s\n", strerror(errno));
02166 errno = 0;
02167 }
02168
02169 return -1;
02170 }
02171
02172 if (iDebug) fprintf(fLogFile,
02173 "-D- end %s: status buffer sent (%d byte)\n\n", cModule, iBuf);
02174
02175 return(iBuf);
02176
02177 }
02178
02179
02180
02181
02182
02183
02184
02185
02186
02187 int rawTestFileName( char *pcFile)
02188 {
02189 char cModule[32] = "rawTestFileName";
02190 int iDebug = 0;
02191
02192 int iRC;
02193 int ilen;
02194 int iError = 0;
02195 unsigned long lFileSize = 0;
02196 int iSize = 0;
02197 char *pdir;
02198
02199 if (iDebug) fprintf(fLogFile,
02200 "-D- begin %s: input file name %s\n", cModule, pcFile);
02201
02202 if ( (pdir = strrchr(pcFile, '*')) != NULL)
02203 {
02204 fprintf(fLogFile,
02205 "-E- invalid file name '%s': '*' not allowed as part of file name\n",
02206 pcFile);
02207 iError = 3;
02208 goto gErrorTest;
02209 }
02210
02211 if ( (pdir = strrchr(pcFile, '?')) != NULL)
02212 {
02213 fprintf(fLogFile,
02214 "-E- invalid file name '%s': '?' not allowed as part of file name\n",
02215 pcFile);
02216 iError = 3;
02217 goto gErrorTest;
02218 }
02219
02220 if ( (pdir = strrchr(pcFile, '/')) == NULL)
02221 {
02222 if (iDebug)
02223 fprintf(fLogFile, " name %s okay\n", pcFile);
02224 }
02225 else
02226 {
02227 ilen = strlen(pdir);
02228 if (iDebug) fprintf(fLogFile,
02229 " trailor %s (len %d)\n", pdir, ilen);
02230 if (ilen == 1)
02231 {
02232 strncpy(pdir, "\0", 1);
02233 if (iDebug)
02234 fprintf(fLogFile, " %s is a directory\n", pcFile);
02235 iError = 2;
02236 goto gErrorTest;
02237 }
02238 else if (iDebug)
02239 fprintf(fLogFile, " rel name %s okay\n", pcFile);
02240 }
02241
02242 iRC = rawGetFileSize(pcFile, &lFileSize, &iSize);
02243 if (iDebug) fprintf(fLogFile,
02244 " after rawGetFileSize, rc = %d\n", iRC);
02245
02246 if (iRC)
02247 {
02248 if (iDebug)
02249 {
02250 fprintf(fLogFile, "-W- %s NOT archived", pcFile);
02251 if (iRC == 1)
02252 fprintf(fLogFile, " - is a directory\n");
02253 else if (iRC == 2)
02254 fprintf(fLogFile, " - is a symbolic link\n");
02255 else if (iRC == 3)
02256 fprintf(fLogFile, " - is not a regular file\n");
02257 else
02258 fprintf(fLogFile, "\n");
02259 }
02260
02261 iError = 2;
02262 goto gErrorTest;
02263 }
02264
02265 if (iDebug) fprintf(fLogFile,
02266 " %s is a regular file\n", pcFile);
02267
02268 gErrorTest:
02269 if (iDebug)
02270 fprintf(fLogFile, "-D- end %s\n\n", cModule);
02271
02272 return iError;
02273
02274 }
02275