4 #include "libradsec-impl.h"
6 const char *_errtxt[] = {
7 "SUCCESS", /* 0 RSE_OK */
8 "NOMEM", /* 1 RSE_NOMEM */
9 "NYI -- not yet implemented", /* 2 RSE_NOSYS */
10 "invalid handle" /* 3 RSE_INVALID_CTX */
11 "invalid connection" /* 4 RSE_INVALID_CONN */
12 "connection type mismatch" /* 5 RSE_CONN_TYPE_MISMATCH */
13 "FreeRadius error" /* 6 RSE_FR */
14 "bad hostname or port" /* 7 RSE_BADADDR */
15 "no peer configured" /* 8 RSE_NOPEER */
28 "some error" /* 21 RSE_SOME_ERROR */
31 static struct rs_error *
32 _err_new (unsigned int code, const char *file, int line, const char *fmt, va_list args)
36 err = malloc (sizeof(struct rs_error));
40 memset (err, 0, sizeof(struct rs_error));
42 n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
45 char *sep = strrchr (file, '/');
48 snprintf (err->buf + n, sizeof(err->buf) - n, " (%s: %d)", file,
56 _ctx_err_vpush_fl (struct rs_handle *ctx, int code, const char *file, int line, const char *fmt, va_list args)
58 struct rs_error *err = _err_new (code, file, line, fmt, args);
66 rs_ctx_err_push (struct rs_handle *ctx, int code, const char *fmt, ...)
70 _ctx_err_vpush_fl (ctx, code, NULL, 0, fmt, args);
76 rs_ctx_err_push_fl (struct rs_handle *ctx, int code, const char *file, int line, const char *fmt, ...)
80 _ctx_err_vpush_fl (ctx, code, file, line, fmt, args);
86 _conn_err_vpush_fl (struct rs_connection *conn, int code, const char *file, int line, const char *fmt, va_list args)
88 struct rs_error *err = _err_new (code, file, line, fmt, args);
96 rs_conn_err_push (struct rs_connection *conn, int code, const char *fmt, ...)
100 _conn_err_vpush_fl (conn, code, NULL, 0, fmt, args);
106 rs_conn_err_push_fl (struct rs_connection *conn, int code, const char *file, int line, const char *fmt, ...)
109 va_start (args, fmt);
110 _conn_err_vpush_fl (conn, code, file, line, fmt, args);
116 rs_ctx_err_pop (struct rs_handle *ctx)
118 struct rs_error *err;
121 return NULL; /* FIXME: RSE_INVALID_CTX. */
128 rs_conn_err_pop (struct rs_connection *conn)
130 struct rs_error *err;
133 return NULL; /* FIXME: RSE_INVALID_CONN */
140 rs_err_free (struct rs_error *err)
149 rs_err_msg (struct rs_error *err, int dofree_flag)
158 msg = strdup (err->buf);
166 rs_err_code (struct rs_error *err, int dofree_flag)