48 #include "magick/studio.h"
49 #include "magick/artifact.h"
50 #include "magick/attribute.h"
51 #include "magick/blob.h"
52 #include "magick/client.h"
53 #include "magick/configure.h"
54 #include "magick/constitute.h"
55 #include "magick/delegate.h"
56 #include "magick/exception.h"
57 #include "magick/exception-private.h"
58 #include "magick/hashmap.h"
59 #include "magick/image-private.h"
60 #include "magick/list.h"
61 #include "magick/memory_.h"
62 #include "magick/nt-base-private.h"
63 #include "magick/option.h"
64 #include "magick/policy.h"
65 #include "magick/policy-private.h"
66 #include "magick/property.h"
67 #include "magick/resource_.h"
68 #include "magick/semaphore.h"
69 #include "magick/signature.h"
70 #include "magick/string_.h"
71 #include "magick/token.h"
72 #include "magick/token-private.h"
73 #include "magick/utility.h"
74 #include "magick/utility-private.h"
75 #include "magick/xml-tree.h"
76 #include "magick/xml-tree-private.h"
81 #if defined(__APPLE__)
82 #include "TargetConditionals.h"
83 #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
84 #define system(s) ((s)==NULL ? 0 : -1)
86 #elif defined(__ANDROID__)
87 #define system(s) ((s)==NULL ? 0 : -1)
89 #define DelegateFilename "delegates.xml"
90 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
91 #define DELEGATE_ESC """
93 #define DELEGATE_ESC "'"
100 *DelegateMap = (
const char *)
101 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
103 " <delegate decode=\"bpg\" command=\"" DELEGATE_ESC
"bpgdec" DELEGATE_ESC
" -b 16 -o " DELEGATE_ESC
"%o.png" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.png" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
104 " <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
"\"/>"
105 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\"" DELEGATE_ESC
"xdg-open" DELEGATE_ESC
" https://imagemagick.org/; rm " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
106 " <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
"\"/>"
107 " <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
"\"/>"
108 " <delegate decode=\"https\" command=\"" DELEGATE_ESC
"curl" DELEGATE_ESC
" -s -k -L -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"https:%M" DELEGATE_ESC
"\"/>"
109 " <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
"\"/>"
110 " <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
"\"/>"
111 " <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
"\"/>"
112 " <delegate decode=\"dot\" command=\"" DELEGATE_ESC
"dot" DELEGATE_ESC
" -Tsvg " DELEGATE_ESC
"%i" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
113 " <delegate decode=\"dvi\" command=\"" DELEGATE_ESC
"dvips" DELEGATE_ESC
" -sstdout=%%stderr -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
114 " <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
"\"/>"
115 " <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
"\"/>"
116 " <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
"\"/>"
117 " <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
"\"/>"
118 " <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
"\"/>"
119 " <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
"\"/>"
120 " <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
"\"/>"
121 " <delegate decode=\"htm\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
122 " <delegate decode=\"html\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
123 " <delegate decode=\"ilbm\" command=\"" DELEGATE_ESC
"ilbmtoppm" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
124 " <delegate decode=\"jpg\" encode=\"lep\" mode=\"encode\" command=\"" DELEGATE_ESC
"lepton" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
125 " <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
"\"/>"
126 " <delegate decode=\"lep\" mode=\"decode\" command=\"" DELEGATE_ESC
"lepton" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
127 " <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
"\"/>"
128 " <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
"\"/>"
129 " <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
"\"/>"
130 " <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
"\"/>"
131 " <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
"\"/>"
132 " <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
"\"/>"
133 " <delegate decode=\"png\" encode=\"clipboard\" command=\"" DELEGATE_ESC
"xclip" DELEGATE_ESC
" -selection clipboard -t image/png " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
134 " <delegate decode=\"clipboard\" command=\"" DELEGATE_ESC
"xclip" DELEGATE_ESC
" -selection clipboard -o > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
135 " <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
"\"/>"
136 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\"" DELEGATE_ESC
"ppmtoilbm" DELEGATE_ESC
" -24if " DELEGATE_ESC
"%i" DELEGATE_ESC
" > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
137 " <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
"\"/>"
138 " <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
"\"/>"
139 " <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
"\"/>"
140 " <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
"\"/>"
141 " <delegate decode=\"ps\" encode=\"prt\" command=\"" DELEGATE_ESC
"lpr" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
142 " <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
"\"/>"
143 " <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
"\"/>"
144 " <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
"\"/>"
145 " <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
"\"/>"
146 " <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
"\"/>"
147 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
148 " <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
"\"/>"
149 " <delegate decode=\"shtml\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
150 " <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
"\"/>"
151 " <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
"\"/>"
152 #ifndef MAGICKCORE_RSVG_DELEGATE
153 " <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
"\"/>"
155 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\"" DELEGATE_ESC
"gimp" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
156 " <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
"\"/>"
157 " <delegate decode=\"webp\" command=\"" DELEGATE_ESC
"dwebp" DELEGATE_ESC
" -pam " DELEGATE_ESC
"%i" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
158 " <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
"\"/>"
159 " <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
"\"/>"
160 " <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
"\"/>"
161 " <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
"\"/>"
162 " <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
"\"/>"
163 " <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
"\"/>"
164 " <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
"\"/>"
181 static MagickBooleanType
183 LoadDelegateCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
218 cache=NewLinkedList(0);
219 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
227 options=GetConfigureOptions(filename,exception);
228 option=(
const StringInfo *) GetNextValueInLinkedList(options);
231 (void) LoadDelegateCache(cache,(
const char *) GetStringInfoDatum(option),
232 GetStringInfoPath(option),0,exception);
233 option=(
const StringInfo *) GetNextValueInLinkedList(options);
235 options=DestroyConfigureOptions(options);
238 if (IsLinkedListEmpty(cache) != MagickFalse)
239 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
261 MagickExport MagickBooleanType DelegateComponentGenesis(
void)
264 delegate_semaphore=AllocateSemaphoreInfo();
287 static void *DestroyDelegate(
void *delegate_info)
293 if (p->path != (
char *) NULL)
294 p->path=DestroyString(p->path);
295 if (p->decode != (
char *) NULL)
296 p->decode=DestroyString(p->decode);
297 if (p->encode != (
char *) NULL)
298 p->encode=DestroyString(p->encode);
299 if (p->commands != (
char *) NULL)
300 p->commands=DestroyString(p->commands);
302 DestroySemaphoreInfo(&p->semaphore);
304 return((
void *) NULL);
307 MagickExport
void DelegateComponentTerminus(
void)
310 ActivateSemaphoreInfo(&delegate_semaphore);
311 LockSemaphoreInfo(delegate_semaphore);
313 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
314 UnlockSemaphoreInfo(delegate_semaphore);
315 DestroySemaphoreInfo(&delegate_semaphore);
354 MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
355 const MagickBooleanType verbose,
const char *command,
char *message,
376 arguments=StringToArgv(command,&number_arguments);
377 if (arguments == (
char **) NULL)
379 if (*arguments[1] ==
'\0')
381 for (i=0; i < (ssize_t) number_arguments; i++)
382 arguments[i]=DestroyString(arguments[i]);
383 arguments=(
char **) RelinquishMagickMemory(arguments);
386 rights=ExecutePolicyRights;
387 domain=DelegatePolicyDomain;
388 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
391 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
392 "NotAuthorized",
"`%s'",arguments[1]);
393 for (i=0; i < (ssize_t) number_arguments; i++)
394 arguments[i]=DestroyString(arguments[i]);
395 arguments=(
char **) RelinquishMagickMemory(arguments);
398 if (verbose != MagickFalse)
400 (void) FormatLocaleFile(stderr,
"%s\n",command);
401 (void) fflush(stderr);
403 sanitize_command=SanitizeString(command);
404 if (asynchronous != MagickFalse)
405 (void) ConcatenateMagickString(sanitize_command,
"&",MaxTextExtent);
406 if (message != (
char *) NULL)
408 #if defined(MAGICKCORE_POSIX_SUPPORT)
409 #if defined(MAGICKCORE_HAVE_POPEN)
410 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
413 buffer[MagickPathExtent];
422 file=popen_utf8(sanitize_command,
"r");
423 if (file == (FILE *) NULL)
424 status=system(sanitize_command);
427 while (fgets(buffer,(
int)
sizeof(buffer),file) != NULL)
432 length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
435 (void) CopyMagickString(message+offset,buffer,length);
445 #if !defined(MAGICKCORE_HAVE_EXECVP)
446 status=system(sanitize_command);
448 if ((asynchronous != MagickFalse) ||
449 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
450 status=system(sanitize_command);
459 child_pid=(pid_t) fork();
460 if (child_pid == (pid_t) -1)
461 status=system(sanitize_command);
465 status=execvp(arguments[1],arguments+1);
477 pid=(pid_t) waitpid(child_pid,&child_status,0);
482 if (WIFEXITED(child_status) != 0)
483 status=WEXITSTATUS(child_status);
485 if (WIFSIGNALED(child_status))
492 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
505 p=strstr(sanitize_command,
"cmd.exe /c");
506 if (p != (
char*) NULL)
509 for ( ; *p !=
'\0'; p++)
511 *p=(*DirectorySeparator);
514 status=NTSystemCommand(sanitize_command,message);
516 status=system(sanitize_command);
518 # error No suitable system() method.
522 if ((message != (
char *) NULL) && (*message !=
'\0'))
523 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
524 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
526 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
527 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
529 sanitize_command=DestroyString(sanitize_command);
530 for (i=0; i < (ssize_t) number_arguments; i++)
531 arguments[i]=DestroyString(arguments[i]);
532 arguments=(
char **) RelinquishMagickMemory(arguments);
574 static char *GetMagickPropertyLetter(
const ImageInfo *image_info,
Image *image,
578 value[MaxTextExtent];
583 assert(image != (
Image *) NULL);
584 assert(image->signature == MagickCoreSignature);
585 if (IsEventLogging() != MagickFalse)
586 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
588 string=(
const char *) value;
596 if (image_info->authenticate != (
char *) NULL)
597 string=image_info->authenticate;
605 (void) FormatMagickSize(image->extent,MagickFalse,value);
606 if (image->extent == 0)
607 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,value);
615 GetPathComponent(image->magick_filename,HeadPath,value);
623 GetPathComponent(image->magick_filename,ExtensionPath,value);
631 GetPathComponent(image->magick_filename,TailPath,value);
639 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
640 (
double) image->page.width,(double) image->page.height,
641 (
double) image->page.x,(double) image->page.y);
649 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
650 (image->rows != 0 ? image->rows : image->magick_rows));
658 string=image->filename;
666 string=image->magick;
674 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
675 GetImageListLength(image));
683 string=image_info->filename;
691 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
692 GetImageIndexInList(image));
700 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
701 MAGICKCORE_QUANTUM_DEPTH);
712 colorspace=image->colorspace;
713 if (SetImageGray(image,&image->exception) != MagickFalse)
714 colorspace=GRAYColorspace;
715 (void) FormatLocaleString(value,MaxTextExtent,
"%s %s %s",
716 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
717 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
718 (ssize_t) colorspace),image->matte != MagickFalse ?
"Matte" :
"" );
726 if (image_info->number_scenes != 0)
727 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
730 (
void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
739 GetPathComponent(image->magick_filename,BasePath,value);
747 string=image_info->unique;
755 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
756 (image->columns != 0 ? image->columns : image->magick_columns));
764 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
765 fabs(image->x_resolution) > MagickEpsilon ? image->x_resolution :
766 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
775 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
776 fabs(image->y_resolution) > MagickEpsilon ? image->y_resolution :
777 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
786 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
795 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
796 CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
804 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
805 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
806 image->compression));
814 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
815 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
824 (void) CopyMagickString(value,image->magick_filename,MaxTextExtent);
832 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
833 image->magick_columns,(double) image->magick_rows);
841 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
850 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
859 string=image->magick_filename;
867 (void) FormatLocaleString(value,MaxTextExtent,
"%+ld%+ld",(
long)
868 image->page.x,(long) image->page.y);
876 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
877 image->page.width,(double) image->page.height);
885 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
886 (100-(image->quality == 0 ? 42 : image->quality))/2);
894 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
895 (image->quality == 0 ? 92 : image->quality));
903 if (image_info->number_scenes == 0)
907 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
908 image_info->scene+image_info->number_scenes);
917 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
926 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
927 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
936 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
945 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
954 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
963 string=image_info->zero;
974 page=GetImageBoundingBox(image,&image->exception);
975 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
976 (
double) page.width,(double) page.height,(
double) page.x,(double)
985 (void) SignatureImage(image);
986 string=GetImageProperty(image,
"signature");
998 return(SanitizeDelegateString(
string));
1001 static char *InterpretDelegateProperties(
const ImageInfo *image_info,
1002 Image *image,
const char *embed_text)
1004 #define ExtendInterpretText(string_length) \
1006 size_t length=(string_length); \
1007 if ((size_t) (q-interpret_text+length+1) >= extent) \
1010 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1011 MaxTextExtent,sizeof(*interpret_text)); \
1012 if (interpret_text == (char *) NULL) \
1013 return((char *) NULL); \
1014 q=interpret_text+strlen(interpret_text); \
1018 #define AppendKeyValue2Text(key,value)\
1020 size_t length=strlen(key)+strlen(value)+2; \
1021 if ((size_t) (q-interpret_text+length+1) >= extent) \
1024 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1025 MaxTextExtent,sizeof(*interpret_text)); \
1026 if (interpret_text == (char *) NULL) \
1027 return((char *) NULL); \
1028 q=interpret_text+strlen(interpret_text); \
1030 q+=(ptrdiff_t) FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
1033 #define AppendString2Text(string) \
1035 size_t length=strlen((string)); \
1036 if ((size_t) (q-interpret_text+length+1) >= extent) \
1039 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1040 MaxTextExtent,sizeof(*interpret_text)); \
1041 if (interpret_text == (char *) NULL) \
1042 return((char *) NULL); \
1043 q=interpret_text+strlen(interpret_text); \
1045 (void) CopyMagickString(q,(string),extent); \
1046 q+=(ptrdiff_t) length; \
1065 assert(image != (
Image *) NULL);
1066 assert(image->signature == MagickCoreSignature);
1067 if (IsEventLogging() != MagickFalse)
1068 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1069 if (embed_text == (
const char *) NULL)
1070 return(ConstantString(
""));
1072 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1075 return(ConstantString(
""));
1079 interpret_text=AcquireString(embed_text);
1080 extent=MaxTextExtent;
1082 for (q=interpret_text; *p!=
'\0';
1083 number=(isdigit((
int) ((
unsigned char) *p))) ? MagickTrue : MagickFalse,p++)
1089 ExtendInterpretText(MaxTextExtent);
1132 if (LocaleNCompare(
"<",p,4) == 0)
1138 if (LocaleNCompare(
">",p,4) == 0)
1144 if (LocaleNCompare(
"&",p,5) == 0)
1165 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1175 if (number != MagickFalse)
1181 property=GetMagickPropertyLetter(image_info,image,*p);
1182 if (property != (
char *) NULL)
1184 AppendString2Text(property);
1185 property=DestroyString(property);
1188 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1189 OptionWarning,
"UnknownImageProperty",
"\"%%%c\"",*p);
1192 return(interpret_text);
1195 MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,
Image *image,
1196 const char *decode,
const char *encode,
ExceptionInfo *exception)
1208 assert(image_info != (
ImageInfo *) NULL);
1209 assert(image_info->signature == MagickCoreSignature);
1210 assert(image != (
Image *) NULL);
1211 assert(image->signature == MagickCoreSignature);
1212 if (IsEventLogging() != MagickFalse)
1213 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1214 delegate_info=GetDelegateInfo(decode,encode,exception);
1217 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1218 "NoTagFound",
"`%s'",decode ? decode : encode);
1219 return((
char *) NULL);
1221 commands=StringToList(delegate_info->commands);
1222 if (commands == (
char **) NULL)
1224 (void) ThrowMagickException(exception,GetMagickModule(),
1225 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1226 decode ? decode : encode);
1227 return((
char *) NULL);
1229 command=InterpretDelegateProperties(image_info,image,commands[0]);
1230 if (command == (
char *) NULL)
1231 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1232 "MemoryAllocationFailed",
"`%s'",commands[0]);
1236 for (i=0; commands[i] != (
char *) NULL; i++)
1237 commands[i]=DestroyString(commands[i]);
1238 commands=(
char **) RelinquishMagickMemory(commands);
1264 MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1266 if (IsEventLogging() != MagickFalse)
1267 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1269 assert(delegate_info->signature == MagickCoreSignature);
1270 return(delegate_info->commands);
1302 MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1309 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1314 LockSemaphoreInfo(delegate_semaphore);
1315 ResetLinkedListIterator(delegate_cache);
1316 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1317 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1319 UnlockSemaphoreInfo(delegate_semaphore);
1326 if (LocaleCompare(p->decode,decode) == 0)
1328 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1333 if (LocaleCompare(p->encode,encode) == 0)
1335 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1338 if (LocaleCompare(decode,p->decode) == 0)
1339 if (LocaleCompare(encode,p->encode) == 0)
1341 if (LocaleCompare(decode,
"*") == 0)
1342 if (LocaleCompare(encode,p->encode) == 0)
1344 if (LocaleCompare(decode,p->decode) == 0)
1345 if (LocaleCompare(encode,
"*") == 0)
1347 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1350 (
void) InsertValueInLinkedList(delegate_cache,0,
1351 RemoveElementByValueFromLinkedList(delegate_cache,p));
1352 UnlockSemaphoreInfo(delegate_semaphore);
1385 #if defined(__cplusplus) || defined(c_plusplus)
1389 static int DelegateInfoCompare(
const void *x,
const void *y)
1400 cmp=LocaleCompare((*p)->path,(*q)->path);
1403 if ((*p)->decode == (
char *) NULL)
1404 if (((*p)->encode != (
char *) NULL) &&
1405 ((*q)->encode != (
char *) NULL))
1406 return(strcmp((*p)->encode,(*q)->encode));
1407 if (((*p)->decode != (
char *) NULL) &&
1408 ((*q)->decode != (
char *) NULL))
1409 return(strcmp((*p)->decode,(*q)->decode));
1414 #if defined(__cplusplus) || defined(c_plusplus)
1418 MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1433 assert(pattern != (
char *) NULL);
1434 assert(number_delegates != (
size_t *) NULL);
1435 if (IsEventLogging() != MagickFalse)
1436 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1437 *number_delegates=0;
1438 p=GetDelegateInfo(
"*",
"*",exception);
1441 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1442 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1448 LockSemaphoreInfo(delegate_semaphore);
1449 ResetLinkedListIterator(delegate_cache);
1450 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1453 if ((p->stealth == MagickFalse) &&
1454 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
1455 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
1457 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1459 UnlockSemaphoreInfo(delegate_semaphore);
1460 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1462 *number_delegates=(size_t) i;
1496 #if defined(__cplusplus) || defined(c_plusplus)
1500 static int DelegateCompare(
const void *x,
const void *y)
1506 p=(
const char **) x;
1507 q=(
const char **) y;
1508 return(LocaleCompare(*p,*q));
1511 #if defined(__cplusplus) || defined(c_plusplus)
1515 MagickExport
char **GetDelegateList(
const char *pattern,
1530 assert(pattern != (
char *) NULL);
1531 assert(number_delegates != (
size_t *) NULL);
1532 if (IsEventLogging() != MagickFalse)
1533 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1534 *number_delegates=0;
1535 p=GetDelegateInfo(
"*",
"*",exception);
1537 return((
char **) NULL);
1538 delegates=(
char **) AcquireQuantumMemory((
size_t)
1539 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1540 if (delegates == (
char **) NULL)
1541 return((
char **) NULL);
1542 LockSemaphoreInfo(delegate_semaphore);
1543 ResetLinkedListIterator(delegate_cache);
1544 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1547 if ((p->stealth == MagickFalse) &&
1548 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
1549 delegates[i++]=ConstantString(p->decode);
1550 if ((p->stealth == MagickFalse) &&
1551 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
1552 delegates[i++]=ConstantString(p->encode);
1553 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1555 UnlockSemaphoreInfo(delegate_semaphore);
1556 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1557 delegates[i]=(
char *) NULL;
1558 *number_delegates=(size_t) i;
1584 MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1586 if (IsEventLogging() != MagickFalse)
1587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1589 assert(delegate_info->signature == MagickCoreSignature);
1590 return(delegate_info->mode);
1617 MagickExport MagickBooleanType GetDelegateThreadSupport(
1620 if (IsEventLogging() != MagickFalse)
1621 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1623 assert(delegate_info->signature == MagickCoreSignature);
1624 return(delegate_info->thread_support);
1650 static MagickBooleanType IsDelegateCacheInstantiated(
ExceptionInfo *exception)
1655 ActivateSemaphoreInfo(&delegate_semaphore);
1656 LockSemaphoreInfo(delegate_semaphore);
1658 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1659 UnlockSemaphoreInfo(delegate_semaphore);
1661 return(delegate_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1694 static MagickBooleanType CopyDelegateFile(
const char *source,
1695 const char *destination,
const MagickBooleanType overwrite,
1724 assert(source != (
const char *) NULL);
1725 assert(destination != (
char *) NULL);
1726 if (overwrite == MagickFalse)
1728 status=GetPathAttributes(destination,&attributes);
1729 if (status != MagickFalse)
1732 if (IsPathAuthorized(WritePolicyRights,destination) == MagickFalse)
1733 ThrowPolicyException(destination,MagickFalse);
1734 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1735 if (destination_file == -1)
1736 return(MagickFalse);
1737 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1738 if (source_file == -1)
1740 (void) close(destination_file);
1741 return(MagickFalse);
1743 quantum=(size_t) MagickMaxBufferExtent;
1744 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1745 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1746 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1747 if (buffer == (
unsigned char *) NULL)
1749 (void) close(source_file);
1750 (void) close(destination_file);
1751 return(MagickFalse);
1754 for (i=0; ; i+=count)
1756 count=(ssize_t) read(source_file,buffer,quantum);
1759 length=(size_t) count;
1760 count=(ssize_t) write(destination_file,buffer,length);
1761 if ((
size_t) count != length)
1764 (void) close(destination_file);
1765 (void) close(source_file);
1766 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1767 return(i != 0 ? MagickTrue : MagickFalse);
1770 MagickExport MagickBooleanType InvokeDelegate(
ImageInfo *image_info,
1776 input_filename[MaxTextExtent],
1777 output_filename[MaxTextExtent];
1795 assert(image_info != (
ImageInfo *) NULL);
1796 assert(image_info->signature == MagickCoreSignature);
1797 assert(image != (
Image *) NULL);
1798 assert(image->signature == MagickCoreSignature);
1799 if (IsEventLogging() != MagickFalse)
1800 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1801 rights=ExecutePolicyRights;
1802 if ((decode != (
const char *) NULL) &&
1803 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1804 ThrowPolicyException(decode,MagickFalse);
1805 if ((encode != (
const char *) NULL) &&
1806 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1807 ThrowPolicyException(encode,MagickFalse);
1808 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1809 if (temporary != MagickFalse)
1810 if (AcquireUniqueFilename(image->filename) == MagickFalse)
1812 ThrowFileException(exception,FileOpenError,
1813 "UnableToCreateTemporaryFile",image->filename);
1814 return(MagickFalse);
1816 delegate_info=GetDelegateInfo(decode,encode,exception);
1819 if (temporary != MagickFalse)
1820 (void) RelinquishUniqueFileResource(image->filename);
1821 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1822 "NoTagFound",
"`%s'",decode ? decode : encode);
1823 return(MagickFalse);
1825 if (*image_info->filename ==
'\0')
1827 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1829 if (temporary != MagickFalse)
1830 (void) RelinquishUniqueFileResource(image->filename);
1831 ThrowFileException(exception,FileOpenError,
1832 "UnableToCreateTemporaryFile",image_info->filename);
1833 return(MagickFalse);
1835 image_info->temporary=MagickTrue;
1837 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1838 (delegate_info->encode != (
char *) NULL)) ||
1839 ((encode != (
const char *) NULL) &&
1840 (delegate_info->decode != (
char *) NULL))))
1854 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1856 ThrowFileException(exception,FileOpenError,
1857 "UnableToCreateTemporaryFile",image_info->unique);
1858 return(MagickFalse);
1860 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1862 (void) RelinquishUniqueFileResource(image_info->unique);
1863 ThrowFileException(exception,FileOpenError,
1864 "UnableToCreateTemporaryFile",image_info->zero);
1865 return(MagickFalse);
1867 magick=InterpretDelegateProperties(image_info,image,
1868 decode != (
char *) NULL ? delegate_info->encode :
1869 delegate_info->decode);
1870 if (magick == (
char *) NULL)
1872 (void) RelinquishUniqueFileResource(image_info->unique);
1873 (void) RelinquishUniqueFileResource(image_info->zero);
1874 if (temporary != MagickFalse)
1875 (void) RelinquishUniqueFileResource(image->filename);
1876 (void) ThrowMagickException(exception,GetMagickModule(),
1877 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1878 return(MagickFalse);
1880 LocaleUpper(magick);
1881 clone_info=CloneImageInfo(image_info);
1882 (void) CopyMagickString((
char *) clone_info->magick,magick,MaxTextExtent);
1883 if (LocaleCompare(magick,
"NULL") != 0)
1884 (
void) CopyMagickString(image->magick,magick,MaxTextExtent);
1885 magick=DestroyString(magick);
1886 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,
"%s:",
1887 delegate_info->decode);
1888 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1890 (void) CopyMagickString(clone_info->filename,image_info->filename,
1892 (void) CopyMagickString(image_info->filename,image->filename,
1894 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1896 (void) FormatLocaleString(p->filename,MaxTextExtent,
"%s:%s",
1897 delegate_info->decode,clone_info->filename);
1898 status=WriteImage(clone_info,p);
1899 if (status == MagickFalse)
1901 (void) RelinquishUniqueFileResource(image_info->unique);
1902 (void) RelinquishUniqueFileResource(image_info->zero);
1903 if (temporary != MagickFalse)
1904 (void) RelinquishUniqueFileResource(image->filename);
1905 clone_info=DestroyImageInfo(clone_info);
1906 (void) ThrowMagickException(exception,GetMagickModule(),
1907 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1908 return(MagickFalse);
1910 if (clone_info->adjoin != MagickFalse)
1913 (void) RelinquishUniqueFileResource(image_info->unique);
1914 (void) RelinquishUniqueFileResource(image_info->zero);
1915 clone_info=DestroyImageInfo(clone_info);
1920 commands=StringToList(delegate_info->commands);
1921 if (commands == (
char **) NULL)
1923 if (temporary != MagickFalse)
1924 (void) RelinquishUniqueFileResource(image->filename);
1925 (void) ThrowMagickException(exception,GetMagickModule(),
1926 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1927 decode ? decode : encode);
1928 return(MagickFalse);
1930 command=(
char *) NULL;
1932 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1933 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1934 for (i=0; commands[i] != (
char *) NULL; i++)
1936 if (IsPathAuthorized(WritePolicyRights,output_filename) == MagickFalse)
1939 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, \
1940 "NotAuthorized",
"`%s'",output_filename);
1943 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1944 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1946 ThrowFileException(exception,FileOpenError,
1947 "UnableToCreateTemporaryFile",image_info->unique);
1950 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1952 (void) RelinquishUniqueFileResource(image_info->unique);
1953 ThrowFileException(exception,FileOpenError,
1954 "UnableToCreateTemporaryFile",image_info->zero);
1957 if (LocaleCompare(decode,
"SCAN") != 0)
1959 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1960 if (status == MagickFalse)
1962 ThrowFileException(exception,FileOpenError,
1963 "UnableToCreateTemporaryFile",input_filename);
1968 command=InterpretDelegateProperties(image_info,image,commands[i]);
1969 if (command != (
char *) NULL)
1974 status=ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1975 command,(
char *) NULL,exception) != 0 ? MagickTrue : MagickFalse;
1976 if (delegate_info->spawn != MagickFalse)
1985 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1986 (void) MagickDelay(100);
1988 command=DestroyString(command);
1990 if (LocaleCompare(decode,
"SCAN") != 0)
1992 if (CopyDelegateFile(image->filename,input_filename,MagickFalse,&image->exception) == MagickFalse)
1993 (void) RelinquishUniqueFileResource(input_filename);
1995 if ((strcmp(input_filename,output_filename) != 0) &&
1996 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue,&image->exception) == MagickFalse))
1997 (void) RelinquishUniqueFileResource(output_filename);
1998 if (image_info->temporary != MagickFalse)
1999 (void) RelinquishUniqueFileResource(image_info->filename);
2000 (void) RelinquishUniqueFileResource(image_info->unique);
2001 (void) RelinquishUniqueFileResource(image_info->zero);
2002 (void) RelinquishUniqueFileResource(image_info->filename);
2003 (void) RelinquishUniqueFileResource(image->filename);
2004 if (status != MagickFalse)
2006 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
2007 "DelegateFailed",
"`%s'",commands[i]);
2010 commands[i]=DestroyString(commands[i]);
2012 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
2013 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
2017 for ( ; commands[i] != (
char *) NULL; i++)
2018 commands[i]=DestroyString(commands[i]);
2019 commands=(
char **) RelinquishMagickMemory(commands);
2020 if (temporary != MagickFalse)
2021 (void) RelinquishUniqueFileResource(image->filename);
2022 return(status == MagickFalse ? MagickTrue : MagickFalse);
2049 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2057 delegate[MaxTextExtent];
2071 if (file == (
const FILE *) NULL)
2073 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2075 return(MagickFalse);
2076 path=(
const char *) NULL;
2077 for (i=0; i < (ssize_t) number_delegates; i++)
2079 if (delegate_info[i]->stealth != MagickFalse)
2081 if ((path == (
const char *) NULL) ||
2082 (LocaleCompare(path,delegate_info[i]->path) != 0))
2084 if (delegate_info[i]->path != (
char *) NULL)
2085 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2086 (void) FormatLocaleFile(file,
"Delegate Command\n");
2087 (void) FormatLocaleFile(file,
2088 "-------------------------------------------------"
2089 "------------------------------\n");
2091 path=delegate_info[i]->path;
2093 if (delegate_info[i]->encode != (
char *) NULL)
2094 (
void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
2095 (void) ConcatenateMagickString(delegate,
" ",MaxTextExtent);
2097 commands=StringToList(delegate_info[i]->commands);
2098 if (commands == (
char **) NULL)
2100 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2101 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2102 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2103 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2104 for (j=1; commands[j] != (
char *) NULL; j++)
2105 (
void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2106 for (j=0; commands[j] != (
char *) NULL; j++)
2107 commands[j]=DestroyString(commands[j]);
2108 commands=(
char **) RelinquishMagickMemory(commands);
2110 (void) fflush(file);
2112 RelinquishMagickMemory((
void *) delegate_info);
2147 static MagickBooleanType LoadDelegateCache(
LinkedListInfo *cache,
2148 const char *xml,
const char *filename,
const size_t depth,
2152 keyword[MaxTextExtent],
2170 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2171 "Loading delegate configuration file \"%s\" ...",filename);
2172 if (xml == (
const char *) NULL)
2173 return(MagickFalse);
2176 token=AcquireString(xml);
2177 extent=strlen(token)+MaxTextExtent;
2178 for (q=(
const char *) xml; *q !=
'\0'; )
2183 (void) GetNextToken(q,&q,extent,token);
2186 (void) CopyMagickString(keyword,token,MaxTextExtent);
2187 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2192 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2193 (
void) GetNextToken(q,&q,extent,token);
2196 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2201 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2202 (void) GetNextToken(q,&q,extent,token);
2205 if (LocaleCompare(keyword,
"<include") == 0)
2210 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2212 (void) CopyMagickString(keyword,token,MaxTextExtent);
2213 (void) GetNextToken(q,&q,extent,token);
2216 (void) GetNextToken(q,&q,extent,token);
2217 if (LocaleCompare(keyword,
"file") == 0)
2219 if (depth > MagickMaxRecursionDepth)
2220 (void) ThrowMagickException(exception,GetMagickModule(),
2221 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2225 path[MaxTextExtent],
2228 GetPathComponent(filename,HeadPath,path);
2230 (void) ConcatenateMagickString(path,DirectorySeparator,
2232 if (*token == *DirectorySeparator)
2233 (void) CopyMagickString(path,token,MaxTextExtent);
2235 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
2236 xml=FileToXML(path,~0UL);
2237 if (xml != (
char *) NULL)
2239 status&=LoadDelegateCache(cache,xml,path,depth+1,
2241 xml=(
char *) RelinquishMagickMemory(xml);
2248 if (LocaleCompare(keyword,
"<delegate") == 0)
2254 sizeof(*delegate_info));
2256 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
2257 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2258 delegate_info->path=ConstantString(filename);
2259 delegate_info->thread_support=MagickTrue;
2260 delegate_info->signature=MagickCoreSignature;
2265 if ((LocaleCompare(keyword,
"/>") == 0) ||
2266 (LocaleCompare(keyword,
"</policy>") == 0))
2268 status=AppendValueToLinkedList(cache,delegate_info);
2269 if (status == MagickFalse)
2270 (void) ThrowMagickException(exception,GetMagickModule(),
2271 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2272 delegate_info->commands);
2276 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2279 (void) GetNextToken(q,&q,extent,token);
2280 (void) GetNextToken(q,&q,extent,token);
2286 if (LocaleCompare((
char *) keyword,
"command") == 0)
2291 commands=AcquireString(token);
2292 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2293 if (strchr(commands,
'@') != (
char *) NULL)
2296 path[MaxTextExtent];
2298 NTGhostscriptEXE(path,MaxTextExtent);
2299 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2301 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2304 (void) SubstituteString((
char **) &commands,
""",
"\"");
2305 (void) SubstituteString((
char **) &commands,
"'",
"'");
2306 (void) SubstituteString((
char **) &commands,
"&",
"&");
2307 (void) SubstituteString((
char **) &commands,
">",
">");
2308 (void) SubstituteString((
char **) &commands,
"<",
"<");
2309 if (delegate_info->commands != (
char *) NULL)
2310 delegate_info->commands=DestroyString(delegate_info->commands);
2311 delegate_info->commands=commands;
2319 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2321 delegate_info->decode=ConstantString(token);
2322 delegate_info->mode=1;
2330 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2332 delegate_info->encode=ConstantString(token);
2333 delegate_info->mode=(-1);
2341 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2343 delegate_info->mode=1;
2344 if (LocaleCompare(token,
"bi") == 0)
2345 delegate_info->mode=0;
2347 if (LocaleCompare(token,
"encode") == 0)
2348 delegate_info->mode=(-1);
2356 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2358 delegate_info->spawn=IsMagickTrue(token);
2361 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2363 delegate_info->stealth=IsMagickTrue(token);
2371 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2373 delegate_info->thread_support=IsMagickTrue(token);
2374 if (delegate_info->thread_support == MagickFalse)
2375 delegate_info->semaphore=AllocateSemaphoreInfo();
2384 token=(
char *) RelinquishMagickMemory(token);
2385 return(status != 0 ? MagickTrue : MagickFalse);