2007-07-05 Marcus Brinkmann <marcus@g10code.de>
[gnupg.git] / g10 / tdbio.h
blobd6af98fd0bd90b7b2d2b542b8dff048520418027
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 3 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, see <http://www.gnu.org/licenses/>.
20 #ifndef G10_TDBIO_H
21 #define G10_TDBIO_H
23 #include "host2net.h"
25 #define TRUST_RECORD_LEN 40
26 #define SIGS_PER_RECORD ((TRUST_RECORD_LEN-10)/5)
27 #define ITEMS_PER_HTBL_RECORD ((TRUST_RECORD_LEN-2)/4)
28 #define ITEMS_PER_HLST_RECORD ((TRUST_RECORD_LEN-6)/5)
29 #define ITEMS_PER_PREF_RECORD (TRUST_RECORD_LEN-10)
30 #if ITEMS_PER_PREF_RECORD % 2
31 #error ITEMS_PER_PREF_RECORD must be even
32 #endif
33 #define MAX_LIST_SIGS_DEPTH 20
36 #define RECTYPE_VER 1
37 #define RECTYPE_HTBL 10
38 #define RECTYPE_HLST 11
39 #define RECTYPE_TRUST 12
40 #define RECTYPE_VALID 13
41 #define RECTYPE_FREE 254
44 struct trust_record {
45 int rectype;
46 int mark;
47 int dirty; /* for now only used internal by functions */
48 struct trust_record *next; /* help pointer to build lists in memory */
49 ulong recnum;
50 union {
51 struct { /* version record: */
52 byte version; /* should be 3 */
53 byte marginals;
54 byte completes;
55 byte cert_depth;
56 byte trust_model;
57 ulong created; /* timestamp of trustdb creation */
58 ulong nextcheck; /* timestamp of next scheduled check */
59 ulong reserved;
60 ulong reserved2;
61 ulong firstfree;
62 ulong reserved3;
63 ulong trusthashtbl;
64 } ver;
65 struct { /* free record */
66 ulong next;
67 } free;
68 struct {
69 ulong item[ITEMS_PER_HTBL_RECORD];
70 } htbl;
71 struct {
72 ulong next;
73 ulong rnum[ITEMS_PER_HLST_RECORD]; /* of another record */
74 } hlst;
75 struct {
76 byte fingerprint[20];
77 byte ownertrust;
78 byte depth;
79 ulong validlist;
80 byte min_ownertrust;
81 } trust;
82 struct {
83 byte namehash[20];
84 ulong next;
85 byte validity;
86 byte full_count;
87 byte marginal_count;
88 } valid;
89 } r;
91 typedef struct trust_record TRUSTREC;
93 /*-- tdbio.c --*/
94 int tdbio_update_version_record(void);
95 int tdbio_set_dbname( const char *new_dbname, int create );
96 const char *tdbio_get_dbname(void);
97 void tdbio_dump_record( TRUSTREC *rec, FILE *fp );
98 int tdbio_read_record( ulong recnum, TRUSTREC *rec, int expected );
99 int tdbio_write_record( TRUSTREC *rec );
100 int tdbio_db_matches_options(void);
101 byte tdbio_read_model(void);
102 ulong tdbio_read_nextcheck (void);
103 int tdbio_write_nextcheck (ulong stamp);
104 int tdbio_is_dirty(void);
105 int tdbio_sync(void);
106 int tdbio_begin_transaction(void);
107 int tdbio_end_transaction(void);
108 int tdbio_cancel_transaction(void);
109 int tdbio_delete_record( ulong recnum );
110 ulong tdbio_new_recnum(void);
111 int tdbio_search_trust_byfpr(const byte *fingerprint, TRUSTREC *rec );
112 int tdbio_search_trust_bypk(PKT_public_key *pk, TRUSTREC *rec );
114 void tdbio_invalid(void);
116 #endif /*G10_TDBIO_H*/