Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
http.c File Reference

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"
Include dependency graph for http.c:

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 DstrHttp_make_content_type (const DilloUrl *url)
 Generate Content-Type header value for a POST query.
 
static DstrHttp_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_tValidSocks = NULL
 
static DilloUrlHTTP_Proxy = NULL
 
static char * HTTP_Proxy_Auth_base64 = NULL
 
static char * HTTP_Language_hdr = NULL
 
static Dlistservers
 
static Dlistfd_map
 

Detailed Description

HTTP connect functions.

Definition in file http.c.

Macro Definition Documentation

◆ _MSG_BW

#define _MSG_BW (   web,
  root,
  ... 
)

Definition at line 52 of file http.c.

◆ MSG_BW

#define MSG_BW (   web,
  root,
  ... 
)
Value:
if (a_Web_valid((web)) && (!(root) || (web)->flags & WEB_RootUrl)) \
a_UIcmd_set_msg((web)->bw, __VA_ARGS__); \
#define D_STMT_START
Definition dlib.h:62
#define D_STMT_END
Definition dlib.h:63
int a_Web_valid(DilloWeb *web)
Validate a DilloWeb pointer.
Definition web.cc:144
#define WEB_RootUrl
Definition web.hh:16

Definition at line 46 of file http.c.

Function Documentation

◆ a_Http_ccc()

◆ a_Http_connect_done()

◆ a_Http_freeall()

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().

◆ a_Http_init()

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().

◆ a_Http_proxy_auth()

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().

◆ a_Http_set_proxy_passwd()

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().

◆ Http_connect_queued_sockets()

◆ Http_connect_socket()

static void Http_connect_socket ( ChainLink Info)
static

◆ Http_connect_socket_cb()

static void Http_connect_socket_cb ( int  fd,
void *  data 
)
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().

◆ Http_connect_tls()

static void Http_connect_tls ( ChainLink info)
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().

◆ Http_dns_cb()

static void Http_dns_cb ( int  Status,
Dlist addr_list,
void *  data 
)
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().

◆ Http_fd_map_add_entry()

static void Http_fd_map_add_entry ( SocketData_t *  sd)
static

◆ Http_fd_map_cmp()

static int Http_fd_map_cmp ( const void *  v1,
const void *  v2 
)
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().

◆ Http_fd_map_remove_all()

static void Http_fd_map_remove_all ( void  )
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().

◆ Http_fd_map_remove_entry()

static void Http_fd_map_remove_entry ( int  fd)
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().

◆ Http_get()

static int Http_get ( ChainLink Info,
void *  Data1 
)
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().

◆ Http_get_connect_str()

static char * Http_get_connect_str ( const DilloUrl url)
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().

◆ Http_get_referer()

static char * Http_get_referer ( const DilloUrl url)
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().

◆ Http_make_content_type()

static Dstr * Http_make_content_type ( const DilloUrl url)
static

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().

◆ Http_make_query_str()

◆ Http_must_use_proxy()

static int Http_must_use_proxy ( const char *  hostname)
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().

◆ Http_send_query()

static void Http_send_query ( SocketData_t *  S)
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().

◆ Http_server_get()

static Server_t * Http_server_get ( const char *  host,
uint_t  port,
bool_t  https 
)
static

◆ Http_server_remove()

static void Http_server_remove ( Server_t *  srv)
static

◆ Http_servers_remove_all()

static void Http_servers_remove_all ( void  )
static

◆ Http_sock_new()

static int Http_sock_new ( void  )
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().

◆ Http_socket_activate()

static void Http_socket_activate ( Server_t *  srv,
SocketData_t *  sd 
)
static

Definition at line 241 of file http.c.

References dList_remove().

Referenced by Http_connect_queued_sockets(), and Http_socket_reuse().

◆ Http_socket_enqueue()

static void Http_socket_enqueue ( Server_t *  srv,
SocketData_t *  sock 
)
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().

◆ Http_socket_free()

◆ Http_socket_reuse()

static void Http_socket_reuse ( int  SKey)
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().

◆ Http_socket_reuse_compatible()

static bool_t Http_socket_reuse_compatible ( SocketData_t *  old,
SocketData_t *  new 
)
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().

Variable Documentation

◆ fd_map

◆ HTTP_Language_hdr

char* HTTP_Language_hdr = NULL
static

Definition at line 107 of file http.c.

Referenced by a_Http_freeall(), a_Http_init(), and Http_make_query_str().

◆ HTTP_Proxy

DilloUrl* HTTP_Proxy = NULL
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().

◆ HTTP_Proxy_Auth_base64

char* HTTP_Proxy_Auth_base64 = NULL
static

◆ HTTP_SOCKET_IOWATCH_ACTIVE

const int HTTP_SOCKET_IOWATCH_ACTIVE = 0x10
static

Definition at line 58 of file http.c.

Referenced by Http_connect_socket(), and Http_socket_free().

◆ HTTP_SOCKET_QUEUED

const int HTTP_SOCKET_QUEUED = 0x2
static

Definition at line 55 of file http.c.

Referenced by Http_socket_enqueue(), and Http_socket_free().

◆ HTTP_SOCKET_TLS

◆ HTTP_SOCKET_TO_BE_FREED

const int HTTP_SOCKET_TO_BE_FREED = 0x4
static

Definition at line 56 of file http.c.

Referenced by Http_connect_queued_sockets(), Http_socket_free(), and Http_socket_reuse().

◆ HTTP_SOCKET_USE_PROXY

const int HTTP_SOCKET_USE_PROXY = 0x1
static

◆ servers

Dlist* servers
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().

◆ ValidSocks