| 58 | } |
| 59 | |
| 60 | bool CChannelSSH::open(OpenMode mode) |
| 61 | { |
| 62 | int nRet = 0; |
| 63 | QString szErr; |
| 64 | |
| 65 | if(!m_pParameter) { |
| 66 | qCritical(log) << "The parameter is null"; |
| 67 | } |
| 68 | Q_ASSERT(m_pParameter); |
| 69 | |
| 70 | bool bRet = QIODevice::open(mode); |
| 71 | if(!bRet) |
| 72 | return bRet; |
| 73 | |
| 74 | m_Session = ssh_new(); |
| 75 | if(NULL == m_Session) |
| 76 | { |
| 77 | szErr = tr("SSH failed: ssh_new."); |
| 78 | qCritical(log) << szErr; |
| 79 | setErrorString(szErr); |
| 80 | return false; |
| 81 | } |
| 82 | |
| 83 | do{ |
| 84 | struct ssh_callbacks_struct cb; |
| 85 | memset(&cb, 0, sizeof(struct ssh_callbacks_struct)); |
| 86 | cb.userdata = this; |
| 87 | cb.log_function = cb_log; |
| 88 | ssh_callbacks_init(&cb); |
| 89 | ssh_set_callbacks(m_Session, &cb); |
| 90 | ssh_set_log_level(SSH_LOG_TRACE); |
| 91 | |
| 92 | /* |
| 93 | int value = 1; |
| 94 | ssh_options_set(m_Session, SSH_OPTIONS_NODELAY, (const void*)&value);//*/ |
| 95 | |
| 96 | /* |
| 97 | See: [ssh_options_set()](https://api.libssh.org/stable/group__libssh__session.html#ga7a801b85800baa3f4e16f5b47db0a73d) |
| 98 | SSH_LOG_NOLOG: No logging |
| 99 | SSH_LOG_WARNING: Only warnings |
| 100 | SSH_LOG_PROTOCOL: High level protocol information |
| 101 | SSH_LOG_PACKET: Lower level protocol information, packet level |
| 102 | SSH_LOG_FUNCTIONS: Every function path The default is SSH_LOG_NOLOG. |
| 103 | */ |
| 104 | int verbosity = SSH_LOG_NOLOG; |
| 105 | ssh_options_set(m_Session, SSH_OPTIONS_LOG_VERBOSITY, &verbosity); |
| 106 | |
| 107 | auto &net = m_pParameter->m_Net; |
| 108 | if(net.GetHost().isEmpty()) { |
| 109 | szErr = tr("SSH failed: the server is empty"); |
| 110 | qCritical(log) << szErr; |
| 111 | setErrorString(szErr); |
| 112 | break; |
| 113 | } else { |
| 114 | nRet = ssh_options_set(m_Session, SSH_OPTIONS_HOST, |
| 115 | net.GetHost().toStdString().c_str()); |
| 116 | if(nRet) { |
| 117 | szErr = tr("SSH failed: Set host fail. host:") |
no test coverage detected