1 /* Copyright 2010, 2011 NORDUnet A/S. All rights reserved.
2 See the file COPYING for licensing information. */
4 #if defined HAVE_CONFIG_H
11 #include <radsec/radsec.h>
12 #include <radsec/radsec-impl.h>
14 static const char *_errtxt[] = {
15 "SUCCESS", /* 0 RSE_OK */
16 "out of memory", /* 1 RSE_NOMEM */
17 "not yet implemented", /* 2 RSE_NOSYS */
18 "invalid handle", /* 3 RSE_INVALID_CTX */
19 "invalid connection", /* 4 RSE_INVALID_CONN */
20 "connection type mismatch", /* 5 RSE_CONN_TYPE_MISMATCH */
21 "FreeRadius error", /* 6 RSE_FR */
22 "bad hostname or port", /* 7 RSE_BADADDR */
23 "no peer configured", /* 8 RSE_NOPEER */
24 "libevent error", /* 9 RSE_EVENT */
25 "socket error", /* 10 RSE_SOCKERR */
26 "invalid configuration file", /* 11 RSE_CONFIG */
27 "authentication failed", /* 12 RSE_BADAUTH */
28 "internal error", /* 13 RSE_INTERNAL */
29 "SSL error", /* 14 RSE_SSLERR */
30 "invalid packet", /* 15 RSE_INVALID_PKT */
31 "connect timeout", /* 16 RSE_TIMEOUT_CONN */
32 "invalid argument", /* 17 RSE_INVAL */
33 "I/O timeout", /* 18 RSE_TIMEOUT_IO */
34 "timeout", /* 19 RSE_TIMEOUT */
36 #define ERRTXT_SIZE (sizeof(_errtxt) / sizeof(*_errtxt))
38 static struct rs_error *
39 _err_vcreate (unsigned int code, const char *file, int line, const char *fmt,
44 err = malloc (sizeof(struct rs_error));
48 memset (err, 0, sizeof(struct rs_error));
51 n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
55 err->code < ERRTXT_SIZE ? _errtxt[err->code] : "",
57 n = strlen (err->buf);
61 char *sep = strrchr (file, '/');
64 snprintf (err->buf + n, sizeof(err->buf) - n, " (%s:%d)", file,
72 _rs_err_create (unsigned int code, const char *file, int line, const char *fmt,
79 err = _err_vcreate (code, file, line, fmt, args);
85 _ctx_err_vpush_fl (struct rs_context *ctx, int code, const char *file,
86 int line, const char *fmt, va_list args)
88 struct rs_error *err = _err_vcreate (code, file, line, fmt, args);
96 rs_err_ctx_push (struct rs_context *ctx, int code, const char *fmt, ...)
100 _ctx_err_vpush_fl (ctx, code, NULL, 0, fmt, args);
106 rs_err_ctx_push_fl (struct rs_context *ctx, int code, const char *file,
107 int line, const char *fmt, ...)
110 va_start (args, fmt);
111 _ctx_err_vpush_fl (ctx, code, file, line, fmt, args);
117 _rs_err_conn_push_err (struct rs_connection *conn, struct rs_error *err)
119 conn->err = err; /* FIXME: use a stack */
124 _conn_err_vpush_fl (struct rs_connection *conn, int code, const char *file,
125 int line, const char *fmt, va_list args)
127 struct rs_error *err = _err_vcreate (code, file, line, fmt, args);
130 _rs_err_conn_push_err (conn, err);
135 rs_err_conn_push (struct rs_connection *conn, int code, const char *fmt, ...)
138 va_start (args, fmt);
139 _conn_err_vpush_fl (conn, code, NULL, 0, fmt, args);
145 rs_err_conn_push_fl (struct rs_connection *conn, int code, const char *file,
146 int line, const char *fmt, ...)
149 va_start (args, fmt);
150 _conn_err_vpush_fl (conn, code, file, line, fmt, args);
156 rs_err_ctx_pop (struct rs_context *ctx)
158 struct rs_error *err;
161 return NULL; /* FIXME: RSE_INVALID_CTX. */
168 rs_err_conn_pop (struct rs_connection *conn)
170 struct rs_error *err;
173 return NULL; /* FIXME: RSE_INVALID_CONN */
180 rs_err_conn_peek_code (struct rs_connection *conn)
183 return -1; /* FIXME: RSE_INVALID_CONN */
185 return conn->err->code;
191 rs_err_free (struct rs_error *err)
198 rs_err_msg (struct rs_error *err)
206 rs_err_code (struct rs_error *err, int dofree_flag)