# MIME API

Header | cups/mime.h
--- | ---
Library | -lcupsmime
See Also | Programming: Introduction to CUPS Programming

## Contents

- Overview
- Functions
  - mimeAddFilter
  - mimeAddType
  - mimeAddTypeRule
  - mimeDelete
  - mimeDeleteFilter
  - mimeDeleteType
  - mimeFileType
  - mimeFilter
  - mimeFilterLookup
  - mimeFirstFilter
  - mimeFirstType
  - mimeLoad
  - mimeLoadFilters
  - mimeLoadTypes
  - mimeNextFilter
  - mimeNextType
  - mimeNumFilters
  - mimeNumTypes
  - mimeType
- Data Types
  - mime_filter_t
  - mime_magic_t
  - mime_op_t
  - mime_t
  - mime_type_t

## Overview

The MIME API provides file typing and conversion services for CUPS.

## Functions

### mimeAddFilter

Add a filter to the current MIME database.

mime_filter_t *mimeAddFilter (
mime_t *mime,
mime_type_t *src,
mime_type_t *dst,
int cost,
const char *filter
);

#### Parameters

mime
  MIME database
src
  Source type
dst
  Destination type
cost
  Relative time/resource cost
filter
  Filter program to run

#### Return Value

New filter

### mimeAddType

Add a MIME type to a database.

mime_type_t *mimeAddType (
mime_t *mime,
const char *super,
const char *type
);

#### Parameters

mime
  MIME database
super
  Super-type name
type
  Type name

#### Return Value

New (or existing) MIME type

### mimeAddTypeRule

Add a detection rule for a file type.

int mimeAddTypeRule (
mime_type_t *mt,
const char *rule
);

#### Parameters

mt
  Type to add to
rule
  Rule to add

#### Return Value

0 on success, -1 on failure

### mimeDelete

Delete (free) a MIME database.

void mimeDelete (
mime_t *mime
);

#### Parameters

mime
  MIME database

### mimeDeleteFilter

Delete a filter from the MIME database.

void mimeDeleteFilter (
mime_t *mime,
mime_filter_t *filter
);

#### Parameters

mime
  MIME database
filter
  Filter

### mimeDeleteType

Delete a type from the MIME database.

void mimeDeleteType (
mime_t *mime,
mime_type_t *mt
);

#### Parameters

mime
  MIME database
mt
  Type

### mimeFileType

Determine the type of a file.

mime_type_t *mimeFileType (
mime_t *mime,
const char *pathname,
const char *filename,
int *compression
);

#### Parameters

mime
  MIME database
pathname
  Name of file to check on disk
filename
  Original filename or NULL
compression
  Is the file compressed?

#### Return Value

Type of file

### mimeFilter

Find the fastest way to convert from one type to another.

cups_array_t *mimeFilter (
mime_t *mime,
mime_type_t *src,
mime_type_t *dst,
int *cost
);

#### Parameters

mime
  MIME database
src
  Source file type
dst
  Destination file type
cost
  Cost of filters

#### Return Value

Array of filters to run

### mimeFilterLookup

Lookup a filter...

mime_filter_t *mimeFilterLookup (
mime_t *mime,
mime_type_t *src,
mime_type_t *dst
);

#### Parameters

mime
  MIME database
src
  Source type
dst
  Destination type

#### Return Value

Filter for src->dst

### mimeFirstFilter

Get the first filter in the MIME database.

mime_filter_t *mimeFirstFilter (
mime_t *mime
);

#### Parameters

mime
  MIME database

#### Return Value

Filter or NULL

### mimeFirstType

Get the first type in the MIME database.

mime_type_t *mimeFirstType (
mime_t *mime
);

#### Parameters

mime
  MIME database

#### Return Value

Type or NULL

### mimeLoad

Create a new MIME database from disk.

mime_t *mimeLoad (
const char *pathname,
const char *filterpath
);

#### Parameters

pathname
  Directory to load
filterpath
  Directory to load

#### Return Value

New MIME database

#### Discussion

This function uses `mimeLoadFilters` and `mimeLoadTypes` to create a MIME database from a single directory.

### mimeLoadFilters

Load filter definitions from disk.

mime_t *mimeLoadFilters (
mime_t *mime,
const char *pathname,
const char *filterpath
);

#### Parameters

mime
  MIME database
pathname
  Directory to load from
filterpath
  Default filter program directory

#### Return Value

MIME database

#### Discussion

This function loads all of the .convs files from the specified directory. Use `mimeLoadTypes` to load all types before you load the filters.

### mimeLoadTypes

Load type definitions from disk.

mime_t *mimeLoadTypes (
mime_t *mime,
const char *pathname
);

#### Parameters

mime
  MIME database or `NULL` to create a new one
pathname
  Directory to load from

#### Return Value

MIME database

#### Discussion

This function loads all of the .types files from the specified directory. Use `mimeLoadFilters` to load all filters after you load the types.

### mimeNextFilter

Get the next filter in the MIME database.

mime_filter_t *mimeNextFilter (
mime_t *mime
);

#### Parameters

mime
  MIME database

#### Return Value

Filter or NULL

### mimeNextType

Get the next type in the MIME database.

mime_type_t *mimeNextType (
mime_t *mime
);

#### Parameters

mime
  MIME database

#### Return Value

Type or NULL

### mimeNumFilters

MIME database

int mimeNumFilters (
mime_t *mime
);

#### Parameters

mime
  MIME database

#### Return Value

Get the number of filters in a MIME database.

### mimeNumTypes

MIME database

int mimeNumTypes (
mime_t *mime
);

#### Parameters

mime
  MIME database

#### Return Value

Get the number of types in a MIME database.

### mimeType

Lookup a file type.

mime_type_t *mimeType (
mime_t *mime,
const char *super,
const char *type
);

#### Parameters

mime
  MIME database
super
  Super-type name
type
  Type name

#### Return Value

Matching file type definition

## Data Types

### mime_filter_t

MIME Conversion Filter Data

typedef struct _mime_filter_s mime_filter_t;

### mime_magic_t

MIME Magic Data

typedef struct _mime_magic_s mime_magic_t;

### mime_op_t

Types/structures...

typedef enum mime_op_t;

### mime_t

MIME Database

typedef struct _mime_s mime_t;

### mime_type_t

MIME Type Data

typedef struct _mime_type_s mime_type_t;