void a_Prefs_init(void) { gchar *old_locale; prefs.width = D_GEOMETRY_DEFAULT_WIDTH; prefs.height = D_GEOMETRY_DEFAULT_HEIGHT; prefs.xpos = D_GEOMETRY_DEFAULT_XPOS; prefs.ypos = D_GEOMETRY_DEFAULT_YPOS; prefs.http_proxy = NULL; prefs.http_proxyuser = NULL; prefs.no_proxy = NULL; prefs.no_proxy_vec = NULL; prefs.link_color = DW_COLOR_DEFAULT_BLUE; prefs.visited_color = DW_COLOR_DEFAULT_PURPLE; prefs.bg_color = DW_COLOR_DEFAULT_BGND; prefs.text_color = DW_COLOR_DEFAULT_BLACK; prefs.use_oblique = FALSE; prefs.start_page = a_Url_new(DILLO_START_PAGE, NULL, 0, 0, 0); prefs.home = a_Url_new(DILLO_HOME, NULL, 0, 0, 0); prefs.allow_white_bg = TRUE; prefs.force_my_colors = FALSE; prefs.contrast_visited_color = FALSE; prefs.show_tooltip = FALSE; prefs.panel_size = 1; prefs.small_icons = FALSE; prefs.limit_text_width = FALSE; prefs.w3c_plus_heuristics = TRUE; prefs.font_factor = 1.0; prefs.use_dicache = FALSE; prefs.show_back=TRUE; prefs.show_forw=TRUE; prefs.show_home=TRUE; prefs.show_reload=TRUE; prefs.show_save=TRUE; prefs.show_stop=TRUE; prefs.show_bookmarks=TRUE; prefs.show_menubar=TRUE; prefs.show_clear_url=TRUE; prefs.show_url=TRUE; prefs.show_search=TRUE; prefs.show_progress_box=TRUE; prefs.fullwindow_start=FALSE; prefs.transient_dialogs=FALSE; prefs.vw_fontname = g_strdup("helvetica"); prefs.fw_fontname = g_strdup("courier"); prefs.generate_submit = FALSE; prefs.enterpress_forces_submit = FALSE; prefs.search_url = g_strdup("http://www.google.com/search?q=%s"); prefs.show_msg = TRUE; prefs.show_extra_warnings = FALSE; /* this locale stuff is to avoid parsing problems with float numbers */ old_locale = g_strdup (setlocale (LC_NUMERIC, NULL)); setlocale (LC_NUMERIC, "C"); Prefs_load(); setlocale (LC_NUMERIC, old_locale); g_free (old_locale); }
/* * Initialize dicache data */ void a_Cache_init(void) { ClientQueue = dList_new(32); DelayedQueue = dList_new(32); CachedURLs = dList_new(256); /* inject the splash screen in the cache */ { DilloUrl *url = a_Url_new("about:splash", NULL); Dstr *ds = dStr_new(AboutSplash); Cache_entry_inject(url, ds); dStr_free(ds, 1); a_Url_free(url); } }
/* * Process redirections (HTTP 30x answers) * (This is a work in progress --not finished yet) */ static int Cache_redirect(CacheEntry_t *entry, int Flags, BrowserWindow *bw) { DilloUrl *NewUrl; _MSG(" Cache_redirect: redirect_level = %d\n", bw->redirect_level); /* Don't allow redirection for SpamSafe/local URLs */ if (URL_FLAGS(entry->Url) & URL_SpamSafe) { a_UIcmd_set_msg(bw, "WARNING: local URL with redirection. Aborting."); return 0; } /* if there's a redirect loop, stop now */ if (bw->redirect_level >= 5) entry->Flags |= CA_RedirectLoop; if (entry->Flags & CA_RedirectLoop) { a_UIcmd_set_msg(bw, "ERROR: redirect loop for: %s", URL_STR_(entry->Url)); bw->redirect_level = 0; return 0; } if ((entry->Flags & CA_Redirect && entry->Location) && (entry->Flags & CA_ForceRedirect || entry->Flags & CA_TempRedirect || !entry->Data->len || entry->Data->len < 1024)) { _MSG(">>>> Redirect from: %s\n to %s <<<<\n", URL_STR_(entry->Url), URL_STR_(entry->Location)); _MSG("%s", entry->Header->str); if (Flags & WEB_RootUrl) { /* Redirection of the main page */ NewUrl = a_Url_new(URL_STR_(entry->Location), URL_STR_(entry->Url)); if (entry->Flags & CA_TempRedirect) a_Url_set_flags(NewUrl, URL_FLAGS(NewUrl) | URL_E2EQuery); a_Nav_push(bw, NewUrl, entry->Url); a_Url_free(NewUrl); } else { /* Sub entity redirection (most probably an image) */ if (!entry->Data->len) { _MSG(">>>> Image redirection without entity-content <<<<\n"); } else { _MSG(">>>> Image redirection with entity-content <<<<\n"); } } } return 0; }
/* * Initialize proxy vars and Accept-Language header */ int a_Http_init(void) { char *env_proxy = getenv("http_proxy"); HTTP_Language_hdr = prefs.http_language ? dStrconcat("Accept-Language: ", prefs.http_language, "\r\n", NULL) : dStrdup(""); if (env_proxy && strlen(env_proxy)) HTTP_Proxy = a_Url_new(env_proxy, NULL); if (!HTTP_Proxy && prefs.http_proxy) HTTP_Proxy = a_Url_dup(prefs.http_proxy); /* This allows for storing the proxy password in "user:passwd" format * in dillorc, but as this constitutes a security problem, it was disabled. * if (HTTP_Proxy && prefs.http_proxyuser && strchr(prefs.http_proxyuser, ':')) HTTP_Proxy_Auth_base64 = a_Misc_encode_base64(prefs.http_proxyuser); */ host_connections = dList_new(5); return 0; }
/* * Read tokens from dillorc and set values in the prefs structure. * (Although this function can be called several times, and not leak, * preferences aren't yet enabled for on-the-fly changes). */ static guint Prefs_parser(GScanner *scanner) { gint st; guint symbol; /* expect a valid symbol */ g_scanner_get_next_token(scanner); symbol = scanner->token; if (scanner->token == G_TOKEN_EQUAL_SIGN) { g_scanner_get_next_token (scanner); return G_TOKEN_NONE; } else if (symbol < DRC_TOKEN_FIRST || symbol > DRC_TOKEN_LAST ) return G_TOKEN_SYMBOL; /* expect '=' */ g_scanner_get_next_token(scanner); if (scanner->token != G_TOKEN_EQUAL_SIGN) return G_TOKEN_EQUAL_SIGN; /* expect a string */ g_scanner_get_next_token(scanner); if (scanner->token != G_TOKEN_STRING) return G_TOKEN_STRING; /* assign value and exit successfully */ switch (symbol) { case DRC_TOKEN_GEOMETRY: a_Misc_parse_geometry(scanner->value.v_string, &prefs.xpos, &prefs.ypos, &prefs.width, &prefs.height); break; case DRC_TOKEN_PROXY: a_Url_free(prefs.http_proxy); prefs.http_proxy = a_Url_new(scanner->value.v_string, NULL, 0, 0, 0); break; case DRC_TOKEN_PROXYUSER: g_free(prefs.http_proxyuser); prefs.http_proxyuser = g_strdup(scanner->value.v_string); break; case DRC_TOKEN_NOPROXY: g_free(prefs.no_proxy); prefs.no_proxy = g_strdup(scanner->value.v_string); prefs.no_proxy_vec = g_strsplit(prefs.no_proxy, " ", 0); break; case DRC_TOKEN_LINK_COLOR: prefs.link_color = a_Color_parse(scanner->value.v_string, prefs.link_color, &st); break; case DRC_TOKEN_VISITED_COLOR: prefs.visited_color = a_Color_parse(scanner->value.v_string, prefs.visited_color, &st); break; case DRC_TOKEN_TEXT_COLOR: prefs.text_color = a_Color_parse(scanner->value.v_string, prefs.text_color, &st); break; case DRC_TOKEN_BG_COLOR: prefs.bg_color = a_Color_parse(scanner->value.v_string, prefs.bg_color, &st); break; case DRC_TOKEN_ALLOW_WHITE_BG: prefs.allow_white_bg = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_FORCE_MY_COLORS: prefs.force_my_colors = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_CONTRAST_VISITED_COLOR: prefs.contrast_visited_color = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_USE_OBLIQUE: prefs.use_oblique = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_PANEL_SIZE: if (!g_strcasecmp(scanner->value.v_string, "tiny")) prefs.panel_size = 1; else if (!g_strcasecmp(scanner->value.v_string, "small")) prefs.panel_size = 2; else if (!g_strcasecmp(scanner->value.v_string, "medium")) prefs.panel_size = 3; else /* default to "large" */ prefs.panel_size = 4; break; case DRC_TOKEN_SMALL_ICONS: prefs.small_icons = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_START_PAGE: a_Url_free(prefs.start_page); prefs.start_page = a_Url_new(scanner->value.v_string, NULL, 0, 0, 0); break; case DRC_TOKEN_HOME: a_Url_free(prefs.home); prefs.home = a_Url_new(scanner->value.v_string, NULL, 0, 0, 0); break; case DRC_TOKEN_SHOW_TOOLTIP: prefs.show_tooltip = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_FONT_FACTOR: prefs.font_factor = strtod(scanner->value.v_string, NULL); break; case DRC_TOKEN_LIMIT_TEXT_WIDTH: prefs.limit_text_width = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_W3C_PLUS_HEURISTICS: prefs.w3c_plus_heuristics = (strcmp(scanner->value.v_string,"YES") == 0); break; case DRC_TOKEN_USE_DICACHE: prefs.use_dicache = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_BACK: prefs.show_back = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_FORW: prefs.show_forw = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_HOME: prefs.show_home = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_RELOAD: prefs.show_reload = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_SAVE: prefs.show_save = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_STOP: prefs.show_stop = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_BOOKMARKS: prefs.show_bookmarks = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_MENUBAR: prefs.show_menubar = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_CLEAR_URL: prefs.show_clear_url = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_URL: prefs.show_url = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_SEARCH: prefs.show_search = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_PROGRESS_BOX: prefs.show_progress_box = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_FULLWINDOW_START: prefs.fullwindow_start = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_TRANSIENT_DIALOGS: prefs.transient_dialogs = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_FW_FONT: g_free(prefs.fw_fontname); prefs.fw_fontname = g_strdup(scanner->value.v_string); break; case DRC_TOKEN_VW_FONT: g_free(prefs.vw_fontname); prefs.vw_fontname = g_strdup(scanner->value.v_string); break; case DRC_TOKEN_GENERATE_SUBMIT: prefs.generate_submit = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_ENTERPRESS_FORCES_SUBMIT: prefs.enterpress_forces_submit = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SEARCH_URL: g_free(prefs.search_url); prefs.search_url = g_strdup(scanner->value.v_string); break; case DRC_TOKEN_SHOW_MSG: prefs.show_msg = (strcmp(scanner->value.v_string, "YES") == 0); break; case DRC_TOKEN_SHOW_EXTRA_WARNINGS: prefs.show_extra_warnings = (strcmp(scanner->value.v_string, "YES") == 0); break; default: break; /* Not reached */ } return G_TOKEN_NONE; }
/* * Scan, allocate, and set things according to header info. * (This function needs the whole header to work) */ static void Cache_parse_header(CacheEntry_t *entry) { char *header = entry->Header->str; char *Length, *Type, *location_str, *encoding; #ifndef DISABLE_COOKIES Dlist *Cookies; #endif Dlist *warnings; void *data; int i; _MSG("Cache_parse_header\n"); if (entry->Header->len > 12) { if (header[9] == '1' && header[10] == '0' && header[11] == '0') { /* 100: Continue. The "real" header has not come yet. */ MSG("An actual 100 Continue header!\n"); entry->Flags &= ~CA_GotHeader; dStr_free(entry->Header, 1); entry->Header = dStr_new(""); return; } if (header[9] == '3' && header[10] == '0' && (location_str = Cache_parse_field(header, "Location"))) { /* 30x: URL redirection */ DilloUrl *location_url = a_Url_new(location_str,URL_STR_(entry->Url)); if (prefs.filter_auto_requests == PREFS_FILTER_SAME_DOMAIN && !a_Url_same_organization(entry->Url, location_url)) { /* don't redirect; just show body like usual (if any) */ MSG("Redirection not followed from %s to %s\n", URL_HOST(entry->Url), URL_STR(location_url)); a_Url_free(location_url); } else { entry->Flags |= CA_Redirect; if (header[11] == '1') entry->Flags |= CA_ForceRedirect; /* 301 Moved Permanently */ else if (header[11] == '2') entry->Flags |= CA_TempRedirect; /* 302 Temporary Redirect */ if (URL_FLAGS(location_url) & (URL_Post + URL_Get) && dStrAsciiCasecmp(URL_SCHEME(location_url), "dpi") == 0 && dStrAsciiCasecmp(URL_SCHEME(entry->Url), "dpi") != 0) { /* Forbid dpi GET and POST from non dpi-generated urls */ MSG("Redirection Denied! '%s' -> '%s'\n", URL_STR(entry->Url), URL_STR(location_url)); a_Url_free(location_url); } else { entry->Location = location_url; } } dFree(location_str); } else if (strncmp(header + 9, "401", 3) == 0) { entry->Auth = Cache_parse_multiple_fields(header, "WWW-Authenticate"); } else if (strncmp(header + 9, "404", 3) == 0) { entry->Flags |= CA_NotFound; } } if ((warnings = Cache_parse_multiple_fields(header, "Warning"))) { for (i = 0; (data = dList_nth_data(warnings, i)); ++i) { MSG_HTTP("%s\n", (char *)data); dFree(data); } dList_free(warnings); } /* * Get Transfer-Encoding and initialize decoder */ encoding = Cache_parse_field(header, "Transfer-Encoding"); entry->TransferDecoder = a_Decode_transfer_init(encoding); if ((Length = Cache_parse_field(header, "Content-Length")) != NULL) { if (encoding) { /* * If Transfer-Encoding is present, Content-Length must be ignored. * If the Transfer-Encoding is non-identity, it is an error. */ if (dStrAsciiCasecmp(encoding, "identity")) MSG_HTTP("Content-Length and non-identity Transfer-Encoding " "headers both present.\n"); } else { entry->Flags |= CA_GotLength; entry->ExpectedSize = MAX(strtol(Length, NULL, 10), 0); } dFree(Length); } dFree(encoding); /* free Transfer-Encoding */ #ifndef DISABLE_COOKIES if ((Cookies = Cache_parse_multiple_fields(header, "Set-Cookie"))) { CacheClient_t *client; for (i = 0; (client = dList_nth_data(ClientQueue, i)); ++i) { if (client->Url == entry->Url) { DilloWeb *web = client->Web; if (!web->requester || a_Url_same_organization(entry->Url, web->requester)) { char *server_date = Cache_parse_field(header, "Date"); a_Cookies_set(Cookies, entry->Url, server_date); dFree(server_date); break; } } } if (i >= dList_length(ClientQueue)) { MSG("Cache: cookies not accepted from '%s'\n", URL_STR(entry->Url)); } for (i = 0; (data = dList_nth_data(Cookies, i)); ++i) dFree(data); dList_free(Cookies); } #endif /* !DISABLE_COOKIES */ /* * Get Content-Encoding and initialize decoder */ encoding = Cache_parse_field(header, "Content-Encoding"); entry->ContentDecoder = a_Decode_content_init(encoding); dFree(encoding); if (entry->ExpectedSize > 0) { if (entry->ExpectedSize > HUGE_FILESIZE) { entry->Flags |= CA_HugeFile; } /* Avoid some reallocs. With MAX_INIT_BUF we avoid a SEGFAULT * with huge files (e.g. iso files). * Note: the buffer grows automatically. */ dStr_free(entry->Data, 1); entry->Data = dStr_sized_new(MIN(entry->ExpectedSize, MAX_INIT_BUF)); } /* Get Content-Type */ if ((Type = Cache_parse_field(header, "Content-Type"))) { /* This HTTP Content-Type is not trusted. It's checked against real data * in Cache_process_queue(); only then CA_GotContentType becomes true. */ a_Cache_set_content_type(entry->Url, Type, "http"); _MSG("TypeHdr {%s} {%s}\n", Type, URL_STR(entry->Url)); _MSG("TypeMeta {%s}\n", entry->TypeMeta); dFree(Type); } Cache_ref_data(entry); }