1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /* ***** BEGIN LICENSE BLOCK *****
3 * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 *
5 * The contents of this file are subject to the Mozilla Public License Version
6 * 1.1 (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 * http://www.mozilla.org/MPL/
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 * the Mozilla Foundation.
19 * Portions created by the Initial Developer are Copyright (C) 2005
20 * the Initial Developer. All Rights Reserved.
21 *
22 * Contributor(s):
23 * Boris Zbarsky <bzbarsky@mit.edu> (original author)
24 * Benjamin Smedberg <benjamin@smedbergs.us>
25 * Prasad Sunkari <prasad@medhas.org>
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 MPL, 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 MPL, the GPL or the LGPL.
38 *
39 * ***** END LICENSE BLOCK ***** */
40
41 #include "nsISupports.idl"
42
43 interface nsIURI;
44
45 /**
46 * nsINetUtil provides various network-related utility methods.
47 */
48 [scriptable, uuid(57322c6f-f4ec-4e46-8253-b74be220de16)]
49 interface nsINetUtil : nsISupports
50 {
51 /**
52 * Parse a content-type header and return the content type and
53 * charset (if any).
54 *
55 * @param aTypeHeader the header string to parse
56 * @param [out] aCharset the charset parameter specified in the
57 * header, if any.
58 * @param [out] aHadCharset whether a charset was explicitly specified.
59 * @return the MIME type specified in the header, in lower-case.
60 */
61 AUTF8String parseContentType(in AUTF8String aTypeHeader,
62 out AUTF8String aCharset,
63 out boolean aHadCharset);
64
65 /**
66 * Test whether the given URI's handler has the given protocol flags.
67 *
68 * @param aURI the URI in question
69 * @param aFlags the flags we're testing for.
70 *
71 * @return whether the protocol handler for aURI has all the flags
72 * in aFlags.
73 */
74 boolean protocolHasFlags(in nsIURI aURI, in unsigned long aFlag);
75
76 /**
77 * Test whether the protocol handler for this URI or that for any of
78 * its inner URIs has the given protocol flags. This will QI aURI to
79 * nsINestedURI and walk the nested URI chain.
80 *
81 * @param aURI the URI in question
82 * @param aFlags the flags we're testing for.
83 *
84 * @return whether any of the protocol handlers involved have all the flags
85 * in aFlags.
86 */
87 boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags);
88
89 /**
90 * Take aURI and produce an immutable version of it for the caller. If aURI
91 * is immutable this will be aURI itself; otherwise this will be a clone,
92 * marked immutable if possible. Passing null to this method is allowed; in
93 * that case it will return null.
94 */
95 nsIURI toImmutableURI(in nsIURI aURI);
96
97 /** Escape every character with its %XX-escaped equivalent */
98 const unsigned long ESCAPE_ALL = 0;
99
100 /** Leave alphanumeric characters intact and %XX-escape all others */
101 const unsigned long ESCAPE_XALPHAS = 1;
102
103 /** Leave alphanumeric characters intact, convert spaces to '+',
104 %XX-escape all others */
105 const unsigned long ESCAPE_XPALPHAS = 2;
106
107 /** Leave alphanumeric characters and forward slashes intact,
108 %XX-escape all others */
109 const unsigned long ESCAPE_URL_PATH = 4;
110
111 /**
112 * escape a string with %00-style escaping
113 */
114 ACString escapeString(in ACString aString, in unsigned long aEscapeType);
115
116 /** %XX-escape URL scheme */
117 const unsigned long ESCAPE_URL_SCHEME = 1;
118
119 /** %XX-escape username in the URL */
120 const unsigned long ESCAPE_URL_USERNAME = 1 << 1;
121
122 /** %XX-escape password in the URL */
123 const unsigned long ESCAPE_URL_PASSWORD = 1 << 2;
124
125 /** %XX-escape URL host */
126 const unsigned long ESCAPE_URL_HOST = 1 << 3;
127
128 /** %XX-escape URL directory */
129 const unsigned long ESCAPE_URL_DIRECTORY = 1 << 4;
130
131 /** %XX-escape file basename in the URL */
132 const unsigned long ESCAPE_URL_FILE_BASENAME = 1 << 5;
133
134 /** %XX-escape file extension in the URL */
135 const unsigned long ESCAPE_URL_FILE_EXTENSION = 1 << 6;
136
137 /** %XX-escape URL parameters */
138 const unsigned long ESCAPE_URL_PARAM = 1 << 7;
139
140 /** %XX-escape URL query */
141 const unsigned long ESCAPE_URL_QUERY = 1 << 8;
142
143 /** %XX-escape URL ref */
144 const unsigned long ESCAPE_URL_REF = 1 << 9;
145
146 /** %XX-escape URL path - same as escaping directory, basename and extension */
147 const unsigned long ESCAPE_URL_FILEPATH =
148 ESCAPE_URL_DIRECTORY | ESCAPE_URL_FILE_BASENAME | ESCAPE_URL_FILE_EXTENSION;
149
150 /** %XX-escape scheme, username, password, host, path, params, query and ref */
151 const unsigned long ESCAPE_URL_MINIMAL =
152 ESCAPE_URL_SCHEME | ESCAPE_URL_USERNAME | ESCAPE_URL_PASSWORD |
153 ESCAPE_URL_HOST | ESCAPE_URL_FILEPATH | ESCAPE_URL_PARAM |
154 ESCAPE_URL_QUERY | ESCAPE_URL_REF;
155
156 /** Force %XX-escaping of already escaped sequences */
157 const unsigned long ESCAPE_URL_FORCED = 1 << 10;
158
159 /** Skip non-ascii octets, %XX-escape all others */
160 const unsigned long ESCAPE_URL_ONLY_ASCII = 1 << 11;
161
162 /**
163 * Skip graphic octets (0x20-0x7E) when escaping
164 * Skips all ASCII octets (0x00-0x7F) when unescaping
165 */
166 const unsigned long ESCAPE_URL_ONLY_NONASCII = 1 << 12;
167
168 /** Force %XX-escape of colon */
169 const unsigned long ESCAPE_URL_COLON = 1 << 14;
170
171 /** Skip C0 and DEL from unescaping */
172 const unsigned long ESCAPE_URL_SKIP_CONTROL = 1 << 15;
173
174 /**
175 * %XX-Escape invalid chars in a URL segment.
176 *
177 * @param aStr the URL to be escaped
178 * @param aFlags the URL segment type flags
179 *
180 * @return the escaped string (the string itself if escaping did not happen)
181 *
182 */
183 ACString escapeURL(in ACString aStr, in unsigned long aFlags);
184
185 /**
186 * Expands URL escape sequences
187 *
188 * @param aStr the URL to be unescaped
189 * @param aFlags only ESCAPE_URL_ONLY_NONASCII and ESCAPE_URL_SKIP_CONTROL
190 * are recognized. If |aFlags| is 0 all escape sequences are
191 * unescaped
192 * @return unescaped string
193 */
194 ACString unescapeString(in ACString aStr, in unsigned long aFlags);
195
196 /**
197 * Extract the charset parameter location and value from a content-type
198 * header.
199 *
200 * @param aTypeHeader the header string to parse
201 * @param [out] aCharset the charset parameter specified in the
202 * header, if any.
203 * @param [out] aCharsetStart index of the start of the charset parameter
204 * (the ';' separating it from what came before) in aTypeHeader.
205 * If this function returns false, this argument will still be
206 * set, to the index of the location where a new charset should
207 * be inserted.
208 * @param [out] aCharsetEnd index of the end of the charset parameter (the
209 * ';' separating it from what comes after, or the end
210 * of the string) in aTypeHeader. If this function returns
211 * false, this argument will still be set, to the index of the
212 * location where a new charset should be inserted.
213 *
214 * @return whether a charset parameter was found. This can be false even in
215 * cases when parseContentType would claim to have a charset, if the type
216 * that won out does not have a charset parameter specified.
217 */
218 boolean extractCharsetFromContentType(in AUTF8String aTypeHeader,
219 out AUTF8String aCharset,
220 out long aCharsetStart,
221 out long aCharsetEnd);
222 };