43#include "MagickCore/studio.h"
44#include "MagickCore/blob.h"
45#include "MagickCore/coder.h"
46#include "MagickCore/client.h"
47#include "MagickCore/configure.h"
48#include "MagickCore/exception.h"
49#include "MagickCore/exception-private.h"
50#include "MagickCore/log.h"
51#include "MagickCore/linked-list.h"
52#include "MagickCore/magic.h"
53#include "MagickCore/magick.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/memory-private.h"
56#include "MagickCore/module.h"
57#include "MagickCore/module-private.h"
58#include "MagickCore/nt-base-private.h"
59#include "MagickCore/policy.h"
60#include "MagickCore/semaphore.h"
61#include "MagickCore/splay-tree.h"
62#include "MagickCore/static.h"
63#include "MagickCore/string_.h"
64#include "MagickCore/string-private.h"
65#include "MagickCore/timer-private.h"
66#include "MagickCore/token.h"
67#include "MagickCore/utility.h"
68#include "MagickCore/utility-private.h"
69#if defined(MAGICKCORE_MODULES_SUPPORT)
70#if defined(MAGICKCORE_LTDL_DELEGATE)
72typedef lt_dlhandle ModuleHandle;
74typedef void *ModuleHandle;
80#if defined(MAGICKCORE_LTDL_DELEGATE)
81# define ModuleGlobExpression "*.la"
84# define ModuleGlobExpression "IM_MOD_DB_*.dll"
86# define ModuleGlobExpression "IM_MOD_RL_*.dll"
105static MagickBooleanType
106 GetMagickModulePath(
const char *,MagickModuleType,
char *,
ExceptionInfo *),
107 IsModuleTreeInstantiated(
void),
111 TagToCoderModuleName(
const char *,
char *),
112 TagToFilterModuleName(
const char *,
char *),
113 TagToModuleName(
const char *,
const char *,
char *);
140MagickExport
ModuleInfo *AcquireModuleInfo(
const char *path,
const char *tag)
145 module_info=(
ModuleInfo *) AcquireCriticalMemory(
sizeof(*module_info));
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() == 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[MagickPathExtent],
395 module_path[MagickPathExtent],
396 path[MagickPathExtent];
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,MagickPathExtent);
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,MagickPathExtent);
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,MagickPathExtent);
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,
586 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
587#if defined(MAGICKCORE_HAVE_REALPATH)
590 resolved_path[PATH_MAX+1];
592 if (realpath(path,resolved_path) != (
char *) NULL)
593 (void) CopyMagickString(path,resolved_path,MagickPathExtent);
596 if (IsPathAccessible(path) != MagickFalse)
598 module_path=DestroyString(module_path);
601 p=strchr(p+1,DirectoryListSeparator);
603 module_path=DestroyString(module_path);
605#if defined(MAGICKCORE_INSTALLED_SUPPORT)
607#if defined(MAGICKCORE_CODER_PATH)
617 case MagickImageCoderModule:
620 directory=MAGICKCORE_CODER_PATH;
623 case MagickImageFilterModule:
625 directory=MAGICKCORE_FILTER_PATH;
629 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s",directory,
631 if (IsPathAccessible(path) == MagickFalse)
633 ThrowFileException(exception,ConfigureWarning,
634 "UnableToOpenModuleFile",path);
640#if defined(MAGICKCORE_WINDOWS_SUPPORT)
653 case MagickImageCoderModule:
656 registry_key=
"CoderModulesPath";
659 case MagickImageFilterModule:
661 registry_key=
"FilterModulesPath";
665 key_value=NTRegistryKeyLookup(registry_key);
666 if (key_value == (
unsigned char *) NULL)
668 ThrowMagickException(exception,GetMagickModule(),ConfigureError,
669 "RegistryKeyLookupFailed",
"`%s'",registry_key);
672 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s%s",(
char *)
673 key_value,DirectorySeparator,filename);
674 key_value=(
unsigned char *) RelinquishMagickMemory(key_value);
675 if (IsPathAccessible(path) == MagickFalse)
677 ThrowFileException(exception,ConfigureWarning,
678 "UnableToOpenModuleFile",path);
685#if !defined(MAGICKCORE_CODER_PATH) && !defined(MAGICKCORE_WINDOWS_SUPPORT)
686# error MAGICKCORE_CODER_PATH or MAGICKCORE_WINDOWS_SUPPORT must be defined when MAGICKCORE_INSTALLED_SUPPORT is defined
693 home=GetEnvironmentValue(
"MAGICK_HOME");
694 if (home != (
char *) NULL)
699#if !defined(MAGICKCORE_POSIX_SUPPORT)
700 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s%s",home,
701 DirectorySeparator,filename);
708 case MagickImageCoderModule:
711 directory=MAGICKCORE_CODER_RELATIVE_PATH;
714 case MagickImageFilterModule:
716 directory=MAGICKCORE_FILTER_RELATIVE_PATH;
720 (void) FormatLocaleString(path,MagickPathExtent,
"%s/lib/%s/%s",home,
723 home=DestroyString(home);
724 if (IsPathAccessible(path) != MagickFalse)
728 if (*GetClientPath() !=
'\0')
733#if !defined(MAGICKCORE_POSIX_SUPPORT)
734 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s%s",GetClientPath(),
735 DirectorySeparator,filename);
738 prefix[MagickPathExtent];
745 case MagickImageCoderModule:
751 case MagickImageFilterModule:
757 (void) CopyMagickString(prefix,GetClientPath(),MagickPathExtent);
758 ChopPathComponents(prefix,1);
759 (void) FormatLocaleString(path,MagickPathExtent,
"%s/lib/%s/%s/%s",prefix,
760 MAGICKCORE_MODULES_RELATIVE_PATH,directory,filename);
762 if (IsPathAccessible(path) != MagickFalse)
765#if defined(MAGICKCORE_WINDOWS_SUPPORT)
770 if ((NTGetModulePath(
"CORE_RL_MagickCore_.dll",path) != MagickFalse) ||
771 (NTGetModulePath(
"CORE_DB_MagickCore_.dll",path) != MagickFalse))
773 (void) ConcatenateMagickString(path,DirectorySeparator,
775 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
776 if (IsPathAccessible(path) != MagickFalse)
785 home=GetEnvironmentValue(
"XDG_CONFIG_HOME");
786 if (home == (
char *) NULL)
787#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__)
788 home=GetEnvironmentValue(
"LOCALAPPDATA");
789 if (home == (
char *) NULL)
790 home=GetEnvironmentValue(
"APPDATA");
791 if (home == (
char *) NULL)
792 home=GetEnvironmentValue(
"USERPROFILE");
794 if (home != (
char *) NULL)
799 (void) FormatLocaleString(path,MagickPathExtent,
"%s%sImageMagick%s%s",
800 home,DirectorySeparator,DirectorySeparator,filename);
801 home=DestroyString(home);
802 if (IsPathAccessible(path) != MagickFalse)
805 home=GetEnvironmentValue(
"HOME");
806 if (home != (
char *) NULL)
811 (void) FormatLocaleString(path,MagickPathExtent,
812 "%s%s.config%sImageMagick%s%s",home,DirectorySeparator,
813 DirectorySeparator,DirectorySeparator,filename);
814 home=DestroyString(home);
815 if (IsPathAccessible(path) != MagickFalse)
822 if (IsPathAccessible(path) != MagickFalse)
824 if (exception->severity < ConfigureError)
825 ThrowFileException(exception,ConfigureWarning,
"UnableToOpenModuleFile",
851static void *DestroyModuleNode(
void *module_info)
859 exception=AcquireExceptionInfo();
861 if (UnregisterModule(p,exception) == MagickFalse)
862 CatchException(exception);
863 if (p->tag != (
char *) NULL)
864 p->tag=DestroyString(p->tag);
865 if (p->path != (
char *) NULL)
866 p->path=DestroyString(p->path);
867 exception=DestroyExceptionInfo(exception);
868 return(RelinquishMagickMemory(p));
871static MagickBooleanType IsModuleTreeInstantiated(
void)
876 ActivateSemaphoreInfo(&module_semaphore);
877 LockSemaphoreInfo(module_semaphore);
889 splay_tree=NewSplayTree(CompareSplayTreeString,
890 (
void *(*)(
void *)) NULL,DestroyModuleNode);
891 module_info=AcquireModuleInfo((
const char *) NULL,
"[boot-strap]");
892 module_info->stealth=MagickTrue;
893 status=AddValueToSplayTree(splay_tree,module_info->tag,module_info);
894 if (status == MagickFalse)
895 ThrowFatalException(ResourceLimitFatalError,
896 "MemoryAllocationFailed");
897#if defined(MAGICKCORE_LTDL_DELEGATE)
898 if (lt_dlinit() != 0)
899 ThrowFatalException(ModuleFatalError,
900 "UnableToInitializeModuleLoader");
902 module_list=splay_tree;
904 UnlockSemaphoreInfo(module_semaphore);
906 return(module_list != (
SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
942MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
946 name[MagickPathExtent],
947 path[MagickPathExtent];
964 assert(images != (
Image **) NULL);
965 assert((*images)->signature == MagickCoreSignature);
966 if (IsEventLogging() != MagickFalse)
967 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
968 (*images)->filename);
969 rights=ReadPolicyRights;
970 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
973 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
974 "NotAuthorized",
"`%s'",tag);
977#if !defined(MAGICKCORE_BUILD_MODULES)
982 status=InvokeStaticImageFilter(tag,images,argc,argv,exception);
983 if (status != MagickFalse)
987 TagToFilterModuleName(tag,name);
988 status=GetMagickModulePath(name,MagickImageFilterModule,path,exception);
989 if (status == MagickFalse)
991 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
992 "UnableToLoadModule",
"'%s': %s",name,path);
998 handle=(ModuleHandle) lt_dlopen(path);
999 if (handle == (ModuleHandle) NULL)
1001 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1002 "UnableToLoadModule",
"'%s': %s",name,lt_dlerror());
1003 return(MagickFalse);
1008#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1009 (void) FormatLocaleString(name,MagickPathExtent,
"%sImage",tag);
1011 (void) FormatLocaleString(name,MagickPathExtent,
"%s%sImage",
1012 MAGICKCORE_NAMESPACE_PREFIX_TAG,tag);
1017 ClearMagickException(exception);
1018 image_filter=(ImageFilterHandler *) lt_dlsym(handle,name);
1019 if (image_filter == (ImageFilterHandler *) NULL)
1020 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1021 "UnableToLoadModule",
"'%s': %s",name,lt_dlerror());
1027 if (IsEventLogging() != MagickFalse)
1028 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1029 "Invoking \"%s\" dynamic image filter",tag);
1030 signature=image_filter(images,argc,argv,exception);
1031 if (IsEventLogging() != MagickFalse)
1032 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
"\"%s\" completes",
1034 if (signature != MagickImageFilterSignature)
1035 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1036 "ImageFilterSignatureMismatch",
"'%s': %8lx != %8lx",tag,
1037 (
unsigned long) signature,(
unsigned long) MagickImageFilterSignature);
1042 if (lt_dlclose(handle) != 0)
1043 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1044 "UnableToCloseModule",
"'%s': %s",name,lt_dlerror());
1045 return(exception->severity < ErrorException ? MagickTrue : MagickFalse);
1072MagickExport MagickBooleanType ListModuleInfo(FILE *file,
1076 filename[MagickPathExtent],
1077 module_path[MagickPathExtent],
1079 path[MagickPathExtent];
1087 if (file == (
const FILE *) NULL)
1092 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1093 if (modules == (
char **) NULL)
1094 return(MagickFalse);
1095 TagToCoderModuleName(
"magick",filename);
1096 (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path,
1098 GetPathComponent(module_path,HeadPath,path);
1099 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1100 (void) FormatLocaleFile(file,
"Image Coder\n");
1101 (void) FormatLocaleFile(file,
1102 "-------------------------------------------------"
1103 "------------------------------\n");
1104 for (i=0; i < (ssize_t) number_modules; i++)
1106 (void) FormatLocaleFile(file,
"%s",modules[i]);
1107 (void) FormatLocaleFile(file,
"\n");
1109 (void) fflush(file);
1113 for (i=0; i < (ssize_t) number_modules; i++)
1114 modules[i]=DestroyString(modules[i]);
1115 modules=(
char **) RelinquishMagickMemory(modules);
1119 modules=GetModuleList(
"*",MagickImageFilterModule,&number_modules,exception);
1120 if (modules == (
char **) NULL)
1121 return(MagickFalse);
1122 TagToFilterModuleName(
"analyze",filename);
1123 (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path,
1125 GetPathComponent(module_path,HeadPath,path);
1126 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1127 (void) FormatLocaleFile(file,
"Image Filter\n");
1128 (void) FormatLocaleFile(file,
1129 "-------------------------------------------------"
1130 "------------------------------\n");
1131 for (i=0; i < (ssize_t) number_modules; i++)
1133 (void) FormatLocaleFile(file,
"%s",modules[i]);
1134 (void) FormatLocaleFile(file,
"\n");
1136 (void) fflush(file);
1140 for (i=0; i < (ssize_t) number_modules; i++)
1141 modules[i]=DestroyString(modules[i]);
1142 modules=(
char **) RelinquishMagickMemory(modules);
1164MagickPrivate MagickBooleanType ModuleComponentGenesis(
void)
1170 module_semaphore=AcquireSemaphoreInfo();
1171 status=IsModuleTreeInstantiated();
1193MagickPrivate
void ModuleComponentTerminus(
void)
1196 ActivateSemaphoreInfo(&module_semaphore);
1197 DestroyModuleList();
1198 RelinquishSemaphoreInfo(&module_semaphore);
1226MagickPrivate MagickBooleanType OpenModule(
const char *module,
1230 module_name[MagickPathExtent],
1231 name[MagickPathExtent],
1232 path[MagickPathExtent];
1255 assert(module != (
const char *) NULL);
1256 module_info=(
ModuleInfo *) GetModuleInfo(module,exception);
1259 (void) CopyMagickString(module_name,module,MagickPathExtent);
1260 p=GetCoderInfo(module,exception);
1262 (void) CopyMagickString(module_name,p->name,MagickPathExtent);
1263 LocaleUpper(module_name);
1264 rights=(PolicyRights) (ReadPolicyRights | WritePolicyRights);
1265 if (IsRightsAuthorized(ModulePolicyDomain,rights,module_name) == MagickFalse)
1268 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1269 "NotAuthorized",
"`%s'",module);
1270 return(MagickFalse);
1272 if (GetValueFromSplayTree(module_list,module_name) != (
void *) NULL)
1277 handle=(ModuleHandle) NULL;
1278 TagToCoderModuleName(module_name,name);
1279 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1280 "Searching for module \"%s\" using filename \"%s\"",module_name,name);
1282 status=GetMagickModulePath(name,MagickImageCoderModule,path,exception);
1283 if (status == MagickFalse)
1284 return(MagickFalse);
1288 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1289 "Opening module at path \"%s\"",path);
1290 handle=(ModuleHandle) lt_dlopen(path);
1291 if (handle == (ModuleHandle) NULL)
1293 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1294 "UnableToLoadModule",
"'%s': %s",path,lt_dlerror());
1295 return(MagickFalse);
1300 module_info=AcquireModuleInfo(path,module_name);
1301 module_info->handle=handle;
1302 if (RegisterModule(module_info,exception) == (
ModuleInfo *) NULL)
1303 return(MagickFalse);
1307 TagToModuleName(module_name,
"Register%sImage",name);
1308 module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name);
1309 if (module_info->register_module == (size_t (*)(
void)) NULL)
1311 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1312 "UnableToRegisterImageFormat",
"'%s': %s",module_name,lt_dlerror());
1313 return(MagickFalse);
1315 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1316 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1317 (
void *) module_info->register_module);
1321 TagToModuleName(module_name,
"Unregister%sImage",name);
1322 module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name);
1323 if (module_info->unregister_module == (void (*)(
void)) NULL)
1325 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1326 "UnableToRegisterImageFormat",
"'%s': %s",module_name,lt_dlerror());
1327 return(MagickFalse);
1329 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1330 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1331 (
void *) module_info->unregister_module);
1332 signature=module_info->register_module();
1333 if (signature != MagickImageCoderSignature)
1335 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1336 "ImageCoderSignatureMismatch",
"'%s': %8lx != %8lx",module_name,
1337 (
unsigned long) signature,(
unsigned long) MagickImageCoderSignature);
1338 return(MagickFalse);
1365MagickPrivate MagickBooleanType OpenModules(
ExceptionInfo *exception)
1379 (void) GetMagickInfo((
char *) NULL,exception);
1381 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1382 if ((modules == (
char **) NULL) || (*modules == (
char *) NULL))
1384 if (modules != (
char **) NULL)
1385 modules=(
char **) RelinquishMagickMemory(modules);
1386 return(MagickFalse);
1388 for (i=0; i < (ssize_t) number_modules; i++)
1389 (
void) OpenModule(modules[i],exception);
1393 for (i=0; i < (ssize_t) number_modules; i++)
1394 modules[i]=DestroyString(modules[i]);
1395 modules=(
char **) RelinquishMagickMemory(modules);
1434 assert(module_info->signature == MagickCoreSignature);
1435 if (IsEventLogging() != MagickFalse)
1436 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1439 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
1440 if (status == MagickFalse)
1441 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1442 "MemoryAllocationFailed",
"`%s'",module_info->tag);
1443 return(module_info);
1471static void TagToCoderModuleName(
const char *tag,
char *name)
1473 assert(tag != (
char *) NULL);
1474 assert(name != (
char *) NULL);
1475 if (IsEventLogging() != MagickFalse)
1476 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1477#if defined(MAGICKCORE_LTDL_DELEGATE)
1478 (void) FormatLocaleString(name,MagickPathExtent,
"%s.la",tag);
1479 (void) LocaleLower(name);
1481#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1482 if (LocaleNCompare(
"IM_MOD_",tag,7) == 0)
1483 (void) CopyMagickString(name,tag,MagickPathExtent);
1487 (void) FormatLocaleString(name,MagickPathExtent,
"IM_MOD_DB_%s_.dll",tag);
1489 (void) FormatLocaleString(name,MagickPathExtent,
"IM_MOD_RL_%s_.dll",tag);
1521static void TagToFilterModuleName(
const char *tag,
char *name)
1523 assert(tag != (
char *) NULL);
1524 assert(name != (
char *) NULL);
1525 if (IsEventLogging() != MagickFalse)
1526 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1527#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1528 (void) FormatLocaleString(name,MagickPathExtent,
"FILTER_%s_.dll",tag);
1529#elif !defined(MAGICKCORE_LTDL_DELEGATE)
1530 (void) FormatLocaleString(name,MagickPathExtent,
"%s.dll",tag);
1532 (void) FormatLocaleString(name,MagickPathExtent,
"%s.la",tag);
1564static void TagToModuleName(
const char *tag,
const char *format,
char *module)
1567 name[MagickPathExtent];
1569 assert(tag != (
const char *) NULL);
1570 assert(format != (
const char *) NULL);
1571 assert(module != (
char *) NULL);
1572 if (IsEventLogging() != MagickFalse)
1573 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1574 (void) CopyMagickString(name,tag,MagickPathExtent);
1576#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1577 (void) FormatLocaleString(module,MagickPathExtent,format,name);
1581 prefix_format[MagickPathExtent];
1583 (void) FormatLocaleString(prefix_format,MagickPathExtent,
"%s%s",
1584 MAGICKCORE_NAMESPACE_PREFIX_TAG,format);
1585 (void) FormatLocaleString(module,MagickPathExtent,prefix_format,name);
1616static MagickBooleanType UnregisterModule(
const ModuleInfo *module_info,
1622 assert(module_info != (
const ModuleInfo *) NULL);
1624 if (IsEventLogging() != MagickFalse)
1625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1626 if (module_info->unregister_module == NULL)
1628 module_info->unregister_module();
1629 if (lt_dlclose((ModuleHandle) module_info->handle) != 0)
1631 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1632 "UnableToCloseModule",
"'%s': %s",module_info->tag,lt_dlerror());
1633 return(MagickFalse);
1639#if !defined(MAGICKCORE_BUILD_MODULES)
1644MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file),
1647 magick_unreferenced(file);
1648 magick_unreferenced(exception);
1652MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
1658 assert(image != (
Image **) NULL);
1659 assert((*image)->signature == MagickCoreSignature);
1660 if (IsEventLogging() != MagickFalse)
1661 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
1662 rights=ReadPolicyRights;
1663 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
1666 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1667 "NotAuthorized",
"`%s'",tag);
1668 return(MagickFalse);
1670#if defined(MAGICKCORE_BUILD_MODULES)
1680 image_filter=(ImageFilterHandler *) NULL;
1681 if (LocaleCompare(
"analyze",tag) == 0)
1682 image_filter=(ImageFilterHandler *) analyzeImage;
1683 if (image_filter == (ImageFilterHandler *) NULL)
1684 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1685 "UnableToLoadModule",
"`%s'",tag);
1691 if ((*image)->debug != MagickFalse)
1692 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1693 "Invoking \"%s\" static image filter",tag);
1694 signature=image_filter(image,argc,argv,exception);
1695 if ((*image)->debug != MagickFalse)
1696 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1697 "\"%s\" completes",tag);
1698 if (signature != MagickImageFilterSignature)
1700 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1701 "ImageFilterSignatureMismatch",
"'%s': %8lx != %8lx",tag,
1702 (
unsigned long) signature,(
unsigned long)
1703 MagickImageFilterSignature);
1704 return(MagickFalse);