MagickCore 7.1.1-37
Convert, Edit, Or Compose Bitmap Images
Loading...
Searching...
No Matches
delegate.c
1/*
2%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3% %
4% %
5% DDDD EEEEE L EEEEE GGGG AAA TTTTT EEEEE %
6% D D E L E G A A T E %
7% D D EEE L EEE G GG AAAAA T EEE %
8% D D E L E G G A A T E %
9% DDDD EEEEE LLLLL EEEEE GGG A A T EEEEE %
10% %
11% %
12% MagickCore Methods to Read/Write/Invoke Delegates %
13% %
14% Software Design %
15% Cristy %
16% October 1998 %
17% %
18% %
19% Copyright @ 1999 ImageMagick Studio LLC, a non-profit organization %
20% dedicated to making software imaging solutions freely available. %
21% %
22% You may not use this file except in compliance with the License. You may %
23% obtain a copy of the License at %
24% %
25% https://imagemagick.org/script/license.php %
26% %
27% Unless required by applicable law or agreed to in writing, software %
28% distributed under the License is distributed on an "AS IS" BASIS, %
29% WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. %
30% See the License for the specific language governing permissions and %
31% limitations under the License. %
32% %
33%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
34%
35% The Delegates methods associate a set of commands with a particular
36% image format. ImageMagick uses delegates for formats it does not handle
37% directly.
38%
39% Thanks to Bob Friesenhahn for the initial inspiration and design of the
40% delegates methods.
41%
42%
43*/
44
45/*
46 Include declarations.
47*/
48#include "MagickCore/studio.h"
49#include "MagickCore/artifact.h"
50#include "MagickCore/attribute.h"
51#include "MagickCore/blob.h"
52#include "MagickCore/client.h"
53#include "MagickCore/configure.h"
54#include "MagickCore/constitute.h"
55#include "MagickCore/delegate.h"
56#include "MagickCore/delegate-private.h"
57#include "MagickCore/exception.h"
58#include "MagickCore/exception-private.h"
59#include "MagickCore/fx-private.h"
60#include "MagickCore/image-private.h"
61#include "MagickCore/linked-list.h"
62#include "MagickCore/linked-list-private.h"
63#include "MagickCore/list.h"
64#include "MagickCore/memory_.h"
65#include "MagickCore/memory-private.h"
66#include "MagickCore/nt-base-private.h"
67#include "MagickCore/option.h"
68#include "MagickCore/policy.h"
69#include "MagickCore/property.h"
70#include "MagickCore/resource_.h"
71#include "MagickCore/semaphore.h"
72#include "MagickCore/signature.h"
73#include "MagickCore/string_.h"
74#include "MagickCore/token.h"
75#include "MagickCore/token-private.h"
76#include "MagickCore/utility.h"
77#include "MagickCore/utility-private.h"
78#include "MagickCore/xml-tree.h"
79#include "MagickCore/xml-tree-private.h"
80
81/*
82 Define declarations.
83*/
84#if defined(__APPLE__)
85 #include "TargetConditionals.h"
86 #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
87 #define system(s) ((s)==NULL ? 0 : -1)
88 #endif // end iOS
89#elif defined(__ANDROID__)
90 #define system(s) ((s)==NULL ? 0 : -1)
91#endif
92#define DelegateFilename "delegates.xml"
93
94/*
95 Declare delegate map.
96*/
97static const char
98 *DelegateMap = (const char *)
99 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
100 "<delegatemap>"
101 " <delegate decode=\"bpg\" command=\"&quot;bpgdec&quot; -b 16 -o &quot;%o.png&quot; &quot;%i&quot;; mv &quot;%o.png&quot; &quot;%o&quot;\"/>"
102 " <delegate decode=\"png\" encode=\"bpg\" command=\"&quot;bpgenc&quot; -b 12 -q %~ -o &quot;%o&quot; &quot;%i&quot;\"/>"
103 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\"&quot;xdg-open&quot; https://imagemagick.org/; rm &quot;%i&quot;\"/>"
104 " <delegate decode=\"cdr\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
105 " <delegate decode=\"cgm\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
106 " <delegate decode=\"https\" command=\"&quot;curl&quot; -s -k -L -o &quot;%o&quot; &quot;https:%M&quot;\"/>"
107 " <delegate decode=\"doc\" command=\"&quot;soffice&quot; --convert-to pdf -outdir `dirname &quot;%i&quot;` &quot;%i&quot; 2&gt; &quot;%u&quot;; mv &quot;%i.pdf&quot; &quot;%o&quot;\"/>"
108 " <delegate decode=\"docx\" command=\"&quot;soffice&quot; --convert-to pdf -outdir `dirname &quot;%i&quot;` &quot;%i&quot; 2&gt; &quot;%u&quot;; mv &quot;%i.pdf&quot; &quot;%o&quot;\"/>"
109 " <delegate decode=\"dng:decode\" command=\"&quot;ufraw-batch&quot; --silent --create-id=also --out-type=png --out-depth=16 &quot;--output=%u.png&quot; &quot;%i&quot;\"/>"
110 " <delegate decode=\"dot\" command=\"&quot;dot&quot; -Tsvg &quot;%i&quot; -o &quot;%o&quot;\"/>"
111 " <delegate decode=\"dvi\" command=\"&quot;dvips&quot; -sstdout=%%stderr -o &quot;%o&quot; &quot;%i&quot;\"/>"
112 " <delegate decode=\"dxf\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
113 " <delegate decode=\"edit\" stealth=\"True\" command=\"&quot;xterm&quot; -title &quot;Edit Image Comment&quot; -e vi &quot;%o&quot;\"/>"
114 " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 &quot;-sDEVICE=pdfwrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
115 " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=ps2write&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
116 " <delegate decode=\"fig\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
117 " <delegate decode=\"hpg\" command=\"&quot;hp2xx&quot; -sstdout=%%stderr -m eps -f `basename &quot;%o&quot;` &quot;%i&quot;; mv -f `basename &quot;%o&quot;` &quot;%o&quot;\"/>"
118 " <delegate decode=\"hpgl\" command=\"&quot;hp2xx&quot; -sstdout=%%stderr -m eps -f `basename &quot;%o&quot;` &quot;%i&quot;; mv -f `basename &quot;%o&quot;` &quot;%o&quot;\"/>"
119 " <delegate decode=\"htm\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
120 " <delegate decode=\"html\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
121 " <delegate decode=\"ilbm\" command=\"&quot;ilbmtoppm&quot; &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
122 " <delegate decode=\"jpg\" encode=\"lep\" mode=\"encode\" command=\"&quot;lepton&quot; &quot;%i&quot; &quot;%o&quot;\"/>"
123 " <delegate decode=\"jxr\" command=\"mv &quot;%i&quot; &quot;%i.jxr&quot;; &quot;JxrDecApp&quot; -i &quot;%i.jxr&quot; -o &quot;%o.tiff&quot;; mv &quot;%i.jxr&quot; &quot;%i&quot;; mv &quot;%o.tiff&quot; &quot;%o&quot;\"/>"
124 " <delegate decode=\"lep\" mode=\"decode\" command=\"&quot;lepton&quot; &quot;%i&quot; &quot;%o&quot;\"/>"
125 " <delegate decode=\"odt\" command=\"&quot;soffice&quot; --convert-to pdf -outdir `dirname &quot;%i&quot;` &quot;%i&quot; 2&gt; &quot;%u&quot;; mv &quot;%i.pdf&quot; &quot;%o&quot;\"/>"
126 " <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pamcmyk32&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
127 " <delegate decode=\"pcl:color\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=ppmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
128 " <delegate decode=\"pcl:mono\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pbmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
129 " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sPDFPassword=&quot;%a&quot; &quot;-sDEVICE=eps2write&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
130 " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=ps2write&quot; -sPDFPassword=&quot;%a&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
131 " <delegate decode=\"png\" encode=\"webp\" command=\"&quot;cwebp&quot; -quiet -q %Q &quot;%i&quot; -o &quot;%o&quot;\"/>"
132 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\"&quot;ppmtoilbm&quot; -24if &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
133 " <delegate decode=\"tiff\" encode=\"jxr\" command=\"mv &quot;%i&quot; &quot;%i.tiff&quot;; &quot;JxrEncApp&quot; -i &quot;%i.tiff&quot; -o &quot;%o.jxr&quot;; mv &quot;%i.tiff&quot; &quot;%i&quot;; mv &quot;%o.jxr&quot; &quot;%o&quot;\"/>"
134 " <delegate decode=\"tiff\" encode=\"wdp\" command=\"mv &quot;%i&quot; &quot;%i.tiff&quot;; &quot;JxrEncApp&quot; -i &quot;%i.tiff&quot; -o &quot;%o.jxr&quot;; mv &quot;%i.tiff&quot; &quot;%i&quot;; mv &quot;%o.jxr&quot; &quot;%o&quot;\"/>"
135 " <delegate decode=\"ppt\" command=\"&quot;soffice&quot; --convert-to pdf -outdir `dirname &quot;%i&quot;` &quot;%i&quot; 2&gt; &quot;%u&quot;; mv &quot;%i.pdf&quot; &quot;%o&quot;\"/>"
136 " <delegate decode=\"pptx\" command=\"&quot;soffice&quot; --convert-to pdf -outdir `dirname &quot;%i&quot;` &quot;%i&quot; 2&gt; &quot;%u&quot;; mv &quot;%i.pdf&quot; &quot;%o&quot;\"/>"
137 " <delegate decode=\"ps\" encode=\"prt\" command=\"&quot;lpr&quot; &quot;%i&quot;\"/>"
138 " <delegate decode=\"ps:alpha\" stealth=\"True\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pngalpha&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
139 " <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pamcmyk32&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
140 " <delegate decode=\"ps:color\" stealth=\"True\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pnmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
141 " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=eps2write&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
142 " <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pdfwrite&quot; &quot;-sOutputFile=%o&quot; &quot;-f%i&quot;\"/>"
143 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr &quot;%i&quot;\"/>"
144 " <delegate decode=\"ps:mono\" stealth=\"True\" command=\"&quot;gs&quot; -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pbmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;-f%s&quot; &quot;-f%s&quot;\"/>"
145 " <delegate decode=\"shtml\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
146 " <delegate decode=\"sid\" command=\"&quot;mrsidgeodecode&quot; -if sid -i &quot;%i&quot; -of tif -o &quot;%o&quot; &gt; &quot;%u&quot;\"/>"
147 " <delegate decode=\"svg\" command=\"&quot;rsvg-convert&quot; --dpi-x %x --dpi-y %y -o &quot;%o&quot; &quot;%i&quot;\"/>"
148#ifndef MAGICKCORE_RSVG_DELEGATE
149 " <delegate decode=\"svg:decode\" stealth=\"True\" command=\"&quot;inkscape&quot; &quot;%s&quot; --export-png=&quot;%s&quot; --export-dpi=&quot;%s&quot; --export-background=&quot;%s&quot; --export-background-opacity=&quot;%s&quot;\"/>"
150#endif
151 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\"&quot;gimp&quot; &quot;%i&quot;\"/>"
152 " <delegate decode=\"wdp\" command=\"mv &quot;%i&quot; &quot;%i.jxr&quot;; &quot;JxrDecApp&quot; -i &quot;%i.jxr&quot; -o &quot;%o.tiff&quot;; mv &quot;%i.jxr&quot; &quot;%i&quot;; mv &quot;%o.tiff&quot; &quot;%o&quot;\"/>"
153 " <delegate decode=\"webp\" command=\"&quot;dwebp&quot; -pam &quot;%i&quot; -o &quot;%o&quot;\"/>"
154 " <delegate decode=\"xls\" command=\"&quot;soffice&quot; --convert-to pdf -outdir `dirname &quot;%i&quot;` &quot;%i&quot; 2&gt; &quot;%u&quot;; mv &quot;%i.pdf&quot; &quot;%o&quot;\"/>"
155 " <delegate decode=\"xlsx\" command=\"&quot;soffice&quot; --convert-to pdf -outdir `dirname &quot;%i&quot;` &quot;%i&quot; 2&gt; &quot;%u&quot;; mv &quot;%i.pdf&quot; &quot;%o&quot;\"/>"
156 " <delegate decode=\"xps:cmyk\" stealth=\"True\" command=\"&quot;gxps&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=bmpsep8&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
157 " <delegate decode=\"xps:color\" stealth=\"True\" command=\"&quot;gxps&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=ppmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
158 " <delegate decode=\"xps:mono\" stealth=\"True\" command=\"&quot;gxps&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pbmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
159 " <delegate decode=\"video:decode\" command=\"&quot;ffmpeg&quot; -nostdin -loglevel error -i &quot;%s&quot; -an -f rawvideo -y %s &quot;%s&quot;\"/>"
160 " <delegate encode=\"video:encode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -nostdin -loglevel error -i &quot;%s%%d.%s&quot; %s &quot;%s.%s&quot;\"/>"
161 "</delegatemap>";
162
163/*
164 Global declarations.
165*/
166static LinkedListInfo
167 *delegate_cache = (LinkedListInfo *) NULL;
168
169static SemaphoreInfo
170 *delegate_semaphore = (SemaphoreInfo *) NULL;
171
172/*
173 Forward declarations.
174*/
175static MagickBooleanType
176 IsDelegateCacheInstantiated(ExceptionInfo *),
177 LoadDelegateCache(LinkedListInfo *,const char *,const char *,const size_t,
178 ExceptionInfo *);
179
180/*
181%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
182% %
183% %
184% %
185% A c q u i r e D e l e g a t e C a c h e %
186% %
187% %
188% %
189%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
190%
191% AcquireDelegateCache() caches one or more delegate configurations which
192% provides a mapping between delegate attributes and a delegate name.
193%
194% The format of the AcquireDelegateCache method is:
195%
196% LinkedListInfo *AcquireDelegateCache(const char *filename,
197% ExceptionInfo *exception)
198%
199% A description of each parameter follows:
200%
201% o filename: the font file name.
202%
203% o exception: return any errors or warnings in this structure.
204%
205*/
206static LinkedListInfo *AcquireDelegateCache(const char *filename,
207 ExceptionInfo *exception)
208{
210 *cache;
211
212 cache=NewLinkedList(0);
213#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
214 {
215 const StringInfo
216 *option;
217
219 *options;
220
221 options=GetConfigureOptions(filename,exception);
222 option=(const StringInfo *) GetNextValueInLinkedList(options);
223 while (option != (const StringInfo *) NULL)
224 {
225 (void) LoadDelegateCache(cache,(const char *)
226 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
227 option=(const StringInfo *) GetNextValueInLinkedList(options);
228 }
229 options=DestroyConfigureOptions(options);
230 }
231#else
232 magick_unreferenced(filename);
233#endif
234 if (IsLinkedListEmpty(cache) != MagickFalse)
235 (void) LoadDelegateCache(cache,DelegateMap,"built-in",0,exception);
236 return(cache);
237}
238
239/*
240%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
241% %
242% %
243% %
244+ D e l e g a t e C o m p o n e n t G e n e s i s %
245% %
246% %
247% %
248%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
249%
250% DelegateComponentGenesis() instantiates the delegate component.
251%
252% The format of the DelegateComponentGenesis method is:
253%
254% MagickBooleanType DelegateComponentGenesis(void)
255%
256*/
257MagickPrivate MagickBooleanType DelegateComponentGenesis(void)
258{
259 if (delegate_semaphore == (SemaphoreInfo *) NULL)
260 delegate_semaphore=AcquireSemaphoreInfo();
261 return(MagickTrue);
262}
263
264/*
265%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
266% %
267% %
268% %
269% D e l e g a t e C o m p o n e n t T e r m i n u s %
270% %
271% %
272% %
273%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
274%
275% DelegateComponentTerminus() destroys the delegate component.
276%
277% The format of the DelegateComponentTerminus method is:
278%
279% DelegateComponentTerminus(void)
280%
281*/
282
283static void *DestroyDelegate(void *delegate_info)
284{
286 *p;
287
288 p=(DelegateInfo *) delegate_info;
289 if (p->path != (char *) NULL)
290 p->path=DestroyString(p->path);
291 if (p->decode != (char *) NULL)
292 p->decode=DestroyString(p->decode);
293 if (p->encode != (char *) NULL)
294 p->encode=DestroyString(p->encode);
295 if (p->commands != (char *) NULL)
296 p->commands=DestroyString(p->commands);
297 if (p->semaphore != (SemaphoreInfo *) NULL)
298 RelinquishSemaphoreInfo(&p->semaphore);
299 p=(DelegateInfo *) RelinquishMagickMemory(p);
300 return((void *) NULL);
301}
302
303MagickPrivate void DelegateComponentTerminus(void)
304{
305 if (delegate_semaphore == (SemaphoreInfo *) NULL)
306 ActivateSemaphoreInfo(&delegate_semaphore);
307 LockSemaphoreInfo(delegate_semaphore);
308 if (delegate_cache != (LinkedListInfo *) NULL)
309 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
310 UnlockSemaphoreInfo(delegate_semaphore);
311 RelinquishSemaphoreInfo(&delegate_semaphore);
312}
313
314/*
315%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
316% %
317% %
318% %
319+ E x t e r n a l D e l e g a t e C o m m a n d %
320% %
321% %
322% %
323%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
324%
325% ExternalDelegateCommand() executes the specified command and waits until it
326% terminates. The returned value is the exit status of the command.
327%
328% The format of the ExternalDelegateCommand method is:
329%
330% int ExternalDelegateCommand(const MagickBooleanType asynchronous,
331% const MagickBooleanType verbose,const char *command,
332% char *message,ExceptionInfo *exception)
333%
334% A description of each parameter follows:
335%
336% o asynchronous: a value other than 0 executes the parent program
337% concurrently with the new child process.
338%
339% o verbose: a value other than 0 prints the executed command before it is
340% invoked.
341%
342% o command: this string is the command to execute.
343%
344% o message: an option buffer to receive any message posted to stdout or
345% stderr.
346%
347% o exception: return any errors here.
348%
349*/
350MagickExport int ExternalDelegateCommand(const MagickBooleanType asynchronous,
351 const MagickBooleanType verbose,const char *command,char *message,
352 ExceptionInfo *exception)
353{
354 char
355 **arguments,
356 *sanitize_command;
357
358 int
359 number_arguments,
360 status;
361
362 PolicyDomain
363 domain;
364
365 PolicyRights
366 rights;
367
368 ssize_t
369 i;
370
371 status=(-1);
372 arguments=StringToArgv(command,&number_arguments);
373 if (arguments == (char **) NULL)
374 return(status);
375 if (*arguments[1] == '\0')
376 {
377 for (i=0; i < (ssize_t) number_arguments; i++)
378 arguments[i]=DestroyString(arguments[i]);
379 arguments=(char **) RelinquishMagickMemory(arguments);
380 return(-1);
381 }
382 rights=ExecutePolicyRights;
383 domain=DelegatePolicyDomain;
384 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
385 {
386 errno=EPERM;
387 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
388 "NotAuthorized","`%s'",arguments[1]);
389 for (i=0; i < (ssize_t) number_arguments; i++)
390 arguments[i]=DestroyString(arguments[i]);
391 arguments=(char **) RelinquishMagickMemory(arguments);
392 return(-1);
393 }
394 if (verbose != MagickFalse)
395 {
396 (void) FormatLocaleFile(stderr,"%s\n",command);
397 (void) fflush(stderr);
398 }
399 sanitize_command=SanitizeString(command);
400 if (asynchronous != MagickFalse)
401 (void) ConcatenateMagickString(sanitize_command,"&",MagickPathExtent);
402 if (message != (char *) NULL)
403 *message='\0';
404#if defined(MAGICKCORE_POSIX_SUPPORT)
405#if defined(MAGICKCORE_HAVE_POPEN)
406 if ((asynchronous == MagickFalse) && (message != (char *) NULL))
407 {
408 FILE
409 *file;
410
411 file=popen_utf8(sanitize_command,"r");
412 if (file == (FILE *) NULL)
413 status=system(sanitize_command);
414 else
415 {
416 size_t
417 offset = 0;
418
419 while ((offset < MagickPathExtent) &&
420 (fgets(message+offset,MagickPathExtent-offset,file) != NULL))
421 offset+=strlen(message);
422 status=pclose(file);
423 }
424 }
425 else
426#endif
427 {
428#if !defined(MAGICKCORE_HAVE_EXECVP)
429 status=system(sanitize_command);
430#else
431 if ((asynchronous != MagickFalse) ||
432 (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
433 status=system(sanitize_command);
434 else
435 {
436 pid_t
437 child_pid;
438
439 /*
440 Call application directly rather than from a shell.
441 */
442 child_pid=(pid_t) fork();
443 if (child_pid == (pid_t) -1)
444 status=system(sanitize_command);
445 else
446 if (child_pid == 0)
447 {
448 status=execvp(arguments[1],arguments+1);
449 _exit(1);
450 }
451 else
452 {
453 int
454 child_status;
455
456 pid_t
457 pid;
458
459 child_status=0;
460 pid=(pid_t) waitpid(child_pid,&child_status,0);
461 if (pid == -1)
462 status=(-1);
463 else
464 {
465 if (WIFEXITED(child_status) != 0)
466 status=WEXITSTATUS(child_status);
467 else
468 if (WIFSIGNALED(child_status))
469 status=(-1);
470 }
471 }
472 }
473#endif
474 }
475#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
476 {
477 char
478 *p;
479
480 /*
481 If a command shell is executed we need to change the forward slashes in
482 files to a backslash. We need to do this to keep Windows happy when we
483 want to 'move' a file.
484
485 TODO: This won't work if one of the delegate parameters has a forward
486 slash as a parameter.
487 */
488 p=strstr(sanitize_command,"cmd.exe /c");
489 if (p != (char*) NULL)
490 {
491 p+=10;
492 for ( ; *p != '\0'; p++)
493 if (*p == '/')
494 *p=(*DirectorySeparator);
495 }
496 }
497 status=NTSystemCommand(sanitize_command,message);
498#elif defined(vms)
499 status=system(sanitize_command);
500#else
501# error No suitable system() method.
502#endif
503 if (status < 0)
504 {
505 if ((message != (char *) NULL) && (*message != '\0'))
506 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
507 "FailedToExecuteCommand","`%s' (%s)",sanitize_command,message);
508 else
509 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
510 "FailedToExecuteCommand","`%s' (%d)",sanitize_command,status);
511 }
512 sanitize_command=DestroyString(sanitize_command);
513 for (i=0; i < (ssize_t) number_arguments; i++)
514 arguments[i]=DestroyString(arguments[i]);
515 arguments=(char **) RelinquishMagickMemory(arguments);
516 return(status);
517}
518
519/*
520%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
521% %
522% %
523% %
524% G e t D e l e g a t e C o m m a n d %
525% %
526% %
527% %
528%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
529%
530% GetDelegateCommand() replaces any embedded formatting characters with the
531% appropriate image attribute and returns the resulting command.
532%
533% The format of the GetDelegateCommand method is:
534%
535% char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
536% const char *decode,const char *encode,ExceptionInfo *exception)
537%
538% A description of each parameter follows:
539%
540% o command: Method GetDelegateCommand returns the command associated
541% with specified delegate tag.
542%
543% o image_info: the image info.
544%
545% o image: the image.
546%
547% o decode: Specifies the decode delegate we are searching for as a
548% character string.
549%
550% o encode: Specifies the encode delegate we are searching for as a
551% character string.
552%
553% o exception: return any errors or warnings in this structure.
554%
555*/
556
557static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
558 const char letter,ExceptionInfo *exception)
559{
560#define WarnNoImageReturn(format,letter) \
561 if (image == (Image *) NULL) \
562 { \
563 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
564 "NoImageForProperty",format,letter); \
565 break; \
566 }
567#define WarnNoImageInfoReturn(format,letter) \
568 if (image_info == (ImageInfo *) NULL) \
569 { \
570 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
571 "NoImageInfoForProperty",format,letter); \
572 break; \
573 }
574
575 char
576 value[MagickPathExtent];
577
578 const char
579 *string;
580
581 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
582 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
583 else
584 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
586 /*
587 Get properties that are directly defined by images.
588 */
589 *value='\0'; /* formatted string */
590 string=(const char *) value;
591 switch (letter)
592 {
593 case 'a': /* authentication passphrase */
594 {
595 WarnNoImageInfoReturn("\"%%%c\"",letter);
596 string=GetImageOption(image_info,"authenticate");
597 break;
598 }
599 case 'b': /* image size read in - in bytes */
600 {
601 WarnNoImageReturn("\"%%%c\"",letter);
602 (void) FormatMagickSize(image->extent,MagickFalse,"B",MagickPathExtent,
603 value);
604 if (image->extent == 0)
605 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
606 MagickPathExtent,value);
607 break;
608 }
609 case 'd': /* Directory component of filename */
610 {
611 WarnNoImageReturn("\"%%%c\"",letter);
612 GetPathComponent(image->magick_filename,HeadPath,value);
613 break;
614 }
615 case 'e': /* Filename extension (suffix) of image file */
616 {
617 WarnNoImageReturn("\"%%%c\"",letter);
618 GetPathComponent(image->magick_filename,ExtensionPath,value);
619 break;
620 }
621 case 'f': /* Filename without directory component */
622 {
623 WarnNoImageReturn("\"%%%c\"",letter);
624 GetPathComponent(image->magick_filename,TailPath,value);
625 break;
626 }
627 case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
628 {
629 WarnNoImageReturn("\"%%%c\"",letter);
630 (void) FormatLocaleString(value,MagickPathExtent,
631 "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
632 image->page.height,(double) image->page.x,(double) image->page.y);
633 break;
634 }
635 case 'h': /* Image height (current) */
636 {
637 WarnNoImageReturn("\"%%%c\"",letter);
638 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
639 (image->rows != 0 ? image->rows : image->magick_rows));
640 break;
641 }
642 case 'i': /* Filename last used for an image (read or write) */
643 {
644 WarnNoImageReturn("\"%%%c\"",letter);
645 string=image->filename;
646 break;
647 }
648 case 'm': /* Image format (file magick) */
649 {
650 WarnNoImageReturn("\"%%%c\"",letter);
651 string=image->magick;
652 break;
653 }
654 case 'n': /* Number of images in the list. */
655 {
656 if (image != (Image *) NULL)
657 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
658 GetImageListLength(image));
659 break;
660 }
661 case 'o': /* Output Filename */
662 {
663 WarnNoImageInfoReturn("\"%%%c\"",letter);
664 string=image_info->filename;
665 break;
666 }
667 case 'p': /* Image index in current image list */
668 {
669 WarnNoImageReturn("\"%%%c\"",letter);
670 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
671 GetImageIndexInList(image));
672 break;
673 }
674 case 'q': /* Quantum depth of image in memory */
675 {
676 WarnNoImageReturn("\"%%%c\"",letter);
677 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
678 MAGICKCORE_QUANTUM_DEPTH);
679 break;
680 }
681 case 'r': /* Image storage class, colorspace, and alpha enabled. */
682 {
683 ColorspaceType
684 colorspace;
685
686 WarnNoImageReturn("\"%%%c\"",letter);
687 colorspace=image->colorspace;
688 (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
689 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
690 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
691 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
692 "Alpha" : "");
693 break;
694 }
695 case 's': /* Image scene number */
696 {
697 WarnNoImageReturn("\"%%%c\"",letter);
698 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
699 image->scene);
700 break;
701 }
702 case 't': /* Base filename without directory or extension */
703 {
704 WarnNoImageReturn("\"%%%c\"",letter);
705 GetPathComponent(image->magick_filename,BasePath,value);
706 break;
707 }
708 case 'u': /* Unique filename */
709 {
710 WarnNoImageInfoReturn("\"%%%c\"",letter);
711 string=image_info->unique;
712 break;
713 }
714 case 'w': /* Image width (current) */
715 {
716 WarnNoImageReturn("\"%%%c\"",letter);
717 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
718 (image->columns != 0 ? image->columns : image->magick_columns));
719 break;
720 }
721 case 'x': /* Image horizontal resolution (with units) */
722 {
723 WarnNoImageReturn("\"%%%c\"",letter);
724 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
725 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
726 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
727 DefaultResolution);
728 break;
729 }
730 case 'y': /* Image vertical resolution (with units) */
731 {
732 WarnNoImageReturn("\"%%%c\"",letter);
733 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
734 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
735 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
736 DefaultResolution);
737 break;
738 }
739 case 'z': /* Image depth as read in */
740 {
741 WarnNoImageReturn("\"%%%c\"",letter);
742 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
743 (double) image->depth);
744 break;
745 }
746 case 'A': /* Image alpha channel */
747 {
748 WarnNoImageReturn("\"%%%c\"",letter);
749 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
750 image->alpha_trait);
751 break;
752 }
753 case 'C': /* Image compression method. */
754 {
755 WarnNoImageReturn("\"%%%c\"",letter);
756 string=CommandOptionToMnemonic(MagickCompressOptions,
757 (ssize_t) image->compression);
758 break;
759 }
760 case 'D': /* Image dispose method. */
761 {
762 WarnNoImageReturn("\"%%%c\"",letter);
763 string=CommandOptionToMnemonic(MagickDisposeOptions,
764 (ssize_t) image->dispose);
765 break;
766 }
767 case 'F':
768 {
769 /*
770 Magick filename - filename given incl. coder & read mods.
771 */
772 WarnNoImageReturn("\"%%%c\"",letter);
773 (void) CopyMagickString(value,image->magick_filename,MagickPathExtent);
774 break;
775 }
776 case 'G': /* Image size as geometry = "%wx%h" */
777 {
778 WarnNoImageReturn("\"%%%c\"",letter);
779 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
780 (double) image->magick_columns,(double) image->magick_rows);
781 break;
782 }
783 case 'H': /* layer canvas height */
784 {
785 WarnNoImageReturn("\"%%%c\"",letter);
786 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
787 (double) image->page.height);
788 break;
789 }
790 case 'I': /* image iterations for animations */
791 {
792 WarnNoImageReturn("\"%%%c\"",letter);
793 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
794 image->iterations);
795 break;
796 }
797 case 'M': /* Magick filename - filename given incl. coder & read mods */
798 {
799 WarnNoImageReturn("\"%%%c\"",letter);
800 string=image->magick_filename;
801 break;
802 }
803 case 'O': /* layer canvas offset with sign = "+%X+%Y" */
804 {
805 WarnNoImageReturn("\"%%%c\"",letter);
806 (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
807 image->page.x,(long) image->page.y);
808 break;
809 }
810 case 'P': /* layer canvas page size = "%Wx%H" */
811 {
812 WarnNoImageReturn("\"%%%c\"",letter);
813 (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
814 (double) image->page.width,(double) image->page.height);
815 break;
816 }
817 case '~': /* BPG image compression quality */
818 {
819 WarnNoImageReturn("\"%%%c\"",letter);
820 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
821 (100-(image->quality == 0 ? 42 : image->quality))/2);
822 break;
823 }
824 case 'Q': /* image compression quality */
825 {
826 WarnNoImageReturn("\"%%%c\"",letter);
827 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
828 (image->quality == 0 ? 92 : image->quality));
829 break;
830 }
831 case 'S': /* Number of scenes in image list. */
832 {
833 WarnNoImageInfoReturn("\"%%%c\"",letter);
834 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
835 (image_info->number_scenes == 0 ? 2147483647 :
836 image_info->number_scenes));
837 break;
838 }
839 case 'T': /* image time delay for animations */
840 {
841 WarnNoImageReturn("\"%%%c\"",letter);
842 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
843 image->delay);
844 break;
845 }
846 case 'U': /* Image resolution units. */
847 {
848 WarnNoImageReturn("\"%%%c\"",letter);
849 string=CommandOptionToMnemonic(MagickResolutionOptions,
850 (ssize_t) image->units);
851 break;
852 }
853 case 'W': /* layer canvas width */
854 {
855 WarnNoImageReturn("\"%%%c\"",letter);
856 (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
857 image->page.width);
858 break;
859 }
860 case 'X': /* layer canvas X offset */
861 {
862 WarnNoImageReturn("\"%%%c\"",letter);
863 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
864 image->page.x);
865 break;
866 }
867 case 'Y': /* layer canvas Y offset */
868 {
869 WarnNoImageReturn("\"%%%c\"",letter);
870 (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
871 image->page.y);
872 break;
873 }
874 case '%': /* percent escaped */
875 {
876 string="%";
877 break;
878 }
879 case '@': /* Trim bounding box, without actually trimming! */
880 {
882 page;
883
884 WarnNoImageReturn("\"%%%c\"",letter);
885 page=GetImageBoundingBox(image,exception);
886 (void) FormatLocaleString(value,MagickPathExtent,
887 "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
888 (double) page.x,(double) page.y);
889 break;
890 }
891 case '#':
892 {
893 /*
894 Image signature.
895 */
896 WarnNoImageReturn("\"%%%c\"",letter);
897 (void) SignatureImage(image,exception);
898 string=GetImageProperty(image,"signature",exception);
899 break;
900 }
901 }
902 return(SanitizeDelegateString(string));
903}
904
905static char *InterpretDelegateProperties(ImageInfo *image_info,
906 Image *image,const char *embed_text,ExceptionInfo *exception)
907{
908#define ExtendInterpretText(string_length) \
909{ \
910 size_t length=(string_length); \
911 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
912 { \
913 extent+=length; \
914 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
915 MagickPathExtent,sizeof(*interpret_text)); \
916 if (interpret_text == (char *) NULL) \
917 return((char *) NULL); \
918 q=interpret_text+strlen(interpret_text); \
919 } \
920}
921
922#define AppendKeyValue2Text(key,value)\
923{ \
924 size_t length=strlen(key)+strlen(value)+2; \
925 if ((size_t) (q-interpret_text+length+1) >= extent) \
926 { \
927 extent+=length; \
928 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
929 MagickPathExtent,sizeof(*interpret_text)); \
930 if (interpret_text == (char *) NULL) \
931 return((char *) NULL); \
932 q=interpret_text+strlen(interpret_text); \
933 } \
934 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
935}
936
937#define AppendString2Text(string) \
938{ \
939 size_t length=strlen((string)); \
940 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
941 { \
942 extent+=length; \
943 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
944 MagickPathExtent,sizeof(*interpret_text)); \
945 if (interpret_text == (char *) NULL) \
946 return((char *) NULL); \
947 q=interpret_text+strlen(interpret_text); \
948 } \
949 (void) CopyMagickString(q,(string),extent); \
950 q+=length; \
951}
952
953 char
954 *interpret_text,
955 *string;
956
957 char
958 *q; /* current position in interpret_text */
959
960 const char
961 *p; /* position in embed_text string being expanded */
962
963 size_t
964 extent; /* allocated length of interpret_text */
965
966 MagickBooleanType
967 number;
968
969 assert(image == NULL || image->signature == MagickCoreSignature);
970 assert(image_info == NULL || image_info->signature == MagickCoreSignature);
971 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
972 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
973 else
974 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
975 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
976 if (embed_text == (const char *) NULL)
977 return(ConstantString(""));
978 p=embed_text;
979 while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
980 p++;
981 if (*p == '\0')
982 return(ConstantString(""));
983 /*
984 Translate any embedded format characters.
985 */
986 interpret_text=AcquireString(embed_text); /* new string with extra space */
987 extent=MagickPathExtent; /* allocated space in string */
988 number=MagickFalse; /* is last char a number? */
989 for (q=interpret_text; *p!='\0';
990 number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
991 {
992 /*
993 Interpret escape characters (e.g. Filename: %M).
994 */
995 *q='\0';
996 ExtendInterpretText(MagickPathExtent);
997 switch (*p)
998 {
999 case '\\':
1000 {
1001 switch (*(p+1))
1002 {
1003 case '\0':
1004 continue;
1005 case 'r': /* convert to RETURN */
1006 {
1007 *q++='\r';
1008 p++;
1009 continue;
1010 }
1011 case 'n': /* convert to NEWLINE */
1012 {
1013 *q++='\n';
1014 p++;
1015 continue;
1016 }
1017 case '\n': /* EOL removal UNIX,MacOSX */
1018 {
1019 p++;
1020 continue;
1021 }
1022 case '\r': /* EOL removal DOS,Windows */
1023 {
1024 p++;
1025 if (*p == '\n') /* return-newline EOL */
1026 p++;
1027 continue;
1028 }
1029 default:
1030 {
1031 p++;
1032 *q++=(*p);
1033 }
1034 }
1035 continue;
1036 }
1037 case '&':
1038 {
1039 if (LocaleNCompare("&lt;",p,4) == 0)
1040 {
1041 *q++='<';
1042 p+=3;
1043 }
1044 else
1045 if (LocaleNCompare("&gt;",p,4) == 0)
1046 {
1047 *q++='>';
1048 p+=3;
1049 }
1050 else
1051 if (LocaleNCompare("&amp;",p,5) == 0)
1052 {
1053 *q++='&';
1054 p+=4;
1055 }
1056 else
1057 *q++=(*p);
1058 continue;
1059 }
1060 case '%':
1061 break; /* continue to next set of handlers */
1062 default:
1063 {
1064 *q++=(*p); /* any thing else is 'as normal' */
1065 continue;
1066 }
1067 }
1068 p++; /* advance beyond the percent */
1069 /*
1070 Doubled Percent - or percent at end of string.
1071 */
1072 if ((*p == '\0') || (*p == '\'') || (*p == '"'))
1073 p--;
1074 if (*p == '%')
1075 {
1076 *q++='%';
1077 continue;
1078 }
1079 /*
1080 Single letter escapes %c.
1081 */
1082 if (number != MagickFalse)
1083 {
1084 /*
1085 But only if not preceded by a number!
1086 */
1087 *q++='%'; /* do NOT substitute the percent */
1088 p--; /* back up one */
1089 continue;
1090 }
1091 string=GetMagickPropertyLetter(image_info,image,*p,exception);
1092 if (string != (char *) NULL)
1093 {
1094 AppendString2Text(string);
1095 string=DestroyString(string);
1096 continue;
1097 }
1098 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1099 "UnknownImageProperty","\"%%%c\"",*p);
1100 }
1101 *q='\0';
1102 return(interpret_text);
1103}
1104
1105MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
1106 const char *decode,const char *encode,ExceptionInfo *exception)
1107{
1108 char
1109 *command,
1110 **commands;
1111
1112 const DelegateInfo
1113 *delegate_info;
1114
1115 ssize_t
1116 i;
1117
1118 assert(image_info != (ImageInfo *) NULL);
1119 assert(image_info->signature == MagickCoreSignature);
1120 assert(image != (Image *) NULL);
1121 assert(image->signature == MagickCoreSignature);
1122 if (IsEventLogging() != MagickFalse)
1123 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1124 delegate_info=GetDelegateInfo(decode,encode,exception);
1125 if (delegate_info == (const DelegateInfo *) NULL)
1126 {
1127 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1128 "NoTagFound","`%s'",decode ? decode : encode);
1129 return((char *) NULL);
1130 }
1131 commands=StringToList(delegate_info->commands);
1132 if (commands == (char **) NULL)
1133 {
1134 (void) ThrowMagickException(exception,GetMagickModule(),
1135 ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode :
1136 encode);
1137 return((char *) NULL);
1138 }
1139 command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1140 commands[0],exception);
1141 if (command == (char *) NULL)
1142 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1143 "MemoryAllocationFailed","`%s'",commands[0]);
1144 /*
1145 Relinquish resources.
1146 */
1147 for (i=0; commands[i] != (char *) NULL; i++)
1148 commands[i]=DestroyString(commands[i]);
1149 commands=(char **) RelinquishMagickMemory(commands);
1150 return(command);
1151}
1152
1153/*
1154%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1155% %
1156% %
1157% %
1158% G e t D e l e g a t e C o m m a n d s %
1159% %
1160% %
1161% %
1162%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1163%
1164% GetDelegateCommands() returns the commands associated with a delegate.
1165%
1166% The format of the GetDelegateCommands method is:
1167%
1168% const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1169%
1170% A description of each parameter follows:
1171%
1172% o delegate_info: The delegate info.
1173%
1174*/
1175MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1176{
1177 if (IsEventLogging() != MagickFalse)
1178 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1179 assert(delegate_info != (DelegateInfo *) NULL);
1180 assert(delegate_info->signature == MagickCoreSignature);
1181 return(delegate_info->commands);
1182}
1183
1184/*
1185%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1186% %
1187% %
1188% %
1189% G e t D e l e g a t e I n f o %
1190% %
1191% %
1192% %
1193%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1194%
1195% GetDelegateInfo() returns any delegates associated with the specified tag.
1196%
1197% The format of the GetDelegateInfo method is:
1198%
1199% const DelegateInfo *GetDelegateInfo(const char *decode,
1200% const char *encode,ExceptionInfo *exception)
1201%
1202% A description of each parameter follows:
1203%
1204% o decode: Specifies the decode delegate we are searching for as a
1205% character string.
1206%
1207% o encode: Specifies the encode delegate we are searching for as a
1208% character string.
1209%
1210% o exception: return any errors or warnings in this structure.
1211%
1212*/
1213MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
1214 const char *encode,ExceptionInfo *exception)
1215{
1216 const DelegateInfo
1217 *delegate_info;
1218
1220 *p;
1221
1222 assert(exception != (ExceptionInfo *) NULL);
1223 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1224 return((const DelegateInfo *) NULL);
1225 /*
1226 Search for named delegate.
1227 */
1228 delegate_info=(const DelegateInfo *) NULL;
1229 LockSemaphoreInfo(delegate_semaphore);
1230 p=GetHeadElementInLinkedList(delegate_cache);
1231 if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
1232 {
1233 UnlockSemaphoreInfo(delegate_semaphore);
1234 if (p != (ElementInfo *) NULL)
1235 delegate_info=(const DelegateInfo* ) p->value;
1236 return(delegate_info);
1237 }
1238 while (p != (ElementInfo *) NULL)
1239 {
1240 delegate_info=(const DelegateInfo* ) p->value;
1241 if (delegate_info->mode > 0)
1242 {
1243 if (LocaleCompare(delegate_info->decode,decode) == 0)
1244 break;
1245 p=p->next;
1246 continue;
1247 }
1248 if (delegate_info->mode < 0)
1249 {
1250 if (LocaleCompare(delegate_info->encode,encode) == 0)
1251 break;
1252 p=p->next;
1253 continue;
1254 }
1255 if (LocaleCompare(decode,delegate_info->decode) == 0)
1256 if (LocaleCompare(encode,delegate_info->encode) == 0)
1257 break;
1258 if (LocaleCompare(decode,"*") == 0)
1259 if (LocaleCompare(encode,delegate_info->encode) == 0)
1260 break;
1261 if (LocaleCompare(decode,delegate_info->decode) == 0)
1262 if (LocaleCompare(encode,"*") == 0)
1263 break;
1264 p=p->next;
1265 }
1266 if (p == (ElementInfo *) NULL)
1267 delegate_info=(const DelegateInfo *) NULL;
1268 else
1269 SetHeadElementInLinkedList(delegate_cache,p);
1270 UnlockSemaphoreInfo(delegate_semaphore);
1271 return(delegate_info);
1272}
1273
1274/*
1275%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1276% %
1277% %
1278% %
1279% G e t D e l e g a t e I n f o L i s t %
1280% %
1281% %
1282% %
1283%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1284%
1285% GetDelegateInfoList() returns any delegates that match the specified pattern.
1286%
1287% The delegate of the GetDelegateInfoList function is:
1288%
1289% const DelegateInfo **GetDelegateInfoList(const char *pattern,
1290% size_t *number_delegates,ExceptionInfo *exception)
1291%
1292% A description of each parameter follows:
1293%
1294% o pattern: Specifies a pointer to a text string containing a pattern.
1295%
1296% o number_delegates: This integer returns the number of delegates in the
1297% list.
1298%
1299% o exception: return any errors or warnings in this structure.
1300%
1301*/
1302
1303#if defined(__cplusplus) || defined(c_plusplus)
1304extern "C" {
1305#endif
1306
1307static int DelegateInfoCompare(const void *x,const void *y)
1308{
1309 const DelegateInfo
1310 **p,
1311 **q;
1312
1313 int
1314 cmp;
1315
1316 p=(const DelegateInfo **) x,
1317 q=(const DelegateInfo **) y;
1318 cmp=LocaleCompare((*p)->path,(*q)->path);
1319 if (cmp == 0)
1320 {
1321 if ((*p)->decode == (char *) NULL)
1322 if (((*p)->encode != (char *) NULL) &&
1323 ((*q)->encode != (char *) NULL))
1324 return(strcmp((*p)->encode,(*q)->encode));
1325 if (((*p)->decode != (char *) NULL) &&
1326 ((*q)->decode != (char *) NULL))
1327 return(strcmp((*p)->decode,(*q)->decode));
1328 }
1329 return(cmp);
1330}
1331
1332#if defined(__cplusplus) || defined(c_plusplus)
1333}
1334#endif
1335
1336MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
1337 size_t *number_delegates,ExceptionInfo *exception)
1338{
1339 const DelegateInfo
1340 **delegates;
1341
1343 *p;
1344
1345 ssize_t
1346 i;
1347
1348 assert(number_delegates != (size_t *) NULL);
1349 assert(pattern != (char *) NULL);
1350 if (IsEventLogging() != MagickFalse)
1351 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1352 *number_delegates=0;
1353 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1354 return((const DelegateInfo **) NULL);
1355 delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
1356 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1357 if (delegates == (const DelegateInfo **) NULL)
1358 return((const DelegateInfo **) NULL);
1359 LockSemaphoreInfo(delegate_semaphore);
1360 p=GetHeadElementInLinkedList(delegate_cache);
1361 for (i=0; p != (ElementInfo *) NULL; )
1362 {
1363 const DelegateInfo
1364 *delegate_info;
1365
1366 delegate_info=(const DelegateInfo *) p->value;
1367 if( (delegate_info->stealth == MagickFalse) &&
1368 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse ||
1369 GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1370 delegates[i++]=delegate_info;
1371 p=p->next;
1372 }
1373 UnlockSemaphoreInfo(delegate_semaphore);
1374 if (i == 0)
1375 delegates=(const DelegateInfo **) RelinquishMagickMemory((void*) delegates);
1376 else
1377 {
1378 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
1379 delegates[i]=(DelegateInfo *) NULL;
1380 }
1381 *number_delegates=(size_t) i;
1382 return(delegates);
1383}
1384
1385/*
1386%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1387% %
1388% %
1389% %
1390% G e t D e l e g a t e L i s t %
1391% %
1392% %
1393% %
1394%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1395%
1396% GetDelegateList() returns any image format delegates that match the
1397% specified pattern.
1398%
1399% The format of the GetDelegateList function is:
1400%
1401% char **GetDelegateList(const char *pattern,
1402% size_t *number_delegates,ExceptionInfo *exception)
1403%
1404% A description of each parameter follows:
1405%
1406% o pattern: Specifies a pointer to a text string containing a pattern.
1407%
1408% o number_delegates: This integer returns the number of delegates
1409% in the list.
1410%
1411% o exception: return any errors or warnings in this structure.
1412%
1413*/
1414
1415#if defined(__cplusplus) || defined(c_plusplus)
1416extern "C" {
1417#endif
1418
1419static int DelegateCompare(const void *x,const void *y)
1420{
1421 const char
1422 **p,
1423 **q;
1424
1425 p=(const char **) x;
1426 q=(const char **) y;
1427 return(LocaleCompare(*p,*q));
1428}
1429
1430#if defined(__cplusplus) || defined(c_plusplus)
1431}
1432#endif
1433
1434MagickExport char **GetDelegateList(const char *pattern,
1435 size_t *number_delegates,ExceptionInfo *exception)
1436{
1437 char
1438 **delegates;
1439
1441 *p;
1442
1443 ssize_t
1444 i;
1445
1446 assert(pattern != (char *) NULL);
1447 if (IsEventLogging() != MagickFalse)
1448 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1449 assert(number_delegates != (size_t *) NULL);
1450 *number_delegates=0;
1451 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1452 return((char **) NULL);
1453 delegates=(char **) AcquireQuantumMemory((size_t)
1454 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1455 if (delegates == (char **) NULL)
1456 return((char **) NULL);
1457 LockSemaphoreInfo(delegate_semaphore);
1458 p=GetHeadElementInLinkedList(delegate_cache);
1459 for (i=0; p != (ElementInfo *) NULL; )
1460 {
1461 const DelegateInfo
1462 *delegate_info;
1463
1464 delegate_info=(const DelegateInfo *) p->value;
1465 if ((delegate_info->stealth == MagickFalse) &&
1466 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse))
1467 delegates[i++]=ConstantString(delegate_info->decode);
1468 if ((delegate_info->stealth == MagickFalse) &&
1469 (GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1470 delegates[i++]=ConstantString(delegate_info->encode);
1471 p=p->next;
1472 }
1473 UnlockSemaphoreInfo(delegate_semaphore);
1474 if (i == 0)
1475 delegates=(char **) RelinquishMagickMemory(delegates);
1476 else
1477 {
1478 qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
1479 delegates[i]=(char *) NULL;
1480 }
1481 *number_delegates=(size_t) i;
1482 return(delegates);
1483}
1484
1485/*
1486%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1487% %
1488% %
1489% %
1490% G e t D e l e g a t e M o d e %
1491% %
1492% %
1493% %
1494%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495%
1496% GetDelegateMode() returns the mode of the delegate.
1497%
1498% The format of the GetDelegateMode method is:
1499%
1500% ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1501%
1502% A description of each parameter follows:
1503%
1504% o delegate_info: The delegate info.
1505%
1506*/
1507MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1508{
1509 if (IsEventLogging() != MagickFalse)
1510 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1511 assert(delegate_info != (DelegateInfo *) NULL);
1512 assert(delegate_info->signature == MagickCoreSignature);
1513 return(delegate_info->mode);
1514}
1515
1516/*
1517%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1518% %
1519% %
1520% %
1521+ G e t D e l e g a t e T h r e a d S u p p o r t %
1522% %
1523% %
1524% %
1525%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526%
1527% GetDelegateThreadSupport() returns MagickTrue if the delegate supports
1528% threads.
1529%
1530% The format of the GetDelegateThreadSupport method is:
1531%
1532% MagickBooleanType GetDelegateThreadSupport(
1533% const DelegateInfo *delegate_info)
1534%
1535% A description of each parameter follows:
1536%
1537% o delegate_info: The delegate info.
1538%
1539*/
1540MagickExport MagickBooleanType GetDelegateThreadSupport(
1541 const DelegateInfo *delegate_info)
1542{
1543 assert(delegate_info != (DelegateInfo *) NULL);
1544 assert(delegate_info->signature == MagickCoreSignature);
1545 if (IsEventLogging() != MagickFalse)
1546 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1547 return(delegate_info->thread_support);
1548}
1549
1550/*
1551%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1552% %
1553% %
1554% %
1555+ I s D e l e g a t e C a c h e I n s t a n t i a t e d %
1556% %
1557% %
1558% %
1559%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1560%
1561% IsDelegateCacheInstantiated() determines if the delegate cache is
1562% instantiated. If not, it instantiates the cache and returns it.
1563%
1564% The format of the IsDelegateInstantiated method is:
1565%
1566% MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1567%
1568% A description of each parameter follows.
1569%
1570% o exception: return any errors or warnings in this structure.
1571%
1572*/
1573static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1574{
1575 if (delegate_cache == (LinkedListInfo *) NULL)
1576 {
1577 if (delegate_semaphore == (SemaphoreInfo *) NULL)
1578 ActivateSemaphoreInfo(&delegate_semaphore);
1579 LockSemaphoreInfo(delegate_semaphore);
1580 if (delegate_cache == (LinkedListInfo *) NULL)
1581 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1582 UnlockSemaphoreInfo(delegate_semaphore);
1583 }
1584 return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1585}
1586
1587/*
1588%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1589% %
1590% %
1591% %
1592% I n v o k e D e l e g a t e %
1593% %
1594% %
1595% %
1596%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1597%
1598% InvokeDelegate replaces any embedded formatting characters with the
1599% appropriate image attribute and executes the resulting command. MagickFalse
1600% is returned if the commands execute with success otherwise MagickTrue.
1601%
1602% The format of the InvokeDelegate method is:
1603%
1604% MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
1605% const char *decode,const char *encode,ExceptionInfo *exception)
1606%
1607% A description of each parameter follows:
1608%
1609% o image_info: the imageInfo.
1610%
1611% o image: the image.
1612%
1613% o exception: return any errors or warnings in this structure.
1614%
1615*/
1616
1617static MagickBooleanType CopyDelegateFile(const char *source,
1618 const char *destination,const MagickBooleanType overwrite)
1619{
1620 int
1621 destination_file,
1622 source_file;
1623
1624 MagickBooleanType
1625 status;
1626
1627 ssize_t
1628 count,
1629 i;
1630
1631 size_t
1632 length,
1633 quantum;
1634
1635 struct stat
1636 attributes;
1637
1638 unsigned char
1639 *buffer;
1640
1641 /*
1642 Copy source file to destination.
1643 */
1644 assert(source != (const char *) NULL);
1645 assert(destination != (char *) NULL);
1646 if (overwrite == MagickFalse)
1647 {
1648 status=GetPathAttributes(destination,&attributes);
1649 if (status != MagickFalse)
1650 return(MagickTrue);
1651 }
1652 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1653 if (destination_file == -1)
1654 return(MagickFalse);
1655 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1656 if (source_file == -1)
1657 {
1658 (void) close(destination_file);
1659 return(MagickFalse);
1660 }
1661 quantum=(size_t) MagickMaxBufferExtent;
1662 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1663 quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
1664 buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
1665 if (buffer == (unsigned char *) NULL)
1666 {
1667 (void) close(source_file);
1668 (void) close(destination_file);
1669 return(MagickFalse);
1670 }
1671 length=0;
1672 for (i=0; ; i+=(ssize_t) count)
1673 {
1674 count=(ssize_t) read(source_file,buffer,quantum);
1675 if (count <= 0)
1676 break;
1677 length=(size_t) count;
1678 count=(ssize_t) write(destination_file,buffer,length);
1679 if ((size_t) count != length)
1680 break;
1681 }
1682 (void) close(destination_file);
1683 (void) close(source_file);
1684 buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1685 return(i != 0 ? MagickTrue : MagickFalse);
1686}
1687
1688MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
1689 Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
1690{
1691 char
1692 *command,
1693 **commands,
1694 input_filename[MagickPathExtent],
1695 output_filename[MagickPathExtent];
1696
1697 const DelegateInfo
1698 *delegate_info;
1699
1700 MagickBooleanType
1701 status,
1702 temporary;
1703
1704 PolicyRights
1705 rights;
1706
1707 ssize_t
1708 i;
1709
1710 /*
1711 Get delegate.
1712 */
1713 assert(image_info != (ImageInfo *) NULL);
1714 assert(image_info->signature == MagickCoreSignature);
1715 assert(image != (Image *) NULL);
1716 assert(image->signature == MagickCoreSignature);
1717 if (IsEventLogging() != MagickFalse)
1718 (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1719 rights=ExecutePolicyRights;
1720 if ((decode != (const char *) NULL) &&
1721 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1722 {
1723 errno=EPERM;
1724 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1725 "NotAuthorized","`%s'",decode);
1726 return(MagickFalse);
1727 }
1728 if ((encode != (const char *) NULL) &&
1729 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1730 {
1731 errno=EPERM;
1732 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1733 "NotAuthorized","`%s'",encode);
1734 return(MagickFalse);
1735 }
1736 temporary=*image->filename == '\0' ? MagickTrue : MagickFalse;
1737 if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1738 MagickFalse))
1739 {
1740 ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
1741 image->filename);
1742 return(MagickFalse);
1743 }
1744 delegate_info=GetDelegateInfo(decode,encode,exception);
1745 if (delegate_info == (DelegateInfo *) NULL)
1746 {
1747 if (temporary != MagickFalse)
1748 (void) RelinquishUniqueFileResource(image->filename);
1749 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1750 "NoTagFound","`%s'",decode ? decode : encode);
1751 return(MagickFalse);
1752 }
1753 if (*image_info->filename == '\0')
1754 {
1755 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1756 {
1757 if (temporary != MagickFalse)
1758 (void) RelinquishUniqueFileResource(image->filename);
1759 ThrowFileException(exception,FileOpenError,
1760 "UnableToCreateTemporaryFile",image_info->filename);
1761 return(MagickFalse);
1762 }
1763 image_info->temporary=MagickTrue;
1764 }
1765 if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
1766 (delegate_info->encode != (char *) NULL)) ||
1767 ((encode != (const char *) NULL) &&
1768 (delegate_info->decode != (char *) NULL))))
1769 {
1770 char
1771 *magick;
1772
1773 ImageInfo
1774 *clone_info;
1775
1776 Image
1777 *p;
1778
1779 /*
1780 Delegate requires a particular image format.
1781 */
1782 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1783 {
1784 ThrowFileException(exception,FileOpenError,
1785 "UnableToCreateTemporaryFile",image_info->unique);
1786 return(MagickFalse);
1787 }
1788 magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
1789 delegate_info->encode : delegate_info->decode,exception);
1790 if (magick == (char *) NULL)
1791 {
1792 (void) RelinquishUniqueFileResource(image_info->unique);
1793 if (temporary != MagickFalse)
1794 (void) RelinquishUniqueFileResource(image->filename);
1795 (void) ThrowMagickException(exception,GetMagickModule(),
1796 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1797 return(MagickFalse);
1798 }
1799 LocaleUpper(magick);
1800 clone_info=CloneImageInfo(image_info);
1801 (void) CopyMagickString((char *) clone_info->magick,magick,
1802 MagickPathExtent);
1803 if (LocaleCompare(magick,"NULL") != 0)
1804 (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1805 magick=DestroyString(magick);
1806 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,"%s:",
1807 delegate_info->decode);
1808 (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
1809 exception);
1810 (void) CopyMagickString(clone_info->filename,image_info->filename,
1811 MagickPathExtent);
1812 (void) CopyMagickString(image_info->filename,image->filename,
1813 MagickPathExtent);
1814 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1815 {
1816 (void) FormatLocaleString(p->filename,MagickPathExtent,"%s:%s",
1817 delegate_info->decode,clone_info->filename);
1818 status=WriteImage(clone_info,p,exception);
1819 if (status == MagickFalse)
1820 {
1821 (void) RelinquishUniqueFileResource(image_info->unique);
1822 if (temporary != MagickFalse)
1823 (void) RelinquishUniqueFileResource(image->filename);
1824 clone_info=DestroyImageInfo(clone_info);
1825 (void) ThrowMagickException(exception,GetMagickModule(),
1826 DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1827 return(MagickFalse);
1828 }
1829 if (clone_info->adjoin != MagickFalse)
1830 break;
1831 }
1832 (void) RelinquishUniqueFileResource(image_info->unique);
1833 clone_info=DestroyImageInfo(clone_info);
1834 }
1835 /*
1836 Invoke delegate.
1837 */
1838 commands=StringToList(delegate_info->commands);
1839 if (commands == (char **) NULL)
1840 {
1841 if (temporary != MagickFalse)
1842 (void) RelinquishUniqueFileResource(image->filename);
1843 (void) ThrowMagickException(exception,GetMagickModule(),
1844 ResourceLimitError,"MemoryAllocationFailed","`%s'",
1845 decode ? decode : encode);
1846 return(MagickFalse);
1847 }
1848 command=(char *) NULL;
1849 status=MagickTrue;
1850 (void) CopyMagickString(output_filename,image_info->filename,
1851 MagickPathExtent);
1852 (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1853 for (i=0; commands[i] != (char *) NULL; i++)
1854 {
1855 (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1856 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1857 {
1858 ThrowFileException(exception,FileOpenError,
1859 "UnableToCreateTemporaryFile",image_info->unique);
1860 break;
1861 }
1862 if (LocaleCompare(decode,"SCAN") != 0)
1863 {
1864 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1865 if (status == MagickFalse)
1866 {
1867 ThrowFileException(exception,FileOpenError,
1868 "UnableToCreateTemporaryFile",input_filename);
1869 break;
1870 }
1871 }
1872 status=MagickTrue;
1873 command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1874 if (command != (char *) NULL)
1875 {
1876 /*
1877 Execute delegate.
1878 */
1879 if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1880 command,(char *) NULL,exception) != 0)
1881 status=MagickFalse;
1882 if (delegate_info->spawn != MagickFalse)
1883 {
1884 ssize_t
1885 count;
1886
1887 /*
1888 Wait for input file to 'disappear', or maximum 2 seconds.
1889 */
1890 count=20;
1891 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1892 (void) MagickDelay(100); /* sleep 0.1 seconds */
1893 }
1894 command=DestroyString(command);
1895 }
1896 if (LocaleCompare(decode,"SCAN") != 0)
1897 {
1898 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1899 (void) RelinquishUniqueFileResource(input_filename);
1900 }
1901 if ((strcmp(input_filename,output_filename) != 0) &&
1902 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1903 (void) RelinquishUniqueFileResource(output_filename);
1904 if (image_info->temporary != MagickFalse)
1905 (void) RelinquishUniqueFileResource(image_info->filename);
1906 (void) RelinquishUniqueFileResource(image_info->unique);
1907 (void) RelinquishUniqueFileResource(image_info->filename);
1908 (void) RelinquishUniqueFileResource(image->filename);
1909 if (status == MagickFalse)
1910 {
1911 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1912 "DelegateFailed","`%s'",commands[i]);
1913 break;
1914 }
1915 commands[i]=DestroyString(commands[i]);
1916 }
1917 (void) CopyMagickString(image_info->filename,output_filename,
1918 MagickPathExtent);
1919 (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
1920 /*
1921 Relinquish resources.
1922 */
1923 for ( ; commands[i] != (char *) NULL; i++)
1924 commands[i]=DestroyString(commands[i]);
1925 commands=(char **) RelinquishMagickMemory(commands);
1926 if (temporary != MagickFalse)
1927 (void) RelinquishUniqueFileResource(image->filename);
1928 return(status);
1929}
1930
1931/*
1932%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1933% %
1934% %
1935% %
1936% L i s t D e l e g a t e I n f o %
1937% %
1938% %
1939% %
1940%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1941%
1942% ListDelegateInfo() lists the image formats to a file.
1943%
1944% The format of the ListDelegateInfo method is:
1945%
1946% MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1947%
1948% A description of each parameter follows.
1949%
1950% o file: An pointer to a FILE.
1951%
1952% o exception: return any errors or warnings in this structure.
1953%
1954*/
1955MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1956 ExceptionInfo *exception)
1957{
1958 const DelegateInfo
1959 **delegate_info;
1960
1961 char
1962 **commands,
1963 delegate[MagickPathExtent];
1964
1965 const char
1966 *path;
1967
1968 ssize_t
1969 i;
1970
1971 size_t
1972 number_delegates;
1973
1974 ssize_t
1975 j;
1976
1977 if (file == (const FILE *) NULL)
1978 file=stdout;
1979 delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1980 if (delegate_info == (const DelegateInfo **) NULL)
1981 return(MagickFalse);
1982 path=(const char *) NULL;
1983 for (i=0; i < (ssize_t) number_delegates; i++)
1984 {
1985 if (delegate_info[i]->stealth != MagickFalse)
1986 continue;
1987 if ((path == (const char *) NULL) ||
1988 (LocaleCompare(path,delegate_info[i]->path) != 0))
1989 {
1990 if (delegate_info[i]->path != (char *) NULL)
1991 (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path);
1992 (void) FormatLocaleFile(file,"Delegate Command\n");
1993 (void) FormatLocaleFile(file,
1994 "-------------------------------------------------"
1995 "------------------------------\n");
1996 }
1997 path=delegate_info[i]->path;
1998 *delegate='\0';
1999 if (delegate_info[i]->encode != (char *) NULL)
2000 (void) CopyMagickString(delegate,delegate_info[i]->encode,
2001 MagickPathExtent);
2002 (void) ConcatenateMagickString(delegate," ",MagickPathExtent);
2003 delegate[8]='\0';
2004 commands=StringToList(delegate_info[i]->commands);
2005 if (commands == (char **) NULL)
2006 continue;
2007 (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
2008 delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
2009 delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
2010 (void) StripMagickString(commands[0]);
2011 (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]);
2012 for (j=1; commands[j] != (char *) NULL; j++)
2013 {
2014 (void) StripMagickString(commands[j]);
2015 (void) FormatLocaleFile(file," \"%s\"\n",commands[j]);
2016 }
2017 for (j=0; commands[j] != (char *) NULL; j++)
2018 commands[j]=DestroyString(commands[j]);
2019 commands=(char **) RelinquishMagickMemory(commands);
2020 }
2021 (void) fflush(file);
2022 delegate_info=(const DelegateInfo **)
2023 RelinquishMagickMemory((void *) delegate_info);
2024 return(MagickTrue);
2025}
2026
2027/*
2028%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2029% %
2030% %
2031% %
2032+ L o a d D e l e g a t e C a c h e %
2033% %
2034% %
2035% %
2036%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2037%
2038% LoadDelegateCache() loads the delegate configurations which provides a
2039% mapping between delegate attributes and a delegate name.
2040%
2041% The format of the LoadDelegateCache method is:
2042%
2043% MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
2044% const char *xml,const char *filename,const size_t depth,
2045% ExceptionInfo *exception)
2046%
2047% A description of each parameter follows:
2048%
2049% o xml: The delegate list in XML format.
2050%
2051% o filename: The delegate list filename.
2052%
2053% o depth: depth of <include /> statements.
2054%
2055% o exception: return any errors or warnings in this structure.
2056%
2057*/
2058static MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
2059 const char *xml,const char *filename,const size_t depth,
2060 ExceptionInfo *exception)
2061{
2062 char
2063 keyword[MagickPathExtent],
2064 *token;
2065
2066 const char
2067 *q;
2068
2070 *delegate_info;
2071
2072 MagickStatusType
2073 status;
2074
2075 size_t
2076 extent;
2077
2078 /*
2079 Load the delegate map file.
2080 */
2081 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2082 "Loading delegate configuration file \"%s\" ...",filename);
2083 if (xml == (const char *) NULL)
2084 return(MagickFalse);
2085 status=MagickTrue;
2086 delegate_info=(DelegateInfo *) NULL;
2087 token=AcquireString(xml);
2088 extent=strlen(token)+MagickPathExtent;
2089 for (q=(const char *) xml; *q != '\0'; )
2090 {
2091 /*
2092 Interpret XML.
2093 */
2094 (void) GetNextToken(q,&q,extent,token);
2095 if (*token == '\0')
2096 break;
2097 (void) CopyMagickString(keyword,token,MagickPathExtent);
2098 if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
2099 {
2100 /*
2101 Doctype element.
2102 */
2103 while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
2104 (void) GetNextToken(q,&q,extent,token);
2105 continue;
2106 }
2107 if (LocaleNCompare(keyword,"<!--",4) == 0)
2108 {
2109 /*
2110 Comment element.
2111 */
2112 while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
2113 (void) GetNextToken(q,&q,extent,token);
2114 continue;
2115 }
2116 if (LocaleCompare(keyword,"<include") == 0)
2117 {
2118 /*
2119 Include element.
2120 */
2121 while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
2122 {
2123 (void) CopyMagickString(keyword,token,MagickPathExtent);
2124 (void) GetNextToken(q,&q,extent,token);
2125 if (*token != '=')
2126 continue;
2127 (void) GetNextToken(q,&q,extent,token);
2128 if (LocaleCompare(keyword,"file") == 0)
2129 {
2130 if (depth > MagickMaxRecursionDepth)
2131 (void) ThrowMagickException(exception,GetMagickModule(),
2132 ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
2133 else
2134 {
2135 char
2136 path[MagickPathExtent],
2137 *file_xml;
2138
2139 GetPathComponent(filename,HeadPath,path);
2140 if (*path != '\0')
2141 (void) ConcatenateMagickString(path,DirectorySeparator,
2142 MagickPathExtent);
2143 if (*token == *DirectorySeparator)
2144 (void) CopyMagickString(path,token,MagickPathExtent);
2145 else
2146 (void) ConcatenateMagickString(path,token,MagickPathExtent);
2147 file_xml=FileToXML(path,~0UL);
2148 if (file_xml != (char *) NULL)
2149 {
2150 status&=(MagickStatusType) LoadDelegateCache(cache,
2151 file_xml,path,depth+1,exception);
2152 file_xml=DestroyString(file_xml);
2153 }
2154 }
2155 }
2156 }
2157 continue;
2158 }
2159 if (LocaleCompare(keyword,"<delegate") == 0)
2160 {
2161 /*
2162 Delegate element.
2163 */
2164 delegate_info=(DelegateInfo *) AcquireCriticalMemory(
2165 sizeof(*delegate_info));
2166 (void) memset(delegate_info,0,sizeof(*delegate_info));
2167 delegate_info->path=ConstantString(filename);
2168 delegate_info->thread_support=MagickTrue;
2169 delegate_info->signature=MagickCoreSignature;
2170 continue;
2171 }
2172 if (delegate_info == (DelegateInfo *) NULL)
2173 continue;
2174 if ((LocaleCompare(keyword,"/>") == 0) ||
2175 (LocaleCompare(keyword,"</policy>") == 0))
2176 {
2177 status=AppendValueToLinkedList(cache,delegate_info);
2178 if (status == MagickFalse)
2179 (void) ThrowMagickException(exception,GetMagickModule(),
2180 ResourceLimitError,"MemoryAllocationFailed","`%s'",
2181 delegate_info->commands);
2182 delegate_info=(DelegateInfo *) NULL;
2183 continue;
2184 }
2185 (void) GetNextToken(q,(const char **) NULL,extent,token);
2186 if (*token != '=')
2187 continue;
2188 (void) GetNextToken(q,&q,extent,token);
2189 (void) GetNextToken(q,&q,extent,token);
2190 switch (*keyword)
2191 {
2192 case 'C':
2193 case 'c':
2194 {
2195 if (LocaleCompare((char *) keyword,"command") == 0)
2196 {
2197 char
2198 *commands;
2199
2200 commands=AcquireString(token);
2201#if defined(MAGICKCORE_WINDOWS_SUPPORT)
2202 if (strchr(commands,'@') != (char *) NULL)
2203 {
2204 char
2205 path[MagickPathExtent];
2206
2207 NTGhostscriptEXE(path,MagickPathExtent);
2208 (void) SubstituteString((char **) &commands,"@PSDelegate@",
2209 path);
2210 (void) SubstituteString((char **) &commands,"\\","/");
2211 }
2212 (void) SubstituteString((char **) &commands,"&quot;","\"");
2213#else
2214 (void) SubstituteString((char **) &commands,"&quot;","'");
2215#endif
2216 (void) SubstituteString((char **) &commands,"&amp;","&");
2217 (void) SubstituteString((char **) &commands,"&gt;",">");
2218 (void) SubstituteString((char **) &commands,"&lt;","<");
2219 if (delegate_info->commands != (char *) NULL)
2220 delegate_info->commands=DestroyString(delegate_info->commands);
2221 delegate_info->commands=commands;
2222 break;
2223 }
2224 break;
2225 }
2226 case 'D':
2227 case 'd':
2228 {
2229 if (LocaleCompare((char *) keyword,"decode") == 0)
2230 {
2231 delegate_info->decode=ConstantString(token);
2232 delegate_info->mode=1;
2233 break;
2234 }
2235 break;
2236 }
2237 case 'E':
2238 case 'e':
2239 {
2240 if (LocaleCompare((char *) keyword,"encode") == 0)
2241 {
2242 delegate_info->encode=ConstantString(token);
2243 delegate_info->mode=(-1);
2244 break;
2245 }
2246 break;
2247 }
2248 case 'M':
2249 case 'm':
2250 {
2251 if (LocaleCompare((char *) keyword,"mode") == 0)
2252 {
2253 delegate_info->mode=1;
2254 if (LocaleCompare(token,"bi") == 0)
2255 delegate_info->mode=0;
2256 else
2257 if (LocaleCompare(token,"encode") == 0)
2258 delegate_info->mode=(-1);
2259 break;
2260 }
2261 break;
2262 }
2263 case 'S':
2264 case 's':
2265 {
2266 if (LocaleCompare((char *) keyword,"spawn") == 0)
2267 {
2268 delegate_info->spawn=IsStringTrue(token);
2269 break;
2270 }
2271 if (LocaleCompare((char *) keyword,"stealth") == 0)
2272 {
2273 delegate_info->stealth=IsStringTrue(token);
2274 break;
2275 }
2276 break;
2277 }
2278 case 'T':
2279 case 't':
2280 {
2281 if (LocaleCompare((char *) keyword,"thread-support") == 0)
2282 {
2283 delegate_info->thread_support=IsStringTrue(token);
2284 if (delegate_info->thread_support == MagickFalse)
2285 delegate_info->semaphore=AcquireSemaphoreInfo();
2286 break;
2287 }
2288 break;
2289 }
2290 default:
2291 break;
2292 }
2293 }
2294 token=(char *) RelinquishMagickMemory(token);
2295 return(status != 0 ? MagickTrue : MagickFalse);
2296}