diff --git a/src/libs/3rdparty/net7ssh/src/ne7ssh.cpp b/src/libs/3rdparty/net7ssh/src/ne7ssh.cpp index 0680e5f28cc108cb90bd1238c588ad8bfac2ba66..d0d113c3245748f3be58757c9cf5b53795cf6b29 100644 --- a/src/libs/3rdparty/net7ssh/src/ne7ssh.cpp +++ b/src/libs/3rdparty/net7ssh/src/ne7ssh.cpp @@ -15,6 +15,7 @@ ***************************************************************************/ #include <signal.h> +#include <string.h> #include <time.h> #include <botan/init.h> #include <botan/auto_rng.h> @@ -634,6 +635,35 @@ const char* ne7ssh::read (int channel, bool do_lock) return 0; } +char *ne7ssh::readAndReset(int channel, char *(*alloc)(size_t)) +{ + if (channel == -1) + { + errs->push (-1, "Bad channel: %i specified for reading.", channel); + return 0; + } + if (!lock()) return 0; + char *buffer = 0; + for (uint32 i = 0; i < conCount; i++) + { + SecureVector<Botan::byte> data; + if (channel == connections[i]->getChannelNo()) + { + data = connections[i]->getReceived(); + if (data.size()) + { + buffer = alloc(connections[i]->getReceived().size()); + strcpy(buffer, reinterpret_cast<char*>(connections[i]->getReceived().begin())); + connections[i]->resetReceiveBuffer(); + } + break; + } + } + if (!unlock()) return false; + return buffer; +} + + void* ne7ssh::readBinary (int channel) { uint32 i; diff --git a/src/libs/3rdparty/net7ssh/src/ne7ssh.h b/src/libs/3rdparty/net7ssh/src/ne7ssh.h index 79fab02edf367757c1bcc98cdfc709397ce5fd20..853d8b08ffe5fca7dceda626138b3b5618ce570f 100644 --- a/src/libs/3rdparty/net7ssh/src/ne7ssh.h +++ b/src/libs/3rdparty/net7ssh/src/ne7ssh.h @@ -245,6 +245,17 @@ class SSH_EXPORT ne7ssh */ const char* read (int channel, bool do_lock=true); + /** + * Reads all data from receiving buffer on specified channel into a newly + * allocated buffer and empties the receive buffer afterwards. + * @param channel Channel to read data on. + * @param alloc Pointer to function allocating the memory for the buffer + * to return. + * @return Returns string read from receiver buffer or 0 if buffer is empty. + * Freeing the returned buffer is the user's responsibility. + */ + char* readAndReset (int channel, char* (*alloc)(size_t)); + /** * Reads all data from receiving buffer on specified channel. Returns pointer to void. Together with getReceivedSize and sendCmd can be used to read remote files. * @param channel Channel to read data on. diff --git a/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.cpp b/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.cpp index eec29c86c853a2af7f0f6f4ac5200576e4dbeabd..c15f638f6fbe2acee0d1e7dd11a25b0ed96cacdb 100644 --- a/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.cpp +++ b/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.cpp @@ -450,3 +450,7 @@ bool ne7ssh_channel::adjustRecvWindow (int bufferSize) return true; } +void ne7ssh_channel::resetReceiveBuffer() +{ + inBuffer.clear(); +} diff --git a/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.h b/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.h index 75d9167327c920b6e46ba6bc50dc821b6d576c6e..5cd570fa3c3ad3c4bd60e1124e15c39c70dc7436 100644 --- a/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.h +++ b/src/libs/3rdparty/net7ssh/src/ne7ssh_channel.h @@ -220,6 +220,9 @@ class ne7ssh_channel * @return Size of the send window. */ uint32 getSendWindow () { return windowSend; } + + /** Empties the receive buffer. */ + void resetReceiveBuffer(); }; #endif diff --git a/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.cpp b/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.cpp index b648822bc6d2e9f31db4966aa84b752fe07c9c4d..7512e1a3eda9c43087f2a29b44846201d0153443 100644 --- a/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.cpp +++ b/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.cpp @@ -338,3 +338,8 @@ bool ne7ssh_connection::isSftpActive () if (sftp) return true; else return false; } + +void ne7ssh_connection::resetReceiveBuffer() +{ + channel->resetReceiveBuffer(); +} diff --git a/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.h b/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.h index 694449ce3e8a1ee7e8a9de2cb7a20d0bb0642240..d2544cab2734ce1731f724428ff7b7bfa9bb4033 100644 --- a/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.h +++ b/src/libs/3rdparty/net7ssh/src/ne7ssh_connection.h @@ -228,6 +228,9 @@ class ne7ssh_connection * @return True if SFTP subsystem is active, otherwise false. */ bool isSftpActive (); + + /** Empties this connection's receive buffer. */ + void resetReceiveBuffer(); }; #endif diff --git a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp index ffaf13c7b5b166d8716824a8ea0fda3ea67a82d7..def3119a3f6e9ac8af940b81c14db33ea0db9a8e 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp +++ b/src/plugins/qt4projectmanager/qt-maemo/maemosshconnection.cpp @@ -45,7 +45,7 @@ #include "maemodeviceconfigurations.h" -#include "/opt/ne7sshModified/include/ne7ssh.h" +#include <ne7ssh.h> #include <QtCore/QFileInfo> #include <QtCore/QStringBuilder> @@ -57,6 +57,11 @@ namespace Qt4ProjectManager { namespace Internal { namespace { ne7ssh ssh; + + char *alloc(size_t n) + { + return new char[n]; + } } // TODO: Which encoding to use for file names? Unicode? Latin1? ASCII? @@ -127,13 +132,11 @@ void MaemoInteractiveSshConnection::runCommand(const QString &command) const char * const error = lastError(); if (error) throw MaemoSshException(tr("SSH error: %1").arg(error)); - ssh.lock(); - const char * output = ssh.read(channel(), false); + const char * output = ssh.readAndReset(channel(), alloc); if (output) { emit remoteOutput(QString::fromUtf8(output)); - ssh.resetInput(channel(), false); + delete[] output; } - ssh.unlock(); } while (!done && !stopRequested()); } diff --git a/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri b/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri index 5db9c5e678ae1d8c998fe8ac0535cfa73da84353..2a7e63f88a84950b092d26979ed17df2a2b4a2ae 100644 --- a/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri +++ b/src/plugins/qt4projectmanager/qt-maemo/qt-maemo.pri @@ -2,10 +2,9 @@ SUPPORT_QT_MAEMO = $$(QTCREATOR_WITH_MAEMO) !isEmpty(SUPPORT_QT_MAEMO) { message("Adding experimental support for Qt/Maemo applications.") DEFINES += QTCREATOR_WITH_MAEMO - - # DEFINES += USE_SSH_LIB - # LIBS += -L/opt/ne7sshModified/lib/ \ - # -lnet7ssh +# DEFINES += USE_SSH_LIB +# INCLUDEPATH += $$PWD/../../../libs/3rdparty/net7ssh/src +# LIBS += -L$$PWD/../../../../lib/qtcreator -lNet7ssh HEADERS += $$PWD/maemorunconfiguration.h \ $$PWD/maemomanager.h \ $$PWD/maemotoolchain.h \