From f985e90c11783cf51ee2ccc22631646175c59d19 Mon Sep 17 00:00:00 2001 From: Konrad Rosenbaum Date: Wed, 13 Feb 2013 08:59:09 +0100 Subject: [PATCH] make server parse its arguments; allow central to show urls --- central/finddlg.cpp | 18 +++- server/main.cpp | 254 +++++++++++++++++++++++++++++++++++++++++---------- 2 files changed, 223 insertions(+), 49 deletions(-) diff --git a/central/finddlg.cpp b/central/finddlg.cpp index 1f1bab4..b70735d 100644 --- a/central/finddlg.cpp +++ b/central/finddlg.cpp @@ -85,8 +85,8 @@ void FinderDialog::updateList() mmodel->setData(idx,sid); mmodel->setData(mmodel->index(i,1),si.description()); if(sid==curuuid)newcur=idx; - //descend to urls - const QList&urls=si.validUrls(); + //descend to raw urls + const QList&urls=si.rawUrls(); mmodel->insertRows(0,urls.size(),idx); mmodel->insertColumn(0,idx); for(int j=0;jsetData(sidx,uri); if(sid==curuuid && uri==cururl) newcur=sidx; + //do we descend further? + const QList&vurls=si.validUrls(urls[j]); + if(vurls.size()==1 && vurls[0]==urls[j]){ + mmodel->setData(sidx,uri,Qt::UserRole); + continue; + } + mmodel->insertRows(0,vurls.size(),sidx); + mmodel->insertColumn(0,sidx); + for(int k=0;kindex(k,0,sidx); + mmodel->setData(tidx,uri); + mmodel->setData(tidx,uri,Qt::UserRole); + } } } mtable->expandAll(); diff --git a/server/main.cpp b/server/main.cpp index 839a05e..aed4a64 100644 --- a/server/main.cpp +++ b/server/main.cpp @@ -5,10 +5,12 @@ #include #include -#include -#include -#include #include +#include +#include +#include +#include +#include #include "provider.h" @@ -16,81 +18,239 @@ #include "SInterface" #include "WServer" -int main(int ac,char**av) +//option: whether to start advertising this service +static bool startAdv=true; +//options: servers to start +static QStringList locals,nets; +//option: the file to provide +static QString filename; + +//the urls that get advertised +static QListurls; +//the advertisement object, if created +static PeaProvider *prov=nullptr; + +static const QString HELP= +"PEA Server\n" +"(c) Konrad Rosenbaum, 2013\n" +"protected under the GNU GPLv3 or at your option any newer\n\n" +"Usage: %1 [-options...] exam-filename.pea\n\n" +"Options:\n" +" -adv\n\tAdvertise the server on the LAN via UDP multicast (default).\n" +" -noadv\n\tDo not advertise this server.\n\n" +" -local=\n" + "\tUse a local UNIX socket or Windows Named Pipe for communication.\n" + "\tIt will be advertised as scgilocal:///exam?_local_=\n\n" +" -net= | -net=: | -net=:\n" + "\tUse a TCP socket for communication.\n" + "\t can be an IPv4 or IPv6 address, or a host name, or one of\n" + "\t these special host names:\n" + "\t '__' listen on all IPv4 and IPv6 addresses (default, if omitted)\n" + "\t '_4' listen on all IPv4 addresses\n" + "\t '_6' listen on all IPv6 addresses\n" + "\t if you use an IPv6 address enclose it brackets, e.g. [::1]\n" + "\t can be any integer between 0 and 65535\n" + "\t 0 - chose a free port (default, if omitted)\n" + "\t 1..1024 - privileged ports, may need root/Admin privileges\n" + "\t ..65535 - you may chose any port not yet used\n" + "\tIt will be advertised as scgi://:/exam with the \n" + "\treplaced by the actual value if it was 0.\n\n" +" You can use any number of -local and -net options, if none are given\n" +" the default is equivalent to -net=__:0\n\n" +" -url=\n" + "\tAdd an URL to what is advertised, use this if you redirect to this\n" + "\tserver from a web server (e.g. Apache).\n\n" +" -h | -? | -help | --help\n\tOutput this help text." +; + +void showHelp() { - QCoreApplication app(ac,av); - //check arguments - bool startAdv=true; - QStringList locals,nets; - QString filename; - for(const auto&arg:app.arguments().mid(1)){ + qDebug()<arguments().value(0)).toLatin1().data(); +} + +//returns true on success +bool parseArguments() +{ + for(const auto&arg:qApp->arguments().mid(1)){ if(arg=="-adv")startAdv=true;else if(arg=="-noadv")startAdv=false;else if(arg.startsWith("-local="))locals.append(arg.mid(7));else if(arg.startsWith("-net="))nets.append(arg.mid(5));else + if(arg.startsWith("-url=")){ + QUrl url(arg.mid(5)); + if(url.isValid()) + urls<urls; + QDomDocument doc; + if(!doc.setContent(&fd)){ + qDebug()<<"Error parsing file"<isActive()){ delete ws; qDebug()<<"Unable to create local socket on"<registerInterface("/exam",&iface); - urls<65535)port=0; + WServer*ws=new WServer(addr,port,qApp); + if(!ws->isActive()){ + delete ws; + qDebug()<<"Unable to create TCP socket for"<registerInterface("/exam",iface); + //URL + url.setPort(ws->tcpPort()); + return true; +} + +//create TCP SCGI servers +bool createTcpServers(SInterface*iface) +{ for(const QString&net:nets){ WServer*ws; //parse string + QUrl pnet("x://"+net); + if(!pnet.isValid()){ + qDebug()<<"Invalid -net spec:"<addrs = QHostInfo::fromName(host).addresses().toSet().toList(); + //sanity check + if(addrs.size()<1){ + qDebug()<<"Host"<setUrls(urls); + qDebug()<<"advertising"<startAdvertising(); +} + +int main(int ac,char**av) +{ + QCoreApplication app(ac,av); + //check arguments + if(!parseArguments())return 1; + //load Exam file + POExam exam; + if(!parseExamFile(exam))return 2; + //create interface + SInterface iface; + //create servers + if(!createLocalServers(&iface) || !createTcpServers(&iface)) + return 3; //create advertiser - PeaProvider *prov=nullptr; - if(startAdv){ - QString mmod=exam.mainmodule(); - POModule mm; - for(POModule m:exam.modules())if(m.id()==mmod)mm=m; - prov=new PeaProvider(QUuid(mm.id()),mm.title(),&app); - prov->setUrls(urls); - prov->advertiseUrl(QUrl("http://no.host:8888/here")); - prov->startAdvertising(); - } + createAdvertiser(exam); //enter loop qDebug()<<"When I grow up I wanna be a server, like my dad!"; return app.exec(); -- 1.7.2.5