José
cfg.h
1 /* vim: set tabstop=8 shiftwidth=4 softtabstop=4 expandtab smarttab colorcolumn=80: */
2 /*
3  * Copyright 2017 Red Hat, Inc.
4  *
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
24 #pragma once
25 
26 #include <stddef.h>
27 #include <stdarg.h>
28 #include <stdint.h>
29 
30 enum {
31  _JOSE_CFG_ERR_BASE = 0x1053000000000000ULL,
32  JOSE_CFG_ERR_JWK_INVALID,
33  JOSE_CFG_ERR_JWK_MISMATCH,
34  JOSE_CFG_ERR_JWK_DENIED,
35  JOSE_CFG_ERR_ALG_NOTSUP,
36  JOSE_CFG_ERR_ALG_NOINFER,
37  JOSE_CFG_ERR_JWS_INVALID,
38 };
39 
40 #ifdef DOXYGEN
41 
51 typedef jose_cfg_t jose_cfg_auto_t;
52 #else
53 #define jose_cfg_auto_t jose_cfg_t __attribute__((cleanup(jose_cfg_auto)))
54 #endif
55 
56 typedef struct jose_cfg jose_cfg_t;
57 typedef void (jose_cfg_err_t)(void *misc, const char *file, int line,
58  uint64_t err, const char *fmt, va_list ap);
59 
65 jose_cfg_t *
66 jose_cfg(void);
67 
68 void
69 jose_cfg_auto(jose_cfg_t **cfg);
70 
79 jose_cfg_t *
80 jose_cfg_incref(jose_cfg_t *cfg);
81 
89 void
90 jose_cfg_decref(jose_cfg_t *cfg);
91 
103 void
104 jose_cfg_set_err_func(jose_cfg_t *cfg, jose_cfg_err_t *err, void *misc);
105 
112 void *
113 jose_cfg_get_err_misc(jose_cfg_t *cfg);
114 
115 #ifdef DOXYGEN
116 
126 void
127 jose_cfg_err(jose_cfg_t *cfg, uint64_t err, const char *fmt, ...);
128 #else
129 void __attribute__((format(printf, 5, 6)))
130 jose_cfg_err(jose_cfg_t *cfg, const char *file, int line, uint64_t err,
131  const char *fmt, ...);
132 
133 #define jose_cfg_err(cfg, err, ...) \
134  jose_cfg_err(cfg, __FILE__, __LINE__, err, __VA_ARGS__)
135 #endif
136 
jose_cfg_t * jose_cfg_incref(jose_cfg_t *cfg)
Increases the reference count of a configuration instance.
jose_cfg_t jose_cfg_auto_t
Defines a jose_cfg_t which calls jose_cfg_decref() at end of scope.
Definition: cfg.h:51
void * jose_cfg_get_err_misc(jose_cfg_t *cfg)
Gets the miscellaneous data associated with the current error handler.
jose_cfg_t * jose_cfg(void)
Creates a new configuration instance.
void jose_cfg_err(jose_cfg_t *cfg, uint64_t err, const char *fmt,...)
Submit an error.
void jose_cfg_set_err_func(jose_cfg_t *cfg, jose_cfg_err_t *err, void *misc)
Sets the error handler function for this configuration instance.
void jose_cfg_decref(jose_cfg_t *cfg)
Decreases the reference count of a configuration instance.