Dillo v3.1.1-119-g140d9ebd
Loading...
Searching...
No Matches
url.h File Reference

Parse and normalize all URL's inside Dillo. More...

#include "d_size.h"
#include "../dlib/dlib.h"
Include dependency graph for url.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  DilloUrl
 

Macros

#define URL_HTTP_PORT   80
 
#define URL_HTTPS_PORT   443
 
#define URL_HOST_ERROR   -1
 
#define URL_HOST_NAME   0
 
#define URL_HOST_IPV4   1
 
#define URL_HOST_IPV6   2
 
#define URL_Get   (1 << 0)
 
#define URL_Post   (1 << 1)
 
#define URL_E2EQuery   (1 << 5)
 
#define URL_ReloadPage   (1 << 7)
 
#define URL_ReloadFromCache   (1 << 8)
 
#define URL_IgnoreScroll   (1 << 9)
 
#define URL_SpamSafe   (1 << 10)
 
#define URL_MultipartEnc   (1 << 11)
 
#define URL_SCHEME_(u)   (u)->scheme
 
#define URL_AUTHORITY_(u)   (u)->authority
 
#define URL_PATH_(u)   (u)->path
 
#define URL_QUERY_(u)   (u)->query
 
#define URL_FRAGMENT_(u)   (u)->fragment
 
#define URL_HOST_(u)   a_Url_hostname(u)
 
#define URL_STR_(u)   a_Url_str(u)
 
#define URL_DATA_(u)   (u)->data
 
#define URL_PORT_(u)   (URL_HOST(u), (u)->port)
 
#define URL_FLAGS_(u)   (u)->flags
 
#define URL_ILLEGAL_CHARS_(u)   (u)->illegal_chars
 
#define URL_ILLEGAL_CHARS_SPC_(u)   (u)->illegal_chars_spc
 
#define NPTR2STR(p)   ((p) ? (p) : "")
 
#define URL_SCHEME(u)   NPTR2STR(URL_SCHEME_(u))
 
#define URL_AUTHORITY(u)   NPTR2STR(URL_AUTHORITY_(u))
 
#define URL_PATH(u)   NPTR2STR(URL_PATH_(u))
 
#define URL_QUERY(u)   NPTR2STR(URL_QUERY_(u))
 
#define URL_FRAGMENT(u)   NPTR2STR(URL_FRAGMENT_(u))
 
#define URL_HOST(u)   NPTR2STR(URL_HOST_(u))
 
#define URL_STR(u)   NPTR2STR(URL_STR_(u))
 
#define URL_DATA(u)   URL_DATA_(u)
 
#define URL_PORT(u)   URL_PORT_(u)
 
#define URL_FLAGS(u)   URL_FLAGS_(u)
 
#define URL_ILLEGAL_CHARS(u)   URL_ILLEGAL_CHARS_(u)
 
#define URL_ILLEGAL_CHARS_SPC(u)   URL_ILLEGAL_CHARS_SPC_(u)
 

Functions

DilloUrla_Url_new (const char *url_str, const char *base_url)
 Transform (and resolve) an URL string into the respective DilloURL.
 
void a_Url_free (DilloUrl *u)
 Free a DilloUrl.
 
char * a_Url_str (const DilloUrl *url)
 Return the url as a string.
 
const char * a_Url_hostname (const DilloUrl *u)
 Return the hostname as a string.
 
DilloUrla_Url_dup (const DilloUrl *u)
 Duplicate a Url structure.
 
int a_Url_cmp (const DilloUrl *A, const DilloUrl *B)
 Compare two Url's to check if they're the same, or which one is bigger.
 
void a_Url_set_flags (DilloUrl *u, int flags)
 Set DilloUrl flags.
 
void a_Url_set_data (DilloUrl *u, Dstr **data)
 Set DilloUrl data (like POST info, etc.)
 
void a_Url_set_ismap_coords (DilloUrl *u, char *coord_str)
 Set DilloUrl ismap coordinates.
 
char * a_Url_decode_hex_str (const char *str)
 Parse possible hexadecimal octets in the URI path.
 
