WIP
[radsecproxy.git] / lib / err.c
index b0f05c6..f81644a 100644 (file)
--- a/lib/err.c
+++ b/lib/err.c
@@ -1,4 +1,7 @@
+/* See the file COPYING for licensing information.  */
+
 #include <stdio.h>
+#include <string.h>
 #include <assert.h>
 #include "libradsec.h"
 #include "libradsec-impl.h"
@@ -13,8 +16,8 @@ const char *_errtxt[] = {
   "FreeRadius error"           /* 6 RSE_FR */
   "bad hostname or port"       /* 7 RSE_BADADDR */
   "no peer configured"         /* 8 RSE_NOPEER */
-  "ERR 9"                      /*  RSE_ */
-  "ERR 10"                     /*  RSE_ */
+  "libevent error"             /* 9 RSE_EVENT */
+  "connection error"           /* 10 RSE_CONNERR */
   "ERR 11"                     /*  RSE_ */
   "ERR 12"                     /*  RSE_ */
   "ERR 13"                     /*  RSE_ */
@@ -27,6 +30,7 @@ const char *_errtxt[] = {
   "ERR "                       /*  RSE_ */
   "some error"                 /* 21 RSE_SOME_ERROR */
 };
+#define ERRTXT_SIZE (sizeof(_errtxt) / sizeof(*_errtxt))
 
 static struct rs_error *
 _err_new (unsigned int code, const char *file, int line, const char *fmt, va_list args)
@@ -39,8 +43,16 @@ _err_new (unsigned int code, const char *file, int line, const char *fmt, va_lis
       int n;
       memset (err, 0, sizeof(struct rs_error));
       err->code = code;
-      n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
-      if (n > 0)
+      if (fmt)
+       n = vsnprintf (err->buf, sizeof(err->buf), fmt, args);
+      else
+       {
+         strncpy (err->buf,
+                  err->code < ERRTXT_SIZE ? _errtxt[err->code] : "",
+                  sizeof(err->buf));
+         n = strlen (err->buf);
+       }
+      if (n >= 0)
        {
          char *sep = strrchr (file, '/');
          if (sep)