Example #1
0
GSList *
metadata_list_append (GSList *metadata, const gchar *strid, const gchar *data)
{
	GSList		*iter = metadata;
	gchar		*tmp, *checked_data = NULL;
	struct pair 	*p;
	
	if (!data)
		return metadata;
	
	/* lookup type and check format */
	switch (metadata_get_type (strid)) {
		case METADATA_TYPE_TEXT:
			/* No check because renderer will process further */
			checked_data = g_strdup (data);
			break;
		case METADATA_TYPE_URL:
			/* Simple sanity check to see if it doesn't break XML */
			if (!strchr(data, '<') && !(strchr (data, '>')) && !(strchr (data, '&'))) {
				checked_data = g_strdup (data);
			} else {
				checked_data = common_uri_escape (data);
			}
			
			/* finally strip whitespace */
			checked_data = g_strchomp (checked_data);
			break;
		default:
			g_warning ("Unknown metadata type: %s (id=%d), please report this Liferea bug! Treating as HTML.", strid, metadata_get_type (strid));
		case METADATA_TYPE_HTML:
			/* Needs to check for proper XHTML */
			if (xhtml_is_well_formed (data)) {
				tmp = g_strdup (data);
			} else {
				debug1 (DEBUG_PARSING, "not well formed HTML: %s", data);
				tmp = g_markup_escape_text (data, -1);
				debug1 (DEBUG_PARSING, "escaped as: %s", tmp);
			}
			/* And needs to remove DHTML */
			checked_data = xhtml_strip_dhtml (tmp);
			g_free (tmp);
			break;
	}
	
	while (iter) {
		p = (struct pair*)iter->data; 
		if (g_str_equal (p->strid, strid)) {
			/* Avoid duplicate values */
			if (NULL == g_slist_find_custom (p->data, checked_data, metadata_value_cmp))
				p->data = g_slist_append (p->data, checked_data);
			return metadata;
		}
		iter = iter->next;
	}
	p = g_new (struct pair, 1);
	p->strid = g_strdup (strid);
	p->data = g_slist_append (NULL, checked_data);
	metadata = g_slist_append (metadata, p);
	return metadata;
}
Example #2
0
static gchar *
htmlview_render_item (itemPtr item, 
                      guint viewMode,
                      gboolean summaryMode) 
{
	renderParamPtr	params;
	gchar		*output = NULL, *baseUrl = NULL;
	nodePtr		node;
	xmlDocPtr 	doc;
	xmlNodePtr 	xmlNode;
	const gchar     *text_direction = NULL;
	gboolean	isMergedItemset;

	debug_enter ("htmlview_render_item");

	/* don't use node from htmlView_priv as this would be
	   wrong for folders and other merged item sets */
	node = node_from_id (item->nodeId);
	
	isMergedItemset = (node != htmlView_priv.node);

	/* do the XML serialization */
	doc = xmlNewDoc ("1.0");
	xmlNode = xmlNewDocNode (doc, NULL, "itemset", NULL);
	xmlDocSetRootElement (doc, xmlNode);
				
	item_to_xml(item, xmlDocGetRootElement (doc));

	text_direction = htmlview_get_item_direction (item);
			
	if (IS_FEED (node)) {
		xmlNodePtr feed;
		feed = xmlNewChild (xmlDocGetRootElement (doc), NULL, "feed", NULL);
		feed_to_xml (node, feed);
	}
	
	/* do the XSLT rendering */
	params = render_parameter_new ();
	
	if (NULL != node_get_base_url (node)) {
		baseUrl = common_uri_escape (node_get_base_url (node));
		render_parameter_add (params, "baseUrl='%s'", baseUrl);
	}

	render_parameter_add (params, "summary='%d'", summaryMode?1:0);
	render_parameter_add (params, "showFeedName='%d'", isMergedItemset?1:0);
	render_parameter_add (params, "single='%d'", (viewMode == ITEMVIEW_SINGLE_ITEM)?1:0);
	render_parameter_add (params, "txtDirection='%s'", text_direction);
	render_parameter_add (params, "appDirection='%s'", common_get_app_direction ());
	output = render_xml (doc, "item", params);
	
	/* For debugging use: xmlSaveFormatFile("/tmp/test.xml", doc, 1); */
	xmlFreeDoc (doc);
	g_free (baseUrl);
	
	debug_exit ("htmlview_render_item");

	return output;
}
Example #3
0
/* to correctly escape and expand URLs */
xmlChar *
common_build_url (const gchar *url, const gchar *baseURL)
{
	xmlChar	*escapedURL, *absURL, *escapedBaseURL;

	escapedURL = common_uri_escape (url);

	if (baseURL) {
		escapedBaseURL = common_uri_escape (baseURL);	
		absURL = xmlBuildURI (escapedURL, escapedBaseURL);
		if (absURL)
			xmlFree (escapedURL);
		else
			absURL = escapedURL;
		
		xmlFree (escapedBaseURL);
	} else {
		absURL = escapedURL;
	}

	return absURL;
}
Example #4
0
xmlChar *
common_uri_sanitize (const xmlChar *uri)
{
	xmlChar *tmp, *result;
	
	/* We must escape all dangerous characters (e.g. & and spaces)
	   in the URL. As we do not know if the URL is already escaped we
	   simply unescape and reescape it. */
	tmp = common_uri_unescape (uri);
	result = common_uri_escape (tmp);
	g_free (tmp);

	return result;
}
Example #5
0
gchar *
enclosure_values_to_string (const gchar *url, const gchar *mime, gssize size, gboolean downloaded)
{
	gchar *result, *safeUrl;
	
	/* There are websites out there encoding -1 as size */
	if (size < 0)
		size = 0;
		
	safeUrl = (gchar *) common_uri_escape (BAD_CAST url);
	result = g_strdup_printf ("enc:%s:%s:%" G_GSSIZE_FORMAT ":%s", downloaded?"1":"0", mime?mime:"", size, safeUrl);
	g_free (safeUrl);
	
	return result;
}