hxopwavenetapi.cpp
上传用户:zhongxx05
上传日期:2007-06-06
资源大小:33641k
文件大小:9k
源码类别:

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. * Technology Compatibility Kit Test Suite(s) Location: 
  29. *    http://www.helixcommunity.org/content/tck 
  30. * Contributor(s): 
  31. *  
  32. * ***** END LICENSE BLOCK ***** */ 
  33. #include "hxopwavenetapi.h"
  34. #include "hxopwaveresolv.h"
  35. #include "hxopwavetcpsock.h"
  36. #include "hxopwaveudpsock.h"
  37. #include "hxcloakedtcp.h"
  38. #include "hxccf.h"
  39. #include "debug.h"
  40. #define D_NETAPI 0x10000000
  41. HXNetworkServices::HXNetworkServices(IUnknown* pContext)
  42. : m_lRefCount(0)
  43. , m_pContext(0)
  44. {
  45.     
  46.     if (pContext)
  47.     {
  48.         m_pContext = pContext;
  49.         m_pContext->AddRef();
  50.     }
  51. }
  52. HXNetworkServices::~HXNetworkServices()
  53. {
  54.     HX_RELEASE(m_pContext);
  55. }
  56. /*
  57. *  IUnknown methods
  58. */
  59. STDMETHODIMP HXNetworkServices::QueryInterface(THIS_
  60.                                                REFIID riid,
  61.                                                void** ppvObj)
  62. {
  63.     
  64.     DPRINTF(D_NETAPI, ("HXNetworkServices::QueryInterface()n"));
  65.     
  66.     if (IsEqualIID(riid, IID_IHXNetworkServices))
  67.     {
  68.         
  69.         AddRef();
  70.         *ppvObj = (IHXNetworkServices*)this;
  71.         return HXR_OK;
  72.     }
  73.     else if (IsEqualIID(riid, IID_IHXCloakedNetworkServices))
  74.     {
  75.         
  76.         AddRef();
  77.         *ppvObj = (IHXCloakedNetworkServices*)this;
  78.         return HXR_OK;
  79.     }
  80.     else if (IsEqualIID(riid, IID_IUnknown))
  81.     {
  82.         AddRef();
  83.         *ppvObj = (IUnknown*)(IHXNetworkServices*)this;
  84.         return HXR_OK;
  85.     }
  86.     
  87.     *ppvObj = NULL;
  88.     return HXR_NOINTERFACE;
  89. }
  90. STDMETHODIMP_(ULONG32) HXNetworkServices::AddRef(THIS)
  91. {
  92.     
  93.     return InterlockedIncrement(&m_lRefCount);
  94.     
  95. }
  96. STDMETHODIMP_(ULONG32)HXNetworkServices::Release(THIS)
  97. {
  98.     
  99.     if (InterlockedDecrement(&m_lRefCount) > 0)
  100.         
  101.     {
  102.         
  103.         return m_lRefCount;
  104.         
  105.     }
  106.     
  107.     
  108.     
  109.     delete this;
  110.     
  111.     return 0;
  112.     
  113. }
  114. /*
  115.   * IHXNetworkServices methods
  116.   
  117. */
  118. /************************************************************************
  119. * Method:
  120. *     IHXNetworkServices::CreateTCPSocket
  121. * Purpose:
  122. *     Create a new TCP socket.
  123. */
  124. STDMETHODIMP HXNetworkServices::CreateTCPSocket(THIS_
  125.                                                 IHXTCPSocket**    /*OUT*/  ppTCPSocket)
  126. {
  127.     
  128.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateTCPSocket()n"));
  129.     
  130.     HX_RESULT res = HXR_FAILED;
  131.     
  132.     IHXCommonClassFactory* pCCF = 0;
  133.     
  134.     if (m_pContext &&
  135.         (m_pContext->QueryInterface(IID_IHXCommonClassFactory, 
  136.     (void**)&pCCF) == HXR_OK) && pCCF)
  137.     {
  138.         
  139.         IHXResolver* pResolver = 0;
  140.         res = CreateResolver(&pResolver);
  141.         
  142.         if (res == HXR_OK)
  143.         {
  144.             *ppTCPSocket = new HXOpwaveTCPSocket(pCCF, pResolver);
  145.             if (*ppTCPSocket)
  146.             {
  147.                 (*ppTCPSocket)->AddRef();
  148.                 res = HXR_OK;
  149.             }
  150.             else
  151.             {
  152.                 res = HXR_OUTOFMEMORY;
  153.             }
  154.         }
  155.         
  156.         HX_RELEASE(pResolver);
  157.     }
  158.     
  159.     HX_RELEASE(pCCF);
  160.     
  161.     return res;
  162.     
  163. }
  164. /************************************************************************
  165. * Method:
  166. *     IHXNetworkServices::CreateUDPSocket
  167. * Purpose:
  168. *     Create a new UDP socket.
  169. */
  170. STDMETHODIMP HXNetworkServices::CreateUDPSocket(THIS_
  171.                                                 IHXUDPSocket**    /*OUT*/  ppUDPSocket)
  172.                                                 
  173. {
  174.     
  175.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateUDPSocket()n"));
  176.     HX_RESULT res = HXR_FAILED;
  177.    
  178.     IHXCommonClassFactory* pCCF = 0;
  179.     
  180.     if (m_pContext &&
  181.         (m_pContext->QueryInterface(IID_IHXCommonClassFactory, 
  182.     (void**)&pCCF) == HXR_OK) && pCCF)
  183.     {
  184.         *ppUDPSocket = new HXOpwaveUDPSocket(pCCF);
  185.         if (*ppUDPSocket)
  186.         {
  187.             (*ppUDPSocket)->AddRef();
  188.             res = HXR_OK;
  189.         }
  190.         else
  191.         {
  192.             res = HXR_OUTOFMEMORY;
  193.         }
  194.     }
  195.     
  196.     HX_RELEASE(pCCF);
  197.     
  198.     return res;
  199.     
  200. }
  201. /************************************************************************
  202.   * Method:
  203.   
  204.     *     IHXNetworkServices::CreateListenSocket
  205.     
  206.       * Purpose:
  207.       
  208.         *     Create a new TCP socket that will listen for connections on a
  209.         
  210.           *     particular port.
  211.           
  212. */
  213. STDMETHODIMP HXNetworkServices::CreateListenSocket(THIS_
  214.                                                    
  215.                                                    IHXListenSocket** /*OUT*/ ppListenSocket)
  216.                                                    
  217. {
  218.     
  219.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateListenSocket()n"));
  220.     
  221.     
  222.     
  223.     return HXR_NOTIMPL;
  224.     
  225. }
  226. /************************************************************************
  227. * Method:
  228. *     IHXNetworkServices::CreateResolver
  229. * Purpose:
  230. *     Create a new resolver that can lookup host names
  231. */
  232. STDMETHODIMP HXNetworkServices::CreateResolver(THIS_
  233.                                                IHXResolver**    /*OUT*/     ppResolver)
  234. {
  235.     
  236.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateResolver()n"));
  237.     
  238.     HX_RESULT res = HXR_OUTOFMEMORY;
  239.     
  240.     *ppResolver = new HXOpwaveResolver();
  241.     if (*ppResolver)
  242.     {
  243.         (*ppResolver)->AddRef();
  244.         res = HXR_OK;
  245.     }
  246.     
  247.     return res;
  248.     
  249. }
  250. /*
  251. * IHXNetworkCloakedServices methods
  252. */
  253. /************************************************************************
  254. * Method:
  255. *     IHXCloakedNetworkServices::CreateClientCloakedSocket
  256. * Purpose:
  257. *     Create a new HTTP cloaked TCP socket for the client.
  258. */
  259. STDMETHODIMP HXNetworkServices::CreateClientCloakedSocket(THIS_
  260.                                                           IHXTCPSocket**    /*OUT*/     ppTCPSocket)
  261. {
  262.     
  263.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateClientCloakedSocket()n"));
  264.     
  265. #if defined(HELIX_FEATURE_HTTPCLOAK)
  266.     
  267.     HX_RESULT res = HXR_FAILED;
  268.     
  269.     
  270.     
  271.     if (m_pContext)
  272.         
  273.     {
  274.         
  275.         *ppTCPSocket = new HXClientCloakedTCPSocket(m_pContext);
  276.         
  277.         
  278.         
  279.         if (*ppTCPSocket)
  280.             
  281.         {
  282.             
  283.             (*ppTCPSocket)->AddRef();
  284.             
  285.             res = HXR_OK;
  286.             
  287.         }
  288.         
  289.         else
  290.             
  291.         {
  292.             
  293.             res = HXR_OUTOFMEMORY;
  294.             
  295.         }
  296.         
  297.     }
  298.     
  299.     
  300.     
  301.     return res;
  302.     
  303. #else
  304.     
  305.     return HXR_NOTIMPL;
  306.     
  307. #endif /* HELIX_FEATURE_HTTPCLOAK */
  308.     
  309. }
  310. /************************************************************************
  311.   * Method:
  312.   
  313.     *     IHXCloakedNetworkServices::CreateServerCloakedSocket
  314.     
  315.       * Purpose:
  316.       
  317.         *     Create a new HTTP cloaked TCP socket that will listen for 
  318.         
  319.           *      connections on a particular port.
  320.           
  321. */
  322. STDMETHODIMP HXNetworkServices::CreateServerCloakedSocket(THIS_
  323.                                                           
  324.                                                           IHXListenSocket**    /*OUT*/     ppListenSocket)
  325.                                                           
  326. {
  327.     
  328.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateServerCloakedSocket()n"));
  329.     
  330.     
  331.     
  332.     return HXR_NOTIMPL;
  333.     
  334. }
  335. void HXNetworkServices::Close()
  336. {
  337.     
  338.     DPRINTF(D_NETAPI, ("HXNetworkServices::Close()n"));
  339.     
  340.     
  341.     
  342.     HX_RELEASE(m_pContext);
  343.     
  344. }