Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Namespace Members | Class Members | File Members

rawProcn.c

Go to the documentation of this file.
00001 //-------------------------------------------------------------
00002 //        Go4 Release Package v3.04-01 (build 30401)
00003 //                      28-November-2008
00004 //---------------------------------------------------------------
00005 //   The GSI Online Offline Object Oriented (Go4) Project
00006 //   Experiment Data Processing at EE department, GSI
00007 //---------------------------------------------------------------
00008 //
00009 //Copyright (C) 2000- Gesellschaft f. Schwerionenforschung, GSI
00010 //                    Planckstr. 1, 64291 Darmstadt, Germany
00011 //Contact:            http://go4.gsi.de
00012 //----------------------------------------------------------------
00013 //This software can be used under the license agreements as stated
00014 //in Go4License.txt file which is part of the distribution.
00015 //----------------------------------------------------------------
00016 /**********************************************************************
00017  * Copyright:
00018  *   GSI, Gesellschaft fuer Schwerionenforschung mbH
00019  *   Planckstr. 1
00020  *   D-64291 Darmstadt
00021  *   Germany
00022  * created 14. 2.1996, Horst Goeringer
00023  **********************************************************************
00024  * rawProcn.c
00025  * utility programs for adsmcli package: all clients
00026  **********************************************************************
00027  * rawGetFileSize:   get file size (byte) via Posix call stat
00028  * rawGetFullFile:   get full file name from generic input & ll name
00029  * rawGetFSName:     get file space name from user identification
00030  * rawGetHLName:     get high level object name from path
00031  * rawGetLLName:     get low level object name from file name
00032  * rawGetPathName:   get path name from high level object name
00033  * rawQueryPrint:    print query results for one object to stdout
00034  * rawQueryString:   print query results for one object to string
00035  * rawRecvError:     receive error message
00036  * rawRecvHead:      receive common buffer header
00037  * rawRecvHeadC:     receive common buffer header and check
00038  * rawRecvRequest:   receive request for next buffer
00039  * rawRecvStatus:    receive status buffer
00040  * rawSendRequest:   send request for next buffer
00041  * rawSendStatus:    send status buffer
00042  * rawTestFileName:  verify that specified name is a valid file name
00043  * rawTestFilePath:  verify that file path not generic
00044  **********************************************************************
00045  * 16. 5.1997, H.G.: keep only modules for all clients here
00046  * 16. 6.1997, H.G.: ported to Linux
00047  * 15.10.1997, H.G.: rawCheckAuth moved to rawCheckAuth.c
00048  * 22.10.1997, H.G.: rawDelFilelist added
00049  *  8. 7.1998, H.G.: new filetype STREAM
00050  * 19.10.1998, H.G.: rawapitd.h introduced, dsmapitd.h removed
00051  * 27. 7.1999, H.G.: rawGetFullFile: don't check matches, rely on ADSM
00052  *  1.12.2000, H.G.: rawSendStatus: send also buffer request headers
00053  *  7. 2.2001, H.G.: new function rawQueryString
00054  * 18. 5.2001, H.G.: function rawDelFilelist -> rawcliproc.c
00055  * 18. 6.2001, H.G.: function rawTestFile: renamed to  rawTestFileName,
00056  *                   handle mixed case
00057  * 18. 7.2001, H.G.: use rawclin.h
00058  *  2.11.2001, H.G.: ported to W2000
00059  * 14.11.2001, H.G.: take alternate delimiter for Windows into account
00060  *  9. 1.2002, H.G.: rawGetLLName: pass object and delimiter as argument
00061  * 19. 2.2002, H.G.: rawGetFileSize added
00062  * 20. 2.2002, H.G.: rawGetCmdParms removed (unused)
00063  *  7. 3.2002, H.G.: rawRecvHeadC added
00064  *  7. 3.2002, H.G.: rawQueryPrint: new type GSI_MEDIA_INCOMPLETE
00065  *  7. 6.2002, H.G.: rawRecvHeadC: check always for error status
00066  * 23. 7.2002, H.G.: replace old printf() -> sprintf(fLogFile)
00067  * 14.10.2002, H.G.: ported to Lynx
00068  * 31. 1.2003, H.G.: use rawdefn.h
00069  * 17. 2.2003, H.G.: rawCheckFilelist, rawCheckObjlist -> rawcliprocn.c
00070  *  3. 6.2003, H.G.: renamed from rawprocn to rawProcn
00071  *  9. 7.2003, H.G.: rawTestFileName: call rawGetFileSize to identify
00072  *                   directories
00073  * 13. 8.2003, H.G.: rawQueryPrint: add user who staged file in output
00074  *  5.12.2003, H.G.: rawRecvStatus: convert status header to host format
00075  * 28. 1.2004, H.G.: GSI_MEDIA_CACHE: rawQueryPrint, rawQueryString
00076  *                   GSI_MEDIA_INCOMPLETE: in rawQueryString
00077  * 26. 5.2004, H.G.: rawQueryPrint, rawQueryString: new print modes:
00078  *                   stage status not checked
00079  **********************************************************************
00080  */
00081 
00082 #include <stdio.h>
00083 #include <string.h>
00084 #include <stdlib.h>
00085 #include <sys/stat.h>
00086 
00087 #ifdef WIN32          /* Windows */
00088 #include <sys\types.h>
00089 #include <winsock.h>
00090 #include <windows.h>
00091 #include <process.h>
00092 #else                 /* Unix */
00093 
00094 #ifdef Lynx
00095 #include <sys/types.h>
00096 #else
00097 #include <sys/types.h>
00098 #endif
00099 
00100 #include <ctype.h>
00101 #include <sys/socket.h>
00102 #include <unistd.h>
00103 #endif              /* end Unix */
00104 
00105 #ifdef Linux
00106 #include <linux/in.h>
00107 #endif
00108 #ifdef Lynx
00109 #include <netinet/in.h>
00110 #endif
00111 
00112 #ifdef _AIX
00113 #include <in.h>
00114 #endif
00115 
00116 #ifdef VMS
00117 #include <in.h>
00118 #include <unixio.h>
00119 #include <unixlib.h>
00120 #endif
00121 
00122 #include "rawapitd.h"
00123 #include "rawapitd-gsi.h"
00124 #include "rawcommn.h"
00125 #include "rawdefn.h"
00126 #include "rawentn.h"
00127 
00128 extern FILE *fLogFile;
00129 
00130 static char cPath[MAX_FILE] = "";
00131 static char cNamefs[MAX_OBJ_FS] = "";
00132 static char cNamehl[MAX_OBJ_HL] = "";
00133 
00134 static char *pcNull = "";        /* to be returned in case of error */
00135                        /* return(NULL) works in AIX, but not in VMS */
00136 
00137 /**********************************************************************
00138  * rawGetFileSize
00139  *    get file size (bytes)
00140  * created 19.2.2002, Horst Goeringer
00141  **********************************************************************
00142  */
00143 
00144 int rawGetFileSize(char *pcFile,
00145                    unsigned long *piSize,
00146                    unsigned long *piRecl)     /* needed only for VMS */
00147 {
00148    char cModule[32] = "rawGetFileSize";
00149    int iDebug = 0;
00150    int iRC;
00151    unsigned long iRecl = 0;
00152    unsigned long iSize = 0;
00153 
00154 #ifdef WIN32          /* Windows */
00155    struct _stat sFileStatus, *pFileStatus;
00156 #else                 /* Unix or VMS */
00157    struct stat sFileStatus, *pFileStatus;
00158 #endif
00159 
00160    if (iDebug) fprintf(fLogFile,
00161       "\n-D- begin %s: file %s\n", cModule, pcFile);
00162 
00163    pFileStatus = &sFileStatus;
00164 
00165 #ifdef WIN32          /* Windows */
00166    iRC = _stat(pcFile, pFileStatus);
00167 #else                 /* Unix or VMS */
00168    iRC = stat(pcFile, pFileStatus);
00169 #endif
00170    if (iRC)
00171    {
00172       fprintf(fLogFile,
00173          "-E- file %s unavailable\n", pcFile);
00174       perror("    ");
00175       return -1;
00176    }
00177 
00178 #ifdef VMS
00179       iRecl = pFileStatus->st_fab_mrs;
00180 #else
00181 #ifdef WIN32
00182       iRecl = 0;    /* not available in Windows */
00183 #else
00184       iRecl = pFileStatus->st_blksize;
00185 #endif
00186 #endif
00187    iSize = pFileStatus->st_size;
00188    if (pFileStatus->st_mode & S_IFREG)
00189    {
00190       iRC = 0;
00191       if (iDebug) fprintf(fLogFile,
00192          "    file %s: size %d, recl %d (byte)\n",
00193          pcFile, iSize, iRecl);
00194    }
00195    else
00196    {
00197       if (pFileStatus->st_mode & S_IFDIR)
00198       {
00199          iRC = 1;
00200          if (iDebug) fprintf(fLogFile,
00201             "-W- %s is a directory, size %d\n", pcFile, iSize);
00202       }
00203 #ifndef WIN32
00204 #ifndef VMS
00205       else if (pFileStatus->st_mode & S_IFLNK)
00206       {
00207          iRC = 2;
00208          if (iDebug) fprintf(fLogFile,
00209             "-W- %s is a symbolic link, size %d\n", pcFile, iSize);
00210       }
00211 #endif
00212 #endif
00213       else
00214       {
00215          iRC = 3;
00216          if (iDebug) fprintf(fLogFile,
00217             "-W- unexpected item %s, size %d\n", pcFile, iSize);
00218       }
00219    }
00220 
00221    *piRecl = iRecl;
00222    *piSize = iSize;
00223    if (iDebug)
00224       fprintf(fLogFile, "-D- end %s\n\n", cModule);
00225 
00226    return iRC;
00227 
00228 } /* rawGetFileSize */
00229 
00230 /********************************************************************
00231  * rawGetFullFile: get full file name from generic input and ll name
00232  *    returns full file name
00233  *
00234  * created 18. 3.1996, Horst Goeringer
00235  ********************************************************************
00236  */
00237 
00238 char *rawGetFullFile(char *pcFile, char *pcNamell)
00239 {
00240 
00241    char cModule[32] = "rawGetFullFile";
00242 
00243    char cname1[MAX_FILE] = "";       /* name structure assumed:    */
00244    char cname2[MAX_FILE] = "";       /*    cPath / cname1 * cname2 */
00245                                      /* cPath globally declared    */
00246 
00247    int iDebug = 0;
00248    int ilen;
00249    int iRC;
00250 
00251    char *ploc=NULL, *pdelim=NULL, *pdelim2=NULL;
00252    char *pc, *pcll;
00253 
00254    strcpy(cPath, pcFile);
00255    pdelim = strrchr(cPath, *pcFileDelim);
00256    if (pdelim != NULL)                           /* path specified */
00257    {
00258       strncpy(pdelim, "\0", 1);
00259       strcpy(cname1, ++pdelim);
00260    }
00261    else
00262    {
00263 #ifdef VMS
00264       pdelim2 = strrchr(cPath, *pcFileDelim2);
00265       if (pdelim2 != NULL)      /* logical device specified */
00266       {
00267          strncpy(pdelim2, "\0", 1);
00268          strcpy(cname1, ++pdelim2);
00269       }
00270       else
00271       {
00272 #endif
00273          strncpy(cPath, "\0", 1);
00274          strcpy(cname1, pcFile);
00275 #ifdef VMS
00276       }
00277 #endif
00278    } /* (pdelim == NULL) */
00279 
00280    ilen = strlen(cname1);
00281    if (iDebug)
00282    {
00283 #ifdef VMS
00284       if (pdelim != NULL)
00285          fprintf(fLogFile, "-D- %s: path %s], name1: %s (len %d)\n",
00286                  cModule, cPath, cname1, ilen);
00287             /* !!! bracket in fprintf needed, as not yet in cPath */
00288       else
00289       {
00290          if (pdelim2 != NULL)
00291             fprintf(fLogFile, "-D- %s: device %s, name1: %s (len %d)\n",
00292                     cModule, cPath, cname1, ilen);
00293          else
00294             fprintf(fLogFile, "-D- %s: no prefix, name1: %s (len %d)\n",
00295                     cModule, cname1, ilen);
00296       }
00297 #else
00298       fprintf(fLogFile,
00299          "    path: %s, name1: %s (len %d)\n", cPath, cname1, ilen);
00300 #endif
00301    }
00302 
00303    pc = &cname1[0];
00304    pcll = pcNamell;
00305    iRC = strncmp(pcll, pcObjDelim, 1);
00306    if (iRC == 0) pcll++;                  /* skip object delimiter */
00307    else
00308    {
00309       iRC = strncmp(pcll, pcObjDelimAlt, 1);
00310       if (iRC == 0) pcll++;               /* skip object delimiter */
00311    }
00312 
00313    if (strlen(cPath) > 0)
00314    {
00315 #ifdef VMS
00316       if (pdelim2 != NULL)
00317          strcat(cPath, pcFileDelim2);
00318       else
00319 #endif
00320          strcat(cPath, pcFileDelim);
00321    }
00322    strcat(cPath, pcll);
00323    if (iDebug) fprintf(fLogFile,
00324       "-D- end %s: full file name found: %s\n\n", cModule, cPath);
00325 
00326    return( (char *) cPath);
00327 
00328 } /* rawGetFullFile */
00329 
00330 /**********************************************************************
00331  * rawGetFSName
00332  *    get file space name from user specification
00333  * created 22.3.1996, Horst Goeringer
00334  **********************************************************************
00335  */
00336 
00337 char *rawGetFSName( char *pcUser )
00338 {
00339    int iDebug = 0;
00340    char cModule[32]="rawGetFSName";
00341    char *pc;
00342 
00343    if (iDebug)
00344       fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00345 
00346    pc = pcUser;
00347    if ( (strchr(pcUser, *pcStar) != NULL) ||
00348         (strchr(pcUser, *pcQM) != NULL) )
00349    {
00350       fprintf(fLogFile,
00351          "-E- %s: generic archive name '%s' not allowed\n",
00352          cModule, pcUser);
00353       return(pcNull);
00354    }
00355 
00356    strcpy(cNamefs, "");                    /* initialize */
00357    if (iDebug)
00358       fprintf(fLogFile, "-D- %s: FS %s, in %s-%s, delim %s\n",
00359               cNamefs, pcUser, pc, pcObjDelim);
00360    if (strncmp(pc, pcObjDelim, 1) == 0)
00361       pc++;
00362    else
00363       /* strncpy(cNamefs, pcObjDelim, 1); */
00364       /* in adsmcli session: beginning with 2nd invocation,
00365          gives incorrect results due to missing \0 ! H.G. 27.10.97 */
00366       strcpy(cNamefs, pcObjDelim);
00367 
00368    if (isalpha(*pc) == 0)
00369    {
00370       fprintf(fLogFile,
00371               "-E- archive name '%s' must start with a letter\n", pc);
00372       return(pcNull);
00373    }
00374 
00375    strcat(cNamefs, pcUser);
00376    if (iDebug) fprintf(fLogFile,
00377       "-D- end %s: FS %s\n", cNamefs, cModule);
00378 
00379    return( (char *) cNamefs);
00380 
00381 } /* rawGetFSName */
00382 
00383 /**********************************************************************/
00384 /* rawGetHLName: get high level object name from path */
00385 /* */
00386 /* insert name part at beginning depending on device */
00387 /* PLATFORM DEPENDENT */
00388 /* */
00389 /* created 16. 2.96, Horst Goeringer */
00390 /* 23. 4.96., H.G: remove device dependency in hl-name, as in */
00391 /*                 ADSM 213 management class may be set in dsmSendObj */
00392 /**********************************************************************/
00393 
00394 char *rawGetHLName( char *pcPath)
00395 {
00396    int iDebug = 0;
00397    char cModule[32]="rawGetHLName";
00398    char *pdelim;
00399 
00400    if (iDebug)
00401       fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00402 
00403    pdelim = strchr(pcPath, *pcObjDelim);
00404    if (pdelim != pcPath)
00405    {
00406       strcpy(cNamehl, pcObjDelim);
00407       if (iDebug) fprintf(fLogFile,
00408          "    delimiter '%s' inserted at begin of archive path\n",
00409          pcObjDelim);
00410       strcat(cNamehl, pcPath);
00411    }
00412    else strcpy(cNamehl, pcPath);
00413 
00414    if (iDebug) fprintf(fLogFile,
00415       "-D- end %s: path: %s, hl: %s\n\n", cModule, pcPath, cNamehl);
00416 
00417    return(cNamehl);
00418 
00419 } /* rawGetHLName */
00420 
00421 /*********************************************************************
00422  * rawGetLLName: get low level object name from file name
00423  *    PLATFORM DEPENDENT
00424  *
00425  * created 16. 2.1996, Horst Goeringer
00426  *********************************************************************
00427  *  9. 1.2002, H.G.: pass object and delimiter as argument
00428  *********************************************************************
00429  */
00430 
00431 int rawGetLLName( char *pcFile, char *pcDelimiter,
00432                   char *pcObject)
00433 {
00434    char cModule[32] = "rawGetLLName";
00435    int iDebug = 0;
00436 
00437    char cNamell[MAX_OBJ_LL] = "";
00438    char *ploc = NULL;
00439 
00440    if (iDebug) fprintf(fLogFile,
00441       "-D- begin %s: object delim %s\n", cModule, pcDelimiter);
00442 
00443    strcpy(cNamell, pcDelimiter);
00444 
00445    ploc = strrchr(pcFile, *pcFileDelim);
00446    if (ploc != NULL)
00447       strcat(cNamell, ++ploc);   /* begin copy after file delimiter */
00448    else
00449    {
00450       ploc = strrchr(pcFile, *pcObjDelimAlt);
00451       if (ploc != NULL)
00452          strcat(cNamell, ++ploc);/* begin copy after file delimiter */
00453       else
00454       {
00455 #ifdef VMS
00456          ploc = strrchr(pcFile, *pcDevDelim); /* look for disk device */
00457          if (ploc != NULL)
00458             strcat(cNamell, ++ploc);
00459                                 /* begin copy after device delimiter */
00460          else
00461 #endif
00462          strcat(cNamell, pcFile);
00463       }
00464    }
00465    strcpy(pcObject, cNamell);
00466 
00467    if (iDebug) fprintf(fLogFile,
00468       "-D- end %s: file %s, object %s\n", cModule, pcFile, pcObject);
00469 
00470    return 0;
00471 
00472 } /* rawGetLLName */
00473 
00474 /*********************************************************************
00475  * rawGetPathName:   get path name from high level object name
00476  *
00477  * created 21. 3.1996, Horst Goeringer
00478  *********************************************************************
00479  * 23. 4.1996, H.G: no more device dependency in hl-name, as with
00480  *                  ADSM V213 management class can be set in dsmSendObj
00481  *********************************************************************
00482  */
00483 
00484 char *rawGetPathName( char *pcNamehl)
00485 {
00486    char cModule[32] = "rawGetPathName";
00487    int iDebug = 0;
00488    char *ploc = NULL, *ploc1 = NULL;
00489    char *pcc;
00490 
00491    if (iDebug)
00492       fprintf(fLogFile, "-D- begin %s: hl: %s\n", cModule, pcNamehl);
00493 
00494    if (strlen(pcNamehl) == 0)
00495    {
00496       fprintf(fLogFile,
00497             "-E- %s: high level name empty\n");
00498       return(pcNull);
00499    }
00500 
00501    pcc = pcNamehl;
00502    ploc = strchr(pcNamehl, *pcObjDelim);
00503    ploc1 = strchr(pcNamehl, *pcObjDelimAlt);
00504    if ( (ploc != pcc) && (ploc1 != pcc) )
00505    {
00506       fprintf(fLogFile,
00507             "-E- %s: invalid prefix in high level name %s\n",
00508               cModule, pcNamehl);
00509       return(pcNull);
00510    }
00511 
00512    strcpy(cPath, pcc);
00513    if (iDebug) fprintf(fLogFile,
00514       "-D- end %s: path %s\n\n", cModule, cPath);
00515 
00516    return cPath;
00517 
00518 } /* rawGetPathName */
00519 
00520 /*********************************************************************
00521  * rawQueryPrint: print query results for one object
00522  * created 19. 2.1996, Horst Goeringer
00523  *********************************************************************
00524  */
00525 
00526 void rawQueryPrint(
00527         srawObjAttr *pQAttr,
00528         int ipMode) /* =  0: default print mode,
00529                        =  1: debug print mode,
00530                        = 10: default print mode, stage status unknown
00531                        = 11: debug print mode, stage status unknown  */
00532 {
00533    char ctype[8] = "";
00534    char cMClass[12] = "";
00535    char cPath[MAX_OBJ_HL];
00536    char cStatus[16] = "";
00537    int iStage = 0;                         /* StagePool (read cache) */
00538    int iCache = 0;                      /* ArchivePool (write cache) */
00539 
00540    switch( ntohl(pQAttr->iFileType) )
00541    {
00542       case FIXED_INTS4:
00543          strcpy(ctype, "FB");
00544          break;
00545       case STREAM:
00546          strcpy(ctype, "U ");
00547          break;
00548       default:
00549          fprintf(fLogFile, "-E- Invalid record format %d found\n",
00550                  ntohl(pQAttr->iFileType));
00551          break;
00552    }
00553 
00554    switch( ntohl(pQAttr->iMediaClass) )
00555    {
00556       case MEDIA_FIXED:
00557          strcpy(cMClass, "DISK");
00558          break;
00559       case MEDIA_LIBRARY:
00560          strcpy(cMClass, "TAPE");
00561          break;
00562       case MEDIA_NETWORK:
00563          strcpy(cMClass, "NETWORK");
00564          break;
00565       case MEDIA_SHELF:
00566          strcpy(cMClass, "SHELF");
00567          break;
00568       case MEDIA_OFFSITE:
00569          strcpy(cMClass, "OFFSITE");
00570          break;
00571       case MEDIA_UNAVAILABLE:
00572          strcpy(cMClass, "UNAVAILABLE");
00573          break;
00574       case GSI_MEDIA_STAGE:
00575       case GSI_MEDIA_LOCKED:
00576          strcpy(cMClass, "STAGE");
00577          strcpy(cStatus, "staged");
00578          iStage = 1;
00579          break;
00580       case GSI_MEDIA_INCOMPLETE:             /* keep TSM media class */
00581          strcpy(cMClass, "TAPE");
00582          break;
00583       case GSI_MEDIA_CACHE:                       /* GSI write cache */
00584          strcpy(cMClass, "CACHE");
00585          strcpy(cStatus, "cached");
00586          iCache = 1;
00587          break;
00588       default:
00589          fprintf(fLogFile, "-E- Invalid media class %d found\n",
00590                  ntohl(pQAttr->iMediaClass));
00591          break;
00592    }
00593 
00594    if ( (ipMode == 10) || (ipMode == 11) )
00595       strcat(cMClass, "??");             /* stage status not checked */
00596 
00597    if (iCache)
00598       strcat(pQAttr->cDate, " ");
00599    strcpy(cPath, rawGetPathName(pQAttr->cNamehl));
00600    fprintf(fLogFile, "%s%s%s  %s  %s %s %d  %s",
00601            pQAttr->cNamefs,
00602            cPath,
00603            pQAttr->cNamell,
00604            pQAttr->cOwner,
00605            pQAttr->cDate,
00606            ctype,
00607            ntohl(pQAttr->iBufsizeFile),
00608            cMClass);
00609    if (ntohl(pQAttr->iFileSize))
00610       fprintf(fLogFile, "  %d", ntohl(pQAttr->iFileSize) );
00611    if (iStage)
00612       fprintf(fLogFile, "  %s  %s", pQAttr->cNode, pQAttr->cStageUser);
00613    if (iCache)
00614       fprintf(fLogFile, "  %s", pQAttr->cNode);
00615    fprintf(fLogFile, "\n");
00616 
00617    if ( (ipMode == 1) || (ipMode == 11) )
00618    {
00619       if (ntohl(pQAttr->iFS))
00620          fprintf(fLogFile, "    %s on data mover %s, FS %d\n",
00621                  cStatus, pQAttr->cNode, ntohl(pQAttr->iFS));
00622       fprintf(fLogFile, "    obj-Id: %lu-%lu, restore order: %lu-%lu\n",
00623               ntohl(pQAttr->iObjHigh),
00624               ntohl(pQAttr->iObjLow),
00625               ntohl(pQAttr->iRestoHigh),
00626               ntohl(pQAttr->iRestoLow) );
00627       fprintf(fLogFile,
00628               "    version %d, owner: %s, OS: %.8s, mgmt-class: %s\n",
00629               ntohl(pQAttr->iVersion),
00630               pQAttr->cOwner,
00631               pQAttr->cOS,
00632               pQAttr->cMgmtClass);
00633    }
00634 
00635 } /* rawQueryPrint */
00636 
00637 /*********************************************************************/
00638 /* rawQueryString: print query results for one object to string */
00639 /* created 19. 2.96, Horst Goeringer */
00640 /*********************************************************************/
00641 
00642 int rawQueryString(
00643         srawObjAttr *pQAttr,
00644         int ipMode, /* =  0: default print mode,
00645                        =  1: debug print mode,
00646                        = 10: default print mode, stage status unknown
00647                        = 11: debug print mode, stage status unknown  */
00648         char *pcOut)
00649 {
00650    int iDebug = 0;
00651    char cModule[32] = "rawQueryString";
00652 
00653    int iOut = 0;
00654    int iMsg = 0;
00655    char ctype[8] = "";
00656    char cMClass[12] = "";
00657    char cPath[MAX_OBJ_HL];
00658    char cMsg[512] = "";
00659    char cMsg1[512] = "";
00660 
00661    int iStage = 0;                         /* StagePool (read cache) */
00662    int iCache = 0;                      /* ArchivePool (write cache) */
00663    switch( ntohl(pQAttr->iFileType) )
00664    {
00665       case FIXED_INTS4:
00666          strcpy(ctype, "FB");
00667          break;
00668       case STREAM:
00669          strcpy(ctype, "U ");
00670          break;
00671       default:
00672          fprintf(fLogFile, "-E- Invalid record format %d found\n",
00673                  ntohl(pQAttr->iFileType));
00674          break;
00675    }
00676 
00677    switch( ntohl(pQAttr->iMediaClass) )
00678    {
00679       case MEDIA_FIXED:
00680          strcpy(cMClass, "DISK");
00681          break;
00682       case MEDIA_LIBRARY:
00683          strcpy(cMClass, "TAPE");
00684          break;
00685       case MEDIA_NETWORK:
00686          strcpy(cMClass, "NETWORK");
00687          break;
00688       case MEDIA_SHELF:
00689          strcpy(cMClass, "SHELF");
00690          break;
00691       case MEDIA_OFFSITE:
00692          strcpy(cMClass, "OFFSITE");
00693          break;
00694       case MEDIA_UNAVAILABLE:
00695          strcpy(cMClass, "UNAVAILABLE");
00696          break;
00697       case GSI_MEDIA_STAGE:
00698       case GSI_MEDIA_LOCKED:
00699          strcpy(cMClass, "STAGE");
00700          iStage = 1;
00701          break;
00702       case GSI_MEDIA_INCOMPLETE:             /* keep TSM media class */
00703          strcpy(cMClass, "TAPE");
00704          break;
00705       case GSI_MEDIA_CACHE:                       /* GSI write cache */
00706          strcpy(cMClass, "CACHE");
00707          iCache = 1;
00708          break;
00709       default:
00710          fprintf(fLogFile, "-E- Invalid media class %d found\n",
00711                  ntohl(pQAttr->iMediaClass));
00712          break;
00713    }
00714 
00715    if ( (ipMode == 10) || (ipMode == 11) )
00716       strcat(cMClass, "??");             /* stage status not checked */
00717 
00718    strcpy(cPath, rawGetPathName(pQAttr->cNamehl));
00719    sprintf(cMsg, "%s%s%s  %s  %s %s %d  %s",
00720                   pQAttr->cNamefs,
00721                   cPath,
00722                   pQAttr->cNamell,
00723                   pQAttr->cOwner,
00724                   pQAttr->cDate,
00725                   ctype,
00726                   ntohl(pQAttr->iBufsizeFile),
00727                   cMClass);
00728 
00729    if (ntohl(pQAttr->iFileSize))
00730    {
00731       sprintf(cMsg1, "  %d", ntohl(pQAttr->iFileSize) );
00732       strcat(cMsg, cMsg1);
00733    }
00734    if (iStage)
00735    {
00736       sprintf(cMsg1, "  %s  %s", pQAttr->cNode, pQAttr->cStageUser);
00737       strcat(cMsg, cMsg1);
00738    }
00739    if (iCache)
00740    {
00741       sprintf(cMsg1, "  %s", pQAttr->cNode);
00742       strcat(cMsg, cMsg1);
00743    }
00744    strcat(cMsg, "\n");
00745 
00746    if ( (ipMode == 1) || (ipMode == 11) )
00747    {
00748       if (ntohl(pQAttr->iFS))
00749          fprintf(fLogFile, "    staged on data mover %s, FS %d\n",
00750                  pQAttr->cNode, ntohl(pQAttr->iFS));
00751       sprintf(cMsg1, "    obj-Id: %lu-%lu, restore order: %lu-%lu\n",
00752                   ntohl(pQAttr->iObjHigh),
00753                   ntohl(pQAttr->iObjLow),
00754                   ntohl(pQAttr->iRestoHigh),
00755                   ntohl(pQAttr->iRestoLow) );
00756       strcat(cMsg, cMsg1);
00757       sprintf(cMsg1, "    version %d, owner: %s, OS: %s, mgmt-class: %s\n",
00758                   ntohl(pQAttr->iVersion),
00759                   pQAttr->cOwner,
00760                   pQAttr->cOS,
00761                   pQAttr->cMgmtClass);
00762       strcat(cMsg, cMsg1);
00763    }
00764 
00765    iOut = strlen(pcOut);
00766    iMsg = strlen(cMsg);
00767    if (iDebug) fprintf(fLogFile,
00768       "-D- %s: message length %d byte, returned %d byte\n",
00769       cModule, iMsg, iOut);
00770 
00771    if (iOut < iMsg)
00772    {
00773       fprintf(fLogFile,
00774          "-W- %s: query information incomplete\n", cModule);
00775       fprintf(fLogFile,
00776          "    %s: output string provided too short (%d byte), need %d\n",
00777         cModule, iOut, iMsg);
00778       strncpy(pcOut, cMsg, iOut);
00779       return iOut;
00780    }
00781 
00782    strcpy(pcOut, cMsg);
00783    return iMsg;
00784 
00785 } /* rawQueryString */
00786 
00787 /*********************************************************************/
00788 /* rawRecvError:   receive error message */
00789 /*    returns length of error message */
00790 /* */
00791 /* created 14. 3.96, Horst Goeringer */
00792 /*********************************************************************/
00793 
00794 int rawRecvError( int iSocket, int iLen, char **pMsg)
00795 {
00796    int iDebug = 0;
00797    char cModule[32]="rawRecvError";
00798    int iRC;
00799    int iBuf, iBufs;
00800    char *pcMsg;
00801 
00802    if (iDebug)
00803       fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00804 
00805    pcMsg = *pMsg;       /* points now to buffer in calling procedure */
00806    iBuf = iLen;                           /* length of error message */
00807    iBufs = iBuf;
00808    while(iBuf > 0)
00809    {
00810       if ( (iRC = recv( iSocket, pcMsg, iBuf, 0 )) < 0 )
00811       {
00812          perror("-E- rawRecvError: receiving error message");
00813          return -1;
00814       }
00815       iBuf -= iRC;
00816       pcMsg += iRC;
00817 
00818    } /* while(iBuf > 0) */
00819 
00820    if (iBuf < 0)
00821    {
00822       fprintf(fLogFile,
00823          "-E- %s: more error data received than expected\n", cModule);
00824       return -2;
00825    }
00826 
00827    *pcMsg = '\0';                          /* delimit message string */
00828 
00829    if (iDebug) fprintf(fLogFile,
00830       "    end %s: error message received (%d bytes)\n    %s\n",
00831       cModule, iBufs, *pMsg);
00832 
00833    return iBufs;
00834 
00835 } /* rawRecvError */
00836 
00837 /*********************************************************************
00838  * rawRecvHead: receive common buffer header
00839  *    returns no. of bytes received or error (< 0)
00840  *
00841  * created  5. 3.96, Horst Goeringer
00842  *********************************************************************
00843  */
00844 
00845 int rawRecvHead( int iSocket, char **pBuf)
00846 {
00847    int iDebug = 0;
00848    char cModule[32]="rawRecvHead";
00849 
00850    int iBuf, iBufs;
00851    int iRC;
00852    int iIdent;
00853    int iStatus;
00854    int iDataLen;
00855    char *pcc;
00856    int *pint;
00857 
00858    if (iDebug)
00859       fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00860 
00861    pcc = *pBuf;        /* points now to buffer in calling procedure */
00862    pint = (int *) pcc;
00863    iBuf = HEAD_LEN;
00864    iBufs = iBuf;
00865    while(iBuf > 0)
00866    {
00867       iRC = recv( iSocket, pcc, iBuf, 0 );
00868       if (iRC <= 0)
00869       {
00870          if (iRC < 0)
00871          {
00872             fprintf(fLogFile, "-E- %s: rc(recv) = %d\n", cModule, iRC);
00873             perror("-E- rawRecvHead: receiving buffer header");
00874          }
00875          else
00876             fprintf(fLogFile, "-E- %s: connection to client broken\n",
00877                    cModule);
00878 
00879          return -1;
00880       }
00881       iBuf -= iRC;
00882       pcc += iRC;
00883 
00884    } /* while(iBuf > 0) */
00885 
00886    iIdent = ntohl(*pint);
00887    pint++;
00888    iStatus = ntohl(*pint);
00889    pint++;
00890    iDataLen = ntohl(*pint);
00891    if (iDebug) fprintf(fLogFile,
00892       "    ident %d, status %d, datalen %d\n",
00893       iIdent, iStatus, iDataLen);
00894 
00895    if ( (iIdent == IDENT_STATUS) &&
00896         ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF)) &&
00897         (iDataLen > 0) )
00898    {
00899       if (iDebug) fprintf(fLogFile,
00900          "-W- %s: error message available for receive (%d byte)\n",
00901          cModule, iDataLen);
00902       return iDataLen;
00903    }
00904 
00905    if (iDebug) fprintf(fLogFile,
00906       "-D- end %s: buffer header received (%d bytes)\n\n",
00907       cModule, iBufs);
00908 
00909    return iBufs;
00910 
00911 } /* rawRecvHead */
00912 
00913 /*********************************************************************
00914  * rawRecvHeadC: receive common buffer header and check
00915  *    return values:
00916  *           >= 0: no error occurred:
00917  *     = HEAD_LEN: header received (and okay)
00918  *     > HEAD_LEN: status message of this size in pcMsg
00919  *           =  0: error status received, but no message
00920  *
00921  *           <  0: error occurred:
00922  *           = -1: recv failed
00923  *           = -2: connection to sender lost
00924  *           = -3: receiving error msg failed
00925  *           = -4: unexpected identifier received
00926  *           = -5: unexpected status received
00927  *
00928  * created  7. 3.2002, Horst Goeringer
00929  *********************************************************************
00930  */
00931 
00932 int rawRecvHeadC(int iSocket,
00933                  char *pBuf,
00934                  int iIdentReq,     /* < 0 => check, = 0 => no check */
00935                  int iStatusReq,   /* >= 0 => check, < 0 => no check */
00936                  char *pcMsg)
00937 {
00938    int iDebug = 0;
00939    char cModule[32] = "rawRecvHeadC";
00940 
00941    /* header to be received */
00942    int iIdent;
00943    int iStatus;
00944    int iDataLen;
00945 
00946    char cMsg[256] = "";          /* for error message to be received */
00947 
00948    int iRC;
00949    int iBuf, iBufs;
00950    char *pcc;
00951    int *pint;
00952 
00953    if (iDebug)
00954       fprintf(fLogFile, "\n-D- begin %s\n", cModule);
00955 
00956    pcc = pBuf;          /* points now to buffer in calling procedure */
00957    iBuf = HEAD_LEN;
00958    iBufs = iBuf;
00959    while(iBuf > 0)
00960    {
00961       if ( (iRC = recv( iSocket, pcc, iBuf, 0 )) <= 0 )
00962       {
00963          if (iRC < 0)
00964          {
00965             perror("-E- rawRecvHeadC: receiving buffer header");
00966             sprintf(pcMsg, "-E- %s: receiving buffer header\n",
00967                     cModule);
00968             return -1;
00969          }
00970          else
00971          {
00972             sprintf(pcMsg, "-E- %s: connection to sender lost\n",
00973                     cModule);
00974             return -2;
00975          }
00976       }
00977       iBuf -= iRC;
00978       pcc += iRC;
00979 
00980    } /* while(iBuf > 0) */
00981 
00982    if (iDebug) fprintf(fLogFile,
00983       "    buffer header received (%d bytes)\n", iBufs);
00984 
00985    pint = (int *) pBuf;
00986    iIdent = ntohl(*pint);
00987    pint++;
00988    iStatus = ntohl(*pint);
00989    pint++;
00990    iDataLen = ntohl(*pint);
00991    if (iDebug) fprintf(fLogFile,
00992       "    ident %d, status %d, datalen %d\n",
00993       iIdent, iStatus, iDataLen);
00994 
00995    if (iIdent == IDENT_STATUS)
00996    {
00997       if (iDebug)
00998          fprintf(fLogFile, "    status received\n");
00999 
01000       if ( (iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF) )
01001       {
01002          if (iDebug)
01003             fprintf(fLogFile, "    error received\n");
01004          /* sprintf(pcMsg, "-E- %s: received error status:\n",
01005                  cModule); */
01006 
01007          if (iDataLen)
01008          {
01009             pcc = cMsg;
01010             iRC = rawRecvError(iSocket, iDataLen, &pcc);
01011             if (iRC < 0)
01012             {
01013                sprintf(pcMsg, "-E- %s: receiving error msg, rc=%d\n",
01014                        cModule, iRC);
01015                return -3;
01016             }
01017 
01018             if (iDebug) fprintf(fLogFile,
01019                "    msg (%d byte): %s\n", iDataLen, pcc);
01020             strcat(pcMsg, pcc);
01021             return strlen(pcMsg);
01022          }
01023          else
01024          {
01025             strcat(pcMsg,
01026                "-W- error status received, but no error message available\n");
01027             return 0;
01028          }
01029 
01030       } /* (iStatus == STA_ERROR || STA_ERROR_EOF) */
01031    } /* iIdent == IDENT_STATUS */
01032 
01033    if (iIdentReq < 0)                /* test for expected identifier */
01034    {
01035       if (iDebug)
01036          fprintf(fLogFile, "    check identifier\n");
01037 
01038       if (iIdent != iIdentReq)
01039       {
01040          sprintf(pcMsg,
01041                  "-E- %s: unexpected header (ident %d) received\n",
01042                  cModule, iIdent);
01043          return -4;
01044 
01045       } /* unexpected ident) */
01046       else
01047       {
01048          if (iStatusReq >= 0)            /* test for expected status */
01049          {
01050             if (iDebug)
01051                fprintf(fLogFile, "    check status\n");
01052 
01053             if (iStatusReq != iStatus)
01054             {
01055                sprintf(pcMsg,
01056                   "-E- %s: unexpected header (status %d) received\n",
01057                   cModule, iStatus);
01058                return -5;
01059             }
01060          }
01061       } /* expected ident */
01062    } /* check ident requested */
01063 
01064    return HEAD_LEN;
01065 
01066 } /* rawRecvHeadC */
01067 
01068 /*********************************************************************
01069  * rawRecvRequest:
01070  *    receive request for next buffer and convert to host format
01071  *    returns   0: request received
01072  *              2: EOF status received
01073  *              3: EOS status received
01074  *           4, 5: error status received
01075  *            < 0: error occured
01076  *
01077  * created 21.12.2000, Horst Goeringer
01078  *********************************************************************
01079  */
01080 
01081 int rawRecvRequest(int iSocket,
01082                    int *piSeekMode,
01083                    int *piOffset,
01084                    int *piBufferSize)
01085 {
01086    int iDebug = 0;
01087    char cModule[32]="rawRecvRequest";
01088 
01089    int iRC;
01090    int iRequSize = sizeof(srawRequest);
01091    int iBuf, iBuf0;
01092    char *pc;
01093    char cMsg[256] = "";                       /* error msg received */
01094 
01095    srawRequest sRequest, *pRequest;
01096 
01097    if (iDebug) fprintf(fLogFile,
01098       "\n-D- begin %s: receive request buffer\n", cModule);
01099 
01100    pRequest = &sRequest;
01101    pc = (char *) pRequest;
01102    iBuf = HEAD_LEN;
01103    while(iBuf > 0)
01104    {
01105       if ( (iRC = recv( iSocket, pc, iBuf, 0 )) < 0 )
01106       {
01107          perror("-E- rawRecvRequest: receiving buffer header");
01108          return -1;
01109       }
01110       iBuf -= iRC;
01111       pc += iRC;
01112    } /* while(iBuf > 0) */
01113 
01114    if (iBuf < 0)
01115    {
01116       fprintf(fLogFile,
01117          "-E- %s: more header data received than expected\n", cModule);
01118       return -2;
01119    }
01120 
01121    pRequest->iIdent = ntohl(pRequest->iIdent);
01122    if (iDebug) fprintf(fLogFile,
01123       "-D- %s: buffer header received (HEAD_LEN bytes, id %d)\n",
01124       cModule, pRequest->iIdent);
01125 
01126    if ( (pRequest->iIdent != IDENT_NEXT_BUFFER) &&
01127         (pRequest->iIdent != IDENT_STATUS) )
01128    {
01129       fprintf(fLogFile, "-E- %s: invalid buffer received (id %d)\n",
01130               cModule, pRequest->iIdent);
01131       return -3;
01132    }
01133 
01134    pRequest->iStatus = ntohl(pRequest->iStatus);
01135    pRequest->iStatusLen = ntohl(pRequest->iStatusLen);
01136    iBuf0 = pRequest->iStatusLen;
01137    iBuf = iBuf0;
01138    if (pRequest->iIdent != IDENT_NEXT_BUFFER)
01139       pc = cMsg;                               /* more space needed */
01140    while(iBuf > 0)
01141    {
01142       if ( (iRC = recv( iSocket, pc, iBuf, 0 )) < 0 )
01143       {
01144          perror("-E- rawRecvRequest: receiving buffer data");
01145          return -1;
01146       }
01147       iBuf -= iRC;
01148       pc += iRC;
01149    } /* while(iBuf > 0) */
01150 
01151    if (iBuf < 0)
01152    {
01153       fprintf(fLogFile, "-E- %s: more data received than expected\n",
01154               cModule);
01155       return -2;
01156    }
01157 
01158    if (pRequest->iIdent == IDENT_NEXT_BUFFER)
01159    {
01160       if (iDebug) fprintf(fLogFile,
01161          "    %s: request data received (%d bytes)\n", cModule, iBuf0);
01162 
01163       if (iBuf0 + HEAD_LEN != iRequSize)
01164       {
01165          fprintf(fLogFile,
01166             "-E- %s: invalid data size (%d) in request buffer (expected %d byte)\n",
01167             cModule, iBuf0, iRequSize-HEAD_LEN);
01168          return -4;
01169       }
01170 
01171       *piSeekMode = ntohl(pRequest->iSeekMode);
01172       *piOffset = ntohl(pRequest->iOffset);
01173       *piBufferSize = ntohl(pRequest->iBufferSize);
01174 
01175       return 0;
01176 
01177    } /* (pRequest->iIdent == IDENT_NEXT_BUFFER) */
01178    else if (pRequest->iIdent == IDENT_STATUS)
01179    {
01180       if ( (pRequest->iStatus == STA_END_OF_FILE) ||
01181            (pRequest->iStatus == STA_END_OF_SESSION) )
01182       {
01183          if (iDebug) fprintf(fLogFile,
01184             "    %s: status info received: end session\n", cModule);
01185       }
01186       else if ( (pRequest->iStatus == STA_ERROR) ||
01187                 (pRequest->iStatus == STA_ERROR_EOF) )
01188 
01189       {
01190          if (iDebug) fprintf(fLogFile,
01191             "-W- %s: error status received: end session\n", cModule);
01192          if (iBuf0 > 0)
01193             fprintf(fLogFile,
01194                "-W- %s: error message from client:\n    %s\n",
01195                cModule, cMsg);
01196          return -4;
01197       }
01198       else
01199       {
01200          fprintf(fLogFile,
01201             "-E- %s: invalid status buffer received (id %d)\n",
01202             cModule, pRequest->iStatus);
01203          return -3;
01204       }
01205 
01206       return pRequest->iStatus;
01207 
01208    } /* (pRequest->iIdent == IDENT_STATUS) */
01209    else
01210    {
01211       fprintf(fLogFile, "-E- %s: invalid buffer received (ident %d)\n",
01212               cModule, pRequest->iIdent);
01213       return -2;
01214    }
01215 
01216 
01217 } /* rawRecvRequest */
01218 
01219 /*********************************************************************
01220  * rawRecvStatus: receive status header
01221  *    returns no. of bytes received or error (< 0)
01222  *    status header will be converted to host format
01223  *
01224  * created 18. 3.96, Horst Goeringer
01225  *********************************************************************
01226  */
01227 
01228 int rawRecvStatus( int iSocket, char **pBuf)
01229 {
01230    int iDebug = 0;
01231    char cModule[32]="rawRecvStatus";
01232 
01233    int iRC;
01234    int iBuf, iBufs;
01235    int iLen;
01236    char *pcc;
01237    srawStatus *pStatus;
01238 
01239    pcc = *pBuf;    /* points now to buffer in calling procedure */
01240    pStatus = (srawStatus *) pcc;
01241    memset(pcc, 0x00, sizeof(HEAD_LEN));
01242    iBuf = HEAD_LEN;
01243    iBufs = iBuf;
01244 
01245    while(iBuf > 0)
01246    {
01247       if ( (iRC = recv( iSocket, pcc, iBuf, 0 )) < 0 )
01248       {
01249          fprintf(fLogFile, "-E- %s: receiving status header\n",
01250                  cModule);
01251          perror("-E- rawRecvStatus: receiving status header");
01252          return -1;
01253       }
01254       iBuf -= iRC;
01255       pcc += iRC;
01256    } /* while(iBuf > 0) */
01257 
01258    if (iBuf < 0)
01259    {
01260       fprintf(fLogFile,
01261          "-E- %s: more status header data received than expected\n",
01262          cModule);
01263       return -2;
01264    }
01265 
01266    pStatus->iIdent = ntohl(pStatus->iIdent);
01267    pStatus->iStatus = ntohl(pStatus->iStatus);
01268    pStatus->iStatusLen = ntohl(pStatus->iStatusLen);
01269    if (pStatus->iIdent != IDENT_STATUS)
01270    {
01271       fprintf(fLogFile, "-E- %s: invalid status header received (%d)\n",
01272               cModule, pStatus->iIdent);
01273       return -3;
01274    }
01275 
01276    if (iDebug) fprintf(fLogFile,
01277       "    %s: status header received (status %d, %d bytes)\n",
01278       cModule, pStatus->iStatus, iBufs);
01279 
01280    iLen = pStatus->iStatusLen;
01281    if (iLen > 0)
01282    {
01283       memset(pcc, 0x00, iLen);
01284       iBuf = iLen;                      /* length of status message */
01285       iBufs += iBuf;
01286       while(iBuf > 0)
01287       {
01288          if ( (iRC = recv( iSocket, pcc, iBuf, 0 )) < 0 )
01289          {
01290             perror("-E- rawRecvStatus: receiving status message");
01291             return -4;
01292          }
01293          iBuf -= iRC;
01294          pcc += iRC;
01295 
01296       } /* while(iBuf > 0) */
01297 
01298       if (iBuf < 0)
01299       {
01300          fprintf(fLogFile,
01301             "-E- %s: more status data received than expected\n",
01302             cModule);
01303          return -5;
01304       }
01305       if (iDebug) fprintf(fLogFile,
01306          "    %s: status message received (%d bytes)\n", cModule, iLen);
01307 
01308    } /*  iLen > 0 */
01309 
01310    return iBufs;
01311 
01312 } /* rawRecvStatus */
01313 
01314 /*********************************************************************
01315  * rawSendRequest: send request buffer
01316  *    returns 0 or error (< 0)
01317  *    status header will be converted to net format
01318  *
01319  * created 21.12.2000, Horst Goeringer
01320  *********************************************************************
01321  */
01322 
01323 int rawSendRequest(int iSocket,
01324                    int iSeekMode,
01325                    int iOffset,
01326                    int iBufferSize)
01327 {
01328    int iDebug = 0;
01329    char cModule[32]="rawSendRequest";
01330 
01331    int iBuf, iRC;
01332    char *pcc;
01333 
01334    srawRequest sRequest;
01335    int iRequSize = sizeof(srawRequest);
01336 
01337    if (iDebug) fprintf(fLogFile,
01338       "\n-D- begin %s: send request buffer\n", cModule);
01339 
01340    sRequest.iIdent = htonl(IDENT_NEXT_BUFFER);
01341    if (iSeekMode < 0)
01342       sRequest.iStatus = htonl(STA_NEXT_BUFFER);
01343    else
01344       sRequest.iStatus = htonl(STA_SEEK_BUFFER);
01345    sRequest.iStatusLen = htonl(iRequSize - HEAD_LEN);
01346 
01347    sRequest.iSeekMode = htonl(iSeekMode);
01348    sRequest.iOffset = htonl(iOffset);
01349    if (iBufferSize < 0)
01350    {
01351       fprintf(fLogFile,
01352          "-E- %s: invalid buffer size %d\n", cModule, iBufferSize);
01353       return -1;
01354    }
01355    sRequest.iBufferSize = htonl(iBufferSize);
01356 
01357    iBuf = iRequSize;
01358    pcc = (char *) &sRequest;
01359    if ( (iRC = send( iSocket, pcc, iBuf, 0 )) < 0 )
01360    {
01361       perror("-E- rawSendRequest: sending request buffer");
01362       return -1;
01363    }
01364 
01365    if (iDebug) fprintf(fLogFile,
01366       "-D- end %s: request buffer sent\n\n", cModule);
01367 
01368    return 0;
01369 
01370 } /* rawSendRequest */
01371 
01372 /*********************************************************************
01373  * rawSendStatus: send status buffer
01374  *    returns no. of bytes sent or error (< 0)
01375  *    status header will be converted to net format
01376  *
01377  * created  5. 3.96, Horst Goeringer
01378  *********************************************************************
01379  */
01380 
01381 int rawSendStatus( int iSocket, int iStatus, char *pcMsg)
01382 {
01383    int iDebug = 0;
01384    char cModule[32]="rawSendStatus";
01385 
01386    int iBuf = HEAD_LEN;
01387    int iRC, iMsgLen;
01388    char *pcc;
01389    srawStatus sStatus;
01390 
01391    if (iDebug) fprintf(fLogFile,
01392       "\n-D- begin %s: send status buffer (%d) to socket %d\n",
01393       cModule, iStatus, iSocket);
01394 
01395    sStatus.iIdent = htonl(IDENT_STATUS);
01396    sStatus.iStatus = htonl(iStatus);
01397    sStatus.iStatusLen = htonl(0);
01398 
01399    if (pcMsg == NULL)
01400       iMsgLen = 0;
01401    else
01402       iMsgLen = strlen(pcMsg);
01403    if (iMsgLen)
01404    {
01405       iBuf += iMsgLen;
01406       sStatus.iStatusLen = htonl(iMsgLen);
01407       strcpy(sStatus.cStatus, pcMsg);
01408       if (iDebug) fprintf(fLogFile,
01409          "    %s: error message (%d bytes):\n    %s\n",
01410          cModule, iMsgLen, pcMsg);
01411    }
01412 
01413    pcc = (char *) &sStatus;
01414    if ( (iRC = send( iSocket, pcc, iBuf, 0 )) < 0 )
01415    {
01416       perror("-E- rawSendStatus: sending status buffer");
01417       return -1;
01418    }
01419 
01420    if (iDebug) fprintf(fLogFile,
01421       "-D- end %s: status buffer sent (%d byte)\n\n", cModule, iBuf);
01422 
01423    return(iBuf);
01424 
01425 } /* rawSendStatus */
01426 
01427 /*********************************************************************
01428  * rawTestFileName: verify that specified name is a valid file name
01429  * created 15.3.1996, Horst Goeringer
01430  *********************************************************************
01431  */
01432 
01433 int rawTestFileName( char *pcFile)
01434 {
01435    char cModule[32] = "rawTestFileName";
01436    int iDebug = 0;
01437    int iRC;
01438    int ilen;
01439    int iError = 0;
01440    unsigned long iFileSize, iSize;     /* dummies for rawGetFileSize */
01441 
01442    char cFile0[MAX_FILE] = "";
01443    char *pdir;
01444 
01445    if (iDebug) fprintf(fLogFile,
01446       "-D- begin %s: input file name %s\n", cModule, pcFile);
01447 
01448    if ( (pdir = strrchr(pcFile, '/')) == NULL)
01449    {
01450       if (iDebug)
01451          fprintf(fLogFile, "    name %s okay\n", pcFile);
01452    }
01453    else       /* name contains '/' */
01454    {
01455       ilen = strlen(pdir);
01456       if (iDebug) fprintf(fLogFile,
01457          "    trailor %s (len %d)\n", pdir, ilen);
01458       if (ilen == 1)
01459       {
01460          strncpy(pdir, "\0", 1);
01461          if (iDebug)
01462             fprintf(fLogFile, "    %s is a directory\n", pcFile);
01463          iError = 2;
01464          goto gErrorTest;
01465       }
01466       else if (iDebug)
01467          fprintf(fLogFile, "    rel name %s okay\n", pcFile);
01468    }
01469 
01470    iRC = rawGetFileSize(pcFile, &iFileSize, (unsigned long *) &iSize);
01471    if (iDebug) printf(
01472       "    after rawGetFileSize, rc = %d\n", iRC);
01473 
01474    if (iRC)
01475    {
01476       if (iDebug)
01477       {
01478          printf("-W- %s NOT archived", pcFile);
01479          if (iRC == 1)
01480             printf(" - is a directory\n");
01481          else if (iRC == 2)
01482             printf(" - is a symbolic link\n");
01483          else if (iRC == 3)
01484             printf(" - is not a regular file\n");
01485          else
01486             printf("\n");
01487       }
01488 
01489       iError = 2;
01490       goto gErrorTest;
01491    }
01492 
01493    if (iDebug) printf(
01494       "    %s is a regular file\n", pcFile);
01495 
01496 gErrorTest:
01497    if (iDebug)
01498       fprintf(fLogFile, "-D- end %s\n\n", cModule);
01499 
01500    return iError;
01501 
01502 } /* rawTestFileName */
01503 
01504 /********************************************************************/
01505 /* rawTestFilePath: verify that file path not generic */
01506 /*                  if tape specified get tape drive name */
01507 /*    returns 0 if file name okay */
01508 /* */
01509 /* created 15. 3.96, Horst Goeringer */
01510 /********************************************************************/
01511 
01512 int rawTestFilePath( char *pcFile0, char **pcFile, char **pcTape)
01513 {
01514 
01515    int iDebug = 0;
01516    char cModule[32]="rawTestFilePath";
01517 
01518    int iloc, irc;
01519    int imax = 0;
01520    int iDevType = 1;                     /* default: disk */
01521 
01522    bool_t bup = bFalse;
01523 
01524    char cText[12] = "", ctemp[MAX_FILE] = "";
01525    char *plocd = NULL, *plocs = NULL, *ploc = NULL;
01526    char *pdelim = NULL, *pgen = NULL;
01527    char *pcSemi = ";";
01528    char *pcc, *pBuft, *pBuff;
01529 
01530    if (iDebug) fprintf(fLogFile,
01531       "\n-D- begin %s: test file %s\n", cModule, pcFile0);
01532 
01533    /* check if device without file name specified */
01534    pBuft = *pcTape;
01535    pBuff = *pcFile;
01536    strcpy(ctemp, pcFile0);
01537    plocd = strchr(ctemp, *pcDevDelim);
01538    if (plocd != NULL)
01539    {
01540       iDevType = 2;        /* tape, if Unix; if VMS: get it later */
01541       pcc = plocd;
01542       irc = strncmp(++pcc, "\0", 1);
01543       if (irc == 0)
01544       {
01545 #ifdef VMS
01546          fprintf(fLogFile,
01547             "-E- file name must be specified explicitly\n");
01548 #else
01549          fprintf(fLogFile, "-E- file name missing in %s\n", pcFile0);
01550 #endif
01551          return(-2);
01552       }
01553    } /* (plocd != NULL) */
01554 
01555 #ifdef VMS
01556    /* eliminate version number */
01557    plocs = strchr(ctemp, *pcSemi);
01558    if (plocs)
01559    {
01560       ++plocs;
01561       irc = isalnum(*plocs);
01562       if (irc)                      /* char after semicolon alphanum. */
01563       {
01564          irc = isalpha(*plocs);
01565          if (irc == 0)              /* char after semicolon no letter */
01566             fprintf(fLogFile,
01567                "-W- version number in file specification removed\n");
01568          else
01569             fprintf(fLogFile,
01570                "-W- invalid version in file specification removed\n");
01571       }
01572       else
01573          fprintf(fLogFile,
01574             "-W- semicolon in file specification removed\n");
01575       strncpy(--plocs, "\0", 1);
01576       strcpy(pcFile0, ctemp);
01577    }
01578 
01579    iDevType = rawCheckDevice(ctemp, pcFile, pcTape);
01580    switch(iDevType)
01581    {
01582       case 0:
01583          if (iDebug) fprintf(fLogFile,
01584             "    no device name specified\n");
01585          break;
01586       case 1:
01587          if (iDebug)
01588          {
01589             if (strlen(*pcFile) == 0)
01590                fprintf(fLogFile, "   disk device %s\n", *pcTape);
01591             else
01592                fprintf(fLogFile,
01593                   "    file %s on disk %s\n", *pcFile, *pcTape);
01594          }
01595          break;
01596       case 2:
01597          if (iDebug)
01598          {
01599             if (strlen(*pcFile) == 0)
01600                fprintf(fLogFile, "   tape device %s\n", *pcTape);
01601             else
01602                fprintf(fLogFile, "    file %s on tape %s\n", *pcFile, *pcTape);
01603          }
01604          break;
01605       default:
01606          fprintf(fLogFile, "-E- invalid file name %s\n", pcFile0);
01607          return(-1);
01608 
01609    } /* switch(iDevType) */
01610 #endif /* VMS */
01611 
01612    if (iDevType == 2)               /* tape */
01613    {
01614 #ifndef VMS
01615       irc = strncmp(pcc, pcDevDelim, 1);
01616       if (irc == 0)
01617       {
01618          fprintf(fLogFile,
01619             "-E- node specification not allowed in file name: %s\n",
01620             pcFile0);
01621          return(-2);
01622       }
01623 #endif /* Unix */
01624 
01625       strncpy(plocd++, "\0", 1);    /* cut string at colon */
01626       strcpy(pBuft, ctemp);
01627 #ifdef VMS
01628       strncat(pBuft, pcDevDelim, 1); /* append colon in VMS */
01629 
01630 #else
01631       pgen = strchr(pBuft, *pcStar);
01632       if (pgen != NULL)
01633       {
01634          fprintf(fLogFile, "-E- specified device %s has generic path\n",
01635                  pBuft);
01636          fprintf(fLogFile,
01637             "    only the relative file name may be generic\n");
01638          return(-1);
01639       }
01640 #endif
01641 
01642       strcpy(pBuff, plocd);
01643       if (iDebug)
01644          fprintf(fLogFile, "    file %s on tape %s\n", pBuff, pBuft);
01645       strcpy(cText, "tape");
01646       irc = 1;
01647 
01648    } /* (iDevType == 2) */
01649    else
01650    {
01651       strcpy(pBuff, ctemp);
01652       strcpy(cText, "disk");
01653       irc = 0;
01654    }
01655 
01656    if (iDebug) fprintf(fLogFile,
01657       "    rawTestFilePath: %s file %s\n", cText, pBuff);
01658 
01659    pdelim = strrchr(pBuff, *pcFileDelim);
01660    if (pdelim != NULL)                             /* path specified */
01661    {
01662 #ifndef VMS
01663       if (iDevType == 2)                             /* file on tape */
01664       {
01665          fprintf(fLogFile,
01666             "-E- path in tape file name not allowed: %s\n", pBuff);
01667          return(-1);
01668       }
01669 #endif
01670 
01671       pgen = strchr(pBuff, *pcStar);
01672       if ( (pgen != NULL) && (pgen < pdelim) )
01673       {
01674          fprintf(fLogFile,
01675             "-E- specified %s file %s has generic path\n",
01676             cText, pBuff);
01677          fprintf(fLogFile,
01678             "    only the relative file name may be generic\n");
01679          return(-1);
01680       }
01681 
01682       pdelim++;                          /* points to rel. file name */
01683 
01684    } /* (pdelim != NULL) */
01685    else pdelim = pBuff;
01686 
01687 #ifndef VMS
01688    /* tape: convert file name from uppercase if necessary */
01689    if (iDevType == 2)
01690    {
01691       pcc = pdelim;
01692       while (*pcc != '\0')
01693       {
01694          iloc = isupper(*pcc);
01695          if (iloc != 0)
01696          {
01697             if (!bup) fprintf(fLogFile,
01698                "-W- upper case in (relative) file name not supported: %s\n",
01699                pdelim);
01700             bup = bTrue;
01701             *pcc = tolower(*pcc);            /* change to lower case */
01702          }
01703          pcc++;
01704       } /* while (*pcc != '\0') */
01705    }
01706 
01707    if (bup)
01708       fprintf(fLogFile, "    instead assumed: %s\n", pdelim);
01709 #endif
01710 
01711    if (iDebug) fprintf(fLogFile,
01712       "    rawTestFilePath: file name %s okay\n", pcFile0);
01713 
01714    return(irc);
01715 
01716 } /* rawTestFilePath */
01717 
01718 
01719 
01720 
01721 //----------------------------END OF GO4 SOURCE FILE ---------------------

Generated on Fri Nov 28 12:59:34 2008 for Go4-v3.04-1 by  doxygen 1.4.2