Exemple #1
0
//-----------------------------------------------------------------------------
// GenNetStream
//
// This is what NetStream out should have been! A generalized net function.
// 
//-----------------------------------------------------------------------------
CStreamOutAnyNet::CStreamOutAnyNet(MWContext* pContext, URL_Struct *URL_s, FO_Present_Types type ){
    NET_StreamClass *stream;
    //URL_s->content_type = XP_STRDUP(TEXT_PLAIN);

    stream = NET_StreamBuilder(type, URL_s, pContext);

    if(!stream){
        XP_ASSERT( FALSE );
    }
    else {
	SetStream(stream);
    }
}
NET_StreamClass *
OLE_ViewStream(int format_out, void *pDataObj, URL_Struct *urls,
              MWContext *pContext)
{
    NET_StreamClass *stream = nil, *viewstream;
	char *org_content_type;
    
    if (!(stream = XP_NEW_ZAP(NET_StreamClass))) {
		XP_TRACE(("OLE_ViewStream memory lossage"));
		return 0;
	}
	
    stream->name           = "ole viewer";
    stream->complete       = ole_view_complete;
    stream->abort          = ole_view_abort;
    stream->is_write_ready = ole_view_write_ready;
    stream->data_object    = NULL;
    stream->window_id      = pContext;
    stream->put_block      = (MKStreamWriteFunc)ole_view_write;

	org_content_type = urls->content_type; 
	urls->content_type = 0;
	StrAllocCopy(urls->content_type, TEXT_HTML);
	urls->is_binary = 1;	/* secret flag for mail-to save as */

	if((viewstream=NET_StreamBuilder(format_out, urls, pContext)) != 0)
	{
        char *buffer = (char*)
            XP_ALLOC(XP_STRLEN(fakehtml) + XP_STRLEN(urls->address) + 1);

        if (buffer)
        {
            XP_SPRINTF(buffer, fakehtml, urls->address);
            (*viewstream->put_block)(viewstream,
                                     buffer, XP_STRLEN(buffer));
            (*viewstream->complete)(viewstream);
            XP_FREE(buffer);
        }
	}

	/* XXX hack alert - this has to be set back for abort to work
       correctly */
	XP_FREE(urls->content_type);
	urls->content_type = org_content_type;

    return stream;
}
Exemple #3
0
void
xmlhtml_complete  (NET_StreamClass *stream)
{
  XMLHTMLInclusion ss =stream->data_object;
  XMLFile xml = ss->xml;
  xml->numOpenStreams--;
  if (xml->numOpenStreams == 0) { 
  /* direct the stream to the html parser */
    NET_StreamClass *newstream;
    URL_Struct *nurls =   NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
    StrAllocCopy(nurls->content_type, TEXT_HTML);
    newstream = NET_StreamBuilder(1,  nurls, (MWContext*) xml->mwcontext);
    xml->stream = newstream;
    convertToHTML(xml);
    newstream->complete(newstream);
    NET_FreeURLStruct(nurls); 
  }     
}
Exemple #4
0
void
xml_complete (NET_StreamClass *stream)
{
  NET_StreamClass *newstream;
  void *obj=stream->data_object;
  URL_Struct *urls = ((XMLFile)obj)->urls;
  freeMem(((XMLFile)obj)->holdOver);
  freeMem(((XMLFile)obj)->line);
  ((XMLFile)obj)->line = ((XMLFile)obj)->holdOver = NULL; 
  ((XMLFile)obj)->numOpenStreams--;
  if (((XMLFile)obj)->numOpenStreams < 1) {
  /* direct the stream to the html parser */
    URL_Struct *nurls =   NET_CreateURLStruct(copyString(urls->address), NET_DONT_RELOAD);
    StrAllocCopy(nurls->content_type, TEXT_HTML);

    newstream = NET_StreamBuilder(1,  nurls, (MWContext*) ((XMLFile)obj)->mwcontext);
    ((XMLFile)obj)->stream = newstream;
    convertToHTML(((XMLFile)obj));
    newstream->complete(newstream);
    NET_FreeURLStruct(nurls); 
  }
}
Exemple #5
0
void
xmlcss_complete  (NET_StreamClass *stream)
{
  StyleSheet ss =stream->data_object;
  URL_Struct *urls = ss->urls;
  XMLFile xml = ss->xmlFile;
  freeMem(ss->holdOver);
  freeMem(ss->line);
  ss->line = ss->holdOver = NULL; 
  xml->numOpenStreams--;
  if (xml->numOpenStreams == 0) { 
  /* direct the stream to the html parser */
    NET_StreamClass *newstream;
    URL_Struct *nurls =   NET_CreateURLStruct(copyString(xml->address), NET_DONT_RELOAD);
    StrAllocCopy(nurls->content_type, TEXT_HTML);
    newstream = NET_StreamBuilder(1,  nurls, (MWContext*) xml->mwcontext);
    xml->stream = newstream;
    convertToHTML(xml);
    newstream->complete(newstream);
    NET_FreeURLStruct(nurls); 
  }     
}
Exemple #6
0
//-----------------------------------------------------------------------------
// NetStream
//-----------------------------------------------------------------------------
CStreamOutNet::CStreamOutNet( MWContext* pContext )
{
    URL_Struct * URL_s;
    Chrome chrome;

    XP_BZERO( &chrome, sizeof( Chrome ) );
    chrome.allow_close = TRUE;
    chrome.allow_resize = TRUE;
    chrome.show_scrollbar = TRUE;
#ifndef XP_WIN
	// NOTE:  need to verify this change on XP_WIN and remove the
	//        ifndef... [ works on XP_UNIX & XP_MAC ]
	//
	chrome.type = MWContextDialog;
#endif

    //
    // LTNOTE: Ownership of the 'chrome' struct isn't documented in the interface.
    //  The windows implementation doesn't appear to keep pointers to the struct.
    //
    MWContext *pNewContext = FE_MakeNewWindow(pContext, NULL, "view-source",
                    &chrome );
    pNewContext->edit_view_source_hack = TRUE;

    URL_s = NET_CreateURLStruct(XP_GetString(EDT_VIEW_SOURCE_WINDOW_TITLE), NET_DONT_RELOAD);  

    URL_s->content_type = XP_STRDUP(TEXT_PLAIN);

    m_pStream = NET_StreamBuilder(FO_PRESENT, URL_s, pNewContext);

    if(!m_pStream){
        XP_ASSERT( FALSE );
        m_status = EOS_FileError;
    } 
    m_status = EOS_NoError;
}
Exemple #7
0
NET_StreamClass *
IL_ViewStream(FO_Present_Types format_out, void *newshack, URL_Struct *urls,
              OPAQUE_CONTEXT *cx)
{
    IL_Stream *stream = nil, *viewstream;
	il_container *ic = nil;
	char *org_content_type;
    char *image_url;

	/* multi-part reconnect hack */

	ic = (il_container*)urls->fe_data;
	if(ic && ic->multi)
	{
		return IL_NewStream(format_out, IL_UNKNOWN, urls, cx);
	}

	/* Create stream object */
    if (!(stream = XP_NEW_ZAP(NET_StreamClass))) {
		XP_TRACE(("il: IL_ViewStream memory lossage"));
		return 0;
	}
	
    stream->name           = "image view";
    stream->complete       = il_view_complete;
    stream->abort          = il_view_abort;
    stream->is_write_ready = il_view_write_ready;
    stream->data_object    = NULL;
    stream->window_id      = cx;
    stream->put_block      = (MKStreamWriteFunc)il_view_write;

	ILTRACE(0,("il: new view stream, %s", urls->address));

	XP_ASSERT(!unconnected_stream);
	unconnected_stream = stream;
	unconnected_urls = urls;

	if(!newshack)
	{
        char *buffer;

		org_content_type = urls->content_type; 
		urls->content_type = 0;
		StrAllocCopy(urls->content_type, TEXT_HTML);
		urls->is_binary = 1;	/* secret flag for mail-to save as */

		/* Force layout to discard the old document and start a new one.
		   We do this so that the pre-fetched image request won't be
		   destroyed by a layout call to IL_DestroyImageGroup. */

		viewstream = NET_StreamBuilder(format_out, urls, cx);
		if (!viewstream) {
			XP_FREE(stream);
			return NULL;
		}
        buffer = XP_STRDUP("<HTML>");
        if (!buffer) {
            XP_FREE(stream);
            XP_FREE(viewstream);
            return NULL;
        }
		(*viewstream->put_block)(viewstream, buffer,
                                 XP_STRLEN(buffer)+1);
        XP_FREE(buffer);

	} /* !newshack */

	/* Prefetch the image.  We do this so that the image library can
	   process image data even if the parser is blocked on the fake IMG
	   tag that we send.  Note that this image request will persist until
	   the document is destroyed (when IL_DestroyImageGroup will be called.) */
    image_url = (char*) XP_ALLOC(XP_STRLEN(urls->address) + 29);
    if (!image_url) {
        XP_FREE(stream);
        XP_FREE(viewstream);
        return NULL;
    }
    XP_SPRINTF(image_url, "internal-external-reconnect:%s", urls->address);
    if (!il_load_image(cx, image_url, urls->force_reload)) {
        XP_FREE(stream);
        XP_FREE(viewstream);
        return NULL;
    }
    XP_FREE(image_url);

	if (!newshack) {
	    if (viewstream) {
            	char *buffer = (char*)
                XP_ALLOC(XP_STRLEN(fakehtml) + XP_STRLEN(urls->address) + 1);

            if (buffer)
            {
                XP_SPRINTF(buffer, fakehtml, urls->address);
                (*viewstream->put_block)(viewstream,
                                         buffer, XP_STRLEN(buffer));
                XP_FREE(buffer);
            }
			(*viewstream->complete)(viewstream);
		}

		/* this has to be set back for abort to work correctly */
		XP_FREE(urls->content_type);
		urls->content_type = org_content_type;
	} /* !newshack */

    return stream;
}
Exemple #8
0
void npl_ScriptPlugin(MWContext *context, lo_DocState *state, PA_Tag *tag, size_t line_buf_len, char * mimebuf)
{
	char * suffix				= NULL;
    char * fname				= NULL;
	char * embedtagstr			= NULL;
	char * NET_suffix			= NULL;
	PA_Tag * newTag				= NULL;
	NET_StreamClass* viewstream = NULL;
    URL_Struct* urls			= NULL;
	int streamStatus			= 0;
	int id						= 0;

	if (!context || !state || !tag || (line_buf_len <= 0) || !mimebuf){
		XP_Trace("npl_ScriptPlugin:  Invalid input(s).");
		return; /* no need to goto clean_exit, since havn't alloc'd anything */
	}

	urls = NET_CreateURLStruct("internal_url.", NET_DONT_RELOAD);
			ALLOC_CHECK(urls,id,abnormal_exit);

	/* NETLib gives me a pointer here instead of a copy of the string, so I have to make
	   my own, make checks, etc. 
	 */
	NET_suffix = NET_cinfo_find_ext(mimebuf);
	if (!NET_suffix)
		goto abnormal_exit;

	suffix = PR_smprintf("internal_url.%s", NET_suffix);
			ALLOC_CHECK(suffix,id,abnormal_exit);

			XP_FREEIF(urls->address);
	StrAllocCopy(urls->address     , suffix);
			ALLOC_CHECK(urls->address,id,abnormal_exit);

			XP_FREEIF(urls->content_name);
	StrAllocCopy(urls->content_name, suffix);
			ALLOC_CHECK(urls->content_name,id,abnormal_exit);

			XP_FREEIF(urls->content_type);
	StrAllocCopy(urls->content_type, mimebuf);
			ALLOC_CHECK(urls->content_type,id,abnormal_exit);

	urls->must_cache = 1;  	/* ugly flag for mailto and saveas */

	viewstream = NET_StreamBuilder(FO_CACHE_ONLY, urls, context);
			ALLOC_CHECK(viewstream,id,abnormal_exit);

	streamStatus =
		(*viewstream->put_block)(viewstream,(CONST char*)state->line_buf, line_buf_len);
	if (streamStatus <= 0)
		goto abnormal_exit;
	(*viewstream->complete)(viewstream);

	/* Now build internal embed tag pointing to this source:  */
    fname = WH_FileName(urls->cache_file, xpCache);
			ALLOC_CHECK(fname,id,abnormal_exit);
	embedtagstr = PR_smprintf("<EMBED SRC=file:///%s HIDDEN=TRUE>", fname);
			ALLOC_CHECK(embedtagstr,id,abnormal_exit);

	newTag = LO_CreateHiddenEmbedTag(tag,embedtagstr);
			ALLOC_CHECK(newTag,id,abnormal_exit);

	lo_FormatEmbed(context,state,newTag);	 
	goto normal_exit;

abnormal_exit:
	XP_Trace("npl_ScriptPlugin:  Abnormal termination, id = %d",id);
	if (urls) {
		XP_FREEIF(urls->content_type);
		XP_FREEIF(urls->content_name);
		XP_FREEIF(urls->address);
		XP_FREE(  urls);
	}

normal_exit:
	XP_FREEIF(newTag);
	XP_FREEIF(embedtagstr);
	XP_FREEIF(fname);
	XP_FREEIF(viewstream);
	XP_FREEIF(suffix);
	return;

}
Exemple #9
0
PUBLIC Stream *
INTL_ConvCharCode (int         format_out,
                         void       *data_obj,
                         URL_Struct *URL_s,
                         MWContext  *mwcontext)
{
	NetStreamData *nsd;
    CCCDataObject	obj;
    Stream *stream;
	iDocumentContext doc_context = (iDocumentContext)mwcontext;
	INTL_CharSetInfo c = LO_GetDocumentCharacterSetInfo(doc_context);
	XP_Bool is_metacharset_reload;
	uint16 default_doc_csid = INTL_DefaultDocCharSetID(mwcontext);
/*
    Should this be ?
	uint16 default_doc_csid = FE_DefaultDocCharSetID(mwcontext);
*/


    TRACEMSG(("Setting up display stream. Have URL: %s\n", URL_s->address));

    stream = XP_NEW_ZAP(Stream);
    if(stream == NULL)
        return(NULL);

    stream->name           = "CharCodeConverter";
    stream->complete       = (MKStreamCompleteFunc) net_CvtCharCodeComplete;
    stream->abort          = (MKStreamAbortFunc) net_CvtCharCodeAbort;

    stream->is_write_ready = (MKStreamWriteReadyFunc) net_CvtCharCodeWriteReady;
    stream->window_id      = doc_context;

	/* initialize the doc_csid (etc.) unless if this is a reload caused by meta charset */
	if ((NET_RESIZE_RELOAD == URL_s->resize_reload) 
		&& (METACHARSET_FORCERELAYOUT == INTL_GetCSIRelayoutFlag(c)))
		is_metacharset_reload = TRUE;
	else
		is_metacharset_reload = FALSE;

	INTL_CSIInitialize(c, is_metacharset_reload, URL_s->charset,
						mwcontext->type, default_doc_csid);

	obj = INTL_CreateDocumentCCC(c, default_doc_csid);
    if (obj == NULL) {
		XP_FREE(stream);
		return(NULL);
	}

    nsd = XP_NEW_ZAP(NetStreamData);
    if(nsd == NULL) {
		XP_FREE(stream);
		XP_FREE(obj);
		return(NULL);
	}
	nsd->current_stream = stream;
	nsd->obj = obj;
    stream->data_object = nsd;  /* document info object */
	INTL_SetCCCReportAutoDetect(obj, net_report_autodetect, nsd);


	if (INTL_GetCSIDocCSID(c) == CS_DEFAULT || INTL_GetCSIDocCSID(c) == CS_UNKNOWN)
	{
		/* we know the default converter but do not install it yet. 
		 * Instead wait until the first block and see if we can determine
		 * what the actual charset is from http/meta tags or from the 
		 * first block. By delaying we can avoid a reload if
		 * we get a different charset from http/meta tag or the first block.
		 */
		stream->put_block	= (MKStreamWriteFunc) net_AutoCharCodeConv;
	}
	else
	{
		if (INTL_GetCCCCvtfunc(obj) == NULL)
			stream->put_block	= (MKStreamWriteFunc) net_NoCharCodeConv;
    	else if (INTL_GetCCCCvtfunc(obj) == (CCCFunc)One2OneCCC)
    		stream->put_block	= (MKStreamWriteFunc) net_1to1CCC;
    	else
    		stream->put_block	= (MKStreamWriteFunc) net_CharCodeConv;
	}

    TRACEMSG(("Returning stream from NET_CvtCharCodeConverter\n"));
	
	/* remap content type to be to INTERNAL_PARSER
 	 */
	StrAllocCopy(URL_s->content_type, INTERNAL_PARSER);

#ifdef JSDEBUGGER
	nsd->next_stream = LM_StreamBuilder(format_out, NULL, URL_s, mwcontext);
#else
	nsd->next_stream = NET_StreamBuilder(format_out, URL_s, doc_context);
#endif /* JSDEBUGGER */

    if(!nsd->next_stream)
	  {
		XP_FREE(obj);
		XP_FREE(stream);
		XP_FREE(nsd);
		return(NULL);
	  }

    return stream;
}
Exemple #10
0
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;
}