48#include "MagickCore/studio.h"
49#include "MagickCore/artifact.h"
50#include "MagickCore/attribute.h"
51#include "MagickCore/blob.h"
52#include "MagickCore/client.h"
53#include "MagickCore/configure.h"
54#include "MagickCore/constitute.h"
55#include "MagickCore/delegate.h"
56#include "MagickCore/delegate-private.h"
57#include "MagickCore/exception.h"
58#include "MagickCore/exception-private.h"
59#include "MagickCore/fx-private.h"
60#include "MagickCore/image-private.h"
61#include "MagickCore/linked-list.h"
62#include "MagickCore/linked-list-private.h"
63#include "MagickCore/list.h"
64#include "MagickCore/memory_.h"
65#include "MagickCore/memory-private.h"
66#include "MagickCore/nt-base-private.h"
67#include "MagickCore/option.h"
68#include "MagickCore/policy.h"
69#include "MagickCore/property.h"
70#include "MagickCore/resource_.h"
71#include "MagickCore/semaphore.h"
72#include "MagickCore/signature.h"
73#include "MagickCore/string_.h"
74#include "MagickCore/token.h"
75#include "MagickCore/token-private.h"
76#include "MagickCore/utility.h"
77#include "MagickCore/utility-private.h"
78#include "MagickCore/xml-tree.h"
79#include "MagickCore/xml-tree-private.h"
85 #include "TargetConditionals.h"
86 #if TARGET_OS_IOS || TARGET_OS_WATCH || TARGET_OS_TV
87 #define system(s) ((s)==NULL ? 0 : -1)
89#elif defined(__ANDROID__)
90 #define system(s) ((s)==NULL ? 0 : -1)
92#define DelegateFilename "delegates.xml"
98 *DelegateMap = (
const char *)
99 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
101 " <delegate decode=\"bpg\" command=\""bpgdec" -b 16 -o "%o.png" "%i"; mv "%o.png" "%o"\"/>"
102 " <delegate decode=\"png\" encode=\"bpg\" command=\""bpgenc" -b 12 -q %~ -o "%o" "%i"\"/>"
103 " <delegate decode=\"browse\" stealth=\"True\" spawn=\"True\" command=\""xdg-open" https://imagemagick.org/; rm "%i"\"/>"
104 " <delegate decode=\"cdr\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
105 " <delegate decode=\"cgm\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
106 " <delegate decode=\"https\" command=\""curl" -s -k -L -o "%o" "https:%M"\"/>"
107 " <delegate decode=\"doc\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
108 " <delegate decode=\"docx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
109 " <delegate decode=\"dng:decode\" command=\""ufraw-batch" --silent --create-id=also --out-type=png --out-depth=16 "--output=%u.png" "%i"\"/>"
110 " <delegate decode=\"dot\" command=\""dot" -Tsvg "%i" -o "%o"\"/>"
111 " <delegate decode=\"dvi\" command=\""dvips" -sstdout=%%stderr -o "%o" "%i"\"/>"
112 " <delegate decode=\"dxf\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
113 " <delegate decode=\"edit\" stealth=\"True\" command=\""xterm" -title "Edit Image Comment" -e vi "%o"\"/>"
114 " <delegate decode=\"eps\" encode=\"pdf\" mode=\"bi\" command=\""gs" -sstdout=%%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 "-sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i"\"/>"
115 " <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"\"/>"
116 " <delegate decode=\"fig\" command=\""uniconvertor" "%i" "%o.svg"; mv "%o.svg" "%o"\"/>"
117 " <delegate decode=\"hpg\" command=\""hp2xx" -sstdout=%%stderr -m eps -f `basename "%o"` "%i"; mv -f `basename "%o"` "%o"\"/>"
118 " <delegate decode=\"hpgl\" command=\""hp2xx" -sstdout=%%stderr -m eps -f `basename "%o"` "%i"; mv -f `basename "%o"` "%o"\"/>"
119 " <delegate decode=\"htm\" command=\""html2ps" -U -o "%o" "%i"\"/>"
120 " <delegate decode=\"html\" command=\""html2ps" -U -o "%o" "%i"\"/>"
121 " <delegate decode=\"ilbm\" command=\""ilbmtoppm" "%i" > "%o"\"/>"
122 " <delegate decode=\"jpg\" encode=\"lep\" mode=\"encode\" command=\""lepton" "%i" "%o"\"/>"
123 " <delegate decode=\"jxr\" command=\"mv "%i" "%i.jxr"; "JxrDecApp" -i "%i.jxr" -o "%o.tiff"; mv "%i.jxr" "%i"; mv "%o.tiff" "%o"\"/>"
124 " <delegate decode=\"lep\" mode=\"decode\" command=\""lepton" "%i" "%o"\"/>"
125 " <delegate decode=\"odt\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
126 " <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"\"/>"
127 " <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"\"/>"
128 " <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"\"/>"
129 " <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"\"/>"
130 " <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"\"/>"
131 " <delegate decode=\"png\" encode=\"clipboard\" command=\""xclip" -selection clipboard -t image/png "%i"\"/>"
132 " <delegate decode=\"clipboard\" command=\""xclip" -selection clipboard -o > "%o"\"/>"
133 " <delegate decode=\"png\" encode=\"webp\" command=\""cwebp" -quiet -q %Q "%i" -o "%o"\"/>"
134 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>"
135 " <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"\"/>"
136 " <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"\"/>"
137 " <delegate decode=\"ppt\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
138 " <delegate decode=\"pptx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
139 " <delegate decode=\"ps\" encode=\"prt\" command=\""lpr" "%i"\"/>"
140 " <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"\"/>"
141 " <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"\"/>"
142 " <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"\"/>"
143 " <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"\"/>"
144 " <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"\"/>"
145 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>"
146 " <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"\"/>"
147 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>"
148 " <delegate decode=\"sid\" command=\""mrsidgeodecode" -if sid -i "%i" -of tif -o "%o" > "%u"\"/>"
149 " <delegate decode=\"svg\" command=\""rsvg-convert" --dpi-x %x --dpi-y %y -o "%o" "%i"\"/>"
150#ifndef MAGICKCORE_RSVG_DELEGATE
151 " <delegate decode=\"svg:decode\" stealth=\"True\" command=\""inkscape" "%s" --export-png="%s" --export-dpi="%s" --export-background="%s" --export-background-opacity="%s"\"/>"
153 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>"
154 " <delegate decode=\"wdp\" command=\"mv "%i" "%i.jxr"; "JxrDecApp" -i "%i.jxr" -o "%o.tiff"; mv "%i.jxr" "%i"; mv "%o.tiff" "%o"\"/>"
155 " <delegate decode=\"webp\" command=\""dwebp" -pam "%i" -o "%o"\"/>"
156 " <delegate decode=\"xls\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
157 " <delegate decode=\"xlsx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>"
158 " <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"\"/>"
159 " <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"\"/>"
160 " <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"\"/>"
161 " <delegate decode=\"video:decode\" command=\""ffmpeg" -nostdin -loglevel error -i "%s" -an -f rawvideo -y %s "%s"\"/>"
162 " <delegate encode=\"video:encode\" stealth=\"True\" command=\""ffmpeg" -nostdin -loglevel error -i "%s%%d.%s" %s "%s.%s"\"/>"
177static MagickBooleanType
179 LoadDelegateCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
214 cache=NewLinkedList(0);
215#if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT
223 options=GetConfigureOptions(filename,exception);
224 option=(
const StringInfo *) GetNextValueInLinkedList(options);
227 (void) LoadDelegateCache(cache,(
const char *)
228 GetStringInfoDatum(option),GetStringInfoPath(option),0,exception);
229 option=(
const StringInfo *) GetNextValueInLinkedList(options);
231 options=DestroyConfigureOptions(options);
234 magick_unreferenced(filename);
236 if (IsLinkedListEmpty(cache) != MagickFalse)
237 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
259MagickPrivate MagickBooleanType DelegateComponentGenesis(
void)
262 delegate_semaphore=AcquireSemaphoreInfo();
285static void *DestroyDelegate(
void *delegate_info)
291 if (p->path != (
char *) NULL)
292 p->path=DestroyString(p->path);
293 if (p->decode != (
char *) NULL)
294 p->decode=DestroyString(p->decode);
295 if (p->encode != (
char *) NULL)
296 p->encode=DestroyString(p->encode);
297 if (p->commands != (
char *) NULL)
298 p->commands=DestroyString(p->commands);
300 RelinquishSemaphoreInfo(&p->semaphore);
302 return((
void *) NULL);
305MagickPrivate
void DelegateComponentTerminus(
void)
308 ActivateSemaphoreInfo(&delegate_semaphore);
309 LockSemaphoreInfo(delegate_semaphore);
311 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
312 UnlockSemaphoreInfo(delegate_semaphore);
313 RelinquishSemaphoreInfo(&delegate_semaphore);
352MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
353 const MagickBooleanType verbose,
const char *command,
char *message,
374 arguments=StringToArgv(command,&number_arguments);
375 if (arguments == (
char **) NULL)
377 if (*arguments[1] ==
'\0')
379 for (i=0; i < (ssize_t) number_arguments; i++)
380 arguments[i]=DestroyString(arguments[i]);
381 arguments=(
char **) RelinquishMagickMemory(arguments);
384 rights=ExecutePolicyRights;
385 domain=DelegatePolicyDomain;
386 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
389 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
390 "NotAuthorized",
"`%s'",arguments[1]);
391 for (i=0; i < (ssize_t) number_arguments; i++)
392 arguments[i]=DestroyString(arguments[i]);
393 arguments=(
char **) RelinquishMagickMemory(arguments);
396 if (verbose != MagickFalse)
398 (void) FormatLocaleFile(stderr,
"%s\n",command);
399 (void) fflush(stderr);
401 sanitize_command=SanitizeString(command);
402 if (asynchronous != MagickFalse)
403 (void) ConcatenateMagickString(sanitize_command,
"&",MagickPathExtent);
404 if (message != (
char *) NULL)
406#if defined(MAGICKCORE_POSIX_SUPPORT)
407#if defined(MAGICKCORE_HAVE_POPEN)
408 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
413 file=popen_utf8(sanitize_command,
"r");
414 if (file == (FILE *) NULL)
415 status=system(sanitize_command);
421 while ((offset < MagickPathExtent) &&
422 (fgets(message+offset,MagickPathExtent-offset,file) != NULL))
423 offset+=strlen(message);
430#if !defined(MAGICKCORE_HAVE_EXECVP)
431 status=system(sanitize_command);
433 if ((asynchronous != MagickFalse) ||
434 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
435 status=system(sanitize_command);
444 child_pid=(pid_t) fork();
445 if (child_pid == (pid_t) -1)
446 status=system(sanitize_command);
450 status=execvp(arguments[1],arguments+1);
462 pid=(pid_t) waitpid(child_pid,&child_status,0);
467 if (WIFEXITED(child_status) != 0)
468 status=WEXITSTATUS(child_status);
470 if (WIFSIGNALED(child_status))
477#elif defined(MAGICKCORE_WINDOWS_SUPPORT)
490 p=strstr(sanitize_command,
"cmd.exe /c");
491 if (p != (
char*) NULL)
494 for ( ; *p !=
'\0'; p++)
496 *p=(*DirectorySeparator);
499 status=NTSystemCommand(sanitize_command,message);
501 status=system(sanitize_command);
503# error No suitable system() method.
507 if ((message != (
char *) NULL) && (*message !=
'\0'))
508 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
509 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
511 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
512 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
514 sanitize_command=DestroyString(sanitize_command);
515 for (i=0; i < (ssize_t) number_arguments; i++)
516 arguments[i]=DestroyString(arguments[i]);
517 arguments=(
char **) RelinquishMagickMemory(arguments);
559static char *GetMagickPropertyLetter(
ImageInfo *image_info,
Image *image,
562#define WarnNoImageReturn(format,letter) \
563 if (image == (Image *) NULL) \
565 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
566 "NoImageForProperty",format,letter); \
569#define WarnNoImageInfoReturn(format,letter) \
570 if (image_info == (ImageInfo *) NULL) \
572 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning, \
573 "NoImageInfoForProperty",format,letter); \
578 value[MagickPathExtent];
583 if ((image != (
Image *) NULL) && (IsEventLogging() != MagickFalse))
584 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
586 if ((image_info != (
ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
587 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-images");
592 string=(
const char *) value;
597 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
598 string=GetImageOption(image_info,
"authenticate");
603 WarnNoImageReturn(
"\"%%%c\"",letter);
604 (void) FormatMagickSize(image->extent,MagickFalse,
"B",MagickPathExtent,
606 if (image->extent == 0)
607 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,
"B",
608 MagickPathExtent,value);
613 WarnNoImageReturn(
"\"%%%c\"",letter);
614 GetPathComponent(image->magick_filename,HeadPath,value);
619 WarnNoImageReturn(
"\"%%%c\"",letter);
620 GetPathComponent(image->magick_filename,ExtensionPath,value);
625 WarnNoImageReturn(
"\"%%%c\"",letter);
626 GetPathComponent(image->magick_filename,TailPath,value);
631 WarnNoImageReturn(
"\"%%%c\"",letter);
632 (void) FormatLocaleString(value,MagickPathExtent,
633 "%.20gx%.20g%+.20g%+.20g",(
double) image->page.width,(
double)
634 image->page.height,(
double) image->page.x,(
double) image->page.y);
639 WarnNoImageReturn(
"\"%%%c\"",letter);
640 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
641 (image->rows != 0 ? image->rows : image->magick_rows));
646 WarnNoImageReturn(
"\"%%%c\"",letter);
647 string=image->filename;
652 WarnNoImageReturn(
"\"%%%c\"",letter);
653 string=image->magick;
658 if (image != (
Image *) NULL)
659 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
660 GetImageListLength(image));
665 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
666 string=image_info->filename;
671 WarnNoImageReturn(
"\"%%%c\"",letter);
672 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
673 GetImageIndexInList(image));
678 WarnNoImageReturn(
"\"%%%c\"",letter);
679 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
680 MAGICKCORE_QUANTUM_DEPTH);
688 WarnNoImageReturn(
"\"%%%c\"",letter);
689 colorspace=image->colorspace;
690 (void) FormatLocaleString(value,MagickPathExtent,
"%s %s %s",
691 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
692 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
693 (ssize_t) colorspace),image->alpha_trait != UndefinedPixelTrait ?
699 WarnNoImageReturn(
"\"%%%c\"",letter);
700 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
706 WarnNoImageReturn(
"\"%%%c\"",letter);
707 GetPathComponent(image->magick_filename,BasePath,value);
712 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
713 string=image_info->unique;
718 WarnNoImageReturn(
"\"%%%c\"",letter);
719 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
720 (image->columns != 0 ? image->columns : image->magick_columns));
725 WarnNoImageReturn(
"\"%%%c\"",letter);
726 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
727 fabs(image->resolution.x) > MagickEpsilon ? image->resolution.x :
728 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
734 WarnNoImageReturn(
"\"%%%c\"",letter);
735 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
736 fabs(image->resolution.y) > MagickEpsilon ? image->resolution.y :
737 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
743 WarnNoImageReturn(
"\"%%%c\"",letter);
744 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
745 (
double) image->depth);
750 WarnNoImageReturn(
"\"%%%c\"",letter);
751 string=CommandOptionToMnemonic(MagickPixelTraitOptions,(ssize_t)
757 WarnNoImageReturn(
"\"%%%c\"",letter);
758 string=CommandOptionToMnemonic(MagickCompressOptions,
759 (ssize_t) image->compression);
764 WarnNoImageReturn(
"\"%%%c\"",letter);
765 string=CommandOptionToMnemonic(MagickDisposeOptions,
766 (ssize_t) image->dispose);
774 WarnNoImageReturn(
"\"%%%c\"",letter);
775 (void) CopyMagickString(value,image->magick_filename,MagickPathExtent);
780 WarnNoImageReturn(
"\"%%%c\"",letter);
781 (void) FormatLocaleString(value,MagickPathExtent,
"%.20gx%.20g",
782 (
double) image->magick_columns,(
double) image->magick_rows);
787 WarnNoImageReturn(
"\"%%%c\"",letter);
788 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",
789 (
double) image->page.height);
794 WarnNoImageReturn(
"\"%%%c\"",letter);
795 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
801 WarnNoImageReturn(
"\"%%%c\"",letter);
802 string=image->magick_filename;
807 WarnNoImageReturn(
"\"%%%c\"",letter);
808 (void) FormatLocaleString(value,MagickPathExtent,
"%+ld%+ld",(
long)
809 image->page.x,(
long) image->page.y);
814 WarnNoImageReturn(
"\"%%%c\"",letter);
815 (void) FormatLocaleString(value,MagickPathExtent,
"%.20gx%.20g",
816 (
double) image->page.width,(
double) image->page.height);
821 WarnNoImageReturn(
"\"%%%c\"",letter);
822 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
823 (100-(image->quality == 0 ? 42 : image->quality))/2);
828 WarnNoImageReturn(
"\"%%%c\"",letter);
829 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
830 (image->quality == 0 ? 92 : image->quality));
835 WarnNoImageInfoReturn(
"\"%%%c\"",letter);
836 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
837 (image_info->number_scenes == 0 ? 2147483647 :
838 image_info->number_scenes));
843 WarnNoImageReturn(
"\"%%%c\"",letter);
844 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
850 WarnNoImageReturn(
"\"%%%c\"",letter);
851 string=CommandOptionToMnemonic(MagickResolutionOptions,
852 (ssize_t) image->units);
857 WarnNoImageReturn(
"\"%%%c\"",letter);
858 (void) FormatLocaleString(value,MagickPathExtent,
"%.20g",(
double)
864 WarnNoImageReturn(
"\"%%%c\"",letter);
865 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
871 WarnNoImageReturn(
"\"%%%c\"",letter);
872 (void) FormatLocaleString(value,MagickPathExtent,
"%+.20g",(
double)
886 WarnNoImageReturn(
"\"%%%c\"",letter);
887 page=GetImageBoundingBox(image,exception);
888 (void) FormatLocaleString(value,MagickPathExtent,
889 "%.20gx%.20g%+.20g%+.20g",(
double) page.width,(
double) page.height,
890 (
double) page.x,(
double) page.y);
898 WarnNoImageReturn(
"\"%%%c\"",letter);
899 (void) SignatureImage(image,exception);
900 string=GetImageProperty(image,
"signature",exception);
904 return(SanitizeDelegateString(
string));
907static char *InterpretDelegateProperties(
ImageInfo *image_info,
910#define ExtendInterpretText(string_length) \
912 size_t length=(string_length); \
913 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
916 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
917 MagickPathExtent,sizeof(*interpret_text)); \
918 if (interpret_text == (char *) NULL) \
919 return((char *) NULL); \
920 q=interpret_text+strlen(interpret_text); \
924#define AppendKeyValue2Text(key,value)\
926 size_t length=strlen(key)+strlen(value)+2; \
927 if ((size_t) (q-interpret_text+length+1) >= extent) \
930 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
931 MagickPathExtent,sizeof(*interpret_text)); \
932 if (interpret_text == (char *) NULL) \
933 return((char *) NULL); \
934 q=interpret_text+strlen(interpret_text); \
936 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \
939#define AppendString2Text(string) \
941 size_t length=strlen((string)); \
942 if ((size_t) (q-interpret_text+(ssize_t) length+1) >= extent) \
945 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \
946 MagickPathExtent,sizeof(*interpret_text)); \
947 if (interpret_text == (char *) NULL) \
948 return((char *) NULL); \
949 q=interpret_text+strlen(interpret_text); \
951 (void) CopyMagickString(q,(string),extent); \
971 assert(image == NULL || image->signature == MagickCoreSignature);
972 assert(image_info == NULL || image_info->signature == MagickCoreSignature);
973 if ((image != (
Image *) NULL) && (IsEventLogging() != MagickFalse))
974 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
976 if ((image_info != (
ImageInfo *) NULL) && (IsEventLogging() != MagickFalse))
977 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",
"no-image");
978 if (embed_text == (
const char *) NULL)
979 return(ConstantString(
""));
981 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
984 return(ConstantString(
""));
988 interpret_text=AcquireString(embed_text);
989 extent=MagickPathExtent;
991 for (q=interpret_text; *p!=
'\0';
992 number=isdigit((
int) ((
unsigned char) *p)) ? MagickTrue : MagickFalse,p++)
998 ExtendInterpretText(MagickPathExtent);
1041 if (LocaleNCompare(
"<",p,4) == 0)
1047 if (LocaleNCompare(
">",p,4) == 0)
1053 if (LocaleNCompare(
"&",p,5) == 0)
1074 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1084 if (number != MagickFalse)
1093 string=GetMagickPropertyLetter(image_info,image,*p,exception);
1094 if (
string != (
char *) NULL)
1096 AppendString2Text(
string);
1097 string=DestroyString(
string);
1100 (void) ThrowMagickException(exception,GetMagickModule(),OptionWarning,
1101 "UnknownImageProperty",
"\"%%%c\"",*p);
1104 return(interpret_text);
1107MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,
Image *image,
1108 const char *decode,
const char *encode,
ExceptionInfo *exception)
1120 assert(image_info != (
ImageInfo *) NULL);
1121 assert(image_info->signature == MagickCoreSignature);
1122 assert(image != (
Image *) NULL);
1123 assert(image->signature == MagickCoreSignature);
1124 if (IsEventLogging() != MagickFalse)
1125 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1126 delegate_info=GetDelegateInfo(decode,encode,exception);
1129 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1130 "NoTagFound",
"`%s'",decode ? decode : encode);
1131 return((
char *) NULL);
1133 commands=StringToList(delegate_info->commands);
1134 if (commands == (
char **) NULL)
1136 (void) ThrowMagickException(exception,GetMagickModule(),
1137 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",decode ? decode :
1139 return((
char *) NULL);
1141 command=InterpretDelegateProperties((
ImageInfo *) image_info,image,
1142 commands[0],exception);
1143 if (command == (
char *) NULL)
1144 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1145 "MemoryAllocationFailed",
"`%s'",commands[0]);
1149 for (i=0; commands[i] != (
char *) NULL; i++)
1150 commands[i]=DestroyString(commands[i]);
1151 commands=(
char **) RelinquishMagickMemory(commands);
1177MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1179 if (IsEventLogging() != MagickFalse)
1180 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1182 assert(delegate_info->signature == MagickCoreSignature);
1183 return(delegate_info->commands);
1215MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1225 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1231 LockSemaphoreInfo(delegate_semaphore);
1232 p=GetHeadElementInLinkedList(delegate_cache);
1233 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1235 UnlockSemaphoreInfo(delegate_semaphore);
1238 return(delegate_info);
1243 if (delegate_info->mode > 0)
1245 if (LocaleCompare(delegate_info->decode,decode) == 0)
1250 if (delegate_info->mode < 0)
1252 if (LocaleCompare(delegate_info->encode,encode) == 0)
1257 if (LocaleCompare(decode,delegate_info->decode) == 0)
1258 if (LocaleCompare(encode,delegate_info->encode) == 0)
1260 if (LocaleCompare(decode,
"*") == 0)
1261 if (LocaleCompare(encode,delegate_info->encode) == 0)
1263 if (LocaleCompare(decode,delegate_info->decode) == 0)
1264 if (LocaleCompare(encode,
"*") == 0)
1271 SetHeadElementInLinkedList(delegate_cache,p);
1272 UnlockSemaphoreInfo(delegate_semaphore);
1273 return(delegate_info);
1305#if defined(__cplusplus) || defined(c_plusplus)
1309static int DelegateInfoCompare(
const void *x,
const void *y)
1320 cmp=LocaleCompare((*p)->path,(*q)->path);
1323 if ((*p)->decode == (
char *) NULL)
1324 if (((*p)->encode != (
char *) NULL) &&
1325 ((*q)->encode != (
char *) NULL))
1326 return(strcmp((*p)->encode,(*q)->encode));
1327 if (((*p)->decode != (
char *) NULL) &&
1328 ((*q)->decode != (
char *) NULL))
1329 return(strcmp((*p)->decode,(*q)->decode));
1334#if defined(__cplusplus) || defined(c_plusplus)
1338MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1350 assert(number_delegates != (
size_t *) NULL);
1351 assert(pattern != (
char *) NULL);
1352 if (IsEventLogging() != MagickFalse)
1353 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1354 *number_delegates=0;
1355 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1357 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1358 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1361 LockSemaphoreInfo(delegate_semaphore);
1362 p=GetHeadElementInLinkedList(delegate_cache);
1369 if( (delegate_info->stealth == MagickFalse) &&
1370 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse ||
1371 GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1372 delegates[i++]=delegate_info;
1375 UnlockSemaphoreInfo(delegate_semaphore);
1377 delegates=(
const DelegateInfo **) RelinquishMagickMemory((
void*) delegates);
1380 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1383 *number_delegates=(size_t) i;
1417#if defined(__cplusplus) || defined(c_plusplus)
1421static int DelegateCompare(
const void *x,
const void *y)
1427 p=(
const char **) x;
1428 q=(
const char **) y;
1429 return(LocaleCompare(*p,*q));
1432#if defined(__cplusplus) || defined(c_plusplus)
1436MagickExport
char **GetDelegateList(
const char *pattern,
1448 assert(pattern != (
char *) NULL);
1449 if (IsEventLogging() != MagickFalse)
1450 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1451 assert(number_delegates != (
size_t *) NULL);
1452 *number_delegates=0;
1453 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1454 return((
char **) NULL);
1455 delegates=(
char **) AcquireQuantumMemory((
size_t)
1456 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1457 if (delegates == (
char **) NULL)
1458 return((
char **) NULL);
1459 LockSemaphoreInfo(delegate_semaphore);
1460 p=GetHeadElementInLinkedList(delegate_cache);
1467 if ((delegate_info->stealth == MagickFalse) &&
1468 (GlobExpression(delegate_info->decode,pattern,MagickFalse) != MagickFalse))
1469 delegates[i++]=ConstantString(delegate_info->decode);
1470 if ((delegate_info->stealth == MagickFalse) &&
1471 (GlobExpression(delegate_info->encode,pattern,MagickFalse) != MagickFalse))
1472 delegates[i++]=ConstantString(delegate_info->encode);
1475 UnlockSemaphoreInfo(delegate_semaphore);
1477 delegates=(
char **) RelinquishMagickMemory(delegates);
1480 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1481 delegates[i]=(
char *) NULL;
1483 *number_delegates=(size_t) i;
1509MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1511 if (IsEventLogging() != MagickFalse)
1512 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1514 assert(delegate_info->signature == MagickCoreSignature);
1515 return(delegate_info->mode);
1542MagickExport MagickBooleanType GetDelegateThreadSupport(
1546 assert(delegate_info->signature == MagickCoreSignature);
1547 if (IsEventLogging() != MagickFalse)
1548 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1549 return(delegate_info->thread_support);
1575static MagickBooleanType IsDelegateCacheInstantiated(
ExceptionInfo *exception)
1580 ActivateSemaphoreInfo(&delegate_semaphore);
1581 LockSemaphoreInfo(delegate_semaphore);
1583 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1584 UnlockSemaphoreInfo(delegate_semaphore);
1586 return(delegate_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1619static MagickBooleanType CopyDelegateFile(
const char *source,
1620 const char *destination,
const MagickBooleanType overwrite)
1646 assert(source != (
const char *) NULL);
1647 assert(destination != (
char *) NULL);
1648 if (overwrite == MagickFalse)
1650 status=GetPathAttributes(destination,&attributes);
1651 if (status != MagickFalse)
1654 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1655 if (destination_file == -1)
1656 return(MagickFalse);
1657 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1658 if (source_file == -1)
1660 (void) close(destination_file);
1661 return(MagickFalse);
1663 quantum=(size_t) MagickMaxBufferExtent;
1664 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1665 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1666 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1667 if (buffer == (
unsigned char *) NULL)
1669 (void) close(source_file);
1670 (void) close(destination_file);
1671 return(MagickFalse);
1674 for (i=0; ; i+=(ssize_t) count)
1676 count=(ssize_t) read(source_file,buffer,quantum);
1679 length=(size_t) count;
1680 count=(ssize_t) write(destination_file,buffer,length);
1681 if ((
size_t) count != length)
1684 (void) close(destination_file);
1685 (void) close(source_file);
1686 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1687 return(i != 0 ? MagickTrue : MagickFalse);
1690MagickExport MagickBooleanType InvokeDelegate(
ImageInfo *image_info,
1696 input_filename[MagickPathExtent],
1697 output_filename[MagickPathExtent];
1715 assert(image_info != (
ImageInfo *) NULL);
1716 assert(image_info->signature == MagickCoreSignature);
1717 assert(image != (
Image *) NULL);
1718 assert(image->signature == MagickCoreSignature);
1719 if (IsEventLogging() != MagickFalse)
1720 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1721 rights=ExecutePolicyRights;
1722 if ((decode != (
const char *) NULL) &&
1723 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1726 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1727 "NotAuthorized",
"`%s'",decode);
1728 return(MagickFalse);
1730 if ((encode != (
const char *) NULL) &&
1731 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1734 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1735 "NotAuthorized",
"`%s'",encode);
1736 return(MagickFalse);
1738 temporary=*image->filename ==
'\0' ? MagickTrue : MagickFalse;
1739 if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
1742 ThrowFileException(exception,FileOpenError,
"UnableToCreateTemporaryFile",
1744 return(MagickFalse);
1746 delegate_info=GetDelegateInfo(decode,encode,exception);
1749 if (temporary != MagickFalse)
1750 (void) RelinquishUniqueFileResource(image->filename);
1751 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1752 "NoTagFound",
"`%s'",decode ? decode : encode);
1753 return(MagickFalse);
1755 if (*image_info->filename ==
'\0')
1757 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1759 if (temporary != MagickFalse)
1760 (void) RelinquishUniqueFileResource(image->filename);
1761 ThrowFileException(exception,FileOpenError,
1762 "UnableToCreateTemporaryFile",image_info->filename);
1763 return(MagickFalse);
1765 image_info->temporary=MagickTrue;
1767 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1768 (delegate_info->encode != (
char *) NULL)) ||
1769 ((encode != (
const char *) NULL) &&
1770 (delegate_info->decode != (
char *) NULL))))
1784 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1786 ThrowFileException(exception,FileOpenError,
1787 "UnableToCreateTemporaryFile",image_info->unique);
1788 return(MagickFalse);
1790 magick=InterpretImageProperties(image_info,image,decode != (
char *) NULL ?
1791 delegate_info->encode : delegate_info->decode,exception);
1792 if (magick == (
char *) NULL)
1794 (void) RelinquishUniqueFileResource(image_info->unique);
1795 if (temporary != MagickFalse)
1796 (void) RelinquishUniqueFileResource(image->filename);
1797 (void) ThrowMagickException(exception,GetMagickModule(),
1798 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1799 return(MagickFalse);
1801 LocaleUpper(magick);
1802 clone_info=CloneImageInfo(image_info);
1803 (void) CopyMagickString((
char *) clone_info->magick,magick,
1805 if (LocaleCompare(magick,
"NULL") != 0)
1806 (void) CopyMagickString(image->magick,magick,MagickPathExtent);
1807 magick=DestroyString(magick);
1808 (void) FormatLocaleString(clone_info->filename,MagickPathExtent,
"%s:",
1809 delegate_info->decode);
1810 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1812 (void) CopyMagickString(clone_info->filename,image_info->filename,
1814 (void) CopyMagickString(image_info->filename,image->filename,
1816 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1818 (void) FormatLocaleString(p->filename,MagickPathExtent,
"%s:%s",
1819 delegate_info->decode,clone_info->filename);
1820 status=WriteImage(clone_info,p,exception);
1821 if (status == MagickFalse)
1823 (void) RelinquishUniqueFileResource(image_info->unique);
1824 if (temporary != MagickFalse)
1825 (void) RelinquishUniqueFileResource(image->filename);
1826 clone_info=DestroyImageInfo(clone_info);
1827 (void) ThrowMagickException(exception,GetMagickModule(),
1828 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1829 return(MagickFalse);
1831 if (clone_info->adjoin != MagickFalse)
1834 (void) RelinquishUniqueFileResource(image_info->unique);
1835 clone_info=DestroyImageInfo(clone_info);
1840 commands=StringToList(delegate_info->commands);
1841 if (commands == (
char **) NULL)
1843 if (temporary != MagickFalse)
1844 (void) RelinquishUniqueFileResource(image->filename);
1845 (void) ThrowMagickException(exception,GetMagickModule(),
1846 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1847 decode ? decode : encode);
1848 return(MagickFalse);
1850 command=(
char *) NULL;
1852 (void) CopyMagickString(output_filename,image_info->filename,
1854 (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
1855 for (i=0; commands[i] != (
char *) NULL; i++)
1857 (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1858 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1860 ThrowFileException(exception,FileOpenError,
1861 "UnableToCreateTemporaryFile",image_info->unique);
1864 if (LocaleCompare(decode,
"SCAN") != 0)
1866 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1867 if (status == MagickFalse)
1869 ThrowFileException(exception,FileOpenError,
1870 "UnableToCreateTemporaryFile",input_filename);
1875 command=InterpretDelegateProperties(image_info,image,commands[i],exception);
1876 if (command != (
char *) NULL)
1881 if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1882 command,(
char *) NULL,exception) != 0)
1884 if (delegate_info->spawn != MagickFalse)
1893 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1894 (void) MagickDelay(100);
1896 command=DestroyString(command);
1898 if (LocaleCompare(decode,
"SCAN") != 0)
1900 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1901 (void) RelinquishUniqueFileResource(input_filename);
1903 if ((strcmp(input_filename,output_filename) != 0) &&
1904 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1905 (void) RelinquishUniqueFileResource(output_filename);
1906 if (image_info->temporary != MagickFalse)
1907 (void) RelinquishUniqueFileResource(image_info->filename);
1908 (void) RelinquishUniqueFileResource(image_info->unique);
1909 (void) RelinquishUniqueFileResource(image_info->filename);
1910 (void) RelinquishUniqueFileResource(image->filename);
1911 if (status == MagickFalse)
1913 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1914 "DelegateFailed",
"`%s'",commands[i]);
1917 commands[i]=DestroyString(commands[i]);
1919 (void) CopyMagickString(image_info->filename,output_filename,
1921 (void) CopyMagickString(image->filename,input_filename,MagickPathExtent);
1925 for ( ; commands[i] != (
char *) NULL; i++)
1926 commands[i]=DestroyString(commands[i]);
1927 commands=(
char **) RelinquishMagickMemory(commands);
1928 if (temporary != MagickFalse)
1929 (void) RelinquishUniqueFileResource(image->filename);
1957MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
1965 delegate[MagickPathExtent];
1979 if (file == (
const FILE *) NULL)
1981 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
1983 return(MagickFalse);
1984 path=(
const char *) NULL;
1985 for (i=0; i < (ssize_t) number_delegates; i++)
1987 if (delegate_info[i]->stealth != MagickFalse)
1989 if ((path == (
const char *) NULL) ||
1990 (LocaleCompare(path,delegate_info[i]->path) != 0))
1992 if (delegate_info[i]->path != (
char *) NULL)
1993 (void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
1994 (void) FormatLocaleFile(file,
"Delegate Command\n");
1995 (void) FormatLocaleFile(file,
1996 "-------------------------------------------------"
1997 "------------------------------\n");
1999 path=delegate_info[i]->path;
2001 if (delegate_info[i]->encode != (
char *) NULL)
2002 (void) CopyMagickString(delegate,delegate_info[i]->encode,
2004 (void) ConcatenateMagickString(delegate,
" ",MagickPathExtent);
2006 commands=StringToList(delegate_info[i]->commands);
2007 if (commands == (
char **) NULL)
2009 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2010 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2011 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2012 (void) StripMagickString(commands[0]);
2013 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2014 for (j=1; commands[j] != (
char *) NULL; j++)
2016 (void) StripMagickString(commands[j]);
2017 (void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2019 for (j=0; commands[j] != (
char *) NULL; j++)
2020 commands[j]=DestroyString(commands[j]);
2021 commands=(
char **) RelinquishMagickMemory(commands);
2023 (void) fflush(file);
2025 RelinquishMagickMemory((
void *) delegate_info);
2061 const char *xml,
const char *filename,
const size_t depth,
2065 keyword[MagickPathExtent],
2083 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2084 "Loading delegate configuration file \"%s\" ...",filename);
2085 if (xml == (
const char *) NULL)
2086 return(MagickFalse);
2089 token=AcquireString(xml);
2090 extent=strlen(token)+MagickPathExtent;
2091 for (q=(
const char *) xml; *q !=
'\0'; )
2096 (void) GetNextToken(q,&q,extent,token);
2099 (void) CopyMagickString(keyword,token,MagickPathExtent);
2100 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2105 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2106 (void) GetNextToken(q,&q,extent,token);
2109 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2114 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2115 (void) GetNextToken(q,&q,extent,token);
2118 if (LocaleCompare(keyword,
"<include") == 0)
2123 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2125 (void) CopyMagickString(keyword,token,MagickPathExtent);
2126 (void) GetNextToken(q,&q,extent,token);
2129 (void) GetNextToken(q,&q,extent,token);
2130 if (LocaleCompare(keyword,
"file") == 0)
2132 if (depth > MagickMaxRecursionDepth)
2133 (void) ThrowMagickException(exception,GetMagickModule(),
2134 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2138 path[MagickPathExtent],
2141 GetPathComponent(filename,HeadPath,path);
2143 (void) ConcatenateMagickString(path,DirectorySeparator,
2145 if (*token == *DirectorySeparator)
2146 (void) CopyMagickString(path,token,MagickPathExtent);
2148 (
void) ConcatenateMagickString(path,token,MagickPathExtent);
2149 file_xml=FileToXML(path,~0UL);
2150 if (file_xml != (
char *) NULL)
2152 status&=(MagickStatusType) LoadDelegateCache(cache,
2153 file_xml,path,depth+1,exception);
2154 file_xml=DestroyString(file_xml);
2161 if (LocaleCompare(keyword,
"<delegate") == 0)
2167 sizeof(*delegate_info));
2168 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2169 delegate_info->path=ConstantString(filename);
2170 delegate_info->thread_support=MagickTrue;
2171 delegate_info->signature=MagickCoreSignature;
2176 if ((LocaleCompare(keyword,
"/>") == 0) ||
2177 (LocaleCompare(keyword,
"</policy>") == 0))
2179 status=AppendValueToLinkedList(cache,delegate_info);
2180 if (status == MagickFalse)
2181 (void) ThrowMagickException(exception,GetMagickModule(),
2182 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2183 delegate_info->commands);
2187 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2190 (void) GetNextToken(q,&q,extent,token);
2191 (void) GetNextToken(q,&q,extent,token);
2197 if (LocaleCompare((
char *) keyword,
"command") == 0)
2202 commands=AcquireString(token);
2203#if defined(MAGICKCORE_WINDOWS_SUPPORT)
2204 if (strchr(commands,
'@') != (
char *) NULL)
2207 path[MagickPathExtent];
2209 NTGhostscriptEXE(path,MagickPathExtent);
2210 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2212 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2214 (void) SubstituteString((
char **) &commands,
""",
"\"");
2216 (void) SubstituteString((
char **) &commands,
""",
"'");
2218 (void) SubstituteString((
char **) &commands,
"&",
"&");
2219 (void) SubstituteString((
char **) &commands,
">",
">");
2220 (void) SubstituteString((
char **) &commands,
"<",
"<");
2221 if (delegate_info->commands != (
char *) NULL)
2222 delegate_info->commands=DestroyString(delegate_info->commands);
2223 delegate_info->commands=commands;
2231 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2233 delegate_info->decode=ConstantString(token);
2234 delegate_info->mode=1;
2242 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2244 delegate_info->encode=ConstantString(token);
2245 delegate_info->mode=(-1);
2253 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2255 delegate_info->mode=1;
2256 if (LocaleCompare(token,
"bi") == 0)
2257 delegate_info->mode=0;
2259 if (LocaleCompare(token,
"encode") == 0)
2260 delegate_info->mode=(-1);
2268 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2270 delegate_info->spawn=IsStringTrue(token);
2273 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2275 delegate_info->stealth=IsStringTrue(token);
2283 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2285 delegate_info->thread_support=IsStringTrue(token);
2286 if (delegate_info->thread_support == MagickFalse)
2287 delegate_info->semaphore=AcquireSemaphoreInfo();
2296 token=(
char *) RelinquishMagickMemory(token);
2297 return(status != 0 ? MagickTrue : MagickFalse);