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 LICENSE for details
10 //
12 
13 #include <QObject>
14 
16 #include "libmythbase/mythversion.h"
17 
18 #include "mythxmlclient.h"
19 
21 //
23 
24 MythXMLClient::MythXMLClient( const QUrl &url )
25  : SOAPClient( url,
26  "urn:schemas-mythtv-org:service:MythTV:1",
27  "/Myth")
28 {
29 }
30 
32 //
34 
35 UPnPResultCode MythXMLClient::GetConnectionInfo( const QString &sPin, DatabaseParams *pParams, QString &sMsg )
36 {
37  if (pParams == nullptr)
39 
40  int nErrCode = 0;
41  QString sErrDesc;
42  QStringMap list;
43 
44  sMsg.clear();
45 
46  list.insert( "Pin", sPin );
47 
48  QDomDocument xmlResults = SendSOAPRequest(
49  "GetConnectionInfo", list, nErrCode, sErrDesc);
50 
51  // --------------------------------------------------------------
52  // Is this a valid response?
53  // --------------------------------------------------------------
54 
55  QDomNode oNode = xmlResults.namedItem( "GetConnectionInfoResult" );
56 
57  if (UPnPResult_Success == nErrCode && !oNode.isNull())
58  {
59  QDomNode dbNode = oNode.namedItem( "Database" );
60 
61  pParams->m_dbHostName = GetNodeValue( dbNode, "Host" , QString());
62  pParams->m_dbPort = GetNodeValue( dbNode, "Port" , 0 );
63  pParams->m_dbUserName = GetNodeValue( dbNode, "UserName" , QString());
64  pParams->m_dbPassword = GetNodeValue( dbNode, "Password" , QString());
65  pParams->m_dbName = GetNodeValue( dbNode, "Name" , QString());
66  pParams->m_dbType = GetNodeValue( dbNode, "Type" , QString());
67 
68  QDomNode wolNode = oNode.namedItem( "WOL" );
69 
70  pParams->m_wolEnabled = GetNodeValue( wolNode, "Enabled" , false );
71  pParams->m_wolReconnect = std::chrono::seconds(GetNodeValue( wolNode, "Reconnect", 0 ));
72  pParams->m_wolRetry = GetNodeValue( wolNode, "Retry" , 0 );
73  pParams->m_wolCommand = GetNodeValue( wolNode, "Command" , QString());
74 
75  QDomNode verNode = oNode.namedItem( "Version" );
76 
77  pParams->m_verVersion = GetNodeValue( verNode, "Version" , "" );
78  pParams->m_verBranch = GetNodeValue( verNode, "Branch" , "" );
79  pParams->m_verProtocol = GetNodeValue( verNode, "Protocol" , "" );
80  pParams->m_verBinary = GetNodeValue( verNode, "Binary" , "" );
81  pParams->m_verSchema = GetNodeValue( verNode, "Schema" , "" );
82 
83  if ((pParams->m_verProtocol != MYTH_PROTO_VERSION) ||
84  (pParams->m_verSchema != MYTH_DATABASE_VERSION))
85  // incompatible version, we cannot use this backend
86  {
87  LOG(VB_GENERAL, LOG_ERR,
88  QString("MythXMLClient::GetConnectionInfo Failed - "
89  "Version Mismatch (%1,%2) != (%3,%4)")
90  .arg(pParams->m_verProtocol,
91  pParams->m_verSchema,
92  MYTH_PROTO_VERSION,
93  MYTH_DATABASE_VERSION));
94  sMsg = QObject::tr("Version Mismatch", "UPNP Errors");
96  }
97 
98  return UPnPResult_Success;
99  }
100 
101  sMsg = sErrDesc;
102 
103  LOG(VB_GENERAL, LOG_ERR,
104  QString("MythXMLClient::GetConnectionInfo Failed - (%1) %2")
105  .arg(nErrCode) .arg(sErrDesc));
106 
107  if (( nErrCode == UPnPResult_HumanInterventionRequired ) ||
108  ( nErrCode == UPnPResult_ActionNotAuthorized ) ||
109  ( nErrCode == UPnPResult_MythTV_XmlParseError ) ||
110  ( nErrCode == 501 ) )
111  {
112  // Service calls no longer return UPnPResult codes,
113  // convert standard 501 to UPnPResult code for now.
114  sMsg = QObject::tr("Not Authorized", "UPNP Errors");
116  }
117 
118  sMsg = QObject::tr("Unknown Error", "UPNP Errors");
120 }
DatabaseParams::m_dbHostName
QString m_dbHostName
database server
Definition: mythdbparams.h:22
UPnPResult_ActionFailed
@ UPnPResult_ActionFailed
Definition: upnp.h:41
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:112
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
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:24
UPnPResult_InvalidArgs
@ UPnPResult_InvalidArgs
Definition: upnp.h:40
DatabaseParams::m_wolReconnect
std::chrono::seconds m_wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:35
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:32
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_ActionNotAuthorized
@ UPnPResult_ActionNotAuthorized
Definition: upnp.h:48
DatabaseParams::m_verProtocol
QString m_verProtocol
backend protocol
Definition: mythdbparams.h:44
UPnPResult_Success
@ UPnPResult_Success
Definition: upnp.h:37
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:35
UPnPResult_HumanInterventionRequired
@ UPnPResult_HumanInterventionRequired
Definition: upnp.h:46
UPnPResultCode
UPnPResultCode
Definition: upnp.h:35
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:183
DatabaseParams::m_wolEnabled
bool m_wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:34
UPnPResult_MythTV_XmlParseError
@ UPnPResult_MythTV_XmlParseError
Definition: upnp.h:87