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 | 93b707b | 2017-12-06 07:05:51 -0500 | [diff] [blame] | 19 | % Copyright 1999-2018 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 | % % |
Cristy | f19d414 | 2017-04-24 11:34:30 -0400 | [diff] [blame] | 25 | % https://www.imagemagick.org/script/license.php % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 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" |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 49 | #include "MagickCore/artifact.h" |
| 50 | #include "MagickCore/attribute.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 51 | #include "MagickCore/blob.h" |
| 52 | #include "MagickCore/client.h" |
| 53 | #include "MagickCore/configure.h" |
| 54 | #include "MagickCore/constitute.h" |
| 55 | #include "MagickCore/delegate.h" |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 56 | #include "MagickCore/delegate-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 57 | #include "MagickCore/exception.h" |
| 58 | #include "MagickCore/exception-private.h" |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 59 | #include "MagickCore/fx-private.h" |
dirk | 007e925 | 2015-01-15 21:02:57 +0000 | [diff] [blame] | 60 | #include "MagickCore/image-private.h" |
dirk | abed7e2 | 2016-01-31 17:10:21 +0100 | [diff] [blame] | 61 | #include "MagickCore/linked-list.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 62 | #include "MagickCore/list.h" |
| 63 | #include "MagickCore/memory_.h" |
Dirk Lemstra | 06344a0 | 2017-10-15 10:10:01 +0200 | [diff] [blame] | 64 | #include "MagickCore/memory-private.h" |
cristy | 1e37e8f | 2014-02-21 17:05:37 +0000 | [diff] [blame] | 65 | #include "MagickCore/nt-base-private.h" |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 66 | #include "MagickCore/option.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 67 | #include "MagickCore/policy.h" |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 68 | #include "MagickCore/property.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 69 | #include "MagickCore/resource_.h" |
| 70 | #include "MagickCore/semaphore.h" |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 71 | #include "MagickCore/signature.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 72 | #include "MagickCore/string_.h" |
| 73 | #include "MagickCore/token.h" |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 74 | #include "MagickCore/token-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 75 | #include "MagickCore/utility.h" |
cristy | d1dd6e4 | 2011-09-04 01:46:08 +0000 | [diff] [blame] | 76 | #include "MagickCore/utility-private.h" |
cristy | 4c08aed | 2011-07-01 19:47:50 +0000 | [diff] [blame] | 77 | #include "MagickCore/xml-tree.h" |
cristy | 3291f51 | 2014-03-16 22:16:22 +0000 | [diff] [blame] | 78 | #include "MagickCore/xml-tree-private.h" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 79 | |
| 80 | /* |
| 81 | Define declarations. |
| 82 | */ |
| 83 | #define DelegateFilename "delegates.xml" |
| 84 | |
| 85 | /* |
| 86 | Declare delegate map. |
| 87 | */ |
| 88 | static const char |
| 89 | *DelegateMap = (const char *) |
| 90 | "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" |
| 91 | "<delegatemap>" |
| 92 | " <delegate decode=\"autotrace\" stealth=\"True\" command=\""autotrace" -output-format svg -output-file "%o" "%i"\"/>" |
| 93 | " <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] | 94 | " <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] | 95 | " <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] | 96 | " <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] | 97 | " <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] | 98 | " <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] | 99 | " <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] | 100 | " <delegate decode=\"fig\" command=\""fig2dev" -L ps "%i" "%o"\"/>" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 101 | " <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] | 102 | " <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] | 103 | " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
| 104 | " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
Cristy | 5f478ca | 2016-05-14 18:43:20 -0400 | [diff] [blame] | 105 | " <delegate decode=\"https\" command=\""curl" -s -k -L -o "%o" "https:%M"\"/>" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 106 | " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>" |
| 107 | " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>" |
cristy | 53798ff | 2015-05-08 18:28:24 +0000 | [diff] [blame] | 108 | " <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"\"/>" |
Cristy | 5f478ca | 2016-05-14 18:43:20 -0400 | [diff] [blame] | 109 | " <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] | 110 | " <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"\"/>" |
| 111 | " <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"\"/>" |
| 112 | " <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] | 113 | " <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"\"/>" |
| 114 | " <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] | 115 | " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>" |
| 116 | " <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>" |
| 117 | " <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] | 118 | " <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] | 119 | " <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] | 120 | " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>" |
cristy | a7bb1c4 | 2012-11-18 00:27:49 +0000 | [diff] [blame] | 121 | " <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"\"/>" |
| 122 | " <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"\"/>" |
| 123 | " <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"\"/>" |
| 124 | " <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"\"/>" |
| 125 | " <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] | 126 | " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>" |
| 127 | " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>" |
Cristy | 5f478ca | 2016-05-14 18:43:20 -0400 | [diff] [blame] | 128 | " <delegate encode=\"show\" spawn=\"True\" command=\""display" -immutable -delay 0 -title "%M" "%i"\"/>" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 129 | " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>" |
cristy | 4689cf0 | 2010-02-17 21:15:45 +0000 | [diff] [blame] | 130 | " <delegate decode=\"svg\" command=\""rsvg" "%i" "%o"\"/>" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 131 | " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>" |
Cristy | 5f478ca | 2016-05-14 18:43:20 -0400 | [diff] [blame] | 132 | " <delegate encode=\"win\" stealth=\"True\" spawn=\"True\" command=\""display" -immutable -delay 0 -title "%M" "%i"\"/>" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 133 | " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>" |
| 134 | "</delegatemap>"; |
| 135 | |
| 136 | /* |
| 137 | Global declaractions. |
| 138 | */ |
| 139 | static LinkedListInfo |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 140 | *delegate_cache = (LinkedListInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 141 | |
| 142 | static SemaphoreInfo |
| 143 | *delegate_semaphore = (SemaphoreInfo *) NULL; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 144 | |
| 145 | /* |
| 146 | Forward declaractions. |
| 147 | */ |
| 148 | static MagickBooleanType |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 149 | IsDelegateCacheInstantiated(ExceptionInfo *), |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 150 | LoadDelegateCache(LinkedListInfo *,const char *,const char *,const size_t, |
| 151 | ExceptionInfo *); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 152 | |
| 153 | /* |
| 154 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 155 | % % |
| 156 | % % |
| 157 | % % |
| 158 | % A c q u i r e D e l e g a t e C a c h e % |
| 159 | % % |
| 160 | % % |
| 161 | % % |
| 162 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 163 | % |
| 164 | % AcquireDelegateCache() caches one or more delegate configurations which |
| 165 | % provides a mapping between delegate attributes and a delegate name. |
| 166 | % |
| 167 | % The format of the AcquireDelegateCache method is: |
| 168 | % |
| 169 | % LinkedListInfo *AcquireDelegateCache(const char *filename, |
| 170 | % ExceptionInfo *exception) |
| 171 | % |
| 172 | % A description of each parameter follows: |
| 173 | % |
| 174 | % o filename: the font file name. |
| 175 | % |
| 176 | % o exception: return any errors or warnings in this structure. |
| 177 | % |
| 178 | */ |
| 179 | static LinkedListInfo *AcquireDelegateCache(const char *filename, |
| 180 | ExceptionInfo *exception) |
| 181 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 182 | LinkedListInfo |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 183 | *cache; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 184 | |
| 185 | MagickStatusType |
| 186 | status; |
| 187 | |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 188 | cache=NewLinkedList(0); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 189 | status=MagickTrue; |
cristy | 191ba5c | 2014-03-16 21:26:40 +0000 | [diff] [blame] | 190 | #if !defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 191 | { |
cristy | 66f8c5f | 2014-03-17 00:12:14 +0000 | [diff] [blame] | 192 | const StringInfo |
| 193 | *option; |
| 194 | |
| 195 | LinkedListInfo |
| 196 | *options; |
| 197 | |
| 198 | options=GetConfigureOptions(filename,exception); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 199 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
cristy | 66f8c5f | 2014-03-17 00:12:14 +0000 | [diff] [blame] | 200 | while (option != (const StringInfo *) NULL) |
| 201 | { |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 202 | status&=LoadDelegateCache(cache,(const char *) |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 203 | GetStringInfoDatum(option),GetStringInfoPath(option),0,exception); |
cristy | 66f8c5f | 2014-03-17 00:12:14 +0000 | [diff] [blame] | 204 | option=(const StringInfo *) GetNextValueInLinkedList(options); |
| 205 | } |
| 206 | options=DestroyConfigureOptions(options); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 207 | } |
cristy | 191ba5c | 2014-03-16 21:26:40 +0000 | [diff] [blame] | 208 | #endif |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 209 | if (IsLinkedListEmpty(cache) != MagickFalse) |
| 210 | status&=LoadDelegateCache(cache,DelegateMap,"built-in",0,exception); |
| 211 | return(cache); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 212 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 213 | |
| 214 | /* |
| 215 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 216 | % % |
| 217 | % % |
| 218 | % % |
cristy | 0d8101e | 2014-04-10 00:13:05 +0000 | [diff] [blame] | 219 | + 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] | 220 | % % |
| 221 | % % |
| 222 | % % |
| 223 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 224 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 225 | % DelegateComponentGenesis() instantiates the delegate component. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 226 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 227 | % The format of the DelegateComponentGenesis method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 228 | % |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 229 | % MagickBooleanType DelegateComponentGenesis(void) |
| 230 | % |
| 231 | */ |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 232 | MagickPrivate MagickBooleanType DelegateComponentGenesis(void) |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 233 | { |
cristy | 7c97706 | 2014-04-04 14:05:53 +0000 | [diff] [blame] | 234 | if (delegate_semaphore == (SemaphoreInfo *) NULL) |
| 235 | delegate_semaphore=AcquireSemaphoreInfo(); |
cristy | f34a145 | 2009-10-24 22:29:27 +0000 | [diff] [blame] | 236 | return(MagickTrue); |
| 237 | } |
| 238 | |
| 239 | /* |
| 240 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 241 | % % |
| 242 | % % |
| 243 | % % |
| 244 | % 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 % |
| 245 | % % |
| 246 | % % |
| 247 | % % |
| 248 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 249 | % |
| 250 | % DelegateComponentTerminus() destroys the delegate component. |
| 251 | % |
| 252 | % The format of the DelegateComponentTerminus method is: |
| 253 | % |
| 254 | % DelegateComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 255 | % |
| 256 | */ |
| 257 | |
| 258 | static void *DestroyDelegate(void *delegate_info) |
| 259 | { |
| 260 | register DelegateInfo |
| 261 | *p; |
| 262 | |
| 263 | p=(DelegateInfo *) delegate_info; |
| 264 | if (p->path != (char *) NULL) |
| 265 | p->path=DestroyString(p->path); |
| 266 | if (p->decode != (char *) NULL) |
| 267 | p->decode=DestroyString(p->decode); |
| 268 | if (p->encode != (char *) NULL) |
| 269 | p->encode=DestroyString(p->encode); |
| 270 | if (p->commands != (char *) NULL) |
| 271 | p->commands=DestroyString(p->commands); |
cristy | 191ba5c | 2014-03-16 21:26:40 +0000 | [diff] [blame] | 272 | if (p->semaphore != (SemaphoreInfo *) NULL) |
cristy | 2f62da4 | 2014-03-19 21:57:49 +0000 | [diff] [blame] | 273 | RelinquishSemaphoreInfo(&p->semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 274 | p=(DelegateInfo *) RelinquishMagickMemory(p); |
| 275 | return((void *) NULL); |
| 276 | } |
| 277 | |
cristy | 5ff4eaf | 2011-09-03 01:38:02 +0000 | [diff] [blame] | 278 | MagickPrivate void DelegateComponentTerminus(void) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 279 | { |
cristy | 18b1744 | 2009-10-25 18:36:48 +0000 | [diff] [blame] | 280 | if (delegate_semaphore == (SemaphoreInfo *) NULL) |
cristy | 04b11db | 2014-02-16 15:10:39 +0000 | [diff] [blame] | 281 | ActivateSemaphoreInfo(&delegate_semaphore); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 282 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 283 | if (delegate_cache != (LinkedListInfo *) NULL) |
| 284 | delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 285 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3d162a9 | 2014-02-16 14:05:06 +0000 | [diff] [blame] | 286 | RelinquishSemaphoreInfo(&delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | /* |
| 290 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 291 | % % |
| 292 | % % |
| 293 | % % |
cristy | dfc19b6 | 2014-10-17 22:52:24 +0000 | [diff] [blame] | 294 | + E x t e r n a l D e l e g a t e C o m m a n d % |
| 295 | % % |
| 296 | % % |
| 297 | % % |
| 298 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 299 | % |
| 300 | % ExternalDelegateCommand() executes the specified command and waits until it |
| 301 | % terminates. The returned value is the exit status of the command. |
| 302 | % |
| 303 | % The format of the ExternalDelegateCommand method is: |
| 304 | % |
| 305 | % int ExternalDelegateCommand(const MagickBooleanType asynchronous, |
| 306 | % const MagickBooleanType verbose,const char *command, |
| 307 | % char *message,ExceptionInfo *exception) |
| 308 | % |
| 309 | % A description of each parameter follows: |
| 310 | % |
| 311 | % o asynchronous: a value other than 0 executes the parent program |
| 312 | % concurrently with the new child process. |
| 313 | % |
| 314 | % o verbose: a value other than 0 prints the executed command before it is |
| 315 | % invoked. |
| 316 | % |
| 317 | % o command: this string is the command to execute. |
| 318 | % |
| 319 | % o message: an option buffer to receive any message posted to stdout or |
| 320 | % stderr. |
| 321 | % |
| 322 | % o exception: return any errors here. |
| 323 | % |
| 324 | */ |
dirk | 457d976 | 2014-10-20 19:58:07 +0000 | [diff] [blame] | 325 | MagickExport int ExternalDelegateCommand(const MagickBooleanType asynchronous, |
cristy | dfc19b6 | 2014-10-17 22:52:24 +0000 | [diff] [blame] | 326 | const MagickBooleanType verbose,const char *command,char *message, |
| 327 | ExceptionInfo *exception) |
| 328 | { |
| 329 | char |
| 330 | **arguments, |
| 331 | *sanitize_command; |
| 332 | |
| 333 | int |
| 334 | number_arguments, |
| 335 | status; |
| 336 | |
| 337 | PolicyDomain |
| 338 | domain; |
| 339 | |
| 340 | PolicyRights |
| 341 | rights; |
| 342 | |
| 343 | register ssize_t |
| 344 | i; |
| 345 | |
| 346 | status=(-1); |
| 347 | arguments=StringToArgv(command,&number_arguments); |
| 348 | if (arguments == (char **) NULL) |
| 349 | return(status); |
| 350 | if (*arguments[1] == '\0') |
| 351 | { |
| 352 | for (i=0; i < (ssize_t) number_arguments; i++) |
| 353 | arguments[i]=DestroyString(arguments[i]); |
| 354 | arguments=(char **) RelinquishMagickMemory(arguments); |
| 355 | return(-1); |
| 356 | } |
| 357 | rights=ExecutePolicyRights; |
| 358 | domain=DelegatePolicyDomain; |
| 359 | if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse) |
| 360 | { |
| 361 | errno=EPERM; |
| 362 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
| 363 | "NotAuthorized","`%s'",arguments[1]); |
| 364 | for (i=0; i < (ssize_t) number_arguments; i++) |
| 365 | arguments[i]=DestroyString(arguments[i]); |
| 366 | arguments=(char **) RelinquishMagickMemory(arguments); |
| 367 | return(-1); |
| 368 | } |
| 369 | if (verbose != MagickFalse) |
| 370 | { |
| 371 | (void) FormatLocaleFile(stderr,"%s\n",command); |
| 372 | (void) fflush(stderr); |
| 373 | } |
Cristy | 40639d1 | 2016-05-29 19:54:23 -0400 | [diff] [blame] | 374 | sanitize_command=SanitizeString(command); |
cristy | dfc19b6 | 2014-10-17 22:52:24 +0000 | [diff] [blame] | 375 | if (asynchronous != MagickFalse) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 376 | (void) ConcatenateMagickString(sanitize_command,"&",MagickPathExtent); |
cristy | dfc19b6 | 2014-10-17 22:52:24 +0000 | [diff] [blame] | 377 | if (message != (char *) NULL) |
| 378 | *message='\0'; |
| 379 | #if defined(MAGICKCORE_POSIX_SUPPORT) |
| 380 | #if !defined(MAGICKCORE_HAVE_EXECVP) |
| 381 | status=system(sanitize_command); |
| 382 | #else |
| 383 | if ((asynchronous != MagickFalse) || |
| 384 | (strpbrk(sanitize_command,"&;<>|") != (char *) NULL)) |
| 385 | status=system(sanitize_command); |
| 386 | else |
| 387 | { |
| 388 | pid_t |
| 389 | child_pid; |
| 390 | |
| 391 | /* |
| 392 | Call application directly rather than from a shell. |
| 393 | */ |
| 394 | child_pid=(pid_t) fork(); |
| 395 | if (child_pid == (pid_t) -1) |
| 396 | status=system(sanitize_command); |
| 397 | else |
| 398 | if (child_pid == 0) |
| 399 | { |
| 400 | status=execvp(arguments[1],arguments+1); |
| 401 | _exit(1); |
| 402 | } |
| 403 | else |
| 404 | { |
| 405 | int |
| 406 | child_status; |
| 407 | |
| 408 | pid_t |
| 409 | pid; |
| 410 | |
| 411 | child_status=0; |
| 412 | pid=(pid_t) waitpid(child_pid,&child_status,0); |
| 413 | if (pid == -1) |
| 414 | status=(-1); |
| 415 | else |
| 416 | { |
| 417 | if (WIFEXITED(child_status) != 0) |
| 418 | status=WEXITSTATUS(child_status); |
| 419 | else |
| 420 | if (WIFSIGNALED(child_status)) |
| 421 | status=(-1); |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | #endif |
| 426 | #elif defined(MAGICKCORE_WINDOWS_SUPPORT) |
dirk | eb0db70 | 2015-02-12 22:17:21 +0000 | [diff] [blame] | 427 | { |
| 428 | register char |
| 429 | *p; |
| 430 | |
| 431 | /* |
| 432 | If a command shell is executed we need to change the forward slashes in |
| 433 | files to a backslash. We need to do this to keep Windows happy when we |
| 434 | want to 'move' a file. |
| 435 | |
| 436 | TODO: This won't work if one of the delegate parameters has a forward |
| 437 | slash as aparameter. |
| 438 | */ |
| 439 | p=strstr(sanitize_command, "cmd.exe /c"); |
| 440 | if (p != (char*) NULL) |
| 441 | { |
| 442 | p+=10; |
| 443 | for (; *p != '\0'; p++) |
| 444 | if (*p == '/') |
| 445 | *p=*DirectorySeparator; |
| 446 | } |
| 447 | } |
cristy | dfc19b6 | 2014-10-17 22:52:24 +0000 | [diff] [blame] | 448 | status=NTSystemCommand(sanitize_command,message); |
| 449 | #elif defined(macintosh) |
| 450 | status=MACSystemCommand(sanitize_command); |
| 451 | #elif defined(vms) |
| 452 | status=system(sanitize_command); |
| 453 | #else |
| 454 | # error No suitable system() method. |
| 455 | #endif |
| 456 | if (status < 0) |
| 457 | { |
| 458 | if ((message != (char *) NULL) && (*message != '\0')) |
| 459 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
dirk | eb0db70 | 2015-02-12 22:17:21 +0000 | [diff] [blame] | 460 | "FailedToExecuteCommand","`%s' (%s)",sanitize_command,message); |
cristy | dfc19b6 | 2014-10-17 22:52:24 +0000 | [diff] [blame] | 461 | else |
| 462 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
dirk | eb0db70 | 2015-02-12 22:17:21 +0000 | [diff] [blame] | 463 | "FailedToExecuteCommand","`%s' (%d)",sanitize_command,status); |
cristy | dfc19b6 | 2014-10-17 22:52:24 +0000 | [diff] [blame] | 464 | } |
| 465 | sanitize_command=DestroyString(sanitize_command); |
| 466 | for (i=0; i < (ssize_t) number_arguments; i++) |
| 467 | arguments[i]=DestroyString(arguments[i]); |
| 468 | arguments=(char **) RelinquishMagickMemory(arguments); |
| 469 | return(status); |
| 470 | } |
| 471 | |
| 472 | /* |
| 473 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 474 | % % |
| 475 | % % |
| 476 | % % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 477 | % G e t D e l e g a t e C o m m a n d % |
| 478 | % % |
| 479 | % % |
| 480 | % % |
| 481 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 482 | % |
| 483 | % GetDelegateCommand() replaces any embedded formatting characters with the |
| 484 | % appropriate image attribute and returns the resulting command. |
| 485 | % |
| 486 | % The format of the GetDelegateCommand method is: |
| 487 | % |
| 488 | % char *GetDelegateCommand(const ImageInfo *image_info,Image *image, |
| 489 | % const char *decode,const char *encode,ExceptionInfo *exception) |
| 490 | % |
| 491 | % A description of each parameter follows: |
| 492 | % |
| 493 | % o command: Method GetDelegateCommand returns the command associated |
| 494 | % with specified delegate tag. |
| 495 | % |
| 496 | % o image_info: the image info. |
| 497 | % |
| 498 | % o image: the image. |
| 499 | % |
| 500 | % o decode: Specifies the decode delegate we are searching for as a |
| 501 | % character string. |
| 502 | % |
| 503 | % o encode: Specifies the encode delegate we are searching for as a |
| 504 | % character string. |
| 505 | % |
| 506 | % o exception: return any errors or warnings in this structure. |
| 507 | % |
| 508 | */ |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 509 | |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 510 | static char *GetMagickPropertyLetter(ImageInfo *image_info,Image *image, |
| 511 | const char letter,ExceptionInfo *exception) |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 512 | { |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 513 | #define WarnNoImageReturn(format,letter) \ |
| 514 | if (image == (Image *) NULL) \ |
| 515 | { \ |
| 516 | (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \ |
| 517 | "NoImageForProperty",format,letter); \ |
| 518 | break; \ |
| 519 | } |
| 520 | #define WarnNoImageInfoReturn(format,letter) \ |
| 521 | if (image_info == (ImageInfo *) NULL) \ |
| 522 | { \ |
| 523 | (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \ |
| 524 | "NoImageInfoForProperty",format,letter); \ |
| 525 | break; \ |
| 526 | } |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 527 | |
| 528 | char |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 529 | value[MagickPathExtent]; |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 530 | |
| 531 | const char |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 532 | *string; |
| 533 | |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 534 | if ((image != (Image *) NULL) && (image->debug != MagickFalse)) |
| 535 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 536 | else |
| 537 | if ((image_info != (ImageInfo *) NULL) && |
| 538 | (image_info->debug != MagickFalse)) |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 539 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-images"); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 540 | /* |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 541 | Get properties that are directly defined by images. |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 542 | */ |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 543 | *value='\0'; /* formatted string */ |
| 544 | string=(const char *) value; |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 545 | switch (letter) |
| 546 | { |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 547 | case 'a': /* authentication passphase */ |
| 548 | { |
| 549 | WarnNoImageInfoReturn("\"%%%c\"",letter); |
| 550 | string=GetImageOption(image_info,"authenticate"); |
| 551 | break; |
| 552 | } |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 553 | case 'b': /* image size read in - in bytes */ |
| 554 | { |
| 555 | WarnNoImageReturn("\"%%%c\"",letter); |
| 556 | (void) FormatMagickSize(image->extent,MagickFalse,"B",MagickPathExtent, |
| 557 | value); |
| 558 | if (image->extent == 0) |
| 559 | (void) FormatMagickSize(GetBlobSize(image),MagickFalse,"B", |
| 560 | MagickPathExtent,value); |
| 561 | break; |
| 562 | } |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 563 | case 'd': /* Directory component of filename */ |
| 564 | { |
| 565 | WarnNoImageReturn("\"%%%c\"",letter); |
| 566 | GetPathComponent(image->magick_filename,HeadPath,value); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 567 | break; |
| 568 | } |
| 569 | case 'e': /* Filename extension (suffix) of image file */ |
| 570 | { |
| 571 | WarnNoImageReturn("\"%%%c\"",letter); |
| 572 | GetPathComponent(image->magick_filename,ExtensionPath,value); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 573 | break; |
| 574 | } |
| 575 | case 'f': /* Filename without directory component */ |
| 576 | { |
| 577 | WarnNoImageReturn("\"%%%c\"",letter); |
| 578 | GetPathComponent(image->magick_filename,TailPath,value); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 579 | break; |
| 580 | } |
| 581 | case 'g': /* Image geometry, canvas and offset %Wx%H+%X+%Y */ |
| 582 | { |
| 583 | WarnNoImageReturn("\"%%%c\"",letter); |
| 584 | (void) FormatLocaleString(value,MagickPathExtent, |
| 585 | "%.20gx%.20g%+.20g%+.20g",(double) image->page.width,(double) |
| 586 | image->page.height,(double) image->page.x,(double) image->page.y); |
| 587 | break; |
| 588 | } |
| 589 | case 'h': /* Image height (current) */ |
| 590 | { |
| 591 | WarnNoImageReturn("\"%%%c\"",letter); |
| 592 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 593 | (image->rows != 0 ? image->rows : image->magick_rows)); |
| 594 | break; |
| 595 | } |
| 596 | case 'i': /* Filename last used for an image (read or write) */ |
| 597 | { |
| 598 | WarnNoImageReturn("\"%%%c\"",letter); |
| 599 | string=image->filename; |
| 600 | break; |
| 601 | } |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 602 | case 'm': /* Image format (file magick) */ |
| 603 | { |
| 604 | WarnNoImageReturn("\"%%%c\"",letter); |
| 605 | string=image->magick; |
| 606 | break; |
| 607 | } |
| 608 | case 'n': /* Number of images in the list. */ |
| 609 | { |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 610 | if (image != (Image *) NULL) |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 611 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 612 | GetImageListLength(image)); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 613 | break; |
| 614 | } |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 615 | case 'o': /* Output Filename */ |
| 616 | { |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 617 | WarnNoImageInfoReturn("\"%%%c\"",letter); |
| 618 | string=image_info->filename; |
| 619 | break; |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 620 | } |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 621 | case 'p': /* Image index in current image list */ |
| 622 | { |
| 623 | WarnNoImageReturn("\"%%%c\"",letter); |
| 624 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 625 | GetImageIndexInList(image)); |
| 626 | break; |
| 627 | } |
| 628 | case 'q': /* Quantum depth of image in memory */ |
| 629 | { |
| 630 | WarnNoImageReturn("\"%%%c\"",letter); |
| 631 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 632 | MAGICKCORE_QUANTUM_DEPTH); |
| 633 | break; |
| 634 | } |
| 635 | case 'r': /* Image storage class, colorspace, and alpha enabled. */ |
| 636 | { |
| 637 | ColorspaceType |
| 638 | colorspace; |
| 639 | |
| 640 | WarnNoImageReturn("\"%%%c\"",letter); |
| 641 | colorspace=image->colorspace; |
| 642 | if (SetImageGray(image,exception) != MagickFalse) |
Cristy | beb4c2b | 2017-12-26 19:43:17 -0500 | [diff] [blame] | 643 | colorspace=GRAYColorspace; /* FUTURE: this is IMv6 not IMv7 */ |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 644 | (void) FormatLocaleString(value,MagickPathExtent,"%s %s %s", |
| 645 | CommandOptionToMnemonic(MagickClassOptions,(ssize_t) |
| 646 | image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions, |
| 647 | (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ? |
| 648 | "Alpha" : ""); |
| 649 | break; |
| 650 | } |
| 651 | case 's': /* Image scene number */ |
| 652 | { |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 653 | WarnNoImageReturn("\"%%%c\"",letter); |
| 654 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 655 | image->scene); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 656 | break; |
| 657 | } |
| 658 | case 't': /* Base filename without directory or extention */ |
| 659 | { |
| 660 | WarnNoImageReturn("\"%%%c\"",letter); |
| 661 | GetPathComponent(image->magick_filename,BasePath,value); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 662 | break; |
| 663 | } |
| 664 | case 'u': /* Unique filename */ |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 665 | { |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 666 | WarnNoImageInfoReturn("\"%%%c\"",letter); |
| 667 | string=image_info->unique; |
| 668 | break; |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 669 | } |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 670 | case 'w': /* Image width (current) */ |
| 671 | { |
| 672 | WarnNoImageReturn("\"%%%c\"",letter); |
| 673 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 674 | (image->columns != 0 ? image->columns : image->magick_columns)); |
| 675 | break; |
| 676 | } |
| 677 | case 'x': /* Image horizontal resolution (with units) */ |
| 678 | { |
| 679 | WarnNoImageReturn("\"%%%c\"",letter); |
| 680 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g", |
| 681 | fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x : 72.0); |
| 682 | break; |
| 683 | } |
| 684 | case 'y': /* Image vertical resolution (with units) */ |
| 685 | { |
| 686 | WarnNoImageReturn("\"%%%c\"",letter); |
| 687 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g", |
| 688 | fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y : 72.0); |
| 689 | break; |
| 690 | } |
| 691 | case 'z': /* Image depth as read in */ |
| 692 | { |
| 693 | WarnNoImageReturn("\"%%%c\"",letter); |
| 694 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g", |
| 695 | (double) image->depth); |
| 696 | break; |
| 697 | } |
| 698 | case 'A': /* Image alpha channel */ |
| 699 | { |
| 700 | WarnNoImageReturn("\"%%%c\"",letter); |
| 701 | string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t) |
| 702 | image->alpha_trait); |
| 703 | break; |
| 704 | } |
| 705 | case 'C': /* Image compression method. */ |
| 706 | { |
| 707 | WarnNoImageReturn("\"%%%c\"",letter); |
| 708 | string=CommandOptionToMnemonic(MagickCompressOptions, |
| 709 | (ssize_t) image->compression); |
| 710 | break; |
| 711 | } |
| 712 | case 'D': /* Image dispose method. */ |
| 713 | { |
| 714 | WarnNoImageReturn("\"%%%c\"",letter); |
| 715 | string=CommandOptionToMnemonic(MagickDisposeOptions, |
| 716 | (ssize_t) image->dispose); |
| 717 | break; |
| 718 | } |
| 719 | case 'F': |
| 720 | { |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 721 | /* |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 722 | Magick filename - filename given incl. coder & read mods. |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 723 | */ |
| 724 | WarnNoImageReturn("\"%%%c\"",letter); |
| 725 | (void) CopyMagickString(value,image->magick_filename,MagickPathExtent); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 726 | break; |
| 727 | } |
| 728 | case 'G': /* Image size as geometry = "%wx%h" */ |
| 729 | { |
| 730 | WarnNoImageReturn("\"%%%c\"",letter); |
| 731 | (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g", |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 732 | (double) image->magick_columns,(double) image->magick_rows); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 733 | break; |
| 734 | } |
| 735 | case 'H': /* layer canvas height */ |
| 736 | { |
| 737 | WarnNoImageReturn("\"%%%c\"",letter); |
| 738 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g", |
| 739 | (double) image->page.height); |
| 740 | break; |
| 741 | } |
| 742 | case 'M': /* Magick filename - filename given incl. coder & read mods */ |
| 743 | { |
| 744 | WarnNoImageReturn("\"%%%c\"",letter); |
| 745 | string=image->magick_filename; |
| 746 | break; |
| 747 | } |
| 748 | case 'O': /* layer canvas offset with sign = "+%X+%Y" */ |
| 749 | { |
| 750 | WarnNoImageReturn("\"%%%c\"",letter); |
| 751 | (void) FormatLocaleString(value,MagickPathExtent,"%+ld%+ld",(long) |
| 752 | image->page.x,(long) image->page.y); |
| 753 | break; |
| 754 | } |
| 755 | case 'P': /* layer canvas page size = "%Wx%H" */ |
| 756 | { |
| 757 | WarnNoImageReturn("\"%%%c\"",letter); |
| 758 | (void) FormatLocaleString(value,MagickPathExtent,"%.20gx%.20g", |
| 759 | (double) image->page.width,(double) image->page.height); |
| 760 | break; |
| 761 | } |
| 762 | case 'Q': /* image compression quality */ |
| 763 | { |
| 764 | WarnNoImageReturn("\"%%%c\"",letter); |
| 765 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 766 | (image->quality == 0 ? 92 : image->quality)); |
| 767 | break; |
| 768 | } |
| 769 | case 'S': /* Number of scenes in image list. */ |
| 770 | { |
| 771 | WarnNoImageInfoReturn("\"%%%c\"",letter); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 772 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 773 | (image_info->number_scenes == 0 ? 2147483647 : |
| 774 | image_info->number_scenes)); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 775 | break; |
| 776 | } |
| 777 | case 'T': /* image time delay for animations */ |
| 778 | { |
| 779 | WarnNoImageReturn("\"%%%c\"",letter); |
| 780 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 781 | image->delay); |
| 782 | break; |
| 783 | } |
| 784 | case 'U': /* Image resolution units. */ |
| 785 | { |
| 786 | WarnNoImageReturn("\"%%%c\"",letter); |
| 787 | string=CommandOptionToMnemonic(MagickResolutionOptions, |
| 788 | (ssize_t) image->units); |
| 789 | break; |
| 790 | } |
| 791 | case 'W': /* layer canvas width */ |
| 792 | { |
| 793 | WarnNoImageReturn("\"%%%c\"",letter); |
| 794 | (void) FormatLocaleString(value,MagickPathExtent,"%.20g",(double) |
| 795 | image->page.width); |
| 796 | break; |
| 797 | } |
| 798 | case 'X': /* layer canvas X offset */ |
| 799 | { |
| 800 | WarnNoImageReturn("\"%%%c\"",letter); |
| 801 | (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double) |
| 802 | image->page.x); |
| 803 | break; |
| 804 | } |
| 805 | case 'Y': /* layer canvas Y offset */ |
| 806 | { |
| 807 | WarnNoImageReturn("\"%%%c\"",letter); |
| 808 | (void) FormatLocaleString(value,MagickPathExtent,"%+.20g",(double) |
| 809 | image->page.y); |
| 810 | break; |
| 811 | } |
| 812 | case '%': /* percent escaped */ |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 813 | { |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 814 | string="%"; |
| 815 | break; |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 816 | } |
| 817 | case '@': /* Trim bounding box, without actually trimming! */ |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 818 | { |
| 819 | RectangleInfo |
| 820 | page; |
| 821 | |
| 822 | WarnNoImageReturn("\"%%%c\"",letter); |
| 823 | page=GetImageBoundingBox(image,exception); |
| 824 | (void) FormatLocaleString(value,MagickPathExtent, |
| 825 | "%.20gx%.20g%+.20g%+.20g",(double) page.width,(double) page.height, |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 826 | (double) page.x,(double) page.y); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 827 | break; |
| 828 | } |
| 829 | case '#': |
| 830 | { |
| 831 | /* |
| 832 | Image signature. |
| 833 | */ |
| 834 | WarnNoImageReturn("\"%%%c\"",letter); |
| 835 | (void) SignatureImage(image,exception); |
| 836 | string=GetImageProperty(image,"signature",exception); |
| 837 | break; |
| 838 | } |
| 839 | } |
Cristy | 40639d1 | 2016-05-29 19:54:23 -0400 | [diff] [blame] | 840 | return(SanitizeString(string)); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 841 | } |
| 842 | |
| 843 | static char *InterpretDelegateProperties(ImageInfo *image_info, |
| 844 | Image *image,const char *embed_text,ExceptionInfo *exception) |
| 845 | { |
| 846 | #define ExtendInterpretText(string_length) \ |
| 847 | DisableMSCWarning(4127) \ |
| 848 | { \ |
| 849 | size_t length=(string_length); \ |
| 850 | if ((size_t) (q-interpret_text+length+1) >= extent) \ |
| 851 | { \ |
| 852 | extent+=length; \ |
| 853 | interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \ |
| 854 | MaxTextExtent,sizeof(*interpret_text)); \ |
| 855 | if (interpret_text == (char *) NULL) \ |
| 856 | return((char *) NULL); \ |
| 857 | q=interpret_text+strlen(interpret_text); \ |
| 858 | } \ |
| 859 | } \ |
| 860 | RestoreMSCWarning |
| 861 | |
| 862 | #define AppendKeyValue2Text(key,value)\ |
| 863 | DisableMSCWarning(4127) \ |
| 864 | { \ |
| 865 | size_t length=strlen(key)+strlen(value)+2; \ |
| 866 | if ((size_t) (q-interpret_text+length+1) >= extent) \ |
| 867 | { \ |
| 868 | extent+=length; \ |
| 869 | interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \ |
| 870 | MaxTextExtent,sizeof(*interpret_text)); \ |
| 871 | if (interpret_text == (char *) NULL) \ |
| 872 | return((char *) NULL); \ |
| 873 | q=interpret_text+strlen(interpret_text); \ |
| 874 | } \ |
| 875 | q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \ |
| 876 | } \ |
| 877 | RestoreMSCWarning |
| 878 | |
| 879 | #define AppendString2Text(string) \ |
| 880 | DisableMSCWarning(4127) \ |
| 881 | { \ |
| 882 | size_t length=strlen((string)); \ |
| 883 | if ((size_t) (q-interpret_text+length+1) >= extent) \ |
| 884 | { \ |
| 885 | extent+=length; \ |
| 886 | interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \ |
| 887 | MaxTextExtent,sizeof(*interpret_text)); \ |
| 888 | if (interpret_text == (char *) NULL) \ |
| 889 | return((char *) NULL); \ |
| 890 | q=interpret_text+strlen(interpret_text); \ |
| 891 | } \ |
| 892 | (void) CopyMagickString(q,(string),extent); \ |
| 893 | q+=length; \ |
| 894 | } \ |
| 895 | RestoreMSCWarning |
| 896 | |
| 897 | char |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 898 | *interpret_text, |
| 899 | *string; |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 900 | |
| 901 | register char |
| 902 | *q; /* current position in interpret_text */ |
| 903 | |
| 904 | register const char |
| 905 | *p; /* position in embed_text string being expanded */ |
| 906 | |
| 907 | size_t |
| 908 | extent; /* allocated length of interpret_text */ |
| 909 | |
| 910 | MagickBooleanType |
| 911 | number; |
| 912 | |
| 913 | assert(image == NULL || image->signature == MagickCoreSignature); |
| 914 | assert(image_info == NULL || image_info->signature == MagickCoreSignature); |
| 915 | if ((image != (Image *) NULL) && (image->debug != MagickFalse)) |
| 916 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 917 | else |
| 918 | if ((image_info != (ImageInfo *) NULL) && (image_info->debug != MagickFalse)) |
| 919 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s","no-image"); |
| 920 | if (embed_text == (const char *) NULL) |
| 921 | return(ConstantString("")); |
| 922 | p=embed_text; |
| 923 | while ((isspace((int) ((unsigned char) *p)) != 0) && (*p != '\0')) |
| 924 | p++; |
| 925 | if (*p == '\0') |
| 926 | return(ConstantString("")); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 927 | /* |
| 928 | Translate any embedded format characters. |
| 929 | */ |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 930 | interpret_text=AcquireString(embed_text); /* new string with extra space */ |
| 931 | extent=MagickPathExtent; /* allocated space in string */ |
| 932 | number=MagickFalse; /* is last char a number? */ |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 933 | for (q=interpret_text; *p!='\0'; |
Roland Illig | 50c202d | 2018-02-18 17:52:42 +0100 | [diff] [blame] | 934 | number=isdigit((int) ((unsigned char) *p)) ? MagickTrue : MagickFalse,p++) |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 935 | { |
| 936 | /* |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 937 | Interpret escape characters (e.g. Filename: %M). |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 938 | */ |
| 939 | *q='\0'; |
| 940 | ExtendInterpretText(MagickPathExtent); |
| 941 | switch (*p) |
| 942 | { |
| 943 | case '\\': |
| 944 | { |
| 945 | switch (*(p+1)) |
| 946 | { |
| 947 | case '\0': |
| 948 | continue; |
| 949 | case 'r': /* convert to RETURN */ |
| 950 | { |
| 951 | *q++='\r'; |
| 952 | p++; |
| 953 | continue; |
| 954 | } |
| 955 | case 'n': /* convert to NEWLINE */ |
| 956 | { |
| 957 | *q++='\n'; |
| 958 | p++; |
| 959 | continue; |
| 960 | } |
| 961 | case '\n': /* EOL removal UNIX,MacOSX */ |
| 962 | { |
| 963 | p++; |
| 964 | continue; |
| 965 | } |
| 966 | case '\r': /* EOL removal DOS,Windows */ |
| 967 | { |
| 968 | p++; |
| 969 | if (*p == '\n') /* return-newline EOL */ |
| 970 | p++; |
| 971 | continue; |
| 972 | } |
| 973 | default: |
| 974 | { |
| 975 | p++; |
| 976 | *q++=(*p); |
| 977 | } |
| 978 | } |
| 979 | continue; |
| 980 | } |
| 981 | case '&': |
| 982 | { |
| 983 | if (LocaleNCompare("<",p,4) == 0) |
| 984 | { |
| 985 | *q++='<'; |
| 986 | p+=3; |
| 987 | } |
| 988 | else |
| 989 | if (LocaleNCompare(">",p,4) == 0) |
| 990 | { |
| 991 | *q++='>'; |
| 992 | p+=3; |
| 993 | } |
| 994 | else |
| 995 | if (LocaleNCompare("&",p,5) == 0) |
| 996 | { |
| 997 | *q++='&'; |
| 998 | p+=4; |
| 999 | } |
| 1000 | else |
| 1001 | *q++=(*p); |
| 1002 | continue; |
| 1003 | } |
| 1004 | case '%': |
| 1005 | break; /* continue to next set of handlers */ |
| 1006 | default: |
| 1007 | { |
| 1008 | *q++=(*p); /* any thing else is 'as normal' */ |
| 1009 | continue; |
| 1010 | } |
| 1011 | } |
| 1012 | p++; /* advance beyond the percent */ |
| 1013 | /* |
| 1014 | Doubled Percent - or percent at end of string. |
| 1015 | */ |
| 1016 | if ((*p == '\0') || (*p == '\'') || (*p == '"')) |
| 1017 | p--; |
| 1018 | if (*p == '%') |
| 1019 | { |
| 1020 | *q++='%'; |
| 1021 | continue; |
| 1022 | } |
| 1023 | /* |
| 1024 | Single letter escapes %c. |
| 1025 | */ |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 1026 | if (number != MagickFalse) |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 1027 | { |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 1028 | /* |
| 1029 | But only if not preceeded by a number! |
| 1030 | */ |
| 1031 | *q++='%'; /* do NOT substitute the percent */ |
| 1032 | p--; /* back up one */ |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 1033 | continue; |
| 1034 | } |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 1035 | string=GetMagickPropertyLetter(image_info,image,*p, exception); |
| 1036 | if (string != (char *) NULL) |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 1037 | { |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 1038 | AppendString2Text(string); |
| 1039 | string=DestroyString(string); |
| 1040 | continue; |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 1041 | } |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 1042 | (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, |
| 1043 | "UnknownImageProperty","\"%%%c\"",*p); |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 1044 | } |
| 1045 | *q='\0'; |
| 1046 | return(interpret_text); |
| 1047 | } |
| 1048 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1049 | MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image, |
| 1050 | const char *decode,const char *encode,ExceptionInfo *exception) |
| 1051 | { |
| 1052 | char |
| 1053 | *command, |
| 1054 | **commands; |
| 1055 | |
| 1056 | const DelegateInfo |
| 1057 | *delegate_info; |
| 1058 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1059 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1060 | i; |
| 1061 | |
| 1062 | assert(image_info != (ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1063 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1064 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1065 | assert(image->signature == MagickCoreSignature); |
cristy | cb190b7 | 2014-08-31 20:04:42 +0000 | [diff] [blame] | 1066 | if (image->debug != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1067 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
anthony | 59c4443 | 2012-05-23 04:41:25 +0000 | [diff] [blame] | 1068 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1069 | delegate_info=GetDelegateInfo(decode,encode,exception); |
| 1070 | if (delegate_info == (const DelegateInfo *) NULL) |
| 1071 | { |
| 1072 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1073 | "NoTagFound","`%s'",decode ? decode : encode); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1074 | return((char *) NULL); |
| 1075 | } |
| 1076 | commands=StringToList(delegate_info->commands); |
| 1077 | if (commands == (char **) NULL) |
| 1078 | { |
| 1079 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | 014ead1 | 2013-04-29 08:47:36 +0000 | [diff] [blame] | 1080 | ResourceLimitError,"MemoryAllocationFailed","`%s'",decode ? decode : |
| 1081 | encode); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1082 | return((char *) NULL); |
| 1083 | } |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 1084 | command=InterpretDelegateProperties((ImageInfo *) image_info,image, |
| 1085 | commands[0],exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1086 | if (command == (char *) NULL) |
| 1087 | (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1088 | "MemoryAllocationFailed","`%s'",commands[0]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1089 | /* |
| 1090 | Relinquish resources. |
| 1091 | */ |
| 1092 | for (i=0; commands[i] != (char *) NULL; i++) |
| 1093 | commands[i]=DestroyString(commands[i]); |
| 1094 | commands=(char **) RelinquishMagickMemory(commands); |
| 1095 | return(command); |
| 1096 | } |
| 1097 | |
| 1098 | /* |
| 1099 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1100 | % % |
| 1101 | % % |
| 1102 | % % |
| 1103 | % G e t D e l e g a t e C o m m a n d s % |
| 1104 | % % |
| 1105 | % % |
| 1106 | % % |
| 1107 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1108 | % |
| 1109 | % GetDelegateCommands() returns the commands associated with a delegate. |
| 1110 | % |
| 1111 | % The format of the GetDelegateCommands method is: |
| 1112 | % |
| 1113 | % const char *GetDelegateCommands(const DelegateInfo *delegate_info) |
| 1114 | % |
| 1115 | % A description of each parameter follows: |
| 1116 | % |
| 1117 | % o delegate_info: The delegate info. |
| 1118 | % |
| 1119 | */ |
| 1120 | MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info) |
| 1121 | { |
| 1122 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
anthony | 59c4443 | 2012-05-23 04:41:25 +0000 | [diff] [blame] | 1123 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1124 | assert(delegate_info != (DelegateInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1125 | assert(delegate_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1126 | return(delegate_info->commands); |
| 1127 | } |
| 1128 | |
| 1129 | /* |
| 1130 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1131 | % % |
| 1132 | % % |
| 1133 | % % |
| 1134 | % G e t D e l e g a t e I n f o % |
| 1135 | % % |
| 1136 | % % |
| 1137 | % % |
| 1138 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1139 | % |
| 1140 | % GetDelegateInfo() returns any delegates associated with the specified tag. |
| 1141 | % |
| 1142 | % The format of the GetDelegateInfo method is: |
| 1143 | % |
| 1144 | % const DelegateInfo *GetDelegateInfo(const char *decode, |
| 1145 | % const char *encode,ExceptionInfo *exception) |
| 1146 | % |
| 1147 | % A description of each parameter follows: |
| 1148 | % |
| 1149 | % o decode: Specifies the decode delegate we are searching for as a |
| 1150 | % character string. |
| 1151 | % |
| 1152 | % o encode: Specifies the encode delegate we are searching for as a |
| 1153 | % character string. |
| 1154 | % |
| 1155 | % o exception: return any errors or warnings in this structure. |
| 1156 | % |
| 1157 | */ |
| 1158 | MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, |
| 1159 | const char *encode,ExceptionInfo *exception) |
| 1160 | { |
| 1161 | register const DelegateInfo |
| 1162 | *p; |
| 1163 | |
| 1164 | assert(exception != (ExceptionInfo *) NULL); |
dirk | 5d0a441 | 2016-01-05 22:28:51 +0100 | [diff] [blame] | 1165 | if (IsDelegateCacheInstantiated(exception) == MagickFalse) |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 1166 | return((const DelegateInfo *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1167 | /* |
| 1168 | Search for named delegate. |
| 1169 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1170 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1171 | ResetLinkedListIterator(delegate_cache); |
| 1172 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 49d4d22 | 2014-03-16 00:37:58 +0000 | [diff] [blame] | 1173 | if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0)) |
| 1174 | { |
| 1175 | UnlockSemaphoreInfo(delegate_semaphore); |
| 1176 | return(p); |
| 1177 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1178 | while (p != (const DelegateInfo *) NULL) |
| 1179 | { |
| 1180 | if (p->mode > 0) |
| 1181 | { |
| 1182 | if (LocaleCompare(p->decode,decode) == 0) |
| 1183 | break; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1184 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1185 | continue; |
| 1186 | } |
| 1187 | if (p->mode < 0) |
| 1188 | { |
| 1189 | if (LocaleCompare(p->encode,encode) == 0) |
| 1190 | break; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1191 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1192 | continue; |
| 1193 | } |
| 1194 | if (LocaleCompare(decode,p->decode) == 0) |
| 1195 | if (LocaleCompare(encode,p->encode) == 0) |
| 1196 | break; |
| 1197 | if (LocaleCompare(decode,"*") == 0) |
| 1198 | if (LocaleCompare(encode,p->encode) == 0) |
| 1199 | break; |
| 1200 | if (LocaleCompare(decode,p->decode) == 0) |
| 1201 | if (LocaleCompare(encode,"*") == 0) |
| 1202 | break; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1203 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1204 | } |
| 1205 | if (p != (const DelegateInfo *) NULL) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1206 | (void) InsertValueInLinkedList(delegate_cache,0, |
| 1207 | RemoveElementByValueFromLinkedList(delegate_cache,p)); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1208 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1209 | return(p); |
| 1210 | } |
| 1211 | |
| 1212 | /* |
| 1213 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1214 | % % |
| 1215 | % % |
| 1216 | % % |
| 1217 | % G e t D e l e g a t e I n f o L i s t % |
| 1218 | % % |
| 1219 | % % |
| 1220 | % % |
| 1221 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1222 | % |
| 1223 | % GetDelegateInfoList() returns any delegates that match the specified pattern. |
| 1224 | % |
| 1225 | % The delegate of the GetDelegateInfoList function is: |
| 1226 | % |
| 1227 | % const DelegateInfo **GetDelegateInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1228 | % size_t *number_delegates,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1229 | % |
| 1230 | % A description of each parameter follows: |
| 1231 | % |
| 1232 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 1233 | % |
| 1234 | % o number_delegates: This integer returns the number of delegates in the |
| 1235 | % list. |
| 1236 | % |
| 1237 | % o exception: return any errors or warnings in this structure. |
| 1238 | % |
| 1239 | */ |
| 1240 | |
| 1241 | #if defined(__cplusplus) || defined(c_plusplus) |
| 1242 | extern "C" { |
| 1243 | #endif |
| 1244 | |
| 1245 | static int DelegateInfoCompare(const void *x,const void *y) |
| 1246 | { |
| 1247 | const DelegateInfo |
| 1248 | **p, |
| 1249 | **q; |
| 1250 | |
dirk | f0dedd8 | 2014-12-16 19:56:13 +0000 | [diff] [blame] | 1251 | int |
| 1252 | cmp; |
| 1253 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1254 | p=(const DelegateInfo **) x, |
| 1255 | q=(const DelegateInfo **) y; |
dirk | f0dedd8 | 2014-12-16 19:56:13 +0000 | [diff] [blame] | 1256 | cmp=LocaleCompare((*p)->path,(*q)->path); |
| 1257 | if (cmp == 0) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1258 | { |
| 1259 | if ((*p)->decode == (char *) NULL) |
| 1260 | if (((*p)->encode != (char *) NULL) && |
| 1261 | ((*q)->encode != (char *) NULL)) |
| 1262 | return(strcmp((*p)->encode,(*q)->encode)); |
| 1263 | if (((*p)->decode != (char *) NULL) && |
| 1264 | ((*q)->decode != (char *) NULL)) |
| 1265 | return(strcmp((*p)->decode,(*q)->decode)); |
| 1266 | } |
dirk | f0dedd8 | 2014-12-16 19:56:13 +0000 | [diff] [blame] | 1267 | return(cmp); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1268 | } |
| 1269 | |
| 1270 | #if defined(__cplusplus) || defined(c_plusplus) |
| 1271 | } |
| 1272 | #endif |
| 1273 | |
| 1274 | MagickExport const DelegateInfo **GetDelegateInfoList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1275 | size_t *number_delegates,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1276 | { |
| 1277 | const DelegateInfo |
| 1278 | **delegates; |
| 1279 | |
| 1280 | register const DelegateInfo |
| 1281 | *p; |
| 1282 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1283 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1284 | i; |
| 1285 | |
| 1286 | /* |
| 1287 | Allocate delegate list. |
| 1288 | */ |
anthony | 59c4443 | 2012-05-23 04:41:25 +0000 | [diff] [blame] | 1289 | assert(number_delegates != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1290 | assert(pattern != (char *) NULL); |
| 1291 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
anthony | 59c4443 | 2012-05-23 04:41:25 +0000 | [diff] [blame] | 1292 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1293 | *number_delegates=0; |
| 1294 | p=GetDelegateInfo("*","*",exception); |
| 1295 | if (p == (const DelegateInfo *) NULL) |
| 1296 | return((const DelegateInfo **) NULL); |
| 1297 | delegates=(const DelegateInfo **) AcquireQuantumMemory((size_t) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1298 | GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1299 | if (delegates == (const DelegateInfo **) NULL) |
| 1300 | return((const DelegateInfo **) NULL); |
| 1301 | /* |
| 1302 | Generate delegate list. |
| 1303 | */ |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1304 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1305 | ResetLinkedListIterator(delegate_cache); |
| 1306 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1307 | for (i=0; p != (const DelegateInfo *) NULL; ) |
| 1308 | { |
dirk | 5d0a441 | 2016-01-05 22:28:51 +0100 | [diff] [blame] | 1309 | if( (p->stealth == MagickFalse) && |
dirk | 11a7cb7 | 2016-01-05 14:00:04 +0100 | [diff] [blame] | 1310 | ( GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse || |
| 1311 | GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse) ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1312 | delegates[i++]=p; |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1313 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1314 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1315 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1316 | qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateInfoCompare); |
| 1317 | delegates[i]=(DelegateInfo *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1318 | *number_delegates=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1319 | return(delegates); |
| 1320 | } |
| 1321 | |
| 1322 | /* |
| 1323 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1324 | % % |
| 1325 | % % |
| 1326 | % % |
| 1327 | % G e t D e l e g a t e L i s t % |
| 1328 | % % |
| 1329 | % % |
| 1330 | % % |
| 1331 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1332 | % |
| 1333 | % GetDelegateList() returns any image format delegates that match the |
| 1334 | % specified pattern. |
| 1335 | % |
| 1336 | % The format of the GetDelegateList function is: |
| 1337 | % |
| 1338 | % char **GetDelegateList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1339 | % size_t *number_delegates,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1340 | % |
| 1341 | % A description of each parameter follows: |
| 1342 | % |
| 1343 | % o pattern: Specifies a pointer to a text string containing a pattern. |
| 1344 | % |
| 1345 | % o number_delegates: This integer returns the number of delegates |
| 1346 | % in the list. |
| 1347 | % |
| 1348 | % o exception: return any errors or warnings in this structure. |
| 1349 | % |
| 1350 | */ |
| 1351 | |
| 1352 | #if defined(__cplusplus) || defined(c_plusplus) |
| 1353 | extern "C" { |
| 1354 | #endif |
| 1355 | |
| 1356 | static int DelegateCompare(const void *x,const void *y) |
| 1357 | { |
| 1358 | register const char |
| 1359 | **p, |
| 1360 | **q; |
| 1361 | |
| 1362 | p=(const char **) x; |
| 1363 | q=(const char **) y; |
| 1364 | return(LocaleCompare(*p,*q)); |
| 1365 | } |
| 1366 | |
| 1367 | #if defined(__cplusplus) || defined(c_plusplus) |
| 1368 | } |
| 1369 | #endif |
| 1370 | |
| 1371 | MagickExport char **GetDelegateList(const char *pattern, |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1372 | size_t *number_delegates,ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1373 | { |
| 1374 | char |
| 1375 | **delegates; |
| 1376 | |
| 1377 | register const DelegateInfo |
| 1378 | *p; |
| 1379 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1380 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1381 | i; |
| 1382 | |
| 1383 | /* |
| 1384 | Allocate delegate list. |
| 1385 | */ |
| 1386 | assert(pattern != (char *) NULL); |
| 1387 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",pattern); |
anthony | 59c4443 | 2012-05-23 04:41:25 +0000 | [diff] [blame] | 1388 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1389 | assert(number_delegates != (size_t *) NULL); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1390 | *number_delegates=0; |
| 1391 | p=GetDelegateInfo("*","*",exception); |
| 1392 | if (p == (const DelegateInfo *) NULL) |
| 1393 | return((char **) NULL); |
| 1394 | delegates=(char **) AcquireQuantumMemory((size_t) |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1395 | GetNumberOfElementsInLinkedList(delegate_cache)+1UL,sizeof(*delegates)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1396 | if (delegates == (char **) NULL) |
| 1397 | return((char **) NULL); |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1398 | LockSemaphoreInfo(delegate_semaphore); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1399 | ResetLinkedListIterator(delegate_cache); |
| 1400 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1401 | for (i=0; p != (const DelegateInfo *) NULL; ) |
| 1402 | { |
dirk | 5d0a441 | 2016-01-05 22:28:51 +0100 | [diff] [blame] | 1403 | if( (p->stealth == MagickFalse) && |
dirk | 11a7cb7 | 2016-01-05 14:00:04 +0100 | [diff] [blame] | 1404 | GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1405 | delegates[i++]=ConstantString(p->decode); |
dirk | 5d0a441 | 2016-01-05 22:28:51 +0100 | [diff] [blame] | 1406 | if( (p->stealth == MagickFalse) && |
dirk | 11a7cb7 | 2016-01-05 14:00:04 +0100 | [diff] [blame] | 1407 | GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse ) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1408 | delegates[i++]=ConstantString(p->encode); |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1409 | p=(const DelegateInfo *) GetNextValueInLinkedList(delegate_cache); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1410 | } |
cristy | f84a193 | 2010-01-03 18:00:18 +0000 | [diff] [blame] | 1411 | UnlockSemaphoreInfo(delegate_semaphore); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1412 | qsort((void *) delegates,(size_t) i,sizeof(*delegates),DelegateCompare); |
| 1413 | delegates[i]=(char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1414 | *number_delegates=(size_t) i; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1415 | return(delegates); |
| 1416 | } |
| 1417 | |
| 1418 | /* |
| 1419 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1420 | % % |
| 1421 | % % |
| 1422 | % % |
| 1423 | % G e t D e l e g a t e M o d e % |
| 1424 | % % |
| 1425 | % % |
| 1426 | % % |
| 1427 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1428 | % |
| 1429 | % GetDelegateMode() returns the mode of the delegate. |
| 1430 | % |
| 1431 | % The format of the GetDelegateMode method is: |
| 1432 | % |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1433 | % ssize_t GetDelegateMode(const DelegateInfo *delegate_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1434 | % |
| 1435 | % A description of each parameter follows: |
| 1436 | % |
| 1437 | % o delegate_info: The delegate info. |
| 1438 | % |
| 1439 | */ |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1440 | MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1441 | { |
| 1442 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
anthony | 59c4443 | 2012-05-23 04:41:25 +0000 | [diff] [blame] | 1443 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1444 | assert(delegate_info != (DelegateInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1445 | assert(delegate_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1446 | return(delegate_info->mode); |
| 1447 | } |
| 1448 | |
| 1449 | /* |
| 1450 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1451 | % % |
| 1452 | % % |
| 1453 | % % |
| 1454 | + G e t D e l e g a t e T h r e a d S u p p o r t % |
| 1455 | % % |
| 1456 | % % |
| 1457 | % % |
| 1458 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1459 | % |
| 1460 | % GetDelegateThreadSupport() returns MagickTrue if the delegate supports |
| 1461 | % threads. |
| 1462 | % |
| 1463 | % The format of the GetDelegateThreadSupport method is: |
| 1464 | % |
| 1465 | % MagickBooleanType GetDelegateThreadSupport( |
| 1466 | % const DelegateInfo *delegate_info) |
| 1467 | % |
| 1468 | % A description of each parameter follows: |
| 1469 | % |
| 1470 | % o delegate_info: The delegate info. |
| 1471 | % |
| 1472 | */ |
| 1473 | MagickExport MagickBooleanType GetDelegateThreadSupport( |
| 1474 | const DelegateInfo *delegate_info) |
| 1475 | { |
| 1476 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"..."); |
anthony | 59c4443 | 2012-05-23 04:41:25 +0000 | [diff] [blame] | 1477 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1478 | assert(delegate_info != (DelegateInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1479 | assert(delegate_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1480 | return(delegate_info->thread_support); |
| 1481 | } |
| 1482 | |
| 1483 | /* |
| 1484 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1485 | % % |
| 1486 | % % |
| 1487 | % % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1488 | + 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] | 1489 | % % |
| 1490 | % % |
| 1491 | % % |
| 1492 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1493 | % |
cristy | 10e530d | 2014-03-19 13:39:13 +0000 | [diff] [blame] | 1494 | % IsDelegateCacheInstantiated() determines if the delegate cache is |
| 1495 | % instantiated. If not, it instantiates the cache and returns it. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1496 | % |
cristy | 904e591 | 2014-03-15 19:53:14 +0000 | [diff] [blame] | 1497 | % The format of the IsDelegateInstantiated method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1498 | % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1499 | % MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1500 | % |
| 1501 | % A description of each parameter follows. |
| 1502 | % |
| 1503 | % o exception: return any errors or warnings in this structure. |
| 1504 | % |
| 1505 | */ |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1506 | static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1507 | { |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1508 | if (delegate_cache == (LinkedListInfo *) NULL) |
| 1509 | { |
| 1510 | if (delegate_semaphore == (SemaphoreInfo *) NULL) |
| 1511 | ActivateSemaphoreInfo(&delegate_semaphore); |
| 1512 | LockSemaphoreInfo(delegate_semaphore); |
| 1513 | if (delegate_cache == (LinkedListInfo *) NULL) |
| 1514 | delegate_cache=AcquireDelegateCache(DelegateFilename,exception); |
| 1515 | UnlockSemaphoreInfo(delegate_semaphore); |
| 1516 | } |
dirk | 972c2e4 | 2015-07-25 19:23:33 +0000 | [diff] [blame] | 1517 | return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1518 | } |
| 1519 | |
| 1520 | /* |
| 1521 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1522 | % % |
| 1523 | % % |
| 1524 | % % |
| 1525 | % I n v o k e D e l e g a t e % |
| 1526 | % % |
| 1527 | % % |
| 1528 | % % |
| 1529 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1530 | % |
| 1531 | % InvokeDelegate replaces any embedded formatting characters with the |
| 1532 | % appropriate image attribute and executes the resulting command. MagickFalse |
| 1533 | % is returned if the commands execute with success otherwise MagickTrue. |
| 1534 | % |
| 1535 | % The format of the InvokeDelegate method is: |
| 1536 | % |
| 1537 | % MagickBooleanType InvokeDelegate(ImageInfo *image_info,Image *image, |
| 1538 | % const char *decode,const char *encode,ExceptionInfo *exception) |
| 1539 | % |
| 1540 | % A description of each parameter follows: |
| 1541 | % |
| 1542 | % o image_info: the imageInfo. |
| 1543 | % |
| 1544 | % o image: the image. |
| 1545 | % |
| 1546 | % o exception: return any errors or warnings in this structure. |
| 1547 | % |
| 1548 | */ |
| 1549 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1550 | static MagickBooleanType CopyDelegateFile(const char *source, |
cristy | 4886c4f | 2015-06-06 15:26:09 +0000 | [diff] [blame] | 1551 | const char *destination,const MagickBooleanType overwrite) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1552 | { |
| 1553 | int |
| 1554 | destination_file, |
| 1555 | source_file; |
| 1556 | |
cristy | 53ac66f | 2012-03-11 02:56:37 +0000 | [diff] [blame] | 1557 | MagickBooleanType |
| 1558 | status; |
| 1559 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1560 | register size_t |
| 1561 | i; |
| 1562 | |
| 1563 | size_t |
| 1564 | length, |
| 1565 | quantum; |
| 1566 | |
| 1567 | ssize_t |
| 1568 | count; |
| 1569 | |
| 1570 | struct stat |
| 1571 | attributes; |
| 1572 | |
| 1573 | unsigned char |
| 1574 | *buffer; |
| 1575 | |
| 1576 | /* |
cristy | 2dfb1df | 2012-02-25 14:16:09 +0000 | [diff] [blame] | 1577 | Copy source file to destination. |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1578 | */ |
| 1579 | assert(source != (const char *) NULL); |
| 1580 | assert(destination != (char *) NULL); |
cristy | 4886c4f | 2015-06-06 15:26:09 +0000 | [diff] [blame] | 1581 | if (overwrite == MagickFalse) |
| 1582 | { |
| 1583 | status=GetPathAttributes(destination,&attributes); |
| 1584 | if (status != MagickFalse) |
| 1585 | return(MagickTrue); |
| 1586 | } |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 1587 | destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1588 | if (destination_file == -1) |
| 1589 | return(MagickFalse); |
cristy | 18c6c27 | 2011-09-23 14:40:37 +0000 | [diff] [blame] | 1590 | source_file=open_utf8(source,O_RDONLY | O_BINARY,0); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1591 | if (source_file == -1) |
| 1592 | { |
| 1593 | (void) close(destination_file); |
| 1594 | return(MagickFalse); |
| 1595 | } |
| 1596 | quantum=(size_t) MagickMaxBufferExtent; |
cristy | f201ba6 | 2015-07-05 13:54:28 +0000 | [diff] [blame] | 1597 | if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1598 | quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent); |
| 1599 | buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer)); |
| 1600 | if (buffer == (unsigned char *) NULL) |
| 1601 | { |
| 1602 | (void) close(source_file); |
| 1603 | (void) close(destination_file); |
| 1604 | return(MagickFalse); |
| 1605 | } |
| 1606 | length=0; |
| 1607 | for (i=0; ; i+=count) |
| 1608 | { |
| 1609 | count=(ssize_t) read(source_file,buffer,quantum); |
| 1610 | if (count <= 0) |
| 1611 | break; |
| 1612 | length=(size_t) count; |
| 1613 | count=(ssize_t) write(destination_file,buffer,length); |
| 1614 | if ((size_t) count != length) |
| 1615 | break; |
| 1616 | } |
| 1617 | (void) close(destination_file); |
| 1618 | (void) close(source_file); |
| 1619 | buffer=(unsigned char *) RelinquishMagickMemory(buffer); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1620 | return(i != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1621 | } |
| 1622 | |
| 1623 | MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info, |
| 1624 | Image *image,const char *decode,const char *encode,ExceptionInfo *exception) |
| 1625 | { |
| 1626 | char |
| 1627 | *command, |
| 1628 | **commands, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1629 | input_filename[MagickPathExtent], |
| 1630 | output_filename[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1631 | |
| 1632 | const DelegateInfo |
| 1633 | *delegate_info; |
| 1634 | |
| 1635 | MagickBooleanType |
| 1636 | status, |
| 1637 | temporary; |
| 1638 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1639 | PolicyRights |
| 1640 | rights; |
| 1641 | |
Cristy | f82a2e0 | 2016-02-13 08:35:17 -0500 | [diff] [blame] | 1642 | register ssize_t |
| 1643 | i; |
| 1644 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1645 | /* |
| 1646 | Get delegate. |
| 1647 | */ |
| 1648 | assert(image_info != (ImageInfo *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1649 | assert(image_info->signature == MagickCoreSignature); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1650 | assert(image != (Image *) NULL); |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 1651 | assert(image->signature == MagickCoreSignature); |
cristy | cb190b7 | 2014-08-31 20:04:42 +0000 | [diff] [blame] | 1652 | if (image->debug != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1653 | (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename); |
| 1654 | rights=ExecutePolicyRights; |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1655 | if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1656 | { |
cristy | a9197f6 | 2010-01-12 02:23:34 +0000 | [diff] [blame] | 1657 | errno=EPERM; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1658 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1659 | "NotAuthorized","`%s'",decode); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1660 | return(MagickFalse); |
| 1661 | } |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1662 | if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1663 | { |
cristy | a9197f6 | 2010-01-12 02:23:34 +0000 | [diff] [blame] | 1664 | errno=EPERM; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1665 | (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1666 | "NotAuthorized","`%s'",encode); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1667 | return(MagickFalse); |
| 1668 | } |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1669 | temporary=*image->filename == '\0' ? MagickTrue : MagickFalse; |
| 1670 | if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) == |
| 1671 | MagickFalse)) |
| 1672 | { |
| 1673 | ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile", |
| 1674 | image->filename); |
| 1675 | return(MagickFalse); |
| 1676 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1677 | delegate_info=GetDelegateInfo(decode,encode,exception); |
| 1678 | if (delegate_info == (DelegateInfo *) NULL) |
| 1679 | { |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1680 | if (temporary != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1681 | (void) RelinquishUniqueFileResource(image->filename); |
| 1682 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1683 | "NoTagFound","`%s'",decode ? decode : encode); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1684 | return(MagickFalse); |
| 1685 | } |
| 1686 | if (*image_info->filename == '\0') |
| 1687 | { |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1688 | if (AcquireUniqueFilename(image_info->filename) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1689 | { |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1690 | if (temporary != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1691 | (void) RelinquishUniqueFileResource(image->filename); |
| 1692 | ThrowFileException(exception,FileOpenError, |
| 1693 | "UnableToCreateTemporaryFile",image_info->filename); |
| 1694 | return(MagickFalse); |
| 1695 | } |
| 1696 | image_info->temporary=MagickTrue; |
| 1697 | } |
cristy | fc7f59b | 2011-09-16 00:41:11 +0000 | [diff] [blame] | 1698 | if ((delegate_info->mode != 0) && (((decode != (const char *) NULL) && |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1699 | (delegate_info->encode != (char *) NULL)) || |
| 1700 | ((encode != (const char *) NULL) && |
| 1701 | (delegate_info->decode != (char *) NULL)))) |
| 1702 | { |
| 1703 | char |
| 1704 | *magick; |
| 1705 | |
| 1706 | ImageInfo |
| 1707 | *clone_info; |
| 1708 | |
| 1709 | register Image |
| 1710 | *p; |
| 1711 | |
| 1712 | /* |
| 1713 | Delegate requires a particular image format. |
| 1714 | */ |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1715 | if (AcquireUniqueFilename(image_info->unique) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1716 | { |
| 1717 | ThrowFileException(exception,FileOpenError, |
| 1718 | "UnableToCreateTemporaryFile",image_info->unique); |
| 1719 | return(MagickFalse); |
| 1720 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1721 | magick=InterpretImageProperties(image_info,image,decode != (char *) NULL ? |
cristy | 018f07f | 2011-09-04 21:15:19 +0000 | [diff] [blame] | 1722 | delegate_info->encode : delegate_info->decode,exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1723 | if (magick == (char *) NULL) |
| 1724 | { |
| 1725 | (void) RelinquishUniqueFileResource(image_info->unique); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1726 | if (temporary != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1727 | (void) RelinquishUniqueFileResource(image->filename); |
| 1728 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1729 | DelegateError,"DelegateFailed","`%s'",decode ? decode : encode); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1730 | return(MagickFalse); |
| 1731 | } |
| 1732 | LocaleUpper(magick); |
| 1733 | clone_info=CloneImageInfo(image_info); |
| 1734 | (void) CopyMagickString((char *) clone_info->magick,magick, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1735 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1736 | if (LocaleCompare(magick,"NULL") != 0) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1737 | (void) CopyMagickString(image->magick,magick,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1738 | magick=DestroyString(magick); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1739 | (void) FormatLocaleString(clone_info->filename,MagickPathExtent,"%s:", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1740 | delegate_info->decode); |
cristy | d965a42 | 2010-03-03 17:47:35 +0000 | [diff] [blame] | 1741 | (void) SetImageInfo(clone_info,(unsigned int) GetImageListLength(image), |
| 1742 | exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1743 | (void) CopyMagickString(clone_info->filename,image_info->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1744 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1745 | (void) CopyMagickString(image_info->filename,image->filename, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1746 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1747 | for (p=image; p != (Image *) NULL; p=GetNextImageInList(p)) |
| 1748 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1749 | (void) FormatLocaleString(p->filename,MagickPathExtent,"%s:%s", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1750 | delegate_info->decode,clone_info->filename); |
cristy | 6f9e0d3 | 2011-08-28 16:32:09 +0000 | [diff] [blame] | 1751 | status=WriteImage(clone_info,p,exception); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1752 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1753 | { |
| 1754 | (void) RelinquishUniqueFileResource(image_info->unique); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1755 | if (temporary != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1756 | (void) RelinquishUniqueFileResource(image->filename); |
| 1757 | clone_info=DestroyImageInfo(clone_info); |
| 1758 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1759 | DelegateError,"DelegateFailed","`%s'",decode ? decode : encode); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1760 | return(MagickFalse); |
| 1761 | } |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1762 | if (clone_info->adjoin != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1763 | break; |
| 1764 | } |
| 1765 | (void) RelinquishUniqueFileResource(image_info->unique); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1766 | clone_info=DestroyImageInfo(clone_info); |
| 1767 | } |
| 1768 | /* |
| 1769 | Invoke delegate. |
| 1770 | */ |
| 1771 | commands=StringToList(delegate_info->commands); |
| 1772 | if (commands == (char **) NULL) |
| 1773 | { |
dirk | 11a7cb7 | 2016-01-05 14:00:04 +0100 | [diff] [blame] | 1774 | if (temporary != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1775 | (void) RelinquishUniqueFileResource(image->filename); |
| 1776 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1777 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1778 | decode ? decode : encode); |
| 1779 | return(MagickFalse); |
| 1780 | } |
| 1781 | command=(char *) NULL; |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1782 | status=MagickTrue; |
| 1783 | (void) CopyMagickString(output_filename,image_info->filename, |
| 1784 | MagickPathExtent); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1785 | (void) CopyMagickString(input_filename,image->filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1786 | for (i=0; commands[i] != (char *) NULL; i++) |
| 1787 | { |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1788 | (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename); |
| 1789 | if (AcquireUniqueFilename(image_info->unique) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1790 | { |
| 1791 | ThrowFileException(exception,FileOpenError, |
| 1792 | "UnableToCreateTemporaryFile",image_info->unique); |
| 1793 | break; |
| 1794 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1795 | if (LocaleCompare(decode,"SCAN") != 0) |
| 1796 | { |
| 1797 | status=AcquireUniqueSymbolicLink(input_filename,image->filename); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1798 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1799 | { |
| 1800 | ThrowFileException(exception,FileOpenError, |
| 1801 | "UnableToCreateTemporaryFile",input_filename); |
| 1802 | break; |
| 1803 | } |
| 1804 | } |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1805 | status=MagickTrue; |
Cristy | 8be0b1e | 2016-05-13 20:45:40 -0400 | [diff] [blame] | 1806 | command=InterpretDelegateProperties(image_info,image,commands[i],exception); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1807 | if (command != (char *) NULL) |
| 1808 | { |
| 1809 | /* |
| 1810 | Execute delegate. |
| 1811 | */ |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1812 | if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose, |
| 1813 | command,(char *) NULL,exception) != 0) |
| 1814 | status=MagickFalse; |
| 1815 | if (delegate_info->spawn != MagickFalse) |
cristy | 77f6939 | 2012-05-26 01:15:25 +0000 | [diff] [blame] | 1816 | { |
| 1817 | ssize_t |
| 1818 | count; |
| 1819 | |
| 1820 | /* |
Cristy | c7107ee | 2016-07-23 19:08:45 -0400 | [diff] [blame] | 1821 | Wait for input file to 'disappear', or maximum 2 seconds. |
cristy | 77f6939 | 2012-05-26 01:15:25 +0000 | [diff] [blame] | 1822 | */ |
Cristy | c7107ee | 2016-07-23 19:08:45 -0400 | [diff] [blame] | 1823 | count=20; |
cristy | 3fe49df | 2012-05-26 01:17:56 +0000 | [diff] [blame] | 1824 | while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0)) |
cristy | 5839938 | 2012-05-26 12:44:41 +0000 | [diff] [blame] | 1825 | (void) MagickDelay(100); /* sleep 0.1 seconds */ |
anthony | 2ec9bd9 | 2012-05-20 05:43:24 +0000 | [diff] [blame] | 1826 | } |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1827 | command=DestroyString(command); |
| 1828 | } |
| 1829 | if (LocaleCompare(decode,"SCAN") != 0) |
| 1830 | { |
cristy | 4886c4f | 2015-06-06 15:26:09 +0000 | [diff] [blame] | 1831 | if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1832 | (void) RelinquishUniqueFileResource(input_filename); |
| 1833 | } |
Cristy | f82a2e0 | 2016-02-13 08:35:17 -0500 | [diff] [blame] | 1834 | if ((strcmp(input_filename,output_filename) != 0) && |
| 1835 | (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1836 | (void) RelinquishUniqueFileResource(output_filename); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1837 | if (image_info->temporary != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1838 | (void) RelinquishUniqueFileResource(image_info->filename); |
| 1839 | (void) RelinquishUniqueFileResource(image_info->unique); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1840 | (void) RelinquishUniqueFileResource(image_info->filename); |
| 1841 | (void) RelinquishUniqueFileResource(image->filename); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1842 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1843 | { |
| 1844 | (void) ThrowMagickException(exception,GetMagickModule(),DelegateError, |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 1845 | "DelegateFailed","`%s'",commands[i]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1846 | break; |
| 1847 | } |
| 1848 | commands[i]=DestroyString(commands[i]); |
| 1849 | } |
Cristy | 8ef5a07 | 2016-05-14 11:49:10 -0400 | [diff] [blame] | 1850 | (void) CopyMagickString(image_info->filename,output_filename, |
| 1851 | MagickPathExtent); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1852 | (void) CopyMagickString(image->filename,input_filename,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1853 | /* |
| 1854 | Relinquish resources. |
| 1855 | */ |
| 1856 | for ( ; commands[i] != (char *) NULL; i++) |
| 1857 | commands[i]=DestroyString(commands[i]); |
| 1858 | commands=(char **) RelinquishMagickMemory(commands); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1859 | if (temporary != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1860 | (void) RelinquishUniqueFileResource(image->filename); |
dirk | b9dbc29 | 2015-07-26 09:50:00 +0000 | [diff] [blame] | 1861 | return(status); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1862 | } |
| 1863 | |
| 1864 | /* |
| 1865 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1866 | % % |
| 1867 | % % |
| 1868 | % % |
| 1869 | % L i s t D e l e g a t e I n f o % |
| 1870 | % % |
| 1871 | % % |
| 1872 | % % |
| 1873 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1874 | % |
| 1875 | % ListDelegateInfo() lists the image formats to a file. |
| 1876 | % |
| 1877 | % The format of the ListDelegateInfo method is: |
| 1878 | % |
| 1879 | % MagickBooleanType ListDelegateInfo(FILE *file,ExceptionInfo *exception) |
| 1880 | % |
| 1881 | % A description of each parameter follows. |
| 1882 | % |
| 1883 | % o file: An pointer to a FILE. |
| 1884 | % |
| 1885 | % o exception: return any errors or warnings in this structure. |
| 1886 | % |
| 1887 | */ |
| 1888 | MagickExport MagickBooleanType ListDelegateInfo(FILE *file, |
| 1889 | ExceptionInfo *exception) |
| 1890 | { |
| 1891 | const DelegateInfo |
| 1892 | **delegate_info; |
| 1893 | |
| 1894 | char |
| 1895 | **commands, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1896 | delegate[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1897 | |
| 1898 | const char |
| 1899 | *path; |
| 1900 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1901 | register ssize_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1902 | i; |
| 1903 | |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1904 | size_t |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1905 | number_delegates; |
| 1906 | |
cristy | 9d314ff | 2011-03-09 01:30:28 +0000 | [diff] [blame] | 1907 | ssize_t |
| 1908 | j; |
| 1909 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1910 | if (file == (const FILE *) NULL) |
| 1911 | file=stdout; |
| 1912 | delegate_info=GetDelegateInfoList("*",&number_delegates,exception); |
| 1913 | if (delegate_info == (const DelegateInfo **) NULL) |
| 1914 | return(MagickFalse); |
| 1915 | path=(const char *) NULL; |
cristy | bb50337 | 2010-05-27 20:51:26 +0000 | [diff] [blame] | 1916 | for (i=0; i < (ssize_t) number_delegates; i++) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1917 | { |
dirk | 11a7cb7 | 2016-01-05 14:00:04 +0100 | [diff] [blame] | 1918 | if (delegate_info[i]->stealth != MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1919 | continue; |
| 1920 | if ((path == (const char *) NULL) || |
| 1921 | (LocaleCompare(path,delegate_info[i]->path) != 0)) |
| 1922 | { |
| 1923 | if (delegate_info[i]->path != (char *) NULL) |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1924 | (void) FormatLocaleFile(file,"\nPath: %s\n\n",delegate_info[i]->path); |
| 1925 | (void) FormatLocaleFile(file,"Delegate Command\n"); |
cristy | 1e60481 | 2011-05-19 18:07:50 +0000 | [diff] [blame] | 1926 | (void) FormatLocaleFile(file, |
| 1927 | "-------------------------------------------------" |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1928 | "------------------------------\n"); |
| 1929 | } |
| 1930 | path=delegate_info[i]->path; |
| 1931 | *delegate='\0'; |
| 1932 | if (delegate_info[i]->encode != (char *) NULL) |
Cristy | 5f478ca | 2016-05-14 18:43:20 -0400 | [diff] [blame] | 1933 | (void) CopyMagickString(delegate,delegate_info[i]->encode, |
| 1934 | MagickPathExtent); |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1935 | (void) ConcatenateMagickString(delegate," ",MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1936 | delegate[8]='\0'; |
| 1937 | commands=StringToList(delegate_info[i]->commands); |
| 1938 | if (commands == (char **) NULL) |
| 1939 | continue; |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1940 | (void) FormatLocaleFile(file,"%11s%c=%c%s ",delegate_info[i]->decode ? |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1941 | delegate_info[i]->decode : "",delegate_info[i]->mode <= 0 ? '<' : ' ', |
| 1942 | delegate_info[i]->mode >= 0 ? '>' : ' ',delegate); |
| 1943 | StripString(commands[0]); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1944 | (void) FormatLocaleFile(file,"\"%s\"\n",commands[0]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1945 | for (j=1; commands[j] != (char *) NULL; j++) |
| 1946 | { |
| 1947 | StripString(commands[j]); |
cristy | b51dff5 | 2011-05-19 16:55:47 +0000 | [diff] [blame] | 1948 | (void) FormatLocaleFile(file," \"%s\"\n",commands[j]); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1949 | } |
| 1950 | for (j=0; commands[j] != (char *) NULL; j++) |
| 1951 | commands[j]=DestroyString(commands[j]); |
| 1952 | commands=(char **) RelinquishMagickMemory(commands); |
| 1953 | } |
| 1954 | (void) fflush(file); |
| 1955 | delegate_info=(const DelegateInfo **) |
| 1956 | RelinquishMagickMemory((void *) delegate_info); |
| 1957 | return(MagickTrue); |
| 1958 | } |
| 1959 | |
| 1960 | /* |
| 1961 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1962 | % % |
| 1963 | % % |
| 1964 | % % |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 1965 | + L o a d D e l e g a t e C a c h e % |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1966 | % % |
| 1967 | % % |
| 1968 | % % |
| 1969 | %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% |
| 1970 | % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1971 | % LoadDelegateCache() loads the delegate configurations which provides a |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1972 | % mapping between delegate attributes and a delegate name. |
| 1973 | % |
cristy | 86e5ac9 | 2014-03-16 19:27:39 +0000 | [diff] [blame] | 1974 | % The format of the LoadDelegateCache method is: |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1975 | % |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 1976 | % MagickBooleanType LoadDelegateCache(LinkedListInfo *cache, |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 1977 | % const char *xml,const char *filename,const size_t depth, |
| 1978 | % ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1979 | % |
| 1980 | % A description of each parameter follows: |
| 1981 | % |
| 1982 | % o xml: The delegate list in XML format. |
| 1983 | % |
| 1984 | % o filename: The delegate list filename. |
| 1985 | % |
| 1986 | % o depth: depth of <include /> statements. |
| 1987 | % |
| 1988 | % o exception: return any errors or warnings in this structure. |
| 1989 | % |
| 1990 | */ |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 1991 | static MagickBooleanType LoadDelegateCache(LinkedListInfo *cache, |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 1992 | const char *xml,const char *filename,const size_t depth, |
| 1993 | ExceptionInfo *exception) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1994 | { |
| 1995 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 1996 | keyword[MagickPathExtent], |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 1997 | *token; |
| 1998 | |
| 1999 | const char |
| 2000 | *q; |
| 2001 | |
| 2002 | DelegateInfo |
| 2003 | *delegate_info; |
| 2004 | |
cristy | 759ba91 | 2014-06-26 11:59:43 +0000 | [diff] [blame] | 2005 | MagickStatusType |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2006 | status; |
| 2007 | |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 2008 | size_t |
| 2009 | extent; |
| 2010 | |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2011 | /* |
| 2012 | Load the delegate map file. |
| 2013 | */ |
| 2014 | (void) LogMagickEvent(ConfigureEvent,GetMagickModule(), |
| 2015 | "Loading delegate configuration file \"%s\" ...",filename); |
| 2016 | if (xml == (const char *) NULL) |
| 2017 | return(MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2018 | status=MagickTrue; |
| 2019 | delegate_info=(DelegateInfo *) NULL; |
| 2020 | token=AcquireString(xml); |
dirk | fc0f124 | 2016-03-26 00:36:39 +0100 | [diff] [blame] | 2021 | extent=strlen(token)+MagickPathExtent; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2022 | for (q=(const char *) xml; *q != '\0'; ) |
| 2023 | { |
| 2024 | /* |
| 2025 | Interpret XML. |
| 2026 | */ |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2027 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2028 | if (*token == '\0') |
| 2029 | break; |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2030 | (void) CopyMagickString(keyword,token,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2031 | if (LocaleNCompare(keyword,"<!DOCTYPE",9) == 0) |
| 2032 | { |
| 2033 | /* |
| 2034 | Doctype element. |
| 2035 | */ |
| 2036 | while ((LocaleNCompare(q,"]>",2) != 0) && (*q != '\0')) |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2037 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2038 | continue; |
| 2039 | } |
| 2040 | if (LocaleNCompare(keyword,"<!--",4) == 0) |
| 2041 | { |
| 2042 | /* |
| 2043 | Comment element. |
| 2044 | */ |
| 2045 | while ((LocaleNCompare(q,"->",2) != 0) && (*q != '\0')) |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2046 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2047 | continue; |
| 2048 | } |
| 2049 | if (LocaleCompare(keyword,"<include") == 0) |
| 2050 | { |
| 2051 | /* |
| 2052 | Include element. |
| 2053 | */ |
| 2054 | while (((*token != '/') && (*(token+1) != '>')) && (*q != '\0')) |
| 2055 | { |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2056 | (void) CopyMagickString(keyword,token,MagickPathExtent); |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2057 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2058 | if (*token != '=') |
| 2059 | continue; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2060 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2061 | if (LocaleCompare(keyword,"file") == 0) |
| 2062 | { |
Cristy | 8a4029f | 2018-02-05 07:35:07 -0500 | [diff] [blame] | 2063 | if (depth > MagickMaxRecursionDepth) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2064 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2065 | ConfigureError,"IncludeElementNestedTooDeeply","`%s'",token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2066 | else |
| 2067 | { |
| 2068 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2069 | path[MagickPathExtent], |
dirk | aa6a11c | 2015-10-18 12:21:23 +0200 | [diff] [blame] | 2070 | *file_xml; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2071 | |
| 2072 | GetPathComponent(filename,HeadPath,path); |
| 2073 | if (*path != '\0') |
| 2074 | (void) ConcatenateMagickString(path,DirectorySeparator, |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2075 | MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2076 | if (*token == *DirectorySeparator) |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2077 | (void) CopyMagickString(path,token,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2078 | else |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2079 | (void) ConcatenateMagickString(path,token,MagickPathExtent); |
dirk | aa6a11c | 2015-10-18 12:21:23 +0200 | [diff] [blame] | 2080 | file_xml=FileToXML(path,~0UL); |
| 2081 | if (file_xml != (char *) NULL) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2082 | { |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 2083 | status&=LoadDelegateCache(cache,file_xml,path, |
cristy | cd2cd18 | 2014-03-18 12:10:55 +0000 | [diff] [blame] | 2084 | depth+1,exception); |
dirk | b81f0ab | 2015-10-20 23:01:53 +0200 | [diff] [blame] | 2085 | file_xml=DestroyString(file_xml); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2086 | } |
| 2087 | } |
| 2088 | } |
| 2089 | } |
| 2090 | continue; |
| 2091 | } |
| 2092 | if (LocaleCompare(keyword,"<delegate") == 0) |
| 2093 | { |
| 2094 | /* |
| 2095 | Delegate element. |
| 2096 | */ |
Dirk Lemstra | 06344a0 | 2017-10-15 10:10:01 +0200 | [diff] [blame] | 2097 | delegate_info=(DelegateInfo *) AcquireCriticalMemory( |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2098 | sizeof(*delegate_info)); |
Cristy | 81bfff2 | 2018-03-10 07:58:31 -0500 | [diff] [blame] | 2099 | (void) memset(delegate_info,0,sizeof(*delegate_info)); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2100 | delegate_info->path=ConstantString(filename); |
cristy | 571ce68 | 2014-03-19 13:52:13 +0000 | [diff] [blame] | 2101 | delegate_info->thread_support=MagickTrue; |
cristy | e1c94d9 | 2015-06-28 12:16:33 +0000 | [diff] [blame] | 2102 | delegate_info->signature=MagickCoreSignature; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2103 | continue; |
| 2104 | } |
| 2105 | if (delegate_info == (DelegateInfo *) NULL) |
| 2106 | continue; |
Cristy | fed111e | 2017-01-09 07:22:16 -0500 | [diff] [blame] | 2107 | if ((LocaleCompare(keyword,"/>") == 0) || |
| 2108 | (LocaleCompare(keyword,"</policy>") == 0)) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2109 | { |
dirk | c9f5cc8 | 2016-07-17 18:59:02 +0200 | [diff] [blame] | 2110 | status=AppendValueToLinkedList(cache,delegate_info); |
dirk | 5d0a441 | 2016-01-05 22:28:51 +0100 | [diff] [blame] | 2111 | if (status == MagickFalse) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2112 | (void) ThrowMagickException(exception,GetMagickModule(), |
cristy | efe601c | 2013-01-05 17:51:12 +0000 | [diff] [blame] | 2113 | ResourceLimitError,"MemoryAllocationFailed","`%s'", |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2114 | delegate_info->commands); |
| 2115 | delegate_info=(DelegateInfo *) NULL; |
cristy | d45122f | 2014-01-14 23:46:16 +0000 | [diff] [blame] | 2116 | continue; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2117 | } |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2118 | GetNextToken(q,(const char **) NULL,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2119 | if (*token != '=') |
| 2120 | continue; |
Cristy | 8bedb4e | 2016-03-25 19:54:25 -0400 | [diff] [blame] | 2121 | GetNextToken(q,&q,extent,token); |
| 2122 | GetNextToken(q,&q,extent,token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2123 | switch (*keyword) |
| 2124 | { |
| 2125 | case 'C': |
| 2126 | case 'c': |
| 2127 | { |
| 2128 | if (LocaleCompare((char *) keyword,"command") == 0) |
| 2129 | { |
| 2130 | char |
| 2131 | *commands; |
| 2132 | |
| 2133 | commands=AcquireString(token); |
cristy | 0157aea | 2010-04-24 21:12:18 +0000 | [diff] [blame] | 2134 | #if defined(MAGICKCORE_WINDOWS_SUPPORT) |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2135 | if (strchr(commands,'@') != (char *) NULL) |
| 2136 | { |
| 2137 | char |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2138 | path[MagickPathExtent]; |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2139 | |
cristy | 151b66d | 2015-04-15 10:50:31 +0000 | [diff] [blame] | 2140 | NTGhostscriptEXE(path,MagickPathExtent); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2141 | (void) SubstituteString((char **) &commands,"@PSDelegate@", |
| 2142 | path); |
| 2143 | (void) SubstituteString((char **) &commands,"\\","/"); |
| 2144 | } |
dirk | 0445144 | 2016-05-15 08:33:28 +0200 | [diff] [blame] | 2145 | (void) SubstituteString((char **) &commands,""","\""); |
| 2146 | #else |
| 2147 | (void) SubstituteString((char **) &commands,""","'"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2148 | #endif |
| 2149 | (void) SubstituteString((char **) &commands,"&","&"); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2150 | (void) SubstituteString((char **) &commands,">",">"); |
| 2151 | (void) SubstituteString((char **) &commands,"<","<"); |
| 2152 | delegate_info->commands=commands; |
| 2153 | break; |
| 2154 | } |
| 2155 | break; |
| 2156 | } |
| 2157 | case 'D': |
| 2158 | case 'd': |
| 2159 | { |
| 2160 | if (LocaleCompare((char *) keyword,"decode") == 0) |
| 2161 | { |
| 2162 | delegate_info->decode=ConstantString(token); |
| 2163 | delegate_info->mode=1; |
| 2164 | break; |
| 2165 | } |
| 2166 | break; |
| 2167 | } |
| 2168 | case 'E': |
| 2169 | case 'e': |
| 2170 | { |
| 2171 | if (LocaleCompare((char *) keyword,"encode") == 0) |
| 2172 | { |
| 2173 | delegate_info->encode=ConstantString(token); |
| 2174 | delegate_info->mode=(-1); |
| 2175 | break; |
| 2176 | } |
| 2177 | break; |
| 2178 | } |
| 2179 | case 'M': |
| 2180 | case 'm': |
| 2181 | { |
| 2182 | if (LocaleCompare((char *) keyword,"mode") == 0) |
| 2183 | { |
| 2184 | delegate_info->mode=1; |
| 2185 | if (LocaleCompare(token,"bi") == 0) |
| 2186 | delegate_info->mode=0; |
| 2187 | else |
| 2188 | if (LocaleCompare(token,"encode") == 0) |
| 2189 | delegate_info->mode=(-1); |
| 2190 | break; |
| 2191 | } |
| 2192 | break; |
| 2193 | } |
| 2194 | case 'S': |
| 2195 | case 's': |
| 2196 | { |
| 2197 | if (LocaleCompare((char *) keyword,"spawn") == 0) |
| 2198 | { |
anthony | 6f20131 | 2012-03-30 04:08:15 +0000 | [diff] [blame] | 2199 | delegate_info->spawn=IsStringTrue(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2200 | break; |
| 2201 | } |
| 2202 | if (LocaleCompare((char *) keyword,"stealth") == 0) |
| 2203 | { |
anthony | 6f20131 | 2012-03-30 04:08:15 +0000 | [diff] [blame] | 2204 | delegate_info->stealth=IsStringTrue(token); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2205 | break; |
| 2206 | } |
| 2207 | break; |
| 2208 | } |
| 2209 | case 'T': |
| 2210 | case 't': |
| 2211 | { |
| 2212 | if (LocaleCompare((char *) keyword,"thread-support") == 0) |
| 2213 | { |
anthony | 6f20131 | 2012-03-30 04:08:15 +0000 | [diff] [blame] | 2214 | delegate_info->thread_support=IsStringTrue(token); |
cristy | 571ce68 | 2014-03-19 13:52:13 +0000 | [diff] [blame] | 2215 | if (delegate_info->thread_support == MagickFalse) |
| 2216 | delegate_info->semaphore=AcquireSemaphoreInfo(); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2217 | break; |
| 2218 | } |
| 2219 | break; |
| 2220 | } |
| 2221 | default: |
| 2222 | break; |
| 2223 | } |
| 2224 | } |
| 2225 | token=(char *) RelinquishMagickMemory(token); |
cristy | 759ba91 | 2014-06-26 11:59:43 +0000 | [diff] [blame] | 2226 | return(status != 0 ? MagickTrue : MagickFalse); |
cristy | 3ed852e | 2009-09-05 21:47:34 +0000 | [diff] [blame] | 2227 | } |