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 #include <QRegExp>
14 
16 //
18 
19 UPnpMSRR::UPnpMSRR( UPnpDevice *pDevice, const QString &sSharePath )
20  : Eventing( "UPnpMSRR", "MSRR_Event", sSharePath)
21 {
23  new StateVariable<unsigned short>("AuthorizationGrantedUpdateID",
24  true));
26  new StateVariable<unsigned short>("AuthorizationDeniedUpdateID", true));
28  new StateVariable<unsigned short>("ValidationSucceededUpdateID", true));
30  new StateVariable<unsigned short>("ValidationRevokedUpdateID", true));
31 
32  SetValue<unsigned short>("AuthorizationGrantedUpdateID", 0);
33  SetValue<unsigned short>("AuthorizationDeniedUpdateID" , 0);
34  SetValue<unsigned short>("ValidationSucceededUpdateID" , 0);
35  SetValue<unsigned short>("ValidationRevokedUpdateID" , 0);
36 
37  QString sUPnpDescPath =
38  UPnp::GetConfiguration()->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) .arg(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:52
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:125
HTTPRequest
Definition: httprequest.h:108
Eventing::GetBasePaths
QStringList GetBasePaths() override
Definition: eventing.cpp:129
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:127
UPnpMSRR::HandleIsAuthorized
static void HandleIsAuthorized(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:119
arg
arg(title).arg(filename).arg(doDelete))
Eventing
Definition: eventing.h:254
StateVariable
Definition: eventing.h:118
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
Eventing::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:141
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:280
NameValues
Definition: upnputil.h:88
HTTPRequest::FormatActionResponse
void FormatActionResponse(Serializer *ser)
Definition: httprequest.cpp:753
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:19
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:100
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:841
upnpmsrr.h
MSRR_RegisterDevice
@ MSRR_RegisterDevice
Definition: upnpmsrr.h:18
UPnpMSRR::HandleIsValidated
static void HandleIsValidated(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:148
Configuration::GetValue
virtual int GetValue(const QString &sSetting, int Default)=0
StateVariables::AddVariable
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:191
UPnpMSRR::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpmsrr.cpp:78
UPnp::GetConfiguration
static Configuration * GetConfiguration()
Definition: upnp.cpp:84
UPnpMSRRMethod
UPnpMSRRMethod
Definition: upnpmsrr.h:14
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