1 //  This may look like C code, but it is really -*- C++ -*-
2 
3 //  ------------------------------------------------------------------
4 //  The Goldware Library
5 //  Copyright (C) 1990-1999 Odinn Sorensen
6 //  ------------------------------------------------------------------
7 //  This library is free software; you can redistribute it and/or
8 //  modify it under the terms of the GNU Library General Public
9 //  License as published by the Free Software Foundation; either
10 //  version 2 of the License, or (at your option) any later version.
11 //
12 //  This library is distributed in the hope that it will be useful,
13 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 //  Library General Public License for more details.
16 //
17 //  You should have received a copy of the GNU Library General Public
18 //  License along with this program; if not, write to the Free
19 //  Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
20 //  MA 02111-1307, USA
21 //  ------------------------------------------------------------------
22 //  $Id: gftnnlv7.h,v 1.1.1.1 2000/02/25 10:12:00 asa Exp $
23 //  ------------------------------------------------------------------
24 //  Version 7 nodelist index.
25 //  Derived from the Binkley 2.50 source code.
26 //  V7+ support based on draft #2 by Thomas Waldmann.
27 //  ------------------------------------------------------------------
28 
29 #ifndef __gftnnlv7_h
30 #define __gftnnlv7_h
31 
32 
33 //  ------------------------------------------------------------------
34 
35 #include <gftnnl.h>
36 
37 
38 //  -------------------------------------------------------------------
39 //  Version 7 Nodelist Index structure. This is a 512-byte record,
40 //  which is defined by three structures: Record 0 is the Control
41 //  Record, then some number of Leaf Node (LNode) Records, then the
42 //  Index Node (INode) Records. This defines an unbalanced binary
43 //  tree.
44 //
45 //  This description is based on Scott Samet's CBTREE.PAS program.
46 //
47 //  Used for NODEX.NDX and SYSOP.NDX
48 //  ------------------------------------------------------------------
49 
50 
51 #if defined(GOLD_CANPACK)
52 #pragma pack(1)
53 #endif
54 
55 //  ------------------------------------------------------------------
56 //  Index Node records
57 
58 struct _V7IndxRef {
59 
60   word  indxofs;    // Offset of string into block
61   word  indxlen;    // Length of string
62   long  indxdata;   // Record number of string
63   long  indxptr;    // Block number of lower index
64 };
65 
66 
67 //  ------------------------------------------------------------------
68 //  Leaf Node records
69 
70 struct _V7LeafRef {
71 
72   word  keyofs;   // Offset of string into block
73   word  keylen;   // Length of string
74   long  keyval;   // Pointer to data block
75 };
76 
77 
78 //  ------------------------------------------------------------------
79 //  Index records
80 
81 struct _V7Ndx {
82 
83   union {
84 
85     // Control Record
86     struct {
87       word        ctlblksize;   // Blocksize of Index Blocks
88       long        ctlroot;      // Block number of Root
89       long        ctlhiblk;     // Block number of last block
90       long        ctlloleaf;    // Block number of first leaf
91       long        ctlhileaf;    // Block number of last leaf
92       long        ctlfree;      // Head of freelist
93       word        ctllvls;      // Number of index levels
94       word        ctlparity;    // XOR of above fields
95     } ctlblk;
96 
97     // Index Node records
98     struct {
99       long        indxfirst;    // Pointer to next lower level
100       long        indxblink;    // Pointer to previous link
101       long        indxflink;    // Pointer to next link
102       short       indxcnt;      // Count of Items in block
103       word        indxstr;      // Offset in block of 1st str
104       _V7IndxRef  indxref[20];  // If IndxFirst is not -1, this is INode
105     } inodeblk;
106 
107     // Leaf Node records
108     struct {
109       long        indxfirst;    // Pointer to next lower level (is -1 in LNodes)
110       long        indxblink;    // Pointer to previous link
111       long        indxflink;    // Pointer to next link
112       short       indxcnt;      // Count of Items in block
113       word        indxstr;      // Offset in block of 1st str
114       _V7LeafRef  leafref[30];
115     } lnodeblk;
116 
117     // Raw index data
118     char rawndx[512];
119 
120   } ndx;
121 };
122 
123 
124 //  ------------------------------------------------------------------
125 //  OPUS 1.20 Version 7 Nodelist structure.
126 //  Copyright 1991 Wynn Wagner III and Doug Boone.
127 
128 struct _V7Data {
129 
130   word zone;           // Zone
131   word net;            // Net
132   word node;           // Node
133   word hubnode;        // Point (if nodeflags&V7_B_point) or hubnode number
134   word callcost;       // Phone company's charge
135   word msgfee;         // Amount charged to user for a message
136   word nodeflags;      // Set of flags (see below)
137   byte modemtype;      // RESERVED for modem type
138   byte phone_len;      // Length of phone number
139   byte password_len;   // Length of password
140   byte bname_len;      // Length of system name
141   byte sname_len;      // Length of sysop name
142   byte cname_len;      // Length of location
143   byte pack_len;       // Length of packed data
144   byte baudrate;       // baud rate divided by 300
145 };
146 
147 
148 //  ------------------------------------------------------------------
149 //  Values for the `_V7Data.nodeflags' field
150 //  ------------------------------------------------------------------
151 
152 #define V7_B_Hub    0x0001  // node is a net hub     00000000 00000001
153 #define V7_B_Host   0x0002  // node is a net host    00000000 00000010
154 #define V7_B_Region 0x0004  // node is region coord  00000000 00000100
155 #define V7_B_Zone   0x0008  // is a zone gateway     00000000 00001000
156 #define V7_B_CM     0x0010  // runs continuous mail  00000000 00010000
157 #define V7_B_Res1   0x0020  // reserved by Opus      00000000 00100000
158 #define V7_B_Res2   0x0040  // reserved by Opus      00000000 01000000
159 #define V7_B_Res3   0x0080  // reserved by Opus      00000000 10000000
160 
161 #define V7_B_Res4   0x0100  // reserved by Opus      00000001 00000000
162 #define V7_B_Res5   0x0200  // reserved for non-Opus 00000010 00000000
163 #define V7_B_Res6   0x0400  // reserved for non-Opus 00000100 00000000
164 #define V7_B_Res7   0x0800  // reserved for non-Opus 00001000 00000000
165 #define V7_B_Point  0x1000  // node is a point       00010000 00000000
166 #define V7_B_Res9   0x2000  // reserved for non-Opus 00100000 00000000
167 #define V7_B_Res10  0x4000  // reserved for non-Opus 01000000 00000000
168 #define V7_B_Plus   0x8000  // V7+ field length list 10000000 00000000
169 
170 #define V7_Hub     0
171 #define V7_Host    1
172 #define V7_Region  2
173 #define V7_Zone    3
174 #define V7_CM      4
175 #define V7_Res1    5
176 #define V7_Res2    6
177 #define V7_Res3    7
178 
179 #define V7_Res4    8
180 #define V7_Res5    9
181 #define V7_Res6   10
182 #define V7_Res7   11
183 #define V7_Point  12
184 #define V7_Res9   13
185 #define V7_Res10  14
186 #define V7_Plus   15
187 
188 
189 //  ------------------------------------------------------------------
190 
191 struct _V7Stk {
192   long  blockno;
193   int   node;
194 };
195 
196 
197 //  ------------------------------------------------------------------
198 
199 struct _V7DTPCtl {
200   word size;           // Size of this control structure
201   byte Version;        // Version of DTP file (current = 0)
202   byte AllFixSize;     // sizeof (_V7DTPAllLnk)
203   byte AddFixSize;     // sizeof (_V7DTPNodeLnk)
204 };
205 
206 #if defined(GOLD_CANPACK)
207 #pragma pack()
208 #endif
209 
210 
211 //  ------------------------------------------------------------------
212 
213 class ftn_version7_nodelist_index : public ftn_nodelist_index_base {
214 
215   int       nfh;
216   int       sfh;
217   int       dfh;
218   int       xfh;
219   int       tfh;
220 
221   _V7Ndx    ctl;
222   _V7Ndx    block;
223   _V7DTPCtl dtpctl;
224 
225   int       node;
226   int       inode;
227   long      blockno;
228   bool      use_v7plus;
229 
230   char      key[160];
231   uint      keylength;
232 
233   _V7Stk    state;
234 
235   char      searchname[80];
236   ftn_addr  searchaddr;
237 
238   void      getindexkey();
239   void      getleafkey();
240   void      getblock();
241   void      getleaf();
242 
243   const char*     namekey() const;
244   const ftn_addr& addrkey() const;
245 
246   int       namecmp() const;
247   int       addrcmp() const;
248 
249   void      fetchdata();
250 
251   void      push();
252   void      pop();
253   bool      prevnode();
254   bool      nextnode();
compare()255   void      compare()           { exactmatch = not (namebrowse ? namecmp() : addrcmp()); }
256   bool      search();
257 
258 public:
259 
260   ftn_version7_nodelist_index();
261   virtual ~ftn_version7_nodelist_index();
262 
can_browse_name()263   bool can_browse_name() const     { return true; }
can_browse_address()264   bool can_browse_address() const  { return true; }
265 
266   bool open();
267   void close();
268 
269   bool find(const char* name);
270   bool find(const ftn_addr& addr);
271 
272   bool previous();
273   bool next();
274 
275   void first();
276   void last();
277 
278   void push_state();
279   void pop_state();
280 
281   const char* index_name() const;
282   const char* nodelist_name() const;
283 
284 };
285 
286 
287 //  ------------------------------------------------------------------
288 
289 #endif
290 
291 //  ------------------------------------------------------------------
292