1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "nsIURI.h"
#include "nsNetCID.h"
#include "nsAddbookUrl.h"
#include "nsStringGlue.h"
#include "nsAbBaseCID.h"
#include "nsComponentManagerUtils.h"
#include "nsAutoPtr.h"
/////////////////////////////////////////////////////////////////////////////////////
// addbook url definition
/////////////////////////////////////////////////////////////////////////////////////
nsAddbookUrl::nsAddbookUrl()
{
m_baseURL = do_CreateInstance(NS_SIMPLEURI_CONTRACTID);
mOperationType = nsIAddbookUrlOperation::InvalidUrl;
}
nsAddbookUrl::~nsAddbookUrl()
{
}
NS_IMPL_ISUPPORTS(nsAddbookUrl, nsIAddbookUrl, nsIURI)
NS_IMETHODIMP
nsAddbookUrl::SetSpec(const nsACString &aSpec)
{
nsresult rv = m_baseURL->SetSpec(aSpec);
NS_ENSURE_SUCCESS(rv, rv);
return ParseUrl();
}
nsresult nsAddbookUrl::ParseUrl()
{
nsAutoCString pathStr;
nsresult rv = m_baseURL->GetPath(pathStr);
NS_ENSURE_SUCCESS(rv,rv);
if (strstr(pathStr.get(), "?action=print"))
mOperationType = nsIAddbookUrlOperation::PrintAddressBook;
else if (strstr(pathStr.get(), "?action=add"))
mOperationType = nsIAddbookUrlOperation::AddVCard;
else
mOperationType = nsIAddbookUrlOperation::InvalidUrl;
return NS_OK;
}
////////////////////////////////////////////////////////////////////////////////////
// Begin nsIURI support
////////////////////////////////////////////////////////////////////////////////////
NS_IMETHODIMP nsAddbookUrl::GetSpec(nsACString &aSpec)
{
return m_baseURL->GetSpec(aSpec);
}
NS_IMETHODIMP nsAddbookUrl::GetPrePath(nsACString &aPrePath)
{
return m_baseURL->GetPrePath(aPrePath);
}
NS_IMETHODIMP nsAddbookUrl::GetScheme(nsACString &aScheme)
{
return m_baseURL->GetScheme(aScheme);
}
NS_IMETHODIMP nsAddbookUrl::SetScheme(const nsACString &aScheme)
{
return m_baseURL->SetScheme(aScheme);
}
NS_IMETHODIMP nsAddbookUrl::GetUserPass(nsACString &aUserPass)
{
return m_baseURL->GetUserPass(aUserPass);
}
NS_IMETHODIMP nsAddbookUrl::SetUserPass(const nsACString &aUserPass)
{
return m_baseURL->SetUserPass(aUserPass);
}
NS_IMETHODIMP nsAddbookUrl::GetUsername(nsACString &aUsername)
{
return m_baseURL->GetUsername(aUsername);
}
NS_IMETHODIMP nsAddbookUrl::SetUsername(const nsACString &aUsername)
{
return m_baseURL->SetUsername(aUsername);
}
NS_IMETHODIMP nsAddbookUrl::GetPassword(nsACString &aPassword)
{
return m_baseURL->GetPassword(aPassword);
}
NS_IMETHODIMP nsAddbookUrl::SetPassword(const nsACString &aPassword)
{
return m_baseURL->SetPassword(aPassword);
}
NS_IMETHODIMP nsAddbookUrl::GetHostPort(nsACString &aHostPort)
{
return m_baseURL->GetHostPort(aHostPort);
}
NS_IMETHODIMP nsAddbookUrl::SetHostPort(const nsACString &aHostPort)
{
return m_baseURL->SetHostPort(aHostPort);
}
NS_IMETHODIMP nsAddbookUrl::SetHostAndPort(const nsACString &aHostPort)
{
return m_baseURL->SetHostAndPort(aHostPort);
}
NS_IMETHODIMP nsAddbookUrl::GetHost(nsACString &aHost)
{
return m_baseURL->GetHost(aHost);
}
NS_IMETHODIMP nsAddbookUrl::SetHost(const nsACString &aHost)
{
return m_baseURL->SetHost(aHost);
}
NS_IMETHODIMP nsAddbookUrl::GetPort(int32_t *aPort)
{
return m_baseURL->GetPort(aPort);
}
NS_IMETHODIMP nsAddbookUrl::SetPort(int32_t aPort)
{
return m_baseURL->SetPort(aPort);
}
NS_IMETHODIMP nsAddbookUrl::GetPath(nsACString &aPath)
{
return m_baseURL->GetPath(aPath);
}
NS_IMETHODIMP nsAddbookUrl::SetPath(const nsACString &aPath)
{
m_baseURL->SetPath(aPath);
return ParseUrl();
}
NS_IMETHODIMP nsAddbookUrl::GetAsciiHost(nsACString &aHostA)
{
return m_baseURL->GetAsciiHost(aHostA);
}
NS_IMETHODIMP nsAddbookUrl::GetAsciiHostPort(nsACString &aHostPortA)
{
return m_baseURL->GetAsciiHostPort(aHostPortA);
}
NS_IMETHODIMP nsAddbookUrl::GetAsciiSpec(nsACString &aSpecA)
{
return m_baseURL->GetAsciiSpec(aSpecA);
}
NS_IMETHODIMP nsAddbookUrl::GetOriginCharset(nsACString &aOriginCharset)
{
return m_baseURL->GetOriginCharset(aOriginCharset);
}
NS_IMETHODIMP nsAddbookUrl::SchemeIs(const char *aScheme, bool *_retval)
{
return m_baseURL->SchemeIs(aScheme, _retval);
}
NS_IMETHODIMP nsAddbookUrl::Equals(nsIURI *other, bool *_retval)
{
// The passed-in URI might be an nsMailtoUrl. Pass our inner URL to its
// Equals method. The other nsMailtoUrl will then pass its inner URL to
// to the Equals method of our inner URL. Other URIs will return false.
if (other)
return other->Equals(m_baseURL, _retval);
return m_baseURL->Equals(other, _retval);
}
nsresult
nsAddbookUrl::CloneInternal(RefHandlingEnum aRefHandlingMode,
const nsACString& newRef, nsIURI** _retval)
{
NS_ENSURE_ARG_POINTER(_retval);
RefPtr<nsAddbookUrl> clone = new nsAddbookUrl();
if (!clone)
return NS_ERROR_OUT_OF_MEMORY;
nsresult rv;
if (aRefHandlingMode == eHonorRef) {
rv = m_baseURL->Clone(getter_AddRefs(clone->m_baseURL));
} else if (aRefHandlingMode == eReplaceRef) {
rv = m_baseURL->CloneWithNewRef(newRef, getter_AddRefs(clone->m_baseURL));
} else {
rv = m_baseURL->CloneIgnoringRef(getter_AddRefs(clone->m_baseURL));
}
NS_ENSURE_SUCCESS(rv, rv);
clone->ParseUrl();
clone.forget(_retval);
return NS_OK;
}
NS_IMETHODIMP nsAddbookUrl::Clone(nsIURI **_retval)
{
return CloneInternal(eHonorRef, EmptyCString(), _retval);
}
NS_IMETHODIMP
nsAddbookUrl::CloneIgnoringRef(nsIURI** _retval)
{
return CloneInternal(eIgnoreRef, EmptyCString(), _retval);
}
NS_IMETHODIMP
nsAddbookUrl::CloneWithNewRef(const nsACString& newRef, nsIURI** _retval)
{
return CloneInternal(eReplaceRef, newRef, _retval);
}
NS_IMETHODIMP nsAddbookUrl::Resolve(const nsACString &relativePath, nsACString &result)
{
return NS_ERROR_NOT_IMPLEMENTED;
}
NS_IMETHODIMP
nsAddbookUrl::GetRef(nsACString &result)
{
return m_baseURL->GetRef(result);
}
NS_IMETHODIMP
nsAddbookUrl::SetRef(const nsACString &aRef)
{
m_baseURL->SetRef(aRef);
return ParseUrl();
}
NS_IMETHODIMP
nsAddbookUrl::GetFilePath(nsACString &aFilePath)
{
return m_baseURL->GetFilePath(aFilePath);
}
NS_IMETHODIMP
nsAddbookUrl::SetFilePath(const nsACString &aFilePath)
{
return m_baseURL->SetFilePath(aFilePath);
}
NS_IMETHODIMP
nsAddbookUrl::GetQuery(nsACString &aQuery)
{
return m_baseURL->GetQuery(aQuery);
}
NS_IMETHODIMP
nsAddbookUrl::SetQuery(const nsACString &aQuery)
{
return m_baseURL->SetQuery(aQuery);
}
NS_IMETHODIMP nsAddbookUrl::EqualsExceptRef(nsIURI *other, bool *_retval)
{
// The passed-in URI might be an nsMailtoUrl. Pass our inner URL to its
// Equals method. The other nsMailtoUrl will then pass its inner URL to
// to the Equals method of our inner URL. Other URIs will return false.
if (other)
return other->EqualsExceptRef(m_baseURL, _retval);
return m_baseURL->EqualsExceptRef(other, _retval);
}
NS_IMETHODIMP
nsAddbookUrl::GetSpecIgnoringRef(nsACString &result)
{
return m_baseURL->GetSpecIgnoringRef(result);
}
NS_IMETHODIMP
nsAddbookUrl::GetHasRef(bool *result)
{
return m_baseURL->GetHasRef(result);
}
//
// Specific nsAddbookUrl operations
//
NS_IMETHODIMP
nsAddbookUrl::GetAddbookOperation(int32_t *_retval)
{
*_retval = mOperationType;
return NS_OK;
}
|