From 6879c02a332824ff63ce0b56de36996d2f0d48cf Mon Sep 17 00:00:00 2001 From: James Bursa Date: Sun, 6 Jun 2004 19:39:17 +0000 Subject: [project @ 2004-06-06 19:39:17 by bursa] Add and improve error handling of save_complete. Save HTML as UTF-8 to prevent encoding issues. svn path=/import/netsurf/; revision=931 --- riscos/save_complete.c | 522 +++++++++++++++++++++++++++++-------------------- 1 file changed, 306 insertions(+), 216 deletions(-) (limited to 'riscos/save_complete.c') diff --git a/riscos/save_complete.c b/riscos/save_complete.c index bdf8682db..4ad1668b6 100644 --- a/riscos/save_complete.c +++ b/riscos/save_complete.c @@ -12,6 +12,7 @@ #include #include +#include #include #include #include @@ -33,24 +34,24 @@ regex_t save_complete_import_re; /** An entry in save_complete_list. */ struct save_complete_entry { - char *url; /**< Fully qualified URL, as per url_join output */ - int ptr; /**< Pointer to object's location in memory */ - struct save_complete_entry *next; /**< Next entry in list */ + struct content *content; + struct save_complete_entry *next; /**< Next entry in list */ }; /** List of urls seen and saved so far. */ -static struct save_complete_entry *save_complete_list; +static struct save_complete_entry *save_complete_list = 0; -static void save_complete_html(struct content *c, const char *path, - bool index); -static void save_imported_sheets(struct content *c, const char *path); +static bool save_complete_html(struct content *c, const char *path, + bool index); +static bool save_imported_sheets(struct content *c, const char *path); static char * rewrite_stylesheet_urls(const char *source, unsigned int size, int *osize, const char *base); -static int rewrite_document_urls(xmlDoc *doc, const char *base); -static int rewrite_urls(xmlNode *n, const char *base); -static void rewrite_url(xmlNode *n, const char *attr, const char *base); -static void save_complete_add_url(const char *url, int id); -static int save_complete_find_url(const char *url); +static bool rewrite_document_urls(xmlDoc *doc, const char *base); +static bool rewrite_urls(xmlNode *n, const char *base); +static bool rewrite_url(xmlNode *n, const char *attr, const char *base); +static bool save_complete_list_add(struct content *content); +static struct content * save_complete_list_find(const char *url); +static bool save_complete_list_check(struct content *content); /** @@ -58,64 +59,89 @@ static int save_complete_find_url(const char *url); * * \param c CONTENT_HTML to save * \param path directory to save to (must exist) + * \return true on success, false on error and error reported */ -void save_complete(struct content *c, const char *path) +bool save_complete(struct content *c, const char *path) { - save_complete_list = 0; + bool result; - save_complete_html(c, path, true); + result = save_complete_html(c, path, true); - /* free save_complete_list */ + /* free save_complete_list */ while (save_complete_list) { struct save_complete_entry *next = save_complete_list->next; - free(save_complete_list->url); free(save_complete_list); save_complete_list = next; } + + return result; } + /** * Save an HTML page with all dependencies, recursing through imported pages. * - * \param c CONTENT_HTML to save - * \param path directory to save to (must exist) + * \param c CONTENT_HTML to save + * \param path directory to save to (must exist) + * \param index true to save as "index" + * \return true on success, false on error and error reported */ -void save_complete_html(struct content *c, const char *path, bool index) +bool save_complete_html(struct content *c, const char *path, bool index) { char spath[256]; unsigned int i; - htmlParserCtxtPtr toSave; + htmlParserCtxtPtr parser; + os_error *error; if (c->type != CONTENT_HTML) - return; + return false; + + if (save_complete_list_check(c)) + return true; - /* save stylesheets, ignoring the base sheet */ - for (i = 1; i != c->data.html.stylesheet_count; i++) { + /* save stylesheets, ignoring the base sheet */ + for (i = 1; i != c->data.html.stylesheet_count; i++) { struct content *css = c->data.html.stylesheet_content[i]; char *source; int source_len; - if (!css) - continue; + if (!css) + continue; + if (save_complete_list_check(css)) + continue; - save_complete_add_url(css->url, (int) css); + if (!save_complete_list_add(css)) { + warn_user("NoMemory", 0); + return false; + } - save_imported_sheets(css, path); + if (!save_imported_sheets(css, path)) + return false; - if (i == 1) continue; /* don't save