URI header now returns pointers with ownership.
I've put `.release()` at most of the callsites, but this gives me something to search for when taking the next steps.
This commit is contained in:
59
src/url.cc
59
src/url.cc
@ -66,10 +66,11 @@ static const char *HEX = "0123456789ABCDEF";
|
||||
* Return the url as a string.
|
||||
* (initializing 'url_string' field if necessary)
|
||||
*/
|
||||
char *a_Url_str(const DilloUrl *u)
|
||||
char *a_Url_str(const DilloUrl &u)
|
||||
{
|
||||
DilloUrl &u_nc= const_cast< DilloUrl & >( u );
|
||||
/* Internal url handling IS transparent to the caller */
|
||||
DilloUrl *url = (DilloUrl *) u;
|
||||
DilloUrl *url = &u_nc;
|
||||
|
||||
dReturn_val_if_fail (url != NULL, NULL);
|
||||
|
||||
@ -95,11 +96,12 @@ char *a_Url_str(const DilloUrl *u)
|
||||
* (initializing 'hostname' and 'port' fields if necessary)
|
||||
* Note: a similar approach can be taken for user:password auth.
|
||||
*/
|
||||
const char *a_Url_hostname(const DilloUrl *u)
|
||||
const char *a_Url_hostname(const DilloUrl &u)
|
||||
{
|
||||
DilloUrl &u_nc= const_cast< DilloUrl & >( u );
|
||||
const char *p;
|
||||
/* Internal url handling IS transparent to the caller */
|
||||
DilloUrl *url = (DilloUrl *) u;
|
||||
DilloUrl *url = &u_nc;
|
||||
|
||||
if (!url->hostname && url->authority) {
|
||||
if (url->authority[0] == '[' && (p = strchr(url->authority, ']'))) {
|
||||
@ -358,7 +360,7 @@ static std::string Url_resolve_relative(const char *RelStr,
|
||||
*
|
||||
* Return NULL if URL is badly formed.
|
||||
*/
|
||||
DilloUrl* a_Url_new(const char *url_str, const char *base_url)
|
||||
std::unique_ptr< DilloUrl > a_Url_new(const char *url_str, const char *base_url)
|
||||
{
|
||||
std::unique_ptr< DilloUrl > url;
|
||||
char *urlstr = (char *)url_str; /* auxiliary variable, don't free */
|
||||
@ -367,12 +369,12 @@ DilloUrl* a_Url_new(const char *url_str, const char *base_url)
|
||||
int i, n_ic, n_ic_spc;
|
||||
|
||||
if (!url_str)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
/* Empty URL without base_url is not valid.
|
||||
* They are used for action="" in forms with base_url set. */
|
||||
if (url_str[0] == '\0' && base_url == NULL)
|
||||
return NULL;
|
||||
return nullptr;
|
||||
|
||||
/* Count illegal characters (0x00-0x1F, 0x7F-0xFF and space) */
|
||||
n_ic = n_ic_spc = 0;
|
||||
@ -429,7 +431,7 @@ DilloUrl* a_Url_new(const char *url_str, const char *base_url)
|
||||
* URLs like "http://en.wikipedia.org:80" to "https://en.wikipedia.org:443".
|
||||
*/
|
||||
if (prefs.http_strict_transport_security &&
|
||||
a_Hsts_require_https(a_Url_hostname(url.get()))) {
|
||||
a_Hsts_require_https(a_Url_hostname(*url))) {
|
||||
_MSG("url: HSTS transformation for %s.\n", url->url_string->str);
|
||||
switch_to_https = TRUE;
|
||||
} else if (prefs.http_force_https) {
|
||||
@ -456,26 +458,26 @@ DilloUrl* a_Url_new(const char *url_str, const char *base_url)
|
||||
url->url_string.reset();
|
||||
}
|
||||
|
||||
return url.release();
|
||||
return url;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Duplicate a Url structure
|
||||
*/
|
||||
DilloUrl* a_Url_dup(const DilloUrl *ori)
|
||||
std::unique_ptr< DilloUrl > a_Url_dup(const DilloUrl &ori)
|
||||
{
|
||||
auto url = Url_object_new(URL_STR_(ori));
|
||||
auto url = Url_object_new(URL_STR_(&ori));
|
||||
dReturn_val_if_fail (url != NULL, NULL);
|
||||
|
||||
url->url_string = URL_STR(ori);
|
||||
url->port = ori->port;
|
||||
url->flags = ori->flags;
|
||||
url->ismap_url_len = ori->ismap_url_len;
|
||||
url->illegal_chars = ori->illegal_chars;
|
||||
url->illegal_chars_spc = ori->illegal_chars_spc;
|
||||
url->data = ori->data;
|
||||
return url.release();
|
||||
url->url_string = URL_STR(&ori);
|
||||
url->port = ori.port;
|
||||
url->flags = ori.flags;
|
||||
url->ismap_url_len = ori.ismap_url_len;
|
||||
url->illegal_chars = ori.illegal_chars;
|
||||
url->illegal_chars_spc = ori.illegal_chars_spc;
|
||||
url->data = ori.data;
|
||||
return url;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -489,8 +491,11 @@ DilloUrl* a_Url_dup(const DilloUrl *ori)
|
||||
*
|
||||
* Note: this function defines a sorting order different from strcmp!
|
||||
*/
|
||||
int a_Url_cmp(const DilloUrl *A, const DilloUrl *B)
|
||||
int a_Url_cmp(const DilloUrl &A_, const DilloUrl &B_)
|
||||
{
|
||||
const DilloUrl *const A= &A_;
|
||||
const DilloUrl *const B= &B_;
|
||||
|
||||
int st;
|
||||
|
||||
dReturn_val_if_fail(A && B, 1);
|
||||
@ -510,18 +515,17 @@ int a_Url_cmp(const DilloUrl *A, const DilloUrl *B)
|
||||
/**
|
||||
* Set DilloUrl flags
|
||||
*/
|
||||
void a_Url_set_flags(DilloUrl *u, int flags)
|
||||
void a_Url_set_flags(DilloUrl &u, int flags)
|
||||
{
|
||||
if (u)
|
||||
u->flags = flags;
|
||||
u.flags = flags;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set DilloUrl data (like POST info, etc.)
|
||||
*/
|
||||
void a_Url_set_data(DilloUrl *u, std::string_view data)
|
||||
void a_Url_set_data(DilloUrl &u, std::string_view data)
|
||||
{
|
||||
u->data= data;
|
||||
u.data= data;
|
||||
}
|
||||
|
||||
/**
|
||||
@ -777,8 +781,11 @@ static const char *Url_host_find_public_suffix(const char *host)
|
||||
return s;
|
||||
}
|
||||
|
||||
bool_t a_Url_same_organization(const DilloUrl *u1, const DilloUrl *u2)
|
||||
bool_t a_Url_same_organization(const DilloUrl &u1_, const DilloUrl &u2_)
|
||||
{
|
||||
const DilloUrl *const u1= &u1_;
|
||||
const DilloUrl *const u2= &u2_;
|
||||
|
||||
if (!u1 || !u2)
|
||||
return FALSE;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user