home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / misc / volume34 / fsp / part03 / common_def.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-12-18  |  5.0 KB  |  105 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 <errno.h>
  14. #include <sys/socket.h>
  15. #include <netinet/in.h>
  16. #include <sys/stat.h>
  17. #include <sys/time.h>
  18. #include <fcntl.h>
  19. #include <signal.h>
  20.  
  21. #ifdef DIRENT
  22. #include <dirent.h>
  23. #else
  24. #include <sys/dir.h>
  25. #endif
  26.  
  27. /****************************************************************************
  28. *  UBUF is the structure of message exchanged between server and clients. 
  29. *
  30. *    The 'buf' part of the buffer is variable lenght up to max of 1024.
  31. *    The 'key' field is used by the server for sequence identification.
  32. *    The 'seq' field is used by the client for sequence identification.
  33. *
  34. *  Client's message to server contain a key value that is the same as the
  35. *  key value of the previous message received from the server.  Similarly,
  36. *  the server's message to client contains a seq value that is the same
  37. *  as the seq value of the previous message from the client. 
  38. *
  39. *  The buf field is logically partitioned into two parts by the len field.
  40. *  The len field indicate the size of the first part of the buffer starting
  41. *  at buf[0].  The rest of the buffer is the second field.  In some cases
  42. *  both fields can contain information.
  43. *
  44. ****************************************************************************/
  45.  
  46. #define UBUF_HSIZE 12                           /* 12 bytes for the header */
  47. #define UBUF_SPACE 1024                    /* maximum payload.        */
  48.  
  49. typedef struct UBUF {            char   cmd;  /* message code.             */
  50.                         unsigned char   sum;  /* message checksum.         */
  51.                         unsigned short  key;  /* message key.              */
  52.                         unsigned short  seq;  /* message sequence number.  */
  53.                         unsigned short  len;  /* number of bytes in buf 1. */
  54.                         unsigned long   pos;  /* location in the file.     */
  55.  
  56.                         char   buf[UBUF_SPACE];
  57.                     } UBUF;
  58.  
  59. /* definition of cmd */
  60.  
  61. #define CC_VERSION    0x10    /* return server's version string.    */
  62. #define CC_ERR          0x40    /* error response from server.          */
  63. #define CC_GET_DIR      0x41    /* get a directory listing.             */
  64. #define CC_GET_FILE     0x42    /* get a file.                          */
  65. #define CC_UP_LOAD      0x43    /* open a file for writing.             */
  66. #define CC_INSTALL      0x44    /* close a file opened for writing.     */
  67. #define CC_DEL_FILE     0x45    /* delete a file.                       */
  68. #define CC_DEL_DIR      0x46    /* delete a directory.                  */
  69. #define CC_GET_PRO      0x47    /* get directory protection.            */
  70. #define CC_SET_PRO      0x48    /* set directory protection.            */
  71. #define CC_MAKE_DIR     0x49    /* create a directory.                  */
  72. #define CC_BYE          0x4A    /* finish a session.                    */
  73. #define CC_GRAB_FILE    0x4B    /* atomic get+delete a file.        */
  74. #define CC_GRAB_DONE    0x4C    /* atomic get+delete a file done.    */
  75. #define CC_LIMIT    0x80    /* # > 0x7f for future cntrl blk ext.   */
  76.  
  77. /****************************************************************************
  78. *  RDIRENT is the structure of a directory entry contained in a .FSP_CONTENT
  79. *  file.  Each entry contains a 4 bytes quantity 'time', a 4 bytes quentity
  80. *  'size', and 1 byte of 'type'.  Then followed by x number of bytes of
  81. *  'name'.  'name' is null terminated.  Then followed by enough number of
  82. *  padding to fill to an 4-byte boundary.  At this point, if the next entry
  83. *  to follow will spread across 1k boundary, then two possible things will
  84. *  happen.  1) if the header fits between this entry and the 1k boundary,
  85. *  a complete header will be filled in with a 'type' set to RDTYPE_SKIP.
  86. *  And then enough bytes to padd to 1k boundary.  2) if the header does
  87. *  not fit, then simply pad to the 1k boundary.  This will make sure that
  88. *  messages carrying directory information carry only complete directory
  89. *  entries and no fragmented entries.  The last entry is type RDTYPE_END.
  90. ****************************************************************************/
  91.  
  92. #define RDHSIZE (2*sizeof(unsigned long)+sizeof(unsigned char))
  93.  
  94. typedef struct RDIRENT { unsigned long  time;
  95.                          unsigned long  size;
  96.                          unsigned char  type;
  97.                          char        name[1]; } RDIRENT;
  98.  
  99. #define RDTYPE_END      0x00
  100. #define RDTYPE_FILE     0x01
  101. #define RDTYPE_DIR      0x02
  102. #define RDTYPE_SKIP     0x2A
  103.  
  104. #define NULLP ((char *) 0)
  105.