diff --git a/amiga/dt_picture.c b/amiga/dt_picture.c index 6866545f5..c86d5321e 100644 --- a/amiga/dt_picture.c +++ b/amiga/dt_picture.c @@ -70,72 +70,6 @@ static const content_handler amiga_dt_picture_content_handler = { .no_share = false, }; -nserror amiga_dt_picture_init_from_mime(void) -{ - lwc_string *type; - lwc_error lerror; - nserror error; - char buffer[256]; - BPTR fh = 0; - struct RDArgs *rargs = NULL; - STRPTR template = "MIMETYPE/A,DEFICON/K,DTPICTURE/S,DTANIM/S,PLUGINCMD/K"; - long rarray[] = {0,0,0,0,0}; - - enum - { - A_MIMETYPE, - A_DEFICON, - A_DTPICTURE, - A_DTANIM, - A_PLUGINCMD - }; - - rargs = AllocDosObjectTags(DOS_RDARGS,TAG_DONE); - - if(fh = FOpen("PROGDIR:Resources/mimetypes", MODE_OLDFILE, 0)) - { - while(FGets(fh, (UBYTE *)&buffer, 256) != 0) - { - rargs->RDA_Source.CS_Buffer = (char *)&buffer; - rargs->RDA_Source.CS_Length = 256; - rargs->RDA_Source.CS_CurChr = 0; - - rargs->RDA_DAList = NULL; - rargs->RDA_Buffer = NULL; - rargs->RDA_BufSiz = 0; - rargs->RDA_ExtHelp = NULL; - rargs->RDA_Flags = 0; - - rarray[A_DTPICTURE] = 0; - -printf("buffer = %s\n", buffer); - if(ReadArgs(template, rarray, rargs)) - { - if(rarray[A_DTPICTURE]) - { -printf("mime = %s\n", rarray[A_MIMETYPE]); - - lerror = lwc_intern_string((char *)rarray[A_MIMETYPE], - strlen((char *)rarray[A_MIMETYPE]), &type); - if (lerror != lwc_error_ok) - return NSERROR_NOMEM; - - error = content_factory_register_handler(type, - &amiga_dt_picture_content_handler); - - lwc_string_unref(type); - - if (error != NSERROR_OK) - return error; - } - } - } - FClose(fh); - } - - return NSERROR_OK; -} - nserror amiga_dt_picture_init(void) { @@ -145,6 +79,7 @@ nserror amiga_dt_picture_init(void) lwc_error lerror; nserror error; BPTR fh = 0; + struct Node *node; while((dt = ObtainDataType(DTST_RAM, NULL, DTA_DataType, prevdt, @@ -169,14 +104,24 @@ nserror amiga_dt_picture_init(void) if (error != NSERROR_OK) return error; + do { + node = ami_mime_from_datatype(dt, &type, node); + + if(node) + { + error = content_factory_register_handler(type, + &amiga_dt_picture_content_handler); + + if (error != NSERROR_OK) + return error; + } + + }while (node != NULL); + } ReleaseDataType(prevdt); - error = amiga_dt_picture_init_from_mime(); - if (error != NSERROR_OK) - return error; - return NSERROR_OK; } diff --git a/amiga/filetype.c b/amiga/filetype.c index 5995ec8d5..009ce6d64 100644 --- a/amiga/filetype.c +++ b/amiga/filetype.c @@ -19,6 +19,7 @@ #include #include #include "amiga/filetype.h" +#include "amiga/object.h" #include "content/fetch.h" #include "content/content.h" #include "utils/log.h" @@ -26,12 +27,23 @@ #include #include #include +#include #include /** * filetype -- determine the MIME type of a local file */ +struct MinList *ami_mime_list; + +struct ami_mime_entry +{ + lwc_string *mimetype; + lwc_string *datatype; + lwc_string *filetype; + lwc_string *plugincmd; +}; + const char *fetch_filetype(const char *unix_path) { static char mimetype[50]; @@ -215,3 +227,159 @@ bool ami_mime_compare(struct hlcache_handle *c, const char *type) } else return false; } + +nserror ami_mime_init(const char *mimefile) +{ + lwc_string *type; + lwc_error lerror; + nserror error; + char buffer[256]; + BPTR fh = 0; + struct RDArgs *rargs = NULL; + STRPTR template = "MIMETYPE/A,DT=DATATYPE/K,TYPE=DEFICON/K,CMD=PLUGINCMD/K"; + long rarray[] = {0,0,0,0}; + struct nsObject *node; + struct ami_mime_entry *mimeentry; + + enum + { + A_MIMETYPE, + A_DATATYPE, + A_FILETYPE, + A_PLUGINCMD + }; + + ami_mime_list = NewObjList(); + + rargs = AllocDosObjectTags(DOS_RDARGS,TAG_DONE); + + if(fh = FOpen(mimefile, MODE_OLDFILE, 0)) + { + while(FGets(fh, (UBYTE *)&buffer, 256) != 0) + { + rargs->RDA_Source.CS_Buffer = (char *)&buffer; + rargs->RDA_Source.CS_Length = 256; + rargs->RDA_Source.CS_CurChr = 0; + + rargs->RDA_DAList = NULL; + rargs->RDA_Buffer = NULL; + rargs->RDA_BufSiz = 0; + rargs->RDA_ExtHelp = NULL; + rargs->RDA_Flags = 0; + + rarray[A_MIMETYPE] = 0; + rarray[A_DATATYPE] = 0; + rarray[A_FILETYPE] = 0; + rarray[A_PLUGINCMD] = 0; + + if(ReadArgs(template, rarray, rargs)) + { + node = AddObject(ami_mime_list, AMINS_MIME); + mimeentry = AllocVec(sizeof(struct ami_mime_entry), MEMF_PRIVATE | MEMF_CLEAR); + node->objstruct = mimeentry; + + if(rarray[A_MIMETYPE]) + { + lerror = lwc_intern_string((char *)rarray[A_MIMETYPE], + strlen((char *)rarray[A_MIMETYPE]), &mimeentry->mimetype); + if (lerror != lwc_error_ok) + return NSERROR_NOMEM; + } + + if(rarray[A_DATATYPE]) + { + lerror = lwc_intern_string((char *)rarray[A_DATATYPE], + strlen((char *)rarray[A_DATATYPE]), &mimeentry->datatype); + if (lerror != lwc_error_ok) + return NSERROR_NOMEM; + } + + if(rarray[A_FILETYPE]) + { + lerror = lwc_intern_string((char *)rarray[A_FILETYPE], + strlen((char *)rarray[A_FILETYPE]), &mimeentry->filetype); + if (lerror != lwc_error_ok) + return NSERROR_NOMEM; + } + + if(rarray[A_PLUGINCMD]) + { + lerror = lwc_intern_string((char *)rarray[A_PLUGINCMD], + strlen((char *)rarray[A_PLUGINCMD]), &mimeentry->plugincmd); + if (lerror != lwc_error_ok) + return NSERROR_NOMEM; + } + } + } + FClose(fh); + } +} + +void ami_mime_free(void) +{ + FreeObjList(ami_mime_list); +} + +void ami_mime_entry_free(struct ami_mime_entry *mimeentry) +{ + if(mimeentry->mimetype) lwc_string_unref(mimeentry->mimetype); + if(mimeentry->datatype) lwc_string_unref(mimeentry->datatype); + if(mimeentry->filetype) lwc_string_unref(mimeentry->filetype); + if(mimeentry->plugincmd) lwc_string_unref(mimeentry->plugincmd); +} + +/** + * Return a MIME Type matching a DataType + * + * \param dt a DataType structure + * \param mimetype lwc_string to hold the MIME type + * \param start_node node to feed back in to continue search + * \return node or NULL if no match + */ + +struct Node *ami_mime_from_datatype(struct DataType *dt, + lwc_string **mimetype, struct Node *start_node) +{ + struct DataTypeHeader *dth = dt->dtn_Header; + struct nsObject *node; + struct nsObject *nnode; + struct ami_mime_entry *mimeentry; + lwc_string *dt_name; + lwc_error lerror; + bool ret = false; + + if(IsMinListEmpty(ami_mime_list)) return NULL; + + lerror = lwc_intern_string(dth->dth_Name, strlen(dth->dth_Name), &dt_name); + if (lerror != lwc_error_ok) + return NULL; + + if(start_node) + { + node = (struct nsObject *)GetSucc(start_node); + if(node == NULL) return NULL; + } + else + { + node = (struct nsObject *)GetHead((struct List *)ami_mime_list); + } + + do + { + nnode=(struct nsObject *)GetSucc((struct Node *)node); + mimeentry = node->objstruct; + lerror = lwc_string_isequal(mimeentry->datatype, dt_name, &ret); + + if((lerror == lwc_error_ok) && (ret == true)) + { + *mimetype = mimeentry->mimetype; + break; + } + + }while(node=nnode); + + lwc_string_unref(dt_name); + + if(ret == true) return (struct Node *)node; + else return NULL; +} diff --git a/amiga/filetype.h b/amiga/filetype.h index a09a79a52..73e71efd9 100644 --- a/amiga/filetype.h +++ b/amiga/filetype.h @@ -19,10 +19,20 @@ #ifndef AMIGA_FILETYPE_H #define AMIGA_FILETYPE_H #include +#include #include "content/content_type.h" +#include "utils/errors.h" #include struct hlcache_handle; +struct ami_mime_entry; + +nserror ami_mime_init(const char *mimefile); +void ami_mime_free(void); +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); const char *ami_content_type_to_file_type(content_type type); void ami_datatype_to_mimetype(struct DataType *dtn, char *mimetype); diff --git a/amiga/gui.c b/amiga/gui.c index 630b7b1ff..80847cbcd 100755 --- a/amiga/gui.c +++ b/amiga/gui.c @@ -58,6 +58,7 @@ #include "amiga/misc.h" #include "amiga/options.h" #include "amiga/plotters.h" +#include "amiga/plugin_hack.h" #include "amiga/print.h" #include "amiga/schedule.h" #include "amiga/search.h" @@ -751,9 +752,11 @@ int main(int argc, char** argv) if(ami_locate_resource(messages, "Messages") == false) die("Cannot open Messages file"); + ami_mime_init("PROGDIR:Resources/mimetypes"); ami_schedule_open_timer(); ami_schedule_create(); + amiga_plugin_hack_init(); amiga_datatypes_init(); netsurf_init(&argc, &argv, "PROGDIR:Resources/Options", messages); @@ -777,9 +780,12 @@ int main(int argc, char** argv) netsurf_exit(); + amiga_plugin_hack_fini(); amiga_datatypes_fini(); amiga_icon_fini(); + ami_mime_free(); + return 0; } diff --git a/amiga/object.c b/amiga/object.c index a5bdc7f38..8a42c6848 100755 --- a/amiga/object.c +++ b/amiga/object.c @@ -53,6 +53,7 @@ void DelObjectInternal(struct nsObject *dtzo, BOOL free_obj) { Remove((struct Node *)dtzo); if(dtzo->Type == AMINS_FONT) ami_font_close(dtzo->objstruct); + if(dtzo->Type == AMINS_MIME) ami_mime_entry_free(dtzo->objstruct); if(dtzo->objstruct && free_obj) FreeVec(dtzo->objstruct); if(dtzo->dtz_Node.ln_Name) free(dtzo->dtz_Node.ln_Name); FreeVec(dtzo); diff --git a/amiga/object.h b/amiga/object.h index 48361ddce..3cb428d55 100755 --- a/amiga/object.h +++ b/amiga/object.h @@ -35,6 +35,7 @@ enum AMINS_GUIOPTSWINDOW, AMINS_PRINTWINDOW, AMINS_FONT, + AMINS_MIME }; struct nsObject diff --git a/amiga/resources/MIME/dt.picture b/amiga/resources/MIME/dt.picture deleted file mode 100644 index 5292f5381..000000000 --- a/amiga/resources/MIME/dt.picture +++ /dev/null @@ -1,66 +0,0 @@ -# This file contains a list of MIME types that can be handled by -# picture class datatypes (subclasses of picture.datatype) -# -# It does not matter if this file contains MIME Types for formats -# that a DataType is not installed for, unless a different -# subclass handles this type. - -# BMP -application/bmp -application/preview -application/x-bmp -application/x-win-bitmap -image/bmp -image/ms-bmp -image/x-bitmap -image/x-bmp -image/x-ms-bmp -image/x-win-bitmap -image/x-windows-bmp -image/x-xbitmap - -# GIF -# Expect this to cause problems with GIF anims if GIFANIM datatype installed -image/gif - -# ICO -application/ico -application/x-ico -image/ico -image/vnd.microsoft.icon -image/x-icon - -# .info -image/x-amiga-icon - -# JNG -image/jng -image/x-jng - -# JPEG -image/jpeg -image/jpg -image/pjpeg - -# JPEG2000 -image/jp2 -image/jpeg2000 - -# MNG -image/mng -image/x-mng -video/mng -video/x-mng - -# PNG -image/png - -# RISC OS Sprite -image/x-riscos-sprite - -# SVG -image/svg -image/svg+xml - -# WebP -image/webp diff --git a/amiga/resources/mimetypes b/amiga/resources/mimetypes index 8f9c0b3e0..800f422b6 100644 --- a/amiga/resources/mimetypes +++ b/amiga/resources/mimetypes @@ -1,7 +1,70 @@ -; mimetypes -; this file is parsed using readargs +; This file contains a list of MIME types that can be handled by NetSurf, +; mapping them to DataType and DefIcons format names. +; It is parsed by ReadArgs with the following template: +; MIMETYPE/A,DT=DATATYPE/K,TYPE=DEFICON/K,CMD=PLUGINCMD/K + +; BMP +application/bmp DT=BMP TYPE=bmp +application/preview DT=BMP TYPE=bmp +application/x-bmp DT=BMP TYPE=bmp +application/x-win-bitmap DT=BMP TYPE=bmp +image/bmp DT=BMP TYPE=bmp +image/ms-bmp DT=BMP TYPE=bmp +image/x-bitmap DT=BMP TYPE=bmp +image/x-bmp DT=BMP TYPE=bmp +image/x-ms-bmp DT=BMP TYPE=bmp +image/x-win-bitmap DT=BMP TYPE=bmp +image/x-windows-bmp DT=BMP TYPE=bmp +image/x-xbitmap DT=BMP TYPE=bmp + +; GIF +; Expect problems with GIF anims if GIFANIM datatype installed +image/gif DT=GIF TYPE=gif +;image/gif DT=GIFANIM TYPE=gif + +; ICO +application/ico DT=ICO TYPE=ico +application/x-ico DT=ICO TYPE=ico +image/ico DT=ICO TYPE=ico +image/vnd.microsoft.icon DT=ICO TYPE=ico +image/x-icon DT=ICO TYPE=ico + +; .info +image/x-amiga-icon DT=INFO + +; JNG +image/jng DT=JNG TYPE=jng +image/x-jng DT=JNG TYPE=jng + +; JPEG +image/jpeg DT=JPEG TYPE=jpeg +image/jpg DT=JPEG TYPE=jpeg +image/pjpeg DT=JPEG TYPE=jpeg + +; JPEG2000 +image/jp2 DT=JP2 TYPE=jp2 +image/jpeg2000 DT=JP2 TYPE=jp2 + +; MNG +image/mng DT=MNG TYPE=mng +image/x-mng DT=MNG TYPE=mng +video/mng DT=MNG TYPE=mng +video/x-mng DT=MNG TYPE=mng + +; PNG +image/png DT=PNG TYPE=png + +; RISC OS Sprite +image/x-riscos-sprite DT=Sprite TYPE=rosprite + +; SVG +image/svg DT=SVG TYPE=svg +image/svg+xml DT=SVG TYPE=svg + +; WebP +image/webp DT=WebP TYPE=webp + ; -image/mng DTPICTURE -image/x-mng DTPICTURE -video/mng DTPICTURE -video/x-mng DTPICTURE +; Experimental +; +application/x-shockwave-flash CMD=gnash:aos4-gnash