600127f0 |
1 | /* -*-c-*- |
2 | * |
600127f0 |
3 | * Framework for checking consistency of keys |
4 | * |
5 | * (c) 2001 Straylight/Edgeware |
6 | */ |
7 | |
45c0fd36 |
8 | /*----- Licensing notice --------------------------------------------------* |
600127f0 |
9 | * |
10 | * This file is part of Catacomb. |
11 | * |
12 | * Catacomb is free software; you can redistribute it and/or modify |
13 | * it under the terms of the GNU Library General Public License as |
14 | * published by the Free Software Foundation; either version 2 of the |
15 | * License, or (at your option) any later version. |
45c0fd36 |
16 | * |
600127f0 |
17 | * Catacomb is distributed in the hope that it will be useful, |
18 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
19 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
20 | * GNU Library General Public License for more details. |
45c0fd36 |
21 | * |
600127f0 |
22 | * You should have received a copy of the GNU Library General Public |
23 | * License along with Catacomb; if not, write to the Free |
24 | * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, |
25 | * MA 02111-1307, USA. |
26 | */ |
27 | |
600127f0 |
28 | #ifndef CATACOMB_KEYCHECK_H |
29 | #define CATACOMB_KEYCHECK_H |
30 | |
31 | #ifdef __cplusplus |
32 | extern "C" { |
33 | #endif |
34 | |
35 | /*----- Header files ------------------------------------------------------*/ |
36 | |
37 | #ifndef CATACOMB_MP_H |
38 | # include "mp.h" |
39 | #endif |
40 | |
41 | /*----- Data structures ---------------------------------------------------*/ |
42 | |
43 | enum { |
44 | KCSEV_ALL, |
45 | KCSEV_INFO = KCSEV_ALL, |
46 | KCSEV_WARN, |
47 | KCSEV_ERR, |
48 | KCSEV_MAX |
49 | }; |
50 | |
51 | typedef struct keycheck { |
52 | unsigned sev[KCSEV_MAX]; |
53 | int (*func)(unsigned /*sev*/, const char */*msg*/, void */*p*/); |
54 | void *p; |
55 | } keycheck; |
56 | |
57 | typedef struct keycheck_reportctx { |
58 | FILE *fp; |
59 | unsigned sev; |
60 | } keycheck_reportctx; |
61 | |
62 | /*----- Generic functions -------------------------------------------------*/ |
63 | |
64 | /* --- @keycheck_report@ --- * |
65 | * |
66 | * Arguments: @keycheck *kc@ = keycheck state |
67 | * @unsigned sev@ = severity of this report |
68 | * @const char *msg@ = message to send along |
69 | * @...@ = things to fill the message in with |
70 | * |
71 | * Returns: Zero to continue, or nonzero to stop and give up. |
72 | * |
73 | * Use: Reports a message to the user function. |
74 | */ |
75 | |
76 | extern int keycheck_report(keycheck */*kc*/, unsigned /*sev*/, |
77 | const char */*msg*/, ...); |
78 | |
79 | /* --- @keycheck_init@ --- * |
80 | * |
81 | * Arguments: @keycheck *kc@ = pointer to block to initialize |
82 | * @int (*func)(unsigned sev, const char *msg, void *p)@ = |
83 | * handler function for problems |
84 | * @void *p@ = pointer to give to handler |
85 | * |
86 | * Returns: --- |
87 | * |
88 | * Use: Initializes a key checking context. |
89 | */ |
90 | |
91 | extern void keycheck_init(keycheck */*kc*/, |
92 | int (*/*func*/)(unsigned /*sev*/, |
93 | const char */*msg*/, |
94 | void */*p*/), |
95 | void */*p*/); |
96 | |
97 | /* --- @keycheck_allclear@ --- * |
98 | * |
99 | * Arguments: @keycheck *kc@ = pointer to keycheck context |
100 | * @unsigned sev@ = minimum severity to care about |
101 | * |
102 | * Returns: Nonzero if no problems of @sev@ or above were noticed. |
103 | */ |
104 | |
105 | extern int keycheck_allclear(keycheck */*kc*/, unsigned /*sev*/); |
106 | |
107 | /*----- A standard report function ----------------------------------------*/ |
108 | |
109 | /* --- @keycheck_stdreport@ --- * |
110 | * |
111 | * Arguments: @unsigned sev@ = problem severity |
112 | * @const char *msg@ = message to report |
113 | * @void *p@ = pointer to a @keycheck_reportctx@ structure |
114 | * |
115 | * Returns: Zero. |
116 | * |
117 | * Use: Reports a message to stderr. |
118 | */ |
119 | |
120 | extern int keycheck_stdreport(unsigned /*sev*/, |
121 | const char */*msg*/, void */*p*/); |
122 | |
123 | /*----- Special support functions for large integers ----------------------*/ |
124 | |
125 | /* --- @keycheck_prime@ --- * |
126 | * |
127 | * Arguments: @keycheck *kc@ = keycheck state |
128 | * @unsigned sev@ = severity if not prime |
129 | * @mp *m@ = a number to check for primality |
130 | * @const char *name@ = name of this number |
131 | * |
132 | * Returns: Zero if OK, or return status from function. |
133 | * |
134 | * Use: Checks that a number is prime. |
135 | */ |
136 | |
137 | extern int keycheck_prime(keycheck */*kc*/, unsigned /*sev*/, |
138 | mp */*m*/, const char */*name*/); |
139 | |
140 | /*----- That's all, folks -------------------------------------------------*/ |
141 | |
142 | #ifdef __cplusplus |
143 | } |
144 | #endif |
145 | |
146 | #endif |