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 
QStringList GetBasePaths() override
Definition: eventing.cpp:129
virtual int GetValue(const QString &sSetting, int Default)=0
static void HandleIsAuthorized(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:119
QString m_sBaseUrl
Definition: httprequest.h:125
QString m_sSharePath
Definition: httpserver.h:78
void RegisterService(UPnpDevice *device)
Creates a UPnpService and adds it to the UPnpDevice's list of services.
UPnpMSRRMethod
Definition: upnpmsrr.h:13
QString m_sMethod
Definition: httprequest.h:127
UPnpMSRR(UPnpDevice *pDevice, const QString &sSharePath)
Definition: upnpmsrr.cpp:19
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:267
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpmsrr.cpp:78
static UPnpMSRRMethod GetMethod(const QString &sURI)
Definition: upnpmsrr.cpp:51
void FormatActionResponse(Serializer *ser)
static Configuration * GetConfiguration()
Definition: upnp.cpp:71
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:141
static void HandleIsValidated(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:148
QStringList GetBasePaths() override
Definition: upnpmsrr.cpp:69
#define LOG(_MASK_, _LEVEL_, _STRING_)
Definition: mythlogging.h:41
static void HandleRegisterDevice(HTTPRequest *pRequest)
Definition: upnpmsrr.cpp:137
QString m_sControlUrl
Definition: upnpmsrr.h:34
QString m_sServiceDescFileName
Definition: upnpmsrr.h:33
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:191
void FormatFileResponse(const QString &sFileName)