Source code

Revision control

Other Tools

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(fe2625ec-b884-4df1-b39c-9e830e47aa94)]
15
interface nsINetUtil : nsISupports
16
{
17
/**
18
* Parse a Content-Type header value in strict mode. This is a more
19
* conservative parser that reject things that violate RFC 7231 section
20
* 3.1.1.1. This is typically useful for parsing Content-Type header values
21
* that are used for HTTP requests, and those that are used to make security
22
* decisions.
23
*
24
* @param aTypeHeader the header string to parse
25
* @param [out] aCharset the charset parameter specified in the
26
* header, if any.
27
* @param [out] aHadCharset whether a charset was explicitly specified.
28
* @return the MIME type specified in the header, in lower-case.
29
*/
30
AUTF8String parseRequestContentType(in AUTF8String aTypeHeader,
31
out AUTF8String aCharset,
32
out boolean aHadCharset);
33
34
/**
35
* Parse a Content-Type header value in relaxed mode. This is a more
36
* permissive parser that ignores things that go against RFC 7231 section
37
* 3.1.1.1. This is typically useful for parsing Content-Type header values
38
* received from web servers where we want to make a best effort attempt
39
* at extracting a useful MIME type and charset.
40
*
41
* NOTE: DO NOT USE THIS if you're going to make security decisions
42
* based on the result.
43
*
44
* @param aTypeHeader the header string to parse
45
* @param [out] aCharset the charset parameter specified in the
46
* header, if any.
47
* @param [out] aHadCharset whether a charset was explicitly specified.
48
* @return the MIME type specified in the header, in lower-case.
49
*/
50
AUTF8String parseResponseContentType(in AUTF8String aTypeHeader,
51
out AUTF8String aCharset,
52
out boolean aHadCharset);
53
54
/**
55
* Test whether the given URI's handler has the given protocol flags.
56
*
57
* @param aURI the URI in question
58
* @param aFlags the flags we're testing for.
59
*
60
* @return whether the protocol handler for aURI has all the flags
61
* in aFlags.
62
*/
63
boolean protocolHasFlags(in nsIURI aURI, in unsigned long aFlag);
64
65
/**
66
* Test whether the protocol handler for this URI or that for any of
67
* its inner URIs has the given protocol flags. This will QI aURI to
68
* nsINestedURI and walk the nested URI chain.
69
*
70
* @param aURI the URI in question
71
* @param aFlags the flags we're testing for.
72
*
73
* @return whether any of the protocol handlers involved have all the flags
74
* in aFlags.
75
*/
76
boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags);
77
78
/** Escape every character with its %XX-escaped equivalent */
79
const unsigned long ESCAPE_ALL = 0;
80
81
/** Leave alphanumeric characters intact and %XX-escape all others */
82
const unsigned long ESCAPE_XALPHAS = 1;
83
84
/** Leave alphanumeric characters intact, convert spaces to '+',
85
%XX-escape all others */
86
const unsigned long ESCAPE_XPALPHAS = 2;
87
88
/** Leave alphanumeric characters and forward slashes intact,
89
%XX-escape all others */
90
const unsigned long ESCAPE_URL_PATH = 4;
91
92
/**
93
* escape a string with %00-style escaping
94
*/
95
ACString escapeString(in ACString aString, in unsigned long aEscapeType);
96
97
/** %XX-escape URL scheme */
98
const unsigned long ESCAPE_URL_SCHEME = 1;
99
100
/** %XX-escape username in the URL */
101
const unsigned long ESCAPE_URL_USERNAME = 1 << 1;
102
103
/** %XX-escape password in the URL */
104
const unsigned long ESCAPE_URL_PASSWORD = 1 << 2;
105
106
/** %XX-escape URL host */
107
const unsigned long ESCAPE_URL_HOST = 1 << 3;
108
109
/** %XX-escape URL directory */
110
const unsigned long ESCAPE_URL_DIRECTORY = 1 << 4;
111
112
/** %XX-escape file basename in the URL */
113
const unsigned long ESCAPE_URL_FILE_BASENAME = 1 << 5;
114
115
/** %XX-escape file extension in the URL */
116
const unsigned long ESCAPE_URL_FILE_EXTENSION = 1 << 6;
117
118
/** %XX-escape URL parameters */
119
const unsigned long ESCAPE_URL_PARAM = 1 << 7;
120
121
/** %XX-escape URL query */
122
const unsigned long ESCAPE_URL_QUERY = 1 << 8;
123
124
/** %XX-escape URL ref */
125
const unsigned long ESCAPE_URL_REF = 1 << 9;
126
127
/** %XX-escape URL path - same as escaping directory, basename and extension */
128
const unsigned long ESCAPE_URL_FILEPATH =
129
ESCAPE_URL_DIRECTORY | ESCAPE_URL_FILE_BASENAME | ESCAPE_URL_FILE_EXTENSION;
130
131
/** %XX-escape scheme, username, password, host, path, params, query and ref */
132
const unsigned long ESCAPE_URL_MINIMAL =
133
ESCAPE_URL_SCHEME | ESCAPE_URL_USERNAME | ESCAPE_URL_PASSWORD |
134
ESCAPE_URL_HOST | ESCAPE_URL_FILEPATH | ESCAPE_URL_PARAM |
135
ESCAPE_URL_QUERY | ESCAPE_URL_REF;
136
137
/** Force %XX-escaping of already escaped sequences */
138
const unsigned long ESCAPE_URL_FORCED = 1 << 10;
139
140
/** Skip non-ascii octets, %XX-escape all others */
141
const unsigned long ESCAPE_URL_ONLY_ASCII = 1 << 11;
142
143
/**
144
* Skip graphic octets (0x20-0x7E) when escaping
145
* Skips all ASCII octets (0x00-0x7F) when unescaping
146
*/
147
const unsigned long ESCAPE_URL_ONLY_NONASCII = 1 << 12;
148
149
/** Force %XX-escape of colon */
150
const unsigned long ESCAPE_URL_COLON = 1 << 14;
151
152
/** Skip C0 and DEL from unescaping */
153
const unsigned long ESCAPE_URL_SKIP_CONTROL = 1 << 15;
154
155
/**
156
* %XX-Escape invalid chars in a URL segment.
157
*
158
* @param aStr the URL to be escaped
159
* @param aFlags the URL segment type flags
160
*
161
* @return the escaped string (the string itself if escaping did not happen)
162
*
163
*/
164
ACString escapeURL(in ACString aStr, in unsigned long aFlags);
165
166
/**
167
* Expands URL escape sequences
168
*
169
* @param aStr the URL to be unescaped
170
* @param aFlags only ESCAPE_URL_ONLY_NONASCII and ESCAPE_URL_SKIP_CONTROL
171
* are recognized. If |aFlags| is 0 all escape sequences are
172
* unescaped
173
* @return unescaped string
174
*/
175
ACString unescapeString(in AUTF8String aStr, in unsigned long aFlags);
176
177
/**
178
* Extract the charset parameter location and value from a content-type
179
* header.
180
*
181
* @param aTypeHeader the header string to parse
182
* @param [out] aCharset the charset parameter specified in the
183
* header, if any.
184
* @param [out] aCharsetStart index of the start of the charset parameter
185
* (the ';' separating it from what came before) in aTypeHeader.
186
* If this function returns false, this argument will still be
187
* set, to the index of the location where a new charset should
188
* be inserted.
189
* @param [out] aCharsetEnd index of the end of the charset parameter (the
190
* ';' separating it from what comes after, or the end
191
* of the string) in aTypeHeader. If this function returns
192
* false, this argument will still be set, to the index of the
193
* location where a new charset should be inserted.
194
*
195
* @return whether a charset parameter was found. This can be false even in
196
* cases when parseContentType would claim to have a charset, if the type
197
* that won out does not have a charset parameter specified.
198
*/
199
boolean extractCharsetFromContentType(in AUTF8String aTypeHeader,
200
out AUTF8String aCharset,
201
out long aCharsetStart,
202
out long aCharsetEnd);
203
204
/**
205
* Parse an attribute referrer policy string (no-referrer, origin, unsafe-url)
206
* and return the according integer code (defined in nsIHttpChannel.idl)
207
*
208
* @param aPolicyString
209
* the policy string given as attribute
210
* @return aPolicyEnum
211
* referrer policy code from nsIHttpChannel.idl, (see parser in
212
* ReferrerPolicy.h for details)
213
*/
214
unsigned long parseAttributePolicyString(in AString aPolicyString);
215
216
/**
217
* Convert referrer policy integer code (defined in nsIHttpChannel.idl) to
218
* string.
219
*
220
* @param aPolicy
221
* the policy integer code (defined in nsIHttpChannel.idl)
222
* @return aPolicyString
223
* referrer policy string from code
224
*/
225
ACString getReferrerPolicyString(in unsigned long aPolicy);
226
227
/**
228
* This is test-only. Send an IPC message to let socket process send a
229
* telemetry.
230
*/
231
void socketProcessTelemetryPing();
232
233
/**
234
* This is a void method that is C++ implemented and always
235
* returns NS_ERROR_NOT_IMPLEMENTED. To be used for testing.
236
*/
237
void notImplemented();
238
};