1 #ifndef SMTP_COMMAND_PARSER_H
2 #define SMTP_COMMAND_PARSER_H
3 
4 #include "smtp-command.h"
5 
6 /* FIXME: drop unused */
7 enum smtp_command_parse_error {
8 	SMTP_COMMAND_PARSE_ERROR_NONE = 0,           /* no error */
9 	SMTP_COMMAND_PARSE_ERROR_BROKEN_STREAM,      /* stream error */
10 	SMTP_COMMAND_PARSE_ERROR_BROKEN_COMMAND,     /* unrecoverable generic error */
11 	SMTP_COMMAND_PARSE_ERROR_BAD_COMMAND,        /* recoverable generic error */
12 	SMTP_COMMAND_PARSE_ERROR_LINE_TOO_LONG,      /* stream error */
13 	SMTP_COMMAND_PARSE_ERROR_DATA_TOO_LARGE      /* data too large (fatal) */
14 };
15 
16 struct smtp_command_parser *
17 smtp_command_parser_init(struct istream *input,
18 			 const struct smtp_command_limits *limits)
19 	ATTR_NULL(2);
20 void smtp_command_parser_deinit(struct smtp_command_parser **_parser);
21 
22 void smtp_command_parser_set_stream(struct smtp_command_parser *parser,
23 	struct istream *input);
24 
25 /* Returns 1 if a command was returned, 0 if more data is needed, -1 on error,
26    -2 if disconnected in SMTP_COMMAND_PARSE_STATE_INIT state. -2 is mainly for
27    unit tests - it can normally be treated the same as -1. */
28 int smtp_command_parse_next(struct smtp_command_parser *parser,
29 			    const char **cmd_name_r, const char **cmd_params_r,
30 			    enum smtp_command_parse_error *error_code_r, const char **error_r);
31 
32 struct istream *
33 smtp_command_parse_data_with_size(struct smtp_command_parser *parser,
34 	uoff_t size);
35 struct istream *
36 smtp_command_parse_data_with_dot(struct smtp_command_parser *parser);
37 bool smtp_command_parser_pending_data(struct smtp_command_parser *parser);
38 
39 /* Returns the same as smtp_command_parse_next() */
40 int smtp_command_parse_auth_response(struct smtp_command_parser *parser,
41 			    const char **line_r, enum smtp_command_parse_error *error_code_r,
42 			    const char **error_r);
43 
44 #endif
45