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 
13 
14 #include "upnp.h"
15 #include "upnpmsrr.h"
16 
18 //
20 
21 UPnpMSRR::UPnpMSRR( UPnpDevice *pDevice, const QString &sSharePath )
22  : Eventing( "UPnpMSRR", "MSRR_Event", sSharePath)
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 =
41 
42  m_sServiceDescFileName = sUPnpDescPath + "MSRR_scpd.xml";
43  m_sControlUrl = "/MSRR_Control";
44 
45  // Add our Service Definition to the device.
46  RegisterService( pDevice );
47 }
48 
50 //
52 
53 UPnpMSRRMethod UPnpMSRR::GetMethod( const QString &sURI )
54 {
55  if (sURI == "GetServDesc" )
57  if (sURI == "IsAuthorized" )
58  return MSRR_IsAuthorized;
59  if (sURI == "RegisterDevice" )
60  return MSRR_RegisterDevice;
61  if (sURI == "IsValidated" )
62  return MSRR_IsValidated;
63 
64  return MSRR_Unknown;
65 }
66 
68 //
70 
71 QStringList UPnpMSRR::GetBasePaths()
72 {
74 }
75 
77 //
79 
81 {
82  if (pRequest)
83  {
84  if (Eventing::ProcessRequest( pRequest ))
85  return true;
86 
87  if ( pRequest->m_sBaseUrl != m_sControlUrl )
88  return false;
89 
90  LOG(VB_UPNP, LOG_INFO,
91  QString("UPnpMSRR::ProcessRequest : %1 : %2 :")
92  .arg(pRequest->m_sBaseUrl, pRequest->m_sMethod));
93 
94  switch(GetMethod(pRequest->m_sMethod))
95  {
98  break;
99  case MSRR_IsAuthorized :
100  HandleIsAuthorized( pRequest );
101  break;
102  case MSRR_RegisterDevice :
103  HandleRegisterDevice( pRequest );
104  break;
105  case MSRR_IsValidated :
106  HandleIsValidated( pRequest );
107  break;
108  default:
110  break;
111  }
112  }
113 
114  return( true );
115 }
116 
118 //
120 
122 {
123  /* Always tell the user they are authorized to access this data */
124  LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsAuthorized");
125  NameValues list;
126 
127  list.push_back(NameValue("Result", "1"));
128 
129  list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes", true);
130  list.back().AddAttribute("dt:dt", "int", true);
131 
132  pRequest->FormatActionResponse(list);
133 }
134 
136 //
138 
140 {
141  /* Sure, register, we don't really care */
142  LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleRegisterDevice");
143  NameValues list;
144 
145  list.push_back(NameValue("Result", "1"));
146 
147  pRequest->FormatActionResponse(list);
148 }
149 
151 {
152  /* You are valid sir */
153  LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsValidated");
154  NameValues list;
155 
156  list.push_back(NameValue("Result", "1"));
157 
158  list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes", true);
159  list.back().AddAttribute( "dt:dt", "int", true);
160 
161  pRequest->FormatActionResponse(list);
162 }
163 
NameValue
Definition: upnputil.h:40
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:126
HTTPRequest
Definition: httprequest.h:108
Eventing::GetBasePaths
QStringList GetBasePaths() override
Definition: eventing.cpp:143
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:128
UPnpMSRR::HandleIsAuthorized
static void HandleIsAuthorized(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:121
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:155
UPnpMSRR::GetBasePaths
QStringList GetBasePaths() override
Definition: upnpmsrr.cpp:71
MSRR_IsAuthorized
@ MSRR_IsAuthorized
Definition: upnpmsrr.h:17
UPnp::FormatErrorResponse
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:241
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:21
upnp.h
mythlogging.h
UPnpMSRR::GetMethod
static UPnpMSRRMethod GetMethod(const QString &sURI)
Definition: upnpmsrr.cpp:53
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
mythcorecontext.h
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:150
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:80
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:139
HttpServerExtension::m_sSharePath
QString m_sSharePath
Definition: httpserver.h:78
MythCoreContext::GetConfiguration
static Configuration * GetConfiguration()
Definition: mythcorecontext.cpp:1838