summaryrefslogtreecommitdiff
path: root/content
diff options
context:
space:
mode:
authorJohn Mark Bell <jmb@netsurf-browser.org>2011-09-15 22:31:16 +0000
committerJohn Mark Bell <jmb@netsurf-browser.org>2011-09-15 22:31:16 +0000
commit3d71da088b83c2cc5741dfdc8f619fbf2bba55a2 (patch)
tree8c26b93479c4a23b657c55809ea823f7b2bc2ca5 /content
parent50508a6e75e8bfa955b9193f0b6252ff2e235220 (diff)
downloadnetsurf-3d71da088b83c2cc5741dfdc8f619fbf2bba55a2.tar.gz
netsurf-3d71da088b83c2cc5741dfdc8f619fbf2bba55a2.tar.bz2
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
Diffstat (limited to 'content')
-rw-r--r--content/content_factory.c14
-rw-r--r--content/content_factory.h26
2 files changed, 15 insertions, 25 deletions
diff --git a/content/content_factory.c b/content/content_factory.c
index 8baa20f7a..3f06dc432 100644
--- a/content/content_factory.c
+++ b/content/content_factory.c
@@ -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;
diff --git a/content/content_factory.h b/content/content_factory.h
index b383f461b..26c587575 100644
--- a/content/content_factory.h
+++ b/content/content_factory.h
@@ -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,