Пример #1
0
PUBLIC NET_StreamClass * 
NET_ProxyConverter(int         format_out,
                   void       *data_obj,
                   URL_Struct *URL_s,
                   MWContext  *window_id)
{
    NET_StreamClass* stream;
    ProxyObj * obj;
    
    TRACEMSG(("Setting up display stream. Have URL: %s \n%s\n", 
									URL_s->address, URL_s->content_type));

    stream = XP_NEW(NET_StreamClass);
    if(stream == NULL) 
        return(NULL);

	obj = XP_NEW(ProxyObj);
    if(obj == NULL) 
	  {
		FREE(stream);
        return(NULL);
	  }

	XP_MEMSET(obj, 0, sizeof(ProxyObj));

	stream->data_object = obj;
	

    stream->name           = "ProxyWriter";
    stream->complete       = (MKStreamCompleteFunc) net_proxy_complete;
    stream->abort          = (MKStreamAbortFunc) net_proxy_abort;
    stream->put_block      = (MKStreamWriteFunc) net_proxy_write;
    stream->is_write_ready = (MKStreamWriteReadyFunc) net_proxy_WriteReady;
    stream->window_id      = window_id;

    TRACEMSG(("Returning stream from display_converter\n"));

    /* send HTTP headers if not already getting an HTTP doc 
	 */
    if(strncasecomp(URL_s->address,"http:",5))
      {
		obj->definately_send_headers = TRUE;
      }
	StrAllocCopy(obj->content_type, URL_s->content_type);
	StrAllocCopy(obj->content_encoding, URL_s->content_encoding);

    return stream;
}
Пример #2
0
PUBLIC NET_StreamClass *
NET_HTMLHelpMapToURL(int         format_out,
                     void       *data_object,
                     URL_Struct *URL_s,
                     MWContext  *window_id)
{
    html_help_map_stream* obj;
    NET_StreamClass* stream;

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

    stream = XP_NEW(NET_StreamClass);
    if(stream == NULL)
        return(NULL);

    obj = XP_NEW(html_help_map_stream);
    if (obj == NULL)
      {
        FREE(stream);
        return(NULL);
      }

    XP_MEMSET(obj, 0, sizeof(html_help_map_stream));

	if(URL_s->cache_file || URL_s->memory_copy)
		obj->file_is_local = TRUE;
	else
		obj->file_is_local = NET_IsLocalFileURL(URL_s->address);
	
    obj->parse_obj = net_ParseHTMLHelpInit(URL_s->address, URL_s->fe_data);

    if(!obj->parse_obj)
      {
        FREE(stream);
        FREE(obj);
      }

    obj->context = window_id;
    stream->name           = "HTML Help Map File converter";
    stream->complete       = (MKStreamCompleteFunc) net_HMFConvComplete;
    stream->abort          = (MKStreamAbortFunc) net_HMFConvAbort;
    stream->put_block      = (MKStreamWriteFunc) net_HMFConvPut;
    stream->is_write_ready = (MKStreamWriteReadyFunc) net_HMFConvWriteReady;
    stream->data_object    = obj;  /* document info object */
    stream->window_id      = window_id;

    return(stream);
}
Пример #3
0
/*************************************
 * Function: pa_CloneMDLTag
 *
 * Description: This function allocates and fills in an entire
 * 		PA_Tag structure for any MDL tag element type.
 *
 * Params: The tag to clone
 *
 * Returns: A pointer to a completely filled in PA_Tag structure
 *      that is a clone of the tag passed in.  On failure it 
 *      returns NULL.
 *************************************/
