Prefs struct is mostly ownership safe now.
This commit is contained in:
+6
-6
@@ -127,13 +127,13 @@ int a_Http_init(void)
|
|||||||
char *env_proxy = getenv("http_proxy");
|
char *env_proxy = getenv("http_proxy");
|
||||||
|
|
||||||
HTTP_Language_hdr = prefs.http_language ?
|
HTTP_Language_hdr = prefs.http_language ?
|
||||||
dStrconcat("Accept-Language: ", prefs.http_language, "\r\n", NULL) :
|
dStrconcat("Accept-Language: ", prefs.http_language.value().c_str(), "\r\n", NULL) :
|
||||||
dStrdup("");
|
dStrdup("");
|
||||||
|
|
||||||
if (env_proxy && strlen(env_proxy))
|
if (env_proxy && strlen(env_proxy))
|
||||||
HTTP_Proxy = a_Url_new(env_proxy, NULL).release();
|
HTTP_Proxy = a_Url_new(env_proxy, NULL).release();
|
||||||
if (!HTTP_Proxy && prefs.http_proxy)
|
if (!HTTP_Proxy && prefs.http_proxy)
|
||||||
HTTP_Proxy = a_Url_dup(prefs.http_proxy).release();
|
HTTP_Proxy = a_Url_dup(prefs.http_proxy.get()).release();
|
||||||
|
|
||||||
/* This allows for storing the proxy password in "user:passwd" format
|
/* This allows for storing the proxy password in "user:passwd" format
|
||||||
* in dillorc, but as this constitutes a security problem, it was disabled.
|
* in dillorc, but as this constitutes a security problem, it was disabled.
|
||||||
@@ -159,7 +159,7 @@ int a_Http_proxy_auth(void)
|
|||||||
*/
|
*/
|
||||||
void a_Http_set_proxy_passwd(const char *str)
|
void a_Http_set_proxy_passwd(const char *str)
|
||||||
{
|
{
|
||||||
char *http_proxyauth = dStrconcat(prefs.http_proxyuser, ":", str, NULL);
|
char *http_proxyauth = dStrconcat(prefs.http_proxyuser.value().c_str(), ":", str, NULL);
|
||||||
HTTP_Proxy_Auth_base64 = a_Misc_encode_base64(http_proxyauth);
|
HTTP_Proxy_Auth_base64 = a_Misc_encode_base64(http_proxyauth);
|
||||||
dFree(http_proxyauth);
|
dFree(http_proxyauth);
|
||||||
}
|
}
|
||||||
@@ -337,10 +337,10 @@ static char *Http_get_referer(const DilloUrl *url)
|
|||||||
{
|
{
|
||||||
char *referer = NULL;
|
char *referer = NULL;
|
||||||
|
|
||||||
if (!strcmp(prefs.http_referer, "host")) {
|
if (!strcmp(prefs.http_referer.c_str(), "host")) {
|
||||||
referer = dStrconcat("Referer: ", URL_SCHEME(url), "://",
|
referer = dStrconcat("Referer: ", URL_SCHEME(url), "://",
|
||||||
URL_AUTHORITY(url), "/", "\r\n", NULL);
|
URL_AUTHORITY(url), "/", "\r\n", NULL);
|
||||||
} else if (!strcmp(prefs.http_referer, "path")) {
|
} else if (!strcmp(prefs.http_referer.c_str(), "path")) {
|
||||||
referer = dStrconcat("Referer: ", URL_SCHEME(url), "://",
|
referer = dStrconcat("Referer: ", URL_SCHEME(url), "://",
|
||||||
URL_AUTHORITY(url),
|
URL_AUTHORITY(url),
|
||||||
URL_PATH_(url) ? URL_PATH(url) : "/", "\r\n", NULL);
|
URL_PATH_(url) ? URL_PATH(url) : "/", "\r\n", NULL);
|
||||||
@@ -684,7 +684,7 @@ static int Http_must_use_proxy(const char *hostname)
|
|||||||
if (prefs.no_proxy) {
|
if (prefs.no_proxy) {
|
||||||
size_t host_len = strlen(hostname);
|
size_t host_len = strlen(hostname);
|
||||||
|
|
||||||
np = dStrdup(prefs.no_proxy);
|
np = dStrdup(prefs.no_proxy.value().c_str());
|
||||||
for (p = np; (tok = dStrsep(&p, " ")); ) {
|
for (p = np; (tok = dStrsep(&p, " ")); ) {
|
||||||
int start = host_len - strlen(tok);
|
int start = host_len - strlen(tok);
|
||||||
|
|
||||||
|
|||||||
+13
-9
@@ -58,6 +58,8 @@
|
|||||||
#include <openssl/x509v3.h> /* for hostname checking */
|
#include <openssl/x509v3.h> /* for hostname checking */
|
||||||
#include <openssl/crypto.h> /* OpenSSL_version */
|
#include <openssl/crypto.h> /* OpenSSL_version */
|
||||||
|
|
||||||
|
#include <sstream>
|
||||||
|
|
||||||
#define CERT_STATUS_NONE 0
|
#define CERT_STATUS_NONE 0
|
||||||
#define CERT_STATUS_RECEIVING 1
|
#define CERT_STATUS_RECEIVING 1
|
||||||
#define CERT_STATUS_CLEAN 2
|
#define CERT_STATUS_CLEAN 2
|
||||||
@@ -324,26 +326,28 @@ void a_Tls_openssl_init(void)
|
|||||||
*/
|
*/
|
||||||
static int Tls_save_certificate_home(X509 * cert)
|
static int Tls_save_certificate_home(X509 * cert)
|
||||||
{
|
{
|
||||||
char buf[4096];
|
std::string buf;
|
||||||
|
|
||||||
FILE * fp = NULL;
|
FILE * fp = NULL;
|
||||||
uint_t i = 0;
|
uint_t i = 0;
|
||||||
int ret = 1;
|
int ret = 1;
|
||||||
|
|
||||||
/* Attempt to create .flenser/certs blindly - check later */
|
/* Attempt to create .flenser/certs blindly - check later */
|
||||||
snprintf(buf, 4096, "%s/.flenser/", dGethomedir());
|
buf= dGethomedir_string().value() + "/.flenser/";
|
||||||
mkdir(buf, 01777);
|
mkdir(buf.c_str(), 01777);
|
||||||
snprintf(buf, 4096, "%s/.flenser/certs/", dGethomedir());
|
buf= dGethomedir_string().value() + "/.flenser/certs/";
|
||||||
mkdir(buf, 01777);
|
mkdir(buf.c_str(), 01777);
|
||||||
|
|
||||||
do {
|
do {
|
||||||
snprintf(buf, 4096, "%s/.flenser/certs/%lx.%u",
|
std::ostringstream oss;
|
||||||
dGethomedir(), X509_subject_name_hash(cert), i);
|
oss << dGethomedir_string().value() + "/.flenser/certs/" << X509_subject_name_hash( cert ) << '.' << i;
|
||||||
|
buf= oss.str();
|
||||||
|
|
||||||
fp=fopen(buf, "r");
|
|
||||||
|
fp=fopen(buf.c_str(), "r");
|
||||||
if (fp == NULL){
|
if (fp == NULL){
|
||||||
/* File name doesn't exist so we can use it safely */
|
/* File name doesn't exist so we can use it safely */
|
||||||
fp=fopen(buf, "w");
|
fp=fopen(buf.c_str(), "w");
|
||||||
if (fp == NULL){
|
if (fp == NULL){
|
||||||
MSG("Unable to open cert save file in home dir\n");
|
MSG("Unable to open cert save file in home dir\n");
|
||||||
break;
|
break;
|
||||||
|
|||||||
+1
-1
@@ -80,7 +80,7 @@ void a_Dicache_init(void)
|
|||||||
|
|
||||||
if (prefs.ignore_image_formats) {
|
if (prefs.ignore_image_formats) {
|
||||||
for (int i = 0; i < DIC_MAX; i++) {
|
for (int i = 0; i < DIC_MAX; i++) {
|
||||||
if (dStriAsciiStr(prefs.ignore_image_formats, format_name[i])) {
|
if (dStriAsciiStr(prefs.ignore_image_formats.value().c_str(), format_name[i])) {
|
||||||
disabled_formats[i] = 1;
|
disabled_formats[i] = 1;
|
||||||
_MSG("Image format %s disabled\n", format_name[i]);
|
_MSG("Image format %s disabled\n", format_name[i]);
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-4
@@ -407,7 +407,7 @@ int main(int argc, char **argv)
|
|||||||
// Sets WM_CLASS hint on X11
|
// Sets WM_CLASS hint on X11
|
||||||
Fl_Window::default_xclass("flenser");
|
Fl_Window::default_xclass("flenser");
|
||||||
|
|
||||||
Fl::scheme(prefs.theme);
|
Fl::scheme(prefs.theme.c_str());
|
||||||
|
|
||||||
// Disable drag and drop as it crashes on MacOSX
|
// Disable drag and drop as it crashes on MacOSX
|
||||||
Fl::dnd_text_ops(0);
|
Fl::dnd_text_ops(0);
|
||||||
@@ -445,7 +445,7 @@ int main(int argc, char **argv)
|
|||||||
|
|
||||||
/* Proxy authentication */
|
/* Proxy authentication */
|
||||||
if (prefs.http_proxyuser && !a_Http_proxy_auth()) {
|
if (prefs.http_proxyuser && !a_Http_proxy_auth()) {
|
||||||
const char *passwd = a_UIcmd_get_passwd(prefs.http_proxyuser);
|
const char *passwd = a_UIcmd_get_passwd(prefs.http_proxyuser.value().c_str());
|
||||||
if (passwd) {
|
if (passwd) {
|
||||||
a_Http_set_proxy_passwd(passwd);
|
a_Http_set_proxy_passwd(passwd);
|
||||||
} else {
|
} else {
|
||||||
@@ -462,8 +462,8 @@ int main(int argc, char **argv)
|
|||||||
strcmp(URL_PATH(prefs.start_page), "blank") == 0)
|
strcmp(URL_PATH(prefs.start_page), "blank") == 0)
|
||||||
a_UIcmd_open_url(bw, NULL); // NULL URL focuses location
|
a_UIcmd_open_url(bw, NULL); // NULL URL focuses location
|
||||||
else {
|
else {
|
||||||
a_UIcmd_open_url(bw, prefs.start_page);
|
a_UIcmd_open_url(bw, prefs.start_page.get());
|
||||||
a_UIcmd_set_location_text(bw, URL_STR(prefs.start_page));
|
a_UIcmd_set_location_text(bw, URL_STR(prefs.start_page.get()));
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = idx; i < argc; i++) {
|
for (int i = idx; i < argc; i++) {
|
||||||
|
|||||||
+1
-1
@@ -448,7 +448,7 @@ void a_Nav_forw(BrowserWindow *bw)
|
|||||||
*/
|
*/
|
||||||
void a_Nav_home(BrowserWindow *bw)
|
void a_Nav_home(BrowserWindow *bw)
|
||||||
{
|
{
|
||||||
a_Nav_push(bw, prefs.home, NULL);
|
a_Nav_push(bw, prefs.home.get(), NULL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
+9
-24
@@ -62,21 +62,17 @@ void a_Prefs_init(void)
|
|||||||
prefs.xpos = PREFS_GEOMETRY_DEFAULT_XPOS;
|
prefs.xpos = PREFS_GEOMETRY_DEFAULT_XPOS;
|
||||||
prefs.ypos = PREFS_GEOMETRY_DEFAULT_YPOS;
|
prefs.ypos = PREFS_GEOMETRY_DEFAULT_YPOS;
|
||||||
|
|
||||||
prefs.home = a_Url_new(PREFS_HOME, NULL).release();
|
prefs.home = a_Url_new(PREFS_HOME, NULL);
|
||||||
prefs.http_language = NULL;
|
|
||||||
prefs.http_proxy = NULL;
|
|
||||||
prefs.http_max_conns = 6;
|
prefs.http_max_conns = 6;
|
||||||
prefs.http_persistent_conns = TRUE;
|
prefs.http_persistent_conns = TRUE;
|
||||||
prefs.http_proxyuser = NULL;
|
prefs.http_referer = PREFS_HTTP_REFERER;
|
||||||
prefs.http_referer = dStrdup(PREFS_HTTP_REFERER);
|
|
||||||
prefs.http_strict_transport_security = TRUE;
|
prefs.http_strict_transport_security = TRUE;
|
||||||
prefs.http_force_https = FALSE;
|
prefs.http_force_https = FALSE;
|
||||||
prefs.http_user_agent = dStrdup(PREFS_HTTP_USER_AGENT);
|
prefs.http_user_agent = PREFS_HTTP_USER_AGENT;
|
||||||
prefs.limit_text_width = FALSE;
|
prefs.limit_text_width = FALSE;
|
||||||
prefs.adjust_min_width = TRUE;
|
prefs.adjust_min_width = TRUE;
|
||||||
prefs.adjust_table_min_width = TRUE;
|
prefs.adjust_table_min_width = TRUE;
|
||||||
prefs.load_images=TRUE;
|
prefs.load_images=TRUE;
|
||||||
prefs.ignore_image_formats = NULL;
|
|
||||||
prefs.load_background_images=FALSE;
|
prefs.load_background_images=FALSE;
|
||||||
prefs.load_stylesheets=TRUE;
|
prefs.load_stylesheets=TRUE;
|
||||||
prefs.middle_click_drags_page = TRUE;
|
prefs.middle_click_drags_page = TRUE;
|
||||||
@@ -84,11 +80,11 @@ void a_Prefs_init(void)
|
|||||||
prefs.right_click_closes_tab = TRUE;
|
prefs.right_click_closes_tab = TRUE;
|
||||||
prefs.scroll_switches_tabs = TRUE;
|
prefs.scroll_switches_tabs = TRUE;
|
||||||
prefs.scroll_switches_tabs_reverse = FALSE;
|
prefs.scroll_switches_tabs_reverse = FALSE;
|
||||||
prefs.no_proxy = dStrdup(PREFS_NO_PROXY);
|
prefs.no_proxy = PREFS_NO_PROXY;
|
||||||
prefs.link_actions = dList_new(16);
|
prefs.link_actions = dList_new(16);
|
||||||
prefs.panel_size = P_medium;
|
prefs.panel_size = P_medium;
|
||||||
prefs.parse_embedded_css=TRUE;
|
prefs.parse_embedded_css=TRUE;
|
||||||
prefs.save_dir = dStrdup(PREFS_SAVE_DIR);
|
prefs.save_dir = PREFS_SAVE_DIR;
|
||||||
prefs.scroll_step = 100;
|
prefs.scroll_step = 100;
|
||||||
prefs.scroll_page_overlap = 50;
|
prefs.scroll_page_overlap = 50;
|
||||||
prefs.search_urls = dList_new(16);
|
prefs.search_urls = dList_new(16);
|
||||||
@@ -116,9 +112,9 @@ void a_Prefs_init(void)
|
|||||||
prefs.show_tooltip = TRUE;
|
prefs.show_tooltip = TRUE;
|
||||||
prefs.show_ui_tooltip = TRUE;
|
prefs.show_ui_tooltip = TRUE;
|
||||||
prefs.small_icons = FALSE;
|
prefs.small_icons = FALSE;
|
||||||
prefs.start_page = a_Url_new(PREFS_START_PAGE, NULL).release();
|
prefs.start_page = a_Url_new(PREFS_START_PAGE, NULL);
|
||||||
prefs.new_tab_page = a_Url_new(PREFS_NEW_TAB_PAGE, NULL).release();
|
prefs.new_tab_page = a_Url_new(PREFS_NEW_TAB_PAGE, NULL);
|
||||||
prefs.theme = dStrdup(PREFS_THEME);
|
prefs.theme = PREFS_THEME;
|
||||||
prefs.ui_button_highlight_color = -1;
|
prefs.ui_button_highlight_color = -1;
|
||||||
prefs.ui_fg_color = -1;
|
prefs.ui_fg_color = -1;
|
||||||
prefs.ui_main_bg_color = -1;
|
prefs.ui_main_bg_color = -1;
|
||||||
@@ -142,22 +138,11 @@ void a_Prefs_init(void)
|
|||||||
* memory-deallocation.
|
* memory-deallocation.
|
||||||
* (Call this one at exit time)
|
* (Call this one at exit time)
|
||||||
*/
|
*/
|
||||||
void a_Prefs_freeall(void)
|
void a_Prefs_freeall()
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
delete prefs.home;
|
|
||||||
dFree(prefs.http_language);
|
|
||||||
delete prefs.http_proxy;
|
|
||||||
dFree(prefs.http_proxyuser);
|
|
||||||
dFree(prefs.http_referer);
|
|
||||||
dFree(prefs.http_user_agent);
|
|
||||||
dFree(prefs.no_proxy);
|
|
||||||
dFree(prefs.save_dir);
|
|
||||||
for (i = 0; i < dList_length(prefs.search_urls); ++i)
|
for (i = 0; i < dList_length(prefs.search_urls); ++i)
|
||||||
dFree(dList_nth_data(prefs.search_urls, i));
|
dFree(dList_nth_data(prefs.search_urls, i));
|
||||||
dList_free(prefs.search_urls);
|
dList_free(prefs.search_urls);
|
||||||
delete prefs.start_page;
|
|
||||||
delete prefs.new_tab_page;
|
|
||||||
dFree(prefs.theme);
|
|
||||||
}
|
}
|
||||||
|
|||||||
+12
-12
@@ -42,16 +42,16 @@ struct DilloPrefs
|
|||||||
int height;
|
int height;
|
||||||
int xpos;
|
int xpos;
|
||||||
int ypos;
|
int ypos;
|
||||||
char *http_language;
|
std::optional< std::string > http_language;
|
||||||
int32_t http_max_conns;
|
int32_t http_max_conns;
|
||||||
DilloUrl *http_proxy;
|
std::unique_ptr< DilloUrl > http_proxy;
|
||||||
char *http_proxyuser;
|
std::optional< std::string > http_proxyuser;
|
||||||
char *http_referer;
|
std::string http_referer;
|
||||||
char *http_user_agent;
|
std::string http_user_agent;
|
||||||
char *no_proxy;
|
std::optional< std::string > no_proxy;
|
||||||
DilloUrl *start_page;
|
std::unique_ptr< DilloUrl > start_page;
|
||||||
DilloUrl *home;
|
std::unique_ptr< DilloUrl > home;
|
||||||
DilloUrl *new_tab_page;
|
std::unique_ptr< DilloUrl > new_tab_page;
|
||||||
bool allow_white_bg;
|
bool allow_white_bg;
|
||||||
int32_t white_bg_replacement;
|
int32_t white_bg_replacement;
|
||||||
int32_t bg_color;
|
int32_t bg_color;
|
||||||
@@ -68,7 +68,7 @@ struct DilloPrefs
|
|||||||
bool contrast_visited_color;
|
bool contrast_visited_color;
|
||||||
bool show_tooltip;
|
bool show_tooltip;
|
||||||
bool show_ui_tooltip;
|
bool show_ui_tooltip;
|
||||||
char *theme;
|
std::string theme;
|
||||||
int panel_size;
|
int panel_size;
|
||||||
bool small_icons;
|
bool small_icons;
|
||||||
bool limit_text_width;
|
bool limit_text_width;
|
||||||
@@ -100,7 +100,7 @@ struct DilloPrefs
|
|||||||
bool show_quit_dialog;
|
bool show_quit_dialog;
|
||||||
bool fullwindow_start;
|
bool fullwindow_start;
|
||||||
bool load_images;
|
bool load_images;
|
||||||
char *ignore_image_formats;
|
std::optional< std::string > ignore_image_formats;
|
||||||
bool load_background_images;
|
bool load_background_images;
|
||||||
bool load_stylesheets;
|
bool load_stylesheets;
|
||||||
bool parse_embedded_css;
|
bool parse_embedded_css;
|
||||||
@@ -120,7 +120,7 @@ struct DilloPrefs
|
|||||||
bool scroll_switches_tabs_reverse;
|
bool scroll_switches_tabs_reverse;
|
||||||
bool search_url_idx;
|
bool search_url_idx;
|
||||||
Dlist *search_urls;
|
Dlist *search_urls;
|
||||||
char *save_dir;
|
std::optional< std::string > save_dir;
|
||||||
bool show_msg;
|
bool show_msg;
|
||||||
bool show_extra_warnings;
|
bool show_extra_warnings;
|
||||||
bool middle_click_drags_page;
|
bool middle_click_drags_page;
|
||||||
|
|||||||
+9
-11
@@ -810,8 +810,8 @@ void a_UIcmd::a_UIcmd_open_url(BrowserWindow *bw, const DilloUrl *url)
|
|||||||
static void UIcmd_open_url_nbw(BrowserWindow *new_bw, const DilloUrl *url)
|
static void UIcmd_open_url_nbw(BrowserWindow *new_bw, const DilloUrl *url)
|
||||||
{
|
{
|
||||||
if (!url && prefs.new_tab_page) {
|
if (!url && prefs.new_tab_page) {
|
||||||
if (strcmp(URL_STR(prefs.new_tab_page), "about:blank") != 0)
|
if (strcmp(URL_STR(prefs.new_tab_page.get()), "about:blank") != 0)
|
||||||
url = prefs.new_tab_page;
|
url = prefs.new_tab_page.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
/* When opening a new BrowserWindow (tab or real window) we focus
|
/* When opening a new BrowserWindow (tab or real window) we focus
|
||||||
@@ -892,7 +892,7 @@ void a_UIcmd::a_UIcmd_forw_popup(void *vbw, int x, int y)
|
|||||||
*/
|
*/
|
||||||
void a_UIcmd::a_UIcmd_home(void *vbw)
|
void a_UIcmd::a_UIcmd_home(void *vbw)
|
||||||
{
|
{
|
||||||
a_UIcmd_open_url((BrowserWindow*)vbw, prefs.home);
|
a_UIcmd_open_url((BrowserWindow*)vbw, prefs.home.get());
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -1030,17 +1030,15 @@ static char *UIcmd_make_save_filename(const DilloUrl *url)
|
|||||||
/*
|
/*
|
||||||
* Set the default directory for saving files.
|
* Set the default directory for saving files.
|
||||||
*/
|
*/
|
||||||
void a_UIcmd::a_UIcmd_init(void)
|
void a_UIcmd::a_UIcmd_init()
|
||||||
{
|
{
|
||||||
const char *dir = prefs.save_dir;
|
if( not prefs.save_dir.has_value() ) return;
|
||||||
|
|
||||||
if (dir && *dir) {
|
std::string dir= prefs.save_dir.value();
|
||||||
// assert a trailing '/'
|
// assert a trailing '/'
|
||||||
save_dir =
|
if( dir.back() != '/' ) dir+= '/';
|
||||||
(dir[strlen(dir)-1] == '/')
|
|
||||||
? dStrdup(dir)
|
save_dir = dStrdup( dir.c_str() );
|
||||||
: dStrconcat(dir, "/", NULL);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
Reference in New Issue
Block a user