Dillo v3.1.1-119-g140d9ebd
|
HTTP connect functions. More...
#include <config.h>
#include <ctype.h>
#include <unistd.h>
#include <errno.h>
#include <stdlib.h>
#include <fcntl.h>
#include <assert.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include "IO.h"
#include "iowatch.hh"
#include "tls.h"
#include "Url.h"
#include "../msg.h"
#include "../klist.h"
#include "../dns.h"
#include "../web.hh"
#include "../cookies.h"
#include "../auth.h"
#include "../prefs.h"
#include "../misc.h"
#include "../uicmd.hh"
Go to the source code of this file.
Macros | |
#define | MSG_BW(web, root, ...) |
#define | _MSG_BW(web, root, ...) |
Functions | |
static void | Http_socket_enqueue (Server_t *srv, SocketData_t *sock) |
Add socket data to the queue. | |
static Server_t * | Http_server_get (const char *host, uint_t port, bool_t https) |
static void | Http_server_remove (Server_t *srv) |
static void | Http_connect_socket (ChainLink *Info) |
This function is called after the DNS succeeds in solving a hostname. | |
static char * | Http_get_connect_str (const DilloUrl *url) |
Return a new string for the request used to tunnel HTTPS through a proxy. | |
static void | Http_send_query (SocketData_t *S) |
Create and submit the HTTP query to the IO engine. | |
static void | Http_socket_free (int SKey) |
Free SocketData_t struct. | |
int | a_Http_init (void) |
Initialize proxy vars and Accept-Language header. | |
int | a_Http_proxy_auth (void) |
Tell whether the proxy auth is already set (user:password). | |
void | a_Http_set_proxy_passwd (const char *str) |
Activate entered proxy password for HTTP. | |
static int | Http_sock_new (void) |
Create and init a new SocketData_t struct, insert into ValidSocks, and return a primary key for it. | |
static int | Http_fd_map_cmp (const void *v1, const void *v2) |
Compare by FD. | |
static void | Http_fd_map_add_entry (SocketData_t *sd) |
static void | Http_fd_map_remove_entry (int fd) |
Remove and free entry from fd_map. | |
void | a_Http_connect_done (int fd, bool_t success) |
static void | Http_socket_activate (Server_t *srv, SocketData_t *sd) |
static void | Http_connect_queued_sockets (Server_t *srv) |
static char * | Http_get_referer (const DilloUrl *url) |
Make the HTTP header's Referer line according to preferences (default is "host" i.e. | |
static Dstr * | Http_make_content_type (const DilloUrl *url) |
Generate Content-Type header value for a POST query. | |
static Dstr * | Http_make_query_str (DilloWeb *web, bool_t use_proxy, bool_t use_tls) |
Make the http query string. | |
static void | Http_connect_tls (ChainLink *info) |
Prepare an HTTPS connection. | |
static void | Http_connect_socket_cb (int fd, void *data) |
connect() couldn't complete before, but now it's ready, so let's try again. | |
static int | Http_must_use_proxy (const char *hostname) |
Test proxy settings and check the no_proxy domains list. | |
static void | Http_dns_cb (int Status, Dlist *addr_list, void *data) |
Callback function for the DNS resolver. | |
static int | Http_get (ChainLink *Info, void *Data1) |
Asynchronously create a new http connection for 'Url'. | |
static bool_t | Http_socket_reuse_compatible (SocketData_t *old, SocketData_t *new) |
Can the old socket's fd be reused for the new socket?. | |
static void | Http_socket_reuse (int SKey) |
If any entry in the socket data queue can reuse our connection, set it up and send off a new query. | |
void | a_Http_ccc (int Op, int Branch, int Dir, ChainLink *Info, void *Data1, void *Data2) |
CCC function for the HTTP module. | |
static void | Http_servers_remove_all (void) |
static void | Http_fd_map_remove_all (void) |
void | a_Http_freeall (void) |
Deallocate memory used by http module. | |
Variables | |
static const int | HTTP_SOCKET_USE_PROXY = 0x1 |
static const int | HTTP_SOCKET_QUEUED = 0x2 |
static const int | HTTP_SOCKET_TO_BE_FREED = 0x4 |
static const int | HTTP_SOCKET_TLS = 0x8 |
static const int | HTTP_SOCKET_IOWATCH_ACTIVE = 0x10 |
static Klist_t * | ValidSocks = NULL |
static DilloUrl * | HTTP_Proxy = NULL |
static char * | HTTP_Proxy_Auth_base64 = NULL |
static char * | HTTP_Language_hdr = NULL |
static Dlist * | servers |
static Dlist * | fd_map |
HTTP connect functions.
Definition in file http.c.
#define MSG_BW | ( | web, | |
root, | |||
... | |||
) |
void a_Http_ccc | ( | int | Op, |
int | Branch, | ||
int | Dir, | ||
ChainLink * | Info, | ||
void * | Data1, | ||
void * | Data2 | ||
) |
CCC function for the HTTP module.
Definition at line 882 of file http.c.
References _MSG, a_Chain_bcb(), a_Chain_bfcb(), a_Chain_check(), a_Chain_fcb(), a_Chain_link_new(), a_Http_ccc(), a_IO_ccc(), a_Klist_get_data(), a_Tls_connect(), BCK, DataBuf::Buf, dFree(), dList_find_custom(), dReturn_if_fail, dStr_append(), dStr_free(), fd_map, FWD, Http_fd_map_cmp(), Http_get(), Http_sock_new(), Http_socket_free(), Http_socket_reuse(), INT2VOIDP, ChainLink::LocalKey, MSG, MSG_BW, MSG_WARN, OpAbort, OpEnd, OpSend, OpStart, URL_HOST, URL_STR, ValidSocks, and VOIDP2INT.
Referenced by a_Capi_ccc(), and a_Http_ccc().
void a_Http_connect_done | ( | int | fd, |
bool_t | success | ||
) |
Definition at line 214 of file http.c.
References a_Chain_bfcb(), a_Klist_get_data(), a_Web_valid(), dClose(), dFree(), dList_find_custom(), fd_map, Http_fd_map_cmp(), Http_send_query(), Http_socket_free(), INT2VOIDP, ChainLink::LocalKey, MSG, MSG_BW, OpAbort, OpSend, ValidSocks, and VOIDP2INT.
Referenced by a_Tls_mbedtls_connect(), a_Tls_openssl_connect(), Http_connect_socket(), Http_connect_socket_cb(), Http_socket_reuse(), Tls_connect(), and Tls_handshake().
void a_Http_freeall | ( | void | ) |
Deallocate memory used by http module.
(Call this one at exit time)
Definition at line 1127 of file http.c.
References a_Klist_free(), a_Url_free(), dFree(), Http_fd_map_remove_all(), HTTP_Language_hdr, HTTP_Proxy, HTTP_Proxy_Auth_base64, Http_servers_remove_all(), and ValidSocks.
Referenced by main().
int a_Http_init | ( | void | ) |
Initialize proxy vars and Accept-Language header.
Definition at line 118 of file http.c.
References a_Url_dup(), a_Url_new(), dList_new(), dStrconcat(), dStrdup(), fd_map, DilloPrefs::http_language, HTTP_Language_hdr, HTTP_Proxy, DilloPrefs::http_proxy, prefs, and servers.
Referenced by main().
int a_Http_proxy_auth | ( | void | ) |
Tell whether the proxy auth is already set (user:password).
Return: 1 Yes, 0 No
Definition at line 148 of file http.c.
References HTTP_Proxy_Auth_base64.
Referenced by main().
void a_Http_set_proxy_passwd | ( | const char * | str | ) |
Activate entered proxy password for HTTP.
Definition at line 156 of file http.c.
References a_Misc_encode_base64(), dFree(), dStrconcat(), HTTP_Proxy_Auth_base64, DilloPrefs::http_proxyuser, and prefs.
Referenced by main().
|
static |
Definition at line 249 of file http.c.
References _MSG, a_Tls_connect_ready(), a_Web_valid(), dFree(), dList_length(), dList_nth_data(), dList_remove(), Http_connect_socket(), DilloPrefs::http_max_conns, Http_server_remove(), Http_socket_activate(), Http_socket_free(), HTTP_SOCKET_TLS, HTTP_SOCKET_TO_BE_FREED, prefs, TLS_CONNECT_NEVER, TLS_CONNECT_READY, and VOIDP2INT.
Referenced by Http_dns_cb(), and Http_socket_free().
|
static |
This function is called after the DNS succeeds in solving a hostname.
Task: Finish socket setup and start connecting the socket.
Definition at line 567 of file http.c.
References a_Http_connect_done(), a_IOwatch_add_fd(), a_Klist_get_data(), a_Web_valid(), DilloHost::af, DilloHost::alen, DilloHost::data, dClose(), DIO_WRITE, dList_length(), dList_nth_data(), dStrerror, FALSE, Http_connect_socket_cb(), Http_connect_tls(), Http_fd_map_add_entry(), Http_fd_map_remove_entry(), HTTP_SOCKET_IOWATCH_ACTIVE, HTTP_SOCKET_TLS, ChainLink::LocalKey, MSG, MSG_BW, TRUE, ValidSocks, VOIDP2INT, and WEB_RootUrl.
Referenced by Http_connect_queued_sockets(), and Http_connect_socket_cb().
|
static |
connect() couldn't complete before, but now it's ready, so let's try again.
Definition at line 529 of file http.c.
References a_Http_connect_done(), a_IOwatch_remove_fd(), a_Klist_get_data(), dStrerror, Http_connect_socket(), Http_connect_tls(), HTTP_SOCKET_TLS, MSG, TRUE, ValidSocks, and VOIDP2INT.
Referenced by Http_connect_socket().
|
static |
Prepare an HTTPS connection.
If necessary, tunnel through a proxy first.
Definition at line 504 of file http.c.
References a_Chain_bcb(), a_Chain_bfcb(), a_Chain_dbuf_new(), a_Klist_get_data(), a_Tls_connect(), dFree(), dStr_new(), Http_get_connect_str(), HTTP_SOCKET_USE_PROXY, ChainLink::LocalKey, MSG_BW, OpSend, ValidSocks, and VOIDP2INT.
Referenced by Http_connect_socket(), and Http_connect_socket_cb().
|
static |
Callback function for the DNS resolver.
Continue connecting the socket, or abort upon error condition. S->web is checked to assert the operation wasn't aborted while waiting.
Definition at line 735 of file http.c.
References a_Chain_bfcb(), a_Klist_get_data(), a_Web_valid(), dFree(), FALSE, Http_connect_queued_sockets(), HTTP_Proxy, Http_server_get(), Http_socket_enqueue(), Http_socket_free(), HTTP_SOCKET_TLS, HTTP_SOCKET_USE_PROXY, MSG_BW, OpAbort, TRUE, URL_HOST, ValidSocks, and VOIDP2INT.
Referenced by Http_get().
|
static |
Definition at line 185 of file http.c.
References dList_append(), dList_find_custom(), dNew0, fd_map, Http_fd_map_cmp(), INT2VOIDP, MSG_ERR, and VOIDP2INT.
Referenced by Http_connect_socket(), and Http_socket_reuse().
|
static |
Compare by FD.
Definition at line 177 of file http.c.
References VOIDP2INT.
Referenced by a_Http_ccc(), a_Http_connect_done(), Http_fd_map_add_entry(), and Http_fd_map_remove_entry().
|
static |
Definition at line 1111 of file http.c.
References dFree(), dList_free(), dList_length(), dList_nth_data(), and fd_map.
Referenced by a_Http_freeall().
|
static |
Remove and free entry from fd_map.
Definition at line 202 of file http.c.
References dFree(), dList_find_custom(), dList_remove_fast(), fd_map, Http_fd_map_cmp(), INT2VOIDP, and MSG.
Referenced by Http_connect_socket(), and Http_socket_free().
|
static |
Asynchronously create a new http connection for 'Url'.
We'll set some socket parameters; the rest will be set later when the IP is known. ( Data1 = Web structure ) Return value: 0 on success, -1 otherwise
Definition at line 779 of file http.c.
References a_Dns_resolve(), a_Klist_get_data(), a_Url_dup(), dFree(), dStrAsciiCasecmp(), dStrdup(), DilloUrl::flags, Http_dns_cb(), Http_must_use_proxy(), HTTP_Proxy, HTTP_SOCKET_TLS, HTTP_SOCKET_USE_PROXY, ChainLink::LocalKey, MSG_BW, URL_HOST, URL_PORT, URL_SCHEME, ValidSocks, and VOIDP2INT.
Referenced by a_Http_ccc().
|
static |
Return a new string for the request used to tunnel HTTPS through a proxy.
Definition at line 692 of file http.c.
References dFree(), dReturn_val_if_fail, dStr_free(), dStr_new(), dStr_sprintfa(), dStrconcat(), dStrdup(), Http_must_use_proxy(), HTTP_Proxy_Auth_base64, Dstr::str, URL_AUTHORITY, and URL_HOST.
Referenced by Http_connect_tls().
|
static |
Make the HTTP header's Referer line according to preferences (default is "host" i.e.
"scheme://hostname/" ).
Definition at line 335 of file http.c.
References _MSG, dStrconcat(), dStrdup(), DilloPrefs::http_referer, prefs, URL_AUTHORITY, URL_PATH, URL_PATH_, and URL_SCHEME.
Referenced by Http_make_query_str().
Generate Content-Type header value for a POST query.
Definition at line 356 of file http.c.
References _MSG, dStr_append_c(), dStr_append_l(), dStr_new(), URL_DATA, URL_FLAGS, and URL_MultipartEnc.
Referenced by Http_make_query_str().
Make the http query string.
Definition at line 383 of file http.c.
References _MSG, a_Auth_get_auth_str(), a_Cookies_get_query(), dFree(), dStr_append_l(), dStr_free(), dStr_new(), dStr_printable(), dStr_sprintf(), dStr_sprintfa(), dStr_truncate(), _DilloWeb::flags, Http_get_referer(), HTTP_Language_hdr, Http_make_content_type(), DilloPrefs::http_persistent_conns, HTTP_Proxy_Auth_base64, DilloPrefs::http_user_agent, prefs, _DilloWeb::requester, Dstr::str, TRUE, _DilloWeb::url, URL_AUTHORITY, URL_DATA, URL_E2EQuery, URL_FLAGS, URL_PATH, URL_PATH_, URL_Post, URL_QUERY, URL_QUERY_, URL_STR, WEB_Image, and WEB_Stylesheet.
Referenced by Http_send_query().
|
static |
Test proxy settings and check the no_proxy domains list.
Return value: whether to use proxy or not.
Definition at line 662 of file http.c.
References _MSG, dFree(), dStrAsciiCasecmp(), dStrdup(), dStrsep(), HTTP_Proxy, DilloPrefs::no_proxy, and prefs.
Referenced by Http_get(), and Http_get_connect_str().
|
static |
Create and submit the HTTP query to the IO engine.
Definition at line 481 of file http.c.
References a_Chain_bcb(), a_Chain_dbuf_new(), dFree(), dStr_free(), Http_make_query_str(), HTTP_SOCKET_TLS, HTTP_SOCKET_USE_PROXY, Dstr::len, MSG_BW, OpSend, and Dstr::str.
Referenced by a_Http_connect_done().
Definition at line 1057 of file http.c.
References dList_append(), dList_length(), dList_new(), dList_nth_data(), dNew0, dStrAsciiCasecmp(), dStrdup(), and servers.
Referenced by Http_dns_cb(), Http_socket_free(), and Http_socket_reuse().
|
static |
Definition at line 1081 of file http.c.
References dFree(), dList_free(), dList_nth_data(), dList_remove_fast(), and servers.
Referenced by Http_connect_queued_sockets(), and Http_servers_remove_all().
|
static |
Definition at line 1095 of file http.c.
References dFree(), dList_free(), dList_length(), dList_nth_data(), dList_remove(), Http_server_remove(), and servers.
Referenced by a_Http_freeall().
|
static |
Create and init a new SocketData_t struct, insert into ValidSocks, and return a primary key for it.
Definition at line 167 of file http.c.
References a_Klist_insert(), dNew0, and ValidSocks.
Referenced by a_Http_ccc().
|
static |
Definition at line 241 of file http.c.
References dList_remove().
Referenced by Http_connect_queued_sockets(), and Http_socket_reuse().
|
static |
Add socket data to the queue.
Pages/stylesheets/etc. have higher priority than images.
Definition at line 1038 of file http.c.
References a_Web_valid(), dList_append(), dList_insert_pos(), dList_length(), dList_nth_data(), HTTP_SOCKET_QUEUED, and WEB_Image.
Referenced by Http_dns_cb().
|
static |
Free SocketData_t struct.
Definition at line 296 of file http.c.
References a_IOwatch_remove_fd(), a_Klist_get_data(), a_Klist_remove(), a_Tls_close_by_fd(), a_Tls_reset_server_state(), a_Url_free(), dClose(), dFree(), dStr_free(), Http_connect_queued_sockets(), Http_fd_map_remove_entry(), Http_server_get(), HTTP_SOCKET_IOWATCH_ACTIVE, HTTP_SOCKET_QUEUED, HTTP_SOCKET_TLS, HTTP_SOCKET_TO_BE_FREED, and ValidSocks.
Referenced by a_Http_ccc(), a_Http_connect_done(), Http_connect_queued_sockets(), Http_dns_cb(), and Http_socket_reuse().
|
static |
If any entry in the socket data queue can reuse our connection, set it up and send off a new query.
Definition at line 841 of file http.c.
References _MSG, a_Http_connect_done(), a_Klist_get_data(), dClose(), dList_length(), dList_nth_data(), Http_fd_map_add_entry(), Http_server_get(), Http_socket_activate(), Http_socket_free(), Http_socket_reuse_compatible(), HTTP_SOCKET_TLS, HTTP_SOCKET_TO_BE_FREED, TRUE, URL_STR, and ValidSocks.
Referenced by a_Http_ccc().
|
static |
Can the old socket's fd be reused for the new socket?.
NOTE: old and new must come from the same Server_t. This is not built to accept arbitrary sockets.
Definition at line 821 of file http.c.
References a_Web_valid(), dStrAsciiCasecmp(), FALSE, HTTP_SOCKET_TLS, HTTP_SOCKET_USE_PROXY, TRUE, URL_HOST, and URL_PORT.
Referenced by Http_socket_reuse().
|
static |
Definition at line 113 of file http.c.
Referenced by a_Http_ccc(), a_Http_connect_done(), a_Http_init(), Http_fd_map_add_entry(), Http_fd_map_remove_all(), and Http_fd_map_remove_entry().
|
static |
Definition at line 107 of file http.c.
Referenced by a_Http_freeall(), a_Http_init(), and Http_make_query_str().
|
static |
Definition at line 105 of file http.c.
Referenced by a_Http_freeall(), a_Http_init(), Http_dns_cb(), Http_get(), and Http_must_use_proxy().
|
static |
Definition at line 106 of file http.c.
Referenced by a_Http_freeall(), a_Http_proxy_auth(), a_Http_set_proxy_passwd(), Http_get_connect_str(), and Http_make_query_str().
|
static |
Definition at line 58 of file http.c.
Referenced by Http_connect_socket(), and Http_socket_free().
|
static |
Definition at line 55 of file http.c.
Referenced by Http_socket_enqueue(), and Http_socket_free().
|
static |
Definition at line 57 of file http.c.
Referenced by Http_connect_queued_sockets(), Http_connect_socket(), Http_connect_socket_cb(), Http_dns_cb(), Http_get(), Http_send_query(), Http_socket_free(), Http_socket_reuse(), and Http_socket_reuse_compatible().
|
static |
Definition at line 56 of file http.c.
Referenced by Http_connect_queued_sockets(), Http_socket_free(), and Http_socket_reuse().
|
static |
Definition at line 54 of file http.c.
Referenced by Http_connect_tls(), Http_dns_cb(), Http_get(), Http_send_query(), and Http_socket_reuse_compatible().
|
static |
Definition at line 108 of file http.c.
Referenced by a_Http_init(), Http_server_get(), Http_server_remove(), and Http_servers_remove_all().
|
static |
Definition at line 103 of file http.c.
Referenced by a_Http_ccc(), a_Http_connect_done(), a_Http_freeall(), Http_connect_socket(), Http_connect_socket_cb(), Http_connect_tls(), Http_dns_cb(), Http_get(), Http_sock_new(), Http_socket_free(), and Http_socket_reuse().