hxopwavenetapi.cpp
上传用户:dangjiwu
上传日期:2013-07-19
资源大小:42019k
文件大小:10k
源码类别:

Symbian

开发平台:

Visual C++

  1. /* ***** BEGIN LICENSE BLOCK *****
  2.  * Source last modified: $Id: hxopwavenetapi.cpp,v 1.2.32.1 2004/07/09 02:08:44 hubbe Exp $
  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,
  7.  * are subject to the current version of the RealNetworks Public
  8.  * Source License (the "RPSL") available at
  9.  * http://www.helixcommunity.org/content/rpsl unless you have licensed
  10.  * the file under the current version of the RealNetworks Community
  11.  * Source License (the "RCSL") available at
  12.  * http://www.helixcommunity.org/content/rcsl, in which case the RCSL
  13.  * will apply. You may also obtain the license terms directly from
  14.  * RealNetworks.  You may not use this file except in compliance with
  15.  * the RPSL or, if you have a valid RCSL with RealNetworks applicable
  16.  * to this file, the RCSL.  Please see the applicable RPSL or RCSL for
  17.  * the rights, obligations and limitations governing use of the
  18.  * contents of the file.
  19.  * 
  20.  * Alternatively, the contents of this file may be used under the
  21.  * terms of the GNU General Public License Version 2 or later (the
  22.  * "GPL") in which case the provisions of the GPL are applicable
  23.  * instead of those above. If you wish to allow use of your version of
  24.  * this file only under the terms of the GPL, and not to allow others
  25.  * to use your version of this file under the terms of either the RPSL
  26.  * or RCSL, indicate your decision by deleting the provisions above
  27.  * and replace them with the notice and other provisions required by
  28.  * the GPL. If you do not delete the provisions above, a recipient may
  29.  * use your version of this file under the terms of any one of the
  30.  * RPSL, the RCSL or the GPL.
  31.  * 
  32.  * This file is part of the Helix DNA Technology. RealNetworks is the
  33.  * developer of the Original Code and owns the copyrights in the
  34.  * portions it created.
  35.  * 
  36.  * This file, and the files included with this file, is distributed
  37.  * and made available on an 'AS IS' basis, WITHOUT WARRANTY OF ANY
  38.  * KIND, EITHER EXPRESS OR IMPLIED, AND REALNETWORKS HEREBY DISCLAIMS
  39.  * ALL SUCH WARRANTIES, INCLUDING WITHOUT LIMITATION, ANY WARRANTIES
  40.  * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, QUIET
  41.  * ENJOYMENT OR NON-INFRINGEMENT.
  42.  * 
  43.  * Technology Compatibility Kit Test Suite(s) Location:
  44.  *    http://www.helixcommunity.org/content/tck
  45.  * 
  46.  * Contributor(s):
  47.  * 
  48.  * ***** END LICENSE BLOCK ***** */
  49. #include "hxopwavenetapi.h"
  50. #include "hxopwaveresolv.h"
  51. #include "hxopwavetcpsock.h"
  52. #include "hxopwaveudpsock.h"
  53. #include "hxcloakedtcp.h"
  54. #include "hxccf.h"
  55. #include "debug.h"
  56. #define D_NETAPI 0x10000000
  57. HXNetworkServices::HXNetworkServices(IUnknown* pContext)
  58. : m_lRefCount(0)
  59. , m_pContext(0)
  60. {
  61.     
  62.     if (pContext)
  63.     {
  64.         m_pContext = pContext;
  65.         m_pContext->AddRef();
  66.     }
  67. }
  68. HXNetworkServices::~HXNetworkServices()
  69. {
  70.     HX_RELEASE(m_pContext);
  71. }
  72. /*
  73. *  IUnknown methods
  74. */
  75. STDMETHODIMP HXNetworkServices::QueryInterface(THIS_
  76.                                                REFIID riid,
  77.                                                void** ppvObj)
  78. {
  79.     
  80.     DPRINTF(D_NETAPI, ("HXNetworkServices::QueryInterface()n"));
  81.     
  82.     if (IsEqualIID(riid, IID_IHXNetworkServices))
  83.     {
  84.         
  85.         AddRef();
  86.         *ppvObj = (IHXNetworkServices*)this;
  87.         return HXR_OK;
  88.     }
  89.     else if (IsEqualIID(riid, IID_IHXCloakedNetworkServices))
  90.     {
  91.         
  92.         AddRef();
  93.         *ppvObj = (IHXCloakedNetworkServices*)this;
  94.         return HXR_OK;
  95.     }
  96.     else if (IsEqualIID(riid, IID_IUnknown))
  97.     {
  98.         AddRef();
  99.         *ppvObj = (IUnknown*)(IHXNetworkServices*)this;
  100.         return HXR_OK;
  101.     }
  102.     
  103.     *ppvObj = NULL;
  104.     return HXR_NOINTERFACE;
  105. }
  106. STDMETHODIMP_(ULONG32) HXNetworkServices::AddRef(THIS)
  107. {
  108.     
  109.     return InterlockedIncrement(&m_lRefCount);
  110.     
  111. }
  112. STDMETHODIMP_(ULONG32)HXNetworkServices::Release(THIS)
  113. {
  114.     
  115.     if (InterlockedDecrement(&m_lRefCount) > 0)
  116.         
  117.     {
  118.         
  119.         return m_lRefCount;
  120.         
  121.     }
  122.     
  123.     
  124.     
  125.     delete this;
  126.     
  127.     return 0;
  128.     
  129. }
  130. /*
  131.   * IHXNetworkServices methods
  132.   
  133. */
  134. /************************************************************************
  135. * Method:
  136. *     IHXNetworkServices::CreateTCPSocket
  137. * Purpose:
  138. *     Create a new TCP socket.
  139. */
  140. STDMETHODIMP HXNetworkServices::CreateTCPSocket(THIS_
  141.                                                 IHXTCPSocket**    /*OUT*/  ppTCPSocket)
  142. {
  143.     
  144.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateTCPSocket()n"));
  145.     
  146.     HX_RESULT res = HXR_FAILED;
  147.     
  148.     IHXCommonClassFactory* pCCF = 0;
  149.     
  150.     if (m_pContext &&
  151.         (m_pContext->QueryInterface(IID_IHXCommonClassFactory, 
  152.     (void**)&pCCF) == HXR_OK) && pCCF)
  153.     {
  154.         
  155.         IHXResolver* pResolver = 0;
  156.         res = CreateResolver(&pResolver);
  157.         
  158.         if (res == HXR_OK)
  159.         {
  160.             *ppTCPSocket = new HXOpwaveTCPSocket(pCCF, pResolver);
  161.             if (*ppTCPSocket)
  162.             {
  163.                 (*ppTCPSocket)->AddRef();
  164.                 res = HXR_OK;
  165.             }
  166.             else
  167.             {
  168.                 res = HXR_OUTOFMEMORY;
  169.             }
  170.         }
  171.         
  172.         HX_RELEASE(pResolver);
  173.     }
  174.     
  175.     HX_RELEASE(pCCF);
  176.     
  177.     return res;
  178.     
  179. }
  180. /************************************************************************
  181. * Method:
  182. *     IHXNetworkServices::CreateUDPSocket
  183. * Purpose:
  184. *     Create a new UDP socket.
  185. */
  186. STDMETHODIMP HXNetworkServices::CreateUDPSocket(THIS_
  187.                                                 IHXUDPSocket**    /*OUT*/  ppUDPSocket)
  188.                                                 
  189. {
  190.     
  191.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateUDPSocket()n"));
  192.     HX_RESULT res = HXR_FAILED;
  193.    
  194.     IHXCommonClassFactory* pCCF = 0;
  195.     
  196.     if (m_pContext &&
  197.         (m_pContext->QueryInterface(IID_IHXCommonClassFactory, 
  198.     (void**)&pCCF) == HXR_OK) && pCCF)
  199.     {
  200.         *ppUDPSocket = new HXOpwaveUDPSocket(pCCF);
  201.         if (*ppUDPSocket)
  202.         {
  203.             (*ppUDPSocket)->AddRef();
  204.             res = HXR_OK;
  205.         }
  206.         else
  207.         {
  208.             res = HXR_OUTOFMEMORY;
  209.         }
  210.     }
  211.     
  212.     HX_RELEASE(pCCF);
  213.     
  214.     return res;
  215.     
  216. }
  217. /************************************************************************
  218.   * Method:
  219.   
  220.     *     IHXNetworkServices::CreateListenSocket
  221.     
  222.       * Purpose:
  223.       
  224.         *     Create a new TCP socket that will listen for connections on a
  225.         
  226.           *     particular port.
  227.           
  228. */
  229. STDMETHODIMP HXNetworkServices::CreateListenSocket(THIS_
  230.                                                    
  231.                                                    IHXListenSocket** /*OUT*/ ppListenSocket)
  232.                                                    
  233. {
  234.     
  235.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateListenSocket()n"));
  236.     
  237.     
  238.     
  239.     return HXR_NOTIMPL;
  240.     
  241. }
  242. /************************************************************************
  243. * Method:
  244. *     IHXNetworkServices::CreateResolver
  245. * Purpose:
  246. *     Create a new resolver that can lookup host names
  247. */
  248. STDMETHODIMP HXNetworkServices::CreateResolver(THIS_
  249.                                                IHXResolver**    /*OUT*/     ppResolver)
  250. {
  251.     
  252.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateResolver()n"));
  253.     
  254.     HX_RESULT res = HXR_OUTOFMEMORY;
  255.     
  256.     *ppResolver = new HXOpwaveResolver();
  257.     if (*ppResolver)
  258.     {
  259.         (*ppResolver)->AddRef();
  260.         res = HXR_OK;
  261.     }
  262.     
  263.     return res;
  264.     
  265. }
  266. /*
  267. * IHXNetworkCloakedServices methods
  268. */
  269. /************************************************************************
  270. * Method:
  271. *     IHXCloakedNetworkServices::CreateClientCloakedSocket
  272. * Purpose:
  273. *     Create a new HTTP cloaked TCP socket for the client.
  274. */
  275. STDMETHODIMP HXNetworkServices::CreateClientCloakedSocket(THIS_
  276.                                                           IHXTCPSocket**    /*OUT*/     ppTCPSocket)
  277. {
  278.     
  279.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateClientCloakedSocket()n"));
  280.     
  281. #if defined(HELIX_FEATURE_HTTPCLOAK)
  282.     
  283.     HX_RESULT res = HXR_FAILED;
  284.     
  285.     
  286.     
  287.     if (m_pContext)
  288.         
  289.     {
  290.         
  291.         *ppTCPSocket = new HXClientCloakedTCPSocket(m_pContext);
  292.         
  293.         
  294.         
  295.         if (*ppTCPSocket)
  296.             
  297.         {
  298.             
  299.             (*ppTCPSocket)->AddRef();
  300.             
  301.             res = HXR_OK;
  302.             
  303.         }
  304.         
  305.         else
  306.             
  307.         {
  308.             
  309.             res = HXR_OUTOFMEMORY;
  310.             
  311.         }
  312.         
  313.     }
  314.     
  315.     
  316.     
  317.     return res;
  318.     
  319. #else
  320.     
  321.     return HXR_NOTIMPL;
  322.     
  323. #endif /* HELIX_FEATURE_HTTPCLOAK */
  324.     
  325. }
  326. /************************************************************************
  327.   * Method:
  328.   
  329.     *     IHXCloakedNetworkServices::CreateServerCloakedSocket
  330.     
  331.       * Purpose:
  332.       
  333.         *     Create a new HTTP cloaked TCP socket that will listen for 
  334.         
  335.           *      connections on a particular port.
  336.           
  337. */
  338. STDMETHODIMP HXNetworkServices::CreateServerCloakedSocket(THIS_
  339.                                                           
  340.                                                           IHXListenSocket**    /*OUT*/     ppListenSocket)
  341.                                                           
  342. {
  343.     
  344.     DPRINTF(D_NETAPI, ("HXNetworkServices::CreateServerCloakedSocket()n"));
  345.     
  346.     
  347.     
  348.     return HXR_NOTIMPL;
  349.     
  350. }
  351. void HXNetworkServices::Close()
  352. {
  353.     
  354.     DPRINTF(D_NETAPI, ("HXNetworkServices::Close()n"));
  355.     
  356.     
  357.     
  358.     HX_RELEASE(m_pContext);
  359.     
  360. }