This source file includes following definitions.
- GetFTPData
- ReadURLImage
- RegisterURLImage
- UnregisterURLImage
#include "magick/studio.h"
#include "magick/blob.h"
#include "magick/blob-private.h"
#include "magick/constitute.h"
#include "magick/exception.h"
#include "magick/exception-private.h"
#include "magick/image.h"
#include "magick/image-private.h"
#include "magick/list.h"
#include "magick/magick.h"
#include "magick/memory_.h"
#include "magick/module.h"
#include "magick/pixel-accessor.h"
#include "magick/quantum-private.h"
#include "magick/static.h"
#include "magick/resource_.h"
#include "magick/string_.h"
#include "magick/utility.h"
#if defined(MAGICKCORE_XML_DELEGATE)
# if defined(MAGICKCORE_WINDOWS_SUPPORT)
# if !defined(__MINGW32__) && !defined(__MINGW64__)
# include <win32config.h>
# endif
# endif
# include <libxml/parser.h>
# include <libxml/xmlmemory.h>
# include <libxml/nanoftp.h>
# include <libxml/nanohttp.h>
#endif
#if defined(MAGICKCORE_WINDOWS_SUPPORT) && \
!(defined(__MINGW32__) || defined(__MINGW64__))
# include <urlmon.h>
# pragma comment(lib, "urlmon.lib")
#endif
#if defined(__cplusplus) || defined(c_plusplus)
extern "C" {
#endif
#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED)
static void GetFTPData(void *userdata,const char *data,int size)
{
FILE
*file;
size_t
length;
file=(FILE *) userdata;
if (file == (FILE *) NULL)
return;
if (size <= 0)
return;
length=fwrite(data,size,1,file);
(void) length;
}
#endif
#if defined(__cplusplus) || defined(c_plusplus)
}
#endif
static Image *ReadURLImage(const ImageInfo *image_info,ExceptionInfo *exception)
{
#define MaxBufferExtent 8192
char
filename[MaxTextExtent];
FILE
*file;
Image
*image;
ImageInfo
*read_info;
int
unique_file;
image=(Image *) NULL;
read_info=CloneImageInfo(image_info);
SetImageInfoBlob(read_info,(void *) NULL,0);
file=(FILE *) NULL;
unique_file=AcquireUniqueFileResource(read_info->filename);
if (unique_file != -1)
file=fdopen(unique_file,"wb");
if ((unique_file == -1) || (file == (FILE *) NULL))
{
ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
read_info->filename);
read_info=DestroyImageInfo(read_info);
return((Image *) NULL);
}
(void) CopyMagickString(filename,image_info->magick,MaxTextExtent);
(void) ConcatenateMagickString(filename,":",MaxTextExtent);
LocaleLower(filename);
(void) ConcatenateMagickString(filename,image_info->filename,MaxTextExtent);
if (LocaleCompare(read_info->magick,"file") == 0)
{
(void) RelinquishUniqueFileResource(read_info->filename);
unique_file=(-1);
(void) CopyMagickString(read_info->filename,image_info->filename+2,
MaxTextExtent);
}
#if defined(MAGICKCORE_WINDOWS_SUPPORT) && \
!(defined(__MINGW32__) || defined(__MINGW64__))
(void) fclose(file);
if (URLDownloadToFile(NULL,filename,read_info->filename,0,NULL) != S_OK)
{
ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
filename);
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
return((Image *) NULL);
}
#else
#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED)
if (LocaleCompare(read_info->magick,"ftp") == 0)
{
void
*context;
xmlNanoFTPInit();
context=xmlNanoFTPNewCtxt(filename);
if (context != (void *) NULL)
{
if (xmlNanoFTPConnect(context) >= 0)
(void) xmlNanoFTPGet(context,GetFTPData,(void *) file,
(char *) NULL);
(void) xmlNanoFTPClose(context);
}
}
#endif
#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_HTTP_ENABLED)
if (LocaleCompare(read_info->magick,"http") == 0)
{
char
buffer[MaxBufferExtent],
*type;
int
bytes;
void
*context;
type=(char *) NULL;
context=xmlNanoHTTPMethod(filename,(const char *) NULL,
(const char *) NULL,&type,(const char *) NULL,0);
if (context != (void *) NULL)
{
ssize_t
count;
while ((bytes=xmlNanoHTTPRead(context,buffer,MaxBufferExtent)) > 0)
count=(ssize_t) fwrite(buffer,bytes,1,file);
(void) count;
xmlNanoHTTPClose(context);
xmlFree(type);
xmlNanoHTTPCleanup();
}
}
#endif
(void) fclose(file);
#endif
{
ExceptionInfo
*sans;
ImageInfo
*clone_info;
clone_info=CloneImageInfo(image_info);
sans=AcquireExceptionInfo();
(void) SetImageInfo(clone_info,0,sans);
(void) CopyMagickString(read_info->magick,clone_info->magick,MaxTextExtent);
clone_info=DestroyImageInfo(clone_info);
sans=DestroyExceptionInfo(sans);
}
*read_info->magick='\0';
image=ReadImage(read_info,exception);
if (unique_file != -1)
(void) RelinquishUniqueFileResource(read_info->filename);
read_info=DestroyImageInfo(read_info);
if (image != (Image *) NULL)
GetPathComponent(image_info->filename,TailPath,image->filename);
else
{
(void) ThrowMagickException(exception,GetMagickModule(),CoderError,
"NoDataReturned","`%s'",filename);
return((Image *) NULL);
}
return(GetFirstImageInList(image));
}
ModuleExport size_t RegisterURLImage(void)
{
MagickInfo
*entry;
entry=SetMagickInfo("HTTP");
#if (defined(MAGICKCORE_WINDOWS_SUPPORT) && \
!(defined(__MINGW32__) || defined(__MINGW64__))) || \
(defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_HTTP_ENABLED))
entry->decoder=(DecodeImageHandler *) ReadURLImage;
#endif
entry->description=ConstantString("Uniform Resource Locator (http://)");
entry->module=ConstantString("URL");
entry->stealth=MagickTrue;
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("HTTPS");
#if defined(MAGICKCORE_WINDOWS_SUPPORT) && \
!(defined(__MINGW32__) || defined(__MINGW64__))
entry->decoder=(DecodeImageHandler *) ReadURLImage;
#endif
entry->description=ConstantString("Uniform Resource Locator (https://)");
entry->module=ConstantString("URL");
entry->stealth=MagickTrue;
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("FTP");
#if (defined(MAGICKCORE_WINDOWS_SUPPORT) && \
!(defined(__MINGW32__) || defined(__MINGW64__))) || \
(defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED))
entry->decoder=(DecodeImageHandler *) ReadURLImage;
#endif
entry->description=ConstantString("Uniform Resource Locator (ftp://)");
entry->module=ConstantString("URL");
entry->stealth=MagickTrue;
(void) RegisterMagickInfo(entry);
entry=SetMagickInfo("FILE");
entry->decoder=(DecodeImageHandler *) ReadURLImage;
entry->description=ConstantString("Uniform Resource Locator (file://)");
entry->module=ConstantString("URL");
entry->stealth=MagickTrue;
(void) RegisterMagickInfo(entry);
return(MagickImageCoderSignature);
}
ModuleExport void UnregisterURLImage(void)
{
(void) UnregisterMagickInfo("HTTP");
(void) UnregisterMagickInfo("HTTPS");
(void) UnregisterMagickInfo("FTP");
(void) UnregisterMagickInfo("FILE");
}