Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  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-8 John-Mark Bell <jmb@netsurf-browser.org>
  6.  */
  7.  
  8. #ifndef hubbub_parser_h_
  9. #define hubbub_parser_h_
  10.  
  11. #ifdef __cplusplus
  12. extern "C"
  13. {
  14. #endif
  15.  
  16. #include <stdbool.h>
  17. #include <inttypes.h>
  18.  
  19. #include <hubbub/errors.h>
  20. #include <hubbub/functypes.h>
  21. #include <hubbub/tree.h>
  22. #include <hubbub/types.h>
  23.  
  24. typedef struct hubbub_parser hubbub_parser;
  25.  
  26. /**
  27.  * Hubbub parser option types
  28.  */
  29. typedef enum hubbub_parser_opttype {
  30.         HUBBUB_PARSER_TOKEN_HANDLER,
  31.         HUBBUB_PARSER_ERROR_HANDLER,
  32.         HUBBUB_PARSER_CONTENT_MODEL,
  33.         HUBBUB_PARSER_TREE_HANDLER,
  34.         HUBBUB_PARSER_DOCUMENT_NODE,
  35.         HUBBUB_PARSER_ENABLE_SCRIPTING,
  36.         HUBBUB_PARSER_PAUSE
  37. } hubbub_parser_opttype;
  38.  
  39. /**
  40.  * Hubbub parser option parameters
  41.  */
  42. typedef union hubbub_parser_optparams {
  43.         struct {
  44.                 hubbub_token_handler handler;
  45.                 void *pw;
  46.         } token_handler;                /**< Token handling callback */
  47.  
  48.         struct {
  49.                 hubbub_error_handler handler;
  50.                 void *pw;
  51.         } error_handler;                /**< Error handling callback */
  52.  
  53.         struct {
  54.                 hubbub_content_model model;
  55.         } content_model;                /**< Current content model */
  56.  
  57.         hubbub_tree_handler *tree_handler;      /**< Tree handling callbacks */
  58.  
  59.         void *document_node;            /**< Document node */
  60.  
  61.         bool enable_scripting;          /**< Whether to enable scripting */
  62.  
  63.         bool pause_parse;               /**< Pause parsing */
  64. } hubbub_parser_optparams;
  65.  
  66. /* Create a hubbub parser */
  67. hubbub_error hubbub_parser_create(const char *enc, bool fix_enc,
  68.                 hubbub_allocator_fn alloc, void *pw, hubbub_parser **parser);
  69. /* Destroy a hubbub parser */
  70. hubbub_error hubbub_parser_destroy(hubbub_parser *parser);
  71.  
  72. /* Configure a hubbub parser */
  73. hubbub_error hubbub_parser_setopt(hubbub_parser *parser,
  74.                 hubbub_parser_opttype type,
  75.                 hubbub_parser_optparams *params);
  76.  
  77. /* Pass a chunk of data to a hubbub parser for parsing */
  78. /* This data is encoded in the input charset */
  79. hubbub_error hubbub_parser_parse_chunk(hubbub_parser *parser,
  80.                 const uint8_t *data, size_t len);
  81.  
  82. /**
  83.  * Insert a chunk of data into a hubbub parser input stream
  84.  *
  85.  * This data is encoded in the input charset
  86.  *
  87.  * Inserts the given data into the input stream ready for parsing but
  88.  * does not cause any additional processing of the input. This is
  89.  * useful to allow hubbub callbacks to add computed data to the input.
  90.  *
  91.  * \param parser  Parser instance to use
  92.  * \param data    Data to parse (encoded in the input charset)
  93.  * \param len     Length, in bytes, of data
  94.  * \return HUBBUB_OK on success, appropriate error otherwise
  95.  */
  96. hubbub_error hubbub_parser_insert_chunk(hubbub_parser *parser,
  97.                                         const uint8_t *data, size_t len);
  98. /* Inform the parser that the last chunk of data has been parsed */
  99. hubbub_error hubbub_parser_completed(hubbub_parser *parser);
  100.  
  101. /* Read the document charset */
  102. const char *hubbub_parser_read_charset(hubbub_parser *parser,
  103.                 hubbub_charset_source *source);
  104.  
  105. #ifdef __cplusplus
  106. }
  107. #endif
  108.  
  109. #endif
  110.  
  111.