Example #1
0
intn
PA_ParseStringToTags(MWContext *context, char *buf, int32 len,
		void *output_func)
{
	intn ret;
	pa_DocData *fake_doc_data;
	NET_StreamClass s;

	fake_doc_data = XP_NEW_ZAP(pa_DocData);
	if (fake_doc_data == NULL)
	{
		return(-1);
	}

	fake_doc_data->doc_id = 100164;
	fake_doc_data->window_id = context;
	fake_doc_data->output_tag = (PA_OutputFunction *)output_func;
	fake_doc_data->hold_buf = XP_ALLOC(HOLD_BUF_UNIT * sizeof(char));
	if (fake_doc_data->hold_buf == NULL)
	{
		XP_DELETE(fake_doc_data);
		return(-1);
	}
	fake_doc_data->hold_size = HOLD_BUF_UNIT;

	fake_doc_data->brute_tag = P_UNKNOWN;
	fake_doc_data->format_out = FO_PRESENT_INLINE;
	fake_doc_data->parser_stream = XP_NEW(NET_StreamClass);
	if (fake_doc_data->parser_stream == NULL)
	{
		XP_FREE(fake_doc_data->hold_buf);
		XP_DELETE(fake_doc_data);
		return(-1);
	}
	/* We don't need most of the fields in the fake stream */
	fake_doc_data->parser_stream->complete = PA_MDLComplete;
	fake_doc_data->parser_stream->data_object = (void *)fake_doc_data;
	fake_doc_data->is_inline_stream = TRUE;

	s.data_object=fake_doc_data;

	ret = PA_ParseBlock(&s, (const char *)buf, (int)len);
	if (ret > 0)
	{
		PA_MDLComplete(&s);
	}

	return(ret);
}
Example #2
0
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;
}
Example #3
0
/* Must remain idempotent.  Also used to make sure that the ic->quantize has the same 
colorSpace info as the rest of ic. */
int
il_init_quantize(il_container *ic)
{
    size_t arraysize;
    int i, j;
    my_cquantize_ptr cquantize;

    if (ic->quantize)
        il_free_quantize(ic);

    ic->quantize = XP_NEW_ZAP(my_cquantize);
    if (!ic->quantize) 
	{
	loser:
		ILTRACE(0,("il: MEM il_init_quantize"));
		return FALSE;
    }

    cquantize = (my_cquantize_ptr) ic->quantize;
    arraysize = (size_t) ((ic->image->header.width + 2) * SIZEOF(FSERROR));
    for (i = 0; i < 3; i++) 
	{
		cquantize->fserrors[i] = (FSERRPTR) XP_CALLOC(1, arraysize);
		if (!cquantize->fserrors[i]) 
		{
			/* ran out of memory part way thru */
			for (j = 0; j < i; j++) 
			{
				if (cquantize->fserrors[j])
				{
					XP_FREE(cquantize->fserrors[j]);
					cquantize->fserrors[j]=0;
				}
			}
			if (cquantize)
			{
				XP_FREE(cquantize);
				ic->quantize = 0;
			}
			goto loser;
		}
    }

    return TRUE;
}
Example #4
0
cfpFactory_Create(JMCException* *exception, struct nffbp* a)
{
    cfpImplHeader* impl = (cfpImplHeader*)XP_NEW_ZAP(cfpImpl);
    cfp* self;
    if (impl == NULL) {
        JMC_EXCEPTION(exception, JMCEXCEPTION_OUT_OF_MEMORY);
        return NULL;
    }
    self = cfpImpl2cfp(impl);
    impl->vtablecfp = &cfpVtable;
    impl->refcount = 1;
    _cfp_init(self, exception, a);
    if (JMC_EXCEPTION_RETURNED(exception)) {
        XP_FREE(impl);
        return NULL;
    }
    return self;
}
Example #5
0
cdlmFactory_Create(JMCException* *exception)
{
	cdlmImplHeader* impl = (cdlmImplHeader*)XP_NEW_ZAP(cdlmImpl);
	cdlm* self;
	if (impl == NULL) {
		JMC_EXCEPTION(exception, JMCEXCEPTION_OUT_OF_MEMORY);
		return NULL;
	}
	self = cdlmImpl2cdlm(impl);
	impl->vtablecdlm = &cdlmVtable;
	impl->refcount = 1;
	_cdlm_init(self, exception);
	if (JMC_EXCEPTION_RETURNED(exception)) {
		XP_FREE(impl);
		return NULL;
	}
	return self;
}
Example #6
0
winrfFactory_Create(JMCException* *exception)
{
	winrfImplHeader* impl = (winrfImplHeader*)XP_NEW_ZAP(winrfImpl);
	winrf* self;
	if (impl == NULL) {
		JMC_EXCEPTION(exception, JMCEXCEPTION_OUT_OF_MEMORY);
		return NULL;
	}
	self = winrfImpl2winrf(impl);
	impl->vtablewinrf = &winrfVtable;
	impl->refcount = 1;
	_winrf_init(self, exception);
	if (JMC_EXCEPTION_RETURNED(exception)) {
		XP_FREE(impl);
		return NULL;
	}
	return self;
}
Example #7
0
winfpFactory_Create(JMCException* *exception, struct nffbp* broker)
{
	winfpImplHeader* impl = (winfpImplHeader*)XP_NEW_ZAP(winfpImpl);
	winfp* self;
	if (impl == NULL) {
		JMC_EXCEPTION(exception, JMCEXCEPTION_OUT_OF_MEMORY);
		return NULL;
	}
	self = winfpImpl2winfp(impl);
	impl->vtablewinfp = &winfpVtable;
	impl->refcount = 1;
	_winfp_init(self, exception, broker);
	if (JMC_EXCEPTION_RETURNED(exception)) {
		XP_FREE(impl);
		return NULL;
	}
	return self;
}
Example #8
0
IMGCBFactory_Create(JMCException* *exception)
{
	IMGCBImplHeader* impl = (IMGCBImplHeader*)XP_NEW_ZAP(IMGCBImpl);
	IMGCB* self;
	if (impl == NULL) {
		JMC_EXCEPTION(exception, JMCEXCEPTION_OUT_OF_MEMORY);
		return NULL;
	}
	self = IMGCBImpl2IMGCB(impl);
	impl->vtableIMGCB = &IMGCBVtable;
	impl->refcount = 1;
	_IMGCB_init(self, exception);
	if (JMC_EXCEPTION_RETURNED(exception)) {
		XP_FREE(impl);
		return NULL;
	}
	return self;
}
Example #9
0
/*
 * XXX chouck - the onLocate stuff hasn't been implemented yet
 *              so just return JS_TRUE and go away
 */