char * a_Url_encode_hex_str (const char *str)
 Urlencode 'str'.
 
char * a_Url_string_strip_delimiters (const char *str)
 RFC-3986 suggests this stripping when "importing" URLs from other media.
 
int a_Url_host_type (const char *host)
 What type of host is this?
 
bool_t a_Url_same_organization (const DilloUrl *u1, const DilloUrl *u2)
 

Detailed Description

Parse and normalize all URL's inside Dillo.

Definition in file url.h.

Macro Definition Documentation

◆ NPTR2STR

#define NPTR2STR (   p)    ((p) ? (p) : "")

Definition at line 69 of file url.h.

◆ URL_AUTHORITY

#define URL_AUTHORITY (   u)    NPTR2STR(URL_AUTHORITY_(u))

Definition at line 71 of file url.h.

◆ URL_AUTHORITY_

#define URL_AUTHORITY_ (   u)    (u)->authority

Definition at line 50 of file url.h.

◆ URL_DATA

#define URL_DATA (   u)    URL_DATA_(u)

Definition at line 77 of file url.h.

◆ URL_DATA_

#define URL_DATA_ (   u)    (u)->data

Definition at line 57 of file url.h.

◆ URL_E2EQuery

#define URL_E2EQuery   (1 << 5)

Definition at line 35 of file url.h.

◆ URL_FLAGS

#define URL_FLAGS (   u)    URL_FLAGS_(u)

Definition at line 79 of file url.h.

◆ URL_FLAGS_

#define URL_FLAGS_ (   u)    (u)->flags

Definition at line 60 of file url.h.

◆ URL_FRAGMENT

#define URL_FRAGMENT (   u)    NPTR2STR(URL_FRAGMENT_(u))

Definition at line 74 of file url.h.

◆ URL_FRAGMENT_

#define URL_FRAGMENT_ (   u)    (u)->fragment

Definition at line 53 of file url.h.

◆ URL_Get

#define URL_Get   (1 << 0)

Definition at line 32 of file url.h.

◆ URL_HOST

#define URL_HOST (   u)    NPTR2STR(URL_HOST_(u))

Definition at line 75 of file url.h.

◆ URL_HOST_

#define URL_HOST_ (   u)    a_Url_hostname(u)

Definition at line 54 of file url.h.

◆ URL_HOST_ERROR

#define URL_HOST_ERROR   -1

Definition at line 23 of file url.h.

◆ URL_HOST_IPV4

#define URL_HOST_IPV4   1

Definition at line 25 of file url.h.

◆ URL_HOST_IPV6

#define URL_HOST_IPV6   2

Definition at line 26 of file url.h.

◆ URL_HOST_NAME

#define URL_HOST_NAME   0

Definition at line 24 of file url.h.

◆ URL_HTTP_PORT

#define URL_HTTP_PORT   80

Definition at line 19 of file url.h.

◆ URL_HTTPS_PORT

#define URL_HTTPS_PORT   443

Definition at line 20 of file url.h.

◆ URL_IgnoreScroll

#define URL_IgnoreScroll   (1 << 9)

Definition at line 39 of file url.h.

◆ URL_ILLEGAL_CHARS

#define URL_ILLEGAL_CHARS (   u)    URL_ILLEGAL_CHARS_(u)

Definition at line 80 of file url.h.

◆ URL_ILLEGAL_CHARS_

#define URL_ILLEGAL_CHARS_ (   u)    (u)->illegal_chars

Definition at line 61 of file url.h.

◆ URL_ILLEGAL_CHARS_SPC

#define URL_ILLEGAL_CHARS_SPC (   u)    URL_ILLEGAL_CHARS_SPC_(u)

Definition at line 81 of file url.h.

◆ URL_ILLEGAL_CHARS_SPC_

#define URL_ILLEGAL_CHARS_SPC_ (   u)    (u)->illegal_chars_spc

Definition at line 62 of file url.h.

◆ URL_MultipartEnc

#define URL_MultipartEnc   (1 << 11)

