mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-08 12:37:37 +00:00
199 lines
6.7 KiB
Plaintext
199 lines
6.7 KiB
Plaintext
/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
/* ***** BEGIN LICENSE BLOCK *****
|
|
* Version: NPL 1.1/GPL 2.0/LGPL 2.1
|
|
*
|
|
* The contents of this file are subject to the Netscape Public License
|
|
* Version 1.1 (the "License"); you may not use this file except in
|
|
* compliance with the License. You may obtain a copy of the License at
|
|
* http://www.mozilla.org/NPL/
|
|
*
|
|
* Software distributed under the License is distributed on an "AS IS" basis,
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
* for the specific language governing rights and limitations under the
|
|
* License.
|
|
*
|
|
* The Original Code is mozilla.org code.
|
|
*
|
|
* The Initial Developer of the Original Code is
|
|
* Netscape Communications Corporation.
|
|
* Portions created by the Initial Developer are Copyright (C) 1998
|
|
* the Initial Developer. All Rights Reserved.
|
|
*
|
|
* Contributor(s):
|
|
*
|
|
* Alternatively, the contents of this file may be used under the terms of
|
|
* either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
* the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
* in which case the provisions of the GPL or the LGPL are applicable instead
|
|
* of those above. If you wish to allow use of your version of this file only
|
|
* under the terms of either the GPL or the LGPL, and not to allow others to
|
|
* use your version of this file under the terms of the NPL, indicate your
|
|
* decision by deleting the provisions above and replace them with the notice
|
|
* and other provisions required by the GPL or the LGPL. If you do not delete
|
|
* the provisions above, a recipient may use your version of this file under
|
|
* the terms of any one of the NPL, the GPL or the LGPL.
|
|
*
|
|
* ***** END LICENSE BLOCK ***** */
|
|
|
|
#include "nsISupports.idl"
|
|
|
|
interface nsIInputStream;
|
|
interface nsIOutputStream;
|
|
interface nsIURI;
|
|
interface nsIFile;
|
|
|
|
/**
|
|
* nsIStreamIO is an abstract interface that gives access to input and output
|
|
* streams on an object. Perhaps the most interesting subclass of this is
|
|
* nsIFileIO which allows access to input and output streams to files.
|
|
*/
|
|
[scriptable, uuid(d6c01ab2-0d04-11d4-986e-00c04fa0cf4a)]
|
|
interface nsIStreamIO : nsISupports
|
|
{
|
|
/**
|
|
* Logically opens a stream I/O object, returning its content type
|
|
* and length. If either of these are unknown, the value -1 is returned.
|
|
*/
|
|
void open(out string contentType,
|
|
out long contentLength);
|
|
|
|
/**
|
|
* Logically closes a stream I/O object. A status value is passed in
|
|
* to indicate a successful close (NS_OK) or failure.
|
|
*/
|
|
void close(in nsresult status);
|
|
|
|
/**
|
|
* Gets an input stream from a stream I/O object.
|
|
*/
|
|
readonly attribute nsIInputStream inputStream;
|
|
|
|
/**
|
|
* Gets an output stream from a stream I/O object.
|
|
*/
|
|
readonly attribute nsIOutputStream outputStream;
|
|
|
|
/**
|
|
* Returns the 'name' of a stream I/O object. This name is often
|
|
* used for display purposes.
|
|
*/
|
|
readonly attribute string name;
|
|
};
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// nsIFileIO
|
|
|
|
/**
|
|
* nsIFileIO specializes nsIStreamIO to allow initialization from an nsIFile
|
|
* object. For this implementation, the name attribute will correspond to the
|
|
* path to the file.
|
|
*/
|
|
[scriptable, uuid(2a45fb42-0d06-11d4-986e-00c04fa0cf4a)]
|
|
interface nsIFileIO : nsIStreamIO
|
|
{
|
|
void init(in nsIFile file,
|
|
in long ioFlags,
|
|
in long perm);
|
|
|
|
readonly attribute nsIFile file;
|
|
};
|
|
|
|
%{C++
|
|
|
|
#include "nsCOMPtr.h"
|
|
#include "nsIComponentManager.h"
|
|
|
|
#define NS_FILEIO_CLASSNAME "File I/O"
|
|
#define NS_FILEIO_CONTRACTID "@mozilla.org/network/file-io;1"
|
|
|
|
#define NS_FILEIO_CID \
|
|
{ /* 0965ce3e-0d06-11d4-986e-00c04fa0cf4a */ \
|
|
0x0965ce3e, \
|
|
0x0d06, \
|
|
0x11d4, \
|
|
{0x98, 0x6e, 0x00, 0xc0, 0x4f, 0xa0, 0xcf, 0x4a} \
|
|
}
|
|
|
|
inline nsresult
|
|
NS_NewFileIO(nsIFileIO **result,
|
|
nsIFile* file,
|
|
PRInt32 ioFlags = -1,
|
|
PRInt32 perm = -1)
|
|
{
|
|
nsresult rv;
|
|
nsCOMPtr<nsIFileIO> fileIO;
|
|
static NS_DEFINE_CID(kFileIOCID, NS_FILEIO_CID);
|
|
rv = nsComponentManager::CreateInstance(kFileIOCID,
|
|
nsnull,
|
|
NS_GET_IID(nsIFileIO),
|
|
getter_AddRefs(fileIO));
|
|
if (NS_FAILED(rv)) return rv;
|
|
rv = fileIO->Init(file, ioFlags, perm);
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
*result = fileIO;
|
|
NS_ADDREF(*result);
|
|
return NS_OK;
|
|
}
|
|
|
|
%}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|
|
// nsIInputStreamIO
|
|
|
|
/**
|
|
* nsIInputStreamIO specializes nsIStreamIO to allow initialization from an
|
|
* input stream, name, content type and length. Note that attempts to access
|
|
* the output stream of an nsIInputStreamIO will fail. This implementation
|
|
* is provided as a convenience, to avoid the need to implement the complete
|
|
* nsIStreamIO interface, when all you need is the input stream part.
|
|
*/
|
|
[scriptable, uuid(2d64af08-0d06-11d4-986e-00c04fa0cf4a)]
|
|
interface nsIInputStreamIO : nsIStreamIO
|
|
{
|
|
void init(in string name,
|
|
in nsIInputStream input,
|
|
in string contentType,
|
|
in long contentLength);
|
|
};
|
|
|
|
%{C++
|
|
|
|
#define NS_INPUTSTREAMIO_CLASSNAME "Input Stream I/O"
|
|
#define NS_INPUTSTREAMIO_CONTRACTID "@mozilla.org/network/input-stream-io;1"
|
|
|
|
#define NS_INPUTSTREAMIO_CID \
|
|
{ /* 0f5e1198-0d06-11d4-986e-00c04fa0cf4a */ \
|
|
0x0f5e1198, \
|
|
0x0d06, \
|
|
0x11d4, \
|
|
{0x98, 0x6e, 0x00, 0xc0, 0x4f, 0xa0, 0xcf, 0x4a} \
|
|
}
|
|
|
|
inline nsresult
|
|
NS_NewInputStreamIO(nsIInputStreamIO* *result,
|
|
const char* name,
|
|
nsIInputStream* inStr,
|
|
const char* contentType,
|
|
PRInt32 contentLength)
|
|
{
|
|
nsresult rv;
|
|
nsCOMPtr<nsIInputStreamIO> io;
|
|
static NS_DEFINE_CID(kInputStreamIOCID, NS_INPUTSTREAMIO_CID);
|
|
rv = nsComponentManager::CreateInstance(kInputStreamIOCID,
|
|
nsnull,
|
|
NS_GET_IID(nsIInputStreamIO),
|
|
getter_AddRefs(io));
|
|
if (NS_FAILED(rv)) return rv;
|
|
rv = io->Init(name, inStr, contentType, contentLength);
|
|
if (NS_FAILED(rv)) return rv;
|
|
|
|
*result = io;
|
|
NS_ADDREF(*result);
|
|
return NS_OK;
|
|
}
|
|
|
|
%}
|
|
|
|
////////////////////////////////////////////////////////////////////////////////
|