-- | Open a SSH session and maybe ignore the known hosts. The next step is to authenticate.
openSession' :: String  -- ^ Hostname
             -> Integer -- ^ Port
             -> Maybe String  -- ^ Path to the known hosts (e.g. ~/.ssh/known_hosts)
             -> SimpleSSH Session
openSession' hostname port knownhostsPathM = liftIOEither $ do
  hostnameC       <- newCString hostname
  knownhostsPathC <- case knownhostsPathM of
    Nothing ->
      return nullPtr
    Just knownhostsPath ->
      newCString knownhostsPath
  let portC = fromInteger port

  res <- liftEitherC (return . Session) $ openSessionC hostnameC portC knownhostsPathC

  free hostnameC
  when (isJust knownhostsPathM) $
    free knownhostsPathC

  return res

-- | Open a SSH session. The next step is to authenticate.
openSession' :: String  -- ^ Hostname
             -> Integer -- ^ Port
             -> Maybe String  -- ^ Path to the known hosts (e.g. ~/.ssh/known_hosts)
             -> SimpleSSH Session
openSession' hostname port knownhostsPathM = liftIOEither $ do
  hostnameC       <- newCString hostname
  knownhostsPathC <- case knownhostsPathM of
    Nothing ->
      return nullPtr
    Just knownhostsPath ->
      newCString knownhostsPath
  let portC = fromInteger port

  res <- liftEitherC (return . Session) $ openSessionC hostnameC portC knownhostsPathC

  free hostnameC
  when (isJust knownhostsPathM) $
    free knownhostsPathC

  return res

-- | Open a SSH session. The next step is to authenticate.
openSession' hostname port knownhostsPathM = liftIOEither $ do
  hostnameC       <- newCString hostname
  knownhostsPathC <- case knownhostsPathM of
    Nothing ->
      return nullPtr
    Just knownhostsPath ->
      newCString knownhostsPath
  let portC = fromInteger port

  res <- liftEitherC (return . Session) $ openSessionC hostnameC portC knownhostsPathC

  free hostnameC
  when (isJust knownhostsPathM) $
    free knownhostsPathC

  return res

-- | Open a SSH session. The next step is to authenticate.