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/policy-private.h"
70#include "MagickCore/property.h"
71#include "MagickCore/resource_.h"
72#include "MagickCore/semaphore.h"
73#include "MagickCore/signature.h"
74#include "MagickCore/string_.h"
75#include "MagickCore/token.h"
76#include "MagickCore/token-private.h"
77#include "MagickCore/utility.h"
78#include "MagickCore/utility-private.h"
79#include "MagickCore/xml-tree.h"
80#include "MagickCore/xml-tree-private.h"
86 #include "TargetConditionals.h"
87 #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
88 #define system(s) ((s)==NULL ? 0 : -1)
90#elif defined(__ANDROID__)
91 #define system(s) ((s)==NULL ? 0 : -1)
93#define DelegateFilename "delegates.xml"
94#if defined(MAGICKCORE_WINDOWS_SUPPORT)
95 #define DELEGATE_ESC """
97 #define DELEGATE_ESC "'"
104 *DelegateMap = (
const char *)
105 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
107 " <delegate decode=\"bpg\" command=\"" DELEGATE_ESC
"bpgdec" DELEGATE_ESC
" -b 16 -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
108 " <delegate decode=\"png\" encode=\"bpg\" command=\"" DELEGATE_ESC
"bpgenc" DELEGATE_ESC
" -b 12 -q %~ -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
109 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\"" DELEGATE_ESC
"xdg-open" DELEGATE_ESC
" https://imagemagick.org/; rm " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
110 " <delegate decode=\"cdr\" command=\"" DELEGATE_ESC
"uniconvertor" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
111 " <delegate decode=\"cgm\" command=\"" DELEGATE_ESC
"uniconvertor" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
112 " <delegate decode=\"http:decode\" command=\"" DELEGATE_ESC
"curl" DELEGATE_ESC
" -s -L -o " DELEGATE_ESC
"%u.dat" DELEGATE_ESC
" " DELEGATE_ESC
"http:%M" DELEGATE_ESC
"\"/>"
113 " <delegate decode=\"https:decode\" command=\"" DELEGATE_ESC
"curl" DELEGATE_ESC
" -s -L -o " DELEGATE_ESC
"%u.dat" DELEGATE_ESC
" " DELEGATE_ESC
"https:%M" DELEGATE_ESC
"\"/>"
114 " <delegate decode=\"doc\" command=\"" DELEGATE_ESC
"soffice" DELEGATE_ESC
" --convert-to pdf -outdir `dirname " DELEGATE_ESC
"%i" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
" 2> " DELEGATE_ESC
"%u" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.pdf" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
115 " <delegate decode=\"docx\" command=\"" DELEGATE_ESC
"soffice" DELEGATE_ESC
" --convert-to pdf -outdir `dirname " DELEGATE_ESC
"%i" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
" 2> " DELEGATE_ESC
"%u" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.pdf" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
116 " <delegate decode=\"dng:decode\" command=\"" DELEGATE_ESC
"ufraw-batch" DELEGATE_ESC
" --silent --create-id=also --out-type=png --out-depth=16 " DELEGATE_ESC
"--output=%u.png" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
117 " <delegate decode=\"dot\" command=\"" DELEGATE_ESC
"dot" DELEGATE_ESC
" -Tsvg " DELEGATE_ESC
"%i" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
118 " <delegate decode=\"dvi\" command=\"" DELEGATE_ESC
"dvips" DELEGATE_ESC
" -sstdout=%%stderr -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
119 " <delegate decode=\"dxf\" command=\"" DELEGATE_ESC
"uniconvertor" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
120 " <delegate decode=\"edit\" stealth=\"True\" command=\"" DELEGATE_ESC
"xterm" DELEGATE_ESC
" -title " DELEGATE_ESC
"Edit Image Comment" DELEGATE_ESC
" -e vi " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
121 " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 " DELEGATE_ESC
"-sDEVICE=pdfwrite" DELEGATE_ESC
" " DELEGATE_ESC
"-sOutputFile=%o" DELEGATE_ESC
" " DELEGATE_ESC
"-f%i" DELEGATE_ESC
"\"/>"
122 " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=ps2write" DELEGATE_ESC
" " DELEGATE_ESC
"-sOutputFile=%o" DELEGATE_ESC
" " DELEGATE_ESC
"-f%i" DELEGATE_ESC
"\"/>"
123 " <delegate decode=\"fig\" command=\"" DELEGATE_ESC
"uniconvertor" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.svg" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
124 " <delegate decode=\"hpg\" command=\"" DELEGATE_ESC
"hp2xx" DELEGATE_ESC
" -sstdout=%%stderr -m eps -f `basename " DELEGATE_ESC
"%o" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv -f `basename " DELEGATE_ESC
"%o" DELEGATE_ESC
"` " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
125 " <delegate decode=\"hpgl\" command=\"" DELEGATE_ESC
"hp2xx" DELEGATE_ESC
" -sstdout=%%stderr -m eps -f `basename " DELEGATE_ESC
"%o" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv -f `basename " DELEGATE_ESC
"%o" DELEGATE_ESC
"` " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
126 " <delegate decode=\"htm\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
127 " <delegate decode=\"html\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
128 " <delegate decode=\"ilbm\" command=\"" DELEGATE_ESC
"ilbmtoppm" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
129 " <delegate decode=\"jpg\" encode=\"lep\" mode=\"encode\" command=\"" DELEGATE_ESC
"lepton" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
130 " <delegate decode=\"jxr\" command=\"mv " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%i.jxr" DELEGATE_ESC
"; " DELEGATE_ESC
"JxrDecApp" DELEGATE_ESC
" -i " DELEGATE_ESC
"%i.jxr" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o.tiff" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.jxr" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.tiff" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
131 " <delegate decode=\"lep\" mode=\"decode\" command=\"" DELEGATE_ESC
"lepton" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
132 " <delegate decode=\"odt\" command=\"" DELEGATE_ESC
"soffice" DELEGATE_ESC
" --convert-to pdf -outdir `dirname " DELEGATE_ESC
"%i" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
" 2> " DELEGATE_ESC
"%u" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.pdf" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
133 " <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\"" DELEGATE_ESC
"pcl6" DELEGATE_ESC
" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pamcmyk32" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
134 " <delegate decode=\"pcl:color\" stealth=\"True\" command=\"" DELEGATE_ESC
"pcl6" DELEGATE_ESC
" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=ppmraw" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
135 " <delegate decode=\"pcl:mono\" stealth=\"True\" command=\"" DELEGATE_ESC
"pcl6" DELEGATE_ESC
" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pbmraw" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
136 " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sPDFPassword=" DELEGATE_ESC
"%a" DELEGATE_ESC
" " DELEGATE_ESC
"-sDEVICE=eps2write" DELEGATE_ESC
" " DELEGATE_ESC
"-sOutputFile=%o" DELEGATE_ESC
" " DELEGATE_ESC
"-f%i" DELEGATE_ESC
"\"/>"
137 " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=ps2write" DELEGATE_ESC
" -sPDFPassword=" DELEGATE_ESC
"%a" DELEGATE_ESC
" " DELEGATE_ESC
"-sOutputFile=%o" DELEGATE_ESC
" " DELEGATE_ESC
"-f%i" DELEGATE_ESC
"\"/>"
138 " <delegate decode=\"png\" encode=\"clipboard\" command=\"" DELEGATE_ESC
"xclip" DELEGATE_ESC
" -selection clipboard -t image/png " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
139 " <delegate decode=\"clipboard\" command=\"" DELEGATE_ESC
"xclip" DELEGATE_ESC
" -selection clipboard -o > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
140 " <delegate decode=\"png\" encode=\"webp\" command=\"" DELEGATE_ESC
"cwebp" DELEGATE_ESC
" -quiet -q %Q " DELEGATE_ESC
"%i" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
141 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\"" DELEGATE_ESC
"ppmtoilbm" DELEGATE_ESC
" -24if " DELEGATE_ESC
"%i" DELEGATE_ESC
" > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
142 " <delegate decode=\"tiff\" encode=\"jxr\" command=\"mv " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%i.tiff" DELEGATE_ESC
"; " DELEGATE_ESC
"JxrEncApp" DELEGATE_ESC
" -i " DELEGATE_ESC
"%i.tiff" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o.jxr" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.tiff" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.jxr" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
143 " <delegate decode=\"tiff\" encode=\"wdp\" command=\"mv " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%i.tiff" DELEGATE_ESC
"; " DELEGATE_ESC
"JxrEncApp" DELEGATE_ESC
" -i " DELEGATE_ESC
"%i.tiff" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o.jxr" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.tiff" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.jxr" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
144 " <delegate decode=\"ppt\" command=\"" DELEGATE_ESC
"soffice" DELEGATE_ESC
" --convert-to pdf -outdir `dirname " DELEGATE_ESC
"%i" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
" 2> " DELEGATE_ESC
"%u" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.pdf" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
145 " <delegate decode=\"pptx\" command=\"" DELEGATE_ESC
"soffice" DELEGATE_ESC
" --convert-to pdf -outdir `dirname " DELEGATE_ESC
"%i" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
" 2> " DELEGATE_ESC
"%u" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.pdf" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
146 " <delegate decode=\"ps\" encode=\"prt\" command=\"" DELEGATE_ESC
"lpr" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
147 " <delegate decode=\"ps:alpha\" stealth=\"True\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pngalpha" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
"\"/>"
148 " <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pamcmyk32" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
"\"/>"
149 " <delegate decode=\"ps:color\" stealth=\"True\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pnmraw" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
"\"/>"
150 " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=eps2write" DELEGATE_ESC
" " DELEGATE_ESC
"-sOutputFile=%o" DELEGATE_ESC
" " DELEGATE_ESC
"-f%i" DELEGATE_ESC
"\"/>"
151 " <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pdfwrite" DELEGATE_ESC
" " DELEGATE_ESC
"-sOutputFile=%o" DELEGATE_ESC
" " DELEGATE_ESC
"-f%i" DELEGATE_ESC
"\"/>"
152 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
153 " <delegate decode=\"ps:mono\" stealth=\"True\" command=\"" DELEGATE_ESC
"gs" DELEGATE_ESC
" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pbmraw" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
" " DELEGATE_ESC
"-f%s" DELEGATE_ESC
"\"/>"
154 " <delegate decode=\"shtml\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
155 " <delegate decode=\"sid\" command=\"" DELEGATE_ESC
"mrsidgeodecode" DELEGATE_ESC
" -if sid -i " DELEGATE_ESC
"%i" DELEGATE_ESC
" -of tif -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" > " DELEGATE_ESC
"%u" DELEGATE_ESC
"\"/>"
156 " <delegate decode=\"svg\" command=\"" DELEGATE_ESC
"rsvg-convert" DELEGATE_ESC
" --dpi-x %x --dpi-y %y -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
157#ifndef MAGICKCORE_RSVG_DELEGATE
158 " <delegate decode=\"svg:decode\" stealth=\"True\" command=\"" DELEGATE_ESC
"inkscape" DELEGATE_ESC
" " DELEGATE_ESC
"%s" DELEGATE_ESC
" --export-png=" DELEGATE_ESC
"%s" DELEGATE_ESC
" --export-dpi=" DELEGATE_ESC
"%s" DELEGATE_ESC
" --export-background=" DELEGATE_ESC
"%s" DELEGATE_ESC
" --export-background-opacity=" DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
160 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\"" DELEGATE_ESC
"gimp" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
161 " <delegate decode=\"wdp\" command=\"mv " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%i.jxr" DELEGATE_ESC
"; " DELEGATE_ESC
"JxrDecApp" DELEGATE_ESC
" -i " DELEGATE_ESC
"%i.jxr" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o.tiff" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.jxr" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.tiff" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
162 " <delegate decode=\"webp\" command=\"" DELEGATE_ESC
"dwebp" DELEGATE_ESC
" -pam " DELEGATE_ESC
"%i" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
163 " <delegate decode=\"xls\" command=\"" DELEGATE_ESC
"soffice" DELEGATE_ESC
" --convert-to pdf -outdir `dirname " DELEGATE_ESC
"%i" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
" 2> " DELEGATE_ESC
"%u" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.pdf" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
164 " <delegate decode=\"xlsx\" command=\"" DELEGATE_ESC
"soffice" DELEGATE_ESC
" --convert-to pdf -outdir `dirname " DELEGATE_ESC
"%i" DELEGATE_ESC
"` " DELEGATE_ESC
"%i" DELEGATE_ESC
" 2> " DELEGATE_ESC
"%u" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%i.pdf" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
165 " <delegate decode=\"xps:cmyk\" stealth=\"True\" command=\"" DELEGATE_ESC
"gxps" DELEGATE_ESC
" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=bmpsep8" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
166 " <delegate decode=\"xps:color\" stealth=\"True\" command=\"" DELEGATE_ESC
"gxps" DELEGATE_ESC
" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=ppmraw" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
167 " <delegate decode=\"xps:mono\" stealth=\"True\" command=\"" DELEGATE_ESC
"gxps" DELEGATE_ESC
" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 " DELEGATE_ESC
"-sDEVICE=pbmraw" DELEGATE_ESC
" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u " DELEGATE_ESC
"-r%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"-sOutputFile=%s" DELEGATE_ESC
" " DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
168 " <delegate decode=\"video:decode\" command=\"" DELEGATE_ESC
"ffmpeg" DELEGATE_ESC
" -nostdin -loglevel error -i " DELEGATE_ESC
"%s" DELEGATE_ESC
" -an -f rawvideo -y %s " DELEGATE_ESC
"%s" DELEGATE_ESC
"\"/>"
169 " <delegate encode=\"video:encode\" stealth=\"True\" command=\"" DELEGATE_ESC
"ffmpeg" DELEGATE_ESC
" -nostdin -loglevel error -i " DELEGATE_ESC
"%s%%d.%s" DELEGATE_ESC
" %s " DELEGATE_ESC
"%s.%s" DELEGATE_ESC
"\"/>"
177 *delegate_cache = (LinkedListInfo *) NULL;
185static MagickBooleanType
186 IsDelegateCacheInstantiated(ExceptionInfo *),
187 LoadDelegateCache(LinkedListInfo *,
const char *,
const char *,
const size_t,
216static LinkedListInfo *AcquireDelegateCache(
const char *filename,
217 ExceptionInfo *exception)
222 cache=NewLinkedList(0);
223#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
231 options=GetConfigureOptions(filename,exception);
232 option=(
const StringInfo *) GetNextValueInLinkedList(options);
233 while (option != (
const StringInfo *) NULL)
235 (void) LoadDelegateCache(cache,(
const char *)
236 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
237 option=(
const StringInfo *) GetNextValueInLinkedList(options);
239 options=DestroyConfigureOptions(options);
242 magick_unreferenced(filename);
244 if (IsLinkedListEmpty(cache) != MagickFalse)
245 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
267MagickPrivate MagickBooleanType DelegateComponentGenesis(
void)
270 delegate_semaphore=AcquireSemaphoreInfo();
293static void *DestroyDelegate(
void *delegate_info)
298 p=(DelegateInfo *) delegate_info;
299 if (p->path != (
char *) NULL)
300 p->path=DestroyString(p->path);
301 if (p->decode != (
char *) NULL)
302 p->decode=DestroyString(p->decode);
303 if (p->encode != (
char *) NULL)
304 p->encode=DestroyString(p->encode);
305 if (p->commands != (
char *) NULL)
306 p->commands=DestroyString(p->commands);
308 RelinquishSemaphoreInfo(&p->semaphore);
309 p=(DelegateInfo *) RelinquishMagickMemory(p);
310 return((
void *) NULL);
313MagickPrivate
void DelegateComponentTerminus(
void)
316 ActivateSemaphoreInfo(&delegate_semaphore);
317 LockSemaphoreInfo(delegate_semaphore);
318 if (delegate_cache != (LinkedListInfo *) NULL)
319 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
320 UnlockSemaphoreInfo(delegate_semaphore);
321 RelinquishSemaphoreInfo(&delegate_semaphore);
361static inline MagickBooleanType IsExecutableToken(
const char *token)
366 if ((token == (
const char *) NULL) || (*token ==
'\0'))
372 if ((*token ==
'\'') || (*token ==
'"'))
374 length=strlen(token);
377 if ((isalpha((
int) *token) != 0) && (token[1] ==
':') &&
378 ((token[2] ==
'\\') || (token[2] ==
'/')))
385 if ((*token ==
'.') && ((token[1] ==
'\\') || (token[1] ==
'/')))
388 if (isalnum((
int) *token))
393MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
394 const MagickBooleanType verbose,
const char *command,
char *message,
395 ExceptionInfo *exception)
415 arguments=StringToArgv(command,&number_arguments);
416 if (arguments == (
char **) NULL)
418 if (*arguments[1] ==
'\0')
420 for (i=0; i < (ssize_t) number_arguments; i++)
421 arguments[i]=DestroyString(arguments[i]);
422 arguments=(
char **) RelinquishMagickMemory(arguments);
425 rights=ExecutePolicyRights;
426 domain=DelegatePolicyDomain;
427 for (i=1; i < (ssize_t) number_arguments; i++)
429 if ((i != 1) && (IsExecutableToken(arguments[i]) == MagickFalse))
431 if (IsRightsAuthorized(domain,rights,arguments[i]) == MagickFalse)
437 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
438 "NotAuthorized",
"`%s'",arguments[i]);
439 for (j=0; j < (ssize_t) number_arguments; j++)
440 arguments[j]=DestroyString(arguments[j]);
441 arguments=(
char **) RelinquishMagickMemory(arguments);
445 if (verbose != MagickFalse)
447 (void) FormatLocaleFile(stderr,
"%s\n",command);
448 (void) fflush(stderr);
450 sanitize_command=SanitizeString(command);
451 if (asynchronous != MagickFalse)
452 (void) ConcatenateMagickString(sanitize_command,
"&",MagickPathExtent);
453 if (message != (
char *) NULL)
455#if defined(MAGICKCORE_POSIX_SUPPORT)
456#if defined(MAGICKCORE_HAVE_POPEN)
457 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
462 file=popen_utf8(sanitize_command,
"r");
463 if (file == (FILE *) NULL)
464 status=system(sanitize_command);
470 while ((offset < MagickPathExtent) &&
471 (fgets(message+offset,(
int) (MagickPathExtent-offset),file) != NULL))
472 offset+=strlen(message);
479#if !defined(MAGICKCORE_HAVE_EXECVP)
480 status=system(sanitize_command);
482 if ((asynchronous != MagickFalse) ||
483 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
484 status=system(sanitize_command);
493 child_pid=(pid_t) fork();
494 if (child_pid == (pid_t) -1)
495 status=system(sanitize_command);
499 status=execvp(arguments[1],arguments+1);
511 pid=(pid_t) waitpid(child_pid,&child_status,0);
516 if (WIFEXITED(child_status) != 0)
517 status=WEXITSTATUS(child_status);
519 if (WIFSIGNALED(child_status))
526#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
539 p=strstr(sanitize_command,
"cmd.exe /c");
540 if (p != (
char*) NULL)
543 for ( ; *p !=
'\0'; p++)
545 *p=(*DirectorySeparator);
548 status=NTSystemCommand(sanitize_command,message);
550 status=system(sanitize_command);
552# error No suitable system() method.
556 if ((message != (
char *) NULL) && (*message !=
'\0'))
557 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
558 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
560 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
561 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
563 sanitize_command=DestroyString(sanitize_command);
564 for (i=0; i < (ssize_t) number_arguments; i++)
565 arguments[i]=DestroyString(arguments[i]);
566 arguments=(
char **) RelinquishMagickMemory(arguments);
608static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
609 const char letter,ExceptionInfo *exception)
611#define WarnNoImageReturn(format,letter) \
612 if (image == (Image *) NULL) \
614 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
615 "NoImageForProperty",format,letter); \
618#define WarnNoImageInfoReturn(format,letter) \
619 if (image_info == (ImageInfo *) NULL) \
621 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
622 "NoImageInfoForProperty",format,letter); \
627 value[MagickPathExtent];
632 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
633 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
635 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
636 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-images");
641 string=(
const char *) value;
646 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
647 string=GetImageOption(image_info,
"authenticate");
652 WarnNoImageReturn(
"\"%%%c\"",letter);
653 (void) FormatMagickSize(image->extent,MagickFalse,
"B",MagickPathExtent,
655 if (image->extent == 0)
656 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,
"B",
657 MagickPathExtent,value);
662 WarnNoImageReturn(
"\"%%%c\"",letter);
663 GetPathComponent(image->magick_filename,HeadPath,value);
668 WarnNoImageReturn(
"\"%%%c\"",letter);
669 GetPathComponent(image->magick_filename,ExtensionPath,value);
674 WarnNoImageReturn(
"\"%%%c\"",letter);
675 GetPathComponent(image->magick_filename,TailPath,value);
680 WarnNoImageReturn(
"\"%%%c\"",letter);
681 (void) FormatLocaleString(value,MagickPathExtent,
682 "%.17gx%.17g%+.20g%+.20g",(
double) image->page.width,(
double)
683 image->page.height,(
double) image->page.x,(
double) image->page.y);
688 WarnNoImageReturn(
"\"%%%c\"",letter);
689 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
690 (image->rows != 0 ? image->rows : image->magick_rows));
695 WarnNoImageReturn(
"\"%%%c\"",letter);
696 string=image->filename;
701 WarnNoImageReturn(
"\"%%%c\"",letter);
702 string=image->magick;
707 if (image != (Image *) NULL)
708 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
709 GetImageListLength(image));
714 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
715 string=image_info->filename;
720 WarnNoImageReturn(
"\"%%%c\"",letter);
721 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
722 GetImageIndexInList(image));
727 WarnNoImageReturn(
"\"%%%c\"",letter);
728 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
729 MAGICKCORE_QUANTUM_DEPTH);
737 WarnNoImageReturn(
"\"%%%c\"",letter);
738 colorspace=image->colorspace;
739 (void) FormatLocaleString(value,MagickPathExtent,
"%s %s %s",
740 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
741 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
742 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
748 WarnNoImageReturn(
"\"%%%c\"",letter);
749 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
755 WarnNoImageReturn(
"\"%%%c\"",letter);
756 GetPathComponent(image->magick_filename,BasePath,value);
761 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
762 string=image_info->unique;
767 WarnNoImageReturn(
"\"%%%c\"",letter);
768 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
769 (image->columns != 0 ? image->columns : image->magick_columns));
774 WarnNoImageReturn(
"\"%%%c\"",letter);
775 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
776 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
777 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
783 WarnNoImageReturn(
"\"%%%c\"",letter);
784 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
785 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
786 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
792 WarnNoImageReturn(
"\"%%%c\"",letter);
793 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
794 (
double) image->depth);
799 WarnNoImageReturn(
"\"%%%c\"",letter);
800 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
806 WarnNoImageReturn(
"\"%%%c\"",letter);
807 string=CommandOptionToMnemonic(MagickCompressOptions,
808 (ssize_t) image->compression);
813 WarnNoImageReturn(
"\"%%%c\"",letter);
814 string=CommandOptionToMnemonic(MagickDisposeOptions,
815 (ssize_t) image->dispose);
823 WarnNoImageReturn(
"\"%%%c\"",letter);
824 (void) CopyMagickString(value,image->magick_filename,MagickPathExtent);
829 WarnNoImageReturn(
"\"%%%c\"",letter);
830 (void) FormatLocaleString(value,MagickPathExtent,
"%.17gx%.17g",
831 (
double) image->magick_columns,(
double) image->magick_rows);
836 WarnNoImageReturn(
"\"%%%c\"",letter);
837 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
838 (
double) image->page.height);
843 WarnNoImageReturn(
"\"%%%c\"",letter);
844 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
850 WarnNoImageReturn(
"\"%%%c\"",letter);
851 string=image->magick_filename;
856 WarnNoImageReturn(
"\"%%%c\"",letter);
857 (void) FormatLocaleString(value,MagickPathExtent,
"%+ld%+ld",(
long)
858 image->page.x,(
long) image->page.y);
863 WarnNoImageReturn(
"\"%%%c\"",letter);
864 (void) FormatLocaleString(value,MagickPathExtent,
"%.17gx%.17g",
865 (
double) image->page.width,(
double) image->page.height);
870 WarnNoImageReturn(
"\"%%%c\"",letter);
871 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
872 (100-(image->quality == 0 ? 42 : image->quality))/2);
877 WarnNoImageReturn(
"\"%%%c\"",letter);
878 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
879 (image->quality == 0 ? 92 : image->quality));
884 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
885 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
886 (image_info->number_scenes == 0 ? 2147483647 :
887 image_info->number_scenes));
892 WarnNoImageReturn(
"\"%%%c\"",letter);
893 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
899 WarnNoImageReturn(
"\"%%%c\"",letter);
900 string=CommandOptionToMnemonic(MagickResolutionOptions,
901 (ssize_t) image->units);
906 WarnNoImageReturn(
"\"%%%c\"",letter);
907 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
913 WarnNoImageReturn(
"\"%%%c\"",letter);
914 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
920 WarnNoImageReturn(
"\"%%%c\"",letter);
921 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
935 WarnNoImageReturn(
"\"%%%c\"",letter);
936 page=GetImageBoundingBox(image,exception);
937 (void) FormatLocaleString(value,MagickPathExtent,
938 "%.17gx%.17g%+.20g%+.20g",(
double) page.width,(
double) page.height,
939 (
double) page.x,(
double) page.y);
947 WarnNoImageReturn(
"\"%%%c\"",letter);
948 (void) SignatureImage(image,exception);
949 string=GetImageProperty(image,
"signature",exception);
953 return(SanitizeDelegateString(
string));
956static char *InterpretDelegateProperties(ImageInfo *image_info,
957 Image *image,
const char *embed_text,ExceptionInfo *exception)
959#define ExtendInterpretText(string_length) \
961 size_t length=(string_length); \
962 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
965 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
966 MagickPathExtent,sizeof(*interpret_text)); \
967 if (interpret_text == (char *) NULL) \
968 return((char *) NULL); \
969 q=interpret_text+strlen(interpret_text); \
973#define AppendKeyValue2Text(key,value)\
975 size_t length=strlen(key)+strlen(value)+2; \
976 if ((size_t) (q-interpret_text+length+1) >= extent) \
979 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
980 MagickPathExtent,sizeof(*interpret_text)); \
981 if (interpret_text == (char *) NULL) \
982 return((char *) NULL); \
983 q=interpret_text+strlen(interpret_text); \
985 q+=(ptrdiff_t) FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
988#define AppendString2Text(string) \
990 size_t length=strlen((string)); \
991 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
994 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
995 MagickPathExtent,sizeof(*interpret_text)); \
996 if (interpret_text == (char *) NULL) \
997 return((char *) NULL); \
998 q=interpret_text+strlen(interpret_text); \
1000 (void) CopyMagickString(q,(string),extent); \
1001 q+=(ptrdiff_t) length; \
1020 assert(image == NULL || image->signature == MagickCoreSignature);
1021 assert(image_info == NULL || image_info->signature == MagickCoreSignature);
1022 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
1023 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1025 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
1026 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-image");
1027 if (embed_text == (
const char *) NULL)
1028 return(ConstantString(
""));
1030 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1033 return(ConstantString(
""));
1037 interpret_text=AcquireString(embed_text);
1038 extent=MagickPathExtent;
1040 for (q=interpret_text; *p!=
'\0';
1041 number=isdigit((
int) ((
unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
1047 ExtendInterpretText(MagickPathExtent);
1090 if (LocaleNCompare(
"<",p,4) == 0)
1096 if (LocaleNCompare(
">",p,4) == 0)
1102 if (LocaleNCompare(
"&",p,5) == 0)
1123 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1133 if (number != MagickFalse)
1142 string=GetMagickPropertyLetter(image_info,image,*p,exception);
1143 if (
string != (
char *) NULL)
1145 AppendString2Text(
string);
1146 string=DestroyString(
string);
1149 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1150 "UnknownImageProperty",
"\"%%%c\"",*p);
1153 return(interpret_text);
1156MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,Image *image,
1157 const char *decode,
const char *encode,ExceptionInfo *exception)
1169 assert(image_info != (ImageInfo *) NULL);
1170 assert(image_info->signature == MagickCoreSignature);
1171 assert(image != (Image *) NULL);
1172 assert(image->signature == MagickCoreSignature);
1173 if (IsEventLogging() != MagickFalse)
1174 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1175 delegate_info=GetDelegateInfo(decode,encode,exception);
1176 if (delegate_info == (
const DelegateInfo *) NULL)
1178 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1179 "NoTagFound",
"`%s'",decode ? decode : encode);
1180 return((
char *) NULL);
1182 commands=StringToList(delegate_info->commands);
1183 if (commands == (
char **) NULL)
1185 (void) ThrowMagickException(exception,GetMagickModule(),
1186 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",decode ? decode :
1188 return((
char *) NULL);
1190 command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1191 commands[0],exception);
1192 if (command == (
char *) NULL)
1193 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1194 "MemoryAllocationFailed",
"`%s'",commands[0]);
1198 for (i=0; commands[i] != (
char *) NULL; i++)
1199 commands[i]=DestroyString(commands[i]);
1200 commands=(
char **) RelinquishMagickMemory(commands);
1226MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1228 if (IsEventLogging() != MagickFalse)
1229 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1230 assert(delegate_info != (DelegateInfo *) NULL);
1231 assert(delegate_info->signature == MagickCoreSignature);
1232 return(delegate_info->commands);
1264MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1265 const char *encode,ExceptionInfo *exception)
1273 assert(exception != (ExceptionInfo *) NULL);
1274 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1275 return((
const DelegateInfo *) NULL);
1279 delegate_info=(
const DelegateInfo *) NULL;
1280 LockSemaphoreInfo(delegate_semaphore);
1281 p=GetHeadElementInLinkedList(delegate_cache);
1282 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1284 UnlockSemaphoreInfo(delegate_semaphore);
1285 if (p != (ElementInfo *) NULL)
1286 delegate_info=(
const DelegateInfo* ) p->value;
1287 return(delegate_info);
1289 while (p != (ElementInfo *) NULL)
1291 delegate_info=(
const DelegateInfo* ) p->value;
1292 if (delegate_info->mode > 0)
1294 if (LocaleCompare(delegate_info->decode,decode) == 0)
1299 if (delegate_info->mode < 0)
1301 if (LocaleCompare(delegate_info->encode,encode) == 0)
1306 if (LocaleCompare(decode,delegate_info->decode) == 0)
1307 if (LocaleCompare(encode,delegate_info->encode) == 0)
1309 if (LocaleCompare(decode,
"*") == 0)
1310 if (LocaleCompare(encode,delegate_info->encode) == 0)
1312 if (LocaleCompare(decode,delegate_info->decode) == 0)
1313 if (LocaleCompare(encode,
"*") == 0)
1317 if (p == (ElementInfo *) NULL)
1318 delegate_info=(
const DelegateInfo *) NULL;
1320 SetHeadElementInLinkedList(delegate_cache,p);
1321 UnlockSemaphoreInfo(delegate_semaphore);
1322 return(delegate_info);
1354#if defined(__cplusplus) || defined(c_plusplus)
1358static int DelegateInfoCompare(
const void *x,
const void *y)
1367 p=(
const DelegateInfo **) x,
1368 q=(
const DelegateInfo **) y;
1369 cmp=LocaleCompare((*p)->path,(*q)->path);
1372 if ((*p)->decode == (
char *) NULL)
1373 if (((*p)->encode != (
char *) NULL) &&
1374 ((*q)->encode != (
char *) NULL))
1375 return(strcmp((*p)->encode,(*q)->encode));
1376 if (((*p)->decode != (
char *) NULL) &&
1377 ((*q)->decode != (
char *) NULL))
1378 return(strcmp((*p)->decode,(*q)->decode));
1383#if defined(__cplusplus) || defined(c_plusplus)
1387MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1388 size_t *number_delegates,ExceptionInfo *exception)
1399 assert(number_delegates != (
size_t *) NULL);
1400 assert(pattern != (
char *) NULL);
1401 if (IsEventLogging() != MagickFalse)
1402 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1403 *number_delegates=0;
1404 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1405 return((
const DelegateInfo **) NULL);
1406 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1407 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1408 if (delegates == (
const DelegateInfo **) NULL)
1409 return((
const DelegateInfo **) NULL);
1410 LockSemaphoreInfo(delegate_semaphore);
1411 p=GetHeadElementInLinkedList(delegate_cache);
1412 for (i=0; p != (ElementInfo *) NULL; )
1417 delegate_info=(
const DelegateInfo *) p->value;
1418 if( (delegate_info->stealth == MagickFalse) &&
1419 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse ||
1420 GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1421 delegates[i++]=delegate_info;
1424 UnlockSemaphoreInfo(delegate_semaphore);
1426 delegates=(
const DelegateInfo **) RelinquishMagickMemory((
void*) delegates);
1429 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1430 delegates[i]=(DelegateInfo *) NULL;
1432 *number_delegates=(size_t) i;
1466#if defined(__cplusplus) || defined(c_plusplus)
1470static int DelegateCompare(
const void *x,
const void *y)
1476 p=(
const char **) x;
1477 q=(
const char **) y;
1478 return(LocaleCompare(*p,*q));
1481#if defined(__cplusplus) || defined(c_plusplus)
1485MagickExport
char **GetDelegateList(
const char *pattern,
1486 size_t *number_delegates,ExceptionInfo *exception)
1497 assert(pattern != (
char *) NULL);
1498 if (IsEventLogging() != MagickFalse)
1499 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1500 assert(number_delegates != (
size_t *) NULL);
1501 *number_delegates=0;
1502 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1503 return((
char **) NULL);
1504 delegates=(
char **) AcquireQuantumMemory((
size_t)
1505 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1506 if (delegates == (
char **) NULL)
1507 return((
char **) NULL);
1508 LockSemaphoreInfo(delegate_semaphore);
1509 p=GetHeadElementInLinkedList(delegate_cache);
1510 for (i=0; p != (ElementInfo *) NULL; )
1515 delegate_info=(
const DelegateInfo *) p->value;
1516 if ((delegate_info->stealth == MagickFalse) &&
1517 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse))
1518 delegates[i++]=ConstantString(delegate_info->decode);
1519 if ((delegate_info->stealth == MagickFalse) &&
1520 (GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1521 delegates[i++]=ConstantString(delegate_info->encode);
1524 UnlockSemaphoreInfo(delegate_semaphore);
1526 delegates=(
char **) RelinquishMagickMemory(delegates);
1529 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1530 delegates[i]=(
char *) NULL;
1532 *number_delegates=(size_t) i;
1558MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1560 if (IsEventLogging() != MagickFalse)
1561 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1562 assert(delegate_info != (DelegateInfo *) NULL);
1563 assert(delegate_info->signature == MagickCoreSignature);
1564 return(delegate_info->mode);
1591MagickExport MagickBooleanType GetDelegateThreadSupport(
1592 const DelegateInfo *delegate_info)
1594 assert(delegate_info != (DelegateInfo *) NULL);
1595 assert(delegate_info->signature == MagickCoreSignature);
1596 if (IsEventLogging() != MagickFalse)
1597 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1598 return(delegate_info->thread_support);
1624static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1626 if (delegate_cache == (LinkedListInfo *) NULL)
1629 ActivateSemaphoreInfo(&delegate_semaphore);
1630 LockSemaphoreInfo(delegate_semaphore);
1631 if (delegate_cache == (LinkedListInfo *) NULL)
1632 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1633 UnlockSemaphoreInfo(delegate_semaphore);
1635 return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1668static MagickBooleanType CopyDelegateFile(
const char *source,
1669 const char *destination,
const MagickBooleanType overwrite,
1670 ExceptionInfo *exception)
1673 destination_file = -1,
1677 status = MagickTrue;
1694 assert(source != (
const char *) NULL);
1695 assert(destination != (
char *) NULL);
1696 if ((overwrite == MagickFalse) &&
1697 (GetPathAttributes(destination,&attributes) != MagickFalse))
1699 if (IsPathAuthorized(WritePolicyRights,destination) == MagickFalse)
1700 ThrowPolicyException(source,MagickFalse);
1701 destination_file=open_utf8(destination,O_WRONLY | O_CLOEXEC | O_BINARY | O_CREAT |
1703 if (destination_file == -1)
1704 return(MagickFalse);
1705 if (IsPathAuthorized(WritePolicyRights,destination) == MagickFalse)
1706 ThrowPolicyException(destination,MagickFalse);
1707 if (IsPathAuthorized(ReadPolicyRights,source) == MagickFalse)
1709 (void) close_utf8(destination_file);
1710 ThrowPolicyException(source,MagickFalse);
1712 source_file=open_utf8(source,O_RDONLY | O_CLOEXEC | O_BINARY,0);
1713 if (source_file == -1)
1715 (void) close_utf8(destination_file);
1716 return(MagickFalse);
1718 quantum=(size_t) MagickMaxBufferExtent;
1719 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1720 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1721 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1722 if (buffer == (
unsigned char *) NULL)
1724 (void) close_utf8(source_file);
1725 (void) close_utf8(destination_file);
1726 return(MagickFalse);
1728 while ((count=read(source_file,buffer,quantum)) > 0)
1730 ssize_t written = write(destination_file,buffer,(
size_t) count);
1731 if (written != count)
1739 (void) close_utf8(destination_file);
1740 (void) close_utf8(source_file);
1741 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1745MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
1746 Image *image,
const char *decode,
const char *encode,ExceptionInfo *exception)
1751 input_filename[MagickPathExtent],
1752 output_filename[MagickPathExtent];
1770 assert(image_info != (ImageInfo *) NULL);
1771 assert(image_info->signature == MagickCoreSignature);
1772 assert(image != (Image *) NULL);
1773 assert(image->signature == MagickCoreSignature);
1774 if (IsEventLogging() != MagickFalse)
1775 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1776 rights=ExecutePolicyRights;
1777 if ((decode != (
const char *) NULL) &&
1778 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1779 ThrowPolicyException(decode,MagickFalse);
1780 if ((encode != (
const char *) NULL) &&
1781 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1782 ThrowPolicyException(encode,MagickFalse);
1783 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1784 if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1787 ThrowFileException(exception,FileOpenError,
"UnableToCreateTemporaryFile",
1789 return(MagickFalse);
1791 delegate_info=GetDelegateInfo(decode,encode,exception);
1792 if (delegate_info == (DelegateInfo *) NULL)
1794 if (temporary != MagickFalse)
1795 (void) RelinquishUniqueFileResource(image->filename);
1796 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1797 "NoTagFound",
"`%s'",decode ? decode : encode);
1798 return(MagickFalse);
1800 if (*image_info->filename ==
'\0')
1802 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1804 if (temporary != MagickFalse)
1805 (void) RelinquishUniqueFileResource(image->filename);
1806 ThrowFileException(exception,FileOpenError,
1807 "UnableToCreateTemporaryFile",image_info->filename);
1808 return(MagickFalse);
1810 image_info->temporary=MagickTrue;
1812 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1813 (delegate_info->encode != (
char *) NULL)) ||
1814 ((encode != (
const char *) NULL) &&
1815 (delegate_info->decode != (
char *) NULL))))
1829 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1831 ThrowFileException(exception,FileOpenError,
1832 "UnableToCreateTemporaryFile",image_info->unique);
1833 return(MagickFalse);
1835 magick=InterpretImageProperties(image_info,image,decode != (
char *) NULL ?
1836 delegate_info->encode : delegate_info->decode,exception);
1837 if (magick == (
char *) NULL)
1839 (void) RelinquishUniqueFileResource(image_info->unique);
1840 if (temporary != MagickFalse)
1841 (void) RelinquishUniqueFileResource(image->filename);
1842 (void) ThrowMagickException(exception,GetMagickModule(),
1843 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1844 return(MagickFalse);
1846 LocaleUpper(magick);
1847 clone_info=CloneImageInfo(image_info);
1848 (void) CopyMagickString((
char *) clone_info->magick,magick,
1850 if (LocaleCompare(magick,
"NULL") != 0)
1851 (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1852 magick=DestroyString(magick);
1853 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
"%s:",
1854 delegate_info->decode);
1855 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1857 (void) CopyMagickString(clone_info->filename,image_info->filename,
1859 (void) CopyMagickString(image_info->filename,image->filename,
1861 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1863 (void) FormatLocaleString(p->filename,MagickPathExtent,
"%s:%s",
1864 delegate_info->decode,clone_info->filename);
1865 status=WriteImage(clone_info,p,exception);
1866 if (status == MagickFalse)
1868 (void) RelinquishUniqueFileResource(image_info->unique);
1869 if (temporary != MagickFalse)
1870 (void) RelinquishUniqueFileResource(image->filename);
1871 clone_info=DestroyImageInfo(clone_info);
1872 (void) ThrowMagickException(exception,GetMagickModule(),
1873 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1874 return(MagickFalse);
1876 if (clone_info->adjoin != MagickFalse)
1879 (void) RelinquishUniqueFileResource(image_info->unique);
1880 clone_info=DestroyImageInfo(clone_info);
1885 commands=StringToList(delegate_info->commands);
1886 if (commands == (
char **) NULL)
1888 if (temporary != MagickFalse)
1889 (void) RelinquishUniqueFileResource(image->filename);
1890 (void) ThrowMagickException(exception,GetMagickModule(),
1891 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1892 decode ? decode : encode);
1893 return(MagickFalse);
1895 command=(
char *) NULL;
1897 (void) CopyMagickString(output_filename,image_info->filename,
1899 (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1900 for (i=0; commands[i] != (
char *) NULL; i++)
1902 (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1903 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1905 ThrowFileException(exception,FileOpenError,
1906 "UnableToCreateTemporaryFile",image_info->unique);
1909 if (IsPathAccessible(input_filename) != MagickFalse)
1911 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1912 if (status == MagickFalse)
1914 ThrowFileException(exception,FileOpenError,
1915 "UnableToCreateTemporaryFile",input_filename);
1920 command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1921 if (command != (
char *) NULL)
1926 if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,command,(
char *) NULL,exception) != 0)
1928 if (delegate_info->spawn != MagickFalse)
1937 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1938 (void) MagickDelay(100);
1940 command=DestroyString(command);
1942 if (IsPathAccessible(input_filename) != MagickFalse)
1944 if (CopyDelegateFile(image->filename,input_filename,MagickFalse,exception) == MagickFalse)
1946 (void) RelinquishUniqueFileResource(input_filename);
1950 if ((strcmp(input_filename,output_filename) != 0) &&
1951 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue,exception) == MagickFalse))
1953 (void) RelinquishUniqueFileResource(output_filename);
1956 if (image_info->temporary != MagickFalse)
1957 (void) RelinquishUniqueFileResource(image_info->filename);
1958 (void) RelinquishUniqueFileResource(image_info->unique);
1959 (void) RelinquishUniqueFileResource(image_info->filename);
1960 (void) RelinquishUniqueFileResource(image->filename);
1961 if (status == MagickFalse)
1963 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1964 "DelegateFailed",
"`%s'",commands[i]);
1967 commands[i]=DestroyString(commands[i]);
1969 (void) CopyMagickString(image_info->filename,output_filename,
1971 (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
1975 for ( ; commands[i] != (
char *) NULL; i++)
1976 commands[i]=DestroyString(commands[i]);
1977 commands=(
char **) RelinquishMagickMemory(commands);
1978 if (temporary != MagickFalse)
1979 (void) RelinquishUniqueFileResource(image->filename);
2007MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2008 ExceptionInfo *exception)
2015 delegate[MagickPathExtent];
2029 if (file == (
const FILE *) NULL)
2031 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2032 if (delegate_info == (
const DelegateInfo **) NULL)
2033 return(MagickFalse);
2034 path=(
const char *) NULL;
2035 for (i=0; i < (ssize_t) number_delegates; i++)
2037 if (delegate_info[i]->stealth != MagickFalse)
2039 if ((path == (
const char *) NULL) ||
2040 (LocaleCompare(path,delegate_info[i]->path) != 0))
2042 if (delegate_info[i]->path != (
char *) NULL)
2043 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2044 (void) FormatLocaleFile(file,
"Delegate Command\n");
2045 (void) FormatLocaleFile(file,
2046 "-------------------------------------------------"
2047 "------------------------------\n");
2049 path=delegate_info[i]->path;
2051 if (delegate_info[i]->encode != (
char *) NULL)
2052 (void) CopyMagickString(delegate,delegate_info[i]->encode,
2054 (void) ConcatenateMagickString(delegate,
" ",MagickPathExtent);
2056 commands=StringToList(delegate_info[i]->commands);
2057 if (commands == (
char **) NULL)
2059 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2060 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2061 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2062 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2063 for (j=1; commands[j] != (
char *) NULL; j++)
2064 (
void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2065 for (j=0; commands[j] != (
char *) NULL; j++)
2066 commands[j]=DestroyString(commands[j]);
2067 commands=(
char **) RelinquishMagickMemory(commands);
2069 (void) fflush(file);
2070 delegate_info=(
const DelegateInfo **)
2071 RelinquishMagickMemory((
void *) delegate_info);
2106static MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
2107 const char *xml,
const char *filename,
const size_t depth,
2108 ExceptionInfo *exception)
2111 keyword[MagickPathExtent],
2129 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2130 "Loading delegate configuration file \"%s\" ...",filename);
2131 if (xml == (
const char *) NULL)
2132 return(MagickFalse);
2134 delegate_info=(DelegateInfo *) NULL;
2135 token=AcquireString(xml);
2136 extent=strlen(token)+MagickPathExtent;
2137 for (q=(
const char *) xml; *q !=
'\0'; )
2142 (void) GetNextToken(q,&q,extent,token);
2145 (void) CopyMagickString(keyword,token,MagickPathExtent);
2146 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2155 for ( ; *q !=
'\0'; q++)
2164 if ((*q ==
'"') || (*q ==
'\''))
2172 if (bracket_depth > 0)
2176 if ((*q ==
'>') && (bracket_depth == 0))
2184 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2189 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2190 (void) GetNextToken(q,&q,extent,token);
2193 if (LocaleCompare(keyword,
"<include") == 0)
2198 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2200 (void) CopyMagickString(keyword,token,MagickPathExtent);
2201 (void) GetNextToken(q,&q,extent,token);
2204 (void) GetNextToken(q,&q,extent,token);
2205 if (LocaleCompare(keyword,
"file") == 0)
2207 if (depth > MagickMaxRecursionDepth)
2208 (void) ThrowMagickException(exception,GetMagickModule(),
2209 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2213 path[MagickPathExtent],
2216 GetPathComponent(filename,HeadPath,path);
2218 (void) ConcatenateMagickString(path,DirectorySeparator,
2220 if (*token == *DirectorySeparator)
2221 (void) CopyMagickString(path,token,MagickPathExtent);
2223 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
2224 file_xml=FileToXML(path,~0UL);
2225 if (file_xml != (
char *) NULL)
2227 status&=(MagickStatusType) LoadDelegateCache(cache,
2228 file_xml,path,depth+1,exception);
2229 file_xml=DestroyString(file_xml);
2236 if (LocaleCompare(keyword,
"<delegate") == 0)
2241 delegate_info=(DelegateInfo *) AcquireCriticalMemory(
2242 sizeof(*delegate_info));
2243 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2244 delegate_info->path=ConstantString(filename);
2245 delegate_info->thread_support=MagickTrue;
2246 delegate_info->signature=MagickCoreSignature;
2249 if (delegate_info == (DelegateInfo *) NULL)
2251 if ((LocaleCompare(keyword,
"/>") == 0) ||
2252 (LocaleCompare(keyword,
"</policy>") == 0))
2254 status=AppendValueToLinkedList(cache,delegate_info);
2255 if (status == MagickFalse)
2256 (void) ThrowMagickException(exception,GetMagickModule(),
2257 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2258 delegate_info->commands);
2259 delegate_info=(DelegateInfo *) NULL;
2262 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2265 (void) GetNextToken(q,&q,extent,token);
2266 (void) GetNextToken(q,&q,extent,token);
2272 if (LocaleCompare((
char *) keyword,
"command") == 0)
2277 commands=AcquireString(token);
2278#if defined(MAGICKCORE_WINDOWS_SUPPORT)
2279 if (strchr(commands,
'@') != (
char *) NULL)
2282 path[MagickPathExtent];
2284 NTGhostscriptEXE(path,MagickPathExtent);
2285 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2287 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2290 (void) SubstituteString((
char **) &commands,
""",
"\"");
2291 (void) SubstituteString((
char **) &commands,
"'",
"'");
2292 (void) SubstituteString((
char **) &commands,
"&",
"&");
2293 (void) SubstituteString((
char **) &commands,
">",
">");
2294 (void) SubstituteString((
char **) &commands,
"<",
"<");
2295 if (delegate_info->commands != (
char *) NULL)
2296 delegate_info->commands=DestroyString(delegate_info->commands);
2297 delegate_info->commands=commands;
2305 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2307 delegate_info->decode=ConstantString(token);
2308 delegate_info->mode=1;
2316 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2318 delegate_info->encode=ConstantString(token);
2319 delegate_info->mode=(-1);
2327 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2329 delegate_info->mode=1;
2330 if (LocaleCompare(token,
"bi") == 0)
2331 delegate_info->mode=0;
2333 if (LocaleCompare(token,
"encode") == 0)
2334 delegate_info->mode=(-1);
2342 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2344 delegate_info->spawn=IsStringTrue(token);
2347 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2349 delegate_info->stealth=IsStringTrue(token);
2357 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2359 delegate_info->thread_support=IsStringTrue(token);
2360 if (delegate_info->thread_support == MagickFalse)
2361 delegate_info->semaphore=AcquireSemaphoreInfo();
2370 token=(
char *) RelinquishMagickMemory(token);
2371 return(status != 0 ? MagickTrue : MagickFalse);