Commit e31236a0 authored by ck's avatar ck
Browse files

Maemo: Patch Net7 library to enable continuous reading.

parent c5cbe37e
......@@ -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;
......
......@@ -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.
......
......@@ -450,3 +450,7 @@ bool ne7ssh_channel::adjustRecvWindow (int bufferSize)
return true;
}
void ne7ssh_channel::resetReceiveBuffer()
{
inBuffer.clear();
}
......@@ -220,6 +220,9 @@ class ne7ssh_channel
* @return Size of the send window.
*/
uint32 getSendWindow () { return windowSend; }
/** Empties the receive buffer. */
void resetReceiveBuffer();
};
#endif
......@@ -338,3 +338,8 @@ bool ne7ssh_connection::isSftpActive ()
if (sftp) return true;
else return false;
}
void ne7ssh_connection::resetReceiveBuffer()
{
channel->resetReceiveBuffer();
}
......@@ -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
......@@ -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());
}
......
......@@ -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 \
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment