1 <!DOCTYPE HTML PUBLIC
"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
3 <!-- SECTION: Programming -->
5 <title>MIME API
</title>
6 <meta name=
"keywords" content=
"Programming">
7 <meta http-equiv=
"Content-Type" content=
"text/html;charset=utf-8">
8 <meta name=
"creator" content=
"Mini-XML v2.7">
9 <style type=
"text/css"><!--
11 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
14 H1, H2, H3, H4, H5, H6, P, TD, TH {
15 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
19 font-family: monaco, courier, monospace;
24 font-family: monaco, courier, monospace;
28 border: dotted thin #7f7f7f;
56 border: dotted thin #999999;
61 PRE.command EM, PRE.example EM {
62 font-family: lucida grande, geneva, helvetica, arial, sans-serif;
66 font-family: monaco, courier, monospace;
77 border: solid thin #999999;
88 -moz-border-radius: 10px;
93 text-decoration: none;
96 A:link:hover, A:visited:hover, A:active {
97 text-decoration: underline;
104 TR.data, TD.data, TR.data TD {
107 border-bottom: solid 1pt #999999;
111 border-bottom: solid 1pt #999999;
118 border: solid thin #999999;
119 border-collapse: collapse;
135 border: solid thin #cccccc;
142 border-bottom: solid thin #999999;
151 caption-side: bottom;
175 border: thin solid black;
183 H2 SPAN.info, H3 SPAN.info, H4 SPAN.info {
192 border-bottom: solid 2pt #000000;
195 DIV.indent, TABLE.indent {
203 border-collapse: collapse;
206 TABLE.indent TD, TABLE.indent TH {
211 border-collapse: collapse;
219 border-bottom: solid thin #cccccc;
224 vertical-align: bottom;
233 border-bottom: solid thin #eeeeee;
238 TABLE.list TR:nth-child(even) {
242 TABLE.list TR:nth-child(odd) {
261 font-family: monaco, courier, monospace;
265 border: solid thin #999999;
266 border-collapse: collapse;
271 DIV.summary TABLE TD, DIV.summary TABLE TH {
272 border: solid thin #999999;
278 DIV.summary TABLE THEAD TH {
282 /* API documentation styles... */
289 div.body h3, div.body h4, div.body h5 {
290 margin-bottom: 0.5em;
293 .class, .enumeration, .function, .struct, .typedef, .union {
294 border-bottom: solid thin #999999;
301 code, p.code, pre, ul.code li {
302 font-family: monaco, courier, monospace;
305 ul.code, ul.contents, ul.subcontents {
306 list-style-type: none;
316 ul.contents li ul.code, ul.contents li ul.subcontents {
329 margin-bottom: 0.5em;
332 /* This is just for the HTML files generated with the framedhelp target */
335 border: solid thin black;
344 div.contents ul.contents {
347 div.contents ul.subcontents li {
356 MIME API header for CUPS.
358 Copyright 2009 by Apple Inc.
360 These coded instructions, statements, and computer programs are the
361 property of Apple Inc. and are protected by Federal copyright
362 law. Distribution and use rights are outlined in the file "LICENSE.txt"
363 which should have been included with this file. If this file is
364 file is missing or damaged, see the license at "http://www.cups.org/".
367 <h1 class='title'
>MIME API
</h1>
369 <div class='summary'
><table summary='General Information'
>
383 <td>Programming:
<a href='api-overview.html' target='_top'
>Introduction to CUPS Programming
</a></td>
387 <h2 class=
"title">Contents
</h2>
388 <ul class=
"contents">
389 <li><a href=
"#OVERVIEW">Overview
</a></li>
390 <li><a href=
"#FUNCTIONS">Functions
</a><ul class=
"code">
391 <li><a href=
"#mimeAddFilter" title=
"Add a filter to the current MIME database.">mimeAddFilter
</a></li>
392 <li><a href=
"#mimeAddType" title=
"Add a MIME type to a database.">mimeAddType
</a></li>
393 <li><a href=
"#mimeAddTypeRule" title=
"Add a detection rule for a file type.">mimeAddTypeRule
</a></li>
394 <li><a href=
"#mimeDelete" title=
"Delete (free) a MIME database.">mimeDelete
</a></li>
395 <li><a href=
"#mimeDeleteFilter" title=
"Delete a filter from the MIME database.">mimeDeleteFilter
</a></li>
396 <li><a href=
"#mimeDeleteType" title=
"Delete a type from the MIME database.">mimeDeleteType
</a></li>
397 <li><a href=
"#mimeFileType" title=
"Determine the type of a file.">mimeFileType
</a></li>
398 <li><a href=
"#mimeFilter" title=
"Find the fastest way to convert from one type to another.">mimeFilter
</a></li>
399 <li><a href=
"#mimeFilter2" title=
"Find the fastest way to convert from one type to another,
400 including file size.">mimeFilter2
</a></li>
401 <li><a href=
"#mimeFilterLookup" title=
"Lookup a filter.">mimeFilterLookup
</a></li>
402 <li><a href=
"#mimeFirstFilter" title=
"Get the first filter in the MIME database.">mimeFirstFilter
</a></li>
403 <li><a href=
"#mimeFirstType" title=
"Get the first type in the MIME database.">mimeFirstType
</a></li>
404 <li><a href=
"#mimeLoad" title=
"Create a new MIME database from disk.">mimeLoad
</a></li>
405 <li><a href=
"#mimeLoadFilters" title=
"Load filter definitions from disk.">mimeLoadFilters
</a></li>
406 <li><a href=
"#mimeLoadTypes" title=
"Load type definitions from disk.">mimeLoadTypes
</a></li>
407 <li><a href=
"#mimeNew" title=
"Create a new, empty MIME database.">mimeNew
</a></li>
408 <li><a href=
"#mimeNextFilter" title=
"Get the next filter in the MIME database.">mimeNextFilter
</a></li>
409 <li><a href=
"#mimeNextType" title=
"Get the next type in the MIME database.">mimeNextType
</a></li>
410 <li><a href=
"#mimeNumFilters" title=
"Next type">mimeNumFilters
</a></li>
411 <li><a href=
"#mimeNumTypes" title=
"MIME database">mimeNumTypes
</a></li>
412 <li><a href=
"#mimeSetErrorCallback" title=
"Set the callback for error messages.">mimeSetErrorCallback
</a></li>
413 <li><a href=
"#mimeType" title=
"Lookup a file type.">mimeType
</a></li>
415 <li><a href=
"#TYPES">Data Types
</a><ul class=
"code">
416 <li><a href=
"#const" title=
"MIME Database">const
</a></li>
417 <li><a href=
"#mime_filter_t" title=
"MIME Conversion Filter Data">mime_filter_t
</a></li>
418 <li><a href=
"#mime_magic_t" title=
"MIME Magic Data">mime_magic_t
</a></li>
419 <li><a href=
"#mime_op_t" title=
"Types/structures...">mime_op_t
</a></li>
420 <li><a href=
"#mime_t" title=
"MIME Database">mime_t
</a></li>
421 <li><a href=
"#mime_type_t" title=
"MIME Type Data">mime_type_t
</a></li>
425 MIME API introduction for CUPS.
427 Copyright 2009 by Apple Inc.
429 These coded instructions, statements, and computer programs are the
430 property of Apple Inc. and are protected by Federal copyright
431 law. Distribution and use rights are outlined in the file "LICENSE.txt"
432 which should have been included with this file. If this file is
433 file is missing or damaged, see the license at "http://www.cups.org/".
436 <h2 class='title'
><a name='OVERVIEW'
>Overview
</a></h2>
438 <p>The MIME API provides file typing and conversion services for CUPS.
</p>
439 <h2 class=
"title"><a name=
"FUNCTIONS">Functions
</a></h2>
440 <h3 class=
"function"><a name=
"mimeAddFilter">mimeAddFilter
</a></h3>
441 <p class=
"description">Add a filter to the current MIME database.
</p>
443 <a href=
"#mime_filter_t">mime_filter_t
</a> *mimeAddFilter (
<br>
444 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
445 <a href=
"#mime_type_t">mime_type_t
</a> *src,
<br>
446 <a href=
"#mime_type_t">mime_type_t
</a> *dst,
<br>
447 int cost,
<br>
448 <a href=
"#const">const
</a> char *filter
<br>
450 <h4 class=
"parameters">Parameters
</h4>
453 <dd class=
"description">MIME database
</dd>
455 <dd class=
"description">Source type
</dd>
457 <dd class=
"description">Destination type
</dd>
459 <dd class=
"description">Relative time/resource cost
</dd>
461 <dd class=
"description">Filter program to run
</dd>
463 <h4 class=
"returnvalue">Return Value
</h4>
464 <p class=
"description">New filter
</p>
465 <h3 class=
"function"><a name=
"mimeAddType">mimeAddType
</a></h3>
466 <p class=
"description">Add a MIME type to a database.
</p>
468 <a href=
"#mime_type_t">mime_type_t
</a> *mimeAddType (
<br>
469 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
470 <a href=
"#const">const
</a> char *super,
<br>
471 <a href=
"#const">const
</a> char *type
<br>
473 <h4 class=
"parameters">Parameters
</h4>
476 <dd class=
"description">MIME database
</dd>
478 <dd class=
"description">Super-type name
</dd>
480 <dd class=
"description">Type name
</dd>
482 <h4 class=
"returnvalue">Return Value
</h4>
483 <p class=
"description">New (or existing) MIME type
</p>
484 <h3 class=
"function"><a name=
"mimeAddTypeRule">mimeAddTypeRule
</a></h3>
485 <p class=
"description">Add a detection rule for a file type.
</p>
487 int mimeAddTypeRule (
<br>
488 <a href=
"#mime_type_t">mime_type_t
</a> *mt,
<br>
489 <a href=
"#const">const
</a> char *rule
<br>
491 <h4 class=
"parameters">Parameters
</h4>
494 <dd class=
"description">Type to add to
</dd>
496 <dd class=
"description">Rule to add
</dd>
498 <h4 class=
"returnvalue">Return Value
</h4>
499 <p class=
"description">0 on success, -
1 on failure
</p>
500 <h3 class=
"function"><a name=
"mimeDelete">mimeDelete
</a></h3>
501 <p class=
"description">Delete (free) a MIME database.
</p>
503 void mimeDelete (
<br>
504 <a href=
"#mime_t">mime_t
</a> *mime
<br>
506 <h4 class=
"parameters">Parameters
</h4>
509 <dd class=
"description">MIME database
</dd>
511 <h3 class=
"function"><a name=
"mimeDeleteFilter">mimeDeleteFilter
</a></h3>
512 <p class=
"description">Delete a filter from the MIME database.
</p>
514 void mimeDeleteFilter (
<br>
515 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
516 <a href=
"#mime_filter_t">mime_filter_t
</a> *filter
<br>
518 <h4 class=
"parameters">Parameters
</h4>
521 <dd class=
"description">MIME database
</dd>
523 <dd class=
"description">Filter
</dd>
525 <h3 class=
"function"><a name=
"mimeDeleteType">mimeDeleteType
</a></h3>
526 <p class=
"description">Delete a type from the MIME database.
</p>
528 void mimeDeleteType (
<br>
529 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
530 <a href=
"#mime_type_t">mime_type_t
</a> *mt
<br>
532 <h4 class=
"parameters">Parameters
</h4>
535 <dd class=
"description">MIME database
</dd>
537 <dd class=
"description">Type
</dd>
539 <h3 class=
"function"><a name=
"mimeFileType">mimeFileType
</a></h3>
540 <p class=
"description">Determine the type of a file.
</p>
542 <a href=
"#mime_type_t">mime_type_t
</a> *mimeFileType (
<br>
543 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
544 <a href=
"#const">const
</a> char *pathname,
<br>
545 <a href=
"#const">const
</a> char *filename,
<br>
546 int *compression
<br>
548 <h4 class=
"parameters">Parameters
</h4>
551 <dd class=
"description">MIME database
</dd>
553 <dd class=
"description">Name of file to check on disk
</dd>
555 <dd class=
"description">Original filename or NULL
</dd>
557 <dd class=
"description">Is the file compressed?
</dd>
559 <h4 class=
"returnvalue">Return Value
</h4>
560 <p class=
"description">Type of file
</p>
561 <h3 class=
"function"><a name=
"mimeFilter">mimeFilter
</a></h3>
562 <p class=
"description">Find the fastest way to convert from one type to another.
</p>
564 cups_array_t *mimeFilter (
<br>
565 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
566 <a href=
"#mime_type_t">mime_type_t
</a> *src,
<br>
567 <a href=
"#mime_type_t">mime_type_t
</a> *dst,
<br>
568 int *cost
<br>
570 <h4 class=
"parameters">Parameters
</h4>
573 <dd class=
"description">MIME database
</dd>
575 <dd class=
"description">Source file type
</dd>
577 <dd class=
"description">Destination file type
</dd>
579 <dd class=
"description">Cost of filters
</dd>
581 <h4 class=
"returnvalue">Return Value
</h4>
582 <p class=
"description">Array of filters to run
</p>
583 <h3 class=
"function"><a name=
"mimeFilter2">mimeFilter2
</a></h3>
584 <p class=
"description">Find the fastest way to convert from one type to another,
585 including file size.
</p>
587 cups_array_t *mimeFilter2 (
<br>
588 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
589 <a href=
"#mime_type_t">mime_type_t
</a> *src,
<br>
590 size_t srcsize,
<br>
591 <a href=
"#mime_type_t">mime_type_t
</a> *dst,
<br>
592 int *cost
<br>
594 <h4 class=
"parameters">Parameters
</h4>
597 <dd class=
"description">MIME database
</dd>
599 <dd class=
"description">Source file type
</dd>
601 <dd class=
"description">Size of source file
</dd>
603 <dd class=
"description">Destination file type
</dd>
605 <dd class=
"description">Cost of filters
</dd>
607 <h4 class=
"returnvalue">Return Value
</h4>
608 <p class=
"description">Array of filters to run
</p>
609 <h3 class=
"function"><a name=
"mimeFilterLookup">mimeFilterLookup
</a></h3>
610 <p class=
"description">Lookup a filter.
</p>
612 <a href=
"#mime_filter_t">mime_filter_t
</a> *mimeFilterLookup (
<br>
613 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
614 <a href=
"#mime_type_t">mime_type_t
</a> *src,
<br>
615 <a href=
"#mime_type_t">mime_type_t
</a> *dst
<br>
617 <h4 class=
"parameters">Parameters
</h4>
620 <dd class=
"description">MIME database
</dd>
622 <dd class=
"description">Source type
</dd>
624 <dd class=
"description">Destination type
</dd>
626 <h4 class=
"returnvalue">Return Value
</h4>
627 <p class=
"description">Filter for src-
>dst
</p>
628 <h3 class=
"function"><a name=
"mimeFirstFilter">mimeFirstFilter
</a></h3>
629 <p class=
"description">Get the first filter in the MIME database.
</p>
631 <a href=
"#mime_filter_t">mime_filter_t
</a> *mimeFirstFilter (
<br>
632 <a href=
"#mime_t">mime_t
</a> *mime
<br>
634 <h4 class=
"parameters">Parameters
</h4>
637 <dd class=
"description">MIME database
</dd>
639 <h4 class=
"returnvalue">Return Value
</h4>
640 <p class=
"description">Filter or NULL
</p>
641 <h3 class=
"function"><a name=
"mimeFirstType">mimeFirstType
</a></h3>
642 <p class=
"description">Get the first type in the MIME database.
</p>
644 <a href=
"#mime_type_t">mime_type_t
</a> *mimeFirstType (
<br>
645 <a href=
"#mime_t">mime_t
</a> *mime
<br>
647 <h4 class=
"parameters">Parameters
</h4>
650 <dd class=
"description">MIME database
</dd>
652 <h4 class=
"returnvalue">Return Value
</h4>
653 <p class=
"description">Type or NULL
</p>
654 <h3 class=
"function"><a name=
"mimeLoad">mimeLoad
</a></h3>
655 <p class=
"description">Create a new MIME database from disk.
</p>
657 <a href=
"#mime_t">mime_t
</a> *mimeLoad (
<br>
658 <a href=
"#const">const
</a> char *pathname,
<br>
659 <a href=
"#const">const
</a> char *filterpath
<br>
661 <h4 class=
"parameters">Parameters
</h4>
664 <dd class=
"description">Directory to load
</dd>
666 <dd class=
"description">Directory to load
</dd>
668 <h4 class=
"returnvalue">Return Value
</h4>
669 <p class=
"description">New MIME database
</p>
670 <h4 class=
"discussion">Discussion
</h4>
671 <p class=
"discussion">This function uses
<a href=
"#mimeLoadFilters"><code>mimeLoadFilters
</code></a> and
<a href=
"#mimeLoadTypes"><code>mimeLoadTypes
</code></a> to
672 create a MIME database from a single directory.
</p>
673 <h3 class=
"function"><a name=
"mimeLoadFilters">mimeLoadFilters
</a></h3>
674 <p class=
"description">Load filter definitions from disk.
</p>
676 <a href=
"#mime_t">mime_t
</a> *mimeLoadFilters (
<br>
677 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
678 <a href=
"#const">const
</a> char *pathname,
<br>
679 <a href=
"#const">const
</a> char *filterpath
<br>
681 <h4 class=
"parameters">Parameters
</h4>
684 <dd class=
"description">MIME database
</dd>
686 <dd class=
"description">Directory to load from
</dd>
688 <dd class=
"description">Default filter program directory
</dd>
690 <h4 class=
"returnvalue">Return Value
</h4>
691 <p class=
"description">MIME database
</p>
692 <h4 class=
"discussion">Discussion
</h4>
693 <p class=
"discussion">This function loads all of the .convs files from the specified directory.
694 Use
<a href=
"#mimeLoadTypes"><code>mimeLoadTypes
</code></a> to load all types before you load the filters.
</p>
695 <h3 class=
"function"><a name=
"mimeLoadTypes">mimeLoadTypes
</a></h3>
696 <p class=
"description">Load type definitions from disk.
</p>
698 <a href=
"#mime_t">mime_t
</a> *mimeLoadTypes (
<br>
699 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
700 <a href=
"#const">const
</a> char *pathname
<br>
702 <h4 class=
"parameters">Parameters
</h4>
705 <dd class=
"description">MIME database or
<code>NULL
</code> to create a new one
</dd>
707 <dd class=
"description">Directory to load from
</dd>
709 <h4 class=
"returnvalue">Return Value
</h4>
710 <p class=
"description">MIME database
</p>
711 <h4 class=
"discussion">Discussion
</h4>
712 <p class=
"discussion">This function loads all of the .types files from the specified directory.
713 Use
<a href=
"#mimeLoadFilters"><code>mimeLoadFilters
</code></a> to load all filters after you load the types.
</p>
714 <h3 class=
"function"><a name=
"mimeNew">mimeNew
</a></h3>
715 <p class=
"description">Create a new, empty MIME database.
</p>
717 <a href=
"#mime_t">mime_t
</a> *mimeNew (void);
</p>
718 <h4 class=
"returnvalue">Return Value
</h4>
719 <p class=
"description">MIME database
</p>
720 <h3 class=
"function"><a name=
"mimeNextFilter">mimeNextFilter
</a></h3>
721 <p class=
"description">Get the next filter in the MIME database.
</p>
723 <a href=
"#mime_filter_t">mime_filter_t
</a> *mimeNextFilter (
<br>
724 <a href=
"#mime_t">mime_t
</a> *mime
<br>
726 <h4 class=
"parameters">Parameters
</h4>
729 <dd class=
"description">MIME database
</dd>
731 <h4 class=
"returnvalue">Return Value
</h4>
732 <p class=
"description">Filter or NULL
</p>
733 <h3 class=
"function"><a name=
"mimeNextType">mimeNextType
</a></h3>
734 <p class=
"description">Get the next type in the MIME database.
</p>
736 <a href=
"#mime_type_t">mime_type_t
</a> *mimeNextType (
<br>
737 <a href=
"#mime_t">mime_t
</a> *mime
<br>
739 <h4 class=
"parameters">Parameters
</h4>
742 <dd class=
"description">MIME database
</dd>
744 <h4 class=
"returnvalue">Return Value
</h4>
745 <p class=
"description">Type or NULL
</p>
746 <h3 class=
"function"><a name=
"mimeNumFilters">mimeNumFilters
</a></h3>
747 <p class=
"description">Next type
</p>
749 int mimeNumFilters (
<br>
750 <a href=
"#mime_t">mime_t
</a> *mime
<br>
752 <h4 class=
"parameters">Parameters
</h4>
755 <dd class=
"description">MIME database
</dd>
757 <h4 class=
"returnvalue">Return Value
</h4>
758 <p class=
"description">Get the number of filters in a MIME database.
</p>
759 <h3 class=
"function"><a name=
"mimeNumTypes">mimeNumTypes
</a></h3>
760 <p class=
"description">MIME database
</p>
762 int mimeNumTypes (
<br>
763 <a href=
"#mime_t">mime_t
</a> *mime
<br>
765 <h4 class=
"parameters">Parameters
</h4>
768 <dd class=
"description">MIME database
</dd>
770 <h4 class=
"returnvalue">Return Value
</h4>
771 <p class=
"description">Get the number of types in a MIME database.
</p>
772 <h3 class=
"function"><a name=
"mimeSetErrorCallback">mimeSetErrorCallback
</a></h3>
773 <p class=
"description">Set the callback for error messages.
</p>
775 void mimeSetErrorCallback (
<br>
776 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
777 mime_error_cb_t cb,
<br>
778 void *ctx
<br>
780 <h4 class=
"parameters">Parameters
</h4>
783 <dd class=
"description">MIME database
</dd>
785 <dd class=
"description">Callback function
</dd>
787 <dd class=
"description">Context pointer for callback
</dd>
789 <h3 class=
"function"><a name=
"mimeType">mimeType
</a></h3>
790 <p class=
"description">Lookup a file type.
</p>
792 <a href=
"#mime_type_t">mime_type_t
</a> *mimeType (
<br>
793 <a href=
"#mime_t">mime_t
</a> *mime,
<br>
794 <a href=
"#const">const
</a> char *super,
<br>
795 <a href=
"#const">const
</a> char *type
<br>
797 <h4 class=
"parameters">Parameters
</h4>
800 <dd class=
"description">MIME database
</dd>
802 <dd class=
"description">Super-type name
</dd>
804 <dd class=
"description">Type name
</dd>
806 <h4 class=
"returnvalue">Return Value
</h4>
807 <p class=
"description">Matching file type definition
</p>
808 <h2 class=
"title"><a name=
"TYPES">Data Types
</a></h2>
809 <h3 class=
"typedef"><a name=
"const">const
</a></h3>
810 <p class=
"description">MIME Database
</p>
812 typedef void (*constmime_error_cb_t)(void *;
814 <h3 class=
"typedef"><a name=
"mime_filter_t">mime_filter_t
</a></h3>
815 <p class=
"description">MIME Conversion Filter Data
</p>
817 typedef struct _mime_filter_s mime_filter_t;
819 <h3 class=
"typedef"><a name=
"mime_magic_t">mime_magic_t
</a></h3>
820 <p class=
"description">MIME Magic Data
</p>
822 typedef struct _mime_magic_s mime_magic_t;
824 <h3 class=
"typedef"><a name=
"mime_op_t">mime_op_t
</a></h3>
825 <p class=
"description">Types/structures...
</p>
827 typedef enum mime_op_t;
829 <h3 class=
"typedef"><a name=
"mime_t">mime_t
</a></h3>
830 <p class=
"description">MIME Database
</p>
832 typedef struct _mime_s mime_t;
834 <h3 class=
"typedef"><a name=
"mime_type_t">mime_type_t
</a></h3>
835 <p class=
"description">MIME Type Data
</p>
837 typedef struct _mime_type_s mime_type_t;