home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / fsp / part02 / common_def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1991-12-12  |  4.8 KB  |  97 lines

  1.     /*********************************************************************\
  2.     *  Copyright (c) 1991 by Wen-King Su (wen-king@vlsi.cs.caltech.edu)   *
  3.     *                                                                     *
  4.     *  You may copy or modify this file in any manner you wish, provided  *
  5.     *  that this notice is always included, and that you hold the author  *
  6.     *  harmless for any loss or damage resulting from the installation or *
  7.     *  use of this software.                                              *
  8.     \*********************************************************************/
  9.  
  10. #include <stdio.h>
  11. #include <sys/param.h>
  12. #include <sys/types.h>
  13. #include <dirent.h>
  14. #include <errno.h>
  15. #include <sys/socket.h>
  16. #include <netinet/in.h>
  17. #include <sys/stat.h>
  18. #include <sys/time.h>
  19. #include <fcntl.h>
  20. #include <signal.h>
  21.  
  22. /****************************************************************************
  23. *  UBUF is the structure of message exchanged between server and clients. 
  24. *
  25. *    The 'buf' part of the buffer is variable lenght up to max of 1024.
  26. *    The 'key' field is used by the server for sequence identification.
  27. *    The 'seq' field is used by the client for sequence identification.
  28. *
  29. *  Client's message to server contain a key value that is the same as the
  30. *  key value of the previous message received from the server.  Similarly,
  31. *  the server's message to client contains a seq value that is the same
  32. *  as the seq value of the previous message from the client. 
  33. *
  34. *  The buf field is logically partitioned into two parts by the len field.
  35. *  The len field indicate the size of the first part of the buffer starting
  36. *  at buf[0].  The rest of the buffer is the second field.  In some cases
  37. *  both fields can contain information.
  38. *
  39. ****************************************************************************/
  40.  
  41. #define UBUF_HSIZE 12                           /* 12 bytes for the header */
  42. #define UBUF_SPACE 1024                    /* maximum payload.        */
  43.  
  44. typedef struct UBUF {            char   cmd;  /* message code.             */
  45.                         unsigned char   sum;  /* message checksum.         */
  46.                         unsigned short  key;  /* message key.              */
  47.                         unsigned short  seq;  /* message sequence number.  */
  48.                         unsigned short  len;  /* number of bytes in buf 1. */
  49.                         unsigned long   pos;  /* location in the file.     */
  50.  
  51.                         char   buf[UBUF_SPACE];
  52.                     } UBUF;
  53.  
  54. /* definition of cmd */
  55.  
  56. #define CC_VERSION    0x10    /* return server's version string.    */
  57. #define CC_ERR          0x40    /* error response from server.          */
  58. #define CC_GET_DIR      0x41    /* get a directory listing.             */
  59. #define CC_GET_FILE     0x42    /* get a file.                          */
  60. #define CC_UP_LOAD      0x43    /* open a file for writing.             */
  61. #define CC_INSTALL      0x44    /* close a file opened for writing.     */
  62. #define CC_DEL_FILE     0x45    /* delete a file.                       */
  63. #define CC_DEL_DIR      0x46    /* delete a directory.                  */
  64. #define CC_GET_PRO      0x47    /* get directory protection.            */
  65. #define CC_SET_PRO      0x48    /* set directory protection.            */
  66. #define CC_MAKE_DIR     0x49    /* create a directory.                  */
  67. #define CC_BYE          0x4A    /* finish a session.                    */
  68.  
  69. /****************************************************************************
  70. *  RDIRENT is the structure of a directory entry contained in a .FSP_CONTENT
  71. *  file.  Each entry contains a 4 bytes quantity 'time', a 4 bytes quentity
  72. *  'size', and 1 byte of 'type'.  Then followed by x number of bytes of
  73. *  'name'.  'name' is null terminated.  Then followed by enough number of
  74. *  padding to fill to an 4-byte boundary.  At this point, if the next entry
  75. *  to follow will spread across 1k boundary, then two possible things will
  76. *  happen.  1) if the header fits between this entry and the 1k boundary,
  77. *  a complete header will be filled in with a 'type' set to RDTYPE_SKIP.
  78. *  And then enough bytes to padd to 1k boundary.  2) if the header does
  79. *  not fit, then simply pad to the 1k boundary.  This will make sure that
  80. *  messages carrying directory information carry only complete directory
  81. *  entries and no fragmented entries.  The last entry is type RDTYPE_END.
  82. ****************************************************************************/
  83.  
  84. #define RDHSIZE (2*sizeof(unsigned long)+sizeof(unsigned char))
  85.  
  86. typedef struct RDIRENT { unsigned long  time;
  87.                          unsigned long  size;
  88.                          unsigned char  type;
  89.                          char        name[1]; } RDIRENT;
  90.  
  91. #define RDTYPE_END      0x00
  92. #define RDTYPE_FILE     0x01
  93. #define RDTYPE_DIR      0x02
  94. #define RDTYPE_SKIP     0x2A
  95.  
  96. #define NULLP ((char *) 0)
  97.