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.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=\"clipboard\" command=\""xclip" -selection clipboard -t image/png "%i"\"/>" 128 " <delegate decode=\"clipboard\" command=\""xclip" -selection clipboard -o > "%o"\"/>" 129 " <delegate decode=\"png\" encode=\"webp\" command=\""cwebp" -quiet -q %Q "%i" -o "%o"\"/>" 130 " <delegate decode=\"pnm\" encode=\"ilbm\" mode=\"encode\" command=\""ppmtoilbm" -24if "%i" > "%o"\"/>" 131 " <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"\"/>" 132 " <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"\"/>" 133 " <delegate decode=\"ppt\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>" 134 " <delegate decode=\"pptx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>" 135 " <delegate decode=\"ps\" encode=\"prt\" command=\""lpr" "%i"\"/>" 136 " <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"\"/>" 137 " <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"\"/>" 138 " <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"\"/>" 139 " <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"\"/>" 140 " <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"\"/>" 141 " <delegate decode=\"ps\" encode=\"print\" mode=\"encode\" command=\"lpr "%i"\"/>" 142 " <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"\"/>" 143 " <delegate decode=\"shtml\" command=\""html2ps" -U -o "%o" "%i"\"/>" 144 " <delegate decode=\"sid\" command=\""mrsidgeodecode" -if sid -i "%i" -of tif -o "%o" > "%u"\"/>" 145 " <delegate decode=\"svg\" command=\""rsvg-convert" -o "%o" "%i"\"/>" 146 #ifndef MAGICKCORE_RSVG_DELEGATE
147 " <delegate decode=\"svg:decode\" stealth=\"True\" command=\""inkscape" "%s" --export-png="%s" --export-dpi="%s" --export-background="%s" --export-background-opacity="%s"\"/>" 149 " <delegate decode=\"tiff\" encode=\"launch\" mode=\"encode\" command=\""gimp" "%i"\"/>" 150 " <delegate decode=\"wdp\" command=\"mv "%i" "%i.jxr"; "JxrDecApp" -i "%i.jxr" -o "%o.tiff"; mv "%i.jxr" "%i"; mv "%o.tiff" "%o"\"/>" 151 " <delegate decode=\"webp\" command=\""dwebp" -pam "%i" -o "%o"\"/>" 152 " <delegate decode=\"xls\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>" 153 " <delegate decode=\"xlsx\" command=\""soffice" --convert-to pdf -outdir `dirname "%i"` "%i" 2> "%u"; mv "%i.pdf" "%o"\"/>" 154 " <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"\"/>" 155 " <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"\"/>" 156 " <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"\"/>" 157 " <delegate decode=\"video:decode\" command=\""ffmpeg" -nostdin -loglevel error -i "%s" -an -f rawvideo -y %s "%s"\"/>" 158 " <delegate encode=\"video:encode\" stealth=\"True\" command=\""ffmpeg" -nostdin -loglevel error -i "%s%%d.%s" %s "%s.%s"\"/>" 173 static MagickBooleanType
175 LoadDelegateCache(
LinkedListInfo *,
const char *,
const char *,
const size_t,
210 cache=NewLinkedList(0);
211 #if !MAGICKCORE_ZERO_CONFIGURATION_SUPPORT 219 options=GetConfigureOptions(filename,exception);
220 option=(
const StringInfo *) GetNextValueInLinkedList(options);
223 (void) LoadDelegateCache(cache,(
const char *) GetStringInfoDatum(option),
224 GetStringInfoPath(option),0,exception);
225 option=(
const StringInfo *) GetNextValueInLinkedList(options);
227 options=DestroyConfigureOptions(options);
230 if (IsLinkedListEmpty(cache) != MagickFalse)
231 (void) LoadDelegateCache(cache,DelegateMap,
"built-in",0,exception);
253 MagickExport MagickBooleanType DelegateComponentGenesis(
void)
256 delegate_semaphore=AllocateSemaphoreInfo();
279 static void *DestroyDelegate(
void *delegate_info)
285 if (p->path != (
char *) NULL)
286 p->path=DestroyString(p->path);
287 if (p->decode != (
char *) NULL)
288 p->decode=DestroyString(p->decode);
289 if (p->encode != (
char *) NULL)
290 p->encode=DestroyString(p->encode);
291 if (p->commands != (
char *) NULL)
292 p->commands=DestroyString(p->commands);
294 DestroySemaphoreInfo(&p->semaphore);
296 return((
void *) NULL);
299 MagickExport
void DelegateComponentTerminus(
void)
302 ActivateSemaphoreInfo(&delegate_semaphore);
303 LockSemaphoreInfo(delegate_semaphore);
305 delegate_cache=DestroyLinkedList(delegate_cache,DestroyDelegate);
306 UnlockSemaphoreInfo(delegate_semaphore);
307 DestroySemaphoreInfo(&delegate_semaphore);
346 MagickExport
int ExternalDelegateCommand(
const MagickBooleanType asynchronous,
347 const MagickBooleanType verbose,
const char *command,
char *message,
368 arguments=StringToArgv(command,&number_arguments);
369 if (arguments == (
char **) NULL)
371 if (*arguments[1] ==
'\0')
373 for (i=0; i < (ssize_t) number_arguments; i++)
374 arguments[i]=DestroyString(arguments[i]);
375 arguments=(
char **) RelinquishMagickMemory(arguments);
378 rights=ExecutePolicyRights;
379 domain=DelegatePolicyDomain;
380 if (IsRightsAuthorized(domain,rights,arguments[1]) == MagickFalse)
383 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
384 "NotAuthorized",
"`%s'",arguments[1]);
385 for (i=0; i < (ssize_t) number_arguments; i++)
386 arguments[i]=DestroyString(arguments[i]);
387 arguments=(
char **) RelinquishMagickMemory(arguments);
390 if (verbose != MagickFalse)
392 (void) FormatLocaleFile(stderr,
"%s\n",command);
393 (void) fflush(stderr);
395 sanitize_command=SanitizeString(command);
396 if (asynchronous != MagickFalse)
397 (void) ConcatenateMagickString(sanitize_command,
"&",MaxTextExtent);
398 if (message != (
char *) NULL)
400 #if defined(MAGICKCORE_POSIX_SUPPORT) 401 #if defined(MAGICKCORE_HAVE_POPEN) 402 if ((asynchronous == MagickFalse) && (message != (
char *) NULL))
405 buffer[MagickPathExtent];
414 file=popen_utf8(sanitize_command,
"r");
415 if (file == (FILE *) NULL)
416 status=system(sanitize_command);
419 while (fgets(buffer,(
int)
sizeof(buffer),file) != NULL)
424 length=MagickMin(MagickPathExtent-offset,strlen(buffer)+1);
427 (void) CopyMagickString(message+offset,buffer,length);
437 #if !defined(MAGICKCORE_HAVE_EXECVP) 438 status=system(sanitize_command);
440 if ((asynchronous != MagickFalse) ||
441 (strpbrk(sanitize_command,
"&;<>|") != (
char *) NULL))
442 status=system(sanitize_command);
451 child_pid=(pid_t) fork();
452 if (child_pid == (pid_t) -1)
453 status=system(sanitize_command);
457 status=execvp(arguments[1],arguments+1);
469 pid=(pid_t) waitpid(child_pid,&child_status,0);
474 if (WIFEXITED(child_status) != 0)
475 status=WEXITSTATUS(child_status);
477 if (WIFSIGNALED(child_status))
484 #elif defined(MAGICKCORE_WINDOWS_SUPPORT) 497 p=strstr(sanitize_command,
"cmd.exe /c");
498 if (p != (
char*) NULL)
501 for ( ; *p !=
'\0'; p++)
503 *p=(*DirectorySeparator);
506 status=NTSystemCommand(sanitize_command,message);
508 status=system(sanitize_command);
510 # error No suitable system() method. 514 if ((message != (
char *) NULL) && (*message !=
'\0'))
515 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
516 "FailedToExecuteCommand",
"`%s' (%s)",sanitize_command,message);
518 (
void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
519 "FailedToExecuteCommand",
"`%s' (%d)",sanitize_command,status);
521 sanitize_command=DestroyString(sanitize_command);
522 for (i=0; i < (ssize_t) number_arguments; i++)
523 arguments[i]=DestroyString(arguments[i]);
524 arguments=(
char **) RelinquishMagickMemory(arguments);
566 static char *GetMagickPropertyLetter(
const ImageInfo *image_info,
Image *image,
570 value[MaxTextExtent];
575 assert(image != (
Image *) NULL);
576 assert(image->signature == MagickCoreSignature);
577 if (IsEventLogging() != MagickFalse)
578 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
580 string=(
const char *) value;
588 if (image_info->authenticate != (
char *) NULL)
589 string=image_info->authenticate;
597 (void) FormatMagickSize(image->extent,MagickFalse,value);
598 if (image->extent == 0)
599 (void) FormatMagickSize(GetBlobSize(image),MagickFalse,value);
607 GetPathComponent(image->magick_filename,HeadPath,value);
615 GetPathComponent(image->magick_filename,ExtensionPath,value);
623 GetPathComponent(image->magick_filename,TailPath,value);
631 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
632 (
double) image->page.width,(double) image->page.height,
633 (
double) image->page.x,(double) image->page.y);
641 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
642 (image->rows != 0 ? image->rows : image->magick_rows));
650 string=image->filename;
658 string=image->magick;
666 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
667 GetImageListLength(image));
675 string=image_info->filename;
683 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
684 GetImageIndexInList(image));
692 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
693 MAGICKCORE_QUANTUM_DEPTH);
704 colorspace=image->colorspace;
705 if (SetImageGray(image,&image->exception) != MagickFalse)
706 colorspace=GRAYColorspace;
707 (void) FormatLocaleString(value,MaxTextExtent,
"%s %s %s",
708 CommandOptionToMnemonic(MagickClassOptions,(ssize_t)
709 image->storage_class),CommandOptionToMnemonic(MagickColorspaceOptions,
710 (ssize_t) colorspace),image->matte != MagickFalse ?
"Matte" :
"" );
718 if (image_info->number_scenes != 0)
719 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
722 (
void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
731 GetPathComponent(image->magick_filename,BasePath,value);
739 string=image_info->unique;
747 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
748 (image->columns != 0 ? image->columns : image->magick_columns));
756 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
757 fabs(image->x_resolution) > MagickEpsilon ? image->x_resolution :
758 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
767 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",
768 fabs(image->y_resolution) > MagickEpsilon ? image->y_resolution :
769 image->units == PixelsPerCentimeterResolution ? DefaultResolution/2.54 :
778 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
787 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
788 CommandOptionToMnemonic(MagickBooleanOptions,(ssize_t) image->matte));
796 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
797 CommandOptionToMnemonic(MagickCompressOptions,(ssize_t)
798 image->compression));
806 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
807 CommandOptionToMnemonic(MagickDisposeOptions,(ssize_t) image->dispose));
816 (void) CopyMagickString(value,image->magick_filename,MaxTextExtent);
824 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
825 image->magick_columns,(double) image->magick_rows);
833 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
842 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
851 string=image->magick_filename;
859 (void) FormatLocaleString(value,MaxTextExtent,
"%+ld%+ld",(
long)
860 image->page.x,(long) image->page.y);
868 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g",(
double)
869 image->page.width,(double) image->page.height);
877 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
878 (100-(image->quality == 0 ? 42 : image->quality))/2);
886 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
887 (image->quality == 0 ? 92 : image->quality));
895 if (image_info->number_scenes == 0)
899 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
900 image_info->scene+image_info->number_scenes);
909 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
918 (void) FormatLocaleString(value,MaxTextExtent,
"%s",
919 CommandOptionToMnemonic(MagickResolutionOptions,(ssize_t)
928 (void) FormatLocaleString(value,MaxTextExtent,
"%.20g",(
double)
937 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
946 (void) FormatLocaleString(value,MaxTextExtent,
"%+.20g",(
double)
955 string=image_info->zero;
966 page=GetImageBoundingBox(image,&image->exception);
967 (void) FormatLocaleString(value,MaxTextExtent,
"%.20gx%.20g%+.20g%+.20g",
968 (
double) page.width,(double) page.height,(
double) page.x,(double)
977 (void) SignatureImage(image);
978 string=GetImageProperty(image,
"signature");
990 return(SanitizeDelegateString(
string));
993 static char *InterpretDelegateProperties(
const ImageInfo *image_info,
994 Image *image,
const char *embed_text)
996 #define ExtendInterpretText(string_length) \ 998 size_t length=(string_length); \ 999 if ((size_t) (q-interpret_text+length+1) >= extent) \ 1002 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \ 1003 MaxTextExtent,sizeof(*interpret_text)); \ 1004 if (interpret_text == (char *) NULL) \ 1005 return((char *) NULL); \ 1006 q=interpret_text+strlen(interpret_text); \ 1010 #define AppendKeyValue2Text(key,value)\ 1012 size_t length=strlen(key)+strlen(value)+2; \ 1013 if ((size_t) (q-interpret_text+length+1) >= extent) \ 1016 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \ 1017 MaxTextExtent,sizeof(*interpret_text)); \ 1018 if (interpret_text == (char *) NULL) \ 1019 return((char *) NULL); \ 1020 q=interpret_text+strlen(interpret_text); \ 1022 q+=FormatLocaleString(q,extent,"%s=%s\n",(key),(value)); \ 1025 #define AppendString2Text(string) \ 1027 size_t length=strlen((string)); \ 1028 if ((size_t) (q-interpret_text+length+1) >= extent) \ 1031 interpret_text=(char *) ResizeQuantumMemory(interpret_text,extent+ \ 1032 MaxTextExtent,sizeof(*interpret_text)); \ 1033 if (interpret_text == (char *) NULL) \ 1034 return((char *) NULL); \ 1035 q=interpret_text+strlen(interpret_text); \ 1037 (void) CopyMagickString(q,(string),extent); \ 1057 assert(image != (
Image *) NULL);
1058 assert(image->signature == MagickCoreSignature);
1059 if (IsEventLogging() != MagickFalse)
1060 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1061 if (embed_text == (
const char *) NULL)
1062 return(ConstantString(
""));
1064 while ((isspace((
int) ((
unsigned char) *p)) != 0) && (*p !=
'\0'))
1067 return(ConstantString(
""));
1071 interpret_text=AcquireString(embed_text);
1072 extent=MaxTextExtent;
1074 for (q=interpret_text; *p!=
'\0';
1075 number=(isdigit((
int) ((
unsigned char) *p))) ? MagickTrue : MagickFalse,p++)
1081 ExtendInterpretText(MaxTextExtent);
1124 if (LocaleNCompare(
"<",p,4) == 0)
1130 if (LocaleNCompare(
">",p,4) == 0)
1136 if (LocaleNCompare(
"&",p,5) == 0)
1157 if ((*p ==
'\0') || (*p ==
'\'') || (*p ==
'"'))
1167 if (number != MagickFalse)
1173 property=GetMagickPropertyLetter(image_info,image,*p);
1174 if (property != (
char *) NULL)
1176 AppendString2Text(property);
1177 property=DestroyString(property);
1180 (void) ThrowMagickException(&image->exception,GetMagickModule(),
1181 OptionWarning,
"UnknownImageProperty",
"\"%%%c\"",*p);
1184 return(interpret_text);
1187 MagickExport
char *GetDelegateCommand(
const ImageInfo *image_info,
Image *image,
1188 const char *decode,
const char *encode,
ExceptionInfo *exception)
1200 assert(image_info != (
ImageInfo *) NULL);
1201 assert(image_info->signature == MagickCoreSignature);
1202 assert(image != (
Image *) NULL);
1203 assert(image->signature == MagickCoreSignature);
1204 if (IsEventLogging() != MagickFalse)
1205 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1206 delegate_info=GetDelegateInfo(decode,encode,exception);
1209 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1210 "NoTagFound",
"`%s'",decode ? decode : encode);
1211 return((
char *) NULL);
1213 commands=StringToList(delegate_info->commands);
1214 if (commands == (
char **) NULL)
1216 (void) ThrowMagickException(exception,GetMagickModule(),
1217 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1218 decode ? decode : encode);
1219 return((
char *) NULL);
1221 command=InterpretDelegateProperties(image_info,image,commands[0]);
1222 if (command == (
char *) NULL)
1223 (void) ThrowMagickException(exception,GetMagickModule(),ResourceLimitError,
1224 "MemoryAllocationFailed",
"`%s'",commands[0]);
1228 for (i=0; commands[i] != (
char *) NULL; i++)
1229 commands[i]=DestroyString(commands[i]);
1230 commands=(
char **) RelinquishMagickMemory(commands);
1256 MagickExport
const char *GetDelegateCommands(
const DelegateInfo *delegate_info)
1258 if (IsEventLogging() != MagickFalse)
1259 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1261 assert(delegate_info->signature == MagickCoreSignature);
1262 return(delegate_info->commands);
1294 MagickExport
const DelegateInfo *GetDelegateInfo(
const char *decode,
1301 if (IsDelegateCacheInstantiated(exception) == MagickFalse)
1306 LockSemaphoreInfo(delegate_semaphore);
1307 ResetLinkedListIterator(delegate_cache);
1308 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1309 if ((LocaleCompare(decode,
"*") == 0) && (LocaleCompare(encode,
"*") == 0))
1311 UnlockSemaphoreInfo(delegate_semaphore);
1318 if (LocaleCompare(p->decode,decode) == 0)
1320 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1325 if (LocaleCompare(p->encode,encode) == 0)
1327 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1330 if (LocaleCompare(decode,p->decode) == 0)
1331 if (LocaleCompare(encode,p->encode) == 0)
1333 if (LocaleCompare(decode,
"*") == 0)
1334 if (LocaleCompare(encode,p->encode) == 0)
1336 if (LocaleCompare(decode,p->decode) == 0)
1337 if (LocaleCompare(encode,
"*") == 0)
1339 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1342 (
void) InsertValueInLinkedList(delegate_cache,0,
1343 RemoveElementByValueFromLinkedList(delegate_cache,p));
1344 UnlockSemaphoreInfo(delegate_semaphore);
1377 #if defined(__cplusplus) || defined(c_plusplus) 1381 static int DelegateInfoCompare(
const void *x,
const void *y)
1392 cmp=LocaleCompare((*p)->path,(*q)->path);
1395 if ((*p)->decode == (
char *) NULL)
1396 if (((*p)->encode != (
char *) NULL) &&
1397 ((*q)->encode != (
char *) NULL))
1398 return(strcmp((*p)->encode,(*q)->encode));
1399 if (((*p)->decode != (
char *) NULL) &&
1400 ((*q)->decode != (
char *) NULL))
1401 return(strcmp((*p)->decode,(*q)->decode));
1406 #if defined(__cplusplus) || defined(c_plusplus) 1410 MagickExport
const DelegateInfo **GetDelegateInfoList(
const char *pattern,
1425 assert(pattern != (
char *) NULL);
1426 assert(number_delegates != (
size_t *) NULL);
1427 if (IsEventLogging() != MagickFalse)
1428 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1429 *number_delegates=0;
1430 p=GetDelegateInfo(
"*",
"*",exception);
1433 delegates=(
const DelegateInfo **) AcquireQuantumMemory((
size_t)
1434 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1440 LockSemaphoreInfo(delegate_semaphore);
1441 ResetLinkedListIterator(delegate_cache);
1442 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1445 if ((p->stealth == MagickFalse) &&
1446 ((GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse) ||
1447 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse)))
1449 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1451 UnlockSemaphoreInfo(delegate_semaphore);
1452 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateInfoCompare);
1454 *number_delegates=(size_t) i;
1488 #if defined(__cplusplus) || defined(c_plusplus) 1492 static int DelegateCompare(
const void *x,
const void *y)
1498 p=(
const char **) x;
1499 q=(
const char **) y;
1500 return(LocaleCompare(*p,*q));
1503 #if defined(__cplusplus) || defined(c_plusplus) 1507 MagickExport
char **GetDelegateList(
const char *pattern,
1522 assert(pattern != (
char *) NULL);
1523 assert(number_delegates != (
size_t *) NULL);
1524 if (IsEventLogging() != MagickFalse)
1525 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",pattern);
1526 *number_delegates=0;
1527 p=GetDelegateInfo(
"*",
"*",exception);
1529 return((
char **) NULL);
1530 delegates=(
char **) AcquireQuantumMemory((
size_t)
1531 GetNumberOfElementsInLinkedList(delegate_cache)+1UL,
sizeof(*delegates));
1532 if (delegates == (
char **) NULL)
1533 return((
char **) NULL);
1534 LockSemaphoreInfo(delegate_semaphore);
1535 ResetLinkedListIterator(delegate_cache);
1536 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1539 if ((p->stealth == MagickFalse) &&
1540 (GlobExpression(p->decode,pattern,MagickFalse) != MagickFalse))
1541 delegates[i++]=ConstantString(p->decode);
1542 if ((p->stealth == MagickFalse) &&
1543 (GlobExpression(p->encode,pattern,MagickFalse) != MagickFalse))
1544 delegates[i++]=ConstantString(p->encode);
1545 p=(
const DelegateInfo *) GetNextValueInLinkedList(delegate_cache);
1547 UnlockSemaphoreInfo(delegate_semaphore);
1548 qsort((
void *) delegates,(
size_t) i,
sizeof(*delegates),DelegateCompare);
1549 delegates[i]=(
char *) NULL;
1550 *number_delegates=(size_t) i;
1576 MagickExport ssize_t GetDelegateMode(
const DelegateInfo *delegate_info)
1578 if (IsEventLogging() != MagickFalse)
1579 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1581 assert(delegate_info->signature == MagickCoreSignature);
1582 return(delegate_info->mode);
1609 MagickExport MagickBooleanType GetDelegateThreadSupport(
1612 if (IsEventLogging() != MagickFalse)
1613 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"...");
1615 assert(delegate_info->signature == MagickCoreSignature);
1616 return(delegate_info->thread_support);
1642 static MagickBooleanType IsDelegateCacheInstantiated(
ExceptionInfo *exception)
1647 ActivateSemaphoreInfo(&delegate_semaphore);
1648 LockSemaphoreInfo(delegate_semaphore);
1650 delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
1651 UnlockSemaphoreInfo(delegate_semaphore);
1653 return(delegate_cache != (
LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
1686 static MagickBooleanType CopyDelegateFile(
const char *source,
1687 const char *destination,
const MagickBooleanType overwrite)
1715 assert(source != (
const char *) NULL);
1716 assert(destination != (
char *) NULL);
1717 if (overwrite == MagickFalse)
1719 status=GetPathAttributes(destination,&attributes);
1720 if (status != MagickFalse)
1723 destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
1724 if (destination_file == -1)
1725 return(MagickFalse);
1726 source_file=open_utf8(source,O_RDONLY | O_BINARY,0);
1727 if (source_file == -1)
1729 (void) close(destination_file);
1730 return(MagickFalse);
1732 quantum=(size_t) MagickMaxBufferExtent;
1733 if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
1734 quantum=MagickMin((
size_t) attributes.st_size,MagickMaxBufferExtent);
1735 buffer=(
unsigned char *) AcquireQuantumMemory(quantum,
sizeof(*buffer));
1736 if (buffer == (
unsigned char *) NULL)
1738 (void) close(source_file);
1739 (void) close(destination_file);
1740 return(MagickFalse);
1743 for (i=0; ; i+=count)
1745 count=(ssize_t) read(source_file,buffer,quantum);
1748 length=(size_t) count;
1749 count=(ssize_t) write(destination_file,buffer,length);
1750 if ((
size_t) count != length)
1753 (void) close(destination_file);
1754 (void) close(source_file);
1755 buffer=(
unsigned char *) RelinquishMagickMemory(buffer);
1756 return(i != 0 ? MagickTrue : MagickFalse);
1759 MagickExport MagickBooleanType InvokeDelegate(
ImageInfo *image_info,
1765 input_filename[MaxTextExtent],
1766 output_filename[MaxTextExtent];
1784 assert(image_info != (
ImageInfo *) NULL);
1785 assert(image_info->signature == MagickCoreSignature);
1786 assert(image != (
Image *) NULL);
1787 assert(image->signature == MagickCoreSignature);
1788 if (IsEventLogging() != MagickFalse)
1789 (void) LogMagickEvent(TraceEvent,GetMagickModule(),
"%s",image->filename);
1790 rights=ExecutePolicyRights;
1791 if ((decode != (
const char *) NULL) &&
1792 (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse))
1795 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1796 "NotAuthorized",
"`%s'",decode);
1797 return(MagickFalse);
1799 if ((encode != (
const char *) NULL) &&
1800 (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse))
1803 (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
1804 "NotAuthorized",
"`%s'",encode);
1805 return(MagickFalse);
1807 temporary=(*image->filename ==
'\0') ? MagickTrue : MagickFalse;
1808 if (temporary != MagickFalse)
1809 if (AcquireUniqueFilename(image->filename) == MagickFalse)
1811 ThrowFileException(exception,FileOpenError,
1812 "UnableToCreateTemporaryFile",image->filename);
1813 return(MagickFalse);
1815 delegate_info=GetDelegateInfo(decode,encode,exception);
1818 if (temporary != MagickFalse)
1819 (void) RelinquishUniqueFileResource(image->filename);
1820 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1821 "NoTagFound",
"`%s'",decode ? decode : encode);
1822 return(MagickFalse);
1824 if (*image_info->filename ==
'\0')
1826 if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
1828 if (temporary != MagickFalse)
1829 (void) RelinquishUniqueFileResource(image->filename);
1830 ThrowFileException(exception,FileOpenError,
1831 "UnableToCreateTemporaryFile",image_info->filename);
1832 return(MagickFalse);
1834 image_info->temporary=MagickTrue;
1836 if ((delegate_info->mode != 0) && (((decode != (
const char *) NULL) &&
1837 (delegate_info->encode != (
char *) NULL)) ||
1838 ((encode != (
const char *) NULL) &&
1839 (delegate_info->decode != (
char *) NULL))))
1853 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1855 ThrowFileException(exception,FileOpenError,
1856 "UnableToCreateTemporaryFile",image_info->unique);
1857 return(MagickFalse);
1859 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1861 (void) RelinquishUniqueFileResource(image_info->unique);
1862 ThrowFileException(exception,FileOpenError,
1863 "UnableToCreateTemporaryFile",image_info->zero);
1864 return(MagickFalse);
1866 magick=InterpretDelegateProperties(image_info,image,
1867 decode != (
char *) NULL ? delegate_info->encode :
1868 delegate_info->decode);
1869 if (magick == (
char *) NULL)
1871 (void) RelinquishUniqueFileResource(image_info->unique);
1872 (void) RelinquishUniqueFileResource(image_info->zero);
1873 if (temporary != MagickFalse)
1874 (void) RelinquishUniqueFileResource(image->filename);
1875 (void) ThrowMagickException(exception,GetMagickModule(),
1876 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1877 return(MagickFalse);
1879 LocaleUpper(magick);
1880 clone_info=CloneImageInfo(image_info);
1881 (void) CopyMagickString((
char *) clone_info->magick,magick,MaxTextExtent);
1882 if (LocaleCompare(magick,
"NULL") != 0)
1883 (
void) CopyMagickString(image->magick,magick,MaxTextExtent);
1884 magick=DestroyString(magick);
1885 (void) FormatLocaleString(clone_info->filename,MaxTextExtent,
"%s:",
1886 delegate_info->decode);
1887 (void) SetImageInfo(clone_info,(
unsigned int) GetImageListLength(image),
1889 (void) CopyMagickString(clone_info->filename,image_info->filename,
1891 (void) CopyMagickString(image_info->filename,image->filename,
1893 for (p=image; p != (
Image *) NULL; p=GetNextImageInList(p))
1895 (void) FormatLocaleString(p->filename,MaxTextExtent,
"%s:%s",
1896 delegate_info->decode,clone_info->filename);
1897 status=WriteImage(clone_info,p);
1898 if (status == MagickFalse)
1900 (void) RelinquishUniqueFileResource(image_info->unique);
1901 (void) RelinquishUniqueFileResource(image_info->zero);
1902 if (temporary != MagickFalse)
1903 (void) RelinquishUniqueFileResource(image->filename);
1904 clone_info=DestroyImageInfo(clone_info);
1905 (void) ThrowMagickException(exception,GetMagickModule(),
1906 DelegateError,
"DelegateFailed",
"`%s'",decode ? decode : encode);
1907 return(MagickFalse);
1909 if (clone_info->adjoin != MagickFalse)
1912 (void) RelinquishUniqueFileResource(image_info->unique);
1913 (void) RelinquishUniqueFileResource(image_info->zero);
1914 clone_info=DestroyImageInfo(clone_info);
1919 commands=StringToList(delegate_info->commands);
1920 if (commands == (
char **) NULL)
1922 if (temporary != MagickFalse)
1923 (void) RelinquishUniqueFileResource(image->filename);
1924 (void) ThrowMagickException(exception,GetMagickModule(),
1925 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
1926 decode ? decode : encode);
1927 return(MagickFalse);
1929 command=(
char *) NULL;
1931 (void) CopyMagickString(output_filename,image_info->filename,MaxTextExtent);
1932 (void) CopyMagickString(input_filename,image->filename,MaxTextExtent);
1933 for (i=0; commands[i] != (
char *) NULL; i++)
1935 status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
1936 if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
1938 ThrowFileException(exception,FileOpenError,
1939 "UnableToCreateTemporaryFile",image_info->unique);
1942 if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
1944 (void) RelinquishUniqueFileResource(image_info->unique);
1945 ThrowFileException(exception,FileOpenError,
1946 "UnableToCreateTemporaryFile",image_info->zero);
1949 if (LocaleCompare(decode,
"SCAN") != 0)
1951 status=AcquireUniqueSymbolicLink(input_filename,image->filename);
1952 if (status == MagickFalse)
1954 ThrowFileException(exception,FileOpenError,
1955 "UnableToCreateTemporaryFile",input_filename);
1960 command=InterpretDelegateProperties(image_info,image,commands[i]);
1961 if (command != (
char *) NULL)
1966 status=ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
1967 command,(
char *) NULL,exception) != 0 ? MagickTrue : MagickFalse;
1968 if (delegate_info->spawn != MagickFalse)
1977 while ((count-- > 0) && (access_utf8(image->filename,F_OK) == 0))
1978 (void) MagickDelay(100);
1980 command=DestroyString(command);
1982 if (LocaleCompare(decode,
"SCAN") != 0)
1984 if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
1985 (void) RelinquishUniqueFileResource(input_filename);
1987 if ((strcmp(input_filename,output_filename) != 0) &&
1988 (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse))
1989 (void) RelinquishUniqueFileResource(output_filename);
1990 if (image_info->temporary != MagickFalse)
1991 (void) RelinquishUniqueFileResource(image_info->filename);
1992 (void) RelinquishUniqueFileResource(image_info->unique);
1993 (void) RelinquishUniqueFileResource(image_info->zero);
1994 (void) RelinquishUniqueFileResource(image_info->filename);
1995 (void) RelinquishUniqueFileResource(image->filename);
1996 if (status != MagickFalse)
1998 (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
1999 "DelegateFailed",
"`%s'",commands[i]);
2002 commands[i]=DestroyString(commands[i]);
2004 (void) CopyMagickString(image_info->filename,output_filename,MaxTextExtent);
2005 (void) CopyMagickString(image->filename,input_filename,MaxTextExtent);
2009 for ( ; commands[i] != (
char *) NULL; i++)
2010 commands[i]=DestroyString(commands[i]);
2011 commands=(
char **) RelinquishMagickMemory(commands);
2012 if (temporary != MagickFalse)
2013 (void) RelinquishUniqueFileResource(image->filename);
2014 return(status == MagickFalse ? MagickTrue : MagickFalse);
2041 MagickExport MagickBooleanType ListDelegateInfo(FILE *file,
2049 delegate[MaxTextExtent];
2063 if (file == (
const FILE *) NULL)
2065 delegate_info=GetDelegateInfoList(
"*",&number_delegates,exception);
2067 return(MagickFalse);
2068 path=(
const char *) NULL;
2069 for (i=0; i < (ssize_t) number_delegates; i++)
2071 if (delegate_info[i]->stealth != MagickFalse)
2073 if ((path == (
const char *) NULL) ||
2074 (LocaleCompare(path,delegate_info[i]->path) != 0))
2076 if (delegate_info[i]->path != (
char *) NULL)
2077 (
void) FormatLocaleFile(file,
"\nPath: %s\n\n",delegate_info[i]->path);
2078 (void) FormatLocaleFile(file,
"Delegate Command\n");
2079 (void) FormatLocaleFile(file,
2080 "-------------------------------------------------" 2081 "------------------------------\n");
2083 path=delegate_info[i]->path;
2085 if (delegate_info[i]->encode != (
char *) NULL)
2086 (
void) CopyMagickString(delegate,delegate_info[i]->encode,MaxTextExtent);
2087 (void) ConcatenateMagickString(delegate,
" ",MaxTextExtent);
2089 commands=StringToList(delegate_info[i]->commands);
2090 if (commands == (
char **) NULL)
2092 (void) FormatLocaleFile(file,
"%11s%c=%c%s ",delegate_info[i]->decode ?
2093 delegate_info[i]->decode :
"",delegate_info[i]->mode <= 0 ?
'<' :
' ',
2094 delegate_info[i]->mode >= 0 ?
'>' :
' ',delegate);
2095 StripString(commands[0]);
2096 (void) FormatLocaleFile(file,
"\"%s\"\n",commands[0]);
2097 for (j=1; commands[j] != (
char *) NULL; j++)
2099 StripString(commands[j]);
2100 (void) FormatLocaleFile(file,
" \"%s\"\n",commands[j]);
2102 for (j=0; commands[j] != (
char *) NULL; j++)
2103 commands[j]=DestroyString(commands[j]);
2104 commands=(
char **) RelinquishMagickMemory(commands);
2106 (void) fflush(file);
2108 RelinquishMagickMemory((
void *) delegate_info);
2143 static MagickBooleanType LoadDelegateCache(
LinkedListInfo *cache,
2144 const char *xml,
const char *filename,
const size_t depth,
2148 keyword[MaxTextExtent],
2166 (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
2167 "Loading delegate configuration file \"%s\" ...",filename);
2168 if (xml == (
const char *) NULL)
2169 return(MagickFalse);
2172 token=AcquireString(xml);
2173 extent=strlen(token)+MaxTextExtent;
2174 for (q=(
const char *) xml; *q !=
'\0'; )
2179 (void) GetNextToken(q,&q,extent,token);
2182 (void) CopyMagickString(keyword,token,MaxTextExtent);
2183 if (LocaleNCompare(keyword,
"<!DOCTYPE",9) == 0)
2188 while ((LocaleNCompare(q,
"]>",2) != 0) && (*q !=
'\0'))
2189 (
void) GetNextToken(q,&q,extent,token);
2192 if (LocaleNCompare(keyword,
"<!--",4) == 0)
2197 while ((LocaleNCompare(q,
"->",2) != 0) && (*q !=
'\0'))
2198 (void) GetNextToken(q,&q,extent,token);
2201 if (LocaleCompare(keyword,
"<include") == 0)
2206 while (((*token !=
'/') && (*(token+1) !=
'>')) && (*q !=
'\0'))
2208 (void) CopyMagickString(keyword,token,MaxTextExtent);
2209 (void) GetNextToken(q,&q,extent,token);
2212 (void) GetNextToken(q,&q,extent,token);
2213 if (LocaleCompare(keyword,
"file") == 0)
2215 if (depth > MagickMaxRecursionDepth)
2216 (void) ThrowMagickException(exception,GetMagickModule(),
2217 ConfigureError,
"IncludeElementNestedTooDeeply",
"`%s'",token);
2221 path[MaxTextExtent],
2224 GetPathComponent(filename,HeadPath,path);
2226 (void) ConcatenateMagickString(path,DirectorySeparator,
2228 if (*token == *DirectorySeparator)
2229 (void) CopyMagickString(path,token,MaxTextExtent);
2231 (
void) ConcatenateMagickString(path,token,MaxTextExtent);
2232 xml=FileToXML(path,~0UL);
2233 if (xml != (
char *) NULL)
2235 status&=LoadDelegateCache(cache,xml,path,depth+1,
2237 xml=(
char *) RelinquishMagickMemory(xml);
2244 if (LocaleCompare(keyword,
"<delegate") == 0)
2250 sizeof(*delegate_info));
2252 ThrowFatalException(ResourceLimitFatalError,
"MemoryAllocationFailed");
2253 (void) memset(delegate_info,0,
sizeof(*delegate_info));
2254 delegate_info->path=ConstantString(filename);
2255 delegate_info->thread_support=MagickTrue;
2256 delegate_info->signature=MagickCoreSignature;
2261 if ((LocaleCompare(keyword,
"/>") == 0) ||
2262 (LocaleCompare(keyword,
"</policy>") == 0))
2264 status=AppendValueToLinkedList(cache,delegate_info);
2265 if (status == MagickFalse)
2266 (void) ThrowMagickException(exception,GetMagickModule(),
2267 ResourceLimitError,
"MemoryAllocationFailed",
"`%s'",
2268 delegate_info->commands);
2272 (void) GetNextToken(q,(
const char **) NULL,extent,token);
2275 (void) GetNextToken(q,&q,extent,token);
2276 (void) GetNextToken(q,&q,extent,token);
2282 if (LocaleCompare((
char *) keyword,
"command") == 0)
2287 commands=AcquireString(token);
2288 #if defined(MAGICKCORE_WINDOWS_SUPPORT) 2289 if (strchr(commands,
'@') != (
char *) NULL)
2292 path[MaxTextExtent];
2294 NTGhostscriptEXE(path,MaxTextExtent);
2295 (void) SubstituteString((
char **) &commands,
"@PSDelegate@",
2297 (void) SubstituteString((
char **) &commands,
"\\",
"/");
2299 (void) SubstituteString((
char **) &commands,
""",
"\"");
2301 (void) SubstituteString((
char **) &commands,
""",
"'");
2303 (void) SubstituteString((
char **) &commands,
"&",
"&");
2304 (void) SubstituteString((
char **) &commands,
">",
">");
2305 (void) SubstituteString((
char **) &commands,
"<",
"<");
2306 if (delegate_info->commands != (
char *) NULL)
2307 delegate_info->commands=DestroyString(delegate_info->commands);
2308 delegate_info->commands=commands;
2316 if (LocaleCompare((
char *) keyword,
"decode") == 0)
2318 delegate_info->decode=ConstantString(token);
2319 delegate_info->mode=1;
2327 if (LocaleCompare((
char *) keyword,
"encode") == 0)
2329 delegate_info->encode=ConstantString(token);
2330 delegate_info->mode=(-1);
2338 if (LocaleCompare((
char *) keyword,
"mode") == 0)
2340 delegate_info->mode=1;
2341 if (LocaleCompare(token,
"bi") == 0)
2342 delegate_info->mode=0;
2344 if (LocaleCompare(token,
"encode") == 0)
2345 delegate_info->mode=(-1);
2353 if (LocaleCompare((
char *) keyword,
"spawn") == 0)
2355 delegate_info->spawn=IsMagickTrue(token);
2358 if (LocaleCompare((
char *) keyword,
"stealth") == 0)
2360 delegate_info->stealth=IsMagickTrue(token);
2368 if (LocaleCompare((
char *) keyword,
"thread-support") == 0)
2370 delegate_info->thread_support=IsMagickTrue(token);
2371 if (delegate_info->thread_support == MagickFalse)
2372 delegate_info->semaphore=AllocateSemaphoreInfo();
2381 token=(
char *) RelinquishMagickMemory(token);
2382 return(status != 0 ? MagickTrue : MagickFalse);