Bug 1919290 - Type checking for data_object in C MIME code. r=BenC
Differential Revision: https://phabricator.services.mozilla.com/D223087 --HG-- extra : rebase_source : 3c2a73c9433c953457a93e1bb270b3c664e39ce4
This commit is contained in:
Родитель
30ce1a27b4
Коммит
569a04bb6f
|
@ -422,10 +422,19 @@ static int dummy_file_write(const char* buf, int32_t size,
|
|||
|
||||
static int mime_parse_stream_write(nsMIMESession* stream, const char* buf,
|
||||
int32_t size) {
|
||||
mime_draft_data* mdd = (mime_draft_data*)stream->data_object;
|
||||
NS_ASSERTION(mdd, "null mime draft data!");
|
||||
NS_ASSERTION(stream->data_object, "null mime data!");
|
||||
if (!stream->data_object) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
if (!mdd || !mdd->obj) return -1;
|
||||
PR_ASSERT(stream->data_object.mType == MimeClosure::isMimeDraftData);
|
||||
if (stream->data_object.mType != MimeClosure::isMimeDraftData) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
mime_draft_data* mdd = (mime_draft_data*)stream->data_object.mClosure;
|
||||
|
||||
if (!mdd->obj) return -1;
|
||||
|
||||
return mdd->obj->clazz->parse_buffer(
|
||||
(char*)buf, size, MimeClosure(MimeClosure::isMimeObject, mdd->obj));
|
||||
|
@ -1115,7 +1124,16 @@ static void convert_plaintext_body_to_html(char** body) {
|
|||
}
|
||||
|
||||
static void mime_parse_stream_complete(nsMIMESession* stream) {
|
||||
mime_draft_data* mdd = (mime_draft_data*)stream->data_object;
|
||||
NS_ASSERTION(stream->data_object, "null mime data");
|
||||
if (!stream->data_object) {
|
||||
return;
|
||||
}
|
||||
PR_ASSERT(stream->data_object.mType == MimeClosure::isMimeDraftData);
|
||||
if (stream->data_object.mType != MimeClosure::isMimeDraftData) {
|
||||
return;
|
||||
}
|
||||
|
||||
mime_draft_data* mdd = (mime_draft_data*)stream->data_object.mClosure;
|
||||
nsCOMPtr<nsIMsgCompFields> fields;
|
||||
int htmlAction = 0;
|
||||
int lineWidth = 0;
|
||||
|
@ -1147,10 +1165,6 @@ static void mime_parse_stream_complete(nsMIMESession* stream) {
|
|||
bool bodyAsAttachment = false;
|
||||
bool charsetOverride = false;
|
||||
|
||||
NS_ASSERTION(mdd, "null mime draft data");
|
||||
|
||||
if (!mdd) return;
|
||||
|
||||
if (mdd->obj) {
|
||||
int status;
|
||||
|
||||
|
@ -1184,7 +1198,7 @@ static void mime_parse_stream_complete(nsMIMESession* stream) {
|
|||
mdd->options = 0;
|
||||
}
|
||||
if (mdd->stream) {
|
||||
mdd->stream->complete((nsMIMESession*)mdd->stream->data_object);
|
||||
mdd->stream->complete(mdd->stream);
|
||||
PR_Free(mdd->stream);
|
||||
mdd->stream = 0;
|
||||
}
|
||||
|
@ -1679,10 +1693,15 @@ static void mime_parse_stream_complete(nsMIMESession* stream) {
|
|||
}
|
||||
|
||||
static void mime_parse_stream_abort(nsMIMESession* stream, int status) {
|
||||
mime_draft_data* mdd = (mime_draft_data*)stream->data_object;
|
||||
NS_ASSERTION(mdd, "null mime draft data");
|
||||
|
||||
if (!mdd) return;
|
||||
NS_ASSERTION(stream->data_object, "null mime data");
|
||||
if (!stream->data_object) {
|
||||
return;
|
||||
}
|
||||
PR_ASSERT(stream->data_object.mType == MimeClosure::isMimeDraftData);
|
||||
if (stream->data_object.mType != MimeClosure::isMimeDraftData) {
|
||||
return;
|
||||
}
|
||||
mime_draft_data* mdd = (mime_draft_data*)stream->data_object.mClosure;
|
||||
|
||||
if (mdd->obj) {
|
||||
int status = 0;
|
||||
|
@ -1701,7 +1720,7 @@ static void mime_parse_stream_abort(nsMIMESession* stream, int status) {
|
|||
}
|
||||
|
||||
if (mdd->stream) {
|
||||
mdd->stream->abort((nsMIMESession*)mdd->stream->data_object, status);
|
||||
mdd->stream->abort(mdd->stream, status);
|
||||
PR_Free(mdd->stream);
|
||||
mdd->stream = 0;
|
||||
}
|
||||
|
@ -2104,7 +2123,7 @@ extern "C" void* mime_bridge_create_draft_stream(
|
|||
stream->complete = mime_parse_stream_complete;
|
||||
stream->abort = mime_parse_stream_abort;
|
||||
stream->put_block = mime_parse_stream_write;
|
||||
stream->data_object = mdd;
|
||||
stream->data_object = MimeClosure(MimeClosure::isMimeDraftData, mdd);
|
||||
|
||||
status = obj->clazz->initialize(obj);
|
||||
if (status >= 0) status = obj->clazz->parse_begin(obj);
|
||||
|
|
|
@ -805,10 +805,17 @@ static int mime_output_fn(const char* buf, int32_t size,
|
|||
|
||||
extern "C" int mime_display_stream_write(nsMIMESession* stream, const char* buf,
|
||||
int32_t size) {
|
||||
mime_stream_data* msd =
|
||||
(mime_stream_data*)((nsMIMESession*)stream)->data_object;
|
||||
if (!stream->data_object) {
|
||||
return -1;
|
||||
}
|
||||
PR_ASSERT(stream->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (stream->data_object.mType != MimeClosure::isMimeStreamData) {
|
||||
return -1;
|
||||
}
|
||||
|
||||
MimeObject* obj = (msd ? msd->obj : 0);
|
||||
mime_stream_data* msd = (mime_stream_data*)stream->data_object.mClosure;
|
||||
|
||||
MimeObject* obj = msd->obj;
|
||||
if (!obj) return -1;
|
||||
|
||||
return obj->clazz->parse_buffer((char*)buf, size,
|
||||
|
@ -816,8 +823,12 @@ extern "C" int mime_display_stream_write(nsMIMESession* stream, const char* buf,
|
|||
}
|
||||
|
||||
extern "C" void mime_display_stream_complete(nsMIMESession* stream) {
|
||||
mime_stream_data* msd =
|
||||
(mime_stream_data*)((nsMIMESession*)stream)->data_object;
|
||||
PR_ASSERT(stream->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (stream->data_object.mType != MimeClosure::isMimeStreamData) {
|
||||
return;
|
||||
}
|
||||
|
||||
mime_stream_data* msd = (mime_stream_data*)stream->data_object.mClosure;
|
||||
MimeObject* obj = (msd ? msd->obj : 0);
|
||||
if (obj) {
|
||||
int status;
|
||||
|
@ -869,8 +880,12 @@ extern "C" void mime_display_stream_complete(nsMIMESession* stream) {
|
|||
}
|
||||
|
||||
extern "C" void mime_display_stream_abort(nsMIMESession* stream, int status) {
|
||||
mime_stream_data* msd =
|
||||
(mime_stream_data*)((nsMIMESession*)stream)->data_object;
|
||||
PR_ASSERT(stream->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (stream->data_object.mType != MimeClosure::isMimeStreamData) {
|
||||
return;
|
||||
}
|
||||
|
||||
mime_stream_data* msd = (mime_stream_data*)stream->data_object.mClosure;
|
||||
|
||||
MimeObject* obj = (msd ? msd->obj : 0);
|
||||
if (obj) {
|
||||
|
@ -1443,7 +1458,7 @@ extern "C" void* mime_bridge_create_display_stream(
|
|||
stream->complete = mime_display_stream_complete;
|
||||
stream->abort = mime_display_stream_abort;
|
||||
stream->put_block = mime_display_stream_write;
|
||||
stream->data_object = msd;
|
||||
stream->data_object = MimeClosure(MimeClosure::isMimeStreamData, msd);
|
||||
|
||||
status = obj->clazz->initialize(obj);
|
||||
if (status >= 0) status = obj->clazz->parse_begin(obj);
|
||||
|
@ -1704,7 +1719,12 @@ extern "C" nsresult mimeEmitterStartHeader(MimeDisplayOptions* opt,
|
|||
extern "C" nsresult mimeSetNewURL(nsMIMESession* stream, char* url) {
|
||||
if ((!stream) || (!url) || (!*url)) return NS_ERROR_FAILURE;
|
||||
|
||||
mime_stream_data* msd = (mime_stream_data*)stream->data_object;
|
||||
PR_ASSERT(stream->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (stream->data_object.mType != MimeClosure::isMimeStreamData) {
|
||||
return NS_ERROR_UNEXPECTED;
|
||||
}
|
||||
|
||||
mime_stream_data* msd = (mime_stream_data*)stream->data_object.mClosure;
|
||||
if (!msd) return NS_ERROR_FAILURE;
|
||||
|
||||
char* tmpPtr = strdup(url);
|
||||
|
|
|
@ -48,16 +48,16 @@ struct _nsMIMESession {
|
|||
|
||||
void* window_id; /* used for progress messages, etc. */
|
||||
|
||||
void* data_object; /* a pointer to whatever
|
||||
* structure you wish to have
|
||||
* passed to the routines below
|
||||
* during writes, etc...
|
||||
*
|
||||
* this data object should hold
|
||||
* the document, document
|
||||
* structure or a pointer to the
|
||||
* document.
|
||||
*/
|
||||
MimeClosure data_object; /* a pointer to whatever
|
||||
* structure you wish to have
|
||||
* passed to the routines below
|
||||
* during writes, etc...
|
||||
*
|
||||
* this data object should hold
|
||||
* the document, document
|
||||
* structure or a pointer to the
|
||||
* document.
|
||||
*/
|
||||
|
||||
MKSessionWriteReadyFunc is_write_ready; /* checks to see if the stream is
|
||||
* ready for writing. Returns 0 if
|
||||
|
|
|
@ -62,8 +62,12 @@ void bridge_set_output_type(void* bridgeStream, nsMimeOutputType aType) {
|
|||
nsMIMESession* session = (nsMIMESession*)bridgeStream;
|
||||
|
||||
if (session) {
|
||||
// BAD ASSUMPTION!!!! NEED TO CHECK aType
|
||||
mime_stream_data* msd = (mime_stream_data*)session->data_object;
|
||||
PR_ASSERT(session->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (session->data_object.mType != MimeClosure::isMimeStreamData) {
|
||||
return;
|
||||
}
|
||||
|
||||
mime_stream_data* msd = (mime_stream_data*)session->data_object.mClosure;
|
||||
if (msd) msd->format_out = aType; // output format type
|
||||
}
|
||||
}
|
||||
|
@ -81,20 +85,28 @@ nsresult bridge_new_new_uri(void* bridgeStream, nsIURI* aURI,
|
|||
|
||||
if ((aOutputType == nsMimeOutput::nsMimeMessageDraftOrTemplate) ||
|
||||
(aOutputType == nsMimeOutput::nsMimeMessageEditorTemplate)) {
|
||||
mime_draft_data* mdd = (mime_draft_data*)session->data_object;
|
||||
if (mdd->options) {
|
||||
default_charset = &(mdd->options->default_charset);
|
||||
override_charset = &(mdd->options->override_charset);
|
||||
url_name = &(mdd->url_name);
|
||||
PR_ASSERT(session->data_object.mType == MimeClosure::isMimeDraftData);
|
||||
if (session->data_object.mType == MimeClosure::isMimeDraftData) {
|
||||
mime_draft_data* mdd =
|
||||
(mime_draft_data*)session->data_object.mClosure;
|
||||
if (mdd->options) {
|
||||
default_charset = &(mdd->options->default_charset);
|
||||
override_charset = &(mdd->options->override_charset);
|
||||
url_name = &(mdd->url_name);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mime_stream_data* msd = (mime_stream_data*)session->data_object;
|
||||
PR_ASSERT(session->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (session->data_object.mType == MimeClosure::isMimeStreamData) {
|
||||
mime_stream_data* msd =
|
||||
(mime_stream_data*)session->data_object.mClosure;
|
||||
|
||||
if (msd->options) {
|
||||
default_charset = &(msd->options->default_charset);
|
||||
override_charset = &(msd->options->override_charset);
|
||||
url_name = &(msd->url_name);
|
||||
fixup_pointer = &(msd->options->url);
|
||||
if (msd->options) {
|
||||
default_charset = &(msd->options->default_charset);
|
||||
override_charset = &(msd->options->override_charset);
|
||||
url_name = &(msd->url_name);
|
||||
fixup_pointer = &(msd->options->url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -167,26 +179,32 @@ nsresult bridge_set_mime_stream_converter_listener(
|
|||
if ((session) && (session->data_object)) {
|
||||
if ((aOutputType == nsMimeOutput::nsMimeMessageDraftOrTemplate) ||
|
||||
(aOutputType == nsMimeOutput::nsMimeMessageEditorTemplate)) {
|
||||
mime_draft_data* mdd = (mime_draft_data*)session->data_object;
|
||||
if (mdd->options) {
|
||||
if (listener) {
|
||||
mdd->options->caller_need_root_headers = true;
|
||||
mdd->options->decompose_headers_info_fn = mime_headers_callback;
|
||||
} else {
|
||||
mdd->options->caller_need_root_headers = false;
|
||||
mdd->options->decompose_headers_info_fn = nullptr;
|
||||
PR_ASSERT(session->data_object.mType == MimeClosure::isMimeDraftData);
|
||||
if (session->data_object.mType == MimeClosure::isMimeDraftData) {
|
||||
mime_draft_data* mdd = (mime_draft_data*)session->data_object.mClosure;
|
||||
if (mdd->options) {
|
||||
if (listener) {
|
||||
mdd->options->caller_need_root_headers = true;
|
||||
mdd->options->decompose_headers_info_fn = mime_headers_callback;
|
||||
} else {
|
||||
mdd->options->caller_need_root_headers = false;
|
||||
mdd->options->decompose_headers_info_fn = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
mime_stream_data* msd = (mime_stream_data*)session->data_object;
|
||||
|
||||
if (msd->options) {
|
||||
if (listener) {
|
||||
msd->options->caller_need_root_headers = true;
|
||||
msd->options->decompose_headers_info_fn = mime_headers_callback;
|
||||
} else {
|
||||
msd->options->caller_need_root_headers = false;
|
||||
msd->options->decompose_headers_info_fn = nullptr;
|
||||
PR_ASSERT(session->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (session->data_object.mType == MimeClosure::isMimeStreamData) {
|
||||
mime_stream_data* msd =
|
||||
(mime_stream_data*)session->data_object.mClosure;
|
||||
if (msd->options) {
|
||||
if (listener) {
|
||||
msd->options->caller_need_root_headers = true;
|
||||
msd->options->decompose_headers_info_fn = mime_headers_callback;
|
||||
} else {
|
||||
msd->options->caller_need_root_headers = false;
|
||||
msd->options->decompose_headers_info_fn = nullptr;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -816,11 +834,19 @@ nsresult nsStreamConverter::OnStopRequest(nsIRequest* request,
|
|||
|
||||
if ((mOutputType == nsMimeOutput::nsMimeMessageDraftOrTemplate) ||
|
||||
(mOutputType == nsMimeOutput::nsMimeMessageEditorTemplate)) {
|
||||
mime_draft_data* mdd = (mime_draft_data*)tSession->data_object;
|
||||
if (mdd) workHeaders = &(mdd->headers);
|
||||
PR_ASSERT(tSession->data_object.mType == MimeClosure::isMimeDraftData);
|
||||
if (tSession->data_object.mType == MimeClosure::isMimeDraftData) {
|
||||
mime_draft_data* mdd =
|
||||
(mime_draft_data*)tSession->data_object.mClosure;
|
||||
if (mdd) workHeaders = &(mdd->headers);
|
||||
}
|
||||
} else {
|
||||
mime_stream_data* msd = (mime_stream_data*)tSession->data_object;
|
||||
if (msd) workHeaders = &(msd->headers);
|
||||
PR_ASSERT(tSession->data_object.mType == MimeClosure::isMimeStreamData);
|
||||
if (tSession->data_object.mType == MimeClosure::isMimeStreamData) {
|
||||
mime_stream_data* msd =
|
||||
(mime_stream_data*)tSession->data_object.mClosure;
|
||||
if (msd) workHeaders = &(msd->headers);
|
||||
}
|
||||
}
|
||||
|
||||
if (workHeaders) {
|
||||
|
|
Загрузка…
Ссылка в новой задаче