8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#ifndef SMTP_COMMAND_PARSER_H
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#define SMTP_COMMAND_PARSER_H
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#include "smtp-command.h"
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch/* FIXME: drop unused */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschenum smtp_command_parse_error {
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch SMTP_COMMAND_PARSE_ERROR_NONE = 0, /* no error */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch SMTP_COMMAND_PARSE_ERROR_BROKEN_STREAM, /* stream error */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch SMTP_COMMAND_PARSE_ERROR_BROKEN_COMMAND, /* unrecoverable generic error */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch SMTP_COMMAND_PARSE_ERROR_BAD_COMMAND, /* recoverable generic error */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch SMTP_COMMAND_PARSE_ERROR_LINE_TOO_LONG, /* stream error */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch SMTP_COMMAND_PARSE_ERROR_DATA_TOO_LARGE /* data too large (fatal) */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch};
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschstruct smtp_command_parser *
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschsmtp_command_parser_init(struct istream *input,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch const struct smtp_command_limits *limits)
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch ATTR_NULL(2);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschvoid smtp_command_parser_deinit(struct smtp_command_parser **_parser);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschvoid smtp_command_parser_set_stream(struct smtp_command_parser *parser,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch struct istream *input);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
4e4b3ae48b9ce1c397189c263cbd42df1b8c1d87Timo Sirainen/* Returns 1 if a command was returned, 0 if more data is needed, -1 on error,
4e4b3ae48b9ce1c397189c263cbd42df1b8c1d87Timo Sirainen -2 if disconnected in SMTP_COMMAND_PARSE_STATE_INIT state. -2 is mainly for
4e4b3ae48b9ce1c397189c263cbd42df1b8c1d87Timo Sirainen unit tests - it can normally be treated the same as -1. */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschint smtp_command_parse_next(struct smtp_command_parser *parser,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch const char **cmd_name_r, const char **cmd_params_r,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch enum smtp_command_parse_error *error_code_r, const char **error_r);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschstruct istream *
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschsmtp_command_parse_data_with_size(struct smtp_command_parser *parser,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch uoff_t size);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschstruct istream *
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschsmtp_command_parse_data_with_dot(struct smtp_command_parser *parser);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschbool smtp_command_parser_pending_data(struct smtp_command_parser *parser);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
4e4b3ae48b9ce1c397189c263cbd42df1b8c1d87Timo Sirainen/* Returns the same as smtp_command_parse_next() */
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Boschint smtp_command_parse_auth_response(struct smtp_command_parser *parser,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch const char **line_r, enum smtp_command_parse_error *error_code_r,
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch const char **error_r);
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch
8141e652481ff9db3bce36fdc1fe04c75a3ba7e3Stephan Bosch#endif