1 /* See the file COPYING for licensing information. */
3 #if defined HAVE_CONFIG_H
10 #include <radsec/radsec.h>
11 #include <radsec/radsec-impl.h>
13 static const char *_errtxt[] = {
14 "SUCCESS", /* 0 RSE_OK */
15 "out of memory", /* 1 RSE_NOMEM */
16 "not yet implemented", /* 2 RSE_NOSYS */
17 "invalid handle", /* 3 RSE_INVALID_CTX */
18 "invalid connection", /* 4 RSE_INVALID_CONN */
19 "connection type mismatch", /* 5 RSE_CONN_TYPE_MISMATCH */
20 "FreeRadius error", /* 6 RSE_FR */
21 "bad hostname or port", /* 7 RSE_BADADDR */
22 "no peer configured", /* 8 RSE_NOPEER */
23 "libevent error", /* 9 RSE_EVENT */
24 "socket error", /* 10 RSE_SOCKERR */
25 "invalid configuration file", /* 11 RSE_CONFIG */
26 "authentication failed", /* 12 RSE_BADAUTH */
27 "internal error", /* 13 RSE_INTERNAL */
28 "SSL error", /* 14 RSE_SSLERR */
29 "invalid packet", /* 15 RSE_INVALID_PKT */
30 "connect timeout", /* 16 RSE_TIMEOUT_CONN */
31 "invalid argument", /* 17 RSE_INVAL */
32 "I/O timeout", /* 18 RSE_TIMEOUT_IO */
34 #define ERRTXT_SIZE (sizeof(_errtxt) / sizeof(*_errtxt))
36 static struct rs_error *
37 _err_vcreate (unsigned int code, const char *file, int line, const char *fmt,
42 err = malloc (sizeof(struct rs_error));
46 memset (err, 0, sizeof(struct rs_error));
49 n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
53 err->code < ERRTXT_SIZE ? _errtxt[err->code] : "",
55 n = strlen (err->buf);
59 char *sep = strrchr (file, '/');
62 snprintf (err->buf + n, sizeof(err->buf) - n, " (%s:%d)", file,
70 _rs_err_create (unsigned int code, const char *file, int line, const char *fmt,
77 err = _err_vcreate (code, file, line, fmt, args);
83 _ctx_err_vpush_fl (struct rs_context *ctx, int code, const char *file,
84 int line, const char *fmt, va_list args)
86 struct rs_error *err = _err_vcreate (code, file, line, fmt, args);
94 rs_err_ctx_push (struct rs_context *ctx, int code, const char *fmt, ...)
98 _ctx_err_vpush_fl (ctx, code, NULL, 0, fmt, args);
104 rs_err_ctx_push_fl (struct rs_context *ctx, int code, const char *file,
105 int line, const char *fmt, ...)
108 va_start (args, fmt);
109 _ctx_err_vpush_fl (ctx, code, file, line, fmt, args);
115 _rs_err_conn_push_err (struct rs_connection *conn, struct rs_error *err)
117 conn->err = err; /* FIXME: use a stack */
122 _conn_err_vpush_fl (struct rs_connection *conn, int code, const char *file,
123 int line, const char *fmt, va_list args)
125 struct rs_error *err = _err_vcreate (code, file, line, fmt, args);
128 _rs_err_conn_push_err (conn, err);
133 rs_err_conn_push (struct rs_connection *conn, int code, const char *fmt, ...)
136 va_start (args, fmt);
137 _conn_err_vpush_fl (conn, code, NULL, 0, fmt, args);
143 rs_err_conn_push_fl (struct rs_connection *conn, int code, const char *file,
144 int line, const char *fmt, ...)
147 va_start (args, fmt);
148 _conn_err_vpush_fl (conn, code, file, line, fmt, args);
154 rs_err_ctx_pop (struct rs_context *ctx)
156 struct rs_error *err;
159 return NULL; /* FIXME: RSE_INVALID_CTX. */
166 rs_err_conn_pop (struct rs_connection *conn)
168 struct rs_error *err;
171 return NULL; /* FIXME: RSE_INVALID_CONN */
178 rs_err_conn_peek_code (struct rs_connection *conn)
180 if (conn && conn->err)
181 return conn->err->code;
187 rs_err_free (struct rs_error *err)
196 rs_err_msg (struct rs_error *err, int dofree_flag)
205 msg = strdup (err->buf);
213 rs_err_code (struct rs_error *err, int dofree_flag)