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: /** michael@0: * URIs are essentially structured names for things -- anything. This interface michael@0: * provides accessors to set and query the most basic components of an URI. michael@0: * Subclasses, including nsIURL, impose greater structure on the URI. michael@0: * michael@0: * This interface follows Tim Berners-Lee's URI spec (RFC2396) [1], where the michael@0: * basic URI components are defined as such: michael@0: *
michael@0: * ftp://username:password@hostname:portnumber/pathname#ref michael@0: * \ / \ / \ / \ /\ \ / michael@0: * - --------------- ------ -------- | - michael@0: * | | | | | | michael@0: * | | | | | Ref michael@0: * | | | Port \ / michael@0: * | | Host / -------- michael@0: * | UserPass / | michael@0: * Scheme / Path michael@0: * \ / michael@0: * -------------------------------- michael@0: * | michael@0: * PrePath michael@0: *michael@0: * The definition of the URI components has been extended to allow for michael@0: * internationalized domain names [2] and the more generic IRI structure [3]. michael@0: * michael@0: * Note also that the RFC defines #-separated fragment identifiers as being michael@0: * "not part of the URI". Despite this, we bundle them as part of the URI, for michael@0: * convenience. michael@0: * michael@0: * [1] http://www.ietf.org/rfc/rfc2396.txt michael@0: * [2] http://www.ietf.org/internet-drafts/draft-ietf-idn-idna-06.txt michael@0: * [3] http://www.ietf.org/internet-drafts/draft-masinter-url-i18n-08.txt michael@0: */ michael@0: michael@0: %{C++ michael@0: #undef GetPort // XXX Windows! michael@0: #undef SetPort // XXX Windows! michael@0: %} michael@0: michael@0: /** michael@0: * nsIURI - interface for an uniform resource identifier w/ i18n support. michael@0: * michael@0: * AUTF8String attributes may contain unescaped UTF-8 characters. michael@0: * Consumers should be careful to escape the UTF-8 strings as necessary, but michael@0: * should always try to "display" the UTF-8 version as provided by this michael@0: * interface. michael@0: * michael@0: * AUTF8String attributes may also contain escaped characters. michael@0: * michael@0: * Unescaping URI segments is unadvised unless there is intimate michael@0: * knowledge of the underlying charset or there is no plan to display (or michael@0: * otherwise enforce a charset on) the resulting URI substring. michael@0: * michael@0: * The correct way to create an nsIURI from a string is via michael@0: * nsIIOService.newURI. michael@0: * michael@0: * NOTE: nsBinaryInputStream::ReadObject contains a hackaround to intercept the michael@0: * old (pre-gecko6) nsIURI IID and swap in the current IID instead, in order michael@0: * for sessionstore to work after an upgrade. If this IID is revved further, michael@0: * we will need to add additional checks there for all intermediate IIDs, until michael@0: * nsPrincipal is fixed to serialize its URIs as nsISupports (bug 662693). michael@0: */ michael@0: [scriptable, uuid(395fe045-7d18-4adb-a3fd-af98c8a1af11)] michael@0: interface nsIURI : nsISupports michael@0: { michael@0: /************************************************************************ michael@0: * The URI is broken down into the following principal components: michael@0: */ michael@0: michael@0: /** michael@0: * Returns a string representation of the URI. Setting the spec causes michael@0: * the new spec to be parsed per the rules for the scheme the URI michael@0: * currently has. In particular, setting the spec to a URI string with a michael@0: * different scheme will generally produce incorrect results; no one michael@0: * outside of a protocol handler implementation should be doing that. If michael@0: * the URI stores information from the nsIIOService.newURI call used to michael@0: * create it other than just the parsed string, then behavior of this michael@0: * information on setting the spec attribute is undefined. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String spec; michael@0: michael@0: /** michael@0: * The prePath (eg. scheme://user:password@host:port) returns the string michael@0: * before the path. This is useful for authentication or managing sessions. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: readonly attribute AUTF8String prePath; michael@0: michael@0: /** michael@0: * The Scheme is the protocol to which this URI refers. The scheme is michael@0: * restricted to the US-ASCII charset per RFC2396. Setting this is michael@0: * highly discouraged outside of a protocol handler implementation, since michael@0: * that will generally lead to incorrect results. michael@0: */ michael@0: attribute ACString scheme; michael@0: michael@0: /** michael@0: * The username:password (or username only if value doesn't contain a ':') michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String userPass; michael@0: michael@0: /** michael@0: * The optional username and password, assuming the preHost consists of michael@0: * username:password. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String username; michael@0: attribute AUTF8String password; michael@0: michael@0: /** michael@0: * The host:port (or simply the host, if port == -1). michael@0: * michael@0: * Characters are NOT escaped. michael@0: */ michael@0: attribute AUTF8String hostPort; michael@0: michael@0: /** michael@0: * The host is the internet domain name to which this URI refers. It could michael@0: * be an IPv4 (or IPv6) address literal. If supported, it could be a michael@0: * non-ASCII internationalized domain name. michael@0: * michael@0: * Characters are NOT escaped. michael@0: */ michael@0: attribute AUTF8String host; michael@0: michael@0: /** michael@0: * A port value of -1 corresponds to the protocol's default port (eg. -1 michael@0: * implies port 80 for http URIs). michael@0: */ michael@0: attribute long port; michael@0: michael@0: /** michael@0: * The path, typically including at least a leading '/' (but may also be michael@0: * empty, depending on the protocol). michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String path; michael@0: michael@0: michael@0: /************************************************************************ michael@0: * An URI supports the following methods: michael@0: */ michael@0: michael@0: /** michael@0: * URI equivalence test (not a strict string comparison). michael@0: * michael@0: * eg. http://foo.com:80/ == http://foo.com/ michael@0: */ michael@0: boolean equals(in nsIURI other); michael@0: michael@0: /** michael@0: * An optimization to do scheme checks without requiring the users of nsIURI michael@0: * to GetScheme, thereby saving extra allocating and freeing. Returns true if michael@0: * the schemes match (case ignored). michael@0: */ michael@0: boolean schemeIs(in string scheme); michael@0: michael@0: /** michael@0: * Clones the current URI. michael@0: */ michael@0: nsIURI clone(); michael@0: michael@0: /** michael@0: * This method resolves a relative string into an absolute URI string, michael@0: * using this URI as the base. michael@0: * michael@0: * NOTE: some implementations may have no concept of a relative URI. michael@0: */ michael@0: AUTF8String resolve(in AUTF8String relativePath); michael@0: michael@0: michael@0: /************************************************************************ michael@0: * Additional attributes: michael@0: */ michael@0: michael@0: /** michael@0: * The URI spec with an ASCII compatible encoding. Host portion follows michael@0: * the IDNA draft spec. Other parts are URL-escaped per the rules of michael@0: * RFC2396. The result is strictly ASCII. michael@0: */ michael@0: readonly attribute ACString asciiSpec; michael@0: michael@0: /** michael@0: * The URI host with an ASCII compatible encoding. Follows the IDNA michael@0: * draft spec for converting internationalized domain names (UTF-8) to michael@0: * ASCII for compatibility with existing internet infrasture. michael@0: */ michael@0: readonly attribute ACString asciiHost; michael@0: michael@0: /** michael@0: * The charset of the document from which this URI originated. An empty michael@0: * value implies UTF-8. michael@0: * michael@0: * If this value is something other than UTF-8 then the URI components michael@0: * (e.g., spec, prePath, username, etc.) will all be fully URL-escaped. michael@0: * Otherwise, the URI components may contain unescaped multibyte UTF-8 michael@0: * characters. michael@0: */ michael@0: readonly attribute ACString originCharset; michael@0: michael@0: /************************************************************************ michael@0: * Additional attribute & methods added for .ref support: michael@0: */ michael@0: michael@0: /** michael@0: * Returns the reference portion (the part after the "#") of the URI. michael@0: * If there isn't one, an empty string is returned. michael@0: * michael@0: * Some characters may be escaped. michael@0: */ michael@0: attribute AUTF8String ref; michael@0: michael@0: /** michael@0: * URI equivalence test (not a strict string comparison), ignoring michael@0: * the value of the .ref member. michael@0: * michael@0: * eg. http://foo.com/# == http://foo.com/ michael@0: * http://foo.com/#aaa == http://foo.com/#bbb michael@0: */ michael@0: boolean equalsExceptRef(in nsIURI other); michael@0: michael@0: /** michael@0: * Clones the current URI, clearing the 'ref' attribute in the clone. michael@0: */ michael@0: nsIURI cloneIgnoringRef(); michael@0: michael@0: /** michael@0: * returns a string for the current URI with the ref element cleared. michael@0: */ michael@0: readonly attribute AUTF8String specIgnoringRef; michael@0: michael@0: /** michael@0: * Returns if there is a reference portion (the part after the "#") of the URI. michael@0: */ michael@0: readonly attribute boolean hasRef; michael@0: };