2003-06-25 03:22:00 +04:00
|
|
|
/*
|
2007-01-13 03:21:15 +03:00
|
|
|
* Copyright 2005-2007 James Bursa <bursa@users.sourceforge.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** \file
|
|
|
|
* Content handling (implementation).
|
2003-09-11 02:27:15 +04:00
|
|
|
*
|
2003-09-08 01:08:13 +04:00
|
|
|
* This implementation is based on the ::handler_map array, which maps
|
|
|
|
* ::content_type to the functions which implement that type.
|
|
|
|
*/
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <assert.h>
|
2005-08-21 16:04:18 +04:00
|
|
|
#include <inttypes.h>
|
2004-06-05 19:03:59 +04:00
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
2003-02-09 15:58:15 +03:00
|
|
|
#include <stdlib.h>
|
2004-06-05 19:03:59 +04:00
|
|
|
#include <string.h>
|
2007-01-30 01:27:15 +03:00
|
|
|
#include <strings.h>
|
2007-01-13 03:21:15 +03:00
|
|
|
#include <time.h>
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/config.h"
|
|
|
|
#include "content/content.h"
|
|
|
|
#include "content/fetch.h"
|
|
|
|
#include "content/fetchcache.h"
|
|
|
|
#include "css/css.h"
|
|
|
|
#include "image/bitmap.h"
|
|
|
|
#include "desktop/options.h"
|
|
|
|
#include "render/directory.h"
|
|
|
|
#include "render/html.h"
|
|
|
|
#include "render/textplain.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_JPEG
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/jpeg.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-07-16 23:47:03 +04:00
|
|
|
#ifdef WITH_MNG
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/mng.h"
|
2004-07-16 23:47:03 +04:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_GIF
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/gif.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "image/bmp.h"
|
|
|
|
#include "image/ico.h"
|
2006-02-25 21:51:51 +03:00
|
|
|
#endif
|
2007-07-18 18:49:26 +04:00
|
|
|
#ifdef WITH_NS_SVG
|
2007-07-13 07:54:47 +04:00
|
|
|
#include "image/svg.h"
|
2007-07-18 18:49:26 +04:00
|
|
|
#endif
|
2007-07-18 21:58:35 +04:00
|
|
|
#ifdef WITH_RSVG
|
|
|
|
#include "image/rsvg.h"
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_SPRITE
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/sprite.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2008-03-29 16:30:04 +03:00
|
|
|
#ifdef WITH_NSSPRITE
|
|
|
|
#include "image/nssprite.h"
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_DRAW
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/draw.h"
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/plugin.h"
|
2003-07-15 02:57:45 +04:00
|
|
|
#endif
|
2005-12-10 17:31:33 +03:00
|
|
|
#ifdef WITH_ARTWORKS
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/artworks.h"
|
2005-12-10 17:31:33 +03:00
|
|
|
#endif
|
2008-09-16 00:23:02 +04:00
|
|
|
#ifdef WITH_PNG
|
|
|
|
#include "image/png.h"
|
|
|
|
#endif
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/talloc.h"
|
|
|
|
#include "utils/utils.h"
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
/** Linked list of all content structures. May include more than one content
|
|
|
|
* per URL. Doubly-linked. */
|
|
|
|
struct content *content_list = 0;
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** An entry in mime_map. */
|
2003-02-09 15:58:15 +03:00
|
|
|
struct mime_entry {
|
2003-07-08 02:10:51 +04:00
|
|
|
char mime_type[40];
|
2003-02-09 15:58:15 +03:00
|
|
|
content_type type;
|
|
|
|
};
|
2003-09-08 01:08:13 +04:00
|
|
|
/** A map from MIME type to ::content_type. Must be sorted by mime_type. */
|
2003-02-09 15:58:15 +03:00
|
|
|
static const struct mime_entry mime_map[] = {
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"application/bmp", CONTENT_BMP},
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_DRAW
|
2005-01-14 01:42:39 +03:00
|
|
|
{"application/drawfile", CONTENT_DRAW},
|
2006-02-25 21:51:51 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_BMP
|
2006-02-26 05:25:19 +03:00
|
|
|
{"application/ico", CONTENT_ICO},
|
2006-02-25 21:51:51 +03:00
|
|
|
{"application/preview", CONTENT_BMP},
|
|
|
|
{"application/x-bmp", CONTENT_BMP},
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
2005-01-14 01:42:39 +03:00
|
|
|
{"application/x-drawfile", CONTENT_DRAW},
|
2005-04-01 06:25:11 +04:00
|
|
|
#endif
|
2006-02-26 05:25:19 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"application/x-ico", CONTENT_ICO},
|
|
|
|
#endif
|
2006-07-06 04:07:11 +04:00
|
|
|
{"application/x-netsurf-directory", CONTENT_DIRECTORY},
|
2005-01-14 01:42:39 +03:00
|
|
|
#ifdef WITH_THEME_INSTALL
|
|
|
|
{"application/x-netsurf-theme", CONTENT_THEME},
|
2006-02-25 21:51:51 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"application/x-win-bitmap", CONTENT_BMP},
|
2005-01-14 01:42:39 +03:00
|
|
|
#endif
|
2005-04-01 06:25:11 +04:00
|
|
|
{"application/xhtml+xml", CONTENT_HTML},
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"image/bmp", CONTENT_BMP},
|
|
|
|
#endif
|
2005-04-01 06:25:11 +04:00
|
|
|
#ifdef WITH_DRAW
|
2005-01-14 01:42:39 +03:00
|
|
|
{"image/drawfile", CONTENT_DRAW},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_GIF
|
2003-06-05 17:17:55 +04:00
|
|
|
{"image/gif", CONTENT_GIF},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2006-02-26 05:25:19 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"image/ico", CONTENT_ICO},
|
|
|
|
#endif
|
2004-07-17 00:57:14 +04:00
|
|
|
#ifdef WITH_MNG
|
|
|
|
{"image/jng", CONTENT_JNG},
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_JPEG
|
2003-02-26 00:00:27 +03:00
|
|
|
{"image/jpeg", CONTENT_JPEG},
|
2008-09-16 12:13:35 +04:00
|
|
|
{"image/jpg", CONTENT_JPEG},
|
2004-07-26 00:45:16 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_MNG
|
|
|
|
{"image/mng", CONTENT_MNG},
|
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"image/ms-bmp", CONTENT_BMP},
|
|
|
|
#endif
|
2004-07-26 00:45:16 +04:00
|
|
|
#ifdef WITH_JPEG
|
2004-03-16 03:51:34 +03:00
|
|
|
{"image/pjpeg", CONTENT_JPEG},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2008-09-16 00:23:02 +04:00
|
|
|
#if defined(WITH_MNG) || defined(WITH_PNG)
|
2003-05-10 15:15:49 +04:00
|
|
|
{"image/png", CONTENT_PNG},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2007-07-18 21:58:35 +04:00
|
|
|
#if defined(WITH_NS_SVG) || defined (WITH_RSVG)
|
2007-07-13 07:54:47 +04:00
|
|
|
{"image/svg", CONTENT_SVG},
|
|
|
|
{"image/svg+xml", CONTENT_SVG},
|
2007-07-18 18:49:26 +04:00
|
|
|
#endif
|
2007-07-21 04:20:04 +04:00
|
|
|
#ifdef WITH_ARTWORKS
|
|
|
|
{"image/x-artworks", CONTENT_ARTWORKS},
|
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"image/x-bitmap", CONTENT_BMP},
|
|
|
|
{"image/x-bmp", CONTENT_BMP},
|
|
|
|
#endif
|
2004-07-17 00:57:14 +04:00
|
|
|
#ifdef WITH_DRAW
|
|
|
|
{"image/x-drawfile", CONTENT_DRAW},
|
|
|
|
#endif
|
2006-02-26 05:25:19 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"image/x-icon", CONTENT_ICO},
|
|
|
|
#endif
|
2004-07-16 23:47:03 +04:00
|
|
|
#ifdef WITH_MNG
|
|
|
|
{"image/x-jng", CONTENT_JNG},
|
|
|
|
{"image/x-mng", CONTENT_MNG},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"image/x-ms-bmp", CONTENT_BMP},
|
|
|
|
#endif
|
2008-03-29 16:30:04 +03:00
|
|
|
#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
|
2003-09-11 02:27:15 +04:00
|
|
|
{"image/x-riscos-sprite", CONTENT_SPRITE},
|
2006-02-25 21:51:51 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_BMP
|
|
|
|
{"image/x-win-bitmap", CONTENT_BMP},
|
|
|
|
{"image/x-windows-bmp", CONTENT_BMP},
|
|
|
|
{"image/x-xbitmap", CONTENT_BMP},
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2003-04-04 19:19:32 +04:00
|
|
|
{"text/css", CONTENT_CSS},
|
2003-02-09 15:58:15 +03:00
|
|
|
{"text/html", CONTENT_HTML},
|
|
|
|
{"text/plain", CONTENT_TEXTPLAIN},
|
2004-07-17 00:57:14 +04:00
|
|
|
#ifdef WITH_MNG
|
|
|
|
{"video/mng", CONTENT_MNG},
|
|
|
|
{"video/x-mng", CONTENT_MNG},
|
|
|
|
#endif
|
2003-02-09 15:58:15 +03:00
|
|
|
};
|
|
|
|
#define MIME_MAP_COUNT (sizeof(mime_map) / sizeof(mime_map[0]))
|
|
|
|
|
2008-07-30 04:54:43 +04:00
|
|
|
const char * const content_type_name[] = {
|
2004-06-11 00:41:26 +04:00
|
|
|
"HTML",
|
|
|
|
"TEXTPLAIN",
|
|
|
|
"CSS",
|
|
|
|
#ifdef WITH_JPEG
|
|
|
|
"JPEG",
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_GIF
|
|
|
|
"GIF",
|
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
"BMP",
|
2006-02-26 05:25:19 +03:00
|
|
|
"ICO",
|
2006-02-25 21:51:51 +03:00
|
|
|
#endif
|
2008-09-16 00:23:02 +04:00
|
|
|
#if defined(WITH_MNG) || defined(WITH_PNG)
|
2004-09-04 02:44:48 +04:00
|
|
|
"PNG",
|
2008-09-16 00:23:02 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_MNG
|
2004-07-17 00:02:28 +04:00
|
|
|
"JNG",
|
2004-07-16 23:47:03 +04:00
|
|
|
"MNG",
|
|
|
|
#endif
|
2008-03-29 16:30:04 +03:00
|
|
|
#if defined(WITH_SPRITE) || defined(WITH_NSSPRITE)
|
2004-06-11 00:41:26 +04:00
|
|
|
"SPRITE",
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_DRAW
|
|
|
|
"DRAW",
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
|
|
|
"PLUGIN",
|
2005-01-14 01:42:39 +03:00
|
|
|
#endif
|
2006-07-06 04:07:11 +04:00
|
|
|
"DIRECTORY",
|
2005-01-14 01:42:39 +03:00
|
|
|
#ifdef WITH_THEME_INSTALL
|
|
|
|
"THEME",
|
2005-12-10 17:31:33 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_ARTWORKS
|
|
|
|
"ARTWORKS",
|
2007-07-21 04:14:15 +04:00
|
|
|
#endif
|
|
|
|
#if defined(WITH_NS_SVG) || defined(WITH_RSVG)
|
|
|
|
"SVG",
|
2004-06-11 00:41:26 +04:00
|
|
|
#endif
|
|
|
|
"OTHER",
|
|
|
|
"UNKNOWN"
|
|
|
|
};
|
|
|
|
|
2008-07-30 04:54:43 +04:00
|
|
|
const char * const content_status_name[] = {
|
2004-06-11 00:41:26 +04:00
|
|
|
"TYPE_UNKNOWN",
|
|
|
|
"LOADING",
|
|
|
|
"READY",
|
|
|
|
"DONE",
|
|
|
|
"ERROR"
|
|
|
|
};
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/** An entry in handler_map. */
|
2003-02-09 15:58:15 +03:00
|
|
|
struct handler_entry {
|
2004-06-11 00:41:26 +04:00
|
|
|
bool (*create)(struct content *c, const char *params[]);
|
|
|
|
bool (*process_data)(struct content *c, char *data, unsigned int size);
|
|
|
|
bool (*convert)(struct content *c, int width, int height);
|
|
|
|
void (*reformat)(struct content *c, int width, int height);
|
2003-02-09 15:58:15 +03:00
|
|
|
void (*destroy)(struct content *c);
|
2004-06-21 03:09:52 +04:00
|
|
|
void (*stop)(struct content *c);
|
2004-08-11 20:26:13 +04:00
|
|
|
bool (*redraw)(struct content *c, int x, int y,
|
2004-06-11 00:41:26 +04:00
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2008-09-29 02:37:13 +04:00
|
|
|
float scale, colour background_colour);
|
2006-02-21 23:49:12 +03:00
|
|
|
bool (*redraw_tiled)(struct content *c, int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2008-09-29 02:37:13 +04:00
|
|
|
float scale, colour background_colour,
|
2006-02-21 23:49:12 +03:00
|
|
|
bool repeat_x, bool repeat_y);
|
2004-08-12 02:08:26 +04:00
|
|
|
void (*open)(struct content *c, struct browser_window *bw,
|
2005-10-31 00:22:19 +03:00
|
|
|
struct content *page, unsigned int index,
|
|
|
|
struct box *box,
|
2004-08-12 02:08:26 +04:00
|
|
|
struct object_params *params);
|
|
|
|
void (*close)(struct content *c);
|
2004-08-11 23:02:32 +04:00
|
|
|
/** There must be one content per user for this type. */
|
|
|
|
bool no_share;
|
2003-02-09 15:58:15 +03:00
|
|
|
};
|
2003-09-08 01:08:13 +04:00
|
|
|
/** A table of handler functions, indexed by ::content_type.
|
|
|
|
* Must be ordered as enum ::content_type. */
|
2003-02-09 15:58:15 +03:00
|
|
|
static const struct handler_entry handler_map[] = {
|
2004-06-11 00:41:26 +04:00
|
|
|
{html_create, html_process_data, html_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
html_reformat, html_destroy, html_stop, html_redraw, 0,
|
2004-08-12 02:08:26 +04:00
|
|
|
html_open, html_close,
|
2004-08-11 23:02:32 +04:00
|
|
|
true},
|
2004-11-22 03:33:04 +03:00
|
|
|
{textplain_create, textplain_process_data, textplain_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
textplain_reformat, textplain_destroy, 0, textplain_redraw, 0,
|
2006-02-13 02:07:28 +03:00
|
|
|
0, 0, true},
|
2006-02-21 23:49:12 +03:00
|
|
|
{0, 0, css_convert, 0, css_destroy, 0, 0, 0, 0, 0, false},
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_JPEG
|
2006-02-21 23:49:12 +03:00
|
|
|
{0, 0, nsjpeg_convert, 0, nsjpeg_destroy, 0,
|
|
|
|
nsjpeg_redraw, nsjpeg_redraw_tiled, 0, 0, false},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2004-04-25 03:42:32 +04:00
|
|
|
#ifdef WITH_GIF
|
2006-02-21 23:49:12 +03:00
|
|
|
{nsgif_create, 0, nsgif_convert, 0, nsgif_destroy, 0,
|
|
|
|
nsgif_redraw, nsgif_redraw_tiled, 0, 0, false},
|
2004-04-25 03:42:32 +04:00
|
|
|
#endif
|
2006-02-25 21:51:51 +03:00
|
|
|
#ifdef WITH_BMP
|
|
|
|
{nsbmp_create, 0, nsbmp_convert, 0, nsbmp_destroy, 0,
|
|
|
|
nsbmp_redraw, nsbmp_redraw_tiled, 0, 0, false},
|
2006-02-26 05:25:19 +03:00
|
|
|
{nsico_create, 0, nsico_convert, 0, nsico_destroy, 0,
|
|
|
|
nsico_redraw, nsico_redraw_tiled, 0, 0, false},
|
2006-02-25 21:51:51 +03:00
|
|
|
#endif
|
2008-09-16 00:23:02 +04:00
|
|
|
|
|
|
|
#ifdef WITH_PNG
|
|
|
|
{nspng_create, nspng_process_data, nspng_convert,
|
|
|
|
0, nspng_destroy, 0, nspng_redraw, nspng_redraw_tiled,
|
|
|
|
0, 0, false},
|
|
|
|
#else
|
2004-09-04 02:44:48 +04:00
|
|
|
#ifdef WITH_MNG
|
2004-07-26 00:45:16 +04:00
|
|
|
{nsmng_create, nsmng_process_data, nsmng_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
0, nsmng_destroy, 0, nsmng_redraw, nsmng_redraw_tiled,
|
2008-09-16 00:23:02 +04:00
|
|
|
0, 0, false},
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef WITH_MNG
|
2004-07-16 23:47:03 +04:00
|
|
|
{nsmng_create, nsmng_process_data, nsmng_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
0, nsmng_destroy, 0, nsmng_redraw, nsmng_redraw_tiled,
|
|
|
|
0, 0, false},
|
2004-07-17 00:02:28 +04:00
|
|
|
{nsmng_create, nsmng_process_data, nsmng_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
0, nsmng_destroy, 0, nsmng_redraw, nsmng_redraw_tiled,
|
|
|
|
0, 0, false},
|
2004-07-16 23:47:03 +04:00
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_SPRITE
|
2005-04-05 21:19:58 +04:00
|
|
|
{0, 0, sprite_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
0, sprite_destroy, 0, sprite_redraw, 0, 0, 0, false},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
2008-03-29 16:30:04 +03:00
|
|
|
#ifdef WITH_NSSPRITE
|
|
|
|
{0, 0, nssprite_convert,
|
|
|
|
0, nssprite_destroy, 0, nssprite_redraw, 0, 0, 0, false},
|
|
|
|
#endif
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_DRAW
|
2004-06-11 00:41:26 +04:00
|
|
|
{0, 0, draw_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
0, draw_destroy, 0, draw_redraw, 0, 0, 0, false},
|
2004-01-05 05:10:59 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_PLUGIN
|
2004-08-11 20:26:13 +04:00
|
|
|
{plugin_create, 0, plugin_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
plugin_reformat, plugin_destroy, 0, plugin_redraw, 0,
|
2004-08-12 02:08:26 +04:00
|
|
|
plugin_open, plugin_close,
|
|
|
|
true},
|
2005-01-14 01:42:39 +03:00
|
|
|
#endif
|
2006-07-06 04:07:11 +04:00
|
|
|
{directory_create, 0, directory_convert,
|
2007-03-29 02:56:54 +04:00
|
|
|
0, directory_destroy, 0, 0, 0, 0, 0, true},
|
2005-01-14 01:42:39 +03:00
|
|
|
#ifdef WITH_THEME_INSTALL
|
2006-02-21 23:49:12 +03:00
|
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false},
|
2005-12-10 17:31:33 +03:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_ARTWORKS
|
|
|
|
{0, 0, artworks_convert,
|
2006-02-21 23:49:12 +03:00
|
|
|
0, artworks_destroy, 0, artworks_redraw, 0, 0, 0, false},
|
2003-06-17 23:24:21 +04:00
|
|
|
#endif
|
2007-07-18 18:49:26 +04:00
|
|
|
#ifdef WITH_NS_SVG
|
2007-07-13 07:54:47 +04:00
|
|
|
{svg_create, 0, svg_convert,
|
|
|
|
0, svg_destroy, 0, svg_redraw, 0, 0, 0, false},
|
2007-07-18 21:58:35 +04:00
|
|
|
#endif
|
|
|
|
#ifdef WITH_RSVG
|
2007-07-19 17:47:59 +04:00
|
|
|
{rsvg_create, rsvg_process_data, rsvg_convert,
|
2007-07-18 21:58:35 +04:00
|
|
|
0, rsvg_destroy, 0, rsvg_redraw, 0, 0, 0, false},
|
2007-07-18 18:49:26 +04:00
|
|
|
#endif
|
2006-02-21 23:49:12 +03:00
|
|
|
{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false}
|
2003-02-09 15:58:15 +03:00
|
|
|
};
|
2003-06-17 23:24:21 +04:00
|
|
|
#define HANDLER_MAP_COUNT (sizeof(handler_map) / sizeof(handler_map[0]))
|
2003-02-09 15:58:15 +03:00
|
|
|
|
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
static void content_update_status(struct content *c);
|
2004-06-21 19:09:59 +04:00
|
|
|
static void content_destroy(struct content *c);
|
2004-06-21 03:09:52 +04:00
|
|
|
static void content_stop_check(struct content *c);
|
|
|
|
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Convert a MIME type to a content_type.
|
|
|
|
*
|
|
|
|
* The returned ::content_type will always be suitable for content_set_type().
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
content_type content_lookup(const char *mime_type)
|
|
|
|
{
|
|
|
|
struct mime_entry *m;
|
|
|
|
m = bsearch(mime_type, mime_map, MIME_MAP_COUNT, sizeof(mime_map[0]),
|
2004-04-20 22:27:46 +04:00
|
|
|
(int (*)(const void *, const void *)) strcasecmp);
|
2003-07-10 01:33:01 +04:00
|
|
|
if (m == 0) {
|
2004-01-05 05:10:59 +03:00
|
|
|
#ifdef WITH_PLUGIN
|
2003-07-10 01:33:01 +04:00
|
|
|
if (plugin_handleable(mime_type))
|
|
|
|
return CONTENT_PLUGIN;
|
2003-07-15 02:57:45 +04:00
|
|
|
#endif
|
2003-02-09 15:58:15 +03:00
|
|
|
return CONTENT_OTHER;
|
2003-07-10 01:33:01 +04:00
|
|
|
}
|
2003-02-09 15:58:15 +03:00
|
|
|
return m->type;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Create a new content structure.
|
|
|
|
*
|
2004-06-11 00:41:26 +04:00
|
|
|
* \param url URL of content, copied
|
|
|
|
* \return the new content structure, or 0 on memory exhaustion
|
|
|
|
*
|
2003-09-08 01:08:13 +04:00
|
|
|
* The type is initialised to CONTENT_UNKNOWN, and the status to
|
|
|
|
* CONTENT_STATUS_TYPE_UNKNOWN.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
struct content * content_create(const char *url)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
|
|
|
struct content *c;
|
2003-06-17 23:24:21 +04:00
|
|
|
struct content_user *user_sentinel;
|
2007-03-18 20:04:18 +03:00
|
|
|
|
2007-03-18 23:19:13 +03:00
|
|
|
c = talloc_zero(0, struct content);
|
2004-06-11 00:41:26 +04:00
|
|
|
if (!c)
|
|
|
|
return 0;
|
2007-03-18 20:04:18 +03:00
|
|
|
|
|
|
|
LOG(("url %s -> %p", url, c));
|
|
|
|
|
2005-04-03 14:58:49 +04:00
|
|
|
user_sentinel = talloc(c, struct content_user);
|
2004-06-11 00:41:26 +04:00
|
|
|
if (!user_sentinel) {
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_free(c);
|
2004-06-11 00:41:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-03 14:58:49 +04:00
|
|
|
c->url = talloc_strdup(c, url);
|
2004-06-11 00:41:26 +04:00
|
|
|
if (!c->url) {
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_free(c);
|
2004-06-11 00:41:26 +04:00
|
|
|
return 0;
|
|
|
|
}
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_set_name_const(c, c->url);
|
2003-06-17 23:24:21 +04:00
|
|
|
c->type = CONTENT_UNKNOWN;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->mime_type = 0;
|
2003-06-17 23:24:21 +04:00
|
|
|
c->status = CONTENT_STATUS_TYPE_UNKNOWN;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->width = 0;
|
|
|
|
c->height = 0;
|
|
|
|
c->available_width = 0;
|
2006-01-25 09:52:38 +03:00
|
|
|
c->refresh = 0;
|
2004-09-04 02:44:48 +04:00
|
|
|
c->bitmap = 0;
|
2004-06-21 19:09:59 +04:00
|
|
|
c->fresh = false;
|
2007-01-30 18:32:31 +03:00
|
|
|
c->time = wallclock();
|
2006-12-04 01:34:26 +03:00
|
|
|
c->size = 0;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->title = 0;
|
|
|
|
c->active = 0;
|
2003-06-17 23:24:21 +04:00
|
|
|
user_sentinel->callback = 0;
|
|
|
|
user_sentinel->p1 = user_sentinel->p2 = 0;
|
|
|
|
user_sentinel->next = 0;
|
|
|
|
c->user_list = user_sentinel;
|
2007-01-13 03:21:15 +03:00
|
|
|
c->sub_status[0] = 0;
|
2005-07-06 02:43:38 +04:00
|
|
|
c->locked = false;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->fetch = 0;
|
|
|
|
c->source_data = 0;
|
|
|
|
c->source_size = 0;
|
2005-04-05 06:36:33 +04:00
|
|
|
c->source_allocated = 0;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->total_size = 0;
|
2007-01-13 03:21:15 +03:00
|
|
|
c->http_code = 0;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->no_error_pages = false;
|
2005-01-03 05:09:20 +03:00
|
|
|
c->download = false;
|
Rework handling of HTTP redirects -- we now count the number of redirects followed for a given item and abort if a fixed limit is reached. This fixes sites which have pages that redirect to themselves.
Redirect handling is now transparent to clients of fetchcache.
The new scheme works as follows:
1) Request content for URL (fetchcache()
2) Start fetch of content (fetchcache_go()
3) If no redirect, continue through LOADING, READY, DONE etc. states as before
If redirect, receive NEWPTR for each redirect that occurs, then continue
through LOADING, READY, DONE etc. states as before.
The upshot of this is that redirects result in extra contents being created. It also means that, until LOADING has been received, the content (and thus the URL being fetched) may change. Therefore, fetchcache clients should expect to have to deal with transient data prior to LOADING occurring.
As a necessary side-effect of this, the HTML object URLs and CSS @import URLs are no longer stored alongside the relevant contents. These URLs can be accessed by interrogating the url member of struct content anyway, so it was a rather redundant scheme before.
svn path=/trunk/netsurf/; revision=3787
2008-01-28 04:35:00 +03:00
|
|
|
c->redirect_count = 0;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->error_count = 0;
|
2008-06-03 05:10:46 +04:00
|
|
|
c->cache_data.req_time = 0;
|
|
|
|
c->cache_data.res_time = 0;
|
|
|
|
c->cache_data.date = 0;
|
|
|
|
c->cache_data.expires = 0;
|
|
|
|
c->cache_data.age = INVALID_AGE;
|
|
|
|
c->cache_data.max_age = INVALID_AGE;
|
|
|
|
c->cache_data.no_cache = false;
|
|
|
|
c->cache_data.etag = 0;
|
|
|
|
c->cache_data.last_modified = 0;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2007-01-13 03:21:15 +03:00
|
|
|
content_set_status(c, messages_get("Loading"));
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
c->prev = 0;
|
|
|
|
c->next = content_list;
|
|
|
|
if (content_list)
|
|
|
|
content_list->prev = c;
|
|
|
|
content_list = c;
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-21 19:09:59 +04:00
|
|
|
/**
|
|
|
|
* Get a content from the memory cache.
|
|
|
|
*
|
|
|
|
* \param url URL of content
|
|
|
|
* \return content if found, or 0
|
|
|
|
*
|
|
|
|
* Searches the list of contents for one corresponding to the given url, and
|
2004-08-11 23:02:32 +04:00
|
|
|
* which is fresh and shareable.
|
2004-06-21 19:09:59 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
struct content * content_get(const char *url)
|
|
|
|
{
|
|
|
|
struct content *c;
|
|
|
|
|
|
|
|
for (c = content_list; c; c = c->next) {
|
2004-08-11 23:02:32 +04:00
|
|
|
if (!c->fresh)
|
|
|
|
/* not fresh */
|
|
|
|
continue;
|
|
|
|
if (c->status == CONTENT_STATUS_ERROR)
|
|
|
|
/* error state */
|
|
|
|
continue;
|
|
|
|
if (c->type != CONTENT_UNKNOWN &&
|
|
|
|
handler_map[c->type].no_share &&
|
|
|
|
c->user_list->next)
|
|
|
|
/* not shareable, and has a user already */
|
|
|
|
continue;
|
|
|
|
if (strcmp(c->url, url))
|
|
|
|
continue;
|
|
|
|
return c;
|
2004-06-21 19:09:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-02-06 03:10:09 +03:00
|
|
|
/**
|
|
|
|
* Get a READY or DONE content from the memory cache.
|
|
|
|
*
|
|
|
|
* \param url URL of content
|
|
|
|
* \return content if found, or 0
|
|
|
|
*
|
|
|
|
* Searches the list of contents for one corresponding to the given url, and
|
|
|
|
* which is fresh, shareable and either READY or DONE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct content * content_get_ready(const char *url)
|
|
|
|
{
|
|
|
|
struct content *c;
|
|
|
|
|
|
|
|
for (c = content_list; c; c = c->next) {
|
|
|
|
if (!c->fresh)
|
|
|
|
/* not fresh */
|
|
|
|
continue;
|
|
|
|
if (c->status != CONTENT_STATUS_READY &&
|
|
|
|
c->status != CONTENT_STATUS_DONE)
|
|
|
|
/* not ready or done */
|
|
|
|
continue;
|
|
|
|
if (c->type != CONTENT_UNKNOWN &&
|
|
|
|
handler_map[c->type].no_share &&
|
|
|
|
c->user_list->next)
|
|
|
|
/* not shareable, and has a user already */
|
|
|
|
continue;
|
|
|
|
if (strcmp(c->url, url))
|
|
|
|
continue;
|
|
|
|
return c;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-03 22:46:20 +03:00
|
|
|
/**
|
|
|
|
* Get whether a content can reformat
|
|
|
|
*
|
|
|
|
* \param c content to check
|
|
|
|
* \return whether the content can reformat
|
|
|
|
*/
|
2007-08-07 07:55:18 +04:00
|
|
|
bool content_can_reformat(struct content *c)
|
|
|
|
{
|
2007-03-03 22:46:20 +03:00
|
|
|
return (handler_map[c->type].reformat != NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Initialise the content for the specified type.
|
|
|
|
*
|
2006-02-21 23:49:12 +03:00
|
|
|
* \param c content structure
|
|
|
|
* \param type content_type to initialise to
|
2004-06-11 00:41:26 +04:00
|
|
|
* \param mime_type MIME-type string for this content
|
|
|
|
* \param params array of strings, ordered attribute, value, attribute, ..., 0
|
|
|
|
* \return true on success, false on error and error broadcast to users and
|
|
|
|
* possibly reported
|
|
|
|
*
|
2003-09-08 01:08:13 +04:00
|
|
|
* The type is updated to the given type, and a copy of mime_type is taken. The
|
|
|
|
* status is changed to CONTENT_STATUS_LOADING. CONTENT_MSG_LOADING is sent to
|
|
|
|
* all users. The create function for the type is called to initialise the type
|
|
|
|
* specific parts of the content structure.
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
bool content_set_type(struct content *c, content_type type,
|
2004-05-05 20:33:15 +04:00
|
|
|
const char *mime_type, const char *params[])
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2004-08-11 23:02:32 +04:00
|
|
|
struct content *clone;
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c, intptr_t p1,
|
|
|
|
intptr_t p2, union content_msg_data data);
|
|
|
|
intptr_t p1, p2;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2003-07-15 02:57:45 +04:00
|
|
|
assert(c != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_TYPE_UNKNOWN);
|
|
|
|
assert(type < CONTENT_UNKNOWN);
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2007-03-18 20:04:18 +03:00
|
|
|
LOG(("content %s (%p), type %i", c->url, c, type));
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2005-04-03 14:58:49 +04:00
|
|
|
c->mime_type = talloc_strdup(c, mime_type);
|
2004-06-11 00:41:26 +04:00
|
|
|
if (!c->mime_type) {
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
c->type = type;
|
|
|
|
c->status = CONTENT_STATUS_LOADING;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2004-08-11 23:02:32 +04:00
|
|
|
if (handler_map[type].no_share && c->user_list->next &&
|
|
|
|
c->user_list->next->next) {
|
|
|
|
/* type not shareable, and more than one user: split into
|
|
|
|
* a content per user */
|
2007-08-07 02:17:04 +04:00
|
|
|
const char *referer =
|
|
|
|
c->fetch ? fetch_get_referer(c->fetch) : NULL;
|
2009-07-10 04:26:37 +04:00
|
|
|
struct content *parent =
|
|
|
|
c->fetch ? fetch_get_parent(c->fetch) : NULL;
|
2007-02-03 02:08:13 +03:00
|
|
|
|
2004-08-11 23:02:32 +04:00
|
|
|
while (c->user_list->next->next) {
|
|
|
|
clone = content_create(c->url);
|
|
|
|
if (!clone) {
|
|
|
|
c->type = CONTENT_UNKNOWN;
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
clone->width = c->width;
|
|
|
|
clone->height = c->height;
|
|
|
|
clone->fresh = c->fresh;
|
|
|
|
|
|
|
|
callback = c->user_list->next->next->callback;
|
|
|
|
p1 = c->user_list->next->next->p1;
|
|
|
|
p2 = c->user_list->next->next->p2;
|
2005-01-02 06:58:21 +03:00
|
|
|
if (!content_add_user(clone, callback, p1, p2)) {
|
|
|
|
c->type = CONTENT_UNKNOWN;
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
content_destroy(clone);
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR,
|
|
|
|
msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-11 23:02:32 +04:00
|
|
|
content_remove_user(c, callback, p1, p2);
|
2008-02-03 15:04:48 +03:00
|
|
|
msg_data.new_url = NULL;
|
2004-08-11 23:02:32 +04:00
|
|
|
content_broadcast(clone, CONTENT_MSG_NEWPTR, msg_data);
|
2007-02-03 02:08:13 +03:00
|
|
|
fetchcache_go(clone, referer,
|
2007-01-27 23:58:20 +03:00
|
|
|
callback, p1, p2,
|
2005-01-25 02:02:37 +03:00
|
|
|
clone->width, clone->height,
|
2009-07-10 04:26:37 +04:00
|
|
|
0, 0, false, parent);
|
2004-08-11 23:02:32 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
if (handler_map[type].create) {
|
|
|
|
if (!handler_map[type].create(c, params)) {
|
2004-06-11 03:55:23 +04:00
|
|
|
c->type = CONTENT_UNKNOWN;
|
2004-06-11 00:41:26 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
content_broadcast(c, CONTENT_MSG_LOADING, msg_data);
|
|
|
|
return true;
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-05 19:03:59 +04:00
|
|
|
/**
|
|
|
|
* Updates content with new status.
|
|
|
|
*
|
|
|
|
* The textual status contained in the content is updated with given string.
|
|
|
|
*
|
|
|
|
* \param status_message new textual status
|
|
|
|
*/
|
2004-06-21 19:09:59 +04:00
|
|
|
|
2004-06-05 19:03:59 +04:00
|
|
|
void content_set_status(struct content *c, const char *status_message, ...)
|
|
|
|
{
|
|
|
|
va_list ap;
|
|
|
|
int len;
|
|
|
|
|
|
|
|
va_start(ap, status_message);
|
2007-01-13 03:21:15 +03:00
|
|
|
if ((len = vsnprintf(c->sub_status, sizeof (c->sub_status),
|
2005-07-06 02:43:38 +04:00
|
|
|
status_message, ap)) < 0 ||
|
2007-01-13 03:21:15 +03:00
|
|
|
(int)sizeof (c->sub_status) <= len)
|
|
|
|
c->sub_status[sizeof (c->sub_status) - 1] = '\0';
|
2004-06-05 19:03:59 +04:00
|
|
|
va_end(ap);
|
2007-01-13 03:21:15 +03:00
|
|
|
|
|
|
|
content_update_status(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void content_update_status(struct content *c)
|
|
|
|
{
|
|
|
|
char token[20];
|
|
|
|
const char *status;
|
2007-01-30 18:32:31 +03:00
|
|
|
unsigned int time;
|
2007-01-13 03:21:15 +03:00
|
|
|
|
|
|
|
snprintf(token, sizeof token, "HTTP%li", c->http_code);
|
|
|
|
status = messages_get(token);
|
|
|
|
if (status == token)
|
|
|
|
status = token + 4;
|
|
|
|
|
|
|
|
if (c->status == CONTENT_STATUS_TYPE_UNKNOWN ||
|
|
|
|
c->status == CONTENT_STATUS_LOADING ||
|
|
|
|
c->status == CONTENT_STATUS_READY)
|
2007-01-30 18:32:31 +03:00
|
|
|
time = wallclock() - c->time;
|
2007-01-13 03:21:15 +03:00
|
|
|
else
|
|
|
|
time = c->time;
|
|
|
|
|
|
|
|
snprintf(c->status_message, sizeof (c->status_message),
|
|
|
|
"%s (%.1fs) %s", status,
|
2007-01-30 18:32:31 +03:00
|
|
|
(float) time / 100, c->sub_status);
|
2007-01-13 03:21:15 +03:00
|
|
|
/* LOG(("%s", c->status_message)); */
|
2004-06-05 19:03:59 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Process a block of source data.
|
|
|
|
*
|
|
|
|
* Calls the process_data function for the content.
|
2004-06-11 00:41:26 +04:00
|
|
|
*
|
2006-02-21 23:49:12 +03:00
|
|
|
* \param c content structure
|
2004-06-11 00:41:26 +04:00
|
|
|
* \param data new data to process
|
|
|
|
* \param size size of data
|
|
|
|
* \return true on success, false on error and error broadcast to users and
|
|
|
|
* possibly reported
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2004-06-22 21:37:51 +04:00
|
|
|
bool content_process_data(struct content *c, const char *data,
|
|
|
|
unsigned int size)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2004-06-11 00:41:26 +04:00
|
|
|
char *source_data;
|
|
|
|
union content_msg_data msg_data;
|
2005-04-05 06:36:33 +04:00
|
|
|
unsigned int extra_space;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
|
|
|
assert(c);
|
|
|
|
assert(c->type < HANDLER_MAP_COUNT);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_LOADING);
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2005-04-05 06:36:33 +04:00
|
|
|
if ((c->source_size + size) > c->source_allocated) {
|
|
|
|
extra_space = (c->source_size + size) / 4;
|
|
|
|
if (extra_space < 65536)
|
|
|
|
extra_space = 65536;
|
|
|
|
source_data = talloc_realloc(c, c->source_data, char,
|
|
|
|
c->source_size + size + extra_space);
|
|
|
|
if (!source_data) {
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
msg_data.error = messages_get("NoMemory");
|
|
|
|
content_broadcast(c, CONTENT_MSG_ERROR, msg_data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
c->source_data = source_data;
|
|
|
|
c->source_allocated = c->source_size + size + extra_space;
|
2004-06-11 00:41:26 +04:00
|
|
|
}
|
2004-03-11 05:19:14 +03:00
|
|
|
memcpy(c->source_data + c->source_size, data, size);
|
|
|
|
c->source_size += size;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
|
|
|
if (handler_map[c->type].process_data) {
|
2004-06-22 21:37:51 +04:00
|
|
|
if (!handler_map[c->type].process_data(c,
|
2005-04-05 06:36:33 +04:00
|
|
|
c->source_data + c->source_size - size, size)) {
|
2004-06-11 00:41:26 +04:00
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* All data has arrived, convert for display.
|
|
|
|
*
|
|
|
|
* Calls the convert function for the content.
|
|
|
|
*
|
|
|
|
* - If the conversion succeeds, but there is still some processing required
|
|
|
|
* (eg. loading images), the content gets status CONTENT_STATUS_READY, and a
|
|
|
|
* CONTENT_MSG_READY is sent to all users.
|
|
|
|
* - If the conversion succeeds and is complete, the content gets status
|
2004-02-25 18:12:58 +03:00
|
|
|
* CONTENT_STATUS_DONE, and CONTENT_MSG_READY then CONTENT_MSG_DONE are sent.
|
2004-06-11 00:41:26 +04:00
|
|
|
* - If the conversion fails, CONTENT_MSG_ERROR is sent. The content will soon
|
|
|
|
* be destroyed and must no longer be used.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
void content_convert(struct content *c, int width, int height)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2004-06-11 00:41:26 +04:00
|
|
|
union content_msg_data msg_data;
|
2005-04-05 06:36:33 +04:00
|
|
|
char *source_data;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
|
|
|
assert(c);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->type < HANDLER_MAP_COUNT);
|
|
|
|
assert(c->status == CONTENT_STATUS_LOADING);
|
2005-07-06 02:43:38 +04:00
|
|
|
assert(!c->locked);
|
2007-03-18 20:04:18 +03:00
|
|
|
LOG(("content %s (%p)", c->url, c));
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2005-04-05 06:36:33 +04:00
|
|
|
if (c->source_allocated != c->source_size) {
|
|
|
|
source_data = talloc_realloc(c, c->source_data, char,
|
|
|
|
c->source_size);
|
|
|
|
if (source_data) {
|
|
|
|
c->source_data = source_data;
|
|
|
|
c->source_allocated = c->source_size;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-07-06 02:43:38 +04:00
|
|
|
c->locked = true;
|
2003-04-15 21:53:00 +04:00
|
|
|
c->available_width = width;
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].convert) {
|
2004-06-11 00:41:26 +04:00
|
|
|
if (!handler_map[c->type].convert(c, width, height)) {
|
|
|
|
c->status = CONTENT_STATUS_ERROR;
|
2005-07-06 02:43:38 +04:00
|
|
|
c->locked = false;
|
2004-03-11 05:19:14 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
2005-07-06 02:43:38 +04:00
|
|
|
c->locked = false;
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_READY ||
|
|
|
|
c->status == CONTENT_STATUS_DONE);
|
2004-06-11 00:41:26 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_READY, msg_data);
|
2004-02-25 18:12:58 +03:00
|
|
|
if (c->status == CONTENT_STATUS_DONE)
|
2007-01-13 03:21:15 +03:00
|
|
|
content_set_done(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Put a content in status CONTENT_STATUS_DONE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void content_set_done(struct content *c)
|
|
|
|
{
|
|
|
|
union content_msg_data msg_data;
|
|
|
|
|
|
|
|
c->status = CONTENT_STATUS_DONE;
|
2007-01-30 18:32:31 +03:00
|
|
|
c->time = wallclock() - c->time;
|
2007-01-13 03:21:15 +03:00
|
|
|
content_update_status(c);
|
|
|
|
content_broadcast(c, CONTENT_MSG_DONE, msg_data);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Reformat to new size.
|
|
|
|
*
|
|
|
|
* Calls the reformat function for the content.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
void content_reformat(struct content *c, int width, int height)
|
2003-02-09 15:58:15 +03:00
|
|
|
{
|
2004-04-25 03:42:32 +04:00
|
|
|
union content_msg_data data;
|
2003-02-09 15:58:15 +03:00
|
|
|
assert(c != 0);
|
2003-06-17 23:24:21 +04:00
|
|
|
assert(c->status == CONTENT_STATUS_READY ||
|
|
|
|
c->status == CONTENT_STATUS_DONE);
|
2005-07-06 02:43:38 +04:00
|
|
|
assert(!c->locked);
|
2007-03-18 20:04:18 +03:00
|
|
|
LOG(("%p %s", c, c->url));
|
2005-07-06 02:43:38 +04:00
|
|
|
c->locked = true;
|
2003-04-15 21:53:00 +04:00
|
|
|
c->available_width = width;
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].reformat) {
|
|
|
|
handler_map[c->type].reformat(c, width, height);
|
2004-04-25 03:42:32 +04:00
|
|
|
content_broadcast(c, CONTENT_MSG_REFORMAT, data);
|
2004-03-11 05:19:14 +03:00
|
|
|
}
|
2005-07-06 02:43:38 +04:00
|
|
|
c->locked = false;
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
/**
|
2004-06-21 19:09:59 +04:00
|
|
|
* Clean unused contents from the content_list.
|
|
|
|
*
|
2004-06-11 00:41:26 +04:00
|
|
|
* Destroys any contents in the content_list with no users or in
|
2004-06-21 19:09:59 +04:00
|
|
|
* CONTENT_STATUS_ERROR. Fresh contents in CONTENT_STATUS_DONE may be kept even
|
|
|
|
* with no users.
|
|
|
|
*
|
|
|
|
* Each content is also checked for stop requests.
|
2004-06-11 00:41:26 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_clean(void)
|
|
|
|
{
|
2004-06-21 19:09:59 +04:00
|
|
|
unsigned int size;
|
|
|
|
struct content *c, *next, *prev;
|
2004-06-11 00:41:26 +04:00
|
|
|
|
2004-06-21 19:09:59 +04:00
|
|
|
/* destroy unused stale contents and contents with errors */
|
2004-06-11 00:41:26 +04:00
|
|
|
for (c = content_list; c; c = next) {
|
|
|
|
next = c->next;
|
2004-06-21 19:09:59 +04:00
|
|
|
|
2005-07-06 02:43:38 +04:00
|
|
|
/* this function must not be called from a content function */
|
|
|
|
assert(!c->locked);
|
|
|
|
|
2004-06-21 19:09:59 +04:00
|
|
|
if (c->user_list->next && c->status != CONTENT_STATUS_ERROR)
|
|
|
|
/* content has users */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
if (c->fresh && c->status == CONTENT_STATUS_DONE)
|
|
|
|
/* content is fresh */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* content can be destroyed */
|
|
|
|
content_destroy(c);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* check for pending stops */
|
|
|
|
for (c = content_list; c; c = c->next) {
|
|
|
|
if (c->status == CONTENT_STATUS_READY)
|
|
|
|
content_stop_check(c);
|
|
|
|
}
|
|
|
|
|
2004-07-30 20:16:07 +04:00
|
|
|
/* attempt to shrink the memory cache (unused fresh contents) */
|
2004-06-21 19:09:59 +04:00
|
|
|
size = 0;
|
|
|
|
next = 0;
|
|
|
|
for (c = content_list; c; c = c->next) {
|
|
|
|
next = c;
|
2008-07-07 18:05:29 +04:00
|
|
|
c->talloc_size = talloc_total_size(c);
|
|
|
|
size += c->size + c->talloc_size;
|
2004-06-21 19:09:59 +04:00
|
|
|
}
|
|
|
|
for (c = next; c && (unsigned int) option_memory_cache_size < size;
|
|
|
|
c = prev) {
|
|
|
|
prev = c->prev;
|
|
|
|
if (c->user_list->next)
|
|
|
|
continue;
|
2008-07-07 18:05:29 +04:00
|
|
|
size -= c->size + c->talloc_size;
|
2004-06-21 19:09:59 +04:00
|
|
|
content_destroy(c);
|
2004-06-11 00:41:26 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-02-09 15:58:15 +03:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Destroy and free a content.
|
|
|
|
*
|
|
|
|
* Calls the destroy function for the content, and frees the structure.
|
2003-02-09 15:58:15 +03:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_destroy(struct content *c)
|
|
|
|
{
|
2004-01-26 17:16:23 +03:00
|
|
|
assert(c);
|
2003-06-17 23:24:21 +04:00
|
|
|
LOG(("content %p %s", c, c->url));
|
2005-07-06 02:43:38 +04:00
|
|
|
assert(!c->locked);
|
2004-01-26 17:16:23 +03:00
|
|
|
|
2004-06-21 19:09:59 +04:00
|
|
|
if (c->fetch)
|
|
|
|
fetch_abort(c->fetch);
|
2004-01-26 17:16:23 +03:00
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
if (c->next)
|
|
|
|
c->next->prev = c->prev;
|
|
|
|
if (c->prev)
|
|
|
|
c->prev->next = c->next;
|
|
|
|
else
|
|
|
|
content_list = c->next;
|
|
|
|
|
2004-03-11 05:19:14 +03:00
|
|
|
if (c->type < HANDLER_MAP_COUNT && handler_map[c->type].destroy)
|
2003-06-17 23:24:21 +04:00
|
|
|
handler_map[c->type].destroy(c);
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_free(c);
|
2003-02-09 15:58:15 +03:00
|
|
|
}
|
|
|
|
|
2003-05-10 15:15:49 +04:00
|
|
|
|
2004-01-23 23:46:29 +03:00
|
|
|
/**
|
|
|
|
* Reset a content.
|
|
|
|
*
|
|
|
|
* Calls the destroy function for the content, but does not free
|
|
|
|
* the structure.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void content_reset(struct content *c)
|
|
|
|
{
|
|
|
|
assert(c != 0);
|
|
|
|
LOG(("content %p %s", c, c->url));
|
2005-07-06 02:43:38 +04:00
|
|
|
assert(!c->locked);
|
2004-03-11 05:19:14 +03:00
|
|
|
if (c->type < HANDLER_MAP_COUNT && handler_map[c->type].destroy)
|
2004-01-23 23:46:29 +03:00
|
|
|
handler_map[c->type].destroy(c);
|
|
|
|
c->type = CONTENT_UNKNOWN;
|
|
|
|
c->status = CONTENT_STATUS_TYPE_UNKNOWN;
|
2006-12-04 01:34:26 +03:00
|
|
|
c->size = 0;
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_free(c->mime_type);
|
2004-01-23 23:46:29 +03:00
|
|
|
c->mime_type = 0;
|
2008-02-27 21:38:41 +03:00
|
|
|
talloc_free(c->refresh);
|
|
|
|
c->refresh = 0;
|
|
|
|
talloc_free(c->title);
|
|
|
|
c->title = 0;
|
|
|
|
talloc_free(c->source_data);
|
|
|
|
c->source_data = 0;
|
|
|
|
c->source_size = c->source_allocated = 0;
|
2004-01-23 23:46:29 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-07-30 20:16:07 +04:00
|
|
|
/**
|
|
|
|
* Free all contents in the content_list.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void content_quit(void)
|
|
|
|
{
|
|
|
|
bool progress = true;
|
|
|
|
struct content *c, *next;
|
|
|
|
|
|
|
|
while (content_list && progress) {
|
|
|
|
progress = false;
|
|
|
|
for (c = content_list; c; c = next) {
|
2006-09-02 19:52:41 +04:00
|
|
|
assert(c->next != c);
|
2004-07-30 20:16:07 +04:00
|
|
|
next = c->next;
|
|
|
|
|
|
|
|
if (c->user_list->next &&
|
|
|
|
c->status != CONTENT_STATUS_ERROR)
|
|
|
|
/* content has users */
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/* content can be destroyed */
|
|
|
|
content_destroy(c);
|
|
|
|
progress = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (content_list) {
|
|
|
|
LOG(("bug: some contents could not be destroyed"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-05-10 15:15:49 +04:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Display content on screen.
|
|
|
|
*
|
|
|
|
* Calls the redraw function for the content, if it exists.
|
2009-02-02 17:06:51 +03:00
|
|
|
*
|
|
|
|
* \param c content
|
|
|
|
* \param x coordinate for top-left of redraw
|
|
|
|
* \param y coordinate for top-left of redraw
|
|
|
|
* \param width available width (not used for HTML redraw)
|
|
|
|
* \param height available height (not used for HTML redraw)
|
|
|
|
* \param clip_x0 clip rectangle left
|
|
|
|
* \param clip_y0 clip rectangle top
|
|
|
|
* \param clip_x1 clip rectangle right
|
|
|
|
* \param clip_y1 clip rectangle bottom
|
|
|
|
* \param scale scale for redraw
|
|
|
|
* \param background_colour the background colour
|
|
|
|
* \return true if successful, false otherwise
|
|
|
|
*
|
|
|
|
* x, y and clip_* are coordinates from the top left of the canvas area.
|
|
|
|
*
|
|
|
|
* The top left corner of the clip rectangle is (clip_x0, clip_y0) and
|
|
|
|
* the bottom right corner of the clip rectangle is (clip_x1, clip_y1).
|
|
|
|
* Units for x, y and clip_* are pixels.
|
2003-05-10 15:15:49 +04:00
|
|
|
*/
|
|
|
|
|
2004-08-11 20:26:13 +04:00
|
|
|
bool content_redraw(struct content *c, int x, int y,
|
2004-06-11 00:41:26 +04:00
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2008-09-29 02:37:13 +04:00
|
|
|
float scale, colour background_colour)
|
2003-05-10 15:15:49 +04:00
|
|
|
{
|
|
|
|
assert(c != 0);
|
2007-03-19 02:48:12 +03:00
|
|
|
// LOG(("%p %s", c, c->url));
|
2005-07-06 02:43:38 +04:00
|
|
|
if (c->locked)
|
|
|
|
/* not safe to attempt redraw */
|
|
|
|
return true;
|
2004-03-11 05:19:14 +03:00
|
|
|
if (handler_map[c->type].redraw)
|
2004-08-11 20:26:13 +04:00
|
|
|
return handler_map[c->type].redraw(c, x, y, width, height,
|
2006-02-21 23:49:12 +03:00
|
|
|
clip_x0, clip_y0, clip_x1, clip_y1, scale,
|
|
|
|
background_colour);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display content on screen with optional tiling.
|
|
|
|
*
|
|
|
|
* Calls the redraw_tile function for the content, or emulates it with the
|
|
|
|
* redraw function if it doesn't exist.
|
|
|
|
*/
|
|
|
|
|
|
|
|
bool content_redraw_tiled(struct content *c, int x, int y,
|
|
|
|
int width, int height,
|
|
|
|
int clip_x0, int clip_y0, int clip_x1, int clip_y1,
|
2008-09-29 02:37:13 +04:00
|
|
|
float scale, colour background_colour,
|
2006-02-21 23:49:12 +03:00
|
|
|
bool repeat_x, bool repeat_y)
|
|
|
|
{
|
|
|
|
int x0, y0, x1, y1;
|
|
|
|
|
|
|
|
assert(c != 0);
|
|
|
|
|
2007-03-19 02:48:12 +03:00
|
|
|
// LOG(("%p %s", c, c->url));
|
2007-03-18 20:04:18 +03:00
|
|
|
|
2006-02-21 23:49:12 +03:00
|
|
|
if (c->locked)
|
|
|
|
/* not safe to attempt redraw */
|
|
|
|
return true;
|
|
|
|
if (handler_map[c->type].redraw_tiled) {
|
|
|
|
return handler_map[c->type].redraw_tiled(c, x, y, width, height,
|
|
|
|
clip_x0, clip_y0, clip_x1, clip_y1, scale,
|
|
|
|
background_colour, repeat_x, repeat_y);
|
|
|
|
} else {
|
|
|
|
/* ensure we have a redrawable content */
|
|
|
|
if ((!handler_map[c->type].redraw) || (width == 0) ||
|
|
|
|
(height == 0))
|
|
|
|
return true;
|
|
|
|
/* simple optimisation for no repeat (common for backgrounds) */
|
|
|
|
if ((!repeat_x) || (!repeat_y))
|
|
|
|
return handler_map[c->type].redraw(c, x, y, width,
|
|
|
|
height, clip_x0, clip_y0, clip_x1, clip_y1,
|
|
|
|
scale, background_colour);
|
|
|
|
/* find the redraw boundaries to loop within*/
|
|
|
|
x0 = x;
|
|
|
|
if (repeat_x) {
|
|
|
|
for (; x0 > clip_x0; x0 -= width);
|
|
|
|
x1 = clip_x1;
|
|
|
|
} else {
|
|
|
|
x1 = x + 1;
|
|
|
|
}
|
|
|
|
y0 = y;
|
|
|
|
if (repeat_y) {
|
|
|
|
for (; y0 > clip_y0; y0 -= height);
|
|
|
|
y1 = clip_y1;
|
|
|
|
} else {
|
|
|
|
y1 = y + 1;
|
|
|
|
}
|
|
|
|
/* repeatedly plot our content */
|
|
|
|
for (y = y0; y < y1; y += height)
|
|
|
|
for (x = x0; x < x1; x += width)
|
|
|
|
if (!handler_map[c->type].redraw(c, x, y,
|
|
|
|
width, height,
|
|
|
|
clip_x0, clip_y0,
|
|
|
|
clip_x1, clip_y1,
|
|
|
|
scale, background_colour))
|
|
|
|
return false;
|
|
|
|
}
|
2004-08-11 20:26:13 +04:00
|
|
|
return true;
|
2003-05-10 15:15:49 +04:00
|
|
|
}
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Register a user for callbacks.
|
|
|
|
*
|
2006-02-21 23:49:12 +03:00
|
|
|
* \param c the content to register
|
2005-01-14 01:42:39 +03:00
|
|
|
* \param callback the callback function
|
|
|
|
* \param p1, p2 callback private data
|
|
|
|
* \return true on success, false otherwise on memory exhaustion
|
2005-01-02 06:58:21 +03:00
|
|
|
*
|
2003-09-08 01:08:13 +04:00
|
|
|
* The callback will be called with p1 and p2 when content_broadcast() is
|
|
|
|
* called with the content.
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
2005-01-02 06:58:21 +03:00
|
|
|
bool content_add_user(struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t p2)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user;
|
2005-01-02 06:58:21 +03:00
|
|
|
|
2007-03-18 20:04:18 +03:00
|
|
|
LOG(("content %s (%p), user %p 0x%" PRIxPTR " 0x%" PRIxPTR,
|
|
|
|
c->url, c, callback, p1, p2));
|
2005-04-03 14:58:49 +04:00
|
|
|
user = talloc(c, struct content_user);
|
2005-01-14 01:42:39 +03:00
|
|
|
if (!user)
|
2005-01-02 06:58:21 +03:00
|
|
|
return false;
|
2003-06-17 23:24:21 +04:00
|
|
|
user->callback = callback;
|
|
|
|
user->p1 = p1;
|
|
|
|
user->p2 = p2;
|
2004-06-21 03:09:52 +04:00
|
|
|
user->stop = false;
|
2003-06-17 23:24:21 +04:00
|
|
|
user->next = c->user_list->next;
|
|
|
|
c->user_list->next = user;
|
2005-01-02 06:58:21 +03:00
|
|
|
|
|
|
|
return true;
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-23 19:41:50 +04:00
|
|
|
/**
|
|
|
|
* Search the users of a content for the specified user.
|
|
|
|
*
|
|
|
|
* \return a content_user struct for the user, or 0 if not found
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct content_user * content_find_user(struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t p2)
|
2004-06-23 19:41:50 +04:00
|
|
|
{
|
|
|
|
struct content_user *user;
|
|
|
|
|
|
|
|
/* user_list starts with a sentinel */
|
|
|
|
for (user = c->user_list; user->next &&
|
|
|
|
!(user->next->callback == callback &&
|
|
|
|
user->next->p1 == p1 &&
|
|
|
|
user->next->p2 == p2); user = user->next)
|
|
|
|
;
|
|
|
|
return user->next;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-06-17 23:24:21 +04:00
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Remove a callback user.
|
|
|
|
*
|
|
|
|
* The callback function, p1, and p2 must be identical to those passed to
|
|
|
|
* content_add_user().
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
|
|
|
void content_remove_user(struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t p2)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user, *next;
|
2007-03-18 20:04:18 +03:00
|
|
|
LOG(("content %s (%p), user %p 0x%" PRIxPTR " 0x%" PRIxPTR,
|
|
|
|
c->url, c, callback, p1, p2));
|
2003-06-17 23:24:21 +04:00
|
|
|
|
|
|
|
/* user_list starts with a sentinel */
|
|
|
|
for (user = c->user_list; user->next != 0 &&
|
|
|
|
!(user->next->callback == callback &&
|
|
|
|
user->next->p1 == p1 &&
|
|
|
|
user->next->p2 == p2); user = user->next)
|
|
|
|
;
|
|
|
|
if (user->next == 0) {
|
|
|
|
LOG(("user not found in list"));
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
next = user->next;
|
|
|
|
user->next = next->next;
|
2005-04-03 14:58:49 +04:00
|
|
|
talloc_free(next);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
2003-09-08 01:08:13 +04:00
|
|
|
* Send a message to all users.
|
2003-06-17 23:24:21 +04:00
|
|
|
*/
|
|
|
|
|
2004-04-25 03:42:32 +04:00
|
|
|
void content_broadcast(struct content *c, content_msg msg,
|
|
|
|
union content_msg_data data)
|
2003-06-17 23:24:21 +04:00
|
|
|
{
|
|
|
|
struct content_user *user, *next;
|
2005-01-13 23:26:16 +03:00
|
|
|
assert(c);
|
2007-03-19 02:48:12 +03:00
|
|
|
// LOG(("%p %s -> %d", c, c->url, msg));
|
2003-06-17 23:24:21 +04:00
|
|
|
for (user = c->user_list->next; user != 0; user = next) {
|
|
|
|
next = user->next; /* user may be destroyed during callback */
|
|
|
|
if (user->callback != 0)
|
2004-04-25 03:42:32 +04:00
|
|
|
user->callback(msg, c, user->p1, user->p2, data);
|
2003-06-17 23:24:21 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2003-07-15 02:57:45 +04:00
|
|
|
|
2004-06-21 03:09:52 +04:00
|
|
|
/**
|
|
|
|
* Stop a content loading.
|
|
|
|
*
|
|
|
|
* May only be called in CONTENT_STATUS_READY only. If all users have requested
|
|
|
|
* stop, the loading is stopped and the content placed in CONTENT_STATUS_DONE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void content_stop(struct content *c,
|
2005-08-21 16:04:18 +04:00
|
|
|
void (*callback)(content_msg msg, struct content *c,
|
|
|
|
intptr_t p1, intptr_t p2, union content_msg_data data),
|
|
|
|
intptr_t p1, intptr_t p2)
|
2004-06-21 03:09:52 +04:00
|
|
|
{
|
|
|
|
struct content_user *user;
|
|
|
|
|
|
|
|
assert(c->status == CONTENT_STATUS_READY);
|
|
|
|
|
2004-06-23 19:41:50 +04:00
|
|
|
user = content_find_user(c, callback, p1, p2);
|
|
|
|
if (!user) {
|
2004-06-21 03:09:52 +04:00
|
|
|
LOG(("user not found in list"));
|
|
|
|
assert(0);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2005-08-21 16:04:18 +04:00
|
|
|
LOG(("%p %s: stop user %p 0x%" PRIxPTR " 0x%" PRIxPTR,
|
|
|
|
c, c->url, callback, p1, p2));
|
2004-06-21 03:09:52 +04:00
|
|
|
user->stop = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Check if all users have requested a stop, and do it if so.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void content_stop_check(struct content *c)
|
|
|
|
{
|
|
|
|
struct content_user *user;
|
|
|
|
union content_msg_data data;
|
|
|
|
|
|
|
|
assert(c->status == CONTENT_STATUS_READY);
|
|
|
|
|
|
|
|
/* user_list starts with a sentinel */
|
|
|
|
for (user = c->user_list->next; user; user = user->next)
|
|
|
|
if (!user->stop)
|
|
|
|
return;
|
|
|
|
|
2004-06-21 19:09:59 +04:00
|
|
|
LOG(("%p %s", c, c->url));
|
|
|
|
|
2004-06-21 03:09:52 +04:00
|
|
|
/* all users have requested stop */
|
|
|
|
assert(handler_map[c->type].stop);
|
|
|
|
handler_map[c->type].stop(c);
|
|
|
|
assert(c->status == CONTENT_STATUS_DONE);
|
|
|
|
|
|
|
|
content_set_status(c, messages_get("Stopped"));
|
|
|
|
content_broadcast(c, CONTENT_MSG_DONE, data);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/**
|
2004-08-12 02:08:26 +04:00
|
|
|
* A window containing the content has been opened.
|
2003-09-08 01:08:13 +04:00
|
|
|
*
|
2006-02-21 23:49:12 +03:00
|
|
|
* \param c content that has been opened
|
|
|
|
* \param bw browser window containing the content
|
|
|
|
* \param page content of type CONTENT_HTML containing c, or 0 if not an
|
|
|
|
* object within a page
|
2005-10-31 00:22:19 +03:00
|
|
|
* \param index index in page->data.html.object, or 0 if not an object
|
2006-02-21 23:49:12 +03:00
|
|
|
* \param box box containing c, or 0 if not an object
|
2005-10-31 00:22:19 +03:00
|
|
|
* \param params object parameters, or 0 if not an object
|
|
|
|
*
|
2004-08-12 02:08:26 +04:00
|
|
|
* Calls the open function for the content.
|
2003-09-08 01:08:13 +04:00
|
|
|
*/
|
|
|
|
|
2004-08-12 02:08:26 +04:00
|
|
|
void content_open(struct content *c, struct browser_window *bw,
|
2005-10-31 00:22:19 +03:00
|
|
|
struct content *page, unsigned int index, struct box *box,
|
2004-08-12 02:08:26 +04:00
|
|
|
struct object_params *params)
|
2003-07-15 02:57:45 +04:00
|
|
|
{
|
|
|
|
assert(c != 0);
|
|
|
|
assert(c->type < CONTENT_UNKNOWN);
|
2007-03-18 20:04:18 +03:00
|
|
|
LOG(("content %p %s", c, c->url));
|
2004-08-12 02:08:26 +04:00
|
|
|
if (handler_map[c->type].open)
|
2005-10-31 00:22:19 +03:00
|
|
|
handler_map[c->type].open(c, bw, page, index, box, params);
|
2003-07-15 02:57:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2003-09-08 01:08:13 +04:00
|
|
|
/**
|
2004-08-12 02:08:26 +04:00
|
|
|
* The window containing the content has been closed.
|
2003-09-08 01:08:13 +04:00
|
|
|
*
|
2004-08-12 02:08:26 +04:00
|
|
|
* Calls the close function for the content.
|
2003-09-08 01:08:13 +04:00
|
|
|
*/
|
|
|
|
|
2004-08-12 02:08:26 +04:00
|
|
|
void content_close(struct content *c)
|
2003-07-15 02:57:45 +04:00
|
|
|
{
|
|
|
|
assert(c != 0);
|
|
|
|
assert(c->type < CONTENT_UNKNOWN);
|
2007-03-18 20:04:18 +03:00
|
|
|
LOG(("content %p %s", c, c->url));
|
2004-08-12 02:08:26 +04:00
|
|
|
if (handler_map[c->type].close)
|
|
|
|
handler_map[c->type].close(c);
|
2003-07-15 02:57:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-06-11 00:41:26 +04:00
|
|
|
void content_add_error(struct content *c, const char *token,
|
|
|
|
unsigned int line)
|
|
|
|
{
|
|
|
|
}
|