Definition at line 42 of file url.h.

◆ URL_PATH

#define URL_PATH (   u)    NPTR2STR(URL_PATH_(u))

Definition at line 72 of file url.h.

◆ URL_PATH_

#define URL_PATH_ (   u)    (u)->path

Definition at line 51 of file url.h.

◆ URL_PORT

#define URL_PORT (   u)    URL_PORT_(u)

Definition at line 78 of file url.h.

◆ URL_PORT_

#define URL_PORT_ (   u)    (URL_HOST(u), (u)->port)

Definition at line 59 of file url.h.

◆ URL_Post

#define URL_Post   (1 << 1)

Definition at line 33 of file url.h.

◆ URL_QUERY

#define URL_QUERY (   u)    NPTR2STR(URL_QUERY_(u))

Definition at line 73 of file url.h.

◆ URL_QUERY_

#define URL_QUERY_ (   u)    (u)->query

Definition at line 52 of file url.h.

◆ URL_ReloadFromCache

#define URL_ReloadFromCache   (1 << 8)

Definition at line 37 of file url.h.

◆ URL_ReloadPage

#define URL_ReloadPage   (1 << 7)

Definition at line 36 of file url.h.

◆ URL_SCHEME

#define URL_SCHEME (   u)    NPTR2STR(URL_SCHEME_(u))

Definition at line 70 of file url.h.

◆ URL_SCHEME_

#define URL_SCHEME_ (   u)    (u)->scheme

Definition at line 49 of file url.h.

◆ URL_SpamSafe

#define URL_SpamSafe   (1 << 10)

Definition at line 40 of file url.h.

◆ URL_STR

#define URL_STR (   u)    NPTR2STR(URL_STR_(u))

Definition at line 76 of file url.h.

◆ URL_STR_

#define URL_STR_ (   u)    a_Url_str(u)

Definition at line 55 of file url.h.

Function Documentation

◆ a_Url_cmp()

int a_Url_cmp ( const DilloUrl A,
const DilloUrl B 
)

Compare two Url's to check if they're the same, or which one is bigger.

The fields which are compared here are: <scheme>, <authority>, <path>, <query> and <data> Other fields are left for the caller to check

Return value: 0 if equal, > 0 if A > B, < 0 if A < B.

Note: this function defines a sorting order different from strcmp!

Definition at line 506 of file url.c.

References DilloUrl::authority, DilloUrl::data, dReturn_val_if_fail, dStr_cmp(), DilloUrl::path, DilloUrl::query, DilloUrl::scheme, URL_STR_FIELD_CMP, and URL_STR_FIELD_I_CMP.

Referenced by a_Bw_add_url(), a_Bw_get_url_doc(), a_Capi_conn_abort_by_url(), a_History_add_url(), a_History_get_title_by_url(), a_History_set_title_by_url(), a_Nav_cancel_expect_if_eq(), a_Nav_push(), Cache_entry_by_url_cmp(), Cache_entry_cmp(), Dicache_entry_cmp(), Html_tag_open_meta(), DilloHtml::loadImages(), and Nav_open_url().

◆ a_Url_decode_hex_str()

char * a_Url_decode_hex_str ( const char *  str)

Parse possible hexadecimal octets in the URI path.

Returns a new allocated string.

Definition at line 586 of file url.c.

References dNew, dRealloc(), dStrdup(), and Url_decode_hex_octet().

◆ a_Url_dup()

◆ a_Url_encode_hex_str()

char * a_Url_encode_hex_str ( const char *  str)

Urlencode 'str'.

-RL :: According to the RFC 1738, only alphanumerics, the special characters "$-_.+!*'(),", and reserved characters ";/?:@=&" used for their reserved purposes may be used unencoded within a URL. We'll escape everything but alphanumeric and "-_.*" (as lynx). –Jcid

Note: the content type "application/x-www-form-urlencoded" is used: i.e., ' ' -> '+' and '
' -> CR LF (see HTML 4.01, Sec. 17.13.4)

Definition at line 620 of file url.c.

