123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- #pragma once
- #include <jose/jose.h>
- #include <getopt.h>
- #define __JCMD_AUTO(t) t ## _t __attribute__((cleanup(t ## _cleanup)))
- #define jcmd_opt_key_auto_t __JCMD_AUTO(jcmd_opt_key)
- #define jcmd_opt_io_auto_t __JCMD_AUTO(jcmd_opt_io)
- #define jcmd_opt_auto_t __JCMD_AUTO(jcmd_opt)
- #define FILE_AUTO FILE __attribute__((cleanup(jcmd_file_cleanup)))
- #define JCMD_REGISTER(summary, function, ...) \
- static void __attribute__((constructor)) \
- jcmd_ ## function ## _register(void) \
- { \
- static const char *names[] = { __VA_ARGS__, NULL }; \
- static jcmd_t cmd = { \
- .names = names, \
- .func = function, \
- .desc = summary \
- }; \
- jcmd_push(&cmd); \
- }
- typedef struct jcmd_cfg jcmd_cfg_t;
- typedef bool jcmd_set_t(const jcmd_cfg_t *cfg, void *vopt, const char *arg);
- typedef struct {
- const char *arg;
- const char *doc;
- } jcmd_doc_t;
- struct jcmd_cfg {
- const jcmd_doc_t *doc;
- struct option opt;
- const char *def;
- jcmd_set_t *set;
- off_t off;
- };
- typedef struct {
- const char *name;
- const char *mult;
- } jcmd_field_t;
- typedef struct {
- const jcmd_field_t *fields;
- FILE *detached;
- bool compact;
- FILE *detach;
- FILE *output;
- FILE *input;
- json_t *obj;
- } jcmd_opt_io_t;
- typedef struct jcmd jcmd_t;
- struct jcmd {
- const jcmd_t *next;
- const char *const *names;
- int (*func)(int argc, char *argv[]);
- const char *desc;
- };
- static const jcmd_doc_t jcmd_doc_key[] = {
- { .arg = "FILE", .doc="Read JWK(Set) from FILE" },
- { .arg = "-", .doc="Read JWK(Set) from standard input" },
- {}
- };
- void
- jcmd_push(jcmd_t *cmd);
- bool
- jcmd_opt_parse(int argc, char *argv[], const jcmd_cfg_t *cfgs, void *arg,
- const char *prefix);
- jcmd_set_t jcmd_opt_io_set_input;
- jcmd_set_t jcmd_opt_set_ifile;
- jcmd_set_t jcmd_opt_set_ofile;
- jcmd_set_t jcmd_opt_set_jsons;
- jcmd_set_t jcmd_opt_set_json;
- jcmd_set_t jcmd_opt_set_jwkt;
- jcmd_set_t jcmd_opt_set_jwks;
- jcmd_set_t jcmd_opt_set_flag;
- void
- jcmd_opt_io_cleanup(jcmd_opt_io_t *io);
- void
- jcmd_opt_key_cleanup(jcmd_opt_io_t *io);
- json_t *
- jcmd_compact_field(FILE *file);
- void
- jcmd_file_cleanup(FILE **file);
|