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