NetSurf
Data Structures | Typedefs | Enumerations | Functions | Variables
save_complete.c File Reference

Save HTML document with dependencies implementation. More...

#include <assert.h>
#include <errno.h>
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <dom/dom.h>
#include "utils/config.h"
#include "utils/regex.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "utils/utf8.h"
#include "utils/utils.h"
#include "utils/file.h"
#include "utils/messages.h"
#include "utils/ascii.h"
#include "netsurf/content.h"
#include "content/hlcache.h"
#include "css/css.h"
#include "html/box.h"
#include "html/html_save.h"
#include "html/html.h"
#include "netsurf/misc.h"
#include "desktop/gui_internal.h"
#include "desktop/save_complete.h"
Include dependency graph for save_complete.c:

Go to the source code of this file.

Data Structures

struct  save_complete_entry
 An entry in save_complete_list. More...
 
struct  save_complete_ctx
 

Typedefs

typedef struct save_complete_entry save_complete_entry
 An entry in save_complete_list. More...
 
typedef struct save_complete_ctx save_complete_ctx
 

Enumerations

enum  save_complete_event_type { EVENT_ENTER , EVENT_LEAVE }
 

Functions

static nserror save_complete_save_html (save_complete_ctx *ctx, hlcache_handle *c, bool index)
 Save an HTML page with all dependencies, recursing through imported pages. More...
 
static nserror save_complete_save_imported_sheets (save_complete_ctx *ctx, struct nscss_import *imports, uint32_t import_count)
 
static void save_complete_ctx_initialise (save_complete_ctx *ctx, const char *path, save_complete_set_type_cb set_type)
 
static void save_complete_ctx_finalise (save_complete_ctx *ctx)
 
static nserror save_complete_ctx_add_content (save_complete_ctx *ctx, struct hlcache_handle *content)
 
static struct hlcache_handlesave_complete_ctx_find_content (save_complete_ctx *ctx, const nsurl *url)
 find handle to content for url More...
 
static bool save_complete_ctx_has_content (save_complete_ctx *ctx, struct hlcache_handle *content)
 
static nserror save_complete_save_buffer (save_complete_ctx *ctx, const char *leafname, const uint8_t *data, size_t data_len, lwc_string *mime_type)
 
static int snregexec (regex_t *preg, const char *string, size_t stringlen, size_t nmatch, regmatch_t pmatch[], int eflags)
 perform a posix regexec on a string without a null terminator More...
 
static uint8_t * save_complete_rewrite_stylesheet_urls (save_complete_ctx *ctx, const uint8_t *source, size_t size, const nsurl *base, size_t *osize)
 Rewrite stylesheet @import rules for save complete. More...
 
static nserror save_complete_save_stylesheet (save_complete_ctx *ctx, hlcache_handle *css)
 
static nserror save_complete_save_html_stylesheet (save_complete_ctx *ctx, struct html_stylesheet *sheet)
 
static nserror save_complete_save_html_stylesheets (save_complete_ctx *ctx, hlcache_handle *c)
 
static nserror save_complete_save_html_object (save_complete_ctx *ctx, hlcache_handle *obj)
 
static nserror save_complete_save_html_objects (save_complete_ctx *ctx, hlcache_handle *c)
 
static bool save_complete_libdom_treewalk (dom_node *root, bool(*callback)(dom_node *node, save_complete_event_type event_type, void *ctx), void *ctx)
 
static bool save_complete_rewrite_url_value (save_complete_ctx *ctx, const char *value, size_t value_len)
 
static bool save_complete_write_value (save_complete_ctx *ctx, const char *value, size_t value_len)
 
static bool save_complete_handle_attr_value (save_complete_ctx *ctx, dom_string *node_name, dom_string *attr_name, dom_string *attr_value)
 
static bool save_complete_handle_attr (save_complete_ctx *ctx, dom_string *node_name, dom_attr *attr)
 
static bool save_complete_handle_attrs (save_complete_ctx *ctx, dom_string *node_name, dom_namednodemap *attrs)
 
static bool save_complete_handle_element (save_complete_ctx *ctx, dom_node *node, save_complete_event_type event_type)
 
static bool save_complete_node_handler (dom_node *node, save_complete_event_type event_type, void *ctxin)
 
static nserror save_complete_save_html_document (save_complete_ctx *ctx, hlcache_handle *c, bool index)
 
static nserror save_complete_inventory (save_complete_ctx *ctx)
 Create the inventory file listing original URLs. More...
 
static nserror regcomp_wrapper (regex_t *preg, const char *regex, int cflags)
 Compile a regular expression, handling errors. More...
 
void save_complete_init (void)
 Initialise save complete module. More...
 
