1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/media/mtransport/nriceresolver.h Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,124 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ 1.5 +/* vim: set ts=2 et sw=2 tw=80: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this file, 1.8 + * You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 + 1.11 +// Original authors: jib@mozilla.com, ekr@rtfm.com 1.12 + 1.13 +// Some of this code is cut-and-pasted from nICEr. Copyright is: 1.14 + 1.15 +/* 1.16 +Copyright (c) 2007, Adobe Systems, Incorporated 1.17 +All rights reserved. 1.18 + 1.19 +Redistribution and use in source and binary forms, with or without 1.20 +modification, are permitted provided that the following conditions are 1.21 +met: 1.22 + 1.23 +* Redistributions of source code must retain the above copyright 1.24 + notice, this list of conditions and the following disclaimer. 1.25 + 1.26 +* Redistributions in binary form must reproduce the above copyright 1.27 + notice, this list of conditions and the following disclaimer in the 1.28 + documentation and/or other materials provided with the distribution. 1.29 + 1.30 +* Neither the name of Adobe Systems, Network Resonance nor the names of its 1.31 + contributors may be used to endorse or promote products derived from 1.32 + this software without specific prior written permission. 1.33 + 1.34 +THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.35 +"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.36 +LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.37 +A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1.38 +OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 1.39 +SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 1.40 +LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 1.41 +DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 1.42 +THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 1.43 +(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 1.44 +OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.45 +*/ 1.46 + 1.47 +#ifndef nriceresolver_h__ 1.48 +#define nriceresolver_h__ 1.49 + 1.50 +#include <map> 1.51 +#include <string> 1.52 +#include "nspr.h" 1.53 +#include "prnetdb.h" 1.54 +#include "nsIDNSService.h" 1.55 +#include "nsIDNSListener.h" 1.56 +#include "nsICancelable.h" 1.57 + 1.58 +typedef struct nr_resolver_ nr_resolver; 1.59 +typedef struct nr_resolver_vtbl_ nr_resolver_vtbl; 1.60 +typedef struct nr_transport_addr_ nr_transport_addr; 1.61 +typedef struct nr_resolver_resource_ nr_resolver_resource; 1.62 + 1.63 +namespace mozilla { 1.64 + 1.65 +class NrIceResolver 1.66 +{ 1.67 + public: 1.68 + NrIceResolver(); 1.69 + ~NrIceResolver(); 1.70 + 1.71 + nsresult Init(); 1.72 + nr_resolver *AllocateResolver(); 1.73 + void DestroyResolver(); 1.74 + NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceResolver) 1.75 + 1.76 + private: 1.77 + // Implementations of vtbl functions 1.78 + static int destroy(void **objp); 1.79 + static int resolve(void *obj, nr_resolver_resource *resource, 1.80 + int (*cb)(void *cb_arg, nr_transport_addr *addr), 1.81 + void *cb_arg, void **handle); 1.82 + static void resolve_cb(NR_SOCKET s, int how, void *cb_arg); 1.83 + static int cancel(void *obj, void *handle); 1.84 + 1.85 + int resolve(nr_resolver_resource *resource, 1.86 + int (*cb)(void *cb_arg, nr_transport_addr *addr), 1.87 + void *cb_arg, void **handle); 1.88 + 1.89 + class PendingResolution : public nsIDNSListener 1.90 + { 1.91 + public: 1.92 + PendingResolution(nsIEventTarget *thread, 1.93 + uint16_t port, 1.94 + int transport, 1.95 + int (*cb)(void *cb_arg, nr_transport_addr *addr), 1.96 + void *cb_arg) : 1.97 + thread_(thread), 1.98 + port_(port), 1.99 + transport_(transport), 1.100 + cb_(cb), cb_arg_(cb_arg), 1.101 + canceled_ (false) {} 1.102 + virtual ~PendingResolution(){}; 1.103 + NS_IMETHOD OnLookupComplete(nsICancelable *request, nsIDNSRecord *record, 1.104 + nsresult status); 1.105 + int cancel(); 1.106 + nsCOMPtr<nsICancelable> request_; 1.107 + NS_DECL_THREADSAFE_ISUPPORTS 1.108 + 1.109 + private: 1.110 + nsCOMPtr<nsIEventTarget> thread_; 1.111 + uint16_t port_; 1.112 + int transport_; 1.113 + int (*cb_)(void *cb_arg, nr_transport_addr *addr); 1.114 + void *cb_arg_; 1.115 + bool canceled_; 1.116 + }; 1.117 + 1.118 + nr_resolver_vtbl* vtbl_; 1.119 + nsCOMPtr<nsIEventTarget> sts_thread_; 1.120 + nsCOMPtr<nsIDNSService> dns_; 1.121 +#ifdef DEBUG 1.122 + int allocated_resolvers_; 1.123 +#endif 1.124 +}; 1.125 + 1.126 +} // End of namespace mozilla 1.127 +#endif