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