added pr logging to ftp

git-svn-id: svn://10.0.0.236/trunk@44346 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
valeski%netscape.com
1999-08-24 21:46:09 +00:00
parent 86195ee6ba
commit fa6574def4
4 changed files with 189 additions and 23 deletions

View File

@@ -38,6 +38,11 @@ static NS_DEFINE_CID(kIOServiceCID, NS_IOSERVICE_CID);
#include "prprf.h" // PR_sscanf
#if defined(PR_LOGGING)
extern PRLogModuleInfo* gFTPLog;
#endif /* PR_LOGGING */
static NS_DEFINE_CID(kEventQueueService, NS_EVENTQUEUESERVICE_CID);
// There are actually two transport connections established for an
@@ -108,9 +113,11 @@ nsFTPChannel::Init(const char* verb, nsIURI* uri, nsIEventSinkGetter* getter)
nsIProgressEventSink* eventSink;
rv = getter->GetEventSink(verb, nsCOMTypeInfo<nsIProgressEventSink>::GetIID(),
(nsISupports**)&eventSink);
//if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::Init() (couldn't find event sink)\n"));
}
// XXX event sinks are optional in ftp
// XXX event sinks are optional (for now) in ftp
if (eventSink) {
mEventSink = eventSink;
NS_ADDREF(mEventSink);
@@ -182,6 +189,8 @@ nsFTPChannel::OpenInputStream(PRUint32 startPosition, PRInt32 readCount,
// data down the output stream end of a pipe.
nsresult rv;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::OpenInputStream() called\n"));
NS_WITH_SERVICE(nsIIOService, serv, kIOServiceCID, &rv);
if (NS_FAILED(rv)) return rv;
@@ -233,6 +242,7 @@ nsFTPChannel::AsyncRead(PRUint32 startPosition, PRInt32 readCount,
{
nsresult rv;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::AsyncRead() called\n"));
///////////////////////////
//// setup channel state
@@ -319,6 +329,8 @@ NS_IMETHODIMP
nsFTPChannel::GetContentType(char* *aContentType) {
nsresult rv = NS_OK;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::GetContentType()\n"));
// Parameter validation...
if (!aContentType) {
return NS_ERROR_NULL_POINTER;
@@ -330,6 +342,7 @@ nsFTPChannel::GetContentType(char* *aContentType) {
if (!*aContentType) {
rv = NS_ERROR_OUT_OF_MEMORY;
}
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::NewChannel() returned %s\n", *aContentType));
return rv;
}
@@ -337,7 +350,8 @@ nsFTPChannel::GetContentType(char* *aContentType) {
if (NS_SUCCEEDED(rv)) {
rv = MIMEService->GetTypeFromURI(mUrl, aContentType);
if (NS_SUCCEEDED(rv)) {
mContentType = *aContentType;
mContentType = *aContentType;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::NewChannel() returned %s\n", *aContentType));
return rv;
}
}
@@ -351,6 +365,8 @@ nsFTPChannel::GetContentType(char* *aContentType) {
rv = NS_OK;
}
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::NewChannel() returned %s\n", *aContentType));
return rv;
}
@@ -416,6 +432,7 @@ nsFTPChannel::SetStreamListener(nsIStreamListener *aListener) {
NS_IMETHODIMP
nsFTPChannel::OnStartRequest(nsIChannel* channel, nsISupports* context) {
nsresult rv = NS_OK;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::OnStartRequest(channel = %x, context = %x)\n", channel, context));
if (mListener) {
rv = mListener->OnStartRequest(channel, context);
}
@@ -427,6 +444,7 @@ nsFTPChannel::OnStopRequest(nsIChannel* channel, nsISupports* context,
nsresult aStatus,
const PRUnichar* aMsg) {
nsresult rv = NS_OK;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::OnStopRequest(channel = %x, context = %x, status = %d, msg = N/A)\n",channel, context, aStatus));
if (mListener) {
rv = mListener->OnStopRequest(channel, context, aStatus, aMsg);
}
@@ -443,6 +461,8 @@ nsFTPChannel::OnDataAvailable(nsIChannel* channel, nsISupports* context,
PRUint32 aLength) {
nsresult rv = NS_OK;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFTPChannel::OnDataAvailable(channel = %x, context = %x, stream = %x, srcOffset = %d, length = %d)\n", channel, context, aIStream, aSourceOffset, aLength));
nsIFTPContext *ftpCtxt = nsnull;
rv = context->QueryInterface(nsCOMTypeInfo<nsIFTPContext>::GetIID(), (void**)&ftpCtxt);
if (NS_FAILED(rv)) return rv;

View File

@@ -36,6 +36,11 @@ static NS_DEFINE_CID(kEventQueueServiceCID, NS_EVENTQUEUESERVICE_CID);
#define FTP_CRLF "\r\n"
#if defined(PR_LOGGING)
extern PRLogModuleInfo* gFTPLog;
#endif /* PR_LOGGING */
#include "prprf.h"
#include "netCore.h"
#include "ftpCore.h"
@@ -118,6 +123,7 @@ nsFtpConnectionThread::nsFtpConnectionThread(nsIEventQueue* aEventQ, nsIStreamLi
NS_ADDREF(channel);
mContext = context;
NS_IF_ADDREF(context);
mDPipe = nsnull;
mCBufInStream = nsnull;
@@ -131,19 +137,14 @@ nsFtpConnectionThread::~nsFtpConnectionThread() {
NS_IF_RELEASE(mContext);
NS_IF_RELEASE(mEventQueue);
// Close the data channel
NS_IF_RELEASE(mDPipe);
// Close the command channel
NS_RELEASE(mCPipe);
// lose the socket transport
NS_RELEASE(mSTS);
nsAllocator::Free(mURLSpec);
}
nsresult
nsFtpConnectionThread::Process() {
nsresult rv;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFtpConnectionThread::Process() started for %x (spec =%s)\n", mUrl, mURLSpec));
while (mKeepRunning) {
@@ -157,8 +158,12 @@ nsFtpConnectionThread::Process() {
char buffer[NS_FTP_BUFFER_READ_SIZE];
PRUint32 read;
rv = mCInStream->Read(buffer, NS_FTP_BUFFER_READ_SIZE, &read);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - READ_BUF - Read() FAILED\n", mUrl));
return rv;
}
buffer[read] = '\0';
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - READ_BUF - read \"%s\" (%d bytes)\n", mUrl, buffer, read));
// get the response code out.
PR_sscanf(buffer, "%d", &mResponseCode);
@@ -214,6 +219,7 @@ nsFtpConnectionThread::Process() {
{
// We have error'd out. Stop binding and pass the error back to the user.
PRUnichar* errorMsg = nsnull;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - ERROR\n", mUrl));
nsFtpOnStopRequestEvent* event =
new nsFtpOnStopRequestEvent(mListener, mChannel, mContext);
if (!event)
@@ -237,6 +243,10 @@ nsFtpConnectionThread::Process() {
return rv;
}
// we're done reading and writing, close the streams.
mCOutStream->Close();
mCInStream->Close();
// after notifying the user of the error, stop processing.
mKeepRunning = PR_FALSE;
break;
@@ -245,6 +255,7 @@ nsFtpConnectionThread::Process() {
case FTP_COMPLETE:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - COMPLETE\n",mUrl));
nsFtpOnStopRequestEvent* event =
new nsFtpOnStopRequestEvent(mListener, mChannel, mContext);
if (event == nsnull)
@@ -255,13 +266,10 @@ nsFtpConnectionThread::Process() {
delete event;
return rv;
}
// clean up the socket transport.
// we're done reading and writing, close the streams.
mCOutStream->Close();
NS_RELEASE(mCOutStream);
mCInStream->Close();
NS_RELEASE(mCInStream);
// fall out of the while loop
mKeepRunning = PR_FALSE;
@@ -276,10 +284,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_USER:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_USER - ", mUrl));
rv = S_user();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_USER;
}
@@ -296,10 +307,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_PASS:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_PASS - ", mUrl));
rv = S_pass();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_PASS;
}
@@ -316,10 +330,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_SYST:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_SYST - ", mUrl));
rv = S_syst();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_SYST;
}
@@ -336,10 +353,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_ACCT:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_ACCT - ", mUrl));
rv = S_acct();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_ACCT;
}
@@ -356,10 +376,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_MACB:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_MACB - ", mUrl));
rv = S_macb();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_MACB;
}
@@ -376,10 +399,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_PWD:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_PWD - ", mUrl));
rv = S_pwd();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_PWD;
}
@@ -396,10 +422,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_MODE:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_MODE - ", mUrl));
rv = S_mode();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_MODE;
}
@@ -416,10 +445,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_CWD:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_CWD - ", mUrl));
rv = S_cwd();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_CWD;
}
@@ -436,10 +468,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_SIZE:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_SIZE - ", mUrl));
rv = S_size();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_SIZE;
}
@@ -456,10 +491,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_MDTM:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_MDTM - ", mUrl));
rv = S_mdtm();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_MDTM;
}
@@ -476,13 +514,21 @@ nsFtpConnectionThread::Process() {
case FTP_S_LIST:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_LIST - ", mUrl));
rv = S_list();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
// get the data channel ready
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_LIST - Opening data stream ", mUrl));
rv = mDPipe->OpenInputStream(0, -1, &mDInStream);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
return rv;
}
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_LIST;
@@ -494,19 +540,28 @@ nsFtpConnectionThread::Process() {
case FTP_R_LIST:
{
mState = R_list();
mDInStream->Close();
break;
}
// END: FTP_R_LIST
case FTP_S_RETR:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_RETR - ", mUrl));
rv = S_retr();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
// get the data channel ready
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_RETR - Opening data stream ", mUrl));
rv = mDPipe->OpenInputStream(0, -1, &mDInStream);
if (NS_FAILED(rv)) return rv;
if (NS_FAILED(rv)) {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
return rv;
}
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_RETR;
@@ -518,6 +573,7 @@ nsFtpConnectionThread::Process() {
case FTP_R_RETR:
{
mState = R_retr();
mDInStream->Close();
break;
}
// END: FTP_R_RETR
@@ -528,10 +584,13 @@ nsFtpConnectionThread::Process() {
//////////////////////////////
case FTP_S_PASV:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_PASV - ", mUrl));
rv = S_pasv();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_PASV;
}
@@ -551,10 +610,13 @@ nsFtpConnectionThread::Process() {
//////////////////////////////
case FTP_S_DEL_FILE:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_DEL_FILE - ", mUrl));
rv = S_del_file();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_DEL_FILE;
}
@@ -571,10 +633,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_DEL_DIR:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_DEL_DIR - ", mUrl));
rv = S_del_dir();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_DEL_DIR;
}
@@ -591,10 +656,13 @@ nsFtpConnectionThread::Process() {
case FTP_S_MKDIR:
{
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Process() - S_MKDIR - ", mUrl));
rv = S_mkdir();
if (NS_FAILED(rv)) {
mState = FTP_ERROR;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
} else {
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
mState = FTP_READ_BUF;
mNextState = FTP_R_MKDIR;
}
@@ -615,6 +683,8 @@ nsFtpConnectionThread::Process() {
} // END: switch
} // END: while loop
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFtpConnectionThread::Process() ended for %x (spec =%s)\n\n\n", mUrl, mURLSpec));
return NS_OK;
}
@@ -640,6 +710,8 @@ nsFtpConnectionThread::S_user() {
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
}
@@ -679,6 +751,8 @@ nsFtpConnectionThread::S_pass() {
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -704,6 +778,8 @@ nsFtpConnectionThread::S_syst() {
PRUint32 bufLen, bytes;
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
}
@@ -736,6 +812,8 @@ nsFtpConnectionThread::S_acct() {
char *buffer = "ACCT noaccount" FTP_CRLF;
PRUint32 bufLen = PL_strlen(buffer), bytes;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
}
@@ -752,6 +830,8 @@ nsFtpConnectionThread::S_macb() {
char *buffer = "MACB ENABLE" FTP_CRLF;
PRUint32 bufLen = PL_strlen(buffer), bytes;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
}
@@ -774,6 +854,8 @@ nsFtpConnectionThread::S_pwd() {
char *buffer = "PWD" FTP_CRLF;
PRUint32 bufLen = PL_strlen(buffer), bytes;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
}
@@ -898,6 +980,8 @@ nsFtpConnectionThread::S_mode() {
}
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
}
@@ -952,7 +1036,8 @@ nsFtpConnectionThread::S_cwd() {
buffer = cwdStr.ToNewCString();
bufLen = PL_strlen(buffer);
// send off the command
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -1010,6 +1095,8 @@ nsFtpConnectionThread::S_size() {
nsAllocator::Free(path);
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -1020,6 +1107,9 @@ nsFtpConnectionThread::R_size() {
if (mResponseCode == 2) {
PRInt32 conversionError;
mLength = mResponseMsg.ToInteger(&conversionError);
} if (mResponseCode == 5) {
// couldn't get the size of what we asked for, must be a dir.
return FTP_S_CWD;
}
return FTP_S_MDTM;
}
@@ -1046,6 +1136,8 @@ nsFtpConnectionThread::S_mdtm() {
if (!buffer) return NS_ERROR_OUT_OF_MEMORY;
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -1106,6 +1198,8 @@ nsFtpConnectionThread::S_list() {
buffer = "NLST" FTP_CRLF;
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
}
@@ -1179,6 +1273,8 @@ nsFtpConnectionThread::S_retr() {
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -1204,8 +1300,6 @@ nsFtpConnectionThread::R_retr() {
readSoFar += read;
}
mDInStream->Close();
// we're done filling this end of the pipe. close it.
bufOutStrm->Close();
@@ -1265,6 +1359,8 @@ nsFtpConnectionThread::S_pasv() {
char *buffer = "PASV" FTP_CRLF;
PRUint32 bufLen = PL_strlen(buffer), bytes;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
return mCOutStream->Write(buffer, bufLen, &bytes);
}
@@ -1393,6 +1489,8 @@ nsFtpConnectionThread::S_del_file() {
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -1425,6 +1523,8 @@ nsFtpConnectionThread::S_del_dir() {
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -1456,6 +1556,8 @@ nsFtpConnectionThread::S_mkdir() {
bufLen = PL_strlen(buffer);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("%x Writing \"%s\"\n", mUrl, buffer));
rv = mCOutStream->Write(buffer, bufLen, &bytes);
nsAllocator::Free(buffer);
return rv;
@@ -1539,7 +1641,14 @@ nsFtpConnectionThread::Run() {
return rv;
}
return Process();
rv = Process();
NS_RELEASE(mCPipe);
NS_IF_RELEASE(mDPipe);
NS_RELEASE(mSTS);
return rv;
}
nsresult
@@ -1548,6 +1657,8 @@ nsFtpConnectionThread::Init(nsIURI* aUrl) {
mUrl = aUrl;
NS_ADDREF(mUrl);
mUrl->GetSpec(&mURLSpec);
// pull any username and/or password out of the uri
char *preHost = nsnull;
rv = mUrl->GetPreHost(&preHost);

View File

@@ -225,6 +225,8 @@ private:
PRBool mKeepRunning; // thread event loop boolean
nsString2 mContentType; // the content type of the data we're dealing w/.
char* mURLSpec;
};
#define NS_FTP_THREAD_SEGMENT_SIZE (4*1024)

View File

@@ -16,6 +16,7 @@
* Reserved.
*/
#include "nspr.h"
#include "nsFTPChannel.h"
#include "nsFtpProtocolHandler.h"
#include "nsIURL.h"
@@ -25,6 +26,22 @@
#include "nsIEventSinkGetter.h"
#include "nsIProgressEventSink.h"
#if defined(PR_LOGGING)
//
// Log module for FTP Protocol logging...
//
// To enable logging (see prlog.h for full details):
//
// set NSPR_LOG_MODULES=nsFTPProtocol:5
// set NSPR_LOG_FILE=nspr.log
//
// this enables PR_LOG_DEBUG level information and places all output in
// the file nspr.log
//
PRLogModuleInfo* gFTPLog = nsnull;
#endif /* PR_LOGGING */
static NS_DEFINE_CID(kStandardURLCID, NS_STANDARDURL_CID);
////////////////////////////////////////////////////////////////////////////////
@@ -41,6 +58,17 @@ NS_IMPL_ISUPPORTS(nsFtpProtocolHandler, nsCOMTypeInfo<nsIProtocolHandler>::GetII
NS_METHOD
nsFtpProtocolHandler::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult)
{
#if defined(PR_LOGGING)
//
// Initialize the global PRLogModule for FTP Protocol logging
// if necessary...
//
if (nsnull == gFTPLog) {
gFTPLog = PR_NewLogModule("nsFTPProtocol");
}
#endif /* PR_LOGGING */
nsFtpProtocolHandler* ph = new nsFtpProtocolHandler();
if (ph == nsnull)
return NS_ERROR_OUT_OF_MEMORY;
@@ -91,6 +119,7 @@ nsFtpProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
nsIURI **result)
{
nsresult rv;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFtpProtocolHandler::NewURI(%s); ", aSpec));
// Ftp URLs (currently) have no additional structure beyond that provided by standard
// URLs, so there is no "outer" given to CreateInstance
@@ -110,6 +139,7 @@ nsFtpProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
}
if (NS_FAILED(rv)) {
NS_RELEASE(url);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
return rv;
}
@@ -118,10 +148,12 @@ nsFtpProtocolHandler::NewURI(const char *aSpec, nsIURI *aBaseURI,
rv = url->SetPort(21);
if (NS_FAILED(rv)) {
NS_RELEASE(url);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("FAILED\n"));
return rv;
}
*result = url;
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("SUCCEEDED\n"));
return rv;
}
@@ -139,6 +171,7 @@ nsFtpProtocolHandler::NewChannel(const char* verb, nsIURI* url,
rv = channel->Init(verb, url, eventSinkGetter);
if (NS_FAILED(rv)) {
NS_RELEASE(channel);
PR_LOG(gFTPLog, PR_LOG_DEBUG, ("nsFtpProtocolHandler::NewChannel() FAILED\n"));
return rv;
}