13ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
23ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
33ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
43ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
53ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
63ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            U   U  RRRR   L                                  %
73ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            U   U  R   R  L                                  %
83ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            U   U  RRRR   L                                  %
93ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                            U   U  R R    L                                  %
103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                             UUU   R  R   LLLLL                              %
113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                        Retrieve An Image Via URL.                           %
143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                              Software Design                                %
16de984cdc3631106b1cbbb8d3972b76a0fc27e8e8cristy%                                   Cristy                                    %
173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                              Bill Radcliffe                                 %
183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                March 2000                                   %
193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
217ce65e7125a4e1df1a274ce373c537a9df9c16cdCristy%  Copyright 1999-2016 ImageMagick Studio LLC, a non-profit organization      %
223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  dedicated to making software imaging solutions freely available.           %
233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  You may not use this file except in compliance with the License.  You may  %
253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  obtain a copy of the License at                                            %
263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    http://www.imagemagick.org/script/license.php                            %
283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  Unless required by applicable law or agreed to in writing, software        %
303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  distributed under the License is distributed on an "AS IS" BASIS,          %
313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.   %
323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  See the License for the specific language governing permissions and        %
333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  limitations under the License.                                             %
343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Include declarations.
423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
434c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/studio.h"
444c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/blob.h"
454c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/blob-private.h"
464c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/constitute.h"
474c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception.h"
484c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/exception-private.h"
494c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/image.h"
504c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/image-private.h"
514c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/list.h"
524c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/magick.h"
534c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/memory_.h"
544c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/module.h"
554c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/quantum-private.h"
564c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/static.h"
574c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/resource_.h"
584c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/string_.h"
594c08aed51c5899665ade97263692328eea4af106cristy#include "MagickCore/utility.h"
603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_XML_DELEGATE)
610157aeadef2fce908277168097a160a8f15a6952cristy#  if defined(MAGICKCORE_WINDOWS_SUPPORT)
6214e6cc75f353320ecec0aa9c1acf0efe43463ec2cristy#    if !defined(__MINGW32__) && !defined(__MINGW64__)
633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#      include <win32config.h>
643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#    endif
653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  endif
663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <libxml/parser.h>
673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <libxml/xmlmemory.h>
683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <libxml/nanoftp.h>
693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#  include <libxml/nanohttp.h>
703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
71b0af14f41c0cb866176f7a0931879afde6b890a7cristy#if defined(MAGICKCORE_WINDOWS_SUPPORT) && \
72b0af14f41c0cb866176f7a0931879afde6b890a7cristy    !(defined(__MINGW32__) || defined(__MINGW64__))
73b0af14f41c0cb866176f7a0931879afde6b890a7cristy#  include <urlmon.h>
745cb71bb7b4fdadec964910e08260f0da3fcb21d7dirk#  pragma comment(lib, "urlmon.lib")
75853b77b21ea750b0223c659b86a3372b1729efc2dirk#endif
76252b3c6f92583f56f6bb28a4570c1a1df1017e7eCristy
773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
813ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
823ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   R e a d U R L I m a g e                                                   %
833ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
843ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
873ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  ReadURLImage retrieves an image via URL, decodes the image, and returns
893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  it.  It allocates the memory necessary for the new Image structure and
903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  returns a pointer to the new image.
913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the ReadURLImage method is:
933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      Image *ReadURLImage(const ImageInfo *image_info,ExceptionInfo *exception)
953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  A description of each parameter follows:
973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o image_info: the image info.
993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%    o exception: return any errors or warnings in this structure.
1013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
1023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
1033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
1053ed852eea50f9d4cd633efb8c2b054b8e33c253cristyextern "C" {
1063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED)
1093ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic void GetFTPData(void *userdata,const char *data,int size)
1103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FILE
1123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *file;
1133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  size_t
1153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    length;
1163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  file=(FILE *) userdata;
1183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (file == (FILE *) NULL)
1193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
1203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (size <= 0)
1213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    return;
1223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  length=fwrite(data,size,1,file);
123da16f16767eb31921af855f17bda465fffc4e000cristy  (void) length;
1243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(__cplusplus) || defined(c_plusplus)
1283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
1293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
1303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1313ed852eea50f9d4cd633efb8c2b054b8e33c253cristystatic Image *ReadURLImage(const ImageInfo *image_info,ExceptionInfo *exception)
1323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
1333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#define MaxBufferExtent  8192
1343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  char
136151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy    filename[MagickPathExtent];
1373ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1383ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  FILE
1393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *file;
1403ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  Image
1423ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *image;
1433ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1443ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  ImageInfo
1453ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *read_info;
1463ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1473ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  int
1483ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    unique_file;
1493ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  read_info=CloneImageInfo(image_info);
1513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  SetImageInfoBlob(read_info,(void *) NULL,0);
152b807e309e4e63195191794d16090d455fc30b837Cristy  if (LocaleCompare(read_info->magick,"file") == 0)
153b807e309e4e63195191794d16090d455fc30b837Cristy    {
154b807e309e4e63195191794d16090d455fc30b837Cristy      (void) CopyMagickString(read_info->filename,image_info->filename+2,
155b807e309e4e63195191794d16090d455fc30b837Cristy        MagickPathExtent);
156b807e309e4e63195191794d16090d455fc30b837Cristy      *read_info->magick='\0';
157b807e309e4e63195191794d16090d455fc30b837Cristy      image=ReadImage(read_info,exception);
158b807e309e4e63195191794d16090d455fc30b837Cristy      read_info=DestroyImageInfo(read_info);
159b807e309e4e63195191794d16090d455fc30b837Cristy      return(GetFirstImageInList(image));
160b807e309e4e63195191794d16090d455fc30b837Cristy    }
1613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  file=(FILE *) NULL;
1623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  unique_file=AcquireUniqueFileResource(read_info->filename);
1633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (unique_file != -1)
1643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    file=fdopen(unique_file,"wb");
1653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if ((unique_file == -1) || (file == (FILE *) NULL))
1663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      ThrowFileException(exception,FileOpenError,"UnableToCreateTemporaryFile",
16812e6547a6d7d2a28a850f4c454b9cdcec0187f50cristy        read_info->filename);
16912e6547a6d7d2a28a850f4c454b9cdcec0187f50cristy      read_info=DestroyImageInfo(read_info);
1703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      return((Image *) NULL);
1713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
172151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) CopyMagickString(filename,image_info->magick,MagickPathExtent);
173151b66dffc9e3c2e8c4f8cdaca37ff987ca0f497cristy  (void) ConcatenateMagickString(filename,":",MagickPathExtent);
1743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  LocaleLower(filename);
175252b3c6f92583f56f6bb28a4570c1a1df1017e7eCristy  (void) ConcatenateMagickString(filename,image_info->filename,
176252b3c6f92583f56f6bb28a4570c1a1df1017e7eCristy    MagickPathExtent);
177b0af14f41c0cb866176f7a0931879afde6b890a7cristy#if defined(MAGICKCORE_WINDOWS_SUPPORT) && \
178b0af14f41c0cb866176f7a0931879afde6b890a7cristy    !(defined(__MINGW32__) || defined(__MINGW64__))
179b0af14f41c0cb866176f7a0931879afde6b890a7cristy  (void) fclose(file);
18093b02b797c4127ce2b06dbd3b2d75ecc33fca759dirk  if (URLDownloadToFile(NULL,filename,read_info->filename,0,NULL) != S_OK)
181b0af14f41c0cb866176f7a0931879afde6b890a7cristy    {
182b0af14f41c0cb866176f7a0931879afde6b890a7cristy      ThrowFileException(exception,FileOpenError,"UnableToOpenFile",
183b0af14f41c0cb866176f7a0931879afde6b890a7cristy        filename);
184b0af14f41c0cb866176f7a0931879afde6b890a7cristy      (void) RelinquishUniqueFileResource(read_info->filename);
185b0af14f41c0cb866176f7a0931879afde6b890a7cristy      read_info=DestroyImageInfo(read_info);
186b0af14f41c0cb866176f7a0931879afde6b890a7cristy      return((Image *) NULL);
187b0af14f41c0cb866176f7a0931879afde6b890a7cristy    }
188853b77b21ea750b0223c659b86a3372b1729efc2dirk#else
1893ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED)
1903ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (LocaleCompare(read_info->magick,"ftp") == 0)
1913ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
1923ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      void
1933ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *context;
1943ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
1953ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      xmlNanoFTPInit();
1963ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      context=xmlNanoFTPNewCtxt(filename);
1973ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (context != (void *) NULL)
1983ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
1993ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          if (xmlNanoFTPConnect(context) >= 0)
2003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            (void) xmlNanoFTPGet(context,GetFTPData,(void *) file,
2013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy              (char *) NULL);
2023ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          (void) xmlNanoFTPClose(context);
2033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
2043ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
2053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
2063ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#if defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_HTTP_ENABLED)
2073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  if (LocaleCompare(read_info->magick,"http") == 0)
2083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    {
2093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      char
2103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        buffer[MaxBufferExtent],
2113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *type;
2123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      int
2143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        bytes;
2153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      void
2173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        *context;
2183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      type=(char *) NULL;
2203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      context=xmlNanoHTTPMethod(filename,(const char *) NULL,
2213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        (const char *) NULL,&type,(const char *) NULL,0);
2223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy      if (context != (void *) NULL)
2233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        {
2243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          ssize_t
2253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            count;
2263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          while ((bytes=xmlNanoHTTPRead(context,buffer,MaxBufferExtent)) > 0)
2283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy            count=(ssize_t) fwrite(buffer,bytes,1,file);
229da16f16767eb31921af855f17bda465fffc4e000cristy          (void) count;
2303ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          xmlNanoHTTPClose(context);
2313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          xmlFree(type);
2323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy          xmlNanoHTTPCleanup();
2333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy        }
2343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    }
2353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
2363ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) fclose(file);
237853b77b21ea750b0223c659b86a3372b1729efc2dirk#endif
238252b3c6f92583f56f6bb28a4570c1a1df1017e7eCristy  *read_info->magick='\0';
2393ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  image=ReadImage(read_info,exception);
240b807e309e4e63195191794d16090d455fc30b837Cristy  (void) RelinquishUniqueFileResource(read_info->filename);
2413ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  read_info=DestroyImageInfo(read_info);
242a134d337460443216515a5d96554364b92ed0687cristy  if (image != (Image *) NULL)
243a134d337460443216515a5d96554364b92ed0687cristy    GetPathComponent(image_info->filename,TailPath,image->filename);
244a134d337460443216515a5d96554364b92ed0687cristy  else
2457ff4c441f90480076c4d5c2e07cd75b13b0fb8c8cristy    {
2467ff4c441f90480076c4d5c2e07cd75b13b0fb8c8cristy      (void) ThrowMagickException(exception,GetMagickModule(),CoderError,
2477ff4c441f90480076c4d5c2e07cd75b13b0fb8c8cristy        "NoDataReturned","`%s'",filename);
2487ff4c441f90480076c4d5c2e07cd75b13b0fb8c8cristy      return((Image *) NULL);
2497ff4c441f90480076c4d5c2e07cd75b13b0fb8c8cristy    }
2503ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(GetFirstImageInList(image));
2513ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
2523ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
2533ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
2543ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2553ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2563ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2573ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2583ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   R e g i s t e r U R L I m a g e                                           %
2593ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2603ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2613ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
2623ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
2633ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2643ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  RegisterURLImage() adds attributes for the URL image format to
2653ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  the list of supported formats.  The attributes include the image format
2663ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  tag, a method to read and/or write the format, whether the format
2673ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  supports the saving of more than one frame to the same file or blob,
2683ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  whether the format supports native in-memory I/O, and a brief
2693ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  description of the format.
2703ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2713ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the RegisterURLImage method is:
2723ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
273bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristy%      size_t RegisterURLImage(void)
2743ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
2753ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
276bb50337b2a8a16ca7e903cc04ab195ff0fd47ae6cristyModuleExport size_t RegisterURLImage(void)
2773ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
2783ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  MagickInfo
2793ed852eea50f9d4cd633efb8c2b054b8e33c253cristy    *entry;
2803ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
28106b627a07ff44e1ff93ef1288c9f428066ded10ddirk  entry=AcquireMagickInfo("URL","HTTP","Uniform Resource Locator (http://)");
282b0af14f41c0cb866176f7a0931879afde6b890a7cristy#if (defined(MAGICKCORE_WINDOWS_SUPPORT) && \
283b0af14f41c0cb866176f7a0931879afde6b890a7cristy    !(defined(__MINGW32__) || defined(__MINGW64__))) || \
284853b77b21ea750b0223c659b86a3372b1729efc2dirk    (defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_HTTP_ENABLED))
2853ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->decoder=(DecodeImageHandler *) ReadURLImage;
2863ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
28770c7b10aec9e3934fb0883396f5c74b9ad6a81e1Cristy  entry->format_type=ImplicitFormatType;
2883ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RegisterMagickInfo(entry);
28906b627a07ff44e1ff93ef1288c9f428066ded10ddirk  entry=AcquireMagickInfo("URL","HTTPS","Uniform Resource Locator (https://)");
290b0af14f41c0cb866176f7a0931879afde6b890a7cristy#if defined(MAGICKCORE_WINDOWS_SUPPORT) && \
291b0af14f41c0cb866176f7a0931879afde6b890a7cristy    !(defined(__MINGW32__) || defined(__MINGW64__))
292b0af14f41c0cb866176f7a0931879afde6b890a7cristy  entry->decoder=(DecodeImageHandler *) ReadURLImage;
293b0af14f41c0cb866176f7a0931879afde6b890a7cristy#endif
29470c7b10aec9e3934fb0883396f5c74b9ad6a81e1Cristy  entry->format_type=ImplicitFormatType;
295853b77b21ea750b0223c659b86a3372b1729efc2dirk  (void) RegisterMagickInfo(entry);
29606b627a07ff44e1ff93ef1288c9f428066ded10ddirk  entry=AcquireMagickInfo("URL","FTP","Uniform Resource Locator (ftp://)");
297b0af14f41c0cb866176f7a0931879afde6b890a7cristy#if (defined(MAGICKCORE_WINDOWS_SUPPORT) && \
298b0af14f41c0cb866176f7a0931879afde6b890a7cristy    !(defined(__MINGW32__) || defined(__MINGW64__))) || \
299853b77b21ea750b0223c659b86a3372b1729efc2dirk    (defined(MAGICKCORE_XML_DELEGATE) && defined(LIBXML_FTP_ENABLED))
3003ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->decoder=(DecodeImageHandler *) ReadURLImage;
3013ed852eea50f9d4cd633efb8c2b054b8e33c253cristy#endif
30270c7b10aec9e3934fb0883396f5c74b9ad6a81e1Cristy  entry->format_type=ImplicitFormatType;
3033ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RegisterMagickInfo(entry);
30406b627a07ff44e1ff93ef1288c9f428066ded10ddirk  entry=AcquireMagickInfo("URL","FILE","Uniform Resource Locator (file://)");
3053ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  entry->decoder=(DecodeImageHandler *) ReadURLImage;
30670c7b10aec9e3934fb0883396f5c74b9ad6a81e1Cristy  entry->format_type=ImplicitFormatType;
3073ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) RegisterMagickInfo(entry);
3083ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  return(MagickImageCoderSignature);
3093ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
3103ed852eea50f9d4cd633efb8c2b054b8e33c253cristy
3113ed852eea50f9d4cd633efb8c2b054b8e33c253cristy/*
3123ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3133ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3143ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3153ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3163ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%   U n r e g i s t e r U R L I m a g e                                       %
3173ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3183ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3193ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%                                                                             %
3203ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
3213ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3223ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  UnregisterURLImage() removes format registrations made by the
3233ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  URL module from the list of supported formats.
3243ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3253ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%  The format of the UnregisterURLImage method is:
3263ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3273ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%      UnregisterURLImage(void)
3283ed852eea50f9d4cd633efb8c2b054b8e33c253cristy%
3293ed852eea50f9d4cd633efb8c2b054b8e33c253cristy*/
3303ed852eea50f9d4cd633efb8c2b054b8e33c253cristyModuleExport void UnregisterURLImage(void)
3313ed852eea50f9d4cd633efb8c2b054b8e33c253cristy{
3323ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) UnregisterMagickInfo("HTTP");
3333ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) UnregisterMagickInfo("FTP");
3343ed852eea50f9d4cd633efb8c2b054b8e33c253cristy  (void) UnregisterMagickInfo("FILE");
3353ed852eea50f9d4cd633efb8c2b054b8e33c253cristy}
336