Fix Cowboy replies
Cleanup debug messages
Support more stream events

Add support for restarting and closing XML streams.
This makes the basic communication support complete,
i.e. registration, auth, simple chat etc all work.