Factor out socket/port parsing for connecting database

Almost same code was used in three DBIs, so let's share it.

Signed-off-by: Michal Čihař <michal@cihar.com>