]> granicus.if.org Git - imagemagick/blobdiff - MagickCore/delegate.c
Update web pages
[imagemagick] / MagickCore / delegate.c
index d0fd2309754b22ccc55bc4bd970b2308c1735f61..0663077af2a599c75974f848cb099e07b031aef1 100644 (file)
@@ -99,8 +99,8 @@ static const char
     "  <delegate decode=\"https\" command=\"&quot;wget&quot; -q -O &quot;%o&quot; &quot;https:%M&quot;\"/>"
     "  <delegate decode=\"ilbm\" command=\"&quot;ilbmtoppm&quot; &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
     "  <delegate decode=\"man\" command=\"&quot;groff&quot; -man -Tps &quot;%i&quot; &gt; &quot;%o&quot;\"/>"
-    "  <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -v -1 -vframes %S -i &quot;%i&quot; -vcodec pam -an -f rawvideo -y &quot;%u.pam&quot; 2&gt; &quot;%Z&quot;\"/>"
-    "  <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -v -1 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 300 -i &quot;%M%%d.jpg&quot; &quot;%u.%m&quot; 2&gt; &quot;%Z&quot;\"/>"
+    "  <delegate decode=\"mpeg:decode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -nostdin -v -1 -vframes %S -i &quot;%i&quot; -vcodec pam -an -f rawvideo -y &quot;%u.pam&quot; 2&gt; &quot;%Z&quot;\"/>"
+    "  <delegate decode=\"null\" encode=\"mpeg:encode\" stealth=\"True\" command=\"&quot;ffmpeg&quot; -nostdin -v -1 -mbd rd -trellis 2 -cmp 2 -subcmp 2 -g 300 -i &quot;%M%%d.jpg&quot; &quot;%u.%m&quot; 2&gt; &quot;%Z&quot;\"/>"
     "  <delegate decode=\"pcl:color\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=ppmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
     "  <delegate decode=\"pcl:cmyk\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=bmpsep8&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
     "  <delegate decode=\"pcl:mono\" stealth=\"True\" command=\"&quot;pcl6&quot; -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 &quot;-sDEVICE=pbmraw&quot; -dTextAlphaBits=%u -dGraphicsAlphaBits=%u &quot;-r%s&quot; %s &quot;-sOutputFile=%s&quot; &quot;%s&quot;\"/>"
@@ -334,7 +334,7 @@ static char *SanitizeDelegateCommand(const char *command)
   static char
     whitelist[] =
       "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_- "
-      ".@&;<>()|/\\\'\":%=~";
+      ".@&;<>()|/\\\'\":%=~`";
 
   sanitize_command=AcquireString(command);
   p=sanitize_command;
