Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic implementation of a Digg input
- Loading branch information
Showing
14 changed files
with
375 additions
and
199 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,122 +1,16 @@ | ||
#include "host.h" | ||
#include "input.h" | ||
|
||
#include <QStringList> | ||
#include <iostream> | ||
#include "glwidget.h" | ||
|
||
using namespace std; | ||
|
||
void Input::start(void) { | ||
proc = new QProcess( this ); | ||
void Input::startProcessing() { | ||
|
||
proc->setProcessChannelMode(QProcess::SeparateChannels); | ||
|
||
connect( proc, SIGNAL(readyReadStandardOutput()), this, SLOT(readFromStdout()) ); | ||
connect( proc, SIGNAL(readyReadStandardError()), this, SLOT(readFromStderr()) ); | ||
QString cmd = getCommandString(); | ||
std::cout << "[" << domain.toStdString() << "] exec[" << cmd.toStdString() << "]" << std::endl; | ||
proc->start( getCommandString() ); | ||
proc->waitForStarted(); | ||
} | ||
|
||
void Input::endProcessing() { | ||
|
||
void Input::end( void ) { | ||
cout << "Terminating[" << domain.toStdString() << "]" << endl; | ||
proc->terminate(); | ||
proc->waitForFinished(2000); | ||
if( proc->state() == QProcess::Running ) { | ||
cout << "Killing[" << domain.toStdString() << "]" << endl; | ||
proc->kill(); | ||
} | ||
|
||
} | ||
|
||
QString Input::getCommandString() { | ||
QStringList cmd; | ||
cmd << "ssh"; | ||
cmd << user + "@" + host; | ||
|
||
if( !port.isEmpty() ) | ||
cmd << "-p" << port; | ||
|
||
cmd << command << args; | ||
|
||
return cmd.join(" "); | ||
} | ||
|
||
void Input::readFromStdout(void ) { | ||
char buf[2048]; | ||
|
||
proc->setReadChannel(QProcess::StandardOutput); | ||
|
||
while( proc->canReadLine() ) { | ||
qint64 len = proc->readLine(buf, sizeof(buf)); | ||
if( len != -1 ) { | ||
|
||
// QString apache_pattern("([\\d\\S.]+) (\\S+) (\\S+) \\[([^\\]]+)\\] \"([^\"]*)\" (\\d+) ([\\S]+) \"([^\"]+)\" \"([^\"]+)\""); | ||
QRegExp rx(pattern); | ||
|
||
if( rx.indexIn(buf) > -1 ) { | ||
QString url = rx.cap(1); | ||
|
||
if( url.contains(" ") ) { | ||
url = url.split(" ")[1]; | ||
} | ||
|
||
QString referrer = rx.cap(2); | ||
|
||
if( ignoreQueryParameters() ) | ||
url = url.split("?")[0]; | ||
|
||
if( !ignore.isEmpty() && url.contains( QRegExp(ignore, Qt::CaseInsensitive) ) ) { | ||
continue; | ||
} | ||
|
||
for( int i = 0; i < replacementPatterns.size(); i++ ) { | ||
url.replace( QRegExp(replacementPatterns[i]), replacementStrings[i] ); | ||
} | ||
|
||
url.replace( QRegExp("/index\\.vsp$"), "/" ); | ||
|
||
if( referrer.contains( QRegExp("http://(.*\\.)?" + domain) ) || referrer.startsWith("/") ) { | ||
referrer = referrer.split("?")[0]; | ||
|
||
for( int i = 0; i < replacementPatterns.size(); i++ ) { | ||
referrer.replace( QRegExp(replacementPatterns[i]), replacementStrings[i] ); | ||
} | ||
} | ||
|
||
referrer.replace( QRegExp("^http://(.*\\.)?" + domain), ""); | ||
bool external = false; | ||
if( referrer.contains("http://") ) { | ||
external = true; | ||
referrer.replace("http://", ""); | ||
} | ||
// std::cout << "[" << domain.toStdString() << "] " << url.toStdString() << " <- " << (const char*) referrer.toLatin1() << std::endl; | ||
|
||
if( url == referrer ) { | ||
referrer = ""; | ||
} | ||
|
||
gl->addRelation(this, url, referrer, external); | ||
|
||
} else { | ||
std::cout << "[" << domain.toStdString() << "] UNKNOWN [" << buf << "]" << std::endl; | ||
} | ||
// glWidget->addRandomElement(); | ||
} | ||
} | ||
} | ||
|
||
void Input::readFromStderr(void) { | ||
char buf[2048]; | ||
std::cout << "STDERR!\n"; | ||
proc->setReadChannel(QProcess::StandardError); | ||
|
||
while( proc->canReadLine() ) { | ||
qint64 len = proc->readLine(buf, sizeof(buf)); | ||
if( len != -1 ) { | ||
std::cout << "[" << domain.toStdString() << "] STDERR [" << buf << "]" << std::endl; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.