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 <cmath>
9 
12 
13 #include "upnp.h"
14 #include "upnpmsrr.h"
15 
17 //
19 
20 UPnpMSRR::UPnpMSRR( UPnpDevice *pDevice, const QString &sSharePath )
21  : Eventing( "UPnpMSRR", "MSRR_Event", sSharePath)
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  m_sControlUrl = "/MSRR_Control";
42 
43  // Add our Service Definition to the device.
44  RegisterService( pDevice );
45 }
46 
48 //
50 
51 UPnpMSRRMethod UPnpMSRR::GetMethod( const QString &sURI )
52 {
53  if (sURI == "GetServDesc" )
55  if (sURI == "IsAuthorized" )
56  return MSRR_IsAuthorized;
57  if (sURI == "RegisterDevice" )
58  return MSRR_RegisterDevice;
59  if (sURI == "IsValidated" )
60  return MSRR_IsValidated;
61 
62  return MSRR_Unknown;
63 }
64 
66 //
68 
69 QStringList UPnpMSRR::GetBasePaths()
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;
97  case MSRR_IsAuthorized :
98  HandleIsAuthorized( pRequest );
99  break;
100  case MSRR_RegisterDevice :
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 
NameValue
Definition: upnputil.h:40
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:127
HTTPRequest
Definition: httprequest.h:109
Eventing::GetBasePaths
QStringList GetBasePaths() override
Definition: eventing.cpp:134
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:129
UPnpMSRR::HandleIsAuthorized
static void HandleIsAuthorized(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:119
Eventing
Definition: eventing.h:245
StateVariable
Definition: eventing.h:112
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:39
Eventing::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:146
UPnpMSRR::GetBasePaths
QStringList GetBasePaths() override
Definition: upnpmsrr.cpp:69
MSRR_IsAuthorized
@ MSRR_IsAuthorized
Definition: upnpmsrr.h:17
UPnp::FormatErrorResponse
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:242
XmlConfiguration
Definition: configuration.h:38
NameValues
Definition: upnputil.h:77
HTTPRequest::FormatActionResponse
void FormatActionResponse(Serializer *ser)
Definition: httprequest.cpp:700
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:20
upnp.h
mythlogging.h
UPnpMSRR::GetMethod
static UPnpMSRRMethod GetMethod(const QString &sURI)
Definition: upnpmsrr.cpp:51
MSRR_GetServiceDescription
@ MSRR_GetServiceDescription
Definition: upnpmsrr.h:16
UPnpDevice
Definition: upnpdevice.h:102
UPnpMSRR::m_sControlUrl
QString m_sControlUrl
Definition: upnpmsrr.h:34
UPnPResult_InvalidAction
@ UPnPResult_InvalidAction
Definition: upnp.h:39
MSRR_IsValidated
@ MSRR_IsValidated
Definition: upnpmsrr.h:19
MSRR_Unknown
@ MSRR_Unknown
Definition: upnpmsrr.h:15
XmlConfiguration::GetValue
QString GetValue(const QString &setting)
Definition: configuration.cpp:185
HTTPRequest::FormatFileResponse
void FormatFileResponse(const QString &sFileName)
Definition: httprequest.cpp:788
upnpmsrr.h
MSRR_RegisterDevice
@ MSRR_RegisterDevice
Definition: upnpmsrr.h:18
configuration.h
UPnpMSRR::HandleIsValidated
static void HandleIsValidated(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:148
StateVariables::AddVariable
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:186
UPnpMSRR::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpmsrr.cpp:78
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:137
HttpServerExtension::m_sSharePath
QString m_sSharePath
Definition: httpserver.h:78