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 "upnp.h"
13#include "upnputil.h"
14
16//
18
19UPnpMSRR::UPnpMSRR( UPnpDevice *pDevice, const QString &sSharePath )
20 : Eventing( "UPnpMSRR", "MSRR_Event", sSharePath),
21 m_sControlUrl("/MSRR_Control")
22{
24 new StateVariable<unsigned short>("AuthorizationGrantedUpdateID",
25 true));
27 new StateVariable<unsigned short>("AuthorizationDeniedUpdateID", true));
29 new StateVariable<unsigned short>("ValidationSucceededUpdateID", true));
31 new StateVariable<unsigned short>("ValidationRevokedUpdateID", true));
32
33 SetValue<unsigned short>("AuthorizationGrantedUpdateID", 0);
34 SetValue<unsigned short>("AuthorizationDeniedUpdateID" , 0);
35 SetValue<unsigned short>("ValidationSucceededUpdateID" , 0);
36 SetValue<unsigned short>("ValidationRevokedUpdateID" , 0);
37
38 QString sUPnpDescPath = XmlConfiguration().GetValue("UPnP/DescXmlPath", m_sSharePath);
39
40 m_sServiceDescFileName = sUPnpDescPath + "MSRR_scpd.xml";
41
42 // Add our Service Definition to the device.
43 RegisterService( pDevice );
44}
45
47//
49
50UPnpMSRRMethod UPnpMSRR::GetMethod( const QString &sURI )
51{
52 if (sURI == "GetServDesc" )
54 if (sURI == "IsAuthorized" )
55 return MSRR_IsAuthorized;
56 if (sURI == "RegisterDevice" )
58 if (sURI == "IsValidated" )
59 return MSRR_IsValidated;
60
61 return MSRR_Unknown;
62}
63
65//
67
69{
71}
72
74//
76
78{
79 if (pRequest)
80 {
81 if (Eventing::ProcessRequest( pRequest ))
82 return true;
83
84 if ( pRequest->m_sBaseUrl != m_sControlUrl )
85 return false;
86
87 LOG(VB_UPNP, LOG_INFO,
88 QString("UPnpMSRR::ProcessRequest : %1 : %2 :")
89 .arg(pRequest->m_sBaseUrl, pRequest->m_sMethod));
90
91 switch(GetMethod(pRequest->m_sMethod))
92 {
95 break;
97 HandleIsAuthorized( pRequest );
98 break;
100 HandleRegisterDevice( pRequest );
101 break;
102 case MSRR_IsValidated :
103 HandleIsValidated( pRequest );
104 break;
105 default:
107 break;
108 }
109 }
110
111 return( true );
112}
113
115//
117
119{
120 /* Always tell the user they are authorized to access this data */
121 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsAuthorized");
122 NameValues list;
123
124 list.push_back(NameValue("Result", "1"));
125
126 list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes", true);
127 list.back().AddAttribute("dt:dt", "int", true);
128
129 pRequest->FormatActionResponse(list);
130}
131
133//
135
137{
138 /* Sure, register, we don't really care */
139 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleRegisterDevice");
140 NameValues list;
141
142 list.push_back(NameValue("Result", "1"));
143
144 pRequest->FormatActionResponse(list);
145}
146
148{
149 /* You are valid sir */
150 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsValidated");
151 NameValues list;
152
153 list.push_back(NameValue("Result", "1"));
154
155 list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes", true);
156 list.back().AddAttribute( "dt:dt", "int", true);
157
158 pRequest->FormatActionResponse(list);
159}
160
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:147
QStringList GetBasePaths() override
Definition: eventing.cpp:135
QString m_sMethod
Definition: httprequest.h:130
void FormatFileResponse(const QString &sFileName)
void FormatActionResponse(Serializer *ser)
QString m_sBaseUrl
Definition: httprequest.h:128
QString m_sSharePath
Definition: httpserver.h:74
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:186
static void HandleIsAuthorized(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:118
UPnpMSRR(UPnpDevice *pDevice, const QString &sSharePath)
Definition: upnpmsrr.cpp:19
static void HandleIsValidated(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:147
QString m_sServiceDescFileName
Definition: upnpmsrr.h:31
QString m_sControlUrl
Definition: upnpmsrr.h:32
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpmsrr.cpp:77
static UPnpMSRRMethod GetMethod(const QString &sURI)
Definition: upnpmsrr.cpp:50
static void HandleRegisterDevice(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:136
QStringList GetBasePaths() override
Definition: upnpmsrr.cpp:68
void RegisterService(UPnpDevice *device)
Creates a UPnpService and adds it to the UPnpDevice's list of services.
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:242
QString GetValue(const QString &setting)
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
@ UPnPResult_InvalidAction
Definition: upnp.h:37
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