48 #include "magick/studio.h"
49 #include "magick/artifact.h"
50 #include "magick/attribute.h"
51 #include "magick/blob.h"
52 #include "magick/client.h"
53 #include "magick/configure.h"
54 #include "magick/constitute.h"
55 #include "magick/delegate.h"
56 #include "magick/exception.h"
57 #include "magick/exception-private.h"
58 #include "magick/hashmap.h"
59 #include "magick/image-private.h"
60 #include "magick/list.h"
61 #include "magick/memory_.h"
62 #include "magick/nt-base-private.h"
63 #include "magick/option.h"
64 #include "magick/policy.h"
65 #include "magick/property.h"
66 #include "magick/resource_.h"
67 #include "magick/semaphore.h"
68 #include "magick/signature.h"
69 #include "magick/string_.h"
70 #include "magick/token.h"
71 #include "magick/token-private.h"
72 #include "magick/utility.h"
73 #include "magick/utility-private.h"
74 #include "magick/xml-tree.h"
75 #include "magick/xml-tree-private.h"
80 #if defined(__APPLE__)
81 #include "TargetConditionals.h"
82 #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
83 #define system(s) ((s)==NULL ? 0 : -1)
85 #elif defined(__ANDROID__)
86 #define system(s) ((s)==NULL ? 0 : -1)
88 #define DelegateFilename "delegates.xml"
94 *DelegateMap = (
const char *)
95 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
97 " <delegate decode=\"autotrace\" stealth=\"True\" command=\""autotrace" -output-format svg -output-file "%o" "%i"\"/>"
98 " <delegate decode=\"avi:decode\" stealth=\"True\" command=\""mplayer" "%i" -really-quiet -ao null -vo png:z=3\"/>"
99 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" http://imagemagick.org/; rm "%i"\"/>"
100 " <delegate decode=\"cgm\" thread-support=\"False\" command=\""ralcgm" -d ps -oC < "%i" > "%o" 2> "%u"\"/>"
101 " <delegate decode=\"dng:decode\" command=\""ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i"\"/>"
102 " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>"
103 " <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"\"/>"
104 " <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"\"/>"
105 " <delegate decode=\"fig\" command=\""fig2dev" -L ps "%i" "%o"\"/>"
106 " <delegate decode=\"hpg\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
107 " <delegate decode=\"hpgl\" command=\""hp2xx" -q -m eps -f `basename "%o"` "%i" mv -f `basename "%o"` "%o"\"/>"
108 " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>"
109 " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>"
110 " <delegate decode=\"https\" command=\""curl" -s -k -L -o "%o" "https:%M"\"/>"
111 " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>"
112 " <delegate decode=\"man\" command=\""groff" -man -Tps "%i" > "%o"\"/>"
113 " <delegate decode=\"video:decode\" command=\""ffmpeg" -nostdin -v -1 -i "%i" -vframes %S -vcodec pam -an -f rawvideo -y "%u.pam" 2> "%u"\"/>"
114 " <delegate encode=\"video:encode\" stealth=\"True\" command=\""ffmpeg" -nostdin -v -1 -i "%M%%d.pam" -plays %I "%u.%m" 2> "%u"\"/>"
115 " <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"\"/>"
116 " <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"\"/>"
117 " <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"\"/>"
118 " <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"\"/>"
119 " <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"\"/>"
120 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>"
121 " <delegate decode=\"pnm\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>"
122 " <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"\"/>"
123 " <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"\"/>"
124 " <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"\"/>"
125 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>"
126 " <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"\"/>"
127 " <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"\"/>"
128 " <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"\"/>"
129 " <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"\"/>"
130 " <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"\"/>"
131 " <delegate decode=\"rgba\" encode=\"rle\" mode=\"encode\" command=\""rawtorle" -o "%o" -v "%i"\"/>"
132 " <delegate decode=\"scan\" command=\""scanimage" -d "%i" > "%o"\"/>"
133 " <delegate encode=\"show\" spawn=\"True\" command=\""display" -immutable -delay 0 -title "%M"\" "%i"\"/>"
134 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>"
135 " <delegate decode=\"svg\" command=\""rsvg" "%i" "%o"\"/>"
136 " <delegate decode=\"txt\" encode=\"ps\" mode=\"bi\" command=\""enscript" -o "%o" "%i"\"/>"
137 " <delegate encode=\"win\" spawn=\"True\" command=\""display" -immutable -delay 0 -title "%M"\" "%i"\"/>"
138 " <delegate decode=\"wmf\" command=\""wmf2eps" -o "%o" "%i"\"/>"
153 static MagickBooleanType
155 LoadDelegateCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
190 cache=NewLinkedList(0);
191 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
199 options=GetConfigureOptions(filename,exception);
200 option=(
const StringInfo *) GetNextValueInLinkedList(options);
203 (void) LoadDelegateCache(cache,(
const char *) GetStringInfoDatum(option),
204 GetStringInfoPath(option),0,exception);
205 option=(
const StringInfo *) GetNextValueInLinkedList(options);
207 options=DestroyConfigureOptions(options);
210 if (IsLinkedListEmpty(cache) != MagickFalse)
211 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
233 MagickExport MagickBooleanType DelegateComponentGenesis(
void)
236 delegate_semaphore=AllocateSemaphoreInfo();
259 static void *DestroyDelegate(
void *delegate_info)
265 if (p->path != (
char *) NULL)
266 p->path=DestroyString(p->path);
267 if (p->decode != (
char *) NULL)
268 p->decode=DestroyString(p->decode);
269 if (p->encode != (
char *) NULL)
270 p->encode=DestroyString(p->encode);
271 if (p->commands != (
char *) NULL)
272 p->commands=DestroyString(p->commands);
274 DestroySemaphoreInfo(&p->semaphore);
276 return((
void *) NULL);
279 MagickExport
void DelegateComponentTerminus(
void)
282 ActivateSemaphoreInfo(&delegate_semaphore);
283 LockSemaphoreInfo(delegate_semaphore);
285 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
286 UnlockSemaphoreInfo(delegate_semaphore);
287 DestroySemaphoreInfo(&delegate_semaphore);
326 MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
327 const MagickBooleanType verbose,
const char *command,
char *message,
348 arguments=StringToArgv(command,&number_arguments);
349 if (arguments == (
char **) NULL)
351 if (*arguments[1] ==
'\0')
353 for (i=0; i < (ssize_t) number_arguments; i++)
354 arguments[i]=DestroyString(arguments[i]);
355 arguments=(
char **) RelinquishMagickMemory(arguments);
358 rights=ExecutePolicyRights;
359 domain=DelegatePolicyDomain;
360 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
363 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
364 "NotAuthorized",
"`%s'",arguments[1]);
365 for (i=0; i < (ssize_t) number_arguments; i++)
366 arguments[i]=DestroyString(arguments[i]);
367 arguments=(
char **) RelinquishMagickMemory(arguments);
370 if (verbose != MagickFalse)
372 (void) FormatLocaleFile(stderr,
"%s\n",command);
373 (void) fflush(stderr);
375 sanitize_command=SanitizeString(command);
376 if (asynchronous != MagickFalse)
377 (void) ConcatenateMagickString(sanitize_command,
"&",MaxTextExtent);
378 if (message != (
char *) NULL)
380 #if defined(MAGICKCORE_POSIX_SUPPORT)
381 #if defined(MAGICKCORE_HAVE_POPEN)
382 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
385 buffer[MagickPathExtent];
394 file=popen_utf8(sanitize_command,
"r");
395 if (file == (FILE *) NULL)
396 status=system(sanitize_command);
399 while (fgets(buffer,(
int)
sizeof(buffer),file) != NULL)
404 length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
407 (void) CopyMagickString(message+offset,buffer,length);
417 #if !defined(MAGICKCORE_HAVE_EXECVP)
418 status=system(sanitize_command);
420 if ((asynchronous != MagickFalse) ||
421 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
422 status=system(sanitize_command);
431 child_pid=(pid_t) fork();
432 if (child_pid == (pid_t) -1)
433 status=system(sanitize_command);
437 status=execvp(arguments[1],arguments+1);
449 pid=(pid_t) waitpid(child_pid,&child_status,0);
454 if (WIFEXITED(child_status) != 0)
455 status=WEXITSTATUS(child_status);
457 if (WIFSIGNALED(child_status))
464 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
477 p=strstr(sanitize_command,
"cmd.exe /c");
478 if (p != (
char*) NULL)
481 for ( ; *p !=
'\0'; p++)
483 *p=(*DirectorySeparator);
486 status=NTSystemCommand(sanitize_command,message);
488 status=system(sanitize_command);
490 # error No suitable system() method.
494 if ((message != (
char *) NULL) && (*message !=
'\0'))
495 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
496 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
498 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
499 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
501 sanitize_command=DestroyString(sanitize_command);
502 for (i=0; i < (ssize_t) number_arguments; i++)
503 arguments[i]=DestroyString(arguments[i]);
504 arguments=(
char **) RelinquishMagickMemory(arguments);
546 static char *GetMagickPropertyLetter(
const ImageInfo *image_info,
Image *image,
550 value[MaxTextExtent];
555 assert(image != (
Image *) NULL);
556 assert(image->signature == MagickCoreSignature);
557 if (IsEventLogging() != MagickFalse)
558 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
560 string=(
const char *) value;
568 if (image_info->authenticate != (
char *) NULL)
569 string=image_info->authenticate;
577 (void) FormatMagickSize(image->extent,MagickFalse,value);
578 if (image->extent == 0)
579 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,value);
587 GetPathComponent(image->magick_filename,HeadPath,value);
595 GetPathComponent(image->magick_filename,ExtensionPath,value);
603 GetPathComponent(image->magick_filename,TailPath,value);
611 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
612 (
double) image->page.width,(double) image->page.height,
613 (
double) image->page.x,(double) image->page.y);
621 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
622 (image->rows != 0 ? image->rows : image->magick_rows));
630 string=image->filename;
638 string=image->magick;
646 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
647 GetImageListLength(image));
655 string=image_info->filename;
663 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
664 GetImageIndexInList(image));
672 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
673 MAGICKCORE_QUANTUM_DEPTH);
684 colorspace=image->colorspace;
685 if (SetImageGray(image,&image->exception) != MagickFalse)
686 colorspace=GRAYColorspace;
687 (void) FormatLocaleString(value,MaxTextExtent,
"%s %s %s",
688 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
689 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
690 (ssize_t) colorspace),image->matte != MagickFalse ?
"Matte" :
"" );
698 if (image_info->number_scenes != 0)
699 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
702 (
void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
711 GetPathComponent(image->magick_filename,BasePath,value);
719 string=image_info->unique;
727 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
728 (image->columns != 0 ? image->columns : image->magick_columns));
736 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
737 fabs(image->x_resolution) > MagickEpsilon ? image->x_resolution :
738 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
747 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
748 fabs(image->y_resolution) > MagickEpsilon ? image->y_resolution :
749 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
758 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
767 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
768 CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
776 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
777 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
778 image->compression));
786 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
787 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
796 (void) CopyMagickString(value,image->magick_filename,MaxTextExtent);
804 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
805 image->magick_columns,(double) image->magick_rows);
813 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
822 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
831 string=image->magick_filename;
839 (void) FormatLocaleString(value,MaxTextExtent,
"%+ld%+ld",(
long)
840 image->page.x,(long) image->page.y);
848 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
849 image->page.width,(double) image->page.height);
857 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
858 (100-(image->quality == 0 ? 42 : image->quality))/2);
866 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
867 (image->quality == 0 ? 92 : image->quality));
875 if (image_info->number_scenes == 0)
879 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
880 image_info->scene+image_info->number_scenes);
889 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
898 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
899 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
908 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
917 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
926 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
935 string=image_info->zero;
946 page=GetImageBoundingBox(image,&image->exception);
947 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
948 (
double) page.width,(double) page.height,(
double) page.x,(double)
957 (void) SignatureImage(image);
958 string=GetImageProperty(image,
"signature");
970 return(SanitizeDelegateString(
string));
973 static char *InterpretDelegateProperties(
const ImageInfo *image_info,
974 Image *image,
const char *embed_text)
976 #define ExtendInterpretText(string_length) \
978 size_t length=(string_length); \
979 if ((size_t) (q-interpret_text+length+1) >= extent) \
982 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
983 MaxTextExtent,sizeof(*interpret_text)); \
984 if (interpret_text == (char *) NULL) \
985 return((char *) NULL); \
986 q=interpret_text+strlen(interpret_text); \
990 #define AppendKeyValue2Text(key,value)\
992 size_t length=strlen(key)+strlen(value)+2; \
993 if ((size_t) (q-interpret_text+length+1) >= extent) \
996 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
997 MaxTextExtent,sizeof(*interpret_text)); \
998 if (interpret_text == (char *) NULL) \
999 return((char *) NULL); \
1000 q=interpret_text+strlen(interpret_text); \
1002 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
1005 #define AppendString2Text(string) \
1007 size_t length=strlen((string)); \
1008 if ((size_t) (q-interpret_text+length+1) >= extent) \
1011 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1012 MaxTextExtent,sizeof(*interpret_text)); \
1013 if (interpret_text == (char *) NULL) \
1014 return((char *) NULL); \
1015 q=interpret_text+strlen(interpret_text); \
1017 (void) CopyMagickString(q,(string),extent); \
1037 assert(image != (
Image *) NULL);
1038 assert(image->signature == MagickCoreSignature);
1039 if (IsEventLogging() != MagickFalse)
1040 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1041 if (embed_text == (
const char *) NULL)
1042 return(ConstantString(
""));
1044 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1047 return(ConstantString(
""));
1051 interpret_text=AcquireString(embed_text);
1052 extent=MaxTextExtent;
1054 for (q=interpret_text; *p!=
'\0';
1055 number=(isdigit((
int) ((
unsigned char) *p))) ? MagickTrue : MagickFalse,p++)
1061 ExtendInterpretText(MaxTextExtent);
1104 if (LocaleNCompare(
"<",p,4) == 0)
1110 if (LocaleNCompare(
">",p,4) == 0)
1116 if (LocaleNCompare(
"&",p,5) == 0)
1137 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1147 if (number != MagickFalse)
1153 property=GetMagickPropertyLetter(image_info,image,*p);
1154 if (property != (
char *) NULL)
1156 AppendString2Text(property);
1157 property=DestroyString(property);
1160 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1161 OptionWarning,
"UnknownImageProperty",
"\"%%%c\"",*p);
1164 return(interpret_text);
1167 MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,
Image *image,
1168 const char *decode,
const char *encode,
ExceptionInfo *exception)
1180 assert(image_info != (
ImageInfo *) NULL);
1181 assert(image_info->signature == MagickCoreSignature);
1182 assert(image != (
Image *) NULL);
1183 assert(image->signature == MagickCoreSignature);
1184 if (IsEventLogging() != MagickFalse)
1185 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1186 delegate_info=GetDelegateInfo(decode,encode,exception);
1189 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1190 "NoTagFound",
"`%s'",decode ? decode : encode);
1191 return((
char *) NULL);
1193 commands=StringToList(delegate_info->commands);
1194 if (commands == (
char **) NULL)
1196 (void) ThrowMagickException(exception,GetMagickModule(),
1197 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1198 decode ? decode : encode);
1199 return((
char *) NULL);
1201 command=InterpretDelegateProperties(image_info,image,commands[0]);
1202 if (command == (
char *) NULL)
1203 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1204 "MemoryAllocationFailed",
"`%s'",commands[0]);
1208 for (i=0; commands[i] != (
char *) NULL; i++)
1209 commands[i]=DestroyString(commands[i]);
1210 commands=(
char **) RelinquishMagickMemory(commands);
1236 MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1238 if (IsEventLogging() != MagickFalse)
1239 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1241 assert(delegate_info->signature == MagickCoreSignature);
1242 return(delegate_info->commands);
1274 MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1281 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1286 LockSemaphoreInfo(delegate_semaphore);
1287 ResetLinkedListIterator(delegate_cache);
1288 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1289 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1291 UnlockSemaphoreInfo(delegate_semaphore);
1298 if (LocaleCompare(p->decode,decode) == 0)
1300 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1305 if (LocaleCompare(p->encode,encode) == 0)
1307 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1310 if (LocaleCompare(decode,p->decode) == 0)
1311 if (LocaleCompare(encode,p->encode) == 0)
1313 if (LocaleCompare(decode,
"*") == 0)
1314 if (LocaleCompare(encode,p->encode) == 0)
1316 if (LocaleCompare(decode,p->decode) == 0)
1317 if (LocaleCompare(encode,
"*") == 0)
1319 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1322 (
void) InsertValueInLinkedList(delegate_cache,0,
1323 RemoveElementByValueFromLinkedList(delegate_cache,p));
1324 UnlockSemaphoreInfo(delegate_semaphore);
1357 #if defined(__cplusplus) || defined(c_plusplus)
1361 static int DelegateInfoCompare(
const void *x,
const void *y)
1372 cmp=LocaleCompare((*p)->path,(*q)->path);
1375 if ((*p)->decode == (
char *) NULL)
1376 if (((*p)->encode != (
char *) NULL) &&
1377 ((*q)->encode != (
char *) NULL))
1378 return(strcmp((*p)->encode,(*q)->encode));
1379 if (((*p)->decode != (
char *) NULL) &&
1380 ((*q)->decode != (
char *) NULL))
1381 return(strcmp((*p)->decode,(*q)->decode));
1386 #if defined(__cplusplus) || defined(c_plusplus)
1390 MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1405 assert(pattern != (
char *) NULL);
1406 assert(number_delegates != (
size_t *) NULL);
1407 if (IsEventLogging() != MagickFalse)
1408 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1409 *number_delegates=0;
1410 p=GetDelegateInfo(
"*",
"*",exception);
1413 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1414 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1420 LockSemaphoreInfo(delegate_semaphore);
1421 ResetLinkedListIterator(delegate_cache);
1422 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1425 if ((p->stealth == MagickFalse) &&
1426 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
1427 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
1429 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1431 UnlockSemaphoreInfo(delegate_semaphore);
1432 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1434 *number_delegates=(size_t) i;
1468 #if defined(__cplusplus) || defined(c_plusplus)
1472 static int DelegateCompare(
const void *x,
const void *y)
1478 p=(
const char **) x;
1479 q=(
const char **) y;
1480 return(LocaleCompare(*p,*q));
1483 #if defined(__cplusplus) || defined(c_plusplus)
1487 MagickExport
char **GetDelegateList(
const char *pattern,
1502 assert(pattern != (
char *) NULL);
1503 assert(number_delegates != (
size_t *) NULL);
1504 if (IsEventLogging() != MagickFalse)
1505 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1506 *number_delegates=0;
1507 p=GetDelegateInfo(
"*",
"*",exception);
1509 return((
char **) NULL);
1510 delegates=(
char **) AcquireQuantumMemory((
size_t)
1511 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1512 if (delegates == (
char **) NULL)
1513 return((
char **) NULL);
1514 LockSemaphoreInfo(delegate_semaphore);
1515 ResetLinkedListIterator(delegate_cache);
1516 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1519 if ((p->stealth == MagickFalse) &&
1520 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
1521 delegates[i++]=ConstantString(p->decode);
1522 if ((p->stealth == MagickFalse) &&
1523 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
1524 delegates[i++]=ConstantString(p->encode);
1525 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1527 UnlockSemaphoreInfo(delegate_semaphore);
1528 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1529 delegates[i]=(
char *) NULL;
1530 *number_delegates=(size_t) i;
1556 MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1558 if (IsEventLogging() != MagickFalse)
1559 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1561 assert(delegate_info->signature == MagickCoreSignature);
1562 return(delegate_info->mode);
1589 MagickExport MagickBooleanType GetDelegateThreadSupport(
1592 if (IsEventLogging() != MagickFalse)
1593 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1595 assert(delegate_info->signature == MagickCoreSignature);
1596 return(delegate_info->thread_support);
1622 static MagickBooleanType IsDelegateCacheInstantiated(
ExceptionInfo *exception)
1627 ActivateSemaphoreInfo(&delegate_semaphore);
1628 LockSemaphoreInfo(delegate_semaphore);
1630 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1631 UnlockSemaphoreInfo(delegate_semaphore);
1633 return(delegate_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1666 static MagickBooleanType CopyDelegateFile(
const char *source,
1667 const char *destination,
const MagickBooleanType overwrite)
1695 assert(source != (
const char *) NULL);
1696 assert(destination != (
char *) NULL);
1697 if (overwrite == MagickFalse)
1699 status=GetPathAttributes(destination,&attributes);
1700 if (status != MagickFalse)
1703 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1704 if (destination_file == -1)
1705 return(MagickFalse);
1706 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1707 if (source_file == -1)
1709 (void) close(destination_file);
1710 return(MagickFalse);
1712 quantum=(size_t) MagickMaxBufferExtent;
1713 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1714 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1715 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1716 if (buffer == (
unsigned char *) NULL)
1718 (void) close(source_file);
1719 (void) close(destination_file);
1720 return(MagickFalse);
1723 for (i=0; ; i+=count)
1725 count=(ssize_t) read(source_file,buffer,quantum);
1728 length=(size_t) count;
1729 count=(ssize_t) write(destination_file,buffer,length);
1730 if ((
size_t) count != length)
1733 (void) close(destination_file);
1734 (void) close(source_file);
1735 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1736 return(i != 0 ? MagickTrue : MagickFalse);
1739 MagickExport MagickBooleanType InvokeDelegate(
ImageInfo *image_info,
1745 input_filename[MaxTextExtent],
1746 output_filename[MaxTextExtent];
1764 assert(image_info != (
ImageInfo *) NULL);
1765 assert(image_info->signature == MagickCoreSignature);
1766 assert(image != (
Image *) NULL);
1767 assert(image->signature == MagickCoreSignature);
1768 if (IsEventLogging() != MagickFalse)
1769 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1770 rights=ExecutePolicyRights;
1771 if ((decode != (
const char *) NULL) &&
1772 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1775 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1776 "NotAuthorized",
"`%s'",decode);
1777 return(MagickFalse);
1779 if ((encode != (
const char *) NULL) &&
1780 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1783 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1784 "NotAuthorized",
"`%s'",encode);
1785 return(MagickFalse);
1787 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1788 if (temporary != MagickFalse)
1789 if (AcquireUniqueFilename(image->filename) == MagickFalse)
1791 ThrowFileException(exception,FileOpenError,
1792 "UnableToCreateTemporaryFile",image->filename);
1793 return(MagickFalse);
1795 delegate_info=GetDelegateInfo(decode,encode,exception);
1798 if (temporary != MagickFalse)
1799 (void) RelinquishUniqueFileResource(image->filename);
1800 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1801 "NoTagFound",
"`%s'",decode ? decode : encode);
1802 return(MagickFalse);
1804 if (*image_info->filename ==
'\0')
1806 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1808 if (temporary != MagickFalse)
1809 (void) RelinquishUniqueFileResource(image->filename);
1810 ThrowFileException(exception,FileOpenError,
1811 "UnableToCreateTemporaryFile",image_info->filename);
1812 return(MagickFalse);
1814 image_info->temporary=MagickTrue;
1816 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1817 (delegate_info->encode != (
char *) NULL)) ||
1818 ((encode != (
const char *) NULL) &&
1819 (delegate_info->decode != (
char *) NULL))))
1833 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1835 ThrowFileException(exception,FileOpenError,
1836 "UnableToCreateTemporaryFile",image_info->unique);
1837 return(MagickFalse);
1839 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1841 (void) RelinquishUniqueFileResource(image_info->unique);
1842 ThrowFileException(exception,FileOpenError,
1843 "UnableToCreateTemporaryFile",image_info->zero);
1844 return(MagickFalse);
1846 magick=InterpretDelegateProperties(image_info,image,
1847 decode != (
char *) NULL ? delegate_info->encode :
1848 delegate_info->decode);
1849 if (magick == (
char *) NULL)
1851 (void) RelinquishUniqueFileResource(image_info->unique);
1852 (void) RelinquishUniqueFileResource(image_info->zero);
1853 if (temporary != MagickFalse)
1854 (void) RelinquishUniqueFileResource(image->filename);
1855 (void) ThrowMagickException(exception,GetMagickModule(),
1856 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1857 return(MagickFalse);
1859 LocaleUpper(magick);
1860 clone_info=CloneImageInfo(image_info);
1861 (void) CopyMagickString((
char *) clone_info->magick,magick,MaxTextExtent);
1862 if (LocaleCompare(magick,
"NULL") != 0)
1863 (
void) CopyMagickString(image->magick,magick,MaxTextExtent);
1864 magick=DestroyString(magick);
1865 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,
"%s:",
1866 delegate_info->decode);
1867 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1869 (void) CopyMagickString(clone_info->filename,image_info->filename,
1871 (void) CopyMagickString(image_info->filename,image->filename,
1873 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1875 (void) FormatLocaleString(p->filename,MaxTextExtent,
"%s:%s",
1876 delegate_info->decode,clone_info->filename);
1877 status=WriteImage(clone_info,p);
1878 if (status == MagickFalse)
1880 (void) RelinquishUniqueFileResource(image_info->unique);
1881 (void) RelinquishUniqueFileResource(image_info->zero);
1882 if (temporary != MagickFalse)
1883 (void) RelinquishUniqueFileResource(image->filename);
1884 clone_info=DestroyImageInfo(clone_info);
1885 (void) ThrowMagickException(exception,GetMagickModule(),
1886 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1887 return(MagickFalse);
1889 if (clone_info->adjoin != MagickFalse)
1892 (void) RelinquishUniqueFileResource(image_info->unique);
1893 (void) RelinquishUniqueFileResource(image_info->zero);
1894 clone_info=DestroyImageInfo(clone_info);
1899 commands=StringToList(delegate_info->commands);
1900 if (commands == (
char **) NULL)
1902 if (temporary != MagickFalse)
1903 (void) RelinquishUniqueFileResource(image->filename);
1904 (void) ThrowMagickException(exception,GetMagickModule(),
1905 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1906 decode ? decode : encode);
1907 return(MagickFalse);
1909 command=(
char *) NULL;
1911 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1912 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1913 for (i=0; commands[i] != (
char *) NULL; i++)
1915 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1916 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1918 ThrowFileException(exception,FileOpenError,
1919 "UnableToCreateTemporaryFile",image_info->unique);
1922 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1924 (void) RelinquishUniqueFileResource(image_info->unique);
1925 ThrowFileException(exception,FileOpenError,
1926 "UnableToCreateTemporaryFile",image_info->zero);
1929 if (LocaleCompare(decode,
"SCAN") != 0)
1931 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1932 if (status == MagickFalse)
1934 ThrowFileException(exception,FileOpenError,
1935 "UnableToCreateTemporaryFile",input_filename);
1940 command=InterpretDelegateProperties(image_info,image,commands[i]);
1941 if (command != (
char *) NULL)
1946 status=ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1947 command,(
char *) NULL,exception) != 0 ? MagickTrue : MagickFalse;
1948 if (delegate_info->spawn != MagickFalse)
1957 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1958 (void) MagickDelay(100);
1960 command=DestroyString(command);
1962 if (LocaleCompare(decode,
"SCAN") != 0)
1964 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1965 (void) RelinquishUniqueFileResource(input_filename);
1967 if ((strcmp(input_filename,output_filename) != 0) &&
1968 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1969 (void) RelinquishUniqueFileResource(output_filename);
1970 if (image_info->temporary != MagickFalse)
1971 (void) RelinquishUniqueFileResource(image_info->filename);
1972 (void) RelinquishUniqueFileResource(image_info->unique);
1973 (void) RelinquishUniqueFileResource(image_info->zero);
1974 (void) RelinquishUniqueFileResource(image_info->filename);
1975 (void) RelinquishUniqueFileResource(image->filename);
1976 if (status != MagickFalse)
1978 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1979 "DelegateFailed",
"`%s'",commands[i]);
1982 commands[i]=DestroyString(commands[i]);
1984 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
1985 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
1989 for ( ; commands[i] != (
char *) NULL; i++)
1990 commands[i]=DestroyString(commands[i]);
1991 commands=(
char **) RelinquishMagickMemory(commands);
1992 if (temporary != MagickFalse)
1993 (void) RelinquishUniqueFileResource(image->filename);
1994 return(status == MagickFalse ? MagickTrue : MagickFalse);
2021 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2029 delegate[MaxTextExtent];
2043 if (file == (
const FILE *) NULL)
2045 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2047 return(MagickFalse);
2048 path=(
const char *) NULL;
2049 for (i=0; i < (ssize_t) number_delegates; i++)
2051 if (delegate_info[i]->stealth != MagickFalse)
2053 if ((path == (
const char *) NULL) ||
2054 (LocaleCompare(path,delegate_info[i]->path) != 0))
2056 if (delegate_info[i]->path != (
char *) NULL)
2057 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2058 (void) FormatLocaleFile(file,
"Delegate Command\n");
2059 (void) FormatLocaleFile(file,
2060 "-------------------------------------------------"
2061 "------------------------------\n");
2063 path=delegate_info[i]->path;
2065 if (delegate_info[i]->encode != (
char *) NULL)
2066 (
void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
2067 (void) ConcatenateMagickString(delegate,
" ",MaxTextExtent);
2069 commands=StringToList(delegate_info[i]->commands);
2070 if (commands == (
char **) NULL)
2072 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2073 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2074 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2075 StripString(commands[0]);
2076 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2077 for (j=1; commands[j] != (
char *) NULL; j++)
2079 StripString(commands[j]);
2080 (void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2082 for (j=0; commands[j] != (
char *) NULL; j++)
2083 commands[j]=DestroyString(commands[j]);
2084 commands=(
char **) RelinquishMagickMemory(commands);
2086 (void) fflush(file);
2088 RelinquishMagickMemory((
void *) delegate_info);
2123 static MagickBooleanType LoadDelegateCache(
LinkedListInfo *cache,
2124 const char *xml,
const char *filename,
const size_t depth,
2128 keyword[MaxTextExtent],
2146 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2147 "Loading delegate configuration file \"%s\" ...",filename);
2148 if (xml == (
const char *) NULL)
2149 return(MagickFalse);
2152 token=AcquireString(xml);
2153 extent=strlen(token)+MaxTextExtent;
2154 for (q=(
const char *) xml; *q !=
'\0'; )
2159 (void) GetNextToken(q,&q,extent,token);
2162 (void) CopyMagickString(keyword,token,MaxTextExtent);
2163 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2168 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2169 (
void) GetNextToken(q,&q,extent,token);
2172 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2177 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2178 (void) GetNextToken(q,&q,extent,token);
2181 if (LocaleCompare(keyword,
"<include") == 0)
2186 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2188 (void) CopyMagickString(keyword,token,MaxTextExtent);
2189 (void) GetNextToken(q,&q,extent,token);
2192 (void) GetNextToken(q,&q,extent,token);
2193 if (LocaleCompare(keyword,
"file") == 0)
2195 if (depth > MagickMaxRecursionDepth)
2196 (void) ThrowMagickException(exception,GetMagickModule(),
2197 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2201 path[MaxTextExtent],
2204 GetPathComponent(filename,HeadPath,path);
2206 (void) ConcatenateMagickString(path,DirectorySeparator,
2208 if (*token == *DirectorySeparator)
2209 (void) CopyMagickString(path,token,MaxTextExtent);
2211 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
2212 xml=FileToXML(path,~0UL);
2213 if (xml != (
char *) NULL)
2215 status&=LoadDelegateCache(cache,xml,path,depth+1,
2217 xml=(
char *) RelinquishMagickMemory(xml);
2224 if (LocaleCompare(keyword,
"<delegate") == 0)
2230 sizeof(*delegate_info));
2232 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
2233 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2234 delegate_info->path=ConstantString(filename);
2235 delegate_info->thread_support=MagickTrue;
2236 delegate_info->signature=MagickCoreSignature;
2241 if ((LocaleCompare(keyword,
"/>") == 0) ||
2242 (LocaleCompare(keyword,
"</policy>") == 0))
2244 status=AppendValueToLinkedList(cache,delegate_info);
2245 if (status == MagickFalse)
2246 (void) ThrowMagickException(exception,GetMagickModule(),
2247 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2248 delegate_info->commands);
2252 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2255 (void) GetNextToken(q,&q,extent,token);
2256 (void) GetNextToken(q,&q,extent,token);
2262 if (LocaleCompare((
char *) keyword,
"command") == 0)
2267 commands=AcquireString(token);
2268 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2269 if (strchr(commands,
'@') != (
char *) NULL)
2272 path[MaxTextExtent];
2274 NTGhostscriptEXE(path,MaxTextExtent);
2275 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2277 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2279 (void) SubstituteString((
char **) &commands,
""",
"\"");
2281 (void) SubstituteString((
char **) &commands,
""",
"'");
2283 (void) SubstituteString((
char **) &commands,
"&",
"&");
2284 (void) SubstituteString((
char **) &commands,
">",
">");
2285 (void) SubstituteString((
char **) &commands,
"<",
"<");
2286 if (delegate_info->commands != (
char *) NULL)
2287 delegate_info->commands=DestroyString(delegate_info->commands);
2288 delegate_info->commands=commands;
2296 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2298 delegate_info->decode=ConstantString(token);
2299 delegate_info->mode=1;
2307 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2309 delegate_info->encode=ConstantString(token);
2310 delegate_info->mode=(-1);
2318 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2320 delegate_info->mode=1;
2321 if (LocaleCompare(token,
"bi") == 0)
2322 delegate_info->mode=0;
2324 if (LocaleCompare(token,
"encode") == 0)
2325 delegate_info->mode=(-1);
2333 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2335 delegate_info->spawn=IsMagickTrue(token);
2338 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2340 delegate_info->stealth=IsMagickTrue(token);
2348 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2350 delegate_info->thread_support=IsMagickTrue(token);
2351 if (delegate_info->thread_support == MagickFalse)
2352 delegate_info->semaphore=AllocateSemaphoreInfo();
2361 token=(
char *) RelinquishMagickMemory(token);
2362 return(status != 0 ? MagickTrue : MagickFalse);