/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k H o m e U R L % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickHomeURL() returns the ImageMagick home URL. % % The format of the GetMagickHomeURL method is: % % char *GetMagickHomeURL(void) % */ MagickExport char *GetMagickHomeURL(void) { char path[MaxTextExtent]; const char *element; ExceptionInfo *exception; LinkedListInfo *paths; exception=AcquireExceptionInfo(); paths=GetConfigurePaths(MagickURLFilename,exception); exception=DestroyExceptionInfo(exception); if (paths == (LinkedListInfo *) NULL) return(ConstantString(MagickHomeURL)); element=(const char *) GetNextValueInLinkedList(paths); while (element != (const char *) NULL) { (void) FormatMagickString(path,MaxTextExtent,"%s%s%s",element, DirectorySeparator,MagickURLFilename); if (IsAccessible(path) != MagickFalse) return(ConstantString(path)); element=(const char *) GetNextValueInLinkedList(paths); } return(ConstantString(MagickHomeURL)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + 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 ((magic_list == (LinkedListInfo *) NULL) || (instantiate_magic == MagickFalse)) if (InitializeMagicList(exception) == MagickFalse) return((const MagicInfo *) NULL); if ((magic_list == (LinkedListInfo *) NULL) || (IsLinkedListEmpty(magic_list) != MagickFalse)) return((const MagicInfo *) NULL); if ((magic == (const unsigned char *) NULL) || (length == 0)) return((const MagicInfo *) GetValueFromLinkedList(magic_list,0)); if (length == 0) return((const MagicInfo *) NULL); /* Search for requested magic. */ AcquireSemaphoreInfo(&magic_semaphore); ResetLinkedListIterator(magic_list); p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); 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_list); } RelinquishSemaphoreInfo(magic_semaphore); return((const MagicInfo *) 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 }
static SplayTreeInfo *AcquireLocaleSplayTree(const char *filename, const char *locale,ExceptionInfo *exception) { MagickStatusType status; SplayTreeInfo *locale_cache; locale_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyLocaleNode); if (locale_cache == (SplayTreeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); status=MagickTrue; #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) { const StringInfo *option; LinkedListInfo *options; options=GetLocaleOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status&=LoadLocaleCache(locale_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),locale,0, exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyLocaleOptions(options); if (GetNumberOfNodesInSplayTree(locale_cache) == 0) { options=GetLocaleOptions("english.xml",exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status&=LoadLocaleCache(locale_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),locale,0, exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyLocaleOptions(options); } } #endif if (GetNumberOfNodesInSplayTree(locale_cache) == 0) status&=LoadLocaleCache(locale_cache,LocaleMap,"built-in",locale,0, exception); return(locale_cache); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + 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 }
static MagickBooleanType SetPolicyValue(const PolicyDomain domain, const char *name,const char *value) { MagickBooleanType status; register PolicyInfo *p; status=MagickTrue; LockSemaphoreInfo(policy_semaphore); ResetLinkedListIterator(policy_cache); p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); while (p != (PolicyInfo *) NULL) { if ((p->domain == domain) && (LocaleCompare(name,p->name) == 0)) break; p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); } if (p != (PolicyInfo *) NULL) { if (p->value != (char *) NULL) p->value=DestroyString(p->value); } else { p=(PolicyInfo *) AcquireCriticalMemory(sizeof(*p)); (void) memset(p,0,sizeof(*p)); p->exempt=MagickFalse; p->signature=MagickCoreSignature; p->domain=domain; p->name=ConstantString(name); status=AppendValueToLinkedList(policy_cache,p); } p->value=ConstantString(value); UnlockSemaphoreInfo(policy_semaphore); if (status == MagickFalse) p=(PolicyInfo *) RelinquishMagickMemory(p); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L o a d M a g i c L i s t s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LoadMagicList() loads one or more magic configuration file which provides a % mapping between magic attributes and a magic name. % % The format of the LoadMagicLists method is: % % MagickBooleanType LoadMagicLists(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 LoadMagicLists(const char *filename, ExceptionInfo *exception) { #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT) return(LoadMagicList(MagicMap,"built-in",0,exception)); #else char 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|=LoadMagicList((const char *) GetStringInfoDatum(option), GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); if ((magic_list == (LinkedListInfo *) NULL) || (IsLinkedListEmpty(magic_list) != MagickFalse)) { (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning, "UnableToOpenConfigureFile","`%s'",path); status|=LoadMagicList(MagicMap,"built-in",0,exception); } return(status != 0 ? MagickTrue : MagickFalse); #endif }
int HasError(ExceptionInfo *exception) { register const ExceptionInfo *p; int result = 0; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); if (exception->exceptions == (void *) NULL) return 0; if (exception->semaphore == (void *) NULL) return 0; LockSemaphoreInfo(exception->semaphore); ResetLinkedListIterator((LinkedListInfo *) exception->exceptions); p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) exception->exceptions); while (p != (const ExceptionInfo *) NULL) { if (p->severity >= ErrorException) result = 1; p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) exception->exceptions); } UnlockSemaphoreInfo(exception->semaphore); return result; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % 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. % */ static LinkedListInfo *AcquireMimeCache(const char *filename, ExceptionInfo *exception) { LinkedListInfo *mime_cache; MagickStatusType status; mime_cache=NewLinkedList(0); if (mime_cache == (LinkedListInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); 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(mime_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); } #endif if (IsLinkedListEmpty(mime_cache) != MagickFalse) status&=LoadMimeCache(mime_cache,MimeMap,"built-in",0,exception); return(mime_cache); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t M i m e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMimeInfo() attempts to classify the content to identify which mime type % is associated with the content, if any. % % The format of the GetMimeInfo method is: % % const MimeInfo *GetMimeInfo(const char *filename, % const unsigned char *magic,const size_t length, % ExceptionInfo *exception) % % A description of each parameter follows: % % o filename: If we cannot not classify the string, we attempt to classify % based on the filename (e.g. *.pdf returns application/pdf). % % 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 MimeInfo *GetMimeInfo(const char *filename, const unsigned char *magic,const size_t length,ExceptionInfo *exception) { const MimeInfo *mime_info; EndianType endian; register const MimeInfo *p; register const unsigned char *q; register ssize_t i; ssize_t value; unsigned long lsb_first; assert(exception != (ExceptionInfo *) NULL); if (IsMimeCacheInstantiated(exception) == MagickFalse) return((const MimeInfo *) NULL); /* Search for mime tag. */ mime_info=(const MimeInfo *) NULL; lsb_first=1; LockSemaphoreInfo(mime_semaphore); ResetLinkedListIterator(mime_cache); p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); if ((magic == (const unsigned char *) NULL) || (length == 0)) { UnlockSemaphoreInfo(mime_semaphore); return(p); } while (p != (const MimeInfo *) NULL) { assert(p->offset >= 0); if (mime_info != (const MimeInfo *) NULL) if (p->priority > mime_info->priority) { p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); continue; } if ((p->pattern != (char *) NULL) && (filename != (char *) NULL)) { if (GlobExpression(filename,p->pattern,MagickFalse) != MagickFalse) mime_info=p; p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); continue; } switch (p->data_type) { case ByteData: { if ((size_t) (p->offset+4) > length) break; q=magic+p->offset; value=(ssize_t) (*q++); if (p->mask == 0) { if (p->value == value) mime_info=p; } else { if ((p->value & p->mask) == value) mime_info=p; } break; } case ShortData: { if ((size_t) (p->offset+4) > length) break; q=magic+p->offset; endian=p->endian; if (p->endian == UndefinedEndian) endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian; if (endian == LSBEndian) { value=(ssize_t) (*q++); value|=(*q++) << 8; } else { value=(ssize_t) (*q++) << 8; value|=(*q++); } if (p->mask == 0) { if (p->value == value) mime_info=p; } else { if ((p->value & p->mask) == value) mime_info=p; } break; } case LongData: { if ((size_t) (p->offset+4) > length) break; q=magic+p->offset; endian=p->endian; if (p->endian == UndefinedEndian) endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian; if (endian == LSBEndian) { value=(ssize_t) (*q++); value|=((ssize_t) *q++) << 8; value|=((ssize_t) *q++) << 16; value|=((ssize_t) *q++) << 24; } else { value=(ssize_t) (*q++) << 24; value|=((ssize_t) *q++) << 16; value|=((ssize_t) *q++) << 8; value|=((ssize_t) *q++); } if (p->mask == 0) { if (p->value == value) mime_info=p; } else { if ((p->value & p->mask) == value) mime_info=p; } break; } case StringData: default: { for (i=0; i <= (ssize_t) p->extent; i++) { if ((size_t) (p->offset+i+p->length) > length) break; if (memcmp(magic+p->offset+i,p->magic,p->length) == 0) { mime_info=p; break; } } break; } } p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); } if (mime_info != (const MimeInfo *) NULL) (void) InsertValueInLinkedList(mime_cache,0, RemoveElementByValueFromLinkedList(mime_cache,p)); UnlockSemaphoreInfo(mime_semaphore); return(mime_info); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t C o n f i g u r e O p t i o n s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetConfigureOptions() returns any Magick configuration options associated % with the specified filename. % % The format of the GetConfigureOptions method is: % % LinkedListInfo *GetConfigureOptions(const char *filename, % ExceptionInfo *exception) % % A description of each parameter follows: % % o filename: the configure file name. % % o exception: return any errors or warnings in this structure. % */ MagickExport LinkedListInfo *GetConfigureOptions(const char *filename, ExceptionInfo *exception) { char path[MaxTextExtent]; const char *element; LinkedListInfo *options, *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. */ options=NewLinkedList(0); paths=GetConfigurePaths(filename,exception); if (paths != (LinkedListInfo *) NULL) { ResetLinkedListIterator(paths); element=(const char *) GetNextValueInLinkedList(paths); while (element != (const char *) NULL) { (void) FormatLocaleString(path,MaxTextExtent,"%s%s",element,filename); (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), "Searching for configure file: \"%s\"",path); xml=ConfigureFileToStringInfo(path); if (xml != (StringInfo *) NULL) (void) AppendValueToLinkedList(options,xml); element=(const char *) GetNextValueInLinkedList(paths); } paths=DestroyLinkedList(paths,RelinquishMagickMemory); } #if defined(MAGICKCORE_WINDOWS_SUPPORT) if (GetNumberOfElementsInLinkedList(options) == 0) { char *blob; blob=(char *) NTResourceToBlob(filename); if (blob != (char *) NULL) { xml=AcquireStringInfo(0); SetStringInfoLength(xml,strlen(blob)+1); SetStringInfoDatum(xml,(unsigned char *) blob); SetStringInfoPath(xml,filename); (void) AppendValueToLinkedList(options,xml); } } #endif if (GetNumberOfElementsInLinkedList(options) == 0) (void) ThrowMagickException(exception,GetMagickModule(),ConfigureWarning, "UnableToOpenConfigureFile","`%s'",filename); ResetLinkedListIterator(options); return(options); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L o a d C o n f i g u r e L i s t s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LoadConfigureList() loads one or more configure configuration files which % provides a mapping between configure attributes and a configure name. % % The format of the LoadConfigureLists method is: % % MagickBooleanType LoadConfigureLists(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 LoadConfigureLists(const char *filename, ExceptionInfo *exception) { const StringInfo *option; LinkedListInfo *options; MagickStatusType status; register ssize_t i; /* Load built-in configure map. */ status=MagickFalse; if (configure_list == (LinkedListInfo *) NULL) { configure_list=NewLinkedList(0); if (configure_list == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } for (i=0; i < (ssize_t) (sizeof(ConfigureMap)/sizeof(*ConfigureMap)); i++) { ConfigureInfo *configure_info; register const ConfigureMapInfo *p; p=ConfigureMap+i; configure_info=(ConfigureInfo *) AcquireMagickMemory( sizeof(*configure_info)); if (configure_info == (ConfigureInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", configure_info->name); continue; } (void) ResetMagickMemory(configure_info,0,sizeof(*configure_info)); configure_info->path=(char *) "[built-in]"; configure_info->name=(char *) p->name; configure_info->value=(char *) p->value; configure_info->exempt=MagickTrue; configure_info->signature=MagickSignature; status=AppendValueToLinkedList(configure_list,configure_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'", configure_info->name); } /* Load external configure map. */ options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status|=LoadConfigureList((const char *) GetStringInfoDatum(option), GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); return(status != 0 ? MagickTrue : MagickFalse); }
static SplayTreeInfo *AcquireCoderCache(const char *filename, ExceptionInfo *exception) { const StringInfo *option; LinkedListInfo *options; MagickStatusType status; register ssize_t i; SplayTreeInfo *coder_cache; /* Load external coder map. */ coder_cache=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyCoderNode); if (coder_cache == (SplayTreeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); status=MagickTrue; options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status&=LoadCoderCache(coder_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); /* Load built-in coder map. */ for (i=0; i < (ssize_t) (sizeof(CoderMap)/sizeof(*CoderMap)); i++) { CoderInfo *coder_info; register const CoderMapInfo *p; p=CoderMap+i; coder_info=(CoderInfo *) AcquireMagickMemory(sizeof(*coder_info)); if (coder_info == (CoderInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); continue; } (void) ResetMagickMemory(coder_info,0,sizeof(*coder_info)); coder_info->path=(char *) "[built-in]"; coder_info->magick=(char *) p->magick; coder_info->name=(char *) p->name; coder_info->exempt=MagickTrue; coder_info->signature=MagickCoreSignature; status&=AddValueToSplayTree(coder_cache,ConstantString(coder_info->magick), coder_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",coder_info->name); } return(coder_cache); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M a g i c C a c h e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagicCache() caches one or more magic configurations which provides a % mapping between magic attributes and a magic name. % % The format of the AcquireMagicCache method is: % % LinkedListInfo *AcquireMagicCache(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 LinkedListInfo *AcquireMagicCache(const char *filename, ExceptionInfo *exception) { char path[MaxTextExtent]; const StringInfo *option; LinkedListInfo *magic_cache, *options; MagickStatusType status; register ssize_t i; magic_cache=NewLinkedList(0); if (magic_cache == (LinkedListInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); /* Load external magic map. */ status=MagickTrue; *path='\0'; options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent); status&=LoadMagicCache(magic_cache,(const char *) GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } /* Load built-in magic map. */ for (i=0; i < (ssize_t) (sizeof(MagicMap)/sizeof(*MagicMap)); i++) { MagicInfo *magic_info; register const MagicMapInfo *p; p=MagicMap+i; magic_info=(MagicInfo *) AcquireMagickMemory(sizeof(*magic_info)); if (magic_info == (MagicInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",p->name); continue; } (void) ResetMagickMemory(magic_info,0,sizeof(*magic_info)); magic_info->path=(char *) "[built-in]"; magic_info->name=(char *) p->name; magic_info->offset=p->offset; magic_info->target=(char *) p->magic; magic_info->magic=(unsigned char *) p->magic; magic_info->length=p->length; magic_info->exempt=MagickTrue; magic_info->signature=MagickSignature; status&=AppendValueToLinkedList(magic_cache,magic_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",magic_info->name); } options=DestroyConfigureOptions(options); return(magic_cache); }
static SplayTreeInfo *AcquireTypeCache(const char *filename, ExceptionInfo *exception) { MagickStatusType status; SplayTreeInfo *type_cache; type_cache=NewSplayTree(CompareSplayTreeString,(void *(*)(void *)) NULL, DestroyTypeNode); if (type_cache == (SplayTreeInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); status=MagickTrue; #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) { char *font_path, path[MaxTextExtent]; const StringInfo *option; LinkedListInfo *options; *path='\0'; options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { (void) CopyMagickString(path,GetStringInfoPath(option),MaxTextExtent); status&=LoadTypeCache(type_cache,(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&=LoadTypeCache(type_cache,option,path,0,exception); option=DestroyString(option); } font_path=DestroyString(font_path); } } #endif if (GetNumberOfNodesInSplayTree(type_cache) == 0) status&=LoadTypeCache(type_cache,TypeMap,"built-in",0,exception); return(type_cache); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L o a d P o l i c y L i s t s % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LoadPolicyList() loads one or more policy configuration file which provides a % mapping between policy attributes and a policy name. % % The format of the LoadPolicyLists method is: % % MagickBooleanType LoadPolicyLists(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 LoadPolicyLists(const char *filename, ExceptionInfo *exception) { const StringInfo *option; LinkedListInfo *options; MagickStatusType status; register ssize_t i; /* Load external policy map. */ if (policy_list == (LinkedListInfo *) NULL) { policy_list=NewLinkedList(0); if (policy_list == (LinkedListInfo *) NULL) { ThrowFileException(exception,ResourceLimitError, "MemoryAllocationFailed",filename); return(MagickFalse); } } status=MagickTrue; options=GetConfigureOptions(filename,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); while (option != (const StringInfo *) NULL) { status&=LoadPolicyList((const char *) GetStringInfoDatum(option), GetStringInfoPath(option),0,exception); option=(const StringInfo *) GetNextValueInLinkedList(options); } options=DestroyConfigureOptions(options); /* Load built-in policy map. */ for (i=0; i < (ssize_t) (sizeof(PolicyMap)/sizeof(*PolicyMap)); i++) { PolicyInfo *policy_info; register const PolicyMapInfo *p; p=PolicyMap+i; policy_info=(PolicyInfo *) AcquireMagickMemory(sizeof(*policy_info)); if (policy_info == (PolicyInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name); continue; } (void) ResetMagickMemory(policy_info,0,sizeof(*policy_info)); policy_info->path=(char *) "[built-in]"; policy_info->domain=p->domain; policy_info->rights=p->rights; policy_info->name=(char *) p->name; policy_info->pattern=(char *) p->pattern; policy_info->value=(char *) p->value; policy_info->exempt=MagickTrue; policy_info->signature=MagickSignature; status&=AppendValueToLinkedList(policy_list,policy_info); if (status == MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), ResourceLimitError,"MemoryAllocationFailed","`%s'",policy_info->name); } return(status != 0 ? MagickTrue : MagickFalse); }