1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 2004 - 2010, 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_COULDNT_RESOLVE_PROXY:
69 return "Couldn't resolve proxy name";
71 case CURLE_COULDNT_RESOLVE_HOST:
72 return "Couldn't resolve host name";
74 case CURLE_COULDNT_CONNECT:
75 return "Couldn't connect to server";
77 case CURLE_FTP_WEIRD_SERVER_REPLY:
78 return "FTP: weird server reply";
80 case CURLE_REMOTE_ACCESS_DENIED:
81 return "Access denied to remote resource";
83 case CURLE_FTP_PRET_FAILED:
84 return "FTP: The server did not accept the PRET command.";
86 case CURLE_FTP_WEIRD_PASS_REPLY:
87 return "FTP: unknown PASS reply";
89 case CURLE_FTP_WEIRD_PASV_REPLY:
90 return "FTP: unknown PASV reply";
92 case CURLE_FTP_WEIRD_227_FORMAT:
93 return "FTP: unknown 227 response format";
95 case CURLE_FTP_CANT_GET_HOST:
96 return "FTP: can't figure out the host in the PASV response";
98 case CURLE_FTP_COULDNT_SET_TYPE:
99 return "FTP: couldn't set file type";
101 case CURLE_PARTIAL_FILE:
102 return "Transferred a partial file";
104 case CURLE_FTP_COULDNT_RETR_FILE:
105 return "FTP: couldn't retrieve (RETR failed) the specified file";
107 case CURLE_QUOTE_ERROR:
108 return "Quote command returned error";
110 case CURLE_HTTP_RETURNED_ERROR:
111 return "HTTP response code said error";
113 case CURLE_WRITE_ERROR:
114 return "Failed writing received data to disk/application";
116 case CURLE_UPLOAD_FAILED:
117 return "Upload failed (at start/before it took off)";
119 case CURLE_READ_ERROR:
120 return "Failed to open/read local data from file/application";
122 case CURLE_OUT_OF_MEMORY:
123 return "Out of memory";
125 case CURLE_OPERATION_TIMEDOUT:
126 return "Timeout was reached";
128 case CURLE_FTP_PORT_FAILED:
129 return "FTP: command PORT failed";
131 case CURLE_FTP_COULDNT_USE_REST:
132 return "FTP: command REST failed";
134 case CURLE_RANGE_ERROR:
135 return "Requested range was not delivered by the server";
137 case CURLE_HTTP_POST_ERROR:
138 return "Internal problem setting up the POST";
140 case CURLE_SSL_CONNECT_ERROR:
141 return "SSL connect error";
143 case CURLE_BAD_DOWNLOAD_RESUME:
144 return "Couldn't resume download";
146 case CURLE_FILE_COULDNT_READ_FILE:
147 return "Couldn't read a file:// file";
149 case CURLE_LDAP_CANNOT_BIND:
150 return "LDAP: cannot bind";
152 case CURLE_LDAP_SEARCH_FAILED:
153 return "LDAP: search failed";
155 case CURLE_FUNCTION_NOT_FOUND:
156 return "A required function in the library was not found";
158 case CURLE_ABORTED_BY_CALLBACK:
159 return "Operation was aborted by an application callback";
161 case CURLE_BAD_FUNCTION_ARGUMENT:
162 return "A libcurl function was given a bad argument";
164 case CURLE_INTERFACE_FAILED:
165 return "Failed binding local connection end";
167 case CURLE_TOO_MANY_REDIRECTS :
168 return "Number of redirects hit maximum amount";
170 case CURLE_UNKNOWN_TELNET_OPTION:
171 return "User specified an unknown telnet option";
173 case CURLE_TELNET_OPTION_SYNTAX :
174 return "Malformed telnet option";
176 case CURLE_PEER_FAILED_VERIFICATION:
177 return "SSL peer certificate or SSH remote key was not OK";
179 case CURLE_GOT_NOTHING:
180 return "Server returned nothing (no headers, no data)";
182 case CURLE_SSL_ENGINE_NOTFOUND:
183 return "SSL crypto engine not found";
185 case CURLE_SSL_ENGINE_SETFAILED:
186 return "Can not set SSL crypto engine as default";
188 case CURLE_SSL_ENGINE_INITFAILED:
189 return "Failed to initialise SSL crypto engine";
191 case CURLE_SEND_ERROR:
192 return "Failed sending data to the peer";
194 case CURLE_RECV_ERROR:
195 return "Failure when receiving data from the peer";
197 case CURLE_SSL_CERTPROBLEM:
198 return "Problem with the local SSL certificate";
200 case CURLE_SSL_CIPHER:
201 return "Couldn't use specified SSL cipher";
203 case CURLE_SSL_CACERT:
204 return "Peer certificate cannot be authenticated with known CA certificates";
206 case CURLE_SSL_CACERT_BADFILE:
207 return "Problem with the SSL CA cert (path? access rights?)";
209 case CURLE_BAD_CONTENT_ENCODING:
210 return "Unrecognized HTTP Content-Encoding";
212 case CURLE_LDAP_INVALID_URL:
213 return "Invalid LDAP URL";
215 case CURLE_FILESIZE_EXCEEDED:
216 return "Maximum file size exceeded";
218 case CURLE_USE_SSL_FAILED:
219 return "Requested SSL level failed";
221 case CURLE_SSL_SHUTDOWN_FAILED:
222 return "Failed to shut down the SSL connection";
224 case CURLE_SSL_CRL_BADFILE:
225 return "Failed to load CRL file (path? access rights?, format?)";
227 case CURLE_SSL_ISSUER_ERROR:
228 return "Issuer check against peer certificate failed";
230 case CURLE_SEND_FAIL_REWIND:
231 return "Send failed since rewinding of the data stream failed";
233 case CURLE_LOGIN_DENIED:
234 return "Login denied";
236 case CURLE_TFTP_NOTFOUND:
237 return "TFTP: File Not Found";
239 case CURLE_TFTP_PERM:
240 return "TFTP: Access Violation";
242 case CURLE_REMOTE_DISK_FULL:
243 return "Disk full or allocation exceeded";
245 case CURLE_TFTP_ILLEGAL:
246 return "TFTP: Illegal operation";
248 case CURLE_TFTP_UNKNOWNID:
249 return "TFTP: Unknown transfer ID";
251 case CURLE_REMOTE_FILE_EXISTS:
252 return "Remote file already exists";
254 case CURLE_TFTP_NOSUCHUSER:
255 return "TFTP: No such user";
257 case CURLE_CONV_FAILED:
258 return "Conversion failed";
260 case CURLE_CONV_REQD:
261 return "Caller must register CURLOPT_CONV_ callback options";
263 case CURLE_REMOTE_FILE_NOT_FOUND:
264 return "Remote file not found";
267 return "Error in the SSH layer";
270 return "Socket not ready for send/recv";
272 case CURLE_RTSP_CSEQ_ERROR:
273 return "RTSP CSeq mismatch or invalid CSeq";
275 case CURLE_RTSP_SESSION_ERROR:
276 return "RTSP session error";
278 case CURLE_FTP_BAD_FILE_LIST:
279 return "Unable to parse FTP file list";
281 case CURLE_CHUNK_FAILED:
282 return "Chunk callback failed";
284 /* error codes not used by current libcurl */
285 case CURLE_OBSOLETE4:
286 case CURLE_OBSOLETE10:
287 case CURLE_OBSOLETE12:
288 case CURLE_OBSOLETE16:
289 case CURLE_OBSOLETE20:
290 case CURLE_OBSOLETE24:
291 case CURLE_OBSOLETE29:
292 case CURLE_OBSOLETE32:
293 case CURLE_OBSOLETE40:
294 case CURLE_OBSOLETE44:
295 case CURLE_OBSOLETE46:
296 case CURLE_OBSOLETE50:
297 case CURLE_OBSOLETE57:
302 * By using a switch, gcc -Wall will complain about enum values
303 * which do not appear, helping keep this function up-to-date.
304 * By using gcc -Wall -Werror, you can't forget.
306 * A table would not have the same benefit. Most compilers will
307 * generate code very similar to a table in any case, so there
308 * is little performance gain from a table. And something is broken
309 * for the user's application, anyways, so does it matter how fast
312 * The line number for the error will be near this comment, which
313 * is why it is here, and not at the start of the switch.
315 return "Unknown error";
317 if(error == CURLE_OK)
325 curl_multi_strerror(CURLMcode error)
327 #ifndef CURL_DISABLE_VERBOSE_STRINGS
329 case CURLM_CALL_MULTI_PERFORM:
330 return "Please call curl_multi_perform() soon";
335 case CURLM_BAD_HANDLE:
336 return "Invalid multi handle";
338 case CURLM_BAD_EASY_HANDLE:
339 return "Invalid easy handle";
341 case CURLM_OUT_OF_MEMORY:
342 return "Out of memory";
344 case CURLM_INTERNAL_ERROR:
345 return "Internal error";
347 case CURLM_BAD_SOCKET:
348 return "Invalid socket argument";
350 case CURLM_UNKNOWN_OPTION:
351 return "Unknown option";
357 return "Unknown error";
359 if(error == CURLM_OK)
367 curl_share_strerror(CURLSHcode error)
369 #ifndef CURL_DISABLE_VERBOSE_STRINGS
374 case CURLSHE_BAD_OPTION:
375 return "Unknown share option";
378 return "Share currently in use";
380 case CURLSHE_INVALID:
381 return "Invalid share handle";
384 return "Out of memory";
390 return "CURLSHcode unknown";
392 if(error == CURLSHE_OK)
401 /* This function handles most / all (?) Winsock errors cURL is able to produce.
404 get_winsock_error (int err, char *buf, size_t len)
408 #ifndef CURL_DISABLE_VERBOSE_STRINGS
411 p = "Call interrupted";
423 p = "Invalid arguments";
426 p = "Out of file descriptors";
429 p = "Call would block";
433 p = "Blocking call in progress";
436 p = "Descriptor is not a socket";
438 case WSAEDESTADDRREQ:
439 p = "Need destination address";
442 p = "Bad message size";
448 p = "Protocol option is unsupported";
450 case WSAEPROTONOSUPPORT:
451 p = "Protocol is unsupported";
453 case WSAESOCKTNOSUPPORT:
454 p = "Socket is unsupported";
457 p = "Operation not supported";
459 case WSAEAFNOSUPPORT:
460 p = "Address family not supported";
462 case WSAEPFNOSUPPORT:
463 p = "Protocol family not supported";
466 p = "Address already in use";
468 case WSAEADDRNOTAVAIL:
469 p = "Address not available";
475 p = "Network unreachable";
478 p = "Network has been reset";
480 case WSAECONNABORTED:
481 p = "Connection was aborted";
484 p = "Connection was reset";
487 p = "No buffer space";
490 p = "Socket is already connected";
493 p = "Socket is not connected";
496 p = "Socket has been shut down";
498 case WSAETOOMANYREFS:
499 p = "Too many references";
504 case WSAECONNREFUSED:
505 p = "Connection refused";
510 case WSAENAMETOOLONG:
516 case WSAEHOSTUNREACH:
517 p = "Host unreachable";
523 p = "Process limit reached";
526 p = "Too many users";
532 p = "Something is stale";
537 #ifdef WSAEDISCON /* missing in SalfordC! */
542 /* Extended Winsock errors */
544 p = "Winsock library is not ready";
546 case WSANOTINITIALISED:
547 p = "Winsock library not initialised";
549 case WSAVERNOTSUPPORTED:
550 p = "Winsock version not supported";
553 /* getXbyY() errors (already handled in herrmsg):
554 * Authoritative Answer: Host not found */
555 case WSAHOST_NOT_FOUND:
556 p = "Host not found";
559 /* Non-Authoritative: Host not found, or SERVERFAIL */
561 p = "Host not found, try again";
564 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
566 p = "Unrecoverable error in call to nameserver";
569 /* Valid name, no data record of requested type */
571 p = "No data record of requested type";
583 strncpy (buf, p, len);
587 #endif /* USE_WINSOCK */
590 * Our thread-safe and smart strerror() replacement.
592 * The 'err' argument passed in to this function MUST be a true errno number
593 * as reported on this system. We do no range checking on the number before
594 * we pass it to the "number-to-message" conversion function and there might
595 * be systems that don't do proper range checking in there themselves.
597 * We don't do range checking (on systems other than Windows) since there is
598 * no good reliable and portable way to do it.
600 const char *Curl_strerror(struct connectdata *conn, int err)
604 int old_errno = ERRNO;
607 DEBUGASSERT(err >= 0);
609 buf = conn->syserr_buf;
610 max = sizeof(conn->syserr_buf)-1;
620 FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
621 LANG_NEUTRAL, wbuf, sizeof(wbuf)/sizeof(wchar_t), NULL);
622 wcstombs(buf,wbuf,max);
625 /* 'sys_nerr' is the maximum errno number, it is not widely portable */
626 if(err >= 0 && err < sys_nerr)
627 strncpy(buf, strerror(err), max);
629 if(!get_winsock_error(err, buf, max) &&
630 !FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
631 LANG_NEUTRAL, buf, (DWORD)max, NULL))
632 snprintf(buf, max, "Unknown error %d (%#x)", err, err);
636 #else /* not USE_WINSOCK coming up */
638 #if defined(HAVE_STRERROR_R) && defined(HAVE_POSIX_STRERROR_R)
640 * The POSIX-style strerror_r() may set errno to ERANGE if insufficient
641 * storage is supplied via 'strerrbuf' and 'buflen' to hold the generated
642 * message string, or EINVAL if 'errnum' is not a valid error number.
644 if(0 != strerror_r(err, buf, max)) {
646 snprintf(buf, max, "Unknown error %d", err);
648 #elif defined(HAVE_STRERROR_R) && defined(HAVE_GLIBC_STRERROR_R)
650 * The glibc-style strerror_r() only *might* use the buffer we pass to
651 * the function, but it always returns the error message as a pointer,
652 * so we must copy that string unconditionally (if non-NULL).
656 char *msg = strerror_r(err, buffer, sizeof(buffer));
658 strncpy(buf, msg, max);
660 snprintf(buf, max, "Unknown error %d", err);
662 #elif defined(HAVE_STRERROR_R) && defined(HAVE_VXWORKS_STRERROR_R)
664 * The vxworks-style strerror_r() does use the buffer we pass to the function.
665 * The buffer size should be at least MAXERRSTR_SIZE (150) defined in rtsold.h
669 if(OK == strerror_r(err, buffer))
670 strncpy(buf, buffer, max);
672 snprintf(buf, max, "Unknown error %d", err);
676 char *msg = strerror(err);
678 strncpy(buf, msg, max);
680 snprintf(buf, max, "Unknown error %d", err);
684 #endif /* end of ! USE_WINSOCK */
686 buf[max] = '\0'; /* make sure the string is zero terminated */
688 /* strip trailing '\r\n' or '\n'. */
689 if((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
691 if((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)
694 if(old_errno != ERRNO)
695 SET_ERRNO(old_errno);
702 * Return error-string for libidn status as returned from idna_to_ascii_lz().
704 const char *Curl_idn_strerror (struct connectdata *conn, int err)
706 #ifdef HAVE_IDNA_STRERROR
708 return idna_strerror((Idna_rc) err);
716 buf = conn->syserr_buf;
717 max = sizeof(conn->syserr_buf)-1;
720 #ifndef CURL_DISABLE_VERBOSE_STRINGS
721 switch ((Idna_rc)err) {
725 case IDNA_STRINGPREP_ERROR:
726 str = "Error in string preparation";
728 case IDNA_PUNYCODE_ERROR:
729 str = "Error in Punycode operation";
731 case IDNA_CONTAINS_NON_LDH:
732 str = "Illegal ASCII characters";
734 case IDNA_CONTAINS_MINUS:
735 str = "Contains minus";
737 case IDNA_INVALID_LENGTH:
738 str = "Invalid output length";
740 case IDNA_NO_ACE_PREFIX:
741 str = "No ACE prefix (\"xn--\")";
743 case IDNA_ROUNDTRIP_VERIFY_ERROR:
744 str = "Round trip verify error";
746 case IDNA_CONTAINS_ACE_PREFIX:
747 str = "Already have ACE prefix (\"xn--\")";
749 case IDNA_ICONV_ERROR:
750 str = "Locale conversion failed";
752 case IDNA_MALLOC_ERROR:
753 str = "Allocation failed";
755 case IDNA_DLOPEN_ERROR:
756 str = "dlopen() error";
759 snprintf(buf, max, "error %d", err);
764 if((Idna_rc)err == IDNA_SUCCESS)
770 strncpy(buf, str, max);
775 #endif /* USE_LIBIDN */