1 /*
2  * This file is part of Hubbub.
3  * Licensed under the MIT License,
4  *                http://www.opensource.org/licenses/mit-license.php
5  * Copyright 2007 John-Mark Bell <jmb@netsurf-browser.org>
6  */
7 
8 #ifndef hubbub_tokeniser_tokeniser_h_
9 #define hubbub_tokeniser_tokeniser_h_
10 
11 #include <stdbool.h>
12 #include <inttypes.h>
13 
14 #include <hubbub/errors.h>
15 #include <hubbub/functypes.h>
16 #include <hubbub/types.h>
17 
18 #include <parserutils/input/inputstream.h>
19 
20 typedef struct hubbub_tokeniser hubbub_tokeniser;
21 
22 /**
23  * Hubbub tokeniser option types
24  */
25 typedef enum hubbub_tokeniser_opttype {
26 	HUBBUB_TOKENISER_TOKEN_HANDLER,
27 	HUBBUB_TOKENISER_ERROR_HANDLER,
28 	HUBBUB_TOKENISER_CONTENT_MODEL,
29 	HUBBUB_TOKENISER_PROCESS_CDATA,
30 	HUBBUB_TOKENISER_PAUSE
31 } hubbub_tokeniser_opttype;
32 
33 /**
34  * Hubbub tokeniser option parameters
35  */
36 typedef union hubbub_tokeniser_optparams {
37 	struct {
38 		hubbub_token_handler handler;
39 		void *pw;
40 	} token_handler;		/**< Token handling callback */
41 
42 	struct {
43 		hubbub_error_handler handler;
44 		void *pw;
45 	} error_handler;		/**< Error handling callback */
46 
47 	struct {
48 		hubbub_content_model model;
49 	} content_model;		/**< Current content model */
50 
51 	bool process_cdata;		/**< Whether to process CDATA sections*/
52 
53 	bool pause_parse;		/**< Pause parsing */
54 } hubbub_tokeniser_optparams;
55 
56 /* Create a hubbub tokeniser */
57 hubbub_error hubbub_tokeniser_create(parserutils_inputstream *input,
58 		hubbub_tokeniser **tokeniser);
59 /* Destroy a hubbub tokeniser */
60 hubbub_error hubbub_tokeniser_destroy(hubbub_tokeniser *tokeniser);
61 
62 /* Configure a hubbub tokeniser */
63 hubbub_error hubbub_tokeniser_setopt(hubbub_tokeniser *tokeniser,
64 		hubbub_tokeniser_opttype type,
65 		hubbub_tokeniser_optparams *params);
66 
67 /* Insert a chunk of data into the input stream */
68 hubbub_error hubbub_tokeniser_insert_chunk(hubbub_tokeniser *tokeniser,
69 		const uint8_t *data, size_t len);
70 
71 /* Process remaining data in the input stream */
72 hubbub_error hubbub_tokeniser_run(hubbub_tokeniser *tokeniser);
73 
74 #endif
75 
76