michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this file, michael@0: * You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: michael@0: // Original authors: jib@mozilla.com, ekr@rtfm.com michael@0: michael@0: // Some of this code is cut-and-pasted from nICEr. Copyright is: michael@0: michael@0: /* michael@0: Copyright (c) 2007, Adobe Systems, Incorporated michael@0: All rights reserved. michael@0: michael@0: Redistribution and use in source and binary forms, with or without michael@0: modification, are permitted provided that the following conditions are michael@0: met: michael@0: michael@0: * Redistributions of source code must retain the above copyright michael@0: notice, this list of conditions and the following disclaimer. michael@0: michael@0: * Redistributions in binary form must reproduce the above copyright michael@0: notice, this list of conditions and the following disclaimer in the michael@0: documentation and/or other materials provided with the distribution. michael@0: michael@0: * Neither the name of Adobe Systems, Network Resonance nor the names of its michael@0: contributors may be used to endorse or promote products derived from michael@0: this software without specific prior written permission. michael@0: michael@0: THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS michael@0: "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT michael@0: LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR michael@0: A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT michael@0: OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, michael@0: SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT michael@0: LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, michael@0: DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY michael@0: THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT michael@0: (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE michael@0: OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. michael@0: */ michael@0: michael@0: #ifndef nriceresolver_h__ michael@0: #define nriceresolver_h__ michael@0: michael@0: #include michael@0: #include michael@0: #include "nspr.h" michael@0: #include "prnetdb.h" michael@0: #include "nsIDNSService.h" michael@0: #include "nsIDNSListener.h" michael@0: #include "nsICancelable.h" michael@0: michael@0: typedef struct nr_resolver_ nr_resolver; michael@0: typedef struct nr_resolver_vtbl_ nr_resolver_vtbl; michael@0: typedef struct nr_transport_addr_ nr_transport_addr; michael@0: typedef struct nr_resolver_resource_ nr_resolver_resource; michael@0: michael@0: namespace mozilla { michael@0: michael@0: class NrIceResolver michael@0: { michael@0: public: michael@0: NrIceResolver(); michael@0: ~NrIceResolver(); michael@0: michael@0: nsresult Init(); michael@0: nr_resolver *AllocateResolver(); michael@0: void DestroyResolver(); michael@0: NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceResolver) michael@0: michael@0: private: michael@0: // Implementations of vtbl functions michael@0: static int destroy(void **objp); michael@0: static int resolve(void *obj, nr_resolver_resource *resource, michael@0: int (*cb)(void *cb_arg, nr_transport_addr *addr), michael@0: void *cb_arg, void **handle); michael@0: static void resolve_cb(NR_SOCKET s, int how, void *cb_arg); michael@0: static int cancel(void *obj, void *handle); michael@0: michael@0: int resolve(nr_resolver_resource *resource, michael@0: int (*cb)(void *cb_arg, nr_transport_addr *addr), michael@0: void *cb_arg, void **handle); michael@0: michael@0: class PendingResolution : public nsIDNSListener michael@0: { michael@0: public: michael@0: PendingResolution(nsIEventTarget *thread, michael@0: uint16_t port, michael@0: int transport, michael@0: int (*cb)(void *cb_arg, nr_transport_addr *addr), michael@0: void *cb_arg) : michael@0: thread_(thread), michael@0: port_(port), michael@0: transport_(transport), michael@0: cb_(cb), cb_arg_(cb_arg), michael@0: canceled_ (false) {} michael@0: virtual ~PendingResolution(){}; michael@0: NS_IMETHOD OnLookupComplete(nsICancelable *request, nsIDNSRecord *record, michael@0: nsresult status); michael@0: int cancel(); michael@0: nsCOMPtr request_; michael@0: NS_DECL_THREADSAFE_ISUPPORTS michael@0: michael@0: private: michael@0: nsCOMPtr thread_; michael@0: uint16_t port_; michael@0: int transport_; michael@0: int (*cb_)(void *cb_arg, nr_transport_addr *addr); michael@0: void *cb_arg_; michael@0: bool canceled_; michael@0: }; michael@0: michael@0: nr_resolver_vtbl* vtbl_; michael@0: nsCOMPtr sts_thread_; michael@0: nsCOMPtr dns_; michael@0: #ifdef DEBUG michael@0: int allocated_resolvers_; michael@0: #endif michael@0: }; michael@0: michael@0: } // End of namespace mozilla michael@0: #endif