#include "MagickCore/xml-tree.h"
#include "MagickCore/xml-tree-private.h"
\f
-/*
- Define declarations.
-*/
-#define MagickCoderFilename "coder.xml"
-\f
/*
Typedef declarations.
*/
Forward declarations.
*/
static MagickBooleanType
- IsCoderTreeInstantiated(ExceptionInfo *),
- LoadCoderCache(SplayTreeInfo *,const char *,const char *,const size_t,
- ExceptionInfo *);
+ IsCoderTreeInstantiated(ExceptionInfo *);
\f
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
return(RelinquishMagickMemory(p));
}
-static SplayTreeInfo *AcquireCoderCache(const char *filename,
- ExceptionInfo *exception)
+static SplayTreeInfo *AcquireCoderCache(ExceptionInfo *exception)
{
MagickStatusType
status;
*cache;
/*
- Load external coder map.
+ Load built-in coder map.
*/
cache=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory,
DestroyCoderNode);
status=MagickTrue;
-#if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
- {
- const StringInfo
- *option;
-
- LinkedListInfo
- *options;
-
- options=GetConfigureOptions(filename,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- while (option != (const StringInfo *) NULL)
- {
- status&=LoadCoderCache(cache,(const char *) GetStringInfoDatum(option),
- GetStringInfoPath(option),0,exception);
- option=(const StringInfo *) GetNextValueInLinkedList(options);
- }
- options=DestroyConfigureOptions(options);
- }
-#endif
- /*
- Load built-in coder map.
- */
for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++)
{
CoderInfo
ActivateSemaphoreInfo(&coder_semaphore);
LockSemaphoreInfo(coder_semaphore);
if (coder_cache == (SplayTreeInfo *) NULL)
- coder_cache=AcquireCoderCache(MagickCoderFilename,exception);
+ coder_cache=AcquireCoderCache(exception);
UnlockSemaphoreInfo(coder_semaphore);
}
return(coder_cache != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
(void) fflush(file);
return(MagickTrue);
}
-\f
-/*
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-% %
-% %
-% %
-+ L o a d C o d e r C a c h e %
-% %
-% %
-% %
-%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
-%
-% LoadCoderCache() loads the coder configurations which provides a
-% mapping between coder attributes and a coder name.
-%
-% The format of the LoadCoderCache coder is:
-%
-% MagickBooleanType LoadCoderCache(SplayTreeInfo *cache,const char *xml,
-% const char *filename,const size_t depth,ExceptionInfo *exception)
-%
-% A description of each parameter follows:
-%
-% o xml: The coder list in XML format.
-%
-% o filename: The coder list filename.
-%
-% o depth: depth of <include /> statements.
-%
-% o exception: return any errors or warnings in this structure.
-%
-*/
-static MagickBooleanType LoadCoderCache(SplayTreeInfo *cache,const char *xml,
- const char *filename,const size_t depth,ExceptionInfo *exception)
-{
- char
- keyword[MagickPathExtent],
- *token;
-
- const char
- *q;
-
- CoderInfo
- *coder_info;
-
- MagickStatusType
- status;
-
- size_t
- extent;
-
- /*
- Load the coder map file.
- */
- (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
- "Loading coder configuration file \"%s\" ...",filename);
- if (xml == (const char *) NULL)
- return(MagickFalse);
- status=MagickTrue;
- coder_info=(CoderInfo *) NULL;
- token=AcquireString(xml);
- extent=strlen(token)+MagickPathExtent;
- for (q=(char *) xml; *q != '\0'; )
- {
- /*
- Interpret XML.
- */
- GetNextToken(q,&q,extent,token);
- if (*token == '\0')
- break;
- (void) CopyMagickString(keyword,token,MagickPathExtent);
- if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
- {
- /*
- Doctype element.
- */
- while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
- GetNextToken(q,&q,extent,token);
- continue;
- }
- if (LocaleNCompare(keyword,"<!--",4) == 0)
- {
- /*
- Comment element.
- */
- while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
- GetNextToken(q,&q,extent,token);
- continue;
- }
- if (LocaleCompare(keyword,"<include") == 0)
- {
- /*
- Include element.
- */
- while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
- {
- (void) CopyMagickString(keyword,token,MagickPathExtent);
- GetNextToken(q,&q,extent,token);
- if (*token != '=')
- continue;
- GetNextToken(q,&q,extent,token);
- if (LocaleCompare(keyword,"file") == 0)
- {
- if (depth > MagickMaxRecursionDepth)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ConfigureError,"IncludeNodeNestedTooDeeply","`%s'",token);
- else
- {
- char
- path[MagickPathExtent],
- *file_xml;
-
- GetPathComponent(filename,HeadPath,path);
- if (*path != '\0')
- (void) ConcatenateMagickString(path,DirectorySeparator,
- MagickPathExtent);
- if (*token == *DirectorySeparator)
- (void) CopyMagickString(path,token,MagickPathExtent);
- else
- (void) ConcatenateMagickString(path,token,MagickPathExtent);
- file_xml=FileToXML(path,~0UL);
- if (file_xml != (char *) NULL)
- {
- status&=LoadCoderCache(cache,file_xml,path,depth+1,
- exception);
- file_xml=DestroyString(file_xml);
- }
- }
- }
- }
- continue;
- }
- if (LocaleCompare(keyword,"<coder") == 0)
- {
- /*
- Coder element.
- */
- coder_info=(CoderInfo *) AcquireCriticalMemory(sizeof(*coder_info));
- (void) memset(coder_info,0,sizeof(*coder_info));
- coder_info->path=ConstantString(filename);
- coder_info->exempt=MagickFalse;
- coder_info->signature=MagickCoreSignature;
- continue;
- }
- if (coder_info == (CoderInfo *) NULL)
- continue;
- if ((LocaleCompare(keyword,"/>") == 0) ||
- (LocaleCompare(keyword,"</policy>") == 0))
- {
- status=AddValueToSplayTree(cache,ConstantString(coder_info->magick),
- coder_info);
- if (status == MagickFalse)
- (void) ThrowMagickException(exception,GetMagickModule(),
- ResourceLimitError,"MemoryAllocationFailed","`%s'",
- coder_info->magick);
- coder_info=(CoderInfo *) NULL;
- continue;
- }
- GetNextToken(q,(const char **) NULL,extent,token);
- if (*token != '=')
- continue;
- GetNextToken(q,&q,extent,token);
- GetNextToken(q,&q,extent,token);
- switch (*keyword)
- {
- case 'M':
- case 'm':
- {
- if (LocaleCompare((char *) keyword,"magick") == 0)
- {
- coder_info->magick=ConstantString(token);
- break;
- }
- break;
- }
- case 'N':
- case 'n':
- {
- if (LocaleCompare((char *) keyword,"name") == 0)
- {
- coder_info->name=ConstantString(token);
- break;
- }
- break;
- }
- case 'S':
- case 's':
- {
- if (LocaleCompare((char *) keyword,"stealth") == 0)
- {
- coder_info->stealth=IsStringTrue(token);
- break;
- }
- break;
- }
- default:
- break;
- }
- }
- token=(char *) RelinquishMagickMemory(token);
- return(status != 0 ? MagickTrue : MagickFalse);
-}