HX_RESULT CBaseArchiver2::NotifyTempFileCreated(const char* pszTempFileName) { // Need to notify clients of the writer of the name of the temp file // This is a feature for the player team that enables them to play // back the temp files while encoding/writing the files. HX_RESULT res = HXR_OK; if(pszTempFileName) { IHXValues* pStatusInfo = NULL; CreateValuesCCF(pStatusInfo, m_pClassFactory); HX_ASSERT(pStatusInfo); if(pStatusInfo) { IHXBuffer* pBufTempFile = NULL; CreateBufferCCF(pBufTempFile, m_pContext); HX_ASSERT(pBufTempFile); if(pBufTempFile) { res = pBufTempFile->Set((UCHAR*)pszTempFileName, strlen(pszTempFileName) + 1); HX_ASSERT(SUCCEEDED(res)); if(SUCCEEDED(res)) { res = pStatusInfo->SetPropertyCString("TempFileName", pBufTempFile); HX_ASSERT(SUCCEEDED(res)); if(SUCCEEDED(res)) { // Send back the name of the temp file created m_pMonitor->OnStatus(HXR_OK, pStatusInfo); } } HX_RELEASE(pBufTempFile); } else { res = HXR_OUTOFMEMORY; } HX_RELEASE(pStatusInfo); } else { res = HXR_OUTOFMEMORY; } } else { res = HXR_POINTER; } return res; }
/************************************************************************ * Method: * IHXPacketHookManager::StartHook * Purpose: * called by the top level client to start recording */ STDMETHODIMP PacketHookManager::StartHook () { HX_RESULT hr = HXR_OK; UINT16 i = 0; UINT16 j = 0; UINT16 k = 0; UINT16 ulSources = 0; UINT16 ulStreams = 0; UINT16 ulStreamIndex = 0; IHXBuffer* pTitle = NULL; IHXBuffer* pAuthor = NULL; IHXBuffer* pCopyright = NULL; IHXValues* pFileHeader = NULL; IHXValues* pStreamHeader = NULL; IUnknown* pUnknown = NULL; IHXPrivateStreamSource *pPrivateSource = NULL; // for IsSaveAllowed, take this out; XXXCP IHXStreamSource* pSource = NULL; IHXInfoLogger* pInfoLogger = NULL; // make sure everything has been initialized if (!m_pPlayer || !m_pPacketHook) { hr = HXR_FAILED; goto cleanup; } // caculate the total number of streams + TAC info. if (!(ulSources = m_pPlayer->GetSourceCount())) { hr = HXR_FAILED; goto cleanup; } m_ulTotalStreams = 0; for (i = 0; i < ulSources; i++) { if (HXR_OK != m_pPlayer->GetSource(i, pUnknown)) { continue; } if (HXR_OK != pUnknown->QueryInterface(IID_IHXStreamSource, (void**)&pSource)) { HX_RELEASE(pUnknown); continue; } if (HXR_OK == pUnknown->QueryInterface(IID_IHXPrivateStreamSource, (void**)&pPrivateSource)) { if (!(pPrivateSource->IsSaveAllowed())) { pPrivateSource->Release(); continue; } pPrivateSource->Release(); } m_ulTotalStreams += pSource->GetStreamCount(); HX_RELEASE(pSource); HX_RELEASE(pUnknown); } if (!m_ulTotalStreams) { hr = HXR_FAILED; goto cleanup; } // prepare the file header CreateBufferCCF(pTitle, m_pPlayer); CreateBufferCCF(pAuthor, m_pPlayer); CreateBufferCCF(pCopyright, m_pPlayer); // XXX HP: find better way to collect TAC info #define szTitle "title" #define szAuthor "author" #define szCopyright "copyright" pTitle->Set((const unsigned char*)szTitle, strlen(szTitle)+1); pAuthor->Set((const unsigned char*)szAuthor, strlen(szAuthor)+1); pCopyright->Set((const unsigned char*)szCopyright, strlen(szCopyright)+1); if (HXR_OK == CreateValuesCCF(pFileHeader, m_pPlayer)) { // set attributes(i.e. num. of streams + TAC) pFileHeader->SetPropertyBuffer("Title", pTitle); pFileHeader->SetPropertyBuffer("Author", pAuthor); pFileHeader->SetPropertyBuffer("Copyright", pCopyright); pFileHeader->SetPropertyULONG32("StreamCount", m_ulTotalStreams); } // signal the top level client of upcoming content m_pPacketHook->OnStart(); // send file header to its top level client hr = m_pPacketHook->OnFileHeader(pFileHeader); if (hr != HXR_OK) { HX_RELEASE(m_pPacketHook); goto cleanup; } // prepare the stream headers m_ulRecordableStreams = 0; ulStreamIndex = 0; for (i = 0; i < ulSources; i++) { if (HXR_OK != m_pPlayer->GetSource(i, pUnknown)) { HX_RELEASE(pUnknown); continue; } if (HXR_OK != pUnknown->QueryInterface(IID_IHXStreamSource, (void**)&pSource)) { HX_RELEASE(pSource); continue; } if (HXR_OK == pUnknown->QueryInterface(IID_IHXPrivateStreamSource, (void**)&pPrivateSource)) { if (!(pPrivateSource->IsSaveAllowed())) { pPrivateSource->Release(); continue; } pPrivateSource->Release(); } if (HXR_OK == pUnknown->QueryInterface(IID_IHXInfoLogger, (void**)&pInfoLogger)) { pInfoLogger->LogInformation("RECSTART", NULL); } HX_RELEASE(pInfoLogger); ulStreams = pSource->GetStreamCount(); for (j = 0; j < ulStreams; j++) { const char* pszPropName = NULL; UINT16 ulRenderers = 0; ULONG32 ulPropValue = 0; HXBOOL bRecordable = FALSE; IHXValues* pHeader = NULL; IHXBuffer* pPropValueSource = NULL; IHXBuffer* pPropValueTarget = NULL; IHXStream* pStream = NULL; // retrieve the stream info pSource->GetStream(j, (IUnknown*&)pStream); pHeader = pStream->GetHeader(); // make a copy of this stream header // XXX HP: this could be wrapped up into one method in CHXHeader CreateValuesCCF(pStreamHeader, m_pPlayer); // copy all the ULONG32 attributes if (HXR_OK == pHeader->GetFirstPropertyULONG32(pszPropName, ulPropValue)) { pStreamHeader->SetPropertyULONG32(pszPropName, ulPropValue); while (HXR_OK == pHeader->GetNextPropertyULONG32(pszPropName, ulPropValue)) { pStreamHeader->SetPropertyULONG32(pszPropName, ulPropValue); } } // copy all the buffer attributes if (HXR_OK == pHeader->GetFirstPropertyBuffer(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyBuffer(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); while (HXR_OK == pHeader->GetNextPropertyBuffer(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyBuffer(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); } } // copy all the CString attributes if (HXR_OK == pHeader->GetFirstPropertyCString(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyCString(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); while (HXR_OK == pHeader->GetNextPropertyCString(pszPropName, (IHXBuffer*&)pPropValueSource)) { if (HXR_OK == CreateAndSetBufferCCF(pPropValueTarget, pPropValueSource->GetBuffer(), pPropValueSource->GetSize(), m_pPlayer)) { pStreamHeader->SetPropertyCString(pszPropName, pPropValueTarget); HX_RELEASE(pPropValueTarget); } HX_RELEASE(pPropValueSource); } } HX_RELEASE(pHeader); // modify some values pStreamHeader->SetPropertyULONG32("StreamNumber", ulStreamIndex); // the stream is recordable as long as there is one renderer supports // IHXPacketHookHelper. Multiple renderers can serve the packets with // the same stream number on it, One solution for this is to choose the // first renderer which supports IHXPacketHookHelper as the only source ulRenderers = pStream->GetRendererCount(); for (k = 0; k < ulRenderers; k++) { IUnknown* pUnknown = NULL; IHXPacketHookHelper* pPacketHookHelper = NULL; pStream->GetRenderer(k, pUnknown); if (HXR_OK == pUnknown->QueryInterface(IID_IHXPacketHookHelper, (void**)&pPacketHookHelper)) { bRecordable = TRUE; pPacketHookHelper->StartHook(ulStreamIndex, 0, new PacketHookHelperResponse(this, ulStreamIndex)); } HX_RELEASE(pPacketHookHelper); HX_RELEASE(pUnknown); } if (bRecordable) { m_ulRecordableStreams++; } pStreamHeader->SetPropertyULONG32("Recordable", (ULONG32)bRecordable); /* * It's possible that StartHook will cause the m_pPacketHook to * be released */ if (!m_pPacketHook) { hr = HXR_UNEXPECTED; goto cleanup; } // send stream header to its top level client hr = m_pPacketHook->OnStreamHeader(pStreamHeader); if (hr != HXR_OK) { HX_RELEASE(m_pPacketHook); goto cleanup; } ulStreamIndex++; HX_RELEASE(pStreamHeader); HX_RELEASE(pStream); } HX_RELEASE(pSource); HX_RELEASE(pUnknown); } cleanup: HX_RELEASE(pTitle); HX_RELEASE(pAuthor); HX_RELEASE(pCopyright); HX_RELEASE(pFileHeader); return hr; }
IHXValues* DataRevertController::InflateConvertHeader(IHXBuffer* pInflate) { IHXValues* pNewHeader = NULL; IHXCommonClassFactory* pCCF; m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&pCCF); pCCF->CreateInstance(CLSID_IHXValues, (void**)&pNewHeader); ULONG32 ul; IHXBuffer* pBuffer; const char* p; IHXBuffer* pTemp; ULONG32 ulTemp; pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pTemp); UINT32 limit = pInflate->GetSize(); UINT32 i = 0; p = (const char*)pInflate->GetBuffer(); while (i < pInflate->GetSize() - 5) { if (p[i] == 'u') { i++; ulTemp = getlong((UINT8*) &(p[i])); i += 4; if (i + ulTemp > limit) { goto error; } pTemp->SetSize(ulTemp + 1); memcpy((char *)pTemp->GetBuffer(), &(p[i]), ulTemp); /* Flawfinder: ignore */ ((char*)pTemp->GetBuffer())[ulTemp] = 0; i += ulTemp; if (i + 4 > limit) { goto error; } ul = getlong((UINT8*) &(p[i])); i += 4; pNewHeader->SetPropertyULONG32((char*)pTemp->GetBuffer(), ul); } else if (p[i] == 's' || p[i] == 'b') { int at = i; i++; ulTemp = getlong((UINT8*) &(p[i])); i += 4; if (i + ulTemp > limit) { goto error; } pTemp->SetSize(ulTemp + 1); memcpy((char*)pTemp->GetBuffer(), &(p[i]), ulTemp); /* Flawfinder: ignore */ ((char*)pTemp->GetBuffer())[ulTemp] = 0; i += ulTemp; if (i + 4 > limit) { goto error; } ulTemp = getlong((UINT8*) &(p[i])); i += 4; if (i + ulTemp > limit) { goto error; } pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pBuffer); pBuffer->SetSize(ulTemp); memcpy((char*)pBuffer->GetBuffer(), &(p[i]), ulTemp); /* Flawfinder: ignore */ if (p[at] == 's') { pNewHeader->SetPropertyCString((const char*)pTemp->GetBuffer(), pBuffer); } else { pNewHeader->SetPropertyBuffer((const char*)pTemp->GetBuffer(), pBuffer); } pBuffer->Release(); i+= ulTemp; } else { goto error; } } if (i != pInflate->GetSize()) { goto error; } goto exit; error:; exit:; HX_RELEASE(pTemp); HX_RELEASE(pCCF); return pNewHeader; }
void DataRevertController::RevertHeaders(IHXValues* pFileHeader, CHXSimpleList* pStreamHeaders, IHXValues* pResponseHeaders) { IHXBuffer* pMimeType = 0; IHXValues* pHeader; CHXSimpleList::Iterator i; char* pConversionType = NULL; IUnknown* pUnkReverter = NULL; HX_RELEASE(m_pDataRevert); i = pStreamHeaders->Begin(); if (i != pStreamHeaders->End()) { pHeader = (IHXValues*)(*i); pHeader->GetPropertyCString("MimeType", pMimeType); if (!pMimeType) { HX_ASSERT(0); goto exit; } if (strncasecmp((const char*)pMimeType->GetBuffer(), HX_CONVERT_MIME_TYPE, (int)strlen(HX_CONVERT_MIME_TYPE))) { goto exit; } pConversionType = (char*)pMimeType->GetBuffer() + strlen(HX_CONVERT_MIME_TYPE); if (m_pPlugin2Handler && HXR_OK == m_pPlugin2Handler->FindPluginUsingStrings( PLUGIN_CLASS, PLUGIN_REVERTER_TYPE, PLUGIN_REVERTER_MIME, pConversionType, NULL, NULL, pUnkReverter)) { pUnkReverter->QueryInterface(IID_IHXDataRevert, (void**)&m_pDataRevert); pUnkReverter->Release(); } if (!m_pDataRevert) { goto exit; } IHXPlugin* pPlugin; m_pDataRevert->QueryInterface(IID_IHXPlugin, (void**)&pPlugin); pPlugin->InitPlugin(m_pContext); pPlugin->Release(); HX_RELEASE(pMimeType); m_pStreamHeaders = new CHXSimpleList; m_pRevertedStreamHeaders = new CHXSimpleList; IHXBuffer* pConvertHeader = 0; for (i = pStreamHeaders->Begin(); i != pStreamHeaders->End(); ++i) { pHeader = (IHXValues*)(*i); /* * If this stream header was converted and flattened then * the one we want to give to the plugin is the result * of re-inflating that. If not, then just give the plugin * the one we already got. */ if (HXR_OK == pHeader->GetPropertyBuffer("DataConvertStreamHeader", pConvertHeader)) { pHeader = InflateConvertHeader(pConvertHeader); pConvertHeader->Release(); } else { IHXBuffer* pPreConvertMimeType; if (HXR_OK == pHeader->GetPropertyCString("PreConvertMimeType", pPreConvertMimeType)) { pHeader->SetPropertyCString("MimeType", pPreConvertMimeType); pPreConvertMimeType->Release(); } pHeader->AddRef(); } m_pStreamHeaders->AddTail((void*)pHeader); } m_pResponseHeaders = pResponseHeaders; m_pResponseHeaders->AddRef(); /* * If playing through an old proxy which does not support * initiate-session then the DataConvertBuffer will come in here. * This is not an ideal situation because only one can come in * at this point, but it's better then nothing. */ IHXBuffer* pConvertBuffer = 0; if (HXR_OK == pFileHeader->GetPropertyBuffer("DataConvertBuffer", pConvertBuffer)) { const char* pContent = (const char*)pConvertBuffer->GetBuffer(); IHXBuffer* pNewBuffer = NULL; if (HXR_OK == CreateBufferCCF(pNewBuffer, m_pContext)) { int contentLen = pConvertBuffer->GetSize(); pNewBuffer->SetSize(contentLen); int offset = BinFrom64(pContent, contentLen, (unsigned char*)pNewBuffer->GetBuffer()); pNewBuffer->SetSize(offset); ControlBufferReady(pNewBuffer); HX_RELEASE(pNewBuffer); } HX_RELEASE(pConvertBuffer); } /* * Again for file header, if the header was converted and * flattened then give to plugin the inflated version of that. * If not, then give the straight old header that we already * have. */ if (HXR_OK == pFileHeader->GetPropertyBuffer("DataConvertFileHeader", pConvertHeader)) { m_pFileHeaders = InflateConvertHeader(pConvertHeader); pConvertHeader->Release(); } else { m_pFileHeaders = pFileHeader; m_pFileHeaders->AddRef(); } m_pDataRevert->DataRevertInit(this); return; } exit:; HX_RELEASE(pMimeType); m_pControlResp->RevertHeadersDone(pFileHeader, pStreamHeaders, pResponseHeaders, FALSE); }
/************************************************************************ * Method: * IHXSiteSupplier::SitesNeeded * Purpose: * Called to inform the site supplier that a site with a particular * set of characteristics is needed. If the site supplier can * fulfill the request it should call the site manager and add one * or more new sites. * Note that the request for sites is associated with a Request ID * the client core will inform the site supplier when this requested * site is no longer needed. */ STDMETHODIMP ExampleSiteSupplier::SitesNeeded ( UINT32 uRequestID, IHXValues* pProps ) { /* * Don't create a site if the -NULL_RENDER command line option * was given. - jfarr */ if (GetGlobal()->g_bNullRender) { return (HXR_OK); } /* * If there are no properties, then we can't really create a * site, because we have no idea what type of site is desired! */ if (!pProps) { return HXR_INVALID_PARAMETER; } HRESULT hres = HXR_OK; IHXValues* pSiteProps = NULL; IHXSiteWindowed* pSiteWindowed = NULL; IHXBuffer* pValue = NULL; UINT32 style = 0; IHXSite* pSite = NULL; // Just let the RMA client core create a windowed site for us. hres = m_pCCF->CreateInstance(CLSID_IHXSiteWindowed,(void**)&pSiteWindowed); if (HXR_OK != hres) { goto exit; } hres = pSiteWindowed->QueryInterface(IID_IHXSite,(void**)&pSite); if (HXR_OK != hres) { goto exit; } if( !m_pSite ) { m_pSite = pSite; m_pSite->AddRef(); } hres = pSiteWindowed->QueryInterface(IID_IHXValues,(void**)&pSiteProps); if (HXR_OK != hres) { goto exit; } /* * We need to figure out what type of site we are supposed to * to create. We need to "switch" between site user and site * properties. So look for the well known site user properties * that are mapped onto sites... */ hres = pProps->GetPropertyCString("playto",pValue); if (HXR_OK == hres) { pSiteProps->SetPropertyCString("channel",pValue); HX_RELEASE(pValue); } else { hres = pProps->GetPropertyCString("name",pValue); if (HXR_OK == hres) { pSiteProps->SetPropertyCString("LayoutGroup",pValue); HX_RELEASE(pValue); } } #ifdef _WINDOWS style = WS_OVERLAPPED | WS_VISIBLE | WS_CLIPCHILDREN; #endif hres = pSiteWindowed->Create(NULL, style); if (HXR_OK != hres) { goto exit; } /* * We need to wait until we have set all the properties before * we add the site. */ hres = m_pSiteManager->AddSite(pSite); if (HXR_OK != hres) { goto exit; } #ifdef _WINDOWS { HXxWindow* pWindow = pSiteWindowed->GetWindow(); if (pWindow && pWindow->window) ::SetForegroundWindow( (HWND)(pWindow->window) ); } #endif m_CreatedSites.SetAt((void*)uRequestID,pSite); pSite->AddRef(); exit: HX_RELEASE(pSiteProps); HX_RELEASE(pSiteWindowed); HX_RELEASE(pSite); return hres; }
HX_RESULT HXCloakedV2TCPSocket::_DoProxyAuthentication(HTTPResponseMessage* pMess) { HX_RESULT res = HXR_FAIL; IHXCommonClassFactory* pCCF = NULL; CHXString getStr = ""; IHXKeyValueList* pRespHeaders = NULL; MIMEHeaderValue* pHeaderValue = NULL; MIMEHeader* pHeader = NULL; CHXString strHeader = ""; CHXString strTemp = ""; IHXBuffer* pBuffer = NULL; IHXRequest* pRequest = NULL; IHXValues* pValues = NULL; IHXClientAuthConversation* pClientAuth = NULL; IUnknown* pUnkConfig = NULL; IHXObjectConfiguration* pConfig = NULL; ////////////////////// // // XXXgfw I really don't think we need all this authentication // garbage. It really seems we only need to TLC to just give us a // dialog to do a user/pass request. It sure seems like this code // below is way overkill. Just check out ResponseReady(), the only // thing is needs from all this is just that one string. Oh well, // until I have time to figure out exactly how this all works (all // the calls through the core and into the TLC from here) I will // just leave it like the original cloaking. // ////////////////////// res = m_pContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&pCCF); if( SUCCEEDED(res) ) { //pRequest will be freed in the ResponseReady() method. res = pCCF->CreateInstance(CLSID_IHXRequest, (void**)&pRequest); if( SUCCEEDED(res) ) { getStr = _GenerateGetRequest(); pRequest->SetURL((const char*)getStr); //Always returns HXR_OK; res = pCCF->CreateInstance(CLSID_IHXKeyValueList, (void**)&pRespHeaders); if( SUCCEEDED(res) ) { pHeader = pMess->getFirstHeader(); while (pHeader) { pHeaderValue = pHeader->getFirstHeaderValue(); strHeader = ""; while( pHeaderValue ) { pHeaderValue->asString(strTemp); strHeader += strTemp; pHeaderValue = pHeader->getNextHeaderValue(); if (pHeaderValue) { strHeader += ", "; } } pBuffer = NULL; CHXBuffer::FromCharArray((const char*)strHeader, &pBuffer); if( pBuffer ) { pRespHeaders->AddKeyValue(pHeader->name(), pBuffer); } HX_RELEASE(pBuffer); pHeader = pMess->getNextHeader(); } pValues = NULL; if (HXR_OK == pRespHeaders->QueryInterface(IID_IHXValues, (void**)&pValues)) { pRequest->SetResponseHeaders(pValues); } HX_RELEASE(pValues); } HX_RELEASE(pRespHeaders); if (HXR_OK == pRequest->GetResponseHeaders(pValues)) { res = pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pBuffer); if (SUCCEEDED(res)) { pBuffer->Set((UCHAR*)m_pszProxyName, strlen(m_pszProxyName)+1); pValues->SetPropertyCString("_server", pBuffer); HX_RELEASE(pBuffer); } // Add the protocol to the response headers because TLC needs it if (SUCCEEDED(pCCF->CreateInstance(CLSID_IHXBuffer, (void**)&pBuffer))) { pBuffer->Set((UCHAR*)"http", strlen("http") + 1); pValues->SetPropertyCString("_protocol", pBuffer); HX_RELEASE(pBuffer); } HX_RELEASE(pValues); } //We now need a CCF from the cloaking context, not our core's context. HX_RELEASE(pCCF); res = m_pCloakContext->QueryInterface(IID_IHXCommonClassFactory, (void**)&pCCF); if(SUCCEEDED(res)) { res = pCCF->CreateInstance( CLSID_CHXClientAuthenticator, (void**)&pUnkConfig ); if(SUCCEEDED(res)) { res = pUnkConfig->QueryInterface(IID_IHXClientAuthConversation, (void**)&pClientAuth); if (SUCCEEDED(res)) { res = pUnkConfig->QueryInterface(IID_IHXObjectConfiguration, (void**)&pConfig); if (SUCCEEDED(res)) { pConfig->SetContext(m_pCloakContext); HX_RELEASE(pConfig); } if ( pClientAuth && !pClientAuth->IsDone() ) { HX_ASSERT(pRequest); //After this if/else, we continue in ResponseReady() after //the TLC calls us back. if (pRequest) { res = pClientAuth->MakeResponse(this, pRequest); } else { // Auth Failed! pClientAuth->Authenticated(FALSE); res = HXR_NOT_AUTHORIZED; res = ResponseReady(res, pRequest); } } } HX_RELEASE(pUnkConfig); } HX_RELEASE(pCCF); } } } //We return this in all cases. the connection will be started over in //the ResponseReady() method. res = HXR_NOT_AUTHORIZED; return res; }