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();
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();
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;}
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;
WTransaction(QString iface=QString());
WTransaction(const WTransaction&);
+ WTransaction& operator=(const WTransaction&);
+
QByteArray executeQuery(QString,QByteArray);
private slots:
void webTimeout();
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;
<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>
<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"/>
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)
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()){
/**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*/
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";
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";
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
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*/
$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
+++ /dev/null
-//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)
<?
-
-//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