myMPD
Internal API documentation
Loading...
Searching...
No Matches
mimetype.c File Reference

Mime type and file extensions functions. More...

#include "compile_time.h"
#include "src/lib/mimetype.h"
#include "src/lib/log.h"
#include "src/lib/sds_extras.h"
#include "src/lib/utility.h"
#include <errno.h>
#include <string.h>
Include dependency graph for mimetype.c:

Data Structures

struct  t_mime_type_entry
 

Functions

const char * get_mime_type_by_ext (const char *filename)
 
const char * get_ext_by_mime_type (const char *mime_type)
 
const char * get_mime_type_by_magic_stream (sds stream)
 
const char * get_mime_type_by_magic_file (const char *filename)
 
bool is_image (const char *filename)
 

Variables

const struct t_mime_type_entry mime_entries []
 
const char * image_extensions []
 

Detailed Description

Mime type and file extensions functions.

Function Documentation

◆ get_ext_by_mime_type()

const char * get_ext_by_mime_type ( const char *  mime_type)

Gets the extension by mime type

Parameters
mime_type
Returns
the extension

◆ get_mime_type_by_ext()

const char * get_mime_type_by_ext ( const char *  filename)

Gets the mime type by extension

Parameters
filenameFilename to get the mime type for
Returns
the mime type

◆ get_mime_type_by_magic_file()

const char * get_mime_type_by_magic_file ( const char *  filename)

Gets the mime type by magic numbers in binary file

Parameters
filename
Returns
the mime type or generic application/octet-stream

◆ get_mime_type_by_magic_stream()

const char * get_mime_type_by_magic_stream ( sds  stream)

Gets the mime type by magic numbers in binary buffer

Parameters
streambinary buffer
Returns
the mime type or generic application/octet-stream

◆ is_image()

bool is_image ( const char *  filename)

Checks the filetype by extension

Parameters
filename
Returns
true if it is a image extension else false

Variable Documentation

◆ image_extensions

const char* image_extensions[]
Initial value:
= {
"webp",
"jpg",
"jpeg",
"png",
"avif",
"svg",
NULL
}

List of image type extensions

◆ mime_entries

const struct t_mime_type_entry mime_entries[]
Initial value:
= {
{0, "89504E470D0A1A0A", "png", "image/png"},
{0, "FFD8FF", "jpg", "image/jpeg"},
{0, "FFD8FF", "jpeg", "image/jpeg"},
{0, "52494646", "webp", "image/webp"},
{4, "667479706d696631", "avif", "image/avif"},
{0, "494433", "mp3", "audio/mpeg"},
{0, "664C6143", "flac", "audio/flac"},
{0, "4F676753", "oga", "audio/ogg"},
{0, "4F676753", "ogg", "audio/ogg"},
{0, "4F676753", "opus", "audio/ogg"},
{0, "4F676753", "spx", "audio/ogg"},
{0, "", "svg", "image/svg+xml"},
{0, NULL, NULL, "application/octet-stream"}
}

Magic bytes to extension and mime type handling