Add session invalidate callbacks

If a stateful session manager supports it, a way is provided for
registering callback functions called whenever a session is invalidated.
This can be handy e.g. for cleaning up resources stored in a session.