michael@0: /* vim:set ts=4 sw=4 et cindent: */ 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 nsIFile; michael@0: interface nsIServerSocketListener; michael@0: interface nsISocketTransport; michael@0: michael@0: native PRNetAddr(union PRNetAddr); michael@0: [ptr] native PRNetAddrPtr(union PRNetAddr); michael@0: michael@0: typedef unsigned long nsServerSocketFlag; michael@0: michael@0: /** michael@0: * nsIServerSocket michael@0: * michael@0: * An interface to a server socket that can accept incoming connections. michael@0: */ michael@0: [scriptable, uuid(7a9c39cb-a13f-4eef-9bdf-a74301628742)] michael@0: interface nsIServerSocket : nsISupports michael@0: { michael@0: /** michael@0: * @name Server Socket Flags michael@0: * These flags define various socket options. michael@0: * @{ michael@0: */ michael@0: /// The server socket will only respond to connections on the michael@0: /// local loopback interface. Otherwise, it will accept connections michael@0: /// from any interface. To specify a particular network interface, michael@0: /// use initWithAddress. michael@0: const nsServerSocketFlag LoopbackOnly = 0x00000001; michael@0: /// The server socket will not be closed when Gecko is set michael@0: /// offline. michael@0: const nsServerSocketFlag KeepWhenOffline = 0x00000002; michael@0: /** @} */ michael@0: michael@0: /** michael@0: * init michael@0: * michael@0: * This method initializes a server socket. michael@0: * michael@0: * @param aPort michael@0: * The port of the server socket. Pass -1 to indicate no preference, michael@0: * and a port will be selected automatically. michael@0: * @param aLoopbackOnly michael@0: * If true, the server socket will only respond to connections on the michael@0: * local loopback interface. Otherwise, it will accept connections michael@0: * from any interface. To specify a particular network interface, michael@0: * use initWithAddress. michael@0: * @param aBackLog michael@0: * The maximum length the queue of pending connections may grow to. michael@0: * This parameter may be silently limited by the operating system. michael@0: * Pass -1 to use the default value. michael@0: */ michael@0: void init(in long aPort, michael@0: in boolean aLoopbackOnly, michael@0: in long aBackLog); michael@0: michael@0: /** michael@0: * initSpecialConnection michael@0: * michael@0: * This method initializes a server socket and offers the ability to have michael@0: * that socket not get terminated if Gecko is set offline. michael@0: * michael@0: * @param aPort michael@0: * The port of the server socket. Pass -1 to indicate no preference, michael@0: * and a port will be selected automatically. michael@0: * @param aFlags michael@0: * Flags for the socket. michael@0: * @param aBackLog michael@0: * The maximum length the queue of pending connections may grow to. michael@0: * This parameter may be silently limited by the operating system. michael@0: * Pass -1 to use the default value. michael@0: */ michael@0: void initSpecialConnection(in long aPort, michael@0: in nsServerSocketFlag aFlags, michael@0: in long aBackLog); michael@0: michael@0: michael@0: /** michael@0: * initWithAddress michael@0: * michael@0: * This method initializes a server socket, and binds it to a particular michael@0: * local address (and hence a particular local network interface). michael@0: * michael@0: * @param aAddr michael@0: * The address to which this server socket should be bound. michael@0: * @param aBackLog michael@0: * The maximum length the queue of pending connections may grow to. michael@0: * This parameter may be silently limited by the operating system. michael@0: * Pass -1 to use the default value. michael@0: */ michael@0: [noscript] void initWithAddress([const] in PRNetAddrPtr aAddr, in long aBackLog); michael@0: michael@0: /** michael@0: * initWithFilename michael@0: * michael@0: * This method initializes a Unix domain or "local" server socket. Such michael@0: * a socket has a name in the filesystem, like an ordinary file. To michael@0: * connect, a client supplies the socket's filename, and the usual michael@0: * permission checks on socket apply. michael@0: * michael@0: * This makes Unix domain sockets useful for communication between the michael@0: * programs being run by a specific user on a single machine: the michael@0: * operating system takes care of authentication, and the user's home michael@0: * directory or profile directory provide natural per-user rendezvous michael@0: * points. michael@0: * michael@0: * Since Unix domain sockets are always local to the machine, they are michael@0: * not affected by the nsIIOService's 'offline' flag. michael@0: * michael@0: * The system-level socket API may impose restrictions on the length of michael@0: * the filename that are stricter than those of the underlying michael@0: * filesystem. If the file name is too long, this returns michael@0: * NS_ERROR_FILE_NAME_TOO_LONG. michael@0: * michael@0: * All components of the path prefix of |aPath| must name directories; michael@0: * otherwise, this returns NS_ERROR_FILE_NOT_DIRECTORY. michael@0: * michael@0: * This call requires execute permission on all directories containing michael@0: * the one in which the socket is to be created, and write and execute michael@0: * permission on the directory itself. Otherwise, this returns michael@0: * NS_ERROR_CONNECTION_REFUSED. michael@0: * michael@0: * This call creates the socket's directory entry. There must not be michael@0: * any existing entry with the given name. If there is, this returns michael@0: * NS_ERROR_SOCKET_ADDRESS_IN_USE. michael@0: * michael@0: * On systems that don't support Unix domain sockets at all, this michael@0: * returns NS_ERROR_SOCKET_ADDRESS_NOT_SUPPORTED. michael@0: * michael@0: * @param aPath nsIFile michael@0: * The file name at which the socket should be created. michael@0: * michael@0: * @param aPermissions unsigned long michael@0: * Unix-style permission bits to be applied to the new socket. michael@0: * michael@0: * Note about permissions: Linux's unix(7) man page claims that some michael@0: * BSD-derived systems ignore permissions on UNIX-domain sockets; michael@0: * NetBSD's bind(2) man page agrees, but says it does check now (dated michael@0: * 2005). POSIX has required 'connect' to fail if write permission on michael@0: * the socket itself is not granted since 2003 (Issue 6). NetBSD says michael@0: * that the permissions on the containing directory (execute) have michael@0: * always applied, so creating sockets in appropriately protected michael@0: * directories should be secure on both old and new systems. michael@0: */ michael@0: void initWithFilename(in nsIFile aPath, in unsigned long aPermissions, michael@0: in long aBacklog); michael@0: michael@0: /** michael@0: * close michael@0: * michael@0: * This method closes a server socket. This does not affect already michael@0: * connected client sockets (i.e., the nsISocketTransport instances michael@0: * created from this server socket). This will cause the onStopListening michael@0: * event to asynchronously fire with a status of NS_BINDING_ABORTED. michael@0: */ michael@0: void close(); michael@0: michael@0: /** michael@0: * asyncListen michael@0: * michael@0: * This method puts the server socket in the listening state. It will michael@0: * asynchronously listen for and accept client connections. The listener michael@0: * will be notified once for each client connection that is accepted. The michael@0: * listener's onSocketAccepted method will be called on the same thread michael@0: * that called asyncListen (the calling thread must have a nsIEventTarget). michael@0: * michael@0: * The listener will be passed a reference to an already connected socket michael@0: * transport (nsISocketTransport). See below for more details. michael@0: * michael@0: * @param aListener michael@0: * The listener to be notified when client connections are accepted. michael@0: */ michael@0: void asyncListen(in nsIServerSocketListener aListener); michael@0: michael@0: /** michael@0: * Returns the port of this server socket. michael@0: */ michael@0: readonly attribute long port; michael@0: michael@0: /** michael@0: * Returns the address to which this server socket is bound. Since a michael@0: * server socket may be bound to multiple network devices, this address michael@0: * may not necessarily be specific to a single network device. In the michael@0: * case of an IP socket, the IP address field would be zerod out to michael@0: * indicate a server socket bound to all network devices. Therefore, michael@0: * this method cannot be used to determine the IP address of the local michael@0: * system. See nsIDNSService::myHostName if this is what you need. michael@0: */ michael@0: [noscript] PRNetAddr getAddress(); michael@0: }; michael@0: michael@0: /** michael@0: * nsIServerSocketListener michael@0: * michael@0: * This interface is notified whenever a server socket accepts a new connection. michael@0: * The transport is in the connected state, and read/write streams can be opened michael@0: * using the normal nsITransport API. The address of the client can be found by michael@0: * calling the nsISocketTransport::GetAddress method or by inspecting michael@0: * nsISocketTransport::GetHost, which returns a string representation of the michael@0: * client's IP address (NOTE: this may be an IPv4 or IPv6 string literal). michael@0: */ michael@0: [scriptable, uuid(836d98ec-fee2-4bde-b609-abd5e966eabd)] michael@0: interface nsIServerSocketListener : nsISupports michael@0: { michael@0: /** michael@0: * onSocketAccepted michael@0: * michael@0: * This method is called when a client connection is accepted. michael@0: * michael@0: * @param aServ michael@0: * The server socket. michael@0: * @param aTransport michael@0: * The connected socket transport. michael@0: */ michael@0: void onSocketAccepted(in nsIServerSocket aServ, michael@0: in nsISocketTransport aTransport); michael@0: michael@0: /** michael@0: * onStopListening michael@0: * michael@0: * This method is called when the listening socket stops for some reason. michael@0: * The server socket is effectively dead after this notification. michael@0: * michael@0: * @param aServ michael@0: * The server socket. michael@0: * @param aStatus michael@0: * The reason why the server socket stopped listening. If the michael@0: * server socket was manually closed, then this value will be michael@0: * NS_BINDING_ABORTED. michael@0: */ michael@0: void onStopListening(in nsIServerSocket aServ, in nsresult aStatus); michael@0: };