~ubuntu-branches/ubuntu/natty/imagemagick/natty-security

« back to all changes in this revision

Viewing changes to magick/nt-base.c

  • Committer: Bazaar Package Importer
  • Author(s): Luke Yelavich
  • Date: 2009-11-27 09:32:04 UTC
  • mfrom: (6.2.4 squeeze)
  • Revision ID: james.westby@ubuntu.com-20091127093204-m038t8kmxk6uvc25
Tags: 7:6.5.7.8-1ubuntu1
* Merge from debian testing.  Remaining changes:
  - Don't build-dep on librsvg, it brings in excessive dependencies
  - Don't build-dep on liblqr-1-0-dev, it is in universe

Show diffs side-by-side

added added

removed removed

Lines of Context:
73
73
  *lt_slsearchpath = (char *) NULL;
74
74
#endif
75
75
 
76
 
static GhostscriptVectors
77
 
  gs_vectors;
 
76
static GhostInfo
 
77
  ghost_info;
78
78
 
79
79
static void
80
 
  *gs_dll_handle = (void *) NULL;
 
80
  *ghost_handle = (void *) NULL;
81
81
 
82
82
/*
83
83
  External declarations.
349
349
 
350
350
static BOOL ControlHandler(DWORD type)
351
351
{
352
 
  AsynchronousDestroyMagickResources();
 
352
  (void) type;
 
353
  AsynchronousResourceComponentTerminus();
353
354
  return(FALSE);
354
355
}
355
356
 
411
412
%
412
413
%  The format of the NTErrorHandler method is:
413
414
%
414
 
%      void NTErrorHandler(const ExceptionType error,const char *reason,
 
415
%      void NTErrorHandler(const ExceptionType severity,const char *reason,
415
416
%        const char *description)
416
417
%
417
418
%  A description of each parameter follows:
418
419
%
419
 
%    o error: Specifies the numeric error category.
 
420
%    o severity: Specifies the numeric error category.
420
421
%
421
422
%    o reason: Specifies the reason to display before terminating the
422
423
%      program.
424
425
%    o description: Specifies any description to the reason.
425
426
%
426
427
*/
427
 
MagickExport void NTErrorHandler(const ExceptionType error,const char *reason,
428
 
  const char *description)
 
428
MagickExport void NTErrorHandler(const ExceptionType severity,
 
429
  const char *reason,const char *description)
