48#include "magick/studio.h"
49#include "magick/artifact.h"
50#include "magick/attribute.h"
51#include "magick/blob.h"
52#include "magick/client.h"
53#include "magick/configure.h"
54#include "magick/constitute.h"
55#include "magick/delegate.h"
56#include "magick/exception.h"
57#include "magick/exception-private.h"
58#include "magick/hashmap.h"
59#include "magick/image-private.h"
60#include "magick/list.h"
61#include "magick/memory_.h"
62#include "magick/nt-base-private.h"
63#include "magick/option.h"
64#include "magick/policy.h"
65#include "magick/property.h"
66#include "magick/resource_.h"
67#include "magick/semaphore.h"
68#include "magick/signature.h"
69#include "magick/string_.h"
70#include "magick/token.h"
71#include "magick/token-private.h"
72#include "magick/utility.h"
73#include "magick/utility-private.h"
74#include "magick/xml-tree.h"
75#include "magick/xml-tree-private.h"
81 #include "TargetConditionals.h"
82 #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
83 #define system(s) ((s)==NULL ? 0 : -1)
85#elif defined(__ANDROID__)
86 #define system(s) ((s)==NULL ? 0 : -1)
88#define DelegateFilename "delegates.xml"
89#if defined(MAGICKCORE_WINDOWS_SUPPORT)
90 #define DELEGATE_ESC """
92 #define DELEGATE_ESC "'"
99 *DelegateMap = (
const char *)
100 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
102 " <delegate decode=\"bpg\" command=\"" DELEGATE_ESC
"bpgdec" DELEGATE_ESC
" -b 16 -o " DELEGATE_ESC
"%o.png" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"; mv " DELEGATE_ESC
"%o.png" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
103 " <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
"\"/>"
104 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\"" DELEGATE_ESC
"xdg-open" DELEGATE_ESC
" https://imagemagick.org/; rm " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
105 " <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
"\"/>"
106 " <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
"\"/>"
107 " <delegate decode=\"https\" command=\"" DELEGATE_ESC
"curl" DELEGATE_ESC
" -s -k -L -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"https:%M" DELEGATE_ESC
"\"/>"
108 " <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
"\"/>"
109 " <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
"\"/>"
110 " <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
"\"/>"
111 " <delegate decode=\"dot\" command=\"" DELEGATE_ESC
"dot" DELEGATE_ESC
" -Tsvg " DELEGATE_ESC
"%i" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
112 " <delegate decode=\"dvi\" command=\"" DELEGATE_ESC
"dvips" DELEGATE_ESC
" -sstdout=%%stderr -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
113 " <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
"\"/>"
114 " <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
"\"/>"
115 " <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
"\"/>"
116 " <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
"\"/>"
117 " <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
"\"/>"
118 " <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
"\"/>"
119 " <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
"\"/>"
120 " <delegate decode=\"htm\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
121 " <delegate decode=\"html\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
122 " <delegate decode=\"ilbm\" command=\"" DELEGATE_ESC
"ilbmtoppm" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
123 " <delegate decode=\"jpg\" encode=\"lep\" mode=\"encode\" command=\"" DELEGATE_ESC
"lepton" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
124 " <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
"\"/>"
125 " <delegate decode=\"lep\" mode=\"decode\" command=\"" DELEGATE_ESC
"lepton" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
" " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
126 " <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
"\"/>"
127 " <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
"\"/>"
128 " <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
"\"/>"
129 " <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
"\"/>"
130 " <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
"\"/>"
131 " <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
"\"/>"
132 " <delegate decode=\"png\" encode=\"clipboard\" command=\"" DELEGATE_ESC
"xclip" DELEGATE_ESC
" -selection clipboard -t image/png " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
133 " <delegate decode=\"clipboard\" command=\"" DELEGATE_ESC
"xclip" DELEGATE_ESC
" -selection clipboard -o > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
134 " <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
"\"/>"
135 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\"" DELEGATE_ESC
"ppmtoilbm" DELEGATE_ESC
" -24if " DELEGATE_ESC
"%i" DELEGATE_ESC
" > " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
136 " <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
"\"/>"
137 " <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
"\"/>"
138 " <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
"\"/>"
139 " <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
"\"/>"
140 " <delegate decode=\"ps\" encode=\"prt\" command=\"" DELEGATE_ESC
"lpr" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
141 " <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
"\"/>"
142 " <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
"\"/>"
143 " <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
"\"/>"
144 " <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
"\"/>"
145 " <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
"\"/>"
146 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
147 " <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
"\"/>"
148 " <delegate decode=\"shtml\" command=\"" DELEGATE_ESC
"html2ps" DELEGATE_ESC
" -U -o " DELEGATE_ESC
"%o" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
149 " <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
"\"/>"
150 " <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
"\"/>"
151#ifndef MAGICKCORE_RSVG_DELEGATE
152 " <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
"\"/>"
154 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\"" DELEGATE_ESC
"gimp" DELEGATE_ESC
" " DELEGATE_ESC
"%i" DELEGATE_ESC
"\"/>"
155 " <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
"\"/>"
156 " <delegate decode=\"webp\" command=\"" DELEGATE_ESC
"dwebp" DELEGATE_ESC
" -pam " DELEGATE_ESC
"%i" DELEGATE_ESC
" -o " DELEGATE_ESC
"%o" DELEGATE_ESC
"\"/>"
157 " <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
"\"/>"
158 " <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
"\"/>"
159 " <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
"\"/>"
160 " <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
"\"/>"
161 " <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
"\"/>"
162 " <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
"\"/>"
163 " <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
"\"/>"
180static MagickBooleanType
182 LoadDelegateCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
217 cache=NewLinkedList(0);
218#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
226 options=GetConfigureOptions(filename,exception);
227 option=(
const StringInfo *) GetNextValueInLinkedList(options);
230 (void) LoadDelegateCache(cache,(
const char *) GetStringInfoDatum(option),
231 GetStringInfoPath(option),0,exception);
232 option=(
const StringInfo *) GetNextValueInLinkedList(options);
234 options=DestroyConfigureOptions(options);
237 if (IsLinkedListEmpty(cache) != MagickFalse)
238 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
260MagickExport MagickBooleanType DelegateComponentGenesis(
void)
263 delegate_semaphore=AllocateSemaphoreInfo();
286static void *DestroyDelegate(
void *delegate_info)
292 if (p->path != (
char *) NULL)
293 p->path=DestroyString(p->path);
294 if (p->decode != (
char *) NULL)
295 p->decode=DestroyString(p->decode);
296 if (p->encode != (
char *) NULL)
297 p->encode=DestroyString(p->encode);
298 if (p->commands != (
char *) NULL)
299 p->commands=DestroyString(p->commands);
301 DestroySemaphoreInfo(&p->semaphore);
303 return((
void *) NULL);
306MagickExport
void DelegateComponentTerminus(
void)
309 ActivateSemaphoreInfo(&delegate_semaphore);
310 LockSemaphoreInfo(delegate_semaphore);
312 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
313 UnlockSemaphoreInfo(delegate_semaphore);
314 DestroySemaphoreInfo(&delegate_semaphore);
353MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
354 const MagickBooleanType verbose,
const char *command,
char *message,
375 arguments=StringToArgv(command,&number_arguments);
376 if (arguments == (
char **) NULL)
378 if (*arguments[1] ==
'\0')
380 for (i=0; i < (ssize_t) number_arguments; i++)
381 arguments[i]=DestroyString(arguments[i]);
382 arguments=(
char **) RelinquishMagickMemory(arguments);
385 rights=ExecutePolicyRights;
386 domain=DelegatePolicyDomain;
387 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
390 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
391 "NotAuthorized",
"`%s'",arguments[1]);
392 for (i=0; i < (ssize_t) number_arguments; i++)
393 arguments[i]=DestroyString(arguments[i]);
394 arguments=(
char **) RelinquishMagickMemory(arguments);
397 if (verbose != MagickFalse)
399 (void) FormatLocaleFile(stderr,
"%s\n",command);
400 (void) fflush(stderr);
402 sanitize_command=SanitizeString(command);
403 if (asynchronous != MagickFalse)
404 (void) ConcatenateMagickString(sanitize_command,
"&",MaxTextExtent);
405 if (message != (
char *) NULL)
407#if defined(MAGICKCORE_POSIX_SUPPORT)
408#if defined(MAGICKCORE_HAVE_POPEN)
409 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
412 buffer[MagickPathExtent];
421 file=popen_utf8(sanitize_command,
"r");
422 if (file == (FILE *) NULL)
423 status=system(sanitize_command);
426 while (fgets(buffer,(
int)
sizeof(buffer),file) != NULL)
431 length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
434 (void) CopyMagickString(message+offset,buffer,length);
444#if !defined(MAGICKCORE_HAVE_EXECVP)
445 status=system(sanitize_command);
447 if ((asynchronous != MagickFalse) ||
448 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
449 status=system(sanitize_command);
458 child_pid=(pid_t) fork();
459 if (child_pid == (pid_t) -1)
460 status=system(sanitize_command);
464 status=execvp(arguments[1],arguments+1);
476 pid=(pid_t) waitpid(child_pid,&child_status,0);
481 if (WIFEXITED(child_status) != 0)
482 status=WEXITSTATUS(child_status);
484 if (WIFSIGNALED(child_status))
491#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
504 p=strstr(sanitize_command,
"cmd.exe /c");
505 if (p != (
char*) NULL)
508 for ( ; *p !=
'\0'; p++)
510 *p=(*DirectorySeparator);
513 status=NTSystemCommand(sanitize_command,message);
515 status=system(sanitize_command);
517# error No suitable system() method.
521 if ((message != (
char *) NULL) && (*message !=
'\0'))
522 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
523 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
525 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
526 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
528 sanitize_command=DestroyString(sanitize_command);
529 for (i=0; i < (ssize_t) number_arguments; i++)
530 arguments[i]=DestroyString(arguments[i]);
531 arguments=(
char **) RelinquishMagickMemory(arguments);
573static char *GetMagickPropertyLetter(
const ImageInfo *image_info,
Image *image,
577 value[MaxTextExtent];
582 assert(image != (
Image *) NULL);
583 assert(image->signature == MagickCoreSignature);
584 if (IsEventLogging() != MagickFalse)
585 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
587 string=(
const char *) value;
595 if (image_info->authenticate != (
char *) NULL)
596 string=image_info->authenticate;
604 (void) FormatMagickSize(image->extent,MagickFalse,value);
605 if (image->extent == 0)
606 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,value);
614 GetPathComponent(image->magick_filename,HeadPath,value);
622 GetPathComponent(image->magick_filename,ExtensionPath,value);
630 GetPathComponent(image->magick_filename,TailPath,value);
638 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
639 (
double) image->page.width,(
double) image->page.height,
640 (
double) image->page.x,(
double) image->page.y);
648 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
649 (image->rows != 0 ? image->rows : image->magick_rows));
657 string=image->filename;
665 string=image->magick;
673 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
674 GetImageListLength(image));
682 string=image_info->filename;
690 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
691 GetImageIndexInList(image));
699 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
700 MAGICKCORE_QUANTUM_DEPTH);
711 colorspace=image->colorspace;
712 if (SetImageGray(image,&image->exception) != MagickFalse)
713 colorspace=GRAYColorspace;
714 (void) FormatLocaleString(value,MaxTextExtent,
"%s %s %s",
715 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
716 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
717 (ssize_t) colorspace),image->matte != MagickFalse ?
"Matte" :
"" );
725 if (image_info->number_scenes != 0)
726 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
729 (
void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
738 GetPathComponent(image->magick_filename,BasePath,value);
746 string=image_info->unique;
754 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
755 (image->columns != 0 ? image->columns : image->magick_columns));
763 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
764 fabs(image->x_resolution) > MagickEpsilon ? image->x_resolution :
765 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
774 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
775 fabs(image->y_resolution) > MagickEpsilon ? image->y_resolution :
776 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
785 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
794 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
795 CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
803 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
804 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
805 image->compression));
813 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
814 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
823 (void) CopyMagickString(value,image->magick_filename,MaxTextExtent);
831 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
832 image->magick_columns,(
double) image->magick_rows);
840 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
849 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
858 string=image->magick_filename;
866 (void) FormatLocaleString(value,MaxTextExtent,
"%+ld%+ld",(
long)
867 image->page.x,(
long) image->page.y);
875 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
876 image->page.width,(
double) image->page.height);
884 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
885 (100-(image->quality == 0 ? 42 : image->quality))/2);
893 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
894 (image->quality == 0 ? 92 : image->quality));
902 if (image_info->number_scenes == 0)
906 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
907 image_info->scene+image_info->number_scenes);
916 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
925 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
926 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
935 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
944 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
953 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
962 string=image_info->zero;
973 page=GetImageBoundingBox(image,&image->exception);
974 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
975 (
double) page.width,(
double) page.height,(
double) page.x,(
double)
984 (void) SignatureImage(image);
985 string=GetImageProperty(image,
"signature");
997 return(SanitizeDelegateString(
string));
1000static char *InterpretDelegateProperties(
const ImageInfo *image_info,
1001 Image *image,
const char *embed_text)
1003#define ExtendInterpretText(string_length) \
1005 size_t length=(string_length); \
1006 if ((size_t) (q-interpret_text+length+1) >= extent) \
1009 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1010 MaxTextExtent,sizeof(*interpret_text)); \
1011 if (interpret_text == (char *) NULL) \
1012 return((char *) NULL); \
1013 q=interpret_text+strlen(interpret_text); \
1017#define AppendKeyValue2Text(key,value)\
1019 size_t length=strlen(key)+strlen(value)+2; \
1020 if ((size_t) (q-interpret_text+length+1) >= extent) \
1023 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1024 MaxTextExtent,sizeof(*interpret_text)); \
1025 if (interpret_text == (char *) NULL) \
1026 return((char *) NULL); \
1027 q=interpret_text+strlen(interpret_text); \
1029 q+=(ptrdiff_t) FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
1032#define AppendString2Text(string) \
1034 size_t length=strlen((string)); \
1035 if ((size_t) (q-interpret_text+length+1) >= extent) \
1038 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1039 MaxTextExtent,sizeof(*interpret_text)); \
1040 if (interpret_text == (char *) NULL) \
1041 return((char *) NULL); \
1042 q=interpret_text+strlen(interpret_text); \
1044 (void) CopyMagickString(q,(string),extent); \
1045 q+=(ptrdiff_t) length; \
1064 assert(image != (
Image *) NULL);
1065 assert(image->signature == MagickCoreSignature);
1066 if (IsEventLogging() != MagickFalse)
1067 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1068 if (embed_text == (
const char *) NULL)
1069 return(ConstantString(
""));
1071 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1074 return(ConstantString(
""));
1078 interpret_text=AcquireString(embed_text);
1079 extent=MaxTextExtent;
1081 for (q=interpret_text; *p!=
'\0';
1082 number=(isdigit((
int) ((
unsigned char) *p))) ? MagickTrue : MagickFalse,p++)
1088 ExtendInterpretText(MaxTextExtent);
1131 if (LocaleNCompare(
"<",p,4) == 0)
1137 if (LocaleNCompare(
">",p,4) == 0)
1143 if (LocaleNCompare(
"&",p,5) == 0)
1164 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1174 if (number != MagickFalse)
1180 property=GetMagickPropertyLetter(image_info,image,*p);
1181 if (property != (
char *) NULL)
1183 AppendString2Text(property);
1184 property=DestroyString(property);
1187 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1188 OptionWarning,
"UnknownImageProperty",
"\"%%%c\"",*p);
1191 return(interpret_text);
1194MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,
Image *image,
1195 const char *decode,
const char *encode,
ExceptionInfo *exception)
1207 assert(image_info != (
ImageInfo *) NULL);
1208 assert(image_info->signature == MagickCoreSignature);
1209 assert(image != (
Image *) NULL);
1210 assert(image->signature == MagickCoreSignature);
1211 if (IsEventLogging() != MagickFalse)
1212 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1213 delegate_info=GetDelegateInfo(decode,encode,exception);
1216 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1217 "NoTagFound",
"`%s'",decode ? decode : encode);
1218 return((
char *) NULL);
1220 commands=StringToList(delegate_info->commands);
1221 if (commands == (
char **) NULL)
1223 (void) ThrowMagickException(exception,GetMagickModule(),
1224 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1225 decode ? decode : encode);
1226 return((
char *) NULL);
1228 command=InterpretDelegateProperties(image_info,image,commands[0]);
1229 if (command == (
char *) NULL)
1230 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1231 "MemoryAllocationFailed",
"`%s'",commands[0]);
1235 for (i=0; commands[i] != (
char *) NULL; i++)
1236 commands[i]=DestroyString(commands[i]);
1237 commands=(
char **) RelinquishMagickMemory(commands);
1263MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1265 if (IsEventLogging() != MagickFalse)
1266 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1268 assert(delegate_info->signature == MagickCoreSignature);
1269 return(delegate_info->commands);
1301MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1308 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1313 LockSemaphoreInfo(delegate_semaphore);
1314 ResetLinkedListIterator(delegate_cache);
1315 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1316 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1318 UnlockSemaphoreInfo(delegate_semaphore);
1325 if (LocaleCompare(p->decode,decode) == 0)
1327 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1332 if (LocaleCompare(p->encode,encode) == 0)
1334 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1337 if (LocaleCompare(decode,p->decode) == 0)
1338 if (LocaleCompare(encode,p->encode) == 0)
1340 if (LocaleCompare(decode,
"*") == 0)
1341 if (LocaleCompare(encode,p->encode) == 0)
1343 if (LocaleCompare(decode,p->decode) == 0)
1344 if (LocaleCompare(encode,
"*") == 0)
1346 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1349 (void) InsertValueInLinkedList(delegate_cache,0,
1350 RemoveElementByValueFromLinkedList(delegate_cache,p));
1351 UnlockSemaphoreInfo(delegate_semaphore);
1384#if defined(__cplusplus) || defined(c_plusplus)
1388static int DelegateInfoCompare(
const void *x,
const void *y)
1399 cmp=LocaleCompare((*p)->path,(*q)->path);
1402 if ((*p)->decode == (
char *) NULL)
1403 if (((*p)->encode != (
char *) NULL) &&
1404 ((*q)->encode != (
char *) NULL))
1405 return(strcmp((*p)->encode,(*q)->encode));
1406 if (((*p)->decode != (
char *) NULL) &&
1407 ((*q)->decode != (
char *) NULL))
1408 return(strcmp((*p)->decode,(*q)->decode));
1413#if defined(__cplusplus) || defined(c_plusplus)
1417MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1432 assert(pattern != (
char *) NULL);
1433 assert(number_delegates != (
size_t *) NULL);
1434 if (IsEventLogging() != MagickFalse)
1435 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1436 *number_delegates=0;
1437 p=GetDelegateInfo(
"*",
"*",exception);
1440 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1441 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1447 LockSemaphoreInfo(delegate_semaphore);
1448 ResetLinkedListIterator(delegate_cache);
1449 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1452 if ((p->stealth == MagickFalse) &&
1453 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
1454 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
1456 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1458 UnlockSemaphoreInfo(delegate_semaphore);
1459 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1461 *number_delegates=(size_t) i;
1495#if defined(__cplusplus) || defined(c_plusplus)
1499static int DelegateCompare(
const void *x,
const void *y)
1505 p=(
const char **) x;
1506 q=(
const char **) y;
1507 return(LocaleCompare(*p,*q));
1510#if defined(__cplusplus) || defined(c_plusplus)
1514MagickExport
char **GetDelegateList(
const char *pattern,
1529 assert(pattern != (
char *) NULL);
1530 assert(number_delegates != (
size_t *) NULL);
1531 if (IsEventLogging() != MagickFalse)
1532 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1533 *number_delegates=0;
1534 p=GetDelegateInfo(
"*",
"*",exception);
1536 return((
char **) NULL);
1537 delegates=(
char **) AcquireQuantumMemory((
size_t)
1538 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1539 if (delegates == (
char **) NULL)
1540 return((
char **) NULL);
1541 LockSemaphoreInfo(delegate_semaphore);
1542 ResetLinkedListIterator(delegate_cache);
1543 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1546 if ((p->stealth == MagickFalse) &&
1547 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
1548 delegates[i++]=ConstantString(p->decode);
1549 if ((p->stealth == MagickFalse) &&
1550 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
1551 delegates[i++]=ConstantString(p->encode);
1552 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1554 UnlockSemaphoreInfo(delegate_semaphore);
1555 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1556 delegates[i]=(
char *) NULL;
1557 *number_delegates=(size_t) i;
1583MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1585 if (IsEventLogging() != MagickFalse)
1586 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1588 assert(delegate_info->signature == MagickCoreSignature);
1589 return(delegate_info->mode);
1616MagickExport MagickBooleanType GetDelegateThreadSupport(
1619 if (IsEventLogging() != MagickFalse)
1620 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1622 assert(delegate_info->signature == MagickCoreSignature);
1623 return(delegate_info->thread_support);
1649static MagickBooleanType IsDelegateCacheInstantiated(
ExceptionInfo *exception)
1654 ActivateSemaphoreInfo(&delegate_semaphore);
1655 LockSemaphoreInfo(delegate_semaphore);
1657 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1658 UnlockSemaphoreInfo(delegate_semaphore);
1660 return(delegate_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1693static MagickBooleanType CopyDelegateFile(
const char *source,
1694 const char *destination,
const MagickBooleanType overwrite)
1722 assert(source != (
const char *) NULL);
1723 assert(destination != (
char *) NULL);
1724 if (overwrite == MagickFalse)
1726 status=GetPathAttributes(destination,&attributes);
1727 if (status != MagickFalse)
1730 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1731 if (destination_file == -1)
1732 return(MagickFalse);
1733 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1734 if (source_file == -1)
1736 (void) close(destination_file);
1737 return(MagickFalse);
1739 quantum=(size_t) MagickMaxBufferExtent;
1740 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1741 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1742 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1743 if (buffer == (
unsigned char *) NULL)
1745 (void) close(source_file);
1746 (void) close(destination_file);
1747 return(MagickFalse);
1750 for (i=0; ; i+=count)
1752 count=(ssize_t) read(source_file,buffer,quantum);
1755 length=(size_t) count;
1756 count=(ssize_t) write(destination_file,buffer,length);
1757 if ((
size_t) count != length)
1760 (void) close(destination_file);
1761 (void) close(source_file);
1762 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1763 return(i != 0 ? MagickTrue : MagickFalse);
1766MagickExport MagickBooleanType InvokeDelegate(
ImageInfo *image_info,
1772 input_filename[MaxTextExtent],
1773 output_filename[MaxTextExtent];
1791 assert(image_info != (
ImageInfo *) NULL);
1792 assert(image_info->signature == MagickCoreSignature);
1793 assert(image != (
Image *) NULL);
1794 assert(image->signature == MagickCoreSignature);
1795 if (IsEventLogging() != MagickFalse)
1796 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1797 rights=ExecutePolicyRights;
1798 if ((decode != (
const char *) NULL) &&
1799 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1802 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1803 "NotAuthorized",
"`%s'",decode);
1804 return(MagickFalse);
1806 if ((encode != (
const char *) NULL) &&
1807 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1810 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1811 "NotAuthorized",
"`%s'",encode);
1812 return(MagickFalse);
1814 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1815 if (temporary != MagickFalse)
1816 if (AcquireUniqueFilename(image->filename) == MagickFalse)
1818 ThrowFileException(exception,FileOpenError,
1819 "UnableToCreateTemporaryFile",image->filename);
1820 return(MagickFalse);
1822 delegate_info=GetDelegateInfo(decode,encode,exception);
1825 if (temporary != MagickFalse)
1826 (void) RelinquishUniqueFileResource(image->filename);
1827 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1828 "NoTagFound",
"`%s'",decode ? decode : encode);
1829 return(MagickFalse);
1831 if (*image_info->filename ==
'\0')
1833 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1835 if (temporary != MagickFalse)
1836 (void) RelinquishUniqueFileResource(image->filename);
1837 ThrowFileException(exception,FileOpenError,
1838 "UnableToCreateTemporaryFile",image_info->filename);
1839 return(MagickFalse);
1841 image_info->temporary=MagickTrue;
1843 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1844 (delegate_info->encode != (
char *) NULL)) ||
1845 ((encode != (
const char *) NULL) &&
1846 (delegate_info->decode != (
char *) NULL))))
1860 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1862 ThrowFileException(exception,FileOpenError,
1863 "UnableToCreateTemporaryFile",image_info->unique);
1864 return(MagickFalse);
1866 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1868 (void) RelinquishUniqueFileResource(image_info->unique);
1869 ThrowFileException(exception,FileOpenError,
1870 "UnableToCreateTemporaryFile",image_info->zero);
1871 return(MagickFalse);
1873 magick=InterpretDelegateProperties(image_info,image,
1874 decode != (
char *) NULL ? delegate_info->encode :
1875 delegate_info->decode);
1876 if (magick == (
char *) NULL)
1878 (void) RelinquishUniqueFileResource(image_info->unique);
1879 (void) RelinquishUniqueFileResource(image_info->zero);
1880 if (temporary != MagickFalse)
1881 (void) RelinquishUniqueFileResource(image->filename);
1882 (void) ThrowMagickException(exception,GetMagickModule(),
1883 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1884 return(MagickFalse);
1886 LocaleUpper(magick);
1887 clone_info=CloneImageInfo(image_info);
1888 (void) CopyMagickString((
char *) clone_info->magick,magick,MaxTextExtent);
1889 if (LocaleCompare(magick,
"NULL") != 0)
1890 (void) CopyMagickString(image->magick,magick,MaxTextExtent);
1891 magick=DestroyString(magick);
1892 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,
"%s:",
1893 delegate_info->decode);
1894 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1896 (void) CopyMagickString(clone_info->filename,image_info->filename,
1898 (void) CopyMagickString(image_info->filename,image->filename,
1900 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1902 (void) FormatLocaleString(p->filename,MaxTextExtent,
"%s:%s",
1903 delegate_info->decode,clone_info->filename);
1904 status=WriteImage(clone_info,p);
1905 if (status == MagickFalse)
1907 (void) RelinquishUniqueFileResource(image_info->unique);
1908 (void) RelinquishUniqueFileResource(image_info->zero);
1909 if (temporary != MagickFalse)
1910 (void) RelinquishUniqueFileResource(image->filename);
1911 clone_info=DestroyImageInfo(clone_info);
1912 (void) ThrowMagickException(exception,GetMagickModule(),
1913 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1914 return(MagickFalse);
1916 if (clone_info->adjoin != MagickFalse)
1919 (void) RelinquishUniqueFileResource(image_info->unique);
1920 (void) RelinquishUniqueFileResource(image_info->zero);
1921 clone_info=DestroyImageInfo(clone_info);
1926 commands=StringToList(delegate_info->commands);
1927 if (commands == (
char **) NULL)
1929 if (temporary != MagickFalse)
1930 (void) RelinquishUniqueFileResource(image->filename);
1931 (void) ThrowMagickException(exception,GetMagickModule(),
1932 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1933 decode ? decode : encode);
1934 return(MagickFalse);
1936 command=(
char *) NULL;
1938 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1939 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1940 for (i=0; commands[i] != (
char *) NULL; i++)
1942 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1943 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1945 ThrowFileException(exception,FileOpenError,
1946 "UnableToCreateTemporaryFile",image_info->unique);
1949 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1951 (void) RelinquishUniqueFileResource(image_info->unique);
1952 ThrowFileException(exception,FileOpenError,
1953 "UnableToCreateTemporaryFile",image_info->zero);
1956 if (LocaleCompare(decode,
"SCAN") != 0)
1958 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1959 if (status == MagickFalse)
1961 ThrowFileException(exception,FileOpenError,
1962 "UnableToCreateTemporaryFile",input_filename);
1967 command=InterpretDelegateProperties(image_info,image,commands[i]);
1968 if (command != (
char *) NULL)
1973 status=ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1974 command,(
char *) NULL,exception) != 0 ? MagickTrue : MagickFalse;
1975 if (delegate_info->spawn != MagickFalse)
1984 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1985 (void) MagickDelay(100);
1987 command=DestroyString(command);
1989 if (LocaleCompare(decode,
"SCAN") != 0)
1991 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1992 (void) RelinquishUniqueFileResource(input_filename);
1994 if ((strcmp(input_filename,output_filename) != 0) &&
1995 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1996 (void) RelinquishUniqueFileResource(output_filename);
1997 if (image_info->temporary != MagickFalse)
1998 (void) RelinquishUniqueFileResource(image_info->filename);
1999 (void) RelinquishUniqueFileResource(image_info->unique);
2000 (void) RelinquishUniqueFileResource(image_info->zero);
2001 (void) RelinquishUniqueFileResource(image_info->filename);
2002 (void) RelinquishUniqueFileResource(image->filename);
2003 if (status != MagickFalse)
2005 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
2006 "DelegateFailed",
"`%s'",commands[i]);
2009 commands[i]=DestroyString(commands[i]);
2011 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
2012 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
2016 for ( ; commands[i] != (
char *) NULL; i++)
2017 commands[i]=DestroyString(commands[i]);
2018 commands=(
char **) RelinquishMagickMemory(commands);
2019 if (temporary != MagickFalse)
2020 (void) RelinquishUniqueFileResource(image->filename);
2021 return(status == MagickFalse ? MagickTrue : MagickFalse);
2048MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2056 delegate[MaxTextExtent];
2070 if (file == (
const FILE *) NULL)
2072 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2074 return(MagickFalse);
2075 path=(
const char *) NULL;
2076 for (i=0; i < (ssize_t) number_delegates; i++)
2078 if (delegate_info[i]->stealth != MagickFalse)
2080 if ((path == (
const char *) NULL) ||
2081 (LocaleCompare(path,delegate_info[i]->path) != 0))
2083 if (delegate_info[i]->path != (
char *) NULL)
2084 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2085 (void) FormatLocaleFile(file,
"Delegate Command\n");
2086 (void) FormatLocaleFile(file,
2087 "-------------------------------------------------"
2088 "------------------------------\n");
2090 path=delegate_info[i]->path;
2092 if (delegate_info[i]->encode != (
char *) NULL)
2093 (void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
2094 (void) ConcatenateMagickString(delegate,
" ",MaxTextExtent);
2096 commands=StringToList(delegate_info[i]->commands);
2097 if (commands == (
char **) NULL)
2099 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2100 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2101 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2102 StripString(commands[0]);
2103 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2104 for (j=1; commands[j] != (
char *) NULL; j++)
2106 StripString(commands[j]);
2107 (void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2109 for (j=0; commands[j] != (
char *) NULL; j++)
2110 commands[j]=DestroyString(commands[j]);
2111 commands=(
char **) RelinquishMagickMemory(commands);
2113 (void) fflush(file);
2115 RelinquishMagickMemory((
void *) delegate_info);
2151 const char *xml,
const char *filename,
const size_t depth,
2155 keyword[MaxTextExtent],
2173 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2174 "Loading delegate configuration file \"%s\" ...",filename);
2175 if (xml == (
const char *) NULL)
2176 return(MagickFalse);
2179 token=AcquireString(xml);
2180 extent=strlen(token)+MaxTextExtent;
2181 for (q=(
const char *) xml; *q !=
'\0'; )
2186 (void) GetNextToken(q,&q,extent,token);
2189 (void) CopyMagickString(keyword,token,MaxTextExtent);
2190 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2195 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2196 (void) GetNextToken(q,&q,extent,token);
2199 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2204 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2205 (void) GetNextToken(q,&q,extent,token);
2208 if (LocaleCompare(keyword,
"<include") == 0)
2213 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2215 (void) CopyMagickString(keyword,token,MaxTextExtent);
2216 (void) GetNextToken(q,&q,extent,token);
2219 (void) GetNextToken(q,&q,extent,token);
2220 if (LocaleCompare(keyword,
"file") == 0)
2222 if (depth > MagickMaxRecursionDepth)
2223 (void) ThrowMagickException(exception,GetMagickModule(),
2224 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2228 path[MaxTextExtent],
2231 GetPathComponent(filename,HeadPath,path);
2233 (void) ConcatenateMagickString(path,DirectorySeparator,
2235 if (*token == *DirectorySeparator)
2236 (void) CopyMagickString(path,token,MaxTextExtent);
2238 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
2239 xml=FileToXML(path,~0UL);
2240 if (xml != (
char *) NULL)
2242 status&=LoadDelegateCache(cache,xml,path,depth+1,
2244 xml=(
char *) RelinquishMagickMemory(xml);
2251 if (LocaleCompare(keyword,
"<delegate") == 0)
2257 sizeof(*delegate_info));
2259 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
2260 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2261 delegate_info->path=ConstantString(filename);
2262 delegate_info->thread_support=MagickTrue;
2263 delegate_info->signature=MagickCoreSignature;
2268 if ((LocaleCompare(keyword,
"/>") == 0) ||
2269 (LocaleCompare(keyword,
"</policy>") == 0))
2271 status=AppendValueToLinkedList(cache,delegate_info);
2272 if (status == MagickFalse)
2273 (void) ThrowMagickException(exception,GetMagickModule(),
2274 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2275 delegate_info->commands);
2279 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2282 (void) GetNextToken(q,&q,extent,token);
2283 (void) GetNextToken(q,&q,extent,token);
2289 if (LocaleCompare((
char *) keyword,
"command") == 0)
2294 commands=AcquireString(token);
2295#if defined(MAGICKCORE_WINDOWS_SUPPORT)
2296 if (strchr(commands,
'@') != (
char *) NULL)
2299 path[MaxTextExtent];
2301 NTGhostscriptEXE(path,MaxTextExtent);
2302 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2304 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2307 (void) SubstituteString((
char **) &commands,
""",
"\"");
2308 (void) SubstituteString((
char **) &commands,
"'",
"'");
2309 (void) SubstituteString((
char **) &commands,
"&",
"&");
2310 (void) SubstituteString((
char **) &commands,
">",
">");
2311 (void) SubstituteString((
char **) &commands,
"<",
"<");
2312 if (delegate_info->commands != (
char *) NULL)
2313 delegate_info->commands=DestroyString(delegate_info->commands);
2314 delegate_info->commands=commands;
2322 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2324 delegate_info->decode=ConstantString(token);
2325 delegate_info->mode=1;
2333 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2335 delegate_info->encode=ConstantString(token);
2336 delegate_info->mode=(-1);
2344 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2346 delegate_info->mode=1;
2347 if (LocaleCompare(token,
"bi") == 0)
2348 delegate_info->mode=0;
2350 if (LocaleCompare(token,
"encode") == 0)
2351 delegate_info->mode=(-1);
2359 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2361 delegate_info->spawn=IsMagickTrue(token);
2364 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2366 delegate_info->stealth=IsMagickTrue(token);
2374 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2376 delegate_info->thread_support=IsMagickTrue(token);
2377 if (delegate_info->thread_support == MagickFalse)
2378 delegate_info->semaphore=AllocateSemaphoreInfo();
2387 token=(
char *) RelinquishMagickMemory(token);
2388 return(status != 0 ? MagickTrue : MagickFalse);