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_ACCEPT_FAILED:
85 return "FTP: The server failed to connect to data port";
87 case CURLE_FTP_ACCEPT_TIMEOUT:
88 return "FTP: Accepting server connect has timed out";
90 case CURLE_FTP_PRET_FAILED:
91 return "FTP: The server did not accept the PRET command.";
93 case CURLE_FTP_WEIRD_PASS_REPLY:
94 return "FTP: unknown PASS reply";
96 case CURLE_FTP_WEIRD_PASV_REPLY:
97 return "FTP: unknown PASV reply";
99 case CURLE_FTP_WEIRD_227_FORMAT:
100 return "FTP: unknown 227 response format";
102 case CURLE_FTP_CANT_GET_HOST:
103 return "FTP: can't figure out the host in the PASV response";
105 case CURLE_FTP_COULDNT_SET_TYPE:
106 return "FTP: couldn't set file type";
108 case CURLE_PARTIAL_FILE:
109 return "Transferred a partial file";
111 case CURLE_FTP_COULDNT_RETR_FILE:
112 return "FTP: couldn't retrieve (RETR failed) the specified file";
114 case CURLE_QUOTE_ERROR:
115 return "Quote command returned error";
117 case CURLE_HTTP_RETURNED_ERROR:
118 return "HTTP response code said error";
120 case CURLE_WRITE_ERROR:
121 return "Failed writing received data to disk/application";
123 case CURLE_UPLOAD_FAILED:
124 return "Upload failed (at start/before it took off)";
126 case CURLE_READ_ERROR:
127 return "Failed to open/read local data from file/application";
129 case CURLE_OUT_OF_MEMORY:
130 return "Out of memory";
132 case CURLE_OPERATION_TIMEDOUT:
133 return "Timeout was reached";
135 case CURLE_FTP_PORT_FAILED:
136 return "FTP: command PORT failed";
138 case CURLE_FTP_COULDNT_USE_REST:
139 return "FTP: command REST failed";
141 case CURLE_RANGE_ERROR:
142 return "Requested range was not delivered by the server";
144 case CURLE_HTTP_POST_ERROR:
145 return "Internal problem setting up the POST";
147 case CURLE_SSL_CONNECT_ERROR:
148 return "SSL connect error";
150 case CURLE_BAD_DOWNLOAD_RESUME:
151 return "Couldn't resume download";
153 case CURLE_FILE_COULDNT_READ_FILE:
154 return "Couldn't read a file:// file";
156 case CURLE_LDAP_CANNOT_BIND:
157 return "LDAP: cannot bind";
159 case CURLE_LDAP_SEARCH_FAILED:
160 return "LDAP: search failed";
162 case CURLE_FUNCTION_NOT_FOUND:
163 return "A required function in the library was not found";
165 case CURLE_ABORTED_BY_CALLBACK:
166 return "Operation was aborted by an application callback";
168 case CURLE_BAD_FUNCTION_ARGUMENT:
169 return "A libcurl function was given a bad argument";
171 case CURLE_INTERFACE_FAILED:
172 return "Failed binding local connection end";
174 case CURLE_TOO_MANY_REDIRECTS :
175 return "Number of redirects hit maximum amount";
177 case CURLE_UNKNOWN_OPTION:
178 return "An unknown option was passed in to libcurl";
180 case CURLE_TELNET_OPTION_SYNTAX :
181 return "Malformed telnet option";
183 case CURLE_PEER_FAILED_VERIFICATION:
184 return "SSL peer certificate or SSH remote key was not OK";
186 case CURLE_GOT_NOTHING:
187 return "Server returned nothing (no headers, no data)";
189 case CURLE_SSL_ENGINE_NOTFOUND:
190 return "SSL crypto engine not found";
192 case CURLE_SSL_ENGINE_SETFAILED:
193 return "Can not set SSL crypto engine as default";
195 case CURLE_SSL_ENGINE_INITFAILED:
196 return "Failed to initialise SSL crypto engine";
198 case CURLE_SEND_ERROR:
199 return "Failed sending data to the peer";
201 case CURLE_RECV_ERROR:
202 return "Failure when receiving data from the peer";
204 case CURLE_SSL_CERTPROBLEM:
205 return "Problem with the local SSL certificate";
207 case CURLE_SSL_CIPHER:
208 return "Couldn't use specified SSL cipher";
210 case CURLE_SSL_CACERT:
211 return "Peer certificate cannot be authenticated with given CA "
214 case CURLE_SSL_CACERT_BADFILE:
215 return "Problem with the SSL CA cert (path? access rights?)";
217 case CURLE_BAD_CONTENT_ENCODING:
218 return "Unrecognized or bad HTTP Content or Transfer-Encoding";
220 case CURLE_LDAP_INVALID_URL:
221 return "Invalid LDAP URL";
223 case CURLE_FILESIZE_EXCEEDED:
224 return "Maximum file size exceeded";
226 case CURLE_USE_SSL_FAILED:
227 return "Requested SSL level failed";
229 case CURLE_SSL_SHUTDOWN_FAILED:
230 return "Failed to shut down the SSL connection";
232 case CURLE_SSL_CRL_BADFILE:
233 return "Failed to load CRL file (path? access rights?, format?)";
235 case CURLE_SSL_ISSUER_ERROR:
236 return "Issuer check against peer certificate failed";
238 case CURLE_SEND_FAIL_REWIND:
239 return "Send failed since rewinding of the data stream failed";
241 case CURLE_LOGIN_DENIED:
242 return "Login denied";
244 case CURLE_TFTP_NOTFOUND:
245 return "TFTP: File Not Found";
247 case CURLE_TFTP_PERM:
248 return "TFTP: Access Violation";
250 case CURLE_REMOTE_DISK_FULL:
251 return "Disk full or allocation exceeded";
253 case CURLE_TFTP_ILLEGAL:
254 return "TFTP: Illegal operation";
256 case CURLE_TFTP_UNKNOWNID:
257 return "TFTP: Unknown transfer ID";
259 case CURLE_REMOTE_FILE_EXISTS:
260 return "Remote file already exists";
262 case CURLE_TFTP_NOSUCHUSER:
263 return "TFTP: No such user";
265 case CURLE_CONV_FAILED:
266 return "Conversion failed";
268 case CURLE_CONV_REQD:
269 return "Caller must register CURLOPT_CONV_ callback options";
271 case CURLE_REMOTE_FILE_NOT_FOUND:
272 return "Remote file not found";
275 return "Error in the SSH layer";
278 return "Socket not ready for send/recv";
280 case CURLE_RTSP_CSEQ_ERROR:
281 return "RTSP CSeq mismatch or invalid CSeq";
283 case CURLE_RTSP_SESSION_ERROR:
284 return "RTSP session error";
286 case CURLE_FTP_BAD_FILE_LIST:
287 return "Unable to parse FTP file list";
289 case CURLE_CHUNK_FAILED:
290 return "Chunk callback failed";
292 /* error codes not used by current libcurl */
293 case CURLE_OBSOLETE16:
294 case CURLE_OBSOLETE20:
295 case CURLE_OBSOLETE24:
296 case CURLE_OBSOLETE29:
297 case CURLE_OBSOLETE32:
298 case CURLE_OBSOLETE40:
299 case CURLE_OBSOLETE44:
300 case CURLE_OBSOLETE46:
301 case CURLE_OBSOLETE50:
302 case CURLE_OBSOLETE57:
307 * By using a switch, gcc -Wall will complain about enum values
308 * which do not appear, helping keep this function up-to-date.
309 * By using gcc -Wall -Werror, you can't forget.
311 * A table would not have the same benefit. Most compilers will
312 * generate code very similar to a table in any case, so there
313 * is little performance gain from a table. And something is broken
314 * for the user's application, anyways, so does it matter how fast
317 * The line number for the error will be near this comment, which
318 * is why it is here, and not at the start of the switch.
320 return "Unknown error";
322 if(error == CURLE_OK)
330 curl_multi_strerror(CURLMcode error)
332 #ifndef CURL_DISABLE_VERBOSE_STRINGS
334 case CURLM_CALL_MULTI_PERFORM:
335 return "Please call curl_multi_perform() soon";
340 case CURLM_BAD_HANDLE:
341 return "Invalid multi handle";
343 case CURLM_BAD_EASY_HANDLE:
344 return "Invalid easy handle";
346 case CURLM_OUT_OF_MEMORY:
347 return "Out of memory";
349 case CURLM_INTERNAL_ERROR:
350 return "Internal error";
352 case CURLM_BAD_SOCKET:
353 return "Invalid socket argument";
355 case CURLM_UNKNOWN_OPTION:
356 return "Unknown option";
362 return "Unknown error";
364 if(error == CURLM_OK)
372 curl_share_strerror(CURLSHcode error)
374 #ifndef CURL_DISABLE_VERBOSE_STRINGS
379 case CURLSHE_BAD_OPTION:
380 return "Unknown share option";
383 return "Share currently in use";
385 case CURLSHE_INVALID:
386 return "Invalid share handle";
389 return "Out of memory";
391 case CURLSHE_NOT_BUILT_IN:
392 return "Feature not enabled in this library";
398 return "CURLSHcode unknown";
400 if(error == CURLSHE_OK)
409 /* This function handles most / all (?) Winsock errors cURL is able to produce.
412 get_winsock_error (int err, char *buf, size_t len)
416 #ifndef CURL_DISABLE_VERBOSE_STRINGS
419 p = "Call interrupted";
431 p = "Invalid arguments";
434 p = "Out of file descriptors";
437 p = "Call would block";
441 p = "Blocking call in progress";
444 p = "Descriptor is not a socket";
446 case WSAEDESTADDRREQ:
447 p = "Need destination address";
450 p = "Bad message size";
456 p = "Protocol option is unsupported";
458 case WSAEPROTONOSUPPORT:
459 p = "Protocol is unsupported";
461 case WSAESOCKTNOSUPPORT:
462 p = "Socket is unsupported";
465 p = "Operation not supported";
467 case WSAEAFNOSUPPORT:
468 p = "Address family not supported";
470 case WSAEPFNOSUPPORT:
471 p = "Protocol family not supported";
474 p = "Address already in use";
476 case WSAEADDRNOTAVAIL:
477 p = "Address not available";
483 p = "Network unreachable";
486 p = "Network has been reset";
488 case WSAECONNABORTED:
489 p = "Connection was aborted";
492 p = "Connection was reset";
495 p = "No buffer space";
498 p = "Socket is already connected";
501 p = "Socket is not connected";
504 p = "Socket has been shut down";
506 case WSAETOOMANYREFS:
507 p = "Too many references";
512 case WSAECONNREFUSED:
513 p = "Connection refused";
518 case WSAENAMETOOLONG:
524 case WSAEHOSTUNREACH:
525 p = "Host unreachable";
531 p = "Process limit reached";
534 p = "Too many users";
540 p = "Something is stale";
545 #ifdef WSAEDISCON /* missing in SalfordC! */
550 /* Extended Winsock errors */
552 p = "Winsock library is not ready";
554 case WSANOTINITIALISED:
555 p = "Winsock library not initialised";
557 case WSAVERNOTSUPPORTED:
558 p = "Winsock version not supported";
561 /* getXbyY() errors (already handled in herrmsg):
562 * Authoritative Answer: Host not found */
563 case WSAHOST_NOT_FOUND:
564 p = "Host not found";
567 /* Non-Authoritative: Host not found, or SERVERFAIL */
569 p = "Host not found, try again";
572 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
574 p = "Unrecoverable error in call to nameserver";
577 /* Valid name, no data record of requested type */
579 p = "No data record of requested type";
591 strncpy (buf, p, len);
595 #endif /* USE_WINSOCK */
598 * Our thread-safe and smart strerror() replacement.
600 * The 'err' argument passed in to this function MUST be a true errno number
601 * as reported on this system. We do no range checking on the number before
602 * we pass it to the "number-to-message" conversion function and there might
603 * be systems that don't do proper range checking in there themselves.
605 * We don't do range checking (on systems other than Windows) since there is
606 * no good reliable and portable way to do it.
608 const char *Curl_strerror(struct connectdata *conn, int err)
612 int old_errno = ERRNO;
615 DEBUGASSERT(err >= 0);
617 buf = conn->syserr_buf;
618 max = sizeof(conn->syserr_buf)-1;
628 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
629 LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
630 wcstombs(buf,wbuf,max);
633 /* 'sys_nerr' is the maximum errno number, it is not widely portable */
634 if(err >= 0 && err < sys_nerr)
635 strncpy(buf, strerror(err), max);
637 if(!get_winsock_error(err, buf, max) &&
638 !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
639 LANG_NEUTRAL, buf, (DWORD)max, NULL))
640 snprintf(buf, max, "Unknown error %d (%#x)", err, err);
644 #else /* not USE_WINSOCK coming up */
646 #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
648 * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
649 * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
650 * message string, or EINVAL if 'errnum' is not a valid error number.
652 if(0 != strerror_r(err, buf, max)) {
654 snprintf(buf, max, "Unknown error %d", err);
656 #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
658 * The glibc-style strerror_r() only *might* use the buffer we pass to
659 * the function, but it always returns the error message as a pointer,
660 * so we must copy that string unconditionally (if non-NULL).
664 char *msg = strerror_r(err, buffer, sizeof(buffer));
666 strncpy(buf, msg, max);
668 snprintf(buf, max, "Unknown error %d", err);
670 #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
672 * The vxworks-style strerror_r() does use the buffer we pass to the function.
673 * The buffer size should be at least MAXERRSTR_SIZE (150) defined in rtsold.h
677 if(OK == strerror_r(err, buffer))
678 strncpy(buf, buffer, max);
680 snprintf(buf, max, "Unknown error %d", err);
684 char *msg = strerror(err);
686 strncpy(buf, msg, max);
688 snprintf(buf, max, "Unknown error %d", err);
692 #endif /* end of ! USE_WINSOCK */
694 buf[max] = '\0'; /* make sure the string is zero terminated */
696 /* strip trailing '\r\n' or '\n'. */
697 if((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
699 if((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
702 if(old_errno != ERRNO)
703 SET_ERRNO(old_errno);
710 * Return error-string for libidn status as returned from idna_to_ascii_lz().
712 const char *Curl_idn_strerror (struct connectdata *conn, int err)
714 #ifdef HAVE_IDNA_STRERROR
716 return idna_strerror((Idna_rc) err);
724 buf = conn->syserr_buf;
725 max = sizeof(conn->syserr_buf)-1;
728 #ifndef CURL_DISABLE_VERBOSE_STRINGS
729 switch ((Idna_rc)err) {
733 case IDNA_STRINGPREP_ERROR:
734 str = "Error in string preparation";
736 case IDNA_PUNYCODE_ERROR:
737 str = "Error in Punycode operation";
739 case IDNA_CONTAINS_NON_LDH:
740 str = "Illegal ASCII characters";
742 case IDNA_CONTAINS_MINUS:
743 str = "Contains minus";
745 case IDNA_INVALID_LENGTH:
746 str = "Invalid output length";
748 case IDNA_NO_ACE_PREFIX:
749 str = "No ACE prefix (\"xn--\")";
751 case IDNA_ROUNDTRIP_VERIFY_ERROR:
752 str = "Round trip verify error";
754 case IDNA_CONTAINS_ACE_PREFIX:
755 str = "Already have ACE prefix (\"xn--\")";
757 case IDNA_ICONV_ERROR:
758 str = "Locale conversion failed";
760 case IDNA_MALLOC_ERROR:
761 str = "Allocation failed";
763 case IDNA_DLOPEN_ERROR:
764 str = "dlopen() error";
767 snprintf(buf, max, "error %d", err);
772 if((Idna_rc)err == IDNA_SUCCESS)
778 strncpy(buf, str, max);
783 #endif /* USE_LIBIDN */