blob: b253bd10c32841aae29efe8d131d00f6546414d9 [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% %
Cristy7ce65e72015-12-12 18:03:16 -050020% Copyright 1999-2016 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 {
Cristy9799a842015-10-04 19:44:36 -0400771 (void) ConcatenateMagickString(path,DirectorySeparator,
772 MagickPathExtent);
cristy151b66d2015-04-15 10:50:31 +0000773 (void) ConcatenateMagickString(path,filename,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +0000774 if (IsPathAccessible(path) != MagickFalse)
775 return(MagickTrue);
776 }
777 }
778#endif
779 {
780 char
781 *home;
782
Cristy9799a842015-10-04 19:44:36 -0400783 home=GetEnvironmentValue("XDG_CONFIG_HOME");
Cristy1dd96da2015-10-06 07:52:01 -0400784 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");
Cristy9799a842015-10-04 19:44:36 -0400790 if (home != (char *) NULL)
Cristy1dd96da2015-10-06 07:52:01 -0400791 {
Cristy9799a842015-10-04 19:44:36 -0400792 /*
793 Search $XDG_CONFIG_HOME/ImageMagick.
794 */
795 (void) FormatLocaleString(path,MaxTextExtent,"%s%sImageMagick%s%s",
796 home,DirectorySeparator,DirectorySeparator,filename);
797 home=DestroyString(home);
798 if (IsPathAccessible(path) != MagickFalse)
799 return(MagickTrue);
800 }
cristy3ed852e2009-09-05 21:47:34 +0000801 home=GetEnvironmentValue("HOME");
cristy3ed852e2009-09-05 21:47:34 +0000802 if (home != (char *) NULL)
803 {
804 /*
cristy9f3b4fc2014-02-08 14:56:20 +0000805 Search $HOME/.config/ImageMagick.
cristy3ed852e2009-09-05 21:47:34 +0000806 */
cristy151b66d2015-04-15 10:50:31 +0000807 (void) FormatLocaleString(path,MagickPathExtent,
cristy9f3b4fc2014-02-08 14:56:20 +0000808 "%s%s.config%sImageMagick%s%s",home,DirectorySeparator,
cristy3ed852e2009-09-05 21:47:34 +0000809 DirectorySeparator,DirectorySeparator,filename);
810 home=DestroyString(home);
811 if (IsPathAccessible(path) != MagickFalse)
812 return(MagickTrue);
813 }
814 }
815 /*
816 Search current directory.
817 */
818 if (IsPathAccessible(path) != MagickFalse)
819 return(MagickTrue);
820 if (exception->severity < ConfigureError)
821 ThrowFileException(exception,ConfigureWarning,"UnableToOpenModuleFile",
822 path);
cristy3ed852e2009-09-05 21:47:34 +0000823#endif
824 return(MagickFalse);
825}
826
827/*
828%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
829% %
830% %
831% %
cristy904e5912014-03-15 19:53:14 +0000832% 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 +0000833% %
834% %
835% %
836%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
837%
cristy904e5912014-03-15 19:53:14 +0000838% IsModuleTreeInstantiated() determines if the module tree is instantiated.
839% If not, it instantiates the tree and returns it.
cristy3ed852e2009-09-05 21:47:34 +0000840%
cristy904e5912014-03-15 19:53:14 +0000841% The format of the IsModuleTreeInstantiated() method is:
cristy3ed852e2009-09-05 21:47:34 +0000842%
cristy904e5912014-03-15 19:53:14 +0000843% IsModuleTreeInstantiated(Exceptioninfo *exception)
cristy3ed852e2009-09-05 21:47:34 +0000844%
845% A description of each parameter follows.
846%
847% o exception: return any errors or warnings in this structure.
848%
849*/
850
851static void *DestroyModuleNode(void *module_info)
852{
853 ExceptionInfo
854 *exception;
855
856 register ModuleInfo
857 *p;
858
859 exception=AcquireExceptionInfo();
860 p=(ModuleInfo *) module_info;
861 if (UnregisterModule(p,exception) == MagickFalse)
862 CatchException(exception);
863 if (p->tag != (char *) NULL)
864 p->tag=DestroyString(p->tag);
865 if (p->path != (char *) NULL)
866 p->path=DestroyString(p->path);
867 exception=DestroyExceptionInfo(exception);
868 return(RelinquishMagickMemory(p));
869}
870
cristy904e5912014-03-15 19:53:14 +0000871static MagickBooleanType IsModuleTreeInstantiated(
cristy3ed852e2009-09-05 21:47:34 +0000872 ExceptionInfo *magick_unused(exception))
873{
cristy1460f262014-03-15 17:38:05 +0000874 if (module_list == (SplayTreeInfo *) NULL)
cristy3ed852e2009-09-05 21:47:34 +0000875 {
cristy86e5ac92014-03-16 19:27:39 +0000876 if (module_semaphore == (SemaphoreInfo *) NULL)
877 ActivateSemaphoreInfo(&module_semaphore);
878 LockSemaphoreInfo(module_semaphore);
cristy1460f262014-03-15 17:38:05 +0000879 if (module_list == (SplayTreeInfo *) NULL)
cristy86e5ac92014-03-16 19:27:39 +0000880 {
881 MagickBooleanType
882 status;
883
884 ModuleInfo
885 *module_info;
886
887 module_list=NewSplayTree(CompareSplayTreeString,
888 (void *(*)(void *)) NULL,DestroyModuleNode);
889 if (module_list == (SplayTreeInfo *) NULL)
890 ThrowFatalException(ResourceLimitFatalError,
891 "MemoryAllocationFailed");
892 module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]");
893 module_info->stealth=MagickTrue;
894 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
895 if (status == MagickFalse)
896 ThrowFatalException(ResourceLimitFatalError,
897 "MemoryAllocationFailed");
898 if (lt_dlinit() != 0)
899 ThrowFatalException(ModuleFatalError,
900 "UnableToInitializeModuleLoader");
901 }
902 UnlockSemaphoreInfo(module_semaphore);
cristy3ed852e2009-09-05 21:47:34 +0000903 }
904 return(module_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse);
905}
906
907/*
908%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
909% %
910% %
911% %
cristy3ed852e2009-09-05 21:47:34 +0000912% I n v o k e D y n a m i c I m a g e F i l t e r %
913% %
914% %
915% %
916%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
917%
918% InvokeDynamicImageFilter() invokes a dynamic image filter.
919%
920% The format of the InvokeDynamicImageFilter module is:
921%
922% MagickBooleanType InvokeDynamicImageFilter(const char *tag,Image **image,
923% const int argc,const char **argv,ExceptionInfo *exception)
924%
925% A description of each parameter follows:
926%
927% o tag: a character string that represents the name of the particular
928% module.
929%
930% o image: the image.
931%
932% o argc: a pointer to an integer describing the number of elements in the
933% argument vector.
934%
935% o argv: a pointer to a text array containing the command line arguments.
936%
937% o exception: return any errors or warnings in this structure.
938%
939*/
940MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
941 Image **images,const int argc,const char **argv,ExceptionInfo *exception)
942{
943 char
cristy151b66d2015-04-15 10:50:31 +0000944 name[MagickPathExtent],
945 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +0000946
947 ImageFilterHandler
948 *image_filter;
949
cristyd1df72d2010-06-29 02:17:03 +0000950 MagickBooleanType
951 status;
952
cristy3ed852e2009-09-05 21:47:34 +0000953 ModuleHandle
954 handle;
955
956 PolicyRights
957 rights;
958
cristy3ed852e2009-09-05 21:47:34 +0000959 /*
960 Find the module.
961 */
962 assert(images != (Image **) NULL);
cristye1c94d92015-06-28 12:16:33 +0000963 assert((*images)->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +0000964 if ((*images)->debug != MagickFalse)
965 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",
966 (*images)->filename);
967#if !defined(MAGICKCORE_BUILD_MODULES)
968 {
969 MagickBooleanType
970 status;
971
972 status=InvokeStaticImageFilter(tag,images,argc,argv,exception);
973 if (status != MagickFalse)
974 return(status);
975 }
976#endif
977 rights=ReadPolicyRights;
978 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
979 {
cristya9197f62010-01-12 02:23:34 +0000980 errno=EPERM;
cristy3ed852e2009-09-05 21:47:34 +0000981 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
cristyefe601c2013-01-05 17:51:12 +0000982 "NotAuthorized","`%s'",tag);
cristy3ed852e2009-09-05 21:47:34 +0000983 return(MagickFalse);
984 }
985 TagToFilterModuleName(tag,name);
cristyd1df72d2010-06-29 02:17:03 +0000986 status=GetMagickModulePath(name,MagickImageFilterModule,path,exception);
987 if (status == MagickFalse)
988 {
989 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +0000990 "UnableToLoadModule","'%s': %s",name,path);
cristyd1df72d2010-06-29 02:17:03 +0000991 return(MagickFalse);
992 }
cristy3ed852e2009-09-05 21:47:34 +0000993 /*
994 Open the module.
995 */
996 handle=(ModuleHandle) lt_dlopen(path);
997 if (handle == (ModuleHandle) NULL)
998 {
999 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001000 "UnableToLoadModule","'%s': %s",name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001001 return(MagickFalse);
1002 }
1003 /*
1004 Locate the module.
1005 */
1006#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
cristy151b66d2015-04-15 10:50:31 +00001007 (void) FormatLocaleString(name,MagickPathExtent,"%sImage",tag);
cristy3ed852e2009-09-05 21:47:34 +00001008#else
cristy151b66d2015-04-15 10:50:31 +00001009 (void) FormatLocaleString(name,MagickPathExtent,"%s%sImage",
cristy3ed852e2009-09-05 21:47:34 +00001010 MAGICKCORE_NAMESPACE_PREFIX,tag);
1011#endif
1012 /*
1013 Execute the module.
1014 */
cristyfe12d6c2010-05-07 01:38:41 +00001015 ClearMagickException(exception);
cristy3ed852e2009-09-05 21:47:34 +00001016 image_filter=(ImageFilterHandler *) lt_dlsym(handle,name);
1017 if (image_filter == (ImageFilterHandler *) NULL)
1018 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001019 "UnableToLoadModule","'%s': %s",name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001020 else
1021 {
cristybb503372010-05-27 20:51:26 +00001022 size_t
cristy3ed852e2009-09-05 21:47:34 +00001023 signature;
1024
1025 if ((*images)->debug != MagickFalse)
1026 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1027 "Invoking \"%s\" dynamic image filter",tag);
1028 signature=image_filter(images,argc,argv,exception);
1029 if ((*images)->debug != MagickFalse)
1030 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),"\"%s\" completes",
1031 tag);
1032 if (signature != MagickImageFilterSignature)
cristyfe12d6c2010-05-07 01:38:41 +00001033 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001034 "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag,
cristyf1d91242010-05-28 02:23:19 +00001035 (unsigned long) signature,(unsigned long) MagickImageFilterSignature);
cristy3ed852e2009-09-05 21:47:34 +00001036 }
1037 /*
1038 Close the module.
1039 */
1040 if (lt_dlclose(handle) != 0)
cristyfe12d6c2010-05-07 01:38:41 +00001041 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
anthonye5b39652012-04-21 05:37:29 +00001042 "UnableToCloseModule","'%s': %s",name,lt_dlerror());
cristyfe12d6c2010-05-07 01:38:41 +00001043 return(exception->severity < ErrorException ? MagickTrue : MagickFalse);
cristy3ed852e2009-09-05 21:47:34 +00001044}
1045
1046/*
1047%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1048% %
1049% %
1050% %
1051% L i s t M o d u l e I n f o %
1052% %
1053% %
1054% %
1055%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1056%
1057% ListModuleInfo() lists the module info to a file.
1058%
1059% The format of the ListModuleInfo module is:
1060%
1061% MagickBooleanType ListModuleInfo(FILE *file,ExceptionInfo *exception)
1062%
1063% A description of each parameter follows.
1064%
1065% o file: An pointer to a FILE.
1066%
1067% o exception: return any errors or warnings in this structure.
1068%
1069*/
1070MagickExport MagickBooleanType ListModuleInfo(FILE *file,
1071 ExceptionInfo *exception)
1072{
cristya6de29a2010-06-30 14:34:26 +00001073 char
cristy151b66d2015-04-15 10:50:31 +00001074 filename[MagickPathExtent],
1075 module_path[MagickPathExtent],
cristya6de29a2010-06-30 14:34:26 +00001076 **modules,
cristy151b66d2015-04-15 10:50:31 +00001077 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001078
cristybb503372010-05-27 20:51:26 +00001079 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001080 i;
1081
cristybb503372010-05-27 20:51:26 +00001082 size_t
cristy3ed852e2009-09-05 21:47:34 +00001083 number_modules;
1084
1085 if (file == (const FILE *) NULL)
1086 file=stdout;
cristya6de29a2010-06-30 14:34:26 +00001087 /*
1088 List image coders.
1089 */
1090 modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception);
1091 if (modules == (char **) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001092 return(MagickFalse);
cristya6de29a2010-06-30 14:34:26 +00001093 TagToCoderModuleName("magick",filename);
1094 (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path,
1095 exception);
1096 GetPathComponent(module_path,HeadPath,path);
cristyb51dff52011-05-19 16:55:47 +00001097 (void) FormatLocaleFile(file,"\nPath: %s\n\n",path);
1098 (void) FormatLocaleFile(file,"Image Coder\n");
cristy1e604812011-05-19 18:07:50 +00001099 (void) FormatLocaleFile(file,
1100 "-------------------------------------------------"
cristy3ed852e2009-09-05 21:47:34 +00001101 "------------------------------\n");
cristybb503372010-05-27 20:51:26 +00001102 for (i=0; i < (ssize_t) number_modules; i++)
cristy3ed852e2009-09-05 21:47:34 +00001103 {
cristyb51dff52011-05-19 16:55:47 +00001104 (void) FormatLocaleFile(file,"%s",modules[i]);
1105 (void) FormatLocaleFile(file,"\n");
cristy3ed852e2009-09-05 21:47:34 +00001106 }
1107 (void) fflush(file);
cristya6de29a2010-06-30 14:34:26 +00001108 /*
1109 Relinquish resources.
1110 */
1111 for (i=0; i < (ssize_t) number_modules; i++)
1112 modules[i]=DestroyString(modules[i]);
1113 modules=(char **) RelinquishMagickMemory(modules);
1114 /*
1115 List image filters.
1116 */
1117 modules=GetModuleList("*",MagickImageFilterModule,&number_modules,exception);
1118 if (modules == (char **) NULL)
1119 return(MagickFalse);
1120 TagToFilterModuleName("analyze",filename);
1121 (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path,
1122 exception);
1123 GetPathComponent(module_path,HeadPath,path);
cristyb51dff52011-05-19 16:55:47 +00001124 (void) FormatLocaleFile(file,"\nPath: %s\n\n",path);
1125 (void) FormatLocaleFile(file,"Image Filter\n");
cristy1e604812011-05-19 18:07:50 +00001126 (void) FormatLocaleFile(file,
1127 "-------------------------------------------------"
cristya6de29a2010-06-30 14:34:26 +00001128 "------------------------------\n");
1129 for (i=0; i < (ssize_t) number_modules; i++)
1130 {
cristyb51dff52011-05-19 16:55:47 +00001131 (void) FormatLocaleFile(file,"%s",modules[i]);
1132 (void) FormatLocaleFile(file,"\n");
cristya6de29a2010-06-30 14:34:26 +00001133 }
1134 (void) fflush(file);
1135 /*
1136 Relinquish resources.
1137 */
1138 for (i=0; i < (ssize_t) number_modules; i++)
1139 modules[i]=DestroyString(modules[i]);
1140 modules=(char **) RelinquishMagickMemory(modules);
cristy3ed852e2009-09-05 21:47:34 +00001141 return(MagickTrue);
1142}
1143
1144/*
1145%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1146% %
1147% %
1148% %
cristyf34a1452009-10-24 22:29:27 +00001149+ M o d u l e C o m p o n e n t G e n e s i s %
1150% %
1151% %
1152% %
1153%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1154%
1155% ModuleComponentGenesis() instantiates the module component.
1156%
1157% The format of the ModuleComponentGenesis method is:
1158%
1159% MagickBooleanType ModuleComponentGenesis(void)
1160%
1161*/
cristy5ff4eaf2011-09-03 01:38:02 +00001162MagickPrivate MagickBooleanType ModuleComponentGenesis(void)
cristyf34a1452009-10-24 22:29:27 +00001163{
1164 ExceptionInfo
1165 *exception;
1166
cristycee97112010-05-28 00:44:52 +00001167 MagickBooleanType
1168 status;
1169
cristy7c977062014-04-04 14:05:53 +00001170 if (module_semaphore == (SemaphoreInfo *) NULL)
1171 module_semaphore=AcquireSemaphoreInfo();
cristyf34a1452009-10-24 22:29:27 +00001172 exception=AcquireExceptionInfo();
cristy904e5912014-03-15 19:53:14 +00001173 status=IsModuleTreeInstantiated(exception);
cristyf34a1452009-10-24 22:29:27 +00001174 exception=DestroyExceptionInfo(exception);
cristycee97112010-05-28 00:44:52 +00001175 return(status);
cristyf34a1452009-10-24 22:29:27 +00001176}
1177
1178/*
1179%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1180% %
1181% %
1182% %
1183+ M o d u l e C o m p o n e n t T e r m i n u s %
1184% %
1185% %
1186% %
1187%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1188%
1189% ModuleComponentTerminus() destroys the module component.
1190%
1191% The format of the ModuleComponentTerminus method is:
1192%
1193% ModuleComponentTerminus(void)
1194%
1195*/
cristy5ff4eaf2011-09-03 01:38:02 +00001196MagickPrivate void ModuleComponentTerminus(void)
cristyf34a1452009-10-24 22:29:27 +00001197{
cristy18b17442009-10-25 18:36:48 +00001198 if (module_semaphore == (SemaphoreInfo *) NULL)
cristy04b11db2014-02-16 15:10:39 +00001199 ActivateSemaphoreInfo(&module_semaphore);
cristyf34a1452009-10-24 22:29:27 +00001200 DestroyModuleList();
cristy3d162a92014-02-16 14:05:06 +00001201 RelinquishSemaphoreInfo(&module_semaphore);
cristyf34a1452009-10-24 22:29:27 +00001202}
1203
1204/*
1205%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1206% %
1207% %
1208% %
cristy3ed852e2009-09-05 21:47:34 +00001209% O p e n M o d u l e %
1210% %
1211% %
1212% %
1213%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1214%
1215% OpenModule() loads a module, and invokes its registration module. It
1216% returns MagickTrue on success, and MagickFalse if there is an error.
1217%
1218% The format of the OpenModule module is:
1219%
1220% MagickBooleanType OpenModule(const char *module,ExceptionInfo *exception)
1221%
1222% A description of each parameter follows:
1223%
1224% o module: a character string that indicates the module to load.
1225%
1226% o exception: return any errors or warnings in this structure.
1227%
1228*/
cristy7832dc22011-09-05 01:21:53 +00001229MagickPrivate MagickBooleanType OpenModule(const char *module,
cristy3ed852e2009-09-05 21:47:34 +00001230 ExceptionInfo *exception)
1231{
1232 char
cristy151b66d2015-04-15 10:50:31 +00001233 filename[MagickPathExtent],
1234 module_name[MagickPathExtent],
1235 name[MagickPathExtent],
1236 path[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001237
cristyd1df72d2010-06-29 02:17:03 +00001238 MagickBooleanType
1239 status;
1240
cristy3ed852e2009-09-05 21:47:34 +00001241 ModuleHandle
1242 handle;
1243
1244 ModuleInfo
1245 *module_info;
1246
1247 register const CoderInfo
1248 *p;
1249
1250 size_t
cristy3ed852e2009-09-05 21:47:34 +00001251 signature;
1252
1253 /*
1254 Assign module name from alias.
1255 */
1256 assert(module != (const char *) NULL);
1257 module_info=(ModuleInfo *) GetModuleInfo(module,exception);
1258 if (module_info != (ModuleInfo *) NULL)
1259 return(MagickTrue);
cristy151b66d2015-04-15 10:50:31 +00001260 (void) CopyMagickString(module_name,module,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001261 p=GetCoderInfo(module,exception);
1262 if (p != (CoderInfo *) NULL)
cristy151b66d2015-04-15 10:50:31 +00001263 (void) CopyMagickString(module_name,p->name,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001264 if (GetValueFromSplayTree(module_list,module_name) != (void *) NULL)
1265 return(MagickTrue); /* module already opened, return */
1266 /*
1267 Locate module.
1268 */
1269 handle=(ModuleHandle) NULL;
1270 TagToCoderModuleName(module_name,filename);
1271 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1272 "Searching for module \"%s\" using filename \"%s\"",module_name,filename);
1273 *path='\0';
cristyd1df72d2010-06-29 02:17:03 +00001274 status=GetMagickModulePath(filename,MagickImageCoderModule,path,exception);
1275 if (status == MagickFalse)
cristy3ed852e2009-09-05 21:47:34 +00001276 return(MagickFalse);
1277 /*
1278 Load module
1279 */
1280 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1281 "Opening module at path \"%s\"",path);
1282 handle=(ModuleHandle) lt_dlopen(path);
1283 if (handle == (ModuleHandle) NULL)
1284 {
1285 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001286 "UnableToLoadModule","'%s': %s",path,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001287 return(MagickFalse);
1288 }
1289 /*
1290 Register module.
1291 */
1292 module_info=AcquireModuleInfo(path,module_name);
1293 module_info->handle=handle;
1294 if (RegisterModule(module_info,exception) == (ModuleInfo *) NULL)
1295 return(MagickFalse);
1296 /*
1297 Define RegisterFORMATImage method.
1298 */
1299 TagToModuleName(module_name,"Register%sImage",name);
cristybb503372010-05-27 20:51:26 +00001300 module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name);
1301 if (module_info->register_module == (size_t (*)(void)) NULL)
cristy3ed852e2009-09-05 21:47:34 +00001302 {
1303 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001304 "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001305 return(MagickFalse);
1306 }
1307 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1308 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1309 (void *) module_info->register_module);
1310 /*
1311 Define UnregisterFORMATImage method.
1312 */
1313 TagToModuleName(module_name,"Unregister%sImage",name);
1314 module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name);
1315 if (module_info->unregister_module == (void (*)(void)) NULL)
1316 {
1317 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001318 "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001319 return(MagickFalse);
1320 }
1321 (void) LogMagickEvent(ModuleEvent,GetMagickModule(),
1322 "Method \"%s\" in module \"%s\" at address %p",name,module_name,
1323 (void *) module_info->unregister_module);
1324 signature=module_info->register_module();
1325 if (signature != MagickImageCoderSignature)
1326 {
1327 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001328 "ImageCoderSignatureMismatch","'%s': %8lx != %8lx",module_name,
cristyf1d91242010-05-28 02:23:19 +00001329 (unsigned long) signature,(unsigned long) MagickImageCoderSignature);
cristy3ed852e2009-09-05 21:47:34 +00001330 return(MagickFalse);
1331 }
1332 return(MagickTrue);
1333}
1334
1335/*
1336%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1337% %
1338% %
1339% %
1340% O p e n M o d u l e s %
1341% %
1342% %
1343% %
1344%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1345%
1346% OpenModules() loads all available modules.
1347%
1348% The format of the OpenModules module is:
1349%
1350% MagickBooleanType OpenModules(ExceptionInfo *exception)
1351%
1352% A description of each parameter follows:
1353%
1354% o exception: return any errors or warnings in this structure.
1355%
1356*/
cristy7832dc22011-09-05 01:21:53 +00001357MagickPrivate MagickBooleanType OpenModules(ExceptionInfo *exception)
cristy3ed852e2009-09-05 21:47:34 +00001358{
1359 char
1360 **modules;
1361
cristybb503372010-05-27 20:51:26 +00001362 register ssize_t
cristy3ed852e2009-09-05 21:47:34 +00001363 i;
1364
cristybb503372010-05-27 20:51:26 +00001365 size_t
cristy3ed852e2009-09-05 21:47:34 +00001366 number_modules;
1367
1368 /*
1369 Load all modules.
1370 */
1371 (void) GetMagickInfo((char *) NULL,exception);
1372 number_modules=0;
cristya6de29a2010-06-30 14:34:26 +00001373 modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception);
Cristy26645012015-08-23 20:24:30 -04001374 if ((modules == (char **) NULL) || (*modules == (char *) NULL))
Cristy6ffac4f2015-08-23 10:55:57 -04001375 {
Cristy1dd96da2015-10-06 07:52:01 -04001376 if (modules != (char **) NULL)
Cristy6ffac4f2015-08-23 10:55:57 -04001377 modules=(char **) RelinquishMagickMemory(modules);
1378 return(MagickFalse);
1379 }
cristybb503372010-05-27 20:51:26 +00001380 for (i=0; i < (ssize_t) number_modules; i++)
cristy3ed852e2009-09-05 21:47:34 +00001381 (void) OpenModule(modules[i],exception);
1382 /*
1383 Relinquish resources.
1384 */
cristybb503372010-05-27 20:51:26 +00001385 for (i=0; i < (ssize_t) number_modules; i++)
cristy3ed852e2009-09-05 21:47:34 +00001386 modules[i]=DestroyString(modules[i]);
1387 modules=(char **) RelinquishMagickMemory(modules);
1388 return(MagickTrue);
1389}
1390
1391/*
1392%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393% %
1394% %
1395% %
1396% R e g i s t e r M o d u l e %
1397% %
1398% %
1399% %
1400%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1401%
1402% RegisterModule() adds an entry to the module list. It returns a pointer to
1403% the registered entry on success.
1404%
1405% The format of the RegisterModule module is:
1406%
1407% ModuleInfo *RegisterModule(const ModuleInfo *module_info,
1408% ExceptionInfo *exception)
1409%
1410% A description of each parameter follows:
1411%
1412% o info: a pointer to the registered entry is returned.
1413%
1414% o module_info: a pointer to the ModuleInfo structure to register.
1415%
1416% o exception: return any errors or warnings in this structure.
1417%
1418*/
1419static const ModuleInfo *RegisterModule(const ModuleInfo *module_info,
1420 ExceptionInfo *exception)
1421{
1422 MagickBooleanType
1423 status;
1424
1425 assert(module_info != (ModuleInfo *) NULL);
cristye1c94d92015-06-28 12:16:33 +00001426 assert(module_info->signature == MagickCoreSignature);
cristy3ed852e2009-09-05 21:47:34 +00001427 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag);
1428 if (module_list == (SplayTreeInfo *) NULL)
1429 return((const ModuleInfo *) NULL);
1430 status=AddValueToSplayTree(module_list,module_info->tag,module_info);
1431 if (status == MagickFalse)
1432 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
cristyefe601c2013-01-05 17:51:12 +00001433 "MemoryAllocationFailed","`%s'",module_info->tag);
cristy3ed852e2009-09-05 21:47:34 +00001434 return(module_info);
1435}
1436
1437/*
1438%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1439% %
1440% %
1441% %
1442% T a g T o C o d e r M o d u l e N a m e %
1443% %
1444% %
1445% %
1446%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1447%
1448% TagToCoderModuleName() munges a module tag and obtains the filename of the
1449% corresponding module.
1450%
1451% The format of the TagToCoderModuleName module is:
1452%
1453% char *TagToCoderModuleName(const char *tag,char *name)
1454%
1455% A description of each parameter follows:
1456%
1457% o tag: a character string representing the module tag.
1458%
1459% o name: return the module name here.
1460%
1461*/
1462static void TagToCoderModuleName(const char *tag,char *name)
1463{
1464 assert(tag != (char *) NULL);
1465 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag);
1466 assert(name != (char *) NULL);
1467#if defined(MAGICKCORE_LTDL_DELEGATE)
cristy151b66d2015-04-15 10:50:31 +00001468 (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag);
cristy3ed852e2009-09-05 21:47:34 +00001469 (void) LocaleLower(name);
1470#else
cristy0157aea2010-04-24 21:12:18 +00001471#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy3ed852e2009-09-05 21:47:34 +00001472 if (LocaleNCompare("IM_MOD_",tag,7) == 0)
cristy151b66d2015-04-15 10:50:31 +00001473 (void) CopyMagickString(name,tag,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001474 else
1475 {
1476#if defined(_DEBUG)
cristy151b66d2015-04-15 10:50:31 +00001477 (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_DB_%s_.dll",tag);
cristy3ed852e2009-09-05 21:47:34 +00001478#else
cristy151b66d2015-04-15 10:50:31 +00001479 (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_RL_%s_.dll",tag);
cristy3ed852e2009-09-05 21:47:34 +00001480#endif
1481 }
1482#endif
1483#endif
1484}
1485
1486/*
1487%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1488% %
1489% %
1490% %
1491% T a g T o F i l t e r M o d u l e N a m e %
1492% %
1493% %
1494% %
1495%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1496%
1497% TagToFilterModuleName() munges a module tag and returns the filename of the
1498% corresponding filter module.
1499%
1500% The format of the TagToFilterModuleName module is:
1501%
1502% void TagToFilterModuleName(const char *tag,char name)
1503%
1504% A description of each parameter follows:
1505%
1506% o tag: a character string representing the module tag.
1507%
1508% o name: return the filter name here.
1509%
1510*/
1511static void TagToFilterModuleName(const char *tag,char *name)
1512{
1513 assert(tag != (char *) NULL);
1514 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag);
1515 assert(name != (char *) NULL);
dirk89fad7c2015-01-17 22:09:51 +00001516#if defined(MAGICKCORE_WINDOWS_SUPPORT)
cristy151b66d2015-04-15 10:50:31 +00001517 (void) FormatLocaleString(name,MagickPathExtent,"FILTER_%s_.dll",tag);
dirk89fad7c2015-01-17 22:09:51 +00001518#elif !defined(MAGICKCORE_LTDL_DELEGATE)
cristy151b66d2015-04-15 10:50:31 +00001519 (void) FormatLocaleString(name,MagickPathExtent,"%s.dll",tag);
cristy3ed852e2009-09-05 21:47:34 +00001520#else
cristy151b66d2015-04-15 10:50:31 +00001521 (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag);
cristy3ed852e2009-09-05 21:47:34 +00001522#endif
1523}
1524
1525/*
1526%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1527% %
1528% %
1529% %
1530% T a g T o M o d u l e N a m e %
1531% %
1532% %
1533% %
1534%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1535%
1536% TagToModuleName() munges the module tag name and returns an upper-case tag
1537% name as the input string, and a user-provided format.
1538%
1539% The format of the TagToModuleName module is:
1540%
1541% TagToModuleName(const char *tag,const char *format,char *module)
1542%
1543% A description of each parameter follows:
1544%
1545% o tag: the module tag.
1546%
1547% o format: a sprintf-compatible format string containing %s where the
1548% upper-case tag name is to be inserted.
1549%
1550% o module: pointer to a destination buffer for the formatted result.
1551%
1552*/
1553static void TagToModuleName(const char *tag,const char *format,char *module)
1554{
1555 char
cristy151b66d2015-04-15 10:50:31 +00001556 name[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001557
1558 assert(tag != (const char *) NULL);
1559 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag);
1560 assert(format != (const char *) NULL);
1561 assert(module != (char *) NULL);
cristy151b66d2015-04-15 10:50:31 +00001562 (void) CopyMagickString(name,tag,MagickPathExtent);
cristy3ed852e2009-09-05 21:47:34 +00001563 LocaleUpper(name);
1564#if !defined(MAGICKCORE_NAMESPACE_PREFIX)
cristy151b66d2015-04-15 10:50:31 +00001565 (void) FormatLocaleString(module,MagickPathExtent,format,name);
cristy3ed852e2009-09-05 21:47:34 +00001566#else
1567 {
1568 char
cristy151b66d2015-04-15 10:50:31 +00001569 prefix_format[MagickPathExtent];
cristy3ed852e2009-09-05 21:47:34 +00001570
cristy151b66d2015-04-15 10:50:31 +00001571 (void) FormatLocaleString(prefix_format,MagickPathExtent,"%s%s",
cristy3ed852e2009-09-05 21:47:34 +00001572 MAGICKCORE_NAMESPACE_PREFIX,format);
cristy151b66d2015-04-15 10:50:31 +00001573 (void) FormatLocaleString(module,MagickPathExtent,prefix_format,name);
cristy3ed852e2009-09-05 21:47:34 +00001574 }
1575#endif
1576}
1577
1578/*
1579%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1580% %
1581% %
1582% %
1583% U n r e g i s t e r M o d u l e %
1584% %
1585% %
1586% %
1587%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1588%
1589% UnregisterModule() unloads a module, and invokes its de-registration module.
1590% Returns MagickTrue on success, and MagickFalse if there is an error.
1591%
1592% The format of the UnregisterModule module is:
1593%
1594% MagickBooleanType UnregisterModule(const ModuleInfo *module_info,
1595% ExceptionInfo *exception)
1596%
1597% A description of each parameter follows:
1598%
1599% o module_info: the module info.
1600%
1601% o exception: return any errors or warnings in this structure.
1602%
1603*/
1604static MagickBooleanType UnregisterModule(const ModuleInfo *module_info,
1605 ExceptionInfo *exception)
1606{
1607 /*
1608 Locate and execute UnregisterFORMATImage module.
1609 */
1610 assert(module_info != (const ModuleInfo *) NULL);
1611 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag);
1612 assert(exception != (ExceptionInfo *) NULL);
1613 if (module_info->unregister_module == NULL)
1614 return(MagickTrue);
1615 module_info->unregister_module();
1616 if (lt_dlclose((ModuleHandle) module_info->handle) != 0)
1617 {
1618 (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning,
anthonye5b39652012-04-21 05:37:29 +00001619 "UnableToCloseModule","'%s': %s",module_info->tag,lt_dlerror());
cristy3ed852e2009-09-05 21:47:34 +00001620 return(MagickFalse);
1621 }
1622 return(MagickTrue);
1623}
1624#else
dirk143157c2014-03-01 10:16:38 +00001625
1626#if !defined(MAGICKCORE_BUILD_MODULES)
1627extern size_t
1628 analyzeImage(Image **,const int,const char **,ExceptionInfo *);
1629#endif
1630
cristy3ed852e2009-09-05 21:47:34 +00001631MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file),
1632 ExceptionInfo *magick_unused(exception))
1633{
1634 return(MagickTrue);
1635}
1636
1637MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag,
1638 Image **image,const int argc,const char **argv,ExceptionInfo *exception)
1639{
cristya6de29a2010-06-30 14:34:26 +00001640 PolicyRights
1641 rights;
1642
1643 assert(image != (Image **) NULL);
cristye1c94d92015-06-28 12:16:33 +00001644 assert((*image)->signature == MagickCoreSignature);
cristya6de29a2010-06-30 14:34:26 +00001645 if ((*image)->debug != MagickFalse)
1646 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
1647 rights=ReadPolicyRights;
1648 if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse)
1649 {
1650 errno=EPERM;
1651 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
cristyefe601c2013-01-05 17:51:12 +00001652 "NotAuthorized","`%s'",tag);
cristya6de29a2010-06-30 14:34:26 +00001653 return(MagickFalse);
1654 }
1655#if defined(MAGICKCORE_BUILD_MODULES)
1656 (void) tag;
1657 (void) argc;
1658 (void) argv;
1659 (void) exception;
1660#else
cristy3ed852e2009-09-05 21:47:34 +00001661 {
cristy3ed852e2009-09-05 21:47:34 +00001662 ImageFilterHandler
1663 *image_filter;
1664
1665 image_filter=(ImageFilterHandler *) NULL;
1666 if (LocaleCompare("analyze",tag) == 0)
cristya6de29a2010-06-30 14:34:26 +00001667 image_filter=(ImageFilterHandler *) analyzeImage;
1668 if (image_filter == (ImageFilterHandler *) NULL)
1669 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
cristyefe601c2013-01-05 17:51:12 +00001670 "UnableToLoadModule","`%s'",tag);
cristya6de29a2010-06-30 14:34:26 +00001671 else
cristy3ed852e2009-09-05 21:47:34 +00001672 {
cristybb503372010-05-27 20:51:26 +00001673 size_t
cristy3ed852e2009-09-05 21:47:34 +00001674 signature;
1675
cristya6de29a2010-06-30 14:34:26 +00001676 if ((*image)->debug != MagickFalse)
1677 (void) LogMagickEvent(CoderEvent,GetMagickModule(),
1678 "Invoking \"%s\" static image filter",tag);
cristy3ed852e2009-09-05 21:47:34 +00001679 signature=image_filter(image,argc,argv,exception);
cristya6de29a2010-06-30 14:34:26 +00001680 if ((*image)->debug != MagickFalse)
1681 (void) LogMagickEvent(CoderEvent,GetMagickModule(),"\"%s\" completes",
1682 tag);
cristy3ed852e2009-09-05 21:47:34 +00001683 if (signature != MagickImageFilterSignature)
1684 {
1685 (void) ThrowMagickException(exception,GetMagickModule(),ModuleError,
anthonye5b39652012-04-21 05:37:29 +00001686 "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag,
cristya6de29a2010-06-30 14:34:26 +00001687 (unsigned long) signature,(unsigned long)
cristy3ed852e2009-09-05 21:47:34 +00001688 MagickImageFilterSignature);
1689 return(MagickFalse);
1690 }
1691 }
1692 }
1693#endif
1694 return(MagickTrue);
1695}
1696#endif