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 
210  status;
211 
212  cache=NewLinkedList(0);
213  status=MagickTrue;
214 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
215  {
216  const StringInfo
217  *option;
218 
220  *options;
221 
222  options=GetConfigureOptions(filename,exception);
223  option=(const StringInfo *) GetNextValueInLinkedList(options);
224  while (option != (const StringInfo *) NULL)
225  {
226  status&=LoadDelegateCache(cache,(const char *)
227  GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
228  option=(const StringInfo *) GetNextValueInLinkedList(options);
229  }
230  options=DestroyConfigureOptions(options);
231  }
232 #endif
233  if (IsLinkedListEmpty(cache) != MagickFalse)
234  status&=LoadDelegateCache(cache,DelegateMap,"built-in",0,exception);
235  return(cache);
236 }
237 
238 /*
239 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
240 % %
241 % %
242 % %
243 + D e l e g a t e C o m p o n e n t G e n e s i s %
244 % %
245 % %
246 % %
247 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
248 %
249 % DelegateComponentGenesis() instantiates the delegate component.
250 %
251 % The format of the DelegateComponentGenesis method is:
252 %
253 % MagickBooleanType DelegateComponentGenesis(void)
254 %
255 */
257 {
258  if (delegate_semaphore == (SemaphoreInfo *) NULL)
260  return(MagickTrue);
261 }
262 
263 /*
264 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
265 % %
266 % %
267 % %
268 % 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 %
269 % %
270 % %
271 % %
272 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
273 %
274 % DelegateComponentTerminus() destroys the delegate component.
275 %
276 % The format of the DelegateComponentTerminus method is:
277 %
278 % DelegateComponentTerminus(void)
279 %
280 */
281 
282 static void *DestroyDelegate(void *delegate_info)
283 {
285  *p;
286 
287  p=(DelegateInfo *) delegate_info;
288  if (p->path != (char *) NULL)
289  p->path=DestroyString(p->path);
290  if (p->decode != (char *) NULL)
291  p->decode=DestroyString(p->decode);
292  if (p->encode != (char *) NULL)
293  p->encode=DestroyString(p->encode);
294  if (p->commands != (char *) NULL)
296  if (p->semaphore != (SemaphoreInfo *) NULL)
299  return((void *) NULL);
300 }
301 
303 {
304  if (delegate_semaphore == (SemaphoreInfo *) NULL)
307  if (delegate_cache != (LinkedListInfo *) NULL)
311 }
312 
313 /*
314 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
315 % %
316 % %
317 % %
318 + E x t e r n a l D e l e g a t e C o m m a n d %
319 % %
320 % %
321 % %
322 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
323 %
324 % ExternalDelegateCommand() executes the specified command and waits until it
325 % terminates. The returned value is the exit status of the command.
326 %
327 % The format of the ExternalDelegateCommand method is:
328 %
329 % int ExternalDelegateCommand(const MagickBooleanType asynchronous,
330 % const MagickBooleanType verbose,const char *command,
331 % char *message,ExceptionInfo *exception)
332 %
333 % A description of each parameter follows:
334 %
335 % o asynchronous: a value other than 0 executes the parent program
336 % concurrently with the new child process.
337 %
338 % o verbose: a value other than 0 prints the executed command before it is
339 % invoked.
340 %
341 % o command: this string is the command to execute.
342 %
343 % o message: an option buffer to receive any message posted to stdout or
344 % stderr.
345 %
346 % o exception: return any errors here.
347 %
348 */
350  const MagickBooleanType verbose,const char *command,char *message,
351  ExceptionInfo *exception)
352 {
353  char
354  **arguments,
355  *sanitize_command;
356 
357  int
358  number_arguments,
359  status;
360 
362  domain;
363 
365  rights;
366 
367  ssize_t
368  i;
369 
370  status=(-1);
371  arguments=StringToArgv(command,&number_arguments);
372  if (arguments == (char **) NULL)
373  return(status);
374  if (*arguments[1] == '\0')
375  {
376  for (i=0; i < (ssize_t) number_arguments; i++)
377  arguments[i]=DestroyString(arguments[i]);
378  arguments=(char **) RelinquishMagickMemory(arguments);
379  return(-1);
380  }
381  rights=ExecutePolicyRights;
382  domain=DelegatePolicyDomain;
383  if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
384  {
385  errno=EPERM;
387  "NotAuthorized","`%s'",arguments[1]);
388  for (i=0; i < (ssize_t) number_arguments; i++)
389  arguments[i]=DestroyString(arguments[i]);
390  arguments=(char **) RelinquishMagickMemory(arguments);
391  return(-1);
392  }
393  if (verbose != MagickFalse)
394  {
395  (void) FormatLocaleFile(stderr,"%s\n",command);
396  (void) fflush(stderr);
397  }
398  sanitize_command=SanitizeString(command);
399  if (asynchronous != MagickFalse)
400  (void) ConcatenateMagickString(sanitize_command,"&",MagickPathExtent);
401  if (message != (char *) NULL)
402  *message='\0';
403 #if defined(MAGICKCORE_POSIX_SUPPORT)
404 #if defined(MAGICKCORE_HAVE_POPEN)
405  if ((asynchronous == MagickFalse) && (message != (char *) NULL))
406  {
407  char
408  buffer[MagickPathExtent];
409 
410  FILE
411  *file;
412 
413  size_t
414  offset;
415 
416  offset=0;
417  file=popen_utf8(sanitize_command,"r");
418  if (file == (FILE *) NULL)
419  status=system(sanitize_command);
420  else
421  {
422  while (fgets(buffer,(int) sizeof(buffer),file) != NULL)
423  {
424  size_t
425  length;
426 
427  length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
428  if (length > 0)
429  {
430  (void) CopyMagickString(message+offset,buffer,length);
431  offset+=length-1;
432  }
433  }
434  status=pclose(file);
435  }
436  }
437  else
438 #endif
439  {
440 #if !defined(MAGICKCORE_HAVE_EXECVP)
441  status=system(sanitize_command);
442 #else
443  if ((asynchronous != MagickFalse) ||
444  (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
445  status=system(sanitize_command);
446  else
447  {
448  pid_t
449  child_pid;
450 
451  /*
452  Call application directly rather than from a shell.
453  */
454  child_pid=(pid_t) fork();
455  if (child_pid == (pid_t) -1)
456  status=system(sanitize_command);
457  else
458  if (child_pid == 0)
459  {
460  status=execvp(arguments[1],arguments+1);
461  _exit(1);
462  }
463  else
464  {
465  int
466  child_status;
467 
468  pid_t
469  pid;
470 
471  child_status=0;
472  pid=(pid_t) waitpid(child_pid,&child_status,0);
473  if (pid == -1)
474  status=(-1);
475  else
476  {
477  if (WIFEXITED(child_status) != 0)
478  status=WEXITSTATUS(child_status);
479  else
480  if (WIFSIGNALED(child_status))
481  status=(-1);
482  }
483  }
484  }
485 #endif
486  }
487 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
488  {
489  char
490  *p;
491 
492  /*
493  If a command shell is executed we need to change the forward slashes in
494  files to a backslash. We need to do this to keep Windows happy when we
495  want to 'move' a file.
496 
497  TODO: This won't work if one of the delegate parameters has a forward
498  slash as aparameter.
499  */
500  p=strstr(sanitize_command,"cmd.exe /c");
501  if (p != (char*) NULL)
502  {
503  p+=10;
504  for ( ; *p != '\0'; p++)
505  if (*p == '/')
506  *p=(*DirectorySeparator);
507  }
508  }
509  status=NTSystemCommand(sanitize_command,message);
510 #elif defined(vms)
511  status=system(sanitize_command);
512 #else
513 # error No suitable system() method.
514 #endif
515  if (status < 0)
516  {
517  if ((message != (char *) NULL) && (*message != '\0'))
519  "FailedToExecuteCommand","`%s' (%s)",sanitize_command,message);
520  else
522  "FailedToExecuteCommand","`%s' (%d)",sanitize_command,status);
523  }
524  sanitize_command=DestroyString(sanitize_command);
525  for (i=0; i < (ssize_t) number_arguments; i++)
526  arguments[i]=DestroyString(arguments[i]);
527  arguments=(char **) RelinquishMagickMemory(arguments);
528  return(status);
529 }
530 
531 /*
532 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
533 % %
534 % %
535 % %
536 % G e t D e l e g a t e C o m m a n d %
537 % %
538 % %
539 % %
540 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
541 %
542 % GetDelegateCommand() replaces any embedded formatting characters with the
543 % appropriate image attribute and returns the resulting command.
544 %
545 % The format of the GetDelegateCommand method is:
546 %
547 % char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
548 % const char *decode,const char *encode,ExceptionInfo *exception)
549 %
550 % A description of each parameter follows:
551 %
552 % o command: Method GetDelegateCommand returns the command associated
553 % with specified delegate tag.
554 %
555 % o image_info: the image info.
556 %
557 % o image: the image.
558 %
559 % o decode: Specifies the decode delegate we are searching for as a
560 % character string.
561 %
562 % o encode: Specifies the encode delegate we are searching for as a
563 % character string.
564 %
565 % o exception: return any errors or warnings in this structure.
566 %
567 */
568 
569 static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
570  const char letter,ExceptionInfo *exception)
571 {
572 #define WarnNoImageReturn(format,letter) \
573  if (image == (Image *) NULL) \
574  { \
575  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
576  "NoImageForProperty",format,letter); \
577  break; \
578  }
579 #define WarnNoImageInfoReturn(format,letter) \
580  if (image_info == (ImageInfo *) NULL) \
581  { \
582  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
583  "NoImageInfoForProperty",format,letter); \
584  break; \
585  }
586 
587  char
588  value[MagickPathExtent];
589 
590  const char
591  *string;
592 
593  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
594  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
595  else
596  if ((image_info != (ImageInfo *) NULL) &&
597  (image_info->debug != MagickFalse))
598  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
599  /*
600  Get properties that are directly defined by images.
601  */
602  *value='\0'; /* formatted string */
603  string=(const char *) value;
604  switch (letter)
605  {
606  case 'a': /* authentication passphase */
607  {
608  WarnNoImageInfoReturn("\"%%%c\"",letter);
609  string=GetImageOption(image_info,"authenticate");
610  break;
611  }
612  case 'b': /* image size read in - in bytes */
613  {
614  WarnNoImageReturn("\"%%%c\"",letter);
616  value);
617  if (image->extent == 0)
618  (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
619  MagickPathExtent,value);
620  break;
621  }
622  case 'd': /* Directory component of filename */
623  {
624  WarnNoImageReturn("\"%%%c\"",letter);
626  break;
627  }
628  case 'e': /* Filename extension (suffix) of image file */
629  {
630  WarnNoImageReturn("\"%%%c\"",letter);
632  break;
633  }
634  case 'f': /* Filename without directory component */
635  {
636  WarnNoImageReturn("\"%%%c\"",letter);
638  break;
639  }
640  case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
641  {
642  WarnNoImageReturn("\"%%%c\"",letter);
644  "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
645  image->page.height,(double) image->page.x,(double) image->page.y);
646  break;
647  }
648  case 'h': /* Image height (current) */
649  {
650  WarnNoImageReturn("\"%%%c\"",letter);
651  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
652  (image->rows != 0 ? image->rows : image->magick_rows));
653  break;
654  }
655  case 'i': /* Filename last used for an image (read or write) */
656  {
657  WarnNoImageReturn("\"%%%c\"",letter);
658  string=image->filename;
659  break;
660  }
661  case 'm': /* Image format (file magick) */
662  {
663  WarnNoImageReturn("\"%%%c\"",letter);
664  string=image->magick;
665  break;
666  }
667  case 'n': /* Number of images in the list. */
668  {
669  if (image != (Image *) NULL)
670  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
671  GetImageListLength(image));
672  break;
673  }
674  case 'o': /* Output Filename */
675  {
676  WarnNoImageInfoReturn("\"%%%c\"",letter);
677  string=image_info->filename;
678  break;
679  }
680  case 'p': /* Image index in current image list */
681  {
682  WarnNoImageReturn("\"%%%c\"",letter);
683  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
684  GetImageIndexInList(image));
685  break;
686  }
687  case 'q': /* Quantum depth of image in memory */
688  {
689  WarnNoImageReturn("\"%%%c\"",letter);
690  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
692  break;
693  }
694  case 'r': /* Image storage class, colorspace, and alpha enabled. */
695  {
697  colorspace;
698 
699  WarnNoImageReturn("\"%%%c\"",letter);
700  colorspace=image->colorspace;
701  (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
704  (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
705  "Alpha" : "");
706  break;
707  }
708  case 's': /* Image scene number */
709  {
710  WarnNoImageReturn("\"%%%c\"",letter);
711  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
712  image->scene);
713  break;
714  }
715  case 't': /* Base filename without directory or extention */
716  {
717  WarnNoImageReturn("\"%%%c\"",letter);
719  break;
720  }
721  case 'u': /* Unique filename */
722  {
723  WarnNoImageInfoReturn("\"%%%c\"",letter);
724  string=image_info->unique;
725  break;
726  }
727  case 'w': /* Image width (current) */
728  {
729  WarnNoImageReturn("\"%%%c\"",letter);
730  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
731  (image->columns != 0 ? image->columns : image->magick_columns));
732  break;
733  }
734  case 'x': /* Image horizontal resolution (with units) */
735  {
736  WarnNoImageReturn("\"%%%c\"",letter);
737  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
738  fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
741  break;
742  }
743  case 'y': /* Image vertical resolution (with units) */
744  {
745  WarnNoImageReturn("\"%%%c\"",letter);
746  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
747  fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
750  break;
751  }
752  case 'z': /* Image depth as read in */
753  {
754  WarnNoImageReturn("\"%%%c\"",letter);
755  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
756  (double) image->depth);
757  break;
758  }
759  case 'A': /* Image alpha channel */
760  {
761  WarnNoImageReturn("\"%%%c\"",letter);
763  image->alpha_trait);
764  break;
765  }
766  case 'C': /* Image compression method. */
767  {
768  WarnNoImageReturn("\"%%%c\"",letter);
770  (ssize_t) image->compression);
771  break;
772  }
773  case 'D': /* Image dispose method. */
774  {
775  WarnNoImageReturn("\"%%%c\"",letter);
777  (ssize_t) image->dispose);
778  break;
779  }
780  case 'F':
781  {
782  /*
783  Magick filename - filename given incl. coder & read mods.
784  */
785  WarnNoImageReturn("\"%%%c\"",letter);
787  break;
788  }
789  case 'G': /* Image size as geometry = "%wx%h" */
790  {
791  WarnNoImageReturn("\"%%%c\"",letter);
792  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
793  (double) image->magick_columns,(double) image->magick_rows);
794  break;
795  }
796  case 'H': /* layer canvas height */
797  {
798  WarnNoImageReturn("\"%%%c\"",letter);
799  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
800  (double) image->page.height);
801  break;
802  }
803  case 'I': /* image iterations for animations */
804  {
805  WarnNoImageReturn("\"%%%c\"",letter);
806  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
807  image->iterations);
808  break;
809  }
810  case 'M': /* Magick filename - filename given incl. coder & read mods */
811  {
812  WarnNoImageReturn("\"%%%c\"",letter);
813  string=image->magick_filename;
814  break;
815  }
816  case 'O': /* layer canvas offset with sign = "+%X+%Y" */
817  {
818  WarnNoImageReturn("\"%%%c\"",letter);
819  (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
820  image->page.x,(long) image->page.y);
821  break;
822  }
823  case 'P': /* layer canvas page size = "%Wx%H" */
824  {
825  WarnNoImageReturn("\"%%%c\"",letter);
826  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
827  (double) image->page.width,(double) image->page.height);
828  break;
829  }
830  case '~': /* BPG image compression quality */
831  {
832  WarnNoImageReturn("\"%%%c\"",letter);
833  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
834  (100-(image->quality == 0 ? 42 : image->quality))/2);
835  break;
836  }
837  case 'Q': /* image compression quality */
838  {
839  WarnNoImageReturn("\"%%%c\"",letter);
840  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
841  (image->quality == 0 ? 92 : image->quality));
842  break;
843  }
844  case 'S': /* Number of scenes in image list. */
845  {
846  WarnNoImageInfoReturn("\"%%%c\"",letter);
847  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
848  (image_info->number_scenes == 0 ? 2147483647 :
849  image_info->number_scenes));
850  break;
851  }
852  case 'T': /* image time delay for animations */
853  {
854  WarnNoImageReturn("\"%%%c\"",letter);
855  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
856  image->delay);
857  break;
858  }
859  case 'U': /* Image resolution units. */
860  {
861  WarnNoImageReturn("\"%%%c\"",letter);
863  (ssize_t) image->units);
864  break;
865  }
866  case 'W': /* layer canvas width */
867  {
868  WarnNoImageReturn("\"%%%c\"",letter);
869  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
870  image->page.width);
871  break;
872  }
873  case 'X': /* layer canvas X offset */
874  {
875  WarnNoImageReturn("\"%%%c\"",letter);
876  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
877  image->page.x);
878  break;
879  }
880  case 'Y': /* layer canvas Y offset */
881  {
882  WarnNoImageReturn("\"%%%c\"",letter);
883  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
884  image->page.y);
885  break;
886  }
887  case '%': /* percent escaped */
888  {
889  string="%";
890  break;
891  }
892  case '@': /* Trim bounding box, without actually trimming! */
893  {
895  page;
896 
897  WarnNoImageReturn("\"%%%c\"",letter);
898  page=GetImageBoundingBox(image,exception);
900  "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
901  (double) page.x,(double) page.y);
902  break;
903  }
904  case '#':
905  {
906  /*
907  Image signature.
908  */
909  WarnNoImageReturn("\"%%%c\"",letter);
910  (void) SignatureImage(image,exception);
911  string=GetImageProperty(image,"signature",exception);
912  break;
913  }
914  }
915  return(SanitizeDelegateString(string));
916 }
917 
918 static char *InterpretDelegateProperties(ImageInfo *image_info,
919  Image *image,const char *embed_text,ExceptionInfo *exception)
920 {
921 #define ExtendInterpretText(string_length) \
922 { \
923  size_t length=(string_length); \
924  if ((size_t) (q-interpret_text+length+1) >= extent) \
925  { \
926  extent+=length; \
927  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
928  MagickPathExtent,sizeof(*interpret_text)); \
929  if (interpret_text == (char *) NULL) \
930  return((char *) NULL); \
931  q=interpret_text+strlen(interpret_text); \
932  } \
933 }
934 
935 #define AppendKeyValue2Text(key,value)\
936 { \
937  size_t length=strlen(key)+strlen(value)+2; \
938  if ((size_t) (q-interpret_text+length+1) >= extent) \
939  { \
940  extent+=length; \
941  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
942  MagickPathExtent,sizeof(*interpret_text)); \
943  if (interpret_text == (char *) NULL) \
944  return((char *) NULL); \
945  q=interpret_text+strlen(interpret_text); \
946  } \
947  q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
948 }
949 
950 #define AppendString2Text(string) \
951 { \
952  size_t length=strlen((string)); \
953  if ((size_t) (q-interpret_text+length+1) >= extent) \
954  { \
955  extent+=length; \
956  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
957  MagickPathExtent,sizeof(*interpret_text)); \
958  if (interpret_text == (char *) NULL) \
959  return((char *) NULL); \
960  q=interpret_text+strlen(interpret_text); \
961  } \
962  (void) CopyMagickString(q,(string),extent); \
963  q+=length; \
964 }
965 
966  char
967  *interpret_text,
968  *string;
969 
970  char
971  *q; /* current position in interpret_text */
972 
973  const char
974  *p; /* position in embed_text string being expanded */
975 
976  size_t
977  extent; /* allocated length of interpret_text */
978 
980  number;
981 
982  assert(image == NULL || image->signature == MagickCoreSignature);
983  assert(image_info == NULL || image_info->signature == MagickCoreSignature);
984  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
985  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
986  else
987  if ((image_info != (ImageInfo *) NULL) && (image_info->debug != MagickFalse))
988  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
989  if (embed_text == (const char *) NULL)
990  return(ConstantString(""));
991  p=embed_text;
992  while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
993  p++;
994  if (*p == '\0')
995  return(ConstantString(""));
996  /*
997  Translate any embedded format characters.
998  */
999  interpret_text=AcquireString(embed_text); /* new string with extra space */
1000  extent=MagickPathExtent; /* allocated space in string */
1001  number=MagickFalse; /* is last char a number? */
1002  for (q=interpret_text; *p!='\0';
1003  number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
1004  {
1005  /*
1006  Interpret escape characters (e.g. Filename: %M).
1007  */
1008  *q='\0';
1010  switch (*p)
1011  {
1012  case '\\':
1013  {
1014  switch (*(p+1))
1015  {
1016  case '\0':
1017  continue;
1018  case 'r': /* convert to RETURN */
1019  {
1020  *q++='\r';
1021  p++;
1022  continue;
1023  }
1024  case 'n': /* convert to NEWLINE */
1025  {
1026  *q++='\n';
1027  p++;
1028  continue;
1029  }
1030  case '\n': /* EOL removal UNIX,MacOSX */
1031  {
1032  p++;
1033  continue;
1034  }
1035  case '\r': /* EOL removal DOS,Windows */
1036  {
1037  p++;
1038  if (*p == '\n') /* return-newline EOL */
1039  p++;
1040  continue;
1041  }
1042  default:
1043  {
1044  p++;
1045  *q++=(*p);
1046  }
1047  }
1048  continue;
1049  }
1050  case '&':
1051  {
1052  if (LocaleNCompare("&lt;",p,4) == 0)
1053  {
1054  *q++='<';
1055  p+=3;
1056  }
1057  else
1058  if (LocaleNCompare("&gt;",p,4) == 0)
1059  {
1060  *q++='>';
1061  p+=3;
1062  }
1063  else
1064  if (LocaleNCompare("&amp;",p,5) == 0)
1065  {
1066  *q++='&';
1067  p+=4;
1068  }
1069  else
1070  *q++=(*p);
1071  continue;
1072  }
1073  case '%':
1074  break; /* continue to next set of handlers */
1075  default:
1076  {
1077  *q++=(*p); /* any thing else is 'as normal' */
1078  continue;
1079  }
1080  }
1081  p++; /* advance beyond the percent */
1082  /*
1083  Doubled Percent - or percent at end of string.
1084  */
1085  if ((*p == '\0') || (*p == '\'') || (*p == '"'))
1086  p--;
1087  if (*p == '%')
1088  {
1089  *q++='%';
1090  continue;
1091  }
1092  /*
1093  Single letter escapes %c.
1094  */
1095  if (number != MagickFalse)
1096  {
1097  /*
1098  But only if not preceeded by a number!
1099  */
1100  *q++='%'; /* do NOT substitute the percent */
1101  p--; /* back up one */
1102  continue;
1103  }
1104  string=GetMagickPropertyLetter(image_info,image,*p,exception);
1105  if (string != (char *) NULL)
1106  {
1107  AppendString2Text(string);
1108  string=DestroyString(string);
1109  continue;
1110  }
1112  "UnknownImageProperty","\"%%%c\"",*p);
1113  }
1114  *q='\0';
1115  return(interpret_text);
1116 }
1117 
1118 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
1119  const char *decode,const char *encode,ExceptionInfo *exception)
1120 {
1121  char
1122  *command,
1123  **commands;
1124 
1125  const DelegateInfo
1126  *delegate_info;
1127 
1128  ssize_t
1129  i;
1130 
1131  assert(image_info != (ImageInfo *) NULL);
1132  assert(image_info->signature == MagickCoreSignature);
1133  assert(image != (Image *) NULL);
1134  assert(image->signature == MagickCoreSignature);
1135  if (image->debug != MagickFalse)
1136  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1137 
1138  delegate_info=GetDelegateInfo(decode,encode,exception);
1139  if (delegate_info == (const DelegateInfo *) NULL)
1140  {
1142  "NoTagFound","`%s'",decode ? decode : encode);
1143  return((char *) NULL);
1144  }
1145  commands=StringToList(delegate_info->commands);
1146  if (commands == (char **) NULL)
1147  {
1148  (void) ThrowMagickException(exception,GetMagickModule(),
1149  ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode :
1150  encode);
1151  return((char *) NULL);
1152  }
1153  command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1154  commands[0],exception);
1155  if (command == (char *) NULL)
1157  "MemoryAllocationFailed","`%s'",commands[0]);
1158  /*
1159  Relinquish resources.
1160  */
1161  for (i=0; commands[i] != (char *) NULL; i++)
1162  commands[i]=DestroyString(commands[i]);
1163  commands=(char **) RelinquishMagickMemory(commands);
1164  return(command);
1165 }
1166 
1167 /*
1168 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1169 % %
1170 % %
1171 % %
1172 % G e t D e l e g a t e C o m m a n d s %
1173 % %
1174 % %
1175 % %
1176 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1177 %
1178 % GetDelegateCommands() returns the commands associated with a delegate.
1179 %
1180 % The format of the GetDelegateCommands method is:
1181 %
1182 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1183 %
1184 % A description of each parameter follows:
1185 %
1186 % o delegate_info: The delegate info.
1187 %
1188 */
1189 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1190 {
1191  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1192 
1193  assert(delegate_info != (DelegateInfo *) NULL);
1194  assert(delegate_info->signature == MagickCoreSignature);
1195  return(delegate_info->commands);
1196 }
1197 
1198 /*
1199 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1200 % %
1201 % %
1202 % %
1203 % G e t D e l e g a t e I n f o %
1204 % %
1205 % %
1206 % %
1207 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1208 %
1209 % GetDelegateInfo() returns any delegates associated with the specified tag.
1210 %
1211 % The format of the GetDelegateInfo method is:
1212 %
1213 % const DelegateInfo *GetDelegateInfo(const char *decode,
1214 % const char *encode,ExceptionInfo *exception)
1215 %
1216 % A description of each parameter follows:
1217 %
1218 % o decode: Specifies the decode delegate we are searching for as a
1219 % character string.
1220 %
1221 % o encode: Specifies the encode delegate we are searching for as a
1222 % character string.
1223 %
1224 % o exception: return any errors or warnings in this structure.
1225 %
1226 */
1227 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
1228  const char *encode,ExceptionInfo *exception)
1229 {
1230  const DelegateInfo
1231  *p;
1232 
1233  assert(exception != (ExceptionInfo *) NULL);
1234  if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1235  return((const DelegateInfo *) NULL);
1236  /*
1237  Search for named delegate.
1238  */
1242  if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
1243  {
1245  return(p);
1246  }
1247  while (p != (const DelegateInfo *) NULL)
1248  {
1249  if (p->mode > 0)
1250  {
1251  if (LocaleCompare(p->decode,decode) == 0)
1252  break;
1254  continue;
1255  }
1256  if (p->mode < 0)
1257  {
1258  if (LocaleCompare(p->encode,encode) == 0)
1259  break;
1261  continue;
1262  }
1263  if (LocaleCompare(decode,p->decode) == 0)
1264  if (LocaleCompare(encode,p->encode) == 0)
1265  break;
1266  if (LocaleCompare(decode,"*") == 0)
1267  if (LocaleCompare(encode,p->encode) == 0)
1268  break;
1269  if (LocaleCompare(decode,p->decode) == 0)
1270  if (LocaleCompare(encode,"*") == 0)
1271  break;
1273  }
1274  if (p != (const DelegateInfo *) NULL)
1278  return(p);
1279 }
1280 
1281 /*
1282 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1283 % %
1284 % %
1285 % %
1286 % G e t D e l e g a t e I n f o L i s t %
1287 % %
1288 % %
1289 % %
1290 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1291 %
1292 % GetDelegateInfoList() returns any delegates that match the specified pattern.
1293 %
1294 % The delegate of the GetDelegateInfoList function is:
1295 %
1296 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
1297 % size_t *number_delegates,ExceptionInfo *exception)
1298 %
1299 % A description of each parameter follows:
1300 %
1301 % o pattern: Specifies a pointer to a text string containing a pattern.
1302 %
1303 % o number_delegates: This integer returns the number of delegates in the
1304 % list.
1305 %
1306 % o exception: return any errors or warnings in this structure.
1307 %
1308 */
1309 
1310 #if defined(__cplusplus) || defined(c_plusplus)
1311 extern "C" {
1312 #endif
1313 
1314 static int DelegateInfoCompare(const void *x,const void *y)
1315 {
1316  const DelegateInfo
1317  **p,
1318  **q;
1319 
1320  int
1321  cmp;
1322 
1323  p=(const DelegateInfo **) x,
1324  q=(const DelegateInfo **) y;
1325  cmp=LocaleCompare((*p)->path,(*q)->path);
1326  if (cmp == 0)
1327  {
1328  if ((*p)->decode == (char *) NULL)
1329  if (((*p)->encode != (char *) NULL) &&
1330  ((*q)->encode != (char *) NULL))
1331  return(strcmp((*p)->encode,(*q)->encode));
1332  if (((*p)->decode != (char *) NULL) &&
1333  ((*q)->decode != (char *) NULL))
1334  return(strcmp((*p)->decode,(*q)->decode));
1335  }
1336  return(cmp);
1337 }
1338 
1339 #if defined(__cplusplus) || defined(c_plusplus)
1340 }
1341 #endif
1342 
1343 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
1344  size_t *number_delegates,ExceptionInfo *exception)
1345 {
1346  const DelegateInfo
1347  **delegates;
1348 
1349  const DelegateInfo
1350  *p;
1351 
1352  ssize_t
1353  i;
1354 
1355  /*
1356  Allocate delegate list.
1357  */
1358  assert(number_delegates != (size_t *) NULL);
1359  assert(pattern != (char *) NULL);
1360  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1361 
1362  *number_delegates=0;
1363  p=GetDelegateInfo("*","*",exception);
1364  if (p == (const DelegateInfo *) NULL)
1365  return((const DelegateInfo **) NULL);
1366  delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
1367  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1368  if (delegates == (const DelegateInfo **) NULL)
1369  return((const DelegateInfo **) NULL);
1370  /*
1371  Generate delegate list.
1372  */
1376  for (i=0; p != (const DelegateInfo *) NULL; )
1377  {
1378  if( (p->stealth == MagickFalse) &&
1379  ( GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse ||
1380  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse) )
1381  delegates[i++]=p;
1383  }
1385  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
1386  delegates[i]=(DelegateInfo *) NULL;
1387  *number_delegates=(size_t) i;
1388  return(delegates);
1389 }
1390 
1391 /*
1392 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1393 % %
1394 % %
1395 % %
1396 % G e t D e l e g a t e L i s t %
1397 % %
1398 % %
1399 % %
1400 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1401 %
1402 % GetDelegateList() returns any image format delegates that match the
1403 % specified pattern.
1404 %
1405 % The format of the GetDelegateList function is:
1406 %
1407 % char **GetDelegateList(const char *pattern,
1408 % size_t *number_delegates,ExceptionInfo *exception)
1409 %
1410 % A description of each parameter follows:
1411 %
1412 % o pattern: Specifies a pointer to a text string containing a pattern.
1413 %
1414 % o number_delegates: This integer returns the number of delegates
1415 % in the list.
1416 %
1417 % o exception: return any errors or warnings in this structure.
1418 %
1419 */
1420 
1421 #if defined(__cplusplus) || defined(c_plusplus)
1422 extern "C" {
1423 #endif
1424 
1425 static int DelegateCompare(const void *x,const void *y)
1426 {
1427  const char
1428  **p,
1429  **q;
1430 
1431  p=(const char **) x;
1432  q=(const char **) y;
1433  return(LocaleCompare(*p,*q));
1434 }
1435 
1436 #if defined(__cplusplus) || defined(c_plusplus)
1437 }
1438 #endif
1439 
1440 MagickExport char **GetDelegateList(const char *pattern,
1441  size_t *number_delegates,ExceptionInfo *exception)
1442 {
1443  char
1444  **delegates;
1445 
1446  const DelegateInfo
1447  *p;
1448 
1449  ssize_t
1450  i;
1451 
1452  /*
1453  Allocate delegate list.
1454  */
1455  assert(pattern != (char *) NULL);
1456  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1457 
1458  assert(number_delegates != (size_t *) NULL);
1459  *number_delegates=0;
1460  p=GetDelegateInfo("*","*",exception);
1461  if (p == (const DelegateInfo *) NULL)
1462  return((char **) NULL);
1463  delegates=(char **) AcquireQuantumMemory((size_t)
1464  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1465  if (delegates == (char **) NULL)
1466  return((char **) NULL);
1470  for (i=0; p != (const DelegateInfo *) NULL; )
1471  {
1472  if( (p->stealth == MagickFalse) &&
1473  GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse )
1474  delegates[i++]=ConstantString(p->decode);
1475  if( (p->stealth == MagickFalse) &&
1476  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse )
1477  delegates[i++]=ConstantString(p->encode);
1479  }
1481  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
1482  delegates[i]=(char *) NULL;
1483  *number_delegates=(size_t) i;
1484  return(delegates);
1485 }
1486 
1487 /*
1488 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1489 % %
1490 % %
1491 % %
1492 % G e t D e l e g a t e M o d e %
1493 % %
1494 % %
1495 % %
1496 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1497 %
1498 % GetDelegateMode() returns the mode of the delegate.
1499 %
1500 % The format of the GetDelegateMode method is:
1501 %
1502 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1503 %
1504 % A description of each parameter follows:
1505 %
1506 % o delegate_info: The delegate info.
1507 %
1508 */
1509 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1510 {
1511  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1512 
1513  assert(delegate_info != (DelegateInfo *) NULL);
1514  assert(delegate_info->signature == MagickCoreSignature);
1515  return(delegate_info->mode);
1516 }
1517 
1518 /*
1519 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1520 % %
1521 % %
1522 % %
1523 + G e t D e l e g a t e T h r e a d S u p p o r t %
1524 % %
1525 % %
1526 % %
1527 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1528 %
1529 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
1530 % threads.
1531 %
1532 % The format of the GetDelegateThreadSupport method is:
1533 %
1534 % MagickBooleanType GetDelegateThreadSupport(
1535 % const DelegateInfo *delegate_info)
1536 %
1537 % A description of each parameter follows:
1538 %
1539 % o delegate_info: The delegate info.
1540 %
1541 */
1543  const DelegateInfo *delegate_info)
1544 {
1545  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1546 
1547  assert(delegate_info != (DelegateInfo *) NULL);
1548  assert(delegate_info->signature == MagickCoreSignature);
1549  return(delegate_info->thread_support);
1550 }
1551 
1552 /*
1553 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1554 % %
1555 % %
1556 % %
1557 + 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 %
1558 % %
1559 % %
1560 % %
1561 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1562 %
1563 % IsDelegateCacheInstantiated() determines if the delegate cache is
1564 % instantiated. If not, it instantiates the cache and returns it.
1565 %
1566 % The format of the IsDelegateInstantiated method is:
1567 %
1568 % MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1569 %
1570 % A description of each parameter follows.
1571 %
1572 % o exception: return any errors or warnings in this structure.
1573 %
1574 */
1576 {
1577  if (delegate_cache == (LinkedListInfo *) NULL)
1578  {
1579  if (delegate_semaphore == (SemaphoreInfo *) NULL)
1582  if (delegate_cache == (LinkedListInfo *) NULL)
1585  }
1586  return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1587 }
1588 
1589 /*
1590 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1591 % %
1592 % %
1593 % %
1594 % I n v o k e D e l e g a t e %
1595 % %
1596 % %
1597 % %
1598 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1599 %
1600 % InvokeDelegate replaces any embedded formatting characters with the
1601 % appropriate image attribute and executes the resulting command. MagickFalse
1602 % is returned if the commands execute with success otherwise MagickTrue.
1603 %
1604 % The format of the InvokeDelegate method is:
1605 %
1606 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
1607 % const char *decode,const char *encode,ExceptionInfo *exception)
1608 %
1609 % A description of each parameter follows:
1610 %
1611 % o image_info: the imageInfo.
1612 %
1613 % o image: the image.
1614 %
1615 % o exception: return any errors or warnings in this structure.
1616 %
1617 */
1618 
1619 static MagickBooleanType CopyDelegateFile(const char *source,
1620  const char *destination,const MagickBooleanType overwrite)
1621 {
1622  int
1623  destination_file,
1624  source_file;
1625 
1627  status;
1628 
1629  size_t
1630  i;
1631 
1632  size_t
1633  length,
1634  quantum;
1635 
1636  ssize_t
1637  count;
1638 
1639  struct stat
1640  attributes;
1641 
1642  unsigned char
1643  *buffer;
1644 
1645  /*
1646  Copy source file to destination.
1647  */
1648  assert(source != (const char *) NULL);
1649  assert(destination != (char *) NULL);
1650  if (overwrite == MagickFalse)
1651  {
1652  status=GetPathAttributes(destination,&attributes);
1653  if (status != MagickFalse)
1654  return(MagickTrue);
1655  }
1656  destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1657  if (destination_file == -1)
1658  return(MagickFalse);
1659  source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1660  if (source_file == -1)
1661  {
1662  (void) close(destination_file);
1663  return(MagickFalse);
1664  }
1665  quantum=(size_t) MagickMaxBufferExtent;
1666  if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1667  quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
1668  buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
1669  if (buffer == (unsigned char *) NULL)
1670  {
1671  (void) close(source_file);
1672  (void) close(destination_file);
1673  return(MagickFalse);
1674  }
1675  length=0;
1676  for (i=0; ; i+=count)
1677  {
1678  count=(ssize_t) read(source_file,buffer,quantum);
1679  if (count <= 0)
1680  break;
1681  length=(size_t) count;
1682  count=(ssize_t) write(destination_file,buffer,length);
1683  if ((size_t) count != length)
1684  break;
1685  }
1686  (void) close(destination_file);
1687  (void) close(source_file);
1688  buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1689  return(i != 0 ? MagickTrue : MagickFalse);
1690 }
1691 
1693  Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
1694 {
1695  char
1696  *command,
1697  **commands,
1698  input_filename[MagickPathExtent],
1699  output_filename[MagickPathExtent];
1700 
1701  const DelegateInfo
1702  *delegate_info;
1703 
1705  status,
1706  temporary;
1707 
1708  PolicyRights
1709  rights;
1710 
1711  ssize_t
1712  i;
1713 
1714  /*
1715  Get delegate.
1716  */
1717  assert(image_info != (ImageInfo *) NULL);
1718  assert(image_info->signature == MagickCoreSignature);
1719  assert(image != (Image *) NULL);
1720  assert(image->signature == MagickCoreSignature);
1721  if (image->debug != MagickFalse)
1722  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1723  rights=ExecutePolicyRights;
1724  if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
1725  {
1726  errno=EPERM;
1728  "NotAuthorized","`%s'",decode);
1729  return(MagickFalse);
1730  }
1731  if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
1732  {
1733  errno=EPERM;
1735  "NotAuthorized","`%s'",encode);
1736  return(MagickFalse);
1737  }
1738  temporary=*image->filename == '\0' ? MagickTrue : MagickFalse;
1739  if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1740  MagickFalse))
1741  {
1742  ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
1743  image->filename);
1744  return(MagickFalse);
1745  }
1746  delegate_info=GetDelegateInfo(decode,encode,exception);
1747  if (delegate_info == (DelegateInfo *) NULL)
1748  {
1749  if (temporary != MagickFalse)
1750  (void) RelinquishUniqueFileResource(image->filename);
1752  "NoTagFound","`%s'",decode ? decode : encode);
1753  return(MagickFalse);
1754  }
1755  if (*image_info->filename == '\0')
1756  {
1757  if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1758  {
1759  if (temporary != MagickFalse)
1760  (void) RelinquishUniqueFileResource(image->filename);
1762  "UnableToCreateTemporaryFile",image_info->filename);
1763  return(MagickFalse);
1764  }
1765  image_info->temporary=MagickTrue;
1766  }
1767  if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
1768  (delegate_info->encode != (char *) NULL)) ||
1769  ((encode != (const char *) NULL) &&
1770  (delegate_info->decode != (char *) NULL))))
1771  {
1772  char
1773  *magick;
1774 
1775  ImageInfo
1776  *clone_info;
1777 
1778  Image
1779  *p;
1780 
1781  /*
1782  Delegate requires a particular image format.
1783  */
1784  if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1785  {
1787  "UnableToCreateTemporaryFile",image_info->unique);
1788  return(MagickFalse);
1789  }
1790  magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
1791  delegate_info->encode : delegate_info->decode,exception);
1792  if (magick == (char *) NULL)
1793  {
1794  (void) RelinquishUniqueFileResource(image_info->unique);
1795  if (temporary != MagickFalse)
1796  (void) RelinquishUniqueFileResource(image->filename);
1797  (void) ThrowMagickException(exception,GetMagickModule(),
1798  DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1799  return(MagickFalse);
1800  }
1801  LocaleUpper(magick);
1802  clone_info=CloneImageInfo(image_info);
1803  (void) CopyMagickString((char *) clone_info->magick,magick,
1805  if (LocaleCompare(magick,"NULL") != 0)
1806  (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1807  magick=DestroyString(magick);
1808  (void) FormatLocaleString(clone_info->filename,MagickPathExtent,"%s:",
1809  delegate_info->decode);
1810  (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
1811  exception);
1812  (void) CopyMagickString(clone_info->filename,image_info->filename,
1814  (void) CopyMagickString(image_info->filename,image->filename,
1816  for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1817  {
1818  (void) FormatLocaleString(p->filename,MagickPathExtent,"%s:%s",
1819  delegate_info->decode,clone_info->filename);
1820  status=WriteImage(clone_info,p,exception);
1821  if (status == MagickFalse)
1822  {
1823  (void) RelinquishUniqueFileResource(image_info->unique);
1824  if (temporary != MagickFalse)
1825  (void) RelinquishUniqueFileResource(image->filename);
1826  clone_info=DestroyImageInfo(clone_info);
1827  (void) ThrowMagickException(exception,GetMagickModule(),
1828  DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1829  return(MagickFalse);
1830  }
1831  if (clone_info->adjoin != MagickFalse)
1832  break;
1833  }
1834  (void) RelinquishUniqueFileResource(image_info->unique);
1835  clone_info=DestroyImageInfo(clone_info);
1836  }
1837  /*
1838  Invoke delegate.
1839  */
1840  commands=StringToList(delegate_info->commands);
1841  if (commands == (char **) NULL)
1842  {
1843  if (temporary != MagickFalse)
1844  (void) RelinquishUniqueFileResource(image->filename);
1845  (void) ThrowMagickException(exception,GetMagickModule(),
1846  ResourceLimitError,"MemoryAllocationFailed","`%s'",
1847  decode ? decode : encode);
1848  return(MagickFalse);
1849  }
1850  command=(char *) NULL;
1851  status=MagickTrue;
1852  (void) CopyMagickString(output_filename,image_info->filename,
1854  (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1855  for (i=0; commands[i] != (char *) NULL; i++)
1856  {
1857  (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1858  if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1859  {
1861  "UnableToCreateTemporaryFile",image_info->unique);
1862  break;
1863  }
1864  if (LocaleCompare(decode,"SCAN") != 0)
1865  {
1866  status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1867  if (status == MagickFalse)
1868  {
1870  "UnableToCreateTemporaryFile",input_filename);
1871  break;
1872  }
1873  }
1874  status=MagickTrue;
1875  command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1876  if (command != (char *) NULL)
1877  {
1878  /*
1879  Execute delegate.
1880  */
1881  if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1882  command,(char *) NULL,exception) != 0)
1883  status=MagickFalse;
1884  if (delegate_info->spawn != MagickFalse)
1885  {
1886  ssize_t
1887  count;
1888 
1889  /*
1890  Wait for input file to 'disappear', or maximum 2 seconds.
1891  */
1892  count=20;
1893  while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1894  (void) MagickDelay(100); /* sleep 0.1 seconds */
1895  }
1896  command=DestroyString(command);
1897  }
1898  if (LocaleCompare(decode,"SCAN") != 0)
1899  {
1900  if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1901  (void) RelinquishUniqueFileResource(input_filename);
1902  }
1903  if ((strcmp(input_filename,output_filename) != 0) &&
1904  (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1905  (void) RelinquishUniqueFileResource(output_filename);
1906  if (image_info->temporary != MagickFalse)
1907  (void) RelinquishUniqueFileResource(image_info->filename);
1908  (void) RelinquishUniqueFileResource(image_info->unique);
1909  (void) RelinquishUniqueFileResource(image_info->filename);
1910  (void) RelinquishUniqueFileResource(image->filename);
1911  if (status == MagickFalse)
1912  {
1914  "DelegateFailed","`%s'",commands[i]);
1915  break;
1916  }
1917  commands[i]=DestroyString(commands[i]);
1918  }
1919  (void) CopyMagickString(image_info->filename,output_filename,
1921  (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
1922  /*
1923  Relinquish resources.
1924  */
1925  for ( ; commands[i] != (char *) NULL; i++)
1926  commands[i]=DestroyString(commands[i]);
1927  commands=(char **) RelinquishMagickMemory(commands);
1928  if (temporary != MagickFalse)
1929  (void) RelinquishUniqueFileResource(image->filename);
1930  return(status);
1931 }
1932 
1933 /*
1934 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1935 % %
1936 % %
1937 % %
1938 % L i s t D e l e g a t e I n f o %
1939 % %
1940 % %
1941 % %
1942 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1943 %
1944 % ListDelegateInfo() lists the image formats to a file.
1945 %
1946 % The format of the ListDelegateInfo method is:
1947 %
1948 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1949 %
1950 % A description of each parameter follows.
1951 %
1952 % o file: An pointer to a FILE.
1953 %
1954 % o exception: return any errors or warnings in this structure.
1955 %
1956 */
1958  ExceptionInfo *exception)
1959 {
1960  const DelegateInfo
1961  **delegate_info;
1962 
1963  char
1964  **commands,
1965  delegate[MagickPathExtent];
1966 
1967  const char
1968  *path;
1969 
1970  ssize_t
1971  i;
1972 
1973  size_t
1974  number_delegates;
1975 
1976  ssize_t
1977  j;
1978 
1979  if (file == (const FILE *) NULL)
1980  file=stdout;
1981  delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1982  if (delegate_info == (const DelegateInfo **) NULL)
1983  return(MagickFalse);
1984  path=(const char *) NULL;
1985  for (i=0; i < (ssize_t) number_delegates; i++)
1986  {
1987  if (delegate_info[i]->stealth != MagickFalse)
1988  continue;
1989  if ((path == (const char *) NULL) ||
1990  (LocaleCompare(path,delegate_info[i]->path) != 0))
1991  {
1992  if (delegate_info[i]->path != (char *) NULL)
1993  (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path);
1994  (void) FormatLocaleFile(file,"Delegate Command\n");
1995  (void) FormatLocaleFile(file,
1996  "-------------------------------------------------"
1997  "------------------------------\n");
1998  }
1999  path=delegate_info[i]->path;
2000  *delegate='\0';
2001  if (delegate_info[i]->encode != (char *) NULL)
2002  (void) CopyMagickString(delegate,delegate_info[i]->encode,
2004  (void) ConcatenateMagickString(delegate," ",MagickPathExtent);
2005  delegate[8]='\0';
2006  commands=StringToList(delegate_info[i]->commands);
2007  if (commands == (char **) NULL)
2008  continue;
2009  (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
2010  delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
2011  delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
2012  (void) StripMagickString(commands[0]);
2013  (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]);
2014  for (j=1; commands[j] != (char *) NULL; j++)
2015  {
2016  (void) StripMagickString(commands[j]);
2017  (void) FormatLocaleFile(file," \"%s\"\n",commands[j]);
2018  }
2019  for (j=0; commands[j] != (char *) NULL; j++)
2020  commands[j]=DestroyString(commands[j]);
2021  commands=(char **) RelinquishMagickMemory(commands);
2022  }
2023  (void) fflush(file);
2024  delegate_info=(const DelegateInfo **)
2025  RelinquishMagickMemory((void *) delegate_info);
2026  return(MagickTrue);
2027 }
2028 
2029 /*
2030 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2031 % %
2032 % %
2033 % %
2034 + L o a d D e l e g a t e C a c h e %
2035 % %
2036 % %
2037 % %
2038 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2039 %
2040 % LoadDelegateCache() loads the delegate configurations which provides a
2041 % mapping between delegate attributes and a delegate name.
2042 %
2043 % The format of the LoadDelegateCache method is:
2044 %
2045 % MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
2046 % const char *xml,const char *filename,const size_t depth,
2047 % ExceptionInfo *exception)
2048 %
2049 % A description of each parameter follows:
2050 %
2051 % o xml: The delegate list in XML format.
2052 %
2053 % o filename: The delegate list filename.
2054 %
2055 % o depth: depth of <include /> statements.
2056 %
2057 % o exception: return any errors or warnings in this structure.
2058 %
2059 */
2061  const char *xml,const char *filename,const size_t depth,
2062  ExceptionInfo *exception)
2063 {
2064  char
2065  keyword[MagickPathExtent],
2066  *token;
2067 
2068  const char
2069  *q;
2070 
2071  DelegateInfo
2072  *delegate_info;
2073 
2075  status;
2076 
2077  size_t
2078  extent;
2079 
2080  /*
2081  Load the delegate map file.
2082  */
2084  "Loading delegate configuration file \"%s\" ...",filename);
2085  if (xml == (const char *) NULL)
2086  return(MagickFalse);
2087  status=MagickTrue;
2088  delegate_info=(DelegateInfo *) NULL;
2089  token=AcquireString(xml);
2090  extent=strlen(token)+MagickPathExtent;
2091  for (q=(const char *) xml; *q != '\0'; )
2092  {
2093  /*
2094  Interpret XML.
2095  */
2096  (void) GetNextToken(q,&q,extent,token);
2097  if (*token == '\0')
2098  break;
2099  (void) CopyMagickString(keyword,token,MagickPathExtent);
2100  if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
2101  {
2102  /*
2103  Doctype element.
2104  */
2105  while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
2106  (void) GetNextToken(q,&q,extent,token);
2107  continue;
2108  }
2109  if (LocaleNCompare(keyword,"<!--",4) == 0)
2110  {
2111  /*
2112  Comment element.
2113  */
2114  while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
2115  (void) GetNextToken(q,&q,extent,token);
2116  continue;
2117  }
2118  if (LocaleCompare(keyword,"<include") == 0)
2119  {
2120  /*
2121  Include element.
2122  */
2123  while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
2124  {
2125  (void) CopyMagickString(keyword,token,MagickPathExtent);
2126  (void) GetNextToken(q,&q,extent,token);
2127  if (*token != '=')
2128  continue;
2129  (void) GetNextToken(q,&q,extent,token);
2130  if (LocaleCompare(keyword,"file") == 0)
2131  {
2132  if (depth > MagickMaxRecursionDepth)
2133  (void) ThrowMagickException(exception,GetMagickModule(),
2134  ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
2135  else
2136  {
2137  char
2138  path[MagickPathExtent],
2139  *file_xml;
2140 
2141  GetPathComponent(filename,HeadPath,path);
2142  if (*path != '\0')
2145  if (*token == *DirectorySeparator)
2146  (void) CopyMagickString(path,token,MagickPathExtent);
2147  else
2148  (void) ConcatenateMagickString(path,token,MagickPathExtent);
2149  file_xml=FileToXML(path,~0UL);
2150  if (file_xml != (char *) NULL)
2151  {
2152  status&=LoadDelegateCache(cache,file_xml,path,
2153  depth+1,exception);
2154  file_xml=DestroyString(file_xml);
2155  }
2156  }
2157  }
2158  }
2159  continue;
2160  }
2161  if (LocaleCompare(keyword,"<delegate") == 0)
2162  {
2163  /*
2164  Delegate element.
2165  */
2166  delegate_info=(DelegateInfo *) AcquireCriticalMemory(
2167  sizeof(*delegate_info));
2168  (void) memset(delegate_info,0,sizeof(*delegate_info));
2169  delegate_info->path=ConstantString(filename);
2170  delegate_info->thread_support=MagickTrue;
2171  delegate_info->signature=MagickCoreSignature;
2172  continue;
2173  }
2174  if (delegate_info == (DelegateInfo *) NULL)
2175  continue;
2176  if ((LocaleCompare(keyword,"/>") == 0) ||
2177  (LocaleCompare(keyword,"</policy>") == 0))
2178  {
2179  status=AppendValueToLinkedList(cache,delegate_info);
2180  if (status == MagickFalse)
2181  (void) ThrowMagickException(exception,GetMagickModule(),
2182  ResourceLimitError,"MemoryAllocationFailed","`%s'",
2183  delegate_info->commands);
2184  delegate_info=(DelegateInfo *) NULL;
2185  continue;
2186  }
2187  (void) GetNextToken(q,(const char **) NULL,extent,token);
2188  if (*token != '=')
2189  continue;
2190  (void) GetNextToken(q,&q,extent,token);
2191  (void) GetNextToken(q,&q,extent,token);
2192  switch (*keyword)
2193  {
2194  case 'C':
2195  case 'c':
2196  {
2197  if (LocaleCompare((char *) keyword,"command") == 0)
2198  {
2199  char
2200  *commands;
2201 
2202  commands=AcquireString(token);
2203 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2204  if (strchr(commands,'@') != (char *) NULL)
2205  {
2206  char
2207  path[MagickPathExtent];
2208 
2209  NTGhostscriptEXE(path,MagickPathExtent);
2210  (void) SubstituteString((char **) &commands,"@PSDelegate@",
2211  path);
2212  (void) SubstituteString((char **) &commands,"\\","/");
2213  }
2214  (void) SubstituteString((char **) &commands,"&quot;","\"");
2215 #else
2216  (void) SubstituteString((char **) &commands,"&quot;","'");
2217 #endif
2218  (void) SubstituteString((char **) &commands,"&amp;","&");
2219  (void) SubstituteString((char **) &commands,"&gt;",">");
2220  (void) SubstituteString((char **) &commands,"&lt;","<");
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 }
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:1425
#define MagickMaxRecursionDepth
Definition: studio.h:352
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:1542
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:1343
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:1575
#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:1440
MagickExport const DelegateInfo * GetDelegateInfo(const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1227
#define MagickMaxBufferExtent
Definition: blob.h:25
MagickExport size_t StripMagickString(char *message)
Definition: string.c:2522
MagickExport char * SanitizeString(const char *source)
Definition: string.c:1589
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:467
MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
Definition: delegate.c:1509
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:1189
MagickExport const char * GetImageOption(const ImageInfo *image_info, const char *option)
Definition: option.c:2382
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:333
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:918
static char * GetMagickPropertyLetter(ImageInfo *image_info, Image *image, const char letter, ExceptionInfo *exception)
Definition: delegate.c:569
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:1180
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:2060
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:1619
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:372
MagickBooleanType
Definition: magick-type.h:169
MagickExport char ** StringToList(const char *text)
Definition: string.c:2302
#define DirectorySeparator
Definition: studio.h:267
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:2761
MagickExport void * AcquireCriticalMemory(const size_t size)
Definition: memory.c:626
MagickPrivate void DelegateComponentTerminus(void)
Definition: delegate.c:302
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:1118
MagickExport int LocaleNCompare(const char *p, const char *q, const size_t length)
Definition: locale.c:1527
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:1390
#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:2587
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:256
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:349
#define S_MODE
Definition: studio.h:247
MagickBooleanType spawn
Definition: delegate.h:40
static void * DestroyDelegate(void *delegate_info)
Definition: delegate.c:282
#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:1403
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:1267
MagickExport char * InterpretImageProperties(ImageInfo *image_info, Image *image, const char *embed_text, ExceptionInfo *exception)
Definition: property.c:3515
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:1957
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:1692
#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:2025
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:1576
MagickExport char * ConstantString(const char *source)
Definition: string.c:678
static int DelegateInfoCompare(const void *x, const void *y)
Definition: delegate.c:1314
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