cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 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 | % % |
cristy | b56bb24 | 2014-11-25 17:12:48 +0000 | [diff] [blame] | 20 | % Copyright 1999-2015 ImageMagick Studio LLC, a non-profit organization % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 21 | % 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 | */ |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 43 | #include "MagickCore/studio.h" |
| 44 | #include "MagickCore/blob.h" |
| 45 | #include "MagickCore/coder.h" |
| 46 | #include "MagickCore/client.h" |
| 47 | #include "MagickCore/configure.h" |
| 48 | #include "MagickCore/exception.h" |
| 49 | #include "MagickCore/exception-private.h" |
| 50 | #include "MagickCore/log.h" |
| 51 | #include "MagickCore/hashmap.h" |
| 52 | #include "MagickCore/magic.h" |
| 53 | #include "MagickCore/magick.h" |
| 54 | #include "MagickCore/memory_.h" |
| 55 | #include "MagickCore/module.h" |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 56 | #include "MagickCore/module-private.h" |
cristy | d2d11ec | 2012-03-28 13:53:49 +0000 | [diff] [blame] | 57 | #include "MagickCore/nt-base-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 58 | #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" |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 63 | #include "MagickCore/string-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 64 | #include "MagickCore/token.h" |
| 65 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 66 | #include "MagickCore/utility-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 67 | #if defined(MAGICKCORE_MODULES_SUPPORT) |
| 68 | #if defined(MAGICKCORE_LTDL_DELEGATE) |
| 69 | #include "ltdl.h" |
| 70 | typedef lt_dlhandle ModuleHandle; |
| 71 | #else |
| 72 | typedef 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 | */ |
| 91 | static SemaphoreInfo |
| 92 | *module_semaphore = (SemaphoreInfo *) NULL; |
| 93 | |
| 94 | static SplayTreeInfo |
| 95 | *module_list = (SplayTreeInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 96 | |
| 97 | /* |
| 98 | Forward declarations. |
| 99 | */ |
| 100 | static const ModuleInfo |
| 101 | *RegisterModule(const ModuleInfo *,ExceptionInfo *); |
| 102 | |
| 103 | static MagickBooleanType |
| 104 | GetMagickModulePath(const char *,MagickModuleType,char *,ExceptionInfo *), |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 105 | IsModuleTreeInstantiated(ExceptionInfo *), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | UnregisterModule(const ModuleInfo *,ExceptionInfo *); |
| 107 | |
| 108 | static 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 | */ |
| 138 | MagickExport ModuleInfo *AcquireModuleInfo(const char *path,const char *tag) |
| 139 | { |
| 140 | ModuleInfo |
| 141 | *module_info; |
| 142 | |
cristy | 73bd4a5 | 2010-10-05 11:24:23 +0000 | [diff] [blame] | 143 | module_info=(ModuleInfo *) AcquireMagickMemory(sizeof(*module_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 144 | 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); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 152 | module_info->signature=MagickCoreSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 153 | 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 | */ |
| 175 | MagickExport void DestroyModuleList(void) |
| 176 | { |
| 177 | /* |
| 178 | Destroy magick modules. |
| 179 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 180 | LockSemaphoreInfo(module_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 181 | #if defined(MAGICKCORE_MODULES_SUPPORT) |
| 182 | if (module_list != (SplayTreeInfo *) NULL) |
| 183 | module_list=DestroySplayTree(module_list); |
cristy | 1e09ca2 | 2009-12-27 18:04:58 +0000 | [diff] [blame] | 184 | #endif |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 185 | UnlockSemaphoreInfo(module_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 186 | } |
| 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 | */ |
| 216 | MagickExport ModuleInfo *GetModuleInfo(const char *tag,ExceptionInfo *exception) |
| 217 | { |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame] | 218 | ModuleInfo |
| 219 | *module_info; |
| 220 | |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 221 | if (IsModuleTreeInstantiated(exception) == MagickFalse) |
| 222 | return((ModuleInfo *) NULL); |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame] | 223 | LockSemaphoreInfo(module_semaphore); |
| 224 | ResetSplayTreeIterator(module_list); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 225 | if ((tag == (const char *) NULL) || (LocaleCompare(tag,"*") == 0)) |
| 226 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 227 | #if defined(MAGICKCORE_MODULES_SUPPORT) |
| 228 | if (LocaleCompare(tag,"*") == 0) |
| 229 | (void) OpenModules(exception); |
| 230 | #endif |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame] | 231 | module_info=(ModuleInfo *) GetNextValueInSplayTree(module_list); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 232 | UnlockSemaphoreInfo(module_semaphore); |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame] | 233 | return(module_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 234 | } |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame] | 235 | module_info=(ModuleInfo *) GetValueFromSplayTree(module_list,tag); |
| 236 | UnlockSemaphoreInfo(module_semaphore); |
| 237 | return(module_info); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 238 | } |
| 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, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 256 | % size_t *number_modules,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 257 | % |
| 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) |
| 269 | extern "C" { |
| 270 | #endif |
| 271 | |
| 272 | static 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 | |
| 289 | MagickExport const ModuleInfo **GetModuleInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 290 | size_t *number_modules,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 291 | { |
| 292 | const ModuleInfo |
| 293 | **modules; |
| 294 | |
| 295 | register const ModuleInfo |
| 296 | *p; |
| 297 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 298 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 299 | i; |
| 300 | |
| 301 | /* |
| 302 | Allocate module list. |
| 303 | */ |
| 304 | assert(pattern != (char *) NULL); |
| 305 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 306 | assert(number_modules != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 307 | *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 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 318 | LockSemaphoreInfo(module_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 319 | 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 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 328 | UnlockSemaphoreInfo(module_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 329 | qsort((void *) modules,(size_t) i,sizeof(*modules),ModuleInfoCompare); |
| 330 | modules[i]=(ModuleInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 331 | *number_modules=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 332 | 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 | % |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 351 | % char **GetModuleList(const char *pattern,const MagickModuleType type, |
| 352 | % size_t *number_modules,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 353 | % |
| 354 | % A description of each parameter follows: |
| 355 | % |
| 356 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 357 | % |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 358 | % o type: choose from MagickImageCoderModule or MagickImageFilterModule. |
| 359 | % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 360 | % 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) |
| 368 | extern "C" { |
| 369 | #endif |
| 370 | |
| 371 | static 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 | |
| 386 | static 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 | |
| 399 | MagickExport char **GetModuleList(const char *pattern, |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 400 | const MagickModuleType type,size_t *number_modules,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 401 | { |
Cristy | 7e784cd | 2015-08-22 16:54:07 -0400 | [diff] [blame^] | 402 | #define MaxModules 511 |
| 403 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 404 | char |
| 405 | **modules, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 406 | filename[MagickPathExtent], |
| 407 | module_path[MagickPathExtent], |
| 408 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 409 | |
| 410 | DIR |
| 411 | *directory; |
| 412 | |
| 413 | MagickBooleanType |
| 414 | status; |
| 415 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 416 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 417 | i; |
| 418 | |
| 419 | size_t |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 420 | max_entries; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 421 | |
| 422 | struct dirent |
| 423 | *buffer, |
| 424 | *entry; |
| 425 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 426 | /* |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 427 | Locate all modules in the image coder or filter path. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 428 | */ |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 429 | 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 | } |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 447 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 448 | return((char **) NULL); |
| 449 | GetPathComponent(module_path,HeadPath,path); |
Cristy | 7e784cd | 2015-08-22 16:54:07 -0400 | [diff] [blame^] | 450 | max_entries=MaxModules; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 451 | 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 | } |
cristy | aaaff84 | 2013-06-30 02:48:11 +0000 | [diff] [blame] | 462 | buffer=(struct dirent *) AcquireMagickMemory(sizeof(*buffer)+FILENAME_MAX+1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 463 | 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; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 474 | if (i >= (ssize_t) max_entries) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 475 | { |
| 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]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 489 | if (LocaleNCompare("IM_MOD_",modules[i],7) == 0) |
| 490 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 491 | (void) CopyMagickString(modules[i],modules[i]+10,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 492 | 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, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 501 | "MemoryAllocationFailed","`%s'",pattern); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 502 | return((char **) NULL); |
| 503 | } |
| 504 | qsort((void *) modules,(size_t) i,sizeof(*modules),ModuleCompare); |
| 505 | modules[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 506 | *number_modules=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 507 | 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 | */ |
| 541 | static 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); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 551 | (void) CopyMagickString(path,filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 552 | 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 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 587 | (void) CopyMagickString(path,p+1,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 588 | q=strchr(path,DirectoryListSeparator); |
| 589 | if (q != (char *) NULL) |
| 590 | *q='\0'; |
| 591 | q=path+strlen(path)-1; |
| 592 | if ((q >= path) && (*q != *DirectorySeparator)) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 593 | (void) ConcatenateMagickString(path,DirectorySeparator,MagickPathExtent); |
| 594 | (void) ConcatenateMagickString(path,filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 595 | 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) |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 605 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 606 | #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 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 628 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s",directory,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 629 | if (IsPathAccessible(path) == MagickFalse) |
| 630 | { |
| 631 | ThrowFileException(exception,ConfigureWarning, |
| 632 | "UnableToOpenModuleFile",path); |
| 633 | return(MagickFalse); |
| 634 | } |
| 635 | return(MagickTrue); |
| 636 | } |
| 637 | #else |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 638 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 639 | { |
| 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, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 667 | "RegistryKeyLookupFailed","`%s'",registery_key); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 668 | return(MagickFalse); |
| 669 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 670 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",(char *) key_value, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 671 | 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 |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 683 | #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 |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 685 | #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) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 698 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 699 | 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 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 718 | (void) FormatLocaleString(path,MagickPathExtent,"%s/lib/%s/%s",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 719 | 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) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 732 | (void) FormatLocaleString(path,MagickPathExtent,"%s%s%s",GetClientPath(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 733 | DirectorySeparator,filename); |
| 734 | #else |
| 735 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 736 | prefix[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 737 | |
| 738 | const char |
| 739 | *directory; |
| 740 | |
| 741 | switch (module_type) |
| 742 | { |
| 743 | case MagickImageCoderModule: |
| 744 | default: |
| 745 | { |
cristy | 905e530 | 2011-11-09 18:08:43 +0000 | [diff] [blame] | 746 | directory="coders"; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 747 | break; |
| 748 | } |
| 749 | case MagickImageFilterModule: |
| 750 | { |
| 751 | directory="filters"; |
| 752 | break; |
| 753 | } |
| 754 | } |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 755 | (void) CopyMagickString(prefix,GetClientPath(),MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 756 | ChopPathComponents(prefix,1); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 757 | (void) FormatLocaleString(path,MagickPathExtent,"%s/lib/%s/%s/%s",prefix, |
cristy | fee6326 | 2012-12-02 21:47:04 +0000 | [diff] [blame] | 758 | MAGICKCORE_MODULES_RELATIVE_PATH,directory,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 759 | #endif |
| 760 | if (IsPathAccessible(path) != MagickFalse) |
| 761 | return(MagickTrue); |
| 762 | } |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 763 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 764 | { |
| 765 | /* |
| 766 | Search module path. |
| 767 | */ |
dirk | 7c6c80c | 2015-01-03 23:41:04 +0000 | [diff] [blame] | 768 | if ((NTGetModulePath("CORE_RL_MagickCore_.dll",path) != MagickFalse) || |
| 769 | (NTGetModulePath("CORE_DB_MagickCore_.dll",path) != MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 770 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 771 | (void) ConcatenateMagickString(path,DirectorySeparator,MagickPathExtent); |
| 772 | (void) ConcatenateMagickString(path,filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 773 | 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 | /* |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 788 | Search $HOME/.config/ImageMagick. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 789 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 790 | (void) FormatLocaleString(path,MagickPathExtent, |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 791 | "%s%s.config%sImageMagick%s%s",home,DirectorySeparator, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 792 | 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); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 806 | #endif |
| 807 | return(MagickFalse); |
| 808 | } |
| 809 | |
| 810 | /* |
| 811 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 812 | % % |
| 813 | % % |
| 814 | % % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 815 | % I s M o d u l e T r e e I n s t a n t i a t e d % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 816 | % % |
| 817 | % % |
| 818 | % % |
| 819 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 820 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 821 | % IsModuleTreeInstantiated() determines if the module tree is instantiated. |
| 822 | % If not, it instantiates the tree and returns it. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 823 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 824 | % The format of the IsModuleTreeInstantiated() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 825 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 826 | % IsModuleTreeInstantiated(Exceptioninfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 827 | % |
| 828 | % A description of each parameter follows. |
| 829 | % |
| 830 | % o exception: return any errors or warnings in this structure. |
| 831 | % |
| 832 | */ |
| 833 | |
| 834 | static 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 | |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 854 | static MagickBooleanType IsModuleTreeInstantiated( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 855 | ExceptionInfo *magick_unused(exception)) |
| 856 | { |
cristy | 1460f26 | 2014-03-15 17:38:05 +0000 | [diff] [blame] | 857 | if (module_list == (SplayTreeInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 858 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 859 | if (module_semaphore == (SemaphoreInfo *) NULL) |
| 860 | ActivateSemaphoreInfo(&module_semaphore); |
| 861 | LockSemaphoreInfo(module_semaphore); |
cristy | 1460f26 | 2014-03-15 17:38:05 +0000 | [diff] [blame] | 862 | if (module_list == (SplayTreeInfo *) NULL) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 863 | { |
| 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); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 886 | } |
| 887 | return(module_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); |
| 888 | } |
| 889 | |
| 890 | /* |
| 891 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 892 | % % |
| 893 | % % |
| 894 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 895 | % 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 | */ |
| 923 | MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag, |
| 924 | Image **images,const int argc,const char **argv,ExceptionInfo *exception) |
| 925 | { |
| 926 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 927 | name[MagickPathExtent], |
| 928 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 929 | |
| 930 | ImageFilterHandler |
| 931 | *image_filter; |
| 932 | |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 933 | MagickBooleanType |
| 934 | status; |
| 935 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 936 | ModuleHandle |
| 937 | handle; |
| 938 | |
| 939 | PolicyRights |
| 940 | rights; |
| 941 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 942 | /* |
| 943 | Find the module. |
| 944 | */ |
| 945 | assert(images != (Image **) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 946 | assert((*images)->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 947 | 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 | { |
cristy | a9197f6 | 2010-01-12 02:23:34 +0000 | [diff] [blame] | 963 | errno=EPERM; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 964 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 965 | "NotAuthorized","`%s'",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 966 | return(MagickFalse); |
| 967 | } |
| 968 | TagToFilterModuleName(tag,name); |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 969 | status=GetMagickModulePath(name,MagickImageFilterModule,path,exception); |
| 970 | if (status == MagickFalse) |
| 971 | { |
| 972 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 973 | "UnableToLoadModule","'%s': %s",name,path); |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 974 | return(MagickFalse); |
| 975 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 976 | /* |
| 977 | Open the module. |
| 978 | */ |
| 979 | handle=(ModuleHandle) lt_dlopen(path); |
| 980 | if (handle == (ModuleHandle) NULL) |
| 981 | { |
| 982 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 983 | "UnableToLoadModule","'%s': %s",name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 984 | return(MagickFalse); |
| 985 | } |
| 986 | /* |
| 987 | Locate the module. |
| 988 | */ |
| 989 | #if !defined(MAGICKCORE_NAMESPACE_PREFIX) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 990 | (void) FormatLocaleString(name,MagickPathExtent,"%sImage",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 991 | #else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 992 | (void) FormatLocaleString(name,MagickPathExtent,"%s%sImage", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 993 | MAGICKCORE_NAMESPACE_PREFIX,tag); |
| 994 | #endif |
| 995 | /* |
| 996 | Execute the module. |
| 997 | */ |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 998 | ClearMagickException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 999 | image_filter=(ImageFilterHandler *) lt_dlsym(handle,name); |
| 1000 | if (image_filter == (ImageFilterHandler *) NULL) |
| 1001 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1002 | "UnableToLoadModule","'%s': %s",name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1003 | else |
| 1004 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1005 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1006 | 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) |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1016 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1017 | "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag, |
cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 1018 | (unsigned long) signature,(unsigned long) MagickImageFilterSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1019 | } |
| 1020 | /* |
| 1021 | Close the module. |
| 1022 | */ |
| 1023 | if (lt_dlclose(handle) != 0) |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1024 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1025 | "UnableToCloseModule","'%s': %s",name,lt_dlerror()); |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1026 | return(exception->severity < ErrorException ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1027 | } |
| 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 | */ |
| 1053 | MagickExport MagickBooleanType ListModuleInfo(FILE *file, |
| 1054 | ExceptionInfo *exception) |
| 1055 | { |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1056 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1057 | filename[MagickPathExtent], |
| 1058 | module_path[MagickPathExtent], |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1059 | **modules, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1060 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1061 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1062 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1063 | i; |
| 1064 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1065 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1066 | number_modules; |
| 1067 | |
| 1068 | if (file == (const FILE *) NULL) |
| 1069 | file=stdout; |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1070 | /* |
| 1071 | List image coders. |
| 1072 | */ |
| 1073 | modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception); |
| 1074 | if (modules == (char **) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1075 | return(MagickFalse); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1076 | TagToCoderModuleName("magick",filename); |
| 1077 | (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path, |
| 1078 | exception); |
| 1079 | GetPathComponent(module_path,HeadPath,path); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1080 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",path); |
| 1081 | (void) FormatLocaleFile(file,"Image Coder\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1082 | (void) FormatLocaleFile(file, |
| 1083 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1084 | "------------------------------\n"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1085 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1086 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1087 | (void) FormatLocaleFile(file,"%s",modules[i]); |
| 1088 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1089 | } |
| 1090 | (void) fflush(file); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1091 | /* |
| 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); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1107 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",path); |
| 1108 | (void) FormatLocaleFile(file,"Image Filter\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1109 | (void) FormatLocaleFile(file, |
| 1110 | "-------------------------------------------------" |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1111 | "------------------------------\n"); |
| 1112 | for (i=0; i < (ssize_t) number_modules; i++) |
| 1113 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1114 | (void) FormatLocaleFile(file,"%s",modules[i]); |
| 1115 | (void) FormatLocaleFile(file,"\n"); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1116 | } |
| 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); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1124 | return(MagickTrue); |
| 1125 | } |
| 1126 | |
| 1127 | /* |
| 1128 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1129 | % % |
| 1130 | % % |
| 1131 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1132 | + 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 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1145 | MagickPrivate MagickBooleanType ModuleComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1146 | { |
| 1147 | ExceptionInfo |
| 1148 | *exception; |
| 1149 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1150 | MagickBooleanType |
| 1151 | status; |
| 1152 | |
cristy | 7c97706 | 2014-04-04 14:05:53 +0000 | [diff] [blame] | 1153 | if (module_semaphore == (SemaphoreInfo *) NULL) |
| 1154 | module_semaphore=AcquireSemaphoreInfo(); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1155 | exception=AcquireExceptionInfo(); |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 1156 | status=IsModuleTreeInstantiated(exception); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1157 | exception=DestroyExceptionInfo(exception); |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1158 | return(status); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1159 | } |
| 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 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1179 | MagickPrivate void ModuleComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1180 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 1181 | if (module_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 1182 | ActivateSemaphoreInfo(&module_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1183 | DestroyModuleList(); |
cristy | 3d162a9 | 2014-02-16 14:05:06 +0000 | [diff] [blame] | 1184 | RelinquishSemaphoreInfo(&module_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1185 | } |
| 1186 | |
| 1187 | /* |
| 1188 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1189 | % % |
| 1190 | % % |
| 1191 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1192 | % 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 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1212 | MagickPrivate MagickBooleanType OpenModule(const char *module, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1213 | ExceptionInfo *exception) |
| 1214 | { |
| 1215 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1216 | filename[MagickPathExtent], |
| 1217 | module_name[MagickPathExtent], |
| 1218 | name[MagickPathExtent], |
| 1219 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1220 | |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 1221 | MagickBooleanType |
| 1222 | status; |
| 1223 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1224 | ModuleHandle |
| 1225 | handle; |
| 1226 | |
| 1227 | ModuleInfo |
| 1228 | *module_info; |
| 1229 | |
| 1230 | register const CoderInfo |
| 1231 | *p; |
| 1232 | |
| 1233 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1234 | 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); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1243 | (void) CopyMagickString(module_name,module,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1244 | p=GetCoderInfo(module,exception); |
| 1245 | if (p != (CoderInfo *) NULL) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1246 | (void) CopyMagickString(module_name,p->name,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1247 | 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'; |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 1257 | status=GetMagickModulePath(filename,MagickImageCoderModule,path,exception); |
| 1258 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1259 | 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, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1269 | "UnableToLoadModule","'%s': %s",path,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1270 | 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); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1283 | module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name); |
| 1284 | if (module_info->register_module == (size_t (*)(void)) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1285 | { |
| 1286 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1287 | "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1288 | 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, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1301 | "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1302 | 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, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1311 | "ImageCoderSignatureMismatch","'%s': %8lx != %8lx",module_name, |
cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 1312 | (unsigned long) signature,(unsigned long) MagickImageCoderSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1313 | 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 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1340 | MagickPrivate MagickBooleanType OpenModules(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1341 | { |
| 1342 | char |
| 1343 | **modules; |
| 1344 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1345 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1346 | i; |
| 1347 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1348 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1349 | number_modules; |
| 1350 | |
| 1351 | /* |
| 1352 | Load all modules. |
| 1353 | */ |
| 1354 | (void) GetMagickInfo((char *) NULL,exception); |
| 1355 | number_modules=0; |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1356 | modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1357 | if (modules == (char **) NULL) |
| 1358 | return(MagickFalse); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1359 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1360 | (void) OpenModule(modules[i],exception); |
| 1361 | /* |
| 1362 | Relinquish resources. |
| 1363 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1364 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1365 | 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 | */ |
| 1398 | static const ModuleInfo *RegisterModule(const ModuleInfo *module_info, |
| 1399 | ExceptionInfo *exception) |
| 1400 | { |
| 1401 | MagickBooleanType |
| 1402 | status; |
| 1403 | |
| 1404 | assert(module_info != (ModuleInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1405 | assert(module_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1406 | (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, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1412 | "MemoryAllocationFailed","`%s'",module_info->tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1413 | 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 | */ |
| 1441 | static 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) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1447 | (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1448 | (void) LocaleLower(name); |
| 1449 | #else |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 1450 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1451 | if (LocaleNCompare("IM_MOD_",tag,7) == 0) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1452 | (void) CopyMagickString(name,tag,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1453 | else |
| 1454 | { |
| 1455 | #if defined(_DEBUG) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1456 | (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_DB_%s_.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1457 | #else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1458 | (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_RL_%s_.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1459 | #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 | */ |
| 1490 | static 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); |
dirk | 89fad7c | 2015-01-17 22:09:51 +0000 | [diff] [blame] | 1495 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1496 | (void) FormatLocaleString(name,MagickPathExtent,"FILTER_%s_.dll",tag); |
dirk | 89fad7c | 2015-01-17 22:09:51 +0000 | [diff] [blame] | 1497 | #elif !defined(MAGICKCORE_LTDL_DELEGATE) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1498 | (void) FormatLocaleString(name,MagickPathExtent,"%s.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1499 | #else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1500 | (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1501 | #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 | */ |
| 1532 | static void TagToModuleName(const char *tag,const char *format,char *module) |
| 1533 | { |
| 1534 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1535 | name[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1536 | |
| 1537 | assert(tag != (const char *) NULL); |
| 1538 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag); |
| 1539 | assert(format != (const char *) NULL); |
| 1540 | assert(module != (char *) NULL); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1541 | (void) CopyMagickString(name,tag,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1542 | LocaleUpper(name); |
| 1543 | #if !defined(MAGICKCORE_NAMESPACE_PREFIX) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1544 | (void) FormatLocaleString(module,MagickPathExtent,format,name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1545 | #else |
| 1546 | { |
| 1547 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1548 | prefix_format[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1549 | |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1550 | (void) FormatLocaleString(prefix_format,MagickPathExtent,"%s%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1551 | MAGICKCORE_NAMESPACE_PREFIX,format); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1552 | (void) FormatLocaleString(module,MagickPathExtent,prefix_format,name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1553 | } |
| 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 | */ |
| 1583 | static 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, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1598 | "UnableToCloseModule","'%s': %s",module_info->tag,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1599 | return(MagickFalse); |
| 1600 | } |
| 1601 | return(MagickTrue); |
| 1602 | } |
| 1603 | #else |
dirk | 143157c | 2014-03-01 10:16:38 +0000 | [diff] [blame] | 1604 | |
| 1605 | #if !defined(MAGICKCORE_BUILD_MODULES) |
| 1606 | extern size_t |
| 1607 | analyzeImage(Image **,const int,const char **,ExceptionInfo *); |
| 1608 | #endif |
| 1609 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1610 | MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file), |
| 1611 | ExceptionInfo *magick_unused(exception)) |
| 1612 | { |
| 1613 | return(MagickTrue); |
| 1614 | } |
| 1615 | |
| 1616 | MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag, |
| 1617 | Image **image,const int argc,const char **argv,ExceptionInfo *exception) |
| 1618 | { |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1619 | PolicyRights |
| 1620 | rights; |
| 1621 | |
| 1622 | assert(image != (Image **) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1623 | assert((*image)->signature == MagickCoreSignature); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1624 | 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, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1631 | "NotAuthorized","`%s'",tag); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1632 | return(MagickFalse); |
| 1633 | } |
| 1634 | #if defined(MAGICKCORE_BUILD_MODULES) |
| 1635 | (void) tag; |
| 1636 | (void) argc; |
| 1637 | (void) argv; |
| 1638 | (void) exception; |
| 1639 | #else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1640 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1641 | ImageFilterHandler |
| 1642 | *image_filter; |
| 1643 | |
| 1644 | image_filter=(ImageFilterHandler *) NULL; |
| 1645 | if (LocaleCompare("analyze",tag) == 0) |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1646 | image_filter=(ImageFilterHandler *) analyzeImage; |
| 1647 | if (image_filter == (ImageFilterHandler *) NULL) |
| 1648 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1649 | "UnableToLoadModule","`%s'",tag); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1650 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1651 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1652 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1653 | signature; |
| 1654 | |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1655 | if ((*image)->debug != MagickFalse) |
| 1656 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 1657 | "Invoking \"%s\" static image filter",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1658 | signature=image_filter(image,argc,argv,exception); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1659 | if ((*image)->debug != MagickFalse) |
| 1660 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"\"%s\" completes", |
| 1661 | tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1662 | if (signature != MagickImageFilterSignature) |
| 1663 | { |
| 1664 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1665 | "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag, |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1666 | (unsigned long) signature,(unsigned long) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1667 | MagickImageFilterSignature); |
| 1668 | return(MagickFalse); |
| 1669 | } |
| 1670 | } |
| 1671 | } |
| 1672 | #endif |
| 1673 | return(MagickTrue); |
| 1674 | } |
| 1675 | #endif |