2005-04-15 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / g10 / tdbio.h
blob708e06d2b85da35c88efbb029190a0043d86a19e
1 /* tdbio.h - Trust database I/O functions
2 * Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation, Inc.
4 * This file is part of GnuPG.
6 * GnuPG is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * GnuPG is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 #ifndef G10_TDBIO_H
22 #define G10_TDBIO_H
24 #include "host2net.h"
26 #define TRUST_RECORD_LEN 40
27 #define SIGS_PER_RECORD ((TRUST_RECORD_LEN-10)/5)
28 #define ITEMS_PER_HTBL_RECORD ((TRUST_RECORD_LEN-2)/4)
29 #define ITEMS_PER_HLST_RECORD ((TRUST_RECORD_LEN-6)/5)
30 #define ITEMS_PER_PREF_RECORD (TRUST_RECORD_LEN-10)
31 #if ITEMS_PER_PREF_RECORD % 2
32 #error ITEMS_PER_PREF_RECORD must be even
33 #endif
34 #define MAX_LIST_SIGS_DEPTH 20
37 #define RECTYPE_VER 1
38 #define RECTYPE_HTBL 10
39 #define RECTYPE_HLST 11
40 #define RECTYPE_TRUST 12
41 #define RECTYPE_VALID 13
42 #define RECTYPE_FREE 254
45 struct trust_record {
46 int rectype;
47 int mark;
48 int dirty; /* for now only used internal by functions */
49 struct trust_record *next; /* help pointer to build lists in memory */
50 ulong recnum;
51 union {
52 struct { /* version record: */
53 byte version; /* should be 3 */
54 byte marginals;
55 byte completes;
56 byte cert_depth;
57 byte trust_model;
58 ulong created; /* timestamp of trustdb creation */
59 ulong nextcheck; /* timestamp of next scheduled check */
60 ulong reserved;
61 ulong reserved2;
62 ulong firstfree;
63 ulong reserved3;
64 ulong trusthashtbl;
65 } ver;
66 struct { /* free record */
67 ulong next;
68 } free;
69 struct {
70 ulong item[ITEMS_PER_HTBL_RECORD];
71 } htbl;
72 struct {
73 ulong next;
74 ulong rnum[ITEMS_PER_HLST_RECORD]; /* of another record */
75 } hlst;
76 struct {
77 byte fingerprint[20];
78 byte ownertrust;
79 byte depth;
80 ulong validlist;
81 byte min_ownertrust;
82 } trust;
83 struct {
84 byte namehash[20];
85 ulong next;
86 byte validity;
87 byte full_count;
88 byte marginal_count;
89 } valid;
90 } r;
92 typedef struct trust_record TRUSTREC;
94 /*-- tdbio.c --*/
95 int tdbio_update_version_record(void);
96 int tdbio_set_dbname( const char *new_dbname, int create );
97 const char *tdbio_get_dbname(void);
98 void tdbio_dump_record( TRUSTREC *rec, FILE *fp );
99 int tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected );
100 int tdbio_write_record( TRUSTREC *rec );
101 int tdbio_db_matches_options(void);
102 byte tdbio_read_model(void);
103 ulong tdbio_read_nextcheck (void);
104 int tdbio_write_nextcheck (ulong stamp);
105 int tdbio_is_dirty(void);
106 int tdbio_sync(void);
107 int tdbio_begin_transaction(void);
108 int tdbio_end_transaction(void);
109 int tdbio_cancel_transaction(void);
110 int tdbio_delete_record( ulong recnum );
111 ulong tdbio_new_recnum(void);
112 int tdbio_search_trust_byfpr(const byte *fingerprint, TRUSTREC *rec );
113 int tdbio_search_trust_bypk(PKT_public_key *pk, TRUSTREC *rec );
115 void tdbio_invalid(void);
117 #endif /*G10_TDBIO_H*/