CString Utils::ReadWebPage(const std::vector<CString>& webPages) { CString strAllPages; CAmHttpSocket httpSocket; CStdioFile file; CFileException e; for (int i=0; i<webPages.size(); i++) { CString strUrl(webPages[i]); CString strProtocol(strUrl.Left(4)); strProtocol.MakeLower(); if (strProtocol == "http") { CString strPage(httpSocket.GetPage(strUrl)); strAllPages += strPage; } else if (file.Open(strUrl, CFile::modeRead, &e)) { CString strLine; while (file.ReadString(strLine)) { strAllPages += strLine; } } } return strAllPages; }
/** * @brief Deletes a port map. * * @param protocol The protocol of the port map to delete. * @param externalPort The external port of the port map to delete. */ void UpnpNatAction::DeletePortMap(const char * protocol, long externalPort) { ValidatePortMapCollection(); // Remote from collection ComString strProtocol(protocol); HRESULT hResult = portMapCollection->Remove(externalPort,strProtocol.GetBSTR()); _ErrorException((hResult != S_OK), "removing a port map from the collection", hResult, __LINE__, __FILE__); // Remove from internal store size_t portMapID = 0; bool found = false; for(size_t n = 0;n<GetPortMapAmount();n++) { if( (portMaps[n].GetProtocol() == protocol) && (portMaps[n].GetExternalPort() == externalPort) ) { found = true; portMapID = n; break; } } if(found == true) { portMaps.Erase(portMapID); } }
EnHttpParseResult CHttpServerListenerImpl::OnUpgrade(IHttpServer* pSender, CONNID dwConnID, EnHttpUpgradeType enUpgradeType) { ::PostOnUpgrade(dwConnID, enUpgradeType, m_strName); if(enUpgradeType == HUT_HTTP_TUNNEL) { pSender->SendResponse(dwConnID, HSC_OK, "Connection Established"); } else if(enUpgradeType == HUT_WEB_SOCKET) { int iHeaderCount = 2; THeader header[] = {{"Connection", UPGRADE_HEADER}, {UPGRADE_HEADER, WEB_SOCKET_HEADER_VALUE}, {nullptr, nullptr}, {nullptr, nullptr}}; LPCSTR lpszAccept = nullptr; if(!pSender->GetHeader(dwConnID, "Sec-WebSocket-Key", &lpszAccept)) return HPR_ERROR; CStringA strAccept; ::MakeSecWebSocketAccept(lpszAccept, strAccept); header[2].name = "Sec-WebSocket-Accept"; header[2].value = strAccept; ++iHeaderCount; CStringA strFirst; LPCSTR lpszProtocol = nullptr; if(pSender->GetHeader(dwConnID, "Sec-WebSocket-Protocol", &lpszProtocol)) { int i = 0; CStringA strProtocol(lpszProtocol); strFirst = strProtocol.Tokenize(", ", i); if(!strFirst.IsEmpty()) { header[3].name = "Sec-WebSocket-Protocol"; header[3].value = strFirst; ++iHeaderCount; } } pSender->SendResponse(dwConnID, HSC_SWITCHING_PROTOCOLS, nullptr, header, iHeaderCount); pSender->SetConnectionExtra(dwConnID, new CBufferPtr); } else ASSERT(FALSE); return HPR_OK; }
/** * @brief Deletes a port map. * * @param portMapID Identifier for the port map. */ void UpnpNatAction::DeletePortMap(size_t portMapID) { ValidatePortMapCollection(); // Remove from collection ComString strProtocol(portMaps[portMapID].GetProtocol().GetNullTerminated()); HRESULT hResult = portMapCollection->Remove(portMaps[portMapID].GetExternalPort(),strProtocol.GetBSTR()); _ErrorException((hResult != S_OK), "removing a port map from the collection", hResult, __LINE__, __FILE__); // Remove from internal store portMaps.Erase(portMapID); }
EnHttpParseResult CServerDlg::OnUpgrade(HP_HttpServer pSender, HP_CONNID dwConnID, EnHttpUpgradeType enUpgradeType) { ::PostOnUpgrade(dwConnID, enUpgradeType, m_spThis->GetSenderName(pSender)); if(enUpgradeType == HUT_HTTP_TUNNEL) { ::HP_HttpServer_SendResponse(pSender, dwConnID, HSC_OK, "Connection Established", nullptr, 0, nullptr, 0); } else if(enUpgradeType == HUT_WEB_SOCKET) { THeader header[] = {{"Connection", UPGRADE_HEADER}, {UPGRADE_HEADER, WEB_SOCKET_HEADER_VALUE}, {nullptr, nullptr}, {nullptr, nullptr}}; LPCSTR lpszAccept = nullptr; if(!::HP_HttpServer_GetHeader(pSender, dwConnID, "Sec-WebSocket-Key", &lpszAccept)) return HPR_ERROR; CStringA strAccept; ::MakeSecWebSocketAccept(lpszAccept, strAccept); header[2].name = "Sec-WebSocket-Accept"; header[2].value = strAccept; LPCSTR lpszProtocol = nullptr; if(::HP_HttpServer_GetHeader(pSender, dwConnID, "Sec-WebSocket-Protocol", &lpszProtocol)) { int i = 0; CStringA strProtocol(lpszProtocol); CStringA strFirst = strProtocol.Tokenize(", ", i); if(!strFirst.IsEmpty()) { header[3].name = "Sec-WebSocket-Protocol"; header[3].value = strFirst; } } int iHeaderCount = sizeof(header) / sizeof(THeader); ::HP_HttpServer_SendResponse(pSender, dwConnID, HSC_SWITCHING_PROTOCOLS, nullptr, header, iHeaderCount, nullptr, 0); ::HP_Server_SetConnectionExtra(pSender, dwConnID, new CBufferPtr); } else ASSERT(FALSE); return HPR_OK; }
/** * @brief Adds a port map to the port forwarding list. * * @param externalPort The external port. * @param protocol The protocol. * @param internalPort The internal port. * @param internalIP The internal ip. * @param enabled True if the entry should be enabled, false if not. * @param description A description of the port map. */ void UpnpNatAction::AddPortMap(long externalPort, const char * protocol, long internalPort, const char * internalIP, bool enabled, const char * description) { ValidatePortMapCollection(); IStaticPortMapping * ptrNewPortMap = NULL; // Convert parameters for use with COM ComString strProtocol(protocol); ComString strInternalIP(internalIP); ComString strDescription(description); VARIANT_BOOL vbEnabled = ComUtility::ConvertBoolean(enabled); // Add to collection HRESULT hResult = portMapCollection->Add(externalPort,strProtocol.GetBSTR(),internalPort,strInternalIP.GetBSTR(),vbEnabled,strDescription.GetBSTR(),&ptrNewPortMap); _ErrorException((hResult != S_OK), "adding a port map to the collection (!= S_OK)", hResult, __LINE__, __FILE__); _ErrorException((ptrNewPortMap == NULL), "adding a port map to the collection (NULL)", NULL, __LINE__, __FILE__); // Add to internal store UpnpNatPortMapAction * newPortMap = new (nothrow) UpnpNatPortMapAction(ptrNewPortMap); Utility::DynamicAllocCheck(newPortMap,__LINE__,__FILE__); portMaps.Add(newPortMap); }
HX_RESULT HXFileSystemManager::ProcessGetFileObjectPending() { HX_LOG_BLOCK( "HXFileSystemManager::ProcessGetFileObjectPending" ); HX_RESULT theErr = HXR_OK; IUnknown* pUnknownFS = NULL; IUnknown* pUnknownFileObject = NULL; IHXFileSystemObject* pFileSystem = NULL; IHXRequestHandler* pRequestHandler = NULL; IHXPlugin2Handler* pPlugin2Handler = NULL; if (!m_pContext) { return HXR_FAILED; } /* * We might get released (and deleted) in the response object. so * Addref here and Release after the response function is called */ AddRef(); // get the plugin handler if (HXR_OK != m_pContext->QueryInterface(IID_IHXPlugin2Handler, (void**)&pPlugin2Handler)) { theErr = HXR_FAILED; goto exit; } const char* pURL; HX_ASSERT( NULL != m_pRequest ); if ( ( NULL == m_pRequest ) || ( m_pRequest->GetURL(pURL) != HXR_OK ) ) { theErr = HXR_FAILED; goto exit; } const char* pProtocolEnd; pProtocolEnd = HXFindChar(pURL,':'); if (!pProtocolEnd) { theErr = HXR_FAILED; } if (!theErr) { int nLength = pProtocolEnd - pURL; CHXString strProtocol(pURL,nLength); if (HXR_OK != (theErr = pPlugin2Handler->FindPluginUsingStrings(PLUGIN_CLASS, PLUGIN_FILESYSTEM_TYPE, PLUGIN_FILESYSTEMPROTOCOL, (char*)(const char*)strProtocol, NULL, NULL, pUnknownFS))) { goto exit; } IHXPlugin* pPluginInterface = NULL; if(!theErr) { theErr = pUnknownFS->QueryInterface(IID_IHXPlugin, (void**)&pPluginInterface); } if(!theErr) { theErr = pPluginInterface->InitPlugin(m_pContext); pPluginInterface->Release(); } if(!theErr) { theErr = pUnknownFS->QueryInterface(IID_IHXFileSystemObject, (void**)&pFileSystem); } // At this point we should initalize the file system.to do this we must find the // IHXValues for this mount path in the Options Cache. IHXValues* pOptions = NULL; pOptions = GetOptionsGivenURL(pURL); pFileSystem->InitFileSystem(pOptions); HX_RELEASE(pOptions); if(!theErr) { theErr = pFileSystem->CreateFile(&pUnknownFileObject); } if(!theErr) { if(HXR_OK == pUnknownFileObject->QueryInterface( IID_IHXRequestHandler, (void**)&pRequestHandler)) { pRequestHandler->SetRequest(m_pRequest); } else { theErr = HXR_FAILED; } } } else { theErr = HXR_FAILED; } if (!theErr && pUnknownFileObject) { m_pFSManagerResponse->FileObjectReady(HXR_OK, pUnknownFileObject); } else { m_pFSManagerResponse->FileObjectReady(HXR_FAILED, NULL); } exit: HX_RELEASE(pUnknownFS); HX_RELEASE(pUnknownFileObject); HX_RELEASE(pRequestHandler); HX_RELEASE(pFileSystem); HX_RELEASE(pPlugin2Handler); #ifndef _MACINTOSH // Note: This change is necessary for the Macintosh build due to the fact // that this platform uses a different approach in GetFileObject. The problem // is that file object processing had generally been done recursively, with // GetFileObject calling ProcessGetFileObjectPending, which in turn indirectly // invoked GetFileObject in a pattern of mutual recursion. The recursion had // always ended with a call to ProcessGetFileObjectPending. With the change // in GetFileObject: // #ifdef _MACINTOSH // if (!IsMacInCooperativeThread()) // the recursion would terminate in a GetFileObject call. This call would // unwind to the scheduler, which would then process the queued file object // by calling ProcessGetFileObjectPending. However, since the request object // was freed during the unwinding of the recursion, this object was no longer // available and hence the process failed. // // The best short term fix appears to be to remove this release. The best long // term fix is to eliminate the recursion (which would also simplify maintenance). // -cconover XXX HX_RELEASE(m_pRequest); #endif /* * Release for extra Addref */ Release(); return theErr; }