/// Work horse for reading. As long as we are initilized once /// to read, we always try to read something of the socket. HX_RESULT HXOpwaveTCPSocket::DoRead() { /// Create a new IHXBuffer for every read HX_RESULT res = HXR_FAIL; IHXBuffer* pReadBuffer = NULL; res = m_pCCF->CreateInstance(IID_IHXBuffer, (void**)&pReadBuffer); if (SUCCEEDED(res)) { res = pReadBuffer->SetSize(m_ulReadSize); UCHAR* pData = pReadBuffer->GetBuffer(); int nRead = read(pData, m_ulReadSize); //OpDPRINTF("DoRead: this=%p, read=%d, askfor=%d\n\n", this, nRead, m_ulReadSize); if (nRead > 0) { pReadBuffer->SetSize(nRead); m_pReadBuffer = pReadBuffer; // Don't ADDREF, m_pReadBuffer will be released in the callback OnReadDone OnReadDone(res, m_pReadBuffer); } } HX_RELEASE(m_pReadBuffer); return res; }
STDMETHODIMP CHTTPDemux::SendMessage(HTTPMessage* pMsg) { HX_RESULT hxr = HXR_OK; UINT32 uBufLen = MAX_HTTP_MSG + pMsg->contentLength(); //XXXTDM IHXBuffer* pBuf = new CHXBuffer(); pBuf->AddRef(); pBuf->SetSize(uBufLen); int msgLen = 0; pMsg->asString((char*)pBuf->GetBuffer(), msgLen, uBufLen); pBuf->SetSize(msgLen); hxr = SendData(pBuf); HX_RELEASE(pBuf); return hxr; }
IHXBuffer* CBaseArchiver2::CreateTrimmedBuffer(IHXBuffer* pBuffer, IUnknown* pContext) { IHXBuffer* pRetBuffer = NULL; if (pBuffer) { ULONG32 ulSize = BufferStringLength(pBuffer); if (ulSize > 0) { IHXBuffer* pNewBuffer = NULL; HX_RESULT retVal = HXR_OK; retVal = CreateBufferCCF(pNewBuffer, pContext); if (SUCCEEDED(retVal)) { retVal = pNewBuffer->SetSize(ulSize); } if (SUCCEEDED(retVal)) { memcpy(pNewBuffer->GetBuffer(), pBuffer->GetBuffer(), ulSize); /* Flawfinder: ignore */ pRetBuffer = (IHXBuffer*) pNewBuffer; pRetBuffer->AddRef(); } HX_RELEASE(pNewBuffer); } } return pRetBuffer; }
STDMETHODIMP HXCloakedV2TCPSocket::Read(IHXBuffer** ppBuf) { HX_RESULT res = HXR_WOULD_BLOCK; ULONG32 ulBytes = 0; IHXBuffer* pNew = NULL; // HX_ASSERT( csReady == m_CloakingState ); *ppBuf = NULL; ulBytes = m_RTSPQueue.GetQueuedItemCount(); if( ulBytes > 0 ) { res = HXR_OUTOFMEMORY; CreateBufferCCF(pNew, m_pContext); if( pNew ) { res = pNew->SetSize(ulBytes); HX_ASSERT(SUCCEEDED(res)); if( SUCCEEDED(res) ) { m_RTSPQueue.DeQueue(pNew->GetBuffer(), ulBytes ); *ppBuf = pNew; } } if( !SUCCEEDED(res) ) { HX_RELEASE(pNew); } } return res; }
IHXBuffer* ReadSDPFile(IHXCommonClassFactory* pCCF, const char* pFilename) { IHXBuffer* pBuf = 0; FILE* pFile = ::fopen(pFilename, "rb"); if (pFile) { if (!fseek(pFile, 0, SEEK_END)) { long fileSize = ftell(pFile); if (HXR_OK == pCCF->CreateInstance(CLSID_IHXBuffer,(void**)&pBuf)) { HXBOOL bFailed = TRUE; if ((HXR_OK == pBuf->SetSize(fileSize)) && (!fseek(pFile, 0, SEEK_SET)) && (fread(pBuf->GetBuffer(), fileSize, 1, pFile) == 1)) { bFailed = FALSE; } if (bFailed) { pBuf->Release(); pBuf = 0; } } } ::fclose(pFile); } return pBuf; }
// SetStreamHeader; called when the stream header for this stream is available STDMETHODIMP CM4AStreamHandler::SetStreamHeader( IHXValues* pHeader ) { HX_RESULT retVal = HXR_OK; UINT32 ulStreamNumber; pHeader->GetPropertyULONG32("StreamNumber", ulStreamNumber); m_unStreamNumber = (UINT16) ulStreamNumber; IHXBuffer* pOpaqueData = NULL; UINT8* ucDecoderInfo = NULL; UINT32 ulDSILength; retVal = pHeader->GetPropertyBuffer( "OpaqueData", pOpaqueData ); if( SUCCEEDED( retVal ) ) { retVal = GetASCFromESD( pOpaqueData, ucDecoderInfo, ulDSILength ); } HX_RELEASE( pOpaqueData ); if( SUCCEEDED( retVal ) ) { IHXBuffer* pBuffer = NULL; retVal = HXR_OUTOFMEMORY; m_pCommonClassFactory->CreateInstance( IID_IHXBuffer, (void**) &pBuffer ); if( pBuffer ) { UCHAR* pBuf; retVal = pBuffer->SetSize( ulDSILength + 2 ); if( SUCCEEDED( retVal ) ) { pBuf = pBuffer->GetBuffer(); // ObjectTypeIndication pBuf[0] = CMP4Atom_esds::ObjectTypeIndicationValues::OTI_Audio_14496_3; // StreamType pBuf[1] = CMP4Atom_esds::DecoderConfigStreamTypes::ST_AudioStream; // Copy in the decoder specific info memcpy( pBuf + 2, ucDecoderInfo, ulDSILength ); pHeader->SetPropertyBuffer("DecoderInfo", pBuffer ); HX_RELEASE( pBuffer ); m_pStreamMixer->SetStreamHeader( pHeader ); retVal = HXR_OK; } } } HX_DELETE( ucDecoderInfo ); return retVal; }
void CoreProcessInitCallback::func(Process* proc) { Config* config = NULL; DistributedLicenseRequester* license_requester = NULL; ServerRegistry* registry = NULL; int backlog = 0; int setegid_err = 0; int seteuid_err = 0; INT32 nUseRegistryForStats = 0; printf ("Starting %s %d.%d Core...\n", ServerVersion::ProductName(), ServerVersion::MajorVersion(), ServerVersion::MinorVersion()); proc->pc = new CoreContainer(proc); proc->pc->process_type = PTCore; proc->pc->lbound_tcp_listenRTSPResponse = NULL; proc->pc->dispatchq = dispatch_queue; proc->pc->dispatchq->init(proc); MulticastAccessControl* mcast_ctrl = new MulticastAccessControl(); /* * Must create the ErrorSinkHandler before accessing Config */ proc->pc->error_sink_handler = new ErrorSinkHandler(); progname = GetProgName(argv[0]); os_init(); registry = new ServerRegistry(proc); proc->pc->registry = registry; registry->AddComp("Client", proc); registry->AddComp("Server", proc); // Add system composite to the registry registry->AddComp("system", proc); // Add startuplog info to the registry ServerBuffer* pBuf = new ServerBuffer((UCHAR*)g_szStartupLog, strlen(g_szStartupLog)); if (g_szStartupLog) registry->AddStr("Server.StartupLogPath", pBuf, proc); config = new Config(proc, g_pszConfigFile, g_pszImportKey, registry); if (!config->valid()) { ERRMSG(proc->pc->error_handler, "Invalid configuration.\n"); terminate(1); } if (g_pszImportKey && g_pszImportKey[0]) { terminate(1); } proc->pc->client_stats_manager = new ClientStatsManager; //proc->pc->client_stats_manager->AddRef(); if (SUCCEEDED(registry->GetInt("config.ClientStats.UseRegistry", &nUseRegistryForStats, proc))) { proc->pc->client_stats_manager->SetUseRegistryForStats(nUseRegistryForStats ? TRUE : FALSE); } proc->pc->license_requester = new DistributedLicenseRequester; /* * Now that the proc->pc and the registry are established, it is safe to * initialize the IHXNetworkServicesContext */ proc->pc->network_services->Init(proc->pc->server_context, proc->pc->engine, NULL); proc->pc->net_services->Init(proc->pc->server_context); // MulticastManager needs MulticastAddressPool! proc->pc->mcst_addr_pool = new MulticastAddressPool(); proc->pc->mcst_addr_pool->AddRef(); /* * CSapManager and MulticastManager both needs * plugin hander which will be avilable in * _main CoreTransferCallback::func */ // will be Init'ed in _main CoreTransferCallback::func proc->pc->sap_mgr = new CSapManager(); proc->pc->sap_mgr->AddRef(); // addtional Init will be done in _main CoreTransferCallback::func proc->pc->multicast_mgr = new MulticastManager(proc->pc->server_context); /* */ proc->pc->alt_server_proxy_cfg_mgr = new AltServerProxyConfigHandler(proc, registry); proc->pc->alt_server_proxy_cfg_mgr->AddRef(); if (HXR_FAIL == proc->pc->alt_server_proxy_cfg_mgr->Init()) { HX_RELEASE(proc->pc->alt_server_proxy_cfg_mgr); } /* setup QoS core */ proc->pc->qos_prof_select = new QoSProfileSelector(proc); proc->pc->qos_prof_select->AddRef(); proc->pc->qos_bus_ctl = new QoSSignalBusController(); proc->pc->qos_bus_ctl->AddRef(); proc->pc->qos_sig_src = new QoSSignalSource(proc, proc->pc->qos_bus_ctl); proc->pc->qos_sig_src->AddRef(); /* setup capex profile cache */ proc->pc->capex_static_cache = new StaticProfileCache(); proc->pc->capex_static_cache->AddRef(); proc->pc->capex_profile_cache = new HTTPProfileCache(); proc->pc->capex_profile_cache->AddRef(); Config_error* error_result = 0; backlog = config->GetInt(proc, "config.ListenBacklog"); if (backlog < CONFIG_BACKLOG) backlog = CONFIG_BACKLOG; #ifdef DEBUG debug_level() = g_ulDebugFlags ? g_ulDebugFlags : config->GetInt(proc, "config.Debug"); debug_func_level() = g_ulDebugFuncFlags ? g_ulDebugFuncFlags : config->GetInt(proc, "config.DebugFunc"); #endif ((CoreContainer*)proc->pc)->m_pListenResponseList = new CHXSimpleList; HXRegistry* hxreg = new HXRegistry(registry, proc); HX_RESULT res = HXR_OK; hxreg->AddRef(); char** pHTTPablePaths = NULL; char** pHTTPpostablePaths = NULL; ::GetHTTPPaths(hxreg, (char*)"config.HTTPDeliverable", pHTTPablePaths); ::GetHTTPPaths(hxreg, (char*)"config.HTTPPostable", pHTTPpostablePaths); /* * Add key for broadcast plugins to register their connections */ hxreg->AddComp("LiveConnections"); hxreg->AddInt("LiveConnections.Index", 0); hxreg->AddInt("LiveConnections.Count", 0); proc->pc->named_lock_manager->CreateNamedLock("LiveConnectionsLock"); INT32* pEncoders = new INT32; IHXBuffer* pIHXBuf = new ServerBuffer(TRUE); HX_ASSERT(pIHXBuf); *pEncoders = 0; pIHXBuf->SetSize(sizeof(void*)); *((void**)pIHXBuf->GetBuffer()) = (void*)pEncoders; hxreg->AddBuf("EncoderConnections.Index", pIHXBuf); HX_RELEASE(pIHXBuf); /* * Add key for monitor plugins to register their connections */ hxreg->AddComp("Monitors"); hxreg->AddInt("Monitors.Count", 0); /* * Add key for splitters to register their connections */ hxreg->AddComp("Splitters"); hxreg->AddInt("Splitters.Index", 0); hxreg->AddInt("Splitters.Count", 0); mcast_ctrl->Init(proc); proc->pc->mcast_ctrl = mcast_ctrl; IHXValues* pAddrList = NULL; IHXBuffer* pAddrBuf = NULL; const char* pAddrStr = NULL; BOOL bBindToLocalHost = FALSE; TimeZoneCheckCallback* tzcb = new TimeZoneCheckCallback(proc); tzcb->SetTimeZone(); tzcb->ScheduleFirstCheckCallback(); HX_RESULT pn_res = hxreg->GetPropListByName("config.IPBindings", pAddrList); if (pn_res != HXR_OK) { pn_res = hxreg->GetPropListByName("config.IPBinding", pAddrList); } INT32 sbind_id = hxreg->AddComp("server.ipbinding"); HX_ASSERT(sbind_id); int num_props = 0; switch (pn_res) { case HXR_OK: { const char* addr_prop_name; UINT32 addr_prop_id; res = pAddrList->GetFirstPropertyULONG32(addr_prop_name, addr_prop_id); while(res == HXR_OK) { char str[64]; if (HXR_OK == hxreg->GetStrById(addr_prop_id, pAddrBuf)) { const char* strAddr = (const char*)pAddrBuf->GetBuffer(); if (!strcmp(strAddr, "*")) { //XXXJJ "*" means any interfaces(including ipv4 and ipv6) // will be handled in "default:". //if we have "*", we shouldn't have other entries in the list. HX_ASSERT(num_props == 0); break; } else if (!strcmp(strAddr, "127.0.0.1") || !strcmp(strAddr, "0.0.0.0")) { bBindToLocalHost = TRUE; } ++num_props; sprintf(str, "server.ipbinding.addr_%.2d", num_props); hxreg->AddStr(str, pAddrBuf); HX_RELEASE(pAddrBuf); } res = pAddrList->GetNextPropertyULONG32(addr_prop_name, addr_prop_id); } pAddrList->Release(); if (num_props) break; } // Three cases fall into here: no ipbinding list, empty list, or only "*" // in the list default: { ServerBuffer::FromCharArray("*", &pAddrBuf); hxreg->AddStr("server.ipbinding.addr_01", pAddrBuf); pAddrBuf->Release(); bBindToLocalHost = TRUE; break; } }; if(!g_pHeartBeatIP) { // heartbeat ip not specified if(!bBindToLocalHost) { //localhost is not in the binding list, we need to manually add it // for heartbeat connection to succeed. char str[64]; ++num_props; sprintf(str, "server.ipbinding.addr_%.2d", num_props); ServerBuffer::FromCharArray("127.0.0.1", &pAddrBuf); hxreg->AddStr(str, pAddrBuf); pAddrBuf->Release(); } } _initializeListenRespObjects(proc, config, registry, backlog); hxreg->Release(); // This used to set g_pCPUCount based on config.ProcessorCount but // setting StreamerCount is the way to do this now. *g_pCPUCount = g_bSkipCPUTest ? 1 : CPUDetect(); // // This just gives the "Linux22Compat" code a platform-neutral // name for testing/debugging on other platforms. // UINT32 ulLessParallel = config->GetInt(proc, "config.LessParallel"); if (ulLessParallel) { printf("Note: Configuration specified LessParallel mode.\n"); *g_bLimitParallelism = TRUE; } #ifdef _UNIX const char* pPIDPath; if ((pPIDPath = config->GetString(proc, "config.PidPath"))) { FILE* f = fopen(pPIDPath, "w"); if (f > 0) { #if defined PTHREADS_SUPPORTED fprintf(f, "%d\n", getpid()); #else fprintf(f, "%d\n", proc->procid(PROC_RM_CONTROLLER)); #endif fclose(f); } else { ERRMSG(proc->pc->error_handler, "Couldn't open PID File %s", pPIDPath); } } int gid = GetGIDFromConfig(proc, config); int uid = GetUIDFromConfig(proc, config); if (pPIDPath && gid >= 0 && uid >= 0) { if (chown(pPIDPath, uid, gid) < 0) perror("could not set the PIDPath's ownership\n"); } if (gid >= 0) { #ifdef _AIX if (setregid(-1, gid) < 0) #elif defined _HPUX if (setresgid(-1, gid, gid) < 0) #else if (setegid(gid) < 0) #endif { setegid_err = errno; perror("setegid() failed(1)"); *return_gid = (UINT32)-1; } else *return_gid = gid; } if (uid >= 0) { #if defined _AIX || defined _HPUX if (setreuid(-1, uid) < 0) #else if (seteuid(uid) < 0) #endif { seteuid_err = errno; perror("seteuid() failed(1)"); *return_uid = (UINT32)-1; } else { *return_uid = uid; } } fflush(0); #endif proc->pc->config = config; /* * Handle streamer_info creation and overriding of capacity defaults * from the config file. */ UINT32 ul; proc->pc->streamer_info = new StreamerInfo; if (HXR_OK == proc->pc->registry->GetInt("config.StreamerSessionCapacity", (INT32*)&ul, proc)) { proc->pc->streamer_info->SetSessionCapacity(ul); } if (HXR_OK == proc->pc->registry->GetInt("config.MaxSockCapacity", (INT32*)&ul, proc)) { SOCK_CAPACITY_VALUE = ul; } if ((HXR_OK == proc->pc->registry->GetInt("config.MaxDescCapacity", (INT32*)&ul, proc)) || (HXR_OK == proc->pc->registry->GetInt("config.MaxDescriptorCapacity", (INT32*)&ul, proc))) { DESCRIPTOR_CAPACITY_VALUE = ul; } proc->pc->conn_id_table = new CHXTSID(config->GetInt(proc, "config.Capacity")); proc->pc->resolver_info = new ResolverInfo; proc->pc->rdispatch = new ResolverDispatch(proc); proc->pc->scheduler = new ServerScheduler(proc); proc->pc->server_prefs = new ServerPreferences(proc); proc->pc->server_info = new ServerInfo(proc); proc->pc->loadinfo = new LoadInfo(proc); //XXXTDM: Where's all the AddRef() calls??? proc->pc->net_services->AddRef(); proc->pc->scheduler->AddRef(); // Tell mem routines where to find a regularly-updated timestamp in shared memory SharedMemory::SetTimePtr(&proc->pc->engine->now); #ifdef PAULM_LEAKCHECK if (g_bLeakCheck) new MemChecker(proc); #endif /* PAULM_LEAKCHECK */ proc->pc->misc_plugins = new CHXMapPtrToPtr(); proc->pc->allowance_plugins = new CHXMapPtrToPtr(); proc->pc->server_fork = new ServerFork(proc); proc->pc->global_server_control = new GlobalServerControl(proc); proc->pc->data_convert_con = new DataConvertController; #if defined _UNIX proc->pc->m_pResMUX = new ResolverMUX(RESOLVER_CAPACITY_VALUE, MAX_RESOLVERS, proc->pc->server_fork, proc->pc->async_io, proc->pc->error_handler); #endif proc->pc->HTTP_deliver_paths = new char**; if (pHTTPablePaths) { *proc->pc->HTTP_deliver_paths= pHTTPablePaths; } else { *proc->pc->HTTP_deliver_paths = NULL; } new HTTPDeliverablePrefController(proc, (char*)"config.HTTPDeliverable", proc->pc->HTTP_deliver_paths); proc->pc->HTTP_postable_paths = new char**; if (pHTTPpostablePaths) { *proc->pc->HTTP_postable_paths= pHTTPpostablePaths; } else { *proc->pc->HTTP_postable_paths = NULL; } new HTTPDeliverablePrefController(proc, (char*)"config.HTTPPostable", proc->pc->HTTP_postable_paths); proc->pc->cloaked_guid_dict = new CloakedGUIDDict(); proc->pc->broadcast_manager = new BroadcastManager(); proc->pc->load_listen_mgr = new LoadBalancedListenerManager(proc); /* * Setup the global mimetype dictionary. */ proc->pc->mime_type_dict = new Dict(); hxreg = new HXRegistry(proc->pc->registry, proc); hxreg->AddRef(); IHXValues* pTypeList; if(HXR_OK == hxreg->GetPropListByName("config.MimeTypes", pTypeList)) { HX_RESULT res; const char* mimeTypeRegname; UINT32 mime_id; res = pTypeList->GetFirstPropertyULONG32(mimeTypeRegname, mime_id); while(HXR_OK == res) { HXPropType mimetypetype = hxreg->GetTypeById(mime_id); if(mimetypetype != PT_COMPOSITE) res = HXR_FAIL; else { const char* mimeType = strrchr(mimeTypeRegname, '.'); if(!mimeType) mimeType = mimeTypeRegname; else mimeType++; IHXValues* pExtList; if(HXR_OK == hxreg->GetPropListById(mime_id, pExtList)) { const char* ext; UINT32 ext_id; res = pExtList->GetFirstPropertyULONG32(ext, ext_id); while(res == HXR_OK) { if(PT_STRING == hxreg->GetTypeById(ext_id) || PT_BUFFER == hxreg->GetTypeById(ext_id)) { IHXBuffer* extBuffer; if(HXR_OK == hxreg->GetStrById(ext_id, extBuffer)) { proc->pc->mime_type_dict->enter( (const char*)extBuffer->GetBuffer(), new_string(mimeType)); HX_RELEASE(extBuffer); } } res = pExtList->GetNextPropertyULONG32(ext, ext_id); } HX_RELEASE(pExtList); } res = pTypeList->GetNextPropertyULONG32(mimeTypeRegname, mime_id); } } HX_RELEASE(pTypeList); } HX_RELEASE(hxreg); proc->pc->rtspstats_manager = new RTSPEventsManager(); proc->pc->sdpstats_manager = new SDPAggregateStats(); proc->pc->sdpstats_manager->AddRef(); // If a default mime type doesn't yet exist, add one so that // we will always send some mime type Dict_entry* ent = proc->pc->mime_type_dict->find("*"); if(!ent) { proc->pc->mime_type_dict->enter("*", new_string("application/octet-stream")); } new MimeTypesPrefController(proc); ((CoreContainer *)proc->pc)->cdispatch = new ConnDispatch(proc); /* * AddRef() all objects handed out by ServerContext */ proc->pc->server_prefs->AddRef(); proc->pc->server_fork->AddRef(); *core_proc = proc; *controller_waiting_on_core = 0; // Signal Controller to continue while (!(*controller_ready)) microsleep(1); // Busy Wait for the Controller delete controller_ready; CoreTransferCallback* cb = new CoreTransferCallback; cb->core_proc = proc; #ifdef DEBUG cb->m_debug_level = debug_level(); cb->m_debug_func_level = debug_func_level(); #endif int* volatile core_waiting_for_refresh; cb->core_waiting_for_refresh = new int; *cb->core_waiting_for_refresh = 1; core_waiting_for_refresh = cb->core_waiting_for_refresh; #ifdef _WIN32 MaybeNotifyServiceUp(); #endif proc->pc->dispatchq->send(proc, cb, PROC_RM_CONTROLLER); /* * Wait here for the controller to get the plugins loaded. */ while (*core_waiting_for_refresh) microsleep(1); delete core_waiting_for_refresh; /* * NOTE: Both NT and mac have servers that run to completion in * os_start() */ os_start(); fflush(0); // add the global var ptr into the registry, so that the mmap managers in // each process can then access and modify the var using atomic // operations. g_pMemoryMappedDataSize is used to report the amount of // mmapped data that is read via the local file system (smplfsys). registry->AddIntRef("server.MMappedDataSize", (INT32 *)g_pMemoryMappedDataSize, proc); proc->pc->engine->mainloop(); // NEVER REACHED! #if 0 delete this; #endif PANIC(("Internal Error cp/737\n")); }
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); }
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); }
HX_RESULT CPCMAudioFormat::DecodeAudioData(HXAudioData& audioData, HXBOOL bFlushCodec, CMediaPacket *pPacket) { HX_RESULT retVal = HXR_FAIL; if (pPacket && m_pCommonClassFactory) { // Create an IHXBuffer IHXBuffer* pBuffer = NULL; m_pCommonClassFactory->CreateInstance(CLSID_IHXBuffer, (void**) &pBuffer); if (pBuffer) { switch(m_ucMimeType) { case kMimeTypeAudioL8: case kMimeTypeAudioL16: case kMimeTypeAudioXPNWav: // Copy the media packet into this buffer retVal = pBuffer->Set(pPacket->m_pData, pPacket->m_ulDataSize); if(SUCCEEDED(retVal)) { // Byteswap the samples if necessary if (m_bSwapSampleBytes) { SwapWordBytes((UINT16*) pBuffer->GetBuffer(), pBuffer->GetSize() / 2); } // Offset 8-bit samples if necessary if (m_bZeroOffsetPCM) { UCHAR* pTmp = (UCHAR*) pBuffer->GetBuffer(); for (UINT32 i = 0; i < pBuffer->GetSize(); i++) { pTmp[i] -= 128; } } } break; case kMimeTypeAudioPCMA: case kMimeTypeAudioPCMU: { UCHAR* pbCurSrc = (UCHAR*)(pPacket->m_pData); UINT16* pwCurDes = NULL; ULONG32 ulSampleNum = pPacket->m_ulDataSize; retVal = pBuffer->SetSize(ulSampleNum<<1); if(SUCCEEDED(retVal)) { pwCurDes = (UINT16*)(pBuffer->GetBuffer()); if(m_ucMimeType == kMimeTypeAudioPCMA) PCM_CONVERTER_ALaw2Linear(pbCurSrc,pwCurDes,ulSampleNum); else PCM_CONVERTER_ULaw2Linear(pbCurSrc,pwCurDes,ulSampleNum); } break; } default: retVal = HXR_FAIL; } if (SUCCEEDED(retVal)) { audioData.pData = pBuffer; audioData.ulAudioTime = pPacket->m_ulTime; audioData.uAudioStreamType = STREAMING_AUDIO; audioData.pData->AddRef(); } } HX_RELEASE(pBuffer); // Delete the packet CMediaPacket::DeletePacket(pPacket); } return retVal; }