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 author: 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 nriceresolverfake_h__ michael@0: #define nriceresolverfake_h__ michael@0: michael@0: #include michael@0: #include michael@0: michael@0: #include "nspr.h" michael@0: #include "prnetdb.h" michael@0: #include "mozilla/NullPtr.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 NrIceResolverFake { michael@0: public: michael@0: NrIceResolverFake(); michael@0: ~NrIceResolverFake(); michael@0: michael@0: void SetAddr(const std::string& hostname, const PRNetAddr& addr) { michael@0: addrs_[hostname] = addr; michael@0: } michael@0: michael@0: nr_resolver *AllocateResolver(); michael@0: michael@0: void DestroyResolver(); 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, michael@0: nr_resolver_resource *resource, michael@0: int (*cb)(void *cb_arg, michael@0: nr_transport_addr *addr), michael@0: void *cb_arg, michael@0: 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: // Get an address. michael@0: const PRNetAddr *Resolve(const std::string& hostname) { michael@0: if (!addrs_.count(hostname)) michael@0: return nullptr; michael@0: michael@0: return &addrs_[hostname]; michael@0: } michael@0: michael@0: michael@0: struct PendingResolution { michael@0: PendingResolution(NrIceResolverFake *resolver, michael@0: const std::string& hostname, 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: resolver_(resolver), michael@0: hostname_(hostname), michael@0: port_(port), michael@0: transport_(transport), michael@0: cb_(cb), cb_arg_(cb_arg) {} michael@0: michael@0: NrIceResolverFake *resolver_; michael@0: std::string hostname_; 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: void *timer_handle_; michael@0: }; michael@0: michael@0: nr_resolver_vtbl* vtbl_; michael@0: std::map addrs_; michael@0: uint32_t delay_ms_; michael@0: int allocated_resolvers_; michael@0: }; michael@0: michael@0: } // End of namespace mozilla michael@0: michael@0: #endif