Skip to content

Commit

Permalink
identify image time-to-live
Browse files Browse the repository at this point in the history
  • Loading branch information
Cristy committed Dec 28, 2023
1 parent 9169a2f commit 377329e
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 21 deletions.
2 changes: 1 addition & 1 deletion coders/cin.c
Original file line number Diff line number Diff line change
Expand Up @@ -998,7 +998,7 @@ static MagickBooleanType WriteCINImage(const ImageInfo *image_info,Image *image)
offset+=WriteBlob(image,sizeof(cin.file.filename),(unsigned char *)
cin.file.filename);
seconds=GetMagickTime();
GetMagickUTCtime(&seconds,&utc_time);
GetMagickUTCTime(&seconds,&utc_time);
(void) memset(timestamp,0,sizeof(timestamp));
(void) strftime(timestamp,MaxTextExtent,"%Y:%m:%d:%H:%M:%SUTC",&utc_time);
(void) memset(cin.file.create_date,0,sizeof(cin.file.create_date));
Expand Down
2 changes: 1 addition & 1 deletion coders/mat.c
Original file line number Diff line number Diff line change
Expand Up @@ -1646,7 +1646,7 @@ static MagickBooleanType WriteMATImage(const ImageInfo *image_info,Image *image)
image->depth=8;

current_time=GetMagickTime();
GetMagickUTCtime(&current_time,&utc_time);
GetMagickUTCTime(&current_time,&utc_time);
(void) memset(MATLAB_HDR,' ',MagickMin(sizeof(MATLAB_HDR),124));
FormatLocaleString(MATLAB_HDR,sizeof(MATLAB_HDR),
"MATLAB 5.0 MAT-file, Platform: %s, Created on: %s %s %2d %2d:%2d:%2d %d",
Expand Down
2 changes: 1 addition & 1 deletion coders/pdf.c
Original file line number Diff line number Diff line change
Expand Up @@ -3035,7 +3035,7 @@ static MagickBooleanType WritePDFImage(const ImageInfo *image_info,Image *image)
}
(void) WriteBlobString(image,buffer);
seconds=GetMagickTime();
GetMagickUTCtime(&seconds,&utc_time);
GetMagickUTCTime(&seconds,&utc_time);
(void) FormatLocaleString(date,MaxTextExtent,"D:%04d%02d%02d%02d%02d%02d",
utc_time.tm_year+1900,utc_time.tm_mon+1,utc_time.tm_mday,
utc_time.tm_hour,utc_time.tm_min,utc_time.tm_sec);
Expand Down
14 changes: 14 additions & 0 deletions magick/identify.c
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
#include "magick/string_.h"
#include "magick/string-private.h"
#include "magick/timer.h"
#include "magick/timer-private.h"
#include "magick/token.h"
#include "magick/utility.h"
#include "magick/version.h"
Expand Down Expand Up @@ -480,6 +481,7 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
char
color[MaxTextExtent],
format[MaxTextExtent],
iso8601[sizeof("9999-99-99T99:99:99Z")],
key[MaxTextExtent];

ChannelFeatures
Expand Down Expand Up @@ -537,6 +539,9 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
struct stat
properties;

struct tm
timestamp;

assert(image != (Image *) NULL);
assert(image->signature == MagickCoreSignature);
if (IsEventLogging() != MagickFalse)
Expand Down Expand Up @@ -1465,6 +1470,15 @@ MagickExport MagickBooleanType IdentifyImage(Image *image,FILE *file,
image->rows/elapsed_time+0.5),MagickFalse,format);
(void) FormatLocaleFile(file," Pixels per second: %s\n",format);
}
(void) GetMagickUTCTime(&image->timestamp,&timestamp);
(void) strftime(iso8601,sizeof(iso8601),"%FT%TZ",&timestamp);
expired=' ';
if (IsImageTTLExpired(image) != MagickFalse)
expired='*';
(void) FormatLocaleFile(file," Time-to-live: %g:%g:%g:%g%c %s\n",
(double) (image->ttl/(3600*24)),(double) ((image->ttl % (24*3600))/3600),
(double) ((image->ttl % 3600)/60),(double) ((image->ttl % 3600) % 60),
expired,iso8601);
(void) FormatLocaleFile(file," User time: %0.3fu\n",user_time);
(void) FormatLocaleFile(file," Elapsed time: %lu:%02lu.%03lu\n",
(unsigned long) (elapsed_time/60.0),(unsigned long) ceil(fmod(
Expand Down
7 changes: 1 addition & 6 deletions magick/image.c
Original file line number Diff line number Diff line change
Expand Up @@ -136,9 +136,6 @@ MagickExport Image *AcquireImage(const ImageInfo *image_info)
Image
*image;

int
time_limit;

MagickStatusType
flags;

Expand Down Expand Up @@ -184,9 +181,7 @@ MagickExport Image *AcquireImage(const ImageInfo *image_info)
image->blob=CloneBlobInfo((BlobInfo *) NULL);
InitializeExceptionInfo(&image->exception);
image->timestamp=GetMagickTime();
time_limit=(int) GetMagickResourceLimit(TimeResource);
if (time_limit > 0)
image->ttl=image->timestamp+time_limit;
image->ttl=(int) GetMagickResourceLimit(TimeResource);
image->debug=(GetLogEventMask() & (ImageEvent | TransformEvent | CoderEvent))
!= 0 ? MagickTrue : MagickFalse;
image->reference_count=1;
Expand Down
22 changes: 11 additions & 11 deletions magick/timer-private.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ extern "C" {

#include "magick/locale_.h"

static inline void GetMagickUTCtime(const time_t *timep,struct tm *result)
static inline void GetMagickUTCTime(const time_t *timep,struct tm *result)
{
#if defined(MAGICKCORE_HAVE_GMTIME_R)
(void) gmtime_r(timep,result);
Expand Down Expand Up @@ -56,6 +56,16 @@ static inline void GetMagickLocaltime(const time_t *timep,struct tm *result)
#endif
}

extern MagickExport time_t
GetMagickTime(void);

static inline MagickBooleanType IsImageTTLExpired(const Image* image)
{
if (image->ttl == (time_t) 0)
return(MagickFalse);
return((image->timestamp+image->ttl) < GetMagickTime() ? MagickTrue : MagickFalse);
}

static inline time_t ParseMagickTimeToLive(const char *time_to_live)
{
char
Expand Down Expand Up @@ -90,16 +100,6 @@ static inline time_t ParseMagickTimeToLive(const char *time_to_live)
return(ttl);
}

extern MagickExport time_t
GetMagickTime(void);

static inline MagickBooleanType IsImageTTLExpired(const Image* image)
{
if (image->ttl == (time_t) 0)
return(MagickFalse);
return(image->ttl < GetMagickTime() ? MagickTrue : MagickFalse);
}

#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion magick/timer.c
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ MagickExport ssize_t FormatMagickTime(const time_t time,const size_t length,
utc_time;

assert(timestamp != (char *) NULL);
GetMagickUTCtime(&time,&utc_time);
GetMagickUTCTime(&time,&utc_time);
count=FormatLocaleString(timestamp,length,
"%04d-%02d-%02dT%02d:%02d:%02d%+03d:00",utc_time.tm_year+1900,
utc_time.tm_mon+1,utc_time.tm_mday,utc_time.tm_hour,utc_time.tm_min,
Expand Down

0 comments on commit 377329e

Please sign in to comment.