2010-04-25 01:16:12 +04:00
|
|
|
/*
|
2012-11-04 03:19:28 +04:00
|
|
|
* Copyright 2012 John-Mark Bell <jmb@netsurf-browser.org>
|
2007-07-05 08:29:09 +04:00
|
|
|
* Copyright 2004-2007 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2004-03-27 21:44:26 +03:00
|
|
|
*/
|
|
|
|
|
2016-06-06 10:59:23 +03:00
|
|
|
/**
|
|
|
|
* \file
|
|
|
|
* Save HTML document with dependencies implementation.
|
2004-02-17 15:41:38 +03:00
|
|
|
*/
|
|
|
|
|
2004-03-24 03:07:21 +03:00
|
|
|
#include <assert.h>
|
2004-06-06 23:39:17 +04:00
|
|
|
#include <errno.h>
|
2007-07-05 08:29:09 +04:00
|
|
|
#include <stdio.h>
|
2004-02-17 15:41:38 +03:00
|
|
|
#include <string.h>
|
2014-12-28 01:48:37 +03:00
|
|
|
#include <strings.h>
|
2004-03-27 21:44:26 +03:00
|
|
|
#include <sys/types.h>
|
|
|
|
#include <regex.h>
|
2012-03-25 00:55:22 +04:00
|
|
|
#include <dom/dom.h>
|
2012-11-04 03:19:28 +04:00
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
#include "utils/config.h"
|
2012-12-31 03:33:27 +04:00
|
|
|
#include "utils/corestrings.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
2012-11-04 03:19:28 +04:00
|
|
|
#include "utils/nsurl.h"
|
2012-12-31 03:33:27 +04:00
|
|
|
#include "utils/utf8.h"
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/utils.h"
|
2014-05-07 19:14:18 +04:00
|
|
|
#include "utils/file.h"
|
2014-05-18 02:14:43 +04:00
|
|
|
#include "utils/messages.h"
|
2016-09-11 12:27:11 +03:00
|
|
|
#include "utils/ascii.h"
|
2016-06-06 10:59:23 +03:00
|
|
|
#include "netsurf/content.h"
|
2014-05-07 19:14:18 +04:00
|
|
|
#include "content/hlcache.h"
|
2016-06-06 16:47:27 +03:00
|
|
|
#include "css/css.h"
|
2018-05-10 13:34:26 +03:00
|
|
|
#include "html/box.h"
|
2018-05-11 15:15:17 +03:00
|
|
|
#include "html/html_save.h"
|
2018-05-10 13:34:26 +03:00
|
|
|
#include "html/html.h"
|
2014-05-07 19:14:18 +04:00
|
|
|
|
2016-05-30 13:23:32 +03:00
|
|
|
#include "netsurf/misc.h"
|
2016-04-26 14:50:16 +03:00
|
|
|
#include "desktop/gui_internal.h"
|
2014-05-07 19:14:18 +04:00
|
|
|
#include "desktop/save_complete.h"
|
2004-02-17 15:41:38 +03:00
|
|
|
|
2004-03-27 21:44:26 +03:00
|
|
|
regex_t save_complete_import_re;
|
|
|
|
|
|
|
|
/** An entry in save_complete_list. */
|
2012-11-04 03:19:28 +04:00
|
|
|
typedef struct save_complete_entry {
|
2016-06-06 10:59:23 +03:00
|
|
|
struct hlcache_handle *content;
|
2004-06-06 23:39:17 +04:00
|
|
|
struct save_complete_entry *next; /**< Next entry in list */
|
2012-11-04 03:19:28 +04:00
|
|
|
} save_complete_entry;
|
2004-02-17 15:41:38 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
typedef struct save_complete_ctx {
|
|
|
|
const char *path;
|
|
|
|
save_complete_entry *list;
|
|
|
|
save_complete_set_type_cb set_type;
|
2004-04-06 02:36:48 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
nsurl *base;
|
|
|
|
FILE *fp;
|
|
|
|
enum { STATE_NORMAL, STATE_IN_STYLE } iter_state;
|
|
|
|
} save_complete_ctx;
|
2007-07-05 08:29:09 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
typedef enum {
|
|
|
|
EVENT_ENTER,
|
|
|
|
EVENT_LEAVE
|
|
|
|
} save_complete_event_type;
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2004-04-06 01:54:22 +04:00
|
|
|
|
2016-06-06 10:59:23 +03:00
|
|
|
static bool save_complete_save_html(save_complete_ctx *ctx, struct hlcache_handle *c,
|
2012-11-04 03:19:28 +04:00
|
|
|
bool index);
|
|
|
|
static bool save_complete_save_imported_sheets(save_complete_ctx *ctx,
|
|
|
|
struct nscss_import *imports, uint32_t import_count);
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2004-04-06 01:54:22 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static void save_complete_ctx_initialise(save_complete_ctx *ctx,
|
|
|
|
const char *path, save_complete_set_type_cb set_type)
|
2004-03-27 21:44:26 +03:00
|
|
|
{
|
2012-11-04 03:19:28 +04:00
|
|
|
ctx->path = path;
|
|
|
|
ctx->list = NULL;
|
|
|
|
ctx->set_type = set_type;
|
|
|
|
}
|
2004-02-17 15:41:38 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static void save_complete_ctx_finalise(save_complete_ctx *ctx)
|
|
|
|
{
|
|
|
|
save_complete_entry *list = ctx->list;
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
while (list != NULL) {
|
|
|
|
save_complete_entry *next = list->next;
|
|
|
|
free(list);
|
|
|
|
list = next;
|
2004-06-06 23:39:17 +04:00
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_ctx_add_content(save_complete_ctx *ctx,
|
2016-06-06 10:59:23 +03:00
|
|
|
struct hlcache_handle *content)
|
2012-11-04 03:19:28 +04:00
|
|
|
{
|
|
|
|
save_complete_entry *entry;
|
2009-03-11 20:22:46 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
entry = malloc(sizeof (*entry));
|
|
|
|
if (entry == NULL)
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
entry->content = content;
|
|
|
|
entry->next = ctx->list;
|
|
|
|
ctx->list = entry;
|
2009-03-11 20:22:46 +03:00
|
|
|
|
2004-06-06 23:39:17 +04:00
|
|
|
return true;
|
2004-02-17 15:41:38 +03:00
|
|
|
}
|
|
|
|
|
2016-06-06 10:59:23 +03:00
|
|
|
/**
|
|
|
|
* find handle to content for url
|
|
|
|
*
|
|
|
|
* \param ctx The save context
|
|
|
|
* \param url The url to find content handle for
|
|
|
|
* \return The content handle or NULL if not found.
|
|
|
|
*/
|
|
|
|
static struct hlcache_handle *
|
|
|
|
save_complete_ctx_find_content(save_complete_ctx *ctx, const nsurl *url)
|
2004-03-11 05:19:14 +03:00
|
|
|
{
|
2012-11-04 03:19:28 +04:00
|
|
|
save_complete_entry *entry;
|
2004-03-11 05:19:14 +03:00
|
|
|
|
2016-06-06 10:59:23 +03:00
|
|
|
for (entry = ctx->list; entry != NULL; entry = entry->next) {
|
2012-11-04 03:19:28 +04:00
|
|
|
if (nsurl_compare(url,
|
2016-06-06 10:59:23 +03:00
|
|
|
hlcache_handle_get_url(entry->content),
|
|
|
|
NSURL_COMPLETE)) {
|
2012-11-04 03:19:28 +04:00
|
|
|
return entry->content;
|
2016-06-06 10:59:23 +03:00
|
|
|
}
|
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
return NULL;
|
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_ctx_has_content(save_complete_ctx *ctx,
|
2016-06-06 10:59:23 +03:00
|
|
|
struct hlcache_handle *content)
|
2012-11-04 03:19:28 +04:00
|
|
|
{
|
|
|
|
save_complete_entry *entry;
|
2010-03-28 16:56:39 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
for (entry = ctx->list; entry != NULL; entry = entry->next)
|
|
|
|
if (entry->content == content)
|
|
|
|
return true;
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_save_buffer(save_complete_ctx *ctx,
|
|
|
|
const char *leafname, const char *data, size_t data_len,
|
|
|
|
lwc_string *mime_type)
|
|
|
|
{
|
2014-05-07 19:14:18 +04:00
|
|
|
nserror ret;
|
2012-11-04 03:19:28 +04:00
|
|
|
FILE *fp;
|
2014-05-07 19:14:18 +04:00
|
|
|
char *fname = NULL;
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, leafname);
|
|
|
|
if (ret != NSERROR_OK) {
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning(messages_get_errorcode(ret), 0);
|
2012-11-04 03:19:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
2011-05-07 00:40:09 +04:00
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
fp = fopen(fname, "wb");
|
2012-11-04 03:19:28 +04:00
|
|
|
if (fp == NULL) {
|
2014-05-07 19:14:18 +04:00
|
|
|
free(fname);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "fopen(): errno = %i", errno);
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("SaveError", strerror(errno));
|
2012-11-04 03:19:28 +04:00
|
|
|
return false;
|
2004-06-06 23:39:17 +04:00
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
fwrite(data, sizeof(*data), data_len, fp);
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
fclose(fp);
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
if (ctx->set_type != NULL) {
|
|
|
|
ctx->set_type(fname, mime_type);
|
|
|
|
}
|
|
|
|
free(fname);
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
return true;
|
2004-03-24 03:07:21 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2004-05-02 00:16:38 +04:00
|
|
|
* Rewrite stylesheet \@import rules for save complete.
|
2004-03-24 03:07:21 +03:00
|
|
|
*
|
2014-11-10 00:49:33 +03:00
|
|
|
* \param ctx Save complete context.
|
|
|
|
* \param source stylesheet source.
|
|
|
|
* \param size size of source.
|
|
|
|
* \param base url of stylesheet.
|
|
|
|
* \param osize updated with the size of the result.
|
|
|
|
* \return converted source, or NULL on out of memory.
|
2004-03-24 03:07:21 +03:00
|
|
|
*/
|
2017-09-10 12:30:27 +03:00
|
|
|
static char *
|
|
|
|
save_complete_rewrite_stylesheet_urls(save_complete_ctx *ctx,
|
|
|
|
const char *source,
|
|
|
|
unsigned long size,
|
|
|
|
const nsurl *base,
|
|
|
|
unsigned long *osize)
|
2004-03-27 21:44:26 +03:00
|
|
|
{
|
2012-11-04 03:19:28 +04:00
|
|
|
char *rewritten;
|
|
|
|
unsigned long offset = 0;
|
2004-03-27 21:44:26 +03:00
|
|
|
unsigned int imports = 0;
|
2012-11-04 03:19:28 +04:00
|
|
|
nserror error;
|
2004-03-27 21:44:26 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
/* count number occurrences of @import to (over)estimate result size */
|
2004-03-27 21:44:26 +03:00
|
|
|
/* can't use strstr because source is not 0-terminated string */
|
2017-09-10 12:30:27 +03:00
|
|
|
for (offset = 0;
|
|
|
|
(SLEN("@import") < size) && (offset <= (size - SLEN("@import")));
|
|
|
|
offset++) {
|
2012-11-04 03:19:28 +04:00
|
|
|
if (source[offset] == '@' &&
|
2016-09-11 12:27:11 +03:00
|
|
|
ascii_to_lower(source[offset + 1]) == 'i' &&
|
|
|
|
ascii_to_lower(source[offset + 2]) == 'm' &&
|
|
|
|
ascii_to_lower(source[offset + 3]) == 'p' &&
|
|
|
|
ascii_to_lower(source[offset + 4]) == 'o' &&
|
|
|
|
ascii_to_lower(source[offset + 5]) == 'r' &&
|
|
|
|
ascii_to_lower(source[offset + 6]) == 't') {
|
2004-03-27 21:44:26 +03:00
|
|
|
imports++;
|
2016-09-11 12:27:11 +03:00
|
|
|
}
|
2004-03-27 21:44:26 +03:00
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
rewritten = malloc(size + imports * 20);
|
|
|
|
if (rewritten == NULL)
|
|
|
|
return NULL;
|
2004-03-27 21:44:26 +03:00
|
|
|
*osize = 0;
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
offset = 0;
|
2004-03-27 21:44:26 +03:00
|
|
|
while (offset < size) {
|
2012-11-04 03:19:28 +04:00
|
|
|
const char *import_url = NULL;
|
|
|
|
char *import_url_copy;
|
|
|
|
int import_url_len = 0;
|
|
|
|
nsurl *url = NULL;
|
|
|
|
regmatch_t match[11];
|
|
|
|
int m = regexec(&save_complete_import_re, source + offset,
|
2004-03-27 21:44:26 +03:00
|
|
|
11, match, 0);
|
|
|
|
if (m)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (match[2].rm_so != -1) {
|
2012-11-04 03:19:28 +04:00
|
|
|
import_url = source + offset + match[2].rm_so;
|
|
|
|
import_url_len = match[2].rm_eo - match[2].rm_so;
|
2004-03-27 21:44:26 +03:00
|
|
|
} else if (match[4].rm_so != -1) {
|
2012-11-04 03:19:28 +04:00
|
|
|
import_url = source + offset + match[4].rm_so;
|
|
|
|
import_url_len = match[4].rm_eo - match[4].rm_so;
|
2004-03-27 21:44:26 +03:00
|
|
|
} else if (match[6].rm_so != -1) {
|
2012-11-04 03:19:28 +04:00
|
|
|
import_url = source + offset + match[6].rm_so;
|
|
|
|
import_url_len = match[6].rm_eo - match[6].rm_so;
|
2004-03-27 21:44:26 +03:00
|
|
|
} else if (match[8].rm_so != -1) {
|
2012-11-04 03:19:28 +04:00
|
|
|
import_url = source + offset + match[8].rm_so;
|
|
|
|
import_url_len = match[8].rm_eo - match[8].rm_so;
|
2004-03-27 21:44:26 +03:00
|
|
|
} else if (match[10].rm_so != -1) {
|
2012-11-04 03:19:28 +04:00
|
|
|
import_url = source + offset + match[10].rm_so;
|
|
|
|
import_url_len = match[10].rm_eo - match[10].rm_so;
|
2004-03-27 21:44:26 +03:00
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
assert(import_url != NULL);
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
import_url_copy = strndup(import_url, import_url_len);
|
|
|
|
if (import_url_copy == NULL) {
|
|
|
|
free(rewritten);
|
|
|
|
return NULL;
|
2004-03-27 21:44:26 +03:00
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
error = nsurl_join(base, import_url_copy, &url);
|
|
|
|
free(import_url_copy);
|
|
|
|
if (error == NSERROR_NOMEM) {
|
|
|
|
free(rewritten);
|
|
|
|
return NULL;
|
2004-06-06 23:39:17 +04:00
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2004-03-27 21:44:26 +03:00
|
|
|
/* copy data before match */
|
2012-11-04 03:19:28 +04:00
|
|
|
memcpy(rewritten + *osize, source + offset, match[0].rm_so);
|
2004-03-27 21:44:26 +03:00
|
|
|
*osize += match[0].rm_so;
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
if (url != NULL) {
|
|
|
|
hlcache_handle *content;
|
|
|
|
content = save_complete_ctx_find_content(ctx, url);
|
|
|
|
if (content != NULL) {
|
2004-08-09 20:11:58 +04:00
|
|
|
/* replace import */
|
2012-11-04 03:19:28 +04:00
|
|
|
char buf[64];
|
2009-12-18 02:55:02 +03:00
|
|
|
snprintf(buf, sizeof buf, "@import '%p'",
|
|
|
|
content);
|
2012-11-04 03:19:28 +04:00
|
|
|
memcpy(rewritten + *osize, buf, strlen(buf));
|
2004-08-09 20:11:58 +04:00
|
|
|
*osize += strlen(buf);
|
|
|
|
} else {
|
|
|
|
/* copy import */
|
2012-11-04 03:19:28 +04:00
|
|
|
memcpy(rewritten + *osize,
|
|
|
|
source + offset + match[0].rm_so,
|
2004-08-09 20:11:58 +04:00
|
|
|
match[0].rm_eo - match[0].rm_so);
|
|
|
|
*osize += match[0].rm_eo - match[0].rm_so;
|
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
nsurl_unref(url);
|
|
|
|
} else {
|
2004-03-27 21:44:26 +03:00
|
|
|
/* copy import */
|
2012-11-04 03:19:28 +04:00
|
|
|
memcpy(rewritten + *osize,
|
|
|
|
source + offset + match[0].rm_so,
|
2004-08-09 20:11:58 +04:00
|
|
|
match[0].rm_eo - match[0].rm_so);
|
2004-03-27 21:44:26 +03:00
|
|
|
*osize += match[0].rm_eo - match[0].rm_so;
|
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2004-03-27 21:44:26 +03:00
|
|
|
assert(0 < match[0].rm_eo);
|
|
|
|
offset += match[0].rm_eo;
|
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2004-03-27 21:44:26 +03:00
|
|
|
/* copy rest of source */
|
|
|
|
if (offset < size) {
|
2012-11-04 03:19:28 +04:00
|
|
|
memcpy(rewritten + *osize, source + offset, size - offset);
|
2004-03-27 21:44:26 +03:00
|
|
|
*osize += size - offset;
|
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
return rewritten;
|
2004-03-24 03:07:21 +03:00
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_save_stylesheet(save_complete_ctx *ctx,
|
|
|
|
hlcache_handle *css)
|
2004-03-24 03:07:21 +03:00
|
|
|
{
|
2012-11-04 03:19:28 +04:00
|
|
|
const char *css_data;
|
|
|
|
unsigned long css_size;
|
|
|
|
char *source;
|
|
|
|
unsigned long source_len;
|
|
|
|
struct nscss_import *imports;
|
|
|
|
uint32_t import_count;
|
|
|
|
lwc_string *type;
|
|
|
|
char filename[32];
|
|
|
|
bool result;
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
if (save_complete_ctx_has_content(ctx, css))
|
|
|
|
return true;
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
if (save_complete_ctx_add_content(ctx, css) == false) {
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("NoMemory", 0);
|
2012-11-04 03:19:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-02-18 02:38:44 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
imports = nscss_get_imports(css, &import_count);
|
|
|
|
if (save_complete_save_imported_sheets(ctx,
|
|
|
|
imports, import_count) == false)
|
|
|
|
return false;
|
2004-03-27 21:44:26 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
css_data = content_get_source_data(css, &css_size);
|
|
|
|
source = save_complete_rewrite_stylesheet_urls(ctx, css_data, css_size,
|
|
|
|
hlcache_handle_get_url(css), &source_len);
|
|
|
|
if (source == NULL) {
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("NoMemory", 0);
|
2012-11-04 03:19:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
2004-03-27 21:44:26 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
type = content_get_mime_type(css);
|
|
|
|
if (type == NULL) {
|
|
|
|
free(source);
|
|
|
|
return false;
|
|
|
|
}
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
snprintf(filename, sizeof filename, "%p", css);
|
2005-05-22 00:29:43 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
result = save_complete_save_buffer(ctx, filename,
|
|
|
|
source, source_len, type);
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
lwc_string_unref(type);
|
|
|
|
free(source);
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
return result;
|
|
|
|
}
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_save_imported_sheets(save_complete_ctx *ctx,
|
|
|
|
struct nscss_import *imports, uint32_t import_count)
|
|
|
|
{
|
|
|
|
uint32_t i;
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
for (i = 0; i < import_count; i++) {
|
2014-07-08 16:25:54 +04:00
|
|
|
/* treat a valid content as a stylesheet to save */
|
|
|
|
if ((imports[i].c != NULL) &&
|
|
|
|
(save_complete_save_stylesheet(ctx, imports[i].c) == false)) {
|
|
|
|
return false;
|
|
|
|
}
|
2005-05-22 00:29:43 +04:00
|
|
|
}
|
2004-06-06 23:39:17 +04:00
|
|
|
|
|
|
|
return true;
|
2004-03-24 03:07:21 +03:00
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_save_html_stylesheet(save_complete_ctx *ctx,
|
|
|
|
struct html_stylesheet *sheet)
|
2004-03-24 03:07:21 +03:00
|
|
|
{
|
2013-02-27 07:11:10 +04:00
|
|
|
if (sheet->sheet == NULL)
|
2012-11-04 03:19:28 +04:00
|
|
|
return true;
|
|
|
|
|
2013-02-27 07:11:10 +04:00
|
|
|
return save_complete_save_stylesheet(ctx, sheet->sheet);
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static bool save_complete_save_html_stylesheets(save_complete_ctx *ctx,
|
|
|
|
hlcache_handle *c)
|
|
|
|
{
|
|
|
|
struct html_stylesheet *sheets;
|
|
|
|
unsigned int i, count;
|
|
|
|
|
|
|
|
sheets = html_get_stylesheets(c, &count);
|
|
|
|
|
|
|
|
for (i = STYLESHEET_START; i != count; i++) {
|
|
|
|
if (save_complete_save_html_stylesheet(ctx,
|
|
|
|
&sheets[i]) == false)
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool save_complete_save_html_object(save_complete_ctx *ctx,
|
|
|
|
hlcache_handle *obj)
|
|
|
|
{
|
|
|
|
const char *obj_data;
|
|
|
|
unsigned long obj_size;
|
|
|
|
lwc_string *type;
|
|
|
|
bool result;
|
|
|
|
char filename[32];
|
|
|
|
|
|
|
|
if (content_get_type(obj) == CONTENT_NONE)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
obj_data = content_get_source_data(obj, &obj_size);
|
|
|
|
if (obj_data == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (save_complete_ctx_has_content(ctx, obj))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (save_complete_ctx_add_content(ctx, obj) == false) {
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("NoMemory", 0);
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (content_get_type(obj) == CONTENT_HTML) {
|
|
|
|
return save_complete_save_html(ctx, obj, false);
|
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
snprintf(filename, sizeof filename, "%p", obj);
|
|
|
|
|
|
|
|
type = content_get_mime_type(obj);
|
|
|
|
if (type == NULL)
|
2004-06-06 23:39:17 +04:00
|
|
|
return false;
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
result = save_complete_save_buffer(ctx, filename,
|
|
|
|
obj_data, obj_size, type);
|
|
|
|
|
|
|
|
lwc_string_unref(type);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool save_complete_save_html_objects(save_complete_ctx *ctx,
|
|
|
|
hlcache_handle *c)
|
|
|
|
{
|
|
|
|
struct content_html_object *object;
|
|
|
|
unsigned int count;
|
|
|
|
|
|
|
|
object = html_get_objects(c, &count);
|
|
|
|
|
|
|
|
for (; object != NULL; object = object->next) {
|
2014-01-07 02:22:41 +04:00
|
|
|
if ((object->content != NULL) && (object->box != NULL)) {
|
2012-11-04 03:19:28 +04:00
|
|
|
if (save_complete_save_html_object(ctx,
|
|
|
|
object->content) == false)
|
2004-08-09 20:11:58 +04:00
|
|
|
return false;
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool save_complete_libdom_treewalk(dom_node *root,
|
|
|
|
bool (*callback)(dom_node *node,
|
|
|
|
save_complete_event_type event_type, void *ctx),
|
|
|
|
void *ctx)
|
|
|
|
{
|
|
|
|
dom_node *node;
|
|
|
|
|
|
|
|
node = dom_node_ref(root); /* tree root */
|
|
|
|
|
|
|
|
while (node != NULL) {
|
|
|
|
dom_node *next = NULL;
|
|
|
|
dom_exception exc;
|
|
|
|
|
|
|
|
exc = dom_node_get_first_child(node, &next);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next != NULL) { /* 1. children */
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = next;
|
2004-08-09 20:11:58 +04:00
|
|
|
} else {
|
2012-11-04 03:19:28 +04:00
|
|
|
exc = dom_node_get_next_sibling(node, &next);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next != NULL) { /* 2. siblings */
|
|
|
|
if (callback(node, EVENT_LEAVE, ctx) == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = next;
|
|
|
|
} else { /* 3. ancestor siblings */
|
|
|
|
while (node != NULL) {
|
|
|
|
exc = dom_node_get_next_sibling(node,
|
|
|
|
&next);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (next != NULL) {
|
|
|
|
dom_node_unref(next);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
exc = dom_node_get_parent_node(node,
|
|
|
|
&next);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = NULL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback(node, EVENT_LEAVE,
|
|
|
|
ctx) == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = next;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (node == NULL)
|
|
|
|
break;
|
|
|
|
|
|
|
|
exc = dom_node_get_next_sibling(node, &next);
|
|
|
|
if (exc != DOM_NO_ERR) {
|
|
|
|
dom_node_unref(node);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (callback(node, EVENT_LEAVE, ctx) == false) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
dom_node_unref(node);
|
|
|
|
node = next;
|
2004-08-09 20:11:58 +04:00
|
|
|
}
|
2004-06-06 23:39:17 +04:00
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
assert(node != NULL);
|
|
|
|
|
|
|
|
if (callback(node, EVENT_ENTER, ctx) == false) {
|
|
|
|
return false; /* callback caused early termination */
|
|
|
|
}
|
|
|
|
|
2004-03-27 21:44:26 +03:00
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2004-06-06 23:39:17 +04:00
|
|
|
return true;
|
2004-03-27 21:44:26 +03:00
|
|
|
}
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_rewrite_url_value(save_complete_ctx *ctx,
|
|
|
|
const char *value, size_t value_len)
|
|
|
|
{
|
|
|
|
nsurl *url;
|
|
|
|
hlcache_handle *content;
|
2012-12-31 03:33:27 +04:00
|
|
|
char *escaped;
|
2012-11-04 03:19:28 +04:00
|
|
|
nserror error;
|
2004-03-24 03:07:21 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
error = nsurl_join(ctx->base, value, &url);
|
|
|
|
if (error == NSERROR_NOMEM)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (url != NULL) {
|
|
|
|
content = save_complete_ctx_find_content(ctx, url);
|
|
|
|
if (content != NULL) {
|
|
|
|
/* found a match */
|
|
|
|
nsurl_unref(url);
|
|
|
|
|
|
|
|
fprintf(ctx->fp, "\"%p\"", content);
|
|
|
|
} else {
|
|
|
|
/* no match found */
|
2014-01-29 01:40:13 +04:00
|
|
|
error = utf8_to_html(nsurl_access(url), "UTF-8",
|
2012-12-31 03:33:27 +04:00
|
|
|
nsurl_length(url), &escaped);
|
2012-11-04 03:19:28 +04:00
|
|
|
nsurl_unref(url);
|
2012-12-31 03:33:27 +04:00
|
|
|
|
2014-01-29 01:40:13 +04:00
|
|
|
if (error != NSERROR_OK)
|
2012-12-31 03:33:27 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
fprintf(ctx->fp, "\"%s\"", escaped);
|
|
|
|
|
|
|
|
free(escaped);
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
|
|
|
} else {
|
2014-01-29 01:40:13 +04:00
|
|
|
error = utf8_to_html(value, "UTF-8", value_len, &escaped);
|
|
|
|
if (error != NSERROR_OK)
|
2012-12-31 03:33:27 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
fprintf(ctx->fp, "\"%s\"", escaped);
|
|
|
|
|
|
|
|
free(escaped);
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2004-03-27 21:44:26 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_write_value(save_complete_ctx *ctx,
|
|
|
|
const char *value, size_t value_len)
|
2004-03-27 21:44:26 +03:00
|
|
|
{
|
2012-12-31 03:33:27 +04:00
|
|
|
char *escaped;
|
2014-01-29 01:40:13 +04:00
|
|
|
nserror ret;
|
2012-12-31 03:33:27 +04:00
|
|
|
|
|
|
|
ret = utf8_to_html(value, "UTF-8", value_len, &escaped);
|
2014-01-29 01:40:13 +04:00
|
|
|
if (ret != NSERROR_OK)
|
2012-12-31 03:33:27 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
fprintf(ctx->fp, "\"%s\"", escaped);
|
|
|
|
|
|
|
|
free(escaped);
|
2012-11-04 03:19:28 +04:00
|
|
|
|
2004-06-06 23:39:17 +04:00
|
|
|
return true;
|
2004-03-27 21:44:26 +03:00
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_handle_attr_value(save_complete_ctx *ctx,
|
|
|
|
dom_string *node_name, dom_string *attr_name,
|
|
|
|
dom_string *attr_value)
|
|
|
|
{
|
|
|
|
const char *node_data = dom_string_data(node_name);
|
|
|
|
size_t node_len = dom_string_byte_length(node_name);
|
|
|
|
const char *name_data = dom_string_data(attr_name);
|
|
|
|
size_t name_len = dom_string_byte_length(attr_name);
|
|
|
|
const char *value_data = dom_string_data(attr_value);
|
|
|
|
size_t value_len = dom_string_byte_length(attr_value);
|
2004-03-27 21:44:26 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
/**
|
|
|
|
* We only need to consider the following cases:
|
|
|
|
*
|
|
|
|
* Attribute: Elements:
|
|
|
|
*
|
2017-02-24 17:02:31 +03:00
|
|
|
* 1) data object
|
|
|
|
* 2) href a, area, link
|
|
|
|
* 3) src script, input, frame, iframe, img
|
2012-11-04 03:19:28 +04:00
|
|
|
* 4) background any (except those above)
|
|
|
|
*/
|
|
|
|
/* 1 */
|
|
|
|
if (name_len == SLEN("data") &&
|
|
|
|
strncasecmp(name_data, "data", name_len) == 0) {
|
|
|
|
if (node_len == SLEN("object") &&
|
|
|
|
strncasecmp(node_data,
|
|
|
|
"object", node_len) == 0) {
|
|
|
|
return save_complete_rewrite_url_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
} else {
|
|
|
|
return save_complete_write_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 2 */
|
|
|
|
else if (name_len == SLEN("href") &&
|
|
|
|
strncasecmp(name_data, "href", name_len) == 0) {
|
|
|
|
if ((node_len == SLEN("a") &&
|
|
|
|
strncasecmp(node_data, "a", node_len) == 0) ||
|
|
|
|
(node_len == SLEN("area") &&
|
|
|
|
strncasecmp(node_data, "area",
|
|
|
|
node_len) == 0) ||
|
|
|
|
(node_len == SLEN("link") &&
|
|
|
|
strncasecmp(node_data, "link",
|
|
|
|
node_len) == 0)) {
|
|
|
|
return save_complete_rewrite_url_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
} else {
|
|
|
|
return save_complete_write_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 3 */
|
|
|
|
else if (name_len == SLEN("src") &&
|
|
|
|
strncasecmp(name_data, "src", name_len) == 0) {
|
|
|
|
if ((node_len == SLEN("frame") &&
|
|
|
|
strncasecmp(node_data, "frame",
|
|
|
|
node_len) == 0) ||
|
|
|
|
(node_len == SLEN("iframe") &&
|
|
|
|
strncasecmp(node_data, "iframe",
|
|
|
|
node_len) == 0) ||
|
|
|
|
(node_len == SLEN("input") &&
|
|
|
|
strncasecmp(node_data, "input",
|
|
|
|
node_len) == 0) ||
|
|
|
|
(node_len == SLEN("img") &&
|
|
|
|
strncasecmp(node_data, "img",
|
|
|
|
node_len) == 0) ||
|
|
|
|
(node_len == SLEN("script") &&
|
|
|
|
strncasecmp(node_data, "script",
|
|
|
|
node_len) == 0)) {
|
|
|
|
return save_complete_rewrite_url_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
} else {
|
|
|
|
return save_complete_write_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
/* 4 */
|
|
|
|
else if (name_len == SLEN("background") &&
|
|
|
|
strncasecmp(name_data, "background", name_len) == 0) {
|
|
|
|
return save_complete_rewrite_url_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
} else {
|
|
|
|
return save_complete_write_value(ctx,
|
|
|
|
value_data, value_len);
|
|
|
|
}
|
|
|
|
}
|
2004-03-27 21:44:26 +03:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_handle_attr(save_complete_ctx *ctx,
|
|
|
|
dom_string *node_name, dom_attr *attr)
|
2004-03-27 21:44:26 +03:00
|
|
|
{
|
2012-11-04 03:19:28 +04:00
|
|
|
dom_string *name;
|
|
|
|
const char *name_data;
|
|
|
|
size_t name_len;
|
|
|
|
dom_string *value;
|
|
|
|
dom_exception error;
|
|
|
|
|
|
|
|
error = dom_attr_get_name(attr, &name);
|
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error = dom_attr_get_value(attr, &value);
|
|
|
|
if (error != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
name_data = dom_string_data(name);
|
|
|
|
name_len = dom_string_byte_length(name);
|
|
|
|
|
|
|
|
fputc(' ', ctx->fp);
|
|
|
|
fwrite(name_data, sizeof(*name_data), name_len, ctx->fp);
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
fputc('=', ctx->fp);
|
|
|
|
if (save_complete_handle_attr_value(ctx, node_name,
|
|
|
|
name, value) == false) {
|
|
|
|
dom_string_unref(value);
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
return true;
|
2004-03-24 03:07:21 +03:00
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_handle_attrs(save_complete_ctx *ctx,
|
|
|
|
dom_string *node_name, dom_namednodemap *attrs)
|
|
|
|
{
|
|
|
|
uint32_t length, i;
|
|
|
|
dom_exception error;
|
|
|
|
|
|
|
|
error = dom_namednodemap_get_length(attrs, &length);
|
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
for (i = 0; i < length; i++) {
|
|
|
|
dom_attr *attr;
|
2004-06-06 23:39:17 +04:00
|
|
|
|
2012-12-31 03:33:27 +04:00
|
|
|
error = dom_namednodemap_item(attrs, i, (void *) &attr);
|
2012-11-04 03:19:28 +04:00
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (attr == NULL)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (save_complete_handle_attr(ctx, node_name, attr) == false) {
|
|
|
|
dom_node_unref(attr);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_node_unref(attr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool save_complete_handle_element(save_complete_ctx *ctx,
|
|
|
|
dom_node *node, save_complete_event_type event_type)
|
2004-06-06 23:39:17 +04:00
|
|
|
{
|
2012-11-04 03:19:28 +04:00
|
|
|
dom_string *name;
|
|
|
|
dom_namednodemap *attrs;
|
|
|
|
const char *name_data;
|
|
|
|
size_t name_len;
|
2012-12-31 03:33:27 +04:00
|
|
|
bool process = true;
|
2012-11-04 03:19:28 +04:00
|
|
|
dom_exception error;
|
|
|
|
|
|
|
|
ctx->iter_state = STATE_NORMAL;
|
|
|
|
|
|
|
|
error = dom_node_get_node_name(node, &name);
|
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
name_data = dom_string_data(name);
|
|
|
|
name_len = dom_string_byte_length(name);
|
|
|
|
|
|
|
|
if (name_len == SLEN("base") &&
|
|
|
|
strncasecmp(name_data, "base", name_len) == 0) {
|
2012-12-31 03:33:27 +04:00
|
|
|
/* Elide BASE elements from the output */
|
|
|
|
process = false;
|
|
|
|
} else if (name_len == SLEN("meta") &&
|
|
|
|
strncasecmp(name_data, "meta", name_len) == 0) {
|
|
|
|
/* Don't emit close tags for META elements */
|
|
|
|
if (event_type == EVENT_LEAVE) {
|
|
|
|
process = false;
|
|
|
|
} else {
|
|
|
|
/* Elide meta charsets */
|
|
|
|
dom_string *value;
|
|
|
|
error = dom_element_get_attribute(node,
|
|
|
|
corestring_dom_http_equiv, &value);
|
|
|
|
if (error != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (value != NULL) {
|
|
|
|
if (dom_string_length(value) ==
|
|
|
|
SLEN("Content-Type") &&
|
|
|
|
strncasecmp(dom_string_data(value),
|
|
|
|
"Content-Type",
|
|
|
|
SLEN("Content-Type")) == 0)
|
|
|
|
process = false;
|
|
|
|
|
|
|
|
dom_string_unref(value);
|
|
|
|
} else {
|
|
|
|
bool yes;
|
|
|
|
|
|
|
|
error = dom_element_has_attribute(node,
|
|
|
|
corestring_dom_charset, &yes);
|
|
|
|
if (error != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (yes)
|
|
|
|
process = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if (event_type == EVENT_LEAVE &&
|
|
|
|
((name_len == SLEN("link") &&
|
|
|
|
strncasecmp(name_data, "link", name_len) == 0))) {
|
|
|
|
/* Don't emit close tags for void elements */
|
|
|
|
process = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (process == false) {
|
2012-11-04 03:19:28 +04:00
|
|
|
dom_string_unref(name);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('<', ctx->fp);
|
|
|
|
if (event_type == EVENT_LEAVE)
|
|
|
|
fputc('/', ctx->fp);
|
|
|
|
fwrite(name_data, sizeof(*name_data), name_len, ctx->fp);
|
|
|
|
|
|
|
|
if (event_type == EVENT_ENTER) {
|
|
|
|
error = dom_node_get_attributes(node, &attrs);
|
|
|
|
if (error != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (save_complete_handle_attrs(ctx, name, attrs) == false) {
|
|
|
|
dom_namednodemap_unref(attrs);
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_namednodemap_unref(attrs);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('>', ctx->fp);
|
|
|
|
|
|
|
|
/* Rewrite contents of style elements */
|
|
|
|
if (event_type == EVENT_ENTER && name_len == SLEN("style") &&
|
|
|
|
strncasecmp(name_data, "style", name_len) == 0) {
|
|
|
|
dom_string *content;
|
|
|
|
|
|
|
|
error = dom_node_get_text_content(node, &content);
|
|
|
|
if (error != DOM_NO_ERR) {
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content != NULL) {
|
|
|
|
char *rewritten;
|
|
|
|
unsigned long len;
|
|
|
|
|
|
|
|
/* Rewrite @import rules */
|
|
|
|
rewritten = save_complete_rewrite_stylesheet_urls(
|
|
|
|
ctx,
|
|
|
|
dom_string_data(content),
|
|
|
|
dom_string_byte_length(content),
|
|
|
|
ctx->base,
|
|
|
|
&len);
|
|
|
|
if (rewritten == NULL) {
|
|
|
|
dom_string_unref(content);
|
|
|
|
dom_string_unref(name);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(content);
|
|
|
|
|
|
|
|
fwrite(rewritten, sizeof(*rewritten), len, ctx->fp);
|
|
|
|
|
|
|
|
free(rewritten);
|
|
|
|
}
|
|
|
|
|
|
|
|
ctx->iter_state = STATE_IN_STYLE;
|
2012-12-31 03:33:27 +04:00
|
|
|
} else if (event_type == EVENT_ENTER && name_len == SLEN("head") &&
|
|
|
|
strncasecmp(name_data, "head", name_len) == 0) {
|
|
|
|
/* If this is a HEAD element, insert a meta charset */
|
|
|
|
fputs("<META http-equiv=\"Content-Type\" "
|
|
|
|
"content=\"text/html; charset=utf-8\">",
|
|
|
|
ctx->fp);
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool save_complete_node_handler(dom_node *node,
|
|
|
|
save_complete_event_type event_type, void *ctxin)
|
|
|
|
{
|
|
|
|
save_complete_ctx *ctx = ctxin;
|
|
|
|
dom_node_type type;
|
|
|
|
dom_exception error;
|
2014-01-29 01:40:13 +04:00
|
|
|
nserror ret;
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
error = dom_node_get_node_type(node, &type);
|
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (type == DOM_ELEMENT_NODE) {
|
|
|
|
return save_complete_handle_element(ctx, node, event_type);
|
|
|
|
} else if (type == DOM_TEXT_NODE || type == DOM_COMMENT_NODE) {
|
|
|
|
if (event_type != EVENT_ENTER)
|
2004-06-06 23:39:17 +04:00
|
|
|
return true;
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
if (ctx->iter_state != STATE_IN_STYLE) {
|
|
|
|
/* Emit text content */
|
|
|
|
dom_string *text;
|
|
|
|
const char *text_data;
|
|
|
|
size_t text_len;
|
|
|
|
|
|
|
|
error = dom_characterdata_get_data(node, &text);
|
|
|
|
if (error != DOM_NO_ERR) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-06 14:02:17 +04:00
|
|
|
if (type == DOM_COMMENT_NODE)
|
|
|
|
fwrite("<!--", 1, sizeof("<!--") - 1, ctx->fp);
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
if (text != NULL) {
|
2012-12-31 03:33:27 +04:00
|
|
|
char *escaped;
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
text_data = dom_string_data(text);
|
|
|
|
text_len = dom_string_byte_length(text);
|
|
|
|
|
2012-12-31 03:33:27 +04:00
|
|
|
ret = utf8_to_html(text_data, "UTF-8",
|
|
|
|
text_len, &escaped);
|
2014-01-29 01:40:13 +04:00
|
|
|
if (ret != NSERROR_OK)
|
2012-12-31 03:33:27 +04:00
|
|
|
return false;
|
|
|
|
|
|
|
|
fwrite(escaped, sizeof(*escaped),
|
|
|
|
strlen(escaped), ctx->fp);
|
|
|
|
|
|
|
|
free(escaped);
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
dom_string_unref(text);
|
|
|
|
}
|
2012-11-06 14:02:17 +04:00
|
|
|
|
|
|
|
if (type == DOM_COMMENT_NODE) {
|
|
|
|
fwrite("-->", 1, sizeof("-->") - 1, ctx->fp);
|
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
2012-11-06 14:02:17 +04:00
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
} else if (type == DOM_DOCUMENT_TYPE_NODE) {
|
|
|
|
dom_string *name;
|
|
|
|
const char *name_data;
|
|
|
|
size_t name_len;
|
|
|
|
|
|
|
|
if (event_type != EVENT_ENTER)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
error = dom_document_type_get_name(node, &name);
|
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (name == NULL)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
name_data = dom_string_data(name);
|
|
|
|
name_len = dom_string_byte_length(name);
|
|
|
|
|
|
|
|
fputs("<!DOCTYPE ", ctx->fp);
|
|
|
|
fwrite(name_data, sizeof(*name_data), name_len, ctx->fp);
|
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
|
|
|
|
error = dom_document_type_get_public_id(node, &name);
|
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (name != NULL) {
|
|
|
|
name_data = dom_string_data(name);
|
|
|
|
name_len = dom_string_byte_length(name);
|
|
|
|
|
2012-12-31 03:33:27 +04:00
|
|
|
if (name_len > 0)
|
|
|
|
fprintf(ctx->fp, " PUBLIC \"%.*s\"",
|
|
|
|
(int) name_len, name_data);
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
error = dom_document_type_get_system_id(node, &name);
|
|
|
|
if (error != DOM_NO_ERR)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (name != NULL) {
|
|
|
|
name_data = dom_string_data(name);
|
|
|
|
name_len = dom_string_byte_length(name);
|
|
|
|
|
2012-12-31 03:33:27 +04:00
|
|
|
if (name_len > 0)
|
|
|
|
fprintf(ctx->fp, " \"%.*s\"",
|
|
|
|
(int) name_len, name_data);
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
dom_string_unref(name);
|
|
|
|
}
|
|
|
|
|
|
|
|
fputc('>', ctx->fp);
|
|
|
|
} else if (type == DOM_DOCUMENT_NODE) {
|
|
|
|
/* Do nothing */
|
|
|
|
} else {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Unhandled node type: %d", type);
|
2012-11-04 03:19:28 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
2004-06-06 23:39:17 +04:00
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_save_html_document(save_complete_ctx *ctx,
|
|
|
|
hlcache_handle *c, bool index)
|
|
|
|
{
|
2014-05-07 19:14:18 +04:00
|
|
|
nserror ret;
|
2012-11-04 03:19:28 +04:00
|
|
|
FILE *fp;
|
2014-05-07 19:14:18 +04:00
|
|
|
char *fname = NULL;
|
2012-11-04 03:19:28 +04:00
|
|
|
dom_document *doc;
|
|
|
|
lwc_string *mime_type;
|
|
|
|
char filename[32];
|
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
if (index) {
|
2012-11-04 03:19:28 +04:00
|
|
|
snprintf(filename, sizeof filename, "index");
|
2014-05-07 19:14:18 +04:00
|
|
|
} else {
|
2012-11-04 03:19:28 +04:00
|
|
|
snprintf(filename, sizeof filename, "%p", c);
|
2014-05-07 19:14:18 +04:00
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, filename);
|
|
|
|
if (ret != NSERROR_OK) {
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning(messages_get_errorcode(ret), NULL);
|
2012-11-04 03:19:28 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
fp = fopen(fname, "wb");
|
2012-11-04 03:19:28 +04:00
|
|
|
if (fp == NULL) {
|
2014-05-07 19:14:18 +04:00
|
|
|
free(fname);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "fopen(): errno = %i", errno);
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("SaveError", strerror(errno));
|
2012-11-04 03:19:28 +04:00
|
|
|
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) {
|
2014-05-07 19:14:18 +04:00
|
|
|
free(fname);
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("NoMemory", 0);
|
2012-11-04 03:19:28 +04:00
|
|
|
fclose(fp);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
mime_type = content_get_mime_type(c);
|
|
|
|
if (mime_type != NULL) {
|
|
|
|
if (ctx->set_type != NULL)
|
2014-05-07 19:14:18 +04:00
|
|
|
ctx->set_type(fname, mime_type);
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
lwc_string_unref(mime_type);
|
|
|
|
}
|
2014-05-07 19:14:18 +04:00
|
|
|
free(fname);
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
2008-07-27 02:29:15 +04:00
|
|
|
|
2005-05-22 00:29:43 +04:00
|
|
|
/**
|
2012-11-04 03:19:28 +04:00
|
|
|
* Save an HTML page with all dependencies, recursing through imported pages.
|
|
|
|
*
|
|
|
|
* \param ctx Save complete context
|
|
|
|
* \param c Content to save
|
|
|
|
* \param index true to save as "index"
|
|
|
|
* \return true on success, false on error and error reported
|
2005-05-22 00:29:43 +04:00
|
|
|
*/
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_save_html(save_complete_ctx *ctx, hlcache_handle *c,
|
|
|
|
bool index)
|
2005-05-22 00:29:43 +04:00
|
|
|
{
|
2012-11-04 03:19:28 +04:00
|
|
|
if (content_get_type(c) != CONTENT_HTML)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (save_complete_ctx_has_content(ctx, c))
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (save_complete_save_html_stylesheets(ctx, c) == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
if (save_complete_save_html_objects(ctx, c) == false)
|
|
|
|
return false;
|
|
|
|
|
|
|
|
return save_complete_save_html_document(ctx, c, index);
|
2005-05-22 00:29:43 +04:00
|
|
|
}
|
|
|
|
|
2007-07-05 08:29:09 +04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create the inventory file listing original URLs.
|
|
|
|
*/
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
static bool save_complete_inventory(save_complete_ctx *ctx)
|
2007-07-05 08:29:09 +04:00
|
|
|
{
|
2014-05-07 19:14:18 +04:00
|
|
|
nserror ret;
|
2007-07-05 08:29:09 +04:00
|
|
|
FILE *fp;
|
2014-05-07 19:14:18 +04:00
|
|
|
char *fname = NULL;
|
2012-11-04 03:19:28 +04:00
|
|
|
save_complete_entry *entry;
|
2007-07-05 08:29:09 +04:00
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
ret = netsurf_mkpath(&fname, NULL, 2, ctx->path, "Inventory");
|
|
|
|
if (ret != NSERROR_OK) {
|
2009-12-18 02:55:02 +03:00
|
|
|
return false;
|
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
|
2014-05-07 19:14:18 +04:00
|
|
|
fp = fopen(fname, "w");
|
|
|
|
free(fname);
|
2012-11-04 03:19:28 +04:00
|
|
|
if (fp == NULL) {
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "fopen(): errno = %i", errno);
|
2016-04-26 14:50:16 +03:00
|
|
|
guit->misc->warning("SaveError", strerror(errno));
|
2007-07-05 08:29:09 +04:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
for (entry = ctx->list; entry != NULL; entry = entry->next) {
|
2010-03-28 16:56:39 +04:00
|
|
|
fprintf(fp, "%p %s\n", entry->content,
|
2012-11-04 03:19:28 +04:00
|
|
|
nsurl_access(hlcache_handle_get_url(
|
|
|
|
entry->content)));
|
2010-03-28 16:56:39 +04:00
|
|
|
}
|
2007-07-05 08:29:09 +04:00
|
|
|
|
|
|
|
fclose(fp);
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2016-04-21 01:33:31 +03:00
|
|
|
/**
|
|
|
|
* Compile a regular expression, handling errors.
|
|
|
|
*
|
|
|
|
* Parameters as for regcomp(), see man regex.
|
|
|
|
*/
|
|
|
|
static nserror regcomp_wrapper(regex_t *preg, const char *regex, int cflags)
|
|
|
|
{
|
|
|
|
int r;
|
|
|
|
r = regcomp(preg, regex, cflags);
|
|
|
|
if (r) {
|
|
|
|
char errbuf[200];
|
|
|
|
regerror(r, preg, errbuf, sizeof errbuf);
|
Use coccinelle to change logging macro calls in c files
for F in $(git ls-files '*.c');do spatch --sp-file foo.cocci --in-place ${F};done
@@ expression E; @@
-LOG(E);
+NSLOG(netsurf, INFO, E);
@@ expression E, E1; @@
-LOG(E, E1);
+NSLOG(netsurf, INFO, E, E1);
@@ expression E, E1, E2; @@
-LOG(E, E1, E2);
+NSLOG(netsurf, INFO, E, E1, E2);
@@ expression E, E1, E2, E3; @@
-LOG(E, E1, E2, E3);
+NSLOG(netsurf, INFO, E, E1, E2, E3);
@@ expression E, E1, E2, E3, E4; @@
-LOG(E, E1, E2, E3, E4);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4);
@@ expression E, E1, E2, E3, E4, E5; @@
-LOG(E, E1, E2, E3, E4, E5);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5);
@@ expression E, E1, E2, E3, E4, E5, E6; @@
-LOG(E, E1, E2, E3, E4, E5, E6);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6);
@@ expression E, E1, E2, E3, E4, E5, E6, E7; @@
-LOG(E, E1, E2, E3, E4, E5, E6, E7);
+NSLOG(netsurf, INFO, E, E1, E2, E3, E4, E5, E6, E7);
2017-09-06 20:28:12 +03:00
|
|
|
NSLOG(netsurf, INFO, "Failed to compile regexp '%s': %s\n",
|
|
|
|
regex, errbuf);
|
2016-04-21 01:33:31 +03:00
|
|
|
return NSERROR_INIT_FAILED;
|
|
|
|
}
|
|
|
|
return NSERROR_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2012-11-04 03:19:28 +04:00
|
|
|
/* Documented in save_complete.h */
|
|
|
|
void save_complete_init(void)
|
|
|
|
{
|
|
|
|
/* Match an @import rule - see CSS 2.1 G.1. */
|
|
|
|
regcomp_wrapper(&save_complete_import_re,
|
|
|
|
"@import" /* IMPORT_SYM */
|
|
|
|
"[ \t\r\n\f]*" /* S* */
|
|
|
|
/* 1 */
|
|
|
|
"(" /* [ */
|
|
|
|
/* 2 3 */
|
|
|
|
"\"(([^\"]|[\\]\")*)\"" /* STRING (approximated) */
|
|
|
|
"|"
|
|
|
|
/* 4 5 */
|
|
|
|
"'(([^']|[\\]')*)'"
|
|
|
|
"|" /* | */
|
|
|
|
"url\\([ \t\r\n\f]*" /* URI (approximated) */
|
|
|
|
/* 6 7 */
|
|
|
|
"\"(([^\"]|[\\]\")*)\""
|
|
|
|
"[ \t\r\n\f]*\\)"
|
|
|
|
"|"
|
|
|
|
"url\\([ \t\r\n\f]*"
|
|
|
|
/* 8 9 */
|
|
|
|
"'(([^']|[\\]')*)'"
|
|
|
|
"[ \t\r\n\f]*\\)"
|
|
|
|
"|"
|
|
|
|
"url\\([ \t\r\n\f]*"
|
|
|
|
/* 10 */
|
|
|
|
"([^) \t\r\n\f]*)"
|
|
|
|
"[ \t\r\n\f]*\\)"
|
|
|
|
")", /* ] */
|
|
|
|
REG_EXTENDED | REG_ICASE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Documented in save_complete.h */
|
|
|
|
bool save_complete(hlcache_handle *c, const char *path,
|
|
|
|
save_complete_set_type_cb set_type)
|
|
|
|
{
|
|
|
|
bool result;
|
|
|
|
save_complete_ctx ctx;
|
|
|
|
|
|
|
|
save_complete_ctx_initialise(&ctx, path, set_type);
|
|
|
|
|
|
|
|
result = save_complete_save_html(&ctx, c, true);
|
|
|
|
|
2014-05-18 02:14:43 +04:00
|
|
|
if (result) {
|
2012-11-04 03:19:28 +04:00
|
|
|
result = save_complete_inventory(&ctx);
|
2014-05-18 02:14:43 +04:00
|
|
|
}
|
2012-11-04 03:19:28 +04:00
|
|
|
|
|
|
|
save_complete_ctx_finalise(&ctx);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|