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"
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.tiff"; mv "%i.jxr" "%i"; mv "%o.tiff" "%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=\"tiff\" encode=\"jxr\" command=\"mv "%i" "%i.tiff"; "JxrEncApp" -i "%i.tiff" -o "%o.jxr"; mv "%i.tiff" "%i"; mv "%o.jxr" "%o"\"/>"
130 " <delegate decode=\"tiff\" encode=\"wdp\" command=\"mv "%i" "%i.tiff"; "JxrEncApp" -i "%i.tiff" -o "%o.jxr"; mv "%i.tiff" "%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#ifndef MAGICKCORE_RSVG_DELEGATE
145 " <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\"/>"
147 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>"
148 " <delegate decode=\"wdp\" command=\"mv "%i" "%i.jxr"; "JxrDecApp" -i "%i.jxr" -o "%o.tiff"; mv "%i.jxr" "%i"; mv "%o.tiff" "%o"\"/>"
149 " <delegate decode=\"webp\" command=\""dwebp" -pam "%i" -o "%o"\"/>"
150 " <delegate decode=\"xls\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
151 " <delegate decode=\"xlsx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
152 " <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"\"/>"
153 " <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"\"/>"
154 " <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"\"/>"
155 " <delegate decode=\"video:decode\" command=\""ffmpeg" -nostdin -loglevel error -i "%s" -an -f rawvideo -y %s "%s"\"/>"
156 " <delegate encode=\"video:encode\" stealth=\"True\" command=\""ffmpeg" -nostdin -loglevel error -i "%s%%d.%s" %s "%s.%s"\"/>"
171static MagickBooleanType
173 LoadDelegateCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
208 cache=NewLinkedList(0);
209#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
217 options=GetConfigureOptions(filename,exception);
218 option=(
const StringInfo *) GetNextValueInLinkedList(options);
221 (void) LoadDelegateCache(cache,(
const char *) GetStringInfoDatum(option),
222 GetStringInfoPath(option),0,exception);
223 option=(
const StringInfo *) GetNextValueInLinkedList(options);
225 options=DestroyConfigureOptions(options);
228 if (IsLinkedListEmpty(cache) != MagickFalse)
229 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
251MagickExport MagickBooleanType DelegateComponentGenesis(
void)
254 delegate_semaphore=AllocateSemaphoreInfo();
277static void *DestroyDelegate(
void *delegate_info)
283 if (p->path != (
char *) NULL)
284 p->path=DestroyString(p->path);
285 if (p->decode != (
char *) NULL)
286 p->decode=DestroyString(p->decode);
287 if (p->encode != (
char *) NULL)
288 p->encode=DestroyString(p->encode);
289 if (p->commands != (
char *) NULL)
290 p->commands=DestroyString(p->commands);
292 DestroySemaphoreInfo(&p->semaphore);
294 return((
void *) NULL);
297MagickExport
void DelegateComponentTerminus(
void)
300 ActivateSemaphoreInfo(&delegate_semaphore);
301 LockSemaphoreInfo(delegate_semaphore);
303 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
304 UnlockSemaphoreInfo(delegate_semaphore);
305 DestroySemaphoreInfo(&delegate_semaphore);
344MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
345 const MagickBooleanType verbose,
const char *command,
char *message,
366 arguments=StringToArgv(command,&number_arguments);
367 if (arguments == (
char **) NULL)
369 if (*arguments[1] ==
'\0')
371 for (i=0; i < (ssize_t) number_arguments; i++)
372 arguments[i]=DestroyString(arguments[i]);
373 arguments=(
char **) RelinquishMagickMemory(arguments);
376 rights=ExecutePolicyRights;
377 domain=DelegatePolicyDomain;
378 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
381 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
382 "NotAuthorized",
"`%s'",arguments[1]);
383 for (i=0; i < (ssize_t) number_arguments; i++)
384 arguments[i]=DestroyString(arguments[i]);
385 arguments=(
char **) RelinquishMagickMemory(arguments);
388 if (verbose != MagickFalse)
390 (void) FormatLocaleFile(stderr,
"%s\n",command);
391 (void) fflush(stderr);
393 sanitize_command=SanitizeString(command);
394 if (asynchronous != MagickFalse)
395 (void) ConcatenateMagickString(sanitize_command,
"&",MaxTextExtent);
396 if (message != (
char *) NULL)
398#if defined(MAGICKCORE_POSIX_SUPPORT)
399#if defined(MAGICKCORE_HAVE_POPEN)
400 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
403 buffer[MagickPathExtent];
412 file=popen_utf8(sanitize_command,
"r");
413 if (file == (FILE *) NULL)
414 status=system(sanitize_command);
417 while (fgets(buffer,(
int)
sizeof(buffer),file) != NULL)
422 length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
425 (void) CopyMagickString(message+offset,buffer,length);
435#if !defined(MAGICKCORE_HAVE_EXECVP)
436 status=system(sanitize_command);
438 if ((asynchronous != MagickFalse) ||
439 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
440 status=system(sanitize_command);
449 child_pid=(pid_t) fork();
450 if (child_pid == (pid_t) -1)
451 status=system(sanitize_command);
455 status=execvp(arguments[1],arguments+1);
467 pid=(pid_t) waitpid(child_pid,&child_status,0);
472 if (WIFEXITED(child_status) != 0)
473 status=WEXITSTATUS(child_status);
475 if (WIFSIGNALED(child_status))
482#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
495 p=strstr(sanitize_command,
"cmd.exe /c");
496 if (p != (
char*) NULL)
499 for ( ; *p !=
'\0'; p++)
501 *p=(*DirectorySeparator);
504 status=NTSystemCommand(sanitize_command,message);
506 status=system(sanitize_command);
508# error No suitable system() method.
512 if ((message != (
char *) NULL) && (*message !=
'\0'))
513 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
514 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
516 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
517 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
519 sanitize_command=DestroyString(sanitize_command);
520 for (i=0; i < (ssize_t) number_arguments; i++)
521 arguments[i]=DestroyString(arguments[i]);
522 arguments=(
char **) RelinquishMagickMemory(arguments);
564static char *GetMagickPropertyLetter(
const ImageInfo *image_info,
Image *image,
568 value[MaxTextExtent];
573 assert(image != (
Image *) NULL);
574 assert(image->signature == MagickCoreSignature);
575 if (IsEventLogging() != MagickFalse)
576 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
578 string=(
const char *) value;
586 if (image_info->authenticate != (
char *) NULL)
587 string=image_info->authenticate;
595 (void) FormatMagickSize(image->extent,MagickFalse,value);
596 if (image->extent == 0)
597 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,value);
605 GetPathComponent(image->magick_filename,HeadPath,value);
613 GetPathComponent(image->magick_filename,ExtensionPath,value);
621 GetPathComponent(image->magick_filename,TailPath,value);
629 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
630 (
double) image->page.width,(double) image->page.height,
631 (
double) image->page.x,(double) image->page.y);
639 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
640 (image->rows != 0 ? image->rows : image->magick_rows));
648 string=image->filename;
656 string=image->magick;
664 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
665 GetImageListLength(image));
673 string=image_info->filename;
681 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
682 GetImageIndexInList(image));
690 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
691 MAGICKCORE_QUANTUM_DEPTH);
702 colorspace=image->colorspace;
703 if (SetImageGray(image,&image->exception) != MagickFalse)
704 colorspace=GRAYColorspace;
705 (void) FormatLocaleString(value,MaxTextExtent,
"%s %s %s",
706 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
707 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
708 (ssize_t) colorspace),image->matte != MagickFalse ?
"Matte" :
"" );
716 if (image_info->number_scenes != 0)
717 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
720 (
void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
729 GetPathComponent(image->magick_filename,BasePath,value);
737 string=image_info->unique;
745 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
746 (image->columns != 0 ? image->columns : image->magick_columns));
754 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
755 fabs(image->x_resolution) > MagickEpsilon ? image->x_resolution :
756 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
765 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
766 fabs(image->y_resolution) > MagickEpsilon ? image->y_resolution :
767 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
776 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
785 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
786 CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
794 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
795 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
796 image->compression));
804 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
805 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
814 (void) CopyMagickString(value,image->magick_filename,MaxTextExtent);
822 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
823 image->magick_columns,(double) image->magick_rows);
831 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
840 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
849 string=image->magick_filename;
857 (void) FormatLocaleString(value,MaxTextExtent,
"%+ld%+ld",(
long)
858 image->page.x,(long) image->page.y);
866 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
867 image->page.width,(double) image->page.height);
875 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
876 (100-(image->quality == 0 ? 42 : image->quality))/2);
884 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
885 (image->quality == 0 ? 92 : image->quality));
893 if (image_info->number_scenes == 0)
897 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
898 image_info->scene+image_info->number_scenes);
907 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
916 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
917 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
926 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
935 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
944 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
953 string=image_info->zero;
964 page=GetImageBoundingBox(image,&image->exception);
965 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
966 (
double) page.width,(double) page.height,(
double) page.x,(double)
975 (void) SignatureImage(image);
976 string=GetImageProperty(image,
"signature");
988 return(SanitizeDelegateString(
string));
991static char *InterpretDelegateProperties(
const ImageInfo *image_info,
992 Image *image,
const char *embed_text)
994#define ExtendInterpretText(string_length) \
996 size_t length=(string_length); \
997 if ((size_t) (q-interpret_text+length+1) >= extent) \
1000 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1001 MaxTextExtent,sizeof(*interpret_text)); \
1002 if (interpret_text == (char *) NULL) \
1003 return((char *) NULL); \
1004 q=interpret_text+strlen(interpret_text); \
1008#define AppendKeyValue2Text(key,value)\
1010 size_t length=strlen(key)+strlen(value)+2; \
1011 if ((size_t) (q-interpret_text+length+1) >= extent) \
1014 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1015 MaxTextExtent,sizeof(*interpret_text)); \
1016 if (interpret_text == (char *) NULL) \
1017 return((char *) NULL); \
1018 q=interpret_text+strlen(interpret_text); \
1020 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
1023#define AppendString2Text(string) \
1025 size_t length=strlen((string)); \
1026 if ((size_t) (q-interpret_text+length+1) >= extent) \
1029 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
1030 MaxTextExtent,sizeof(*interpret_text)); \
1031 if (interpret_text == (char *) NULL) \
1032 return((char *) NULL); \
1033 q=interpret_text+strlen(interpret_text); \
1035 (void) CopyMagickString(q,(string),extent); \
1055 assert(image != (
Image *) NULL);
1056 assert(image->signature == MagickCoreSignature);
1057 if (IsEventLogging() != MagickFalse)
1058 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1059 if (embed_text == (
const char *) NULL)
1060 return(ConstantString(
""));
1062 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1065 return(ConstantString(
""));
1069 interpret_text=AcquireString(embed_text);
1070 extent=MaxTextExtent;
1072 for (q=interpret_text; *p!=
'\0';
1073 number=(isdigit((
int) ((
unsigned char) *p))) ? MagickTrue : MagickFalse,p++)
1079 ExtendInterpretText(MaxTextExtent);
1122 if (LocaleNCompare(
"<",p,4) == 0)
1128 if (LocaleNCompare(
">",p,4) == 0)
1134 if (LocaleNCompare(
"&",p,5) == 0)
1155 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1165 if (number != MagickFalse)
1171 property=GetMagickPropertyLetter(image_info,image,*p);
1172 if (property != (
char *) NULL)
1174 AppendString2Text(property);
1175 property=DestroyString(property);
1178 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1179 OptionWarning,
"UnknownImageProperty",
"\"%%%c\"",*p);
1182 return(interpret_text);
1185MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,
Image *image,
1186 const char *decode,
const char *encode,
ExceptionInfo *exception)
1198 assert(image_info != (
ImageInfo *) NULL);
1199 assert(image_info->signature == MagickCoreSignature);
1200 assert(image != (
Image *) NULL);
1201 assert(image->signature == MagickCoreSignature);
1202 if (IsEventLogging() != MagickFalse)
1203 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1204 delegate_info=GetDelegateInfo(decode,encode,exception);
1207 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1208 "NoTagFound",
"`%s'",decode ? decode : encode);
1209 return((
char *) NULL);
1211 commands=StringToList(delegate_info->commands);
1212 if (commands == (
char **) NULL)
1214 (void) ThrowMagickException(exception,GetMagickModule(),
1215 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1216 decode ? decode : encode);
1217 return((
char *) NULL);
1219 command=InterpretDelegateProperties(image_info,image,commands[0]);
1220 if (command == (
char *) NULL)
1221 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1222 "MemoryAllocationFailed",
"`%s'",commands[0]);
1226 for (i=0; commands[i] != (
char *) NULL; i++)
1227 commands[i]=DestroyString(commands[i]);
1228 commands=(
char **) RelinquishMagickMemory(commands);
1254MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1256 if (IsEventLogging() != MagickFalse)
1257 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1259 assert(delegate_info->signature == MagickCoreSignature);
1260 return(delegate_info->commands);
1292MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1299 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1304 LockSemaphoreInfo(delegate_semaphore);
1305 ResetLinkedListIterator(delegate_cache);
1306 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1307 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1309 UnlockSemaphoreInfo(delegate_semaphore);
1316 if (LocaleCompare(p->decode,decode) == 0)
1318 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1323 if (LocaleCompare(p->encode,encode) == 0)
1325 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1328 if (LocaleCompare(decode,p->decode) == 0)
1329 if (LocaleCompare(encode,p->encode) == 0)
1331 if (LocaleCompare(decode,
"*") == 0)
1332 if (LocaleCompare(encode,p->encode) == 0)
1334 if (LocaleCompare(decode,p->decode) == 0)
1335 if (LocaleCompare(encode,
"*") == 0)
1337 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1340 (
void) InsertValueInLinkedList(delegate_cache,0,
1341 RemoveElementByValueFromLinkedList(delegate_cache,p));
1342 UnlockSemaphoreInfo(delegate_semaphore);
1375#if defined(__cplusplus) || defined(c_plusplus)
1379static int DelegateInfoCompare(
const void *x,
const void *y)
1390 cmp=LocaleCompare((*p)->path,(*q)->path);
1393 if ((*p)->decode == (
char *) NULL)
1394 if (((*p)->encode != (
char *) NULL) &&
1395 ((*q)->encode != (
char *) NULL))
1396 return(strcmp((*p)->encode,(*q)->encode));
1397 if (((*p)->decode != (
char *) NULL) &&
1398 ((*q)->decode != (
char *) NULL))
1399 return(strcmp((*p)->decode,(*q)->decode));
1404#if defined(__cplusplus) || defined(c_plusplus)
1408MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1423 assert(pattern != (
char *) NULL);
1424 assert(number_delegates != (
size_t *) NULL);
1425 if (IsEventLogging() != MagickFalse)
1426 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1427 *number_delegates=0;
1428 p=GetDelegateInfo(
"*",
"*",exception);
1431 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1432 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1438 LockSemaphoreInfo(delegate_semaphore);
1439 ResetLinkedListIterator(delegate_cache);
1440 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1443 if ((p->stealth == MagickFalse) &&
1444 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
1445 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
1447 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1449 UnlockSemaphoreInfo(delegate_semaphore);
1450 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1452 *number_delegates=(size_t) i;
1486#if defined(__cplusplus) || defined(c_plusplus)
1490static int DelegateCompare(
const void *x,
const void *y)
1496 p=(
const char **) x;
1497 q=(
const char **) y;
1498 return(LocaleCompare(*p,*q));
1501#if defined(__cplusplus) || defined(c_plusplus)
1505MagickExport
char **GetDelegateList(
const char *pattern,
1520 assert(pattern != (
char *) NULL);
1521 assert(number_delegates != (
size_t *) NULL);
1522 if (IsEventLogging() != MagickFalse)
1523 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1524 *number_delegates=0;
1525 p=GetDelegateInfo(
"*",
"*",exception);
1527 return((
char **) NULL);
1528 delegates=(
char **) AcquireQuantumMemory((
size_t)
1529 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1530 if (delegates == (
char **) NULL)
1531 return((
char **) NULL);
1532 LockSemaphoreInfo(delegate_semaphore);
1533 ResetLinkedListIterator(delegate_cache);
1534 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1537 if ((p->stealth == MagickFalse) &&
1538 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
1539 delegates[i++]=ConstantString(p->decode);
1540 if ((p->stealth == MagickFalse) &&
1541 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
1542 delegates[i++]=ConstantString(p->encode);
1543 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1545 UnlockSemaphoreInfo(delegate_semaphore);
1546 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1547 delegates[i]=(
char *) NULL;
1548 *number_delegates=(size_t) i;
1574MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1576 if (IsEventLogging() != MagickFalse)
1577 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1579 assert(delegate_info->signature == MagickCoreSignature);
1580 return(delegate_info->mode);
1607MagickExport MagickBooleanType GetDelegateThreadSupport(
1610 if (IsEventLogging() != MagickFalse)
1611 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1613 assert(delegate_info->signature == MagickCoreSignature);
1614 return(delegate_info->thread_support);
1640static MagickBooleanType IsDelegateCacheInstantiated(
ExceptionInfo *exception)
1645 ActivateSemaphoreInfo(&delegate_semaphore);
1646 LockSemaphoreInfo(delegate_semaphore);
1648 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1649 UnlockSemaphoreInfo(delegate_semaphore);
1651 return(delegate_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1684static MagickBooleanType CopyDelegateFile(
const char *source,
1685 const char *destination,
const MagickBooleanType overwrite)
1713 assert(source != (
const char *) NULL);
1714 assert(destination != (
char *) NULL);
1715 if (overwrite == MagickFalse)
1717 status=GetPathAttributes(destination,&attributes);
1718 if (status != MagickFalse)
1721 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1722 if (destination_file == -1)
1723 return(MagickFalse);
1724 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1725 if (source_file == -1)
1727 (void) close(destination_file);
1728 return(MagickFalse);
1730 quantum=(size_t) MagickMaxBufferExtent;
1731 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1732 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1733 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1734 if (buffer == (
unsigned char *) NULL)
1736 (void) close(source_file);
1737 (void) close(destination_file);
1738 return(MagickFalse);
1741 for (i=0; ; i+=count)
1743 count=(ssize_t) read(source_file,buffer,quantum);
1746 length=(size_t) count;
1747 count=(ssize_t) write(destination_file,buffer,length);
1748 if ((
size_t) count != length)
1751 (void) close(destination_file);
1752 (void) close(source_file);
1753 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1754 return(i != 0 ? MagickTrue : MagickFalse);
1757MagickExport MagickBooleanType InvokeDelegate(
ImageInfo *image_info,
1763 input_filename[MaxTextExtent],
1764 output_filename[MaxTextExtent];
1782 assert(image_info != (
ImageInfo *) NULL);
1783 assert(image_info->signature == MagickCoreSignature);
1784 assert(image != (
Image *) NULL);
1785 assert(image->signature == MagickCoreSignature);
1786 if (IsEventLogging() != MagickFalse)
1787 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1788 rights=ExecutePolicyRights;
1789 if ((decode != (
const char *) NULL) &&
1790 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1793 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1794 "NotAuthorized",
"`%s'",decode);
1795 return(MagickFalse);
1797 if ((encode != (
const char *) NULL) &&
1798 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1801 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1802 "NotAuthorized",
"`%s'",encode);
1803 return(MagickFalse);
1805 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1806 if (temporary != MagickFalse)
1807 if (AcquireUniqueFilename(image->filename) == MagickFalse)
1809 ThrowFileException(exception,FileOpenError,
1810 "UnableToCreateTemporaryFile",image->filename);
1811 return(MagickFalse);
1813 delegate_info=GetDelegateInfo(decode,encode,exception);
1816 if (temporary != MagickFalse)
1817 (void) RelinquishUniqueFileResource(image->filename);
1818 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1819 "NoTagFound",
"`%s'",decode ? decode : encode);
1820 return(MagickFalse);
1822 if (*image_info->filename ==
'\0')
1824 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1826 if (temporary != MagickFalse)
1827 (void) RelinquishUniqueFileResource(image->filename);
1828 ThrowFileException(exception,FileOpenError,
1829 "UnableToCreateTemporaryFile",image_info->filename);
1830 return(MagickFalse);
1832 image_info->temporary=MagickTrue;
1834 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1835 (delegate_info->encode != (
char *) NULL)) ||
1836 ((encode != (
const char *) NULL) &&
1837 (delegate_info->decode != (
char *) NULL))))
1851 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1853 ThrowFileException(exception,FileOpenError,
1854 "UnableToCreateTemporaryFile",image_info->unique);
1855 return(MagickFalse);
1857 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1859 (void) RelinquishUniqueFileResource(image_info->unique);
1860 ThrowFileException(exception,FileOpenError,
1861 "UnableToCreateTemporaryFile",image_info->zero);
1862 return(MagickFalse);
1864 magick=InterpretDelegateProperties(image_info,image,
1865 decode != (
char *) NULL ? delegate_info->encode :
1866 delegate_info->decode);
1867 if (magick == (
char *) NULL)
1869 (void) RelinquishUniqueFileResource(image_info->unique);
1870 (void) RelinquishUniqueFileResource(image_info->zero);
1871 if (temporary != MagickFalse)
1872 (void) RelinquishUniqueFileResource(image->filename);
1873 (void) ThrowMagickException(exception,GetMagickModule(),
1874 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1875 return(MagickFalse);
1877 LocaleUpper(magick);
1878 clone_info=CloneImageInfo(image_info);
1879 (void) CopyMagickString((
char *) clone_info->magick,magick,MaxTextExtent);
1880 if (LocaleCompare(magick,
"NULL") != 0)
1881 (
void) CopyMagickString(image->magick,magick,MaxTextExtent);
1882 magick=DestroyString(magick);
1883 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,
"%s:",
1884 delegate_info->decode);
1885 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1887 (void) CopyMagickString(clone_info->filename,image_info->filename,
1889 (void) CopyMagickString(image_info->filename,image->filename,
1891 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1893 (void) FormatLocaleString(p->filename,MaxTextExtent,
"%s:%s",
1894 delegate_info->decode,clone_info->filename);
1895 status=WriteImage(clone_info,p);
1896 if (status == MagickFalse)
1898 (void) RelinquishUniqueFileResource(image_info->unique);
1899 (void) RelinquishUniqueFileResource(image_info->zero);
1900 if (temporary != MagickFalse)
1901 (void) RelinquishUniqueFileResource(image->filename);
1902 clone_info=DestroyImageInfo(clone_info);
1903 (void) ThrowMagickException(exception,GetMagickModule(),
1904 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1905 return(MagickFalse);
1907 if (clone_info->adjoin != MagickFalse)
1910 (void) RelinquishUniqueFileResource(image_info->unique);
1911 (void) RelinquishUniqueFileResource(image_info->zero);
1912 clone_info=DestroyImageInfo(clone_info);
1917 commands=StringToList(delegate_info->commands);
1918 if (commands == (
char **) NULL)
1920 if (temporary != MagickFalse)
1921 (void) RelinquishUniqueFileResource(image->filename);
1922 (void) ThrowMagickException(exception,GetMagickModule(),
1923 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1924 decode ? decode : encode);
1925 return(MagickFalse);
1927 command=(
char *) NULL;
1929 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1930 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1931 for (i=0; commands[i] != (
char *) NULL; i++)
1933 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1934 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1936 ThrowFileException(exception,FileOpenError,
1937 "UnableToCreateTemporaryFile",image_info->unique);
1940 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1942 (void) RelinquishUniqueFileResource(image_info->unique);
1943 ThrowFileException(exception,FileOpenError,
1944 "UnableToCreateTemporaryFile",image_info->zero);
1947 if (LocaleCompare(decode,
"SCAN") != 0)
1949 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1950 if (status == MagickFalse)
1952 ThrowFileException(exception,FileOpenError,
1953 "UnableToCreateTemporaryFile",input_filename);
1958 command=InterpretDelegateProperties(image_info,image,commands[i]);
1959 if (command != (
char *) NULL)
1964 status=ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1965 command,(
char *) NULL,exception) != 0 ? MagickTrue : MagickFalse;
1966 if (delegate_info->spawn != MagickFalse)
1975 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1976 (void) MagickDelay(100);
1978 command=DestroyString(command);
1980 if (LocaleCompare(decode,
"SCAN") != 0)
1982 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1983 (void) RelinquishUniqueFileResource(input_filename);
1985 if ((strcmp(input_filename,output_filename) != 0) &&
1986 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1987 (void) RelinquishUniqueFileResource(output_filename);
1988 if (image_info->temporary != MagickFalse)
1989 (void) RelinquishUniqueFileResource(image_info->filename);
1990 (void) RelinquishUniqueFileResource(image_info->unique);
1991 (void) RelinquishUniqueFileResource(image_info->zero);
1992 (void) RelinquishUniqueFileResource(image_info->filename);
1993 (void) RelinquishUniqueFileResource(image->filename);
1994 if (status != MagickFalse)
1996 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1997 "DelegateFailed",
"`%s'",commands[i]);
2000 commands[i]=DestroyString(commands[i]);
2002 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
2003 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
2007 for ( ; commands[i] != (
char *) NULL; i++)
2008 commands[i]=DestroyString(commands[i]);
2009 commands=(
char **) RelinquishMagickMemory(commands);
2010 if (temporary != MagickFalse)
2011 (void) RelinquishUniqueFileResource(image->filename);
2012 return(status == MagickFalse ? MagickTrue : MagickFalse);
2039MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2047 delegate[MaxTextExtent];
2061 if (file == (
const FILE *) NULL)
2063 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2065 return(MagickFalse);
2066 path=(
const char *) NULL;
2067 for (i=0; i < (ssize_t) number_delegates; i++)
2069 if (delegate_info[i]->stealth != MagickFalse)
2071 if ((path == (
const char *) NULL) ||
2072 (LocaleCompare(path,delegate_info[i]->path) != 0))
2074 if (delegate_info[i]->path != (
char *) NULL)
2075 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2076 (void) FormatLocaleFile(file,
"Delegate Command\n");
2077 (void) FormatLocaleFile(file,
2078 "-------------------------------------------------"
2079 "------------------------------\n");
2081 path=delegate_info[i]->path;
2083 if (delegate_info[i]->encode != (
char *) NULL)
2084 (
void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
2085 (void) ConcatenateMagickString(delegate,
" ",MaxTextExtent);
2087 commands=StringToList(delegate_info[i]->commands);
2088 if (commands == (
char **) NULL)
2090 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2091 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2092 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2093 StripString(commands[0]);
2094 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2095 for (j=1; commands[j] != (
char *) NULL; j++)
2097 StripString(commands[j]);
2098 (void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2100 for (j=0; commands[j] != (
char *) NULL; j++)
2101 commands[j]=DestroyString(commands[j]);
2102 commands=(
char **) RelinquishMagickMemory(commands);
2104 (void) fflush(file);
2106 RelinquishMagickMemory((
void *) delegate_info);
2142 const char *xml,
const char *filename,
const size_t depth,
2146 keyword[MaxTextExtent],
2164 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2165 "Loading delegate configuration file \"%s\" ...",filename);
2166 if (xml == (
const char *) NULL)
2167 return(MagickFalse);
2170 token=AcquireString(xml);
2171 extent=strlen(token)+MaxTextExtent;
2172 for (q=(
const char *) xml; *q !=
'\0'; )
2177 (void) GetNextToken(q,&q,extent,token);
2180 (void) CopyMagickString(keyword,token,MaxTextExtent);
2181 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2186 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2187 (
void) GetNextToken(q,&q,extent,token);
2190 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2195 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2196 (void) GetNextToken(q,&q,extent,token);
2199 if (LocaleCompare(keyword,
"<include") == 0)
2204 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2206 (void) CopyMagickString(keyword,token,MaxTextExtent);
2207 (void) GetNextToken(q,&q,extent,token);
2210 (void) GetNextToken(q,&q,extent,token);
2211 if (LocaleCompare(keyword,
"file") == 0)
2213 if (depth > MagickMaxRecursionDepth)
2214 (void) ThrowMagickException(exception,GetMagickModule(),
2215 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2219 path[MaxTextExtent],
2222 GetPathComponent(filename,HeadPath,path);
2224 (void) ConcatenateMagickString(path,DirectorySeparator,
2226 if (*token == *DirectorySeparator)
2227 (void) CopyMagickString(path,token,MaxTextExtent);
2229 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
2230 xml=FileToXML(path,~0UL);
2231 if (xml != (
char *) NULL)
2233 status&=LoadDelegateCache(cache,xml,path,depth+1,
2235 xml=(
char *) RelinquishMagickMemory(xml);
2242 if (LocaleCompare(keyword,
"<delegate") == 0)
2248 sizeof(*delegate_info));
2250 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
2251 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2252 delegate_info->path=ConstantString(filename);
2253 delegate_info->thread_support=MagickTrue;
2254 delegate_info->signature=MagickCoreSignature;
2259 if ((LocaleCompare(keyword,
"/>") == 0) ||
2260 (LocaleCompare(keyword,
"</policy>") == 0))
2262 status=AppendValueToLinkedList(cache,delegate_info);
2263 if (status == MagickFalse)
2264 (void) ThrowMagickException(exception,GetMagickModule(),
2265 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2266 delegate_info->commands);
2270 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2273 (void) GetNextToken(q,&q,extent,token);
2274 (void) GetNextToken(q,&q,extent,token);
2280 if (LocaleCompare((
char *) keyword,
"command") == 0)
2285 commands=AcquireString(token);
2286#if defined(MAGICKCORE_WINDOWS_SUPPORT)
2287 if (strchr(commands,
'@') != (
char *) NULL)
2290 path[MaxTextExtent];
2292 NTGhostscriptEXE(path,MaxTextExtent);
2293 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2295 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2297 (void) SubstituteString((
char **) &commands,
""",
"\"");
2299 (void) SubstituteString((
char **) &commands,
""",
"'");
2301 (void) SubstituteString((
char **) &commands,
"&",
"&");
2302 (void) SubstituteString((
char **) &commands,
">",
">");
2303 (void) SubstituteString((
char **) &commands,
"<",
"<");
2304 if (delegate_info->commands != (
char *) NULL)
2305 delegate_info->commands=DestroyString(delegate_info->commands);
2306 delegate_info->commands=commands;
2314 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2316 delegate_info->decode=ConstantString(token);
2317 delegate_info->mode=1;
2325 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2327 delegate_info->encode=ConstantString(token);
2328 delegate_info->mode=(-1);
2336 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2338 delegate_info->mode=1;
2339 if (LocaleCompare(token,
"bi") == 0)
2340 delegate_info->mode=0;
2342 if (LocaleCompare(token,
"encode") == 0)
2343 delegate_info->mode=(-1);
2351 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2353 delegate_info->spawn=IsMagickTrue(token);
2356 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2358 delegate_info->stealth=IsMagickTrue(token);
2366 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2368 delegate_info->thread_support=IsMagickTrue(token);
2369 if (delegate_info->thread_support == MagickFalse)
2370 delegate_info->semaphore=AllocateSemaphoreInfo();
2379 token=(
char *) RelinquishMagickMemory(token);
2380 return(status != 0 ? MagickTrue : MagickFalse);