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