1 /* Status/error messages managment */
11 #include "intl/gettext/libintl.h"
12 #include "network/connection.h"
13 #include "network/state.h"
14 #include "terminal/terminal.h"
15 #include "util/conv.h"
16 #include "util/lists.h"
17 #include "util/memory.h"
18 #include "util/string.h"
21 /* Global variables */
26 static const struct s_msg_dsc msg_dsc
[] = {
27 {S_WAIT
, N_("Waiting in queue")},
28 {S_DNS
, N_("Looking up host")},
29 {S_CONN
, N_("Making connection")},
30 {S_SSL_NEG
, N_("SSL negotiation")},
31 {S_SENT
, N_("Request sent")},
32 {S_LOGIN
, N_("Logging in")},
33 {S_GETH
, N_("Getting headers")},
34 {S_PROC
, N_("Server is processing request")},
35 {S_TRANS
, N_("Transferring")},
36 #ifdef CONFIG_BITTORRENT
37 {S_RESUME
, N_("Resuming")},
38 {S_CONN_PEERS
, N_("Connecting to peers")},
39 {S_CONN_TRACKER
, N_("Connecting to tracker")},
42 {S_WAIT_REDIR
, N_("Waiting for redirect confirmation")},
44 {S_INTERRUPTED
, N_("Interrupted")},
45 {S_EXCEPT
, N_("Socket exception")},
46 {S_INTERNAL
, N_("Internal error")},
47 {S_OUT_OF_MEM
, N_("Out of memory")},
48 {S_NO_DNS
, N_("Host not found")},
49 {S_CANT_WRITE
, N_("Error writing to socket")},
50 {S_CANT_READ
, N_("Error reading from socket")},
51 {S_MODIFIED
, N_("Data modified")},
52 {S_BAD_URL
, N_("Bad URL syntax")},
53 {S_TIMEOUT
, N_("Receive timeout")},
54 {S_RESTART
, N_("Request must be restarted")},
55 {S_STATE
, N_("Can't get socket state")},
56 {S_LOCAL_ONLY
, N_("Only local connections are permitted")},
57 {S_NO_FORCED_DNS
, N_("No host in the specified IP family was found")},
58 #if defined(CONFIG_GZIP) || defined(CONFIG_BZIP2)
59 {S_ENCODE_ERROR
, N_("Error while decoding file. This might be caused\n"
60 "by the encoded file being corrupt.") },
62 {S_UNKNOWN_PROTOCOL
, N_("This URL contains a protocol not yet known by ELinks.\n"
63 "You can configure an external handler for it through\n"
64 "the options system.")},
66 {S_EXTERNAL_PROTOCOL
, N_("This URL contains a protocol that is not natively known\n"
67 "by ELinks which means that ELinks relies on external\n"
68 "programs for handling it. Downloading URLs using external\n"
69 "programs is not supported.")},
71 {S_HTTP_ERROR
, N_("Bad HTTP response")},
72 {S_HTTP_204
, N_("No content")},
74 {S_FILE_TYPE
, N_("Unknown file type")},
75 {S_FILE_ERROR
, N_("Error opening file")},
76 {S_FILE_CGI_BAD_PATH
, N_("CGI script not in CGI path")},
77 {S_FILE_ANONYMOUS
, N_("Local file access is not allowed in anonymous mode")},
80 {S_FTP_ERROR
, N_("Bad FTP response")},
81 {S_FTP_UNAVAIL
, N_("FTP service unavailable")},
82 {S_FTP_LOGIN
, N_("Bad FTP login")},
83 {S_FTP_PORT
, N_("FTP PORT command failed")},
84 {S_FTP_NO_FILE
, N_("File not found")},
85 {S_FTP_FILE_ERROR
, N_("FTP file error")},
89 {S_SSL_ERROR
, N_("SSL error")},
91 {S_SSL_ERROR
, N_("This version of ELinks does not contain SSL/TLS support")},
94 {S_NO_JAVASCRIPT
, N_("JavaScript support is not enabled")},
97 {S_NNTP_ERROR
, N_("Bad NNTP response")},
98 {S_NNTP_NEWS_SERVER
, N_("Unable to handle news: URI because no news server has been\n"
99 "been configured. Either set the option protocol.nntp.server\n"
100 "or set the NNTPSERVER environment variable.")},
101 {S_NNTP_SERVER_HANG_UP
, N_("Server hang up for some reason")},
102 {S_NNTP_GROUP_UNKNOWN
, N_("No such newsgroup")},
103 {S_NNTP_ARTICLE_UNKNOWN
,N_("No such article")},
104 {S_NNTP_TRANSFER_ERROR
, N_("Transfer failed")},
105 {S_NNTP_AUTH_REQUIRED
, N_("Authorization required")},
106 {S_NNTP_ACCESS_DENIED
, N_("Access to server denied")},
110 {S_GOPHER_CSO_ERROR
, N_("The CSO phone-book protocol is not supported.")},
113 {S_PROXY_ERROR
, N_("Configuration of the proxy server failed.\n"
114 "This might be caused by an incorrect proxy\n"
115 "setting specified by an environment variable\n"
116 "or returned by a scripting proxy hook.\n"
118 "The correct syntax for proxy settings are\n"
119 "a host name optionally followed by a colon\n"
120 "and a port number. Example: 'localhost:8080'.")},
122 #ifdef CONFIG_BITTORRENT
123 {S_BITTORRENT_ERROR
, N_("BitTorrent error")},
124 {S_BITTORRENT_METAINFO
, N_("The BitTorrent metainfo file contained errors")},
125 {S_BITTORRENT_TRACKER
, N_("The tracker requesting failed")},
126 {S_BITTORRENT_BAD_URL
, N_("The BitTorrent URL does not point to a valid URL")},
133 struct strerror_val
{
134 LIST_HEAD(struct strerror_val
);
136 unsigned char msg
[1]; /* must be last */
139 static INIT_LIST_OF(struct strerror_val
, strerror_buf
);
141 /* It returns convenient error message, depending on @state.
142 * It never returns NULL (if one changes that, be warn that
143 * callers may not test for this condition) --Zas */
145 get_state_message(enum connection_state state
, struct terminal
*term
)
148 struct strerror_val
*s
;
150 unsigned char *unknown_error
= _("Unknown error", term
);
152 if (!is_system_error(state
)) {
155 for (i
= 0; msg_dsc
[i
].msg
; i
++)
156 if (msg_dsc
[i
].n
== state
)
157 return _(msg_dsc
[i
].msg
, term
);
159 return unknown_error
;
162 e
= (unsigned char *) strerror(-state
);
163 if (!e
|| !*e
) return unknown_error
;
167 foreach (s
, strerror_buf
)
168 if (!strlcmp(s
->msg
, -1, e
, len
))
171 s
= mem_calloc(1, sizeof(*s
) + len
);
172 if (!s
) return unknown_error
;
174 memcpy(s
->msg
, e
, len
+ 1);
175 add_to_list(strerror_buf
, s
);
181 done_state_message(void)
183 free_list(strerror_buf
);