MythTV  master
mythxmlclient.cpp
Go to the documentation of this file.
1 // Program Name: mythxmlclient.cpp
3 // Created : Mar. 19, 2007
4 //
5 // Purpose : Myth XML protocol client
6 //
7 // Copyright (c) 2007 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see COPYING for details
10 //
12 
13 #include "mythversion.h"
14 #include "mythxmlclient.h"
15 #include "mythlogging.h"
16 
17 #include <QObject>
18 
20 //
22 
23 MythXMLClient::MythXMLClient( const QUrl &url )
24  : SOAPClient( url,
25  "urn:schemas-mythtv-org:service:MythTV:1",
26  "/Myth")
27 {
28 }
29 
31 //
33 
34 UPnPResultCode MythXMLClient::GetConnectionInfo( const QString &sPin, DatabaseParams *pParams, QString &sMsg )
35 {
36  if (pParams == nullptr)
38 
39  int nErrCode = 0;
40  QString sErrDesc;
41  QStringMap list;
42 
43  sMsg.clear();
44 
45  list.insert( "Pin", sPin );
46 
47  QDomDocument xmlResults = SendSOAPRequest(
48  "GetConnectionInfo", list, nErrCode, sErrDesc);
49 
50  // --------------------------------------------------------------
51  // Is this a valid response?
52  // --------------------------------------------------------------
53 
54  QDomNode oNode = xmlResults.namedItem( "GetConnectionInfoResult" );
55 
56  if (UPnPResult_Success == nErrCode && !oNode.isNull())
57  {
58  QDomNode dbNode = oNode.namedItem( "Database" );
59 
60  pParams->dbHostName = GetNodeValue( dbNode, "Host" , QString());
61  pParams->dbPort = GetNodeValue( dbNode, "Port" , 0 );
62  pParams->dbUserName = GetNodeValue( dbNode, "UserName" , QString());
63  pParams->dbPassword = GetNodeValue( dbNode, "Password" , QString());
64  pParams->dbName = GetNodeValue( dbNode, "Name" , QString());
65  pParams->dbType = GetNodeValue( dbNode, "Type" , QString());
66 
67  QDomNode wolNode = oNode.namedItem( "WOL" );
68 
69  pParams->wolEnabled = GetNodeValue( wolNode, "Enabled" , false );
70  pParams->wolReconnect = GetNodeValue( wolNode, "Reconnect", 0 );
71  pParams->wolRetry = GetNodeValue( wolNode, "Retry" , 0 );
72  pParams->wolCommand = GetNodeValue( wolNode, "Command" , QString());
73 
74  QDomNode verNode = oNode.namedItem( "Version" );
75 
76  pParams->verVersion = GetNodeValue( verNode, "Version" , "" );
77  pParams->verBranch = GetNodeValue( verNode, "Branch" , "" );
78  pParams->verProtocol = GetNodeValue( verNode, "Protocol" , "" );
79  pParams->verBinary = GetNodeValue( verNode, "Binary" , "" );
80  pParams->verSchema = GetNodeValue( verNode, "Schema" , "" );
81 
82  if ((pParams->verProtocol != MYTH_PROTO_VERSION) ||
83  (pParams->verSchema != MYTH_DATABASE_VERSION))
84  // incompatible version, we cannot use this backend
85  {
86  LOG(VB_GENERAL, LOG_ERR,
87  QString("MythXMLClient::GetConnectionInfo Failed - "
88  "Version Mismatch (%1,%2) != (%3,%4)")
89  .arg(pParams->verProtocol)
90  .arg(pParams->verSchema)
91  .arg(MYTH_PROTO_VERSION)
92  .arg(MYTH_DATABASE_VERSION));
93  sMsg = QObject::tr("Version Mismatch", "UPNP Errors");
95  }
96 
97  return UPnPResult_Success;
98  }
99 
100  sMsg = sErrDesc;
101 
102  LOG(VB_GENERAL, LOG_ERR,
103  QString("MythXMLClient::GetConnectionInfo Failed - (%1) %2")
104  .arg(nErrCode) .arg(sErrDesc));
105 
106  if (( nErrCode == UPnPResult_HumanInterventionRequired ) ||
107  ( nErrCode == UPnPResult_ActionNotAuthorized ) ||
108  ( nErrCode == UPnPResult_MythTV_XmlParseError ) ||
109  ( nErrCode == 501 ) )
110  {
111  // Service calls no longer return UPnPResult codes,
112  // convert standard 501 to UPnPResult code for now.
113  sMsg = QObject::tr("Not Authorized", "UPNP Errors");
115  }
116 
117  sMsg = QObject::tr("Unknown Error", "UPNP Errors");
119 }
bool wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:33
Subclass SOAPClient to perform actions using the command URL.
Definition: soapclient.h:24
QString wolCommand
command to use for wake-on-lan
Definition: mythdbparams.h:36
QString dbName
database name
Definition: mythdbparams.h:26
UPnPResultCode
Definition: upnp.h:31
QString verSchema
core schema version
Definition: mythdbparams.h:45
int GetNodeValue(const QDomNode &node, const QString &sName, int nDefault) const
Gets the named value using QDomNode as the baseNode in the search, returns default if it is not found...
Definition: soapclient.cpp:107
QString verBinary
binary library version
Definition: mythdbparams.h:44
QString verProtocol
backend protocol
Definition: mythdbparams.h:43
QString dbPassword
DB password.
Definition: mythdbparams.h:25
QMap< QString, QString > QStringMap
Definition: upnputil.h:40
QString dbUserName
DB user name.
Definition: mythdbparams.h:24
QString dbType
database type (MySQL, Postgres, etc.)
Definition: mythdbparams.h:27
#define MYTH_PROTO_VERSION
Increment this whenever the MythTV network protocol changes.
Definition: mythversion.h:48
MythXMLClient(const QUrl &url)
int wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:34
QDomDocument SendSOAPRequest(const QString &sMethod, QStringMap &list, int &nErrCode, QString &sErrDesc)
Actually sends the sMethod action to the command URL specified in the constructor (url+[/]+sControlPa...
Definition: soapclient.cpp:178
Structure containing the basic Database parameters.
Definition: mythdbparams.h:9
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
QString dbHostName
database server
Definition: mythdbparams.h:21
UPnPResultCode GetConnectionInfo(const QString &sPin, DatabaseParams *pParams, QString &sMsg)
QString verBranch
git branch
Definition: mythdbparams.h:42
int dbPort
database port
Definition: mythdbparams.h:23
int wolRetry
times to retry to reconnect
Definition: mythdbparams.h:35
QString verVersion
git version string
Definition: mythdbparams.h:41
#define MYTH_DATABASE_VERSION
Increment this whenever the MythTV core database schema changes.
Definition: mythversion.h:78