⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sbinetchannel.cpp

📁 Open VXI. This is a open source.
💻 CPP
📖 第 1 页 / 共 2 页
字号:
/****************License************************************************ * * Copyright 2001.  SpeechWorks International, Inc. * * Use of this software is subject to notices and obligations set forth * in the SpeechWorks Public License - Software Version 1.1 which is * included with this software. *  * SpeechWorks is a registered trademark, and SpeechWorks Here,  * DialogModules and the SpeechWorks logo are trademarks of SpeechWorks  * International, Inc. in the United States and other countries.  *  *********************************************************************** * * SBinetChannel Implementation * * $Id: SBinetChannel.cpp,v 1.24.2.1.2.3 2001/10/03 16:20:51 dmeyer Exp $ * ***********************************************************************/#ifndef _SB_USE_STD_NAMESPACE#define _SB_USE_STD_NAMESPACE#endif#include <WWWLib.h>#include <WWWHTTP.h>#include <WWWInit.h>#ifdef EINVAL// Conflicts with OS definition#undef EINVAL#endif#define SBINET_EXPORTS#include "VXItypes.h"#include "VXIvalue.h"#include "VXIinet.h"#include "VXItrd.h"#include "VXIlog.h"#include "SBinetLog.h"#include "SBinetStream.h"#include "SBinetChannel.h"#include "SBinetURL.h"#include "SBinetCookie.h"/***************************************************************************** ***************************************************************************** * SBinetChannel Implementation ***************************************************************************** ***************************************************************************** */SBinetChannel::SBinetChannel( VXIlogInterface* pVXILog,			      VXIunsigned diagLogBase ) :  SBinetLogger(MODULE_SBINET_CHANNEL, pVXILog, diagLogBase){  Diag (MODULE_SBINET_CHANNEL_TAGID, L"SBinetChannel::SBinetChannel",	L"0x%p", pVXILog);  m_cookies = NULL;  m_numCookies = 0;  m_jarChanged = true;  m_cookiesEnabled = false; // Until SetCookieJar() is called with a valid jar  m_pVXILog = pVXILog;}SBinetChannel::~SBinetChannel( ){  Diag (MODULE_SBINET_CHANNEL_TAGID, L"SBinetChannel::~SBinetChannel", NULL);  deleteAllCookies();  // NOP //    // NOP //    // NOP //}SBinetStream*SBinetChannel::GetStream(VXIinetStream* str){  return((SBinetStream*)str);        // really should validate, but for now}/* * Prefetch: For now punt, eventually spawn thread to call Open() into /dev/null */VXIinetResult SBinetChannel::Prefetch(  const VXIchar*  pszModuleName,			  const VXIchar*  pszName,			  VXIinetOpenMode eMode,			  VXIint32        nFlags,			  const VXIMap*   pProperties ){  /*   * Add prefetch request to prefetch queue. These requests are   * processed when the fetch engine is idle, and the fetched    * documents are stored in the Inet cache until retrieved by   * a subsequent Open call. Note that in order for prefetching    * to work, caching must be enabled, the fetched document must    * be cachable (server must not return a 'no-cache' directive)    * and the caching mode must not be SAFE.   */#if 0 // NOT YET IMPLEMENTED  Diag( MODULE_SBINET_CHANNEL_TAGID, L"SBinetChannel::Prefetch",	    L"(%s)", pszName );  if(eMode != INET_MODE_READ)    return VXIinet_RESULT_UNSUPPORTED;  // Only HTTP requests can be prefetched  // Parse URL, combine and narrow  SBinetURL* url = new SBinetURL();  if(url == NULL) {    Error(103, NULL);    return VXIinet_RESULT_OUT_OF_MEMORY;  }  else if(url->Parse(pszName, eMode, nFlags, pProperties) != 0) {    delete url;    return VXIinet_RESULT_INVALID_ARGUMENT;  }  int scheme = url->GetScheme();  if(scheme == SBinetURL::FILE_SCHEME) {    delete url;    return VXIinet_RESULT_UNSUPPORTED;  }  SBinetPrefetchRequest *request = new SBinetPrefetchRequest;  if( request == NULL) {    Error(103, NULL);    return VXIinet_RESULT_OUT_OF_MEMORY;  }  request->pChannel = this;  request->pInetURL = url;  request->nFlags = nFlags;  // Clone the properties and extract the prefetch priority  if( pProperties != NULL ) {    request->pProperties = VXIMapClone(pProperties);    VXIInteger *priority =       (VXIInteger *)VXIMapGetProperty(pProperties, INET_PREFETCH_PRIORITY);    if( priority != NULL)      request->ePriority = (VXIinetPrefetchPriority)VXIIntegerValue(priority);  }  AddToPrefetchQueue(request);#endif  return VXIinet_RESULT_SUCCESS;}#if 0 // NOT YET IMPLEMENTED// PrefetchRequest//class SBinetPrefetchRequest { public:  VXIinetPrefetchPriority ePriority;  SBinetURL* pInetURL;  VXIint32 nFlags;  VXIMap *pProperties;  SBinetChannel *pChannel;  SBinetPrefetchRequest() {    ePriority = INET_PREFETCH_PRIORITY_LOW;    pInetURL = NULL;    nFlags = 0;    pProperties = NULL;  }  ~SBinetPrefetchRequest() {    if( pInetURL != NULL )      delete pInetURL;    if( pProperties != NULL )      VXIMapDestroy(&pProperties);  }};VXIinetResult SBinetChannel::ProcessPrefetchRequest( SBinetPrefetchRequest *pRequest ){  Diag( MODULE_SBINET_CHANNEL_TAGID, L"SBinetChannel::ProcessPrefetchRequest",	    L"(%s)", pRequest->pInetURL->GetAbsoluteWide());  /*   * Create Stream   */  SBinetStream* pStream =     (SBinetStream *)(new SBinetHttpStream(pRequest->pInetURL, this));  if(pStream == NULL) {    delete pRequest;    return VXIinet_RESULT_OUT_OF_MEMORY;  }  /*   * Call Stream Open.   *  At the moment (5/9/01, this will block until entire page is loaded   */  VXIinetResult result =     pStream->Open(pRequest->nFlags, (VXIMap*)pRequest->pProperties, NULL);  if( result == VXIinet_RESULT_SUCCESS )    result = Close((VXIinetStream **)&pStream);  return result;}#endifVXIinetResultSBinetChannel::CloseAll(){  // should interate over open stream and close gracefully  return(VXIinet_RESULT_SUCCESS);}/* * Open: Serious work here. *   Parse URL and combine with base *   Collect properties and query args *   Call appropriate Stream constructor base on URL scheme (http or file) *   Call Open() on stream */VXIinetResult SBinetChannel::Open( const VXIchar*   pszModuleName,		     const  VXIchar*  pszName,		     VXIinetOpenMode  eMode,		     VXIint32         nFlags,		     const VXIMap*    pProperties,		     VXIMap*          pmapStreamInfo,		     VXIinetStream**  ppStream     ){  if(eMode != INET_MODE_READ)    return(VXIinet_RESULT_UNSUPPORTED);  if(!ppStream) {    Error(200, L"%s%s", L"Operation", L"Open");    return(VXIinet_RESULT_INVALID_ARGUMENT);  }  *ppStream = (VXIinetStream*)NULL; // in case of failure  /*   * Parse URL, combine and narrow   */  Diag (MODULE_SBINET_CHANNEL_TAGID, L"SBinetChannel::Open",	L"(%s)", pszName);  SBinetURL* url = new SBinetURL();  // NULL constructor  if (! url) {    Error(103, NULL);    return(VXIinet_RESULT_OUT_OF_MEMORY);  } else if(url->Parse(pszName,eMode,nFlags,pProperties)) {    delete url;    Error(200, L"%s%s", L"Operation", L"Open");    return(VXIinet_RESULT_INVALID_ARGUMENT);  }  /*   * Create Stream   */  SBinetStream* st = NULL;  int scheme = url->GetScheme();  /*   * Note: Stream now owns url and must delete on cleanup   */  if(scheme == SBinetURL::HTTP_SCHEME)    st = (SBinetStream*)(new SBinetHttpStream(url, this,                                               GetLog(), GetDiagBase()));  else if(scheme == SBinetURL::FILE_SCHEME)    st = (SBinetStream*)(new SBinetFileStream(url, GetLog(), GetDiagBase()));  if(!st) {    delete url;    Error(103, NULL);    return(VXIinet_RESULT_OUT_OF_MEMORY);  }  /*   * Call Stream Open.   *  At the moment (5/9/01, this will block until entire page is loaded   */  VXIinetResult err = st->Open(nFlags,(VXIMap*)pProperties,pmapStreamInfo);  if(err == VXIinet_RESULT_SUCCESS)    *ppStream = (VXIinetStream*)st;  else    delete st;  return(err);}VXIinetResult SBinetChannel::Close(VXIinetStream**  ppStream){  if(!ppStream) {    Error(200, L"%s%s", L"Operation", L"Close");    return(VXIinet_RESULT_INVALID_ARGUMENT);  }  SBinetStream* st = GetStream(*ppStream);   // Really just validates and casts  VXIinetResult err;  if(st){    err = st->Close();    delete st;    st = NULL;  }  else{    Error(200, L"%s%s", L"Operation", L"Close");    err = VXIinet_RESULT_INVALID_ARGUMENT;  }  *ppStream = (VXIinetStream*)NULL;  return(err);}//// Static method//VXIinetResult SBinetChannel::SetCookieJar( const VXIVector* pJar ){  const VXIchar  *key = NULL;  const VXIValue *value = NULL;  char *EMPTY_STRING = "";  deleteAllCookies();  if(pJar == NULL) { // NULL jar means 'disable cookie usage'    m_jarChanged = false;    m_cookiesEnabled = false;    return VXIinet_RESULT_SUCCESS;  }  m_cookiesEnabled = true; // Enable cookie usage  VXIunsigned numElements = VXIVectorLength(pJar);  for (VXIunsigned i = 0; i < numElements; i++) {    const VXIMap *cookie = (const VXIMap *) VXIVectorGetElement(pJar, i);    if ( cookie == NULL ) {

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -