MythTV master
upnpmsrr.cpp
Go to the documentation of this file.
1
2// Program Name: upnpmsrr.cpp
3//
4// Purpose - uPnp Microsoft Media Receiver Registrar "fake" Service
5//
7#include "upnpmsrr.h"
8
11
12#include "httprequest.h"
13#include "upnpresultcode.h"
14#include "upnputil.h"
15
17//
19
20UPnpMSRR::UPnpMSRR( UPnpDevice *pDevice, const QString &sSharePath )
21 : Eventing( "UPnpMSRR", "MSRR_Event", sSharePath),
22 m_sControlUrl("/MSRR_Control")
23{
25 new StateVariable<unsigned short>("AuthorizationGrantedUpdateID",
26 true));
28 new StateVariable<unsigned short>("AuthorizationDeniedUpdateID", true));
30 new StateVariable<unsigned short>("ValidationSucceededUpdateID", true));
32 new StateVariable<unsigned short>("ValidationRevokedUpdateID", true));
33
34 SetValue<unsigned short>("AuthorizationGrantedUpdateID", 0);
35 SetValue<unsigned short>("AuthorizationDeniedUpdateID" , 0);
36 SetValue<unsigned short>("ValidationSucceededUpdateID" , 0);
37 SetValue<unsigned short>("ValidationRevokedUpdateID" , 0);
38
39 QString sUPnpDescPath = XmlConfiguration().GetValue("UPnP/DescXmlPath", m_sSharePath);
40
41 m_sServiceDescFileName = sUPnpDescPath + "MSRR_scpd.xml";
42
43 // Add our Service Definition to the device.
44 RegisterService( pDevice );
45}
46
48//
50
51UPnpMSRRMethod UPnpMSRR::GetMethod( const QString &sURI )
52{
53 if (sURI == "GetServDesc" )
55 if (sURI == "IsAuthorized" )
56 return MSRR_IsAuthorized;
57 if (sURI == "RegisterDevice" )
59 if (sURI == "IsValidated" )
60 return MSRR_IsValidated;
61
62 return MSRR_Unknown;
63}
64
66//
68
70{
72}
73
75//
77
79{
80 if (pRequest)
81 {
82 if (Eventing::ProcessRequest( pRequest ))
83 return true;
84
85 if ( pRequest->m_sBaseUrl != m_sControlUrl )
86 return false;
87
88 LOG(VB_UPNP, LOG_INFO,
89 QString("UPnpMSRR::ProcessRequest : %1 : %2 :")
90 .arg(pRequest->m_sBaseUrl, pRequest->m_sMethod));
91
92 switch(GetMethod(pRequest->m_sMethod))
93 {
96 break;
98 HandleIsAuthorized( pRequest );
99 break;
101 HandleRegisterDevice( pRequest );
102 break;
103 case MSRR_IsValidated :
104 HandleIsValidated( pRequest );
105 break;
106 default:
108 break;
109 }
110 }
111
112 return true;
113}
114
116//
118
120{
121 /* Always tell the user they are authorized to access this data */
122 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsAuthorized");
123 NameValues list;
124
125 list.push_back(NameValue("Result", "1"));
126
127 list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes", true);
128 list.back().AddAttribute("dt:dt", "int", true);
129
130 pRequest->FormatActionResponse(list);
131}
132
134//
136
138{
139 /* Sure, register, we don't really care */
140 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleRegisterDevice");
141 NameValues list;
142
143 list.push_back(NameValue("Result", "1"));
144
145 pRequest->FormatActionResponse(list);
146}
147
149{
150 /* You are valid sir */
151 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsValidated");
152 NameValues list;
153
154 list.push_back(NameValue("Result", "1"));
155
156 list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes", true);
157 list.back().AddAttribute( "dt:dt", "int", true);
158
159 pRequest->FormatActionResponse(list);
160}
161
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:148
QStringList GetBasePaths() override
Definition: eventing.cpp:136
void FormatErrorResponse(bool bServerError, const QString &sFaultString, const QString &sDetails)
QString m_sMethod
Definition: httprequest.h:131
void FormatFileResponse(const QString &sFileName)
void FormatActionResponse(Serializer *ser)
QString m_sBaseUrl
Definition: httprequest.h:129
QString m_sSharePath
Definition: httpserver.h:79
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:186
static void HandleIsAuthorized(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:119
UPnpMSRR(UPnpDevice *pDevice, const QString &sSharePath)
Definition: upnpmsrr.cpp:20
static void HandleIsValidated(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:148
QString m_sServiceDescFileName
Definition: upnpmsrr.h:31
QString m_sControlUrl
Definition: upnpmsrr.h:32
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpmsrr.cpp:78
static UPnpMSRRMethod GetMethod(const QString &sURI)
Definition: upnpmsrr.cpp:51
static void HandleRegisterDevice(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:137
QStringList GetBasePaths() override
Definition: upnpmsrr.cpp:69
void RegisterService(UPnpDevice *device)
Creates a UPnpService and adds it to the UPnpDevice's list of services.
QString GetValue(const QString &setting)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
UPnpMSRRMethod
Definition: upnpmsrr.h:12
@ MSRR_RegisterDevice
Definition: upnpmsrr.h:16
@ MSRR_IsValidated
Definition: upnpmsrr.h:17
@ MSRR_Unknown
Definition: upnpmsrr.h:13
@ MSRR_GetServiceDescription
Definition: upnpmsrr.h:14
@ MSRR_IsAuthorized
Definition: upnpmsrr.h:15
@ UPnPResult_InvalidAction