strerror.c 18 KB

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