static MagickBooleanType SetPolicyValue(const PolicyDomain domain, const char *name,const char *value) { MagickBooleanType status; register PolicyInfo *p; status=MagickTrue; LockSemaphoreInfo(policy_semaphore); ResetLinkedListIterator(policy_cache); p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); while (p != (PolicyInfo *) NULL) { if ((p->domain == domain) && (LocaleCompare(name,p->name) == 0)) break; p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); } if (p != (PolicyInfo *) NULL) { if (p->value != (char *) NULL) p->value=DestroyString(p->value); } else { p=(PolicyInfo *) AcquireCriticalMemory(sizeof(*p)); (void) memset(p,0,sizeof(*p)); p->exempt=MagickFalse; p->signature=MagickCoreSignature; p->domain=domain; p->name=ConstantString(name); status=AppendValueToLinkedList(policy_cache,p); } p->value=ConstantString(value); UnlockSemaphoreInfo(policy_semaphore); if (status == MagickFalse) p=(PolicyInfo *) RelinquishMagickMemory(p); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + I n i t i a l i z e L o c a l e L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InitializeLocaleList() initializes the locale list. % % The format of the InitializeLocaleList method is: % % MagickBooleanType InitializeLocaleList(ExceptionInfo *exception) % % A description of each parameter follows. % % o exception: return any errors or warnings in this structure. % */ static MagickBooleanType InitializeLocaleList(ExceptionInfo *exception) { if ((locale_list == (SplayTreeInfo *) NULL) && (instantiate_locale == MagickFalse)) { if (locale_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&locale_semaphore); LockSemaphoreInfo(locale_semaphore); if ((locale_list == (SplayTreeInfo *) NULL) && (instantiate_locale == MagickFalse)) { char *locale; register const char *p; locale=(char *) NULL; p=setlocale(LC_CTYPE,(const char *) NULL); if (p != (const char *) NULL) locale=ConstantString(p); if (locale == (char *) NULL) locale=GetEnvironmentValue("LC_ALL"); if (locale == (char *) NULL) locale=GetEnvironmentValue("LC_MESSAGES"); if (locale == (char *) NULL) locale=GetEnvironmentValue("LC_CTYPE"); if (locale == (char *) NULL) locale=GetEnvironmentValue("LANG"); if (locale == (char *) NULL) locale=ConstantString("C"); (void) LoadLocaleLists(LocaleFilename,locale,exception); locale=DestroyString(locale); instantiate_locale=MagickTrue; } UnlockSemaphoreInfo(locale_semaphore); } return(locale_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + D e s t r o y M a g i c k M e m o r y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyMagickMemory() deallocates memory associated with the memory manager. % % The format of the DestroyMagickMemory method is: % % DestroyMagickMemory(void) % */ MagickExport void DestroyMagickMemory(void) { #if defined(MAGICKCORE_ZERO_CONFIGURATION_SUPPORT) register ssize_t i; if (memory_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&memory_semaphore); LockSemaphoreInfo(memory_semaphore); for (i=0; i < (ssize_t) memory_pool.number_segments; i++) if (memory_pool.segments[i]->mapped == MagickFalse) memory_methods.destroy_memory_handler( memory_pool.segments[i]->allocation); else (void) UnmapBlob(memory_pool.segments[i]->allocation, memory_pool.segments[i]->length); free_segments=(DataSegmentInfo *) NULL; (void) ResetMagickMemory(&memory_pool,0,sizeof(memory_pool)); UnlockSemaphoreInfo(memory_semaphore); DestroySemaphoreInfo(&memory_semaphore); #endif }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e S e m a p h o r e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireSemaphoreInfo() acquires a semaphore. % % The format of the AcquireSemaphoreInfo method is: % % void AcquireSemaphoreInfo(SemaphoreInfo **semaphore_info) % % A description of each parameter follows: % % o semaphore_info: Specifies a pointer to an SemaphoreInfo structure. % */ MagickExport void AcquireSemaphoreInfo(SemaphoreInfo **semaphore_info) { assert(semaphore_info != (SemaphoreInfo **) NULL); #if defined(MAGICKCORE_HAVE_PTHREAD) if (pthread_mutex_lock(&semaphore_mutex) != 0) (void) fprintf(stderr,"pthread_mutex_lock failed %s\n", GetExceptionMessage(errno)); #elif defined(MAGICKORE_HAVE_WINTHREADS) while (InterlockedCompareExchange(&semaphore_mutex,1L,0L) != 0) Sleep(10); #endif if (*semaphore_info == (SemaphoreInfo *) NULL) *semaphore_info=AllocateSemaphoreInfo(); #if defined(MAGICKCORE_HAVE_PTHREAD) if (pthread_mutex_unlock(&semaphore_mutex) != 0) (void) fprintf(stderr,"pthread_mutex_unlock failed %s\n", GetExceptionMessage(errno)); #elif defined(MAGICKORE_HAVE_WINTHREADS) InterlockedExchange(&semaphore_mutex,0L); #endif (void) LockSemaphoreInfo(*semaphore_info); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i s t M a g i c k R e s o u r c e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ListMagickResourceInfo() lists the resource info to a file. % % The format of the ListMagickResourceInfo method is: % % MagickBooleanType ListMagickResourceInfo(FILE *file, % ExceptionInfo *exception) % % A description of each parameter follows. % % o file: An pointer to a FILE. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickBooleanType ListMagickResourceInfo(FILE *file, ExceptionInfo *magick_unused(exception)) { char area_limit[MaxTextExtent], disk_limit[MaxTextExtent], map_limit[MaxTextExtent], memory_limit[MaxTextExtent], time_limit[MaxTextExtent]; if (file == (const FILE *) NULL) file=stdout; if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); (void) FormatMagickSize(resource_info.area_limit,MagickFalse,area_limit); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue,memory_limit); (void) FormatMagickSize(resource_info.map_limit,MagickTrue,map_limit); (void) CopyMagickString(disk_limit,"unlimited",MaxTextExtent); if (resource_info.disk_limit != MagickResourceInfinity) (void) FormatMagickSize(resource_info.disk_limit,MagickTrue,disk_limit); (void) CopyMagickString(time_limit,"unlimited",MaxTextExtent); if (resource_info.time_limit != MagickResourceInfinity) (void) FormatLocaleString(time_limit,MaxTextExtent,"%.20g",(double) ((MagickOffsetType) resource_info.time_limit)); (void) FormatLocaleFile(file," File Area Memory Map" " Disk Thread Throttle Time\n"); (void) FormatLocaleFile(file, "--------------------------------------------------------" "------------------------\n"); (void) FormatLocaleFile(file,"%6g %10s %10s %10s %10s %8g %8g %10s\n", (double) ((MagickOffsetType) resource_info.file_limit),area_limit, memory_limit,map_limit,disk_limit,(double) ((MagickOffsetType) resource_info.thread_limit),(double) ((MagickOffsetType) resource_info.throttle_limit),time_limit); (void) fflush(file); UnlockSemaphoreInfo(resource_semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % T h r o w E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ThrowException() throws an exception with the specified severity code, % reason, and optional description. % % The format of the ThrowException method is: % % MagickBooleanType ThrowException(ExceptionInfo *exception, % const ExceptionType severity,const char *reason, % const char *description) % % A description of each parameter follows: % % o exception: the exception info. % % o severity: the severity of the exception. % % o reason: the reason for the exception. % % o description: the exception description. % */ MagickExport MagickBooleanType ThrowException(ExceptionInfo *exception, const ExceptionType severity,const char *reason,const char *description) { register ExceptionInfo *p; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); LockSemaphoreInfo(exception->semaphore); p=(ExceptionInfo *) GetLastValueInLinkedList((LinkedListInfo *) exception->exceptions); if ((p != (ExceptionInfo *) NULL) && (p->severity == severity) && (LocaleCompare(exception->reason,reason) == 0) && (LocaleCompare(exception->description,description) == 0)) { UnlockSemaphoreInfo(exception->semaphore); return(MagickTrue); } p=(ExceptionInfo *) AcquireMagickMemory(sizeof(*p)); if (p == (ExceptionInfo *) NULL) { UnlockSemaphoreInfo(exception->semaphore); ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); } (void) ResetMagickMemory(p,0,sizeof(*p)); p->severity=severity; if (reason != (const char *) NULL) p->reason=ConstantString(reason); if (description != (const char *) NULL) p->description=ConstantString(description); p->signature=MagickSignature; (void) AppendValueToLinkedList((LinkedListInfo *) exception->exceptions,p); exception->severity=p->severity; exception->reason=p->reason; exception->description=p->description; UnlockSemaphoreInfo(exception->semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t M a g i c I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagicInfo() searches the magic list for the specified name and if found % returns attributes for that magic. % % The format of the GetMagicInfo method is: % % const MagicInfo *GetMagicInfo(const unsigned char *magic, % const size_t length,ExceptionInfo *exception) % % A description of each parameter follows: % % o magic: A binary string generally representing the first few characters % of the image file or blob. % % o length: the length of the binary signature. % % o exception: return any errors or warnings in this structure. % */ MagickExport const MagicInfo *GetMagicInfo(const unsigned char *magic, const size_t length,ExceptionInfo *exception) { register const MagicInfo *p; assert(exception != (ExceptionInfo *) NULL); if ((magic_list == (LinkedListInfo *) NULL) || (instantiate_magic == MagickFalse)) if (InitializeMagicList(exception) == MagickFalse) return((const MagicInfo *) NULL); if ((magic_list == (LinkedListInfo *) NULL) || (IsLinkedListEmpty(magic_list) != MagickFalse)) return((const MagicInfo *) NULL); if (magic == (const unsigned char *) NULL) return((const MagicInfo *) GetValueFromLinkedList(magic_list,0)); if (length == 0) return((const MagicInfo *) NULL); /* Search for magic tag. */ LockSemaphoreInfo(magic_semaphore); ResetLinkedListIterator(magic_list); p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); while (p != (const MagicInfo *) NULL) { assert(p->offset >= 0); if (((size_t) (p->offset+p->length) <= length) && (memcmp(magic+p->offset,p->magic,p->length) == 0)) break; p=(const MagicInfo *) GetNextValueInLinkedList(magic_list); } if (p != (const MagicInfo *) NULL) (void) InsertValueInLinkedList(magic_list,0, RemoveElementByValueFromLinkedList(magic_list,p)); UnlockSemaphoreInfo(magic_semaphore); return(p); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % D e s t r o y E x c e p t i o n I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % DestroyExceptionInfo() deallocates memory associated with an exception. % % The format of the DestroyExceptionInfo method is: % % ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) % % A description of each parameter follows: % % o exception: the exception info. % */ MagickExport ExceptionInfo *DestroyExceptionInfo(ExceptionInfo *exception) { MagickBooleanType relinquish; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); if (exception->semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&exception->semaphore); LockSemaphoreInfo(exception->semaphore); exception->severity=UndefinedException; if (exception->exceptions != (void *) NULL) exception->exceptions=(void *) DestroyLinkedList((LinkedListInfo *) exception->exceptions,DestroyExceptionElement); relinquish=exception->relinquish; if (exception->relinquish != MagickFalse) exception->signature=(~MagickSignature); UnlockSemaphoreInfo(exception->semaphore); DestroySemaphoreInfo(&exception->semaphore); if (relinquish != MagickFalse) exception=(ExceptionInfo *) RelinquishMagickMemory(exception); return(exception); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i n k e d L i s t T o A r r a y % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % LinkedListToArray() converts the linked-list to an array. % % The format of the LinkedListToArray method is: % % MagickBooleanType LinkedListToArray(LinkedListInfo *list_info, % void **array) % % A description of each parameter follows: % % o list_info: the linked-list info. % % o array: the array. % */ MagickExport MagickBooleanType LinkedListToArray(LinkedListInfo *list_info, void **array) { register ElementInfo *next; register ssize_t i; assert(list_info != (LinkedListInfo *) NULL); assert(list_info->signature == MagickCoreSignature); if (array == (void **) NULL) return(MagickFalse); LockSemaphoreInfo(list_info->semaphore); next=list_info->head; for (i=0; next != (ElementInfo *) NULL; i++) { array[i]=next->value; next=next->next; } UnlockSemaphoreInfo(list_info->semaphore); return(MagickTrue); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickInfo() returns a pointer MagickInfo structure that matches % the specified name. If name is NULL, the head of the image format list % is returned. It is not safe to traverse the list by using the previous and % next pointers in the MagickInfo structure since the list contents or order % may be altered while the list is being traversed. If the list must be % traversed, access it via the GetMagickInfoArray function instead. % % If GraphicsMagick has not been initialized via InitializeMagick() % then this function will not work. % % The format of the GetMagickInfo method is: % % const MagickInfo *GetMagickInfo(const char *name,ExceptionInfo *exception) % % A description of each parameter follows: % % o name: The image format we are looking for. % % o exception: Return any errors or warnings in this structure. % % */ static MagickInfo * GetMagickInfoEntryLocked(const char *name) { register MagickInfo *p; LockSemaphoreInfo(magick_semaphore); p=magick_list; if ((name != (const char *) NULL) && (name[0] != '*')) { for (p=magick_list; p != (MagickInfo *) NULL; p=p->next) if (LocaleCompare(p->name,name) == 0) break; if (p != (MagickInfo *) NULL) if (p != magick_list) { /* Self-adjusting list. */ if (p->previous != (MagickInfo *) NULL) p->previous->next=p->next; if (p->next != (MagickInfo *) NULL) p->next->previous=p->previous; p->previous=(MagickInfo *) NULL; p->next=magick_list; magick_list->previous=p; magick_list=p; } } UnlockSemaphoreInfo(magick_semaphore); return p; }
MagickExport void ClearMagickException(ExceptionInfo *exception) { register ExceptionInfo *p; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); if (exception->exceptions == (void *) NULL) return; LockSemaphoreInfo(exception->semaphore); p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *) exception->exceptions); while (p != (ExceptionInfo *) NULL) { (void) DestroyExceptionElement(p); p=(ExceptionInfo *) RemoveLastElementFromLinkedList((LinkedListInfo *) exception->exceptions); } exception->severity=UndefinedException; exception->reason=(char *) NULL; exception->description=(char *) NULL; UnlockSemaphoreInfo(exception->semaphore); errno=0; }
int HasError(ExceptionInfo *exception) { register const ExceptionInfo *p; int result = 0; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); if (exception->exceptions == (void *) NULL) return 0; if (exception->semaphore == (void *) NULL) return 0; LockSemaphoreInfo(exception->semaphore); ResetLinkedListIterator((LinkedListInfo *) exception->exceptions); p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) exception->exceptions); while (p != (const ExceptionInfo *) NULL) { if (p->severity >= ErrorException) result = 1; p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) exception->exceptions); } UnlockSemaphoreInfo(exception->semaphore); return result; }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % I n h e r i t E x c e p t i o n % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % InheritException() inherits an exception from a related exception. % % The format of the InheritException method is: % % InheritException(ExceptionInfo *exception,const ExceptionInfo *relative) % % A description of each parameter follows: % % o exception: the exception info. % % o relative: the related exception info. % */ MagickExport void InheritException(ExceptionInfo *exception, const ExceptionInfo *relative) { register const ExceptionInfo *p; assert(exception != (ExceptionInfo *) NULL); assert(exception->signature == MagickSignature); assert(relative != (ExceptionInfo *) NULL); assert(relative->signature == MagickSignature); if (relative->exceptions == (void *) NULL) return; LockSemaphoreInfo(relative->semaphore); ResetLinkedListIterator((LinkedListInfo *) relative->exceptions); p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) relative->exceptions); while (p != (const ExceptionInfo *) NULL) { (void) ThrowException(exception,p->severity,p->reason,p->description); p=(const ExceptionInfo *) GetNextValueInLinkedList((LinkedListInfo *) relative->exceptions); } UnlockSemaphoreInfo(relative->semaphore); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t V a l u e F r o m L i n k e d L i s t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetValueFromLinkedList() gets a value from the linked-list at the specified % location. % % The format of the GetValueFromLinkedList method is: % % void *GetValueFromLinkedList(LinkedListInfo *list_info, % const size_t index) % % A description of each parameter follows: % % o list_info: the linked_list info. % % o index: the list index. % */ MagickExport void *GetValueFromLinkedList(LinkedListInfo *list_info, const size_t index) { register ElementInfo *next; register ssize_t i; void *value; assert(list_info != (LinkedListInfo *) NULL); assert(list_info->signature == MagickCoreSignature); if (index >= list_info->elements) return((void *) NULL); LockSemaphoreInfo(list_info->semaphore); if (index == 0) { value=list_info->head->value; UnlockSemaphoreInfo(list_info->semaphore); return(value); } if (index == (list_info->elements-1)) { value=list_info->tail->value; UnlockSemaphoreInfo(list_info->semaphore); return(value); } next=list_info->head; for (i=0; i < (ssize_t) index; i++) next=next->next; value=next->value; UnlockSemaphoreInfo(list_info->semaphore); return(value); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h U n i q u e F i l e R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishUniqueFileResource() relinquishes a unique file resource. % % The format of the RelinquishUniqueFileResource() method is: % % MagickBooleanType RelinquishUniqueFileResource(const char *path) % % A description of each parameter follows: % % o name: the name of the temporary resource. % */ MagickExport MagickBooleanType RelinquishUniqueFileResource(const char *path) { char cache_path[MagickPathExtent]; MagickBooleanType status; assert(path != (const char *) NULL); status=MagickFalse; (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); if (temporary_resources != (SplayTreeInfo *) NULL) status=DeleteNodeFromSplayTree(temporary_resources, (const void *) path); UnlockSemaphoreInfo(resource_semaphore); (void) CopyMagickString(cache_path,path,MagickPathExtent); AppendImageFormat("cache",cache_path); (void) ShredFile(cache_path); if (status == MagickFalse) status=ShredFile(path); return(status); }
static MagickBooleanType InitializeTypeList(ExceptionInfo *exception) { if ((type_list == (SplayTreeInfo *) NULL) && (instantiate_type == MagickFalse)) { if (type_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&type_semaphore); LockSemaphoreInfo(type_semaphore); if ((type_list == (SplayTreeInfo *) NULL) && (instantiate_type == MagickFalse)) { (void) LoadTypeLists(MagickTypeFilename,exception); #if defined(MAGICKCORE_WINDOWS_SUPPORT) (void) NTLoadTypeLists(type_list,exception); #endif #if defined(MAGICKCORE_FONTCONFIG_DELEGATE) (void) LoadFontConfigFonts(type_list,exception); #endif instantiate_type=MagickTrue; } UnlockSemaphoreInfo(type_semaphore); } return(type_list != (SplayTreeInfo *) NULL ? MagickTrue : MagickFalse); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % A c q u i r e M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % AcquireMagickResource() acquires resources of the specified type. % MagickFalse is returned if the specified resource is exhausted otherwise % MagickTrue. % % The format of the AcquireMagickResource() method is: % % MagickBooleanType AcquireMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: the type of resource. % % o size: the number of bytes needed from for this resource. % */ MagickExport MagickBooleanType AcquireMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MaxTextExtent], resource_limit[MaxTextExtent], resource_request[MaxTextExtent]; MagickBooleanType status; MagickSizeType limit; status=MagickFalse; (void) FormatMagickSize(size,MagickFalse,resource_request); if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case AreaResource: { resource_info.area=(MagickOffsetType) size; limit=resource_info.area_limit; status=(resource_info.area_limit == MagickResourceInfinity) || (size < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse, resource_current); (void) FormatMagickSize(resource_info.area_limit,MagickFalse, resource_limit); break; } case MemoryResource: { resource_info.memory+=size; limit=resource_info.memory_limit; status=(resource_info.memory_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.memory < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.memory,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue, resource_limit); break; } case MapResource: { resource_info.map+=size; limit=resource_info.map_limit; status=(resource_info.map_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.map < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.map_limit,MagickTrue, resource_limit); break; } case DiskResource: { resource_info.disk+=size; limit=resource_info.disk_limit; status=(resource_info.disk_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.disk < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.disk_limit,MagickTrue, resource_limit); break; } case FileResource: { resource_info.file+=size; limit=resource_info.file_limit; status=(resource_info.file_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.file < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, MagickFalse,resource_limit); break; } case ThreadResource: { limit=resource_info.thread_limit; status=(resource_info.thread_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.thread < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit, MagickFalse,resource_limit); break; } case TimeResource: { resource_info.time+=size; limit=resource_info.time_limit; status=(resource_info.time_limit == MagickResourceInfinity) || ((MagickSizeType) resource_info.time < limit) ? MagickTrue : MagickFalse; (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.time_limit, MagickFalse,resource_limit); break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type), resource_request,resource_current,resource_limit); return(status); }
MagickExport MagickBooleanType SetMagickResourceLimit(const ResourceType type, const MagickSizeType limit) { char *value; if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); value=(char *) NULL; switch (type) { case AreaResource: { resource_info.area_limit=limit; value=GetPolicyValue("area"); if (value != (char *) NULL) resource_info.area_limit=MagickMin(limit,StringToSizeType(value,100.0)); break; } case MemoryResource: { resource_info.memory_limit=limit; value=GetPolicyValue("memory"); if (value != (char *) NULL) resource_info.memory_limit=MagickMin(limit,StringToSizeType(value, 100.0)); break; } case MapResource: { resource_info.map_limit=limit; value=GetPolicyValue("map"); if (value != (char *) NULL) resource_info.map_limit=MagickMin(limit,StringToSizeType(value,100.0)); break; } case DiskResource: { resource_info.disk_limit=limit; value=GetPolicyValue("disk"); if (value != (char *) NULL) resource_info.disk_limit=MagickMin(limit,StringToSizeType(value,100.0)); break; } case FileResource: { resource_info.file_limit=limit; value=GetPolicyValue("file"); if (value != (char *) NULL) resource_info.file_limit=MagickMin(limit,StringToSizeType(value,100.0)); break; } case ThreadResource: { resource_info.thread_limit=limit; value=GetPolicyValue("thread"); if (value != (char *) NULL) resource_info.thread_limit=MagickMin(limit,StringToSizeType(value, 100.0)); if (resource_info.thread_limit > GetOpenMPMaximumThreads()) resource_info.thread_limit=GetOpenMPMaximumThreads(); break; } case TimeResource: { resource_info.time_limit=limit; value=GetPolicyValue("time"); if (value != (char *) NULL) resource_info.time_limit=MagickMin(limit,StringToSizeType(value,100.0)); break; } default: break; } if (value != (char *) NULL) value=DestroyString(value); UnlockSemaphoreInfo(resource_semaphore); return(MagickTrue); }
MagickExport MagickBooleanType SetImageRegistry(const RegistryType type, const char *key,const void *value,ExceptionInfo *exception) { MagickBooleanType status; RegistryInfo *registry_info; void *clone_value; if (IsEventLogging() != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s",key); clone_value=(void *) NULL; switch (type) { case StringRegistryType: default: { const char *string; string=(const char *) value; clone_value=(void *) ConstantString(string); break; } case ImageRegistryType: { const Image *image; image=(const Image *) value; if (image->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageList(image,exception); break; } case ImageInfoRegistryType: { const ImageInfo *image_info; image_info=(const ImageInfo *) value; if (image_info->signature != MagickSignature) { (void) ThrowMagickException(exception,GetMagickModule(),RegistryError, "UnableToSetRegistry","%s",key); return(MagickFalse); } clone_value=(void *) CloneImageInfo(image_info); break; } } if (clone_value == (void *) NULL) return(MagickFalse); registry_info=(RegistryInfo *) AcquireMagickMemory(sizeof(*registry_info)); if (registry_info == (RegistryInfo *) NULL) ThrowFatalException(ResourceLimitFatalError,"MemoryAllocationFailed"); (void) ResetMagickMemory(registry_info,0,sizeof(*registry_info)); registry_info->type=type; registry_info->value=clone_value; registry_info->signature=MagickSignature; if ((registry == (SplayTreeInfo *) NULL) && (instantiate_registry == MagickFalse)) { if (registry_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(®istry_semaphore); LockSemaphoreInfo(registry_semaphore); if ((registry == (SplayTreeInfo *) NULL) && (instantiate_registry == MagickFalse)) { registry=NewSplayTree(CompareSplayTreeString,RelinquishMagickMemory, DestroyRegistryNode); instantiate_registry=MagickTrue; } UnlockSemaphoreInfo(registry_semaphore); } status=AddValueToSplayTree(registry,ConstantString(key),registry_info); return(status); }
MagickExport const TypeInfo *GetTypeInfoByFamily(const char *family, const StyleType style,const StretchType stretch,const size_t weight, ExceptionInfo *exception) { typedef struct _Fontmap { const char *name, *substitute; } Fontmap; const TypeInfo *type_info; register const TypeInfo *p; register ssize_t i; ssize_t range; static const Fontmap fontmap[] = { { "fixed", "courier" }, { "modern","courier" }, { "monotype corsiva", "courier" }, { "news gothic", "helvetica" }, { "system", "courier" }, { "terminal", "courier" }, { "wingdings", "symbol" }, { NULL, NULL } }; size_t max_score, score; /* Check for an exact type match. */ (void) GetTypeInfo("*",exception); if (type_list == (SplayTreeInfo *) NULL) return((TypeInfo *) NULL); LockSemaphoreInfo(type_semaphore); ResetSplayTreeIterator(type_list); type_info=(const TypeInfo *) NULL; p=(const TypeInfo *) GetNextValueInSplayTree(type_list); while (p != (const TypeInfo *) NULL) { if (p->family == (char *) NULL) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } if (family == (const char *) NULL) { if ((LocaleCompare(p->family,"arial") != 0) && (LocaleCompare(p->family,"helvetica") != 0)) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } } else if (LocaleCompare(p->family,family) != 0) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } if ((style != UndefinedStyle) && (style != AnyStyle) && (p->style != style)) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } if ((stretch != UndefinedStretch) && (stretch != AnyStretch) && (p->stretch != stretch)) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } if ((weight != 0) && (p->weight != weight)) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } type_info=p; break; } UnlockSemaphoreInfo(type_semaphore); if (type_info != (const TypeInfo *) NULL) return(type_info); /* Check for types in the same family. */ max_score=0; LockSemaphoreInfo(type_semaphore); ResetSplayTreeIterator(type_list); p=(const TypeInfo *) GetNextValueInSplayTree(type_list); while (p != (const TypeInfo *) NULL) { if (p->family == (char *) NULL) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } if (family == (const char *) NULL) { if ((LocaleCompare(p->family,"arial") != 0) && (LocaleCompare(p->family,"helvetica") != 0)) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } } else if (LocaleCompare(p->family,family) != 0) { p=(const TypeInfo *) GetNextValueInSplayTree(type_list); continue; } score=0; if ((style == UndefinedStyle) || (style == AnyStyle) || (p->style == style)) score+=32; else if (((style == ItalicStyle) || (style == ObliqueStyle)) && ((p->style == ItalicStyle) || (p->style == ObliqueStyle))) score+=25; if (weight == 0) score+=16; else score+=(16*(800-((ssize_t) MagickMax(MagickMin(weight,900),p->weight)- (ssize_t) MagickMin(MagickMin(weight,900),p->weight))))/800; if ((stretch == UndefinedStretch) || (stretch == AnyStretch)) score+=8; else { range=(ssize_t) UltraExpandedStretch-(ssize_t) NormalStretch; score+=(8*(range-((ssize_t) MagickMax(stretch,p->stretch)- (ssize_t) MagickMin(stretch,p->stretch))))/range; } if (score > max_score) { max_score=score; type_info=p; } p=(const TypeInfo *) GetNextValueInSplayTree(type_list); } UnlockSemaphoreInfo(type_semaphore); if (type_info != (const TypeInfo *) NULL) return(type_info); /* Check for table-based substitution match. */ for (i=0; fontmap[i].name != (char *) NULL; i++) { if (family == (const char *) NULL) { if ((LocaleCompare(fontmap[i].name,"arial") != 0) && (LocaleCompare(fontmap[i].name,"helvetica") != 0)) continue; } else if (LocaleCompare(fontmap[i].name,family) != 0) continue; type_info=GetTypeInfoByFamily(fontmap[i].substitute,style,stretch,weight, exception); break; } if (type_info != (const TypeInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(),TypeError, "FontSubstitutionRequired","`%s'",type_info->family); return(type_info); } if (family != (const char *) NULL) type_info=GetTypeInfoByFamily((const char *) NULL,style,stretch,weight, exception); return(type_info); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % W r i t e I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % WriteImage() writes an image or an image sequence to a file or file handle. % If writing to a file is on disk, the name is defined by the filename member % of the image structure. WriteImage() returns MagickFalse is there is a % memory shortage or if the image cannot be written. Check the exception % member of image to determine the cause for any failure. % % The format of the WriteImage method is: % % MagickBooleanType WriteImage(const ImageInfo *image_info,Image *image, % ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: the image info. % % o image: the image. % % o exception: return any errors or warnings in this structure. % */ MagickExport MagickBooleanType WriteImage(const ImageInfo *image_info, Image *image,ExceptionInfo *exception) { char filename[MaxTextExtent]; const char *option; const DelegateInfo *delegate_info; const MagickInfo *magick_info; ExceptionInfo *sans_exception; ImageInfo *write_info; MagickBooleanType status, temporary; MagickStatusType thread_support; PolicyDomain domain; PolicyRights rights; /* Determine image type from filename prefix or suffix (e.g. image.jpg). */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); if (image->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(image != (Image *) NULL); assert(image->signature == MagickSignature); assert(exception != (ExceptionInfo *) NULL); sans_exception=AcquireExceptionInfo(); write_info=CloneImageInfo(image_info); (void) CopyMagickString(write_info->filename,image->filename,MaxTextExtent); if (*write_info->magick == '\0') (void) CopyMagickString(write_info->magick,image->magick,MaxTextExtent); (void) SetImageInfo(write_info,1,sans_exception); if (LocaleCompare(write_info->magick,"clipmask") == 0) { if (image->clip_mask == (Image *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), OptionError,"NoClipPathDefined","`%s'",image->filename); return(MagickFalse); } image=image->clip_mask; (void) SetImageInfo(write_info,1,sans_exception); } (void) CopyMagickString(filename,image->filename,MaxTextExtent); (void) CopyMagickString(image->filename,write_info->filename,MaxTextExtent); domain=CoderPolicyDomain; rights=WritePolicyRights; if (IsRightsAuthorized(domain,rights,write_info->magick) == MagickFalse) { sans_exception=DestroyExceptionInfo(sans_exception); errno=EPERM; ThrowBinaryException(PolicyError,"NotAuthorized",filename); } magick_info=GetMagickInfo(write_info->magick,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (magick_info != (const MagickInfo *) NULL) { if (GetMagickEndianSupport(magick_info) == MagickFalse) image->endian=UndefinedEndian; else if ((image_info->endian == UndefinedEndian) && (GetMagickRawSupport(magick_info) != MagickFalse)) { size_t lsb_first; lsb_first=1; image->endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian; } } (void) SyncImageProfiles(image); option=GetImageOption(image_info,"delegate:bimodal"); if ((option != (const char *) NULL) && (IsMagickTrue(option) != MagickFalse) && (write_info->page == (char *) NULL) && (GetPreviousImageInList(image) == (Image *) NULL) && (GetNextImageInList(image) == (Image *) NULL) && (IsTaintImage(image) == MagickFalse)) { delegate_info=GetDelegateInfo(image->magick,write_info->magick,exception); if ((delegate_info != (const DelegateInfo *) NULL) && (GetDelegateMode(delegate_info) == 0) && (IsPathAccessible(image->magick_filename) != MagickFalse)) { /* Process image with bi-modal delegate. */ (void) CopyMagickString(image->filename,image->magick_filename, MaxTextExtent); status=InvokeDelegate(write_info,image,image->magick, write_info->magick,exception); write_info=DestroyImageInfo(write_info); (void) CopyMagickString(image->filename,filename,MaxTextExtent); return(status); } } status=MagickFalse; temporary=MagickFalse; if ((magick_info != (const MagickInfo *) NULL) && (GetMagickSeekableStream(magick_info) != MagickFalse)) { char filename[MaxTextExtent]; (void) CopyMagickString(filename,image->filename,MaxTextExtent); status=OpenBlob(image_info,image,WriteBinaryBlobMode,exception); (void) CopyMagickString(image->filename,filename,MaxTextExtent); if (status != MagickFalse) { if (IsBlobSeekable(image) == MagickFalse) { /* A seekable stream is required by the encoder. */ write_info->adjoin=MagickTrue; (void) CopyMagickString(write_info->filename,image->filename, MaxTextExtent); (void) AcquireUniqueFilename(image->filename); temporary=MagickTrue; } (void) CloseBlob(image); } } if (constitute_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&constitute_semaphore); if ((magick_info != (const MagickInfo *) NULL) && (GetImageEncoder(magick_info) != (EncodeImageHandler *) NULL)) { /* Call appropriate image writer based on image type. */ thread_support=GetMagickThreadSupport(magick_info); if ((thread_support & EncoderThreadSupport) == 0) LockSemaphoreInfo(constitute_semaphore); status=GetImageEncoder(magick_info)(write_info,image,exception); if ((thread_support & EncoderThreadSupport) == 0) UnlockSemaphoreInfo(constitute_semaphore); } else { delegate_info=GetDelegateInfo((char *) NULL,write_info->magick,exception); if (delegate_info != (DelegateInfo *) NULL) { /* Process the image with delegate. */ *write_info->filename='\0'; if (GetDelegateThreadSupport(delegate_info) == MagickFalse) LockSemaphoreInfo(constitute_semaphore); status=InvokeDelegate(write_info,image,(char *) NULL, write_info->magick,exception); if (GetDelegateThreadSupport(delegate_info) == MagickFalse) UnlockSemaphoreInfo(constitute_semaphore); (void) CopyMagickString(image->filename,filename,MaxTextExtent); } else { sans_exception=AcquireExceptionInfo(); magick_info=GetMagickInfo(write_info->magick,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if ((write_info->affirm == MagickFalse) && (magick_info == (const MagickInfo *) NULL)) { (void) CopyMagickString(write_info->magick,image->magick, MaxTextExtent); magick_info=GetMagickInfo(write_info->magick,exception); } if ((magick_info == (const MagickInfo *) NULL) || (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL)) { char extension[MaxTextExtent]; GetPathComponent(image->filename,ExtensionPath,extension); if (*extension != '\0') magick_info=GetMagickInfo(extension,exception); else magick_info=GetMagickInfo(image->magick,exception); (void) CopyMagickString(image->filename,filename,MaxTextExtent); } if ((magick_info == (const MagickInfo *) NULL) || (GetImageEncoder(magick_info) == (EncodeImageHandler *) NULL)) (void) ThrowMagickException(exception,GetMagickModule(), MissingDelegateError,"NoEncodeDelegateForThisImageFormat","`%s'", image->filename); else { /* Call appropriate image writer based on image type. */ thread_support=GetMagickThreadSupport(magick_info); if ((thread_support & EncoderThreadSupport) == 0) LockSemaphoreInfo(constitute_semaphore); status=GetImageEncoder(magick_info)(write_info,image,exception); if ((thread_support & EncoderThreadSupport) == 0) UnlockSemaphoreInfo(constitute_semaphore); } } } if (GetBlobError(image) != MagickFalse) ThrowFileException(exception,FileOpenError, "AnErrorHasOccurredWritingToFile",image->filename); if (temporary == MagickTrue) { /* Copy temporary image file to permanent. */ status=OpenBlob(write_info,image,ReadBinaryBlobMode,exception); if (status != MagickFalse) status=ImageToFile(image,write_info->filename,exception); (void) CloseBlob(image); (void) RelinquishUniqueFileResource(image->filename); (void) CopyMagickString(image->filename,write_info->filename, MaxTextExtent); } if ((LocaleCompare(write_info->magick,"info") != 0) && (write_info->verbose != MagickFalse)) (void) IdentifyImage(image,stdout,MagickFalse,exception); write_info=DestroyImageInfo(write_info); return(status); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e a d I m a g e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % ReadImage() reads an image or image sequence from a file or file handle. % The method returns a NULL if there is a memory shortage or if the image % cannot be read. On failure, a NULL image is returned and exception % describes the reason for the failure. % % The format of the ReadImage method is: % % Image *ReadImage(const ImageInfo *image_info,ExceptionInfo *exception) % % A description of each parameter follows: % % o image_info: Read the image defined by the file or filename members of % this structure. % % o exception: return any errors or warnings in this structure. % */ MagickExport Image *ReadImage(const ImageInfo *image_info, ExceptionInfo *exception) { char filename[MaxTextExtent], magick[MaxTextExtent], magick_filename[MaxTextExtent]; const char *value; const DelegateInfo *delegate_info; const MagickInfo *magick_info; ExceptionInfo *sans_exception; GeometryInfo geometry_info; Image *image, *next; ImageInfo *read_info; MagickStatusType flags, thread_support; PolicyDomain domain; PolicyRights rights; /* Determine image type from filename prefix or suffix (e.g. image.jpg). */ assert(image_info != (ImageInfo *) NULL); assert(image_info->signature == MagickSignature); assert(image_info->filename != (char *) NULL); if (image_info->debug != MagickFalse) (void) LogMagickEvent(TraceEvent,GetMagickModule(),"%s", image_info->filename); assert(exception != (ExceptionInfo *) NULL); read_info=CloneImageInfo(image_info); (void) CopyMagickString(magick_filename,read_info->filename,MaxTextExtent); (void) SetImageInfo(read_info,0,exception); (void) CopyMagickString(filename,read_info->filename,MaxTextExtent); (void) CopyMagickString(magick,read_info->magick,MaxTextExtent); domain=CoderPolicyDomain; rights=ReadPolicyRights; if (IsRightsAuthorized(domain,rights,read_info->magick) == MagickFalse) { errno=EPERM; (void) ThrowMagickException(exception,GetMagickModule(),PolicyError, "NotAuthorized","`%s'",read_info->filename); return((Image *) NULL); } /* Call appropriate image reader based on image type. */ sans_exception=AcquireExceptionInfo(); magick_info=GetMagickInfo(read_info->magick,sans_exception); sans_exception=DestroyExceptionInfo(sans_exception); if (magick_info != (const MagickInfo *) NULL) { if (GetMagickEndianSupport(magick_info) == MagickFalse) read_info->endian=UndefinedEndian; else if ((image_info->endian == UndefinedEndian) && (GetMagickRawSupport(magick_info) != MagickFalse)) { size_t lsb_first; lsb_first=1; read_info->endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian; } } if ((magick_info != (const MagickInfo *) NULL) && (GetMagickSeekableStream(magick_info) != MagickFalse)) { MagickBooleanType status; image=AcquireImage(read_info,exception); (void) CopyMagickString(image->filename,read_info->filename, MaxTextExtent); status=OpenBlob(image_info,image,ReadBinaryBlobMode,exception); if (status == MagickFalse) { read_info=DestroyImageInfo(read_info); image=DestroyImage(image); return((Image *) NULL); } if (IsBlobSeekable(image) == MagickFalse) { /* Coder requires a seekable stream. */ *read_info->filename='\0'; status=ImageToFile(image,read_info->filename,exception); if (status == MagickFalse) { (void) CloseBlob(image); read_info=DestroyImageInfo(read_info); image=DestroyImage(image); return((Image *) NULL); } read_info->temporary=MagickTrue; } (void) CloseBlob(image); image=DestroyImage(image); } image=NewImageList(); if (constitute_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&constitute_semaphore); if ((magick_info != (const MagickInfo *) NULL) && (GetImageDecoder(magick_info) != (DecodeImageHandler *) NULL)) { thread_support=GetMagickThreadSupport(magick_info); if ((thread_support & DecoderThreadSupport) == 0) LockSemaphoreInfo(constitute_semaphore); image=GetImageDecoder(magick_info)(read_info,exception); if ((thread_support & DecoderThreadSupport) == 0) UnlockSemaphoreInfo(constitute_semaphore); } else { delegate_info=GetDelegateInfo(read_info->magick,(char *) NULL,exception); if (delegate_info == (const DelegateInfo *) NULL) { (void) ThrowMagickException(exception,GetMagickModule(), MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'", read_info->filename); if (read_info->temporary != MagickFalse) (void) RelinquishUniqueFileResource(read_info->filename); read_info=DestroyImageInfo(read_info); return((Image *) NULL); } /* Let our decoding delegate process the image. */ image=AcquireImage(read_info,exception); if (image == (Image *) NULL) { read_info=DestroyImageInfo(read_info); return((Image *) NULL); } (void) CopyMagickString(image->filename,read_info->filename, MaxTextExtent); *read_info->filename='\0'; if (GetDelegateThreadSupport(delegate_info) == MagickFalse) LockSemaphoreInfo(constitute_semaphore); (void) InvokeDelegate(read_info,image,read_info->magick,(char *) NULL, exception); if (GetDelegateThreadSupport(delegate_info) == MagickFalse) UnlockSemaphoreInfo(constitute_semaphore); image=DestroyImageList(image); read_info->temporary=MagickTrue; (void) SetImageInfo(read_info,0,exception); magick_info=GetMagickInfo(read_info->magick,exception); if ((magick_info == (const MagickInfo *) NULL) || (GetImageDecoder(magick_info) == (DecodeImageHandler *) NULL)) { if (IsPathAccessible(read_info->filename) != MagickFalse) (void) ThrowMagickException(exception,GetMagickModule(), MissingDelegateError,"NoDecodeDelegateForThisImageFormat","`%s'", read_info->filename); else ThrowFileException(exception,FileOpenError,"UnableToOpenFile", read_info->filename); read_info=DestroyImageInfo(read_info); return((Image *) NULL); } thread_support=GetMagickThreadSupport(magick_info); if ((thread_support & DecoderThreadSupport) == 0) LockSemaphoreInfo(constitute_semaphore); image=(Image *) (GetImageDecoder(magick_info))(read_info,exception); if ((thread_support & DecoderThreadSupport) == 0) UnlockSemaphoreInfo(constitute_semaphore); } if (read_info->temporary != MagickFalse) { (void) RelinquishUniqueFileResource(read_info->filename); read_info->temporary=MagickFalse; if (image != (Image *) NULL) (void) CopyMagickString(image->filename,filename,MaxTextExtent); } if (image == (Image *) NULL) { read_info=DestroyImageInfo(read_info); return(image); } if (exception->severity >= ErrorException) (void) LogMagickEvent(ExceptionEvent,GetMagickModule(), "Coder (%s) generated an image despite an error (%d), " "notify the developers",image->magick,exception->severity); if (IsBlobTemporary(image) != MagickFalse) (void) RelinquishUniqueFileResource(read_info->filename); if ((GetNextImageInList(image) != (Image *) NULL) && (IsSceneGeometry(read_info->scenes,MagickFalse) != MagickFalse)) { Image *clones; clones=CloneImages(image,read_info->scenes,exception); if (clones == (Image *) NULL) (void) ThrowMagickException(exception,GetMagickModule(),OptionError, "SubimageSpecificationReturnsNoImages","`%s'",read_info->filename); else { image=DestroyImageList(image); image=GetFirstImageInList(clones); } } if (GetBlobError(image) != MagickFalse) { ThrowFileException(exception,FileOpenError, "AnErrorHasOccurredReadingFromFile",read_info->filename); image=DestroyImageList(image); read_info=DestroyImageInfo(read_info); return((Image *) NULL); } for (next=image; next != (Image *) NULL; next=GetNextImageInList(next)) { char magick_path[MaxTextExtent], *property, timestamp[MaxTextExtent]; const char *option; const StringInfo *profile; next->taint=MagickFalse; GetPathComponent(magick_filename,MagickPath,magick_path); if (*magick_path == '\0') (void) CopyMagickString(next->magick,magick,MaxTextExtent); (void) CopyMagickString(next->magick_filename,magick_filename, MaxTextExtent); if (IsBlobTemporary(image) != MagickFalse) (void) CopyMagickString(next->filename,filename,MaxTextExtent); if (next->magick_columns == 0) next->magick_columns=next->columns; if (next->magick_rows == 0) next->magick_rows=next->rows; value=GetImageProperty(next,"tiff:Orientation",exception); if (value == (char *) NULL) value=GetImageProperty(next,"exif:Orientation",exception); if (value != (char *) NULL) { next->orientation=(OrientationType) StringToLong(value); (void) DeleteImageProperty(next,"tiff:Orientation"); (void) DeleteImageProperty(next,"exif:Orientation"); } value=GetImageProperty(next,"exif:XResolution",exception); if (value != (char *) NULL) { geometry_info.rho=next->resolution.x; geometry_info.sigma=1.0; flags=ParseGeometry(value,&geometry_info); if (geometry_info.sigma != 0) next->resolution.x=geometry_info.rho/geometry_info.sigma; (void) DeleteImageProperty(next,"exif:XResolution"); } value=GetImageProperty(next,"exif:YResolution",exception); if (value != (char *) NULL) { geometry_info.rho=next->resolution.y; geometry_info.sigma=1.0; flags=ParseGeometry(value,&geometry_info); if (geometry_info.sigma != 0) next->resolution.y=geometry_info.rho/geometry_info.sigma; (void) DeleteImageProperty(next,"exif:YResolution"); } value=GetImageProperty(next,"tiff:ResolutionUnit",exception); if (value == (char *) NULL) value=GetImageProperty(next,"exif:ResolutionUnit",exception); if (value != (char *) NULL) { next->units=(ResolutionType) (StringToLong(value)-1); (void) DeleteImageProperty(next,"exif:ResolutionUnit"); (void) DeleteImageProperty(next,"tiff:ResolutionUnit"); } if (next->page.width == 0) next->page.width=next->columns; if (next->page.height == 0) next->page.height=next->rows; option=GetImageOption(read_info,"caption"); if (option != (const char *) NULL) { property=InterpretImageProperties(read_info,next,option,exception); (void) SetImageProperty(next,"caption",property,exception); property=DestroyString(property); } option=GetImageOption(read_info,"comment"); if (option != (const char *) NULL) { property=InterpretImageProperties(read_info,next,option,exception); (void) SetImageProperty(next,"comment",property,exception); property=DestroyString(property); } option=GetImageOption(read_info,"label"); if (option != (const char *) NULL) { property=InterpretImageProperties(read_info,next,option,exception); (void) SetImageProperty(next,"label",property,exception); property=DestroyString(property); } if (LocaleCompare(next->magick,"TEXT") == 0) (void) ParseAbsoluteGeometry("0x0+0+0",&next->page); if ((read_info->extract != (char *) NULL) && (read_info->stream == (StreamHandler) NULL)) { RectangleInfo geometry; flags=ParseAbsoluteGeometry(read_info->extract,&geometry); if ((next->columns != geometry.width) || (next->rows != geometry.height)) { if (((flags & XValue) != 0) || ((flags & YValue) != 0)) { Image *crop_image; crop_image=CropImage(next,&geometry,exception); if (crop_image != (Image *) NULL) ReplaceImageInList(&next,crop_image); } else if (((flags & WidthValue) != 0) || ((flags & HeightValue) != 0)) { Image *size_image; flags=ParseRegionGeometry(next,read_info->extract,&geometry, exception); size_image=ResizeImage(next,geometry.width,geometry.height, next->filter,next->blur,exception); if (size_image != (Image *) NULL) ReplaceImageInList(&next,size_image); } } } profile=GetImageProfile(next,"icc"); if (profile == (const StringInfo *) NULL) profile=GetImageProfile(next,"icm"); profile=GetImageProfile(next,"iptc"); if (profile == (const StringInfo *) NULL) profile=GetImageProfile(next,"8bim"); (void) FormatMagickTime(GetBlobProperties(next)->st_mtime,MaxTextExtent, timestamp); (void) SetImageProperty(next,"date:modify",timestamp,exception); (void) FormatMagickTime(GetBlobProperties(next)->st_ctime,MaxTextExtent, timestamp); (void) SetImageProperty(next,"date:create",timestamp,exception); option=GetImageOption(image_info,"delay"); if (option != (const char *) NULL) { GeometryInfo geometry_info; flags=ParseGeometry(option,&geometry_info); if ((flags & GreaterValue) != 0) { if (next->delay > (size_t) floor(geometry_info.rho+0.5)) next->delay=(size_t) floor(geometry_info.rho+0.5); } else if ((flags & LessValue) != 0) { if (next->delay < (size_t) floor(geometry_info.rho+0.5)) next->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); } else next->delay=(size_t) floor(geometry_info.rho+0.5); if ((flags & SigmaValue) != 0) next->ticks_per_second=(ssize_t) floor(geometry_info.sigma+0.5); } option=GetImageOption(image_info,"dispose"); if (option != (const char *) NULL) next->dispose=(DisposeType) ParseCommandOption(MagickDisposeOptions, MagickFalse,option); if (read_info->verbose != MagickFalse) (void) IdentifyImage(next,stderr,MagickFalse,exception); image=next; } read_info=DestroyImageInfo(read_info); return(GetFirstImageInList(image)); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t D e l e g a t e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method GetDelegateInfo returns any delegates associated with the specified % tag. % % The format of the GetDelegateInfo method is: % % const DelegateInfo *GetDelegateInfo(const char *decode, % const char *encode,ExceptionInfo *exception) % % A description of each parameter follows: % % o delgate_info: Method GetDelegateInfo returns any delegates associated % with the specified tag. % % o decode: Specifies the decode delegate we are searching for as a % character string. % % o encode: Specifies the encode delegate we are searching for as a % character string. % % o exception: Return any errors or warnings in this structure. % % */ MagickExport const DelegateInfo *GetDelegateInfo(const char *decode, const char *encode,ExceptionInfo *exception) { register DelegateInfo *p; if (delegate_list == (DelegateInfo *) NULL) { LockSemaphoreInfo(delegate_semaphore); if (delegate_list == (DelegateInfo *) NULL) (void) ReadConfigureFile(DelegateFilename,0,exception); UnlockSemaphoreInfo(delegate_semaphore); } if ((LocaleCompare(decode,"*") == 0) && (LocaleCompare(encode,"*") == 0)) return((const DelegateInfo *) delegate_list); /* Search for requested delegate. */ LockSemaphoreInfo(delegate_semaphore); for (p=delegate_list; p != (const DelegateInfo *) NULL; p=p->next) { if (p->mode > 0) { if (LocaleCompare(p->decode,decode) == 0) break; continue; } if (p->mode < 0) { if (LocaleCompare(p->encode,encode) == 0) break; continue; } if (LocaleCompare(decode,p->decode) == 0) if (LocaleCompare(encode,p->encode) == 0) break; if (LocaleCompare(decode,"*") == 0) if (LocaleCompare(encode,p->encode) == 0) break; if (LocaleCompare(decode,p->decode) == 0) if (LocaleCompare(encode,"*") == 0) break; } if (p != (DelegateInfo *) NULL) if (p != delegate_list) { /* Self-adjusting list. */ if (p->previous != (DelegateInfo *) NULL) p->previous->next=p->next; if (p->next != (DelegateInfo *) NULL) p->next->previous=p->previous; p->previous=(DelegateInfo *) NULL; p->next=delegate_list; delegate_list->previous=p; delegate_list=p; } UnlockSemaphoreInfo(delegate_semaphore); return((const DelegateInfo *) p); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % L i s t D e l e g a t e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % Method ListDelegateInfo lists the image formats to a file. % % The format of the ListDelegateInfo method is: % % unsigned int ListDelegateInfo(FILE *file,ExceptionInfo *exception) % % A description of each parameter follows. % % o file: An pointer to a FILE. % % o exception: Return any errors or warnings in this structure. % % */ MagickExport unsigned int ListDelegateInfo(FILE *file,ExceptionInfo *exception) { char **commands, delegate[MaxTextExtent]; register long i; register const DelegateInfo *p; if (file == (const FILE *) NULL) file=stdout; (void) GetDelegateInfo("*","*",exception); LockSemaphoreInfo(delegate_semaphore); for (p=delegate_list; p != (const DelegateInfo *) NULL; p=p->next) { if ((p->previous == (DelegateInfo *) NULL) || (LocaleCompare(p->path,p->previous->path) != 0)) { if (p->previous != (DelegateInfo *) NULL) (void) fprintf(file,"\n"); if (p->path != (char *) NULL) (void) fprintf(file,"Path: %.1024s\n\n",p->path); (void) fprintf(file,"Delegate Command\n"); (void) fprintf(file,"-------------------------------------------------" "------------------------------\n"); } if (p->stealth) continue; *delegate='\0'; if (p->encode != (char *) NULL) (void) strlcpy(delegate,p->encode,MaxTextExtent); (void) strcat(delegate," "); delegate[8]='\0'; commands=StringToList(p->commands); if (commands == (char **) NULL) continue; { int command_start_column, command_length, formatted_chars=0, length=0, screen_width=79, strip_length; char *s; /* Format output so that command spans multiple lines if necessary */ if (getenv("COLUMNS")) screen_width=atoi(getenv("COLUMNS"))-1; command_length=strlen(commands[0]); command_start_column=fprintf(file,"%8s%c=%c%s ",p->decode ? p->decode : "", p->mode <= 0 ? '<' : ' ',p->mode >= 0 ? '>' : ' ',delegate); for (s=commands[0]; length < command_length; s+=formatted_chars) { if (s != commands[0]) (void) fprintf(file,"%*s",command_start_column,""); strip_length=screen_width-command_start_column; if (length+strip_length < command_length) { char *e; for(e=s+strip_length; (*e != ' ') && (e > s) ; e--); strip_length=e-s; } formatted_chars=fprintf(file,"%.*s",strip_length,s); length+=formatted_chars; (void) fprintf(file,"\n"); if (formatted_chars <= 0) break; } } for (i=0; commands[i] != (char *) NULL; i++) MagickFreeMemory(commands[i]); MagickFreeMemory(commands); } (void) fflush(file); UnlockSemaphoreInfo(delegate_semaphore); return(True); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k R e s o u r c e L i m i t % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickResourceLimit() returns the specified resource limit. % % The format of the GetMagickResourceLimit() method is: % % MagickSizeType GetMagickResourceLimit(const ResourceType type) % % A description of each parameter follows: % % o type: the type of resource. % */ MagickExport MagickSizeType GetMagickResourceLimit(const ResourceType type) { MagickSizeType resource; resource=0; if (resource_semaphore == (SemaphoreInfo *) NULL) ActivateSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case WidthResource: { resource=resource_info.width_limit; break; } case HeightResource: { resource=resource_info.height_limit; break; } case AreaResource: { resource=resource_info.area_limit; break; } case MemoryResource: { resource=resource_info.memory_limit; break; } case MapResource: { resource=resource_info.map_limit; break; } case DiskResource: { resource=resource_info.disk_limit; break; } case FileResource: { resource=resource_info.file_limit; break; } case ThreadResource: { resource=resource_info.thread_limit; break; } case ThrottleResource: { resource=resource_info.throttle_limit; break; } case TimeResource: { resource=resource_info.time_limit; break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); return(resource); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % G e t M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMagickResource() returns the specified resource. % % The format of the GetMagickResource() method is: % % MagickSizeType GetMagickResource(const ResourceType type) % % A description of each parameter follows: % % o type: the type of resource. % */ MagickExport MagickSizeType GetMagickResource(const ResourceType type) { MagickSizeType resource; resource=0; LockSemaphoreInfo(resource_semaphore); switch (type) { case WidthResource: { resource=(MagickSizeType) resource_info.width; break; } case HeightResource: { resource=(MagickSizeType) resource_info.height; break; } case AreaResource: { resource=(MagickSizeType) resource_info.area; break; } case MemoryResource: { resource=(MagickSizeType) resource_info.memory; break; } case MapResource: { resource=(MagickSizeType) resource_info.map; break; } case DiskResource: { resource=(MagickSizeType) resource_info.disk; break; } case FileResource: { resource=(MagickSizeType) resource_info.file; break; } case ThreadResource: { resource=(MagickSizeType) resource_info.thread; break; } case ThrottleResource: { resource=(MagickSizeType) resource_info.throttle; break; } case TimeResource: { resource=(MagickSizeType) resource_info.time; break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); return(resource); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t P o l i c y I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetPolicyInfo() searches the policy list for the specified name and if found % returns attributes for that policy. % % The format of the GetPolicyInfo method is: % % PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception) % % A description of each parameter follows: % % o name: the policy name. % % o exception: return any errors or warnings in this structure. % */ static PolicyInfo *GetPolicyInfo(const char *name,ExceptionInfo *exception) { char policyname[MagickPathExtent]; PolicyDomain domain; register PolicyInfo *p; register char *q; assert(exception != (ExceptionInfo *) NULL); if (IsPolicyCacheInstantiated(exception) == MagickFalse) return((PolicyInfo *) NULL); /* Strip names of whitespace. */ *policyname='\0'; if (name != (const char *) NULL) (void) CopyMagickString(policyname,name,MagickPathExtent); for (q=policyname; *q != '\0'; q++) { if (isspace((int) ((unsigned char) *q)) == 0) continue; (void) CopyMagickString(q,q+1,MagickPathExtent); q--; } /* Strip domain from policy name (e.g. resource:map). */ domain=UndefinedPolicyDomain; for (q=policyname; *q != '\0'; q++) { if (*q != ':') continue; *q='\0'; domain=(PolicyDomain) ParseCommandOption(MagickPolicyDomainOptions, MagickTrue,policyname); (void) CopyMagickString(policyname,q+1,MagickPathExtent); break; } /* Search for policy tag. */ LockSemaphoreInfo(policy_semaphore); ResetLinkedListIterator(policy_cache); p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); if ((name == (const char *) NULL) || (LocaleCompare(name,"*") == 0)) { UnlockSemaphoreInfo(policy_semaphore); return(p); } while (p != (PolicyInfo *) NULL) { if ((domain == UndefinedPolicyDomain) || (p->domain == domain)) if (LocaleCompare(policyname,p->name) == 0) break; p=(PolicyInfo *) GetNextValueInLinkedList(policy_cache); } if (p != (PolicyInfo *) NULL) (void) InsertValueInLinkedList(policy_cache,0, RemoveElementByValueFromLinkedList(policy_cache,p)); UnlockSemaphoreInfo(policy_semaphore); return(p); }
MagickExport int AcquireUniqueFileResource(char *path) { #if !defined(O_NOFOLLOW) #define O_NOFOLLOW 0 #endif #if !defined(TMP_MAX) # define TMP_MAX 238328 #endif int c, file; register char *p; register ssize_t i; static const char portable_filename[65] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789_-"; StringInfo *key; unsigned char *datum; assert(path != (char *) NULL); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (random_info == (RandomInfo *) NULL) random_info=AcquireRandomInfo(); file=(-1); for (i=0; i < (ssize_t) TMP_MAX; i++) { /* Get temporary pathname. */ (void) GetPathTemplate(path); key=GetRandomKey(random_info,2); p=path+strlen(path)-8; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); #if defined(MAGICKCORE_HAVE_MKSTEMP) file=mkstemp(path); #if defined(__OS2__) setmode(file,O_BINARY); #endif if (file != -1) break; #endif key=GetRandomKey(random_info,6); p=path+strlen(path)-6; datum=GetStringInfoDatum(key); for (i=0; i < (ssize_t) GetStringInfoLength(key); i++) { c=(int) (datum[i] & 0x3f); *p++=portable_filename[c]; } key=DestroyStringInfo(key); file=open_utf8(path,O_RDWR | O_CREAT | O_EXCL | O_BINARY | O_NOFOLLOW,S_MODE); if ((file >= 0) || (errno != EEXIST)) break; } (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s",path); if (file == -1) return(file); if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); if (temporary_resources == (SplayTreeInfo *) NULL) temporary_resources=NewSplayTree(CompareSplayTreeString, DestroyTemporaryResources,(void *(*)(void *)) NULL); UnlockSemaphoreInfo(resource_semaphore); (void) AddValueToSplayTree(temporary_resources,ConstantString(path), (const void *) NULL); return(file); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % % R e l i n q u i s h M a g i c k R e s o u r c e % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % RelinquishMagickResource() relinquishes resources of the specified type. % % The format of the RelinquishMagickResource() method is: % % void RelinquishMagickResource(const ResourceType type, % const MagickSizeType size) % % A description of each parameter follows: % % o type: the type of resource. % % o size: the size of the resource. % */ MagickExport void RelinquishMagickResource(const ResourceType type, const MagickSizeType size) { char resource_current[MaxTextExtent], resource_limit[MaxTextExtent], resource_request[MaxTextExtent]; (void) FormatMagickSize(size,MagickFalse,resource_request); if (resource_semaphore == (SemaphoreInfo *) NULL) AcquireSemaphoreInfo(&resource_semaphore); LockSemaphoreInfo(resource_semaphore); switch (type) { case AreaResource: { resource_info.area=(MagickOffsetType) size; (void) FormatMagickSize((MagickSizeType) resource_info.area,MagickFalse, resource_current); (void) FormatMagickSize(resource_info.area_limit,MagickFalse, resource_limit); break; } case MemoryResource: { resource_info.memory-=size; (void) FormatMagickSize((MagickSizeType) resource_info.memory, MagickTrue,resource_current); (void) FormatMagickSize(resource_info.memory_limit,MagickTrue, resource_limit); break; } case MapResource: { resource_info.map-=size; (void) FormatMagickSize((MagickSizeType) resource_info.map,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.map_limit,MagickTrue, resource_limit); break; } case DiskResource: { resource_info.disk-=size; (void) FormatMagickSize((MagickSizeType) resource_info.disk,MagickTrue, resource_current); (void) FormatMagickSize(resource_info.disk_limit,MagickTrue, resource_limit); break; } case FileResource: { resource_info.file-=size; (void) FormatMagickSize((MagickSizeType) resource_info.file,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.file_limit, MagickFalse,resource_limit); break; } case ThreadResource: { (void) FormatMagickSize((MagickSizeType) resource_info.thread,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.thread_limit, MagickFalse,resource_limit); break; } case TimeResource: { resource_info.time-=size; (void) FormatMagickSize((MagickSizeType) resource_info.time,MagickFalse, resource_current); (void) FormatMagickSize((MagickSizeType) resource_info.time_limit, MagickFalse,resource_limit); break; } default: break; } UnlockSemaphoreInfo(resource_semaphore); (void) LogMagickEvent(ResourceEvent,GetMagickModule(),"%s: %s/%s/%s", CommandOptionToMnemonic(MagickResourceOptions,(ssize_t) type), resource_request,resource_current,resource_limit); }
/* %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % % % % % + G e t M i m e I n f o % % % % % % % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % % GetMimeInfo() attempts to classify the content to identify which mime type % is associated with the content, if any. % % The format of the GetMimeInfo method is: % % const MimeInfo *GetMimeInfo(const char *filename, % const unsigned char *magic,const size_t length, % ExceptionInfo *exception) % % A description of each parameter follows: % % o filename: If we cannot not classify the string, we attempt to classify % based on the filename (e.g. *.pdf returns application/pdf). % % o magic: A binary string generally representing the first few characters % of the image file or blob. % % o length: the length of the binary signature. % % o exception: return any errors or warnings in this structure. % */ MagickExport const MimeInfo *GetMimeInfo(const char *filename, const unsigned char *magic,const size_t length,ExceptionInfo *exception) { const MimeInfo *mime_info; EndianType endian; register const MimeInfo *p; register const unsigned char *q; register ssize_t i; ssize_t value; unsigned long lsb_first; assert(exception != (ExceptionInfo *) NULL); if (IsMimeCacheInstantiated(exception) == MagickFalse) return((const MimeInfo *) NULL); /* Search for mime tag. */ mime_info=(const MimeInfo *) NULL; lsb_first=1; LockSemaphoreInfo(mime_semaphore); ResetLinkedListIterator(mime_cache); p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); if ((magic == (const unsigned char *) NULL) || (length == 0)) { UnlockSemaphoreInfo(mime_semaphore); return(p); } while (p != (const MimeInfo *) NULL) { assert(p->offset >= 0); if (mime_info != (const MimeInfo *) NULL) if (p->priority > mime_info->priority) { p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); continue; } if ((p->pattern != (char *) NULL) && (filename != (char *) NULL)) { if (GlobExpression(filename,p->pattern,MagickFalse) != MagickFalse) mime_info=p; p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); continue; } switch (p->data_type) { case ByteData: { if ((size_t) (p->offset+4) > length) break; q=magic+p->offset; value=(ssize_t) (*q++); if (p->mask == 0) { if (p->value == value) mime_info=p; } else { if ((p->value & p->mask) == value) mime_info=p; } break; } case ShortData: { if ((size_t) (p->offset+4) > length) break; q=magic+p->offset; endian=p->endian; if (p->endian == UndefinedEndian) endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian; if (endian == LSBEndian) { value=(ssize_t) (*q++); value|=(*q++) << 8; } else { value=(ssize_t) (*q++) << 8; value|=(*q++); } if (p->mask == 0) { if (p->value == value) mime_info=p; } else { if ((p->value & p->mask) == value) mime_info=p; } break; } case LongData: { if ((size_t) (p->offset+4) > length) break; q=magic+p->offset; endian=p->endian; if (p->endian == UndefinedEndian) endian=(*(char *) &lsb_first) == 1 ? LSBEndian : MSBEndian; if (endian == LSBEndian) { value=(ssize_t) (*q++); value|=((ssize_t) *q++) << 8; value|=((ssize_t) *q++) << 16; value|=((ssize_t) *q++) << 24; } else { value=(ssize_t) (*q++) << 24; value|=((ssize_t) *q++) << 16; value|=((ssize_t) *q++) << 8; value|=((ssize_t) *q++); } if (p->mask == 0) { if (p->value == value) mime_info=p; } else { if ((p->value & p->mask) == value) mime_info=p; } break; } case StringData: default: { for (i=0; i <= (ssize_t) p->extent; i++) { if ((size_t) (p->offset+i+p->length) > length) break; if (memcmp(magic+p->offset+i,p->magic,p->length) == 0) { mime_info=p; break; } } break; } } p=(const MimeInfo *) GetNextValueInLinkedList(mime_cache); } if (mime_info != (const MimeInfo *) NULL) (void) InsertValueInLinkedList(mime_cache,0, RemoveElementByValueFromLinkedList(mime_cache,p)); UnlockSemaphoreInfo(mime_semaphore); return(mime_info); }