/src/mozilla-central/media/mtransport/nriceresolver.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* vim: set ts=2 et sw=2 tw=80: */ |
3 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
4 | | * License, v. 2.0. If a copy of the MPL was not distributed with this file, |
5 | | * You can obtain one at http://mozilla.org/MPL/2.0/. */ |
6 | | |
7 | | |
8 | | // Original authors: jib@mozilla.com, ekr@rtfm.com |
9 | | |
10 | | // Some of this code is cut-and-pasted from nICEr. Copyright is: |
11 | | |
12 | | /* |
13 | | Copyright (c) 2007, Adobe Systems, Incorporated |
14 | | All rights reserved. |
15 | | |
16 | | Redistribution and use in source and binary forms, with or without |
17 | | modification, are permitted provided that the following conditions are |
18 | | met: |
19 | | |
20 | | * Redistributions of source code must retain the above copyright |
21 | | notice, this list of conditions and the following disclaimer. |
22 | | |
23 | | * Redistributions in binary form must reproduce the above copyright |
24 | | notice, this list of conditions and the following disclaimer in the |
25 | | documentation and/or other materials provided with the distribution. |
26 | | |
27 | | * Neither the name of Adobe Systems, Network Resonance nor the names of its |
28 | | contributors may be used to endorse or promote products derived from |
29 | | this software without specific prior written permission. |
30 | | |
31 | | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
32 | | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
33 | | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
34 | | A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
35 | | OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
36 | | SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
37 | | LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
38 | | DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
39 | | THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
40 | | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
41 | | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
42 | | */ |
43 | | |
44 | | #ifndef nriceresolver_h__ |
45 | | #define nriceresolver_h__ |
46 | | |
47 | | #include <map> |
48 | | #include <string> |
49 | | #include "nspr.h" |
50 | | #include "prnetdb.h" |
51 | | #include "nsIDNSService.h" |
52 | | #include "nsIDNSListener.h" |
53 | | #include "nsICancelable.h" |
54 | | #include "nricectx.h" |
55 | | |
56 | | typedef struct nr_resolver_ nr_resolver; |
57 | | typedef struct nr_resolver_vtbl_ nr_resolver_vtbl; |
58 | | typedef struct nr_transport_addr_ nr_transport_addr; |
59 | | typedef struct nr_resolver_resource_ nr_resolver_resource; |
60 | | |
61 | | namespace mozilla { |
62 | | |
63 | | class NrIceResolver |
64 | | { |
65 | | private: |
66 | | ~NrIceResolver(); |
67 | | public: |
68 | | NrIceResolver(); |
69 | | |
70 | | nsresult Init(); |
71 | | nr_resolver *AllocateResolver(); |
72 | | void DestroyResolver(); |
73 | | NS_INLINE_DECL_THREADSAFE_REFCOUNTING(NrIceResolver) |
74 | | |
75 | | int resolve(nr_resolver_resource *resource, |
76 | | int (*cb)(void *cb_arg, nr_transport_addr *addr), |
77 | | void *cb_arg, void **handle); |
78 | | |
79 | | private: |
80 | | // Implementations of vtbl functions |
81 | | static int destroy(void **objp); |
82 | | static int resolve(void *obj, nr_resolver_resource *resource, |
83 | | int (*cb)(void *cb_arg, nr_transport_addr *addr), |
84 | | void *cb_arg, void **handle); |
85 | | static void resolve_cb(NR_SOCKET s, int how, void *cb_arg); |
86 | | static int cancel(void *obj, void *handle); |
87 | | |
88 | | class PendingResolution : public nsIDNSListener |
89 | | { |
90 | | public: |
91 | | PendingResolution(nsIEventTarget *thread, |
92 | | uint16_t port, |
93 | | int transport, |
94 | | int (*cb)(void *cb_arg, nr_transport_addr *addr), |
95 | | void *cb_arg) : |
96 | | thread_(thread), |
97 | | port_(port), |
98 | | transport_(transport), |
99 | 0 | cb_(cb), cb_arg_(cb_arg) {} |
100 | | NS_IMETHOD OnLookupComplete(nsICancelable *request, nsIDNSRecord *record, |
101 | | nsresult status) override; |
102 | | NS_IMETHOD OnLookupByTypeComplete(nsICancelable *request, |
103 | | nsIDNSByTypeRecord *res, |
104 | | nsresult status) override |
105 | 0 | { |
106 | 0 | return NS_OK; |
107 | 0 | } |
108 | | int cancel(); |
109 | | nsCOMPtr<nsICancelable> request_; |
110 | | NS_DECL_THREADSAFE_ISUPPORTS |
111 | | |
112 | | private: |
113 | 0 | virtual ~PendingResolution(){}; |
114 | | nsCOMPtr<nsIEventTarget> thread_; |
115 | | uint16_t port_; |
116 | | int transport_; |
117 | | int (*cb_)(void *cb_arg, nr_transport_addr *addr); |
118 | | void *cb_arg_; |
119 | | }; |
120 | | |
121 | | nr_resolver_vtbl* vtbl_; |
122 | | nsCOMPtr<nsIEventTarget> sts_thread_; |
123 | | nsCOMPtr<nsIDNSService> dns_; |
124 | | #ifdef DEBUG |
125 | | int allocated_resolvers_; |
126 | | #endif |
127 | | }; |
128 | | |
129 | | } // End of namespace mozilla |
130 | | #endif |