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