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