23#include <proto/icon.h>
25#include <proto/datatypes.h>
26#include <proto/exec.h>
27#include <workbench/icon.h>
60 static char mimetype[50];
61 struct DiskObject *dobj = NULL;
64 lwc_string *lwc_mimetype;
70 if(strncmp(unix_path + strlen(unix_path) - 5,
".info", 5) == 0) {
71 strcpy(mimetype,
"image/x-amiga-icon");
80 if((dobj = GetIconTags(unix_path,ICONGETA_FailIfUnavailable,FALSE,
83 ttype = FindToolType(dobj->do_ToolTypes,
"MIMETYPE");
85 strcpy(mimetype,ttype);
96 if ((lock = Lock(unix_path, ACCESS_READ))) {
97 if ((dtn = ObtainDataTypeA (DTST_FILE, (APTR)lock, NULL))) {
99 strcpy(mimetype, lwc_string_data(lwc_mimetype));
101 ReleaseDataType(dtn);
114 if((!found) || (strcmp(
"text/plain", mimetype) == 0))
116 if((strncmp(unix_path + strlen(unix_path) - 4,
".css", 4) == 0) ||
117 (strncmp(unix_path + strlen(unix_path) - 4,
",f79", 4) == 0))
119 strcpy(mimetype,
"text/css");
123 if((strncmp(unix_path + strlen(unix_path) - 4,
".htm", 4) == 0) ||
124 (strncmp(unix_path + strlen(unix_path) - 5,
".html", 5) == 0) ||
125 (strncmp(unix_path + strlen(unix_path) - 4,
",faf", 4) == 0))
127 strcpy(mimetype,
"text/html");
130 if(strncmp(unix_path + strlen(unix_path) - 3,
".js", 3) == 0) {
131 strcpy(mimetype,
"application/javascript");
136 if(!found) strcpy(mimetype,
"text/plain");
182 struct RDArgs *rargs = NULL;
183 CONST_STRPTR
template =
"MIMETYPE/A,DT=DATATYPE/K,TYPE=DEFICON/K,CMD=PLUGINCMD/K";
184 long rarray[] = {0,0,0,0};
188 NSLOG(netsurf, INFO,
"mimetypes file: %s", mimefile);
193 rargs = AllocDosObjectTags(DOS_RDARGS,TAG_DONE);
196 if((fh =
FOpen(mimefile, MODE_OLDFILE, 0)))
198 while((FGets(fh, (STRPTR)&
buffer, 256) != 0))
200 rargs->RDA_Source.CS_Buffer = (
char *)&
buffer;
201 rargs->RDA_Source.CS_Length = 256;
202 rargs->RDA_Source.CS_CurChr = 0;
204 rargs->RDA_DAList = NULL;
205 rargs->RDA_Buffer = NULL;
206 rargs->RDA_BufSiz = 0;
207 rargs->RDA_ExtHelp = NULL;
208 rargs->RDA_Flags = 0;
215 if(ReadArgs(
template, rarray, rargs))
226 if (lerror != lwc_error_ok)
234 if (lerror != lwc_error_ok)
242 if (lerror != lwc_error_ok)
250 if (lerror != lwc_error_ok)
259 FreeDosObject(DOS_RDARGS, rargs);
280 int type,
struct Node **start_node)
293 if(node == NULL)
return NULL;
305 lerror = lwc_error_ok;
311 lerror = lwc_string_isequal(mimeentry->
mimetype, search, &ret);
312 else if(mimeentry->
mimetype != NULL)
318 lerror = lwc_string_isequal(mimeentry->
datatype, search, &ret);
319 else if(mimeentry->
datatype != NULL)
325 lerror = lwc_string_isequal(mimeentry->
filetype, search, &ret);
326 else if(mimeentry->
filetype != NULL)
332 lerror = lwc_string_isequal(mimeentry->
plugincmd, search, &ret);
338 if((lerror == lwc_error_ok) && (ret ==
true))
341 }
while((node=nnode));
343 *start_node = (
struct Node *)node;
345 if(ret ==
true)
return mimeentry;
354 char *dt_name_lwr = NULL;
357 struct DataTypeHeader *dth = dt->dtn_Header;
361 if(node == NULL)
return NULL;
364 if(mimeentry == NULL)
return NULL;
369 lerror = lwc_intern_string(dth->dth_Name, strlen(dth->dth_Name), &mimeentry->
datatype);
370 if (lerror != lwc_error_ok)
373 dt_name_lwr = strdup(dth->dth_Name);
374 if(dt_name_lwr == NULL)
return NULL;
381 if(*p ==
' ') *p =
'-';
382 if(*p ==
'/') *p =
'-';
386 switch(dth->dth_GroupID)
390 if(strcmp(
"ascii", dt_name_lwr)==0)
392 strcpy(mimetype,
"text/plain");
396 sprintf(mimetype,
"text/%s", dt_name_lwr);
402 sprintf(mimetype,
"audio/%s", dt_name_lwr);
405 if(strcmp(
"sprite", dt_name_lwr)==0)
407 strcpy(mimetype,
"image/x-riscos-sprite");
411 sprintf(mimetype,
"image/%s", dt_name_lwr);
416 sprintf(mimetype,
"video/%s", dt_name_lwr);
420 if(strcmp(
"directory", dt_name_lwr)==0)
422 strcpy(mimetype,
"application/x-netsurf-directory");
424 else if(strcmp(
"binary", dt_name_lwr)==0)
426 strcpy(mimetype,
"application/octet-stream");
428 else sprintf(mimetype,
"application/%s", dt_name_lwr);
432 lerror = lwc_intern_string(mimetype, strlen(mimetype), &mimeentry->
mimetype);
433 if (lerror != lwc_error_ok)
436 *lwc_mimetype = mimeentry->
mimetype;
438 lerror = lwc_intern_string(dt_name_lwr, strlen(dt_name_lwr), &mimeentry->
filetype);
439 if (lerror != lwc_error_ok)
456 lwc_string **mimetype,
struct Node *start_node)
458 struct DataTypeHeader *dth;
464 if(dt == NULL)
return NULL;
466 dth = dt->dtn_Header;
467 lerror = lwc_intern_string(dth->dth_Name, strlen(dth->dth_Name), &dt_name);
468 if (lerror != lwc_error_ok)
473 lwc_string_unref(dt_name);
475 if(mimeentry != NULL)
478 return (
struct Node *)node;
482 if(start_node == NULL)
504 lwc_string **filetype,
struct Node *start_node)
512 if(mimeentry != NULL)
515 return (
struct Node *)node;
526 lwc_string *filetype;
527 lwc_string *mimetype;
533 if(node && (filetype != NULL))
534 return lwc_string_data(filetype);
555 if(mimeentry != NULL)
558 return (
struct Node *)node;
576 lwc_string **plugincmd,
struct Node *start_node)
584 if(mimeentry != NULL)
587 return (
struct Node *)node;
598 lwc_string *plugincmd;
599 lwc_string *mimetype;
606 if(node && (plugincmd != NULL))
return plugincmd;
618 lwc_string *filetype;
619 lwc_string *mime_filetype;
625 lerror = lwc_intern_string(
type, strlen(
type), &filetype);
626 if (lerror != lwc_error_ok)
629 lerror = lwc_string_isequal(filetype, mime_filetype, &ret);
630 if (lerror != lwc_error_ok)
633 lwc_string_unref(filetype);
641 struct Node *node = NULL;
645 NSLOG(netsurf, INFO,
"%s DT=\"%s\" TYPE=\"%s\" CMD=\"%s\"",
static struct MinList * ami_mime_list
filetype – determine the MIME type of a local file
static struct Node * ami_mime_to_plugincmd(lwc_string *mimetype, lwc_string **plugincmd, struct Node *start_node)
Return the plugincmd matching a MIME type.
const char * ami_content_type_to_file_type(content_type type)
lwc_string * ami_mime_content_to_cmd(struct hlcache_handle *c)
static APTR ami_mime_guess_add_datatype(struct DataType *dt, lwc_string **lwc_mimetype)
const char * fetch_filetype(const char *unix_path)
Determine the MIME type of a local file.
struct Node * ami_mime_from_datatype(struct DataType *dt, lwc_string **mimetype, struct Node *start_node)
Return a MIME Type matching a DataType.
nserror ami_mime_init(const char *mimefile)
static struct ami_mime_entry * ami_mime_entry_locate(lwc_string *search, int type, struct Node **start_node)
Return next matching MIME entry.
struct Node * ami_mime_to_filetype(lwc_string *mimetype, lwc_string **filetype, struct Node *start_node)
Return the DefIcons type matching a MIME type.
bool ami_mime_compare(struct hlcache_handle *c, const char *type)
Compare the MIME type of an hlcache_handle to a DefIcons type.
static void ami_mime_entry_free(void *nso)
const char * ami_mime_content_to_filetype(struct hlcache_handle *c)
struct Node * ami_mime_has_cmd(lwc_string **mimetype, struct Node *start_node)
Return all MIME types containing a plugincmd.
static osspriteop_area * buffer
The buffer characteristics.
content_type
The type of a content.
@ CONTENT_IMAGE
All images.
@ CONTENT_CSS
content is CSS
@ CONTENT_HTML
content is HTML
@ CONTENT_TEXTPLAIN
content is plain text
nserror
Enumeration of error codes.
@ NSERROR_NOMEM
Memory exhaustion.
struct MinList * NewObjList(void)
void FreeObjList(struct MinList *objlist)
void ObjectCallback(struct nsObject *dtzo, void(*callback)(void *nso))
struct nsObject * AddObject(struct MinList *objlist, ULONG otype)
Public content interface.
lwc_string * content_get_mime_type(struct hlcache_handle *h)
Retrieve mime-type of content.
content_type content_get_type(struct hlcache_handle *h)
Retrieve computed type of content.
#define NSLOG(catname, level, logmsg, args...)
struct Node * GetHead(struct List *list)
struct Node * GetSucc(struct Node *node)
Minimal compatibility header for AmigaOS 3.
#define IsMinListEmpty(L)
Interface to utility string handling.
Interface to a number of general purpose functionality.