blob: 60650c970aeb8ffcd8b81c0290ee6ef792c2c829 [file] [log] [blame]
cristy3ed852e2009-09-05 21:47:34 +00001/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% %
6% M M OOO DDDD U U L EEEEE %
7% MM MM O O D D U U L E %
8% M M M O O D D U U L EEE %
9% M M O O D D U U L E %
10% M M OOO DDDD UUU LLLLL EEEEE %
11% %
12% %
13% MagickCore Module Methods %
14% %
15% Software Design %
16% Bob Friesenhahn %
17% March 2000 %
18% %
19% %
cristyb56bb242014-11-25 17:12:48 +000020% Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization %
cristy3ed852e2009-09-05 21:47:34 +000021% dedicated to making software imaging solutions freely available. %
22% %
23% You may not use this file except in compliance with the License. You may %
24% obtain a copy of the License at %
25% %
26% http://www.imagemagick.org/script/license.php %
27% %
28% Unless required by applicable law or agreed to in writing, software %
29% distributed under the License is distributed on an "AS IS" BASIS, %
30% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
31% See the License for the specific language governing permissions and %
32% limitations under the License. %
33% %
34%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
35%
36%
37%
38*/
39
40/*
41 Include declarations.
42*/
cristy4c08aed2011-07-01 19:47:50 +000043#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/hashmap.h"
52#include "MagickCore/magic.h"
53#include "MagickCore/magick.h"
54#include "MagickCore/memory_.h"
55#include "MagickCore/module.h"
cristy5ff4eaf2011-09-03 01:38:02 +000056#include "MagickCore/module-private.h"
cristyd2d11ec2012-03-28 13:53:49 +000057#include "MagickCore/nt-base-private.h"
cristy4c08aed2011-07-01 19:47:50 +000058#include "MagickCore/policy.h"
59#include "MagickCore/semaphore.h"
60#include "MagickCore/splay-tree.h"
61#include "MagickCore/static.h"
62#include "MagickCore/string_.h"
cristy7832dc22011-09-05 01:21:53 +000063#include "MagickCore/string-private.h"
cristy4c08aed2011-07-01 19:47:50 +000064#include "MagickCore/token.h"
65#include "MagickCore/utility.h"
cristyd1dd6e42011-09-04 01:46:08 +000066#include "MagickCore/utility-private.h"
cristy3ed852e2009-09-05 21:47:34 +000067#if defined(MAGICKCORE_MODULES_SUPPORT)
68#if defined(MAGICKCORE_LTDL_DELEGATE)
69#include "ltdl.h"
70typedef lt_dlhandle ModuleHandle;
71#else
72typedef void *ModuleHandle;
73#endif
74
75/*
76 Define declarations.
77*/
78#if defined(MAGICKCORE_LTDL_DELEGATE)
79# define ModuleGlobExpression "*.la"
80#else
81# if defined(_DEBUG)
82# define ModuleGlobExpression "IM_MOD_DB_*.dll"
83# else
84# define ModuleGlobExpression "IM_MOD_RL_*.dll"
85# endif
86#endif
87
88/*
89 Global declarations.
90*/
91static SemaphoreInfo
92 *module_semaphore = (SemaphoreInfo *) NULL;
93
94static SplayTreeInfo
95 *module_list = (SplayTreeInfo *) NULL;
cristy3ed852e2009-09-05 21:47:34 +000096
97/*
98 Forward declarations.
99*/
100static const ModuleInfo
101 *RegisterModule(const ModuleInfo *,ExceptionInfo *);
102
103static MagickBooleanType
104 GetMagickModulePath(const char *,MagickModuleType,char *,ExceptionInfo *),
cristy904e5912014-03-15 19:53:14 +0000105 IsModuleTreeInstantiated(ExceptionInfo *),
cristy3ed852e2009-09-05 21:47:34 +0000106 UnregisterModule(const ModuleInfo *,ExceptionInfo *);
107
108static void
109 TagToCoderModuleName(const char *,char *),
110 TagToFilterModuleName(const char *,char *),
111 TagToModuleName(const char *,const char *,char *);
112
113/*
114%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
115% %
116% %
117% %
118% A c q u i r e M o d u l e I n f o %
119% %
120% %
121% %
122%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
123%
124% AcquireModuleInfo() allocates the ModuleInfo structure.
125%
126% The format of the AcquireModuleInfo method is:
127%
128% ModuleInfo *AcquireModuleInfo(const char *path,const char *tag)
129%
130% A description of each parameter follows:
131%
132% o path: the path associated with the tag.
133%
134% o tag: a character string that represents the image format we are
135% looking for.
136%
137*/
138MagickExport ModuleInfo *AcquireModuleInfo(const char *path,const char *tag)
139{
140 ModuleInfo
141 *module_info;
142
cristy73bd4a52010-10-05 11:24:23 +0000143 module_info=(ModuleInfo *) AcquireMagickMemory(sizeof(*module_info));
cristy3ed852e2009-09-05 21:47:34 +0000144 if (module_info == (ModuleInfo *) NULL)
145 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
146 (void) ResetMagickMemory(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=time(0);
cristye1c94d92015-06-28 12:16:33 +0000152 module_info->signature=MagickCoreSignature;
cristy3ed852e2009-09-05 21:47:34 +0000153 return(module_info);
154}
155
156/*
157%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
158% %
159% %
160% %
161% D e s t r o y M o d u l e L i s t %
162% %
163% %
164% %
165%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
166%
167% DestroyModuleList() unregisters any previously loaded modules and exits
168% the module loaded environment.
169%
170% The format of the DestroyModuleList module is:
171%
172% void DestroyModuleList(void)
173%
174*/
175MagickExport void DestroyModuleList(void)
176{
177 /*
178 Destroy magick modules.
179 */
cristyf84a1932010-01-03 18:00:18 +0000180 LockSemaphoreInfo(module_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000181#if defined(MAGICKCORE_MODULES_SUPPORT)
182 if (module_list != (SplayTreeInfo *) NULL)
183 module_list=DestroySplayTree(module_list);
cristy1e09ca22009-12-27 18:04:58 +0000184#endif
cristyf84a1932010-01-03 18:00:18 +0000185 UnlockSemaphoreInfo(module_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000186}
187
188/*
189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190% %
191% %
192% %
193% G e t M o d u l e I n f o %
194% %
195% %
196% %
197%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
198%
199% GetModuleInfo() returns a pointer to a ModuleInfo structure that matches the
200% specified tag. If tag is NULL, the head of the module list is returned. If
201% no modules are loaded, or the requested module is not found, NULL is
202% returned.
203%
204% The format of the GetModuleInfo module is:
205%
206% ModuleInfo *GetModuleInfo(const char *tag,ExceptionInfo *exception)
207%
208% A description of each parameter follows:
209%
210% o tag: a character string that represents the image format we are
211% looking for.
212%
213% o exception: return any errors or warnings in this structure.
214%
215*/
216MagickExport ModuleInfo *GetModuleInfo(const char *tag,ExceptionInfo *exception)
217{
cristy49d4d222014-03-16 00:37:58 +0000218 ModuleInfo
219 *module_info;
220
cristy904e5912014-03-15 19:53:14 +0000221 if (IsModuleTreeInstantiated(exception) == MagickFalse)
222 return((ModuleInfo *) NULL);
cristy49d4d222014-03-16 00:37:58 +0000223 LockSemaphoreInfo(module_semaphore);
224 ResetSplayTreeIterator(module_list);
cristy3ed852e2009-09-05 21:47:34 +0000225 if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0))
226 {
cristy3ed852e2009-09-05 21:47:34 +0000227#if defined(MAGICKCORE_MODULES_SUPPORT)
228 if (LocaleCompare(tag,"*") == 0)
229 (void) OpenModules(exception);
230#endif
cristy49d4d222014-03-16 00:37:58 +0000231 module_info=(ModuleInfo *) GetNextValueInSplayTree(module_list);
cristyf84a1932010-01-03 18:00:18 +0000232 UnlockSemaphoreInfo(module_semaphore);
cristy49d4d222014-03-16 00:37:58 +0000233 return(module_info);
cristy3ed852e2009-09-05 21:47:34 +0000234 }
cristy49d4d222014-03-16 00:37:58 +0000235 module_info=(ModuleInfo *) GetValueFromSplayTree(module_list,tag);
236 UnlockSemaphoreInfo(module_semaphore);
237 return(module_info);
cristy3ed852e2009-09-05 21:47:34 +0000238}
239
240/*
241%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
242% %
243% %
244% %
245% G e t M o d u l e I n f o L i s t %
246% %
247% %
248% %
249%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
250%
251% GetModuleInfoList() returns any modules that match the specified pattern.
252%
253% The format of the GetModuleInfoList function is:
254%
255% const ModuleInfo **GetModuleInfoList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000256% size_t *number_modules,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000257%
258% A description of each parameter follows:
259%
260% o pattern: Specifies a pointer to a text string containing a pattern.
261%
262% o number_modules: This integer returns the number of modules in the list.
263%
264% o exception: return any errors or warnings in this structure.
265%
266*/
267
268#if defined(__cplusplus) || defined(c_plusplus)
269extern "C" {
270#endif
271
272static int ModuleInfoCompare(const void *x,const void *y)
273{
274 const ModuleInfo
275 **p,
276 **q;
277
278 p=(const ModuleInfo **) x,
279 q=(const ModuleInfo **) y;
280 if (LocaleCompare((*p)->path,(*q)->path) == 0)
281 return(LocaleCompare((*p)->tag,(*q)->tag));
282 return(LocaleCompare((*p)->path,(*q)->path));
283}
284
285#if defined(__cplusplus) || defined(c_plusplus)
286}
287#endif
288
289MagickExport const ModuleInfo **GetModuleInfoList(const char *pattern,
cristybb503372010-05-27 20:51:26 +0000290 size_t *number_modules,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000291{
292 const ModuleInfo
293 **modules;
294
295 register const ModuleInfo
296 *p;
297
cristybb503372010-05-27 20:51:26 +0000298 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000299 i;
300
301 /*
302 Allocate module list.
303 */
304 assert(pattern != (char *) NULL);
305 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
cristybb503372010-05-27 20:51:26 +0000306 assert(number_modules != (size_t *) NULL);
cristy3ed852e2009-09-05 21:47:34 +0000307 *number_modules=0;
308 p=GetModuleInfo("*",exception);
309 if (p == (const ModuleInfo *) NULL)
310 return((const ModuleInfo **) NULL);
311 modules=(const ModuleInfo **) AcquireQuantumMemory((size_t)
312 GetNumberOfNodesInSplayTree(module_list)+1UL,sizeof(*modules));
313 if (modules == (const ModuleInfo **) NULL)
314 return((const ModuleInfo **) NULL);
315 /*
316 Generate module list.
317 */
cristyf84a1932010-01-03 18:00:18 +0000318 LockSemaphoreInfo(module_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000319 ResetSplayTreeIterator(module_list);
320 p=(const ModuleInfo *) GetNextValueInSplayTree(module_list);
321 for (i=0; p != (const ModuleInfo *) NULL; )
322 {
323 if ((p->stealth == MagickFalse) &&
324 (GlobExpression(p->tag,pattern,MagickFalse) != MagickFalse))
325 modules[i++]=p;
326 p=(const ModuleInfo *) GetNextValueInSplayTree(module_list);
327 }
cristyf84a1932010-01-03 18:00:18 +0000328 UnlockSemaphoreInfo(module_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000329 qsort((void *) modules,(size_t) i,sizeof(*modules),ModuleInfoCompare);
330 modules[i]=(ModuleInfo *) NULL;
cristybb503372010-05-27 20:51:26 +0000331 *number_modules=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000332 return(modules);
333}
334
335/*
336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
337% %
338% %
339% %
340% G e t M o d u l e L i s t %
341% %
342% %
343% %
344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
345%
346% GetModuleList() returns any image format modules that match the specified
347% pattern.
348%
349% The format of the GetModuleList function is:
350%
cristya6de29a2010-06-30 14:34:26 +0000351% char **GetModuleList(const char *pattern,const MagickModuleType type,
352% size_t *number_modules,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000353%
354% A description of each parameter follows:
355%
356% o pattern: Specifies a pointer to a text string containing a pattern.
357%
cristya6de29a2010-06-30 14:34:26 +0000358% o type: choose from MagickImageCoderModule or MagickImageFilterModule.
359%
cristy3ed852e2009-09-05 21:47:34 +0000360% o number_modules: This integer returns the number of modules in the
361% list.
362%
363% o exception: return any errors or warnings in this structure.
364%
365*/
366
367#if defined(__cplusplus) || defined(c_plusplus)
368extern "C" {
369#endif
370
371static int ModuleCompare(const void *x,const void *y)
372{
373 register const char
374 **p,
375 **q;
376
377 p=(const char **) x;
378 q=(const char **) y;
379 return(LocaleCompare(*p,*q));
380}
381
382#if defined(__cplusplus) || defined(c_plusplus)
383}
384#endif
385
386static inline int MagickReadDirectory(DIR *directory,struct dirent *entry,
387 struct dirent **result)
388{
389#if defined(MAGICKCORE_HAVE_READDIR_R)
390 return(readdir_r(directory,entry,result));
391#else
392 (void) entry;
393 errno=0;
394 *result=readdir(directory);
395 return(errno);
396#endif
397}
398
399MagickExport char **GetModuleList(const char *pattern,
cristya6de29a2010-06-30 14:34:26 +0000400 const MagickModuleType type,size_t *number_modules,ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000401{
Cristy7e784cd2015-08-22 16:54:07 -0400402#define MaxModules 511
403
cristy3ed852e2009-09-05 21:47:34 +0000404 char
405 **modules,
cristy151b66d2015-04-15 10:50:31 +0000406 filename[MagickPathExtent],
407 module_path[MagickPathExtent],
408 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +0000409
410 DIR
411 *directory;
412
413 MagickBooleanType
414 status;
415
cristybb503372010-05-27 20:51:26 +0000416 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +0000417 i;
418
419 size_t
cristyd1df72d2010-06-29 02:17:03 +0000420 max_entries;
cristy3ed852e2009-09-05 21:47:34 +0000421
422 struct dirent
423 *buffer,
424 *entry;
425
cristy3ed852e2009-09-05 21:47:34 +0000426 /*
cristya6de29a2010-06-30 14:34:26 +0000427 Locate all modules in the image coder or filter path.
cristy3ed852e2009-09-05 21:47:34 +0000428 */
cristya6de29a2010-06-30 14:34:26 +0000429 switch (type)
430 {
431 case MagickImageCoderModule:
432 default:
433 {
434 TagToCoderModuleName("magick",filename);
435 status=GetMagickModulePath(filename,MagickImageCoderModule,module_path,
436 exception);
437 break;
438 }
439 case MagickImageFilterModule:
440 {
441 TagToFilterModuleName("analyze",filename);
442 status=GetMagickModulePath(filename,MagickImageFilterModule,module_path,
443 exception);
444 break;
445 }
446 }
cristyd1df72d2010-06-29 02:17:03 +0000447 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +0000448 return((char **) NULL);
449 GetPathComponent(module_path,HeadPath,path);
Cristy7e784cd2015-08-22 16:54:07 -0400450 max_entries=MaxModules;
cristy3ed852e2009-09-05 21:47:34 +0000451 modules=(char **) AcquireQuantumMemory((size_t) max_entries+1UL,
452 sizeof(*modules));
453 if (modules == (char **) NULL)
454 return((char **) NULL);
455 *modules=(char *) NULL;
456 directory=opendir(path);
457 if (directory == (DIR *) NULL)
458 {
459 modules=(char **) RelinquishMagickMemory(modules);
460 return((char **) NULL);
461 }
cristyaaaff842013-06-30 02:48:11 +0000462 buffer=(struct dirent *) AcquireMagickMemory(sizeof(*buffer)+FILENAME_MAX+1);
cristy3ed852e2009-09-05 21:47:34 +0000463 if (buffer == (struct dirent *) NULL)
464 ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed");
465 i=0;
466 while ((MagickReadDirectory(directory,buffer,&entry) == 0) &&
467 (entry != (struct dirent *) NULL))
468 {
469 status=GlobExpression(entry->d_name,ModuleGlobExpression,MagickFalse);
470 if (status == MagickFalse)
471 continue;
472 if (GlobExpression(entry->d_name,pattern,MagickFalse) == MagickFalse)
473 continue;
cristybb503372010-05-27 20:51:26 +0000474 if (i >= (ssize_t) max_entries)
cristy3ed852e2009-09-05 21:47:34 +0000475 {
476 modules=(char **) NULL;
477 if (~max_entries > max_entries)
478 modules=(char **) ResizeQuantumMemory(modules,(size_t)
479 (max_entries << 1),sizeof(*modules));
480 max_entries<<=1;
481 if (modules == (char **) NULL)
482 break;
483 }
484 /*
485 Add new module name to list.
486 */
487 modules[i]=AcquireString((char *) NULL);
488 GetPathComponent(entry->d_name,BasePath,modules[i]);
cristy3ed852e2009-09-05 21:47:34 +0000489 if (LocaleNCompare("IM_MOD_",modules[i],7) == 0)
490 {
cristy151b66d2015-04-15 10:50:31 +0000491 (void) CopyMagickString(modules[i],modules[i]+10,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000492 modules[i][strlen(modules[i])-1]='\0';
493 }
494 i++;
495 }
496 buffer=(struct dirent *) RelinquishMagickMemory(buffer);
497 (void) closedir(directory);
498 if (modules == (char **) NULL)
499 {
500 (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError,
cristyefe601c2013-01-05 17:51:12 +0000501 "MemoryAllocationFailed","`%s'",pattern);
cristy3ed852e2009-09-05 21:47:34 +0000502 return((char **) NULL);
503 }
504 qsort((void *) modules,(size_t) i,sizeof(*modules),ModuleCompare);
505 modules[i]=(char *) NULL;
cristybb503372010-05-27 20:51:26 +0000506 *number_modules=(size_t) i;
cristy3ed852e2009-09-05 21:47:34 +0000507 return(modules);
508}
509
510/*
511%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
512% %
513% %
514% %
515% G e t M a g i c k M o d u l e P a t h %
516% %
517% %
518% %
519%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
520%
521% GetMagickModulePath() finds a module with the specified module type and
522% filename.
523%
524% The format of the GetMagickModulePath module is:
525%
526% MagickBooleanType GetMagickModulePath(const char *filename,
527% MagickModuleType module_type,char *path,ExceptionInfo *exception)
528%
529% A description of each parameter follows:
530%
531% o filename: the module file name.
532%
533% o module_type: the module type: MagickImageCoderModule or
534% MagickImageFilterModule.
535%
536% o path: the path associated with the filename.
537%
538% o exception: return any errors or warnings in this structure.
539%
540*/
541static MagickBooleanType GetMagickModulePath(const char *filename,
542 MagickModuleType module_type,char *path,ExceptionInfo *exception)
543{
544 char
545 *module_path;
546
547 assert(filename != (const char *) NULL);
548 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename);
549 assert(path != (char *) NULL);
550 assert(exception != (ExceptionInfo *) NULL);
cristy151b66d2015-04-15 10:50:31 +0000551 (void) CopyMagickString(path,filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000552 module_path=(char *) NULL;
553 switch (module_type)
554 {
555 case MagickImageCoderModule:
556 default:
557 {
558 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
559 "Searching for coder module file \"%s\" ...",filename);
560 module_path=GetEnvironmentValue("MAGICK_CODER_MODULE_PATH");
561#if defined(MAGICKCORE_CODER_PATH)
562 if (module_path == (char *) NULL)
563 module_path=AcquireString(MAGICKCORE_CODER_PATH);
564#endif
565 break;
566 }
567 case MagickImageFilterModule:
568 {
569 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
570 "Searching for filter module file \"%s\" ...",filename);
571 module_path=GetEnvironmentValue("MAGICK_CODER_FILTER_PATH");
572#if defined(MAGICKCORE_FILTER_PATH)
573 if (module_path == (char *) NULL)
574 module_path=AcquireString(MAGICKCORE_FILTER_PATH);
575#endif
576 break;
577 }
578 }
579 if (module_path != (char *) NULL)
580 {
581 register char
582 *p,
583 *q;
584
585 for (p=module_path-1; p != (char *) NULL; )
586 {
cristy151b66d2015-04-15 10:50:31 +0000587 (void) CopyMagickString(path,p+1,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000588 q=strchr(path,DirectoryListSeparator);
589 if (q != (char *) NULL)
590 *q='\0';
591 q=path+strlen(path)-1;
592 if ((q >= path) && (*q != *DirectorySeparator))
cristy151b66d2015-04-15 10:50:31 +0000593 (void) ConcatenateMagickString(path,DirectorySeparator,MagickPathExtent);
594 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000595 if (IsPathAccessible(path) != MagickFalse)
596 {
597 module_path=DestroyString(module_path);
598 return(MagickTrue);
599 }
600 p=strchr(p+1,DirectoryListSeparator);
601 }
602 module_path=DestroyString(module_path);
603 }
604#if defined(MAGICKCORE_INSTALLED_SUPPORT)
cristyd1df72d2010-06-29 02:17:03 +0000605 else
cristy3ed852e2009-09-05 21:47:34 +0000606#if defined(MAGICKCORE_CODER_PATH)
607 {
608 const char
609 *directory;
610
611 /*
612 Search hard coded paths.
613 */
614 switch (module_type)
615 {
616 case MagickImageCoderModule:
617 default:
618 {
619 directory=MAGICKCORE_CODER_PATH;
620 break;
621 }
622 case MagickImageFilterModule:
623 {
624 directory=MAGICKCORE_FILTER_PATH;
625 break;
626 }
627 }
cristy151b66d2015-04-15 10:50:31 +0000628 (void) FormatLocaleString(path,MagickPathExtent,"%s%s",directory,filename);
cristy3ed852e2009-09-05 21:47:34 +0000629 if (IsPathAccessible(path) == MagickFalse)
630 {
631 ThrowFileException(exception,ConfigureWarning,
632 "UnableToOpenModuleFile",path);
633 return(MagickFalse);
634 }
635 return(MagickTrue);
636 }
637#else
cristy0157aea2010-04-24 21:12:18 +0000638#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000639 {
640 const char
641 *registery_key;
642
643 unsigned char
644 *key_value;
645
646 /*
647 Locate path via registry key.
648 */
649 switch (module_type)
650 {
651 case MagickImageCoderModule:
652 default:
653 {
654 registery_key="CoderModulesPath";
655 break;
656 }
657 case MagickImageFilterModule:
658 {
659 registery_key="FilterModulesPath";
660 break;
661 }
662 }
663 key_value=NTRegistryKeyLookup(registery_key);
664 if (key_value == (unsigned char *) NULL)
665 {
666 ThrowMagickException(exception,GetMagickModule(),ConfigureError,
cristyefe601c2013-01-05 17:51:12 +0000667 "RegistryKeyLookupFailed","`%s'",registery_key);
cristy3ed852e2009-09-05 21:47:34 +0000668 return(MagickFalse);
669 }
cristy151b66d2015-04-15 10:50:31 +0000670 (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",(char *) key_value,
cristy3ed852e2009-09-05 21:47:34 +0000671 DirectorySeparator,filename);
672 key_value=(unsigned char *) RelinquishMagickMemory(key_value);
673 if (IsPathAccessible(path) == MagickFalse)
674 {
675 ThrowFileException(exception,ConfigureWarning,
676 "UnableToOpenModuleFile",path);
677 return(MagickFalse);
678 }
679 return(MagickTrue);
680 }
681#endif
682#endif
cristy0157aea2010-04-24 21:12:18 +0000683#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
cristy3ed852e2009-09-05 21:47:34 +0000685#endif
686#else
687 {
688 char
689 *home;
690
691 home=GetEnvironmentValue("MAGICK_HOME");
692 if (home != (char *) NULL)
693 {
694 /*
695 Search MAGICK_HOME.
696 */
697#if !defined(MAGICKCORE_POSIX_SUPPORT)
cristy151b66d2015-04-15 10:50:31 +0000698 (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",home,
cristy3ed852e2009-09-05 21:47:34 +0000699 DirectorySeparator,filename);
700#else
701 const char
702 *directory;
703
704 switch (module_type)
705 {
706 case MagickImageCoderModule:
707 default:
708 {
709 directory=MAGICKCORE_CODER_RELATIVE_PATH;
710 break;
711 }
712 case MagickImageFilterModule:
713 {
714 directory=MAGICKCORE_FILTER_RELATIVE_PATH;
715 break;
716 }
717 }
cristy151b66d2015-04-15 10:50:31 +0000718 (void) FormatLocaleString(path,MagickPathExtent,"%s/lib/%s/%s",home,
cristy3ed852e2009-09-05 21:47:34 +0000719 directory,filename);
720#endif
721 home=DestroyString(home);
722 if (IsPathAccessible(path) != MagickFalse)
723 return(MagickTrue);
724 }
725 }
726 if (*GetClientPath() != '\0')
727 {
728 /*
729 Search based on executable directory.
730 */
731#if !defined(MAGICKCORE_POSIX_SUPPORT)
cristy151b66d2015-04-15 10:50:31 +0000732 (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",GetClientPath(),
cristy3ed852e2009-09-05 21:47:34 +0000733 DirectorySeparator,filename);
734#else
735 char
cristy151b66d2015-04-15 10:50:31 +0000736 prefix[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +0000737
738 const char
739 *directory;
740
741 switch (module_type)
742 {
743 case MagickImageCoderModule:
744 default:
745 {
cristy905e5302011-11-09 18:08:43 +0000746 directory="coders";
cristy3ed852e2009-09-05 21:47:34 +0000747 break;
748 }
749 case MagickImageFilterModule:
750 {
751 directory="filters";
752 break;
753 }
754 }
cristy151b66d2015-04-15 10:50:31 +0000755 (void) CopyMagickString(prefix,GetClientPath(),MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000756 ChopPathComponents(prefix,1);
cristy151b66d2015-04-15 10:50:31 +0000757 (void) FormatLocaleString(path,MagickPathExtent,"%s/lib/%s/%s/%s",prefix,
cristyfee63262012-12-02 21:47:04 +0000758 MAGICKCORE_MODULES_RELATIVE_PATH,directory,filename);
cristy3ed852e2009-09-05 21:47:34 +0000759#endif
760 if (IsPathAccessible(path) != MagickFalse)
761 return(MagickTrue);
762 }
cristy0157aea2010-04-24 21:12:18 +0000763#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +0000764 {
765 /*
766 Search module path.
767 */
dirk7c6c80c2015-01-03 23:41:04 +0000768 if ((NTGetModulePath("CORE_RL_MagickCore_.dll",path) != MagickFalse) ||
769 (NTGetModulePath("CORE_DB_MagickCore_.dll",path) != MagickFalse))
cristy3ed852e2009-09-05 21:47:34 +0000770 {
cristy151b66d2015-04-15 10:50:31 +0000771 (void) ConcatenateMagickString(path,DirectorySeparator,MagickPathExtent);
772 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000773 if (IsPathAccessible(path) != MagickFalse)
774 return(MagickTrue);
775 }
776 }
777#endif
778 {
779 char
780 *home;
781
782 home=GetEnvironmentValue("HOME");
783 if (home == (char *) NULL)
784 home=GetEnvironmentValue("USERPROFILE");
785 if (home != (char *) NULL)
786 {
787 /*
cristy9f3b4fc2014-02-08 14:56:20 +0000788 Search $HOME/.config/ImageMagick.
cristy3ed852e2009-09-05 21:47:34 +0000789 */
cristy151b66d2015-04-15 10:50:31 +0000790 (void) FormatLocaleString(path,MagickPathExtent,
cristy9f3b4fc2014-02-08 14:56:20 +0000791 "%s%s.config%sImageMagick%s%s",home,DirectorySeparator,
cristy3ed852e2009-09-05 21:47:34 +0000792 DirectorySeparator,DirectorySeparator,filename);
793 home=DestroyString(home);
794 if (IsPathAccessible(path) != MagickFalse)
795 return(MagickTrue);
796 }
797 }
798 /*
799 Search current directory.
800 */
801 if (IsPathAccessible(path) != MagickFalse)
802 return(MagickTrue);
803 if (exception->severity < ConfigureError)
804 ThrowFileException(exception,ConfigureWarning,"UnableToOpenModuleFile",
805 path);
cristy3ed852e2009-09-05 21:47:34 +0000806#endif
807 return(MagickFalse);
808}
809
810/*
811%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
812% %
813% %
814% %
cristy904e5912014-03-15 19:53:14 +0000815% I s M o d u l e T r e e I n s t a n t i a t e d %
cristy3ed852e2009-09-05 21:47:34 +0000816% %
817% %
818% %
819%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
820%
cristy904e5912014-03-15 19:53:14 +0000821% IsModuleTreeInstantiated() determines if the module tree is instantiated.
822% If not, it instantiates the tree and returns it.
cristy3ed852e2009-09-05 21:47:34 +0000823%
cristy904e5912014-03-15 19:53:14 +0000824% The format of the IsModuleTreeInstantiated() method is:
cristy3ed852e2009-09-05 21:47:34 +0000825%
cristy904e5912014-03-15 19:53:14 +0000826% IsModuleTreeInstantiated(Exceptioninfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000827%
828% A description of each parameter follows.
829%
830% o exception: return any errors or warnings in this structure.
831%
832*/
833
834static void *DestroyModuleNode(void *module_info)
835{
836 ExceptionInfo
837 *exception;
838
839 register ModuleInfo
840 *p;
841
842 exception=AcquireExceptionInfo();
843 p=(ModuleInfo *) module_info;
844 if (UnregisterModule(p,exception) == MagickFalse)
845 CatchException(exception);
846 if (p->tag != (char *) NULL)
847 p->tag=DestroyString(p->tag);
848 if (p->path != (char *) NULL)
849 p->path=DestroyString(p->path);
850 exception=DestroyExceptionInfo(exception);
851 return(RelinquishMagickMemory(p));
852}
853
cristy904e5912014-03-15 19:53:14 +0000854static MagickBooleanType IsModuleTreeInstantiated(
cristy3ed852e2009-09-05 21:47:34 +0000855 ExceptionInfo *magick_unused(exception))
856{
cristy1460f262014-03-15 17:38:05 +0000857 if (module_list == (SplayTreeInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000858 {
cristy86e5ac92014-03-16 19:27:39 +0000859 if (module_semaphore == (SemaphoreInfo *) NULL)
860 ActivateSemaphoreInfo(&module_semaphore);
861 LockSemaphoreInfo(module_semaphore);
cristy1460f262014-03-15 17:38:05 +0000862 if (module_list == (SplayTreeInfo *) NULL)
cristy86e5ac92014-03-16 19:27:39 +0000863 {
864 MagickBooleanType
865 status;
866
867 ModuleInfo
868 *module_info;
869
870 module_list=NewSplayTree(CompareSplayTreeString,
871 (void *(*)(void *)) NULL,DestroyModuleNode);
872 if (module_list == (SplayTreeInfo *) NULL)
873 ThrowFatalException(ResourceLimitFatalError,
874 "MemoryAllocationFailed");
875 module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]");
876 module_info->stealth=MagickTrue;
877 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
878 if (status == MagickFalse)
879 ThrowFatalException(ResourceLimitFatalError,
880 "MemoryAllocationFailed");
881 if (lt_dlinit() != 0)
882 ThrowFatalException(ModuleFatalError,
883 "UnableToInitializeModuleLoader");
884 }
885 UnlockSemaphoreInfo(module_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000886 }
887 return(module_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
888}
889
890/*
891%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
892% %
893% %
894% %
cristy3ed852e2009-09-05 21:47:34 +0000895% I n v o k e D y n a m i c I m a g e F i l t e r %
896% %
897% %
898% %
899%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
900%
901% InvokeDynamicImageFilter() invokes a dynamic image filter.
902%
903% The format of the InvokeDynamicImageFilter module is:
904%
905% MagickBooleanType InvokeDynamicImageFilter(const char *tag,Image **image,
906% const int argc,const char **argv,ExceptionInfo *exception)
907%
908% A description of each parameter follows:
909%
910% o tag: a character string that represents the name of the particular
911% module.
912%
913% o image: the image.
914%
915% o argc: a pointer to an integer describing the number of elements in the
916% argument vector.
917%
918% o argv: a pointer to a text array containing the command line arguments.
919%
920% o exception: return any errors or warnings in this structure.
921%
922*/
923MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
924 Image **images,const int argc,const char **argv,ExceptionInfo *exception)
925{
926 char
cristy151b66d2015-04-15 10:50:31 +0000927 name[MagickPathExtent],
928 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +0000929
930 ImageFilterHandler
931 *image_filter;
932
cristyd1df72d2010-06-29 02:17:03 +0000933 MagickBooleanType
934 status;
935
cristy3ed852e2009-09-05 21:47:34 +0000936 ModuleHandle
937 handle;
938
939 PolicyRights
940 rights;
941
cristy3ed852e2009-09-05 21:47:34 +0000942 /*
943 Find the module.
944 */
945 assert(images != (Image **) NULL);
cristye1c94d92015-06-28 12:16:33 +0000946 assert((*images)->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000947 if ((*images)->debug != MagickFalse)
948 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
949 (*images)->filename);
950#if !defined(MAGICKCORE_BUILD_MODULES)
951 {
952 MagickBooleanType
953 status;
954
955 status=InvokeStaticImageFilter(tag,images,argc,argv,exception);
956 if (status != MagickFalse)
957 return(status);
958 }
959#endif
960 rights=ReadPolicyRights;
961 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
962 {
cristya9197f62010-01-12 02:23:34 +0000963 errno=EPERM;
cristy3ed852e2009-09-05 21:47:34 +0000964 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
cristyefe601c2013-01-05 17:51:12 +0000965 "NotAuthorized","`%s'",tag);
cristy3ed852e2009-09-05 21:47:34 +0000966 return(MagickFalse);
967 }
968 TagToFilterModuleName(tag,name);
cristyd1df72d2010-06-29 02:17:03 +0000969 status=GetMagickModulePath(name,MagickImageFilterModule,path,exception);
970 if (status == MagickFalse)
971 {
972 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +0000973 "UnableToLoadModule","'%s': %s",name,path);
cristyd1df72d2010-06-29 02:17:03 +0000974 return(MagickFalse);
975 }
cristy3ed852e2009-09-05 21:47:34 +0000976 /*
977 Open the module.
978 */
979 handle=(ModuleHandle) lt_dlopen(path);
980 if (handle == (ModuleHandle) NULL)
981 {
982 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +0000983 "UnableToLoadModule","'%s': %s",name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +0000984 return(MagickFalse);
985 }
986 /*
987 Locate the module.
988 */
989#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
cristy151b66d2015-04-15 10:50:31 +0000990 (void) FormatLocaleString(name,MagickPathExtent,"%sImage",tag);
cristy3ed852e2009-09-05 21:47:34 +0000991#else
cristy151b66d2015-04-15 10:50:31 +0000992 (void) FormatLocaleString(name,MagickPathExtent,"%s%sImage",
cristy3ed852e2009-09-05 21:47:34 +0000993 MAGICKCORE_NAMESPACE_PREFIX,tag);
994#endif
995 /*
996 Execute the module.
997 */
cristyfe12d6c2010-05-07 01:38:41 +0000998 ClearMagickException(exception);
cristy3ed852e2009-09-05 21:47:34 +0000999 image_filter=(ImageFilterHandler *) lt_dlsym(handle,name);
1000 if (image_filter == (ImageFilterHandler *) NULL)
1001 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001002 "UnableToLoadModule","'%s': %s",name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001003 else
1004 {
cristybb503372010-05-27 20:51:26 +00001005 size_t
cristy3ed852e2009-09-05 21:47:34 +00001006 signature;
1007
1008 if ((*images)->debug != MagickFalse)
1009 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1010 "Invoking \"%s\" dynamic image filter",tag);
1011 signature=image_filter(images,argc,argv,exception);
1012 if ((*images)->debug != MagickFalse)
1013 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),"\"%s\" completes",
1014 tag);
1015 if (signature != MagickImageFilterSignature)
cristyfe12d6c2010-05-07 01:38:41 +00001016 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001017 "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag,
cristyf1d91242010-05-28 02:23:19 +00001018 (unsigned long) signature,(unsigned long) MagickImageFilterSignature);
cristy3ed852e2009-09-05 21:47:34 +00001019 }
1020 /*
1021 Close the module.
1022 */
1023 if (lt_dlclose(handle) != 0)
cristyfe12d6c2010-05-07 01:38:41 +00001024 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
anthonye5b39652012-04-21 05:37:29 +00001025 "UnableToCloseModule","'%s': %s",name,lt_dlerror());
cristyfe12d6c2010-05-07 01:38:41 +00001026 return(exception->severity < ErrorException ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001027}
1028
1029/*
1030%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1031% %
1032% %
1033% %
1034% L i s t M o d u l e I n f o %
1035% %
1036% %
1037% %
1038%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1039%
1040% ListModuleInfo() lists the module info to a file.
1041%
1042% The format of the ListModuleInfo module is:
1043%
1044% MagickBooleanType ListModuleInfo(FILE *file,ExceptionInfo *exception)
1045%
1046% A description of each parameter follows.
1047%
1048% o file: An pointer to a FILE.
1049%
1050% o exception: return any errors or warnings in this structure.
1051%
1052*/
1053MagickExport MagickBooleanType ListModuleInfo(FILE *file,
1054 ExceptionInfo *exception)
1055{
cristya6de29a2010-06-30 14:34:26 +00001056 char
cristy151b66d2015-04-15 10:50:31 +00001057 filename[MagickPathExtent],
1058 module_path[MagickPathExtent],
cristya6de29a2010-06-30 14:34:26 +00001059 **modules,
cristy151b66d2015-04-15 10:50:31 +00001060 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001061
cristybb503372010-05-27 20:51:26 +00001062 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001063 i;
1064
cristybb503372010-05-27 20:51:26 +00001065 size_t
cristy3ed852e2009-09-05 21:47:34 +00001066 number_modules;
1067
1068 if (file == (const FILE *) NULL)
1069 file=stdout;
cristya6de29a2010-06-30 14:34:26 +00001070 /*
1071 List image coders.
1072 */
1073 modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception);
1074 if (modules == (char **) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001075 return(MagickFalse);
cristya6de29a2010-06-30 14:34:26 +00001076 TagToCoderModuleName("magick",filename);
1077 (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path,
1078 exception);
1079 GetPathComponent(module_path,HeadPath,path);
cristyb51dff52011-05-19 16:55:47 +00001080 (void) FormatLocaleFile(file,"\nPath: %s\n\n",path);
1081 (void) FormatLocaleFile(file,"Image Coder\n");
cristy1e604812011-05-19 18:07:50 +00001082 (void) FormatLocaleFile(file,
1083 "-------------------------------------------------"
cristy3ed852e2009-09-05 21:47:34 +00001084 "------------------------------\n");
cristybb503372010-05-27 20:51:26 +00001085 for (i=0; i < (ssize_t) number_modules; i++)
cristy3ed852e2009-09-05 21:47:34 +00001086 {
cristyb51dff52011-05-19 16:55:47 +00001087 (void) FormatLocaleFile(file,"%s",modules[i]);
1088 (void) FormatLocaleFile(file,"\n");
cristy3ed852e2009-09-05 21:47:34 +00001089 }
1090 (void) fflush(file);
cristya6de29a2010-06-30 14:34:26 +00001091 /*
1092 Relinquish resources.
1093 */
1094 for (i=0; i < (ssize_t) number_modules; i++)
1095 modules[i]=DestroyString(modules[i]);
1096 modules=(char **) RelinquishMagickMemory(modules);
1097 /*
1098 List image filters.
1099 */
1100 modules=GetModuleList("*",MagickImageFilterModule,&number_modules,exception);
1101 if (modules == (char **) NULL)
1102 return(MagickFalse);
1103 TagToFilterModuleName("analyze",filename);
1104 (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path,
1105 exception);
1106 GetPathComponent(module_path,HeadPath,path);
cristyb51dff52011-05-19 16:55:47 +00001107 (void) FormatLocaleFile(file,"\nPath: %s\n\n",path);
1108 (void) FormatLocaleFile(file,"Image Filter\n");
cristy1e604812011-05-19 18:07:50 +00001109 (void) FormatLocaleFile(file,
1110 "-------------------------------------------------"
cristya6de29a2010-06-30 14:34:26 +00001111 "------------------------------\n");
1112 for (i=0; i < (ssize_t) number_modules; i++)
1113 {
cristyb51dff52011-05-19 16:55:47 +00001114 (void) FormatLocaleFile(file,"%s",modules[i]);
1115 (void) FormatLocaleFile(file,"\n");
cristya6de29a2010-06-30 14:34:26 +00001116 }
1117 (void) fflush(file);
1118 /*
1119 Relinquish resources.
1120 */
1121 for (i=0; i < (ssize_t) number_modules; i++)
1122 modules[i]=DestroyString(modules[i]);
1123 modules=(char **) RelinquishMagickMemory(modules);
cristy3ed852e2009-09-05 21:47:34 +00001124 return(MagickTrue);
1125}
1126
1127/*
1128%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1129% %
1130% %
1131% %
cristyf34a1452009-10-24 22:29:27 +00001132+ M o d u l e C o m p o n e n t G e n e s i s %
1133% %
1134% %
1135% %
1136%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1137%
1138% ModuleComponentGenesis() instantiates the module component.
1139%
1140% The format of the ModuleComponentGenesis method is:
1141%
1142% MagickBooleanType ModuleComponentGenesis(void)
1143%
1144*/
cristy5ff4eaf2011-09-03 01:38:02 +00001145MagickPrivate MagickBooleanType ModuleComponentGenesis(void)
cristyf34a1452009-10-24 22:29:27 +00001146{
1147 ExceptionInfo
1148 *exception;
1149
cristycee97112010-05-28 00:44:52 +00001150 MagickBooleanType
1151 status;
1152
cristy7c977062014-04-04 14:05:53 +00001153 if (module_semaphore == (SemaphoreInfo *) NULL)
1154 module_semaphore=AcquireSemaphoreInfo();
cristyf34a1452009-10-24 22:29:27 +00001155 exception=AcquireExceptionInfo();
cristy904e5912014-03-15 19:53:14 +00001156 status=IsModuleTreeInstantiated(exception);
cristyf34a1452009-10-24 22:29:27 +00001157 exception=DestroyExceptionInfo(exception);
cristycee97112010-05-28 00:44:52 +00001158 return(status);
cristyf34a1452009-10-24 22:29:27 +00001159}
1160
1161/*
1162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1163% %
1164% %
1165% %
1166+ M o d u l e C o m p o n e n t T e r m i n u s %
1167% %
1168% %
1169% %
1170%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1171%
1172% ModuleComponentTerminus() destroys the module component.
1173%
1174% The format of the ModuleComponentTerminus method is:
1175%
1176% ModuleComponentTerminus(void)
1177%
1178*/
cristy5ff4eaf2011-09-03 01:38:02 +00001179MagickPrivate void ModuleComponentTerminus(void)
cristyf34a1452009-10-24 22:29:27 +00001180{
cristy18b17442009-10-25 18:36:48 +00001181 if (module_semaphore == (SemaphoreInfo *) NULL)
cristy04b11db2014-02-16 15:10:39 +00001182 ActivateSemaphoreInfo(&module_semaphore);
cristyf34a1452009-10-24 22:29:27 +00001183 DestroyModuleList();
cristy3d162a92014-02-16 14:05:06 +00001184 RelinquishSemaphoreInfo(&module_semaphore);
cristyf34a1452009-10-24 22:29:27 +00001185}
1186
1187/*
1188%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1189% %
1190% %
1191% %
cristy3ed852e2009-09-05 21:47:34 +00001192% O p e n M o d u l e %
1193% %
1194% %
1195% %
1196%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1197%
1198% OpenModule() loads a module, and invokes its registration module. It
1199% returns MagickTrue on success, and MagickFalse if there is an error.
1200%
1201% The format of the OpenModule module is:
1202%
1203% MagickBooleanType OpenModule(const char *module,ExceptionInfo *exception)
1204%
1205% A description of each parameter follows:
1206%
1207% o module: a character string that indicates the module to load.
1208%
1209% o exception: return any errors or warnings in this structure.
1210%
1211*/
cristy7832dc22011-09-05 01:21:53 +00001212MagickPrivate MagickBooleanType OpenModule(const char *module,
cristy3ed852e2009-09-05 21:47:34 +00001213 ExceptionInfo *exception)
1214{
1215 char
cristy151b66d2015-04-15 10:50:31 +00001216 filename[MagickPathExtent],
1217 module_name[MagickPathExtent],
1218 name[MagickPathExtent],
1219 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001220
cristyd1df72d2010-06-29 02:17:03 +00001221 MagickBooleanType
1222 status;
1223
cristy3ed852e2009-09-05 21:47:34 +00001224 ModuleHandle
1225 handle;
1226
1227 ModuleInfo
1228 *module_info;
1229
1230 register const CoderInfo
1231 *p;
1232
1233 size_t
cristy3ed852e2009-09-05 21:47:34 +00001234 signature;
1235
1236 /*
1237 Assign module name from alias.
1238 */
1239 assert(module != (const char *) NULL);
1240 module_info=(ModuleInfo *) GetModuleInfo(module,exception);
1241 if (module_info != (ModuleInfo *) NULL)
1242 return(MagickTrue);
cristy151b66d2015-04-15 10:50:31 +00001243 (void) CopyMagickString(module_name,module,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001244 p=GetCoderInfo(module,exception);
1245 if (p != (CoderInfo *) NULL)
cristy151b66d2015-04-15 10:50:31 +00001246 (void) CopyMagickString(module_name,p->name,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001247 if (GetValueFromSplayTree(module_list,module_name) != (void *) NULL)
1248 return(MagickTrue); /* module already opened, return */
1249 /*
1250 Locate module.
1251 */
1252 handle=(ModuleHandle) NULL;
1253 TagToCoderModuleName(module_name,filename);
1254 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1255 "Searching for module \"%s\" using filename \"%s\"",module_name,filename);
1256 *path='\0';
cristyd1df72d2010-06-29 02:17:03 +00001257 status=GetMagickModulePath(filename,MagickImageCoderModule,path,exception);
1258 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001259 return(MagickFalse);
1260 /*
1261 Load module
1262 */
1263 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1264 "Opening module at path \"%s\"",path);
1265 handle=(ModuleHandle) lt_dlopen(path);
1266 if (handle == (ModuleHandle) NULL)
1267 {
1268 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001269 "UnableToLoadModule","'%s': %s",path,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001270 return(MagickFalse);
1271 }
1272 /*
1273 Register module.
1274 */
1275 module_info=AcquireModuleInfo(path,module_name);
1276 module_info->handle=handle;
1277 if (RegisterModule(module_info,exception) == (ModuleInfo *) NULL)
1278 return(MagickFalse);
1279 /*
1280 Define RegisterFORMATImage method.
1281 */
1282 TagToModuleName(module_name,"Register%sImage",name);
cristybb503372010-05-27 20:51:26 +00001283 module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name);
1284 if (module_info->register_module == (size_t (*)(void)) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001285 {
1286 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001287 "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001288 return(MagickFalse);
1289 }
1290 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1291 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1292 (void *) module_info->register_module);
1293 /*
1294 Define UnregisterFORMATImage method.
1295 */
1296 TagToModuleName(module_name,"Unregister%sImage",name);
1297 module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name);
1298 if (module_info->unregister_module == (void (*)(void)) NULL)
1299 {
1300 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001301 "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001302 return(MagickFalse);
1303 }
1304 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1305 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1306 (void *) module_info->unregister_module);
1307 signature=module_info->register_module();
1308 if (signature != MagickImageCoderSignature)
1309 {
1310 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001311 "ImageCoderSignatureMismatch","'%s': %8lx != %8lx",module_name,
cristyf1d91242010-05-28 02:23:19 +00001312 (unsigned long) signature,(unsigned long) MagickImageCoderSignature);
cristy3ed852e2009-09-05 21:47:34 +00001313 return(MagickFalse);
1314 }
1315 return(MagickTrue);
1316}
1317
1318/*
1319%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1320% %
1321% %
1322% %
1323% O p e n M o d u l e s %
1324% %
1325% %
1326% %
1327%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1328%
1329% OpenModules() loads all available modules.
1330%
1331% The format of the OpenModules module is:
1332%
1333% MagickBooleanType OpenModules(ExceptionInfo *exception)
1334%
1335% A description of each parameter follows:
1336%
1337% o exception: return any errors or warnings in this structure.
1338%
1339*/
cristy7832dc22011-09-05 01:21:53 +00001340MagickPrivate MagickBooleanType OpenModules(ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001341{
1342 char
1343 **modules;
1344
cristybb503372010-05-27 20:51:26 +00001345 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001346 i;
1347
cristybb503372010-05-27 20:51:26 +00001348 size_t
cristy3ed852e2009-09-05 21:47:34 +00001349 number_modules;
1350
1351 /*
1352 Load all modules.
1353 */
1354 (void) GetMagickInfo((char *) NULL,exception);
1355 number_modules=0;
cristya6de29a2010-06-30 14:34:26 +00001356 modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception);
cristy3ed852e2009-09-05 21:47:34 +00001357 if (modules == (char **) NULL)
1358 return(MagickFalse);
cristybb503372010-05-27 20:51:26 +00001359 for (i=0; i < (ssize_t) number_modules; i++)
cristy3ed852e2009-09-05 21:47:34 +00001360 (void) OpenModule(modules[i],exception);
1361 /*
1362 Relinquish resources.
1363 */
cristybb503372010-05-27 20:51:26 +00001364 for (i=0; i < (ssize_t) number_modules; i++)
cristy3ed852e2009-09-05 21:47:34 +00001365 modules[i]=DestroyString(modules[i]);
1366 modules=(char **) RelinquishMagickMemory(modules);
1367 return(MagickTrue);
1368}
1369
1370/*
1371%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1372% %
1373% %
1374% %
1375% R e g i s t e r M o d u l e %
1376% %
1377% %
1378% %
1379%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1380%
1381% RegisterModule() adds an entry to the module list. It returns a pointer to
1382% the registered entry on success.
1383%
1384% The format of the RegisterModule module is:
1385%
1386% ModuleInfo *RegisterModule(const ModuleInfo *module_info,
1387% ExceptionInfo *exception)
1388%
1389% A description of each parameter follows:
1390%
1391% o info: a pointer to the registered entry is returned.
1392%
1393% o module_info: a pointer to the ModuleInfo structure to register.
1394%
1395% o exception: return any errors or warnings in this structure.
1396%
1397*/
1398static const ModuleInfo *RegisterModule(const ModuleInfo *module_info,
1399 ExceptionInfo *exception)
1400{
1401 MagickBooleanType
1402 status;
1403
1404 assert(module_info != (ModuleInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001405 assert(module_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001406 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag);
1407 if (module_list == (SplayTreeInfo *) NULL)
1408 return((const ModuleInfo *) NULL);
1409 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
1410 if (status == MagickFalse)
1411 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
cristyefe601c2013-01-05 17:51:12 +00001412 "MemoryAllocationFailed","`%s'",module_info->tag);
cristy3ed852e2009-09-05 21:47:34 +00001413 return(module_info);
1414}
1415
1416/*
1417%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1418% %
1419% %
1420% %
1421% T a g T o C o d e r M o d u l e N a m e %
1422% %
1423% %
1424% %
1425%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1426%
1427% TagToCoderModuleName() munges a module tag and obtains the filename of the
1428% corresponding module.
1429%
1430% The format of the TagToCoderModuleName module is:
1431%
1432% char *TagToCoderModuleName(const char *tag,char *name)
1433%
1434% A description of each parameter follows:
1435%
1436% o tag: a character string representing the module tag.
1437%
1438% o name: return the module name here.
1439%
1440*/
1441static void TagToCoderModuleName(const char *tag,char *name)
1442{
1443 assert(tag != (char *) NULL);
1444 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag);
1445 assert(name != (char *) NULL);
1446#if defined(MAGICKCORE_LTDL_DELEGATE)
cristy151b66d2015-04-15 10:50:31 +00001447 (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag);
cristy3ed852e2009-09-05 21:47:34 +00001448 (void) LocaleLower(name);
1449#else
cristy0157aea2010-04-24 21:12:18 +00001450#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00001451 if (LocaleNCompare("IM_MOD_",tag,7) == 0)
cristy151b66d2015-04-15 10:50:31 +00001452 (void) CopyMagickString(name,tag,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001453 else
1454 {
1455#if defined(_DEBUG)
cristy151b66d2015-04-15 10:50:31 +00001456 (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_DB_%s_.dll",tag);
cristy3ed852e2009-09-05 21:47:34 +00001457#else
cristy151b66d2015-04-15 10:50:31 +00001458 (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_RL_%s_.dll",tag);
cristy3ed852e2009-09-05 21:47:34 +00001459#endif
1460 }
1461#endif
1462#endif
1463}
1464
1465/*
1466%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1467% %
1468% %
1469% %
1470% T a g T o F i l t e r M o d u l e N a m e %
1471% %
1472% %
1473% %
1474%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1475%
1476% TagToFilterModuleName() munges a module tag and returns the filename of the
1477% corresponding filter module.
1478%
1479% The format of the TagToFilterModuleName module is:
1480%
1481% void TagToFilterModuleName(const char *tag,char name)
1482%
1483% A description of each parameter follows:
1484%
1485% o tag: a character string representing the module tag.
1486%
1487% o name: return the filter name here.
1488%
1489*/
1490static void TagToFilterModuleName(const char *tag,char *name)
1491{
1492 assert(tag != (char *) NULL);
1493 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag);
1494 assert(name != (char *) NULL);
dirk89fad7c2015-01-17 22:09:51 +00001495#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy151b66d2015-04-15 10:50:31 +00001496 (void) FormatLocaleString(name,MagickPathExtent,"FILTER_%s_.dll",tag);
dirk89fad7c2015-01-17 22:09:51 +00001497#elif !defined(MAGICKCORE_LTDL_DELEGATE)
cristy151b66d2015-04-15 10:50:31 +00001498 (void) FormatLocaleString(name,MagickPathExtent,"%s.dll",tag);
cristy3ed852e2009-09-05 21:47:34 +00001499#else
cristy151b66d2015-04-15 10:50:31 +00001500 (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag);
cristy3ed852e2009-09-05 21:47:34 +00001501#endif
1502}
1503
1504/*
1505%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1506% %
1507% %
1508% %
1509% T a g T o M o d u l e N a m e %
1510% %
1511% %
1512% %
1513%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1514%
1515% TagToModuleName() munges the module tag name and returns an upper-case tag
1516% name as the input string, and a user-provided format.
1517%
1518% The format of the TagToModuleName module is:
1519%
1520% TagToModuleName(const char *tag,const char *format,char *module)
1521%
1522% A description of each parameter follows:
1523%
1524% o tag: the module tag.
1525%
1526% o format: a sprintf-compatible format string containing %s where the
1527% upper-case tag name is to be inserted.
1528%
1529% o module: pointer to a destination buffer for the formatted result.
1530%
1531*/
1532static void TagToModuleName(const char *tag,const char *format,char *module)
1533{
1534 char
cristy151b66d2015-04-15 10:50:31 +00001535 name[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001536
1537 assert(tag != (const char *) NULL);
1538 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag);
1539 assert(format != (const char *) NULL);
1540 assert(module != (char *) NULL);
cristy151b66d2015-04-15 10:50:31 +00001541 (void) CopyMagickString(name,tag,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001542 LocaleUpper(name);
1543#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
cristy151b66d2015-04-15 10:50:31 +00001544 (void) FormatLocaleString(module,MagickPathExtent,format,name);
cristy3ed852e2009-09-05 21:47:34 +00001545#else
1546 {
1547 char
cristy151b66d2015-04-15 10:50:31 +00001548 prefix_format[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001549
cristy151b66d2015-04-15 10:50:31 +00001550 (void) FormatLocaleString(prefix_format,MagickPathExtent,"%s%s",
cristy3ed852e2009-09-05 21:47:34 +00001551 MAGICKCORE_NAMESPACE_PREFIX,format);
cristy151b66d2015-04-15 10:50:31 +00001552 (void) FormatLocaleString(module,MagickPathExtent,prefix_format,name);
cristy3ed852e2009-09-05 21:47:34 +00001553 }
1554#endif
1555}
1556
1557/*
1558%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1559% %
1560% %
1561% %
1562% U n r e g i s t e r M o d u l e %
1563% %
1564% %
1565% %
1566%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1567%
1568% UnregisterModule() unloads a module, and invokes its de-registration module.
1569% Returns MagickTrue on success, and MagickFalse if there is an error.
1570%
1571% The format of the UnregisterModule module is:
1572%
1573% MagickBooleanType UnregisterModule(const ModuleInfo *module_info,
1574% ExceptionInfo *exception)
1575%
1576% A description of each parameter follows:
1577%
1578% o module_info: the module info.
1579%
1580% o exception: return any errors or warnings in this structure.
1581%
1582*/
1583static MagickBooleanType UnregisterModule(const ModuleInfo *module_info,
1584 ExceptionInfo *exception)
1585{
1586 /*
1587 Locate and execute UnregisterFORMATImage module.
1588 */
1589 assert(module_info != (const ModuleInfo *) NULL);
1590 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag);
1591 assert(exception != (ExceptionInfo *) NULL);
1592 if (module_info->unregister_module == NULL)
1593 return(MagickTrue);
1594 module_info->unregister_module();
1595 if (lt_dlclose((ModuleHandle) module_info->handle) != 0)
1596 {
1597 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
anthonye5b39652012-04-21 05:37:29 +00001598 "UnableToCloseModule","'%s': %s",module_info->tag,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001599 return(MagickFalse);
1600 }
1601 return(MagickTrue);
1602}
1603#else
dirk143157c2014-03-01 10:16:38 +00001604
1605#if !defined(MAGICKCORE_BUILD_MODULES)
1606extern size_t
1607 analyzeImage(Image **,const int,const char **,ExceptionInfo *);
1608#endif
1609
cristy3ed852e2009-09-05 21:47:34 +00001610MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file),
1611 ExceptionInfo *magick_unused(exception))
1612{
1613 return(MagickTrue);
1614}
1615
1616MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
1617 Image **image,const int argc,const char **argv,ExceptionInfo *exception)
1618{
cristya6de29a2010-06-30 14:34:26 +00001619 PolicyRights
1620 rights;
1621
1622 assert(image != (Image **) NULL);
cristye1c94d92015-06-28 12:16:33 +00001623 assert((*image)->signature == MagickCoreSignature);
cristya6de29a2010-06-30 14:34:26 +00001624 if ((*image)->debug != MagickFalse)
1625 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1626 rights=ReadPolicyRights;
1627 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
1628 {
1629 errno=EPERM;
1630 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
cristyefe601c2013-01-05 17:51:12 +00001631 "NotAuthorized","`%s'",tag);
cristya6de29a2010-06-30 14:34:26 +00001632 return(MagickFalse);
1633 }
1634#if defined(MAGICKCORE_BUILD_MODULES)
1635 (void) tag;
1636 (void) argc;
1637 (void) argv;
1638 (void) exception;
1639#else
cristy3ed852e2009-09-05 21:47:34 +00001640 {
cristy3ed852e2009-09-05 21:47:34 +00001641 ImageFilterHandler
1642 *image_filter;
1643
1644 image_filter=(ImageFilterHandler *) NULL;
1645 if (LocaleCompare("analyze",tag) == 0)
cristya6de29a2010-06-30 14:34:26 +00001646 image_filter=(ImageFilterHandler *) analyzeImage;
1647 if (image_filter == (ImageFilterHandler *) NULL)
1648 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
cristyefe601c2013-01-05 17:51:12 +00001649 "UnableToLoadModule","`%s'",tag);
cristya6de29a2010-06-30 14:34:26 +00001650 else
cristy3ed852e2009-09-05 21:47:34 +00001651 {
cristybb503372010-05-27 20:51:26 +00001652 size_t
cristy3ed852e2009-09-05 21:47:34 +00001653 signature;
1654
cristya6de29a2010-06-30 14:34:26 +00001655 if ((*image)->debug != MagickFalse)
1656 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1657 "Invoking \"%s\" static image filter",tag);
cristy3ed852e2009-09-05 21:47:34 +00001658 signature=image_filter(image,argc,argv,exception);
cristya6de29a2010-06-30 14:34:26 +00001659 if ((*image)->debug != MagickFalse)
1660 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"\"%s\" completes",
1661 tag);
cristy3ed852e2009-09-05 21:47:34 +00001662 if (signature != MagickImageFilterSignature)
1663 {
1664 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001665 "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag,
cristya6de29a2010-06-30 14:34:26 +00001666 (unsigned long) signature,(unsigned long)
cristy3ed852e2009-09-05 21:47:34 +00001667 MagickImageFilterSignature);
1668 return(MagickFalse);
1669 }
1670 }
1671 }
1672#endif
1673 return(MagickTrue);
1674}
1675#endif