43#include "magick/studio.h"
44#include "magick/blob.h"
45#include "magick/coder.h"
46#include "magick/client.h"
47#include "magick/configure.h"
48#include "magick/deprecate.h"
49#include "magick/exception.h"
50#include "magick/exception-private.h"
51#include "magick/log.h"
52#include "magick/hashmap.h"
53#include "magick/magic.h"
54#include "magick/magick.h"
55#include "magick/memory_.h"
56#include "magick/module.h"
57#include "magick/nt-base-private.h"
58#include "magick/policy.h"
59#include "magick/semaphore.h"
60#include "magick/splay-tree.h"
61#include "magick/static.h"
62#include "magick/string_.h"
63#include "magick/timer-private.h"
64#include "magick/token.h"
65#include "magick/utility.h"
66#include "magick/utility-private.h"
67#if defined(MAGICKCORE_MODULES_SUPPORT)
68#if defined(MAGICKCORE_LTDL_DELEGATE)
70typedef lt_dlhandle ModuleHandle;
72typedef void *ModuleHandle;
78#if defined(MAGICKCORE_LTDL_DELEGATE)
79# define ModuleGlobExpression "*.la"
82# define ModuleGlobExpression "IM_MOD_DB_*.dll"
84# define ModuleGlobExpression "IM_MOD_RL_*.dll"
103static MagickBooleanType
104 GetMagickModulePath(
const char *,MagickModuleType,
char *,
ExceptionInfo *),
109 TagToCoderModuleName(
const char *,
char *),
110 TagToFilterModuleName(
const char *,
char *),
111 TagToModuleName(
const char *,
const char *,
char *);
138MagickExport
ModuleInfo *AcquireModuleInfo(
const char *path,
const char *tag)
143 module_info=(
ModuleInfo *) AcquireMagickMemory(
sizeof(*module_info));
145 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
146 (void) memset(module_info,0,
sizeof(*module_info));
147 if (path != (
const char *) NULL)
148 module_info->path=ConstantString(path);
149 if (tag != (
const char *) NULL)
150 module_info->tag=ConstantString(tag);
151 module_info->timestamp=GetMagickTime();
152 module_info->signature=MagickCoreSignature;
175MagickExport
void DestroyModuleList(
void)
180 LockSemaphoreInfo(module_semaphore);
181#if defined(MAGICKCORE_MODULES_SUPPORT)
183 module_list=DestroySplayTree(module_list);
185 UnlockSemaphoreInfo(module_semaphore);
221 if (IsModuleTreeInstantiated(exception) == MagickFalse)
223 LockSemaphoreInfo(module_semaphore);
224 ResetSplayTreeIterator(module_list);
225 if ((tag == (
const char *) NULL) || (LocaleCompare(tag,
"*") == 0))
227#if defined(MAGICKCORE_MODULES_SUPPORT)
228 if (LocaleCompare(tag,
"*") == 0)
229 (void) OpenModules(exception);
231 module_info=(
ModuleInfo *) GetNextValueInSplayTree(module_list);
232 UnlockSemaphoreInfo(module_semaphore);
235 module_info=(
ModuleInfo *) GetValueFromSplayTree(module_list,tag);
236 UnlockSemaphoreInfo(module_semaphore);
268#if defined(__cplusplus) || defined(c_plusplus)
272static int ModuleInfoCompare(
const void *x,
const void *y)
280 if (LocaleCompare((*p)->path,(*q)->path) == 0)
281 return(LocaleCompare((*p)->tag,(*q)->tag));
282 return(LocaleCompare((*p)->path,(*q)->path));
285#if defined(__cplusplus) || defined(c_plusplus)
289MagickExport
const ModuleInfo **GetModuleInfoList(
const char *pattern,
304 assert(pattern != (
char *) NULL);
305 assert(number_modules != (
size_t *) NULL);
306 if (IsEventLogging() != MagickFalse)
307 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
309 p=GetModuleInfo(
"*",exception);
312 modules=(
const ModuleInfo **) AcquireQuantumMemory((
size_t)
313 GetNumberOfNodesInSplayTree(module_list)+1UL,
sizeof(*modules));
319 LockSemaphoreInfo(module_semaphore);
320 ResetSplayTreeIterator(module_list);
321 p=(
const ModuleInfo *) GetNextValueInSplayTree(module_list);
324 if ((p->stealth == MagickFalse) &&
325 (GlobExpression(p->tag,pattern,MagickFalse) != MagickFalse))
327 p=(
const ModuleInfo *) GetNextValueInSplayTree(module_list);
329 UnlockSemaphoreInfo(module_semaphore);
330 qsort((
void *) modules,(
size_t) i,
sizeof(*modules),ModuleInfoCompare);
332 *number_modules=(size_t) i;
368#if defined(__cplusplus) || defined(c_plusplus)
372static int ModuleCompare(
const void *x,
const void *y)
380 return(LocaleCompare(*p,*q));
383#if defined(__cplusplus) || defined(c_plusplus)
387MagickExport
char **GetModuleList(
const char *pattern,
388 const MagickModuleType type,
size_t *number_modules,
ExceptionInfo *exception)
390#define MaxModules 511
394 filename[MaxTextExtent],
395 module_path[MaxTextExtent],
419 case MagickImageCoderModule:
422 TagToCoderModuleName(
"magick",filename);
423 status=GetMagickModulePath(filename,MagickImageCoderModule,module_path,
427 case MagickImageFilterModule:
429 TagToFilterModuleName(
"analyze",filename);
430 status=GetMagickModulePath(filename,MagickImageFilterModule,module_path,
435 if (status == MagickFalse)
436 return((
char **) NULL);
437 GetPathComponent(module_path,HeadPath,path);
438 max_entries=MaxModules;
439 modules=(
char **) AcquireQuantumMemory((
size_t) max_entries+1UL,
441 if (modules == (
char **) NULL)
442 return((
char **) NULL);
443 *modules=(
char *) NULL;
444 directory=opendir(path);
445 if (directory == (
DIR *) NULL)
447 modules=(
char **) RelinquishMagickMemory(modules);
448 return((
char **) NULL);
450 buffer=(
struct dirent *) AcquireMagickMemory(
sizeof(*buffer)+FILENAME_MAX+1);
451 if (buffer == (
struct dirent *) NULL)
452 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
454 while ((MagickReadDirectory(directory,buffer,&entry) == 0) &&
455 (entry != (
struct dirent *) NULL))
457 status=GlobExpression(entry->d_name,ModuleGlobExpression,MagickFalse);
458 if (status == MagickFalse)
460 if (GlobExpression(entry->d_name,pattern,MagickFalse) == MagickFalse)
462 if (i >= (ssize_t) max_entries)
464 modules=(
char **) NULL;
465 if (~max_entries > max_entries)
466 modules=(
char **) ResizeQuantumMemory(modules,(
size_t)
467 (max_entries << 1),
sizeof(*modules));
469 if (modules == (
char **) NULL)
475 modules[i]=AcquireString((
char *) NULL);
476 GetPathComponent(entry->d_name,BasePath,modules[i]);
477 if (LocaleNCompare(
"IM_MOD_",modules[i],7) == 0)
479 (void) CopyMagickString(modules[i],modules[i]+10,MaxTextExtent);
480 modules[i][strlen(modules[i])-1]=
'\0';
484 buffer=(
struct dirent *) RelinquishMagickMemory(buffer);
485 (void) closedir(directory);
486 if (modules == (
char **) NULL)
488 (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
489 "MemoryAllocationFailed",
"`%s'",pattern);
490 return((
char **) NULL);
492 qsort((
void *) modules,(
size_t) i,
sizeof(*modules),ModuleCompare);
493 modules[i]=(
char *) NULL;
494 *number_modules=(size_t) i;
529static MagickBooleanType GetMagickModulePath(
const char *filename,
530 MagickModuleType module_type,
char *path,
ExceptionInfo *exception)
535 assert(filename != (
const char *) NULL);
536 assert(path != (
char *) NULL);
538 if (IsEventLogging() != MagickFalse)
539 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
540 if (strchr(filename,
'/') != (
char *) NULL)
542 (void) CopyMagickString(path,filename,MaxTextExtent);
543 module_path=(
char *) NULL;
546 case MagickImageCoderModule:
549 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
550 "Searching for coder module file \"%s\" ...",filename);
551 module_path=GetEnvironmentValue(
"MAGICK_CODER_MODULE_PATH");
552#if defined(MAGICKCORE_CODER_PATH)
553 if (module_path == (
char *) NULL)
554 module_path=AcquireString(MAGICKCORE_CODER_PATH);
558 case MagickImageFilterModule:
560 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
561 "Searching for filter module file \"%s\" ...",filename);
562 module_path=GetEnvironmentValue(
"MAGICK_CODER_FILTER_PATH");
563#if defined(MAGICKCORE_FILTER_PATH)
564 if (module_path == (
char *) NULL)
565 module_path=AcquireString(MAGICKCORE_FILTER_PATH);
570 if (module_path != (
char *) NULL)
576 for (p=module_path-1; p != (
char *) NULL; )
578 (void) CopyMagickString(path,p+1,MaxTextExtent);
579 q=strchr(path,DirectoryListSeparator);
580 if (q != (
char *) NULL)
582 q=path+strlen(path)-1;
583 if ((q >= path) && (*q != *DirectorySeparator))
584 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
585 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
586#if defined(MAGICKCORE_HAVE_REALPATH)
589 resolved_path[PATH_MAX+1];
591 if (realpath(path,resolved_path) != (
char *) NULL)
592 (void) CopyMagickString(path,resolved_path,MaxTextExtent);
595 if (IsPathAccessible(path) != MagickFalse)
597 module_path=DestroyString(module_path);
600 p=strchr(p+1,DirectoryListSeparator);
602 module_path=DestroyString(module_path);
604#if defined(MAGICKCORE_INSTALLED_SUPPORT)
606#if defined(MAGICKCORE_CODER_PATH)
616 case MagickImageCoderModule:
619 directory=MAGICKCORE_CODER_PATH;
622 case MagickImageFilterModule:
624 directory=MAGICKCORE_FILTER_PATH;
628 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s",directory,filename);
629 if (IsPathAccessible(path) == MagickFalse)
631 ThrowFileException(exception,ConfigureWarning,
632 "UnableToOpenModuleFile",path);
638#if defined(MAGICKCORE_WINDOWS_SUPPORT)
651 case MagickImageCoderModule:
654 registry_key=
"CoderModulesPath";
657 case MagickImageFilterModule:
659 registry_key=
"FilterModulesPath";
663 key_value=NTRegistryKeyLookup(registry_key);
664 if (key_value == (
unsigned char *) NULL)
666 ThrowMagickException(exception,GetMagickModule(),ConfigureError,
667 "RegistryKeyLookupFailed",
"`%s'",registry_key);
670 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",(
char *) key_value,
671 DirectorySeparator,filename);
672 key_value=(
unsigned char *) RelinquishMagickMemory(key_value);
673 if (IsPathAccessible(path) == MagickFalse)
675 ThrowFileException(exception,ConfigureWarning,
676 "UnableToOpenModuleFile",path);
683#if !defined(MAGICKCORE_CODER_PATH) && !defined(MAGICKCORE_WINDOWS_SUPPORT)
684# error MAGICKCORE_CODER_PATH or MAGICKCORE_WINDOWS_SUPPORT must be defined when MAGICKCORE_INSTALLED_SUPPORT is defined
691 home=GetEnvironmentValue(
"MAGICK_HOME");
692 if (home != (
char *) NULL)
697#if !defined(MAGICKCORE_POSIX_SUPPORT)
698 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",home,
699 DirectorySeparator,filename);
706 case MagickImageCoderModule:
709 directory=MAGICKCORE_CODER_RELATIVE_PATH;
712 case MagickImageFilterModule:
714 directory=MAGICKCORE_FILTER_RELATIVE_PATH;
718 (void) FormatLocaleString(path,MaxTextExtent,
"%s/lib/%s/%s",home,
721 home=DestroyString(home);
722 if (IsPathAccessible(path) != MagickFalse)
726 if (*GetClientPath() !=
'\0')
731#if !defined(MAGICKCORE_POSIX_SUPPORT)
732 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",GetClientPath(),
733 DirectorySeparator,filename);
736 prefix[MaxTextExtent];
743 case MagickImageCoderModule:
749 case MagickImageFilterModule:
755 (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent);
756 ChopPathComponents(prefix,1);
757 (void) FormatLocaleString(path,MaxTextExtent,
"%s/lib/%s/%s/%s",prefix,
758 MAGICKCORE_MODULES_RELATIVE_PATH,directory,filename);
760 if (IsPathAccessible(path) != MagickFalse)
763#if defined(MAGICKCORE_WINDOWS_SUPPORT)
768 if ((NTGetModulePath(
"CORE_RL_magick_.dll",path) != MagickFalse) ||
769 (NTGetModulePath(
"CORE_DB_magick_.dll",path) != MagickFalse) ||
770 (NTGetModulePath(
"Magick.dll",path) != MagickFalse))
772 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
773 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
774 if (IsPathAccessible(path) != MagickFalse)
783 home=GetEnvironmentValue(
"XDG_CONFIG_HOME");
784#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__)
785 if (home == (
char *) NULL)
786 home=GetEnvironmentValue(
"LOCALAPPDATA");
787 if (home == (
char *) NULL)
788 home=GetEnvironmentValue(
"APPDATA");
789 if (home == (
char *) NULL)
790 home=GetEnvironmentValue(
"USERPROFILE");
792 if (home != (
char *) NULL)
797 (void) FormatLocaleString(path,MaxTextExtent,
"%s%sImageMagick%s%s",
798 home,DirectorySeparator,DirectorySeparator,filename);
799 home=DestroyString(home);
800 if (IsPathAccessible(path) != MagickFalse)
803 home=GetEnvironmentValue(
"HOME");
804 if (home != (
char *) NULL)
809 (void) FormatLocaleString(path,MaxTextExtent,
810 "%s%s.config%sImageMagick%s%s",home,DirectorySeparator,
811 DirectorySeparator,DirectorySeparator,filename);
812 if (IsPathAccessible(path) != MagickFalse)
814 home=DestroyString(home);
820 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s.magick%s%s",home,
821 DirectorySeparator,DirectorySeparator,filename);
822 home=DestroyString(home);
823 if (IsPathAccessible(path) != MagickFalse)
830 if (IsPathAccessible(path) != MagickFalse)
832 if (exception->severity < ConfigureError)
833 ThrowFileException(exception,ConfigureWarning,
"UnableToOpenModuleFile",
863static void *DestroyModuleNode(
void *module_info)
871 exception=AcquireExceptionInfo();
873 if (UnregisterModule(p,exception) == MagickFalse)
874 CatchException(exception);
875 if (p->tag != (
char *) NULL)
876 p->tag=DestroyString(p->tag);
877 if (p->path != (
char *) NULL)
878 p->path=DestroyString(p->path);
879 exception=DestroyExceptionInfo(exception);
880 return(RelinquishMagickMemory(p));
883static MagickBooleanType IsModuleTreeInstantiated(
886 magick_unreferenced(exception);
891 ActivateSemaphoreInfo(&module_semaphore);
892 LockSemaphoreInfo(module_semaphore);
904 splay_tree=NewSplayTree(CompareSplayTreeString,
905 (
void *(*)(
void *)) NULL,DestroyModuleNode);
907 ThrowFatalException(ResourceLimitFatalError,
908 "MemoryAllocationFailed");
909 module_info=AcquireModuleInfo((
const char *) NULL,
"[boot-strap]");
910 module_info->stealth=MagickTrue;
911 status=AddValueToSplayTree(splay_tree,module_info->tag,module_info);
912 if (status == MagickFalse)
913 ThrowFatalException(ResourceLimitFatalError,
914 "MemoryAllocationFailed");
915 if (lt_dlinit() != 0)
916 ThrowFatalException(ModuleFatalError,
917 "UnableToInitializeModuleLoader");
918 module_list=splay_tree;
920 UnlockSemaphoreInfo(module_semaphore);
922 return(module_list != (
SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
925MagickExport MagickBooleanType InitializeModuleList(
ExceptionInfo *exception)
927 return(IsModuleTreeInstantiated(exception));
963MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
985 assert(images != (
Image **) NULL);
986 assert((*images)->signature == MagickCoreSignature);
987 if (IsEventLogging() != MagickFalse)
988 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
989 (*images)->filename);
990 rights=ReadPolicyRights;
991 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
994 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
995 "NotAuthorized",
"`%s'",tag);
998#if !defined(MAGICKCORE_BUILD_MODULES)
1003 status=InvokeStaticImageFilter(tag,images,argc,argv,exception);
1004 if (status != MagickFalse)
1008 TagToFilterModuleName(tag,name);
1009 status=GetMagickModulePath(name,MagickImageFilterModule,path,exception);
1010 if (status == MagickFalse)
1012 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1013 "UnableToLoadModule",
"`%s': %s",name,path);
1014 return(MagickFalse);
1019 handle=(ModuleHandle) lt_dlopen(path);
1020 if (handle == (ModuleHandle) NULL)
1022 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1023 "UnableToLoadModule",
"`%s': %s",name,lt_dlerror());
1024 return(MagickFalse);
1029#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1030 (void) FormatLocaleString(name,MaxTextExtent,
"%sImage",tag);
1032 (void) FormatLocaleString(name,MaxTextExtent,
"%s%sImage",
1033 MAGICKCORE_NAMESPACE_PREFIX_TAG,tag);
1038 ClearMagickException(exception);
1039 image_filter=(ImageFilterHandler *) lt_dlsym(handle,name);
1040 if (image_filter == (ImageFilterHandler *) NULL)
1041 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1042 "UnableToLoadModule",
"`%s': %s",name,lt_dlerror());
1048 if (IsEventLogging() != MagickFalse)
1049 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1050 "Invoking \"%s\" dynamic image filter",tag);
1051 signature=image_filter(images,argc,argv,exception);
1052 if (IsEventLogging() != MagickFalse)
1053 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
"\"%s\" completes",
1055 if (signature != MagickImageFilterSignature)
1056 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1057 "ImageFilterSignatureMismatch",
"`%s': %8lx != %8lx",tag,
1058 (
unsigned long) signature,(
unsigned long) MagickImageFilterSignature);
1063 if (lt_dlclose(handle) != 0)
1064 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1065 "UnableToCloseModule",
"`%s': %s",name,lt_dlerror());
1066 return(exception->severity < ErrorException ? MagickTrue : MagickFalse);
1093MagickExport MagickBooleanType ListModuleInfo(FILE *file,
1097 filename[MaxTextExtent],
1098 module_path[MaxTextExtent],
1100 path[MaxTextExtent];
1108 if (file == (
const FILE *) NULL)
1113 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1114 if (modules == (
char **) NULL)
1115 return(MagickFalse);
1116 TagToCoderModuleName(
"magick",filename);
1117 (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path,
1119 GetPathComponent(module_path,HeadPath,path);
1120 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1121 (void) FormatLocaleFile(file,
"Image Coder\n");
1122 (void) FormatLocaleFile(file,
1123 "-------------------------------------------------"
1124 "------------------------------\n");
1125 for (i=0; i < (ssize_t) number_modules; i++)
1127 (void) FormatLocaleFile(file,
"%s",modules[i]);
1128 (void) FormatLocaleFile(file,
"\n");
1130 (void) fflush(file);
1134 for (i=0; i < (ssize_t) number_modules; i++)
1135 modules[i]=DestroyString(modules[i]);
1136 modules=(
char **) RelinquishMagickMemory(modules);
1140 modules=GetModuleList(
"*",MagickImageFilterModule,&number_modules,exception);
1141 if (modules == (
char **) NULL)
1142 return(MagickFalse);
1143 TagToFilterModuleName(
"analyze",filename);
1144 (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path,
1146 GetPathComponent(module_path,HeadPath,path);
1147 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1148 (void) FormatLocaleFile(file,
"Image Filter\n");
1149 (void) FormatLocaleFile(file,
1150 "-------------------------------------------------"
1151 "------------------------------\n");
1152 for (i=0; i < (ssize_t) number_modules; i++)
1154 (void) FormatLocaleFile(file,
"%s",modules[i]);
1155 (void) FormatLocaleFile(file,
"\n");
1157 (void) fflush(file);
1161 for (i=0; i < (ssize_t) number_modules; i++)
1162 modules[i]=DestroyString(modules[i]);
1163 modules=(
char **) RelinquishMagickMemory(modules);
1185MagickExport MagickBooleanType ModuleComponentGenesis(
void)
1194 module_semaphore=AllocateSemaphoreInfo();
1195 exception=AcquireExceptionInfo();
1196 status=IsModuleTreeInstantiated(exception);
1197 exception=DestroyExceptionInfo(exception);
1219MagickExport
void ModuleComponentTerminus(
void)
1222 ActivateSemaphoreInfo(&module_semaphore);
1223 DestroyModuleList();
1224 DestroySemaphoreInfo(&module_semaphore);
1252MagickExport MagickBooleanType OpenModule(
const char *module,
1256 module_name[MaxTextExtent],
1257 name[MaxTextExtent],
1258 path[MaxTextExtent];
1281 assert(module != (
const char *) NULL);
1282 module_info=(
ModuleInfo *) GetModuleInfo(module,exception);
1285 (void) CopyMagickString(module_name,module,MaxTextExtent);
1286 p=GetCoderInfo(module,exception);
1288 (void) CopyMagickString(module_name,p->name,MaxTextExtent);
1289 LocaleUpper(module_name);
1290 rights=(PolicyRights) (ReadPolicyRights | WritePolicyRights);
1291 if (IsRightsAuthorized(ModulePolicyDomain,rights,module_name) == MagickFalse)
1294 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1295 "NotAuthorized",
"`%s'",module);
1296 return(MagickFalse);
1298 if (GetValueFromSplayTree(module_list,module_name) != (
void *) NULL)
1303 handle=(ModuleHandle) NULL;
1304 TagToCoderModuleName(module_name,name);
1305 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1306 "Searching for module \"%s\" using filename \"%s\"",module_name,name);
1308 status=GetMagickModulePath(name,MagickImageCoderModule,path,exception);
1309 if (status == MagickFalse)
1310 return(MagickFalse);
1314 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1315 "Opening module at path \"%s\"",path);
1316 handle=(ModuleHandle) lt_dlopen(path);
1317 if (handle == (ModuleHandle) NULL)
1319 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1320 "UnableToLoadModule",
"`%s': %s",path,lt_dlerror());
1321 return(MagickFalse);
1326 module_info=AcquireModuleInfo(path,module_name);
1327 module_info->handle=handle;
1328 if (RegisterModule(module_info,exception) == (
ModuleInfo *) NULL)
1329 return(MagickFalse);
1333 TagToModuleName(module_name,
"Register%sImage",name);
1334 module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name);
1335 if (module_info->register_module == (size_t (*)(
void)) NULL)
1337 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1338 "UnableToRegisterImageFormat",
"`%s': %s",module_name,lt_dlerror());
1339 return(MagickFalse);
1341 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1342 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1343 (
void *) module_info->register_module);
1347 TagToModuleName(module_name,
"Unregister%sImage",name);
1348 module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name);
1349 if (module_info->unregister_module == (void (*)(
void)) NULL)
1351 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1352 "UnableToRegisterImageFormat",
"`%s': %s",module_name,lt_dlerror());
1353 return(MagickFalse);
1355 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1356 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1357 (
void *) module_info->unregister_module);
1358 signature=module_info->register_module();
1359 if (signature != MagickImageCoderSignature)
1361 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1362 "ImageCoderSignatureMismatch",
"`%s': %8lx != %8lx",module_name,
1363 (
unsigned long) signature,(
unsigned long) MagickImageCoderSignature);
1364 return(MagickFalse);
1391MagickExport MagickBooleanType OpenModules(
ExceptionInfo *exception)
1405 (void) GetMagickInfo((
char *) NULL,exception);
1407 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1408 if ((modules == (
char **) NULL) || (*modules == (
char *) NULL))
1410 if (modules != (
char **) NULL)
1411 modules=(
char **) RelinquishMagickMemory(modules);
1412 return(MagickFalse);
1414 for (i=0; i < (ssize_t) number_modules; i++)
1415 (
void) OpenModule(modules[i],exception);
1419 for (i=0; i < (ssize_t) number_modules; i++)
1420 modules[i]=DestroyString(modules[i]);
1421 modules=(
char **) RelinquishMagickMemory(modules);
1460 assert(module_info->signature == MagickCoreSignature);
1461 if (IsEventLogging() != MagickFalse)
1462 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1465 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
1466 if (status == MagickFalse)
1467 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1468 "MemoryAllocationFailed",
"`%s'",module_info->tag);
1469 return(module_info);
1497static void TagToCoderModuleName(
const char *tag,
char *name)
1499 assert(tag != (
char *) NULL);
1500 assert(name != (
char *) NULL);
1501 if (IsEventLogging() != MagickFalse)
1502 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1503#if defined(MAGICKCORE_LTDL_DELEGATE)
1504 (void) FormatLocaleString(name,MaxTextExtent,
"%s.la",tag);
1505 (void) LocaleLower(name);
1507#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1508 if (LocaleNCompare(
"IM_MOD_",tag,7) == 0)
1509 (void) CopyMagickString(name,tag,MaxTextExtent);
1513 (void) FormatLocaleString(name,MaxTextExtent,
"IM_MOD_DB_%s_.dll",tag);
1515 (void) FormatLocaleString(name,MaxTextExtent,
"IM_MOD_RL_%s_.dll",tag);
1547static void TagToFilterModuleName(
const char *tag,
char *name)
1549 assert(tag != (
char *) NULL);
1550 assert(name != (
char *) NULL);
1551 if (IsEventLogging() != MagickFalse)
1552 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1553#if !defined(MAGICKCORE_LTDL_DELEGATE)
1554 (void) FormatLocaleString(name,MaxTextExtent,
"%s.dll",tag);
1556 (void) FormatLocaleString(name,MaxTextExtent,
"%s.la",tag);
1588static void TagToModuleName(
const char *tag,
const char *format,
char *module)
1591 name[MaxTextExtent];
1593 assert(tag != (
const char *) NULL);
1594 assert(format != (
const char *) NULL);
1595 assert(module != (
char *) NULL);
1596 if (IsEventLogging() != MagickFalse)
1597 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1598 (void) CopyMagickString(name,tag,MaxTextExtent);
1600#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1601 (void) FormatLocaleString(module,MaxTextExtent,format,name);
1605 prefix_format[MaxTextExtent];
1607 (void) FormatLocaleString(prefix_format,MaxTextExtent,
"%s%s",
1608 MAGICKCORE_NAMESPACE_PREFIX_TAG,format);
1609 (void) FormatLocaleString(module,MaxTextExtent,prefix_format,name);
1640static MagickBooleanType UnregisterModule(
const ModuleInfo *module_info,
1646 assert(module_info != (
const ModuleInfo *) NULL);
1648 if (IsEventLogging() != MagickFalse)
1649 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1650 if (module_info->unregister_module == NULL)
1652 module_info->unregister_module();
1653 if (lt_dlclose((ModuleHandle) module_info->handle) != 0)
1655 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1656 "UnableToCloseModule",
"`%s': %s",module_info->tag,lt_dlerror());
1657 return(MagickFalse);
1663#if !defined(MAGICKCORE_BUILD_MODULES)
1668MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file),
1671 magick_unreferenced(file);
1672 magick_unreferenced(exception);
1676MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
1682 assert(image != (
Image **) NULL);
1683 assert((*image)->signature == MagickCoreSignature);
1684 if (IsEventLogging() != MagickFalse)
1685 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
1686 rights=ReadPolicyRights;
1687 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
1690 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1691 "NotAuthorized",
"`%s'",tag);
1692 return(MagickFalse);
1694#if defined(MAGICKCORE_BUILD_MODULES)
1704 image_filter=(ImageFilterHandler *) NULL;
1705 if (LocaleCompare(
"analyze",tag) == 0)
1706 image_filter=(ImageFilterHandler *) analyzeImage;
1707 if (image_filter == (ImageFilterHandler *) NULL)
1708 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1709 "UnableToLoadModule",
"`%s'",tag);
1715 if ((*image)->debug != MagickFalse)
1716 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1717 "Invoking \"%s\" static image filter",tag);
1718 signature=image_filter(image,argc,argv,exception);
1719 if ((*image)->debug != MagickFalse)
1720 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1721 "\"%s\" completes",tag);
1722 if (signature != MagickImageFilterSignature)
1724 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1725 "ImageFilterSignatureMismatch",
"`%s': %8lx != %8lx",tag,
1726 (
unsigned long) signature,(
unsigned long)
1727 MagickImageFilterSignature);
1728 return(MagickFalse);