429
430
{
430
431
  char
431
432
    buffer[3*MaxTextExtent],
432
433
    *message;
433
434
 
 
435
  (void) severity;
434
436
  if (reason == (char *) NULL)
435
437
    {
436
438
      MagickCoreTerminus();
533
535
  status=CryptReleaseContext(handle,0);
534
536
  if (status == 0)
535
537
    return(MagickFalse);
 
538
#else
 
539
  (void) random;
 
540
  (void) length;
536
541
#endif
537
542
  return(MagickTrue);
538
543
}
738
743
%                                                                             %
739
744
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
740
745
%
741
 
%  NTGhostscriptDLL() obtains the path to the latest Ghostscript DLL.  The
742
 
%  method returns MagickFalse if a value is not obtained.
 
746
%  NTGhostscriptDLL() returns the path to the most recent Ghostscript version
 
747
%  DLL.  The method returns TRUE on success otherwise FALSE.
743
748
%
744
749
%  The format of the NTGhostscriptDLL method is:
745
750
%
746
 
%      int NTGhostscriptDLL(char *path, int length)
 
751
%      int NTGhostscriptDLL(char *path,int length)
747
752
%
748
753
%  A description of each parameter follows:
749
754
%
750
 
%    o path: Pointer to buffer in which to return result.
751
 
%
752
 
%    o length: Length of buffer
753
 
%
754
 
*/
755
 
 
756
 
#define GS_PRODUCT_AFPL "AFPL Ghostscript"
757
 
#define GS_PRODUCT_ALADDIN "Aladdin Ghostscript"
758
 
#define GS_PRODUCT_GNU "GNU Ghostscript"
759
 
#define GS_PRODUCT_GPL "GPL Ghostscript"
760
 
#define GS_MINIMUM_VERSION 550
761
 
 
762
 
/*
763
 
  Get Ghostscript versions for given product.
764
 
  Store results starting at pver + 1 + offset.
765
 
  Returns total number of versions in pver.
766
 
*/
767
 
static int NTGhostscriptProductVersions(int *pver,int offset,
768
 
  const char *gs_productfamily)
 
755
%    o path: return the Ghostscript DLL path here.
 
756
%
 
757
%    o length: the buffer length.
 
758
%
 
759
*/
 
760
 
 
761
static int NTGetRegistryValue(HKEY root,const char *key,const char *name,
 
762
  char *value,int *length)
769
763
{
770
 
  HKEY
771
 
    hkey,
772
 
    hkeyroot;
 
764
  BYTE
 
765
    byte,
 
766
    *p;
773
767
 
774
768
  DWORD
775
 
    cbData;
776
 
 
777
 
  char
778
 
    key[MaxTextExtent],
779
 
    *p;
780
 
 
781
 
  int
782
 
    n = 0,
783
 
    ver;
784
 
 
785
 
  (void) FormatMagickString(key,MaxTextExtent,"Software\\%s",gs_productfamily);
786
 
  hkeyroot = HKEY_LOCAL_MACHINE;
787
 
  if (RegOpenKeyExA(hkeyroot,key,0,KEY_READ,&hkey) == ERROR_SUCCESS)
788
 
    {
789
 
      /*
790
 
        Now enumerate the keys.
791
 
      */
792
 
      cbData = sizeof(key) / sizeof(char);
793
 
      while (RegEnumKeyA(hkey,n,key,cbData) == ERROR_SUCCESS)
794
 
      {
795
 
        n++;
796
 
        ver = 0;
797
 
        p = key;
798
 
        while (*p && (*p!='.')) {
799
 
          ver = (ver * 10) + (*p - '0')*100;
800
 
          p++;
801
 
        }
802
 
        if (*p == '.')
803
 
          p++;
804
 
        if (*p)
805
 
          {
806
 
            ver+=10*(*p-'0');
807
 
            p++;
808
 
          }
809
 
        if (*p)
810
 
          ver+=(*p - '0');
811
 
        if ((n+offset) < pver[0])
812
 
          pver[n+offset]=ver;
813
 
      }
814
 
      RegCloseKey(hkey);
815
 
    }
816
 
  return(n+offset);
817
 
}
818
 
 
819
 
/* Query registry to find which versions of Ghostscript are installed.
820
 
 * Return version numbers in an integer array.
821
 
 * On entry, the first element in the array must be the array size
822
 
 * in elements.
823
 
 * If all is well, TRUE is returned.
824
 
 * On exit, the first element is set to the number of Ghostscript
825
 
 * versions installed, and subsequent elements to the version
826
 
 * numbers of Ghostscript.
827
 
 * e.g. on entry {5, 0, 0, 0, 0}, on exit {3, 550, 600, 596, 0}
828
 
 * Returned version numbers may not be sorted.
829
 
 *
830
 
 * If Ghostscript is not installed at all, return FALSE
831
 
 * and set pver[0] to 0.
832
 
 * If the array is not large enough, return FALSE
833
 
 * and set pver[0] to the number of Ghostscript versions installed.
834
 
 */
835
 
 
836
 
static int NTGhostscriptEnumerateVersions(int *pver)
837
 
{
838
 
  int
839
 
    n;
840
 
 
841
 
  assert(pver != (int *) NULL);
842
 
  n=NTGhostscriptProductVersions(pver,0,GS_PRODUCT_AFPL);
843
 
  n=NTGhostscriptProductVersions(pver,n,GS_PRODUCT_ALADDIN);
844
 
  n=NTGhostscriptProductVersions(pver,n,GS_PRODUCT_GNU);
845
 
  n=NTGhostscriptProductVersions(pver,n,GS_PRODUCT_GPL);
846
 
  if (n >= pver[0])
847
 
    {
848
 
      pver[0]=n;
849
 
      return(FALSE);  /* too small */
850
 
    }
851
 
  if (n == 0)
852
 
    {
853
 
      pver[0] = 0;
854
 
      return(FALSE);  /* not installed */
855
 
    }
856
 
  pver[0]=n;
857
 
  return(TRUE);
858
 
}
859
 
 
860
 
/*
861
 
 Get a named registry value.
862
 
 Key = hkeyroot\\key, named value = name.
863
 
 name, ptr, plen and return values are the same as in gp_getenv();
864
 
*/
865
 
static int NTGetRegistryValue(HKEY hkeyroot,const char *key,const char *name,
866
 
  char *ptr,int *plen)
867
 
{
 
769
    extent,
 
770
    type;
 
771
 
868
772
  HKEY
869
773
    hkey;
870
774
 
871
 
  DWORD
872
 
    cbData,
873
 
    keytype;
874
 
 
875
 
  BYTE
876
 
    b,
877
 
    *bptr = (BYTE *)ptr;
878
 
 
879
775
  LONG
880
 
    rc;
 
776
    status;
881
777
 
882
 
  if (RegOpenKeyExA(hkeyroot,key,0,KEY_READ,&hkey) == ERROR_SUCCESS)
883
 
    {
884
 
      keytype = REG_SZ;
885
 
      cbData = *plen;
886
 
      if (bptr == (BYTE *)NULL)
887
 
        bptr=(&b);  /* Registry API won't return ERROR_MORE_DATA */
888
 
      /* if ptr is NULL */
889
 
      rc=RegQueryValueExA(hkey,(char *) name,0,&keytype,bptr,&cbData);
890
 
      RegCloseKey(hkey);
891
 
      if (rc == ERROR_SUCCESS)
892
 
        {
893
 
          *plen = cbData;
894
 
          return 0;  /* found environment variable and copied it */
895
 
        } else if (rc == ERROR_MORE_DATA) {
896
 
        /* buffer wasn't large enough */
897
 
          *plen = cbData;
898
 
          return -1;
899
 
        }
 
778
  /*
 
779
    Get a registry value: key = root\\key, named value = name.
 
780
  */
 
781
  if (RegOpenKeyExA(root,key,0,KEY_READ,&hkey) != ERROR_SUCCESS)
 
782
    return(1);  /* no match */
 
783
  p=(BYTE *) value;
 
784
  type=REG_SZ;
 
785
  extent=(*length);
 
786
  if (p == (BYTE *) NULL)
 
787
    p=(&byte);  /* ERROR_MORE_DATA only if value is NULL */
 
788
  status=RegQueryValueExA(hkey,(char *) name,0,&type,p,&extent);
 
789
  RegCloseKey(hkey);
 
790
  if (status == ERROR_SUCCESS)
 
791
    {
 
792
      *length=extent;
 
793
      return(0);  /* return the match */
 
794
    }
 
795
  if (status == ERROR_MORE_DATA)
 
796
    {
 
797
      *length=extent;
 
798
      return(-1);  /* buffer not large enough */
900
799
    }
901
800
  return(1);  /* not found */
902
801
}
903
802
 
904
 
static int NTGhostscriptGetProductString(int gs_revision,const char *name,
905
 
  char *ptr,int len,const char *gs_productfamily)
906
 
{
907
 
  /* If using Win32, look in the registry for a value with
908
 
   * the given name.  The registry value will be under the key
909
 
   * HKEY_CURRENT_USER\Software\AFPL Ghostscript\N.NN
910
 
   * or if that fails under the key
911
 
   * HKEY_LOCAL_MACHINE\Software\AFPL Ghostscript\N.NN
912
 
   * where "AFPL Ghostscript" is actually gs_productfamily
913
 
   * and N.NN is obtained from gs_revision.
914
 
   */
915
 
 
 
803
static int NTLocateGhostscript(const char **product_family,int *major_version,
 
804
  int *minor_version)
 
805
{
 
806
  int
 
807
    i;
 
808
 
 
809
  MagickBooleanType
 
810
    status;
 
811
 
 
812
  static const char
 
813
    *products[4] =
 
814
    {
 
815
      "GPL Ghostscript",
 
816
      "GNU Ghostscript",
 
817
      "AFPL Ghostscript",
 
818
      "Aladdin Ghostscript"
 
819
    };
 
820
 
 
821
  /*
 
822
    Find the most recent version of Ghostscript.
 
823
  */
 
824
  status=FALSE;
 
825
  *product_family=NULL;
 
826
  *major_version=5;
 
827
  *minor_version=49; /* min version of Ghostscript is 5.50 */
 
828
  for (i=0; i < (long) (sizeof(products)/sizeof(products[0])); i++)
 
829
  {
 
830
    char
 
831
      key[MaxTextExtent];
 
832
 
 
833
    HKEY
 
834
      hkey,
 
835
      root;
 
836
 
 
837
    REGSAM
 
838
      mode;
 
839
 
 
840
    (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s",products[i]);
 
841
    root=HKEY_LOCAL_MACHINE;
 
842
    mode=KEY_READ;
 
843
#if defined(KEY_WOW64_32KEY)
 
844
    mode|=KEY_WOW64_32KEY;
 
845
#endif
 
846
    if (RegOpenKeyExA(root,key,0,mode,&hkey) == ERROR_SUCCESS)
 
847
      {
 
848
        DWORD
 
849
          extent;
 
850
 
 
851
        int
 
852
          j;
 
853
 
 
854
        /*
 
855
          Now enumerate the keys.
 
856
        */
 
857
        extent=sizeof(key)/sizeof(char);
 
858
        for (j=0; RegEnumKeyA(hkey,j,key,extent) == ERROR_SUCCESS; j++)
 
859
        {
 
860
          int
 
861
            major,
 
862
            minor;
 
863
 
 
864
          major=0;
 
865
          minor=0;
 
866
          if (sscanf(key,"%d.%d",&major,&minor) != 2)
 
867
            continue;
 
868
          if ((major > *major_version) || ((major == *major_version) &&
 
869
              (minor > *minor_version)))
 
870
            {
 
871
              *product_family=products[i];
 
872
              *major_version=major;
 
873
              *minor_version=minor;
 
874
              status=MagickTrue;
 
875
            }
 
876
       }
 
877
       (void) RegCloseKey(hkey);
 
878
     }
 
879
  }
 
880
  if (status == MagickFalse)
 
881
    {
 
882
      *major_version=0;
 
883
      *minor_version=0;
 
884
    }
 
885
  (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),"Ghostscript (%s) "
 
886
    "version %d.%02d",*product_family,*major_version,*minor_version);
 
887
  return(status);
 
888
}
 
889
 
 
890
static int NTGhostscriptGetString(const char *name,char *value,
 
891
  const size_t length)
 
892
{
916
893
  char
917
 
    dotversion[MaxTextExtent],
918
894
    key[MaxTextExtent];
919
895
 
920
896
  int
921
 
    code,
922
 
    length;
923
 
 
924
 
  DWORD version = GetVersion();
925
 
 
926
 
  if (((HIWORD(version) & 0x8000) != 0) && ((HIWORD(version) & 0x4000) == 0))
927
 
    {
928
 
      /* Win32s */
929
 
      return FALSE;
930
 
    }
931
 
  (void) FormatMagickString(dotversion,MaxTextExtent,"%d.%02d",(int)
932
 
    (gs_revision/100),(int) (gs_revision % 100));
933
 
  (void) FormatMagickString(key,MaxTextExtent,"Software\\%s\\%s",
934
 
    gs_productfamily,dotversion);
935
 
  length = len;
936
 
  code = NTGetRegistryValue(HKEY_CURRENT_USER, key, name, ptr, &length);
937
 
  if ( code == 0 )
938
 
    return TRUE;  /* found it */
939
 
  length = len;
940
 
  code = NTGetRegistryValue(HKEY_LOCAL_MACHINE, key, name, ptr, &length);
941
 
  if ( code == 0 )
942
 
    return TRUE;  /* found it */
943
 
  return FALSE;
944
 
}
945
 
 
946
 
static int NTGhostscriptGetString(int gs_revision,const char *name,char *ptr,
947
 
  int len)
948
 
{
949
 
  if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_AFPL))
950
 
    return(TRUE);
951
 
  if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_ALADDIN))
