MythTV  master
upnpmsrr.cpp
Go to the documentation of this file.
1 // Program Name: upnpmsrr.cpp
3 //
4 // Purpose - uPnp Microsoft Media Receiver Registrar "fake" Service
5 //
7 
8 #include "upnp.h"
9 #include "upnpmsrr.h"
10 #include "mythlogging.h"
11 
12 #include <cmath>
13 
15 //
17 
18 UPnpMSRR::UPnpMSRR( UPnpDevice *pDevice, const QString &sSharePath )
19  : Eventing( "UPnpMSRR", "MSRR_Event", sSharePath)
20 {
22  new StateVariable<unsigned short>("AuthorizationGrantedUpdateID",
23  true));
25  new StateVariable<unsigned short>("AuthorizationDeniedUpdateID", true));
27  new StateVariable<unsigned short>("ValidationSucceededUpdateID", true));
29  new StateVariable<unsigned short>("ValidationRevokedUpdateID", true));
30 
31  SetValue<unsigned short>("AuthorizationGrantedUpdateID", 0);
32  SetValue<unsigned short>("AuthorizationDeniedUpdateID" , 0);
33  SetValue<unsigned short>("ValidationSucceededUpdateID" , 0);
34  SetValue<unsigned short>("ValidationRevokedUpdateID" , 0);
35 
36  QString sUPnpDescPath =
37  UPnp::GetConfiguration()->GetValue( "UPnP/DescXmlPath", m_sSharePath );
38 
39  m_sServiceDescFileName = sUPnpDescPath + "MSRR_scpd.xml";
40  m_sControlUrl = "/MSRR_Control";
41 
42  // Add our Service Definition to the device.
43  RegisterService( pDevice );
44 }
45 
47 //
49 
50 UPnpMSRRMethod UPnpMSRR::GetMethod( const QString &sURI )
51 {
52  if (sURI == "GetServDesc" )
54  if (sURI == "IsAuthorized" )
55  return MSRR_IsAuthorized;
56  if (sURI == "RegisterDevice" )
57  return MSRR_RegisterDevice;
58  if (sURI == "IsValidated" )
59  return MSRR_IsValidated;
60 
61  return MSRR_Unknown;
62 }
63 
65 //
67 
68 QStringList UPnpMSRR::GetBasePaths()
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;
96  case MSRR_IsAuthorized :
97  HandleIsAuthorized( pRequest );
98  break;
99  case MSRR_RegisterDevice :
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 
NameValue
Definition: upnputil.h:52
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:126
HTTPRequest
Definition: httprequest.h:108
Eventing::GetBasePaths
QStringList GetBasePaths() override
Definition: eventing.cpp:141
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:128
UPnpMSRR::HandleIsAuthorized
static void HandleIsAuthorized(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:118
Eventing
Definition: eventing.h:245
StateVariable
Definition: eventing.h:112
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
Eventing::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:153
UPnpMSRR::GetBasePaths
QStringList GetBasePaths() override
Definition: upnpmsrr.cpp:68
MSRR_IsAuthorized
@ MSRR_IsAuthorized
Definition: upnpmsrr.h:17
UPnp::FormatErrorResponse
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:280
NameValues
Definition: upnputil.h:89
HTTPRequest::FormatActionResponse
void FormatActionResponse(Serializer *ser)
Definition: httprequest.cpp:770
UPnpServiceImpl::RegisterService
void RegisterService(UPnpDevice *device)
Creates a UPnpService and adds it to the UPnpDevice's list of services.
Definition: upnpserviceimpl.cpp:5
UPnpMSRR::UPnpMSRR
UPnpMSRR(UPnpDevice *pDevice, const QString &sSharePath)
Definition: upnpmsrr.cpp:18
upnp.h
mythlogging.h
UPnpMSRR::GetMethod
static UPnpMSRRMethod GetMethod(const QString &sURI)
Definition: upnpmsrr.cpp:50
MSRR_GetServiceDescription
@ MSRR_GetServiceDescription
Definition: upnpmsrr.h:16
UPnpDevice
Definition: upnpdevice.h:101
UPnpMSRR::m_sControlUrl
QString m_sControlUrl
Definition: upnpmsrr.h:34
UPnPResult_InvalidAction
@ UPnPResult_InvalidAction
Definition: upnp.h:40
MSRR_IsValidated
@ MSRR_IsValidated
Definition: upnpmsrr.h:19
MSRR_Unknown
@ MSRR_Unknown
Definition: upnpmsrr.h:15
HTTPRequest::FormatFileResponse
void FormatFileResponse(const QString &sFileName)
Definition: httprequest.cpp:858
upnpmsrr.h
MSRR_RegisterDevice
@ MSRR_RegisterDevice
Definition: upnpmsrr.h:18
UPnpMSRR::HandleIsValidated
static void HandleIsValidated(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:147
Configuration::GetValue
virtual int GetValue(const QString &sSetting, int Default)=0
StateVariables::AddVariable
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:186
UPnpMSRR::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpmsrr.cpp:77
UPnp::GetConfiguration
static Configuration * GetConfiguration()
Definition: upnp.cpp:84
UPnpMSRRMethod
UPnpMSRRMethod
Definition: upnpmsrr.h:13
UPnpMSRR::m_sServiceDescFileName
QString m_sServiceDescFileName
Definition: upnpmsrr.h:33
UPnpMSRR::HandleRegisterDevice
static void HandleRegisterDevice(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:136
HttpServerExtension::m_sSharePath
QString m_sSharePath
Definition: httpserver.h:76