diff --git a/mozilla/allmakefiles.sh b/mozilla/allmakefiles.sh index 48f2bae883c..578c3048b7f 100755 --- a/mozilla/allmakefiles.sh +++ b/mozilla/allmakefiles.sh @@ -403,6 +403,8 @@ netwerk/protocol/finger/src/Makefile netwerk/protocol/ftp/Makefile netwerk/protocol/ftp/public/Makefile netwerk/protocol/ftp/src/Makefile +netwerk/protocol/gopher/Makefile +netwerk/protocol/gopher/src/Makefile netwerk/protocol/http/Makefile netwerk/protocol/http/public/Makefile netwerk/protocol/http/src/Makefile diff --git a/mozilla/build/mac/build_scripts/MozillaBuildList.pm b/mozilla/build/mac/build_scripts/MozillaBuildList.pm index 23954bc7a81..c000b815f09 100644 --- a/mozilla/build/mac/build_scripts/MozillaBuildList.pm +++ b/mozilla/build/mac/build_scripts/MozillaBuildList.pm @@ -306,6 +306,7 @@ sub ProcessJarManifests() CreateJarFromManifest(":mozilla:caps:src:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:docshell:base:jar.mn", $chrome_dir, \%jars); + CreateJarFromManifest(":mozilla:dom:src:base:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:editor:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:embedding:browser:chrome:jar.mn", $chrome_dir, \%jars); CreateJarFromManifest(":mozilla:embedding:browser:chrome:locale:en-US:jar.mn", $chrome_dir, \%jars); diff --git a/mozilla/dom/src/base/jar.mn b/mozilla/dom/src/base/jar.mn new file mode 100644 index 00000000000..01804dd5809 --- /dev/null +++ b/mozilla/dom/src/base/jar.mn @@ -0,0 +1,2 @@ +en-US.jar: + locale/en-US/global/jsdom.properties diff --git a/mozilla/dom/src/base/jsdom.properties b/mozilla/dom/src/base/jsdom.properties new file mode 100644 index 00000000000..9914a4ab828 --- /dev/null +++ b/mozilla/dom/src/base/jsdom.properties @@ -0,0 +1,2 @@ +infiniteLoopTitle=Scripdrgdrgarning +infiniteLoopMsg=A script on tfdsgdrgla to run slowly. If it continues to run, your computer may become unresponsive.\n\nDo you want to abort the script? diff --git a/mozilla/extensions/datetime/nsDateTimeChannel.cpp b/mozilla/extensions/datetime/nsDateTimeChannel.cpp index 4311d2914d2..2a2e3b721ea 100644 --- a/mozilla/extensions/datetime/nsDateTimeChannel.cpp +++ b/mozilla/extensions/datetime/nsDateTimeChannel.cpp @@ -88,7 +88,6 @@ nsDateTimeChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult NS_IMETHODIMP nsDateTimeChannel::GetName(PRUnichar* *result) { - NS_NOTREACHED("nsDateTimeChannel::GetName"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/extensions/finger/nsFingerChannel.cpp b/mozilla/extensions/finger/nsFingerChannel.cpp index 70a6ab6c06e..6ef9f010e5c 100644 --- a/mozilla/extensions/finger/nsFingerChannel.cpp +++ b/mozilla/extensions/finger/nsFingerChannel.cpp @@ -78,29 +78,19 @@ nsFingerChannel::Init(nsIURI* uri) rv = mUrl->GetPath(getter_Copies(autoBuffer)); // autoBuffer = user@host if (NS_FAILED(rv)) return rv; - nsCString cString(autoBuffer); - nsCString tempBuf; - - PRUint32 i; - // Now parse out the user and host - for (i=0; cString[i] != '\0'; i++) { - if (cString[i] == '@') { - cString.Left(tempBuf, i); - mUser = tempBuf; - cString.Right(tempBuf, cString.Length() - i - 1); - mHost = tempBuf; - break; - } - } + const char* buf = autoBuffer.get(); + const char* pos = PL_strchr(buf, '@'); // Catch the case of just the host being given - - if (cString[i] == '\0') { - mHost = cString; + if (!pos) { + mHost.Assign(buf); + } else { + mUser.Assign(buf,pos-buf); + mHost.Assign(pos+1); // ignore '@' } - if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED; + if (mHost.IsEmpty()) return NS_ERROR_NOT_INITIALIZED; return NS_OK; } @@ -123,7 +113,6 @@ nsFingerChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) NS_IMETHODIMP nsFingerChannel::GetName(PRUnichar* *result) { - NS_NOTREACHED("nsFingerChannel::GetName"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/extensions/finger/nsFingerChannel.h b/mozilla/extensions/finger/nsFingerChannel.h index e77455dc689..b15716d09ee 100644 --- a/mozilla/extensions/finger/nsFingerChannel.h +++ b/mozilla/extensions/finger/nsFingerChannel.h @@ -71,8 +71,8 @@ protected: PRBool mActAsObserver; PRInt32 mPort; - nsXPIDLCString mHost; - nsXPIDLCString mUser; + nsCString mHost; + nsCString mUser; nsXPIDLCString mRequest; diff --git a/mozilla/netwerk/build/nsNetModule.cpp b/mozilla/netwerk/build/nsNetModule.cpp index 873d5c1234b..5f9b0fbcf8a 100644 --- a/mozilla/netwerk/build/nsNetModule.cpp +++ b/mozilla/netwerk/build/nsNetModule.cpp @@ -179,6 +179,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAboutCacheEntry) /////////////////////////////////////////////////////////////////////////////// #include "nsFTPDirListingConv.h" +#include "nsGopherDirListingConv.h" #include "nsMultiMixedConv.h" #include "nsHTTPChunkConv.h" #include "nsHTTPCompressConv.h" @@ -188,6 +189,7 @@ NS_GENERIC_FACTORY_CONSTRUCTOR(nsAboutCacheEntry) #include "nsIndexedToHTML.h" nsresult NS_NewFTPDirListingConv(nsFTPDirListingConv** result); +nsresult NS_NewGopherDirListingConv(nsGopherDirListingConv** result); nsresult NS_NewMultiMixedConv (nsMultiMixedConv** result); nsresult MOZ_NewTXTToHTMLConv (mozTXTToHTMLConv** result); nsresult NS_NewHTTPChunkConv (nsHTTPChunkConv ** result); @@ -197,6 +199,7 @@ nsresult NS_NewStreamConv(nsStreamConverterService **aStreamConv); #define FTP_UNIX_TO_INDEX "?from=text/ftp-dir-unix&to=application/http-index-format" #define FTP_NT_TO_INDEX "?from=text/ftp-dir-nt&to=application/http-index-format" +#define GOPHER_TO_INDEX "?from=text/gopher-dir&to=application/http-index-format" #define INDEX_TO_HTML "?from=application/http-index-format&to=text/html" #define MULTI_MIXED_X "?from=multipart/x-mixed-replace&to=*/*" #define MULTI_MIXED "?from=multipart/mixed&to=*/*" @@ -210,11 +213,12 @@ nsresult NS_NewStreamConv(nsStreamConverterService **aStreamConv); #define DEFLATE_TO_UNCOMPRESSED "?from=deflate&to=uncompressed" #define PLAIN_TO_HTML "?from=text/plain&to=text/html" -static PRUint32 g_StreamConverterCount = 14; +static PRUint32 g_StreamConverterCount = 15; static char *g_StreamConverterArray[] = { FTP_UNIX_TO_INDEX, FTP_NT_TO_INDEX, + GOPHER_TO_INDEX, INDEX_TO_HTML, MULTI_MIXED_X, MULTI_MIXED, @@ -328,6 +332,30 @@ CreateNewFTPDirListingConv(nsISupports* aOuter, REFNSIID aIID, void **aResult) return rv; } +static NS_IMETHODIMP +CreateNewGopherDirListingConv(nsISupports* aOuter, REFNSIID aIID, void **aResult) +{ + if (!aResult) { + return NS_ERROR_INVALID_POINTER; + } + if (aOuter) { + *aResult = nsnull; + return NS_ERROR_NO_AGGREGATION; + } + nsGopherDirListingConv* inst = nsnull; + nsresult rv = NS_NewGopherDirListingConv(&inst); + if (NS_FAILED(rv)) { + *aResult = nsnull; + return rv; + } + rv = inst->QueryInterface(aIID, aResult); + if (NS_FAILED(rv)) { + *aResult = nsnull; + } + NS_RELEASE(inst); /* get rid of extra refcnt */ + return rv; +} + static NS_IMETHODIMP CreateNewMultiMixedConvFactory(nsISupports* aOuter, REFNSIID aIID, void **aResult) { @@ -653,6 +681,12 @@ static nsModuleComponentInfo gNetModuleInfo[] = { CreateNewFTPDirListingConv }, + { "GopherDirListingConverter", + NS_GOPHERDIRLISTINGCONVERTER_CID, + NS_ISTREAMCONVERTER_KEY GOPHER_TO_INDEX, + CreateNewGopherDirListingConv + }, + { "Indexed to HTML Converter", NS_NSINDEXEDTOHTMLCONVERTER_CID, NS_ISTREAMCONVERTER_KEY INDEX_TO_HTML, diff --git a/mozilla/netwerk/build2/Makefile.in b/mozilla/netwerk/build2/Makefile.in index ee3757ff69a..75cca14e444 100644 --- a/mozilla/netwerk/build2/Makefile.in +++ b/mozilla/netwerk/build2/Makefile.in @@ -34,12 +34,14 @@ REQUIRES = xpcom string CPPSRCS = nsNetModule2.cpp SHARED_LIBRARY_LIBS = \ + $(DIST)/lib/libnkgopher_s.$(LIB_SUFFIX) \ $(DIST)/lib/libnkftp_s.$(LIB_SUFFIX) \ $(DIST)/lib/libnkfinger_s.$(LIB_SUFFIX) \ $(DIST)/lib/libnkdatetm_s.$(LIB_SUFFIX) \ $(NULL) LOCAL_INCLUDES = \ + -I$(srcdir)/../protocol/gopher/src \ -I$(srcdir)/../protocol/ftp/src \ -I$(srcdir)/../protocol/finger/src \ -I$(srcdir)/../protocol/datetime/src \ diff --git a/mozilla/netwerk/build2/makefile.win b/mozilla/netwerk/build2/makefile.win index 121101e53a5..209cb137ca0 100644 --- a/mozilla/netwerk/build2/makefile.win +++ b/mozilla/netwerk/build2/makefile.win @@ -34,6 +34,7 @@ CPP_OBJS= \ LLIBS= \ $(DIST)\lib\xpcom.lib \ + $(DIST)\lib\nkgopher_s.lib \ $(DIST)\lib\nkftp_s.lib \ $(DIST)\lib\nkfinger_s.lib \ $(DIST)\lib\nkdatetm_s.lib \ @@ -41,6 +42,7 @@ LLIBS= \ INCS = $(INCS) \ -I$(DEPTH)\dist\include \ + -I$(DEPTH)\netwerk\protocol\gopher\src \ -I$(DEPTH)\netwerk\protocol\ftp\src \ -I$(DEPTH)\netwerk\protocol\finger\src \ -I$(DEPTH)\netwerk\protocol\datetime\src \ diff --git a/mozilla/netwerk/protocol/Makefile.in b/mozilla/netwerk/protocol/Makefile.in index fe6403bdb38..ae472cab925 100644 --- a/mozilla/netwerk/protocol/Makefile.in +++ b/mozilla/netwerk/protocol/Makefile.in @@ -27,7 +27,7 @@ VPATH = @srcdir@ include $(DEPTH)/config/autoconf.mk DIRS = about data file ftp http keyword jar res \ - datetime finger + datetime finger gopher include $(topsrcdir)/config/rules.mk diff --git a/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp b/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp index 4311d2914d2..2a2e3b721ea 100644 --- a/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp +++ b/mozilla/netwerk/protocol/datetime/src/nsDateTimeChannel.cpp @@ -88,7 +88,6 @@ nsDateTimeChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult NS_IMETHODIMP nsDateTimeChannel::GetName(PRUnichar* *result) { - NS_NOTREACHED("nsDateTimeChannel::GetName"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp index 70a6ab6c06e..6ef9f010e5c 100644 --- a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp +++ b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.cpp @@ -78,29 +78,19 @@ nsFingerChannel::Init(nsIURI* uri) rv = mUrl->GetPath(getter_Copies(autoBuffer)); // autoBuffer = user@host if (NS_FAILED(rv)) return rv; - nsCString cString(autoBuffer); - nsCString tempBuf; - - PRUint32 i; - // Now parse out the user and host - for (i=0; cString[i] != '\0'; i++) { - if (cString[i] == '@') { - cString.Left(tempBuf, i); - mUser = tempBuf; - cString.Right(tempBuf, cString.Length() - i - 1); - mHost = tempBuf; - break; - } - } + const char* buf = autoBuffer.get(); + const char* pos = PL_strchr(buf, '@'); // Catch the case of just the host being given - - if (cString[i] == '\0') { - mHost = cString; + if (!pos) { + mHost.Assign(buf); + } else { + mUser.Assign(buf,pos-buf); + mHost.Assign(pos+1); // ignore '@' } - if (!*(const char *)mHost) return NS_ERROR_NOT_INITIALIZED; + if (mHost.IsEmpty()) return NS_ERROR_NOT_INITIALIZED; return NS_OK; } @@ -123,7 +113,6 @@ nsFingerChannel::Create(nsISupports* aOuter, const nsIID& aIID, void* *aResult) NS_IMETHODIMP nsFingerChannel::GetName(PRUnichar* *result) { - NS_NOTREACHED("nsFingerChannel::GetName"); return NS_ERROR_NOT_IMPLEMENTED; } diff --git a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.h b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.h index e77455dc689..b15716d09ee 100644 --- a/mozilla/netwerk/protocol/finger/src/nsFingerChannel.h +++ b/mozilla/netwerk/protocol/finger/src/nsFingerChannel.h @@ -71,8 +71,8 @@ protected: PRBool mActAsObserver; PRInt32 mPort; - nsXPIDLCString mHost; - nsXPIDLCString mUser; + nsCString mHost; + nsCString mUser; nsXPIDLCString mRequest; diff --git a/mozilla/netwerk/protocol/gopher/Makefile.in b/mozilla/netwerk/protocol/gopher/Makefile.in new file mode 100644 index 00000000000..60250b6dfc9 --- /dev/null +++ b/mozilla/netwerk/protocol/gopher/Makefile.in @@ -0,0 +1,30 @@ +# +# The contents of this file are subject to the Mozilla 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/MPL/ +# +# 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 Bradley Baetz +# Portions created by Brian Ryner are Copyright (C) 2000 Bradley Baetz. +# All Rights Reserved. +# +# Contributor(s): +# Bradley Baetz + +DEPTH = ../../.. +topsrcdir = @top_srcdir@ +srcdir = @srcdir@ +VPATH = @srcdir@ + +include $(DEPTH)/config/autoconf.mk + +DIRS = src + +include $(topsrcdir)/config/rules.mk diff --git a/mozilla/netwerk/protocol/gopher/makefile.win b/mozilla/netwerk/protocol/gopher/makefile.win new file mode 100644 index 00000000000..d57275ad75a --- /dev/null +++ b/mozilla/netwerk/protocol/gopher/makefile.win @@ -0,0 +1,30 @@ +#!gmake +# +# The contents of this file are subject to the Mozilla 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/MPL/ +# +# 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 Bradley Baetz. +# Portions created by Brian Ryner are Copyright (C) 2000 Bradley Baetz. +# All Rights Reserved. +# +# Contributor(s): +# Bradley Baetz + +DEPTH = ..\..\.. + +MODULE = necko + +DIRS= \ + src \ + $(NULL) + +include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/netwerk/protocol/makefile.win b/mozilla/netwerk/protocol/makefile.win index 7dbcb95aa88..cbbf14da8d4 100644 --- a/mozilla/netwerk/protocol/makefile.win +++ b/mozilla/netwerk/protocol/makefile.win @@ -34,6 +34,7 @@ DIRS= \ datetime \ res \ finger \ + gopher \ $(NULL) include <$(DEPTH)\config\rules.mak> diff --git a/mozilla/netwerk/streamconv/converters/Makefile.in b/mozilla/netwerk/streamconv/converters/Makefile.in index c790dde7aa6..4b3c9ed2e71 100644 --- a/mozilla/netwerk/streamconv/converters/Makefile.in +++ b/mozilla/netwerk/streamconv/converters/Makefile.in @@ -37,6 +37,7 @@ EXPORTS = \ CPPSRCS = \ nsMultiMixedConv.cpp \ nsFTPDirListingConv.cpp \ + nsGopherDirListingConv.cpp \ mozTXTToHTMLConv.cpp \ nsUnknownDecoder.cpp \ nsHTTPChunkConv.cpp \ diff --git a/mozilla/netwerk/streamconv/converters/makefile.win b/mozilla/netwerk/streamconv/converters/makefile.win index 4e26dda3d67..d2aa36f577d 100644 --- a/mozilla/netwerk/streamconv/converters/makefile.win +++ b/mozilla/netwerk/streamconv/converters/makefile.win @@ -34,6 +34,7 @@ EXPORTS = \ CPP_OBJS = \ .\$(OBJDIR)\nsMultiMixedConv.obj \ .\$(OBJDIR)\nsFTPDirListingConv.obj \ + .\$(OBJDIR)\nsGopherDirListingConv.obj \ .\$(OBJDIR)\mozTXTToHTMLConv.obj \ .\$(OBJDIR)\nsHTTPChunkConv.obj \ .\$(OBJDIR)\nsHTTPCompressConv.obj \ diff --git a/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.cpp b/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.cpp new file mode 100644 index 00000000000..a132b625f43 --- /dev/null +++ b/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.cpp @@ -0,0 +1,426 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the gopher-directory to http-index code. + * + * The Initial Developer of the Original Code is Bradley Baetz. + * Portions created by Bradley Baetz are Copyright (C) 2000 Bradley Baetz. + * All Rights Reserved. + * + * Contributor(s): + * Bradley Baetz + */ + +/* This code is based on the ftp directory translation code */ + +#include "plstr.h" +#include "nsMemory.h" +#include "nsCRT.h" +#include "nsIServiceManager.h" +#include "nsIGenericFactory.h" +#include "nsString.h" +#include "nsCOMPtr.h" +#include "nsIURI.h" +#include "nsEscape.h" +#include "nsIStreamListener.h" +#include "nsIStreamConverter.h" +#include "nsIStringStream.h" +#include "nsIStreamObserver.h" +#include "nsNetUtil.h" + +#include "nsGopherDirListingConv.h" + +// nsISupports implementation +NS_IMPL_THREADSAFE_ISUPPORTS3(nsGopherDirListingConv, + nsIStreamConverter, + nsIStreamListener, + nsIStreamObserver); + +// nsIStreamConverter implementation + +#define CONV_BUF_SIZE (4*1024) + +NS_IMETHODIMP +nsGopherDirListingConv::Convert(nsIInputStream *aFromStream, + const PRUnichar *aFromType, + const PRUnichar *aToType, + nsISupports *aCtxt, nsIInputStream **_retval) { + + nsresult rv; + + char buffer[CONV_BUF_SIZE]; + int i = 0; + while (i < CONV_BUF_SIZE) { + buffer[i] = '\0'; + i++; + } + CBufDescriptor desc(buffer, PR_TRUE, CONV_BUF_SIZE); + nsCAutoString aBuffer(desc); + nsCAutoString convertedData; + + NS_ASSERTION(aCtxt, "Gopher dir conversion needs the context"); + // build up the 300: line + nsXPIDLCString spec; + mUri = do_QueryInterface(aCtxt, &rv); + if (NS_FAILED(rv)) return rv; + + rv = mUri->GetSpec(getter_Copies(spec)); + if (NS_FAILED(rv)) return rv; + + convertedData.Append("300: "); + convertedData.Append(spec); + convertedData.Append(LF); + // END 300: + + //Column headings + // We should also send the content-type, probably. The stuff in + // nsGopherChannel::GetContentType should then be moved out - + // maybe into an nsIGopherURI interface/class? + + // Should also possibly use different hosts as a symlink, but the directory + // viewer stuff doesn't support SYM-FILE or SYM-DIRECTORY + convertedData.Append("200: description filename file-type\n"); + + // build up the body + while (1) { + PRUint32 amtRead = 0; + + rv = aFromStream->Read(buffer+aBuffer.Length(), + CONV_BUF_SIZE-aBuffer.Length(), &amtRead); + if (NS_FAILED(rv)) return rv; + + if (!amtRead) { + // EOF + break; + } + + aBuffer = DigestBufferLines(buffer, convertedData); + } + + // send the converted data out. + nsCOMPtr inputData; + nsCOMPtr inputDataSup; + + rv = NS_NewCStringInputStream(getter_AddRefs(inputDataSup), convertedData); + if (NS_FAILED(rv)) return rv; + + inputData = do_QueryInterface(inputDataSup, &rv); + if (NS_FAILED(rv)) return rv; + + *_retval = inputData.get(); + NS_ADDREF(*_retval); + + return NS_OK; +} + +// Stream converter service calls this to initialize the actual +// stream converter (us). +NS_IMETHODIMP +nsGopherDirListingConv::AsyncConvertData(const PRUnichar *aFromType, + const PRUnichar *aToType, + nsIStreamListener *aListener, + nsISupports *aCtxt) { + NS_ASSERTION(aListener && aFromType && aToType, + "null pointer passed into gopher dir listing converter"); + nsresult rv; + + // hook up our final listener. this guy gets the various On*() calls + // we want to throw at him. + mFinalListener = aListener; + NS_ADDREF(mFinalListener); + + // we need our own channel that represents the content-type of the + // converted data. + NS_ASSERTION(aCtxt, "Gopher dir listing needs a context (the uri)"); + mUri = do_QueryInterface(aCtxt,&rv); + if (NS_FAILED(rv)) return rv; + + rv = NS_NewInputStreamChannel(&mPartChannel, + mUri, + nsnull, + "application/http-index-format", + -1); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +// nsIStreamListener implementation +NS_IMETHODIMP +nsGopherDirListingConv::OnDataAvailable(nsIRequest *request, + nsISupports *ctxt, + nsIInputStream *inStr, + PRUint32 sourceOffset, + PRUint32 count) { + nsresult rv; + + PRUint32 read, streamLen; + nsCAutoString indexFormat; + indexFormat.SetCapacity(72); // quick guess + + rv = inStr->Available(&streamLen); + if (NS_FAILED(rv)) return rv; + + char *buffer = (char*)nsMemory::Alloc(streamLen + 1); + rv = inStr->Read(buffer, streamLen, &read); + if (NS_FAILED(rv)) return rv; + + // the dir listings are ascii text, null terminate this sucker. + buffer[streamLen] = '\0'; + + if (!mBuffer.IsEmpty()) { + // we have data left over from a previous OnDataAvailable() call. + // combine the buffers so we don't lose any data. + mBuffer.Append(buffer); + nsMemory::Free(buffer); + buffer = mBuffer.ToNewCString(); + mBuffer.Truncate(); + } + + if (!mSentHeading) { + // build up the 300: line + nsXPIDLCString spec; + rv = mUri->GetSpec(getter_Copies(spec)); + if (NS_FAILED(rv)) return rv; + + //printf("spec is %s\n",spec.get()); + + indexFormat.Append("300: "); + indexFormat.Append(spec.get()); + indexFormat.Append(LF); + // END 300: + + // build up the column heading; 200: + indexFormat.Append("200: description filename file-type\n"); + // END 200: + + mSentHeading = PR_TRUE; + } + char *line = buffer; + line = DigestBufferLines(line, indexFormat); + // if there's any data left over, buffer it. + if (line && *line) { + mBuffer.Append(line); + } + + nsMemory::Free(buffer); + + // send the converted data out. + nsCOMPtr inputData; + nsCOMPtr inputDataSup; + + rv = NS_NewCStringInputStream(getter_AddRefs(inputDataSup), indexFormat); + if (NS_FAILED(rv)) return rv; + + inputData = do_QueryInterface(inputDataSup, &rv); + if (NS_FAILED(rv)) return rv; + + rv = mFinalListener->OnDataAvailable(mPartChannel, ctxt, inputData, + 0, indexFormat.Length()); + if (NS_FAILED(rv)) return rv; + + return NS_OK; +} + +// nsIStreamObserver implementation +NS_IMETHODIMP +nsGopherDirListingConv::OnStartRequest(nsIRequest *request, nsISupports *ctxt) { + // we don't care about start. move along... but start masqeurading + // as the http-index channel now. + return mFinalListener->OnStartRequest(mPartChannel, ctxt); +} + +NS_IMETHODIMP +nsGopherDirListingConv::OnStopRequest(nsIRequest *request, nsISupports *ctxt, + nsresult aStatus, + const PRUnichar* aStatusArg) { + // we don't care about stop. move along... + nsCOMPtr loadgroup; + nsresult rv = mPartChannel->GetLoadGroup(getter_AddRefs(loadgroup)); + if (NS_FAILED(rv)) return rv; + if (loadgroup) + (void)loadgroup->RemoveRequest(mPartChannel, nsnull, + aStatus, aStatusArg); + + return mFinalListener->OnStopRequest(mPartChannel, ctxt, + aStatus, aStatusArg); +} + +// nsGopherDirListingConv methods +nsGopherDirListingConv::nsGopherDirListingConv() { + NS_INIT_ISUPPORTS(); + mFinalListener = nsnull; + mPartChannel = nsnull; + mSentHeading = PR_FALSE; +} + +nsGopherDirListingConv::~nsGopherDirListingConv() { + NS_IF_RELEASE(mFinalListener); + NS_IF_RELEASE(mPartChannel); +} + +nsresult +nsGopherDirListingConv::Init() { + return NS_OK; +} + +char* +nsGopherDirListingConv::DigestBufferLines(char* aBuffer, nsCAutoString& aString) { + char *line = aBuffer; + char *eol; + PRBool cr = PR_FALSE; + + // while we have new lines, parse 'em into application/http-index-format. + while (line && (eol = PL_strchr(line, LF)) ) { + // yank any carriage returns too. + if (eol > line && *(eol-1) == CR) { + eol--; + *eol = '\0'; + cr = PR_TRUE; + } else { + *eol = '\0'; + cr = PR_FALSE; + } + + if (line[0]=='.' && line[1]=='\0') { + if (cr) + line = eol+2; + else + line = eol+1; + continue; + } + + char type; + nsCAutoString desc, selector, host; + PRInt32 port = GOPHER_PORT; + + type = line[0]; + line++; + char* tabPos = PL_strchr(line,'\t'); + + /* Get the description */ + if (tabPos) { + char* descStr = PL_strndup(line,tabPos-line); + char* escName = nsEscape(descStr,url_Path); + desc = escName; + nsMemory::Free(escName); + nsMemory::Free(descStr); + + line = tabPos+1; + tabPos = PL_strchr(line,'\t'); + } + + /* Get selector */ + if (tabPos) { + char* sel = PL_strndup(line,tabPos-line); + char* escName = nsEscape(sel,url_Path); + selector = escName; + nsMemory::Free(escName); + nsMemory::Free(sel); + line = tabPos+1; + tabPos = PL_strchr(line,'\t'); + } + + /* Host and Port - put together because there is + no tab after the port */ + if (tabPos) { + host = nsCString(line,tabPos-line); + line = tabPos+1; + tabPos = PL_strchr(line,'\t'); + if (tabPos==NULL) + tabPos = PL_strchr(line,'\0'); + + /* Port */ + nsCAutoString portStr(line,tabPos-line); + port = atol(portStr.get()); + line = tabPos+1; + } + + // Now create the url + nsCAutoString filename; + if (type != '8' && type != 'T') { + filename.Assign("gopher://"); + filename.Append(host); + if (port != GOPHER_PORT) { + filename.Append(':'); + filename.AppendInt(port); + } + filename.Append('/'); + filename.Append(type); + filename.Append(selector); + } else { + // construct telnet/tn3270 url. + // Moz doesn't support these, so this is UNTESTED!!!!! + // (I do get the correct error message though) + if (type == '8') + // telnet + filename.Assign("telnet://"); + else + // tn3270 + filename.Assign("tn3270://"); + if (!selector.IsEmpty()) { + filename.Append(selector); + filename.Append('@'); + } + filename.Append(host); + if (port != 23) { // telnet port + filename.Append(':'); + filename.AppendInt(port); + } + } + + if (tabPos) { + /* Don't display error messages or informative messages + because they could be selected, and they'll be sorted + out of order. + If FTP displays .messages/READMEs ever, then I could use the + same method to display these + */ + if (type != '3' && type != 'i') { + aString.Append("201: "); + aString.Append(desc); + aString.Append(' '); + aString.Append(filename); + aString.Append(' '); + if (type == '1') + aString.Append("DIRECTORY"); + else + aString.Append("FILE"); + aString.Append(LF); + } + } else { + NS_WARNING("Error parsing gopher directory response.\n"); + //printf("Got: %s\n",filename.get()); + } + + if (cr) + line = eol+2; + else + line = eol+1; + } + return line; +} + +nsresult +NS_NewGopherDirListingConv(nsGopherDirListingConv** aGopherDirListingConv) +{ + NS_PRECONDITION(aGopherDirListingConv, "null ptr"); + if (! aGopherDirListingConv) + return NS_ERROR_NULL_POINTER; + + *aGopherDirListingConv = new nsGopherDirListingConv(); + if (! *aGopherDirListingConv) + return NS_ERROR_OUT_OF_MEMORY; + + NS_ADDREF(*aGopherDirListingConv); + return (*aGopherDirListingConv)->Init(); +} diff --git a/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.h b/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.h new file mode 100644 index 00000000000..fc97fa913a3 --- /dev/null +++ b/mozilla/netwerk/streamconv/converters/nsGopherDirListingConv.h @@ -0,0 +1,101 @@ +/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 4 -*- + * + * The contents of this file are subject to the Mozilla 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/MPL/ + * + * 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 the gopher-directory to http-index code. + * + * The Initial Developer of the Original Code is Bradley Baetz. + * Portions created by Bradley Baetz are Copyright (C) 2000 Bradley Baetz. + * All Rights Reserved. + * + * Contributor(s): + * Bradley Baetz + */ + +/* This code is heavily based on nsFTPDirListingConv.{cpp,h} */ + +#ifndef __nsgopherdirlistingconv__h__ +#define __nsgopherdirlistingconv__h__ + +#include "nspr.h" +#include "prtypes.h" +#include "nsIStreamConverter.h" +#include "nsIChannel.h" +#include "nsString.h" +#include "nsIChannel.h" +#include "nsCOMPtr.h" +#include "nsIURI.h" + +#include "nsIFactory.h" + +#define NS_GOPHERDIRLISTINGCONVERTER_CID \ + { /* ea617873-3b73-4efd-a2c4-fc39bfab809d */ \ + 0xea617873, \ + 0x3b73, \ + 0x4efd, \ + { 0xa2, 0xc4, 0xfc, 0x39, 0xbf, 0xab, 0x80, 0x9d} \ +} +static NS_DEFINE_CID(kGopherDirListingConverterCID, + NS_GOPHERDIRLISTINGCONVERTER_CID); + +#define GOPHER_PORT 70 + +class nsGopherDirListingConv : public nsIStreamConverter { +public: + // nsISupports methods + NS_DECL_ISUPPORTS + + // nsIStreamConverter methods + NS_DECL_NSISTREAMCONVERTER + + // nsIStreamListener methods + NS_DECL_NSISTREAMLISTENER + + // nsIStreamObserver methods + NS_DECL_NSISTREAMOBSERVER + + nsGopherDirListingConv(); + virtual ~nsGopherDirListingConv(); + nsresult Init(); + + // For factory creation. + static NS_METHOD + Create(nsISupports *aOuter, REFNSIID aIID, void **aResult) { + nsresult rv; + if (aOuter) + return NS_ERROR_NO_AGGREGATION; + + nsGopherDirListingConv* _s = new nsGopherDirListingConv(); + if (!_s) + return NS_ERROR_OUT_OF_MEMORY; + NS_ADDREF(_s); + rv = _s->Init(); + if (NS_FAILED(rv)) { + delete _s; + return rv; + } + rv = _s->QueryInterface(aIID, aResult); + NS_RELEASE(_s); + return rv; + } + +private: + char* DigestBufferLines(char *aBuffer, nsCAutoString& aString); + + nsCOMPtr mUri; + + nsCAutoString mBuffer; // buffered data. + PRBool mSentHeading; + nsIStreamListener *mFinalListener; // this guy gets the converted data via his OnDataAvailable() + nsIChannel *mPartChannel; // the channel for the given part we're processing. +}; + +#endif /* __nsgopherdirlistingdconv__h__ */