hxnetapi.h
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:14k
源码类别:

Symbian

开发平台:

C/C++

  1. /* ***** BEGIN LICENSE BLOCK ***** 
  2.  * Version: RCSL 1.0/RPSL 1.0 
  3.  *  
  4.  * Portions Copyright (c) 1995-2002 RealNetworks, Inc. All Rights Reserved. 
  5.  *      
  6.  * The contents of this file, and the files included with this file, are 
  7.  * subject to the current version of the RealNetworks Public Source License 
  8.  * Version 1.0 (the "RPSL") available at 
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed 
  10.  * the file under the RealNetworks Community Source License Version 1.0 
  11.  * (the "RCSL") available at http://www.helixcommunity.org/content/rcsl, 
  12.  * in which case the RCSL will apply. You may also obtain the license terms 
  13.  * directly from RealNetworks.  You may not use this file except in 
  14.  * compliance with the RPSL or, if you have a valid RCSL with RealNetworks 
  15.  * applicable to this file, the RCSL.  Please see the applicable RPSL or 
  16.  * RCSL for the rights, obligations and limitations governing use of the 
  17.  * contents of the file.  
  18.  *  
  19.  * This file is part of the Helix DNA Technology. RealNetworks is the 
  20.  * developer of the Original Code and owns the copyrights in the portions 
  21.  * it created. 
  22.  *  
  23.  * This file, and the files included with this file, is distributed and made 
  24.  * available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER 
  25.  * EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS ALL SUCH WARRANTIES, 
  26.  * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, FITNESS 
  27.  * FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. 
  28.  * 
  29.  * Technology Compatibility Kit Test Suite(s) Location: 
  30.  *    http://www.helixcommunity.org/content/tck 
  31.  * 
  32.  * Contributor(s): 
  33.  *  
  34.  * ***** END LICENSE BLOCK ***** */ 
  35. #ifndef _HXNETAPI_H_
  36. #define _HXNETAPI_H_
  37. #if defined(_SYMBIAN)
  38. #include "platform/symbian/hxsymbiannetapi.h"
  39. #elif defined(_OPENWAVE)
  40. #include "platform/openwave/hxopwavenetapi.h"
  41. #else
  42. #include "conn.h"
  43. #include "hxengin.h"
  44. #include "hxslist.h"
  45. #include "hxpnets.h"
  46. #include "preftran.h"
  47. // necessary for authentication 
  48. #include "hxauthn.h"
  49. #include "hxathsp.h"
  50. #include "hxcomsp.h"
  51. #include "hxplnsp.h"
  52. #include "hxcloakedtcp.h"
  53. #include "hxsockcallback.h"
  54. #include "hxnetutil.h"
  55. struct IHXCloakedNetworkServices;
  56. struct IHXNetworkServices;
  57. struct IHXListenSocket;
  58. struct IHXTCPSocket;
  59. struct IHXUDPSocket;
  60. struct IHXInterruptState;
  61. struct IHXInterruptSafe;
  62. // for sockets
  63. #if defined(_WIN32) || defined(_WINDOWS)
  64. #include "platform/win/win_net.h"
  65. #elif defined(_OPENWAVE)
  66. #include "socketdefs.h"
  67. #elif defined(__TCS__)
  68. #include "sockio.h"
  69. #else
  70. #include "hlxclib/sys/socket.h"
  71. #endif
  72. class CByteGrowingQueue;
  73. class HXAsyncNetCallback;
  74. class HXMutex;
  75. class HXEvent;
  76. #ifdef _MACINTOSH
  77. struct IhxQueueElement 
  78. {
  79. IhxQueueElement  *mNextElementInQueue; // link must be first member
  80. IUnknown *mObject;
  81. };
  82. class InterruptSafeMacQueue 
  83. {
  84. protected:
  85. QHdr  mQueueHeader;
  86. Boolean mDestructing;
  87. public:
  88. InterruptSafeMacQueue(void);
  89. ~InterruptSafeMacQueue(void); // decrements the ref on the irma nodes (via release)
  90. IUnknown *  RemoveHead(void);
  91. HX_RESULT  AddTail(IUnknown* pObject); // increments the ref
  92. HX_RESULT TransferToSimpleList(CHXSimpleList &simpleList); // leaves the ref incremented
  93. };
  94. #endif // _MACINTOSH
  95. class HXNetworkServices : public IHXNetworkServices,
  96.    public IHXCloakedNetworkServices,
  97.    public IHXNetworkInterfaceEnumerator
  98. {
  99. public:
  100. HXNetworkServices(IUnknown* pContext);
  101. ~HXNetworkServices();
  102.     /* IUnknown interface */
  103.     STDMETHOD(QueryInterface)     (THIS_ 
  104.     REFIID riid, void** ppvObj);
  105.     STDMETHOD_(ULONG32,AddRef)     (THIS);
  106.     STDMETHOD_(ULONG32,Release)     (THIS);
  107.     /* IHXNetworkServices interface */
  108.     STDMETHOD(CreateTCPSocket)      (THIS_ 
  109.     IHXTCPSocket** ppTCPSocket);
  110.     STDMETHOD(CreateUDPSocket) (THIS_
  111. IHXUDPSocket**    /*OUT*/     ppUDPSocket);
  112.     STDMETHOD(CreateListenSocket)   (THIS_ 
  113.     IHXListenSocket** ppListenSocket);
  114.     STDMETHOD(CreateResolver)     (THIS_
  115.          IHXResolver** ppResolver);
  116.     /* IHXCloakedNetworkServices interface */
  117.     STDMETHOD(CreateClientCloakedSocket) (THIS_
  118. IHXTCPSocket**    /*OUT*/     ppTCPSocket);
  119.     STDMETHOD(CreateServerCloakedSocket) (THIS_
  120. IHXListenSocket**    /*OUT*/     ppListenSocket);
  121.     /* IHXNetworkInterfaceEnumerator methods */
  122.     STDMETHOD(EnumerateInterfaces) (THIS_
  123. REF(UINT32*) pulInterfaces, REF(UINT32) ulNumInterfaces);
  124.     void Close();
  125.     void UseDrivers();
  126. private:
  127.     LONG32                      m_lRefCount;
  128.     IUnknown* m_pContext;
  129.     BOOL m_bNeedToCleanupDrivers;
  130. #if !defined(HELIX_CONFIG_NOSTATICS)
  131.     static UINT16 z_muNumDriverInstance;
  132. #else
  133.     static const UINT16 z_muNumDriverInstance;
  134. #endif
  135. };
  136. class HXResolver: public IHXResolver
  137. {
  138. public:
  139.      HXResolver(HXNetworkServices* pNetworkServices);
  140.      ~HXResolver();
  141.                                 HXResolver(HXNetworkServices* pNetworkServices,
  142.                                             IUnknown*           pContext );
  143.                                 
  144.     STDMETHOD(QueryInterface)   (THIS_ REFIID riid, void** ppvObj);
  145.     STDMETHOD_(ULONG32,AddRef)  (THIS);
  146.     STDMETHOD_(ULONG32,Release) (THIS);
  147.     STDMETHOD(Init)             (THIS_ IHXResolverResponse* pResp);
  148.     STDMETHOD(GetHostByName)    (THIS_ const char* pHostName);
  149. private:
  150.     class HXResolverCallback: public HXAsyncNetCallback
  151.     {
  152.     public:
  153. HX_RESULT Func(NotificationType Type, BOOL bSuccess = TRUE, conn* pConn = NULL);
  154. HXResolver* m_pContext;
  155.     };
  156.     friend class HXResolverCallback;
  157.     void    DNSDone(BOOL bSuccess);
  158.     HXResolverCallback* m_pCallback;
  159.     LONG32                      m_lRefCount;
  160.     IHXResolverResponse*       m_pResp;
  161.     BOOL m_bResolverPending;
  162.     conn* m_pData;
  163.     HXNetworkServices* m_pNetworkServices;
  164.     IUnknown*                   m_pContext;
  165. };
  166. class HXUDPSocket : public IHXUDPSocket,
  167.      public IHXSetSocketOption,
  168.      public SocketCallbackInterface,
  169.      public IHXUDPMulticastInit,
  170.      public IHXSetPrivateSocketOption
  171. {
  172. public:
  173. HXUDPSocket(IUnknown* pContext, HXNetworkServices* pNetworkServices);
  174. ~HXUDPSocket();
  175.     /* IUnknown interface */
  176.     STDMETHOD(QueryInterface) (THIS_ 
  177. REFIID riid, void** ppvObj);
  178.     STDMETHOD_(ULONG32,AddRef) (THIS);
  179.     STDMETHOD_(ULONG32,Release) (THIS);
  180.    /* SocketCallbackInterface interface */
  181.   enum {
  182. UDP_READ_COMMAND,
  183. UDP_WRITE_COMMAND,
  184. UDP_BIND_COMMAND
  185. };
  186. STDMETHODIMP HandleCallback(INT32 theCommand, HX_RESULT theError);
  187.     /* IHXUDPSocket interface */
  188.     STDMETHOD(Init) (THIS_
  189. ULONG32 ulAddr,
  190. UINT16 nPort,
  191. IHXUDPResponse* pUDPResponse);
  192.     STDMETHOD(Bind) (THIS_
  193. UINT32 ulLocalAddr,
  194. UINT16  nPort);
  195.     STDMETHOD(Read) (THIS_
  196. UINT16 Size);
  197.     STDMETHOD(Write) (THIS_
  198. IHXBuffer* pBuffer);
  199.     STDMETHOD(WriteTo) (THIS_
  200.      ULONG32 ulAddr,
  201. UINT16 nPort,
  202. IHXBuffer* pBuffer);
  203.     STDMETHOD(GetLocalPort) (THIS_
  204.      UINT16& nPort);
  205.     STDMETHOD(JoinMulticastGroup) (THIS_
  206.      ULONG32     ulMulticastAddr,
  207.      ULONG32     ulInterfaceAddr);
  208.     STDMETHOD(LeaveMulticastGroup) (THIS_
  209.      ULONG32     ulMulticastAddr,
  210.      ULONG32     ulInterfaceAddr);
  211.     /*
  212.      * IHXUDPMulticastInit methods
  213.      */
  214.  
  215.     STDMETHOD(InitMulticast)            (THIS_
  216.                                          UINT8       ulTTL);
  217.     /*
  218.      * IHXListenSocket methods
  219.      */
  220.     STDMETHOD(SetOption) (THIS_ 
  221.  HX_SOCKET_OPTION option,
  222.  UINT32 ulValue);
  223.     /*
  224.      * IHXSetPrivateSocketOption methods
  225.      */
  226.     STDMETHOD(SetOption) (THIS_ 
  227.  HX_PRIVATE_SOCKET_OPTION option,
  228.  UINT32 ulValue);    
  229.     class UDPSocketCallback: public HXAsyncNetCallback
  230.     {
  231.     public:
  232. HX_RESULT Func(NotificationType Type, BOOL bSuccess = TRUE, conn* pConn = NULL);
  233. HXUDPSocket* m_pContext;
  234.     };
  235.     friend class UDPSocketCallback;
  236.   private:
  237.     IUnknown*                   m_pContext;
  238.     HX_RESULT DoRead();
  239.     HX_RESULT DoWrite();
  240.     BOOL IsSafe();
  241.     LONG32                      m_lRefCount;
  242.     IHXUDPResponse* m_pUDPResponse;
  243.     conn* m_pData;
  244.     struct sockaddr_in m_sockAddr;
  245.     HX_BITFIELD m_bReadPending : 1;
  246.     HX_BITFIELD m_bInRead : 1;
  247.     HX_BITFIELD m_bInDoRead : 1;
  248.     HX_BITFIELD m_bInWrite : 1;
  249.     UINT32 m_nRequired;
  250.     CHXSimpleList m_ReadBuffers;
  251.     CHXSimpleList m_WriteBuffers;
  252.     IHXScheduler* m_pScheduler;
  253.     UDPSocketCallback* m_pCallback;
  254.     ScheduledSocketCallback* m_pSchedulerReadCallback;
  255.     ScheduledSocketCallback* m_pSchedulerWriteCallback;
  256.     ScheduledSocketCallback* m_pNonInterruptReadCallback;
  257.     UINT16 m_nDestPort;
  258.     HX_BITFIELD m_bInitComplete : 1;
  259.     IHXInterruptState* m_pInterruptState;
  260.     IHXInterruptSafe* m_pResponseInterruptSafe;
  261.     HXMutex* m_pMutex;
  262.     HX_BITFIELD m_bInDestructor : 1;
  263.     HXNetworkServices* m_pNetworkServices;
  264. #ifdef _MACINTOSH
  265. InterruptSafeMacQueue* m_pInterruptSafeMacWriteQueue; // only instantiated on the mac
  266. #endif
  267.     BOOL m_bReuseAddr;
  268.     BOOL m_bReusePort;    
  269. };
  270. class HXTCPSocket : public IHXTCPSocket,
  271.      public IHXSetSocketOption,
  272.      public SocketCallbackInterface,
  273.      public IHXTCPSecureSocket
  274. {
  275. public:
  276. HXTCPSocket(IUnknown* pContext, HXNetworkServices* pNetworkServices);
  277. ~HXTCPSocket();
  278.     
  279.     /* IUnknown interface */
  280.     STDMETHOD(QueryInterface)   (THIS_ 
  281. REFIID riid, void** ppvObj);
  282.     STDMETHOD_(ULONG32,AddRef)  (THIS);
  283.     STDMETHOD_(ULONG32,Release) (THIS);
  284.    /* SocketCallbackInterface interface */
  285.   enum {
  286. TCP_READ_COMMAND,
  287. TCP_WRITE_COMMAND,
  288. TCP_BIND_COMMAND,
  289. TCP_READ_DONE_COMMAND,
  290. TCP_CONNECT_DONE_COMMAND
  291. };
  292. STDMETHODIMP HandleCallback(INT32 theCommand, HX_RESULT theError);
  293.     /*
  294.      *  IHXTCPSocket methods
  295.      */
  296.     STDMETHOD(Init) (THIS_
  297. IHXTCPResponse*    /*IN*/  pTCPResponse);
  298.     STDMETHOD(SetResponse) (THIS_
  299. IHXTCPResponse*    /*IN*/  pTCPResponse);
  300.     STDMETHOD(Bind) (THIS_
  301. UINT32     ulLocalAddr,
  302. UINT16      nPort);
  303.     STDMETHOD(Connect) (THIS_
  304. const char*     pDestination,
  305. UINT16     nPort);
  306.     STDMETHOD(Read) (THIS_
  307. UINT16     uSize);
  308.     STDMETHOD(Write) (THIS_
  309. IHXBuffer*     pBuffer);
  310.     STDMETHOD(WantWrite) (THIS);
  311.     STDMETHOD(GetLocalAddress) (THIS_
  312. UINT32&     lAddress);
  313.     STDMETHOD(GetForeignAddress)(THIS_
  314. UINT32&     lAddress);
  315.     STDMETHOD(GetLocalPort) (THIS_
  316.      UINT16&     nPort);
  317.     STDMETHOD(GetForeignPort) (THIS_
  318.      UINT16&     nPort);
  319.     /*
  320.      * IHXTCPSecureSocket
  321.      */
  322.     
  323.     STDMETHOD(SetSecure) (THIS_
  324.      BOOL bSecure);
  325.     
  326.     /*
  327.      * IHXListenSocket methods
  328.      */
  329.     STDMETHOD(SetOption) (THIS_ 
  330.  HX_SOCKET_OPTION option,
  331.  UINT32 ulValue);
  332.     class TCPSocketCallback: public HXAsyncNetCallback
  333.     {
  334.     public:
  335. HX_RESULT Func(NotificationType Type, BOOL bSuccess = TRUE, conn* pConn = NULL);
  336. HXTCPSocket* m_pContext;
  337.     };
  338.    friend class TCPSocketCallback;
  339.     STDMETHOD(AcceptConnection) (THIS_ conn* pNewCon);
  340. private:
  341.     HX_RESULT DoRead();
  342.     HX_RESULT DoWrite();
  343.     void CloseDone();
  344.     void DNSDone(BOOL bSuccess);
  345.     void TransferBuffers();
  346.     void ConnectDone(BOOL bResult);
  347.     BOOL IsSafe();
  348.     LONG32                      m_lRefCount;
  349.     IHXTCPResponse* m_pTCPResponse;
  350.     conn* m_pCtrl;
  351.     UINT32 m_lForeignAddress;
  352.     UINT16 m_nForeignPort : 16;
  353.     UINT16 m_nRequired : 16;
  354.     HX_BITFIELD m_bReadPending : 1;
  355.     HX_BITFIELD m_bConnected : 1;
  356.     HX_BITFIELD m_bWantWritePending : 1;
  357.     HX_BITFIELD m_bInitComplete : 1;
  358.     HX_BITFIELD m_bInDestructor : 1;
  359.     HX_BITFIELD m_bInRead : 1;
  360.     HX_BITFIELD m_bInDoRead : 1;
  361.     HX_BITFIELD m_bInWrite : 1;
  362.     HX_BITFIELD m_bWriteFlushPending : 1;
  363.     CByteGrowingQueue* mSendTCP;
  364.     CByteGrowingQueue* mReceiveTCP;
  365.     CHXSimpleList m_PendingWriteBuffers;
  366.     char* m_pBuffer;
  367.     TCPSocketCallback* m_pCallback;
  368.     UINT16 m_nLocalPort;
  369.     IHXScheduler* m_pScheduler;
  370.     ScheduledSocketCallback* m_pSchedulerReadCallback;
  371.     ScheduledSocketCallback* m_pSchedulerWriteCallback;
  372.     ScheduledSocketCallback* m_pNonInterruptReadCallback;
  373. #ifdef _MACINTOSH
  374. ScheduledSocketCallback*  m_pMacCommandCallback;
  375. InterruptSafeMacQueue* m_pInterruptSafeMacWriteQueue; // only instantiated on the mac
  376. #endif
  377.     IHXInterruptState* m_pInterruptState;
  378.     IHXInterruptSafe* m_pResponseInterruptSafe;
  379.     HXMutex* m_pMutex;
  380.     HXNetworkServices* m_pNetworkServices;
  381.     IHXPreferences* m_pPreferences;
  382.     BOOL m_bReuseAddr;
  383.     BOOL m_bReusePort;
  384.     IUnknown*                   m_pContext;
  385.     BOOL m_bSecureSocket;
  386. };
  387. class HXListenSocket : public IHXListenSocket,
  388. public IHXSetSocketOption
  389. {
  390. public:
  391. HXListenSocket(IUnknown* pContext, HXNetworkServices* pNetworkServices);
  392. ~HXListenSocket();
  393.     /* IUnknown interface */
  394.     STDMETHOD(QueryInterface)   (THIS_ 
  395. REFIID riid, void** ppvObj);
  396.     STDMETHOD_(ULONG32,AddRef)  (THIS);
  397.     STDMETHOD_(ULONG32,Release) (THIS);
  398.     /*
  399.      *  IHXListenSocket methods
  400.      */
  401.     STDMETHOD(Init) (THIS_
  402. UINT32 ulLocalAddr,
  403. UINT16 port,
  404. IHXListenResponse*    /*IN*/ pListenResponse);
  405.     /*
  406.      * IHXSetSocketOption methods
  407.      */
  408.     STDMETHOD(SetOption) (THIS_ 
  409.  HX_SOCKET_OPTION option,
  410.  UINT32 ulValue);
  411.     class ListenSocketCallback: public HXAsyncNetCallback
  412.     {
  413.     public:
  414. HX_RESULT Func(NotificationType Type, BOOL bSuccess = TRUE, conn* pConn = NULL);
  415. HXListenSocket* m_pContext;
  416.     };
  417.     friend class ListenSocketCallback;
  418. private:
  419.     LONG32                      m_lRefCount;
  420.     IHXListenResponse* m_pListenResponse;
  421.     HXNetworkServices* m_pNetworkServices;
  422.     IUnknown* m_pContext;
  423.     conn* m_pListenConn;
  424.     ListenSocketCallback* m_pCallback;
  425.     BOOL m_bReuseAddr;
  426.     BOOL m_bReusePort;
  427. };
  428. #endif /* defined(_SYMBIAN) */
  429. #endif /*_HXNETAPI_H_*/