]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/mime.c
(no commit message)
[imagemagick] / MagickCore / mime.c
index ada6eb7789f59f596b586fa35a0aabf12256026f..25a71830b3598e050b866ff31b7e9e581b55d9d9 100644 (file)
@@ -125,7 +125,8 @@ static SemaphoreInfo
 */
 static MagickBooleanType
   IsMimeCacheInstantiated(ExceptionInfo *),
-  LoadMimeCache(const char *,const char *,const size_t,ExceptionInfo *);
+  LoadMimeCache(LinkedListInfo *,const char *,const char *,const size_t,
+    ExceptionInfo *);
 \f
 /*
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
@@ -138,8 +139,8 @@ static MagickBooleanType
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  AcquireMimeCache() caches one or more magic configurations which provides a
-%  mapping between magic attributes and a magic name.
+%  AcquireMimeCache() caches one or more magic configurations which provides
+%  mapping between magic attributes and a magic name.
 %
 %  The format of the AcquireMimeCache method is:
 %
@@ -156,15 +157,8 @@ static MagickBooleanType
 MagickExport LinkedListInfo *AcquireMimeCache(const char *filename,
   ExceptionInfo *exception)
 {
-#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
-  return(LoadMimeCache(MimeMap,"built-in",0,exception));
-#else
-  const StringInfo
-    *option;
-
   LinkedListInfo
-    *mime_cache,
-    *options;
+    *mime_cache;
 
   MagickStatusType
     status;
@@ -173,22 +167,28 @@ MagickExport LinkedListInfo *AcquireMimeCache(const char *filename,
   if (mime_cache == (LinkedListInfo *) NULL)
     ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
   status=MagickTrue;
-  options=GetConfigureOptions(filename,exception);
-  option=(const StringInfo *) GetNextValueInLinkedList(options);
-  while (option != (const StringInfo *) NULL)
+#if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
   {
-    status&=LoadMimeCache((const char *) GetStringInfoDatum(option),
-      GetStringInfoPath(option),0,exception);
+    const StringInfo
+      *option;
+
+    LinkedListInfo
+      *options;
+
+    options=GetConfigureOptions(filename,exception);
     option=(const StringInfo *) GetNextValueInLinkedList(options);
+    while (option != (const StringInfo *) NULL)
+    {
+      status&=LoadMimeCache(mime_cache,(const char *)
+        GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
+      option=(const StringInfo *) GetNextValueInLinkedList(options);
+    }
+    options=DestroyConfigureOptions(options);
   }
-  options=DestroyConfigureOptions(options);
-  if ((mime_cache == (LinkedListInfo *) NULL) ||
-      (IsLinkedListEmpty(mime_cache) != MagickFalse))
-    status&=LoadMimeCache(MimeMap,"built-in",0,exception);
-  else
-    ClearMagickException(exception);
-  return(mime_cache);
 #endif
+  if (IsLinkedListEmpty(mime_cache) != MagickFalse)
+    status&=LoadMimeCache(mime_cache,MimeMap,"built-in",0,exception);
+  return(mime_cache);
 }
 \f
 /*
@@ -341,16 +341,16 @@ MagickExport const MimeInfo *GetMimeInfo(const char *filename,
         if (endian == LSBEndian)
           {
             value=(ssize_t) (*q++);
-            value|=(*q++) << 8;
-            value|=(*q++) << 16;
-            value|=(*q++) << 24;
+            value|=((ssize_t) *q++) << 8;
+            value|=((ssize_t) *q++) << 16;
+            value|=((ssize_t) *q++) << 24;
           }
         else
           {
             value=(ssize_t) (*q++) << 24;
-            value|=(*q++) << 16;
-            value|=(*q++) << 8;
-            value|=(*q++);
+            value|=((ssize_t) *q++) << 16;
+            value|=((ssize_t) *q++) << 8;
+            value|=((ssize_t) *q++);
           }
         if (p->mask == 0)
           {
@@ -382,11 +382,11 @@ MagickExport const MimeInfo *GetMimeInfo(const char *filename,
     }
     p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache);
   }
-  if (p != (const MimeInfo *) NULL)
+  if (mime_info != (const MimeInfo *) NULL)
     (void) InsertValueInLinkedList(mime_cache,0,
       RemoveElementByValueFromLinkedList(mime_cache,p));
   UnlockSemaphoreInfo(mime_semaphore);
-  return(p);
+  return(mime_info);
 }
 \f
 /*
@@ -764,19 +764,20 @@ MagickExport MagickBooleanType ListMimeInfo(FILE *file,ExceptionInfo *exception)
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   L o a d M i m e L i s t                                                   %
++   L o a d M i m e C a c h e                                                 %
 %                                                                             %
 %                                                                             %
 %                                                                             %
 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
 %
-%  LoadMimeCache() loads the magic configurations which provides a mapping
-%  between magic attributes and a magic name.
+%  LoadMimeCache() loads the mime configurations which provides a mapping
+%  between mime attributes and a mime name.
 %
 %  The format of the LoadMimeCache method is:
 %
-%      MagickBooleanType LoadMimeCache(const char *xml,const char *filename,
-%        const size_t depth,ExceptionInfo *exception)
+%      MagickBooleanType LoadMimeCache(LinkedListInfo *mime_cache,
+%        const char *xml,const char *filename,const size_t depth,
+%        ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
 %
@@ -789,8 +790,9 @@ MagickExport MagickBooleanType ListMimeInfo(FILE *file,ExceptionInfo *exception)
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType LoadMimeCache(const char *xml,const char *filename,
-  const size_t depth,ExceptionInfo *exception)
+static MagickBooleanType LoadMimeCache(LinkedListInfo *mime_cache,
+  const char *xml,const char *filename,const size_t depth,
+  ExceptionInfo *exception)
 {
   const char
     *attribute;
@@ -813,16 +815,6 @@ static MagickBooleanType LoadMimeCache(const char *xml,const char *filename,
     "Loading mime map \"%s\" ...",filename);
   if (xml == (const char *) NULL)
     return(MagickFalse);
-  if (mime_cache == (LinkedListInfo *) NULL)
-    {
-      mime_cache=NewLinkedList(0);
-      if (mime_cache == (LinkedListInfo *) NULL)
-        {
-          ThrowFileException(exception,ResourceLimitError,
-            "MemoryAllocationFailed",filename);
-          return(MagickFalse);
-        }
-    }
   mime_map=NewXMLTree(xml,exception);
   if (mime_map == (XMLTreeInfo *) NULL)
     return(MagickFalse);
@@ -856,7 +848,7 @@ static MagickBooleanType LoadMimeCache(const char *xml,const char *filename,
             xml=FileToXML(path,~0UL);
             if (xml != (char *) NULL)
               {
-                status=LoadMimeCache(xml,path,depth+1,exception);
+                status&=LoadMimeCache(mime_cache,xml,path,depth+1,exception);
                 xml=DestroyString(xml);
               }
           }
@@ -967,7 +959,8 @@ static MagickBooleanType LoadMimeCache(const char *xml,const char *filename,
     if (attribute != (const char *) NULL)
       mime_info->priority=(ssize_t) strtol(attribute,(char **) NULL,0);
     attribute=GetXMLTreeAttribute(mime,"stealth");
-    mime_info->stealth=IsStringTrue(attribute);
+    if (attribute != (const char *) NULL)
+      mime_info->stealth=IsStringTrue(attribute);
     attribute=GetXMLTreeAttribute(mime,"type");
     if (attribute != (const char *) NULL)
       mime_info->type=ConstantString(attribute);
@@ -1050,7 +1043,8 @@ MagickExport char *MagickToMime(const char *magick)
 */
 MagickPrivate MagickBooleanType MimeComponentGenesis(void)
 {
-  mime_semaphore=AcquireSemaphoreInfo();
+  if (mime_semaphore == (SemaphoreInfo *) NULL)
+    mime_semaphore=AcquireSemaphoreInfo();
   return(MagickTrue);
 }
 \f