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 #else
229  magick_unreferenced(filename);
230 #endif
231  if (IsLinkedListEmpty(cache) != MagickFalse)
232  (void) LoadDelegateCache(cache,DelegateMap,"built-in",0,exception);
233  return(cache);
234 }
235 
236 /*
237 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
238 % %
239 % %
240 % %
241 + D e l e g a t e C o m p o n e n t G e n e s i s %
242 % %
243 % %
244 % %
245 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
246 %
247 % DelegateComponentGenesis() instantiates the delegate component.
248 %
249 % The format of the DelegateComponentGenesis method is:
250 %
251 % MagickBooleanType DelegateComponentGenesis(void)
252 %
253 */
255 {
256  if (delegate_semaphore == (SemaphoreInfo *) NULL)
258  return(MagickTrue);
259 }
260 
261 /*
262 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
263 % %
264 % %
265 % %
266 % 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 %
267 % %
268 % %
269 % %
270 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
271 %
272 % DelegateComponentTerminus() destroys the delegate component.
273 %
274 % The format of the DelegateComponentTerminus method is:
275 %
276 % DelegateComponentTerminus(void)
277 %
278 */
279 
280 static void *DestroyDelegate(void *delegate_info)
281 {
283  *p;
284 
285  p=(DelegateInfo *) delegate_info;
286  if (p->path != (char *) NULL)
287  p->path=DestroyString(p->path);
288  if (p->decode != (char *) NULL)
289  p->decode=DestroyString(p->decode);
290  if (p->encode != (char *) NULL)
291  p->encode=DestroyString(p->encode);
292  if (p->commands != (char *) NULL)
294  if (p->semaphore != (SemaphoreInfo *) NULL)
297  return((void *) NULL);
298 }
299 
301 {
302  if (delegate_semaphore == (SemaphoreInfo *) NULL)
305  if (delegate_cache != (LinkedListInfo *) NULL)
309 }
310 
311 /*
312 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
313 % %
314 % %
315 % %
316 + E x t e r n a l D e l e g a t e C o m m a n d %
317 % %
318 % %
319 % %
320 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
321 %
322 % ExternalDelegateCommand() executes the specified command and waits until it
323 % terminates. The returned value is the exit status of the command.
324 %
325 % The format of the ExternalDelegateCommand method is:
326 %
327 % int ExternalDelegateCommand(const MagickBooleanType asynchronous,
328 % const MagickBooleanType verbose,const char *command,
329 % char *message,ExceptionInfo *exception)
330 %
331 % A description of each parameter follows:
332 %
333 % o asynchronous: a value other than 0 executes the parent program
334 % concurrently with the new child process.
335 %
336 % o verbose: a value other than 0 prints the executed command before it is
337 % invoked.
338 %
339 % o command: this string is the command to execute.
340 %
341 % o message: an option buffer to receive any message posted to stdout or
342 % stderr.
343 %
344 % o exception: return any errors here.
345 %
346 */
348  const MagickBooleanType verbose,const char *command,char *message,
349  ExceptionInfo *exception)
350 {
351  char
352  **arguments,
353  *sanitize_command;
354 
355  int
356  number_arguments,
357  status;
358 
360  domain;
361 
363  rights;
364 
365  ssize_t
366  i;
367 
368  status=(-1);
369  arguments=StringToArgv(command,&number_arguments);
370  if (arguments == (char **) NULL)
371  return(status);
372  if (*arguments[1] == '\0')
373  {
374  for (i=0; i < (ssize_t) number_arguments; i++)
375  arguments[i]=DestroyString(arguments[i]);
376  arguments=(char **) RelinquishMagickMemory(arguments);
377  return(-1);
378  }
379  rights=ExecutePolicyRights;
380  domain=DelegatePolicyDomain;
381  if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
382  {
383  errno=EPERM;
385  "NotAuthorized","`%s'",arguments[1]);
386  for (i=0; i < (ssize_t) number_arguments; i++)
387  arguments[i]=DestroyString(arguments[i]);
388  arguments=(char **) RelinquishMagickMemory(arguments);
389  return(-1);
390  }
391  if (verbose != MagickFalse)
392  {
393  (void) FormatLocaleFile(stderr,"%s\n",command);
394  (void) fflush(stderr);
395  }
396  sanitize_command=SanitizeString(command);
397  if (asynchronous != MagickFalse)
398  (void) ConcatenateMagickString(sanitize_command,"&",MagickPathExtent);
399  if (message != (char *) NULL)
400  *message='\0';
401 #if defined(MAGICKCORE_POSIX_SUPPORT)
402 #if defined(MAGICKCORE_HAVE_POPEN)
403  if ((asynchronous == MagickFalse) && (message != (char *) NULL))
404  {
405  char
406  buffer[MagickPathExtent];
407 
408  FILE
409  *file;
410 
411  size_t
412  offset;
413 
414  offset=0;
415  file=popen_utf8(sanitize_command,"r");
416  if (file == (FILE *) NULL)
417  status=system(sanitize_command);
418  else
419  {
420  while (fgets(buffer,(int) sizeof(buffer),file) != NULL)
421  {
422  size_t
423  length;
424 
425  length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
426  if (length > 0)
427  {
428  (void) CopyMagickString(message+offset,buffer,length);
429  offset+=length-1;
430  }
431  }
432  status=pclose(file);
433  }
434  }
435  else
436 #endif
437  {
438 #if !defined(MAGICKCORE_HAVE_EXECVP)
439  status=system(sanitize_command);
440 #else
441  if ((asynchronous != MagickFalse) ||
442  (strpbrk(sanitize_command,"&;<>|") != (char *) NULL))
443  status=system(sanitize_command);
444  else
445  {
446  pid_t
447  child_pid;
448 
449  /*
450  Call application directly rather than from a shell.
451  */
452  child_pid=(pid_t) fork();
453  if (child_pid == (pid_t) -1)
454  status=system(sanitize_command);
455  else
456  if (child_pid == 0)
457  {
458  status=execvp(arguments[1],arguments+1);
459  _exit(1);
460  }
461  else
462  {
463  int
464  child_status;
465 
466  pid_t
467  pid;
468 
469  child_status=0;
470  pid=(pid_t) waitpid(child_pid,&child_status,0);
471  if (pid == -1)
472  status=(-1);
473  else
474  {
475  if (WIFEXITED(child_status) != 0)
476  status=WEXITSTATUS(child_status);
477  else
478  if (WIFSIGNALED(child_status))
479  status=(-1);
480  }
481  }
482  }
483 #endif
484  }
485 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
486  {
487  char
488  *p;
489 
490  /*
491  If a command shell is executed we need to change the forward slashes in
492  files to a backslash. We need to do this to keep Windows happy when we
493  want to 'move' a file.
494 
495  TODO: This won't work if one of the delegate parameters has a forward
496  slash as aparameter.
497  */
498  p=strstr(sanitize_command,"cmd.exe /c");
499  if (p != (char*) NULL)
500  {
501  p+=10;
502  for ( ; *p != '\0'; p++)
503  if (*p == '/')
504  *p=(*DirectorySeparator);
505  }
506  }
507  status=NTSystemCommand(sanitize_command,message);
508 #elif defined(vms)
509  status=system(sanitize_command);
510 #else
511 # error No suitable system() method.
512 #endif
513  if (status < 0)
514  {
515  if ((message != (char *) NULL) && (*message != '\0'))
517  "FailedToExecuteCommand","`%s' (%s)",sanitize_command,message);
518  else
520  "FailedToExecuteCommand","`%s' (%d)",sanitize_command,status);
521  }
522  sanitize_command=DestroyString(sanitize_command);
523  for (i=0; i < (ssize_t) number_arguments; i++)
524  arguments[i]=DestroyString(arguments[i]);
525  arguments=(char **) RelinquishMagickMemory(arguments);
526  return(status);
527 }
528 
529 /*
530 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
531 % %
532 % %
533 % %
534 % G e t D e l e g a t e C o m m a n d %
535 % %
536 % %
537 % %
538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
539 %
540 % GetDelegateCommand() replaces any embedded formatting characters with the
541 % appropriate image attribute and returns the resulting command.
542 %
543 % The format of the GetDelegateCommand method is:
544 %
545 % char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
546 % const char *decode,const char *encode,ExceptionInfo *exception)
547 %
548 % A description of each parameter follows:
549 %
550 % o command: Method GetDelegateCommand returns the command associated
551 % with specified delegate tag.
552 %
553 % o image_info: the image info.
554 %
555 % o image: the image.
556 %
557 % o decode: Specifies the decode delegate we are searching for as a
558 % character string.
559 %
560 % o encode: Specifies the encode delegate we are searching for as a
561 % character string.
562 %
563 % o exception: return any errors or warnings in this structure.
564 %
565 */
566 
567 static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
568  const char letter,ExceptionInfo *exception)
569 {
570 #define WarnNoImageReturn(format,letter) \
571  if (image == (Image *) NULL) \
572  { \
573  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
574  "NoImageForProperty",format,letter); \
575  break; \
576  }
577 #define WarnNoImageInfoReturn(format,letter) \
578  if (image_info == (ImageInfo *) NULL) \
579  { \
580  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
581  "NoImageInfoForProperty",format,letter); \
582  break; \
583  }
584 
585  char
586  value[MagickPathExtent];
587 
588  const char
589  *string;
590 
591  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
592  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
593  else
594  if ((image_info != (ImageInfo *) NULL) &&
595  (image_info->debug != MagickFalse))
596  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
597  /*
598  Get properties that are directly defined by images.
599  */
600  *value='\0'; /* formatted string */
601  string=(const char *) value;
602  switch (letter)
603  {
604  case 'a': /* authentication passphase */
605  {
606  WarnNoImageInfoReturn("\"%%%c\"",letter);
607  string=GetImageOption(image_info,"authenticate");
608  break;
609  }
610  case 'b': /* image size read in - in bytes */
611  {
612  WarnNoImageReturn("\"%%%c\"",letter);
614  value);
615  if (image->extent == 0)
616  (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
617  MagickPathExtent,value);
618  break;
619  }
620  case 'd': /* Directory component of filename */
621  {
622  WarnNoImageReturn("\"%%%c\"",letter);
624  break;
625  }
626  case 'e': /* Filename extension (suffix) of image file */
627  {
628  WarnNoImageReturn("\"%%%c\"",letter);
630  break;
631  }
632  case 'f': /* Filename without directory component */
633  {
634  WarnNoImageReturn("\"%%%c\"",letter);
636  break;
637  }
638  case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
639  {
640  WarnNoImageReturn("\"%%%c\"",letter);
642  "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
643  image->page.height,(double) image->page.x,(double) image->page.y);
644  break;
645  }
646  case 'h': /* Image height (current) */
647  {
648  WarnNoImageReturn("\"%%%c\"",letter);
649  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
650  (image->rows != 0 ? image->rows : image->magick_rows));
651  break;
652  }
653  case 'i': /* Filename last used for an image (read or write) */
654  {
655  WarnNoImageReturn("\"%%%c\"",letter);
656  string=image->filename;
657  break;
658  }
659  case 'm': /* Image format (file magick) */
660  {
661  WarnNoImageReturn("\"%%%c\"",letter);
662  string=image->magick;
663  break;
664  }
665  case 'n': /* Number of images in the list. */
666  {
667  if (image != (Image *) NULL)
668  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
669  GetImageListLength(image));
670  break;
671  }
672  case 'o': /* Output Filename */
673  {
674  WarnNoImageInfoReturn("\"%%%c\"",letter);
675  string=image_info->filename;
676  break;
677  }
678  case 'p': /* Image index in current image list */
679  {
680  WarnNoImageReturn("\"%%%c\"",letter);
681  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
682  GetImageIndexInList(image));
683  break;
684  }
685  case 'q': /* Quantum depth of image in memory */
686  {
687  WarnNoImageReturn("\"%%%c\"",letter);
688  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
690  break;
691  }
692  case 'r': /* Image storage class, colorspace, and alpha enabled. */
693  {
695  colorspace;
696 
697  WarnNoImageReturn("\"%%%c\"",letter);
698  colorspace=image->colorspace;
699  (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
702  (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
703  "Alpha" : "");
704  break;
705  }
706  case 's': /* Image scene number */
707  {
708  WarnNoImageReturn("\"%%%c\"",letter);
709  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
710  image->scene);
711  break;
712  }
713  case 't': /* Base filename without directory or extention */
714  {
715  WarnNoImageReturn("\"%%%c\"",letter);
717  break;
718  }
719  case 'u': /* Unique filename */
720  {
721  WarnNoImageInfoReturn("\"%%%c\"",letter);
722  string=image_info->unique;
723  break;
724  }
725  case 'w': /* Image width (current) */
726  {
727  WarnNoImageReturn("\"%%%c\"",letter);
728  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
729  (image->columns != 0 ? image->columns : image->magick_columns));
730  break;
731  }
732  case 'x': /* Image horizontal resolution (with units) */
733  {
734  WarnNoImageReturn("\"%%%c\"",letter);
735  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
736  fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
739  break;
740  }
741  case 'y': /* Image vertical resolution (with units) */
742  {
743  WarnNoImageReturn("\"%%%c\"",letter);
744  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
745  fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
748  break;
749  }
750  case 'z': /* Image depth as read in */
751  {
752  WarnNoImageReturn("\"%%%c\"",letter);
753  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
754  (double) image->depth);
755  break;
756  }
757  case 'A': /* Image alpha channel */
758  {
759  WarnNoImageReturn("\"%%%c\"",letter);
761  image->alpha_trait);
762  break;
763  }
764  case 'C': /* Image compression method. */
765  {
766  WarnNoImageReturn("\"%%%c\"",letter);
768  (ssize_t) image->compression);
769  break;
770  }
771  case 'D': /* Image dispose method. */
772  {
773  WarnNoImageReturn("\"%%%c\"",letter);
775  (ssize_t) image->dispose);
776  break;
777  }
778  case 'F':
779  {
780  /*
781  Magick filename - filename given incl. coder & read mods.
782  */
783  WarnNoImageReturn("\"%%%c\"",letter);
785  break;
786  }
787  case 'G': /* Image size as geometry = "%wx%h" */
788  {
789  WarnNoImageReturn("\"%%%c\"",letter);
790  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
791  (double) image->magick_columns,(double) image->magick_rows);
792  break;
793  }
794  case 'H': /* layer canvas height */
795  {
796  WarnNoImageReturn("\"%%%c\"",letter);
797  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
798  (double) image->page.height);
799  break;
800  }
801  case 'I': /* image iterations for animations */
802  {
803  WarnNoImageReturn("\"%%%c\"",letter);
804  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
805  image->iterations);
806  break;
807  }
808  case 'M': /* Magick filename - filename given incl. coder & read mods */
809  {
810  WarnNoImageReturn("\"%%%c\"",letter);
811  string=image->magick_filename;
812  break;
813  }
814  case 'O': /* layer canvas offset with sign = "+%X+%Y" */
815  {
816  WarnNoImageReturn("\"%%%c\"",letter);
817  (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
818  image->page.x,(long) image->page.y);
819  break;
820  }
821  case 'P': /* layer canvas page size = "%Wx%H" */
822  {
823  WarnNoImageReturn("\"%%%c\"",letter);
824  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
825  (double) image->page.width,(double) image->page.height);
826  break;
827  }
828  case '~': /* BPG image compression quality */
829  {
830  WarnNoImageReturn("\"%%%c\"",letter);
831  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
832  (100-(image->quality == 0 ? 42 : image->quality))/2);
833  break;
834  }
835  case 'Q': /* image compression quality */
836  {
837  WarnNoImageReturn("\"%%%c\"",letter);
838  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
839  (image->quality == 0 ? 92 : image->quality));
840  break;
841  }
842  case 'S': /* Number of scenes in image list. */
843  {
844  WarnNoImageInfoReturn("\"%%%c\"",letter);
845  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
846  (image_info->number_scenes == 0 ? 2147483647 :
847  image_info->number_scenes));
848  break;
849  }
850  case 'T': /* image time delay for animations */
851  {
852  WarnNoImageReturn("\"%%%c\"",letter);
853  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
854  image->delay);
855  break;
856  }
857  case 'U': /* Image resolution units. */
858  {
859  WarnNoImageReturn("\"%%%c\"",letter);
861  (ssize_t) image->units);
862  break;
863  }
864  case 'W': /* layer canvas width */
865  {
866  WarnNoImageReturn("\"%%%c\"",letter);
867  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
868  image->page.width);
869  break;
870  }
871  case 'X': /* layer canvas X offset */
872  {
873  WarnNoImageReturn("\"%%%c\"",letter);
874  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
875  image->page.x);
876  break;
877  }
878  case 'Y': /* layer canvas Y offset */
879  {
880  WarnNoImageReturn("\"%%%c\"",letter);
881  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
882  image->page.y);
883  break;
884  }
885  case '%': /* percent escaped */
886  {
887  string="%";
888  break;
889  }
890  case '@': /* Trim bounding box, without actually trimming! */
891  {
893  page;
894 
895  WarnNoImageReturn("\"%%%c\"",letter);
896  page=GetImageBoundingBox(image,exception);
898  "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
899  (double) page.x,(double) page.y);
900  break;
901  }
902  case '#':
903  {
904  /*
905  Image signature.
906  */
907  WarnNoImageReturn("\"%%%c\"",letter);
908  (void) SignatureImage(image,exception);
909  string=GetImageProperty(image,"signature",exception);
910  break;
911  }
912  }
913  return(SanitizeDelegateString(string));
914 }
915 
916 static char *InterpretDelegateProperties(ImageInfo *image_info,
917  Image *image,const char *embed_text,ExceptionInfo *exception)
918 {
919 #define ExtendInterpretText(string_length) \
920 { \
921  size_t length=(string_length); \
922  if ((size_t) (q-interpret_text+length+1) >= extent) \
923  { \
924  extent+=length; \
925  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
926  MagickPathExtent,sizeof(*interpret_text)); \
927  if (interpret_text == (char *) NULL) \
928  return((char *) NULL); \
929  q=interpret_text+strlen(interpret_text); \
930  } \
931 }
932 
933 #define AppendKeyValue2Text(key,value)\
934 { \
935  size_t length=strlen(key)+strlen(value)+2; \
936  if ((size_t) (q-interpret_text+length+1) >= extent) \
937  { \
938  extent+=length; \
939  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
940  MagickPathExtent,sizeof(*interpret_text)); \
941  if (interpret_text == (char *) NULL) \
942  return((char *) NULL); \
943  q=interpret_text+strlen(interpret_text); \
944  } \
945  q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
946 }
947 
948 #define AppendString2Text(string) \
949 { \
950  size_t length=strlen((string)); \
951  if ((size_t) (q-interpret_text+length+1) >= extent) \
952  { \
953  extent+=length; \
954  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
955  MagickPathExtent,sizeof(*interpret_text)); \
956  if (interpret_text == (char *) NULL) \
957  return((char *) NULL); \
958  q=interpret_text+strlen(interpret_text); \
959  } \
960  (void) CopyMagickString(q,(string),extent); \
961  q+=length; \
962 }
963 
964  char
965  *interpret_text,
966  *string;
967 
968  char
969  *q; /* current position in interpret_text */
970 
971  const char
972  *p; /* position in embed_text string being expanded */
973 
974  size_t
975  extent; /* allocated length of interpret_text */
976 
978  number;
979 
980  assert(image == NULL || image->signature == MagickCoreSignature);
981  assert(image_info == NULL || image_info->signature == MagickCoreSignature);
982  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
983  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
984  else
985  if ((image_info != (ImageInfo *) NULL) && (image_info->debug != MagickFalse))
986  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
987  if (embed_text == (const char *) NULL)
988  return(ConstantString(""));
989  p=embed_text;
990  while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
991  p++;
992  if (*p == '\0')
993  return(ConstantString(""));
994  /*
995  Translate any embedded format characters.
996  */
997  interpret_text=AcquireString(embed_text); /* new string with extra space */
998  extent=MagickPathExtent; /* allocated space in string */
999  number=MagickFalse; /* is last char a number? */
1000  for (q=interpret_text; *p!='\0';
1001  number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
1002  {
1003  /*
1004  Interpret escape characters (e.g. Filename: %M).
1005  */
1006  *q='\0';
1008  switch (*p)
1009  {
1010  case '\\':
1011  {
1012  switch (*(p+1))
1013  {
1014  case '\0':
1015  continue;
1016  case 'r': /* convert to RETURN */
1017  {
1018  *q++='\r';
1019  p++;
1020  continue;
1021  }
1022  case 'n': /* convert to NEWLINE */
1023  {
1024  *q++='\n';
1025  p++;
1026  continue;
1027  }
1028  case '\n': /* EOL removal UNIX,MacOSX */
1029  {
1030  p++;
1031  continue;
1032  }
1033  case '\r': /* EOL removal DOS,Windows */
1034  {
1035  p++;
1036  if (*p == '\n') /* return-newline EOL */
1037  p++;
1038  continue;
1039  }
1040  default:
1041  {
1042  p++;
1043  *q++=(*p);
1044  }
1045  }
1046  continue;
1047  }
1048  case '&':
1049  {
1050  if (LocaleNCompare("&lt;",p,4) == 0)
1051  {
1052  *q++='<';
1053  p+=3;
1054  }
1055  else
1056  if (LocaleNCompare("&gt;",p,4) == 0)
1057  {
1058  *q++='>';
1059  p+=3;
1060  }
1061  else
1062  if (LocaleNCompare("&amp;",p,5) == 0)
1063  {
1064  *q++='&';
1065  p+=4;
1066  }
1067  else
1068  *q++=(*p);
1069  continue;
1070  }
1071  case '%':
1072  break; /* continue to next set of handlers */
1073  default:
1074  {
1075  *q++=(*p); /* any thing else is 'as normal' */
1076  continue;
1077  }
1078  }
1079  p++; /* advance beyond the percent */
1080  /*
1081  Doubled Percent - or percent at end of string.
1082  */
1083  if ((*p == '\0') || (*p == '\'') || (*p == '"'))
1084  p--;
1085  if (*p == '%')
1086  {
1087  *q++='%';
1088  continue;
1089  }
1090  /*
1091  Single letter escapes %c.
1092  */
1093  if (number != MagickFalse)
1094  {
1095  /*
1096  But only if not preceeded by a number!
1097  */
1098  *q++='%'; /* do NOT substitute the percent */
1099  p--; /* back up one */
1100  continue;
1101  }
1102  string=GetMagickPropertyLetter(image_info,image,*p,exception);
1103  if (string != (char *) NULL)
1104  {
1105  AppendString2Text(string);
1106  string=DestroyString(string);
1107  continue;
1108  }
1110  "UnknownImageProperty","\"%%%c\"",*p);
1111  }
1112  *q='\0';
1113  return(interpret_text);
1114 }
1115 
1116 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
1117  const char *decode,const char *encode,ExceptionInfo *exception)
1118 {
1119  char
1120  *command,
1121  **commands;
1122 
1123  const DelegateInfo
1124  *delegate_info;
1125 
1126  ssize_t
1127  i;
1128 
1129  assert(image_info != (ImageInfo *) NULL);
1130  assert(image_info->signature == MagickCoreSignature);
1131  assert(image != (Image *) NULL);
1132  assert(image->signature == MagickCoreSignature);
1133  if (image->debug != MagickFalse)
1134  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1135 
1136  delegate_info=GetDelegateInfo(decode,encode,exception);
1137  if (delegate_info == (const DelegateInfo *) NULL)
1138  {
1140  "NoTagFound","`%s'",decode ? decode : encode);
1141  return((char *) NULL);
1142  }
1143  commands=StringToList(delegate_info->commands);
1144  if (commands == (char **) NULL)
1145  {
1146  (void) ThrowMagickException(exception,GetMagickModule(),
1147  ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode :
1148  encode);
1149  return((char *) NULL);
1150  }
1151  command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1152  commands[0],exception);
1153  if (command == (char *) NULL)
1155  "MemoryAllocationFailed","`%s'",commands[0]);
1156  /*
1157  Relinquish resources.
1158  */
1159  for (i=0; commands[i] != (char *) NULL; i++)
1160  commands[i]=DestroyString(commands[i]);
1161  commands=(char **) RelinquishMagickMemory(commands);
1162  return(command);
1163 }
1164 
1165 /*
1166 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1167 % %
1168 % %
1169 % %
1170 % G e t D e l e g a t e C o m m a n d s %
1171 % %
1172 % %
1173 % %
1174 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1175 %
1176 % GetDelegateCommands() returns the commands associated with a delegate.
1177 %
1178 % The format of the GetDelegateCommands method is:
1179 %
1180 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1181 %
1182 % A description of each parameter follows:
1183 %
1184 % o delegate_info: The delegate info.
1185 %
1186 */
1187 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1188 {
1189  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1190 
1191  assert(delegate_info != (DelegateInfo *) NULL);
1192  assert(delegate_info->signature == MagickCoreSignature);
1193  return(delegate_info->commands);
1194 }
1195 
1196 /*
1197 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1198 % %
1199 % %
1200 % %
1201 % G e t D e l e g a t e I n f o %
1202 % %
1203 % %
1204 % %
1205 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1206 %
1207 % GetDelegateInfo() returns any delegates associated with the specified tag.
1208 %
1209 % The format of the GetDelegateInfo method is:
1210 %
1211 % const DelegateInfo *GetDelegateInfo(const char *decode,
1212 % const char *encode,ExceptionInfo *exception)
1213 %
1214 % A description of each parameter follows:
1215 %
1216 % o decode: Specifies the decode delegate we are searching for as a
1217 % character string.
1218 %
1219 % o encode: Specifies the encode delegate we are searching for as a
1220 % character string.
1221 %
1222 % o exception: return any errors or warnings in this structure.
1223 %
1224 */
1225 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
1226  const char *encode,ExceptionInfo *exception)
1227 {
1228  const DelegateInfo
1229  *p;
1230 
1231  assert(exception != (ExceptionInfo *) NULL);
1232  if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1233  return((const DelegateInfo *) NULL);
1234  /*
1235  Search for named delegate.
1236  */
1240  if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
1241  {
1243  return(p);
1244  }
1245  while (p != (const DelegateInfo *) NULL)
1246  {
1247  if (p->mode > 0)
1248  {
1249  if (LocaleCompare(p->decode,decode) == 0)
1250  break;
1252  continue;
1253  }
1254  if (p->mode < 0)
1255  {
1256  if (LocaleCompare(p->encode,encode) == 0)
1257  break;
1259  continue;
1260  }
1261  if (LocaleCompare(decode,p->decode) == 0)
1262  if (LocaleCompare(encode,p->encode) == 0)
1263  break;
1264  if (LocaleCompare(decode,"*") == 0)
1265  if (LocaleCompare(encode,p->encode) == 0)
1266  break;
1267  if (LocaleCompare(decode,p->decode) == 0)
1268  if (LocaleCompare(encode,"*") == 0)
1269  break;
1271  }
1272  if (p != (const DelegateInfo *) NULL)
1276  return(p);
1277 }
1278 
1279 /*
1280 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1281 % %
1282 % %
1283 % %
1284 % G e t D e l e g a t e I n f o L i s t %
1285 % %
1286 % %
1287 % %
1288 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1289 %
1290 % GetDelegateInfoList() returns any delegates that match the specified pattern.
1291 %
1292 % The delegate of the GetDelegateInfoList function is:
1293 %
1294 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
1295 % size_t *number_delegates,ExceptionInfo *exception)
1296 %
1297 % A description of each parameter follows:
1298 %
1299 % o pattern: Specifies a pointer to a text string containing a pattern.
1300 %
1301 % o number_delegates: This integer returns the number of delegates in the
1302 % list.
1303 %
1304 % o exception: return any errors or warnings in this structure.
1305 %
1306 */
1307 
1308 #if defined(__cplusplus) || defined(c_plusplus)
1309 extern "C" {
1310 #endif
1311 
1312 static int DelegateInfoCompare(const void *x,const void *y)
1313 {
1314  const DelegateInfo
1315  **p,
1316  **q;
1317 
1318  int
1319  cmp;
1320 
1321  p=(const DelegateInfo **) x,
1322  q=(const DelegateInfo **) y;
1323  cmp=LocaleCompare((*p)->path,(*q)->path);
1324  if (cmp == 0)
1325  {
1326  if ((*p)->decode == (char *) NULL)
1327  if (((*p)->encode != (char *) NULL) &&
1328  ((*q)->encode != (char *) NULL))
1329  return(strcmp((*p)->encode,(*q)->encode));
1330  if (((*p)->decode != (char *) NULL) &&
1331  ((*q)->decode != (char *) NULL))
1332  return(strcmp((*p)->decode,(*q)->decode));
1333  }
1334  return(cmp);
1335 }
1336 
1337 #if defined(__cplusplus) || defined(c_plusplus)
1338 }
1339 #endif
1340 
1341 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
1342  size_t *number_delegates,ExceptionInfo *exception)
1343 {
1344  const DelegateInfo
1345  **delegates;
1346 
1347  const DelegateInfo
1348  *p;
1349 
1350  ssize_t
1351  i;
1352 
1353  /*
1354  Allocate delegate list.
1355  */
1356  assert(number_delegates != (size_t *) NULL);
1357  assert(pattern != (char *) NULL);
1358  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1359 
1360  *number_delegates=0;
1361  p=GetDelegateInfo("*","*",exception);
1362  if (p == (const DelegateInfo *) NULL)
1363  return((const DelegateInfo **) NULL);
1364  delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
1365  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1366  if (delegates == (const DelegateInfo **) NULL)
1367  return((const DelegateInfo **) NULL);
1368  /*
1369  Generate delegate list.
1370  */
1374  for (i=0; p != (const DelegateInfo *) NULL; )
1375  {
1376  if( (p->stealth == MagickFalse) &&
1377  ( GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse ||
1378  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse) )
1379  delegates[i++]=p;
1381  }
1383  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
1384  delegates[i]=(DelegateInfo *) NULL;
1385  *number_delegates=(size_t) i;
1386  return(delegates);
1387 }
1388 
1389 /*
1390 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1391 % %
1392 % %
1393 % %
1394 % G e t D e l e g a t e L i s t %
1395 % %
1396 % %
1397 % %
1398 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1399 %
1400 % GetDelegateList() returns any image format delegates that match the
1401 % specified pattern.
1402 %
1403 % The format of the GetDelegateList function is:
1404 %
1405 % char **GetDelegateList(const char *pattern,
1406 % size_t *number_delegates,ExceptionInfo *exception)
1407 %
1408 % A description of each parameter follows:
1409 %
1410 % o pattern: Specifies a pointer to a text string containing a pattern.
1411 %
1412 % o number_delegates: This integer returns the number of delegates
1413 % in the list.
1414 %
1415 % o exception: return any errors or warnings in this structure.
1416 %
1417 */
1418 
1419 #if defined(__cplusplus) || defined(c_plusplus)
1420 extern "C" {
1421 #endif
1422 
1423 static int DelegateCompare(const void *x,const void *y)
1424 {
1425  const char
1426  **p,
1427  **q;
1428 
1429  p=(const char **) x;
1430  q=(const char **) y;
1431  return(LocaleCompare(*p,*q));
1432 }
1433 
1434 #if defined(__cplusplus) || defined(c_plusplus)
1435 }
1436 #endif
1437 
1438 MagickExport char **GetDelegateList(const char *pattern,
1439  size_t *number_delegates,ExceptionInfo *exception)
1440 {
1441  char
1442  **delegates;
1443 
1444  const DelegateInfo
1445  *p;
1446 
1447  ssize_t
1448  i;
1449 
1450  /*
1451  Allocate delegate list.
1452  */
1453  assert(pattern != (char *) NULL);
1454  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1455 
1456  assert(number_delegates != (size_t *) NULL);
1457  *number_delegates=0;
1458  p=GetDelegateInfo("*","*",exception);
1459  if (p == (const DelegateInfo *) NULL)
1460  return((char **) NULL);
1461  delegates=(char **) AcquireQuantumMemory((size_t)
1462  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1463  if (delegates == (char **) NULL)
1464  return((char **) NULL);
1468  for (i=0; p != (const DelegateInfo *) NULL; )
1469  {
1470  if( (p->stealth == MagickFalse) &&
1471  GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse )
1472  delegates[i++]=ConstantString(p->decode);
1473  if( (p->stealth == MagickFalse) &&
1474  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse )
1475  delegates[i++]=ConstantString(p->encode);
1477  }
1479  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
1480  delegates[i]=(char *) NULL;
1481  *number_delegates=(size_t) i;
1482  return(delegates);
1483 }
1484 
1485 /*
1486 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1487 % %
1488 % %
1489 % %
1490 % G e t D e l e g a t e M o d e %
1491 % %
1492 % %
1493 % %
1494 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1495 %
1496 % GetDelegateMode() returns the mode of the delegate.
1497 %
1498 % The format of the GetDelegateMode method is:
1499 %
1500 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1501 %
1502 % A description of each parameter follows:
1503 %
1504 % o delegate_info: The delegate info.
1505 %
1506 */
1507 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1508 {
1509  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1510 
1511  assert(delegate_info != (DelegateInfo *) NULL);
1512  assert(delegate_info->signature == MagickCoreSignature);
1513  return(delegate_info->mode);
1514 }
1515 
1516 /*
1517 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1518 % %
1519 % %
1520 % %
1521 + G e t D e l e g a t e T h r e a d S u p p o r t %
1522 % %
1523 % %
1524 % %
1525 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1526 %
1527 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
1528 % threads.
1529 %
1530 % The format of the GetDelegateThreadSupport method is:
1531 %
1532 % MagickBooleanType GetDelegateThreadSupport(
1533 % const DelegateInfo *delegate_info)
1534 %
1535 % A description of each parameter follows:
1536 %
1537 % o delegate_info: The delegate info.
1538 %
1539 */
1541  const DelegateInfo *delegate_info)
1542 {
1543  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1544 
1545  assert(delegate_info != (DelegateInfo *) NULL);
1546  assert(delegate_info->signature == MagickCoreSignature);
1547  return(delegate_info->thread_support);
1548 }
1549 
1550 /*
1551 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1552 % %
1553 % %
1554 % %
1555 + I s D e l e g a t e C a c h e I n s t a n t i a t e d %
1556 % %
1557 % %
1558 % %
1559 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1560 %
1561 % IsDelegateCacheInstantiated() determines if the delegate cache is
1562 % instantiated. If not, it instantiates the cache and returns it.
1563 %
1564 % The format of the IsDelegateInstantiated method is:
1565 %
1566 % MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1567 %
1568 % A description of each parameter follows.
1569 %
1570 % o exception: return any errors or warnings in this structure.
1571 %
1572 */
1574 {
1575  if (delegate_cache == (LinkedListInfo *) NULL)
1576  {
1577  if (delegate_semaphore == (SemaphoreInfo *) NULL)
1580  if (delegate_cache == (LinkedListInfo *) NULL)
1583  }
1584  return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1585 }
1586 
1587 /*
1588 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1589 % %
1590 % %
1591 % %
1592 % I n v o k e D e l e g a t e %
1593 % %
1594 % %
1595 % %
1596 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1597 %
1598 % InvokeDelegate replaces any embedded formatting characters with the
1599 % appropriate image attribute and executes the resulting command. MagickFalse
1600 % is returned if the commands execute with success otherwise MagickTrue.
1601 %
1602 % The format of the InvokeDelegate method is:
1603 %
1604 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
1605 % const char *decode,const char *encode,ExceptionInfo *exception)
1606 %
1607 % A description of each parameter follows:
1608 %
1609 % o image_info: the imageInfo.
1610 %
1611 % o image: the image.
1612 %
1613 % o exception: return any errors or warnings in this structure.
1614 %
1615 */
1616 
1617 static MagickBooleanType CopyDelegateFile(const char *source,
1618  const char *destination,const MagickBooleanType overwrite)
1619 {
1620  int
1621  destination_file,
1622  source_file;
1623 
1625  status;
1626 
1627  size_t
1628  i;
1629 
1630  size_t
1631  length,
1632  quantum;
1633 
1634  ssize_t
1635  count;
1636 
1637  struct stat
1638  attributes;
1639 
1640  unsigned char
1641  *buffer;
1642 
1643  /*
1644  Copy source file to destination.
1645  */
1646  assert(source != (const char *) NULL);
1647  assert(destination != (char *) NULL);
1648  if (overwrite == MagickFalse)
1649  {
1650  status=GetPathAttributes(destination,&attributes);
1651  if (status != MagickFalse)
1652  return(MagickTrue);
1653  }
1654  destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1655  if (destination_file == -1)
1656  return(MagickFalse);
1657  source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1658  if (source_file == -1)
1659  {
1660  (void) close(destination_file);
1661  return(MagickFalse);
1662  }
1663  quantum=(size_t) MagickMaxBufferExtent;
1664  if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1665  quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
1666  buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
1667  if (buffer == (unsigned char *) NULL)
1668  {
1669  (void) close(source_file);
1670  (void) close(destination_file);
1671  return(MagickFalse);
1672  }
1673  length=0;
1674  for (i=0; ; i+=count)
1675  {
1676  count=(ssize_t) read(source_file,buffer,quantum);
1677  if (count <= 0)
1678  break;
1679  length=(size_t) count;
1680  count=(ssize_t) write(destination_file,buffer,length);
1681  if ((size_t) count != length)
1682  break;
1683  }
1684  (void) close(destination_file);
1685  (void) close(source_file);
1686  buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1687  return(i != 0 ? MagickTrue : MagickFalse);
1688 }
1689 
1691  Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
1692 {
1693  char
1694  *command,
1695  **commands,
1696  input_filename[MagickPathExtent],
1697  output_filename[MagickPathExtent];
1698 
1699  const DelegateInfo
1700  *delegate_info;
1701 
1703  status,
1704  temporary;
1705 
1706  PolicyRights
1707  rights;
1708 
1709  ssize_t
1710  i;
1711 
1712  /*
1713  Get delegate.
1714  */
1715  assert(image_info != (ImageInfo *) NULL);
1716  assert(image_info->signature == MagickCoreSignature);
1717  assert(image != (Image *) NULL);
1718  assert(image->signature == MagickCoreSignature);
1719  if (image->debug != MagickFalse)
1720  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1721  rights=ExecutePolicyRights;
1722  if ((decode != (const char *) NULL) &&
1724  {
1725  errno=EPERM;
1727  "NotAuthorized","`%s'",decode);
1728  return(MagickFalse);
1729  }
1730  if ((encode != (const char *) NULL) &&
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  if (delegate_info->commands != (char *) NULL)
2222  delegate_info->commands=DestroyString(delegate_info->commands);
2223  delegate_info->commands=commands;
2224  break;
2225  }
2226  break;
2227  }
2228  case 'D':
2229  case 'd':
2230  {
2231  if (LocaleCompare((char *) keyword,"decode") == 0)
2232  {
2233  delegate_info->decode=ConstantString(token);
2234  delegate_info->mode=1;
2235  break;
2236  }
2237  break;
2238  }
2239  case 'E':
2240  case 'e':
2241  {
2242  if (LocaleCompare((char *) keyword,"encode") == 0)
2243  {
2244  delegate_info->encode=ConstantString(token);
2245  delegate_info->mode=(-1);
2246  break;
2247  }
2248  break;
2249  }
2250  case 'M':
2251  case 'm':
2252  {
2253  if (LocaleCompare((char *) keyword,"mode") == 0)
2254  {
2255  delegate_info->mode=1;
2256  if (LocaleCompare(token,"bi") == 0)
2257  delegate_info->mode=0;
2258  else
2259  if (LocaleCompare(token,"encode") == 0)
2260  delegate_info->mode=(-1);
2261  break;
2262  }
2263  break;
2264  }
2265  case 'S':
2266  case 's':
2267  {
2268  if (LocaleCompare((char *) keyword,"spawn") == 0)
2269  {
2270  delegate_info->spawn=IsStringTrue(token);
2271  break;
2272  }
2273  if (LocaleCompare((char *) keyword,"stealth") == 0)
2274  {
2275  delegate_info->stealth=IsStringTrue(token);
2276  break;
2277  }
2278  break;
2279  }
2280  case 'T':
2281  case 't':
2282  {
2283  if (LocaleCompare((char *) keyword,"thread-support") == 0)
2284  {
2285  delegate_info->thread_support=IsStringTrue(token);
2286  if (delegate_info->thread_support == MagickFalse)
2287  delegate_info->semaphore=AcquireSemaphoreInfo();
2288  break;
2289  }
2290  break;
2291  }
2292  default:
2293  break;
2294  }
2295  }
2296  token=(char *) RelinquishMagickMemory(token);
2297  return(status != 0 ? MagickTrue : MagickFalse);
2298 }
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:1423
#define MagickMaxRecursionDepth
Definition: studio.h:338
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:1540
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:1341
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:1573
#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:1438
MagickExport const DelegateInfo * GetDelegateInfo(const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1225
#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:465
MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
Definition: delegate.c:1507
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:1187
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:319
ClassType storage_class
Definition: image.h:154
size_t width
Definition: geometry.h:132
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:916
static char * GetMagickPropertyLetter(ImageInfo *image_info, Image *image, const char letter, ExceptionInfo *exception)
Definition: delegate.c:567
double x
Definition: geometry.h:125
#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:645
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:1617
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:370
MagickBooleanType
Definition: magick-type.h:161
MagickExport char ** StringToList(const char *text)
Definition: string.c:2298
#define DirectorySeparator
Definition: studio.h:256
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:352
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:300
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:1116
MagickExport int LocaleNCompare(const char *p, const char *q, const size_t length)
Definition: locale.c:1525
double y
Definition: geometry.h:125
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:2781
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:1662
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:136
size_t height
Definition: geometry.h:132
MagickExport LinkedListInfo * NewLinkedList(const size_t capacity)
Definition: linked-list.c:713
MagickPrivate MagickBooleanType DelegateComponentGenesis(void)
Definition: delegate.c:254
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:347
#define S_MODE
Definition: studio.h:236
MagickBooleanType spawn
Definition: delegate.h:40
static void * DestroyDelegate(void *delegate_info)
Definition: delegate.c:280
#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:1401
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:1247
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:935
#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
#define magick_unreferenced(x)
MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, Image *image, const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1690
#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:136
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:317
MagickExport void LocaleUpper(char *string)
Definition: locale.c:1574
MagickExport char * ConstantString(const char *source)
Definition: string.c:678
static int DelegateInfoCompare(const void *x, const void *y)
Definition: delegate.c:1312
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