Call decompress_data only for compressed data.
[elinks/elinks-j605.git] / src / network / state.h
blob41f13378de944e7d0c7b8c00b0c9b373f4e198f8
1 #ifndef EL__NETWORK_STATE_H
2 #define EL__NETWORK_STATE_H
4 #include "util/error.h" /* assert() */
6 struct terminal;
8 enum connection_priority {
9 PRI_MAIN = 0,
10 PRI_DOWNLOAD = 0,
11 PRI_FRAME,
12 PRI_CSS,
13 PRI_NEED_IMG,
14 PRI_IMG,
15 PRI_PRELOAD,
16 PRI_CANCEL,
17 PRIORITIES,
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. */
29 #undef S_OK
31 enum connection_basic_state {
32 /* States >= 0 are used for connections still in progress. */
33 S_WAIT = 0,
34 S_DNS,
35 S_CONN,
36 S_SSL_NEG,
37 S_SENT,
38 S_LOGIN,
39 S_GETH,
40 S_PROC,
41 S_TRANS,
42 S_QUESTIONS,
43 S_CONN_PEERS,
44 S_CONN_TRACKER,
45 S_RESUME,
47 /* State < 0 are used for the final result of a connection
48 * (it's finished already and it ended up like this) */
49 S_ERRNO = -1,
50 S_OK = -100000,
51 S_INTERRUPTED = -100001,
52 S_EXCEPT = -100002,
53 S_INTERNAL = -100003,
54 S_OUT_OF_MEM = -100004,
55 S_NO_DNS = -100005,
56 S_CANT_WRITE = -100006,
57 S_CANT_READ = -100007,
58 S_MODIFIED = -100008,
59 S_BAD_URL = -100009,
60 S_TIMEOUT = -100010,
61 S_RESTART = -100011,
62 S_STATE = -100012,
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,
72 S_HTTP_204 = -100101,
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,
83 S_FTP_PORT = -100303,
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. */
122 int syserr;
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;
136 state.basic = basic;
137 return state;
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;
149 return state;
152 #endif