/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% C a t c h E x c e p t i o n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% CatchException() returns if no exceptions is found otherwise it reports
% the exception as a warning, error, or fatal depending on the severity.
%
% The format of the CatchException method is:
%
% CatchException(ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o exception: the exception info.
%
*/
MagickExport void CatchException(ExceptionInfo *exception)
{
register const ExceptionInfo
*p;
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
if (exception->exceptions == (void *) NULL)
return;
LockSemaphoreInfo(exception->semaphore);
ResetLinkedListIterator((LinkedListInfo *) exception->exceptions);
p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
exception->exceptions);
while (p != (const ExceptionInfo *) NULL)
{
if ((p->severity >= WarningException) && (p->severity < ErrorException))
MagickWarning(p->severity,p->reason,p->description);
if ((p->severity >= ErrorException) && (p->severity < FatalErrorException))
MagickError(p->severity,p->reason,p->description);
if (p->severity >= FatalErrorException)
MagickFatalError(p->severity,p->reason,p->description);
p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
exception->exceptions);
}
UnlockSemaphoreInfo(exception->semaphore);
ClearMagickException(exception);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L o a d C o d e r L i s t s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LoadCoderLists() loads one or more coder configuration file which
% provides a mapping between coder attributes and a coder name.
%
% The format of the LoadCoderLists coder is:
%
% MagickBooleanType LoadCoderLists(const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o filename: The font file name.
%
% o exception: Return any errors or warnings in this structure.
%
%
*/
static MagickBooleanType LoadCoderLists(const char *filename,
ExceptionInfo *exception)
{
#if defined(UseEmbeddableMagick)
return(LoadCoderList(CoderMap,"built-in",0,exception));
#else
const StringInfo
*option;
LinkedListInfo
*options;
MagickStatusType
status;
status=MagickFalse;
options=GetConfigureOptions(filename,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
while (option != (const StringInfo *) NULL)
{
status|=LoadCoderList((const char *) option->datum,option->path,0,
exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyConfigureOptions(options);
if ((coder_list == (SplayTreeInfo *) NULL) ||
(GetNumberOfNodesInSplayTree(coder_list) == 0))
status|=LoadCoderList(CoderMap,"built-in",0,exception);
else
(void) SetExceptionInfo(exception,UndefinedException);
return(status != 0 ? MagickTrue : MagickFalse);
#endif
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% A c q u i r e M i m e C a c h e %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% AcquireMimeCache() caches one or more magic configurations which provides
% a mapping between magic attributes and a magic name.
%
% The format of the AcquireMimeCache method is:
%
% LinkedListInfo *AcquireMimeCache(const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o filename: the font file name.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport LinkedListInfo *AcquireMimeCache(const char *filename,
ExceptionInfo *exception)
{
LinkedListInfo
*cache;
MagickStatusType
status;
cache=NewLinkedList(0);
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&=LoadMimeCache(cache,(const char *)
GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyConfigureOptions(options);
}
#endif
if (IsLinkedListEmpty(cache) != MagickFalse)
status&=LoadMimeCache(cache,MimeMap,"built-in",0,exception);
return(cache);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I n h e r i t E x c e p t i o n %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% InheritException() inherits an exception from a related exception.
%
% The format of the InheritException method is:
%
% InheritException(ExceptionInfo *exception,const ExceptionInfo *relative)
%
% A description of each parameter follows:
%
% o exception: the exception info.
%
% o relative: the related exception info.
%
*/
MagickExport void InheritException(ExceptionInfo *exception,
const ExceptionInfo *relative)
{
register const ExceptionInfo
*p;
assert(exception != (ExceptionInfo *) NULL);
assert(exception->signature == MagickSignature);
assert(relative != (ExceptionInfo *) NULL);
assert(relative->signature == MagickSignature);
assert(exception != relative);
if (relative->exceptions == (void *) NULL)
return;
LockSemaphoreInfo(relative->semaphore);
ResetLinkedListIterator((LinkedListInfo *) relative->exceptions);
p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
relative->exceptions);
while (p != (const ExceptionInfo *) NULL)
{
(void) ThrowException(exception,p->severity,p->reason,p->description);
p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *)
relative->exceptions);
}
UnlockSemaphoreInfo(relative->semaphore);
}
开发者ID:Babelz,项目名称:SaNi,代码行数:49,代码来源:exception.c
示例5: GetConfigureInfo
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ G e t C o n f i g u r e I n f o %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GetConfigureInfo() searches the configure list for the specified name and if
% found returns attributes for that element.
%
% The format of the GetConfigureInfo method is:
%
% const ConfigureInfo *GetConfigureInfo(const char *name,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o configure_info: GetConfigureInfo() searches the configure list for the
% specified name and if found returns attributes for that element.
%
% o name: The configure name.
%
% o exception: Return any errors or warnings in this structure.
%
*/
WizardExport const ConfigureInfo *GetConfigureInfo(const char *name,
ExceptionInfo *exception)
{
register const ConfigureInfo
*p;
assert(exception != (ExceptionInfo *) NULL);
if (IsConfigureCacheInstantiated(exception) == WizardFalse)
return((const ConfigureInfo *) NULL);
/*
Search for named configure.
*/
LockSemaphoreInfo(configure_semaphore);
ResetLinkedListIterator(configure_cache);
p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache);
if ((name == (const char *) NULL) || (strcasecmp(name,"*") == 0))
{
UnlockSemaphoreInfo(configure_semaphore);
return(p);
}
while (p != (const ConfigureInfo *) NULL)
{
if (strcasecmp(name,p->name) == 0)
break;
p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_cache);
}
if (p == (ConfigureInfo *) NULL)
(void) ThrowWizardException(exception,GetWizardModule(),OptionWarning,
"no such configure list `%s'",name);
else
(void) InsertValueInLinkedList(configure_cache,0,
RemoveElementByValueFromLinkedList(configure_cache,p));
UnlockSemaphoreInfo(configure_semaphore);
return(p);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ G e t M a g i c I n f o %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GetMagicInfo() searches the magic list for the specified name and if found
% returns attributes for that magic.
%
% The format of the GetMagicInfo method is:
%
% const MagicInfo *GetMagicInfo(const unsigned char *magic,
% const size_t length,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o magic: A binary string generally representing the first few characters
% of the image file or blob.
%
% o length: the length of the binary signature.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport const MagicInfo *GetMagicInfo(const unsigned char *magic,
const size_t length,ExceptionInfo *exception)
{
register const MagicInfo
*p;
assert(exception != (ExceptionInfo *) NULL);
if (IsMagicCacheInstantiated(exception) == MagickFalse)
return((const MagicInfo *) NULL);
/*
Search for magic tag.
*/
LockSemaphoreInfo(magic_semaphore);
ResetLinkedListIterator(magic_cache);
p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache);
if (magic == (const unsigned char *) NULL)
{
UnlockSemaphoreInfo(magic_semaphore);
return(p);
}
while (p != (const MagicInfo *) NULL)
{
assert(p->offset >= 0);
if (((size_t) (p->offset+p->length) <= length) &&
(memcmp(magic+p->offset,p->magic,p->length) == 0))
break;
p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache);
}
if (p != (const MagicInfo *) NULL)
(void) InsertValueInLinkedList(magic_cache,0,
RemoveElementByValueFromLinkedList(magic_cache,p));
UnlockSemaphoreInfo(magic_semaphore);
return(p);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ G e t C o n f i g u r e I n f o %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GetConfigureInfo() searches the configure list for the specified name and if
% found returns attributes for that element.
%
% The format of the GetConfigureInfo method is:
%
% const ConfigureInfo *GetConfigureInfo(const char *name,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o configure_info: GetConfigureInfo() searches the configure list for the
% specified name and if found returns attributes for that element.
%
% o name: the configure name.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport const ConfigureInfo *GetConfigureInfo(const char *name,
ExceptionInfo *exception)
{
register const ConfigureInfo
*p;
assert(exception != (ExceptionInfo *) NULL);
if ((configure_list == (LinkedListInfo *) NULL) ||
(instantiate_configure == MagickFalse))
if (InitializeConfigureList(exception) == MagickFalse)
return((const ConfigureInfo *) NULL);
if ((configure_list == (LinkedListInfo *) NULL) ||
(IsLinkedListEmpty(configure_list) != MagickFalse))
return((const ConfigureInfo *) NULL);
if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
return((const ConfigureInfo *) GetValueFromLinkedList(configure_list,0));
/*
Search for configure tag.
*/
LockSemaphoreInfo(configure_semaphore);
ResetLinkedListIterator(configure_list);
p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
while (p != (const ConfigureInfo *) NULL)
{
if (LocaleCompare(name,p->name) == 0)
break;
p=(const ConfigureInfo *) GetNextValueInLinkedList(configure_list);
}
if (p != (ConfigureInfo *) NULL)
(void) InsertValueInLinkedList(configure_list,0,
RemoveElementByValueFromLinkedList(configure_list,p));
UnlockSemaphoreInfo(configure_semaphore);
return(p);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L o a d M i m e L i s t s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LoadMimeList() loads one or more magic configuration file which provides a
% mapping between magic attributes and a magic name.
%
% The format of the LoadMimeLists method is:
%
% MagickBooleanType LoadMimeLists(const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o filename: the font file name.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport MagickBooleanType LoadMimeLists(const char *filename,
ExceptionInfo *exception)
{
#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
return(LoadMimeList(MimeMap,"built-in",0,exception));
#else
const StringInfo
*option;
LinkedListInfo
*options;
MagickStatusType
status;
status=MagickFalse;
options=GetConfigureOptions(filename,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
while (option != (const StringInfo *) NULL)
{
status&=LoadMimeList((const char *) GetStringInfoDatum(option),
GetStringInfoPath(option),0,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyConfigureOptions(options);
if ((mime_list == (LinkedListInfo *) NULL) ||
(IsLinkedListEmpty(mime_list) != MagickFalse))
status&=LoadMimeList(MimeMap,"built-in",0,exception);
else
ClearMagickException(exception);
return(status != 0 ? MagickTrue : MagickFalse);
#endif
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% G e t M a g i c P a t t e r n E x t e n t %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GetMagicPatternExtent() returns the the extent of the buffer that is
% required to check all the MagickInfos. It returns zero if the list is empty.
%
% The format of the GetMagicPatternExtent method is:
%
% size_t GetMagicPatternExtent(ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport size_t GetMagicPatternExtent(ExceptionInfo *exception)
{
register const MagicInfo
*p;
size_t
magickSize,
max;
static size_t
size=0;
assert(exception != (ExceptionInfo *) NULL);
if ((size != 0) || (IsMagicCacheInstantiated(exception) == MagickFalse))
return(size);
LockSemaphoreInfo(magic_semaphore);
ResetLinkedListIterator(magic_cache);
max=0;
p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache);
while (p != (const MagicInfo *) NULL)
{
magickSize=(size_t) (p->offset+p->length);
if (magickSize > max)
max=magickSize;
p=(const MagicInfo *) GetNextValueInLinkedList(magic_cache);
}
size=max;
UnlockSemaphoreInfo(magic_semaphore);
return(size);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L o a d C o d e r L i s t s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LoadCoderLists() loads one or more coder configuration file which
% provides a mapping between coder attributes and a coder name.
%
% The format of the LoadCoderLists coder is:
%
% MagickBooleanType LoadCoderLists(const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o filename: the font file name.
%
% o exception: return any errors or warnings in this structure.
%
*/
static MagickBooleanType LoadCoderLists(const char *filename,
ExceptionInfo *exception)
{
#if defined(MAGICKCORE_EMBEDDABLE_SUPPORT)
return(LoadCoderList(CoderMap,"built-in",0,exception));
#else
const StringInfo
*option;
LinkedListInfo
*options;
MagickStatusType
status;
status=MagickFalse;
options=GetConfigureOptions(filename,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
while (option != (const StringInfo *) NULL)
{
status|=LoadCoderList((const char *) GetStringInfoDatum(option),
GetStringInfoPath(option),0,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyConfigureOptions(options);
if ((coder_list == (SplayTreeInfo *) NULL) ||
(GetNumberOfNodesInSplayTree(coder_list) == 0))
status|=LoadCoderList(CoderMap,"built-in",0,exception);
return(status != 0 ? MagickTrue : MagickFalse);
#endif
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% G e t L o c a l e O p t i o n s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GetLocaleOptions() returns any Magick configuration messages associated
% with the specified filename.
%
% The format of the GetLocaleOptions method is:
%
% LinkedListInfo *GetLocaleOptions(const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o filename: the locale file tag.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport LinkedListInfo *GetLocaleOptions(const char *filename,
ExceptionInfo *exception)
{
char
path[MaxTextExtent];
const char
*element;
LinkedListInfo
*messages,
*paths;
StringInfo
*xml;
assert(filename != (const char *) NULL);
(void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
assert(exception != (ExceptionInfo *) NULL);
(void) CopyMagickString(path,filename,MaxTextExtent);
/*
Load XML from configuration files to linked-list.
*/
messages=NewLinkedList(0);
paths=GetConfigurePaths(filename,exception);
if (paths != (LinkedListInfo *) NULL)
{
ResetLinkedListIterator(paths);
element=(const char *) GetNextValueInLinkedList(paths);
while (element != (const char *) NULL)
{
(void) FormatMagickString(path,MaxTextExtent,"%s%s",element,filename);
(void) LogMagickEvent(LocaleEvent,GetMagickModule(),
"Searching for locale file: \"%s\"",path);
xml=ConfigureFileToStringInfo(path);
if (xml != (StringInfo *) NULL)
(void) AppendValueToLinkedList(messages,xml);
element=(const char *) GetNextValueInLinkedList(paths);
}
paths=DestroyLinkedList(paths,RelinquishMagickMemory);
}
#if defined(MAGICKCORE_WINDOWS_SUPPORT)
{
char
*blob;
blob=(char *) NTResourceToBlob(filename);
if (blob != (char *) NULL)
{
xml=StringToStringInfo(blob);
(void) AppendValueToLinkedList(messages,xml);
blob=DestroyString(blob);
}
}
#endif
ResetLinkedListIterator(messages);
return(messages);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L o a d T y p e L i s t s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LoadTypeList() loads one or more type configuration files which provides a
% mapping between type attributes and a type name.
%
% The format of the LoadTypeLists method is:
%
% MagickBooleanType LoadTypeLists(const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o filename: the font file name.
%
% o exception: return any errors or warnings in this structure.
%
*/
static MagickBooleanType LoadTypeLists(const char *filename,
ExceptionInfo *exception)
{
#if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT)
return(LoadTypeList(TypeMap,"built-in",0,exception));
#else
char
*font_path,
path[MaxTextExtent];
const StringInfo
*option;
LinkedListInfo
*options;
MagickStatusType
status;
status=MagickFalse;
*path='\0';
options=GetConfigureOptions(filename,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
while (option != (const StringInfo *) NULL)
{
(void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent);
status&=LoadTypeList((const char *) GetStringInfoDatum(option),
GetStringInfoPath(option),0,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyConfigureOptions(options);
font_path=GetEnvironmentValue("MAGICK_FONT_PATH");
if (font_path != (char *) NULL)
{
char
*option;
/*
Search MAGICK_FONT_PATH.
*/
(void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",font_path,
DirectorySeparator,filename);
option=FileToString(path,~0UL,exception);
if (option != (void *) NULL)
{
status&=LoadTypeList(option,path,0,exception);
option=DestroyString(option);
}
font_path=DestroyString(font_path);
}
if ((type_list == (SplayTreeInfo *) NULL) ||
(GetNumberOfNodesInSplayTree(type_list) == 0))
status&=LoadTypeList(TypeMap,"built-in",0,exception);
return(status != 0 ? MagickTrue : MagickFalse);
#endif
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
+ G e t P o l i c y I n f o %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% GetPolicyInfo() searches the policy list for the specified name and if found
% returns attributes for that policy.
%
% The format of the GetPolicyInfo method is:
%
% PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o name: the policy name.
%
% o exception: return any errors or warnings in this structure.
%
*/
static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception)
{
char
policyname[MaxTextExtent];
register PolicyInfo
*p;
register char
*q;
assert(exception != (ExceptionInfo *) NULL);
if ((policy_list == (LinkedListInfo *) NULL) ||
(instantiate_policy == MagickFalse))
if (InitializePolicyList(exception) == MagickFalse)
return((PolicyInfo *) NULL);
if ((policy_list == (LinkedListInfo *) NULL) ||
(IsLinkedListEmpty(policy_list) != MagickFalse))
return((PolicyInfo *) NULL);
if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0))
return((PolicyInfo *) GetValueFromLinkedList(policy_list,0));
/*
Strip names of whitespace.
*/
(void) CopyMagickString(policyname,name,MaxTextExtent);
for (q=policyname; *q != '\0'; q++)
{
if (isspace((int) ((unsigned char) *q)) == 0)
continue;
(void) CopyMagickString(q,q+1,MaxTextExtent);
q--;
}
/*
Search for policy tag.
*/
LockSemaphoreInfo(policy_semaphore);
ResetLinkedListIterator(policy_list);
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
while (p != (PolicyInfo *) NULL)
{
if (LocaleCompare(policyname,p->name) == 0)
break;
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
}
if (p != (PolicyInfo *) NULL)
(void) InsertValueInLinkedList(policy_list,0,
RemoveElementByValueFromLinkedList(policy_list,p));
UnlockSemaphoreInfo(policy_semaphore);
return(p);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% I s R i g h t s A u t h o r i z e d %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% IsRightsAuthorized() returns MagickTrue if the policy authorizes the
% requested rights for the specified domain.
%
% The format of the IsRightsAuthorized method is:
%
% MagickBooleanType IsRightsAuthorized(const PolicyDomain domain,
% const PolicyRights rights,const char *pattern)
%
% A description of each parameter follows:
%
% o domain: the policy domain.
%
% o rights: the policy rights.
%
% o pattern: the coder, delegate, filter, or path pattern.
%
*/
MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain,
const PolicyRights rights,const char *pattern)
{
const PolicyInfo
*policy_info;
ExceptionInfo
*exception;
MagickBooleanType
authorized;
register PolicyInfo
*p;
(void) LogMagickEvent(PolicyEvent,GetMagickModule(),
"Domain: %s; rights=%s; pattern=\"%s\" ...",
CommandOptionToMnemonic(MagickPolicyDomainOptions,domain),
CommandOptionToMnemonic(MagickPolicyRightsOptions,rights),pattern);
exception=AcquireExceptionInfo();
policy_info=GetPolicyInfo("*",exception);
exception=DestroyExceptionInfo(exception);
if (policy_info == (PolicyInfo *) NULL)
return(MagickTrue);
authorized=MagickTrue;
LockSemaphoreInfo(policy_semaphore);
ResetLinkedListIterator(policy_list);
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
while ((p != (PolicyInfo *) NULL) && (authorized != MagickFalse))
{
if ((p->domain == domain) &&
(GlobExpression(pattern,p->pattern,MagickFalse) != MagickFalse))
{
if (((rights & ReadPolicyRights) != 0) &&
((p->rights & ReadPolicyRights) == 0))
authorized=MagickFalse;
if (((rights & WritePolicyRights) != 0) &&
((p->rights & WritePolicyRights) == 0))
authorized=MagickFalse;
if (((rights & ExecutePolicyRights) != 0) &&
((p->rights & ExecutePolicyRights) == 0))
authorized=MagickFalse;
}
p=(PolicyInfo *) GetNextValueInLinkedList(policy_list);
}
UnlockSemaphoreInfo(policy_semaphore);
return(authorized);
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% S e t M a g i c k S e c u r i t y P o l i c y %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% SetMagickSecurityPolicy() sets the ImageMagick security policy. It returns
% MagickFalse if the policy is already set or if the policy does not parse.
%
% The format of the SetMagickSecurityPolicy method is:
%
% MagickBooleanType SetMagickSecurityPolicy(const char *policy,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o policy: the security policy in the XML format.
%
% o exception: return any errors or warnings in this structure.
%
*/
MagickExport MagickBooleanType SetMagickSecurityPolicy(const char *policy,
ExceptionInfo *exception)
{
PolicyInfo
*p;
MagickBooleanType
status;
assert(exception != (ExceptionInfo *) NULL);
if (policy == (const char *) NULL)
return(MagickFalse);
if (IsPolicyCacheInstantiated(exception) == MagickFalse)
return(MagickFalse);
LockSemaphoreInfo(policy_semaphore);
ResetLinkedListIterator(policy_cache);
p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache);
if ((p != (PolicyInfo *) NULL) && (p->domain != UndefinedPolicyDomain))
{
UnlockSemaphoreInfo(policy_semaphore);
return(MagickFalse);
}
UnlockSemaphoreInfo(policy_semaphore);
status=LoadPolicyCache(policy_cache,policy,"[user-policy]",0,exception);
if (status == MagickFalse)
return(MagickFalse);
return(ResourceComponentGenesis());
}
/*
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% %
% %
% %
% L o a d L o c a l e L i s t s %
% %
% %
% %
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% LoadLocaleList() loads one or more locale configuration file which
% provides a mapping between locale attributes and a locale tag.
%
% The format of the LoadLocaleLists method is:
%
% MagickBooleanType LoadLocaleLists(const char *filename,
% ExceptionInfo *exception)
%
% A description of each parameter follows:
%
% o filename: The font file tag.
%
% o locale: The actual locale.
%
% o exception: Return any errors or warnings in this structure.
%
%
*/
static MagickBooleanType LoadLocaleLists(const char *filename,
const char *locale,ExceptionInfo *exception)
{
#if defined(UseEmbeddableMagick)
return(LoadLocaleList(LocaleMap,"built-in",locale,0,exception));
#else
const StringInfo
*option;
LinkedListInfo
*options;
MagickStatusType
status;
status=MagickFalse;
options=GetLocaleOptions(filename,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
while (option != (const StringInfo *) NULL)
{
status|=LoadLocaleList((const char *) option->datum,option->path,locale,0,
exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyLocaleOptions(options);
if ((locale_list == (SplayTreeInfo *) NULL) ||
(GetNumberOfNodesInSplayTree(locale_list) == 0))
{
options=GetLocaleOptions("english.xml",exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
while (option != (const StringInfo *) NULL)
{
status|=LoadLocaleList((const char *) option->datum,option->path,locale,
0,exception);
option=(const StringInfo *) GetNextValueInLinkedList(options);
}
options=DestroyLocaleOptions(options);
}
if ((locale_list == (SplayTreeInfo *) NULL) ||
(GetNumberOfNodesInSplayTree(locale_list) == 0))
status|=LoadLocaleList(LocaleMap,"built-in",locale,0,exception);
return(status != 0 ? MagickTrue : MagickFalse);
#endif
}
请发表评论