PA_Tag *
PA_CloneMDLTag(PA_Tag * src)
{
	PA_Tag *tag;
	PA_Block buff;
	char *locked_buff, *src_buff;

	/*
	 * Allocate a new tag structure, return NULL
	 * if you can't.
	 */
	tag = XP_NEW(PA_Tag);
	if (tag == NULL)
	{
		return(NULL);
	}
	tag->type = src->type;
	tag->is_end = src->is_end;
	tag->newline_count = src->newline_count;
	tag->data_len = src->data_len;
	tag->true_len = src->true_len;
	tag->lo_data = NULL;
	tag->next = NULL;

	/* sure wish we could just do a strdup() here */
	buff = PA_ALLOC((tag->data_len + 1) * sizeof(char));
	if (buff != NULL)
	{
		PA_LOCK(locked_buff, char *, buff);
		PA_LOCK(src_buff, char *, src->data);
		XP_BCOPY(src_buff, locked_buff, tag->data_len);
		locked_buff[tag->data_len] = '\0';
		PA_UNLOCK(locked_buff);
		PA_UNLOCK(src_buff);
	}
Пример #4
0
/*	Constructs a URL_Struct from the the specified URL to the prefetch_list based
	on the value of the pre subtag. 
*/
PUBLIC void
PRE_AddToList(MWContext* context, char* url, double value) 
{
	/* Construct a new URL_Struct with this url, and Prefetch priority */
	URL_Struct* urls;
	PrefetchURLStruct *pus = XP_NEW(PrefetchURLStruct); 

	if (!pre_enabled || !value || !pus || !pre_OKToPrefetch(url))
		return;

	urls = NET_CreateURLStruct(url, NET_DONT_RELOAD);
	if (!urls)
		return;
	
	urls->priority = Prefetch_priority;
	urls->load_background = TRUE;
					
	if (prefetch_list == NULL)
	{
		prefetch_list = XP_ListNew();
	}
	
	pus->prevalue = value;
	pus->URL_s = urls;

	XP_ListAddObjectToEnd(prefetch_list, pus);
}
Пример #5
0
PRIVATE HTMLHelpParseObj *
net_ParseHTMLHelpInit(char *url_to_map_file, char *id)
{
	HTMLHelpParseObj *rv = XP_NEW(HTMLHelpParseObj);

	if(!rv)
		return(NULL);

	XP_ASSERT(url_to_map_file && id);

	if(!url_to_map_file || !id)
		return(NULL);

	XP_MEMSET(rv, 0, sizeof(HTMLHelpParseObj));

	rv->url_to_map_file = XP_STRDUP(url_to_map_file);
	rv->id              = XP_STRDUP(id);
	rv->helpVersion     = 1;

	rv->window_height = DEFAULT_HELP_WINDOW_HEIGHT;
	rv->window_width  = DEFAULT_HELP_WINDOW_WIDTH;

	rv->frame_group_stack = XP_ListNew();

	return(rv);
}
Пример #6
0
/*
 * The beginning of a usemap MAP record.
 * Allocate the structure and initialize it.  It will be filled
 * by later AREA tags.
 */
void
lo_BeginMap(MWContext *context, lo_DocState *state, PA_Tag *tag)
{
	PA_Block buff;
	char *str;
	lo_MapRec *map;

	map = XP_NEW(lo_MapRec);
	if (map == NULL)
	{
		state->top_state->out_of_memory = TRUE;
		return;
	}

	map->name = NULL;
	map->areas = NULL;
	map->areas_last = NULL;
	map->next = NULL;

	buff = lo_FetchParamValue(context, tag, PARAM_NAME);
	if (buff != NULL)
	{
		char *name;

		PA_LOCK(str, char *, buff);
		if (str != NULL)
		{
			int32 len;

			len = lo_StripTextWhitespace(str, XP_STRLEN(str));
		}
		name = (char *)XP_ALLOC(XP_STRLEN(str) + 1);
		if (name == NULL)
		{
			map->name = NULL;
		}
		else
		{
			XP_STRCPY(name, str);
			map->name = name;
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}
	else
	{
		map->name = NULL;
	}

	if (map->name == NULL)
	{
		XP_DELETE(map);
		return;
	}

	state->top_state->current_map = map;
}
Пример #7
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);
}
Пример #8
0
lo_ListStack *
lo_DefaultList(lo_DocState *state)
{
	lo_ListStack *lptr;

	lptr = XP_NEW(lo_ListStack);
	if (lptr == NULL)
	{
		return(NULL);
	}

	lptr->type = P_UNKNOWN;
	lptr->level = 0;
	lptr->value = 1;
	lptr->compact = FALSE;
	lptr->bullet_type = BULLET_BASIC;
	lptr->quote_type = QUOTE_NONE;
	lptr->old_left_margin = state->win_left;
	lptr->old_right_margin = state->win_width - state->win_right;
	lptr->next = NULL;

	return(lptr);
}
Пример #9
0
/* mquote means quoted mail message */
void
lo_PushList(lo_DocState *state, PA_Tag *tag, int8 quote_type)
{
	lo_ListStack *lptr;
	intn bullet_type;
	int32 val;
	Bool no_level;
    int32 mquote_line_num = 0;
    int32 mquote_x = 0;

	val = 1;
	no_level = FALSE;
	switch (tag->type)
	{
		/*
		 * Blockquotes and multicolumns pretend to be the current
		 * list type, unless the current list is nothing.
		 * Now we have DIV tags that can act like MULTICOL tags.
		 */
		case P_MULTICOLUMN:
		case P_DIVISION:
		case P_BLOCKQUOTE:
			bullet_type = state->list_stack->bullet_type;
			no_level = TRUE;
			if (state->list_stack->type != P_UNKNOWN)
			{
				tag->type = state->list_stack->type;
			}
			val = state->list_stack->value;
			break;
		case P_NUM_LIST:
			bullet_type = BULLET_NUM;
			break;
		case P_UNUM_LIST:
		case P_MENU:
		case P_DIRECTORY:
			bullet_type = BULLET_BASIC;
			break;
		default:
			bullet_type = BULLET_NONE;
			break;
	}

    /* Support for mail compose quoting. */
    if (quote_type != QUOTE_NONE) 
    {
        mquote_line_num = state->line_num;
        mquote_x = state->left_margin;
    }

	lptr = XP_NEW(lo_ListStack);
	if (lptr == NULL)
	{
		state->top_state->out_of_memory = TRUE;
		return;
	}

	lptr->type = tag->type;
	if (no_level != FALSE)
	{
		lptr->level = state->list_stack->level;
	}
	else
	{
		lptr->level = state->list_stack->level + 1;
	}
	lptr->compact = FALSE;
	lptr->value = val;
	lptr->bullet_type = bullet_type;
	lptr->old_left_margin = state->left_margin;
	lptr->old_right_margin = state->right_margin;
    lptr->quote_type = quote_type;
    lptr->mquote_line_num = mquote_line_num;
    lptr->mquote_x = mquote_x;

	lptr->next = state->list_stack;
	state->list_stack = lptr;
}
Пример #10
0
/*
 * This is an AREA tag.  Create the structure, fill it in based on the
 * attributes passed, and add it to the map record for the current
 * MAP tag.
 */
