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