Esempio n. 1
0
static nserror svg_clone(const struct content *old, struct content **newc)
{
	svg_content *svg;
	nserror error;

	svg = calloc(1, sizeof(svg_content));
	if (svg == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &svg->base);
	if (error != NSERROR_OK) {
		content_destroy(&svg->base);
		return error;
	}

	/* Simply replay create/convert */
	error = svg_create_svg_data(svg);
	if (error != NSERROR_OK) {
		content_destroy(&svg->base);
		return error;
	}

	if (old->status == CONTENT_STATUS_READY ||
			old->status == CONTENT_STATUS_DONE) {
		if (svg_convert(&svg->base) == false) {
			content_destroy(&svg->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) svg;

	return NSERROR_OK;
}
Esempio n. 2
0
/**
 * Clone content.
 */
static nserror nsjpeg_clone(const struct content *old, struct content **newc)
{
	struct content *jpeg_c;
	nserror error;

	jpeg_c = talloc_zero(0, struct content);
	if (jpeg_c == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, jpeg_c);
	if (error != NSERROR_OK) {
		content_destroy(jpeg_c);
		return error;
	}

	/* re-convert if the content is ready */
	if ((old->status == CONTENT_STATUS_READY) ||
	    (old->status == CONTENT_STATUS_DONE)) {
		if (nsjpeg_convert(jpeg_c) == false) {
			content_destroy(jpeg_c);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = jpeg_c;

	return NSERROR_OK;
}
Esempio n. 3
0
nserror amiga_dt_picture_clone(const struct content *old, struct content **newc)
{
	struct content *adt;
	nserror error;

	LOG(("amiga_dt_picture_clone"));

	adt = calloc(1, sizeof(struct content));
	if (adt == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, adt);
	if (error != NSERROR_OK) {
		content_destroy(adt);
		return error;
	}

	/* We "clone" the old content by replaying conversion */
	if ((old->status == CONTENT_STATUS_READY) || 
	    (old->status == CONTENT_STATUS_DONE)) {
		if (amiga_dt_picture_convert(adt) == false) {
			content_destroy(adt);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = adt;

	return NSERROR_OK;
}
Esempio n. 4
0
static nserror nsgif_clone(const struct content *old, struct content **newc)
{
	nsgif_content *gif;
	nserror error;

	gif = calloc(1, sizeof(nsgif_content));
	if (gif == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &gif->base);
	if (error != NSERROR_OK) {
		content_destroy(&gif->base);
		return error;
	}

	/* Simply replay creation and conversion of content */
	error = nsgif_create_gif_data(gif);
	if (error != NSERROR_OK) {
		content_destroy(&gif->base);
		return error;
	}

	if (old->status == CONTENT_STATUS_READY ||
			old->status == CONTENT_STATUS_DONE) {
		if (nsgif_convert(&gif->base) == false) {
			content_destroy(&gif->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) gif;

	return NSERROR_OK;
}
Esempio n. 5
0
static nserror nsico_clone(const struct content *old, struct content **newc)
{
	nsico_content *ico;
	nserror error;

	ico = calloc(1, sizeof(nsico_content));
	if (ico == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &ico->base);
	if (error != NSERROR_OK) {
		content_destroy(&ico->base);
		return error;
	}

	/* Simply replay creation and conversion */
	error = nsico_create_ico_data(ico);
	if (error != NSERROR_OK) {
		content_destroy(&ico->base);
		return error;
	}

	if (old->status == CONTENT_STATUS_READY ||
			old->status == CONTENT_STATUS_DONE) {
		if (nsico_convert(&ico->base) == false) {
			content_destroy(&ico->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) ico;

	return NSERROR_OK;
}
Esempio n. 6
0
nserror artworks_clone(const struct content *old, struct content **newc)
{
	artworks_content *aw;
	nserror error;

	aw = calloc(1, sizeof(artworks_content));
	if (aw == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &aw->base);
	if (error != NSERROR_OK) {
		content_destroy(&aw->base);
		return error;
	}

	/* Simply re-run convert */
	if (old->status == CONTENT_STATUS_READY || 
			old->status == CONTENT_STATUS_DONE) {
		if (artworks_convert(&aw->base) == false) {
			content_destroy(&aw->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) aw;

	return NSERROR_OK;
}
Esempio n. 7
0
File: icon.c Progetto: ysei/NetSurf
nserror amiga_icon_clone(const struct content *old, struct content **newc)
{
	amiga_icon_content *ai;
	nserror error;

	ai = calloc(1, sizeof(amiga_icon_content));
	if (ai == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &ai->base);
	if (error != NSERROR_OK) {
		content_destroy(&ai->base);
		return error;
	}

	/* Simply replay convert */
	if (old->status == CONTENT_STATUS_READY ||
			old->status == CONTENT_STATUS_DONE) {
		if (amiga_icon_convert(&ai->base) == false) {
			content_destroy(&ai->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) ai;

	return NSERROR_OK;
}
Esempio n. 8
0
static nserror nssprite_clone(const struct content *old, struct content **newc)
{
	nssprite_content *sprite;
	nserror error;

	sprite = calloc(1, sizeof(nssprite_content));
	if (sprite == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &sprite->base);
	if (error != NSERROR_OK) {
		content_destroy(&sprite->base);
		return error;
	}

	/* Simply replay convert */
	if (old->status == CONTENT_STATUS_READY ||
			old->status == CONTENT_STATUS_DONE) {
		if (nssprite_convert(&sprite->base) == false) {
			content_destroy(&sprite->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) sprite;

	return NSERROR_OK;
}
Esempio n. 9
0
static nserror nsbmp_clone(const struct content *old, struct content **newc)
{
	nsbmp_content *new_bmp;
	nserror error;

	new_bmp = calloc(1, sizeof(nsbmp_content));
	if (new_bmp == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &new_bmp->base);
	if (error != NSERROR_OK) {
		content_destroy(&new_bmp->base);
		return error;
	}

	/* We "clone" the old content by replaying creation and conversion */
	error = nsbmp_create_bmp_data(new_bmp);
	if (error != NSERROR_OK) {
		content_destroy(&new_bmp->base);
		return error;
	}

	if (old->status == CONTENT_STATUS_READY || 
			old->status == CONTENT_STATUS_DONE) {
		if (nsbmp_convert(&new_bmp->base) == false) {
			content_destroy(&new_bmp->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) new_bmp;

	return NSERROR_OK;
}
Esempio n. 10
0
nserror nscss_clone(const struct content *old, struct content **newc)
{
	const nscss_content *old_css = (const nscss_content *) old;
	nscss_content *new_css;
	const char *data;
	unsigned long size;
	nserror error;

	new_css = calloc(1, sizeof(nscss_content));
	if (new_css == NULL)
		return NSERROR_NOMEM;

	/* Clone content */
	error = content__clone(old, &new_css->base);
	if (error != NSERROR_OK) {
		content_destroy(&new_css->base);
		return error;
	}

	/* Simply replay create/process/convert */
	error = nscss_create_css_data(&new_css->data,
			nsurl_access(content_get_url(&new_css->base)),
			old_css->data.charset, 
			new_css->base.quirks,
			nscss_content_done, new_css);
	if (error != NSERROR_OK) {
		content_destroy(&new_css->base);
		return error;
	}

	data = content__get_source_data(&new_css->base, &size);
	if (size > 0) {
		if (nscss_process_data(&new_css->base, data, size) == false) {
			content_destroy(&new_css->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	if (old->status == CONTENT_STATUS_READY ||
			old->status == CONTENT_STATUS_DONE) {
		if (nscss_convert(&new_css->base) == false) {
			content_destroy(&new_css->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) new_css;

	return NSERROR_OK;
}
Esempio n. 11
0
static int
_pilot_servicehttp_runparser(struct pilot_service *thiz, ServerData *data)
{
	int len;
	switch (data->state)
	{
		case EBegin:
			data->req = httprequest_new();
			data->state = EParse;
		break;
		case EParse:
		{
			char buff[256];
			len = sizeof(buff);

			len = thiz->socket->action.read(thiz->socket, buff, len - 1);
			if (len < 0)
				data->state = EEnd;
			len = httprequest_parse(data->req, buff, len);
			if (len == 0)
				data->state = EContent;
		}
		break;
		case EContent:
		{
			Content *content = contentfile_new("/home/http", data->req->m_filepath);
			data->response = httpresponse_new(content);
			data->state = EResponse;
		}
		break;
		case EResponse:
		{
			char buff[256];
			len = sizeof(buff);
			len = httpresponse_format(data->response, buff, len - 1);
			if (len > 0)
				len = thiz->socket->action.write(thiz->socket, buff, len);
			else if (len == 0)
				data->state = EEnd;
		}
		break;
		case EEnd:
			if (data->response->m_Content)
				content_destroy(data->response->m_Content);
			data->response->m_Content = NULL;
			if (data->response)
				httpresponse_destroy(data->response);
			data->response = NULL;
			if (data->req)
				httprequest_destroy(data->req);
			data->req = NULL;
			data->state = EBegin;
		break;
	}
			
	return 0;
}
Esempio n. 12
0
static nserror rsvg_clone(const struct content *old, struct content **newc)
{
	rsvg_content *svg;
	nserror error;
	const char *data;
	unsigned long size;

	svg = talloc_zero(0, rsvg_content);
	if (svg == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &svg->base);
	if (error != NSERROR_OK) {
		content_destroy(&svg->base);
		return error;
	}

	/* Simply replay create/process/convert */
	error = rsvg_create_svg_data(svg);
	if (error != NSERROR_OK) {
		content_destroy(&svg->base);
		return error;
	}

	data = content__get_source_data(&svg->base, &size);
	if (size > 0) {
		if (rsvg_process_data(&svg->base, data, size) == false) {
			content_destroy(&svg->base);
			return NSERROR_NOMEM;
		}
	}

	if (old->status == CONTENT_STATUS_READY ||
			old->status == CONTENT_STATUS_DONE) {
		if (rsvg_convert(&svg->base) == false) {
			content_destroy(&svg->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*newc = (struct content *) svg;

	return NSERROR_OK;
}
Esempio n. 13
0
static nserror nspng_clone(const struct content *old_c, struct content **new_c)
{
	nspng_content *clone_png_c;
	nserror error;
	const char *data;
	unsigned long size;

	clone_png_c = calloc(1, sizeof(nspng_content));
	if (clone_png_c == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old_c, &clone_png_c->base);
	if (error != NSERROR_OK) {
		content_destroy(&clone_png_c->base);
		return error;
	}

	/* Simply replay create/process/convert */
	error = nspng_create_png_data(clone_png_c);
	if (error != NSERROR_OK) {
		content_destroy(&clone_png_c->base);
		return error;
	}

	data = content__get_source_data(&clone_png_c->base, &size);
	if (size > 0) {
		if (nspng_process_data(&clone_png_c->base, data, size) == false) {
			content_destroy(&clone_png_c->base);
			return NSERROR_NOMEM;
		}
	}

	if ((old_c->status == CONTENT_STATUS_READY) ||
	    (old_c->status == CONTENT_STATUS_DONE)) {
		if (nspng_convert(&clone_png_c->base) == false) {
			content_destroy(&clone_png_c->base);
			return NSERROR_CLONE_FAILED;
		}
	}

	*new_c = (struct content *)clone_png_c;

	return NSERROR_OK;
}
Esempio n. 14
0
/**
 * Attempt to clean the cache
 */
static void hlcache_clean(void *ignored)
{
	hlcache_entry *entry, *next;

	for (entry = hlcache->content_list; entry != NULL; entry = next) {
		next = entry->next;

		if (entry->content == NULL)
			continue;

		if (content__get_status(entry->content) ==
				CONTENT_STATUS_LOADING)
			continue;

		if (content_count_users(entry->content) != 0)
			continue;

		/** \todo This is over-zealous: all unused contents
		 * will be immediately destroyed. Ideally, we want to
		 * purge all unused contents that are using stale
		 * source data, and enough fresh contents such that
		 * the cache fits in the configured cache size limit.
		 */

		/* Remove entry from cache */
		if (entry->prev == NULL)
			hlcache->content_list = entry->next;
		else
			entry->prev->next = entry->next;

		if (entry->next != NULL)
			entry->next->prev = entry->prev;

		/* Destroy content */
		content_destroy(entry->content);

		/* Destroy entry */
		free(entry);
	}

	/* Attempt to clean the llcache */
	llcache_clean();

	/* Re-schedule ourselves */
	guit->browser->schedule(hlcache->params.bg_clean_time, hlcache_clean, NULL);
}
Esempio n. 15
0
static nserror 
javascript_clone(const struct content *old, struct content **newc)
{
	javascript_content *script;
	nserror error;

	script = calloc(1, sizeof(javascript_content));
	if (script == NULL)
		return NSERROR_NOMEM;

	error = content__clone(old, &script->base);
	if (error != NSERROR_OK) {
		content_destroy(&script->base);
		return error;
	}

	*newc = (struct content *) script;

	return NSERROR_OK;
}