772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen#ifndef FTS_PARSER_H
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen#define FTS_PARSER_H
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainenstruct message_block;
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainenstruct mail_user;
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitovstruct fts_parser_context {
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov /* Can't be NULL */
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov struct mail_user *user;
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov /* Can't be NULL */
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov const char *content_type;
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov const char *content_disposition;
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov};
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainenstruct fts_parser_vfuncs {
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitov struct fts_parser *(*try_init)(struct fts_parser_context *parser_context);
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen void (*more)(struct fts_parser *parser, struct message_block *block);
72d301f5751986396533088b769a9e74735a467cSergey Kitov int (*deinit)(struct fts_parser *parser, const char **retriable_err_msg_r);
3ad57148af55e45cc45401162d3460ed0b237a10Timo Sirainen void (*unload)(void);
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen};
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainenstruct fts_parser {
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainen struct fts_parser_vfuncs v;
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainen buffer_t *utf8_output;
8e1eaf849ce4668c0941338e3e3671db159da575Sergey Kitov bool may_need_retry;
8e1eaf849ce4668c0941338e3e3671db159da575Sergey Kitov char *retriable_error_msg;
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainen};
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainen
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainenextern struct fts_parser_vfuncs fts_parser_html;
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainenextern struct fts_parser_vfuncs fts_parser_script;
ce87b647a0418ec4a6f4e860a9c918b2331ab353Timo Sirainenextern struct fts_parser_vfuncs fts_parser_tika;
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen
43f4e550efe7afa72aab3a7ded7ad7ce606526fbSergey Kitovbool fts_parser_init(struct fts_parser_context *parser_context,
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen struct fts_parser **parser_r);
4d27f95c76bd008bb38f9c442567046da2b6ce14Timo Sirainenstruct fts_parser *fts_parser_text_init(void);
4d27f95c76bd008bb38f9c442567046da2b6ce14Timo Sirainen
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainen/* The parser is initially called with message body blocks. Once message is
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainen finished, it's still called with incoming size=0 while the parser increases
ecc5a1a440799a0966c26da956f5d6e2d8073e03Timo Sirainen it to non-zero. */
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainenvoid fts_parser_more(struct fts_parser *parser, struct message_block *block);
8c93c82c97d7c125838344df7fdcb9df1b77f9a3Timo Sirainen/* Returns 1 if ok, 0 if the parsing should be retried, -1 if error.
8c93c82c97d7c125838344df7fdcb9df1b77f9a3Timo Sirainen If 0 is returned, the retriable_err_msg_r is set, which should be logged
8c93c82c97d7c125838344df7fdcb9df1b77f9a3Timo Sirainen as error if no retrying is performed. */
72d301f5751986396533088b769a9e74735a467cSergey Kitovint fts_parser_deinit(struct fts_parser **parser, const char **retriable_err_msg_r);
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen
3ad57148af55e45cc45401162d3460ed0b237a10Timo Sirainenvoid fts_parsers_unload(void);
3ad57148af55e45cc45401162d3460ed0b237a10Timo Sirainen
772120713c176bde8c932b3fb4c413d223741fcdTimo Sirainen#endif