cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1 | /* |
| 2 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 3 | % % |
| 4 | % % |
| 5 | % DDDD EEEEE L EEEEE GGGG AAA TTTTT EEEEE % |
| 6 | % D D E L E G A A T E % |
| 7 | % D D EEE L EEE G GG AAAAA T EEE % |
| 8 | % D D E L E G G A A T E % |
| 9 | % DDDD EEEEE LLLLL EEEEE GGG A A T EEEEE % |
| 10 | % % |
| 11 | % % |
| 12 | % MagickCore Methods to Read/Write/Invoke Delegates % |
| 13 | % % |
| 14 | % Software Design % |
| 15 | % John Cristy % |
| 16 | % October 1998 % |
| 17 | % % |
| 18 | % % |
| 19 | % Copyright 1999-2009 ImageMagick Studio LLC, a non-profit organization % |
| 20 | % dedicated to making software imaging solutions freely available. % |
| 21 | % % |
| 22 | % You may not use this file except in compliance with the License. You may % |
| 23 | % obtain a copy of the License at % |
| 24 | % % |
| 25 | % http://www.imagemagick.org/script/license.php % |
| 26 | % % |
| 27 | % Unless required by applicable law or agreed to in writing, software % |
| 28 | % distributed under the License is distributed on an "AS IS" BASIS, % |
| 29 | % WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. % |
| 30 | % See the License for the specific language governing permissions and % |
| 31 | % limitations under the License. % |
| 32 | % % |
| 33 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 34 | % |
| 35 | % The Delegates methods associate a set of commands with a particular |
| 36 | % image format. ImageMagick uses delegates for formats it does not handle |
| 37 | % directly. |
| 38 | % |
| 39 | % Thanks to Bob Friesenhahn for the initial inspiration and design of the |
| 40 | % delegates methods. |
| 41 | % |
| 42 | % |
| 43 | */ |
| 44 | |
| 45 | /* |
| 46 | Include declarations. |
| 47 | */ |
| 48 | #include "magick/studio.h" |
| 49 | #include "magick/property.h" |
| 50 | #include "magick/blob.h" |
| 51 | #include "magick/client.h" |
| 52 | #include "magick/configure.h" |
| 53 | #include "magick/constitute.h" |
| 54 | #include "magick/delegate.h" |
| 55 | #include "magick/exception.h" |
| 56 | #include "magick/exception-private.h" |
| 57 | #include "magick/hashmap.h" |
| 58 | #include "magick/list.h" |
| 59 | #include "magick/memory_.h" |
| 60 | #include "magick/policy.h" |
| 61 | #include "magick/resource_.h" |
| 62 | #include "magick/semaphore.h" |
| 63 | #include "magick/string_.h" |
| 64 | #include "magick/token.h" |
| 65 | #include "magick/utility.h" |
| 66 | #include "magick/xml-tree.h" |
| 67 | |
| 68 | /* |
| 69 | Define declarations. |
| 70 | */ |
| 71 | #define DelegateFilename "delegates.xml" |
| 72 | |
| 73 | /* |
| 74 | Declare delegate map. |
| 75 | */ |
| 76 | static const char |
| 77 | *DelegateMap = (const char *) |
| 78 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 79 | "<delegatemap>" |
| 80 | " <delegate decode=\"autotrace\" stealth=\"True\" command=\""autotrace" -output-format svg -output-file "%o" "%i"\"/>" |
| 81 | " <delegate decode=\"avi:decode\" stealth=\"True\" command=\""mplayer" "%i" -really-quiet -ao null -vo png:z=3\"/>" |
| 82 | " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" http://www.imagemagick.org/\"/>" |
| 83 | " <delegate decode=\"cgm\" thread-support=\"False\" command=\""ralcgm" -d ps -oC < "%i" > "%o" 2> "%u"\"/>" |
| 84 | " <delegate decode=\"dng:decode\" command=\""/usr/bin/ufraw-batch" --silent --wb=camera --black-point=auto --exposure=auto --create-id=also --out-type=ppm16 "--output=%u.pnm" "%i"\"/>" |
| 85 | " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>" |
| 86 | " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>" |
| 87 | " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>" |
| 88 | " <delegate decode=\"fig\" command=\""fig2dev" -L ps "%i" "%o"\"/>" |
| 89 | " <delegate decode=\"gplt\" command=\""echo" "set size 1.25,0.62 set terminal postscript portrait color solid; set output "%o"; load "%i"" > "%u";"gnuplot" "%u"\"/>" |
| 90 | " <delegate decode=\"hdr\" command=\""ra_pfm" "%i" "%o"\"/>" |
| 91 | " <delegate decode=\"hpg\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>" |
| 92 | " <delegate decode=\"hpgl\" command=\"if [ -e hp2xx -o -e /usr/bin/hp2xx ]; then hp2xx -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o else echo "You need to install hp2xx to use HPGL files with ImageMagick." exit 1 fi\"/>" |
| 93 | " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
| 94 | " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
| 95 | " <delegate decode=\"https\" command=\""wget" -q -O "%o" "https:%M"\"/>" |
| 96 | " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>" |
| 97 | " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>" |
| 98 | " <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\""ffmpeg" --i "%i" -vcodec pam -an -f rawvideo -y "%u0.pam" 2;> "%Z"\"/>" |
| 99 | " <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\""ffmpeg" "%M%%d.jpg" "%u.%m" 2;> "%Z"\"/>" |
| 100 | " <delegate decode=\"pcl:color\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=ppmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>" |
| 101 | " <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>" |
| 102 | " <delegate decode=\"pcl:mono\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>" |
| 103 | " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>" |
| 104 | " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pswrite" "-sOutputFile=%o" "-f%i"\"/>" |
| 105 | " <delegate decode=\"pic\" command=\""ra_pfm" "%i" "%o"\"/>" |
| 106 | " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>" |
| 107 | " <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>" |
| 108 | " <delegate decode=\"pov\" command=\""povray" "+i"%i"" -D0 +o"%o" +fn%q +w%w +h%h +a -q9 -kfi"%s" -kff"%n" "convert" -concatenate "%o*.png" "%o"\"/>" |
| 109 | " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=epswrite" "-sOutputFile=%o" "-f%i"\"/>" |
| 110 | " <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>" |
| 111 | " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>" |
| 112 | " <delegate decode=\"ps:alpha\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
| 113 | " <delegate decode=\"ps:bbox\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=bbox" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
| 114 | " <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pam" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
| 115 | " <delegate decode=\"ps:color\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
| 116 | " <delegate decode=\"ps:mono\" stealth=\"True\" command=\""gs" -q -dQUIET -dSAFER -dPARANOIDSAFE -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=0 "-sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>" |
| 117 | " <delegate decode=\"rad\" command=\""ra_pfm" "%i" "%o"\"/>" |
| 118 | " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>" |
| 119 | " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>" |
| 120 | " <delegate encode=\"show\" stealth=\"True\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>" |
| 121 | " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
| 122 | " <delegate decode=\"svg\" command=\""wmf2eps" -o "%o" "%i"\"/>" |
| 123 | " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>" |
| 124 | " <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\""/usr/local/bin/display" -immutable -delay 0 -window-group %g -title "%l of %f" "temporary:%i"\"/>" |
| 125 | " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>" |
| 126 | "</delegatemap>"; |
| 127 | |
| 128 | /* |
| 129 | Global declaractions. |
| 130 | */ |
| 131 | static LinkedListInfo |
| 132 | *delegate_list = (LinkedListInfo *) NULL; |
| 133 | |
| 134 | static SemaphoreInfo |
| 135 | *delegate_semaphore = (SemaphoreInfo *) NULL; |
| 136 | |
| 137 | static volatile MagickBooleanType |
| 138 | instantiate_delegate = MagickFalse; |
| 139 | |
| 140 | /* |
| 141 | Forward declaractions. |
| 142 | */ |
| 143 | static MagickBooleanType |
| 144 | InitializeDelegateList(ExceptionInfo *), |
| 145 | LoadDelegateLists(const char *,ExceptionInfo *); |
| 146 | |
| 147 | /* |
| 148 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 149 | % % |
| 150 | % % |
| 151 | % % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 152 | + D e l e g a t e C o m p o n e n t T e r m i n u s % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 153 | % % |
| 154 | % % |
| 155 | % % |
| 156 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 157 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 158 | % DelegateComponentGenesis() instantiates the delegate component. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 159 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 160 | % The format of the DelegateComponentGenesis method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 161 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 162 | % MagickBooleanType DelegateComponentGenesis(void) |
| 163 | % |
| 164 | */ |
| 165 | MagickExport MagickBooleanType DelegateComponentGenesis(void) |
| 166 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 167 | assert(delegate_semaphore == (SemaphoreInfo *) NULL); |
| 168 | delegate_semaphore=AllocateSemaphoreInfo(); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 169 | return(MagickTrue); |
| 170 | } |
| 171 | |
| 172 | /* |
| 173 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 174 | % % |
| 175 | % % |
| 176 | % % |
| 177 | % D e l e g a t e C o m p o n e n t T e r m i n u s % |
| 178 | % % |
| 179 | % % |
| 180 | % % |
| 181 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 182 | % |
| 183 | % DelegateComponentTerminus() destroys the delegate component. |
| 184 | % |
| 185 | % The format of the DelegateComponentTerminus method is: |
| 186 | % |
| 187 | % DelegateComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 188 | % |
| 189 | */ |
| 190 | |
| 191 | static void *DestroyDelegate(void *delegate_info) |
| 192 | { |
| 193 | register DelegateInfo |
| 194 | *p; |
| 195 | |
| 196 | p=(DelegateInfo *) delegate_info; |
| 197 | if (p->path != (char *) NULL) |
| 198 | p->path=DestroyString(p->path); |
| 199 | if (p->decode != (char *) NULL) |
| 200 | p->decode=DestroyString(p->decode); |
| 201 | if (p->encode != (char *) NULL) |
| 202 | p->encode=DestroyString(p->encode); |
| 203 | if (p->commands != (char *) NULL) |
| 204 | p->commands=DestroyString(p->commands); |
| 205 | p=(DelegateInfo *) RelinquishMagickMemory(p); |
| 206 | return((void *) NULL); |
| 207 | } |
| 208 | |
| 209 | |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 210 | MagickExport void DelegateComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 211 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 212 | if (delegate_semaphore == (SemaphoreInfo *) NULL) |
| 213 | AcquireSemaphoreInfo(&delegate_semaphore); |
| 214 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 215 | if (delegate_list != (LinkedListInfo *) NULL) |
| 216 | delegate_list=DestroyLinkedList(delegate_list,DestroyDelegate); |
| 217 | instantiate_delegate=MagickFalse; |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 218 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 219 | DestroySemaphoreInfo(&delegate_semaphore); |
| 220 | } |
| 221 | |
| 222 | /* |
| 223 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 224 | % % |
| 225 | % % |
| 226 | % % |
| 227 | % G e t D e l e g a t e C o m m a n d % |
| 228 | % % |
| 229 | % % |
| 230 | % % |
| 231 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 232 | % |
| 233 | % GetDelegateCommand() replaces any embedded formatting characters with the |
| 234 | % appropriate image attribute and returns the resulting command. |
| 235 | % |
| 236 | % The format of the GetDelegateCommand method is: |
| 237 | % |
| 238 | % char *GetDelegateCommand(const ImageInfo *image_info,Image *image, |
| 239 | % const char *decode,const char *encode,ExceptionInfo *exception) |
| 240 | % |
| 241 | % A description of each parameter follows: |
| 242 | % |
| 243 | % o command: Method GetDelegateCommand returns the command associated |
| 244 | % with specified delegate tag. |
| 245 | % |
| 246 | % o image_info: the image info. |
| 247 | % |
| 248 | % o image: the image. |
| 249 | % |
| 250 | % o decode: Specifies the decode delegate we are searching for as a |
| 251 | % character string. |
| 252 | % |
| 253 | % o encode: Specifies the encode delegate we are searching for as a |
| 254 | % character string. |
| 255 | % |
| 256 | % o exception: return any errors or warnings in this structure. |
| 257 | % |
| 258 | */ |
| 259 | MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image, |
| 260 | const char *decode,const char *encode,ExceptionInfo *exception) |
| 261 | { |
| 262 | char |
| 263 | *command, |
| 264 | **commands; |
| 265 | |
| 266 | const DelegateInfo |
| 267 | *delegate_info; |
| 268 | |
| 269 | register long |
| 270 | i; |
| 271 | |
| 272 | assert(image_info != (ImageInfo *) NULL); |
| 273 | assert(image_info->signature == MagickSignature); |
| 274 | assert(image != (Image *) NULL); |
| 275 | assert(image->signature == MagickSignature); |
| 276 | if (image->debug != MagickFalse) |
| 277 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 278 | delegate_info=GetDelegateInfo(decode,encode,exception); |
| 279 | if (delegate_info == (const DelegateInfo *) NULL) |
| 280 | { |
| 281 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
| 282 | "NoTagFound","`%s'",decode ? decode : encode); |
| 283 | return((char *) NULL); |
| 284 | } |
| 285 | commands=StringToList(delegate_info->commands); |
| 286 | if (commands == (char **) NULL) |
| 287 | { |
| 288 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 289 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 290 | decode ? decode : encode); |
| 291 | return((char *) NULL); |
| 292 | } |
| 293 | command=InterpretImageProperties(image_info,image,commands[0]); |
| 294 | if (command == (char *) NULL) |
| 295 | (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError, |
| 296 | "MemoryAllocationFailed","`%s'",commands[0]); |
| 297 | /* |
| 298 | Relinquish resources. |
| 299 | */ |
| 300 | for (i=0; commands[i] != (char *) NULL; i++) |
| 301 | commands[i]=DestroyString(commands[i]); |
| 302 | commands=(char **) RelinquishMagickMemory(commands); |
| 303 | return(command); |
| 304 | } |
| 305 | |
| 306 | /* |
| 307 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 308 | % % |
| 309 | % % |
| 310 | % % |
| 311 | % G e t D e l e g a t e C o m m a n d s % |
| 312 | % % |
| 313 | % % |
| 314 | % % |
| 315 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 316 | % |
| 317 | % GetDelegateCommands() returns the commands associated with a delegate. |
| 318 | % |
| 319 | % The format of the GetDelegateCommands method is: |
| 320 | % |
| 321 | % const char *GetDelegateCommands(const DelegateInfo *delegate_info) |
| 322 | % |
| 323 | % A description of each parameter follows: |
| 324 | % |
| 325 | % o delegate_info: The delegate info. |
| 326 | % |
| 327 | */ |
| 328 | MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info) |
| 329 | { |
| 330 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 331 | assert(delegate_info != (DelegateInfo *) NULL); |
| 332 | assert(delegate_info->signature == MagickSignature); |
| 333 | return(delegate_info->commands); |
| 334 | } |
| 335 | |
| 336 | /* |
| 337 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 338 | % % |
| 339 | % % |
| 340 | % % |
| 341 | % G e t D e l e g a t e I n f o % |
| 342 | % % |
| 343 | % % |
| 344 | % % |
| 345 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 346 | % |
| 347 | % GetDelegateInfo() returns any delegates associated with the specified tag. |
| 348 | % |
| 349 | % The format of the GetDelegateInfo method is: |
| 350 | % |
| 351 | % const DelegateInfo *GetDelegateInfo(const char *decode, |
| 352 | % const char *encode,ExceptionInfo *exception) |
| 353 | % |
| 354 | % A description of each parameter follows: |
| 355 | % |
| 356 | % o decode: Specifies the decode delegate we are searching for as a |
| 357 | % character string. |
| 358 | % |
| 359 | % o encode: Specifies the encode delegate we are searching for as a |
| 360 | % character string. |
| 361 | % |
| 362 | % o exception: return any errors or warnings in this structure. |
| 363 | % |
| 364 | */ |
| 365 | MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, |
| 366 | const char *encode,ExceptionInfo *exception) |
| 367 | { |
| 368 | register const DelegateInfo |
| 369 | *p; |
| 370 | |
| 371 | assert(exception != (ExceptionInfo *) NULL); |
| 372 | if ((delegate_list == (LinkedListInfo *) NULL) || |
| 373 | (instantiate_delegate == MagickFalse)) |
| 374 | if (InitializeDelegateList(exception) == MagickFalse) |
| 375 | return((const DelegateInfo *) NULL); |
| 376 | if ((delegate_list == (LinkedListInfo *) NULL) || |
| 377 | (IsLinkedListEmpty(delegate_list) != MagickFalse)) |
| 378 | return((const DelegateInfo *) NULL); |
| 379 | if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0)) |
| 380 | return((const DelegateInfo *) GetValueFromLinkedList(delegate_list,0)); |
| 381 | /* |
| 382 | Search for named delegate. |
| 383 | */ |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 384 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 385 | ResetLinkedListIterator(delegate_list); |
| 386 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 387 | while (p != (const DelegateInfo *) NULL) |
| 388 | { |
| 389 | if (p->mode > 0) |
| 390 | { |
| 391 | if (LocaleCompare(p->decode,decode) == 0) |
| 392 | break; |
| 393 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 394 | continue; |
| 395 | } |
| 396 | if (p->mode < 0) |
| 397 | { |
| 398 | if (LocaleCompare(p->encode,encode) == 0) |
| 399 | break; |
| 400 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 401 | continue; |
| 402 | } |
| 403 | if (LocaleCompare(decode,p->decode) == 0) |
| 404 | if (LocaleCompare(encode,p->encode) == 0) |
| 405 | break; |
| 406 | if (LocaleCompare(decode,"*") == 0) |
| 407 | if (LocaleCompare(encode,p->encode) == 0) |
| 408 | break; |
| 409 | if (LocaleCompare(decode,p->decode) == 0) |
| 410 | if (LocaleCompare(encode,"*") == 0) |
| 411 | break; |
| 412 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 413 | } |
| 414 | if (p != (const DelegateInfo *) NULL) |
| 415 | (void) InsertValueInLinkedList(delegate_list,0, |
| 416 | RemoveElementByValueFromLinkedList(delegate_list,p)); |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 417 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 418 | return(p); |
| 419 | } |
| 420 | |
| 421 | /* |
| 422 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 423 | % % |
| 424 | % % |
| 425 | % % |
| 426 | % G e t D e l e g a t e I n f o L i s t % |
| 427 | % % |
| 428 | % % |
| 429 | % % |
| 430 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 431 | % |
| 432 | % GetDelegateInfoList() returns any delegates that match the specified pattern. |
| 433 | % |
| 434 | % The delegate of the GetDelegateInfoList function is: |
| 435 | % |
| 436 | % const DelegateInfo **GetDelegateInfoList(const char *pattern, |
| 437 | % unsigned long *number_delegates,ExceptionInfo *exception) |
| 438 | % |
| 439 | % A description of each parameter follows: |
| 440 | % |
| 441 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 442 | % |
| 443 | % o number_delegates: This integer returns the number of delegates in the |
| 444 | % list. |
| 445 | % |
| 446 | % o exception: return any errors or warnings in this structure. |
| 447 | % |
| 448 | */ |
| 449 | |
| 450 | #if defined(__cplusplus) || defined(c_plusplus) |
| 451 | extern "C" { |
| 452 | #endif |
| 453 | |
| 454 | static int DelegateInfoCompare(const void *x,const void *y) |
| 455 | { |
| 456 | const DelegateInfo |
| 457 | **p, |
| 458 | **q; |
| 459 | |
| 460 | p=(const DelegateInfo **) x, |
| 461 | q=(const DelegateInfo **) y; |
| 462 | if (LocaleCompare((*p)->path,(*q)->path) == 0) |
| 463 | { |
| 464 | if ((*p)->decode == (char *) NULL) |
| 465 | if (((*p)->encode != (char *) NULL) && |
| 466 | ((*q)->encode != (char *) NULL)) |
| 467 | return(strcmp((*p)->encode,(*q)->encode)); |
| 468 | if (((*p)->decode != (char *) NULL) && |
| 469 | ((*q)->decode != (char *) NULL)) |
| 470 | return(strcmp((*p)->decode,(*q)->decode)); |
| 471 | } |
| 472 | return(LocaleCompare((*p)->path,(*q)->path)); |
| 473 | } |
| 474 | |
| 475 | #if defined(__cplusplus) || defined(c_plusplus) |
| 476 | } |
| 477 | #endif |
| 478 | |
| 479 | MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern, |
| 480 | unsigned long *number_delegates,ExceptionInfo *exception) |
| 481 | { |
| 482 | const DelegateInfo |
| 483 | **delegates; |
| 484 | |
| 485 | register const DelegateInfo |
| 486 | *p; |
| 487 | |
| 488 | register long |
| 489 | i; |
| 490 | |
| 491 | /* |
| 492 | Allocate delegate list. |
| 493 | */ |
| 494 | assert(pattern != (char *) NULL); |
| 495 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
| 496 | assert(number_delegates != (unsigned long *) NULL); |
| 497 | *number_delegates=0; |
| 498 | p=GetDelegateInfo("*","*",exception); |
| 499 | if (p == (const DelegateInfo *) NULL) |
| 500 | return((const DelegateInfo **) NULL); |
| 501 | delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t) |
| 502 | GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates)); |
| 503 | if (delegates == (const DelegateInfo **) NULL) |
| 504 | return((const DelegateInfo **) NULL); |
| 505 | /* |
| 506 | Generate delegate list. |
| 507 | */ |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 508 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 509 | ResetLinkedListIterator(delegate_list); |
| 510 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 511 | for (i=0; p != (const DelegateInfo *) NULL; ) |
| 512 | { |
| 513 | if ((p->stealth == MagickFalse) && |
| 514 | ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) || |
| 515 | (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))) |
| 516 | delegates[i++]=p; |
| 517 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 518 | } |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 519 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 520 | qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare); |
| 521 | delegates[i]=(DelegateInfo *) NULL; |
| 522 | *number_delegates=(unsigned long) i; |
| 523 | return(delegates); |
| 524 | } |
| 525 | |
| 526 | /* |
| 527 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 528 | % % |
| 529 | % % |
| 530 | % % |
| 531 | % G e t D e l e g a t e L i s t % |
| 532 | % % |
| 533 | % % |
| 534 | % % |
| 535 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 536 | % |
| 537 | % GetDelegateList() returns any image format delegates that match the |
| 538 | % specified pattern. |
| 539 | % |
| 540 | % The format of the GetDelegateList function is: |
| 541 | % |
| 542 | % char **GetDelegateList(const char *pattern, |
| 543 | % unsigned long *number_delegates,ExceptionInfo *exception) |
| 544 | % |
| 545 | % A description of each parameter follows: |
| 546 | % |
| 547 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 548 | % |
| 549 | % o number_delegates: This integer returns the number of delegates |
| 550 | % in the list. |
| 551 | % |
| 552 | % o exception: return any errors or warnings in this structure. |
| 553 | % |
| 554 | */ |
| 555 | |
| 556 | #if defined(__cplusplus) || defined(c_plusplus) |
| 557 | extern "C" { |
| 558 | #endif |
| 559 | |
| 560 | static int DelegateCompare(const void *x,const void *y) |
| 561 | { |
| 562 | register const char |
| 563 | **p, |
| 564 | **q; |
| 565 | |
| 566 | p=(const char **) x; |
| 567 | q=(const char **) y; |
| 568 | return(LocaleCompare(*p,*q)); |
| 569 | } |
| 570 | |
| 571 | #if defined(__cplusplus) || defined(c_plusplus) |
| 572 | } |
| 573 | #endif |
| 574 | |
| 575 | MagickExport char **GetDelegateList(const char *pattern, |
| 576 | unsigned long *number_delegates,ExceptionInfo *exception) |
| 577 | { |
| 578 | char |
| 579 | **delegates; |
| 580 | |
| 581 | register const DelegateInfo |
| 582 | *p; |
| 583 | |
| 584 | register long |
| 585 | i; |
| 586 | |
| 587 | /* |
| 588 | Allocate delegate list. |
| 589 | */ |
| 590 | assert(pattern != (char *) NULL); |
| 591 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
| 592 | assert(number_delegates != (unsigned long *) NULL); |
| 593 | *number_delegates=0; |
| 594 | p=GetDelegateInfo("*","*",exception); |
| 595 | if (p == (const DelegateInfo *) NULL) |
| 596 | return((char **) NULL); |
| 597 | delegates=(char **) AcquireQuantumMemory((size_t) |
| 598 | GetNumberOfElementsInLinkedList(delegate_list)+1UL,sizeof(*delegates)); |
| 599 | if (delegates == (char **) NULL) |
| 600 | return((char **) NULL); |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 601 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 602 | ResetLinkedListIterator(delegate_list); |
| 603 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 604 | for (i=0; p != (const DelegateInfo *) NULL; ) |
| 605 | { |
| 606 | if ((p->stealth == MagickFalse) && |
| 607 | (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse)) |
| 608 | delegates[i++]=ConstantString(p->decode); |
| 609 | if ((p->stealth == MagickFalse) && |
| 610 | (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)) |
| 611 | delegates[i++]=ConstantString(p->encode); |
| 612 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_list); |
| 613 | } |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 614 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 615 | qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare); |
| 616 | delegates[i]=(char *) NULL; |
| 617 | *number_delegates=(unsigned long) i; |
| 618 | return(delegates); |
| 619 | } |
| 620 | |
| 621 | /* |
| 622 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 623 | % % |
| 624 | % % |
| 625 | % % |
| 626 | % G e t D e l e g a t e M o d e % |
| 627 | % % |
| 628 | % % |
| 629 | % % |
| 630 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 631 | % |
| 632 | % GetDelegateMode() returns the mode of the delegate. |
| 633 | % |
| 634 | % The format of the GetDelegateMode method is: |
| 635 | % |
| 636 | % long GetDelegateMode(const DelegateInfo *delegate_info) |
| 637 | % |
| 638 | % A description of each parameter follows: |
| 639 | % |
| 640 | % o delegate_info: The delegate info. |
| 641 | % |
| 642 | */ |
| 643 | MagickExport long GetDelegateMode(const DelegateInfo *delegate_info) |
| 644 | { |
| 645 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 646 | assert(delegate_info != (DelegateInfo *) NULL); |
| 647 | assert(delegate_info->signature == MagickSignature); |
| 648 | return(delegate_info->mode); |
| 649 | } |
| 650 | |
| 651 | /* |
| 652 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 653 | % % |
| 654 | % % |
| 655 | % % |
| 656 | + G e t D e l e g a t e T h r e a d S u p p o r t % |
| 657 | % % |
| 658 | % % |
| 659 | % % |
| 660 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 661 | % |
| 662 | % GetDelegateThreadSupport() returns MagickTrue if the delegate supports |
| 663 | % threads. |
| 664 | % |
| 665 | % The format of the GetDelegateThreadSupport method is: |
| 666 | % |
| 667 | % MagickBooleanType GetDelegateThreadSupport( |
| 668 | % const DelegateInfo *delegate_info) |
| 669 | % |
| 670 | % A description of each parameter follows: |
| 671 | % |
| 672 | % o delegate_info: The delegate info. |
| 673 | % |
| 674 | */ |
| 675 | MagickExport MagickBooleanType GetDelegateThreadSupport( |
| 676 | const DelegateInfo *delegate_info) |
| 677 | { |
| 678 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
| 679 | assert(delegate_info != (DelegateInfo *) NULL); |
| 680 | assert(delegate_info->signature == MagickSignature); |
| 681 | return(delegate_info->thread_support); |
| 682 | } |
| 683 | |
| 684 | /* |
| 685 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 686 | % % |
| 687 | % % |
| 688 | % % |
| 689 | + I n i t i a l i z e D e l e g a t e L i s t % |
| 690 | % % |
| 691 | % % |
| 692 | % % |
| 693 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 694 | % |
| 695 | % InitializeDelegateList() initializes the delegate list. |
| 696 | % |
| 697 | % The format of the InitializeDelegateList method is: |
| 698 | % |
| 699 | % MagickBooleanType InitializeDelegateList(ExceptionInfo *exception) |
| 700 | % |
| 701 | % A description of each parameter follows. |
| 702 | % |
| 703 | % o exception: return any errors or warnings in this structure. |
| 704 | % |
| 705 | */ |
| 706 | static MagickBooleanType InitializeDelegateList(ExceptionInfo *exception) |
| 707 | { |
| 708 | if ((delegate_list == (LinkedListInfo *) NULL) && |
| 709 | (instantiate_delegate == MagickFalse)) |
| 710 | { |
cristy | 4e1dff6 | 2009-10-25 20:36:03 +0000 | [diff] [blame^] | 711 | if (delegate_semaphore == (SemaphoreInfo *) NULL) |
| 712 | AcquireSemaphoreInfo(&delegate_semaphore); |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 713 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 714 | if ((delegate_list == (LinkedListInfo *) NULL) && |
| 715 | (instantiate_delegate == MagickFalse)) |
| 716 | { |
| 717 | (void) LoadDelegateLists(DelegateFilename,exception); |
| 718 | instantiate_delegate=MagickTrue; |
| 719 | } |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 720 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 721 | } |
| 722 | return(delegate_list != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); |
| 723 | } |
| 724 | |
| 725 | /* |
| 726 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 727 | % % |
| 728 | % % |
| 729 | % % |
| 730 | % I n v o k e D e l e g a t e % |
| 731 | % % |
| 732 | % % |
| 733 | % % |
| 734 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 735 | % |
| 736 | % InvokeDelegate replaces any embedded formatting characters with the |
| 737 | % appropriate image attribute and executes the resulting command. MagickFalse |
| 738 | % is returned if the commands execute with success otherwise MagickTrue. |
| 739 | % |
| 740 | % The format of the InvokeDelegate method is: |
| 741 | % |
| 742 | % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image, |
| 743 | % const char *decode,const char *encode,ExceptionInfo *exception) |
| 744 | % |
| 745 | % A description of each parameter follows: |
| 746 | % |
| 747 | % o image_info: the imageInfo. |
| 748 | % |
| 749 | % o image: the image. |
| 750 | % |
| 751 | % o exception: return any errors or warnings in this structure. |
| 752 | % |
| 753 | */ |
| 754 | |
| 755 | static inline size_t MagickMin(const size_t x,const size_t y) |
| 756 | { |
| 757 | if (x < y) |
| 758 | return(x); |
| 759 | return(y); |
| 760 | } |
| 761 | |
| 762 | static MagickBooleanType CopyDelegateFile(const char *source, |
| 763 | const char *destination) |
| 764 | { |
| 765 | int |
| 766 | destination_file, |
| 767 | source_file; |
| 768 | |
| 769 | MagickBooleanType |
| 770 | status; |
| 771 | |
| 772 | register size_t |
| 773 | i; |
| 774 | |
| 775 | size_t |
| 776 | length, |
| 777 | quantum; |
| 778 | |
| 779 | ssize_t |
| 780 | count; |
| 781 | |
| 782 | struct stat |
| 783 | attributes; |
| 784 | |
| 785 | unsigned char |
| 786 | *buffer; |
| 787 | |
| 788 | /* |
| 789 | Return if destination file already exists and is not empty. |
| 790 | */ |
| 791 | assert(source != (const char *) NULL); |
| 792 | assert(destination != (char *) NULL); |
| 793 | status=GetPathAttributes(destination,&attributes); |
| 794 | if ((status != MagickFalse) && (attributes.st_size != 0)) |
| 795 | return(MagickTrue); |
| 796 | /* |
| 797 | Copy source file to destination. |
| 798 | */ |
| 799 | destination_file=open(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE); |
| 800 | if (destination_file == -1) |
| 801 | return(MagickFalse); |
| 802 | source_file=open(source,O_RDONLY | O_BINARY); |
| 803 | if (source_file == -1) |
| 804 | { |
| 805 | (void) close(destination_file); |
| 806 | return(MagickFalse); |
| 807 | } |
| 808 | quantum=(size_t) MagickMaxBufferExtent; |
| 809 | if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0)) |
| 810 | quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent); |
| 811 | buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer)); |
| 812 | if (buffer == (unsigned char *) NULL) |
| 813 | { |
| 814 | (void) close(source_file); |
| 815 | (void) close(destination_file); |
| 816 | return(MagickFalse); |
| 817 | } |
| 818 | length=0; |
| 819 | for (i=0; ; i+=count) |
| 820 | { |
| 821 | count=(ssize_t) read(source_file,buffer,quantum); |
| 822 | if (count <= 0) |
| 823 | break; |
| 824 | length=(size_t) count; |
| 825 | count=(ssize_t) write(destination_file,buffer,length); |
| 826 | if ((size_t) count != length) |
| 827 | break; |
| 828 | } |
| 829 | (void) close(destination_file); |
| 830 | (void) close(source_file); |
| 831 | buffer=(unsigned char *) RelinquishMagickMemory(buffer); |
| 832 | return(i != 0 ? MagickTrue : MagickFalse); |
| 833 | } |
| 834 | |
| 835 | MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, |
| 836 | Image *image,const char *decode,const char *encode,ExceptionInfo *exception) |
| 837 | { |
| 838 | char |
| 839 | *command, |
| 840 | **commands, |
| 841 | input_filename[MaxTextExtent], |
| 842 | output_filename[MaxTextExtent]; |
| 843 | |
| 844 | const DelegateInfo |
| 845 | *delegate_info; |
| 846 | |
| 847 | MagickBooleanType |
| 848 | status, |
| 849 | temporary; |
| 850 | |
| 851 | register long |
| 852 | i; |
| 853 | |
| 854 | PolicyRights |
| 855 | rights; |
| 856 | |
| 857 | /* |
| 858 | Get delegate. |
| 859 | */ |
| 860 | assert(image_info != (ImageInfo *) NULL); |
| 861 | assert(image_info->signature == MagickSignature); |
| 862 | assert(image != (Image *) NULL); |
| 863 | assert(image->signature == MagickSignature); |
| 864 | if (image->debug != MagickFalse) |
| 865 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 866 | rights=ExecutePolicyRights; |
| 867 | if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse) |
| 868 | { |
| 869 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
| 870 | "NotAuthorized","`%s'",decode); |
| 871 | return(MagickFalse); |
| 872 | } |
| 873 | if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse) |
| 874 | { |
| 875 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
| 876 | "NotAuthorized","`%s'",encode); |
| 877 | return(MagickFalse); |
| 878 | } |
| 879 | temporary=(*image->filename == '\0') ? MagickTrue : MagickFalse; |
| 880 | if (temporary != MagickFalse) |
| 881 | if (AcquireUniqueFilename(image->filename) == MagickFalse) |
| 882 | { |
| 883 | ThrowFileException(exception,FileOpenError, |
| 884 | "UnableToCreateTemporaryFile",image->filename); |
| 885 | return(MagickFalse); |
| 886 | } |
| 887 | delegate_info=GetDelegateInfo(decode,encode,exception); |
| 888 | if (delegate_info == (DelegateInfo *) NULL) |
| 889 | { |
| 890 | if (temporary != MagickFalse) |
| 891 | (void) RelinquishUniqueFileResource(image->filename); |
| 892 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
| 893 | "NoTagFound","`%s'",decode ? decode : encode); |
| 894 | return(MagickFalse); |
| 895 | } |
| 896 | if (*image_info->filename == '\0') |
| 897 | { |
| 898 | if (AcquireUniqueFilename(image_info->filename) == MagickFalse) |
| 899 | { |
| 900 | if (temporary != MagickFalse) |
| 901 | (void) RelinquishUniqueFileResource(image->filename); |
| 902 | ThrowFileException(exception,FileOpenError, |
| 903 | "UnableToCreateTemporaryFile",image_info->filename); |
| 904 | return(MagickFalse); |
| 905 | } |
| 906 | image_info->temporary=MagickTrue; |
| 907 | } |
| 908 | if ((delegate_info->mode != 0) && |
| 909 | (((decode != (const char *) NULL) && |
| 910 | (delegate_info->encode != (char *) NULL)) || |
| 911 | ((encode != (const char *) NULL) && |
| 912 | (delegate_info->decode != (char *) NULL)))) |
| 913 | { |
| 914 | char |
| 915 | *magick; |
| 916 | |
| 917 | ImageInfo |
| 918 | *clone_info; |
| 919 | |
| 920 | register Image |
| 921 | *p; |
| 922 | |
| 923 | /* |
| 924 | Delegate requires a particular image format. |
| 925 | */ |
| 926 | if (AcquireUniqueFilename(image_info->unique) == MagickFalse) |
| 927 | { |
| 928 | ThrowFileException(exception,FileOpenError, |
| 929 | "UnableToCreateTemporaryFile",image_info->unique); |
| 930 | return(MagickFalse); |
| 931 | } |
| 932 | if (AcquireUniqueFilename(image_info->zero) == MagickFalse) |
| 933 | { |
| 934 | (void) RelinquishUniqueFileResource(image_info->zero); |
| 935 | ThrowFileException(exception,FileOpenError, |
| 936 | "UnableToCreateTemporaryFile",image_info->zero); |
| 937 | return(MagickFalse); |
| 938 | } |
| 939 | magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ? |
| 940 | delegate_info->encode : delegate_info->decode); |
| 941 | if (magick == (char *) NULL) |
| 942 | { |
| 943 | (void) RelinquishUniqueFileResource(image_info->unique); |
| 944 | (void) RelinquishUniqueFileResource(image_info->zero); |
| 945 | if (temporary != MagickFalse) |
| 946 | (void) RelinquishUniqueFileResource(image->filename); |
| 947 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 948 | DelegateError,"DelegateFailed","`%s'",decode ? decode : encode); |
| 949 | return(MagickFalse); |
| 950 | } |
| 951 | LocaleUpper(magick); |
| 952 | clone_info=CloneImageInfo(image_info); |
| 953 | (void) CopyMagickString((char *) clone_info->magick,magick, |
| 954 | MaxTextExtent); |
| 955 | if (LocaleCompare(magick,"NULL") != 0) |
| 956 | (void) CopyMagickString(image->magick,magick,MaxTextExtent); |
| 957 | magick=DestroyString(magick); |
| 958 | (void) FormatMagickString(clone_info->filename,MaxTextExtent,"%s:", |
| 959 | delegate_info->decode); |
| 960 | (void) SetImageInfo(clone_info,MagickTrue,exception); |
| 961 | (void) CopyMagickString(clone_info->filename,image_info->filename, |
| 962 | MaxTextExtent); |
| 963 | (void) CopyMagickString(image_info->filename,image->filename, |
| 964 | MaxTextExtent); |
| 965 | for (p=image; p != (Image *) NULL; p=GetNextImageInList(p)) |
| 966 | { |
| 967 | (void) FormatMagickString(p->filename,MaxTextExtent,"%s:%s", |
| 968 | delegate_info->decode,clone_info->filename); |
| 969 | status=WriteImage(clone_info,p); |
| 970 | if (status == MagickFalse) |
| 971 | { |
| 972 | (void) RelinquishUniqueFileResource(image_info->unique); |
| 973 | (void) RelinquishUniqueFileResource(image_info->zero); |
| 974 | if (temporary != MagickFalse) |
| 975 | (void) RelinquishUniqueFileResource(image->filename); |
| 976 | clone_info=DestroyImageInfo(clone_info); |
| 977 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 978 | DelegateError,"DelegateFailed","`%s'",decode ? decode : encode); |
| 979 | return(MagickFalse); |
| 980 | } |
| 981 | if (clone_info->adjoin != MagickFalse) |
| 982 | break; |
| 983 | } |
| 984 | (void) RelinquishUniqueFileResource(image_info->unique); |
| 985 | (void) RelinquishUniqueFileResource(image_info->zero); |
| 986 | clone_info=DestroyImageInfo(clone_info); |
| 987 | } |
| 988 | /* |
| 989 | Invoke delegate. |
| 990 | */ |
| 991 | commands=StringToList(delegate_info->commands); |
| 992 | if (commands == (char **) NULL) |
| 993 | { |
| 994 | if (temporary != MagickFalse) |
| 995 | (void) RelinquishUniqueFileResource(image->filename); |
| 996 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 997 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 998 | decode ? decode : encode); |
| 999 | return(MagickFalse); |
| 1000 | } |
| 1001 | command=(char *) NULL; |
| 1002 | status=MagickFalse; |
| 1003 | (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent); |
| 1004 | (void) CopyMagickString(input_filename,image->filename,MaxTextExtent); |
| 1005 | for (i=0; commands[i] != (char *) NULL; i++) |
| 1006 | { |
| 1007 | status=AcquireUniqueSymbolicLink(output_filename,image_info->filename); |
| 1008 | if (AcquireUniqueFilename(image_info->unique) == MagickFalse) |
| 1009 | { |
| 1010 | ThrowFileException(exception,FileOpenError, |
| 1011 | "UnableToCreateTemporaryFile",image_info->unique); |
| 1012 | break; |
| 1013 | } |
| 1014 | if (AcquireUniqueFilename(image_info->zero) == MagickFalse) |
| 1015 | { |
| 1016 | (void) RelinquishUniqueFileResource(image_info->unique); |
| 1017 | ThrowFileException(exception,FileOpenError, |
| 1018 | "UnableToCreateTemporaryFile",image_info->zero); |
| 1019 | break; |
| 1020 | } |
| 1021 | if (LocaleCompare(decode,"SCAN") != 0) |
| 1022 | { |
| 1023 | status=AcquireUniqueSymbolicLink(input_filename,image->filename); |
| 1024 | if (status == MagickFalse) |
| 1025 | { |
| 1026 | ThrowFileException(exception,FileOpenError, |
| 1027 | "UnableToCreateTemporaryFile",input_filename); |
| 1028 | break; |
| 1029 | } |
| 1030 | } |
| 1031 | status=MagickFalse; |
| 1032 | command=InterpretImageProperties(image_info,image,commands[i]); |
| 1033 | if (command != (char *) NULL) |
| 1034 | { |
| 1035 | /* |
| 1036 | Execute delegate. |
| 1037 | */ |
| 1038 | if (delegate_info->spawn != MagickFalse) |
| 1039 | (void) ConcatenateString(&command," &"); |
cristy | b32b90a | 2009-09-07 21:45:48 +0000 | [diff] [blame] | 1040 | status=SystemCommand(image_info->verbose,command,exception) != 0 ? |
| 1041 | MagickTrue : MagickFalse; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1042 | if (delegate_info->spawn != MagickFalse) |
| 1043 | (void) sleep(2); |
| 1044 | command=DestroyString(command); |
| 1045 | } |
| 1046 | if (LocaleCompare(decode,"SCAN") != 0) |
| 1047 | { |
| 1048 | if (CopyDelegateFile(image->filename,input_filename) == MagickFalse) |
| 1049 | (void) RelinquishUniqueFileResource(input_filename); |
| 1050 | } |
| 1051 | if (CopyDelegateFile(image_info->filename,output_filename) == MagickFalse) |
| 1052 | (void) RelinquishUniqueFileResource(output_filename); |
| 1053 | if (image_info->temporary != MagickFalse) |
| 1054 | (void) RelinquishUniqueFileResource(image_info->filename); |
| 1055 | (void) RelinquishUniqueFileResource(image_info->unique); |
| 1056 | (void) RelinquishUniqueFileResource(image_info->zero); |
| 1057 | (void) RelinquishUniqueFileResource(image_info->filename); |
| 1058 | (void) RelinquishUniqueFileResource(image->filename); |
| 1059 | if (status != MagickFalse) |
| 1060 | { |
| 1061 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
| 1062 | "DelegateFailed","`%s'",commands[i]); |
| 1063 | break; |
| 1064 | } |
| 1065 | commands[i]=DestroyString(commands[i]); |
| 1066 | } |
| 1067 | (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent); |
| 1068 | (void) CopyMagickString(image->filename,input_filename,MaxTextExtent); |
| 1069 | /* |
| 1070 | Relinquish resources. |
| 1071 | */ |
| 1072 | for ( ; commands[i] != (char *) NULL; i++) |
| 1073 | commands[i]=DestroyString(commands[i]); |
| 1074 | commands=(char **) RelinquishMagickMemory(commands); |
| 1075 | if (temporary != MagickFalse) |
| 1076 | (void) RelinquishUniqueFileResource(image->filename); |
| 1077 | return(status == MagickFalse ? MagickTrue : MagickFalse); |
| 1078 | } |
| 1079 | |
| 1080 | /* |
| 1081 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1082 | % % |
| 1083 | % % |
| 1084 | % % |
| 1085 | % L i s t D e l e g a t e I n f o % |
| 1086 | % % |
| 1087 | % % |
| 1088 | % % |
| 1089 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1090 | % |
| 1091 | % ListDelegateInfo() lists the image formats to a file. |
| 1092 | % |
| 1093 | % The format of the ListDelegateInfo method is: |
| 1094 | % |
| 1095 | % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception) |
| 1096 | % |
| 1097 | % A description of each parameter follows. |
| 1098 | % |
| 1099 | % o file: An pointer to a FILE. |
| 1100 | % |
| 1101 | % o exception: return any errors or warnings in this structure. |
| 1102 | % |
| 1103 | */ |
| 1104 | MagickExport MagickBooleanType ListDelegateInfo(FILE *file, |
| 1105 | ExceptionInfo *exception) |
| 1106 | { |
| 1107 | const DelegateInfo |
| 1108 | **delegate_info; |
| 1109 | |
| 1110 | char |
| 1111 | **commands, |
| 1112 | delegate[MaxTextExtent]; |
| 1113 | |
| 1114 | const char |
| 1115 | *path; |
| 1116 | |
| 1117 | long |
| 1118 | j; |
| 1119 | |
| 1120 | register long |
| 1121 | i; |
| 1122 | |
| 1123 | unsigned long |
| 1124 | number_delegates; |
| 1125 | |
| 1126 | if (file == (const FILE *) NULL) |
| 1127 | file=stdout; |
| 1128 | delegate_info=GetDelegateInfoList("*",&number_delegates,exception); |
| 1129 | if (delegate_info == (const DelegateInfo **) NULL) |
| 1130 | return(MagickFalse); |
| 1131 | path=(const char *) NULL; |
| 1132 | for (i=0; i < (long) number_delegates; i++) |
| 1133 | { |
| 1134 | if (delegate_info[i]->stealth != MagickFalse) |
| 1135 | continue; |
| 1136 | if ((path == (const char *) NULL) || |
| 1137 | (LocaleCompare(path,delegate_info[i]->path) != 0)) |
| 1138 | { |
| 1139 | if (delegate_info[i]->path != (char *) NULL) |
| 1140 | (void) fprintf(file,"\nPath: %s\n\n",delegate_info[i]->path); |
| 1141 | (void) fprintf(file,"Delegate Command\n"); |
| 1142 | (void) fprintf(file,"-------------------------------------------------" |
| 1143 | "------------------------------\n"); |
| 1144 | } |
| 1145 | path=delegate_info[i]->path; |
| 1146 | *delegate='\0'; |
| 1147 | if (delegate_info[i]->encode != (char *) NULL) |
| 1148 | (void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent); |
| 1149 | (void) ConcatenateMagickString(delegate," ",MaxTextExtent); |
| 1150 | delegate[8]='\0'; |
| 1151 | commands=StringToList(delegate_info[i]->commands); |
| 1152 | if (commands == (char **) NULL) |
| 1153 | continue; |
| 1154 | (void) fprintf(file,"%11s%c=%c%s ",delegate_info[i]->decode ? |
| 1155 | delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ', |
| 1156 | delegate_info[i]->mode >= 0 ? '>' : ' ',delegate); |
| 1157 | StripString(commands[0]); |
| 1158 | (void) fprintf(file,"\"%s\"\n",commands[0]); |
| 1159 | for (j=1; commands[j] != (char *) NULL; j++) |
| 1160 | { |
| 1161 | StripString(commands[j]); |
| 1162 | (void) fprintf(file," \"%s\"\n",commands[j]); |
| 1163 | } |
| 1164 | for (j=0; commands[j] != (char *) NULL; j++) |
| 1165 | commands[j]=DestroyString(commands[j]); |
| 1166 | commands=(char **) RelinquishMagickMemory(commands); |
| 1167 | } |
| 1168 | (void) fflush(file); |
| 1169 | delegate_info=(const DelegateInfo **) |
| 1170 | RelinquishMagickMemory((void *) delegate_info); |
| 1171 | return(MagickTrue); |
| 1172 | } |
| 1173 | |
| 1174 | /* |
| 1175 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1176 | % % |
| 1177 | % % |
| 1178 | % % |
| 1179 | + L o a d D e l e g a t e L i s t % |
| 1180 | % % |
| 1181 | % % |
| 1182 | % % |
| 1183 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1184 | % |
| 1185 | % LoadDelegateList() loads the delegate configuration file which provides a |
| 1186 | % mapping between delegate attributes and a delegate name. |
| 1187 | % |
| 1188 | % The format of the LoadDelegateList method is: |
| 1189 | % |
| 1190 | % MagickBooleanType LoadDelegateList(const char *xml,const char *filename, |
| 1191 | % const unsigned long depth,ExceptionInfo *exception) |
| 1192 | % |
| 1193 | % A description of each parameter follows: |
| 1194 | % |
| 1195 | % o xml: The delegate list in XML format. |
| 1196 | % |
| 1197 | % o filename: The delegate list filename. |
| 1198 | % |
| 1199 | % o depth: depth of <include /> statements. |
| 1200 | % |
| 1201 | % o exception: return any errors or warnings in this structure. |
| 1202 | % |
| 1203 | */ |
| 1204 | static MagickBooleanType LoadDelegateList(const char *xml,const char *filename, |
| 1205 | const unsigned long depth,ExceptionInfo *exception) |
| 1206 | { |
| 1207 | char |
| 1208 | keyword[MaxTextExtent], |
| 1209 | *token; |
| 1210 | |
| 1211 | const char |
| 1212 | *q; |
| 1213 | |
| 1214 | DelegateInfo |
| 1215 | *delegate_info; |
| 1216 | |
| 1217 | MagickBooleanType |
| 1218 | status; |
| 1219 | |
| 1220 | /* |
| 1221 | Load the delegate map file. |
| 1222 | */ |
| 1223 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 1224 | "Loading delegate configuration file \"%s\" ...",filename); |
| 1225 | if (xml == (const char *) NULL) |
| 1226 | return(MagickFalse); |
| 1227 | if (delegate_list == (LinkedListInfo *) NULL) |
| 1228 | { |
| 1229 | delegate_list=NewLinkedList(0); |
| 1230 | if (delegate_list == (LinkedListInfo *) NULL) |
| 1231 | { |
| 1232 | ThrowFileException(exception,ResourceLimitError, |
| 1233 | "MemoryAllocationFailed",filename); |
| 1234 | return(MagickFalse); |
| 1235 | } |
| 1236 | } |
| 1237 | status=MagickTrue; |
| 1238 | delegate_info=(DelegateInfo *) NULL; |
| 1239 | token=AcquireString(xml); |
| 1240 | for (q=(const char *) xml; *q != '\0'; ) |
| 1241 | { |
| 1242 | /* |
| 1243 | Interpret XML. |
| 1244 | */ |
| 1245 | GetMagickToken(q,&q,token); |
| 1246 | if (*token == '\0') |
| 1247 | break; |
| 1248 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1249 | if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) |
| 1250 | { |
| 1251 | /* |
| 1252 | Doctype element. |
| 1253 | */ |
| 1254 | while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) |
| 1255 | GetMagickToken(q,&q,token); |
| 1256 | continue; |
| 1257 | } |
| 1258 | if (LocaleNCompare(keyword,"<!--",4) == 0) |
| 1259 | { |
| 1260 | /* |
| 1261 | Comment element. |
| 1262 | */ |
| 1263 | while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) |
| 1264 | GetMagickToken(q,&q,token); |
| 1265 | continue; |
| 1266 | } |
| 1267 | if (LocaleCompare(keyword,"<include") == 0) |
| 1268 | { |
| 1269 | /* |
| 1270 | Include element. |
| 1271 | */ |
| 1272 | while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) |
| 1273 | { |
| 1274 | (void) CopyMagickString(keyword,token,MaxTextExtent); |
| 1275 | GetMagickToken(q,&q,token); |
| 1276 | if (*token != '=') |
| 1277 | continue; |
| 1278 | GetMagickToken(q,&q,token); |
| 1279 | if (LocaleCompare(keyword,"file") == 0) |
| 1280 | { |
| 1281 | if (depth > 200) |
| 1282 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1283 | ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); |
| 1284 | else |
| 1285 | { |
| 1286 | char |
| 1287 | path[MaxTextExtent], |
| 1288 | *xml; |
| 1289 | |
| 1290 | GetPathComponent(filename,HeadPath,path); |
| 1291 | if (*path != '\0') |
| 1292 | (void) ConcatenateMagickString(path,DirectorySeparator, |
| 1293 | MaxTextExtent); |
| 1294 | if (*token == *DirectorySeparator) |
| 1295 | (void) CopyMagickString(path,token,MaxTextExtent); |
| 1296 | else |
| 1297 | (void) ConcatenateMagickString(path,token,MaxTextExtent); |
| 1298 | xml=FileToString(path,~0,exception); |
| 1299 | if (xml != (char *) NULL) |
| 1300 | { |
| 1301 | status=LoadDelegateList(xml,path,depth+1,exception); |
| 1302 | xml=(char *) RelinquishMagickMemory(xml); |
| 1303 | } |
| 1304 | } |
| 1305 | } |
| 1306 | } |
| 1307 | continue; |
| 1308 | } |
| 1309 | if (LocaleCompare(keyword,"<delegate") == 0) |
| 1310 | { |
| 1311 | /* |
| 1312 | Delegate element. |
| 1313 | */ |
| 1314 | delegate_info=(DelegateInfo *) AcquireMagickMemory( |
| 1315 | sizeof(*delegate_info)); |
| 1316 | if (delegate_info == (DelegateInfo *) NULL) |
| 1317 | ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); |
| 1318 | (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info)); |
| 1319 | delegate_info->path=ConstantString(filename); |
| 1320 | delegate_info->signature=MagickSignature; |
| 1321 | continue; |
| 1322 | } |
| 1323 | if (delegate_info == (DelegateInfo *) NULL) |
| 1324 | continue; |
| 1325 | if (LocaleCompare(keyword,"/>") == 0) |
| 1326 | { |
| 1327 | status=AppendValueToLinkedList(delegate_list,delegate_info); |
| 1328 | if (status == MagickFalse) |
| 1329 | (void) ThrowMagickException(exception,GetMagickModule(), |
| 1330 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
| 1331 | delegate_info->commands); |
| 1332 | delegate_info=(DelegateInfo *) NULL; |
| 1333 | } |
| 1334 | GetMagickToken(q,(const char **) NULL,token); |
| 1335 | if (*token != '=') |
| 1336 | continue; |
| 1337 | GetMagickToken(q,&q,token); |
| 1338 | GetMagickToken(q,&q,token); |
| 1339 | switch (*keyword) |
| 1340 | { |
| 1341 | case 'C': |
| 1342 | case 'c': |
| 1343 | { |
| 1344 | if (LocaleCompare((char *) keyword,"command") == 0) |
| 1345 | { |
| 1346 | char |
| 1347 | *commands; |
| 1348 | |
| 1349 | commands=AcquireString(token); |
| 1350 | #if defined(__WINDOWS__) |
| 1351 | if (strchr(commands,'@') != (char *) NULL) |
| 1352 | { |
| 1353 | char |
| 1354 | path[MaxTextExtent]; |
| 1355 | |
| 1356 | NTGhostscriptEXE(path,MaxTextExtent); |
| 1357 | (void) SubstituteString((char **) &commands,"@PSDelegate@", |
| 1358 | path); |
| 1359 | (void) SubstituteString((char **) &commands,"\\","/"); |
| 1360 | } |
| 1361 | #endif |
| 1362 | (void) SubstituteString((char **) &commands,"&","&"); |
| 1363 | (void) SubstituteString((char **) &commands,""","\""); |
| 1364 | (void) SubstituteString((char **) &commands,">",">"); |
| 1365 | (void) SubstituteString((char **) &commands,"<","<"); |
| 1366 | delegate_info->commands=commands; |
| 1367 | break; |
| 1368 | } |
| 1369 | break; |
| 1370 | } |
| 1371 | case 'D': |
| 1372 | case 'd': |
| 1373 | { |
| 1374 | if (LocaleCompare((char *) keyword,"decode") == 0) |
| 1375 | { |
| 1376 | delegate_info->decode=ConstantString(token); |
| 1377 | delegate_info->mode=1; |
| 1378 | break; |
| 1379 | } |
| 1380 | break; |
| 1381 | } |
| 1382 | case 'E': |
| 1383 | case 'e': |
| 1384 | { |
| 1385 | if (LocaleCompare((char *) keyword,"encode") == 0) |
| 1386 | { |
| 1387 | delegate_info->encode=ConstantString(token); |
| 1388 | delegate_info->mode=(-1); |
| 1389 | break; |
| 1390 | } |
| 1391 | break; |
| 1392 | } |
| 1393 | case 'M': |
| 1394 | case 'm': |
| 1395 | { |
| 1396 | if (LocaleCompare((char *) keyword,"mode") == 0) |
| 1397 | { |
| 1398 | delegate_info->mode=1; |
| 1399 | if (LocaleCompare(token,"bi") == 0) |
| 1400 | delegate_info->mode=0; |
| 1401 | else |
| 1402 | if (LocaleCompare(token,"encode") == 0) |
| 1403 | delegate_info->mode=(-1); |
| 1404 | break; |
| 1405 | } |
| 1406 | break; |
| 1407 | } |
| 1408 | case 'S': |
| 1409 | case 's': |
| 1410 | { |
| 1411 | if (LocaleCompare((char *) keyword,"spawn") == 0) |
| 1412 | { |
| 1413 | delegate_info->spawn=IsMagickTrue(token); |
| 1414 | break; |
| 1415 | } |
| 1416 | if (LocaleCompare((char *) keyword,"stealth") == 0) |
| 1417 | { |
| 1418 | delegate_info->stealth=IsMagickTrue(token); |
| 1419 | break; |
| 1420 | } |
| 1421 | break; |
| 1422 | } |
| 1423 | case 'T': |
| 1424 | case 't': |
| 1425 | { |
| 1426 | if (LocaleCompare((char *) keyword,"thread-support") == 0) |
| 1427 | { |
| 1428 | delegate_info->thread_support=IsMagickTrue(token); |
| 1429 | break; |
| 1430 | } |
| 1431 | break; |
| 1432 | } |
| 1433 | default: |
| 1434 | break; |
| 1435 | } |
| 1436 | } |
| 1437 | token=(char *) RelinquishMagickMemory(token); |
| 1438 | return(status); |
| 1439 | } |
| 1440 | |
| 1441 | /* |
| 1442 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1443 | % % |
| 1444 | % % |
| 1445 | % % |
| 1446 | % L o a d D e l e g a t e L i s t s % |
| 1447 | % % |
| 1448 | % % |
| 1449 | % % |
| 1450 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1451 | % |
| 1452 | % LoadDelegateList() loads one or more delegate configuration file which |
| 1453 | % provides a mapping between delegate attributes and a delegate name. |
| 1454 | % |
| 1455 | % The format of the LoadDelegateLists method is: |
| 1456 | % |
| 1457 | % MagickBooleanType LoadDelegateLists(const char *filename, |
| 1458 | % ExceptionInfo *exception) |
| 1459 | % |
| 1460 | % A description of each parameter follows: |
| 1461 | % |
| 1462 | % o filename: the font file name. |
| 1463 | % |
| 1464 | % o exception: return any errors or warnings in this structure. |
| 1465 | % |
| 1466 | */ |
| 1467 | static MagickBooleanType LoadDelegateLists(const char *filename, |
| 1468 | ExceptionInfo *exception) |
| 1469 | { |
| 1470 | #if defined(MAGICKCORE_EMBEDDABLE_SUPPORT) |
| 1471 | return(LoadDelegateList(DelegateMap,"built-in",0,exception)); |
| 1472 | #else |
| 1473 | const StringInfo |
| 1474 | *option; |
| 1475 | |
| 1476 | LinkedListInfo |
| 1477 | *options; |
| 1478 | |
| 1479 | MagickStatusType |
| 1480 | status; |
| 1481 | |
| 1482 | status=MagickFalse; |
| 1483 | options=GetConfigureOptions(filename,exception); |
| 1484 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1485 | while (option != (const StringInfo *) NULL) |
| 1486 | { |
| 1487 | status|=LoadDelegateList((const char *) GetStringInfoDatum(option), |
| 1488 | GetStringInfoPath(option),0,exception); |
| 1489 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 1490 | } |
| 1491 | options=DestroyConfigureOptions(options); |
| 1492 | if ((delegate_list == (LinkedListInfo *) NULL) || |
| 1493 | (IsLinkedListEmpty(delegate_list) != MagickFalse)) |
| 1494 | status|=LoadDelegateList(DelegateMap,"built-in",0,exception); |
| 1495 | return(status != 0 ? MagickTrue : MagickFalse); |
| 1496 | #endif |
| 1497 | } |