诸暨麻将添加redis
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

1123 lines
28 KiB

  1. /***************************************************************************
  2. * _ _ ____ _
  3. * Project ___| | | | _ \| |
  4. * / __| | | | |_) | |
  5. * | (__| |_| | _ <| |___
  6. * \___|\___/|_| \_\_____|
  7. *
  8. * Copyright (C) 2004 - 2012, 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. ***************************************************************************/
  22. #include "curl_setup.h"
  23. #ifdef HAVE_STRERROR_R
  24. # if (!defined(HAVE_POSIX_STRERROR_R) && \
  25. !defined(HAVE_GLIBC_STRERROR_R) && \
  26. !defined(HAVE_VXWORKS_STRERROR_R)) || \
  27. (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
  28. (defined(HAVE_GLIBC_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
  29. (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
  30. # error "strerror_r MUST be either POSIX, glibc or vxworks-style"
  31. # endif
  32. #endif
  33. #include <curl/curl.h>
  34. #ifdef USE_LIBIDN
  35. #include <idna.h>
  36. #endif
  37. #include "strerror.h"
  38. #define _MPRINTF_REPLACE /* use our functions only */
  39. #include <curl/mprintf.h>
  40. #include "curl_memory.h"
  41. /* The last #include file should be: */
  42. #include "memdebug.h"
  43. const char *
  44. curl_easy_strerror(CURLcode error)
  45. {
  46. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  47. switch (error) {
  48. case CURLE_OK:
  49. return "No error";
  50. case CURLE_UNSUPPORTED_PROTOCOL:
  51. return "Unsupported protocol";
  52. case CURLE_FAILED_INIT:
  53. return "Failed initialization";
  54. case CURLE_URL_MALFORMAT:
  55. return "URL using bad/illegal format or missing URL";
  56. case CURLE_NOT_BUILT_IN:
  57. return "A requested feature, protocol or option was not found built-in in"
  58. " this libcurl due to a build-time decision.";
  59. case CURLE_COULDNT_RESOLVE_PROXY:
  60. return "Couldn't resolve proxy name";
  61. case CURLE_COULDNT_RESOLVE_HOST:
  62. return "Couldn't resolve host name";
  63. case CURLE_COULDNT_CONNECT:
  64. return "Couldn't connect to server";
  65. case CURLE_FTP_WEIRD_SERVER_REPLY:
  66. return "FTP: weird server reply";
  67. case CURLE_REMOTE_ACCESS_DENIED:
  68. return "Access denied to remote resource";
  69. case CURLE_FTP_ACCEPT_FAILED:
  70. return "FTP: The server failed to connect to data port";
  71. case CURLE_FTP_ACCEPT_TIMEOUT:
  72. return "FTP: Accepting server connect has timed out";
  73. case CURLE_FTP_PRET_FAILED:
  74. return "FTP: The server did not accept the PRET command.";
  75. case CURLE_FTP_WEIRD_PASS_REPLY:
  76. return "FTP: unknown PASS reply";
  77. case CURLE_FTP_WEIRD_PASV_REPLY:
  78. return "FTP: unknown PASV reply";
  79. case CURLE_FTP_WEIRD_227_FORMAT:
  80. return "FTP: unknown 227 response format";
  81. case CURLE_FTP_CANT_GET_HOST:
  82. return "FTP: can't figure out the host in the PASV response";
  83. case CURLE_FTP_COULDNT_SET_TYPE:
  84. return "FTP: couldn't set file type";
  85. case CURLE_PARTIAL_FILE:
  86. return "Transferred a partial file";
  87. case CURLE_FTP_COULDNT_RETR_FILE:
  88. return "FTP: couldn't retrieve (RETR failed) the specified file";
  89. case CURLE_QUOTE_ERROR:
  90. return "Quote command returned error";
  91. case CURLE_HTTP_RETURNED_ERROR:
  92. return "HTTP response code said error";
  93. case CURLE_WRITE_ERROR:
  94. return "Failed writing received data to disk/application";
  95. case CURLE_UPLOAD_FAILED:
  96. return "Upload failed (at start/before it took off)";
  97. case CURLE_READ_ERROR:
  98. return "Failed to open/read local data from file/application";
  99. case CURLE_OUT_OF_MEMORY:
  100. return "Out of memory";
  101. case CURLE_OPERATION_TIMEDOUT:
  102. return "Timeout was reached";
  103. case CURLE_FTP_PORT_FAILED:
  104. return "FTP: command PORT failed";
  105. case CURLE_FTP_COULDNT_USE_REST:
  106. return "FTP: command REST failed";
  107. case CURLE_RANGE_ERROR:
  108. return "Requested range was not delivered by the server";
  109. case CURLE_HTTP_POST_ERROR:
  110. return "Internal problem setting up the POST";
  111. case CURLE_SSL_CONNECT_ERROR:
  112. return "SSL connect error";
  113. case CURLE_BAD_DOWNLOAD_RESUME:
  114. return "Couldn't resume download";
  115. case CURLE_FILE_COULDNT_READ_FILE:
  116. return "Couldn't read a file:// file";
  117. case CURLE_LDAP_CANNOT_BIND:
  118. return "LDAP: cannot bind";
  119. case CURLE_LDAP_SEARCH_FAILED:
  120. return "LDAP: search failed";
  121. case CURLE_FUNCTION_NOT_FOUND:
  122. return "A required function in the library was not found";
  123. case CURLE_ABORTED_BY_CALLBACK:
  124. return "Operation was aborted by an application callback";
  125. case CURLE_BAD_FUNCTION_ARGUMENT:
  126. return "A libcurl function was given a bad argument";
  127. case CURLE_INTERFACE_FAILED:
  128. return "Failed binding local connection end";
  129. case CURLE_TOO_MANY_REDIRECTS :
  130. return "Number of redirects hit maximum amount";
  131. case CURLE_UNKNOWN_OPTION:
  132. return "An unknown option was passed in to libcurl";
  133. case CURLE_TELNET_OPTION_SYNTAX :
  134. return "Malformed telnet option";
  135. case CURLE_PEER_FAILED_VERIFICATION:
  136. return "SSL peer certificate or SSH remote key was not OK";
  137. case CURLE_GOT_NOTHING:
  138. return "Server returned nothing (no headers, no data)";
  139. case CURLE_SSL_ENGINE_NOTFOUND:
  140. return "SSL crypto engine not found";
  141. case CURLE_SSL_ENGINE_SETFAILED:
  142. return "Can not set SSL crypto engine as default";
  143. case CURLE_SSL_ENGINE_INITFAILED:
  144. return "Failed to initialise SSL crypto engine";
  145. case CURLE_SEND_ERROR:
  146. return "Failed sending data to the peer";
  147. case CURLE_RECV_ERROR:
  148. return "Failure when receiving data from the peer";
  149. case CURLE_SSL_CERTPROBLEM:
  150. return "Problem with the local SSL certificate";
  151. case CURLE_SSL_CIPHER:
  152. return "Couldn't use specified SSL cipher";
  153. case CURLE_SSL_CACERT:
  154. return "Peer certificate cannot be authenticated with given CA "
  155. "certificates";
  156. case CURLE_SSL_CACERT_BADFILE:
  157. return "Problem with the SSL CA cert (path? access rights?)";
  158. case CURLE_BAD_CONTENT_ENCODING:
  159. return "Unrecognized or bad HTTP Content or Transfer-Encoding";
  160. case CURLE_LDAP_INVALID_URL:
  161. return "Invalid LDAP URL";
  162. case CURLE_FILESIZE_EXCEEDED:
  163. return "Maximum file size exceeded";
  164. case CURLE_USE_SSL_FAILED:
  165. return "Requested SSL level failed";
  166. case CURLE_SSL_SHUTDOWN_FAILED:
  167. return "Failed to shut down the SSL connection";
  168. case CURLE_SSL_CRL_BADFILE:
  169. return "Failed to load CRL file (path? access rights?, format?)";
  170. case CURLE_SSL_ISSUER_ERROR:
  171. return "Issuer check against peer certificate failed";
  172. case CURLE_SEND_FAIL_REWIND:
  173. return "Send failed since rewinding of the data stream failed";
  174. case CURLE_LOGIN_DENIED:
  175. return "Login denied";
  176. case CURLE_TFTP_NOTFOUND:
  177. return "TFTP: File Not Found";
  178. case CURLE_TFTP_PERM:
  179. return "TFTP: Access Violation";
  180. case CURLE_REMOTE_DISK_FULL:
  181. return "Disk full or allocation exceeded";
  182. case CURLE_TFTP_ILLEGAL:
  183. return "TFTP: Illegal operation";
  184. case CURLE_TFTP_UNKNOWNID:
  185. return "TFTP: Unknown transfer ID";
  186. case CURLE_REMOTE_FILE_EXISTS:
  187. return "Remote file already exists";
  188. case CURLE_TFTP_NOSUCHUSER:
  189. return "TFTP: No such user";
  190. case CURLE_CONV_FAILED:
  191. return "Conversion failed";
  192. case CURLE_CONV_REQD:
  193. return "Caller must register CURLOPT_CONV_ callback options";
  194. case CURLE_REMOTE_FILE_NOT_FOUND:
  195. return "Remote file not found";
  196. case CURLE_SSH:
  197. return "Error in the SSH layer";
  198. case CURLE_AGAIN:
  199. return "Socket not ready for send/recv";
  200. case CURLE_RTSP_CSEQ_ERROR:
  201. return "RTSP CSeq mismatch or invalid CSeq";
  202. case CURLE_RTSP_SESSION_ERROR:
  203. return "RTSP session error";
  204. case CURLE_FTP_BAD_FILE_LIST:
  205. return "Unable to parse FTP file list";
  206. case CURLE_CHUNK_FAILED:
  207. return "Chunk callback failed";
  208. case CURLE_NO_CONNECTION_AVAILABLE:
  209. return "The max connection limit is reached";
  210. /* error codes not used by current libcurl */
  211. case CURLE_OBSOLETE16:
  212. case CURLE_OBSOLETE20:
  213. case CURLE_OBSOLETE24:
  214. case CURLE_OBSOLETE29:
  215. case CURLE_OBSOLETE32:
  216. case CURLE_OBSOLETE40:
  217. case CURLE_OBSOLETE44:
  218. case CURLE_OBSOLETE46:
  219. case CURLE_OBSOLETE50:
  220. case CURLE_OBSOLETE57:
  221. case CURL_LAST:
  222. break;
  223. }
  224. /*
  225. * By using a switch, gcc -Wall will complain about enum values
  226. * which do not appear, helping keep this function up-to-date.
  227. * By using gcc -Wall -Werror, you can't forget.
  228. *
  229. * A table would not have the same benefit. Most compilers will
  230. * generate code very similar to a table in any case, so there
  231. * is little performance gain from a table. And something is broken
  232. * for the user's application, anyways, so does it matter how fast
  233. * it _doesn't_ work?
  234. *
  235. * The line number for the error will be near this comment, which
  236. * is why it is here, and not at the start of the switch.
  237. */
  238. return "Unknown error";
  239. #else
  240. if(error == CURLE_OK)
  241. return "No error";
  242. else
  243. return "Error";
  244. #endif
  245. }
  246. const char *
  247. curl_multi_strerror(CURLMcode error)
  248. {
  249. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  250. switch (error) {
  251. case CURLM_CALL_MULTI_PERFORM:
  252. return "Please call curl_multi_perform() soon";
  253. case CURLM_OK:
  254. return "No error";
  255. case CURLM_BAD_HANDLE:
  256. return "Invalid multi handle";
  257. case CURLM_BAD_EASY_HANDLE:
  258. return "Invalid easy handle";
  259. case CURLM_OUT_OF_MEMORY:
  260. return "Out of memory";
  261. case CURLM_INTERNAL_ERROR:
  262. return "Internal error";
  263. case CURLM_BAD_SOCKET:
  264. return "Invalid socket argument";
  265. case CURLM_UNKNOWN_OPTION:
  266. return "Unknown option";
  267. case CURLM_LAST:
  268. break;
  269. }
  270. return "Unknown error";
  271. #else
  272. if(error == CURLM_OK)
  273. return "No error";
  274. else
  275. return "Error";
  276. #endif
  277. }
  278. const char *
  279. curl_share_strerror(CURLSHcode error)
  280. {
  281. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  282. switch (error) {
  283. case CURLSHE_OK:
  284. return "No error";
  285. case CURLSHE_BAD_OPTION:
  286. return "Unknown share option";
  287. case CURLSHE_IN_USE:
  288. return "Share currently in use";
  289. case CURLSHE_INVALID:
  290. return "Invalid share handle";
  291. case CURLSHE_NOMEM:
  292. return "Out of memory";
  293. case CURLSHE_NOT_BUILT_IN:
  294. return "Feature not enabled in this library";
  295. case CURLSHE_LAST:
  296. break;
  297. }
  298. return "CURLSHcode unknown";
  299. #else
  300. if(error == CURLSHE_OK)
  301. return "No error";
  302. else
  303. return "Error";
  304. #endif
  305. }
  306. #ifdef USE_WINSOCK
  307. /* This function handles most / all (?) Winsock errors cURL is able to produce.
  308. */
  309. static const char *
  310. get_winsock_error (int err, char *buf, size_t len)
  311. {
  312. const char *p;
  313. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  314. switch (err) {
  315. case WSAEINTR:
  316. p = "Call interrupted";
  317. break;
  318. case WSAEBADF:
  319. p = "Bad file";
  320. break;
  321. case WSAEACCES:
  322. p = "Bad access";
  323. break;
  324. case WSAEFAULT:
  325. p = "Bad argument";
  326. break;
  327. case WSAEINVAL:
  328. p = "Invalid arguments";
  329. break;
  330. case WSAEMFILE:
  331. p = "Out of file descriptors";
  332. break;
  333. case WSAEWOULDBLOCK:
  334. p = "Call would block";
  335. break;
  336. case WSAEINPROGRESS:
  337. case WSAEALREADY:
  338. p = "Blocking call in progress";
  339. break;
  340. case WSAENOTSOCK:
  341. p = "Descriptor is not a socket";
  342. break;
  343. case WSAEDESTADDRREQ:
  344. p = "Need destination address";
  345. break;
  346. case WSAEMSGSIZE:
  347. p = "Bad message size";
  348. break;
  349. case WSAEPROTOTYPE:
  350. p = "Bad protocol";
  351. break;
  352. case WSAENOPROTOOPT:
  353. p = "Protocol option is unsupported";
  354. break;
  355. case WSAEPROTONOSUPPORT:
  356. p = "Protocol is unsupported";
  357. break;
  358. case WSAESOCKTNOSUPPORT:
  359. p = "Socket is unsupported";
  360. break;
  361. case WSAEOPNOTSUPP:
  362. p = "Operation not supported";
  363. break;
  364. case WSAEAFNOSUPPORT:
  365. p = "Address family not supported";
  366. break;
  367. case WSAEPFNOSUPPORT:
  368. p = "Protocol family not supported";
  369. break;
  370. case WSAEADDRINUSE:
  371. p = "Address already in use";
  372. break;
  373. case WSAEADDRNOTAVAIL:
  374. p = "Address not available";
  375. break;
  376. case WSAENETDOWN:
  377. p = "Network down";
  378. break;
  379. case WSAENETUNREACH:
  380. p = "Network unreachable";
  381. break;
  382. case WSAENETRESET:
  383. p = "Network has been reset";
  384. break;
  385. case WSAECONNABORTED:
  386. p = "Connection was aborted";
  387. break;
  388. case WSAECONNRESET:
  389. p = "Connection was reset";
  390. break;
  391. case WSAENOBUFS:
  392. p = "No buffer space";
  393. break;
  394. case WSAEISCONN:
  395. p = "Socket is already connected";
  396. break;
  397. case WSAENOTCONN:
  398. p = "Socket is not connected";
  399. break;
  400. case WSAESHUTDOWN:
  401. p = "Socket has been shut down";
  402. break;
  403. case WSAETOOMANYREFS:
  404. p = "Too many references";
  405. break;
  406. case WSAETIMEDOUT:
  407. p = "Timed out";
  408. break;
  409. case WSAECONNREFUSED:
  410. p = "Connection refused";
  411. break;
  412. case WSAELOOP:
  413. p = "Loop??";
  414. break;
  415. case WSAENAMETOOLONG:
  416. p = "Name too long";
  417. break;
  418. case WSAEHOSTDOWN:
  419. p = "Host down";
  420. break;
  421. case WSAEHOSTUNREACH:
  422. p = "Host unreachable";
  423. break;
  424. case WSAENOTEMPTY:
  425. p = "Not empty";
  426. break;
  427. case WSAEPROCLIM:
  428. p = "Process limit reached";
  429. break;
  430. case WSAEUSERS:
  431. p = "Too many users";
  432. break;
  433. case WSAEDQUOT:
  434. p = "Bad quota";
  435. break;
  436. case WSAESTALE:
  437. p = "Something is stale";
  438. break;
  439. case WSAEREMOTE:
  440. p = "Remote error";
  441. break;
  442. #ifdef WSAEDISCON /* missing in SalfordC! */
  443. case WSAEDISCON:
  444. p = "Disconnected";
  445. break;
  446. #endif
  447. /* Extended Winsock errors */
  448. case WSASYSNOTREADY:
  449. p = "Winsock library is not ready";
  450. break;
  451. case WSANOTINITIALISED:
  452. p = "Winsock library not initialised";
  453. break;
  454. case WSAVERNOTSUPPORTED:
  455. p = "Winsock version not supported";
  456. break;
  457. /* getXbyY() errors (already handled in herrmsg):
  458. * Authoritative Answer: Host not found */
  459. case WSAHOST_NOT_FOUND:
  460. p = "Host not found";
  461. break;
  462. /* Non-Authoritative: Host not found, or SERVERFAIL */
  463. case WSATRY_AGAIN:
  464. p = "Host not found, try again";
  465. break;
  466. /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
  467. case WSANO_RECOVERY:
  468. p = "Unrecoverable error in call to nameserver";
  469. break;
  470. /* Valid name, no data record of requested type */
  471. case WSANO_DATA:
  472. p = "No data record of requested type";
  473. break;
  474. default:
  475. return NULL;
  476. }
  477. #else
  478. if(err == CURLE_OK)
  479. return NULL;
  480. else
  481. p = "error";
  482. #endif
  483. strncpy (buf, p, len);
  484. buf [len-1] = '\0';
  485. return buf;
  486. }
  487. #endif /* USE_WINSOCK */
  488. /*
  489. * Our thread-safe and smart strerror() replacement.
  490. *
  491. * The 'err' argument passed in to this function MUST be a true errno number
  492. * as reported on this system. We do no range checking on the number before
  493. * we pass it to the "number-to-message" conversion function and there might
  494. * be systems that don't do proper range checking in there themselves.
  495. *
  496. * We don't do range checking (on systems other than Windows) since there is
  497. * no good reliable and portable way to do it.
  498. */
  499. const char *Curl_strerror(struct connectdata *conn, int err)
  500. {
  501. char *buf, *p;
  502. size_t max;
  503. int old_errno = ERRNO;
  504. DEBUGASSERT(conn);
  505. DEBUGASSERT(err >= 0);
  506. buf = conn->syserr_buf;
  507. max = sizeof(conn->syserr_buf)-1;
  508. *buf = '\0';
  509. #ifdef USE_WINSOCK
  510. #ifdef _WIN32_WCE
  511. {
  512. wchar_t wbuf[256];
  513. wbuf[0] = L'\0';
  514. FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
  515. LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
  516. wcstombs(buf,wbuf,max);
  517. }
  518. #else
  519. /* 'sys_nerr' is the maximum errno number, it is not widely portable */
  520. if(err >= 0 && err < sys_nerr)
  521. strncpy(buf, strerror(err), max);
  522. else {
  523. if(!get_winsock_error(err, buf, max) &&
  524. !FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
  525. LANG_NEUTRAL, buf, (DWORD)max, NULL))
  526. snprintf(buf, max, "Unknown error %d (%#x)", err, err);
  527. }
  528. #endif
  529. #else /* not USE_WINSOCK coming up */
  530. #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
  531. /*
  532. * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
  533. * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
  534. * message string, or EINVAL if 'errnum' is not a valid error number.
  535. */
  536. if(0 != strerror_r(err, buf, max)) {
  537. if('\0' == buf[0])
  538. snprintf(buf, max, "Unknown error %d", err);
  539. }
  540. #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
  541. /*
  542. * The glibc-style strerror_r() only *might* use the buffer we pass to
  543. * the function, but it always returns the error message as a pointer,
  544. * so we must copy that string unconditionally (if non-NULL).
  545. */
  546. {
  547. char buffer[256];
  548. char *msg = strerror_r(err, buffer, sizeof(buffer));
  549. if(msg)
  550. strncpy(buf, msg, max);
  551. else
  552. snprintf(buf, max, "Unknown error %d", err);
  553. }
  554. #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
  555. /*
  556. * The vxworks-style strerror_r() does use the buffer we pass to the function.
  557. * The buffer size should be at least MAXERRSTR_SIZE (150) defined in rtsold.h
  558. */
  559. {
  560. char buffer[256];
  561. if(OK == strerror_r(err, buffer))
  562. strncpy(buf, buffer, max);
  563. else
  564. snprintf(buf, max, "Unknown error %d", err);
  565. }
  566. #else
  567. {
  568. char *msg = strerror(err);
  569. if(msg)
  570. strncpy(buf, msg, max);
  571. else
  572. snprintf(buf, max, "Unknown error %d", err);
  573. }
  574. #endif
  575. #endif /* end of ! USE_WINSOCK */
  576. buf[max] = '\0'; /* make sure the string is zero terminated */
  577. /* strip trailing '\r\n' or '\n'. */
  578. if((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
  579. *p = '\0';
  580. if((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
  581. *p = '\0';
  582. if(old_errno != ERRNO)
  583. SET_ERRNO(old_errno);
  584. return buf;
  585. }
  586. #ifdef USE_LIBIDN
  587. /*
  588. * Return error-string for libidn status as returned from idna_to_ascii_lz().
  589. */
  590. const char *Curl_idn_strerror (struct connectdata *conn, int err)
  591. {
  592. #ifdef HAVE_IDNA_STRERROR
  593. (void)conn;
  594. return idna_strerror((Idna_rc) err);
  595. #else
  596. const char *str;
  597. char *buf;
  598. size_t max;
  599. DEBUGASSERT(conn);
  600. buf = conn->syserr_buf;
  601. max = sizeof(conn->syserr_buf)-1;
  602. *buf = '\0';
  603. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  604. switch ((Idna_rc)err) {
  605. case IDNA_SUCCESS:
  606. str = "No error";
  607. break;
  608. case IDNA_STRINGPREP_ERROR:
  609. str = "Error in string preparation";
  610. break;
  611. case IDNA_PUNYCODE_ERROR:
  612. str = "Error in Punycode operation";
  613. break;
  614. case IDNA_CONTAINS_NON_LDH:
  615. str = "Illegal ASCII characters";
  616. break;
  617. case IDNA_CONTAINS_MINUS:
  618. str = "Contains minus";
  619. break;
  620. case IDNA_INVALID_LENGTH:
  621. str = "Invalid output length";
  622. break;
  623. case IDNA_NO_ACE_PREFIX:
  624. str = "No ACE prefix (\"xn--\")";
  625. break;
  626. case IDNA_ROUNDTRIP_VERIFY_ERROR:
  627. str = "Round trip verify error";
  628. break;
  629. case IDNA_CONTAINS_ACE_PREFIX:
  630. str = "Already have ACE prefix (\"xn--\")";
  631. break;
  632. case IDNA_ICONV_ERROR:
  633. str = "Locale conversion failed";
  634. break;
  635. case IDNA_MALLOC_ERROR:
  636. str = "Allocation failed";
  637. break;
  638. case IDNA_DLOPEN_ERROR:
  639. str = "dlopen() error";
  640. break;
  641. default:
  642. snprintf(buf, max, "error %d", err);
  643. str = NULL;
  644. break;
  645. }
  646. #else
  647. if((Idna_rc)err == IDNA_SUCCESS)
  648. str = "No error";
  649. else
  650. str = "Error";
  651. #endif
  652. if(str)
  653. strncpy(buf, str, max);
  654. buf[max] = '\0';
  655. return (buf);
  656. #endif
  657. }
  658. #endif /* USE_LIBIDN */
  659. #ifdef USE_WINDOWS_SSPI
  660. const char *Curl_sspi_strerror (struct connectdata *conn, int err)
  661. {
  662. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  663. char txtbuf[80];
  664. char msgbuf[sizeof(conn->syserr_buf)];
  665. char *p, *str, *msg = NULL;
  666. bool msg_formatted = FALSE;
  667. int old_errno;
  668. #endif
  669. const char *txt;
  670. char *outbuf;
  671. size_t outmax;
  672. DEBUGASSERT(conn);
  673. outbuf = conn->syserr_buf;
  674. outmax = sizeof(conn->syserr_buf)-1;
  675. *outbuf = '\0';
  676. #ifndef CURL_DISABLE_VERBOSE_STRINGS
  677. old_errno = ERRNO;
  678. switch (err) {
  679. case SEC_E_OK:
  680. txt = "No error";
  681. break;
  682. case SEC_E_ALGORITHM_MISMATCH:
  683. txt = "SEC_E_ALGORITHM_MISMATCH";
  684. break;
  685. case SEC_E_BAD_BINDINGS:
  686. txt = "SEC_E_BAD_BINDINGS";
  687. break;
  688. case SEC_E_BAD_PKGID:
  689. txt = "SEC_E_BAD_PKGID";
  690. break;
  691. case SEC_E_BUFFER_TOO_SMALL:
  692. txt = "SEC_E_BUFFER_TOO_SMALL";
  693. break;
  694. case SEC_E_CANNOT_INSTALL:
  695. txt = "SEC_E_CANNOT_INSTALL";
  696. break;
  697. case SEC_E_CANNOT_PACK:
  698. txt = "SEC_E_CANNOT_PACK";
  699. break;
  700. case SEC_E_CERT_EXPIRED:
  701. txt = "SEC_E_CERT_EXPIRED";
  702. break;
  703. case SEC_E_CERT_UNKNOWN:
  704. txt = "SEC_E_CERT_UNKNOWN";
  705. break;
  706. case SEC_E_CERT_WRONG_USAGE:
  707. txt = "SEC_E_CERT_WRONG_USAGE";
  708. break;
  709. case SEC_E_CONTEXT_EXPIRED:
  710. txt = "SEC_E_CONTEXT_EXPIRED";
  711. break;
  712. case SEC_E_CROSSREALM_DELEGATION_FAILURE:
  713. txt = "SEC_E_CROSSREALM_DELEGATION_FAILURE";
  714. break;
  715. case SEC_E_CRYPTO_SYSTEM_INVALID:
  716. txt = "SEC_E_CRYPTO_SYSTEM_INVALID";
  717. break;
  718. case SEC_E_DECRYPT_FAILURE:
  719. txt = "SEC_E_DECRYPT_FAILURE";
  720. break;
  721. case SEC_E_DELEGATION_POLICY:
  722. txt = "SEC_E_DELEGATION_POLICY";
  723. break;
  724. case SEC_E_DELEGATION_REQUIRED:
  725. txt = "SEC_E_DELEGATION_REQUIRED";
  726. break;
  727. case SEC_E_DOWNGRADE_DETECTED:
  728. txt = "SEC_E_DOWNGRADE_DETECTED";
  729. break;
  730. case SEC_E_ENCRYPT_FAILURE:
  731. txt = "SEC_E_ENCRYPT_FAILURE";
  732. break;
  733. case SEC_E_ILLEGAL_MESSAGE:
  734. txt = "SEC_E_ILLEGAL_MESSAGE";
  735. break;
  736. case SEC_E_INCOMPLETE_CREDENTIALS:
  737. txt = "SEC_E_INCOMPLETE_CREDENTIALS";
  738. break;
  739. case SEC_E_INCOMPLETE_MESSAGE:
  740. txt = "SEC_E_INCOMPLETE_MESSAGE";
  741. break;
  742. case SEC_E_INSUFFICIENT_MEMORY:
  743. txt = "SEC_E_INSUFFICIENT_MEMORY";
  744. break;
  745. case SEC_E_INTERNAL_ERROR:
  746. txt = "SEC_E_INTERNAL_ERROR";
  747. break;
  748. case SEC_E_INVALID_HANDLE:
  749. txt = "SEC_E_INVALID_HANDLE";
  750. break;
  751. case SEC_E_INVALID_PARAMETER:
  752. txt = "SEC_E_INVALID_PARAMETER";
  753. break;
  754. case SEC_E_INVALID_TOKEN:
  755. txt = "SEC_E_INVALID_TOKEN";
  756. break;
  757. case SEC_E_ISSUING_CA_UNTRUSTED:
  758. txt = "SEC_E_ISSUING_CA_UNTRUSTED";
  759. break;
  760. case SEC_E_ISSUING_CA_UNTRUSTED_KDC:
  761. txt = "SEC_E_ISSUING_CA_UNTRUSTED_KDC";
  762. break;
  763. case SEC_E_KDC_CERT_EXPIRED:
  764. txt = "SEC_E_KDC_CERT_EXPIRED";
  765. break;
  766. case SEC_E_KDC_CERT_REVOKED:
  767. txt = "SEC_E_KDC_CERT_REVOKED";
  768. break;
  769. case SEC_E_KDC_INVALID_REQUEST:
  770. txt = "SEC_E_KDC_INVALID_REQUEST";
  771. break;
  772. case SEC_E_KDC_UNABLE_TO_REFER:
  773. txt = "SEC_E_KDC_UNABLE_TO_REFER";
  774. break;
  775. case SEC_E_KDC_UNKNOWN_ETYPE:
  776. txt = "SEC_E_KDC_UNKNOWN_ETYPE";
  777. break;
  778. case SEC_E_LOGON_DENIED:
  779. txt = "SEC_E_LOGON_DENIED";
  780. break;
  781. case SEC_E_MAX_REFERRALS_EXCEEDED:
  782. txt = "SEC_E_MAX_REFERRALS_EXCEEDED";
  783. break;
  784. case SEC_E_MESSAGE_ALTERED:
  785. txt = "SEC_E_MESSAGE_ALTERED";
  786. break;
  787. case SEC_E_MULTIPLE_ACCOUNTS:
  788. txt = "SEC_E_MULTIPLE_ACCOUNTS";
  789. break;
  790. case SEC_E_MUST_BE_KDC:
  791. txt = "SEC_E_MUST_BE_KDC";
  792. break;
  793. case SEC_E_NOT_OWNER:
  794. txt = "SEC_E_NOT_OWNER";
  795. break;
  796. case SEC_E_NO_AUTHENTICATING_AUTHORITY:
  797. txt = "SEC_E_NO_AUTHENTICATING_AUTHORITY";
  798. break;
  799. case SEC_E_NO_CREDENTIALS:
  800. txt = "SEC_E_NO_CREDENTIALS";
  801. break;
  802. case SEC_E_NO_IMPERSONATION:
  803. txt = "SEC_E_NO_IMPERSONATION";
  804. break;
  805. case SEC_E_NO_IP_ADDRESSES:
  806. txt = "SEC_E_NO_IP_ADDRESSES";
  807. break;
  808. case SEC_E_NO_KERB_KEY:
  809. txt = "SEC_E_NO_KERB_KEY";
  810. break;
  811. case SEC_E_NO_PA_DATA:
  812. txt = "SEC_E_NO_PA_DATA";
  813. break;
  814. case SEC_E_NO_S4U_PROT_SUPPORT:
  815. txt = "SEC_E_NO_S4U_PROT_SUPPORT";
  816. break;
  817. case SEC_E_NO_TGT_REPLY:
  818. txt = "SEC_E_NO_TGT_REPLY";
  819. break;
  820. case SEC_E_OUT_OF_SEQUENCE:
  821. txt = "SEC_E_OUT_OF_SEQUENCE";
  822. break;
  823. case SEC_E_PKINIT_CLIENT_FAILURE:
  824. txt = "SEC_E_PKINIT_CLIENT_FAILURE";
  825. break;
  826. case SEC_E_PKINIT_NAME_MISMATCH:
  827. txt = "SEC_E_PKINIT_NAME_MISMATCH";
  828. break;
  829. case SEC_E_POLICY_NLTM_ONLY:
  830. txt = "SEC_E_POLICY_NLTM_ONLY";
  831. break;
  832. case SEC_E_QOP_NOT_SUPPORTED:
  833. txt = "SEC_E_QOP_NOT_SUPPORTED";
  834. break;
  835. case SEC_E_REVOCATION_OFFLINE_C:
  836. txt = "SEC_E_REVOCATION_OFFLINE_C";
  837. break;
  838. case SEC_E_REVOCATION_OFFLINE_KDC:
  839. txt = "SEC_E_REVOCATION_OFFLINE_KDC";
  840. break;
  841. case SEC_E_SECPKG_NOT_FOUND:
  842. txt = "SEC_E_SECPKG_NOT_FOUND";
  843. break;
  844. case SEC_E_SECURITY_QOS_FAILED:
  845. txt = "SEC_E_SECURITY_QOS_FAILED";
  846. break;
  847. case SEC_E_SHUTDOWN_IN_PROGRESS:
  848. txt = "SEC_E_SHUTDOWN_IN_PROGRESS";
  849. break;
  850. case SEC_E_SMARTCARD_CERT_EXPIRED:
  851. txt = "SEC_E_SMARTCARD_CERT_EXPIRED";
  852. break;
  853. case SEC_E_SMARTCARD_CERT_REVOKED:
  854. txt = "SEC_E_SMARTCARD_CERT_REVOKED";
  855. break;
  856. case SEC_E_SMARTCARD_LOGON_REQUIRED:
  857. txt = "SEC_E_SMARTCARD_LOGON_REQUIRED";
  858. break;
  859. case SEC_E_STRONG_CRYPTO_NOT_SUPPORTED:
  860. txt = "SEC_E_STRONG_CRYPTO_NOT_SUPPORTED";
  861. break;
  862. case SEC_E_TARGET_UNKNOWN:
  863. txt = "SEC_E_TARGET_UNKNOWN";
  864. break;
  865. case SEC_E_TIME_SKEW:
  866. txt = "SEC_E_TIME_SKEW";
  867. break;
  868. case SEC_E_TOO_MANY_PRINCIPALS:
  869. txt = "SEC_E_TOO_MANY_PRINCIPALS";
  870. break;
  871. case SEC_E_UNFINISHED_CONTEXT_DELETED:
  872. txt = "SEC_E_UNFINISHED_CONTEXT_DELETED";
  873. break;
  874. case SEC_E_UNKNOWN_CREDENTIALS:
  875. txt = "SEC_E_UNKNOWN_CREDENTIALS";
  876. break;
  877. case SEC_E_UNSUPPORTED_FUNCTION:
  878. txt = "SEC_E_UNSUPPORTED_FUNCTION";
  879. break;
  880. case SEC_E_UNSUPPORTED_PREAUTH:
  881. txt = "SEC_E_UNSUPPORTED_PREAUTH";
  882. break;
  883. case SEC_E_UNTRUSTED_ROOT:
  884. txt = "SEC_E_UNTRUSTED_ROOT";
  885. break;
  886. case SEC_E_WRONG_CREDENTIAL_HANDLE:
  887. txt = "SEC_E_WRONG_CREDENTIAL_HANDLE";
  888. break;
  889. case SEC_E_WRONG_PRINCIPAL:
  890. txt = "SEC_E_WRONG_PRINCIPAL";
  891. break;
  892. case SEC_I_COMPLETE_AND_CONTINUE:
  893. txt = "SEC_I_COMPLETE_AND_CONTINUE";
  894. break;
  895. case SEC_I_COMPLETE_NEEDED:
  896. txt = "SEC_I_COMPLETE_NEEDED";
  897. break;
  898. case SEC_I_CONTEXT_EXPIRED:
  899. txt = "SEC_I_CONTEXT_EXPIRED";
  900. break;
  901. case SEC_I_CONTINUE_NEEDED:
  902. txt = "SEC_I_CONTINUE_NEEDED";
  903. break;
  904. case SEC_I_INCOMPLETE_CREDENTIALS:
  905. txt = "SEC_I_INCOMPLETE_CREDENTIALS";
  906. break;
  907. case SEC_I_LOCAL_LOGON:
  908. txt = "SEC_I_LOCAL_LOGON";
  909. break;
  910. case SEC_I_NO_LSA_CONTEXT:
  911. txt = "SEC_I_NO_LSA_CONTEXT";
  912. break;
  913. case SEC_I_RENEGOTIATE:
  914. txt = "SEC_I_RENEGOTIATE";
  915. break;
  916. case SEC_I_SIGNATURE_NEEDED:
  917. txt = "SEC_I_SIGNATURE_NEEDED";
  918. break;
  919. default:
  920. txt = "Unknown error";
  921. }
  922. if(err == SEC_E_OK)
  923. strncpy(outbuf, txt, outmax);
  924. else {
  925. str = txtbuf;
  926. snprintf(txtbuf, sizeof(txtbuf), "%s (0x%04X%04X)",
  927. txt, (err >> 16) & 0xffff, err & 0xffff);
  928. txtbuf[sizeof(txtbuf)-1] = '\0';
  929. #ifdef _WIN32_WCE
  930. {
  931. wchar_t wbuf[256];
  932. wbuf[0] = L'\0';
  933. if(FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM |
  934. FORMAT_MESSAGE_IGNORE_INSERTS,
  935. NULL, err, LANG_NEUTRAL,
  936. wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL)) {
  937. wcstombs(msgbuf,wbuf,sizeof(msgbuf)-1);
  938. msg_formatted = TRUE;
  939. }
  940. }
  941. #else
  942. if(FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM |
  943. FORMAT_MESSAGE_IGNORE_INSERTS,
  944. NULL, err, LANG_NEUTRAL,
  945. msgbuf, sizeof(msgbuf)-1, NULL)) {
  946. msg_formatted = TRUE;
  947. }
  948. #endif
  949. if(msg_formatted) {
  950. msgbuf[sizeof(msgbuf)-1] = '\0';
  951. /* strip trailing '\r\n' or '\n' */
  952. if((p = strrchr(msgbuf,'\n')) != NULL && (p - msgbuf) >= 2)
  953. *p = '\0';
  954. if((p = strrchr(msgbuf,'\r')) != NULL && (p - msgbuf) >= 1)
  955. *p = '\0';
  956. msg = msgbuf;
  957. }
  958. if(msg)
  959. snprintf(outbuf, outmax, "%s - %s", str, msg);
  960. else
  961. strncpy(outbuf, str, outmax);
  962. }
  963. if(old_errno != ERRNO)
  964. SET_ERRNO(old_errno);
  965. #else
  966. if(err == SEC_E_OK)
  967. txt = "No error";
  968. else
  969. txt = "Error";
  970. strncpy(outbuf, txt, outmax);
  971. #endif
  972. outbuf[outmax] = '\0';
  973. return outbuf;
  974. }
  975. #endif /* USE_WINDOWS_SSPI */