| 1 | /* -*-c-*- |
| 2 | * |
| 3 | * Framework for checking consistency of keys |
| 4 | * |
| 5 | * (c) 2001 Straylight/Edgeware |
| 6 | */ |
| 7 | |
| 8 | /*----- Licensing notice --------------------------------------------------* |
| 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. |
| 16 | * |
| 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. |
| 21 | * |
| 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 | |
| 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 PRINTF_LIKE(3, 4) |
| 77 | keycheck_report(keycheck */*kc*/, unsigned /*sev*/, |
| 78 | const char */*msg*/, ...); |
| 79 | |
| 80 | /* --- @keycheck_init@ --- * |
| 81 | * |
| 82 | * Arguments: @keycheck *kc@ = pointer to block to initialize |
| 83 | * @int (*func)(unsigned sev, const char *msg, void *p)@ = |
| 84 | * handler function for problems |
| 85 | * @void *p@ = pointer to give to handler |
| 86 | * |
| 87 | * Returns: --- |
| 88 | * |
| 89 | * Use: Initializes a key checking context. |
| 90 | */ |
| 91 | |
| 92 | extern void keycheck_init(keycheck */*kc*/, |
| 93 | int (*/*func*/)(unsigned /*sev*/, |
| 94 | const char */*msg*/, |
| 95 | void */*p*/), |
| 96 | void */*p*/); |
| 97 | |
| 98 | /* --- @keycheck_allclear@ --- * |
| 99 | * |
| 100 | * Arguments: @keycheck *kc@ = pointer to keycheck context |
| 101 | * @unsigned sev@ = minimum severity to care about |
| 102 | * |
| 103 | * Returns: Nonzero if no problems of @sev@ or above were noticed. |
| 104 | */ |
| 105 | |
| 106 | extern int keycheck_allclear(keycheck */*kc*/, unsigned /*sev*/); |
| 107 | |
| 108 | /*----- A standard report function ----------------------------------------*/ |
| 109 | |
| 110 | /* --- @keycheck_stdreport@ --- * |
| 111 | * |
| 112 | * Arguments: @unsigned sev@ = problem severity |
| 113 | * @const char *msg@ = message to report |
| 114 | * @void *p@ = pointer to a @keycheck_reportctx@ structure |
| 115 | * |
| 116 | * Returns: Zero. |
| 117 | * |
| 118 | * Use: Reports a message to stderr. |
| 119 | */ |
| 120 | |
| 121 | extern int keycheck_stdreport(unsigned /*sev*/, |
| 122 | const char */*msg*/, void */*p*/); |
| 123 | |
| 124 | /*----- Special support functions for large integers ----------------------*/ |
| 125 | |
| 126 | /* --- @keycheck_prime@ --- * |
| 127 | * |
| 128 | * Arguments: @keycheck *kc@ = keycheck state |
| 129 | * @unsigned sev@ = severity if not prime |
| 130 | * @mp *m@ = a number to check for primality |
| 131 | * @const char *name@ = name of this number |
| 132 | * |
| 133 | * Returns: Zero if OK, or return status from function. |
| 134 | * |
| 135 | * Use: Checks that a number is prime. |
| 136 | */ |
| 137 | |
| 138 | extern int keycheck_prime(keycheck */*kc*/, unsigned /*sev*/, |
| 139 | mp */*m*/, const char */*name*/); |
| 140 | |
| 141 | /*----- That's all, folks -------------------------------------------------*/ |
| 142 | |
| 143 | #ifdef __cplusplus |
| 144 | } |
| 145 | #endif |
| 146 | |
| 147 | #endif |