MagickCore  7.1.0
static.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % SSSSS TTTTT AAA TTTTT IIIII CCCC %
7 % SS T A A T I C %
8 % SSS T AAAAA T I C %
9 % SS T A A T I C %
10 % SSSSS T A A T IIIII CCCC %
11 % %
12 % %
13 % MagickCore Static Methods %
14 % %
15 % Software Design %
16 % Cristy %
17 % March 2000 %
18 % %
19 % %
20 % Copyright 1999-2021 ImageMagick Studio LLC, a non-profit organization %
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 % https://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 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/coder.h"
46 #include "MagickCore/image.h"
47 #include "MagickCore/module.h"
48 #include "MagickCore/policy.h"
49 #include "MagickCore/static.h"
50 #include "MagickCore/string_.h"
51 #include "coders/coders.h"
52 
53 /*
54  Define declarations.
55 */
56 #define AddMagickCoder(coder) { #coder, MagickFalse, \
57  Register ## coder ## Image, Unregister ## coder ## Image },
58 
59 /*
60  ImageMagick module stub.
61 */
63 {
65 }
66 
68 {
69 }
70 
71 /*
72  ImageMagick modules.
73 */
74 static struct
75 {
76  const char
78 
81 
82  size_t
83  (*register_module)(void);
84 
85  void
87 } MagickModules[] = {
88 #if !defined(MAGICKCORE_BUILD_MODULES)
89  #include "coders/coders-list.h"
90 #endif
92 };
93 
94 /*
95 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
96 % %
97 % %
98 % %
99 % I n v o k e S t a t i c I m a g e F i l t e r %
100 % %
101 % %
102 % %
103 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
104 %
105 % InvokeStaticImageFilter() invokes a static image filter.
106 %
107 % The format of the InvokeStaticImageFilter method is:
108 %
109 % MagickBooleanType InvokeStaticImageFilter(const char *tag,Image **image,
110 % const int argc,const char **argv)
111 %
112 % A description of each parameter follows:
113 %
114 % o tag: the module tag.
115 %
116 % o image: the image.
117 %
118 % o argc: the number of elements in the argument vector.
119 %
120 % o argv: A text array containing the command line arguments.
121 %
122 % o argv: A text array containing the command line arguments.
123 %
124 % o exception: return any errors or warnings in this structure.
125 %
126 */
127 #if defined(MAGICKCORE_MODULES_SUPPORT)
129  Image **image,const int argc,const char **argv,ExceptionInfo *exception)
130 {
132  rights;
133 
134  assert(image != (Image **) NULL);
135  assert((*image)->signature == MagickCoreSignature);
136  if ((*image)->debug != MagickFalse)
137  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",(*image)->filename);
138  rights=ReadPolicyRights;
140  {
141  errno=EPERM;
143  "NotAuthorized","`%s'",tag);
144  return(MagickFalse);
145  }
146 #if defined(MAGICKCORE_MODULES_SUPPORT)
147  (void) tag;
148  (void) argc;
149  (void) argv;
150  (void) exception;
151 #else
152  {
153  extern size_t
154  analyzeImage(Image **,const int,char **,ExceptionInfo *);
155 
157  *image_filter;
158 
159  image_filter=(ImageFilterHandler *) NULL;
160  if (LocaleCompare("analyze",tag) == 0)
161  image_filter=(ImageFilterHandler *) analyzeImage;
162  if (image_filter == (ImageFilterHandler *) NULL)
164  "UnableToLoadModule","`%s'",tag);
165  else
166  {
167  size_t
168  signature;
169 
170  if ((*image)->debug != MagickFalse)
172  "Invoking \"%s\" static image filter",tag);
173  signature=image_filter(image,argc,argv,exception);
174  if ((*image)->debug != MagickFalse)
175  (void) LogMagickEvent(CoderEvent,GetMagickModule(),"\"%s\" completes",
176  tag);
178  {
180  "ImageFilterSignatureMismatch","'%s': %8lx != %8lx",tag,
181  (unsigned long) signature,(unsigned long)
183  return(MagickFalse);
184  }
185  }
186  }
187 #endif
188  return(MagickTrue);
189 }
190 #endif
191 
192 /*
193 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
194 % %
195 % %
196 % %
197 % R e g i s t e r S t a t i c M o d u l e %
198 % %
199 % %
200 % %
201 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
202 %
203 % RegisterStaticModule() statically registers a module.
204 %
205 % The format of the RegisterStaticModule method is:
206 %
207 % MagickBooleanType RegisterStaticModule(const char module,
208 % ExceptionInfo *exception)
209 %
210 % A description of each parameter follows:
211 %
212 % o module: the want to register.
213 %
214 % o exception: return any errors or warnings in this structure.
215 %
216 */
218  ExceptionInfo *exception)
219 {
220  char
221  module_name[MagickPathExtent];
222 
224  rights;
225 
226  const CoderInfo
227  *p;
228 
229  size_t
230  extent;
231 
232  ssize_t
233  i;
234 
235  /*
236  Assign module name from alias.
237  */
238  assert(module != (const char *) NULL);
239  (void) CopyMagickString(module_name,module,MagickPathExtent);
240  p=GetCoderInfo(module,exception);
241  if (p != (CoderInfo *) NULL)
242  (void) CopyMagickString(module_name,p->name,MagickPathExtent);
244  if (IsRightsAuthorized(ModulePolicyDomain,rights,module_name) == MagickFalse)
245  {
246  errno=EPERM;
248  "NotAuthorized","`%s'",module);
249  return(MagickFalse);
250  }
251  extent=sizeof(MagickModules)/sizeof(MagickModules[0]);
252  for (i=0; i < (ssize_t) extent; i++)
253  if (LocaleCompare(MagickModules[i].module,module_name) == 0)
254  {
256  {
257  (void) (MagickModules[i].register_module)();
258  MagickModules[i].registered=MagickTrue;
259  }
260  return(MagickTrue);
261  }
262  return(MagickFalse);
263 }
264 
265 /*
266 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
267 % %
268 % %
269 % %
270 % R e g i s t e r S t a t i c M o d u l e s %
271 % %
272 % %
273 % %
274 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
275 %
276 % RegisterStaticModules() statically registers all the available module
277 % handlers.
278 %
279 % The format of the RegisterStaticModules method is:
280 %
281 % (void) RegisterStaticModules(void)
282 %
283 */
285 {
287  rights;
288 
289  size_t
290  extent;
291 
292  ssize_t
293  i;
294 
296  extent=sizeof(MagickModules)/sizeof(MagickModules[0]);
297  for (i=0; i < (ssize_t) extent; i++)
298  {
300  {
303  continue;
304  (void) (MagickModules[i].register_module)();
305  MagickModules[i].registered=MagickTrue;
306  }
307  }
308 }
309 
310 /*
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 % %
313 % %
314 % %
315 % U n r e g i s t e r S t a t i c M o d u l e %
316 % %
317 % %
318 % %
319 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
320 %
321 % UnregisterStaticModule() statically unregisters the named module.
322 %
323 % The format of the UnregisterStaticModule method is:
324 %
325 % MagickBooleanType UnregisterStaticModule(const char *module)
326 %
327 % A description of each parameter follows:
328 %
329 % o module: the module we want to unregister.
330 %
331 */
333 {
334  size_t
335  extent;
336 
337  ssize_t
338  i;
339 
340  extent=sizeof(MagickModules)/sizeof(MagickModules[0]);
341  for (i=0; i < (ssize_t) extent; i++)
343  {
345  {
346  (MagickModules[i].unregister_module)();
347  MagickModules[i].registered=MagickFalse;
348  }
349  return(MagickTrue);
350  }
351  return(MagickFalse);
352 }
353 
354 /*
355 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
356 % %
357 % %
358 % %
359 % U n r e g i s t e r S t a t i c M o d u l e s %
360 % %
361 % %
362 % %
363 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
364 %
365 % UnregisterStaticModules() statically unregisters all the available module
366 % handlers.
367 %
368 % The format of the UnregisterStaticModules method is:
369 %
370 % UnregisterStaticModules(void)
371 %
372 */
374 {
375  size_t
376  extent;
377 
378  ssize_t
379  i;
380 
381  extent=sizeof(MagickModules)/sizeof(MagickModules[0]);
382  for (i=0; i < (ssize_t) extent; i++)
383  {
385  {
386  (MagickModules[i].unregister_module)();
387  MagickModules[i].registered=MagickFalse;
388  }
389  }
390 }
#define ModuleExport
MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, const PolicyRights rights, const char *pattern)
Definition: policy.c:620
MagickExport MagickBooleanType RegisterStaticModule(const char *module, ExceptionInfo *exception)
Definition: static.c:217
MagickExport void RegisterStaticModules(void)
Definition: static.c:284
PolicyRights
Definition: policy.h:41
#define MagickImageCoderSignature
Definition: module.h:27
MagickBooleanType registered
Definition: static.c:80
ModuleExport size_t RegisterUndefinedImage(void)
Definition: static.c:62
size_t signature
Definition: splay-tree.c:112
MagickExport size_t CopyMagickString(char *magick_restrict destination, const char *magick_restrict source, const size_t length)
Definition: string.c:731
size_t(* register_module)(void)
Definition: static.c:83
Definition: log.h:52
size_t ImageFilterHandler(Image **, const int, const char **, ExceptionInfo *)
Definition: module.h:62
Definition: image.h:151
MagickExport MagickBooleanType UnregisterStaticModule(const char *module)
Definition: static.c:332
#define MagickCoreSignature
#define MagickImageFilterSignature
Definition: module.h:29
MagickBooleanType
Definition: magick-type.h:165
ModuleExport void UnregisterUndefinedImage(void)
Definition: static.c:67
#define MagickPathExtent
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1145
const char * module
Definition: static.c:77
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1660
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1399
#define GetMagickModule()
Definition: log.h:28
MagickExport const CoderInfo * GetCoderInfo(const char *name, ExceptionInfo *exception)
Definition: coder.c:268
char * name
Definition: coder.h:28
MagickExport void UnregisterStaticModules(void)
Definition: static.c:373
size_t analyzeImage(Image **, const int, const char **, ExceptionInfo *)
#define MagickExport
void(* unregister_module)(void)
Definition: static.c:86
static struct @0 MagickModules[]
MagickExport MagickBooleanType InvokeStaticImageFilter(const char *, Image **, const int, const char **, ExceptionInfo *)
Definition: log.h:41