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 COPYING for details
10 //
12 
13 #include "upnp.h"
14 #include "upnpcmgr.h"
15 #include "mythlogging.h"
16 
18 //
20 
22  const QString &sSharePath,
23  const QString &sSourceProtocols,
24  const QString &sSinkProtocols )
25  : Eventing( "UPnpCMGR", "CMGR_Event", sSharePath)
26 {
27  AddVariable( new StateVariable< QString >( "SourceProtocolInfo" , true ) );
28  AddVariable( new StateVariable< QString >( "SinkProtocolInfo" , true ) );
29  AddVariable( new StateVariable< QString >( "CurrentConnectionIDs", true ) );
30  AddVariable( new StateVariable< QString >( "FeatureList" , true ) );
31 
32  SetValue< QString >( "CurrentConnectionIDs", "0" );
33  SetValue< QString >( "SourceProtocolInfo" , sSourceProtocols );
34  SetValue< QString >( "SinkProtocolInfo" , sSinkProtocols );
35  SetValue< QString >( "FeatureList" , "" );
36 
37  QString sUPnpDescPath = UPnp::GetConfiguration()->GetValue( "UPnP/DescXmlPath",
38  m_sSharePath );
39  m_sServiceDescFileName = sUPnpDescPath + "CMGR_scpd.xml";
40  m_sControlUrl = "/CMGR_Control";
41 
42  // Add our Service Definition to the device.
43 
44  RegisterService( pDevice );
45 
46  // ConnectionManager uses a different schema definition for the FeatureList
47  // to the ContentDirectoryService
49  "urn:schemas-upnp-org:av:cm-featureList" ));
50  m_features.AddAttribute(NameValue( "xmlns:xsi",
51  "http://www.w3.org/2001/XMLSchema-instance" ));
52  m_features.AddAttribute(NameValue( "xsi:schemaLocation",
53  "urn:schemas-upnp-org:av:cm-featureList "
54  "http://www.upnp.org/schemas/av/cm-featureList.xsd" ));
55 }
56 
58 //
60 
61 void UPnpCMGR::AddSourceProtocol( const QString &sProtocol )
62 {
63  auto sValue = GetValue< QString >( "SourceProtocolInfo" );
64 
65  if (sValue.length() > 0 )
66  sValue += ',';
67 
68  sValue += sProtocol;
69 
70  SetValue< QString >( "SourceProtocolInfo", sValue );
71 }
72 
74 //
76 
77 void UPnpCMGR::AddSinkProtocol( const QString &sProtocol )
78 {
79  auto sValue = GetValue< QString >( "SinkProtocolInfo" );
80 
81  if (sValue.length() > 0 )
82  sValue += ',';
83 
84  sValue += sProtocol;
85 
86  SetValue< QString >( "SinkProtocolInfo", sValue );
87 }
88 
89 
91 //
93 
94 UPnpCMGRMethod UPnpCMGR::GetMethod( const QString &sURI )
95 {
96  if (sURI == "GetServDesc" ) return CMGRM_GetServiceDescription ;
97  if (sURI == "GetProtocolInfo" ) return CMGRM_GetProtocolInfo ;
98  if (sURI == "GetCurrentConnectionInfo" ) return CMGRM_GetCurrentConnectionInfo;
99  if (sURI == "GetCurrentConnectionIDs" ) return CMGRM_GetCurrentConnectionIDs ;
100  if (sURI == "GetFeatureList" ) return CMGRM_GetFeatureList ;
101 
102  return CMGRM_Unknown;
103 }
104 
106 //
108 
110 {
112 }
113 
115 //
117 
119 {
120  if (pRequest)
121  {
122  if (Eventing::ProcessRequest( pRequest ))
123  return true;
124 
125  if ( pRequest->m_sBaseUrl != m_sControlUrl )
126  {
127 #if 0
128  LOG(VB_UPNP, LOG_DEBUG,
129  QString("UPnpCMGR::ProcessRequest - BaseUrl (%1) not ours...")
130  .arg(pRequest->m_sBaseUrl));
131 #endif
132  return false;
133  }
134 
135  LOG(VB_UPNP, LOG_INFO,
136  QString("UPnpCMGR::ProcessRequest - Method (%1)")
137  .arg(pRequest->m_sMethod));
138 
139  switch( GetMethod( pRequest->m_sMethod ) )
140  {
143  break;
144  case CMGRM_GetProtocolInfo :
145  HandleGetProtocolInfo( pRequest );
146  break;
148  HandleGetCurrentConnectionInfo( pRequest );
149  break;
151  HandleGetCurrentConnectionIDs ( pRequest );
152  break;
153  case CMGRM_GetFeatureList :
154  HandleGetFeatureList( pRequest );
155  break;
156  default:
158  break;
159  }
160  return true;
161  }
162 
163  return false;
164 }
165 
167 //
169 
171 {
172  NameValues list;
173 
174  list.push_back(
175  NameValue("Source", GetValue<QString>("SourceProtocolInfo")));
176  list.push_back(
177  NameValue("Sink", GetValue<QString>("SinkProtocolInfo")));
178 
179  pRequest->FormatActionResponse(list);
180 }
181 
183 //
185 
187 {
188  unsigned short nId = pRequest->m_mapParams[ "ConnectionID" ].toUShort();
189 
190  if ( nId != 0)
191  {
192  UPnp::FormatErrorResponse( pRequest,
194  return;
195  }
196 
197  NameValues list;
198 
199  list.push_back(NameValue( "RcsID" , "-1" , true));
200  list.push_back(NameValue( "AVTransportID" , "-1" , true));
201  list.push_back(NameValue( "ProtocolInfo" , "http-get:*:*:*" , true));
202  list.push_back(NameValue( "PeerConnectionManager", "/" , true));
203  list.push_back(NameValue( "PeerConnectionID" , "-1" , true));
204  list.push_back(NameValue( "Direction" , "Output" , true));
205  list.push_back(NameValue( "Status" , "Unknown" , true));
206 
207  pRequest->FormatActionResponse(list);
208 }
209 
211 //
213 
215 {
216  NameValues list;
217 
218  list.push_back(
219  NameValue("ConnectionIDs", GetValue<QString>("CurrentConnectionIDs")));
220 
221  pRequest->FormatActionResponse(list);
222 }
223 
225 {
226  NameValues list;
227 
228  QString sResults = m_features.toXML();
229 
230  list.push_back(NameValue("FeatureList", sResults));
231 
232  pRequest->FormatActionResponse(list);
233 }
NameValue
Definition: upnputil.h:52
HTTPRequest::m_sBaseUrl
QString m_sBaseUrl
Definition: httprequest.h:125
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:129
UPnpCMGR::UPnpCMGR
UPnpCMGR(UPnpDevice *pDevice, const QString &sSharePath, const QString &sSourceProtocols="", const QString &sSinkProtocols="")
Definition: upnpcmgr.cpp:21
HTTPRequest::m_sMethod
QString m_sMethod
Definition: httprequest.h:127
arg
arg(title).arg(filename).arg(doDelete))
Eventing
Definition: eventing.h:254
StateVariable
Definition: eventing.h:118
UPnpCMGR::HandleGetCurrentConnectionIDs
void HandleGetCurrentConnectionIDs(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:214
upnpcmgr.h
LOG
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
Definition: mythlogging.h:23
Eventing::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: eventing.cpp:141
UPnp::FormatErrorResponse
static void FormatErrorResponse(HTTPRequest *pRequest, UPnPResultCode eCode, const QString &sMsg="")
Definition: upnp.cpp:280
CMGRM_GetFeatureList
@ CMGRM_GetFeatureList
Definition: upnpcmgr.h:26
UPnpCMGRMethod
UPnpCMGRMethod
Definition: upnpcmgr.h:20
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
upnp.h
mythlogging.h
UPnpCMGR::HandleGetFeatureList
void HandleGetFeatureList(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:224
UPnpCMGR::AddSourceProtocol
void AddSourceProtocol(const QString &sProtocol)
Definition: upnpcmgr.cpp:61
HTTPRequest::m_mapParams
QStringMap m_mapParams
Definition: httprequest.h:129
UPnpCMGR::AddSinkProtocol
void AddSinkProtocol(const QString &sProtocol)
Definition: upnpcmgr.cpp:77
CMGRM_Unknown
@ CMGRM_Unknown
Definition: upnpcmgr.h:21
UPnPFeatureList::AddAttribute
void AddAttribute(const NameValue &attribute)
Definition: upnpserviceimpl.cpp:41
UPnpDevice
Definition: upnpdevice.h:100
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:82
UPnPResult_InvalidAction
@ UPnPResult_InvalidAction
Definition: upnp.h:40
CMGRM_GetCurrentConnectionInfo
@ CMGRM_GetCurrentConnectionInfo
Definition: upnpcmgr.h:24
HTTPRequest::FormatFileResponse
void FormatFileResponse(const QString &sFileName)
Definition: httprequest.cpp:841
UPnpCMGR::m_sServiceDescFileName
QString m_sServiceDescFileName
Definition: upnpcmgr.h:52
UPnpCMGR::HandleGetCurrentConnectionInfo
static void HandleGetCurrentConnectionInfo(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:186
Configuration::GetValue
virtual int GetValue(const QString &sSetting, int Default)=0
StateVariables::AddVariable
void AddVariable(StateVariableBase *pBase)
Definition: eventing.h:191
UPnpCMGR::GetMethod
static UPnpCMGRMethod GetMethod(const QString &sURI)
Definition: upnpcmgr.cpp:94
UPnp::GetConfiguration
static Configuration * GetConfiguration()
Definition: upnp.cpp:84
UPnPFeatureList::toXML
QString toXML()
Definition: upnpserviceimpl.cpp:46
UPnpCMGR::ProcessRequest
bool ProcessRequest(HTTPRequest *pRequest) override
Definition: upnpcmgr.cpp:118
UPnpCMGR::HandleGetProtocolInfo
void HandleGetProtocolInfo(HTTPRequest *pRequest)
Definition: upnpcmgr.cpp:170
UPnpCMGR::GetBasePaths
QStringList GetBasePaths() override
Definition: upnpcmgr.cpp:109
HttpServerExtension::m_sSharePath
QString m_sSharePath
Definition: httpserver.h:78