From acf9c44bae1f40f74c1a75af74cfcfe5bf0884d6 Mon Sep 17 00:00:00 2001 From: konrad Date: Sun, 9 Aug 2009 18:06:28 +0000 Subject: [PATCH] *finally got rid of version.inc (version info is now fully woc generated) *implemented backup transaction (yet untested) *checking compatibility before login *multiple minor fixes git-svn-id: https://silmor.de/svn/softmagic/smoke/trunk@327 6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33 --- src/mainwindow.cpp | 4 +++- src/msinterface.cpp | 28 ++++++++++++++++++++++++++++ src/msinterface.h | 4 ++++ src/wbase/WTransaction.cpp | 10 ++++++++++ src/wbase/WTransaction.h | 2 ++ src/wbase/nullable.h | 12 ++++++++++++ wob/basics.wolf | 8 ++++++++ wob/user.wolf | 2 +- woc/phpout.cpp | 16 +++++++++++++++- woc/phpout.h | 3 +++ woc/qtout.cpp | 34 ++++++++++++++++++++++++++-------- www/inc/db/db.php | 18 ++++++++++-------- www/inc/machine/autoload.php | 3 +-- www/inc/machine/version.inc | 27 --------------------------- www/inc/machine/version.php | 40 ++++++---------------------------------- 15 files changed, 129 insertions(+), 82 deletions(-) delete mode 100644 www/inc/machine/version.inc diff --git a/src/mainwindow.cpp b/src/mainwindow.cpp index 6a61bf0..198c4c7 100644 --- a/src/mainwindow.cpp +++ b/src/mainwindow.cpp @@ -213,7 +213,9 @@ void MMainWindow::startLogin() mw->setUrl(serverurl->text()); if(useproxy->isChecked()) mw->setProxy(proxyname->text(),proxyport->value(),proxyuser->text(),proxypass->text()); - //start request + //check server version + if(!mw->checkServer())return; + //start login request QString hn; if(usealterhost->isChecked())hn=alterhostname->text(); else hn=QSettings().value("hostname").toString(); diff --git a/src/msinterface.cpp b/src/msinterface.cpp index 70fb6de..b2ddbc6 100644 --- a/src/msinterface.cpp +++ b/src/msinterface.cpp @@ -52,6 +52,34 @@ bool MSInterface::login(QString username,QString passwd,QString hostname,QString return true; } +bool MSInterface::checkServer() +{ + MTServerInfo si; + try{si=MTServerInfo::query();}catch(WException e){ + qDebug("caught exception while getting server info (%s): %s", + e.component().toAscii().data(), + e.error().toAscii().data()); + QMessageBox::warning(0,tr("Error"),tr("Communication problem while talking to the server, see log for details.")); + return false; + } + if(si.stage()!=si.Success){ + QMessageBox::warning(0,tr("Error"),tr("Communication with server was not successful.")); + return false; + } + //is server new enough for me? + if(si.getServerVersion().value()commVersion()){ + QMessageBox::warning(0,tr("Error"),tr("This client is too old for the server, please upgrade.")); + return false; + } + //we are ok + return true; +} + void MSInterface::logout() { if(m_sessid!="")queryLogout(); diff --git a/src/msinterface.h b/src/msinterface.h index 6733260..7d60d90 100644 --- a/src/msinterface.h +++ b/src/msinterface.h @@ -29,6 +29,10 @@ class MSInterface:public MInterface bool hasRight(Right)const; QString dataDir()const; QString settingsGroup()const; + + /**checks the server for compatibility*/ + bool checkServer(); + /**returns the current session ID*/ QString sessionId()const{return m_sessid;} diff --git a/src/wbase/WTransaction.cpp b/src/wbase/WTransaction.cpp index 40ef1f4..7a4cae5 100644 --- a/src/wbase/WTransaction.cpp +++ b/src/wbase/WTransaction.cpp @@ -37,6 +37,16 @@ WTransaction::WTransaction(const WTransaction&t) m_httpid=-1; } +WTransaction& WTransaction::operator=(const WTransaction&t) +{ + m_stage=t.m_stage; + m_errstr=t.m_errstr; + m_errtype=t.m_errtype; + m_iface=t.m_iface; + m_httpid=-1; + return *this; +} + static inline QString esc(const QByteArray ar) { QString r; diff --git a/src/wbase/WTransaction.h b/src/wbase/WTransaction.h index 4effa4c..4ebb71e 100644 --- a/src/wbase/WTransaction.h +++ b/src/wbase/WTransaction.h @@ -36,6 +36,8 @@ class WTransaction:public QObject WTransaction(QString iface=QString()); WTransaction(const WTransaction&); + WTransaction& operator=(const WTransaction&); + QByteArray executeQuery(QString,QByteArray); private slots: void webTimeout(); diff --git a/src/wbase/nullable.h b/src/wbase/nullable.h index ec11c9d..1557cca 100644 --- a/src/wbase/nullable.h +++ b/src/wbase/nullable.h @@ -30,6 +30,18 @@ templateclass Nullable T& value(){return elem;} T value()const{if(isnull)return T();else return elem;} + + bool operator==(const T&t){if(isnull)return false;else return elem == t;} + bool operator!=(const T&t){if(isnull)return true;else return elem != t;} + + bool operator==(const Nullable&t){ + if(isnull != t.isnull)return false; + if(isnull)return true; + else return elem == t.elem;} + bool operator!=(const Nullable&t){ + if(isnull != t.isnull)return true; + if(isnull)return false; + else return elem != t.elem;} private: bool isnull; T elem; diff --git a/wob/basics.wolf b/wob/basics.wolf index e59db60..e1b31d0 100644 --- a/wob/basics.wolf +++ b/wob/basics.wolf @@ -30,4 +30,12 @@ + + + + + + + + diff --git a/wob/user.wolf b/wob/user.wolf index 786136f..dadbf4b 100644 --- a/wob/user.wolf +++ b/wob/user.wolf @@ -65,7 +65,7 @@ - + diff --git a/woc/phpout.cpp b/woc/phpout.cpp index 2de7e4a..9eb00e5 100644 --- a/woc/phpout.cpp +++ b/woc/phpout.cpp @@ -21,7 +21,8 @@ static const QByteArray PHPEND("\n//END OF AUTOGENERATED FILE\n?>"); static const QByteArray SCHEMASTART("class WobSchema extends WobSchemaBase\n{\nfunction __construct(){\n"); static const QByteArray SCHEMAEND("}};\n"); -static const QByteArray TRANSACTSTART("class WobTransaction extends WobTransactionBase\n{\nstatic public function handle(){switch(WobTransactionBase::getTransactionName()){\n"); +static const QByteArray TRANSACTCLASS("class WobTransaction extends WobTransactionBase\n{\n"); +static const QByteArray TRANSACTSTART("static public function handle(){switch(WobTransactionBase::getTransactionName()){\n"); static const QByteArray TRANSACTEND("\tdefault:WobTransactionBase::noSuchTransaction();break;\n}}\n};\n"); WocPHPServerOut::WocPHPServerOut(const QDomElement&el) @@ -78,10 +79,23 @@ WocPHPServerOut::WocPHPServerOut(const QDomElement&el) return; } m_transact.write(PHPSTART); + m_transact.write(TRANSACTCLASS); + transInfo(); m_transact.write(TRANSACTSTART); addLoad("WobTransaction","transaction"); } +void WocPHPServerOut::transInfo() +{ + WocProcessor*woc=WocProcessor::instance(); + m_transact.write(QString(" static public function commVersion(){return \""+woc->verComm()+"\";}\n").toAscii()); + m_transact.write(QString(" static public function needCommVersion(){return \""+woc->verNeedComm()+"\";}\n").toAscii()); + m_transact.write(QString(" static public function version(){return \""+woc->verHR()+"\";}\n").toAscii()); + m_transact.write(QString(" static public function svnVersion(){return \""+woc->svnRevision()+"\";}\n\n").toAscii()); + m_transact.write(QString(" static public function svnRepositoryRoot(){return \""+woc->svnRepositoryRoot()+"\";}\n\n").toAscii()); + m_transact.write(QString(" static public function svnRepositoryUrl(){return \""+woc->svnRepositoryUrl()+"\";}\n\n").toAscii()); +} + void WocPHPServerOut::finalize() { if(m_loader.isOpen()){ diff --git a/woc/phpout.h b/woc/phpout.h index b3dba00..ddebf5b 100644 --- a/woc/phpout.h +++ b/woc/phpout.h @@ -61,6 +61,9 @@ class WocPHPServerOut:public WocOutput /**helper: generate setters for sclar properties*/ QString classPropertyScalarSetters(const WocClass&,QString); + /**helper: create info functions (mainly version info)*/ + void transInfo(); + /**helper: create transaction constructor*/ QString trnConstruct(const WocTransaction&); /**helper: create transaction input parser*/ diff --git a/woc/qtout.cpp b/woc/qtout.cpp index 8f9bc08..469cb13 100644 --- a/woc/qtout.cpp +++ b/woc/qtout.cpp @@ -488,31 +488,51 @@ void WocQtClientOut::newTransaction(const WocTransaction&trn) hcd+="\t"+qttype(trn,out[i],Out)+"out_"+out[i]+";\n"; hdr.write(hcd.toAscii()); - //interface code + //query method decl + hdr.write(QByteArray("\tvoid netquery();\n")); + + //global interface code QString sif=" "+cn+" query"+trn.name()+"("+inlist+")\n\t"; sif+="{return "+cn+"::query("+clist+(clist!=""?",":"")+"name());}\n"; m_iface.write(sif.toAscii()); - //create constructor + //create constructors if(inlist!="")inlist+=","; inlist+="QString iface"; if(clist!="")clist+=","; clist+="iface"; QString defparm="=\""+WocProcessor::instance()->projectName()+"\""; - hcd="\t"+cn+"("+inlist+defparm+");\n"; + //define parametric constructor + hcd=" public:\n"; + hcd+="\t"+cn+"("+inlist+defparm+");\n"; + //parametric constructor implementation scd+=cn+"::"+cn+"("+inlist+")\n\t:WTransaction(iface)\n{\n"; for(int i=0;ilockDB(false); //dump basic stuff - print("startbackup\n"); - print("backupversion 0\n"); - print("dbversion ".$dbScheme->version()."\n"); + $ret="startbackup\n"; + $ret.="backupversion 0\n"; + $ret.="dbversion ".$dbScheme->version()."\n"; //go through backup tables foreach($dbScheme->backupTables() as $tab){ - print("table ".$tab."\n"); + $ret.="table ".$tab."\n"; //get columns $cols=$dbScheme->tableColumns($tab); //go through rows @@ -441,14 +441,16 @@ abstract class DbEngine foreach($res as $row){ foreach($cols as $col){ $val=$row[$col]; - print("value $col ".$this->escapeBackup($tab,$col,$val)."\n"); + $ret.="value $col ".$this->escapeBackup($tab,$col,$val)."\n"; } - print("insert\n"); + $ret.="insert\n"; } } - print("endofbackup\n"); + $ret.="endofbackup\n"; //release lock & commit $this->unlockDB(); + + return $ret; } /**helper: decode backup data from transport format*/ diff --git a/www/inc/machine/autoload.php b/www/inc/machine/autoload.php index 8fb7f1f..159ef15 100644 --- a/www/inc/machine/autoload.php +++ b/www/inc/machine/autoload.php @@ -14,6 +14,5 @@ $AUTOCLASS["Session"]="./inc/machine/session.php"; $AUTOCLASS["Host"]="./inc/machine/host.php"; $AUTOCLASS["Template"]="./inc/machine/template.php"; - -include("./inc/machine/version.php"); +$AUTOCLASS["Version"]="./inc/machine/version.php"; ?> \ No newline at end of file diff --git a/www/inc/machine/version.inc b/www/inc/machine/version.inc deleted file mode 100644 index 6a53038..0000000 --- a/www/inc/machine/version.inc +++ /dev/null @@ -1,27 +0,0 @@ -//This file contains the protocol version of MagicSmoke. - -//Syntax: -// defversion(token,version) -// token - identifies the version described -// version - is the version string -// both arguments MUST NOT have quotes -// lines with // and empty lines are ignored - -// C++: defversion is a preprocessor macro -// PHP: scans each line splitting at () and , - -//minimum version that the server understands (4 hex digits) -defversion(MINSERVER,0101) -//current version of the server -defversion(CURSERVER,0101) - -//current human readable version of the server -defversion(HRSERVER,1.91 alpha) - -//minimum version that the client requires -defversion(MINCLIENT,0101) -//current version of the client -defversion(CURCLIENT,0101) - -//current human readable version of the client -defversion(HRCLIENT,1.91 alpha) diff --git a/www/inc/machine/version.php b/www/inc/machine/version.php index cadb3bd..32443ed 100644 --- a/www/inc/machine/version.php +++ b/www/inc/machine/version.php @@ -1,40 +1,12 @@ "","("=>"",")"=>"",";"=>""))); - $sp=explode(",",$line); - //syntax check - if(count($sp)!=2)continue; - //store - $k=trim($sp[0]);$v=trim($sp[1]); - $MSVERSION[$k]=$v; - } -} - -/**this variable contains version information about the server protocol: - MINSERVER=minimum protocol version the server understands; - CURSERVER=protocol version the server implements; - HRSERVER=human readable server version; - note that the database layer has its own version that is not stored here*/ -$MSVERSION=array(); - -//load version include -defversion(); - -function serverInfoXml($trans) +class Version { +public static function serverInfoXml($trans) { global $MSVERSION; - $trans->setServerVersion($MSVERSION["HRSERVER"]); - $trans->setMinimumProtocolVersion($MSVERSION["MINSERVER"]); - $trans->setServerProtocolVersion($MSVERSION["CURSERVER"]); + $trans->setServerVersion($trans->commVersion()); + $trans->setMinimumProtocolVersion($trans->needCommVersion()); + $trans->setServerProtocolVersion($trans->version()); } +}; ?> \ No newline at end of file -- 1.7.2.5