summaryrefslogtreecommitdiff
path: root/src/tokeniser/tokeniser.h
blob: e13a03a0d9c781d3c4f958f2db4ecac613fb8045 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/*
 * This file is part of Hubbub.
 * Licensed under the MIT License,
 *                http://www.opensource.org/licenses/mit-license.php
 * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
 */

#ifndef hubbub_tokeniser_tokeniser_h_
#define hubbub_tokeniser_tokeniser_h_

#include <stdbool.h>
#include <inttypes.h>

#include <hubbub/errors.h>
#include <hubbub/functypes.h>
#include <hubbub/types.h>

#include <parserutils/input/inputstream.h>

typedef struct hubbub_tokeniser hubbub_tokeniser;

/**
 * Hubbub tokeniser option types
 */
typedef enum hubbub_tokeniser_opttype {
	HUBBUB_TOKENISER_TOKEN_HANDLER,
	HUBBUB_TOKENISER_ERROR_HANDLER,
	HUBBUB_TOKENISER_CONTENT_MODEL,
	HUBBUB_TOKENISER_PROCESS_CDATA
} hubbub_tokeniser_opttype;

/**
 * Hubbub tokeniser option parameters
 */
typedef union hubbub_tokeniser_optparams {
	struct {
		hubbub_token_handler handler;
		void *pw;
	} token_handler;		/**< Token handling callback */

	struct {
		hubbub_error_handler handler;
		void *pw;
	} error_handler;		/**< Error handling callback */

	struct {
		hubbub_content_model model;
	} content_model;		/**< Current content model */

	bool process_cdata;		/**< Whether to process CDATA sections*/
} hubbub_tokeniser_optparams;

/* Create a hubbub tokeniser */
hubbub_error hubbub_tokeniser_create(parserutils_inputstream *input,
		hubbub_allocator_fn alloc, void *pw, 
		hubbub_tokeniser **tokeniser);
/* Destroy a hubbub tokeniser */
hubbub_error hubbub_tokeniser_destroy(hubbub_tokeniser *tokeniser);

/* Configure a hubbub tokeniser */
hubbub_error hubbub_tokeniser_setopt(hubbub_tokeniser *tokeniser,
		hubbub_tokeniser_opttype type,
		hubbub_tokeniser_optparams *params);

/* Insert a chunk of data into the input stream */
hubbub_error hubbub_tokeniser_insert_chunk(hubbub_tokeniser *tokeniser,
		const uint8_t *data, size_t len);

/* Process remaining data in the input stream */
hubbub_error hubbub_tokeniser_run(hubbub_tokeniser *tokeniser);

#endif