MythTV  master
upnpcmgr.cpp
Go to the documentation of this file.
1 // Program Name: UPnpCMGR.cpp
3 // Created : Dec. 28, 2006
4 //
5 // Purpose : uPnp Connection Manager Service
6 //
7 // Copyright (c) 2006 David Blain <dblain@mythtv.org>
8 //
9 // Licensed under the GPL v2 or later, see LICENSE for details
10 //
12 
16 
17 #include "upnp.h"
18 #include "upnpcmgr.h"
19 
21 //
23 
25  const QString &sSharePath,
26  const QString &sSourceProtocols,
27  const QString &sSinkProtocols )
28  : Eventing( "UPnpCMGR", "CMGR_Event", sSharePath)
29 {
30  AddVariable( new StateVariable< QString >( "SourceProtocolInfo" , true ) );
31  AddVariable( new StateVariable< QString >( "SinkProtocolInfo" , true ) );
32  AddVariable( new StateVariable< QString >( "CurrentConnectionIDs", true ) );
33  AddVariable( new StateVariable< QString >( "FeatureList" , true ) );
34 
35  SetValue< QString >( "CurrentConnectionIDs", "0" );
36  SetValue< QString >( "SourceProtocolInfo" , sSourceProtocols );
37  SetValue< QString >( "SinkProtocolInfo" , sSinkProtocols );
38  SetValue< QString >( "FeatureList" , "" );
39 
40  QString sUPnpDescPath = MythCoreContext::GetConfiguration()->GetValue( "UPnP/DescXmlPath",
41  m_sSharePath );
42  m_sServiceDescFileName = sUPnpDescPath + "CMGR_scpd.xml";
43  m_sControlUrl = "/CMGR_Control";
44 
45  // Add our Service Definition to the device.
46 
47  RegisterService( pDevice );
48 
49  // ConnectionManager uses a different schema definition for the FeatureList
50  // to the ContentDirectoryService
52  "urn:schemas-upnp-org:av:cm-featureList" ));
53  m_features.AddAttribute(NameValue( "xmlns:xsi",
54  "http://www.w3.org/2001/XMLSchema-instance" ));
55  m_features.AddAttribute(NameValue( "xsi:schemaLocation",
56  "urn:schemas-upnp-org:av:cm-featureList "
57  "http://www.upnp.org/schemas/av/cm-featureList.xsd" ));
58 }
59 
61 //
63 
64 void UPnpCMGR::AddSourceProtocol( const QString &sProtocol )
65 {
66  auto sValue = GetValue< QString >( "SourceProtocolInfo" );
67 
68  if (sValue.length() > 0 )
69  sValue += ',';
70 
71  sValue += sProtocol;
72 
73  SetValue< QString >( "SourceProtocolInfo", sValue );
74 }
75 
77 //
79 
80 void UPnpCMGR::AddSinkProtocol( const QString &sProtocol )
81 {
82  auto sValue = GetValue< QString >( "SinkProtocolInfo" );
83 
84  if (sValue.length() > 0 )
85  sValue += ',';
86 
87  sValue += sProtocol;
88 
89  SetValue< QString >( "SinkProtocolInfo", sValue );
90 }
91 
92 
94 //
96 
97 UPnpCMGRMethod UPnpCMGR::GetMethod( const QString &sURI )
98 {
99  if (sURI == "GetServDesc" ) return CMGRM_GetServiceDescription ;
100  if (sURI == "GetProtocolInfo" ) return CMGRM_GetProtocolInfo ;
101  if (sURI == "GetCurrentConnectionInfo" ) return CMGRM_GetCurrentConnectionInfo;
102  if (sURI == "GetCurrentConnectionIDs" ) return CMGRM_GetCurrentConnectionIDs ;
103  if (sURI == "GetFeatureList" ) return CMGRM_GetFeatureList ;
104 
105  return CMGRM_Unknown;
106 }
107 
109 //
111 
113 {
115 }
116 
118 //
120 
122 {
123  if (pRequest)
124  {
125  if (Eventing::ProcessRequest( pRequest ))
126  return true;
127 
128  if ( pRequest->m_sBaseUrl != m_sControlUrl )
129  {
130 #if 0
131  LOG(VB_UPNP, LOG_DEBUG,
132  QString("UPnpCMGR::ProcessRequest - BaseUrl (%1) not ours...")
133  .arg(pRequest->m_sBaseUrl));
134 #endif
135  return false;
136  }
137 
138  LOG(VB_UPNP, LOG_INFO,
139  QString("UPnpCMGR::ProcessRequest - Method (%1)")
140  .arg(pRequest->m_sMethod));
141 
142  switch( GetMethod( pRequest->m_sMethod ) )
143  {
146  break;
147  case CMGRM_GetProtocolInfo :
148  HandleGetProtocolInfo( pRequest );
149  break;
151  HandleGetCurrentConnectionInfo( pRequest );
152  break;
154  HandleGetCurrentConnectionIDs ( pRequest );
155  break;
156  case CMGRM_GetFeatureList :
157  HandleGetFeatureList( pRequest );
158  break;
159  default:
161  break;
162  }
163  return true;
164  }
165 
166  return false;
167 }
168 
170 //
172 
174 {
175  NameValues list;
176 
177  list.push_back(
178  NameValue("Source", GetValue<QString>("SourceProtocolInfo")));
179  list.push_back(
180  NameValue("Sink", GetValue<QString>("SinkProtocolInfo")));
181 
182  pRequest->FormatActionResponse(list);
183 }
184 
186 //
188 
190 {
191  unsigned short nId = pRequest->m_mapParams[ "ConnectionID" ].toUShort();
192 
193  if ( nId != 0)
194  {
195  UPnp::FormatErrorResponse( pRequest,
197  return;
198  }
199 
200  NameValues list;
201 
202  list.push_back(NameValue( "RcsID" , "-1" , true));
203  list.push_back(NameValue( "AVTransportID" , "-1" , true));
204  list.push_back(NameValue( "ProtocolInfo" , "http-get:*:*:*" , true));
205  list.push_back(NameValue( "PeerConnectionManager", "/" , true));
206  list.push_back(NameValue( "PeerConnectionID" , "-1" , true));
207  list.push_back(NameValue( "Direction" , "Output" , true));
208  list.push_back(NameValue( "Status" , "Unknown" , true));
209 
210  pRequest->FormatActionResponse(list);
211 }
212 
214 //
216 
218 {
219  NameValues list;
220 
221  list.push_back(
222  NameValue("ConnectionIDs", GetValue<QString>("CurrentConnectionIDs")));
223 
224  pRequest->FormatActionResponse(list);
225 }
226 
228 {
229  NameValues list;
230 
231  QString sResults = m_features.toXML();
232 
233  list.push_back(NameValue("FeatureList", sResults));
234 
235  pRequest->FormatActionResponse(list);
236 }
NameValue
Definition: upnputil.h:40
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:126
HTTPRequest
Definition: httprequest.h:108
UPnpCMGR::m_sControlUrl
QString m_sControlUrl
Definition: upnpcmgr.h:53
CMGRM_GetServiceDescription
@ CMGRM_GetServiceDescription
Definition: upnpcmgr.h:22
Eventing::GetBasePaths
QStringList GetBasePaths() override
Definition: eventing.cpp:143
UPnpCMGR::UPnpCMGR
UPnpCMGR(UPnpDevice *pDevice, const QString &sSharePath, const QString &sSourceProtocols="", const QString &sSinkProtocols="")
Definition: upnpcmgr.cpp:24
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:128
Eventing
Definition: eventing.h:245
StateVariable
Definition: eventing.h:112
UPnpCMGR::HandleGetCurrentConnectionIDs
void HandleGetCurrentConnectionIDs(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:217
upnpcmgr.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
Eventing::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:155
UPnp::FormatErrorResponse
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:241
CMGRM_GetFeatureList
@ CMGRM_GetFeatureList
Definition: upnpcmgr.h:26
UPnpCMGRMethod
UPnpCMGRMethod
Definition: upnpcmgr.h:19
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
upnp.h
mythlogging.h
UPnpCMGR::HandleGetFeatureList
void HandleGetFeatureList(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:227
UPnpCMGR::AddSourceProtocol
void AddSourceProtocol(const QString &sProtocol)
Definition: upnpcmgr.cpp:64
HTTPRequest::m_mapParams
QStringMap m_mapParams
Definition: httprequest.h:130
UPnpCMGR::AddSinkProtocol
void AddSinkProtocol(const QString &sProtocol)
Definition: upnpcmgr.cpp:80
CMGRM_Unknown
@ CMGRM_Unknown
Definition: upnpcmgr.h:21
UPnPFeatureList::AddAttribute
void AddAttribute(const NameValue &attribute)
Definition: upnpserviceimpl.cpp:41
UPnpDevice
Definition: upnpdevice.h:102
CMGRM_GetProtocolInfo
@ CMGRM_GetProtocolInfo
Definition: upnpcmgr.h:23
UPnpCMGR::m_features
UPnPFeatureList m_features
Definition: upnpcmgr.h:55
CMGRM_GetCurrentConnectionIDs
@ CMGRM_GetCurrentConnectionIDs
Definition: upnpcmgr.h:25
UPnPResult_CMGR_InvalidConnectionRef
@ UPnPResult_CMGR_InvalidConnectionRef
Definition: upnp.h:81
UPnPResult_InvalidAction
@ UPnPResult_InvalidAction
Definition: upnp.h:39
mythcorecontext.h
CMGRM_GetCurrentConnectionInfo
@ CMGRM_GetCurrentConnectionInfo
Definition: upnpcmgr.h:24
HTTPRequest::FormatFileResponse
void FormatFileResponse(const QString &sFileName)
Definition: httprequest.cpp:788
UPnpCMGR::m_sServiceDescFileName
QString m_sServiceDescFileName
Definition: upnpcmgr.h:52
configuration.h
UPnpCMGR::HandleGetCurrentConnectionInfo
static void HandleGetCurrentConnectionInfo(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:189
Configuration::GetValue
virtual int GetValue(const QString &sSetting, int Default)=0
StateVariables::AddVariable
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:186
UPnpCMGR::GetMethod
static UPnpCMGRMethod GetMethod(const QString &sURI)
Definition: upnpcmgr.cpp:97
UPnPFeatureList::toXML
QString toXML()
Definition: upnpserviceimpl.cpp:46
UPnpCMGR::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpcmgr.cpp:121
UPnpCMGR::HandleGetProtocolInfo
void HandleGetProtocolInfo(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:173
UPnpCMGR::GetBasePaths
QStringList GetBasePaths() override
Definition: upnpcmgr.cpp:112
HttpServerExtension::m_sSharePath
QString m_sSharePath
Definition: httpserver.h:78
MythCoreContext::GetConfiguration
static Configuration * GetConfiguration()
Definition: mythcorecontext.cpp:1838