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