📄 httpfsys.cpp
字号:
HX_RESULT theErr = HXR_OK; IHXRequestHandler* pReqHandler = NULL; IHXRequest* pRequest = NULL; IHXProxyAutoConfig* pPAC = NULL; if (m_bInitialized) { if (m_LastError == HXR_OK) { AddNoCacheHeader(); pFileExistsResponse->DoesExistDone(TRUE); return HXR_OK; } else { pFileExistsResponse->DoesExistDone(FALSE); return HXR_OK; } } // If we have received a request object, extract from it the // full URL. This will include any URL parameters which we // need, but which are not contained in the simple file name // that was passed in as our first parameter. - DPS HX_ASSERT(m_pRequest); if (m_pRequest) { m_pRequest->GetURL(pPath); } // we don't want use PAC if we are within the process of PAC detecting if (HXR_OK == pFileExistsResponse->QueryInterface(IID_IHXProxyAutoConfig, (void**)&pPAC)) { theErr = _OpenFile(pPath, HX_FILE_READ | HX_FILE_BINARY | HX_FILE_NOPAC); } else { theErr = _OpenFile(pPath, HX_FILE_READ | HX_FILE_BINARY); } HX_RELEASE(pPAC); if (HXR_OK == theErr || HXR_WOULD_BLOCK == theErr) { if (m_bCached) { pFileExistsResponse->DoesExistDone(TRUE); } else { m_pFileExistsResponse = pFileExistsResponse; m_pFileExistsResponse->AddRef(); m_bFileExistsResponsePending = TRUE; } return HXR_OK; } else { pFileExistsResponse->DoesExistDone(FALSE); return HXR_OK; }}/* * IHXFileMimeMapper methods *//************************************************************************ * Method: * IHXFileMimeMapper::FindMimeType * Purpose: */STDMETHODIMP CHTTPFileObject::FindMimeType( const char* /*IN*/ pURL, IHXFileMimeMapperResponse* /*IN*/ pMimeMapperResponse){ LOGX ((szDbgTemp, "FindMimeType(%s)", pURL)); HX_RESULT theErr = HXR_OK; if (m_bInitialized) { if (m_LastError == HXR_OK) { // Determine mime type here! const char* pMimeType = NULL; if (!m_strMimeType.IsEmpty()) pMimeType = m_strMimeType; LOGX ((szDbgTemp, " MimeTypeFound(%s)", pMimeType)); pMimeMapperResponse->MimeTypeFound(HXR_OK, pMimeType); return HXR_OK; } else { LOGX ((szDbgTemp, " MimeTypeFound(NULL)")); pMimeMapperResponse->MimeTypeFound(m_LastError, NULL); return HXR_FAILED; } } // If we have received a request object, extract from it the // full URL. This will include any URL parameters which we // need, but which are not contained in the simple file name // that was passed in as our first parameter. HX_ASSERT(m_pRequest); if (m_pRequest) { m_pRequest->GetURL(pURL); } theErr = _OpenFile(pURL,HX_FILE_READ|HX_FILE_BINARY); if (HXR_OK == theErr || HXR_WOULD_BLOCK == theErr) { if (m_bCached) { const char* pMimeType = NULL; if (!m_strMimeType.IsEmpty()) { pMimeType = m_strMimeType; } LOGX ((szDbgTemp, " Cached MimeType='%s'", NULLOK(m_strMimeType))); pMimeMapperResponse->MimeTypeFound(HXR_OK, pMimeType); } else { m_pMimeMapperResponse = pMimeMapperResponse; m_pMimeMapperResponse->AddRef(); m_bMimeResponsePending = TRUE; } return HXR_OK; } else { pMimeMapperResponse->MimeTypeFound(HXR_INVALID_PATH, NULL); return HXR_FAILED; }}/* * IHXPendingStatus methods *//************************************************************************ * Method: * IHXPendingStatus::GetStatus * Purpose: * Called by the user to get the current pending status from an object */STDMETHODIMP CHTTPFileObject::GetStatus(REF(UINT16) uStatusCode, REF(IHXBuffer*) pStatusDesc, REF(UINT16) ulPercentDone){ /* Default values*/ uStatusCode = HX_STATUS_READY; pStatusDesc = 0; ulPercentDone = 0; if (!m_bConnectDone) { uStatusCode = HX_STATUS_CONTACTING; if (!m_strHost.IsEmpty()) { CHXString statusDesc = "Contacting "; statusDesc += m_strHost; statusDesc += "..."; pStatusDesc = new CHXBuffer; pStatusDesc->AddRef(); pStatusDesc->Set((UCHAR*)(const char*) statusDesc, strlen((const char*)statusDesc)+1); } ulPercentDone = 0; } else if (m_bReadContentsDone) { uStatusCode = HX_STATUS_READY; ulPercentDone = 0; } else if (m_bSeekPending || !m_PendingReadList.IsEmpty()) { uStatusCode = HX_STATUS_BUFFERING; ULONG32 ulReadCount = 0; if (!m_PendingReadList.IsEmpty()) { ulReadCount = (ULONG32)(PTR_INT)m_PendingReadList.GetHead(); } if (m_ulCurrentReadPosition+ulReadCount) { ulPercentDone = (UINT16) ((m_nContentRead*100)/(m_ulCurrentReadPosition+ulReadCount)); ulPercentDone = ulPercentDone <= 100 ? (UINT16) ulPercentDone : 100; } else { ulPercentDone = (UINT16) 100; } } return HXR_OK;}/************************************************************************ * Method: * Private interface::OpenFile * Purpose: * This common method is used from Init() and GetFileObjectFromPool() */HX_RESULT CHTTPFileObject::_OpenFile(const char* url, ULONG32 ulFlags){ HX_RESULT theErr = HXR_OK; HX_RESULT lResult = HXR_OK; UINT16 un16Temp = 0; char* pTemp = NULL; IHXBuffer* pBuffer = NULL; IHXBuffer* pProxyName = NULL; IHXBuffer* pProxyPort = NULL; IHXProxyManager* pProxyManager = NULL; LOG("_OpenFile"); LOGX((szDbgTemp, " URL='%s'", url)); // Make local copy of url CHXString strTemp = url; char* pTempURL = strTemp.GetBuffer(strTemp.GetLength()); char* pURL = NULL; char* pOrigURL = NULL; CHXURL* pCHXURL = new CHXURL(pTempURL); if (pCHXURL) { IHXValues* pHeader = pCHXURL->GetProperties(); if(pHeader) { IHXBuffer* pUrlBuffer = NULL; if(HXR_OK == pHeader->GetPropertyBuffer(PROPERTY_URL, pUrlBuffer) && pUrlBuffer) { pURL = ::new_string((const char*)pUrlBuffer->GetBuffer()); HX_RELEASE(pUrlBuffer); } HX_RELEASE(pHeader); } delete pCHXURL; } // if somehow the URL is messed up and the URL parser freaks out, // we fall back to the original URL. if (!pURL) { pURL = ::new_string(pTempURL); } pOrigURL = pURL; if (pOrigURL && (strncasecmp(pOrigURL, "https:", 6) == 0)) { m_bUseHTTPS = TRUE; } else { m_bUseHTTPS = FALSE; } // HTTP requires '/' as the element delimiter. // (Or at least the TIS proxy does) // So change all '\\' to '/'. // Also, try not to proccess any parameters. pTemp = pURL; while(*pTemp && *pTemp!='?' && *pTemp!='#') { if(*pTemp == '\\') { *pTemp = '/'; } pTemp++; } // We always store the entire original URL as the proxy resource! m_strProxyResource = pURL; m_strHost = ""; m_nPort = DEF_HTTP_PORT; m_strResource = ""; // if the url's first five characters are "http:" // then jump past them... Otherwise, just assume // the URL starts with the host... This will allow // someone to mount the HTTP file system on the // server and proxy another web server... <g> // [Modified to look for ':' character - fnh] char* pcColon = (char *) HXFindChar (pURL, ':'); char* pcQuery = (char *) HXFindChar (pURL, '?'); if (pcColon && (pcQuery == 0 || pcColon < pcQuery)) { pURL = pcColon + 1; } // Jump past the double whack if present... if (HXCompareStrings(pURL, "//", 2) == 0) { pURL += 2; } pTemp = (char *)HXFindChar(pURL, '/'); if (pTemp) { // Fix for PR104465 // CHXURL now always unescapes the URL which means we need to make sure that resource is correctly encoded // before sending to the server. CHXURL::encodeURL(pTemp, m_strResource); // /* Remainder is resource */ *pTemp = '\0'; } // Look for the '@' character which means there is a username and/or password. We skip over this part to the // hostname. The '@' character is reserved according to RFC 1738 show it shouldn't appear in a URL pTemp = (char *)HXFindChar (pURL, '@'); if (pTemp) pURL += (pTemp - pURL + 1); /* Port (optional) */ pTemp = (char *)HXFindChar (pURL, ':'); if (pTemp) { *pTemp = '\0'; m_nPort = ::atoi(pTemp+1); // port '0' is invalid, but we'll get that if the url had ':' but no port number // following. Setting to default http_port in this case will mimic the // behaviour of pnm: and rtsp: if no port specified after ':' if (m_nPort==0) { m_nPort = DEF_HTTP_PORT; } } /* if (pTemp) */ m_strHost = pURL; if (m_pPreferences->ReadPref("HTTPProxyAutoConfig", pBuffer) == HXR_OK) { un16Temp = atoi((const char*) pBuffer->GetBuffer()); } // previously released Enterprise player may use "ProxyAutoConfig" for // HTTP proxy auto config else if (m_pPreferences->ReadPref("ProxyAutoConfig", pBuffer) == HXR_OK) { un16Temp = atoi((const char*) pBuffer->GetBuffer()); } HX_RELEASE(pBuffer); // HTTP Proxy Auto Config if (un16Temp && !(HX_FILE_NOPAC & ulFlags)) { if (!m_pPAC) { m_pContext->QueryInterface(IID_IHXProxyAutoConfig, (void**)&m_pPAC); } if (m_pPAC && (!m_pPACInfoList || 0 == m_pPACInfoList->GetCount())) { theErr = m_pPAC->GetHTTPProxyInfo((IHXProxyAutoConfigCallback*)this, url, m_strHost); } // attempt the next proxy info from m_pPACInfoList else if (m_pPACInfoList && m_PACInfoPosition) { PACInfo* pPACInfo = (PACInfo*)m_pPACInfoList->GetNext(m_PACInfoPosition); if (pPACInfo && pPACInfo->type != PAC_DIRECT) { m_bUseProxy = TRUE; m_nProxyPort = pPACInfo->ulPort; m_strProxyHost = pPACInfo->pszHost; } } // XXX HP TBD // we should attempt the next proxy info from m_pPACInfoList if (HXR_WOULD_BLOCK == theErr) { m_bGetProxyInfoPending = TRUE; goto cleanup; } } else if (m_pPreferences->ReadPref("HTTPProxySupport", pBuffer) == HXR_OK) { if (atoi((const char*)pBuffer->GetBuffer())) { if(m_pPreferences->ReadPref("HTTPProxyHost", pProxyName) == HXR_OK && m_pPreferences->ReadPref("HTTPProxyPort", pProxyPort) == HXR_OK) { m_nProxyPort = atoi((const char*)pProxyPort->GetBuffer()); m_strProxyHost = (const char*)pProxyName->GetBuffer(); if (m_strProxyHost.GetLength() > 0 && m_nProxyPort > 0) { if (HXR_OK == m_pContext->QueryInterface(IID_IHXProxyManager, (void**)&pProxyManager) && pProxyManager) { m_bUseProxy = !(pProxyManager->IsExemptionHost((char*)(const char*)m_strHost)); }#if defined(HELIX_FEATURE_PROXYMGR) else { pProxyManager = new HXProxyManager(); pProxyManager->AddRef(); if (HXR_OK == pProxyManager->Initialize(m_pContext)) { m_bUseProxy = !(pProxyManager->IsExemptionHost((char*)(const char*)m_strHost)); } }#endif /* #if defined(HELIX_FEATURE_PROXYMGR) */ HX_RELEASE(pProxyManager); } } HX_RELEASE(pProxyName); HX_RELEASE(pProxyPort); } } HX_RELEASE(pBuffer); theErr = _OpenFileExt();cleanup: HX_VECTOR_DELETE(pOrigURL); return theErr;}HX_RESULTCHTTPFileObject::_OpenFileExt(){ HX_RESULT theErr = HXR_OK; CacheSupport_OpenFile(); if (m_bCached) { m_bInitPending = FALSE; } else { /* connect to the host and start getting the data */ theErr = BeginGet(m_uByteRangeSeekOffset); if (!theErr) { m_bInitPending = TRUE; } } return the
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -