From 38bcb14d7765a1231527f65f9a1c3d9e8045697e Mon Sep 17 00:00:00 2001 From: Chris Young Date: Tue, 10 May 2011 19:32:21 +0000 Subject: Migrate to new MIMEtyper svn path=/trunk/netsurf/; revision=12375 --- amiga/dt_anim.c | 37 +++++++++++++------------------- amiga/filetype.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++---- amiga/filetype.h | 12 +++++++++-- amiga/plugin_hack.c | 35 +++++++++--------------------- 4 files changed, 92 insertions(+), 53 deletions(-) (limited to 'amiga') diff --git a/amiga/dt_anim.c b/amiga/dt_anim.c index 55ec60578..cad77ce46 100644 --- a/amiga/dt_anim.c +++ b/amiga/dt_anim.c @@ -92,17 +92,18 @@ nserror amiga_dt_anim_init(void) lwc_error lerror; nserror error; BPTR fh = 0; + struct Node *node = NULL; while((dt = ObtainDataType(DTST_RAM, NULL, DTA_DataType, prevdt, - DTA_GroupID, GID_ANIMATION, + DTA_GroupID, GID_PICTURE, // we only support images for now TAG_DONE)) != NULL) { ReleaseDataType(prevdt); prevdt = dt; ami_datatype_to_mimetype(dt, dt_mime); - LOG(("Guessed MIME from DT: %s", dt_mime)); + LOG(("Guessed MIME from anim DT: %s", dt_mime)); lerror = lwc_intern_string(dt_mime, strlen(dt_mime), &type); if (lerror != lwc_error_ok) @@ -116,32 +117,24 @@ nserror amiga_dt_anim_init(void) if (error != NSERROR_OK) return error; - } + do { + node = ami_mime_from_datatype(dt, &type, node); - ReleaseDataType(prevdt); + if(node) + { + error = content_factory_register_handler(type, + &amiga_dt_anim_content_handler); - if(fh = FOpen("PROGDIR:Resources/MIME/dt.animation", MODE_OLDFILE, 0)) - { - while(FGets(fh, (UBYTE *)&dt_mime, 50) != 0) - { - dt_mime[strlen(dt_mime) - 1] = '\0'; - if((dt_mime[0] == '\0') || (dt_mime[0] == '#')) - continue; /* Skip blank lines and comments */ + if (error != NSERROR_OK) + return error; + } - lerror = lwc_intern_string(dt_mime, strlen(dt_mime), &type); - if (lerror != lwc_error_ok) - return NSERROR_NOMEM; + }while (node != NULL); - error = content_factory_register_handler(type, - &amiga_dt_anim_content_handler); + } - lwc_string_unref(type); + ReleaseDataType(prevdt); - if (error != NSERROR_OK) - return error; - } - FClose(fh); - } return NSERROR_OK; } diff --git a/amiga/filetype.c b/amiga/filetype.c index 28c780f5f..4a5d9aa62 100644 --- a/amiga/filetype.c +++ b/amiga/filetype.c @@ -318,7 +318,7 @@ void ami_mime_entry_free(struct ami_mime_entry *mimeentry) /** * Return next matching MIME entry * - * \param search lwc_string to search for + * \param search lwc_string to search for (or NULL for all) * \param type of value being searched for (AMI_MIME_#?) * \param start_node node to continue search (updated on exit) * \return entry or NULL if no match @@ -412,7 +412,6 @@ struct Node *ami_mime_from_datatype(struct DataType *dt, lwc_string *dt_name; lwc_error lerror; - if(IsMinListEmpty(ami_mime_list)) return NULL; if(dt == NULL) return NULL; dth = dt->dtn_Header; @@ -451,8 +450,6 @@ struct Node *ami_mime_to_filetype(lwc_string *mimetype, struct Node *node; struct ami_mime_entry *mimeentry; - if(IsMinListEmpty(ami_mime_list)) return NULL; - node = start_node; mimeentry = ami_mime_entry_locate(mimetype, AMI_MIME_MIMETYPE, &node); @@ -467,6 +464,62 @@ struct Node *ami_mime_to_filetype(lwc_string *mimetype, } } +/** + * Return all MIME types containing a plugincmd + * + * \param mimetype ptr to lwc_string MIME type + * \param start_node node to feed back in to continue search + * \return node or NULL if no match + */ + +struct Node *ami_mime_has_cmd(lwc_string **mimetype, struct Node *start_node) +{ + struct Node *node; + struct ami_mime_entry *mimeentry; + + node = start_node; + mimeentry = ami_mime_entry_locate(NULL, AMI_MIME_PLUGINCMD, &node); + + if(mimeentry != NULL) + { + *mimetype = mimeentry->mimetype; + return (struct Node *)node; + } + else + { + return NULL; + } +} + +/** + * Return the plugincmd matching a MIME type + * + * \param mimetype lwc_string MIME type + * \param plugincmd ptr to lwc_string to hold plugincmd + * \param start_node node to feed back in to continue search + * \return node or NULL if no match + */ + +struct Node *ami_mime_to_plugincmd(lwc_string *mimetype, + lwc_string **plugincmd, struct Node *start_node) +{ + struct Node *node; + struct ami_mime_entry *mimeentry; + + node = start_node; + mimeentry = ami_mime_entry_locate(mimetype, AMI_MIME_MIMETYPE, &node); + + if(mimeentry != NULL) + { + *plugincmd = mimeentry->plugincmd; + return (struct Node *)node; + } + else + { + return NULL; + } +} + /** * Compare the MIME type of an hlcache_handle to a DefIcons type */ diff --git a/amiga/filetype.h b/amiga/filetype.h index 73e71efd9..d9b76ee5f 100644 --- a/amiga/filetype.h +++ b/amiga/filetype.h @@ -1,5 +1,5 @@ /* - * Copyright 2010 Chris Young + * Copyright 2010 - 2011 Chris Young * * This file is part of NetSurf, http://www.netsurf-browser.org/ * @@ -33,8 +33,16 @@ void ami_mime_entry_free(struct ami_mime_entry *mimeentry); struct Node *ami_mime_from_datatype(struct DataType *dt, lwc_string **mimetype, struct Node *start_node); +struct Node *ami_mime_to_filetype(lwc_string *mimetype, + lwc_string **filetype, struct Node *start_node); +struct Node *ami_mime_to_plugincmd(lwc_string *mimetype, + lwc_string **plugincmd, struct Node *start_node); +struct Node *ami_mime_has_cmd(lwc_string **mimetype, struct Node *start_node); + +bool ami_mime_compare(struct hlcache_handle *c, const char *type); + +/* deprecated */ const char *ami_content_type_to_file_type(content_type type); void ami_datatype_to_mimetype(struct DataType *dtn, char *mimetype); -bool ami_mime_compare(struct hlcache_handle *c, const char *type); #endif diff --git a/amiga/plugin_hack.c b/amiga/plugin_hack.c index 8779ad11a..51a7c9373 100644 --- a/amiga/plugin_hack.c +++ b/amiga/plugin_hack.c @@ -39,12 +39,6 @@ typedef struct amiga_plugin_hack_content { struct content base; - - Object *dto; - int x; - int y; - int w; - int h; } amiga_plugin_hack_content; static nserror amiga_plugin_hack_create(const content_handler *handler, @@ -83,35 +77,26 @@ static const content_handler amiga_plugin_hack_content_handler = { nserror amiga_plugin_hack_init(void) { - char dt_mime[50]; - struct DataType *dt, *prevdt = NULL; + struct Node *node = NULL; lwc_string *type; - lwc_error lerror; nserror error; - BPTR fh = 0; - if(fh = FOpen("PROGDIR:Resources/MIME/pluginhack", MODE_OLDFILE, 0)) - { - while(FGets(fh, (UBYTE *)&dt_mime, 50) != 0) - { - dt_mime[strlen(dt_mime) - 1] = '\0'; - if((dt_mime[0] == '\0') || (dt_mime[0] == '#')) - continue; /* Skip blank lines and comments */ + do { + node = ami_mime_has_cmd(&type, node); - lerror = lwc_intern_string(dt_mime, strlen(dt_mime), &type); - if (lerror != lwc_error_ok) - return NSERROR_NOMEM; + if(node) + { + printf("plugin_hack registered %s\n",lwc_string_data(type)); error = content_factory_register_handler(type, - &amiga_plugin_hack_content_handler); - - lwc_string_unref(type); + &amiga_plugin_hack_content_handler); if (error != NSERROR_OK) return error; } - FClose(fh); - } + + }while (node != NULL); + return NSERROR_OK; } -- cgit v1.2.3