Move duplicate code into XMPPConnection

from XMPPTCPConnection and XMPPBOSHConnection.