add callback mechanisms to prepare for linemode

several other state tracking changes to prevent telnet negotiation loops, assertions, etc.