nserror save_complete_finalise (void)
 Finalise save complete module. More...
 
nserror save_complete (hlcache_handle *c, const char *path, save_complete_set_type_cb set_type)
 Save an HTML page with all dependencies. More...
 

Variables

static regex_t save_complete_import_re
 

Detailed Description

Save HTML document with dependencies implementation.

Definition in file save_complete.c.

Typedef Documentation

◆ save_complete_ctx

◆ save_complete_entry

An entry in save_complete_list.

Enumeration Type Documentation

◆ save_complete_event_type

Enumerator
EVENT_ENTER 
EVENT_LEAVE 

Definition at line 72 of file save_complete.c.

Function Documentation

◆ regcomp_wrapper()

static nserror regcomp_wrapper ( regex_t preg,
const char *  regex,
int  cflags 
)
static

Compile a regular expression, handling errors.

Parameters as for regcomp(), see man regex.

Definition at line 1273 of file save_complete.c.

References NSERROR_INIT_FAILED, NSERROR_OK, NSLOG, regcomp(), and regerror().

Referenced by save_complete_init().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete()

nserror save_complete ( struct hlcache_handle c,
const char *  path,
save_complete_set_type_cb  set_type 
)

Save an HTML page with all dependencies.

Parameters
cCONTENT_HTML to save
pathNative path to directory to save in to (must exist)
set_typeCallback to set type of a file, or NULL
Returns
NSERROR_OK on success else error code

Definition at line 1330 of file save_complete.c.

References NSERROR_OK, path(), result, save_complete_ctx_finalise(), save_complete_ctx_initialise(), save_complete_inventory(), and save_complete_save_html().

Referenced by ami_file_save(), menu_save_page(), ro_gui_save_complete(), and savepage_button_clicked_cb().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_ctx_add_content()

static nserror save_complete_ctx_add_content ( save_complete_ctx ctx,
struct hlcache_handle content 
)
static

Definition at line 103 of file save_complete.c.

References save_complete_entry::content, save_complete_ctx::list, save_complete_entry::next, NSERROR_NOMEM, and NSERROR_OK.

Referenced by save_complete_save_html_object(), and save_complete_save_stylesheet().

Here is the caller graph for this function:

◆ save_complete_ctx_finalise()

static void save_complete_ctx_finalise ( save_complete_ctx ctx)
static

Definition at line 91 of file save_complete.c.

References save_complete_ctx::list, and save_complete_entry::next.

Referenced by save_complete().

Here is the caller graph for this function:

◆ save_complete_ctx_find_content()

static struct hlcache_handle * save_complete_ctx_find_content ( save_complete_ctx ctx,
const nsurl url 
)
static

find handle to content for url

Parameters
ctxThe save context
urlThe url to find content handle for
Returns
The content handle or NULL if not found.

Definition at line 128 of file save_complete.c.

References hlcache_entry::content, hlcache_handle::entry, hlcache_handle_get_url(), save_complete_ctx::list, hlcache_entry::next, nsurl_compare(), and NSURL_COMPLETE.

Referenced by save_complete_rewrite_stylesheet_urls(), save_complete_rewrite_url_value(), save_complete_save_html_object(), and save_complete_save_stylesheet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_ctx_has_content()

static bool save_complete_ctx_has_content ( save_complete_ctx ctx,
struct hlcache_handle content 
)
static

Definition at line 145 of file save_complete.c.

References hlcache_entry::content, hlcache_handle::entry, hlcache_handle_get_content(), save_complete_ctx::list, and hlcache_entry::next.

Referenced by save_complete_save_html().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_ctx_initialise()

static void save_complete_ctx_initialise ( save_complete_ctx ctx,
const char *  path,
save_complete_set_type_cb  set_type 
)
static

Definition at line 83 of file save_complete.c.

References save_complete_ctx::list, save_complete_ctx::path, path(), and save_complete_ctx::set_type.

Referenced by save_complete().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_finalise()

nserror save_complete_finalise ( void  )

Finalise save complete module.

Definition at line 1322 of file save_complete.c.

References NSERROR_OK, regfree(), and save_complete_import_re.

Referenced by nsgtk_finalise().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_handle_attr()

static bool save_complete_handle_attr ( save_complete_ctx ctx,
dom_string *  node_name,
dom_attr *  attr 
)
static

Definition at line 786 of file save_complete.c.

References save_complete_ctx::fp, node_name(), and save_complete_handle_attr_value().

Referenced by save_complete_handle_attrs().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_handle_attr_value()

static bool save_complete_handle_attr_value ( save_complete_ctx ctx,
dom_string *  node_name,
dom_string *  attr_name,
dom_string *  attr_value 
)
static

