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/token.h"
64 #include "magick/utility.h"
65 #include "magick/utility-private.h"
66 #if defined(MAGICKCORE_MODULES_SUPPORT)
67 #if defined(MAGICKCORE_LTDL_DELEGATE)
69 typedef lt_dlhandle ModuleHandle;
71 typedef void *ModuleHandle;
77 #if defined(MAGICKCORE_LTDL_DELEGATE)
78 # define ModuleGlobExpression "*.la"
81 # define ModuleGlobExpression "IM_MOD_DB_*.dll"
83 # define ModuleGlobExpression "IM_MOD_RL_*.dll"
102 static MagickBooleanType
103 GetMagickModulePath(
const char *,MagickModuleType,
char *,
ExceptionInfo *),
108 TagToCoderModuleName(
const char *,
char *),
109 TagToFilterModuleName(
const char *,
char *),
110 TagToModuleName(
const char *,
const char *,
char *);
137 MagickExport
ModuleInfo *AcquireModuleInfo(
const char *path,
const char *tag)
142 module_info=(
ModuleInfo *) AcquireMagickMemory(
sizeof(*module_info));
144 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
145 (void) memset(module_info,0,
sizeof(*module_info));
146 if (path != (
const char *) NULL)
147 module_info->path=ConstantString(path);
148 if (tag != (
const char *) NULL)
149 module_info->tag=ConstantString(tag);
150 module_info->timestamp=time(0);
151 module_info->signature=MagickCoreSignature;
174 MagickExport
void DestroyModuleList(
void)
179 LockSemaphoreInfo(module_semaphore);
180 #if defined(MAGICKCORE_MODULES_SUPPORT)
182 module_list=DestroySplayTree(module_list);
184 UnlockSemaphoreInfo(module_semaphore);
220 if (IsModuleTreeInstantiated(exception) == MagickFalse)
222 LockSemaphoreInfo(module_semaphore);
223 ResetSplayTreeIterator(module_list);
224 if ((tag == (
const char *) NULL) || (LocaleCompare(tag,
"*") == 0))
226 #if defined(MAGICKCORE_MODULES_SUPPORT)
227 if (LocaleCompare(tag,
"*") == 0)
228 (void) OpenModules(exception);
230 module_info=(
ModuleInfo *) GetNextValueInSplayTree(module_list);
231 UnlockSemaphoreInfo(module_semaphore);
234 module_info=(
ModuleInfo *) GetValueFromSplayTree(module_list,tag);
235 UnlockSemaphoreInfo(module_semaphore);
267 #if defined(__cplusplus) || defined(c_plusplus)
271 static int ModuleInfoCompare(
const void *x,
const void *y)
279 if (LocaleCompare((*p)->path,(*q)->path) == 0)
280 return(LocaleCompare((*p)->tag,(*q)->tag));
281 return(LocaleCompare((*p)->path,(*q)->path));
284 #if defined(__cplusplus) || defined(c_plusplus)
288 MagickExport
const ModuleInfo **GetModuleInfoList(
const char *pattern,
303 assert(pattern != (
char *) NULL);
304 assert(number_modules != (
size_t *) NULL);
305 if (IsEventLogging() != MagickFalse)
306 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
308 p=GetModuleInfo(
"*",exception);
311 modules=(
const ModuleInfo **) AcquireQuantumMemory((
size_t)
312 GetNumberOfNodesInSplayTree(module_list)+1UL,
sizeof(*modules));
318 LockSemaphoreInfo(module_semaphore);
319 ResetSplayTreeIterator(module_list);
320 p=(
const ModuleInfo *) GetNextValueInSplayTree(module_list);
323 if ((p->stealth == MagickFalse) &&
324 (GlobExpression(p->tag,pattern,MagickFalse) != MagickFalse))
326 p=(
const ModuleInfo *) GetNextValueInSplayTree(module_list);
328 UnlockSemaphoreInfo(module_semaphore);
329 qsort((
void *) modules,(
size_t) i,
sizeof(*modules),ModuleInfoCompare);
331 *number_modules=(size_t) i;
367 #if defined(__cplusplus) || defined(c_plusplus)
371 static int ModuleCompare(
const void *x,
const void *y)
379 return(LocaleCompare(*p,*q));
382 #if defined(__cplusplus) || defined(c_plusplus)
386 MagickExport
char **GetModuleList(
const char *pattern,
387 const MagickModuleType type,
size_t *number_modules,
ExceptionInfo *exception)
389 #define MaxModules 511
393 filename[MaxTextExtent],
394 module_path[MaxTextExtent],
418 case MagickImageCoderModule:
421 TagToCoderModuleName(
"magick",filename);
422 status=GetMagickModulePath(filename,MagickImageCoderModule,module_path,
426 case MagickImageFilterModule:
428 TagToFilterModuleName(
"analyze",filename);
429 status=GetMagickModulePath(filename,MagickImageFilterModule,module_path,
434 if (status == MagickFalse)
435 return((
char **) NULL);
436 GetPathComponent(module_path,HeadPath,path);
437 max_entries=MaxModules;
438 modules=(
char **) AcquireQuantumMemory((
size_t) max_entries+1UL,
440 if (modules == (
char **) NULL)
441 return((
char **) NULL);
442 *modules=(
char *) NULL;
443 directory=opendir(path);
444 if (directory == (
DIR *) NULL)
446 modules=(
char **) RelinquishMagickMemory(modules);
447 return((
char **) NULL);
449 buffer=(
struct dirent *) AcquireMagickMemory(
sizeof(*buffer)+FILENAME_MAX+1);
450 if (buffer == (
struct dirent *) NULL)
451 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
453 while ((MagickReadDirectory(directory,buffer,&entry) == 0) &&
454 (entry != (
struct dirent *) NULL))
456 status=GlobExpression(entry->d_name,ModuleGlobExpression,MagickFalse);
457 if (status == MagickFalse)
459 if (GlobExpression(entry->d_name,pattern,MagickFalse) == MagickFalse)
461 if (i >= (ssize_t) max_entries)
463 modules=(
char **) NULL;
464 if (~max_entries > max_entries)
465 modules=(
char **) ResizeQuantumMemory(modules,(
size_t)
466 (max_entries << 1),
sizeof(*modules));
468 if (modules == (
char **) NULL)
474 modules[i]=AcquireString((
char *) NULL);
475 GetPathComponent(entry->d_name,BasePath,modules[i]);
476 if (LocaleNCompare(
"IM_MOD_",modules[i],7) == 0)
478 (void) CopyMagickString(modules[i],modules[i]+10,MaxTextExtent);
479 modules[i][strlen(modules[i])-1]=
'\0';
483 buffer=(
struct dirent *) RelinquishMagickMemory(buffer);
484 (void) closedir(directory);
485 if (modules == (
char **) NULL)
487 (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
488 "MemoryAllocationFailed",
"`%s'",pattern);
489 return((
char **) NULL);
491 qsort((
void *) modules,(
size_t) i,
sizeof(*modules),ModuleCompare);
492 modules[i]=(
char *) NULL;
493 *number_modules=(size_t) i;
528 static MagickBooleanType GetMagickModulePath(
const char *filename,
529 MagickModuleType module_type,
char *path,
ExceptionInfo *exception)
534 assert(filename != (
const char *) NULL);
535 assert(path != (
char *) NULL);
537 if (IsEventLogging() != MagickFalse)
538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",filename);
539 if (strchr(filename,
'/') != (
char *) NULL)
541 (void) CopyMagickString(path,filename,MaxTextExtent);
542 module_path=(
char *) NULL;
545 case MagickImageCoderModule:
548 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
549 "Searching for coder module file \"%s\" ...",filename);
550 module_path=GetEnvironmentValue(
"MAGICK_CODER_MODULE_PATH");
551 #if defined(MAGICKCORE_CODER_PATH)
552 if (module_path == (
char *) NULL)
553 module_path=AcquireString(MAGICKCORE_CODER_PATH);
557 case MagickImageFilterModule:
559 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
560 "Searching for filter module file \"%s\" ...",filename);
561 module_path=GetEnvironmentValue(
"MAGICK_CODER_FILTER_PATH");
562 #if defined(MAGICKCORE_FILTER_PATH)
563 if (module_path == (
char *) NULL)
564 module_path=AcquireString(MAGICKCORE_FILTER_PATH);
569 if (module_path != (
char *) NULL)
575 for (p=module_path-1; p != (
char *) NULL; )
577 (void) CopyMagickString(path,p+1,MaxTextExtent);
578 q=strchr(path,DirectoryListSeparator);
579 if (q != (
char *) NULL)
581 q=path+strlen(path)-1;
582 if ((q >= path) && (*q != *DirectorySeparator))
583 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
584 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
585 #if defined(MAGICKCORE_HAVE_REALPATH)
588 resolved_path[PATH_MAX+1];
590 if (realpath(path,resolved_path) != (
char *) NULL)
591 (void) CopyMagickString(path,resolved_path,MaxTextExtent);
594 if (IsPathAccessible(path) != MagickFalse)
596 module_path=DestroyString(module_path);
599 p=strchr(p+1,DirectoryListSeparator);
601 module_path=DestroyString(module_path);
603 #if defined(MAGICKCORE_INSTALLED_SUPPORT)
605 #if defined(MAGICKCORE_CODER_PATH)
615 case MagickImageCoderModule:
618 directory=MAGICKCORE_CODER_PATH;
621 case MagickImageFilterModule:
623 directory=MAGICKCORE_FILTER_PATH;
627 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s",directory,filename);
628 if (IsPathAccessible(path) == MagickFalse)
630 ThrowFileException(exception,ConfigureWarning,
631 "UnableToOpenModuleFile",path);
637 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
650 case MagickImageCoderModule:
653 registery_key=
"CoderModulesPath";
656 case MagickImageFilterModule:
658 registery_key=
"FilterModulesPath";
662 key_value=NTRegistryKeyLookup(registery_key);
663 if (key_value == (
unsigned char *) NULL)
665 ThrowMagickException(exception,GetMagickModule(),ConfigureError,
666 "RegistryKeyLookupFailed",
"`%s'",registery_key);
669 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",(
char *) key_value,
670 DirectorySeparator,filename);
671 key_value=(
unsigned char *) RelinquishMagickMemory(key_value);
672 if (IsPathAccessible(path) == MagickFalse)
674 ThrowFileException(exception,ConfigureWarning,
675 "UnableToOpenModuleFile",path);
682 #if !defined(MAGICKCORE_CODER_PATH) && !defined(MAGICKCORE_WINDOWS_SUPPORT)
683 # error MAGICKCORE_CODER_PATH or MAGICKCORE_WINDOWS_SUPPORT must be defined when MAGICKCORE_INSTALLED_SUPPORT is defined
690 home=GetEnvironmentValue(
"MAGICK_HOME");
691 if (home != (
char *) NULL)
696 #if !defined(MAGICKCORE_POSIX_SUPPORT)
697 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",home,
698 DirectorySeparator,filename);
705 case MagickImageCoderModule:
708 directory=MAGICKCORE_CODER_RELATIVE_PATH;
711 case MagickImageFilterModule:
713 directory=MAGICKCORE_FILTER_RELATIVE_PATH;
717 (void) FormatLocaleString(path,MaxTextExtent,
"%s/lib/%s/%s",home,
720 home=DestroyString(home);
721 if (IsPathAccessible(path) != MagickFalse)
725 if (*GetClientPath() !=
'\0')
730 #if !defined(MAGICKCORE_POSIX_SUPPORT)
731 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s%s",GetClientPath(),
732 DirectorySeparator,filename);
735 prefix[MaxTextExtent];
742 case MagickImageCoderModule:
748 case MagickImageFilterModule:
754 (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent);
755 ChopPathComponents(prefix,1);
756 (void) FormatLocaleString(path,MaxTextExtent,
"%s/lib/%s/%s/%s",prefix,
757 MAGICKCORE_MODULES_RELATIVE_PATH,directory,filename);
759 if (IsPathAccessible(path) != MagickFalse)
762 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
767 if ((NTGetModulePath(
"CORE_RL_magick_.dll",path) != MagickFalse) ||
768 (NTGetModulePath(
"CORE_DB_magick_.dll",path) != MagickFalse) ||
769 (NTGetModulePath(
"Magick.dll",path) != MagickFalse))
771 (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent);
772 (void) ConcatenateMagickString(path,filename,MaxTextExtent);
773 if (IsPathAccessible(path) != MagickFalse)
782 home=GetEnvironmentValue(
"XDG_CONFIG_HOME");
783 #if defined(MAGICKCORE_WINDOWS_SUPPORT) || defined(__MINGW32__)
784 if (home == (
char *) NULL)
785 home=GetEnvironmentValue(
"LOCALAPPDATA");
786 if (home == (
char *) NULL)
787 home=GetEnvironmentValue(
"APPDATA");
788 if (home == (
char *) NULL)
789 home=GetEnvironmentValue(
"USERPROFILE");
791 if (home != (
char *) NULL)
796 (void) FormatLocaleString(path,MaxTextExtent,
"%s%sImageMagick%s%s",
797 home,DirectorySeparator,DirectorySeparator,filename);
798 home=DestroyString(home);
799 if (IsPathAccessible(path) != MagickFalse)
802 home=GetEnvironmentValue(
"HOME");
803 if (home != (
char *) NULL)
808 (void) FormatLocaleString(path,MaxTextExtent,
809 "%s%s.config%sImageMagick%s%s",home,DirectorySeparator,
810 DirectorySeparator,DirectorySeparator,filename);
811 if (IsPathAccessible(path) != MagickFalse)
813 home=DestroyString(home);
819 (void) FormatLocaleString(path,MaxTextExtent,
"%s%s.magick%s%s",home,
820 DirectorySeparator,DirectorySeparator,filename);
821 home=DestroyString(home);
822 if (IsPathAccessible(path) != MagickFalse)
829 if (IsPathAccessible(path) != MagickFalse)
831 if (exception->severity < ConfigureError)
832 ThrowFileException(exception,ConfigureWarning,
"UnableToOpenModuleFile",
862 static void *DestroyModuleNode(
void *module_info)
870 exception=AcquireExceptionInfo();
872 if (UnregisterModule(p,exception) == MagickFalse)
873 CatchException(exception);
874 if (p->tag != (
char *) NULL)
875 p->tag=DestroyString(p->tag);
876 if (p->path != (
char *) NULL)
877 p->path=DestroyString(p->path);
878 exception=DestroyExceptionInfo(exception);
879 return(RelinquishMagickMemory(p));
882 static MagickBooleanType IsModuleTreeInstantiated(
885 magick_unreferenced(exception);
890 ActivateSemaphoreInfo(&module_semaphore);
891 LockSemaphoreInfo(module_semaphore);
903 splay_tree=NewSplayTree(CompareSplayTreeString,
904 (
void *(*)(
void *)) NULL,DestroyModuleNode);
906 ThrowFatalException(ResourceLimitFatalError,
907 "MemoryAllocationFailed");
908 module_info=AcquireModuleInfo((
const char *) NULL,
"[boot-strap]");
909 module_info->stealth=MagickTrue;
910 status=AddValueToSplayTree(splay_tree,module_info->tag,module_info);
911 if (status == MagickFalse)
912 ThrowFatalException(ResourceLimitFatalError,
913 "MemoryAllocationFailed");
914 if (lt_dlinit() != 0)
915 ThrowFatalException(ModuleFatalError,
916 "UnableToInitializeModuleLoader");
917 module_list=splay_tree;
919 UnlockSemaphoreInfo(module_semaphore);
921 return(module_list != (
SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
924 MagickExport MagickBooleanType InitializeModuleList(
ExceptionInfo *exception)
926 return(IsModuleTreeInstantiated(exception));
962 MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
984 assert(images != (
Image **) NULL);
985 assert((*images)->signature == MagickCoreSignature);
986 if (IsEventLogging() != MagickFalse)
987 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
988 (*images)->filename);
989 rights=ReadPolicyRights;
990 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
993 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
994 "NotAuthorized",
"`%s'",tag);
997 #if !defined(MAGICKCORE_BUILD_MODULES)
1002 status=InvokeStaticImageFilter(tag,images,argc,argv,exception);
1003 if (status != MagickFalse)
1007 TagToFilterModuleName(tag,name);
1008 status=GetMagickModulePath(name,MagickImageFilterModule,path,exception);
1009 if (status == MagickFalse)
1011 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1012 "UnableToLoadModule",
"`%s': %s",name,path);
1013 return(MagickFalse);
1018 handle=(ModuleHandle) lt_dlopen(path);
1019 if (handle == (ModuleHandle) NULL)
1021 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1022 "UnableToLoadModule",
"`%s': %s",name,lt_dlerror());
1023 return(MagickFalse);
1028 #if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1029 (void) FormatLocaleString(name,MaxTextExtent,
"%sImage",tag);
1031 (void) FormatLocaleString(name,MaxTextExtent,
"%s%sImage",
1032 MAGICKCORE_NAMESPACE_PREFIX_TAG,tag);
1037 ClearMagickException(exception);
1038 image_filter=(ImageFilterHandler *) lt_dlsym(handle,name);
1039 if (image_filter == (ImageFilterHandler *) NULL)
1040 (
void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1041 "UnableToLoadModule",
"`%s': %s",name,lt_dlerror());
1047 if (IsEventLogging() != MagickFalse)
1048 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1049 "Invoking \"%s\" dynamic image filter",tag);
1050 signature=image_filter(images,argc,argv,exception);
1051 if (IsEventLogging() != MagickFalse)
1052 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
"\"%s\" completes",
1054 if (signature != MagickImageFilterSignature)
1055 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1056 "ImageFilterSignatureMismatch",
"`%s': %8lx != %8lx",tag,
1057 (
unsigned long) signature,(
unsigned long) MagickImageFilterSignature);
1062 if (lt_dlclose(handle) != 0)
1063 (
void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1064 "UnableToCloseModule",
"`%s': %s",name,lt_dlerror());
1065 return(exception->severity < ErrorException ? MagickTrue : MagickFalse);
1092 MagickExport MagickBooleanType ListModuleInfo(FILE *file,
1096 filename[MaxTextExtent],
1097 module_path[MaxTextExtent],
1099 path[MaxTextExtent];
1107 if (file == (
const FILE *) NULL)
1112 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1113 if (modules == (
char **) NULL)
1114 return(MagickFalse);
1115 TagToCoderModuleName(
"magick",filename);
1116 (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path,
1118 GetPathComponent(module_path,HeadPath,path);
1119 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1120 (void) FormatLocaleFile(file,
"Image Coder\n");
1121 (void) FormatLocaleFile(file,
1122 "-------------------------------------------------"
1123 "------------------------------\n");
1124 for (i=0; i < (ssize_t) number_modules; i++)
1126 (void) FormatLocaleFile(file,
"%s",modules[i]);
1127 (void) FormatLocaleFile(file,
"\n");
1129 (void) fflush(file);
1133 for (i=0; i < (ssize_t) number_modules; i++)
1134 modules[i]=DestroyString(modules[i]);
1135 modules=(
char **) RelinquishMagickMemory(modules);
1139 modules=GetModuleList(
"*",MagickImageFilterModule,&number_modules,exception);
1140 if (modules == (
char **) NULL)
1141 return(MagickFalse);
1142 TagToFilterModuleName(
"analyze",filename);
1143 (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path,
1145 GetPathComponent(module_path,HeadPath,path);
1146 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",path);
1147 (void) FormatLocaleFile(file,
"Image Filter\n");
1148 (void) FormatLocaleFile(file,
1149 "-------------------------------------------------"
1150 "------------------------------\n");
1151 for (i=0; i < (ssize_t) number_modules; i++)
1153 (void) FormatLocaleFile(file,
"%s",modules[i]);
1154 (void) FormatLocaleFile(file,
"\n");
1156 (void) fflush(file);
1160 for (i=0; i < (ssize_t) number_modules; i++)
1161 modules[i]=DestroyString(modules[i]);
1162 modules=(
char **) RelinquishMagickMemory(modules);
1184 MagickExport MagickBooleanType ModuleComponentGenesis(
void)
1193 module_semaphore=AllocateSemaphoreInfo();
1194 exception=AcquireExceptionInfo();
1195 status=IsModuleTreeInstantiated(exception);
1196 exception=DestroyExceptionInfo(exception);
1218 MagickExport
void ModuleComponentTerminus(
void)
1221 ActivateSemaphoreInfo(&module_semaphore);
1222 DestroyModuleList();
1223 DestroySemaphoreInfo(&module_semaphore);
1251 MagickExport MagickBooleanType OpenModule(
const char *module,
1255 module_name[MaxTextExtent],
1256 name[MaxTextExtent],
1257 path[MaxTextExtent];
1280 assert(module != (
const char *) NULL);
1281 module_info=(
ModuleInfo *) GetModuleInfo(module,exception);
1284 (void) CopyMagickString(module_name,module,MaxTextExtent);
1285 p=GetCoderInfo(module,exception);
1287 (void) CopyMagickString(module_name,p->name,MaxTextExtent);
1288 rights=(PolicyRights) (ReadPolicyRights | WritePolicyRights);
1289 if (IsRightsAuthorized(ModulePolicyDomain,rights,module_name) == MagickFalse)
1292 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1293 "NotAuthorized",
"`%s'",module);
1294 return(MagickFalse);
1296 if (GetValueFromSplayTree(module_list,module_name) != (
void *) NULL)
1301 handle=(ModuleHandle) NULL;
1302 TagToCoderModuleName(module_name,name);
1303 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1304 "Searching for module \"%s\" using filename \"%s\"",module_name,name);
1306 status=GetMagickModulePath(name,MagickImageCoderModule,path,exception);
1307 if (status == MagickFalse)
1308 return(MagickFalse);
1312 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1313 "Opening module at path \"%s\"",path);
1314 handle=(ModuleHandle) lt_dlopen(path);
1315 if (handle == (ModuleHandle) NULL)
1317 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1318 "UnableToLoadModule",
"`%s': %s",path,lt_dlerror());
1319 return(MagickFalse);
1324 module_info=AcquireModuleInfo(path,module_name);
1325 module_info->handle=handle;
1326 if (RegisterModule(module_info,exception) == (
ModuleInfo *) NULL)
1327 return(MagickFalse);
1331 TagToModuleName(module_name,
"Register%sImage",name);
1332 module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name);
1333 if (module_info->register_module == (size_t (*)(
void)) NULL)
1335 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1336 "UnableToRegisterImageFormat",
"`%s': %s",module_name,lt_dlerror());
1337 return(MagickFalse);
1339 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1340 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1341 (
void *) module_info->register_module);
1345 TagToModuleName(module_name,
"Unregister%sImage",name);
1346 module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name);
1347 if (module_info->unregister_module == (void (*)(
void)) NULL)
1349 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1350 "UnableToRegisterImageFormat",
"`%s': %s",module_name,lt_dlerror());
1351 return(MagickFalse);
1353 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1354 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1355 (
void *) module_info->unregister_module);
1356 signature=module_info->register_module();
1357 if (signature != MagickImageCoderSignature)
1359 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1360 "ImageCoderSignatureMismatch",
"`%s': %8lx != %8lx",module_name,
1361 (
unsigned long) signature,(
unsigned long) MagickImageCoderSignature);
1362 return(MagickFalse);
1389 MagickExport MagickBooleanType OpenModules(
ExceptionInfo *exception)
1403 (void) GetMagickInfo((
char *) NULL,exception);
1405 modules=GetModuleList(
"*",MagickImageCoderModule,&number_modules,exception);
1406 if ((modules == (
char **) NULL) || (*modules == (
char *) NULL))
1408 if (modules != (
char **) NULL)
1409 modules=(
char **) RelinquishMagickMemory(modules);
1410 return(MagickFalse);
1412 for (i=0; i < (ssize_t) number_modules; i++)
1413 (
void) OpenModule(modules[i],exception);
1417 for (i=0; i < (ssize_t) number_modules; i++)
1418 modules[i]=DestroyString(modules[i]);
1419 modules=(
char **) RelinquishMagickMemory(modules);
1458 assert(module_info->signature == MagickCoreSignature);
1459 if (IsEventLogging() != MagickFalse)
1460 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1463 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
1464 if (status == MagickFalse)
1465 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1466 "MemoryAllocationFailed",
"`%s'",module_info->tag);
1467 return(module_info);
1495 static void TagToCoderModuleName(
const char *tag,
char *name)
1497 assert(tag != (
char *) NULL);
1498 assert(name != (
char *) NULL);
1499 if (IsEventLogging() != MagickFalse)
1500 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1501 #if defined(MAGICKCORE_LTDL_DELEGATE)
1502 (void) FormatLocaleString(name,MaxTextExtent,
"%s.la",tag);
1503 (void) LocaleLower(name);
1505 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
1506 if (LocaleNCompare(
"IM_MOD_",tag,7) == 0)
1507 (
void) CopyMagickString(name,tag,MaxTextExtent);
1511 (void) FormatLocaleString(name,MaxTextExtent,
"IM_MOD_DB_%s_.dll",tag);
1513 (void) FormatLocaleString(name,MaxTextExtent,
"IM_MOD_RL_%s_.dll",tag);
1545 static void TagToFilterModuleName(
const char *tag,
char *name)
1547 assert(tag != (
char *) NULL);
1548 assert(name != (
char *) NULL);
1549 if (IsEventLogging() != MagickFalse)
1550 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1551 #if !defined(MAGICKCORE_LTDL_DELEGATE)
1552 (void) FormatLocaleString(name,MaxTextExtent,
"%s.dll",tag);
1554 (void) FormatLocaleString(name,MaxTextExtent,
"%s.la",tag);
1586 static void TagToModuleName(
const char *tag,
const char *format,
char *module)
1589 name[MaxTextExtent];
1591 assert(tag != (
const char *) NULL);
1592 assert(format != (
const char *) NULL);
1593 assert(module != (
char *) NULL);
1594 if (IsEventLogging() != MagickFalse)
1595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",tag);
1596 (void) CopyMagickString(name,tag,MaxTextExtent);
1598 #if !defined(MAGICKCORE_NAMESPACE_PREFIX)
1599 (void) FormatLocaleString(module,MaxTextExtent,format,name);
1603 prefix_format[MaxTextExtent];
1605 (void) FormatLocaleString(prefix_format,MaxTextExtent,
"%s%s",
1606 MAGICKCORE_NAMESPACE_PREFIX_TAG,format);
1607 (void) FormatLocaleString(module,MaxTextExtent,prefix_format,name);
1638 static MagickBooleanType UnregisterModule(
const ModuleInfo *module_info,
1644 assert(module_info != (
const ModuleInfo *) NULL);
1646 if (IsEventLogging() != MagickFalse)
1647 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",module_info->tag);
1648 if (module_info->unregister_module == NULL)
1650 module_info->unregister_module();
1651 if (lt_dlclose((ModuleHandle) module_info->handle) != 0)
1653 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
1654 "UnableToCloseModule",
"`%s': %s",module_info->tag,lt_dlerror());
1655 return(MagickFalse);
1661 #if !defined(MAGICKCORE_BUILD_MODULES)
1666 MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file),
1669 magick_unreferenced(file);
1670 magick_unreferenced(exception);
1674 MagickExport MagickBooleanType InvokeDynamicImageFilter(
const char *tag,
1680 assert(image != (
Image **) NULL);
1681 assert((*image)->signature == MagickCoreSignature);
1682 if (IsEventLogging() != MagickFalse)
1683 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",(*image)->filename);
1684 rights=ReadPolicyRights;
1685 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
1688 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1689 "NotAuthorized",
"`%s'",tag);
1690 return(MagickFalse);
1692 #if defined(MAGICKCORE_BUILD_MODULES)
1702 image_filter=(ImageFilterHandler *) NULL;
1703 if (LocaleCompare(
"analyze",tag) == 0)
1704 image_filter=(ImageFilterHandler *) analyzeImage;
1705 if (image_filter == (ImageFilterHandler *) NULL)
1706 (
void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1707 "UnableToLoadModule",
"`%s'",tag);
1713 if ((*image)->debug != MagickFalse)
1714 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1715 "Invoking \"%s\" static image filter",tag);
1716 signature=image_filter(image,argc,argv,exception);
1717 if ((*image)->debug != MagickFalse)
1718 (void) LogMagickEvent(TransformEvent,GetMagickModule(),
1719 "\"%s\" completes",tag);
1720 if (signature != MagickImageFilterSignature)
1722 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
1723 "ImageFilterSignatureMismatch",
"`%s': %8lx != %8lx",tag,
1724 (
unsigned long) signature,(
unsigned long)
1725 MagickImageFilterSignature);
1726 return(MagickFalse);