Clean up content_factory_register_handler API -- content handlers no longer use the mime type, so don't require it to be interned up front

svn path=/trunk/netsurf/; revision=12796
This commit is contained in:
John Mark Bell 2011-09-15 22:31:16 +00:00
parent 50508a6e75
commit 3d71da088b
14 changed files with 53 additions and 242 deletions

View File

@ -116,7 +116,8 @@ nserror amiga_dt_anim_init(void)
if(node)
{
error = content_factory_register_handler(type,
error = content_factory_register_handler(
lwc_string_data(type),
&amiga_dt_anim_content_handler);
if (error != NSERROR_OK)

View File

@ -103,7 +103,8 @@ nserror amiga_dt_picture_init(void)
if(node)
{
error = content_factory_register_handler(type,
error = content_factory_register_handler(
lwc_string_data(type),
&amiga_dt_picture_content_handler);
if (error != NSERROR_OK)

View File

@ -100,7 +100,8 @@ nserror amiga_dt_sound_init(void)
if(node)
{
error = content_factory_register_handler(type,
error = content_factory_register_handler(
lwc_string_data(type),
&amiga_dt_sound_content_handler);
if (error != NSERROR_OK)

View File

@ -97,47 +97,8 @@ static const char *amiga_icon_types[] = {
"image/x-amiga-icon"
};
static lwc_string *amiga_icon_mime_types[NOF_ELEMENTS(amiga_icon_types)];
nserror amiga_icon_init(void)
{
uint32_t i;
lwc_error lerror;
nserror error;
for (i = 0; i < NOF_ELEMENTS(amiga_icon_mime_types); i++) {
lerror = lwc_intern_string(amiga_icon_types[i],
strlen(amiga_icon_types[i]),
&amiga_icon_mime_types[i]);
if (lerror != lwc_error_ok) {
error = NSERROR_NOMEM;
goto error;
}
error = content_factory_register_handler(
amiga_icon_mime_types[i],
&amiga_icon_content_handler);
if (error != NSERROR_OK)
goto error;
}
return NSERROR_OK;
error:
amiga_icon_fini();
return error;
}
void amiga_icon_fini(void)
{
uint32_t i;
for (i = 0; i < NOF_ELEMENTS(amiga_icon_mime_types); i++) {
if (amiga_icon_mime_types[i] != NULL)
lwc_string_unref(amiga_icon_mime_types[i]);
}
}
CONTENT_FACTORY_REGISTER_TYPES(amiga_icon, amiga_icon_types,
amiga_icon_content_handler)
nserror amiga_icon_create(const content_handler *handler,
lwc_string *imime_type, const http_parameter *params,

View File

@ -81,7 +81,8 @@ nserror amiga_plugin_hack_init(void)
{
LOG(("plugin_hack registered %s\n",lwc_string_data(type)));
error = content_factory_register_handler(type,
error = content_factory_register_handler(
lwc_string_data(type),
&amiga_plugin_hack_content_handler);
if (error != NSERROR_OK)

View File

@ -77,13 +77,7 @@ static nserror register_for_type( NSString *mime )
return NSERROR_OK;
#endif
lwc_string *string = NULL;
lwc_error lerror = lwc_intern_string( type, strlen( type ), &string );
if (lerror != lwc_error_ok) return NSERROR_NOMEM;
nserror error = content_factory_register_handler( string, &apple_image_content_handler );
lwc_string_unref( string );
nserror error = content_factory_register_handler( type, &apple_image_content_handler );
if (error != NSERROR_OK) return error;
return NSERROR_OK;

View File

@ -71,14 +71,20 @@ void content_factory_fini(void)
*
* \note Latest registration for a MIME type wins
*/
nserror content_factory_register_handler(lwc_string *mime_type,
nserror content_factory_register_handler(const char *mime_type,
const content_handler *handler)
{
lwc_string *imime_type;
lwc_error lerror;
content_handler_entry *entry;
bool match;
lerror = lwc_intern_string(mime_type, strlen(mime_type), &imime_type);
if (lerror != lwc_error_ok)
return NSERROR_NOMEM;
for (entry = content_handlers; entry != NULL; entry = entry->next) {
if (lwc_string_caseless_isequal(mime_type, entry->mime_type,
if (lwc_string_caseless_isequal(imime_type, entry->mime_type,
&match) == lwc_error_ok && match)
break;
}
@ -91,7 +97,9 @@ nserror content_factory_register_handler(lwc_string *mime_type,
entry->next = content_handlers;
content_handlers = entry;
entry->mime_type = lwc_string_ref(mime_type);
entry->mime_type = imime_type;
} else {
lwc_string_unref(imime_type);
}
entry->handler = handler;

View File

@ -28,25 +28,14 @@
#define CONTENT_FACTORY_REGISTER_TYPES(HNAME, HTYPELIST, HHANDLER) \
\
static lwc_string *HNAME##_mime_types[NOF_ELEMENTS(HTYPELIST)]; \
\
nserror HNAME##_init(void) \
{ \
uint32_t i; \
lwc_error lerror; \
nserror error; \
\
for (i = 0; i < NOF_ELEMENTS(HNAME##_mime_types); i++) { \
lerror = lwc_intern_string(HTYPELIST[i], \
strlen(HTYPELIST[i]), \
&HNAME##_mime_types[i]); \
if (lerror != lwc_error_ok) { \
error = NSERROR_NOMEM; \
goto error; \
} \
\
for (i = 0; i < NOF_ELEMENTS(HTYPELIST); i++) { \
error = content_factory_register_handler( \
HNAME##_mime_types[i], \
HTYPELIST[i], \
&HHANDLER); \
if (error != NSERROR_OK) \
goto error; \
@ -59,16 +48,9 @@ error: \
\
return error; \
} \
\
/* Pointless */ \
void HNAME##_fini(void) \
{ \
uint32_t i; \
\
for (i = 0; i < NOF_ELEMENTS(HNAME##_mime_types); i++) { \
if (HNAME##_mime_types[i] != NULL) { \
lwc_string_unref(HNAME##_mime_types[i]); \
} \
} \
}
struct content;
@ -78,7 +60,7 @@ typedef struct content_handler content_handler;
void content_factory_fini(void);
nserror content_factory_register_handler(lwc_string *mime_type,
nserror content_factory_register_handler(const char *mime_type,
const content_handler *handler);
struct content *content_factory_create_content(struct llcache_handle *llcache,

View File

@ -89,7 +89,6 @@ static const content_handler css_content_handler = {
.no_share = false,
};
static lwc_string *css_mime_type;
static lwc_string *css_charset;
static css_stylesheet *blank_import;
@ -101,22 +100,15 @@ nserror css_init(void)
lwc_error lerror;
nserror error;
lerror = lwc_intern_string("text/css", SLEN("text/css"),
&css_mime_type);
if (lerror != lwc_error_ok)
return NSERROR_NOMEM;
lerror = lwc_intern_string("charset", SLEN("charset"), &css_charset);
if (lerror != lwc_error_ok) {
lwc_string_unref(css_mime_type);
return NSERROR_NOMEM;
}
error = content_factory_register_handler(css_mime_type,
error = content_factory_register_handler("text/css",
&css_content_handler);
if (error != NSERROR_OK) {
lwc_string_unref(css_charset);
lwc_string_unref(css_mime_type);
}
return error;
@ -127,12 +119,15 @@ nserror css_init(void)
*/
void css_fini(void)
{
lwc_string_unref(css_charset);
if (css_charset != NULL) {
lwc_string_unref(css_charset);
css_charset = NULL;
}
lwc_string_unref(css_mime_type);
if (blank_import != NULL)
if (blank_import != NULL) {
css_stylesheet_destroy(blank_import);
blank_import = NULL;
}
}
/**

View File

@ -145,7 +145,6 @@ static const char *html_types[] = {
"text/html"
};
static lwc_string *html_mime_types[NOF_ELEMENTS(html_types)];
static lwc_string *html_charset;
nserror html_init(void)
@ -160,16 +159,8 @@ nserror html_init(void)
goto error;
}
for (i = 0; i < NOF_ELEMENTS(html_mime_types); i++) {
lerror = lwc_intern_string(html_types[i],
strlen(html_types[i]),
&html_mime_types[i]);
if (lerror != lwc_error_ok) {
error = NSERROR_NOMEM;
goto error;
}
error = content_factory_register_handler(html_mime_types[i],
for (i = 0; i < NOF_ELEMENTS(html_types); i++) {
error = content_factory_register_handler(html_types[i],
&html_content_handler);
if (error != NSERROR_OK)
goto error;
@ -185,15 +176,10 @@ error:
void html_fini(void)
{
uint32_t i;
for (i = 0; i < NOF_ELEMENTS(html_mime_types); i++) {
if (html_mime_types[i] != NULL)
lwc_string_unref(html_mime_types[i]);
}
if (html_charset != NULL)
if (html_charset != NULL) {
lwc_string_unref(html_charset);
html_charset = NULL;
}
}
/**

View File

@ -148,7 +148,6 @@ static const content_handler textplain_content_handler = {
.no_share = true,
};
static lwc_string *textplain_mime_type;
static lwc_string *textplain_charset;
static lwc_string *textplain_default_charset;
@ -160,15 +159,9 @@ nserror textplain_init(void)
lwc_error lerror;
nserror error;
lerror = lwc_intern_string("text/plain", SLEN("text/plain"),
&textplain_mime_type);
if (lerror != lwc_error_ok)
return NSERROR_NOMEM;
lerror = lwc_intern_string("charset", SLEN("charset"),
&textplain_charset);
if (lerror != lwc_error_ok) {
lwc_string_unref(textplain_mime_type);
return NSERROR_NOMEM;
}
@ -176,16 +169,14 @@ nserror textplain_init(void)
&textplain_default_charset);
if (lerror != lwc_error_ok) {
lwc_string_unref(textplain_charset);
lwc_string_unref(textplain_mime_type);
return NSERROR_NOMEM;
}
error = content_factory_register_handler(textplain_mime_type,
error = content_factory_register_handler("text/plain",
&textplain_content_handler);
if (error != NSERROR_OK) {
lwc_string_unref(textplain_default_charset);
lwc_string_unref(textplain_charset);
lwc_string_unref(textplain_mime_type);
}
return error;
@ -196,9 +187,15 @@ nserror textplain_init(void)
*/
void textplain_fini(void)
{
lwc_string_unref(textplain_default_charset);
lwc_string_unref(textplain_charset);
lwc_string_unref(textplain_mime_type);
if (textplain_default_charset != NULL) {
lwc_string_unref(textplain_default_charset);
textplain_default_charset = NULL;
}
if (textplain_charset != NULL) {
lwc_string_unref(textplain_charset);
textplain_charset = NULL;
}
}
/**

View File

@ -129,46 +129,8 @@ static const char *artworks_types[] = {
"image/x-artworks"
};
static lwc_string *artworks_mime_types[NOF_ELEMENTS(artworks_types)];
nserror artworks_init(void)
{
uint32_t i;
lwc_error lerror;
nserror error;
for (i = 0; i < NOF_ELEMENTS(artworks_mime_types); i++) {
lerror = lwc_intern_string(artworks_types[i],
strlen(artworks_types[i]),
&artworks_mime_types[i]);
if (lerror != lwc_error_ok) {
error = NSERROR_NOMEM;
goto error;
}
error = content_factory_register_handler(artworks_mime_types[i],
&artworks_content_handler);
if (error != NSERROR_OK)
goto error;
}
return NSERROR_OK;
error:
artworks_fini();
return error;
}
void artworks_fini(void)
{
uint32_t i;
for (i = 0; i < NOF_ELEMENTS(artworks_mime_types); i++) {
if (artworks_mime_types[i] != NULL)
lwc_string_unref(artworks_mime_types[i]);
}
}
CONTENT_FACTORY_REGISTER_TYPES(artworks, artworks_types,
artworks_content_handler)
nserror artworks_create(const content_handler *handler,
lwc_string *imime_type, const http_parameter *params,

View File

@ -72,46 +72,7 @@ static const char *draw_types[] = {
"image/x-drawfile"
};
static lwc_string *draw_mime_types[NOF_ELEMENTS(draw_types)];
nserror draw_init(void)
{
uint32_t i;
lwc_error lerror;
nserror error;
for (i = 0; i < NOF_ELEMENTS(draw_mime_types); i++) {
lerror = lwc_intern_string(draw_types[i],
strlen(draw_types[i]),
&draw_mime_types[i]);
if (lerror != lwc_error_ok) {
error = NSERROR_NOMEM;
goto error;
}
error = content_factory_register_handler(draw_mime_types[i],
&draw_content_handler);
if (error != NSERROR_OK)
goto error;
}
return NSERROR_OK;
error:
draw_fini();
return error;
}
void draw_fini(void)
{
uint32_t i;
for (i = 0; i < NOF_ELEMENTS(draw_mime_types); i++) {
if (draw_mime_types[i] != NULL)
lwc_string_unref(draw_mime_types[i]);
}
}
CONTENT_FACTORY_REGISTER_TYPES(draw, draw_types, draw_content_handler)
nserror draw_create(const content_handler *handler,
lwc_string *imime_type, const http_parameter *params,

View File

@ -71,46 +71,7 @@ static const char *sprite_types[] = {
"image/x-riscos-sprite"
};
static lwc_string *sprite_mime_types[NOF_ELEMENTS(sprite_types)];
nserror sprite_init(void)
{
uint32_t i;
lwc_error lerror;
nserror error;
for (i = 0; i < NOF_ELEMENTS(sprite_mime_types); i++) {
lerror = lwc_intern_string(sprite_types[i],
strlen(sprite_types[i]),
&sprite_mime_types[i]);
if (lerror != lwc_error_ok) {
error = NSERROR_NOMEM;
goto error;
}
error = content_factory_register_handler(sprite_mime_types[i],
&sprite_content_handler);
if (error != NSERROR_OK)
goto error;
}
return NSERROR_OK;
error:
sprite_fini();
return error;
}
void sprite_fini(void)
{
uint32_t i;
for (i = 0; i < NOF_ELEMENTS(sprite_mime_types); i++) {
if (sprite_mime_types[i] != NULL)
lwc_string_unref(sprite_mime_types[i]);
}
}
CONTENT_FACTORY_REGISTER_TYPES(sprite, sprite_types, sprite_content_handler)
nserror sprite_create(const content_handler *handler,
lwc_string *imime_type, const http_parameter *params,