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->m_dbHostName = GetNodeValue( dbNode, "Host" , QString());
61  pParams->m_dbPort = GetNodeValue( dbNode, "Port" , 0 );
62  pParams->m_dbUserName = GetNodeValue( dbNode, "UserName" , QString());
63  pParams->m_dbPassword = GetNodeValue( dbNode, "Password" , QString());
64  pParams->m_dbName = GetNodeValue( dbNode, "Name" , QString());
65  pParams->m_dbType = GetNodeValue( dbNode, "Type" , QString());
66 
67  QDomNode wolNode = oNode.namedItem( "WOL" );
68 
69  pParams->m_wolEnabled = GetNodeValue( wolNode, "Enabled" , false );
70  pParams->m_wolReconnect = std::chrono::seconds(GetNodeValue( wolNode, "Reconnect", 0 ));
71  pParams->m_wolRetry = GetNodeValue( wolNode, "Retry" , 0 );
72  pParams->m_wolCommand = GetNodeValue( wolNode, "Command" , QString());
73 
74  QDomNode verNode = oNode.namedItem( "Version" );
75 
76  pParams->m_verVersion = GetNodeValue( verNode, "Version" , "" );
77  pParams->m_verBranch = GetNodeValue( verNode, "Branch" , "" );
78  pParams->m_verProtocol = GetNodeValue( verNode, "Protocol" , "" );
79  pParams->m_verBinary = GetNodeValue( verNode, "Binary" , "" );
80  pParams->m_verSchema = GetNodeValue( verNode, "Schema" , "" );
81 
82  if ((pParams->m_verProtocol != MYTH_PROTO_VERSION) ||
83  (pParams->m_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->m_verProtocol,
90  pParams->m_verSchema,
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 }
UPnPResult_InvalidArgs
@ UPnPResult_InvalidArgs
Definition: upnp.h:41
DatabaseParams::m_dbHostName
QString m_dbHostName
database server
Definition: mythdbparams.h:22
DatabaseParams
Structure containing the basic Database parameters.
Definition: mythdbparams.h:10
SOAPClient
Subclass SOAPClient to perform actions using the command URL.
Definition: soapclient.h:24
mythxmlclient.h
SOAPClient::GetNodeValue
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:115
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
DatabaseParams::m_dbType
QString m_dbType
database type (MySQL, Postgres, etc.)
Definition: mythdbparams.h:28
DatabaseParams::m_verBranch
QString m_verBranch
git branch
Definition: mythdbparams.h:43
MythXMLClient::MythXMLClient
MythXMLClient(const QUrl &url)
Definition: mythxmlclient.cpp:23
DatabaseParams::m_wolReconnect
std::chrono::seconds m_wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:35
mythversion.h
UPnPResult_HumanInterventionRequired
@ UPnPResult_HumanInterventionRequired
Definition: upnp.h:47
DatabaseParams::m_dbPort
int m_dbPort
database port
Definition: mythdbparams.h:24
DatabaseParams::m_verVersion
QString m_verVersion
git version string
Definition: mythdbparams.h:42
mythlogging.h
QStringMap
QMap< QString, QString > QStringMap
Definition: upnputil.h:44
DatabaseParams::m_verSchema
QString m_verSchema
core schema version
Definition: mythdbparams.h:46
DatabaseParams::m_dbPassword
QString m_dbPassword
DB password.
Definition: mythdbparams.h:26
DatabaseParams::m_wolRetry
int m_wolRetry
times to retry to reconnect
Definition: mythdbparams.h:36
DatabaseParams::m_dbName
QString m_dbName
database name
Definition: mythdbparams.h:27
UPnPResult_MythTV_XmlParseError
@ UPnPResult_MythTV_XmlParseError
Definition: upnp.h:88
UPnPResult_ActionNotAuthorized
@ UPnPResult_ActionNotAuthorized
Definition: upnp.h:49
UPnPResult_ActionFailed
@ UPnPResult_ActionFailed
Definition: upnp.h:42
DatabaseParams::m_verProtocol
QString m_verProtocol
backend protocol
Definition: mythdbparams.h:44
MYTH_PROTO_VERSION
#define MYTH_PROTO_VERSION
Increment this whenever the MythTV network protocol changes.
Definition: mythversion.h:47
DatabaseParams::m_wolCommand
QString m_wolCommand
command to use for wake-on-lan
Definition: mythdbparams.h:37
DatabaseParams::m_verBinary
QString m_verBinary
binary library version
Definition: mythdbparams.h:45
DatabaseParams::m_dbUserName
QString m_dbUserName
DB user name.
Definition: mythdbparams.h:25
MythXMLClient::GetConnectionInfo
UPnPResultCode GetConnectionInfo(const QString &sPin, DatabaseParams *pParams, QString &sMsg)
Definition: mythxmlclient.cpp:34
MYTH_DATABASE_VERSION
#define MYTH_DATABASE_VERSION
Increment this whenever the MythTV core database schema changes.
Definition: mythversion.h:77
UPnPResult_Success
@ UPnPResult_Success
Definition: upnp.h:38
SOAPClient::SendSOAPRequest
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:186
DatabaseParams::m_wolEnabled
bool m_wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:34
UPnPResultCode
UPnPResultCode
Definition: upnp.h:36