1 /***************************************************************************
3 * Project ___| | | | _ \| |
5 * | (__| |_| | _ <| |___
6 * \___|\___/|_| \_\_____|
8 * Copyright (C) 2004, 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 #include <curl/curl.h>
32 #define _MPRINTF_REPLACE /* use our functions only */
33 #include <curl/mprintf.h>
36 curl_easy_strerror(CURLcode error)
42 case CURLE_UNSUPPORTED_PROTOCOL:
43 return "unsupported protocol";
45 case CURLE_FAILED_INIT:
48 case CURLE_URL_MALFORMAT:
49 return "url malformat";
51 case CURLE_URL_MALFORMAT_USER:
52 return "url malformat user";
54 case CURLE_COULDNT_RESOLVE_PROXY:
55 return "couldnt resolve proxy";
57 case CURLE_COULDNT_RESOLVE_HOST:
58 return "couldnt resolve host";
60 case CURLE_COULDNT_CONNECT:
61 return "couldn't connect";
63 case CURLE_FTP_WEIRD_SERVER_REPLY:
64 return "ftp weird server reply";
66 case CURLE_FTP_ACCESS_DENIED:
67 return "ftp access denied";
69 case CURLE_FTP_USER_PASSWORD_INCORRECT:
70 return "ftp user password incorrect";
72 case CURLE_FTP_WEIRD_PASS_REPLY:
73 return "ftp weird pass reply";
75 case CURLE_FTP_WEIRD_USER_REPLY:
76 return "ftp weird user reply";
78 case CURLE_FTP_WEIRD_PASV_REPLY:
79 return "ftp weird pasv reply";
81 case CURLE_FTP_WEIRD_227_FORMAT:
82 return "ftp weird 227 format";
84 case CURLE_FTP_CANT_GET_HOST:
85 return "ftp cant get host";
87 case CURLE_FTP_CANT_RECONNECT:
88 return "ftp can't reconnect";
90 case CURLE_FTP_COULDNT_SET_BINARY:
91 return "ftp couldn't set binary";
93 case CURLE_PARTIAL_FILE:
94 return "partial file";
96 case CURLE_FTP_COULDNT_RETR_FILE:
97 return "ftp couldn't retr file";
99 case CURLE_FTP_WRITE_ERROR:
100 return "ftp write error";
102 case CURLE_FTP_QUOTE_ERROR:
103 return "ftp quote error";
105 case CURLE_HTTP_NOT_FOUND:
106 return "http not found";
108 case CURLE_WRITE_ERROR:
109 return "write error";
111 case CURLE_MALFORMAT_USER:
112 return "user name is illegally specified";
114 case CURLE_FTP_COULDNT_STOR_FILE:
115 return "failed FTP upload";
117 case CURLE_READ_ERROR:
118 return "could open/read from file";
120 case CURLE_OUT_OF_MEMORY:
121 return "out of memory";
123 case CURLE_OPERATION_TIMEOUTED:
124 return "the timeout time was reached";
126 case CURLE_FTP_COULDNT_SET_ASCII:
127 return "TYPE A failed";
129 case CURLE_FTP_PORT_FAILED:
130 return "FTP PORT operation failed";
132 case CURLE_FTP_COULDNT_USE_REST:
133 return "the REST command failed";
135 case CURLE_FTP_COULDNT_GET_SIZE:
136 return "the SIZE command failed";
138 case CURLE_HTTP_RANGE_ERROR:
139 return "RANGE \"command\" didn't work";
141 case CURLE_HTTP_POST_ERROR:
142 return "http post error";
144 case CURLE_SSL_CONNECT_ERROR:
145 return "wrong when connecting with SSL";
147 case CURLE_FTP_BAD_DOWNLOAD_RESUME:
148 return "couldn't resume download";
150 case CURLE_FILE_COULDNT_READ_FILE:
151 return "file couldn't read 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_LIBRARY_NOT_FOUND:
160 return "library not found";
162 case CURLE_FUNCTION_NOT_FOUND:
163 return "function not found";
165 case CURLE_ABORTED_BY_CALLBACK:
166 return "aborted by callback";
168 case CURLE_BAD_FUNCTION_ARGUMENT:
169 return "bad function argument";
171 case CURLE_BAD_CALLING_ORDER:
172 return "bad calling order";
174 case CURLE_HTTP_PORT_FAILED:
175 return "HTTP Interface operation failed";
177 case CURLE_BAD_PASSWORD_ENTERED:
178 return "my getpass() returns fail";
180 case CURLE_TOO_MANY_REDIRECTS :
181 return "catch endless re-direct loops";
183 case CURLE_UNKNOWN_TELNET_OPTION:
184 return "User specified an unknown option";
186 case CURLE_TELNET_OPTION_SYNTAX :
187 return "Malformed telnet option";
192 case CURLE_SSL_PEER_CERTIFICATE:
193 return "peer's certificate wasn't ok";
195 case CURLE_GOT_NOTHING:
196 return "when this is a specific error";
198 case CURLE_SSL_ENGINE_NOTFOUND:
199 return "SSL crypto engine not found";
201 case CURLE_SSL_ENGINE_SETFAILED:
202 return "can not set SSL crypto engine as default";
204 case CURLE_SEND_ERROR:
205 return "failed sending network data";
207 case CURLE_RECV_ERROR:
208 return "failure in receiving network data";
210 case CURLE_SHARE_IN_USE:
211 return "CURLE_SHARE_IN_USER";
213 case CURLE_SSL_CERTPROBLEM:
214 return "problem with the local certificate";
216 case CURLE_SSL_CIPHER:
217 return "couldn't use specified cipher";
219 case CURLE_SSL_CACERT:
220 return "problem with the CA cert (path? access rights?)";
222 case CURLE_BAD_CONTENT_ENCODING:
223 return "Unrecognized transfer encoding";
225 case CURLE_LDAP_INVALID_URL:
226 return "Invalid LDAP URL";
228 case CURLE_FILESIZE_EXCEEDED:
229 return "Maximum file size exceeded";
231 case CURLE_FTP_SSL_FAILED:
232 return "Requested FTP SSL level failed";
238 * By using a switch, gcc -Wall will complain about enum values
239 * which do not appear, helping keep this function up-to-date.
240 * By using gcc -Wall -Werror, you can't forget.
242 * A table would not have the same benefit. Most compilers will
243 * generate code very similar to a table in any case, so there
244 * is little performance gain from a table. And something is broken
245 * for the user's application, anyways, so does it matter how fast
248 * The line number for the error will be near this comment, which
249 * is why it is here, and not at the start of the switch.
251 return "CURLcode unknown";
255 curl_multi_strerror(CURLMcode error)
259 case CURLM_CALL_MULTI_PERFORM:
260 return "please call curl_multi_perform() soon";
265 case CURLM_BAD_HANDLE:
266 return "CURLM not valid multi handle";
268 case CURLM_BAD_EASY_HANDLE:
269 return "CURLM not valid easy handle";
271 case CURLM_OUT_OF_MEMORY:
272 return "CURLM libcurl out of memory";
274 case CURLM_INTERNAL_ERROR:
275 return "CURLM libcurl internal bug";
281 return "CURLMcode unknown";
285 curl_share_strerror(CURLSHcode error)
292 case CURLSHE_BAD_OPTION:
293 return "CURLSH bad option";
296 return "CURLSH in use";
298 case CURLSHE_INVALID:
299 return "CURLSH invalid";
305 return "CURLSH unknown";
308 #if defined(WIN32) && !defined(__CYGWIN__)
310 /* This function handles most / all (?) Winsock errors cURL is able to produce.
313 get_winsock_error (int err, char *buf, size_t len)
320 p = "Call interrupted.";
332 p = "Invalid arguments";
335 p = "Out of file descriptors";
338 p = "Call would block";
342 p = "Blocking call in progress";
345 p = "Descriptor is not a socket.";
347 case WSAEDESTADDRREQ:
348 p = "Need destination address";
351 p = "Bad message size";
357 p = "Protocol option is unsupported";
359 case WSAEPROTONOSUPPORT:
360 p = "Protocol is unsupported";
362 case WSAESOCKTNOSUPPORT:
363 p = "Socket is unsupported";
366 p = "Operation not supported";
368 case WSAEAFNOSUPPORT:
369 p = "Address family not supported";
371 case WSAEPFNOSUPPORT:
372 p = "Protocol family not supported";
375 p = "Address already in use";
377 case WSAEADDRNOTAVAIL:
378 p = "Address not available";
384 p = "Network unreachable";
387 p = "Network has been reset";
389 case WSAECONNABORTED:
390 p = "Connection was aborted";
393 p = "Connection was reset";
396 p = "No buffer space";
399 p = "Socket is already connected";
402 p = "Socket is not connected";
405 p = "Socket has been shut down";
407 case WSAETOOMANYREFS:
408 p = "Too many references";
413 case WSAECONNREFUSED:
414 p = "Connection refused";
419 case WSAENAMETOOLONG:
425 case WSAEHOSTUNREACH:
426 p = "Host unreachable";
432 p = "Process limit reached";
435 p = "Too many users";
441 p = "Something is stale";
450 /* Extended Winsock errors */
452 p = "Winsock library is not ready";
454 case WSANOTINITIALISED:
455 p = "Winsock library not initalised";
457 case WSAVERNOTSUPPORTED:
458 p = "Winsock version not supported.";
461 /* getXbyY() errors (already handled in herrmsg):
462 * Authoritative Answer: Host not found */
463 case WSAHOST_NOT_FOUND:
464 p = "Host not found";
467 /* Non-Authoritative: Host not found, or SERVERFAIL */
469 p = "Host not found, try again";
472 /* Non recoverable errors, FORMERR, REFUSED, NOTIMP */
474 p = "Unrecoverable error in call to nameserver";
477 /* Valid name, no data record of requested type */
479 p = "No data record of requested type";
485 strncpy (buf, p, len);
489 #endif /* WIN32 && !__CYGWIN__ */
496 * Our thread-safe and smart strerror() replacement.
498 const char *Curl_strerror(struct connectdata *conn, int err)
505 buf = conn->syserr_buf;
506 max = sizeof(conn->syserr_buf)-1;
508 if (err >= 0 && err < sys_nerr) {
509 /* These should be atomic and hopefully thread-safe */
510 #ifdef HAVE_STRERROR_R
511 #ifdef HAVE_POSIX_STRERROR_R
512 strerror_r(err, buf, max);
513 /* this may set errno to ERANGE if insufficient storage was supplied via
514 strerrbuf and buflen to contain the generated message string, or EINVAL
515 if the value of errnum is not a valid error number.*/
517 /* HAVE_GLIBC_STRERROR_R */
519 char *msg = strerror_r(err, buffer, sizeof(buffer));
520 strncpy(buf, msg, max);
523 strncpy(buf, strerror(err), max);
528 #if defined(WIN32) && !defined(__CYGWIN__)
529 if (!get_winsock_error (err, buf, max) &&
530 !FormatMessage (FORMAT_MESSAGE_FROM_SYSTEM, NULL, err,
531 LANG_NEUTRAL, buf, max, NULL))
533 snprintf(buf, max, "Unknown error %d (%#x)", err, err);
535 /* strip trailing '\r\n' or '\n'. */
536 if ((p = strrchr(buf,'\n')) != NULL && (p - buf) >= 2)
538 if ((p = strrchr(buf,'\r')) != NULL && (p - buf) >= 1)