We only need to consider the following cases:

Attribute: Elements:

1) data object 2) href a, area, link 3) src script, input, frame, iframe, img 4) background any (except those above)

Definition at line 697 of file save_complete.c.

References node_name(), save_complete_rewrite_url_value(), save_complete_write_value(), and SLEN.

Referenced by save_complete_handle_attr().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_handle_attrs()

static bool save_complete_handle_attrs ( save_complete_ctx ctx,
dom_string *  node_name,
dom_namednodemap *  attrs 
)
static

Definition at line 832 of file save_complete.c.

References node_name(), and save_complete_handle_attr().

Referenced by save_complete_handle_element().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_handle_element()

static bool save_complete_handle_element ( save_complete_ctx ctx,
dom_node *  node,
save_complete_event_type  event_type 
)
static

Definition at line 865 of file save_complete.c.

References save_complete_ctx::base, content_html_object::content, EVENT_ENTER, EVENT_LEAVE, save_complete_ctx::fp, save_complete_ctx::iter_state, save_complete_handle_attrs(), save_complete_rewrite_stylesheet_urls(), and SLEN.

Referenced by save_complete_node_handler().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_init()

void save_complete_init ( void  )

Initialise save complete module.

Definition at line 1289 of file save_complete.c.

References REG_EXTENDED, REG_ICASE, regcomp_wrapper(), and save_complete_import_re.

Referenced by gui_init(), main(), menu_save_page(), and nsgtk_setup().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_inventory()

static nserror save_complete_inventory ( save_complete_ctx ctx)
static

Create the inventory file listing original URLs.

Definition at line 1237 of file save_complete.c.

References save_complete_entry::content, hlcache_handle_get_url(), save_complete_ctx::list, netsurf_mkpath(), save_complete_entry::next, NSERROR_OK, NSERROR_SAVE_FAILED, NSLOG, nsurl_access(), and save_complete_ctx::path.

Referenced by save_complete().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_libdom_treewalk()

static bool save_complete_libdom_treewalk ( dom_node *  root,
bool(*)(dom_node *node, save_complete_event_type event_type, void *ctx)  callback,
void *  ctx 
)
static

Definition at line 540 of file save_complete.c.

References EVENT_ENTER, EVENT_LEAVE, content_html_object::next, and root.

Referenced by save_complete_save_html_document().

Here is the caller graph for this function:

◆ save_complete_node_handler()

static bool save_complete_node_handler ( dom_node *  node,
save_complete_event_type  event_type,
void *  ctxin 
)
static

Definition at line 1017 of file save_complete.c.

References EVENT_ENTER, save_complete_ctx::fp, save_complete_ctx::iter_state, NSERROR_OK, NSLOG, save_complete_handle_element(), text(), type, and utf8_to_html().

Referenced by save_complete_save_html_document().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_rewrite_stylesheet_urls()

static uint8_t * save_complete_rewrite_stylesheet_urls ( save_complete_ctx ctx,
const uint8_t *  source,
size_t  size,
const nsurl base,
size_t *  osize 
)
static

Rewrite stylesheet @import rules for save complete.

Parameters
ctxSave complete context.
sourcestylesheet source.
sizesize of source.
baseurl of stylesheet.
osizeupdated with the size of the result.
Returns
converted source, or NULL on out of memory.

Definition at line 234 of file save_complete.c.

References ascii_to_lower(), base, NSERROR_NOMEM, nsurl_join(), nsurl_unref(), regmatch_t::rm_eo, regmatch_t::rm_so, save_complete_ctx_find_content(), save_complete_import_re, SLEN, snregexec(), and strndup().

Referenced by save_complete_handle_element(), and save_complete_save_stylesheet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_rewrite_url_value()

static bool save_complete_rewrite_url_value ( save_complete_ctx ctx,
const char *  value,
size_t  value_len 
)
static

Definition at line 635 of file save_complete.c.

References save_complete_ctx::base, content_html_object::content, save_complete_ctx::fp, NSERROR_NOMEM, NSERROR_OK, nsurl_access(), nsurl_join(), nsurl_length(), nsurl_unref(), save_complete_ctx_find_content(), and utf8_to_html().

Referenced by save_complete_handle_attr_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_buffer()

static nserror save_complete_save_buffer ( save_complete_ctx ctx,
const char *  leafname,
const uint8_t *  data,
size_t  data_len,
lwc_string *  mime_type 
)
static

Definition at line 160 of file save_complete.c.

References netsurf_mkpath(), NSERROR_OK, NSERROR_SAVE_FAILED, NSLOG, save_complete_ctx::path, and save_complete_ctx::set_type.

