1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 2004 - 2011, Daniel Stenberg, <daniel@haxx.se>, et al.
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.
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.
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
21 ***************************************************************************/
25 #ifdef HAVE_STRERROR_R
26 # if (!defined(HAVE_POSIX_STRERROR_R) && \
27 !defined(HAVE_GLIBC_STRERROR_R) && \
28 !defined(HAVE_VXWORKS_STRERROR_R)) || \
29 (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
30 (defined(HAVE_GLIBC_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)) || \
31 (defined(HAVE_POSIX_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R))
32 # error "strerror_r MUST be either POSIX, glibc or vxworks-style"
36 #include <curl/curl.h>
44 #define _MPRINTF_REPLACE /* use our functions only */
45 #include <curl/mprintf.h>
49 curl_easy_strerror(CURLcode error)
51 #ifndef CURL_DISABLE_VERBOSE_STRINGS
56 case CURLE_UNSUPPORTED_PROTOCOL:
57 return "Unsupported protocol";
59 case CURLE_FAILED_INIT:
60 return "Failed initialization";
62 case CURLE_URL_MALFORMAT:
63 return "URL using bad/illegal format or missing URL";
65 case CURLE_NOT_BUILT_IN:
66 return "A requested feature, protocol or option was not found built-in in"
67 " this libcurl due to a build-time decision.";
69 case CURLE_COULDNT_RESOLVE_PROXY:
70 return "Couldn't resolve proxy name";
72 case CURLE_COULDNT_RESOLVE_HOST:
73 return "Couldn't resolve host name";
75 case CURLE_COULDNT_CONNECT:
76 return "Couldn't connect to server";
78 case CURLE_FTP_WEIRD_SERVER_REPLY:
79 return "FTP: weird server reply";
81 case CURLE_REMOTE_ACCESS_DENIED:
82 return "Access denied to remote resource";
84 case CURLE_FTP_PRET_FAILED:
85 return "FTP: The server did not accept the PRET command.";
87 case CURLE_FTP_WEIRD_PASS_REPLY:
88 return "FTP: unknown PASS reply";
90 case CURLE_FTP_WEIRD_PASV_REPLY:
91 return "FTP: unknown PASV reply";
93 case CURLE_FTP_WEIRD_227_FORMAT:
94 return "FTP: unknown 227 response format";
96 case CURLE_FTP_CANT_GET_HOST:
97 return "FTP: can't figure out the host in the PASV response";
99 case CURLE_FTP_COULDNT_SET_TYPE:
100 return "FTP: couldn't set file type";
102 case CURLE_PARTIAL_FILE:
103 return "Transferred a partial file";
105 case CURLE_FTP_COULDNT_RETR_FILE:
106 return "FTP: couldn't retrieve (RETR failed) the specified file";
108 case CURLE_QUOTE_ERROR:
109 return "Quote command returned error";
111 case CURLE_HTTP_RETURNED_ERROR:
112 return "HTTP response code said error";
114 case CURLE_WRITE_ERROR:
115 return "Failed writing received data to disk/application";
117 case CURLE_UPLOAD_FAILED:
118 return "Upload failed (at start/before it took off)";
120 case CURLE_READ_ERROR:
121 return "Failed to open/read local data from file/application";
123 case CURLE_OUT_OF_MEMORY:
124 return "Out of memory";
126 case CURLE_OPERATION_TIMEDOUT:
127 return "Timeout was reached";
129 case CURLE_FTP_PORT_FAILED:
130 return "FTP: command PORT failed";
132 case CURLE_FTP_COULDNT_USE_REST:
133 return "FTP: command REST failed";
135 case CURLE_RANGE_ERROR:
136 return "Requested range was not delivered by the server";
138 case CURLE_HTTP_POST_ERROR:
139 return "Internal problem setting up the POST";
141 case CURLE_SSL_CONNECT_ERROR:
142 return "SSL connect error";
144 case CURLE_BAD_DOWNLOAD_RESUME:
145 return "Couldn't resume download";
147 case CURLE_FILE_COULDNT_READ_FILE:
148 return "Couldn't read a file:// file";
150 case CURLE_LDAP_CANNOT_BIND:
151 return "LDAP: cannot bind";
153 case CURLE_LDAP_SEARCH_FAILED:
154 return "LDAP: search failed";
156 case CURLE_FUNCTION_NOT_FOUND:
157 return "A required function in the library was not found";
159 case CURLE_ABORTED_BY_CALLBACK:
160 return "Operation was aborted by an application callback";
162 case CURLE_BAD_FUNCTION_ARGUMENT:
163 return "A libcurl function was given a bad argument";
165 case CURLE_INTERFACE_FAILED:
166 return "Failed binding local connection end";
168 case CURLE_TOO_MANY_REDIRECTS :
169 return "Number of redirects hit maximum amount";
171 case CURLE_UNKNOWN_OPTION:
172 return "An unknown option was passed in to libcurl";
174 case CURLE_TELNET_OPTION_SYNTAX :
175 return "Malformed telnet option";
177 case CURLE_PEER_FAILED_VERIFICATION:
178 return "SSL peer certificate or SSH remote key was not OK";
180 case CURLE_GOT_NOTHING:
181 return "Server returned nothing (no headers, no data)";
183 case CURLE_SSL_ENGINE_NOTFOUND:
184 return "SSL crypto engine not found";
186 case CURLE_SSL_ENGINE_SETFAILED:
187 return "Can not set SSL crypto engine as default";
189 case CURLE_SSL_ENGINE_INITFAILED:
190 return "Failed to initialise SSL crypto engine";
192 case CURLE_SEND_ERROR:
193 return "Failed sending data to the peer";
195 case CURLE_RECV_ERROR:
196 return "Failure when receiving data from the peer";
198 case CURLE_SSL_CERTPROBLEM:
199 return "Problem with the local SSL certificate";
201 case CURLE_SSL_CIPHER:
202 return "Couldn't use specified SSL cipher";
204 case CURLE_SSL_CACERT:
205 return "Peer certificate cannot be authenticated with given CA "
208 case CURLE_SSL_CACERT_BADFILE:
209 return "Problem with the SSL CA cert (path? access rights?)";
211 case CURLE_BAD_CONTENT_ENCODING:
212 return "Unrecognized or bad HTTP Content or Transfer-Encoding";
214 case CURLE_LDAP_INVALID_URL:
215 return "Invalid LDAP URL";
217 case CURLE_FILESIZE_EXCEEDED:
218 return "Maximum file size exceeded";
220 case CURLE_USE_SSL_FAILED:
221 return "Requested SSL level failed";
223 case CURLE_SSL_SHUTDOWN_FAILED:
224 return "Failed to shut down the SSL connection";
226 case CURLE_SSL_CRL_BADFILE:
227 return "Failed to load CRL file (path? access rights?, format?)";
229 case CURLE_SSL_ISSUER_ERROR:
230 return "Issuer check against peer certificate failed";
232 case CURLE_SEND_FAIL_REWIND:
233 return "Send failed since rewinding of the data stream failed";
235 case CURLE_LOGIN_DENIED:
236 return "Login denied";
238 case CURLE_TFTP_NOTFOUND:
239 return "TFTP: File Not Found";
241 case CURLE_TFTP_PERM:
242 return "TFTP: Access Violation";
244 case CURLE_REMOTE_DISK_FULL:
245 return "Disk full or allocation exceeded";
247 case CURLE_TFTP_ILLEGAL:
248 return "TFTP: Illegal operation";
250 case CURLE_TFTP_UNKNOWNID:
251 return "TFTP: Unknown transfer ID";
253 case CURLE_REMOTE_FILE_EXISTS:
254 return "Remote file already exists";
256 case CURLE_TFTP_NOSUCHUSER:
257 return "TFTP: No such user";
259 case CURLE_CONV_FAILED:
260 return "Conversion failed";
262 case CURLE_CONV_REQD:
263 return "Caller must register CURLOPT_CONV_ callback options";
265 case CURLE_REMOTE_FILE_NOT_FOUND:
266 return "Remote file not found";
269 return "Error in the SSH layer";
272 return "Socket not ready for send/recv";
274 case CURLE_RTSP_CSEQ_ERROR:
275 return "RTSP CSeq mismatch or invalid CSeq";
277 case CURLE_RTSP_SESSION_ERROR:
278 return "RTSP session error";
280 case CURLE_FTP_BAD_FILE_LIST:
281 return "Unable to parse FTP file list";
283 case CURLE_CHUNK_FAILED:
284 return "Chunk callback failed";
286 /* error codes not used by current libcurl */
287 case CURLE_OBSOLETE10:
288 case CURLE_OBSOLETE12:
289 case CURLE_OBSOLETE16:
290 case CURLE_OBSOLETE20:
291 case CURLE_OBSOLETE24:
292 case CURLE_OBSOLETE29:
293 case CURLE_OBSOLETE32:
294 case CURLE_OBSOLETE40:
295 case CURLE_OBSOLETE44:
296 case CURLE_OBSOLETE46:
297 case CURLE_OBSOLETE50:
298 case CURLE_OBSOLETE57:
303 * By using a switch, gcc -Wall will complain about enum values
304 * which do not appear, helping keep this function up-to-date.
305 * By using gcc -Wall -Werror, you can't forget.
307 * A table would not have the same benefit. Most compilers will
308 * generate code very similar to a table in any case, so there
309 * is little performance gain from a table. And something is broken
310 * for the user's application, anyways, so does it matter how fast
313 * The line number for the error will be near this comment, which
314 * is why it is here, and not at the start of the switch.
316 return "Unknown error";
318 if(error == CURLE_OK)
326 curl_multi_strerror(CURLMcode error)
328 #ifndef CURL_DISABLE_VERBOSE_STRINGS
330 case CURLM_CALL_MULTI_PERFORM:
331 return "Please call curl_multi_perform() soon";
336 case CURLM_BAD_HANDLE:
337 return "Invalid multi handle";
339 case CURLM_BAD_EASY_HANDLE:
340 return "Invalid easy handle";
342 case CURLM_OUT_OF_MEMORY:
343 return "Out of memory";
345 case CURLM_INTERNAL_ERROR:
346 return "Internal error";
348 case CURLM_BAD_SOCKET:
349 return "Invalid socket argument";
351 case CURLM_UNKNOWN_OPTION:
352 return "Unknown option";
358 return "Unknown error";
360 if(error == CURLM_OK)
368 curl_share_strerror(CURLSHcode error)
370 #ifndef CURL_DISABLE_VERBOSE_STRINGS
375 case CURLSHE_BAD_OPTION:
376 return "Unknown share option";
379 return "Share currently in use";
381 case CURLSHE_INVALID:
382 return "Invalid share handle";
385 return "Out of memory";
387 case CURLSHE_NOT_BUILT_IN:
388 return "Feature not enabled in this library";
394 return "CURLSHcode unknown";
396 if(error == CURLSHE_OK)
405 /* This function handles most / all (?) Winsock errors cURL is able to produce.
408 get_winsock_error (int err, char *buf, size_t len)
412 #ifndef CURL_DISABLE_VERBOSE_STRINGS
415 p = "Call interrupted";
427 p = "Invalid arguments";
430 p = "Out of file descriptors";
433 p = "Call would block";
437 p = "Blocking call in progress";
440 p = "Descriptor is not a socket";
442 case WSAEDESTADDRREQ:
443 p = "Need destination address";
446 p = "Bad message size";
452 p = "Protocol option is unsupported";
454 case WSAEPROTONOSUPPORT:
455 p = "Protocol is unsupported";
457 case WSAESOCKTNOSUPPORT:
458 p = "Socket is unsupported";
461 p = "Operation not supported";
463 case WSAEAFNOSUPPORT:
464 p = "Address family not supported";
466 case WSAEPFNOSUPPORT:
467 p = "Protocol family not supported";
470 p = "Address already in use";
472 case WSAEADDRNOTAVAIL:
473 p = "Address not available";
479 p = "Network unreachable";
482 p = "Network has been reset";
484 case WSAECONNABORTED:
485 p = "Connection was aborted";
488 p = "Connection was reset";
491 p = "No buffer space";
494 p = "Socket is already connected";
497 p = "Socket is not connected";
500 p = "Socket has been shut down";
502 case WSAETOOMANYREFS:
503 p = "Too many references";
508 case WSAECONNREFUSED:
509 p = "Connection refused";
514 case WSAENAMETOOLONG:
520 case WSAEHOSTUNREACH:
521 p = "Host unreachable";
527 p = "Process limit reached";
530 p = "Too many users";
536 p = "Something is stale";
541 #ifdef WSAEDISCON /* missing in SalfordC! */
546 /* Extended Winsock errors */
548 p = "Winsock library is not ready";
550 case WSANOTINITIALISED:
551 p = "Winsock library not initialised";
553 case WSAVERNOTSUPPORTED:
554 p = "Winsock version not supported";
557 /* getXbyY() errors (already handled in herrmsg):
558 * Authoritative Answer: Host not found */
559 case WSAHOST_NOT_FOUND:
560 p = "Host not found";
563 /* Non-Authoritative: Host not found, or SERVERFAIL */
565 p = "Host not found, try again";
568 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
570 p = "Unrecoverable error in call to nameserver";
573 /* Valid name, no data record of requested type */
575 p = "No data record of requested type";
587 strncpy (buf, p, len);
591 #endif /* USE_WINSOCK */
594 * Our thread-safe and smart strerror() replacement.
596 * The 'err' argument passed in to this function MUST be a true errno number
597 * as reported on this system. We do no range checking on the number before
598 * we pass it to the "number-to-message" conversion function and there might
599 * be systems that don't do proper range checking in there themselves.
601 * We don't do range checking (on systems other than Windows) since there is
602 * no good reliable and portable way to do it.
604 const char *Curl_strerror(struct connectdata *conn, int err)
608 int old_errno = ERRNO;
611 DEBUGASSERT(err >= 0);
613 buf = conn->syserr_buf;
614 max = sizeof(conn->syserr_buf)-1;
624 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
625 LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
626 wcstombs(buf,wbuf,max);
629 /* 'sys_nerr' is the maximum errno number, it is not widely portable */
630 if(err >= 0 && err < sys_nerr)
631 strncpy(buf, strerror(err), max);
633 if(!get_winsock_error(err, buf, max) &&
634 !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
635 LANG_NEUTRAL, buf, (DWORD)max, NULL))
636 snprintf(buf, max, "Unknown error %d (%#x)", err, err);
640 #else /* not USE_WINSOCK coming up */
642 #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
644 * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
645 * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
646 * message string, or EINVAL if 'errnum' is not a valid error number.
648 if(0 != strerror_r(err, buf, max)) {
650 snprintf(buf, max, "Unknown error %d", err);
652 #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
654 * The glibc-style strerror_r() only *might* use the buffer we pass to
655 * the function, but it always returns the error message as a pointer,
656 * so we must copy that string unconditionally (if non-NULL).
660 char *msg = strerror_r(err, buffer, sizeof(buffer));
662 strncpy(buf, msg, max);
664 snprintf(buf, max, "Unknown error %d", err);
666 #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
668 * The vxworks-style strerror_r() does use the buffer we pass to the function.
669 * The buffer size should be at least MAXERRSTR_SIZE (150) defined in rtsold.h
673 if(OK == strerror_r(err, buffer))
674 strncpy(buf, buffer, max);
676 snprintf(buf, max, "Unknown error %d", err);
680 char *msg = strerror(err);
682 strncpy(buf, msg, max);
684 snprintf(buf, max, "Unknown error %d", err);
688 #endif /* end of ! USE_WINSOCK */
690 buf[max] = '\0'; /* make sure the string is zero terminated */
692 /* strip trailing '\r\n' or '\n'. */
693 if((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
695 if((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
698 if(old_errno != ERRNO)
699 SET_ERRNO(old_errno);
706 * Return error-string for libidn status as returned from idna_to_ascii_lz().
708 const char *Curl_idn_strerror (struct connectdata *conn, int err)
710 #ifdef HAVE_IDNA_STRERROR
712 return idna_strerror((Idna_rc) err);
720 buf = conn->syserr_buf;
721 max = sizeof(conn->syserr_buf)-1;
724 #ifndef CURL_DISABLE_VERBOSE_STRINGS
725 switch ((Idna_rc)err) {
729 case IDNA_STRINGPREP_ERROR:
730 str = "Error in string preparation";
732 case IDNA_PUNYCODE_ERROR:
733 str = "Error in Punycode operation";
735 case IDNA_CONTAINS_NON_LDH:
736 str = "Illegal ASCII characters";
738 case IDNA_CONTAINS_MINUS:
739 str = "Contains minus";
741 case IDNA_INVALID_LENGTH:
742 str = "Invalid output length";
744 case IDNA_NO_ACE_PREFIX:
745 str = "No ACE prefix (\"xn--\")";
747 case IDNA_ROUNDTRIP_VERIFY_ERROR:
748 str = "Round trip verify error";
750 case IDNA_CONTAINS_ACE_PREFIX:
751 str = "Already have ACE prefix (\"xn--\")";
753 case IDNA_ICONV_ERROR:
754 str = "Locale conversion failed";
756 case IDNA_MALLOC_ERROR:
757 str = "Allocation failed";
759 case IDNA_DLOPEN_ERROR:
760 str = "dlopen() error";
763 snprintf(buf, max, "error %d", err);
768 if((Idna_rc)err == IDNA_SUCCESS)
774 strncpy(buf, str, max);
779 #endif /* USE_LIBIDN */