JSBool
LM_SendOnLocate(MWContext *context, lo_NameList *name_rec)
{
    JSBool ok;
    JSObject *obj;
    jsval result;
    JSEvent *event;

    return JS_TRUE;

    obj = name_rec->mocha_object;
    if (!obj)
        return JS_FALSE;

    event = XP_NEW_ZAP(JSEvent);
    event->type = EVENT_LOCATE;
    ok = lm_SendEvent(context, obj, event, &result);
    return ok;
}
Example #10
0
/* WARNING ! the mac FE does not call this ! */
MWContext *
XP_NewContext(void)
{
	MWContext *context;

	context = XP_NEW_ZAP(MWContext);
	XP_ASSERT(NULL != context);
	if (NULL == context)
	{
		return NULL;
	}
	context->INTL_CSIInfo = INTL_CSICreate();
	if (NULL == context->INTL_CSIInfo)
	{
		XP_FREE(context);
		return NULL;
	}
	XP_InitializeContext(context);
	return context;
}
Example #11
0
PUBLIC
void CSS_ConvertToJS(char * src, int32 src_count, char ** dst, int32 * dst_count)
{
    StyleBuffer sb;
    XP_Bool translated;

    *dst = NULL;
    *dst_count = 0;

    if (NULL == src || 0 == src_count)
        return;

    input_buffer = src;
    input_buffer_count = src_count;
    input_buffer_index = 0;

    css_tree_root = NULL;
    if (css_parse() != 0)
        return;

    sb = XP_NEW_ZAP(StyleBufferRec);
    if (sb == NULL)
        return;

    translated = ConvertStyleSheet(css_tree_root, sb);
    css_FreeNode(css_tree_root);
#if ALLOW_IMPORT
    if (! translated)
        EchoCSS(src, src_count, sb);
#endif

    /* The caller should free *dst. */
    *dst = sb->buffer;
    *dst_count = sb->buffer_count;
    XP_DELETE(sb);
}
Example #12
0
static void
lo_script_archive_exit_fn(URL_Struct *url_struct, int status, MWContext *context)
{
    ScriptData *data = NULL;
    char *name;
    JSPrincipals *principals;
    ETEvalStuff * stuff;

    data = (ScriptData *) url_struct->fe_data;
    stuff = (ETEvalStuff *) XP_NEW_ZAP(ETEvalStuff);
    if (!stuff)
	return;

    stuff->line_no = 1;
    stuff->scope_to = NULL;
    stuff->want_result = JS_FALSE;
    stuff->version = data->version;
    stuff->data = context;

#ifndef JAVA
    /* No Java; execute without principals. */
    if (data->buffer) {
	stuff->principals = NULL;
        ET_EvaluateScript(context, data->buffer, stuff, lo_ScriptEvalExitFn);
    }
    else {
	XP_FREE(stuff);
    }
#else
    name = data->archiveSrc ? data->archiveSrc : data->id;
    principals = LM_NewJSPrincipals(url_struct, name, data->codebase);
    if (principals != NULL) {
        char *src;
        uint srcSize;

        if (data->archiveSrc) {
            /* Extract from archive using "SRC=" value */
            src = LM_ExtractFromPrincipalsArchive(principals, data->archiveSrc, 
                                                  &srcSize);
                                                  
#ifdef JSDEBUGGER
        if( src != NULL && LM_GetJSDebugActive() )
        {
            char *path = lo_BuildJSArchiveURL(url_struct->address,
            data->archiveSrc);
            if (path)
            {
                LM_JamSourceIntoJSDebug( path, src, srcSize, context );
                XP_FREE(path);
            }
        }
#endif /* JSDEBUGGER */

            if (src == NULL) {
                /* Unsuccessful extracting from archive. Now try normal SRC= lookup. */
                (*principals->destroy)(NULL, principals);
                data->url = NET_MakeAbsoluteURL(data->state->top_state->base_url, 
                                                data->archiveSrc);
                XP_FREEIF(data->archiveSrc);
                data->archiveSrc = NULL;
                lo_GetScriptFromURL(data, data->state->top_state->in_script);
                goto out;
	    }
        } else {
            /* Should be an inline script */
            src = data->buffer;
            srcSize = data->bufferSize;
        }

	stuff->len = srcSize;
	stuff->principals = principals;
        ET_EvaluateScript(context, src, stuff, lo_ScriptEvalExitFn);

        if (data->archiveSrc){
            ET_SetNestingUrl(context, NULL);
            XP_FREE(src);
        }            
    }
    else {
	XP_FREE(stuff);
    }
	 
#endif /* ifdef JAVA */

    lo_DestroyScriptData(data);

out:
    /* Always free (or drop a ref on) the url_struct before returning. */
    NET_FreeURLStruct(url_struct);
}    
Example #13
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;
}
Example #14
0
lo_ObjectStack*
lo_PushObject(MWContext* context, lo_DocState* state, PA_Tag* tag)
{
	/*
	 * If possible, reuse an object stack entry created in
	 * a previous pass over this tag (i.e. while blocked, by
	 * lo_BlockObjectTag).  If there's no previously-created
	 * object, make a new one.
	 */
	lo_TopState* top_state = state->top_state;
	lo_ObjectStack* new_top = top_state->object_cache;

	if (new_top != NULL)
	{
		/* Find and remove the matching item, if any */
		if (new_top->real_tag == tag)
			top_state->object_cache = new_top->next;
		else
		{
			while (new_top->next != NULL)
			{
				if (new_top->next->real_tag == tag)
				{
					lo_ObjectStack* temp = new_top->next;
					new_top->next = new_top->next->next;
					new_top = temp;
					break;
				}
				new_top = new_top->next;
			}
		}
	}
	
	if (new_top == NULL || new_top->real_tag != tag)
	{
		new_top = XP_NEW_ZAP(lo_ObjectStack);
		if (new_top == NULL)
		{
			state->top_state->out_of_memory = TRUE;
			return NULL;
		}
	}
	
	new_top->next = top_state->object_stack;
	top_state->object_stack = new_top;

	new_top->context = context;
	new_top->state = state;
	
	/*
	 * Clone the tag since the tag passed in may be freed
	 * by the parser before we're ready for it.
	 */
	if (new_top->real_tag != tag)
	{
		new_top->real_tag = tag;

		if (new_top->clone_tag != NULL)
			PA_FreeTag(new_top->clone_tag);

		new_top->clone_tag = XP_NEW(PA_Tag);
		if (new_top->clone_tag != NULL)
		{
			XP_MEMCPY(new_top->clone_tag, tag, sizeof(PA_Tag));
			new_top->clone_tag->data = PA_ALLOC((tag->data_len + 1) * sizeof (char)); 
			if (new_top->clone_tag->data != NULL)
			{
				char* source;
				char* dest;
				PA_LOCK(source, char*, tag->data);
				PA_LOCK(dest, char*, new_top->clone_tag->data);
				XP_MEMCPY(dest, source, tag->data_len + 1);
				PA_UNLOCK(dest);
				PA_UNLOCK(source);
			}
Example #15
0
void
lo_ProcessScriptTag(MWContext *context, lo_DocState *state, PA_Tag *tag, JSObject *obj)
{
    lo_TopState *top_state;
    pa_DocData *doc_data;
    XP_Bool type_explicitly_set=FALSE;
    XP_Bool saw_archive=FALSE;
#ifdef DEBUG_ScriptPlugin
	char * mimebuf = NULL;
#endif

    top_state = state->top_state;
    doc_data = (pa_DocData *)top_state->doc_data;
    XP_ASSERT(doc_data != NULL || state->in_relayout || tag->lo_data);

    if (tag->is_end == FALSE) {
        PA_Block buff;
        char *str, *url, *archiveSrc, *id, *codebase;

        /* Controversial default language value. */
        top_state->version = JSVERSION_DEFAULT;
        if (tag->type == P_STYLE || tag->type == P_LINK) {
            top_state->in_script = top_state->default_style_script_type;
        }
        else {
            /* in order to get old script behaviour, pretend
             * that the content-type is explicitly set for all scripts
             */
            type_explicitly_set = TRUE;
            top_state->in_script = SCRIPT_TYPE_MOCHA;
        }

        /* XXX account for HTML comment bytes and  "lost" newlines */
        if (lo_IsAnyCurrentAncestorSourced(state))
            top_state->script_bytes = top_state->layout_bytes;
        else
            top_state->script_bytes = top_state->layout_bytes - tag->true_len;
        if (tag->lo_data != NULL) {
            top_state->script_bytes += (int32)tag->lo_data - 1;
            tag->lo_data = NULL;
        } 
        else if (doc_data != NULL) {
            top_state->script_bytes += doc_data->comment_bytes;
        } 
        else {
            XP_ASSERT(state->in_relayout);
        }

	lo_ParseScriptLanguage(context, tag, &top_state->in_script,
			       &top_state->version);
#ifdef DEBUG_ScriptPlugin
		if (top_state->in_script == SCRIPT_TYPE_UNKNOWN)
		{
			mimebuf = npl_Script2mimeType(context,tag);
			if (mimebuf){
				if (NPL_FindPluginEnabledForType(mimebuf)){
					top_state->in_script = SCRIPT_TYPE_PLUGIN;
					XP_ASSERT(top_state->mimetype == NULL);
					StrAllocCopy((char *)top_state->mimetype,mimebuf);
					XP_FREE(mimebuf);
					mimebuf = NULL;
				}
				else{
					XP_FREE(mimebuf);
					mimebuf = NULL;
				}
			}
		}
#endif /* DEBUG_ScriptPlugin */

        buff = lo_FetchParamValue(context, tag, PARAM_TYPE);
        if (buff != NULL) {
            PA_LOCK(str, char *, buff);
            if ((XP_STRCASECMP(str, js_content_type) == 0) ||
                (!XP_STRCASECMP(str, "text/javascript"))) {
		if(tag->type == P_STYLE || tag->type == P_LINK)
		{
		    top_state->in_script = SCRIPT_TYPE_JSSS;
		    top_state->default_style_script_type = SCRIPT_TYPE_JSSS;
		}
		else
		{
		    top_state->in_script = SCRIPT_TYPE_MOCHA;                    
		}
                type_explicitly_set = TRUE;
            } 
            else if ((XP_STRCASECMP(str, TEXT_CSS) == 0)) {
                top_state->in_script = SCRIPT_TYPE_CSS;
                top_state->default_style_script_type = SCRIPT_TYPE_CSS;
                type_explicitly_set = TRUE;
            } 
            else {
                top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                top_state->default_style_script_type = SCRIPT_TYPE_UNKNOWN;
            }
            PA_UNLOCK(buff);
            PA_FREE(buff);
        } 

	/* check for media=screen
	 * don't load the style sheet if there 
	 * is a media not equal to screen
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_MEDIA);
	if (buff) {
	    if (strcasecomp((char*)buff, "screen")) {
		/* set the script type to UNKNOWN
		 * so that it will get thrown away
		 */
		top_state->in_script = SCRIPT_TYPE_UNKNOWN;
	    }
	    PA_FREE(buff);
	}

        /*
         * Flush the line buffer so we can start storing Mocha script
         * source lines in there.
         */
        lo_FlushLineBuffer(context, state);

        url = archiveSrc = id = codebase = NULL;
        if (top_state->in_script != SCRIPT_TYPE_NOT) {
            /*
             * Check for the archive parameter for known languages.
             */
            buff = lo_FetchParamValue(context, tag, PARAM_ARCHIVE);
            if (buff != NULL) {
                saw_archive = TRUE;
                PA_LOCK(str, char *, buff);
                url = NET_MakeAbsoluteURL(top_state->base_url, str);
                PA_UNLOCK(buff);
                PA_FREE(buff);
		if (url == NULL) {
                    top_state->out_of_memory = TRUE;
                    return;
		}
            }

            /* 
             * Look for ID attribute. If it's there we have may have
             * an inline signed script.
             */
            buff = lo_FetchParamValue(context, tag, PARAM_ID);
            if (buff != NULL) {
                PA_LOCK(str, char *, buff);
                StrAllocCopy(id, str);
                PA_UNLOCK(buff);
                PA_FREE(buff);
		if (id == NULL) {
                    top_state->out_of_memory = TRUE;
		    XP_FREEIF(url);
                    return;
		}
            }

            /*
             * Now look for a SRC="url" attribute for known languages.
             * If found, synchronously load the url.
             */
	    buff = lo_FetchParamValue(context, tag, PARAM_SRC);  /* XXX overloaded rv */
            if (buff != NULL) {
		XP_Bool allowFileSrc = FALSE;
                char *absUrl;

                PA_LOCK(str, char *, buff);

		PREF_GetBoolPref(lo_jsAllowFileSrcFromNonFile, &allowFileSrc);
                absUrl = NET_MakeAbsoluteURL(top_state->base_url, str);
		if (absUrl == NULL) {
		    top_state->out_of_memory = TRUE;
		    XP_FREEIF(id);
                } else if (allowFileSrc == FALSE &&
		           NET_URL_Type(absUrl) == FILE_TYPE_URL &&
		           NET_URL_Type(top_state->url) != FILE_TYPE_URL) {
		    /*
		     * Deny access from http: to file: via SCRIPT SRC=...
		     * XXX silently
		     */
                    top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                    XP_FREE(absUrl);
                    XP_FREEIF(url);
		    XP_FREEIF(id);
		} else if (url != NULL) {
                    XP_FREE(absUrl);
                    StrAllocCopy(archiveSrc, str);
		    if (archiveSrc == NULL) {
			top_state->out_of_memory = TRUE;
			XP_FREE(url);
			XP_FREEIF(id);
		    }
                } else {
                    url = absUrl;
                }
                PA_UNLOCK(buff);
                PA_FREE(buff);
		if (top_state->out_of_memory)
		    return;

                /*
                 * If we are doing a <script src=""> mocha script but JS
                 *   is turned off just ignore the tag
                 */
		if (!LM_CanDoJS(context)) {
                    top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                    XP_FREE(url);
		    XP_FREEIF(id);
		    XP_FREEIF(archiveSrc);
                    return;
                }
            }
        }

        /*
         * Set text_divert so we know to accumulate text in line_buf
         * without interpretation.
         */
        state->text_divert = tag->type;

        /*
         * XXX need to stack these to handle blocked SCRIPT tags
         */
        top_state->script_lineno = tag->newline_count + 1;

        /* if we got here as a result of a LINK tag
         * check to make sure rel=stylesheet and then
         * check for an HREF and if one does not exist
         * fail
         */
        if (tag->type == P_LINK) {
            char *cbuff = (char*)lo_FetchParamValue(context, tag, PARAM_REL);
                        
            if (cbuff && !strcasecomp(cbuff, "stylesheet")) {
                XP_FREE(cbuff);

                cbuff = (char*)lo_FetchParamValue(context, tag, PARAM_HREF);

                if (cbuff) {
                    if (saw_archive && url) {
                        archiveSrc = XP_STRDUP(cbuff);
                    } else {
		        XP_FREEIF(url);
                        url = NET_MakeAbsoluteURL(top_state->base_url, cbuff);
                    }
		}
            }

            XP_FREEIF(cbuff);
        }

        if (url != NULL || id != NULL || codebase != NULL) {
            if ((doc_data != NULL) &&
                (state->in_relayout == FALSE) &&
                SCRIPT_EXEC_OK(top_state, state, tag->type, P_SCRIPT)) {
                ScriptData *data;

                data = XP_ALLOC(sizeof(ScriptData));
                if (data == NULL) {
                    top_state->out_of_memory = TRUE;
                    return;
                }
                data->context = context;
                data->state = state;
                data->tag = PA_CloneMDLTag(tag);
                if (data->tag == NULL) {
                    top_state->out_of_memory = TRUE;
		    XP_FREE(data);
                    return;
                }
                data->url = url;
                data->archiveSrc = archiveSrc;
                data->id = id;
                if (codebase == NULL) {
                    StrAllocCopy(codebase, top_state->base_url);
                }
                data->codebase = codebase;
                data->buffer = NULL;
                data->bufferSize = 0;
                data->version = top_state->version;

		/*
		 * Only SCRIPT ARCHIVE= ID= without SRC= is an inline signed
		 * script -- if there is a SRC= attribute, archiveSrc will be
		 * non-null.
		 */
                data->inlineSigned = (JSBool)
		    (url != NULL && archiveSrc == NULL && id != NULL);

                /* Reset version accumulator */
                top_state->version = JSVERSION_UNKNOWN;

                XP_ASSERT (tag->type == P_SCRIPT || tag->type == P_STYLE || 
			   tag->type == P_LINK);

	        /* 
		 * Out-of-line included (by src=) or inline signed script.
		 * Save continuatation data on top_state.  If it's signed,
		 * we'll verify the signature once we see </script> and
		 * have the inline script to verify.
		 */
		top_state->scriptData = data;

            } 
	    else {
                XP_FREE(url);
		XP_FREEIF(id);
		XP_FREEIF(archiveSrc);
            }
        }
    } 
    else {

	/*
	 * We are in the </script> tag now...
	 */

        size_t line_buf_len;
        intn script_type;
        char *scope_to=NULL;
        char *untransformed = NULL;

        script_type = top_state->in_script;
        top_state->in_script = SCRIPT_TYPE_NOT;

	/* guard against superfluous end tags */
	if (script_type == SCRIPT_TYPE_NOT)
	    goto end_tag_out;

	/* convert from CSS to JavaScript here */
        if (tag->type != P_LINK && script_type == SCRIPT_TYPE_CSS) {
            char *new_buffer;
            int32 new_buffer_length;

            CSS_ConvertToJS((char *)state->line_buf, 
                            state->line_buf_len,
                            &new_buffer,
                            &new_buffer_length);

            if (!new_buffer) {
                /* css translator error, unblock layout and return */
                state->text_divert = P_UNKNOWN;
                state->line_buf_len = 0; /* clear script text */
                goto end_tag_out;
            }

            untransformed = (char *) state->line_buf;
            state->line_buf = (PA_Block) new_buffer;
            state->line_buf_len = new_buffer_length;
            state->line_buf_size = new_buffer_length;

            if (state->line_buf_len)
                state->line_buf_len--; /* hack: subtract one to remove final \n */

            script_type = SCRIPT_TYPE_JSSS;
        }

        if (tag->type == P_STYLE) {
            /* mocha scoped to document == jsss */
            scope_to = "document";
        }

        /*
         * Reset these before potentially recursing indirectly through
         * the document.write() built-in function, which writes to the
         * very same doc_data->parser_stream that this <SCRIPT> tag
         * came in on.
         */
        state->text_divert = P_UNKNOWN;
        line_buf_len = state->line_buf_len;
        state->line_buf_len = 0;

        if (script_type != SCRIPT_TYPE_UNKNOWN && 
	    script_type != SCRIPT_TYPE_NOT) {
            /*
             * If mocha is disabled or can't be done in this context we
             *   are going to just ignore the buffer contents
             */
            if (!LM_CanDoJS(context)) {
				top_state->in_script = SCRIPT_TYPE_UNKNOWN;
                goto end_tag_out;
            }

            if ((doc_data != NULL) &&
                (state->in_relayout == FALSE) &&
                SCRIPT_EXEC_OK(top_state, state, tag->type, P_SCRIPT)) {

                /*
                 * First off, make sure layout is blocking on us
                 */
                if (lo_create_script_blockage(context, state, 
					tag->type == P_SCRIPT ? LO_SCRIPT : LO_UNKNOWN)) 
				{
                    ScriptData *data;

                    /*
                     * Extreme hackery.  Hideous and shameful.  See the comment
						* in lo_BlockScriptTag before similar is_end/overflow code
						* and commence vomiting.
                     */
                    lo_BlockScriptTag(context, state, NULL);

		    if (tag->is_end == (PRPackedBool)1) {
			  PA_PushOverflow(doc_data);
			  doc_data->overflow_depth ++;
		    }

		    /*
		     * Set the document.write tag insertion point.
		     */
             top_state->input_write_point[top_state->input_write_level] = &top_state->tags;

		    data = top_state->scriptData;
                    top_state->scriptData = NULL;
                    if (data && data->url) {
			/*
			 * Three cases:
			 * 1.  SCRIPT SRC=: url non-null
			 * 2.  SCRIPT ARCHIVE= SRC=: url, archiveSrc non-null
			 * 3.  SCRIPT ARCHIVE= ID=: url, id non-null
			 * In the last case, we copy the inline script into
			 * data's buffer and let lo_script_archive_exit_fn do
			 * the eval.  We use an inlineSigned flag to avoid a
			 * bunch of (url != NULL && archiveSrc == NULL && id
			 * != NULL) tests.
			 */
			if (data->inlineSigned) {
                            StrAllocCopy(data->buffer, (char *) state->line_buf);
                            data->bufferSize = line_buf_len;
			}
			lo_GetScriptFromURL(data, script_type);
                    }
		    else {
                        JSPrincipals *principals = NULL;
			ETEvalStuff * stuff;
			
                        if (data) {
			    principals = LM_NewJSPrincipals(NULL, data->id, 
							    data->codebase);
                            if (untransformed &&
				!LM_SetUntransformedSource(principals, 
                                                           untransformed,
                                                           (char *) state->line_buf))
                            {
                                top_state->out_of_memory = TRUE;
                            }
                            lo_DestroyScriptData(data);
			}

                        /* 
                         * send the buffer off to be evaluated 
			 */
#ifdef DEBUG_ScriptPlugin
			 			if (script_type == SCRIPT_TYPE_PLUGIN)
						{
							XP_ASSERT(mimebuf == NULL);
							npl_ScriptPlugin(context, state, tag, line_buf_len,top_state->mimetype);
						    lo_unblock_script_tag(context, TRUE);
						}
						else
#endif /* DEBUG_ScriptPlugin */
 

			stuff = (ETEvalStuff *) XP_NEW_ZAP(ETEvalStuff);
			if (!stuff)
			    goto end_tag_out;

			stuff->len = line_buf_len;
			stuff->line_no = top_state->script_lineno;
			if (scope_to)
			    stuff->scope_to = XP_STRDUP(scope_to);
			else
			    stuff->scope_to = NULL;
			stuff->want_result = JS_FALSE;
			stuff->data = context;
			stuff->version = top_state->version;
			stuff->principals = principals;

                        ET_EvaluateScript(context, 
                                          (char *) state->line_buf,
					  stuff,
                                          lo_ScriptEvalExitFn);
                    }

                    /* Reset version accumulator */
                    top_state->version = JSVERSION_UNKNOWN;
                }
            }
        }
      end_tag_out:
	/*
	 * If we got a </SCRIPT> and still have scriptData set here, it must
	 *   be left over from an error case above, so we free it.
	 */
	if (top_state->scriptData) {
	    XP_ASSERT(!top_state->layout_blocking_element);
            lo_DestroyScriptData(top_state->scriptData);
	    top_state->scriptData = NULL;
	}
        XP_FREEIF(untransformed);
    }
}
Example #16
0
/* evaluate the buffer encompassed by the style attribute on any tag.
 * this will be JSS or CSS 
 *
 * Returns TRUE if it needs to block layout
 * Returns FALSE if not.
 */
XP_Bool
lo_ProcessStyleAttribute(MWContext *context, lo_DocState *state, PA_Tag *tag, char *script_buff)
{
    lo_TopState *top_state;
    char *scope_to = NULL;
    int32 script_buff_len;
    char *new_id;
    XP_Bool in_double_quote=FALSE, in_single_quote=FALSE;
    char *ptr, *end;
    ETEvalStuff * stuff;

    if (!state)
  	{
       XP_FREEIF(script_buff);
	   return FALSE;
	}


    if (!script_buff)
        return FALSE;

    /* @@@ A bit of a hack.
     * Get rid of the style attribute in the tag->data so that we don't
     * go circular
     *
     * get rid of STYLE by rewriting it as SYTLE so that the parser 
     * ignores it :)
     */
    for (ptr=(char*)tag->data, end = ptr+tag->data_len; ptr < end; ptr++) {
        if (*ptr == '"') {
            in_double_quote = !in_double_quote;
        }
        else if (*ptr == '\'') {
            in_single_quote = !in_single_quote;
        }
        else if (!in_single_quote &&
                 !in_double_quote &&
                 !strncasecomp(ptr, PARAM_STYLE, sizeof(PARAM_STYLE)-1)) {
            *ptr = 'T';    /* ttyle NOT style */
            break;
        }
    }

    script_buff_len = XP_STRLEN(script_buff);

    top_state = state->top_state;

    /* get the tag ID if it has one */
    new_id = (char *)lo_FetchParamValue(context, tag, PARAM_ID);

    if (!new_id)
        new_id = PR_smprintf(NSIMPLICITID"%ld", top_state->tag_count);

    if (!new_id)
        return FALSE;

    if (top_state->default_style_script_type == SCRIPT_TYPE_JSSS ||
	top_state->default_style_script_type == SCRIPT_TYPE_MOCHA) {

    	StrAllocCopy(scope_to, "document.ids.");
    	StrAllocCat(scope_to, new_id);

    	if (!scope_to) {
    	    XP_FREE(new_id);
	    return(FALSE);
	}
    }
    else if (top_state->default_style_script_type == SCRIPT_TYPE_CSS) {
        char *new_jss_buff;
        int32 new_jss_buff_len;
        char *new_css_buff;
        int32 new_css_buff_len;

        /* scope the css to the ns implicit ID */
        new_css_buff = PR_smprintf("#%s { %s }", new_id, script_buff);

        XP_FREE(script_buff);

        if (!new_css_buff) {
	    XP_FREE(new_id);
	    return FALSE;
	}

        new_css_buff_len = XP_STRLEN(new_css_buff);
        
        /* convert to JSS */
        CSS_ConvertToJS(new_css_buff,
                        new_css_buff_len,
                        &new_jss_buff,
                        &new_jss_buff_len);

        XP_FREE(new_css_buff);

        if (!new_jss_buff) {
	    XP_FREE(new_id);
	    return FALSE;
	}

        script_buff = new_jss_buff;
        script_buff_len = new_jss_buff_len;
    }
    else {
        /* unknown script type, punt */
        XP_FREE(script_buff);
	XP_FREE(new_id);
        return FALSE;
    }

    /* not needed anymore */
    XP_FREE(new_id);

    stuff = (ETEvalStuff *) XP_NEW_ZAP(ETEvalStuff);
    if (!stuff) {
	/* what do we free here? */
	XP_FREE(new_id);
        return FALSE;
    }

    if (lo_CloneTagAndBlockLayout(context, state, tag)) {
        tag->type = P_UNKNOWN;
	stuff->len = XP_STRLEN(script_buff);
	stuff->line_no = top_state->script_lineno;
	stuff->scope_to = scope_to;
	stuff->want_result = JS_FALSE;
	stuff->data = context;
	stuff->version = top_state->version;
	stuff->principals = NULL;

        ET_EvaluateScript(context, script_buff, stuff, lo_StyleEvalExitFn);

	/* don't free scope_to, ET_EvaluateScript has taken possession */
        XP_FREE(script_buff);

        return TRUE;
    }

    XP_FREEIF(scope_to);
    XP_FREE(script_buff);
    
    return FALSE;
}
Example #17
0
PRIVATE void
net_ParseHTMLHelpLoadHelpDoc(HTMLHelpParseObj *obj, MWContext *context)
{
	URL_Struct *URL_s;
	char *frame_address = NULL;
	char *content_address = NULL;
	MWContext *new_context;
	frame_set_struct *fgs;

	if(obj->id_value || obj->default_id_value)
		content_address = NET_MakeAbsoluteURL(obj->url_to_map_file, 
											  obj->id_value ? 
												obj->id_value : 
												obj->default_id_value);

	if(!content_address)
	  {
		FE_Alert(context, XP_GetString(MK_CANT_LOAD_HELP_TOPIC));
		return;
	  }

	fgs = XP_ListPeekTopObject(obj->frame_group_stack);

	if(fgs)
	  {
		if(fgs->address)
		  {
			frame_address = NET_MakeAbsoluteURL(obj->url_to_map_file, 
												fgs->address);
		  }
	  }

	if(frame_address)
		URL_s = NET_CreateURLStruct(frame_address, NET_DONT_RELOAD);
	else
		URL_s = NET_CreateURLStruct(content_address, NET_DONT_RELOAD);

	if(!URL_s)
		goto cleanup;

	URL_s->window_chrome = XP_NEW(Chrome);	

	if(!URL_s->window_chrome)
		goto cleanup;

	XP_MEMSET(URL_s->window_chrome, 0, sizeof(Chrome));

	if(obj->window_name)
		URL_s->window_target = XP_STRDUP(obj->window_name);
	else
		URL_s->window_target = XP_STRDUP(DEFAULT_HELP_WINDOW_NAME);

	net_help_init_chrome(URL_s->window_chrome, 
						 obj->window_width, 
						 obj->window_height);

	/* We want to revert the character set of the help frame from the standard
	   character set, not whatever happened to be the last viewed source */

	StrAllocCopy(URL_s->charset, INTL_ResourceCharSet());
	
	new_context = XP_FindNamedContextInList(NULL, URL_s->window_target);

	if(frame_address)
	  {
		URL_Struct *content_URL_s;

		/* if there is a frame_address then we load the
		 * frame first and then load the contents
		 * in the frame exit function.
		 */
		content_URL_s = NET_CreateURLStruct(content_address, NET_DONT_RELOAD);

		if(obj->content_target)
			content_URL_s->window_target = XP_STRDUP(obj->content_target);
		else if(fgs->target)
			content_URL_s->window_target = XP_STRDUP(fgs->target);

		/* doesn't work: URL_s->fe_data = (void *) content_URL_s; */

		/* hack for older versions, see pre_exit_routine_above */
		if (obj->helpVersion < 2) {
			frame_content_for_pre_exit_routine = content_URL_s;
		} else {
			frame_content_for_pre_exit_routine = NULL;
			NET_FreeURLStruct(content_URL_s);
		}

		URL_s->pre_exit_fn = net_HelpPreExitRoutine;
	  }

	if(!new_context)
	  {
	  
		/* this will cause the load too */
		new_context = FE_MakeNewWindow(context, 
						 URL_s, 
						 (obj->window_name) ? obj->window_name :  DEFAULT_HELP_WINDOW_NAME, 
						 URL_s->window_chrome);

		if (HELP_INFO_PTR(*new_context) == NULL) {
			new_context->pHelpInfo = XP_NEW_ZAP(HelpInfoStruct);
		}
		
		if (HELP_INFO_PTR(*new_context)->topicURL != NULL) {
			XP_FREE(HELP_INFO_PTR(*new_context)->topicURL);
			HELP_INFO_PTR(*new_context)->topicURL = NULL;
		}
		
		StrAllocCopy(HELP_INFO_PTR(*new_context)->topicURL, content_address);

	  }
	else
	  {
	
		if (HELP_INFO_PTR(*new_context) == NULL) {
			new_context->pHelpInfo = XP_NEW_ZAP(HelpInfoStruct);
		}
		
		if (HELP_INFO_PTR(*new_context)->topicURL != NULL) {
			XP_FREE(HELP_INFO_PTR(*new_context)->topicURL);
			HELP_INFO_PTR(*new_context)->topicURL = NULL;
		}
		
		StrAllocCopy(HELP_INFO_PTR(*new_context)->topicURL, content_address);

		FE_RaiseWindow(new_context);

		/* Compatibility with earlier versions of NetHelp */
		if (obj->helpVersion < 2) {
			FE_GetURL(new_context, URL_s);
		} else {
			LM_SendOnHelp(new_context);
		}
	  }

cleanup:
	FREEIF(frame_address);
	FREE(content_address);

	return;
}
Example #18
0
//
// If the user has hit return load the url
// Otherwise pass the key on to the base library
//
void CNetscapeEdit::OnChar(UINT nChar, UINT nCnt, UINT nFlags)
{
    BOOL bJsWantsEvent = m_Form->event_handler_present ||
	LM_EventCaptureCheck(m_Context, EVENT_KEYDOWN | EVENT_KEYUP | EVENT_KEYPRESS);

    // Check if we generated this event.  If so, the base.  If not, call JS
    if (m_callBase || !bJsWantsEvent) {

	if(nChar == '\r') {	   // the user hit return

#ifdef DEBUG
        if(!m_bOnCreateCalled) {
            TRACE("Bug 88020 still present\n");
#if defined (DEBUG_blythe) || defined(DEBUG_ftang) || defined(DEBUG_bstell) || defined(DEBUG_nhotta) || defined(DEBUG_jliu)
            ASSERT(0);
#endif
        }
#endif

	    if(m_Submit) { // if we are the only element, return == submit

		// if the text is different throw out the old text and add the
		//   new text into the layout structure
		UpdateAndCheckForChange();

		// we are about to submit so tell libmocha about it first
		//   do the submit in our closure if libmocha says its OK
		JSEvent *event;
		event = XP_NEW_ZAP(JSEvent);
		event->type = EVENT_SUBMIT;
		event->layer_id = m_Form->layer_id;

		ET_SendEvent(m_Context, (LO_Element *)m_Form, event, 
			     edit_submit_closure, this);

		return;
	    } 
	    else {

		// we aren't auto-submitting, but the user still hit return
		//   they prolly mean that we should check to see if we should
		//   send a change event
		if(!(GetStyle() & ES_MULTILINE))
		    UpdateAndCheckForChange();

	    }

        } // wasn't the return key
	
//#ifdef  NO_TAB_NAVIGATION 
/*
	// let the CGenericView to handle the Tab, to step through Form elements
	// and links, even links inside a form.
	if(nChar == VK_TAB) {
        // if the high order bit is set (i.e. its negative) the shift 
        //   key is being held down
        BOOL bShift = GetKeyState(VK_SHIFT) < 0 ? TRUE : FALSE;

        //  Determine our form element.
        if(m_Context)   {
            CFormElement *pMe = CFormElement::GetFormElement(ABSTRACTCX(m_Context), m_Form);
            if(pMe) {
                //  We're handling tabbing between form elements.
                pMe->Tab(bShift);
                return;
            }
        }
	}                                              
	CEdit::OnChar(nChar, nCnt, nFlags);
*/
//#endif	/* NO_TAB_NAVIGATION */

	CEdit::OnChar(nChar, nCnt, nFlags);
	//If m_callBase is set, this event is a callback from a JS event and
	//we have to update the value of the edit field to reflect new values.
	if (bJsWantsEvent) {
	    UpdateEditField();
	}
	return;
    }

    // Give the event to JS.  They'll call the base when they get back.
    //
    // Grab key events for this layer's parent.
    CL_GrabKeyEvents(m_Context->compositor, CL_GetLayerParent(m_Form->layer));

    /* 
     * If there's a compositor and someone has keyboard focus.
     * Note that if noone has event focus, we don't really need
     * to dispatch the event.
     */
    if (m_Context->compositor && 
        !CL_IsKeyEventGrabber(m_Context->compositor, NULL)) {
        CL_Event event;
        fe_EventStruct fe_event;

	fe_event.fe_modifiers = nCnt;	    
	fe_event.nChar = nChar;	    
	fe_event.uFlags = nFlags;
	fe_event.x = 1;

        event.type = CL_EVENT_KEY_DOWN;
        event.which = nChar;
	event.fe_event = (void *)&fe_event;
	event.fe_event_size = sizeof(fe_EventStruct);
        event.modifiers = (GetKeyState(VK_SHIFT) < 0 ? EVENT_SHIFT_MASK : 0) 
			| (GetKeyState(VK_CONTROL) < 0 ? EVENT_CONTROL_MASK : 0) 
			| (GetKeyState(VK_MENU) < 0 ? EVENT_ALT_MASK : 0); 
        event.x = CL_GetLayerXOrigin(m_Form->layer);
        event.y = CL_GetLayerYOrigin(m_Form->layer);
	event.data = nFlags>>14 & 1;//Bit represeting key repetition

        CL_DispatchEvent(m_Context->compositor, &event);
    }
Example #19
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;
}