summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMorten Sorvig <morten.sorvig@nokia.com>2010-02-05 07:26:22 +0100
committerMorten Sorvig <morten.sorvig@nokia.com>2010-02-05 07:26:22 +0100
commit4aea19501732e79fb236d3d0bb39daa07283fc49 (patch)
tree1f03bbf0f168fbcebac7d214d3e29e2bfd63c1d2
parent4734d63bd4549f9d51a8484f5ea6aec5e1953861 (diff)
Fix NaCl directory detection in the demo server.
This should make the demo server actually usable, so update the documentation as well.
-rw-r--r--readme-nacl10
-rw-r--r--tools/nacldemoserver/httpserver.cpp38
2 files changed, 30 insertions, 18 deletions
diff --git a/readme-nacl b/readme-nacl
index 41ed0136a9..4b7f04bbb2 100644
--- a/readme-nacl
+++ b/readme-nacl
@@ -31,6 +31,12 @@ Test (sel_ldr)
Run: sel_ldr examples/widgets/wiggly/wiggly
Test (browser)
-For now, use one of the included examples as a template and replace the executable. The
-voronoy example works well for this.
+Use tools/nacldemoserver to browse the examples. Nacldemoserver needs to be compiled
+for the host system - use a different Qt buld, not the NaCl one:
+
+cd tools/nacldemoserver
+/path/to/other/qmake -nocache
+make
+./nacldemoserver
+Point your browser to http://localhost:5103/
diff --git a/tools/nacldemoserver/httpserver.cpp b/tools/nacldemoserver/httpserver.cpp
index c64c733842..fb5382bd31 100644
--- a/tools/nacldemoserver/httpserver.cpp
+++ b/tools/nacldemoserver/httpserver.cpp
@@ -212,8 +212,8 @@ void Server::addRootPath(const QString &path)
void Server::serveResponseFromPath(HttpResponse *response, QString path)
{
- qDebug() << "";
- qDebug() << "htmlForPath" << path;
+// qDebug() << "";
+// qDebug() << "htmlForPath" << path;
QByteArray html;
html += "<H2>Qt for Google Native Client Demo Browser </H2>";
// special case for /: serve the root paths
@@ -239,8 +239,14 @@ void Server::serveResponseFromPath(HttpResponse *response, QString path)
// is the path pointing directly to a nacl file?
bool isNaClFile = (QFile::exists(canonicalPath) && QFileInfo(canonicalPath).isDir() == false);
- // is the path a leaf directroy containing a nacl executable?
- bool isNaClDir = (QDir(canonicalPath).entryList(QDir::Dirs).count() <= 2);
+ // does the the path a leaf directroy containing a nacl executable?
+ bool isdir = QFileInfo(canonicalPath).isDir();
+ QString leafName = QDir(canonicalPath).dirName();
+ bool hasNaclFile = QFile::exists(canonicalPath + "/" + leafName);
+ bool isNaClDir = isdir && hasNaclFile;
+
+// qDebug() << "canonical path" << canonicalPath;
+// qDebug() << "isNaClFile" << isNaClFile << "isNaClDir" << isNaClDir;
// serve the file, a combined tree/nacl area view or a dir tree view.
if (isNaClFile) {
@@ -252,7 +258,7 @@ void Server::serveResponseFromPath(HttpResponse *response, QString path)
} else if (isNaClDir) {
// chop of the last directory in the path
QStringList pathParts = path.split('/', QString::SkipEmptyParts);
- qDebug() << "nacl dir" << path << pathParts;
+ // qDebug() << "nacl dir" << path << pathParts;
QString last = pathParts.takeLast();
QString newPath = pathParts.join("/");
@@ -296,33 +302,33 @@ QString Server::findCanonicalPath(QString path)
if (path.startsWith("/"))
path.remove(0,1);
- qDebug() << "path" << path;
+ // qDebug() << "path" << path;
// path should loook like rootPath/foo/bar
int firstSlash = path.indexOf('/');
if (firstSlash == -1)
return canonicalPath;
- qDebug() << "first slash at" << firstSlash;
+ // qDebug() << "first slash at" << firstSlash;
// for security, test that the subpath is a proper subpath
// of one of the root paths.
QString rootPathCandidate = path.mid(0, firstSlash);
QString subPath = path.mid(firstSlash);
- qDebug() << "rootPathCandidate" << rootPathCandidate;
- qDebug() << "subPath" << subPath;
+ // qDebug() << "rootPathCandidate" << rootPathCandidate;
+ // qDebug() << "subPath" << subPath;
foreach (const QString &rootPath, rootPaths) {
- qDebug() << "test" << rootPath << QDir(rootPath).dirName() << rootPathCandidate ;
+ // qDebug() << "test" << rootPath << QDir(rootPath).dirName() << rootPathCandidate ;
if (QDir(rootPath).dirName() == rootPathCandidate){
QString canonicalPathCandidate = QDir(rootPath + subPath).canonicalPath();
- qDebug() << "canonicalPathCandidate" << canonicalPathCandidate;
+ // qDebug() << "canonicalPathCandidate" << canonicalPathCandidate;
if (QDir().exists(canonicalPathCandidate))
canonicalPath = canonicalPathCandidate;
}
}
- qDebug() << "canonical path" << canonicalPath;
+ // qDebug() << "canonical path" << canonicalPath;
return canonicalPath;
}
@@ -335,7 +341,7 @@ QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path, QString
if (path.endsWith('/') == false)
path.append("/");
- qDebug() << "link path is" << path;
+// qDebug() << "link path is" << path;
html.append("<a href=" + linkPrefix + "../>..</a><br>");
QDirIterator it(canonicalPath);
@@ -352,7 +358,7 @@ QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path, QString
) {
QDir dir(it.filePath());
QString name = dir.dirName();
- qDebug() << "payh is" << path;
+ // qDebug() << "payh is" << path;
html.append("<a href=" + linkPrefix + name + "/>" + name + "</a><br>");
}
}
@@ -362,7 +368,7 @@ QByteArray Server::htmlLinksForPath(QString canonicalPath, QString path, QString
QByteArray Server::instantiateNaclHtmlContent(QString appName)
{
- qDebug() << "instantiateNaclHtmlContent" << appName;
+// qDebug() << "instantiateNaclHtmlContent" << appName;
QByteArray html = naclHtmlContent;
html.replace("NEXE", appName.toUtf8());
return html;
@@ -405,7 +411,7 @@ void Server::saveDemoFiles()
foreach(QString rootPath, rootPaths) {
QString saveRootPath = savePath + "/" + QDir(rootPath).dirName();
- qDebug() << "save" << saveRootPath;
+ // qDebug() << "save" << saveRootPath;
QDir().mkpath(saveRootPath);
saveDirectory(rootPath, saveRootPath);
}