void
lo_BeginMapArea(MWContext *context, lo_DocState *state, PA_Tag *tag)
{
	PA_Block buff;
	char *str;
	lo_MapRec *map;
	lo_MapAreaRec *area;
        lo_DocLists *doc_lists;
        
        doc_lists = lo_GetCurrentDocLists(state);

	/*
	 * Get the current map, if there is none, error out.
	 */
	map = state->top_state->current_map;
	if (map == NULL)
	{
		return;
	}

	area = XP_NEW(lo_MapAreaRec);
	if (area == NULL)
	{
		state->top_state->out_of_memory = TRUE;
		return;
	}

	area->type = AREA_SHAPE_RECT;
	area->coords = NULL;
	area->coord_cnt = 0;
	area->anchor = NULL;
	area->alt = NULL;
	area->alt_len = 0;
	area->next = NULL;

	buff = lo_FetchParamValue(context, tag, PARAM_SHAPE);
	if (buff != NULL)
	{
		PA_LOCK(str, char *, buff);
		if (pa_TagEqual(S_AREA_SHAPE_RECT, str))
		{
			area->type = AREA_SHAPE_RECT;
		}
		else if (pa_TagEqual(S_AREA_SHAPE_CIRCLE, str))
		{
			area->type = AREA_SHAPE_CIRCLE;
		}
		else if (pa_TagEqual(S_AREA_SHAPE_POLY, str))
		{
			area->type = AREA_SHAPE_POLY;
		}
		else if (pa_TagEqual(S_AREA_SHAPE_POLYGON, str))
		{
			area->type = AREA_SHAPE_POLY;
		}
		else if (pa_TagEqual(S_AREA_SHAPE_DEFAULT, str))
		{
			area->type = AREA_SHAPE_DEFAULT;
		}
		else
		{
			area->type = AREA_SHAPE_UNKNOWN;
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}

	/*
	 * Get the alt parameter, and store the resulting
	 * text, and its length.
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_ALT);
	if (buff != NULL)
	{
		PA_LOCK(str, char *, buff);
		area->alt_len = XP_STRLEN(str);
		area->alt_len = (int16)lo_StripTextNewlines(str,
						(int32)area->alt_len);
		PA_UNLOCK(buff);
	}
	area->alt = buff;

	/*
	 * Parse the comma separated coordinate list into an
	 * array of integers.
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_COORDS);
	if (buff != NULL)
	{
		int32 cnt;
		Bool must_be_odd;

		must_be_odd = FALSE;
		if (area->type == AREA_SHAPE_POLY)
		{
			must_be_odd = TRUE;
		}
		PA_LOCK(str, char *, buff);
		area->coords = lo_parse_coord_list(str, &cnt, must_be_odd);
		if (area->coords != NULL)
		{
			area->coord_cnt = cnt;
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}

	/*
	 * Get the HREF, and if one exists, get the TARGET to go along
	 * with it.
	 */
	buff = lo_FetchParamValue(context, tag, PARAM_HREF);
	if (buff != NULL)
	{
		char *target;
		PA_Block targ_buff;
		PA_Block href_buff;
		LO_AnchorData *anchor;

		anchor = NULL;
		PA_LOCK(str, char *, buff);
		if (str != NULL)
		{
			int32 len;

			len = lo_StripTextWhitespace(str, XP_STRLEN(str));
		}
		str = NET_MakeAbsoluteURL(state->top_state->base_url, str);
		if (str == NULL)
		{
			href_buff = NULL;
		}
		else
		{
			href_buff = PA_ALLOC(XP_STRLEN(str) + 1);
			if (href_buff != NULL)
			{
				char *full_url;

				PA_LOCK(full_url, char *, href_buff);
				XP_STRCPY(full_url, str);
				PA_UNLOCK(href_buff);
			}
			else
			{
				state->top_state->out_of_memory = TRUE;
			}
			XP_FREE(str);
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);

		if (href_buff != NULL)
		{
			targ_buff = lo_FetchParamValue(context, tag, PARAM_TARGET);
			if (targ_buff != NULL)
			{
				int32 len;

				PA_LOCK(target, char *, targ_buff);
				len = lo_StripTextWhitespace(target,
						XP_STRLEN(target));
				if ((*target == '\0')||
				    (lo_IsValidTarget(target) == FALSE))
				{
					PA_UNLOCK(targ_buff);
					PA_FREE(targ_buff);
					targ_buff = NULL;
				}
				else
				{
					PA_UNLOCK(targ_buff);
				}
			}

			/*
			 * If there was no target use the default one.
			 * (default provided by BASE tag)
			 */
			if ((targ_buff == NULL)&&
			    (state->top_state->base_target != NULL))
			{
				targ_buff = PA_ALLOC(XP_STRLEN(
					state->top_state->base_target) + 1);
				if (targ_buff != NULL)
				{
					char *targ;

					PA_LOCK(targ, char *, targ_buff);
					XP_STRCPY(targ,
						state->top_state->base_target);
					PA_UNLOCK(targ_buff);
				}
				else
				{
					state->top_state->out_of_memory = TRUE;
				}
			}

			anchor = lo_NewAnchor(state, href_buff, targ_buff);
			if (anchor == NULL)
			{
				PA_FREE(href_buff);
				if (targ_buff != NULL)
				{
					PA_FREE(targ_buff);
				}
			}
			/*
			 * If the AREA tag has an ALT attribute,
			 * stick that text into the anchor data.
			 */
			else if (area->alt != NULL)
			{
				PA_Block alt_buff;
				char *alt_text;

				PA_LOCK(alt_text, char *, area->alt);
				alt_buff = PA_ALLOC(area->alt_len + 1);
				if (alt_buff != NULL)
				{
					char *new_alt;

					PA_LOCK(new_alt, char *, alt_buff);
					XP_STRCPY(new_alt, alt_text);
					PA_UNLOCK(alt_buff);
				}
				PA_UNLOCK(area->alt);
				anchor->alt = alt_buff;
			}
Пример #11
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);
			}
Пример #12
0
PUBLIC NET_StreamClass *
CRAWL_CrawlerConverter(int format_out,
						void *data_object,
						URL_Struct *URL_s,
						MWContext  *window_id)
{
#if defined(XP_MAC)
#pragma unused(format_out, data_object)
#endif
	NET_StreamClass *stream = NULL;

	crawl_page_scan_stream *obj;

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

	XP_TRACE(("CRAWL_CrawlerConverter: %d %s", URL_s->server_status, URL_s->address));

	if (URL_s->SARCache != NULL) {
		/* if the content length would exceed the cache limit, don't convert this */
		if (((uint32)URL_s->content_length >= (URL_s->SARCache->MaxSize - URL_s->SARCache->DiskCacheSize)) &&
			((uint32)URL_s->content_length < BOGUS_CONTENT_LENGTH)) {
			CRAWL_PageInfo page = URL_s->owner_data;
			XP_TRACE(("not converting %s", URL_s->address));
			if ((page->scan_complete_func != NULL) && (page->page_owner != NULL)) {
				page->scan_complete_func(page->page_owner, page);
				return(NULL);
			}
		}
	}

	stream = XP_NEW(NET_StreamClass);
	if(stream == NULL)
		return(NULL);

	obj = XP_NEW(crawl_page_scan_stream);
	if (obj == NULL)
	  {
		XP_FREE(stream);
		return(NULL);
	  }
	obj->parse_obj = CRAWL_MakeParseObj();			/* this object used to parse the page and destroyed 
												in completion or abort function */
	if (obj->parse_obj == NULL) return(NULL);
	obj->page = URL_s->owner_data;				/* this data was set in crawl_makePage */
	obj->page->lastModified = URL_s->last_modified;
	/* if there was a server error, read but don't parse the document */
	if ((URL_s->server_status >= 400) ||
		/* don't attempt to parse non-html */
		((XP_STRSTR(URL_s->content_type, TEXT_HTML) == NULL) &&
		 (XP_STRSTR(URL_s->content_type, INTERNAL_PARSER) == NULL))) {
		/* URL_s->dont_cache = PR_FALSE; */
		obj->page->dontFollow = PR_TRUE;
	}

	stream->name           = "Crawler Converter";
	stream->complete       = (MKStreamCompleteFunc) crawl_PageScanConvComplete;
	stream->abort          = (MKStreamAbortFunc) crawl_PageScanConvAbort;
	stream->put_block      = (MKStreamWriteFunc) crawl_PageScanConvPut;
	stream->is_write_ready = (MKStreamWriteReadyFunc) crawl_PageScanConvWriteReady;
	stream->data_object    = obj;  /* document info object */
	stream->window_id      = window_id;
	return(stream);
}
Пример #13
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;
}
Пример #14
0
/* parse lines in an HTML help mapping file.
 * get window_size and name, etc...
 *
 * when the id is found function returns HTML_HELP_ID_FOUND
 * on error function returns negative error code.
 */
PRIVATE int
net_ParseHTMLHelpLine(HTMLHelpParseObj *obj, char *line_data)
{
	char *line = XP_StripLine(line_data);
	char *token;
	char *next_word;

	if(*line == '<')
	  {
		/* find and terminate the end '>' */
		XP_STRTOK(line, ">");

		token = XP_StripLine(line+1);

		if(!strncasecomp(token, 
						 ID_MAP_TOKEN, 
						 sizeof(ID_MAP_TOKEN)-1))
		  {
			obj->in_id_mapping = TRUE;
		  }
		else if(!strncasecomp(token, 
						 END_ID_MAP_TOKEN, 
						 sizeof(END_ID_MAP_TOKEN)-1))
		  {
			obj->in_id_mapping = FALSE;
		  }
		else if(!strncasecomp(token, 
						 FRAME_GROUP_TOKEN, 
						 sizeof(FRAME_GROUP_TOKEN)-1))
		  {
			char *cp = token + sizeof(FRAME_GROUP_TOKEN)-1;
			frame_set_struct * fgs = XP_NEW(frame_set_struct);

			while(isspace(*cp)) cp++;

			if(fgs)
			  {
				XP_MEMSET(fgs, 0, sizeof(frame_set_struct));

				next_word=NULL; /* init */

				do {
					if(!strncasecomp(cp, SRC_TOKEN, sizeof(SRC_TOKEN)-1))
				  	  {
						char *address = net_get_html_help_token(
														cp+sizeof(SRC_TOKEN)-1,
														&next_word);
						cp = next_word;
						fgs->address = XP_STRDUP(address);
				  	  }
					else if(!strncasecomp(cp, 
									  WINDOW_TOKEN, 
									  sizeof(WINDOW_TOKEN)-1))
				      {
					    char *window = net_get_html_help_token(
													cp+sizeof(WINDOW_TOKEN)-1, 
													&next_word);
					    cp = next_word;
					    fgs->target = XP_STRDUP(window);
				      }
					else
					  {
						/* unknown attribute.  Skip to next whitespace
						 */ 
						while(*cp && !isspace(*cp)) 
							cp++;


						if(*cp)
						  {
							while(isspace(*cp)) cp++;
							next_word = cp;
						  }
						else
						  {
							next_word = NULL;
						  }
					  }

				  } while(next_word);
			
				XP_ListAddObject(obj->frame_group_stack, fgs);
			  }
		  }
		else if(!strncasecomp(token, 
						 END_FRAME_GROUP_TOKEN, 
						 sizeof(END_FRAME_GROUP_TOKEN)-1))
		  {
			frame_set_struct *fgs;

			fgs = XP_ListRemoveTopObject(obj->frame_group_stack);

			if(fgs)
				net_help_free_frame_group_struct(fgs);
		  }
	  }
	else if(!obj->in_id_mapping)
	  {
		if(!strncasecomp(line, 
					 	WINDOW_SIZE_TOKEN, 
					 	sizeof(WINDOW_SIZE_TOKEN)-1))
		  {
			/* get window size */
			char *comma=0;
			char *window_size = net_get_html_help_token(line+
												sizeof(WINDOW_SIZE_TOKEN)-1, 
												NULL);

			if(window_size)
				comma = XP_STRCHR(window_size, ',');

			if(comma)
			  {
				*comma =  '\0';
				obj->window_width = XP_ATOI(window_size);
				obj->window_height = XP_ATOI(comma+1);
			  }
		  }
		else if(!strncasecomp(line, 
						 	WINDOW_NAME_TOKEN, 
						 	sizeof(WINDOW_NAME_TOKEN)-1))
		  {
			char *window_name = net_get_html_help_token(line+
												sizeof(WINDOW_NAME_TOKEN)-1,
												NULL);

			if(window_name)
			  {
				FREEIF(obj->window_name);
				obj->window_name = XP_STRDUP(window_name);
			  }
		  }
		else if(!strncasecomp(line, 
					 	HELP_VERSION_TOKEN, 
					 	sizeof(HELP_VERSION_TOKEN)-1))
		  {
			/* get window size */
			char *help_version = net_get_html_help_token(line+
												sizeof(HELP_VERSION_TOKEN)-1, 
												NULL);

			if(help_version)
			  {
				obj->helpVersion = XP_ATOI(help_version);
			  }
		  }
	  }
	else
	  {
		/* id mapping pair */
		if(!strncasecomp(line, obj->id, XP_STRLEN(obj->id)))
		  {
			char *id_value = net_get_html_help_token(line+XP_STRLEN(obj->id),
													 &next_word);

			if(id_value)
			  {
			  	obj->id_value = XP_STRDUP(id_value);

				while(next_word)
				  {
					char *cp = next_word;

                    if(!strncasecomp(cp,
                                     TARGET_TOKEN,
                                      sizeof(TARGET_TOKEN)-1))
                      {
                        char *target = net_get_html_help_token(
                                                    cp+sizeof(TARGET_TOKEN)-1,
                                                    &next_word);
                        cp = next_word;
                        obj->content_target = XP_STRDUP(target);
                      }
					else
					  {
                        /* unknown attribute.  Skip to next whitespace
                         */
                        while(*cp && !isspace(*cp))
                            cp++;

                        if(*cp)
                          {
                            while(isspace(*cp)) cp++;
                            next_word = cp;
                          }
                        else
                          {
                            next_word = NULL;
                          }
					  }
				  }
			  }
		
			return(HTML_HELP_ID_FOUND);
		  }
		if(!strncasecomp(line, DEFAULT_HELP_ID, sizeof(DEFAULT_HELP_ID)-1))
		  {
			char *default_id_value = net_get_html_help_token(
												line+sizeof(DEFAULT_HELP_ID)-1,
												NULL);

            if(default_id_value)
                obj->default_id_value = XP_STRDUP(default_id_value);
		  }
		
	  }

	return(0);
}
Пример #15
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;
}
Пример #16
0
void
lo_BeginMulticolumn(MWContext *context, lo_DocState *state, PA_Tag *tag, LO_MulticolumnStruct *multicolEle)
{
	lo_MultiCol *multicol;
	PA_Block buff;
	char *str;
	int32 val;
	int32 doc_width;
	/* int32 width; */

	multicol = XP_NEW(lo_MultiCol);
	if (multicol == NULL)
	{
		state->top_state->out_of_memory = TRUE;
		return;
	}

	multicol->width = 0;
	multicol->isPercentWidth = FALSE;	

	/* Put a pointer to lo_multicol inside the MULTICOLUMN layout element that will be placed on the
	   line list */
	multicolEle->multicol = multicol;
    
	/*
     * If this multicol is within a layer, then we have to create an
     * artificial TABLE around it (since the multicol code depends on
     * the state's line array, which isn't in an updated state within
     * a layer). 
     */
    if (state->layer_nest_level > 0)
    {
        PA_Tag *tmp_tag;
        lo_TableRec *table;

        if (state->in_paragraph != FALSE)
        {
            lo_CloseParagraph(context, &state, tag, 2);
        }

        lo_BeginTableAttributes(context, state, NULL, NULL, NULL, NULL,
                                NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                                NULL, NULL, NULL, NULL, NULL, NULL, NULL,
                                NULL, NULL, NULL);
        
        table = state->current_table;
        if (table) {
            lo_BeginTableRowAttributes(context, state, table,
                                       NULL, NULL, NULL, NULL);

            lo_BeginTableCellAttributes(context, state, table,
                                        NULL, NULL, NULL, NULL, NULL,
                                        LO_TILE_BOTH, NULL, NULL, NULL, NULL,
                                        FALSE, TRUE);

            /* 
             * If we've successfully created a subdoc, we need to clone
             * the MULTICOL tag and save it in the subdoc, since the code
             * above us doesn't realize we're now in a table.
             */
            if (state->sub_state) {
                state = state->sub_state;
                tmp_tag = PA_CloneMDLTag(tag);
                lo_SaveSubdocTags(context, state, tmp_tag);
            }
            multicol->close_table = TRUE;
        }
    }
    else {		
		/* if (line will not be flushed by lo_SetSoftLineBreak) and (there exist some elements on the line list) */
		if (state->linefeed_state >= 2 && state->line_list != NULL)
		{
			/* Append zero width and height line feed to the line list and flush the line list into
			   the line array. This forces the layout of elements contained within the MULTICOL tags
			   to start on a blank line_list and hence on a new line.  lo_EndMultiColumn needs this to
			   do its line array hacking properly. */
			lo_AppendZeroWidthAndHeightLF(context, state);			
		}

		lo_SetSoftLineBreakState(context, state, FALSE, 2);
        multicol->close_table = FALSE;		
    }

	/*
	 * Since we are going to block layout during multicol
	 * processing, we need to flush the compositor of any
	 * pending displays.
	 */
	if (context->compositor)
	{
		CL_CompositeNow(context->compositor);
	}

	lo_StartMultiColInit( state, multicol );

	/*
	multicol->end_last_line = state->end_last_line;
	multicol->start_ele = state->top_state->element_id;
	multicol->start_line = state->line_num;
	multicol->end_line = multicol->start_line;
	multicol->start_x = state->x;
	multicol->start_y = state->y;
	multicol->end_y = multicol->start_y;
	*/
	multicol->cols = 1;
	multicol->gutter = MULTICOL_GUTTER_WIDTH;

	/*	
     * Get the cols parameter.
     */
    buff = lo_FetchParamValue(context, tag, PARAM_COLS);
    if (buff != NULL)
    {
		PA_LOCK(str, char *, buff);
		multicol->cols = XP_ATOI(str);
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}

	if (multicol->cols <= 1)
	{
		XP_DELETE(multicol);
		multicolEle->multicol = NULL;
		return;
	}

	/*
     * Get the gutter parameter.
     */
    buff = lo_FetchParamValue(context, tag, PARAM_GUTTER);
    if (buff != NULL)
    {
        PA_LOCK(str, char *, buff);
		multicol->gutter = XP_ATOI(str);
		if (multicol->gutter < 1)
		{
			multicol->gutter = 1;
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}

	multicol->gutter = FEUNITS_X(multicol->gutter, context);

	doc_width = state->right_margin - state->left_margin;
	/* width = doc_width; */

	/*
	 * Get the width parameter, in absolute or percentage.
	 * If percentage, make it absolute.
	 */
	/*
	buff = lo_FetchParamValue(context, tag, PARAM_WIDTH);
	if (buff != NULL)
	{
		Bool is_percent;

		PA_LOCK(str, char *, buff);
		val = lo_ValueOrPercent(str, &is_percent);
		if (is_percent != FALSE)
		{
			if (state->allow_percent_width == FALSE)
			{
				val = 0;
			}
			else
			{
				val = doc_width * val / 100;
				if (val < 1)
				{
					val = 1;
				}
			}
		}
		else
		{
			val = FEUNITS_X(val, context);
			if (val < 1)
			{
				val = 1;
			}
		}
		width = val;
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}
	*/

	buff = lo_FetchParamValue(context, tag, PARAM_WIDTH);
	if (buff != NULL)
	{
		Bool is_percent;

		PA_LOCK(str, char *, buff);
		val = lo_ValueOrPercent(str, &is_percent);
		if (is_percent != FALSE)
		{
			multicol->width = val;
			multicol->isPercentWidth = TRUE;
		}
		else
		{
			multicol->width = val;
			multicol->isPercentWidth = FALSE;
			val = FEUNITS_X(val, context);
			if (val < 1)
			{
				val = 1;
			}
		}
		PA_UNLOCK(buff);
		PA_FREE(buff);
	}

	/*
	width = width - ((multicol->cols - 1) * multicol->gutter);
	multicol->col_width = width / multicol->cols;
	if (multicol->col_width < MULTICOL_MIN_WIDTH)
	{
		multicol->col_width = MULTICOL_MIN_WIDTH;
	}

	multicol->orig_margin = state->right_margin;

	lo_PushList(state, tag, QUOTE_NONE);
*/

	lo_SetupStateForBeginMulticol( state, multicol, doc_width );
	
	/*
	state->right_margin = state->left_margin + multicol->col_width;
	state->x = state->left_margin;
	state->list_stack->old_left_margin = state->left_margin;
	state->list_stack->old_right_margin = state->right_margin;

	multicol->orig_min_width = state->min_width;
	state->min_width = 0;
	*/

	/*
	 * Don't display anything while processing the multicolumn text.
	 */
	/*
	multicol->orig_display_blocking_element_y = state->display_blocking_element_y;
	state->display_blocking_element_y = -1;
	multicol->orig_display_blocked = state->display_blocked;
	state->display_blocked = TRUE;

	multicol->next = state->current_multicol;
	state->current_multicol = multicol;
	*/
}