1 /* See the file COPYING for licensing information. */
6 #include <radsec/radsec.h>
7 #include <radsec/radsec-impl.h>
9 const char *_errtxt[] = {
10 "SUCCESS", /* 0 RSE_OK */
11 "NOMEM", /* 1 RSE_NOMEM */
12 "NYI -- not yet implemented", /* 2 RSE_NOSYS */
13 "invalid handle" /* 3 RSE_INVALID_CTX */
14 "invalid connection" /* 4 RSE_INVALID_CONN */
15 "connection type mismatch" /* 5 RSE_CONN_TYPE_MISMATCH */
16 "FreeRadius error" /* 6 RSE_FR */
17 "bad hostname or port" /* 7 RSE_BADADDR */
18 "no peer configured" /* 8 RSE_NOPEER */
19 "libevent error" /* 9 RSE_EVENT */
20 "connection error" /* 10 RSE_CONNERR */
21 "invalid configuration file" /* 11 RSE_CONFIG */
31 "some error" /* 21 RSE_SOME_ERROR */
33 #define ERRTXT_SIZE (sizeof(_errtxt) / sizeof(*_errtxt))
35 static struct rs_error *
36 _err_vcreate (unsigned int code, const char *file, int line, const char *fmt,
41 err = malloc (sizeof(struct rs_error));
45 memset (err, 0, sizeof(struct rs_error));
48 n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
52 err->code < ERRTXT_SIZE ? _errtxt[err->code] : "",
54 n = strlen (err->buf);
58 char *sep = strrchr (file, '/');
61 snprintf (err->buf + n, sizeof(err->buf) - n, " (%s: %d)", file,
69 _rs_err_create (unsigned int code, const char *file, int line, const char *fmt,
76 err = _err_vcreate (code, file, line, fmt, args);
82 _ctx_err_vpush_fl (struct rs_handle *ctx, int code, const char *file, int line, const char *fmt, va_list args)
84 struct rs_error *err = _err_vcreate (code, file, line, fmt, args);
92 rs_err_ctx_push (struct rs_handle *ctx, int code, const char *fmt, ...)
96 _ctx_err_vpush_fl (ctx, code, NULL, 0, fmt, args);
102 rs_err_ctx_push_fl (struct rs_handle *ctx, int code, const char *file, int line, const char *fmt, ...)
105 va_start (args, fmt);
106 _ctx_err_vpush_fl (ctx, code, file, line, fmt, args);
112 _rs_err_conn_push_err (struct rs_connection *conn, struct rs_error *err)
114 conn->err = err; /* FIXME: use a stack */
119 _conn_err_vpush_fl (struct rs_connection *conn, int code, const char *file, int line, const char *fmt, va_list args)
121 struct rs_error *err = _err_vcreate (code, file, line, fmt, args);
124 _rs_err_conn_push_err (conn, err);
129 rs_err_conn_push (struct rs_connection *conn, int code, const char *fmt, ...)
132 va_start (args, fmt);
133 _conn_err_vpush_fl (conn, code, NULL, 0, fmt, args);
139 rs_err_conn_push_fl (struct rs_connection *conn, int code, const char *file, int line, const char *fmt, ...)
142 va_start (args, fmt);
143 _conn_err_vpush_fl (conn, code, file, line, fmt, args);
149 rs_err_ctx_pop (struct rs_handle *ctx)
151 struct rs_error *err;
154 return NULL; /* FIXME: RSE_INVALID_CTX. */
161 rs_err_conn_pop (struct rs_connection *conn)
163 struct rs_error *err;
166 return NULL; /* FIXME: RSE_INVALID_CONN */
173 rs_err_free (struct rs_error *err)
182 rs_err_msg (struct rs_error *err, int dofree_flag)
191 msg = strdup (err->buf);
199 rs_err_code (struct rs_error *err, int dofree_flag)