~ubuntu-branches/ubuntu/precise/kompozer/precise

« back to all changes in this revision

Viewing changes to mozilla/embedding/wrappers/DotNETEmbed/DotNETNetworking.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Anthony Yarusso
  • Date: 2007-08-27 01:11:03 UTC
  • Revision ID: james.westby@ubuntu.com-20070827011103-2jgf4s6532gqu2ka
Tags: upstream-0.7.10
ImportĀ upstreamĀ versionĀ 0.7.10

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
 
2
/* ***** BEGIN LICENSE BLOCK *****
 
3
 * Version: NPL 1.1/GPL 2.0/LGPL 2.1
 
4
 *
 
5
 * The contents of this file are subject to the Netscape Public License
 
6
 * Version 1.1 (the "License"); you may not use this file except in
 
7
 * compliance with the License. You may obtain a copy of the License at
 
8
 * http://www.mozilla.org/NPL/
 
9
 *
 
10
 * Software distributed under the License is distributed on an "AS IS" basis,
 
11
 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
 
12
 * for the specific language governing rights and limitations under the
 
13
 * License.
 
14
 *
 
15
 * The Original Code is mozilla.org code.
 
16
 *
 
17
 * The Initial Developer of the Original Code is
 
18
 * Netscape Communications Corporation.
 
19
 * Portions created by the Initial Developer are Copyright (C) 2003
 
20
 * the Initial Developer. All Rights Reserved.
 
21
 *
 
22
 * Contributor(s):
 
23
 *   Roy Yokoyama <yokoyama@netscape.com> (original author)
 
24
 *   Johnny Stenback <jst@netscape.com>
 
25
 *
 
26
 *
 
27
 * Alternatively, the contents of this file may be used under the terms of
 
28
 * either the GNU General Public License Version 2 or later (the "GPL"), or
 
29
 * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
 
30
 * in which case the provisions of the GPL or the LGPL are applicable instead
 
31
 * of those above. If you wish to allow use of your version of this file only
 
32
 * under the terms of either the GPL or the LGPL, and not to allow others to
 
33
 * use your version of this file under the terms of the NPL, indicate your
 
34
 * decision by deleting the provisions above and replace them with the notice
 
35
 * and other provisions required by the GPL or the LGPL. If you do not delete
 
36
 * the provisions above, a recipient may use your version of this file under
 
37
 * the terms of any one of the NPL, the GPL or the LGPL.
 
38
 *
 
39
 * ***** END LICENSE BLOCK ***** */
 
40
 
 
41
#using <mscorlib.dll>
 
42
 
 
43
#include "nsISupports.h"
 
44
#include "nsCOMPtr.h"
 
45
#include "nsIURI.h"
 
46
#include "nsNetUtil.h"
 
47
#include "DotNETNetworking.h"
 
48
 
 
49
using namespace Mozilla::Embedding::Networking;
 
50
 
 
51
URI::URI(nsIURI *aURI)
 
52
  : mURI(aURI)
 
53
{
 
54
  NS_IF_ADDREF(mURI);
 
55
}
 
56
 
 
57
URI::URI(String *aSpec)
 
58
  : mURI(nsnull)
 
59
{
 
60
  nsCAutoString spec;
 
61
  CopyString(aSpec, spec);
 
62
 
 
63
  nsCOMPtr<nsIURI> uri;
 
64
  nsresult rv = NS_NewURI(getter_AddRefs(uri), spec.get());
 
65
  ThrowIfFailed(rv);
 
66
 
 
67
  mURI = uri.get();
 
68
  NS_IF_ADDREF(mURI);
 
69
}
 
70
 
 
71
URI::~URI()
 
72
{
 
73
  NS_IF_RELEASE(mURI);
 
74
}
 
75
 
 
76
Object *
 
77
URI::Clone()
 
78
{
 
79
  nsCOMPtr<nsIURI> uriClone;
 
80
 
 
81
  if (mURI) {
 
82
    nsresult rv = mURI->Clone(getter_AddRefs(uriClone));
 
83
    ThrowIfFailed(rv);
 
84
  }
 
85
 
 
86
  return new URI(uriClone);
 
87
}
 
88
 
 
89
void
 
90
URI::Dispose()
 
