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