SBinetChannel.h
上传用户:xqtpzdz
上传日期:2022-05-21
资源大小:1764k
文件大小:11k
源码类别:

xml/soap/webservice

开发平台:

Visual C++

  1. #ifndef SBINETCHANNEL_H                   /* Allows multiple inclusions */
  2. #define SBINETCHANNEL_H
  3. /****************License************************************************
  4.  * Vocalocity OpenVXI
  5.  * Copyright (C) 2004-2005 by Vocalocity, Inc. All Rights Reserved.
  6.  * This program is free software; you can redistribute it and/or
  7.  * modify it under the terms of the GNU General Public License
  8.  * as published by the Free Software Foundation; either version 2
  9.  * of the License, or (at your option) any later version.
  10.  *  
  11.  * This program is distributed in the hope that it will be useful,
  12.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14.  * GNU General Public License for more details.
  15.  *
  16.  * You should have received a copy of the GNU General Public License
  17.  * along with this program; if not, write to the Free Software
  18.  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
  19.  * Vocalocity, the Vocalocity logo, and VocalOS are trademarks or 
  20.  * registered trademarks of Vocalocity, Inc. 
  21.  * OpenVXI is a trademark of Scansoft, Inc. and used under license 
  22.  * by Vocalocity.
  23.  ***********************************************************************/
  24. #include "VXItypes.h"
  25. #include "VXIvalue.h"
  26. #include "VXIinet.h"
  27. #include "VXItrd.h"
  28. #include "VXIcache.h"
  29. #include "SBinetLog.h"
  30. #include <SWIutilLogger.hpp>
  31. #include "SBinetString.hpp"
  32. #include <SWIHashMap.hpp>
  33. #include <SWIList.hpp>
  34. #include <SWIstream.hpp>
  35. class SBinetCookie;
  36. class SBinetURL;
  37. class SBinetProxyMatcher;
  38. class SWIoutputStream;
  39. class SWIinputStream;
  40. class SWIdataOutputStream;
  41. class SBinetHttpConnection;
  42. class SBinetHttpCacheStream;
  43. class SBinetMD5;
  44. class VXItrdMutexRef;
  45. class SBinetChannel : public VXIinetInterface, public SWIutilLogger
  46. {
  47.   public:
  48.   SBinetChannel(VXIlogInterface* log,
  49.                 VXIunsigned diagLogBase,
  50.                 VXIcacheInterface* pVXIcache);
  51.   ~SBinetChannel();
  52.   // Adds a cookie without verifying whether the cookie already exists.
  53.   bool addCookie(SBinetCookie* cookie);
  54.   // If a corresponding cookie already exists. Replaces it, otherwise adds it.
  55.   bool updateCookie(SBinetCookie* cookie);
  56.   VXIint cleanCookies();
  57.   void deleteAllCookies();
  58.   void collectCookies(SWIoutputStream* output,
  59.                       const char *domain,
  60.                       const char *path);
  61.   bool updateCookieIfExists( const char*   pszDomain,
  62.                              const char*   pszPath,
  63.                              const char*   pszName,
  64.                              const char*   pszValue,
  65.                              time_t  nExpires,
  66.                              bool fSecure );
  67.   bool cookiesEnabled() { return _cookiesEnabled; }
  68.   SBinetHttpConnection *getHttpConnection(const SBinetURL *url,
  69.                                           const VXIMap *properties);
  70.   void putHttpConnection(SBinetHttpConnection *connection);
  71.   void closeHttpConnections();
  72.  public:
  73.   // Initialize the class at startup, shutdown later
  74.   static VXIinetResult init(const VXIMap *configParams, const SWIutilLogger *logger);
  75.   static void shutdown();
  76.   static const VXIchar* mapExtension(const VXIchar* ext);
  77.   static void addExtensionRule(const VXIchar* ext, const VXIchar* mimeType);
  78.   static VXIint32 getPostContinueTimeout();
  79.   static bool setPostContinueTimeout(VXIint32 timeout);
  80.   static VXIint32 getPageLoadTimeout();
  81.   static bool setPageLoadTimeout(VXIint32 timeout);
  82.   static time_t getFreshnessLifetime();
  83.   static bool setFreshnessLifetime(time_t freshnessLifetime);
  84.   static double getFreshnessFraction();
  85.   static bool setFreshnessFraction(double freshnessFraction);
  86.   static time_t getMaxLifetime();
  87.   static bool setMaxLifetime(time_t maxLifetime);
  88.   static bool getUsePersistentConnections();
  89.   static void setUsePersistentConnections(bool f);
  90.   VXIinetResult closeAllStreams();
  91.   VXIinetResult prefetch(/* [IN]  */ const VXIchar*   pszModuleName,
  92.                          /* [IN]  */ const VXIchar*   pszName,
  93.  /* [IN]  */ VXIinetOpenMode  eMode,
  94.  /* [IN]  */ VXIint32         nFlags,
  95.  /* [IN]  */ const VXIMap*    pProperties  );
  96.   VXIinetResult open(/* [IN]  */ const VXIchar*   pszModuleName,
  97.                      /* [IN]  */ const  VXIchar*  pszName,
  98.                      /* [IN]  */ VXIinetOpenMode  eMode,
  99.                      /* [IN]  */ VXIint32         nFlags,
  100.                      /* [IN]  */ const VXIMap*    pProperties,
  101.                      /* [OUT] */ VXIMap*          pmapStreamInfo,
  102.                      /* [OUT] */ VXIinetStream**  ppStream     );
  103.   VXIinetResult close(/* [IN]  */ VXIinetStream**  ppStream     );
  104.   VXIinetResult read(/* [OUT] */ VXIbyte*         pBuffer,
  105.                      /* [IN]  */ VXIulong         nBuflen,
  106.                      /* [OUT] */ VXIulong*        pnRead,
  107.                      /* [IN]  */ VXIinetStream*   pStream      );
  108.   VXIinetResult write(/* [OUT] */ const VXIbyte*   pBuffer,
  109.                       /* [IN]  */ VXIulong         nBuflen,
  110.                       /* [OUT] */ VXIulong*        pnWritten,
  111.                       /* [IN]  */ VXIinetStream*   pStream      );
  112.   VXIinetResult setCookieJar( /* [IN]  */ const VXIVector*    pJar );
  113.   VXIinetResult getCookieJar( /* [OUT] */ VXIVector**      ppJar,
  114.                               /* [OUT] */ VXIbool*         pfChanged    );
  115.   VXIinetResult getAbsoluteName(/* [IN]  */ const VXIchar *moduleName,
  116.                                 /* [IN]  */ const VXIchar *name,
  117.                                 /* [IN]  */ const VXIMap  *properties,
  118.                                 /* [OUT] */ VXIString     **absoluteName);  
  119.   SWIstream::Result writeString(SWIoutputStream* output, const char *data);
  120.   int writeData(SWIoutputStream* output, const void *data, int dataSize);
  121.   SWIstream::Result writeInt(SWIoutputStream* output, int value);
  122.   void writeDebugString(const char *data);
  123.   int readData(SWIinputStream* input, void *buffer, int bufferSize);
  124.   int readChar(SWIinputStream* input);
  125.   SWIstream::Result readLine(SWIinputStream* input, SWIdataOutputStream* line);
  126.   VXIcacheInterface *getCache()
  127.   {
  128.     return _pVXICache;
  129.   }
  130.   static const char *getUserAgent();
  131.   static const VXIchar *getDefaultMimeType();
  132.   static SBinetProxyMatcher *getProxyMatcher(const char *domain, const char *path);
  133.  private:
  134.   static VXIint32 GetVersion(void);
  135.   static const VXIchar* GetImplementationName(void);
  136.   static VXIinetResult staticPrefetch(/* [IN]  */ VXIinetInterface*      pThis,
  137.                                       /* [IN]  */ const VXIchar*   pszModuleName,
  138.                                       /* [IN]  */ const VXIchar*   pszName,
  139.                                       /* [IN]  */ VXIinetOpenMode  eMode,
  140.                                       /* [IN]  */ VXIint32         nFlags,
  141.                                       /* [IN]  */ const VXIMap*    pProperties  );
  142.   static VXIinetResult staticOpen(/* [IN]  */ VXIinetInterface*      pThis,
  143.                                   /* [IN]  */ const VXIchar*   pszModuleName,
  144.                                   /* [IN]  */ const  VXIchar*  pszName,
  145.                                   /* [IN]  */ VXIinetOpenMode  eMode,
  146.                                   /* [IN]  */ VXIint32         nFlags,
  147.                                   /* [IN]  */ const VXIMap*    pProperties,
  148.                                   /* [OUT] */ VXIMap*          pmapStreamInfo,
  149.                                   /* [OUT] */ VXIinetStream**  ppStream     );
  150.   static VXIinetResult staticClose(/* [IN]  */ VXIinetInterface*      pThis,
  151.                                    /* [IN]  */ VXIinetStream**  ppStream     );
  152.   static VXIinetResult staticRead(/* [IN]  */ VXIinetInterface*      pThis,
  153.                                   /* [OUT] */ VXIbyte*         pBuffer,
  154.                                   /* [IN]  */ VXIulong         nBuflen,
  155.                                   /* [OUT] */ VXIulong*        pnRead,
  156.                                   /* [IN]  */ VXIinetStream*   pStream      );
  157.   static VXIinetResult staticWrite(/* [IN]  */ VXIinetInterface*      pThis,
  158.                                    /* [IN]  */ const VXIbyte*   pBuffer,
  159.                                    /* [IN]  */ VXIulong         nBuflen,
  160.                                    /* [OUT] */ VXIulong*        pnWritten,
  161.                                    /* [IN]  */ VXIinetStream*   pStream      );
  162.   static VXIinetResult staticSetCookieJar(/* [IN] */ VXIinetInterface* pThis,
  163.                                           /* [IN] */ const VXIVector* pJar );
  164.   static VXIinetResult staticGetCookieJar(/* [IN]  */ VXIinetInterface* pThis,
  165.                                           /* [OUT] */ VXIVector** ppJar,
  166.                                           /* [OUT] */ VXIbool* pfChanged );
  167.   static VXIinetResult staticGetAbsoluteName
  168.   (
  169.     /* [IN]  */ VXIinetInterface* pThis,
  170.     /* [IN]  */ const VXIchar *moduleName,
  171.     /* [IN]  */ const VXIchar *name,
  172.     /* [IN]  */ const VXIMap  *properties,
  173.     /* [OUT] */ VXIString     **absoluteName);  
  174.   VXIinetResult createStream(SBinetURL *url,
  175.                              const VXIMap *properties,
  176.                              VXIinetStream* &stream);
  177.   VXIinetStream* createHttpStream(SBinetURL *url, const VXIMap *properties);
  178.   VXIlogResult echoStreamWrite(const void *buffer, size_t buflen);
  179.   //void eraseCookie(CookieList::iterator &vi);
  180.  private:
  181.   SWIList _cookieList;
  182.   static SWIList _proxyMatcherList;
  183.   bool _jarChanged; // For GetCookieJar()
  184.   bool _cookiesEnabled; // Enable or diable cookie usage
  185.   VXIlogInterface *_pVXILog;
  186.   VXIcacheInterface *_pVXICache;
  187.   VXIlogStream *_echoStream;
  188.   SWIHashMap _connectionMap;
  189.   int _connectionCount;
  190.  private:
  191.   static double _freshnessFraction;
  192.   static time_t _freshnessLifetime;
  193.   static time_t _maxLifetime;
  194.   static VXIint32 _pageLoadTimeout;
  195.   static VXIint32 _postContinueTimeout;
  196.   static VXItrdMutex *_extensionRulesMutex;
  197.   static VXIMap *_extensionRules;
  198.   static SBinetNString *_userAgent;
  199.   static bool _usePersistentConnections;
  200.   static SBinetString *_defaultMimeType;
  201.   
  202.  private:  
  203.   static VXItrdMutex *_globalMD5Mutex;
  204.   static VXItrdMutex *_globalMapMutex; 
  205.     
  206.  public:
  207.   //static VXItrdMutexRef* acquireEntryLock(const SBinetMD5 & md5k);
  208.   static VXItrdMutexRef* acquireEntryLock(const VXIchar* absurl, SWIutilLogger *logger);
  209.   static void releaseEntryLock(VXItrdMutexRef* e_lock, SWIutilLogger *logger);
  210.   
  211.   static bool setCacheExistence(const SBinetMD5 & md5k, 
  212.                                 SBinetHttpCacheStream* p, bool done);
  213.   static bool getCacheExistence(const SBinetMD5 & md5k);    
  214. };
  215. #endif