Exemplo n.º 1
0
binding_error binding_create_tree(void *arena, const char *charset, void **ctx)
{
	dom_hubbub_parser *parser = NULL;

	parser = dom_hubbub_parser_create(charset, true, NULL, NULL);
        if (parser == NULL) {
                LOG(("Can't create Hubbub Parser\n"));
                return BINDING_NOMEM;
        }
	*ctx = parser;
	return BINDING_OK;
}
Exemplo n.º 2
0
/**
 * Load the file as it is a HTML file
 *
 * \param file		The file path 
 * \param willBeModified	Whether this file will be modified, not used
 */
dom_document *load_html(const char *file, bool willBeModified)
{
	dom_hubbub_parser *parser = NULL;
	int handle;
	int readed;
	dom_hubbub_error error;
	dom_document *ret;
	uint8_t buffer[1024];
	dom_hubbub_parser_params params;

	UNUSED(willBeModified);

	params.enc = NULL;
	params.fix_enc = true;
	params.enable_script = false;
	params.msg = mymsg;
	params.script = NULL;
	params.ctx = NULL;
	params.daf = NULL;

	error = dom_hubbub_parser_create(&params, &parser, &ret);
	if (error != DOM_HUBBUB_OK) {
		fprintf(stderr, "Can't create Hubbub Parser\n");
		return NULL;
	}

	handle = open(file, O_RDONLY);
	if (handle == -1) {
		dom_hubbub_parser_destroy(parser);
		/* fprintf(stderr, "Can't open test input file: %s\n", file); */
		return NULL;
	}

	readed = read(handle, buffer, 1024);
	error = dom_hubbub_parser_parse_chunk(parser, buffer, readed);
	if (error != DOM_HUBBUB_OK) {
		dom_hubbub_parser_destroy(parser);
		fprintf(stderr, "Parsing errors occur\n");
		return NULL;
	}

	while(readed == 1024) {
		readed = read(handle, buffer, 1024);
		error = dom_hubbub_parser_parse_chunk(parser, buffer, readed);
		if (error != DOM_HUBBUB_OK) {
			dom_hubbub_parser_destroy(parser);
			fprintf(stderr, "Parsing errors occur\n");
			return NULL;
		}
	}

	error = dom_hubbub_parser_completed(parser);
	if (error != DOM_HUBBUB_OK) {
		dom_hubbub_parser_destroy(parser);
		fprintf(stderr, "Parsing error when construct DOM\n");
		return NULL;
	}

	dom_hubbub_parser_destroy(parser);

	return ret;
}