home *** CD-ROM | disk | FTP | other *** search
/ Unix System Administration Handbook 1997 October / usah_oct97.iso / news / nn.tar / nn-6.5.1 / db.h < prev    next >
C/C++ Source or Header  |  1995-04-29  |  3KB  |  115 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. #ifndef _NN_DB_H
  52. #define _NN_DB_H 1
  53.  
  54. #ifdef NETWORK_DATABASE
  55. typedef int32 cross_post_number;
  56. #ifdef NETWORK_BYTE_ORDER
  57. #define NETW_CROSS_INT(cp) cp
  58. #define NETW_CROSS_EXT(cp) cp
  59. #else
  60. #define NETW_CROSS_INT(cp) ntohl(cp)
  61. #define NETW_CROSS_EXT(cp) htonl(cp)
  62. #endif
  63. #else
  64. typedef group_number cross_post_number;
  65. #define NETW_CROSS_INT(cp) cp
  66. #define NETW_CROSS_EXT(cp) cp
  67. #endif
  68.  
  69. typedef struct {
  70.     article_number    dh_number;
  71.  
  72.     time_stamp    dh_date; /* encoded Date: filed (not a time_t value!!) */
  73.  
  74.     off_t    dh_hpos; /* absolute offset for first byte of header */
  75.     off_t    dh_lpos; /* absolute offset for last byte of article */
  76.     int16    dh_fpos; /* relative offset for first byte in article text */
  77.  
  78.     int16    dh_lines;
  79.     int8    dh_replies;
  80.  
  81.     int8    dh_cross_postings;
  82.     int8    dh_subject_length;
  83.     int8    dh_sender_length;
  84. } data_header;
  85.  
  86. #define DBUF_SIZE    255
  87.  
  88. typedef struct {
  89.     int            dh_type;
  90.  
  91. #define    DH_NORMAL        0
  92. #define    DH_DIGEST_HEADER    1
  93. #define DH_SUB_DIGEST        2
  94.  
  95.     cross_post_number    dh_cross[DBUF_SIZE+1];
  96.     char        dh_sender[DBUF_SIZE+1];
  97.     char        dh_subject[DBUF_SIZE+1];
  98. } data_dynamic_data;
  99.  
  100.  
  101. /* open database files */
  102.  
  103. FILE *open_data_file();
  104.  
  105. /* data access */
  106.  
  107. off_t db_read_art();
  108. off_t get_index_offset(), get_data_offset();
  109.  
  110. extern data_header db_hdr;
  111. extern data_dynamic_data db_data;
  112.  
  113. #endif /* _NN_DB_H */
  114.  
  115.