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 | 7ce65e7 | 2015-12-12 18:03:16 -0500 | [diff] [blame] | 20 | % Copyright 1999-2016 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 | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 771 | (void) ConcatenateMagickString(path,DirectorySeparator, |
| 772 | MagickPathExtent); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 773 | (void) ConcatenateMagickString(path,filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 774 | if (IsPathAccessible(path) != MagickFalse) |
| 775 | return(MagickTrue); |
| 776 | } |
| 777 | } |
| 778 | #endif |
| 779 | { |
| 780 | char |
| 781 | *home; |
| 782 | |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 783 | home=GetEnvironmentValue("XDG_CONFIG_HOME"); |
Cristy | 1dd96da | 2015-10-06 07:52:01 -0400 | [diff] [blame] | 784 | if (home == (char *) NULL) |
| 785 | home=GetEnvironmentValue("LOCALAPPDATA"); |
| 786 | if (home == (char *) NULL) |
| 787 | home=GetEnvironmentValue("APPDATA"); |
| 788 | if (home == (char *) NULL) |
| 789 | home=GetEnvironmentValue("USERPROFILE"); |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 790 | if (home != (char *) NULL) |
Cristy | 1dd96da | 2015-10-06 07:52:01 -0400 | [diff] [blame] | 791 | { |
Cristy | 9799a84 | 2015-10-04 19:44:36 -0400 | [diff] [blame] | 792 | /* |
| 793 | Search $XDG_CONFIG_HOME/ImageMagick. |
| 794 | */ |
| 795 | (void) FormatLocaleString(path,MaxTextExtent,"%s%sImageMagick%s%s", |
| 796 | home,DirectorySeparator,DirectorySeparator,filename); |
| 797 | home=DestroyString(home); |
| 798 | if (IsPathAccessible(path) != MagickFalse) |
| 799 | return(MagickTrue); |
| 800 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 801 | home=GetEnvironmentValue("HOME"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 802 | if (home != (char *) NULL) |
| 803 | { |
| 804 | /* |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 805 | Search $HOME/.config/ImageMagick. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 806 | */ |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 807 | (void) FormatLocaleString(path,MagickPathExtent, |
cristy | 9f3b4fc | 2014-02-08 14:56:20 +0000 | [diff] [blame] | 808 | "%s%s.config%sImageMagick%s%s",home,DirectorySeparator, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 809 | DirectorySeparator,DirectorySeparator,filename); |
| 810 | home=DestroyString(home); |
| 811 | if (IsPathAccessible(path) != MagickFalse) |
| 812 | return(MagickTrue); |
| 813 | } |
| 814 | } |
| 815 | /* |
| 816 | Search current directory. |
| 817 | */ |
| 818 | if (IsPathAccessible(path) != MagickFalse) |
| 819 | return(MagickTrue); |
| 820 | if (exception->severity < ConfigureError) |
| 821 | ThrowFileException(exception,ConfigureWarning,"UnableToOpenModuleFile", |
| 822 | path); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 823 | #endif |
| 824 | return(MagickFalse); |
| 825 | } |
| 826 | |
| 827 | /* |
| 828 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 829 | % % |
| 830 | % % |
| 831 | % % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 832 | % 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] | 833 | % % |
| 834 | % % |
| 835 | % % |
| 836 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 837 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 838 | % IsModuleTreeInstantiated() determines if the module tree is instantiated. |
| 839 | % If not, it instantiates the tree and returns it. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 840 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 841 | % The format of the IsModuleTreeInstantiated() method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 842 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 843 | % IsModuleTreeInstantiated(Exceptioninfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 844 | % |
| 845 | % A description of each parameter follows. |
| 846 | % |
| 847 | % o exception: return any errors or warnings in this structure. |
| 848 | % |
| 849 | */ |
| 850 | |
| 851 | static void *DestroyModuleNode(void *module_info) |
| 852 | { |
| 853 | ExceptionInfo |
| 854 | *exception; |
| 855 | |
| 856 | register ModuleInfo |
| 857 | *p; |
| 858 | |
| 859 | exception=AcquireExceptionInfo(); |
| 860 | p=(ModuleInfo *) module_info; |
| 861 | if (UnregisterModule(p,exception) == MagickFalse) |
| 862 | CatchException(exception); |
| 863 | if (p->tag != (char *) NULL) |
| 864 | p->tag=DestroyString(p->tag); |
| 865 | if (p->path != (char *) NULL) |
| 866 | p->path=DestroyString(p->path); |
| 867 | exception=DestroyExceptionInfo(exception); |
| 868 | return(RelinquishMagickMemory(p)); |
| 869 | } |
| 870 | |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 871 | static MagickBooleanType IsModuleTreeInstantiated( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 872 | ExceptionInfo *magick_unused(exception)) |
| 873 | { |
cristy | 1460f26 | 2014-03-15 17:38:05 +0000 | [diff] [blame] | 874 | if (module_list == (SplayTreeInfo *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 875 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 876 | if (module_semaphore == (SemaphoreInfo *) NULL) |
| 877 | ActivateSemaphoreInfo(&module_semaphore); |
| 878 | LockSemaphoreInfo(module_semaphore); |
cristy | 1460f26 | 2014-03-15 17:38:05 +0000 | [diff] [blame] | 879 | if (module_list == (SplayTreeInfo *) NULL) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 880 | { |
| 881 | MagickBooleanType |
| 882 | status; |
| 883 | |
| 884 | ModuleInfo |
| 885 | *module_info; |
| 886 | |
| 887 | module_list=NewSplayTree(CompareSplayTreeString, |
| 888 | (void *(*)(void *)) NULL,DestroyModuleNode); |
| 889 | if (module_list == (SplayTreeInfo *) NULL) |
| 890 | ThrowFatalException(ResourceLimitFatalError, |
| 891 | "MemoryAllocationFailed"); |
| 892 | module_info=AcquireModuleInfo((const char *) NULL,"[boot-strap]"); |
| 893 | module_info->stealth=MagickTrue; |
| 894 | status=AddValueToSplayTree(module_list,module_info->tag,module_info); |
| 895 | if (status == MagickFalse) |
| 896 | ThrowFatalException(ResourceLimitFatalError, |
| 897 | "MemoryAllocationFailed"); |
| 898 | if (lt_dlinit() != 0) |
| 899 | ThrowFatalException(ModuleFatalError, |
| 900 | "UnableToInitializeModuleLoader"); |
| 901 | } |
| 902 | UnlockSemaphoreInfo(module_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 903 | } |
| 904 | return(module_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); |
| 905 | } |
| 906 | |
| 907 | /* |
| 908 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 909 | % % |
| 910 | % % |
| 911 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 912 | % I n v o k e D y n a m i c I m a g e F i l t e r % |
| 913 | % % |
| 914 | % % |
| 915 | % % |
| 916 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 917 | % |
| 918 | % InvokeDynamicImageFilter() invokes a dynamic image filter. |
| 919 | % |
| 920 | % The format of the InvokeDynamicImageFilter module is: |
| 921 | % |
| 922 | % MagickBooleanType InvokeDynamicImageFilter(const char *tag,Image **image, |
| 923 | % const int argc,const char **argv,ExceptionInfo *exception) |
| 924 | % |
| 925 | % A description of each parameter follows: |
| 926 | % |
| 927 | % o tag: a character string that represents the name of the particular |
| 928 | % module. |
| 929 | % |
| 930 | % o image: the image. |
| 931 | % |
| 932 | % o argc: a pointer to an integer describing the number of elements in the |
| 933 | % argument vector. |
| 934 | % |
| 935 | % o argv: a pointer to a text array containing the command line arguments. |
| 936 | % |
| 937 | % o exception: return any errors or warnings in this structure. |
| 938 | % |
| 939 | */ |
| 940 | MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag, |
| 941 | Image **images,const int argc,const char **argv,ExceptionInfo *exception) |
| 942 | { |
| 943 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 944 | name[MagickPathExtent], |
| 945 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 946 | |
| 947 | ImageFilterHandler |
| 948 | *image_filter; |
| 949 | |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 950 | MagickBooleanType |
| 951 | status; |
| 952 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 953 | ModuleHandle |
| 954 | handle; |
| 955 | |
| 956 | PolicyRights |
| 957 | rights; |
| 958 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 959 | /* |
| 960 | Find the module. |
| 961 | */ |
| 962 | assert(images != (Image **) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 963 | assert((*images)->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 964 | if ((*images)->debug != MagickFalse) |
| 965 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", |
| 966 | (*images)->filename); |
| 967 | #if !defined(MAGICKCORE_BUILD_MODULES) |
| 968 | { |
| 969 | MagickBooleanType |
| 970 | status; |
| 971 | |
| 972 | status=InvokeStaticImageFilter(tag,images,argc,argv,exception); |
| 973 | if (status != MagickFalse) |
| 974 | return(status); |
| 975 | } |
| 976 | #endif |
| 977 | rights=ReadPolicyRights; |
| 978 | if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse) |
| 979 | { |
cristy | a9197f6 | 2010-01-12 02:23:34 +0000 | [diff] [blame] | 980 | errno=EPERM; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 981 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 982 | "NotAuthorized","`%s'",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 983 | return(MagickFalse); |
| 984 | } |
| 985 | TagToFilterModuleName(tag,name); |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 986 | status=GetMagickModulePath(name,MagickImageFilterModule,path,exception); |
| 987 | if (status == MagickFalse) |
| 988 | { |
| 989 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 990 | "UnableToLoadModule","'%s': %s",name,path); |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 991 | return(MagickFalse); |
| 992 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 993 | /* |
| 994 | Open the module. |
| 995 | */ |
| 996 | handle=(ModuleHandle) lt_dlopen(path); |
| 997 | if (handle == (ModuleHandle) NULL) |
| 998 | { |
| 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 | return(MagickFalse); |
| 1002 | } |
| 1003 | /* |
| 1004 | Locate the module. |
| 1005 | */ |
| 1006 | #if !defined(MAGICKCORE_NAMESPACE_PREFIX) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1007 | (void) FormatLocaleString(name,MagickPathExtent,"%sImage",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1008 | #else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1009 | (void) FormatLocaleString(name,MagickPathExtent,"%s%sImage", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1010 | MAGICKCORE_NAMESPACE_PREFIX,tag); |
| 1011 | #endif |
| 1012 | /* |
| 1013 | Execute the module. |
| 1014 | */ |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1015 | ClearMagickException(exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1016 | image_filter=(ImageFilterHandler *) lt_dlsym(handle,name); |
| 1017 | if (image_filter == (ImageFilterHandler *) NULL) |
| 1018 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1019 | "UnableToLoadModule","'%s': %s",name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1020 | else |
| 1021 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1022 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1023 | signature; |
| 1024 | |
| 1025 | if ((*images)->debug != MagickFalse) |
| 1026 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1027 | "Invoking \"%s\" dynamic image filter",tag); |
| 1028 | signature=image_filter(images,argc,argv,exception); |
| 1029 | if ((*images)->debug != MagickFalse) |
| 1030 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(),"\"%s\" completes", |
| 1031 | tag); |
| 1032 | if (signature != MagickImageFilterSignature) |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1033 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1034 | "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag, |
cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 1035 | (unsigned long) signature,(unsigned long) MagickImageFilterSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1036 | } |
| 1037 | /* |
| 1038 | Close the module. |
| 1039 | */ |
| 1040 | if (lt_dlclose(handle) != 0) |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1041 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1042 | "UnableToCloseModule","'%s': %s",name,lt_dlerror()); |
cristy | fe12d6c | 2010-05-07 01:38:41 +0000 | [diff] [blame] | 1043 | return(exception->severity < ErrorException ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /* |
| 1047 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1048 | % % |
| 1049 | % % |
| 1050 | % % |
| 1051 | % L i s t M o d u l e I n f o % |
| 1052 | % % |
| 1053 | % % |
| 1054 | % % |
| 1055 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1056 | % |
| 1057 | % ListModuleInfo() lists the module info to a file. |
| 1058 | % |
| 1059 | % The format of the ListModuleInfo module is: |
| 1060 | % |
| 1061 | % MagickBooleanType ListModuleInfo(FILE *file,ExceptionInfo *exception) |
| 1062 | % |
| 1063 | % A description of each parameter follows. |
| 1064 | % |
| 1065 | % o file: An pointer to a FILE. |
| 1066 | % |
| 1067 | % o exception: return any errors or warnings in this structure. |
| 1068 | % |
| 1069 | */ |
| 1070 | MagickExport MagickBooleanType ListModuleInfo(FILE *file, |
| 1071 | ExceptionInfo *exception) |
| 1072 | { |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1073 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1074 | filename[MagickPathExtent], |
| 1075 | module_path[MagickPathExtent], |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1076 | **modules, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1077 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1078 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1079 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1080 | i; |
| 1081 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1082 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1083 | number_modules; |
| 1084 | |
| 1085 | if (file == (const FILE *) NULL) |
| 1086 | file=stdout; |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1087 | /* |
| 1088 | List image coders. |
| 1089 | */ |
| 1090 | modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception); |
| 1091 | if (modules == (char **) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1092 | return(MagickFalse); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1093 | TagToCoderModuleName("magick",filename); |
| 1094 | (void) GetMagickModulePath(filename,MagickImageCoderModule,module_path, |
| 1095 | exception); |
| 1096 | GetPathComponent(module_path,HeadPath,path); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1097 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",path); |
| 1098 | (void) FormatLocaleFile(file,"Image Coder\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1099 | (void) FormatLocaleFile(file, |
| 1100 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1101 | "------------------------------\n"); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1102 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1103 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1104 | (void) FormatLocaleFile(file,"%s",modules[i]); |
| 1105 | (void) FormatLocaleFile(file,"\n"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1106 | } |
| 1107 | (void) fflush(file); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1108 | /* |
| 1109 | Relinquish resources. |
| 1110 | */ |
| 1111 | for (i=0; i < (ssize_t) number_modules; i++) |
| 1112 | modules[i]=DestroyString(modules[i]); |
| 1113 | modules=(char **) RelinquishMagickMemory(modules); |
| 1114 | /* |
| 1115 | List image filters. |
| 1116 | */ |
| 1117 | modules=GetModuleList("*",MagickImageFilterModule,&number_modules,exception); |
| 1118 | if (modules == (char **) NULL) |
| 1119 | return(MagickFalse); |
| 1120 | TagToFilterModuleName("analyze",filename); |
| 1121 | (void) GetMagickModulePath(filename,MagickImageFilterModule,module_path, |
| 1122 | exception); |
| 1123 | GetPathComponent(module_path,HeadPath,path); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1124 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",path); |
| 1125 | (void) FormatLocaleFile(file,"Image Filter\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1126 | (void) FormatLocaleFile(file, |
| 1127 | "-------------------------------------------------" |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1128 | "------------------------------\n"); |
| 1129 | for (i=0; i < (ssize_t) number_modules; i++) |
| 1130 | { |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1131 | (void) FormatLocaleFile(file,"%s",modules[i]); |
| 1132 | (void) FormatLocaleFile(file,"\n"); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1133 | } |
| 1134 | (void) fflush(file); |
| 1135 | /* |
| 1136 | Relinquish resources. |
| 1137 | */ |
| 1138 | for (i=0; i < (ssize_t) number_modules; i++) |
| 1139 | modules[i]=DestroyString(modules[i]); |
| 1140 | modules=(char **) RelinquishMagickMemory(modules); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1141 | return(MagickTrue); |
| 1142 | } |
| 1143 | |
| 1144 | /* |
| 1145 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1146 | % % |
| 1147 | % % |
| 1148 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1149 | + M o d u l e C o m p o n e n t G e n e s i s % |
| 1150 | % % |
| 1151 | % % |
| 1152 | % % |
| 1153 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1154 | % |
| 1155 | % ModuleComponentGenesis() instantiates the module component. |
| 1156 | % |
| 1157 | % The format of the ModuleComponentGenesis method is: |
| 1158 | % |
| 1159 | % MagickBooleanType ModuleComponentGenesis(void) |
| 1160 | % |
| 1161 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1162 | MagickPrivate MagickBooleanType ModuleComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1163 | { |
| 1164 | ExceptionInfo |
| 1165 | *exception; |
| 1166 | |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1167 | MagickBooleanType |
| 1168 | status; |
| 1169 | |
cristy | 7c97706 | 2014-04-04 14:05:53 +0000 | [diff] [blame] | 1170 | if (module_semaphore == (SemaphoreInfo *) NULL) |
| 1171 | module_semaphore=AcquireSemaphoreInfo(); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1172 | exception=AcquireExceptionInfo(); |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 1173 | status=IsModuleTreeInstantiated(exception); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1174 | exception=DestroyExceptionInfo(exception); |
cristy | cee9711 | 2010-05-28 00:44:52 +0000 | [diff] [blame] | 1175 | return(status); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1176 | } |
| 1177 | |
| 1178 | /* |
| 1179 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1180 | % % |
| 1181 | % % |
| 1182 | % % |
| 1183 | + M o d u l e C o m p o n e n t T e r m i n u s % |
| 1184 | % % |
| 1185 | % % |
| 1186 | % % |
| 1187 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1188 | % |
| 1189 | % ModuleComponentTerminus() destroys the module component. |
| 1190 | % |
| 1191 | % The format of the ModuleComponentTerminus method is: |
| 1192 | % |
| 1193 | % ModuleComponentTerminus(void) |
| 1194 | % |
| 1195 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 1196 | MagickPrivate void ModuleComponentTerminus(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1197 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 1198 | if (module_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 1199 | ActivateSemaphoreInfo(&module_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1200 | DestroyModuleList(); |
cristy | 3d162a9 | 2014-02-16 14:05:06 +0000 | [diff] [blame] | 1201 | RelinquishSemaphoreInfo(&module_semaphore); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 1202 | } |
| 1203 | |
| 1204 | /* |
| 1205 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1206 | % % |
| 1207 | % % |
| 1208 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1209 | % O p e n M o d u l e % |
| 1210 | % % |
| 1211 | % % |
| 1212 | % % |
| 1213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1214 | % |
| 1215 | % OpenModule() loads a module, and invokes its registration module. It |
| 1216 | % returns MagickTrue on success, and MagickFalse if there is an error. |
| 1217 | % |
| 1218 | % The format of the OpenModule module is: |
| 1219 | % |
| 1220 | % MagickBooleanType OpenModule(const char *module,ExceptionInfo *exception) |
| 1221 | % |
| 1222 | % A description of each parameter follows: |
| 1223 | % |
| 1224 | % o module: a character string that indicates the module to load. |
| 1225 | % |
| 1226 | % o exception: return any errors or warnings in this structure. |
| 1227 | % |
| 1228 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1229 | MagickPrivate MagickBooleanType OpenModule(const char *module, |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1230 | ExceptionInfo *exception) |
| 1231 | { |
| 1232 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1233 | filename[MagickPathExtent], |
| 1234 | module_name[MagickPathExtent], |
| 1235 | name[MagickPathExtent], |
| 1236 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1237 | |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 1238 | MagickBooleanType |
| 1239 | status; |
| 1240 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1241 | ModuleHandle |
| 1242 | handle; |
| 1243 | |
| 1244 | ModuleInfo |
| 1245 | *module_info; |
| 1246 | |
| 1247 | register const CoderInfo |
| 1248 | *p; |
| 1249 | |
| 1250 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1251 | signature; |
| 1252 | |
| 1253 | /* |
| 1254 | Assign module name from alias. |
| 1255 | */ |
| 1256 | assert(module != (const char *) NULL); |
| 1257 | module_info=(ModuleInfo *) GetModuleInfo(module,exception); |
| 1258 | if (module_info != (ModuleInfo *) NULL) |
| 1259 | return(MagickTrue); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1260 | (void) CopyMagickString(module_name,module,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1261 | p=GetCoderInfo(module,exception); |
| 1262 | if (p != (CoderInfo *) NULL) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1263 | (void) CopyMagickString(module_name,p->name,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1264 | if (GetValueFromSplayTree(module_list,module_name) != (void *) NULL) |
| 1265 | return(MagickTrue); /* module already opened, return */ |
| 1266 | /* |
| 1267 | Locate module. |
| 1268 | */ |
| 1269 | handle=(ModuleHandle) NULL; |
| 1270 | TagToCoderModuleName(module_name,filename); |
| 1271 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1272 | "Searching for module \"%s\" using filename \"%s\"",module_name,filename); |
| 1273 | *path='\0'; |
cristy | d1df72d | 2010-06-29 02:17:03 +0000 | [diff] [blame] | 1274 | status=GetMagickModulePath(filename,MagickImageCoderModule,path,exception); |
| 1275 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1276 | return(MagickFalse); |
| 1277 | /* |
| 1278 | Load module |
| 1279 | */ |
| 1280 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1281 | "Opening module at path \"%s\"",path); |
| 1282 | handle=(ModuleHandle) lt_dlopen(path); |
| 1283 | if (handle == (ModuleHandle) NULL) |
| 1284 | { |
| 1285 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1286 | "UnableToLoadModule","'%s': %s",path,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1287 | return(MagickFalse); |
| 1288 | } |
| 1289 | /* |
| 1290 | Register module. |
| 1291 | */ |
| 1292 | module_info=AcquireModuleInfo(path,module_name); |
| 1293 | module_info->handle=handle; |
| 1294 | if (RegisterModule(module_info,exception) == (ModuleInfo *) NULL) |
| 1295 | return(MagickFalse); |
| 1296 | /* |
| 1297 | Define RegisterFORMATImage method. |
| 1298 | */ |
| 1299 | TagToModuleName(module_name,"Register%sImage",name); |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1300 | module_info->register_module=(size_t (*)(void)) lt_dlsym(handle,name); |
| 1301 | if (module_info->register_module == (size_t (*)(void)) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1302 | { |
| 1303 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1304 | "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1305 | return(MagickFalse); |
| 1306 | } |
| 1307 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1308 | "Method \"%s\" in module \"%s\" at address %p",name,module_name, |
| 1309 | (void *) module_info->register_module); |
| 1310 | /* |
| 1311 | Define UnregisterFORMATImage method. |
| 1312 | */ |
| 1313 | TagToModuleName(module_name,"Unregister%sImage",name); |
| 1314 | module_info->unregister_module=(void (*)(void)) lt_dlsym(handle,name); |
| 1315 | if (module_info->unregister_module == (void (*)(void)) NULL) |
| 1316 | { |
| 1317 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1318 | "UnableToRegisterImageFormat","'%s': %s",module_name,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1319 | return(MagickFalse); |
| 1320 | } |
| 1321 | (void) LogMagickEvent(ModuleEvent,GetMagickModule(), |
| 1322 | "Method \"%s\" in module \"%s\" at address %p",name,module_name, |
| 1323 | (void *) module_info->unregister_module); |
| 1324 | signature=module_info->register_module(); |
| 1325 | if (signature != MagickImageCoderSignature) |
| 1326 | { |
| 1327 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1328 | "ImageCoderSignatureMismatch","'%s': %8lx != %8lx",module_name, |
cristy | f1d9124 | 2010-05-28 02:23:19 +0000 | [diff] [blame] | 1329 | (unsigned long) signature,(unsigned long) MagickImageCoderSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1330 | return(MagickFalse); |
| 1331 | } |
| 1332 | return(MagickTrue); |
| 1333 | } |
| 1334 | |
| 1335 | /* |
| 1336 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1337 | % % |
| 1338 | % % |
| 1339 | % % |
| 1340 | % O p e n M o d u l e s % |
| 1341 | % % |
| 1342 | % % |
| 1343 | % % |
| 1344 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1345 | % |
| 1346 | % OpenModules() loads all available modules. |
| 1347 | % |
| 1348 | % The format of the OpenModules module is: |
| 1349 | % |
| 1350 | % MagickBooleanType OpenModules(ExceptionInfo *exception) |
| 1351 | % |
| 1352 | % A description of each parameter follows: |
| 1353 | % |
| 1354 | % o exception: return any errors or warnings in this structure. |
| 1355 | % |
| 1356 | */ |
cristy | 7832dc2 | 2011-09-05 01:21:53 +0000 | [diff] [blame] | 1357 | MagickPrivate MagickBooleanType OpenModules(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1358 | { |
| 1359 | char |
| 1360 | **modules; |
| 1361 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1362 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1363 | i; |
| 1364 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1365 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1366 | number_modules; |
| 1367 | |
| 1368 | /* |
| 1369 | Load all modules. |
| 1370 | */ |
| 1371 | (void) GetMagickInfo((char *) NULL,exception); |
| 1372 | number_modules=0; |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1373 | modules=GetModuleList("*",MagickImageCoderModule,&number_modules,exception); |
Cristy | 2664501 | 2015-08-23 20:24:30 -0400 | [diff] [blame] | 1374 | if ((modules == (char **) NULL) || (*modules == (char *) NULL)) |
Cristy | 6ffac4f | 2015-08-23 10:55:57 -0400 | [diff] [blame] | 1375 | { |
Cristy | 1dd96da | 2015-10-06 07:52:01 -0400 | [diff] [blame] | 1376 | if (modules != (char **) NULL) |
Cristy | 6ffac4f | 2015-08-23 10:55:57 -0400 | [diff] [blame] | 1377 | modules=(char **) RelinquishMagickMemory(modules); |
| 1378 | return(MagickFalse); |
| 1379 | } |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1380 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1381 | (void) OpenModule(modules[i],exception); |
| 1382 | /* |
| 1383 | Relinquish resources. |
| 1384 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1385 | for (i=0; i < (ssize_t) number_modules; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1386 | modules[i]=DestroyString(modules[i]); |
| 1387 | modules=(char **) RelinquishMagickMemory(modules); |
| 1388 | return(MagickTrue); |
| 1389 | } |
| 1390 | |
| 1391 | /* |
| 1392 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1393 | % % |
| 1394 | % % |
| 1395 | % % |
| 1396 | % R e g i s t e r M o d u l e % |
| 1397 | % % |
| 1398 | % % |
| 1399 | % % |
| 1400 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1401 | % |
| 1402 | % RegisterModule() adds an entry to the module list. It returns a pointer to |
| 1403 | % the registered entry on success. |
| 1404 | % |
| 1405 | % The format of the RegisterModule module is: |
| 1406 | % |
| 1407 | % ModuleInfo *RegisterModule(const ModuleInfo *module_info, |
| 1408 | % ExceptionInfo *exception) |
| 1409 | % |
| 1410 | % A description of each parameter follows: |
| 1411 | % |
| 1412 | % o info: a pointer to the registered entry is returned. |
| 1413 | % |
| 1414 | % o module_info: a pointer to the ModuleInfo structure to register. |
| 1415 | % |
| 1416 | % o exception: return any errors or warnings in this structure. |
| 1417 | % |
| 1418 | */ |
| 1419 | static const ModuleInfo *RegisterModule(const ModuleInfo *module_info, |
| 1420 | ExceptionInfo *exception) |
| 1421 | { |
| 1422 | MagickBooleanType |
| 1423 | status; |
| 1424 | |
| 1425 | assert(module_info != (ModuleInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1426 | assert(module_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1427 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag); |
| 1428 | if (module_list == (SplayTreeInfo *) NULL) |
| 1429 | return((const ModuleInfo *) NULL); |
| 1430 | status=AddValueToSplayTree(module_list,module_info->tag,module_info); |
| 1431 | if (status == MagickFalse) |
| 1432 | (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1433 | "MemoryAllocationFailed","`%s'",module_info->tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1434 | return(module_info); |
| 1435 | } |
| 1436 | |
| 1437 | /* |
| 1438 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1439 | % % |
| 1440 | % % |
| 1441 | % % |
| 1442 | % T a g T o C o d e r M o d u l e N a m e % |
| 1443 | % % |
| 1444 | % % |
| 1445 | % % |
| 1446 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1447 | % |
| 1448 | % TagToCoderModuleName() munges a module tag and obtains the filename of the |
| 1449 | % corresponding module. |
| 1450 | % |
| 1451 | % The format of the TagToCoderModuleName module is: |
| 1452 | % |
| 1453 | % char *TagToCoderModuleName(const char *tag,char *name) |
| 1454 | % |
| 1455 | % A description of each parameter follows: |
| 1456 | % |
| 1457 | % o tag: a character string representing the module tag. |
| 1458 | % |
| 1459 | % o name: return the module name here. |
| 1460 | % |
| 1461 | */ |
| 1462 | static void TagToCoderModuleName(const char *tag,char *name) |
| 1463 | { |
| 1464 | assert(tag != (char *) NULL); |
| 1465 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag); |
| 1466 | assert(name != (char *) NULL); |
| 1467 | #if defined(MAGICKCORE_LTDL_DELEGATE) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1468 | (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1469 | (void) LocaleLower(name); |
| 1470 | #else |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 1471 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1472 | if (LocaleNCompare("IM_MOD_",tag,7) == 0) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1473 | (void) CopyMagickString(name,tag,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1474 | else |
| 1475 | { |
| 1476 | #if defined(_DEBUG) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1477 | (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_DB_%s_.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1478 | #else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1479 | (void) FormatLocaleString(name,MagickPathExtent,"IM_MOD_RL_%s_.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1480 | #endif |
| 1481 | } |
| 1482 | #endif |
| 1483 | #endif |
| 1484 | } |
| 1485 | |
| 1486 | /* |
| 1487 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1488 | % % |
| 1489 | % % |
| 1490 | % % |
| 1491 | % T a g T o F i l t e r M o d u l e N a m e % |
| 1492 | % % |
| 1493 | % % |
| 1494 | % % |
| 1495 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1496 | % |
| 1497 | % TagToFilterModuleName() munges a module tag and returns the filename of the |
| 1498 | % corresponding filter module. |
| 1499 | % |
| 1500 | % The format of the TagToFilterModuleName module is: |
| 1501 | % |
| 1502 | % void TagToFilterModuleName(const char *tag,char name) |
| 1503 | % |
| 1504 | % A description of each parameter follows: |
| 1505 | % |
| 1506 | % o tag: a character string representing the module tag. |
| 1507 | % |
| 1508 | % o name: return the filter name here. |
| 1509 | % |
| 1510 | */ |
| 1511 | static void TagToFilterModuleName(const char *tag,char *name) |
| 1512 | { |
| 1513 | assert(tag != (char *) NULL); |
| 1514 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag); |
| 1515 | assert(name != (char *) NULL); |
dirk | 89fad7c | 2015-01-17 22:09:51 +0000 | [diff] [blame] | 1516 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1517 | (void) FormatLocaleString(name,MagickPathExtent,"FILTER_%s_.dll",tag); |
dirk | 89fad7c | 2015-01-17 22:09:51 +0000 | [diff] [blame] | 1518 | #elif !defined(MAGICKCORE_LTDL_DELEGATE) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1519 | (void) FormatLocaleString(name,MagickPathExtent,"%s.dll",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1520 | #else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1521 | (void) FormatLocaleString(name,MagickPathExtent,"%s.la",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1522 | #endif |
| 1523 | } |
| 1524 | |
| 1525 | /* |
| 1526 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1527 | % % |
| 1528 | % % |
| 1529 | % % |
| 1530 | % T a g T o M o d u l e N a m e % |
| 1531 | % % |
| 1532 | % % |
| 1533 | % % |
| 1534 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1535 | % |
| 1536 | % TagToModuleName() munges the module tag name and returns an upper-case tag |
| 1537 | % name as the input string, and a user-provided format. |
| 1538 | % |
| 1539 | % The format of the TagToModuleName module is: |
| 1540 | % |
| 1541 | % TagToModuleName(const char *tag,const char *format,char *module) |
| 1542 | % |
| 1543 | % A description of each parameter follows: |
| 1544 | % |
| 1545 | % o tag: the module tag. |
| 1546 | % |
| 1547 | % o format: a sprintf-compatible format string containing %s where the |
| 1548 | % upper-case tag name is to be inserted. |
| 1549 | % |
| 1550 | % o module: pointer to a destination buffer for the formatted result. |
| 1551 | % |
| 1552 | */ |
| 1553 | static void TagToModuleName(const char *tag,const char *format,char *module) |
| 1554 | { |
| 1555 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1556 | name[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1557 | |
| 1558 | assert(tag != (const char *) NULL); |
| 1559 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",tag); |
| 1560 | assert(format != (const char *) NULL); |
| 1561 | assert(module != (char *) NULL); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1562 | (void) CopyMagickString(name,tag,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1563 | LocaleUpper(name); |
| 1564 | #if !defined(MAGICKCORE_NAMESPACE_PREFIX) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1565 | (void) FormatLocaleString(module,MagickPathExtent,format,name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1566 | #else |
| 1567 | { |
| 1568 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1569 | prefix_format[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1570 | |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1571 | (void) FormatLocaleString(prefix_format,MagickPathExtent,"%s%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1572 | MAGICKCORE_NAMESPACE_PREFIX,format); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1573 | (void) FormatLocaleString(module,MagickPathExtent,prefix_format,name); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1574 | } |
| 1575 | #endif |
| 1576 | } |
| 1577 | |
| 1578 | /* |
| 1579 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1580 | % % |
| 1581 | % % |
| 1582 | % % |
| 1583 | % U n r e g i s t e r M o d u l e % |
| 1584 | % % |
| 1585 | % % |
| 1586 | % % |
| 1587 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1588 | % |
| 1589 | % UnregisterModule() unloads a module, and invokes its de-registration module. |
| 1590 | % Returns MagickTrue on success, and MagickFalse if there is an error. |
| 1591 | % |
| 1592 | % The format of the UnregisterModule module is: |
| 1593 | % |
| 1594 | % MagickBooleanType UnregisterModule(const ModuleInfo *module_info, |
| 1595 | % ExceptionInfo *exception) |
| 1596 | % |
| 1597 | % A description of each parameter follows: |
| 1598 | % |
| 1599 | % o module_info: the module info. |
| 1600 | % |
| 1601 | % o exception: return any errors or warnings in this structure. |
| 1602 | % |
| 1603 | */ |
| 1604 | static MagickBooleanType UnregisterModule(const ModuleInfo *module_info, |
| 1605 | ExceptionInfo *exception) |
| 1606 | { |
| 1607 | /* |
| 1608 | Locate and execute UnregisterFORMATImage module. |
| 1609 | */ |
| 1610 | assert(module_info != (const ModuleInfo *) NULL); |
| 1611 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",module_info->tag); |
| 1612 | assert(exception != (ExceptionInfo *) NULL); |
| 1613 | if (module_info->unregister_module == NULL) |
| 1614 | return(MagickTrue); |
| 1615 | module_info->unregister_module(); |
| 1616 | if (lt_dlclose((ModuleHandle) module_info->handle) != 0) |
| 1617 | { |
| 1618 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleWarning, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1619 | "UnableToCloseModule","'%s': %s",module_info->tag,lt_dlerror()); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1620 | return(MagickFalse); |
| 1621 | } |
| 1622 | return(MagickTrue); |
| 1623 | } |
| 1624 | #else |
dirk | 143157c | 2014-03-01 10:16:38 +0000 | [diff] [blame] | 1625 | |
| 1626 | #if !defined(MAGICKCORE_BUILD_MODULES) |
| 1627 | extern size_t |
| 1628 | analyzeImage(Image **,const int,const char **,ExceptionInfo *); |
| 1629 | #endif |
| 1630 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1631 | MagickExport MagickBooleanType ListModuleInfo(FILE *magick_unused(file), |
| 1632 | ExceptionInfo *magick_unused(exception)) |
| 1633 | { |
| 1634 | return(MagickTrue); |
| 1635 | } |
| 1636 | |
| 1637 | MagickExport MagickBooleanType InvokeDynamicImageFilter(const char *tag, |
| 1638 | Image **image,const int argc,const char **argv,ExceptionInfo *exception) |
| 1639 | { |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1640 | PolicyRights |
| 1641 | rights; |
| 1642 | |
| 1643 | assert(image != (Image **) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1644 | assert((*image)->signature == MagickCoreSignature); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1645 | if ((*image)->debug != MagickFalse) |
| 1646 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename); |
| 1647 | rights=ReadPolicyRights; |
| 1648 | if (IsRightsAuthorized(FilterPolicyDomain,rights,tag) == MagickFalse) |
| 1649 | { |
| 1650 | errno=EPERM; |
| 1651 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1652 | "NotAuthorized","`%s'",tag); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1653 | return(MagickFalse); |
| 1654 | } |
| 1655 | #if defined(MAGICKCORE_BUILD_MODULES) |
| 1656 | (void) tag; |
| 1657 | (void) argc; |
| 1658 | (void) argv; |
| 1659 | (void) exception; |
| 1660 | #else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1661 | { |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1662 | ImageFilterHandler |
| 1663 | *image_filter; |
| 1664 | |
| 1665 | image_filter=(ImageFilterHandler *) NULL; |
| 1666 | if (LocaleCompare("analyze",tag) == 0) |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1667 | image_filter=(ImageFilterHandler *) analyzeImage; |
| 1668 | if (image_filter == (ImageFilterHandler *) NULL) |
| 1669 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1670 | "UnableToLoadModule","`%s'",tag); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1671 | else |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1672 | { |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1673 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1674 | signature; |
| 1675 | |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1676 | if ((*image)->debug != MagickFalse) |
| 1677 | (void) LogMagickEvent(CoderEvent,GetMagickModule(), |
| 1678 | "Invoking \"%s\" static image filter",tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1679 | signature=image_filter(image,argc,argv,exception); |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1680 | if ((*image)->debug != MagickFalse) |
| 1681 | (void) LogMagickEvent(CoderEvent,GetMagickModule(),"\"%s\" completes", |
| 1682 | tag); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1683 | if (signature != MagickImageFilterSignature) |
| 1684 | { |
| 1685 | (void) ThrowMagickException(exception,GetMagickModule(),ModuleError, |
anthony | e5b3965 | 2012-04-21 05:37:29 +0000 | [diff] [blame] | 1686 | "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag, |
cristy | a6de29a | 2010-06-30 14:34:26 +0000 | [diff] [blame] | 1687 | (unsigned long) signature,(unsigned long) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1688 | MagickImageFilterSignature); |
| 1689 | return(MagickFalse); |
| 1690 | } |
| 1691 | } |
| 1692 | } |
| 1693 | #endif |
| 1694 | return(MagickTrue); |
| 1695 | } |
| 1696 | #endif |