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); |
| 152 | module_info->signature=MagickSignature; |
| 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 | { |
| 402 | char |
| 403 | **modules, |
| 404 | filename[MaxTextExtent], |
| 405 | module_path[MaxTextExtent], |
| 406 | path[MaxTextExtent]; |
| 407 | |
| 408 | DIR |
| 409 | *directory; |
| 410 | |
| 411 | MagickBooleanType |
| 412 | status; |
| 413 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 414 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 415 | i; |
| 416 | |
| 417 | size_t |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 418 | max_entries; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 419 | |
| 420 | struct dirent |
| 421 | *buffer, |
| 422 | *entry; |
| 423 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 424 | /* |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 425 | Locate all modules in the image coder or filter path. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 426 | */ |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 427 | switch (type) |
| 428 | { |
| 429 | case MagickImageCoderModule: |
| 430 | default: |
| 431 | { |
| 432 | TagToCoderModuleName("magick",filename); |
| 433 | status=GetMagickModulePath(filename,MagickImageCoderModule,module_path, |
| 434 | exception); |
| 435 | break; |
| 436 | } |
| 437 | case MagickImageFilterModule: |
| 438 | { |
| 439 | TagToFilterModuleName("analyze",filename); |
| 440 | status=GetMagickModulePath(filename,MagickImageFilterModule,module_path, |
| 441 | exception); |
| 442 | break; |
| 443 | } |
| 444 | } |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 445 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 446 | return((char **) NULL); |
| 447 | GetPathComponent(module_path,HeadPath,path); |
| 448 | max_entries=255; |
| 449 | modules=(char **) AcquireQuantumMemory((size_t) max_entries+1UL, |
| 450 | sizeof(*modules)); |
| 451 | if (modules == (char **) NULL) |
| 452 | return((char **) NULL); |
| 453 | *modules=(char *) NULL; |
| 454 | directory=opendir(path); |
| 455 | if (directory == (DIR *) NULL) |
| 456 | { |
| 457 | modules=(char **) RelinquishMagickMemory(modules); |
| 458 | return((char **) NULL); |
| 459 | } |
cristy | aaaff84 | 2013-06-30 02:48:11 +0000 | [diff] [blame] | 460 | buffer=(struct dirent *) AcquireMagickMemory(sizeof(*buffer)+FILENAME_MAX+1); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 461 | if (buffer == (struct dirent *) NULL) |
| 462 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 463 | i=0; |
| 464 | while ((MagickReadDirectory(directory,buffer,&entry) == 0) && |
| 465 | (entry != (struct dirent *) NULL)) |
| 466 | { |
| 467 | status=GlobExpression(entry->d_name,ModuleGlobExpression,MagickFalse); |
| 468 | if (status == MagickFalse) |
| 469 | continue; |
| 470 | if (GlobExpression(entry->d_name,pattern,MagickFalse) == MagickFalse) |
| 471 | continue; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 472 | if (i >= (ssize_t) max_entries) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 473 | { |
| 474 | modules=(char **) NULL; |
| 475 | if (~max_entries > max_entries) |
| 476 | modules=(char **) ResizeQuantumMemory(modules,(size_t) |
| 477 | (max_entries << 1),sizeof(*modules)); |
| 478 | max_entries<<=1; |
| 479 | if (modules == (char **) NULL) |
| 480 | break; |
| 481 | } |
| 482 | /* |
| 483 | Add new module name to list. |
| 484 | */ |
| 485 | modules[i]=AcquireString((char *) NULL); |
| 486 | GetPathComponent(entry->d_name,BasePath,modules[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 487 | if (LocaleNCompare("IM_MOD_",modules[i],7) == 0) |
| 488 | { |
| 489 | (void) CopyMagickString(modules[i],modules[i]+10,MaxTextExtent); |
| 490 | modules[i][strlen(modules[i])-1]='\0'; |
| 491 | } |
| 492 | i++; |
| 493 | } |
| 494 | buffer=(struct dirent *) RelinquishMagickMemory(buffer); |
| 495 | (void) closedir(directory); |
| 496 | if (modules == (char **) NULL) |
| 497 | { |
| 498 | (void) ThrowMagickException(exception,GetMagickModule(),ConfigureError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 499 | "MemoryAllocationFailed","`%s'",pattern); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 500 | return((char **) NULL); |
| 501 | } |
| 502 | qsort((void *) modules,(size_t) i,sizeof(*modules),ModuleCompare); |
| 503 | modules[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 504 | *number_modules=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 505 | return(modules); |
| 506 | } |
| 507 | |
| 508 | /* |
| 509 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 510 | % % |
| 511 | % % |
| 512 | % % |
| 513 | % G e t M a g i c k M o d u l e P a t h % |
| 514 | % % |
| 515 | % % |
| 516 | % % |
| 517 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 518 | % |
| 519 | % GetMagickModulePath() finds a module with the specified module type and |
| 520 | % filename. |
| 521 | % |
| 522 | % The format of the GetMagickModulePath module is: |
| 523 | % |
| 524 | % MagickBooleanType GetMagickModulePath(const char *filename, |
| 525 | % MagickModuleType module_type,char *path,ExceptionInfo *exception) |
| 526 | % |
| 527 | % A description of each parameter follows: |
| 528 | % |
| 529 | % o filename: the module file name. |
| 530 | % |
| 531 | % o module_type: the module type: MagickImageCoderModule or |
| 532 | % MagickImageFilterModule. |
| 533 | % |
| 534 | % o path: the path associated with the filename. |
| 535 | % |
| 536 | % o exception: return any errors or warnings in this structure. |
| 537 | % |
| 538 | */ |
| 539 | static MagickBooleanType GetMagickModulePath(const char *filename, |
| 540 | MagickModuleType module_type,char *path,ExceptionInfo *exception) |
| 541 | { |
| 542 | char |
| 543 | *module_path; |
| 544 | |
| 545 | assert(filename != (const char *) NULL); |
| 546 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",filename); |
| 547 | assert(path != (char *) NULL); |
| 548 | assert(exception != (ExceptionInfo *) NULL); |
| 549 | (void) CopyMagickString(path,filename,MaxTextExtent); |
| 550 | module_path=(char *) NULL; |
| 551 | switch (module_type) |
| 552 | { |
| 553 | case MagickImageCoderModule: |
| 554 | default: |
| 555 | { |
| 556 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 557 | "Searching for coder module file \"%s\" ...",filename); |
| 558 | module_path=GetEnvironmentValue("MAGICK_CODER_MODULE_PATH"); |
| 559 | #if defined(MAGICKCORE_CODER_PATH) |
| 560 | if (module_path == (char *) NULL) |
| 561 | module_path=AcquireString(MAGICKCORE_CODER_PATH); |
| 562 | #endif |
| 563 | break; |
| 564 | } |
| 565 | case MagickImageFilterModule: |
| 566 | { |
| 567 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 568 | "Searching for filter module file \"%s\" ...",filename); |
| 569 | module_path=GetEnvironmentValue("MAGICK_CODER_FILTER_PATH"); |
| 570 | #if defined(MAGICKCORE_FILTER_PATH) |
| 571 | if (module_path == (char *) NULL) |
| 572 | module_path=AcquireString(MAGICKCORE_FILTER_PATH); |
| 573 | #endif |
| 574 | break; |
| 575 | } |
| 576 | } |
| 577 | if (module_path != (char *) NULL) |
| 578 | { |
| 579 | register char |
| 580 | *p, |
| 581 | *q; |
| 582 | |
| 583 | for (p=module_path-1; p != (char *) NULL; ) |
| 584 | { |
| 585 | (void) CopyMagickString(path,p+1,MaxTextExtent); |
| 586 | q=strchr(path,DirectoryListSeparator); |
| 587 | if (q != (char *) NULL) |
| 588 | *q='\0'; |
| 589 | q=path+strlen(path)-1; |
| 590 | if ((q >= path) && (*q != *DirectorySeparator)) |
| 591 | (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent); |
| 592 | (void) ConcatenateMagickString(path,filename,MaxTextExtent); |
| 593 | if (IsPathAccessible(path) != MagickFalse) |
| 594 | { |
| 595 | module_path=DestroyString(module_path); |
| 596 | return(MagickTrue); |
| 597 | } |
| 598 | p=strchr(p+1,DirectoryListSeparator); |
| 599 | } |
| 600 | module_path=DestroyString(module_path); |
| 601 | } |
| 602 | #if defined(MAGICKCORE_INSTALLED_SUPPORT) |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 603 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 604 | #if defined(MAGICKCORE_CODER_PATH) |
| 605 | { |
| 606 | const char |
| 607 | *directory; |
| 608 | |
| 609 | /* |
| 610 | Search hard coded paths. |
| 611 | */ |
| 612 | switch (module_type) |
| 613 | { |
| 614 | case MagickImageCoderModule: |
| 615 | default: |
| 616 | { |
| 617 | directory=MAGICKCORE_CODER_PATH; |
| 618 | break; |
| 619 | } |
| 620 | case MagickImageFilterModule: |
| 621 | { |
| 622 | directory=MAGICKCORE_FILTER_PATH; |
| 623 | break; |
| 624 | } |
| 625 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 626 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s",directory,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 627 | if (IsPathAccessible(path) == MagickFalse) |
| 628 | { |
| 629 | ThrowFileException(exception,ConfigureWarning, |
| 630 | "UnableToOpenModuleFile",path); |
| 631 | return(MagickFalse); |
| 632 | } |
| 633 | return(MagickTrue); |
| 634 | } |
| 635 | #else |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 636 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 637 | { |
| 638 | const char |
| 639 | *registery_key; |
| 640 | |
| 641 | unsigned char |
| 642 | *key_value; |
| 643 | |
| 644 | /* |
| 645 | Locate path via registry key. |
| 646 | */ |
| 647 | switch (module_type) |
| 648 | { |
| 649 | case MagickImageCoderModule: |
| 650 | default: |
| 651 | { |
| 652 | registery_key="CoderModulesPath"; |
| 653 | break; |
| 654 | } |
| 655 | case MagickImageFilterModule: |
| 656 | { |
| 657 | registery_key="FilterModulesPath"; |
| 658 | break; |
| 659 | } |
| 660 | } |
| 661 | key_value=NTRegistryKeyLookup(registery_key); |
| 662 | if (key_value == (unsigned char *) NULL) |
| 663 | { |
| 664 | ThrowMagickException(exception,GetMagickModule(),ConfigureError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 665 | "RegistryKeyLookupFailed","`%s'",registery_key); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 666 | return(MagickFalse); |
| 667 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 668 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",(char *) key_value, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 669 | DirectorySeparator,filename); |
| 670 | key_value=(unsigned char *) RelinquishMagickMemory(key_value); |
| 671 | if (IsPathAccessible(path) == MagickFalse) |
| 672 | { |
| 673 | ThrowFileException(exception,ConfigureWarning, |
| 674 | "UnableToOpenModuleFile",path); |
| 675 | return(MagickFalse); |
| 676 | } |
| 677 | return(MagickTrue); |
| 678 | } |
| 679 | #endif |
| 680 | #endif |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 681 | #if !defined(MAGICKCORE_CODER_PATH) && !defined(MAGICKCORE_WINDOWS_SUPPORT) |
| 682 | # 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] | 683 | #endif |
| 684 | #else |
| 685 | { |
| 686 | char |
| 687 | *home; |
| 688 | |
| 689 | home=GetEnvironmentValue("MAGICK_HOME"); |
| 690 | if (home != (char *) NULL) |
| 691 | { |
| 692 | /* |
| 693 | Search MAGICK_HOME. |
| 694 | */ |
| 695 | #if !defined(MAGICKCORE_POSIX_SUPPORT) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 696 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 697 | DirectorySeparator,filename); |
| 698 | #else |
| 699 | const char |
| 700 | *directory; |
| 701 | |
| 702 | switch (module_type) |
| 703 | { |
| 704 | case MagickImageCoderModule: |
| 705 | default: |
| 706 | { |
| 707 | directory=MAGICKCORE_CODER_RELATIVE_PATH; |
| 708 | break; |
| 709 | } |
| 710 | case MagickImageFilterModule: |
| 711 | { |
| 712 | directory=MAGICKCORE_FILTER_RELATIVE_PATH; |
| 713 | break; |
| 714 | } |
| 715 | } |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 716 | (void) FormatLocaleString(path,MaxTextExtent,"%s/lib/%s/%s",home, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 717 | directory,filename); |
| 718 | #endif |
| 719 | home=DestroyString(home); |
| 720 | if (IsPathAccessible(path) != MagickFalse) |
| 721 | return(MagickTrue); |
| 722 | } |
| 723 | } |
| 724 | if (*GetClientPath() != '\0') |
| 725 | { |
| 726 | /* |
| 727 | Search based on executable directory. |
| 728 | */ |
| 729 | #if !defined(MAGICKCORE_POSIX_SUPPORT) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 730 | (void) FormatLocaleString(path,MaxTextExtent,"%s%s%s",GetClientPath(), |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 731 | DirectorySeparator,filename); |
| 732 | #else |
| 733 | char |
| 734 | prefix[MaxTextExtent]; |
| 735 | |
| 736 | const char |
| 737 | *directory; |
| 738 | |
| 739 | switch (module_type) |
| 740 | { |
| 741 | case MagickImageCoderModule: |
| 742 | default: |
| 743 | { |
cristy | 905e530 | 2011-11-09 18:08:43 +0000 | [diff] [blame] | 744 | directory="coders"; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 745 | break; |
| 746 | } |
| 747 | case MagickImageFilterModule: |
| 748 | { |
| 749 | directory="filters"; |
| 750 | break; |
| 751 | } |
| 752 | } |
| 753 | (void) CopyMagickString(prefix,GetClientPath(),MaxTextExtent); |
| 754 | ChopPathComponents(prefix,1); |
cristy | fee6326 | 2012-12-02 21:47:04 +0000 | [diff] [blame] | 755 | (void) FormatLocaleString(path,MaxTextExtent,"%s/lib/%s/%s/%s",prefix, |
| 756 | MAGICKCORE_MODULES_RELATIVE_PATH,directory,filename); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 757 | #endif |
| 758 | if (IsPathAccessible(path) != MagickFalse) |
| 759 | return(MagickTrue); |
| 760 | } |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 761 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 762 | { |
| 763 | /* |
| 764 | Search module path. |
| 765 | */ |
dirk | 7c6c80c | 2015-01-03 23:41:04 +0000 | [diff] [blame^] | 766 | if ((NTGetModulePath("CORE_RL_MagickCore_.dll",path) != MagickFalse) || |
| 767 | (NTGetModulePath("CORE_DB_MagickCore_.dll",path) != MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 768 | { |
| 769 | (void) ConcatenateMagickString(path,DirectorySeparator,MaxTextExtent); |
| 770 | (void) ConcatenateMagickString(path,filename,MaxTextExtent); |
| 771 | if (IsPathAccessible(path) != MagickFalse) |
| 772 | return(MagickTrue); |
| 773 | } |
| 774 | } |
| 775 | #endif |
| 776 | { |
| 777 | char |
| 778 | *home; |
| 779 | |
| 780 | home=GetEnvironmentValue("HOME"); |
| 781 | if (home == (char *) NULL) |
| 782 | home=GetEnvironmentValue("USERPROFILE"); |
| 783 | if (home != (char *) NULL) |
| 784 | { |
| 785 | /* |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 786 | Search $HOME/.config/ImageMagick. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 787 | */ |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 788 | (void) FormatLocaleString(path,MaxTextExtent, |
| 789 | "%s%s.config%sImageMagick%s%s",home,DirectorySeparator, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 790 | DirectorySeparator,DirectorySeparator,filename); |
| 791 | home=DestroyString(home); |
| 792 | if (IsPathAccessible(path) != MagickFalse) |
| 793 | return(MagickTrue); |
| 794 | } |
| 795 | } |
| 796 | /* |
| 797 | Search current directory. |
| 798 | */ |
| 799 | if (IsPathAccessible(path) != MagickFalse) |
| 800 | return(MagickTrue); |
| 801 | if (exception->severity < ConfigureError) |
| 802 | ThrowFileException(exception,ConfigureWarning,"UnableToOpenModuleFile", |
| 803 | path); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 804 | #endif |
| 805 | return(MagickFalse); |
| 806 | } |
| 807 | |
| 808 | /* |
| 809 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 810 | % % |
| 811 | % % |
| 812 | % % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 813 | % 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] | 814 | % % |
| 815 | % % |
| 816 | % % |
| 817 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 818 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 819 | % IsModuleTreeInstantiated() determines if the module tree is instantiated. |
| 820 | % If not, it instantiates the tree and returns it. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 821 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 822 | % The format of the IsModuleTreeInstantiated() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 823 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 824 | % IsModuleTreeInstantiated(Exceptioninfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 825 | % |
| 826 | % A description of each parameter follows. |
| 827 | % |
| 828 | % o exception: return any errors or warnings in this structure. |
| 829 | % |
| 830 | */ |
| 831 | |
| 832 | static void *DestroyModuleNode(void *module_info) |
| 833 | { |
| 834 | ExceptionInfo |
| 835 | *exception; |
| 836 | |
| 837 | register ModuleInfo |
| 838 | *p; |
| 839 | |
| 840 | exception=AcquireExceptionInfo(); |
| 841 | p=(ModuleInfo *) module_info; |
| 842 | if (UnregisterModule(p,exception) == MagickFalse) |
| 843 | CatchException(exception); |
| 844 | if (p->tag != (char *) NULL) |
| 845 | p->tag=DestroyString(p->tag); |
| 846 | if (p->path != (char *) NULL) |
| 847 | p->path=DestroyString(p->path); |
| 848 | exception=DestroyExceptionInfo(exception); |
| 849 | return(RelinquishMagickMemory(p)); |
| 850 | } |
| 851 | |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 852 | static MagickBooleanType IsModuleTreeInstantiated( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 853 | ExceptionInfo *magick_unused(exception)) |
| 854 | { |
cristy | 1460f26 | 2014-03-15 17:38:05 +0000 | [diff] [blame] | 855 | if (module_list == (SplayTreeInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 856 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 857 | if (module_semaphore == (SemaphoreInfo *) NULL) |
| 858 | ActivateSemaphoreInfo(&module_semaphore); |
| 859 | LockSemaphoreInfo(module_semaphore); |
cristy | 1460f26 | 2014-03-15 17:38:05 +0000 | [diff] [blame] | 860 | if (module_list == (SplayTreeInfo *) NULL) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 861 | { |
| 862 | MagickBooleanType |
| 863 | status; |
| 864 | |
| 865 | ModuleInfo |
| 866 | *module_info; |
| 867 | |
| 868 | module_list=NewSplayTree(CompareSplayTreeString, |
| 869 | (void *(*)(void *)) NULL,DestroyModuleNode); |
| 870 | if (module_list == (SplayTreeInfo *) NULL) |
| 871 | ThrowFatalException(ResourceLimitFatalError, |
| 872 | "MemoryAllocationFailed"); |
| 873 | module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]"); |
| 874 | module_info->stealth=MagickTrue; |
| 875 | status=AddValueToSplayTree(module_list,module_info->tag,module_info); |
| 876 | if (status == MagickFalse) |
| 877 | ThrowFatalException(ResourceLimitFatalError, |
| 878 | "MemoryAllocationFailed"); |
| 879 | if (lt_dlinit() != 0) |
| 880 | ThrowFatalException(ModuleFatalError, |
| 881 | "UnableToInitializeModuleLoader"); |
| 882 | } |
| 883 | UnlockSemaphoreInfo(module_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 884 | } |
| 885 | return(module_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); |
| 886 | } |
| 887 | |
| 888 | /* |
| 889 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 890 | % % |
| 891 | % % |
| 892 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 893 | % I n v o k e D y n a m i c I m a g e F i l t e r % |
| 894 | % % |
| 895 | % % |
| 896 | % % |
| 897 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 898 | % |
| 899 | % InvokeDynamicImageFilter() invokes a dynamic image filter. |
| 900 | % |
| 901 | % The format of the InvokeDynamicImageFilter module is: |
| 902 | % |
| 903 | % MagickBooleanType InvokeDynamicImageFilter(const char *tag,Image **image, |
| 904 | % const int argc,const char **argv,ExceptionInfo *exception) |
| 905 | % |
| 906 | % A description of each parameter follows: |
| 907 | % |
| 908 | % o tag: a character string that represents the name of the particular |
| 909 | % module. |
| 910 | % |
| 911 | % o image: the image. |
| 912 | % |
| 913 | % o argc: a pointer to an integer describing the number of elements in the |
| 914 | % argument vector. |
| 915 | % |
| 916 | % o argv: a pointer to a text array containing the command line arguments. |
| 917 | % |
| 918 | % o exception: return any errors or warnings in this structure. |
| 919 | % |
| 920 | */ |
| 921 | MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag, |
| 922 | Image **images,const int argc,const char **argv,ExceptionInfo *exception) |
| 923 | { |
| 924 | char |
| 925 | name[MaxTextExtent], |
| 926 | path[MaxTextExtent]; |
| 927 | |
| 928 | ImageFilterHandler |
| 929 | *image_filter; |
| 930 | |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 931 | MagickBooleanType |
| 932 | status; |
| 933 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 934 | ModuleHandle |
| 935 | handle; |
| 936 | |
| 937 | PolicyRights |
| 938 | rights; |
| 939 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 940 | /* |
| 941 | Find the module. |
| 942 | */ |
| 943 | assert(images != (Image **) NULL); |
| 944 | assert((*images)->signature == MagickSignature); |
| 945 | if ((*images)->debug != MagickFalse) |
| 946 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 947 | (*images)->filename); |
| 948 | #if !defined(MAGICKCORE_BUILD_MODULES) |
| 949 | { |
| 950 | MagickBooleanType |
| 951 | status; |
| 952 | |
| 953 | status=InvokeStaticImageFilter(tag,images,argc,argv,exception); |
| 954 | if (status != MagickFalse) |
| 955 | return(status); |
| 956 | } |
| 957 | #endif |
| 958 | rights=ReadPolicyRights; |
| 959 | if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse) |
| 960 | { |
cristy | a9197f6 | 2010-01-12 02:23:34 +0000 | [diff] [blame] | 961 | errno=EPERM; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 962 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 963 | "NotAuthorized","`%s'",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 964 | return(MagickFalse); |
| 965 | } |
| 966 | TagToFilterModuleName(tag,name); |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 967 | status=GetMagickModulePath(name,MagickImageFilterModule,path,exception); |
| 968 | if (status == MagickFalse) |
| 969 | { |
| 970 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 971 | "UnableToLoadModule","'%s': %s",name,path); |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 972 | return(MagickFalse); |
| 973 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 974 | /* |
| 975 | Open the module. |
| 976 | */ |
| 977 | handle=(ModuleHandle) lt_dlopen(path); |
| 978 | if (handle == (ModuleHandle) NULL) |
| 979 | { |
| 980 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 981 | "UnableToLoadModule","'%s': %s",name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 982 | return(MagickFalse); |
| 983 | } |
| 984 | /* |
| 985 | Locate the module. |
| 986 | */ |
| 987 | #if !defined(MAGICKCORE_NAMESPACE_PREFIX) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 988 | (void) FormatLocaleString(name,MaxTextExtent,"%sImage",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 989 | #else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 990 | (void) FormatLocaleString(name,MaxTextExtent,"%s%sImage", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 991 | MAGICKCORE_NAMESPACE_PREFIX,tag); |
| 992 | #endif |
| 993 | /* |
| 994 | Execute the module. |
| 995 | */ |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 996 | ClearMagickException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 997 | image_filter=(ImageFilterHandler *) lt_dlsym(handle,name); |
| 998 | if (image_filter == (ImageFilterHandler *) NULL) |
| 999 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1000 | "UnableToLoadModule","'%s': %s",name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1001 | else |
| 1002 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1003 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1004 | signature; |
| 1005 | |
| 1006 | if ((*images)->debug != MagickFalse) |
| 1007 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1008 | "Invoking \"%s\" dynamic image filter",tag); |
| 1009 | signature=image_filter(images,argc,argv,exception); |
| 1010 | if ((*images)->debug != MagickFalse) |
| 1011 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(),"\"%s\" completes", |
| 1012 | tag); |
| 1013 | if (signature != MagickImageFilterSignature) |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1014 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1015 | "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag, |
cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 1016 | (unsigned long) signature,(unsigned long) MagickImageFilterSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1017 | } |
| 1018 | /* |
| 1019 | Close the module. |
| 1020 | */ |
| 1021 | if (lt_dlclose(handle) != 0) |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1022 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1023 | "UnableToCloseModule","'%s': %s",name,lt_dlerror()); |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1024 | return(exception->severity < ErrorException ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | /* |
| 1028 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1029 | % % |
| 1030 | % % |
| 1031 | % % |
| 1032 | % L i s t M o d u l e I n f o % |
| 1033 | % % |
| 1034 | % % |
| 1035 | % % |
| 1036 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1037 | % |
| 1038 | % ListModuleInfo() lists the module info to a file. |
| 1039 | % |
| 1040 | % The format of the ListModuleInfo module is: |
| 1041 | % |
| 1042 | % MagickBooleanType ListModuleInfo(FILE *file,ExceptionInfo *exception) |
| 1043 | % |
| 1044 | % A description of each parameter follows. |
| 1045 | % |
| 1046 | % o file: An pointer to a FILE. |
| 1047 | % |
| 1048 | % o exception: return any errors or warnings in this structure. |
| 1049 | % |
| 1050 | */ |
| 1051 | MagickExport MagickBooleanType ListModuleInfo(FILE *file, |
| 1052 | ExceptionInfo *exception) |
| 1053 | { |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1054 | char |
| 1055 | filename[MaxTextExtent], |
| 1056 | module_path[MaxTextExtent], |
| 1057 | **modules, |
| 1058 | path[MaxTextExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1059 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1060 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1061 | i; |
| 1062 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1063 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1064 | number_modules; |
| 1065 | |
| 1066 | if (file == (const FILE *) NULL) |
| 1067 | file=stdout; |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1068 | /* |
| 1069 | List image coders. |
| 1070 | */ |
| 1071 | modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception); |
| 1072 | if (modules == (char **) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1073 | return(MagickFalse); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1074 | TagToCoderModuleName("magick",filename); |
| 1075 | (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path, |
| 1076 | exception); |
| 1077 | GetPathComponent(module_path,HeadPath,path); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1078 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",path); |
| 1079 | (void) FormatLocaleFile(file,"Image Coder\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1080 | (void) FormatLocaleFile(file, |
| 1081 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1082 | "------------------------------\n"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1083 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1084 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1085 | (void) FormatLocaleFile(file,"%s",modules[i]); |
| 1086 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1087 | } |
| 1088 | (void) fflush(file); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1089 | /* |
| 1090 | Relinquish resources. |
| 1091 | */ |
| 1092 | for (i=0; i < (ssize_t) number_modules; i++) |
| 1093 | modules[i]=DestroyString(modules[i]); |
| 1094 | modules=(char **) RelinquishMagickMemory(modules); |
| 1095 | /* |
| 1096 | List image filters. |
| 1097 | */ |
| 1098 | modules=GetModuleList("*",MagickImageFilterModule,&number_modules,exception); |
| 1099 | if (modules == (char **) NULL) |
| 1100 | return(MagickFalse); |
| 1101 | TagToFilterModuleName("analyze",filename); |
| 1102 | (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path, |
| 1103 | exception); |
| 1104 | GetPathComponent(module_path,HeadPath,path); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1105 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",path); |
| 1106 | (void) FormatLocaleFile(file,"Image Filter\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1107 | (void) FormatLocaleFile(file, |
| 1108 | "-------------------------------------------------" |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1109 | "------------------------------\n"); |
| 1110 | for (i=0; i < (ssize_t) number_modules; i++) |
| 1111 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1112 | (void) FormatLocaleFile(file,"%s",modules[i]); |
| 1113 | (void) FormatLocaleFile(file,"\n"); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1114 | } |
| 1115 | (void) fflush(file); |
| 1116 | /* |
| 1117 | Relinquish resources. |
| 1118 | */ |
| 1119 | for (i=0; i < (ssize_t) number_modules; i++) |
| 1120 | modules[i]=DestroyString(modules[i]); |
| 1121 | modules=(char **) RelinquishMagickMemory(modules); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1122 | return(MagickTrue); |
| 1123 | } |
| 1124 | |
| 1125 | /* |
| 1126 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1127 | % % |
| 1128 | % % |
| 1129 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1130 | + M o d u l e C o m p o n e n t G e n e s i s % |
| 1131 | % % |
| 1132 | % % |
| 1133 | % % |
| 1134 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1135 | % |
| 1136 | % ModuleComponentGenesis() instantiates the module component. |
| 1137 | % |
| 1138 | % The format of the ModuleComponentGenesis method is: |
| 1139 | % |
| 1140 | % MagickBooleanType ModuleComponentGenesis(void) |
| 1141 | % |
| 1142 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1143 | MagickPrivate MagickBooleanType ModuleComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1144 | { |
| 1145 | ExceptionInfo |
| 1146 | *exception; |
| 1147 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1148 | MagickBooleanType |
| 1149 | status; |
| 1150 | |
cristy | 7c97706 | 2014-04-04 14:05:53 +0000 | [diff] [blame] | 1151 | if (module_semaphore == (SemaphoreInfo *) NULL) |
| 1152 | module_semaphore=AcquireSemaphoreInfo(); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1153 | exception=AcquireExceptionInfo(); |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 1154 | status=IsModuleTreeInstantiated(exception); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1155 | exception=DestroyExceptionInfo(exception); |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1156 | return(status); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1157 | } |
| 1158 | |
| 1159 | /* |
| 1160 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1161 | % % |
| 1162 | % % |
| 1163 | % % |
| 1164 | + M o d u l e C o m p o n e n t T e r m i n u s % |
| 1165 | % % |
| 1166 | % % |
| 1167 | % % |
| 1168 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1169 | % |
| 1170 | % ModuleComponentTerminus() destroys the module component. |
| 1171 | % |
| 1172 | % The format of the ModuleComponentTerminus method is: |
| 1173 | % |
| 1174 | % ModuleComponentTerminus(void) |
| 1175 | % |
| 1176 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1177 | MagickPrivate void ModuleComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1178 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 1179 | if (module_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 1180 | ActivateSemaphoreInfo(&module_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1181 | DestroyModuleList(); |
cristy | 3d162a9 | 2014-02-16 14:05:06 +0000 | [diff] [blame] | 1182 | RelinquishSemaphoreInfo(&module_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1183 | } |
| 1184 | |
| 1185 | /* |
| 1186 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1187 | % % |
| 1188 | % % |
| 1189 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1190 | % O p e n M o d u l e % |
| 1191 | % % |
| 1192 | % % |
| 1193 | % % |
| 1194 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1195 | % |
| 1196 | % OpenModule() loads a module, and invokes its registration module. It |
| 1197 | % returns MagickTrue on success, and MagickFalse if there is an error. |
| 1198 | % |
| 1199 | % The format of the OpenModule module is: |
| 1200 | % |
| 1201 | % MagickBooleanType OpenModule(const char *module,ExceptionInfo *exception) |
| 1202 | % |
| 1203 | % A description of each parameter follows: |
| 1204 | % |
| 1205 | % o module: a character string that indicates the module to load. |
| 1206 | % |
| 1207 | % o exception: return any errors or warnings in this structure. |
| 1208 | % |
| 1209 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1210 | MagickPrivate MagickBooleanType OpenModule(const char *module, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1211 | ExceptionInfo *exception) |
| 1212 | { |
| 1213 | char |
| 1214 | filename[MaxTextExtent], |
| 1215 | module_name[MaxTextExtent], |
| 1216 | name[MaxTextExtent], |
| 1217 | path[MaxTextExtent]; |
| 1218 | |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 1219 | MagickBooleanType |
| 1220 | status; |
| 1221 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1222 | ModuleHandle |
| 1223 | handle; |
| 1224 | |
| 1225 | ModuleInfo |
| 1226 | *module_info; |
| 1227 | |
| 1228 | register const CoderInfo |
| 1229 | *p; |
| 1230 | |
| 1231 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1232 | signature; |
| 1233 | |
| 1234 | /* |
| 1235 | Assign module name from alias. |
| 1236 | */ |
| 1237 | assert(module != (const char *) NULL); |
| 1238 | module_info=(ModuleInfo *) GetModuleInfo(module,exception); |
| 1239 | if (module_info != (ModuleInfo *) NULL) |
| 1240 | return(MagickTrue); |
| 1241 | (void) CopyMagickString(module_name,module,MaxTextExtent); |
| 1242 | p=GetCoderInfo(module,exception); |
| 1243 | if (p != (CoderInfo *) NULL) |
| 1244 | (void) CopyMagickString(module_name,p->name,MaxTextExtent); |
| 1245 | if (GetValueFromSplayTree(module_list,module_name) != (void *) NULL) |
| 1246 | return(MagickTrue); /* module already opened, return */ |
| 1247 | /* |
| 1248 | Locate module. |
| 1249 | */ |
| 1250 | handle=(ModuleHandle) NULL; |
| 1251 | TagToCoderModuleName(module_name,filename); |
| 1252 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1253 | "Searching for module \"%s\" using filename \"%s\"",module_name,filename); |
| 1254 | *path='\0'; |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 1255 | status=GetMagickModulePath(filename,MagickImageCoderModule,path,exception); |
| 1256 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1257 | return(MagickFalse); |
| 1258 | /* |
| 1259 | Load module |
| 1260 | */ |
| 1261 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1262 | "Opening module at path \"%s\"",path); |
| 1263 | handle=(ModuleHandle) lt_dlopen(path); |
| 1264 | if (handle == (ModuleHandle) NULL) |
| 1265 | { |
| 1266 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1267 | "UnableToLoadModule","'%s': %s",path,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1268 | return(MagickFalse); |
| 1269 | } |
| 1270 | /* |
| 1271 | Register module. |
| 1272 | */ |
| 1273 | module_info=AcquireModuleInfo(path,module_name); |
| 1274 | module_info->handle=handle; |
| 1275 | if (RegisterModule(module_info,exception) == (ModuleInfo *) NULL) |
| 1276 | return(MagickFalse); |
| 1277 | /* |
| 1278 | Define RegisterFORMATImage method. |
| 1279 | */ |
| 1280 | TagToModuleName(module_name,"Register%sImage",name); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1281 | module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name); |
| 1282 | if (module_info->register_module == (size_t (*)(void)) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1283 | { |
| 1284 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1285 | "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1286 | return(MagickFalse); |
| 1287 | } |
| 1288 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1289 | "Method \"%s\" in module \"%s\" at address %p",name,module_name, |
| 1290 | (void *) module_info->register_module); |
| 1291 | /* |
| 1292 | Define UnregisterFORMATImage method. |
| 1293 | */ |
| 1294 | TagToModuleName(module_name,"Unregister%sImage",name); |
| 1295 | module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name); |
| 1296 | if (module_info->unregister_module == (void (*)(void)) NULL) |
| 1297 | { |
| 1298 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1299 | "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1300 | return(MagickFalse); |
| 1301 | } |
| 1302 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1303 | "Method \"%s\" in module \"%s\" at address %p",name,module_name, |
| 1304 | (void *) module_info->unregister_module); |
| 1305 | signature=module_info->register_module(); |
| 1306 | if (signature != MagickImageCoderSignature) |
| 1307 | { |
| 1308 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1309 | "ImageCoderSignatureMismatch","'%s': %8lx != %8lx",module_name, |
cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 1310 | (unsigned long) signature,(unsigned long) MagickImageCoderSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1311 | return(MagickFalse); |
| 1312 | } |
| 1313 | return(MagickTrue); |
| 1314 | } |
| 1315 | |
| 1316 | /* |
| 1317 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1318 | % % |
| 1319 | % % |
| 1320 | % % |
| 1321 | % O p e n M o d u l e s % |
| 1322 | % % |
| 1323 | % % |
| 1324 | % % |
| 1325 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1326 | % |
| 1327 | % OpenModules() loads all available modules. |
| 1328 | % |
| 1329 | % The format of the OpenModules module is: |
| 1330 | % |
| 1331 | % MagickBooleanType OpenModules(ExceptionInfo *exception) |
| 1332 | % |
| 1333 | % A description of each parameter follows: |
| 1334 | % |
| 1335 | % o exception: return any errors or warnings in this structure. |
| 1336 | % |
| 1337 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1338 | MagickPrivate MagickBooleanType OpenModules(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1339 | { |
| 1340 | char |
| 1341 | **modules; |
| 1342 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1343 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1344 | i; |
| 1345 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1346 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1347 | number_modules; |
| 1348 | |
| 1349 | /* |
| 1350 | Load all modules. |
| 1351 | */ |
| 1352 | (void) GetMagickInfo((char *) NULL,exception); |
| 1353 | number_modules=0; |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1354 | modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1355 | if (modules == (char **) NULL) |
| 1356 | return(MagickFalse); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1357 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1358 | (void) OpenModule(modules[i],exception); |
| 1359 | /* |
| 1360 | Relinquish resources. |
| 1361 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1362 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1363 | modules[i]=DestroyString(modules[i]); |
| 1364 | modules=(char **) RelinquishMagickMemory(modules); |
| 1365 | return(MagickTrue); |
| 1366 | } |
| 1367 | |
| 1368 | /* |
| 1369 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1370 | % % |
| 1371 | % % |
| 1372 | % % |
| 1373 | % R e g i s t e r M o d u l e % |
| 1374 | % % |
| 1375 | % % |
| 1376 | % % |
| 1377 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1378 | % |
| 1379 | % RegisterModule() adds an entry to the module list. It returns a pointer to |
| 1380 | % the registered entry on success. |
| 1381 | % |
| 1382 | % The format of the RegisterModule module is: |
| 1383 | % |
| 1384 | % ModuleInfo *RegisterModule(const ModuleInfo *module_info, |
| 1385 | % ExceptionInfo *exception) |
| 1386 | % |
| 1387 | % A description of each parameter follows: |
| 1388 | % |
| 1389 | % o info: a pointer to the registered entry is returned. |
| 1390 | % |
| 1391 | % o module_info: a pointer to the ModuleInfo structure to register. |
| 1392 | % |
| 1393 | % o exception: return any errors or warnings in this structure. |
| 1394 | % |
| 1395 | */ |
| 1396 | static const ModuleInfo *RegisterModule(const ModuleInfo *module_info, |
| 1397 | ExceptionInfo *exception) |
| 1398 | { |
| 1399 | MagickBooleanType |
| 1400 | status; |
| 1401 | |
| 1402 | assert(module_info != (ModuleInfo *) NULL); |
| 1403 | assert(module_info->signature == MagickSignature); |
| 1404 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag); |
| 1405 | if (module_list == (SplayTreeInfo *) NULL) |
| 1406 | return((const ModuleInfo *) NULL); |
| 1407 | status=AddValueToSplayTree(module_list,module_info->tag,module_info); |
| 1408 | if (status == MagickFalse) |
| 1409 | (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1410 | "MemoryAllocationFailed","`%s'",module_info->tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1411 | return(module_info); |
| 1412 | } |
| 1413 | |
| 1414 | /* |
| 1415 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1416 | % % |
| 1417 | % % |
| 1418 | % % |
| 1419 | % T a g T o C o d e r M o d u l e N a m e % |
| 1420 | % % |
| 1421 | % % |
| 1422 | % % |
| 1423 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1424 | % |
| 1425 | % TagToCoderModuleName() munges a module tag and obtains the filename of the |
| 1426 | % corresponding module. |
| 1427 | % |
| 1428 | % The format of the TagToCoderModuleName module is: |
| 1429 | % |
| 1430 | % char *TagToCoderModuleName(const char *tag,char *name) |
| 1431 | % |
| 1432 | % A description of each parameter follows: |
| 1433 | % |
| 1434 | % o tag: a character string representing the module tag. |
| 1435 | % |
| 1436 | % o name: return the module name here. |
| 1437 | % |
| 1438 | */ |
| 1439 | static void TagToCoderModuleName(const char *tag,char *name) |
| 1440 | { |
| 1441 | assert(tag != (char *) NULL); |
| 1442 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag); |
| 1443 | assert(name != (char *) NULL); |
| 1444 | #if defined(MAGICKCORE_LTDL_DELEGATE) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1445 | (void) FormatLocaleString(name,MaxTextExtent,"%s.la",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1446 | (void) LocaleLower(name); |
| 1447 | #else |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 1448 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1449 | if (LocaleNCompare("IM_MOD_",tag,7) == 0) |
| 1450 | (void) CopyMagickString(name,tag,MaxTextExtent); |
| 1451 | else |
| 1452 | { |
| 1453 | #if defined(_DEBUG) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1454 | (void) FormatLocaleString(name,MaxTextExtent,"IM_MOD_DB_%s_.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1455 | #else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1456 | (void) FormatLocaleString(name,MaxTextExtent,"IM_MOD_RL_%s_.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1457 | #endif |
| 1458 | } |
| 1459 | #endif |
| 1460 | #endif |
| 1461 | } |
| 1462 | |
| 1463 | /* |
| 1464 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1465 | % % |
| 1466 | % % |
| 1467 | % % |
| 1468 | % T a g T o F i l t e r M o d u l e N a m e % |
| 1469 | % % |
| 1470 | % % |
| 1471 | % % |
| 1472 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1473 | % |
| 1474 | % TagToFilterModuleName() munges a module tag and returns the filename of the |
| 1475 | % corresponding filter module. |
| 1476 | % |
| 1477 | % The format of the TagToFilterModuleName module is: |
| 1478 | % |
| 1479 | % void TagToFilterModuleName(const char *tag,char name) |
| 1480 | % |
| 1481 | % A description of each parameter follows: |
| 1482 | % |
| 1483 | % o tag: a character string representing the module tag. |
| 1484 | % |
| 1485 | % o name: return the filter name here. |
| 1486 | % |
| 1487 | */ |
| 1488 | static void TagToFilterModuleName(const char *tag,char *name) |
| 1489 | { |
| 1490 | assert(tag != (char *) NULL); |
| 1491 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag); |
| 1492 | assert(name != (char *) NULL); |
| 1493 | #if !defined(MAGICKCORE_LTDL_DELEGATE) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1494 | (void) FormatLocaleString(name,MaxTextExtent,"%s.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1495 | #else |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1496 | (void) FormatLocaleString(name,MaxTextExtent,"%s.la",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1497 | #endif |
| 1498 | } |
| 1499 | |
| 1500 | /* |
| 1501 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1502 | % % |
| 1503 | % % |
| 1504 | % % |
| 1505 | % T a g T o M o d u l e N a m e % |
| 1506 | % % |
| 1507 | % % |
| 1508 | % % |
| 1509 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1510 | % |
| 1511 | % TagToModuleName() munges the module tag name and returns an upper-case tag |
| 1512 | % name as the input string, and a user-provided format. |
| 1513 | % |
| 1514 | % The format of the TagToModuleName module is: |
| 1515 | % |
| 1516 | % TagToModuleName(const char *tag,const char *format,char *module) |
| 1517 | % |
| 1518 | % A description of each parameter follows: |
| 1519 | % |
| 1520 | % o tag: the module tag. |
| 1521 | % |
| 1522 | % o format: a sprintf-compatible format string containing %s where the |
| 1523 | % upper-case tag name is to be inserted. |
| 1524 | % |
| 1525 | % o module: pointer to a destination buffer for the formatted result. |
| 1526 | % |
| 1527 | */ |
| 1528 | static void TagToModuleName(const char *tag,const char *format,char *module) |
| 1529 | { |
| 1530 | char |
| 1531 | name[MaxTextExtent]; |
| 1532 | |
| 1533 | assert(tag != (const char *) NULL); |
| 1534 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag); |
| 1535 | assert(format != (const char *) NULL); |
| 1536 | assert(module != (char *) NULL); |
| 1537 | (void) CopyMagickString(name,tag,MaxTextExtent); |
| 1538 | LocaleUpper(name); |
| 1539 | #if !defined(MAGICKCORE_NAMESPACE_PREFIX) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1540 | (void) FormatLocaleString(module,MaxTextExtent,format,name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1541 | #else |
| 1542 | { |
| 1543 | char |
| 1544 | prefix_format[MaxTextExtent]; |
| 1545 | |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1546 | (void) FormatLocaleString(prefix_format,MaxTextExtent,"%s%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1547 | MAGICKCORE_NAMESPACE_PREFIX,format); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1548 | (void) FormatLocaleString(module,MaxTextExtent,prefix_format,name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1549 | } |
| 1550 | #endif |
| 1551 | } |
| 1552 | |
| 1553 | /* |
| 1554 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1555 | % % |
| 1556 | % % |
| 1557 | % % |
| 1558 | % U n r e g i s t e r M o d u l e % |
| 1559 | % % |
| 1560 | % % |
| 1561 | % % |
| 1562 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1563 | % |
| 1564 | % UnregisterModule() unloads a module, and invokes its de-registration module. |
| 1565 | % Returns MagickTrue on success, and MagickFalse if there is an error. |
| 1566 | % |
| 1567 | % The format of the UnregisterModule module is: |
| 1568 | % |
| 1569 | % MagickBooleanType UnregisterModule(const ModuleInfo *module_info, |
| 1570 | % ExceptionInfo *exception) |
| 1571 | % |
| 1572 | % A description of each parameter follows: |
| 1573 | % |
| 1574 | % o module_info: the module info. |
| 1575 | % |
| 1576 | % o exception: return any errors or warnings in this structure. |
| 1577 | % |
| 1578 | */ |
| 1579 | static MagickBooleanType UnregisterModule(const ModuleInfo *module_info, |
| 1580 | ExceptionInfo *exception) |
| 1581 | { |
| 1582 | /* |
| 1583 | Locate and execute UnregisterFORMATImage module. |
| 1584 | */ |
| 1585 | assert(module_info != (const ModuleInfo *) NULL); |
| 1586 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag); |
| 1587 | assert(exception != (ExceptionInfo *) NULL); |
| 1588 | if (module_info->unregister_module == NULL) |
| 1589 | return(MagickTrue); |
| 1590 | module_info->unregister_module(); |
| 1591 | if (lt_dlclose((ModuleHandle) module_info->handle) != 0) |
| 1592 | { |
| 1593 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1594 | "UnableToCloseModule","'%s': %s",module_info->tag,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1595 | return(MagickFalse); |
| 1596 | } |
| 1597 | return(MagickTrue); |
| 1598 | } |
| 1599 | #else |
dirk | 143157c | 2014-03-01 10:16:38 +0000 | [diff] [blame] | 1600 | |
| 1601 | #if !defined(MAGICKCORE_BUILD_MODULES) |
| 1602 | extern size_t |
| 1603 | analyzeImage(Image **,const int,const char **,ExceptionInfo *); |
| 1604 | #endif |
| 1605 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1606 | MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file), |
| 1607 | ExceptionInfo *magick_unused(exception)) |
| 1608 | { |
| 1609 | return(MagickTrue); |
| 1610 | } |
| 1611 | |
| 1612 | MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag, |
| 1613 | Image **image,const int argc,const char **argv,ExceptionInfo *exception) |
| 1614 | { |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1615 | PolicyRights |
| 1616 | rights; |
| 1617 | |
| 1618 | assert(image != (Image **) NULL); |
| 1619 | assert((*image)->signature == MagickSignature); |
| 1620 | if ((*image)->debug != MagickFalse) |
| 1621 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename); |
| 1622 | rights=ReadPolicyRights; |
| 1623 | if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse) |
| 1624 | { |
| 1625 | errno=EPERM; |
| 1626 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1627 | "NotAuthorized","`%s'",tag); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1628 | return(MagickFalse); |
| 1629 | } |
| 1630 | #if defined(MAGICKCORE_BUILD_MODULES) |
| 1631 | (void) tag; |
| 1632 | (void) argc; |
| 1633 | (void) argv; |
| 1634 | (void) exception; |
| 1635 | #else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1636 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1637 | ImageFilterHandler |
| 1638 | *image_filter; |
| 1639 | |
| 1640 | image_filter=(ImageFilterHandler *) NULL; |
| 1641 | if (LocaleCompare("analyze",tag) == 0) |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1642 | image_filter=(ImageFilterHandler *) analyzeImage; |
| 1643 | if (image_filter == (ImageFilterHandler *) NULL) |
| 1644 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1645 | "UnableToLoadModule","`%s'",tag); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1646 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1647 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1648 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1649 | signature; |
| 1650 | |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1651 | if ((*image)->debug != MagickFalse) |
| 1652 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 1653 | "Invoking \"%s\" static image filter",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1654 | signature=image_filter(image,argc,argv,exception); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1655 | if ((*image)->debug != MagickFalse) |
| 1656 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"\"%s\" completes", |
| 1657 | tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1658 | if (signature != MagickImageFilterSignature) |
| 1659 | { |
| 1660 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1661 | "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag, |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1662 | (unsigned long) signature,(unsigned long) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1663 | MagickImageFilterSignature); |
| 1664 | return(MagickFalse); |
| 1665 | } |
| 1666 | } |
| 1667 | } |
| 1668 | #endif |
| 1669 | return(MagickTrue); |
| 1670 | } |
| 1671 | #endif |