strerror.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2004 - 2007, Daniel Stenberg, <[email protected]>, et al.
  9. *
  10. * This software is licensed as described in the file COPYING, which
  11. * you should have received as part of this distribution. The terms
  12. * are also available at http://curl.haxx.se/docs/copyright.html.
  13. *
  14. * You may opt to use, copy, modify, merge, publish, distribute and/or sell
  15. * copies of the Software, and permit persons to whom the Software is
  16. * furnished to do so, under the terms of the COPYING file.
  17. *
  18. * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
  19. * KIND, either express or implied.
  20. *
  21. * $Id$
  22. ***************************************************************************/
  23. #include "setup.h"
  24. #ifdef HAVE_STRERROR_R
  25. #if !defined(HAVE_POSIX_STRERROR_R) && !defined(HAVE_GLIBC_STRERROR_R)
  26. #error "you MUST have either POSIX or glibc strerror_r if strerror_r is found"
  27. #endif /* !POSIX && !glibc */
  28. #endif /* HAVE_STRERROR_R */
  29. #include <curl/curl.h>
  30. #include <stdlib.h>
  31. #include <string.h>
  32. #include <errno.h>
  33. #ifdef USE_LIBIDN
  34. #include <idna.h>
  35. #endif
  36. #include "strerror.h"
  37. #define _MPRINTF_REPLACE /* use our functions only */
  38. #include <curl/mprintf.h>
  39. #if defined(HAVE_STRERROR_R) && defined(HAVE_NO_STRERROR_R_DECL)
  40. #ifdef HAVE_POSIX_STRERROR_R
  41. /* seen on AIX 5100-02 gcc 2.9 */
  42. extern int strerror_r(int errnum, char *strerrbuf, size_t buflen);
  43. #else
  44. extern char *strerror_r(int errnum, char *buf, size_t buflen);
  45. #endif
  46. #endif
  47. const char *
  48. curl_easy_strerror(CURLcode error)
  49. {
  50. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  51. switch (error) {
  52. case CURLE_OK:
  53. return "No error";
  54. case CURLE_UNSUPPORTED_PROTOCOL:
  55. return "Unsupported protocol";
  56. case CURLE_FAILED_INIT:
  57. return "Failed initialization";
  58. case CURLE_URL_MALFORMAT:
  59. return "URL using bad/illegal format or missing URL";
  60. case CURLE_COULDNT_RESOLVE_PROXY:
  61. return "Couldn't resolve proxy name";
  62. case CURLE_COULDNT_RESOLVE_HOST:
  63. return "Couldn't resolve host name";
  64. case CURLE_COULDNT_CONNECT:
  65. return "Couldn't connect to server";
  66. case CURLE_FTP_WEIRD_SERVER_REPLY:
  67. return "FTP: weird server reply";
  68. case CURLE_REMOTE_ACCESS_DENIED:
  69. return "Access denied to remote resource";
  70. case CURLE_FTP_WEIRD_PASS_REPLY:
  71. return "FTP: unknown PASS reply";
  72. case CURLE_FTP_WEIRD_PASV_REPLY:
  73. return "FTP: unknown PASV reply";
  74. case CURLE_FTP_WEIRD_227_FORMAT:
  75. return "FTP: unknown 227 response format";
  76. case CURLE_FTP_CANT_GET_HOST:
  77. return "FTP: can't figure out the host in the PASV response";
  78. case CURLE_FTP_COULDNT_SET_TYPE:
  79. return "FTP: couldn't set file type";
  80. case CURLE_PARTIAL_FILE:
  81. return "Transferred a partial file";
  82. case CURLE_FTP_COULDNT_RETR_FILE:
  83. return "FTP: couldn't retrieve (RETR failed) the specified file";
  84. case CURLE_QUOTE_ERROR:
  85. return "Quote command returned error";
  86. case CURLE_HTTP_RETURNED_ERROR:
  87. return "HTTP response code said error";
  88. case CURLE_WRITE_ERROR:
  89. return "Failed writing received data to disk/application";
  90. case CURLE_UPLOAD_FAILED:
  91. return "Upload failed (at start/before it took off)";
  92. case CURLE_READ_ERROR:
  93. return "Failed to open/read local data from file/application";
  94. case CURLE_OUT_OF_MEMORY:
  95. return "Out of memory";
  96. case CURLE_OPERATION_TIMEDOUT:
  97. return "Timeout was reached";
  98. case CURLE_FTP_PORT_FAILED:
  99. return "FTP: command PORT failed";
  100. case CURLE_FTP_COULDNT_USE_REST:
  101. return "FTP: command REST failed";
  102. case CURLE_RANGE_ERROR:
  103. return "Requested range was not delivered by the server";
  104. case CURLE_HTTP_POST_ERROR:
  105. return "Internal problem setting up the POST";
  106. case CURLE_SSL_CONNECT_ERROR:
  107. return "SSL connect error";
  108. case CURLE_BAD_DOWNLOAD_RESUME:
  109. return "Couldn't resume download";
  110. case CURLE_FILE_COULDNT_READ_FILE:
  111. return "Couldn't read a file:// file";
  112. case CURLE_LDAP_CANNOT_BIND:
  113. return "LDAP: cannot bind";
  114. case CURLE_LDAP_SEARCH_FAILED:
  115. return "LDAP: search failed";
  116. case CURLE_FUNCTION_NOT_FOUND:
  117. return "A required function in the library was not found";
  118. case CURLE_ABORTED_BY_CALLBACK:
  119. return "Operation was aborted by an application callback";
  120. case CURLE_BAD_FUNCTION_ARGUMENT:
  121. return "A libcurl function was given a bad argument";
  122. case CURLE_INTERFACE_FAILED:
  123. return "Failed binding local connection end";
  124. case CURLE_TOO_MANY_REDIRECTS :
  125. return "Number of redirects hit maximum amount";
  126. case CURLE_UNKNOWN_TELNET_OPTION:
  127. return "User specified an unknown telnet option";
  128. case CURLE_TELNET_OPTION_SYNTAX :
  129. return "Malformed telnet option";
  130. case CURLE_PEER_FAILED_VERIFICATION:
  131. return "SSL peer certificate or SSH md5 fingerprint was not OK";
  132. case CURLE_GOT_NOTHING:
  133. return "Server returned nothing (no headers, no data)";
  134. case CURLE_SSL_ENGINE_NOTFOUND:
  135. return "SSL crypto engine not found";
  136. case CURLE_SSL_ENGINE_SETFAILED:
  137. return "Can not set SSL crypto engine as default";
  138. case CURLE_SSL_ENGINE_INITFAILED:
  139. return "Failed to initialise SSL crypto engine";
  140. case CURLE_SEND_ERROR:
  141. return "Failed sending data to the peer";
  142. case CURLE_RECV_ERROR:
  143. return "Failure when receiving data from the peer";
  144. case CURLE_SSL_CERTPROBLEM:
  145. return "Problem with the local SSL certificate";
  146. case CURLE_SSL_CIPHER:
  147. return "Couldn't use specified SSL cipher";
  148. case CURLE_SSL_CACERT:
  149. return "Peer certificate cannot be authenticated with known CA certificates";
  150. case CURLE_SSL_CACERT_BADFILE:
  151. return "Problem with the SSL CA cert (path? access rights?)";
  152. case CURLE_BAD_CONTENT_ENCODING:
  153. return "Unrecognized HTTP Content-Encoding";
  154. case CURLE_LDAP_INVALID_URL:
  155. return "Invalid LDAP URL";
  156. case CURLE_FILESIZE_EXCEEDED:
  157. return "Maximum file size exceeded";
  158. case CURLE_USE_SSL_FAILED:
  159. return "Requested SSL level failed";
  160. case CURLE_SSL_SHUTDOWN_FAILED:
  161. return "Failed to shut down the SSL connection";
  162. case CURLE_SSL_CRL_BADFILE:
  163. return "Failed to load CRL file (path? access rights?, format?)";
  164. case CURLE_SSL_ISSUER_ERROR:
  165. return "Issuer check against peer certificate failed";
  166. case CURLE_SEND_FAIL_REWIND:
  167. return "Send failed since rewinding of the data stream failed";
  168. case CURLE_LOGIN_DENIED:
  169. return "Login denied";
  170. case CURLE_TFTP_NOTFOUND:
  171. return "TFTP: File Not Found";
  172. case CURLE_TFTP_PERM:
  173. return "TFTP: Access Violation";
  174. case CURLE_REMOTE_DISK_FULL:
  175. return "Disk full or allocation exceeded";
  176. case CURLE_TFTP_ILLEGAL:
  177. return "TFTP: Illegal operation";
  178. case CURLE_TFTP_UNKNOWNID:
  179. return "TFTP: Unknown transfer ID";
  180. case CURLE_REMOTE_FILE_EXISTS:
  181. return "Remote file already exists";
  182. case CURLE_TFTP_NOSUCHUSER:
  183. return "TFTP: No such user";
  184. case CURLE_CONV_FAILED:
  185. return "Conversion failed";
  186. case CURLE_CONV_REQD:
  187. return "Caller must register CURLOPT_CONV_ callback options";
  188. case CURLE_REMOTE_FILE_NOT_FOUND:
  189. return "Remote file not found";
  190. case CURLE_SSH:
  191. return "Error in the SSH layer";
  192. case CURLE_AGAIN:
  193. return "Socket not ready for send/recv";
  194. /* error codes not used by current libcurl */
  195. case CURLE_OBSOLETE4:
  196. case CURLE_OBSOLETE10:
  197. case CURLE_OBSOLETE12:
  198. case CURLE_OBSOLETE16:
  199. case CURLE_OBSOLETE20:
  200. case CURLE_OBSOLETE24:
  201. case CURLE_OBSOLETE29:
  202. case CURLE_OBSOLETE32:
  203. case CURLE_OBSOLETE40:
  204. case CURLE_OBSOLETE44:
  205. case CURLE_OBSOLETE46:
  206. case CURLE_OBSOLETE50:
  207. case CURLE_OBSOLETE57:
  208. case CURL_LAST:
  209. break;
  210. }
  211. /*
  212. * By using a switch, gcc -Wall will complain about enum values
  213. * which do not appear, helping keep this function up-to-date.
  214. * By using gcc -Wall -Werror, you can't forget.
  215. *
  216. * A table would not have the same benefit. Most compilers will
  217. * generate code very similar to a table in any case, so there
  218. * is little performance gain from a table. And something is broken
  219. * for the user's application, anyways, so does it matter how fast
  220. * it _doesn't_ work?
  221. *
  222. * The line number for the error will be near this comment, which
  223. * is why it is here, and not at the start of the switch.
  224. */
  225. return "Unknown error";
  226. #else
  227. if(error == CURLE_OK)
  228. return "No error";
  229. else
  230. return "Error";
  231. #endif
  232. }
  233. const char *
  234. curl_multi_strerror(CURLMcode error)
  235. {
  236. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  237. switch (error) {
  238. case CURLM_CALL_MULTI_PERFORM:
  239. return "Please call curl_multi_perform() soon";
  240. case CURLM_OK:
  241. return "No error";
  242. case CURLM_BAD_HANDLE:
  243. return "Invalid multi handle";
  244. case CURLM_BAD_EASY_HANDLE:
  245. return "Invalid easy handle";
  246. case CURLM_OUT_OF_MEMORY:
  247. return "Out of memory";
  248. case CURLM_INTERNAL_ERROR:
  249. return "Internal error";
  250. case CURLM_BAD_SOCKET:
  251. return "Invalid socket argument";
  252. case CURLM_UNKNOWN_OPTION:
  253. return "Unknown option";
  254. case CURLM_LAST:
  255. break;
  256. }
  257. return "Unknown error";
  258. #else
  259. if(error == CURLM_OK)
  260. return "No error";
  261. else
  262. return "Error";
  263. #endif
  264. }
  265. const char *
  266. curl_share_strerror(CURLSHcode error)
  267. {
  268. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  269. switch (error) {
  270. case CURLSHE_OK:
  271. return "No error";
  272. case CURLSHE_BAD_OPTION:
  273. return "Unknown share option";
  274. case CURLSHE_IN_USE:
  275. return "Share currently in use";
  276. case CURLSHE_INVALID:
  277. return "Invalid share handle";
  278. case CURLSHE_NOMEM:
  279. return "Out of memory";
  280. case CURLSHE_LAST:
  281. break;
  282. }
  283. return "CURLSHcode unknown";
  284. #else
  285. if(error == CURLSHE_OK)
  286. return "No error";
  287. else
  288. return "Error";
  289. #endif
  290. }
  291. #ifdef USE_WINSOCK
  292. /* This function handles most / all (?) Winsock errors cURL is able to produce.
  293. */
  294. static const char *
  295. get_winsock_error (int err, char *buf, size_t len)
  296. {
  297. const char *p;
  298. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  299. switch (err) {
  300. case WSAEINTR:
  301. p = "Call interrupted";
  302. break;
  303. case WSAEBADF:
  304. p = "Bad file";
  305. break;
  306. case WSAEACCES:
  307. p = "Bad access";
  308. break;
  309. case WSAEFAULT:
  310. p = "Bad argument";
  311. break;
  312. case WSAEINVAL:
  313. p = "Invalid arguments";
  314. break;
  315. case WSAEMFILE:
  316. p = "Out of file descriptors";
  317. break;
  318. case WSAEWOULDBLOCK:
  319. p = "Call would block";
  320. break;
  321. case WSAEINPROGRESS:
  322. case WSAEALREADY:
  323. p = "Blocking call in progress";
  324. break;
  325. case WSAENOTSOCK:
  326. p = "Descriptor is not a socket";
  327. break;
  328. case WSAEDESTADDRREQ:
  329. p = "Need destination address";
  330. break;
  331. case WSAEMSGSIZE:
  332. p = "Bad message size";
  333. break;
  334. case WSAEPROTOTYPE:
  335. p = "Bad protocol";
  336. break;
  337. case WSAENOPROTOOPT:
  338. p = "Protocol option is unsupported";
  339. break;
  340. case WSAEPROTONOSUPPORT:
  341. p = "Protocol is unsupported";
  342. break;
  343. case WSAESOCKTNOSUPPORT:
  344. p = "Socket is unsupported";
  345. break;
  346. case WSAEOPNOTSUPP:
  347. p = "Operation not supported";
  348. break;
  349. case WSAEAFNOSUPPORT:
  350. p = "Address family not supported";
  351. break;
  352. case WSAEPFNOSUPPORT:
  353. p = "Protocol family not supported";
  354. break;
  355. case WSAEADDRINUSE:
  356. p = "Address already in use";
  357. break;
  358. case WSAEADDRNOTAVAIL:
  359. p = "Address not available";
  360. break;
  361. case WSAENETDOWN:
  362. p = "Network down";
  363. break;
  364. case WSAENETUNREACH:
  365. p = "Network unreachable";
  366. break;
  367. case WSAENETRESET:
  368. p = "Network has been reset";
  369. break;
  370. case WSAECONNABORTED:
  371. p = "Connection was aborted";
  372. break;
  373. case WSAECONNRESET:
  374. p = "Connection was reset";
  375. break;
  376. case WSAENOBUFS:
  377. p = "No buffer space";
  378. break;
  379. case WSAEISCONN:
  380. p = "Socket is already connected";
  381. break;
  382. case WSAENOTCONN:
  383. p = "Socket is not connected";
  384. break;
  385. case WSAESHUTDOWN:
  386. p = "Socket has been shut down";
  387. break;
  388. case WSAETOOMANYREFS:
  389. p = "Too many references";
  390. break;
  391. case WSAETIMEDOUT:
  392. p = "Timed out";
  393. break;
  394. case WSAECONNREFUSED:
  395. p = "Connection refused";
  396. break;
  397. case WSAELOOP:
  398. p = "Loop??";
  399. break;
  400. case WSAENAMETOOLONG:
  401. p = "Name too long";
  402. break;
  403. case WSAEHOSTDOWN:
  404. p = "Host down";
  405. break;
  406. case WSAEHOSTUNREACH:
  407. p = "Host unreachable";
  408. break;
  409. case WSAENOTEMPTY:
  410. p = "Not empty";
  411. break;
  412. case WSAEPROCLIM:
  413. p = "Process limit reached";
  414. break;
  415. case WSAEUSERS:
  416. p = "Too many users";
  417. break;
  418. case WSAEDQUOT:
  419. p = "Bad quota";
  420. break;
  421. case WSAESTALE:
  422. p = "Something is stale";
  423. break;
  424. case WSAEREMOTE:
  425. p = "Remote error";
  426. break;
  427. #ifdef WSAEDISCON /* missing in SalfordC! */
  428. case WSAEDISCON:
  429. p = "Disconnected";
  430. break;
  431. #endif
  432. /* Extended Winsock errors */
  433. case WSASYSNOTREADY:
  434. p = "Winsock library is not ready";
  435. break;
  436. case WSANOTINITIALISED:
  437. p = "Winsock library not initialised";
  438. break;
  439. case WSAVERNOTSUPPORTED:
  440. p = "Winsock version not supported";
  441. break;
  442. /* getXbyY() errors (already handled in herrmsg):
  443. * Authoritative Answer: Host not found */
  444. case WSAHOST_NOT_FOUND:
  445. p = "Host not found";
  446. break;
  447. /* Non-Authoritative: Host not found, or SERVERFAIL */
  448. case WSATRY_AGAIN:
  449. p = "Host not found, try again";
  450. break;
  451. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  452. case WSANO_RECOVERY:
  453. p = "Unrecoverable error in call to nameserver";
  454. break;
  455. /* Valid name, no data record of requested type */
  456. case WSANO_DATA:
  457. p = "No data record of requested type";
  458. break;
  459. default:
  460. return NULL;
  461. }
  462. #else
  463. if(err == CURLE_OK)
  464. return NULL;
  465. else
  466. p = "error";
  467. #endif
  468. strncpy (buf, p, len);
  469. buf [len-1] = '\0';
  470. return buf;
  471. }
  472. #endif /* USE_WINSOCK */
  473. /*
  474. * Our thread-safe and smart strerror() replacement.
  475. *
  476. * The 'err' argument passed in to this function MUST be a true errno number
  477. * as reported on this system. We do no range checking on the number before
  478. * we pass it to the "number-to-message" conversion function and there might
  479. * be systems that don't do proper range checking in there themselves.
  480. *
  481. * We don't do range checking (on systems other than Windows) since there is
  482. * no good reliable and portable way to do it.
  483. */
  484. const char *Curl_strerror(struct connectdata *conn, int err)
  485. {
  486. char *buf, *p;
  487. size_t max;
  488. DEBUGASSERT(conn);
  489. DEBUGASSERT(err >= 0);
  490. buf = conn->syserr_buf;
  491. max = sizeof(conn->syserr_buf)-1;
  492. *buf = '\0';
  493. #ifdef USE_WINSOCK
  494. #ifdef _WIN32_WCE
  495. buf[0]=0;
  496. {
  497. wchar_t wbuf[256];
  498. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
  499. LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
  500. wcstombs(buf,wbuf,max);
  501. }
  502. #else
  503. /* 'sys_nerr' is the maximum errno number, it is not widely portable */
  504. if(err >= 0 && err < sys_nerr)
  505. strncpy(buf, strerror(err), max);
  506. else {
  507. if(!get_winsock_error(err, buf, max) &&
  508. !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
  509. LANG_NEUTRAL, buf, (DWORD)max, NULL))
  510. snprintf(buf, max, "Unknown error %d (%#x)", err, err);
  511. }
  512. #endif
  513. #else /* not USE_WINSOCK coming up */
  514. /* These should be atomic and hopefully thread-safe */
  515. #ifdef HAVE_STRERROR_R
  516. /* There are two different APIs for strerror_r(). The POSIX and the GLIBC
  517. versions. */
  518. #ifdef HAVE_POSIX_STRERROR_R
  519. strerror_r(err, buf, max);
  520. /* this may set errno to ERANGE if insufficient storage was supplied via
  521. 'strerrbuf' and 'buflen' to contain the generated message string, or
  522. EINVAL if the value of 'errnum' is not a valid error number.*/
  523. #else
  524. {
  525. /* HAVE_GLIBC_STRERROR_R */
  526. char buffer[256];
  527. char *msg = strerror_r(err, buffer, sizeof(buffer));
  528. /* this version of strerror_r() only *might* use the buffer we pass to
  529. the function, but it always returns the error message as a pointer,
  530. so we must copy that string unconditionally (if non-NULL) */
  531. if(msg)
  532. strncpy(buf, msg, max);
  533. else
  534. snprintf(buf, max, "Unknown error %d", err);
  535. }
  536. #endif /* end of HAVE_GLIBC_STRERROR_R */
  537. #else /* HAVE_STRERROR_R */
  538. strncpy(buf, strerror(err), max);
  539. #endif /* end of HAVE_STRERROR_R */
  540. #endif /* end of ! USE_WINSOCK */
  541. buf[max] = '\0'; /* make sure the string is zero terminated */
  542. /* strip trailing '\r\n' or '\n'. */
  543. if((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
  544. *p = '\0';
  545. if((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
  546. *p = '\0';
  547. return buf;
  548. }
  549. #ifdef USE_LIBIDN
  550. /*
  551. * Return error-string for libidn status as returned from idna_to_ascii_lz().
  552. */
  553. const char *Curl_idn_strerror (struct connectdata *conn, int err)
  554. {
  555. #ifdef HAVE_IDNA_STRERROR
  556. (void)conn;
  557. return idna_strerror((Idna_rc) err);
  558. #else
  559. const char *str;
  560. char *buf;
  561. size_t max;
  562. DEBUGASSERT(conn);
  563. buf = conn->syserr_buf;
  564. max = sizeof(conn->syserr_buf)-1;
  565. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  566. switch ((Idna_rc)err) {
  567. case IDNA_SUCCESS:
  568. str = "No error";
  569. break;
  570. case IDNA_STRINGPREP_ERROR:
  571. str = "Error in string preparation";
  572. break;
  573. case IDNA_PUNYCODE_ERROR:
  574. str = "Error in Punycode operation";
  575. break;
  576. case IDNA_CONTAINS_NON_LDH:
  577. str = "Illegal ASCII characters";
  578. break;
  579. case IDNA_CONTAINS_MINUS:
  580. str = "Contains minus";
  581. break;
  582. case IDNA_INVALID_LENGTH:
  583. str = "Invalid output length";
  584. break;
  585. case IDNA_NO_ACE_PREFIX:
  586. str = "No ACE prefix (\"xn--\")";
  587. break;
  588. case IDNA_ROUNDTRIP_VERIFY_ERROR:
  589. str = "Round trip verify error";
  590. break;
  591. case IDNA_CONTAINS_ACE_PREFIX:
  592. str = "Already have ACE prefix (\"xn--\")";
  593. break;
  594. case IDNA_ICONV_ERROR:
  595. str = "Locale conversion failed";
  596. break;
  597. case IDNA_MALLOC_ERROR:
  598. str = "Allocation failed";
  599. break;
  600. case IDNA_DLOPEN_ERROR:
  601. str = "dlopen() error";
  602. break;
  603. default:
  604. snprintf(buf, max, "error %d", (int)err);
  605. str = NULL;
  606. break;
  607. }
  608. #else
  609. if((Idna_rc)err == IDNA_SUCCESS)
  610. str = "No error";
  611. else
  612. str = "Error";
  613. #endif
  614. if(str)
  615. strncpy(buf, str, max);
  616. buf[max] = '\0';
  617. return (buf);
  618. #endif
  619. }
  620. #endif /* USE_LIBIDN */