91
{
 
92
  NS_IF_RELEASE(mURI);
 
93
 
 
94
  GC::SuppressFinalize(this);
 
95
}
 
96
 
 
97
String *
 
98
URI::get_Spec()
 
99
{
 
100
  nsCAutoString spec;
 
101
  nsresult rv = mURI->GetSpec(spec);
 
102
  ThrowIfFailed(rv);
 
103
 
 
104
  return CopyString(spec);
 
105
}
 
106
 
 
107
void
 
108
URI::set_Spec(String *aSpec)
 
109
{
 
110
  nsCAutoString spec;
 
111
  CopyString(aSpec, spec);
 
112
 
 
113
  nsresult rv = mURI->SetSpec(spec);
 
114
  ThrowIfFailed(rv);
 
115
}
 
116
 
 
117
String *
 
118
URI::get_PrePath()
 
119
{
 
120
  nsCAutoString prePath;
 
121
  nsresult rv = mURI->GetPrePath(prePath);
 
122
  ThrowIfFailed(rv);
 
123
 
 
124
  return CopyString(prePath);
 
125
}
 
126
 
 
127
String *
 
128
URI::get_Scheme()
 
129
{
 
130
  nsCAutoString scheme;
 
131
  nsresult rv = mURI->GetScheme(scheme);
 
132
  ThrowIfFailed(rv);
 
133
 
 
134
  return CopyString(scheme);
 
135
}
 
136
 
 
137
void
 
138
URI::set_Scheme(String *aScheme)
 
139
{
 
140
  nsCAutoString scheme;
 
141
  CopyString(aScheme, scheme);
 
142
 
 
143
  nsresult rv = mURI->SetScheme(scheme);
 
144
  ThrowIfFailed(rv);
 
145
}
 
146
 
 
147
String *
 
148
URI::get_UserPass()
 
149
{
 
150
  nsCAutoString userPass;
 
151
  nsresult rv = mURI->GetUserPass(userPass);
 
152
  ThrowIfFailed(rv);
 
153
 
 
154
  return CopyString(userPass);
 
155
}
 
156
 
 
157
void
 
158
URI::set_UserPass(String *aUserPass)
 
159
{
 
160
  nsCAutoString userPass;
 
161
  CopyString(aUserPass, userPass);
 
162
 
 
163
  nsresult rv = mURI->SetUserPass(userPass);
 
164
  ThrowIfFailed(rv);
 
165
}
 
166
 
 
167
String *
 
168
URI::get_Username()
 
169
{
 
170
  nsCAutoString username;
 
171
  nsresult rv = mURI->GetUsername(username);
 
172
  ThrowIfFailed(rv);
 
173
 
 
174
  return CopyString(username);
 
175
}
 
176
 
 
177
void
 
178
URI::set_Username(String *aUsername)
 
179
{
 
180
  nsCAutoString username;
 
181
  CopyString(aUsername, username);
 
182
 
 
183
  nsresult rv = mURI->SetUsername(username);
 
184
  ThrowIfFailed(rv);
 
185
}
 
186
 
 
187
String *
 
188
URI::get_Password()
 
189
{
 
190
  nsCAutoString password;
 
191
  nsresult rv = mURI->GetPassword(password);
 
192
  ThrowIfFailed(rv);
 
193
 
 
194
  return CopyString(password);
 
195
}
 
196
 
 
197
void
 
198
URI::set_Password(String *aPassword)
 
199
{
 
200
  nsCAutoString password;
 
201
  CopyString(aPassword, password);
 
202
 
 
203
  nsresult rv = mURI->SetPassword(password);
 
204
  ThrowIfFailed(rv);
 
205
}
 
206
 
 
207
String *
 
208
URI::get_HostPort()
 
209
{
 
210
  nsCAutoString hostPort;
 
211
  nsresult rv = mURI->GetHostPort(hostPort);
 
212
  ThrowIfFailed(rv);
 
213
 
 
214
  return CopyString(hostPort);
 
215
}
 
216
 
 
217
void
 
218
URI::set_HostPort(String *aHostPort)
 
219
{
 
220
  nsCAutoString hostPort;
 
221
  CopyString(aHostPort, hostPort);
 
222
 
 
223
  nsresult rv = mURI->SetHostPort(hostPort);
 
224
  ThrowIfFailed(rv);
 
225
}
 
