Moving standalone netlib work from /m/src into pub
git-svn-id: svn://10.0.0.236/branches/MODULAR_NETLIB_BRANCH@116 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
342
mozilla/lib/libnet/bamwrap.cpp
Executable file
342
mozilla/lib/libnet/bamwrap.cpp
Executable file
@@ -0,0 +1,342 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
|
||||
#include "net.h"
|
||||
#include "structs.h"
|
||||
#include "ctxtfunc.h"
|
||||
|
||||
#include "nsIStreamNotification.h"
|
||||
#include "net_strm.h"
|
||||
|
||||
/****************************************************************************/
|
||||
/* Beginning of MWContext Evil!!! */
|
||||
/* ------------------------------- */
|
||||
/* */
|
||||
/* Define a dummy MWContext where all of the upcalls are stubbed out. */
|
||||
/* */
|
||||
/****************************************************************************/
|
||||
|
||||
PRIVATE int
|
||||
stub_noop(int x, ...)
|
||||
{
|
||||
#ifdef XP_MAC
|
||||
#pragma unused (x)
|
||||
#endif
|
||||
/* DebugBreak(); */
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define MAKE_FE_TYPES_PREFIX(func) func##_t
|
||||
#define MAKE_FE_FUNCS_TYPES
|
||||
#include "mk_cx_fn.h"
|
||||
#undef MAKE_FE_FUNCS_TYPES
|
||||
|
||||
#define stub_CreateNewDocWindow (CreateNewDocWindow_t)stub_noop
|
||||
#define stub_LayoutNewDocument (LayoutNewDocument_t)stub_noop
|
||||
#define stub_SetDocTitle (SetDocTitle_t)stub_noop
|
||||
#define stub_FinishedLayout (FinishedLayout_t)stub_noop
|
||||
#define stub_TranslateISOText (TranslateISOText_t)stub_noop
|
||||
#define stub_GetTextInfo (GetTextInfo_t)stub_noop
|
||||
#define stub_MeasureText (MeasureText_t)stub_noop
|
||||
#define stub_GetEmbedSize (GetEmbedSize_t)stub_noop
|
||||
#define stub_GetJavaAppSize (GetJavaAppSize_t)stub_noop
|
||||
#define stub_GetFormElementInfo (GetFormElementInfo_t)stub_noop
|
||||
#define stub_GetFormElementValue (GetFormElementValue_t)stub_noop
|
||||
#define stub_ResetFormElement (ResetFormElement_t)stub_noop
|
||||
#define stub_SetFormElementToggle (SetFormElementToggle_t)stub_noop
|
||||
#define stub_FreeFormElement (FreeFormElement_t)stub_noop
|
||||
#define stub_FreeImageElement (FreeImageElement_t)stub_noop
|
||||
#define stub_FreeEmbedElement (FreeEmbedElement_t)stub_noop
|
||||
#define stub_FreeJavaAppElement (FreeJavaAppElement_t)stub_noop
|
||||
#define stub_CreateEmbedWindow (CreateEmbedWindow_t)stub_noop
|
||||
#define stub_SaveEmbedWindow (SaveEmbedWindow_t)stub_noop
|
||||
#define stub_RestoreEmbedWindow (RestoreEmbedWindow_t)stub_noop
|
||||
#define stub_DestroyEmbedWindow (DestroyEmbedWindow_t)stub_noop
|
||||
#define stub_HideJavaAppElement (HideJavaAppElement_t)stub_noop
|
||||
#define stub_FreeEdgeElement (FreeEdgeElement_t)stub_noop
|
||||
#define stub_FormTextIsSubmit (FormTextIsSubmit_t)stub_noop
|
||||
#define stub_DisplaySubtext (DisplaySubtext_t)stub_noop
|
||||
#define stub_DisplayText (DisplayText_t)stub_noop
|
||||
#define stub_DisplayImage (DisplayImage_t)stub_noop
|
||||
#define stub_DisplayEmbed (DisplayEmbed_t)stub_noop
|
||||
#define stub_DisplayJavaApp (DisplayJavaApp_t)stub_noop
|
||||
#define stub_DisplaySubImage (DisplaySubImage_t)stub_noop
|
||||
#define stub_DisplayEdge (DisplayEdge_t)stub_noop
|
||||
#define stub_DisplayTable (DisplayTable_t)stub_noop
|
||||
#define stub_DisplayCell (DisplayCell_t)stub_noop
|
||||
#define stub_InvalidateEntireTableOrCell (InvalidateEntireTableOrCell_t)stub_noop
|
||||
#define stub_DisplayAddRowOrColBorder (DisplayAddRowOrColBorder_t)stub_noop
|
||||
#define stub_DisplaySubDoc (DisplaySubDoc_t)stub_noop
|
||||
#define stub_DisplayLineFeed (DisplayLineFeed_t)stub_noop
|
||||
#define stub_DisplayHR (DisplayHR_t)stub_noop
|
||||
#define stub_DisplayBullet (DisplayBullet_t)stub_noop
|
||||
#define stub_DisplayFormElement (DisplayFormElement_t)stub_noop
|
||||
#define stub_DisplayBorder (DisplayBorder_t)stub_noop
|
||||
#define stub_UpdateEnableStates (UpdateEnableStates_t)stub_noop
|
||||
#define stub_DisplayFeedback (DisplayFeedback_t)stub_noop
|
||||
#define stub_ClearView (ClearView_t)stub_noop
|
||||
#define stub_SetDocDimension (SetDocDimension_t)stub_noop
|
||||
#define stub_SetDocPosition (SetDocPosition_t)stub_noop
|
||||
#define stub_GetDocPosition (GetDocPosition_t)stub_noop
|
||||
#define stub_BeginPreSection (BeginPreSection_t)stub_noop
|
||||
#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_SetCallNetlibAllTheTime (SetCallNetlibAllTheTime_t)stub_noop
|
||||
#define stub_ClearCallNetlibAllTheTime (ClearCallNetlibAllTheTime_t)stub_noop
|
||||
#define stub_GraphProgressInit (GraphProgressInit_t)stub_noop
|
||||
#define stub_GraphProgressDestroy (GraphProgressDestroy_t)stub_noop
|
||||
#define stub_GraphProgress (GraphProgress_t)stub_noop
|
||||
#define stub_UseFancyFTP (UseFancyFTP_t)stub_noop
|
||||
#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_PromptWithCaption (PromptWithCaption_t)stub_noop
|
||||
#define stub_PromptUsernameAndPassword (PromptUsernameAndPassword_t)stub_noop
|
||||
#define stub_PromptPassword (PromptPassword_t)stub_noop
|
||||
#define stub_EnableClicking (EnableClicking_t)stub_noop
|
||||
#define stub_AllConnectionsComplete (AllConnectionsComplete_t)stub_noop
|
||||
#define stub_ImageSize (ImageSize_t)stub_noop
|
||||
#define stub_ImageData (ImageData_t)stub_noop
|
||||
#define stub_ImageIcon (ImageIcon_t)stub_noop
|
||||
#define stub_ImageOnScreen (ImageOnScreen_t)stub_noop
|
||||
#define stub_SetColormap (SetColormap_t)stub_noop
|
||||
#ifdef LAYERS
|
||||
#define stub_EraseBackground (EraseBackground_t)stub_noop
|
||||
#define stub_SetDrawable (SetDrawable_t)stub_noop
|
||||
#define stub_GetTextFrame (GetTextFrame_t)stub_noop
|
||||
#define stub_SetClipRegion (SetClipRegion_t)stub_noop
|
||||
#define stub_SetOrigin (SetOrigin_t)stub_noop
|
||||
#define stub_GetOrigin (GetOrigin_t)stub_noop
|
||||
#define stub_GetTextFrame (GetTextFrame_t)stub_noop
|
||||
#endif
|
||||
|
||||
#define stub_GetDefaultBackgroundColor (GetDefaultBackgroundColor_t)stub_noop
|
||||
#define stub_LoadFontResource (LoadFontResource_t)stub_noop
|
||||
|
||||
#define stub_DrawJavaApp (DrawJavaApp_t)stub_noop
|
||||
#define stub_HandleClippingView (HandleClippingView_t)stub_noop
|
||||
|
||||
/* Just reuse the same set of context functions: */
|
||||
ContextFuncs stub_context_funcs;
|
||||
|
||||
MWContext *new_stub_context()
|
||||
{
|
||||
static int funcsInitialized = 0;
|
||||
MWContext *context;
|
||||
|
||||
if (!funcsInitialized) {
|
||||
#define MAKE_FE_FUNCS_PREFIX(f) stub_##f
|
||||
#define MAKE_FE_FUNCS_ASSIGN stub_context_funcs.
|
||||
#include "mk_cx_fn.h"
|
||||
|
||||
funcsInitialized = 1;
|
||||
}
|
||||
|
||||
context = (MWContext *)calloc(sizeof(struct MWContext_), 1);
|
||||
|
||||
context->funcs = &stub_context_funcs;
|
||||
context->type = MWContextBrowser;
|
||||
|
||||
return context;
|
||||
}
|
||||
|
||||
void free_stub_context(MWContext *window_id)
|
||||
{
|
||||
TRACEMSG(("Freeing stub context...\n"));
|
||||
free(window_id);
|
||||
}
|
||||
|
||||
|
||||
/****************************************************************************/
|
||||
/* End of MWContext Evil!!! */
|
||||
/****************************************************************************/
|
||||
|
||||
#if 0
|
||||
|
||||
typedef struct NetlibEvent_OnDataAvailable {
|
||||
PREvent ce;
|
||||
stream_connection_t *pStreamInfo;
|
||||
} NetlibEvent_OnDataAvailable;
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
bam_HandleEvent_OnDataAvailable(NetlibEvent_OnDataAvailable* e)
|
||||
{
|
||||
pStreamInfo->pConsumer->OnDataAvailable(pStreamInfo->pNetStream);
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
bam_OnDataAvailable(stream_connection_t *stream_info)
|
||||
{
|
||||
NetlibEvent_OnDataAvailable* event;
|
||||
|
||||
event = PR_NEW(NetlibEvent_OnDataAvailable);
|
||||
if (event == NULL) goto done;
|
||||
PL_InitEvent(&event->ce, stream_info,
|
||||
(PLHandleEventProc)bam_HandleEvent_OnDataAvailable,
|
||||
(PLDestroyEventProc)bam_DestroyEvent_GenericEvent);
|
||||
event->pStreamInfo = stream_info;
|
||||
PL_PostEvent(netlib_event_queue, &event->ce);
|
||||
|
||||
done:
|
||||
}
|
||||
|
||||
|
||||
#endif /* 0 */
|
||||
|
||||
|
||||
/*
|
||||
* Define a NET_StreamClass which pushes its data into an nsIStream
|
||||
* and fires off notifications through the nsIStreamNotification interface
|
||||
*/
|
||||
|
||||
void stub_complete(NET_StreamClass *stream)
|
||||
{
|
||||
nsConnectionInfo *pConn = (nsConnectionInfo *)stream->data_object;
|
||||
|
||||
TRACEMSG(("+++ stream complete.\n"));
|
||||
|
||||
pConn->pNetStream->Close();
|
||||
|
||||
/* Notify the Data Consumer that the Binding has completed... */
|
||||
if (pConn->pConsumer) {
|
||||
pConn->pConsumer->OnStopBinding();
|
||||
pConn->pConsumer->Release();
|
||||
pConn->pConsumer = NULL;
|
||||
}
|
||||
|
||||
/* Free the nsConnectionInfo object hanging off of the data_object */
|
||||
pConn->pNetStream->Release();
|
||||
pConn->pNetStream = NULL;
|
||||
pConn->Release();
|
||||
stream->data_object = NULL;
|
||||
}
|
||||
|
||||
void stub_abort(NET_StreamClass *stream, int status)
|
||||
{
|
||||
TRACEMSG(("+++ stream abort. Status = %d\n", status));
|
||||
}
|
||||
|
||||
int stub_put_block(NET_StreamClass *stream, const char *buffer, int32 length)
|
||||
{
|
||||
PRInt32 bytesWritten;
|
||||
nsConnectionInfo *pConn = (nsConnectionInfo *)stream->data_object;
|
||||
|
||||
TRACEMSG(("+++ stream put_block. Length = %d\n", length));
|
||||
|
||||
bytesWritten = pConn->pNetStream->Write(buffer, length);
|
||||
|
||||
/* XXX: check return value to abort connection if necessary */
|
||||
if (pConn->pConsumer) {
|
||||
pConn->pConsumer->OnDataAvailable(pConn->pNetStream);
|
||||
}
|
||||
|
||||
PR_ASSERT(bytesWritten == length);
|
||||
return (bytesWritten == length);
|
||||
}
|
||||
|
||||
unsigned int stub_is_write_ready(NET_StreamClass *stream)
|
||||
{
|
||||
unsigned int free_space = 0;
|
||||
nsConnectionInfo *pConn = (nsConnectionInfo *)stream->data_object;
|
||||
|
||||
free_space = (unsigned int)pConn->pNetStream->GetAvailableSpace();
|
||||
|
||||
TRACEMSG(("+++ stream is_write_ready. Returning %d\n", free_space));
|
||||
return free_space;
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
/*
|
||||
*Find a converter routine to create a stream and return the stream struct
|
||||
*/
|
||||
PUBLIC NET_StreamClass *
|
||||
NET_StreamBuilder (FO_Present_Types format_out,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *context)
|
||||
{
|
||||
// MOZ_FUNCTION_STUB;
|
||||
NET_StreamClass *stream = NULL;
|
||||
PRBool bSuccess = PR_TRUE;
|
||||
|
||||
/*
|
||||
* Only create a stream if an nsConnectionInfo object is
|
||||
* available from the fe_data...
|
||||
*/
|
||||
if (NULL != URL_s->fe_data) {
|
||||
stream = (NET_StreamClass *)calloc(sizeof(NET_StreamClass), 1);
|
||||
|
||||
if (NULL != stream) {
|
||||
nsConnectionInfo *pConn;
|
||||
|
||||
/*
|
||||
* Initialize the NET_StreamClass instance...
|
||||
*/
|
||||
stream->name = "Stub Stream";
|
||||
stream->window_id = context;
|
||||
|
||||
stream->complete = stub_complete;
|
||||
stream->abort = stub_abort;
|
||||
stream->put_block = stub_put_block;
|
||||
stream->is_write_ready = stub_is_write_ready;
|
||||
|
||||
/*
|
||||
* Create a stream_connection struct to hold the information
|
||||
* about the connection progress...
|
||||
*
|
||||
* Remember to AddRef() the objects because we are storing
|
||||
* references to them...
|
||||
*/
|
||||
pConn = (nsConnectionInfo *)URL_s->fe_data;
|
||||
|
||||
/*
|
||||
* Create an Async stream unless a blocking stream is already
|
||||
* available in the ConnectionInfo...
|
||||
*/
|
||||
if (NULL == pConn->pNetStream) {
|
||||
pConn->pNetStream = new nsAsyncStream(8192);
|
||||
if (NULL == pConn->pNetStream) {
|
||||
free(stream);
|
||||
return NULL;
|
||||
}
|
||||
pConn->pNetStream->AddRef();
|
||||
}
|
||||
|
||||
/* Hang the stream_connection off of the NET_StreamClass */
|
||||
stream->data_object = pConn;
|
||||
pConn->AddRef();
|
||||
|
||||
/* Notify the data consumer that Binding is beginning...*/
|
||||
/* XXX: check result to terminate connection if necessary */
|
||||
if (pConn->pConsumer) {
|
||||
pConn->pConsumer->OnStartBinding();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
}; /* extern "C" */
|
||||
1761
mozilla/lib/libnet/depend.c
Executable file
1761
mozilla/lib/libnet/depend.c
Executable file
File diff suppressed because it is too large
Load Diff
24
mozilla/lib/libnet/depend.h
Executable file
24
mozilla/lib/libnet/depend.h
Executable file
@@ -0,0 +1,24 @@
|
||||
/* -*- Mode: C; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#if 0
|
||||
#define MOZ_FUNCTION_STUB \
|
||||
DebugBreak();
|
||||
#else
|
||||
#define MOZ_FUNCTION_STUB
|
||||
#endif
|
||||
124
mozilla/lib/libnet/makefile.win
Normal file
124
mozilla/lib/libnet/makefile.win
Normal file
@@ -0,0 +1,124 @@
|
||||
# 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.
|
||||
|
||||
NODEPEND=1
|
||||
IGNORE_MANIFEST = 1
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
# New build system where zip dll is build indepenant of java stubs.
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
MODULE = netlib
|
||||
EXPORTS = nsIStreamNotification.h \
|
||||
nsINetService.h \
|
||||
$(NULL)
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Specify the depth of the current directory relative to the
|
||||
#// root of NS
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DEPTH= ..\..\
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Make Variables here: (ie. PDFFILE, MAPFILE, ...)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
DLLNAME=netlib.dll
|
||||
PDBFILE=netlib.pdb
|
||||
MAPFILE=netlib.map
|
||||
DEFFILE=net.def
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define the files necessary to build the target (ie. OBJS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
OBJS= \
|
||||
.\$(OBJDIR)\bamwrap.obj \
|
||||
.\$(OBJDIR)\net_serv.obj \
|
||||
.\$(OBJDIR)\net_strm.obj \
|
||||
.\$(OBJDIR)\depend.obj \
|
||||
.\$(OBJDIR)\moz_depend.obj \
|
||||
.\$(OBJDIR)\mkgeturl.obj \
|
||||
.\$(OBJDIR)\mkconect.obj \
|
||||
.\$(OBJDIR)\mksockrw.obj \
|
||||
.\$(OBJDIR)\mkselect.obj \
|
||||
.\$(OBJDIR)\mkcache.obj \
|
||||
.\$(OBJDIR)\mkmemcac.obj \
|
||||
.\$(OBJDIR)\extcache.obj \
|
||||
.\$(OBJDIR)\mkextcac.obj \
|
||||
.\$(OBJDIR)\mkpadpac.obj \
|
||||
.\$(OBJDIR)\mkautocf.obj \
|
||||
.\$(OBJDIR)\mkaccess.obj \
|
||||
.\$(OBJDIR)\mkformat.obj \
|
||||
.\$(OBJDIR)\jscookie.obj \
|
||||
.\$(OBJDIR)\mkparse.obj \
|
||||
.\$(OBJDIR)\mkutils.obj \
|
||||
.\$(OBJDIR)\mkfsort.obj \
|
||||
.\$(OBJDIR)\mksort.obj \
|
||||
.\$(OBJDIR)\mkmessag.obj \
|
||||
.\$(OBJDIR)\mktrace.obj \
|
||||
.\$(OBJDIR)\mkhttp.obj \
|
||||
.\$(OBJDIR)\mkfile.obj \
|
||||
$(NULL)
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any Public Targets here (ie. PROGRAM, LIBRARY, DLL, ...)
|
||||
#// (these must be defined before the common makefiles are included)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME)
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Define any local options for the make tools
|
||||
#// (ie. LCFLAGS, LLFLAGS, LLIBS, LINCS)
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
LCFLAGS=-DNETSCAPE -DB1M
|
||||
LLIBS=$(LLIBS) $(LIBNSPR) \
|
||||
$(DIST)\lib\js3240.lib \
|
||||
$(DIST)\lib\xppref32.lib \
|
||||
$(DIST)\lib\xpcom32.lib \
|
||||
$(DIST)\lib\xplib.lib
|
||||
LINCS=$(LINCS) -I. \
|
||||
-I$(DEPTH)\raptor\base\src \
|
||||
-I$(PUBLIC)\security \
|
||||
-I$(PUBLIC)\pref \
|
||||
-I$(PUBLIC)\js \
|
||||
-I$(PUBLIC)\xpcom \
|
||||
$(NULL)
|
||||
|
||||
# clobber and clobber_all will remove the following garbage:
|
||||
GARBAGE = $(GARBAGE) _gen
|
||||
|
||||
|
||||
#//------------------------------------------------------------------------
|
||||
#//
|
||||
#// Include the common makefile rules
|
||||
#//
|
||||
#//------------------------------------------------------------------------
|
||||
include <$(DEPTH)/config/rules.mak>
|
||||
|
||||
export:: $(DLL)
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\$(DLLNAME) $(DIST)\bin
|
||||
$(MAKE_INSTALL) .\$(OBJDIR)\netlib.lib $(DIST)\lib
|
||||
1240
mozilla/lib/libnet/moz_depend.cpp
Executable file
1240
mozilla/lib/libnet/moz_depend.cpp
Executable file
File diff suppressed because it is too large
Load Diff
21
mozilla/lib/libnet/net.def
Executable file
21
mozilla/lib/libnet/net.def
Executable file
@@ -0,0 +1,21 @@
|
||||
; 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.
|
||||
|
||||
LIBRARY netlib.dll
|
||||
|
||||
EXPORTS
|
||||
NS_NewINetService
|
||||
NET_ToggleTrace
|
||||
NET_PollSockets
|
||||
229
mozilla/lib/libnet/net_serv.cpp
Executable file
229
mozilla/lib/libnet/net_serv.cpp
Executable file
@@ -0,0 +1,229 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "net_serv.h"
|
||||
#include "net_strm.h"
|
||||
#include "net.h"
|
||||
#include "mktrace.h"
|
||||
|
||||
/* XXX: Legacy definitions... */
|
||||
MWContext *new_stub_context();
|
||||
void free_stub_context(MWContext *window_id);
|
||||
void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id);
|
||||
|
||||
extern "C" {
|
||||
extern char *XP_AppCodeName;
|
||||
extern char *XP_AppVersion;
|
||||
};
|
||||
|
||||
|
||||
nsNetlibService::nsNetlibService()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
m_stubContext = new_stub_context();
|
||||
|
||||
/* Initialize netlib with 32 sockets... */
|
||||
NET_InitNetLib(0, 32);
|
||||
|
||||
|
||||
/* XXX: How should the User Agent get initialized? */
|
||||
XP_AppCodeName = strdup("Mozilla");
|
||||
XP_AppVersion = strdup("1.0");
|
||||
|
||||
}
|
||||
|
||||
|
||||
NS_DEFINE_IID(kINetServiceIID, NS_INETSERVICE_IID);
|
||||
NS_IMPL_ISUPPORTS(nsNetlibService,kINetServiceIID);
|
||||
|
||||
|
||||
nsNetlibService::~nsNetlibService()
|
||||
{
|
||||
TRACEMSG(("nsNetlibService is being destroyed...\n"));
|
||||
|
||||
if (NULL == m_stubContext) {
|
||||
free_stub_context((MWContext *)m_stubContext);
|
||||
}
|
||||
|
||||
NET_ShutdownNetLib();
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsNetlibService::OpenStream(const char *aUrl,
|
||||
nsIStreamNotification *aConsumer)
|
||||
{
|
||||
URL_Struct *URL_s;
|
||||
nsConnectionInfo *pConn;
|
||||
|
||||
/* Create a new dummy context for the URL load... */
|
||||
if ((NULL == m_stubContext) || (NULL == aConsumer)) {
|
||||
return NS_FALSE;
|
||||
}
|
||||
|
||||
/* Create the nsConnectionInfo object... */
|
||||
pConn = new nsConnectionInfo(NULL, aConsumer);
|
||||
if (NULL == pConn) {
|
||||
return NS_FALSE;
|
||||
}
|
||||
pConn->AddRef();
|
||||
|
||||
/* Create the URLStruct... */
|
||||
URL_s = NET_CreateURLStruct(aUrl, NET_NORMAL_RELOAD);
|
||||
if (NULL == URL_s) {
|
||||
pConn->Release();
|
||||
return NS_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark the URL as background loading. This prevents many
|
||||
* client upcall notifications...
|
||||
*/
|
||||
URL_s->load_background = TRUE;
|
||||
|
||||
/*
|
||||
* Attach the Data Consumer to the URL_Struct.
|
||||
*
|
||||
* Both the Data Consumer and the URL_Struct are freed in the
|
||||
* bam_exit_routine(...)
|
||||
*/
|
||||
URL_s->fe_data = pConn;
|
||||
pConn->AddRef();
|
||||
|
||||
/* Start the URL load... */
|
||||
NET_GetURL (URL_s, /* URL_Struct */
|
||||
FO_CACHE_AND_PRESENT, /* FO_Present_type */
|
||||
(MWContext *)m_stubContext, /* MWContext */
|
||||
bam_exit_routine); /* Exit routine... */
|
||||
|
||||
/* Remember, the URL_s may have been freed ! */
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsNetlibService::OpenBlockingStream(const char *aUrl,
|
||||
nsIStreamNotification *aConsumer,
|
||||
nsIInputStream **aNewStream)
|
||||
{
|
||||
URL_Struct *URL_s;
|
||||
nsConnectionInfo *pConn;
|
||||
|
||||
if (NULL != aNewStream) {
|
||||
*aNewStream = NULL;
|
||||
|
||||
/* Create the nsConnectionInfo object... */
|
||||
pConn = new nsConnectionInfo(NULL, aConsumer);
|
||||
if (NULL == pConn) {
|
||||
return NS_FALSE;
|
||||
}
|
||||
pConn->AddRef();
|
||||
|
||||
/* Create the blocking stream... */
|
||||
pConn->pNetStream = new nsBlockingStream();
|
||||
if (NULL == pConn->pNetStream) {
|
||||
pConn->Release();
|
||||
}
|
||||
pConn->pNetStream->AddRef();
|
||||
|
||||
*aNewStream = pConn->pNetStream;
|
||||
pConn->pNetStream->AddRef();
|
||||
|
||||
/* Create the URLStruct... */
|
||||
URL_s = NET_CreateURLStruct(aUrl, NET_NORMAL_RELOAD);
|
||||
if (NULL == URL_s) {
|
||||
pConn->pNetStream->Release();
|
||||
pConn->Release();
|
||||
return NS_FALSE;
|
||||
}
|
||||
|
||||
/*
|
||||
* Mark the URL as background loading. This prevents many
|
||||
* client upcall notifications...
|
||||
*/
|
||||
URL_s->load_background = TRUE;
|
||||
|
||||
/*
|
||||
* Attach the Data Consumer to the URL_Struct.
|
||||
*
|
||||
* Both the Data Consumer and the URL_Struct are freed in the
|
||||
* bam_exit_routine(...)
|
||||
*/
|
||||
URL_s->fe_data = pConn;
|
||||
|
||||
/* Start the URL load... */
|
||||
NET_GetURL (URL_s, /* URL_Struct */
|
||||
FO_CACHE_AND_PRESENT, /* FO_Present_type */
|
||||
(MWContext *)m_stubContext, /* MWContext */
|
||||
bam_exit_routine); /* Exit routine... */
|
||||
|
||||
/* Remember, the URL_s may have been freed ! */
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_FALSE;
|
||||
}
|
||||
|
||||
|
||||
extern "C" {
|
||||
/*
|
||||
* Factory for creating instance of the NetlibService...
|
||||
*/
|
||||
/* NS_BASE */ nsresult NS_NewINetService(nsINetService** aInstancePtrResult,
|
||||
nsISupports* aOuter)
|
||||
{
|
||||
static nsNetlibService *pNetlib = NULL;
|
||||
|
||||
if (NULL != aOuter) {
|
||||
return NS_ERROR_NO_AGGREGATION;
|
||||
}
|
||||
|
||||
/* XXX: For now only allow a single instance of the Netlib Service */
|
||||
if (NULL == pNetlib) {
|
||||
pNetlib = new nsNetlibService();
|
||||
}
|
||||
|
||||
if (NULL == pNetlib) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return pNetlib->QueryInterface(kINetServiceIID, (void**)aInstancePtrResult);
|
||||
}
|
||||
|
||||
}; /* extern "C" */
|
||||
|
||||
|
||||
/*
|
||||
* This is the generic exit routine for all URLs loaded via the new
|
||||
* BAM APIs...
|
||||
*/
|
||||
static void bam_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id)
|
||||
{
|
||||
TRACEMSG(("bam_exit_routine was called...\n"));
|
||||
|
||||
if (NULL != URL_s) {
|
||||
/* Release the nsIstreamNotification object held in the URL_Struct. */
|
||||
nsIStreamNotification *pConsumer = (nsIStreamNotification *)URL_s->fe_data;
|
||||
pConsumer->Release();
|
||||
|
||||
/* Delete the URL_Struct... */
|
||||
NET_FreeURLStruct(URL_s);
|
||||
}
|
||||
}
|
||||
|
||||
47
mozilla/lib/libnet/net_serv.h
Executable file
47
mozilla/lib/libnet/net_serv.h
Executable file
@@ -0,0 +1,47 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 net_serv_h___
|
||||
#define net_serv_h___
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsINetService.h"
|
||||
|
||||
class nsNetlibService : public nsINetService {
|
||||
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsNetlibService();
|
||||
|
||||
/* Implementation of the nsINetService interface */
|
||||
NS_IMETHOD OpenStream(const char *aUrl, nsIStreamNotification *aConsumer);
|
||||
NS_IMETHOD OpenBlockingStream(const char *aUrl,
|
||||
nsIStreamNotification *aConsumer,
|
||||
nsIInputStream **aNewStream);
|
||||
|
||||
protected:
|
||||
~nsNetlibService();
|
||||
|
||||
private:
|
||||
/* XXX: This is temporary until bamwrap.cpp is removed... */
|
||||
void *m_stubContext;
|
||||
};
|
||||
|
||||
|
||||
#endif /* net_strm_h___ */
|
||||
542
mozilla/lib/libnet/net_strm.cpp
Executable file
542
mozilla/lib/libnet/net_strm.cpp
Executable file
@@ -0,0 +1,542 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
#include "net_strm.h"
|
||||
#include "net.h"
|
||||
#include "mktrace.h"
|
||||
|
||||
|
||||
/* XXX: Declare NET_PollSockets(...) for the blocking stream hack... */
|
||||
extern "C" {
|
||||
XP_Bool NET_PollSockets(void);
|
||||
};
|
||||
|
||||
|
||||
NS_DEFINE_IID(kIInputStreamIID, NS_IINPUTSTREAM_IID);
|
||||
|
||||
#define BUFFER_BLOCK_SIZE 8192
|
||||
|
||||
|
||||
|
||||
|
||||
nsConnectionInfo::nsConnectionInfo(nsNetlibStream *pStream,
|
||||
nsIStreamNotification *pNotify)
|
||||
{
|
||||
pNetStream = pStream;
|
||||
pConsumer = pNotify;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsConnectionInfo,kISupportsIID);
|
||||
|
||||
|
||||
nsConnectionInfo::~nsConnectionInfo()
|
||||
{
|
||||
TRACEMSG(("nsConnectionInfo is being destroyed...\n"));
|
||||
|
||||
pNetStream = NULL;
|
||||
pConsumer = NULL;
|
||||
}
|
||||
|
||||
|
||||
|
||||
nsNetlibStream::nsNetlibStream(void)
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
m_Lock = PR_NewMonitor();
|
||||
m_bIsClosed = PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsNetlibStream,kIInputStreamIID);
|
||||
|
||||
|
||||
nsNetlibStream::~nsNetlibStream()
|
||||
{
|
||||
if (m_Lock) {
|
||||
PR_DestroyMonitor(m_Lock);
|
||||
m_Lock = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void nsNetlibStream::Close()
|
||||
{
|
||||
LockStream();
|
||||
m_bIsClosed = PR_TRUE;
|
||||
UnlockStream();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
nsBufferedStream::nsBufferedStream(void)
|
||||
{
|
||||
m_BufferLength = BUFFER_BLOCK_SIZE;
|
||||
|
||||
m_Buffer = new char[m_BufferLength];
|
||||
/* If the allocation failed, mark the stream as closed... */
|
||||
if (NULL == m_Buffer) {
|
||||
m_bIsClosed = PR_TRUE;
|
||||
m_BufferLength = 0;
|
||||
}
|
||||
|
||||
m_DataLength = 0;
|
||||
m_ReadOffset = m_WriteOffset = 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
nsBufferedStream::~nsBufferedStream()
|
||||
{
|
||||
TRACEMSG(("nsBufferedStream is being destroyed...\n"));
|
||||
|
||||
if (m_Buffer) {
|
||||
free(m_Buffer);
|
||||
m_Buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsBufferedStream::GetAvailableSpace(void)
|
||||
{
|
||||
PRInt32 size;
|
||||
|
||||
LockStream();
|
||||
size = m_bIsClosed ? 0 : m_BufferLength - m_WriteOffset;
|
||||
UnlockStream();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsBufferedStream::Write(const char *aBuf, PRInt32 aLen)
|
||||
{
|
||||
PRInt32 bytesWritten = 0;
|
||||
PRInt32 bytesFree;
|
||||
|
||||
LockStream();
|
||||
|
||||
NS_PRECONDITION((m_Buffer || m_bIsClosed), "m_Buffer is NULL!");
|
||||
NS_PRECONDITION((m_WriteOffset >= m_ReadOffset), "Read past the end of buffer.");
|
||||
|
||||
if (!m_bIsClosed && aBuf) {
|
||||
/* Grow the buffer if necessary */
|
||||
bytesFree = GetAvailableSpace();
|
||||
if (aLen > bytesFree) {
|
||||
char *newBuffer;
|
||||
|
||||
m_BufferLength += (((aLen - bytesFree) / BUFFER_BLOCK_SIZE)+1) * BUFFER_BLOCK_SIZE;
|
||||
newBuffer = (char *)realloc(m_Buffer, m_BufferLength);
|
||||
/* If the allocation failed, close the stream and free the buffer... */
|
||||
if (NULL == newBuffer) {
|
||||
m_bIsClosed = PR_TRUE;
|
||||
free(m_Buffer);
|
||||
m_Buffer = NULL;
|
||||
m_BufferLength = 0;
|
||||
|
||||
goto done;
|
||||
} else {
|
||||
m_Buffer = newBuffer;
|
||||
}
|
||||
}
|
||||
|
||||
memcpy(&m_Buffer[m_WriteOffset], aBuf, aLen);
|
||||
m_WriteOffset += aLen;
|
||||
|
||||
bytesWritten = aLen;
|
||||
m_DataLength += aLen;
|
||||
}
|
||||
|
||||
done:
|
||||
UnlockStream();
|
||||
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsBufferedStream::Read(PRInt32 *aErrorCode,
|
||||
char *aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount)
|
||||
{
|
||||
PRInt32 bytesRead = 0;
|
||||
|
||||
LockStream();
|
||||
|
||||
NS_PRECONDITION((m_Buffer || m_bIsClosed), "m_Buffer is NULL!");
|
||||
NS_PRECONDITION((m_WriteOffset >= m_ReadOffset), "Read past the end of buffer.");
|
||||
|
||||
/* Check for initial error conditions... */
|
||||
if (NULL == aBuf) {
|
||||
*aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS;
|
||||
goto done;
|
||||
} else if (m_bIsClosed && (0 == m_DataLength)) {
|
||||
*aErrorCode = NS_INPUTSTREAM_EOF;
|
||||
bytesRead = -1;
|
||||
goto done;
|
||||
} else {
|
||||
*aErrorCode = 0;
|
||||
}
|
||||
|
||||
if (m_Buffer && m_DataLength) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/* Do not read more data than there is available... */
|
||||
if (aCount > m_DataLength) {
|
||||
aCount = m_DataLength;
|
||||
}
|
||||
|
||||
memcpy(aBuf, &m_Buffer[m_ReadOffset], aCount);
|
||||
m_ReadOffset += aCount;
|
||||
|
||||
bytesRead = aCount;
|
||||
m_DataLength -= aCount;
|
||||
}
|
||||
|
||||
done:
|
||||
UnlockStream();
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nsAsyncStream::nsAsyncStream(PRInt32 buffer_size)
|
||||
{
|
||||
m_BufferLength = buffer_size;
|
||||
|
||||
m_Buffer = (char *)malloc(m_BufferLength);
|
||||
/* If the allocation failed, mark the stream as closed... */
|
||||
if (NULL == m_Buffer) {
|
||||
m_bIsClosed = PR_TRUE;
|
||||
m_BufferLength = 0;
|
||||
}
|
||||
|
||||
m_DataLength = 0;
|
||||
m_ReadOffset = m_WriteOffset = 0;
|
||||
}
|
||||
|
||||
|
||||
nsAsyncStream::~nsAsyncStream()
|
||||
{
|
||||
TRACEMSG(("nsAsyncStream is being destroyed...\n"));
|
||||
|
||||
if (m_Buffer) {
|
||||
free(m_Buffer);
|
||||
m_Buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsAsyncStream::GetAvailableSpace(void)
|
||||
{
|
||||
PRInt32 size;
|
||||
|
||||
LockStream();
|
||||
size = m_bIsClosed ? 0 : m_BufferLength - m_DataLength;
|
||||
UnlockStream();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsAsyncStream::Write(const char *aBuf, PRInt32 aLen)
|
||||
{
|
||||
PRInt32 bytesWritten = 0;
|
||||
PRInt32 bytesFree;
|
||||
|
||||
LockStream();
|
||||
|
||||
NS_PRECONDITION((m_Buffer || m_bIsClosed), "m_Buffer is NULL!");
|
||||
|
||||
if (!m_bIsClosed && aBuf) {
|
||||
/* Do not store more data than there is space for... */
|
||||
bytesFree = GetAvailableSpace();
|
||||
if (aLen > bytesFree) {
|
||||
aLen = bytesFree;
|
||||
}
|
||||
|
||||
/* Storing the data will cause m_WriteOffset to wrap */
|
||||
if (m_WriteOffset + aLen > m_BufferLength) {
|
||||
PRInt32 delta;
|
||||
|
||||
/* Store the first chunk through the end of the buffer */
|
||||
delta = m_BufferLength - m_WriteOffset;
|
||||
memcpy(&m_Buffer[m_WriteOffset], aBuf, delta);
|
||||
|
||||
/* Store the second chunk from the beginning of the buffer */
|
||||
m_WriteOffset = aLen-delta;
|
||||
memcpy(m_Buffer, &aBuf[delta], m_WriteOffset);
|
||||
} else {
|
||||
memcpy(&m_Buffer[m_WriteOffset], aBuf, aLen);
|
||||
m_WriteOffset += aLen;
|
||||
}
|
||||
|
||||
bytesWritten = aLen;
|
||||
m_DataLength += aLen;
|
||||
}
|
||||
|
||||
UnlockStream();
|
||||
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsAsyncStream::Read(PRInt32 *aErrorCode,
|
||||
char *aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount)
|
||||
{
|
||||
PRInt32 bytesRead = 0;
|
||||
|
||||
LockStream();
|
||||
|
||||
NS_PRECONDITION((m_Buffer || m_bIsClosed), "m_Buffer is NULL!");
|
||||
|
||||
/* Check for initial error conditions... */
|
||||
if (NULL == aBuf) {
|
||||
*aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS;
|
||||
goto done;
|
||||
} else if (m_bIsClosed && (0 == m_DataLength)) {
|
||||
*aErrorCode = NS_INPUTSTREAM_EOF;
|
||||
bytesRead = -1;
|
||||
goto done;
|
||||
} else {
|
||||
*aErrorCode = 0;
|
||||
}
|
||||
|
||||
if (m_Buffer && m_DataLength) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/* Do not read more data than there is available... */
|
||||
if (aCount > m_DataLength) {
|
||||
aCount = m_DataLength;
|
||||
}
|
||||
|
||||
/* Reading the data will cause m_ReadOffset to wrap */
|
||||
if (m_ReadOffset + aCount > m_BufferLength) {
|
||||
PRInt32 delta;
|
||||
|
||||
/* Read the first chunk through the end of the buffer */
|
||||
delta = m_BufferLength - m_ReadOffset;
|
||||
memcpy(aBuf, &m_Buffer[m_ReadOffset], delta);
|
||||
|
||||
/* Read the second chunk from the beginning of the buffer */
|
||||
m_ReadOffset = aCount-delta;
|
||||
memcpy(&aBuf[delta], m_Buffer, m_ReadOffset);
|
||||
} else {
|
||||
memcpy(aBuf, &m_Buffer[m_ReadOffset], aCount);
|
||||
m_ReadOffset += aCount;
|
||||
}
|
||||
|
||||
bytesRead = aCount;
|
||||
m_DataLength -= aCount;
|
||||
}
|
||||
|
||||
done:
|
||||
UnlockStream();
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
nsBlockingStream::nsBlockingStream()
|
||||
{
|
||||
m_BufferLength = BUFFER_BLOCK_SIZE;
|
||||
|
||||
m_Buffer = (char *)malloc(m_BufferLength);
|
||||
/* If the allocation failed, mark the stream as closed... */
|
||||
if (NULL == m_Buffer) {
|
||||
m_bIsClosed = PR_TRUE;
|
||||
m_BufferLength = 0;
|
||||
}
|
||||
|
||||
m_DataLength = 0;
|
||||
m_ReadOffset = m_WriteOffset = 0;
|
||||
}
|
||||
|
||||
|
||||
nsBlockingStream::~nsBlockingStream()
|
||||
{
|
||||
TRACEMSG(("nsBlockingStream is being destroyed...\n"));
|
||||
|
||||
if (m_Buffer) {
|
||||
free(m_Buffer);
|
||||
m_Buffer = NULL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsBlockingStream::GetAvailableSpace(void)
|
||||
{
|
||||
PRInt32 size;
|
||||
|
||||
LockStream();
|
||||
size = m_bIsClosed ? 0 : m_BufferLength - m_DataLength;
|
||||
UnlockStream();
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsBlockingStream::Write(const char *aBuf, PRInt32 aLen)
|
||||
{
|
||||
PRInt32 bytesWritten = 0;
|
||||
PRInt32 bytesFree;
|
||||
|
||||
LockStream();
|
||||
|
||||
NS_PRECONDITION((m_Buffer || m_bIsClosed), "m_Buffer is NULL!");
|
||||
|
||||
if (!m_bIsClosed && aBuf) {
|
||||
/* Do not store more data than there is space for... */
|
||||
bytesFree = GetAvailableSpace();
|
||||
if (aLen > bytesFree) {
|
||||
aLen = bytesFree;
|
||||
}
|
||||
|
||||
/* Storing the data will cause m_WriteOffset to wrap */
|
||||
if (m_WriteOffset + aLen > m_BufferLength) {
|
||||
PRInt32 delta;
|
||||
|
||||
/* Store the first chunk through the end of the buffer */
|
||||
delta = m_BufferLength - m_WriteOffset;
|
||||
memcpy(&m_Buffer[m_WriteOffset], aBuf, delta);
|
||||
|
||||
/* Store the second chunk from the beginning of the buffer */
|
||||
m_WriteOffset = aLen-delta;
|
||||
memcpy(m_Buffer, &aBuf[delta], m_WriteOffset);
|
||||
} else {
|
||||
memcpy(&m_Buffer[m_WriteOffset], aBuf, aLen);
|
||||
m_WriteOffset += aLen;
|
||||
}
|
||||
|
||||
bytesWritten = aLen;
|
||||
m_DataLength += aLen;
|
||||
}
|
||||
|
||||
UnlockStream();
|
||||
|
||||
return bytesWritten;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsBlockingStream::Read(PRInt32 *aErrorCode,
|
||||
char *aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount)
|
||||
{
|
||||
PRInt32 bytesRead = 0;
|
||||
|
||||
LockStream();
|
||||
|
||||
NS_PRECONDITION((m_Buffer || m_bIsClosed), "m_Buffer is NULL!");
|
||||
|
||||
/* Check for initial error conditions... */
|
||||
if (NULL == aBuf) {
|
||||
*aErrorCode = NS_INPUTSTREAM_ILLEGAL_ARGS;
|
||||
goto done;
|
||||
} else if (m_bIsClosed && (0 == m_DataLength)) {
|
||||
*aErrorCode = NS_INPUTSTREAM_EOF;
|
||||
bytesRead = -1;
|
||||
goto done;
|
||||
} else {
|
||||
*aErrorCode = 0;
|
||||
}
|
||||
|
||||
if (m_Buffer) {
|
||||
/* Skip the appropriate number of bytes in the input buffer... */
|
||||
if (aOffset) {
|
||||
aBuf += aOffset;
|
||||
}
|
||||
|
||||
/* Not enough data is available... Must block. */
|
||||
if (aCount > m_DataLength) {
|
||||
UnlockStream();
|
||||
do {
|
||||
NET_PollSockets();
|
||||
bytesRead += ReadBuffer(aBuf, aCount);
|
||||
/* XXX m_bIsClosed is checked outside of the lock! */
|
||||
} while ((aCount > bytesRead) && !m_bIsClosed);
|
||||
LockStream();
|
||||
} else {
|
||||
bytesRead = ReadBuffer(aBuf, aCount);
|
||||
}
|
||||
}
|
||||
|
||||
done:
|
||||
UnlockStream();
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
|
||||
PRInt32 nsBlockingStream::ReadBuffer(char *aBuf, PRInt32 aCount)
|
||||
{
|
||||
PRInt32 bytesRead = 0;
|
||||
|
||||
LockStream();
|
||||
|
||||
/* Do not read more data than there is available... */
|
||||
if (aCount > m_DataLength) {
|
||||
aCount = m_DataLength;
|
||||
}
|
||||
|
||||
/* Reading the data will cause m_ReadOffset to wrap */
|
||||
if (m_ReadOffset + aCount > m_BufferLength) {
|
||||
PRInt32 delta;
|
||||
|
||||
/* Read the first chunk through the end of the buffer */
|
||||
delta = m_BufferLength - m_ReadOffset;
|
||||
memcpy(aBuf, &m_Buffer[m_ReadOffset], delta);
|
||||
|
||||
/* Read the second chunk from the beginning of the buffer */
|
||||
m_ReadOffset = aCount-delta;
|
||||
memcpy(&aBuf[delta], m_Buffer, m_ReadOffset);
|
||||
} else {
|
||||
memcpy(aBuf, &m_Buffer[m_ReadOffset], aCount);
|
||||
m_ReadOffset += aCount;
|
||||
}
|
||||
|
||||
bytesRead = aCount;
|
||||
m_DataLength -= aCount;
|
||||
|
||||
UnlockStream();
|
||||
|
||||
return bytesRead;
|
||||
}
|
||||
|
||||
169
mozilla/lib/libnet/net_strm.h
Executable file
169
mozilla/lib/libnet/net_strm.h
Executable file
@@ -0,0 +1,169 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 net_strm_h___
|
||||
#define net_strm_h___
|
||||
|
||||
#include "nspr.h"
|
||||
#include "nsIInputStream.h"
|
||||
#include "nsIStreamNotification.h"
|
||||
|
||||
|
||||
/* Forward declaration... */
|
||||
class nsNetlibStream;
|
||||
|
||||
|
||||
class nsConnectionInfo : public nsISupports
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsConnectionInfo(nsNetlibStream *pStream, nsIStreamNotification *pNotify);
|
||||
|
||||
protected:
|
||||
virtual ~nsConnectionInfo();
|
||||
|
||||
public:
|
||||
nsNetlibStream *pNetStream;
|
||||
nsIStreamNotification *pConsumer;
|
||||
};
|
||||
|
||||
|
||||
class nsNetlibStream : public nsIInputStream
|
||||
{
|
||||
public:
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
nsNetlibStream(void);
|
||||
|
||||
virtual PRInt32 GetAvailableSpace(void) = 0;
|
||||
virtual PRInt32 Write(const char *aBuf, PRInt32 aLen) = 0;
|
||||
|
||||
/* From nsIInputStream... */
|
||||
virtual void Close(void);
|
||||
|
||||
protected:
|
||||
virtual ~nsNetlibStream();
|
||||
|
||||
inline void LockStream (void) { if (m_Lock) PR_EnterMonitor(m_Lock); }
|
||||
inline void UnlockStream(void) { if (m_Lock) PR_ExitMonitor (m_Lock); }
|
||||
|
||||
protected:
|
||||
PRBool m_bIsClosed;
|
||||
|
||||
private:
|
||||
PRMonitor *m_Lock;
|
||||
|
||||
};
|
||||
|
||||
/*
|
||||
* Variable size, buffered input stream...
|
||||
*/
|
||||
class nsBufferedStream : public nsNetlibStream {
|
||||
|
||||
public:
|
||||
nsBufferedStream(void);
|
||||
|
||||
/* nsIInputStream interface */
|
||||
virtual PRInt32 Read(PRInt32 *aErrorCode,
|
||||
char *aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount);
|
||||
|
||||
/* nsNetlibStream methods... */
|
||||
virtual PRInt32 GetAvailableSpace(void);
|
||||
virtual PRInt32 Write(const char *aBuf, PRInt32 aLen);
|
||||
|
||||
protected:
|
||||
virtual ~nsBufferedStream();
|
||||
|
||||
private:
|
||||
char *m_Buffer;
|
||||
PRInt32 m_BufferLength;
|
||||
|
||||
PRInt32 m_DataLength;
|
||||
PRInt32 m_ReadOffset;
|
||||
PRInt32 m_WriteOffset;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Fixed size, buffered input stream...
|
||||
*/
|
||||
|
||||
class nsAsyncStream : public nsNetlibStream {
|
||||
|
||||
public:
|
||||
nsAsyncStream(PRInt32 buffer_size);
|
||||
|
||||
/* nsIInputStream interface */
|
||||
virtual PRInt32 Read(PRInt32 *aErrorCode,
|
||||
char *aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount);
|
||||
|
||||
/* nsNetlibStream methods... */
|
||||
virtual PRInt32 GetAvailableSpace(void);
|
||||
virtual PRInt32 Write(const char *aBuf, PRInt32 aLen);
|
||||
|
||||
protected:
|
||||
virtual ~nsAsyncStream();
|
||||
|
||||
private:
|
||||
char *m_Buffer;
|
||||
PRInt32 m_BufferLength;
|
||||
|
||||
PRInt32 m_DataLength;
|
||||
PRInt32 m_ReadOffset;
|
||||
PRInt32 m_WriteOffset;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Variable size, buffered input stream...
|
||||
*/
|
||||
class nsBlockingStream : public nsNetlibStream {
|
||||
|
||||
public:
|
||||
nsBlockingStream(void);
|
||||
|
||||
/* nsIInputStream interface */
|
||||
virtual PRInt32 Read(PRInt32 *aErrorCode,
|
||||
char *aBuf,
|
||||
PRInt32 aOffset,
|
||||
PRInt32 aCount);
|
||||
|
||||
/* nsNetlibStream methods... */
|
||||
virtual PRInt32 GetAvailableSpace(void);
|
||||
virtual PRInt32 Write(const char *aBuf, PRInt32 aLen);
|
||||
|
||||
protected:
|
||||
virtual ~nsBlockingStream();
|
||||
|
||||
PRInt32 ReadBuffer(char *aBuf, PRInt32 aCount);
|
||||
|
||||
private:
|
||||
char *m_Buffer;
|
||||
PRInt32 m_BufferLength;
|
||||
|
||||
PRInt32 m_DataLength;
|
||||
PRInt32 m_ReadOffset;
|
||||
PRInt32 m_WriteOffset;
|
||||
};
|
||||
|
||||
#endif /* net_strm_h___ */
|
||||
55
mozilla/lib/libnet/nsINetService.h
Executable file
55
mozilla/lib/libnet/nsINetService.h
Executable file
@@ -0,0 +1,55 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 nsINetService_h___
|
||||
#define nsINetService_h___
|
||||
|
||||
#include "nsISupports.h"
|
||||
#include "nsIStreamNotification.h"
|
||||
|
||||
/* XXX: This should be moved to ns/xpcom/src/nserror.h */
|
||||
#define NS_OK 0
|
||||
#define NS_FALSE 1
|
||||
|
||||
|
||||
/* cfb1a480-c78f-11d1-bea2-00805f8a66dc */
|
||||
#define NS_INETSERVICE_IID \
|
||||
{ 0xcfb1a480, 0xc78f, 0x11d1, \
|
||||
{0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
||||
|
||||
|
||||
struct nsINetService : public nsISupports
|
||||
{
|
||||
NS_IMETHOD OpenStream(const char *aUrl,
|
||||
nsIStreamNotification *aConsumer) = 0;
|
||||
NS_IMETHOD OpenBlockingStream(const char *aUrl,
|
||||
nsIStreamNotification *aConsumer,
|
||||
nsIInputStream **aNewStream) = 0;
|
||||
};
|
||||
|
||||
|
||||
/*
|
||||
* Create an instance of the INetService
|
||||
*
|
||||
* XXX: Add NS_BASE when nscore.h can be included...
|
||||
*/
|
||||
extern "C" /* NS_BASE */ nsresult NS_NewINetService(nsINetService** aInstancePtrResult,
|
||||
nsISupports* aOuter);
|
||||
|
||||
|
||||
#endif /* nsINetService_h___ */
|
||||
45
mozilla/lib/libnet/nsIStreamNotification.h
Executable file
45
mozilla/lib/libnet/nsIStreamNotification.h
Executable file
@@ -0,0 +1,45 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 2 -*-
|
||||
*
|
||||
* 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 nsIStreamNotification_h___
|
||||
#define nsIStreamNotification_h___
|
||||
|
||||
#include "prtypes.h"
|
||||
#include "nsISupports.h"
|
||||
|
||||
/* forward declaration */
|
||||
class nsIInputStream;
|
||||
|
||||
|
||||
/* 45d234d0-c6c9-11d1-bea2-00805f8a66dc */
|
||||
#define NS_ISTREAMNOTIFICATION_IID \
|
||||
{ 0x45d234d0, 0xc6c9, 0x11d1, \
|
||||
{0xbe, 0xa2, 0x00, 0x80, 0x5f, 0x8a, 0x66, 0xdc} }
|
||||
|
||||
|
||||
struct nsIStreamNotification : public nsISupports
|
||||
{
|
||||
NS_IMETHOD GetBindInfo(void) = 0;
|
||||
NS_IMETHOD OnProgress(void) = 0;
|
||||
NS_IMETHOD OnStartBinding(void) = 0;
|
||||
NS_IMETHOD OnDataAvailable(nsIInputStream *pIStream) = 0;
|
||||
NS_IMETHOD OnStopBinding(void) = 0;
|
||||
};
|
||||
|
||||
|
||||
#endif /* nsIStreamNotification_h___ */
|
||||
Reference in New Issue
Block a user