@@ -542,9 +542,9 @@ MagickExport char *GetDelegateCommand(const ImageInfo *image_info,Image *image,
     i;
 
   assert(image_info != (ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
 
@@ -604,7 +604,7 @@ MagickExport const char *GetDelegateCommands(const DelegateInfo *delegate_info)
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
 
   assert(delegate_info != (DelegateInfo *) NULL);
-  assert(delegate_info->signature == MagickSignature);
+  assert(delegate_info->signature == MagickCoreSignature);
   return(delegate_info->commands);
 }
 \f
@@ -924,7 +924,7 @@ MagickExport ssize_t GetDelegateMode(const DelegateInfo *delegate_info)
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
 
   assert(delegate_info != (DelegateInfo *) NULL);
-  assert(delegate_info->signature == MagickSignature);
+  assert(delegate_info->signature == MagickCoreSignature);
   return(delegate_info->mode);
 }
 \f
@@ -958,7 +958,7 @@ MagickExport MagickBooleanType GetDelegateThreadSupport(
   (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
 
   assert(delegate_info != (DelegateInfo *) NULL);
-  assert(delegate_info->signature == MagickSignature);
+  assert(delegate_info->signature == MagickCoreSignature);
   return(delegate_info->thread_support);
 }
 \f
@@ -996,7 +996,7 @@ static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
         delegate_cache=AcquireDelegateCache(DelegateFilename,exception);
       UnlockSemaphoreInfo(delegate_semaphore);
     }
-  return(IsMagickNotNULL(delegate_cache));
+  return(delegate_cache != (LinkedListInfo *) NULL ? MagickTrue : MagickFalse);
 }
 \f
 /*
@@ -1030,7 +1030,7 @@ static MagickBooleanType IsDelegateCacheInstantiated(ExceptionInfo *exception)
 */
 
 static MagickBooleanType CopyDelegateFile(const char *source,
-  const char *destination)
+  const char *destination,const MagickBooleanType overwrite)
 {
   int
     destination_file,
@@ -1060,9 +1060,12 @@ static MagickBooleanType CopyDelegateFile(const char *source,
   */
   assert(source != (const char *) NULL);
   assert(destination != (char *) NULL);
-  status=GetPathAttributes(destination,&attributes);
-  if (status != MagickFalse)
-    return(MagickTrue);
+  if (overwrite == MagickFalse)
+    {
+      status=GetPathAttributes(destination,&attributes);
+      if (status != MagickFalse)
+        return(MagickTrue);
+    }
   destination_file=open_utf8(destination,O_WRONLY | O_BINARY | O_CREAT,S_MODE);
   if (destination_file == -1)
     return(MagickFalse);
@@ -1073,7 +1076,7 @@ static MagickBooleanType CopyDelegateFile(const char *source,
       return(MagickFalse);
     }
   quantum=(size_t) MagickMaxBufferExtent;
-  if ((fstat(source_file,&attributes) == 0) && (attributes.st_size != 0))
+  if ((fstat(source_file,&attributes) == 0) && (attributes.st_size > 0))
     quantum=MagickMin((size_t) attributes.st_size,MagickMaxBufferExtent);
   buffer=(unsigned char *) AcquireQuantumMemory(quantum,sizeof(*buffer));
   if (buffer == (unsigned char *) NULL)
@@ -1096,7 +1099,7 @@ static MagickBooleanType CopyDelegateFile(const char *source,
   (void) close(destination_file);
   (void) close(source_file);
   buffer=(unsigned char *) RelinquishMagickMemory(buffer);
-  return(IsMagickTrue(i!=0));
+  return(i != 0 ? MagickTrue : MagickFalse);
 }
 
 MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
@@ -1125,39 +1128,39 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
     Get delegate.
   */
   assert(image_info != (ImageInfo *) NULL);
-  assert(image_info->signature == MagickSignature);
+  assert(image_info->signature == MagickCoreSignature);
   assert(image != (Image *) NULL);
-  assert(image->signature == MagickSignature);
+  assert(image->signature == MagickCoreSignature);
   if (image->debug != MagickFalse)
     (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",image->filename);
 
   rights=ExecutePolicyRights;
-  if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,decode)) )
+  if (IsRightsAuthorized(DelegatePolicyDomain,rights,decode) == MagickFalse)
     {
       errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
         "NotAuthorized","`%s'",decode);
       return(MagickFalse);
     }
-  if( IfMagickFalse(IsRightsAuthorized(DelegatePolicyDomain,rights,encode)) )
+  if (IsRightsAuthorized(DelegatePolicyDomain,rights,encode) == MagickFalse)
     {
       errno=EPERM;
       (void) ThrowMagickException(exception,GetMagickModule(),PolicyError,
         "NotAuthorized","`%s'",encode);
       return(MagickFalse);
     }
