MagickCore  7.1.0
delegate.c
Go to the documentation of this file.
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-2021 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"
57 #include "MagickCore/exception.h"
59 #include "MagickCore/fx-private.h"
61 #include "MagickCore/linked-list.h"
62 #include "MagickCore/list.h"
63 #include "MagickCore/memory_.h"
66 #include "MagickCore/option.h"
67 #include "MagickCore/policy.h"
68 #include "MagickCore/property.h"
69 #include "MagickCore/resource_.h"
70 #include "MagickCore/semaphore.h"
71 #include "MagickCore/signature.h"
72 #include "MagickCore/string_.h"
73 #include "MagickCore/token.h"
75 #include "MagickCore/utility.h"
77 #include "MagickCore/xml-tree.h"
79 
80 /*
81  Define declarations.
82 */
83 #if defined(__APPLE__)
84  #include "TargetConditionals.h"
85  #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
86  #define system(s) ((s)==NULL ? 0 : -1)
87  #endif // end iOS
88 #elif defined(__ANDROID__)
89  #define system(s) ((s)==NULL ? 0 : -1)
90 #endif
91 #define DelegateFilename "delegates.xml"
92 
93 /*
94  Declare delegate map.
95 */
96 static const char
97  *DelegateMap = (const char *)
98  "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
99  "<delegatemap>"
100  " <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;\"/>"
101  " <delegate decode=\"png\" encode=\"bpg\" command=\"&quot;bpgenc&quot; -b 12 -q %~ -o &quot;%o&quot; &quot;%i&quot;\"/>"
102  " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\"&quot;xdg-open&quot; https://imagemagick.org/; rm &quot;%i&quot;\"/>"
103  " <delegate decode=\"cdr\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
104  " <delegate decode=\"cgm\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
105  " <delegate decode=\"https\" command=\"&quot;curl&quot; -s -k -L -o &quot;%o&quot; &quot;https:%M&quot;\"/>"
106  " <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;\"/>"
107  " <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;\"/>"
108  " <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;\"/>"
109  " <delegate decode=\"dot\" command=\"&quot;dot&quot; -Tsvg &quot;%i&quot; -o &quot;%o&quot;\"/>"
110  " <delegate decode=\"dvi\" command=\"&quot;dvips&quot; -sstdout=%%stderr -o &quot;%o&quot; &quot;%i&quot;\"/>"
111  " <delegate decode=\"dxf\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
112  " <delegate decode=\"edit\" stealth=\"True\" command=\"&quot;xterm&quot; -title &quot;Edit Image Comment&quot; -e vi &quot;%o&quot;\"/>"
113  " <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;\"/>"
114  " <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;\"/>"
115  " <delegate decode=\"fig\" command=\"&quot;uniconvertor&quot; &quot;%i&quot; &quot;%o.svg&quot;; mv &quot;%o.svg&quot; &quot;%o&quot;\"/>"
116  " <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;\"/>"
117  " <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;\"/>"
118  " <delegate decode=\"htm\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
119  " <delegate decode=\"html\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
120  " <delegate decode=\"ilbm\" command=\"&quot;ilbmtoppm&quot; &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
121  " <delegate decode=\"jpg\" encode=\"lep\" mode=\"encode\" command=\"&quot;lepton&quot; &quot;%i&quot; &quot;%o&quot;\"/>"
122  " <delegate decode=\"jxr\" command=\"mv &quot;%i&quot; &quot;%i.jxr&quot;; &quot;JxrDecApp&quot; -i &quot;%i.jxr&quot; -o &quot;%o.pnm&quot;; mv &quot;%i.jxr&quot; &quot;%i&quot;; mv &quot;%o.pnm&quot; &quot;%o&quot;\"/>"
123  " <delegate decode=\"lep\" mode=\"decode\" command=\"&quot;lepton&quot; &quot;%i&quot; &quot;%o&quot;\"/>"
124  " <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;\"/>"
125  " <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;\"/>"
126  " <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;\"/>"
127  " <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;\"/>"
128  " <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;\"/>"
129  " <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;\"/>"
130  " <delegate decode=\"png\" encode=\"webp\" command=\"&quot;cwebp&quot; -quiet -q %Q &quot;%i&quot; -o &quot;%o&quot;\"/>"
131  " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\"&quot;ppmtoilbm&quot; -24if &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
132  " <delegate decode=\"bmp\" encode=\"jxr\" command=\"mv &quot;%i&quot; &quot;%i.bmp&quot;; &quot;JxrEncApp&quot; -i &quot;%i.bmp&quot; -o &quot;%o.jxr&quot;; mv &quot;%i.bmp&quot; &quot;%i&quot;; mv &quot;%o.jxr&quot; &quot;%o&quot;\"/>"
133  " <delegate decode=\"bmp\" encode=\"wdp\" command=\"mv &quot;%i&quot; &quot;%i.bmp&quot;; &quot;JxrEncApp&quot; -i &quot;%i.bmp&quot; -o &quot;%o.jxr&quot;; mv &quot;%i.bmp&quot; &quot;%i&quot;; mv &quot;%o.jxr&quot; &quot;%o&quot;\"/>"
134  " <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;\"/>"
135  " <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;\"/>"
136  " <delegate decode=\"ps\" encode=\"prt\" command=\"&quot;lpr&quot; &quot;%i&quot;\"/>"
137  " <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;\"/>"
138  " <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;\"/>"
139  " <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;\"/>"
140  " <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;\"/>"
141  " <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;\"/>"
142  " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr &quot;%i&quot;\"/>"
143  " <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;\"/>"
144  " <delegate decode=\"shtml\" command=\"&quot;html2ps&quot; -U -o &quot;%o&quot; &quot;%i&quot;\"/>"
145  " <delegate decode=\"sid\" command=\"&quot;mrsidgeodecode&quot; -if sid -i &quot;%i&quot; -of tif -o &quot;%o&quot; &gt; &quot;%u&quot;\"/>"
146  " <delegate decode=\"svg\" command=\"&quot;rsvg-convert&quot; -o &quot;%o&quot; &quot;%i&quot;\"/>"
147  " <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; &gt; &quot;%s&quot; 2&gt;&amp;1\"/>"
148  " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\"&quot;gimp&quot; &quot;%i&quot;\"/>"
149  " <delegate decode=\"wdp\" command=\"mv &quot;%i&quot; &quot;%i.jxr&quot;; &quot;JxrDecApp&quot; -i &quot;%i.jxr&quot; -o &quot;%o.bmp&quot;; mv &quot;%i.jxr&quot; &quot;%i&quot;; mv &quot;%o.bmp&quot; &quot;%o&quot;\"/>"
150  " <delegate decode=\"webp\" command=\"&quot;dwebp&quot; -pam &quot;%i&quot; -o &quot;%o&quot;\"/>"
151  " <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;\"/>"
152  " <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;\"/>"
153  " <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;\"/>"
154  " <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;\"/>"
155  " <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;\"/>"
156  " <delegate decode=\"mpeg:decode\" command=\"&quot;ffmpeg&quot; -v -1 -i &quot;%i&quot; -vframes %S -vcodec pam -an -f rawvideo -y &quot;%u.pam&quot; 2&gt; &quot;%u&quot;\"/>"
157  " <delegate encode=\"mpeg:encode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -v -1 -i &quot;%M%%d.jpg&quot; -plays %I &quot;%u.%m&quot; 2&gt; &quot;%u&quot;\"/>"
158  "</delegatemap>";
159 
160 /*
161  Global declaractions.
162 */
163 static LinkedListInfo
165 
166 static SemaphoreInfo
168 
169 /*
170  Forward declaractions.
171 */
172 static MagickBooleanType
174  LoadDelegateCache(LinkedListInfo *,const char *,const char *,const size_t,
175  ExceptionInfo *);
176 
177 /*
178 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
179 % %
180 % %
181 % %
182 % A c q u i r e D e l e g a t e C a c h e %
183 % %
184 % %
185 % %
186 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
187 %
188 % AcquireDelegateCache() caches one or more delegate configurations which
189 % provides a mapping between delegate attributes and a delegate name.
190 %
191 % The format of the AcquireDelegateCache method is:
192 %
193 % LinkedListInfo *AcquireDelegateCache(const char *filename,
194 % ExceptionInfo *exception)
195 %
196 % A description of each parameter follows:
197 %
198 % o filename: the font file name.
199 %
200 % o exception: return any errors or warnings in this structure.
201 %
202 */
203 static LinkedListInfo *AcquireDelegateCache(const char *filename,
204  ExceptionInfo *exception)
205 {
207  *cache;
208 
209  cache=NewLinkedList(0);
210 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
211  {
212  const StringInfo
213  *option;
214 
216  *options;
217 
218  options=GetConfigureOptions(filename,exception);
219  option=(const StringInfo *) GetNextValueInLinkedList(options);
220  while (option != (const StringInfo *) NULL)
221  {
222  (void) LoadDelegateCache(cache,(const char *)
223  GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
224  option=(const StringInfo *) GetNextValueInLinkedList(options);
225  }
226  options=DestroyConfigureOptions(options);
227  }
228 #endif
229  if (IsLinkedListEmpty(cache) != MagickFalse)
230  (void) LoadDelegateCache(cache,DelegateMap,"built-in",0,exception);
231  return(cache);
232 }
233 
234 /*
235 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
236 % %
237 % %
238 % %
239 + D e l e g a t e C o m p o n e n t G e n e s i s %
240 % %
241 % %
242 % %
243 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
244 %
245 % DelegateComponentGenesis() instantiates the delegate component.
246 %
247 % The format of the DelegateComponentGenesis method is:
248 %
249 % MagickBooleanType DelegateComponentGenesis(void)
250 %
251 */
253 {
254  if (delegate_semaphore == (SemaphoreInfo *) NULL)
256  return(MagickTrue);
257 }
258 
259 /*
260 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
261 % %
262 % %
263 % %
264 % 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 %
265 % %
266 % %
267 % %
268 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
269 %
270 % DelegateComponentTerminus() destroys the delegate component.
271 %
272 % The format of the DelegateComponentTerminus method is:
273 %
274 % DelegateComponentTerminus(void)
275 %
276 */
277 
278 static void *DestroyDelegate(void *delegate_info)
279 {
281  *p;
282 
283  p=(DelegateInfo *) delegate_info;
284  if (p->path != (char *) NULL)
285  p->path=DestroyString(p->path);
286  if (p->decode != (char *) NULL)
287  p->decode=DestroyString(p->decode);
288  if (p->encode != (char *) NULL)
289  p->encode=DestroyString(p->encode);
290  if (p->commands != (char *) NULL)
292  if (p->semaphore != (SemaphoreInfo *) NULL)
295  return((void *) NULL);
296 }
297 
299 {
300  if (delegate_semaphore == (SemaphoreInfo *) NULL)
303  if (delegate_cache != (LinkedListInfo *) NULL)
307 }
308 
309 /*
310 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
311 % %
312 % %
313 % %
314 + E x t e r n a l D e l e g a t e C o m m a n d %
315 % %
316 % %
317 % %
318 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
319 %
320 % ExternalDelegateCommand() executes the specified command and waits until it
321 % terminates. The returned value is the exit status of the command.
322 %
323 % The format of the ExternalDelegateCommand method is:
324 %
325 % int ExternalDelegateCommand(const MagickBooleanType asynchronous,
326 % const MagickBooleanType verbose,const char *command,
327 % char *message,ExceptionInfo *exception)
328 %
329 % A description of each parameter follows:
330 %
331 % o asynchronous: a value other than 0 executes the parent program
332 % concurrently with the new child process.
333 %
334 % o verbose: a value other than 0 prints the executed command before it is
335 % invoked.
336 %
337 % o command: this string is the command to execute.
338 %
339 % o message: an option buffer to receive any message posted to stdout or
340 % stderr.
341 %
342 % o exception: return any errors here.
343 %
344 */
346  const MagickBooleanType verbose,const char *command,char *message,
347  ExceptionInfo *exception)
348 {
349  char
350  **arguments,
351  *sanitize_command;
352 
353  int
354  number_arguments,
355  status;
356 
358  domain;
359 
361  rights;
362 
363  ssize_t
364  i;
365 
366  status=(-1);
367  arguments=StringToArgv(command,&number_arguments);
368  if (arguments == (char **) NULL)
369  return(status);
370  if (*arguments[1] == '\0')
371  {
372  for (i=0; i < (ssize_t) number_arguments; i++)
373  arguments[i]=DestroyString(arguments[i]);
374  arguments=(char **) RelinquishMagickMemory(arguments);
375  return(-1);
376  }
377  rights=ExecutePolicyRights;
378  domain=DelegatePolicyDomain;
379  if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
380  {
381  errno=EPERM;
383  "NotAuthorized","`%s'",arguments[1]);
384  for (i=0; i < (ssize_t) number_arguments; i++)
385  arguments[i]=DestroyString(arguments[i]);
386  arguments=(char **) RelinquishMagickMemory(arguments);
387  return(-1);
388  }
389  if (verbose != MagickFalse)
390  {
391  (void) FormatLocaleFile(stderr,"%s\n",command);
392  (void) fflush(stderr);
393  }
394  sanitize_command=SanitizeString(command);
395  if (asynchronous != MagickFalse)
396  (void) ConcatenateMagickString(sanitize_command,"&",MagickPathExtent);
397  if (message != (char *) NULL)
398  *message='\0';
399 #if defined(MAGICKCORE_POSIX_SUPPORT)
400 #if defined(MAGICKCORE_HAVE_POPEN)
401  if ((asynchronous == MagickFalse) && (message != (char *) NULL))
402  {
403  char
404  buffer[MagickPathExtent];
405 
406  FILE
407  *file;
408 
409  size_t
410  offset;
411 
412  offset=0;
413  file=popen_utf8(sanitize_command,"r");
414  if (file == (FILE *) NULL)
415  status=system(sanitize_command);
416  else
417  {
418  while (fgets(buffer,(int) sizeof(buffer),file) != NULL)
419  {
420  size_t
421  length;
422 
423  length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
424  if (length > 0)
425  {
426  (void) CopyMagickString(message+offset,buffer,length);
427  offset+=length-1;
428  }
429  }
430  status=pclose(file);
431  }
432  }
433  else
434 #endif
435  {
436 #if !defined(MAGICKCORE_HAVE_EXECVP)
437  status=system(sanitize_command);
438 #else
439  if ((asynchronous != MagickFalse) ||
440  (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
441  status=system(sanitize_command);
442  else
443  {
444  pid_t
445  child_pid;
446 
447  /*
448  Call application directly rather than from a shell.
449  */
450  child_pid=(pid_t) fork();
451  if (child_pid == (pid_t) -1)
452  status=system(sanitize_command);
453  else
454  if (child_pid == 0)
455  {
456  status=execvp(arguments[1],arguments+1);
457  _exit(1);
458  }
459  else
460  {
461  int
462  child_status;
463 
464  pid_t
465  pid;
466 
467  child_status=0;
468  pid=(pid_t) waitpid(child_pid,&child_status,0);
469  if (pid == -1)
470  status=(-1);
471  else
472  {
473  if (WIFEXITED(child_status) != 0)
474  status=WEXITSTATUS(child_status);
475  else
476  if (WIFSIGNALED(child_status))
477  status=(-1);
478  }
479  }
480  }
481 #endif
482  }
483 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
484  {
485  char
486  *p;
487 
488  /*
489  If a command shell is executed we need to change the forward slashes in
490  files to a backslash. We need to do this to keep Windows happy when we
491  want to 'move' a file.
492 
493  TODO: This won't work if one of the delegate parameters has a forward
494  slash as aparameter.
495  */
496  p=strstr(sanitize_command,"cmd.exe /c");
497  if (p != (char*) NULL)
498  {
499  p+=10;
500  for ( ; *p != '\0'; p++)
501  if (*p == '/')
502  *p=(*DirectorySeparator);
503  }
504  }
505  status=NTSystemCommand(sanitize_command,message);
506 #elif defined(vms)
507  status=system(sanitize_command);
508 #else
509 # error No suitable system() method.
510 #endif
511  if (status < 0)
512  {
513  if ((message != (char *) NULL) && (*message != '\0'))
515  "FailedToExecuteCommand","`%s' (%s)",sanitize_command,message);
516  else
518  "FailedToExecuteCommand","`%s' (%d)",sanitize_command,status);
519  }
520  sanitize_command=DestroyString(sanitize_command);
521  for (i=0; i < (ssize_t) number_arguments; i++)
522  arguments[i]=DestroyString(arguments[i]);
523  arguments=(char **) RelinquishMagickMemory(arguments);
524  return(status);
525 }
526 
527 /*
528 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
529 % %
530 % %
531 % %
532 % G e t D e l e g a t e C o m m a n d %
533 % %
534 % %
535 % %
536 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
537 %
538 % GetDelegateCommand() replaces any embedded formatting characters with the
539 % appropriate image attribute and returns the resulting command.
540 %
541 % The format of the GetDelegateCommand method is:
542 %
543 % char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
544 % const char *decode,const char *encode,ExceptionInfo *exception)
545 %
546 % A description of each parameter follows:
547 %
548 % o command: Method GetDelegateCommand returns the command associated
549 % with specified delegate tag.
550 %
551 % o image_info: the image info.
552 %
553 % o image: the image.
554 %
555 % o decode: Specifies the decode delegate we are searching for as a
556 % character string.
557 %
558 % o encode: Specifies the encode delegate we are searching for as a
559 % character string.
560 %
561 % o exception: return any errors or warnings in this structure.
562 %
563 */
564 
565 static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
566  const char letter,ExceptionInfo *exception)
567 {
568 #define WarnNoImageReturn(format,letter) \
569  if (image == (Image *) NULL) \
570  { \
571  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
572  "NoImageForProperty",format,letter); \
573  break; \
574  }
575 #define WarnNoImageInfoReturn(format,letter) \
576  if (image_info == (ImageInfo *) NULL) \
577  { \
578  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
579  "NoImageInfoForProperty",format,letter); \
580  break; \
581  }
582 
583  char
584  value[MagickPathExtent];
585 
586  const char
587  *string;
588 
589  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
590  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
591  else
592  if ((image_info != (ImageInfo *) NULL) &&
593  (image_info->debug != MagickFalse))
594  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
595  /*
596  Get properties that are directly defined by images.
597  */
598  *value='\0'; /* formatted string */
599  string=(const char *) value;
600  switch (letter)
601  {
602  case 'a': /* authentication passphase */
603  {
604  WarnNoImageInfoReturn("\"%%%c\"",letter);
605  string=GetImageOption(image_info,"authenticate");
606  break;
607  }
608  case 'b': /* image size read in - in bytes */
609  {
610  WarnNoImageReturn("\"%%%c\"",letter);
612  value);
613  if (image->extent == 0)
614  (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
615  MagickPathExtent,value);
616  break;
617  }
618  case 'd': /* Directory component of filename */
619  {
620  WarnNoImageReturn("\"%%%c\"",letter);
622  break;
623  }
624  case 'e': /* Filename extension (suffix) of image file */
625  {
626  WarnNoImageReturn("\"%%%c\"",letter);
628  break;
629  }
630  case 'f': /* Filename without directory component */
631  {
632  WarnNoImageReturn("\"%%%c\"",letter);
634  break;
635  }
636  case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
637  {
638  WarnNoImageReturn("\"%%%c\"",letter);
640  "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
641  image->page.height,(double) image->page.x,(double) image->page.y);
642  break;
643  }
644  case 'h': /* Image height (current) */
645  {
646  WarnNoImageReturn("\"%%%c\"",letter);
647  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
648  (image->rows != 0 ? image->rows : image->magick_rows));
649  break;
650  }
651  case 'i': /* Filename last used for an image (read or write) */
652  {
653  WarnNoImageReturn("\"%%%c\"",letter);
654  string=image->filename;
655  break;
656  }
657  case 'm': /* Image format (file magick) */
658  {
659  WarnNoImageReturn("\"%%%c\"",letter);
660  string=image->magick;
661  break;
662  }
663  case 'n': /* Number of images in the list. */
664  {
665  if (image != (Image *) NULL)
666  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
667  GetImageListLength(image));
668  break;
669  }
670  case 'o': /* Output Filename */
671  {
672  WarnNoImageInfoReturn("\"%%%c\"",letter);
673  string=image_info->filename;
674  break;
675  }
676  case 'p': /* Image index in current image list */
677  {
678  WarnNoImageReturn("\"%%%c\"",letter);
679  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
680  GetImageIndexInList(image));
681  break;
682  }
683  case 'q': /* Quantum depth of image in memory */
684  {
685  WarnNoImageReturn("\"%%%c\"",letter);
686  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
688  break;
689  }
690  case 'r': /* Image storage class, colorspace, and alpha enabled. */
691  {
693  colorspace;
694 
695  WarnNoImageReturn("\"%%%c\"",letter);
696  colorspace=image->colorspace;
697  (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
700  (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
701  "Alpha" : "");
702  break;
703  }
704  case 's': /* Image scene number */
705  {
706  WarnNoImageReturn("\"%%%c\"",letter);
707  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
708  image->scene);
709  break;
710  }
711  case 't': /* Base filename without directory or extention */
712  {
713  WarnNoImageReturn("\"%%%c\"",letter);
715  break;
716  }
717  case 'u': /* Unique filename */
718  {
719  WarnNoImageInfoReturn("\"%%%c\"",letter);
720  string=image_info->unique;
721  break;
722  }
723  case 'w': /* Image width (current) */
724  {
725  WarnNoImageReturn("\"%%%c\"",letter);
726  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
727  (image->columns != 0 ? image->columns : image->magick_columns));
728  break;
729  }
730  case 'x': /* Image horizontal resolution (with units) */
731  {
732  WarnNoImageReturn("\"%%%c\"",letter);
733  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
734  fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
737  break;
738  }
739  case 'y': /* Image vertical resolution (with units) */
740  {
741  WarnNoImageReturn("\"%%%c\"",letter);
742  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
743  fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
746  break;
747  }
748  case 'z': /* Image depth as read in */
749  {
750  WarnNoImageReturn("\"%%%c\"",letter);
751  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
752  (double) image->depth);
753  break;
754  }
755  case 'A': /* Image alpha channel */
756  {
757  WarnNoImageReturn("\"%%%c\"",letter);
759  image->alpha_trait);
760  break;
761  }
762  case 'C': /* Image compression method. */
763  {
764  WarnNoImageReturn("\"%%%c\"",letter);
766  (ssize_t) image->compression);
767  break;
768  }
769  case 'D': /* Image dispose method. */
770  {
771  WarnNoImageReturn("\"%%%c\"",letter);
773  (ssize_t) image->dispose);
774  break;
775  }
776  case 'F':
777  {
778  /*
779  Magick filename - filename given incl. coder & read mods.
780  */
781  WarnNoImageReturn("\"%%%c\"",letter);
783  break;
784  }
785  case 'G': /* Image size as geometry = "%wx%h" */
786  {
787  WarnNoImageReturn("\"%%%c\"",letter);
788  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
789  (double) image->magick_columns,(double) image->magick_rows);
790  break;
791  }
792  case 'H': /* layer canvas height */
793  {
794  WarnNoImageReturn("\"%%%c\"",letter);
795  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
796  (double) image->page.height);
797  break;
798  }
799  case 'I': /* image iterations for animations */
800  {
801  WarnNoImageReturn("\"%%%c\"",letter);
802  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
803  image->iterations);
804  break;
805  }
806  case 'M': /* Magick filename - filename given incl. coder & read mods */
807  {
808  WarnNoImageReturn("\"%%%c\"",letter);
809  string=image->magick_filename;
810  break;
811  }
812  case 'O': /* layer canvas offset with sign = "+%X+%Y" */
813  {
814  WarnNoImageReturn("\"%%%c\"",letter);
815  (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
816  image->page.x,(long) image->page.y);
817  break;
818  }
819  case 'P': /* layer canvas page size = "%Wx%H" */
820  {
821  WarnNoImageReturn("\"%%%c\"",letter);
822  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
823  (double) image->page.width,(double) image->page.height);
824  break;
825  }
826  case '~': /* BPG image compression quality */
827  {
828  WarnNoImageReturn("\"%%%c\"",letter);
829  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
830  (100-(image->quality == 0 ? 42 : image->quality))/2);
831  break;
832  }
833  case 'Q': /* image compression quality */
834  {
835  WarnNoImageReturn("\"%%%c\"",letter);
836  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
837  (image->quality == 0 ? 92 : image->quality));
838  break;
839  }
840  case 'S': /* Number of scenes in image list. */
841  {
842  WarnNoImageInfoReturn("\"%%%c\"",letter);
843  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
844  (image_info->number_scenes == 0 ? 2147483647 :
845  image_info->number_scenes));
846  break;
847  }
848  case 'T': /* image time delay for animations */
849  {
850  WarnNoImageReturn("\"%%%c\"",letter);
851  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
852  image->delay);
853  break;
854  }
855  case 'U': /* Image resolution units. */
856  {
857  WarnNoImageReturn("\"%%%c\"",letter);
859  (ssize_t) image->units);
860  break;
861  }
862  case 'W': /* layer canvas width */
863  {
864  WarnNoImageReturn("\"%%%c\"",letter);
865  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
866  image->page.width);
867  break;
868  }
869  case 'X': /* layer canvas X offset */
870  {
871  WarnNoImageReturn("\"%%%c\"",letter);
872  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
873  image->page.x);
874  break;
875  }
876  case 'Y': /* layer canvas Y offset */
877  {
878  WarnNoImageReturn("\"%%%c\"",letter);
879  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
880  image->page.y);
881  break;
882  }
883  case '%': /* percent escaped */
884  {
885  string="%";
886  break;
887  }
888  case '@': /* Trim bounding box, without actually trimming! */
889  {
891  page;
892 
893  WarnNoImageReturn("\"%%%c\"",letter);
894  page=GetImageBoundingBox(image,exception);
896  "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
897  (double) page.x,(double) page.y);
898  break;
899  }
900  case '#':
901  {
902  /*
903  Image signature.
904  */
905  WarnNoImageReturn("\"%%%c\"",letter);
906  (void) SignatureImage(image,exception);
907  string=GetImageProperty(image,"signature",exception);
908  break;
909  }
910  }
911  return(SanitizeDelegateString(string));
912 }
913 
914 static char *InterpretDelegateProperties(ImageInfo *image_info,
915  Image *image,const char *embed_text,ExceptionInfo *exception)
916 {
917 #define ExtendInterpretText(string_length) \
918 { \
919  size_t length=(string_length); \
920  if ((size_t) (q-interpret_text+length+1) >= extent) \
921  { \
922  extent+=length; \
923  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
924  MagickPathExtent,sizeof(*interpret_text)); \
925  if (interpret_text == (char *) NULL) \
926  return((char *) NULL); \
927  q=interpret_text+strlen(interpret_text); \
928  } \
929 }
930 
931 #define AppendKeyValue2Text(key,value)\
932 { \
933  size_t length=strlen(key)+strlen(value)+2; \
934  if ((size_t) (q-interpret_text+length+1) >= extent) \
935  { \
936  extent+=length; \
937  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
938  MagickPathExtent,sizeof(*interpret_text)); \
939  if (interpret_text == (char *) NULL) \
940  return((char *) NULL); \
941  q=interpret_text+strlen(interpret_text); \
942  } \
943  q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
944 }
945 
946 #define AppendString2Text(string) \
947 { \
948  size_t length=strlen((string)); \
949  if ((size_t) (q-interpret_text+length+1) >= extent) \
950  { \
951  extent+=length; \
952  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
953  MagickPathExtent,sizeof(*interpret_text)); \
954  if (interpret_text == (char *) NULL) \
955  return((char *) NULL); \
956  q=interpret_text+strlen(interpret_text); \
957  } \
958  (void) CopyMagickString(q,(string),extent); \
959  q+=length; \
960 }
961 
962  char
963  *interpret_text,
964  *string;
965 
966  char
967  *q; /* current position in interpret_text */
968 
969  const char
970  *p; /* position in embed_text string being expanded */
971 
972  size_t
973  extent; /* allocated length of interpret_text */
974 
976  number;
977 
978  assert(image == NULL || image->signature == MagickCoreSignature);
979  assert(image_info == NULL || image_info->signature == MagickCoreSignature);
980  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
981  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
982  else
983  if ((image_info != (ImageInfo *) NULL) && (image_info->debug != MagickFalse))
984  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
985  if (embed_text == (const char *) NULL)
986  return(ConstantString(""));
987  p=embed_text;
988  while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
989  p++;
990  if (*p == '\0')
991  return(ConstantString(""));
992  /*
993  Translate any embedded format characters.
994  */
995  interpret_text=AcquireString(embed_text); /* new string with extra space */
996  extent=MagickPathExtent; /* allocated space in string */
997  number=MagickFalse; /* is last char a number? */
998  for (q=interpret_text; *p!='\0';
999  number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
1000  {
1001  /*
1002  Interpret escape characters (e.g. Filename: %M).
1003  */
1004  *q='\0';
1006  switch (*p)
1007  {
1008  case '\\':
1009  {
1010  switch (*(p+1))
1011  {
1012  case '\0':
1013  continue;
1014  case 'r': /* convert to RETURN */
1015  {
1016  *q++='\r';
1017  p++;
1018  continue;
1019  }
1020  case 'n': /* convert to NEWLINE */
1021  {
1022  *q++='\n';
1023  p++;
1024  continue;
1025  }
1026  case '\n': /* EOL removal UNIX,MacOSX */
1027  {
1028  p++;
1029  continue;
1030  }
1031  case '\r': /* EOL removal DOS,Windows */
1032  {
1033  p++;
1034  if (*p == '\n') /* return-newline EOL */
1035  p++;
1036  continue;
1037  }
1038  default:
1039  {
1040  p++;
1041  *q++=(*p);
1042  }
1043  }
1044  continue;
1045  }
1046  case '&':
1047  {
1048  if (LocaleNCompare("&lt;",p,4) == 0)
1049  {
1050  *q++='<';
1051  p+=3;
1052  }
1053  else
1054  if (LocaleNCompare("&gt;",p,4) == 0)
1055  {
1056  *q++='>';
1057  p+=3;
1058  }
1059  else
1060  if (LocaleNCompare("&amp;",p,5) == 0)
1061  {
1062  *q++='&';
1063  p+=4;
1064  }
1065  else
1066  *q++=(*p);
1067  continue;
1068  }
1069  case '%':
1070  break; /* continue to next set of handlers */
1071  default:
1072  {
1073  *q++=(*p); /* any thing else is 'as normal' */
1074  continue;
1075  }
1076  }
1077  p++; /* advance beyond the percent */
1078  /*
1079  Doubled Percent - or percent at end of string.
1080  */
1081  if ((*p == '\0') || (*p == '\'') || (*p == '"'))
1082  p--;
1083  if (*p == '%')
1084  {
1085  *q++='%';
1086  continue;
1087  }
1088  /*
1089  Single letter escapes %c.
1090  */
1091  if (number != MagickFalse)
1092  {
1093  /*
1094  But only if not preceeded by a number!
1095  */
1096  *q++='%'; /* do NOT substitute the percent */
1097  p--; /* back up one */
1098  continue;
1099  }
1100  string=GetMagickPropertyLetter(image_info,image,*p,exception);
1101  if (string != (char *) NULL)
1102  {
1103  AppendString2Text(string);
1104  string=DestroyString(string);
1105  continue;
1106  }
1108  "UnknownImageProperty","\"%%%c\"",*p);
1109  }
1110  *q='\0';
1111  return(interpret_text);
1112 }
1113 
1114 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
1115  const char *decode,const char *encode,ExceptionInfo *exception)
1116 {
1117  char
1118  *command,
1119  **commands;
1120 
1121  const DelegateInfo
1122  *delegate_info;
1123 
1124  ssize_t
1125  i;
1126 
1127  assert(image_info != (ImageInfo *) NULL);
1128  assert(image_info->signature == MagickCoreSignature);
1129  assert(image != (Image *) NULL);
1130  assert(image->signature == MagickCoreSignature);
1131  if (image->debug != MagickFalse)
1132  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1133 
1134  delegate_info=GetDelegateInfo(decode,encode,exception);
1135  if (delegate_info == (const DelegateInfo *) NULL)
1136  {
1138  "NoTagFound","`%s'",decode ? decode : encode);
1139  return((char *) NULL);
1140  }
1141  commands=StringToList(delegate_info->commands);
1142  if (commands == (char **) NULL)
1143  {
1144  (void) ThrowMagickException(exception,GetMagickModule(),
1145  ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode :
1146  encode);
1147  return((char *) NULL);
1148  }
1149  command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1150  commands[0],exception);
1151  if (command == (char *) NULL)
1153  "MemoryAllocationFailed","`%s'",commands[0]);
1154  /*
1155  Relinquish resources.
1156  */
1157  for (i=0; commands[i] != (char *) NULL; i++)
1158  commands[i]=DestroyString(commands[i]);
1159  commands=(char **) RelinquishMagickMemory(commands);
1160  return(command);
1161 }
1162 
1163 /*
1164 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1165 % %
1166 % %
1167 % %
1168 % G e t D e l e g a t e C o m m a n d s %
1169 % %
1170 % %
1171 % %
1172 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1173 %
1174 % GetDelegateCommands() returns the commands associated with a delegate.
1175 %
1176 % The format of the GetDelegateCommands method is:
1177 %
1178 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1179 %
1180 % A description of each parameter follows:
1181 %
1182 % o delegate_info: The delegate info.
1183 %
1184 */
1185 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1186 {
1187  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1188 
1189  assert(delegate_info != (DelegateInfo *) NULL);
1190  assert(delegate_info->signature == MagickCoreSignature);
1191  return(delegate_info->commands);
1192 }
1193 
1194 /*
1195 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1196 % %
1197 % %
1198 % %
1199 % G e t D e l e g a t e I n f o %
1200 % %
1201 % %
1202 % %
1203 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1204 %
1205 % GetDelegateInfo() returns any delegates associated with the specified tag.
1206 %
1207 % The format of the GetDelegateInfo method is:
1208 %
1209 % const DelegateInfo *GetDelegateInfo(const char *decode,
1210 % const char *encode,ExceptionInfo *exception)
1211 %
1212 % A description of each parameter follows:
1213 %
1214 % o decode: Specifies the decode delegate we are searching for as a
1215 % character string.
1216 %
1217 % o encode: Specifies the encode delegate we are searching for as a
1218 % character string.
1219 %
1220 % o exception: return any errors or warnings in this structure.
1221 %
1222 */
1223 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
1224  const char *encode,ExceptionInfo *exception)
1225 {
1226  const DelegateInfo
1227  *p;
1228 
1229  assert(exception != (ExceptionInfo *) NULL);
1230  if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1231  return((const DelegateInfo *) NULL);
1232  /*
1233  Search for named delegate.
1234  */
1238  if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
1239  {
1241  return(p);
1242  }
1243  while (p != (const DelegateInfo *) NULL)
1244  {
1245  if (p->mode > 0)
1246  {
1247  if (LocaleCompare(p->decode,decode) == 0)
1248  break;
1250  continue;
1251  }
1252  if (p->mode < 0)
1253  {
1254  if (LocaleCompare(p->encode,encode) == 0)
1255  break;
1257  continue;
1258  }
1259  if (LocaleCompare(decode,p->decode) == 0)
1260  if (LocaleCompare(encode,p->encode) == 0)
1261  break;
1262  if (LocaleCompare(decode,"*") == 0)
1263  if (LocaleCompare(encode,p->encode) == 0)
1264  break;
1265  if (LocaleCompare(decode,p->decode) == 0)
1266  if (LocaleCompare(encode,"*") == 0)
1267  break;
1269  }
1270  if (p != (const DelegateInfo *) NULL)
1274  return(p);
1275 }
1276 
1277 /*
1278 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1279 % %
1280 % %
1281 % %
1282 % G e t D e l e g a t e I n f o L i s t %
1283 % %
1284 % %
1285 % %
1286 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1287 %
1288 % GetDelegateInfoList() returns any delegates that match the specified pattern.
1289 %
1290 % The delegate of the GetDelegateInfoList function is:
1291 %
1292 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
1293 % size_t *number_delegates,ExceptionInfo *exception)
1294 %
1295 % A description of each parameter follows:
1296 %
1297 % o pattern: Specifies a pointer to a text string containing a pattern.
1298 %
1299 % o number_delegates: This integer returns the number of delegates in the
1300 % list.
1301 %
1302 % o exception: return any errors or warnings in this structure.
1303 %
1304 */
1305 
1306 #if defined(__cplusplus) || defined(c_plusplus)
1307 extern "C" {
1308 #endif
1309 
1310 static int DelegateInfoCompare(const void *x,const void *y)
1311 {
1312  const DelegateInfo
1313  **p,
1314  **q;
1315 
1316  int
1317  cmp;
1318 
1319  p=(const DelegateInfo **) x,
1320  q=(const DelegateInfo **) y;
1321  cmp=LocaleCompare((*p)->path,(*q)->path);
1322  if (cmp == 0)
1323  {
1324  if ((*p)->decode == (char *) NULL)
1325  if (((*p)->encode != (char *) NULL) &&
1326  ((*q)->encode != (char *) NULL))
1327  return(strcmp((*p)->encode,(*q)->encode));
1328  if (((*p)->decode != (char *) NULL) &&
1329  ((*q)->decode != (char *) NULL))
1330  return(strcmp((*p)->decode,(*q)->decode));
1331  }
1332  return(cmp);
1333 }
1334 
1335 #if defined(__cplusplus) || defined(c_plusplus)
1336 }
1337 #endif
1338 
1339 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
1340  size_t *number_delegates,ExceptionInfo *exception)
1341 {
1342  const DelegateInfo
1343  **delegates;
1344 
1345  const DelegateInfo
1346  *p;
1347 
1348  ssize_t
1349  i;
1350 
1351  /*
1352  Allocate delegate list.
1353  */
1354  assert(number_delegates != (size_t *) NULL);
1355  assert(pattern != (char *) NULL);
1356  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1357 
1358  *number_delegates=0;
1359  p=GetDelegateInfo("*","*",exception);
1360  if (p == (const DelegateInfo *) NULL)
1361  return((const DelegateInfo **) NULL);
1362  delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
1363  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1364  if (delegates == (const DelegateInfo **) NULL)
1365  return((const DelegateInfo **) NULL);
1366  /*
1367  Generate delegate list.
1368  */
1372  for (i=0; p != (const DelegateInfo *) NULL; )
1373  {
1374  if( (p->stealth == MagickFalse) &&
1375  ( GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse ||
1376  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse) )
1377  delegates[i++]=p;
1379  }
1381  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
1382  delegates[i]=(DelegateInfo *) NULL;
1383  *number_delegates=(size_t) i;
1384  return(delegates);
1385 }
1386 
1387 /*
1388 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1389 % %
1390 % %
1391 % %
1392 % G e t D e l e g a t e L i s t %
1393 % %
1394 % %
1395 % %
1396 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1397 %
1398 % GetDelegateList() returns any image format delegates that match the
1399 % specified pattern.
1400 %
1401 % The format of the GetDelegateList function is:
1402 %
1403 % char **GetDelegateList(const char *pattern,
1404 % size_t *number_delegates,ExceptionInfo *exception)
1405 %
1406 % A description of each parameter follows:
1407 %
1408 % o pattern: Specifies a pointer to a text string containing a pattern.
1409 %
1410 % o number_delegates: This integer returns the number of delegates
1411 % in the list.
1412 %
1413 % o exception: return any errors or warnings in this structure.
1414 %
1415 */
1416 
1417 #if defined(__cplusplus) || defined(c_plusplus)
1418 extern "C" {
1419 #endif
1420 
1421 static int DelegateCompare(const void *x,const void *y)
1422 {
1423  const char
1424  **p,
1425  **q;
1426 
1427  p=(const char **) x;
1428  q=(const char **) y;
1429  return(LocaleCompare(*p,*q));
1430 }
1431 
1432 #if defined(__cplusplus) || defined(c_plusplus)
1433 }
1434 #endif
1435 
1436 MagickExport char **GetDelegateList(const char *pattern,
1437  size_t *number_delegates,ExceptionInfo *exception)
1438 {
1439  char
1440  **delegates;
1441 
1442  const DelegateInfo
1443  *p;
1444 
1445  ssize_t
1446  i;
1447 
1448  /*
1449  Allocate delegate list.
1450  */
1451  assert(pattern != (char *) NULL);
1452  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1453 
1454  assert(number_delegates != (size_t *) NULL);
1455  *number_delegates=0;
1456  p=GetDelegateInfo("*","*",exception);
1457  if (p == (const DelegateInfo *) NULL)
1458  return((char **) NULL);
1459  delegates=(char **) AcquireQuantumMemory((size_t)
1460  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1461  if (delegates == (char **) NULL)
1462  return((char **) NULL);
1466  for (i=0; p != (const DelegateInfo *) NULL; )
1467  {
1468  if( (p->stealth == MagickFalse) &&
1469  GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse )
1470  delegates[i++]=ConstantString(p->decode);
1471  if( (p->stealth == MagickFalse) &&
1472  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse )
1473  delegates[i++]=ConstantString(p->encode);
1475  }
1477  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
1478  delegates[i]=(char *) NULL;
1479  *number_delegates=(size_t) i;
1480  return(delegates);
1481 }
1482 
1483 /*
1484 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1485 % %
1486 % %
1487 % %
1488 % G e t D e l e g a t e M o d e %
1489 % %
1490 % %
1491 % %
1492 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1493 %
1494 % GetDelegateMode() returns the mode of the delegate.
1495 %
1496 % The format of the GetDelegateMode method is:
1497 %
1498 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1499 %
1500 % A description of each parameter follows:
1501 %
1502 % o delegate_info: The delegate info.
1503 %
1504 */
1505 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1506 {
1507  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1508 
1509  assert(delegate_info != (DelegateInfo *) NULL);
1510  assert(delegate_info->signature == MagickCoreSignature);
1511  return(delegate_info->mode);
1512 }
1513 
1514 /*
1515 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1516 % %
1517 % %
1518 % %
1519 + G e t D e l e g a t e T h r e a d S u p p o r t %
1520 % %
1521 % %
1522 % %
1523 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1524 %
1525 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
1526 % threads.
1527 %
1528 % The format of the GetDelegateThreadSupport method is:
1529 %
1530 % MagickBooleanType GetDelegateThreadSupport(
1531 % const DelegateInfo *delegate_info)
1532 %
1533 % A description of each parameter follows:
1534 %
1535 % o delegate_info: The delegate info.
1536 %
1537 */
1539  const DelegateInfo *delegate_info)
1540 {
1541  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1542 
1543  assert(delegate_info != (DelegateInfo *) NULL);
1544  assert(delegate_info->signature == MagickCoreSignature);
1545  return(delegate_info->thread_support);
1546 }
1547 
1548 /*
1549 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1550 % %
1551 % %
1552 % %
1553 + 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 %
1554 % %
1555 % %
1556 % %
1557 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1558 %
1559 % IsDelegateCacheInstantiated() determines if the delegate cache is
1560 % instantiated. If not, it instantiates the cache and returns it.
1561 %
1562 % The format of the IsDelegateInstantiated method is:
1563 %
1564 % MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1565 %
1566 % A description of each parameter follows.
1567 %
1568 % o exception: return any errors or warnings in this structure.
1569 %
1570 */
1572 {
1573  if (delegate_cache == (LinkedListInfo *) NULL)
1574  {
1575  if (delegate_semaphore == (SemaphoreInfo *) NULL)
1578  if (delegate_cache == (LinkedListInfo *) NULL)
1581  }
1582  return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1583 }
1584 
1585 /*
1586 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1587 % %
1588 % %
1589 % %
1590 % I n v o k e D e l e g a t e %
1591 % %
1592 % %
1593 % %
1594 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1595 %
1596 % InvokeDelegate replaces any embedded formatting characters with the
1597 % appropriate image attribute and executes the resulting command. MagickFalse
1598 % is returned if the commands execute with success otherwise MagickTrue.
1599 %
1600 % The format of the InvokeDelegate method is:
1601 %
1602 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
1603 % const char *decode,const char *encode,ExceptionInfo *exception)
1604 %
1605 % A description of each parameter follows:
1606 %
1607 % o image_info: the imageInfo.
1608 %
1609 % o image: the image.
1610 %
1611 % o exception: return any errors or warnings in this structure.
1612 %
1613 */
1614 
1615 static MagickBooleanType CopyDelegateFile(const char *source,
1616  const char *destination,const MagickBooleanType overwrite)
1617 {
1618  int
1619  destination_file,
1620  source_file;
1621 
1623  status;
1624 
1625  size_t
1626  i;
1627 
1628  size_t
1629  length,
1630  quantum;
1631 
1632  ssize_t
1633  count;
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+=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 
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 
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 (image->debug != MagickFalse)
1718  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1719  rights=ExecutePolicyRights;
1720  if ((decode != (const char *) NULL) &&
1722  {
1723  errno=EPERM;
1725  "NotAuthorized","`%s'",decode);
1726  return(MagickFalse);
1727  }
1728  if ((encode != (const char *) NULL) &&
1730  {
1731  errno=EPERM;
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);
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);
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  {
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,
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,
1812  (void) CopyMagickString(image_info->filename,image->filename,
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,
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  {
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  {
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  {
1912  "DelegateFailed","`%s'",commands[i]);
1913  break;
1914  }
1915  commands[i]=DestroyString(commands[i]);
1916  }
1917  (void) CopyMagickString(image_info->filename,output_filename,
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 */
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,
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 */
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 
2069  DelegateInfo
2070  *delegate_info;
2071 
2073  status;
2074 
2075  size_t
2076  extent;
2077 
2078  /*
2079  Load the delegate map file.
2080  */
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')
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&=LoadDelegateCache(cache,file_xml,path,
2151  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  delegate_info->commands=commands;
2220  break;
2221  }
2222  break;
2223  }
2224  case 'D':
2225  case 'd':
2226  {
2227  if (LocaleCompare((char *) keyword,"decode") == 0)
2228  {
2229  delegate_info->decode=ConstantString(token);
2230  delegate_info->mode=1;
2231  break;
2232  }
2233  break;
2234  }
2235  case 'E':
2236  case 'e':
2237  {
2238  if (LocaleCompare((char *) keyword,"encode") == 0)
2239  {
2240  delegate_info->encode=ConstantString(token);
2241  delegate_info->mode=(-1);
2242  break;
2243  }
2244  break;
2245  }
2246  case 'M':
2247  case 'm':
2248  {
2249  if (LocaleCompare((char *) keyword,"mode") == 0)
2250  {
2251  delegate_info->mode=1;
2252  if (LocaleCompare(token,"bi") == 0)
2253  delegate_info->mode=0;
2254  else
2255  if (LocaleCompare(token,"encode") == 0)
2256  delegate_info->mode=(-1);
2257  break;
2258  }
2259  break;
2260  }
2261  case 'S':
2262  case 's':
2263  {
2264  if (LocaleCompare((char *) keyword,"spawn") == 0)
2265  {
2266  delegate_info->spawn=IsStringTrue(token);
2267  break;
2268  }
2269  if (LocaleCompare((char *) keyword,"stealth") == 0)
2270  {
2271  delegate_info->stealth=IsStringTrue(token);
2272  break;
2273  }
2274  break;
2275  }
2276  case 'T':
2277  case 't':
2278  {
2279  if (LocaleCompare((char *) keyword,"thread-support") == 0)
2280  {
2281  delegate_info->thread_support=IsStringTrue(token);
2282  if (delegate_info->thread_support == MagickFalse)
2283  delegate_info->semaphore=AcquireSemaphoreInfo();
2284  break;
2285  }
2286  break;
2287  }
2288  default:
2289  break;
2290  }
2291  }
2292  token=(char *) RelinquishMagickMemory(token);
2293  return(status != 0 ? MagickTrue : MagickFalse);
2294 }
size_t rows
Definition: image.h:172
MagickExport ssize_t FormatMagickSize(const MagickSizeType size, const MagickBooleanType bi, const char *suffix, const size_t length, char *format)
Definition: string.c:1058
size_t signature
Definition: image.h:488
static int DelegateCompare(const void *x, const void *y)
Definition: delegate.c:1421
#define MagickMaxRecursionDepth
Definition: studio.h:349
MagickExport MagickBooleanType GetPathAttributes(const char *path, void *attributes)
Definition: utility.c:1173
DisposeType dispose
Definition: image.h:237
char magick[MagickPathExtent]
Definition: image.h:480
MagickExport MagickBooleanType GetDelegateThreadSupport(const DelegateInfo *delegate_info)
Definition: delegate.c:1538
MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, const PolicyRights rights, const char *pattern)
Definition: policy.c:620
size_t iterations
Definition: image.h:248
MagickExport size_t ConcatenateMagickString(char *magick_restrict destination, const char *magick_restrict source, const size_t length)
Definition: string.c:392
MagickExport void UnlockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:449
MagickExport void ResetLinkedListIterator(LinkedListInfo *list_info)
Definition: linked-list.c:959
MagickExport const DelegateInfo ** GetDelegateInfoList(const char *pattern, size_t *number_delegates, ExceptionInfo *exception)
Definition: delegate.c:1339
static SemaphoreInfo * delegate_semaphore
Definition: delegate.c:167
PolicyRights
Definition: policy.h:41
MagickExport LinkedListInfo * DestroyLinkedList(LinkedListInfo *list_info, void *(*relinquish_value)(void *))
Definition: linked-list.c:219
static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *)
Definition: delegate.c:1571
#define WarnNoImageReturn(format, letter)
size_t number_scenes
Definition: image.h:396
#define WarnNoImageInfoReturn(format, letter)
MagickBooleanType debug
Definition: image.h:485
MagickExport SemaphoreInfo * AcquireSemaphoreInfo(void)
Definition: semaphore.c:192
MagickExport MagickBooleanType InsertValueInLinkedList(LinkedListInfo *list_info, const size_t index, const void *value)
Definition: linked-list.c:447
MagickExport char ** GetDelegateList(const char *pattern, size_t *number_delegates, ExceptionInfo *exception)
Definition: delegate.c:1436
MagickExport const DelegateInfo * GetDelegateInfo(const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1223
#define MagickMaxBufferExtent
Definition: blob.h:25
MagickExport size_t StripMagickString(char *message)
Definition: string.c:2518
MagickExport char * SanitizeString(const char *source)
Definition: string.c:1585
static FILE * popen_utf8(const char *command, const char *type)
MagickExport MagickBooleanType IsLinkedListEmpty(const LinkedListInfo *list_info)
Definition: linked-list.c:633
MagickExport MagickBooleanType AppendValueToLinkedList(LinkedListInfo *list_info, const void *value)
Definition: linked-list.c:111
MagickExport ssize_t FormatLocaleString(char *magick_restrict string, const size_t length, const char *magick_restrict format,...)
Definition: locale.c:463
MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
Definition: delegate.c:1505
MagickExport size_t CopyMagickString(char *magick_restrict destination, const char *magick_restrict source, const size_t length)
Definition: string.c:731
ResolutionType units
Definition: image.h:198
MagickExport MagickBooleanType SignatureImage(Image *image, ExceptionInfo *exception)
Definition: signature.c:470
size_t delay
Definition: image.h:240
MagickExport void * RemoveElementByValueFromLinkedList(LinkedListInfo *list_info, const void *value)
Definition: linked-list.c:756
char magick[MagickPathExtent]
Definition: image.h:319
#define MAGICKCORE_QUANTUM_DEPTH
Definition: magick-type.h:32
size_t magick_rows
Definition: image.h:324
#define DefaultResolution
Definition: image-private.h:27
MagickBooleanType verbose
Definition: image.h:445
MagickExport const char * GetDelegateCommands(const DelegateInfo *delegate_info)
Definition: delegate.c:1185
MagickExport const char * GetImageOption(const ImageInfo *image_info, const char *option)
Definition: option.c:2383
char * commands
Definition: delegate.h:31
#define MagickEpsilon
Definition: magick-type.h:114
CompressionType compression
Definition: image.h:160
#define O_BINARY
Definition: studio.h:330
ClassType storage_class
Definition: image.h:154
size_t width
Definition: geometry.h:131
MagickExport MagickBooleanType AcquireUniqueFilename(char *path)
Definition: utility.c:111
Definition: log.h:52
MagickBooleanType thread_support
Definition: delegate.h:40
Definition: image.h:151
SemaphoreInfo * semaphore
Definition: delegate.h:45
MagickExport void * GetNextValueInLinkedList(LinkedListInfo *list_info)
Definition: linked-list.c:305
static char * InterpretDelegateProperties(ImageInfo *image_info, Image *image, const char *embed_text, ExceptionInfo *exception)
Definition: delegate.c:914
static char * GetMagickPropertyLetter(ImageInfo *image_info, Image *image, const char letter, ExceptionInfo *exception)
Definition: delegate.c:565
double x
Definition: geometry.h:124
#define MagickCoreSignature
MagickExport void LockSemaphoreInfo(SemaphoreInfo *semaphore_info)
Definition: semaphore.c:293
MagickExport unsigned char * GetStringInfoDatum(const StringInfo *string_info)
Definition: string.c:1176
MagickExport LinkedListInfo * GetConfigureOptions(const char *filename, ExceptionInfo *exception)
Definition: configure.c:642
static MagickBooleanType LoadDelegateCache(LinkedListInfo *, const char *, const char *, const size_t, ExceptionInfo *)
Definition: delegate.c:2058
MagickExport void GetPathComponent(const char *path, PathType type, char *component)
Definition: utility.c:1221
static MagickBooleanType CopyDelegateFile(const char *source, const char *destination, const MagickBooleanType overwrite)
Definition: delegate.c:1615
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:368
MagickBooleanType
Definition: magick-type.h:165
MagickExport char ** StringToList(const char *text)
Definition: string.c:2298
#define DirectorySeparator
Definition: studio.h:264
size_t scene
Definition: image.h:240
unsigned int MagickStatusType
Definition: magick-type.h:125
MagickExport char * AcquireString(const char *source)
Definition: string.c:94
MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info, Image *image, ExceptionInfo *exception)
Definition: constitute.c:1083
MagickExport MagickBooleanType GlobExpression(const char *magick_restrict expression, const char *magick_restrict pattern, const MagickBooleanType case_insensitive)
Definition: token.c:355
MagickExport const char * CommandOptionToMnemonic(const CommandOption option, const ssize_t type)
Definition: option.c:2764
MagickExport void * AcquireCriticalMemory(const size_t size)
Definition: memory.c:626
MagickPrivate void DelegateComponentTerminus(void)
Definition: delegate.c:298
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:665
char filename[MagickPathExtent]
Definition: image.h:480
MagickExport char * GetDelegateCommand(const ImageInfo *image_info, Image *image, const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1114
MagickExport int LocaleNCompare(const char *p, const char *q, const size_t length)
Definition: locale.c:1523
double y
Definition: geometry.h:124
MagickExport magick_hot_spot size_t GetNextToken(const char *magick_restrict start, const char **magick_restrict end, const size_t extent, char *magick_restrict token)
Definition: token.c:174
MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path)
Definition: resource.c:1098
char * decode
Definition: delegate.h:31
RectangleInfo page
Definition: image.h:212
size_t magick_columns
Definition: image.h:324
#define MagickPathExtent
MagickExport void MagickDelay(const MagickSizeType milliseconds)
Definition: utility.c:1730
MagickExport MagickBooleanType IsStringTrue(const char *value)
Definition: string.c:1386
#define ThrowFileException(exception, severity, tag, context)
PixelTrait alpha_trait
Definition: image.h:280
size_t signature
Definition: delegate.h:48
MagickExport MagickBooleanType SetImageInfo(ImageInfo *image_info, const unsigned int frames, ExceptionInfo *exception)
Definition: image.c:2782
char magick_filename[MagickPathExtent]
Definition: image.h:319
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1145
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1660
static int open_utf8(const char *path, int flags, mode_t mode)
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
MagickExport MagickBooleanType AcquireUniqueSymbolicLink(const char *source, char *destination)
Definition: utility.c:153
MagickExport MagickBooleanType SubstituteString(char **string, const char *search, const char *replace)
Definition: string.c:2583
ssize_t x
Definition: geometry.h:135
size_t height
Definition: geometry.h:131
MagickExport LinkedListInfo * NewLinkedList(const size_t capacity)
Definition: linked-list.c:713
MagickPrivate MagickBooleanType DelegateComponentGenesis(void)
Definition: delegate.c:252
ssize_t mode
Definition: delegate.h:37
MagickExport int ExternalDelegateCommand(const MagickBooleanType asynchronous, const MagickBooleanType verbose, const char *command, char *message, ExceptionInfo *exception)
Definition: delegate.c:345
#define S_MODE
Definition: studio.h:244
MagickBooleanType spawn
Definition: delegate.h:40
static void * DestroyDelegate(void *delegate_info)
Definition: delegate.c:278
#define AppendString2Text(string)
size_t quality
Definition: image.h:163
PolicyDomain
Definition: policy.h:28
MagickExport int LocaleCompare(const char *p, const char *q)
Definition: locale.c:1399
char filename[MagickPathExtent]
Definition: image.h:319
#define GetMagickModule()
Definition: log.h:28
MagickBooleanType stealth
Definition: delegate.h:40
MagickExport const char * GetStringInfoPath(const StringInfo *string_info)
Definition: string.c:1263
MagickExport char * InterpretImageProperties(ImageInfo *image_info, Image *image, const char *embed_text, ExceptionInfo *exception)
Definition: property.c:3512
MagickExport MagickSizeType GetBlobSize(const Image *image)
Definition: blob.c:1844
char unique[MagickPathExtent]
Definition: image.h:480
MagickExport ImageInfo * DestroyImageInfo(ImageInfo *image_info)
Definition: image.c:1248
static char * SanitizeDelegateString(const char *source)
static LinkedListInfo * delegate_cache
Definition: delegate.c:164
MagickExport MagickBooleanType ListDelegateInfo(FILE *file, ExceptionInfo *exception)
Definition: delegate.c:1955
char * path
Definition: delegate.h:31
#define DelegateFilename
Definition: delegate.c:91
MagickExport RectangleInfo GetImageBoundingBox(const Image *image, ExceptionInfo *exception)
Definition: attribute.c:389
static const char * DelegateMap
Definition: delegate.c:97
MagickExport ssize_t GetImageIndexInList(const Image *images)
Definition: list.c:672
MagickExport Image * GetNextImageInList(const Image *images)
Definition: list.c:786
MagickExport char * DestroyString(char *string)
Definition: string.c:788
MagickExport void ActivateSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:98
MagickExport const char * GetImageProperty(const Image *image, const char *property, ExceptionInfo *exception)
Definition: property.c:2216
MagickExport size_t GetNumberOfElementsInLinkedList(const LinkedListInfo *list_info)
Definition: linked-list.c:348
MagickExport ImageInfo * CloneImageInfo(const ImageInfo *image_info)
Definition: image.c:936
#define ExtendInterpretText(string_length)
static int access_utf8(const char *path, int mode)
#define MagickMin(x, y)
Definition: image-private.h:37
ColorspaceType
Definition: colorspace.h:25
static LinkedListInfo * AcquireDelegateCache(const char *filename, ExceptionInfo *exception)
Definition: delegate.c:203
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1162
PointInfo resolution
Definition: image.h:209
MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, Image *image, const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1688
#define MagickPrivate
MagickPrivate char * FileToXML(const char *, const size_t)
Definition: xml-tree.c:524
#define MagickExport
MagickSizeType extent
Definition: image.h:270
char * encode
Definition: delegate.h:31
ssize_t y
Definition: geometry.h:135
MagickExport char ** StringToArgv(const char *text, int *argc)
Definition: string.c:2021
MagickBooleanType adjoin
Definition: image.h:384
MagickExport size_t GetImageListLength(const Image *images)
Definition: list.c:711
MagickExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:351
MagickExport LinkedListInfo * DestroyConfigureOptions(LinkedListInfo *options)
Definition: configure.c:314
MagickExport void LocaleUpper(char *string)
Definition: locale.c:1572
MagickExport char * ConstantString(const char *source)
Definition: string.c:678
static int DelegateInfoCompare(const void *x, const void *y)
Definition: delegate.c:1310
ColorspaceType colorspace
Definition: image.h:157
MagickBooleanType temporary
Definition: image.h:384
MagickBooleanType debug
Definition: image.h:334
size_t depth
Definition: image.h:172