*finally got rid of version.inc (version info is now fully woc generated)
authorkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 9 Aug 2009 18:06:28 +0000 (18:06 +0000)
committerkonrad <konrad@6e3c4bff-ac9f-4ac1-96c5-d2ea494d3e33>
Sun, 9 Aug 2009 18:06:28 +0000 (18:06 +0000)
*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

15 files changed:
src/mainwindow.cpp
src/msinterface.cpp
src/msinterface.h
src/wbase/WTransaction.cpp
src/wbase/WTransaction.h
src/wbase/nullable.h
wob/basics.wolf
wob/user.wolf
woc/phpout.cpp
woc/phpout.h
woc/qtout.cpp
www/inc/db/db.php
www/inc/machine/autoload.php
www/inc/machine/version.inc [deleted file]
www/inc/machine/version.php

index 6a61bf0..198c4c7 100644 (file)
@@ -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();
index 70fb6de..b2ddbc6 100644 (file)
@@ -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("The server implementation is too old for this client."));
+               return false;
+       }
+       //am I new enough for server?
+       if(si.getMinimumProtocolVersion().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();
index 6733260..7d60d90 100644 (file)
@@ -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;}
                
index 40ef1f4..7a4cae5 100644 (file)
@@ -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;
index 4effa4c..4ebb71e 100644 (file)
@@ -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();
index ec11c9d..1557cca 100644 (file)
@@ -30,6 +30,18 @@ template<class T>class 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>&t){
+                       if(isnull != t.isnull)return false;
+                       if(isnull)return true;
+                       else return elem == t.elem;}
+               bool operator!=(const Nullable<T>&t){
+                       if(isnull != t.isnull)return true;
+                       if(isnull)return false;
+                       else return elem != t.elem;}
        private:
                bool isnull;
                T elem;
index e59db60..e1b31d0 100644 (file)
                <Column name="dolog" type="bool" default="0"/>
                <Column name="flags" type="string"/>
        </Table>
+       
+       <Transaction name="Backup">
+               <Input/>
+               <Call lang="php" method="global $db;$this->setbackup($db->dumpBackup());"/>
+               <Output>
+                       <Var name="backup" type="string"/>
+               </Output>
+       </Transaction>
 </Wolf>
index 786136f..dadbf4b 100644 (file)
@@ -65,7 +65,7 @@
        
        <Transaction name="ServerInfo" mode="open">
                <Input/>
-               <Call lang="php" method="serverInfoXml($this);"/>
+               <Call lang="php" method="Version::serverInfoXml($this);"/>
                <Output>
                        <Var name="ServerVersion" type="string"/>
                        <Var name="MinimumProtocolVersion" type="astring"/>
index 2de7e4a..9eb00e5 100644 (file)
@@ -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()){
index b3dba00..ddebf5b 100644 (file)
@@ -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*/
index 8f9bc08..469cb13 100644 (file)
@@ -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;i<in.size();i++){
                scd+="\tin_"+in[i]+"=a"+in[i]+";\n";
        }
        scd+="}\n\n";
+       //decl copy constructor
+       hcd+="\t"+cn+"(const "+cn+"&);\n";
+       //copy constructor implementation
        scd+=cn+"::"+cn+"(const "+cn+"&t)\n\t:WTransaction(t)\n{\n";
        for(int i=0;i<in.size();i++){
                scd+="\tin_"+in[i]+"=t.in_"+in[i]+";\n";
        }
        scd+="}\n\n";
+       //decl copy operator
+       hcd+="\t"+cn+"& operator=(const "+cn+"&);\n";
+       //copy operator implemented
+       scd+=cn+"& "+cn+"::operator=(const "+cn+"&t)\n{\n";
+       scd+="\tWTransaction::operator=(t);\n";
+       for(int i=0;i<in.size();i++){
+               scd+="\tin_"+in[i]+"=t.in_"+in[i]+";\n";
+       }
+       for(int i=0;i<out.size();i++){
+               scd+="\tout_"+out[i]+"=t.out_"+out[i]+";\n";
+       }
+       scd+="\treturn *this;\n}\n\n";
        
-       //query method
-       hcd+="\tvoid netquery();\n";
+       //query method implemented
        scd+="void "+cn+"::netquery()\n{\n";
        scd+="\tQDomDocument doc;QDomElement root=doc.createElement(\"WobRequest\");\n";
        scd+="\tQDomElement tmp;\n";
@@ -530,10 +550,8 @@ void WocQtClientOut::newTransaction(const WocTransaction&trn)
        src.write(scd.toAscii());
        
        
-       //create copy constructor
-       hcd="  public:\n";
-       hcd+="\t"+cn+"(const "+cn+"&);\n";
        //create getters
+       hcd="";
        for(int i=0;i<out.size();i++){
                QString tp=qttype(trn,out[i],Out);
                hcd+="\t"+tp+" get"+out[i]+"(){return out_"+out[i]+";}\n";
index 1b0c300..00a7656 100644 (file)
@@ -421,19 +421,19 @@ abstract class DbEngine
                return "str ".base64_encode($val);
        }
        
-       /**dump a backup to stdout*/
+       /**dump a backup (returned as string)*/
        public function dumpBackup()
        {
                global $dbScheme;
                //make sure nobody else can disturb us (read lock)
                $this->lockDB(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*/
index 8fb7f1f..159ef15 100644 (file)
@@ -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 (file)
index 6a53038..0000000
+++ /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)
index cadb3bd..32443ed 100644 (file)
@@ -1,40 +1,12 @@
 <?
-
-//function to register version info
-function defversion()
-{
-       global $MSVERSION;
-       foreach(file('inc/machine/version.inc') as $line){
-               $line=trim($line);
-               //check whether we need this line
-               if(substr($line,0,10)!="defversion")continue;
-               //extract useful information
-               $line=trim(strtr($line,array("defversion"=>"","("=>"",")"=>"",";"=>"")));
-               $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