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=\"bpg\" command=\""bpgdec" -b 16 -o "%o.png" "%i"; mv "%o.png" "%o"\"/>"
98 " <delegate decode=\"png\" encode=\"bpg\" command=\""bpgenc" -b 12 -q %~ -o "%o" "%i"\"/>"
99 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" https://imagemagick.org/; rm "%i"\"/>"
100 " <delegate decode=\"cdr\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
101 " <delegate decode=\"cgm\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
102 " <delegate decode=\"https\" command=\""curl" -s -k -L -o "%o" "https:%M"\"/>"
103 " <delegate decode=\"doc\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
104 " <delegate decode=\"docx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
105 " <delegate decode=\"dng:decode\" command=\""ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i"\"/>"
106 " <delegate decode=\"dot\" command=\""dot" -Tsvg "%i" -o "%o"\"/>"
107 " <delegate decode=\"dvi\" command=\""dvips" -sstdout=%%stderr -o "%o" "%i"\"/>"
108 " <delegate decode=\"dxf\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
109 " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>"
110 " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>"
111 " <delegate decode=\"eps\" encode=\"ps\" mode=\"bi\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" "-sOutputFile=%o" "-f%i"\"/>"
112 " <delegate decode=\"fig\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
113 " <delegate decode=\"hpg\" command=\""hp2xx" -sstdout=%%stderr -m eps -f `basename "%o"` "%i"; mv -f `basename "%o"` "%o"\"/>"
114 " <delegate decode=\"hpgl\" command=\""hp2xx" -sstdout=%%stderr -m eps -f `basename "%o"` "%i"; mv -f `basename "%o"` "%o"\"/>"
115 " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>"
116 " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>"
117 " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>"
118 " <delegate decode=\"jpg\" encode=\"lep\" mode=\"encode\" command=\""lepton" "%i" "%o"\"/>"
119 " <delegate decode=\"jxr\" command=\"mv "%i" "%i.jxr"; "JxrDecApp" -i "%i.jxr" -o "%o.pnm"; mv "%i.jxr" "%i"; mv "%o.pnm" "%o"\"/>"
120 " <delegate decode=\"lep\" mode=\"decode\" command=\""lepton" "%i" "%o"\"/>"
121 " <delegate decode=\"odt\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
122 " <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\""pcl6" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pamcmyk32" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
123 " <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"\"/>"
124 " <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"\"/>"
125 " <delegate decode=\"pdf\" encode=\"eps\" mode=\"bi\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 -sPDFPassword="%a" "-sDEVICE=eps2write" "-sOutputFile=%o" "-f%i"\"/>"
126 " <delegate decode=\"pdf\" encode=\"ps\" mode=\"bi\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ps2write" -sPDFPassword="%a" "-sOutputFile=%o" "-f%i"\"/>"
127 " <delegate decode=\"png\" encode=\"webp\" command=\""cwebp" -quiet -q %Q "%i" -o "%o"\"/>"
128 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>"
129 " <delegate decode=\"bmp\" encode=\"jxr\" command=\"mv "%i" "%i.bmp"; "JxrEncApp" -i "%i.bmp" -o "%o.jxr"; mv "%i.bmp" "%i"; mv "%o.jxr" "%o"\"/>"
130 " <delegate decode=\"bmp\" encode=\"wdp\" command=\"mv "%i" "%i.bmp"; "JxrEncApp" -i "%i.bmp" -o "%o.jxr"; mv "%i.bmp" "%i"; mv "%o.jxr" "%o"\"/>"
131 " <delegate decode=\"ppt\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
132 " <delegate decode=\"pptx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
133 " <delegate decode=\"ps\" encode=\"prt\" command=\""lpr" "%i"\"/>"
134 " <delegate decode=\"ps:alpha\" stealth=\"True\" command=\""gs" -sstdout=%%stderr -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"\"/>"
135 " <delegate decode=\"ps:cmyk\" stealth=\"True\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pamcmyk32" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
136 " <delegate decode=\"ps:color\" stealth=\"True\" command=\""gs" -sstdout=%%stderr -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"\"/>"
137 " <delegate decode=\"ps\" encode=\"eps\" mode=\"bi\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=eps2write" "-sOutputFile=%o" "-f%i"\"/>"
138 " <delegate decode=\"ps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>"
139 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>"
140 " <delegate decode=\"ps:mono\" stealth=\"True\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "-f%s" "-f%s"\"/>"
141 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>"
142 " <delegate decode=\"sid\" command=\""mrsidgeodecode" -if sid -i "%i" -of tif -o "%o" > "%u"\"/>"
143 " <delegate decode=\"svg\" command=\""rsvg-convert" -o "%o" "%i"\"/>"
144 " <delegate decode=\"svg:decode\" stealth=\"True\" command=\""inkscape" "%s" --export-png="%s" --export-dpi="%s" --export-background="%s" --export-background-opacity="%s" > "%s" 2>&1\"/>"
145 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>"
146 " <delegate decode=\"wdp\" command=\"mv "%i" "%i.jxr"; "JxrDecApp" -i "%i.jxr" -o "%o.bmp"; mv "%i.jxr" "%i"; mv "%o.bmp" "%o"\"/>"
147 " <delegate decode=\"webp\" command=\""dwebp" -pam "%i" -o "%o"\"/>"
148 " <delegate decode=\"xls\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
149 " <delegate decode=\"xlsx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
150 " <delegate decode=\"xps:cmyk\" stealth=\"True\" command=\""gxps" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=bmpsep8" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
151 " <delegate decode=\"xps:color\" stealth=\"True\" command=\""gxps" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=ppmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
152 " <delegate decode=\"xps:mono\" stealth=\"True\" command=\""gxps" -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 "-sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u "-r%s" %s "-sOutputFile=%s" "%s"\"/>"
153 " <delegate decode=\"video:decode\" command=\""ffmpeg" -nostdin -loglevel error -i "%s" -an -f rawvideo -y %s "%s"\"/>"
154 " <delegate encode=\"video:encode\" stealth=\"True\" command=\""ffmpeg" -nostdin -loglevel error -i "%s%%d.%s" %s "%s.%s"\"/>"
169 static MagickBooleanType
171 LoadDelegateCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
206 cache=NewLinkedList(0);
207 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
215 options=GetConfigureOptions(filename,exception);
216 option=(
const StringInfo *) GetNextValueInLinkedList(options);
219 (void) LoadDelegateCache(cache,(
const char *) GetStringInfoDatum(option),
220 GetStringInfoPath(option),0,exception);
221 option=(
const StringInfo *) GetNextValueInLinkedList(options);
223 options=DestroyConfigureOptions(options);
226 if (IsLinkedListEmpty(cache) != MagickFalse)
227 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
249 MagickExport MagickBooleanType DelegateComponentGenesis(
void)
252 delegate_semaphore=AllocateSemaphoreInfo();
275 static void *DestroyDelegate(
void *delegate_info)
281 if (p->path != (
char *) NULL)
282 p->path=DestroyString(p->path);
283 if (p->decode != (
char *) NULL)
284 p->decode=DestroyString(p->decode);
285 if (p->encode != (
char *) NULL)
286 p->encode=DestroyString(p->encode);
287 if (p->commands != (
char *) NULL)
288 p->commands=DestroyString(p->commands);
290 DestroySemaphoreInfo(&p->semaphore);
292 return((
void *) NULL);
295 MagickExport
void DelegateComponentTerminus(
void)
298 ActivateSemaphoreInfo(&delegate_semaphore);
299 LockSemaphoreInfo(delegate_semaphore);
301 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
302 UnlockSemaphoreInfo(delegate_semaphore);
303 DestroySemaphoreInfo(&delegate_semaphore);
342 MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
343 const MagickBooleanType verbose,
const char *command,
char *message,
364 arguments=StringToArgv(command,&number_arguments);
365 if (arguments == (
char **) NULL)
367 if (*arguments[1] ==
'\0')
369 for (i=0; i < (ssize_t) number_arguments; i++)
370 arguments[i]=DestroyString(arguments[i]);
371 arguments=(
char **) RelinquishMagickMemory(arguments);
374 rights=ExecutePolicyRights;
375 domain=DelegatePolicyDomain;
376 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
379 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
380 "NotAuthorized",
"`%s'",arguments[1]);
381 for (i=0; i < (ssize_t) number_arguments; i++)
382 arguments[i]=DestroyString(arguments[i]);
383 arguments=(
char **) RelinquishMagickMemory(arguments);
386 if (verbose != MagickFalse)
388 (void) FormatLocaleFile(stderr,
"%s\n",command);
389 (void) fflush(stderr);
391 sanitize_command=SanitizeString(command);
392 if (asynchronous != MagickFalse)
393 (void) ConcatenateMagickString(sanitize_command,
"&",MaxTextExtent);
394 if (message != (
char *) NULL)
396 #if defined(MAGICKCORE_POSIX_SUPPORT)
397 #if defined(MAGICKCORE_HAVE_POPEN)
398 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
401 buffer[MagickPathExtent];
410 file=popen_utf8(sanitize_command,
"r");
411 if (file == (FILE *) NULL)
412 status=system(sanitize_command);
415 while (fgets(buffer,(
int)
sizeof(buffer),file) != NULL)
420 length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
423 (void) CopyMagickString(message+offset,buffer,length);
433 #if !defined(MAGICKCORE_HAVE_EXECVP)
434 status=system(sanitize_command);
436 if ((asynchronous != MagickFalse) ||
437 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
438 status=system(sanitize_command);
447 child_pid=(pid_t) fork();
448 if (child_pid == (pid_t) -1)
449 status=system(sanitize_command);
453 status=execvp(arguments[1],arguments+1);
465 pid=(pid_t) waitpid(child_pid,&child_status,0);
470 if (WIFEXITED(child_status) != 0)
471 status=WEXITSTATUS(child_status);
473 if (WIFSIGNALED(child_status))
480 #elif defined(MAGICKCORE_WINDOWS_SUPPORT)
493 p=strstr(sanitize_command,
"cmd.exe /c");
494 if (p != (
char*) NULL)
497 for ( ; *p !=
'\0'; p++)
499 *p=(*DirectorySeparator);
502 status=NTSystemCommand(sanitize_command,message);
504 status=system(sanitize_command);
506 # error No suitable system() method.
510 if ((message != (
char *) NULL) && (*message !=
'\0'))
511 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
512 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
514 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
515 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
517 sanitize_command=DestroyString(sanitize_command);
518 for (i=0; i < (ssize_t) number_arguments; i++)
519 arguments[i]=DestroyString(arguments[i]);
520 arguments=(
char **) RelinquishMagickMemory(arguments);
562 static char *GetMagickPropertyLetter(
const ImageInfo *image_info,
Image *image,
566 value[MaxTextExtent];
571 assert(image != (
Image *) NULL);
572 assert(image->signature == MagickCoreSignature);
573 if (IsEventLogging() != MagickFalse)
574 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
576 string=(
const char *) value;
584 if (image_info->authenticate != (
char *) NULL)
585 string=image_info->authenticate;
593 (void) FormatMagickSize(image->extent,MagickFalse,value);
594 if (image->extent == 0)
595 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,value);
603 GetPathComponent(image->magick_filename,HeadPath,value);
611 GetPathComponent(image->magick_filename,ExtensionPath,value);
619 GetPathComponent(image->magick_filename,TailPath,value);
627 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
628 (
double) image->page.width,(double) image->page.height,
629 (
double) image->page.x,(double) image->page.y);
637 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
638 (image->rows != 0 ? image->rows : image->magick_rows));
646 string=image->filename;
654 string=image->magick;
662 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
663 GetImageListLength(image));
671 string=image_info->filename;
679 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
680 GetImageIndexInList(image));
688 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
689 MAGICKCORE_QUANTUM_DEPTH);
700 colorspace=image->colorspace;
701 if (SetImageGray(image,&image->exception) != MagickFalse)
702 colorspace=GRAYColorspace;
703 (void) FormatLocaleString(value,MaxTextExtent,
"%s %s %s",
704 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
705 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
706 (ssize_t) colorspace),image->matte != MagickFalse ?
"Matte" :
"" );
714 if (image_info->number_scenes != 0)
715 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
718 (
void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
727 GetPathComponent(image->magick_filename,BasePath,value);
735 string=image_info->unique;
743 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
744 (image->columns != 0 ? image->columns : image->magick_columns));
752 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
753 fabs(image->x_resolution) > MagickEpsilon ? image->x_resolution :
754 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
763 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
764 fabs(image->y_resolution) > MagickEpsilon ? image->y_resolution :
765 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
774 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
783 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
784 CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
792 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
793 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
794 image->compression));
802 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
803 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
812 (void) CopyMagickString(value,image->magick_filename,MaxTextExtent);
820 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
821 image->magick_columns,(double) image->magick_rows);
829 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
838 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
847 string=image->magick_filename;
855 (void) FormatLocaleString(value,MaxTextExtent,
"%+ld%+ld",(
long)
856 image->page.x,(long) image->page.y);
864 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
865 image->page.width,(double) image->page.height);
873 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
874 (100-(image->quality == 0 ? 42 : image->quality))/2);
882 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
883 (image->quality == 0 ? 92 : image->quality));
891 if (image_info->number_scenes == 0)
895 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
896 image_info->scene+image_info->number_scenes);
905 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
914 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
915 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
924 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
933 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
942 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
951 string=image_info->zero;
962 page=GetImageBoundingBox(image,&image->exception);
963 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
964 (
double) page.width,(double) page.height,(
double) page.x,(double)
973 (void) SignatureImage(image);
974 string=GetImageProperty(image,
"signature");
986 return(SanitizeDelegateString(
string));
989 static char *InterpretDelegateProperties(
const ImageInfo *image_info,
990 Image *image,
const char *embed_text)
992 #define ExtendInterpretText(string_length) \
994 size_t length=(string_length); \
995 if ((size_t) (q-interpret_text+length+1) >= extent) \
998 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
999 MaxTextExtent,sizeof(*interpret_text)); \
1000 if (interpret_text == (char *) NULL) \
1001 return((char *) NULL); \
1002 q=interpret_text+strlen(interpret_text); \
1006 #define AppendKeyValue2Text(key,value)\
1008 size_t length=strlen(key)+strlen(value)+2; \
1009 if ((size_t) (q-interpret_text+length+1) >= extent) \
1012 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1013 MaxTextExtent,sizeof(*interpret_text)); \
1014 if (interpret_text == (char *) NULL) \
1015 return((char *) NULL); \
1016 q=interpret_text+strlen(interpret_text); \
1018 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
1021 #define AppendString2Text(string) \
1023 size_t length=strlen((string)); \
1024 if ((size_t) (q-interpret_text+length+1) >= extent) \
1027 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1028 MaxTextExtent,sizeof(*interpret_text)); \
1029 if (interpret_text == (char *) NULL) \
1030 return((char *) NULL); \
1031 q=interpret_text+strlen(interpret_text); \
1033 (void) CopyMagickString(q,(string),extent); \
1053 assert(image != (
Image *) NULL);
1054 assert(image->signature == MagickCoreSignature);
1055 if (IsEventLogging() != MagickFalse)
1056 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1057 if (embed_text == (
const char *) NULL)
1058 return(ConstantString(
""));
1060 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1063 return(ConstantString(
""));
1067 interpret_text=AcquireString(embed_text);
1068 extent=MaxTextExtent;
1070 for (q=interpret_text; *p!=
'\0';
1071 number=(isdigit((
int) ((
unsigned char) *p))) ? MagickTrue : MagickFalse,p++)
1077 ExtendInterpretText(MaxTextExtent);
1120 if (LocaleNCompare(
"<",p,4) == 0)
1126 if (LocaleNCompare(
">",p,4) == 0)
1132 if (LocaleNCompare(
"&",p,5) == 0)
1153 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1163 if (number != MagickFalse)
1169 property=GetMagickPropertyLetter(image_info,image,*p);
1170 if (property != (
char *) NULL)
1172 AppendString2Text(property);
1173 property=DestroyString(property);
1176 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1177 OptionWarning,
"UnknownImageProperty",
"\"%%%c\"",*p);
1180 return(interpret_text);
1183 MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,
Image *image,
1184 const char *decode,
const char *encode,
ExceptionInfo *exception)
1196 assert(image_info != (
ImageInfo *) NULL);
1197 assert(image_info->signature == MagickCoreSignature);
1198 assert(image != (
Image *) NULL);
1199 assert(image->signature == MagickCoreSignature);
1200 if (IsEventLogging() != MagickFalse)
1201 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1202 delegate_info=GetDelegateInfo(decode,encode,exception);
1205 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1206 "NoTagFound",
"`%s'",decode ? decode : encode);
1207 return((
char *) NULL);
1209 commands=StringToList(delegate_info->commands);
1210 if (commands == (
char **) NULL)
1212 (void) ThrowMagickException(exception,GetMagickModule(),
1213 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1214 decode ? decode : encode);
1215 return((
char *) NULL);
1217 command=InterpretDelegateProperties(image_info,image,commands[0]);
1218 if (command == (
char *) NULL)
1219 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1220 "MemoryAllocationFailed",
"`%s'",commands[0]);
1224 for (i=0; commands[i] != (
char *) NULL; i++)
1225 commands[i]=DestroyString(commands[i]);
1226 commands=(
char **) RelinquishMagickMemory(commands);
1252 MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1254 if (IsEventLogging() != MagickFalse)
1255 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1257 assert(delegate_info->signature == MagickCoreSignature);
1258 return(delegate_info->commands);
1290 MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1297 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1302 LockSemaphoreInfo(delegate_semaphore);
1303 ResetLinkedListIterator(delegate_cache);
1304 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1305 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1307 UnlockSemaphoreInfo(delegate_semaphore);
1314 if (LocaleCompare(p->decode,decode) == 0)
1316 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1321 if (LocaleCompare(p->encode,encode) == 0)
1323 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1326 if (LocaleCompare(decode,p->decode) == 0)
1327 if (LocaleCompare(encode,p->encode) == 0)
1329 if (LocaleCompare(decode,
"*") == 0)
1330 if (LocaleCompare(encode,p->encode) == 0)
1332 if (LocaleCompare(decode,p->decode) == 0)
1333 if (LocaleCompare(encode,
"*") == 0)
1335 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1338 (
void) InsertValueInLinkedList(delegate_cache,0,
1339 RemoveElementByValueFromLinkedList(delegate_cache,p));
1340 UnlockSemaphoreInfo(delegate_semaphore);
1373 #if defined(__cplusplus) || defined(c_plusplus)
1377 static int DelegateInfoCompare(
const void *x,
const void *y)
1388 cmp=LocaleCompare((*p)->path,(*q)->path);
1391 if ((*p)->decode == (
char *) NULL)
1392 if (((*p)->encode != (
char *) NULL) &&
1393 ((*q)->encode != (
char *) NULL))
1394 return(strcmp((*p)->encode,(*q)->encode));
1395 if (((*p)->decode != (
char *) NULL) &&
1396 ((*q)->decode != (
char *) NULL))
1397 return(strcmp((*p)->decode,(*q)->decode));
1402 #if defined(__cplusplus) || defined(c_plusplus)
1406 MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1421 assert(pattern != (
char *) NULL);
1422 assert(number_delegates != (
size_t *) NULL);
1423 if (IsEventLogging() != MagickFalse)
1424 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1425 *number_delegates=0;
1426 p=GetDelegateInfo(
"*",
"*",exception);
1429 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1430 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1436 LockSemaphoreInfo(delegate_semaphore);
1437 ResetLinkedListIterator(delegate_cache);
1438 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1441 if ((p->stealth == MagickFalse) &&
1442 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
1443 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
1445 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1447 UnlockSemaphoreInfo(delegate_semaphore);
1448 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1450 *number_delegates=(size_t) i;
1484 #if defined(__cplusplus) || defined(c_plusplus)
1488 static int DelegateCompare(
const void *x,
const void *y)
1494 p=(
const char **) x;
1495 q=(
const char **) y;
1496 return(LocaleCompare(*p,*q));
1499 #if defined(__cplusplus) || defined(c_plusplus)
1503 MagickExport
char **GetDelegateList(
const char *pattern,
1518 assert(pattern != (
char *) NULL);
1519 assert(number_delegates != (
size_t *) NULL);
1520 if (IsEventLogging() != MagickFalse)
1521 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1522 *number_delegates=0;
1523 p=GetDelegateInfo(
"*",
"*",exception);
1525 return((
char **) NULL);
1526 delegates=(
char **) AcquireQuantumMemory((
size_t)
1527 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1528 if (delegates == (
char **) NULL)
1529 return((
char **) NULL);
1530 LockSemaphoreInfo(delegate_semaphore);
1531 ResetLinkedListIterator(delegate_cache);
1532 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1535 if ((p->stealth == MagickFalse) &&
1536 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
1537 delegates[i++]=ConstantString(p->decode);
1538 if ((p->stealth == MagickFalse) &&
1539 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
1540 delegates[i++]=ConstantString(p->encode);
1541 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1543 UnlockSemaphoreInfo(delegate_semaphore);
1544 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1545 delegates[i]=(
char *) NULL;
1546 *number_delegates=(size_t) i;
1572 MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1574 if (IsEventLogging() != MagickFalse)
1575 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1577 assert(delegate_info->signature == MagickCoreSignature);
1578 return(delegate_info->mode);
1605 MagickExport MagickBooleanType GetDelegateThreadSupport(
1608 if (IsEventLogging() != MagickFalse)
1609 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1611 assert(delegate_info->signature == MagickCoreSignature);
1612 return(delegate_info->thread_support);
1638 static MagickBooleanType IsDelegateCacheInstantiated(
ExceptionInfo *exception)
1643 ActivateSemaphoreInfo(&delegate_semaphore);
1644 LockSemaphoreInfo(delegate_semaphore);
1646 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1647 UnlockSemaphoreInfo(delegate_semaphore);
1649 return(delegate_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1682 static MagickBooleanType CopyDelegateFile(
const char *source,
1683 const char *destination,
const MagickBooleanType overwrite)
1711 assert(source != (
const char *) NULL);
1712 assert(destination != (
char *) NULL);
1713 if (overwrite == MagickFalse)
1715 status=GetPathAttributes(destination,&attributes);
1716 if (status != MagickFalse)
1719 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1720 if (destination_file == -1)
1721 return(MagickFalse);
1722 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1723 if (source_file == -1)
1725 (void) close(destination_file);
1726 return(MagickFalse);
1728 quantum=(size_t) MagickMaxBufferExtent;
1729 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1730 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1731 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1732 if (buffer == (
unsigned char *) NULL)
1734 (void) close(source_file);
1735 (void) close(destination_file);
1736 return(MagickFalse);
1739 for (i=0; ; i+=count)
1741 count=(ssize_t) read(source_file,buffer,quantum);
1744 length=(size_t) count;
1745 count=(ssize_t) write(destination_file,buffer,length);
1746 if ((
size_t) count != length)
1749 (void) close(destination_file);
1750 (void) close(source_file);
1751 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1752 return(i != 0 ? MagickTrue : MagickFalse);
1755 MagickExport MagickBooleanType InvokeDelegate(
ImageInfo *image_info,
1761 input_filename[MaxTextExtent],
1762 output_filename[MaxTextExtent];
1780 assert(image_info != (
ImageInfo *) NULL);
1781 assert(image_info->signature == MagickCoreSignature);
1782 assert(image != (
Image *) NULL);
1783 assert(image->signature == MagickCoreSignature);
1784 if (IsEventLogging() != MagickFalse)
1785 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1786 rights=ExecutePolicyRights;
1787 if ((decode != (
const char *) NULL) &&
1788 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1791 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1792 "NotAuthorized",
"`%s'",decode);
1793 return(MagickFalse);
1795 if ((encode != (
const char *) NULL) &&
1796 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1799 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1800 "NotAuthorized",
"`%s'",encode);
1801 return(MagickFalse);
1803 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1804 if (temporary != MagickFalse)
1805 if (AcquireUniqueFilename(image->filename) == MagickFalse)
1807 ThrowFileException(exception,FileOpenError,
1808 "UnableToCreateTemporaryFile",image->filename);
1809 return(MagickFalse);
1811 delegate_info=GetDelegateInfo(decode,encode,exception);
1814 if (temporary != MagickFalse)
1815 (void) RelinquishUniqueFileResource(image->filename);
1816 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1817 "NoTagFound",
"`%s'",decode ? decode : encode);
1818 return(MagickFalse);
1820 if (*image_info->filename ==
'\0')
1822 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1824 if (temporary != MagickFalse)
1825 (void) RelinquishUniqueFileResource(image->filename);
1826 ThrowFileException(exception,FileOpenError,
1827 "UnableToCreateTemporaryFile",image_info->filename);
1828 return(MagickFalse);
1830 image_info->temporary=MagickTrue;
1832 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1833 (delegate_info->encode != (
char *) NULL)) ||
1834 ((encode != (
const char *) NULL) &&
1835 (delegate_info->decode != (
char *) NULL))))
1849 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1851 ThrowFileException(exception,FileOpenError,
1852 "UnableToCreateTemporaryFile",image_info->unique);
1853 return(MagickFalse);
1855 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1857 (void) RelinquishUniqueFileResource(image_info->unique);
1858 ThrowFileException(exception,FileOpenError,
1859 "UnableToCreateTemporaryFile",image_info->zero);
1860 return(MagickFalse);
1862 magick=InterpretDelegateProperties(image_info,image,
1863 decode != (
char *) NULL ? delegate_info->encode :
1864 delegate_info->decode);
1865 if (magick == (
char *) NULL)
1867 (void) RelinquishUniqueFileResource(image_info->unique);
1868 (void) RelinquishUniqueFileResource(image_info->zero);
1869 if (temporary != MagickFalse)
1870 (void) RelinquishUniqueFileResource(image->filename);
1871 (void) ThrowMagickException(exception,GetMagickModule(),
1872 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1873 return(MagickFalse);
1875 LocaleUpper(magick);
1876 clone_info=CloneImageInfo(image_info);
1877 (void) CopyMagickString((
char *) clone_info->magick,magick,MaxTextExtent);
1878 if (LocaleCompare(magick,
"NULL") != 0)
1879 (
void) CopyMagickString(image->magick,magick,MaxTextExtent);
1880 magick=DestroyString(magick);
1881 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,
"%s:",
1882 delegate_info->decode);
1883 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1885 (void) CopyMagickString(clone_info->filename,image_info->filename,
1887 (void) CopyMagickString(image_info->filename,image->filename,
1889 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1891 (void) FormatLocaleString(p->filename,MaxTextExtent,
"%s:%s",
1892 delegate_info->decode,clone_info->filename);
1893 status=WriteImage(clone_info,p);
1894 if (status == MagickFalse)
1896 (void) RelinquishUniqueFileResource(image_info->unique);
1897 (void) RelinquishUniqueFileResource(image_info->zero);
1898 if (temporary != MagickFalse)
1899 (void) RelinquishUniqueFileResource(image->filename);
1900 clone_info=DestroyImageInfo(clone_info);
1901 (void) ThrowMagickException(exception,GetMagickModule(),
1902 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1903 return(MagickFalse);
1905 if (clone_info->adjoin != MagickFalse)
1908 (void) RelinquishUniqueFileResource(image_info->unique);
1909 (void) RelinquishUniqueFileResource(image_info->zero);
1910 clone_info=DestroyImageInfo(clone_info);
1915 commands=StringToList(delegate_info->commands);
1916 if (commands == (
char **) NULL)
1918 if (temporary != MagickFalse)
1919 (void) RelinquishUniqueFileResource(image->filename);
1920 (void) ThrowMagickException(exception,GetMagickModule(),
1921 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1922 decode ? decode : encode);
1923 return(MagickFalse);
1925 command=(
char *) NULL;
1927 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1928 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1929 for (i=0; commands[i] != (
char *) NULL; i++)
1931 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1932 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1934 ThrowFileException(exception,FileOpenError,
1935 "UnableToCreateTemporaryFile",image_info->unique);
1938 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1940 (void) RelinquishUniqueFileResource(image_info->unique);
1941 ThrowFileException(exception,FileOpenError,
1942 "UnableToCreateTemporaryFile",image_info->zero);
1945 if (LocaleCompare(decode,
"SCAN") != 0)
1947 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1948 if (status == MagickFalse)
1950 ThrowFileException(exception,FileOpenError,
1951 "UnableToCreateTemporaryFile",input_filename);
1956 command=InterpretDelegateProperties(image_info,image,commands[i]);
1957 if (command != (
char *) NULL)
1962 status=ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1963 command,(
char *) NULL,exception) != 0 ? MagickTrue : MagickFalse;
1964 if (delegate_info->spawn != MagickFalse)
1973 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1974 (void) MagickDelay(100);
1976 command=DestroyString(command);
1978 if (LocaleCompare(decode,
"SCAN") != 0)
1980 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1981 (void) RelinquishUniqueFileResource(input_filename);
1983 if ((strcmp(input_filename,output_filename) != 0) &&
1984 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1985 (void) RelinquishUniqueFileResource(output_filename);
1986 if (image_info->temporary != MagickFalse)
1987 (void) RelinquishUniqueFileResource(image_info->filename);
1988 (void) RelinquishUniqueFileResource(image_info->unique);
1989 (void) RelinquishUniqueFileResource(image_info->zero);
1990 (void) RelinquishUniqueFileResource(image_info->filename);
1991 (void) RelinquishUniqueFileResource(image->filename);
1992 if (status != MagickFalse)
1994 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1995 "DelegateFailed",
"`%s'",commands[i]);
1998 commands[i]=DestroyString(commands[i]);
2000 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
2001 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
2005 for ( ; commands[i] != (
char *) NULL; i++)
2006 commands[i]=DestroyString(commands[i]);
2007 commands=(
char **) RelinquishMagickMemory(commands);
2008 if (temporary != MagickFalse)
2009 (void) RelinquishUniqueFileResource(image->filename);
2010 return(status == MagickFalse ? MagickTrue : MagickFalse);
2037 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2045 delegate[MaxTextExtent];
2059 if (file == (
const FILE *) NULL)
2061 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2063 return(MagickFalse);
2064 path=(
const char *) NULL;
2065 for (i=0; i < (ssize_t) number_delegates; i++)
2067 if (delegate_info[i]->stealth != MagickFalse)
2069 if ((path == (
const char *) NULL) ||
2070 (LocaleCompare(path,delegate_info[i]->path) != 0))
2072 if (delegate_info[i]->path != (
char *) NULL)
2073 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2074 (void) FormatLocaleFile(file,
"Delegate Command\n");
2075 (void) FormatLocaleFile(file,
2076 "-------------------------------------------------"
2077 "------------------------------\n");
2079 path=delegate_info[i]->path;
2081 if (delegate_info[i]->encode != (
char *) NULL)
2082 (
void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
2083 (void) ConcatenateMagickString(delegate,
" ",MaxTextExtent);
2085 commands=StringToList(delegate_info[i]->commands);
2086 if (commands == (
char **) NULL)
2088 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2089 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2090 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2091 StripString(commands[0]);
2092 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2093 for (j=1; commands[j] != (
char *) NULL; j++)
2095 StripString(commands[j]);
2096 (void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2098 for (j=0; commands[j] != (
char *) NULL; j++)
2099 commands[j]=DestroyString(commands[j]);
2100 commands=(
char **) RelinquishMagickMemory(commands);
2102 (void) fflush(file);
2104 RelinquishMagickMemory((
void *) delegate_info);
2139 static MagickBooleanType LoadDelegateCache(
LinkedListInfo *cache,
2140 const char *xml,
const char *filename,
const size_t depth,
2144 keyword[MaxTextExtent],
2162 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2163 "Loading delegate configuration file \"%s\" ...",filename);
2164 if (xml == (
const char *) NULL)
2165 return(MagickFalse);
2168 token=AcquireString(xml);
2169 extent=strlen(token)+MaxTextExtent;
2170 for (q=(
const char *) xml; *q !=
'\0'; )
2175 (void) GetNextToken(q,&q,extent,token);
2178 (void) CopyMagickString(keyword,token,MaxTextExtent);
2179 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2184 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2185 (
void) GetNextToken(q,&q,extent,token);
2188 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2193 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2194 (void) GetNextToken(q,&q,extent,token);
2197 if (LocaleCompare(keyword,
"<include") == 0)
2202 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2204 (void) CopyMagickString(keyword,token,MaxTextExtent);
2205 (void) GetNextToken(q,&q,extent,token);
2208 (void) GetNextToken(q,&q,extent,token);
2209 if (LocaleCompare(keyword,
"file") == 0)
2211 if (depth > MagickMaxRecursionDepth)
2212 (void) ThrowMagickException(exception,GetMagickModule(),
2213 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2217 path[MaxTextExtent],
2220 GetPathComponent(filename,HeadPath,path);
2222 (void) ConcatenateMagickString(path,DirectorySeparator,
2224 if (*token == *DirectorySeparator)
2225 (void) CopyMagickString(path,token,MaxTextExtent);
2227 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
2228 xml=FileToXML(path,~0UL);
2229 if (xml != (
char *) NULL)
2231 status&=LoadDelegateCache(cache,xml,path,depth+1,
2233 xml=(
char *) RelinquishMagickMemory(xml);
2240 if (LocaleCompare(keyword,
"<delegate") == 0)
2246 sizeof(*delegate_info));
2248 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
2249 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2250 delegate_info->path=ConstantString(filename);
2251 delegate_info->thread_support=MagickTrue;
2252 delegate_info->signature=MagickCoreSignature;
2257 if ((LocaleCompare(keyword,
"/>") == 0) ||
2258 (LocaleCompare(keyword,
"</policy>") == 0))
2260 status=AppendValueToLinkedList(cache,delegate_info);
2261 if (status == MagickFalse)
2262 (void) ThrowMagickException(exception,GetMagickModule(),
2263 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2264 delegate_info->commands);
2268 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2271 (void) GetNextToken(q,&q,extent,token);
2272 (void) GetNextToken(q,&q,extent,token);
2278 if (LocaleCompare((
char *) keyword,
"command") == 0)
2283 commands=AcquireString(token);
2284 #if defined(MAGICKCORE_WINDOWS_SUPPORT)
2285 if (strchr(commands,
'@') != (
char *) NULL)
2288 path[MaxTextExtent];
2290 NTGhostscriptEXE(path,MaxTextExtent);
2291 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2293 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2295 (void) SubstituteString((
char **) &commands,
""",
"\"");
2297 (void) SubstituteString((
char **) &commands,
""",
"'");
2299 (void) SubstituteString((
char **) &commands,
"&",
"&");
2300 (void) SubstituteString((
char **) &commands,
">",
">");
2301 (void) SubstituteString((
char **) &commands,
"<",
"<");
2302 if (delegate_info->commands != (
char *) NULL)
2303 delegate_info->commands=DestroyString(delegate_info->commands);
2304 delegate_info->commands=commands;
2312 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2314 delegate_info->decode=ConstantString(token);
2315 delegate_info->mode=1;
2323 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2325 delegate_info->encode=ConstantString(token);
2326 delegate_info->mode=(-1);
2334 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2336 delegate_info->mode=1;
2337 if (LocaleCompare(token,
"bi") == 0)
2338 delegate_info->mode=0;
2340 if (LocaleCompare(token,
"encode") == 0)
2341 delegate_info->mode=(-1);
2349 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2351 delegate_info->spawn=IsMagickTrue(token);
2354 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2356 delegate_info->stealth=IsMagickTrue(token);
2364 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2366 delegate_info->thread_support=IsMagickTrue(token);
2367 if (delegate_info->thread_support == MagickFalse)
2368 delegate_info->semaphore=AllocateSemaphoreInfo();
2377 token=(
char *) RelinquishMagickMemory(token);
2378 return(status != 0 ? MagickTrue : MagickFalse);