void CHTTPDemux::handleInput(IHXBuffer* pBuf) { UINT32 ulBufLen = 0; if (pBuf) { ulBufLen = pBuf->GetSize(); if (m_ulMsgLen+ulBufLen > MAX_HTTP_MSG_SIZE) { if (m_pSock) { IHXSockAddr* pAddr = 0; m_pSock->GetPeerAddr(&pAddr); if (pAddr) { IHXBuffer* pAddrBuf = 0; pAddr->GetAddr(&pAddrBuf); if (pAddrBuf) { fprintf(stderr, "W: Large HTTP message (greater than 64K) being received from addr <%s>.\n" " Possible DOS attack!\n", (const char *)pAddrBuf->GetBuffer()); pAddrBuf->Release(); } pAddr->Release(); } } Close(HXR_FAIL); return; } } if (m_pFragBuf == NULL) { pBuf->AddRef(); } else { IHXBuffer* pNewBuf = new CHXBuffer(); pNewBuf->AddRef(); pNewBuf->SetSize(m_pFragBuf->GetSize() + ulBufLen); memcpy(pNewBuf->GetBuffer(), m_pFragBuf->GetBuffer(), m_pFragBuf->GetSize()); memcpy(pNewBuf->GetBuffer()+m_pFragBuf->GetSize(), pBuf->GetBuffer(), ulBufLen); HX_RELEASE(m_pFragBuf); pBuf = pNewBuf; } while (pBuf != NULL && !m_bClosed) { BYTE* pData = pBuf->GetBuffer(); UINT32 uDataLen = pBuf->GetSize(); UINT32 uDataUsed = 0; IHXBuffer* pNewBuf = NULL; IHXBuffer* pContentBuf = NULL; BOOL bFirstRun = FALSE; BOOL bMsgTooLarge = FALSE; if (m_ReadState == DEMUX_READ_MSG) { HTTPMessage* pMsg = NULL; uDataUsed = uDataLen; pMsg = m_pParser->parse((const char*)pData, uDataUsed, bMsgTooLarge); if (pMsg == NULL) { if (bMsgTooLarge) { if (pBuf) pBuf->Release(); if (m_pSock) { IHXSockAddr* pAddr = 0; m_pSock->GetPeerAddr(&pAddr); if (pAddr) { IHXBuffer* pAddrBuf = 0; pAddr->GetAddr(&pAddrBuf); if (pAddrBuf) { fprintf(stderr, "W: Large amount of HTTP data being received from addr <%s>.\n" " Possible DOS attack!\n", (const char *)pAddrBuf->GetBuffer()); pAddrBuf->Release(); } pAddr->Release(); } } Close(HXR_FAIL); return; } break; } // Remove used data from the buffer if (uDataUsed == uDataLen) { HX_RELEASE(pBuf); } else { pNewBuf = new CHXStaticBuffer(pBuf, uDataUsed, uDataLen-uDataUsed); pNewBuf->AddRef(); HX_RELEASE(pBuf); pBuf = pNewBuf; } if (m_pResponse == NULL) { DetectHandler(pMsg); HX_ASSERT(m_pResponse != NULL); m_pResponse->Init(this); bFirstRun = TRUE; } if (m_pResponse->GetFeatureFlags() & HTTP_FEATURE_IGNORE_CONTENT_LENGTH) { // Cloaking V2. if (m_pResponse->GetFeatureFlags() & ( HTTP_FEATURE_V11_SUPPORT | HTTP_FEATURE_CHUNKED_ENCODING_SUPPORT)) { m_uContentRemain = 0; CHXString strEncoding = pMsg->getHeaderValue("Transfer-Encoding"); if (strEncoding == "chunked") { m_ReadState = DEMUX_READ_DATA; } } else // Far less strict for non-persistent HTTP/1.0 connections. { m_uContentRemain = 0; m_ReadState = DEMUX_READ_DATA; } } else { MIMEHeader* pHdr = pMsg->getHeader("Content-Length"); if (!pHdr) { m_uContentRemain = 0; } else { CHXString strLen; pHdr->asString(strLen); int iLen = atoi(strLen); if (iLen < 0 || iLen > 0xffff) { DPRINTF(D_ERROR, ("HTTP: Bad content length %d\n", iLen)); if (pBuf) pBuf->Release(); Close(HXR_FAIL); return; } m_uContentRemain = (UINT32)iLen; m_ReadState = DEMUX_READ_DATA; } } if (bFirstRun && m_pResponse->AutoDispatch()) { m_pSavedMessage = pMsg; static_cast<CHXServSocket*>(m_pSock)->Dispatch(); break; } DispatchMessage(pMsg); delete pMsg; } else if (m_ReadState == DEMUX_READ_DATA) { BOOL bEnforceContentLength = FALSE; if (m_pResponse->GetFeatureFlags() & HTTP_FEATURE_IGNORE_CONTENT_LENGTH) { HX_ASSERT(m_uContentRemain == 0); // This value not used. pContentBuf = pBuf; pBuf = NULL; } else { if (m_uContentRemain >= pBuf->GetSize()) { pContentBuf = pBuf; m_uContentRemain -= pBuf->GetSize(); pBuf = NULL; } else { pContentBuf = new CHXStaticBuffer(pBuf, 0, m_uContentRemain); pContentBuf->AddRef(); pNewBuf = new CHXStaticBuffer(pBuf, m_uContentRemain, pBuf->GetSize()-m_uContentRemain); pNewBuf->AddRef(); HX_RELEASE(pBuf); pBuf = pNewBuf; m_uContentRemain = 0; m_ReadState = DEMUX_READ_MSG; } } m_pResponse->OnData(pContentBuf); HX_RELEASE(pContentBuf); } } if (pBuf != NULL) { m_pFragBuf = pBuf; m_pFragBuf->AddRef(); } HX_RELEASE(pBuf); }
HX_RESULT CAudioOutOpenwave::_Imp_Write( const HXAudioData* pAudioOutHdr ) { ULONG32 ulCount = 0; //Schedule callbacks. if( m_bInitCallback && pAudioOutHdr ) { m_bInitCallback = FALSE; // Initialize the playback callback time. HXTimeval lTime = m_pScheduler->GetCurrentSchedulerTime(); m_pPlaybackCountCBTime->tv_sec = lTime.tv_sec; m_pPlaybackCountCBTime->tv_usec = lTime.tv_usec; // Scheduler playback callback. ReschedPlaybackCheck(); } //Blindly add the incoming data to the tail of the writelist. if( pAudioOutHdr != NULL) { IHXBuffer* pTmpBuff = pAudioOutHdr->pData; m_pWriteList->AddTail(pTmpBuff); pTmpBuff->AddRef(); } //OpDPRINTF("_Imp_Write : m_pWriteList(%d) \n", m_pWriteList->GetCount()); //Just return if there is nothing to do if( m_pWriteList->GetCount() <= 0 || m_wState==RA_AOS_OPEN_PAUSED ) { return RA_AOE_NOERR; } m_wState = RA_AOS_OPEN_PLAYING; if( m_bFirstWrite ) { if (m_pWriteList->GetCount() >= 10) { m_bFirstWrite = FALSE; for (int i=0; i<2; i++) { m_bWriteDone = TRUE; ulCount = _PushBits(); // Start the double buffering } } } else { //ulCount = _PushBits();// causes two competing threads } if ( m_bInitCallback ) { m_bInitCallback = FALSE; // Initialize the playback callback time. HXTimeval lTime = m_pScheduler->GetCurrentSchedulerTime(); m_pPlaybackCountCBTime->tv_sec = lTime.tv_sec; m_pPlaybackCountCBTime->tv_usec = lTime.tv_usec; // Scheduler playback callback. ReschedPlaybackCheck(); } //make sure the device is kept full. //if( m_pWriteList->GetCount()>0 && ulCount>0) //_PushBits(); return m_wLastError; }