📄 sbinet.cpp
字号:
const VXIchar* SBinetInterface::GetImplementationName(void){ return SBINET_IMPLEMENTATION_NAME;}VXIinetResult SBinetInterface::Prefetch(/* [IN] */ VXIinetInterface* pThis, /* [IN] */ const VXIchar* pszModuleName, /* [IN] */ const VXIchar* pszName, /* [IN] */ VXIinetOpenMode eMode, /* [IN] */ VXIint32 nFlags, /* [IN] */ const VXIMap* pProperties ){ SBinetInterface* intr = (SBinetInterface*)pThis; if (!intr) { intr->Error(200, L"%s%s", L"Operation", L"Prefetch"); return (VXIinet_RESULT_INVALID_ARGUMENT); } VXIinetResult rc = VXIinet_RESULT_SUCCESS; SBinetLogFunc apiTrace (intr->GetLog(), g_SBinetDiagLogBase + MODULE_SBINET_TAGID, L"SBinetInterface::Prefetch", (int *) &rc, L"entering: 0x%p, %s, %s, 0x%x, 0x%x, 0x%p", pThis, pszModuleName, pszName, eMode, nFlags, pProperties); // check validation SBinetChannel* ch = intr->m_ch; if (!ch) { intr->Error(200, L"%s%s", L"Operation", L"Prefetch"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } rc = (ch->Prefetch)(pszModuleName, pszName, eMode, nFlags, pProperties); if (rc != VXIinet_RESULT_SUCCESS) { intr->Error(203,L"%s%d",L"rc",rc); } return (rc);}/* * Call Channel method */VXIinetResult SBinetInterface::Open(/* [IN] */ VXIinetInterface* pThis, /* [IN] */ const VXIchar* pszModuleName, /* [IN] */ const VXIchar* pszName, /* [IN] */ VXIinetOpenMode eMode, /* [IN] */ VXIint32 nFlags, /* [IN] */ const VXIMap* pProperties, /* [OUT] */ VXIMap* pmapStreamInfo, /* [OUT] */ VXIinetStream** ppStream ){ SBinetInterface* intr = (SBinetInterface*)pThis; if (!intr) { intr->Error(200, L"%s%s", L"Operation", L"Open"); return (VXIinet_RESULT_INVALID_ARGUMENT); } VXIinetResult rc = VXIinet_RESULT_SUCCESS; SBinetLogFunc apiTrace (intr->GetLog(), g_SBinetDiagLogBase + MODULE_SBINET_TAGID, L"SBinetInterface::Open", (int *) &rc, L"entering: 0x%p, %s, %s, 0x%x, 0x%x, 0x%p, " L"0x%p, 0x%p", pThis, pszModuleName, pszName, eMode, nFlags, pProperties, pmapStreamInfo, ppStream); // check validation SBinetChannel* ch = intr->m_ch; if (!ch) { intr->Error(200, L"%s%s", L"Operation", L"Prefetch"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } rc = (ch->Open)(pszModuleName, pszName, eMode, nFlags, pProperties, pmapStreamInfo,ppStream); if ((rc != VXIinet_RESULT_SUCCESS) && (rc != VXIinet_RESULT_NOT_MODIFIED) && (rc != VXIinet_RESULT_LOCAL_FILE)) { intr->Error(204,L"%s%d",L"rc",rc); } return (rc);}/* * We must call channel method so we can GC the stream */VXIinetResult SBinetInterface::Close(/* [IN] */ VXIinetInterface* pThis, /* [IN] */ VXIinetStream** ppStream ){ SBinetInterface* intr = (SBinetInterface*)pThis; if (!intr) { intr->Error(200, L"%s%s", L"Operation", L"Close"); return (VXIinet_RESULT_INVALID_ARGUMENT); } VXIinetResult rc = VXIinet_RESULT_SUCCESS; SBinetLogFunc apiTrace (intr->GetLog(), g_SBinetDiagLogBase + MODULE_SBINET_TAGID, L"SBinetInterface::Close", (int *) &rc, L"entering: 0x%p, 0x%p (0x%p)", pThis, ppStream, (ppStream ? *ppStream : NULL)); // check validation SBinetChannel* ch = intr->m_ch; if (!ch || !ppStream) { intr->Error(200, L"%s%s", L"Operation", L"Close"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } rc = (ch->Close)(ppStream); if (rc != VXIinet_RESULT_SUCCESS) { intr->Error(205,L"%s%d",L"rc",rc); } return (rc);} /* * Actually, we are simply going to go and call Stream routine directly here */VXIinetResult SBinetInterface::Read(/* [IN] */ VXIinetInterface* pThis, /* [OUT] */ VXIbyte* pBuffer, /* [IN] */ VXIulong nBuflen, /* [OUT] */ VXIulong* pnRead, /* [IN] */ VXIinetStream* pStream ){ SBinetInterface* intr = (SBinetInterface*)pThis; if (!intr) { intr->Error(200, L"%s%s", L"Operation", L"Read"); return (VXIinet_RESULT_INVALID_ARGUMENT); } VXIinetResult rc = VXIinet_RESULT_SUCCESS; SBinetLogFunc apiTrace (intr->GetLog(), g_SBinetDiagLogBase + MODULE_SBINET_TAGID, L"SBinetInterface::Read", (int *) &rc, L"entering: 0x%p, 0x%p, %lu, %lu, 0x%p", pThis, pBuffer, nBuflen, pnRead, pStream); // check validation SBinetChannel* ch = intr->m_ch; if (!ch) { intr->Error(200, L"%s%s", L"Operation", L"Read"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } SBinetStream* st = ch->GetStream(pStream); // Really just validates and casts if (!st) { intr->Error(200, L"%s%s", L"Operation", L"Read"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } //pBuffer[0] = 0; // may cause buffer overrun problems rc = (st->Read)(pBuffer,nBuflen, pnRead ); if ((rc != VXIinet_RESULT_SUCCESS) && (rc != VXIinet_RESULT_WOULD_BLOCK) && (rc != VXIinet_RESULT_END_OF_STREAM)) { intr->Error(206,L"%s%d",L"rc",rc); } return (rc);} /* * We don't implement this any where so just return */VXIinetResult SBinetInterface::Write(/* [IN] */ VXIinetInterface* pThis, /* [OUT] */ const VXIbyte* pBuffer, /* [IN] */ VXIulong nBuflen, /* [OUT] */ VXIulong* pnWritten, /* [IN] */ VXIinetStream* pStream ){ SBinetInterface* intr = (SBinetInterface*)pThis; if (!intr) { intr->Error(200, L"%s%s", L"Operation", L"Write"); return (VXIinet_RESULT_INVALID_ARGUMENT); } VXIinetResult rc = VXIinet_RESULT_SUCCESS; SBinetLogFunc apiTrace (intr->GetLog(), g_SBinetDiagLogBase + MODULE_SBINET_TAGID, L"SBinetInterface::Write", (int *) &rc, L"entering: 0x%p, 0x%p, %lu, 0x%p, 0x%p", pThis, pBuffer, nBuflen, pnWritten, pStream); // check validation SBinetChannel* ch = intr->m_ch; if (rc != VXIinet_RESULT_SUCCESS) { intr->Error(207,L"%s%d",L"rc",rc); } if (!ch) { intr->Error(200, L"%s%s", L"Operation", L"Write"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } // Not currently supported return (rc = VXIinet_RESULT_UNSUPPORTED);}/* * Call Channel method */VXIinetResult SBinetInterface::SetCookieJar( /* [IN] */ VXIinetInterface* pThis, /* [IN] */ const VXIVector* pJar ){ SBinetInterface* intr = (SBinetInterface*)pThis; if (!intr) { intr->Error(200, L"%s%s", L"Operation", L"SetCookieJar"); return (VXIinet_RESULT_INVALID_ARGUMENT); } VXIinetResult rc = VXIinet_RESULT_SUCCESS; SBinetLogFunc apiTrace (intr->GetLog(), g_SBinetDiagLogBase + MODULE_SBINET_TAGID, L"SBinetInterface::SetCookieJar", (int *) &rc, L"entering: 0x%p, 0x%p", pThis, pJar); // check validation SBinetChannel* ch = intr->m_ch; if (!ch) { intr->Error(200, L"%s%s", L"Operation", L"SetCookieJar"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } rc = (ch->SetCookieJar)(pJar); if (rc != VXIinet_RESULT_SUCCESS) { intr->Error(208,L"%s%d",L"rc",rc); } return (rc);} /* * Call Channel method */VXIinetResult SBinetInterface::GetCookieJar( /* [IN] */ VXIinetInterface* pThis, /* [OUT] */ VXIVector** ppJar, /* [OUT] */ VXIbool* pfChanged ){ SBinetInterface* intr = (SBinetInterface*)pThis; if (!intr) { intr->Error(200, L"%s%s", L"Operation", L"GetCookieJar"); return (VXIinet_RESULT_INVALID_ARGUMENT); } VXIinetResult rc = VXIinet_RESULT_SUCCESS; SBinetLogFunc apiTrace (intr->GetLog(), g_SBinetDiagLogBase + MODULE_SBINET_TAGID, L"SBinetInterface::GetCookieJar", (int *) &rc, L"entering: 0x%p, 0x%p, 0x%p", pThis, ppJar, pfChanged); // check validation SBinetChannel* ch = intr->m_ch; if (!ch) { intr->Error(200, L"%s%s", L"Operation", L"GetCookieJar"); return (rc = VXIinet_RESULT_INVALID_ARGUMENT); } rc = (ch->GetCookieJar)(ppJar,pfChanged); if (rc != VXIinet_RESULT_SUCCESS) { intr->Error(209, L"%s%d", L"rc", rc); } return (rc);}/* * Static callback for libwww to give us cookies. */BOOL SBinetInterface::setCookie(HTRequest* pHtRequest, HTCookie* pHtCookie, void* pParam){ VXIbool retVal = YES; if (pHtCookie) { HTParentAnchor* pParentAnchor = HTRequest_anchor( pHtRequest ); SBinetHttpStream* st = (SBinetHttpStream*)HTRequest_context(pHtRequest); if (!st) return (NO); SBinetChannel* chan = st->getChannel(); if (!chan) return (NO); if (!chan->cookiesEnabled()) return (NO); // Don't accept cookies /* These are owned by the anchor, freed when the anchor is */ const char *pszBase = HTAnchor_base( pParentAnchor ); const char *pszAnchorLocation = HTAnchor_address((HTAnchor*)pParentAnchor); if (pszAnchorLocation == NULL) pszAnchorLocation = ""; // Added this to prevent HTParse from // failing below // We use the actual originating domain rather than the sent // domain, for security. Really should compare the sent domain with // the one specified by the cookie, rejecting it if the domains are // different (can't be a straight strcmp( ), have to allow for // subdomains, see the cookie RFC). // // PARSE_HOST: Host name, e.g. "www.w3.org" // PARSE_ACCESS: URL scheme, e.g. "HTTP" char *pszDomain = HTParse(pszAnchorLocation, pszBase, PARSE_HOST); char *pszAccess = HTParse(pszAnchorLocation, pszBase, PARSE_ACCESS); // const char* pszDomain = HTCookie_domain( pHtCookie ); const char *pszPath = HTCookie_path ( pHtCookie ); const char *pszName = HTCookie_name ( pHtCookie ); const char *pszValue = HTCookie_value ( pHtCookie ); // Need to check for proper number of .'s in domain as specified // by the cookie RFC if ((pszDomain != NULL) && (pszAccess != NULL) && (pszPath != NULL) && (pszName != NULL) && (pszValue != NULL)) { time_t tExpiration = HTCookie_expiration( pHtCookie ); VXIbool fSecure = HTCookie_isSecure( pHtCookie ) ? true : false; if (chan->updateCookieIfExists(pszDomain, pszPath, pszName, pszValue, tExpiration, fSecure) == 0) { // Create new cookie SBinetCookie* pSBinetCookie = new SBinetCookie( pszDomain, pszPath, pszName, pszValue, tExpiration, fSecure ); if (pSBinetCookie != NULL) { if (chan->addCookie(pSBinetCookie) == 0) delete pSBinetCookie; // Could not add } else retVal = NO; } } if (pszDomain != NULL) HT_FREE( pszDomain ); if (pszAccess != NULL) HT_FREE( pszAccess ); } return (retVal);}HTAssocList* SBinetInterface::findCookie( HTRequest* pHtRequest, void* pParam){ if (!pHtRequest ) return NULL; // Sanity HTParentAnchor* pParentAnchor = HTRequest_anchor( pHtRequest ); SBinetHttpStream* st = (SBinetHttpStream*)HTRequest_context(pHtRequest); if (!st) return (NULL); SBinetChannel* chan = st->getChannel(); if (!chan) return (NULL); if (!chan->cookiesEnabled()) return (NULL); // Don't send cookies char* pszAnchorLocation = HTAnchor_location( pParentAnchor ); if (pszAnchorLocation == NULL) pszAnchorLocation = ""; // Added this to prevent HTParse from failing // below char* pszBase = HTAnchor_base( pParentAnchor ); // Host name, e.g. "www.w3.org" char* pszDomain = HTParse(pszAnchorLocation,pszBase,PARSE_HOST); // URL Path, e.g. "pub/WWW/TheProject.html" char* pszPath = HTParse(pszAnchorLocation,pszBase,PARSE_PATH); // Remove the filename portion of the path, leaving the trailing // slash or backslash. (Note we don't have to worry about the // query args containing a slash because the standard for query // args makes it so slashes are hex encoded.) if (pszPath) { char *ptr = strrchr (pszPath, '/'); char *ptr2 = strrchr (pszPath, '\\'); if ((! ptr) || ((ptr2) && (ptr2 > ptr))) ptr = ptr2; if (ptr) *(ptr + 1) = '\0'; else strcpy (pszPath, "/"); } // Collect cookies HTAssocList* pAssocList = chan->collectCookies(pszDomain, pszPath); if (pszDomain != NULL) HT_FREE(pszDomain); if (pszPath != NULL) HT_FREE(pszPath); return (pAssocList);}//// LibWWW global trace and alert handlers (static!)//PUBLIC int SBinet::PrintCallback(const char * fmt, va_list pArgs){ int rc = 0; if ((g_SBinet) && (g_SBinet->DiagIsEnabled(MODULE_SBINET_HTPRINT_TAGID))) { char buffer[4096]; rc = vsprintf(buffer, fmt, pArgs); if ((buffer) && (buffer[0])) g_SBinet->Diag (MODULE_SBINET_HTPRINT_TAGID, NULL, L"%S", buffer); } return rc;}PUBLIC int SBinet::TraceCallback(const char * fmt, va_list pArgs){ int rc = 0; if ((g_SBinet) && (g_SBinet->DiagIsEnabled(MODULE_SBINET_HTTRACE_TAGID))) { char buffer[4096]; rc = vsprintf(buffer, fmt, pArgs); if ((buffer) && (buffer[0])) g_SBinet->Diag (MODULE_SBINET_HTTRACE_TAGID, NULL, L"%S", buffer); } return rc;}PUBLIC intSBinet::TraceDataCallback(char * data, size_t len, char * fmt, va_list pArgs){ int rc = 0; if ((g_SBinet) && (g_SBinet->DiagIsEnabled(MODULE_SBINET_HTTRACEDATA_TAGID))) { char buffer[4096]; rc = vsprintf(buffer, fmt, pArgs); if ((data) && (len) && (rc < 4096 - 3)) { if (rc > 0) { ::strcat(&buffer[rc], ": "); rc += 2; } else { rc = 0; } if (rc + len < 4096 - 1) { ::strncat(&buffer[rc], data, len); rc += len; } else { ::strncat(&buffer[rc], data, 4095 - rc); rc = 4095; } buffer[rc] = 0; } if ((buffer) && (buffer[0])) g_SBinet->Diag (MODULE_SBINET_HTTRACEDATA_TAGID, NULL, L"%S", buffer); } return rc;}PUBLIC BOOLSBinet::AlertCallback(HTRequest* pHtRequest, HTAlertOpcode eOpCode, int nMessageNum, const char* pszDefault, void* pvInput, HTAlertPar* pReply){ if ((g_SBinet) && (g_SBinet->DiagIsEnabled(MODULE_SBINET_HTALERT_TAGID))) { // Have to free the message when we're done with it char *pszMessageText = HTDialog_progressMessage(pHtRequest, eOpCode, nMessageNum, pszDefault, pvInput); if ((pszMessageText) && (pszMessageText[0])) g_SBinet->Diag (MODULE_SBINET_HTALERT_TAGID, NULL, L"%S", pszMessageText); HT_FREE(pszMessageText); } return ((BOOL)YES ); // Confirm...}PUBLIC voidSBinet::OutOfMemoryExitCallback(char *name, char *file, unsigned long line){ if (g_SBinet) g_SBinet->Error(106, L"%s%S%s%S%s%lu", L"name", name, L"file", file, L"line", line); // Libwww doesn't know how to recover so we have to exit, see // HTMemory.c. For Win32, show an exception window, on UNIX dump // core.#ifdef WIN32 static char exception_msg[4096]; static DWORD exception_args[EXCEPTION_MAXIMUM_PARAMETERS]; sprintf (exception_msg, "Libwww out of memory for %s, file %s, line %lu", name, file, line); exception_args[0] = (DWORD) exception_msg; RaiseException(0xE001AEAE, EXCEPTION_NONCONTINUABLE, 1, exception_args);#else abort();#endif}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -