MagickCore  7.0.10
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-2020 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 !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 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
539  whitelist[] =
540  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
541  "$-_.+!;*(),{}|^~[]`\'><#%/?:@&=";
542 #else
543  whitelist[] =
544  "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789 "
545  "$-_.+!;*(),{}|\\^~[]`\"><#%/?:@&=";
546 #endif
547 
548  sanitize_source=AcquireString(source);
549  p=sanitize_source;
550  q=sanitize_source+strlen(sanitize_source);
551  for (p+=strspn(p,whitelist); p != q; p+=strspn(p,whitelist))
552  *p='_';
553  return(sanitize_source);
554 }
555 
556 static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
557  const char letter,ExceptionInfo *exception)
558 {
559 #define WarnNoImageReturn(format,letter) \
560  if (image == (Image *) NULL) \
561  { \
562  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
563  "NoImageForProperty",format,letter); \
564  break; \
565  }
566 #define WarnNoImageInfoReturn(format,letter) \
567  if (image_info == (ImageInfo *) NULL) \
568  { \
569  (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
570  "NoImageInfoForProperty",format,letter); \
571  break; \
572  }
573 
574  char
575  value[MagickPathExtent];
576 
577  const char
578  *string;
579 
580  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
581  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
582  else
583  if ((image_info != (ImageInfo *) NULL) &&
584  (image_info->debug != MagickFalse))
585  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images");
586  /*
587  Get properties that are directly defined by images.
588  */
589  *value='\0'; /* formatted string */
590  string=(const char *) value;
591  switch (letter)
592  {
593  case 'a': /* authentication passphase */
594  {
595  WarnNoImageInfoReturn("\"%%%c\"",letter);
596  string=GetImageOption(image_info,"authenticate");
597  break;
598  }
599  case 'b': /* image size read in - in bytes */
600  {
601  WarnNoImageReturn("\"%%%c\"",letter);
603  value);
604  if (image->extent == 0)
605  (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B",
606  MagickPathExtent,value);
607  break;
608  }
609  case 'd': /* Directory component of filename */
610  {
611  WarnNoImageReturn("\"%%%c\"",letter);
613  break;
614  }
615  case 'e': /* Filename extension (suffix) of image file */
616  {
617  WarnNoImageReturn("\"%%%c\"",letter);
619  break;
620  }
621  case 'f': /* Filename without directory component */
622  {
623  WarnNoImageReturn("\"%%%c\"",letter);
625  break;
626  }
627  case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */
628  {
629  WarnNoImageReturn("\"%%%c\"",letter);
631  "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double)
632  image->page.height,(double) image->page.x,(double) image->page.y);
633  break;
634  }
635  case 'h': /* Image height (current) */
636  {
637  WarnNoImageReturn("\"%%%c\"",letter);
638  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
639  (image->rows != 0 ? image->rows : image->magick_rows));
640  break;
641  }
642  case 'i': /* Filename last used for an image (read or write) */
643  {
644  WarnNoImageReturn("\"%%%c\"",letter);
645  string=image->filename;
646  break;
647  }
648  case 'm': /* Image format (file magick) */
649  {
650  WarnNoImageReturn("\"%%%c\"",letter);
651  string=image->magick;
652  break;
653  }
654  case 'n': /* Number of images in the list. */
655  {
656  if (image != (Image *) NULL)
657  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
658  GetImageListLength(image));
659  break;
660  }
661  case 'o': /* Output Filename */
662  {
663  WarnNoImageInfoReturn("\"%%%c\"",letter);
664  string=image_info->filename;
665  break;
666  }
667  case 'p': /* Image index in current image list */
668  {
669  WarnNoImageReturn("\"%%%c\"",letter);
670  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
671  GetImageIndexInList(image));
672  break;
673  }
674  case 'q': /* Quantum depth of image in memory */
675  {
676  WarnNoImageReturn("\"%%%c\"",letter);
677  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
679  break;
680  }
681  case 'r': /* Image storage class, colorspace, and alpha enabled. */
682  {
684  colorspace;
685 
686  WarnNoImageReturn("\"%%%c\"",letter);
687  colorspace=image->colorspace;
688  if (SetImageGray(image,exception) != MagickFalse)
689  colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */
690  (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s",
693  (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
694  "Alpha" : "");
695  break;
696  }
697  case 's': /* Image scene number */
698  {
699  WarnNoImageReturn("\"%%%c\"",letter);
700  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
701  image->scene);
702  break;
703  }
704  case 't': /* Base filename without directory or extention */
705  {
706  WarnNoImageReturn("\"%%%c\"",letter);
708  break;
709  }
710  case 'u': /* Unique filename */
711  {
712  WarnNoImageInfoReturn("\"%%%c\"",letter);
713  string=image_info->unique;
714  break;
715  }
716  case 'w': /* Image width (current) */
717  {
718  WarnNoImageReturn("\"%%%c\"",letter);
719  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
720  (image->columns != 0 ? image->columns : image->magick_columns));
721  break;
722  }
723  case 'x': /* Image horizontal resolution (with units) */
724  {
725  WarnNoImageReturn("\"%%%c\"",letter);
726  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
727  fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0);
728  break;
729  }
730  case 'y': /* Image vertical resolution (with units) */
731  {
732  WarnNoImageReturn("\"%%%c\"",letter);
733  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
734  fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0);
735  break;
736  }
737  case 'z': /* Image depth as read in */
738  {
739  WarnNoImageReturn("\"%%%c\"",letter);
740  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
741  (double) image->depth);
742  break;
743  }
744  case 'A': /* Image alpha channel */
745  {
746  WarnNoImageReturn("\"%%%c\"",letter);
748  image->alpha_trait);
749  break;
750  }
751  case 'C': /* Image compression method. */
752  {
753  WarnNoImageReturn("\"%%%c\"",letter);
755  (ssize_t) image->compression);
756  break;
757  }
758  case 'D': /* Image dispose method. */
759  {
760  WarnNoImageReturn("\"%%%c\"",letter);
762  (ssize_t) image->dispose);
763  break;
764  }
765  case 'F':
766  {
767  /*
768  Magick filename - filename given incl. coder & read mods.
769  */
770  WarnNoImageReturn("\"%%%c\"",letter);
772  break;
773  }
774  case 'G': /* Image size as geometry = "%wx%h" */
775  {
776  WarnNoImageReturn("\"%%%c\"",letter);
777  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
778  (double) image->magick_columns,(double) image->magick_rows);
779  break;
780  }
781  case 'H': /* layer canvas height */
782  {
783  WarnNoImageReturn("\"%%%c\"",letter);
784  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",
785  (double) image->page.height);
786  break;
787  }
788  case 'I': /* image iterations for animations */
789  {
790  WarnNoImageReturn("\"%%%c\"",letter);
791  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
792  image->iterations);
793  break;
794  }
795  case 'M': /* Magick filename - filename given incl. coder & read mods */
796  {
797  WarnNoImageReturn("\"%%%c\"",letter);
798  string=image->magick_filename;
799  break;
800  }
801  case 'O': /* layer canvas offset with sign = "+%X+%Y" */
802  {
803  WarnNoImageReturn("\"%%%c\"",letter);
804  (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long)
805  image->page.x,(long) image->page.y);
806  break;
807  }
808  case 'P': /* layer canvas page size = "%Wx%H" */
809  {
810  WarnNoImageReturn("\"%%%c\"",letter);
811  (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g",
812  (double) image->page.width,(double) image->page.height);
813  break;
814  }
815  case '~': /* BPG image compression quality */
816  {
817  WarnNoImageReturn("\"%%%c\"",letter);
818  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
819  (100-(image->quality == 0 ? 42 : image->quality))/2);
820  break;
821  }
822  case 'Q': /* image compression quality */
823  {
824  WarnNoImageReturn("\"%%%c\"",letter);
825  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
826  (image->quality == 0 ? 92 : image->quality));
827  break;
828  }
829  case 'S': /* Number of scenes in image list. */
830  {
831  WarnNoImageInfoReturn("\"%%%c\"",letter);
832  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
833  (image_info->number_scenes == 0 ? 2147483647 :
834  image_info->number_scenes));
835  break;
836  }
837  case 'T': /* image time delay for animations */
838  {
839  WarnNoImageReturn("\"%%%c\"",letter);
840  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
841  image->delay);
842  break;
843  }
844  case 'U': /* Image resolution units. */
845  {
846  WarnNoImageReturn("\"%%%c\"",letter);
848  (ssize_t) image->units);
849  break;
850  }
851  case 'W': /* layer canvas width */
852  {
853  WarnNoImageReturn("\"%%%c\"",letter);
854  (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double)
855  image->page.width);
856  break;
857  }
858  case 'X': /* layer canvas X offset */
859  {
860  WarnNoImageReturn("\"%%%c\"",letter);
861  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
862  image->page.x);
863  break;
864  }
865  case 'Y': /* layer canvas Y offset */
866  {
867  WarnNoImageReturn("\"%%%c\"",letter);
868  (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double)
869  image->page.y);
870  break;
871  }
872  case '%': /* percent escaped */
873  {
874  string="%";
875  break;
876  }
877  case '@': /* Trim bounding box, without actually trimming! */
878  {
880  page;
881 
882  WarnNoImageReturn("\"%%%c\"",letter);
883  page=GetImageBoundingBox(image,exception);
885  "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height,
886  (double) page.x,(double) page.y);
887  break;
888  }
889  case '#':
890  {
891  /*
892  Image signature.
893  */
894  WarnNoImageReturn("\"%%%c\"",letter);
895  (void) SignatureImage(image,exception);
896  string=GetImageProperty(image,"signature",exception);
897  break;
898  }
899  }
900  return(SanitizeDelegateString(string));
901 }
902 
903 static char *InterpretDelegateProperties(ImageInfo *image_info,
904  Image *image,const char *embed_text,ExceptionInfo *exception)
905 {
906 #define ExtendInterpretText(string_length) \
907 { \
908  size_t length=(string_length); \
909  if ((size_t) (q-interpret_text+length+1) >= extent) \
910  { \
911  extent+=length; \
912  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
913  MaxTextExtent,sizeof(*interpret_text)); \
914  if (interpret_text == (char *) NULL) \
915  return((char *) NULL); \
916  q=interpret_text+strlen(interpret_text); \
917  } \
918 }
919 
920 #define AppendKeyValue2Text(key,value)\
921 { \
922  size_t length=strlen(key)+strlen(value)+2; \
923  if ((size_t) (q-interpret_text+length+1) >= extent) \
924  { \
925  extent+=length; \
926  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
927  MaxTextExtent,sizeof(*interpret_text)); \
928  if (interpret_text == (char *) NULL) \
929  return((char *) NULL); \
930  q=interpret_text+strlen(interpret_text); \
931  } \
932  q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
933 }
934 
935 #define AppendString2Text(string) \
936 { \
937  size_t length=strlen((string)); \
938  if ((size_t) (q-interpret_text+length+1) >= extent) \
939  { \
940  extent+=length; \
941  interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
942  MaxTextExtent,sizeof(*interpret_text)); \
943  if (interpret_text == (char *) NULL) \
944  return((char *) NULL); \
945  q=interpret_text+strlen(interpret_text); \
946  } \
947  (void) CopyMagickString(q,(string),extent); \
948  q+=length; \
949 }
950 
951  char
952  *interpret_text,
953  *string;
954 
955  register char
956  *q; /* current position in interpret_text */
957 
958  register const char
959  *p; /* position in embed_text string being expanded */
960 
961  size_t
962  extent; /* allocated length of interpret_text */
963 
965  number;
966 
967  assert(image == NULL || image->signature == MagickCoreSignature);
968  assert(image_info == NULL || image_info->signature == MagickCoreSignature);
969  if ((image != (Image *) NULL) && (image->debug != MagickFalse))
970  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
971  else
972  if ((image_info != (ImageInfo *) NULL) && (image_info->debug != MagickFalse))
973  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image");
974  if (embed_text == (const char *) NULL)
975  return(ConstantString(""));
976  p=embed_text;
977  while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0'))
978  p++;
979  if (*p == '\0')
980  return(ConstantString(""));
981  /*
982  Translate any embedded format characters.
983  */
984  interpret_text=AcquireString(embed_text); /* new string with extra space */
985  extent=MagickPathExtent; /* allocated space in string */
986  number=MagickFalse; /* is last char a number? */
987  for (q=interpret_text; *p!='\0';
988  number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
989  {
990  /*
991  Interpret escape characters (e.g. Filename: %M).
992  */
993  *q='\0';
995  switch (*p)
996  {
997  case '\\':
998  {
999  switch (*(p+1))
1000  {
1001  case '\0':
1002  continue;
1003  case 'r': /* convert to RETURN */
1004  {
1005  *q++='\r';
1006  p++;
1007  continue;
1008  }
1009  case 'n': /* convert to NEWLINE */
1010  {
1011  *q++='\n';
1012  p++;
1013  continue;
1014  }
1015  case '\n': /* EOL removal UNIX,MacOSX */
1016  {
1017  p++;
1018  continue;
1019  }
1020  case '\r': /* EOL removal DOS,Windows */
1021  {
1022  p++;
1023  if (*p == '\n') /* return-newline EOL */
1024  p++;
1025  continue;
1026  }
1027  default:
1028  {
1029  p++;
1030  *q++=(*p);
1031  }
1032  }
1033  continue;
1034  }
1035  case '&':
1036  {
1037  if (LocaleNCompare("&lt;",p,4) == 0)
1038  {
1039  *q++='<';
1040  p+=3;
1041  }
1042  else
1043  if (LocaleNCompare("&gt;",p,4) == 0)
1044  {
1045  *q++='>';
1046  p+=3;
1047  }
1048  else
1049  if (LocaleNCompare("&amp;",p,5) == 0)
1050  {
1051  *q++='&';
1052  p+=4;
1053  }
1054  else
1055  *q++=(*p);
1056  continue;
1057  }
1058  case '%':
1059  break; /* continue to next set of handlers */
1060  default:
1061  {
1062  *q++=(*p); /* any thing else is 'as normal' */
1063  continue;
1064  }
1065  }
1066  p++; /* advance beyond the percent */
1067  /*
1068  Doubled Percent - or percent at end of string.
1069  */
1070  if ((*p == '\0') || (*p == '\'') || (*p == '"'))
1071  p--;
1072  if (*p == '%')
1073  {
1074  *q++='%';
1075  continue;
1076  }
1077  /*
1078  Single letter escapes %c.
1079  */
1080  if (number != MagickFalse)
1081  {
1082  /*
1083  But only if not preceeded by a number!
1084  */
1085  *q++='%'; /* do NOT substitute the percent */
1086  p--; /* back up one */
1087  continue;
1088  }
1089  string=GetMagickPropertyLetter(image_info,image,*p,exception);
1090  if (string != (char *) NULL)
1091  {
1092  AppendString2Text(string);
1093  string=DestroyString(string);
1094  continue;
1095  }
1097  "UnknownImageProperty","\"%%%c\"",*p);
1098  }
1099  *q='\0';
1100  return(interpret_text);
1101 }
1102 
1103 MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
1104  const char *decode,const char *encode,ExceptionInfo *exception)
1105 {
1106  char
1107  *command,
1108  **commands;
1109 
1110  const DelegateInfo
1111  *delegate_info;
1112 
1113  register ssize_t
1114  i;
1115 
1116  assert(image_info != (ImageInfo *) NULL);
1117  assert(image_info->signature == MagickCoreSignature);
1118  assert(image != (Image *) NULL);
1119  assert(image->signature == MagickCoreSignature);
1120  if (image->debug != MagickFalse)
1121  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1122 
1123  delegate_info=GetDelegateInfo(decode,encode,exception);
1124  if (delegate_info == (const DelegateInfo *) NULL)
1125  {
1127  "NoTagFound","`%s'",decode ? decode : encode);
1128  return((char *) NULL);
1129  }
1130  commands=StringToList(delegate_info->commands);
1131  if (commands == (char **) NULL)
1132  {
1133  (void) ThrowMagickException(exception,GetMagickModule(),
1134  ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode :
1135  encode);
1136  return((char *) NULL);
1137  }
1138  command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1139  commands[0],exception);
1140  if (command == (char *) NULL)
1142  "MemoryAllocationFailed","`%s'",commands[0]);
1143  /*
1144  Relinquish resources.
1145  */
1146  for (i=0; commands[i] != (char *) NULL; i++)
1147  commands[i]=DestroyString(commands[i]);
1148  commands=(char **) RelinquishMagickMemory(commands);
1149  return(command);
1150 }
1151 
1152 /*
1153 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1154 % %
1155 % %
1156 % %
1157 % G e t D e l e g a t e C o m m a n d s %
1158 % %
1159 % %
1160 % %
1161 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1162 %
1163 % GetDelegateCommands() returns the commands associated with a delegate.
1164 %
1165 % The format of the GetDelegateCommands method is:
1166 %
1167 % const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1168 %
1169 % A description of each parameter follows:
1170 %
1171 % o delegate_info: The delegate info.
1172 %
1173 */
1174 MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
1175 {
1176  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1177 
1178  assert(delegate_info != (DelegateInfo *) NULL);
1179  assert(delegate_info->signature == MagickCoreSignature);
1180  return(delegate_info->commands);
1181 }
1182 
1183 /*
1184 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1185 % %
1186 % %
1187 % %
1188 % G e t D e l e g a t e I n f o %
1189 % %
1190 % %
1191 % %
1192 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1193 %
1194 % GetDelegateInfo() returns any delegates associated with the specified tag.
1195 %
1196 % The format of the GetDelegateInfo method is:
1197 %
1198 % const DelegateInfo *GetDelegateInfo(const char *decode,
1199 % const char *encode,ExceptionInfo *exception)
1200 %
1201 % A description of each parameter follows:
1202 %
1203 % o decode: Specifies the decode delegate we are searching for as a
1204 % character string.
1205 %
1206 % o encode: Specifies the encode delegate we are searching for as a
1207 % character string.
1208 %
1209 % o exception: return any errors or warnings in this structure.
1210 %
1211 */
1212 MagickExport const DelegateInfo *GetDelegateInfo(const char *decode,
1213  const char *encode,ExceptionInfo *exception)
1214 {
1215  register const DelegateInfo
1216  *p;
1217 
1218  assert(exception != (ExceptionInfo *) NULL);
1219  if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1220  return((const DelegateInfo *) NULL);
1221  /*
1222  Search for named delegate.
1223  */
1227  if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0))
1228  {
1230  return(p);
1231  }
1232  while (p != (const DelegateInfo *) NULL)
1233  {
1234  if (p->mode > 0)
1235  {
1236  if (LocaleCompare(p->decode,decode) == 0)
1237  break;
1239  continue;
1240  }
1241  if (p->mode < 0)
1242  {
1243  if (LocaleCompare(p->encode,encode) == 0)
1244  break;
1246  continue;
1247  }
1248  if (LocaleCompare(decode,p->decode) == 0)
1249  if (LocaleCompare(encode,p->encode) == 0)
1250  break;
1251  if (LocaleCompare(decode,"*") == 0)
1252  if (LocaleCompare(encode,p->encode) == 0)
1253  break;
1254  if (LocaleCompare(decode,p->decode) == 0)
1255  if (LocaleCompare(encode,"*") == 0)
1256  break;
1258  }
1259  if (p != (const DelegateInfo *) NULL)
1263  return(p);
1264 }
1265 
1266 /*
1267 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1268 % %
1269 % %
1270 % %
1271 % G e t D e l e g a t e I n f o L i s t %
1272 % %
1273 % %
1274 % %
1275 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1276 %
1277 % GetDelegateInfoList() returns any delegates that match the specified pattern.
1278 %
1279 % The delegate of the GetDelegateInfoList function is:
1280 %
1281 % const DelegateInfo **GetDelegateInfoList(const char *pattern,
1282 % size_t *number_delegates,ExceptionInfo *exception)
1283 %
1284 % A description of each parameter follows:
1285 %
1286 % o pattern: Specifies a pointer to a text string containing a pattern.
1287 %
1288 % o number_delegates: This integer returns the number of delegates in the
1289 % list.
1290 %
1291 % o exception: return any errors or warnings in this structure.
1292 %
1293 */
1294 
1295 #if defined(__cplusplus) || defined(c_plusplus)
1296 extern "C" {
1297 #endif
1298 
1299 static int DelegateInfoCompare(const void *x,const void *y)
1300 {
1301  const DelegateInfo
1302  **p,
1303  **q;
1304 
1305  int
1306  cmp;
1307 
1308  p=(const DelegateInfo **) x,
1309  q=(const DelegateInfo **) y;
1310  cmp=LocaleCompare((*p)->path,(*q)->path);
1311  if (cmp == 0)
1312  {
1313  if ((*p)->decode == (char *) NULL)
1314  if (((*p)->encode != (char *) NULL) &&
1315  ((*q)->encode != (char *) NULL))
1316  return(strcmp((*p)->encode,(*q)->encode));
1317  if (((*p)->decode != (char *) NULL) &&
1318  ((*q)->decode != (char *) NULL))
1319  return(strcmp((*p)->decode,(*q)->decode));
1320  }
1321  return(cmp);
1322 }
1323 
1324 #if defined(__cplusplus) || defined(c_plusplus)
1325 }
1326 #endif
1327 
1328 MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern,
1329  size_t *number_delegates,ExceptionInfo *exception)
1330 {
1331  const DelegateInfo
1332  **delegates;
1333 
1334  register const DelegateInfo
1335  *p;
1336 
1337  register ssize_t
1338  i;
1339 
1340  /*
1341  Allocate delegate list.
1342  */
1343  assert(number_delegates != (size_t *) NULL);
1344  assert(pattern != (char *) NULL);
1345  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1346 
1347  *number_delegates=0;
1348  p=GetDelegateInfo("*","*",exception);
1349  if (p == (const DelegateInfo *) NULL)
1350  return((const DelegateInfo **) NULL);
1351  delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t)
1352  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1353  if (delegates == (const DelegateInfo **) NULL)
1354  return((const DelegateInfo **) NULL);
1355  /*
1356  Generate delegate list.
1357  */
1361  for (i=0; p != (const DelegateInfo *) NULL; )
1362  {
1363  if( (p->stealth == MagickFalse) &&
1364  ( GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse ||
1365  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse) )
1366  delegates[i++]=p;
1368  }
1370  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare);
1371  delegates[i]=(DelegateInfo *) NULL;
1372  *number_delegates=(size_t) i;
1373  return(delegates);
1374 }
1375 
1376 /*
1377 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1378 % %
1379 % %
1380 % %
1381 % G e t D e l e g a t e L i s t %
1382 % %
1383 % %
1384 % %
1385 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1386 %
1387 % GetDelegateList() returns any image format delegates that match the
1388 % specified pattern.
1389 %
1390 % The format of the GetDelegateList function is:
1391 %
1392 % char **GetDelegateList(const char *pattern,
1393 % size_t *number_delegates,ExceptionInfo *exception)
1394 %
1395 % A description of each parameter follows:
1396 %
1397 % o pattern: Specifies a pointer to a text string containing a pattern.
1398 %
1399 % o number_delegates: This integer returns the number of delegates
1400 % in the list.
1401 %
1402 % o exception: return any errors or warnings in this structure.
1403 %
1404 */
1405 
1406 #if defined(__cplusplus) || defined(c_plusplus)
1407 extern "C" {
1408 #endif
1409 
1410 static int DelegateCompare(const void *x,const void *y)
1411 {
1412  register const char
1413  **p,
1414  **q;
1415 
1416  p=(const char **) x;
1417  q=(const char **) y;
1418  return(LocaleCompare(*p,*q));
1419 }
1420 
1421 #if defined(__cplusplus) || defined(c_plusplus)
1422 }
1423 #endif
1424 
1425 MagickExport char **GetDelegateList(const char *pattern,
1426  size_t *number_delegates,ExceptionInfo *exception)
1427 {
1428  char
1429  **delegates;
1430 
1431  register const DelegateInfo
1432  *p;
1433 
1434  register ssize_t
1435  i;
1436 
1437  /*
1438  Allocate delegate list.
1439  */
1440  assert(pattern != (char *) NULL);
1441  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern);
1442 
1443  assert(number_delegates != (size_t *) NULL);
1444  *number_delegates=0;
1445  p=GetDelegateInfo("*","*",exception);
1446  if (p == (const DelegateInfo *) NULL)
1447  return((char **) NULL);
1448  delegates=(char **) AcquireQuantumMemory((size_t)
1449  GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates));
1450  if (delegates == (char **) NULL)
1451  return((char **) NULL);
1455  for (i=0; p != (const DelegateInfo *) NULL; )
1456  {
1457  if( (p->stealth == MagickFalse) &&
1458  GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse )
1459  delegates[i++]=ConstantString(p->decode);
1460  if( (p->stealth == MagickFalse) &&
1461  GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse )
1462  delegates[i++]=ConstantString(p->encode);
1464  }
1466  qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare);
1467  delegates[i]=(char *) NULL;
1468  *number_delegates=(size_t) i;
1469  return(delegates);
1470 }
1471 
1472 /*
1473 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1474 % %
1475 % %
1476 % %
1477 % G e t D e l e g a t e M o d e %
1478 % %
1479 % %
1480 % %
1481 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1482 %
1483 % GetDelegateMode() returns the mode of the delegate.
1484 %
1485 % The format of the GetDelegateMode method is:
1486 %
1487 % ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1488 %
1489 % A description of each parameter follows:
1490 %
1491 % o delegate_info: The delegate info.
1492 %
1493 */
1494 MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
1495 {
1496  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1497 
1498  assert(delegate_info != (DelegateInfo *) NULL);
1499  assert(delegate_info->signature == MagickCoreSignature);
1500  return(delegate_info->mode);
1501 }
1502 
1503 /*
1504 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1505 % %
1506 % %
1507 % %
1508 + G e t D e l e g a t e T h r e a d S u p p o r t %
1509 % %
1510 % %
1511 % %
1512 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1513 %
1514 % GetDelegateThreadSupport() returns MagickTrue if the delegate supports
1515 % threads.
1516 %
1517 % The format of the GetDelegateThreadSupport method is:
1518 %
1519 % MagickBooleanType GetDelegateThreadSupport(
1520 % const DelegateInfo *delegate_info)
1521 %
1522 % A description of each parameter follows:
1523 %
1524 % o delegate_info: The delegate info.
1525 %
1526 */
1528  const DelegateInfo *delegate_info)
1529 {
1530  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1531 
1532  assert(delegate_info != (DelegateInfo *) NULL);
1533  assert(delegate_info->signature == MagickCoreSignature);
1534  return(delegate_info->thread_support);
1535 }
1536 
1537 /*
1538 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1539 % %
1540 % %
1541 % %
1542 + 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 %
1543 % %
1544 % %
1545 % %
1546 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1547 %
1548 % IsDelegateCacheInstantiated() determines if the delegate cache is
1549 % instantiated. If not, it instantiates the cache and returns it.
1550 %
1551 % The format of the IsDelegateInstantiated method is:
1552 %
1553 % MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1554 %
1555 % A description of each parameter follows.
1556 %
1557 % o exception: return any errors or warnings in this structure.
1558 %
1559 */
1561 {
1562  if (delegate_cache == (LinkedListInfo *) NULL)
1563  {
1564  if (delegate_semaphore == (SemaphoreInfo *) NULL)
1567  if (delegate_cache == (LinkedListInfo *) NULL)
1570  }
1571  return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1572 }
1573 
1574 /*
1575 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1576 % %
1577 % %
1578 % %
1579 % I n v o k e D e l e g a t e %
1580 % %
1581 % %
1582 % %
1583 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1584 %
1585 % InvokeDelegate replaces any embedded formatting characters with the
1586 % appropriate image attribute and executes the resulting command. MagickFalse
1587 % is returned if the commands execute with success otherwise MagickTrue.
1588 %
1589 % The format of the InvokeDelegate method is:
1590 %
1591 % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image,
1592 % const char *decode,const char *encode,ExceptionInfo *exception)
1593 %
1594 % A description of each parameter follows:
1595 %
1596 % o image_info: the imageInfo.
1597 %
1598 % o image: the image.
1599 %
1600 % o exception: return any errors or warnings in this structure.
1601 %
1602 */
1603 
1604 static MagickBooleanType CopyDelegateFile(const char *source,
1605  const char *destination,const MagickBooleanType overwrite)
1606 {
1607  int
1608  destination_file,
1609  source_file;
1610 
1612  status;
1613 
1614  register size_t
1615  i;
1616 
1617  size_t
1618  length,
1619  quantum;
1620 
1621  ssize_t
1622  count;
1623 
1624  struct stat
1625  attributes;
1626 
1627  unsigned char
1628  *buffer;
1629 
1630  /*
1631  Copy source file to destination.
1632  */
1633  assert(source != (const char *) NULL);
1634  assert(destination != (char *) NULL);
1635  if (overwrite == MagickFalse)
1636  {
1637  status=GetPathAttributes(destination,&attributes);
1638  if (status != MagickFalse)
1639  return(MagickTrue);
1640  }
1641  destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1642  if (destination_file == -1)
1643  return(MagickFalse);
1644  source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1645  if (source_file == -1)
1646  {
1647  (void) close(destination_file);
1648  return(MagickFalse);
1649  }
1650  quantum=(size_t) MagickMaxBufferExtent;
1651  if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1652  quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
1653  buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
1654  if (buffer == (unsigned char *) NULL)
1655  {
1656  (void) close(source_file);
1657  (void) close(destination_file);
1658  return(MagickFalse);
1659  }
1660  length=0;
1661  for (i=0; ; i+=count)
1662  {
1663  count=(ssize_t) read(source_file,buffer,quantum);
1664  if (count <= 0)
1665  break;
1666  length=(size_t) count;
1667  count=(ssize_t) write(destination_file,buffer,length);
1668  if ((size_t) count != length)
1669  break;
1670  }
1671  (void) close(destination_file);
1672  (void) close(source_file);
1673  buffer=(unsigned char *) RelinquishMagickMemory(buffer);
1674  return(i != 0 ? MagickTrue : MagickFalse);
1675 }
1676 
1678  Image *image,const char *decode,const char *encode,ExceptionInfo *exception)
1679 {
1680  char
1681  *command,
1682  **commands,
1683  input_filename[MagickPathExtent],
1684  output_filename[MagickPathExtent];
1685 
1686  const DelegateInfo
1687  *delegate_info;
1688 
1690  status,
1691  temporary;
1692 
1693  PolicyRights
1694  rights;
1695 
1696  register ssize_t
1697  i;
1698 
1699  /*
1700  Get delegate.
1701  */
1702  assert(image_info != (ImageInfo *) NULL);
1703  assert(image_info->signature == MagickCoreSignature);
1704  assert(image != (Image *) NULL);
1705  assert(image->signature == MagickCoreSignature);
1706  if (image->debug != MagickFalse)
1707  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
1708  rights=ExecutePolicyRights;
1709  if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
1710  {
1711  errno=EPERM;
1713  "NotAuthorized","`%s'",decode);
1714  return(MagickFalse);
1715  }
1716  if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
1717  {
1718  errno=EPERM;
1720  "NotAuthorized","`%s'",encode);
1721  return(MagickFalse);
1722  }
1723  temporary=*image->filename == '\0' ? MagickTrue : MagickFalse;
1724  if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1725  MagickFalse))
1726  {
1727  ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
1728  image->filename);
1729  return(MagickFalse);
1730  }
1731  delegate_info=GetDelegateInfo(decode,encode,exception);
1732  if (delegate_info == (DelegateInfo *) NULL)
1733  {
1734  if (temporary != MagickFalse)
1735  (void) RelinquishUniqueFileResource(image->filename);
1737  "NoTagFound","`%s'",decode ? decode : encode);
1738  return(MagickFalse);
1739  }
1740  if (*image_info->filename == '\0')
1741  {
1742  if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1743  {
1744  if (temporary != MagickFalse)
1745  (void) RelinquishUniqueFileResource(image->filename);
1747  "UnableToCreateTemporaryFile",image_info->filename);
1748  return(MagickFalse);
1749  }
1750  image_info->temporary=MagickTrue;
1751  }
1752  if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) &&
1753  (delegate_info->encode != (char *) NULL)) ||
1754  ((encode != (const char *) NULL) &&
1755  (delegate_info->decode != (char *) NULL))))
1756  {
1757  char
1758  *magick;
1759 
1760  ImageInfo
1761  *clone_info;
1762 
1763  register Image
1764  *p;
1765 
1766  /*
1767  Delegate requires a particular image format.
1768  */
1769  if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1770  {
1772  "UnableToCreateTemporaryFile",image_info->unique);
1773  return(MagickFalse);
1774  }
1775  magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ?
1776  delegate_info->encode : delegate_info->decode,exception);
1777  if (magick == (char *) NULL)
1778  {
1779  (void) RelinquishUniqueFileResource(image_info->unique);
1780  if (temporary != MagickFalse)
1781  (void) RelinquishUniqueFileResource(image->filename);
1782  (void) ThrowMagickException(exception,GetMagickModule(),
1783  DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1784  return(MagickFalse);
1785  }
1786  LocaleUpper(magick);
1787  clone_info=CloneImageInfo(image_info);
1788  (void) CopyMagickString((char *) clone_info->magick,magick,
1790  if (LocaleCompare(magick,"NULL") != 0)
1791  (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1792  magick=DestroyString(magick);
1793  (void) FormatLocaleString(clone_info->filename,MagickPathExtent,"%s:",
1794  delegate_info->decode);
1795  (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image),
1796  exception);
1797  (void) CopyMagickString(clone_info->filename,image_info->filename,
1799  (void) CopyMagickString(image_info->filename,image->filename,
1801  for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1802  {
1803  (void) FormatLocaleString(p->filename,MagickPathExtent,"%s:%s",
1804  delegate_info->decode,clone_info->filename);
1805  status=WriteImage(clone_info,p,exception);
1806  if (status == MagickFalse)
1807  {
1808  (void) RelinquishUniqueFileResource(image_info->unique);
1809  if (temporary != MagickFalse)
1810  (void) RelinquishUniqueFileResource(image->filename);
1811  clone_info=DestroyImageInfo(clone_info);
1812  (void) ThrowMagickException(exception,GetMagickModule(),
1813  DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
1814  return(MagickFalse);
1815  }
1816  if (clone_info->adjoin != MagickFalse)
1817  break;
1818  }
1819  (void) RelinquishUniqueFileResource(image_info->unique);
1820  clone_info=DestroyImageInfo(clone_info);
1821  }
1822  /*
1823  Invoke delegate.
1824  */
1825  commands=StringToList(delegate_info->commands);
1826  if (commands == (char **) NULL)
1827  {
1828  if (temporary != MagickFalse)
1829  (void) RelinquishUniqueFileResource(image->filename);
1830  (void) ThrowMagickException(exception,GetMagickModule(),
1831  ResourceLimitError,"MemoryAllocationFailed","`%s'",
1832  decode ? decode : encode);
1833  return(MagickFalse);
1834  }
1835  command=(char *) NULL;
1836  status=MagickTrue;
1837  (void) CopyMagickString(output_filename,image_info->filename,
1839  (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1840  for (i=0; commands[i] != (char *) NULL; i++)
1841  {
1842  (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1843  if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1844  {
1846  "UnableToCreateTemporaryFile",image_info->unique);
1847  break;
1848  }
1849  if (LocaleCompare(decode,"SCAN") != 0)
1850  {
1851  status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1852  if (status == MagickFalse)
1853  {
1855  "UnableToCreateTemporaryFile",input_filename);
1856  break;
1857  }
1858  }
1859  status=MagickTrue;
1860  command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1861  if (command != (char *) NULL)
1862  {
1863  /*
1864  Execute delegate.
1865  */
1866  if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1867  command,(char *) NULL,exception) != 0)
1868  status=MagickFalse;
1869  if (delegate_info->spawn != MagickFalse)
1870  {
1871  ssize_t
1872  count;
1873 
1874  /*
1875  Wait for input file to 'disappear', or maximum 2 seconds.
1876  */
1877  count=20;
1878  while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1879  (void) MagickDelay(100); /* sleep 0.1 seconds */
1880  }
1881  command=DestroyString(command);
1882  }
1883  if (LocaleCompare(decode,"SCAN") != 0)
1884  {
1885  if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1886  (void) RelinquishUniqueFileResource(input_filename);
1887  }
1888  if ((strcmp(input_filename,output_filename) != 0) &&
1889  (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1890  (void) RelinquishUniqueFileResource(output_filename);
1891  if (image_info->temporary != MagickFalse)
1892  (void) RelinquishUniqueFileResource(image_info->filename);
1893  (void) RelinquishUniqueFileResource(image_info->unique);
1894  (void) RelinquishUniqueFileResource(image_info->filename);
1895  (void) RelinquishUniqueFileResource(image->filename);
1896  if (status == MagickFalse)
1897  {
1899  "DelegateFailed","`%s'",commands[i]);
1900  break;
1901  }
1902  commands[i]=DestroyString(commands[i]);
1903  }
1904  (void) CopyMagickString(image_info->filename,output_filename,
1906  (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
1907  /*
1908  Relinquish resources.
1909  */
1910  for ( ; commands[i] != (char *) NULL; i++)
1911  commands[i]=DestroyString(commands[i]);
1912  commands=(char **) RelinquishMagickMemory(commands);
1913  if (temporary != MagickFalse)
1914  (void) RelinquishUniqueFileResource(image->filename);
1915  return(status);
1916 }
1917 
1918 /*
1919 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1920 % %
1921 % %
1922 % %
1923 % L i s t D e l e g a t e I n f o %
1924 % %
1925 % %
1926 % %
1927 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1928 %
1929 % ListDelegateInfo() lists the image formats to a file.
1930 %
1931 % The format of the ListDelegateInfo method is:
1932 %
1933 % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception)
1934 %
1935 % A description of each parameter follows.
1936 %
1937 % o file: An pointer to a FILE.
1938 %
1939 % o exception: return any errors or warnings in this structure.
1940 %
1941 */
1943  ExceptionInfo *exception)
1944 {
1945  const DelegateInfo
1946  **delegate_info;
1947 
1948  char
1949  **commands,
1950  delegate[MagickPathExtent];
1951 
1952  const char
1953  *path;
1954 
1955  register ssize_t
1956  i;
1957 
1958  size_t
1959  number_delegates;
1960 
1961  ssize_t
1962  j;
1963 
1964  if (file == (const FILE *) NULL)
1965  file=stdout;
1966  delegate_info=GetDelegateInfoList("*",&number_delegates,exception);
1967  if (delegate_info == (const DelegateInfo **) NULL)
1968  return(MagickFalse);
1969  path=(const char *) NULL;
1970  for (i=0; i < (ssize_t) number_delegates; i++)
1971  {
1972  if (delegate_info[i]->stealth != MagickFalse)
1973  continue;
1974  if ((path == (const char *) NULL) ||
1975  (LocaleCompare(path,delegate_info[i]->path) != 0))
1976  {
1977  if (delegate_info[i]->path != (char *) NULL)
1978  (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path);
1979  (void) FormatLocaleFile(file,"Delegate Command\n");
1980  (void) FormatLocaleFile(file,
1981  "-------------------------------------------------"
1982  "------------------------------\n");
1983  }
1984  path=delegate_info[i]->path;
1985  *delegate='\0';
1986  if (delegate_info[i]->encode != (char *) NULL)
1987  (void) CopyMagickString(delegate,delegate_info[i]->encode,
1989  (void) ConcatenateMagickString(delegate," ",MagickPathExtent);
1990  delegate[8]='\0';
1991  commands=StringToList(delegate_info[i]->commands);
1992  if (commands == (char **) NULL)
1993  continue;
1994  (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ?
1995  delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ',
1996  delegate_info[i]->mode >= 0 ? '>' : ' ',delegate);
1997  StripString(commands[0]);
1998  (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]);
1999  for (j=1; commands[j] != (char *) NULL; j++)
2000  {
2001  StripString(commands[j]);
2002  (void) FormatLocaleFile(file," \"%s\"\n",commands[j]);
2003  }
2004  for (j=0; commands[j] != (char *) NULL; j++)
2005  commands[j]=DestroyString(commands[j]);
2006  commands=(char **) RelinquishMagickMemory(commands);
2007  }
2008  (void) fflush(file);
2009  delegate_info=(const DelegateInfo **)
2010  RelinquishMagickMemory((void *) delegate_info);
2011  return(MagickTrue);
2012 }
2013 
2014 /*
2015 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2016 % %
2017 % %
2018 % %
2019 + L o a d D e l e g a t e C a c h e %
2020 % %
2021 % %
2022 % %
2023 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2024 %
2025 % LoadDelegateCache() loads the delegate configurations which provides a
2026 % mapping between delegate attributes and a delegate name.
2027 %
2028 % The format of the LoadDelegateCache method is:
2029 %
2030 % MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
2031 % const char *xml,const char *filename,const size_t depth,
2032 % ExceptionInfo *exception)
2033 %
2034 % A description of each parameter follows:
2035 %
2036 % o xml: The delegate list in XML format.
2037 %
2038 % o filename: The delegate list filename.
2039 %
2040 % o depth: depth of <include /> statements.
2041 %
2042 % o exception: return any errors or warnings in this structure.
2043 %
2044 */
2046  const char *xml,const char *filename,const size_t depth,
2047  ExceptionInfo *exception)
2048 {
2049  char
2050  keyword[MagickPathExtent],
2051  *token;
2052 
2053  const char
2054  *q;
2055 
2056  DelegateInfo
2057  *delegate_info;
2058 
2060  status;
2061 
2062  size_t
2063  extent;
2064 
2065  /*
2066  Load the delegate map file.
2067  */
2069  "Loading delegate configuration file \"%s\" ...",filename);
2070  if (xml == (const char *) NULL)
2071  return(MagickFalse);
2072  status=MagickTrue;
2073  delegate_info=(DelegateInfo *) NULL;
2074  token=AcquireString(xml);
2075  extent=strlen(token)+MagickPathExtent;
2076  for (q=(const char *) xml; *q != '\0'; )
2077  {
2078  /*
2079  Interpret XML.
2080  */
2081  (void) GetNextToken(q,&q,extent,token);
2082  if (*token == '\0')
2083  break;
2084  (void) CopyMagickString(keyword,token,MagickPathExtent);
2085  if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0)
2086  {
2087  /*
2088  Doctype element.
2089  */
2090  while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0'))
2091  (void) GetNextToken(q,&q,extent,token);
2092  continue;
2093  }
2094  if (LocaleNCompare(keyword,"<!--",4) == 0)
2095  {
2096  /*
2097  Comment element.
2098  */
2099  while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0'))
2100  (void) GetNextToken(q,&q,extent,token);
2101  continue;
2102  }
2103  if (LocaleCompare(keyword,"<include") == 0)
2104  {
2105  /*
2106  Include element.
2107  */
2108  while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0'))
2109  {
2110  (void) CopyMagickString(keyword,token,MagickPathExtent);
2111  (void) GetNextToken(q,&q,extent,token);
2112  if (*token != '=')
2113  continue;
2114  (void) GetNextToken(q,&q,extent,token);
2115  if (LocaleCompare(keyword,"file") == 0)
2116  {
2117  if (depth > MagickMaxRecursionDepth)
2118  (void) ThrowMagickException(exception,GetMagickModule(),
2119  ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token);
2120  else
2121  {
2122  char
2123  path[MagickPathExtent],
2124  *file_xml;
2125 
2126  GetPathComponent(filename,HeadPath,path);
2127  if (*path != '\0')
2130  if (*token == *DirectorySeparator)
2131  (void) CopyMagickString(path,token,MagickPathExtent);
2132  else
2133  (void) ConcatenateMagickString(path,token,MagickPathExtent);
2134  file_xml=FileToXML(path,~0UL);
2135  if (file_xml != (char *) NULL)
2136  {
2137  status&=LoadDelegateCache(cache,file_xml,path,
2138  depth+1,exception);
2139  file_xml=DestroyString(file_xml);
2140  }
2141  }
2142  }
2143  }
2144  continue;
2145  }
2146  if (LocaleCompare(keyword,"<delegate") == 0)
2147  {
2148  /*
2149  Delegate element.
2150  */
2151  delegate_info=(DelegateInfo *) AcquireCriticalMemory(
2152  sizeof(*delegate_info));
2153  (void) memset(delegate_info,0,sizeof(*delegate_info));
2154  delegate_info->path=ConstantString(filename);
2155  delegate_info->thread_support=MagickTrue;
2156  delegate_info->signature=MagickCoreSignature;
2157  continue;
2158  }
2159  if (delegate_info == (DelegateInfo *) NULL)
2160  continue;
2161  if ((LocaleCompare(keyword,"/>") == 0) ||
2162  (LocaleCompare(keyword,"</policy>") == 0))
2163  {
2164  status=AppendValueToLinkedList(cache,delegate_info);
2165  if (status == MagickFalse)
2166  (void) ThrowMagickException(exception,GetMagickModule(),
2167  ResourceLimitError,"MemoryAllocationFailed","`%s'",
2168  delegate_info->commands);
2169  delegate_info=(DelegateInfo *) NULL;
2170  continue;
2171  }
2172  (void) GetNextToken(q,(const char **) NULL,extent,token);
2173  if (*token != '=')
2174  continue;
2175  (void) GetNextToken(q,&q,extent,token);
2176  (void) GetNextToken(q,&q,extent,token);
2177  switch (*keyword)
2178  {
2179  case 'C':
2180  case 'c':
2181  {
2182  if (LocaleCompare((char *) keyword,"command") == 0)
2183  {
2184  char
2185  *commands;
2186 
2187  commands=AcquireString(token);
2188 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2189  if (strchr(commands,'@') != (char *) NULL)
2190  {
2191  char
2192  path[MagickPathExtent];
2193 
2194  NTGhostscriptEXE(path,MagickPathExtent);
2195  (void) SubstituteString((char **) &commands,"@PSDelegate@",
2196  path);
2197  (void) SubstituteString((char **) &commands,"\\","/");
2198  }
2199  (void) SubstituteString((char **) &commands,"&quot;","\"");
2200 #else
2201  (void) SubstituteString((char **) &commands,"&quot;","'");
2202 #endif
2203  (void) SubstituteString((char **) &commands,"&amp;","&");
2204  (void) SubstituteString((char **) &commands,"&gt;",">");
2205  (void) SubstituteString((char **) &commands,"&lt;","<");
2206  delegate_info->commands=commands;
2207  break;
2208  }
2209  break;
2210  }
2211  case 'D':
2212  case 'd':
2213  {
2214  if (LocaleCompare((char *) keyword,"decode") == 0)
2215  {
2216  delegate_info->decode=ConstantString(token);
2217  delegate_info->mode=1;
2218  break;
2219  }
2220  break;
2221  }
2222  case 'E':
2223  case 'e':
2224  {
2225  if (LocaleCompare((char *) keyword,"encode") == 0)
2226  {
2227  delegate_info->encode=ConstantString(token);
2228  delegate_info->mode=(-1);
2229  break;
2230  }
2231  break;
2232  }
2233  case 'M':
2234  case 'm':
2235  {
2236  if (LocaleCompare((char *) keyword,"mode") == 0)
2237  {
2238  delegate_info->mode=1;
2239  if (LocaleCompare(token,"bi") == 0)
2240  delegate_info->mode=0;
2241  else
2242  if (LocaleCompare(token,"encode") == 0)
2243  delegate_info->mode=(-1);
2244  break;
2245  }
2246  break;
2247  }
2248  case 'S':
2249  case 's':
2250  {
2251  if (LocaleCompare((char *) keyword,"spawn") == 0)
2252  {
2253  delegate_info->spawn=IsStringTrue(token);
2254  break;
2255  }
2256  if (LocaleCompare((char *) keyword,"stealth") == 0)
2257  {
2258  delegate_info->stealth=IsStringTrue(token);
2259  break;
2260  }
2261  break;
2262  }
2263  case 'T':
2264  case 't':
2265  {
2266  if (LocaleCompare((char *) keyword,"thread-support") == 0)
2267  {
2268  delegate_info->thread_support=IsStringTrue(token);
2269  if (delegate_info->thread_support == MagickFalse)
2270  delegate_info->semaphore=AcquireSemaphoreInfo();
2271  break;
2272  }
2273  break;
2274  }
2275  default:
2276  break;
2277  }
2278  }
2279  token=(char *) RelinquishMagickMemory(token);
2280  return(status != 0 ? MagickTrue : MagickFalse);
2281 }
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:1083
size_t signature
Definition: image.h:488
static int DelegateCompare(const void *x, const void *y)
Definition: delegate.c:1410
#define MagickMaxRecursionDepth
Definition: studio.h:352
MagickExport MagickBooleanType GetPathAttributes(const char *path, void *attributes)
Definition: utility.c:1175
DisposeType dispose
Definition: image.h:237
char magick[MagickPathExtent]
Definition: image.h:480
MagickExport MagickBooleanType GetDelegateThreadSupport(const DelegateInfo *delegate_info)
Definition: delegate.c:1527
MagickExport MagickBooleanType IsRightsAuthorized(const PolicyDomain domain, const PolicyRights rights, const char *pattern)
Definition: policy.c:595
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:428
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:1328
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:1560
#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:1425
MagickExport const DelegateInfo * GetDelegateInfo(const char *decode, const char *encode, ExceptionInfo *exception)
Definition: delegate.c:1212
#define MagickMaxBufferExtent
Definition: blob.h:25
MagickExport char * SanitizeString(const char *source)
Definition: string.c:1614
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:1494
MagickExport size_t CopyMagickString(char *magick_restrict destination, const char *magick_restrict source, const size_t length)
Definition: string.c:756
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
MagickBooleanType verbose
Definition: image.h:445
MagickExport const char * GetDelegateCommands(const DelegateInfo *delegate_info)
Definition: delegate.c:1174
MagickExport const char * GetImageOption(const ImageInfo *image_info, const char *option)
Definition: option.c:2320
char * commands
Definition: delegate.h:31
#define MagickEpsilon
Definition: magick-type.h:114
CompressionType compression
Definition: image.h:160
#define O_BINARY
Definition: studio.h:333
ClassType storage_class
Definition: image.h:154
MagickExport void StripString(char *message)
Definition: string.c:2503
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:1392
static char * InterpretDelegateProperties(ImageInfo *image_info, Image *image, const char *embed_text, ExceptionInfo *exception)
Definition: delegate.c:903
static char * GetMagickPropertyLetter(ImageInfo *image_info, Image *image, const char letter, ExceptionInfo *exception)
Definition: delegate.c:556
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:1205
MagickExport LinkedListInfo * GetConfigureOptions(const char *filename, ExceptionInfo *exception)
Definition: configure.c:642
static MagickBooleanType LoadDelegateCache(LinkedListInfo *, const char *, const char *, const size_t, ExceptionInfo *)
Definition: delegate.c:2045
MagickExport void GetPathComponent(const char *path, PathType type, char *component)
Definition: utility.c:1223
static MagickBooleanType CopyDelegateFile(const char *source, const char *destination, const MagickBooleanType overwrite)
Definition: delegate.c:1604
MagickExport ssize_t FormatLocaleFile(FILE *file, const char *magick_restrict format,...)
Definition: locale.c:404
MagickBooleanType
Definition: magick-type.h:169
MagickExport char ** StringToList(const char *text)
Definition: string.c:2289
#define DirectorySeparator
Definition: studio.h:267
size_t scene
Definition: image.h:240
unsigned int MagickStatusType
Definition: magick-type.h:125
MagickExport char * AcquireString(const char *source)
Definition: string.c:129
MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info, Image *image, ExceptionInfo *exception)
Definition: constitute.c:1053
MagickExport MagickBooleanType GlobExpression(const char *magick_restrict expression, const char *magick_restrict pattern, const MagickBooleanType case_insensitive)
Definition: token.c:355
MagickExport const char * CommandOptionToMnemonic(const CommandOption option, const ssize_t type)
Definition: option.c:2698
MagickExport void * AcquireCriticalMemory(const size_t size)
Definition: memory.c:595
MagickPrivate void DelegateComponentTerminus(void)
Definition: delegate.c:294
MagickExport void * AcquireQuantumMemory(const size_t count, const size_t quantum)
Definition: memory.c:634
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:1103
MagickExport int LocaleNCompare(const char *p, const char *q, const size_t length)
Definition: locale.c:1570
double y
Definition: geometry.h:123
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:1715
MagickExport MagickBooleanType IsStringTrue(const char *value)
Definition: string.c:1415
#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:2693
char magick_filename[MagickPathExtent]
Definition: image.h:319
MagickExport MagickBooleanType ThrowMagickException(ExceptionInfo *exception, const char *module, const char *function, const size_t line, const ExceptionType severity, const char *tag, const char *format,...)
Definition: exception.c:1145
MagickExport MagickBooleanType LogMagickEvent(const LogEventType type, const char *module, const char *function, const size_t line, const char *format,...)
Definition: log.c:1660
static int open_utf8(const char *path, int flags, mode_t mode)
size_t signature
Definition: image.h:354
size_t columns
Definition: image.h:172
MagickExport MagickBooleanType AcquireUniqueSymbolicLink(const char *source, char *destination)
Definition: utility.c:153
MagickExport MagickBooleanType SubstituteString(char **string, const char *search, const char *replace)
Definition: string.c:2565
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
MagickPrivate MagickBooleanType DelegateComponentGenesis(void)
Definition: delegate.c:248
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:341
#define S_MODE
Definition: studio.h:247
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:1292
MagickExport char * InterpretImageProperties(ImageInfo *image_info, Image *image, const char *embed_text, ExceptionInfo *exception)
Definition: property.c:3482
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:1231
static LinkedListInfo * delegate_cache
Definition: delegate.c:156
MagickExport MagickBooleanType ListDelegateInfo(FILE *file, ExceptionInfo *exception)
Definition: delegate.c:1942
char * path
Definition: delegate.h:31
#define DelegateFilename
Definition: delegate.c:83
MagickExport RectangleInfo GetImageBoundingBox(const Image *image, ExceptionInfo *exception)
Definition: attribute.c:389
static const char * DelegateMap
Definition: delegate.c:89
MagickExport ssize_t GetImageIndexInList(const Image *images)
Definition: list.c:670
MagickExport Image * GetNextImageInList(const Image *images)
Definition: list.c:784
MagickExport char * DestroyString(char *string)
Definition: string.c:813
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:2217
MagickExport size_t GetNumberOfElementsInLinkedList(const LinkedListInfo *list_info)
Definition: linked-list.c:348
MagickExport ImageInfo * CloneImageInfo(const ImageInfo *image_info)
Definition: image.c:919
#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:195
MagickExport void * RelinquishMagickMemory(void *memory)
Definition: memory.c:1122
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:1677
#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:2012
MagickBooleanType adjoin
Definition: image.h:384
MagickExport size_t GetImageListLength(const Image *images)
Definition: list.c:709
MagickExport void RelinquishSemaphoreInfo(SemaphoreInfo **semaphore_info)
Definition: semaphore.c:351
MagickExport LinkedListInfo * DestroyConfigureOptions(LinkedListInfo *options)
Definition: configure.c:314
MagickExport void LocaleUpper(char *string)
Definition: locale.c:1630
static char * SanitizeDelegateString(const char *source)
Definition: delegate.c:526
MagickExport char * ConstantString(const char *source)
Definition: string.c:702
static int DelegateInfoCompare(const void *x, const void *y)
Definition: delegate.c:1299
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