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 ((number_arguments <= 1) || (arguments[1] == (
char *) NULL) ||
419 (*arguments[1] ==
'\0'))
421 for (i=0; i < (ssize_t) number_arguments; i++)
422 arguments[i]=DestroyString(arguments[i]);
423 arguments=(
char **) RelinquishMagickMemory(arguments);
426 rights=ExecutePolicyRights;
427 domain=DelegatePolicyDomain;
428 for (i=1; i < (ssize_t) number_arguments; i++)
430 if ((i != 1) && (IsExecutableToken(arguments[i]) == MagickFalse))
432 if (IsRightsAuthorized(domain,rights,arguments[i]) == MagickFalse)
438 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
439 "NotAuthorized",
"`%s'",arguments[i]);
440 for (j=0; j < (ssize_t) number_arguments; j++)
441 arguments[j]=DestroyString(arguments[j]);
442 arguments=(
char **) RelinquishMagickMemory(arguments);
446 if (verbose != MagickFalse)
448 (void) FormatLocaleFile(stderr,
"%s\n",command);
449 (void) fflush(stderr);
451 sanitize_command=SanitizeString(command);
452 if (asynchronous != MagickFalse)
453 (void) ConcatenateMagickString(sanitize_command,
"&",MagickPathExtent);
454 if (message != (
char *) NULL)
456#if defined(MAGICKCORE_POSIX_SUPPORT)
457#if defined(MAGICKCORE_HAVE_POPEN)
458 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
461 buffer[MagickPathExtent];
466 file=popen_utf8(sanitize_command,
"r");
467 if (file == (FILE *) NULL)
468 status=system(sanitize_command);
474 while (fgets(buffer,(
int)
sizeof(buffer),file) != NULL)
480 length=strlen(buffer);
481 count=MagickMin(length,MagickPathExtent-offset-1);
484 (void) memcpy(message+offset,buffer,count);
486 message[offset]=
'\0';
495#if !defined(MAGICKCORE_HAVE_EXECVP)
496 status=system(sanitize_command);
498 if ((asynchronous != MagickFalse) ||
499 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
500 status=system(sanitize_command);
509 child_pid=(pid_t) fork();
510 if (child_pid == (pid_t) -1)
511 status=system(sanitize_command);
515 status=execvp(arguments[1],arguments+1);
527 pid=(pid_t) waitpid(child_pid,&child_status,0);
532 if (WIFEXITED(child_status) != 0)
533 status=WEXITSTATUS(child_status);
535 if (WIFSIGNALED(child_status))
542#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
555 p=strstr(sanitize_command,
"cmd.exe /c");
556 if (p != (
char*) NULL)
559 for ( ; *p !=
'\0'; p++)
561 *p=(*DirectorySeparator);
564 status=NTSystemCommand(sanitize_command,message);
566 status=system(sanitize_command);
568# error No suitable system() method.
572 if ((message != (
char *) NULL) && (*message !=
'\0'))
573 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
574 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
576 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
577 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
579 sanitize_command=DestroyString(sanitize_command);
580 for (i=0; i < (ssize_t) number_arguments; i++)
581 arguments[i]=DestroyString(arguments[i]);
582 arguments=(
char **) RelinquishMagickMemory(arguments);
624static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
625 const char letter,ExceptionInfo *exception)
627#define WarnNoImageReturn(format,letter) \
628 if (image == (Image *) NULL) \
630 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
631 "NoImageForProperty",format,letter); \
634#define WarnNoImageInfoReturn(format,letter) \
635 if (image_info == (ImageInfo *) NULL) \
637 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
638 "NoImageInfoForProperty",format,letter); \
643 value[MagickPathExtent];
648 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
649 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
651 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
652 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-images");
657 string=(
const char *) value;
662 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
663 string=GetImageOption(image_info,
"authenticate");
668 WarnNoImageReturn(
"\"%%%c\"",letter);
669 (void) FormatMagickSize(image->extent,MagickFalse,
"B",MagickPathExtent,
671 if (image->extent == 0)
672 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,
"B",
673 MagickPathExtent,value);
678 WarnNoImageReturn(
"\"%%%c\"",letter);
679 GetPathComponent(image->magick_filename,HeadPath,value);
684 WarnNoImageReturn(
"\"%%%c\"",letter);
685 GetPathComponent(image->magick_filename,ExtensionPath,value);
690 WarnNoImageReturn(
"\"%%%c\"",letter);
691 GetPathComponent(image->magick_filename,TailPath,value);
696 WarnNoImageReturn(
"\"%%%c\"",letter);
697 (void) FormatLocaleString(value,MagickPathExtent,
698 "%.17gx%.17g%+.20g%+.20g",(
double) image->page.width,(
double)
699 image->page.height,(
double) image->page.x,(
double) image->page.y);
704 WarnNoImageReturn(
"\"%%%c\"",letter);
705 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
706 (image->rows != 0 ? image->rows : image->magick_rows));
711 WarnNoImageReturn(
"\"%%%c\"",letter);
712 string=image->filename;
717 WarnNoImageReturn(
"\"%%%c\"",letter);
718 string=image->magick;
723 if (image != (Image *) NULL)
724 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
725 GetImageListLength(image));
730 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
731 string=image_info->filename;
736 WarnNoImageReturn(
"\"%%%c\"",letter);
737 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
738 GetImageIndexInList(image));
743 WarnNoImageReturn(
"\"%%%c\"",letter);
744 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
745 MAGICKCORE_QUANTUM_DEPTH);
753 WarnNoImageReturn(
"\"%%%c\"",letter);
754 colorspace=image->colorspace;
755 (void) FormatLocaleString(value,MagickPathExtent,
"%s %s %s",
756 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
757 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
758 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
764 WarnNoImageReturn(
"\"%%%c\"",letter);
765 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
771 WarnNoImageReturn(
"\"%%%c\"",letter);
772 GetPathComponent(image->magick_filename,BasePath,value);
777 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
778 string=image_info->unique;
783 WarnNoImageReturn(
"\"%%%c\"",letter);
784 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
785 (image->columns != 0 ? image->columns : image->magick_columns));
790 WarnNoImageReturn(
"\"%%%c\"",letter);
791 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
792 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
793 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
799 WarnNoImageReturn(
"\"%%%c\"",letter);
800 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
801 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
802 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
808 WarnNoImageReturn(
"\"%%%c\"",letter);
809 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
810 (
double) image->depth);
815 WarnNoImageReturn(
"\"%%%c\"",letter);
816 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
822 WarnNoImageReturn(
"\"%%%c\"",letter);
823 string=CommandOptionToMnemonic(MagickCompressOptions,
824 (ssize_t) image->compression);
829 WarnNoImageReturn(
"\"%%%c\"",letter);
830 string=CommandOptionToMnemonic(MagickDisposeOptions,
831 (ssize_t) image->dispose);
839 WarnNoImageReturn(
"\"%%%c\"",letter);
840 (void) CopyMagickString(value,image->magick_filename,MagickPathExtent);
845 WarnNoImageReturn(
"\"%%%c\"",letter);
846 (void) FormatLocaleString(value,MagickPathExtent,
"%.17gx%.17g",
847 (
double) image->magick_columns,(
double) image->magick_rows);
852 WarnNoImageReturn(
"\"%%%c\"",letter);
853 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",
854 (
double) image->page.height);
859 WarnNoImageReturn(
"\"%%%c\"",letter);
860 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
866 WarnNoImageReturn(
"\"%%%c\"",letter);
867 string=image->magick_filename;
872 WarnNoImageReturn(
"\"%%%c\"",letter);
873 (void) FormatLocaleString(value,MagickPathExtent,
"%+ld%+ld",(
long)
874 image->page.x,(
long) image->page.y);
879 WarnNoImageReturn(
"\"%%%c\"",letter);
880 (void) FormatLocaleString(value,MagickPathExtent,
"%.17gx%.17g",
881 (
double) image->page.width,(
double) image->page.height);
886 WarnNoImageReturn(
"\"%%%c\"",letter);
887 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
888 (100-(image->quality == 0 ? 42 : image->quality))/2);
893 WarnNoImageReturn(
"\"%%%c\"",letter);
894 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
895 (image->quality == 0 ? 92 : image->quality));
900 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
901 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
902 (image_info->number_scenes == 0 ? 2147483647 :
903 image_info->number_scenes));
908 WarnNoImageReturn(
"\"%%%c\"",letter);
909 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
915 WarnNoImageReturn(
"\"%%%c\"",letter);
916 string=CommandOptionToMnemonic(MagickResolutionOptions,
917 (ssize_t) image->units);
922 WarnNoImageReturn(
"\"%%%c\"",letter);
923 (void) FormatLocaleString(value,MagickPathExtent,
"%.17g",(
double)
929 WarnNoImageReturn(
"\"%%%c\"",letter);
930 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
936 WarnNoImageReturn(
"\"%%%c\"",letter);
937 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
951 WarnNoImageReturn(
"\"%%%c\"",letter);
952 page=GetImageBoundingBox(image,exception);
953 (void) FormatLocaleString(value,MagickPathExtent,
954 "%.17gx%.17g%+.20g%+.20g",(
double) page.width,(
double) page.height,
955 (
double) page.x,(
double) page.y);
963 WarnNoImageReturn(
"\"%%%c\"",letter);
964 (void) SignatureImage(image,exception);
965 string=GetImageProperty(image,
"signature",exception);
969 return(SanitizeDelegateString(
string));
972static char *InterpretDelegateProperties(ImageInfo *image_info,
973 Image *image,
const char *embed_text,ExceptionInfo *exception)
975#define ExtendInterpretText(string_length) \
977 size_t length=(string_length); \
978 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
981 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
982 MagickPathExtent,sizeof(*interpret_text)); \
983 if (interpret_text == (char *) NULL) \
984 return((char *) NULL); \
985 q=interpret_text+strlen(interpret_text); \
989#define AppendKeyValue2Text(key,value)\
991 size_t length=strlen(key)+strlen(value)+2; \
992 if ((size_t) (q-interpret_text+length+1) >= extent) \
995 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
996 MagickPathExtent,sizeof(*interpret_text)); \
997 if (interpret_text == (char *) NULL) \
998 return((char *) NULL); \
999 q=interpret_text+strlen(interpret_text); \
1001 q+=(ptrdiff_t) FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
1004#define AppendString2Text(string) \
1006 size_t length=strlen((string)); \
1007 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
1010 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1011 MagickPathExtent,sizeof(*interpret_text)); \
1012 if (interpret_text == (char *) NULL) \
1013 return((char *) NULL); \
1014 q=interpret_text+strlen(interpret_text); \
1016 (void) CopyMagickString(q,(string),extent); \
1017 q+=(ptrdiff_t) length; \
1036 assert(image == NULL || image->signature == MagickCoreSignature);
1037 assert(image_info == NULL || image_info->signature == MagickCoreSignature);
1038 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
1039 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1041 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
1042 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-image");
1043 if (embed_text == (
const char *) NULL)
1044 return(ConstantString(
""));
1046 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1049 return(ConstantString(
""));
1053 interpret_text=AcquireString(embed_text);
1054 extent=MagickPathExtent;
1056 for (q=interpret_text; *p!=
'\0';
1057 number=isdigit((
int) ((
unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
1063 ExtendInterpretText(MagickPathExtent);
1106 if (LocaleNCompare(
"<",p,4) == 0)
1112 if (LocaleNCompare(
">",p,4) == 0)
1118 if (LocaleNCompare(
"&",p,5) == 0)
1139 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1149 if (number != MagickFalse)
1158 string=GetMagickPropertyLetter(image_info,image,*p,exception);
1159 if (
string != (
char *) NULL)
1161 AppendString2Text(
string);
1162 string=DestroyString(
string);
1165 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1166 "UnknownImageProperty",
"\"%%%c\"",*p);
1169 return(interpret_text);
1172MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,Image *image,
1173 const char *decode,
const char *encode,ExceptionInfo *exception)
1185 assert(image_info != (ImageInfo *) NULL);
1186 assert(image_info->signature == MagickCoreSignature);
1187 assert(image != (Image *) NULL);
1188 assert(image->signature == MagickCoreSignature);
1189 if (IsEventLogging() != MagickFalse)
1190 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1191 delegate_info=GetDelegateInfo(decode,encode,exception);
1192 if (delegate_info == (
const DelegateInfo *) NULL)
1194 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1195 "NoTagFound",
"`%s'",decode ? decode : encode);
1196 return((
char *) NULL);
1198 commands=StringToList(delegate_info->commands);
1199 if (commands == (
char **) NULL)
1201 (void) ThrowMagickException(exception,GetMagickModule(),
1202 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",decode ? decode :
1204 return((
char *) NULL);
1206 command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1207 commands[0],exception);
1208 if (command == (
char *) NULL)
1209 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1210 "MemoryAllocationFailed",
"`%s'",commands[0]);
1214 for (i=0; commands[i] != (
char *) NULL; i++)
1215 commands[i]=DestroyString(commands[i]);
1216 commands=(
char **) RelinquishMagickMemory(commands);
1242MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1244 if (IsEventLogging() != MagickFalse)
1245 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1246 assert(delegate_info != (DelegateInfo *) NULL);
1247 assert(delegate_info->signature == MagickCoreSignature);
1248 return(delegate_info->commands);
1280MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1281 const char *encode,ExceptionInfo *exception)
1289 assert(exception != (ExceptionInfo *) NULL);
1290 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1291 return((
const DelegateInfo *) NULL);
1295 delegate_info=(
const DelegateInfo *) NULL;
1296 LockSemaphoreInfo(delegate_semaphore);
1297 p=GetHeadElementInLinkedList(delegate_cache);
1298 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1300 UnlockSemaphoreInfo(delegate_semaphore);
1301 if (p != (ElementInfo *) NULL)
1302 delegate_info=(
const DelegateInfo* ) p->value;
1303 return(delegate_info);
1305 while (p != (ElementInfo *) NULL)
1307 delegate_info=(
const DelegateInfo* ) p->value;
1308 if (delegate_info->mode > 0)
1310 if (LocaleCompare(delegate_info->decode,decode) == 0)
1315 if (delegate_info->mode < 0)
1317 if (LocaleCompare(delegate_info->encode,encode) == 0)
1322 if (LocaleCompare(decode,delegate_info->decode) == 0)
1323 if (LocaleCompare(encode,delegate_info->encode) == 0)
1325 if (LocaleCompare(decode,
"*") == 0)
1326 if (LocaleCompare(encode,delegate_info->encode) == 0)
1328 if (LocaleCompare(decode,delegate_info->decode) == 0)
1329 if (LocaleCompare(encode,
"*") == 0)
1333 if (p == (ElementInfo *) NULL)
1334 delegate_info=(
const DelegateInfo *) NULL;
1336 SetHeadElementInLinkedList(delegate_cache,p);
1337 UnlockSemaphoreInfo(delegate_semaphore);
1338 return(delegate_info);
1370#if defined(__cplusplus) || defined(c_plusplus)
1374static int DelegateInfoCompare(
const void *x,
const void *y)
1383 p=(
const DelegateInfo **) x,
1384 q=(
const DelegateInfo **) y;
1385 cmp=LocaleCompare((*p)->path,(*q)->path);
1388 if ((*p)->decode == (
char *) NULL)
1389 if (((*p)->encode != (
char *) NULL) &&
1390 ((*q)->encode != (
char *) NULL))
1391 return(strcmp((*p)->encode,(*q)->encode));
1392 if (((*p)->decode != (
char *) NULL) &&
1393 ((*q)->decode != (
char *) NULL))
1394 return(strcmp((*p)->decode,(*q)->decode));
1399#if defined(__cplusplus) || defined(c_plusplus)
1403MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1404 size_t *number_delegates,ExceptionInfo *exception)
1415 assert(number_delegates != (
size_t *) NULL);
1416 assert(pattern != (
char *) NULL);
1417 if (IsEventLogging() != MagickFalse)
1418 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1419 *number_delegates=0;
1420 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1421 return((
const DelegateInfo **) NULL);
1422 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1423 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1424 if (delegates == (
const DelegateInfo **) NULL)
1425 return((
const DelegateInfo **) NULL);
1426 LockSemaphoreInfo(delegate_semaphore);
1427 p=GetHeadElementInLinkedList(delegate_cache);
1428 for (i=0; p != (ElementInfo *) NULL; )
1433 delegate_info=(
const DelegateInfo *) p->value;
1434 if( (delegate_info->stealth == MagickFalse) &&
1435 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse ||
1436 GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1437 delegates[i++]=delegate_info;
1440 UnlockSemaphoreInfo(delegate_semaphore);
1442 delegates=(
const DelegateInfo **) RelinquishMagickMemory((
void*) delegates);
1445 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1446 delegates[i]=(DelegateInfo *) NULL;
1448 *number_delegates=(size_t) i;
1482#if defined(__cplusplus) || defined(c_plusplus)
1486static int DelegateCompare(
const void *x,
const void *y)
1492 p=(
const char **) x;
1493 q=(
const char **) y;
1494 return(LocaleCompare(*p,*q));
1497#if defined(__cplusplus) || defined(c_plusplus)
1501MagickExport
char **GetDelegateList(
const char *pattern,
1502 size_t *number_delegates,ExceptionInfo *exception)
1513 assert(pattern != (
char *) NULL);
1514 if (IsEventLogging() != MagickFalse)
1515 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1516 assert(number_delegates != (
size_t *) NULL);
1517 *number_delegates=0;
1518 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1519 return((
char **) NULL);
1520 delegates=(
char **) AcquireQuantumMemory((
size_t)
1521 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1522 if (delegates == (
char **) NULL)
1523 return((
char **) NULL);
1524 LockSemaphoreInfo(delegate_semaphore);
1525 p=GetHeadElementInLinkedList(delegate_cache);
1526 for (i=0; p != (ElementInfo *) NULL; )
1531 delegate_info=(
const DelegateInfo *) p->value;
1532 if ((delegate_info->stealth == MagickFalse) &&
1533 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse))
1534 delegates[i++]=ConstantString(delegate_info->decode);
1535 if ((delegate_info->stealth == MagickFalse) &&
1536 (GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1537 delegates[i++]=ConstantString(delegate_info->encode);
1540 UnlockSemaphoreInfo(delegate_semaphore);
1542 delegates=(
char **) RelinquishMagickMemory(delegates);
1545 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1546 delegates[i]=(
char *) NULL;
1548 *number_delegates=(size_t) i;
1574MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1576 if (IsEventLogging() != MagickFalse)
1577 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1578 assert(delegate_info != (DelegateInfo *) NULL);
1579 assert(delegate_info->signature == MagickCoreSignature);
1580 return(delegate_info->mode);
1607MagickExport MagickBooleanType GetDelegateThreadSupport(
1608 const DelegateInfo *delegate_info)
1610 assert(delegate_info != (DelegateInfo *) NULL);
1611 assert(delegate_info->signature == MagickCoreSignature);
1612 if (IsEventLogging() != MagickFalse)
1613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1614 return(delegate_info->thread_support);
1640static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1642 if (delegate_cache == (LinkedListInfo *) NULL)
1645 ActivateSemaphoreInfo(&delegate_semaphore);
1646 LockSemaphoreInfo(delegate_semaphore);
1647 if (delegate_cache == (LinkedListInfo *) NULL)
1648 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1649 UnlockSemaphoreInfo(delegate_semaphore);
1651 return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1684static MagickBooleanType CopyDelegateFile(
const char *source,
1685 const char *destination,
const MagickBooleanType overwrite,
1686 ExceptionInfo *exception)
1689 destination_file = -1,
1693 status = MagickTrue;
1710 assert(source != (
const char *) NULL);
1711 assert(destination != (
char *) NULL);
1712 if ((overwrite == MagickFalse) &&
1713 (GetPathAttributes(destination,&attributes) != MagickFalse))
1715 if (IsPathAuthorized(WritePolicyRights,destination) == MagickFalse)
1716 ThrowPolicyException(source,MagickFalse);
1717 destination_file=open_utf8(destination,O_WRONLY | O_CLOEXEC | O_BINARY |
1718 O_CREAT | O_NOFOLLOW | (overwrite != MagickFalse ? O_TRUNC : 0),S_MODE);
1719 if (destination_file == -1)
1720 return(MagickFalse);
1721 if (IsPathAuthorized(WritePolicyRights,destination) == MagickFalse)
1722 ThrowPolicyException(destination,MagickFalse);
1723 if (IsPathAuthorized(ReadPolicyRights,source) == MagickFalse)
1725 (void) close_utf8(destination_file);
1726 ThrowPolicyException(source,MagickFalse);
1728 source_file=open_utf8(source,O_RDONLY | O_CLOEXEC | O_BINARY,0);
1729 if (source_file == -1)
1731 (void) close_utf8(destination_file);
1732 return(MagickFalse);
1734 quantum=(size_t) MagickMaxBufferExtent;
1735 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1736 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1737 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1738 if (buffer == (
unsigned char *) NULL)
1740 (void) close_utf8(source_file);
1741 (void) close_utf8(destination_file);
1742 return(MagickFalse);
1744 while ((count=read(source_file,buffer,quantum)) > 0)
1749 while (offset < count)
1754 written=write(destination_file,buffer+offset,(
size_t) (count-offset));
1769 if (status == MagickFalse)
1774 (void) close_utf8(destination_file);
1775 (void) close_utf8(source_file);
1776 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1780MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
1781 Image *image,
const char *decode,
const char *encode,ExceptionInfo *exception)
1786 input_filename[MagickPathExtent],
1787 output_filename[MagickPathExtent];
1805 assert(image_info != (ImageInfo *) NULL);
1806 assert(image_info->signature == MagickCoreSignature);
1807 assert(image != (Image *) NULL);
1808 assert(image->signature == MagickCoreSignature);
1809 if (IsEventLogging() != MagickFalse)
1810 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1811 rights=ExecutePolicyRights;
1812 if ((decode != (
const char *) NULL) &&
1813 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1814 ThrowPolicyException(decode,MagickFalse);
1815 if ((encode != (
const char *) NULL) &&
1816 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1817 ThrowPolicyException(encode,MagickFalse);
1818 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1819 if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1822 ThrowFileException(exception,FileOpenError,
"UnableToCreateTemporaryFile",
1824 return(MagickFalse);
1826 delegate_info=GetDelegateInfo(decode,encode,exception);
1827 if (delegate_info == (DelegateInfo *) NULL)
1829 if (temporary != MagickFalse)
1830 (void) RelinquishUniqueFileResource(image->filename);
1831 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1832 "NoTagFound",
"`%s'",decode ? decode : encode);
1833 return(MagickFalse);
1835 if (*image_info->filename ==
'\0')
1837 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1839 if (temporary != MagickFalse)
1840 (void) RelinquishUniqueFileResource(image->filename);
1841 ThrowFileException(exception,FileOpenError,
1842 "UnableToCreateTemporaryFile",image_info->filename);
1843 return(MagickFalse);
1845 image_info->temporary=MagickTrue;
1847 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1848 (delegate_info->encode != (
char *) NULL)) ||
1849 ((encode != (
const char *) NULL) &&
1850 (delegate_info->decode != (
char *) NULL))))
1864 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1866 ThrowFileException(exception,FileOpenError,
1867 "UnableToCreateTemporaryFile",image_info->unique);
1868 return(MagickFalse);
1870 magick=InterpretImageProperties(image_info,image,decode != (
char *) NULL ?
1871 delegate_info->encode : delegate_info->decode,exception);
1872 if (magick == (
char *) NULL)
1874 (void) RelinquishUniqueFileResource(image_info->unique);
1875 if (temporary != MagickFalse)
1876 (void) RelinquishUniqueFileResource(image->filename);
1877 (void) ThrowMagickException(exception,GetMagickModule(),
1878 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1879 return(MagickFalse);
1881 LocaleUpper(magick);
1882 clone_info=CloneImageInfo(image_info);
1883 (void) CopyMagickString((
char *) clone_info->magick,magick,
1885 if (LocaleCompare(magick,
"NULL") != 0)
1886 (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1887 magick=DestroyString(magick);
1888 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
"%s:",
1889 delegate_info->decode);
1890 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1892 (void) CopyMagickString(clone_info->filename,image_info->filename,
1894 (void) CopyMagickString(image_info->filename,image->filename,
1896 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1898 (void) FormatLocaleString(p->filename,MagickPathExtent,
"%s:%s",
1899 delegate_info->decode,clone_info->filename);
1900 status=WriteImage(clone_info,p,exception);
1901 if (status == MagickFalse)
1903 (void) RelinquishUniqueFileResource(image_info->unique);
1904 if (temporary != MagickFalse)
1905 (void) RelinquishUniqueFileResource(image->filename);
1906 clone_info=DestroyImageInfo(clone_info);
1907 (void) ThrowMagickException(exception,GetMagickModule(),
1908 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1909 return(MagickFalse);
1911 if (clone_info->adjoin != MagickFalse)
1914 (void) RelinquishUniqueFileResource(image_info->unique);
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,
1934 (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1935 for (i=0; commands[i] != (
char *) NULL; i++)
1937 (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1938 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1940 ThrowFileException(exception,FileOpenError,
1941 "UnableToCreateTemporaryFile",image_info->unique);
1944 if (IsPathAccessible(input_filename) != MagickFalse)
1946 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1947 if (status == MagickFalse)
1949 ThrowFileException(exception,FileOpenError,
1950 "UnableToCreateTemporaryFile",input_filename);
1955 command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1956 if (command != (
char *) NULL)
1961 if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,command,(
char *) NULL,exception) != 0)
1963 if (delegate_info->spawn != MagickFalse)
1972 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1973 (void) MagickDelay(100);
1975 command=DestroyString(command);
1977 if (IsPathAccessible(input_filename) != MagickFalse)
1979 if (CopyDelegateFile(image->filename,input_filename,MagickFalse,exception) == MagickFalse)
1981 (void) RelinquishUniqueFileResource(input_filename);
1985 if ((strcmp(input_filename,output_filename) != 0) &&
1986 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue,exception) == MagickFalse))
1988 (void) RelinquishUniqueFileResource(output_filename);
1991 if (image_info->temporary != MagickFalse)
1992 (void) RelinquishUniqueFileResource(image_info->filename);
1993 (void) RelinquishUniqueFileResource(image_info->unique);
1994 (void) RelinquishUniqueFileResource(image_info->filename);
1995 (void) RelinquishUniqueFileResource(image->filename);
1996 if (status == MagickFalse)
1998 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1999 "DelegateFailed",
"`%s'",commands[i]);
2002 commands[i]=DestroyString(commands[i]);
2004 (void) CopyMagickString(image_info->filename,output_filename,
2006 (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
2010 for ( ; commands[i] != (
char *) NULL; i++)
2011 commands[i]=DestroyString(commands[i]);
2012 commands=(
char **) RelinquishMagickMemory(commands);
2013 if (temporary != MagickFalse)
2014 (void) RelinquishUniqueFileResource(image->filename);
2042MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2043 ExceptionInfo *exception)
2050 delegate[MagickPathExtent];
2064 if (file == (
const FILE *) NULL)
2066 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2067 if (delegate_info == (
const DelegateInfo **) NULL)
2068 return(MagickFalse);
2069 path=(
const char *) NULL;
2070 for (i=0; i < (ssize_t) number_delegates; i++)
2072 if (delegate_info[i]->stealth != MagickFalse)
2074 if ((path == (
const char *) NULL) ||
2075 (LocaleCompare(path,delegate_info[i]->path) != 0))
2077 if (delegate_info[i]->path != (
char *) NULL)
2078 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2079 (void) FormatLocaleFile(file,
"Delegate Command\n");
2080 (void) FormatLocaleFile(file,
2081 "-------------------------------------------------"
2082 "------------------------------\n");
2084 path=delegate_info[i]->path;
2086 if (delegate_info[i]->encode != (
char *) NULL)
2087 (void) CopyMagickString(delegate,delegate_info[i]->encode,
2089 (void) ConcatenateMagickString(delegate,
" ",MagickPathExtent);
2091 commands=StringToList(delegate_info[i]->commands);
2092 if (commands == (
char **) NULL)
2094 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2095 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2096 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2097 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2098 for (j=1; commands[j] != (
char *) NULL; j++)
2099 (
void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2100 for (j=0; commands[j] != (
char *) NULL; j++)
2101 commands[j]=DestroyString(commands[j]);
2102 commands=(
char **) RelinquishMagickMemory(commands);
2104 (void) fflush(file);
2105 delegate_info=(
const DelegateInfo **)
2106 RelinquishMagickMemory((
void *) delegate_info);
2141static MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
2142 const char *xml,
const char *filename,
const size_t depth,
2143 ExceptionInfo *exception)
2146 keyword[MagickPathExtent],
2164 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2165 "Loading delegate configuration file \"%s\" ...",filename);
2166 if (xml == (
const char *) NULL)
2167 return(MagickFalse);
2169 delegate_info=(DelegateInfo *) NULL;
2170 token=AcquireString(xml);
2171 extent=strlen(token)+MagickPathExtent;
2172 for (q=(
const char *) xml; *q !=
'\0'; )
2177 if (SkipXMLComment(&q) == MagickFalse)
2179 (void) ThrowMagickException(exception,GetMagickModule(),
2180 ConfigureError,
"UnterminatedComment",
"`%s'",filename);
2184 (void) GetNextToken(q,&q,extent,token);
2187 (void) CopyMagickString(keyword,token,MagickPathExtent);
2188 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2190 if (SkipXMLDocType(&q) == MagickFalse)
2195 (void) ThrowMagickException(exception,GetMagickModule(),
2196 ConfigureError,
"UnterminatedDOCTYPE",
"`%s'",filename);
2202 if (LocaleCompare(keyword,
"<include") == 0)
2207 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2209 (void) CopyMagickString(keyword,token,MagickPathExtent);
2210 (void) GetNextToken(q,&q,extent,token);
2213 (void) GetNextToken(q,&q,extent,token);
2214 if (LocaleCompare(keyword,
"file") == 0)
2216 if (depth >= MagickMaxRecursionDepth)
2217 (void) ThrowMagickException(exception,GetMagickModule(),
2218 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2222 path[MagickPathExtent],
2225 GetPathComponent(filename,HeadPath,path);
2227 (void) ConcatenateMagickString(path,DirectorySeparator,
2229 if (*token == *DirectorySeparator)
2230 (void) CopyMagickString(path,token,MagickPathExtent);
2232 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
2233 file_xml=FileToXML(path,~0UL);
2234 if (file_xml != (
char *) NULL)
2236 if (LoadDelegateCache(cache,file_xml,path,depth+1,exception) == MagickFalse)
2238 file_xml=DestroyString(file_xml);
2239 if (status == MagickFalse)
2245 if (status == MagickFalse)
2249 if (LocaleCompare(keyword,
"<delegate") == 0)
2254 delegate_info=(DelegateInfo *) AcquireCriticalMemory(
2255 sizeof(*delegate_info));
2256 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2257 delegate_info->path=ConstantString(filename);
2258 delegate_info->thread_support=MagickTrue;
2259 delegate_info->signature=MagickCoreSignature;
2262 if (delegate_info == (DelegateInfo *) NULL)
2264 if ((LocaleCompare(keyword,
"/>") == 0) ||
2265 (LocaleCompare(keyword,
"</policy>") == 0))
2267 status=AppendValueToLinkedList(cache,delegate_info);
2268 if (status == MagickFalse)
2269 (void) ThrowMagickException(exception,GetMagickModule(),
2270 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2271 delegate_info->commands);
2272 delegate_info=(DelegateInfo *) NULL;
2275 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2278 (void) GetNextToken(q,&q,extent,token);
2279 (void) GetNextToken(q,&q,extent,token);
2285 if (LocaleCompare((
char *) keyword,
"command") == 0)
2290 commands=AcquireString(token);
2291#if defined(MAGICKCORE_WINDOWS_SUPPORT)
2292 if (strchr(commands,
'@') != (
char *) NULL)
2295 path[MagickPathExtent];
2297 NTGhostscriptEXE(path,MagickPathExtent);
2298 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2300 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2303 (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 if (delegate_info->commands != (
char *) NULL)
2309 delegate_info->commands=DestroyString(delegate_info->commands);
2310 delegate_info->commands=commands;
2318 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2320 delegate_info->decode=ConstantString(token);
2321 delegate_info->mode=1;
2329 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2331 delegate_info->encode=ConstantString(token);
2332 delegate_info->mode=(-1);
2340 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2342 delegate_info->mode=1;
2343 if (LocaleCompare(token,
"bi") == 0)
2344 delegate_info->mode=0;
2346 if (LocaleCompare(token,
"encode") == 0)
2347 delegate_info->mode=(-1);
2355 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2357 delegate_info->spawn=IsStringTrue(token);
2360 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2362 delegate_info->stealth=IsStringTrue(token);
2370 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2372 delegate_info->thread_support=IsStringTrue(token);
2373 if (delegate_info->thread_support == MagickFalse)
2374 delegate_info->semaphore=AcquireSemaphoreInfo();
2383 token=(
char *) RelinquishMagickMemory(token);