michael@0: /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "nsISupports.idl" michael@0: michael@0: interface nsIURI; michael@0: interface nsIPrefBranch; michael@0: michael@0: /** michael@0: * nsINetUtil provides various network-related utility methods. michael@0: */ michael@0: [scriptable, uuid(ca68c485-9db3-4c12-82a6-4fab7948e2d5)] michael@0: interface nsINetUtil : nsISupports michael@0: { michael@0: /** michael@0: * Parse a content-type header and return the content type and michael@0: * charset (if any). michael@0: * michael@0: * @param aTypeHeader the header string to parse michael@0: * @param [out] aCharset the charset parameter specified in the michael@0: * header, if any. michael@0: * @param [out] aHadCharset whether a charset was explicitly specified. michael@0: * @return the MIME type specified in the header, in lower-case. michael@0: */ michael@0: AUTF8String parseContentType(in AUTF8String aTypeHeader, michael@0: out AUTF8String aCharset, michael@0: out boolean aHadCharset); michael@0: michael@0: /** michael@0: * Test whether the given URI's handler has the given protocol flags. michael@0: * michael@0: * @param aURI the URI in question michael@0: * @param aFlags the flags we're testing for. michael@0: * michael@0: * @return whether the protocol handler for aURI has all the flags michael@0: * in aFlags. michael@0: */ michael@0: boolean protocolHasFlags(in nsIURI aURI, in unsigned long aFlag); michael@0: michael@0: /** michael@0: * Test whether the protocol handler for this URI or that for any of michael@0: * its inner URIs has the given protocol flags. This will QI aURI to michael@0: * nsINestedURI and walk the nested URI chain. michael@0: * michael@0: * @param aURI the URI in question michael@0: * @param aFlags the flags we're testing for. michael@0: * michael@0: * @return whether any of the protocol handlers involved have all the flags michael@0: * in aFlags. michael@0: */ michael@0: boolean URIChainHasFlags(in nsIURI aURI, in unsigned long aFlags); michael@0: michael@0: /** michael@0: * Take aURI and produce an immutable version of it for the caller. If aURI michael@0: * is immutable this will be aURI itself; otherwise this will be a clone, michael@0: * marked immutable if possible. Passing null to this method is allowed; in michael@0: * that case it will return null. michael@0: */ michael@0: nsIURI toImmutableURI(in nsIURI aURI); michael@0: michael@0: /** michael@0: * Create a simple nested URI using the result of michael@0: * toImmutableURI on the passed-in aURI which may not be null. michael@0: * Note: The return URI will not have had its spec set yet. michael@0: */ michael@0: nsIURI newSimpleNestedURI(in nsIURI aURI); michael@0: michael@0: /** Escape every character with its %XX-escaped equivalent */ michael@0: const unsigned long ESCAPE_ALL = 0; michael@0: michael@0: /** Leave alphanumeric characters intact and %XX-escape all others */ michael@0: const unsigned long ESCAPE_XALPHAS = 1; michael@0: michael@0: /** Leave alphanumeric characters intact, convert spaces to '+', michael@0: %XX-escape all others */ michael@0: const unsigned long ESCAPE_XPALPHAS = 2; michael@0: michael@0: /** Leave alphanumeric characters and forward slashes intact, michael@0: %XX-escape all others */ michael@0: const unsigned long ESCAPE_URL_PATH = 4; michael@0: michael@0: /** michael@0: * escape a string with %00-style escaping michael@0: */ michael@0: ACString escapeString(in ACString aString, in unsigned long aEscapeType); michael@0: michael@0: /** %XX-escape URL scheme */ michael@0: const unsigned long ESCAPE_URL_SCHEME = 1; michael@0: michael@0: /** %XX-escape username in the URL */ michael@0: const unsigned long ESCAPE_URL_USERNAME = 1 << 1; michael@0: michael@0: /** %XX-escape password in the URL */ michael@0: const unsigned long ESCAPE_URL_PASSWORD = 1 << 2; michael@0: michael@0: /** %XX-escape URL host */ michael@0: const unsigned long ESCAPE_URL_HOST = 1 << 3; michael@0: michael@0: /** %XX-escape URL directory */ michael@0: const unsigned long ESCAPE_URL_DIRECTORY = 1 << 4; michael@0: michael@0: /** %XX-escape file basename in the URL */ michael@0: const unsigned long ESCAPE_URL_FILE_BASENAME = 1 << 5; michael@0: michael@0: /** %XX-escape file extension in the URL */ michael@0: const unsigned long ESCAPE_URL_FILE_EXTENSION = 1 << 6; michael@0: michael@0: /** %XX-escape URL parameters */ michael@0: const unsigned long ESCAPE_URL_PARAM = 1 << 7; michael@0: michael@0: /** %XX-escape URL query */ michael@0: const unsigned long ESCAPE_URL_QUERY = 1 << 8; michael@0: michael@0: /** %XX-escape URL ref */ michael@0: const unsigned long ESCAPE_URL_REF = 1 << 9; michael@0: michael@0: /** %XX-escape URL path - same as escaping directory, basename and extension */ michael@0: const unsigned long ESCAPE_URL_FILEPATH = michael@0: ESCAPE_URL_DIRECTORY | ESCAPE_URL_FILE_BASENAME | ESCAPE_URL_FILE_EXTENSION; michael@0: michael@0: /** %XX-escape scheme, username, password, host, path, params, query and ref */ michael@0: const unsigned long ESCAPE_URL_MINIMAL = michael@0: ESCAPE_URL_SCHEME | ESCAPE_URL_USERNAME | ESCAPE_URL_PASSWORD | michael@0: ESCAPE_URL_HOST | ESCAPE_URL_FILEPATH | ESCAPE_URL_PARAM | michael@0: ESCAPE_URL_QUERY | ESCAPE_URL_REF; michael@0: michael@0: /** Force %XX-escaping of already escaped sequences */ michael@0: const unsigned long ESCAPE_URL_FORCED = 1 << 10; michael@0: michael@0: /** Skip non-ascii octets, %XX-escape all others */ michael@0: const unsigned long ESCAPE_URL_ONLY_ASCII = 1 << 11; michael@0: michael@0: /** michael@0: * Skip graphic octets (0x20-0x7E) when escaping michael@0: * Skips all ASCII octets (0x00-0x7F) when unescaping michael@0: */ michael@0: const unsigned long ESCAPE_URL_ONLY_NONASCII = 1 << 12; michael@0: michael@0: /** Force %XX-escape of colon */ michael@0: const unsigned long ESCAPE_URL_COLON = 1 << 14; michael@0: michael@0: /** Skip C0 and DEL from unescaping */ michael@0: const unsigned long ESCAPE_URL_SKIP_CONTROL = 1 << 15; michael@0: michael@0: /** michael@0: * %XX-Escape invalid chars in a URL segment. michael@0: * michael@0: * @param aStr the URL to be escaped michael@0: * @param aFlags the URL segment type flags michael@0: * michael@0: * @return the escaped string (the string itself if escaping did not happen) michael@0: * michael@0: */ michael@0: ACString escapeURL(in ACString aStr, in unsigned long aFlags); michael@0: michael@0: /** michael@0: * Expands URL escape sequences michael@0: * michael@0: * @param aStr the URL to be unescaped michael@0: * @param aFlags only ESCAPE_URL_ONLY_NONASCII and ESCAPE_URL_SKIP_CONTROL michael@0: * are recognized. If |aFlags| is 0 all escape sequences are michael@0: * unescaped michael@0: * @return unescaped string michael@0: */ michael@0: ACString unescapeString(in AUTF8String aStr, in unsigned long aFlags); michael@0: michael@0: /** michael@0: * Extract the charset parameter location and value from a content-type michael@0: * header. michael@0: * michael@0: * @param aTypeHeader the header string to parse michael@0: * @param [out] aCharset the charset parameter specified in the michael@0: * header, if any. michael@0: * @param [out] aCharsetStart index of the start of the charset parameter michael@0: * (the ';' separating it from what came before) in aTypeHeader. michael@0: * If this function returns false, this argument will still be michael@0: * set, to the index of the location where a new charset should michael@0: * be inserted. michael@0: * @param [out] aCharsetEnd index of the end of the charset parameter (the michael@0: * ';' separating it from what comes after, or the end michael@0: * of the string) in aTypeHeader. If this function returns michael@0: * false, this argument will still be set, to the index of the michael@0: * location where a new charset should be inserted. michael@0: * michael@0: * @return whether a charset parameter was found. This can be false even in michael@0: * cases when parseContentType would claim to have a charset, if the type michael@0: * that won out does not have a charset parameter specified. michael@0: */ michael@0: boolean extractCharsetFromContentType(in AUTF8String aTypeHeader, michael@0: out AUTF8String aCharset, michael@0: out long aCharsetStart, michael@0: out long aCharsetEnd); michael@0: };