GSI Object Oriented Online Offline (Go4)  GO4-6.2.0
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
rawProcn.c
Go to the documentation of this file.
1 /**********************************************************************
2  * Copyright:
3  * GSI, Gesellschaft fuer Schwerionenforschung mbH
4  * Planckstr. 1
5  * D-64291 Darmstadt
6  * Germany
7  * created 14. 2.1996, Horst Goeringer
8  **********************************************************************
9  * rawProcn.c
10  * utility programs for gStore package: client and server
11  **********************************************************************
12  * rawAddStrings: add 2 messages avoiding overflows
13  * rawCheckClientFile: check gStore naming conventions for client file
14  * rawGetFSpName: get file space name from user specification
15  * rawGetHLName: get high level object name from path
16  * rawGetLLName: get low level object name from file name
17  * rawGetFileSize: get file size (byte) via Posix call stat
18  * rawGetPathName: get path name from high level object name
19  * rawQueryFile: get query information for single file
20  * rawRecvError: receive error message
21  * rawRecvHead: receive common buffer header
22  * rawRecvHeadC: receive common buffer header and check
23  * rawRecvRequest: receive request for next buffer
24  * rawRecvStatus: receive status buffer
25  * rawSendRequest: send request for next buffer
26  * rawSendStatus: send status buffer
27  * rawTestFileName: verify that specified name is a valid file name
28  **********************************************************************
29  * 23. 4.1996., H.G: rawGetHLName: remove device dependency in hl-name,
30  * as in ADSM 213 class may be set in dsmSendObj
31  * 16. 5.1997, H.G.: keep only modules for all clients here
32  * 16. 6.1997, H.G.: ported to Linux
33  * 15.10.1997, H.G.: rawCheckAuth moved to rawCheckAuth.c
34  * 22.10.1997, H.G.: rawDelFilelist added
35  * 8. 7.1998, H.G.: new filetype STREAM
36  * 19.10.1998, H.G.: rawapitd.h introduced, dsmapitd.h removed
37  * 1.12.2000, H.G.: rawSendStatus: send also buffer request headers
38  * 7. 2.2001, H.G.: new function rawQueryString
39  * 21. 2.2001, H.G.: renamed file rawQueryFile.c -> rawProcQuery.c
40  * function rawQueryList added
41  * 18. 5.2001, H.G.: function rawDelFilelist -> rawcliproc.c
42  * merge into new file rawcliproc.c: rawProcQuery.c
43  * 18. 6.2001, H.G.: function rawTestFile: renamed to rawTestFileName,
44  * handle mixed case
45  * 2.11.2001, H.G.: ported to W2000
46  * 14.11.2001, H.G.: take alternate delimiter for Windows into account
47  * 9. 1.2002, H.G.: rawGetLLName: pass object and delimiter as argument
48  * 19. 2.2002, H.G.: rawGetFileSize added
49  * 20. 2.2002, H.G.: rawGetCmdParms removed (unused)
50  * 7. 3.2002, H.G.: rawQueryPrint: new type GSI_MEDIA_INCOMPLETE
51  * rawRecvHeadC added
52  * 7. 6.2002, H.G.: rawRecvHeadC: check always for error status
53  * 23. 7.2002, H.G.: replace old printf() -> fprintf(fLogFile)
54  * 5. 8.2002, H.G.: rawQueryFile: handle QUERY_RETRIEVE, QUERY_STAGE
55  * 14.10.2002, H.G.: ported to Lynx
56  * 31. 1.2003, H.G.: use rawdefn.h
57  * 17. 2.2003, H.G.: rawCheckFilelist, rawCheckObjlist -> rawcliprocn.c
58  * 3. 6.2003, H.G.: renamed from rawprocn to rawProcn
59  * 9. 7.2003, H.G.: rawTestFileName: call rawGetFileSize to identify
60  * directories
61  * 13. 8.2003, H.G.: rawQueryPrint: add user who staged file in output
62  * 5.12.2003, H.G.: rawRecvStatus: convert status header to host format
63  * 28. 1.2004, H.G.: GSI_MEDIA_CACHE: rawQueryPrint, rawQueryString
64  * GSI_MEDIA_INCOMPLETE: in rawQueryString
65  * 26. 5.2004, H.G.: rawQueryPrint, rawQueryString: new print modes:
66  * stage status not checked
67  * 29. 6.2004, H.G.: rawRecvHeadC: recv error msg, if write cache full
68  * 24.11.2004, H.G.: rawQueryFile: handle status values
69  * STA_NO_ACCESS, STA_ARCHIVE_NOT_AVAIL
70  * 25. 1.2005, H.G.: use rawapitd-gsin.h, new media names:
71  * GSI_..._LOCKED, GSI_..._INCOMPLETE
72  * 1. 2.2005, H.G.: ported to Linux and gcc322
73  * 25.11.2005, H.G.: rename rawGetFSName to rawGetFSpName (file space),
74  * rawGetFSName in rawProcPooln (get file system name)
75  * 3. 4.2006, H.G.: ported to sarge
76  * 29. 9.2006, H.G.: rawQueryPrint: handle ATL server
77  * 4.10.2006, H.G.: rawQueryPrint: handle cacheDB entry V4
78  * 2.11.2006, H.G.: rawQueryString: handle ATL server, cacheDB entry V4
79  * 8.12.2006, H.G.: rawQueryFile: handle query on several ATL Servers
80  * 8. 5.2008, H.G.: rawGetFullFile: move -> rawCliProcn.c
81  * rawQueryFile: moved from rawCliProcn.c, repl printf
82  * rawQueryList: moved from rawCliProcn.c, repl printf
83  * 16. 5.2008, H.G.: rawGetHLName: remove './' and trailing '/.' in path
84  * 28. 8.2008, H.G.: rawQueryPrint, rawQueryString:
85  * remove ATL server no. in query output
86  * 6.10.2008, H.G.: replace perror by strerr(errno), improve msgs
87  * rawRecvRequest: better handling rc=0 from recv()
88  * 30.10.2008, H.G.: rawQueryFile,rawQueryList: better: rc=0 from recv()
89  * 5.11.2008, H.G.: rawRecvError: better handling rc=0 from recv()
90  * arg 3: char ** -> char *
91  * rawRecvHead: better handling rc=0 from recv()
92  * arg 3: char ** -> char *
93  * rawRecvStatus: better handling rc=0 from recv()
94  * arg 3: char ** -> char *
95  * 11.11.2008, H.G.: add suggestions of Hakan
96  * 3.12.2008, H.G.: add suggestions of Hakan, part II
97  * 12.12.2008, H.G.: handle CUR_QUERY_LIMIT
98  * 4. 5.2009, H.G.: rawRecvHeadC: improve debug output
99  * 7. 5.2009, H.G.: new entry rawAddStrings
100  * 22. 6.2008, H.G.: replace long->int if 64bit client (ifdef SYSTEM64)
101  * 8. 7.2008, H.G.: rawQueryPrint/String: print filesize with %10d
102  * 23.11.2009, H.G.: rawTestFileName: inhibit '*', '?' as file name part
103  * 10.12.2009, H.G.: rawQueryFile, rawQueryPrint, rawQueryString:
104  * handle enhanced structure srawObjAttr
105  * old version info also available in new structure
106  * rawQueryList not upgraded, obviously unused???
107  * 29. 1.2010, H.G.: replace MAX_FILE -> MAX_FULL_FILE in:
108  * static string cPath,
109  * rawTestFilePath: cTemp
110  * enhance cMsg: 256 -> STATUS_LEN in:
111  * rawRecvHeadC, rawRecvRequest
112  * 5. 2.2010, H.G.: move rawQueryPrint,rawQueryString -> rawCliProcn.c
113  * move rawQueryList -> Unused.c
114  * 11. 2.2010, H.G.: rename rawTestFilePath -> rawCheckClientFile
115  * rawCheckClientFile: all checks of local file name
116  * concerning gStore conventions are done here
117  * 3. 5.2010, H.G.: rawGetFileSize: specific error msg if filesize>2GB
118  * 23. 8.2010, H.G.: rawGetFileSize, rawTestFileName:
119  * remove SYSTEM64, allow "long"
120  * 5.11.2010, H.G.: reset errno after error,
121  * better error handling after recv/send
122  * 18.11.2010, H.G.: rawRecvError: provide also incomplete msg
123  **********************************************************************
124  */
125 
126 /* file deepcode ignore BufferOverflow: <comment the reason here> */
127 
128 #include <stdio.h>
129 #include <string.h>
130 #include <errno.h>
131 
132 #ifdef WIN32 /* Windows */
133 #include <sys\types.h>
134 #include <winsock.h>
135 #include <windows.h>
136 #include <process.h>
137 #include <sys\stat.h>
138 #else /* all Unix */
139 #include <sys/stat.h>
140 #include <ctype.h>
141 #include <stdlib.h>
142 #include <unistd.h>
143 #include <netinet/in.h>
144 
145 #ifdef Lynx /* Lynx */
146 #include <sys/types.h>
147 #include <socket.h>
148 #elif Linux /* Linux */
149 #include <sys/socket.h>
150 #else /* AIX */
151 #include <sys/socket.h>
152 #endif
153 
154 #endif /* all Unix */
155 
156 #include "rawapitd.h"
157 #include "rawapitd-gsin.h"
158 #include "rawcommn.h"
159 #include "rawdefn.h"
160 #include "rawentn.h"
161 #include "rawapplcli.h"
162 
163 extern FILE *fLogFile;
164 
165 static char cPath[MAX_FULL_FILE] = "";
166 static char cNamefs[MAX_OBJ_FS] = "";
167 static char cNamehl[MAX_OBJ_HL] = "";
168 static char *pcNull = (char *) "";/* to be returned in case of error */
169  /* return(NULL) works in AIX, but not in VMS */
170 
171 static int iObjAttr = sizeof(srawObjAttr);
172 
173 /*********************************************************************
174  * rawAddStrings
175  * add 2 messages avoiding string overflows
176  * created 7.5.2009, Horst Goeringer
177  *********************************************************************
178  */
179 
180 int rawAddStrings(char *pcMsg1, /* 1st string, always complete */
181  int iMaxLength1, /* max length of string1 */
182  char *pcMsg2, /* added string, possibly cut */
183  int iMaxLength2, /* max length of string2 */
184  int iErrno, /* = 0: add contents of string2
185  > 0: add system error msg (errno) */
186  char *pcMsgE, /* error msg in case of problem */
187  int iMaxLengthE) /* max length of error string */
188 {
189  char cModule[32]="rawAddStrings";
190  int iDebug = 0;
191 
192  int iRC = 0; /* = 0: okay
193  < 0: problem:
194  =-1: specified string too large
195  =-2: string without contents provided
196  =-3: max length <=0 provided
197  =-4: iErrno, but string2 < STATUS_LEN byte
198  =-5: error string < STATUS_LEN byte provided
199  > 0: no. of chars cut from the 2nd string */
200  int iString1 = 0;
201  int iString2 = 0;
202  int iStringE = 0;
203  int iString = 0; /* sum of string1 + string2 */
204  int iMinLen = STATUS_LEN; /* for pcMsgE, if needed */
205  char cMsg[STATUS_LEN] = ""; /* internal copy */
206  char *pcc;
207 
208  iString1 = strlen(pcMsg1);
209  iString2 = strlen(pcMsg2);
210  iString = iString1 + iString2;
211 
212  if (iDebug)
213  {
214  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
215  fprintf(fLogFile, " string1 (%d byte, max %d byte):\n %s",
216  iString1, iMaxLength1, pcMsg1);
217  if (iErrno)
218  fprintf(fLogFile, " add msg for errno=%d\n", errno);
219  else
220  fprintf(fLogFile, " add string2 (%d byte, max %d byte):\n %s",
221  iString2, iMaxLength2, pcMsg2);
222  }
223 
224  if ( (iString1 <= iMaxLength1) &&
225  (iString2 <= iMaxLength2) )
226  {
227  if (iErrno)
228  {
229  if (iMaxLength2 >= iMinLen)
230  {
231  sprintf(pcMsg2, " %s\n", strerror(errno));
232  iString2 = strlen(pcMsg2);
233  iString = iString1 + iString2;
234  }
235  else
236  {
237  iRC = -4;
238  sprintf(cMsg,
239  "-E- %s: 2nd string (%d byte) possibly too small for system error: requ. %d byte\n",
240  cModule, iMaxLength2, iMinLen);
241 
242  goto gErrorMsg;
243  }
244  } /* (iErrno) */
245 
246  if (iString < iMaxLength1)
247  {
248  strcat(pcMsg1, pcMsg2);
249  if (iDebug) fprintf(fLogFile,
250  " returned msg (%d byte):\n %s", iString, pcMsg1);
251  }
252  else
253  {
254  strncat(pcMsg1, pcMsg2, iMaxLength1-iString1-1);
255  strcat(pcMsg1, "\n");
256  iRC = iString -iMaxLength1;
257  if (iDebug)
258  {
259  fprintf(fLogFile, " returned msg:\n %s", pcMsg1);
260  pcc = pcMsg2;
261  pcc+= iMaxLength1-iString1-1;
262  fprintf(fLogFile, " skipped msg part:\n %s", pcc);
263  }
264  }
265  }
266  else
267  {
268  if (iMaxLength1 <= 0)
269  {
270  iRC = -3;
271  sprintf(cMsg, "-E- %s: 1st string length (%d byte) invalid\n",
272  cModule, iMaxLength1);
273  }
274  if (iMaxLength2 <= 0)
275  {
276  iRC = -3;
277  sprintf(cMsg, "-E- %s: 2nd string length (%d byte) invalid\n",
278  cModule, iMaxLength2);
279  }
280  else if (iString == 0)
281  {
282  iRC = -2;
283  sprintf(cMsg, "-E- %s: empty strings provided\n", cModule);
284  }
285  else if (iString1 > iMaxLength1)
286  {
287  iRC = -1;
288  sprintf(cMsg, "-E- %s: 1st string longer (%d byte) than length provided (%d)\n",
289  cModule, iString1, iMaxLength1);
290  }
291  else if ( (iString2 > iMaxLength2) && (iErrno == 0) )
292  {
293  iRC = -1;
294  sprintf(cMsg, "-E- %s: 2nd string longer (%d byte) than length provided (%d)\n",
295  cModule, iString2, iMaxLength2);
296  }
297  }
298 
299  if (iRC >= 0)
300  {
301  strcpy(pcMsgE, "");
302  goto gEndAddStrings;
303  }
304 
305 gErrorMsg:
306  iStringE = strlen(cMsg);
307  if (iDebug) fprintf(fLogFile,
308  " error string (%d byte, max %d byte):\n %s\n",
309  iStringE, iMaxLengthE, cMsg);
310 
311  if (iMaxLengthE < iStringE)
312  {
313  iRC = -5;
314  fprintf(fLogFile, "-E- %s: size error string too small: max %d byte (needed %d)",
315  cModule, iMaxLengthE, iStringE);
316  strncat(pcMsgE, cMsg, iMaxLengthE);
317  fprintf(fLogFile, ", provided: %s\n", pcMsgE);
318  }
319  else
320  {
321  if (iDebug) fprintf(fLogFile, "%s", cMsg);
322  strcpy(pcMsgE, cMsg);
323  }
324 
325 gEndAddStrings:
326  if (iDebug)
327  fprintf(fLogFile, "-D- end %s: rc=%d\n\n", cModule, iRC);
328 
329  return iRC;
330 
331 } /* rawAddStrings */
332 
333 /********************************************************************
334  * rawCheckClientFile:
335  * check client file name for gStore naming conventions
336  * verify that file path not generic
337  * if tape specified get tape drive name
338  * returns 0 if valid disk file name
339  * returns >0 if valid tape file name
340  *
341  * created 15. 3.96, Horst Goeringer
342  ********************************************************************
343  */
344 
345 int rawCheckClientFile( char *pcFile0, char **pcFile, char **pcTape)
346 {
347 
348  char cModule[32]="rawCheckClientFile";
349  int iDebug = 0;
350 
351  int iloc, iRC, ii;
352  int iDevType = 1; /* default: disk */
353 
354  bool_t bup = bFalse;
355 
356  char cText[12] = "";
357  char cTemp[MAX_FULL_FILE] = "";
358  char *plocd = NULL, *plocs = NULL;
359  char *pdelim = NULL, *pgen = NULL;
360  const char *pcSemi = ";";
361  char *pcc = NULL, *pBufTape, *pBufFile;
362 
363  if (iDebug) fprintf(fLogFile,
364  "\n-D- begin %s: test file %s\n", cModule, pcFile0);
365 
366  pBufTape = *pcTape;
367  pBufFile = *pcFile;
368  strcpy(cTemp, pcFile0);
369 
370  /* check if device name specified */
371  plocd = strchr(cTemp, *pcDevDelim);
372  if (plocd != NULL)
373  {
374  iRC = strncmp(cTemp, "/dev", 4);
375  {
376  fprintf(fLogFile,
377  "-E- invalid file name: %s\n path names must not contain '%s'\n",
378  pcFile0, pcDevDelim);
379  return(-2);
380  }
381 
382  if (iRC)
383  pdelim = strrchr(cTemp, *pcFileDelim);
384  if ( (pdelim == NULL) || (pdelim > plocd) )
385  {
386  fprintf(fLogFile,
387  "-E- invalid disk file name: %s\n path names must not contain '%s'\n",
388  pcFile0, pcDevDelim);
389  return(-2);
390  }
391 
392  pcc = plocd;
393  pcc++;
394  if (strlen(pcc) > MAX_TAPE_FILE)
395  {
396  ii = MAX_TAPE_FILE;
397  fprintf(fLogFile,
398  "-E- invalid tape file name: %s\n name too long: max %d byte after dev name\n",
399  pcFile0, ii);
400  return(-2);
401  }
402 
403  iDevType = 2; /* tape, if Unix; if VMS: get it later */
404  iRC = strncmp(++pcc, "\0", 1);
405  if (iRC == 0)
406  {
407 #ifdef VMS
408  fprintf(fLogFile,
409  "-E- file name must be specified explicitly\n");
410 #else
411  fprintf(fLogFile, "-E- file name missing in %s\n", pcFile0);
412 #endif
413  return(-2);
414  }
415  } /* (plocd != NULL) */
416 
417 #ifdef VMS
418  /* eliminate version number */
419  plocs = strchr(cTemp, *pcSemi);
420  if (plocs)
421  {
422  ++plocs;
423  iRC = isalnum(*plocs);
424  if (iRC) /* char after semicolon alphanum. */
425  {
426  iRC = isalpha(*plocs);
427  if (iRC == 0) /* char after semicolon no letter */
428  fprintf(fLogFile,
429  "-W- version number in file specification removed\n");
430  else
431  fprintf(fLogFile,
432  "-W- invalid version in file specification removed\n");
433  }
434  else
435  fprintf(fLogFile,
436  "-W- semicolon in file specification removed\n");
437  strncpy(--plocs, "\0", 1);
438  strcpy(pcFile0, cTemp);
439  }
440 
441  iDevType = rawCheckDevice(cTemp, pcFile, pcTape);
442  switch(iDevType)
443  {
444  case 0:
445  if (iDebug) fprintf(fLogFile,
446  " no device name specified\n");
447  break;
448  case 1:
449  if (iDebug)
450  {
451  if (strlen(*pcFile) == 0)
452  fprintf(fLogFile, " disk device %s\n", *pcTape);
453  else
454  fprintf(fLogFile,
455  " file %s on disk %s\n", *pcFile, *pcTape);
456  }
457  break;
458  case 2:
459  if (iDebug)
460  {
461  if (strlen(*pcFile) == 0)
462  fprintf(fLogFile, " tape device %s\n", *pcTape);
463  else
464  fprintf(fLogFile, " file %s on tape %s\n", *pcFile, *pcTape);
465  }
466  break;
467  default:
468  fprintf(fLogFile, "-E- invalid file name %s\n", pcFile0);
469  return(-1);
470 
471  } /* switch(iDevType) */
472 #endif /* VMS */
473 
474  if (iDevType == 2) /* tape */
475  {
476 #ifndef VMS
477  /* check string after 1st device delimiter */
478  iRC = strncmp(pcc, pcDevDelim, 1);
479  if (iRC == 0)
480  {
481  fprintf(fLogFile,
482  "-E- node specification not allowed in file name: %s\n",
483  pcFile0);
484  return(-2);
485  }
486 #endif /* Unix */
487 
488  strncpy(plocd++, "\0", 1); /* cut string at colon */
489  strcpy(pBufTape, cTemp);
490 #ifdef VMS
491  strncat(pBufTape, pcDevDelim, 1); /* append colon in VMS */
492 
493 #else
494  pgen = strchr(pBufTape, *pcStar);
495  if (pgen != NULL)
496  {
497  fprintf(fLogFile,
498  "-E- specified device %s has generic path\n", pBufTape);
499  fprintf(fLogFile,
500  " only the relative file name may be generic\n");
501  return(-1);
502  }
503 #endif
504 
505  strcpy(pBufFile, plocd);
506  if (iDebug) fprintf(fLogFile,
507  " file %s on tape %s\n", pBufFile, pBufTape);
508  strcpy(cText, "tape");
509  iRC = 1;
510 
511  } /* (iDevType == 2) */
512  else
513  {
514  strcpy(pBufFile, cTemp);
515  strcpy(cText, "disk");
516  iRC = 0;
517  }
518 
519  if (iDebug) fprintf(fLogFile,
520  " %s file %s\n", cText, pBufFile);
521 
522  pdelim = strrchr(pBufFile, *pcFileDelim);
523  if (pdelim != NULL) /* path specified */
524  {
525 #ifndef VMS
526  if (iDevType == 2) /* file on tape */
527  {
528  fprintf(fLogFile,
529  "-E- path in tape file name not allowed: %s\n", pBufFile);
530  return(-1);
531  }
532 #endif
533 
534  /* disk file prefixed with path */
535  pgen = strchr(pBufFile, *pcStar);
536  if (pgen == NULL)
537  pgen = strchr(pBufFile, *pcQM);
538  if ( (pgen != NULL) && (pgen < pdelim) )
539  {
540  fprintf(fLogFile,
541  "-E- specified %s file %s has wildcard chars in path name\n",
542  cText, pBufFile);
543  fprintf(fLogFile,
544  " only the relative file name may contain wildcard chars\n");
545  return(-1);
546  }
547 
548  pdelim++; /* points to rel. file name */
549 
550  } /* (pdelim != NULL) */
551  else pdelim = pBufFile;
552 
553  ii = MAX_OBJ_LL - 2;
554  if (strlen(pdelim) > ii)
555  {
556  fprintf(fLogFile,
557  "-E- rel file name %s too long:\n has %ld chars, max allowed %d\n",
558  pdelim, (long) strlen(pdelim), ii);
559  return(-1);
560  }
561 
562 #ifndef VMS
563  /* tape: convert file name from uppercase if necessary */
564  if (iDevType == 2)
565  {
566  pcc = pdelim;
567  while (*pcc != '\0')
568  {
569  iloc = isupper(*pcc);
570  if (iloc != 0)
571  {
572  if (!bup) fprintf(fLogFile,
573  "-W- upper case in (relative) file name not supported: %s\n",
574  pdelim);
575  bup = bTrue;
576  *pcc = tolower(*pcc); /* change to lower case */
577  }
578  pcc++;
579  } /* while (*pcc != '\0') */
580  }
581 
582  if (bup)
583  fprintf(fLogFile, " instead assumed: %s\n", pdelim);
584 #endif
585 
586  if (iDebug) fprintf(fLogFile,
587  "\n end %s: file name %s okay\n", cModule, pcFile0);
588 
589  return(iRC);
590 
591 } /* rawCheckClientFile */
592 
593 /**********************************************************************
594  * rawGetFSpName
595  * get file space name from user specification
596  * created 22.3.1996, Horst Goeringer
597  **********************************************************************
598  */
599 
600 char *rawGetFSpName( char *pcUser )
601 {
602  char cModule[32]="rawGetFSpName";
603  int iDebug = 0;
604 
605  char *pc;
606 
607  if (iDebug)
608  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
609 
610  pc = pcUser;
611  if ( (strchr(pcUser, *pcStar) != NULL) ||
612  (strchr(pcUser, *pcQM) != NULL) )
613  {
614  fprintf(fLogFile,
615  "-E- %s: generic archive name '%s' not allowed\n",
616  cModule, pcUser);
617  return(pcNull);
618  }
619 
620  strcpy(cNamefs, ""); /* initialize */
621  if (iDebug)
622  fprintf(fLogFile, "-D- %s: FS %s, in %s-%s, delim %s\n",
623  cModule, cNamefs, pcUser, pc, pcObjDelim);
624  if (strncmp(pc, pcObjDelim, 1) == 0)
625  pc++;
626  else
627  /* strncpy(cNamefs, pcObjDelim, 1); */
628  /* in adsmcli session: beginning with 2nd invocation,
629  gives incorrect results due to missing \0 ! H.G. 27.10.97 */
630  strcpy(cNamefs, pcObjDelim);
631 
632  if (isalpha(*pc) == 0)
633  {
634  fprintf(fLogFile,
635  "-E- archive name '%s' must start with a letter\n", pc);
636  return(pcNull);
637  }
638 
639  strcat(cNamefs, pcUser);
640  if (iDebug) fprintf(fLogFile,
641  "-D- end %s: FS %s\n", cNamefs, cModule);
642 
643  return( (char *) cNamefs);
644 
645 } /* rawGetFSpName */
646 
647 /*********************************************************************
648  * rawGetHLName: get high level object name from path
649  *
650  * insert name part at beginning depending on device
651  * PLATFORM DEPENDENT
652  *
653  * created 16. 2.96, Horst Goeringer
654  *********************************************************************
655  */
656 
657 char *rawGetHLName( char *pcPath)
658 {
659  char cModule[32]="rawGetHLName";
660  int iDebug = 0;
661 
662  char *pcc;
663  char *pdelim;
664  char cNameTemp[MAX_OBJ_HL] = "";
665  int ii = 0, ii1 = 0;
666 
667  if (iDebug) fprintf(fLogFile,
668  "\n-D- begin %s\n path specified: %s\n", cModule, pcPath);
669 
670  pdelim = strchr(pcPath, *pcObjDelim);
671  if (pdelim != pcPath)
672  {
673  strcpy(cNamehl, pcObjDelim);
674  if (iDebug) fprintf(fLogFile,
675  " delimiter '%s' inserted at begin of archive path\n",
676  pcObjDelim);
677  strcat(cNamehl, pcPath);
678  }
679  else strcpy(cNamehl, pcPath);
680 
681  pdelim = strstr(cNamehl, "/./");
682  if (pdelim != NULL)
683  {
684  strcpy(cNameTemp, cNamehl);
685  pdelim = strstr(cNameTemp, "/./");
686 
687  while (pdelim != NULL)
688  {
689  ii++;
690  strncpy(pdelim, "\0", 1);
691  strcpy(cNamehl, cNameTemp);
692  pdelim++;
693  pdelim++;
694  strcat(cNamehl, pdelim);
695 
696  strcpy(cNameTemp, cNamehl);
697  pdelim = strstr(cNameTemp, "/./");
698  }
699  if (iDebug) fprintf(fLogFile,
700  " %d unnecessary './' removed\n", ii);
701  }
702 
703  pdelim = strstr(cNamehl, "/.");
704  if (pdelim != NULL)
705  {
706  pcc= cNamehl;
707  ii = strlen(cNamehl);
708  ii1 = pdelim - pcc;
709  if (ii1 < 0)
710  ii1 = -ii1;
711  if (ii1+2 == ii)
712  {
713  strncpy(pdelim, "\0", 1);
714  if (iDebug) fprintf(fLogFile,
715  " trailing '/.' removed\n");
716  }
717  }
718 
719  if (iDebug) fprintf(fLogFile,
720  " hl name: %s\n-D- end %s\n\n", cNamehl, cModule);
721 
722  return(cNamehl);
723 
724 } /* rawGetHLName */
725 
726 /*********************************************************************
727  * rawGetLLName: get low level object name from file name
728  * PLATFORM DEPENDENT
729  *
730  * created 16. 2.1996, Horst Goeringer
731  *********************************************************************
732  * 9. 1.2002, H.G.: pass object and delimiter as argument
733  *********************************************************************
734  */
735 
736 int rawGetLLName( char *pcFile, const char *pcDelimiter,
737  char *pcObject)
738 {
739  char cModule[32] = "rawGetLLName";
740  int iDebug = 0;
741 
742  char cNamell[MAX_OBJ_LL] = "";
743  char *ploc = NULL;
744 
745  if (iDebug) fprintf(fLogFile,
746  "\n-D- begin %s\n file %s, object delimiter %s\n",
747  cModule, pcFile, pcDelimiter);
748 
749  strcpy(cNamell, pcDelimiter);
750 
751  ploc = strrchr(pcFile, *pcFileDelim);
752  if (ploc != NULL)
753  strcat(cNamell, ++ploc); /* begin copy after file delimiter */
754  else
755  {
756  ploc = strrchr(pcFile, *pcObjDelimAlt);
757  if (ploc != NULL)
758  strcat(cNamell, ++ploc);/* begin copy after file delimiter */
759  else
760  {
761 #ifdef VMS
762  ploc = strrchr(pcFile, *pcDevDelim); /* look for disk device */
763  if (ploc != NULL)
764  strcat(cNamell, ++ploc);
765  /* begin copy after device delimiter */
766  else
767 #endif
768  strcat(cNamell, pcFile);
769  }
770  }
771  strcpy(pcObject, cNamell);
772 
773  if (iDebug) fprintf(fLogFile,
774  " ll name %s\n-D- end %s\n\n", pcObject, cModule);
775 
776  return 0;
777 
778 } /* rawGetLLName */
779 
780 /**********************************************************************
781  * rawGetFileSize
782  * get file size (bytes)
783  * created 19.2.2002, Horst Goeringer
784  **********************************************************************
785  */
786 
787 int rawGetFileSize(char *pcFile,
788  unsigned long *piSize,
789  unsigned int *piRecl) /* needed only for VMS */
790 {
791  char cModule[32] = "rawGetFileSize";
792  int iDebug = 0;
793 
794  int iRC;
795  int iRecl = 0;
796  unsigned long iSize = 0;
797 
798 #ifdef WIN32 /* Windows */
799  struct _stat sFileStatus, *pFileStatus;
800 #else /* Unix or VMS */
801  struct stat sFileStatus, *pFileStatus;
802 #endif
803 
804  if (iDebug) fprintf(fLogFile,
805  "\n-D- begin %s: file %s\n", cModule, pcFile);
806 
807  pFileStatus = &sFileStatus;
808 
809 #ifdef WIN32 /* Windows */
810  iRC = _stat(pcFile, pFileStatus);
811 #else /* Unix or VMS */
812  iRC = stat(pcFile, pFileStatus);
813 #endif
814  if (iRC)
815  {
816  fprintf(fLogFile,
817  "-E- %s: file %s unavailable (stat)\n", cModule, pcFile);
818  if (errno)
819  {
820  fprintf(fLogFile, " %s\n", strerror(errno));
821 
822  /* valid only for 32 bit OS */
823  if (strcmp(strerror(errno),
824  "Value too large for defined data type") == 0)
825  {
826  fprintf(fLogFile,
827  "-E- %s: file size of %s > 2 GByte: use 64 bit gStore client\n",
828  cModule, pcFile);
829 
830  errno = 0;
831  return -99;
832  }
833  errno = 0;
834  }
835 
836  return -1;
837  }
838 
839 #ifdef VMS
840  iRecl = pFileStatus->st_fab_mrs;
841 #else
842 #ifdef WIN32
843  iRecl = 0; /* not available in Windows */
844 #else
845  iRecl = pFileStatus->st_blksize;
846 #endif
847 #endif
848  iSize = pFileStatus->st_size;
849  if (pFileStatus->st_mode & S_IFREG)
850  {
851  iRC = 0;
852  if (iDebug) fprintf(fLogFile,
853  " file %s: size %lu, recl %d (byte)\n",
854  pcFile, iSize, iRecl);
855  }
856  else
857  {
858  if (pFileStatus->st_mode & S_IFDIR)
859  {
860  iRC = 1;
861  if (iDebug) fprintf(fLogFile,
862  "-W- %s is a directory, size %lu\n", pcFile, iSize);
863  }
864 #ifndef WIN32
865 #ifndef VMS
866  else if (pFileStatus->st_mode & S_IFLNK)
867  {
868  iRC = 2;
869  if (iDebug) fprintf(fLogFile,
870  "-W- %s is a symbolic link, size %lu\n", pcFile, iSize);
871  }
872 #endif
873 #endif
874  else
875  {
876  iRC = 3;
877  if (iDebug) fprintf(fLogFile,
878  "-W- unexpected item %s, size %lu\n", pcFile, iSize);
879  }
880  }
881 
882  *piRecl = iRecl;
883  *piSize = iSize;
884  if (iDebug)
885  fprintf(fLogFile, "-D- end %s\n\n", cModule);
886 
887  return iRC;
888 
889 } /* rawGetFileSize */
890 
891 /*********************************************************************
892  * rawGetPathName: get path name from high level object name
893  *
894  * created 21. 3.1996, Horst Goeringer
895  *********************************************************************
896  * 23. 4.1996, H.G: no more device dependency in hl-name, as with
897  * ADSM V213 management class can be set in dsmSendObj
898  *********************************************************************
899  */
900 
901 char *rawGetPathName( char *pcNamehl)
902 {
903  char cModule[32] = "rawGetPathName";
904  int iDebug = 0;
905 
906  char *ploc = NULL, *ploc1 = NULL;
907  char *pcc;
908 
909  if (iDebug)
910  fprintf(fLogFile, "-D- begin %s: hl: %s\n", cModule, pcNamehl);
911 
912  if (strlen(pcNamehl) == 0)
913  {
914  fprintf(fLogFile, "-E- %s: high level name empty\n", cModule);
915  return(pcNull);
916  }
917 
918  pcc = pcNamehl;
919  ploc = strchr(pcNamehl, *pcObjDelim);
920  ploc1 = strchr(pcNamehl, *pcObjDelimAlt);
921  if ( (ploc != pcc) && (ploc1 != pcc) )
922  {
923  fprintf(fLogFile,
924  "-E- %s: invalid prefix in high level name %s\n",
925  cModule, pcNamehl);
926  return(pcNull);
927  }
928 
929  strcpy(cPath, pcc);
930  if (iDebug) fprintf(fLogFile,
931  "-D- end %s: path %s\n\n", cModule, cPath);
932 
933  return cPath;
934 
935 } /* rawGetPathName */
936 
937 /********************************************************************
938  * rawQueryFile: get query information for single file
939  *
940  * used for tape input handled sequentially
941  * buffers for communication and query info allocated in calling
942  * procedure
943  ********************************************************************
944  */
945 
947  int iSocket,
948  int iAltMaster, /* currently unused */
949  srawComm *pCommBuf,
950  void **pQueryBuf)
951 {
952  char cModule[32] = "rawQueryFile";
953  int iDebug = 0;
954 
955  int iATLServer = -1; /* =0: all, =1: aixtsm1, =2: gsitsma */
956  int iNameWC = -1;
957  int iRC;
958  int iAction;
959  int iIdent, iQuery = -1, iAttrLen;
960  int iQueryAll = 0;
961  int iStatus, iStatusLen;
962  int iBuf, iBufComm;
963  int ii, jj;
964  char *pcc;
965 
966  int iVersionObjAttr = 0;
967  /* version no. of srawObjAttr:
968  =3: 288 byte cache buffer, 2 restore fields
969  =4: 304 byte, 5 restore fields, ATL server no.
970  =5: 384 byte, maior enhancement */
971  int iPoolId = 0;
972  int iObjLow = 0;
973  int iFS = 0;
974 
975  srawComm *pComm;
976  srawQueryResult *pQuery;
977  srawObjAttr *pObjAttr;
978 
979  pComm = pCommBuf;
980  iAction = ntohl(pComm->iAction);
981  iATLServer = ntohl(pComm->iATLServer);
982  pQuery = (srawQueryResult *) (*pQueryBuf);
983 
984  iBufComm = ntohl(pComm->iCommLen) + HEAD_LEN;
985  if (iDebug) fprintf(fLogFile,
986  "\n-D- begin %s: query file %s in ATL Server %d (action %d)\n",
987  cModule, pComm->cNamell, iATLServer, iAction);
988 
989  switch(iAction)
990  {
991  case QUERY:
992  case QUERY_ARCHIVE:
995  case QUERY_ARCHIVE_MGR:
996  case QUERY_REMOVE:
997  case QUERY_REMOVE_MGR:
998  case QUERY_RETRIEVE:
1000  case QUERY_STAGE:
1001  ; /* okay */
1002  break;
1003  default:
1004  fprintf(fLogFile,
1005  "-E- %s: invalid action %d\n", cModule, iAction);
1006  iQuery = -1;
1007  goto gEndQueryFile;
1008  }
1009 
1010  pcc = (char *) pComm;
1011  iRC = send(iSocket, pcc, (unsigned) iBufComm, 0);
1012  if (iRC < iBufComm)
1013  {
1014  if (iRC < 0) fprintf(fLogFile,
1015  "-E- %s: sending command buffer for query file %s\n",
1016  cModule, pComm->cNamell);
1017  else fprintf(fLogFile,
1018  "-E- %s: query command buffer incompletely sent (%d of %d byte)\n",
1019  cModule, iRC, iBufComm);
1020 
1021  if (errno)
1022  {
1023  fprintf(fLogFile, " %s\n", strerror(errno));
1024  errno = 0;
1025  }
1026 
1027  iQuery = -1;
1028  goto gEndQueryFile;
1029  }
1030 
1031  if (iDebug) fprintf(fLogFile,
1032  " query command sent to entry server (%d bytes), look for reply\n",
1033  iBufComm);
1034 
1035  /******************* look for reply from server *******************/
1036 
1037 gNextReply:
1038  pcc = (char *) pQuery;
1039  iRC = rawRecvHead(iSocket, pcc);
1040  if (iRC <= 0)
1041  {
1042  fprintf(fLogFile,
1043  "-E- %s: receiving buffer header with query information\n",
1044  cModule);
1045  iQuery = -1;
1046  goto gEndQueryFile;
1047  }
1048 
1049  pcc += HEAD_LEN;
1050  iIdent = ntohl(pQuery->iIdent);
1051  iQuery = ntohl(pQuery->iObjCount);
1052  iAttrLen = ntohl(pQuery->iAttrLen);
1053 
1054  if (iDebug) fprintf(fLogFile,
1055  " %d bytes received: iIdent %d, iQuery %d, iAttrLen %d\n",
1056  iRC, iIdent, iQuery, iAttrLen);
1057 
1058  if ( (iIdent != IDENT_QUERY) && (iIdent != IDENT_QUERY_DONE) &&
1059  (iIdent != IDENT_QUERY_ARCHDB) )
1060  {
1061  iStatus = iQuery;
1062  iQuery = -1; /* query failed */
1063 
1064  if (iIdent == IDENT_STATUS)
1065  {
1066  iStatusLen = iAttrLen;
1067  if ( (iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF) ||
1068  (iStatus == STA_ARCHIVE_NOT_AVAIL) ||
1069  (iStatus == STA_NO_ACCESS) )
1070  {
1071  if ( (iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF) )
1072  fprintf(fLogFile,
1073  "-E- %s: error status from entry server instead of query data:\n",
1074  cModule);
1075 
1076  if (iStatusLen > 0)
1077  {
1078  iRC = rawRecvError(iSocket, iStatusLen, pcc);
1079  if (iRC < 0) fprintf(fLogFile,
1080  "-E- receiving error msg from server, rc = %d\n",
1081  iRC);
1082  else if ( (iDebug) || (iStatus == STA_ERROR) ||
1083  (iStatus == STA_ERROR_EOF) )
1084  fprintf(fLogFile, "%s", pcc);
1085  }
1086  else
1087  fprintf(fLogFile," no error message available\n");
1088 
1089  if (iStatus == STA_ARCHIVE_NOT_AVAIL)
1090  iQuery = -1000;
1091  else if (iStatus == STA_NO_ACCESS)
1092  iQuery = -1001;
1093 
1094  } /* (iStatus == STA_ERROR || STA_ERROR_EOF ||
1095  STA_ARCHIVE_NOT_AVAIL || STA_NO_ACCESS) */
1096  else fprintf(fLogFile,
1097  "-E- %s: unexpected status (type %d) received from server\n",
1098  cModule, iStatus);
1099 
1100  } /* iIdent == IDENT_STATUS */
1101  else fprintf(fLogFile,
1102  "-E- %s: unexpected header (type %d) received from server\n",
1103  cModule, iIdent);
1104 
1105  iQueryAll = iQuery;
1106  goto gEndQueryFile;
1107 
1108  } /* iIdent != IDENT_QUERY && != IDENT_QUERY_DONE &&
1109  != IDENT_QUERY_ARCHDB */
1110 
1111  iQueryAll += iQuery;
1112  if (iQuery > 0)
1113  {
1114  pcc = (char *) pQuery + HEAD_LEN;
1115  pObjAttr = (srawObjAttr *) pcc;
1116 
1117  /* DDD iQuery = 1 only! */
1118  for (ii=1; ii<=iQuery; ii++)
1119  {
1120  iBuf = iAttrLen; /* only space for one object buffer */
1121  while(iBuf > 0)
1122  {
1123  if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
1124  {
1125  if (iRC < 0)
1126  {
1127  fprintf(fLogFile,
1128  "-E- %s: receiving buffer %d with query results\n",
1129  cModule, ii);
1130 
1131  iQuery = -1;
1132  iQueryAll -= iQuery;
1133  }
1134  else
1135  {
1136  jj = iAttrLen - iBuf;
1137  fprintf(fLogFile,
1138  "-E- %s: connection to server broken, only %d bytes of query object %d (%d byte) received\n",
1139  cModule, jj, ii, iAttrLen);
1140 
1141  if (ii == 1)
1142  {
1143  iQuery = -1;
1144  iQueryAll -= iQuery;
1145  }
1146  else
1147  {
1148  fprintf(fLogFile,
1149  "-E- %s: only %d of %d objects received\n",
1150  cModule, --ii, iQuery);
1151  iQueryAll -= iQuery - ii;
1152  iQuery = ii;
1153  }
1154  }
1155 
1156  if (errno)
1157  {
1158  fprintf(fLogFile, " %s\n", strerror(errno));
1159  errno = 0;
1160  }
1161 
1162  goto gEndQueryFile;
1163  }
1164 
1165  iBuf -= iRC;
1166  pcc += iRC;
1167 
1168  } /* while(iBuf > 0) */
1169 
1170  iVersionObjAttr = ntohl(pObjAttr->iVersion);
1171  if ( (iVersionObjAttr != VERSION_SRAWOBJATTR) &&
1172  (iVersionObjAttr != VERSION_SRAWOBJATTR-1) )
1173  {
1174  fprintf(fLogFile,
1175  "-E- %s: invalid cacheDB entry version %d\n",
1176  cModule, iVersionObjAttr);
1177 
1178  iQuery = -1;
1179  goto gEndQueryFile;
1180  }
1181 
1182  iPoolId = ntohl(pObjAttr->iPoolId);
1183  if (iDebug)
1184  {
1185  if (ii == 1) fprintf(fLogFile,
1186  " query buffer received (%d bytes, objAttr data V%d)\n",
1187  iAttrLen, iVersionObjAttr);
1188  else fprintf(fLogFile,
1189  " query buffer overlaid (%d bytes)\n", iAttrLen);
1190 
1191  fprintf(fLogFile, " %s%s%s: poolId %d",
1192  pObjAttr->cNamefs, pObjAttr->cNamehl,
1193  pObjAttr->cNamell, iPoolId);
1194  if (iPoolId == 1)
1195  fprintf(fLogFile, " (RetrievePool)\n");
1196  else if (iPoolId == 2)
1197  fprintf(fLogFile, " (StagePool)\n");
1198  else if (iPoolId == 3)
1199  fprintf(fLogFile, " (ArchivePool)\n");
1200  else if (iPoolId == 4)
1201  fprintf(fLogFile, " (DAQPool)\n");
1202  else
1203  fprintf(fLogFile, " (TSM DB)\n");
1204  }
1205  } /* object loop */
1206  } /* (iQuery > 0) */
1207  else if ( (iQuery == 0) && (iDebug) )
1208  fprintf(fLogFile,
1209  " no more objects found in ATL server %d\n", iATLServer);
1210 
1211  /* if object explicitly specified, stop query if found */
1212  if ( (strchr(pComm->cNamell, *pcStar) == NULL) &&
1213  (strchr(pComm->cNamell, *pcQM) == NULL) &&
1214  (strchr(pComm->cNamell, *pcPerc) == NULL) &&
1215  (strchr(pComm->cNamehl, *pcStar) == NULL) &&
1216  (strchr(pComm->cNamehl, *pcQM) == NULL) &&
1217  (strchr(pComm->cNamehl, *pcPerc) == NULL) )
1218  iNameWC = 0;
1219  else
1220  iNameWC = 1;
1221 
1222  if ( (iNameWC == 0) && (iQuery > 0) ) /* fixed name, found */
1223  goto gEndQueryFile;
1224 
1225  if ( (iIdent == IDENT_QUERY) || (iIdent == IDENT_QUERY_ARCHDB) )
1226  goto gNextReply;
1227 
1228 gEndQueryFile:
1229  switch (iQueryAll)
1230  {
1231  case 0:
1232  if (iDebug) fprintf(fLogFile,
1233  " no matching object %s in gStore found\n",
1234  pComm->cNamell);
1235  break;
1236  case 1:
1237  if (iDebug) fprintf(fLogFile,
1238  " file %s available in gStore\n", pComm->cNamell);
1239  break;
1240  case -1:
1241  fprintf(fLogFile,
1242  "-E- %s: query in gStore could not be executed\n",
1243  cModule);
1244  iQuery = -1;
1245  break;
1246  case -1000:
1247  if (iDebug) fprintf(fLogFile,
1248  " requested archive %s not existing in gStore\n",
1249  pComm->cNamefs);
1250  break;
1251  case -1001:
1252  if (iDebug) fprintf(fLogFile,
1253  " requested access to file %s not allowed\n",
1254  pComm->cNamell);
1255  break;
1256  default:
1257  if (iQueryAll > 1)
1258  {
1259  if (strcmp(pComm->cOwner, "goeri") == 0)
1260  fprintf(fLogFile, "-W- %d versions of %s exist!\n",
1261  iQuery, pComm->cNamell);
1262  }
1263  else
1264  {
1265  fprintf(fLogFile,
1266  "-E- %s: invalid number %d of objects %s found\n",
1267  cModule, iQuery, pComm->cNamell);
1268  iQuery = -1;
1269  }
1270  } /* switch (iQuery) */
1271 
1272  if (iDebug) fprintf(fLogFile,
1273  "-D- end %s\n\n", cModule);
1274 
1275  return iQuery;
1276 
1277 } /* end rawQueryFile */
1278 
1279 /*********************************************************************/
1280 /* rawRecvError: receive error message */
1281 /* returns length of error message */
1282 /* */
1283 /* created 14. 3.96, Horst Goeringer */
1284 /*********************************************************************/
1285 
1286 int rawRecvError(int iSocket, int iLen, char *pcMsg)
1287 {
1288  char cModule[32]="rawRecvError";
1289  int iDebug = 0;
1290 
1291  int iRC = 0, ii;
1292  int iBuf, iBufs;
1293  char *pcc;
1294 
1295  if (iDebug)
1296  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
1297 
1298  strcpy(pcMsg, "");
1299  pcc = pcMsg; /* points now to buffer in calling procedure */
1300 
1301  iBuf = iLen; /* length of error message */
1302  iBufs = iBuf;
1303  while(iBuf > 0)
1304  {
1305  if ( (iRC = recv(iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
1306  {
1307  if (iRC < 0)
1308  {
1309  fprintf(fLogFile,
1310  "-E- %s: receiving error message\n", cModule);
1311 
1312  if (errno)
1313  {
1314  fprintf(fLogFile, " %s\n", strerror(errno));
1315  errno = 0;
1316  }
1317 
1318  iRC = -9;
1319  break;
1320  }
1321  else
1322  {
1323  ii = iLen - iBuf;
1324  if (ii) /* append delimiters after part of message received */
1325  {
1326  *pcc = '\0'; /* delimit message string */
1327  pcc++;
1328  *pcc = '\n';
1329  pcc++;
1330  if (iDebug) fprintf(fLogFile,
1331  "-E- incomplete error message received:\n %s", pcMsg);
1332  }
1333  fprintf(fLogFile,
1334  "-E- %s: connection to sender broken, %d byte of error message (%d byte) received\n",
1335  cModule, ii, iLen);
1336 
1337  if (errno)
1338  {
1339  fprintf(fLogFile, " %s\n", strerror(errno));
1340  errno = 0;
1341  }
1342 
1343  iRC = -8;
1344  break;
1345  }
1346  }
1347 
1348  iBuf -= iRC;
1349  pcc += iRC;
1350 
1351  } /* while(iBuf > 0) */
1352 
1353  if (iBuf < 0)
1354  {
1355  fprintf(fLogFile,
1356  "-E- %s: more error data received than expected:\n %s",
1357  pcMsg, cModule);
1358  iRC = -2;
1359  }
1360 
1361  if (iRC == -9)
1362  {
1363  if (iDebug)
1364  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1365 
1366  return iRC;
1367  }
1368  else
1369  {
1370  /* also okay if no message (iLen = 0) */
1371  *pcc = '\0'; /* delimit message string */
1372 
1373  /* only msg part received */
1374  if (iRC == -8)
1375  iBufs = ii;
1376 
1377  if (iDebug)
1378  {
1379  fprintf(fLogFile,
1380  " error message received (%d bytes):\n %s",
1381  iBufs, pcMsg);
1382  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1383  }
1384 
1385  return iBufs;
1386  }
1387 
1388 } /* rawRecvError */
1389 
1390 /*********************************************************************
1391  * rawRecvHead: receive common buffer header
1392  * returns no. of bytes received or error (< 0)
1393  *
1394  * created 5. 3.96, Horst Goeringer
1395  *********************************************************************
1396  */
1397 
1398 int rawRecvHead( int iSocket, char *pcBuf)
1399 {
1400  char cModule[32]="rawRecvHead";
1401  int iDebug = 0;
1402 
1403  int iBuf, iBufs;
1404  int iRC, ii;
1405  int iIdent;
1406  int iStatus;
1407  int iDataLen;
1408  char *pcc;
1409  int *pint;
1410 
1411  if (iDebug)
1412  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
1413 
1414  strcpy(pcBuf, "");
1415  pcc = pcBuf; /* points now to buffer in calling procedure */
1416  pint = (int *) pcc;
1417 
1418  iBuf = HEAD_LEN;
1419  iBufs = iBuf;
1420  while(iBuf > 0)
1421  {
1422  iRC = recv(iSocket, pcc, (unsigned) iBuf, 0);
1423  if (iRC <= 0)
1424  {
1425  if (iRC < 0) fprintf(fLogFile,
1426  "-E- %s: receiving buffer header\n", cModule);
1427  else
1428  {
1429  ii = iBufs - iBuf;
1430  fprintf(fLogFile,
1431  "-E- %s: connection to sender broken, %d byte of buffer header (%d byte) received\n",
1432  cModule, ii, iBufs);
1433  }
1434 
1435  if (errno)
1436  {
1437  fprintf(fLogFile, " %s\n", strerror(errno));
1438  errno = 0;
1439  }
1440 
1441  return -1;
1442  }
1443 
1444  iBuf -= iRC;
1445  pcc += iRC;
1446 
1447  } /* while(iBuf > 0) */
1448 
1449  iIdent = ntohl(*pint);
1450  pint++;
1451  iStatus = ntohl(*pint);
1452  pint++;
1453  iDataLen = ntohl(*pint);
1454  if (iDebug) fprintf(fLogFile,
1455  " ident %d, status %d, datalen %d\n",
1456  iIdent, iStatus, iDataLen);
1457 
1458  if ( (iIdent == IDENT_STATUS) &&
1459  ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF)) &&
1460  (iDataLen > 0) )
1461  {
1462  if (iDebug) fprintf(fLogFile,
1463  "-W- %s: error message available for receive (%d byte)\n",
1464  cModule, iDataLen);
1465  return iDataLen;
1466  }
1467 
1468  if (iDebug) fprintf(fLogFile,
1469  "-D- end %s: buffer header received (%d bytes)\n\n",
1470  cModule, iBufs);
1471 
1472  return iBufs;
1473 
1474 } /* rawRecvHead */
1475 
1476 /*********************************************************************
1477  * rawRecvHeadC: receive common buffer header and check
1478  * return values:
1479  * >= 0: no error occurred:
1480  * = HEAD_LEN: header received (and okay)
1481  * > HEAD_LEN: status message of this size in pcMsg
1482  * = 0: error status received, but no message
1483  *
1484  * < 0: error occurred:
1485  * = -1: recv failed
1486  * = -2: connection to sender lost
1487  * = -3: receiving error msg failed
1488  * = -4: unexpected identifier received
1489  * = -5: unexpected status received
1490  *
1491  * created 7. 3.2002, Horst Goeringer
1492  *********************************************************************
1493  */
1494 
1495 int rawRecvHeadC(int iSocket,
1496  char *pcBuf,
1497  int iIdentReq, /* < 0 => check, = 0 => no check */
1498  int iStatusReq, /* >= 0 => check, < 0 => no check */
1499  char *pcMsg)
1500 {
1501  char cModule[32] = "rawRecvHeadC";
1502  int iDebug = 0;
1503 
1504  /* header to be received */
1505  int iIdent;
1506  int iStatus;
1507  int iDataLen;
1508 
1509  char cMsg1[STATUS_LEN] = "";
1510 
1511  int iRC, ii;
1512  int iBuf, iBufs;
1513  char *pcc;
1514  int *pint;
1515 
1516  if (iDebug)
1517  {
1518  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
1519 
1520  if (iIdentReq < 0) fprintf(fLogFile,
1521  " check Ident, expect %d\n", iIdentReq);
1522  else
1523  fprintf(fLogFile, " no check of Ident\n");
1524  if (iStatusReq >= 0) fprintf(fLogFile,
1525  " check Status, expect %d\n", iStatusReq);
1526  else
1527  fprintf(fLogFile, " no check of Status\n");
1528  }
1529 
1530  strcpy(pcMsg, "");
1531  strcpy(pcBuf, "");
1532  pcc = pcBuf; /* points now to buffer in calling procedure */
1533 
1534  iBuf = HEAD_LEN;
1535  iBufs = iBuf;
1536  while(iBuf > 0)
1537  {
1538  if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
1539  {
1540  if (iRC < 0)
1541  {
1542  sprintf(pcMsg, "-E- %s: receiving buffer header\n",
1543  cModule);
1544  iRC = -1;
1545  }
1546  else
1547  {
1548  ii = iBufs - iBuf;
1549  sprintf(pcMsg,
1550  "-E- %s: connection to sender broken, %d byte of buffer header (%d byte) received\n",
1551  cModule, ii, iBufs);
1552  iRC = -2;
1553  }
1554 
1555  if (errno)
1556  {
1557  snprintf(cMsg1, sizeof(cMsg1), " %s\n", strerror(errno));
1558  strcat(pcMsg, cMsg1);
1559  errno = 0;
1560  }
1561 
1562  if (iDebug)
1563  fprintf(fLogFile, "%s", pcMsg);
1564 
1565  goto gEndRecvHeadC;
1566  }
1567 
1568  iBuf -= iRC;
1569  pcc += iRC;
1570 
1571  } /* while(iBuf > 0) */
1572 
1573  if (iDebug) fprintf(fLogFile,
1574  " buffer header received (%d bytes)\n", iBufs);
1575 
1576  pint = (int *) pcBuf;
1577  iIdent = ntohl(*pint);
1578  pint++;
1579  iStatus = ntohl(*pint);
1580  pint++;
1581  iDataLen = ntohl(*pint);
1582 
1583  if (iDebug) fprintf(fLogFile,
1584  " ident %d, status %d, datalen %d\n",
1585  iIdent, iStatus, iDataLen);
1586 
1587  if (iIdent == IDENT_STATUS)
1588  {
1589  if (iDebug)
1590  {
1591  fprintf(fLogFile, " status received");
1592  if ( (iDataLen) &&
1593  ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF)) )
1594  fprintf(fLogFile, " with error message\n");
1595  else
1596  fprintf(fLogFile, "\n");
1597  }
1598 
1599  if ( (iDataLen) &&
1600  ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF) ||
1601  (iStatus == STA_CACHE_FULL)) )
1602  {
1603  pcc = cMsg1;
1604  iRC = rawRecvError(iSocket, iDataLen, pcc);
1605  if (iRC < 0)
1606  {
1607  sprintf(pcMsg, "-E- %s: receiving error msg, rc=%d\n",
1608  cModule, iRC);
1609  if (iDebug)
1610  fprintf(fLogFile, "%s", pcMsg);
1611 
1612  iRC = -3;
1613  goto gEndRecvHeadC;
1614  }
1615 
1616  if (iDebug) fprintf(fLogFile,
1617  " msg (%d byte): %s\n", iDataLen, pcc);
1618  strcat(pcMsg, pcc);
1619  iRC = strlen(pcMsg);
1620  goto gEndRecvHeadC;
1621  }
1622 
1623  if ( (iDataLen == 0) &&
1624  ((iStatus == STA_ERROR) || (iStatus == STA_ERROR_EOF)) )
1625  {
1626  strcat(pcMsg,
1627  "-W- error status received, but no error message\n");
1628  iRC = 0;
1629  goto gEndRecvHeadC;
1630  }
1631  } /* (iIdent == IDENT_STATUS) */
1632 
1633  if (iIdentReq < 0) /* test for expected identifier, values < 0 */
1634  {
1635  if (iDebug)
1636  fprintf(fLogFile, " check identifier\n");
1637 
1638  if (iIdent != iIdentReq)
1639  {
1640  sprintf(pcMsg,
1641  "-E- %s: unexpected header (ident %d) received\n",
1642  cModule, iIdent);
1643  if (iDebug)
1644  fprintf(fLogFile, "%s", pcMsg);
1645 
1646  iRC = -4;
1647  goto gEndRecvHeadC;
1648 
1649  } /* unexpected ident) */
1650  else
1651  {
1652  if (iStatusReq >= 0) /* test for expected status */
1653  {
1654  if (iDebug)
1655  fprintf(fLogFile, " check status\n");
1656 
1657  if (iStatusReq != iStatus)
1658  {
1659  sprintf(pcMsg,
1660  "-E- %s: unexpected header (status %d) received\n",
1661  cModule, iStatus);
1662  if (iDebug)
1663  fprintf(fLogFile, "%s", pcMsg);
1664 
1665  iRC = -5;
1666  goto gEndRecvHeadC;
1667  }
1668  }
1669  } /* expected ident */
1670  } /* check ident requested */
1671 
1672  iRC = HEAD_LEN;
1673 
1674 gEndRecvHeadC:
1675  if (iDebug)
1676  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1677 
1678  return iRC;
1679 
1680 } /* rawRecvHeadC */
1681 
1682 /*********************************************************************
1683  * rawRecvRequest:
1684  * receive request for next buffer and convert to host format
1685  * returns 0: request received
1686  * 2: EOF status received
1687  * 3: EOS status received
1688  * 4, 5: error status received
1689  * < 0: error occured
1690  *
1691  * created 21.12.2000, Horst Goeringer
1692  *********************************************************************
1693  */
1694 
1695 int rawRecvRequest(int iSocket,
1696  int *piSeekMode,
1697  int *piOffset,
1698  int *piBufferSize)
1699 {
1700  char cModule[32]="rawRecvRequest";
1701  int iDebug = 0;
1702 
1703  int iRC;
1704  int iError = 0;
1705  int iRequSize = sizeof(srawRequest);
1706  int iBuf, iBuf0;
1707  int ii, iimax;
1708  char *pcc;
1709  char cMsg[STATUS_LEN] = ""; /* error msg received */
1710 
1711  srawRequest sRequest, *pRequest;
1712 
1713  if (iDebug) fprintf(fLogFile,
1714  "\n-D- begin %s: receive request buffer\n", cModule);
1715 
1716  pRequest = &sRequest;
1717  pcc = (char *) pRequest;
1718  iBuf = HEAD_LEN;
1719  iimax = HEAD_LEN;
1720  while(iBuf > 0)
1721  {
1722  if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
1723  {
1724  if (iRC < 0)
1725  {
1726  fprintf(fLogFile,
1727  "-E- %s: receiving buffer header\n", cModule);
1728  iError = -1;
1729  }
1730  else
1731  {
1732  ii = iimax - iBuf;
1733  fprintf(fLogFile,
1734  "-W- %s: connection to sender broken, %d byte of buffer header (%d byte) received\n",
1735  cModule, ii, iimax);
1736  iError = -5;
1737  }
1738 
1739  goto gErrorRecvRequest;
1740  }
1741 
1742  iBuf -= iRC;
1743  pcc += iRC;
1744 
1745  } /* while(iBuf > 0) */
1746 
1747  if (iBuf < 0)
1748  {
1749  fprintf(fLogFile,
1750  "-E- %s: more buffer header data received than expected\n",
1751  cModule);
1752 
1753  iError = -2;
1754  goto gErrorRecvRequest;
1755  }
1756 
1757  pRequest->iIdent = ntohl(pRequest->iIdent);
1758  if (iDebug) fprintf(fLogFile,
1759  " buffer header received (%d bytes, id %d)\n",
1760  iimax, pRequest->iIdent);
1761 
1762  if ( (pRequest->iIdent != IDENT_NEXT_BUFFER) &&
1763  (pRequest->iIdent != IDENT_STATUS) )
1764  {
1765  fprintf(fLogFile, "-E- %s: invalid buffer received (id %d)\n",
1766  cModule, pRequest->iIdent);
1767  iError = -3;
1768  goto gErrorRecvRequest;
1769  }
1770 
1771  pRequest->iStatus = ntohl(pRequest->iStatus);
1772  pRequest->iStatusLen = ntohl(pRequest->iStatusLen);
1773  iBuf0 = pRequest->iStatusLen;
1774  iBuf = iBuf0;
1775  if (pRequest->iIdent != IDENT_NEXT_BUFFER)
1776  pcc = cMsg; /* more space needed */
1777 
1778  while(iBuf > 0)
1779  {
1780  if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
1781  {
1782  if (iRC < 0)
1783  {
1784  fprintf(fLogFile,
1785  "-E- %s: receiving buffer data\n", cModule);
1786  iError = -1;
1787  }
1788  else
1789  {
1790  ii = iBuf0 - iBuf;
1791  fprintf(fLogFile,
1792  "-W- %s: connection to sender broken, %d byte of data (%d byte) received\n",
1793  cModule, ii, iBuf0);
1794  iError = -5;
1795  }
1796 
1797  if (errno)
1798  {
1799  fprintf(fLogFile, " %s\n", strerror(errno));
1800  errno = 0;
1801  }
1802 
1803  goto gErrorRecvRequest;
1804  }
1805 
1806  iBuf -= iRC;
1807  pcc += iRC;
1808 
1809  } /* while(iBuf > 0) */
1810 
1811  if (iBuf < 0)
1812  {
1813  fprintf(fLogFile, "-E- %s: more data received than expected\n",
1814  cModule);
1815  iError = -2;
1816  goto gErrorRecvRequest;
1817  }
1818 
1819  if (pRequest->iIdent == IDENT_NEXT_BUFFER)
1820  {
1821  if (iDebug) fprintf(fLogFile,
1822  " %s: request data received (%d bytes)\n", cModule, iBuf0);
1823 
1824  if (iBuf0 + HEAD_LEN != iRequSize)
1825  {
1826  fprintf(fLogFile,
1827  "-E- %s: invalid data size (%d) in request buffer (expected %d byte)\n",
1828  cModule, iBuf0, iRequSize-HEAD_LEN);
1829  iError = -4;
1830  goto gErrorRecvRequest;
1831  }
1832 
1833  *piSeekMode = ntohl(pRequest->iSeekMode);
1834  *piOffset = ntohl(pRequest->iOffset);
1835  *piBufferSize = ntohl(pRequest->iBufferSize);
1836 
1837  if (iDebug)
1838  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1839 
1840  return 0;
1841 
1842  } /* (pRequest->iIdent == IDENT_NEXT_BUFFER) */
1843  else if (pRequest->iIdent == IDENT_STATUS)
1844  {
1845  if ( (pRequest->iStatus == STA_END_OF_FILE) ||
1846  (pRequest->iStatus == STA_END_OF_SESSION) )
1847  {
1848  if (iDebug) fprintf(fLogFile,
1849  " %s: status info received: end session\n", cModule);
1850  }
1851  else if ( (pRequest->iStatus == STA_ERROR) ||
1852  (pRequest->iStatus == STA_ERROR_EOF) )
1853 
1854  {
1855  if (iDebug) fprintf(fLogFile,
1856  "-W- %s: error status received: end session\n", cModule);
1857  if (iBuf0 > 0) fprintf(fLogFile,
1858  "-W- %s: error message from client:\n %s\n",
1859  cModule, cMsg);
1860  iError = -4;
1861  goto gErrorRecvRequest;
1862  }
1863  else
1864  {
1865  fprintf(fLogFile,
1866  "-E- %s: invalid status buffer received (id %d)\n",
1867  cModule, pRequest->iStatus);
1868  iError = -3;
1869  goto gErrorRecvRequest;
1870  }
1871 
1872  iError = pRequest->iStatus;
1873  goto gErrorRecvRequest;
1874 
1875  } /* (pRequest->iIdent == IDENT_STATUS) */
1876  else
1877  {
1878  fprintf(fLogFile, "-E- %s: invalid buffer received (ident %d)\n",
1879  cModule, pRequest->iIdent);
1880  iError = -2;
1881  goto gErrorRecvRequest;
1882  }
1883 
1884 gErrorRecvRequest:
1885  if (iDebug)
1886  fprintf(fLogFile, "-D- end %s\n\n", cModule);
1887 
1888  if (iError)
1889  return iError;
1890 
1891  return 0;
1892 
1893 } /* rawRecvRequest */
1894 
1895 /*********************************************************************
1896  * rawRecvStatus: receive status header
1897  * returns no. of bytes received or error (< 0)
1898  * status header will be converted to host format
1899  *
1900  * created 18. 3.96, Horst Goeringer
1901  *********************************************************************
1902  */
1903 
1904 int rawRecvStatus( int iSocket, char *pcBuf)
1905 {
1906  char cModule[32]="rawRecvStatus";
1907  int iDebug = 0;
1908 
1909  int iRC, ii;
1910  int iBuf, iBufs;
1911  int iLen;
1912  char *pcc;
1913  srawStatus *pStatus;
1914 
1915  if (iDebug)
1916  fprintf(fLogFile, "\n-D- begin %s\n", cModule);
1917 
1918  pcc = pcBuf; /* points now to buffer in calling procedure */
1919  pStatus = (srawStatus *) pcc;
1920  memset(pcc, 0x00, sizeof(HEAD_LEN));
1921  iBuf = HEAD_LEN;
1922  iBufs = iBuf;
1923 
1924  while(iBuf > 0)
1925  {
1926  if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
1927  {
1928  if (iRC < 0) fprintf(fLogFile,
1929  "-E- %s: receiving status header\n", cModule);
1930  else
1931  {
1932  ii = iBufs - iBuf;
1933  fprintf(fLogFile,
1934  "-E- %s: connection to sender broken, %d byte of status header (%d byte) received\n",
1935  cModule, ii, iBufs);
1936  }
1937 
1938  if (errno)
1939  {
1940  fprintf(fLogFile, " %s\n", strerror(errno));
1941  errno = 0;
1942  }
1943 
1944  return -1;
1945  }
1946 
1947  iBuf -= iRC;
1948  pcc += iRC;
1949 
1950  } /* while(iBuf > 0) */
1951 
1952  if (iBuf < 0)
1953  {
1954  fprintf(fLogFile,
1955  "-E- %s: more status header data received than expected\n",
1956  cModule);
1957  return -2;
1958  }
1959 
1960  pStatus->iIdent = ntohl(pStatus->iIdent);
1961  pStatus->iStatus = ntohl(pStatus->iStatus);
1962  pStatus->iStatusLen = ntohl(pStatus->iStatusLen);
1963 
1964  if (iDebug)
1965  {
1966  fprintf(fLogFile, " status header received (%d bytes)\n",
1967  iBufs);
1968  fprintf(fLogFile, " ident %d, status %d, status len %d\n",
1969  pStatus->iIdent, pStatus->iStatus, pStatus->iStatusLen);
1970  }
1971 
1972  if (pStatus->iIdent != IDENT_STATUS)
1973  {
1974  fprintf(fLogFile, "-E- %s: invalid status header received (%d)\n",
1975  cModule, pStatus->iIdent);
1976  return -3;
1977  }
1978 
1979  iLen = pStatus->iStatusLen;
1980  if (iLen > 0)
1981  {
1982  memset(pcc, 0x00, (unsigned) iLen);
1983  iBuf = iLen; /* length of status message */
1984  iBufs += iBuf;
1985  while(iBuf > 0)
1986  {
1987  if ( (iRC = recv( iSocket, pcc, (unsigned) iBuf, 0 )) <= 0 )
1988  {
1989  if (iRC < 0) fprintf(fLogFile,
1990  "-E- %s: receiving status message\n", cModule);
1991  else
1992  {
1993  ii = iLen - iBuf;
1994  fprintf(fLogFile,
1995  "-E- %s: connection to sender broken, %d byte of status message (%d byte) received\n",
1996  cModule, ii, iLen);
1997  }
1998 
1999  if (errno)
2000  {
2001  fprintf(fLogFile, " %s\n", strerror(errno));
2002  errno = 0;
2003  }
2004 
2005  return -4;
2006  }
2007 
2008  iBuf -= iRC;
2009  pcc += iRC;
2010 
2011  } /* while(iBuf > 0) */
2012 
2013  if (iBuf < 0)
2014  {
2015  fprintf(fLogFile,
2016  "-E- %s: more status data received than expected\n",
2017  cModule);
2018  return -5;
2019  }
2020 
2021  if (iDebug) fprintf(fLogFile,
2022  " status message received (%d bytes):\n%s\n",
2023  iLen, pStatus->cStatus);
2024 
2025  } /* iLen > 0 */
2026 
2027  if (iDebug)
2028  fprintf(fLogFile, "-D- end %s\n\n", cModule);
2029 
2030  return iBufs;
2031 
2032 } /* rawRecvStatus */
2033 
2034 /*********************************************************************
2035  * rawSendRequest: send request buffer
2036  * returns 0 or error (< 0)
2037  * status header will be converted to net format
2038  *
2039  * created 21.12.2000, Horst Goeringer
2040  *********************************************************************
2041  */
2042 
2043 int rawSendRequest(int iSocket,
2044  int iSeekMode,
2045  int iOffset,
2046  int iBufferSize)
2047 {
2048  char cModule[32]="rawSendRequest";
2049  int iDebug = 0;
2050 
2051  int iBuf, iRC;
2052  char *pcc;
2053 
2054  srawRequest sRequest;
2055  int iRequSize = sizeof(srawRequest);
2056 
2057  if (iDebug) fprintf(fLogFile,
2058  "\n-D- begin %s: send request buffer\n", cModule);
2059 
2060  sRequest.iIdent = htonl((unsigned int) IDENT_NEXT_BUFFER);
2061  if (iSeekMode < 0)
2062  sRequest.iStatus = htonl(STA_NEXT_BUFFER);
2063  else
2064  sRequest.iStatus = htonl(STA_SEEK_BUFFER);
2065  sRequest.iStatusLen = htonl(iRequSize - HEAD_LEN);
2066 
2067  sRequest.iSeekMode = htonl(iSeekMode);
2068  sRequest.iOffset = htonl(iOffset);
2069  if (iBufferSize < 0)
2070  {
2071  fprintf(fLogFile,
2072  "-E- %s: invalid buffer size %d\n", cModule, iBufferSize);
2073  return -1;
2074  }
2075  sRequest.iBufferSize = htonl(iBufferSize);
2076 
2077  iBuf = iRequSize;
2078  pcc = (char *) &sRequest;
2079  iRC = send(iSocket, pcc, (unsigned) iBuf, 0);
2080  if (iRC < iBuf)
2081  {
2082  if (iRC < 0) fprintf(fLogFile,
2083  "-E- %s: sending request buffer\n", cModule);
2084  else fprintf(fLogFile,
2085  "-E- %s: request buffer incompletely sent (%d of %d byte)\n",
2086  cModule, iRC, iBuf);
2087 
2088  if (errno)
2089  {
2090  fprintf(fLogFile, " %s\n", strerror(errno));
2091  errno = 0;
2092  }
2093 
2094  return -1;
2095  }
2096 
2097  if (iDebug) fprintf(fLogFile,
2098  "-D- end %s: request buffer sent\n\n", cModule);
2099 
2100  return 0;
2101 
2102 } /* rawSendRequest */
2103 
2104 /*********************************************************************
2105  * rawSendStatus: send status buffer
2106  * returns no. of bytes sent or error (< 0)
2107  * status header will be converted to net format
2108  *
2109  * created 5. 3.96, Horst Goeringer
2110  *********************************************************************
2111  */
2112 
2113 int rawSendStatus( int iSocket, int iStatus, char *pcMsg)
2114 {
2115  char cModule[32]="rawSendStatus";
2116  int iDebug = 0;
2117 
2118  int iBuf = HEAD_LEN;
2119  int iRC, iMsgLen;
2120  char *pcc;
2121  srawStatus sStatus;
2122 
2123  if (iDebug) fprintf(fLogFile,
2124  "\n-D- begin %s: send status buffer (%d) to socket %d\n",
2125  cModule, iStatus, iSocket);
2126 
2127  sStatus.iIdent = htonl((unsigned int) IDENT_STATUS);
2128  sStatus.iStatus = htonl(iStatus);
2129  sStatus.iStatusLen = htonl(0);
2130 
2131  if (pcMsg == NULL)
2132  iMsgLen = 0;
2133  else
2134  iMsgLen = strlen(pcMsg);
2135  if (iMsgLen)
2136  {
2137  iBuf += iMsgLen;
2138  sStatus.iStatusLen = htonl(iMsgLen);
2139  strcpy(sStatus.cStatus, pcMsg);
2140  if (iDebug) fprintf(fLogFile,
2141  " %s: error message (%d bytes):\n %s\n",
2142  cModule, iMsgLen, pcMsg);
2143  }
2144 
2145  pcc = (char *) &sStatus;
2146  if (iDebug)
2147  {
2148  fprintf(fLogFile,
2149  " now send (iIdent %d, iStatus %d, iStatusLen %d), %d byte:\n",
2150  ntohl(sStatus.iIdent), ntohl(sStatus.iStatus),
2151  ntohl(sStatus.iStatusLen), iBuf);
2152  fflush(fLogFile);
2153  }
2154 
2155  iRC = send(iSocket, pcc, (unsigned) iBuf, 0);
2156  if (iRC < iBuf)
2157  {
2158  if (iRC < 0) fprintf(fLogFile,
2159  "-E- %s: sending status buffer\n", cModule);
2160  else fprintf(fLogFile,
2161  "-E- %s: status buffer incompletely sent (%d of %d byte)\n",
2162  cModule, iRC, iBuf);
2163 
2164  if (errno)
2165  {
2166  fprintf(fLogFile, " %s\n", strerror(errno));
2167  errno = 0;
2168  }
2169 
2170  return -1;
2171  }
2172 
2173  if (iDebug) fprintf(fLogFile,
2174  "-D- end %s: status buffer sent (%d byte)\n\n", cModule, iBuf);
2175 
2176  return(iBuf);
2177 
2178 } /* rawSendStatus */
2179 
2180 /*********************************************************************
2181  * rawTestFileName:
2182  * verify that specified name is a valid file name
2183  * and has no wildcards
2184  * created 15.3.1996, Horst Goeringer
2185  *********************************************************************
2186  */
2187 
2188 int rawTestFileName( char *pcFile)
2189 {
2190  char cModule[32] = "rawTestFileName";
2191  int iDebug = 0;
2192 
2193  int iRC;
2194  int ilen;
2195  int iError = 0;
2196  unsigned long lFileSize = 0; /* dummy for rawGetFileSize */
2197  unsigned int iSize = 0; /* dummy for rawGetFileSize */
2198  char *pdir;
2199 
2200  if (iDebug) fprintf(fLogFile,
2201  "-D- begin %s: input file name %s\n", cModule, pcFile);
2202 
2203  if ( (pdir = strrchr(pcFile, '*')) != NULL)
2204  {
2205  fprintf(fLogFile,
2206  "-E- invalid file name '%s': '*' not allowed as part of file name\n",
2207  pcFile);
2208  iError = 3;
2209  goto gErrorTest;
2210  }
2211 
2212  if ( (pdir = strrchr(pcFile, '?')) != NULL)
2213  {
2214  fprintf(fLogFile,
2215  "-E- invalid file name '%s': '?' not allowed as part of file name\n",
2216  pcFile);
2217  iError = 3;
2218  goto gErrorTest;
2219  }
2220 
2221  if ( (pdir = strrchr(pcFile, '/')) == NULL)
2222  {
2223  if (iDebug)
2224  fprintf(fLogFile, " name %s okay\n", pcFile);
2225  }
2226  else /* name contains '/' */
2227  {
2228  ilen = strlen(pdir);
2229  if (iDebug) fprintf(fLogFile,
2230  " trailor %s (len %d)\n", pdir, ilen);
2231  if (ilen == 1)
2232  {
2233  strncpy(pdir, "\0", 1);
2234  if (iDebug)
2235  fprintf(fLogFile, " %s is a directory\n", pcFile);
2236  iError = 2;
2237  goto gErrorTest;
2238  }
2239  else if (iDebug)
2240  fprintf(fLogFile, " rel name %s okay\n", pcFile);
2241  }
2242 
2243  iRC = rawGetFileSize(pcFile, &lFileSize, &iSize);
2244  if (iDebug) fprintf(fLogFile,
2245  " after rawGetFileSize, rc = %d\n", iRC);
2246 
2247  if (iRC)
2248  {
2249  if (iDebug)
2250  {
2251  fprintf(fLogFile, "-W- %s NOT archived", pcFile);
2252  if (iRC == 1)
2253  fprintf(fLogFile, " - is a directory\n");
2254  else if (iRC == 2)
2255  fprintf(fLogFile, " - is a symbolic link\n");
2256  else if (iRC == 3)
2257  fprintf(fLogFile, " - is not a regular file\n");
2258  else
2259  fprintf(fLogFile, "\n");
2260  }
2261 
2262  iError = 2;
2263  goto gErrorTest;
2264  }
2265 
2266  if (iDebug) fprintf(fLogFile,
2267  " %s is a regular file\n", pcFile);
2268 
2269 gErrorTest:
2270  if (iDebug)
2271  fprintf(fLogFile, "-D- end %s\n\n", cModule);
2272 
2273  return iError;
2274 
2275 } /* rawTestFileName */
2276 
int iAction
Definition: rawcommn.h:399
int iVersion
Definition: rawcommn.h:520
Definition: rawapitd.h:31
int rawRecvStatus(int iSocket, char *pcBuf)
Definition: rawProcn.c:1904
int iBufferSize
Definition: rawcommn.h:486
int iIdent
Definition: rawcommn.h:470
char cNamehl[MAX_OBJ_HL]
Definition: rawcommn.h:523
int iOffset
Definition: rawcommn.h:485
#define MAX_OBJ_LL
Definition: rawcommn.h:266
#define MAX_OBJ_FS
Definition: rawcommn.h:263
#define VERSION_SRAWOBJATTR
Definition: rawcommn.h:259
int iStatusLen
Definition: rawcommn.h:472
int rawCheckClientFile(char *pcFile0, char **pcFile, char **pcTape)
Definition: rawProcn.c:345
int rawTestFileName(char *pcFile)
Definition: rawProcn.c:2188
int rawRecvError(int iSocket, int iLen, char *pcMsg)
Definition: rawProcn.c:1286
static const char * pcStar
Definition: rawdefn.h:64
int iSeekMode
Definition: rawcommn.h:481
int iStatus
Definition: rawcommn.h:471
char * rawGetHLName(char *pcPath)
Definition: rawProcn.c:657
int rawAddStrings(char *pcMsg1, int iMaxLength1, char *pcMsg2, int iMaxLength2, int iErrno, char *pcMsgE, int iMaxLengthE)
Definition: rawProcn.c:180
static char cPath[MAX_FULL_FILE]
Definition: rawProcn.c:165
char cNamefs[MAX_OBJ_FS]
Definition: rawcommn.h:401
int rawSendStatus(int iSocket, int iStatus, char *pcMsg)
Definition: rawProcn.c:2113
int rawQueryFile(int iSocket, int iAltMaster, srawComm *pCommBuf, void **pQueryBuf)
Definition: rawProcn.c:946
#define MAX_TAPE_FILE
Definition: rawcommn.h:257
int rawGetLLName(char *pcFile, const char *pcDelimiter, char *pcObject)
Definition: rawProcn.c:736
int iStatusLen
Definition: rawcommn.h:480
int iPoolId
Definition: rawcommn.h:543
#define IDENT_QUERY_ARCHDB
Definition: rawcommn.h:302
static const char * pcQM
Definition: rawdefn.h:65
char cNamefs[MAX_OBJ_FS]
Definition: rawcommn.h:522
int rawRecvHeadC(int iSocket, char *pcBuf, int iIdentReq, int iStatusReq, char *pcMsg)
Definition: rawProcn.c:1495
int rawSendRequest(int iSocket, int iSeekMode, int iOffset, int iBufferSize)
Definition: rawProcn.c:2043
int iATLServer
Definition: rawcommn.h:422
#define IDENT_QUERY
Definition: rawcommn.h:291
static const char * pcPerc
Definition: rawdefn.h:66
#define MAX_FULL_FILE
Definition: rawcommn.h:255
static int iObjAttr
Definition: rawProcn.c:171
int rawRecvHead(int iSocket, char *pcBuf)
Definition: rawProcn.c:1398
static char cNamefs[MAX_OBJ_FS]
Definition: rawProcn.c:166
#define STATUS_LEN
Definition: rawcommn.h:284
int iIdent
Definition: rawcommn.h:478
#define IDENT_QUERY_DONE
Definition: rawcommn.h:307
int iCommLen
Definition: rawcommn.h:400
char * rawGetPathName(char *pcNamehl)
Definition: rawProcn.c:901
static char cNamehl[MAX_OBJ_HL]
Definition: rawProcn.c:167
char cNamell[MAX_OBJ_LL]
Definition: rawcommn.h:524
#define HEAD_LEN
Definition: rawcommn.h:283
char cNamell[MAX_OBJ_LL]
Definition: rawcommn.h:403
static char * pcNull
Definition: rawProcn.c:168
int rawRecvRequest(int iSocket, int *piSeekMode, int *piOffset, int *piBufferSize)
Definition: rawProcn.c:1695
bool_t
Definition: rawapitd.h:28
int rawGetFileSize(char *pcFile, unsigned long *piSize, unsigned int *piRecl)
Definition: rawProcn.c:787
FILE * fLogFile
Definition: rawapin.c:185
int iStatus
Definition: rawcommn.h:479
#define IDENT_NEXT_BUFFER
Definition: rawcommn.h:294
#define IDENT_STATUS
Definition: rawcommn.h:290
char cStatus[STATUS_LEN]
Definition: rawcommn.h:473
#define MAX_OBJ_HL
Definition: rawcommn.h:265
char * rawGetFSpName(char *pcUser)
Definition: rawProcn.c:600
static const char * pcDevDelim
Definition: rawdefn.h:31
static int iATLServer
Definition: rawapin.c:214
char cOwner[MAX_OWNER]
Definition: rawcommn.h:404
char cNamehl[MAX_OBJ_HL]
Definition: rawcommn.h:402