1999-01-25 22:10:04 +03:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
|
|
|
*
|
|
|
|
* The contents of this file are subject to the Netscape Public License
|
|
|
|
* Version 1.0 (the "NPL"); you may not use this file except in
|
|
|
|
* compliance with the NPL. You may obtain a copy of the NPL at
|
|
|
|
* http://www.mozilla.org/NPL/
|
|
|
|
*
|
|
|
|
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
|
|
|
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
|
|
|
* for the specific language governing rights and limitations under the
|
|
|
|
* NPL.
|
|
|
|
*
|
|
|
|
* The Initial Developer of this code under the NPL is Netscape
|
|
|
|
* Communications Corporation. Portions created by Netscape are
|
|
|
|
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
|
|
|
* Reserved.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef nsSocketTransport_h__
|
|
|
|
#define nsSocketTransport_h__
|
|
|
|
|
1999-03-09 12:44:27 +03:00
|
|
|
#include "nsIComponentManager.h"
|
1999-01-25 22:10:04 +03:00
|
|
|
#include "nsITransport.h"
|
|
|
|
#include "nsIStreamListener.h"
|
|
|
|
#include "nsIInputStream.h"
|
|
|
|
#include "nsIOutputStream.h"
|
|
|
|
#include "nsIEventQueueService.h"
|
|
|
|
#include "nsAgg.h"
|
|
|
|
#include "nsString.h"
|
|
|
|
|
|
|
|
#define NET_SOCKSTUB_BUF_SIZE 1024
|
|
|
|
|
|
|
|
/* forward declaration */
|
|
|
|
struct URL_Struct_;
|
|
|
|
|
|
|
|
class nsSocketTransport : public nsITransport
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsISupports:
|
|
|
|
|
|
|
|
NS_DECL_ISUPPORTS
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsITransport:
|
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD GetURL(nsIURI* *result);
|
1999-01-25 22:10:04 +03:00
|
|
|
|
|
|
|
NS_IMETHOD SetInputStreamConsumer(nsIStreamListener* aListener);
|
|
|
|
|
|
|
|
NS_IMETHOD GetOutputStreamConsumer(nsIStreamListener ** aConsumer);
|
|
|
|
|
|
|
|
NS_IMETHOD GetOutputStream(nsIOutputStream ** aOutputStream);
|
|
|
|
|
1999-02-05 02:50:37 +03:00
|
|
|
NS_IMETHOD IsTransportOpen(PRBool * aSocketOpen);
|
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD Open(nsIURI * aUrl);
|
1999-01-25 22:10:04 +03:00
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// from nsIStreamListener:
|
|
|
|
|
1999-07-01 23:30:20 +04:00
|
|
|
NS_IMETHOD OnStartRequest(nsIURI* aURL, const char *aContentType);
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD OnProgress(nsIURI* aURL, PRUint32 aProgress, PRUint32 aProgressMax);
|
|
|
|
NS_IMETHOD OnStatus(nsIURI* aURL, const PRUnichar* aMsg);
|
1999-07-01 23:30:20 +04:00
|
|
|
NS_IMETHOD OnStopRequest(nsIURI* aURL, nsresult aStatus, const PRUnichar* aMsg);
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD GetBindInfo(nsIURI* aURL, nsStreamBindingInfo* aInfo);
|
|
|
|
NS_IMETHOD OnDataAvailable(nsIURI* aURL, nsIInputStream *aIStream,
|
1999-01-25 22:10:04 +03:00
|
|
|
PRUint32 aLength);
|
|
|
|
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////////////
|
|
|
|
// nsSocketTransport:
|
|
|
|
|
1999-02-11 05:56:58 +03:00
|
|
|
// we have two types of connections: socket and file based....
|
1999-01-25 22:10:04 +03:00
|
|
|
nsSocketTransport(PRUint32 aPortToUse, const char * aHostName);
|
1999-02-11 05:56:58 +03:00
|
|
|
nsSocketTransport(const char * fileName);
|
|
|
|
|
1999-01-25 22:10:04 +03:00
|
|
|
virtual ~nsSocketTransport(void);
|
1999-06-23 07:29:44 +04:00
|
|
|
NS_IMETHOD GetURLInfo(nsIURI* pURL, URL_Struct_ **aResult);
|
|
|
|
NS_IMETHOD SetSocketBinding(nsIURI* pURL, URL_Struct_ ** aResult);
|
1999-01-25 22:10:04 +03:00
|
|
|
|
|
|
|
// the following routines are called by the sock stub protocol hack....
|
|
|
|
// we should be able to remove this dependency once we move things to the new
|
|
|
|
// net lib world...
|
|
|
|
PRUint32 GetPort() {return m_port;}
|
|
|
|
const char * GetHostName() { return m_hostName;}
|
1999-02-11 05:56:58 +03:00
|
|
|
const char * GetFileName() { return m_fileName;}
|
1999-01-25 22:10:04 +03:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
1999-02-05 02:50:37 +03:00
|
|
|
// use this function to close the underlying connection....
|
|
|
|
nsresult CloseCurrentConnection();
|
1999-02-11 05:56:58 +03:00
|
|
|
// common initialization code..
|
|
|
|
void Initialize();
|
1999-02-05 02:50:37 +03:00
|
|
|
|
1999-01-25 22:10:04 +03:00
|
|
|
// socket specific information...
|
|
|
|
PRUint32 m_port;
|
|
|
|
char *m_hostName;
|
1999-02-11 05:56:58 +03:00
|
|
|
char *m_fileName;
|
1999-02-05 02:50:37 +03:00
|
|
|
PRBool m_socketIsOpen; // set when we have opened a socket....
|
1999-02-11 05:56:58 +03:00
|
|
|
PRBool m_isFileConnection;
|
1999-01-25 22:10:04 +03:00
|
|
|
|
|
|
|
// the stream we write data from the socket into
|
|
|
|
nsIInputStream * m_inputStream;
|
|
|
|
|
|
|
|
// XXX sock stub hack..need to remember stream with data to be written to the socket
|
|
|
|
nsIInputStream * m_outStream;
|
|
|
|
PRUint32 m_outStreamSize;
|
|
|
|
|
|
|
|
// the proxied stream listener. Whenever the transport layer
|
|
|
|
// writes socket date to input stream, it calls OnDataAvailable
|
|
|
|
// through the inputStreamConsumer any socket specific data
|
|
|
|
nsIStreamListener *m_inputStreamConsumer;
|
|
|
|
|
1999-06-23 07:29:44 +04:00
|
|
|
nsIURI *m_url; // the url we are currently running...
|
1999-01-25 22:10:04 +03:00
|
|
|
nsString* mData;
|
|
|
|
PRFileDesc *m_ready_fd;
|
|
|
|
nsIEventQueueService* mEventQService;
|
1999-05-05 03:31:26 +04:00
|
|
|
nsIEventQueue* m_evQueue;
|
1999-01-25 22:10:04 +03:00
|
|
|
char m_buffer[NET_SOCKSTUB_BUF_SIZE];
|
1999-05-14 02:55:44 +04:00
|
|
|
|
|
|
|
URL_Struct_ * m_bindedUrlStruct;
|
1999-01-25 22:10:04 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // nsSocketTransport_h__
|