]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/log.c
...
[imagemagick] / MagickCore / log.c
index 0790fbc3645945599dd515b2884b2b32753587de..4221b318cb2296256c579f63039b01692103cf08 100644 (file)
 %                                September 2002                               %
 %                                                                             %
 %                                                                             %
-%  Copyright 1999-2014 ImageMagick Studio LLC, a non-profit organization      %
+%  Copyright 1999-2017 ImageMagick Studio LLC, a non-profit organization      %
 %  dedicated to making software imaging solutions freely available.           %
 %                                                                             %
 %  You may not use this file except in compliance with the License.  You may  %
 %  obtain a copy of the License at                                            %
 %                                                                             %
-%    http://www.imagemagick.org/script/license.php                            %
+%    https://www.imagemagick.org/script/license.php                           %
 %                                                                             %
 %  Unless required by applicable law or agreed to in writing, software        %
 %  distributed under the License is distributed on an "AS IS" BASIS,          %
@@ -46,7 +46,7 @@
 #include "MagickCore/configure-private.h"
 #include "MagickCore/exception.h"
 #include "MagickCore/exception-private.h"
-#include "MagickCore/hashmap.h"
+#include "MagickCore/linked-list.h"
 #include "MagickCore/log.h"
 #include "MagickCore/log-private.h"
 #include "MagickCore/memory_.h"
@@ -159,7 +159,7 @@ typedef struct _LogMapInfo
   Static declarations.
 */
 static const HandlerInfo
-  LogHandlers[] =
+  LogHandlers[32] =
   {
     { "Console", ConsoleHandler },
     { "Debug", DebugHandler },
@@ -168,6 +168,30 @@ static const HandlerInfo
     { "None", NoHandler },
     { "Stderr", StderrHandler },
     { "Stdout", StdoutHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
+    { (char *) NULL, UndefinedHandler },
     { (char *) NULL, UndefinedHandler }
   };
 
@@ -179,7 +203,7 @@ static const LogMapInfo
   };
 
 static char
-  log_name[MaxTextExtent] = "Magick";
+  log_name[MagickPathExtent] = "Magick";
 
 static LinkedListInfo
   *log_cache = (LinkedListInfo *) NULL;
