diff --git a/mozilla/network/module/MANIFEST b/mozilla/network/module/MANIFEST index f91f91c4bd5..955070ee7a4 100644 --- a/mozilla/network/module/MANIFEST +++ b/mozilla/network/module/MANIFEST @@ -4,6 +4,7 @@ nsIStreamListener.h nsINetService.h +nsINetSupport.h nsIRelatedLinks.h nsIURL.h nsIPostToServer.h diff --git a/mozilla/network/module/Makefile b/mozilla/network/module/Makefile index c319f31d80a..1e998e71713 100644 --- a/mozilla/network/module/Makefile +++ b/mozilla/network/module/Makefile @@ -37,6 +37,7 @@ REQUIRES = raptor js dbm nspr security pref xpcom util img \ EXPORTS = nsIStreamListener.h \ nsINetService.h \ + nsINetSupport.h \ nsIURL.h \ nsIRelatedLinks.h \ nsIPostToServer.h \ diff --git a/mozilla/network/module/makefile.win b/mozilla/network/module/makefile.win index 4a4f167c966..e2bb04d4e10 100644 --- a/mozilla/network/module/makefile.win +++ b/mozilla/network/module/makefile.win @@ -24,6 +24,7 @@ IGNORE_MANIFEST = 1 MODULE = netlib EXPORTS = nsIStreamListener.h \ nsINetService.h \ + nsINetSupport.h \ nsIURL.h \ nsIPostToServer.h \ nsIHttpUrl.h \ @@ -107,6 +108,7 @@ LLIBS=$(LLIBS) $(LIBNSPR) \ $(DIST)\lib\xpcom32.lib \ $(DIST)\lib\xplib.lib \ $(DIST)\lib\raptorbase.lib \ + $(DIST)\lib\dbm32.lib \ $(NETLIBS) \ $(NULL) @@ -144,4 +146,13 @@ $(DLL): $(NETLIBS) libs:: $(DLL) $(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME) $(DIST)\bin $(MAKE_INSTALL) .\$(OBJDIR)\netlib.lib $(DIST)\lib + $(MAKE_INSTALL) .\res\gopher-audio.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-binary.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-find.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-image.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-menu.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-movie.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-telnet.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-text.gif $(DIST)\bin\res\network + $(MAKE_INSTALL) .\res\gopher-unknown.gif $(DIST)\bin\res\network diff --git a/mozilla/network/module/net.def b/mozilla/network/module/net.def index 32b8281e938..62fb3a3496f 100644 --- a/mozilla/network/module/net.def +++ b/mozilla/network/module/net.def @@ -20,3 +20,4 @@ EXPORTS NET_ToggleTrace NET_PollSockets NS_NewRelatedLinks + kINetSupportIID diff --git a/mozilla/network/module/nsINetSupport.h b/mozilla/network/module/nsINetSupport.h index abc55d7a049..c4fdd42de97 100644 --- a/mozilla/network/module/nsINetSupport.h +++ b/mozilla/network/module/nsINetSupport.h @@ -33,11 +33,12 @@ public: const nsString &aDefault, nsString &aResult) = 0; - NS_IMETHOD_(PRBool) PasswordPrompt(const nsString &aText, - nsString &aUser, - nsString &aPassword) = 0; + NS_IMETHOD_(PRBool) PromptUserAndPassword(const nsString &aText, + nsString &aUser, + nsString &aPassword) = 0; - + NS_IMETHOD_(PRBool) PromptPassword(const nsString &aText, + nsString &aPassword) = 0; }; #endif diff --git a/mozilla/network/module/nsIStreamListener.h b/mozilla/network/module/nsIStreamListener.h index a9b3cc17890..a8b1a97ded4 100644 --- a/mozilla/network/module/nsIStreamListener.h +++ b/mozilla/network/module/nsIStreamListener.h @@ -79,6 +79,9 @@ public: { 0x45d234d0, 0xc6c9, 0x11d1, \ {0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} } +NS_DECLARE_ID(kIStreamListenerIID, 0x45d234d0, 0xc6c9, 0x11d1, + 0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc); + /** * The nsIStreamListener interface provides the necessary notifications * during both synchronous and asynchronous URL loading. diff --git a/mozilla/network/module/nsNetIDs.cpp b/mozilla/network/module/nsNetIDs.cpp index 5cce809c64b..0bab65e23d1 100644 --- a/mozilla/network/module/nsNetIDs.cpp +++ b/mozilla/network/module/nsNetIDs.cpp @@ -1,2 +1,4 @@ #define NS_IMPL_IDS +#include "nsINetSupport.h" +#include "nsIStreamListener.h" #include "nsIPref.h" diff --git a/mozilla/network/module/nsNetService.cpp b/mozilla/network/module/nsNetService.cpp index 24057561aab..8432ca32323 100644 --- a/mozilla/network/module/nsNetService.cpp +++ b/mozilla/network/module/nsNetService.cpp @@ -35,7 +35,7 @@ extern "C" { #include "nsINetContainerApplication.h" /* XXX: Legacy definitions... */ -MWContext *new_stub_context(); +MWContext *new_stub_context(URL_Struct *URL_s); void free_stub_context(MWContext *window_id); static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id); @@ -94,7 +94,9 @@ nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp) { NS_INIT_REFCNT(); - m_stubContext = new_stub_context(); + /* + m_stubContext = new_stub_context(); + */ /* Initialize netlib with 32 sockets... */ NET_InitNetLib(0, 32); @@ -108,6 +110,8 @@ nsNetlibService::nsNetlibService(nsINetContainerApplication *aContainerApp) NET_CacheConverter); NET_RegisterContentTypeConverter("*", FO_NGLAYOUT, NULL, NET_NGLayoutConverter); + NET_RegisterContentTypeConverter(APPLICATION_HTTP_INDEX, FO_NGLAYOUT, + NULL, NET_HTTPIndexFormatToHTMLConverter); NET_RegisterUniversalEncodingConverter("chunked", NULL, @@ -163,10 +167,12 @@ nsNetlibService::~nsNetlibService() { TRACEMSG(("nsNetlibService is being destroyed...\n")); - if (NULL != m_stubContext) { + /* + if (NULL != m_stubContext) { free_stub_context((MWContext *)m_stubContext); m_stubContext = NULL; - } + } + */ NS_IF_RELEASE(mContainer); NET_ShutdownNetLib(); @@ -174,7 +180,7 @@ nsNetlibService::~nsNetlibService() nsresult nsNetlibService::OpenStream(nsIURL *aUrl, - nsIStreamListener *aConsumer) + nsIStreamListener *aConsumer) { URL_Struct *URL_s; nsConnectionInfo *pConn; @@ -221,16 +227,23 @@ nsresult nsNetlibService::OpenStream(nsIURL *aUrl, * XXX: Currently the return value form InitializeURLInfo(...) is * ignored... Should the connection abort if it fails? */ - result = aUrl->QueryInterface(kIProtocolConnectionIID, (void**)&pProtocol); - if (NS_OK == result) { - pProtocol->InitializeURLInfo(URL_s); - NS_RELEASE(pProtocol); - } - + result = aUrl->QueryInterface(kIProtocolConnectionIID, (void**)&pProtocol); + if (NS_OK == result) { + pProtocol->InitializeURLInfo(URL_s); + NS_RELEASE(pProtocol); + } + + MWContext *stubContext = new_stub_context(URL_s); /* Start the URL load... */ +/* + NET_GetURL (URL_s, // URL_Struct + FO_CACHE_AND_NGLAYOUT, // FO_Present_type + (MWContext *)m_stubContext, // MWContext + bam_exit_routine); // Exit routine... +*/ NET_GetURL (URL_s, /* URL_Struct */ FO_CACHE_AND_NGLAYOUT, /* FO_Present_type */ - (MWContext *)m_stubContext, /* MWContext */ + (MWContext *)stubContext, /* MWContext */ bam_exit_routine); /* Exit routine... */ /* Remember, the URL_s may have been freed ! */ @@ -312,10 +325,18 @@ nsresult nsNetlibService::OpenBlockingStream(nsIURL *aUrl, /* printf("+++ Loading %s\n", aUrl); */ + MWContext *stubContext = new_stub_context(URL_s); + /* Start the URL load... */ +/* + NET_GetURL (URL_s, // URL_Struct + FO_CACHE_AND_NGLAYOUT, // FO_Present_type + (MWContext *)m_stubContext, // MWContext + bam_exit_routine); // Exit routine... +*/ NET_GetURL (URL_s, /* URL_Struct */ FO_CACHE_AND_NGLAYOUT, /* FO_Present_type */ - (MWContext *)m_stubContext, /* MWContext */ + (MWContext *) stubContext, /* MWContext */ bam_exit_routine); /* Exit routine... */ /* Remember, the URL_s may have been freed ! */ @@ -485,5 +506,8 @@ static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id /* Delete the URL_Struct... */ NET_FreeURLStruct(URL_s); } + if (NULL != window_id) { +// free_stub_context(window_id); + } } diff --git a/mozilla/network/module/nsNetStubs.cpp b/mozilla/network/module/nsNetStubs.cpp index 5fc2d1704ee..294ca72c1db 100644 --- a/mozilla/network/module/nsNetStubs.cpp +++ b/mozilla/network/module/nsNetStubs.cpp @@ -42,7 +42,7 @@ extern "C" { extern "C" { -#if defined(XP_UNIX) || defined(XP_WIN) +#if defined(XP_UNIX) DB * dbopen(const char *fname, int flags,int mode, DBTYPE type, const void *openinfo) @@ -755,7 +755,9 @@ XP_FileOpen(const char * name, XP_FileType type, const XP_FilePerm perm) switch (type) { case xpURL: - case xpFileToPost: { + case xpFileToPost: + case xpHTTPCookie: + { XP_File fp; char* newName = WH_FileName(name, type); @@ -822,7 +824,13 @@ WH_FileName (const char *NetName, XP_FileType type) { MOZ_FUNCTION_STUB; - if ((type == xpURL) || (type == xpFileToPost)) { + if (type == xpHTTPCookie) { +#ifdef XP_PC + return PL_strdup("cookies.txt"); +#else + return PL_strdup("cookies"); +#endif + } else if ((type == xpURL) || (type == xpFileToPost)) { /* * This is the body of XP_NetToDosFileName(...) which is implemented * for Windows only in fegui.cpp @@ -955,12 +963,6 @@ char *INTL_ResourceCharSet(void) *--------------------------------------------------------------------------- */ -void FE_Alert(MWContext *pContext, const char *pMsg) -{ - MOZ_FUNCTION_STUB; -} - - int32 FE_GetContextID(MWContext *pContext) { MOZ_FUNCTION_STUB; diff --git a/mozilla/network/module/nsStubContext.cpp b/mozilla/network/module/nsStubContext.cpp index 41280a66c06..34e0776352a 100644 --- a/mozilla/network/module/nsStubContext.cpp +++ b/mozilla/network/module/nsStubContext.cpp @@ -1,4 +1,4 @@ -/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*- +/* -*- 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 @@ -22,9 +22,11 @@ #include "structs.h" #include "ctxtfunc.h" #include "xp_list.h" +#include "plstr.h" #include "nsString.h" #include "nsIStreamListener.h" +#include "nsINetSupport.h" #include "nsNetStream.h" /****************************************************************************/ @@ -45,27 +47,181 @@ stub_noop(int x, ...) return 0; } -PRIVATE void stub_GraphProgressInit(MWContext *context, - URL_Struct *URL_s, - int32 content_length) +static nsIStreamListener *getStreamListener(URL_Struct *URL_s) { - nsConnectionInfo *pConn; - - if (NULL != URL_s->fe_data) { - - if (URL_s->load_background) - return; + nsIStreamListener *res = NULL; + + if (URL_s->fe_data) { /* * Retrieve the nsConnectionInfo object from the fe_data field * of the URL_Struct... */ - pConn = (nsConnectionInfo *)URL_s->fe_data; - if ((NULL != pConn) && (NULL != pConn->pConsumer)) { - nsAutoString status; - - pConn->pConsumer->OnProgress(pConn->pURL, 0, content_length, status); + nsConnectionInfo *pConn = (nsConnectionInfo *)URL_s->fe_data; + if (pConn) { + res = pConn->pConsumer; } } + + NS_IF_ADDREF(res); + + return res; +} + +static nsINetSupport *getNetSupport(URL_Struct *URL_s) +{ + nsIStreamListener *isl = getStreamListener(URL_s); + if (isl) { + nsINetSupport *ins; + isl->QueryInterface(kINetSupportIID, (void **) &ins); + isl->Release(); + return ins; + } + return NULL; +} + +void stub_Alert(MWContext *context, + const char *msg) +{ + nsINetSupport *ins; + + if (ins = getNetSupport(context->modular_data)) { + nsString str(msg); + ins->Alert(str); + ins->Release(); + } else { + printf("Alert: %s", msg); + } +} + +extern "C" void FE_Alert(MWContext *context, const char *msg) +{ + stub_Alert(context, msg); +} + +XP_Bool stub_Confirm(MWContext *context, + const char *msg) +{ + nsINetSupport *ins; + + if (ins = getNetSupport(context->modular_data)) { + XP_Bool res; + nsString str(msg); + res = ins->Confirm(str); + ins->Release(); + return res; + } else { + printf("Confirm: %s", msg); + } + return FALSE; +} + +char *stub_Prompt(MWContext *context, + const char *msg, + const char *def) +{ + nsINetSupport *ins; + + if (ins = getNetSupport(context->modular_data)) { + nsString str(msg); + nsString defStr(def); + nsString res; + if (ins->Prompt(msg, defStr, res)) { + ins->Release(); + return res.ToNewCString(); + } + ins->Release(); + } else { + char buf[256]; + printf("%s\n", msg); + printf("Prompt: "); + scanf("%s", buf); + if (PL_strlen(buf)) { + return PL_strdup(buf); + } + } + + return NULL; +} + +PRIVATE XP_Bool +stub_PromptUsernameAndPassword(MWContext *context, + const char *msg, + char **username, + char **password) +{ + nsINetSupport *ins; + + if (ins = getNetSupport(context->modular_data)) { + nsString str(msg); + nsString userStr; + nsString pwdStr; + if (ins->PromptUserAndPassword(msg, userStr, pwdStr)) { + ins->Release(); + *username = userStr.ToNewCString(); + *password = pwdStr.ToNewCString(); + return TRUE; + } + ins->Release(); + } else { + char buf[256]; + printf("%s\n", msg); + printf("Username: "); + scanf("%s", buf); + *username = PL_strdup(buf); + printf("Password: "); + scanf("%s", buf); + *password = PL_strdup(buf); + if (**username) { + return TRUE; + } + PR_FREEIF(*username); + PR_FREEIF(*password); + } + + return FALSE; +} + +char *stub_PromptPassword(MWContext *context, + const char *msg) +{ + nsINetSupport *ins; + + if (ins = getNetSupport(context->modular_data)) { + nsString str(msg); + nsString res; + if (ins->PromptPassword(msg, res)) { + ins->Release(); + return res.ToNewCString(); + } + ins->Release(); + } else { + char buf[256]; + printf("%s\n", msg); + printf("Password: "); + scanf("%s", buf); + if (PL_strlen(buf)) { + return PL_strdup(buf); + } + } + + return NULL; +} + +PRIVATE void stub_GraphProgressInit(MWContext *context, + URL_Struct *URL_s, + int32 content_length) +{ + nsIStreamListener *pListener; + + if (URL_s->load_background) + return; + + if (pListener = getStreamListener(URL_s)) { + nsConnectionInfo *pConn = (nsConnectionInfo *) URL_s->fe_data; + nsAutoString status; + pListener->OnProgress(pConn->pURL, 0, content_length, status); + pListener->Release(); + } } @@ -75,22 +231,17 @@ PRIVATE void stub_GraphProgress(MWContext *context, int32 bytes_since_last_time, int32 content_length) { - nsConnectionInfo *pConn; + nsIStreamListener *pListener; - if (NULL != URL_s->fe_data) { - if (URL_s->load_background) - return; - /* - * Retrieve the nsConnectionInfo object from the fe_data field - * of the URL_Struct... - */ - pConn = (nsConnectionInfo *)URL_s->fe_data; - if ((NULL != pConn) && (NULL != pConn->pConsumer)) { - nsAutoString status; + if (URL_s->load_background) + return; - pConn->pConsumer->OnProgress(pConn->pURL, bytes_received, - content_length, status); - } + if (pListener = getStreamListener(URL_s)) { + nsConnectionInfo *pConn = (nsConnectionInfo *) URL_s->fe_data; + nsAutoString status; + pListener->OnProgress(pConn->pURL, bytes_received, + content_length, status); + pListener->Release(); } } @@ -99,32 +250,39 @@ PRIVATE void stub_GraphProgressDestroy(MWContext *context, int32 content_length, int32 total_bytes_read) { - nsConnectionInfo *pConn; - /* * XXX: Currently this function never calls OnProgress(...) because * netlib calls FE_GraphProgressDestroy(...) after closing the * stream... So, OnStopBinding(...) has already been called and * the nsConnectionInfo->pConsumer has been released and NULLed... */ - if (NULL != URL_s->fe_data) { - if (URL_s->load_background) - return; - /* - * Retrieve the nsConnectionInfo object from the fe_data field - * of the URL_Struct... - */ - pConn = (nsConnectionInfo *)URL_s->fe_data; - if ((NULL != pConn) && (NULL != pConn->pConsumer)) { - nsAutoString status; + nsIStreamListener *pListener; - pConn->pConsumer->OnProgress(pConn->pURL, total_bytes_read, - content_length, status); - } + if (URL_s->load_background) + return; + + if (pListener = getStreamListener(URL_s)) { + nsConnectionInfo *pConn = (nsConnectionInfo *) URL_s->fe_data; + nsAutoString status; + pListener->OnProgress(pConn->pURL, total_bytes_read, + content_length, status); } } +PRIVATE void stub_Progress(MWContext *context, const char *msg) +{ + nsIStreamListener *pListener; + if (pListener = getStreamListener(context->modular_data)) { + nsConnectionInfo *pConn = + (nsConnectionInfo *) context->modular_data->fe_data; + nsAutoString status(msg); + pListener->OnProgress(pConn->pURL, -1, -1, status); + pListener->Release(); + } else { + printf("%s\n", msg); + } +} #define MAKE_FE_TYPES_PREFIX(func) func##_t @@ -183,8 +341,8 @@ PRIVATE void stub_GraphProgressDestroy(MWContext *context, #define stub_EndPreSection (EndPreSection_t)stub_noop #define stub_SetProgressBarPercent (SetProgressBarPercent_t)stub_noop #define stub_SetBackgroundColor (SetBackgroundColor_t)stub_noop -#define stub_Progress (Progress_t)stub_noop -#define stub_Alert (Alert_t)stub_noop +#define stub_Progress (Progress_t)stub_Progress +#define stub_Alert (Alert_t)stub_Alert #define stub_SetCallNetlibAllTheTime (SetCallNetlibAllTheTime_t)stub_noop #define stub_ClearCallNetlibAllTheTime (ClearCallNetlibAllTheTime_t)stub_noop #define stub_GraphProgressInit (GraphProgressInit_t)stub_GraphProgressInit @@ -194,11 +352,11 @@ PRIVATE void stub_GraphProgressDestroy(MWContext *context, #define stub_UseFancyNewsgroupListing (UseFancyNewsgroupListing_t)stub_noop #define stub_FileSortMethod (FileSortMethod_t)stub_noop #define stub_ShowAllNewsArticles (ShowAllNewsArticles_t)stub_noop -#define stub_Confirm (Confirm_t)stub_noop -#define stub_Prompt (Prompt_t)stub_noop +#define stub_Confirm (Confirm_t)stub_Confirm +#define stub_Prompt (Prompt_t)stub_Prompt #define stub_PromptWithCaption (PromptWithCaption_t)stub_noop -#define stub_PromptUsernameAndPassword (PromptUsernameAndPassword_t)stub_noop -#define stub_PromptPassword (PromptPassword_t)stub_noop +#define stub_PromptUsernameAndPassword (PromptUsernameAndPassword_t)stub_PromptUsernameAndPassword +#define stub_PromptPassword (PromptPassword_t)stub_PromptPassword #define stub_EnableClicking (EnableClicking_t)stub_noop #define stub_AllConnectionsComplete (AllConnectionsComplete_t)stub_noop #define stub_ImageSize (ImageSize_t)stub_noop @@ -227,7 +385,7 @@ ContextFuncs stub_context_funcs; XP_List *stub_context_list = NULL; -MWContext *new_stub_context() +MWContext *new_stub_context(URL_Struct *URL_s) { static int funcsInitialized = 0; MWContext *context; @@ -247,6 +405,7 @@ MWContext *new_stub_context() if (nsnull != context) { context->funcs = &stub_context_funcs; context->type = MWContextBrowser; + context->modular_data = URL_s; if (nsnull != stub_context_list) { XP_ListAddObjectToEnd(stub_context_list, context); @@ -260,13 +419,15 @@ void free_stub_context(MWContext *window_id) { TRACEMSG(("Freeing stub context...\n")); - if (stub_context_list) { - PRBool result; - - result = XP_ListRemoveObject(stub_context_list, window_id); - PR_ASSERT(PR_TRUE == result); + if (window_id) { + if (stub_context_list) { + PRBool result; + + result = XP_ListRemoveObject(stub_context_list, window_id); + PR_ASSERT(PR_TRUE == result); + } + free(window_id); } - free(window_id); }