1 #ifndef EL__NETWORK_STATE_H
2 #define EL__NETWORK_STATE_H
4 #include "util/error.h" /* assert() */
8 enum connection_priority
{
20 #define is_system_error(state) ((state).basic == S_ERRNO)
21 #define is_in_state(state,basic_) ((state).basic == (basic_))
22 #define is_in_result_state(state) ((state).basic < 0)
23 #define is_in_progress_state(state) ((state).basic >= 0)
24 #define is_in_connecting_state(state) (S_WAIT < (state).basic && (state).basic < S_TRANS)
25 #define is_in_transfering_state(state) ((state).basic >= S_TRANS)
26 #define is_in_queued_state(state) (is_in_connecting_state(state) || (state).basic == S_WAIT)
28 /* FIXME: Namespace clash with Windows headers. */
31 enum connection_basic_state
{
32 /* States >= 0 are used for connections still in progress. */
47 /* State < 0 are used for the final result of a connection
48 * (it's finished already and it ended up like this) */
51 S_INTERRUPTED
= -100001,
54 S_OUT_OF_MEM
= -100004,
56 S_CANT_WRITE
= -100006,
57 S_CANT_READ
= -100007,
63 S_WAIT_REDIR
= -100013,
64 S_LOCAL_ONLY
= -100014,
65 S_UNKNOWN_PROTOCOL
= -100015,
66 S_EXTERNAL_PROTOCOL
= -100016,
67 S_ENCODE_ERROR
= -100017,
68 S_SSL_ERROR
= -100018,
69 S_NO_FORCED_DNS
= -100019,
71 S_HTTP_ERROR
= -100100,
73 S_HTTP_UPLOAD_RESIZED
= -100102,
75 S_FILE_TYPE
= -100200,
76 S_FILE_ERROR
= -100201,
77 S_FILE_CGI_BAD_PATH
= -100202,
78 S_FILE_ANONYMOUS
= -100203,
80 S_FTP_ERROR
= -100300,
81 S_FTP_UNAVAIL
= -100301,
82 S_FTP_LOGIN
= -100302,
84 S_FTP_NO_FILE
= -100304,
85 S_FTP_FILE_ERROR
= -100305,
87 S_NNTP_ERROR
= -100400,
88 S_NNTP_NEWS_SERVER
= -100401,
89 S_NNTP_SERVER_HANG_UP
= -100402,
90 S_NNTP_GROUP_UNKNOWN
= -100403,
91 S_NNTP_ARTICLE_UNKNOWN
= -100404,
92 S_NNTP_TRANSFER_ERROR
= -100405,
93 S_NNTP_AUTH_REQUIRED
= -100406,
94 S_NNTP_ACCESS_DENIED
= -100407,
95 S_NNTP_SERVER_ERROR
= -100408,
97 S_GOPHER_CSO_ERROR
= -100500,
99 S_NO_JAVASCRIPT
= -100600,
101 S_PROXY_ERROR
= -100700,
103 S_BITTORRENT_ERROR
= -100800,
104 S_BITTORRENT_METAINFO
= -100801,
105 S_BITTORRENT_TRACKER
= -100802,
106 S_BITTORRENT_BAD_URL
= -100803,
107 S_BITTORRENT_PEER_URL
= -100804,
109 S_FSP_OPEN_SESSION_UNKN
= -100900,
112 /** Either an ELinks internal status code or an error code from the
113 * system. Use connection_state() or connection_state_for_errno()
114 * to construct objects of this type. */
115 struct connection_state
{
116 /** An ELinks internal status code, or ::S_ERRNO if this
117 * structure holds a system error instead. */
118 enum connection_basic_state basic
;
120 /** When #basic is ::S_ERRNO, syserr is the saved value of
121 * errno. Otherwise, syserr should be 0. */
125 unsigned char *get_state_message(struct connection_state state
, struct terminal
*term
);
126 void done_state_message(void);
128 static inline struct connection_state
129 connection_state(enum connection_basic_state basic
)
131 struct connection_state state
= {0};
133 assert(basic
!= S_ERRNO
);
134 if_assert_failed basic
= S_INTERNAL
;
140 static inline struct connection_state
141 connection_state_for_errno(int syserr
)
143 struct connection_state state
= {0};
145 /* read_encoded_file() can pass syserr==0 here, so don't
146 * assert otherwise. */
147 state
.basic
= S_ERRNO
;
148 state
.syserr
= syserr
;