MythTV master
mythxmlclient.cpp
Go to the documentation of this file.
1
2// 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#include "mythxmlclient.h"
13
14#include <QObject>
15
17#include "libmythbase/mythversion.h"
18
20//
22
24 : SOAPClient( url,
25 "urn:schemas-mythtv-org:service:MythTV:1",
26 "/Myth")
27{
28}
29
31//
33
34UPnPResultCode 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( "ConnectionInfo" );
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,
91 MYTH_PROTO_VERSION,
92 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}
Structure containing the basic Database parameters.
Definition: mythdbparams.h:11
QString m_verBranch
git branch
Definition: mythdbparams.h:40
QString m_dbName
database name
Definition: mythdbparams.h:26
QString m_dbPassword
DB password.
Definition: mythdbparams.h:25
std::chrono::seconds m_wolReconnect
seconds to wait for reconnect
Definition: mythdbparams.h:34
QString m_verBinary
binary library version
Definition: mythdbparams.h:42
QString m_dbUserName
DB user name.
Definition: mythdbparams.h:24
QString m_verSchema
core schema version
Definition: mythdbparams.h:43
QString m_dbType
database type (MySQL, Postgres, etc.)
Definition: mythdbparams.h:27
QString m_verVersion
git version string
Definition: mythdbparams.h:39
QString m_wolCommand
command to use for wake-on-lan
Definition: mythdbparams.h:36
bool m_wolEnabled
true if wake-on-lan params are used
Definition: mythdbparams.h:33
int m_dbPort
database port
Definition: mythdbparams.h:23
int m_wolRetry
times to retry to reconnect
Definition: mythdbparams.h:35
QString m_dbHostName
database server
Definition: mythdbparams.h:21
QString m_verProtocol
backend protocol
Definition: mythdbparams.h:41
UPnPResultCode GetConnectionInfo(const QString &sPin, DatabaseParams *pParams, QString &sMsg)
MythXMLClient(const QUrl &url)
Subclass SOAPClient to perform actions using the command URL.
Definition: soapclient.h:25
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:111
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:182
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
UPnPResultCode
Definition: upnp.h:34
@ UPnPResult_HumanInterventionRequired
Definition: upnp.h:44
@ UPnPResult_Success
Definition: upnp.h:35
@ UPnPResult_MythTV_XmlParseError
Definition: upnp.h:85
@ UPnPResult_ActionFailed
Definition: upnp.h:39
@ UPnPResult_ActionNotAuthorized
Definition: upnp.h:46
@ UPnPResult_InvalidArgs
Definition: upnp.h:38
QMap< QString, QString > QStringMap
Definition: upnputil.h:28