References d_isascii, dIsalnum, dNew, and HEX.

Referenced by Menu_bugmeter_validate(), and UIcmd_make_search_str().

◆ a_Url_free()

◆ a_Url_host_type()

int a_Url_host_type ( const char *  host)

◆ a_Url_hostname()

const char * a_Url_hostname ( const DilloUrl u)

Return the hostname as a string.

(initializing 'hostname' and 'port' fields if necessary) Note: a similar approach can be taken for user:password auth.

Definition at line 98 of file url.c.

References DilloUrl::authority, dStrAsciiCasecmp(), dStrndup(), DilloUrl::hostname, DilloUrl::port, DilloUrl::scheme, URL_HTTP_PORT, and URL_HTTPS_PORT.

Referenced by a_Url_new().

◆ a_Url_new()

DilloUrl * a_Url_new ( const char *  url_str,
const char *  base_url 
)

Transform (and resolve) an URL string into the respective DilloURL.

If URL = "http://dillo.sf.net:8080/index.html?long#part2" then the resulting DilloURL should be:

DilloURL = {
url_string = "http://dillo.sf.net:8080/index.html?long#part2"
scheme = "http"
authority = "dillo.sf.net:8080:
path = "/index.html"
query = "long"
fragment = "part2"
hostname = "dillo.sf.net"
port = 8080
flags = URL_Get
data = Dstr * ("")
ismap_url_len = 0
}

Return NULL if URL is badly formed.

Definition at line 371 of file url.c.

References _MSG, a_Hsts_require_https(), a_Url_hostname(), DilloUrl::authority, DilloUrl::data, dFree(), dNew, dStr_free(), dStr_new(), dStrAsciiCasecmp(), dStrconcat(), FALSE, HEX, DilloPrefs::http_force_https, DilloPrefs::http_strict_transport_security, DilloUrl::illegal_chars, DilloUrl::illegal_chars_spc, DilloUrl::port, prefs, DilloUrl::scheme, Dstr::str, TRUE, URL_HTTP_PORT, URL_HTTPS_PORT, Url_object_new(), Url_resolve_relative(), and DilloUrl::url_string.

Referenced by a_Cache_init(), a_Html_url_new(), a_Http_init(), a_Prefs_init(), a_UIcmd_book(), a_UIcmd_open_file(), a_UIcmd_open_urlstr(), a_UIcmd_view_page_source(), StyleEngine::apply(), Cache_parse_header(), Cache_redirect(), makeStartUrl(), parseOption(), and CssParser::parseUrl().

◆ a_Url_same_organization()

bool_t a_Url_same_organization ( const DilloUrl u1,
const DilloUrl u2 
)

◆ a_Url_set_data()

void a_Url_set_data ( DilloUrl u,
Dstr **  data 
)

Set DilloUrl data (like POST info, etc.)

Definition at line 536 of file url.c.

References DilloUrl::data, and dStr_free().

◆ a_Url_set_flags()

void a_Url_set_flags ( DilloUrl u,
int  flags 
)

◆ a_Url_set_ismap_coords()

void a_Url_set_ismap_coords ( DilloUrl u,
char *  coord_str 
)

Set DilloUrl ismap coordinates.

(this is optimized for not hogging the CPU)

Definition at line 549 of file url.c.

References dReturn_if_fail, dStr_append(), dStr_truncate(), DilloUrl::ismap_url_len, Dstr::len, DilloUrl::query, Dstr::str, URL_STR_, and DilloUrl::url_string.

Referenced by Html_set_link_coordinates().

◆ a_Url_str()

char * a_Url_str ( const DilloUrl u)

◆ a_Url_string_strip_delimiters()

char * a_Url_string_strip_delimiters ( const char *  str)

RFC-3986 suggests this stripping when "importing" URLs from other media.

Strip: "URL:", enclosing < >, and embedded whitespace. (We also strip illegal chars: 00-1F and 7F-FF)

Definition at line 658 of file url.c.

References dStrdup().

Referenced by a_UIcmd_open_urlstr(), and makeStartUrl().