00001
00002
00003
00004
00005
00006
00007
00008
00010
00011 #include "upnp.h"
00012 #include "upnpcmgr.h"
00013
00015
00017
00018 UPnpCMGR::UPnpCMGR ( UPnpDevice *pDevice,
00019 const QString &sSharePath,
00020 const QString &sSourceProtocols,
00021 const QString &sSinkProtocols )
00022 : Eventing( "UPnpCMGR", "CMGR_Event" )
00023 {
00024 AddVariable( new StateVariable< QString >( "SourceProtocolInfo" , true ) );
00025 AddVariable( new StateVariable< QString >( "SinkProtocolInfo" , true ) );
00026 AddVariable( new StateVariable< QString >( "CurrentConnectionIDs", true ) );
00027
00028 SetValue< QString >( "CurrentConnectionIDs", "0" );
00029 SetValue< QString >( "SourceProtocolInfo" , sSourceProtocols );
00030 SetValue< QString >( "SinkProtocolInfo" , sSinkProtocols );
00031
00032 QString sUPnpDescPath = UPnp::g_pConfig->GetValue( "UPnP/DescXmlPath",
00033 sSharePath );
00034 m_sSharePath = sSharePath;
00035 m_sServiceDescFileName = sUPnpDescPath + "CMGR_scpd.xml";
00036 m_sControlUrl = "/CMGR_Control";
00037
00038
00039
00040 RegisterService( pDevice );
00041 }
00042
00044
00046
00047 UPnpCMGR::~UPnpCMGR()
00048 {
00049 }
00050
00052
00054
00055 void UPnpCMGR::AddSourceProtocol( const QString &sProtocol )
00056 {
00057 QString sValue = GetValue< QString >( "SourceProtocolInfo" );
00058
00059 if (sValue.length() > 0 )
00060 sValue += ",";
00061
00062 sValue += sProtocol;
00063
00064 SetValue< QString >( "SourceProtocolInfo", sValue );
00065 }
00066
00068
00070
00071 void UPnpCMGR::AddSinkProtocol( const QString &sProtocol )
00072 {
00073 QString sValue = GetValue< QString >( "SinkProtocolInfo" );
00074
00075 if (sValue.length() > 0 )
00076 sValue += ",";
00077
00078 sValue += sProtocol;
00079
00080 SetValue< QString >( "SinkProtocolInfo", sValue );
00081 }
00082
00083
00085
00087
00088 UPnpCMGRMethod UPnpCMGR::GetMethod( const QString &sURI )
00089 {
00090 if (sURI == "GetServDesc" ) return CMGRM_GetServiceDescription ;
00091 if (sURI == "GetProtocolInfo" ) return CMGRM_GetProtocolInfo ;
00092 if (sURI == "GetCurrentConnectionInfo" ) return CMGRM_GetCurrentConnectionInfo;
00093 if (sURI == "GetCurrentConnectionIDs" ) return CMGRM_GetCurrentConnectionIDs ;
00094
00095 return CMGRM_Unknown;
00096 }
00097
00099
00101
00102 bool UPnpCMGR::ProcessRequest( HttpWorkerThread *pThread, HTTPRequest *pRequest )
00103 {
00104 if (pRequest)
00105 {
00106 if (Eventing::ProcessRequest( pThread, pRequest ))
00107 return true;
00108
00109 if ( pRequest->m_sBaseUrl != m_sControlUrl )
00110 {
00111
00112 return false;
00113 }
00114
00115 VERBOSE( VB_UPNP, QString("UPnpCMGR::ProcessRequest - Method (%1)").arg(pRequest->m_sMethod ));
00116
00117 switch( GetMethod( pRequest->m_sMethod ) )
00118 {
00119 case CMGRM_GetServiceDescription : pRequest->FormatFileResponse ( m_sServiceDescFileName ); break;
00120 case CMGRM_GetProtocolInfo : HandleGetProtocolInfo ( pRequest ); break;
00121 case CMGRM_GetCurrentConnectionInfo: HandleGetCurrentConnectionInfo( pRequest ); break;
00122 case CMGRM_GetCurrentConnectionIDs : HandleGetCurrentConnectionIDs ( pRequest ); break;
00123 default:
00124 UPnp::FormatErrorResponse( pRequest, UPnPResult_InvalidAction );
00125 break;
00126 }
00127 return true;
00128 }
00129
00130 return false;
00131 }
00132
00134
00136
00137 void UPnpCMGR::HandleGetProtocolInfo( HTTPRequest *pRequest )
00138 {
00139 NameValueList list;
00140
00141 list.append( new NameValue( "Source", GetValue< QString >( "SourceProtocolInfo")));
00142 list.append( new NameValue( "Sink" , GetValue< QString >( "SinkProtocolInfo" )));
00143
00144 pRequest->FormatActionResponse( &list );
00145 }
00146
00148
00150
00151 void UPnpCMGR::HandleGetCurrentConnectionInfo( HTTPRequest *pRequest )
00152 {
00153 unsigned short nId = pRequest->m_mapParams[ "ConnectionID" ].toUShort();
00154
00155 if ( nId != 0)
00156 {
00157 UPnp::FormatErrorResponse( pRequest, UPnPResult_CMGR_InvalidConnectionRef );
00158 return;
00159 }
00160
00161 NameValueList list;
00162
00163 list.append( new NameValue( "RcsID" , "-1" ));
00164 list.append( new NameValue( "AVTransportID" , "-1" ));
00165 list.append( new NameValue( "ProtocolInfo" , "http-get:*:*:*" ));
00166 list.append( new NameValue( "PeerConnectionManager", "/" ));
00167 list.append( new NameValue( "PeerConnectionID" , "-1" ));
00168 list.append( new NameValue( "Direction" , "Output" ));
00169 list.append( new NameValue( "Status" , "Unknown" ));
00170
00171 pRequest->FormatActionResponse( &list );
00172
00173 }
00174
00176
00178
00179 void UPnpCMGR::HandleGetCurrentConnectionIDs ( HTTPRequest *pRequest )
00180 {
00181 NameValueList list;
00182
00183 list.append( new NameValue( "ConnectionIDs", GetValue< QString >( "CurrentConnectionIDs" )));
00184
00185 pRequest->FormatActionResponse( &list );
00186
00187 }