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\" command=\"" DELEGATE_ESC
"curl" DELEGATE_ESC
" -s -L -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"http:%M" DELEGATE_ESC
"\"/>"
113 " <delegate decode=\"https\" command=\"" DELEGATE_ESC
"curl" DELEGATE_ESC
" -s -L -o " DELEGATE_ESC
"%o" 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);
360MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
361 const MagickBooleanType verbose,
const char *command,
char *message,
362 ExceptionInfo *exception)
382 arguments=StringToArgv(command,&number_arguments);
383 if (arguments == (
char **) NULL)
385 if (*arguments[1] ==
'\0')
387 for (i=0; i < (ssize_t) number_arguments; i++)
388 arguments[i]=DestroyString(arguments[i]);
389 arguments=(
char **) RelinquishMagickMemory(arguments);
392 rights=ExecutePolicyRights;
393 domain=DelegatePolicyDomain;
394 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
397 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
398 "NotAuthorized",
"`%s'",arguments[1]);
399 for (i=0; i < (ssize_t) number_arguments; i++)
400 arguments[i]=DestroyString(arguments[i]);
401 arguments=(
char **) RelinquishMagickMemory(arguments);
404 if (verbose != MagickFalse)
406 (void) FormatLocaleFile(stderr,
"%s\n",command);
407 (void) fflush(stderr);
409 sanitize_command=SanitizeString(command);
410 if (asynchronous != MagickFalse)
411 (void) ConcatenateMagickString(sanitize_command,
"&",MagickPathExtent);
412 if (message != (
char *) NULL)
414#if defined(MAGICKCORE_POSIX_SUPPORT)
415#if defined(MAGICKCORE_HAVE_POPEN)
416 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
421 file=popen_utf8(sanitize_command,
"r");
422 if (file == (FILE *) NULL)
423 status=system(sanitize_command);
429 while ((offset < MagickPathExtent) &&
430 (fgets(message+offset,(
int) (MagickPathExtent-offset),file) != NULL))
431 offset+=strlen(message);
438#if !defined(MAGICKCORE_HAVE_EXECVP)
439 status=system(sanitize_command);
441 if ((asynchronous != MagickFalse) ||
442 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
443 status=system(sanitize_command);
452 child_pid=(pid_t) fork();
453 if (child_pid == (pid_t) -1)
454 status=system(sanitize_command);
458 status=execvp(arguments[1],arguments+1);
470 pid=(pid_t) waitpid(child_pid,&child_status,0);
475 if (WIFEXITED(child_status) != 0)
476 status=WEXITSTATUS(child_status);
478 if (WIFSIGNALED(child_status))
485#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
498 p=strstr(sanitize_command,
"cmd.exe /c");
499 if (p != (
char*) NULL)
502 for ( ; *p !=
'\0'; p++)
504 *p=(*DirectorySeparator);
507 status=NTSystemCommand(sanitize_command,message);
509 status=system(sanitize_command);
511# error No suitable system() method.
515 if ((message != (
char *) NULL) && (*message !=
'\0'))
516 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
517 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
519 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
520 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
522 sanitize_command=DestroyString(sanitize_command);
523 for (i=0; i < (ssize_t) number_arguments; i++)
524 arguments[i]=DestroyString(arguments[i]);
525 arguments=(
char **) RelinquishMagickMemory(arguments);
567static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image,
568 const char letter,ExceptionInfo *exception)
570#define WarnNoImageReturn(format,letter) \
571 if (image == (Image *) NULL) \
573 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
574 "NoImageForProperty",format,letter); \
577#define WarnNoImageInfoReturn(format,letter) \
578 if (image_info == (ImageInfo *) NULL) \
580 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
581 "NoImageInfoForProperty",format,letter); \
586 value[MagickPathExtent];
591 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
592 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
594 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
595 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-images");
600 string=(
const char *) value;
605 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
606 string=GetImageOption(image_info,
"authenticate");
611 WarnNoImageReturn(
"\"%%%c\"",letter);
612 (void) FormatMagickSize(image->extent,MagickFalse,
"B",MagickPathExtent,
614 if (image->extent == 0)
615 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,
"B",
616 MagickPathExtent,value);
621 WarnNoImageReturn(
"\"%%%c\"",letter);
622 GetPathComponent(image->magick_filename,HeadPath,value);
627 WarnNoImageReturn(
"\"%%%c\"",letter);
628 GetPathComponent(image->magick_filename,ExtensionPath,value);
633 WarnNoImageReturn(
"\"%%%c\"",letter);
634 GetPathComponent(image->magick_filename,TailPath,value);
639 WarnNoImageReturn(
"\"%%%c\"",letter);
640 (void) FormatLocaleString(value,MagickPathExtent,
641 "%.20gx%.20g%+.20g%+.20g",(
double) image->page.width,(
double)
642 image->page.height,(
double) image->page.x,(
double) image->page.y);
647 WarnNoImageReturn(
"\"%%%c\"",letter);
648 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
649 (image->rows != 0 ? image->rows : image->magick_rows));
654 WarnNoImageReturn(
"\"%%%c\"",letter);
655 string=image->filename;
660 WarnNoImageReturn(
"\"%%%c\"",letter);
661 string=image->magick;
666 if (image != (Image *) NULL)
667 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
668 GetImageListLength(image));
673 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
674 string=image_info->filename;
679 WarnNoImageReturn(
"\"%%%c\"",letter);
680 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
681 GetImageIndexInList(image));
686 WarnNoImageReturn(
"\"%%%c\"",letter);
687 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
688 MAGICKCORE_QUANTUM_DEPTH);
696 WarnNoImageReturn(
"\"%%%c\"",letter);
697 colorspace=image->colorspace;
698 (void) FormatLocaleString(value,MagickPathExtent,
"%s %s %s",
699 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
700 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
701 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
707 WarnNoImageReturn(
"\"%%%c\"",letter);
708 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
714 WarnNoImageReturn(
"\"%%%c\"",letter);
715 GetPathComponent(image->magick_filename,BasePath,value);
720 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
721 string=image_info->unique;
726 WarnNoImageReturn(
"\"%%%c\"",letter);
727 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
728 (image->columns != 0 ? image->columns : image->magick_columns));
733 WarnNoImageReturn(
"\"%%%c\"",letter);
734 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
735 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
736 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
742 WarnNoImageReturn(
"\"%%%c\"",letter);
743 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
744 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
745 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
751 WarnNoImageReturn(
"\"%%%c\"",letter);
752 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
753 (
double) image->depth);
758 WarnNoImageReturn(
"\"%%%c\"",letter);
759 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
765 WarnNoImageReturn(
"\"%%%c\"",letter);
766 string=CommandOptionToMnemonic(MagickCompressOptions,
767 (ssize_t) image->compression);
772 WarnNoImageReturn(
"\"%%%c\"",letter);
773 string=CommandOptionToMnemonic(MagickDisposeOptions,
774 (ssize_t) image->dispose);
782 WarnNoImageReturn(
"\"%%%c\"",letter);
783 (void) CopyMagickString(value,image->magick_filename,MagickPathExtent);
788 WarnNoImageReturn(
"\"%%%c\"",letter);
789 (void) FormatLocaleString(value,MagickPathExtent,
"%.20gx%.20g",
790 (
double) image->magick_columns,(
double) image->magick_rows);
795 WarnNoImageReturn(
"\"%%%c\"",letter);
796 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
797 (
double) image->page.height);
802 WarnNoImageReturn(
"\"%%%c\"",letter);
803 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
809 WarnNoImageReturn(
"\"%%%c\"",letter);
810 string=image->magick_filename;
815 WarnNoImageReturn(
"\"%%%c\"",letter);
816 (void) FormatLocaleString(value,MagickPathExtent,
"%+ld%+ld",(
long)
817 image->page.x,(
long) image->page.y);
822 WarnNoImageReturn(
"\"%%%c\"",letter);
823 (void) FormatLocaleString(value,MagickPathExtent,
"%.20gx%.20g",
824 (
double) image->page.width,(
double) image->page.height);
829 WarnNoImageReturn(
"\"%%%c\"",letter);
830 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
831 (100-(image->quality == 0 ? 42 : image->quality))/2);
836 WarnNoImageReturn(
"\"%%%c\"",letter);
837 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
838 (image->quality == 0 ? 92 : image->quality));
843 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
844 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
845 (image_info->number_scenes == 0 ? 2147483647 :
846 image_info->number_scenes));
851 WarnNoImageReturn(
"\"%%%c\"",letter);
852 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
858 WarnNoImageReturn(
"\"%%%c\"",letter);
859 string=CommandOptionToMnemonic(MagickResolutionOptions,
860 (ssize_t) image->units);
865 WarnNoImageReturn(
"\"%%%c\"",letter);
866 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
872 WarnNoImageReturn(
"\"%%%c\"",letter);
873 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
879 WarnNoImageReturn(
"\"%%%c\"",letter);
880 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
894 WarnNoImageReturn(
"\"%%%c\"",letter);
895 page=GetImageBoundingBox(image,exception);
896 (void) FormatLocaleString(value,MagickPathExtent,
897 "%.20gx%.20g%+.20g%+.20g",(
double) page.width,(
double) page.height,
898 (
double) page.x,(
double) page.y);
906 WarnNoImageReturn(
"\"%%%c\"",letter);
907 (void) SignatureImage(image,exception);
908 string=GetImageProperty(image,
"signature",exception);
912 return(SanitizeDelegateString(
string));
915static char *InterpretDelegateProperties(ImageInfo *image_info,
916 Image *image,
const char *embed_text,ExceptionInfo *exception)
918#define ExtendInterpretText(string_length) \
920 size_t length=(string_length); \
921 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
924 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
925 MagickPathExtent,sizeof(*interpret_text)); \
926 if (interpret_text == (char *) NULL) \
927 return((char *) NULL); \
928 q=interpret_text+strlen(interpret_text); \
932#define AppendKeyValue2Text(key,value)\
934 size_t length=strlen(key)+strlen(value)+2; \
935 if ((size_t) (q-interpret_text+length+1) >= extent) \
938 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
939 MagickPathExtent,sizeof(*interpret_text)); \
940 if (interpret_text == (char *) NULL) \
941 return((char *) NULL); \
942 q=interpret_text+strlen(interpret_text); \
944 q+=(ptrdiff_t) FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
947#define AppendString2Text(string) \
949 size_t length=strlen((string)); \
950 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
953 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
954 MagickPathExtent,sizeof(*interpret_text)); \
955 if (interpret_text == (char *) NULL) \
956 return((char *) NULL); \
957 q=interpret_text+strlen(interpret_text); \
959 (void) CopyMagickString(q,(string),extent); \
960 q+=(ptrdiff_t) length; \
979 assert(image == NULL || image->signature == MagickCoreSignature);
980 assert(image_info == NULL || image_info->signature == MagickCoreSignature);
981 if ((image != (Image *) NULL) && (IsEventLogging() != MagickFalse))
982 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
984 if ((image_info != (ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
985 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-image");
986 if (embed_text == (
const char *) NULL)
987 return(ConstantString(
""));
989 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
992 return(ConstantString(
""));
996 interpret_text=AcquireString(embed_text);
997 extent=MagickPathExtent;
999 for (q=interpret_text; *p!=
'\0';
1000 number=isdigit((
int) ((
unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
1006 ExtendInterpretText(MagickPathExtent);
1049 if (LocaleNCompare(
"<",p,4) == 0)
1055 if (LocaleNCompare(
">",p,4) == 0)
1061 if (LocaleNCompare(
"&",p,5) == 0)
1082 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1092 if (number != MagickFalse)
1101 string=GetMagickPropertyLetter(image_info,image,*p,exception);
1102 if (
string != (
char *) NULL)
1104 AppendString2Text(
string);
1105 string=DestroyString(
string);
1108 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1109 "UnknownImageProperty",
"\"%%%c\"",*p);
1112 return(interpret_text);
1115MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,Image *image,
1116 const char *decode,
const char *encode,ExceptionInfo *exception)
1128 assert(image_info != (ImageInfo *) NULL);
1129 assert(image_info->signature == MagickCoreSignature);
1130 assert(image != (Image *) NULL);
1131 assert(image->signature == MagickCoreSignature);
1132 if (IsEventLogging() != MagickFalse)
1133 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1134 delegate_info=GetDelegateInfo(decode,encode,exception);
1135 if (delegate_info == (
const DelegateInfo *) NULL)
1137 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1138 "NoTagFound",
"`%s'",decode ? decode : encode);
1139 return((
char *) NULL);
1141 commands=StringToList(delegate_info->commands);
1142 if (commands == (
char **) NULL)
1144 (void) ThrowMagickException(exception,GetMagickModule(),
1145 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",decode ? decode :
1147 return((
char *) NULL);
1149 command=InterpretDelegateProperties((ImageInfo *) image_info,image,
1150 commands[0],exception);
1151 if (command == (
char *) NULL)
1152 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1153 "MemoryAllocationFailed",
"`%s'",commands[0]);
1157 for (i=0; commands[i] != (
char *) NULL; i++)
1158 commands[i]=DestroyString(commands[i]);
1159 commands=(
char **) RelinquishMagickMemory(commands);
1185MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1187 if (IsEventLogging() != MagickFalse)
1188 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1189 assert(delegate_info != (DelegateInfo *) NULL);
1190 assert(delegate_info->signature == MagickCoreSignature);
1191 return(delegate_info->commands);
1223MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1224 const char *encode,ExceptionInfo *exception)
1232 assert(exception != (ExceptionInfo *) NULL);
1233 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1234 return((
const DelegateInfo *) NULL);
1238 delegate_info=(
const DelegateInfo *) NULL;
1239 LockSemaphoreInfo(delegate_semaphore);
1240 p=GetHeadElementInLinkedList(delegate_cache);
1241 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1243 UnlockSemaphoreInfo(delegate_semaphore);
1244 if (p != (ElementInfo *) NULL)
1245 delegate_info=(
const DelegateInfo* ) p->value;
1246 return(delegate_info);
1248 while (p != (ElementInfo *) NULL)
1250 delegate_info=(
const DelegateInfo* ) p->value;
1251 if (delegate_info->mode > 0)
1253 if (LocaleCompare(delegate_info->decode,decode) == 0)
1258 if (delegate_info->mode < 0)
1260 if (LocaleCompare(delegate_info->encode,encode) == 0)
1265 if (LocaleCompare(decode,delegate_info->decode) == 0)
1266 if (LocaleCompare(encode,delegate_info->encode) == 0)
1268 if (LocaleCompare(decode,
"*") == 0)
1269 if (LocaleCompare(encode,delegate_info->encode) == 0)
1271 if (LocaleCompare(decode,delegate_info->decode) == 0)
1272 if (LocaleCompare(encode,
"*") == 0)
1276 if (p == (ElementInfo *) NULL)
1277 delegate_info=(
const DelegateInfo *) NULL;
1279 SetHeadElementInLinkedList(delegate_cache,p);
1280 UnlockSemaphoreInfo(delegate_semaphore);
1281 return(delegate_info);
1313#if defined(__cplusplus) || defined(c_plusplus)
1317static int DelegateInfoCompare(
const void *x,
const void *y)
1326 p=(
const DelegateInfo **) x,
1327 q=(
const DelegateInfo **) y;
1328 cmp=LocaleCompare((*p)->path,(*q)->path);
1331 if ((*p)->decode == (
char *) NULL)
1332 if (((*p)->encode != (
char *) NULL) &&
1333 ((*q)->encode != (
char *) NULL))
1334 return(strcmp((*p)->encode,(*q)->encode));
1335 if (((*p)->decode != (
char *) NULL) &&
1336 ((*q)->decode != (
char *) NULL))
1337 return(strcmp((*p)->decode,(*q)->decode));
1342#if defined(__cplusplus) || defined(c_plusplus)
1346MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1347 size_t *number_delegates,ExceptionInfo *exception)
1358 assert(number_delegates != (
size_t *) NULL);
1359 assert(pattern != (
char *) NULL);
1360 if (IsEventLogging() != MagickFalse)
1361 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1362 *number_delegates=0;
1363 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1364 return((
const DelegateInfo **) NULL);
1365 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1366 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1367 if (delegates == (
const DelegateInfo **) NULL)
1368 return((
const DelegateInfo **) NULL);
1369 LockSemaphoreInfo(delegate_semaphore);
1370 p=GetHeadElementInLinkedList(delegate_cache);
1371 for (i=0; p != (ElementInfo *) NULL; )
1376 delegate_info=(
const DelegateInfo *) p->value;
1377 if( (delegate_info->stealth == MagickFalse) &&
1378 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse ||
1379 GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1380 delegates[i++]=delegate_info;
1383 UnlockSemaphoreInfo(delegate_semaphore);
1385 delegates=(
const DelegateInfo **) RelinquishMagickMemory((
void*) delegates);
1388 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1389 delegates[i]=(DelegateInfo *) NULL;
1391 *number_delegates=(size_t) i;
1425#if defined(__cplusplus) || defined(c_plusplus)
1429static int DelegateCompare(
const void *x,
const void *y)
1435 p=(
const char **) x;
1436 q=(
const char **) y;
1437 return(LocaleCompare(*p,*q));
1440#if defined(__cplusplus) || defined(c_plusplus)
1444MagickExport
char **GetDelegateList(
const char *pattern,
1445 size_t *number_delegates,ExceptionInfo *exception)
1456 assert(pattern != (
char *) NULL);
1457 if (IsEventLogging() != MagickFalse)
1458 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1459 assert(number_delegates != (
size_t *) NULL);
1460 *number_delegates=0;
1461 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1462 return((
char **) NULL);
1463 delegates=(
char **) AcquireQuantumMemory((
size_t)
1464 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1465 if (delegates == (
char **) NULL)
1466 return((
char **) NULL);
1467 LockSemaphoreInfo(delegate_semaphore);
1468 p=GetHeadElementInLinkedList(delegate_cache);
1469 for (i=0; p != (ElementInfo *) NULL; )
1474 delegate_info=(
const DelegateInfo *) p->value;
1475 if ((delegate_info->stealth == MagickFalse) &&
1476 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse))
1477 delegates[i++]=ConstantString(delegate_info->decode);
1478 if ((delegate_info->stealth == MagickFalse) &&
1479 (GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1480 delegates[i++]=ConstantString(delegate_info->encode);
1483 UnlockSemaphoreInfo(delegate_semaphore);
1485 delegates=(
char **) RelinquishMagickMemory(delegates);
1488 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1489 delegates[i]=(
char *) NULL;
1491 *number_delegates=(size_t) i;
1517MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1519 if (IsEventLogging() != MagickFalse)
1520 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1521 assert(delegate_info != (DelegateInfo *) NULL);
1522 assert(delegate_info->signature == MagickCoreSignature);
1523 return(delegate_info->mode);
1550MagickExport MagickBooleanType GetDelegateThreadSupport(
1551 const DelegateInfo *delegate_info)
1553 assert(delegate_info != (DelegateInfo *) NULL);
1554 assert(delegate_info->signature == MagickCoreSignature);
1555 if (IsEventLogging() != MagickFalse)
1556 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1557 return(delegate_info->thread_support);
1583static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
1585 if (delegate_cache == (LinkedListInfo *) NULL)
1588 ActivateSemaphoreInfo(&delegate_semaphore);
1589 LockSemaphoreInfo(delegate_semaphore);
1590 if (delegate_cache == (LinkedListInfo *) NULL)
1591 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1592 UnlockSemaphoreInfo(delegate_semaphore);
1594 return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1627static MagickBooleanType CopyDelegateFile(
const char *source,
1628 const char *destination,
const MagickBooleanType overwrite,
1629 ExceptionInfo *exception)
1655 assert(source != (
const char *) NULL);
1656 assert(destination != (
char *) NULL);
1657 if (overwrite == MagickFalse)
1659 status=GetPathAttributes(destination,&attributes);
1660 if (status != MagickFalse)
1663 if (IsPathAuthorized(WritePolicyRights,destination) == MagickFalse)
1664 ThrowPolicyException(destination,MagickFalse);
1665 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1666 if (destination_file == -1)
1667 return(MagickFalse);
1668 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1669 if (source_file == -1)
1671 (void) close_utf8(destination_file);
1672 return(MagickFalse);
1674 quantum=(size_t) MagickMaxBufferExtent;
1675 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1676 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1677 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1678 if (buffer == (
unsigned char *) NULL)
1680 (void) close_utf8(source_file);
1681 (void) close_utf8(destination_file);
1682 return(MagickFalse);
1685 for (i=0; ; i+=(ssize_t) count)
1687 count=(ssize_t) read(source_file,buffer,quantum);
1690 length=(size_t) count;
1691 count=(ssize_t) write(destination_file,buffer,length);
1692 if ((
size_t) count != length)
1695 (void) close_utf8(destination_file);
1696 (void) close_utf8(source_file);
1697 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1698 return(i != 0 ? MagickTrue : MagickFalse);
1701MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
1702 Image *image,
const char *decode,
const char *encode,ExceptionInfo *exception)
1707 input_filename[MagickPathExtent],
1708 output_filename[MagickPathExtent];
1726 assert(image_info != (ImageInfo *) NULL);
1727 assert(image_info->signature == MagickCoreSignature);
1728 assert(image != (Image *) NULL);
1729 assert(image->signature == MagickCoreSignature);
1730 if (IsEventLogging() != MagickFalse)
1731 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1732 rights=ExecutePolicyRights;
1733 if ((decode != (
const char *) NULL) &&
1734 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1735 ThrowPolicyException(decode,MagickFalse);
1736 if ((encode != (
const char *) NULL) &&
1737 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1738 ThrowPolicyException(encode,MagickFalse);
1739 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1740 if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1743 ThrowFileException(exception,FileOpenError,
"UnableToCreateTemporaryFile",
1745 return(MagickFalse);
1747 delegate_info=GetDelegateInfo(decode,encode,exception);
1748 if (delegate_info == (DelegateInfo *) NULL)
1750 if (temporary != MagickFalse)
1751 (void) RelinquishUniqueFileResource(image->filename);
1752 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1753 "NoTagFound",
"`%s'",decode ? decode : encode);
1754 return(MagickFalse);
1756 if (*image_info->filename ==
'\0')
1758 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1760 if (temporary != MagickFalse)
1761 (void) RelinquishUniqueFileResource(image->filename);
1762 ThrowFileException(exception,FileOpenError,
1763 "UnableToCreateTemporaryFile",image_info->filename);
1764 return(MagickFalse);
1766 image_info->temporary=MagickTrue;
1768 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1769 (delegate_info->encode != (
char *) NULL)) ||
1770 ((encode != (
const char *) NULL) &&
1771 (delegate_info->decode != (
char *) NULL))))
1785 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1787 ThrowFileException(exception,FileOpenError,
1788 "UnableToCreateTemporaryFile",image_info->unique);
1789 return(MagickFalse);
1791 magick=InterpretImageProperties(image_info,image,decode != (
char *) NULL ?
1792 delegate_info->encode : delegate_info->decode,exception);
1793 if (magick == (
char *) NULL)
1795 (void) RelinquishUniqueFileResource(image_info->unique);
1796 if (temporary != MagickFalse)
1797 (void) RelinquishUniqueFileResource(image->filename);
1798 (void) ThrowMagickException(exception,GetMagickModule(),
1799 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1800 return(MagickFalse);
1802 LocaleUpper(magick);
1803 clone_info=CloneImageInfo(image_info);
1804 (void) CopyMagickString((
char *) clone_info->magick,magick,
1806 if (LocaleCompare(magick,
"NULL") != 0)
1807 (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1808 magick=DestroyString(magick);
1809 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
"%s:",
1810 delegate_info->decode);
1811 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1813 (void) CopyMagickString(clone_info->filename,image_info->filename,
1815 (void) CopyMagickString(image_info->filename,image->filename,
1817 for (p=image; p != (Image *) NULL; p=GetNextImageInList(p))
1819 (void) FormatLocaleString(p->filename,MagickPathExtent,
"%s:%s",
1820 delegate_info->decode,clone_info->filename);
1821 status=WriteImage(clone_info,p,exception);
1822 if (status == MagickFalse)
1824 (void) RelinquishUniqueFileResource(image_info->unique);
1825 if (temporary != MagickFalse)
1826 (void) RelinquishUniqueFileResource(image->filename);
1827 clone_info=DestroyImageInfo(clone_info);
1828 (void) ThrowMagickException(exception,GetMagickModule(),
1829 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1830 return(MagickFalse);
1832 if (clone_info->adjoin != MagickFalse)
1835 (void) RelinquishUniqueFileResource(image_info->unique);
1836 clone_info=DestroyImageInfo(clone_info);
1841 commands=StringToList(delegate_info->commands);
1842 if (commands == (
char **) NULL)
1844 if (temporary != MagickFalse)
1845 (void) RelinquishUniqueFileResource(image->filename);
1846 (void) ThrowMagickException(exception,GetMagickModule(),
1847 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1848 decode ? decode : encode);
1849 return(MagickFalse);
1851 command=(
char *) NULL;
1853 (void) CopyMagickString(output_filename,image_info->filename,
1855 (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1856 for (i=0; commands[i] != (
char *) NULL; i++)
1858 if (IsPathAuthorized(WritePolicyRights,output_filename) == MagickFalse)
1861 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, \
1862 "NotAuthorized",
"`%s'",output_filename);
1865 (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1866 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1868 ThrowFileException(exception,FileOpenError,
1869 "UnableToCreateTemporaryFile",image_info->unique);
1872 if (LocaleCompare(decode,
"SCAN") != 0)
1874 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1875 if (status == MagickFalse)
1877 ThrowFileException(exception,FileOpenError,
1878 "UnableToCreateTemporaryFile",input_filename);
1883 command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1884 if (command != (
char *) NULL)
1889 if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1890 command,(
char *) NULL,exception) != 0)
1892 if (delegate_info->spawn != MagickFalse)
1901 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1902 (void) MagickDelay(100);
1904 command=DestroyString(command);
1906 if (LocaleCompare(decode,
"SCAN") != 0)
1908 if (CopyDelegateFile(image->filename,input_filename,MagickFalse,exception) == MagickFalse)
1909 (void) RelinquishUniqueFileResource(input_filename);
1911 if ((strcmp(input_filename,output_filename) != 0) &&
1912 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue,exception) == MagickFalse))
1913 (void) RelinquishUniqueFileResource(output_filename);
1914 if (image_info->temporary != MagickFalse)
1915 (void) RelinquishUniqueFileResource(image_info->filename);
1916 (void) RelinquishUniqueFileResource(image_info->unique);
1917 (void) RelinquishUniqueFileResource(image_info->filename);
1918 (void) RelinquishUniqueFileResource(image->filename);
1919 if (status == MagickFalse)
1921 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1922 "DelegateFailed",
"`%s'",commands[i]);
1925 commands[i]=DestroyString(commands[i]);
1927 (void) CopyMagickString(image_info->filename,output_filename,
1929 (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
1933 for ( ; commands[i] != (
char *) NULL; i++)
1934 commands[i]=DestroyString(commands[i]);
1935 commands=(
char **) RelinquishMagickMemory(commands);
1936 if (temporary != MagickFalse)
1937 (void) RelinquishUniqueFileResource(image->filename);
1965MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1966 ExceptionInfo *exception)
1973 delegate[MagickPathExtent];
1987 if (file == (
const FILE *) NULL)
1989 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
1990 if (delegate_info == (
const DelegateInfo **) NULL)
1991 return(MagickFalse);
1992 path=(
const char *) NULL;
1993 for (i=0; i < (ssize_t) number_delegates; i++)
1995 if (delegate_info[i]->stealth != MagickFalse)
1997 if ((path == (
const char *) NULL) ||
1998 (LocaleCompare(path,delegate_info[i]->path) != 0))
2000 if (delegate_info[i]->path != (
char *) NULL)
2001 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2002 (void) FormatLocaleFile(file,
"Delegate Command\n");
2003 (void) FormatLocaleFile(file,
2004 "-------------------------------------------------"
2005 "------------------------------\n");
2007 path=delegate_info[i]->path;
2009 if (delegate_info[i]->encode != (
char *) NULL)
2010 (void) CopyMagickString(delegate,delegate_info[i]->encode,
2012 (void) ConcatenateMagickString(delegate,
" ",MagickPathExtent);
2014 commands=StringToList(delegate_info[i]->commands);
2015 if (commands == (
char **) NULL)
2017 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2018 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2019 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2020 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2021 for (j=1; commands[j] != (
char *) NULL; j++)
2022 (
void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2023 for (j=0; commands[j] != (
char *) NULL; j++)
2024 commands[j]=DestroyString(commands[j]);
2025 commands=(
char **) RelinquishMagickMemory(commands);
2027 (void) fflush(file);
2028 delegate_info=(
const DelegateInfo **)
2029 RelinquishMagickMemory((
void *) delegate_info);
2064static MagickBooleanType LoadDelegateCache(LinkedListInfo *cache,
2065 const char *xml,
const char *filename,
const size_t depth,
2066 ExceptionInfo *exception)
2069 keyword[MagickPathExtent],
2087 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2088 "Loading delegate configuration file \"%s\" ...",filename);
2089 if (xml == (
const char *) NULL)
2090 return(MagickFalse);
2092 delegate_info=(DelegateInfo *) NULL;
2093 token=AcquireString(xml);
2094 extent=strlen(token)+MagickPathExtent;
2095 for (q=(
const char *) xml; *q !=
'\0'; )
2100 (void) GetNextToken(q,&q,extent,token);
2103 (void) CopyMagickString(keyword,token,MagickPathExtent);
2104 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2109 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2110 (void) GetNextToken(q,&q,extent,token);
2113 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2118 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2119 (void) GetNextToken(q,&q,extent,token);
2122 if (LocaleCompare(keyword,
"<include") == 0)
2127 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2129 (void) CopyMagickString(keyword,token,MagickPathExtent);
2130 (void) GetNextToken(q,&q,extent,token);
2133 (void) GetNextToken(q,&q,extent,token);
2134 if (LocaleCompare(keyword,
"file") == 0)
2136 if (depth > MagickMaxRecursionDepth)
2137 (void) ThrowMagickException(exception,GetMagickModule(),
2138 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2142 path[MagickPathExtent],
2145 GetPathComponent(filename,HeadPath,path);
2147 (void) ConcatenateMagickString(path,DirectorySeparator,
2149 if (*token == *DirectorySeparator)
2150 (void) CopyMagickString(path,token,MagickPathExtent);
2152 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
2153 file_xml=FileToXML(path,~0UL);
2154 if (file_xml != (
char *) NULL)
2156 status&=(MagickStatusType) LoadDelegateCache(cache,
2157 file_xml,path,depth+1,exception);
2158 file_xml=DestroyString(file_xml);
2165 if (LocaleCompare(keyword,
"<delegate") == 0)
2170 delegate_info=(DelegateInfo *) AcquireCriticalMemory(
2171 sizeof(*delegate_info));
2172 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2173 delegate_info->path=ConstantString(filename);
2174 delegate_info->thread_support=MagickTrue;
2175 delegate_info->signature=MagickCoreSignature;
2178 if (delegate_info == (DelegateInfo *) NULL)
2180 if ((LocaleCompare(keyword,
"/>") == 0) ||
2181 (LocaleCompare(keyword,
"</policy>") == 0))
2183 status=AppendValueToLinkedList(cache,delegate_info);
2184 if (status == MagickFalse)
2185 (void) ThrowMagickException(exception,GetMagickModule(),
2186 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2187 delegate_info->commands);
2188 delegate_info=(DelegateInfo *) NULL;
2191 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2194 (void) GetNextToken(q,&q,extent,token);
2195 (void) GetNextToken(q,&q,extent,token);
2201 if (LocaleCompare((
char *) keyword,
"command") == 0)
2206 commands=AcquireString(token);
2207#if defined(MAGICKCORE_WINDOWS_SUPPORT)
2208 if (strchr(commands,
'@') != (
char *) NULL)
2211 path[MagickPathExtent];
2213 NTGhostscriptEXE(path,MagickPathExtent);
2214 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2216 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2219 (void) SubstituteString((
char **) &commands,
""",
"\"");
2220 (void) SubstituteString((
char **) &commands,
"'",
"'");
2221 (void) SubstituteString((
char **) &commands,
"&",
"&");
2222 (void) SubstituteString((
char **) &commands,
">",
">");
2223 (void) SubstituteString((
char **) &commands,
"<",
"<");
2224 if (delegate_info->commands != (
char *) NULL)
2225 delegate_info->commands=DestroyString(delegate_info->commands);
2226 delegate_info->commands=commands;
2234 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2236 delegate_info->decode=ConstantString(token);
2237 delegate_info->mode=1;
2245 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2247 delegate_info->encode=ConstantString(token);
2248 delegate_info->mode=(-1);
2256 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2258 delegate_info->mode=1;
2259 if (LocaleCompare(token,
"bi") == 0)
2260 delegate_info->mode=0;
2262 if (LocaleCompare(token,
"encode") == 0)
2263 delegate_info->mode=(-1);
2271 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2273 delegate_info->spawn=IsStringTrue(token);
2276 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2278 delegate_info->stealth=IsStringTrue(token);
2286 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2288 delegate_info->thread_support=IsStringTrue(token);
2289 if (delegate_info->thread_support == MagickFalse)
2290 delegate_info->semaphore=AcquireSemaphoreInfo();
2299 token=(
char *) RelinquishMagickMemory(token);
2300 return(status != 0 ? MagickTrue : MagickFalse);