mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-04 02:57:38 +00:00
More cleanup for modular libmime.
This commit is contained in:
parent
22b2c95c5c
commit
dec7693094
@ -96,6 +96,7 @@ OBJS= \
|
||||
.\$(OBJDIR)\mimeunty.obj \
|
||||
.\$(OBJDIR)\mimemoz.obj \
|
||||
.\$(OBJDIR)\mimecth.obj \
|
||||
.\$(OBJDIR)\mimebuf.obj \
|
||||
#
|
||||
# THIS WILL NEED WORK AFTER WE GET A LIBMSG MORE XP-COM-afied
|
||||
# .\$(OBJDIR)\mimedrft.obj \
|
||||
@ -106,7 +107,6 @@ OBJS= \
|
||||
# WHEN NEW WORLD FUNCTIONS ARE FOUND
|
||||
.\$(OBJDIR)\oldnet.obj \
|
||||
.\$(OBJDIR)\oldi18n.obj \
|
||||
.\$(OBJDIR)\oldmsg.obj \
|
||||
.\$(OBJDIR)\oldmaddr.obj \
|
||||
.\$(OBJDIR)\oldfile.obj \
|
||||
.\$(OBJDIR)\oldxp.obj \
|
||||
|
@ -25,7 +25,7 @@
|
||||
extern int MK_OUT_OF_MEMORY;
|
||||
|
||||
int
|
||||
msg_GrowBuffer (PRUint32 desired_size, PRUint32 element_size, PRUint32 quantum,
|
||||
mime_GrowBuffer (PRUint32 desired_size, PRUint32 element_size, PRUint32 quantum,
|
||||
char **buffer, PRUint32 *size)
|
||||
{
|
||||
if (*size <= desired_size)
|
||||
@ -48,14 +48,14 @@ msg_GrowBuffer (PRUint32 desired_size, PRUint32 element_size, PRUint32 quantum,
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* The opposite of msg_LineBuffer(): takes small buffers and packs them
|
||||
/* The opposite of mime_LineBuffer(): takes small buffers and packs them
|
||||
up into bigger buffers before passing them along.
|
||||
|
||||
Pass in a desired_buffer_size 0 to tell it to flush (for example, in
|
||||
in the very last call to this function.)
|
||||
*/
|
||||
int
|
||||
msg_ReBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
mime_ReBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
PRUint32 desired_buffer_size,
|
||||
char **bufferP, PRUint32 *buffer_sizeP, PRUint32 *buffer_fpP,
|
||||
PRInt32 (*per_buffer_fn) (char *buffer, PRUint32 buffer_size,
|
||||
@ -66,7 +66,7 @@ msg_ReBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
|
||||
if (desired_buffer_size >= (*buffer_sizeP))
|
||||
{
|
||||
status = msg_GrowBuffer (desired_buffer_size, sizeof(char), 1024,
|
||||
status = mime_GrowBuffer (desired_buffer_size, sizeof(char), 1024,
|
||||
bufferP, buffer_sizeP);
|
||||
if (status < 0) return status;
|
||||
}
|
||||
@ -98,7 +98,7 @@ msg_ReBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
}
|
||||
|
||||
static int
|
||||
msg_convert_and_send_buffer(char* buf, int length, PRBool convert_newlines_p,
|
||||
convert_and_send_buffer(char* buf, int length, PRBool convert_newlines_p,
|
||||
PRInt32 (*per_line_fn) (char *line,
|
||||
PRUint32 line_length,
|
||||
void *closure),
|
||||
@ -147,7 +147,7 @@ msg_convert_and_send_buffer(char* buf, int length, PRBool convert_newlines_p,
|
||||
}
|
||||
|
||||
int
|
||||
msg_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
mime_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
char **bufferP, PRUint32 *buffer_sizeP, PRUint32 *buffer_fpP,
|
||||
PRBool convert_newlines_p,
|
||||
PRInt32 (*per_line_fn) (char *line, PRUint32 line_length,
|
||||
@ -161,7 +161,7 @@ msg_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
with a LF. This old buffer should be shipped out and discarded. */
|
||||
PR_ASSERT(*buffer_sizeP > *buffer_fpP);
|
||||
if (*buffer_sizeP <= *buffer_fpP) return -1;
|
||||
status = msg_convert_and_send_buffer(*bufferP, *buffer_fpP,
|
||||
status = convert_and_send_buffer(*bufferP, *buffer_fpP,
|
||||
convert_newlines_p,
|
||||
per_line_fn, closure);
|
||||
if (status < 0) return status;
|
||||
@ -211,7 +211,7 @@ msg_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
|
||||
if (desired_size >= (*buffer_sizeP))
|
||||
{
|
||||
status = msg_GrowBuffer (desired_size, sizeof(char), 1024,
|
||||
status = mime_GrowBuffer (desired_size, sizeof(char), 1024,
|
||||
bufferP, buffer_sizeP);
|
||||
if (status < 0) return status;
|
||||
}
|
||||
@ -228,7 +228,7 @@ msg_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
if (!newline)
|
||||
return 0;
|
||||
|
||||
status = msg_convert_and_send_buffer(*bufferP, *buffer_fpP,
|
||||
status = convert_and_send_buffer(*bufferP, *buffer_fpP,
|
||||
convert_newlines_p,
|
||||
per_line_fn, closure);
|
||||
if (status < 0) return status;
|
||||
|
@ -19,11 +19,11 @@
|
||||
#ifndef _MIMEBUF_H_
|
||||
#define _MIMEBUF_H_
|
||||
|
||||
extern int msg_GrowBuffer (PRUint32 desired_size,
|
||||
extern int mime_GrowBuffer (PRUint32 desired_size,
|
||||
PRUint32 element_size, PRUint32 quantum,
|
||||
char **buffer, PRUint32 *size);
|
||||
|
||||
extern int msg_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
extern int mime_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
char **bufferP, PRUint32 *buffer_sizeP,
|
||||
PRUint32 *buffer_fpP,
|
||||
PRBool convert_newlines_p,
|
||||
@ -31,7 +31,7 @@ extern int msg_LineBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
line_length, void *closure),
|
||||
void *closure);
|
||||
|
||||
extern int msg_ReBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
extern int mime_ReBuffer (const char *net_buffer, PRInt32 net_buffer_size,
|
||||
PRUint32 desired_buffer_size,
|
||||
char **bufferP, PRUint32 *buffer_sizeP,
|
||||
PRUint32 *buffer_fpP,
|
||||
|
@ -29,6 +29,7 @@
|
||||
#include "msgcom.h"
|
||||
#include "imap.h"
|
||||
#include "prefapi.h"
|
||||
#include "mimebuf.h"
|
||||
|
||||
extern int MK_OUT_OF_MEMORY;
|
||||
extern int MK_MSG_NO_HEADERS;
|
||||
@ -214,7 +215,7 @@ MimeHeaders_parse_line (const char *buffer, PRInt32 size, MimeHeaders *hdrs)
|
||||
desired_size = hdrs->all_headers_fp + size + 1;
|
||||
if (desired_size >= hdrs->all_headers_size)
|
||||
{
|
||||
status = msg_GrowBuffer (desired_size, sizeof(char), 255,
|
||||
status = mime_GrowBuffer (desired_size, sizeof(char), 255,
|
||||
&hdrs->all_headers, &hdrs->all_headers_size);
|
||||
if (status < 0) return status;
|
||||
}
|
||||
@ -835,7 +836,7 @@ MimeHeaders_default_addbook_link_generator (const char *dest, void *closure,
|
||||
|
||||
#define MimeHeaders_grow_obuffer(hdrs, desired_size) \
|
||||
((((long) (desired_size)) >= ((long) (hdrs)->obuffer_size)) ? \
|
||||
msg_GrowBuffer ((desired_size), sizeof(char), 255, \
|
||||
mime_GrowBuffer ((desired_size), sizeof(char), 255, \
|
||||
&(hdrs)->obuffer, &(hdrs)->obuffer_size) \
|
||||
: 0)
|
||||
|
||||
|
@ -39,6 +39,7 @@
|
||||
#include "mimemrel.h"
|
||||
#include "mimemalt.h"
|
||||
#include "xpgetstr.h"
|
||||
#include "mimebuf.h"
|
||||
|
||||
#ifdef RICHIE_VCARD
|
||||
# include "mimevcrd.h" /* for MIME_VCardConverter */
|
||||
@ -67,7 +68,7 @@ extern int XP_FORWARDED_MESSAGE_ATTACHMENT;
|
||||
|
||||
#include "mimei.h" /* for moved MimeDisplayData struct */
|
||||
#include "mimemoz.h"
|
||||
#include "msgutils.h" /* for msg_MakeRebufferingStream() */
|
||||
#include "mimebuf.h"
|
||||
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
@ -78,6 +79,14 @@ extern int MK_UNABLE_TO_OPEN_TMP_FILE;
|
||||
/* Arrgh. Why isn't this in a reasonable header file somewhere??? ###tw */
|
||||
extern char * NET_ExplainErrorDetails (int code, ...);
|
||||
|
||||
/*
|
||||
* RICHIE - should this still be here....
|
||||
* For now, I am moving this libmsg type stuff into mimemoz.c
|
||||
*/
|
||||
extern NET_StreamClass *msg_MakeRebufferingStream (NET_StreamClass *next,
|
||||
URL_Struct *url,
|
||||
MWContext *context);
|
||||
|
||||
|
||||
/* Interface between netlib and the top-level message/rfc822 parser:
|
||||
MIME_MessageConverter()
|
||||
@ -2066,7 +2075,7 @@ static int
|
||||
mime_richtext_write (void *stream, const char* buf, PRInt32 size)
|
||||
{
|
||||
struct mime_richtext_data *data = (struct mime_richtext_data *) stream;
|
||||
return msg_LineBuffer (buf, size, &data->ibuffer, &data->ibuffer_size,
|
||||
return mime_LineBuffer (buf, size, &data->ibuffer, &data->ibuffer_size,
|
||||
&data->ibuffer_fp, PR_FALSE, mime_richtext_write_line,
|
||||
data);
|
||||
}
|
||||
@ -2396,3 +2405,135 @@ MIME_VCardConverter2 ( int format_out,
|
||||
return stream;
|
||||
}
|
||||
#endif /* RICHIE_VCARD */
|
||||
|
||||
|
||||
/* RICHIE
|
||||
* HOW WILL THIS BE HANDLED GOING FORWARD????
|
||||
*/
|
||||
PRBool
|
||||
ValidateDocData(MWContext *window_id)
|
||||
{
|
||||
printf("ValidateDocData not implemented, stubbed in webshell/tests/viewer/nsStubs.cpp\n");
|
||||
return PR_TRUE;
|
||||
}
|
||||
|
||||
struct msg_rebuffering_stream_data
|
||||
{
|
||||
PRUint32 desired_size;
|
||||
char *buffer;
|
||||
PRUint32 buffer_size;
|
||||
PRUint32 buffer_fp;
|
||||
NET_StreamClass *next_stream;
|
||||
};
|
||||
|
||||
|
||||
static PRInt32
|
||||
msg_rebuffering_stream_write_next_chunk (char *buffer, PRUint32 buffer_size,
|
||||
void *closure)
|
||||
{
|
||||
struct msg_rebuffering_stream_data *sd =
|
||||
(struct msg_rebuffering_stream_data *) closure;
|
||||
PR_ASSERT (sd);
|
||||
if (!sd) return -1;
|
||||
if (!sd->next_stream) return -1;
|
||||
return (*sd->next_stream->put_block) (sd->next_stream->data_object,
|
||||
buffer, buffer_size);
|
||||
}
|
||||
|
||||
static int
|
||||
msg_rebuffering_stream_write_chunk (void *stream,
|
||||
const char* net_buffer,
|
||||
PRInt32 net_buffer_size)
|
||||
{
|
||||
struct msg_rebuffering_stream_data *sd =
|
||||
(struct msg_rebuffering_stream_data *) stream;
|
||||
PR_ASSERT (sd);
|
||||
if (!sd) return -1;
|
||||
return mime_ReBuffer (net_buffer, net_buffer_size,
|
||||
sd->desired_size,
|
||||
&sd->buffer, &sd->buffer_size, &sd->buffer_fp,
|
||||
msg_rebuffering_stream_write_next_chunk,
|
||||
sd);
|
||||
}
|
||||
|
||||
static void
|
||||
msg_rebuffering_stream_abort (void *stream, int status)
|
||||
{
|
||||
struct msg_rebuffering_stream_data *sd =
|
||||
(struct msg_rebuffering_stream_data *) stream;
|
||||
if (!sd) return;
|
||||
PR_FREEIF (sd->buffer);
|
||||
if (sd->next_stream)
|
||||
{
|
||||
if (ValidateDocData(sd->next_stream->window_id)) /* otherwise doc_data is gone ! */
|
||||
(*sd->next_stream->abort) (sd->next_stream->data_object, status);
|
||||
PR_Free (sd->next_stream);
|
||||
}
|
||||
PR_Free (sd);
|
||||
}
|
||||
|
||||
static void
|
||||
msg_rebuffering_stream_complete (void *stream)
|
||||
{
|
||||
struct msg_rebuffering_stream_data *sd =
|
||||
(struct msg_rebuffering_stream_data *) stream;
|
||||
if (!sd) return;
|
||||
sd->desired_size = 0;
|
||||
msg_rebuffering_stream_write_chunk (stream, "", 0);
|
||||
PR_FREEIF (sd->buffer);
|
||||
if (sd->next_stream)
|
||||
{
|
||||
(*sd->next_stream->complete) (sd->next_stream->data_object);
|
||||
PR_Free (sd->next_stream);
|
||||
}
|
||||
PR_Free (sd);
|
||||
}
|
||||
|
||||
static unsigned int
|
||||
msg_rebuffering_stream_write_ready (void *stream)
|
||||
{
|
||||
struct msg_rebuffering_stream_data *sd =
|
||||
(struct msg_rebuffering_stream_data *) stream;
|
||||
if (sd && sd->next_stream)
|
||||
return ((*sd->next_stream->is_write_ready)
|
||||
(sd->next_stream->data_object));
|
||||
else
|
||||
return (MAX_WRITE_READY);
|
||||
}
|
||||
|
||||
NET_StreamClass *
|
||||
msg_MakeRebufferingStream (NET_StreamClass *next_stream,
|
||||
URL_Struct *url,
|
||||
MWContext *context)
|
||||
{
|
||||
NET_StreamClass *stream;
|
||||
struct msg_rebuffering_stream_data *sd;
|
||||
|
||||
PR_ASSERT (next_stream);
|
||||
|
||||
stream = PR_NEW (NET_StreamClass);
|
||||
if (!stream) return 0;
|
||||
|
||||
sd = PR_NEW (struct msg_rebuffering_stream_data);
|
||||
if (! sd)
|
||||
{
|
||||
PR_Free (stream);
|
||||
return 0;
|
||||
}
|
||||
|
||||
memset (sd, 0, sizeof(*sd));
|
||||
memset (stream, 0, sizeof(*stream));
|
||||
|
||||
sd->next_stream = next_stream;
|
||||
sd->desired_size = 10240;
|
||||
|
||||
stream->name = "ReBuffering Stream";
|
||||
stream->complete = msg_rebuffering_stream_complete;
|
||||
stream->abort = msg_rebuffering_stream_abort;
|
||||
stream->put_block = msg_rebuffering_stream_write_chunk;
|
||||
stream->is_write_ready = msg_rebuffering_stream_write_ready;
|
||||
stream->data_object = sd;
|
||||
stream->window_id = context;
|
||||
|
||||
return stream;
|
||||
}
|
||||
|
@ -17,9 +17,9 @@
|
||||
*/
|
||||
|
||||
#include "mimeobj.h"
|
||||
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
#include "mimebuf.h"
|
||||
|
||||
/* Way to destroy any notions of modularity or class hierarchy, Terry! */
|
||||
# include "mimetpla.h"
|
||||
@ -205,7 +205,7 @@ MimeObject_parse_buffer (char *buffer, PRInt32 size, MimeObject *obj)
|
||||
PR_ASSERT(!obj->closed_p);
|
||||
if (obj->closed_p) return -1;
|
||||
|
||||
return msg_LineBuffer (buffer, size,
|
||||
return mime_LineBuffer (buffer, size,
|
||||
&obj->ibuffer, &obj->ibuffer_size, &obj->ibuffer_fp,
|
||||
PR_TRUE,
|
||||
((int (*) (char *, PRInt32, void *))
|
||||
|
@ -188,7 +188,7 @@ struct MimeObject {
|
||||
|
||||
#define MimeObject_grow_obuffer(obj, desired_size) \
|
||||
(((desired_size) >= (obj)->obuffer_size) ? \
|
||||
msg_GrowBuffer ((desired_size), sizeof(char), 1024, \
|
||||
mime_GrowBuffer ((desired_size), sizeof(char), 1024, \
|
||||
&(obj)->obuffer, &(obj)->obuffer_size) \
|
||||
: 0)
|
||||
|
||||
|
@ -15,9 +15,9 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "mimetext.h"
|
||||
#include "libi18n.h"
|
||||
#include "mimebuf.h"
|
||||
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
@ -232,7 +232,7 @@ MimeInlineText_parse_decoded_buffer (char *buf, PRInt32 size, MimeObject *obj)
|
||||
MimeLeaf class, except that we line-buffer to our own wrapper on the
|
||||
`parse_line' method instead of calling the `parse_line' method directly.
|
||||
*/
|
||||
return msg_LineBuffer (buf, size,
|
||||
return mime_LineBuffer (buf, size,
|
||||
&obj->ibuffer, &obj->ibuffer_size, &obj->ibuffer_fp,
|
||||
PR_TRUE,
|
||||
((int (*) (char *, PRInt32, void *))
|
||||
@ -244,7 +244,7 @@ MimeInlineText_parse_decoded_buffer (char *buf, PRInt32 size, MimeObject *obj)
|
||||
|
||||
#define MimeInlineText_grow_cbuffer(text, desired_size) \
|
||||
(((desired_size) >= (text)->cbuffer_size) ? \
|
||||
msg_GrowBuffer ((desired_size), sizeof(char), 100, \
|
||||
mime_GrowBuffer ((desired_size), sizeof(char), 100, \
|
||||
&(text)->cbuffer, &(text)->cbuffer_size) \
|
||||
: 0)
|
||||
|
||||
|
@ -17,7 +17,7 @@
|
||||
*/
|
||||
|
||||
#include "mimetpla.h"
|
||||
|
||||
#include "mimebuf.h"
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
|
||||
|
@ -15,9 +15,8 @@
|
||||
* Copyright (C) 1998 Netscape Communications Corporation. All Rights
|
||||
* Reserved.
|
||||
*/
|
||||
|
||||
#include "mimetric.h"
|
||||
|
||||
#include "mimebuf.h"
|
||||
#include "prmem.h"
|
||||
#include "plstr.h"
|
||||
|
||||
@ -84,7 +83,7 @@ MimeRichtextConvert (char *line, PRInt32 length,
|
||||
|
||||
desired_size = length * 4;
|
||||
if (desired_size >= *obuffer_sizeP)
|
||||
status = msg_GrowBuffer (desired_size, sizeof(char), 1024,
|
||||
status = mime_GrowBuffer (desired_size, sizeof(char), 1024,
|
||||
obufferP, obuffer_sizeP);
|
||||
if (status < 0) return status;
|
||||
|
||||
|
@ -24,7 +24,6 @@
|
||||
#include "xp.h"
|
||||
#include "msgcom.h"
|
||||
#include "msgnet.h"
|
||||
#include "msgutils.h"
|
||||
#include "xpgetstr.h"
|
||||
|
||||
#ifdef XP_CPLUSPLUS
|
||||
|
Loading…
Reference in New Issue
Block a user