|
MythTV
0.26-pre
|
00001 00002 // Program Name: upnpmsrr.cpp 00003 // 00004 // Purpose - uPnp Microsoft Media Receiver Registrar "fake" Service 00005 // 00007 00008 #include "upnp.h" 00009 #include "upnpmsrr.h" 00010 #include "mythlogging.h" 00011 00012 #include <cmath> 00013 #include <QRegExp> 00014 00016 // 00018 00019 UPnpMSRR::UPnpMSRR( UPnpDevice *pDevice, const QString &sSharePath ) 00020 : Eventing( "UPnpMSRR", "MSRR_Event", sSharePath) 00021 { 00022 AddVariable( 00023 new StateVariable<unsigned short>("AuthorizationGrantedUpdateID", 00024 true)); 00025 AddVariable( 00026 new StateVariable<unsigned short>("AuthorizationDeniedUpdateID", true)); 00027 AddVariable( 00028 new StateVariable<unsigned short>("ValidationSucceededUpdateID", true)); 00029 AddVariable( 00030 new StateVariable<unsigned short>("ValidationRevokedUpdateID", true)); 00031 00032 SetValue<unsigned short>("AuthorizationGrantedUpdateID", 0); 00033 SetValue<unsigned short>("AuthorizationDeniedUpdateID" , 0); 00034 SetValue<unsigned short>("ValidationSucceededUpdateID" , 0); 00035 SetValue<unsigned short>("ValidationRevokedUpdateID" , 0); 00036 00037 QString sUPnpDescPath = 00038 UPnp::GetConfiguration()->GetValue( "UPnP/DescXmlPath", m_sSharePath ); 00039 00040 m_sServiceDescFileName = sUPnpDescPath + "MSRR_scpd.xml"; 00041 m_sControlUrl = "/MSRR_Control"; 00042 00043 // Add our Service Definition to the device. 00044 RegisterService( pDevice ); 00045 } 00046 00048 // 00050 00051 UPnpMSRR::~UPnpMSRR() 00052 { 00053 } 00054 00056 // 00058 00059 UPnpMSRRMethod UPnpMSRR::GetMethod( const QString &sURI ) 00060 { 00061 if (sURI == "GetServDesc" ) 00062 return MSRR_GetServiceDescription; 00063 if (sURI == "IsAuthorized" ) 00064 return MSRR_IsAuthorized; 00065 if (sURI == "RegisterDevice" ) 00066 return MSRR_RegisterDevice; 00067 if (sURI == "IsValidated" ) 00068 return MSRR_IsValidated; 00069 00070 return MSRR_Unknown; 00071 } 00072 00074 // 00076 00077 QStringList UPnpMSRR::GetBasePaths() 00078 { 00079 return Eventing::GetBasePaths() << m_sControlUrl; 00080 } 00081 00083 // 00085 00086 bool UPnpMSRR::ProcessRequest( HTTPRequest *pRequest ) 00087 { 00088 if (pRequest) 00089 { 00090 if (Eventing::ProcessRequest( pRequest )) 00091 return true; 00092 00093 if ( pRequest->m_sBaseUrl != m_sControlUrl ) 00094 return false; 00095 00096 LOG(VB_UPNP, LOG_INFO, 00097 QString("UPnpMSRR::ProcessRequest : %1 : %2 :") 00098 .arg(pRequest->m_sBaseUrl) .arg(pRequest->m_sMethod)); 00099 00100 switch(GetMethod(pRequest->m_sMethod)) 00101 { 00102 case MSRR_GetServiceDescription : 00103 pRequest->FormatFileResponse( m_sServiceDescFileName ); 00104 break; 00105 case MSRR_IsAuthorized : 00106 HandleIsAuthorized( pRequest ); 00107 break; 00108 case MSRR_RegisterDevice : 00109 HandleRegisterDevice( pRequest ); 00110 break; 00111 case MSRR_IsValidated : 00112 HandleIsValidated( pRequest ); 00113 break; 00114 default: 00115 UPnp::FormatErrorResponse( pRequest, UPnPResult_InvalidAction ); 00116 break; 00117 } 00118 } 00119 00120 return( true ); 00121 } 00122 00124 // 00126 00127 void UPnpMSRR::HandleIsAuthorized( HTTPRequest *pRequest ) 00128 { 00129 /* Always tell the user they are authorized to access this data */ 00130 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsAuthorized"); 00131 NameValues list; 00132 00133 list.push_back(NameValue("Result", "1")); 00134 00135 list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes"); 00136 list.back().AddAttribute("dt:dt", "int"); 00137 00138 pRequest->FormatActionResponse(list); 00139 } 00140 00142 // 00144 00145 void UPnpMSRR::HandleRegisterDevice( HTTPRequest *pRequest ) 00146 { 00147 /* Sure, register, we don't really care */ 00148 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleRegisterDevice"); 00149 NameValues list; 00150 00151 list.push_back(NameValue("Result", "1")); 00152 00153 pRequest->FormatActionResponse(list); 00154 } 00155 00156 void UPnpMSRR::HandleIsValidated( HTTPRequest *pRequest ) 00157 { 00158 /* You are valid sir */ 00159 LOG(VB_UPNP, LOG_DEBUG, "UPnpMSRR::HandleIsValidated"); 00160 NameValues list; 00161 00162 list.push_back(NameValue("Result", "1")); 00163 00164 list.back().AddAttribute("xmlns:dt", "urn:schemas-microsoft-com:datatypes"); 00165 list.back().AddAttribute( "dt:dt", "int"); 00166 00167 pRequest->FormatActionResponse(list); 00168 } 00169
1.7.6.1