226
 
 
227
String *
 
228
URI::get_Host()
 
229
{
 
230
  nsCAutoString host;
 
231
  nsresult rv = mURI->GetHost(host);
 
232
  ThrowIfFailed(rv);
 
233
 
 
234
  return CopyString(host);
 
235
}
 
236
 
 
237
void
 
238
URI::set_Host(String *aHost)
 
239
{
 
240
  nsCAutoString host;
 
241
  CopyString(aHost, host);
 
242
 
 
243
  nsresult rv = mURI->SetHost(host);
 
244
  ThrowIfFailed(rv);
 
245
}
 
246
 
 
247
Int32
 
248
URI::get_Port()
 
249
{
 
250
  PRInt32 port;
 
251
  nsresult rv = mURI->GetPort(&port);
 
252
  ThrowIfFailed(rv);
 
253
 
 
254
  return port;
 
255
}
 
256
 
 
257
void
 
258
URI::set_Port(Int32 aPort)
 
259
{
 
260
  nsresult rv = mURI->SetPort(aPort);
 
261
  ThrowIfFailed(rv);
 
262
}
 
263
 
 
264
String *
 
265
URI::get_Path()
 
266
{
 
267
  nsCAutoString path;
 
268
  nsresult rv = mURI->GetPath(path);
 
269
  ThrowIfFailed(rv);
 
270
 
 
271
  return CopyString(path);
 
272
}
 
273
 
 
274
void
 
275
URI::set_Path(String *aPath)
 
276
{
 
277
  nsCAutoString path;
 
278
  CopyString(aPath, path);
 
279
 
 
280
  nsresult rv = mURI->SetPath(path);
 
281
  ThrowIfFailed(rv);
 
282
}
 
283
 
 
284
bool
 
285
URI::Equals(URI *aOther)
 
286
{
 
287
  if (!mURI) {
 
288
    if (!aOther || !aOther->mURI) {
 
289
      return true;
 
290
    }
 
291
 
 
292
    return false;
 
293
  }
 
294
 
 
295
  PRBool equals;
 
296
  nsresult rv = mURI->Equals(aOther->mURI, &equals);
 
297
  ThrowIfFailed(rv);
 
298
 
 
299
  return equals;
 
300
}
 
301
 
 
302
bool
 
303
URI::SchemeIs(String *aScheme)
 
304
{
 
305
  nsCAutoString scheme;
 
306
  CopyString(aScheme, scheme);
 
307
 
 
308
  PRBool isScheme = PR_FALSE;
 
309
 
 
310
  nsresult rv = mURI->SchemeIs(scheme.get(), &isScheme);
 
311
  ThrowIfFailed(rv);
 
312
 
 
313
  return isScheme;
 
314
}
 
315
 
 
316
String *
 
317
URI::Resolve(String *aRelativePath)
 
318
{
 
319
  nsCAutoString relativePath, resolvedPath;
 
320
  CopyString(aRelativePath, relativePath);
 
321
 
 
322
  nsresult rv = mURI->Resolve(relativePath, resolvedPath);
 
323
  ThrowIfFailed(rv);
 
324
 
 
325
  return CopyString(resolvedPath);
 
326
}
 
327
 
 
328
String *
 
329
URI::get_AsciiSpec()
 
330
{
 
331
  nsCAutoString asciiSpec;
 
332
  nsresult rv = mURI->GetAsciiSpec(asciiSpec);
 
333
  ThrowIfFailed(rv);
 
334
 
 
335
  return CopyString(asciiSpec);
 
336
}
 
337
 
 
338
String *
 
339
URI::get_AsciiHost()
 
340
{
 
341
  nsCAutoString asciiHost;
 
342
  nsresult rv = mURI->GetAsciiHost(asciiHost);
 
343
  ThrowIfFailed(rv);
 
344
 
 
345
  return CopyString(asciiHost);
 
346
}
 
347
 
 
348
String *
 
349
URI::get_OriginCharset()
 
350
{
 
351
  nsCAutoString originalCharset;
 
352
  nsresult rv = mURI->GetOriginCharset(originalCharset);
 
353
  ThrowIfFailed(rv);
 
354
 
 
355
  return CopyString(originalCharset);
 
356
}