600127f0 |
1 | /* -*-c-*- |
2 | * |
8ca05294 |
3 | * $Id: keycheck.c,v 1.2 2002/01/13 13:49:01 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 | |
30 | /*----- Revision history --------------------------------------------------* |
31 | * |
32 | * $Log: keycheck.c,v $ |
8ca05294 |
33 | * Revision 1.2 2002/01/13 13:49:01 mdw |
34 | * Track @dstr_vputf@ change. |
35 | * |
600127f0 |
36 | * Revision 1.1 2001/02/03 16:08:24 mdw |
37 | * Add consistency checking for public keys. |
38 | * |
39 | */ |
40 | |
41 | /*----- Header files ------------------------------------------------------*/ |
42 | |
43 | #include <stdarg.h> |
44 | |
45 | #include <mLib/dstr.h> |
46 | |
47 | #include "keycheck.h" |
48 | |
49 | /*----- Main code ---------------------------------------------------------*/ |
50 | |
51 | /* --- @keycheck_report@ --- * |
52 | * |
53 | * Arguments: @keycheck *kc@ = keycheck state |
54 | * @unsigned sev@ = severity of this report |
55 | * @const char *msg@ = message to send along |
56 | * @...@ = things to fill the message in with |
57 | * |
58 | * Returns: Zero to continue, or nonzero to stop and give up. |
59 | * |
60 | * Use: Reports a message to the user function. |
61 | */ |
62 | |
63 | int keycheck_report(keycheck *kc, unsigned sev, const char *msg, ...) |
64 | { |
65 | int rc; |
66 | va_list ap; |
67 | dstr d = DSTR_INIT; |
68 | |
69 | kc->sev[sev]++; |
70 | va_start(ap, msg); |
8ca05294 |
71 | dstr_vputf(&d, msg, &ap); |
600127f0 |
72 | va_end(ap); |
73 | rc = kc->func ? kc->func(sev, d.buf, kc->p) : 0; |
74 | dstr_destroy(&d); |
75 | return (rc); |
76 | } |
77 | |
78 | /* --- @keycheck_init@ --- * |
79 | * |
80 | * Arguments: @keycheck *kc@ = pointer to block to initialize |
81 | * @int (*func)(unsigned sev, const char *msg, void *p)@ = |
82 | * handler function for problems |
83 | * @void *p@ = pointer to give to handler |
84 | * |
85 | * Returns: --- |
86 | * |
87 | * Use: Initializes a key checking context. |
88 | */ |
89 | |
90 | void keycheck_init(keycheck *kc, |
91 | int (*func)(unsigned /*sev*/, |
92 | const char */*msg*/, |
93 | void */*p*/), |
94 | void *p) |
95 | { |
96 | unsigned i; |
97 | kc->func = func; |
98 | kc->p = p; |
99 | for (i = 0; i < KCSEV_MAX; i++) |
100 | kc->sev[i] = 0; |
101 | } |
102 | |
103 | /* --- @keycheck_allclear@ --- * |
104 | * |
105 | * Arguments: @keycheck *kc@ = pointer to keycheck context |
106 | * @unsigned sev@ = minimum severity to care about |
107 | * |
108 | * Returns: Nonzero if no problems of @sev@ or above were noticed. |
109 | */ |
110 | |
111 | int keycheck_allclear(keycheck *kc, unsigned sev) |
112 | { |
113 | while (sev < KCSEV_MAX) { |
114 | if (kc->sev[sev]) |
115 | return (0); |
116 | sev++; |
117 | } |
118 | return (1); |
119 | } |
120 | |
121 | /*----- That's all, folks -------------------------------------------------*/ |