netwerk/base/public/nsINetUtil.idl

changeset 0
6474c204b198
equal deleted inserted replaced
-1:000000000000 0:f3a108910a4d
1 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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 "nsISupports.idl"
7
8 interface nsIURI;
9 interface nsIPrefBranch;
10
11 /**
12 * nsINetUtil provides various network-related utility methods.
13 */
14 [scriptable, uuid(ca68c485-9db3-4c12-82a6-4fab7948e2d5)]
15 interface nsINetUtil : nsISupports
16 {
17 /**
18 * Parse a content-type header and return the content type and
19 * charset (if any).
20 *
21 * @param aTypeHeader the header string to parse
22 * @param [out] aCharset the charset parameter specified in the
23 * header, if any.
24 * @param [out] aHadCharset whether a charset was explicitly specified.
25 * @return the MIME type specified in the header, in lower-case.
26 */
27 AUTF8String parseContentType(in AUTF8String aTypeHeader,
28 out AUTF8String aCharset,
29 out boolean aHadCharset);
30
31 /**
32 * Test whether the given URI's handler has the given protocol flags.
33 *
34 * @param aURI the URI in question
35 * @param aFlags the flags we're testing for.
36 *
37 * @return whether the protocol handler for aURI has all the flags
38 * in aFlags.
39 */
40 boolean protocolHasFlags(in nsIURI aURI, in unsigned long aFlag);
41
42 /**
43 * Test whether the protocol handler for this URI or that for any of
44 * its inner URIs has the given protocol flags. This will QI aURI to
45 * nsINestedURI and walk the nested URI chain.
46 *
47 * @param aURI the URI in question
48 * @param aFlags the flags we're testing for.
49 *
50 * @return whether any of the protocol handlers involved have all the flags
51 * in aFlags.
52 */
53 boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags);
54
55 /**
56 * Take aURI and produce an immutable version of it for the caller. If aURI
57 * is immutable this will be aURI itself; otherwise this will be a clone,
58 * marked immutable if possible. Passing null to this method is allowed; in
59 * that case it will return null.
60 */
61 nsIURI toImmutableURI(in nsIURI aURI);
62
63 /**
64 * Create a simple nested URI using the result of
65 * toImmutableURI on the passed-in aURI which may not be null.
66 * Note: The return URI will not have had its spec set yet.
67 */
68 nsIURI newSimpleNestedURI(in nsIURI aURI);
69
70 /** Escape every character with its %XX-escaped equivalent */
71 const unsigned long ESCAPE_ALL = 0;
72
73 /** Leave alphanumeric characters intact and %XX-escape all others */
74 const unsigned long ESCAPE_XALPHAS = 1;
75
76 /** Leave alphanumeric characters intact, convert spaces to '+',
77 %XX-escape all others */
78 const unsigned long ESCAPE_XPALPHAS = 2;
79
80 /** Leave alphanumeric characters and forward slashes intact,
81 %XX-escape all others */
82 const unsigned long ESCAPE_URL_PATH = 4;
83
84 /**
85 * escape a string with %00-style escaping
86 */
87 ACString escapeString(in ACString aString, in unsigned long aEscapeType);
88
89 /** %XX-escape URL scheme */
90 const unsigned long ESCAPE_URL_SCHEME = 1;
91
92 /** %XX-escape username in the URL */
93 const unsigned long ESCAPE_URL_USERNAME = 1 << 1;
94
95 /** %XX-escape password in the URL */
96 const unsigned long ESCAPE_URL_PASSWORD = 1 << 2;
97
98 /** %XX-escape URL host */
99 const unsigned long ESCAPE_URL_HOST = 1 << 3;
100
101 /** %XX-escape URL directory */
102 const unsigned long ESCAPE_URL_DIRECTORY = 1 << 4;
103
104 /** %XX-escape file basename in the URL */
105 const unsigned long ESCAPE_URL_FILE_BASENAME = 1 << 5;
106
107 /** %XX-escape file extension in the URL */
108 const unsigned long ESCAPE_URL_FILE_EXTENSION = 1 << 6;
109
110 /** %XX-escape URL parameters */
111 const unsigned long ESCAPE_URL_PARAM = 1 << 7;
112
113 /** %XX-escape URL query */
114 const unsigned long ESCAPE_URL_QUERY = 1 << 8;
115
116 /** %XX-escape URL ref */
117 const unsigned long ESCAPE_URL_REF = 1 << 9;
118
119 /** %XX-escape URL path - same as escaping directory, basename and extension */
120 const unsigned long ESCAPE_URL_FILEPATH =
121 ESCAPE_URL_DIRECTORY | ESCAPE_URL_FILE_BASENAME | ESCAPE_URL_FILE_EXTENSION;
122
123 /** %XX-escape scheme, username, password, host, path, params, query and ref */
124 const unsigned long ESCAPE_URL_MINIMAL =
125 ESCAPE_URL_SCHEME | ESCAPE_URL_USERNAME | ESCAPE_URL_PASSWORD |
126 ESCAPE_URL_HOST | ESCAPE_URL_FILEPATH | ESCAPE_URL_PARAM |
127 ESCAPE_URL_QUERY | ESCAPE_URL_REF;
128
129 /** Force %XX-escaping of already escaped sequences */
130 const unsigned long ESCAPE_URL_FORCED = 1 << 10;
131
132 /** Skip non-ascii octets, %XX-escape all others */
133 const unsigned long ESCAPE_URL_ONLY_ASCII = 1 << 11;
134
135 /**
136 * Skip graphic octets (0x20-0x7E) when escaping
137 * Skips all ASCII octets (0x00-0x7F) when unescaping
138 */
139 const unsigned long ESCAPE_URL_ONLY_NONASCII = 1 << 12;
140
141 /** Force %XX-escape of colon */
142 const unsigned long ESCAPE_URL_COLON = 1 << 14;
143
144 /** Skip C0 and DEL from unescaping */
145 const unsigned long ESCAPE_URL_SKIP_CONTROL = 1 << 15;
146
147 /**
148 * %XX-Escape invalid chars in a URL segment.
149 *
150 * @param aStr the URL to be escaped
151 * @param aFlags the URL segment type flags
152 *
153 * @return the escaped string (the string itself if escaping did not happen)
154 *
155 */
156 ACString escapeURL(in ACString aStr, in unsigned long aFlags);
157
158 /**
159 * Expands URL escape sequences
160 *
161 * @param aStr the URL to be unescaped
162 * @param aFlags only ESCAPE_URL_ONLY_NONASCII and ESCAPE_URL_SKIP_CONTROL
163 * are recognized. If |aFlags| is 0 all escape sequences are
164 * unescaped
165 * @return unescaped string
166 */
167 ACString unescapeString(in AUTF8String aStr, in unsigned long aFlags);
168
169 /**
170 * Extract the charset parameter location and value from a content-type
171 * header.
172 *
173 * @param aTypeHeader the header string to parse
174 * @param [out] aCharset the charset parameter specified in the
175 * header, if any.
176 * @param [out] aCharsetStart index of the start of the charset parameter
177 * (the ';' separating it from what came before) in aTypeHeader.
178 * If this function returns false, this argument will still be
179 * set, to the index of the location where a new charset should
180 * be inserted.
181 * @param [out] aCharsetEnd index of the end of the charset parameter (the
182 * ';' separating it from what comes after, or the end
183 * of the string) in aTypeHeader. If this function returns
184 * false, this argument will still be set, to the index of the
185 * location where a new charset should be inserted.
186 *
187 * @return whether a charset parameter was found. This can be false even in
188 * cases when parseContentType would claim to have a charset, if the type
189 * that won out does not have a charset parameter specified.
190 */
191 boolean extractCharsetFromContentType(in AUTF8String aTypeHeader,
192 out AUTF8String aCharset,
193 out long aCharsetStart,
194 out long aCharsetEnd);
195 };

mercurial