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-style, glibc-style or vxworks-style"
36 #include <curl/curl.h>
47 #define _MPRINTF_REPLACE /* use our functions only */
48 #include <curl/mprintf.h>
52 curl_easy_strerror(CURLcode error)
54 #ifndef CURL_DISABLE_VERBOSE_STRINGS
59 case CURLE_UNSUPPORTED_PROTOCOL:
60 return "Unsupported protocol";
62 case CURLE_FAILED_INIT:
63 return "Failed initialization";
65 case CURLE_URL_MALFORMAT:
66 return "URL using bad/illegal format or missing URL";
68 case CURLE_NOT_BUILT_IN:
69 return "A requested feature, protocol or option was not found built-in in"
70 " this libcurl due to a build-time decision.";
72 case CURLE_COULDNT_RESOLVE_PROXY:
73 return "Couldn't resolve proxy name";
75 case CURLE_COULDNT_RESOLVE_HOST:
76 return "Couldn't resolve host name";
78 case CURLE_COULDNT_CONNECT:
79 return "Couldn't connect to server";
81 case CURLE_FTP_WEIRD_SERVER_REPLY:
82 return "FTP: weird server reply";
84 case CURLE_REMOTE_ACCESS_DENIED:
85 return "Access denied to remote resource";
87 case CURLE_FTP_PRET_FAILED:
88 return "FTP: The server did not accept the PRET command.";
90 case CURLE_FTP_WEIRD_PASS_REPLY:
91 return "FTP: unknown PASS reply";
93 case CURLE_FTP_WEIRD_PASV_REPLY:
94 return "FTP: unknown PASV reply";
96 case CURLE_FTP_WEIRD_227_FORMAT:
97 return "FTP: unknown 227 response format";
99 case CURLE_FTP_CANT_GET_HOST:
100 return "FTP: can't figure out the host in the PASV response";
102 case CURLE_FTP_COULDNT_SET_TYPE:
103 return "FTP: couldn't set file type";
105 case CURLE_PARTIAL_FILE:
106 return "Transferred a partial file";
108 case CURLE_FTP_COULDNT_RETR_FILE:
109 return "FTP: couldn't retrieve (RETR failed) the specified file";
111 case CURLE_QUOTE_ERROR:
112 return "Quote command returned error";
114 case CURLE_HTTP_RETURNED_ERROR:
115 return "HTTP response code said error";
117 case CURLE_WRITE_ERROR:
118 return "Failed writing received data to disk/application";
120 case CURLE_UPLOAD_FAILED:
121 return "Upload failed (at start/before it took off)";
123 case CURLE_READ_ERROR:
124 return "Failed to open/read local data from file/application";
126 case CURLE_OUT_OF_MEMORY:
127 return "Out of memory";
129 case CURLE_OPERATION_TIMEDOUT:
130 return "Timeout was reached";
132 case CURLE_FTP_PORT_FAILED:
133 return "FTP: command PORT failed";
135 case CURLE_FTP_COULDNT_USE_REST:
136 return "FTP: command REST failed";
138 case CURLE_RANGE_ERROR:
139 return "Requested range was not delivered by the server";
141 case CURLE_HTTP_POST_ERROR:
142 return "Internal problem setting up the POST";
144 case CURLE_SSL_CONNECT_ERROR:
145 return "SSL connect error";
147 case CURLE_BAD_DOWNLOAD_RESUME:
148 return "Couldn't resume download";
150 case CURLE_FILE_COULDNT_READ_FILE:
151 return "Couldn't read a file:// file";
153 case CURLE_LDAP_CANNOT_BIND:
154 return "LDAP: cannot bind";
156 case CURLE_LDAP_SEARCH_FAILED:
157 return "LDAP: search failed";
159 case CURLE_FUNCTION_NOT_FOUND:
160 return "A required function in the library was not found";
162 case CURLE_ABORTED_BY_CALLBACK:
163 return "Operation was aborted by an application callback";
165 case CURLE_BAD_FUNCTION_ARGUMENT:
166 return "A libcurl function was given a bad argument";
168 case CURLE_INTERFACE_FAILED:
169 return "Failed binding local connection end";
171 case CURLE_TOO_MANY_REDIRECTS :
172 return "Number of redirects hit maximum amount";
174 case CURLE_UNKNOWN_OPTION:
175 return "An unknown option was passed in to libcurl";
177 case CURLE_TELNET_OPTION_SYNTAX :
178 return "Malformed telnet option";
180 case CURLE_PEER_FAILED_VERIFICATION:
181 return "SSL peer certificate or SSH remote key was not OK";
183 case CURLE_GOT_NOTHING:
184 return "Server returned nothing (no headers, no data)";
186 case CURLE_SSL_ENGINE_NOTFOUND:
187 return "SSL crypto engine not found";
189 case CURLE_SSL_ENGINE_SETFAILED:
190 return "Can not set SSL crypto engine as default";
192 case CURLE_SSL_ENGINE_INITFAILED:
193 return "Failed to initialise SSL crypto engine";
195 case CURLE_SEND_ERROR:
196 return "Failed sending data to the peer";
198 case CURLE_RECV_ERROR:
199 return "Failure when receiving data from the peer";
201 case CURLE_SSL_CERTPROBLEM:
202 return "Problem with the local SSL certificate";
204 case CURLE_SSL_CIPHER:
205 return "Couldn't use specified SSL cipher";
207 case CURLE_SSL_CACERT:
208 return "Peer certificate cannot be authenticated with known CA certificates";
210 case CURLE_SSL_CACERT_BADFILE:
211 return "Problem with the SSL CA cert (path? access rights?)";
213 case CURLE_BAD_CONTENT_ENCODING:
214 return "Unrecognized HTTP Content-Encoding";
216 case CURLE_LDAP_INVALID_URL:
217 return "Invalid LDAP URL";
219 case CURLE_FILESIZE_EXCEEDED:
220 return "Maximum file size exceeded";
222 case CURLE_USE_SSL_FAILED:
223 return "Requested SSL level failed";
225 case CURLE_SSL_SHUTDOWN_FAILED:
226 return "Failed to shut down the SSL connection";
228 case CURLE_SSL_CRL_BADFILE:
229 return "Failed to load CRL file (path? access rights?, format?)";
231 case CURLE_SSL_ISSUER_ERROR:
232 return "Issuer check against peer certificate failed";
234 case CURLE_SEND_FAIL_REWIND:
235 return "Send failed since rewinding of the data stream failed";
237 case CURLE_LOGIN_DENIED:
238 return "Login denied";
240 case CURLE_TFTP_NOTFOUND:
241 return "TFTP: File Not Found";
243 case CURLE_TFTP_PERM:
244 return "TFTP: Access Violation";
246 case CURLE_REMOTE_DISK_FULL:
247 return "Disk full or allocation exceeded";
249 case CURLE_TFTP_ILLEGAL:
250 return "TFTP: Illegal operation";
252 case CURLE_TFTP_UNKNOWNID:
253 return "TFTP: Unknown transfer ID";
255 case CURLE_REMOTE_FILE_EXISTS:
256 return "Remote file already exists";
258 case CURLE_TFTP_NOSUCHUSER:
259 return "TFTP: No such user";
261 case CURLE_CONV_FAILED:
262 return "Conversion failed";
264 case CURLE_CONV_REQD:
265 return "Caller must register CURLOPT_CONV_ callback options";
267 case CURLE_REMOTE_FILE_NOT_FOUND:
268 return "Remote file not found";
271 return "Error in the SSH layer";
274 return "Socket not ready for send/recv";
276 case CURLE_RTSP_CSEQ_ERROR:
277 return "RTSP CSeq mismatch or invalid CSeq";
279 case CURLE_RTSP_SESSION_ERROR:
280 return "RTSP session error";
282 case CURLE_FTP_BAD_FILE_LIST:
283 return "Unable to parse FTP file list";
285 case CURLE_CHUNK_FAILED:
286 return "Chunk callback failed";
288 /* error codes not used by current libcurl */
289 case CURLE_OBSOLETE10:
290 case CURLE_OBSOLETE12:
291 case CURLE_OBSOLETE16:
292 case CURLE_OBSOLETE20:
293 case CURLE_OBSOLETE24:
294 case CURLE_OBSOLETE29:
295 case CURLE_OBSOLETE32:
296 case CURLE_OBSOLETE40:
297 case CURLE_OBSOLETE44:
298 case CURLE_OBSOLETE46:
299 case CURLE_OBSOLETE50:
300 case CURLE_OBSOLETE57:
305 * By using a switch, gcc -Wall will complain about enum values
306 * which do not appear, helping keep this function up-to-date.
307 * By using gcc -Wall -Werror, you can't forget.
309 * A table would not have the same benefit. Most compilers will
310 * generate code very similar to a table in any case, so there
311 * is little performance gain from a table. And something is broken
312 * for the user's application, anyways, so does it matter how fast
315 * The line number for the error will be near this comment, which
316 * is why it is here, and not at the start of the switch.
318 return "Unknown error";
320 if(error == CURLE_OK)
328 curl_multi_strerror(CURLMcode error)
330 #ifndef CURL_DISABLE_VERBOSE_STRINGS
332 case CURLM_CALL_MULTI_PERFORM:
333 return "Please call curl_multi_perform() soon";
338 case CURLM_BAD_HANDLE:
339 return "Invalid multi handle";
341 case CURLM_BAD_EASY_HANDLE:
342 return "Invalid easy handle";
344 case CURLM_OUT_OF_MEMORY:
345 return "Out of memory";
347 case CURLM_INTERNAL_ERROR:
348 return "Internal error";
350 case CURLM_BAD_SOCKET:
351 return "Invalid socket argument";
353 case CURLM_UNKNOWN_OPTION:
354 return "Unknown option";
360 return "Unknown error";
362 if(error == CURLM_OK)
370 curl_share_strerror(CURLSHcode error)
372 #ifndef CURL_DISABLE_VERBOSE_STRINGS
377 case CURLSHE_BAD_OPTION:
378 return "Unknown share option";
381 return "Share currently in use";
383 case CURLSHE_INVALID:
384 return "Invalid share handle";
387 return "Out of memory";
393 return "CURLSHcode unknown";
395 if(error == CURLSHE_OK)
404 /* This function handles most / all (?) Winsock errors cURL is able to produce.
407 get_winsock_error (int err, char *buf, size_t len)
411 #ifndef CURL_DISABLE_VERBOSE_STRINGS
414 p = "Call interrupted";
426 p = "Invalid arguments";
429 p = "Out of file descriptors";
432 p = "Call would block";
436 p = "Blocking call in progress";
439 p = "Descriptor is not a socket";
441 case WSAEDESTADDRREQ:
442 p = "Need destination address";
445 p = "Bad message size";
451 p = "Protocol option is unsupported";
453 case WSAEPROTONOSUPPORT:
454 p = "Protocol is unsupported";
456 case WSAESOCKTNOSUPPORT:
457 p = "Socket is unsupported";
460 p = "Operation not supported";
462 case WSAEAFNOSUPPORT:
463 p = "Address family not supported";
465 case WSAEPFNOSUPPORT:
466 p = "Protocol family not supported";
469 p = "Address already in use";
471 case WSAEADDRNOTAVAIL:
472 p = "Address not available";
478 p = "Network unreachable";
481 p = "Network has been reset";
483 case WSAECONNABORTED:
484 p = "Connection was aborted";
487 p = "Connection was reset";
490 p = "No buffer space";
493 p = "Socket is already connected";
496 p = "Socket is not connected";
499 p = "Socket has been shut down";
501 case WSAETOOMANYREFS:
502 p = "Too many references";
507 case WSAECONNREFUSED:
508 p = "Connection refused";
513 case WSAENAMETOOLONG:
519 case WSAEHOSTUNREACH:
520 p = "Host unreachable";
526 p = "Process limit reached";
529 p = "Too many users";
535 p = "Something is stale";
540 #ifdef WSAEDISCON /* missing in SalfordC! */
545 /* Extended Winsock errors */
547 p = "Winsock library is not ready";
549 case WSANOTINITIALISED:
550 p = "Winsock library not initialised";
552 case WSAVERNOTSUPPORTED:
553 p = "Winsock version not supported";
556 /* getXbyY() errors (already handled in herrmsg):
557 * Authoritative Answer: Host not found */
558 case WSAHOST_NOT_FOUND:
559 p = "Host not found";
562 /* Non-Authoritative: Host not found, or SERVERFAIL */
564 p = "Host not found, try again";
567 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
569 p = "Unrecoverable error in call to nameserver";
572 /* Valid name, no data record of requested type */
574 p = "No data record of requested type";
586 strncpy (buf, p, len);
590 #endif /* USE_WINSOCK */
593 * Our thread-safe and smart strerror() replacement.
595 * The 'err' argument passed in to this function MUST be a true errno number
596 * as reported on this system. We do no range checking on the number before
597 * we pass it to the "number-to-message" conversion function and there might
598 * be systems that don't do proper range checking in there themselves.
600 * We don't do range checking (on systems other than Windows) since there is
601 * no good reliable and portable way to do it.
603 const char *Curl_strerror(struct connectdata *conn, int err)
607 int old_errno = ERRNO;
610 DEBUGASSERT(err >= 0);
612 buf = conn->syserr_buf;
613 max = sizeof(conn->syserr_buf)-1;
623 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
624 LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
625 wcstombs(buf,wbuf,max);
628 /* 'sys_nerr' is the maximum errno number, it is not widely portable */
629 if(err >= 0 && err < sys_nerr)
630 strncpy(buf, strerror(err), max);
632 if(!get_winsock_error(err, buf, max) &&
633 !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
634 LANG_NEUTRAL, buf, (DWORD)max, NULL))
635 snprintf(buf, max, "Unknown error %d (%#x)", err, err);
639 #else /* not USE_WINSOCK coming up */
641 #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
643 * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
644 * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
645 * message string, or EINVAL if 'errnum' is not a valid error number.
647 if(0 != strerror_r(err, buf, max)) {
649 snprintf(buf, max, "Unknown error %d", err);
651 #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
653 * The glibc-style strerror_r() only *might* use the buffer we pass to
654 * the function, but it always returns the error message as a pointer,
655 * so we must copy that string unconditionally (if non-NULL).
659 char *msg = strerror_r(err, buffer, sizeof(buffer));
661 strncpy(buf, msg, max);
663 snprintf(buf, max, "Unknown error %d", err);
665 #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
667 * The vxworks-style strerror_r() does use the buffer we pass to the function.
668 * The buffer size should be at least MAXERRSTR_SIZE (150) defined in rtsold.h
672 if(OK == strerror_r(err, buffer))
673 strncpy(buf, buffer, max);
675 snprintf(buf, max, "Unknown error %d", err);
679 char *msg = strerror(err);
681 strncpy(buf, msg, max);
683 snprintf(buf, max, "Unknown error %d", err);
687 #endif /* end of ! USE_WINSOCK */
689 buf[max] = '\0'; /* make sure the string is zero terminated */
691 /* strip trailing '\r\n' or '\n'. */
692 if((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
694 if((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
697 if(old_errno != ERRNO)
698 SET_ERRNO(old_errno);
705 * Return error-string for libidn status as returned from idna_to_ascii_lz().
707 const char *Curl_idn_strerror (struct connectdata *conn, int err)
709 #ifdef HAVE_IDNA_STRERROR
711 return idna_strerror((Idna_rc) err);
719 buf = conn->syserr_buf;
720 max = sizeof(conn->syserr_buf)-1;
723 #ifndef CURL_DISABLE_VERBOSE_STRINGS
724 switch ((Idna_rc)err) {
728 case IDNA_STRINGPREP_ERROR:
729 str = "Error in string preparation";
731 case IDNA_PUNYCODE_ERROR:
732 str = "Error in Punycode operation";
734 case IDNA_CONTAINS_NON_LDH:
735 str = "Illegal ASCII characters";
737 case IDNA_CONTAINS_MINUS:
738 str = "Contains minus";
740 case IDNA_INVALID_LENGTH:
741 str = "Invalid output length";
743 case IDNA_NO_ACE_PREFIX:
744 str = "No ACE prefix (\"xn--\")";
746 case IDNA_ROUNDTRIP_VERIFY_ERROR:
747 str = "Round trip verify error";
749 case IDNA_CONTAINS_ACE_PREFIX:
750 str = "Already have ACE prefix (\"xn--\")";
752 case IDNA_ICONV_ERROR:
753 str = "Locale conversion failed";
755 case IDNA_MALLOC_ERROR:
756 str = "Allocation failed";
758 case IDNA_DLOPEN_ERROR:
759 str = "dlopen() error";
762 snprintf(buf, max, "error %d", err);
767 if((Idna_rc)err == IDNA_SUCCESS)
773 strncpy(buf, str, max);
778 #endif /* USE_LIBIDN */