-  temporary=IsMagickTrue(*image->filename == '\0');
-  if( IfMagickTrue(temporary) )
-    if( IfMagickFalse(AcquireUniqueFilename(image->filename)) )
-      {
-        ThrowFileException(exception,FileOpenError,
-          "UnableToCreateTemporaryFile",image->filename);
-        return(MagickFalse);
-      }
+  temporary=*image->filename == '\0' ? MagickTrue : MagickFalse;
+  if ((temporary != MagickFalse) && (AcquireUniqueFilename(image->filename) ==
+      MagickFalse))
+    {
+      ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
+        image->filename);
+      return(MagickFalse);
+    }
   delegate_info=GetDelegateInfo(decode,encode,exception);
   if (delegate_info == (DelegateInfo *) NULL)
     {
-      if( IfMagickTrue(temporary) )
+      if (temporary != MagickFalse)
         (void) RelinquishUniqueFileResource(image->filename);
       (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
         "NoTagFound","`%s'",decode ? decode : encode);
@@ -1165,9 +1168,9 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
     }
   if (*image_info->filename == '\0')
     {
-      if( IfMagickFalse(AcquireUniqueFilename(image_info->filename)) )
+      if (AcquireUniqueFilename(image_info->filename) == MagickFalse)
         {
-          if( IfMagickTrue(temporary) )
+          if (temporary != MagickFalse)
             (void) RelinquishUniqueFileResource(image->filename);
           ThrowFileException(exception,FileOpenError,
             "UnableToCreateTemporaryFile",image_info->filename);
@@ -1192,13 +1195,13 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
       /*
         Delegate requires a particular image format.
       */
-      if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
+      if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
         {
           ThrowFileException(exception,FileOpenError,
             "UnableToCreateTemporaryFile",image_info->unique);
           return(MagickFalse);
         }
-      if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
+      if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
         {
           (void) RelinquishUniqueFileResource(image_info->unique);
           ThrowFileException(exception,FileOpenError,
@@ -1211,7 +1214,7 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
         {
           (void) RelinquishUniqueFileResource(image_info->unique);
           (void) RelinquishUniqueFileResource(image_info->zero);
-          if( IfMagickTrue(temporary) )
+          if (temporary != MagickFalse)
             (void) RelinquishUniqueFileResource(image->filename);
           (void) ThrowMagickException(exception,GetMagickModule(),
             DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
@@ -1237,18 +1240,18 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
         (void) FormatLocaleString(p->filename,MagickPathExtent,"%s:%s",
           delegate_info->decode,clone_info->filename);
         status=WriteImage(clone_info,p,exception);
-        if( IfMagickFalse(status) )
+        if (status == MagickFalse)
           {
             (void) RelinquishUniqueFileResource(image_info->unique);
             (void) RelinquishUniqueFileResource(image_info->zero);
-            if( IfMagickTrue(temporary) )
+            if (temporary != MagickFalse)
               (void) RelinquishUniqueFileResource(image->filename);
             clone_info=DestroyImageInfo(clone_info);
             (void) ThrowMagickException(exception,GetMagickModule(),
               DelegateError,"DelegateFailed","`%s'",decode ? decode : encode);
             return(MagickFalse);
           }
-        if( IfMagickTrue(clone_info->adjoin) )
+        if (clone_info->adjoin != MagickFalse)
           break;
       }
       (void) RelinquishUniqueFileResource(image_info->unique);
@@ -1269,19 +1272,20 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
       return(MagickFalse);
     }
   command=(char *) NULL;
-  status=MagickFalse;
-  (void) CopyMagickString(output_filename,image_info->filename,MagickPathExtent);
+  status=MagickTrue;
+  (void) CopyMagickString(output_filename,image_info->filename,
+    MagickPathExtent);
   (void) CopyMagickString(input_filename,image->filename,MagickPathExtent);
   for (i=0; commands[i] != (char *) NULL; i++)
   {
-    status=AcquireUniqueSymbolicLink(output_filename,image_info->filename);
-    if( IfMagickFalse(AcquireUniqueFilename(image_info->unique)) )
+    (void) AcquireUniqueSymbolicLink(output_filename,image_info->filename);
+    if (AcquireUniqueFilename(image_info->unique) == MagickFalse)
       {
         ThrowFileException(exception,FileOpenError,
           "UnableToCreateTemporaryFile",image_info->unique);
         break;
       }
-    if( IfMagickFalse(AcquireUniqueFilename(image_info->zero)) )
+    if (AcquireUniqueFilename(image_info->zero) == MagickFalse)
       {
         (void) RelinquishUniqueFileResource(image_info->unique);
         ThrowFileException(exception,FileOpenError,
@@ -1291,23 +1295,24 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
     if (LocaleCompare(decode,"SCAN") != 0)
       {
         status=AcquireUniqueSymbolicLink(input_filename,image->filename);
-        if( IfMagickFalse(status) )
+        if (status == MagickFalse)
           {
             ThrowFileException(exception,FileOpenError,
               "UnableToCreateTemporaryFile",input_filename);
             break;
           }
       }
-    status=MagickFalse;
+    status=MagickTrue;
     command=InterpretImageProperties(image_info,image,commands[i],exception);
     if (command != (char *) NULL)
       {
         /*
           Execute delegate.
         */
-        status=IsMagickTrue(ExternalDelegateCommand(delegate_info->spawn,
-          image_info->verbose,command,(char *) NULL,exception) != 0);
-        if (IfMagickTrue(delegate_info->spawn))
+        if (ExternalDelegateCommand(delegate_info->spawn,image_info->verbose,
+          command,(char *) NULL,exception) != 0)
+          status=MagickFalse;
+        if (delegate_info->spawn != MagickFalse)
           {
             ssize_t
               count;
@@ -1323,18 +1328,18 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
       }
     if (LocaleCompare(decode,"SCAN") != 0)
       {
-        if (IfMagickFalse(CopyDelegateFile(image->filename,input_filename)))
+        if (CopyDelegateFile(image->filename,input_filename,MagickFalse) == MagickFalse)
           (void) RelinquishUniqueFileResource(input_filename);
       }
-    if (IfMagickFalse(CopyDelegateFile(image_info->filename,output_filename)))
+    if (CopyDelegateFile(image_info->filename,output_filename,MagickTrue) == MagickFalse)
       (void) RelinquishUniqueFileResource(output_filename);
-    if( IfMagickTrue(image_info->temporary) )
+    if (image_info->temporary != MagickFalse)
       (void) RelinquishUniqueFileResource(image_info->filename);
     (void) RelinquishUniqueFileResource(image_info->unique);
     (void) RelinquishUniqueFileResource(image_info->zero);
     (void) RelinquishUniqueFileResource(image_info->filename);
     (void) RelinquishUniqueFileResource(image->filename);
-    if( IfMagickTrue(status) )
+    if (status == MagickFalse)
       {
         (void) ThrowMagickException(exception,GetMagickModule(),DelegateError,
           "DelegateFailed","`%s'",commands[i]);
@@ -1350,9 +1355,9 @@ MagickExport MagickBooleanType InvokeDelegate(ImageInfo *image_info,
   for ( ; commands[i] != (char *) NULL; i++)
     commands[i]=DestroyString(commands[i]);
   commands=(char **) RelinquishMagickMemory(commands);
-  if( IfMagickTrue(temporary) )
+  if (temporary != MagickFalse)
     (void) RelinquishUniqueFileResource(image->filename);
-  return(IsMagickFalse(status));
+  return(status);
 }
 \f
 /*
@@ -1590,7 +1595,7 @@ static MagickBooleanType LoadDelegateCache(LinkedListInfo *delegate_cache,
         (void) ResetMagickMemory(delegate_info,0,sizeof(*delegate_info));
         delegate_info->path=ConstantString(filename);
         delegate_info->thread_support=MagickTrue;
-        delegate_info->signature=MagickSignature;
+        delegate_info->signature=MagickCoreSignature;
         continue;
       }
     if (delegate_info == (DelegateInfo *) NULL)