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);
589 *real_path = realpath_utf8(path);
591 if (real_path != (
char *) NULL)
593 (void) CopyMagickString(path,real_path,MagickPathExtent);
594 real_path=DestroyString(real_path);
597 if (IsPathAccessible(path) != MagickFalse)
599 module_path=DestroyString(module_path);
602 p=strchr(p+1,DirectoryListSeparator);
604 module_path=DestroyString(module_path);
606#if defined(MAGICKCORE_INSTALLED_SUPPORT)
608#if defined(MAGICKCORE_CODER_PATH)
618 case MagickImageCoderModule:
621 directory=MAGICKCORE_CODER_PATH;
624 case MagickImageFilterModule:
626 directory=MAGICKCORE_FILTER_PATH;
630 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s",directory,
632 if (IsPathAccessible(path) == MagickFalse)
634 ThrowFileException(exception,ConfigureWarning,
635 "UnableToOpenModuleFile",path);
641#if defined(MAGICKCORE_WINDOWS_SUPPORT)
654 case MagickImageCoderModule:
657 registry_key=
"CoderModulesPath";
660 case MagickImageFilterModule:
662 registry_key=
"FilterModulesPath";
666 key_value=NTRegistryKeyLookup(registry_key);
667 if (key_value == (
unsigned char *) NULL)
669 ThrowMagickException(exception,GetMagickModule(),ConfigureError,
670 "RegistryKeyLookupFailed",
"`%s'",registry_key);
673 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s%s",(
char *)
674 key_value,DirectorySeparator,filename);
675 key_value=(
unsigned char *) RelinquishMagickMemory(key_value);
676 if (IsPathAccessible(path) == MagickFalse)
678 ThrowFileException(exception,ConfigureWarning,
679 "UnableToOpenModuleFile",path);
686#if !defined(MAGICKCORE_CODER_PATH) && !defined(MAGICKCORE_WINDOWS_SUPPORT)
687# error MAGICKCORE_CODER_PATH or MAGICKCORE_WINDOWS_SUPPORT must be defined when MAGICKCORE_INSTALLED_SUPPORT is defined
694 home=GetEnvironmentValue(
"MAGICK_HOME");
695 if (home != (
char *) NULL)
700#if !defined(MAGICKCORE_POSIX_SUPPORT)
701 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s%s",home,
702 DirectorySeparator,filename);
709 case MagickImageCoderModule:
712 directory=MAGICKCORE_CODER_RELATIVE_PATH;
715 case MagickImageFilterModule:
717 directory=MAGICKCORE_FILTER_RELATIVE_PATH;
721 (void) FormatLocaleString(path,MagickPathExtent,
"%s/lib/%s/%s",home,
724 home=DestroyString(home);
725 if (IsPathAccessible(path) != MagickFalse)
729 if (*GetClientPath() !=
'\0')
734#if !defined(MAGICKCORE_POSIX_SUPPORT)
735 (void) FormatLocaleString(path,MagickPathExtent,
"%s%s%s",GetClientPath(),
736 DirectorySeparator,filename);
739 prefix[MagickPathExtent];
746 case MagickImageCoderModule:
752 case MagickImageFilterModule:
758 (void) CopyMagickString(prefix,GetClientPath(),MagickPathExtent);
759 ChopPathComponents(prefix,1);
760 (void) FormatLocaleString(path,MagickPathExtent,
"%s/lib/%s/%s/%s",prefix,
761 MAGICKCORE_MODULES_RELATIVE_PATH,directory,filename);
763 if (IsPathAccessible(path) != MagickFalse)
766#if defined(MAGICKCORE_WINDOWS_SUPPORT)
771 if ((NTGetModulePath(
"CORE_RL_MagickCore_.dll",path) != MagickFalse) ||
772 (NTGetModulePath(
"CORE_DB_MagickCore_.dll",path) != MagickFalse))
774 (void) ConcatenateMagickString(path,DirectorySeparator,
776 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
777 if (IsPathAccessible(path) != MagickFalse)
786 home=GetEnvironmentValue(
"XDG_CONFIG_HOME");
787 if (home == (
char *) NULL)
788#if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__)
789 home=GetEnvironmentValue(
"LOCALAPPDATA");
790 if (home == (
char *) NULL)
791 home=GetEnvironmentValue(
"APPDATA");
792 if (home == (
char *) NULL)
793 home=GetEnvironmentValue(
"USERPROFILE");
795 if (home != (
char *) NULL)
800 (void) FormatLocaleString(path,MagickPathExtent,
"%s%sImageMagick%s%s",
801 home,DirectorySeparator,DirectorySeparator,filename);
802 home=DestroyString(home);
803 if (IsPathAccessible(path) != MagickFalse)
806 home=GetEnvironmentValue(
"HOME");
807 if (home != (
char *) NULL)
812 (void) FormatLocaleString(path,MagickPathExtent,
813 "%s%s.config%sImageMagick%s%s",home,DirectorySeparator,
814 DirectorySeparator,DirectorySeparator,filename);
815 home=DestroyString(home);
816 if (IsPathAccessible(path) != MagickFalse)
823 if (IsPathAccessible(path) != MagickFalse)
825 if (exception->severity < ConfigureError)
826 ThrowFileException(exception,ConfigureWarning,
"UnableToOpenModuleFile",
852static void *DestroyModuleNode(
void *module_info)
860 exception=AcquireExceptionInfo();
862 if (UnregisterModule(p,exception) == MagickFalse)
863 CatchException(exception);
864 if (p->tag != (
char *) NULL)
865 p->tag=DestroyString(p->tag);
866 if (p->path != (
char *) NULL)
867 p->path=DestroyString(p->path);
868 exception=DestroyExceptionInfo(exception);
869 return(RelinquishMagickMemory(p));
872static MagickBooleanType IsModuleTreeInstantiated(
void)
877 ActivateSemaphoreInfo(&module_semaphore);
878 LockSemaphoreInfo(module_semaphore);
890 splay_tree=NewSplayTree(CompareSplayTreeString,
891 (
void *(*)(
void *)) NULL,DestroyModuleNode);
892 module_info=AcquireModuleInfo((
const char *) NULL,
"[boot-strap]");
893 module_info->stealth=MagickTrue;
894 status=AddValueToSplayTree(splay_tree,module_info->tag,module_info);
895 if (status == MagickFalse)
896 ThrowFatalException(ResourceLimitFatalError,
897 "MemoryAllocationFailed");
898#if defined(MAGICKCORE_LTDL_DELEGATE)
899 if (lt_dlinit() != 0)
900 ThrowFatalException(ModuleFatalError,
901 "UnableToInitializeModuleLoader");
903 module_list=splay_tree;
905 UnlockSemaphoreInfo(module_semaphore);
907 return(module_list != (
SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
943MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
947 name[MagickPathExtent],
948 path[MagickPathExtent];
965 assert(images != (
Image **) NULL);
966 assert((*images)->signature == MagickCoreSignature);
967 if (IsEventLogging() != MagickFalse)
968 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
969 (*images)->filename);
970 rights=ReadPolicyRights;
971 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
974 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
975 "NotAuthorized",
"`%s'",tag);
978#if !defined(MAGICKCORE_BUILD_MODULES)
983 status=InvokeStaticImageFilter(tag,images,argc,argv,exception);
984 if (status != MagickFalse)
988 TagToFilterModuleName(tag,name);
989 status=GetMagickModulePath(name,MagickImageFilterModule,path,exception);
990 if (status == MagickFalse)
992 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
993 "UnableToLoadModule",
"'%s': %s",name,path);
999 handle=(ModuleHandle) lt_dlopen(path);
1000 if (handle == (ModuleHandle) NULL)
1002 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1003 "UnableToLoadModule",
"'%s': %s",name,lt_dlerror());
1004 return(MagickFalse);
1009#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1010 (void) FormatLocaleString(name,MagickPathExtent,
"%sImage",tag);
1012 (void) FormatLocaleString(name,MagickPathExtent,
"%s%sImage",
1013 MAGICKCORE_NAMESPACE_PREFIX_TAG,tag);
1018 ClearMagickException(exception);
1019 image_filter=(ImageFilterHandler *) lt_dlsym(handle,name);
1020 if (image_filter == (ImageFilterHandler *) NULL)
1021 (
void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1022 "UnableToLoadModule",
"'%s': %s",name,lt_dlerror());
1028 if (IsEventLogging() != MagickFalse)
1029 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1030 "Invoking \"%s\" dynamic image filter",tag);
1031 signature=image_filter(images,argc,argv,exception);
1032 if (IsEventLogging() != MagickFalse)
1033 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
"\"%s\" completes",
1035 if (signature != MagickImageFilterSignature)
1036 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1037 "ImageFilterSignatureMismatch",
"'%s': %8lx != %8lx",tag,
1038 (
unsigned long) signature,(
unsigned long) MagickImageFilterSignature);
1043 if (lt_dlclose(handle) != 0)
1044 (
void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1045 "UnableToCloseModule",
"'%s': %s",name,lt_dlerror());
1046 return(exception->severity < ErrorException ? MagickTrue : MagickFalse);
1073MagickExport MagickBooleanType ListModuleInfo(FILE *file,
1077 filename[MagickPathExtent],
1078 module_path[MagickPathExtent],
1080 path[MagickPathExtent];
1088 if (file == (
const FILE *) NULL)
1093 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1094 if (modules == (
char **) NULL)
1095 return(MagickFalse);
1096 TagToCoderModuleName(
"magick",filename);
1097 (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path,
1099 GetPathComponent(module_path,HeadPath,path);
1100 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1101 (void) FormatLocaleFile(file,
"Image Coder\n");
1102 (void) FormatLocaleFile(file,
1103 "-------------------------------------------------"
1104 "------------------------------\n");
1105 for (i=0; i < (ssize_t) number_modules; i++)
1107 (void) FormatLocaleFile(file,
"%s",modules[i]);
1108 (void) FormatLocaleFile(file,
"\n");
1110 (void) fflush(file);
1114 for (i=0; i < (ssize_t) number_modules; i++)
1115 modules[i]=DestroyString(modules[i]);
1116 modules=(
char **) RelinquishMagickMemory(modules);
1120 modules=GetModuleList(
"*",MagickImageFilterModule,&number_modules,exception);
1121 if (modules == (
char **) NULL)
1122 return(MagickFalse);
1123 TagToFilterModuleName(
"analyze",filename);
1124 (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path,
1126 GetPathComponent(module_path,HeadPath,path);
1127 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1128 (void) FormatLocaleFile(file,
"Image Filter\n");
1129 (void) FormatLocaleFile(file,
1130 "-------------------------------------------------"
1131 "------------------------------\n");
1132 for (i=0; i < (ssize_t) number_modules; i++)
1134 (void) FormatLocaleFile(file,
"%s",modules[i]);
1135 (void) FormatLocaleFile(file,
"\n");
1137 (void) fflush(file);
1141 for (i=0; i < (ssize_t) number_modules; i++)
1142 modules[i]=DestroyString(modules[i]);
1143 modules=(
char **) RelinquishMagickMemory(modules);
1165MagickPrivate MagickBooleanType ModuleComponentGenesis(
void)
1171 module_semaphore=AcquireSemaphoreInfo();
1172 status=IsModuleTreeInstantiated();
1194MagickPrivate
void ModuleComponentTerminus(
void)
1197 ActivateSemaphoreInfo(&module_semaphore);
1198 DestroyModuleList();
1199 RelinquishSemaphoreInfo(&module_semaphore);
1227MagickPrivate MagickBooleanType OpenModule(
const char *module,
1231 module_name[MagickPathExtent],
1232 name[MagickPathExtent],
1233 path[MagickPathExtent];
1256 assert(module != (
const char *) NULL);
1257 module_info=(
ModuleInfo *) GetModuleInfo(module,exception);
1260 (void) CopyMagickString(module_name,module,MagickPathExtent);
1261 p=GetCoderInfo(module,exception);
1263 (void) CopyMagickString(module_name,p->name,MagickPathExtent);
1264 LocaleUpper(module_name);
1265 rights=(PolicyRights) (ReadPolicyRights | WritePolicyRights);
1266 if (IsRightsAuthorized(ModulePolicyDomain,rights,module_name) == MagickFalse)
1269 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1270 "NotAuthorized",
"`%s'",module);
1271 return(MagickFalse);
1273 if (GetValueFromSplayTree(module_list,module_name) != (
void *) NULL)
1278 handle=(ModuleHandle) NULL;
1279 TagToCoderModuleName(module_name,name);
1280 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1281 "Searching for module \"%s\" using filename \"%s\"",module_name,name);
1283 status=GetMagickModulePath(name,MagickImageCoderModule,path,exception);
1284 if (status == MagickFalse)
1285 return(MagickFalse);
1289 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1290 "Opening module at path \"%s\"",path);
1291 handle=(ModuleHandle) lt_dlopen(path);
1292 if (handle == (ModuleHandle) NULL)
1294 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1295 "UnableToLoadModule",
"'%s': %s",path,lt_dlerror());
1296 return(MagickFalse);
1301 module_info=AcquireModuleInfo(path,module_name);
1302 module_info->handle=handle;
1303 if (RegisterModule(module_info,exception) == (
ModuleInfo *) NULL)
1304 return(MagickFalse);
1308 TagToModuleName(module_name,
"Register%sImage",name);
1309 module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name);
1310 if (module_info->register_module == (size_t (*)(
void)) NULL)
1312 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1313 "UnableToRegisterImageFormat",
"'%s': %s",module_name,lt_dlerror());
1314 return(MagickFalse);
1316 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1317 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1318 (
void *) module_info->register_module);
1322 TagToModuleName(module_name,
"Unregister%sImage",name);
1323 module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name);
1324 if (module_info->unregister_module == (void (*)(
void)) NULL)
1326 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1327 "UnableToRegisterImageFormat",
"'%s': %s",module_name,lt_dlerror());
1328 return(MagickFalse);
1330 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1331 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1332 (
void *) module_info->unregister_module);
1333 signature=module_info->register_module();
1334 if (signature != MagickImageCoderSignature)
1336 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1337 "ImageCoderSignatureMismatch",
"'%s': %8lx != %8lx",module_name,
1338 (
unsigned long) signature,(
unsigned long) MagickImageCoderSignature);
1339 return(MagickFalse);
1366MagickPrivate MagickBooleanType OpenModules(
ExceptionInfo *exception)
1380 (void) GetMagickInfo((
char *) NULL,exception);
1382 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1383 if ((modules == (
char **) NULL) || (*modules == (
char *) NULL))
1385 if (modules != (
char **) NULL)
1386 modules=(
char **) RelinquishMagickMemory(modules);
1387 return(MagickFalse);
1389 for (i=0; i < (ssize_t) number_modules; i++)
1390 (
void) OpenModule(modules[i],exception);
1394 for (i=0; i < (ssize_t) number_modules; i++)
1395 modules[i]=DestroyString(modules[i]);
1396 modules=(
char **) RelinquishMagickMemory(modules);
1435 assert(module_info->signature == MagickCoreSignature);
1436 if (IsEventLogging() != MagickFalse)
1437 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1440 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
1441 if (status == MagickFalse)
1442 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1443 "MemoryAllocationFailed",
"`%s'",module_info->tag);
1444 return(module_info);
1472static void TagToCoderModuleName(
const char *tag,
char *name)
1474 assert(tag != (
char *) NULL);
1475 assert(name != (
char *) NULL);
1476 if (IsEventLogging() != MagickFalse)
1477 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1478#if defined(MAGICKCORE_LTDL_DELEGATE)
1479 (void) FormatLocaleString(name,MagickPathExtent,
"%s.la",tag);
1480 (void) LocaleLower(name);
1482#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1483 if (LocaleNCompare(
"IM_MOD_",tag,7) == 0)
1484 (
void) CopyMagickString(name,tag,MagickPathExtent);
1488 (void) FormatLocaleString(name,MagickPathExtent,
"IM_MOD_DB_%s_.dll",tag);
1490 (void) FormatLocaleString(name,MagickPathExtent,
"IM_MOD_RL_%s_.dll",tag);
1522static void TagToFilterModuleName(
const char *tag,
char *name)
1524 assert(tag != (
char *) NULL);
1525 assert(name != (
char *) NULL);
1526 if (IsEventLogging() != MagickFalse)
1527 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1528#if defined(MAGICKCORE_WINDOWS_SUPPORT)
1529 (void) FormatLocaleString(name,MagickPathExtent,
"FILTER_%s_.dll",tag);
1530#elif !defined(MAGICKCORE_LTDL_DELEGATE)
1531 (void) FormatLocaleString(name,MagickPathExtent,
"%s.dll",tag);
1533 (void) FormatLocaleString(name,MagickPathExtent,
"%s.la",tag);
1565static void TagToModuleName(
const char *tag,
const char *format,
char *module)
1568 name[MagickPathExtent];
1570 assert(tag != (
const char *) NULL);
1571 assert(format != (
const char *) NULL);
1572 assert(module != (
char *) NULL);
1573 if (IsEventLogging() != MagickFalse)
1574 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1575 (void) CopyMagickString(name,tag,MagickPathExtent);
1577#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1578 (void) FormatLocaleString(module,MagickPathExtent,format,name);
1582 prefix_format[MagickPathExtent];
1584 (void) FormatLocaleString(prefix_format,MagickPathExtent,
"%s%s",
1585 MAGICKCORE_NAMESPACE_PREFIX_TAG,format);
1586 (void) FormatLocaleString(module,MagickPathExtent,prefix_format,name);
1617static MagickBooleanType UnregisterModule(
const ModuleInfo *module_info,
1623 assert(module_info != (
const ModuleInfo *) NULL);
1625 if (IsEventLogging() != MagickFalse)
1626 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1627 if (module_info->unregister_module == NULL)
1629 module_info->unregister_module();
1630 if (lt_dlclose((ModuleHandle) module_info->handle) != 0)
1632 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1633 "UnableToCloseModule",
"'%s': %s",module_info->tag,lt_dlerror());
1634 return(MagickFalse);
1640#if !defined(MAGICKCORE_BUILD_MODULES)
1645MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file),
1648 magick_unreferenced(file);
1649 magick_unreferenced(exception);
1653MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
1659 assert(image != (
Image **) NULL);
1660 assert((*image)->signature == MagickCoreSignature);
1661 if (IsEventLogging() != MagickFalse)
1662 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
1663 rights=ReadPolicyRights;
1664 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
1667 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1668 "NotAuthorized",
"`%s'",tag);
1669 return(MagickFalse);
1671#if defined(MAGICKCORE_BUILD_MODULES)
1681 image_filter=(ImageFilterHandler *) NULL;
1682 if (LocaleCompare(
"analyze",tag) == 0)
1683 image_filter=(ImageFilterHandler *) analyzeImage;
1684 if (image_filter == (ImageFilterHandler *) NULL)
1685 (
void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1686 "UnableToLoadModule",
"`%s'",tag);
1692 if ((*image)->debug != MagickFalse)
1693 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1694 "Invoking \"%s\" static image filter",tag);
1695 signature=image_filter(image,argc,argv,exception);
1696 if ((*image)->debug != MagickFalse)
1697 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1698 "\"%s\" completes",tag);
1699 if (signature != MagickImageFilterSignature)
1701 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1702 "ImageFilterSignatureMismatch",
"'%s': %8lx != %8lx",tag,
1703 (
unsigned long) signature,(
unsigned long)
1704 MagickImageFilterSignature);
1705 return(MagickFalse);