home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume22 / nn6.4 / part20 / db.h < prev    next >
Encoding:
C/C++ Source or Header  |  1990-06-07  |  2.8 KB  |  108 lines

  1. /*
  2.  *    (c) Copyright 1990, Kim Fabricius Storm.  All rights reserved.
  3.  *
  4.  *    DATABASE ORGANIZATION:
  5.  *
  6.  *    The central nn information is contained in following files:
  7.  *        DB_DIRECTORY/MASTER
  8.  *        DB_DIRECTORY/GROUPS
  9.  *        DB_DIRECTORY/DATA/nnn.x
  10.  *        DB_DIRECTORY/DATA/nnn.d
  11.  *
  12.  *     The MASTER file consists of a header and one entry for each news
  13.  *    group.  The sequence of the group headers defines the group
  14.  *    number associated with the group.
  15.  *
  16.  *     The GROUPS file contains the names of the news groups; the names
  17.  *    occur in the same sequence as in the MASTER file.
  18.  *
  19.  *    For each news group, the DATA directory contains two files whose
  20.  *    name is constructed from the group number 'nnn':
  21.  *
  22.  *        nnn.x    Index file
  23.  *        nnn.d    Data file
  24.  *
  25.  *    The index file provides a a mapping from article numbers to offsets
  26.  *    in the data file.
  27.  *
  28.  *    The data file contains the actual header data.  Each article is
  29.  *    represented by a Header, an array of Cross Postings, and the
  30.  *    strings representing the sender name and the article subject:
  31.  *
  32.  *        header
  33.  *        group_number 1 [ if cross posted ]
  34.  *        group_number 2
  35.  *        ...
  36.  *        sender name (null terminated) [if sender_length > 0]
  37.  *        subject (null terminated) [if subject_length > 0]
  38.  *
  39.  *    For a digest, cross posted groups are only specified for the
  40.  *    first entry (the header entry).
  41.  *
  42.  *    On disk, the article_number is negative for digest article
  43.  *    header and zero for following sub articles.
  44.  *
  45.  *    The format of the index and data files are specified below.
  46.  *
  47.  *    Unless NETWORK_DATABASE is defined, the database will
  48.  *    will contain machine dependent binary data.
  49.  */
  50.  
  51. #ifdef NETWORK_DATABASE
  52. typedef int32 cross_post_number;
  53. #ifdef NETWORK_BYTE_ORDER
  54. #define NETW_CROSS_INT(cp) cp
  55. #define NETW_CROSS_EXT(cp) cp
  56. #else
  57. #define NETW_CROSS_INT(cp) ntohl(cp)
  58. #define NETW_CROSS_EXT(cp) htonl(cp)
  59. #endif
  60. #else
  61. typedef group_number cross_post_number;
  62. #define NETW_CROSS_INT(cp) cp
  63. #define NETW_CROSS_EXT(cp) cp
  64. #endif
  65.  
  66. typedef struct {
  67.     article_number    dh_number;
  68.  
  69.     time_stamp    dh_date; /* encoded Date: filed (not a time_t value!!) */
  70.  
  71.     off_t    dh_hpos; /* absolute offset for first byte of header */
  72.     off_t    dh_lpos; /* absolute offset for last byte of article */
  73.     int16    dh_fpos; /* relative offset for first byte in article text */
  74.  
  75.     int16    dh_lines;
  76.     int8    dh_replies;
  77.  
  78.     int8    dh_cross_postings;
  79.     int8    dh_subject_length;
  80.     int8    dh_sender_length;
  81. } data_header;
  82.  
  83. #define DBUF_SIZE    255
  84.  
  85. typedef struct {
  86.     int            dh_type;
  87.  
  88. #define    DH_NORMAL        0
  89. #define    DH_DIGEST_HEADER    1
  90. #define DH_SUB_DIGEST        2
  91.  
  92.     cross_post_number    dh_cross[DBUF_SIZE+1];
  93.     char        dh_sender[DBUF_SIZE+1];
  94.     char        dh_subject[DBUF_SIZE+1];
  95. } data_dynamic_data;
  96.  
  97.  
  98. /* open database files */
  99.  
  100. FILE *open_data_file();
  101.  
  102. /* data access */
  103.  
  104. off_t get_index_offset(), get_data_offset();
  105.  
  106. extern data_header db_hdr;
  107. extern data_dynamic_data db_data;
  108.