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 libdom.
  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 dom_hubbub_parser_h_
  9. #define dom_hubbub_parser_h_
  10.  
  11. #include <stddef.h>
  12. #include <inttypes.h>
  13.  
  14. #include <hubbub/errors.h>
  15.  
  16. #include <dom/dom.h>
  17.  
  18. #include "errors.h"
  19.  
  20. /**
  21.  * Type of script completion function
  22.  */
  23. typedef dom_hubbub_error (*dom_script)(void *ctx, struct dom_node *node);
  24.  
  25. typedef struct dom_hubbub_parser dom_hubbub_parser;
  26.  
  27. /* The encoding source of the document */
  28. typedef enum dom_hubbub_encoding_source {
  29.         DOM_HUBBUB_ENCODING_SOURCE_HEADER,
  30.         DOM_HUBBUB_ENCODING_SOURCE_DETECTED,
  31.         DOM_HUBBUB_ENCODING_SOURCE_META
  32. } dom_hubbub_encoding_source;
  33.  
  34. /* The recommended way to use the parser is:
  35.  *
  36.  * dom_hubbub_parser_create(...);
  37.  * dom_hubbub_parser_parse_chunk(...);
  38.  * call _parse_chunk for all chunks of data
  39.  *
  40.  * After you have parsed the data,
  41.  *
  42.  * dom_hubbub_parser_completed(...);
  43.  * dom_hubbub_parser_destroy(...);
  44.  *
  45.  * Clients must ensure that these function calls above are called in
  46.  * the order shown. dom_hubbub_parser_create() will pass the ownership
  47.  * of the document to the client. After that, the parser should be destroyed.
  48.  * The client must not call any method of this parser after destruction.
  49.  */
  50.  
  51. /**
  52.  * Parameter block for dom_hubbub_parser_create
  53.  */
  54. typedef struct dom_hubbub_parser_params {
  55.         const char *enc; /**< Source charset, or NULL */
  56.         bool fix_enc; /**< Whether fix the encoding */
  57.  
  58.         bool enable_script; /**< Whether scripting should be enabled. */
  59.         dom_script script; /**< Script callback function */
  60.  
  61.         dom_msg msg; /**< Informational message function */
  62.         void *ctx; /**< Pointer to client-specific private data */
  63.  
  64.         /** default action fetcher function */
  65.         dom_events_default_action_fetcher daf;
  66. } dom_hubbub_parser_params;
  67.  
  68. /* Create a Hubbub parser instance */
  69. dom_hubbub_error dom_hubbub_parser_create(dom_hubbub_parser_params *params,
  70.                 dom_hubbub_parser **parser,
  71.                 dom_document **document);
  72.  
  73. /* Destroy a Hubbub parser instance */
  74. void dom_hubbub_parser_destroy(dom_hubbub_parser *parser);
  75.  
  76. /* Parse a chunk of data */
  77. dom_hubbub_error dom_hubbub_parser_parse_chunk(dom_hubbub_parser *parser,
  78.                 const uint8_t *data, size_t len);
  79.  
  80. /* insert data into the parse stream but do not parse it */
  81. dom_hubbub_error dom_hubbub_parser_insert_chunk(dom_hubbub_parser *parser,
  82.                 const uint8_t *data, size_t length);
  83.  
  84. /* Notify parser that datastream is empty */
  85. dom_hubbub_error dom_hubbub_parser_completed(dom_hubbub_parser *parser);
  86.  
  87. /* Retrieve the document's encoding */
  88. const char *dom_hubbub_parser_get_encoding(dom_hubbub_parser *parser,
  89.                 dom_hubbub_encoding_source *source);
  90.  
  91. /**
  92.  * Set the Parse pause state.
  93.  *
  94.  * \param parser  The parser object
  95.  * \param pause   The pause state to set.
  96.  * \return DOM_HUBBUB_OK on success,
  97.  *         DOM_HUBBUB_HUBBUB_ERR | <hubbub_error> on failure
  98.  */
  99. dom_hubbub_error dom_hubbub_parser_pause(dom_hubbub_parser *parser, bool pause);
  100.  
  101. #endif
  102.