00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00012
00013 #include "upnp.h"
00014 #include "upnpcmgr.h"
00015 #include "mythlogging.h"
00016
00018
00020
00021 UPnpCMGR::UPnpCMGR ( UPnpDevice *pDevice,
00022 const QString &sSharePath,
00023 const QString &sSourceProtocols,
00024 const QString &sSinkProtocols )
00025 : Eventing( "UPnpCMGR", "CMGR_Event", sSharePath)
00026 {
00027 AddVariable( new StateVariable< QString >( "SourceProtocolInfo" , true ) );
00028 AddVariable( new StateVariable< QString >( "SinkProtocolInfo" , true ) );
00029 AddVariable( new StateVariable< QString >( "CurrentConnectionIDs", true ) );
00030
00031 SetValue< QString >( "CurrentConnectionIDs", "0" );
00032 SetValue< QString >( "SourceProtocolInfo" , sSourceProtocols );
00033 SetValue< QString >( "SinkProtocolInfo" , sSinkProtocols );
00034
00035 QString sUPnpDescPath = UPnp::GetConfiguration()->GetValue( "UPnP/DescXmlPath",
00036 m_sSharePath );
00037 m_sServiceDescFileName = sUPnpDescPath + "CMGR_scpd.xml";
00038 m_sControlUrl = "/CMGR_Control";
00039
00040
00041
00042 RegisterService( pDevice );
00043 }
00044
00046
00048
00049 UPnpCMGR::~UPnpCMGR()
00050 {
00051 }
00052
00054
00056
00057 void UPnpCMGR::AddSourceProtocol( const QString &sProtocol )
00058 {
00059 QString sValue = GetValue< QString >( "SourceProtocolInfo" );
00060
00061 if (sValue.length() > 0 )
00062 sValue += ',';
00063
00064 sValue += sProtocol;
00065
00066 SetValue< QString >( "SourceProtocolInfo", sValue );
00067 }
00068
00070
00072
00073 void UPnpCMGR::AddSinkProtocol( const QString &sProtocol )
00074 {
00075 QString sValue = GetValue< QString >( "SinkProtocolInfo" );
00076
00077 if (sValue.length() > 0 )
00078 sValue += ',';
00079
00080 sValue += sProtocol;
00081
00082 SetValue< QString >( "SinkProtocolInfo", sValue );
00083 }
00084
00085
00087
00089
00090 UPnpCMGRMethod UPnpCMGR::GetMethod( const QString &sURI )
00091 {
00092 if (sURI == "GetServDesc" ) return CMGRM_GetServiceDescription ;
00093 if (sURI == "GetProtocolInfo" ) return CMGRM_GetProtocolInfo ;
00094 if (sURI == "GetCurrentConnectionInfo" ) return CMGRM_GetCurrentConnectionInfo;
00095 if (sURI == "GetCurrentConnectionIDs" ) return CMGRM_GetCurrentConnectionIDs ;
00096
00097 return CMGRM_Unknown;
00098 }
00099
00101
00103
00104 QStringList UPnpCMGR::GetBasePaths()
00105 {
00106 return Eventing::GetBasePaths() << m_sControlUrl;
00107 }
00108
00110
00112
00113 bool UPnpCMGR::ProcessRequest( HTTPRequest *pRequest )
00114 {
00115 if (pRequest)
00116 {
00117 if (Eventing::ProcessRequest( pRequest ))
00118 return true;
00119
00120 if ( pRequest->m_sBaseUrl != m_sControlUrl )
00121 {
00122 #if 0
00123 LOG(VB_UPNP, LOG_DEBUG,
00124 QString("UPnpCMGR::ProcessRequest - BaseUrl (%1) not ours...")
00125 .arg(pRequest->m_sBaseUrl));
00126 #endif
00127 return false;
00128 }
00129
00130 LOG(VB_UPNP, LOG_INFO,
00131 QString("UPnpCMGR::ProcessRequest - Method (%1)")
00132 .arg(pRequest->m_sMethod));
00133
00134 switch( GetMethod( pRequest->m_sMethod ) )
00135 {
00136 case CMGRM_GetServiceDescription :
00137 pRequest->FormatFileResponse( m_sServiceDescFileName );
00138 break;
00139 case CMGRM_GetProtocolInfo :
00140 HandleGetProtocolInfo( pRequest );
00141 break;
00142 case CMGRM_GetCurrentConnectionInfo:
00143 HandleGetCurrentConnectionInfo( pRequest );
00144 break;
00145 case CMGRM_GetCurrentConnectionIDs :
00146 HandleGetCurrentConnectionIDs ( pRequest );
00147 break;
00148 default:
00149 UPnp::FormatErrorResponse( pRequest, UPnPResult_InvalidAction );
00150 break;
00151 }
00152 return true;
00153 }
00154
00155 return false;
00156 }
00157
00159
00161
00162 void UPnpCMGR::HandleGetProtocolInfo( HTTPRequest *pRequest )
00163 {
00164 NameValues list;
00165
00166 list.push_back(
00167 NameValue("Source", GetValue<QString>("SourceProtocolInfo")));
00168 list.push_back(
00169 NameValue("Sink", GetValue<QString>("SinkProtocolInfo")));
00170
00171 pRequest->FormatActionResponse(list);
00172 }
00173
00175
00177
00178 void UPnpCMGR::HandleGetCurrentConnectionInfo( HTTPRequest *pRequest )
00179 {
00180 unsigned short nId = pRequest->m_mapParams[ "ConnectionID" ].toUShort();
00181
00182 if ( nId != 0)
00183 {
00184 UPnp::FormatErrorResponse( pRequest,
00185 UPnPResult_CMGR_InvalidConnectionRef );
00186 return;
00187 }
00188
00189 NameValues list;
00190
00191 list.push_back(NameValue( "RcsID" , "-1" ));
00192 list.push_back(NameValue( "AVTransportID" , "-1" ));
00193 list.push_back(NameValue( "ProtocolInfo" , "http-get:*:*:*" ));
00194 list.push_back(NameValue( "PeerConnectionManager", "/" ));
00195 list.push_back(NameValue( "PeerConnectionID" , "-1" ));
00196 list.push_back(NameValue( "Direction" , "Output" ));
00197 list.push_back(NameValue( "Status" , "Unknown" ));
00198
00199 pRequest->FormatActionResponse(list);
00200 }
00201
00203
00205
00206 void UPnpCMGR::HandleGetCurrentConnectionIDs ( HTTPRequest *pRequest )
00207 {
00208 NameValues list;
00209
00210 list.push_back(
00211 NameValue("ConnectionIDs", GetValue<QString>("CurrentConnectionIDs")));
00212
00213 pRequest->FormatActionResponse(list);
00214 }