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