NetSurf
Data Structures | Macros | Functions | Variables
filetype.c File Reference
#include <stdlib.h>
#include <string.h>
#include <unixlib/local.h>
#include "oslib/mimemap.h"
#include "oslib/osfile.h"
#include "utils/config.h"
#include "utils/log.h"
#include "netsurf/content.h"
#include "riscos/filetype.h"
#include "riscos/gui.h"
Include dependency graph for filetype.c:

Go to the source code of this file.

Data Structures

struct  type_entry
 

Macros

#define TYPE_MAP_COUNT   (sizeof(type_map) / sizeof(type_map[0]))
 
#define BUF_SIZE   (256)
 

Functions

static int cmp_type (const void *x, const void *y)
 Comparison function for bsearch. More...
 
const char * fetch_filetype (const char *unix_path)
 filetype – determine the MIME type of a local file More...
 
char * fetch_mimetype (const char *ro_path)
 Find a MIME type for a local file. More...
 
int ro_content_filetype (struct hlcache_handle *c)
 Determine the RISC OS filetype for a content. More...
 
int ro_content_native_type (struct hlcache_handle *c)
 Determine the native RISC OS filetype to export a content as. More...
 
int ro_content_filetype_from_mime_type (lwc_string *mime_type)
 Determine the RISC OS filetype for a MIME type. More...
 
int ro_content_filetype_from_type (content_type type)
 Determine the RISC OS filetype from a content type. More...
 
bits ro_filetype_from_unix_path (const char *unix_path)
 Determine the type of a local file. More...
 

Variables

static const struct type_entry type_map []
 
static char type_buf [BUF_SIZE]
 

Macro Definition Documentation

◆ BUF_SIZE

#define BUF_SIZE   (256)

Definition at line 58 of file filetype.c.

◆ TYPE_MAP_COUNT

#define TYPE_MAP_COUNT   (sizeof(type_map) / sizeof(type_map[0]))

Definition at line 56 of file filetype.c.

Function Documentation

◆ cmp_type()

int cmp_type ( const void *  x,
const void *  y 
)
static

Comparison function for bsearch.

Definition at line 235 of file filetype.c.

References type_entry::file_type.

Referenced by fetch_filetype(), and fetch_mimetype().

Here is the caller graph for this function:

◆ fetch_filetype()

const char * fetch_filetype ( const char *  unix_path)

filetype – determine the MIME type of a local file

Determine the MIME type of a local file.

Definition at line 65 of file filetype.c.

References BUF_SIZE, cmp_type(), type_entry::file_type, type_entry::mime_type, NSLOG, path(), ro_warn_user(), type_buf, type_map, and TYPE_MAP_COUNT.

Here is the call graph for this function:

◆ fetch_mimetype()

char * fetch_mimetype ( const char *  ro_path)

Find a MIME type for a local file.

Parameters
ro_pathRISC OS style path to file on disk
Returns
MIME type string (on heap, caller should free), or NULL

Definition at line 154 of file filetype.c.

References BUF_SIZE, cmp_type(), type_entry::mime_type, NSLOG, ro_warn_user(), type_map, and TYPE_MAP_COUNT.

Here is the call graph for this function:

◆ ro_content_filetype()

int ro_content_filetype ( struct hlcache_handle h)

Determine the RISC OS filetype for a content.

Parameters
hThe handle of the content to examine.
Returns
The RISC OS filetype corresponding to the content

Definition at line 243 of file filetype.c.

References content_get_mime_type(), content_get_type(), type_entry::file_type, type_entry::mime_type, ro_content_filetype_from_mime_type(), and ro_content_filetype_from_type().

Referenced by print_send_printsave(), ro_content_native_type(), ro_gui_save_content(), ro_gui_save_object_native(), ro_gui_save_set_state(), ro_gui_url_bar_set_content_favicon(), ro_gui_view_source(), ro_gui_window_prepare_objectinfo(), and ro_gui_window_prepare_pageinfo().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_content_filetype_from_mime_type()

int ro_content_filetype_from_mime_type ( lwc_string *  mime_type)

Determine the RISC OS filetype for a MIME type.

Parameters
mime_typeMIME type to consider
Returns
Corresponding RISC OS filetype

Definition at line 288 of file filetype.c.

References type_entry::file_type, type_entry::mime_type, type_map, and TYPE_MAP_COUNT.

Referenced by ro_content_filetype(), and ro_gui_save_set_file_type().

Here is the caller graph for this function:

◆ ro_content_filetype_from_type()

int ro_content_filetype_from_type ( content_type  type)

Determine the RISC OS filetype from a content type.

Parameters
typeThe content type to examine.
Returns
The RISC OS filetype corresponding to the content, or 0 for unknown

Definition at line 315 of file filetype.c.

References CONTENT_CSS, CONTENT_HTML, CONTENT_TEXTPLAIN, FILETYPE_HTML, and type.

Referenced by ro_content_filetype(), and ro_gui_url_complete_redraw().

Here is the caller graph for this function:

◆ ro_content_native_type()

int ro_content_native_type ( struct hlcache_handle c)

Determine the native RISC OS filetype to export a content as.

Parameters
cThe content to examine
Returns
Native RISC OS filetype for export

Definition at line 263 of file filetype.c.

References FILETYPE_BMP, FILETYPE_GIF, FILETYPE_ICO, FILETYPE_JNG, FILETYPE_JPEG, FILETYPE_MNG, FILETYPE_PNG, FILETYPE_SVG, FILETYPE_WEBP, and ro_content_filetype().

Referenced by ro_gui_save_object_native(), ro_gui_save_set_state(), and ro_gui_window_content_export_types().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ ro_filetype_from_unix_path()

bits ro_filetype_from_unix_path ( const char *  unix_path)

Determine the type of a local file.

Parameters
unix_pathUnix style path to file on disk
Returns
File type

Definition at line 327 of file filetype.c.

References type_entry::file_type, NSLOG, path(), and ro_warn_user().

Referenced by download_ro_filetype().

Here is the call graph for this function:
Here is the caller graph for this function:

Variable Documentation

◆ type_buf

char type_buf[BUF_SIZE]
static

Definition at line 59 of file filetype.c.

Referenced by fetch_filetype().

◆ type_map

const struct type_entry type_map[]
static
Initial value:
= {
{0x132, "image/ico"},
{0x188, "application/x-shockwave-flash"},
{0x695, "image/gif"},
{0x69c, "image/x-ms-bmp"},
{0xa66, "image/webp"},
{0xaad, "image/svg+xml"},
{0xaff, "image/x-drawfile"},
{0xb60, "image/png"},
{0xc85, "image/jpeg"},
{0xd94, "image/x-artworks"},
{0xf78, "image/jng"},
{0xf79, "text/css"},
{0xf81, "application/javascript"},
{0xf83, "image/mng"},
{0xfaf, "text/html"},
{0xff9, "image/x-riscos-sprite"},
{0xfff, "text/plain"},
}

Definition at line 37 of file filetype.c.

Referenced by fetch_filetype(), fetch_mimetype(), and ro_content_filetype_from_mime_type().