X-Git-Url: https://git.distorted.org.uk/u/mdw/catacomb/blobdiff_plain/86a47753c5ed92211c3d6f5dcf47a1cfb85031a8..2685767a6125c1620719c7de6234aedf41857b7e:/key.h diff --git a/key.h b/key.h index 88d4de5..09bcad5 100644 --- a/key.h +++ b/key.h @@ -1,6 +1,6 @@ /* -*-c-*- * - * $Id: key.h,v 1.5 2000/02/12 18:55:40 mdw Exp $ + * $Id: key.h,v 1.8 2001/02/03 11:57:38 mdw Exp $ * * Simple key management * @@ -30,6 +30,16 @@ /*----- Revision history --------------------------------------------------* * * $Log: key.h,v $ + * Revision 1.8 2001/02/03 11:57:38 mdw + * Allow creating keyfiles with no file attached. + * + * Revision 1.7 2000/12/06 20:33:27 mdw + * Make flags be macros rather than enumerations, to ensure that they're + * unsigned. + * + * Revision 1.6 2000/06/17 11:27:43 mdw + * Add key fetching interface. + * * Revision 1.5 2000/02/12 18:55:40 mdw * Make it all compile properly. * @@ -138,10 +148,8 @@ typedef struct key_file { /* --- Key file flags --- */ -enum { - KF_WRITE = 1, /* File opened for writing */ - KF_MODIFIED = 2 /* File has been modified */ -}; +#define KF_WRITE 1u /* File opened for writing */ +#define KF_MODIFIED 2u /* File has been modified */ /* --- Iterating over keys --- * * @@ -152,12 +160,21 @@ enum { typedef struct { hash_iter i; time_t t; } key_iter; typedef struct { sym_iter i; } key_attriter; +/* --- Key fetching --- */ + +typedef struct key_fetchdef { + char *name; /* Name of item */ + size_t off; /* Offset into target structure */ + unsigned e; /* Flags for the item */ + const struct key_fetchdef *kf; /* Substructure pointer */ +} key_fetchdef; + /* --- File opening options --- */ -enum { - KOPEN_READ, - KOPEN_WRITE -}; +#define KOPEN_READ 0u +#define KOPEN_WRITE 1u +#define KOPEN_MASK 0xff +#define KOPEN_NOFILE 0x100 /* --- Various other magic numbers --- */ @@ -238,7 +255,7 @@ extern int key_extract(key_file */*f*/, key */*k*/, FILE */*fp*/, * * Arguments: @key_file *f@ = pointer to file structure to initialize * @const char *file@ = pointer to the file name - * @int how@ = opening options (@KOPEN_*@). + * @unsigned how@ = opening options (@KOPEN_*@). * @key_reporter *rep@ = error reporting function * @void *arg@ = argument for function * @@ -252,7 +269,7 @@ extern int key_extract(key_file */*f*/, key */*k*/, FILE */*fp*/, * owner only. */ -extern int key_open(key_file */*f*/, const char */*file*/, int /*how*/, +extern int key_open(key_file */*f*/, const char */*file*/, unsigned /*how*/, key_reporter */*rep*/, void */*arg*/); /* --- @key_close@ --- * @@ -289,7 +306,7 @@ extern int key_save(key_file */*f*/); * * Arguments: @key_file *f@ = pointer to file structure to initialize * @const char *file@ = pointer to the file name - * @int how@ = opening options (@KOPEN_*@). + * @unsigned how@ = opening options (@KOPEN_*@). * * Returns: Zero if it worked, nonzero otherwise. * @@ -304,7 +321,8 @@ extern int key_save(key_file */*f*/); * for the private use of @key_open@. */ -extern int key_lockfile(key_file */*f*/, const char */*file*/, int /*how*/); +extern int key_lockfile(key_file */*f*/, const char */*file*/, + unsigned /*how*/); /*----- Creating and manipulating keys ------------------------------------*/ @@ -596,6 +614,63 @@ extern void key_mkiter(key_iter */*i*/, key_file */*f*/); extern key *key_next(key_iter */*i*/); +/*----- Fetching key data conveniently ------------------------------------*/ + +/* --- @key_fetchinit@ --- * + * + * Arguments: @const key_fetchdef *kf@ = pointer to base definition + * @key_packstruct *kps@ = pointer to destination packing def + * @void *p@ = pointer to destination block + * + * Returns: Pointer to packing definition. + * + * Use: Initializes a packing definition (@key_packdef@ structure). + * If @kps@ is null on entry, an appropriately sized block is + * allocated automatically. Otherwise it must be large enough. + */ + +extern key_packdef *key_fetchinit(const key_fetchdef */*kf*/, + key_packstruct */*kp*/, void */*p*/); + +/* --- @key_fetch@ --- * + * + * Arguments: @key_packdef *kp@ = pointer to packing structure + * @key *k@ = key file containing desired key + * + * Returns: Error code, or zero. + * + * Use: Fetches an unpacked key from a packed one. + */ + +extern int key_fetch(key_packdef */*kp*/, key */*k*/); + +/* --- @key_fetchbyname@ --- * + * + * Arguments: @key_packdef *kp@ = pointer to packing structure + * @key_file *kf@ = key file containing desired key + * @const char *tag@ = user's tag describing the key + * + * Returns: Error code, or zero. + * + * Use: Fetches a named key from a key file and unpacks it + * conveniently. + */ + +extern int key_fetchbyname(key_packdef */*kp*/, + key_file */*kf*/, const char */*tag*/); + +/* --- @key_fetchdone@ --- * + * + * Arguments: @key_packdef *kp@ = pointer to packing structure + * + * Returns: --- + * + * Use: Frees a packing structure. If the structure was allocated by + * @key_fetchinit@ then it is freed. + */ + +extern void key_fetchdone(key_packdef */*kp*/); + /*----- Other functions ---------------------------------------------------*/ /* --- @key_moan@ --- *