MagickCore  7.0.7
Convert, Edit, Or Compose Bitmap Images
registry.c
Go to the documentation of this file.
1 /*
2 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3 % %
4 % %
5 % %
6 % RRRR EEEEE GGG IIIII SSSSS TTTTT RRRR Y Y %
7 % R R E G I SS T R R Y Y %
8 % RRRR EEE G GGG I SSS T RRRR Y %
9 % R R E G G I SS T R R Y %
10 % R R EEEEE GGG IIIII SSSSS T R R Y %
11 % %
12 % %
13 % MagickCore Registry Methods %
14 % %
15 % Software Design %
16 % Cristy %
17 % March 2000 %
18 % %
19 % %
20 % Copyright 1999-2018 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://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 */
43 #include "MagickCore/studio.h"
44 #include "MagickCore/exception.h"
46 #include "MagickCore/image.h"
47 #include "MagickCore/list.h"
48 #include "MagickCore/memory_.h"
50 #include "MagickCore/registry.h"
52 #include "MagickCore/splay-tree.h"
53 #include "MagickCore/string_.h"
54 #include "MagickCore/utility.h"
55 
56 /*
57  Typedef declarations.
58 */
59 typedef struct _RegistryInfo
60 {
63 
64  void
66 
67  size_t
69 } RegistryInfo;
70 
71 /*
72  Static declarations.
73 */
74 static SplayTreeInfo
75  *registry = (SplayTreeInfo *) NULL;
76 
77 static SemaphoreInfo
79 
80 /*
81 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
82 % %
83 % %
84 % %
85 % D e f i n e I m a g e R e g i s t r y %
86 % %
87 % %
88 % %
89 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
90 %
91 % DefineImageRegistry() associates a key/value pair with the image registry.
92 %
93 % The format of the DefineImageRegistry method is:
94 %
95 % MagickBooleanType DefineImageRegistry(const RegistryType type,
96 % const char *option,ExceptionInfo *exception)
97 %
98 % A description of each parameter follows:
99 %
100 % o type: the type.
101 %
102 % o option: the option.
103 %
104 % o exception: the exception.
105 %
106 */
108  const char *option,ExceptionInfo *exception)
109 {
110  char
111  key[MagickPathExtent],
113 
114  register char
115  *p;
116 
117  assert(option != (const char *) NULL);
118  (void) CopyMagickString(key,option,MagickPathExtent);
119  for (p=key; *p != '\0'; p++)
120  if (*p == '=')
121  break;
122  *value='\0';
123  if (*p == '=')
124  (void) CopyMagickString(value,p+1,MagickPathExtent);
125  *p='\0';
126  return(SetImageRegistry(type,key,value,exception));
127 }
128 
129 /*
130 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
131 % %
132 % %
133 % %
134 % D e l e t e I m a g e R e g i s t r y %
135 % %
136 % %
137 % %
138 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
139 %
140 % DeleteImageRegistry() deletes a key from the image registry.
141 %
142 % The format of the DeleteImageRegistry method is:
143 %
144 % MagickBooleanType DeleteImageRegistry(const char *key)
145 %
146 % A description of each parameter follows:
147 %
148 % o key: the registry.
149 %
150 */
152 {
153  if (IsEventLogging() != MagickFalse)
154  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
155  if (registry == (void *) NULL)
156  return(MagickFalse);
157  return(DeleteNodeFromSplayTree(registry,key));
158 }
159 
160 /*
161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
162 % %
163 % %
164 % %
165 % G e t I m a g e R e g i s t r y %
166 % %
167 % %
168 % %
169 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
170 %
171 % GetImageRegistry() returns a value associated with an image registry key.
172 %
173 % The format of the GetImageRegistry method is:
174 %
175 % void *GetImageRegistry(const RegistryType type,const char *key,
176 % ExceptionInfo *exception)
177 %
178 % A description of each parameter follows:
179 %
180 % o type: the type.
181 %
182 % o key: the key.
183 %
184 % o exception: the exception.
185 %
186 */
187 MagickExport void *GetImageRegistry(const RegistryType type,const char *key,
188  ExceptionInfo *exception)
189 {
190  void
191  *value;
192 
194  *registry_info;
195 
196  if (IsEventLogging() != MagickFalse)
197  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
198  if (registry == (void *) NULL)
199  return((void *) NULL);
200  registry_info=(RegistryInfo *) GetValueFromSplayTree(registry,key);
201  if (registry_info == (void *) NULL)
202  return((void *) NULL);
203  value=(void *) NULL;
204  switch (type)
205  {
206  case ImageRegistryType:
207  {
208  if (type == registry_info->type)
209  value=(void *) CloneImageList((Image *) registry_info->value,exception);
210  break;
211  }
213  {
214  if (type == registry_info->type)
215  value=(void *) CloneImageInfo((ImageInfo *) registry_info->value);
216  break;
217  }
218  case StringRegistryType:
219  {
220  switch (registry_info->type)
221  {
222  case ImageRegistryType:
223  {
224  value=(Image *) ConstantString(((Image *)
225  registry_info->value)->filename);
226  break;
227  }
229  {
230  value=(Image *) ConstantString(((ImageInfo *)
231  registry_info->value)->filename);
232  break;
233  }
234  case StringRegistryType:
235  {
236  value=(void *) ConstantString((char *) registry_info->value);
237  break;
238  }
239  default:
240  break;
241  }
242  break;
243  }
244  default:
245  break;
246  }
247  return(value);
248 }
249 
250 /*
251 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
252 % %
253 % %
254 % %
255 % G e t N e x t I m a g e R e g i s t r y %
256 % %
257 % %
258 % %
259 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
260 %
261 % GetNextImageRegistry() gets the next image registry value.
262 %
263 % The format of the GetNextImageRegistry method is:
264 %
265 % char *GetNextImageRegistry(void)
266 %
267 */
269 {
270  if (IsEventLogging() != MagickFalse)
271  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
272  if (registry == (void *) NULL)
273  return((char *) NULL);
274  return((char *) GetNextKeyInSplayTree(registry));
275 }
276 
277 /*
278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
279 % %
280 % %
281 % %
282 + R e g i s t r y C o m p o n e n t G e n e s i s %
283 % %
284 % %
285 % %
286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
287 %
288 % RegistryComponentGenesis() instantiates the registry component.
289 %
290 % The format of the RegistryComponentGenesis method is:
291 %
292 % MagickBooleanType RegistryComponentGenesis(void)
293 %
294 */
296 {
297  if (registry_semaphore == (SemaphoreInfo *) NULL)
299  return(MagickTrue);
300 }
301 
302 /*
303 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
304 % %
305 % %
306 % %
307 % R e g i s t r y C o m p o n e n t T e r m i n u s %
308 % %
309 % %
310 % %
311 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
312 %
313 % RegistryComponentTerminus() destroys the registry component.
314 %
315 % The format of the DestroyDefines method is:
316 %
317 % void RegistryComponentTerminus(void)
318 %
319 */
321 {
322  if (registry_semaphore == (SemaphoreInfo *) NULL)
325  if (IsEventLogging() != MagickFalse)
326  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
327  if (registry != (void *) NULL)
331 }
332 
333 /*
334 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
335 % %
336 % %
337 % %
338 % R e m o v e I m a g e R e g i s t r y %
339 % %
340 % %
341 % %
342 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
343 %
344 % RemoveImageRegistry() removes a key from the image registry and returns its
345 % value.
346 %
347 % The format of the RemoveImageRegistry method is:
348 %
349 % void *RemoveImageRegistry(const char *key)
350 %
351 % A description of each parameter follows:
352 %
353 % o key: the registry.
354 %
355 */
356 MagickExport void *RemoveImageRegistry(const char *key)
357 {
358  if (IsEventLogging() != MagickFalse)
359  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
360  if (registry == (void *) NULL)
361  return((void *) NULL);
362  return(RemoveNodeFromSplayTree(registry,key));
363 }
364 
365 /*
366 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
367 % %
368 % %
369 % %
370 % R e s e t I m a g e R e g i s t r y I t e r a t o r %
371 % %
372 % %
373 % %
374 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
375 %
376 % ResetImageRegistryIterator() resets the registry iterator. Use it in
377 % conjunction with GetNextImageRegistry() to iterate over all the values
378 % in the image registry.
379 %
380 % The format of the ResetImageRegistryIterator method is:
381 %
382 % ResetImageRegistryIterator(void)
383 %
384 */
386 {
387  if (IsEventLogging() != MagickFalse)
388  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
389  if (registry == (void *) NULL)
390  return;
392 }
393 
394 /*
395 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
396 % %
397 % %
398 % %
399 % S e t I m a g e R e g i s t r y %
400 % %
401 % %
402 % %
403 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
404 %
405 % SetImageRegistry() associates a value with an image registry key.
406 %
407 % The format of the SetImageRegistry method is:
408 %
409 % MagickBooleanType SetImageRegistry(const RegistryType type,
410 % const char *key,const void *value,ExceptionInfo *exception)
411 %
412 % A description of each parameter follows:
413 %
414 % o type: the type.
415 %
416 % o key: the key.
417 %
418 % o value: the value.
419 %
420 % o exception: the exception.
421 %
422 */
423 
424 static void *DestroyRegistryNode(void *registry_info)
425 {
426  register RegistryInfo
427  *p;
428 
429  p=(RegistryInfo *) registry_info;
430  switch (p->type)
431  {
432  case StringRegistryType:
433  default:
434  {
436  break;
437  }
438  case ImageRegistryType:
439  {
440  p->value=(void *) DestroyImageList((Image *) p->value);
441  break;
442  }
444  {
445  p->value=(void *) DestroyImageInfo((ImageInfo *) p->value);
446  break;
447  }
448  }
449  return(RelinquishMagickMemory(p));
450 }
451 
453  const char *key,const void *value,ExceptionInfo *exception)
454 {
456  status;
457 
459  *registry_info;
460 
461  void
462  *clone_value;
463 
464  if (IsEventLogging() != MagickFalse)
465  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key);
466  if (value == (const void *) NULL)
467  return(MagickFalse);
468  clone_value=(void *) NULL;
469  switch (type)
470  {
471  case StringRegistryType:
472  default:
473  {
474  const char
475  *string;
476 
477  string=(const char *) value;
478  clone_value=(void *) ConstantString(string);
479  break;
480  }
481  case ImageRegistryType:
482  {
483  const Image
484  *image;
485 
486  image=(const Image *) value;
487  if (image->signature != MagickCoreSignature)
488  {
490  "UnableToSetRegistry","%s",key);
491  return(MagickFalse);
492  }
493  clone_value=(void *) CloneImageList(image,exception);
494  break;
495  }
497  {
498  const ImageInfo
499  *image_info;
500 
501  image_info=(const ImageInfo *) value;
502  if (image_info->signature != MagickCoreSignature)
503  {
505  "UnableToSetRegistry","%s",key);
506  return(MagickFalse);
507  }
508  clone_value=(void *) CloneImageInfo(image_info);
509  break;
510  }
511  }
512  if (clone_value == (void *) NULL)
513  return(MagickFalse);
514  registry_info=(RegistryInfo *) AcquireCriticalMemory(sizeof(*registry_info));
515  (void) ResetMagickMemory(registry_info,0,sizeof(*registry_info));
516  registry_info->type=type;
517  registry_info->value=clone_value;
518  registry_info->signature=MagickCoreSignature;
519  if (registry == (SplayTreeInfo *) NULL)
520  {
521  if (registry_semaphore == (SemaphoreInfo *) NULL)
524  if (registry == (SplayTreeInfo *) NULL)
528  }
529  status=AddValueToSplayTree(registry,ConstantString(key),registry_info);
530  return(status);
531 }
size_t signature
Definition: image.h:479
MagickExport MagickBooleanType AddValueToSplayTree(SplayTreeInfo *splay_tree, const void *key, const void *value)
Definition: splay-tree.c:154
MagickExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:450
static SemaphoreInfo * registry_semaphore
Definition: registry.c:78
RegistryType type
Definition: registry.c:62
struct _RegistryInfo RegistryInfo
MagickExport SemaphoreInfo * AcquireSemaphoreInfo(void)
Definition: semaphore.c:192
MagickExport char * GetNextImageRegistry(void)
Definition: registry.c:268
Definition: log.h:52
Definition: image.h:151
#define MagickCoreSignature
size_t signature
Definition: registry.c:68
MagickExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:293
MagickBooleanType
Definition: magick-type.h:156
MagickExport void * ResetMagickMemory(void *memory, int byte, const size_t size)
Definition: memory.c:1164
MagickExport SplayTreeInfo * DestroySplayTree(SplayTreeInfo *splay_tree)
Definition: splay-tree.c:682
#define MagickPathExtent
MagickExport MagickBooleanType IsEventLogging(void)
Definition: log.c:716
MagickExport MagickBooleanType static void * AcquireCriticalMemory(const size_t size)
MagickExport SplayTreeInfo * NewSplayTree(int(*compare)(const void *, const void *), void *(*relinquish_key)(void *), void *(*relinquish_value)(void *))
Definition: splay-tree.c:1141
MagickExport void ResetImageRegistryIterator(void)
Definition: registry.c:385
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:1058
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1397
size_t signature
Definition: image.h:354
MagickPrivate MagickBooleanType RegistryComponentGenesis(void)
Definition: registry.c:295
MagickExport size_t CopyMagickString(char *destination, const char *source, const size_t length)
Definition: string.c:742
RegistryType
Definition: registry.h:25
MagickPrivate void RegistryComponentTerminus(void)
Definition: registry.c:320
MagickExport Image * DestroyImageList(Image *images)
Definition: list.c:442
MagickExport const void * GetValueFromSplayTree(SplayTreeInfo *splay_tree, const void *key)
Definition: splay-tree.c:921
MagickExport MagickBooleanType SetImageRegistry(const RegistryType type, const char *key, const void *value, ExceptionInfo *exception)
Definition: registry.c:452
#define GetMagickModule()
Definition: log.h:28
MagickExport Image * CloneImageList(const Image *images, ExceptionInfo *exception)
Definition: list.c:125
MagickExport int CompareSplayTreeString(const void *target, const void *source)
Definition: splay-tree.c:412
MagickExport ImageInfo * DestroyImageInfo(ImageInfo *image_info)
Definition: image.c:1253
MagickExport const void * GetNextKeyInSplayTree(SplayTreeInfo *splay_tree)
Definition: splay-tree.c:769
MagickExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:97
MagickExport ImageInfo * CloneImageInfo(const ImageInfo *image_info)
Definition: image.c:942
MagickExport void * RemoveNodeFromSplayTree(SplayTreeInfo *splay_tree, const void *key)
Definition: splay-tree.c:1299
void * value
Definition: registry.c:65
MagickExport MagickBooleanType DeleteNodeFromSplayTree(SplayTreeInfo *splay_tree, const void *key)
Definition: splay-tree.c:603
MagickExport MagickBooleanType DeleteImageRegistry(const char *key)
Definition: registry.c:151
MagickExport void ResetSplayTreeIterator(SplayTreeInfo *splay_tree)
Definition: splay-tree.c:1472
MagickExport void * RemoveImageRegistry(const char *key)
Definition: registry.c:356
MagickExport MagickBooleanType DefineImageRegistry(const RegistryType type, const char *option, ExceptionInfo *exception)
Definition: registry.c:107
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1038
MagickExport void * GetImageRegistry(const RegistryType type, const char *key, ExceptionInfo *exception)
Definition: registry.c:187
#define MagickPrivate
#define MagickExport
MagickExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:351
MagickExport char * ConstantString(const char *source)
Definition: string.c:687
static void * DestroyRegistryNode(void *registry_info)
Definition: registry.c:424
static SplayTreeInfo * registry
Definition: registry.c:75