NetSurf
Macros | Functions | Variables
filetype.c File Reference

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

#include <stdio.h>
#include <stdbool.h>
#include <stdint.h>
#include <string.h>
#include <strings.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "utils/log.h"
#include "utils/ascii.h"
#include "utils/hashtable.h"
#include "monkey/filetype.h"
Include dependency graph for filetype.c:

Go to the source code of this file.

Macros

#define HASH_SIZE   117
 
#define MAX_LINE_LEN   256
 

Functions

void monkey_fetch_filetype_init (const char *mimefile)
 
void monkey_fetch_filetype_fin (void)
 
const char * monkey_fetch_filetype (const char *unix_path)
 Determine the MIME type of a local file. More...
 

Variables

static struct hash_tablemime_hash = NULL
 

Detailed Description

file extension to mimetype mapping for the monkey frontend

allows monkey 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 filetype.c.

Macro Definition Documentation

◆ HASH_SIZE

#define HASH_SIZE   117

Definition at line 49 of file filetype.c.

◆ MAX_LINE_LEN

#define MAX_LINE_LEN   256

Definition at line 50 of file filetype.c.

Function Documentation

◆ monkey_fetch_filetype()

const char * monkey_fetch_filetype ( const char *  unix_path)

Determine the MIME type of a local file.

Note
used in file fetcher
Parameters
unix_pathUnix style path to file on disk
Returns
Pointer to static MIME type string (should not be freed) not NULL. invalidated on next call to fetch_filetype.

Definition at line 182 of file filetype.c.

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

Here is the call graph for this function:

◆ monkey_fetch_filetype_fin()

void monkey_fetch_filetype_fin ( void  )

Definition at line 168 of file filetype.c.

References hash_destroy(), and mime_hash.

Referenced by monkey_quit().

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

◆ monkey_fetch_filetype_init()

void monkey_fetch_filetype_init ( const char *  mimefile)

Definition at line 54 of file filetype.c.

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

Referenced by main().

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

Variable Documentation

◆ mime_hash

struct hash_table* mime_hash = NULL
static