2005-09-15 09:58:31 -04:00
|
|
|
#ifndef EL__NETWORK_CONNECTION_H
|
|
|
|
#define EL__NETWORK_CONNECTION_H
|
|
|
|
|
|
|
|
#include "cache/cache.h"
|
|
|
|
#include "encoding/encoding.h"
|
|
|
|
#include "main/timer.h" /* timer_id_T */
|
|
|
|
#include "network/state.h"
|
|
|
|
#include "util/lists.h"
|
2006-05-18 15:46:42 -04:00
|
|
|
#include <stdio.h>
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
struct download;
|
|
|
|
struct socket;
|
|
|
|
struct uri;
|
|
|
|
|
|
|
|
|
|
|
|
struct connection {
|
|
|
|
LIST_HEAD(struct connection);
|
|
|
|
|
2007-07-26 15:39:08 -04:00
|
|
|
LIST_OF(struct download) downloads;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct progress *progress;
|
2008-06-03 02:57:58 -04:00
|
|
|
|
|
|
|
/** Progress of sending the request and attached files to the
|
|
|
|
* server. This happens before any download.
|
|
|
|
*
|
|
|
|
* Currently, ELinks supports file uploads only in HTTP and
|
|
|
|
* local CGI. Therefore, upload_stat_timer() in connection.c
|
|
|
|
* assumes that #info points to struct http_connection_info
|
|
|
|
* whenever @c http_upload_progress is not NULL. */
|
|
|
|
struct progress *http_upload_progress;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* If no proxy is used uri and proxied_uri are the same. */
|
|
|
|
struct uri *uri;
|
|
|
|
struct uri *proxied_uri;
|
|
|
|
struct uri *referrer;
|
|
|
|
|
|
|
|
/* Cache information. */
|
2022-01-28 11:32:27 -05:00
|
|
|
cache_mode_T cache_mode;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct cache_entry *cached;
|
|
|
|
|
|
|
|
off_t from; /* Position for new data in the cache entry. */
|
|
|
|
off_t received; /* The number of received bytes. */
|
|
|
|
off_t est_length; /* Estimated number of bytes to transfer. */
|
|
|
|
|
2022-01-28 10:17:25 -05:00
|
|
|
stream_encoding_T content_encoding;
|
2005-09-15 09:58:31 -04:00
|
|
|
struct stream_encoded *stream;
|
|
|
|
|
|
|
|
/* Called if non NULL when shutting down a connection. */
|
|
|
|
void (*done)(struct connection *);
|
|
|
|
|
|
|
|
unsigned int id;
|
|
|
|
|
2008-08-03 08:24:26 -04:00
|
|
|
struct connection_state state;
|
|
|
|
struct connection_state prev_error;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* The communication socket with the other side. */
|
|
|
|
struct socket *socket;
|
|
|
|
/* The data socket. It is used, when @socket is used for the control,
|
|
|
|
* and the actual data is transmitted through a different channel. */
|
2007-03-05 12:34:19 -05:00
|
|
|
/* The only users now are FTP, FSP, and SMB. */
|
2005-09-15 09:58:31 -04:00
|
|
|
struct socket *data_socket;
|
|
|
|
|
|
|
|
int tries;
|
|
|
|
timer_id_T timer;
|
2022-09-28 15:07:31 -04:00
|
|
|
milliseconds_T xhr_timeout;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
unsigned int running:1;
|
|
|
|
unsigned int unrestartable:1;
|
|
|
|
unsigned int detached:1;
|
2008-03-09 07:50:09 -04:00
|
|
|
unsigned int cgi:1;
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Each document is downloaded with some priority. When downloading a
|
|
|
|
* document, the existing connections are checked to see if a
|
|
|
|
* connection to the host already exists before creating a new one. If
|
|
|
|
* it finds out that something had that idea earlier and connection for
|
|
|
|
* download of the very same URL is active already, it just attaches
|
|
|
|
* the struct download it got to the connection, _and_ updates its @pri
|
|
|
|
* array by the priority it has thus, sum of values in all fields of
|
|
|
|
* @pri is also kinda refcount of the connection. */
|
2007-06-23 11:08:08 -04:00
|
|
|
int pri[PRIORITIES];
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
/* Private protocol specific info. If non-NULL it is free()d when
|
|
|
|
* stopping the connection. */
|
|
|
|
void *info;
|
|
|
|
};
|
|
|
|
|
|
|
|
int register_check_queue(void);
|
|
|
|
|
|
|
|
int get_connections_count(void);
|
|
|
|
int get_keepalive_connections_count(void);
|
|
|
|
int get_connections_connecting_count(void);
|
|
|
|
int get_connections_transfering_count(void);
|
|
|
|
|
2008-08-03 08:24:26 -04:00
|
|
|
void set_connection_state(struct connection *, struct connection_state);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
int has_keepalive_connection(struct connection *);
|
|
|
|
void add_keepalive_connection(struct connection *conn, long timeout_in_seconds,
|
|
|
|
void (*done)(struct connection *));
|
|
|
|
|
2008-08-03 08:24:26 -04:00
|
|
|
void abort_connection(struct connection *, struct connection_state);
|
|
|
|
void retry_connection(struct connection *, struct connection_state);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
2006-02-03 04:44:28 -05:00
|
|
|
void cancel_download(struct download *download, int interrupt);
|
2016-04-20 12:42:22 -04:00
|
|
|
void move_download(struct download *old, struct download *new_,
|
2022-01-28 10:22:03 -05:00
|
|
|
connection_priority_T newpri);
|
2006-02-03 04:44:28 -05:00
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
void detach_connection(struct download *, off_t);
|
|
|
|
void abort_all_connections(void);
|
|
|
|
void abort_background_connections(void);
|
|
|
|
|
|
|
|
void set_connection_timeout(struct connection *);
|
2022-09-28 15:07:31 -04:00
|
|
|
void set_connection_timeout_xhr(struct connection *conn, milliseconds_T timeout);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
void shutdown_connection_stream(struct connection *conn);
|
|
|
|
|
|
|
|
/* Initiates a connection to get the given @uri. */
|
|
|
|
/* Note that stat's data _MUST_ be struct file_download * if start > 0! Yes,
|
|
|
|
* that should be probably something else than data, but... ;-) */
|
|
|
|
/* Returns 0 on success and -1 on failure. */
|
|
|
|
int load_uri(struct uri *uri, struct uri *referrer, struct download *download,
|
2022-01-28 11:32:27 -05:00
|
|
|
connection_priority_T pri, cache_mode_T cache_mode, off_t start);
|
2005-09-15 09:58:31 -04:00
|
|
|
|
|
|
|
int is_entry_used(struct cache_entry *cached);
|
|
|
|
|
2020-10-05 14:14:55 -04:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-09-15 09:58:31 -04:00
|
|
|
#endif
|