@@ -231,12 +255,8 @@ static MagickBooleanType
 static LinkedListInfo *AcquireLogCache(const char *filename,
   ExceptionInfo *exception)
 {
-  const StringInfo
-    *option;
-
   LinkedListInfo
-    *log_cache,
-    *options;
+    *cache;
 
   MagickStatusType
     status;
@@ -247,19 +267,29 @@ static LinkedListInfo *AcquireLogCache(const char *filename,
   /*
     Load external log map.
   */
-  log_cache=NewLinkedList(0);
-  if (log_cache == (LinkedListInfo *) NULL)
+  cache=NewLinkedList(0);
+  if (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&=LoadLogCache(log_cache,(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&=LoadLogCache(cache,(const char *) GetStringInfoDatum(option),
+        GetStringInfoPath(option),0,exception);
+      option=(const StringInfo *) GetNextValueInLinkedList(options);
+    }
+    options=DestroyConfigureOptions(options);
   }
-  options=DestroyConfigureOptions(options);
+#endif
   /*
     Load built-in log map.
   */
@@ -286,13 +316,13 @@ static LinkedListInfo *AcquireLogCache(const char *filename,
     log_info->handler_mask=p->handler_mask;
     log_info->filename=ConstantString(p->filename);
     log_info->format=ConstantString(p->format);
-    log_info->signature=MagickSignature;
-    status&=AppendValueToLinkedList(log_cache,log_info);
+    log_info->signature=MagickCoreSignature;
+    status&=AppendValueToLinkedList(cache,log_info);
     if (status == MagickFalse)
       (void) ThrowMagickException(exception,GetMagickModule(),
         ResourceLimitError,"MemoryAllocationFailed","`%s'",log_info->name);
   }
-  return(log_cache);
+  return(cache);
 }
 \f
 /*
@@ -534,8 +564,8 @@ static int LogCompare(const void *x,const void *y)
 }
 #endif
 
-MagickExport char **GetLogList(const char *pattern,
-  size_t *number_preferences,ExceptionInfo *exception)
+MagickExport char **GetLogList(const char *pattern,size_t *number_preferences,
+  ExceptionInfo *exception)
 {
   char
     **preferences;
@@ -743,6 +773,8 @@ MagickExport MagickBooleanType ListLogInfo(FILE *file,ExceptionInfo *exception)
           size_t
             mask;
 
+          if (LogHandlers[j].name == (const char *) NULL)
+            break;
           mask=1;
           mask<<=j;
           if ((log_info[i]->handler_mask & mask) != 0)
@@ -750,8 +782,6 @@ MagickExport MagickBooleanType ListLogInfo(FILE *file,ExceptionInfo *exception)
               (void) FormatLocaleFile(file,"%s ",LogHandlers[j].name);
               length+=strlen(LogHandlers[j].name);
             }
-          if (LogHandlers[j].name == (const char * NULL))
-            break;
         }
         for (j=(ssize_t) length; j <= 12; j++)
           (void) FormatLocaleFile(file," ");
@@ -899,9 +929,8 @@ MagickPrivate void LogComponentTerminus(void)
 %    o format: the output format.
 %
 */
-static char *TranslateEvent(const LogEventType magick_unused(type),
-  const char *module,const char *function,const size_t line,
-  const char *domain,const char *event)
+static char *TranslateEvent(const char *module,const char *function,
+  const size_t line,const char *domain,const char *event)
 {
   char
     *text;
@@ -937,11 +966,11 @@ static char *TranslateEvent(const LogEventType magick_unused(type),
   text=AcquireString(event);
   if (log_info->format == (char *) NULL)
     return(text);
-  extent=strlen(event)+MaxTextExtent;
+  extent=strlen(event)+MagickPathExtent;
   if (LocaleCompare(log_info->format,"xml") == 0)
     {
       char
-        timestamp[MaxTextExtent];
+        timestamp[MagickPathExtent];
 
       /*
         Translate event in "XML" format.
@@ -973,10 +1002,10 @@ static char *TranslateEvent(const LogEventType magick_unused(type),
   for (p=log_info->format; *p != '\0'; p++)
   {
     *q='\0';
-    if ((size_t) (q-text+MaxTextExtent) >= extent)
+    if ((size_t) (q-text+MagickPathExtent) >= extent)
       {
-        extent+=MaxTextExtent;
-        text=(char *) ResizeQuantumMemory(text,extent+MaxTextExtent,
+        extent+=MagickPathExtent;
+        text=(char *) ResizeQuantumMemory(text,extent+MagickPathExtent,
           sizeof(*text));
         if (text == (char *) NULL)
           return((char *) NULL);
@@ -1142,15 +1171,15 @@ static char *TranslateFilename(const LogInfo *log_info)
   assert(log_info != (LogInfo *) NULL);
   assert(log_info->filename != (char *) NULL);
   filename=AcquireString((char *) NULL);
-  extent=MaxTextExtent;
+  extent=MagickPathExtent;
   q=filename;
   for (p=log_info->filename; *p != '\0'; p++)
   {
     *q='\0';
-    if ((size_t) (q-filename+MaxTextExtent) >= extent)
+    if ((size_t) (q-filename+MagickPathExtent) >= extent)
       {
-        extent+=MaxTextExtent;
-        filename=(char *) ResizeQuantumMemory(filename,extent+MaxTextExtent,
+        extent+=MagickPathExtent;
+        filename=(char *) ResizeQuantumMemory(filename,extent+MagickPathExtent,
           sizeof(*filename));
         if (filename == (char *) NULL)
           return((char *) NULL);
@@ -1224,11 +1253,10 @@ static char *TranslateFilename(const LogInfo *log_info)
 }
 
 MagickBooleanType LogMagickEventList(const LogEventType type,const char *module,
-  const char *function,const size_t line,const char *format,
-  va_list operands)
+  const char *function,const size_t line,const char *format,va_list operands)
 {
   char
-    event[MaxTextExtent],
+    event[MagickPathExtent],
     *text;
 
   const char
@@ -1258,13 +1286,13 @@ MagickBooleanType LogMagickEventList(const LogEventType type,const char *module,
     }
   domain=CommandOptionToMnemonic(MagickLogEventOptions,type);
 #if defined(MAGICKCORE_HAVE_VSNPRINTF)
-  n=vsnprintf(event,MaxTextExtent,format,operands);
+  n=vsnprintf(event,MagickPathExtent,format,operands);
 #else
   n=vsprintf(event,format,operands);
 #endif
   if (n < 0)
-    event[MaxTextExtent-1]='\0';
-  text=TranslateEvent(type,module,function,line,domain,event);
+    event[MagickPathExtent-1]='\0';
+  text=TranslateEvent(module,function,line,domain,event);
   if (text == (char *) NULL)
     {
       (void) ContinueTimer((TimerInfo *) &log_info->timer);
@@ -1373,7 +1401,7 @@ MagickBooleanType LogMagickEvent(const LogEventType type,const char *module,
 %                                                                             %
 %                                                                             %
 %                                                                             %
-+   L o a d L o g L i s t                                                     %
++   L o a d L o g C a c h e                                                   %
 %                                                                             %
 %                                                                             %
 %                                                                             %
@@ -1384,7 +1412,7 @@ MagickBooleanType LogMagickEvent(const LogEventType type,const char *module,
 %
 %  The format of the LoadLogCache method is:
 %
-%      MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
+%      MagickBooleanType LoadLogCache(LinkedListInfo *cache,const char *xml,
 %        const char *filename,const size_t depth,ExceptionInfo *exception)
 %
 %  A description of each parameter follows:
@@ -1398,11 +1426,11 @@ MagickBooleanType LogMagickEvent(const LogEventType type,const char *module,
 %    o exception: return any errors or warnings in this structure.
 %
 */
-static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
+static MagickBooleanType LoadLogCache(LinkedListInfo *cache,const char *xml,
   const char *filename,const size_t depth,ExceptionInfo *exception)
 {
   char
-    keyword[MaxTextExtent],
+    keyword[MagickPathExtent],
     *token;
 
   const char
@@ -1414,29 +1442,33 @@ static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
   MagickStatusType
     status;
 
+  size_t
+    extent;
+
   /*
     Load the log map file.
   */
   if (xml == (const char *) NULL)
     return(MagickFalse);
   status=MagickTrue;
-  token=AcquireString((const char *) xml);
+  token=AcquireString(xml);
+  extent=strlen(token)+MagickPathExtent;
   for (q=(const char *) xml; *q != '\0'; )
   {
     /*
       Interpret XML.
     */
-    GetMagickToken(q,&q,token);
+    GetNextToken(q,&q,extent,token);
     if (*token == '\0')
       break;
-    (void) CopyMagickString(keyword,token,MaxTextExtent);
+    (void) CopyMagickString(keyword,token,MagickPathExtent);
     if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
       {
         /*
           Doctype element.
         */
         while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
-          GetMagickToken(q,&q,token);
+          GetNextToken(q,&q,extent,token);
         continue;
       }
     if (LocaleNCompare(keyword,"<!--",4) == 0)
@@ -1445,7 +1477,7 @@ static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
           Comment element.
         */
         while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
-          GetMagickToken(q,&q,token);
+          GetNextToken(q,&q,extent,token);
         continue;
       }
     if (LocaleCompare(keyword,"<include") == 0)
@@ -1455,11 +1487,11 @@ static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
         */
         while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
         {
-          (void) CopyMagickString(keyword,token,MaxTextExtent);
-          GetMagickToken(q,&q,token);
+          (void) CopyMagickString(keyword,token,MagickPathExtent);
+          GetNextToken(q,&q,extent,token);
           if (*token != '=')
             continue;
-          GetMagickToken(q,&q,token);
+          GetNextToken(q,&q,extent,token);
           if (LocaleCompare(keyword,"file") == 0)
             {
               if (depth > 200)
@@ -1468,23 +1500,23 @@ static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
               else
                 {
                   char
-                    path[MaxTextExtent],
-                    *xml;
+                    path[MagickPathExtent],
+                    *file_xml;
 
                   GetPathComponent(filename,HeadPath,path);
                   if (*path != '\0')
                     (void) ConcatenateMagickString(path,DirectorySeparator,
-                      MaxTextExtent);
+                      MagickPathExtent);
                   if (*token == *DirectorySeparator)
-                    (void) CopyMagickString(path,token,MaxTextExtent);
+                    (void) CopyMagickString(path,token,MagickPathExtent);
                   else
-                    (void) ConcatenateMagickString(path,token,MaxTextExtent);
-                  xml=FileToXML(path,~0UL);
-                  if (xml != (char *) NULL)
+                    (void) ConcatenateMagickString(path,token,MagickPathExtent);
+                  file_xml=FileToXML(path,~0UL);
+                  if (file_xml != (char *) NULL)
                     {
-                      status&=LoadLogCache(log_cache,xml,path,depth+1,
+                      status&=LoadLogCache(cache,file_xml,path,depth+1,
                         exception);
-                      xml=DestroyString(xml);
+                      file_xml=DestroyString(file_xml);
                     }
                 }
             }
@@ -1502,25 +1534,25 @@ static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
         (void) ResetMagickMemory(log_info,0,sizeof(*log_info));
         log_info->path=ConstantString(filename);
         GetTimerInfo((TimerInfo *) &log_info->timer);
-        log_info->signature=MagickSignature;
+        log_info->signature=MagickCoreSignature;
         continue;
       }
     if (log_info == (LogInfo *) NULL)
       continue;
     if (LocaleCompare(keyword,"</logmap>") == 0)
       {
-        status=AppendValueToLinkedList(log_cache,log_info);
+        status=AppendValueToLinkedList(cache,log_info);
         if (status == MagickFalse)
           (void) ThrowMagickException(exception,GetMagickModule(),
             ResourceLimitError,"MemoryAllocationFailed","`%s'",filename);
         log_info=(LogInfo *) NULL;
         continue;
       }
-    GetMagickToken(q,(const char **) NULL,token);
+    GetNextToken(q,(const char **) NULL,extent,token);
     if (*token != '=')
       continue;
-    GetMagickToken(q,&q,token);
-    GetMagickToken(q,&q,token);
+    GetNextToken(q,&q,extent,token);
+    GetNextToken(q,&q,extent,token);
     switch (*keyword)
     {
       case 'E':
@@ -1601,7 +1633,7 @@ static MagickBooleanType LoadLogCache(LinkedListInfo *log_cache,const char *xml,
     }
   }
   token=DestroyString(token);
-  if (log_cache == (LinkedListInfo *) NULL)
+  if (cache == (LinkedListInfo *) NULL)
     return(MagickFalse);
   return(status != 0 ? MagickTrue : MagickFalse);
 }
@@ -1821,6 +1853,6 @@ MagickExport void SetLogMethod(MagickLogMethod method)
 MagickExport const char *SetLogName(const char *name)
 {
   if ((name != (char *) NULL) && (*name != '\0'))
-    (void) CopyMagickString(log_name,name,MaxTextExtent);
+    (void) CopyMagickString(log_name,name,MagickPathExtent);
   return(log_name);
 }