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