952
 
    return(TRUE);
953
 
  if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_GNU))
954
 
    return(TRUE);
955
 
  if (NTGhostscriptGetProductString(gs_revision,name,ptr,len,GS_PRODUCT_GPL))
956
 
    return(TRUE);
957
 
  return(FALSE);
958
 
}
959
 
 
960
 
static int NTGetLatestGhostscript( void )
961
 
{
962
 
  int
963
 
    count,
964
897
    i,
965
 
    gsver,
966
 
    *ver;
967
 
 
968
 
  DWORD version = GetVersion();
969
 
  if ( ((HIWORD(version) & 0x8000)!=0) && ((HIWORD(version) & 0x4000)==0) )
970
 
    return FALSE;  /* win32s */
971
 
 
972
 
  count = 1;
973
 
  NTGhostscriptEnumerateVersions(&count);
974
 
  if (count < 1)
975
 
    return FALSE;
976
 
  ver=(int *) AcquireQuantumMemory(count+1UL,sizeof(*ver));
977
 
  if (ver == (int *)NULL)
 
898
    extent;
 
899
 
 
900
  static const char
 
901
    *product_family = (const char *) NULL;
 
902
 
 
903
  static int
 
904
    major_version=0,
 
905
    minor_version=0;
 
906
 
 
907
  struct
 
908
  {
 
909
    const HKEY
 
910
      hkey;
 
911
 
 
912
    const char
 
913
      *name;
 
914
  }
 
915
  hkeys[2] =
 
916
  {
 
917
    { HKEY_CURRENT_USER,  "HKEY_CURRENT_USER"  },
 
918
    { HKEY_LOCAL_MACHINE, "HKEY_LOCAL_MACHINE" }
 
919
  };
 
920
 
 
921
  /*
 
922
    Get a string from the installed Ghostscript.
 
923
  */
 
924
  *value='\0';
 
925
  if (product_family == NULL)
 
926
    (void) NTLocateGhostscript(&product_family,&major_version,&minor_version);
 
927
  if (product_family == NULL)
978
928
    return(FALSE);
979
 
  ver[0]=count+1;
980
 
  if (!NTGhostscriptEnumerateVersions(ver))
981
 
    {
982
 
      ver=(int *) RelinquishMagickMemory(ver);
983
 
      return FALSE;
984
 
    }
985
 
  gsver = 0;
986
 
  for (i=1; i<=ver[0]; i++) {
987
 
    if (ver[i] > gsver)
988
 
      gsver = ver[i];
 
929
  (void) FormatMagickString(key,MaxTextExtent,"SOFTWARE\\%s\\%d.%02d",
 
930
    product_family,major_version,minor_version);
 
931
  for (i=0; i < (long) (sizeof(hkeys)/sizeof(hkeys[0])); i++)
 
932
  {
 
933
    extent=(int) length;
 
934
    if (NTGetRegistryValue(hkeys[i].hkey,key,name,value,&extent) == 0)
 
935
      {
 
936
        (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
 
937
          "registry: \"%s\\%s\\%s\"=\"%s\"",hkeys[i].name,key,name,value);
 
938
        return(TRUE);
 
939
      }
 
940
    (void) LogMagickEvent(ConfigureEvent,GetMagickModule(),
 
941
      "registry: \"%s\\%s\\%s\" (failed)",hkeys[i].name,key,name);
989
942
  }
990
 
  ver=(int *) RelinquishMagickMemory(ver);
991
 
  return(gsver);
 
943
  return(FALSE);
992
944
}
993
945
 
994
 
 
995
 
/*
996
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
997
 
%                                                                             %
998
 
%                                                                             %
999
 
%                                                                             %
1000
 
%   N T G h o s t s c r i p t D L L                                           %
1001
 
%                                                                             %
1002
 
%                                                                             %
1003
 
%                                                                             %
1004
 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1005
 
%
1006
 
%  NTGhostscriptDLL() obtains the path to the latest Ghostscript DLL.  The
1007
 
%  method returns MagickFalse if a value is not obtained.
1008
 
%
1009
 
%  The format of the NTGhostscriptDLL method is:
1010
 
%
1011
 
%      int NTGhostscriptDLL( char *path, int length)
1012
 
%
1013
 
%  A description of each parameter follows:
1014
 
%
1015
 
%    o path: Pointer to path buffer to update
1016
 
%
1017
 
%    o length: Allocation size of path buffer.
1018
 
%
1019
 
*/
1020
 
MagickExport int NTGhostscriptDLL(char *path, int length)
 
946
MagickExport int NTGhostscriptDLL(char *path,int length)
1021
947
{
1022
 
  int
1023
 
    gsver;
1024
 
 
1025
 
  char
1026
 
    buf[256];
 
948
  static char
 
949
    dll[MaxTextExtent] = { "" };
1027
950
 
1028
951
  *path='\0';
1029
 
  gsver = NTGetLatestGhostscript();
1030
 
  if ((gsver == FALSE) || (gsver < GS_MINIMUM_VERSION))
1031
 
    return FALSE;
1032
 
 
1033
 
  if (!NTGhostscriptGetString(gsver, "GS_DLL", buf, sizeof(buf)))
1034
 
    return FALSE;
1035
 
 
1036
 
  (void) CopyMagickString(path,buf,length+1);
 
952
  if ((*dll == '\0') &&
 
953
      (NTGhostscriptGetString("GS_DLL",dll,sizeof(dll)) == FALSE))
 
954
    return(FALSE);
 
955
  (void) CopyMagickString(path,dll,length);
1037
956
  return(TRUE);
1038
957
}
1039
958
 
1048
967
%                                                                             %
1049
968
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1050
969
%
1051
 
%  NTGhostscriptDLLVectors() returns a GhostscriptVectors structure containing
 
970
%  NTGhostscriptDLLVectors() returns a GhostInfo structure that includes
1052
971
%  function vectors to invoke Ghostscript DLL functions. A null pointer is
1053
 
%  returned if there is an error with loading the DLL or retrieving the
 
972
%  returned if there is an error when loading the DLL or retrieving the
1054
973
%  function vectors.
1055
974
%
1056
975
%  The format of the NTGhostscriptDLLVectors method is:
1057
976
%
1058
 
%      const GhostscriptVectors *NTGhostscriptDLLVectors(void)
 
977
%      const GhostInfo *NTGhostscriptDLLVectors(void)
1059
978
%
1060
979
*/
1061
 
MagickExport const GhostscriptVectors *NTGhostscriptDLLVectors( void )
 
980
MagickExport const GhostInfo *NTGhostscriptDLLVectors(void)
1062
981
{
1063
 
  if (NTGhostscriptLoadDLL())
1064
 
    return(&gs_vectors);
1065
 
  return((GhostscriptVectors*) NULL);
 
982
  if (NTGhostscriptLoadDLL() == FALSE)
 
983
    return((GhostInfo *) NULL);
 
984
  return(&ghost_info);
1066
985
}
1067
986
 
1068
987
/*
1077
996
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1078
997
%
1079
998
%  NTGhostscriptEXE() obtains the path to the latest Ghostscript executable.
1080
 
%  The method returns MagickFalse if a value is not obtained.
 
999
%  The method returns FALSE if a full path value is not obtained and returns
 
1000
%  a default path of gswin32c.exe.
1081
1001
%
1082
1002
%  The format of the NTGhostscriptEXE method is:
1083
1003
%
1084
 
%      int NTGhostscriptEXE(char *path, int length)
 
1004
%      int NTGhostscriptEXE(char *path,int length)
1085
1005
%
1086
1006
%  A description of each parameter follows:
1087
1007
%
1088
 
%    o path: Pointer to buffer in which to return result.
 
1008
%    o path: return the Ghostscript executable path here.
1089
1009
%
1090
 
%    o length: Length of buffer
 
1010
%    o length: length of buffer.
1091
1011
%
1092
1012
*/
1093
1013
MagickExport int NTGhostscriptEXE(char *path,int length)
1094
1014
{
1095
 
  int
1096
 
    gsver;
1097
 
 
1098
 
  char
1099
 
    buf[256],
 
1015
  register char
1100
1016
    *p;
1101
1017
 
 
1018
  static char
 
1019
    program[MaxTextExtent] = { "" };
 
1020
 
1102
1021
  (void) CopyMagickString(path,"gswin32c.exe",length);
1103
 
  gsver=NTGetLatestGhostscript();
1104
 
  if ((gsver == FALSE) || (gsver < GS_MINIMUM_VERSION))
1105
 
    return(FALSE);
1106
 
  if (!NTGhostscriptGetString(gsver, "GS_DLL", buf, sizeof(buf)))
1107
 
    return(FALSE);
1108
 
  p=strrchr(buf, '\\');
1109
 
  if (p) {
1110
 
    p++;
1111
 
    *p = 0;
1112
 
    (void) CopyMagickString(p,"gswin32c.exe",sizeof(buf));
1113
 
    (void) CopyMagickString(path,buf,length+1);
1114
 
    return TRUE;
1115
 
  }
1116
 
 
1117
 
  return FALSE;
 
1022
  if ((*program == '\0') &&
 
1023
      (NTGhostscriptGetString("GS_DLL",program,sizeof(program)) == FALSE))
 
1024
    return(FALSE);
 
1025
  p=strrchr(program,'\\');
 
1026
  if (p != (char *) NULL)
 
1027
    {
 
1028
      p++;
 
1029
      *p='\0';
 
1030
      (void) ConcatenateMagickString(program,"gswin32c.exe",sizeof(program));
 
1031
    }
 
1032
  (void) CopyMagickString(path,program,length);
 
1033
  return(TRUE);
1118
1034
}
1119
1035
 
1120
1036
/*
1128
1044
%                                                                             %
1129
1045
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1130
1046
%
1131
 
%  NTGhostscriptFonts() gets the path to the Ghostscript fonts.  The method
1132
 
%  returns MagickFalse if an error occurs otherwise MagickTrue.
 
1047
%  NTGhostscriptFonts() obtains the path to the Ghostscript fonts.  The method
 
1048
%  returns FALSE if it cannot determine the font path.
1133
1049
%
1134
1050
%  The format of the NTGhostscriptFonts method is:
1135
1051
%
1136
 
%      int NTGhostscriptFonts(char *path,int length)
 
1052
%      int NTGhostscriptFonts(char *path, int length)
1137
1053
%
1138
1054
%  A description of each parameter follows:
1139
1055
%
1140
 
%    o path: Pointer to buffer in which to return result.
 
1056
%    o path: return the font path here.
1141
1057
%
1142
 
%    o length: Length of buffer.
 
1058
%    o length: length of the path buffer.
1143
1059
%
1144
1060
*/
1145
1061
MagickExport int NTGhostscriptFonts(char *path,int length)
1148
1064
    buffer[MaxTextExtent],
1149
1065
    filename[MaxTextExtent];
1150
1066
 
1151
 
  int
1152
 
    version;
1153
 
 
1154
1067
  register char
1155
1068
    *p,
1156
1069
    *q;
1157
1070
 
1158
1071
  *path='\0';
1159
 
  version=NTGetLatestGhostscript();
1160
 
  if ((version == FALSE) || (version < GS_MINIMUM_VERSION))
1161
 
    return(FALSE);
1162
 
  if (!NTGhostscriptGetString(version,"GS_LIB",buffer,MaxTextExtent))
 
1072
  if (NTGhostscriptGetString("GS_LIB",buffer,MaxTextExtent) == FALSE)
1163
1073
    return(FALSE);
1164
1074
  for (p=buffer-1; p != (char *) NULL; p=strchr(p+1,DirectoryListSeparator))
1165
1075
  {
1167
1077
    q=strchr(path,DirectoryListSeparator);
1168
1078
    if (q != (char *) NULL)
1169
1079
      *q='\0';
1170
 
    FormatMagickString(filename,MaxTextExtent,"%s%sfonts.dir",path,
 
1080
    (void) FormatMagickString(filename,MaxTextExtent,"%s%sfonts.dir",path,
1171
1081
      DirectorySeparator);
1172
1082
    if (IsPathAccessible(filename) != MagickFalse)
1173
1083
      return(TRUE);
1187
1097
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1188
1098
%
1189
1099
%  NTGhostscriptLoadDLL() attempts to load the Ghostscript DLL and returns
1190
 
%  MagickTrue if it succeeds.
 
1100
%  TRUE if it succeeds.
1191
1101
%
1192
1102
%  The format of the NTGhostscriptLoadDLL method is:
1193
1103
%
1197
1107
MagickExport int NTGhostscriptLoadDLL(void)
1198
1108
{
1199
1109
  char
1200
 
    module_path[MaxTextExtent];
 
1110
    path[MaxTextExtent];
1201
1111
 
1202
 
  if (gs_dll_handle != (void *) NULL)
1203
 
    return(MagickTrue);
1204
 
  if (NTGhostscriptDLL(module_path,sizeof(module_path)) == MagickFalse)
1205
 
    return(MagickFalse);
1206
 
  gs_dll_handle=NTOpenLibrary(module_path);
1207
 
  if (gs_dll_handle == (void *) NULL)
1208
 
    return(MagickFalse);
1209
 
  (void) ResetMagickMemory((void *) &gs_vectors,0,sizeof(GhostscriptVectors));
1210
 
  gs_vectors.exit=(int (MagickDLLCall *)
1211
 
    (gs_main_instance *)) NTGetLibrarySymbol(gs_dll_handle,"gsapi_exit");
1212
 
  gs_vectors.init_with_args=(int (MagickDLLCall *)
1213
 
    (gs_main_instance *,int,char **))
1214
 
    (NTGetLibrarySymbol(gs_dll_handle,"gsapi_init_with_args"));
1215
 
  gs_vectors.new_instance=(int (MagickDLLCall *) (gs_main_instance **,void *))
1216
 
    (NTGetLibrarySymbol(gs_dll_handle,"gsapi_new_instance"));
1217
 
  gs_vectors.run_string=(int (MagickDLLCall *)
1218
 
    (gs_main_instance *,const char *,int,int *))
1219
 
    (NTGetLibrarySymbol(gs_dll_handle,"gsapi_run_string"));
1220
 
  gs_vectors.delete_instance=(void (MagickDLLCall *)(gs_main_instance *))
1221
 
    (NTGetLibrarySymbol(gs_dll_handle,"gsapi_delete_instance"));
1222
 
  if ((gs_vectors.exit == NULL) ||
1223
 
      (gs_vectors.init_with_args == NULL) ||
1224
 
      (gs_vectors.new_instance == NULL) ||
1225
 
      (gs_vectors.run_string == NULL) ||
1226
 
      (gs_vectors.delete_instance == NULL))
1227
 
    return(MagickFalse);
1228
 
  return(MagickTrue);
 
1112
  if (ghost_handle != (void *) NULL)
 
1113
    return(TRUE);
 
1114
  if (NTGhostscriptDLL(path,sizeof(path)) == FALSE)
 
1115
    return(FALSE);
 
1116
  ghost_handle=lt_dlopen(path);
 
1117
  if (ghost_handle == (void *) NULL)
 
1118
    return(FALSE);
 
1119
  (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
 
1120
  ghost_info.exit=(int (MagickDLLCall *)(gs_main_instance*))
 
1121
    lt_dlsym(ghost_handle,"gsapi_exit");
 
1122
  ghost_info.init_with_args=(int (MagickDLLCall *)(gs_main_instance *,int,
 
1123
    char **)) (lt_dlsym(ghost_handle,"gsapi_init_with_args"));
 
1124
  ghost_info.new_instance=(int (MagickDLLCall *)(gs_main_instance **,void *)) (
 
1125
    lt_dlsym(ghost_handle,"gsapi_new_instance"));
 
1126
  ghost_info.run_string=(int (MagickDLLCall *)(gs_main_instance *,const char *,
 
1127
    int,int *)) (lt_dlsym(ghost_handle,"gsapi_run_string"));
 
1128
  ghost_info.delete_instance=(void (MagickDLLCall *) (gs_main_instance *)) (
 
1129
    lt_dlsym(ghost_handle,"gsapi_delete_instance"));
 
1130
  if ((ghost_info.exit == NULL) || (ghost_info.init_with_args == NULL) ||
 
1131
      (ghost_info.new_instance == NULL) || (ghost_info.run_string == NULL) ||
 
1132
      (ghost_info.delete_instance == NULL))
 
1133
    return(FALSE);
 
1134
  return(TRUE);
1229
1135
}
1230
1136
 
1231
1137
/*
1239
1145
%                                                                             %
1240
1146
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
1241
1147
%
1242
 
%  NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL if it is loaded.
 
1148
%  NTGhostscriptUnLoadDLL() unloads the Ghostscript DLL and returns TRUE if
 
1149
%  it succeeds.
1243
1150
%
1244
1151
%  The format of the NTGhostscriptUnLoadDLL method is:
1245
1152
%
1248
1155
*/
1249
1156
MagickExport int NTGhostscriptUnLoadDLL(void)
1250
1157
{
1251
 
  if (gs_dll_handle == (void *) NULL)
1252
 
    return(MagickFalse);
1253
 
  NTCloseLibrary(gs_dll_handle);
1254
 
  gs_dll_handle=(void *) NULL;
1255
 
  (void) ResetMagickMemory((void *) &gs_vectors,0,sizeof(GhostscriptVectors));
1256
 
  return(MagickTrue);
 
1158
  int
 
1159
    status;
 
1160
 
 
1161
  if (ghost_handle == (void *) NULL)
 
1162
    return(FALSE);
 
1163
  status=lt_dlclose(ghost_handle);
 
1164
  ghost_handle=(void *) NULL;
 
1165
  (void) ResetMagickMemory((void *) &ghost_info,0,sizeof(GhostInfo));
 
1166
  return(status);
1257
1167
}
1258
1168
 
1259
1169
/*
1316
1226
  void
1317
1227
    *map;
1318
1228
 
 
1229
  (void) address;
1319
1230
  access_mode=0;
1320
1231
  file_handle=INVALID_HANDLE_VALUE;
1321
1232
  low_length=(DWORD) (length & 0xFFFFFFFFUL);
1811
1722
*/
1812
1723
MagickExport void NTSeekDirectory(DIR *entry,long position)
1813
1724
{
 
1725
  (void) position;
1814
1726
  (void) LogMagickEvent(TraceEvent,GetMagickModule(),"...");
1815
1727
  assert(entry != (DIR *) NULL);
1816
1728
}
1880
1792
*/
1881
1793
MagickExport int NTSyncMemory(void *address,size_t length,int flags)
1882
1794
{
 
1795
  (void) flags;
1883
1796
  if (FlushViewOfFile(address,length) == MagickFalse)
1884
1797
    return(-1);
1885
1798
  return(0);
1899
1812
%  NTSystemCommand() executes the specified command and waits until it
1900
1813
%  terminates.  The returned value is the exit status of the command.
1901
1814
%
1902
 
%  The format of the NTSystemComman method is:
 
1815
%  The format of the NTSystemCommand method is:
1903
1816
%
1904
 
%      int NTSystemComman(const char *command)
 
1817
%      int NTSystemCommand(const char *command)
1905
1818
%
1906
1819
%  A description of each parameter follows:
1907
1820
%
1952
1865
    return(status == 0);
1953
1866
  status=WaitForSingleObject(process_info.hProcess,INFINITE);
1954
1867
  if (status != WAIT_OBJECT_0)
1955
 
    return (status);
 
1868
    return(status);
1956
1869
  status=GetExitCodeProcess(process_info.hProcess,&child_status);
1957
1870
  if (status == 0)
1958
1871
    return(-1);
2138
2051
*/
2139
2052
MagickExport int NTUnmapMemory(void *map,size_t length)
2140
2053
{
 
2054
  (void) length;
2141
2055
  if (UnmapViewOfFile(map) == 0)
2142
2056
    return(-1);
2143
2057
  return(0);
2218
2132
%
2219
2133
%  The format of the NTWarningHandler method is:
2220
2134
%
2221
 
%      void NTWarningHandler(const ExceptionType warning,const char *reason,
 
2135
%      void NTWarningHandler(const ExceptionType severity,const char *reason,
2222
2136
%        const char *description)
2223
2137
%
2224
2138
%  A description of each parameter follows:
2225
2139
%
2226
 
%    o warning: Specifies the numeric warning category.
 
2140
%    o severity: Specifies the numeric warning category.
2227
2141
%
2228
2142
%    o reason: Specifies the reason to display before terminating the
2229
2143
%      program.
2231
2145
%    o description: Specifies any description to the reason.
2232
2146
%
2233
2147
*/
2234
 
MagickExport void NTWarningHandler(const ExceptionType warning,
 
2148
MagickExport void NTWarningHandler(const ExceptionType severity,
2235
2149
  const char *reason,const char *description)
2236
2150
{
2237
2151
  char
2238
2152
    buffer[2*MaxTextExtent];
2239
2153
 
 
2154
  (void) severity;
2240
2155
  if (reason == (char *) NULL)
2241
2156
    return;
2242
2157
  if (description == (char *) NULL)