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