void GetHTTPPaths(HXRegistry* hxreg, char* pCharListName, char**& pHTTPablePaths) { IHXValues* pHTTPPath = 0; HX_RESULT res = HXR_OK; if (HXR_OK == hxreg->GetPropListByName(pCharListName, pHTTPPath)) { const char* name; UINT32 id; UINT32 ulCount = 0; res = pHTTPPath->GetFirstPropertyULONG32(name, id); while(res == HXR_OK) { ulCount++; res = pHTTPPath->GetNextPropertyULONG32(name, id); } pHTTPablePaths = new char*[ulCount + 1]; UINT32 i = 0; res = pHTTPPath->GetFirstPropertyULONG32(name, id); while(res == HXR_OK) { IHXBuffer* pBuf = 0; if(HXR_OK == hxreg->GetStrById(id, pBuf)) { pHTTPablePaths[i] = new_string((const char *)pBuf->GetBuffer()); i++; HX_RELEASE(pBuf); } res = pHTTPPath->GetNextPropertyULONG32(name, id); } pHTTPablePaths[i] = 0; pHTTPPath->Release(); } }
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")); }
/* * Make a default rule of "any" if necessary. * It assumes "config.Multicast.ControlList" is present in the registy */ HX_RESULT MulticastRuleChain::_makeDefaultRule() { HX_RESULT res = HXR_OK; IHXValues* props = 0; const char* propName = 0; ULONG32 propID = 0; IHXBuffer* pBuf = 0; UINT32 ul = 0; CHXString str; /* * This is how it looks like... <List Name="Multicast"> <List Name="ControlList"> <List Name="100"> <Var Allow="any"/> </List> </List> </List> */ // create the right registry entry if we need to. Figoure out if we need to // do this at all as well! if (SUCCEEDED(m_registry->GetPropList("config.Multicast.ControlList", props, m_proc))) { // we need to make sure there is at least one good entry in the list if (SUCCEEDED(props->GetFirstPropertyULONG32(propName, propID))) { if (_findRule(propID)) { // found a rule...no need for a default. HX_RELEASE(props); res = HXR_OK; goto bail; } else { // try to see if there is any other entry under ControlList while (SUCCEEDED(props->GetNextPropertyULONG32(propName, propID))) { if (_findRule(propID)) { HX_RELEASE(props); res = HXR_OK; goto bail; } } } } HX_RELEASE(props); } else { // need to see what's in the registry if (FAILED(m_registry->GetPropList("config.Multicast", props, m_proc))) { HX_ASSERT(!props); // there is no Multicast section....Add it if (!m_registry->AddComp("config.Multicast", m_proc)) { // there is nothing we can do... res = HXR_FAIL; goto bail; } } HX_RELEASE(props); if (FAILED(m_registry->GetPropList("config.Multicast.ControlList", props, m_proc))) { HX_ASSERT(!props); if (!m_registry->AddComp("config.Multicast.ControlList", m_proc)) { // there is nothing we can do... res = HXR_FAIL; goto bail; } } HX_RELEASE(props); } // shouldn't make a default if there is a list HX_ASSERT(!m_numRules); // put a default entry in a registry, so the rest of the process can take // place. Try at most 100 times do { ul += 100; str.Format("config.Multicast.ControlList.%u", ul); } while (!m_registry->AddComp(str, m_proc) && ul <= 10000); str += ".Allow"; res = _addDefaultRule((const char*)str); bail: HX_RELEASE(props); HX_RELEASE(pBuf); 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; }
/* * Copyright (c) 1996, 1997, 1998 Real Networks * * Function Name: MulticastRuleChain::_parseRule * Input Params: const char* ruleNumStr, ULONG32 regId * Return Value: MulticastACRule* * Description: * This method takes a rule number (registry Composite property) * and the id and retrieves all the properties under it. it then * parses the info and puts it into a access rule structure which * gets returned back to the caller. * In case an error occurs while parsing, a NULL pointer is returned. */ MulticastACRule* MulticastRuleChain::_parseRule(const char* ruleNumStr, ULONG32 regId) { IHXValues* props = 0; const char* propName = 0; // here it represents the rule number ULONG32 propID = 0; MulticastACRule* rule = 0; char* ruleVar = 0; INT32 ruleNum = 0; char* strValue = 0; IHXBuffer* fromAddr = 0; IHXBuffer* netmask = 0; IHXBuffer* value = 0; ULONG32 netLongFromAddr = 0L; ULONG32 netLongFromNetmask = 0L; ULONG32 netLongFromLowerLimit = 0L; ULONG32 netLongFromUpperLimit = 0L; BOOL fromAddrIsAny = FALSE; int numProps = 0; ruleVar = (char*)strrchr(ruleNumStr, '.'); if (!ruleVar || !*ruleVar) { // printf("invalid Access rule # -- %s\n", ruleNumStr); goto fin; } ruleVar++; // advance past the '.' ruleNum = atoi(ruleVar); m_registry->GetPropList(regId, props, m_proc); if (!props) { // printf("invalid Access rule # -- %s - !props\n", ruleNumStr); goto fin; } props->GetFirstPropertyULONG32(propName, propID); if (!propName || !propID) { // printf("invalid Access rule # -- %s - !propName||!propID\n", // ruleNumStr); goto fin; } while (propName && propID) { ruleVar = (char*)strrchr(propName, '.'); if (!ruleVar || !*ruleVar) { // printf("invalid Access rule # -- %s - !ruleVar||!*ruleVar\n", ruleNumStr); break; } ruleVar++; // advance past the '.' // printf("%s ", ruleVar); if (!strcasecmp(ruleVar, "Allow")) { if (HXR_OK != m_registry->GetStr(propID, fromAddr, m_proc)) break; // printf("= %s", (const char *)fromAddr->GetBuffer()); if (!strcasecmp("any", (const char *)fromAddr->GetBuffer())) { netLongFromNetmask = 0xffffffff; netLongFromLowerLimit = 0L; netLongFromUpperLimit = netLongClassCULimit; fromAddrIsAny = TRUE; } else { // This is an error, INADDR_NONE was returned from parsing // the address and this caused a fail result to be returned // To handle gracefully, log an error to let know that the // error has occurred and specify all addresses allowed if (HXR_OK != _parseAddr( (const char *)fromAddr->GetBuffer(), fromAddr->GetSize(), netLongFromAddr, netLongFromNetmask)) { char szMsg[128]; snprintf(szMsg, 128, g_zcszInvalidAddressMsg, fromAddr->GetSize(), (const char*) fromAddr->GetBuffer()); // If this is not a valid ip address, then // report an error and default to any m_pErrorHandler->Report(HXLOG_ERR, 0, 0, szMsg, 0); netLongFromNetmask = 0xffffffff; netLongFromLowerLimit = 0L; netLongFromUpperLimit = netLongClassCULimit; fromAddrIsAny = TRUE; } else { // If INADDR_ANY '0.0.0.0' then should be the same as specifying Any // and this is not considered an error if(netLongFromAddr == INADDR_ANY) { netLongFromNetmask = 0xffffffff; netLongFromLowerLimit = 0L; netLongFromUpperLimit = netLongClassCULimit; fromAddrIsAny = TRUE; } else { /* * ToAddr ==> 172.16.2.0 * Netmask => 255.255.255.0 * UpperLimit => 172.16.2.255 */ netLongFromLowerLimit = netLongFromAddr; netLongFromUpperLimit = netLongFromAddr | ~netLongFromNetmask; } } } /**** printf(" -- addr(%lu), lower(%lu), upper(%lu)\n", netLongFromAddr, netLongFromLowerLimit, netLongFromUpperLimit); ****/ numProps++; } else { // printf("erroneous property under rule # %s\n", ruleNumStr); } propName = 0; propID = 0; props->GetNextPropertyULONG32(propName, propID); } // printf("\n"); if (numProps == 1) { rule = new MulticastACRule; rule->nRuleNum = ruleNum; rule->pFromAddr = fromAddr; rule->pFromAddr->AddRef(); if (netmask) { rule->pNetmask = netmask; rule->pNetmask->AddRef(); } rule->ulFromAddr = netLongFromAddr; rule->ulFromNetmask = netLongFromNetmask; rule->ulFromAddrLowerLimit = netLongFromLowerLimit; rule->ulFromAddrUpperLimit = netLongFromUpperLimit; rule->bFromAddrIsAny = fromAddrIsAny; // printf("all of 1 rule parts detected\n"); } fin: return rule; }
HX_RESULT MulticastRuleChain::_createMulticastRuleChain() { HX_RESULT res = HXR_OK; IHXValues* props = 0; const char* propName = 0; // here it represents the rule number ULONG32 propID = 0; MulticastACRule* rule = 0; int i = 0; // if we need to, make a default rule in the registry, so the rest of the // process can take place. _makeDefaultRule(); res = m_registry->GetPropList("config.Multicast.ControlList", props, m_proc); /* * XXXAAK -- remember to change ServerRegistry::_getPropList() * to return NULL (IHXValues *) in case the property does not exist */ if (SUCCEEDED(res) && props) { props->GetFirstPropertyULONG32(propName, propID); if (!propName || !propID) { res = HXR_FAIL; goto endInit; } // printf("creating rule chain\n"); while(propName && propID) { // printf("rule %d detected\n", m_numRules); rule = _parseRule(propName, propID); if (rule) m_rules[m_numRules++] = rule; propName = 0; propID = 0; props->GetNextPropertyULONG32(propName, propID); } // printf("total %d rules\n", m_numRules); if (m_numRules) { ::qsort(m_rules, m_numRules, sizeof(MulticastACRule *), _mcastRuleCompare); m_beginIdx = m_numRules; m_endIdx = 0; } } else { // now that we are making a default, it shouldn't get here HX_ASSERT(!"ControlList missing..."); res = HXR_FAIL; } endInit: // printf("_createMulticastRuleChain() returns %lu\n", res); HX_RELEASE(props); return res; }
/************************************************************************ * IHXActivePropUser::SetActiveStr * * Async request to set string pName to string in pBuffer. */ STDMETHODIMP HTTPDeliverablePrefController::SetActiveStr(const char* pName, IHXBuffer* pBuffer, IHXActivePropUserResponse* pResponse) { /* * Get everything under HTTPDeliverable. */ IHXValues* pHTTPPath = 0; IHXBuffer* pBuf = 0; char** pNewHTTPD; HX_RESULT res; const char* name; UINT32 ul; int i; /* * If the list is already in the reg, then we have to merge * our new stuff to set with the stuff from the reg. */ if (HXR_OK == m_proc->pc->registry->GetPropList( m_pCharListName, pHTTPPath, m_proc)) { UINT32 ulNumPaths = 0; res = pHTTPPath->GetFirstPropertyULONG32(name, ul); while (res == HXR_OK) { ulNumPaths++; res = pHTTPPath->GetNextPropertyULONG32(name, ul); } /* * If we are changing one that is already there... */ if (HXR_OK == pHTTPPath->GetPropertyULONG32( pName, ul)) { pNewHTTPD = new char* [ulNumPaths+1]; i = 0; res = pHTTPPath->GetFirstPropertyULONG32(name, ul); while (res == HXR_OK) { pBuf = 0; /* * If this is the one we are changing... */ if (!strcasecmp(name, pName)) { pNewHTTPD[i] = new_string( (const char*)pBuffer->GetBuffer()); } else { m_proc->pc->registry->GetStr(name, pBuf, m_proc); if (!pBuf) { i--; } else { pNewHTTPD[i] = new_string( (const char*)pBuf->GetBuffer()); pBuf->Release(); } } i++; res = pHTTPPath->GetNextPropertyULONG32(name, ul); } pNewHTTPD[i] = 0; } /* * We must be adding one... */ else { pNewHTTPD = new char* [ulNumPaths+2]; i = 0; res = pHTTPPath->GetFirstPropertyULONG32(name, ul); while (res == HXR_OK) { pBuf = 0; m_proc->pc->registry->GetStr(name, pBuf, m_proc); if (pBuf) { pNewHTTPD[i] = new_string( (const char*)pBuf->GetBuffer()); pBuf->Release(); i++; } res = pHTTPPath->GetNextPropertyULONG32(name, ul); } pNewHTTPD[i++] = new_string((const char*)pBuffer->GetBuffer()); pNewHTTPD[i] = 0; } } /* * It was not in the reg, so this is the only one. */ else { pNewHTTPD = new char* [2]; pNewHTTPD[0] = new_string((const char*)pBuffer->GetBuffer()); pNewHTTPD[1] = 0; } /* * Clean up the old one. */ if (m_HTTP_paths && *m_HTTP_paths) { i = 0; while ((*m_HTTP_paths)[i]) { delete[] (*m_HTTP_paths)[i]; i++; } delete[] (*m_HTTP_paths); } *m_HTTP_paths = pNewHTTPD; pResponse->SetActiveStrDone(HXR_OK, pName, pBuffer, 0, 0); return HXR_OK; }
/************************************************************************ * IHXActivePropUser::DeleteActiveProp * * Async request to delete the active property. */ STDMETHODIMP HTTPDeliverablePrefController::DeleteActiveProp(const char* pName, IHXActivePropUserResponse* pResponse) { IHXValues* pHTTPPath; char** pNewHTTPD = 0; const char* name; UINT32 ul; UINT32 ulNumPaths = 0; HX_RESULT res; int i; IHXBuffer* pBuf = 0; if (HXR_OK == m_proc->pc->registry->GetPropList( m_pCharListName, pHTTPPath, m_proc)) { if (HXR_OK == pHTTPPath->GetPropertyULONG32(pName, ul)) { /* * Count the number of current paths. */ res = pHTTPPath->GetFirstPropertyULONG32(name, ul); while (res == HXR_OK) { ulNumPaths++; res = pHTTPPath->GetNextPropertyULONG32(name, ul); } pNewHTTPD = new char* [ulNumPaths]; i = 0; res = pHTTPPath->GetFirstPropertyULONG32(name, ul); while (res == HXR_OK) { pBuf = 0; /* * If this is the one we want to delete, then just * skip over it in the copy. */ if (strcasecmp(name, pName)) { m_proc->pc->registry->GetStr(name, pBuf, m_proc); if (pBuf) { pNewHTTPD[i] = new_string( (const char*)pBuf->GetBuffer()); pBuf->Release(); i++; } } res = pHTTPPath->GetNextPropertyULONG32(name, ul); } pNewHTTPD[i] = 0; /* * Clean up the old one and set it to the new one. */ if (m_HTTP_paths && *m_HTTP_paths) { i = 0; while ((*m_HTTP_paths)[i]) { delete[] (*m_HTTP_paths)[i]; i++; } delete[] (*m_HTTP_paths); } *m_HTTP_paths = pNewHTTPD; pNewHTTPD = 0; } } pResponse->DeleteActivePropDone(HXR_OK, pName, 0, 0); return HXR_OK; }
void HXFileSystemManager::InitMountPoints(IUnknown* pContext) { #if defined(HELIX_CONFIG_NOSTATICS) HXBOOL& zm_IsInited = (HXBOOL&)HXGlobalInt32::Get(&HXFileSystemManager::zm_IsInited); #endif if (zm_IsInited) return; zm_IsInited = TRUE; IHXBuffer* mount_point = 0; IHXBuffer* real_short_name = 0; const char* short_name = 0; IHXValues* options = 0; IHXRegistry* pRegistry; IHXValues* pNameList = NULL; if(HXR_OK != pContext->QueryInterface(IID_IHXRegistry, (void**)&pRegistry)) { return; } if(HXR_OK != pRegistry->GetPropListByName("config.FSMount", pNameList)) { pRegistry->Release(); return; } HX_RESULT res; const char* plugName; UINT32 plug_id; res = pNameList->GetFirstPropertyULONG32(plugName, plug_id); while(res == HXR_OK) { HXPropType plugtype = pRegistry->GetTypeById(plug_id); if(plugtype != PT_COMPOSITE) res = HXR_FAIL; else { short_name = strrchr(plugName, '.'); if(!short_name) short_name = plugName; else short_name++; IHXValues* pPropList; if(HXR_OK == pRegistry->GetPropListById(plug_id, pPropList)) { const char* propName; UINT32 prop_id; CreateValuesCCF(options, pContext); res = pPropList->GetFirstPropertyULONG32(propName, prop_id); while(res == HXR_OK) { HXPropType type = pRegistry->GetTypeById(prop_id); const char*propSubName = strrchr(propName, '.') + 1; switch(type) { case PT_INTEGER: { INT32 val; if(HXR_OK == pRegistry->GetIntById(prop_id, val)) { options->SetPropertyULONG32(propSubName, val); } break; } case PT_STRING: { IHXBuffer* pBuffer; if(HXR_OK == pRegistry->GetStrById(prop_id, pBuffer)) { options->SetPropertyBuffer(propSubName, pBuffer); pBuffer->Release(); } break; } case PT_BUFFER: { IHXBuffer* pBuffer; if(HXR_OK == pRegistry->GetBufById(prop_id, pBuffer)) { options->SetPropertyBuffer(propSubName, pBuffer); pBuffer->Release(); } break; } default: break; } res = pPropList->GetNextPropertyULONG32(propName, prop_id); } res = HXR_OK; } if(HXR_OK == options->GetPropertyBuffer("MountPoint", mount_point)) { if(HXR_OK == options->GetPropertyBuffer("ShortName", real_short_name)) short_name = (const char*) real_short_name->GetBuffer(); AddMountPoint(short_name,(const char*)mount_point->GetBuffer(), options, pContext); if(real_short_name) { real_short_name->Release(); real_short_name = 0; } mount_point->Release(); } res = pNameList->GetNextPropertyULONG32(plugName, plug_id); } } pNameList->Release(); pRegistry->Release(); }