NetSurf
Macros | Functions | Variables
fetch.c File Reference

file extension to mimetype mapping for the GTK frontend More...

#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <string.h>
#include <strings.h>
#include <gtk/gtk.h>
#include "utils/log.h"
#include "utils/hashtable.h"
#include "utils/filepath.h"
#include "utils/file.h"
#include "utils/nsurl.h"
#include "utils/ascii.h"
#include "netsurf/fetch.h"
#include "gtk/gui.h"
#include "gtk/resources.h"
#include "gtk/fetch.h"
Include dependency graph for fetch.c:

Go to the source code of this file.

Macros

#define HASH_SIZE   117
 
#define MAX_LINE_LEN   256
 

Functions

void gtk_fetch_filetype_init (const char *mimefile)
 
void gtk_fetch_filetype_fin (void)
 
const char * fetch_filetype (const char *unix_path)
 filetype – determine the MIME type of a local file More...
 
static nsurlnsgtk_get_resource_url (const char *path)
 

Variables

static struct hash_tablemime_hash = NULL
 
static struct gui_fetch_table fetch_table
 
struct gui_fetch_tablensgtk_fetch_table = &fetch_table
 

Detailed Description

file extension to mimetype mapping for the GTK frontend

allows GTK frontend to map file extension to mime types using a default builtin list and /etc/mime.types file if present.

mime type and content type handling is derived from the BNF in RFC822 section 3.3, RFC2045 section 5.1 and RFC6838 section 4.2. Upshot is their charset and parsing is all a strict subset of ASCII hence not using locale dependant ctype functions for parsing.

Definition in file fetch.c.

Macro Definition Documentation

◆ HASH_SIZE

#define HASH_SIZE   117

Definition at line 55 of file fetch.c.

◆ MAX_LINE_LEN

#define MAX_LINE_LEN   256

Definition at line 56 of file fetch.c.

Function Documentation

◆ 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 184 of file fetch.c.

References ascii_to_lower(), hash_get(), mime_hash, and type.

Here is the call graph for this function:

◆ gtk_fetch_filetype_fin()

void gtk_fetch_filetype_fin ( void  )

Definition at line 179 of file fetch.c.

References hash_destroy(), and mime_hash.

Referenced by nsgtk_finalise().

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

◆ gtk_fetch_filetype_init()

void gtk_fetch_filetype_init ( const char *  mimefile)

Definition at line 60 of file fetch.c.

References ascii_is_space(), hash_add(), hash_create(), HASH_SIZE, line(), MAX_LINE_LEN, mime_hash, NSLOG, and type.

Referenced by nsgtk_setup().

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

◆ nsgtk_get_resource_url()

static nsurl * nsgtk_get_resource_url ( const char *  path)
static

Definition at line 251 of file fetch.c.

References filepath_sfind(), netsurf_path_to_nsurl(), nsurl_create(), path(), PATH_MAX, and respaths.

Here is the call graph for this function:

Variable Documentation

◆ fetch_table

struct gui_fetch_table fetch_table
static
Initial value:
= {
.filetype = fetch_filetype,
.get_resource_url = nsgtk_get_resource_url,
.get_resource_data = nsgtk_data_from_resname,
}
const char * fetch_filetype(const char *unix_path)
filetype – determine the MIME type of a local file
Definition: fetch.c:184
static nsurl * nsgtk_get_resource_url(const char *path)
Definition: fetch.c:251
nserror nsgtk_data_from_resname(const char *resname, const uint8_t **data_out, size_t *data_size_out)
Get direct pointer to resource data.
Definition: resources.c:574

Definition at line 266 of file fetch.c.

◆ mime_hash

struct hash_table* mime_hash = NULL
static

Definition at line 58 of file fetch.c.

Referenced by fetch_filetype(), gtk_fetch_filetype_fin(), and gtk_fetch_filetype_init().

◆ nsgtk_fetch_table

struct gui_fetch_table* nsgtk_fetch_table = &fetch_table

Definition at line 273 of file fetch.c.

Referenced by main().