2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
5 % M M IIIII M M EEEEE %
9 % M M IIIII M M EEEEE %
12 % MagickCore Mime Methods %
18 % Copyright 1999-2011 ImageMagick Studio LLC, a non-profit organization %
19 % dedicated to making software imaging solutions freely available. %
21 % You may not use this file except in compliance with the License. You may %
22 % obtain a copy of the License at %
24 % http://www.imagemagick.org/MagicksToolkit/script/license.php %
26 % Unless required by applicable law or agreed to in writing, software %
27 % distributed under the License is distributed on an "AS IS" BASIS, %
28 % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
29 % See the License for the specific language governing permissions and %
30 % limitations under the License. %
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
40 #include "MagickCore/studio.h"
41 #include "MagickCore/blob.h"
42 #include "MagickCore/client.h"
43 #include "MagickCore/configure.h"
44 #include "MagickCore/exception.h"
45 #include "MagickCore/exception-private.h"
46 #include "MagickCore/hashmap.h"
47 #include "MagickCore/memory_.h"
48 #include "MagickCore/mime.h"
49 #include "MagickCore/mime-private.h"
50 #include "MagickCore/option.h"
51 #include "MagickCore/semaphore.h"
52 #include "MagickCore/string_.h"
53 #include "MagickCore/token.h"
54 #include "MagickCore/utility.h"
55 #include "MagickCore/utility-private.h"
56 #include "MagickCore/xml-tree.h"
57 #include "MagickCore/xml-tree-private.h"
62 #define MimeFilename "mime.xml"
112 "<?xml version=\"1.0\"?>"
116 static LinkedListInfo
117 *mime_list = (LinkedListInfo *) NULL;
120 *mime_semaphore = (SemaphoreInfo *) NULL;
122 static volatile MagickBooleanType
123 instantiate_mime = MagickFalse;
126 Forward declarations.
128 static MagickBooleanType
129 InitializeMimeList(ExceptionInfo *);
132 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
136 + G e t M i m e I n f o %
140 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
142 % GetMimeInfo() attempts to classify the content to identify which mime type
143 % is associated with the content, if any.
145 % The format of the GetMimeInfo method is:
147 % const MimeInfo *GetMimeInfo(const char *filename,
148 % const unsigned char *magic,const size_t length,
149 % ExceptionInfo *exception)
151 % A description of each parameter follows:
153 % o filename: If we cannot not classify the string, we attempt to classify
154 % based on the filename (e.g. *.pdf returns application/pdf).
156 % o magic: A binary string generally representing the first few characters
157 % of the image file or blob.
159 % o length: the length of the binary signature.
161 % o exception: return any errors or warnings in this structure.
164 MagickExport const MimeInfo *GetMimeInfo(const char *filename,
165 const unsigned char *magic,const size_t length,ExceptionInfo *exception)
173 register const MimeInfo
176 register const unsigned char
188 assert(exception != (ExceptionInfo *) NULL);
189 if ((mime_list == (LinkedListInfo *) NULL) ||
190 (instantiate_mime == MagickFalse))
191 if (InitializeMimeList(exception) == MagickFalse)
192 return((const MimeInfo *) NULL);
193 if ((mime_list == (LinkedListInfo *) NULL) ||
194 (IsLinkedListEmpty(mime_list) != MagickFalse))
195 return((const MimeInfo *) NULL);
196 if ((magic == (const unsigned char *) NULL) || (length == 0))
197 return((const MimeInfo *) GetValueFromLinkedList(mime_list,0));
199 return((const MimeInfo *) NULL);
203 mime_info=(const MimeInfo *) NULL;
205 LockSemaphoreInfo(mime_semaphore);
206 ResetLinkedListIterator(mime_list);
207 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
208 while (p != (const MimeInfo *) NULL)
210 assert(p->offset >= 0);
211 if (mime_info != (const MimeInfo *) NULL)
212 if (p->priority > mime_info->priority)
214 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
217 if ((p->pattern != (char *) NULL) && (filename != (char *) NULL))
219 if (GlobExpression(filename,p->pattern,MagickFalse) != MagickFalse)
221 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
224 switch (p->data_type)
228 if ((size_t) (p->offset+4) > length)
231 value=(ssize_t) (*q++);
234 if (p->value == value)
239 if ((p->value & p->mask) == value)
246 if ((size_t) (p->offset+4) > length)
250 if (p->endian == UndefinedEndian)
251 endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
252 if (endian == LSBEndian)
254 value=(ssize_t) (*q++);
259 value=(ssize_t) (*q++) << 8;
264 if (p->value == value)
269 if ((p->value & p->mask) == value)
276 if ((size_t) (p->offset+4) > length)
280 if (p->endian == UndefinedEndian)
281 endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian;
282 if (endian == LSBEndian)
284 value=(ssize_t) (*q++);
291 value=(ssize_t) (*q++) << 24;
298 if (p->value == value)
303 if ((p->value & p->mask) == value)
311 for (i=0; i <= (ssize_t) p->extent; i++)
313 if ((size_t) (p->offset+i+p->length) > length)
315 if (memcmp(magic+p->offset+i,p->magic,p->length) == 0)
324 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
326 if (p != (const MimeInfo *) NULL)
327 (void) InsertValueInLinkedList(mime_list,0,
328 RemoveElementByValueFromLinkedList(mime_list,p));
329 UnlockSemaphoreInfo(mime_semaphore);
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
338 % G e t M i m e I n f o L i s t %
342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
344 % GetMimeInfoList() returns any image aliases that match the specified
347 % The magic of the GetMimeInfoList function is:
349 % const MimeInfo **GetMimeInfoList(const char *pattern,
350 % size_t *number_aliases,ExceptionInfo *exception)
352 % A description of each parameter follows:
354 % o pattern: Specifies a pointer to a text string containing a pattern.
356 % o number_aliases: This integer returns the number of magics in the
359 % o exception: return any errors or warnings in this structure.
363 #if defined(__cplusplus) || defined(c_plusplus)
367 static int MimeInfoCompare(const void *x,const void *y)
373 p=(const MimeInfo **) x,
374 q=(const MimeInfo **) y;
375 if (strcasecmp((*p)->path,(*q)->path) == 0)
376 return(strcasecmp((*p)->type,(*q)->type));
377 return(strcasecmp((*p)->path,(*q)->path));
380 #if defined(__cplusplus) || defined(c_plusplus)
384 MagickExport const MimeInfo **GetMimeInfoList(const char *pattern,
385 size_t *number_aliases,ExceptionInfo *exception)
390 register const MimeInfo
399 assert(pattern != (char *) NULL);
400 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
401 assert(number_aliases != (size_t *) NULL);
403 p=GetMimeInfo((char *) NULL,(unsigned char *) "*",0,exception);
404 if (p == (const MimeInfo *) NULL)
405 return((const MimeInfo **) NULL);
406 aliases=(const MimeInfo **) AcquireQuantumMemory((size_t)
407 GetNumberOfElementsInLinkedList(mime_list)+1UL,sizeof(*aliases));
408 if (aliases == (const MimeInfo **) NULL)
409 return((const MimeInfo **) NULL);
413 LockSemaphoreInfo(mime_semaphore);
414 ResetLinkedListIterator(mime_list);
415 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
416 for (i=0; p != (const MimeInfo *) NULL; )
418 if ((p->stealth == MagickFalse) &&
419 (GlobExpression(p->type,pattern,MagickFalse) != MagickFalse))
421 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
423 UnlockSemaphoreInfo(mime_semaphore);
424 qsort((void *) aliases,(size_t) i,sizeof(*aliases),MimeInfoCompare);
425 aliases[i]=(MimeInfo *) NULL;
426 *number_aliases=(size_t) i;
431 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
435 % G e t M i m e L i s t %
439 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
441 % GetMimeList() returns any image format alias that matches the specified
444 % The format of the GetMimeList function is:
446 % char **GetMimeList(const char *pattern,size_t *number_aliases,
447 % ExceptionInfo *exception)
449 % A description of each parameter follows:
451 % o pattern: Specifies a pointer to a text string containing a pattern.
453 % o number_aliases: This integer returns the number of image format aliases
456 % o exception: return any errors or warnings in this structure.
460 #if defined(__cplusplus) || defined(c_plusplus)
464 static int MimeCompare(const void *x,const void *y)
472 return(strcasecmp(p,q));
475 #if defined(__cplusplus) || defined(c_plusplus)
479 MagickExport char **GetMimeList(const char *pattern,
480 size_t *number_aliases,ExceptionInfo *exception)
485 register const MimeInfo
492 Allocate configure list.
494 assert(pattern != (char *) NULL);
495 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
496 assert(number_aliases != (size_t *) NULL);
498 p=GetMimeInfo((char *) NULL,(unsigned char *) "*",0,exception);
499 if (p == (const MimeInfo *) NULL)
500 return((char **) NULL);
501 aliases=(char **) AcquireQuantumMemory((size_t)
502 GetNumberOfElementsInLinkedList(mime_list)+1UL,sizeof(*aliases));
503 if (aliases == (char **) NULL)
504 return((char **) NULL);
505 LockSemaphoreInfo(mime_semaphore);
506 ResetLinkedListIterator(mime_list);
507 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
508 for (i=0; p != (const MimeInfo *) NULL; )
510 if ((p->stealth == MagickFalse) &&
511 (GlobExpression(p->type,pattern,MagickFalse) != MagickFalse))
512 aliases[i++]=ConstantString(p->type);
513 p=(const MimeInfo *) GetNextValueInLinkedList(mime_list);
515 UnlockSemaphoreInfo(mime_semaphore);
516 qsort((void *) aliases,(size_t) i,sizeof(*aliases),MimeCompare);
517 aliases[i]=(char *) NULL;
518 *number_aliases=(size_t) i;
523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
527 % G e t M i m e D e s c r i p t i o n %
531 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533 % GetMimeDescription() returns the mime type description.
535 % The format of the GetMimeDescription method is:
537 % const char *GetMimeDescription(const MimeInfo *mime_info)
539 % A description of each parameter follows:
541 % o mime_info: The magic info.
544 MagickExport const char *GetMimeDescription(const MimeInfo *mime_info)
546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
547 assert(mime_info != (MimeInfo *) NULL);
548 assert(mime_info->signature == MagickSignature);
549 return(mime_info->description);
553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
557 % G e t M i m e T y p e %
561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
563 % GetMimeType() returns the mime type.
565 % The format of the GetMimeType method is:
567 % const char *GetMimeType(const MimeInfo *mime_info)
569 % A description of each parameter follows:
571 % o mime_info: The magic info.
574 MagickExport const char *GetMimeType(const MimeInfo *mime_info)
576 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
577 assert(mime_info != (MimeInfo *) NULL);
578 assert(mime_info->signature == MagickSignature);
579 return(mime_info->type);
583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
587 + I n i t i a l i z e M i m e L i s t %
591 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
593 % InitializeMimeList() initializes the mime list.
595 % The format of the InitializeMimeList method is:
597 % MagickBooleanType InitializeMimeList(ExceptionInfo *exception)
599 % A description of each parameter follows.
601 % o exception: return any errors or warnings in this structure.
604 static MagickBooleanType InitializeMimeList(ExceptionInfo *exception)
606 if ((mime_list == (LinkedListInfo *) NULL) &&
607 (instantiate_mime == MagickFalse))
609 if (mime_semaphore == (SemaphoreInfo *) NULL)
610 AcquireSemaphoreInfo(&mime_semaphore);
611 LockSemaphoreInfo(mime_semaphore);
612 if ((mime_list == (LinkedListInfo *) NULL) &&
613 (instantiate_mime == MagickFalse))
615 (void) LoadMimeLists(MimeFilename,exception);
616 instantiate_mime=MagickTrue;
618 UnlockSemaphoreInfo(mime_semaphore);
620 return(mime_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
624 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
628 % L i s t M i m e I n f o %
632 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
634 % ListMimeInfo() lists the magic info to a file.
636 % The format of the ListMimeInfo method is:
638 % MagickBooleanType ListMimeInfo(FILE *file,ExceptionInfo *exception)
640 % A description of each parameter follows.
642 % o file: An pointer to a FILE.
644 % o exception: return any errors or warnings in this structure.
647 MagickExport MagickBooleanType ListMimeInfo(FILE *file,ExceptionInfo *exception)
664 if (file == (const FILE *) NULL)
666 mime_info=GetMimeInfoList("*",&number_aliases,exception);
667 if (mime_info == (const MimeInfo **) NULL)
670 path=(const char *) NULL;
671 for (i=0; i < (ssize_t) number_aliases; i++)
673 if (mime_info[i]->stealth != MagickFalse)
675 if ((path == (const char *) NULL) ||
676 (strcasecmp(path,mime_info[i]->path) != 0))
678 if (mime_info[i]->path != (char *) NULL)
679 (void) FormatLocaleFile(file,"\nPath: %s\n\n",mime_info[i]->path);
680 (void) FormatLocaleFile(file,"Type Description\n");
681 (void) FormatLocaleFile(file,
682 "-------------------------------------------------"
683 "------------------------------\n");
685 path=mime_info[i]->path;
686 (void) FormatLocaleFile(file,"%s",mime_info[i]->type);
687 if (strlen(mime_info[i]->type) <= 25)
689 for (j=(ssize_t) strlen(mime_info[i]->type); j <= 27; j++)
690 (void) FormatLocaleFile(file," ");
694 (void) FormatLocaleFile(file,"\n");
695 for (j=0; j <= 27; j++)
696 (void) FormatLocaleFile(file," ");
698 if (mime_info[i]->description != (char *) NULL)
699 (void) FormatLocaleFile(file,"%s",mime_info[i]->description);
700 (void) FormatLocaleFile(file,"\n");
703 mime_info=(const MimeInfo **) RelinquishMagickMemory((void *) mime_info);
708 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
712 + L o a d M i m e L i s t %
716 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
718 % LoadMimeList() loads the magic configuration file which provides a mapping
719 % between magic attributes and a magic name.
721 % The format of the LoadMimeList method is:
723 % MagickBooleanType LoadMimeList(const char *xml,const char *filename,
724 % const size_t depth,ExceptionInfo *exception)
726 % A description of each parameter follows:
728 % o xml: The mime list in XML format.
730 % o filename: The mime list filename.
732 % o depth: depth of <include /> statements.
734 % o exception: return any errors or warnings in this structure.
737 static MagickBooleanType LoadMimeList(const char *xml,const char *filename,
738 const size_t depth,ExceptionInfo *exception)
744 *mime_info = (MimeInfo *) NULL;
755 Load the mime map file.
757 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
758 "Loading mime map \"%s\" ...",filename);
759 if (xml == (const char *) NULL)
761 if (mime_list == (LinkedListInfo *) NULL)
763 mime_list=NewLinkedList(0);
764 if (mime_list == (LinkedListInfo *) NULL)
766 ThrowFileException(exception,ResourceLimitError,
767 "MemoryAllocationFailed",filename);
771 mime_map=NewXMLTree(xml,exception);
772 if (mime_map == (XMLTreeInfo *) NULL)
775 include=GetXMLTreeChild(mime_map,"include");
776 while (include != (XMLTreeInfo *) NULL)
779 Process include element.
781 attribute=GetXMLTreeAttribute(include,"file");
782 if (attribute != (const char *) NULL)
785 (void) ThrowMagickException(exception,GetMagickModule(),
786 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",filename);
793 GetPathComponent(filename,HeadPath,path);
795 (void) ConcatenateMagickString(path,DirectorySeparator,
797 if (*attribute == *DirectorySeparator)
798 (void) CopyMagickString(path,attribute,MaxTextExtent);
800 (void) ConcatenateMagickString(path,attribute,MaxTextExtent);
801 xml=FileToString(path,~0,exception);
802 if (xml != (char *) NULL)
804 status=LoadMimeList(xml,path,depth+1,exception);
805 xml=DestroyString(xml);
809 include=GetNextXMLTreeTag(include);
811 mime=GetXMLTreeChild(mime_map,"mime");
812 while (mime != (XMLTreeInfo *) NULL)
818 Process mime element.
820 mime_info=(MimeInfo *) AcquireMagickMemory(sizeof(*mime_info));
821 if (mime_info == (MimeInfo *) NULL)
822 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
823 (void) ResetMagickMemory(mime_info,0,sizeof(*mime_info));
824 mime_info->path=ConstantString(filename);
825 mime_info->signature=MagickSignature;
826 attribute=GetXMLTreeAttribute(mime,"data-type");
827 if (attribute != (const char *) NULL)
828 mime_info->data_type=(DataType) ParseCommandOption(MagickDataTypeOptions,
829 MagickTrue,attribute);
830 attribute=GetXMLTreeAttribute(mime,"description");
831 if (attribute != (const char *) NULL)
832 mime_info->description=ConstantString(attribute);
833 attribute=GetXMLTreeAttribute(mime,"endian");
834 if (attribute != (const char *) NULL)
835 mime_info->endian=(EndianType) ParseCommandOption(MagickEndianOptions,
836 MagickTrue,attribute);
837 attribute=GetXMLTreeAttribute(mime,"magic");
838 if (attribute != (const char *) NULL)
846 register unsigned char
849 token=AcquireString(attribute);
850 (void) SubstituteString((char **) &token,"<","<");
851 (void) SubstituteString((char **) &token,"&","&");
852 (void) SubstituteString((char **) &token,""","\"");
853 mime_info->magic=(unsigned char *) AcquireString(token);
855 for (p=token; *p != '\0'; )
860 if (isdigit((int) ((unsigned char) *p)) != 0)
865 *q++=(unsigned char) strtol(p,&end,8);
872 case 'b': *q='\b'; break;
873 case 'f': *q='\f'; break;
874 case 'n': *q='\n'; break;
875 case 'r': *q='\r'; break;
876 case 't': *q='\t'; break;
877 case 'v': *q='\v'; break;
878 case 'a': *q='a'; break;
879 case '?': *q='\?'; break;
880 default: *q=(unsigned char) (*p); break;
887 *q++=(unsigned char) (*p++);
890 token=DestroyString(token);
891 if (mime_info->data_type != StringData)
892 mime_info->value=(ssize_t) strtoul((char *) mime_info->magic,
895 attribute=GetXMLTreeAttribute(mime,"mask");
896 if (attribute != (const char *) NULL)
897 mime_info->mask=(ssize_t) strtoul(attribute,(char **) NULL,0);
898 attribute=GetXMLTreeAttribute(mime,"offset");
899 if (attribute != (const char *) NULL)
904 mime_info->offset=(MagickOffsetType) strtol(attribute,&c,0);
906 mime_info->extent=(size_t) strtol(c+1,(char **) NULL,0);
908 attribute=GetXMLTreeAttribute(mime,"pattern");
909 if (attribute != (const char *) NULL)
910 mime_info->pattern=ConstantString(attribute);
911 attribute=GetXMLTreeAttribute(mime,"priority");
912 if (attribute != (const char *) NULL)
913 mime_info->priority=(ssize_t) strtol(attribute,(char **) NULL,0);
914 attribute=GetXMLTreeAttribute(mime,"stealth");
915 if (attribute != (const char *) NULL)
916 mime_info->stealth=IsMagickTrue(attribute);
917 attribute=GetXMLTreeAttribute(mime,"type");
918 if (attribute != (const char *) NULL)
919 mime_info->type=ConstantString(attribute);
920 status=AppendValueToLinkedList(mime_list,mime_info);
921 if (status == MagickFalse)
922 (void) ThrowMagickException(exception,GetMagickModule(),
923 ResourceLimitError,"MemoryAllocationFailed","`%s'",filename);
924 mime=GetNextXMLTreeTag(mime);
926 mime_map=DestroyXMLTree(mime_map);
931 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
935 % L o a d M i m e L i s t s %
939 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
941 % LoadMimeList() loads one or more magic configuration file which provides a
942 % mapping between magic attributes and a magic name.
944 % The format of the LoadMimeLists method is:
946 % MagickBooleanType LoadMimeLists(const char *filename,
947 % ExceptionInfo *exception)
949 % A description of each parameter follows:
951 % o filename: the font file name.
953 % o exception: return any errors or warnings in this structure.
956 MagickExport MagickBooleanType LoadMimeLists(const char *filename,
957 ExceptionInfo *exception)
959 #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
960 return(LoadMimeList(MimeMap,"built-in",0,exception));
972 options=GetConfigureOptions(filename,exception);
973 option=(const StringInfo *) GetNextValueInLinkedList(options);
974 while (option != (const StringInfo *) NULL)
976 status|=LoadMimeList((const char *) GetStringInfoDatum(option),
977 GetStringInfoPath(option),0,exception);
978 option=(const StringInfo *) GetNextValueInLinkedList(options);
980 options=DestroyConfigureOptions(options);
981 if ((mime_list == (LinkedListInfo *) NULL) ||
982 (IsLinkedListEmpty(mime_list) != MagickFalse))
983 status|=LoadMimeList(MimeMap,"built-in",0,exception);
985 ClearMagickException(exception);
986 return(status != 0 ? MagickTrue : MagickFalse);
991 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
995 + M a g i c k T o M i m e %
999 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1001 % MagickToMime() returns the officially registered (or de facto) MIME
1002 % media-type corresponding to a magick string. If there is no registered
1003 % media-type, then the string "image/x-magick" (all lower case) is returned.
1004 % The returned string must be deallocated by the user.
1006 % The format of the MagickToMime method is:
1008 % char *MagickToMime(const char *magick)
1010 % A description of each parameter follows.
1012 % o magick: ImageMagick format specification "magick" tag.
1015 MagickExport char *MagickToMime(const char *magick)
1018 filename[MaxTextExtent],
1019 media[MaxTextExtent];
1027 (void) FormatLocaleString(filename,MaxTextExtent,"file.%s",magick);
1028 LocaleLower(filename);
1029 exception=AcquireExceptionInfo();
1030 mime_info=GetMimeInfo(filename,(unsigned char *) " ",1,exception);
1031 exception=DestroyExceptionInfo(exception);
1032 if (mime_info != (const MimeInfo *) NULL)
1033 return(ConstantString(GetMimeType(mime_info)));
1034 (void) FormatLocaleString(media,MaxTextExtent,"image/x-%s",magick);
1035 LocaleLower(media+8);
1036 return(ConstantString(media));
1040 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1044 + M i m e C o m p o n e n t G e n e s i s %
1048 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050 % MimeComponentGenesis() instantiates the mime component.
1052 % The format of the MimeComponentGenesis method is:
1054 % MagickBooleanType MimeComponentGenesis(void)
1057 MagickPrivate MagickBooleanType MimeComponentGenesis(void)
1059 AcquireSemaphoreInfo(&mime_semaphore);
1064 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1068 + M i m e C o m p o n e n t T e r m i n u s %
1072 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1074 % MimeComponentTerminus() destroys the mime component.
1076 % The format of the MimeComponentTerminus method is:
1078 % MimeComponentTerminus(void)
1082 static void *DestroyMimeElement(void *mime_info)
1087 p=(MimeInfo *) mime_info;
1088 if (p->magic != (unsigned char *) NULL)
1089 p->magic=(unsigned char *) RelinquishMagickMemory(p->magic);
1090 if (p->pattern != (char *) NULL)
1091 p->pattern=DestroyString(p->pattern);
1092 if (p->description != (char *) NULL)
1093 p->description=DestroyString(p->description);
1094 if (p->type != (char *) NULL)
1095 p->type=DestroyString(p->type);
1096 if (p->path != (char *) NULL)
1097 p->path=DestroyString(p->path);
1098 p=(MimeInfo *) RelinquishMagickMemory(p);
1099 return((void *) NULL);
1102 MagickPrivate void MimeComponentTerminus(void)
1104 if (mime_semaphore == (SemaphoreInfo *) NULL)
1105 AcquireSemaphoreInfo(&mime_semaphore);
1106 LockSemaphoreInfo(mime_semaphore);
1107 if (mime_list != (LinkedListInfo *) NULL)
1108 mime_list=DestroyLinkedList(mime_list,DestroyMimeElement);
1109 instantiate_mime=MagickFalse;
1110 UnlockSemaphoreInfo(mime_semaphore);
1111 DestroySemaphoreInfo(&mime_semaphore);