/** * Set option defaults for gtk frontend. * * @param defaults The option table to update. * @return error status. */ static nserror set_defaults(struct nsoption_s *defaults) { char *fname; /* cookie file default */ fname = NULL; netsurf_mkpath(&fname, NULL, 2, nsgtk_config_home, "Cookies"); if (fname != NULL) { nsoption_setnull_charp(cookie_file, fname); } /* cookie jar default */ fname = NULL; netsurf_mkpath(&fname, NULL, 2, nsgtk_config_home, "Cookies"); if (fname != NULL) { nsoption_setnull_charp(cookie_jar, fname); } /* url database default */ fname = NULL; netsurf_mkpath(&fname, NULL, 2, nsgtk_config_home, "URLs"); if (fname != NULL) { nsoption_setnull_charp(url_file, fname); } /* bookmark database default */ fname = NULL; netsurf_mkpath(&fname, NULL, 2, nsgtk_config_home, "Hotlist"); if (fname != NULL) { nsoption_setnull_charp(hotlist_path, fname); } /* download directory default */ fname = getenv("HOME"); if (fname != NULL) { nsoption_setnull_charp(downloads_directory, strdup(fname)); } /* default path to certificates */ nsoption_setnull_charp(ca_path, strdup("/etc/ssl/certs")); if ((nsoption_charp(cookie_file) == NULL) || (nsoption_charp(cookie_jar) == NULL) || (nsoption_charp(url_file) == NULL) || (nsoption_charp(hotlist_path) == NULL) || (nsoption_charp(downloads_directory) == NULL) || (nsoption_charp(ca_path) == NULL)) { LOG("Failed initialising default resource paths"); return NSERROR_BAD_PARAMETER; } /* set default font names */ nsoption_set_charp(font_sans, strdup("Sans")); nsoption_set_charp(font_serif, strdup("Serif")); nsoption_set_charp(font_mono, strdup("Monospace")); nsoption_set_charp(font_cursive, strdup("Serif")); nsoption_set_charp(font_fantasy, strdup("Serif")); return NSERROR_OK; }
static nserror create_cache_home(char **cache_home_out) { char *cache_home = NULL; char *home_dir; char *xdg_cache_dir; nserror ret; LOG("Attempting to create configuration directory"); /* $XDG_CACHE_HOME defines the base directory * relative to which user specific cache files * should be stored. */ xdg_cache_dir = getenv("XDG_CACHE_HOME"); if ((xdg_cache_dir == NULL) || (*xdg_cache_dir == 0)) { home_dir = getenv("HOME"); if ((home_dir == NULL) || (*home_dir == 0)) { return NSERROR_NOT_DIRECTORY; } ret = netsurf_mkpath(&cache_home, NULL, 4, home_dir, ".cache", "netsurf", "/"); if (ret != NSERROR_OK) { return ret; } } else { ret = netsurf_mkpath(&cache_home, NULL, 3, xdg_cache_dir, "netsurf", "/"); if (ret != NSERROR_OK) { return ret; } } /* ensure all elements of path exist (the trailing / is required) */ ret = netsurf_mkdir_all(cache_home); if (ret != NSERROR_OK) { free(cache_home); return ret; } /* strip the trailing separator */ cache_home[strlen(cache_home) - 1] = 0; LOG("\"%s\"", cache_home); *cache_home_out = cache_home; return NSERROR_OK; }
/** * create directory name and check it is acessible and a directory. */ static nserror check_dirname(const char *path, const char *leaf, char **dirname_out) { nserror ret; char *dirname = NULL; struct stat dirname_stat; ret = netsurf_mkpath(&dirname, NULL, 2, path, leaf); if (ret != NSERROR_OK) { return ret; } /* ensure access is possible and the entry is actualy * a directory. */ if (stat(dirname, &dirname_stat) == 0) { if (S_ISDIR(dirname_stat.st_mode)) { if (access(dirname, R_OK | W_OK) == 0) { *dirname_out = dirname; return NSERROR_OK; } else { ret = NSERROR_PERMISSION; } } else { ret = NSERROR_NOT_DIRECTORY; } } else { ret = NSERROR_NOT_FOUND; } free(dirname); return ret; }
static nserror nsgtk_option_init(int *pargc, char** argv) { nserror ret; char *choices = NULL; /* user options setup */ ret = nsoption_init(set_defaults, &nsoptions, &nsoptions_default); if (ret != NSERROR_OK) { return ret; } /* Attempt to load the user choices */ ret = netsurf_mkpath(&choices, NULL, 2, nsgtk_config_home, "Choices"); if (ret == NSERROR_OK) { nsoption_read(choices, nsoptions); free(choices); } /* overide loaded options with those from commandline */ nsoption_commandline(pargc, argv, nsoptions); /* ensure all options fall within sensible bounds */ /* Attempt to handle nonsense status bar widths. These may exist * in people's Choices as the GTK front end used to abuse the * status bar width option by using it for an absolute value in px. * The GTK front end now correctly uses it as a proportion of window * width. Here we assume that a value of less than 15% is wrong * and set to the default two thirds. */ if (nsoption_int(toolbar_status_size) < 1500) { nsoption_set_int(toolbar_status_size, 6667); } return NSERROR_OK; }
static bool save_complete_save_buffer(save_complete_ctx *ctx, const char *leafname, const char *data, size_t data_len, lwc_string *mime_type) { nserror ret; FILE *fp; char *fname = NULL; ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, leafname); if (ret != NSERROR_OK) { guit->misc->warning(messages_get_errorcode(ret), 0); return false; } fp = fopen(fname, "wb"); if (fp == NULL) { free(fname); LOG("fopen(): errno = %i", errno); guit->misc->warning("SaveError", strerror(errno)); return false; } fwrite(data, sizeof(*data), data_len, fp); fclose(fp); if (ctx->set_type != NULL) { ctx->set_type(fname, mime_type); } free(fname); return true; }
static bool save_complete_inventory(save_complete_ctx *ctx) { nserror ret; FILE *fp; char *fname = NULL; save_complete_entry *entry; ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, "Inventory"); if (ret != NSERROR_OK) { return false; } fp = fopen(fname, "w"); free(fname); if (fp == NULL) { LOG("fopen(): errno = %i", errno); guit->misc->warning("SaveError", strerror(errno)); return false; } for (entry = ctx->list; entry != NULL; entry = entry->next) { fprintf(fp, "%p %s\n", entry->content, nsurl_access(hlcache_handle_get_url( entry->content))); } fclose(fp); return true; }
static bool save_complete_save_html_document(save_complete_ctx *ctx, hlcache_handle *c, bool index) { nserror ret; FILE *fp; char *fname = NULL; dom_document *doc; lwc_string *mime_type; char filename[32]; if (index) { snprintf(filename, sizeof filename, "index"); } else { snprintf(filename, sizeof filename, "%p", c); } ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, filename); if (ret != NSERROR_OK) { guit->misc->warning(messages_get_errorcode(ret), NULL); return false; } fp = fopen(fname, "wb"); if (fp == NULL) { free(fname); LOG("fopen(): errno = %i", errno); guit->misc->warning("SaveError", strerror(errno)); return false; } ctx->base = html_get_base_url(c); ctx->fp = fp; ctx->iter_state = STATE_NORMAL; doc = html_get_document(c); if (save_complete_libdom_treewalk((dom_node *) doc, save_complete_node_handler, ctx) == false) { free(fname); guit->misc->warning("NoMemory", 0); fclose(fp); return false; } fclose(fp); mime_type = content_get_mime_type(c); if (mime_type != NULL) { if (ctx->set_type != NULL) ctx->set_type(fname, mime_type); lwc_string_unref(mime_type); } free(fname); return true; }