bug 991: Added the bit field cgi to the structs connection and type_query.
[elinks.git] / src / network / connection.h
blob311bbaaf79398c88000bb09705a3a993f75c0c47
1 #ifndef EL__NETWORK_CONNECTION_H
2 #define EL__NETWORK_CONNECTION_H
4 #include "cache/cache.h"
5 #include "encoding/encoding.h"
6 #include "main/timer.h" /* timer_id_T */
7 #include "network/state.h"
8 #include "util/lists.h"
9 #include <stdio.h>
11 struct download;
12 struct socket;
13 struct uri;
16 struct connection {
17 LIST_HEAD(struct connection);
19 LIST_OF(struct download) downloads;
20 struct progress *progress;
22 /* If no proxy is used uri and proxied_uri are the same. */
23 struct uri *uri;
24 struct uri *proxied_uri;
25 struct uri *referrer;
27 /* Cache information. */
28 enum cache_mode cache_mode;
29 struct cache_entry *cached;
31 off_t from; /* Position for new data in the cache entry. */
32 off_t received; /* The number of received bytes. */
33 off_t est_length; /* Estimated number of bytes to transfer. */
35 enum stream_encoding content_encoding;
36 struct stream_encoded *stream;
38 /* Called if non NULL when shutting down a connection. */
39 void (*done)(struct connection *);
41 unsigned int id;
43 enum connection_state state;
44 enum connection_state prev_error;
46 /* The communication socket with the other side. */
47 struct socket *socket;
48 /* The data socket. It is used, when @socket is used for the control,
49 * and the actual data is transmitted through a different channel. */
50 /* The only users now are FTP, FSP, and SMB. */
51 struct socket *data_socket;
53 int tries;
54 timer_id_T timer;
55 int stream_pipes[2];
57 unsigned int running:1;
58 unsigned int unrestartable:1;
59 unsigned int detached:1;
60 unsigned int popen:1;
61 unsigned int cgi:1;
63 /* Each document is downloaded with some priority. When downloading a
64 * document, the existing connections are checked to see if a
65 * connection to the host already exists before creating a new one. If
66 * it finds out that something had that idea earlier and connection for
67 * download of the very same URL is active already, it just attaches
68 * the struct download it got to the connection, _and_ updates its @pri
69 * array by the priority it has thus, sum of values in all fields of
70 * @pri is also kinda refcount of the connection. */
71 int pri[PRIORITIES];
73 /* Private protocol specific info. If non-NULL it is free()d when
74 * stopping the connection. */
75 void *info;
78 struct popen_data {
79 LIST_HEAD(struct popen_data);
81 int fd;
82 FILE *stream;
83 unsigned char *filename;
86 extern LIST_OF(struct popen_data) copiousoutput_data;
88 int register_check_queue(void);
90 int get_connections_count(void);
91 int get_keepalive_connections_count(void);
92 int get_connections_connecting_count(void);
93 int get_connections_transfering_count(void);
95 void set_connection_state(struct connection *, enum connection_state);
97 int has_keepalive_connection(struct connection *);
98 void add_keepalive_connection(struct connection *conn, long timeout_in_seconds,
99 void (*done)(struct connection *));
101 void abort_connection(struct connection *, enum connection_state);
102 void retry_connection(struct connection *, enum connection_state);
104 void cancel_download(struct download *download, int interrupt);
105 void move_download(struct download *old, struct download *new,
106 enum connection_priority newpri);
108 void detach_connection(struct download *, off_t);
109 void abort_all_connections(void);
110 void abort_background_connections(void);
112 void set_connection_timeout(struct connection *);
114 void shutdown_connection_stream(struct connection *conn);
116 /* Initiates a connection to get the given @uri. */
117 /* Note that stat's data _MUST_ be struct file_download * if start > 0! Yes,
118 * that should be probably something else than data, but... ;-) */
119 /* Returns 0 on success and -1 on failure. */
120 int load_uri(struct uri *uri, struct uri *referrer, struct download *download,
121 enum connection_priority pri, enum cache_mode cache_mode, off_t start);
123 int is_entry_used(struct cache_entry *cached);
125 #endif