aboutsummaryrefslogtreecommitdiff
path: root/lib/strerror.c
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2004-10-02 13:01:44 +0000
committerDaniel Stenberg <daniel@haxx.se>2004-10-02 13:01:44 +0000
commit19b284c21452b2c50924de3e0a04f5ed8040430d (patch)
tree4d7ac58fcea833c2d730affa4080f5e816318b92 /lib/strerror.c
parent6b3e3095ead3b496a9f5cad480c529f9d2b3c79d (diff)
Gisle Vanem provided code that displays an error message when the (libidn
based) IDN conversion fails. This is really due to a missing suitable function in the libidn API that I hope we can remove once libidn gets a function like this.
Diffstat (limited to 'lib/strerror.c')
-rw-r--r--lib/strerror.c69
1 files changed, 69 insertions, 0 deletions
diff --git a/lib/strerror.c b/lib/strerror.c
index 5263f442c..b64af1cb8 100644
--- a/lib/strerror.c
+++ b/lib/strerror.c
@@ -27,6 +27,10 @@
#include <string.h>
#include <errno.h>
+#ifdef USE_LIBIDN
+#include <idna.h>
+#endif
+
#include "strerror.h"
#define _MPRINTF_REPLACE /* use our functions only */
@@ -556,3 +560,68 @@ const char *Curl_strerror(struct connectdata *conn, int err)
*p = '\0';
return buf;
}
+
+#ifdef USE_LIBIDN
+/*
+ * Return error-string for libidn status as returned
+ * from idna_to_ascii_lz().
+ */
+const char *Curl_idn_strerror (struct connectdata *conn, int err)
+{
+ const char *str;
+ char *buf;
+ size_t max;
+
+ curlassert(conn);
+
+ buf = conn->syserr_buf;
+ max = sizeof(conn->syserr_buf)-1;
+
+ switch ((Idna_rc)err) {
+ case IDNA_SUCCESS:
+ str = "No error";
+ break;
+ case IDNA_STRINGPREP_ERROR:
+ str = "Error in string preparation";
+ break;
+ case IDNA_PUNYCODE_ERROR:
+ str = "Error in Punycode operation";
+ break;
+ case IDNA_CONTAINS_NON_LDH:
+ str = "Illegal ASCII characters";
+ break;
+ case IDNA_CONTAINS_MINUS:
+ str = "Contains minus";
+ break;
+ case IDNA_INVALID_LENGTH:
+ str = "Invalid output length";
+ break;
+ case IDNA_NO_ACE_PREFIX:
+ str = "No ACE prefix (\"xn--\")";
+ break;
+ case IDNA_ROUNDTRIP_VERIFY_ERROR:
+ str = "Roundtrip verify error";
+ break;
+ case IDNA_CONTAINS_ACE_PREFIX:
+ str = "Already have ACE prefix (\"xn--\")";
+ break;
+ case IDNA_ICONV_ERROR:
+ str = "Locale conversion failed";
+ break;
+ case IDNA_MALLOC_ERROR:
+ str = "Allocation failed";
+ break;
+ case IDNA_DLOPEN_ERROR:
+ str = "dlopen() error";
+ break;
+ default:
+ snprintf(buf, max, "error %d", (int)err);
+ str = NULL;
+ break;
+ }
+ if (str)
+ strncpy(buf, str, max);
+ buf[max] = '\0';
+ return (buf);
+}
+#endif /* USE_LIBIDN */