From e31236a08f29b0590eecbf266bebf396b652071a Mon Sep 17 00:00:00 2001
From: ck <qt-info@nokia.com>
Date: Tue, 12 Jan 2010 13:40:38 +0100
Subject: [PATCH] Maemo: Patch Net7 library to enable continuous reading.

---
 src/libs/3rdparty/net7ssh/src/ne7ssh.cpp      | 30 +++++++++++++++++++
 src/libs/3rdparty/net7ssh/src/ne7ssh.h        | 11 +++++++
 .../3rdparty/net7ssh/src/ne7ssh_channel.cpp   |  4 +++
 .../3rdparty/net7ssh/src/ne7ssh_channel.h     |  3 ++
 .../net7ssh/src/ne7ssh_connection.cpp         |  5 ++++
 .../3rdparty/net7ssh/src/ne7ssh_connection.h  |  3 ++
 .../qt-maemo/maemosshconnection.cpp           | 13 ++++----
 .../qt4projectmanager/qt-maemo/qt-maemo.pri   |  7 ++---
 8 files changed, 67 insertions(+), 9 deletions(-)

diff --git a/src/libs/3rdparty/net7ssh/src/ne7ssh.cpp b/src/libs/3rdparty/net7ssh/src/ne7ssh.cpp
index 0680e5f28cc..d0d113c3245 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 79fab02edf3..853d8b08ffe 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 eec29c86c85..c15f638f6fb 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 75d9167327c..5cd570fa3c3 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 b648822bc6d..7512e1a3eda 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 694449ce3e8..d2544cab273 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 ffaf13c7b5b..def3119a3f6 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 5db9c5e678a..2a7e63f88a8 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 \
-- 
GitLab