Compare commits
2 Commits
FAST-GTK-G
...
tags/LIBNE
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
73de3f63a3 | ||
|
|
7af78328dc |
@@ -1,375 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 <math.h>
|
||||
|
||||
#include "nspr.h"
|
||||
#include "il_util.h"
|
||||
|
||||
#include "nsDeviceContextGTK.h"
|
||||
#include "nsGfxCIID.h"
|
||||
|
||||
#include "../ps/nsDeviceContextPS.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#define NS_TO_GDK_RGB(ns) (ns & 0xff) << 16 | (ns & 0xff00) | ((ns >> 16) & 0xff)
|
||||
|
||||
#define GDK_COLOR_TO_NS_RGB(c) \
|
||||
((nscolor) NS_RGB(c.red, c.green, c.blue))
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kDeviceContextIID, NS_IDEVICE_CONTEXT_IID);
|
||||
|
||||
nsDeviceContextGTK::nsDeviceContextGTK()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mTwipsToPixels = 1.0;
|
||||
mPixelsToTwips = 1.0;
|
||||
mDepth = 0 ;
|
||||
mPaletteInfo.isPaletteDevice = PR_FALSE;
|
||||
mPaletteInfo.sizePalette = 0;
|
||||
mPaletteInfo.numReserved = 0;
|
||||
mPaletteInfo.palette = NULL;
|
||||
mNumCells = 0;
|
||||
}
|
||||
|
||||
nsDeviceContextGTK::~nsDeviceContextGTK()
|
||||
{
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextGTK, kDeviceContextIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextGTK)
|
||||
NS_IMPL_RELEASE(nsDeviceContextGTK)
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::Init(nsNativeWidget aNativeWidget)
|
||||
{
|
||||
GdkVisual *vis;
|
||||
GtkRequisition req;
|
||||
GtkWidget *sb;
|
||||
|
||||
mWidget = aNativeWidget;
|
||||
|
||||
// Compute dpi of display
|
||||
float screenWidth = float(::gdk_screen_width());
|
||||
float screenWidthIn = float(::gdk_screen_width_mm()) / 25.4f;
|
||||
nscoord dpi = nscoord(screenWidth / screenWidthIn);
|
||||
|
||||
// Now for some wacky heuristics.
|
||||
if (dpi < 84) dpi = 72;
|
||||
else if (dpi < 108) dpi = 96;
|
||||
else if (dpi < 132) dpi = 120;
|
||||
|
||||
mTwipsToPixels = float(dpi) / float(NSIntPointsToTwips(72));
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
|
||||
#if 0
|
||||
mTwipsToPixels = ( ((float)::gdk_screen_width()) /
|
||||
((float)::gdk_screen_width_mm()) * 25.4) /
|
||||
(float)NSIntPointsToTwips(72);
|
||||
|
||||
mPixelsToTwips = 1.0f / mTwipsToPixels;
|
||||
#endif
|
||||
|
||||
vis = gdk_rgb_get_visual();
|
||||
mDepth = vis->depth;
|
||||
|
||||
sb = gtk_vscrollbar_new(NULL);
|
||||
gtk_widget_ref(sb);
|
||||
gtk_object_sink(GTK_OBJECT(sb));
|
||||
gtk_widget_size_request(sb,&req);
|
||||
mScrollbarWidth = req.width;
|
||||
gtk_widget_destroy(sb);
|
||||
gtk_widget_unref(sb);
|
||||
|
||||
sb = gtk_hscrollbar_new(NULL);
|
||||
gtk_widget_ref(sb);
|
||||
gtk_object_sink(GTK_OBJECT(sb));
|
||||
gtk_widget_size_request(sb,&req);
|
||||
mScrollbarHeight = req.height;
|
||||
gtk_widget_destroy(sb);
|
||||
gtk_widget_unref(sb);
|
||||
|
||||
#ifdef DEBUG
|
||||
static PRBool once = PR_TRUE;
|
||||
if (once) {
|
||||
printf("GFX: dpi=%d t2p=%g p2t=%g depth=%d\n", dpi, mTwipsToPixels, mPixelsToTwips,mDepth);
|
||||
once = PR_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::CreateRenderingContext(nsIRenderingContext *&aContext)
|
||||
{
|
||||
nsIRenderingContext *pContext;
|
||||
nsresult rv;
|
||||
nsDrawingSurfaceGTK *surf;
|
||||
|
||||
// to call init for this, we need to have a valid nsDrawingSurfaceGTK created
|
||||
pContext = new nsRenderingContextGTK();
|
||||
|
||||
if (nsnull != pContext)
|
||||
{
|
||||
NS_ADDREF(pContext);
|
||||
|
||||
// create the nsDrawingSurfaceGTK
|
||||
surf = new nsDrawingSurfaceGTK();
|
||||
|
||||
if (nsnull != surf)
|
||||
{
|
||||
GdkDrawable *win = nsnull;
|
||||
// FIXME
|
||||
if (GTK_IS_LAYOUT((GtkWidget*)mWidget))
|
||||
win = (GdkDrawable*)gdk_window_ref(GTK_LAYOUT((GtkWidget*)mWidget)->bin_window);
|
||||
else
|
||||
win = (GdkDrawable*)gdk_window_ref(((GtkWidget*)mWidget)->window);
|
||||
|
||||
GdkGC *gc = gdk_gc_new(win);
|
||||
|
||||
// init the nsDrawingSurfaceGTK
|
||||
rv = surf->Init(win,gc);
|
||||
|
||||
if (NS_OK == rv)
|
||||
// Init the nsRenderingContextGTK
|
||||
rv = pContext->Init(this, surf);
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
else
|
||||
rv = NS_ERROR_OUT_OF_MEMORY;
|
||||
|
||||
if (NS_OK != rv)
|
||||
{
|
||||
NS_IF_RELEASE(pContext);
|
||||
}
|
||||
|
||||
aContext = pContext;
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::SupportsNativeWidgets(PRBool &aSupportsWidgets)
|
||||
{
|
||||
//XXX it is very critical that this not lie!! MMP
|
||||
// read the comments in the mac code for this
|
||||
aSupportsWidgets = PR_TRUE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::GetScrollBarDimensions(float &aWidth, float &aHeight) const
|
||||
{
|
||||
aWidth = mScrollbarWidth * mPixelsToTwips;
|
||||
aHeight = mScrollbarHeight * mPixelsToTwips;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const
|
||||
{
|
||||
nsresult status = NS_OK;
|
||||
GtkStyle *style = gtk_style_new(); // get the default styles
|
||||
|
||||
switch (anID) {
|
||||
//---------
|
||||
// Colors
|
||||
//---------
|
||||
case eSystemAttr_Color_WindowBackground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
|
||||
break;
|
||||
case eSystemAttr_Color_WindowForeground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
|
||||
break;
|
||||
case eSystemAttr_Color_WidgetBackground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
|
||||
break;
|
||||
case eSystemAttr_Color_WidgetForeground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
|
||||
break;
|
||||
case eSystemAttr_Color_WidgetSelectBackground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_SELECTED]);
|
||||
break;
|
||||
case eSystemAttr_Color_WidgetSelectForeground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_SELECTED]);
|
||||
break;
|
||||
case eSystemAttr_Color_Widget3DHighlight:
|
||||
*aInfo->mColor = NS_RGB(0xa0,0xa0,0xa0);
|
||||
break;
|
||||
case eSystemAttr_Color_Widget3DShadow:
|
||||
*aInfo->mColor = NS_RGB(0x40,0x40,0x40);
|
||||
break;
|
||||
case eSystemAttr_Color_TextBackground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_NORMAL]);
|
||||
break;
|
||||
case eSystemAttr_Color_TextForeground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->fg[GTK_STATE_NORMAL]);
|
||||
break;
|
||||
case eSystemAttr_Color_TextSelectBackground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->bg[GTK_STATE_SELECTED]);
|
||||
break;
|
||||
case eSystemAttr_Color_TextSelectForeground:
|
||||
*aInfo->mColor = GDK_COLOR_TO_NS_RGB(style->text[GTK_STATE_SELECTED]);
|
||||
break;
|
||||
//---------
|
||||
// Size
|
||||
//---------
|
||||
case eSystemAttr_Size_ScrollbarHeight:
|
||||
aInfo->mSize = mScrollbarHeight;
|
||||
break;
|
||||
case eSystemAttr_Size_ScrollbarWidth:
|
||||
aInfo->mSize = mScrollbarWidth;
|
||||
break;
|
||||
case eSystemAttr_Size_WindowTitleHeight:
|
||||
aInfo->mSize = 0;
|
||||
break;
|
||||
case eSystemAttr_Size_WindowBorderWidth:
|
||||
aInfo->mSize = style->klass->xthickness;
|
||||
break;
|
||||
case eSystemAttr_Size_WindowBorderHeight:
|
||||
aInfo->mSize = style->klass->ythickness;
|
||||
break;
|
||||
case eSystemAttr_Size_Widget3DBorder:
|
||||
aInfo->mSize = 4;
|
||||
break;
|
||||
//---------
|
||||
// Fonts
|
||||
//---------
|
||||
case eSystemAttr_Font_Caption:
|
||||
case eSystemAttr_Font_Icon:
|
||||
case eSystemAttr_Font_Menu:
|
||||
case eSystemAttr_Font_MessageBox:
|
||||
case eSystemAttr_Font_SmallCaption:
|
||||
case eSystemAttr_Font_StatusBar:
|
||||
case eSystemAttr_Font_Tooltips:
|
||||
case eSystemAttr_Font_Widget:
|
||||
status = NS_ERROR_FAILURE;
|
||||
break;
|
||||
} // switch
|
||||
|
||||
gtk_style_unref(style);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::GetDrawingSurface(nsIRenderingContext &aContext,
|
||||
nsDrawingSurface &aSurface)
|
||||
{
|
||||
aContext.CreateDrawingSurface(nsnull, 0, aSurface);
|
||||
return nsnull == aSurface ? NS_ERROR_OUT_OF_MEMORY : NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::ConvertPixel(nscolor aColor,
|
||||
PRUint32 & aPixel)
|
||||
{
|
||||
aPixel = ::gdk_rgb_xpixel_from_rgb (NS_TO_GDK_RGB(aColor));
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::CheckFontExistence(const nsString& aFontName)
|
||||
{
|
||||
char **fnames = nsnull;
|
||||
PRInt32 namelen = aFontName.Length() + 1;
|
||||
char *wildstring = (char *)PR_Malloc(namelen + 200);
|
||||
float t2d;
|
||||
GetTwipsToDevUnits(t2d);
|
||||
PRInt32 dpi = NSToIntRound(t2d * 1440);
|
||||
int numnames = 0;
|
||||
XFontStruct *fonts;
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
|
||||
if (nsnull == wildstring)
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
|
||||
if (abs(dpi - 75) < abs(dpi - 100))
|
||||
dpi = 75;
|
||||
else
|
||||
dpi = 100;
|
||||
|
||||
char* fontName = aFontName.ToNewCString();
|
||||
PR_snprintf(wildstring, namelen + 200,
|
||||
"*-%s-*-*-normal--*-*-%d-%d-*-*-*",
|
||||
fontName, dpi, dpi);
|
||||
delete [] fontName;
|
||||
|
||||
fnames = ::XListFontsWithInfo(GDK_DISPLAY(), wildstring, 1, &numnames, &fonts);
|
||||
|
||||
if (numnames > 0)
|
||||
{
|
||||
::XFreeFontInfo(fnames, fonts, numnames);
|
||||
rv = NS_OK;
|
||||
}
|
||||
|
||||
PR_Free(wildstring);
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight)
|
||||
{
|
||||
aWidth = 1;
|
||||
aHeight = 1;
|
||||
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
|
||||
nsIDeviceContext *&aContext)
|
||||
{
|
||||
// Create a Postscript device context
|
||||
aContext = new nsDeviceContextPS();
|
||||
((nsDeviceContextPS *)aContext)->SetSpec(aDevice);
|
||||
NS_ADDREF(aDevice);
|
||||
return((nsDeviceContextPS *) aContext)->Init((nsIDeviceContext*)aContext, (nsIDeviceContext*)this);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::BeginDocument(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::EndDocument(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::BeginPage(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::EndPage(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextGTK::GetDepth(PRUint32& aDepth)
|
||||
{
|
||||
GdkVisual * rgb_visual = gdk_rgb_get_visual();
|
||||
|
||||
gint rgb_depth = rgb_visual->depth;
|
||||
|
||||
aDepth = (PRUint32) rgb_depth;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,79 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsDeviceContextGTK_h___
|
||||
#define nsDeviceContextGTK_h___
|
||||
|
||||
#include "nsDeviceContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsIView.h"
|
||||
#include "nsIRenderingContext.h"
|
||||
|
||||
#include "nsRenderingContextGTK.h"
|
||||
|
||||
class nsDeviceContextGTK : public DeviceContextImpl
|
||||
{
|
||||
public:
|
||||
nsDeviceContextGTK();
|
||||
virtual ~nsDeviceContextGTK();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(nsNativeWidget aNativeWidget);
|
||||
|
||||
NS_IMETHOD CreateRenderingContext(nsIRenderingContext *&aContext);
|
||||
NS_IMETHOD SupportsNativeWidgets(PRBool &aSupportsWidgets);
|
||||
|
||||
NS_IMETHOD GetScrollBarDimensions(float &aWidth, float &aHeight) const;
|
||||
NS_IMETHOD GetSystemAttribute(nsSystemAttrID anID, SystemAttrStruct * aInfo) const;
|
||||
|
||||
//get a low level drawing surface for rendering. the rendering context
|
||||
//that is passed in is used to create the drawing surface if there isn't
|
||||
//already one in the device context. the drawing surface is then cached
|
||||
//in the device context for re-use.
|
||||
|
||||
NS_IMETHOD GetDrawingSurface(nsIRenderingContext &aContext, nsDrawingSurface &aSurface);
|
||||
|
||||
NS_IMETHOD ConvertPixel(nscolor aColor, PRUint32 & aPixel);
|
||||
NS_IMETHOD CheckFontExistence(const nsString& aFontName);
|
||||
|
||||
NS_IMETHOD GetDeviceSurfaceDimensions(PRInt32 &aWidth, PRInt32 &aHeight);
|
||||
|
||||
NS_IMETHOD GetDeviceContextFor(nsIDeviceContextSpec *aDevice,
|
||||
nsIDeviceContext *&aContext);
|
||||
|
||||
NS_IMETHOD BeginDocument(void);
|
||||
NS_IMETHOD EndDocument(void);
|
||||
|
||||
NS_IMETHOD BeginPage(void);
|
||||
NS_IMETHOD EndPage(void);
|
||||
|
||||
NS_IMETHOD GetDepth(PRUint32& aDepth);
|
||||
|
||||
private:
|
||||
PRUint32 mDepth;
|
||||
PRBool mWriteable;
|
||||
nsPaletteInfo mPaletteInfo;
|
||||
PRUint32 mNumCells;
|
||||
PRInt16 mScrollbarHeight;
|
||||
PRInt16 mScrollbarWidth;
|
||||
};
|
||||
|
||||
#endif /* nsDeviceContextGTK_h___ */
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "nsDeviceContextSpecFactoryG.h"
|
||||
#include "nsDeviceContextSpecG.h"
|
||||
#include "nsGfxCIID.h"
|
||||
#include "plstr.h"
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Constructor
|
||||
* @update dc 2/16/98
|
||||
*/
|
||||
nsDeviceContextSpecFactoryGTK :: nsDeviceContextSpecFactoryGTK()
|
||||
{
|
||||
}
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Destructor
|
||||
* @update dc 2/16/98
|
||||
*/
|
||||
nsDeviceContextSpecFactoryGTK :: ~nsDeviceContextSpecFactoryGTK()
|
||||
{
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kDeviceContextSpecFactoryIID, NS_IDEVICE_CONTEXT_SPEC_FACTORY_IID);
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
|
||||
static NS_DEFINE_IID(kDeviceContextSpecCID, NS_DEVICE_CONTEXT_SPEC_CID);
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextSpecFactoryGTK, kDeviceContextSpecFactoryIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecFactoryGTK)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecFactoryGTK)
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Initialize the device context spec factory
|
||||
* @update dc 2/16/98
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextSpecFactoryGTK :: Init(void)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Get a device context specification
|
||||
* @update dc 2/16/98
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextSpecFactoryGTK :: CreateDeviceContextSpec(nsIDeviceContextSpec *aOldSpec,
|
||||
nsIDeviceContextSpec *&aNewSpec,
|
||||
PRBool aQuiet)
|
||||
{
|
||||
nsresult rv = NS_ERROR_FAILURE;
|
||||
nsIDeviceContextSpec *devSpec = nsnull;
|
||||
|
||||
nsComponentManager::CreateInstance(kDeviceContextSpecCID, nsnull, kIDeviceContextSpecIID, (void **)&devSpec);
|
||||
|
||||
if (nsnull != devSpec){
|
||||
if (NS_OK == ((nsDeviceContextSpecGTK *)devSpec)->Init(aQuiet)){
|
||||
aNewSpec = devSpec;
|
||||
rv = NS_OK;
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
@@ -1,41 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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) 1999 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#ifndef nsDeviceContextSpecFactoryG_h___
|
||||
#define nsDeviceContextSpecFactoryG_h___
|
||||
|
||||
#include "nsIDeviceContextSpecFactory.h"
|
||||
#include "nsIDeviceContextSpec.h"
|
||||
|
||||
class nsDeviceContextSpecFactoryGTK : public nsIDeviceContextSpecFactory
|
||||
{
|
||||
public:
|
||||
nsDeviceContextSpecFactoryGTK();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(void);
|
||||
NS_IMETHOD CreateDeviceContextSpec(nsIDeviceContextSpec *aOldSpec,
|
||||
nsIDeviceContextSpec *&aNewSpec,
|
||||
PRBool aQuiet);
|
||||
|
||||
protected:
|
||||
virtual ~nsDeviceContextSpecFactoryGTK();
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,197 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 "nsDeviceContextSpecG.h"
|
||||
#include "prenv.h" /* for PR_GetEnv */
|
||||
|
||||
//#include "prmem.h"
|
||||
//#include "plstr.h"
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Construct the nsDeviceContextSpecGTK
|
||||
* @update dc 12/02/98
|
||||
*/
|
||||
nsDeviceContextSpecGTK :: nsDeviceContextSpecGTK()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
}
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Destroy the nsDeviceContextSpecGTK
|
||||
* @update dc 2/15/98
|
||||
*/
|
||||
nsDeviceContextSpecGTK :: ~nsDeviceContextSpecGTK()
|
||||
{
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecIID, NS_IDEVICE_CONTEXT_SPEC_IID);
|
||||
static NS_DEFINE_IID(kIDeviceContextSpecPSIID, NS_IDEVICE_CONTEXT_SPEC_PS_IID);
|
||||
|
||||
#if 0
|
||||
NS_IMPL_QUERY_INTERFACE(nsDeviceContextSpecGTK, kDeviceContextSpecIID)
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecGTK)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecGTK)
|
||||
#endif
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(kIDeviceContextSpecIID))
|
||||
{
|
||||
nsIDeviceContextSpec* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(kIDeviceContextSpecPSIID))
|
||||
{
|
||||
nsIDeviceContextSpecPS* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
if (aIID.Equals(kISupportsIID))
|
||||
{
|
||||
nsIDeviceContextSpec* tmp = this;
|
||||
nsISupports* tmp2 = tmp;
|
||||
*aInstancePtr = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDeviceContextSpecGTK)
|
||||
NS_IMPL_RELEASE(nsDeviceContextSpecGTK)
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Initialize the nsDeviceContextSpecGTK
|
||||
* @update dc 2/15/98
|
||||
* @update syd 3/2/99
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: Init(PRBool aQuiet)
|
||||
{
|
||||
char *path;
|
||||
|
||||
// XXX these settings should eventually come out of preferences
|
||||
|
||||
mPrData.toPrinter = PR_TRUE;
|
||||
mPrData.fpf = PR_TRUE;
|
||||
mPrData.grayscale = PR_FALSE;
|
||||
mPrData.size = NS_LETTER_SIZE;
|
||||
sprintf( mPrData.command, "lpr" );
|
||||
|
||||
// PWD, HOME, or fail
|
||||
|
||||
if ( ( path = PR_GetEnv( "PWD" ) ) == (char *) NULL )
|
||||
if ( ( path = PR_GetEnv( "HOME" ) ) == (char *) NULL )
|
||||
strcpy( mPrData.path, "netscape.ps" );
|
||||
if ( path != (char *) NULL )
|
||||
sprintf( mPrData.path, "%s/netscape.ps", path );
|
||||
else
|
||||
return NS_ERROR_FAILURE;
|
||||
|
||||
::UnixPrDialog( &mPrData );
|
||||
if ( mPrData.cancel == PR_TRUE )
|
||||
return NS_ERROR_FAILURE;
|
||||
else
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetToPrinter( PRBool &aToPrinter )
|
||||
{
|
||||
aToPrinter = mPrData.toPrinter;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetFirstPageFirst ( PRBool &aFpf )
|
||||
{
|
||||
aFpf = mPrData.fpf;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetGrayscale ( PRBool &aGrayscale )
|
||||
{
|
||||
aGrayscale = mPrData.grayscale;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetSize ( int &aSize )
|
||||
{
|
||||
aSize = mPrData.size;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetTopMargin ( float &value )
|
||||
{
|
||||
value = mPrData.top;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetBottomMargin ( float &value )
|
||||
{
|
||||
value = mPrData.bottom;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetRightMargin ( float &value )
|
||||
{
|
||||
value = mPrData.right;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetLeftMargin ( float &value )
|
||||
{
|
||||
value = mPrData.left;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetCommand ( char **aCommand )
|
||||
{
|
||||
*aCommand = &mPrData.command[0];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetPath ( char **aPath )
|
||||
{
|
||||
*aPath = &mPrData.path[0];
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: GetUserCancelled( PRBool &aCancel )
|
||||
{
|
||||
aCancel = mPrData.cancel;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/** -------------------------------------------------------
|
||||
* Closes the printmanager if it is open.
|
||||
* @update dc 2/15/98
|
||||
*/
|
||||
NS_IMETHODIMP nsDeviceContextSpecGTK :: ClosePrintManager()
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,97 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsDeviceContextSpecG_h___
|
||||
#define nsDeviceContextSpecG_h___
|
||||
|
||||
#include "nsIDeviceContextSpec.h"
|
||||
#include "nsDeviceContextSpecG.h"
|
||||
#include "nsIDeviceContextSpecPS.h"
|
||||
|
||||
#include "nsPrintdGTK.h"
|
||||
|
||||
class nsDeviceContextSpecGTK : public nsIDeviceContextSpec ,
|
||||
public nsIDeviceContextSpecPS
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Construct a nsDeviceContextSpecMac, which is an object which contains and manages a mac printrecord
|
||||
* @update dc 12/02/98
|
||||
*/
|
||||
nsDeviceContextSpecGTK();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
* Initialize the nsDeviceContextSpecMac for use. This will allocate a printrecord for use
|
||||
* @update dc 2/16/98
|
||||
* @param aQuiet if PR_TRUE, prevent the need for user intervention
|
||||
* in obtaining device context spec. if nsnull is passed in for
|
||||
* the aOldSpec, this will typically result in getting a device
|
||||
* context spec for the default output device (i.e. default
|
||||
* printer).
|
||||
* @return error status
|
||||
*/
|
||||
NS_IMETHOD Init(PRBool aQuiet);
|
||||
|
||||
|
||||
/**
|
||||
* Closes the printmanager if it is open.
|
||||
* @update dc 2/13/98
|
||||
* @update syd 3/20/99
|
||||
* @return error status
|
||||
*/
|
||||
|
||||
NS_IMETHOD ClosePrintManager();
|
||||
|
||||
NS_IMETHOD GetToPrinter( PRBool &aToPrinter );
|
||||
|
||||
NS_IMETHOD GetFirstPageFirst ( PRBool &aFpf );
|
||||
|
||||
NS_IMETHOD GetGrayscale( PRBool &aGrayscale );
|
||||
|
||||
NS_IMETHOD GetSize ( int &aSize );
|
||||
|
||||
NS_IMETHOD GetTopMargin ( float &value );
|
||||
|
||||
NS_IMETHOD GetBottomMargin ( float &value );
|
||||
|
||||
NS_IMETHOD GetLeftMargin ( float &value );
|
||||
|
||||
NS_IMETHOD GetRightMargin ( float &value );
|
||||
|
||||
NS_IMETHOD GetCommand ( char **aCommand );
|
||||
|
||||
NS_IMETHOD GetPath ( char **aPath );
|
||||
|
||||
NS_IMETHOD GetUserCancelled( PRBool &aCancel );
|
||||
|
||||
protected:
|
||||
/**
|
||||
* Destuct a nsDeviceContextSpecMac, this will release the printrecord
|
||||
* @update dc 2/16/98
|
||||
*/
|
||||
virtual ~nsDeviceContextSpecGTK();
|
||||
|
||||
protected:
|
||||
|
||||
UnixPrData mPrData;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,367 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 defined (HAVE_IPC_H) && defined (HAVE_SHM_H) && defined (HAVE_XSHM_H)
|
||||
#define USE_SHM
|
||||
#endif
|
||||
|
||||
//#define USE_SHM
|
||||
|
||||
#include <gdk/gdkx.h>
|
||||
#include <gdk/gdkprivate.h>
|
||||
#ifdef USE_SHM
|
||||
#include <sys/ipc.h>
|
||||
#include <sys/shm.h>
|
||||
#include <X11/extensions/XShm.h>
|
||||
#endif /* USE_SHM */
|
||||
#include "nsDrawingSurfaceGTK.h"
|
||||
|
||||
static NS_DEFINE_IID(kIDrawingSurfaceIID, NS_IDRAWING_SURFACE_IID);
|
||||
static NS_DEFINE_IID(kIDrawingSurfaceGTKIID, NS_IDRAWING_SURFACE_GTK_IID);
|
||||
|
||||
nsDrawingSurfaceGTK :: nsDrawingSurfaceGTK()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
GdkVisual *v;
|
||||
|
||||
mPixmap = nsnull;
|
||||
mGC = nsnull;
|
||||
mDepth = 0;
|
||||
mWidth = mHeight = 0;
|
||||
mFlags = 0;
|
||||
|
||||
mImage = nsnull;
|
||||
mLockWidth = mLockHeight = 0;
|
||||
mLockFlags = 0;
|
||||
mLocked = PR_FALSE;
|
||||
|
||||
v = ::gdk_rgb_get_visual();
|
||||
|
||||
mPixFormat.mRedMask = v->red_mask;
|
||||
mPixFormat.mGreenMask = v->green_mask;
|
||||
mPixFormat.mBlueMask = v->blue_mask;
|
||||
// FIXME
|
||||
mPixFormat.mAlphaMask = 0;
|
||||
|
||||
mPixFormat.mRedShift = v->red_shift;
|
||||
mPixFormat.mGreenShift = v->green_shift;
|
||||
mPixFormat.mBlueShift = v->blue_shift;
|
||||
// FIXME
|
||||
mPixFormat.mAlphaShift = 0;
|
||||
|
||||
mDepth = v->depth;
|
||||
}
|
||||
|
||||
nsDrawingSurfaceGTK :: ~nsDrawingSurfaceGTK()
|
||||
{
|
||||
if (mPixmap)
|
||||
::gdk_pixmap_unref(mPixmap);
|
||||
|
||||
if (mImage)
|
||||
::gdk_image_destroy(mImage);
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: QueryInterface(REFNSIID aIID, void** aInstancePtr)
|
||||
{
|
||||
if (nsnull == aInstancePtr)
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
|
||||
if (aIID.Equals(kIDrawingSurfaceIID))
|
||||
{
|
||||
nsIDrawingSurface* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
if (aIID.Equals(kIDrawingSurfaceGTKIID))
|
||||
{
|
||||
nsDrawingSurfaceGTK* tmp = this;
|
||||
*aInstancePtr = (void*) tmp;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
|
||||
if (aIID.Equals(kISupportsIID))
|
||||
{
|
||||
nsIDrawingSurface* tmp = this;
|
||||
nsISupports* tmp2 = tmp;
|
||||
*aInstancePtr = (void*) tmp2;
|
||||
NS_ADDREF_THIS();
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
NS_IMPL_ADDREF(nsDrawingSurfaceGTK);
|
||||
NS_IMPL_RELEASE(nsDrawingSurfaceGTK);
|
||||
|
||||
|
||||
/**
|
||||
* Lock a rect of a drawing surface and return a
|
||||
* pointer to the upper left hand corner of the
|
||||
* bitmap.
|
||||
* @param aX x position of subrect of bitmap
|
||||
* @param aY y position of subrect of bitmap
|
||||
* @param aWidth width of subrect of bitmap
|
||||
* @param aHeight height of subrect of bitmap
|
||||
* @param aBits out parameter for upper left hand
|
||||
* corner of bitmap
|
||||
* @param aStride out parameter for number of bytes
|
||||
* to add to aBits to go from scanline to scanline
|
||||
* @param aWidthBytes out parameter for number of
|
||||
* bytes per line in aBits to process aWidth pixels
|
||||
* @return error status
|
||||
*
|
||||
**/
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: Lock(PRInt32 aX, PRInt32 aY,
|
||||
PRUint32 aWidth, PRUint32 aHeight,
|
||||
void **aBits, PRInt32 *aStride,
|
||||
PRInt32 *aWidthBytes, PRUint32 aFlags)
|
||||
{
|
||||
#if 0
|
||||
g_print("nsDrawingSurfaceGTK::Lock() called\n" \
|
||||
" aX = %i, aY = %i,\n" \
|
||||
" aWidth = %i, aHeight = %i,\n" \
|
||||
" aBits, aStride, aWidthBytes,\n" \
|
||||
" aFlags = %i\n", aX, aY, aWidth, aHeight, aFlags);
|
||||
#endif
|
||||
|
||||
if (mLocked)
|
||||
{
|
||||
NS_ASSERTION(0, "nested lock attempt");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
mLocked = PR_TRUE;
|
||||
|
||||
mLockX = aX;
|
||||
mLockY = aY;
|
||||
mLockWidth = aWidth;
|
||||
mLockHeight = aHeight;
|
||||
mLockFlags = aFlags;
|
||||
|
||||
// Obtain an ximage from the pixmap.
|
||||
#ifdef USE_SHM
|
||||
if (gdk_get_use_xshm())
|
||||
{
|
||||
mImage = gdk_image_new(GDK_IMAGE_FASTEST,
|
||||
gdk_rgb_get_visual(),
|
||||
mLockWidth,
|
||||
mLockHeight);
|
||||
|
||||
XShmGetImage(GDK_DISPLAY(),
|
||||
GDK_WINDOW_XWINDOW(mPixmap),
|
||||
GDK_IMAGE_XIMAGE(mImage),
|
||||
mLockX, mLockY,
|
||||
0xFFFFFFFF);
|
||||
|
||||
gdk_flush();
|
||||
}
|
||||
else
|
||||
{
|
||||
#endif /* USE_SHM */
|
||||
mImage = ::gdk_image_get(mPixmap, mLockX, mLockY, mLockWidth, mLockHeight);
|
||||
#ifdef USE_SHM
|
||||
}
|
||||
#endif /* USE_SHM */
|
||||
|
||||
*aBits = GDK_IMAGE_XIMAGE(mImage)->data;
|
||||
|
||||
*aWidthBytes = GDK_IMAGE_XIMAGE(mImage)->bytes_per_line;
|
||||
*aStride = GDK_IMAGE_XIMAGE(mImage)->bytes_per_line;
|
||||
|
||||
|
||||
#if 0
|
||||
int bytes_per_line = GDK_IMAGE_XIMAGE(mImage)->bytes_per_line;
|
||||
|
||||
//
|
||||
// All this code is a an attempt to set the stride width properly.
|
||||
// Needs to be cleaned up alot. For now, it will only work in the
|
||||
// case where aWidthBytes and aStride are the same. One is assigned to
|
||||
// the other.
|
||||
//
|
||||
|
||||
*aWidthBytes = mImage->bpl;
|
||||
*aStride = mImage->bpl;
|
||||
|
||||
int width_in_pixels = *aWidthBytes << 8;
|
||||
|
||||
|
||||
int bitmap_pad = GDK_IMAGE_XIMAGE(mImage)->bitmap_pad;
|
||||
int depth = GDK_IMAGE_XIMAGE(mImage)->depth;
|
||||
|
||||
#define RASWIDTH8(width, bpp) (width)
|
||||
#define RASWIDTH16(width, bpp) ((((width) * (bpp) + 15) >> 4) << 1)
|
||||
#define RASWIDTH32(width, bpp) ((((width) * (bpp) + 31) >> 5) << 2)
|
||||
|
||||
switch(bitmap_pad)
|
||||
{
|
||||
case 8:
|
||||
*aStride = RASWIDTH8(aWidth,bitmap_pad);
|
||||
break;
|
||||
|
||||
case 16:
|
||||
*aStride = bytes_per_line;
|
||||
*aStride = RASWIDTH16(aWidth,bitmap_pad);
|
||||
break;
|
||||
|
||||
case 32:
|
||||
*aStride = bytes_per_line;
|
||||
*aStride = RASWIDTH32(aWidth,bitmap_pad);
|
||||
break;
|
||||
|
||||
default:
|
||||
|
||||
NS_ASSERTION(nsnull,"something got screwed");
|
||||
|
||||
}
|
||||
|
||||
*aStride = (*aWidthBytes) + ((bitmap_pad >> 3) - 1);
|
||||
|
||||
GDK_IMAGE_XIMAGE(mImage)->bitmap_pad;
|
||||
|
||||
*aWidthBytes = mImage->bpl;
|
||||
#endif
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: Unlock(void)
|
||||
{
|
||||
// g_print("nsDrawingSurfaceGTK::UnLock() called\n");
|
||||
if (!mLocked)
|
||||
{
|
||||
NS_ASSERTION(0, "attempting to unlock an DS that isn't locked");
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
|
||||
// If the lock was not read only, put the bits back on the pixmap
|
||||
if (!(mLockFlags & NS_LOCK_SURFACE_READ_ONLY))
|
||||
{
|
||||
#if 0
|
||||
g_print("gdk_draw_image(pixmap=%p,lockx=%d,locky=%d,lockw=%d,lockh=%d)\n",
|
||||
mPixmap,
|
||||
mLockX, mLockY,
|
||||
mLockWidth, mLockHeight);
|
||||
#endif
|
||||
|
||||
gdk_draw_image(mPixmap,
|
||||
mGC,
|
||||
mImage,
|
||||
0, 0,
|
||||
mLockX, mLockY,
|
||||
mLockWidth, mLockHeight);
|
||||
|
||||
}
|
||||
|
||||
// FIXME if we are using shared mem, we shouldn't destroy the image...
|
||||
if (mImage)
|
||||
::gdk_image_destroy(mImage);
|
||||
mImage = nsnull;
|
||||
|
||||
mLocked = PR_FALSE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight)
|
||||
{
|
||||
*aWidth = mWidth;
|
||||
*aHeight = mHeight;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: IsOffscreen(PRBool *aOffScreen)
|
||||
{
|
||||
*aOffScreen = mIsOffscreen;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: IsPixelAddressable(PRBool *aAddressable)
|
||||
{
|
||||
// FIXME
|
||||
*aAddressable = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetPixelFormat(nsPixelFormat *aFormat)
|
||||
{
|
||||
*aFormat = mPixFormat;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkDrawable *aDrawable, GdkGC *aGC)
|
||||
{
|
||||
mGC = aGC;
|
||||
mPixmap = aDrawable;
|
||||
// this is definatly going to be on the screen, as it will be the window of a
|
||||
// widget or something.
|
||||
mIsOffscreen = PR_FALSE;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: Init(GdkGC *aGC, PRUint32 aWidth,
|
||||
PRUint32 aHeight, PRUint32 aFlags)
|
||||
{
|
||||
// ::g_return_val_if_fail (aGC != nsnull, NS_ERROR_FAILURE);
|
||||
// ::g_return_val_if_fail ((aWidth > 0) && (aHeight > 0), NS_ERROR_FAILURE);
|
||||
|
||||
mGC = aGC;
|
||||
mWidth = aWidth;
|
||||
mHeight = aHeight;
|
||||
mFlags = aFlags;
|
||||
|
||||
// we can draw on this offscreen because it has no parent
|
||||
mIsOffscreen = PR_TRUE;
|
||||
|
||||
mPixmap = ::gdk_pixmap_new(nsnull, mWidth, mHeight, mDepth);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: GetGC(GdkGC *aGC)
|
||||
{
|
||||
aGC = ::gdk_gc_ref(mGC);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsDrawingSurfaceGTK :: ReleaseGC(void)
|
||||
{
|
||||
::gdk_gc_unref(mGC);
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
/* below are utility functions used mostly for nsRenderingContext and nsImage
|
||||
* to plug into gdk_* functions for drawing. You should not set a pointer
|
||||
* that might hang around with the return from these. instead use the ones
|
||||
* above. pav
|
||||
*/
|
||||
GdkGC *nsDrawingSurfaceGTK::GetGC(void)
|
||||
{
|
||||
return mGC;
|
||||
}
|
||||
|
||||
GdkDrawable *nsDrawingSurfaceGTK::GetDrawable(void)
|
||||
{
|
||||
return mPixmap;
|
||||
}
|
||||
|
||||
@@ -1,85 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsDrawingSurfaceGTK_h___
|
||||
#define nsDrawingSurfaceGTK_h___
|
||||
|
||||
#include "nsIDrawingSurface.h"
|
||||
#include "nsIDrawingSurfaceGTK.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
class nsDrawingSurfaceGTK : public nsIDrawingSurface,
|
||||
public nsIDrawingSurfaceGTK
|
||||
{
|
||||
public:
|
||||
nsDrawingSurfaceGTK();
|
||||
virtual ~nsDrawingSurfaceGTK();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
//nsIDrawingSurface interface
|
||||
|
||||
NS_IMETHOD Lock(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
|
||||
void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
|
||||
PRUint32 aFlags);
|
||||
NS_IMETHOD Unlock(void);
|
||||
NS_IMETHOD GetDimensions(PRUint32 *aWidth, PRUint32 *aHeight);
|
||||
NS_IMETHOD IsOffscreen(PRBool *aOffScreen);
|
||||
NS_IMETHOD IsPixelAddressable(PRBool *aAddressable);
|
||||
NS_IMETHOD GetPixelFormat(nsPixelFormat *aFormat);
|
||||
|
||||
//nsIDrawingSurfaceGTK interface
|
||||
|
||||
NS_IMETHOD Init(GdkDrawable *aDrawable, GdkGC *aGC);
|
||||
NS_IMETHOD Init(GdkGC *aGC, PRUint32 aWidth, PRUint32 aHeight, PRUint32 aFlags);
|
||||
|
||||
/* get the GC and manage the GdkGC's refcount */
|
||||
NS_IMETHOD GetGC(GdkGC *aGC);
|
||||
NS_IMETHOD ReleaseGC(void);
|
||||
|
||||
/* below are utility functions used mostly for nsRenderingContext and nsImage
|
||||
* to plug into gdk_* functions for drawing. You should not set a pointer
|
||||
* that might hang around with the return from these. instead use the ones
|
||||
* above. pav
|
||||
*/
|
||||
GdkGC *GetGC(void);
|
||||
GdkDrawable *GetDrawable(void);
|
||||
|
||||
private:
|
||||
/* general */
|
||||
GdkPixmap *mPixmap;
|
||||
GdkGC *mGC;
|
||||
gint mDepth;
|
||||
nsPixelFormat mPixFormat;
|
||||
PRUint32 mWidth;
|
||||
PRUint32 mHeight;
|
||||
PRUint32 mFlags;
|
||||
PRBool mIsOffscreen;
|
||||
|
||||
/* for locks */
|
||||
GdkImage *mImage;
|
||||
PRInt32 mLockX;
|
||||
PRInt32 mLockY;
|
||||
PRUint32 mLockWidth;
|
||||
PRUint32 mLockHeight;
|
||||
PRUint32 mLockFlags;
|
||||
PRBool mLocked;
|
||||
};
|
||||
|
||||
#endif
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,162 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsFontMetricsGTK_h__
|
||||
#define nsFontMetricsGTK_h__
|
||||
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsString.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsDeviceContextGTK.h"
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#define FONT_SWITCHING
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
#ifdef ADD_GLYPH
|
||||
#undef ADD_GLYPH
|
||||
#endif
|
||||
#define ADD_GLYPH(map, g) (map)[(g) >> 3] |= (1 << ((g) & 7))
|
||||
|
||||
#ifdef FONT_HAS_GLYPH
|
||||
#undef FONT_HAS_GLYPH
|
||||
#endif
|
||||
#define FONT_HAS_GLYPH(map, g) (((map)[(g) >> 3] >> ((g) & 7)) & 1)
|
||||
|
||||
typedef struct nsFontCharSetInfo nsFontCharSetInfo;
|
||||
|
||||
typedef gint (*nsFontCharSetConverter)(nsFontCharSetInfo* aSelf,
|
||||
const PRUnichar* aSrcBuf, PRUint32 aSrcLen, PRUint8* aDestBuf,
|
||||
PRUint32 aDestLen);
|
||||
|
||||
struct nsFontCharSet;
|
||||
class nsFontMetricsGTK;
|
||||
|
||||
struct nsFontGTK
|
||||
{
|
||||
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||
|
||||
void LoadFont(nsFontCharSet* aCharSet, nsFontMetricsGTK* aMetrics);
|
||||
|
||||
GdkFont* mFont;
|
||||
PRUint8* mMap;
|
||||
nsFontCharSetInfo* mCharSetInfo;
|
||||
char* mName;
|
||||
PRUint16 mSize;
|
||||
PRUint16 mActualSize;
|
||||
PRInt16 mBaselineAdjust;
|
||||
};
|
||||
|
||||
struct nsFontStretch;
|
||||
struct nsFontFamily;
|
||||
typedef struct nsFontSearch nsFontSearch;
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
|
||||
class nsFontMetricsGTK : public nsIFontMetrics
|
||||
{
|
||||
public:
|
||||
nsFontMetricsGTK();
|
||||
virtual ~nsFontMetricsGTK();
|
||||
|
||||
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(const nsFont& aFont, nsIDeviceContext* aContext);
|
||||
NS_IMETHOD Destroy();
|
||||
|
||||
NS_IMETHOD GetXHeight(nscoord& aResult);
|
||||
NS_IMETHOD GetSuperscriptOffset(nscoord& aResult);
|
||||
NS_IMETHOD GetSubscriptOffset(nscoord& aResult);
|
||||
NS_IMETHOD GetStrikeout(nscoord& aOffset, nscoord& aSize);
|
||||
NS_IMETHOD GetUnderline(nscoord& aOffset, nscoord& aSize);
|
||||
|
||||
NS_IMETHOD GetHeight(nscoord &aHeight);
|
||||
NS_IMETHOD GetLeading(nscoord &aLeading);
|
||||
NS_IMETHOD GetMaxAscent(nscoord &aAscent);
|
||||
NS_IMETHOD GetMaxDescent(nscoord &aDescent);
|
||||
NS_IMETHOD GetMaxAdvance(nscoord &aAdvance);
|
||||
NS_IMETHOD GetFont(const nsFont *&aFont);
|
||||
NS_IMETHOD GetFontHandle(nsFontHandle &aHandle);
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
nsFontGTK* FindFont(PRUnichar aChar);
|
||||
static gint GetWidth(nsFontGTK* aFont, const PRUnichar* aString,
|
||||
PRUint32 aLength);
|
||||
static void DrawString(nsDrawingSurfaceGTK* aSurface, nsFontGTK* aFont,
|
||||
nscoord aX, nscoord aY, const PRUnichar* aString,
|
||||
PRUint32 aLength);
|
||||
static void InitFonts(void);
|
||||
|
||||
friend void PickASizeAndLoad(nsFontSearch* aSearch, nsFontStretch* aStretch,
|
||||
nsFontCharSet* aCharSet);
|
||||
friend void TryCharSet(nsFontSearch* aSearch, nsFontCharSet* aCharSet);
|
||||
friend void TryFamily(nsFontSearch* aSearch, nsFontFamily* aFamily);
|
||||
friend struct nsFontGTK;
|
||||
|
||||
nsFontGTK **mLoadedFonts;
|
||||
PRUint16 mLoadedFontsAlloc;
|
||||
PRUint16 mLoadedFontsCount;
|
||||
|
||||
nsString *mFonts;
|
||||
PRUint16 mFontsAlloc;
|
||||
PRUint16 mFontsCount;
|
||||
PRUint16 mFontsIndex;
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
|
||||
protected:
|
||||
char *PickAppropriateSize(char **names, XFontStruct *fonts, int cnt, nscoord desired);
|
||||
void RealizeFont();
|
||||
|
||||
nsIDeviceContext *mDeviceContext;
|
||||
nsFont *mFont;
|
||||
GdkFont *mFontHandle;
|
||||
|
||||
nscoord mHeight;
|
||||
nscoord mAscent;
|
||||
nscoord mDescent;
|
||||
nscoord mLeading;
|
||||
nscoord mMaxAscent;
|
||||
nscoord mMaxDescent;
|
||||
nscoord mMaxAdvance;
|
||||
nscoord mXHeight;
|
||||
nscoord mSuperscriptOffset;
|
||||
nscoord mSubscriptOffset;
|
||||
nscoord mStrikeoutSize;
|
||||
nscoord mStrikeoutOffset;
|
||||
nscoord mUnderlineSize;
|
||||
nscoord mUnderlineOffset;
|
||||
|
||||
#ifdef FONT_SWITCHING
|
||||
|
||||
PRUint16 mPixelSize;
|
||||
PRUint8 mStretchIndex;
|
||||
PRUint8 mStyleIndex;
|
||||
|
||||
#endif /* FONT_SWITCHING */
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,205 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 <gtk/gtk.h>
|
||||
|
||||
#include "nscore.h"
|
||||
#include "nsIFactory.h"
|
||||
#include "nsISupports.h"
|
||||
#include "nsGfxCIID.h"
|
||||
#include "nsFontMetricsGTK.h"
|
||||
#include "nsRenderingContextGTK.h"
|
||||
#include "nsImageGTK.h"
|
||||
#include "nsDeviceContextGTK.h"
|
||||
#include "nsRegionGTK.h"
|
||||
#include "nsBlender.h"
|
||||
#include "nsDeviceContextSpecG.h"
|
||||
#include "nsDeviceContextSpecFactoryG.h"
|
||||
#include "nsIDeviceContextSpecPS.h"
|
||||
|
||||
static NS_DEFINE_IID(kCFontMetrics, NS_FONT_METRICS_CID);
|
||||
static NS_DEFINE_IID(kCRenderingContext, NS_RENDERING_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kCImage, NS_IMAGE_CID);
|
||||
static NS_DEFINE_IID(kCDeviceContext, NS_DEVICE_CONTEXT_CID);
|
||||
static NS_DEFINE_IID(kCRegion, NS_REGION_CID);
|
||||
|
||||
static NS_DEFINE_IID(kCBlender, NS_BLENDER_CID);
|
||||
|
||||
static NS_DEFINE_IID(kISupportsIID, NS_ISUPPORTS_IID);
|
||||
static NS_DEFINE_IID(kIFactoryIID, NS_IFACTORY_IID);
|
||||
|
||||
static NS_DEFINE_IID(kCDeviceContextSpec, NS_DEVICE_CONTEXT_SPEC_CID);
|
||||
static NS_DEFINE_IID(kCDeviceContextSpecFactory, NS_DEVICE_CONTEXT_SPEC_FACTORY_CID);
|
||||
|
||||
|
||||
class nsGfxFactoryGTK : public nsIFactory
|
||||
{
|
||||
public:
|
||||
// nsISupports methods
|
||||
NS_IMETHOD QueryInterface(const nsIID &aIID,
|
||||
void **aResult);
|
||||
NS_IMETHOD_(nsrefcnt) AddRef(void);
|
||||
NS_IMETHOD_(nsrefcnt) Release(void);
|
||||
|
||||
// nsIFactory methods
|
||||
NS_IMETHOD CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult);
|
||||
|
||||
NS_IMETHOD LockFactory(PRBool aLock);
|
||||
|
||||
nsGfxFactoryGTK(const nsCID &aClass);
|
||||
virtual ~nsGfxFactoryGTK();
|
||||
|
||||
private:
|
||||
nsrefcnt mRefCnt;
|
||||
nsCID mClassID;
|
||||
};
|
||||
|
||||
nsGfxFactoryGTK::nsGfxFactoryGTK(const nsCID &aClass)
|
||||
{
|
||||
mRefCnt = 0;
|
||||
mClassID = aClass;
|
||||
}
|
||||
|
||||
nsGfxFactoryGTK::~nsGfxFactoryGTK()
|
||||
{
|
||||
NS_ASSERTION(mRefCnt == 0, "non-zero refcnt at destruction");
|
||||
}
|
||||
|
||||
nsresult nsGfxFactoryGTK::QueryInterface(const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
// Always NULL result, in case of failure
|
||||
*aResult = NULL;
|
||||
|
||||
if (aIID.Equals(kISupportsIID)) {
|
||||
*aResult = (void *)(nsISupports*)this;
|
||||
} else if (aIID.Equals(kIFactoryIID)) {
|
||||
*aResult = (void *)(nsIFactory*)this;
|
||||
}
|
||||
|
||||
if (*aResult == NULL) {
|
||||
return NS_NOINTERFACE;
|
||||
}
|
||||
|
||||
AddRef(); // Increase reference count for caller
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
nsrefcnt nsGfxFactoryGTK::AddRef()
|
||||
{
|
||||
return ++mRefCnt;
|
||||
}
|
||||
|
||||
nsrefcnt nsGfxFactoryGTK::Release()
|
||||
{
|
||||
if (--mRefCnt == 0) {
|
||||
delete this;
|
||||
return 0; // Don't access mRefCnt after deleting!
|
||||
}
|
||||
return mRefCnt;
|
||||
}
|
||||
|
||||
nsresult nsGfxFactoryGTK::CreateInstance(nsISupports *aOuter,
|
||||
const nsIID &aIID,
|
||||
void **aResult)
|
||||
{
|
||||
if (aResult == NULL) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aResult = NULL;
|
||||
|
||||
nsISupports *inst = nsnull;
|
||||
|
||||
if (mClassID.Equals(kCFontMetrics)) {
|
||||
inst = (nsISupports *)new nsFontMetricsGTK();
|
||||
}
|
||||
else if (mClassID.Equals(kCDeviceContext)) {
|
||||
inst = (nsISupports *)new nsDeviceContextGTK();
|
||||
}
|
||||
else if (mClassID.Equals(kCRenderingContext)) {
|
||||
inst = (nsISupports *)new nsRenderingContextGTK();
|
||||
}
|
||||
else if (mClassID.Equals(kCImage)) {
|
||||
inst = (nsISupports *)new nsImageGTK();
|
||||
}
|
||||
else if (mClassID.Equals(kCRegion)) {
|
||||
inst = (nsISupports *)new nsRegionGTK();
|
||||
}
|
||||
else if (mClassID.Equals(kCBlender)) {
|
||||
inst = (nsISupports *)new nsBlender;
|
||||
}
|
||||
else if (mClassID.Equals(kCDeviceContextSpec)) {
|
||||
nsDeviceContextSpecGTK* dcs;
|
||||
NS_NEWXPCOM(dcs, nsDeviceContextSpecGTK);
|
||||
inst = (nsISupports *)((nsIDeviceContextSpecPS *)dcs);
|
||||
}
|
||||
else if (mClassID.Equals(kCDeviceContextSpecFactory)) {
|
||||
nsDeviceContextSpecFactoryGTK* dcs;
|
||||
NS_NEWXPCOM(dcs, nsDeviceContextSpecFactoryGTK);
|
||||
inst = (nsISupports *)dcs;
|
||||
}
|
||||
|
||||
if (inst == NULL) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
nsresult res = inst->QueryInterface(aIID, aResult);
|
||||
|
||||
if (res != NS_OK) {
|
||||
// We didn't get the right interface, so clean up
|
||||
delete inst;
|
||||
}
|
||||
// else {
|
||||
// inst->Release();
|
||||
// }
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
nsresult nsGfxFactoryGTK::LockFactory(PRBool aLock)
|
||||
{
|
||||
// Not implemented in simplest case.
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
// return the proper factory to the caller
|
||||
extern "C" NS_GFXNONXP nsresult NSGetFactory(nsISupports* servMgr,
|
||||
const nsCID &aClass,
|
||||
const char *aClassName,
|
||||
const char *aProgID,
|
||||
nsIFactory **aFactory)
|
||||
{
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_NULL_POINTER;
|
||||
}
|
||||
|
||||
*aFactory = new nsGfxFactoryGTK(aClass);
|
||||
|
||||
if (nsnull == aFactory) {
|
||||
return NS_ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
|
||||
return (*aFactory)->QueryInterface(kIFactoryIID, (void**)aFactory);
|
||||
}
|
||||
@@ -1,77 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsIDrawingSurfaceGTK_h___
|
||||
#define nsIDrawingSurfaceGTK_h___
|
||||
|
||||
#include "nsIDrawingSurface.h"
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
// windows specific drawing surface method set
|
||||
|
||||
#define NS_IDRAWING_SURFACE_GTK_IID \
|
||||
{ 0x1ed958b0, 0xcab6, 0x11d2, \
|
||||
{ 0xa8, 0x49, 0x00, 0x40, 0x95, 0x9a, 0x28, 0xc9 } }
|
||||
|
||||
class nsIDrawingSurfaceGTK : public nsISupports
|
||||
{
|
||||
public:
|
||||
/**
|
||||
* Initialize a drawing surface using a windows DC.
|
||||
* aDC is "owned" by the drawing surface until the drawing
|
||||
* surface is destroyed.
|
||||
* @param aDC HDC to initialize drawing surface with
|
||||
* @return error status
|
||||
**/
|
||||
NS_IMETHOD Init(GdkDrawable *aDrawable, GdkGC *aGC) = 0;
|
||||
|
||||
/**
|
||||
* Initialize an offscreen drawing surface using a
|
||||
* windows DC. aDC is not "owned" by this drawing surface, instead
|
||||
* it is used to create a drawing surface compatible
|
||||
* with aDC. if width or height are less than zero, aDC will
|
||||
* be created with no offscreen bitmap installed.
|
||||
* @param aDC HDC to initialize drawing surface with
|
||||
* @param aWidth width of drawing surface
|
||||
* @param aHeight height of drawing surface
|
||||
* @param aFlags flags used to control type of drawing
|
||||
* surface created
|
||||
* @return error status
|
||||
**/
|
||||
NS_IMETHOD Init(GdkGC *aGC, PRUint32 aWidth, PRUint32 aHeight,
|
||||
PRUint32 aFlags) = 0;
|
||||
|
||||
/**
|
||||
* Get a windows DC that represents the drawing surface.
|
||||
* GetDC() must be paired with ReleaseDC(). Getting a DC
|
||||
* and Lock()ing are mutually exclusive operations.
|
||||
* @param aDC out parameter for HDC
|
||||
* @return error status
|
||||
**/
|
||||
NS_IMETHOD GetGC(GdkGC *aGC) = 0;
|
||||
|
||||
/**
|
||||
* Release a windows DC obtained by GetDC().
|
||||
* ReleaseDC() must be preceded by a call to ReleaseDC().
|
||||
* @return error status
|
||||
**/
|
||||
NS_IMETHOD ReleaseGC(void) = 0;
|
||||
|
||||
};
|
||||
|
||||
#endif // nsIDrawingSurfaceGTK_h___
|
||||
@@ -1,515 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 <gtk/gtk.h>
|
||||
#include <gdk/gdkx.h>
|
||||
|
||||
#include "nsImageGTK.h"
|
||||
#include "nsRenderingContextGTK.h"
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
#define IsFlagSet(a,b) (a & b)
|
||||
|
||||
#undef CHEAP_PERFORMANCE_MEASURMENT
|
||||
|
||||
|
||||
// Defining this will trace the allocation of images. This includes
|
||||
// ctor, dtor and update.
|
||||
#undef TRACE_IMAGE_ALLOCATION
|
||||
|
||||
static NS_DEFINE_IID(kIImageIID, NS_IIMAGE_IID);
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsImageGTK::nsImageGTK()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
mImageBits = nsnull;
|
||||
mWidth = 0;
|
||||
mHeight = 0;
|
||||
mDepth = 0;
|
||||
mAlphaBits = nsnull;
|
||||
mAlphaPixmap = nsnull;
|
||||
mImagePixmap = nsnull;
|
||||
mGC = nsnull;
|
||||
|
||||
#ifdef TRACE_IMAGE_ALLOCATION
|
||||
printf("nsImageGTK::nsImageGTK(this=%p)\n",
|
||||
this);
|
||||
#endif
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsImageGTK::~nsImageGTK()
|
||||
{
|
||||
if(nsnull != mImageBits) {
|
||||
delete[] (PRUint8*)mImageBits;
|
||||
mImageBits = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mAlphaBits) {
|
||||
delete[] (PRUint8*)mAlphaBits;
|
||||
mAlphaBits = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mAlphaPixmap) {
|
||||
gdk_pixmap_unref(mAlphaPixmap);
|
||||
mAlphaPixmap = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mImagePixmap) {
|
||||
gdk_pixmap_unref(mImagePixmap);
|
||||
mImagePixmap = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mGC) {
|
||||
gdk_gc_unref(mGC);
|
||||
mGC = nsnull;
|
||||
}
|
||||
|
||||
#ifdef TRACE_IMAGE_ALLOCATION
|
||||
printf("nsImageGTK::~nsImageGTK(this=%p)\n",
|
||||
this);
|
||||
#endif
|
||||
}
|
||||
|
||||
NS_IMPL_ISUPPORTS(nsImageGTK, kIImageIID);
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsresult nsImageGTK::Init(PRInt32 aWidth, PRInt32 aHeight,
|
||||
PRInt32 aDepth, nsMaskRequirements aMaskRequirements)
|
||||
{
|
||||
g_return_val_if_fail ((aWidth != 0) || (aHeight != 0), NS_ERROR_FAILURE);
|
||||
|
||||
if (nsnull != mImageBits) {
|
||||
delete[] (PRUint8*)mImageBits;
|
||||
mImageBits = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mAlphaBits) {
|
||||
delete[] (PRUint8*)mAlphaBits;
|
||||
mAlphaBits = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mAlphaPixmap) {
|
||||
gdk_pixmap_unref(mAlphaPixmap);
|
||||
mAlphaPixmap = nsnull;
|
||||
}
|
||||
|
||||
if (nsnull != mImagePixmap) {
|
||||
gdk_pixmap_unref(mImagePixmap);
|
||||
mImagePixmap = nsnull;
|
||||
}
|
||||
|
||||
if (24 == aDepth) {
|
||||
mNumBytesPixel = 3;
|
||||
} else {
|
||||
NS_ASSERTION(PR_FALSE, "unexpected image depth");
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
mImageUpdated = PR_TRUE;
|
||||
mWidth = aWidth;
|
||||
mHeight = aHeight;
|
||||
mDepth = aDepth;
|
||||
mIsTopToBottom = PR_TRUE;
|
||||
|
||||
#ifdef TRACE_IMAGE_ALLOCATION
|
||||
printf("nsImageGTK::Init(this=%p,%d,%d,%d,%d)\n",
|
||||
this,
|
||||
aWidth,
|
||||
aHeight,
|
||||
aDepth,
|
||||
aMaskRequirements);
|
||||
#endif
|
||||
|
||||
// create the memory for the image
|
||||
ComputMetrics();
|
||||
|
||||
mImageBits = (PRUint8*) new PRUint8[mSizeImage];
|
||||
|
||||
switch(aMaskRequirements)
|
||||
{
|
||||
case nsMaskRequirements_kNoMask:
|
||||
mAlphaBits = nsnull;
|
||||
mAlphaWidth = 0;
|
||||
mAlphaHeight = 0;
|
||||
break;
|
||||
|
||||
case nsMaskRequirements_kNeeds1Bit:
|
||||
mAlphaRowBytes = (aWidth + 7) / 8;
|
||||
mAlphaDepth = 1;
|
||||
|
||||
// 32-bit align each row
|
||||
mAlphaRowBytes = (mAlphaRowBytes + 3) & ~0x3;
|
||||
|
||||
mAlphaBits = new PRUint8[mAlphaRowBytes * aHeight];
|
||||
mAlphaWidth = aWidth;
|
||||
mAlphaHeight = aHeight;
|
||||
|
||||
mAlphaPixmap = gdk_pixmap_new(nsnull, aWidth, aHeight,
|
||||
mAlphaDepth);
|
||||
break;
|
||||
|
||||
case nsMaskRequirements_kNeeds8Bit:
|
||||
mAlphaBits = nsnull;
|
||||
mAlphaWidth = 0;
|
||||
mAlphaHeight = 0;
|
||||
mAlphaDepth = 8;
|
||||
g_print("TODO: want an 8bit mask for an image..\n");
|
||||
|
||||
mAlphaPixmap = gdk_pixmap_new(nsnull, aWidth, aHeight,
|
||||
mAlphaDepth);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
mImagePixmap = gdk_pixmap_new(nsnull, aWidth, aHeight,
|
||||
gdk_rgb_get_visual()->depth);
|
||||
mGC = gdk_gc_new(mImagePixmap);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
PRInt32 nsImageGTK::CalcBytesSpan(PRUint32 aWidth)
|
||||
{
|
||||
PRInt32 spanbytes;
|
||||
|
||||
spanbytes = (aWidth * mDepth) >> 5;
|
||||
|
||||
if (((PRUint32)aWidth * mDepth) & 0x1F)
|
||||
spanbytes++;
|
||||
spanbytes <<= 2;
|
||||
return(spanbytes);
|
||||
}
|
||||
|
||||
void nsImageGTK::ComputMetrics()
|
||||
{
|
||||
mRowBytes = CalcBytesSpan(mWidth);
|
||||
mSizeImage = mRowBytes * mHeight;
|
||||
}
|
||||
|
||||
PRInt32 nsImageGTK::GetHeight()
|
||||
{
|
||||
return mHeight;
|
||||
}
|
||||
|
||||
PRInt32 nsImageGTK::GetWidth()
|
||||
{
|
||||
return mWidth;
|
||||
}
|
||||
|
||||
PRUint8 *nsImageGTK::GetBits()
|
||||
{
|
||||
return mImageBits;
|
||||
}
|
||||
|
||||
void *nsImageGTK::GetBitInfo()
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
PRInt32 nsImageGTK::GetLineStride()
|
||||
{
|
||||
return mRowBytes;
|
||||
}
|
||||
|
||||
nsColorMap *nsImageGTK::GetColorMap()
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
PRBool nsImageGTK::IsOptimized()
|
||||
{
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
PRUint8 *nsImageGTK::GetAlphaBits()
|
||||
{
|
||||
return mAlphaBits;
|
||||
}
|
||||
|
||||
PRInt32 nsImageGTK::GetAlphaWidth()
|
||||
{
|
||||
return mAlphaWidth;
|
||||
}
|
||||
|
||||
PRInt32 nsImageGTK::GetAlphaHeight()
|
||||
{
|
||||
return mAlphaHeight;
|
||||
}
|
||||
|
||||
PRInt32 nsImageGTK::GetAlphaLineStride()
|
||||
{
|
||||
return mAlphaRowBytes;
|
||||
}
|
||||
|
||||
nsIImage *nsImageGTK::DuplicateImage()
|
||||
{
|
||||
return nsnull;
|
||||
}
|
||||
|
||||
void nsImageGTK::SetAlphaLevel(PRInt32 aAlphaLevel)
|
||||
{
|
||||
}
|
||||
|
||||
PRInt32 nsImageGTK::GetAlphaLevel()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void nsImageGTK::MoveAlphaMask(PRInt32 aX, PRInt32 aY)
|
||||
{
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
// set up the palette to the passed in color array, RGB only in this array
|
||||
void nsImageGTK::ImageUpdated(nsIDeviceContext *aContext,
|
||||
PRUint8 aFlags,
|
||||
nsRect *aUpdateRect)
|
||||
{
|
||||
#ifdef TRACE_IMAGE_ALLOCATION
|
||||
printf("nsImageGTK::ImageUpdated(this=%p,%d)\n",
|
||||
this,
|
||||
aFlags);
|
||||
#endif
|
||||
|
||||
if (IsFlagSet(nsImageUpdateFlags_kBitsChanged, aFlags)) {
|
||||
mImageUpdated = PR_TRUE;
|
||||
// FIXME do something with aUpdateRect
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef CHEAP_PERFORMANCE_MEASURMENT
|
||||
static PRTime gConvertTime, gStartTime, gPixmapTime, gEndTime;
|
||||
#endif
|
||||
|
||||
// Draw the bitmap, this method has a source and destination coordinates
|
||||
NS_IMETHODIMP
|
||||
nsImageGTK::Draw(nsIRenderingContext &aContext, nsDrawingSurface aSurface,
|
||||
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
|
||||
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight)
|
||||
{
|
||||
g_return_val_if_fail ((aSurface != nsnull), NS_ERROR_FAILURE);
|
||||
|
||||
nsDrawingSurfaceGTK *drawing = (nsDrawingSurfaceGTK*)aSurface;
|
||||
|
||||
if (mAlphaBits)
|
||||
g_print("calling nsImageGTK::Draw() with alpha bits\n");
|
||||
|
||||
gdk_draw_rgb_image (drawing->GetDrawable(),
|
||||
mGC,
|
||||
aDX, aDY, aDWidth, aDHeight,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
mImageBits + mRowBytes * aSY + 3 * aDX,
|
||||
mRowBytes);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
// Draw the bitmap, this draw just has destination coordinates
|
||||
NS_IMETHODIMP
|
||||
nsImageGTK::Draw(nsIRenderingContext &aContext,
|
||||
nsDrawingSurface aSurface,
|
||||
PRInt32 aX, PRInt32 aY,
|
||||
PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
g_return_val_if_fail ((aSurface != nsnull), NS_ERROR_FAILURE);
|
||||
|
||||
|
||||
// XXX kipp: this is temporary code until we eliminate the
|
||||
// width/height arguments from the draw method.
|
||||
if ((aWidth != mWidth) || (aHeight != mHeight)) {
|
||||
aWidth = mWidth;
|
||||
aHeight = mHeight;
|
||||
}
|
||||
|
||||
#ifdef TRACE_IMAGE_ALLOCATION
|
||||
printf("nsImageGTK::Draw(this=%p,x=%d,y=%d,width=%d,height=%d)\n",
|
||||
this,
|
||||
aX,
|
||||
aY,
|
||||
aWidth,
|
||||
aHeight);
|
||||
#endif
|
||||
|
||||
nsDrawingSurfaceGTK* drawing = (nsDrawingSurfaceGTK*) aSurface;
|
||||
|
||||
XImage *x_image = nsnull;
|
||||
Pixmap pixmap = 0;
|
||||
Display *dpy = nsnull;
|
||||
Visual *visual = nsnull;
|
||||
GC gc;
|
||||
XGCValues gcv;
|
||||
|
||||
#ifdef CHEAP_PERFORMANCE_MEASURMENT
|
||||
gStartTime = gPixmapTime = PR_Now();
|
||||
#endif
|
||||
|
||||
// Create gc clip-mask on demand
|
||||
if ((mAlphaBits) && (mImageUpdated == PR_TRUE))
|
||||
{
|
||||
/* get the X primitives */
|
||||
dpy = GDK_WINDOW_XDISPLAY(mAlphaPixmap);
|
||||
|
||||
|
||||
/* this is the depth of the pixmap that we are going to draw to.
|
||||
It's always a bitmap. We're doing alpha here folks. */
|
||||
visual = GDK_VISUAL_XVISUAL(gdk_rgb_get_visual());
|
||||
|
||||
// Make an image out of the alpha-bits created by the image library
|
||||
x_image = XCreateImage(dpy, visual,
|
||||
1, /* visual depth...1 for bitmaps */
|
||||
XYPixmap,
|
||||
0, /* x offset, XXX fix this */
|
||||
(char *)mAlphaBits, /* cast away our sign. */
|
||||
aWidth,
|
||||
aHeight,
|
||||
32,/* bitmap pad */
|
||||
mAlphaRowBytes); /* bytes per line */
|
||||
|
||||
x_image->bits_per_pixel=1;
|
||||
|
||||
/* Image library always places pixels left-to-right MSB to LSB */
|
||||
x_image->bitmap_bit_order = MSBFirst;
|
||||
|
||||
/* This definition doesn't depend on client byte ordering
|
||||
because the image library ensures that the bytes in
|
||||
bitmask data are arranged left to right on the screen,
|
||||
low to high address in memory. */
|
||||
x_image->byte_order = MSBFirst;
|
||||
#if defined(IS_LITTLE_ENDIAN)
|
||||
// no, it's still MSB XXX check on this!!
|
||||
// x_image->byte_order = LSBFirst;
|
||||
#elif defined (IS_BIG_ENDIAN)
|
||||
x_image->byte_order = MSBFirst;
|
||||
#else
|
||||
#error ERROR! Endianness is unknown;
|
||||
#endif
|
||||
|
||||
// Write into the pixemap that is underneath gdk's mAlphaPixmap
|
||||
// the image we just created.
|
||||
|
||||
pixmap = GDK_WINDOW_XWINDOW(mAlphaPixmap);
|
||||
memset(&gcv, 0, sizeof(XGCValues));
|
||||
gcv.function = GXcopy;
|
||||
gc = XCreateGC(dpy, pixmap, GCFunction, &gcv);
|
||||
XPutImage(dpy, pixmap, gc, x_image, 0, 0, 0, 0,
|
||||
aWidth, aHeight);
|
||||
XFreeGC(dpy, gc);
|
||||
|
||||
// Now we are done with the temporary image
|
||||
x_image->data = 0; /* Don't free the IL_Pixmap's bits. */
|
||||
XDestroyImage(x_image);
|
||||
|
||||
#ifdef CHEAP_PERFORMANCE_MEASURMENT
|
||||
gPixmapTime = PR_Now();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Render unique image bits onto an off screen pixmap only once
|
||||
// The image bits can change as a result of ImageUpdated() - for
|
||||
// example: animated GIFs.
|
||||
if (mImageUpdated == PR_TRUE)
|
||||
{
|
||||
#ifdef TRACE_IMAGE_ALLOCATION
|
||||
printf("nsImageGTK::Draw(this=%p) gdk_pixmap_new(nsnull,width=%d,height=%d,depth=%d)\n",
|
||||
this,
|
||||
aWidth,
|
||||
aHeight,
|
||||
mDepth);
|
||||
#endif
|
||||
|
||||
gdk_gc_set_clip_origin(mGC, 0, 0);
|
||||
gdk_gc_set_clip_mask(mGC, nsnull);
|
||||
|
||||
// Render the image bits into an off screen pixmap
|
||||
gdk_draw_rgb_image (mImagePixmap,
|
||||
mGC,
|
||||
0, 0, aWidth, aHeight,
|
||||
GDK_RGB_DITHER_MAX,
|
||||
mImageBits, mRowBytes);
|
||||
|
||||
if (mAlphaPixmap)
|
||||
{
|
||||
// Setup gc to use the given alpha-pixmap for clipping
|
||||
gdk_gc_set_clip_mask(mGC, mAlphaPixmap);
|
||||
gdk_gc_set_clip_origin(mGC, aX, aY);
|
||||
}
|
||||
|
||||
#ifdef TRACE_IMAGE_ALLOCATION
|
||||
printf("nsImageGTK::Draw(this=%p) gdk_draw_pixmap(x=%d,y=%d,width=%d,height=%d)\n",
|
||||
this,
|
||||
aX,
|
||||
aY,
|
||||
aWidth,
|
||||
aHeight);
|
||||
#endif
|
||||
|
||||
mImageUpdated = PR_FALSE;
|
||||
}
|
||||
|
||||
|
||||
// copy our offscreen pixmap onto the window.
|
||||
gdk_window_copy_area(drawing->GetDrawable(), // dest window
|
||||
mGC, // gc
|
||||
aX, // xsrc
|
||||
aY, // ysrc
|
||||
mImagePixmap, // source window
|
||||
0, // xdest
|
||||
0, // ydest
|
||||
aWidth, // width
|
||||
aHeight); // height
|
||||
|
||||
if (mAlphaBits)
|
||||
{
|
||||
// Revert gc to its old clip-mask and origin
|
||||
gdk_gc_set_clip_origin(mGC, 0, 0);
|
||||
gdk_gc_set_clip_mask(mGC, nsnull);
|
||||
}
|
||||
|
||||
#ifdef CHEAP_PERFORMANCE_MEASURMENT
|
||||
gEndTime = PR_Now();
|
||||
printf("nsImageGTK::Draw(this=%p,w=%d,h=%d) total=%lld pixmap=%lld, cvt=%lld\n",
|
||||
this,
|
||||
aWidth, aHeight,
|
||||
gEndTime - gStartTime,
|
||||
gPixmapTime - gStartTime,
|
||||
gConvertTime - gPixmapTime);
|
||||
#endif
|
||||
|
||||
mImageUpdated = PR_FALSE;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
//------------------------------------------------------------
|
||||
|
||||
nsresult nsImageGTK::Optimize(nsIDeviceContext* aContext)
|
||||
{
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -1,115 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsImageGTK_h___
|
||||
#define nsImageGTK_h___
|
||||
|
||||
#include "nsIImage.h"
|
||||
|
||||
#include "X11/Xlib.h"
|
||||
#include "X11/Xutil.h"
|
||||
#include <gdk/gdk.h>
|
||||
|
||||
#undef Bool
|
||||
|
||||
class nsImageGTK : public nsIImage
|
||||
{
|
||||
public:
|
||||
nsImageGTK();
|
||||
virtual ~nsImageGTK();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
/**
|
||||
@see nsIImage.h
|
||||
*/
|
||||
virtual PRInt32 GetBytesPix() { return mNumBytesPixel; }
|
||||
virtual PRInt32 GetHeight();
|
||||
virtual PRInt32 GetWidth();
|
||||
virtual PRUint8* GetBits();
|
||||
virtual void* GetBitInfo();
|
||||
virtual PRBool GetIsRowOrderTopToBottom() { return mIsTopToBottom; }
|
||||
virtual PRInt32 GetLineStride();
|
||||
virtual nsColorMap* GetColorMap();
|
||||
NS_IMETHOD Draw(nsIRenderingContext &aContext,
|
||||
nsDrawingSurface aSurface,
|
||||
PRInt32 aX, PRInt32 aY,
|
||||
PRInt32 aWidth, PRInt32 aHeight);
|
||||
NS_IMETHOD Draw(nsIRenderingContext &aContext,
|
||||
nsDrawingSurface aSurface,
|
||||
PRInt32 aSX, PRInt32 aSY, PRInt32 aSWidth, PRInt32 aSHeight,
|
||||
PRInt32 aDX, PRInt32 aDY, PRInt32 aDWidth, PRInt32 aDHeight);
|
||||
virtual void ImageUpdated(nsIDeviceContext *aContext,
|
||||
PRUint8 aFlags, nsRect *aUpdateRect);
|
||||
virtual nsresult Init(PRInt32 aWidth, PRInt32 aHeight,
|
||||
PRInt32 aDepth,
|
||||
nsMaskRequirements aMaskRequirements);
|
||||
virtual PRBool IsOptimized();
|
||||
|
||||
virtual nsresult Optimize(nsIDeviceContext* aContext);
|
||||
virtual PRUint8* GetAlphaBits();
|
||||
virtual PRInt32 GetAlphaWidth();
|
||||
virtual PRInt32 GetAlphaHeight();
|
||||
virtual PRInt32 GetAlphaLineStride();
|
||||
virtual nsIImage* DuplicateImage();
|
||||
|
||||
/**
|
||||
* Calculate the number of bytes spaned for this image for a given width
|
||||
* @param aWidth is the width to calculate the number of bytes for
|
||||
* @return the number of bytes in this span
|
||||
*/
|
||||
PRInt32 CalcBytesSpan(PRUint32 aWidth);
|
||||
virtual void SetAlphaLevel(PRInt32 aAlphaLevel);
|
||||
virtual PRInt32 GetAlphaLevel();
|
||||
virtual void MoveAlphaMask(PRInt32 aX, PRInt32 aY);
|
||||
|
||||
private:
|
||||
/**
|
||||
* Calculate the amount of memory needed for the initialization of the image
|
||||
*/
|
||||
void ComputMetrics();
|
||||
void ComputePaletteSize(PRIntn nBitCount);
|
||||
|
||||
private:
|
||||
PRInt32 mWidth;
|
||||
PRInt32 mHeight;
|
||||
PRInt32 mDepth; // bits per pixel
|
||||
PRInt32 mRowBytes;
|
||||
PRUint8 *mImageBits;
|
||||
PRUint8 *mConvertedBits;
|
||||
PRInt32 mSizeImage;
|
||||
PRBool mIsTopToBottom;
|
||||
PRBool mImageUpdated;
|
||||
|
||||
PRInt8 mNumBytesPixel;
|
||||
|
||||
// alpha layer members
|
||||
PRUint8 *mAlphaBits;
|
||||
GdkPixmap *mAlphaPixmap;
|
||||
PRInt8 mAlphaDepth; // alpha layer depth
|
||||
PRInt16 mAlphaRowBytes; // alpha bytes per row
|
||||
PRInt16 mAlphaWidth; // alpha layer width
|
||||
PRInt16 mAlphaHeight; // alpha layer height
|
||||
nsPoint mLocation; // alpha mask location
|
||||
|
||||
GdkPixmap *mImagePixmap;
|
||||
|
||||
GdkGC *mGC;
|
||||
};
|
||||
|
||||
#endif
|
||||
@@ -1,452 +0,0 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* Original Code: Syd Logan (syd@netscape.com) 3/12/99 */
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "nspr.h"
|
||||
|
||||
#include "nsPrintdGTK.h"
|
||||
|
||||
/* A structure to hold widgets that need to be referenced in callbacks. We
|
||||
declare this statically in the caller entry point (as a field of
|
||||
UnixPrOps, below), and pass a pointer to the structure to Gtk+ for each
|
||||
signal handler registered. This avoids use of globals. */
|
||||
|
||||
typedef struct prwidgets {
|
||||
GtkWidget *toplevel; /* should be set to toplevel window */
|
||||
GtkWidget *prDialog;
|
||||
GtkWidget *cmdEntry;
|
||||
GtkWidget *pathEntry;
|
||||
GtkWidget *browseButton;
|
||||
GtkWidget *fpfToggle;
|
||||
GtkWidget *greyToggle;
|
||||
GtkWidget *letterToggle;
|
||||
GtkWidget *legalToggle;
|
||||
GtkWidget *execToggle;
|
||||
GtkWidget *topSpinner;
|
||||
GtkWidget *bottomSpinner;
|
||||
GtkWidget *leftSpinner;
|
||||
GtkWidget *rightSpinner;
|
||||
GtkFileSelection *fsWidget;
|
||||
} PrWidgets;
|
||||
|
||||
typedef struct unixprops {
|
||||
UnixPrData *prData; /* pointer to caller struct */
|
||||
PrWidgets widgets;
|
||||
} UnixPrOps;
|
||||
|
||||
/* user clicked cancel. tear things down, and set cancel field in
|
||||
caller data to PR_TRUE so printing will not happen */
|
||||
|
||||
static void
|
||||
CancelPrint (GtkWidget *widget, UnixPrOps *prOps)
|
||||
{
|
||||
gtk_main_quit();
|
||||
gtk_widget_destroy( GTK_WIDGET(prOps->widgets.prDialog) );
|
||||
prOps->prData->cancel = PR_TRUE;
|
||||
}
|
||||
|
||||
/* user selected the Print button. Collect any remaining data from the
|
||||
widgets, and set cancel field in caller data to PR_FALSE so printing
|
||||
will be performed. Also, tear down dialog and exit inner main loop */
|
||||
|
||||
static void
|
||||
DoPrint (GtkWidget *widget, UnixPrOps *prOps)
|
||||
{
|
||||
strcpy( prOps->prData->command,
|
||||
gtk_entry_get_text( GTK_ENTRY( prOps->widgets.cmdEntry ) ) );
|
||||
strcpy( prOps->prData->path,
|
||||
gtk_entry_get_text( GTK_ENTRY( prOps->widgets.pathEntry ) ) );
|
||||
|
||||
if ( GTK_TOGGLE_BUTTON( prOps->widgets.fpfToggle )->active == PR_TRUE )
|
||||
prOps->prData->fpf = PR_TRUE;
|
||||
else
|
||||
prOps->prData->fpf = PR_FALSE;
|
||||
|
||||
if ( GTK_TOGGLE_BUTTON( prOps->widgets.greyToggle )->active == PR_TRUE )
|
||||
prOps->prData->grayscale = PR_TRUE;
|
||||
else
|
||||
prOps->prData->grayscale = PR_FALSE;
|
||||
if ( GTK_TOGGLE_BUTTON( prOps->widgets.letterToggle )->active == PR_TRUE )
|
||||
prOps->prData->size = NS_LETTER_SIZE;
|
||||
else if ( GTK_TOGGLE_BUTTON( prOps->widgets.legalToggle )->active == PR_TRUE )
|
||||
prOps->prData->size = NS_LEGAL_SIZE;
|
||||
else if ( GTK_TOGGLE_BUTTON( prOps->widgets.execToggle )->active == PR_TRUE )
|
||||
prOps->prData->size = NS_EXECUTIVE_SIZE;
|
||||
else
|
||||
prOps->prData->size = NS_A4_SIZE;
|
||||
|
||||
/* margins */
|
||||
|
||||
prOps->prData->top = gtk_spin_button_get_value_as_float(
|
||||
GTK_SPIN_BUTTON(prOps->widgets.topSpinner) );
|
||||
prOps->prData->bottom = gtk_spin_button_get_value_as_float(
|
||||
GTK_SPIN_BUTTON(prOps->widgets.bottomSpinner) );
|
||||
prOps->prData->left = gtk_spin_button_get_value_as_float(
|
||||
GTK_SPIN_BUTTON(prOps->widgets.leftSpinner) );
|
||||
prOps->prData->right = gtk_spin_button_get_value_as_float(
|
||||
GTK_SPIN_BUTTON(prOps->widgets.rightSpinner) );
|
||||
|
||||
/* we got everything... bring down the dialog and tell caller
|
||||
it's o.k. to print */
|
||||
|
||||
gtk_main_quit();
|
||||
gtk_widget_destroy( GTK_WIDGET(prOps->widgets.prDialog) );
|
||||
prOps->prData->cancel = PR_FALSE;
|
||||
}
|
||||
|
||||
/* User hit ok in file selection widget brought up by the browse button.
|
||||
snarf the selected file, stuff it in caller data */
|
||||
|
||||
static void
|
||||
ModifyPrPath (GtkWidget *widget, UnixPrOps *prOps)
|
||||
{
|
||||
strcpy( prOps->prData->path,
|
||||
gtk_file_selection_get_filename(prOps->widgets.fsWidget) );
|
||||
gtk_entry_set_text (GTK_ENTRY (prOps->widgets.pathEntry),
|
||||
prOps->prData->path);
|
||||
gtk_widget_destroy( GTK_WIDGET(prOps->widgets.fsWidget) );
|
||||
}
|
||||
|
||||
/* user selected print to printer. de-sensitize print to file fields */
|
||||
|
||||
static void
|
||||
SwitchToPrinter (GtkWidget *widget, UnixPrOps *prOps)
|
||||
{
|
||||
gtk_widget_set_sensitive( prOps->widgets.cmdEntry, PR_TRUE );
|
||||
gtk_widget_set_sensitive( prOps->widgets.pathEntry, PR_FALSE );
|
||||
gtk_widget_set_sensitive( prOps->widgets.browseButton, PR_FALSE );
|
||||
prOps->prData->toPrinter = PR_TRUE;
|
||||
}
|
||||
|
||||
/* user selected print to file. de-sensitize print to printer fields */
|
||||
|
||||
static void
|
||||
SwitchToFile (GtkWidget *widget, UnixPrOps *prOps)
|
||||
{
|
||||
gtk_widget_set_sensitive( prOps->widgets.cmdEntry, PR_FALSE );
|
||||
gtk_widget_set_sensitive( prOps->widgets.pathEntry, PR_TRUE );
|
||||
gtk_widget_set_sensitive( prOps->widgets.browseButton, PR_TRUE );
|
||||
prOps->prData->toPrinter = PR_FALSE;
|
||||
}
|
||||
|
||||
/* user hit the browse button. Pop up a file selection widget and grab
|
||||
result */
|
||||
|
||||
static void
|
||||
GetPrPath (GtkWidget *widget, UnixPrOps *prOps)
|
||||
{
|
||||
GtkWidget *fs;
|
||||
|
||||
fs = gtk_file_selection_new("Netscape: File Browser");
|
||||
|
||||
gtk_file_selection_set_filename( GTK_FILE_SELECTION(fs),
|
||||
prOps->prData->path );
|
||||
|
||||
gtk_window_set_modal (GTK_WINDOW(fs),PR_TRUE);
|
||||
|
||||
#if 0
|
||||
/* XXX not sure what the toplevel window should be. */
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (fs),
|
||||
GTK_WINDOW (prOps->widgets.toplevel));
|
||||
#endif
|
||||
|
||||
prOps->widgets.fsWidget = GTK_FILE_SELECTION(fs);
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT(GTK_FILE_SELECTION(fs)->ok_button),
|
||||
"clicked", GTK_SIGNAL_FUNC(ModifyPrPath), prOps);
|
||||
|
||||
gtk_signal_connect_object (GTK_OBJECT(
|
||||
GTK_FILE_SELECTION(fs)->cancel_button), "clicked",
|
||||
GTK_SIGNAL_FUNC(gtk_widget_destroy), GTK_OBJECT (fs));
|
||||
|
||||
gtk_widget_show(fs);
|
||||
}
|
||||
|
||||
/* create file data dialog. XXX widget should be NULL */
|
||||
|
||||
static void
|
||||
DoPrintGTK (GtkWidget *widget, UnixPrOps *prOps)
|
||||
{
|
||||
GtkWidget *separator, *dialog, *label, *vbox, *entry, *hbox,
|
||||
*button, *fileButton, *prButton, *table, *spinner1;
|
||||
GtkAdjustment *adj;
|
||||
|
||||
prOps->widgets.prDialog = dialog =
|
||||
gtk_window_new( GTK_WINDOW_TOPLEVEL );
|
||||
gtk_window_set_modal( GTK_WINDOW(dialog), PR_TRUE );
|
||||
#if 0
|
||||
/* not yet sure what the toplevel window should be */
|
||||
|
||||
gtk_window_set_transient_for (GTK_WINDOW (dialog),
|
||||
GTK_WINDOW (prOps->widgets.toplevel));
|
||||
#endif
|
||||
gtk_window_set_title( GTK_WINDOW(dialog), "Netscape: Print" );
|
||||
|
||||
vbox = gtk_vbox_new (PR_FALSE, 0);
|
||||
gtk_container_add (GTK_CONTAINER (dialog), vbox);
|
||||
|
||||
table = gtk_table_new (3, 3, PR_FALSE);
|
||||
gtk_table_set_row_spacings (GTK_TABLE (table), 5);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (table), 10);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, PR_TRUE, PR_TRUE, 5);
|
||||
label = gtk_label_new( "Print To:" );
|
||||
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
|
||||
0, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = prButton = gtk_radio_button_new_with_label (NULL, "Printer");
|
||||
if ( prOps->prData->toPrinter == PR_TRUE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 0, 1,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
|
||||
button = fileButton = gtk_radio_button_new_with_label (
|
||||
gtk_radio_button_group (GTK_RADIO_BUTTON (button)), "File");
|
||||
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
if ( prOps->prData->toPrinter == PR_FALSE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
|
||||
label = gtk_label_new( "Print Command:" );
|
||||
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 1, 2,
|
||||
0, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
entry = gtk_entry_new ();
|
||||
gtk_entry_set_text (GTK_ENTRY (entry), prOps->prData->command);
|
||||
gtk_table_attach (GTK_TABLE (table), entry, 1, 3, 1, 2,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
if ( prOps->prData->toPrinter == PR_FALSE )
|
||||
gtk_widget_set_sensitive( entry, PR_FALSE );
|
||||
prOps->widgets.cmdEntry = entry;
|
||||
|
||||
label = gtk_label_new( "File Name:" );
|
||||
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
|
||||
0, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
entry = gtk_entry_new ();
|
||||
gtk_table_attach (GTK_TABLE (table), entry, 1, 2, 2, 3,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
gtk_entry_set_text (GTK_ENTRY (entry), prOps->prData->path);
|
||||
if ( prOps->prData->toPrinter == PR_TRUE )
|
||||
gtk_widget_set_sensitive( entry, PR_FALSE );
|
||||
prOps->widgets.pathEntry = entry;
|
||||
|
||||
button = gtk_button_new_with_label ("Browse...");
|
||||
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 2, 3,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||
GTK_SIGNAL_FUNC (GetPrPath), prOps);
|
||||
if ( prOps->prData->toPrinter == PR_TRUE )
|
||||
gtk_widget_set_sensitive( entry, PR_FALSE );
|
||||
prOps->widgets.browseButton = button;
|
||||
|
||||
separator = gtk_hseparator_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), separator, PR_TRUE, PR_FALSE, 0);
|
||||
|
||||
table = gtk_table_new (2, 4, PR_FALSE);
|
||||
gtk_table_set_row_spacings (GTK_TABLE (table), 5);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (table), 10);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, PR_TRUE, PR_FALSE, 0);
|
||||
|
||||
label = gtk_label_new( "Print: " );
|
||||
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 0, 1,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = gtk_radio_button_new_with_label (NULL, "First Page First");
|
||||
if ( prOps->prData->fpf == PR_TRUE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
prOps->widgets.fpfToggle = button;
|
||||
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 0, 1,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = gtk_radio_button_new_with_label (
|
||||
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
|
||||
"Last Page First");
|
||||
if ( prOps->prData->fpf == PR_FALSE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 0, 1,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
|
||||
label = gtk_label_new( "Print: " );
|
||||
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 2, 3,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = gtk_radio_button_new_with_label (NULL, "Greyscale");
|
||||
prOps->widgets.greyToggle = button;
|
||||
if ( prOps->prData->grayscale == PR_TRUE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 2, 3,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = gtk_radio_button_new_with_label (
|
||||
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
|
||||
"Color");
|
||||
if ( prOps->prData->grayscale == PR_FALSE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 2, 3,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
|
||||
label = gtk_label_new( "Paper Size: " );
|
||||
gtk_table_attach (GTK_TABLE (table), label, 0, 1, 3, 4,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = gtk_radio_button_new_with_label (NULL,
|
||||
"Letter (8 1/2 x 11 in.)");
|
||||
prOps->widgets.letterToggle = button;
|
||||
if ( prOps->prData->size == NS_LETTER_SIZE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 3, 4,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = gtk_radio_button_new_with_label (
|
||||
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
|
||||
"Legal (8 1/2 x 14 in.)");
|
||||
prOps->widgets.legalToggle = button;
|
||||
if ( prOps->prData->size == NS_LEGAL_SIZE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 3, 4,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
|
||||
button = gtk_radio_button_new_with_label (
|
||||
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
|
||||
"Executive (7 1/2 x 10 in.)");
|
||||
prOps->widgets.execToggle = button;
|
||||
if ( prOps->prData->size == NS_EXECUTIVE_SIZE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 1, 2, 4, 5,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
button = gtk_radio_button_new_with_label (
|
||||
gtk_radio_button_group (GTK_RADIO_BUTTON (button)),
|
||||
"A4 (210 x 297 mm)");
|
||||
if ( prOps->prData->size == NS_A4_SIZE )
|
||||
gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (button),
|
||||
PR_TRUE);
|
||||
gtk_table_attach (GTK_TABLE (table), button, 2, 3, 4, 5,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
|
||||
/* margins */
|
||||
|
||||
separator = gtk_hseparator_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), separator, PR_TRUE, PR_FALSE, 0);
|
||||
|
||||
hbox = gtk_hbox_new (PR_FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, PR_FALSE, PR_FALSE, 5);
|
||||
label = gtk_label_new( "Margins (inches):" );
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, PR_FALSE, PR_FALSE, 10);
|
||||
|
||||
table = gtk_table_new (1, 2, PR_FALSE);
|
||||
gtk_table_set_row_spacings (GTK_TABLE (table), 5);
|
||||
gtk_table_set_col_spacings (GTK_TABLE (table), 5);
|
||||
gtk_container_set_border_width (GTK_CONTAINER (table), 10);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), table, PR_TRUE, PR_FALSE, 0);
|
||||
hbox = gtk_hbox_new (PR_FALSE, 0);
|
||||
gtk_table_attach (GTK_TABLE (table), hbox, 0, 1, 0, 1,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
label = gtk_label_new( "Top: " );
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, PR_TRUE, PR_FALSE, 0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 0.0, 999.0,
|
||||
0.25, 1.0, 0.0);
|
||||
prOps->widgets.topSpinner = spinner1 =
|
||||
gtk_spin_button_new (adj, 1.0, 2);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner1), TRUE);
|
||||
gtk_widget_set_usize (spinner1, 60, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), spinner1, FALSE, TRUE, 0);
|
||||
|
||||
label = gtk_label_new( "Bottom: " );
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, PR_TRUE, PR_FALSE, 0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (1.0, 0.0, 999.0,
|
||||
0.25, 1.0, 0.0);
|
||||
prOps->widgets.bottomSpinner = spinner1 =
|
||||
gtk_spin_button_new (adj, 1.0, 2);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner1), TRUE);
|
||||
gtk_widget_set_usize (spinner1, 60, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), spinner1, FALSE, TRUE, 0);
|
||||
|
||||
hbox = gtk_hbox_new (PR_FALSE, 0);
|
||||
gtk_table_attach (GTK_TABLE (table), hbox, 1, 2, 0, 1,
|
||||
GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
|
||||
|
||||
label = gtk_label_new( "Left: " );
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, PR_TRUE, PR_FALSE, 0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (0.75, 0.0, 999.0,
|
||||
0.25, 1.0, 0.0);
|
||||
prOps->widgets.leftSpinner = spinner1 =
|
||||
gtk_spin_button_new (adj, 1.0, 2);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner1), TRUE);
|
||||
gtk_widget_set_usize (spinner1, 60, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), spinner1, FALSE, TRUE, 0);
|
||||
|
||||
label = gtk_label_new( "Right: " );
|
||||
gtk_box_pack_start (GTK_BOX (hbox), label, PR_TRUE, PR_FALSE, 0);
|
||||
adj = (GtkAdjustment *) gtk_adjustment_new (0.75, 0.0, 999.0,
|
||||
0.25, 1.0, 0.0);
|
||||
prOps->widgets.rightSpinner = spinner1 =
|
||||
gtk_spin_button_new (adj, 1.0, 2);
|
||||
gtk_spin_button_set_wrap (GTK_SPIN_BUTTON (spinner1), TRUE);
|
||||
gtk_widget_set_usize (spinner1, 60, 0);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), spinner1, FALSE, TRUE, 0);
|
||||
|
||||
separator = gtk_hseparator_new ();
|
||||
gtk_box_pack_start (GTK_BOX (vbox), separator, PR_TRUE, PR_FALSE, 0);
|
||||
|
||||
hbox = gtk_hbox_new (PR_FALSE, 0);
|
||||
gtk_box_pack_start (GTK_BOX (vbox), hbox, PR_TRUE, PR_FALSE, 5);
|
||||
button = gtk_button_new_with_label ("Print");
|
||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||
GTK_SIGNAL_FUNC (DoPrint), prOps );
|
||||
gtk_box_pack_start (GTK_BOX (hbox), button, PR_TRUE, PR_FALSE, 0);
|
||||
|
||||
GTK_WIDGET_SET_FLAGS (button, GTK_CAN_DEFAULT);
|
||||
gtk_widget_grab_default (button);
|
||||
|
||||
button = gtk_button_new_with_label ("Cancel");
|
||||
gtk_signal_connect (GTK_OBJECT (button), "clicked",
|
||||
GTK_SIGNAL_FUNC ( CancelPrint ), prOps);
|
||||
gtk_box_pack_start (GTK_BOX (hbox), button, PR_TRUE, PR_FALSE, 0);
|
||||
|
||||
/* Do this here, otherwise, upon creation the callbacks will be
|
||||
triggered and the widgets these callbacks set sensitivity on
|
||||
do not exist yet */
|
||||
|
||||
gtk_signal_connect (GTK_OBJECT (prButton), "clicked",
|
||||
GTK_SIGNAL_FUNC (SwitchToPrinter), prOps);
|
||||
gtk_signal_connect (GTK_OBJECT (fileButton), "clicked",
|
||||
GTK_SIGNAL_FUNC (SwitchToFile), prOps);
|
||||
|
||||
gtk_widget_show_all( dialog );
|
||||
gtk_main ();
|
||||
}
|
||||
|
||||
/* public interface to print dialog. Caller passes in preferences using
|
||||
argument, we return any changes and indication of whether to print
|
||||
or cancel. */
|
||||
|
||||
void
|
||||
UnixPrDialog( UnixPrData *prData )
|
||||
{
|
||||
static UnixPrOps prOps;
|
||||
|
||||
prOps.prData = prData;
|
||||
DoPrintGTK( (GtkWidget *) NULL, &prOps );
|
||||
}
|
||||
|
||||
@@ -1,60 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
|
||||
*
|
||||
* The contents of this file are subject to the Netscape Public License
|
||||
* Version 1.0 (the "NPL"); you may not use this file except in
|
||||
* compliance with the NPL. You may obtain a copy of the NPL at
|
||||
* http://www.mozilla.org/NPL/
|
||||
*
|
||||
* Software distributed under the NPL is distributed on an "AS IS" basis,
|
||||
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the NPL
|
||||
* for the specific language governing rights and limitations under the
|
||||
* NPL.
|
||||
*
|
||||
* The Initial Developer of this code under the NPL is Netscape
|
||||
* Communications Corporation. Portions created by Netscape are
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
/* Original Code: Syd Logan (syd@netscape.com) 3/12/99 */
|
||||
|
||||
#ifndef nsPrintdGTK_h___
|
||||
#define nsPrintdGTK_h___
|
||||
|
||||
#include <limits.h>
|
||||
|
||||
PR_BEGIN_EXTERN_C
|
||||
|
||||
/* stolen from nsPostScriptObj.h. needs to be put somewhere else that
|
||||
both ps and gtk can see easily */
|
||||
|
||||
#ifndef NS_LEGAL_SIZE
|
||||
#define NS_LETTER_SIZE 0
|
||||
#define NS_LEGAL_SIZE 1
|
||||
#define NS_EXECUTIVE_SIZE 2
|
||||
#define NS_A4_SIZE 3
|
||||
#endif
|
||||
|
||||
#ifndef PATH_MAX
|
||||
#define PATH_MAX _POSIX_PATH_MAX
|
||||
#endif
|
||||
|
||||
typedef struct unixprdata {
|
||||
PRBool toPrinter; /* If PR_TRUE, print to printer */
|
||||
PRBool fpf; /* If PR_TRUE, first page first */
|
||||
PRBool grayscale; /* If PR_TRUE, print grayscale */
|
||||
int size; /* Paper size e.g., SizeLetter */
|
||||
char command[ PATH_MAX ]; /* Print command e.g., lpr */
|
||||
char path[ PATH_MAX ]; /* If toPrinter = PR_FALSE, dest file */
|
||||
PRBool cancel; /* If PR_TRUE, user cancelled */
|
||||
float left; /* left margin */
|
||||
float right; /* right margin */
|
||||
float top; /* top margin */
|
||||
float bottom; /* bottom margin */
|
||||
} UnixPrData;
|
||||
|
||||
void UnixPrDialog(UnixPrData *prData);
|
||||
|
||||
PR_END_EXTERN_C
|
||||
|
||||
#endif /* nsPrintdGTK_h___ */
|
||||
@@ -1,302 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 <gtk/gtk.h>
|
||||
#include <gdk/gdkprivate.h>
|
||||
#include "nsRegionGTK.h"
|
||||
#include "xregion.h"
|
||||
#include "prmem.h"
|
||||
|
||||
static NS_DEFINE_IID(kRegionIID, NS_IREGION_IID);
|
||||
|
||||
nsRegionGTK::nsRegionGTK()
|
||||
{
|
||||
NS_INIT_REFCNT();
|
||||
|
||||
mRegion = nsnull;
|
||||
mRegionType = eRegionComplexity_empty;
|
||||
}
|
||||
|
||||
nsRegionGTK::~nsRegionGTK()
|
||||
{
|
||||
if (mRegion)
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nsnull;
|
||||
}
|
||||
|
||||
NS_IMPL_QUERY_INTERFACE(nsRegionGTK, kRegionIID)
|
||||
NS_IMPL_ADDREF(nsRegionGTK)
|
||||
NS_IMPL_RELEASE(nsRegionGTK)
|
||||
|
||||
nsresult nsRegionGTK::Init(void)
|
||||
{
|
||||
NS_ADDREF_THIS();
|
||||
mRegion = ::gdk_region_new();
|
||||
mRegionType = eRegionComplexity_empty;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsRegionGTK::SetTo(const nsIRegion &aRegion)
|
||||
{
|
||||
nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;
|
||||
|
||||
SetRegionEmpty();
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::SetTo(const nsRegionGTK *aRegion)
|
||||
{
|
||||
SetRegionEmpty();
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_union(mRegion, aRegion->mRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
SetRegionEmpty();
|
||||
|
||||
GdkRectangle grect;
|
||||
|
||||
grect.x = aX;
|
||||
grect.y = aY;
|
||||
grect.width = aWidth;
|
||||
grect.height = aHeight;
|
||||
|
||||
GdkRegion *nRegion = ::gdk_region_union_with_rect(mRegion, &grect);
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::Intersect(const nsIRegion &aRegion)
|
||||
{
|
||||
nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_intersect(mRegion, pRegion->mRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
GdkRegion *tRegion = CreateRectRegion(aX, aY, aWidth, aHeight);
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_intersect(mRegion, tRegion);
|
||||
::gdk_region_destroy(tRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::Union(const nsIRegion &aRegion)
|
||||
{
|
||||
nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_union(mRegion, pRegion->mRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
GdkRegion *tRegion = CreateRectRegion(aX, aY, aWidth, aHeight);
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_union(mRegion, tRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
::gdk_region_destroy(tRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::Subtract(const nsIRegion &aRegion)
|
||||
{
|
||||
nsRegionGTK * pRegion = (nsRegionGTK *)&aRegion;
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, pRegion->mRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
void nsRegionGTK::Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
GdkRegion *tRegion = CreateRectRegion(aX, aY, aWidth, aHeight);
|
||||
|
||||
GdkRegion *nRegion = ::gdk_regions_subtract(mRegion, tRegion);
|
||||
::gdk_region_destroy(mRegion);
|
||||
::gdk_region_destroy(tRegion);
|
||||
mRegion = nRegion;
|
||||
}
|
||||
|
||||
PRBool nsRegionGTK::IsEmpty(void)
|
||||
{
|
||||
return (::gdk_region_empty(mRegion));
|
||||
}
|
||||
|
||||
PRBool nsRegionGTK::IsEqual(const nsIRegion &aRegion)
|
||||
{
|
||||
nsRegionGTK *pRegion = (nsRegionGTK *)&aRegion;
|
||||
|
||||
return(::gdk_region_equal(mRegion, pRegion->mRegion));
|
||||
|
||||
}
|
||||
|
||||
void nsRegionGTK::GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight)
|
||||
{
|
||||
GdkRectangle rect;
|
||||
|
||||
::gdk_region_get_clipbox(mRegion, &rect);
|
||||
|
||||
*aX = rect.x;
|
||||
*aY = rect.y;
|
||||
*aWidth = rect.width;
|
||||
*aHeight = rect.height;
|
||||
}
|
||||
|
||||
void nsRegionGTK::Offset(PRInt32 aXOffset, PRInt32 aYOffset)
|
||||
{
|
||||
::gdk_region_offset(mRegion, aXOffset, aYOffset);
|
||||
}
|
||||
|
||||
PRBool nsRegionGTK::ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight)
|
||||
{
|
||||
GdkOverlapType containment;
|
||||
GdkRectangle rect;
|
||||
|
||||
rect.x = aX;
|
||||
rect.y = aY;
|
||||
rect.width = aWidth;
|
||||
rect.height = aHeight;
|
||||
|
||||
containment = ::gdk_region_rect_in(mRegion, &rect);
|
||||
|
||||
if (containment != GDK_OVERLAP_RECTANGLE_OUT)
|
||||
return PR_TRUE;
|
||||
else
|
||||
return PR_FALSE;
|
||||
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRegionGTK::GetRects(nsRegionRectSet **aRects)
|
||||
{
|
||||
nsRegionRectSet *rects;
|
||||
GdkRegionPrivate *priv = (GdkRegionPrivate *)mRegion;
|
||||
Region pRegion = priv->xregion;
|
||||
int nbox;
|
||||
BOX *pbox;
|
||||
nsRegionRect *rect;
|
||||
|
||||
NS_ASSERTION(!(nsnull == aRects), "bad ptr");
|
||||
|
||||
//code lifted from old xfe. MMP
|
||||
|
||||
pbox = pRegion->rects;
|
||||
nbox = pRegion->numRects;
|
||||
|
||||
rects = *aRects;
|
||||
|
||||
if ((nsnull == rects) || (rects->mRectsLen < (PRUint32)nbox))
|
||||
{
|
||||
void *buf = PR_Realloc(rects, sizeof(nsRegionRectSet) + (sizeof(nsRegionRect) * (nbox - 1)));
|
||||
|
||||
if (nsnull == buf)
|
||||
{
|
||||
if (nsnull != rects)
|
||||
rects->mNumRects = 0;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
rects = (nsRegionRectSet *)buf;
|
||||
rects->mRectsLen = nbox;
|
||||
}
|
||||
|
||||
rects->mNumRects = nbox;
|
||||
rects->mArea = 0;
|
||||
rect = &rects->mRects[0];
|
||||
|
||||
while (nbox--)
|
||||
{
|
||||
rect->x = pbox->x1;
|
||||
rect->width = (pbox->x2 - pbox->x1);
|
||||
rect->y = pbox->y1;
|
||||
rect->height = (pbox->y2 - pbox->y1);
|
||||
|
||||
rects->mArea += rect->width * rect->height;
|
||||
|
||||
pbox++;
|
||||
rect++;
|
||||
}
|
||||
|
||||
*aRects = rects;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRegionGTK::FreeRects(nsRegionRectSet *aRects)
|
||||
{
|
||||
if (nsnull != aRects)
|
||||
PR_Free((void *)aRects);
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRegionGTK::GetNativeRegion(void *&aRegion) const
|
||||
{
|
||||
aRegion = (void *)mRegion;
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP nsRegionGTK::GetRegionComplexity(nsRegionComplexity &aComplexity) const
|
||||
{
|
||||
// cast to avoid const-ness problems on some compilers
|
||||
if (((nsRegionGTK*)this)->IsEmpty())
|
||||
aComplexity = eRegionComplexity_empty;
|
||||
else
|
||||
aComplexity = eRegionComplexity_complex;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void nsRegionGTK::SetRegionEmpty()
|
||||
{
|
||||
if (!IsEmpty()) {
|
||||
::gdk_region_destroy(mRegion);
|
||||
mRegion = ::gdk_region_new();
|
||||
}
|
||||
}
|
||||
|
||||
GdkRegion *nsRegionGTK::CreateRectRegion(PRInt32 aX,
|
||||
PRInt32 aY,
|
||||
PRInt32 aWidth,
|
||||
PRInt32 aHeight)
|
||||
{
|
||||
GdkRegion *tRegion = ::gdk_region_new();
|
||||
GdkRectangle rect;
|
||||
|
||||
rect.x = aX;
|
||||
rect.y = aY;
|
||||
rect.width = aWidth;
|
||||
rect.height = aHeight;
|
||||
|
||||
GdkRegion *rRegion = ::gdk_region_union_with_rect(tRegion, &rect);
|
||||
::gdk_region_destroy(tRegion);
|
||||
|
||||
return (rRegion);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsRegionGTK_h___
|
||||
#define nsRegionGTK_h___
|
||||
|
||||
#include "nsIRegion.h"
|
||||
|
||||
class nsRegionGTK : public nsIRegion
|
||||
{
|
||||
public:
|
||||
nsRegionGTK();
|
||||
virtual ~nsRegionGTK();
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
virtual nsresult Init();
|
||||
|
||||
virtual void SetTo(const nsIRegion &aRegion);
|
||||
virtual void SetTo(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
void SetTo(const nsRegionGTK *aRegion);
|
||||
virtual void Intersect(const nsIRegion &aRegion);
|
||||
virtual void Intersect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual void Union(const nsIRegion &aRegion);
|
||||
virtual void Union(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual void Subtract(const nsIRegion &aRegion);
|
||||
virtual void Subtract(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
virtual PRBool IsEmpty(void);
|
||||
virtual PRBool IsEqual(const nsIRegion &aRegion);
|
||||
virtual void GetBoundingBox(PRInt32 *aX, PRInt32 *aY, PRInt32 *aWidth, PRInt32 *aHeight);
|
||||
virtual void Offset(PRInt32 aXOffset, PRInt32 aYOffset);
|
||||
virtual PRBool ContainsRect(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
NS_IMETHOD GetRects(nsRegionRectSet **aRects);
|
||||
NS_IMETHOD FreeRects(nsRegionRectSet *aRects);
|
||||
NS_IMETHOD GetNativeRegion(void *&aRegion) const;
|
||||
NS_IMETHOD GetRegionComplexity(nsRegionComplexity &aComplexity) const;
|
||||
|
||||
GdkRegion *CreateRectRegion(PRInt32 aX, PRInt32 aY, PRInt32 aWidth, PRInt32 aHeight);
|
||||
|
||||
private:
|
||||
GdkRegion *mRegion;
|
||||
nsRegionComplexity mRegionType;
|
||||
|
||||
virtual void SetRegionEmpty();
|
||||
|
||||
};
|
||||
|
||||
#endif // nsRegionGTK_h___
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,173 +0,0 @@
|
||||
/* -*- Mode: C++; tab-width: 2; 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 nsRenderingContextGTK_h___
|
||||
#define nsRenderingContextGTK_h___
|
||||
|
||||
#include "nsIRenderingContext.h"
|
||||
#include "nsUnitConversion.h"
|
||||
#include "nsFont.h"
|
||||
#include "nsIFontMetrics.h"
|
||||
#include "nsPoint.h"
|
||||
#include "nsString.h"
|
||||
#include "nsCRT.h"
|
||||
#include "nsTransform2D.h"
|
||||
#include "nsIViewManager.h"
|
||||
#include "nsIWidget.h"
|
||||
#include "nsRect.h"
|
||||
#include "nsImageGTK.h"
|
||||
#include "nsIDeviceContext.h"
|
||||
#include "nsVoidArray.h"
|
||||
|
||||
#include "nsDrawingSurfaceGTK.h"
|
||||
#include "nsRegionGTK.h"
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
class nsRenderingContextGTK : public nsIRenderingContext
|
||||
{
|
||||
public:
|
||||
nsRenderingContextGTK();
|
||||
virtual ~nsRenderingContextGTK();
|
||||
|
||||
NS_DECL_AND_IMPL_ZEROING_OPERATOR_NEW
|
||||
|
||||
NS_DECL_ISUPPORTS
|
||||
|
||||
NS_IMETHOD Init(nsIDeviceContext* aContext, nsIWidget *aWindow);
|
||||
NS_IMETHOD Init(nsIDeviceContext* aContext, nsDrawingSurface aSurface);
|
||||
|
||||
NS_IMETHOD Reset(void);
|
||||
|
||||
NS_IMETHOD GetDeviceContext(nsIDeviceContext *&aContext);
|
||||
|
||||
NS_IMETHOD LockDrawingSurface(PRInt32 aX, PRInt32 aY, PRUint32 aWidth, PRUint32 aHeight,
|
||||
void **aBits, PRInt32 *aStride, PRInt32 *aWidthBytes,
|
||||
PRUint32 aFlags);
|
||||
NS_IMETHOD UnlockDrawingSurface(void);
|
||||
|
||||
NS_IMETHOD SelectOffScreenDrawingSurface(nsDrawingSurface aSurface);
|
||||
NS_IMETHOD GetDrawingSurface(nsDrawingSurface *aSurface);
|
||||
NS_IMETHOD GetHints(PRUint32& aResult);
|
||||
|
||||
NS_IMETHOD PushState(void);
|
||||
NS_IMETHOD PopState(PRBool &aClipEmpty);
|
||||
|
||||
NS_IMETHOD IsVisibleRect(const nsRect& aRect, PRBool &aVisible);
|
||||
|
||||
NS_IMETHOD SetClipRect(const nsRect& aRect, nsClipCombine aCombine, PRBool &aClipEmpty);
|
||||
NS_IMETHOD GetClipRect(nsRect &aRect, PRBool &aClipValid);
|
||||
NS_IMETHOD SetClipRegion(const nsIRegion& aRegion, nsClipCombine aCombine, PRBool &aClipEmpty);
|
||||
NS_IMETHOD GetClipRegion(nsIRegion **aRegion);
|
||||
|
||||
NS_IMETHOD SetLineStyle(nsLineStyle aLineStyle);
|
||||
NS_IMETHOD GetLineStyle(nsLineStyle &aLineStyle);
|
||||
|
||||
NS_IMETHOD SetColor(nscolor aColor);
|
||||
NS_IMETHOD GetColor(nscolor &aColor) const;
|
||||
|
||||
NS_IMETHOD SetFont(const nsFont& aFont);
|
||||
NS_IMETHOD SetFont(nsIFontMetrics *aFontMetrics);
|
||||
|
||||
NS_IMETHOD GetFontMetrics(nsIFontMetrics *&aFontMetrics);
|
||||
|
||||
NS_IMETHOD Translate(nscoord aX, nscoord aY);
|
||||
NS_IMETHOD Scale(float aSx, float aSy);
|
||||
NS_IMETHOD GetCurrentTransform(nsTransform2D *&aTransform);
|
||||
|
||||
NS_IMETHOD CreateDrawingSurface(nsRect *aBounds, PRUint32 aSurfFlags, nsDrawingSurface &aSurface);
|
||||
NS_IMETHOD DestroyDrawingSurface(nsDrawingSurface aDS);
|
||||
|
||||
NS_IMETHOD DrawLine(nscoord aX0, nscoord aY0, nscoord aX1, nscoord aY1);
|
||||
NS_IMETHOD DrawPolyline(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
NS_IMETHOD DrawRect(const nsRect& aRect);
|
||||
NS_IMETHOD DrawRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
NS_IMETHOD FillRect(const nsRect& aRect);
|
||||
NS_IMETHOD FillRect(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
NS_IMETHOD FillPolygon(const nsPoint aPoints[], PRInt32 aNumPoints);
|
||||
|
||||
NS_IMETHOD DrawEllipse(const nsRect& aRect);
|
||||
NS_IMETHOD DrawEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
NS_IMETHOD FillEllipse(const nsRect& aRect);
|
||||
NS_IMETHOD FillEllipse(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight);
|
||||
|
||||
NS_IMETHOD DrawArc(const nsRect& aRect,
|
||||
float aStartAngle, float aEndAngle);
|
||||
NS_IMETHOD DrawArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||
float aStartAngle, float aEndAngle);
|
||||
NS_IMETHOD FillArc(const nsRect& aRect,
|
||||
float aStartAngle, float aEndAngle);
|
||||
NS_IMETHOD FillArc(nscoord aX, nscoord aY, nscoord aWidth, nscoord aHeight,
|
||||
float aStartAngle, float aEndAngle);
|
||||
|
||||
NS_IMETHOD GetWidth(char aC, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(PRUnichar aC, nscoord &aWidth,
|
||||
PRInt32 *aFontID);
|
||||
NS_IMETHOD GetWidth(const nsString& aString, nscoord &aWidth,
|
||||
PRInt32 *aFontID);
|
||||
NS_IMETHOD GetWidth(const char *aString, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const char *aString, PRUint32 aLength, nscoord &aWidth);
|
||||
NS_IMETHOD GetWidth(const PRUnichar *aString, PRUint32 aLength, nscoord &aWidth,
|
||||
PRInt32 *aFontID);
|
||||
|
||||
NS_IMETHOD DrawString(const char *aString, PRUint32 aLength,
|
||||
nscoord aX, nscoord aY,
|
||||
const nscoord* aSpacing);
|
||||
NS_IMETHOD DrawString(const PRUnichar *aString, PRUint32 aLength,
|
||||
nscoord aX, nscoord aY,
|
||||
PRInt32 aFontID,
|
||||
const nscoord* aSpacing);
|
||||
NS_IMETHOD DrawString(const nsString& aString, nscoord aX, nscoord aY,
|
||||
PRInt32 aFontID,
|
||||
const nscoord* aSpacing);
|
||||
|
||||
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY);
|
||||
NS_IMETHOD DrawImage(nsIImage *aImage, nscoord aX, nscoord aY,
|
||||
nscoord aWidth, nscoord aHeight);
|
||||
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aRect);
|
||||
NS_IMETHOD DrawImage(nsIImage *aImage, const nsRect& aSRect, const nsRect& aDRect);
|
||||
|
||||
NS_IMETHOD CopyOffScreenBits(nsDrawingSurface aSrcSurf, PRInt32 aSrcX, PRInt32 aSrcY,
|
||||
const nsRect &aDestBounds, PRUint32 aCopyFlags);
|
||||
|
||||
//locals
|
||||
NS_IMETHOD CommonInit();
|
||||
|
||||
protected:
|
||||
nsDrawingSurfaceGTK *mOffscreenSurface;
|
||||
nsDrawingSurfaceGTK *mSurface;
|
||||
nsIDeviceContext *mContext;
|
||||
nsIFontMetrics *mFontMetrics;
|
||||
nsRegionGTK *mClipRegion;
|
||||
nsTransform2D *mTMatrix;
|
||||
float mP2T;
|
||||
GdkWChar* mDrawStringBuf;
|
||||
PRUint32 mDrawStringSize;
|
||||
|
||||
// graphic state stack (GraphicsState)
|
||||
nsVoidArray *mStateCache;
|
||||
|
||||
nscolor mCurrentColor;
|
||||
GdkFont *mCurrentFont;
|
||||
nsLineStyle mCurrentLineStyle;
|
||||
};
|
||||
|
||||
#endif /* nsRenderingContextGTK_h___ */
|
||||
File diff suppressed because it is too large
Load Diff
@@ -1,177 +0,0 @@
|
||||
/* $XConsortium: region.h,v 11.13 91/09/10 08:21:49 rws Exp $ */
|
||||
/************************************************************************
|
||||
Copyright 1987 by Digital Equipment Corporation, Maynard, Massachusetts,
|
||||
and the Massachusetts Institute of Technology, Cambridge, Massachusetts.
|
||||
|
||||
All Rights Reserved
|
||||
|
||||
Permission to use, copy, modify, and distribute this software and its
|
||||
documentation for any purpose and without fee is hereby granted,
|
||||
provided that the above copyright notice appear in all copies and that
|
||||
both that copyright notice and this permission notice appear in
|
||||
supporting documentation, and that the names of Digital or MIT not be
|
||||
used in advertising or publicity pertaining to distribution of the
|
||||
software without specific, written prior permission.
|
||||
|
||||
DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
|
||||
ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
|
||||
DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
|
||||
ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
|
||||
WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
|
||||
ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
|
||||
SOFTWARE.
|
||||
|
||||
************************************************************************/
|
||||
|
||||
#ifndef _XREGION_H
|
||||
#define _XREGION_H
|
||||
|
||||
typedef struct {
|
||||
short x1, x2, y1, y2;
|
||||
} Box, BOX, BoxRec, *BoxPtr;
|
||||
|
||||
typedef struct {
|
||||
short x, y, width, height;
|
||||
}RECTANGLE, RectangleRec, *RectanglePtr;
|
||||
|
||||
#ifdef TRUE
|
||||
#undef TRUE
|
||||
#endif
|
||||
|
||||
#define TRUE 1
|
||||
#ifndef FALSE
|
||||
#define FALSE 0
|
||||
#endif
|
||||
#ifndef MAXSHORT
|
||||
#define MAXSHORT 32767
|
||||
#endif
|
||||
#ifndef MINSHORT
|
||||
#define MINSHORT -MAXSHORT
|
||||
#endif
|
||||
#ifndef MAX
|
||||
#define MAX(a,b) (((a) > (b)) ? (a) : (b))
|
||||
#endif
|
||||
#ifndef MIN
|
||||
#define MIN(a,b) (((a) < (b)) ? (a) : (b))
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* clip region
|
||||
*/
|
||||
|
||||
typedef struct _XRegion {
|
||||
long size;
|
||||
long numRects;
|
||||
BOX *rects;
|
||||
BOX extents;
|
||||
} REGION;
|
||||
|
||||
/* Xutil.h contains the declaration:
|
||||
* typedef struct _XRegion *Region;
|
||||
*/
|
||||
|
||||
/* 1 if two BOXs overlap.
|
||||
* 0 if two BOXs do not overlap.
|
||||
* Remember, x2 and y2 are not in the region
|
||||
*/
|
||||
#define EXTENTCHECK(r1, r2) \
|
||||
((r1)->x2 > (r2)->x1 && \
|
||||
(r1)->x1 < (r2)->x2 && \
|
||||
(r1)->y2 > (r2)->y1 && \
|
||||
(r1)->y1 < (r2)->y2)
|
||||
|
||||
/*
|
||||
* update region extents
|
||||
*/
|
||||
#define EXTENTS(r,idRect){\
|
||||
if((r)->x1 < (idRect)->extents.x1)\
|
||||
(idRect)->extents.x1 = (r)->x1;\
|
||||
if((r)->y1 < (idRect)->extents.y1)\
|
||||
(idRect)->extents.y1 = (r)->y1;\
|
||||
if((r)->x2 > (idRect)->extents.x2)\
|
||||
(idRect)->extents.x2 = (r)->x2;\
|
||||
if((r)->y2 > (idRect)->extents.y2)\
|
||||
(idRect)->extents.y2 = (r)->y2;\
|
||||
}
|
||||
|
||||
/*
|
||||
* Check to see if there is enough memory in the present region.
|
||||
*/
|
||||
#define MEMCHECK(reg, rect, firstrect){\
|
||||
if ((reg)->numRects >= ((reg)->size - 1)){\
|
||||
(firstrect) = (BOX *) Xrealloc \
|
||||
((char *)(firstrect), (unsigned) (2 * (sizeof(BOX)) * ((reg)->size)));\
|
||||
if ((firstrect) == 0)\
|
||||
return(0);\
|
||||
(reg)->size *= 2;\
|
||||
(rect) = &(firstrect)[(reg)->numRects];\
|
||||
}\
|
||||
}
|
||||
|
||||
/* this routine checks to see if the previous rectangle is the same
|
||||
* or subsumes the new rectangle to add.
|
||||
*/
|
||||
|
||||
#define CHECK_PREVIOUS(Reg, R, Rx1, Ry1, Rx2, Ry2)\
|
||||
(!(((Reg)->numRects > 0)&&\
|
||||
((R-1)->y1 == (Ry1)) &&\
|
||||
((R-1)->y2 == (Ry2)) &&\
|
||||
((R-1)->x1 <= (Rx1)) &&\
|
||||
((R-1)->x2 >= (Rx2))))
|
||||
|
||||
/* add a rectangle to the given Region */
|
||||
#define ADDRECT(reg, r, rx1, ry1, rx2, ry2){\
|
||||
if (((rx1) < (rx2)) && ((ry1) < (ry2)) &&\
|
||||
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
|
||||
(r)->x1 = (rx1);\
|
||||
(r)->y1 = (ry1);\
|
||||
(r)->x2 = (rx2);\
|
||||
(r)->y2 = (ry2);\
|
||||
EXTENTS((r), (reg));\
|
||||
(reg)->numRects++;\
|
||||
(r)++;\
|
||||
}\
|
||||
}
|
||||
|
||||
|
||||
|
||||
/* add a rectangle to the given Region */
|
||||
#define ADDRECTNOX(reg, r, rx1, ry1, rx2, ry2){\
|
||||
if ((rx1 < rx2) && (ry1 < ry2) &&\
|
||||
CHECK_PREVIOUS((reg), (r), (rx1), (ry1), (rx2), (ry2))){\
|
||||
(r)->x1 = (rx1);\
|
||||
(r)->y1 = (ry1);\
|
||||
(r)->x2 = (rx2);\
|
||||
(r)->y2 = (ry2);\
|
||||
(reg)->numRects++;\
|
||||
(r)++;\
|
||||
}\
|
||||
}
|
||||
|
||||
#define EMPTY_REGION(pReg) pReg->numRects = 0
|
||||
|
||||
#define REGION_NOT_EMPTY(pReg) pReg->numRects
|
||||
|
||||
#define INBOX(r, x, y) \
|
||||
( ( ((r).x2 > x)) && \
|
||||
( ((r).x1 <= x)) && \
|
||||
( ((r).y2 > y)) && \
|
||||
( ((r).y1 <= y)) )
|
||||
|
||||
/*
|
||||
* number of points to buffer before sending them off
|
||||
* to scanlines() : Must be an even number
|
||||
*/
|
||||
#define NUMPTSTOBUFFER 200
|
||||
|
||||
/*
|
||||
* used to allocate buffers for points and link
|
||||
* the buffers together
|
||||
*/
|
||||
typedef struct _POINTBLOCK {
|
||||
XPoint pts[NUMPTSTOBUFFER];
|
||||
struct _POINTBLOCK *next;
|
||||
} POINTBLOCK;
|
||||
|
||||
#endif
|
||||
20
mozilla/lib/libnet/MANIFEST
Normal file
20
mozilla/lib/libnet/MANIFEST
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
extcache.h
|
||||
mkutils.h
|
||||
mkselect.h
|
||||
mkaccess.h
|
||||
mkautocf.h
|
||||
mkcache.h
|
||||
mkformat.h
|
||||
mkgeturl.h
|
||||
mkhelp.h
|
||||
mkstream.h
|
||||
mktcp.h
|
||||
mktrace.h
|
||||
mkpadpac.h
|
||||
mkmarimb.h
|
||||
mkparse.h
|
||||
mkimap4.h
|
||||
202
mozilla/lib/libnet/Makefile
Normal file
202
mozilla/lib/libnet/Makefile
Normal file
@@ -0,0 +1,202 @@
|
||||
#!gmake
|
||||
#
|
||||
# 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.
|
||||
|
||||
DEPTH = ../..
|
||||
|
||||
MODULE = net
|
||||
LIBRARY_NAME = net
|
||||
|
||||
CSRCS = cvactive.c \
|
||||
cvcolor.c \
|
||||
cvdisk.c \
|
||||
cvextcon.c \
|
||||
cvproxy.c \
|
||||
cvsimple.c \
|
||||
cvview.c \
|
||||
cvchunk.c \
|
||||
extcache.c \
|
||||
mkaccess.c \
|
||||
mkdaturl.c \
|
||||
mkformat.c \
|
||||
mkfsort.c \
|
||||
mkgopher.c \
|
||||
mkhelp.c \
|
||||
mkinit.c \
|
||||
mkjscfg.c \
|
||||
mkmocha.c \
|
||||
mkparse.c \
|
||||
mkremote.c \
|
||||
mkselect.c \
|
||||
mksockrw.c \
|
||||
mksort.c \
|
||||
mkstream.c \
|
||||
mktrace.c \
|
||||
mkpadpac.c \
|
||||
txview.c \
|
||||
jscookie.c \
|
||||
cvmime.c \
|
||||
cvunzip.c \
|
||||
mkautocf.c \
|
||||
mkcache.c \
|
||||
mkconect.c \
|
||||
mkcburl.c \
|
||||
mkextcac.c \
|
||||
mkfile.c \
|
||||
mkftp.c \
|
||||
mkgeturl.c \
|
||||
mkhttp.c \
|
||||
mkmemcac.c \
|
||||
mkmessag.c \
|
||||
mkutils.c \
|
||||
prefetch.c \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS = mkmarimb.cpp
|
||||
|
||||
|
||||
REQUIRES = netcast parse js dbm nspr security htmldlgs ldap softupdt \
|
||||
img util jtools layer pref java libfont lay style applet \
|
||||
zlib li msg progress net
|
||||
|
||||
EXPORTS = extcache.h \
|
||||
mkutils.h \
|
||||
mkselect.h \
|
||||
mkaccess.h \
|
||||
mkautocf.h \
|
||||
mkcache.h \
|
||||
mkformat.h \
|
||||
mkgeturl.h \
|
||||
mkhelp.h \
|
||||
mkstream.h \
|
||||
mktcp.h \
|
||||
mktrace.h \
|
||||
mkpadpac.h \
|
||||
mkmarimb.h \
|
||||
mkparse.h \
|
||||
$(NULL)
|
||||
|
||||
include $(DEPTH)/config/config.mk
|
||||
|
||||
ifdef MOZ_MAIL_NEWS
|
||||
CSRCS += \
|
||||
mkcertld.c \
|
||||
imap4url.c \
|
||||
mkmailbx.c \
|
||||
mknews.c \
|
||||
mknewsgr.c \
|
||||
mkpop3.c \
|
||||
mksmtp.c \
|
||||
$(NULL)
|
||||
|
||||
CPPSRCS += mkabook.cpp \
|
||||
imapbody.cpp \
|
||||
imaphier.cpp \
|
||||
imapearl.cpp \
|
||||
mkimap4.cpp \
|
||||
mkldap.cpp \
|
||||
imappars.cpp \
|
||||
$(NULL)
|
||||
endif
|
||||
|
||||
ifndef NO_UNIX_ASYNC_DNS
|
||||
CSRCS += unix-dns.c
|
||||
endif
|
||||
|
||||
include $(DEPTH)/config/rules.mk
|
||||
|
||||
DEFINES += -DNEW_DECODERS
|
||||
|
||||
ifndef NO_UNIX_ASYNC_DNS
|
||||
DEFINES += -DUNIX_ASYNC_DNS
|
||||
endif
|
||||
|
||||
ifndef NO_UNIX_LDAP
|
||||
INCLUDES += -I$(DIST)/include
|
||||
DEFINES += -DLIBNET_LDAP
|
||||
endif
|
||||
|
||||
#
|
||||
# This converts mime.types to C source code,
|
||||
# and also to an HTML table that shows what's in it.
|
||||
#
|
||||
MIME_TYPES = ./mime.types
|
||||
MIME_TYPES_UNIX = ./mime.types-unix
|
||||
MIME_TYPES_NONUNIX = ./mime.types-nonunix
|
||||
AD2C = sh $(DEPTH)/cmd/xfe/ad2c
|
||||
|
||||
#
|
||||
# Workaround for a SCO compiler bug.
|
||||
#
|
||||
# If mkutils.c is compiled optimized, password authorization
|
||||
# always fails. Probably due to NET_UUEncode routine.
|
||||
#
|
||||
# We could try using GCC 2.7.x instead, since that is the first
|
||||
# version that can produce SCO ELF binaries.
|
||||
#
|
||||
ifeq ($(OS_ARCH),SCOOS)
|
||||
SCO_OPT_FIX = -O0
|
||||
endif
|
||||
|
||||
$(OBJDIR)/mkformat.o: mkformat.c mktypes.h
|
||||
|
||||
$(LIBRARY): $(OBJS)
|
||||
|
||||
$(OBJDIR)/mkutils.o $(OBJDIR)/LITE_mkutils.o: mkutils.c
|
||||
@$(MAKE_OBJDIR)
|
||||
$(CC) -o $@ -c $(CFLAGS) $(SCO_OPT_FIX) $<
|
||||
|
||||
|
||||
mktypes.h: $(MIME_TYPES) $(MIME_TYPES_UNIX) $(MIME_TYPES_NONUNIX)
|
||||
rm -f $@
|
||||
@echo "generating $@ from $<..." ; \
|
||||
(echo '/* Generated file - do not edit! */' ; \
|
||||
echo '' ; \
|
||||
cat $(MIME_TYPES) | grep -v '^#' | $(AD2C) ; \
|
||||
echo '' ; \
|
||||
echo '#ifdef XP_UNIX' ; \
|
||||
cat $(MIME_TYPES_UNIX) | grep -v '^#' | $(AD2C) ; \
|
||||
echo '#else /* !XP_UNIX */' ; \
|
||||
cat $(MIME_TYPES_NONUNIX) | grep -v '^#' | $(AD2C) ; \
|
||||
echo '#endif /* !XP_UNIX */' ; \
|
||||
) > $@
|
||||
|
||||
mime-types.html: $(MIME_TYPES) $(MIME_TYPES_UNIX)
|
||||
rm -f $@
|
||||
@echo "generating $@ from $<..." ; \
|
||||
(echo '<TITLE>Netscape MIME Types</TITLE>' ; \
|
||||
echo '<H1 ALIGN=CENTER>Netscape MIME Types</H1>' ; \
|
||||
echo '<CENTER>' ; \
|
||||
echo '<TABLE BORDER CELLSPACING=0 CELLPADDING=5>' ; \
|
||||
echo '<TR><TH></TH><TH>Content Type:</TH>' ; \
|
||||
echo '<TH>Extensions:</TH><TH>Description:</TH></TR>' ; \
|
||||
echo '<TR></TR><TR></TR><TR></TR>' ; \
|
||||
cat $(MIME_TYPES) $(MIME_TYPES_UNIX) | grep -v '^#' | \
|
||||
sed 's@exts="\([^"]*\)"[ ]*[\]*@<TR><TD><TT>\1</TT></TD>@; \
|
||||
s@desc="\([^"]*\)"[ ]*[\]*@<TD>\1</TD>@; \
|
||||
s@enc=\([^ ]*\)[ ]*[\]*$$@<TD>encoding/\1</TD>@; \
|
||||
s@type=\([^ ]*\)[ ]*[\]*$$@<TD>\1</TD>@; \
|
||||
s@icon=\([^ ]*\)[ ]*[\]*$$@<TD><IMG SRC=\1></TD></TR>@'\
|
||||
| sed 's/,/ /g' \
|
||||
| awk '{if ( $$0 ~ /^<TR/ ) {printf "%s" , $$0} \
|
||||
else {printf "%s\n" , $$0} }' \
|
||||
| sed 's@\(<TR>\)\(<TD>.*</TD>\)\(<TD>.*</TD>\)\(<TD>.*</TD>\)\(<TD>.*</TD>\)\(</TR>\)$$@\1\5!\3!\2!\4\6@' \
|
||||
| tr '!' '\012' \
|
||||
| sed 's@<TD></TD>@<TD>\ </TD>@' ; \
|
||||
echo '</TABLE>' ; \
|
||||
echo '</CENTER>' ; \
|
||||
) > $@
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
#!gmake
|
||||
#
|
||||
#!/usr/local/bin/tcl -f
|
||||
# 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
|
||||
@@ -15,39 +14,11 @@
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
# Reserved.
|
||||
|
||||
DEPTH = ../../..
|
||||
topsrcdir = @top_srcdir@
|
||||
srcdir = @srcdir@
|
||||
VPATH = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
include $(topsrcdir)/config/config.mk
|
||||
|
||||
LIBRARY_NAME = gfxgtk
|
||||
|
||||
MODULE=raptor
|
||||
|
||||
REQUIRES=util img xpcom raptor netlib ps
|
||||
|
||||
DEFINES += -D_IMPL_NS_GFXONXP
|
||||
CXXFLAGS += $(TK_CFLAGS)
|
||||
INCLUDES += $(TK_CFLAGS) -I$(srcdir)/..
|
||||
|
||||
CPPSRCS = \
|
||||
nsDrawingSurfaceGTK.cpp \
|
||||
nsDeviceContextGTK.cpp \
|
||||
nsDeviceContextSpecFactoryG.cpp \
|
||||
nsDeviceContextSpecG.cpp \
|
||||
nsFontMetricsGTK.cpp \
|
||||
nsGfxFactoryGTK.cpp \
|
||||
nsRenderingContextGTK.cpp \
|
||||
nsImageGTK.cpp \
|
||||
nsRegionGTK.cpp
|
||||
|
||||
CSRCS = \
|
||||
nsPrintdGTK.c
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
# This takes a date string (fairly arbitrarily formatted), and spews out
|
||||
# a number suitable for pasting into the timebomb code.
|
||||
|
||||
foreach i $argv {
|
||||
set num [convertclock $i]
|
||||
puts "$num [fmtclock $num]"
|
||||
}
|
||||
137
mozilla/lib/libnet/cachedump.c
Normal file
137
mozilla/lib/libnet/cachedump.c
Normal file
@@ -0,0 +1,137 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/* this little program will sequentially dump out
|
||||
* every record in the database
|
||||
*/
|
||||
#include "extcache.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <assert.h>
|
||||
|
||||
#ifdef _sgi
|
||||
#include <sys/endian.h>
|
||||
#endif /* _sgi */
|
||||
|
||||
/* URL methods
|
||||
*/
|
||||
#define URL_GET_METHOD 0
|
||||
#define URL_POST_METHOD 1
|
||||
#define URL_HEAD_METHOD 2
|
||||
|
||||
static DB *
|
||||
net_OpenExtCacheFatDB(char *filename)
|
||||
{
|
||||
DB *rv;
|
||||
HASHINFO hash_info = {
|
||||
16*1024, /* bucket size */
|
||||
0, /* fill factor */
|
||||
0, /* number of elements */
|
||||
0, /* bytes to cache */
|
||||
0, /* hash function */
|
||||
0}; /* byte order */
|
||||
|
||||
|
||||
rv = dbopen(filename,
|
||||
O_RDWR | O_CREAT,
|
||||
0644,
|
||||
DB_HASH,
|
||||
&hash_info);
|
||||
|
||||
if(!rv)
|
||||
{
|
||||
printf("Could not open cache database: %s\n", filename);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
char url[4028];
|
||||
struct stat stat_s;
|
||||
net_CacheObject * cache_obj;
|
||||
DB * ext_cache_database=0;
|
||||
DBT key;
|
||||
DBT data;
|
||||
int len;
|
||||
char *end;
|
||||
|
||||
memset(&cache_obj, 0, sizeof(net_CacheObject));
|
||||
|
||||
if(argc != 2)
|
||||
{
|
||||
printf("Usage:\n"
|
||||
"%s database\n"
|
||||
"\n"
|
||||
"database: path and name of the database\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
/* open the cache database */
|
||||
ext_cache_database = net_OpenExtCacheFatDB(argv[1]);
|
||||
|
||||
if(!ext_cache_database)
|
||||
{
|
||||
perror("Could not open cache database");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
while(!(ext_cache_database->seq)(ext_cache_database, &key, &data, 0))
|
||||
{
|
||||
|
||||
if(key.size == XP_STRLEN(EXT_CACHE_NAME_STRING)
|
||||
&& !XP_STRCMP(key.data, EXT_CACHE_NAME_STRING))
|
||||
{
|
||||
/* make sure it's a terminated string */
|
||||
if(((char *)data.data)[data.size-1] == '\0')
|
||||
printf("\n\nDatabase Name: %s\n", (char*)data.data);
|
||||
else
|
||||
printf("\n\nDatabase Name is corrupted!\n");
|
||||
printf("\n--------------------------------------\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* try and convert the db struct to a cache struct */
|
||||
cache_obj = net_DBDataToCacheStruct(&data);
|
||||
|
||||
if(!cache_obj)
|
||||
{
|
||||
printf("Malformed database entry:\n");
|
||||
printf("key: ");
|
||||
fwrite(key.data, 1, key.size, stdout);
|
||||
printf("\ndata: ");
|
||||
fwrite(data.data, 1, data.size, stdout);
|
||||
printf("\n");
|
||||
printf("--------------------------------------\n");
|
||||
continue;
|
||||
}
|
||||
|
||||
/* the URL is 8 bytes into the key struct
|
||||
*/
|
||||
printf("URL: %s\n",(char*)key.data+8);
|
||||
printf("file: %s\n", cache_obj->filename);
|
||||
printf("is_relative_path: %s\n", cache_obj->is_relative_path ? "TRUE" : "FALSE");
|
||||
printf("content_type: %s\n", cache_obj->content_type);
|
||||
printf("content_length: %d\n", cache_obj->content_length);
|
||||
printf("last_modified: %s\n", ctime(&cache_obj->last_modified));
|
||||
printf("--------------------------------------\n");
|
||||
}
|
||||
}
|
||||
|
||||
1459
mozilla/lib/libnet/crawler.c
Normal file
1459
mozilla/lib/libnet/crawler.c
Normal file
File diff suppressed because it is too large
Load Diff
179
mozilla/lib/libnet/crawler.h
Normal file
179
mozilla/lib/libnet/crawler.h
Normal file
@@ -0,0 +1,179 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*** crawler.h ****************************************************/
|
||||
/* description: html crawler */
|
||||
|
||||
|
||||
/********************************************************************
|
||||
|
||||
The crawler scans html pages and the links in those pages to a specified
|
||||
depth in a breadth first manner, optionally caching them in an external cache.
|
||||
Items are crawled sequentially - an item must finish being crawled or cached
|
||||
before the next item is crawled. Multiple instances of the crawler may be running
|
||||
at the same time.
|
||||
|
||||
Depth = 1 means that only the initial page, and any images and resources that
|
||||
it contains, are cached.
|
||||
|
||||
Depth = n means that the crawler will crawl to n levels deep. Assuming the
|
||||
maximum cache size is sufficient, the crawler will cache images and resources
|
||||
for each page it encounters. Normally, resources are cached after all the pages
|
||||
for a given level have been processed, but some resources are considered "required",
|
||||
meaning they will be cached immediately after the page containing them has been
|
||||
processed. An example of a "required" resource is a stylesheet.
|
||||
|
||||
The crawler obeys the robots.txt directives on a site, which may allow or deny access
|
||||
to specific urls or directories. The robots.txt file is by convention at the top level
|
||||
of a site.
|
||||
|
||||
The type of links that are crawled are determined in pagescan.c.
|
||||
The parsing code is in htmparse.c
|
||||
The robots.txt parser is in robotxt.c
|
||||
|
||||
$Revision: 3.1 $
|
||||
$Date: 1998-03-28 03:31:25 $
|
||||
|
||||
*********************************************************************/
|
||||
|
||||
#ifndef crawler_h___
|
||||
#define crawler_h___
|
||||
|
||||
#include "ntypes.h" /* for MWContext */
|
||||
#include "prtypes.h" /* for PRBool */
|
||||
#include "net.h" /* for ExtCacheDBInfo, URL_Struct */
|
||||
|
||||
/* Error codes */
|
||||
typedef PRUint16 CRAWL_Error;
|
||||
|
||||
#define CRAWL_CACHE_FULL ((CRAWL_Error)0x0001)
|
||||
#define CRAWL_NO_MEMORY ((CRAWL_Error)0x0002)
|
||||
#define CRAWL_SERVER_ERR ((CRAWL_Error)0x0004)
|
||||
#define CRAWL_INTERRUPTED ((CRAWL_Error)0x0008)
|
||||
|
||||
/* these error codes indicate if and how the cache has been updated and are only
|
||||
set if CRAWL_MakeCrawler was called with manageCache set to true. Note that replaced
|
||||
links may not have been reported as such if the server does not provide a last
|
||||
modified date.
|
||||
*/
|
||||
#define CRAWL_NEW_LINK ((CRAWL_Error)0x0010)
|
||||
#define CRAWL_REPLACED_LINK ((CRAWL_Error)0x0020)
|
||||
#define CRAWL_REMOVED_LINK ((CRAWL_Error)0x0040)
|
||||
|
||||
/* Most of the APIs require a reference to CRAWL_Crawler, which is created by CRAWL_MakeCrawler. */
|
||||
typedef struct _CRAWL_CrawlerStruct *CRAWL_Crawler;
|
||||
|
||||
/*
|
||||
* Typedef for a callback executed when an item has been processed.
|
||||
*/
|
||||
typedef void
|
||||
(PR_CALLBACK *CRAWL_PostProcessItemFn)(CRAWL_Crawler crawler, URL_Struct *url_s, PRBool isCached, void *data);
|
||||
|
||||
/*
|
||||
* Typedef for a callback executed when the crawler is done.
|
||||
*/
|
||||
typedef void
|
||||
(PR_CALLBACK *CRAWL_ExitFn)(CRAWL_Crawler crawler, void *data);
|
||||
|
||||
/****************************************************************************************/
|
||||
/* public API */
|
||||
/****************************************************************************************/
|
||||
|
||||
NSPR_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
Creates a crawler which may be used for one crawling request. Subsequent requests
|
||||
to crawl urls should use a separate crawler instance. Returns NULL if not enough
|
||||
memory is available, or the depth is less than 1.
|
||||
|
||||
Parameters:
|
||||
context - needed by netlib (the crawler does not check this parameter)
|
||||
siteName - url of the site
|
||||
stayInSite - whether to restrict crawling to the site named.
|
||||
manageCache - whether to maintain a local file describing the cache contents.
|
||||
If true, the crawler uses the file to remove dangling links from the cache
|
||||
the next time it is invoked with the same cache. This is not guaranteed to
|
||||
work correctly if another crawling instance uses the same cache simultaneously.
|
||||
cache - the external cache. This may be NULL if the crawled items do not need
|
||||
to be put in an external cache.
|
||||
postProcessItemFn - a function which is called after each item has been handled
|
||||
by netlib. This may be NULL.
|
||||
postProcessItemData - this data is supplied as a parameter to the postProcessItemFn
|
||||
and is opaque to the crawler. This may be NULL.
|
||||
exitFn - a function which is called when the crawler is done or has terminated
|
||||
prematurely (because the cache is full, or no memory is available). This may be NULL.
|
||||
exitData - this data is supplied as a parameter to the exitFn and is opaque to
|
||||
the crawler. This may be NULL.
|
||||
*/
|
||||
PR_EXTERN(CRAWL_Crawler)
|
||||
CRAWL_MakeCrawler(MWContext *context,
|
||||
char *siteName,
|
||||
uint8 depth,
|
||||
PRBool stayInSite,
|
||||
PRBool manageCache,
|
||||
ExtCacheDBInfo *cache,
|
||||
CRAWL_PostProcessItemFn postProcessItemFn,
|
||||
void *postProcessItemData,
|
||||
CRAWL_ExitFn exitFn,
|
||||
void *exitData);
|
||||
|
||||
/*
|
||||
Destroys the crawler and all memory associated with it. The crawler instance should not be
|
||||
used after calling this function.
|
||||
*/
|
||||
PR_EXTERN(void)
|
||||
CRAWL_DestroyCrawler(CRAWL_Crawler crawler);
|
||||
|
||||
/*
|
||||
Starts crawling from the url. If its content type is text/html, links may be traversed. This function
|
||||
returns as soon as the first network request is issued.
|
||||
*/
|
||||
PR_EXTERN(void)
|
||||
CRAWL_StartCrawler(CRAWL_Crawler crawler, char *url);
|
||||
|
||||
/*
|
||||
Stops crawling at the next link. This function returns immediately and cannot fail.
|
||||
*/
|
||||
PR_EXTERN(void)
|
||||
CRAWL_StopCrawler(CRAWL_Crawler crawler);
|
||||
|
||||
/*
|
||||
Returns the crawler error code. This function returns immediately and cannot fail.
|
||||
*/
|
||||
PR_EXTERN(CRAWL_Error)
|
||||
CRAWL_GetError(CRAWL_Crawler crawler);
|
||||
|
||||
/*
|
||||
Returns true if the crawler has stopped, which is the case before and after crawling. Returns
|
||||
immediately and cannot fail.
|
||||
*/
|
||||
PR_EXTERN(PRBool)
|
||||
CRAWL_IsStopped(CRAWL_Crawler crawler);
|
||||
|
||||
NSPR_END_EXTERN_C
|
||||
|
||||
/*
|
||||
Stream function for crawling resources. Resources are not parsed, but the crawler checks the
|
||||
content length to see if the cache would be exceeded.
|
||||
*/
|
||||
PUBLIC NET_StreamClass*
|
||||
CRAWL_CrawlerResourceConverter(int format_out,
|
||||
void *data_object,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
#endif /* crawler_h___ */
|
||||
482
mozilla/lib/libnet/cvactive.c
Normal file
482
mozilla/lib/libnet/cvactive.c
Normal file
@@ -0,0 +1,482 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
#include "cvactive.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "mkstream.h"
|
||||
#include "glhist.h"
|
||||
#include "xp.h"
|
||||
#include "merrors.h"
|
||||
|
||||
|
||||
extern int MK_OUT_OF_MEMORY;
|
||||
|
||||
|
||||
typedef struct _DataObject {
|
||||
int state;
|
||||
NET_StreamClass *next_stream;
|
||||
char *prev_buffer;
|
||||
int32 prev_buffer_len;
|
||||
MWContext *window_id;
|
||||
int format_out;
|
||||
URL_Struct *URL_s;
|
||||
XP_Bool signal_at_end_of_multipart;
|
||||
} DataObject;
|
||||
|
||||
#define NORMAL_S 1
|
||||
#define FOUND_BOUNDARY_S 2
|
||||
|
||||
#define MAX_MIME_LINE 200
|
||||
|
||||
/* parse a mime/multipart stream. The boundary is already
|
||||
* known and we start off in the content of the original
|
||||
* message/822 body.
|
||||
*
|
||||
* buffer data up to the size of the passed in data length
|
||||
* for efficiency of the upstream module.
|
||||
*/
|
||||
PRIVATE int net_MultipleDocumentWrite (NET_StreamClass *stream, CONST char* s, int32 l)
|
||||
{
|
||||
int32 i=0;
|
||||
int32 line_length=1;
|
||||
int rv=0;
|
||||
char *cp;
|
||||
char *line;
|
||||
char *push_buffer=NULL;
|
||||
int32 push_buffer_size=0;
|
||||
XP_Bool all_done=FALSE;
|
||||
DataObject *obj=stream->data_object;
|
||||
BlockAllocCat(obj->prev_buffer, obj->prev_buffer_len, s, l);
|
||||
obj->prev_buffer_len += l;
|
||||
|
||||
if(!obj->prev_buffer)
|
||||
return(MK_OUT_OF_MEMORY);
|
||||
|
||||
line = obj->prev_buffer;
|
||||
|
||||
/* try and find a line
|
||||
*/
|
||||
for(cp=obj->prev_buffer; i < obj->prev_buffer_len; cp++, i++, line_length++)
|
||||
{
|
||||
if(*cp == '\n')
|
||||
{
|
||||
|
||||
switch(obj->state)
|
||||
{
|
||||
case NORMAL_S:
|
||||
{
|
||||
char *cp2 = line;
|
||||
int blength = XP_STRLEN(obj->URL_s->boundary);
|
||||
|
||||
/* look for boundary. We can rest assured that these
|
||||
XP_STRNCMP() calls are safe, because we know that the
|
||||
valid portion of the string starting at cp2 has a
|
||||
newline in it (at *cp), and we know that boundary
|
||||
strings never have newlines in them. */
|
||||
if((!XP_STRNCMP(cp2, "--",2) &&
|
||||
!XP_STRNCMP(cp2+2,
|
||||
obj->URL_s->boundary,
|
||||
blength))
|
||||
|| (!XP_STRNCMP(cp2,
|
||||
obj->URL_s->boundary,
|
||||
blength)))
|
||||
{
|
||||
TRACEMSG(("Found boundary: %s", obj->URL_s->boundary));
|
||||
obj->state = FOUND_BOUNDARY_S;
|
||||
|
||||
if(obj->next_stream)
|
||||
{
|
||||
|
||||
if(push_buffer)
|
||||
{
|
||||
/* strip the last newline before the
|
||||
* boundary
|
||||
*/
|
||||
push_buffer_size--;
|
||||
/* if there is a CR as well as a LF
|
||||
* strip that too
|
||||
*/
|
||||
if(push_buffer_size > 0 && push_buffer[push_buffer_size-1] == CR)
|
||||
push_buffer_size--;
|
||||
rv = (*obj->next_stream->put_block)
|
||||
(obj->next_stream,
|
||||
push_buffer,
|
||||
push_buffer_size);
|
||||
FREE(push_buffer);
|
||||
push_buffer = NULL;
|
||||
push_buffer_size = 0;
|
||||
}
|
||||
|
||||
TRACEMSG(("Completeing an open stream"));
|
||||
/* if this stream is not the last one, set a flag
|
||||
before completion to let completion do special stuff */
|
||||
XP_ASSERT(cp2 + blength <= cp);
|
||||
/* Because the above XP_STRCMP calls succeeded.
|
||||
Because this is true, we know the first call
|
||||
to XP_STRNCMP below is always safe, but we
|
||||
need to check lengths before we can be sure
|
||||
the other call is safe. */
|
||||
|
||||
if( (cp2 + blength + 2 < cp &&
|
||||
!XP_STRNCMP(cp2+2+blength, "--",2))
|
||||
|| !XP_STRNCMP(cp2+blength, "--",2))
|
||||
{
|
||||
/* very last boundary */
|
||||
obj->next_stream->is_multipart = FALSE;
|
||||
|
||||
/* set the all_done flag when
|
||||
* we have found the final boundary
|
||||
*/
|
||||
all_done = TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->next_stream->is_multipart = TRUE;
|
||||
}
|
||||
|
||||
/* complete the last stream
|
||||
*/
|
||||
(*obj->next_stream->complete)
|
||||
(obj->next_stream);
|
||||
FREE(obj->next_stream);
|
||||
obj->next_stream = NULL;
|
||||
}
|
||||
|
||||
/* move the line ptr up to new data */
|
||||
line = cp+1;
|
||||
line_length=1; /* reset */
|
||||
|
||||
if(all_done && obj->signal_at_end_of_multipart)
|
||||
return(MK_MULTIPART_MESSAGE_COMPLETED);
|
||||
break;
|
||||
}
|
||||
else
|
||||
{
|
||||
TRACEMSG(("Pushing line (actually buffering)"));
|
||||
|
||||
/* didn't find the boundary
|
||||
*/
|
||||
if(obj->next_stream)
|
||||
{
|
||||
|
||||
BlockAllocCat(push_buffer, push_buffer_size,
|
||||
line, line_length);
|
||||
push_buffer_size += line_length;
|
||||
if(!push_buffer)
|
||||
return(MK_OUT_OF_MEMORY);
|
||||
}
|
||||
|
||||
/* move the line ptr up to new data */
|
||||
line = cp+1;
|
||||
line_length=0; /* reset */
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
case FOUND_BOUNDARY_S:
|
||||
|
||||
XP_ASSERT(*cp == '\n'); /* from the 'if' above */
|
||||
|
||||
/* terminate at the newline.
|
||||
* now 'line' points to a valid NULL terminated C string
|
||||
*/
|
||||
*cp = '\0';
|
||||
|
||||
TRACEMSG(("Parsing header: >%s<", line));
|
||||
|
||||
/* parse mime headers
|
||||
* stop when a blank line is encountered
|
||||
*/
|
||||
if(*line == '\0' || *line == '\r')
|
||||
{
|
||||
int format_out;
|
||||
obj->state = NORMAL_S;
|
||||
|
||||
TRACEMSG(("Found end of headers"));
|
||||
if (obj->URL_s->content_type == NULL)
|
||||
StrAllocCopy(obj->URL_s->content_type, TEXT_PLAIN);
|
||||
|
||||
/* abort all existing streams. We
|
||||
* have to do this to prevent the
|
||||
* image lib and other things from
|
||||
* continuing to load the page after
|
||||
* we left.
|
||||
*
|
||||
* don't abort other streams if it's
|
||||
* just a new inline image or if the
|
||||
* stream is not going to the screen
|
||||
*/
|
||||
if(CLEAR_CACHE_BIT(obj->format_out) != FO_INTERNAL_IMAGE
|
||||
&& (!strncasecomp(obj->URL_s->content_type,
|
||||
"text", 4)
|
||||
||
|
||||
!strncasecomp(obj->URL_s->content_type,
|
||||
"image", 4)) )
|
||||
{
|
||||
NET_SilentInterruptWindow(obj->window_id);
|
||||
format_out = obj->format_out;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* don't cache image animations... */
|
||||
format_out = CLEAR_CACHE_BIT(obj->format_out);
|
||||
}
|
||||
|
||||
/* libimg and libplugin use the fe_data to store
|
||||
* urls data, so clear it only if its not them */
|
||||
if( (CLEAR_CACHE_BIT(obj->format_out) != FO_INTERNAL_IMAGE)
|
||||
&& (CLEAR_CACHE_BIT(obj->format_out) != FO_PLUGIN)
|
||||
&& (CLEAR_CACHE_BIT(obj->format_out) != FO_BYTERANGE)
|
||||
&& strncasecomp(obj->URL_s->content_type, "image", 5))
|
||||
{
|
||||
obj->URL_s->fe_data = NULL;
|
||||
}
|
||||
|
||||
/* build a stream
|
||||
*/
|
||||
obj->next_stream = NET_StreamBuilder(format_out,
|
||||
obj->URL_s,
|
||||
obj->window_id);
|
||||
|
||||
if(!obj->next_stream)
|
||||
return(MK_UNABLE_TO_CONVERT);
|
||||
|
||||
}
|
||||
else if(!strncasecomp(line, "CONTENT-TYPE:", 13))
|
||||
{
|
||||
|
||||
XP_STRTOK(line+13, ";"); /* terminate at ; */
|
||||
|
||||
StrAllocCopy(obj->URL_s->content_type,
|
||||
XP_StripLine(line+13));
|
||||
|
||||
if(!obj->URL_s->content_type || !*obj->URL_s->content_type)
|
||||
StrAllocCopy(obj->URL_s->content_type, TEXT_PLAIN);
|
||||
|
||||
TRACEMSG(("found new content_type: %s",
|
||||
obj->URL_s->content_type));
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
/* Pass all other headers to the MIME header parser
|
||||
*/
|
||||
char *value = XP_STRCHR(line, ':');
|
||||
if(value)
|
||||
value++;
|
||||
NET_ParseMimeHeader(NET_AllowForeignCookies,
|
||||
obj->window_id,
|
||||
obj->URL_s,
|
||||
line,
|
||||
value, FALSE);
|
||||
}
|
||||
line = cp+1;
|
||||
line_length = 0;
|
||||
break;
|
||||
|
||||
default:
|
||||
assert(0);
|
||||
break;
|
||||
|
||||
}
|
||||
} /* end if */
|
||||
} /* end for */
|
||||
|
||||
if(line_length > MAX_MIME_LINE * 2)
|
||||
{
|
||||
int32 new_size;
|
||||
|
||||
TRACEMSG(("Line too long pushing it"));
|
||||
|
||||
if(obj->next_stream)
|
||||
{
|
||||
if(push_buffer)
|
||||
{
|
||||
rv = (*obj->next_stream->put_block)(obj->next_stream,
|
||||
push_buffer,
|
||||
push_buffer_size);
|
||||
rv = (*obj->next_stream->put_block)(obj->next_stream,
|
||||
line,
|
||||
MAX_MIME_LINE);
|
||||
FREE(push_buffer);
|
||||
push_buffer = 0;
|
||||
push_buffer_size = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
rv = (*obj->next_stream->put_block)(obj->next_stream,
|
||||
line,
|
||||
MAX_MIME_LINE);
|
||||
}
|
||||
|
||||
if(rv < 0)
|
||||
return(rv);
|
||||
}
|
||||
|
||||
/* newsize equals the old size minus the difference
|
||||
* between line and the start of the old buffer and
|
||||
* the MAX_MIME_LENGTH that we just wrote out
|
||||
*/
|
||||
new_size = obj->prev_buffer_len -
|
||||
((line - obj->prev_buffer) + MAX_MIME_LINE);
|
||||
|
||||
XP_MEMMOVE(obj->prev_buffer, line+MAX_MIME_LINE, new_size);
|
||||
obj->prev_buffer_len = new_size;
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
if(line != obj->prev_buffer)
|
||||
{
|
||||
/* some part of the line has been digested, get rid of
|
||||
* the part that has been used
|
||||
*/
|
||||
obj->prev_buffer_len -= (line - obj->prev_buffer);
|
||||
XP_MEMMOVE(obj->prev_buffer, line, obj->prev_buffer_len);
|
||||
}
|
||||
|
||||
/* if there is anything in the push buffer send it now
|
||||
*/
|
||||
if(push_buffer)
|
||||
{
|
||||
if(obj->next_stream)
|
||||
{
|
||||
TRACEMSG(("Pushing buffered data"));
|
||||
rv = (*obj->next_stream->put_block)(obj->next_stream,
|
||||
push_buffer,
|
||||
push_buffer_size);
|
||||
}
|
||||
FREE(push_buffer);
|
||||
if (rv < 0)
|
||||
return rv;
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* is the stream ready for writeing?
|
||||
*/
|
||||
PRIVATE unsigned int net_MultipleDocumentWriteReady (NET_StreamClass * stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
if(obj->next_stream)
|
||||
return((*obj->next_stream->is_write_ready)(obj->next_stream));
|
||||
else
|
||||
return(MAX_WRITE_READY);
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_MultipleDocumentComplete (NET_StreamClass *stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
|
||||
if(obj->next_stream)
|
||||
{
|
||||
(*obj->next_stream->complete)(obj->next_stream);
|
||||
FREE(obj->next_stream);
|
||||
}
|
||||
|
||||
FREEIF(obj->prev_buffer);
|
||||
FREE(obj);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE void net_MultipleDocumentAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
if(obj->next_stream)
|
||||
{
|
||||
(*obj->next_stream->abort)(obj->next_stream, status);
|
||||
FREE(obj->next_stream);
|
||||
}
|
||||
|
||||
FREEIF(obj->prev_buffer);
|
||||
FREE(obj);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
CV_MakeMultipleDocumentStream (int format_out,
|
||||
void *data_object,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
DataObject* obj;
|
||||
NET_StreamClass* stream;
|
||||
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
GH_UpdateGlobalHistory(URL_s);
|
||||
|
||||
URL_s->is_active = TRUE; /* set to disable view source */
|
||||
|
||||
stream = XP_NEW(NET_StreamClass);
|
||||
if(stream == NULL)
|
||||
return(NULL);
|
||||
|
||||
obj = XP_NEW(DataObject);
|
||||
if (obj == NULL)
|
||||
return(NULL);
|
||||
|
||||
XP_MEMSET(obj, 0, sizeof(DataObject));
|
||||
|
||||
if(CVACTIVE_SIGNAL_AT_END_OF_MULTIPART == (int) data_object)
|
||||
obj->signal_at_end_of_multipart = TRUE;
|
||||
|
||||
stream->name = "Multiple Document";
|
||||
stream->complete = (MKStreamCompleteFunc) net_MultipleDocumentComplete;
|
||||
stream->abort = (MKStreamAbortFunc) net_MultipleDocumentAbort;
|
||||
stream->put_block = (MKStreamWriteFunc) net_MultipleDocumentWrite;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc) net_MultipleDocumentWriteReady;
|
||||
stream->data_object = obj; /* document info object */
|
||||
stream->window_id = window_id;
|
||||
|
||||
/* don't cache these
|
||||
format_out = CLEAR_CACHE_BIT(format_out);
|
||||
*/
|
||||
|
||||
/* enable clicking since it doesnt go through the cache
|
||||
* code
|
||||
*/
|
||||
FE_EnableClicking(window_id);
|
||||
|
||||
obj->next_stream = NULL;
|
||||
obj->window_id = window_id;
|
||||
obj->format_out = format_out;
|
||||
obj->URL_s = URL_s;
|
||||
obj->state = NORMAL_S;
|
||||
|
||||
/* make sure that we have a real boundary.
|
||||
* if not fill in '--' as a boundary
|
||||
*/
|
||||
if(!URL_s->boundary)
|
||||
StrAllocCopy(URL_s->boundary, "--");
|
||||
|
||||
/* overwrite the current content type with TEXT/PLAIN since
|
||||
* we want that as the default content-type for
|
||||
* body parts
|
||||
*/
|
||||
StrAllocCopy(URL_s->content_type, TEXT_PLAIN);
|
||||
|
||||
TRACEMSG(("Returning stream from NET_MultipleDocumentConverter\n"));
|
||||
|
||||
return stream;
|
||||
}
|
||||
315
mozilla/lib/libnet/cvchunk.c
Normal file
315
mozilla/lib/libnet/cvchunk.c
Normal file
@@ -0,0 +1,315 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/* Please leave outside of ifdef for windows precompiled headers */
|
||||
#include "mkutils.h"
|
||||
|
||||
#ifdef MOZILLA_CLIENT
|
||||
|
||||
#include "cvchunk.h" /* prototype */
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "xp.h"
|
||||
|
||||
extern int MK_OUT_OF_MEMORY;
|
||||
|
||||
typedef enum {
|
||||
FIND_CHUNK_SIZE,
|
||||
READ_CHUNK,
|
||||
STRIP_CRLF,
|
||||
PARSE_FOOTER
|
||||
} States;
|
||||
|
||||
typedef struct _DataObject {
|
||||
NET_StreamClass *next_stream;
|
||||
char *in_buf;
|
||||
uint32 in_buf_size;
|
||||
uint32 chunk_size;
|
||||
uint32 amount_of_chunk_parsed;
|
||||
States cur_state;
|
||||
FO_Present_Types format_out;
|
||||
MWContext *context;
|
||||
URL_Struct *URL_s;
|
||||
} DataObject;
|
||||
|
||||
|
||||
/* unchunk the message and return MK_MULTIPART_MESSAGE_COMPLETED
|
||||
* when end detected
|
||||
*/
|
||||
PRIVATE int net_ChunkedWrite (NET_StreamClass *stream, char* s, int32 l)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
BlockAllocCat(obj->in_buf, obj->in_buf_size, s, l);
|
||||
if(!obj->in_buf)
|
||||
return MK_OUT_OF_MEMORY;
|
||||
obj->in_buf_size += l;
|
||||
|
||||
while(obj->in_buf_size > 0)
|
||||
{
|
||||
if(obj->cur_state == FIND_CHUNK_SIZE)
|
||||
{
|
||||
char *line_feed;
|
||||
char *semicolon;
|
||||
char *end;
|
||||
|
||||
/* we don't have a current chunk size
|
||||
* look for a new chunk size
|
||||
*
|
||||
* make sure the line has a CRLF
|
||||
*/
|
||||
if((line_feed = XP_STRNCHR(obj->in_buf, LF, obj->in_buf_size)) == NULL)
|
||||
{
|
||||
return 1; /* need more data */
|
||||
}
|
||||
|
||||
*line_feed = '\0';
|
||||
|
||||
semicolon = XP_STRNCHR(obj->in_buf, ';', line_feed-obj->in_buf);
|
||||
|
||||
if(semicolon)
|
||||
*semicolon = '\0';
|
||||
|
||||
end = semicolon ? semicolon : line_feed;
|
||||
|
||||
/* read the first integer and ignore any thing
|
||||
* else on the line. Extensions are allowed
|
||||
*/
|
||||
obj->chunk_size = strtol(obj->in_buf, &end, 16);
|
||||
|
||||
/* strip everything up to the line feed */
|
||||
obj->in_buf_size -= (line_feed+1) - obj->in_buf;
|
||||
if(obj->in_buf_size)
|
||||
XP_MEMMOVE(obj->in_buf,
|
||||
line_feed+1,
|
||||
obj->in_buf_size);
|
||||
|
||||
if(obj->chunk_size == 0)
|
||||
{
|
||||
/* the stream should be done now */
|
||||
obj->cur_state = PARSE_FOOTER;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->cur_state = READ_CHUNK;
|
||||
}
|
||||
|
||||
}
|
||||
else if(obj->cur_state == READ_CHUNK)
|
||||
{
|
||||
uint32 data_size;
|
||||
int32 status;
|
||||
|
||||
/* take as much data as we have and push it up the stream
|
||||
*/
|
||||
|
||||
data_size = MIN(obj->in_buf_size, obj->chunk_size-obj->amount_of_chunk_parsed);
|
||||
|
||||
status = (obj->next_stream->put_block)(obj->next_stream,
|
||||
obj->in_buf,
|
||||
data_size);
|
||||
if(status < 0)
|
||||
return status;
|
||||
|
||||
/* remove the part that has been pushed */
|
||||
obj->in_buf_size -= data_size;
|
||||
if(obj->in_buf_size)
|
||||
XP_MEMMOVE(obj->in_buf,
|
||||
obj->in_buf+data_size,
|
||||
obj->in_buf_size);
|
||||
|
||||
obj->amount_of_chunk_parsed += data_size;
|
||||
|
||||
if(obj->amount_of_chunk_parsed >= obj->chunk_size)
|
||||
{
|
||||
XP_ASSERT(obj->amount_of_chunk_parsed == obj->chunk_size);
|
||||
/* reinit */
|
||||
obj->amount_of_chunk_parsed = 0;
|
||||
obj->cur_state = STRIP_CRLF;
|
||||
}
|
||||
}
|
||||
else if(obj->cur_state == STRIP_CRLF)
|
||||
{
|
||||
if(obj->in_buf_size > 1 && obj->in_buf[0] == CR && obj->in_buf[1] == LF)
|
||||
{
|
||||
/* strip two bytes */
|
||||
obj->in_buf_size -= 2;
|
||||
if(obj->in_buf_size)
|
||||
XP_MEMMOVE(obj->in_buf,
|
||||
obj->in_buf+2,
|
||||
obj->in_buf_size);
|
||||
obj->cur_state = FIND_CHUNK_SIZE;
|
||||
}
|
||||
else if(obj->in_buf[0] == LF)
|
||||
{
|
||||
/* strip one bytes */
|
||||
obj->in_buf_size -= 1;
|
||||
if(obj->in_buf_size)
|
||||
XP_MEMMOVE(obj->in_buf,
|
||||
obj->in_buf+1,
|
||||
obj->in_buf_size);
|
||||
obj->cur_state = FIND_CHUNK_SIZE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if(obj->in_buf_size >= 2)
|
||||
{
|
||||
int status;
|
||||
|
||||
/* a fatal parse error */
|
||||
XP_ASSERT(0);
|
||||
|
||||
/* just spew the buf to the screen */
|
||||
status = (obj->next_stream->put_block)(obj->next_stream,
|
||||
obj->in_buf,
|
||||
obj->in_buf_size);
|
||||
if(status < 0)
|
||||
return status;
|
||||
|
||||
/* remove the part that has been pushed */
|
||||
obj->in_buf_size = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(obj->cur_state == PARSE_FOOTER)
|
||||
{
|
||||
char *line_feed;
|
||||
char *value;
|
||||
|
||||
/* parse until we see two CRLF's in a row */
|
||||
if((line_feed = XP_STRNCHR(obj->in_buf, LF, obj->in_buf_size)) == NULL)
|
||||
{
|
||||
return 1; /* need more data */
|
||||
}
|
||||
|
||||
*line_feed = '\0';
|
||||
|
||||
/* strip the CR */
|
||||
if(line_feed != obj->in_buf && *(line_feed-1) == CR)
|
||||
*(line_feed-1) = '\0';
|
||||
|
||||
if(*obj->in_buf == '\0')
|
||||
{
|
||||
/* end of parse stream */
|
||||
return MK_MULTIPART_MESSAGE_COMPLETED;
|
||||
}
|
||||
|
||||
/* names are separated from values with a colon
|
||||
*/
|
||||
value = XP_STRCHR(obj->in_buf, ':');
|
||||
if(value)
|
||||
value++;
|
||||
|
||||
/* otherwise parse the line as a mime header */
|
||||
NET_ParseMimeHeader(obj->format_out,
|
||||
obj->context,
|
||||
obj->URL_s,
|
||||
obj->in_buf,
|
||||
value,
|
||||
FALSE);
|
||||
|
||||
/* strip the line from the buffer */
|
||||
obj->in_buf_size -= (line_feed+1) - obj->in_buf;
|
||||
if(obj->in_buf_size)
|
||||
XP_MEMMOVE(obj->in_buf,
|
||||
line_feed+1,
|
||||
obj->in_buf_size);
|
||||
}
|
||||
}
|
||||
|
||||
XP_ASSERT(obj->in_buf_size == 0);
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* is the stream ready for writeing?
|
||||
*/
|
||||
PRIVATE unsigned int net_ChunkedWriteReady (NET_StreamClass * stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
return (*obj->next_stream->is_write_ready)(obj->next_stream);
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_ChunkedComplete (NET_StreamClass *stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
(*obj->next_stream->complete)(obj->next_stream);
|
||||
|
||||
FREE(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE void net_ChunkedAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
(*obj->next_stream->abort)(obj->next_stream, status);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
MODULE_PRIVATE NET_StreamClass *
|
||||
NET_ChunkedDecoderStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
DataObject* obj;
|
||||
NET_StreamClass* stream;
|
||||
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
stream = XP_NEW(NET_StreamClass);
|
||||
if(stream == NULL)
|
||||
return(NULL);
|
||||
|
||||
obj = XP_NEW_ZAP(DataObject);
|
||||
if (obj == NULL)
|
||||
return(NULL);
|
||||
|
||||
stream->name = "Chunked decoder";
|
||||
stream->complete = (MKStreamCompleteFunc) net_ChunkedComplete;
|
||||
stream->abort = (MKStreamAbortFunc) net_ChunkedAbort;
|
||||
stream->put_block = (MKStreamWriteFunc) net_ChunkedWrite;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc) net_ChunkedWriteReady;
|
||||
stream->data_object = obj; /* document info object */
|
||||
stream->window_id = window_id;
|
||||
|
||||
/* clear the "chunked" encoding */
|
||||
if(URL_s->transfer_encoding)
|
||||
FREE_AND_CLEAR(URL_s->transfer_encoding);
|
||||
else
|
||||
FREE_AND_CLEAR(URL_s->content_encoding);
|
||||
obj->next_stream = NET_StreamBuilder(format_out, URL_s, window_id);
|
||||
|
||||
if(!obj->next_stream)
|
||||
{
|
||||
XP_FREE(obj);
|
||||
XP_FREE(stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj->context = window_id;
|
||||
obj->format_out = format_out;
|
||||
obj->URL_s = URL_s;
|
||||
|
||||
TRACEMSG(("Returning stream from NET_ChunkedConverter\n"));
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
28
mozilla/lib/libnet/cvchunk.h
Normal file
28
mozilla/lib/libnet/cvchunk.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* -*- 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 CVCHUNK_H
|
||||
#define CVCHUNK_H
|
||||
|
||||
MODULE_PRIVATE NET_StreamClass *
|
||||
NET_ChunkedDecoderStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
#endif /* CVCHUNK_H */
|
||||
592
mozilla/lib/libnet/cvcolor.c
Normal file
592
mozilla/lib/libnet/cvcolor.c
Normal file
@@ -0,0 +1,592 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/* Please leave outside of ifdef for windows precompiled headers */
|
||||
#include "mkutils.h"
|
||||
|
||||
#ifdef MOZILLA_CLIENT
|
||||
|
||||
/* take an HTML stream. Escape all the HTML and
|
||||
* use <FONT color=> to color the different syntactical parts
|
||||
* of the HTML stream
|
||||
*/
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "pa_parse.h"
|
||||
#include "xp.h"
|
||||
#include "xpgetstr.h"
|
||||
#include "intl_csi.h"
|
||||
#define VIEW_SOURCE_TARGET_WINDOW_NAME "%ViewSourceWindow"
|
||||
|
||||
typedef enum StatesEnum {
|
||||
IN_CONTENT,
|
||||
IN_SCRIPT,
|
||||
ABOUT_TO_BEGIN_TAG,
|
||||
IN_BEGIN_TAG,
|
||||
IN_TAG,
|
||||
BEGIN_ATTRIBUTE_VALUE,
|
||||
IN_QUOTED_ATTRIBUTE_VALUE,
|
||||
IN_BROKEN_QUOTED_ATTRIBUTE_VALUE,
|
||||
IN_UNQUOTED_ATTRIBUTE_VALUE,
|
||||
IN_COMMENT,
|
||||
IN_AMPERSAND_THINGY
|
||||
} StatesEnum;
|
||||
|
||||
#define MAXTAGLEN 15
|
||||
|
||||
typedef struct _DataObject {
|
||||
NET_StreamClass * next_stream;
|
||||
StatesEnum state;
|
||||
char tag[MAXTAGLEN+1];
|
||||
uint tag_index;
|
||||
int tag_type;
|
||||
XP_Bool in_broken_html;
|
||||
} DataObject;
|
||||
|
||||
#define BEGIN_TAG_MARKUP "<B>"
|
||||
#define END_TAG_MARKUP "</B>"
|
||||
#define BEGIN_TAG_NAME_MARKUP "<FONT SIZE=+0 COLOR=\"#551A8B\">"
|
||||
#define END_TAG_NAME_MARKUP "</FONT>"
|
||||
#define BEGIN_ATTRIBUTE_VALUE_MARKUP "</B><FONT SIZE=+0 COLOR=\"003E98\">"
|
||||
#define END_ATTRIBUTE_VALUE_MARKUP "</FONT><B>"
|
||||
#define BEGIN_BROKEN_ATTRIBUTE_MARKUP "<FONT COLOR=#0000FF><BLINK>"
|
||||
#define END_BROKEN_ATTRIBUTE_MARKUP "</BLINK></FONT>"
|
||||
#define BEGIN_COMMENT_MARKUP "<I>"
|
||||
#define END_COMMENT_MARKUP "</I>"
|
||||
#define BEGIN_AMPERSAND_THINGY_MARKUP "<FONT SIZE=+0 COLOR=\"#2F4F2F\">"
|
||||
#define END_AMPERSAND_THINGY_MARKUP "</FONT>"
|
||||
|
||||
extern int MK_CVCOLOR_SOURCE_OF;
|
||||
|
||||
PRIVATE char *net_BeginColorHTMLTag (DataObject *obj)
|
||||
{
|
||||
char *new_markup = 0;
|
||||
|
||||
if (obj->tag_type == P_SCRIPT)
|
||||
{
|
||||
StrAllocCopy(new_markup, "</XMP><PRE>");
|
||||
obj->tag_type = P_UNKNOWN;
|
||||
}
|
||||
StrAllocCat(new_markup, BEGIN_TAG_MARKUP);
|
||||
StrAllocCat(new_markup, "<");
|
||||
StrAllocCat(new_markup, BEGIN_TAG_NAME_MARKUP);
|
||||
obj->state = ABOUT_TO_BEGIN_TAG;
|
||||
return new_markup;
|
||||
}
|
||||
|
||||
PRIVATE char *net_EndColorHTMLTag (DataObject *obj)
|
||||
{
|
||||
char *new_markup = 0;
|
||||
|
||||
if(obj->in_broken_html)
|
||||
{
|
||||
StrAllocCopy(new_markup, END_BROKEN_ATTRIBUTE_MARKUP);
|
||||
obj->in_broken_html = FALSE;
|
||||
}
|
||||
StrAllocCat(new_markup, ">");
|
||||
StrAllocCat(new_markup, END_TAG_MARKUP);
|
||||
if (obj->tag_type == P_SCRIPT)
|
||||
{
|
||||
StrAllocCat(new_markup, "</PRE><XMP>");
|
||||
obj->state = IN_SCRIPT;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->state = IN_CONTENT;
|
||||
}
|
||||
return new_markup;
|
||||
}
|
||||
|
||||
PRIVATE int net_ColorHTMLWrite (NET_StreamClass *stream, CONST char *s, int32 l)
|
||||
{
|
||||
int32 i;
|
||||
int32 last_output_point;
|
||||
char *new_markup=0;
|
||||
char *tmp_markup=0;
|
||||
char tiny_buf[4];
|
||||
CONST char *cp;
|
||||
int status;
|
||||
DataObject *obj=stream->data_object;
|
||||
|
||||
last_output_point = 0;
|
||||
|
||||
for(i = 0, cp = s; i < l; i++, cp++)
|
||||
{
|
||||
switch(obj->state)
|
||||
{
|
||||
case IN_CONTENT:
|
||||
/* do nothing until you find a '<' "<!--" or '&' */
|
||||
if(*cp == '<')
|
||||
{
|
||||
/* XXX we can miss a comment spanning a block boundary */
|
||||
if(i+4 <= l && !XP_STRNCMP(cp, "<!--", 4))
|
||||
{
|
||||
StrAllocCopy(new_markup, BEGIN_COMMENT_MARKUP);
|
||||
StrAllocCat(new_markup, "<");
|
||||
obj->state = IN_COMMENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
new_markup = net_BeginColorHTMLTag(obj);
|
||||
}
|
||||
}
|
||||
else if(*cp == '&')
|
||||
{
|
||||
StrAllocCopy(new_markup, BEGIN_AMPERSAND_THINGY_MARKUP);
|
||||
StrAllocCat(new_markup, "&");
|
||||
obj->state = IN_AMPERSAND_THINGY;
|
||||
}
|
||||
break;
|
||||
case IN_SCRIPT:
|
||||
/* do nothing until you find '</SCRIPT>' */
|
||||
if(*cp == '<')
|
||||
{
|
||||
/* XXX we can miss a </SCRIPT> spanning a block boundary */
|
||||
if(i+8 <= l && !XP_STRNCASECMP(cp, "</SCRIPT", 8))
|
||||
{
|
||||
new_markup = net_BeginColorHTMLTag(obj);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ABOUT_TO_BEGIN_TAG:
|
||||
/* we have seen the first '<'
|
||||
* once we see a non-whitespace character
|
||||
* we will be in the tag identifier
|
||||
*/
|
||||
if(*cp == '>')
|
||||
{
|
||||
StrAllocCopy(new_markup, END_TAG_NAME_MARKUP);
|
||||
tmp_markup = net_EndColorHTMLTag(obj);
|
||||
StrAllocCat(new_markup, tmp_markup);
|
||||
FREE_AND_CLEAR(tmp_markup);
|
||||
}
|
||||
else if(!XP_IS_SPACE(*cp))
|
||||
{
|
||||
obj->state = IN_BEGIN_TAG;
|
||||
obj->tag_index = 0;
|
||||
obj->tag[obj->tag_index++] = *cp;
|
||||
if(*cp == '<')
|
||||
StrAllocCopy(new_markup, "<");
|
||||
|
||||
}
|
||||
break;
|
||||
case IN_BEGIN_TAG:
|
||||
/* go to the IN_TAG state when we see
|
||||
* the first whitespace
|
||||
*/
|
||||
if(XP_IS_SPACE(*cp))
|
||||
{
|
||||
StrAllocCopy(new_markup, END_TAG_NAME_MARKUP);
|
||||
XP_SPRINTF(tiny_buf, "%c", *cp);
|
||||
StrAllocCat(new_markup, tiny_buf);
|
||||
obj->state = IN_TAG;
|
||||
obj->tag[obj->tag_index] = '\0';
|
||||
obj->tag_type = pa_tokenize_tag(obj->tag);
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
StrAllocCopy(new_markup, END_TAG_NAME_MARKUP);
|
||||
tmp_markup = net_EndColorHTMLTag(obj);
|
||||
StrAllocCat(new_markup, tmp_markup);
|
||||
FREE_AND_CLEAR(tmp_markup);
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
if(!obj->in_broken_html)
|
||||
{
|
||||
obj->in_broken_html = TRUE;
|
||||
StrAllocCopy(new_markup, BEGIN_BROKEN_ATTRIBUTE_MARKUP);
|
||||
StrAllocCat(new_markup, "<");
|
||||
}
|
||||
else
|
||||
{
|
||||
StrAllocCopy(new_markup, "<");
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (obj->tag_index < MAXTAGLEN)
|
||||
obj->tag[obj->tag_index++] = *cp;
|
||||
}
|
||||
break;
|
||||
case IN_TAG:
|
||||
/* do nothing until you find a opening '=' or end '>' */
|
||||
if(*cp == '=')
|
||||
{
|
||||
StrAllocCopy(new_markup, "=");
|
||||
StrAllocCat(new_markup, BEGIN_ATTRIBUTE_VALUE_MARKUP);
|
||||
obj->state = BEGIN_ATTRIBUTE_VALUE;
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
new_markup = net_EndColorHTMLTag(obj);
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "<");
|
||||
}
|
||||
break;
|
||||
case BEGIN_ATTRIBUTE_VALUE:
|
||||
/* when we reach the first non-whitespace
|
||||
* we will enter the UNQUOTED or the QUOTED
|
||||
* ATTRIBUTE state
|
||||
*/
|
||||
if(!XP_IS_SPACE(*cp))
|
||||
{
|
||||
if(*cp == '"')
|
||||
{
|
||||
obj->state = IN_QUOTED_ATTRIBUTE_VALUE;
|
||||
/* no need to jump to the quoted attr handler
|
||||
* since this char can't be a dangerous char
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->state = IN_UNQUOTED_ATTRIBUTE_VALUE;
|
||||
/* need to jump to the unquoted attr handler
|
||||
* since this char can be a dangerous character
|
||||
*/
|
||||
goto unquoted_attribute_jump_point;
|
||||
}
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP);
|
||||
tmp_markup = net_EndColorHTMLTag(obj);
|
||||
StrAllocCat(new_markup, tmp_markup);
|
||||
FREE_AND_CLEAR(tmp_markup);
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "<");
|
||||
}
|
||||
break;
|
||||
case IN_UNQUOTED_ATTRIBUTE_VALUE:
|
||||
unquoted_attribute_jump_point:
|
||||
/* do nothing until you find a whitespace */
|
||||
if(XP_IS_SPACE(*cp))
|
||||
{
|
||||
StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP);
|
||||
XP_SPRINTF(tiny_buf, "%c", *cp);
|
||||
StrAllocCat(new_markup, tiny_buf);
|
||||
obj->state = IN_TAG;
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
StrAllocCopy(new_markup, END_ATTRIBUTE_VALUE_MARKUP);
|
||||
tmp_markup = net_EndColorHTMLTag(obj);
|
||||
StrAllocCat(new_markup, tmp_markup);
|
||||
FREE_AND_CLEAR(tmp_markup);
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "<");
|
||||
}
|
||||
else if(*cp == '&')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "&");
|
||||
}
|
||||
break;
|
||||
case IN_QUOTED_ATTRIBUTE_VALUE:
|
||||
/* do nothing until you find a closing '"' */
|
||||
if(*cp == '\"')
|
||||
{
|
||||
if(obj->in_broken_html)
|
||||
{
|
||||
StrAllocCopy(new_markup, END_BROKEN_ATTRIBUTE_MARKUP);
|
||||
obj->in_broken_html = FALSE;
|
||||
}
|
||||
StrAllocCat(new_markup, "\"");
|
||||
StrAllocCat(new_markup, END_ATTRIBUTE_VALUE_MARKUP);
|
||||
obj->state = IN_TAG;
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "<");
|
||||
}
|
||||
else if(*cp == '&')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "&");
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
/* probably a broken attribute value */
|
||||
if(!obj->in_broken_html)
|
||||
{
|
||||
obj->in_broken_html = TRUE;
|
||||
StrAllocCopy(new_markup, BEGIN_BROKEN_ATTRIBUTE_MARKUP);
|
||||
StrAllocCat(new_markup, ">");
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IN_COMMENT:
|
||||
/* do nothing until you find a closing '-->' */
|
||||
if(!XP_STRNCMP(cp, "-->", 3))
|
||||
{
|
||||
StrAllocCopy(new_markup, ">");
|
||||
cp += 2;
|
||||
i += 2;
|
||||
StrAllocCat(new_markup, END_COMMENT_MARKUP);
|
||||
obj->state = IN_CONTENT;
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "<");
|
||||
}
|
||||
break;
|
||||
case IN_AMPERSAND_THINGY:
|
||||
/* do nothing until you find a ';' or space */
|
||||
if(*cp == ';' || XP_IS_SPACE(*cp))
|
||||
{
|
||||
XP_SPRINTF(tiny_buf, "%c", *cp);
|
||||
StrAllocCopy(new_markup, tiny_buf);
|
||||
StrAllocCat(new_markup, END_AMPERSAND_THINGY_MARKUP);
|
||||
obj->state = IN_CONTENT;
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
StrAllocCopy(new_markup, "<");
|
||||
}
|
||||
break;
|
||||
default:
|
||||
XP_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
if(new_markup)
|
||||
{
|
||||
/* push all the way up to but not including *cp */
|
||||
status = (*obj->next_stream->put_block)
|
||||
(obj->next_stream,
|
||||
&s[last_output_point],
|
||||
i-last_output_point);
|
||||
last_output_point = i+1;
|
||||
|
||||
if(status < 0)
|
||||
{
|
||||
FREE(new_markup);
|
||||
return(status);
|
||||
}
|
||||
|
||||
/* add new markup */
|
||||
status = (*obj->next_stream->put_block)
|
||||
(obj->next_stream,
|
||||
new_markup, XP_STRLEN(new_markup));
|
||||
if(status < 0)
|
||||
{
|
||||
FREE(new_markup);
|
||||
return(status);
|
||||
}
|
||||
|
||||
FREE_AND_CLEAR(new_markup);
|
||||
}
|
||||
}
|
||||
|
||||
if(last_output_point < l)
|
||||
return((*obj->next_stream->put_block)(obj->next_stream,
|
||||
&s[last_output_point],
|
||||
(l-last_output_point)));
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* is the stream ready for writeing?
|
||||
*/
|
||||
PRIVATE unsigned int net_ColorHTMLWriteReady (NET_StreamClass * stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
return((*obj->next_stream->is_write_ready)(obj->next_stream));
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_ColorHTMLComplete (NET_StreamClass *stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
(*obj->next_stream->complete)(obj->next_stream);
|
||||
}
|
||||
|
||||
PRIVATE void net_ColorHTMLAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
(*obj->next_stream->abort)(obj->next_stream, status);
|
||||
}
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
net_ColorHTMLStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
DataObject* obj;
|
||||
char *new_markup=0;
|
||||
char *new_url=0;
|
||||
char *old_url;
|
||||
int status, type;
|
||||
NET_StreamClass *next_stream, *new_stream;
|
||||
Bool is_html_stream = FALSE;
|
||||
INTL_CharSetInfo csi = LO_GetDocumentCharacterSetInfo(window_id);
|
||||
INTL_CharSetInfo next_csi;
|
||||
|
||||
TRACEMSG(("Setting up ColorHTML stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
/* treat the stream as html if the closure data says
|
||||
* it's HTML and it is also not a mail or news message
|
||||
*/
|
||||
type = NET_URL_Type(URL_s->address);
|
||||
if(data_obj
|
||||
&& !XP_STRCMP((char *)data_obj, TEXT_HTML)
|
||||
&& type != MAILBOX_TYPE_URL
|
||||
&& type != IMAP_TYPE_URL
|
||||
&& type != NEWS_TYPE_URL)
|
||||
is_html_stream = TRUE;
|
||||
|
||||
/* use a new named window */
|
||||
StrAllocCopy(URL_s->window_target, VIEW_SOURCE_TARGET_WINDOW_NAME);
|
||||
|
||||
/* add the url address to the name so that there can be
|
||||
* one view source window per url
|
||||
*/
|
||||
StrAllocCat(URL_s->window_target, URL_s->address);
|
||||
|
||||
/* zero position_tag to prevent hash lossage */
|
||||
URL_s->position_tag = 0;
|
||||
|
||||
/* alloc a new chrome struct and stick it in the URL
|
||||
* so that we can turn off the relavent stuff
|
||||
*/
|
||||
URL_s->window_chrome = XP_NEW(Chrome);
|
||||
if(URL_s->window_chrome)
|
||||
{
|
||||
/* zero everything to turn off all chrome */
|
||||
XP_MEMSET(URL_s->window_chrome, 0, sizeof(Chrome));
|
||||
URL_s->window_chrome->type = MWContextDialog;
|
||||
URL_s->window_chrome->show_scrollbar = TRUE;
|
||||
URL_s->window_chrome->allow_resize = TRUE;
|
||||
URL_s->window_chrome->allow_close = TRUE;
|
||||
}
|
||||
|
||||
/* call the HTML parser */
|
||||
StrAllocCopy(URL_s->content_type, INTERNAL_PARSER);
|
||||
|
||||
/* use the view-source: url instead */
|
||||
StrAllocCopy(new_url, VIEW_SOURCE_URL_PREFIX);
|
||||
StrAllocCat(new_url, URL_s->address);
|
||||
old_url = URL_s->address;
|
||||
URL_s->address = new_url;
|
||||
|
||||
format_out = FO_PRESENT;
|
||||
|
||||
/* open next stream */
|
||||
next_stream = NET_StreamBuilder(format_out, URL_s, window_id);
|
||||
|
||||
if(!next_stream)
|
||||
{
|
||||
FREE(old_url);
|
||||
return(NULL);
|
||||
}
|
||||
next_csi = LO_GetDocumentCharacterSetInfo(next_stream->window_id);
|
||||
|
||||
/* jliu: for international's reason,
|
||||
set the value ASAP, so the following stream can share it */
|
||||
INTL_SetCSIWinCSID(next_csi, INTL_GetCSIWinCSID(csi));
|
||||
INTL_SetCSIDocCSID(next_csi, INTL_GetCSIDocCSID(csi));
|
||||
|
||||
|
||||
#define DEF_PICS_LABEL "<META http-equiv=PICS-Label content='(PICS-1.0 \"http://home.netscape.com/default_rating\" l gen true r (s 0))'>"
|
||||
|
||||
/* add a PICS label */
|
||||
StrAllocCopy(new_markup, DEF_PICS_LABEL);
|
||||
StrAllocCat(new_markup, "<TITLE>");
|
||||
StrAllocCat(new_markup, XP_GetString(MK_CVCOLOR_SOURCE_OF));
|
||||
StrAllocCat(new_markup, old_url);
|
||||
StrAllocCat(new_markup, "</TITLE><BODY BGCOLOR=#C0C0C0>");
|
||||
|
||||
|
||||
if(!is_html_stream)
|
||||
StrAllocCat(new_markup, "<PLAINTEXT>");
|
||||
else
|
||||
StrAllocCat(new_markup, "<PRE>");
|
||||
|
||||
FREE(old_url);
|
||||
|
||||
status = (*next_stream->put_block)(next_stream,
|
||||
new_markup,
|
||||
XP_STRLEN(new_markup));
|
||||
FREE(new_markup);
|
||||
|
||||
if(status < 0)
|
||||
{
|
||||
(*next_stream->abort)(next_stream, status);
|
||||
FREE(next_stream);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
if(!is_html_stream)
|
||||
return(next_stream);
|
||||
|
||||
/* else; continue on and build up this stream module
|
||||
* and attach the next stream to it
|
||||
*/
|
||||
|
||||
new_stream = XP_NEW(NET_StreamClass);
|
||||
if(new_stream == NULL)
|
||||
{
|
||||
(*next_stream->abort)(next_stream, status);
|
||||
FREE(next_stream);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
obj = XP_NEW(DataObject);
|
||||
|
||||
if (obj == NULL)
|
||||
{
|
||||
(*next_stream->abort)(next_stream, status);
|
||||
FREE(next_stream);
|
||||
FREE(new_stream);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
XP_MEMSET(obj, 0, sizeof(DataObject));
|
||||
|
||||
obj->state = IN_CONTENT;
|
||||
|
||||
obj->next_stream = next_stream;
|
||||
obj->tag_type = P_UNKNOWN;
|
||||
|
||||
new_stream->name = "HTML Colorer";
|
||||
new_stream->complete = (MKStreamCompleteFunc) net_ColorHTMLComplete;
|
||||
new_stream->abort = (MKStreamAbortFunc) net_ColorHTMLAbort;
|
||||
new_stream->put_block = (MKStreamWriteFunc) net_ColorHTMLWrite;
|
||||
new_stream->is_write_ready = (MKStreamWriteReadyFunc)
|
||||
net_ColorHTMLWriteReady;
|
||||
new_stream->data_object = (void *) obj; /* document info object */
|
||||
new_stream->window_id = window_id;
|
||||
|
||||
TRACEMSG(("Returning stream from HTMLColorConverter\n"));
|
||||
|
||||
return new_stream;
|
||||
}
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
29
mozilla/lib/libnet/cvcolor.h
Normal file
29
mozilla/lib/libnet/cvcolor.h
Normal file
@@ -0,0 +1,29 @@
|
||||
/* -*- 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 CVCOLOR_H
|
||||
#define CVCOLOR_H
|
||||
|
||||
extern NET_StreamClass *
|
||||
net_ColorHTMLStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
#endif /* CVCOLOR_H */
|
||||
117
mozilla/lib/libnet/cvdisk.c
Normal file
117
mozilla/lib/libnet/cvdisk.c
Normal file
@@ -0,0 +1,117 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/* Please leave outside of ifdef for windows precompiled headers */
|
||||
#include "mkutils.h"
|
||||
|
||||
#ifdef MOZILLA_CLIENT
|
||||
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "xp.h"
|
||||
|
||||
typedef struct _DataObject {
|
||||
FILE * fp;
|
||||
char * filename;
|
||||
} DataObject;
|
||||
|
||||
|
||||
PRIVATE int net_SaveToDiskWrite (NET_StreamClass *stream, CONST char* s, int32 l)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
fwrite(s, 1, l, obj->fp);
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* is the stream ready for writeing?
|
||||
*/
|
||||
PRIVATE unsigned int net_SaveToDiskWriteReady (NET_StreamClass * stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
return(MAX_WRITE_READY); /* always ready for writing */
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_SaveToDiskComplete (NET_StreamClass *stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
fclose(obj->fp);
|
||||
|
||||
FREEIF(obj->filename);
|
||||
|
||||
FREE(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE void net_SaveToDiskAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
fclose(obj->fp);
|
||||
|
||||
if(obj->filename)
|
||||
{
|
||||
remove(obj->filename);
|
||||
FREE(obj->filename);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
fe_MakeSaveAsStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
DataObject* obj;
|
||||
NET_StreamClass* stream;
|
||||
static int count=0;
|
||||
char filename[256];
|
||||
FILE *fp = stdout;
|
||||
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
PR_snprintf(filename, sizeof(filename), "foo%d.unknown",count++);
|
||||
fp = fopen(filename,"w");
|
||||
|
||||
stream = XP_NEW(NET_StreamClass);
|
||||
if(stream == NULL)
|
||||
return(NULL);
|
||||
|
||||
obj = XP_NEW(DataObject);
|
||||
if (obj == NULL)
|
||||
return(NULL);
|
||||
|
||||
stream->name = "FileWriter";
|
||||
stream->complete = (MKStreamCompleteFunc) net_SaveToDiskComplete;
|
||||
stream->abort = (MKStreamAbortFunc) net_SaveToDiskAbort;
|
||||
stream->put_block = (MKStreamWriteFunc) net_SaveToDiskWrite;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc) net_SaveToDiskWriteReady;
|
||||
stream->data_object = obj; /* document info object */
|
||||
stream->window_id = window_id;
|
||||
|
||||
obj->fp = fp;
|
||||
obj->filename = 0;
|
||||
StrAllocCopy(obj->filename, filename);
|
||||
|
||||
TRACEMSG(("Returning stream from NET_SaveToDiskConverter\n"));
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
27
mozilla/lib/libnet/cvdisk.h
Normal file
27
mozilla/lib/libnet/cvdisk.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/* -*- 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 CVDISK_H
|
||||
#define CVDISK_H
|
||||
|
||||
extern NET_StreamClass* fe_MakeSaveAsStream (FO_Present_Types format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
#endif /* CVDISK_H */
|
||||
412
mozilla/lib/libnet/cvextcon.c
Normal file
412
mozilla/lib/libnet/cvextcon.c
Normal file
@@ -0,0 +1,412 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/* cvextcon.c --- using external Unix programs as content-encoding filters.
|
||||
*/
|
||||
|
||||
#include "mkutils.h"
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "xp.h"
|
||||
#include "cvextcon.h"
|
||||
#include "mkformat.h"
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/wait.h>
|
||||
|
||||
#ifdef __sgi
|
||||
#include <bstring.h> /* FD_ZERO uses bzero() which needs this */
|
||||
/* file for its prototype. */
|
||||
#endif
|
||||
|
||||
typedef struct _CVG_DataObject {
|
||||
NET_StreamClass *next_stream; /* Where the output goes */
|
||||
pid_t pid; /* process in which the filter is running */
|
||||
int infd; /* for reading from the process */
|
||||
int outfd; /* for writing to the process */
|
||||
struct sigaction oldact; /* Old SIGCHLD handler */
|
||||
} CVG_DataObject;
|
||||
|
||||
|
||||
PRIVATE int net_ExtConverterRead (CVG_DataObject *data, Bool block_p)
|
||||
{
|
||||
char input_buffer [1024];
|
||||
int bytes_read;
|
||||
|
||||
AGAIN:
|
||||
while ((bytes_read = read (data->infd, input_buffer, sizeof (input_buffer)))
|
||||
> 0)
|
||||
{
|
||||
if (data->next_stream)
|
||||
{
|
||||
int status = ((*data->next_stream->put_block)
|
||||
(data->next_stream,
|
||||
input_buffer, bytes_read));
|
||||
/* abort */
|
||||
if (status < 0)
|
||||
return status;
|
||||
}
|
||||
}
|
||||
|
||||
/* It's necessary that we block here waiting for the process to produce
|
||||
the rest of its output before we allow the `complete' method to return.
|
||||
We've already set the socket to be nonblocking, and there doesn't appear
|
||||
to be any way to set it to do blocking reads again, so instead, we'll
|
||||
use select() to block for it. That will return when there is some input
|
||||
available, and we'll read it, and (maybe) block again, repeating until
|
||||
we get an EOF.
|
||||
|
||||
To implement this in a non-blocking way would require the input and
|
||||
output sides of this to be disconnected - the output side would be as in
|
||||
this file, but the input side would need to be a new stream type in
|
||||
NET_ProcessNet(), at the level of http, ftp, and file streams.
|
||||
*/
|
||||
if (bytes_read == -1 && block_p &&
|
||||
(errno == EAGAIN || errno == EWOULDBLOCK))
|
||||
{
|
||||
fd_set rset;
|
||||
FD_ZERO (&rset);
|
||||
FD_SET (data->infd, &rset);
|
||||
if (select (data->infd+1, &rset, 0, 0, 0) < 0)
|
||||
perror ("select");
|
||||
goto AGAIN;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
PRIVATE int net_ExtConverterWrite (NET_StreamClass *stream,
|
||||
CONST char* output_buffer,
|
||||
int32 output_length)
|
||||
{
|
||||
CVG_DataObject *data = (CVG_DataObject *) stream->data_object;
|
||||
|
||||
while (output_length > 0)
|
||||
{
|
||||
int bytes_written = 0;
|
||||
|
||||
/* write as much as possible (until done, or the pipe is full.)
|
||||
*/
|
||||
while (output_length > 0 &&
|
||||
(bytes_written = write (data->outfd, output_buffer,
|
||||
output_length))
|
||||
> 0)
|
||||
{
|
||||
output_buffer += bytes_written;
|
||||
output_length -= bytes_written;
|
||||
}
|
||||
|
||||
if (bytes_written == -1 && errno != EAGAIN && errno != EWOULDBLOCK)
|
||||
{
|
||||
perror ("write");
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* Now read as much as possible (until done, or the pipe is drained.)
|
||||
*/
|
||||
{
|
||||
int status = net_ExtConverterRead (data, FALSE);
|
||||
/* abort */
|
||||
if (status < 0)
|
||||
return status;
|
||||
}
|
||||
|
||||
/* Now go around the loop again, if we weren't able to write all of
|
||||
the output buffer at once (because the pipe filled up.) Now that
|
||||
we've read the available data from the pipe, we will presumably
|
||||
be able to write to it again.
|
||||
*/
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
PRIVATE int net_ExtConverterWriteReady (NET_StreamClass *stream)
|
||||
{
|
||||
/* #### I'm not sure what the right thing to do here is. --jwz */
|
||||
#if 1
|
||||
return (MAX_WRITE_READY);
|
||||
#else
|
||||
CVG_DataObject *data = (CVG_DataObject *) stream->data_object;
|
||||
if(data->next_stream)
|
||||
return ((*data->next_stream->is_write_ready)
|
||||
(data->next_stream));
|
||||
else
|
||||
return (MAX_WRITE_READY);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void
|
||||
net_KillConverterProcess (CVG_DataObject *data)
|
||||
{
|
||||
pid_t wait_status;
|
||||
/* It may not actually be necessary to kill the process here if we have
|
||||
exited normally, since in that case it has already closed its stdout;
|
||||
but it can't hurt.
|
||||
|
||||
After it dies, we have to wait() for it, or it becomes a zombie.
|
||||
I'm not entirely sure that the perror() is correct - it could be that
|
||||
0 is a legitimate value from waitpid() if the process had already
|
||||
exited before we kill()ed it, but I'm not sure.
|
||||
*/
|
||||
|
||||
kill (data->pid, SIGINT);
|
||||
wait_status = waitpid (data->pid, 0, 0);
|
||||
#ifdef DEBUG_dp
|
||||
fprintf(stderr, "Restoring sigchild handler for pid %d.\n", data->pid);
|
||||
#endif
|
||||
/* Reset SIGCHLD signal hander before returning */
|
||||
sigaction(SIGCHLD, &data->oldact, NULL);
|
||||
|
||||
if (wait_status != data->pid)
|
||||
perror ("waitpid");
|
||||
}
|
||||
|
||||
PRIVATE void net_ExtConverterComplete (NET_StreamClass *stream)
|
||||
{
|
||||
CVG_DataObject *data = (CVG_DataObject *) stream->data_object;
|
||||
|
||||
/* Send an EOF to the stdin of the subprocess; then wait for the rest
|
||||
of its output to show up on its stdout; then close stdout, and kill
|
||||
the process. */
|
||||
close (data->outfd);
|
||||
net_ExtConverterRead (data, TRUE);
|
||||
close (data->infd);
|
||||
net_KillConverterProcess (data);
|
||||
|
||||
/* complete the next stream */
|
||||
if (data->next_stream)
|
||||
{
|
||||
(*data->next_stream->complete) (data->next_stream);
|
||||
free (data->next_stream);
|
||||
}
|
||||
free (data);
|
||||
}
|
||||
|
||||
PRIVATE void net_ExtConverterAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
CVG_DataObject *data = (CVG_DataObject *) stream->data_object;
|
||||
|
||||
/* Close the streams and kill the process, discarding any output still
|
||||
in the pipe. */
|
||||
close (data->outfd);
|
||||
close (data->infd);
|
||||
net_KillConverterProcess (data);
|
||||
|
||||
/* abort the next stream */
|
||||
if (data->next_stream)
|
||||
{
|
||||
(*data->next_stream->abort) (data->next_stream, status);
|
||||
free (data->next_stream);
|
||||
}
|
||||
free (data);
|
||||
}
|
||||
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
NET_ExtConverterConverter (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
CVG_DataObject* obj;
|
||||
CV_ExtConverterStruct * ext_con_obj = (CV_ExtConverterStruct *) data_obj;
|
||||
NET_StreamClass* stream;
|
||||
struct sigaction newact;
|
||||
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
stream = XP_NEW(NET_StreamClass);
|
||||
if(stream == NULL)
|
||||
return(NULL);
|
||||
|
||||
XP_MEMSET(stream, 0, sizeof(NET_StreamClass));
|
||||
|
||||
obj = XP_NEW(CVG_DataObject);
|
||||
if (obj == NULL)
|
||||
return(NULL);
|
||||
memset(obj, 0, sizeof(CVG_DataObject));
|
||||
|
||||
stream->name = "Filter Stream";
|
||||
stream->complete = (MKStreamCompleteFunc) net_ExtConverterComplete;
|
||||
stream->abort = (MKStreamAbortFunc) net_ExtConverterAbort;
|
||||
stream->put_block = (MKStreamWriteFunc) net_ExtConverterWrite;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc) net_ExtConverterWriteReady;
|
||||
stream->data_object = obj; /* document info object */
|
||||
stream->window_id = window_id;
|
||||
|
||||
/* Open the next stream.
|
||||
First, swap in the content-encoding or content-type of the document
|
||||
as we are about to convert it, to look up the proper next converter
|
||||
(and to avoid looping.) But once we have set up the stream, put the
|
||||
original encoding back, so that the URL_Struct is not permanently
|
||||
altered - foo.html.gz must still have content-encoding x-gzip even
|
||||
though it has been decoded for display.
|
||||
*/
|
||||
{
|
||||
char *old, *new;
|
||||
if (ext_con_obj->is_encoding_converter)
|
||||
{
|
||||
old = URL_s->content_encoding;
|
||||
new = XP_STRDUP (ext_con_obj->new_format);
|
||||
if (!new) return (NULL);
|
||||
URL_s->content_encoding = new;
|
||||
}
|
||||
else
|
||||
{
|
||||
old = URL_s->content_type;
|
||||
new = XP_STRDUP (ext_con_obj->new_format);
|
||||
if (!new) return (NULL);
|
||||
URL_s->content_type = new;
|
||||
}
|
||||
|
||||
obj->next_stream = NET_StreamBuilder (format_out, URL_s, window_id);
|
||||
|
||||
if (ext_con_obj->is_encoding_converter)
|
||||
{
|
||||
XP_FREE (URL_s->content_encoding);
|
||||
URL_s->content_encoding = old;
|
||||
}
|
||||
else
|
||||
{
|
||||
XP_FREE (URL_s->content_type);
|
||||
URL_s->content_type = old;
|
||||
}
|
||||
}
|
||||
|
||||
if (!obj->next_stream)
|
||||
return (NULL);
|
||||
|
||||
/* Open two pipes, one for writing to a subprocess, and one for reading
|
||||
from it (for a total of four file descriptors, I/O for us, and O/I
|
||||
for the kid.)
|
||||
*/
|
||||
{
|
||||
int infds [2];
|
||||
int outfds[2];
|
||||
pid_t forked;
|
||||
|
||||
if (pipe (infds))
|
||||
{
|
||||
perror ("creating input pipe");
|
||||
free (stream);
|
||||
free (obj);
|
||||
return 0;
|
||||
}
|
||||
if (pipe (outfds))
|
||||
{
|
||||
perror ("creating output pipe");
|
||||
free (stream);
|
||||
free (obj);
|
||||
return 0;
|
||||
}
|
||||
obj->infd = infds [0];
|
||||
obj->outfd = outfds [1];
|
||||
|
||||
/* Set our side of the pipes to be nonblocking. (It's important not
|
||||
to set the other side of the pipes to be nonblocking - that
|
||||
decision must be left up to the process on the other end. */
|
||||
|
||||
#if defined(O_NONBLOCK)
|
||||
# define NONBLOCK_FLAG O_NONBLOCK
|
||||
#elif defined(O_NDELAY)
|
||||
# define NONBLOCK_FLAG O_NDELAY
|
||||
#else
|
||||
ERROR!! neither O_NONBLOCK nor O_NDELAY are defined.
|
||||
#endif
|
||||
fcntl (obj->infd, F_SETFL, NONBLOCK_FLAG);
|
||||
fcntl (obj->outfd, F_SETFL, NONBLOCK_FLAG);
|
||||
#undef NONBLOCK_FLAG
|
||||
|
||||
obj->pid = 0;
|
||||
|
||||
#ifdef DEBUG_dp
|
||||
fprintf(stderr, "Ignoring sigchild.\n");
|
||||
#endif
|
||||
/* Setup signals so that SIGCHLD is ignored as we want to do waitpid
|
||||
* when the helperapp ends
|
||||
*/
|
||||
newact.sa_handler = SIG_DFL;
|
||||
newact.sa_flags = 0;
|
||||
sigfillset(&newact.sa_mask);
|
||||
sigaction (SIGCHLD, &newact, &obj->oldact);
|
||||
|
||||
switch (forked = fork ())
|
||||
{
|
||||
case -1:
|
||||
perror ("fork");
|
||||
close (outfds[0]);
|
||||
close (outfds[1]);
|
||||
close (infds [0]);
|
||||
close (infds [1]);
|
||||
free (stream);
|
||||
free (obj);
|
||||
/* Reset SIGCHLD signal hander before returning */
|
||||
sigaction(SIGCHLD, &obj->oldact, NULL);
|
||||
return 0;
|
||||
case 0:
|
||||
{
|
||||
/* This is the new process. exec() the filter here.
|
||||
We do this with sh to get tokenization and pipelines
|
||||
and all that junk.
|
||||
*/
|
||||
char *av[10];
|
||||
int ac = 0;
|
||||
|
||||
av [ac++] = "/bin/sh";
|
||||
av [ac++] = "-c";
|
||||
av [ac++] = ext_con_obj->command;
|
||||
av [ac++] = 0;
|
||||
|
||||
dup2 (outfds[0], 0); /* stdin */
|
||||
dup2 (infds [1], 1); /* stdout */
|
||||
/* dup2 (infds [1], 2); * stderr */
|
||||
|
||||
/* We have copied the two pipes to stdin/stdout.
|
||||
We no longer need the other file descriptors hanging around.
|
||||
(Actually I think we need to close these, or the other side
|
||||
of the pipe doesn't see an eof when we close stdout...)
|
||||
*/
|
||||
close (outfds[0]);
|
||||
close (outfds[1]);
|
||||
close (infds [0]);
|
||||
close (infds [1]);
|
||||
|
||||
execv (av[0], av);
|
||||
/* exec() should never return. */
|
||||
perror ("execv");
|
||||
exit (1); /* This only exits a child fork. */
|
||||
break;
|
||||
}
|
||||
default:
|
||||
/* This is the "old" process (subproc pid is in `forked'.) */
|
||||
obj->pid = forked;
|
||||
|
||||
/* These are the file descriptors we created for the benefit
|
||||
of the child process - we don't need them in the parent. */
|
||||
close (outfds[0]);
|
||||
close (infds [1]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
TRACEMSG(("Returning stream from NET_ExtConverterConverter\n"));
|
||||
|
||||
return stream;
|
||||
}
|
||||
34
mozilla/lib/libnet/cvextcon.h
Normal file
34
mozilla/lib/libnet/cvextcon.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* -*- 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 CVEXTCON_H
|
||||
#define CVEXTCON_H
|
||||
|
||||
typedef struct _CV_ExtConverterStruct {
|
||||
char * command;
|
||||
char * new_format;
|
||||
Bool is_encoding_converter;
|
||||
} CV_ExtConverterStruct;
|
||||
|
||||
extern NET_StreamClass *
|
||||
NET_ExtConverterConverter(FO_Present_Types format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
#endif /* CVEXTCON_H */
|
||||
1052
mozilla/lib/libnet/cvmime.c
Normal file
1052
mozilla/lib/libnet/cvmime.c
Normal file
File diff suppressed because it is too large
Load Diff
25
mozilla/lib/libnet/cvmime.h
Normal file
25
mozilla/lib/libnet/cvmime.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* -*- 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 CVMIME_H
|
||||
#define CVMIME_H
|
||||
|
||||
extern NET_StreamClass *
|
||||
NET_MimeEncodingConverter(int, void *, URL_Struct *, MWContext *);
|
||||
|
||||
#endif /* CVMIME_H */
|
||||
383
mozilla/lib/libnet/cvpics.c
Normal file
383
mozilla/lib/libnet/cvpics.c
Normal file
@@ -0,0 +1,383 @@
|
||||
|
||||
/* this set of functions parses an incoming stream of HTML and tries to find
|
||||
* any PICS label within it. It doesn't do anything accept parse the pics label
|
||||
* and finish
|
||||
*/
|
||||
#include "mkutils.h"
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "pa_parse.h"
|
||||
#include "xp.h"
|
||||
#include "xpgetstr.h"
|
||||
#include "layout.h"
|
||||
#include "pics.h"
|
||||
|
||||
typedef enum StatesEnum {
|
||||
IN_CONTENT,
|
||||
IN_SCRIPT,
|
||||
ABOUT_TO_BEGIN_TAG,
|
||||
IN_BEGIN_TAG,
|
||||
IN_TAG,
|
||||
BEGIN_ATTRIBUTE_VALUE,
|
||||
IN_QUOTED_ATTRIBUTE_VALUE,
|
||||
IN_BROKEN_QUOTED_ATTRIBUTE_VALUE,
|
||||
IN_UNQUOTED_ATTRIBUTE_VALUE,
|
||||
IN_COMMENT,
|
||||
IN_AMPERSAND_THINGY
|
||||
} StatesEnum;
|
||||
|
||||
#define MAXTAGLEN 15
|
||||
|
||||
typedef struct _DataObject {
|
||||
MWContext *context;
|
||||
URL_Struct *URL_s;
|
||||
StatesEnum state;
|
||||
char tag[MAXTAGLEN+1];
|
||||
uint tag_index;
|
||||
int tag_type;
|
||||
XP_Bool in_broken_html;
|
||||
char *tag_data; /* the contents of the current tag */
|
||||
} DataObject;
|
||||
|
||||
extern int MK_CVCOLOR_SOURCE_OF;
|
||||
|
||||
PRIVATE void net_BeginPICSLabelFinderTag (DataObject *obj)
|
||||
{
|
||||
|
||||
if(obj->tag_data)
|
||||
*obj->tag_data = '\0'; /* empty tag_data */
|
||||
|
||||
if (obj->tag_type == P_SCRIPT)
|
||||
{
|
||||
obj->tag_type = P_UNKNOWN;
|
||||
}
|
||||
obj->state = ABOUT_TO_BEGIN_TAG;
|
||||
return ;
|
||||
}
|
||||
|
||||
PRIVATE void net_EndPICSLabelFinderTag (DataObject *obj)
|
||||
{
|
||||
if(obj->in_broken_html)
|
||||
{
|
||||
obj->in_broken_html = FALSE;
|
||||
}
|
||||
|
||||
if (obj->tag_type == P_SCRIPT)
|
||||
{
|
||||
obj->state = IN_SCRIPT;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->state = IN_CONTENT;
|
||||
}
|
||||
|
||||
/* check tag_data for a META tag */
|
||||
if(obj->tag_data && !strncasecomp(obj->tag_data, "META", 4))
|
||||
{
|
||||
PA_Tag tmp_tag;
|
||||
char *name;
|
||||
|
||||
tmp_tag.type = P_META;
|
||||
tmp_tag.data = (void*)obj->tag_data;
|
||||
tmp_tag.data_len = XP_STRLEN((char*)tmp_tag.data);
|
||||
|
||||
name = (char *)lo_FetchParamValue(obj->context, &tmp_tag, PARAM_HTTP_EQUIV);
|
||||
|
||||
#define PICS_HEADER "PICS-Label"
|
||||
if(name && !strcasecomp(name, PICS_HEADER))
|
||||
{
|
||||
char *label = (char *)lo_FetchParamValue(obj->context, &tmp_tag, PARAM_CONTENT);
|
||||
|
||||
if(label)
|
||||
{
|
||||
PICS_RatingsStruct * rs = PICS_ParsePICSLable(label);
|
||||
FREE(label);
|
||||
PICS_CompareToUserSettings(rs, obj->URL_s->address);
|
||||
PICS_FreeRatingsStruct(rs); /* handles NULL */
|
||||
}
|
||||
}
|
||||
|
||||
FREEIF(name);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE int net_PICSLabelFinderWrite (NET_StreamClass *stream, CONST char *s, int32 l)
|
||||
{
|
||||
int32 i;
|
||||
CONST char *cp;
|
||||
DataObject *obj = (DataObject *)stream->data_object;
|
||||
char tiny_buf[8];
|
||||
|
||||
for(i = 0, cp = s; i < l; i++, cp++)
|
||||
{
|
||||
switch(obj->state)
|
||||
{
|
||||
case IN_CONTENT:
|
||||
/* do nothing until you find a '<' "<!--" or '&' */
|
||||
if(*cp == '<')
|
||||
{
|
||||
/* XXX we can miss a comment spanning a block boundary */
|
||||
if(i+4 <= l && !XP_STRNCMP(cp, "<!--", 4))
|
||||
{
|
||||
obj->state = IN_COMMENT;
|
||||
}
|
||||
else
|
||||
{
|
||||
net_BeginPICSLabelFinderTag(obj);
|
||||
}
|
||||
}
|
||||
else if(*cp == '&')
|
||||
{
|
||||
obj->state = IN_AMPERSAND_THINGY;
|
||||
}
|
||||
break;
|
||||
case IN_SCRIPT:
|
||||
/* do nothing until you find '</SCRIPT>' */
|
||||
if(*cp == '<')
|
||||
{
|
||||
/* XXX we can miss a </SCRIPT> spanning a block boundary */
|
||||
if(i+8 <= l && !XP_STRNCASECMP(cp, "</SCRIPT", 8))
|
||||
{
|
||||
net_BeginPICSLabelFinderTag(obj);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case ABOUT_TO_BEGIN_TAG:
|
||||
/* we have seen the first '<'
|
||||
* once we see a non-whitespace character
|
||||
* we will be in the tag identifier
|
||||
*/
|
||||
if(*cp == '>')
|
||||
{
|
||||
net_EndPICSLabelFinderTag(obj);
|
||||
}
|
||||
else if(!XP_IS_SPACE(*cp))
|
||||
{
|
||||
/* capture all tag data */
|
||||
tiny_buf[0] = *cp;
|
||||
tiny_buf[1] = '\0';
|
||||
StrAllocCat(obj->tag_data, tiny_buf);
|
||||
|
||||
obj->state = IN_BEGIN_TAG;
|
||||
obj->tag_index = 0;
|
||||
obj->tag[obj->tag_index++] = *cp;
|
||||
|
||||
}
|
||||
break;
|
||||
case IN_BEGIN_TAG:
|
||||
/* go to the IN_TAG state when we see
|
||||
* the first whitespace
|
||||
*/
|
||||
|
||||
/* capture all tag data */
|
||||
tiny_buf[0] = *cp;
|
||||
tiny_buf[1] = '\0';
|
||||
StrAllocCat(obj->tag_data, tiny_buf);
|
||||
|
||||
if(XP_IS_SPACE(*cp))
|
||||
{
|
||||
obj->state = IN_TAG;
|
||||
obj->tag[obj->tag_index] = '\0';
|
||||
obj->tag_type = pa_tokenize_tag(obj->tag);
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
net_EndPICSLabelFinderTag(obj);
|
||||
}
|
||||
else if(*cp == '<')
|
||||
{
|
||||
/* protect ourselves from markup */
|
||||
if(!obj->in_broken_html)
|
||||
{
|
||||
obj->in_broken_html = TRUE;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (obj->tag_index < MAXTAGLEN)
|
||||
obj->tag[obj->tag_index++] = *cp;
|
||||
}
|
||||
break;
|
||||
case IN_TAG:
|
||||
/* capture all tag data */
|
||||
tiny_buf[0] = *cp;
|
||||
tiny_buf[1] = '\0';
|
||||
StrAllocCat(obj->tag_data, tiny_buf);
|
||||
|
||||
/* do nothing until you find a opening '=' or end '>' */
|
||||
if(*cp == '=')
|
||||
{
|
||||
obj->state = BEGIN_ATTRIBUTE_VALUE;
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
net_EndPICSLabelFinderTag(obj);
|
||||
}
|
||||
break;
|
||||
case BEGIN_ATTRIBUTE_VALUE:
|
||||
/* capture all tag data */
|
||||
tiny_buf[0] = *cp;
|
||||
tiny_buf[1] = '\0';
|
||||
StrAllocCat(obj->tag_data, tiny_buf);
|
||||
|
||||
/* when we reach the first non-whitespace
|
||||
* we will enter the UNQUOTED or the QUOTED
|
||||
* ATTRIBUTE state
|
||||
*/
|
||||
if(!XP_IS_SPACE(*cp))
|
||||
{
|
||||
if(*cp == '"')
|
||||
{
|
||||
obj->state = IN_QUOTED_ATTRIBUTE_VALUE;
|
||||
/* no need to jump to the quoted attr handler
|
||||
* since this char can't be a dangerous char
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->state = IN_UNQUOTED_ATTRIBUTE_VALUE;
|
||||
/* need to jump to the unquoted attr handler
|
||||
* since this char can be a dangerous character
|
||||
*/
|
||||
goto unquoted_attribute_jump_point;
|
||||
}
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
net_EndPICSLabelFinderTag(obj);
|
||||
}
|
||||
break;
|
||||
case IN_UNQUOTED_ATTRIBUTE_VALUE:
|
||||
/* capture all tag data */
|
||||
tiny_buf[0] = *cp;
|
||||
tiny_buf[1] = '\0';
|
||||
StrAllocCat(obj->tag_data, tiny_buf);
|
||||
|
||||
unquoted_attribute_jump_point:
|
||||
/* do nothing until you find a whitespace */
|
||||
if(XP_IS_SPACE(*cp))
|
||||
{
|
||||
obj->state = IN_TAG;
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
net_EndPICSLabelFinderTag(obj);
|
||||
}
|
||||
break;
|
||||
case IN_QUOTED_ATTRIBUTE_VALUE:
|
||||
/* capture all tag data */
|
||||
tiny_buf[0] = *cp;
|
||||
tiny_buf[1] = '\0';
|
||||
StrAllocCat(obj->tag_data, tiny_buf);
|
||||
|
||||
/* do nothing until you find a closing '"' */
|
||||
if(*cp == '\"')
|
||||
{
|
||||
if(obj->in_broken_html)
|
||||
{
|
||||
obj->in_broken_html = FALSE;
|
||||
}
|
||||
obj->state = IN_TAG;
|
||||
}
|
||||
else if(*cp == '>')
|
||||
{
|
||||
/* probably a broken attribute value */
|
||||
if(!obj->in_broken_html)
|
||||
{
|
||||
obj->in_broken_html = TRUE;
|
||||
}
|
||||
}
|
||||
break;
|
||||
case IN_COMMENT:
|
||||
/* do nothing until you find a closing '-->' */
|
||||
if(!XP_STRNCMP(cp, "-->", 3))
|
||||
{
|
||||
cp += 2;
|
||||
i += 2;
|
||||
obj->state = IN_CONTENT;
|
||||
}
|
||||
break;
|
||||
case IN_AMPERSAND_THINGY:
|
||||
/* do nothing until you find a ';' or space */
|
||||
if(*cp == ';' || XP_IS_SPACE(*cp))
|
||||
{
|
||||
XP_SPRINTF(tiny_buf, "%c", *cp);
|
||||
obj->state = IN_CONTENT;
|
||||
}
|
||||
break;
|
||||
default:
|
||||
XP_ASSERT(0);
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return(0);
|
||||
}
|
||||
|
||||
/* is the stream ready for writeing?
|
||||
*/
|
||||
PRIVATE unsigned int net_PICSLabelFinderWriteReady (NET_StreamClass *stream)
|
||||
{
|
||||
return(MAX_WRITE_READY);
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_PICSLabelFinderComplete (NET_StreamClass *stream)
|
||||
{
|
||||
}
|
||||
|
||||
PRIVATE void net_PICSLabelFinderAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
}
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
net_PICSLabelFinderStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
DataObject* obj;
|
||||
NET_StreamClass *new_stream;
|
||||
Bool is_html_stream = FALSE;
|
||||
|
||||
TRACEMSG(("Setting up PICSLabelFinder stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
new_stream = XP_NEW_ZAP(NET_StreamClass);
|
||||
|
||||
if(!new_stream)
|
||||
return NULL;
|
||||
|
||||
obj = XP_NEW(DataObject);
|
||||
|
||||
if (obj == NULL)
|
||||
{
|
||||
FREE(new_stream);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
XP_MEMSET(obj, 0, sizeof(DataObject));
|
||||
|
||||
obj->state = IN_CONTENT;
|
||||
|
||||
obj->tag_type = P_UNKNOWN;
|
||||
|
||||
obj->context = window_id;
|
||||
obj->URL_s = URL_s;
|
||||
|
||||
new_stream->name = "PICSLabelFinder";
|
||||
new_stream->complete = (MKStreamCompleteFunc) net_PICSLabelFinderComplete;
|
||||
new_stream->abort = (MKStreamAbortFunc) net_PICSLabelFinderAbort;
|
||||
new_stream->put_block = (MKStreamWriteFunc) net_PICSLabelFinderWrite;
|
||||
new_stream->is_write_ready = (MKStreamWriteReadyFunc)
|
||||
net_PICSLabelFinderWriteReady;
|
||||
new_stream->data_object = (void *) obj; /* document info object */
|
||||
new_stream->window_id = window_id;
|
||||
|
||||
/* don't cache this URL, since the content type is wrong */
|
||||
URL_s->dont_cache = TRUE;
|
||||
|
||||
return new_stream;
|
||||
}
|
||||
11
mozilla/lib/libnet/cvpics.h
Normal file
11
mozilla/lib/libnet/cvpics.h
Normal file
@@ -0,0 +1,11 @@
|
||||
|
||||
#ifndef CVPICS_H
|
||||
#define CVPICS_H
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
net_PICSLabelFinderStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
#endif /* CVPICS_H */
|
||||
131
mozilla/lib/libnet/cvproxy.c
Normal file
131
mozilla/lib/libnet/cvproxy.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "xp.h"
|
||||
|
||||
typedef struct _ProxyObj {
|
||||
Bool past_first_line;
|
||||
Bool definately_send_headers;
|
||||
char *content_type;
|
||||
char *content_encoding;
|
||||
} ProxyObj;
|
||||
|
||||
PRIVATE int net_proxy_write (NET_StreamClass *stream, CONST char* s, int32 len)
|
||||
{
|
||||
ProxyObj *obj=stream->data_object;
|
||||
/* send HTTP headers if not already getting an HTTP doc
|
||||
*/
|
||||
if(!obj->past_first_line)
|
||||
{
|
||||
if(obj->definately_send_headers || strncmp(s, "HTTP/", len >= 5 ? 5 : len))
|
||||
{
|
||||
write(1, "HTTP/1.0 200 OK\r\n",17);
|
||||
write(1, "Content-type: ",14);
|
||||
write(1, obj->content_type, XP_STRLEN(obj->content_type));
|
||||
if(obj->content_encoding)
|
||||
{
|
||||
write(1, "\r\nContent-encoding: ",18);
|
||||
write(1, obj->content_encoding, XP_STRLEN(obj->content_encoding));
|
||||
}
|
||||
write(1, "\r\nServer: MKLib proxy agent\r\n",29);
|
||||
write(1, "\r\n", 2); /* finish it */
|
||||
}
|
||||
|
||||
obj->past_first_line = TRUE;
|
||||
}
|
||||
|
||||
write(1, s, len);
|
||||
return(1);
|
||||
}
|
||||
|
||||
PRIVATE unsigned int net_proxy_WriteReady (NET_StreamClass *stream)
|
||||
{
|
||||
return(MAX_WRITE_READY); /* always ready for writing */
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_proxy_complete (NET_StreamClass *stream)
|
||||
{
|
||||
ProxyObj *obj=stream->data_object;
|
||||
FREEIF(obj->content_type);
|
||||
FREEIF(obj->content_encoding);
|
||||
FREE(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE void net_proxy_abort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
ProxyObj *obj=stream->data_object;
|
||||
FREEIF(obj->content_type);
|
||||
FREEIF(obj->content_encoding);
|
||||
FREE(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
NET_ProxyConverter(int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
NET_StreamClass* stream;
|
||||
ProxyObj * obj;
|
||||
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s \n%s\n",
|
||||
URL_s->address, URL_s->content_type));
|
||||
|
||||
stream = XP_NEW(NET_StreamClass);
|
||||
if(stream == NULL)
|
||||
return(NULL);
|
||||
|
||||
obj = XP_NEW(ProxyObj);
|
||||
if(obj == NULL)
|
||||
{
|
||||
FREE(stream);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
XP_MEMSET(obj, 0, sizeof(ProxyObj));
|
||||
|
||||
stream->data_object = obj;
|
||||
|
||||
|
||||
stream->name = "ProxyWriter";
|
||||
stream->complete = (MKStreamCompleteFunc) net_proxy_complete;
|
||||
stream->abort = (MKStreamAbortFunc) net_proxy_abort;
|
||||
stream->put_block = (MKStreamWriteFunc) net_proxy_write;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc) net_proxy_WriteReady;
|
||||
stream->window_id = window_id;
|
||||
|
||||
TRACEMSG(("Returning stream from display_converter\n"));
|
||||
|
||||
/* send HTTP headers if not already getting an HTTP doc
|
||||
*/
|
||||
if(strncasecomp(URL_s->address,"http:",5))
|
||||
{
|
||||
obj->definately_send_headers = TRUE;
|
||||
}
|
||||
StrAllocCopy(obj->content_type, URL_s->content_type);
|
||||
StrAllocCopy(obj->content_encoding, URL_s->content_encoding);
|
||||
|
||||
return stream;
|
||||
}
|
||||
22
mozilla/lib/libnet/cvproxy.h
Normal file
22
mozilla/lib/libnet/cvproxy.h
Normal file
@@ -0,0 +1,22 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
extern NET_StreamClass* NET_ProxyConverter (FO_Present_Types format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
123
mozilla/lib/libnet/cvsimple.c
Normal file
123
mozilla/lib/libnet/cvsimple.c
Normal file
@@ -0,0 +1,123 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/**********************************************************************
|
||||
cvsimple.c
|
||||
By Daniel Malmer <malmer@netscape.com>
|
||||
1/14/98
|
||||
|
||||
Simple converter that just saves the data in a buffer.
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
#include "cvsimple.h"
|
||||
#include "xp.h"
|
||||
|
||||
typedef void (*simple_complete_t)(void* bytes, int32 bytes_written);
|
||||
|
||||
typedef struct {
|
||||
unsigned char* bytes;
|
||||
int32 bytes_written;
|
||||
int32 max_bytes;
|
||||
simple_complete_t complete;
|
||||
} NET_SimpleStreamData;
|
||||
|
||||
|
||||
/*
|
||||
* simple_complete
|
||||
*/
|
||||
PRIVATE void
|
||||
simple_complete(NET_StreamClass *stream)
|
||||
{
|
||||
NET_SimpleStreamData* obj = (NET_SimpleStreamData*) stream->data_object;
|
||||
|
||||
if ( obj && obj->complete ) {
|
||||
(obj->complete)(obj->bytes, obj->bytes_written);
|
||||
}
|
||||
|
||||
if ( obj && obj->bytes ) XP_FREE(obj->bytes);
|
||||
if ( obj ) XP_FREE(obj);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* simple_abort
|
||||
*/
|
||||
PRIVATE void
|
||||
simple_abort(NET_StreamClass *stream, int status)
|
||||
{
|
||||
NET_SimpleStreamData* obj = (NET_SimpleStreamData*) stream->data_object;
|
||||
|
||||
if ( obj && obj->bytes ) XP_FREE(obj->bytes);
|
||||
if ( obj ) XP_FREE(obj);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* simple_write
|
||||
*/
|
||||
PRIVATE int
|
||||
simple_write(NET_StreamClass *stream, const char* str, int32 len)
|
||||
{
|
||||
NET_SimpleStreamData* obj = (NET_SimpleStreamData*) stream->data_object;
|
||||
|
||||
if ( obj->bytes_written + len > obj->max_bytes ) {
|
||||
/* Round to nearest 1024 */
|
||||
obj->max_bytes = ( ( ( (obj->max_bytes + len) >> 10) + 1) << 10);
|
||||
obj->bytes = XP_REALLOC(obj->bytes, obj->max_bytes);
|
||||
}
|
||||
|
||||
XP_MEMCPY(obj->bytes + obj->bytes_written, str, len);
|
||||
obj->bytes_written+= len;
|
||||
|
||||
return MK_DATA_LOADED;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* simple_write_ready
|
||||
*/
|
||||
PRIVATE unsigned int
|
||||
simple_write_ready(NET_StreamClass *stream)
|
||||
{
|
||||
return MAX_WRITE_READY;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* NET_SimpleStream
|
||||
* Simple stream constructor.
|
||||
*/
|
||||
MODULE_PRIVATE NET_StreamClass*
|
||||
NET_SimpleStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w)
|
||||
{
|
||||
NET_SimpleStreamData* obj;
|
||||
|
||||
if ( (obj = XP_NEW_ZAP(NET_SimpleStreamData)) == NULL ) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj->bytes = NULL;
|
||||
obj->bytes_written = 0;
|
||||
obj->max_bytes = 0;
|
||||
obj->complete = (simple_complete_t) data_obj;
|
||||
|
||||
return NET_NewStream("SimpleStream", simple_write, simple_complete,
|
||||
simple_abort, simple_write_ready, obj, w);
|
||||
}
|
||||
|
||||
|
||||
36
mozilla/lib/libnet/cvsimple.h
Normal file
36
mozilla/lib/libnet/cvsimple.h
Normal file
@@ -0,0 +1,36 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/**********************************************************************
|
||||
cvsimple.h
|
||||
By Daniel Malmer <malmer@netscape.com>
|
||||
1/14/98
|
||||
|
||||
Simple converter that just saves the data in a buffer.
|
||||
|
||||
**********************************************************************/
|
||||
|
||||
|
||||
#ifndef __cvsimple_h
|
||||
#define __cvsimple_h
|
||||
|
||||
#include "net.h"
|
||||
|
||||
MODULE_PRIVATE NET_StreamClass*
|
||||
NET_SimpleStream(int fmt, void* data_obj, URL_Struct* URL_s, MWContext* w);
|
||||
|
||||
#endif
|
||||
482
mozilla/lib/libnet/cvunzip.c
Normal file
482
mozilla/lib/libnet/cvunzip.c
Normal file
@@ -0,0 +1,482 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* Please leave outside of ifdef for windows precompiled headers */
|
||||
#include "mkutils.h"
|
||||
#include "cvunzip.h"
|
||||
|
||||
#ifdef MOZILLA_CLIENT
|
||||
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "xp.h"
|
||||
#include "zlib.h"
|
||||
|
||||
extern int MK_OUT_OF_MEMORY;
|
||||
extern int MK_BAD_GZIP_HEADER;
|
||||
|
||||
typedef struct _DataObject {
|
||||
NET_StreamClass *next_stream;
|
||||
z_stream d_stream; /* decompression stream */
|
||||
unsigned char *dcomp_buf;
|
||||
uint32 dcomp_buf_size;
|
||||
XP_Bool is_done;
|
||||
XP_Bool checking_crc_footer;
|
||||
unsigned char *incoming_buf;
|
||||
uint32 incoming_buf_size;
|
||||
XP_Bool header_skipped;
|
||||
URL_Struct *URL_s;
|
||||
uint32 crc_check;
|
||||
} DataObject;
|
||||
|
||||
#define DECOMP_BUF_SIZE NET_Socket_Buffer_Size*2
|
||||
|
||||
enum check_header_response {
|
||||
HEADER_OK,
|
||||
BAD_HEADER,
|
||||
NEED_MORE_HEADER
|
||||
};
|
||||
|
||||
static uint32 gz_magic[2] = {0x1f, 0x8b}; /* gzip magic header */
|
||||
|
||||
/* gzip flag byte */
|
||||
#define ASCII_FLAG 0x01 /* bit 0 set: file probably ascii text */
|
||||
#define HEAD_CRC 0x02 /* bit 1 set: header CRC present */
|
||||
#define EXTRA_FIELD 0x04 /* bit 2 set: extra field present */
|
||||
#define ORIG_NAME 0x08 /* bit 3 set: original file name present */
|
||||
#define COMMENT 0x10 /* bit 4 set: file comment present */
|
||||
#define RESERVED 0xE0 /* bits 5..7: reserved */
|
||||
|
||||
/* code copied from Zlib please see zlib.h for copyright statement */
|
||||
/* ===========================================================================
|
||||
Check the gzip header of a gz_stream opened for reading. Set the stream
|
||||
mode to transparent if the gzip magic header is not present; set s->err
|
||||
to Z_DATA_ERROR if the magic header is present but the rest of the header
|
||||
is incorrect.
|
||||
IN assertion: the stream s has already been created sucessfully;
|
||||
s->stream.avail_in is zero for the first time, but may be non-zero
|
||||
for concatenated .gz files.
|
||||
*/
|
||||
static enum check_header_response
|
||||
check_header(unsigned char *header, uint32 header_length, uint32 *actual_header_size)
|
||||
{
|
||||
int method; /* method byte */
|
||||
int flags; /* flags byte */
|
||||
uInt len;
|
||||
uint32 c;
|
||||
uint32 orig_header_size = header_length;
|
||||
|
||||
/* header must be at least 10 bytes */
|
||||
if(header_length < 10)
|
||||
return NEED_MORE_HEADER;
|
||||
|
||||
/* Check the gzip magic header */
|
||||
for (len = 0; len < 2; len++) {
|
||||
c = (uint32) *header++;
|
||||
header_length--;
|
||||
if (c != gz_magic[len]) {
|
||||
return BAD_HEADER;
|
||||
}
|
||||
}
|
||||
method = *header++;
|
||||
header_length--;
|
||||
flags = *header++;
|
||||
header_length--;
|
||||
if (method != Z_DEFLATED || (flags & RESERVED) != 0) {
|
||||
return BAD_HEADER;
|
||||
}
|
||||
|
||||
/* Discard time, xflags and OS code: */
|
||||
for (len = 0; len < 6; len++)
|
||||
{
|
||||
header++;
|
||||
header_length--;
|
||||
}
|
||||
|
||||
/* OK we now passed the safe 10 byte boundary, we need to check from here
|
||||
* on out to make sure we have enough data
|
||||
*/
|
||||
|
||||
if ((flags & EXTRA_FIELD) != 0) { /* skip the extra field */
|
||||
if(header_length < 2)
|
||||
return NEED_MORE_HEADER;
|
||||
|
||||
len = (uInt)*header++;
|
||||
header_length--;
|
||||
len += ((uInt)*header++)<<8;
|
||||
header_length--;
|
||||
|
||||
/* len is garbage if EOF but the loop below will quit anyway */
|
||||
|
||||
if(header_length < len)
|
||||
return NEED_MORE_HEADER;
|
||||
|
||||
while (len-- != 0)
|
||||
{
|
||||
header++;
|
||||
header_length--;
|
||||
}
|
||||
}
|
||||
if ((flags & ORIG_NAME) != 0) { /* skip the original file name */
|
||||
|
||||
if(header_length < 1)
|
||||
return NEED_MORE_HEADER;
|
||||
|
||||
while (*header != '\0')
|
||||
{
|
||||
header++;
|
||||
header_length--;
|
||||
|
||||
if(header_length == 0)
|
||||
return NEED_MORE_HEADER;
|
||||
}
|
||||
|
||||
/* skip null byte */
|
||||
header++;
|
||||
header_length--;
|
||||
}
|
||||
if ((flags & COMMENT) != 0) { /* skip the .gz file comment */
|
||||
|
||||
if(header_length < 1)
|
||||
return NEED_MORE_HEADER;
|
||||
|
||||
while (*header != '\0')
|
||||
{
|
||||
header++;
|
||||
header_length--;
|
||||
|
||||
if(header_length == 0)
|
||||
return NEED_MORE_HEADER;
|
||||
}
|
||||
|
||||
/* skip null byte */
|
||||
header++;
|
||||
header_length--;
|
||||
|
||||
}
|
||||
if ((flags & HEAD_CRC) != 0) { /* skip the header crc */
|
||||
|
||||
if(header_length < 2)
|
||||
return NEED_MORE_HEADER;
|
||||
|
||||
for (len = 0; len < 2; len++)
|
||||
{
|
||||
header++;
|
||||
header_length--;
|
||||
}
|
||||
}
|
||||
|
||||
*actual_header_size = orig_header_size - header_length;
|
||||
|
||||
return HEADER_OK;
|
||||
}
|
||||
|
||||
PRIVATE int
|
||||
do_end_crc_check(DataObject *obj)
|
||||
{
|
||||
|
||||
if(obj->incoming_buf_size >= 8)
|
||||
{
|
||||
uint32 crc_int;
|
||||
uint32 size_int;
|
||||
|
||||
obj->checking_crc_footer = FALSE;
|
||||
obj->is_done = TRUE;
|
||||
|
||||
crc_int = (uint32)obj->incoming_buf[0];
|
||||
crc_int += (uint32)obj->incoming_buf[1]<<8;
|
||||
crc_int += (uint32)obj->incoming_buf[2]<<16;
|
||||
crc_int += (uint32)obj->incoming_buf[3]<<24;
|
||||
|
||||
size_int = (uint32)obj->incoming_buf[4];
|
||||
size_int += (uint32)obj->incoming_buf[5]<<8;
|
||||
size_int += (uint32)obj->incoming_buf[6]<<16;
|
||||
size_int += (uint32)obj->incoming_buf[7]<<24;
|
||||
|
||||
if(obj->crc_check != crc_int
|
||||
|| obj->d_stream.total_out != size_int)
|
||||
{
|
||||
/* crc or size checksum failure */
|
||||
obj->URL_s->error_msg = NET_ExplainErrorDetails(MK_BAD_GZIP_HEADER);
|
||||
return MK_BAD_GZIP_HEADER;
|
||||
}
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0; /* need more data */
|
||||
}
|
||||
|
||||
PRIVATE int net_UnZipWrite (NET_StreamClass *stream, CONST char* s, int32 l)
|
||||
{
|
||||
int err;
|
||||
uint32 prev_total_out;
|
||||
uint32 new_data_total_out;
|
||||
uint32 input_used_up, input_left_over;
|
||||
char * tempPtr = NULL;
|
||||
DataObject *obj=stream->data_object;
|
||||
if(obj->is_done)
|
||||
{
|
||||
/* multipart gzip? */
|
||||
XP_ASSERT(0);
|
||||
return (1);
|
||||
}
|
||||
|
||||
BlockAllocCat( tempPtr, obj->incoming_buf_size, s, l);
|
||||
obj->incoming_buf = (unsigned char*)tempPtr;
|
||||
|
||||
if(!obj->incoming_buf)
|
||||
return MK_OUT_OF_MEMORY;
|
||||
obj->incoming_buf_size += l;
|
||||
|
||||
/* parse and skip the header */
|
||||
if(!obj->header_skipped)
|
||||
{
|
||||
uint32 actual_header_size;
|
||||
enum check_header_response status;
|
||||
|
||||
status = check_header((unsigned char *)obj->incoming_buf, obj->incoming_buf_size, &actual_header_size);
|
||||
|
||||
if(status == HEADER_OK)
|
||||
{
|
||||
/* squash the header */
|
||||
obj->incoming_buf_size -= actual_header_size;
|
||||
XP_MEMMOVE(obj->incoming_buf,
|
||||
obj->incoming_buf+actual_header_size,
|
||||
obj->incoming_buf_size);
|
||||
|
||||
obj->header_skipped = TRUE;
|
||||
}
|
||||
else if(status == BAD_HEADER)
|
||||
{
|
||||
obj->URL_s->error_msg = NET_ExplainErrorDetails(MK_BAD_GZIP_HEADER);
|
||||
return MK_BAD_GZIP_HEADER;
|
||||
}
|
||||
else if(status == NEED_MORE_HEADER)
|
||||
{
|
||||
return 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
XP_ASSERT(0);
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
else if(obj->checking_crc_footer)
|
||||
{
|
||||
return do_end_crc_check(obj);
|
||||
}
|
||||
|
||||
obj->d_stream.next_in = (unsigned char *)obj->incoming_buf;
|
||||
obj->d_stream.avail_in = obj->incoming_buf_size;
|
||||
obj->d_stream.next_out = (unsigned char *)obj->dcomp_buf;
|
||||
obj->d_stream.avail_out = obj->dcomp_buf_size;
|
||||
|
||||
if(obj->d_stream.avail_in <= 0)
|
||||
return 1; /* wait for more data */
|
||||
|
||||
prev_total_out = obj->d_stream.total_out;
|
||||
|
||||
/* need to loop to finish for small output bufs */
|
||||
while(1)
|
||||
{
|
||||
err = inflate(&obj->d_stream, Z_NO_FLUSH);
|
||||
|
||||
/* the amount of new uncompressed data is: */
|
||||
new_data_total_out = obj->d_stream.total_out - prev_total_out;
|
||||
|
||||
if(new_data_total_out > 0)
|
||||
{
|
||||
obj->crc_check = crc32(obj->crc_check,
|
||||
obj->dcomp_buf,
|
||||
new_data_total_out);
|
||||
|
||||
(*obj->next_stream->put_block)(obj->next_stream,
|
||||
(char *) obj->dcomp_buf,
|
||||
new_data_total_out);
|
||||
|
||||
|
||||
}
|
||||
|
||||
obj->d_stream.avail_out = obj->dcomp_buf_size;
|
||||
obj->d_stream.next_out = (unsigned char *)obj->dcomp_buf;
|
||||
prev_total_out = obj->d_stream.total_out;
|
||||
|
||||
if(err == Z_STREAM_END)
|
||||
{
|
||||
obj->checking_crc_footer = TRUE;
|
||||
break;
|
||||
}
|
||||
else if(err != Z_OK)
|
||||
{
|
||||
/* need to get more data on next pass
|
||||
* @@@ should check for more critical errors
|
||||
*/
|
||||
break;
|
||||
}
|
||||
else if(obj->d_stream.avail_in <= 0)
|
||||
{
|
||||
/* need more data */
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* remove the part that has already been decoding from the incoming buf */
|
||||
input_left_over = obj->d_stream.avail_in;
|
||||
|
||||
if(input_left_over > 0)
|
||||
{
|
||||
input_used_up = obj->incoming_buf_size - input_left_over;
|
||||
XP_MEMMOVE(obj->incoming_buf, obj->incoming_buf+input_used_up, input_left_over);
|
||||
obj->incoming_buf_size = input_left_over;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj->incoming_buf_size = 0;
|
||||
}
|
||||
|
||||
if(obj->checking_crc_footer == TRUE)
|
||||
{
|
||||
return do_end_crc_check(obj);
|
||||
}
|
||||
|
||||
return(1);
|
||||
}
|
||||
|
||||
/* is the stream ready for writeing?
|
||||
*/
|
||||
PRIVATE unsigned int net_UnZipWriteReady (NET_StreamClass * stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
return((*obj->next_stream->is_write_ready)(obj->next_stream)); /* always ready for writing */
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_UnZipComplete (NET_StreamClass *stream)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
int err;
|
||||
|
||||
(*obj->next_stream->complete)(obj->next_stream);
|
||||
|
||||
err = inflateEnd(&(obj->d_stream));
|
||||
XP_ASSERT(err == Z_OK);
|
||||
|
||||
if(!obj->is_done)
|
||||
{
|
||||
/* we didn't complete the crc and size checks */
|
||||
/* @@@ not sure what to do here yet */
|
||||
XP_ASSERT(0);
|
||||
}
|
||||
|
||||
FREE(obj->dcomp_buf);
|
||||
FREE(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE void net_UnZipAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
DataObject *obj=stream->data_object;
|
||||
int err;
|
||||
|
||||
(*obj->next_stream->abort)(obj->next_stream, status);
|
||||
|
||||
err = inflateEnd(&(obj->d_stream));
|
||||
XP_ASSERT(err == Z_OK);
|
||||
|
||||
FREE(obj->dcomp_buf);
|
||||
FREE(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
NET_UnZipConverter (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
DataObject* obj;
|
||||
NET_StreamClass* stream;
|
||||
int err;
|
||||
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
stream = XP_NEW(NET_StreamClass);
|
||||
if(stream == NULL)
|
||||
return(NULL);
|
||||
|
||||
obj = XP_NEW_ZAP(DataObject);
|
||||
if (obj == NULL)
|
||||
{
|
||||
FREE(stream);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
stream->name = "UnZiper";
|
||||
stream->complete = (MKStreamCompleteFunc) net_UnZipComplete;
|
||||
stream->abort = (MKStreamAbortFunc) net_UnZipAbort;
|
||||
stream->put_block = (MKStreamWriteFunc) net_UnZipWrite;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc) net_UnZipWriteReady;
|
||||
stream->data_object = obj; /* document info object */
|
||||
stream->window_id = window_id;
|
||||
|
||||
obj->dcomp_buf = XP_ALLOC(DECOMP_BUF_SIZE);
|
||||
obj->dcomp_buf_size = DECOMP_BUF_SIZE;
|
||||
|
||||
if(!obj->dcomp_buf)
|
||||
{
|
||||
FREE(stream);
|
||||
FREE(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj->URL_s = URL_s;
|
||||
|
||||
obj->d_stream.zalloc = (alloc_func)0;
|
||||
obj->d_stream.zfree = (free_func)0;
|
||||
obj->d_stream.opaque = (voidpf)0;
|
||||
|
||||
err = inflateInit2(&obj->d_stream, -15);
|
||||
|
||||
if(err != Z_OK)
|
||||
{
|
||||
FREE(stream);
|
||||
FREE(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* create the next stream, but strip the compressed encoding */
|
||||
FREE_AND_CLEAR(URL_s->content_encoding);
|
||||
obj->next_stream = NET_StreamBuilder(format_out, URL_s, window_id);
|
||||
|
||||
if(!obj->next_stream)
|
||||
{
|
||||
inflateEnd(&obj->d_stream);
|
||||
FREE(stream);
|
||||
FREE(obj);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
TRACEMSG(("Returning stream from NET_UnZipConverter\n"));
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
28
mozilla/lib/libnet/cvunzip.h
Normal file
28
mozilla/lib/libnet/cvunzip.h
Normal file
@@ -0,0 +1,28 @@
|
||||
/* -*- 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 CVUNZIP_H
|
||||
#define CVUNZIP_H
|
||||
|
||||
NET_StreamClass *
|
||||
NET_UnZipConverter (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
#endif /* CVUNZIP_H */
|
||||
580
mozilla/lib/libnet/cvview.c
Normal file
580
mozilla/lib/libnet/cvview.c
Normal file
@@ -0,0 +1,580 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* Please leave outside of ifdef for windows precompiled headers */
|
||||
#include "mkutils.h"
|
||||
|
||||
#ifdef MOZILLA_CLIENT
|
||||
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "xp.h"
|
||||
#include "mkparse.h"
|
||||
#include "cvview.h"
|
||||
|
||||
#include "libmime.h"
|
||||
|
||||
|
||||
/* for XP_GetString() */
|
||||
#include <xpgetstr.h>
|
||||
extern int XP_CONFIRM_EXEC_UNIXCMD_ARE;
|
||||
extern int XP_CONFIRM_EXEC_UNIXCMD_MAYBE;
|
||||
extern int XP_ALERT_UNABLE_INVOKEVIEWER;
|
||||
extern int MK_UNABLE_TO_OPEN_TMP_FILE;
|
||||
|
||||
|
||||
typedef struct _CV_DataObject {
|
||||
FILE * fp;
|
||||
char * filename;
|
||||
char * command;
|
||||
char * url;
|
||||
unsigned int stream_block_size;
|
||||
int32 cur_size;
|
||||
int32 tot_size;
|
||||
MWContext * context;
|
||||
} CV_DataObject;
|
||||
|
||||
|
||||
/*
|
||||
** build_viewer_cmd
|
||||
** Build up the command for forking the external viewer.
|
||||
** Argument list is the template for the command and the a set of
|
||||
** (char,char*) pairs of characters to be recognized as '%' escapes
|
||||
** and what they should expand to, terminated with a 0.
|
||||
**
|
||||
** Return value is a malloc'ed string, must be freed when command is done.
|
||||
**
|
||||
** Example:
|
||||
** char* s=build_viewer(line_from_mailcap, 's', tmpFile, 'u', url, 0);
|
||||
**
|
||||
** I'm completely unsure what to do about security considerations and
|
||||
** encodings. Should the URL get % encoded. What if it contains "bad"
|
||||
** characters. etc. etc. etc
|
||||
*/
|
||||
|
||||
char*
|
||||
build_viewer_cmd(char *template, ...)
|
||||
{
|
||||
va_list args;
|
||||
char *ret, *from, *to;
|
||||
int len;
|
||||
|
||||
if (template == NULL)
|
||||
return NULL;
|
||||
|
||||
len = strlen(template);
|
||||
ret = (char*) malloc(len+1);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
|
||||
from = template, to = ret;
|
||||
|
||||
while (*from) {
|
||||
if (*from != '%' || *++from == '%') {
|
||||
*to++ = *from++;
|
||||
} else {
|
||||
|
||||
/*
|
||||
** We have a % escape, now look through all the arguments for
|
||||
** a matching one. When one is found, substitute in the
|
||||
** passed value. If none is found, the % and following character
|
||||
** get swallowed.
|
||||
*/
|
||||
char argc;
|
||||
char* argv;
|
||||
|
||||
va_start(args, template);
|
||||
while ((argc = va_arg(args, int)) != 0) {
|
||||
argv = va_arg(args, char*);
|
||||
if (*from == argc) {
|
||||
int off = to - ret;
|
||||
int arglen = strlen(argv);
|
||||
|
||||
len = len + arglen - 2;
|
||||
ret = (char*) realloc(ret, len + 1);
|
||||
if (ret == NULL)
|
||||
return NULL;
|
||||
XP_STRCPY(ret + off, argv);
|
||||
to = ret + off + arglen;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (*from) from++; /* skip char following % unless it was last */
|
||||
va_end(args);
|
||||
}
|
||||
}
|
||||
*to = '\0';
|
||||
return ret;
|
||||
}
|
||||
|
||||
PRIVATE int net_ExtViewWrite (NET_StreamClass *stream, CONST char* s, int32 l)
|
||||
{
|
||||
CV_DataObject *obj=stream->data_object;
|
||||
if(obj->tot_size)
|
||||
{
|
||||
obj->cur_size += l;
|
||||
|
||||
obj->context->funcs->SetProgressBarPercent(obj->context, (obj->cur_size*100)/obj->tot_size);
|
||||
}
|
||||
|
||||
/* TRACEMSG(("Length of string passed to display: %d\n",l));
|
||||
*/
|
||||
return(fwrite((char *) s, 1, l, obj->fp));
|
||||
}
|
||||
|
||||
PRIVATE int net_ExtViewWriteReady (NET_StreamClass * stream)
|
||||
{
|
||||
CV_DataObject *obj=stream->data_object;
|
||||
fd_set write_fds;
|
||||
struct timeval timeout;
|
||||
int ret;
|
||||
|
||||
if(obj->command)
|
||||
{
|
||||
return(MAX_WRITE_READY); /* never wait for files */
|
||||
}
|
||||
|
||||
timeout.tv_sec = 0;
|
||||
timeout.tv_usec = 1; /* minimum hopefully */
|
||||
|
||||
XP_MEMSET(&write_fds, 0, sizeof(fd_set));
|
||||
|
||||
FD_SET(fileno(obj->fp), &write_fds);
|
||||
|
||||
ret = select(fileno(obj->fp)+1, NULL, &write_fds, NULL, &timeout);
|
||||
|
||||
if(ret)
|
||||
return(obj->stream_block_size); /* read in a max of 8000 bytes */
|
||||
else
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void net_ExtViewComplete (NET_StreamClass *stream)
|
||||
{
|
||||
CV_DataObject *obj=stream->data_object;
|
||||
obj->context->funcs->SetProgressBarPercent(obj->context, 100);
|
||||
|
||||
if(obj->command)
|
||||
{
|
||||
char *p_tmp;
|
||||
char *command;
|
||||
|
||||
/* restrict to allowed url chars
|
||||
*
|
||||
*/
|
||||
for(p_tmp = obj->url; *p_tmp != '\0'; p_tmp++)
|
||||
if( (*p_tmp >= '0' && *p_tmp <= '9')
|
||||
|| (*p_tmp >= 'A' && *p_tmp <= 'Z')
|
||||
|| (*p_tmp >= 'a' && *p_tmp <= 'z')
|
||||
|| (*p_tmp == '_')
|
||||
|| (*p_tmp == '?')
|
||||
|| (*p_tmp == '#')
|
||||
|| (*p_tmp == '&')
|
||||
|| (*p_tmp == '%')
|
||||
|| (*p_tmp == '/')
|
||||
|| (*p_tmp == ':')
|
||||
|| (*p_tmp == '+')
|
||||
|| (*p_tmp == '.')
|
||||
|| (*p_tmp == '~')
|
||||
|| (*p_tmp == '=')
|
||||
|| (*p_tmp == '-'))
|
||||
{
|
||||
/* this is a good character. Allow it.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_tmp = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
command=build_viewer_cmd(obj->command,
|
||||
's', obj->filename,
|
||||
'u', obj->url, 0);
|
||||
|
||||
fclose(obj->fp);
|
||||
TRACEMSG(("Invoking: %s", command));
|
||||
|
||||
system(command);
|
||||
FREEIF(obj->command);
|
||||
}
|
||||
else
|
||||
{
|
||||
pclose(obj->fp);
|
||||
}
|
||||
|
||||
FREEIF(obj->filename);
|
||||
FREEIF(obj->url);
|
||||
FREE(obj);
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE void net_ExtViewAbort (NET_StreamClass *stream, int status)
|
||||
{
|
||||
CV_DataObject *obj=stream->data_object;
|
||||
obj->context->funcs->SetProgressBarPercent(obj->context, 100);
|
||||
|
||||
fclose(obj->fp);
|
||||
|
||||
if(obj->filename)
|
||||
{
|
||||
remove(obj->filename);
|
||||
FREE(obj->filename);
|
||||
}
|
||||
|
||||
FREEIF(obj->url);
|
||||
FREEIF(obj->command);
|
||||
|
||||
FREE(obj);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
#ifdef XP_UNIX
|
||||
extern char **fe_encoding_extensions; /* gag! */
|
||||
#endif
|
||||
|
||||
|
||||
PUBLIC NET_StreamClass *
|
||||
NET_ExtViewerConverter (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id)
|
||||
{
|
||||
CV_DataObject* obj;
|
||||
NET_StreamClass* stream;
|
||||
char *tmp_filename;
|
||||
char *dot;
|
||||
char *path;
|
||||
CV_ExtViewStruct * view_struct = (CV_ExtViewStruct *)data_obj;
|
||||
char small_buf[256];
|
||||
int yes_stream=0;
|
||||
|
||||
/* If this URL is a mail or news attachment, use the name of that
|
||||
attachment as the URL -- this is so the temp file gets the right
|
||||
extension on it (some helper apps are picky about that...)
|
||||
*/
|
||||
path = MimeGuessURLContentName(window_id, URL_s->address);
|
||||
if (!path)
|
||||
path = NET_ParseURL(URL_s->address, GET_PATH_PART);
|
||||
if (!path)
|
||||
return 0;
|
||||
|
||||
|
||||
TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));
|
||||
|
||||
stream = XP_NEW(NET_StreamClass);
|
||||
if(stream == NULL)
|
||||
return(NULL);
|
||||
|
||||
memset(stream, 0, sizeof(NET_StreamClass));
|
||||
|
||||
obj = XP_NEW(CV_DataObject);
|
||||
if (obj == NULL)
|
||||
return(NULL);
|
||||
memset(obj, 0, sizeof(CV_DataObject));
|
||||
|
||||
obj->context = window_id;
|
||||
|
||||
if(URL_s->content_length)
|
||||
{
|
||||
obj->tot_size = URL_s->content_length;
|
||||
}
|
||||
else
|
||||
{
|
||||
/* start the progress bar cyloning
|
||||
*/
|
||||
obj->context->funcs->SetProgressBarPercent(window_id, -1);
|
||||
}
|
||||
|
||||
stream->name = "Execute external viewer";
|
||||
stream->complete = (MKStreamCompleteFunc) net_ExtViewComplete;
|
||||
stream->abort = (MKStreamAbortFunc) net_ExtViewAbort;
|
||||
stream->put_block = (MKStreamWriteFunc) net_ExtViewWrite;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc) net_ExtViewWriteReady;
|
||||
stream->data_object = obj; /* document info object */
|
||||
stream->window_id = window_id;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
/* Some naive people may have trustingly put
|
||||
|
||||
application/x-sh; sh %s
|
||||
application/x-csh; csh %s
|
||||
|
||||
in their mailcap files without realizing how dangerous that is.
|
||||
Worse, it might be there and they might not realize it. So, if
|
||||
we're about to execute a shell, pop up a dialog box first.
|
||||
*/
|
||||
{
|
||||
char *prog = XP_STRDUP (view_struct->system_command);
|
||||
char *s, *start, *end;
|
||||
int danger = 0;
|
||||
|
||||
/* strip end space */
|
||||
end = XP_StripLine(prog);
|
||||
|
||||
/* Extract the leaf name of the program: " /bin/sh -foo" ==> "sh". */
|
||||
for (; *end && !XP_IS_SPACE(*end); end++)
|
||||
;
|
||||
*end = 0;
|
||||
|
||||
if ((start = XP_STRRCHR (prog, '/')))
|
||||
start++;
|
||||
else
|
||||
start = XP_StripLine(prog); /* start at first non-white space */
|
||||
|
||||
/* Strip off everything after the first nonalphabetic.
|
||||
This is so "perl-4.0" is compared as "perl" and
|
||||
"emacs19" is compared as "emacs".
|
||||
*/
|
||||
for (s = start; *s; s++)
|
||||
if (!isalpha (*s))
|
||||
*s = 0;
|
||||
|
||||
/* These are things known to be shells - very bad. */
|
||||
if (!XP_STRCMP (start, "ash") ||
|
||||
!XP_STRCMP (start, "bash") ||
|
||||
!XP_STRCMP (start, "csh") ||
|
||||
!XP_STRCMP (start, "jsh") ||
|
||||
!XP_STRCMP (start, "ksh") ||
|
||||
!XP_STRCMP (start, "pdksh") ||
|
||||
!XP_STRCMP (start, "sh") ||
|
||||
!XP_STRCMP (start, "tclsh") ||
|
||||
!XP_STRCMP (start, "tcsh") ||
|
||||
!XP_STRCMP (start, "wish") || /* a tcl thing */
|
||||
!XP_STRCMP (start, "wksh") ||
|
||||
!XP_STRCMP (start, "zsh"))
|
||||
danger = 2;
|
||||
|
||||
/* Remote shells are potentially dangerous, in the case of
|
||||
"rsh somehost some-dangerous-program", but it's hard to
|
||||
parse that out, since rsh could take arbitrarily complicated
|
||||
args, like "rsh somehost -u something -pass8 /bin/sh %s".
|
||||
And we don't want to squawk about "rsh somehost playulaw -".
|
||||
So... allow rsh to possibly be a security hole.
|
||||
*/
|
||||
else if (!XP_STRCMP (start, "remsh") || /* remote shell */
|
||||
!XP_STRCMP (start, "rksh") ||
|
||||
!XP_STRCMP (start, "rsh") /* remote- or restricted- */
|
||||
)
|
||||
danger = 0;
|
||||
|
||||
/* These are things which aren't really shells, but can do the
|
||||
same damage anyway since they can write files and/or execute
|
||||
other programs. */
|
||||
else if (!XP_STRCMP (start, "awk") ||
|
||||
!XP_STRCMP (start, "e") ||
|
||||
!XP_STRCMP (start, "ed") ||
|
||||
!XP_STRCMP (start, "ex") ||
|
||||
!XP_STRCMP (start, "gawk") ||
|
||||
!XP_STRCMP (start, "m4") ||
|
||||
!XP_STRCMP (start, "sed") ||
|
||||
!XP_STRCMP (start, "vi") ||
|
||||
!XP_STRCMP (start, "emacs") ||
|
||||
!XP_STRCMP (start, "lemacs") ||
|
||||
!XP_STRCMP (start, "xemacs") ||
|
||||
!XP_STRCMP (start, "temacs") ||
|
||||
|
||||
/* Other dangerous interpreters */
|
||||
!XP_STRCMP (start, "basic") ||
|
||||
!XP_STRCMP (start, "expect") ||
|
||||
!XP_STRCMP (start, "expectk") ||
|
||||
!XP_STRCMP (start, "perl") ||
|
||||
!XP_STRCMP (start, "python") ||
|
||||
!XP_STRCMP (start, "rexx")
|
||||
)
|
||||
danger = 1;
|
||||
|
||||
/* Be suspicious of anything ending in "sh". */
|
||||
else if (XP_STRLEN (start) > 2 &&
|
||||
!XP_STRCMP (start + XP_STRLEN (start) - 2, "sh"))
|
||||
danger = 1;
|
||||
|
||||
if (danger)
|
||||
{
|
||||
char msg [2048];
|
||||
PR_snprintf (msg,
|
||||
sizeof(msg),
|
||||
(danger > 1 ? XP_GetString(XP_CONFIRM_EXEC_UNIXCMD_ARE) : XP_GetString(XP_CONFIRM_EXEC_UNIXCMD_MAYBE)),
|
||||
start
|
||||
);
|
||||
if (!FE_Confirm (window_id, msg))
|
||||
{
|
||||
FREE (stream);
|
||||
FREE (obj);
|
||||
FREE (path);
|
||||
FREE (prog);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
FREE (prog);
|
||||
}
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
if(view_struct->stream_block_size)
|
||||
{
|
||||
/* asks the user if they want to stream data.
|
||||
* -1 cancel
|
||||
* 0 No, don't stream data, play from the file
|
||||
* 1 Yes, stream the data from the network
|
||||
*/
|
||||
int XFE_AskStreamQuestion(MWContext * window_id); /* definition */
|
||||
|
||||
if (NET_URL_Type (URL_s->address) == ABOUT_TYPE_URL)
|
||||
yes_stream = 1;
|
||||
else
|
||||
yes_stream = XFE_AskStreamQuestion(window_id);
|
||||
|
||||
if(yes_stream == -1)
|
||||
{
|
||||
FREE(stream);
|
||||
FREE(obj);
|
||||
FREE(path);
|
||||
return(NULL);
|
||||
}
|
||||
}
|
||||
|
||||
if(yes_stream && view_struct->stream_block_size)
|
||||
{
|
||||
/* use popen */
|
||||
obj->fp = popen(view_struct->system_command, "w");
|
||||
|
||||
if(!obj->fp)
|
||||
{
|
||||
FE_Alert(window_id, XP_GetString(XP_ALERT_UNABLE_INVOKEVIEWER));
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
obj->stream_block_size = view_struct->stream_block_size;
|
||||
|
||||
signal(SIGPIPE, SIG_IGN);
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
dot = XP_STRRCHR(path, '.');
|
||||
|
||||
#ifdef XP_UNIX
|
||||
/* Gag. foo.ps.gz --> tmpXXXXX.ps, not tmpXXXXX.gz. */
|
||||
if (dot && fe_encoding_extensions)
|
||||
{
|
||||
int i = 0;
|
||||
while (fe_encoding_extensions [i])
|
||||
{
|
||||
if (!XP_STRCMP (dot, fe_encoding_extensions [i]))
|
||||
{
|
||||
*dot = 0;
|
||||
dot--;
|
||||
while (dot > path && *dot != '.')
|
||||
dot--;
|
||||
if (*dot != '.')
|
||||
dot = 0;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
tmp_filename = WH_TempName(xpTemporary, "MO");
|
||||
if (!tmp_filename) {
|
||||
FREEIF(stream);
|
||||
FREEIF(obj);
|
||||
return NULL;
|
||||
}
|
||||
if (dot)
|
||||
{
|
||||
char * p_tmp;
|
||||
|
||||
StrAllocCopy(obj->filename, tmp_filename);
|
||||
|
||||
/* restrict to ascii alphanumeric chars
|
||||
*
|
||||
* this fixes really bad security hole
|
||||
*/
|
||||
for(p_tmp = dot+1; *p_tmp != '\0'; p_tmp++)
|
||||
if( (*p_tmp >= '0' && *p_tmp <= '9')
|
||||
|| (*p_tmp >= 'A' && *p_tmp <= 'Z')
|
||||
|| (*p_tmp >= 'a' && *p_tmp <= 'z')
|
||||
|| (*p_tmp == '_')
|
||||
|| (*p_tmp == '+')
|
||||
|| (*p_tmp == '-'))
|
||||
{
|
||||
/* this is a good character. Allow it.
|
||||
*/
|
||||
}
|
||||
else
|
||||
{
|
||||
*p_tmp = '\0';
|
||||
break;
|
||||
}
|
||||
|
||||
StrAllocCat(obj->filename, dot);
|
||||
}
|
||||
else
|
||||
{
|
||||
StrAllocCopy(obj->filename, tmp_filename);
|
||||
}
|
||||
|
||||
FREE(path);
|
||||
XP_FREE(tmp_filename);
|
||||
|
||||
obj->fp = XP_FileOpen(obj->filename, xpTemporary, XP_FILE_WRITE);
|
||||
|
||||
TRACEMSG(("Trying to open output file: %s\n", obj->filename));
|
||||
|
||||
if(!obj->fp)
|
||||
{
|
||||
char *s = NET_ExplainErrorDetails (MK_UNABLE_TO_OPEN_TMP_FILE,
|
||||
obj->filename);
|
||||
if (s)
|
||||
{
|
||||
FE_Alert (window_id, s);
|
||||
XP_FREE (s);
|
||||
}
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* construct the command like this
|
||||
*
|
||||
* (( COMMAND ); rm %s )&
|
||||
*/
|
||||
StrAllocCopy(obj->command, "((");
|
||||
|
||||
/* this is a stream writable program that the user wants
|
||||
* to use non streaming
|
||||
*/
|
||||
if(view_struct->stream_block_size)
|
||||
StrAllocCat(obj->command, "cat %s | ");
|
||||
|
||||
StrAllocCat(obj->command, view_struct->system_command);
|
||||
|
||||
PR_snprintf(small_buf, sizeof(small_buf), "); rm %.200s )&", obj->filename);
|
||||
StrAllocCat(obj->command, small_buf);
|
||||
}
|
||||
|
||||
StrAllocCopy(obj->url, URL_s->address);
|
||||
|
||||
TRACEMSG(("Returning stream from NET_ExtViewer\n"));
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
32
mozilla/lib/libnet/cvview.h
Normal file
32
mozilla/lib/libnet/cvview.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* -*- 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 CVVIEW_H
|
||||
#define CVVIEW_H
|
||||
|
||||
extern NET_StreamClass* NET_ExtViewerConverter ( FO_Present_Types format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *window_id);
|
||||
|
||||
typedef struct _CV_ExtViewStruct {
|
||||
char * system_command;
|
||||
unsigned int stream_block_size;
|
||||
} CV_ExtViewStruct;
|
||||
|
||||
#endif /* CVVIEW_H */
|
||||
20
mozilla/lib/libnet/export.mac
Normal file
20
mozilla/lib/libnet/export.mac
Normal file
@@ -0,0 +1,20 @@
|
||||
#
|
||||
# This is a list of local files which get copied to the mozilla:dist directory
|
||||
#
|
||||
|
||||
extcache.h
|
||||
mkutils.h
|
||||
mkselect.h
|
||||
mkaccess.h
|
||||
mkautocf.h
|
||||
mkcache.h
|
||||
mkformat.h
|
||||
mkgeturl.h
|
||||
mkhelp.h
|
||||
mkstream.h
|
||||
mktcp.h
|
||||
mktrace.h
|
||||
mkpadpac.h
|
||||
mkmarimb.h
|
||||
mkparse.h
|
||||
mkimap4.h
|
||||
880
mozilla/lib/libnet/extcache.c
Normal file
880
mozilla/lib/libnet/extcache.c
Normal file
@@ -0,0 +1,880 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/* Please leave outside of ifdef for window precompiled headers */
|
||||
#include "mkutils.h"
|
||||
|
||||
#ifdef MOZILLA_CLIENT
|
||||
|
||||
/* Publicly released Netscape cache access routines.
|
||||
*
|
||||
* These routines are shared between the netscape executable
|
||||
* and the programs released as a cache developers kit.
|
||||
*
|
||||
* Created: Lou Montulli <montulli@netscape.com>, July-95.
|
||||
* Modifications/Addition: Gagan Saksena, 97
|
||||
*/
|
||||
|
||||
#ifndef EXT_DB_ROUTINES
|
||||
#include "secnav.h"
|
||||
#include "sechash.h"
|
||||
#endif
|
||||
|
||||
#include "extcache.h" /* include this for everything */
|
||||
|
||||
#ifdef EXT_DB_ROUTINES
|
||||
|
||||
#include <fcntl.h>
|
||||
#include <sys/stat.h>
|
||||
#include <assert.h>
|
||||
|
||||
typedef struct {
|
||||
int32 len;
|
||||
char *data;
|
||||
} SECItem;
|
||||
|
||||
#ifdef _sgi
|
||||
#include <sys/endian.h>
|
||||
#endif /* _sgi */
|
||||
|
||||
|
||||
/* URL methods
|
||||
*/
|
||||
#define URL_GET_METHOD 0
|
||||
#define URL_POST_METHOD 1
|
||||
#define URL_HEAD_METHOD 2
|
||||
|
||||
#endif /* DB_STORE */
|
||||
|
||||
|
||||
MODULE_PRIVATE DBT *
|
||||
net_CacheDBTDup(DBT *obj)
|
||||
{
|
||||
DBT * rv = XP_NEW(DBT);
|
||||
|
||||
if(!rv)
|
||||
return(NULL);
|
||||
|
||||
rv->size = obj->size;
|
||||
rv->data = XP_ALLOC(rv->size);
|
||||
|
||||
if(!rv->data)
|
||||
{
|
||||
FREE(rv);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
XP_MEMCPY(rv->data, obj->data, rv->size);
|
||||
|
||||
return(rv);
|
||||
|
||||
}
|
||||
|
||||
/* free the cache object
|
||||
*/
|
||||
MODULE_PRIVATE void net_freeCacheObj (net_CacheObject * cache_obj)
|
||||
{
|
||||
|
||||
FREEIF(cache_obj->address);
|
||||
FREEIF(cache_obj->post_data);
|
||||
FREEIF(cache_obj->post_headers);
|
||||
FREEIF(cache_obj->content_type);
|
||||
FREEIF(cache_obj->charset);
|
||||
FREEIF(cache_obj->content_encoding);
|
||||
FREEIF(cache_obj->page_services_url);
|
||||
FREEIF(cache_obj->filename);
|
||||
|
||||
#ifndef EXT_DB_ROUTINES
|
||||
FREEIF(cache_obj->sec_info);
|
||||
#endif
|
||||
|
||||
FREE(cache_obj);
|
||||
}
|
||||
|
||||
/* returns true if this DBT looks like a valid
|
||||
* entry. It looks at the checksum and the
|
||||
* version number to see if it's valid
|
||||
*/
|
||||
#define MAX_VALID_DBT_SIZE 10000
|
||||
|
||||
MODULE_PRIVATE Bool
|
||||
net_IsValidCacheDBT(DBT *obj)
|
||||
{
|
||||
char *cur_ptr, *max_ptr;
|
||||
uint32 len;
|
||||
|
||||
if(!obj || obj->size < 9 || obj->size > MAX_VALID_DBT_SIZE)
|
||||
return(FALSE);
|
||||
|
||||
cur_ptr = (char *)obj->data;
|
||||
max_ptr = cur_ptr+obj->size;
|
||||
|
||||
/* get the total size of the struct out of
|
||||
* the first field to check it
|
||||
*/
|
||||
COPY_INT32(&len, cur_ptr);
|
||||
cur_ptr += sizeof(int32);
|
||||
|
||||
if(len != obj->size)
|
||||
{
|
||||
TRACEMSG(("Size going in is not the same as size coming out"));
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
/* get the version number of the written structure
|
||||
*/
|
||||
if(cur_ptr > max_ptr)
|
||||
return(FALSE);
|
||||
COPY_INT32(&len, cur_ptr);
|
||||
cur_ptr += sizeof(int32);
|
||||
|
||||
if(len != CACHE_FORMAT_VERSION)
|
||||
{
|
||||
TRACEMSG(("Version of cache structure is wrong!: %d", len));
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
/* looks good to me... */
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
|
||||
/* takes a cache object and returns a malloc'd
|
||||
* (void *) suitible for passing in as a database
|
||||
* data storage object
|
||||
*/
|
||||
MODULE_PRIVATE DBT *
|
||||
net_CacheStructToDBData(net_CacheObject * old_obj)
|
||||
{
|
||||
int32 len;
|
||||
char *cur_ptr;
|
||||
void *new_obj;
|
||||
int32 total_size;
|
||||
DBT *rv;
|
||||
|
||||
rv = XP_NEW(DBT);
|
||||
|
||||
if(!rv)
|
||||
return(NULL);
|
||||
|
||||
total_size = sizeof(net_CacheObject);
|
||||
|
||||
#define ADD_STRING_SIZE(string) \
|
||||
total_size += old_obj->string ? XP_STRLEN(old_obj->string)+1 : 0
|
||||
|
||||
ADD_STRING_SIZE(address);
|
||||
total_size += old_obj->post_data_size+1;
|
||||
ADD_STRING_SIZE(post_headers);
|
||||
ADD_STRING_SIZE(content_type);
|
||||
ADD_STRING_SIZE(content_encoding);
|
||||
ADD_STRING_SIZE(charset);
|
||||
ADD_STRING_SIZE(filename);
|
||||
total_size += sizeof(uint32); /* size of secinfo */
|
||||
total_size += SECNAV_SSLSocketStatusLength(old_obj->sec_info);
|
||||
ADD_STRING_SIZE(page_services_url);
|
||||
|
||||
#undef ADD_STRING_SIZE
|
||||
|
||||
new_obj = XP_ALLOC(total_size * sizeof(char));
|
||||
|
||||
if(!new_obj)
|
||||
{
|
||||
FREE(rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
XP_MEMSET(new_obj, 0, total_size * sizeof(char));
|
||||
|
||||
/*
|
||||
* order is:
|
||||
* int32 size of the entire structure;
|
||||
*
|
||||
* int32 version of the structure format (CACHE_FORMAT_VERSION)
|
||||
*
|
||||
* time_t last_modified;
|
||||
* time_t last_accessed;
|
||||
* time_t expires;
|
||||
* uint32 content_length;
|
||||
* Bool is_netsite;
|
||||
*
|
||||
* time_t lock_date;
|
||||
*
|
||||
* char * filename;
|
||||
* int32 filename_len;
|
||||
*
|
||||
* int32 security_on;
|
||||
* unsigned char * sec_info;
|
||||
*
|
||||
* int32 method;
|
||||
*
|
||||
* # don't store address, or post_data stuff
|
||||
* # char * address;
|
||||
* # uint32 post_data_size;
|
||||
* # char * post_data;
|
||||
*
|
||||
* char * post_headers;
|
||||
* char * content_type;
|
||||
* char * content_encoding;
|
||||
* char * charset;
|
||||
*
|
||||
* Bool incomplete_file;
|
||||
* uint32 total_content_length;
|
||||
*
|
||||
* char * page_services_url;
|
||||
*
|
||||
* string lengths all include null terminators
|
||||
* all integer constants are stored as 4 bytes
|
||||
* all booleans are stored as one byte
|
||||
*/
|
||||
|
||||
/* VERY VERY IMPORTANT. Whenever the
|
||||
* format of the record structure changes
|
||||
* you must verify that the byte positions
|
||||
* in extcache.h are updated
|
||||
*/
|
||||
|
||||
#define STUFF_STRING(string) \
|
||||
{ \
|
||||
len = (old_obj->string ? XP_STRLEN(old_obj->string)+1 : 0); \
|
||||
COPY_INT32((void *)cur_ptr, &len); \
|
||||
cur_ptr = cur_ptr + sizeof(int32); \
|
||||
if(len) \
|
||||
XP_MEMCPY((void *)cur_ptr, old_obj->string, len); \
|
||||
cur_ptr += len; \
|
||||
}
|
||||
|
||||
#define STUFF_NUMBER(number) \
|
||||
{ \
|
||||
COPY_INT32((void *)cur_ptr, &old_obj->number); \
|
||||
cur_ptr = cur_ptr + sizeof(int32); \
|
||||
}
|
||||
|
||||
#define STUFF_TIMET(number) \
|
||||
{ \
|
||||
COPY_INT32((void *)cur_ptr, &old_obj->number); \
|
||||
cur_ptr = cur_ptr + sizeof(time_t); \
|
||||
}
|
||||
|
||||
#define STUFF_BOOL(bool_val) \
|
||||
{ \
|
||||
if(old_obj->bool_val) \
|
||||
((char *)(cur_ptr))[0] = 1; \
|
||||
else \
|
||||
((char *)(cur_ptr))[0] = 0; \
|
||||
cur_ptr = cur_ptr + sizeof(char); \
|
||||
}
|
||||
|
||||
cur_ptr = (char *)new_obj;
|
||||
|
||||
/* put the total size of the struct into
|
||||
* the first field so that we have
|
||||
* a cross check against corruption
|
||||
*/
|
||||
COPY_INT32((void *)cur_ptr, &total_size);
|
||||
cur_ptr = cur_ptr + sizeof(int32);
|
||||
|
||||
/* put the version number of the structure
|
||||
* format that we are using
|
||||
* By using a version string when writting
|
||||
* we can support backwards compatibility
|
||||
* in our reading code
|
||||
* (use "len" as a temp variable)
|
||||
*/
|
||||
len = CACHE_FORMAT_VERSION;
|
||||
COPY_INT32((void *)cur_ptr, &len);
|
||||
cur_ptr = cur_ptr + sizeof(int32);
|
||||
|
||||
STUFF_TIMET(last_modified);
|
||||
STUFF_TIMET(last_accessed);
|
||||
STUFF_TIMET(expires);
|
||||
STUFF_NUMBER(content_length);
|
||||
STUFF_BOOL(is_netsite);
|
||||
|
||||
STUFF_TIMET(lock_date);
|
||||
|
||||
STUFF_STRING(filename);
|
||||
STUFF_NUMBER(filename_len);
|
||||
|
||||
STUFF_BOOL(is_relative_path);
|
||||
|
||||
STUFF_NUMBER(security_on);
|
||||
|
||||
#ifndef EXT_DB_ROUTINES
|
||||
/* save the security info */
|
||||
if ( old_obj->sec_info ) {
|
||||
len = SECNAV_SSLSocketStatusLength(old_obj->sec_info);
|
||||
COPY_INT32((void *)cur_ptr, &len);
|
||||
cur_ptr = cur_ptr + sizeof(int32);
|
||||
|
||||
XP_MEMCPY((void *)cur_ptr, old_obj->sec_info, len);
|
||||
cur_ptr += len;
|
||||
} else
|
||||
#endif
|
||||
{
|
||||
len = 0;
|
||||
COPY_INT32((void *)cur_ptr, &len);
|
||||
cur_ptr = cur_ptr + sizeof(int32);
|
||||
}
|
||||
|
||||
STUFF_NUMBER(method);
|
||||
|
||||
#ifdef STORE_ADDRESS_AND_POST_DATA
|
||||
|
||||
STUFF_STRING(address);
|
||||
STUFF_NUMBER(post_data_size);
|
||||
|
||||
/* post_data
|
||||
* this is special since it not necessarily a string
|
||||
*/
|
||||
if(old_obj->post_data_size)
|
||||
{
|
||||
XP_MEMCPY(cur_ptr, old_obj->post_data, old_obj->post_data_size+1);
|
||||
cur_ptr += old_obj->post_data_size+1;
|
||||
}
|
||||
|
||||
#endif /* STORE_ADDRESS_AND_POST_DATA */
|
||||
|
||||
STUFF_STRING(post_headers);
|
||||
|
||||
STUFF_STRING(content_type);
|
||||
STUFF_STRING(content_encoding);
|
||||
STUFF_STRING(charset);
|
||||
|
||||
STUFF_BOOL(incomplete_file);
|
||||
STUFF_NUMBER(real_content_length);
|
||||
|
||||
STUFF_STRING(page_services_url);
|
||||
|
||||
#undef STUFF_STRING
|
||||
#undef STUFF_NUMBER
|
||||
#undef STUFF_BOOL
|
||||
|
||||
rv->data = new_obj;
|
||||
rv->size = total_size;
|
||||
|
||||
return(rv);
|
||||
|
||||
}
|
||||
|
||||
/* takes a database storage object and returns a malloc'd
|
||||
* cache data object. The cache object needs all of
|
||||
* it's parts free'd.
|
||||
*
|
||||
* returns NULL on parse error
|
||||
*/
|
||||
MODULE_PRIVATE net_CacheObject *
|
||||
net_DBDataToCacheStruct(DBT * db_obj)
|
||||
{
|
||||
net_CacheObject * rv = XP_NEW(net_CacheObject);
|
||||
char * cur_ptr;
|
||||
char * max_ptr;
|
||||
uint32 len;
|
||||
int32 version;
|
||||
|
||||
if(!rv)
|
||||
return NULL;
|
||||
|
||||
XP_MEMSET(rv, 0, sizeof(net_CacheObject));
|
||||
|
||||
/* if any strings are larger than this then
|
||||
* there was a serious database error
|
||||
*/
|
||||
#define MAX_HUGE_STRING_SIZE 10000
|
||||
|
||||
#define RETRIEVE_STRING(string) \
|
||||
{ \
|
||||
if(cur_ptr > max_ptr) \
|
||||
{ \
|
||||
net_freeCacheObj(rv); \
|
||||
return(NULL); \
|
||||
} \
|
||||
COPY_INT32(&len, cur_ptr); \
|
||||
cur_ptr += sizeof(int32); \
|
||||
if(len) \
|
||||
{ \
|
||||
if(len > MAX_HUGE_STRING_SIZE) \
|
||||
{ \
|
||||
net_freeCacheObj(rv); \
|
||||
return(NULL); \
|
||||
} \
|
||||
rv->string = (char*)XP_ALLOC(len); \
|
||||
if(!rv->string) \
|
||||
{ \
|
||||
net_freeCacheObj(rv); \
|
||||
return(NULL); \
|
||||
} \
|
||||
XP_MEMCPY(rv->string, cur_ptr, len); \
|
||||
cur_ptr += len; \
|
||||
} \
|
||||
}
|
||||
|
||||
#define RETRIEVE_NUMBER(number) \
|
||||
{ \
|
||||
if(cur_ptr > max_ptr) \
|
||||
return(rv); \
|
||||
COPY_INT32(&rv->number, cur_ptr); \
|
||||
cur_ptr += sizeof(int32); \
|
||||
}
|
||||
|
||||
#define RETRIEVE_TIMET(number) \
|
||||
{ \
|
||||
if(cur_ptr > max_ptr) \
|
||||
return(rv); \
|
||||
COPY_INT32(&rv->number, cur_ptr); \
|
||||
cur_ptr += sizeof(time_t); \
|
||||
}
|
||||
|
||||
#define RETRIEVE_BOOL(bool) \
|
||||
{ \
|
||||
if(cur_ptr > max_ptr) \
|
||||
return(rv); \
|
||||
if(((char *)(cur_ptr))[0]) \
|
||||
rv->bool = TRUE; \
|
||||
else \
|
||||
rv->bool = FALSE; \
|
||||
cur_ptr += sizeof(char); \
|
||||
}
|
||||
|
||||
cur_ptr = (char *)db_obj->data;
|
||||
|
||||
max_ptr = cur_ptr+db_obj->size;
|
||||
|
||||
/* get the total size of the struct out of
|
||||
* the first field to check it
|
||||
*/
|
||||
COPY_INT32(&len, cur_ptr);
|
||||
cur_ptr += sizeof(int32);
|
||||
|
||||
if(len != db_obj->size)
|
||||
{
|
||||
TRACEMSG(("Size going in is not the same as size coming out"));
|
||||
FREE(rv);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
/* get the version number of the written structure
|
||||
*/
|
||||
if(cur_ptr > max_ptr)
|
||||
return(rv);
|
||||
COPY_INT32(&version, cur_ptr);
|
||||
cur_ptr += sizeof(int32);
|
||||
|
||||
if(version != CACHE_FORMAT_VERSION)
|
||||
{
|
||||
TRACEMSG(("Version of cache structure is wrong!: %d", version));
|
||||
FREE(rv);
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
RETRIEVE_TIMET(last_modified);
|
||||
RETRIEVE_TIMET(last_accessed);
|
||||
RETRIEVE_TIMET(expires);
|
||||
RETRIEVE_NUMBER(content_length);
|
||||
RETRIEVE_BOOL(is_netsite);
|
||||
|
||||
RETRIEVE_TIMET(lock_date);
|
||||
|
||||
RETRIEVE_STRING(filename);
|
||||
RETRIEVE_NUMBER(filename_len);
|
||||
|
||||
RETRIEVE_BOOL(is_relative_path);
|
||||
|
||||
RETRIEVE_NUMBER(security_on);
|
||||
|
||||
/* security info */
|
||||
if(cur_ptr > max_ptr)
|
||||
return(rv);
|
||||
COPY_INT32(&len, cur_ptr);
|
||||
cur_ptr += sizeof(int32);
|
||||
|
||||
if ( len == 0 ) {
|
||||
rv->sec_info = NULL;
|
||||
} else {
|
||||
rv->sec_info = XP_ALLOC(len);
|
||||
if ( rv->sec_info == NULL ) {
|
||||
return(rv);
|
||||
}
|
||||
|
||||
XP_MEMCPY(rv->sec_info, cur_ptr, len);
|
||||
cur_ptr += len;
|
||||
}
|
||||
|
||||
|
||||
RETRIEVE_NUMBER(method);
|
||||
|
||||
#ifdef STORE_ADDRESS_AND_POST_DATA
|
||||
|
||||
RETRIEVE_STRING(address);
|
||||
RETRIEVE_NUMBER(post_data_size);
|
||||
|
||||
/* post_data
|
||||
* this is special since it not necessarily a string
|
||||
*/
|
||||
if(rv->post_data_size)
|
||||
{
|
||||
rv->post_data = XP_ALLOC(rv->post_data_size+1);
|
||||
if(rv->post_data)
|
||||
XP_MEMCPY(rv->post_data, cur_ptr, rv->post_data_size+1);
|
||||
cur_ptr += rv->post_data_size+1;
|
||||
}
|
||||
|
||||
#endif /* STORE_ADDRESS_AND_POST_DATA */
|
||||
|
||||
RETRIEVE_STRING(post_headers);
|
||||
|
||||
RETRIEVE_STRING(content_type);
|
||||
RETRIEVE_STRING(content_encoding);
|
||||
RETRIEVE_STRING(charset);
|
||||
|
||||
RETRIEVE_BOOL(incomplete_file);
|
||||
RETRIEVE_NUMBER(real_content_length);
|
||||
|
||||
RETRIEVE_STRING(page_services_url);
|
||||
#undef RETRIEVE_STRING
|
||||
#undef RETRIEVE_NUMBER
|
||||
#undef RETRIEVE_BOOL
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
#if defined(DEBUG) && defined(UNIX)
|
||||
int
|
||||
cache_test_me()
|
||||
{
|
||||
|
||||
net_CacheObject test;
|
||||
net_CacheObject *rv;
|
||||
int32 total_size;
|
||||
DBT *db_obj;
|
||||
|
||||
XP_MEMSET(&test, 0, sizeof(net_CacheObject));
|
||||
StrAllocCopy(test.address, "test1");
|
||||
db_obj = net_CacheStructToDBData(&test);
|
||||
rv = net_DBDataToCacheStruct(db_obj);
|
||||
printf("test1: %s\n", rv->address);
|
||||
|
||||
XP_MEMSET(&test, 0, sizeof(net_CacheObject));
|
||||
StrAllocCopy(test.address, "test2");
|
||||
StrAllocCopy(test.charset, "test2");
|
||||
db_obj = net_CacheStructToDBData(&test);
|
||||
rv = net_DBDataToCacheStruct(db_obj);
|
||||
printf("test2: %s %s\n", rv->address, rv->charset);
|
||||
|
||||
XP_MEMSET(&test, 0, sizeof(net_CacheObject));
|
||||
StrAllocCopy(test.address, "test3");
|
||||
StrAllocCopy(test.charset, "test3");
|
||||
test.content_length = 3 ;
|
||||
test.method = 3 ;
|
||||
test.is_netsite = 3 ;
|
||||
db_obj = net_CacheStructToDBData(&test);
|
||||
rv = net_DBDataToCacheStruct(db_obj);
|
||||
printf("test3: %s %s %d %d %s\n",
|
||||
rv->address, rv->charset,
|
||||
rv->content_length, rv->method,
|
||||
(rv->is_netsite == 3 ? "TRUE" : "FALSE"));
|
||||
|
||||
}
|
||||
#endif
|
||||
|
||||
/* generates a key for use in the cache database
|
||||
* from a CacheObject struct
|
||||
*
|
||||
* Key is based on the address and the post_data
|
||||
*
|
||||
* looks like:
|
||||
* size checksum | size of address | ADDRESS | size of post data | POST DATA
|
||||
*/
|
||||
MODULE_PRIVATE DBT *
|
||||
net_GenCacheDBKey(char *address, char *post_data, int32 post_data_size)
|
||||
{
|
||||
DBT *rv = XP_NEW(DBT);
|
||||
char *hash;
|
||||
char *data_ptr;
|
||||
int32 str_len;
|
||||
int32 size;
|
||||
|
||||
#define MD5_HASH_SIZE 16 /* always 16 due to md5 hash type */
|
||||
|
||||
if(!rv)
|
||||
return(NULL);
|
||||
|
||||
if(!address)
|
||||
{
|
||||
XP_ASSERT(0);
|
||||
rv->size = 0;
|
||||
return(rv);
|
||||
}
|
||||
|
||||
hash = XP_STRCHR(address, '#');
|
||||
|
||||
/* don't include '#' in a key */
|
||||
if(hash)
|
||||
*hash = '\0';
|
||||
|
||||
str_len = XP_STRLEN(address)+1;
|
||||
|
||||
size = sizeof(int32); /* for check sum */
|
||||
size += sizeof(int32); /* for size of address */
|
||||
size += str_len; /* for address string */
|
||||
size += sizeof(int32); /* for size of post_data */
|
||||
|
||||
if(post_data_size)
|
||||
size += MD5_HASH_SIZE;
|
||||
|
||||
rv->size = size;
|
||||
rv->data = XP_ALLOC(size);
|
||||
|
||||
if(!rv->data)
|
||||
{
|
||||
FREE(rv);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
data_ptr = (char *) rv->data;
|
||||
|
||||
/* put in the checksum size */
|
||||
COPY_INT32(data_ptr, &size);
|
||||
data_ptr = data_ptr + sizeof(int32);
|
||||
|
||||
/* put in the size of the address string */
|
||||
COPY_INT32(data_ptr, &str_len);
|
||||
data_ptr = data_ptr + sizeof(int32);
|
||||
|
||||
/* put in the address string data */
|
||||
XP_MEMCPY(data_ptr, address, str_len);
|
||||
data_ptr = data_ptr + str_len;
|
||||
|
||||
/* set the address back to it's original form */
|
||||
if(hash)
|
||||
*hash = '#';
|
||||
|
||||
/* put in the size of the post data */
|
||||
if(post_data_size)
|
||||
{
|
||||
int32 size_of_md5 = MD5_HASH_SIZE;
|
||||
unsigned char post_data_hash[MD5_HASH_SIZE];
|
||||
|
||||
MD5_HashBuf(post_data_hash, (unsigned char*)post_data, post_data_size);
|
||||
|
||||
COPY_INT32(data_ptr, &size_of_md5);
|
||||
data_ptr = data_ptr + sizeof(int32);
|
||||
|
||||
/* put in the post data if there is any */
|
||||
XP_MEMCPY(data_ptr, post_data_hash, sizeof(post_data_hash));
|
||||
}
|
||||
else
|
||||
{
|
||||
COPY_INT32(data_ptr, &post_data_size);
|
||||
data_ptr = data_ptr + sizeof(int32);
|
||||
}
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
/* returns a static string that contains the
|
||||
* URL->address of the key
|
||||
*
|
||||
* returns NULL on error
|
||||
*/
|
||||
MODULE_PRIVATE char *
|
||||
net_GetAddressFromCacheKey(DBT *key)
|
||||
{
|
||||
uint32 size;
|
||||
char *data;
|
||||
|
||||
/* check for minimum size */
|
||||
if(key->size < 10)
|
||||
return(NULL);
|
||||
|
||||
/* validate size checksum */
|
||||
data = (char *)key->data;
|
||||
COPY_INT32(&size, data);
|
||||
data += sizeof(int32);
|
||||
|
||||
if(size != key->size)
|
||||
return(NULL);
|
||||
|
||||
/* get size of address string */
|
||||
COPY_INT32(&size, data);
|
||||
data += sizeof(int32);
|
||||
|
||||
/* make sure it's a valid c string */
|
||||
if(data[size] != '\0')
|
||||
return(NULL);
|
||||
|
||||
/* it's valid return it */
|
||||
return(data);
|
||||
}
|
||||
|
||||
|
||||
/* checks a date within a DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns 0 on error
|
||||
*/
|
||||
MODULE_PRIVATE time_t
|
||||
net_GetTimeInCacheDBT(DBT *data, int byte_position)
|
||||
{
|
||||
time_t date;
|
||||
char *ptr = (char *)data->data;
|
||||
|
||||
if(data->size < byte_position+sizeof(time_t))
|
||||
return(0);
|
||||
|
||||
if(!net_IsValidCacheDBT(data))
|
||||
return(0);
|
||||
|
||||
COPY_INT32(&date, ptr+byte_position);
|
||||
|
||||
/* TRACEMSG(("Got date from cache DBT: %d", date)); */
|
||||
|
||||
return(date);
|
||||
|
||||
}
|
||||
|
||||
/* Sets a date within a DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns 0 on error
|
||||
*/
|
||||
MODULE_PRIVATE void
|
||||
net_SetTimeInCacheDBT(DBT *data, int byte_position, time_t date)
|
||||
{
|
||||
char *ptr = (char *)data->data;
|
||||
|
||||
if(data->size < byte_position+sizeof(time_t))
|
||||
return;
|
||||
|
||||
if(!net_IsValidCacheDBT(data))
|
||||
return;
|
||||
|
||||
COPY_INT32(ptr+byte_position, &date);
|
||||
|
||||
return;
|
||||
|
||||
}
|
||||
|
||||
/* Gets the filename within a cache DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns NULL on error
|
||||
*/
|
||||
#define MAX_FILE_SIZE 2048
|
||||
MODULE_PRIVATE char *
|
||||
net_GetFilenameInCacheDBT(DBT *data)
|
||||
{
|
||||
int32 size;
|
||||
char *rv;
|
||||
char *ptr = (char*)data->data;
|
||||
|
||||
if(data->size < FILENAME_BYTE_POSITION)
|
||||
return(NULL);
|
||||
|
||||
if(!net_IsValidCacheDBT(data))
|
||||
return(0);
|
||||
|
||||
COPY_INT32(&size, ptr+FILENAME_SIZE_BYTE_POSITION);
|
||||
|
||||
if(data->size < FILENAME_BYTE_POSITION+size
|
||||
|| size > MAX_FILE_SIZE)
|
||||
return(NULL);
|
||||
|
||||
rv = (char *)XP_ALLOC(size);
|
||||
if(!rv)
|
||||
return(NULL);
|
||||
XP_MEMCPY(rv, ptr+FILENAME_BYTE_POSITION, size);
|
||||
|
||||
TRACEMSG(("Got filename: %s from DBT", rv));
|
||||
|
||||
return(rv);
|
||||
}
|
||||
|
||||
/* Gets a int32 within a DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns 0 on error
|
||||
*/
|
||||
MODULE_PRIVATE time_t
|
||||
net_GetInt32InCacheDBT(DBT *data, int byte_position)
|
||||
{
|
||||
int32 num;
|
||||
char *ptr = (char *)data->data;
|
||||
|
||||
if(!net_IsValidCacheDBT(data))
|
||||
return(0);
|
||||
|
||||
if(data->size < byte_position+sizeof(time_t))
|
||||
return(0);
|
||||
|
||||
COPY_INT32(&num, ptr+byte_position);
|
||||
|
||||
/* TRACEMSG(("Got int32 from cache DBT: %d", num)); */
|
||||
|
||||
return(num);
|
||||
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
net_FreeCacheDBTdata(DBT *stuff)
|
||||
{
|
||||
if(stuff)
|
||||
{
|
||||
FREE(stuff->data);
|
||||
FREE(stuff);
|
||||
}
|
||||
}
|
||||
|
||||
/* takes a database storage object and returns an un-malloc'd
|
||||
* cache data object. The structure returned has pointers
|
||||
* directly into the database memory and are only valid
|
||||
* until the next call to any database function
|
||||
*
|
||||
* do not free anything returned by this structure
|
||||
*/
|
||||
MODULE_PRIVATE net_CacheObject *
|
||||
net_Fast_DBDataToCacheStruct(DBT *obj)
|
||||
{
|
||||
static net_CacheObject *rv=0;
|
||||
|
||||
/* free any previous one */
|
||||
if(rv)
|
||||
net_freeCacheObj(rv);
|
||||
|
||||
rv = net_DBDataToCacheStruct(obj);
|
||||
|
||||
return(rv);
|
||||
|
||||
}
|
||||
|
||||
#endif /* MOZILLA_CLIENT */
|
||||
273
mozilla/lib/libnet/extcache.h
Normal file
273
mozilla/lib/libnet/extcache.h
Normal file
@@ -0,0 +1,273 @@
|
||||
/* -*- 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 EXT_CACHE_H
|
||||
#define EXT_CACHE_H
|
||||
|
||||
#ifndef EXT_DB_ROUTINES
|
||||
#include "mcom_db.h"
|
||||
#endif
|
||||
|
||||
#ifdef EXT_DB_ROUTINES
|
||||
#define Bool char
|
||||
#define uint32 unsigned int
|
||||
#define int32 int
|
||||
#define XP_NEW(structure) ((structure *) malloc(sizeof(structure)))
|
||||
#define XP_ALLOC (void *) malloc
|
||||
#define XP_MEMCPY memcpy
|
||||
#define XP_MEMSET memset
|
||||
#define TRACEMSG(x) printf x
|
||||
#define FREEIF(x) do { if(x) free(x); } while(0)
|
||||
#define FREE free
|
||||
#define XP_STRLEN strlen
|
||||
#define XP_STRCHR strchr
|
||||
#define XP_STRCMP strcmp
|
||||
#define XP_ASSERT assert
|
||||
#define MODULE_PRIVATE
|
||||
#define PRIVATE static
|
||||
#define TRUE !0
|
||||
#define FALSE 0
|
||||
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <db.h>
|
||||
#endif
|
||||
|
||||
#ifndef EXT_DB_ROUTINES
|
||||
#include "mkutils.h"
|
||||
|
||||
#ifndef NSPR20
|
||||
#include "prosdep.h" /* for IS_LITTLE_ENDIAN / IS_BIG_ENDIAN */
|
||||
#else
|
||||
#include "prtypes.h"
|
||||
#endif
|
||||
|
||||
#endif /* EXT_DB_ROUTINES */
|
||||
|
||||
#if !defined(IS_LITTLE_ENDIAN) && !defined(IS_BIG_ENDIAN)
|
||||
ERROR! Must have a byte order
|
||||
#endif
|
||||
|
||||
#ifdef IS_LITTLE_ENDIAN
|
||||
#define COPY_INT32(_a,_b) XP_MEMCPY(_a, _b, sizeof(int32));
|
||||
#else
|
||||
#define COPY_INT32(_a,_b) /* swap */ \
|
||||
do { \
|
||||
((char *)(_a))[0] = ((char *)(_b))[3]; \
|
||||
((char *)(_a))[1] = ((char *)(_b))[2]; \
|
||||
((char *)(_a))[2] = ((char *)(_b))[1]; \
|
||||
((char *)(_a))[3] = ((char *)(_b))[0]; \
|
||||
} while(0)
|
||||
#endif
|
||||
|
||||
#define EXT_CACHE_NAME_STRING "INT_ExternalCacheNameString"
|
||||
|
||||
/* Internal WARNING!! Some slots of this structure
|
||||
* are shared with URL_Struct and
|
||||
* History_entry. If you add a slot, decide whether it needs to be shared
|
||||
* as well.
|
||||
*/
|
||||
typedef struct _net_CacheObject {
|
||||
time_t last_modified;
|
||||
time_t last_accessed;
|
||||
time_t expires;
|
||||
Bool is_netsite;
|
||||
uint32 content_length;
|
||||
|
||||
char * filename; /* cache file name */
|
||||
int32 filename_len; /* optimization */
|
||||
Bool is_relative_path; /* is the path relative? */
|
||||
|
||||
/* Security information */
|
||||
int32 security_on; /* is security on? */
|
||||
unsigned char *sec_info;
|
||||
|
||||
time_t lock_date; /* the file is locked if this
|
||||
* is non-zero. The date
|
||||
* represents the time the
|
||||
* lock was put in place.
|
||||
* Locks are only valid for
|
||||
* one session
|
||||
*/
|
||||
|
||||
int32 method;
|
||||
char * address;
|
||||
uint32 post_data_size;
|
||||
char * post_data;
|
||||
char * post_headers;
|
||||
char * content_type;
|
||||
char * content_encoding;
|
||||
char * charset;
|
||||
|
||||
Bool incomplete_file; /* means that the whole
|
||||
* file is not there.
|
||||
* This can only be true
|
||||
* if the server supports byteranges
|
||||
*/
|
||||
uint32 real_content_length; /* the whole content length
|
||||
* i.e. the server size of a truncated
|
||||
* client file
|
||||
*/
|
||||
char * page_services_url;
|
||||
char * etag; /* HTTP/1.1 Etag */
|
||||
|
||||
} net_CacheObject;
|
||||
|
||||
/* this is the version number of the cache database entry.
|
||||
* It should be incremented in integer ingrements up
|
||||
* to MAXINT32
|
||||
*/
|
||||
#define CACHE_FORMAT_VERSION 5
|
||||
|
||||
/* these defines specify the exact byte position
|
||||
* of the first 4 elements in the DBT data struct
|
||||
* Change these if you change the order of entry into
|
||||
* the DBT
|
||||
*/
|
||||
#define LAST_MODIFIED_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)
|
||||
#define LAST_ACCESSED_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)+sizeof(time_t)
|
||||
#define EXPIRES_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t)
|
||||
#define CONTENT_LENGTH_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
|
||||
+sizeof(time_t)
|
||||
#define IS_NETSITE_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
|
||||
+sizeof(time_t)+sizeof(int32)
|
||||
|
||||
#define LOCK_DATE_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
|
||||
+sizeof(time_t)+sizeof(int32)+sizeof(char)
|
||||
|
||||
#define FILENAME_SIZE_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
|
||||
+sizeof(time_t)+sizeof(uint32)+sizeof(char)+sizeof(time_t)
|
||||
#define FILENAME_BYTE_POSITION \
|
||||
sizeof(int32)+sizeof(int32)+sizeof(time_t)+sizeof(time_t) \
|
||||
+sizeof(time_t)+sizeof(uint32)+sizeof(char)+sizeof(time_t) \
|
||||
+sizeof(int32)
|
||||
|
||||
/* generates a key for use in the cache database
|
||||
* from a CacheObject struct
|
||||
*
|
||||
* Key is based on the address and the post_data
|
||||
*/
|
||||
extern DBT *
|
||||
net_GenCacheDBKey(char *address, char *post_data, int32 post_data_size);
|
||||
|
||||
/* returns a static string that contains the
|
||||
* URL->address of the key
|
||||
*
|
||||
* returns NULL on error
|
||||
*/
|
||||
extern char *
|
||||
net_GetAddressFromCacheKey(DBT *key);
|
||||
|
||||
|
||||
/* allocs and copies a new DBT from an existing DBT
|
||||
*/
|
||||
extern DBT * net_CacheDBTDup(DBT *obj);
|
||||
|
||||
/* free the cache object
|
||||
*/
|
||||
extern void net_freeCacheObj (net_CacheObject * cache_obj);
|
||||
|
||||
/* takes a cache object and returns a malloc'd
|
||||
* (void *) suitible for passing in as a database
|
||||
* data storage object
|
||||
*/
|
||||
extern DBT * net_CacheStructToDBData(net_CacheObject * old_obj);
|
||||
|
||||
/* takes a database storage object and returns a malloc'd
|
||||
* cache data object. The cache object needs all of
|
||||
* it's parts free'd.
|
||||
*
|
||||
* returns NULL on parse error
|
||||
*/
|
||||
extern net_CacheObject * net_DBDataToCacheStruct(DBT * db_obj);
|
||||
|
||||
/* checks a date within a DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns 0 on error
|
||||
*/
|
||||
extern time_t net_GetTimeInCacheDBT(DBT *data, int byte_position);
|
||||
|
||||
/* Sets a date within a DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns 0 on error
|
||||
*/
|
||||
extern void net_SetTimeInCacheDBT(DBT *data, int byte_position, time_t date);
|
||||
|
||||
/* Gets the filename within a cache DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns NULL on error
|
||||
*/
|
||||
extern char * net_GetFilenameInCacheDBT(DBT *data);
|
||||
|
||||
/* Gets a int32 within a DBT struct so
|
||||
* that we don't have to convert it into a CacheObject
|
||||
*
|
||||
* This works because of the fixed length record format
|
||||
* of the first part of the specific DBT format I'm
|
||||
* using
|
||||
*
|
||||
* returns 0 on error
|
||||
*/
|
||||
extern time_t net_GetInt32InCacheDBT(DBT *data, int byte_position);
|
||||
|
||||
/* free's a DBT struct
|
||||
*/
|
||||
extern void net_FreeCacheDBTdata(DBT *stuff);
|
||||
|
||||
/* stores a cache object in the DBM database
|
||||
*/
|
||||
extern void net_ExtCacheStore(DB *database, net_CacheObject * obj);
|
||||
|
||||
/* takes a database storage object and returns an un-malloc'd
|
||||
* cache data object. The structure returned has pointers
|
||||
* directly into the database memory and are only valid
|
||||
* until the next call to any database function
|
||||
*
|
||||
* do not free anything returned by this structure
|
||||
*/
|
||||
extern net_CacheObject * net_Fast_DBDataToCacheStruct(DBT *obj);
|
||||
|
||||
/* returns true if this DBT looks like a valid
|
||||
* entry. It looks at the checksum and the
|
||||
* version number to see if it's valid
|
||||
*/
|
||||
extern Bool net_IsValidCacheDBT(DBT *obj);
|
||||
|
||||
#endif /* EXT_CACHE_H */
|
||||
510
mozilla/lib/libnet/htmparse.c
Normal file
510
mozilla/lib/libnet/htmparse.c
Normal file
@@ -0,0 +1,510 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*** htmparse.c ***************************************************/
|
||||
/* description: html parser */
|
||||
|
||||
|
||||
/********************************************************************
|
||||
|
||||
$Revision: 3.1 $
|
||||
$Date: 1998-03-28 03:31:31 $
|
||||
|
||||
*********************************************************************/
|
||||
|
||||
#include "xp.h"
|
||||
#include "xp_str.h"
|
||||
#include "htmparse.h"
|
||||
#include "prtypes.h"
|
||||
#include "pa_tags.h"
|
||||
#include "pa_parse.h" /* for pa_tokenize_tag */
|
||||
#include "prmem.h"
|
||||
#if 0
|
||||
#include "prio.h" /* for test only */
|
||||
#include <stdio.h> /* for test only */
|
||||
#endif
|
||||
|
||||
typedef char ParseState;
|
||||
|
||||
/* states of the parser */
|
||||
#define PS_START 0 /* starting state */
|
||||
#define PS_BETWEEN_TAGS 1 /* characters not enclosed by < > */
|
||||
#define PS_TAG_NAME 2
|
||||
#define PS_EMPTY_TAG 3
|
||||
#define PS_CLOSE_BRACKET 4
|
||||
#define PS_ATTRIBUTE 5
|
||||
#define PS_EQUALS 6
|
||||
#define PS_VALUE 7
|
||||
#define PS_START_COMMENT 8
|
||||
#define PS_END_COMMENT 9
|
||||
|
||||
typedef struct _CRAWL_TagStruc {
|
||||
char *name;
|
||||
intn token;
|
||||
char **attributeNames;
|
||||
char **attributeValues; /* max length of html attribute is 1024 chars */
|
||||
uint16 sizeNames;
|
||||
uint16 numNames;
|
||||
uint16 sizeValues;
|
||||
uint16 numValues;
|
||||
PRBool emptyTagp;
|
||||
PRBool endTagp;
|
||||
} CRAWL_TagStruc;
|
||||
|
||||
/* maintains state of parser */
|
||||
typedef struct _CRAWL_ParseObjStruc {
|
||||
ParseState state;
|
||||
CRAWL_Tag tag;
|
||||
char *data;
|
||||
uint16 dataLen;
|
||||
uint16 dataSize;
|
||||
char *str;
|
||||
uint16 strLen;
|
||||
uint16 strSize;
|
||||
char prev1;
|
||||
char prev2;
|
||||
char inQuote; /* current quote character. when not in quote, value is '\0' */
|
||||
PRBool inComment; /* we don't support comment nesting anymore */
|
||||
PRBool inScript; /* inside <SCRIPT> and </SCRIPT> */
|
||||
PRBool skipWhitespace;
|
||||
PRBool isRDF;
|
||||
} CRAWL_ParseObjStruc;
|
||||
|
||||
/* prototypes */
|
||||
static CRAWL_Tag crawl_makeTag();
|
||||
static void crawl_recycleTag(CRAWL_Tag tag);
|
||||
static void crawl_destroyTag(CRAWL_Tag tag);
|
||||
static void crawl_recycleParseObj(CRAWL_ParseObj obj);
|
||||
|
||||
int crawl_appendString(char **str, uint16 *len, uint16 *size, char c);
|
||||
int crawl_appendStringList(char ***list_p, uint16 *len, uint16 *size, char *str);
|
||||
|
||||
/* accessors */
|
||||
PR_IMPLEMENT(CRAWL_Tag) CRAWL_GetTagParsed(CRAWL_ParseObj obj) {
|
||||
if (obj->data != NULL) return NULL;
|
||||
else return obj->tag;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char*) CRAWL_GetDataParsed(CRAWL_ParseObj obj) {
|
||||
if (obj->data != NULL) return obj->data;
|
||||
else return NULL;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char*) CRAWL_GetTagName(CRAWL_Tag tag) {
|
||||
return tag->name;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(intn) CRAWL_GetTagToken(CRAWL_Tag tag) {
|
||||
return tag->token;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PRBool) CRAWL_IsEmptyTag(CRAWL_Tag tag) {
|
||||
return tag->emptyTagp;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(PRBool) CRAWL_IsEndTag(CRAWL_Tag tag) {
|
||||
return tag->endTagp;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(uint16) CRAWL_GetNumberOfAttributes(CRAWL_Tag tag) {
|
||||
return tag->numNames;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char*) CRAWL_GetNthAttributeName(CRAWL_Tag tag, uint16 n) {
|
||||
return *(tag->attributeNames + n);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char*) CRAWL_GetNthAttributeValue(CRAWL_Tag tag, uint16 n) {
|
||||
return *(tag->attributeValues + n);
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(char*) CRAWL_GetAttributeValue(CRAWL_Tag tag, char *attributeName) {
|
||||
int count = 0;
|
||||
while (count < tag->numNames) {
|
||||
if (XP_STRCASECMP(attributeName, *(tag->attributeNames + count)) == 0)
|
||||
return *(tag->attributeValues + count);
|
||||
count++;
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static CRAWL_Tag crawl_makeTag() {
|
||||
CRAWL_Tag tag = PR_NEWZAP(CRAWL_TagStruc);
|
||||
if (tag == NULL) return NULL;
|
||||
tag->sizeNames = tag->sizeValues = 4;
|
||||
tag->attributeNames = (char**)PR_MALLOC(sizeof(char*) * tag->sizeNames);
|
||||
if (tag->attributeNames == NULL) return NULL;
|
||||
tag->attributeValues = (char**)PR_MALLOC(sizeof(char*) * tag->sizeValues);
|
||||
if (tag->attributeValues == NULL) return NULL;
|
||||
return tag;
|
||||
}
|
||||
|
||||
static void crawl_recycleTag(CRAWL_Tag tag) {
|
||||
int count;
|
||||
if (tag->name != NULL) PR_Free(tag->name);
|
||||
tag->name = NULL;
|
||||
for (count = 0; count < tag->numNames; count++) {
|
||||
PR_Free(*(tag->attributeNames + count));
|
||||
}
|
||||
tag->numNames = 0;
|
||||
for (count = 0; count < tag->numValues; count++) {
|
||||
PR_Free(*(tag->attributeValues + count));
|
||||
}
|
||||
tag->numValues = 0;
|
||||
tag->emptyTagp = PR_FALSE;
|
||||
tag->endTagp = PR_FALSE;
|
||||
}
|
||||
|
||||
static void crawl_destroyTag(CRAWL_Tag tag) {
|
||||
crawl_recycleTag(tag);
|
||||
if (tag->attributeNames != NULL) PR_Free(tag->attributeNames);
|
||||
if (tag->attributeValues != NULL) PR_Free(tag->attributeValues);
|
||||
PR_Free(tag);
|
||||
}
|
||||
|
||||
static void crawl_recycleParseObj(CRAWL_ParseObj obj) {
|
||||
crawl_recycleTag(obj->tag);
|
||||
if (obj->data != NULL) PR_Free(obj->data);
|
||||
obj->data = NULL;
|
||||
obj->dataLen = obj->dataSize = 0;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(CRAWL_ParseObj) CRAWL_MakeParseObj() {
|
||||
CRAWL_ParseObj obj = PR_NEWZAP(CRAWL_ParseObjStruc);
|
||||
if (obj == NULL) return NULL;
|
||||
obj->tag = crawl_makeTag();
|
||||
if (obj->tag == NULL) {
|
||||
PR_Free(obj);
|
||||
return NULL;
|
||||
}
|
||||
return obj;
|
||||
}
|
||||
|
||||
PR_IMPLEMENT(void) CRAWL_DestroyParseObj(CRAWL_ParseObj obj) {
|
||||
crawl_destroyTag(obj->tag);
|
||||
if (obj->data != NULL) PR_Free(obj->data);
|
||||
obj->data = NULL;
|
||||
obj->dataLen = obj->dataSize = 0;
|
||||
if (obj->str != NULL) PR_Free(obj->str);
|
||||
obj->str = NULL;
|
||||
obj->strLen = obj->strSize = 0;
|
||||
PR_Free(obj);
|
||||
}
|
||||
|
||||
#define STRING_EXPANSION_INCREMENT 16
|
||||
/* returns 0 if no error, -1 if no memory */
|
||||
int crawl_appendString(char **str, uint16 *len, uint16 *size, char c) {
|
||||
if (*len == *size) {
|
||||
char *newName = (char*)PR_MALLOC(*size + STRING_EXPANSION_INCREMENT);
|
||||
char *old = *str;
|
||||
if (newName == NULL) return -1;
|
||||
XP_MEMCPY(newName, *str, *size);
|
||||
*str = newName;
|
||||
if (old != NULL) PR_Free(old);
|
||||
*size += STRING_EXPANSION_INCREMENT;
|
||||
}
|
||||
*(*str + *len) = c;
|
||||
++(*len);
|
||||
return 0;
|
||||
}
|
||||
|
||||
#define STRINGLIST_EXPANSION_INCREMENT 8
|
||||
|
||||
/* returns 0 if no error, -1 if no memory */
|
||||
int crawl_appendStringList(char ***list_p, uint16 *len, uint16 *size, char *str) {
|
||||
char **list = *list_p;
|
||||
if (*len == *size) {
|
||||
char **newList = (char**)PR_MALLOC(sizeof(char*) * (*size + STRINGLIST_EXPANSION_INCREMENT));
|
||||
char **old = list;
|
||||
if (newList == NULL) return -1;
|
||||
XP_MEMCPY(newList, list, (sizeof(char*) * (*size)));
|
||||
list = newList;
|
||||
if (old != NULL) PR_Free(old);
|
||||
*size += STRINGLIST_EXPANSION_INCREMENT;
|
||||
}
|
||||
*(list + *len) = str;
|
||||
++(*len);
|
||||
*list_p = list;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* returns index to last character of buffer parsed */
|
||||
PR_IMPLEMENT(int) CRAWL_ParserPut(CRAWL_ParseObj obj, char *str, uint32 len, CRAWL_ParseFunc func, void *data) {
|
||||
uint32 n = 0; /* where we are in the buffer */
|
||||
uint32 lastn = 0; /* position the last time in the loop */
|
||||
char c;
|
||||
|
||||
while (n < len) {
|
||||
if (lastn < n) { /* we advanced a character */
|
||||
obj->prev1 = obj->prev2;
|
||||
obj->prev2 = c;
|
||||
}
|
||||
lastn = n;
|
||||
c = *(str + n);
|
||||
if (obj->inComment) {
|
||||
/* if we're in a comment, ignore everything until we detect end of comment */
|
||||
if ((obj->prev1 == '-') && (obj->prev2 == '-') && (c == '>')) obj->inComment = PR_FALSE;
|
||||
n++;
|
||||
} else if (obj->skipWhitespace) {
|
||||
if ((c == ' ') || (c == '\n') || (c == '\r')) {
|
||||
n++;
|
||||
} else obj->skipWhitespace = PR_FALSE;
|
||||
} else {
|
||||
PRBool endOfString = PR_FALSE;
|
||||
switch (obj->state) {
|
||||
case PS_START:
|
||||
/* PS_START - expecting open bracket or character data */
|
||||
if (c == '<') {
|
||||
obj->state = PS_TAG_NAME;
|
||||
n++;
|
||||
} else {
|
||||
obj->state = PS_BETWEEN_TAGS;
|
||||
}
|
||||
break;
|
||||
case PS_BETWEEN_TAGS:
|
||||
/* PS_BETWEEN_TAGS - expecting open bracket (terminating character data) or more character data */
|
||||
if (obj->inQuote == c) {
|
||||
obj->inQuote = '\0'; /* close quote */
|
||||
} else if ((c == '"') || (obj->inScript && (c == '\''))) { /* start a quote, only double quotes significant in between tags */
|
||||
obj->inQuote = c;
|
||||
}
|
||||
/* open bracket not in quoted section indicates end of data */
|
||||
if ((obj->inQuote == '\0') && (c == '<')) {
|
||||
obj->state = PS_START;
|
||||
if (crawl_appendString(&obj->data, &obj->dataLen, &obj->dataSize, '\0') != 0) /* null terminate string */
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
if (func(obj, PR_FALSE, data) == PARSE_STOP) return CRAWL_PARSE_TERMINATE;
|
||||
crawl_recycleParseObj(obj);
|
||||
} else {
|
||||
if (crawl_appendString(&obj->data, &obj->dataLen, &obj->dataSize, c) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
n++;
|
||||
}
|
||||
break;
|
||||
case PS_TAG_NAME:
|
||||
/* PS_TAG_NAME - terminated by space, \r, \n, >, / */
|
||||
if ((c == '"') || (c == '\'')) return CRAWL_PARSE_ERROR; /* error - these are not allowed in tagname */
|
||||
else if (c == ' ') {
|
||||
/* Note: Both mozilla and XML don't allow any spaces between < and tagname.
|
||||
Need to check for zero-length tagname.
|
||||
*/
|
||||
if (obj->str == NULL) return CRAWL_PARSE_ERROR; /* obj->str is the buffer we're working on */
|
||||
endOfString = PR_TRUE;
|
||||
obj->state = PS_ATTRIBUTE;
|
||||
obj->skipWhitespace = PR_TRUE;
|
||||
n++;
|
||||
} else if (c == '/') {
|
||||
if (obj->tag->name == NULL) obj->tag->endTagp = PR_TRUE; /* indicates end tag if no tag name read yet */
|
||||
else if (obj->isRDF) { /* otherwise its an empty tag (RDF only) */
|
||||
endOfString = PR_TRUE;
|
||||
obj->tag->emptyTagp = PR_TRUE;
|
||||
obj->state = PS_CLOSE_BRACKET;
|
||||
} else return CRAWL_PARSE_ERROR;
|
||||
n++;
|
||||
} else if (c == '>') {
|
||||
endOfString = PR_TRUE;
|
||||
obj->state = PS_CLOSE_BRACKET;
|
||||
} else if ((c != '\r') && (c != '\n')) {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, c) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
n++;
|
||||
} else {
|
||||
endOfString = PR_TRUE;
|
||||
obj->state = PS_ATTRIBUTE; /* note - mozilla allows newline after tag name */
|
||||
obj->skipWhitespace = PR_TRUE;
|
||||
n++;
|
||||
}
|
||||
if (endOfString) {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, '\0') != 0) /* null terminate string */
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
if (strcmp(obj->str, "!--") == 0) { /* html comment */
|
||||
obj->inComment = PR_TRUE;
|
||||
obj->state = PS_START;
|
||||
} else {
|
||||
obj->tag->name = obj->str;
|
||||
obj->tag->token = pa_tokenize_tag(obj->str);
|
||||
}
|
||||
obj->str = NULL;
|
||||
obj->strLen = obj->strSize = 0;
|
||||
endOfString = PR_FALSE;
|
||||
}
|
||||
break;
|
||||
case PS_CLOSE_BRACKET:
|
||||
/* PS_CLOSE_BRACKET - expecting a close bracket, anything else is an error */
|
||||
if (c == '>') {
|
||||
if (!obj->isRDF && (obj->tag->token == P_SCRIPT)) {
|
||||
/* we're inside a script tag (not RDF) */
|
||||
if (obj->tag->endTagp) obj->inScript = PR_FALSE;
|
||||
else obj->inScript = PR_TRUE;
|
||||
}
|
||||
if (func(obj, PR_TRUE, data) == PARSE_STOP) return CRAWL_PARSE_TERMINATE;
|
||||
crawl_recycleParseObj(obj);
|
||||
obj->state = PS_START;
|
||||
n++;
|
||||
} else return CRAWL_PARSE_ERROR; /* error */
|
||||
break;
|
||||
case PS_ATTRIBUTE:
|
||||
/* PS_ATTRIBUTE - expecting an attribute name, or / (RDF only) or > indicating no more attributes */
|
||||
/* accept attributes without values, such as <tag attr1 attr2=val2>
|
||||
or <tag attr2=val2 attr1>
|
||||
*/
|
||||
if (obj->inQuote == c) {
|
||||
obj->inQuote = '\0'; /* close quote */
|
||||
} else if (((c == '"') || (c == '\'')) && (obj->inQuote == '\0')) {
|
||||
/* start a quote if none is already in effect */
|
||||
obj->inQuote = c;
|
||||
}
|
||||
if (obj->inQuote == '\0') {
|
||||
if ((((c == '/') && obj->isRDF) || (c == '>')) && (obj->str == NULL)) {
|
||||
obj->state = PS_CLOSE_BRACKET;
|
||||
} else if ((c == ' ') || (c == '=') || (c == '\n') || (c == '\r') || ((c == '/') && obj->isRDF) || (c == '>')) {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, '\0') != 0) /* null terminate string */
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
if (crawl_appendStringList(&obj->tag->attributeNames, &obj->tag->numNames, &obj->tag->sizeNames, obj->str) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
obj->str = NULL;
|
||||
obj->strLen = obj->strSize = 0;
|
||||
obj->state = PS_EQUALS; /* if non-null attribute name */
|
||||
} else {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, c) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
n++;
|
||||
}
|
||||
} else {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, c) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
n++;
|
||||
}
|
||||
break;
|
||||
case PS_EQUALS:
|
||||
if ((c == ' ') || (c == '\n') || (c == '\r')) {
|
||||
obj->skipWhitespace = PR_TRUE;
|
||||
n++;
|
||||
} else if (c == '=') {
|
||||
obj->skipWhitespace = PR_TRUE;
|
||||
obj->state = PS_VALUE;
|
||||
n++;
|
||||
} else { /* no value for the attribute - error in RDF? */
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, '\0') != 0) /* null terminate string */
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
if (crawl_appendStringList(&obj->tag->attributeValues, &obj->tag->numValues, &obj->tag->sizeValues, obj->str) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
obj->str = NULL;
|
||||
obj->strLen = obj->strSize = 0;
|
||||
obj->state = PS_ATTRIBUTE;
|
||||
}
|
||||
break;
|
||||
case PS_VALUE:
|
||||
/* expecting a value, or space, / (RDF only), or > indicating end of value. */
|
||||
{
|
||||
PRBool include = PR_TRUE; /* whether the current character should be included in value */
|
||||
if (obj->inQuote == c) {
|
||||
obj->inQuote = '\0'; /* close quote */
|
||||
include = PR_FALSE;
|
||||
} else if (((c == '"') || (c == '\'')) && (obj->inQuote == '\0')) {
|
||||
/* start a quote if none is already in effect */
|
||||
obj->inQuote = c;
|
||||
include = PR_FALSE;
|
||||
}
|
||||
if (obj->inQuote == '\0') {
|
||||
if ((c == '/') && obj->isRDF) {
|
||||
endOfString = PR_TRUE;
|
||||
obj->state = PS_CLOSE_BRACKET;
|
||||
n++;
|
||||
} else if (c == '>') {
|
||||
endOfString = PR_TRUE;
|
||||
obj->state = PS_CLOSE_BRACKET;
|
||||
} else if ((c == ' ') || (c == '\r') || (c == '\n')) {
|
||||
endOfString = PR_TRUE;
|
||||
obj->skipWhitespace = PR_TRUE;
|
||||
obj->state = PS_ATTRIBUTE; /* if non-null value name */
|
||||
n++;
|
||||
} else if (include) {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, c) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
n++;
|
||||
} else n++;
|
||||
} else if (include) {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, c) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
n++;
|
||||
} else n++;
|
||||
if (endOfString) {
|
||||
if (crawl_appendString(&obj->str, &obj->strLen, &obj->strSize, '\0') != 0) /* null terminate string */
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
if (crawl_appendStringList(&obj->tag->attributeValues, &obj->tag->numValues, &obj->tag->sizeValues, obj->str) != 0)
|
||||
return CRAWL_PARSE_OUT_OF_MEMORY;
|
||||
obj->str = NULL;
|
||||
obj->strLen = obj->strSize = 0;
|
||||
endOfString = PR_FALSE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
return CRAWL_PARSE_NO_ERROR;
|
||||
}
|
||||
|
||||
#if 0
|
||||
void printParseObj(CRAWL_ParseObj obj, PRBool isTag, void *data) {
|
||||
if (isTag) {
|
||||
CRAWL_Tag tag = CRAWL_GetTagParsed(obj);
|
||||
if (CRAWL_IsEndTag(tag)) {
|
||||
printf("</%s>\n", CRAWL_GetTagName(tag));
|
||||
} else {
|
||||
uint16 i;
|
||||
printf("<%s", CRAWL_GetTagName(tag));
|
||||
for (i = 0; i < CRAWL_GetNumberOfAttributes(tag); i++) {
|
||||
printf(" %s=\"%s\"", CRAWL_GetNthAttributeName(tag, i), CRAWL_GetNthAttributeValue(tag, i));
|
||||
}
|
||||
if (CRAWL_IsEmptyTag(tag)) printf("/>\n");
|
||||
else printf(">\n");
|
||||
}
|
||||
} else printf(">>>>>%s<<<<<\n", CRAWL_GetDataParsed(obj));
|
||||
}
|
||||
|
||||
void parseLocalFile (char *url) {
|
||||
PRFileDesc *fp;
|
||||
int32 len;
|
||||
char *path;
|
||||
static char buf[512]; /* xxx alloc */
|
||||
CRAWL_ParseObj parse;
|
||||
|
||||
/* XXX need to unescape URL */
|
||||
path=&url[8];
|
||||
fp = PR_Open(path, PR_RDONLY, 0644); /* WR_ONLY|PR_TRUNCATE */
|
||||
if(fp == NULL)
|
||||
{
|
||||
/* abortRDFParse(file); */
|
||||
return;
|
||||
}
|
||||
parse = CRAWL_MakeParseObj();
|
||||
while((len=PR_Read(fp, buf, 512))>0) {
|
||||
int result;
|
||||
result = CRAWL_ParserPut(parse, buf, len, printParseObj, NULL);
|
||||
if (result == len) printf("************NO ERRORS************\n");
|
||||
else printf("************PARSING ERROR************\n");
|
||||
}
|
||||
PR_Close(fp);
|
||||
CRAWL_DestroyParseObj(parse);
|
||||
/* finishRDFParse(file); */
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
155
mozilla/lib/libnet/htmparse.h
Normal file
155
mozilla/lib/libnet/htmparse.h
Normal file
@@ -0,0 +1,155 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*** htmparse.h ***************************************************/
|
||||
/* description: html parser */
|
||||
|
||||
|
||||
/********************************************************************
|
||||
|
||||
The client calls CRAWL_ParserPut, and gets called back with
|
||||
a function whose prototype is described by CRAWL_ParseFunc. The
|
||||
parser calls this function whenever a begin or end tag, or run of
|
||||
character data has been scanned, and does not build a tree.
|
||||
|
||||
$Revision: 3.1 $
|
||||
$Date: 1998-03-28 03:31:31 $
|
||||
|
||||
*********************************************************************/
|
||||
|
||||
|
||||
#ifndef htmparse_h___
|
||||
#define htmparse_h___
|
||||
#include "prtypes.h"
|
||||
|
||||
/* return values from CRAWL_ParserPut */
|
||||
#define CRAWL_PARSE_NO_ERROR 0 /* no error */
|
||||
#define CRAWL_PARSE_ERROR 1 /* syntax error */
|
||||
#define CRAWL_PARSE_TERMINATE 2 /* don't continue to parse */
|
||||
#define CRAWL_PARSE_OUT_OF_MEMORY 3 /* out of memory */
|
||||
|
||||
/* return values for CRAWL_ParseFunc callback function */
|
||||
#define PARSE_GET_NEXT_TOKEN 0
|
||||
#define PARSE_STOP 1
|
||||
#define PARSE_OUT_OF_MEMORY 2
|
||||
|
||||
typedef struct _CRAWL_TagStruc *CRAWL_Tag;
|
||||
|
||||
/*
|
||||
The client of this API creates a reference to this with CRAWL_MakeParseObj and provides it as
|
||||
a parameter to CRAWL_ParserPut. It is passed as a parameter to the CRAWL_ParseFunc function and
|
||||
the parsed data may be extracted from it through the API. It should be considered opaque data.
|
||||
*/
|
||||
typedef struct _CRAWL_ParseObjStruc *CRAWL_ParseObj;
|
||||
|
||||
/*
|
||||
Typedef for a parse callback. The memory in CRAWL_ParseObj is reused across successive calls.
|
||||
*/
|
||||
typedef int
|
||||
(PR_CALLBACK *CRAWL_ParseFunc)(CRAWL_ParseObj obj, PRBool isTag, void *data);
|
||||
|
||||
/****************************************************************************************/
|
||||
/* public API */
|
||||
/****************************************************************************************/
|
||||
|
||||
NSPR_BEGIN_EXTERN_C
|
||||
|
||||
/*
|
||||
Returns the tag parsed
|
||||
*/
|
||||
PR_EXTERN(CRAWL_Tag)
|
||||
CRAWL_GetTagParsed(CRAWL_ParseObj obj);
|
||||
|
||||
/*
|
||||
Returns the character data between tags
|
||||
*/
|
||||
PR_EXTERN(char*)
|
||||
CRAWL_GetDataParsed(CRAWL_ParseObj obj);
|
||||
|
||||
/*
|
||||
Returns the tag name
|
||||
*/
|
||||
PR_EXTERN(char*)
|
||||
CRAWL_GetTagName(CRAWL_Tag tag);
|
||||
|
||||
/*
|
||||
Returns the libparse tag code as defined in pa_tags.h
|
||||
*/
|
||||
PR_EXTERN(intn)
|
||||
CRAWL_GetTagToken(CRAWL_Tag tag);
|
||||
|
||||
/*
|
||||
a tag of the form <tagname /> Empty tags are recognized only if the page has been designated as
|
||||
containing RDF (the API doesn't support this yet)
|
||||
*/
|
||||
PR_EXTERN(PRBool)
|
||||
CRAWL_IsEmptyTag(CRAWL_Tag tag);
|
||||
|
||||
/*
|
||||
A tag of the form </tagname>.
|
||||
*/
|
||||
PR_EXTERN(PRBool)
|
||||
CRAWL_IsEndTag(CRAWL_Tag tag);
|
||||
|
||||
/*
|
||||
Returns the tag attribute given a name
|
||||
*/
|
||||
PR_EXTERN(char*)
|
||||
CRAWL_GetAttributeValue(CRAWL_Tag tag, char *attributeName);
|
||||
|
||||
/*
|
||||
Returns the number of attributes for the tag.
|
||||
*/
|
||||
PR_EXTERN(uint16)
|
||||
CRAWL_GetNumberOfAttributes(CRAWL_Tag tag);
|
||||
|
||||
/*
|
||||
Returns the nth attribute of the tag.
|
||||
*/
|
||||
PR_EXTERN(char*)
|
||||
CRAWL_GetNthAttributeName(CRAWL_Tag tag, uint16 n);
|
||||
|
||||
/*
|
||||
Returns the nth attribute value of the tag.
|
||||
*/
|
||||
PR_EXTERN(char*)
|
||||
CRAWL_GetNthAttributeValue(CRAWL_Tag tag, uint16 n);
|
||||
|
||||
/*
|
||||
Creates a new CRAWL_ParseObj suitable for passing to CRAWL_ParserPut.
|
||||
Returns NULL if out of memory.
|
||||
*/
|
||||
PR_EXTERN(CRAWL_ParseObj)
|
||||
CRAWL_MakeParseObj();
|
||||
|
||||
/*
|
||||
Destroys the CRAWL_ParseObj and all associated memory
|
||||
*/
|
||||
PR_EXTERN(void)
|
||||
CRAWL_DestroyParseObj(CRAWL_ParseObj obj);
|
||||
|
||||
/*
|
||||
Parse characters in buffer and call func when an element (tag or data) has been
|
||||
scanned. Returns an error code. The same CRAWL_ParseObj must be provided for successive
|
||||
puts in the same buffer. It is up to the caller to create and destroy the CRAWL_ParseObj.
|
||||
*/
|
||||
PR_EXTERN(int)
|
||||
CRAWL_ParserPut(CRAWL_ParseObj obj, char *str, uint32 len, CRAWL_ParseFunc func, void *data);
|
||||
|
||||
NSPR_END_EXTERN_C
|
||||
|
||||
#endif /* htmparse_h___ */
|
||||
1585
mozilla/lib/libnet/imap4pvt.h
Normal file
1585
mozilla/lib/libnet/imap4pvt.h
Normal file
File diff suppressed because it is too large
Load Diff
658
mozilla/lib/libnet/imap4url.c
Normal file
658
mozilla/lib/libnet/imap4url.c
Normal file
@@ -0,0 +1,658 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
|
||||
#ifndef __imap__
|
||||
#include "imap.h"
|
||||
#endif
|
||||
|
||||
#ifndef _MCOM_H_
|
||||
#include "xp_mcom.h"
|
||||
#endif
|
||||
|
||||
/* 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
|
||||
char useme;
|
||||
|
||||
static char *createStartOfIMAPurl(const char *imapHost, int additionalSize)
|
||||
{
|
||||
static const char *formatString = "IMAP://%s?";
|
||||
|
||||
char *returnString = XP_ALLOC(XP_STRLEN(formatString) + XP_STRLEN(imapHost) + additionalSize);
|
||||
if (returnString)
|
||||
sprintf(returnString, formatString, imapHost);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
|
||||
/* Selecting a mailbox */
|
||||
/* imap4://HOST>select>MAILBOXPATH */
|
||||
char *CreateImapMailboxSelectUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *undoDeleteIdentifierList)
|
||||
{
|
||||
static const char *formatString = "select>%c%s>%s";
|
||||
|
||||
/* 22 enough for huge index string */
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) +
|
||||
XP_STRLEN(mailbox) +
|
||||
(undoDeleteIdentifierList ? XP_STRLEN(undoDeleteIdentifierList) : 1) +
|
||||
22);
|
||||
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString),
|
||||
formatString,
|
||||
hierarchySeparator,
|
||||
mailbox,
|
||||
undoDeleteIdentifierList ? undoDeleteIdentifierList : "");
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* lite select, used to verify UIDVALIDITY while going on/offline */
|
||||
char *CreateImapMailboxLITESelectUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "liteselect>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailbox));
|
||||
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString),
|
||||
formatString,
|
||||
hierarchySeparator,
|
||||
mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* expunge, used in traditional imap delete model */
|
||||
char *CreateImapMailboxExpungeUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "expunge>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailbox));
|
||||
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString),
|
||||
formatString,
|
||||
hierarchySeparator,
|
||||
mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* Creating a mailbox */
|
||||
/* imap4://HOST>create>MAILBOXPATH */
|
||||
char *CreateImapMailboxCreateUrl(const char *imapHost, const char *mailbox,char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "create>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, hierarchySeparator, mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* discover the mailboxes of this account */
|
||||
char *CreateImapAllMailboxDiscoveryUrl(const char *imapHost)
|
||||
{
|
||||
static const char *formatString = "discoverallboxes";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
|
||||
/* discover the mailboxes of this account, and the subscribed mailboxes */
|
||||
char *CreateImapAllAndSubscribedMailboxDiscoveryUrl(const char *imapHost)
|
||||
{
|
||||
static const char *formatString = "discoverallandsubscribedboxes";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* discover the children of this mailbox */
|
||||
char *CreateImapChildDiscoveryUrl(const char *imapHost, const char *mailbox,char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "discoverchildren>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, hierarchySeparator, mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
/* discover the n-th level deep children of this mailbox */
|
||||
char *CreateImapLevelChildDiscoveryUrl(const char *imapHost, const char *mailbox,char hierarchySeparator, int n)
|
||||
{
|
||||
static const char *formatString = "discoverlevelchildren>%d>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, n, hierarchySeparator, mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* deleting a mailbox */
|
||||
/* imap4://HOST>delete>MAILBOXPATH */
|
||||
char *CreateImapMailboxDeleteUrl(const char *imapHost, const char *mailbox, char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "delete>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, hierarchySeparator, mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* renaming a mailbox */
|
||||
/* imap4://HOST>rename>OLDNAME>NEWNAME */
|
||||
char *CreateImapMailboxRenameLeafUrl(const char *imapHost,
|
||||
const char *oldBoxPathName,
|
||||
char hierarchySeparator,
|
||||
const char *newBoxLeafName)
|
||||
{
|
||||
static const char *formatString = "rename>%c%s>%c%s";
|
||||
|
||||
char *returnString = NULL;
|
||||
|
||||
/* figure out the new mailbox name */
|
||||
char *slash;
|
||||
char *newPath = XP_ALLOC(XP_STRLEN(oldBoxPathName) + XP_STRLEN(newBoxLeafName) + 1);
|
||||
if (newPath)
|
||||
{
|
||||
XP_STRCPY (newPath, oldBoxPathName);
|
||||
slash = XP_STRRCHR (newPath, '/');
|
||||
if (slash)
|
||||
slash++;
|
||||
else
|
||||
slash = newPath; /* renaming a 1st level box */
|
||||
|
||||
XP_STRCPY (slash, newBoxLeafName);
|
||||
|
||||
|
||||
returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(oldBoxPathName) + XP_STRLEN(newPath));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, hierarchySeparator, oldBoxPathName, hierarchySeparator, newPath);
|
||||
|
||||
XP_FREE( newPath);
|
||||
}
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* renaming a mailbox, moving hierarchy */
|
||||
/* imap4://HOST>movefolderhierarchy>OLDNAME>NEWNAME */
|
||||
/* oldBoxPathName is the old name of the child folder */
|
||||
/* destinationBoxPathName is the name of the new parent */
|
||||
char *CreateImapMailboxMoveFolderHierarchyUrl(const char *imapHost,
|
||||
const char *oldBoxPathName,
|
||||
char oldHierarchySeparator,
|
||||
const char *newBoxPathName,
|
||||
char newHierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "movefolderhierarchy>%c%s>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(oldBoxPathName) + XP_STRLEN(newBoxPathName));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, oldHierarchySeparator, oldBoxPathName, newHierarchySeparator, newBoxPathName);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* listing available mailboxes */
|
||||
/* imap4://HOST>list>referenceName>MAILBOXPATH */
|
||||
/* MAILBOXPATH can contain wildcard */
|
||||
/* **** jefft -- I am using this url to detect whether an mailbox
|
||||
exists on the Imap sever
|
||||
*/
|
||||
char *CreateImapListUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
const char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "list>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost,
|
||||
XP_STRLEN(formatString) +
|
||||
XP_STRLEN(mailbox) + 1);
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString,
|
||||
hierarchySeparator, mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* biff */
|
||||
char *CreateImapBiffUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
uint32 uidHighWater)
|
||||
{
|
||||
static const char *formatString = "biff>%c%s>%ld";
|
||||
|
||||
/* 22 enough for huge uid string */
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) +
|
||||
XP_STRLEN(mailbox) + 22);
|
||||
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, hierarchySeparator, mailbox, (long)uidHighWater);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
|
||||
static const char *sequenceString = "SEQUENCE";
|
||||
static const char *uidString = "UID";
|
||||
|
||||
/* fetching RFC822 messages */
|
||||
/* imap4://HOST>fetch><UID/SEQUENCE>>MAILBOXPATH>x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
/* will set the 'SEEN' flag */
|
||||
char *CreateImapMessageFetchUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *messageIdentifierList,
|
||||
XP_Bool messageIdsAreUID)
|
||||
{
|
||||
static const char *formatString = "fetch>%s>%c%s>%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(sequenceString) + XP_STRLEN(mailbox) + XP_STRLEN(messageIdentifierList));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, messageIdsAreUID ? uidString : sequenceString, hierarchySeparator, mailbox, messageIdentifierList);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* fetching the headers of RFC822 messages */
|
||||
/* imap4://HOST>header><UID/SEQUENCE>>MAILBOXPATH>x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
/* will not affect the 'SEEN' flag */
|
||||
char *CreateImapMessageHeaderUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *messageIdentifierList,
|
||||
XP_Bool messageIdsAreUID)
|
||||
{
|
||||
static const char *formatString = "header>%s>%c%s>%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(sequenceString) + XP_STRLEN(mailbox) + XP_STRLEN(messageIdentifierList));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, messageIdsAreUID ? uidString : sequenceString, hierarchySeparator, mailbox, messageIdentifierList);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* search an online mailbox */
|
||||
/* imap4://HOST>search><UID/SEQUENCE>>MAILBOXPATH>SEARCHSTRING */
|
||||
/* 'x' is the message sequence number list */
|
||||
char *CreateImapSearchUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *searchString,
|
||||
XP_Bool messageIdsAreUID)
|
||||
{
|
||||
static const char *formatString = "search>%s>%c%s>%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(sequenceString) + XP_STRLEN(mailbox) + XP_STRLEN(searchString));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, messageIdsAreUID ? uidString : sequenceString, hierarchySeparator, mailbox, searchString);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* delete messages */
|
||||
/* imap4://HOST>deletemsg><UID/SEQUENCE>>MAILBOXPATH>x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
char *CreateImapDeleteMessageUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *messageIds,
|
||||
XP_Bool idsAreUids)
|
||||
{
|
||||
static const char *formatString = "deletemsg>%s>%c%s>%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(sequenceString) + XP_STRLEN(mailbox) + XP_STRLEN(messageIds));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, idsAreUids ? uidString : sequenceString, hierarchySeparator, mailbox, messageIds);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* delete all messages */
|
||||
/* imap4://HOST>deleteallmsgs>MAILBOXPATH */
|
||||
char *CreateImapDeleteAllMessagesUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "deleteallmsgs>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, hierarchySeparator, mailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* store +flags url */
|
||||
/* imap4://HOST>store+flags><UID/SEQUENCE>>MAILBOXPATH>x>f */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
/* 'f' is the byte of flags */
|
||||
char *CreateImapAddMessageFlagsUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *messageIds,
|
||||
imapMessageFlagsType flags,
|
||||
XP_Bool idsAreUids)
|
||||
{
|
||||
static const char *formatString = "addmsgflags>%s>%c%s>%s>%d";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(sequenceString) + XP_STRLEN(mailbox) + XP_STRLEN(messageIds) + 10);
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, idsAreUids ? uidString : sequenceString, hierarchySeparator, mailbox, messageIds, (int) flags);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* store -flags url */
|
||||
/* imap4://HOST>store-flags><UID/SEQUENCE>>MAILBOXPATH>x>f */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
/* 'f' is the byte of flags */
|
||||
char *CreateImapSubtractMessageFlagsUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *messageIds,
|
||||
imapMessageFlagsType flags,
|
||||
XP_Bool idsAreUids)
|
||||
{
|
||||
static const char *formatString = "subtractmsgflags>%s>%c%s>%s>%d";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(sequenceString) + XP_STRLEN(mailbox) + XP_STRLEN(messageIds) + 10);
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, idsAreUids ? uidString : sequenceString, hierarchySeparator, mailbox, messageIds, (int) flags);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* set flags url, make the flags match */
|
||||
char *CreateImapSetMessageFlagsUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
char hierarchySeparator,
|
||||
const char *messageIds,
|
||||
imapMessageFlagsType flags,
|
||||
XP_Bool idsAreUids)
|
||||
{
|
||||
static const char *formatString = "setmsgflags>%s>%c%s>%s>%d";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(sequenceString) + XP_STRLEN(mailbox) + XP_STRLEN(messageIds) + 10);
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, idsAreUids ? uidString : sequenceString, hierarchySeparator, mailbox, messageIds, (int) flags);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* copy messages from one online box to another */
|
||||
/* imap4://HOST>onlineCopy><UID/SEQUENCE>>SOURCEMAILBOXPATH>x>
|
||||
DESTINATIONMAILBOXPATH */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
char *CreateImapOnlineCopyUrl(const char *imapHost,
|
||||
const char *sourceMailbox,
|
||||
char sourceHierarchySeparator,
|
||||
const char *messageIds,
|
||||
const char *destinationMailbox,
|
||||
char destinationHierarchySeparator,
|
||||
XP_Bool idsAreUids,
|
||||
XP_Bool isMove)
|
||||
{
|
||||
static const char *formatString = "%s>%s>%c%s>%s>%c%s";
|
||||
static const char *moveString = "onlinemove";
|
||||
static const char *copyString = "onlinecopy";
|
||||
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(moveString) + XP_STRLEN(sequenceString) + XP_STRLEN(sourceMailbox) + XP_STRLEN(messageIds) + XP_STRLEN(destinationMailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString,
|
||||
isMove ? moveString : copyString,
|
||||
idsAreUids ? uidString : sequenceString,
|
||||
sourceHierarchySeparator, sourceMailbox,
|
||||
messageIds,
|
||||
destinationHierarchySeparator, destinationMailbox);
|
||||
|
||||
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* copy messages from one online box to another */
|
||||
/* imap4://HOST>onlineCopy><UID/SEQUENCE>>SOURCEMAILBOXPATH>x>
|
||||
DESTINATIONMAILBOXPATH */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
char *CreateImapOnToOfflineCopyUrl(const char *imapHost,
|
||||
const char *sourceMailbox,
|
||||
char sourceHierarchySeparator,
|
||||
const char *messageIds,
|
||||
const char *destinationMailbox,
|
||||
XP_Bool idsAreUids,
|
||||
XP_Bool isMove)
|
||||
{
|
||||
static const char *formatString = "%s>%s>%c%s>%s>%c%s";
|
||||
static const char *moveString = "onlinetoofflinemove";
|
||||
static const char *copyString = "onlinetoofflinecopy";
|
||||
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(moveString) + XP_STRLEN(sequenceString) + XP_STRLEN(sourceMailbox) + XP_STRLEN(messageIds) + XP_STRLEN(destinationMailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString,
|
||||
isMove ? moveString : copyString,
|
||||
idsAreUids ? uidString : sequenceString,
|
||||
sourceHierarchySeparator, sourceMailbox,
|
||||
messageIds,
|
||||
kOnlineHierarchySeparatorUnknown, destinationMailbox);
|
||||
|
||||
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* copy messages from an offline box to an online box */
|
||||
/* imap4://HOST>offtoonCopy>SOURCEMAILBOXPATH>x>
|
||||
DESTINATIONMAILBOXPATH */
|
||||
/* 'x' is the size of the message to upload */
|
||||
char *CreateImapOffToOnlineCopyUrl(const char *imapHost,
|
||||
const char *destinationMailbox,
|
||||
char destinationHierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "offlinetoonlinecopy>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(destinationMailbox));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, destinationHierarchySeparator, destinationMailbox);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* get mail account rul */
|
||||
/* imap4://HOST>NETSCAPE */
|
||||
char *CreateImapManageMailAccountUrl(const char *imapHost)
|
||||
{
|
||||
static const char *formatString = "netscape";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + 1);
|
||||
StrAllocCat(returnString, formatString);;
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* append message from file url */
|
||||
/* imap4://HOST>appendmsgfromfile>DESTINATIONMAILBOXPATH */
|
||||
char *CreateImapAppendMessageFromFileUrl(const char *imapHost,
|
||||
const char *destinationMailboxPath,
|
||||
const char hierarchySeparator,
|
||||
XP_Bool isDraft)
|
||||
{
|
||||
const char *formatString = isDraft ? "appenddraftfromfile>%c%s" :
|
||||
"appendmsgfromfile>%c%s";
|
||||
char *returnString =
|
||||
createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) +
|
||||
XP_STRLEN(destinationMailboxPath));
|
||||
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString,
|
||||
hierarchySeparator, destinationMailboxPath);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
|
||||
/* Subscribe to a mailbox on the given IMAP host */
|
||||
char *CreateIMAPSubscribeMailboxURL(const char *imapHost, const char *mailboxName)
|
||||
{
|
||||
/* we don't need the hierarchy delimiter, so just use slash ("/") */
|
||||
static const char *formatString = "subscribe>/%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailboxName));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, mailboxName);
|
||||
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
/* Unsubscribe from a mailbox on the given IMAP host */
|
||||
char *CreateIMAPUnsubscribeMailboxURL(const char *imapHost, const char *mailboxName)
|
||||
{
|
||||
/* we don't need the hierarchy delimiter, so just use slash ("/") */
|
||||
static const char *formatString = "unsubscribe>/%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailboxName));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, mailboxName);
|
||||
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/* Refresh the ACL for a folder on the given IMAP host */
|
||||
char *CreateIMAPRefreshACLForFolderURL(const char *imapHost, const char *mailboxName)
|
||||
{
|
||||
/* we don't need the hierarchy delimiter, so just use slash ("/") */
|
||||
static const char *formatString = "refreshacl>/%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailboxName));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, mailboxName);
|
||||
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
/* Refresh the ACL for all folders on the given IMAP host */
|
||||
char *CreateIMAPRefreshACLForAllFoldersURL(const char *imapHost)
|
||||
{
|
||||
/* we don't need the hierarchy delimiter, so just use slash ("/") */
|
||||
static const char *formatString = "refreshallacls>/";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString);
|
||||
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
/* Auto-Upgrade to IMAP subscription */
|
||||
char *CreateIMAPUpgradeToSubscriptionURL(const char *imapHost, XP_Bool subscribeToAll)
|
||||
{
|
||||
static char *formatString = "upgradetosubscription>/";
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString));
|
||||
if (subscribeToAll)
|
||||
formatString[XP_STRLEN(formatString)-1] = '.';
|
||||
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString);
|
||||
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
/* do a status command on a folder on the given IMAP host */
|
||||
char *CreateIMAPStatusFolderURL(const char *imapHost, const char *mailboxName, char hierarchySeparator)
|
||||
{
|
||||
static const char *formatString = "folderstatus>%c%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailboxName));
|
||||
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString),
|
||||
formatString,
|
||||
hierarchySeparator,
|
||||
mailboxName);
|
||||
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
/* Refresh the admin url for a folder on the given IMAP host */
|
||||
char *CreateIMAPRefreshFolderURLs(const char *imapHost, const char *mailboxName)
|
||||
{
|
||||
/* we don't need the hierarchy delimiter, so just use slash ("/") */
|
||||
static const char *formatString = "refreshfolderurls>/%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailboxName));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, mailboxName);
|
||||
|
||||
return returnString;
|
||||
|
||||
}
|
||||
|
||||
/* Force the reload of all parts of the message given in url */
|
||||
char *IMAP_CreateReloadAllPartsUrl(const char *url)
|
||||
{
|
||||
char *returnUrl = PR_smprintf("%s&allparts", url);
|
||||
return returnUrl;
|
||||
}
|
||||
|
||||
/* Explicitly LIST a given mailbox, and refresh its flags in the folder list */
|
||||
char *CreateIMAPListFolderURL(const char *imapHost, const char *mailboxName)
|
||||
{
|
||||
/* we don't need the hierarchy delimiter, so just use slash ("/") */
|
||||
static const char *formatString = "listfolder>/%s";
|
||||
|
||||
char *returnString = createStartOfIMAPurl(imapHost, XP_STRLEN(formatString) + XP_STRLEN(mailboxName));
|
||||
if (returnString)
|
||||
sprintf(returnString + XP_STRLEN(returnString), formatString, mailboxName);
|
||||
|
||||
return returnString;
|
||||
}
|
||||
157
mozilla/lib/libnet/imap4url.h
Normal file
157
mozilla/lib/libnet/imap4url.h
Normal file
@@ -0,0 +1,157 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/* this file defines the syntax of the imap4 url's and offers functions
|
||||
that create url strings. If the functions do not offer enough
|
||||
functionality then let kevin know before you starting creating strings
|
||||
from scratch. */
|
||||
|
||||
#ifndef IMAP4URL_H
|
||||
#define IMAP4URL_H
|
||||
|
||||
#include "xp_mcom.h"
|
||||
|
||||
/* 45678901234567890123456789012345678901234567890123456789012345678901234567890
|
||||
*/
|
||||
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
/* need mailbox status urls to get the number of message and the
|
||||
number of unread messages */
|
||||
|
||||
/* Creating a mailbox */
|
||||
/* imap4://HOST?create?MAILBOXPATH */
|
||||
char *CreateImapMailboxCreateUrl(const char *imapHost, const char *mailbox);
|
||||
|
||||
/* deleting a mailbox */
|
||||
/* imap4://HOST?delete?MAILBOXPATH */
|
||||
char *CreateImapMailboxDeleteUrl(const char *imapHost, const char *mailbox);
|
||||
|
||||
/* renaming a mailbox */
|
||||
/* imap4://HOST?rename?OLDNAME?NEWNAME */
|
||||
char *CreateImapMailboxRenameUrl(const char *imapHost,
|
||||
const char *oldBoxName,
|
||||
const char *newBoxName);
|
||||
|
||||
/* listing available mailboxes */
|
||||
/* imap4://HOST?list */
|
||||
char *CreateImapListUrl(const char *imapHost);
|
||||
|
||||
|
||||
/* fetching RFC822 messages */
|
||||
/* imap4://HOST?fetch?<UID/SEQUENCE>?MAILBOXPATH?x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
/* will set the 'SEEN' flag */
|
||||
char *CreateImapMessageFetchUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
const char *messageIdentifierList,
|
||||
XP_Bool messageIdsAreUID);
|
||||
|
||||
|
||||
/* fetching the headers of RFC822 messages */
|
||||
/* imap4://HOST?header?<UID/SEQUENCE>?MAILBOXPATH?x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
/* will not affect the 'SEEN' flag */
|
||||
char *CreateImapMessageHeaderUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
const char *messageIdentifierList,
|
||||
XP_Bool messageIdsAreUID);
|
||||
|
||||
/* dump headers url. Notify the front end when the mailbox is selected and
|
||||
when each message line is dumped */
|
||||
char *CreateImapMessageHeaderDumpUrl(const char *imapHost,
|
||||
const char *mailbox);
|
||||
|
||||
/* search an online mailbox */
|
||||
/* imap4://HOST?search?<UID/SEQUENCE>?MAILBOXPATH?SEARCHSTRING */
|
||||
/* 'x' is the message sequence number list */
|
||||
char *CreateImapSearchUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
const char *searchString,
|
||||
XP_Bool messageIdsAreUID);
|
||||
|
||||
/* delete messages */
|
||||
/* imap4://HOST?deletemsg?<UID/SEQUENCE>?MAILBOXPATH?x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
char *CreateImapDeleteMessageUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
const char *messageIds,
|
||||
XP_Bool idsAreUids);
|
||||
|
||||
/* mark messages as read */
|
||||
/* imap4://HOST?markread?<UID/SEQUENCE>?MAILBOXPATH?x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
char *CreateImapMarkMessageReadUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
const char *messageIds,
|
||||
XP_Bool idsAreUids);
|
||||
|
||||
/* mark messages as unread */
|
||||
/* imap4://HOST?markunread?<UID/SEQUENCE>?MAILBOXPATH?x */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
char *CreateImapMarkMessageUnReadUrl(const char *imapHost,
|
||||
const char *mailbox,
|
||||
const char *messageIds,
|
||||
XP_Bool idsAreUids);
|
||||
|
||||
/* copy messages from one online box to another */
|
||||
/* imap4://HOST?onlineCopy?<UID/SEQUENCE>?
|
||||
SOURCEMAILBOXPATH?x?DESTINATIONMAILBOXPATH */
|
||||
/* 'x' is the message UID or sequence number list */
|
||||
char *CreateImapOnlineCopyUrl(const char *imapHost,
|
||||
const char *sourceMailbox,
|
||||
const char *messageIds,
|
||||
const char *destinationMailbox,
|
||||
XP_Bool idsAreUids);
|
||||
|
||||
#if DOTHISSTUFFLATER
|
||||
/* copy a message from an online box to an offline box */
|
||||
/* imap4://HOST?ontooffCopy?SOURCEMAILBOXPATH?number=x?
|
||||
DESTINATIONMAILBOXPATH */
|
||||
/* 'x' is the message sequence number */
|
||||
char *CreateImapOnToOfflineCopyUrl(const char *imapHost,
|
||||
const char *sourceOnlineMailbox,
|
||||
int32 messageSequenceNumber,
|
||||
const char *destinationOfflineMailbox);
|
||||
|
||||
/* copy a message from an offline box to an online box */
|
||||
/* imap4://HOST?offtoonCopy?SOURCEMAILBOXPATH?number=x?
|
||||
DESTINATIONMAILBOXPATH */
|
||||
/* 'x' is the message sequence number */
|
||||
char *CreateImapOffToOnlineCopyUrl(const char *imapHost,
|
||||
const char *sourceOnlineMailbox,
|
||||
int32 messageSequenceNumber,
|
||||
const char *destinationOfflineMailbox);
|
||||
|
||||
/* get mail account rul */
|
||||
/* imap4://HOST?NETSCAPE */
|
||||
char *CreateImapManageMailAccountUrl(const char *imapHost);
|
||||
|
||||
/* append message from file url */
|
||||
/* imap4://HOST?appendmsgfromfile>DESTINATIONMAILBOXPATH */
|
||||
char *CreateImapAppendMessageFromFileUrl(const char *imapHost,
|
||||
const char *destinationMailboxPath,
|
||||
const char hierarchySeparator,
|
||||
XP_Bool isDraft);
|
||||
|
||||
#endif
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif /* IMAP4URL_H */
|
||||
|
||||
1614
mozilla/lib/libnet/imapbody.cpp
Normal file
1614
mozilla/lib/libnet/imapbody.cpp
Normal file
File diff suppressed because it is too large
Load Diff
364
mozilla/lib/libnet/imapbody.h
Normal file
364
mozilla/lib/libnet/imapbody.h
Normal file
@@ -0,0 +1,364 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
TIMAPBodyShell and associated classes
|
||||
*/
|
||||
|
||||
#ifndef IMAPBODY_H
|
||||
#define IMAPBODY_H
|
||||
|
||||
#include "imap.h"
|
||||
#include "xp_list.h"
|
||||
|
||||
|
||||
typedef enum _TIMAPBodypartType {
|
||||
IMAP_BODY_MESSAGE_RFC822,
|
||||
IMAP_BODY_MESSAGE_HEADER,
|
||||
IMAP_BODY_LEAF,
|
||||
IMAP_BODY_MULTIPART
|
||||
} TIMAPBodypartType;
|
||||
|
||||
class TIMAPGenericParser;
|
||||
class TNavigatorImapConnection;
|
||||
class TIMAPBodyShell;
|
||||
class XPPtrArray;
|
||||
class TIMAPBodypartMessage;
|
||||
typedef struct xp_HashTable *XP_HashTable;
|
||||
|
||||
|
||||
class TIMAPBodypart : public TIMAPGenericParser
|
||||
{
|
||||
public:
|
||||
// Construction
|
||||
static TIMAPBodypart *CreatePart(TIMAPBodyShell *shell, char *partNum, const char *buf, TIMAPBodypart *parentPart);
|
||||
virtual XP_Bool GetIsValid() { return m_isValid; }
|
||||
virtual void SetIsValid(XP_Bool valid);
|
||||
virtual TIMAPBodypartType GetType() = 0;
|
||||
|
||||
// Generation
|
||||
virtual int32 Generate(XP_Bool /*stream*/, XP_Bool /* prefetch */) { return -1; } // Generates an HTML representation of this part. Returns content length generated, -1 if failed.
|
||||
virtual void AdoptPartDataBuffer(char *buf); // Adopts storage for part data buffer. If NULL, sets isValid to FALSE.
|
||||
virtual void AdoptHeaderDataBuffer(char *buf); // Adopts storage for header data buffer. If NULL, sets isValid to FALSE.
|
||||
virtual XP_Bool ShouldFetchInline() { return TRUE; } // returns TRUE if this part should be fetched inline for generation.
|
||||
virtual XP_Bool PreflightCheckAllInline() { return TRUE; }
|
||||
|
||||
virtual XP_Bool ShouldExplicitlyFetchInline();
|
||||
virtual XP_Bool ShouldExplicitlyNotFetchInline();
|
||||
|
||||
protected: // If stream is FALSE, simply returns the content length that will be generated
|
||||
virtual int32 GeneratePart(XP_Bool stream, XP_Bool prefetch); // the body of the part itself
|
||||
virtual int32 GenerateMIMEHeader(XP_Bool stream, XP_Bool prefetch); // the MIME headers of the part
|
||||
virtual int32 GenerateBoundary(XP_Bool stream, XP_Bool prefetch, XP_Bool lastBoundary); // Generates the MIME boundary wrapper for this part.
|
||||
// lastBoundary indicates whether or not this should be the boundary for the
|
||||
// final MIME part of the multipart message.
|
||||
virtual int32 GenerateEmptyFilling(XP_Bool stream, XP_Bool prefetch); // Generates (possibly empty) filling for a part that won't be filled in inline.
|
||||
|
||||
// Part Numbers / Hierarchy
|
||||
public:
|
||||
virtual int GetPartNumber() { return m_partNumber; } // Returns the part number on this hierarchy level
|
||||
virtual char *GetPartNumberString() { return m_partNumberString; }
|
||||
virtual TIMAPBodypart *FindPartWithNumber(const char *partNum); // Returns the part object with the given number
|
||||
virtual TIMAPBodypart *GetParentPart() { return m_parentPart; } // Returns the parent of this part.
|
||||
// We will define a part of type message/rfc822 to be the
|
||||
// parent of its body and header.
|
||||
// A multipart is a parent of its child parts.
|
||||
// All other leafs do not have children.
|
||||
|
||||
// Other / Helpers
|
||||
public:
|
||||
virtual ~TIMAPBodypart();
|
||||
virtual XP_Bool GetNextLineForParser(char **nextLine);
|
||||
virtual XP_Bool ContinueParse(); // overrides the parser, but calls it anyway
|
||||
virtual TIMAPBodypartMessage *GetTIMAPBodypartMessage() { return NULL; }
|
||||
|
||||
|
||||
protected:
|
||||
virtual void QueuePrefetchMIMEHeader();
|
||||
//virtual void PrefetchMIMEHeader(); // Initiates a prefetch for the MIME header of this part.
|
||||
virtual XP_Bool ParseIntoObjects() = 0; // Parses buffer and fills in both this and any children with associated objects
|
||||
// Returns TRUE if it produced a valid Shell
|
||||
// Must be overridden in the concerte derived class
|
||||
const char *GetBodyType() { return m_bodyType; }
|
||||
const char *GetBodySubType() { return m_bodySubType; }
|
||||
|
||||
TIMAPBodypart(TIMAPBodyShell *shell, char *partNumber, const char *buf, TIMAPBodypart *parentPart);
|
||||
|
||||
protected:
|
||||
TIMAPBodyShell *m_shell; // points back to the shell
|
||||
XP_Bool m_isValid; // If this part is valid.
|
||||
int m_partNumber; // part number on this hierarchy level
|
||||
char *m_partNumberString; // string representation of this part's full-hierarchy number. Define 0 to be the top-level message
|
||||
char *m_partData; // data for this part. NULL if not filled in yet.
|
||||
char *m_headerData; // data for this part's MIME header. NULL if not filled in yet.
|
||||
char *m_boundaryData; // MIME boundary for this part
|
||||
int32 m_partLength;
|
||||
int32 m_contentLength; // Total content length which will be Generate()'d. -1 if not filled in yet.
|
||||
char *m_responseBuffer; // The buffer for this object
|
||||
TIMAPBodypart *m_parentPart; // Parent of this part
|
||||
|
||||
// Fields - Filled in from parsed BODYSTRUCTURE response (as well as others)
|
||||
char *m_contentType; // constructed from m_bodyType and m_bodySubType
|
||||
char *m_bodyType;
|
||||
char *m_bodySubType;
|
||||
char *m_bodyID;
|
||||
char *m_bodyDescription;
|
||||
char *m_bodyEncoding;
|
||||
// we ignore extension data for now
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Message headers
|
||||
// A special type of TIMAPBodypart
|
||||
// These may be headers for the top-level message,
|
||||
// or any body part of type message/rfc822.
|
||||
class TIMAPMessageHeaders : public TIMAPBodypart
|
||||
{
|
||||
public:
|
||||
TIMAPMessageHeaders(TIMAPBodyShell *shell, char *partNum, TIMAPBodypart *parentPart);
|
||||
virtual TIMAPBodypartType GetType();
|
||||
virtual int32 Generate(XP_Bool stream, XP_Bool prefetch); // Generates an HTML representation of this part. Returns content length generated, -1 if failed.
|
||||
virtual XP_Bool ShouldFetchInline();
|
||||
virtual void QueuePrefetchMessageHeaders();
|
||||
protected:
|
||||
virtual XP_Bool ParseIntoObjects(); // Parses m_responseBuffer and fills in m_partList with associated objects
|
||||
// Returns TRUE if it produced a valid Shell
|
||||
|
||||
};
|
||||
|
||||
|
||||
class TIMAPBodypartMultipart : public TIMAPBodypart
|
||||
{
|
||||
public:
|
||||
TIMAPBodypartMultipart(TIMAPBodyShell *shell, char *partNum, const char *buf, TIMAPBodypart *parentPart);
|
||||
virtual TIMAPBodypartType GetType();
|
||||
virtual ~TIMAPBodypartMultipart();
|
||||
virtual XP_Bool ShouldFetchInline();
|
||||
virtual XP_Bool PreflightCheckAllInline();
|
||||
virtual int32 Generate(XP_Bool stream, XP_Bool prefetch); // Generates an HTML representation of this part. Returns content length generated, -1 if failed.
|
||||
virtual TIMAPBodypart *FindPartWithNumber(const char *partNum); // Returns the part object with the given number
|
||||
|
||||
protected:
|
||||
virtual XP_Bool ParseIntoObjects();
|
||||
|
||||
protected:
|
||||
XPPtrArray *m_partList; // An ordered list of top-level body parts for this shell
|
||||
};
|
||||
|
||||
|
||||
// The name "leaf" is somewhat misleading, since a part of type message/rfc822 is technically
|
||||
// a leaf, even though it can contain other parts within it.
|
||||
class TIMAPBodypartLeaf : public TIMAPBodypart
|
||||
{
|
||||
public:
|
||||
TIMAPBodypartLeaf(TIMAPBodyShell *shell, char *partNum, const char *buf, TIMAPBodypart *parentPart);
|
||||
virtual TIMAPBodypartType GetType();
|
||||
virtual int32 Generate(XP_Bool stream, XP_Bool prefetch); // Generates an HTML representation of this part. Returns content length generated, -1 if failed.
|
||||
virtual XP_Bool ShouldFetchInline(); // returns TRUE if this part should be fetched inline for generation.
|
||||
virtual XP_Bool PreflightCheckAllInline();
|
||||
|
||||
protected:
|
||||
virtual XP_Bool ParseIntoObjects();
|
||||
|
||||
};
|
||||
|
||||
|
||||
class TIMAPBodypartMessage : public TIMAPBodypartLeaf
|
||||
{
|
||||
public:
|
||||
TIMAPBodypartMessage(TIMAPBodyShell *shell, char *partNum, const char *buf, TIMAPBodypart *parentPart, XP_Bool topLevelMessage);
|
||||
virtual TIMAPBodypartType GetType();
|
||||
virtual ~TIMAPBodypartMessage();
|
||||
virtual int32 Generate(XP_Bool stream, XP_Bool prefetch);
|
||||
virtual XP_Bool ShouldFetchInline();
|
||||
virtual XP_Bool PreflightCheckAllInline();
|
||||
virtual TIMAPBodypart *FindPartWithNumber(const char *partNum); // Returns the part object with the given number
|
||||
void AdoptMessageHeaders(char *headers); // Fills in buffer (and adopts storage) for header object
|
||||
// partNum specifies the message part number to which the
|
||||
// headers correspond. NULL indicates the top-level message
|
||||
virtual TIMAPBodypartMessage *GetTIMAPBodypartMessage() { return this; }
|
||||
virtual XP_Bool GetIsTopLevelMessage() { return m_topLevelMessage; }
|
||||
|
||||
protected:
|
||||
virtual XP_Bool ParseIntoObjects();
|
||||
|
||||
protected:
|
||||
TIMAPMessageHeaders *m_headers; // Every body shell should have headers
|
||||
TIMAPBodypart *m_body;
|
||||
XP_Bool m_topLevelMessage; // Whether or not this is the top-level message
|
||||
|
||||
};
|
||||
|
||||
|
||||
class TIMAPMessagePartIDArray;
|
||||
|
||||
// We will refer to a Body "Shell" as a hierarchical object representation of a parsed BODYSTRUCTURE
|
||||
// response. A shell contains representations of Shell "Parts." A Body Shell can undergo essentially
|
||||
// two operations: Construction and Generation.
|
||||
// Shell Construction occurs by parsing a BODYSTRUCTURE response into empty Parts.
|
||||
// Shell Generation generates a "MIME Shell" of the message and streams it to libmime for
|
||||
// display. The MIME Shell has selected (inline) parts filled in, and leaves all others
|
||||
// for on-demand retrieval through explicit part fetches.
|
||||
|
||||
class TIMAPBodyShell
|
||||
{
|
||||
public:
|
||||
|
||||
// Construction
|
||||
TIMAPBodyShell(TNavigatorImapConnection *connection, const char *bs, uint32 UID, const char *folderName); // Constructor takes in a buffer containing an IMAP
|
||||
// bodystructure response from the server, with the associated
|
||||
// tag/command/etc. stripped off.
|
||||
// That is, it takes in something of the form:
|
||||
// (("TEXT" "PLAIN" ..... ))
|
||||
virtual ~TIMAPBodyShell();
|
||||
void SetConnection(TNavigatorImapConnection *con) { m_connection = con; } // To be used after a shell is uncached
|
||||
virtual XP_Bool GetIsValid() { return m_isValid; }
|
||||
virtual void SetIsValid(XP_Bool valid);
|
||||
|
||||
// Prefetch
|
||||
void AddPrefetchToQueue(TIMAP4BlockingConnection::eFetchFields, const char *partNum); // Adds a message body part to the queue to be prefetched
|
||||
// in a single, pipelined command
|
||||
void FlushPrefetchQueue(); // Runs a single pipelined command which fetches all of the
|
||||
// elements in the prefetch queue
|
||||
void AdoptMessageHeaders(char *headers, const char *partNum); // Fills in buffer (and adopts storage) for header object
|
||||
// partNum specifies the message part number to which the
|
||||
// headers correspond. NULL indicates the top-level message
|
||||
void AdoptMimeHeader(const char *partNum, char *mimeHeader); // Fills in buffer (and adopts storage) for MIME headers in appropriate object.
|
||||
// If object can't be found, sets isValid to FALSE.
|
||||
|
||||
// Generation
|
||||
virtual int32 Generate(char *partNum); // Streams out an HTML representation of this IMAP message, going along and
|
||||
// fetching parts it thinks it needs, and leaving empty shells for the parts
|
||||
// it doesn't.
|
||||
// Returns number of bytes generated, or -1 if invalid.
|
||||
// If partNum is not NULL, then this works to generates a MIME part that hasn't been downloaded yet
|
||||
// and leaves out all other parts. By default, to generate a normal message, partNum should be NULL.
|
||||
|
||||
XP_Bool GetShowAttachmentsInline(); // Returns TRUE if the user has the pref "Show Attachments Inline" set.
|
||||
// Returns FALSE if the setting is "Show Attachments as Links"
|
||||
XP_Bool PreflightCheckAllInline(); // Returns TRUE if all parts are inline, FALSE otherwise. Does not generate anything.
|
||||
|
||||
// Helpers
|
||||
TNavigatorImapConnection *GetConnection() { return m_connection; }
|
||||
XP_Bool GetPseudoInterrupted();
|
||||
XP_Bool DeathSignalReceived();
|
||||
const char *GetUID() { return m_UID; }
|
||||
const char *GetFolderName() { return m_folderName; }
|
||||
char *GetGeneratingPart() { return m_generatingPart; }
|
||||
XP_Bool IsBeingGenerated() { return m_isBeingGenerated; } // Returns TRUE if this is in the process of being
|
||||
// generated, so we don't re-enter
|
||||
XP_Bool IsShellCached() { return m_cached; }
|
||||
void SetIsCached(XP_Bool isCached) { m_cached = isCached; }
|
||||
XP_Bool GetGeneratingWholeMessage() { return m_generatingWholeMessage; }
|
||||
|
||||
protected:
|
||||
|
||||
TIMAPBodypartMessage *m_message;
|
||||
|
||||
TIMAPMessagePartIDArray *m_prefetchQueue; // array of pipelined part prefetches. Ok, so it's not really a queue.
|
||||
|
||||
XP_Bool m_isValid;
|
||||
TNavigatorImapConnection *m_connection; // Connection, for filling in parts
|
||||
char *m_UID; // UID of this message
|
||||
char *m_folderName; // folder that contains this message
|
||||
char *m_generatingPart; // If a specific part is being generated, this is it. Otherwise, NULL.
|
||||
XP_Bool m_isBeingGenerated; // TRUE if this body shell is in the process of being generated
|
||||
XP_Bool m_showAttachmentsInline;
|
||||
XP_Bool m_gotAttachmentPref;
|
||||
XP_Bool m_cached; // Whether or not this shell is cached
|
||||
XP_Bool m_generatingWholeMessage; // whether or not we are generating the whole (non-MPOD) message
|
||||
// Set to FALSE if we are generating by parts
|
||||
};
|
||||
|
||||
|
||||
|
||||
// This class caches shells, so we don't have to always go and re-fetch them.
|
||||
// This does not cache any of the filled-in inline parts; those are cached individually
|
||||
// in the libnet memory cache. (ugh, how will we do that?)
|
||||
// Since we'll only be retrieving shells for messages over a given size, and since the
|
||||
// shells themselves won't be very large, this cache will not grow very big (relatively)
|
||||
// and should handle most common usage scenarios.
|
||||
|
||||
// A body cache is associated with a given host, spanning folders.
|
||||
// It should pay attention to UIDVALIDITY.
|
||||
|
||||
class TIMAPBodyShellCache
|
||||
{
|
||||
|
||||
public:
|
||||
static TIMAPBodyShellCache *Create();
|
||||
virtual ~TIMAPBodyShellCache();
|
||||
|
||||
XP_Bool AddShellToCache(TIMAPBodyShell *shell); // Adds shell to cache, possibly ejecting
|
||||
// another entry based on scheme in EjectEntry().
|
||||
TIMAPBodyShell *FindShellForUID(const char *UID, const char *mailboxName); // Looks up a shell in the cache given the message's UID.
|
||||
TIMAPBodyShell *FindShellForUID(uint32 UID, const char *mailboxName); // Looks up a shell in the cache given the message's UID.
|
||||
// Returns the shell if found, NULL if not found.
|
||||
|
||||
protected:
|
||||
TIMAPBodyShellCache();
|
||||
XP_Bool EjectEntry(); // Chooses an entry to eject; deletes that entry; and ejects it from the cache,
|
||||
// clearing up a new space. Returns TRUE if it found an entry to eject, FALSE otherwise.
|
||||
uint32 GetSize() { return m_shellList->GetSize(); }
|
||||
uint32 GetMaxSize() { return 20; }
|
||||
|
||||
|
||||
protected:
|
||||
XPPtrArray *m_shellList; // For maintenance
|
||||
XP_HashTable m_shellHash; // For quick lookup based on UID
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
// MessagePartID and MessagePartIDArray are used for pipelining prefetches.
|
||||
|
||||
class TIMAPMessagePartID
|
||||
{
|
||||
public:
|
||||
TIMAPMessagePartID(TIMAP4BlockingConnection::eFetchFields fields, const char *partNumberString);
|
||||
TIMAP4BlockingConnection::eFetchFields GetFields() { return m_fields; }
|
||||
const char *GetPartNumberString() { return m_partNumberString; }
|
||||
|
||||
|
||||
protected:
|
||||
const char *m_partNumberString;
|
||||
TIMAP4BlockingConnection::eFetchFields m_fields;
|
||||
};
|
||||
|
||||
|
||||
class TIMAPMessagePartIDArray : public XPPtrArray {
|
||||
public:
|
||||
TIMAPMessagePartIDArray();
|
||||
~TIMAPMessagePartIDArray();
|
||||
|
||||
void RemoveAndFreeAll();
|
||||
int GetNumParts() {return GetSize();}
|
||||
TIMAPMessagePartID *GetPart(int i)
|
||||
{
|
||||
XP_ASSERT(i >= 0 && i < GetSize());
|
||||
return (TIMAPMessagePartID *) GetAt(i);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif // IMAPBODY_H
|
||||
677
mozilla/lib/libnet/imapearl.cpp
Normal file
677
mozilla/lib/libnet/imapearl.cpp
Normal file
@@ -0,0 +1,677 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
#include "imap.h"
|
||||
#include "imap4pvt.h"
|
||||
|
||||
#define ISHEX(c) ( ((c) >= '0' && (c) <= '9') || ((c) >= 'a' && (c) <= 'f') || ((c) >= 'A' && (c) <= 'F') )
|
||||
#define NONHEX(c) (!ISHEX(c))
|
||||
|
||||
extern "C" char * escape_unescaped_percents(const char *incomingURL);
|
||||
|
||||
extern "C"
|
||||
{
|
||||
char * escape_unescaped_percents(const char *incomingURL)
|
||||
{
|
||||
const char *inC;
|
||||
char *outC;
|
||||
char *result = (char *) XP_ALLOC(XP_STRLEN(incomingURL)*3+1);
|
||||
|
||||
if (result)
|
||||
{
|
||||
for(inC = incomingURL, outC = result; *inC != '\0'; inC++)
|
||||
{
|
||||
if (*inC == '%')
|
||||
{
|
||||
// Check if either of the next two characters are non-hex.
|
||||
if ( !*(inC+1) || NONHEX(*(inC+1)) || !*(inC+2) || NONHEX(*(inC+2)) )
|
||||
{
|
||||
// Hex characters don't follow, escape the
|
||||
// percent char
|
||||
*outC++ = '%'; *outC++ = '2'; *outC++ = '5';
|
||||
}
|
||||
else
|
||||
{
|
||||
// Hex characters follow, so assume the percent
|
||||
// is escaping something else
|
||||
*outC++ = *inC;
|
||||
}
|
||||
}
|
||||
else
|
||||
*outC++ = *inC;
|
||||
}
|
||||
*outC = '\0';
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
// member functions of the TIMAPUrl class
|
||||
TIMAPUrl::TIMAPUrl(const char *url_string, XP_Bool internal)
|
||||
: fHostSubString(nil),
|
||||
fUrlidSubString(nil),
|
||||
fSourceCanonicalFolderPathSubString(nil),
|
||||
fDestinationCanonicalFolderPathSubString(nil),
|
||||
fSearchCriteriaString(nil),
|
||||
fListOfMessageIds(nil),
|
||||
fTokenPlaceHolder(nil),
|
||||
fFlags(0),
|
||||
fIdsAreUids(FALSE),
|
||||
fIMAPstate(kAuthenticatedStateURL),
|
||||
fUrlType(kTest),
|
||||
fValidURL(FALSE),
|
||||
fMimePartSelectorDetected(FALSE),
|
||||
fInternal(internal),
|
||||
fDiscoveryDepth(0)
|
||||
{
|
||||
fOnlineSubDirSeparator = '/'; // initial guess
|
||||
fUrlString = escape_unescaped_percents(url_string); // this duplicates url_string
|
||||
fUrlString = NET_UnEscape(fUrlString); // ### mwelch - Put spaces and '>'s back in.
|
||||
Parse();
|
||||
}
|
||||
|
||||
|
||||
TIMAPUrl::~TIMAPUrl()
|
||||
{
|
||||
FREEIF( fUrlString);
|
||||
}
|
||||
|
||||
void TIMAPUrl::ParseFolderPath(char **resultingCanonicalPath)
|
||||
{
|
||||
*resultingCanonicalPath = fTokenPlaceHolder ? XP_STRTOK_R(nil, IMAP_URL_TOKEN_SEPARATOR, &fTokenPlaceHolder) : (char *)NULL;
|
||||
|
||||
if (!*resultingCanonicalPath)
|
||||
{
|
||||
fValidURL = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
// The delimiter will be set for a given URL, but will not be statically available
|
||||
// from an arbitrary URL. It is the creator's responsibility to fill in the correct
|
||||
// delimiter from the folder's namespace when creating the URL.
|
||||
char dirSeparator = *(*resultingCanonicalPath)++;
|
||||
if (dirSeparator != kOnlineHierarchySeparatorUnknown)
|
||||
SetOnlineSubDirSeparator( dirSeparator);
|
||||
|
||||
// if dirSeparator == kOnlineHierarchySeparatorUnknown, then this must be a create
|
||||
// of a top level imap box. If there is an online subdir, we will automatically
|
||||
// use its separator. If there is not an online subdir, we don't need a separator.
|
||||
|
||||
/*
|
||||
|
||||
// I don't think we want to do any of this anymore (for 5.0).
|
||||
|
||||
const char *hostDir = TIMAPHostInfo::GetPersonalOrDefaultOnlineSubDirForHost(GetUrlHost());
|
||||
if (!hostDir)
|
||||
{
|
||||
// couldn't find the host in our list
|
||||
fValidURL = FALSE;
|
||||
return;
|
||||
}
|
||||
int lengthOfImapSubDirString = XP_STRLEN(hostDir);
|
||||
|
||||
if (*resultingCanonicalPath &&
|
||||
((lengthOfImapSubDirString + XP_STRLEN("INBOX")) == XP_STRLEN(*resultingCanonicalPath)) &&
|
||||
!XP_STRCASECMP("INBOX", *resultingCanonicalPath + lengthOfImapSubDirString))
|
||||
{
|
||||
// this is the inbox
|
||||
*resultingCanonicalPath = "INBOX";
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
void TIMAPUrl::ParseSearchCriteriaString()
|
||||
{
|
||||
fSearchCriteriaString = fTokenPlaceHolder ? XP_STRTOK_R(nil, IMAP_URL_TOKEN_SEPARATOR, &fTokenPlaceHolder) : (char *)NULL;
|
||||
if (!fSearchCriteriaString)
|
||||
fValidURL = FALSE;
|
||||
}
|
||||
|
||||
|
||||
void TIMAPUrl::ParseChildDiscoveryDepth()
|
||||
{
|
||||
char *discoveryDepth = fTokenPlaceHolder ? XP_STRTOK_R(nil, IMAP_URL_TOKEN_SEPARATOR, &fTokenPlaceHolder) : (char *)NULL;
|
||||
if (!discoveryDepth)
|
||||
{
|
||||
fValidURL = FALSE;
|
||||
fDiscoveryDepth = 0;
|
||||
return;
|
||||
}
|
||||
fDiscoveryDepth = atoi(discoveryDepth);
|
||||
}
|
||||
|
||||
void TIMAPUrl::ParseUidChoice()
|
||||
{
|
||||
char *uidChoiceString = fTokenPlaceHolder ? XP_STRTOK_R(nil, IMAP_URL_TOKEN_SEPARATOR, &fTokenPlaceHolder) : (char *)NULL;
|
||||
if (!uidChoiceString)
|
||||
fValidURL = FALSE;
|
||||
else
|
||||
fIdsAreUids = XP_STRCMP(uidChoiceString, "UID") == 0;
|
||||
}
|
||||
|
||||
void TIMAPUrl::ParseMsgFlags()
|
||||
{
|
||||
char *flagsPtr = fTokenPlaceHolder ? XP_STRTOK_R(nil, IMAP_URL_TOKEN_SEPARATOR, &fTokenPlaceHolder) : (char *)NULL;
|
||||
if (flagsPtr)
|
||||
{
|
||||
// the url is encodes the flags byte as ascii
|
||||
int intFlags = atoi(flagsPtr);
|
||||
fFlags = (imapMessageFlagsType) intFlags; // cast here
|
||||
}
|
||||
else
|
||||
fFlags = 0;
|
||||
}
|
||||
|
||||
void TIMAPUrl::ParseListofMessageIds()
|
||||
{
|
||||
fListOfMessageIds = fTokenPlaceHolder ? XP_STRTOK_R(nil, IMAP_URL_TOKEN_SEPARATOR, &fTokenPlaceHolder) : (char *)NULL;
|
||||
if (!fListOfMessageIds)
|
||||
fValidURL = FALSE;
|
||||
else
|
||||
{
|
||||
fMimePartSelectorDetected = XP_STRSTR(fListOfMessageIds, "&part=") != 0;
|
||||
}
|
||||
}
|
||||
|
||||
void TIMAPUrl::Parse()
|
||||
{
|
||||
fValidURL = TRUE; // hope for the best
|
||||
|
||||
// first token separator is a "?" so others can grab the host
|
||||
char *urlStartToken = XP_STRTOK_R(fUrlString, "?", &fTokenPlaceHolder);
|
||||
|
||||
if (!XP_STRNCASECMP(urlStartToken, "IMAP://",7) )
|
||||
{
|
||||
fHostSubString = urlStartToken + 7;
|
||||
fUrlidSubString = fTokenPlaceHolder ? XP_STRTOK_R(nil, IMAP_URL_TOKEN_SEPARATOR, &fTokenPlaceHolder) : (char *)NULL;
|
||||
if (!fUrlidSubString)
|
||||
{
|
||||
fValidURL = FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!XP_STRCASECMP(fUrlidSubString, "fetch"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kMsgFetch;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
}
|
||||
else if (fInternal)
|
||||
{
|
||||
if (!XP_STRCASECMP(fUrlidSubString, "header"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kMsgHeader;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "deletemsg"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kDeleteMsg;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "deleteallmsgs"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kDeleteAllMsgs;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "addmsgflags"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kAddMsgFlags;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
ParseMsgFlags();
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "subtractmsgflags"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kSubtractMsgFlags;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
ParseMsgFlags();
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "setmsgflags"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kSetMsgFlags;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
ParseMsgFlags();
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "onlinecopy"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kOnlineCopy;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "onlinemove"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kOnlineMove;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "onlinetoofflinecopy"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kOnlineToOfflineCopy;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "onlinetoofflinemove"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kOnlineToOfflineMove;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "offlinetoonlinecopy"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kOfflineToOnlineMove;
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "search"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kSearch;
|
||||
ParseUidChoice();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseSearchCriteriaString();
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "test"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kTest;
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "select"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kSelectFolder;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
if (fTokenPlaceHolder && *fTokenPlaceHolder)
|
||||
ParseListofMessageIds();
|
||||
else
|
||||
fListOfMessageIds = "";
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "liteselect"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kLiteSelectFolder;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "expunge"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kExpungeFolder;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
fListOfMessageIds = ""; // no ids to UNDO
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "create"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kCreateFolder;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "discoverchildren"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kDiscoverChildrenUrl;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "discoverlevelchildren"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kDiscoverLevelChildrenUrl;
|
||||
ParseChildDiscoveryDepth();
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "discoverallboxes"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kDiscoverAllBoxesUrl;
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "discoverallandsubscribedboxes"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kDiscoverAllAndSubscribedBoxesUrl;
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "delete"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kDeleteFolder;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "rename"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kRenameFolder;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "movefolderhierarchy"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kMoveFolderHierarchy;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
if (fTokenPlaceHolder && *fTokenPlaceHolder) // handle promote to root
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "list"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kLsubFolders;
|
||||
ParseFolderPath(&fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "biff"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kBiff;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
ParseListofMessageIds();
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "netscape"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kGetMailAccountUrl;
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "appendmsgfromfile"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kAppendMsgFromFile;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "appenddraftfromfile"))
|
||||
{
|
||||
fIMAPstate = kSelectedStateURL;
|
||||
fUrlType = kAppendMsgFromFile;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "subscribe"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kSubscribe;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "unsubscribe"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kUnsubscribe;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "refreshacl"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kRefreshACL;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "refreshfolderurls"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kRefreshFolderUrls;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "refreshallacls"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kRefreshAllACLs;
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "listfolder"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kListFolder;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "upgradetosubscription"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kUpgradeToSubscription;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else if (!XP_STRCASECMP(fUrlidSubString, "folderstatus"))
|
||||
{
|
||||
fIMAPstate = kAuthenticatedStateURL;
|
||||
fUrlType = kFolderStatus;
|
||||
ParseFolderPath(&fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
else
|
||||
fValidURL = FALSE;
|
||||
}
|
||||
else fValidURL = FALSE;
|
||||
}
|
||||
else
|
||||
fValidURL = FALSE;
|
||||
}
|
||||
|
||||
TIMAPUrl::EUrlIMAPstate TIMAPUrl::GetUrlIMAPstate()
|
||||
{
|
||||
return fIMAPstate;
|
||||
}
|
||||
|
||||
TIMAPUrl::EIMAPurlType TIMAPUrl::GetIMAPurlType()
|
||||
{
|
||||
return fUrlType;
|
||||
}
|
||||
|
||||
|
||||
|
||||
char *TIMAPUrl::CreateCanonicalSourceFolderPathString()
|
||||
{
|
||||
return XP_STRDUP(fSourceCanonicalFolderPathSubString ? fSourceCanonicalFolderPathSubString : "");
|
||||
}
|
||||
|
||||
char *TIMAPUrl::CreateCanonicalDestinationFolderPathString()
|
||||
{
|
||||
return XP_STRDUP(fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
|
||||
char *TIMAPUrl::CreateServerSourceFolderPathString()
|
||||
{
|
||||
return AllocateServerPath(fSourceCanonicalFolderPathSubString);
|
||||
}
|
||||
|
||||
char *TIMAPUrl::CreateServerDestinationFolderPathString()
|
||||
{
|
||||
// its possible for the destination folder path to be the root
|
||||
if (!fDestinationCanonicalFolderPathSubString)
|
||||
return XP_STRDUP("");
|
||||
else
|
||||
return AllocateServerPath(fDestinationCanonicalFolderPathSubString);
|
||||
}
|
||||
|
||||
char *TIMAPUrl::CreateSearchCriteriaString()
|
||||
{
|
||||
return XP_STRDUP(fSearchCriteriaString);
|
||||
}
|
||||
|
||||
char *TIMAPUrl::CreateListOfMessageIdsString()
|
||||
{
|
||||
char *returnIdString = XP_STRDUP(fListOfMessageIds);
|
||||
if (returnIdString)
|
||||
{
|
||||
// mime may have glommed a "&part=" for a part download
|
||||
// we return the entire message and let mime extract
|
||||
// the part. Pop and news work this way also.
|
||||
// this algorithm truncates the "&part" string.
|
||||
char *currentChar = returnIdString;
|
||||
while (*currentChar && (*currentChar != '&'))
|
||||
currentChar++;
|
||||
if (*currentChar == '&')
|
||||
*currentChar = 0;
|
||||
|
||||
// we should also strip off anything after "/;section="
|
||||
// since that can specify an IMAP MIME part
|
||||
char *wherepart = XP_STRSTR(returnIdString, "/;section=");
|
||||
if (wherepart)
|
||||
*wherepart = 0;
|
||||
}
|
||||
return returnIdString;
|
||||
}
|
||||
|
||||
char *TIMAPUrl::GetIMAPPartToFetch()
|
||||
{
|
||||
char *wherepart = NULL, *rv = NULL;
|
||||
if (fListOfMessageIds && (wherepart = XP_STRSTR(fListOfMessageIds, "/;section=")) != NULL)
|
||||
{
|
||||
wherepart += 10; // XP_STRLEN("/;section=")
|
||||
if (wherepart)
|
||||
{
|
||||
char *wherelibmimepart = XP_STRSTR(wherepart, "&part=");
|
||||
int len = XP_STRLEN(fListOfMessageIds), numCharsToCopy = 0;
|
||||
if (wherelibmimepart)
|
||||
numCharsToCopy = (wherelibmimepart - wherepart);
|
||||
else
|
||||
numCharsToCopy = XP_STRLEN(fListOfMessageIds) - (wherepart - fListOfMessageIds);
|
||||
if (numCharsToCopy)
|
||||
{
|
||||
rv = (char *) XP_ALLOC(sizeof(char) * (numCharsToCopy + 1));
|
||||
if (rv)
|
||||
XP_STRNCPY_SAFE(rv, wherepart, numCharsToCopy + 1); // appends a \0
|
||||
}
|
||||
}
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
|
||||
|
||||
imapMessageFlagsType TIMAPUrl::GetMsgFlags() // kAddMsgFlags or kSubtractMsgFlags only
|
||||
{
|
||||
return fFlags;
|
||||
}
|
||||
|
||||
|
||||
|
||||
XP_Bool TIMAPUrl::ValidIMAPUrl()
|
||||
{
|
||||
return fValidURL;
|
||||
}
|
||||
|
||||
XP_Bool TIMAPUrl::MessageIdsAreUids()
|
||||
{
|
||||
return fIdsAreUids;
|
||||
}
|
||||
|
||||
char *TIMAPUrl::AllocateServerPath(const char *canonicalPath)
|
||||
{
|
||||
XP_ASSERT(GetOnlineSubDirSeparator() != kOnlineHierarchySeparatorUnknown);
|
||||
return ReplaceCharsInCopiedString(canonicalPath, '/', GetOnlineSubDirSeparator());
|
||||
}
|
||||
|
||||
char *TIMAPUrl::AllocateCanonicalPath(const char *serverPath)
|
||||
{
|
||||
char *canonicalPath = ReplaceCharsInCopiedString(serverPath, GetOnlineSubDirSeparator() , '/');
|
||||
|
||||
// eat any escape characters for escaped dir separators
|
||||
if (canonicalPath)
|
||||
{
|
||||
char *currentEscapeSequence = XP_STRSTR(canonicalPath, "\\/");
|
||||
while (currentEscapeSequence)
|
||||
{
|
||||
XP_STRCPY(currentEscapeSequence, currentEscapeSequence+1);
|
||||
currentEscapeSequence = XP_STRSTR(currentEscapeSequence+1, "\\/");
|
||||
}
|
||||
}
|
||||
|
||||
return canonicalPath;
|
||||
}
|
||||
|
||||
char *TIMAPUrl::ReplaceCharsInCopiedString(const char *stringToCopy, char oldChar, char newChar)
|
||||
{
|
||||
char oldCharString[2];
|
||||
*oldCharString = oldChar;
|
||||
*(oldCharString+1) = 0;
|
||||
|
||||
char *translatedString = XP_STRDUP(stringToCopy);
|
||||
char *currentSeparator = strstr(translatedString, oldCharString);
|
||||
|
||||
while(currentSeparator)
|
||||
{
|
||||
*currentSeparator = newChar;
|
||||
currentSeparator = strstr(currentSeparator+1, oldCharString);
|
||||
}
|
||||
|
||||
return translatedString;
|
||||
}
|
||||
|
||||
void TIMAPUrl::SetOnlineSubDirSeparator(char onlineDirSeparator)
|
||||
{
|
||||
fOnlineSubDirSeparator = onlineDirSeparator;
|
||||
}
|
||||
|
||||
char TIMAPUrl::GetOnlineSubDirSeparator()
|
||||
{
|
||||
return fOnlineSubDirSeparator;
|
||||
}
|
||||
|
||||
XP_Bool TIMAPUrl::GetShouldSubscribeToAll()
|
||||
{
|
||||
return (GetOnlineSubDirSeparator() == '.');
|
||||
}
|
||||
|
||||
#if 0
|
||||
// According to the comment in imap.h, where the prototype lives and has been commented out,
|
||||
// this is obsolete. So let's get rid of the "no prototype" warning.
|
||||
extern "C" {
|
||||
void
|
||||
IMAP_SetNamespacesFromPrefs(const char *hostName, char *personalPrefix, char *publicPrefixes, char *otherUsersPrefixes)
|
||||
{
|
||||
TIMAPHostInfo::ClearPrefsNamespacesForHost(hostName);
|
||||
if (XP_STRCMP(personalPrefix,""))
|
||||
{
|
||||
TIMAPNamespace *ns = new TIMAPNamespace(kPersonalNamespace, personalPrefix, '/', TRUE);
|
||||
if (ns)
|
||||
TIMAPHostInfo::AddNewNamespaceForHost(hostName, ns);
|
||||
}
|
||||
if (XP_STRCMP(publicPrefixes,""))
|
||||
{
|
||||
TIMAPNamespace *ns = new TIMAPNamespace(kPublicNamespace, publicPrefixes, '/', TRUE);
|
||||
if (ns)
|
||||
TIMAPHostInfo::AddNewNamespaceForHost(hostName, ns);
|
||||
}
|
||||
if (XP_STRCMP(otherUsersPrefixes,""))
|
||||
{
|
||||
TIMAPNamespace *ns = new TIMAPNamespace(kOtherUsersNamespace, otherUsersPrefixes, '/', TRUE);
|
||||
if (ns)
|
||||
TIMAPHostInfo::AddNewNamespaceForHost(hostName, ns);
|
||||
}
|
||||
}
|
||||
} // extern "C"
|
||||
#endif // 0
|
||||
|
||||
203
mozilla/lib/libnet/imaphier.cpp
Normal file
203
mozilla/lib/libnet/imaphier.cpp
Normal file
@@ -0,0 +1,203 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
|
||||
#include "imaphier.h"
|
||||
#include "imap4pvt.h"
|
||||
#include "imap.h"
|
||||
|
||||
ImapHierarchyMover::ImapHierarchyMover(
|
||||
const char *destinationNodeName,
|
||||
const char *sourceNodeName,
|
||||
TNavigatorImapConnection &connection)
|
||||
: fIMAPConnection(connection)
|
||||
{
|
||||
fDestinationNodeName = XP_STRDUP(destinationNodeName);
|
||||
fSourceNodeName = XP_STRDUP(sourceNodeName);
|
||||
fMailboxHierarchy = XP_ListNew();
|
||||
}
|
||||
|
||||
|
||||
|
||||
ImapHierarchyMover::~ImapHierarchyMover()
|
||||
{
|
||||
// this is a leak, delete the structs
|
||||
if (fMailboxHierarchy)
|
||||
XP_ListDestroy(fMailboxHierarchy);
|
||||
FREEIF(fDestinationNodeName);
|
||||
FREEIF(fSourceNodeName);
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ImapHierarchyMover::AddToHierarchy(const char *nodeName)
|
||||
{
|
||||
int stringLength = XP_STRLEN(nodeName);
|
||||
char *nodeTokens = new char [stringLength + 2]; // end the string in double null so AddToSubTree
|
||||
XP_STRCPY(nodeTokens, nodeName); // will work
|
||||
*(nodeTokens + stringLength) = 0;
|
||||
*(nodeTokens + stringLength+1) = 0;
|
||||
AddToSubTree(nodeTokens, nodeName, fMailboxHierarchy);
|
||||
delete nodeTokens;
|
||||
}
|
||||
|
||||
|
||||
void ImapHierarchyMover::AddToSubTree(char *nodeTokens, const char *nodeName, XP_List *subTree)
|
||||
{
|
||||
char *positionOfNodeTokens = XP_STRSTR(nodeName, nodeTokens);
|
||||
// make sure we find the last one
|
||||
char *currentPositionOfNodeTokens = positionOfNodeTokens;
|
||||
while (currentPositionOfNodeTokens && strlen(nodeTokens))
|
||||
{
|
||||
currentPositionOfNodeTokens = XP_STRSTR(currentPositionOfNodeTokens + 1, nodeTokens);
|
||||
if (currentPositionOfNodeTokens)
|
||||
positionOfNodeTokens = currentPositionOfNodeTokens;
|
||||
}
|
||||
|
||||
char *placeHolderInTokenString = nil;
|
||||
char *currentNodeToken = XP_STRTOK_R(nodeTokens, "/",&placeHolderInTokenString);
|
||||
if (currentNodeToken)
|
||||
{
|
||||
// find the current node, if it exists
|
||||
HierarchyNode *currentNode = NULL;
|
||||
int numberOfNodes = XP_ListCount(subTree);
|
||||
XP_Bool nodeFound = FALSE;
|
||||
while (numberOfNodes && !nodeFound)
|
||||
{
|
||||
currentNode = (HierarchyNode *) XP_ListGetObjectNum(subTree, numberOfNodes--);
|
||||
nodeFound = XP_STRCMP(currentNode->fNodeToken, currentNodeToken) == 0;
|
||||
}
|
||||
|
||||
if (!nodeFound)
|
||||
{
|
||||
// create the node
|
||||
currentNode = (HierarchyNode *) XP_ALLOC(sizeof(HierarchyNode));
|
||||
if (currentNode)
|
||||
{
|
||||
currentNode->fPresentName = XP_STRDUP(nodeName);
|
||||
// less the remaining tokens
|
||||
*(currentNode->fPresentName + (positionOfNodeTokens-nodeName) + XP_STRLEN(currentNodeToken)) = 0;
|
||||
|
||||
currentNode->fNodeToken = XP_STRDUP(currentNodeToken);
|
||||
currentNode->fSubFolders = XP_ListNew();
|
||||
XP_ListAddObjectToEnd(subTree, currentNode);
|
||||
}
|
||||
}
|
||||
|
||||
// recurse!
|
||||
char *subNodeTokens = nodeTokens + XP_STRLEN(currentNodeToken) + 1; // +1 see note in AddToHierarchy
|
||||
AddToSubTree(subNodeTokens, nodeName, currentNode->fSubFolders);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// depth first, post process unsubscribe and delete everything including and below source node name
|
||||
void ImapHierarchyMover::DestroyOldFolderTree(XP_List *subTree)
|
||||
{
|
||||
int numberOfNodesAtThisLevel = XP_ListCount(subTree);
|
||||
for (int nodeIndex=numberOfNodesAtThisLevel; nodeIndex > 0; nodeIndex--)
|
||||
{
|
||||
HierarchyNode *currentNode = (HierarchyNode *) XP_ListGetObjectNum(subTree, nodeIndex);
|
||||
DestroyOldFolderTree(currentNode->fSubFolders);
|
||||
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful() &&
|
||||
XP_STRSTR(currentNode->fPresentName, fSourceNodeName))
|
||||
{
|
||||
fIMAPConnection.Unsubscribe(currentNode->fPresentName);
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
fIMAPConnection.DeleteMailbox(currentNode->fPresentName);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
// depth first, pre-process create, subscribe, and fill with messages
|
||||
void ImapHierarchyMover::CreateNewFolderTree(const char *destinationNodeName, XP_List *subTree)
|
||||
{
|
||||
int numberOfNodesAtThisLevel = XP_ListCount(subTree);
|
||||
for (int nodeIndex=1; nodeIndex <= numberOfNodesAtThisLevel; nodeIndex++)
|
||||
{
|
||||
HierarchyNode *currentNode = (HierarchyNode *) XP_ListGetObjectNum(subTree, nodeIndex);
|
||||
|
||||
if (!XP_STRSTR(fSourceNodeName, currentNode->fPresentName) ||
|
||||
!XP_STRCMP(fSourceNodeName, currentNode->fPresentName)) // if we are not yet at the node name, don't rename
|
||||
{
|
||||
char *newNodeName = (char *) XP_ALLOC(XP_STRLEN(destinationNodeName) +
|
||||
XP_STRLEN(currentNode->fNodeToken) + 2);
|
||||
XP_STRCPY(newNodeName, destinationNodeName);
|
||||
XP_STRCAT(newNodeName, "/");
|
||||
XP_STRCAT(newNodeName, currentNode->fNodeToken);
|
||||
|
||||
fIMAPConnection.CreateMailbox(newNodeName);
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
{
|
||||
fIMAPConnection.Subscribe(newNodeName);
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
{
|
||||
// close the current folder if one is selected
|
||||
if (fIMAPConnection.GetServerStateParser().GetIMAPstate() ==
|
||||
TImapServerState::kFolderSelected)
|
||||
fIMAPConnection.Close();
|
||||
|
||||
// select the old folder
|
||||
fIMAPConnection.SelectMailbox(currentNode->fPresentName);
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
{
|
||||
// copy its entire contents to the destination
|
||||
int numOfMsgs = fIMAPConnection.GetServerStateParser().NumberOfMessages();
|
||||
if (numOfMsgs)
|
||||
{
|
||||
char msgList[100]; // enough for trillions?
|
||||
sprintf(msgList, "1:%d", numOfMsgs);
|
||||
fIMAPConnection.Copy(msgList, newNodeName, FALSE); // not uids
|
||||
}
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
fIMAPConnection.Close();
|
||||
}
|
||||
}
|
||||
}
|
||||
// recurse to my children
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
CreateNewFolderTree(newNodeName, currentNode->fSubFolders);
|
||||
FREEIF( newNodeName);
|
||||
}
|
||||
else
|
||||
CreateNewFolderTree(destinationNodeName, currentNode->fSubFolders);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int ImapHierarchyMover::DoMove()
|
||||
{
|
||||
int returnValue = 0;
|
||||
|
||||
CreateNewFolderTree(fDestinationNodeName, fMailboxHierarchy);
|
||||
|
||||
if (fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
{
|
||||
DestroyOldFolderTree(fMailboxHierarchy);
|
||||
if (!fIMAPConnection.GetServerStateParser().LastCommandSuccessful())
|
||||
returnValue = -1;
|
||||
}
|
||||
else
|
||||
returnValue = -1;
|
||||
|
||||
return returnValue;
|
||||
}
|
||||
|
||||
55
mozilla/lib/libnet/imaphier.h
Normal file
55
mozilla/lib/libnet/imaphier.h
Normal 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 IMAPHIER
|
||||
#define IMAPHIER
|
||||
|
||||
#include "xp_list.h"
|
||||
|
||||
|
||||
class TNavigatorImapConnection;
|
||||
|
||||
struct HierarchyNode {
|
||||
char *fPresentName;
|
||||
char *fNodeToken; // leaf name of node
|
||||
XP_List *fSubFolders;
|
||||
};
|
||||
|
||||
class ImapHierarchyMover {
|
||||
public:
|
||||
ImapHierarchyMover(const char *destinationNodeName,
|
||||
const char *sourceNodeName,
|
||||
TNavigatorImapConnection &connection);
|
||||
virtual ~ImapHierarchyMover();
|
||||
|
||||
virtual void AddToHierarchy(const char *nodeName);
|
||||
virtual int DoMove();
|
||||
protected:
|
||||
virtual void AddToSubTree(char *nodeTokens, const char *nodeName, XP_List *subTree);
|
||||
virtual void CreateNewFolderTree(const char *destinationNodeName, XP_List *subTree);
|
||||
virtual void DestroyOldFolderTree(XP_List *subTree);
|
||||
|
||||
private:
|
||||
XP_List *fMailboxHierarchy;
|
||||
|
||||
TNavigatorImapConnection &fIMAPConnection;
|
||||
char *fDestinationNodeName;
|
||||
char *fSourceNodeName;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
3298
mozilla/lib/libnet/imappars.cpp
Normal file
3298
mozilla/lib/libnet/imappars.cpp
Normal file
File diff suppressed because it is too large
Load Diff
303
mozilla/lib/libnet/jsautocf.c
Normal file
303
mozilla/lib/libnet/jsautocf.c
Normal file
@@ -0,0 +1,303 @@
|
||||
/* -*- 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 "mkutils.h" /* LF */
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "jsautocf.h"
|
||||
#include "xp_mem.h" /* XP_NEW_ZAP() */
|
||||
#ifndef XP_MAC
|
||||
#include <sys/types.h>
|
||||
#endif
|
||||
#include "libi18n.h"
|
||||
|
||||
#include "mkstream.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "cvextcon.h"
|
||||
#include "mkformat.h"
|
||||
/* acharya: This file is obsolete and not used in this file.
|
||||
#include "il.h"
|
||||
*/
|
||||
#include "mime.h"
|
||||
#include "cvactive.h"
|
||||
#include "gui.h"
|
||||
#include "msgcom.h"
|
||||
|
||||
#include "xp_reg.h"
|
||||
#if defined(XP_UNIX) || defined(XP_WIN32)
|
||||
#include "prnetdb.h"
|
||||
#else
|
||||
#define PRHostEnt struct hostent
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Private object for the proxy config loader stream.
|
||||
*
|
||||
*
|
||||
*/
|
||||
typedef struct _JSACF_Object {
|
||||
MWContext * context;
|
||||
int flag;
|
||||
} JSACF_Object;
|
||||
|
||||
|
||||
/*
|
||||
* A struct for holding queued state.
|
||||
*
|
||||
* The state is saved when NET_GetURL() is called for the first time,
|
||||
* and the Javascript autoconfig retrieve has to be started (and finished)
|
||||
* before the first actual document can be loaded.
|
||||
*
|
||||
* A pre-exit function for the Javascript autoconfig URL restarts the
|
||||
* original URL retrieve by calling NET_GetURL() again with the
|
||||
* same parameters.
|
||||
*
|
||||
*/
|
||||
typedef struct _JSACF_QueuedState {
|
||||
URL_Struct * URL_s;
|
||||
FO_Present_Types output_format;
|
||||
MWContext * window_id;
|
||||
Net_GetUrlExitFunc* exit_routine;
|
||||
} JSACF_QueuedState;
|
||||
|
||||
PRIVATE Bool jsacf_loading = FALSE;
|
||||
PRIVATE Bool jsacf_ok = FALSE;
|
||||
PRIVATE char * jsacf_url = NULL;
|
||||
PRIVATE char * jsacf_src_buf = NULL;
|
||||
PRIVATE int jsacf_src_len = 0;
|
||||
|
||||
|
||||
/*
|
||||
* Saves out the proxy autoconfig file to disk, in case the server
|
||||
* is down the next time.
|
||||
*
|
||||
* Returns 0 on success, -1 on failure.
|
||||
*
|
||||
*/
|
||||
PRIVATE int jsacf_save_config(void)
|
||||
{
|
||||
XP_File fp;
|
||||
int32 len = 0;
|
||||
|
||||
// TODO: jonm
|
||||
if(!(fp = XP_FileOpen("", xpProxyConfig, XP_FILE_WRITE)))
|
||||
return -1;
|
||||
|
||||
len = XP_FileWrite(jsacf_src_buf, jsacf_src_len, fp);
|
||||
XP_FileClose(fp);
|
||||
if (len != jsacf_src_len)
|
||||
return -1;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Reads the proxy autoconfig file from disk.
|
||||
* This is called if the config server is not responding.
|
||||
*
|
||||
* returns 0 on success -1 on failure.
|
||||
*
|
||||
*/
|
||||
PRIVATE int jsacf_read_config(void)
|
||||
{
|
||||
XP_StatStruct st;
|
||||
XP_File fp;
|
||||
|
||||
if (XP_Stat("", &st, xpProxyConfig) == -1)
|
||||
return -1;
|
||||
|
||||
if (!(fp = XP_FileOpen("", xpProxyConfig, XP_FILE_READ)))
|
||||
return -1;
|
||||
|
||||
jsacf_src_len = st.st_size;
|
||||
jsacf_src_buf = (char *)XP_ALLOC(jsacf_src_len + 1);
|
||||
if (!jsacf_src_buf) {
|
||||
XP_FileClose(fp);
|
||||
jsacf_src_len = 0;
|
||||
return -1;
|
||||
}
|
||||
|
||||
if ((jsacf_src_len = XP_FileRead(jsacf_src_buf, jsacf_src_len, fp)) > 0)
|
||||
{
|
||||
jsacf_src_buf[jsacf_src_len] = '\0';
|
||||
}
|
||||
else
|
||||
{
|
||||
XP_FREE(jsacf_src_buf);
|
||||
jsacf_src_buf = NULL;
|
||||
jsacf_src_len = 0;
|
||||
}
|
||||
|
||||
XP_FileClose(fp);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
* Private stream object methods for receiving the proxy autoconfig
|
||||
* file.
|
||||
*
|
||||
*
|
||||
*/
|
||||
PRIVATE int jsacf_write(NET_StreamClass *stream, CONST char *buf, int32 len)
|
||||
{
|
||||
JSACF_Object *obj=stream->data_object;
|
||||
if (len > 0) {
|
||||
if (!jsacf_src_buf)
|
||||
jsacf_src_buf = (char*)XP_ALLOC(len + 1);
|
||||
else
|
||||
jsacf_src_buf = (char*)XP_REALLOC(jsacf_src_buf,
|
||||
jsacf_src_len + len + 1);
|
||||
|
||||
if (!jsacf_src_buf) { /* Out of memory */
|
||||
jsacf_src_len = 0;
|
||||
return MK_DATA_LOADED;
|
||||
}
|
||||
|
||||
XP_MEMCPY(jsacf_src_buf + jsacf_src_len, buf, len);
|
||||
jsacf_src_len += len;
|
||||
jsacf_src_buf[jsacf_src_len] = '\0';
|
||||
}
|
||||
return MK_DATA_LOADED;
|
||||
}
|
||||
|
||||
|
||||
PRIVATE unsigned int jsacf_write_ready(NET_StreamClass *stream)
|
||||
{
|
||||
return MAX_WRITE_READY;
|
||||
}
|
||||
|
||||
extern int PREF_EvaluateJSBuffer(char * js_buffer, size_t length);
|
||||
|
||||
PRIVATE void jsacf_complete(NET_StreamClass *stream)
|
||||
{
|
||||
JSACF_Object *obj=stream->data_object;
|
||||
int err = PREF_EvaluateJSBuffer(jsacf_src_buf,jsacf_src_len);
|
||||
if (jsacf_src_buf) XP_FREE(jsacf_src_buf);
|
||||
}
|
||||
|
||||
|
||||
PRIVATE void jsacf_abort(NET_StreamClass *stream, int status)
|
||||
{
|
||||
JSACF_Object *obj=stream->data_object;
|
||||
jsacf_loading = FALSE;
|
||||
// FE_Alert(obj->context, CONFIG_LOAD_ABORTED);
|
||||
XP_FREE(obj);
|
||||
}
|
||||
|
||||
/*
|
||||
* A stream constructor function for application/x-ns-proxy-autoconfig.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
MODULE_PRIVATE NET_StreamClass *
|
||||
NET_JavaScriptAutoConfig(int fmt, void *data_obj, URL_Struct *URL_s, MWContext *w)
|
||||
{
|
||||
JSACF_Object *obj;
|
||||
NET_StreamClass *stream;
|
||||
|
||||
#ifdef LATER
|
||||
if (!jsacf_loading) {
|
||||
/*
|
||||
* The Navigator didn't start this config retrieve
|
||||
* intentionally. Discarding the config.
|
||||
*/
|
||||
alert2(w, CONFIG_BLAST_WARNING, URL_s->address);
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
NET_Progress(w, XP_GetString( XP_RECEIVING_PROXY_AUTOCFG ) );
|
||||
}
|
||||
#endif
|
||||
|
||||
if (jsacf_src_buf) {
|
||||
XP_FREE(jsacf_src_buf);
|
||||
jsacf_src_buf = NULL;
|
||||
jsacf_src_len = 0;
|
||||
}
|
||||
|
||||
if (!(stream = XP_NEW_ZAP(NET_StreamClass)))
|
||||
return NULL;
|
||||
|
||||
if (!(obj = XP_NEW_ZAP(JSACF_Object))) {
|
||||
XP_FREE(stream);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
obj->context = w;
|
||||
|
||||
stream->data_object = obj;
|
||||
stream->name = "JavaScriptAutoConfigLoader";
|
||||
stream->complete = (MKStreamCompleteFunc) jsacf_complete;
|
||||
stream->abort = (MKStreamAbortFunc) jsacf_abort;
|
||||
stream->put_block = (MKStreamWriteFunc) jsacf_write;
|
||||
stream->is_write_ready = (MKStreamWriteReadyFunc)jsacf_write_ready;
|
||||
stream->window_id = w;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
||||
|
||||
void jsacf_exit_routine(URL_Struct *URL_s, int status, MWContext *window_id)
|
||||
{}
|
||||
|
||||
PRIVATE void
|
||||
simple_exit(URL_Struct *URL_s, int status, MWContext *window_id)
|
||||
{
|
||||
if(status != MK_CHANGING_CONTEXT)
|
||||
NET_FreeURLStruct(URL_s);
|
||||
}
|
||||
|
||||
/*
|
||||
* Called by mkgeturl.c to originally retrieve, and re-retrieve
|
||||
* the javascript autoconfig file.
|
||||
*
|
||||
* autoconfig_url is the URL pointing to the autoconfig.
|
||||
*
|
||||
*/
|
||||
MODULE_PRIVATE int NET_LoadJavaScriptConfig(char *autoconf_url,MWContext *window_id)
|
||||
{
|
||||
URL_Struct *my_url_s = NULL;
|
||||
|
||||
if (!autoconf_url)
|
||||
return -1;
|
||||
|
||||
StrAllocCopy(jsacf_url, autoconf_url);
|
||||
my_url_s = NET_CreateURLStruct(autoconf_url, NET_SUPER_RELOAD);
|
||||
|
||||
/* Alert the proxy autoconfig module that config is coming */
|
||||
jsacf_loading = TRUE;
|
||||
|
||||
return NET_GetURL(my_url_s, FO_CACHE_AND_JAVASCRIPT_CONFIG, window_id, simple_exit);
|
||||
//return FE_GetURL(window_id, my_url_s);
|
||||
}
|
||||
|
||||
/*
|
||||
* Returns a pointer to a NULL-terminted buffer which contains
|
||||
* the text of the proxy autoconfig file.
|
||||
*
|
||||
*
|
||||
*/
|
||||
PUBLIC char * NET_GetJavaScriptConfigSource(void)
|
||||
{
|
||||
return jsacf_src_buf;
|
||||
}
|
||||
41
mozilla/lib/libnet/jsautocf.h
Normal file
41
mozilla/lib/libnet/jsautocf.h
Normal file
@@ -0,0 +1,41 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*
|
||||
* jsautocf.h: JavaScript auto-config parser and evaluator
|
||||
*/
|
||||
|
||||
#ifndef MK_JAVASCRIPT_AUTO_CONFIG
|
||||
#define MK_JAVASCRIPT_AUTO_CONFIG
|
||||
|
||||
|
||||
#include "xp_mcom.h"
|
||||
#include "xp.h"
|
||||
|
||||
/*
|
||||
* A stream constructor function for application/x-ns-javascript-autoconfig.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
MODULE_PRIVATE NET_StreamClass *
|
||||
NET_JavaScriptAutoConfig(int fmt, void *data_obj, URL_Struct *URL_s, MWContext *w);
|
||||
|
||||
MODULE_PRIVATE int NET_LoadJavaScriptConfig(char *autoconf_url,MWContext *window_id);
|
||||
|
||||
#endif /* ! MK_JAVASCRIPT_AUTO_CONFIG */
|
||||
|
||||
604
mozilla/lib/libnet/jscookie.c
Normal file
604
mozilla/lib/libnet/jscookie.c
Normal file
@@ -0,0 +1,604 @@
|
||||
/* -*- Mode: C++; tab-width: 8; 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.
|
||||
*/
|
||||
/*
|
||||
jscookie.c -- javascript reflection of cookies for filters.
|
||||
Created: Frederick G.M. Roeber <roeber@netscape.com>, 12-Jul-97.
|
||||
Adopted: Judson Valeski, 1997.
|
||||
Large chunks of this were stolen from jsmsg.c.
|
||||
*/
|
||||
|
||||
#include "mkutils.h"
|
||||
#include "mkutils.h"
|
||||
#include "mkparse.h"
|
||||
#include "mkaccess.h"
|
||||
#include "prefapi.h"
|
||||
#include "jsapi.h"
|
||||
#include "xp_core.h"
|
||||
#include "xp_mcom.h"
|
||||
#include "jscookie.h"
|
||||
#include "ds.h"
|
||||
#include "htmldlgs.h"
|
||||
#include "xpgetstr.h"
|
||||
|
||||
extern int MK_ACCESS_JAVASCRIPT_COOKIE_FILTER;
|
||||
|
||||
static JSObject *filter_obj = NULL;
|
||||
static JSContext *filter_context = NULL;
|
||||
|
||||
static JSBool error_reporter_installed = JS_FALSE;
|
||||
static JSErrorReporter previous_error_reporter;
|
||||
|
||||
/* tells us when we should recompile the file. */
|
||||
static JSBool need_compile = JS_TRUE;
|
||||
|
||||
/* This is the private instance data associated with a cookie */
|
||||
typedef struct JSCookieData {
|
||||
JSContext *js_context;
|
||||
JSObject *js_object;
|
||||
JSCFCookieData *data;
|
||||
PRPackedBool property_changed, rejected, accepted, ask, decision_made;
|
||||
} JSCookieData;
|
||||
|
||||
/* The properties of a cookie that we reflect */
|
||||
enum cookie_slot {
|
||||
COOKIE_PATH = -1,
|
||||
COOKIE_DOMAIN = -2,
|
||||
COOKIE_NAME = -3,
|
||||
COOKIE_VALUE = -4,
|
||||
COOKIE_EXPIRES = -5,
|
||||
COOKIE_URL = -6,
|
||||
COOKIE_IS_SECURE = -7,
|
||||
COOKIE_IS_DOMAIN = -8,
|
||||
COOKIE_PROMPT_PREF = -9,
|
||||
COOKIE_PREF = -10
|
||||
};
|
||||
|
||||
/*
|
||||
* Should more of these be readonly? What does it mean for a cookie
|
||||
* to de secure? -chouck
|
||||
*/
|
||||
static JSPropertySpec cookie_props[] = {
|
||||
{ "path", COOKIE_PATH, JSPROP_ENUMERATE },
|
||||
{ "domain", COOKIE_DOMAIN, JSPROP_ENUMERATE },
|
||||
{ "name", COOKIE_NAME, JSPROP_ENUMERATE },
|
||||
{ "value", COOKIE_VALUE, JSPROP_ENUMERATE },
|
||||
{ "expires", COOKIE_EXPIRES, JSPROP_ENUMERATE },
|
||||
{ "url", COOKIE_URL, JSPROP_ENUMERATE|JSPROP_READONLY },
|
||||
{ "isSecure", COOKIE_IS_SECURE, JSPROP_ENUMERATE },
|
||||
{ "isDomain", COOKIE_IS_DOMAIN, JSPROP_ENUMERATE },
|
||||
{ "prompt", COOKIE_PROMPT_PREF, JSPROP_ENUMERATE|JSPROP_READONLY },
|
||||
{ "preference", COOKIE_PREF, JSPROP_ENUMERATE|JSPROP_READONLY },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
cookie_getProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSCookieData *data;
|
||||
JSString *str;
|
||||
jsint slot;
|
||||
|
||||
data = (JSCookieData *)JS_GetPrivate(cx, obj);
|
||||
if (!data)
|
||||
return JS_TRUE;
|
||||
|
||||
if (!JSVAL_IS_INT(id))
|
||||
return JS_TRUE;
|
||||
|
||||
slot = JSVAL_TO_INT(id);
|
||||
|
||||
switch (slot) {
|
||||
case COOKIE_PATH:
|
||||
str = JS_NewStringCopyZ(cx, (const char *)data->data->path_from_header);
|
||||
if( (JSString *)0 == str )
|
||||
return JS_FALSE;
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
case COOKIE_DOMAIN:
|
||||
str = JS_NewStringCopyZ(cx, (const char *)data->data->host_from_header);
|
||||
if( (JSString *)0 == str )
|
||||
return JS_FALSE;
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
case COOKIE_NAME:
|
||||
str = JS_NewStringCopyZ(cx, (const char *)data->data->name_from_header);
|
||||
if( (JSString *)0 == str )
|
||||
return JS_FALSE;
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
case COOKIE_VALUE:
|
||||
str = JS_NewStringCopyZ(cx, (const char *)data->data->cookie_from_header);
|
||||
if( (JSString *)0 == str )
|
||||
return JS_FALSE;
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
case COOKIE_EXPIRES:
|
||||
*vp = INT_TO_JSVAL(data->data->expires);
|
||||
break;
|
||||
case COOKIE_URL:
|
||||
str = JS_NewStringCopyZ(cx, (const char *)data->data->url);
|
||||
if( (JSString *)0 == str )
|
||||
return JS_FALSE;
|
||||
*vp = STRING_TO_JSVAL(str);
|
||||
break;
|
||||
case COOKIE_IS_SECURE:
|
||||
*vp = BOOLEAN_TO_JSVAL(data->data->secure);
|
||||
break;
|
||||
case COOKIE_IS_DOMAIN:
|
||||
*vp = BOOLEAN_TO_JSVAL(data->data->domain);
|
||||
break;
|
||||
case COOKIE_PROMPT_PREF:
|
||||
*vp = BOOLEAN_TO_JSVAL(data->data->prompt);
|
||||
break;
|
||||
case COOKIE_PREF:
|
||||
*vp = INT_TO_JSVAL(data->data->preference);
|
||||
break;
|
||||
}
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
cookie_setProperty(JSContext *cx, JSObject *obj, jsval id, jsval *vp)
|
||||
{
|
||||
JSCookieData *data;
|
||||
jsint slot;
|
||||
PRInt32 i;
|
||||
JSBool b;
|
||||
|
||||
data = (JSCookieData *)JS_GetPrivate(cx, obj);
|
||||
if (!data)
|
||||
return JS_TRUE;
|
||||
|
||||
if (!JSVAL_IS_INT(id))
|
||||
return JS_TRUE;
|
||||
|
||||
slot = JSVAL_TO_INT(id);
|
||||
|
||||
if (slot == COOKIE_PATH) {
|
||||
data->data->path_from_header = JS_GetStringBytes(JSVAL_TO_STRING(*vp));
|
||||
}
|
||||
else if (slot == COOKIE_DOMAIN) {
|
||||
data->data->host_from_header = JS_GetStringBytes(JSVAL_TO_STRING(*vp));
|
||||
}
|
||||
else if (slot == COOKIE_NAME) {
|
||||
data->data->name_from_header = JS_GetStringBytes(JSVAL_TO_STRING(*vp));
|
||||
}
|
||||
else if (slot == COOKIE_VALUE) {
|
||||
data->data->cookie_from_header = JS_GetStringBytes(JSVAL_TO_STRING(*vp));
|
||||
}
|
||||
else if (slot == COOKIE_EXPIRES) {
|
||||
if( !JS_ValueToInt32(cx, *vp, (long *)&i) )
|
||||
return JS_FALSE;
|
||||
data->data->expires = i;
|
||||
}
|
||||
else if (slot == COOKIE_IS_SECURE) {
|
||||
if( !JS_ValueToBoolean(cx, *vp, &b) )
|
||||
return JS_FALSE;
|
||||
data->data->secure = b;
|
||||
}
|
||||
else if (slot == COOKIE_IS_DOMAIN) {
|
||||
if( !JS_ValueToBoolean(cx, *vp, &b) )
|
||||
return JS_FALSE;
|
||||
data->data->domain = b;
|
||||
}
|
||||
|
||||
data->property_changed = TRUE;
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
cookie_finalize(JSContext *cx, JSObject *obj)
|
||||
{
|
||||
JSCookieData *cookie;
|
||||
cookie = JS_GetPrivate(cx, obj);
|
||||
FREEIF(cookie);
|
||||
}
|
||||
|
||||
/* So we can possibly add functions "global" to filters... */
|
||||
static JSClass global_class = {
|
||||
"CookieFilters", 0 /* no private data */,
|
||||
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub
|
||||
};
|
||||
|
||||
static JSClass js_cookie_class = {
|
||||
"Cookie", JSCLASS_HAS_PRIVATE,
|
||||
JS_PropertyStub, JS_PropertyStub, cookie_getProperty, cookie_setProperty,
|
||||
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, cookie_finalize
|
||||
};
|
||||
|
||||
/* cookie.accept() -- mark it okay */
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
cookie_accept(JSContext *cx, JSObject *obj, uint argc, jsval *argv, jsval * rval)
|
||||
{
|
||||
JSCookieData *data;
|
||||
|
||||
if (!(data = (JSCookieData*)JS_GetInstancePrivate(cx, obj, &js_cookie_class, argv)))
|
||||
return JS_FALSE;
|
||||
|
||||
data->accepted = TRUE;
|
||||
data->rejected = FALSE;
|
||||
data->ask = FALSE;
|
||||
data->decision_made = TRUE;
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* cookie.reject() -- reject it out of hand */
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
cookie_reject(JSContext *cx, JSObject *obj, uint argc, jsval *argv, jsval * rval)
|
||||
{
|
||||
JSCookieData *data;
|
||||
|
||||
if (!(data = (JSCookieData*)JS_GetInstancePrivate(cx, obj, &js_cookie_class, argv)))
|
||||
return JS_FALSE;
|
||||
|
||||
data->accepted = FALSE;
|
||||
data->rejected = TRUE;
|
||||
data->ask = FALSE;
|
||||
data->decision_made = TRUE;
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* cookie.ask() -- ask the luser, even if that pref is off */
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
cookie_ask(JSContext *cx, JSObject *obj, uint argc, jsval *argv, jsval * rval)
|
||||
{
|
||||
JSCookieData *data;
|
||||
|
||||
if (!(data = (JSCookieData*)JS_GetInstancePrivate(cx, obj, &js_cookie_class, argv)))
|
||||
return JS_FALSE;
|
||||
|
||||
data->accepted = FALSE;
|
||||
data->rejected = FALSE;
|
||||
data->ask = TRUE;
|
||||
data->decision_made = TRUE;
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
/* cookie.confirm() -- pop up a confirmation box */
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
cookie_confirm(JSContext *cx, JSObject *obj, uint argc, jsval *argv, jsval * rval)
|
||||
{
|
||||
JSCookieData *data;
|
||||
JSString *str;
|
||||
char *msg = (char *)0;
|
||||
Bool result;
|
||||
MWContext * context = XP_FindSomeContext();
|
||||
|
||||
if (argc < 1 || !context)
|
||||
return JS_FALSE;
|
||||
|
||||
if (!(data = (JSCookieData*)JS_GetInstancePrivate(cx, obj, &js_cookie_class, argv)))
|
||||
return JS_FALSE;
|
||||
|
||||
str = JS_ValueToString(cx, argv[0]);
|
||||
if (!str)
|
||||
return JS_FALSE;
|
||||
|
||||
StrAllocCopy(msg, XP_GetString(MK_ACCESS_JAVASCRIPT_COOKIE_FILTER));
|
||||
StrAllocCat(msg, JS_GetStringBytes(str));
|
||||
if (!msg)
|
||||
return JS_FALSE;
|
||||
|
||||
result = FE_Confirm(context, msg);
|
||||
FREEIF(msg);
|
||||
|
||||
*rval = BOOLEAN_TO_JSVAL(result);
|
||||
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
#if DEBUG
|
||||
/* trace() -- outputs spew to stderr. Actually, this (or something like it
|
||||
that perhaps outputs to the same file that the rest of the filter logging code
|
||||
writes to) would probably be very useful in the normal course of writing filters. */
|
||||
PR_STATIC_CALLBACK(JSBool)
|
||||
cookie_filter_trace(JSContext *cx, JSObject * obj, uint argc, jsval *argv, jsval * rval)
|
||||
{
|
||||
|
||||
if (argc > 0)
|
||||
{
|
||||
JSString *str;
|
||||
const char *trace_str;
|
||||
if (!(str = JS_ValueToString(cx, argv[0])))
|
||||
return JS_FALSE;
|
||||
|
||||
trace_str = JS_GetStringBytes(str);
|
||||
if (*trace_str != '\0')
|
||||
{
|
||||
fprintf (stderr, "cookie filter trace: %s\n", trace_str);
|
||||
}
|
||||
return JS_TRUE;
|
||||
}
|
||||
|
||||
return JS_FALSE;
|
||||
}
|
||||
#endif
|
||||
|
||||
static JSFunctionSpec cookie_methods[] = {
|
||||
{ "accept", cookie_accept, 0 },
|
||||
{ "reject", cookie_reject, 0 },
|
||||
{ "ask", cookie_ask, 0 },
|
||||
{ "confirm", cookie_confirm, 1 },
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
static JSFunctionSpec filter_methods[] = {
|
||||
#ifdef DEBUG
|
||||
{ "trace", cookie_filter_trace, 1 },
|
||||
#endif
|
||||
{ 0 }
|
||||
};
|
||||
|
||||
PRIVATE void
|
||||
destroyJSCookieFilterStuff(void)
|
||||
{
|
||||
filter_obj = NULL;
|
||||
}
|
||||
|
||||
/*
|
||||
* This function used to take an MWContext and store it as the private data
|
||||
* of the filter object. That is a no-no since the filter_obj is going to
|
||||
* be around until the end of time but there is no guarentee that the
|
||||
* context won't get free'd out from under us. The solution is to not
|
||||
* hold onto any particular context but just call XP_FindSomeContext() or
|
||||
* some derivative of it when we need to.
|
||||
*/
|
||||
PRIVATE JSContext *
|
||||
initializeJSCookieFilterStuff()
|
||||
{
|
||||
|
||||
/* Only bother initializing once */
|
||||
if (filter_obj)
|
||||
return filter_context;
|
||||
|
||||
/* If we can't get the mozilla-thread global context just bail */
|
||||
PREF_GetConfigContext(&filter_context);
|
||||
if (!filter_context)
|
||||
return NULL;
|
||||
|
||||
/* create our "global" object. We make the message object a child of this */
|
||||
filter_obj = JS_NewObject(filter_context, &global_class, NULL, NULL);
|
||||
|
||||
/* MLM - don't do JS_InitStandardClasses() twice */
|
||||
if (!filter_obj
|
||||
|| !JS_DefineFunctions(filter_context, filter_obj, filter_methods))
|
||||
{
|
||||
destroyJSCookieFilterStuff();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return filter_context;
|
||||
}
|
||||
|
||||
PRIVATE JSObject *
|
||||
newCookieObject(void)
|
||||
{
|
||||
JSObject *rv;
|
||||
JSCookieData *cookie_data;
|
||||
|
||||
rv = JS_DefineObject(filter_context, filter_obj,
|
||||
"cookie", &js_cookie_class,
|
||||
NULL, JSPROP_ENUMERATE);
|
||||
|
||||
if( (JSObject *)0 == rv )
|
||||
return (JSObject *)0;
|
||||
|
||||
cookie_data = XP_NEW_ZAP(JSCookieData);
|
||||
|
||||
if( (JSCookieData *)0 == cookie_data )
|
||||
return (JSObject *)0;
|
||||
|
||||
if( !JS_SetPrivate(filter_context, rv, cookie_data)
|
||||
|| !JS_DefineProperties(filter_context, rv, cookie_props)
|
||||
|| !JS_DefineFunctions(filter_context, rv, cookie_methods)) {
|
||||
return (JSObject *)0;
|
||||
}
|
||||
|
||||
return rv;
|
||||
}
|
||||
|
||||
PR_STATIC_CALLBACK(void)
|
||||
jscookie_ErrorReporter(JSContext *cx, const char *message, JSErrorReport *report)
|
||||
{
|
||||
char *msg = NULL;
|
||||
MWContext *context;
|
||||
|
||||
context = XP_FindSomeContext();
|
||||
if(!context || !report)
|
||||
return;
|
||||
|
||||
/*XXX: i18n-ise this */
|
||||
msg = PR_sprintf_append(NULL,
|
||||
"JavaScript Cookie Filter Error:\n"
|
||||
"You will be prompted manually to accept or reject this cookie.\n"
|
||||
"Filename: %s\n"
|
||||
"Line #: %u\n"
|
||||
"%s\n"
|
||||
"%.*s\n",
|
||||
report->filename,
|
||||
report->lineno,
|
||||
report->linebuf,
|
||||
(int)(report->tokenptr - report->linebuf) + 1,
|
||||
"^"
|
||||
);
|
||||
|
||||
if (!msg)
|
||||
return;
|
||||
|
||||
FE_Alert(context, msg);
|
||||
XP_FREE(msg);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
PRIVATE JSBool
|
||||
compileJSCookieFilters(void)
|
||||
{
|
||||
static time_t m_time = 0; /* the last modification time of filters.js */
|
||||
static JSBool ret_val = JS_FALSE;
|
||||
char *filename;
|
||||
XP_File fp;
|
||||
XP_StatStruct stats;
|
||||
|
||||
if (!need_compile)
|
||||
return ret_val;
|
||||
|
||||
filename = WH_FileName("", xpJSCookieFilters);
|
||||
|
||||
XP_Trace("+Filename for script filter is %s\n", filename);
|
||||
|
||||
/* If we can't get to the file, get the hell outa dodge. */
|
||||
if(XP_Stat(filename, &stats, xpJSCookieFilters))
|
||||
return ret_val;
|
||||
|
||||
if (stats.st_mtime > m_time || need_compile)
|
||||
{
|
||||
long fileLength;
|
||||
char *buffer;
|
||||
jsval rval;
|
||||
|
||||
m_time = stats.st_mtime;
|
||||
|
||||
fileLength = stats.st_size;
|
||||
if (fileLength <= 1)
|
||||
{
|
||||
ret_val = JS_FALSE;
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
if( !(fp = XP_FileOpen(filename, xpJSCookieFilters, "r")) ) {
|
||||
ret_val = JS_FALSE;
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
buffer = (char*)malloc(fileLength);
|
||||
if (!buffer) {
|
||||
XP_FileClose(fp);
|
||||
ret_val = JS_FALSE;
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
fileLength = XP_FileRead(buffer, fileLength, fp);
|
||||
|
||||
XP_FileClose(fp);
|
||||
|
||||
XP_Trace("+Compiling filters.js...\n");
|
||||
|
||||
ret_val = JS_EvaluateScript(filter_context, filter_obj, buffer, fileLength,
|
||||
filename, 1, &rval);
|
||||
|
||||
XP_Trace("+Done.\n");
|
||||
|
||||
XP_FREE(buffer);
|
||||
|
||||
need_compile = JS_FALSE;
|
||||
}
|
||||
|
||||
return ret_val;
|
||||
}
|
||||
|
||||
PUBLIC JSCFResult
|
||||
JSCF_Execute(
|
||||
MWContext *mwcontext,
|
||||
const char *script_name,
|
||||
JSCFCookieData *data,
|
||||
Bool *data_changed
|
||||
)
|
||||
{
|
||||
jsval result;
|
||||
jsval filter_arg; /* we will this in with the message object we create. */
|
||||
JSObject *cookie_obj;
|
||||
JSCookieData *cookie_data;
|
||||
|
||||
if (!script_name)
|
||||
return JSCF_error;
|
||||
|
||||
/* initialize the filter stuff, and bomb out early if it fails */
|
||||
if (!initializeJSCookieFilterStuff())
|
||||
return JSCF_error;
|
||||
|
||||
/*
|
||||
* try loading (reloading if necessary) the filter file before bothering
|
||||
* to create any JS-objects
|
||||
*/
|
||||
if (!compileJSCookieFilters())
|
||||
return JSCF_error;
|
||||
|
||||
if (!error_reporter_installed)
|
||||
{
|
||||
error_reporter_installed = JS_TRUE;
|
||||
previous_error_reporter = JS_SetErrorReporter(filter_context,
|
||||
jscookie_ErrorReporter);
|
||||
}
|
||||
|
||||
|
||||
cookie_obj = newCookieObject();
|
||||
if( (JSObject *)0 == cookie_obj )
|
||||
return JSCF_error;
|
||||
|
||||
cookie_data = (JSCookieData *)JS_GetPrivate(filter_context, cookie_obj);
|
||||
cookie_data->js_context = filter_context;
|
||||
cookie_data->js_object = cookie_obj;
|
||||
cookie_data->data = data;
|
||||
cookie_data->property_changed = FALSE;
|
||||
cookie_data->rejected = FALSE;
|
||||
cookie_data->accepted = FALSE;
|
||||
cookie_data->decision_made = FALSE;
|
||||
|
||||
filter_arg = OBJECT_TO_JSVAL(cookie_obj);
|
||||
JS_CallFunctionName(filter_context, filter_obj, script_name, 1,
|
||||
&filter_arg, &result);
|
||||
|
||||
*data_changed = cookie_data->property_changed;
|
||||
if( cookie_data->decision_made ) {
|
||||
if( cookie_data->rejected )
|
||||
return JSCF_reject;
|
||||
else if( cookie_data->accepted )
|
||||
return JSCF_accept;
|
||||
else if( cookie_data->ask )
|
||||
return JSCF_ask;
|
||||
}
|
||||
|
||||
return JSCF_whatever;
|
||||
}
|
||||
|
||||
PUBLIC void
|
||||
JSCF_Cleanup(void)
|
||||
{
|
||||
TRACEMSG(("+Cleaning up JS Cookie Filters"));
|
||||
|
||||
need_compile = JS_TRUE;
|
||||
|
||||
if (filter_context)
|
||||
{
|
||||
if (error_reporter_installed)
|
||||
{
|
||||
error_reporter_installed = JS_FALSE;
|
||||
JS_SetErrorReporter(filter_context, previous_error_reporter);
|
||||
}
|
||||
|
||||
JS_GC(filter_context);
|
||||
|
||||
destroyJSCookieFilterStuff();
|
||||
}
|
||||
}
|
||||
62
mozilla/lib/libnet/jscookie.h
Normal file
62
mozilla/lib/libnet/jscookie.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*
|
||||
jscookie.h -- javascript reflection of cookies for filters.
|
||||
Created: Frederick G.M. Roeber <roeber@netscape.com>, 12-Jul-97.
|
||||
Adopted: Judson Valeski, 1997
|
||||
*/
|
||||
|
||||
#ifndef _JSCOOKIE_H_
|
||||
#define _JSCOOKIE_H_
|
||||
|
||||
typedef enum {
|
||||
JSCF_accept,
|
||||
JSCF_reject,
|
||||
JSCF_ask,
|
||||
JSCF_whatever,
|
||||
JSCF_error
|
||||
}
|
||||
JSCFResult;
|
||||
|
||||
typedef struct {
|
||||
char *path_from_header;
|
||||
char *host_from_header;
|
||||
char *name_from_header;
|
||||
char *cookie_from_header;
|
||||
time_t expires;
|
||||
char *url;
|
||||
Bool secure;
|
||||
Bool domain;
|
||||
Bool prompt; /* the preference */
|
||||
NET_CookieBehaviorEnum preference;
|
||||
}
|
||||
JSCFCookieData;
|
||||
|
||||
extern JSCFResult JSCF_Execute(
|
||||
MWContext *mwcontext,
|
||||
const char *script_name,
|
||||
JSCFCookieData *data,
|
||||
Bool *data_changed
|
||||
);
|
||||
|
||||
/* runs the garbage collector on the filter context. Probably a good
|
||||
idea to call on completion of NET_GetURL or something. */
|
||||
extern void JSCF_Cleanup(void);
|
||||
|
||||
#endif /* _JSCOOKIE_H_ */
|
||||
|
||||
292
mozilla/lib/libnet/mime.types
Normal file
292
mozilla/lib/libnet/mime.types
Normal file
@@ -0,0 +1,292 @@
|
||||
#--Netscape Communications Corporation MIME Information
|
||||
# Do not delete the above line. It is used to identify the file type.
|
||||
|
||||
# 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.
|
||||
|
||||
# This file defines all of the default file extensions recognised by Netscape.
|
||||
# See also mime.types-unix and mime.types-nonunix for some platform-specific
|
||||
# stuff.
|
||||
|
||||
# If you add a new non-"text/" type to this file, and it's primarily a
|
||||
# line-based textual type, you may also want to update the list of
|
||||
# application-types-that-are-really-textual in mime_type_requires_b64_p()
|
||||
# in libmsg/compose.c, so that docs of that type don't always get base64
|
||||
# encoded when mailed.
|
||||
|
||||
####################################################################
|
||||
# Text
|
||||
####################################################################
|
||||
|
||||
exts="txt,text" type=text/plain \
|
||||
desc="Plain Text" icon=internal-gopher-text
|
||||
|
||||
exts="html,htm" type=text/html \
|
||||
desc="Hypertext Markup Language" icon=internal-gopher-text
|
||||
|
||||
exts="xml" type=text/xml \
|
||||
desc="Extensible Markup Language" icon=internal-gopher-text
|
||||
|
||||
exts="rtf" type=application/rtf \
|
||||
desc="Rich Text Format" icon=internal-gopher-text
|
||||
# note: text/richtext is *not the same format*
|
||||
|
||||
exts="pdf" type=application/pdf \
|
||||
desc="Portable Document Format" icon=internal-gopher-text
|
||||
|
||||
exts="tex" type=application/x-tex \
|
||||
desc="TeX Document" icon=internal-gopher-text
|
||||
|
||||
exts="latex" type=application/x-latex \
|
||||
desc="LaTeX Document" icon=internal-gopher-text
|
||||
|
||||
exts="dvi" type=application/x-dvi \
|
||||
desc="TeX DVI Data" icon=internal-gopher-text
|
||||
|
||||
exts="texi,texinfo" type=application/x-texinfo \
|
||||
desc="GNU TeXinfo Document" icon=internal-gopher-text
|
||||
|
||||
exts="vcf" type=text/x-vcard \
|
||||
desc="VCard" icon=internal-gopher-unknown
|
||||
|
||||
|
||||
####################################################################
|
||||
# Images
|
||||
####################################################################
|
||||
|
||||
exts="gif" type=image/gif \
|
||||
desc="GIF Image" icon=internal-gopher-image
|
||||
|
||||
exts="jpeg,jpg,jpe,jfif,pjpeg,pjp" type=image/jpeg \
|
||||
desc="JPEG Image" icon=internal-gopher-image
|
||||
|
||||
exts="tiff,tif" type=image/tiff \
|
||||
desc="TIFF Image" icon=internal-gopher-image
|
||||
|
||||
exts="ras" type=image/x-cmu-raster \
|
||||
desc="CMU Raster Image" icon=internal-gopher-image
|
||||
|
||||
exts="xbm" type=image/x-xbitmap \
|
||||
desc="X Bitmap" icon=internal-gopher-image
|
||||
# note: have also seen "image/x-bitmap"
|
||||
|
||||
exts="xpm" type=image/x-xpixmap \
|
||||
desc="X Pixmap" icon=internal-gopher-image
|
||||
# note: have also seen "image/x-xpm"
|
||||
|
||||
exts="xwd" type=image/x-xwindowdump \
|
||||
desc="X Window Dump Image" icon=internal-gopher-image
|
||||
# note: have also seen "image/x-xwd"
|
||||
|
||||
exts="pnm" type=image/x-portable-anymap \
|
||||
desc="PBM Image" icon=internal-gopher-image
|
||||
|
||||
exts="pbm" type=image/x-portable-bitmap \
|
||||
desc="PBM Image" icon=internal-gopher-image
|
||||
|
||||
exts="pgm" type=image/x-portable-graymap \
|
||||
desc="PGM Image" icon=internal-gopher-image
|
||||
|
||||
exts="ppm" type=image/x-portable-pixmap \
|
||||
desc="PPM Image" icon=internal-gopher-image
|
||||
# note: have also seen "image/x-pbm", "image/x-pgm", "image/x-ppm".
|
||||
|
||||
exts="rgb" type=image/x-rgb \
|
||||
desc="RGB Image" icon=internal-gopher-image
|
||||
|
||||
exts="bmp" type=image/x-MS-bmp \
|
||||
desc="Windows Bitmap" icon=internal-gopher-image
|
||||
|
||||
exts="pcd" type=image/x-photo-cd \
|
||||
desc="PhotoCD Image" icon=internal-gopher-image
|
||||
|
||||
exts="png" type=image/x-png \
|
||||
desc="PNG Image" icon=internal-gopher-image
|
||||
|
||||
exts="ief" type=image/ief \
|
||||
desc="" icon=internal-gopher-image
|
||||
# What is "ief"?
|
||||
|
||||
exts="fif" type=application/fractals \
|
||||
desc="Fractal Image Format" icon=internal-gopher-image
|
||||
|
||||
|
||||
####################################################################
|
||||
# Audio
|
||||
####################################################################
|
||||
|
||||
exts="au,snd" type=audio/basic \
|
||||
desc="ULAW Audio" icon=internal-gopher-sound
|
||||
|
||||
exts="aif,aiff,aifc" type=audio/x-aiff \
|
||||
desc="AIFF Audio" icon=internal-gopher-sound
|
||||
|
||||
exts="wav" type=audio/x-wav \
|
||||
desc="WAV Audio" icon=internal-gopher-sound
|
||||
|
||||
exts="mp2,mpa,abs,mpega" type=audio/x-mpeg \
|
||||
desc="MPEG Audio" icon=internal-gopher-sound
|
||||
|
||||
exts="ra,ram" type=audio/x-pn-realaudio \
|
||||
desc="RealAudio" icon=internal-gopher-sound
|
||||
|
||||
|
||||
####################################################################
|
||||
# Video
|
||||
####################################################################
|
||||
|
||||
exts="mpeg,mpg,mpe,mpv,vbs,mpegv" type=video/mpeg \
|
||||
desc="MPEG Video" icon=internal-gopher-movie
|
||||
|
||||
exts="mpv2,mp2v" type=video/x-mpeg2 \
|
||||
desc="MPEG2 Video" icon=internal-gopher-movie
|
||||
|
||||
exts="qt,mov,moov" type=video/quicktime \
|
||||
desc="Quicktime Video" icon=internal-gopher-movie
|
||||
|
||||
exts="avi" type=video/x-msvideo \
|
||||
desc="Microsoft Video" icon=internal-gopher-movie
|
||||
|
||||
|
||||
####################################################################
|
||||
# Archives
|
||||
####################################################################
|
||||
|
||||
exts="hqx" type=application/mac-binhex40 \
|
||||
desc="Macintosh BinHex Archive" icon=internal-gopher-binary
|
||||
# note: have also seen "application/x-macbinhex40"
|
||||
|
||||
exts="sit" type=application/x-stuffit \
|
||||
desc="Macintosh StuffIt Archive" icon=internal-gopher-binary
|
||||
|
||||
exts="zip" type=application/x-zip-compressed \
|
||||
desc="Zip Compressed Data" icon=internal-gopher-binary
|
||||
|
||||
exts="shar" type=application/x-shar \
|
||||
desc="Unix Shell Archive" icon=internal-gopher-unknown
|
||||
|
||||
exts="tar" type=application/x-tar \
|
||||
desc="Unix Tape Archive" icon=internal-gopher-binary
|
||||
|
||||
exts="gtar" type=application/x-gtar \
|
||||
desc="GNU Tape Archive" icon=internal-gopher-binary
|
||||
|
||||
exts="cpio" type=application/x-cpio \
|
||||
desc="Unix CPIO Archive" icon=internal-gopher-binary
|
||||
# note: have also seen "application/x-sv4cpio"
|
||||
# and "application/x-bcpio" for ".bcpio" files -- what's that?
|
||||
# and "application/x-sv4crc" for ".sv4crc" -- what's that?
|
||||
|
||||
exts="jar" type=application/java-archive \
|
||||
desc="Java Archive" icon=internal-gopher-binary
|
||||
|
||||
|
||||
####################################################################
|
||||
# Programs
|
||||
####################################################################
|
||||
|
||||
exts="exe,bin" type=application/octet-stream \
|
||||
desc="Binary Executable" icon=internal-gopher-binary
|
||||
|
||||
exts="ai,eps,ps" type=application/postscript \
|
||||
desc="Postscript Document" icon=internal-gopher-text
|
||||
|
||||
exts="csh" type=application/x-csh \
|
||||
desc="C Shell Program" icon=internal-gopher-unknown
|
||||
|
||||
exts="sh" type=application/x-sh \
|
||||
desc="Bourne Shell Program" icon=internal-gopher-unknown
|
||||
|
||||
exts="tcl" type=application/x-tcl \
|
||||
desc="TCL Program" icon=internal-gopher-unknown
|
||||
|
||||
exts="pl" type=application/x-perl \
|
||||
desc="Perl Program" icon=internal-gopher-unknown
|
||||
|
||||
exts="js,mocha" type=application/x-javascript \
|
||||
desc="JavaScript Program" icon=internal-gopher-unknown
|
||||
|
||||
exts="pac" type=application/x-ns-proxy-autoconfig \
|
||||
desc="Proxy Auto-Config" icon=internal-gopher-unknown
|
||||
|
||||
exts="jsc" type=application/x-javascript-config \
|
||||
desc="JavaScript Config" icon=internal-gopher-unknown
|
||||
|
||||
exts="p7m,p7c" type=application/x-pkcs7-mime \
|
||||
desc="PKCS7 Encrypted Data" icon=internal-gopher-binary
|
||||
|
||||
exts="p7s" type=application/x-pkcs7-signature \
|
||||
desc="PKCS7 Signature" icon=internal-gopher-binary
|
||||
|
||||
exts="enc" type=application/pre-encrypted \
|
||||
desc="Pre-encrypted Data" icon=internal-gopher-binary
|
||||
|
||||
exts="crl" type=application/x-pkcs7-crl \
|
||||
desc="Certificate Revocation List" icon=internal-gopher-binary
|
||||
|
||||
exts="ckl" type=application/x-fortezza-ckl \
|
||||
desc="Compromised Key List" icon=internal-gopher-binary
|
||||
|
||||
# This is too ambiguous an extension. Those losers.
|
||||
#exts="src" type=application/x-wais-source \
|
||||
#desc="WAIS Source" icon=internal-gopher-unknown
|
||||
|
||||
####################################################################
|
||||
# Encodings
|
||||
####################################################################
|
||||
|
||||
exts="uu,uue" enc=x-uuencode \
|
||||
desc="UUEncoded Data" icon=internal-gopher-binary
|
||||
|
||||
####################################################################
|
||||
# Documents
|
||||
####################################################################
|
||||
|
||||
exts="doc,dot" type=application/msword \
|
||||
desc="Microsoft Word Document" icon=internal-gopher-text
|
||||
|
||||
exts="xls,xlt,xlm,xld,xla,xlc,xlw,xll" type=application/vnd.ms-excel \
|
||||
desc="Microsoft Excel Worksheet" icon=internal-gopher-text
|
||||
|
||||
exts="mdb,mda,mde" type=application/vnd.ms-access \
|
||||
desc="Microsoft Access Database" icon=internal-gopher-text
|
||||
|
||||
exts="ppt,pot,ppa,pps,pwz" type=application/vnd.ms-powerpoint \
|
||||
desc="Microsoft PowerPoint Show" icon=internal-gopher-text
|
||||
|
||||
exts="scd,sch,sc2" type=application/vnd.ms-schedule \
|
||||
desc="Microsoft Schedule+ Application" icon=internal-gopher-text
|
||||
|
||||
exts="lwp,sam" type=application/vnd.lotus-wordpro \
|
||||
desc="Lotus WordPro Document" icon=internal-gopher-text
|
||||
|
||||
exts="123,wk4,wk3,wk1" type=application/vnd.lotus-1-2-3 \
|
||||
desc="Lotus 123 Document" icon=internal-gopher-text
|
||||
|
||||
exts="apr,vew" type=application/vnd.lotus-approach \
|
||||
desc="Lotus Approach Document" icon=internal-gopher-text
|
||||
|
||||
exts="prz,pre" type=application/vnd.lotus-freelance \
|
||||
desc="Lotus Freelance Document" icon=internal-gopher-text
|
||||
|
||||
exts="or3,or2,org" type=application/vnd.lotus-organizer \
|
||||
desc="Lotus Organizer Document" icon=internal-gopher-text
|
||||
|
||||
exts="scm" type=application/vnd.lotus-screencam \
|
||||
desc="Lotus ScreenCam Movie" icon=internal-gopher-text
|
||||
|
||||
exts="wpd,wp6" type=application/wordperfect5.1 \
|
||||
desc="WordPerfect Document" icon=internal-gopher-text
|
||||
|
||||
30
mozilla/lib/libnet/mime.types-nonunix
Normal file
30
mozilla/lib/libnet/mime.types-nonunix
Normal file
@@ -0,0 +1,30 @@
|
||||
#--Netscape Communications Corporation MIME Information
|
||||
# Do not delete the above line. It is used to identify the file type.
|
||||
|
||||
# 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.
|
||||
|
||||
# This file defines all of the default file extensions recognised by Netscape
|
||||
# on non-Unix platforms. See also mime.types and mime.types-unix.
|
||||
|
||||
####################################################################
|
||||
# Archives
|
||||
####################################################################
|
||||
|
||||
exts="Z" type=application/x-compress \
|
||||
desc="Compressed Data" icon=internal-gopher-binary
|
||||
|
||||
exts="gz" enc=x-gzip \
|
||||
desc="GNU Zip Compressed Data" icon=internal-gopher-binary
|
||||
56
mozilla/lib/libnet/mime.types-unix
Normal file
56
mozilla/lib/libnet/mime.types-unix
Normal file
@@ -0,0 +1,56 @@
|
||||
#--Netscape Communications Corporation MIME Information
|
||||
# Do not delete the above line. It is used to identify the file type.
|
||||
|
||||
# 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.
|
||||
|
||||
# This file defines all of the default file extensions recognised by Netscape
|
||||
# on Unix platforms. See also mime.types and mime.types-nonunix.
|
||||
|
||||
|
||||
####################################################################
|
||||
# Text
|
||||
####################################################################
|
||||
|
||||
exts="t,tr,roff" type=application/x-troff \
|
||||
desc="TROFF Document" icon=internal-gopher-text
|
||||
|
||||
exts="me" type=application/x-troff-me \
|
||||
desc="TROFF Document" icon=internal-gopher-text
|
||||
|
||||
exts="ms" type=application/x-troff-ms \
|
||||
desc="TROFF Document" icon=internal-gopher-text
|
||||
|
||||
exts="man" type=application/x-troff-man \
|
||||
desc="Unix Manual Page" icon=internal-gopher-text
|
||||
|
||||
|
||||
####################################################################
|
||||
# Video
|
||||
####################################################################
|
||||
|
||||
exts="movie" type=video/x-sgi-movie \
|
||||
desc="SGI Video" icon=internal-gopher-movie
|
||||
|
||||
|
||||
####################################################################
|
||||
# Encodings
|
||||
####################################################################
|
||||
|
||||
exts="Z" enc=x-compress \
|
||||
desc="Compressed Data" icon=internal-gopher-binary
|
||||
|
||||
exts="gz" enc=x-gzip \
|
||||
desc="GNU Zip Compressed Data" icon=internal-gopher-binary
|
||||
85
mozilla/lib/libnet/mkabook.cpp
Normal file
85
mozilla/lib/libnet/mkabook.cpp
Normal file
@@ -0,0 +1,85 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
//
|
||||
// mkabook.cpp -- Handles "addbook:" " URLs for core Navigator, without
|
||||
// requiring libmsg. mkabook is intended for adding
|
||||
// to the address-book.
|
||||
//
|
||||
//
|
||||
|
||||
#include "mkutils.h"
|
||||
|
||||
#include "xp.h"
|
||||
#include "xp_str.h"
|
||||
|
||||
#include "mkgeturl.h"
|
||||
#include "mkabook.h"
|
||||
#include "addrbook.h"
|
||||
|
||||
//
|
||||
// Callbacks from NET_GetURL
|
||||
//
|
||||
|
||||
extern "C" int32 net_AddressBookLoad (ActiveEntry *ce)
|
||||
{
|
||||
char * url = ce->URL_s->address;
|
||||
char * path = NET_ParseURL(url, GET_PATH_PART);
|
||||
char * search = NET_ParseURL(url, GET_SEARCH_PART);
|
||||
if (!XP_STRNCASECMP(path,"add",3)) {
|
||||
if (!XP_STRNCASECMP (search, "?vcard=", 7)) {
|
||||
ABook* addressbook = FE_GetAddressBook(NULL);
|
||||
if (addressbook)
|
||||
AB_ImportFromVcardURL(addressbook, ce->window_id, NET_UnEscape(search+7));
|
||||
}
|
||||
}
|
||||
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
extern "C" int32 net_ProcessAddressBook (ActiveEntry *ce)
|
||||
{
|
||||
XP_ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
extern "C" int32 net_InterruptAddressBook (ActiveEntry * ce)
|
||||
{
|
||||
XP_ASSERT(0);
|
||||
return -1;
|
||||
}
|
||||
|
||||
extern "C" void
|
||||
net_CleanupAddressBook(void)
|
||||
{
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
NET_InitAddressBookProtocol(void)
|
||||
{
|
||||
static NET_ProtoImpl abook_proto_impl;
|
||||
|
||||
abook_proto_impl.init = net_AddressBookLoad;
|
||||
abook_proto_impl.process = net_ProcessAddressBook;
|
||||
abook_proto_impl.interrupt = net_InterruptAddressBook;
|
||||
abook_proto_impl.cleanup = net_CleanupAddressBook;
|
||||
|
||||
NET_RegisterProtocolImplementation(&abook_proto_impl, ADDRESS_BOOK_TYPE_URL);
|
||||
}
|
||||
|
||||
27
mozilla/lib/libnet/mkabook.h
Normal file
27
mozilla/lib/libnet/mkabook.h
Normal file
@@ -0,0 +1,27 @@
|
||||
/* -*- 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 MKABOOK_H
|
||||
#define MKABOOK_H
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
void NET_InitAddressBookProtocol(void);
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif
|
||||
2900
mozilla/lib/libnet/mkaccess.c
Normal file
2900
mozilla/lib/libnet/mkaccess.c
Normal file
File diff suppressed because it is too large
Load Diff
131
mozilla/lib/libnet/mkaccess.h
Normal file
131
mozilla/lib/libnet/mkaccess.h
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- 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 MKACCESS_H
|
||||
#define MKACCESS_H
|
||||
|
||||
#ifndef MKGETURL_H
|
||||
#include "mkgeturl.h"
|
||||
#endif
|
||||
/* returns TRUE if authorization is required
|
||||
*/
|
||||
extern Bool NET_AuthorizationRequired(char * address);
|
||||
|
||||
/* returns false if the user wishes to cancel authorization
|
||||
* and TRUE if the user wants to continue with a new authorization
|
||||
* string
|
||||
*/
|
||||
extern Bool NET_AskForAuthString(MWContext * context,
|
||||
URL_Struct *URL_s,
|
||||
char * authenticate,
|
||||
char * prot_template,
|
||||
Bool already_sent_auth);
|
||||
|
||||
/* returns a authorization string if one is required, otherwise
|
||||
* returns NULL
|
||||
*/
|
||||
extern char * NET_BuildAuthString(MWContext * context, URL_Struct *URL_s);
|
||||
|
||||
/* removes all authorization structs from the auth list */
|
||||
extern void
|
||||
NET_RemoveAllAuthorizations();
|
||||
|
||||
/* removes all cookies structs from the cookie list */
|
||||
extern void
|
||||
NET_RemoveAllCookies();
|
||||
|
||||
/* returns TRUE if authorization is required
|
||||
*/
|
||||
extern char *
|
||||
NET_GetCookie(MWContext * context, char * address);
|
||||
|
||||
extern void
|
||||
NET_SetCookieString(MWContext * context,
|
||||
char * cur_url,
|
||||
char * set_cookie_header);
|
||||
|
||||
/* wrapper of NET_SetCookieString for netlib use. We need outformat and url_struct to determine
|
||||
* whether we're dealing with inline cookies */
|
||||
extern void
|
||||
NET_SetCookieStringFromHttp(FO_Present_Types outputFormat,
|
||||
URL_Struct * URL_s,
|
||||
MWContext * context,
|
||||
char * cur_url,
|
||||
char * set_cookie_header);
|
||||
|
||||
/* saves out the HTTP cookies to disk
|
||||
*
|
||||
* on entry pass in the name of the file to save
|
||||
*
|
||||
* returns 0 on success -1 on failure.
|
||||
*
|
||||
*/
|
||||
extern int NET_SaveCookies(char * filename);
|
||||
|
||||
/* reads HTTP cookies from disk
|
||||
*
|
||||
* on entry pass in the name of the file to read
|
||||
*
|
||||
* returns 0 on success -1 on failure.
|
||||
*
|
||||
*/
|
||||
extern int NET_ReadCookies(char * filename);
|
||||
|
||||
|
||||
/*
|
||||
* Builds the Proxy-authorization string
|
||||
*/
|
||||
extern char *
|
||||
NET_BuildProxyAuthString(MWContext * context,
|
||||
URL_Struct * url_s,
|
||||
char * proxy_addr);
|
||||
|
||||
/*
|
||||
* Returns FALSE if the user wishes to cancel proxy authorization
|
||||
* and TRUE if the user wants to continue with a new authorization
|
||||
* string.
|
||||
*/
|
||||
PUBLIC XP_Bool
|
||||
NET_AskForProxyAuth(MWContext * context,
|
||||
char * proxy_addr,
|
||||
char * pauth_params,
|
||||
XP_Bool already_sent_auth);
|
||||
|
||||
/*
|
||||
* Figure out better of two {WWW,Proxy}-Authenticate headers;
|
||||
* SimpleMD5 is better than Basic. Uses the order of AuthType
|
||||
* enum values.
|
||||
*
|
||||
*/
|
||||
extern XP_Bool
|
||||
net_IsBetterAuth(char *new_auth, char *old_auth);
|
||||
|
||||
/* create an HTML stream and push a bunch of HTML about cookies */
|
||||
extern void
|
||||
NET_DisplayCookieInfoAsHTML(ActiveEntry * cur_entry);
|
||||
|
||||
MODULE_PRIVATE int PR_CALLBACK
|
||||
NET_CookieBehaviorPrefChanged(const char * newpref, void * data);
|
||||
|
||||
MODULE_PRIVATE int PR_CALLBACK
|
||||
NET_CookieWarningPrefChanged(const char * newpref, void * data);
|
||||
|
||||
MODULE_PRIVATE int PR_CALLBACK
|
||||
NET_CookieScriptPrefChanged(const char * newpref, void * data);
|
||||
|
||||
#endif /* MKACCESS_H */
|
||||
293
mozilla/lib/libnet/mkalert.c
Normal file
293
mozilla/lib/libnet/mkalert.c
Normal file
@@ -0,0 +1,293 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
#include "mkgeturl.h"
|
||||
|
||||
#include <stdio.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
PUBLIC Bool
|
||||
FE_SecurityDialog(MWContext * context, int message)
|
||||
{
|
||||
switch(message)
|
||||
{
|
||||
case SD_INSECURE_POST_FROM_SECURE_DOC:
|
||||
case SD_INSECURE_POST_FROM_INSECURE_DOC:
|
||||
case SD_ENTERING_SECURE_SPACE:
|
||||
case SD_LEAVING_SECURE_SPACE:
|
||||
case SD_INSECURE_DOCS_WITHIN_SECURE_DOCS_NOT_SHOWN:
|
||||
case SD_REDIRECTION_TO_INSECURE_DOC:
|
||||
case SD_REDIRECTION_TO_SECURE_SITE:
|
||||
printf("Security message: %d", message);
|
||||
}
|
||||
}
|
||||
|
||||
void
|
||||
TESTFE_AllConnectionsComplete(MWContext * context)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
TESTFE_EnableClicking(MWContext * context)
|
||||
{
|
||||
}
|
||||
|
||||
void
|
||||
XFE_SetProgressBarPercent(MWContext * context, int percent)
|
||||
{
|
||||
}
|
||||
|
||||
PUBLIC const char *
|
||||
FE_UsersMailAddress(void)
|
||||
{
|
||||
return("montulli@netscape.com");
|
||||
}
|
||||
|
||||
PUBLIC const char *
|
||||
FE_UsersFullName(void)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
extern void sample_exit_routine(URL_Struct *URL_s,int status,MWContext *window_id);
|
||||
|
||||
PUBLIC void
|
||||
FE_EditMailMessage (MWContext *context,
|
||||
const char * to_address,
|
||||
const char * subject,
|
||||
const char * newsgroups,
|
||||
const char * references,
|
||||
const char * news_url)
|
||||
{
|
||||
#if 0
|
||||
URL_Struct * URL_s;
|
||||
char buffer[356];
|
||||
|
||||
XP_SPRINTF(buffer, "mailto:%.256s", to_address);
|
||||
|
||||
URL_s = NET_CreateURLStruct(buffer, FALSE);
|
||||
|
||||
StrAllocCopy(URL_s->post_headers,"Subject: This is a test\r\nX-URL: http://bogus\r\n");
|
||||
StrAllocCopy(URL_s->post_data,"This is a test, this is only a test\n");
|
||||
URL_s->method = URL_POST_METHOD;
|
||||
|
||||
NET_GetURL(URL_s, FO_CACHE_AND_PRESENT, (MWContext *)0 ,sample_exit_routine);
|
||||
|
||||
return;
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
PUBLIC void
|
||||
FE_ConnectToRemoteHost(MWContext * window_id, int url_type, char * hostname, char * port, char * username)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
extern NET_StreamClass *
|
||||
IL_NewStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *context)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
fe_MakeViewSourceStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *context)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
fe_MakeMailToStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *context)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
|
||||
fe_MakePPMStream (int format_out,
|
||||
void *data_obj,
|
||||
URL_Struct *URL_s,
|
||||
MWContext *context)
|
||||
{
|
||||
return(NULL);
|
||||
}
|
||||
|
||||
Bool
|
||||
TESTFE_ShowAllNewsArticles(MWContext * window_id)
|
||||
{
|
||||
return(FALSE);
|
||||
}
|
||||
|
||||
|
||||
intn
|
||||
LO_Format(void * data_object, PA_Tag *tag, intn status)
|
||||
{
|
||||
return(0);
|
||||
}
|
||||
|
||||
|
||||
void
|
||||
XP_Trace (const char* message, ...)
|
||||
{
|
||||
int actualLen;
|
||||
static char xp_Buffer[2048];
|
||||
va_list stack;
|
||||
|
||||
va_start (stack, message);
|
||||
actualLen = vsprintf (xp_Buffer, message, stack);
|
||||
va_end (stack);
|
||||
|
||||
fwrite(xp_Buffer, 1, strlen(xp_Buffer), stderr);
|
||||
fprintf (stderr, "\n");
|
||||
}
|
||||
|
||||
|
||||
|
||||
PUBLIC int32 FE_GetContextID(MWContext * window_id)
|
||||
{
|
||||
return((int) window_id);
|
||||
}
|
||||
|
||||
PUBLIC int TESTFE_FileSortMethod(MWContext * window_id)
|
||||
{
|
||||
return(SORT_BY_NAME);
|
||||
}
|
||||
|
||||
PUBLIC Bool TESTFE_UseFancyNewsgroupListing (MWContext * window_id)
|
||||
{
|
||||
return(TRUE);
|
||||
}
|
||||
|
||||
PUBLIC Bool TESTFE_UseFancyFTP(MWContext * window_id)
|
||||
{
|
||||
return(1);
|
||||
}
|
||||
|
||||
PUBLIC int TESTFE_CheckForInterrupt(void * window_id)
|
||||
{
|
||||
/* check check check check and check again */
|
||||
return(0);
|
||||
}
|
||||
|
||||
PUBLIC void TESTFE_Spinner (MWContext * window_id)
|
||||
{
|
||||
/* big wheel keep on rolling. Proud Mary keep on.... */
|
||||
}
|
||||
|
||||
PUBLIC void TESTFE_Alert (MWContext * window_id, CONST char * mess)
|
||||
{
|
||||
TRACEMSG(("WWW Alert: %s\n", mess));
|
||||
}
|
||||
|
||||
PUBLIC void TESTFE_Progress (MWContext * window_id, CONST char * mess)
|
||||
{
|
||||
TRACEMSG((" %s ...\n", mess));
|
||||
}
|
||||
|
||||
PUBLIC void TESTFE_GraphProgressInit (MWContext * window_id, URL_Struct *url, int32 total_length)
|
||||
{
|
||||
TRACEMSG((" GraphInit: %s is %d long...\n", url->address, total_length));
|
||||
}
|
||||
|
||||
PUBLIC void TESTFE_GraphProgressDestroy (MWContext * window_id, URL_Struct *url, int32 bytes_transferred, int32 total_length)
|
||||
{
|
||||
TRACEMSG((" GraphDestroy: %s is %d long...\n", url->address, total_length));
|
||||
}
|
||||
|
||||
PUBLIC void TESTFE_GraphProgress (MWContext * window_id, URL_Struct *url, int32 cur_length, int32 length_delta, int32 total_length)
|
||||
{
|
||||
TRACEMSG((" GraphProgress: %d of %d ...\n", cur_length, total_length));
|
||||
}
|
||||
|
||||
PUBLIC Bool TESTFE_Confirm (MWContext * window_id, CONST char * mess)
|
||||
{
|
||||
char Reply[4];
|
||||
char *URep;
|
||||
|
||||
fprintf(stderr, "WWW: %s (y/n) ", mess);
|
||||
|
||||
|
||||
fgets(Reply, 4, stdin); /* get reply, max 3 characters */
|
||||
URep=Reply;
|
||||
while (*URep) {
|
||||
if (*URep == '\n') {
|
||||
*URep = (char)0; /* Overwrite newline */
|
||||
break;
|
||||
}
|
||||
*URep=toupper(*URep);
|
||||
URep++; /* This was previously embedded in the TOUPPER */
|
||||
/* call an it became evaluated twice because */
|
||||
}
|
||||
|
||||
if ((XP_STRCMP(Reply,"YES")==0) || (XP_STRCMP(Reply,"Y")==0))
|
||||
return(YES);
|
||||
else
|
||||
return(NO);
|
||||
}
|
||||
|
||||
/* Prompt for answer and get text back
|
||||
*/
|
||||
PUBLIC char * TESTFE_Prompt (MWContext * window_id, CONST char * mess, CONST char * deflt)
|
||||
{
|
||||
char temp[512];
|
||||
char * t_string = 0;
|
||||
|
||||
fprintf(stderr, "Prompt: %s", mess);
|
||||
if (deflt) fprintf(stderr, " (RETURN for [%s]) ", deflt);
|
||||
|
||||
fgets(temp, 200, stdin);
|
||||
temp[XP_STRLEN(temp)-1] = (char)0; /* Overwrite newline */
|
||||
|
||||
StrAllocCopy(t_string, *temp ? temp : deflt);
|
||||
return t_string;
|
||||
}
|
||||
|
||||
|
||||
/* Prompt for password without echoing the reply
|
||||
*/
|
||||
PUBLIC char * TESTFE_PromptPassword (MWContext * window_id, CONST char * mess)
|
||||
{
|
||||
char *result = NULL;
|
||||
char pw[80];
|
||||
|
||||
printf("%s",mess ? mess : "Type your password:");
|
||||
scanf("%s",pw);
|
||||
|
||||
StrAllocCopy(result, pw);
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
PUBLIC void TESTFE_PromptUsernameAndPassword (MWContext * window_id,
|
||||
CONST char * mess,
|
||||
char ** username,
|
||||
char ** password)
|
||||
{
|
||||
if (mess)
|
||||
fprintf(stderr, "WWW: %s\n", mess);
|
||||
*username = TESTFE_Prompt(window_id, "Username: ", *username);
|
||||
*password = TESTFE_PromptPassword(window_id, "Password: ");
|
||||
}
|
||||
|
||||
1771
mozilla/lib/libnet/mkautocf.c
Normal file
1771
mozilla/lib/libnet/mkautocf.c
Normal file
File diff suppressed because it is too large
Load Diff
98
mozilla/lib/libnet/mkautocf.h
Normal file
98
mozilla/lib/libnet/mkautocf.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/* mkautocf.h: Proxy auto-config parser and evaluator
|
||||
* Ari Luotonen */
|
||||
|
||||
#ifndef MK_PROXY_AUTO_CONFIG
|
||||
#define MK_PROXY_AUTO_CONFIG
|
||||
|
||||
|
||||
#include "xp_mcom.h"
|
||||
#include "xp.h"
|
||||
|
||||
/*
|
||||
* Called by netlib to get a single string of "host:port" format,
|
||||
* given the XP_List containing opaque proxy config objects.
|
||||
*
|
||||
* This function will return an address to a proxy that is (to its
|
||||
* knowledge) up and running. Netlib can later inform this module
|
||||
* using the function pacf_proxy_is_down() that a proxy is down
|
||||
* and should not be called for a few minutes.
|
||||
*
|
||||
* Returns FALSE if everything has failed, and an error should be
|
||||
* displayed to the user.
|
||||
*
|
||||
* Returns TRUE if there is hope.
|
||||
* If *ret is NULL, a direct connection should be attempted.
|
||||
* If *ret is not null, it is the proxy address to use.
|
||||
*
|
||||
*/
|
||||
MODULE_PRIVATE Bool
|
||||
pacf_get_proxy_addr(MWContext *context, char *list,
|
||||
char ** ret_proxy_addr,
|
||||
u_long * ret_socks_addr,
|
||||
short * ret_socks_port);
|
||||
|
||||
|
||||
MODULE_PRIVATE char *pacf_find_proxies_for_url(MWContext *context,
|
||||
URL_Struct *URL_s);
|
||||
|
||||
|
||||
/*
|
||||
* A stream constructor function for application/x-ns-proxy-autoconfig.
|
||||
*
|
||||
*
|
||||
*
|
||||
*/
|
||||
MODULE_PRIVATE NET_StreamClass *
|
||||
NET_ProxyAutoConfig(int fmt, void *data_obj, URL_Struct *URL_s, MWContext *w);
|
||||
|
||||
|
||||
/*
|
||||
* Called by mkgeturl.c to originally retrieve, and re-retrieve
|
||||
* the proxy autoconfig file.
|
||||
*
|
||||
* autoconfig_url is the URL pointing to the autoconfig.
|
||||
*
|
||||
* The rest of the parameters are what was passed to NET_GetURL(),
|
||||
* and when the autoconfig load finishes NET_GetURL() will be called
|
||||
* with those exact same parameters.
|
||||
*
|
||||
* This is because the proxy config is loaded when NET_GetURL() is
|
||||
* called for the very first time, and the actual request must be put
|
||||
* on hold when the proxy config is being loaded.
|
||||
*
|
||||
* When called from the explicit proxy config RE-load function
|
||||
* NET_ReloadProxyConfig, the four last parameters are all zero,
|
||||
* and no request gets restarted.
|
||||
*
|
||||
*/
|
||||
MODULE_PRIVATE int NET_LoadProxyConfig(char *autoconf_url,
|
||||
URL_Struct *URL_s,
|
||||
FO_Present_Types output_format,
|
||||
MWContext *window_id,
|
||||
Net_GetUrlExitFunc *exit_routine);
|
||||
|
||||
/*
|
||||
* NET_GetNoProxyFailover
|
||||
* Returns TRUE if we're not allowing proxy failover.
|
||||
*/
|
||||
MODULE_PRIVATE Bool NET_GetNoProxyFailover(void);
|
||||
|
||||
#endif /* ! MK_PROXY_AUTO_CONFIG */
|
||||
|
||||
3430
mozilla/lib/libnet/mkcache.c
Normal file
3430
mozilla/lib/libnet/mkcache.c
Normal file
File diff suppressed because it is too large
Load Diff
69
mozilla/lib/libnet/mkcache.h
Normal file
69
mozilla/lib/libnet/mkcache.h
Normal file
@@ -0,0 +1,69 @@
|
||||
/* -*- 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 MKCACHE_H
|
||||
#define MKCACHE_H
|
||||
|
||||
#include "mkgeturl.h"
|
||||
|
||||
#ifndef EXT_CACHE_H
|
||||
#include "extcache.h"
|
||||
#endif
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
|
||||
extern void NET_CleanupCache (char * filename);
|
||||
extern int NET_FindURLInCache(URL_Struct * URL_s, MWContext *ctxt);
|
||||
extern void NET_RefreshCacheFileExpiration(URL_Struct * URL_s);
|
||||
|
||||
/* read the Cache File allocation table.
|
||||
*/
|
||||
extern void NET_ReadCacheFAT(char * cachefatfile, Bool stat_files);
|
||||
|
||||
/* remove a URL from the cache
|
||||
*/
|
||||
extern void NET_RemoveURLFromCache(URL_Struct *URL_s);
|
||||
|
||||
/* create an HTML stream and push a bunch of HTML about
|
||||
* the cache
|
||||
*/
|
||||
extern void NET_DisplayCacheInfoAsHTML(ActiveEntry * cur_entry);
|
||||
|
||||
/* trace variable for cache testing */
|
||||
extern XP_Bool NET_CacheTraceOn;
|
||||
|
||||
/* public accessor function for netcaster */
|
||||
extern Bool NET_CacheStore(net_CacheObject *cacheObject, URL_Struct *url_s, Bool accept_partial_files);
|
||||
|
||||
/* return TRUE if the URL is in the cache and
|
||||
* is a partial cache file
|
||||
*/
|
||||
extern Bool NET_IsPartialCacheFile(URL_Struct *URL_s);
|
||||
|
||||
/* encapsulated access to the first object in cache_database */
|
||||
extern int NET_FirstCacheObject(DBT *key, DBT *data);
|
||||
|
||||
/* encapsulated access to the next object in the cache_database */
|
||||
extern int NET_NextCacheObject(DBT *key, DBT *data);
|
||||
|
||||
/* Max size for displaying in the cache browser */
|
||||
extern int32 NET_GetMaxDiskCacheSize();
|
||||
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif /* MKCACHE_H */
|
||||
125
mozilla/lib/libnet/mkcburl.c
Normal file
125
mozilla/lib/libnet/mkcburl.c
Normal file
@@ -0,0 +1,125 @@
|
||||
/* -*- 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 "xp.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "netcburl.h"
|
||||
#include "secrng.h" /* For RNG_GenerateGlobalRandomBytes */
|
||||
|
||||
typedef struct _NET_CallbackURLData {
|
||||
int id;
|
||||
char* match;
|
||||
NET_CallbackURLFunc func;
|
||||
void* closure;
|
||||
struct _NET_CallbackURLData* next;
|
||||
} NET_CallbackURLData;
|
||||
|
||||
static NET_CallbackURLData* First = NULL;
|
||||
static int Counter = 1;
|
||||
|
||||
|
||||
char*
|
||||
NET_CallbackURLCreate(NET_CallbackURLFunc func, void* closure) {
|
||||
unsigned char rand_buf[13];
|
||||
char* result = NULL;
|
||||
NET_CallbackURLData* tmp;
|
||||
NET_CallbackURLFree(func, closure);
|
||||
tmp = XP_NEW(NET_CallbackURLData);
|
||||
if (!tmp) return NULL;
|
||||
tmp->id = Counter++;
|
||||
RNG_GenerateGlobalRandomBytes((void *) rand_buf, 12);
|
||||
tmp->match =
|
||||
PR_smprintf("%02X%02X%02X%02X"
|
||||
"%02X%02X%02X%02X"
|
||||
"%02X%02X%02X%02X",
|
||||
rand_buf[0], rand_buf[1], rand_buf[2], rand_buf[3],
|
||||
rand_buf[4], rand_buf[5], rand_buf[6], rand_buf[7],
|
||||
rand_buf[8], rand_buf[9], rand_buf[10], rand_buf[11]);
|
||||
if (tmp->match) {
|
||||
result = PR_smprintf("internal-callback-handler:%d/%s",
|
||||
tmp->id, tmp->match);
|
||||
}
|
||||
if (result == NULL) {
|
||||
if (tmp->match) XP_FREE(tmp->match);
|
||||
XP_FREE(tmp);
|
||||
return NULL;
|
||||
}
|
||||
tmp->next = First;
|
||||
First = tmp;
|
||||
tmp->func = func;
|
||||
tmp->closure = closure;
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
NET_CallbackURLFree(NET_CallbackURLFunc func, void* closure) {
|
||||
NET_CallbackURLData** tmp;
|
||||
NET_CallbackURLData* t;
|
||||
for (tmp = &First ; *tmp ; tmp = &((*tmp)->next)) {
|
||||
t = *tmp;
|
||||
if (t->func == func && t->closure == closure) {
|
||||
*tmp = t->next;
|
||||
XP_FREE(t->match);
|
||||
XP_FREE(t);
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
||||
int NET_LoadCallbackURL (ActiveEntry* ce)
|
||||
{
|
||||
char* url = ce->URL_s->address;
|
||||
char* path;
|
||||
char* match;
|
||||
int id;
|
||||
NET_CallbackURLData* tmp;
|
||||
|
||||
path = NET_ParseURL(url, GET_PATH_PART);
|
||||
if (path == NULL) return -1;
|
||||
id = XP_ATOI(path);
|
||||
match = XP_STRCHR(path, '/');
|
||||
if (match) match++;
|
||||
else match = "";
|
||||
|
||||
for (tmp = First ; tmp ; tmp = tmp->next) {
|
||||
if (id == tmp->id && XP_STRCMP(match, tmp->match) == 0) {
|
||||
(*tmp->func)(tmp->closure, url);
|
||||
break;
|
||||
}
|
||||
}
|
||||
XP_FREE(path);
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
int NET_ProcessCallbackURL(ActiveEntry* ce)
|
||||
{
|
||||
return -1; /* Should never get here */
|
||||
}
|
||||
|
||||
|
||||
int NET_InterruptCallbackURL(ActiveEntry* ce)
|
||||
{
|
||||
return -1; /* Should never get here */
|
||||
}
|
||||
|
||||
131
mozilla/lib/libnet/mkcertld.c
Normal file
131
mozilla/lib/libnet/mkcertld.c
Normal file
@@ -0,0 +1,131 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "net.h"
|
||||
#include "secnav.h"
|
||||
#include "ldap.h"
|
||||
#include "certldap.h"
|
||||
#include "mkcertld.h"
|
||||
|
||||
PRIVATE int32
|
||||
net_CertLdapLoad(ActiveEntry *ce)
|
||||
{
|
||||
int err = 0;
|
||||
CertLdapConnData *connData;
|
||||
|
||||
connData = SECNAV_CertLdapLoad(ce->URL_s);
|
||||
ce->con_data = connData;
|
||||
if ( connData == NULL ) {
|
||||
err = -1;
|
||||
}
|
||||
|
||||
if ( err ) {
|
||||
ce->status = err;
|
||||
} else {
|
||||
|
||||
#ifdef NSPR20_DISABLED /* need to convert to PRFileDesc */
|
||||
ce->socket = connData->fd;
|
||||
#endif
|
||||
XP_ASSERT(0);
|
||||
|
||||
#ifdef XP_UNIX
|
||||
NET_SetConnectSelect(ce->window_id, ce->socket);
|
||||
NET_TotalNumberOfOpenConnections++;
|
||||
#else
|
||||
NET_SetCallNetlibAllTheTime(ce->window_id, "mkcertld");
|
||||
#endif
|
||||
}
|
||||
|
||||
return(err);
|
||||
}
|
||||
|
||||
PRIVATE int32
|
||||
net_ProcessCertLdap(ActiveEntry *ce)
|
||||
{
|
||||
int err;
|
||||
CertLdapConnData *connData;
|
||||
|
||||
connData = (CertLdapConnData *)ce->con_data;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
NET_ClearConnectSelect(ce->window_id, connData->fd);
|
||||
NET_SetReadSelect(ce->window_id, connData->fd);
|
||||
#endif
|
||||
|
||||
err = SECNAV_CertLdapProcess(connData);
|
||||
|
||||
if ( err ) {
|
||||
if ( err == 1 ) {
|
||||
/* done */
|
||||
ce->status = 0;
|
||||
err = -1;
|
||||
} else {
|
||||
ce->status = err;
|
||||
}
|
||||
#ifdef XP_UNIX
|
||||
NET_ClearReadSelect(ce->window_id, connData->fd);
|
||||
NET_TotalNumberOfOpenConnections--;
|
||||
#else
|
||||
NET_ClearCallNetlibAllTheTime(ce->window_id, "mkcertld");
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
return(err);
|
||||
}
|
||||
|
||||
PRIVATE int32
|
||||
net_InterruptCertLdap(ActiveEntry *ce)
|
||||
{
|
||||
int err;
|
||||
CertLdapConnData *connData;
|
||||
|
||||
connData = (CertLdapConnData *)ce->con_data;
|
||||
|
||||
err = SECNAV_CertLdapInterrupt(connData);
|
||||
ce->status = MK_INTERRUPTED;
|
||||
|
||||
#ifdef XP_UNIX
|
||||
NET_ClearReadSelect(ce->window_id, connData->fd);
|
||||
NET_TotalNumberOfOpenConnections--;
|
||||
#else
|
||||
NET_ClearCallNetlibAllTheTime(ce->window_id, "mkcertld");
|
||||
#endif
|
||||
|
||||
return(err);
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
net_CleanupCertLdap(void)
|
||||
{
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
NET_InitCertLdapProtocol(void)
|
||||
{
|
||||
static NET_ProtoImpl certldap_proto_impl;
|
||||
|
||||
certldap_proto_impl.init = net_CertLdapLoad;
|
||||
certldap_proto_impl.process = net_ProcessCertLdap;
|
||||
certldap_proto_impl.interrupt = net_InterruptCertLdap;
|
||||
certldap_proto_impl.cleanup = net_CleanupCertLdap;
|
||||
|
||||
NET_RegisterProtocolImplementation(&certldap_proto_impl, INTERNAL_CERTLDAP_TYPE_URL);
|
||||
}
|
||||
|
||||
32
mozilla/lib/libnet/mkcertld.h
Normal file
32
mozilla/lib/libnet/mkcertld.h
Normal file
@@ -0,0 +1,32 @@
|
||||
/* -*- 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 _MKCERTLD_H_
|
||||
#define _MKCERTLD_H_
|
||||
/*
|
||||
* mkcertld.h - api to cert ldap protocol code
|
||||
*
|
||||
* $Id: mkcertld.h,v 3.1 1998-03-28 03:31:36 ltabb Exp $
|
||||
*/
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
void NET_InitCertLdapProtocol(void);
|
||||
XP_END_PROTOS
|
||||
|
||||
#endif /* _MKCERTLD_H_ */
|
||||
|
||||
|
||||
1571
mozilla/lib/libnet/mkconect.c
Normal file
1571
mozilla/lib/libnet/mkconect.c
Normal file
File diff suppressed because it is too large
Load Diff
156
mozilla/lib/libnet/mkdaturl.c
Normal file
156
mozilla/lib/libnet/mkdaturl.c
Normal file
@@ -0,0 +1,156 @@
|
||||
/* -*- 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 "mkutils.h"
|
||||
#include "mkgeturl.h"
|
||||
#include "cvmime.h"
|
||||
#include "mkdaturl.h"
|
||||
|
||||
extern int MK_OUT_OF_MEMORY;
|
||||
extern int MK_MALFORMED_URL_ERROR;
|
||||
|
||||
/* format of the DATA: URL
|
||||
*
|
||||
* data:[CONTENT-TYPE][;base64],DATA
|
||||
*/
|
||||
PRIVATE int32
|
||||
net_DataURLLoad (ActiveEntry * ce)
|
||||
{
|
||||
char *data_buffer;
|
||||
XP_Bool is_base64 = FALSE;
|
||||
NET_StreamClass *stream;
|
||||
char *comma;
|
||||
|
||||
ce->protocol = DATA_TYPE_URL;
|
||||
|
||||
/* we need a buffer equal to or smaller than the size of the URL
|
||||
*/
|
||||
data_buffer = (char *)XP_ALLOC(XP_STRLEN(ce->URL_s->address)+1);
|
||||
|
||||
if(!data_buffer)
|
||||
return(MK_OUT_OF_MEMORY);
|
||||
|
||||
/* determine the content type */
|
||||
|
||||
/* find the first comma */
|
||||
comma = XP_STRCHR(ce->URL_s->address, ',');
|
||||
|
||||
/* if no comma abort */
|
||||
if(!comma)
|
||||
{
|
||||
ce->URL_s->error_msg = NET_ExplainErrorDetails(MK_MALFORMED_URL_ERROR, ce->URL_s->address);
|
||||
return(MK_MALFORMED_URL_ERROR);
|
||||
}
|
||||
|
||||
/* fill in default content type */
|
||||
StrAllocCopy(ce->URL_s->content_type, TEXT_PLAIN);
|
||||
|
||||
/* check for a content type */
|
||||
if(comma != ce->URL_s->address + XP_STRLEN("data:"))
|
||||
{
|
||||
*comma = '\0';
|
||||
XP_STRCPY(data_buffer, ce->URL_s->address + XP_STRLEN("data:"));
|
||||
*comma = ',';
|
||||
|
||||
/* check for base 64 encoding */
|
||||
if(strcasestr(data_buffer, "base64"))
|
||||
is_base64 = TRUE;
|
||||
|
||||
/* parse the rest as a content-type */
|
||||
NET_ParseContentTypeHeader(ce->window_id, data_buffer, ce->URL_s, FALSE);
|
||||
|
||||
}
|
||||
|
||||
if(is_base64)
|
||||
{
|
||||
stream = NET_MimeEncodingConverter(ce->format_out, ENCODING_BASE64, ce->URL_s, ce->window_id);
|
||||
}
|
||||
else
|
||||
{
|
||||
/* open the outgoing stream
|
||||
*/
|
||||
stream = NET_StreamBuilder(ce->format_out, ce->URL_s, ce->window_id);
|
||||
}
|
||||
|
||||
if(!stream)
|
||||
{
|
||||
ce->URL_s->error_msg = NET_ExplainErrorDetails(MK_UNABLE_TO_CONVERT);
|
||||
ce->status = MK_UNABLE_TO_CONVERT;
|
||||
return (ce->status);
|
||||
}
|
||||
|
||||
/* @@@@ bug: ignore is_write_ready */
|
||||
|
||||
/* copy the data part of the URL into a scratch buffer */
|
||||
XP_STRCPY(data_buffer, comma+1);
|
||||
|
||||
ce->status = (*stream->put_block)(stream,
|
||||
data_buffer,
|
||||
XP_STRLEN(data_buffer));
|
||||
if(ce->status < 0)
|
||||
{
|
||||
(*stream->abort)(stream, ce->status);
|
||||
return (ce->status);
|
||||
}
|
||||
|
||||
(*stream->complete)(stream);
|
||||
|
||||
ce->status = MK_DATA_LOADED;
|
||||
return(-1); /* all done */
|
||||
|
||||
}
|
||||
|
||||
/* called repeatedly from NET_ProcessNet to push all the
|
||||
* data up the stream
|
||||
*/
|
||||
PRIVATE int32
|
||||
net_ProcessDataURL (ActiveEntry * cur_entry)
|
||||
{
|
||||
XP_ASSERT(0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* called by functions in mkgeturl to interrupt the loading of
|
||||
* an object. (Usually a user interrupt)
|
||||
*/
|
||||
PRIVATE int32
|
||||
net_InterruptDataURL (ActiveEntry * cur_entry)
|
||||
{
|
||||
XP_ASSERT(0);
|
||||
return(-1);
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
net_CleanupDataURL(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void
|
||||
NET_InitDataURLProtocol(void)
|
||||
{
|
||||
static NET_ProtoImpl dataurl_proto_impl;
|
||||
|
||||
dataurl_proto_impl.init = net_DataURLLoad;
|
||||
dataurl_proto_impl.process = net_ProcessDataURL;
|
||||
dataurl_proto_impl.interrupt = net_InterruptDataURL;
|
||||
dataurl_proto_impl.cleanup = net_CleanupDataURL;
|
||||
|
||||
NET_RegisterProtocolImplementation(&dataurl_proto_impl, DATA_TYPE_URL);
|
||||
}
|
||||
|
||||
24
mozilla/lib/libnet/mkdaturl.h
Normal file
24
mozilla/lib/libnet/mkdaturl.h
Normal 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.
|
||||
*/
|
||||
|
||||
#ifndef MKDATURL_H
|
||||
#define MKDATURL_H
|
||||
|
||||
extern void NET_InitDataURLProtocol(void);
|
||||
|
||||
#endif /* MKDATURL_H */
|
||||
1551
mozilla/lib/libnet/mkextcac.c
Normal file
1551
mozilla/lib/libnet/mkextcac.c
Normal file
File diff suppressed because it is too large
Load Diff
40
mozilla/lib/libnet/mkextcac.h
Normal file
40
mozilla/lib/libnet/mkextcac.h
Normal file
@@ -0,0 +1,40 @@
|
||||
/* -*- 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 MKEXTCACHE_H
|
||||
#define MKEXTCACHE_H
|
||||
|
||||
/* lookup routine
|
||||
*
|
||||
* builds a key and looks for it in
|
||||
* the database. Returns an access
|
||||
* method and sets a filename in the
|
||||
* URL struct if found
|
||||
*/
|
||||
extern int NET_FindURLInExtCache(URL_Struct * URL_s, MWContext *ctxt);
|
||||
|
||||
extern void
|
||||
NET_OpenExtCacheFAT(MWContext *ctxt, char * cache_name, char * instructions);
|
||||
|
||||
extern void
|
||||
CACHE_CloseAllOpenSARCache();
|
||||
|
||||
extern void
|
||||
CACHE_OpenAllSARCache();
|
||||
|
||||
#endif /* MKEXTCACHE_H */
|
||||
1830
mozilla/lib/libnet/mkfile.c
Normal file
1830
mozilla/lib/libnet/mkfile.c
Normal file
File diff suppressed because it is too large
Load Diff
34
mozilla/lib/libnet/mkfile.h
Normal file
34
mozilla/lib/libnet/mkfile.h
Normal file
@@ -0,0 +1,34 @@
|
||||
/* -*- 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 MKFILE_H
|
||||
#define MKFILE_H
|
||||
|
||||
#include "mkfsort.h"
|
||||
|
||||
extern void NET_InitFileProtocol(void);
|
||||
|
||||
extern int
|
||||
NET_PrintDirectory(SortStruct **sort_base, NET_StreamClass * stream, char * path, URL_Struct *URL_s);
|
||||
|
||||
extern NET_StreamClass *
|
||||
net_CloneWysiwygLocalFile(MWContext *window_id, URL_Struct *URL_s,
|
||||
uint32 nbytes, const char * wysiwyg_url,
|
||||
const char * base_href);
|
||||
|
||||
#endif /* MKFILE_H */
|
||||
1262
mozilla/lib/libnet/mkformat.c
Normal file
1262
mozilla/lib/libnet/mkformat.c
Normal file
File diff suppressed because it is too large
Load Diff
98
mozilla/lib/libnet/mkformat.h
Normal file
98
mozilla/lib/libnet/mkformat.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*
|
||||
* cinfo.h: Content Information for a file, i.e. its type, etc.
|
||||
*
|
||||
* See cinfo.c for dependency information.
|
||||
*
|
||||
* Rob McCool
|
||||
*/
|
||||
|
||||
#ifndef MKFORMAT_H
|
||||
#define MKFORMAT_H
|
||||
|
||||
#ifndef MKSTREAM_H
|
||||
#include "mkstream.h"
|
||||
#endif /* MKSTREAM_H */
|
||||
|
||||
/* ------------------------------ Constants ------------------------------- */
|
||||
|
||||
|
||||
/*
|
||||
* This will be the first string in the file, followed by x.x version
|
||||
* where x is an integer.
|
||||
*
|
||||
* If this magic string is not found, cinfo_merge will try to parse
|
||||
* the file as a NCSA httpd mime.types file.
|
||||
*/
|
||||
|
||||
#define MCC_MT_MAGIC "#--MCOM MIME Information"
|
||||
#define MCC_MT_MAGIC_LEN 24
|
||||
|
||||
#define NCC_MT_MAGIC "#--Netscape Communications Corporation MIME Information"
|
||||
#define NCC_MT_MAGIC_LEN 40 /* Don't bother to check it all */
|
||||
|
||||
/* The character which separates extensions with cinfo_find */
|
||||
|
||||
#define CINFO_SEPARATOR '.'
|
||||
|
||||
/* The maximum length of a line in this file */
|
||||
|
||||
#define CINFO_MAX_LEN 1024
|
||||
|
||||
/* The hash function for the database. Hashed on extension. */
|
||||
#include <ctype.h>
|
||||
#define CINFO_HASH(s) (isalpha(s[0]) ? tolower(s[0]) - 'a' : 26)
|
||||
|
||||
/* The hash table size for that function */
|
||||
#define CINFO_HASHSIZE 27
|
||||
|
||||
|
||||
/* ------------------------------ Structures ------------------------------ */
|
||||
|
||||
/* see ../include/net.h for the NET_cinfo struct */
|
||||
|
||||
/* ------------------------------ Prototypes ------------------------------ */
|
||||
|
||||
/*
|
||||
* cinfo_find finds any content information for the given uri. The file name
|
||||
* is the string following the last / in the uri. Multiple extensions are
|
||||
* separated by CINFO_SEPARATOR. You may pass in a filename instead of uri.
|
||||
*
|
||||
* Returns a newly allocated cinfo structure with the information it
|
||||
* finds. The elements of this structure are coming right out of the types
|
||||
* database and so if you change it or want to keep it around for long you
|
||||
* should strdup it. You should free only the structure itself when finished
|
||||
* with it.
|
||||
*
|
||||
* If there is no information for any one of the extensions it
|
||||
* finds, it will ignore that extension. If it cannot find information for
|
||||
* any of the extensions, it will return NULL.
|
||||
*/
|
||||
extern NET_cinfo *NET_cinfo_find(char *uri);
|
||||
extern NET_cinfo *NET_cinfo_find_type(char *uri);
|
||||
extern NET_cinfo *NET_cinfo_find_enc (char *uri);
|
||||
|
||||
|
||||
/*
|
||||
* cinfo_lookup finds the information about the given content-type, and
|
||||
* returns a cinfo structure so you can look up description and icon.
|
||||
*/
|
||||
NET_cinfo *NET_cinfo_lookup(char *type);
|
||||
|
||||
#endif /* MKFORMAT_H */
|
||||
153
mozilla/lib/libnet/mkfsort.c
Normal file
153
mozilla/lib/libnet/mkfsort.c
Normal file
@@ -0,0 +1,153 @@
|
||||
/* -*- 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.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* routines to sort an array of file objects
|
||||
* uses qsort alg
|
||||
*
|
||||
* Designed and implemented by Lou Montulli '94
|
||||
*/
|
||||
|
||||
#include "mkutils.h"
|
||||
#include "mkfsort.h"
|
||||
#include "mkgeturl.h"
|
||||
|
||||
#ifdef PROFILE
|
||||
#pragma profile on
|
||||
#endif
|
||||
|
||||
PRIVATE int net_file_sort_method = SORT_BY_NAME;
|
||||
|
||||
/* print a text string in place of the NET_FileEntryInfo special_type int */
|
||||
PUBLIC char *
|
||||
NET_PrintFileType(int special_type)
|
||||
{
|
||||
switch(special_type)
|
||||
{
|
||||
case NET_FILE_TYPE:
|
||||
return("FILE");
|
||||
case NET_DIRECTORY:
|
||||
return("DIRECTORY");
|
||||
case NET_SYM_LINK:
|
||||
return("SYMBOLIC-LINK");
|
||||
case NET_SYM_LINK_TO_DIR:
|
||||
return("SYM-DIRECTORY");
|
||||
case NET_SYM_LINK_TO_FILE:
|
||||
return("SYM-FILE");
|
||||
default:
|
||||
XP_ASSERT(0);
|
||||
return("FILE");
|
||||
}
|
||||
}
|
||||
|
||||
PRIVATE void
|
||||
NET_SetFileSortMethod(int method)
|
||||
{
|
||||
net_file_sort_method = method;
|
||||
}
|
||||
|
||||
MODULE_PRIVATE void NET_FreeEntryInfoStruct(NET_FileEntryInfo *entry_info)
|
||||
{
|
||||
if(entry_info)
|
||||
{
|
||||
FREEIF(entry_info->filename);
|
||||
/* free the struct */
|
||||
XP_FREE(entry_info);
|
||||
}
|
||||
}
|
||||
|
||||
MODULE_PRIVATE NET_FileEntryInfo * NET_CreateFileEntryInfoStruct (void)
|
||||
{
|
||||
NET_FileEntryInfo * new_entry = XP_NEW(NET_FileEntryInfo);
|
||||
|
||||
if(!new_entry)
|
||||
return(NULL);
|
||||
|
||||
XP_MEMSET(new_entry, 0, sizeof(NET_FileEntryInfo));
|
||||
|
||||
new_entry->permissions = -1;
|
||||
|
||||
return(new_entry);
|
||||
|
||||
}
|
||||
|
||||
/* This function is used as a comparer function for the Qsort routine.
|
||||
* It uses a function FE_FileSortMethod() to determine the
|
||||
* field to sort on.
|
||||
*
|
||||
*/
|
||||
PRIVATE int
|
||||
NET_CompareFileEntryInfoStructs (const void *ent2, const void *ent1)
|
||||
{
|
||||
int status;
|
||||
const NET_FileEntryInfo *entry1 = *(NET_FileEntryInfo **) ent1;
|
||||
const NET_FileEntryInfo *entry2 = *(NET_FileEntryInfo **) ent2;
|
||||
|
||||
if(!entry1 || !entry2)
|
||||
return(-1);
|
||||
|
||||
switch(net_file_sort_method)
|
||||
{
|
||||
case SORT_BY_SIZE:
|
||||
/* both equal or both 0 */
|
||||
if(entry1->size == entry2->size)
|
||||
return(XP_STRCMP(entry2->filename, entry1->filename));
|
||||
else
|
||||
if(entry1->size > entry2->size)
|
||||
return(-1);
|
||||
else
|
||||
return(1);
|
||||
/* break; NOT NEEDED */
|
||||
case SORT_BY_TYPE:
|
||||
if(entry1->cinfo && entry1->cinfo->desc &&
|
||||
entry2->cinfo && entry2->cinfo->desc)
|
||||
{
|
||||
status = XP_STRCMP(entry1->cinfo->desc, entry2->cinfo->desc);
|
||||
if(status)
|
||||
return(status);
|
||||
/* else fall to filename comparison */
|
||||
}
|
||||
return (XP_STRCMP(entry2->filename, entry1->filename));
|
||||
/* break; NOT NEEDED */
|
||||
case SORT_BY_DATE:
|
||||
if(entry1->date == entry2->date)
|
||||
return(XP_STRCMP(entry2->filename, entry1->filename));
|
||||
else
|
||||
if(entry1->size > entry2->size)
|
||||
return(-1);
|
||||
else
|
||||
return(1);
|
||||
/* break; NOT NEEDED */
|
||||
case SORT_BY_NAME:
|
||||
default:
|
||||
return (XP_STRCMP(entry2->filename, entry1->filename));
|
||||
}
|
||||
}
|
||||
|
||||
/* sort the files
|
||||
*/
|
||||
MODULE_PRIVATE void
|
||||
NET_DoFileSort(SortStruct * sort_list)
|
||||
{
|
||||
NET_DoSort(sort_list, NET_CompareFileEntryInfoStructs);
|
||||
}
|
||||
|
||||
#ifdef PROFILE
|
||||
#pragma profile off
|
||||
#endif
|
||||
|
||||
35
mozilla/lib/libnet/mkfsort.h
Normal file
35
mozilla/lib/libnet/mkfsort.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* -*- 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 MKFSORT_H
|
||||
#define MKFSORT_H
|
||||
|
||||
#include "mksort.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#ifdef XP_UNIX
|
||||
#include <sys/types.h>
|
||||
#endif /* XP_UNIX */
|
||||
|
||||
extern void NET_FreeEntryInfoStruct(NET_FileEntryInfo *entry_info);
|
||||
extern NET_FileEntryInfo * NET_CreateFileEntryInfoStruct (void);
|
||||
extern int NET_CompareEntryInfoStructs (void *ent1, void *ent2);
|
||||
extern void NET_DoFileSort (SortStruct * sort_list);
|
||||
|
||||
#endif /* MKFSORT_H */
|
||||
4729
mozilla/lib/libnet/mkftp.c
Normal file
4729
mozilla/lib/libnet/mkftp.c
Normal file
File diff suppressed because it is too large
Load Diff
26
mozilla/lib/libnet/mkftp.h
Normal file
26
mozilla/lib/libnet/mkftp.h
Normal file
@@ -0,0 +1,26 @@
|
||||
/* -*- 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 MKFTP_H
|
||||
#define MKFTP_H
|
||||
|
||||
#include "mkgeturl.h"
|
||||
|
||||
extern void NET_InitFTPProtocol(void);
|
||||
|
||||
#endif /* HTFTP_H */
|
||||
5855
mozilla/lib/libnet/mkgeturl.c
Normal file
5855
mozilla/lib/libnet/mkgeturl.c
Normal file
File diff suppressed because it is too large
Load Diff
130
mozilla/lib/libnet/mkgeturl.h
Normal file
130
mozilla/lib/libnet/mkgeturl.h
Normal file
@@ -0,0 +1,130 @@
|
||||
/* -*- 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 MKGETURL_H
|
||||
#define MKGETURL_H
|
||||
|
||||
#include "mkutils.h"
|
||||
#include "xp.h"
|
||||
#include "mktcp.h"
|
||||
#include "nslocks.h"
|
||||
|
||||
|
||||
/* fix Mac warnings about missing prototypes */
|
||||
MODULE_PRIVATE int PR_CALLBACK
|
||||
NET_PrefChangedFunc(const char *pref, void *data);
|
||||
|
||||
/* Debugging routine prints an URL (and string "header")
|
||||
*/
|
||||
XP_BEGIN_PROTOS
|
||||
#ifdef DEBUG
|
||||
extern void TraceURL (URL_Struct *url, char *header);
|
||||
#else
|
||||
#define TraceURL(U,M)
|
||||
#endif /* DEBUG */
|
||||
XP_END_PROTOS
|
||||
|
||||
/* forward declared; see below */
|
||||
typedef struct _NET_ProtoImpl NET_ProtoImpl;
|
||||
|
||||
/* structure for maintaining multiple active data transfers
|
||||
*/
|
||||
typedef struct _ActiveEntry {
|
||||
URL_Struct *URL_s; /* the URL data */
|
||||
int status; /* current status */
|
||||
int32 bytes_received; /* number of bytes received so far */
|
||||
PRFileDesc *socket; /* data sock */
|
||||
PRFileDesc *con_sock; /* socket waiting for connection */
|
||||
Bool local_file; /* are we reading a local file */
|
||||
Bool memory_file; /* are we reading from memory? */
|
||||
int protocol; /* protocol used for transfer */
|
||||
NET_ProtoImpl *proto_impl; /* handle to protocol implemenation */
|
||||
void *con_data; /* data about the transfer connection and status */
|
||||
/* routine to call when finished */
|
||||
Net_GetUrlExitFunc *exit_routine;
|
||||
MWContext * window_id; /* a unique window id */
|
||||
FO_Present_Types format_out; /* the output format */
|
||||
|
||||
NET_StreamClass * save_stream; /* used for cacheing of partial docs
|
||||
* The file code opens this stream
|
||||
* and writes part of the file down it.
|
||||
* Then the stream is saved
|
||||
* and the rest is loaded from the
|
||||
* network
|
||||
*/
|
||||
Bool busy;
|
||||
|
||||
char * proxy_conf; /* Proxy autoconfig string */
|
||||
char * proxy_addr; /* Proxy address in host:port format */
|
||||
u_long socks_host; /* SOCKS host IP address */
|
||||
short socks_port; /* SOCKS port number */
|
||||
|
||||
} ActiveEntry;
|
||||
|
||||
/* typedefs of protocol implementation functions
|
||||
*
|
||||
* All these currently take an ActiveEntry Struct but
|
||||
* should probably be abstracted out considerably more
|
||||
*/
|
||||
typedef int32 NET_ProtoInitFunc(ActiveEntry *ce);
|
||||
typedef int32 NET_ProtoProcessFunc(ActiveEntry *ce);
|
||||
typedef int32 NET_ProtoInterruptFunc(ActiveEntry *ce);
|
||||
typedef int32 NET_ProtoCleanupFunc(void);
|
||||
|
||||
/* a structure to hold the registered implementation of
|
||||
* a protocol converter
|
||||
*/
|
||||
struct _NET_ProtoImpl {
|
||||
int32 (*init) (ActiveEntry *ce);
|
||||
int32 (*process) (ActiveEntry *ce);
|
||||
int32 (*interrupt) (ActiveEntry *ce);
|
||||
void (*cleanup) (void); /* note that cleanup can be called more
|
||||
* than once, when we need to shut down
|
||||
* connections or free up memory
|
||||
*/
|
||||
};
|
||||
|
||||
XP_BEGIN_PROTOS
|
||||
extern int NET_TotalNumberOfOpenConnections;
|
||||
extern int NET_MaxNumberOfOpenConnections;
|
||||
extern CacheUseEnum NET_CacheUseMethod;
|
||||
extern time_t NET_StartupTime; /* time we began the program */
|
||||
extern XP_Bool NET_ProxyAcLoaded;
|
||||
/*
|
||||
* Silently Interrupts all transfers in progress that have the same
|
||||
* window id as the one passed in.
|
||||
*/
|
||||
extern int NET_SilentInterruptWindow(MWContext * window_id);
|
||||
/* cause prefs to be read or updated */
|
||||
extern void NET_SetupPrefs(const char * prefChanged);
|
||||
|
||||
extern NET_ProxyStyle NET_GetProxyStyle(void);
|
||||
extern const char * net_GetPACUrl(void);
|
||||
extern void net_SetPACUrl(char *u);
|
||||
|
||||
/* return a proxy server host and port to the caller or NULL
|
||||
*/
|
||||
extern char * NET_FindProxyHostForUrl(int urltype, char *urladdress);
|
||||
|
||||
/* registers a protocol impelementation for a particular url_type
|
||||
* see NET_URL_Type() for types
|
||||
*/
|
||||
extern void NET_RegisterProtocolImplementation(NET_ProtoImpl *impl, int for_url_type);
|
||||
|
||||
XP_END_PROTOS
|
||||
#endif /* not MKGetURL_H */
|
||||
1170
mozilla/lib/libnet/mkgopher.c
Normal file
1170
mozilla/lib/libnet/mkgopher.c
Normal file
File diff suppressed because it is too large
Load Diff
25
mozilla/lib/libnet/mkgopher.h
Normal file
25
mozilla/lib/libnet/mkgopher.h
Normal file
@@ -0,0 +1,25 @@
|
||||
/* -*- 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 MKGOPHER_H
|
||||
#define MKGOPHER_H
|
||||
|
||||
extern void NET_InitGopherProtocol(void);
|
||||
|
||||
#endif /* MKGOPHER_H */
|
||||
|
||||
1022
mozilla/lib/libnet/mkhelp.c
Normal file
1022
mozilla/lib/libnet/mkhelp.c
Normal file
File diff suppressed because it is too large
Load Diff
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user