#ifndef AUTH_H #define AUTH_H #include #include #include "buffer.h" enum auth_state { auth_version, auth_ulen, auth_uname, auth_plen, auth_passwd, auth_done, auth_error_unsupported_version, auth_user_error }; struct auth_parser { void (* on_username) (struct auth_parser * parser, char * username); void (* on_password) (struct auth_parser * parser, char * password); void * data; enum auth_state state; int user_pos; char * username; char idx; char password[255]; uint8_t * verified; uint8_t remaining; }; void auth_parser_init(struct auth_parser *p); enum auth_state auth_parser_feed(struct auth_parser * p, uint8_t b); enum auth_state auth_consume(buffer * b, struct auth_parser * p, bool * errored); bool auth_is_done(enum auth_state state, bool * errored); extern const char * auth_error(const struct auth_parser *p); void auth_parser_close(struct auth_parser *p); extern int auth_marshall(buffer * b, uint8_t status); #endif