/src/mozilla-central/netwerk/dns/mdns/libmdns/nsDNSServiceInfo.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #include "nsDNSServiceInfo.h" |
7 | | #include "nsHashPropertyBag.h" |
8 | | #include "nsIProperty.h" |
9 | | #include "nsISimpleEnumerator.h" |
10 | | #include "nsISupportsImpl.h" |
11 | | #include "mozilla/Unused.h" |
12 | | |
13 | | namespace mozilla { |
14 | | namespace net { |
15 | | |
16 | | NS_IMPL_ISUPPORTS(nsDNSServiceInfo, nsIDNSServiceInfo) |
17 | | |
18 | | nsDNSServiceInfo::nsDNSServiceInfo(nsIDNSServiceInfo* aServiceInfo) |
19 | 0 | { |
20 | 0 | if (NS_WARN_IF(!aServiceInfo)) { |
21 | 0 | return; |
22 | 0 | } |
23 | 0 | |
24 | 0 | nsAutoCString str; |
25 | 0 | uint16_t value; |
26 | 0 |
|
27 | 0 | if (NS_SUCCEEDED(aServiceInfo->GetHost(str))) { |
28 | 0 | Unused << NS_WARN_IF(NS_FAILED(SetHost(str))); |
29 | 0 | } |
30 | 0 | if (NS_SUCCEEDED(aServiceInfo->GetAddress(str))) { |
31 | 0 | Unused << NS_WARN_IF(NS_FAILED(SetAddress(str))); |
32 | 0 | } |
33 | 0 | if (NS_SUCCEEDED(aServiceInfo->GetPort(&value))) { |
34 | 0 | Unused << NS_WARN_IF(NS_FAILED(SetPort(value))); |
35 | 0 | } |
36 | 0 | if (NS_SUCCEEDED(aServiceInfo->GetServiceName(str))) { |
37 | 0 | Unused << NS_WARN_IF(NS_FAILED(SetServiceName(str))); |
38 | 0 | } |
39 | 0 | if (NS_SUCCEEDED(aServiceInfo->GetServiceType(str))) { |
40 | 0 | Unused << NS_WARN_IF(NS_FAILED(SetServiceType(str))); |
41 | 0 | } |
42 | 0 | if (NS_SUCCEEDED(aServiceInfo->GetDomainName(str))) { |
43 | 0 | Unused << NS_WARN_IF(NS_FAILED(SetDomainName(str))); |
44 | 0 | } |
45 | 0 |
|
46 | 0 | nsCOMPtr<nsIPropertyBag2> attributes; // deep copy |
47 | 0 | if (NS_SUCCEEDED(aServiceInfo->GetAttributes(getter_AddRefs(attributes)))) { |
48 | 0 | nsCOMPtr<nsISimpleEnumerator> enumerator; |
49 | 0 | if (NS_WARN_IF(NS_FAILED(attributes->GetEnumerator(getter_AddRefs(enumerator))))) { |
50 | 0 | return; |
51 | 0 | } |
52 | 0 | |
53 | 0 | nsCOMPtr<nsIWritablePropertyBag2> newAttributes = new nsHashPropertyBag(); |
54 | 0 |
|
55 | 0 | bool hasMoreElements; |
56 | 0 | while (NS_SUCCEEDED(enumerator->HasMoreElements(&hasMoreElements)) && |
57 | 0 | hasMoreElements) { |
58 | 0 | nsCOMPtr<nsISupports> element; |
59 | 0 | Unused << |
60 | 0 | NS_WARN_IF(NS_FAILED(enumerator->GetNext(getter_AddRefs(element)))); |
61 | 0 | nsCOMPtr<nsIProperty> property = do_QueryInterface(element); |
62 | 0 | MOZ_ASSERT(property); |
63 | 0 |
|
64 | 0 | nsAutoString name; |
65 | 0 | nsCOMPtr<nsIVariant> value; |
66 | 0 | Unused << NS_WARN_IF(NS_FAILED(property->GetName(name))); |
67 | 0 | Unused << NS_WARN_IF(NS_FAILED(property->GetValue(getter_AddRefs(value)))); |
68 | 0 | nsAutoCString valueStr; |
69 | 0 | Unused << NS_WARN_IF(NS_FAILED(value->GetAsACString(valueStr))); |
70 | 0 |
|
71 | 0 | Unused << NS_WARN_IF(NS_FAILED(newAttributes->SetPropertyAsACString(name, valueStr))); |
72 | 0 | } |
73 | 0 |
|
74 | 0 | Unused << NS_WARN_IF(NS_FAILED(SetAttributes(newAttributes))); |
75 | 0 | } |
76 | 0 | } |
77 | | |
78 | | NS_IMETHODIMP |
79 | | nsDNSServiceInfo::GetHost(nsACString& aHost) |
80 | 0 | { |
81 | 0 | if (!mIsHostSet) { |
82 | 0 | return NS_ERROR_NOT_INITIALIZED; |
83 | 0 | } |
84 | 0 | aHost = mHost; |
85 | 0 | return NS_OK; |
86 | 0 | } |
87 | | |
88 | | NS_IMETHODIMP |
89 | | nsDNSServiceInfo::SetHost(const nsACString& aHost) |
90 | 0 | { |
91 | 0 | mHost = aHost; |
92 | 0 | mIsHostSet = true; |
93 | 0 | return NS_OK; |
94 | 0 | } |
95 | | |
96 | | NS_IMETHODIMP |
97 | | nsDNSServiceInfo::GetAddress(nsACString& aAddress) |
98 | 0 | { |
99 | 0 | if (!mIsAddressSet) { |
100 | 0 | return NS_ERROR_NOT_INITIALIZED; |
101 | 0 | } |
102 | 0 | aAddress = mAddress; |
103 | 0 | return NS_OK; |
104 | 0 | } |
105 | | |
106 | | NS_IMETHODIMP |
107 | | nsDNSServiceInfo::SetAddress(const nsACString& aAddress) |
108 | 0 | { |
109 | 0 | mAddress = aAddress; |
110 | 0 | mIsAddressSet = true; |
111 | 0 | return NS_OK; |
112 | 0 | } |
113 | | |
114 | | NS_IMETHODIMP |
115 | | nsDNSServiceInfo::GetPort(uint16_t* aPort) |
116 | 0 | { |
117 | 0 | if (NS_WARN_IF(!aPort)) { |
118 | 0 | return NS_ERROR_INVALID_ARG; |
119 | 0 | } |
120 | 0 | if (!mIsPortSet) { |
121 | 0 | return NS_ERROR_NOT_INITIALIZED; |
122 | 0 | } |
123 | 0 | *aPort = mPort; |
124 | 0 | return NS_OK; |
125 | 0 | } |
126 | | |
127 | | NS_IMETHODIMP |
128 | | nsDNSServiceInfo::SetPort(uint16_t aPort) |
129 | 0 | { |
130 | 0 | mPort = aPort; |
131 | 0 | mIsPortSet = true; |
132 | 0 | return NS_OK; |
133 | 0 | } |
134 | | |
135 | | NS_IMETHODIMP |
136 | | nsDNSServiceInfo::GetServiceName(nsACString& aServiceName) |
137 | 0 | { |
138 | 0 | if (!mIsServiceNameSet) { |
139 | 0 | return NS_ERROR_NOT_INITIALIZED; |
140 | 0 | } |
141 | 0 | aServiceName = mServiceName; |
142 | 0 | return NS_OK; |
143 | 0 | } |
144 | | |
145 | | NS_IMETHODIMP |
146 | | nsDNSServiceInfo::SetServiceName(const nsACString& aServiceName) |
147 | 0 | { |
148 | 0 | mServiceName = aServiceName; |
149 | 0 | mIsServiceNameSet = true; |
150 | 0 | return NS_OK; |
151 | 0 | } |
152 | | |
153 | | NS_IMETHODIMP |
154 | | nsDNSServiceInfo::GetServiceType(nsACString& aServiceType) |
155 | 0 | { |
156 | 0 | if (!mIsServiceTypeSet) { |
157 | 0 | return NS_ERROR_NOT_INITIALIZED; |
158 | 0 | } |
159 | 0 | aServiceType = mServiceType; |
160 | 0 | return NS_OK; |
161 | 0 | } |
162 | | |
163 | | NS_IMETHODIMP |
164 | | nsDNSServiceInfo::SetServiceType(const nsACString& aServiceType) |
165 | 0 | { |
166 | 0 | mServiceType = aServiceType; |
167 | 0 | mIsServiceTypeSet = true; |
168 | 0 | return NS_OK; |
169 | 0 | } |
170 | | |
171 | | NS_IMETHODIMP |
172 | | nsDNSServiceInfo::GetDomainName(nsACString& aDomainName) |
173 | 0 | { |
174 | 0 | if (!mIsDomainNameSet) { |
175 | 0 | return NS_ERROR_NOT_INITIALIZED; |
176 | 0 | } |
177 | 0 | aDomainName = mDomainName; |
178 | 0 | return NS_OK; |
179 | 0 | } |
180 | | |
181 | | NS_IMETHODIMP |
182 | | nsDNSServiceInfo::SetDomainName(const nsACString& aDomainName) |
183 | 0 | { |
184 | 0 | mDomainName = aDomainName; |
185 | 0 | mIsDomainNameSet = true; |
186 | 0 | return NS_OK; |
187 | 0 | } |
188 | | |
189 | | NS_IMETHODIMP |
190 | | nsDNSServiceInfo::GetAttributes(nsIPropertyBag2** aAttributes) |
191 | 0 | { |
192 | 0 | if (!mIsAttributesSet) { |
193 | 0 | return NS_ERROR_NOT_INITIALIZED; |
194 | 0 | } |
195 | 0 | nsCOMPtr<nsIPropertyBag2> attributes(mAttributes); |
196 | 0 | attributes.forget(aAttributes); |
197 | 0 | return NS_OK; |
198 | 0 | } |
199 | | |
200 | | NS_IMETHODIMP |
201 | | nsDNSServiceInfo::SetAttributes(nsIPropertyBag2* aAttributes) |
202 | 0 | { |
203 | 0 | mAttributes = aAttributes; |
204 | 0 | mIsAttributesSet = aAttributes ? true : false; |
205 | 0 | return NS_OK; |
206 | 0 | } |
207 | | |
208 | | } // namespace net |
209 | | } // namespace mozilla |