Referenced by save_complete_save_html_object(), and save_complete_save_stylesheet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_html()

static nserror save_complete_save_html ( save_complete_ctx ctx,
hlcache_handle c,
bool  index 
)
static

Save an HTML page with all dependencies, recursing through imported pages.

Parameters
ctxSave complete context
cContent to save
indextrue to save as "index"
Returns
true on success, false on error and error reported

Definition at line 1205 of file save_complete.c.

References content_get_type(), CONTENT_HTML, NSERROR_INVALID, NSERROR_OK, save_complete_ctx_has_content(), save_complete_save_html_document(), save_complete_save_html_objects(), and save_complete_save_html_stylesheets().

Referenced by save_complete(), and save_complete_save_html_object().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_html_document()

static nserror save_complete_save_html_document ( save_complete_ctx ctx,
hlcache_handle c,
bool  index 
)
static

Definition at line 1138 of file save_complete.c.

References save_complete_ctx::base, content_get_mime_type(), save_complete_ctx::fp, html_get_base_url(), html_get_document(), save_complete_ctx::iter_state, netsurf_mkpath(), NSERROR_NOMEM, NSERROR_OK, NSERROR_SAVE_FAILED, NSLOG, save_complete_ctx::path, save_complete_libdom_treewalk(), save_complete_node_handler(), and save_complete_ctx::set_type.

Referenced by save_complete_save_html().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_html_object()

static nserror save_complete_save_html_object ( save_complete_ctx ctx,
hlcache_handle obj 
)
static

Definition at line 471 of file save_complete.c.

References content_get_mime_type(), content_get_source_data(), content_get_type(), CONTENT_HTML, CONTENT_NONE, hlcache_handle_get_url(), NSERROR_NOMEM, NSERROR_OK, result, save_complete_ctx_add_content(), save_complete_ctx_find_content(), save_complete_save_buffer(), save_complete_save_html(), and type.

Referenced by save_complete_save_html_objects().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_html_objects()

static nserror save_complete_save_html_objects ( save_complete_ctx ctx,
hlcache_handle c 
)
static

Definition at line 517 of file save_complete.c.

References content_html_object::box, content_html_object::content, count(), html_get_objects(), NSERROR_OK, and save_complete_save_html_object().

Referenced by save_complete_save_html().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_html_stylesheet()

static nserror save_complete_save_html_stylesheet ( save_complete_ctx ctx,
struct html_stylesheet sheet 
)
static

Definition at line 440 of file save_complete.c.

References NSERROR_OK, save_complete_save_stylesheet(), and html_stylesheet::sheet.

Referenced by save_complete_save_html_stylesheets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_html_stylesheets()

static nserror save_complete_save_html_stylesheets ( save_complete_ctx ctx,
hlcache_handle c 
)
static

Definition at line 451 of file save_complete.c.

References count(), html_get_stylesheets(), NSERROR_OK, save_complete_save_html_stylesheet(), and STYLESHEET_START.

Referenced by save_complete_save_html().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_imported_sheets()

static nserror save_complete_save_imported_sheets ( save_complete_ctx ctx,
struct nscss_import imports,
uint32_t  import_count 
)
static

Definition at line 419 of file save_complete.c.

References nscss_import::c, NSERROR_OK, and save_complete_save_stylesheet().

Referenced by save_complete_save_stylesheet().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_save_stylesheet()

static nserror save_complete_save_stylesheet ( save_complete_ctx ctx,
hlcache_handle css 
)
static

Definition at line 360 of file save_complete.c.

References content_get_mime_type(), content_get_source_data(), hlcache_handle_get_url(), nscss_get_imports(), NSERROR_NOMEM, NSERROR_OK, result, save_complete_ctx_add_content(), save_complete_ctx_find_content(), save_complete_rewrite_stylesheet_urls(), save_complete_save_buffer(), save_complete_save_imported_sheets(), and type.

Referenced by save_complete_save_html_stylesheet(), and save_complete_save_imported_sheets().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ save_complete_write_value()

static bool save_complete_write_value ( save_complete_ctx ctx,
const char *  value,
size_t  value_len 
)
static

Definition at line 680 of file save_complete.c.

References save_complete_ctx::fp, NSERROR_OK, and utf8_to_html().

Referenced by save_complete_handle_attr_value().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ snregexec()

static int snregexec ( regex_t preg,
const char *  string,
size_t  stringlen,
size_t  nmatch,
regmatch_t  pmatch[],
int  eflags 
)
static

perform a posix regexec on a string without a null terminator

Definition at line 199 of file save_complete.c.

References regexec().

Referenced by save_complete_rewrite_stylesheet_urls().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ save_complete_import_re

regex_t save_complete_import_re
static