static bool save_complete_rewrite_url_value(save_complete_ctx *ctx, const char *value, size_t value_len) { nsurl *url; hlcache_handle *content; char *escaped; nserror error; utf8_convert_ret ret; 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 */ ret = utf8_to_html(nsurl_access(url), "UTF-8", nsurl_length(url), &escaped); nsurl_unref(url); if (ret != UTF8_CONVERT_OK) return false; fprintf(ctx->fp, "\"%s\"", escaped); free(escaped); } } else { ret = utf8_to_html(value, "UTF-8", value_len, &escaped); if (ret != UTF8_CONVERT_OK) return false; fprintf(ctx->fp, "\"%s\"", escaped); free(escaped); } return true; }
/** Callback for treeview_walk node entering */ static nserror global_history_export_enter_cb(void *ctx, void *node_data, enum treeview_node_type type, bool *abort) { struct treeview_export_walk_ctx *tw = ctx; nserror ret; if (type == TREE_NODE_ENTRY) { struct global_history_entry *e = node_data; char *t_text; char *u_text; ret = utf8_to_html(e->data[GH_TITLE].value, "iso-8859-1", e->data[GH_TITLE].value_len, &t_text); if (ret != NSERROR_OK) return NSERROR_SAVE_FAILED; ret = utf8_to_html(e->data[GH_URL].value, "iso-8859-1", e->data[GH_URL].value_len, &u_text); if (ret != NSERROR_OK) { free(t_text); return NSERROR_SAVE_FAILED; } fprintf(tw->fp, "<li><a href=\"%s\">%s</a></li>\n", u_text, t_text); free(t_text); free(u_text); } else if (type == TREE_NODE_FOLDER) { struct global_history_folder *f = node_data; char *f_text; ret = utf8_to_html(f->data.value, "iso-8859-1", f->data.value_len, &f_text); if (ret != NSERROR_OK) return NSERROR_SAVE_FAILED; fprintf(tw->fp, "<li><h4>%s</h4>\n<ul>\n", f_text); free(f_text); } return NSERROR_OK; }
static bool save_complete_write_value(save_complete_ctx *ctx, const char *value, size_t value_len) { char *escaped; utf8_convert_ret ret; ret = utf8_to_html(value, "UTF-8", value_len, &escaped); if (ret != UTF8_CONVERT_OK) return false; fprintf(ctx->fp, "\"%s\"", escaped); free(escaped); 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; utf8_convert_ret ret; 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) return true; 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; } if (type == DOM_COMMENT_NODE) fwrite("<!--", 1, sizeof("<!--") - 1, ctx->fp); if (text != NULL) { char *escaped; text_data = dom_string_data(text); text_len = dom_string_byte_length(text); ret = utf8_to_html(text_data, "UTF-8", text_len, &escaped); if (ret != UTF8_CONVERT_OK) return false; fwrite(escaped, sizeof(*escaped), strlen(escaped), ctx->fp); free(escaped); dom_string_unref(text); } if (type == DOM_COMMENT_NODE) { fwrite("-->", 1, sizeof("-->") - 1, ctx->fp); } } } 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); if (name_len > 0) fprintf(ctx->fp, " PUBLIC \"%.*s\"", (int) name_len, name_data); 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); if (name_len > 0) fprintf(ctx->fp, " \"%.*s\"", (int) name_len, name_data); dom_string_unref(name); } fputc('>', ctx->fp); } else if (type == DOM_DOCUMENT_NODE) { /* Do nothing */ } else { LOG(("Unhandled node type: %d", type)); } return true; }