Browse Source

postgresql封装

Jeff 6 years ago
parent
commit
b456da451c
100 changed files with 22533 additions and 0 deletions
  1. BIN
      libpq_test/exe所需的dll/libeay32.dll
  2. BIN
      libpq_test/exe所需的dll/libiconv-2.dll
  3. BIN
      libpq_test/exe所需的dll/libintl-8.dll
  4. BIN
      libpq_test/exe所需的dll/libpq.dll
  5. BIN
      libpq_test/exe所需的dll/ssleay32.dll
  6. 67 0
      libpq_test/include/autosprintf.h
  7. 87 0
      libpq_test/include/cpl_atomic_ops.h
  8. 233 0
      libpq_test/include/cpl_config.h
  9. 40 0
      libpq_test/include/cpl_config_extras.h
  10. 278 0
      libpq_test/include/cpl_conv.h
  11. 71 0
      libpq_test/include/cpl_csv.h
  12. 135 0
      libpq_test/include/cpl_error.h
  13. 92 0
      libpq_test/include/cpl_hash_set.h
  14. 105 0
      libpq_test/include/cpl_http.h
  15. 72 0
      libpq_test/include/cpl_list.h
  16. 160 0
      libpq_test/include/cpl_minixml.h
  17. 90 0
      libpq_test/include/cpl_minizip_ioapi.h
  18. 381 0
      libpq_test/include/cpl_minizip_unzip.h
  19. 259 0
      libpq_test/include/cpl_minizip_zip.h
  20. 228 0
      libpq_test/include/cpl_multiproc.h
  21. 288 0
      libpq_test/include/cpl_odbc.h
  22. 625 0
      libpq_test/include/cpl_port.h
  23. 47 0
      libpq_test/include/cpl_progress.h
  24. 100 0
      libpq_test/include/cpl_quad_tree.h
  25. 79 0
      libpq_test/include/cpl_spawn.h
  26. 376 0
      libpq_test/include/cpl_string.h
  27. 41 0
      libpq_test/include/cpl_time.h
  28. 389 0
      libpq_test/include/cpl_virtualmem.h
  29. 284 0
      libpq_test/include/cpl_vsi.h
  30. 202 0
      libpq_test/include/cpl_vsi_virtual.h
  31. 49 0
      libpq_test/include/cpl_vsil_curl_priv.h
  32. 105 0
      libpq_test/include/cpl_win32ce_api.h
  33. 44 0
      libpq_test/include/cpl_wince.h
  34. 66 0
      libpq_test/include/cplkeywordparser.h
  35. 19 0
      libpq_test/include/dynloader.h
  36. 5 0
      libpq_test/include/ecpg_config.h
  37. 90 0
      libpq_test/include/ecpg_informix.h
  38. 79 0
      libpq_test/include/ecpgerrno.h
  39. 100 0
      libpq_test/include/ecpglib.h
  40. 106 0
      libpq_test/include/ecpgtype.h
  41. 45 0
      libpq_test/include/evdns.h
  42. 85 0
      libpq_test/include/event.h
  43. 45 0
      libpq_test/include/evhttp.h
  44. 45 0
      libpq_test/include/evrpc.h
  45. 39 0
      libpq_test/include/evutil.h
  46. 1090 0
      libpq_test/include/gdal.h
  47. 482 0
      libpq_test/include/gdal_alg.h
  48. 229 0
      libpq_test/include/gdal_alg_priv.h
  49. 41 0
      libpq_test/include/gdal_csv.h
  50. 187 0
      libpq_test/include/gdal_frmts.h
  51. 207 0
      libpq_test/include/gdal_mdreader.h
  52. 316 0
      libpq_test/include/gdal_pam.h
  53. 1237 0
      libpq_test/include/gdal_priv.h
  54. 384 0
      libpq_test/include/gdal_proxy.h
  55. 349 0
      libpq_test/include/gdal_rat.h
  56. 554 0
      libpq_test/include/gdal_simplesurf.h
  57. 29 0
      libpq_test/include/gdal_version.h
  58. 105 0
      libpq_test/include/gdal_vrt.h
  59. 241 0
      libpq_test/include/gdalexif.h
  60. 57 0
      libpq_test/include/gdalgeorefpamdataset.h
  61. 122 0
      libpq_test/include/gdalgrid.h
  62. 99 0
      libpq_test/include/gdalgrid_priv.h
  63. 60 0
      libpq_test/include/gdaljp2abstractdataset.h
  64. 196 0
      libpq_test/include/gdaljp2metadata.h
  65. 40 0
      libpq_test/include/gdaljp2metadatagenerator.h
  66. 571 0
      libpq_test/include/gdalsse_priv.h
  67. 450 0
      libpq_test/include/gdalwarper.h
  68. 198 0
      libpq_test/include/gdalwarpkernel_opencl.h
  69. 781 0
      libpq_test/include/geodesic.h
  70. 35 0
      libpq_test/include/geos.h
  71. 1850 0
      libpq_test/include/geos_c.h
  72. 94 0
      libpq_test/include/gvgcpfit.h
  73. 242 0
      libpq_test/include/iconv.h
  74. 14 0
      libpq_test/include/informix/esql/datetime.h
  75. 13 0
      libpq_test/include/informix/esql/decimal.h
  76. 57 0
      libpq_test/include/informix/esql/sqltypes.h
  77. 1107 0
      libpq_test/include/internal/c.h
  78. 675 0
      libpq_test/include/internal/libpq-int.h
  79. 206 0
      libpq_test/include/internal/libpq/pqcomm.h
  80. 477 0
      libpq_test/include/internal/port.h
  81. 29 0
      libpq_test/include/internal/postgres_fe.h
  82. 182 0
      libpq_test/include/internal/pqexpbuffer.h
  83. 46 0
      libpq_test/include/libcharset.h
  84. 464 0
      libpq_test/include/libintl.h
  85. 94 0
      libpq_test/include/libpq-events.h
  86. 607 0
      libpq_test/include/libpq-fe.h
  87. 24 0
      libpq_test/include/libpq/libpq-fs.h
  88. 96 0
      libpq_test/include/libxml/DOCBparser.h
  89. 306 0
      libpq_test/include/libxml/HTMLparser.h
  90. 147 0
      libpq_test/include/libxml/HTMLtree.h
  91. 173 0
      libpq_test/include/libxml/SAX.h
  92. 178 0
      libpq_test/include/libxml/SAX2.h
  93. 126 0
      libpq_test/include/libxml/c14n.h
  94. 182 0
      libpq_test/include/libxml/catalog.h
  95. 230 0
      libpq_test/include/libxml/chvalid.h
  96. 217 0
      libpq_test/include/libxml/debugXML.h
  97. 86 0
      libpq_test/include/libxml/dict.h
  98. 240 0
      libpq_test/include/libxml/encoding.h
  99. 151 0
      libpq_test/include/libxml/entities.h
  100. 509 0
      libpq_test/include/libxml/globals.h

BIN
libpq_test/exe所需的dll/libeay32.dll


BIN
libpq_test/exe所需的dll/libiconv-2.dll


BIN
libpq_test/exe所需的dll/libintl-8.dll


BIN
libpq_test/exe所需的dll/libpq.dll


BIN
libpq_test/exe所需的dll/ssleay32.dll


+ 67 - 0
libpq_test/include/autosprintf.h

@@ -0,0 +1,67 @@
+/* Class autosprintf - formatted output to an ostream.
+   Copyright (C) 2002, 2012, 2013 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef _AUTOSPRINTF_H
+#define _AUTOSPRINTF_H
+
+/* This feature is available in gcc versions 2.5 and later.  */
+#if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 5) || __STRICT_ANSI__
+# define _AUTOSPRINTF_ATTRIBUTE_FORMAT() /* empty */
+#else
+/* The __-protected variants of 'format' and 'printf' attributes
+   are accepted by gcc versions 2.6.4 (effectively 2.7) and later.  */
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 7)
+#  define _AUTOSPRINTF_ATTRIBUTE_FORMAT() \
+  __attribute__ ((__format__ (__printf__, 2, 3)))
+# else
+#  define _AUTOSPRINTF_ATTRIBUTE_FORMAT() \
+  __attribute__ ((format (printf, 2, 3)))
+# endif
+#endif
+
+#include <string>
+#include <iostream>
+
+namespace gnu
+{
+  /* A temporary object, usually allocated on the stack, representing
+     the result of an asprintf() call.  */
+  class autosprintf
+  {
+  public:
+    /* Constructor: takes a format string and the printf arguments.  */
+    autosprintf (const char *format, ...)
+                _AUTOSPRINTF_ATTRIBUTE_FORMAT();
+    /* Copy constructor.  */
+    autosprintf (const autosprintf& src);
+    autosprintf& operator = (autosprintf copy);
+    /* Destructor: frees the temporarily allocated string.  */
+    ~autosprintf ();
+    /* Conversion to string.  */
+    operator char * () const;
+    operator std::string () const;
+    /* Output to an ostream.  */
+    friend inline std::ostream& operator<< (std::ostream& stream, const autosprintf& tmp)
+    {
+      stream << (tmp.str ? tmp.str : "(error in autosprintf)");
+      return stream;
+    }
+  private:
+    char *str;
+  };
+}
+
+#endif /* _AUTOSPRINTF_H */

+ 87 - 0
libpq_test/include/cpl_atomic_ops.h

@@ -0,0 +1,87 @@
+/**********************************************************************
+ * $Id: cpl_atomic_ops.h 27869 2014-10-17 02:22:42Z rouault $
+ *
+ * Name:     cpl_atomic_ops.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Atomic operation functions.
+ * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
+ *
+ **********************************************************************
+ * Copyright (c) 2009-2010, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_ATOMIC_OPS_INCLUDED
+#define _CPL_ATOMIC_OPS_INCLUDED
+
+#include "cpl_port.h"
+
+CPL_C_START
+
+/** Add a value to a pointed integer in a thread and SMP-safe way
+  * and return the resulting value of the operation.
+  *
+  * This function, which in most cases is implemented by a few
+  * efficient machine instructions, guarantees that the value pointed
+  * by ptr will be incremented in a thread and SMP-safe way.
+  * The variables for this function must be aligned on a 32-bit boundary.
+  *
+  * Depending on the platforms, this function can also act as a
+  * memory barrier, but this should not be assumed.
+  *
+  * Current platforms/architectures where an efficient implementation
+  * exists are MacOSX, MS Windows, i386/x86_64 with GCC and platforms
+  * supported by GCC 4.1 or higher. For other platforms supporting
+  * the pthread library, and when GDAL is configured with thread-support,
+  * the atomicity will be done with a mutex, but with
+  * reduced efficiently. For the remaining platforms, a simple addition
+  * with no locking will be done...
+  *
+  * @param ptr a pointer to an integer to increment
+  * @param increment the amount to add to the pointed integer
+  * @return the pointed value AFTER the result of the addition
+  */
+int CPL_DLL CPLAtomicAdd(volatile int* ptr, int increment);
+
+/** Increment of 1 the pointed integer in a thread and SMP-safe way
+  * and return the resulting value of the operation.
+  *
+  * @see CPLAtomicAdd for the details and guarantees of this atomic
+  *      operation
+  *
+  * @param ptr a pointer to an integer to increment
+  * @return the pointed value AFTER the opeation: *ptr + 1
+  */
+#define CPLAtomicInc(ptr) CPLAtomicAdd(ptr, 1)
+
+/** Decrement of 1 the pointed integer in a thread and SMP-safe way
+  * and return the resulting value of the operation.
+  *
+  * @see CPLAtomicAdd for the details and guarantees of this atomic
+  *      operation
+  *
+  * @param ptr a pointer to an integer to decrement
+  * @return the pointed value AFTER the opeation: *ptr - 1
+  */
+#define CPLAtomicDec(ptr) CPLAtomicAdd(ptr, -1)
+
+CPL_C_END
+
+#endif /* _CPL_ATOMIC_OPS_INCLUDED */

+ 233 - 0
libpq_test/include/cpl_config.h

@@ -0,0 +1,233 @@
+/* port/cpl_config.h.  Generated from cpl_config.h.in by configure.  */
+/* port/cpl_config.h.in.  Generated from configure.in by autoheader.  */
+
+/* Define if you want to use pthreads based multiprocessing support */
+/* #undef CPL_MULTIPROC_PTHREAD */
+
+/* Define to 1 if you have the `PTHREAD_MUTEX_RECURSIVE' constant. */
+/* #undef HAVE_PTHREAD_MUTEX_RECURSIVE */
+
+/* Define to 1 if you have the `PTHREAD_MUTEX_ADAPTIVE_NP' constant. */
+/* #undef HAVE_PTHREAD_MUTEX_ADAPTIVE_NP */
+
+/* Define to 1 if you have the `pthread_spinlock_t' type. */
+/* #undef HAVE_PTHREAD_SPINLOCK */
+
+/* Define to 1 if you have the 5 args `mremap' function. */
+/* #undef HAVE_5ARGS_MREMAP */
+
+/* --prefix directory for GDAL install */
+#define GDAL_PREFIX "/c/pgBuild32"
+
+/* Define to 1 if you have the <assert.h> header file. */
+#define HAVE_ASSERT_H 1
+
+/* Define to 1 if you have the `atoll' function. */
+#define HAVE_ATOLL 1
+
+/* Define to 1 if you have the <csf.h> header file. */
+/* #undef HAVE_CSF_H */
+
+/* Define to 1 if you have the <dbmalloc.h> header file. */
+/* #undef HAVE_DBMALLOC_H */
+
+/* Define to 1 if you have the declaration of `strtof', and to 0 if you don't.
+   */
+#define HAVE_DECL_STRTOF 1
+
+/* Define to 1 if you have the <direct.h> header file. */
+#define HAVE_DIRECT_H 1
+
+/* Define to 1 if you have the <dlfcn.h> header file. */
+/* #undef HAVE_DLFCN_H */
+
+/* Define to 1 if you don't have `vprintf' but do have `_doprnt.' */
+/* #undef HAVE_DOPRNT */
+
+/* Define to 1 if you have the <errno.h> header file. */
+#define HAVE_ERRNO_H 1
+
+/* Define to 1 if you have the <fcntl.h> header file. */
+#define HAVE_FCNTL_H 1
+
+/* Define to 1 if you have the <float.h> header file. */
+#define HAVE_FLOAT_H 1
+
+/* Define to 1 if you have the `getcwd' function. */
+#define HAVE_GETCWD 1
+
+/* Define if you have the iconv() function and it works. */
+/* #undef HAVE_ICONV */
+
+/* Define as 0 or 1 according to the floating point format suported by the
+   machine */
+#define HAVE_IEEEFP 1
+
+/* Define to 1 if the system has the type `int16'. */
+/* #undef HAVE_INT16 */
+
+/* Define to 1 if the system has the type `int32'. */
+/* #undef HAVE_INT32 */
+
+/* Define to 1 if the system has the type `int8'. */
+/* #undef HAVE_INT8 */
+
+/* Define to 1 if you have the <inttypes.h> header file. */
+#define HAVE_INTTYPES_H 1
+
+/* Define to 1 if you have the <jpeglib.h> header file. */
+/* #undef HAVE_JPEGLIB_H */
+
+/* Define to 1 if you have the `dl' library (-ldl). */
+/* #undef HAVE_LIBDL */
+
+/* Define to 1 if you have the `m' library (-lm). */
+/* #undef HAVE_LIBM */
+
+/* Define to 1 if you have the `pq' library (-lpq). */
+/* #undef HAVE_LIBPQ */
+
+/* Define to 1 if you have the `rt' library (-lrt). */
+/* #undef HAVE_LIBRT */
+
+/* Define to 1 if you have the <limits.h> header file. */
+#define HAVE_LIMITS_H 1
+
+/* Define to 1 if you have the <locale.h> header file. */
+#define HAVE_LOCALE_H 1
+
+/* Define to 1, if your compiler supports long long data type */
+#define HAVE_LONG_LONG 1
+
+/* Define to 1 if you have the <memory.h> header file. */
+#define HAVE_MEMORY_H 1
+
+/* Define to 1 if you have the <png.h> header file. */
+/* #undef HAVE_PNG_H */
+
+/* Define to 1 if you have the `snprintf' function. */
+#define HAVE_SNPRINTF 1
+
+/* Define to 1 if you have the <stdint.h> header file. */
+#define HAVE_STDINT_H 1
+
+/* Define to 1 if you have the <stdlib.h> header file. */
+#define HAVE_STDLIB_H 1
+
+/* Define to 1 if you have the <strings.h> header file. */
+#define HAVE_STRINGS_H 1
+
+/* Define to 1 if you have the <string.h> header file. */
+#define HAVE_STRING_H 1
+
+/* Define to 1 if you have the `strtof' function. */
+#define HAVE_STRTOF 1
+
+/* Define to 1 if you have the <sys/stat.h> header file. */
+#define HAVE_SYS_STAT_H 1
+
+/* Define to 1 if you have the <sys/types.h> header file. */
+#define HAVE_SYS_TYPES_H 1
+
+/* Define to 1 if you have the <unistd.h> header file. */
+#define HAVE_UNISTD_H 1
+
+/* Define to 1 if you have the <values.h> header file. */
+#define HAVE_VALUES_H 1
+
+/* Define to 1 if you have the `vprintf' function. */
+#define HAVE_VPRINTF 1
+
+/* Define to 1 if you have the `vsnprintf' function. */
+#define HAVE_VSNPRINTF 1
+
+/* Define to 1 if you have the `readlink' function. */
+/* #undef HAVE_READLINK */
+
+/* Define to 1 if you have the `posix_spawnp' function. */
+/* #undef HAVE_POSIX_SPAWNP */
+
+/* Define to 1 if you have the `vfork' function. */
+/* #undef HAVE_VFORK */
+
+/* Define to 1 if you have the `lstat' function. */
+/* #undef HAVE_LSTAT */
+
+/* Set the native cpu bit order (FILLORDER_LSB2MSB or FILLORDER_MSB2LSB) */
+#define HOST_FILLORDER FILLORDER_LSB2MSB
+
+/* Define as const if the declaration of iconv() needs const. */
+/* #undef ICONV_CONST */
+
+/* For .cpp files, define as const if the declaration of iconv() needs const. */
+/* #undef ICONV_CPP_CONST */
+
+/* Define to the sub-directory in which libtool stores uninstalled libraries.
+   */
+#define LT_OBJDIR ".libs/"
+
+/* Define for Mac OSX Framework build */
+/* #undef MACOSX_FRAMEWORK */
+
+/* The size of `int', as computed by sizeof. */
+#define SIZEOF_INT 4
+
+/* The size of `long', as computed by sizeof. */
+/* #undef SIZEOF_LONG */
+
+/* The size of `unsigned long', as computed by sizeof. */
+#define SIZEOF_UNSIGNED_LONG 4
+
+/* The size of `void*', as computed by sizeof. */
+#define SIZEOF_VOIDP 4
+
+/* Define to 1 if you have the ANSI C header files. */
+#define STDC_HEADERS 1
+
+/* Define to 1 if you have fseek64, ftell64 */
+/* #undef UNIX_STDIO_64 */
+
+/* Define to 1 if you want to use the -fvisibility GCC flag */
+/* #undef USE_GCC_VISIBILITY_FLAG */
+
+/* Define to 1 if GCC atomic builtins are available */
+/* #undef HAVE_GCC_ATOMIC_BUILTINS */
+
+/* Define to name of 64bit fopen function */
+/* #undef VSI_FOPEN64 */
+
+/* Define to name of 64bit ftruncate function */
+/* #undef VSI_FTRUNCATE64 */
+
+/* Define to name of 64bit fseek func */
+/* #undef VSI_FSEEK64 */
+
+/* Define to name of 64bit ftell func */
+/* #undef VSI_FTELL64 */
+
+/* Define to 1, if you have 64 bit STDIO API */
+/* #undef VSI_LARGE_API_SUPPORTED */
+
+/* Define to 1, if you have LARGEFILE64_SOURCE */
+/* #undef VSI_NEED_LARGEFILE64_SOURCE */
+
+/* Define to name of 64bit stat function */
+#define VSI_STAT64 _stat64
+
+/* Define to name of 64bit stat structure */
+#define VSI_STAT64_T __stat64
+
+/* Define to 1 if your processor stores words with the most significant byte
+   first (like Motorola and SPARC, unlike Intel and VAX). */
+/* #undef WORDS_BIGENDIAN */
+
+/* Define to 1 if you have the `getaddrinfo' function. */
+/* #undef HAVE_GETADDRINFO */
+
+/* Define to 1 if you have the _SC_PHYS_PAGES' constant. */
+/* #undef HAVE_SC_PHYS_PAGES */
+
+/* Use this file to override settings in instances where you're doing FAT compiles
+   on Apple.  It is currently off by default because it doesn't seem to work with 
+   newish ( XCode >= 3/28/11) XCodes */
+/* #include "cpl_config_extras.h" */

+ 40 - 0
libpq_test/include/cpl_config_extras.h

@@ -0,0 +1,40 @@
+
+#ifndef INCLUDED_CPL_CONFIG_EXTRAS
+#define INCLUDED_CPL_CONFIG_EXTRAS
+
+#if defined(__APPLE__)
+
+#ifdef __BIG_ENDIAN__
+  #define HOST_FILLORDER FILLORDER_MSB2LSB
+#else
+  #define HOST_FILLORDER FILLORDER_LSB2MSB
+#endif
+
+
+#ifdef __LP64__
+  #define SIZEOF_UNSIGNED_LONG 8
+#else
+  #define SIZEOF_UNSIGNED_LONG 4
+#endif
+
+#ifdef __LP64__
+  #define SIZEOF_VOIDP 8
+#else
+  #define SIZEOF_VOIDP 4
+#endif
+
+#ifdef __BIG_ENDIAN__
+  #define WORDS_BIGENDIAN 1
+#else
+  #undef WORDS_BIGENDIAN
+#endif
+
+#undef VSI_STAT64
+#undef VSI_STAT64_T
+
+#define VSI_STAT64 stat
+#define VSI_STAT64_T stat
+
+#endif // APPLE
+
+#endif //INCLUDED_CPL_CONFIG_EXTRAS

+ 278 - 0
libpq_test/include/cpl_conv.h

@@ -0,0 +1,278 @@
+/******************************************************************************
+ * $Id: cpl_conv.h 28601 2015-03-03 11:06:40Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Convenience functions declarations.
+ *           This is intended to remain light weight.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 1998, Frank Warmerdam
+ * Copyright (c) 2007-2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_CONV_H_INCLUDED
+#define CPL_CONV_H_INCLUDED
+
+#include "cpl_port.h"
+#include "cpl_vsi.h"
+#include "cpl_error.h"
+
+/**
+ * \file cpl_conv.h
+ *
+ * Various convenience functions for CPL.
+ *
+ */
+
+/* -------------------------------------------------------------------- */
+/*      Runtime check of various configuration items.                   */
+/* -------------------------------------------------------------------- */
+CPL_C_START
+
+void CPL_DLL CPLVerifyConfiguration(void);
+
+const char CPL_DLL * CPL_STDCALL
+CPLGetConfigOption( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
+void CPL_DLL CPL_STDCALL CPLSetConfigOption( const char *, const char * );
+void CPL_DLL CPL_STDCALL CPLSetThreadLocalConfigOption( const char *pszKey, 
+                                                        const char *pszValue );
+void CPL_DLL CPL_STDCALL CPLFreeConfig(void);
+
+/* -------------------------------------------------------------------- */
+/*      Safe malloc() API.  Thin cover over VSI functions with fatal    */
+/*      error reporting if memory allocation fails.                     */
+/* -------------------------------------------------------------------- */
+void CPL_DLL *CPLMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
+void CPL_DLL *CPLCalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
+void CPL_DLL *CPLRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL *CPLStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL *CPLStrlwr( char *);
+
+#define CPLFree VSIFree
+
+/* -------------------------------------------------------------------- */
+/*      Read a line from a text file, and strip of CR/LF.               */
+/* -------------------------------------------------------------------- */
+char CPL_DLL *CPLFGets( char *, int, FILE *);
+const char CPL_DLL *CPLReadLine( FILE * );
+const char CPL_DLL *CPLReadLineL( VSILFILE * );
+const char CPL_DLL *CPLReadLine2L( VSILFILE * , int nMaxCols, char** papszOptions);
+
+/* -------------------------------------------------------------------- */
+/*      Convert ASCII string to floationg point number                  */
+/*      (THESE FUNCTIONS ARE NOT LOCALE AWARE!).                        */
+/* -------------------------------------------------------------------- */
+double CPL_DLL CPLAtof(const char *);
+double CPL_DLL CPLAtofDelim(const char *, char);
+double CPL_DLL CPLStrtod(const char *, char **);
+double CPL_DLL CPLStrtodDelim(const char *, char **, char);
+float CPL_DLL CPLStrtof(const char *, char **);
+float CPL_DLL CPLStrtofDelim(const char *, char **, char);
+
+/* -------------------------------------------------------------------- */
+/*      Convert number to string.  This function is locale agnostic     */
+/*      (ie. it will support "," or "." regardless of current locale)   */
+/* -------------------------------------------------------------------- */
+double CPL_DLL CPLAtofM(const char *);
+
+/* -------------------------------------------------------------------- */
+/*      Read a numeric value from an ASCII character string.            */
+/* -------------------------------------------------------------------- */
+char CPL_DLL *CPLScanString( const char *, int, int, int );
+double CPL_DLL CPLScanDouble( const char *, int );
+long CPL_DLL CPLScanLong( const char *, int );
+unsigned long CPL_DLL CPLScanULong( const char *, int );
+GUIntBig CPL_DLL CPLScanUIntBig( const char *, int );
+GIntBig CPL_DLL CPLAtoGIntBig( const char* pszString );
+GIntBig CPL_DLL CPLAtoGIntBigEx( const char* pszString, int bWarn, int *pbOverflow );
+void CPL_DLL *CPLScanPointer( const char *, int );
+
+/* -------------------------------------------------------------------- */
+/*      Print a value to an ASCII character string.                     */
+/* -------------------------------------------------------------------- */
+int CPL_DLL CPLPrintString( char *, const char *, int );
+int CPL_DLL CPLPrintStringFill( char *, const char *, int );
+int CPL_DLL CPLPrintInt32( char *, GInt32 , int );
+int CPL_DLL CPLPrintUIntBig( char *, GUIntBig , int );
+int CPL_DLL CPLPrintDouble( char *, const char *, double, const char * );
+int CPL_DLL CPLPrintTime( char *, int , const char *, const struct tm *,
+                          const char * );
+int CPL_DLL CPLPrintPointer( char *, void *, int );
+
+/* -------------------------------------------------------------------- */
+/*      Fetch a function from DLL / so.                                 */
+/* -------------------------------------------------------------------- */
+
+void CPL_DLL *CPLGetSymbol( const char *, const char * );
+
+/* -------------------------------------------------------------------- */
+/*      Fetch executable path.                                          */
+/* -------------------------------------------------------------------- */
+int CPL_DLL CPLGetExecPath( char *pszPathBuf, int nMaxLength );
+
+/* -------------------------------------------------------------------- */
+/*      Filename handling functions.                                    */
+/* -------------------------------------------------------------------- */
+const char CPL_DLL *CPLGetPath( const char * );
+const char CPL_DLL *CPLGetDirname( const char * );
+const char CPL_DLL *CPLGetFilename( const char * );
+const char CPL_DLL *CPLGetBasename( const char * );
+const char CPL_DLL *CPLGetExtension( const char * );
+char       CPL_DLL *CPLGetCurrentDir(void);
+const char CPL_DLL *CPLFormFilename( const char *pszPath,
+                                     const char *pszBasename,
+                                     const char *pszExtension );
+const char CPL_DLL *CPLFormCIFilename( const char *pszPath,
+                                       const char *pszBasename,
+                                       const char *pszExtension );
+const char CPL_DLL *CPLResetExtension( const char *, const char * );
+const char CPL_DLL *CPLProjectRelativeFilename( const char *pszProjectDir, 
+                                            const char *pszSecondaryFilename );
+int CPL_DLL CPLIsFilenameRelative( const char *pszFilename );
+const char CPL_DLL *CPLExtractRelativePath(const char *, const char *, int *);
+const char CPL_DLL *CPLCleanTrailingSlash( const char * );
+char CPL_DLL      **CPLCorrespondingPaths( const char *pszOldFilename, 
+                                           const char *pszNewFilename, 
+                                           char **papszFileList );
+int CPL_DLL CPLCheckForFile( char *pszFilename, char **papszSiblingList );
+
+const char CPL_DLL *CPLGenerateTempFilename( const char *pszStem );
+
+/* -------------------------------------------------------------------- */
+/*      Find File Function                                              */
+/* -------------------------------------------------------------------- */
+typedef const char *(*CPLFileFinder)(const char *, const char *);
+
+const char    CPL_DLL *CPLFindFile(const char *pszClass, 
+                                   const char *pszBasename);
+const char    CPL_DLL *CPLDefaultFindFile(const char *pszClass, 
+                                          const char *pszBasename);
+void          CPL_DLL CPLPushFileFinder( CPLFileFinder pfnFinder );
+CPLFileFinder CPL_DLL CPLPopFileFinder(void);
+void          CPL_DLL CPLPushFinderLocation( const char * );
+void          CPL_DLL CPLPopFinderLocation(void);
+void          CPL_DLL CPLFinderClean(void);
+
+/* -------------------------------------------------------------------- */
+/*      Safe version of stat() that works properly on stuff like "C:".  */
+/* -------------------------------------------------------------------- */
+int CPL_DLL     CPLStat( const char *, VSIStatBuf * );
+
+/* -------------------------------------------------------------------- */
+/*      Reference counted file handle manager.  Makes sharing file      */
+/*      handles more practical.                                         */
+/* -------------------------------------------------------------------- */
+typedef struct {
+    FILE *fp;
+    int   nRefCount;
+    int   bLarge;
+    char  *pszFilename;
+    char  *pszAccess;
+} CPLSharedFileInfo;
+
+FILE CPL_DLL    *CPLOpenShared( const char *, const char *, int );
+void CPL_DLL     CPLCloseShared( FILE * );
+CPLSharedFileInfo CPL_DLL *CPLGetSharedList( int * );
+void CPL_DLL     CPLDumpSharedList( FILE * );
+void CPL_DLL     CPLCleanupSharedFileMutex( void );
+
+/* -------------------------------------------------------------------- */
+/*      DMS to Dec to DMS conversion.                                   */
+/* -------------------------------------------------------------------- */
+double CPL_DLL CPLDMSToDec( const char *is );
+const char CPL_DLL *CPLDecToDMS( double dfAngle, const char * pszAxis,
+                                 int nPrecision );
+double CPL_DLL CPLPackedDMSToDec( double );
+double CPL_DLL CPLDecToPackedDMS( double dfDec );
+
+void CPL_DLL CPLStringToComplex( const char *pszString, 
+                                 double *pdfReal, double *pdfImag );
+
+/* -------------------------------------------------------------------- */
+/*      Misc other functions.                                           */
+/* -------------------------------------------------------------------- */
+int CPL_DLL CPLUnlinkTree( const char * );
+int CPL_DLL CPLCopyFile( const char *pszNewPath, const char *pszOldPath );
+int CPL_DLL CPLCopyTree( const char *pszNewPath, const char *pszOldPath );
+int CPL_DLL CPLMoveFile( const char *pszNewPath, const char *pszOldPath );
+
+/* -------------------------------------------------------------------- */
+/*      ZIP Creation.                                                   */
+/* -------------------------------------------------------------------- */
+#define CPL_ZIP_API_OFFERED
+void CPL_DLL  *CPLCreateZip( const char *pszZipFilename, char **papszOptions );
+CPLErr CPL_DLL CPLCreateFileInZip( void *hZip, const char *pszFilename, 
+                                   char **papszOptions );
+CPLErr CPL_DLL CPLWriteFileInZip( void *hZip, const void *pBuffer, int nBufferSize );
+CPLErr CPL_DLL CPLCloseFileInZip( void *hZip );
+CPLErr CPL_DLL CPLCloseZip( void *hZip );
+
+/* -------------------------------------------------------------------- */
+/*      ZLib compression                                                */
+/* -------------------------------------------------------------------- */
+
+void CPL_DLL *CPLZLibDeflate( const void* ptr, size_t nBytes, int nLevel,
+                              void* outptr, size_t nOutAvailableBytes,
+                              size_t* pnOutBytes );
+void CPL_DLL *CPLZLibInflate( const void* ptr, size_t nBytes,
+                              void* outptr, size_t nOutAvailableBytes,
+                              size_t* pnOutBytes );
+
+/* -------------------------------------------------------------------- */
+/*      XML validation.                                                 */
+/* -------------------------------------------------------------------- */
+int CPL_DLL CPLValidateXML(const char* pszXMLFilename,
+                           const char* pszXSDFilename,
+                           char** papszOptions);
+						   
+/* -------------------------------------------------------------------- */
+/*      Locale handling. Prevents parallel executions of setlocale().   */
+/* -------------------------------------------------------------------- */
+char* CPLsetlocale (int category, const char* locale);
+void CPLCleanupSetlocaleMutex(void);
+
+CPL_C_END
+
+/* -------------------------------------------------------------------- */
+/*      C++ object for temporariliy forcing a LC_NUMERIC locale to "C". */
+/* -------------------------------------------------------------------- */
+
+#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
+
+class CPL_DLL CPLLocaleC
+{
+public:
+    CPLLocaleC();
+    ~CPLLocaleC();
+
+private:
+    char *pszOldLocale;
+
+    /* Make it non-copyable */
+    CPLLocaleC(CPLLocaleC&);
+    CPLLocaleC& operator=(CPLLocaleC&);
+};
+
+#endif /* def __cplusplus */
+
+
+#endif /* ndef CPL_CONV_H_INCLUDED */

+ 71 - 0
libpq_test/include/cpl_csv.h

@@ -0,0 +1,71 @@
+/******************************************************************************
+ * $Id: cpl_csv.h 16759 2009-04-09 21:32:43Z rouault $
+ *
+ * Project:  Common Portability Library
+ * Purpose:  Functions for reading and scaning CSV (comma separated,
+ *           variable length text files holding tables) files.  
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 1999, Frank Warmerdam
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_CSV_H_INCLUDED
+#define CPL_CSV_H_INCLUDED
+
+#include "cpl_conv.h"
+#include "cpl_string.h"
+#include "cpl_vsi.h"
+
+CPL_C_START
+
+typedef enum {
+    CC_ExactString,
+    CC_ApproxString,
+    CC_Integer
+} CSVCompareCriteria;
+
+const char CPL_DLL *CSVFilename( const char * );
+
+char CPL_DLL CSVDetectSeperator( const char *pszLine );
+
+char CPL_DLL  **CSVReadParseLine( FILE *fp);
+char CPL_DLL  **CSVReadParseLine2( FILE *fp, char chDelimiter );
+char CPL_DLL **CSVScanLines( FILE *, int, const char *, CSVCompareCriteria );
+char CPL_DLL **CSVScanFile( const char *, int, const char *,
+                            CSVCompareCriteria );
+char CPL_DLL **CSVScanFileByName( const char *, const char *, const char *,
+                                  CSVCompareCriteria );
+char CPL_DLL **CSVGetNextLine( const char * );
+int CPL_DLL CSVGetFieldId( FILE *, const char * );
+int CPL_DLL CSVGetFileFieldId( const char *, const char * );
+
+void CPL_DLL CSVDeaccess( const char * );
+
+const char CPL_DLL *CSVGetField( const char *, const char *, const char *,
+                                 CSVCompareCriteria, const char * );
+
+void CPL_DLL SetCSVFilenameHook( const char *(*)(const char *) );
+
+CPL_C_END
+
+#endif /* ndef CPL_CSV_H_INCLUDED */
+

+ 135 - 0
libpq_test/include/cpl_error.h

@@ -0,0 +1,135 @@
+/**********************************************************************
+ * $Id: cpl_error.h 27384 2014-05-24 12:28:12Z rouault $
+ *
+ * Name:     cpl_error.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  CPL Error handling
+ * Author:   Daniel Morissette, danmo@videotron.ca
+ *
+ **********************************************************************
+ * Copyright (c) 1998, Daniel Morissette
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_ERROR_H_INCLUDED
+#define CPL_ERROR_H_INCLUDED
+
+#include "cpl_port.h"
+
+/*=====================================================================
+                   Error handling functions (cpl_error.c)
+ =====================================================================*/
+
+/**
+ * \file cpl_error.h
+ *
+ * CPL error handling services.
+ */
+  
+CPL_C_START
+
+typedef enum
+{
+    CE_None = 0,
+    CE_Debug = 1,
+    CE_Warning = 2,
+    CE_Failure = 3,
+    CE_Fatal = 4
+} CPLErr;
+
+void CPL_DLL CPLError(CPLErr eErrClass, int err_no, const char *fmt, ...)  CPL_PRINT_FUNC_FORMAT (3, 4);
+void CPL_DLL CPLErrorV(CPLErr, int, const char *, va_list );
+void CPL_DLL CPLEmergencyError( const char * );
+void CPL_DLL CPL_STDCALL CPLErrorReset( void );
+int CPL_DLL CPL_STDCALL CPLGetLastErrorNo( void );
+CPLErr CPL_DLL CPL_STDCALL CPLGetLastErrorType( void );
+const char CPL_DLL * CPL_STDCALL CPLGetLastErrorMsg( void );
+void CPL_DLL * CPL_STDCALL CPLGetErrorHandlerUserData(void);
+void CPL_DLL CPLErrorSetState( CPLErr eErrClass, int err_no, const char* pszMsg );
+void CPL_DLL CPLCleanupErrorMutex( void );
+
+typedef void (CPL_STDCALL *CPLErrorHandler)(CPLErr, int, const char*);
+
+void CPL_DLL CPL_STDCALL CPLLoggingErrorHandler( CPLErr, int, const char * );
+void CPL_DLL CPL_STDCALL CPLDefaultErrorHandler( CPLErr, int, const char * );
+void CPL_DLL CPL_STDCALL CPLQuietErrorHandler( CPLErr, int, const char * );
+void CPLTurnFailureIntoWarning(int bOn );
+
+CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandler(CPLErrorHandler);
+CPLErrorHandler CPL_DLL CPL_STDCALL CPLSetErrorHandlerEx(CPLErrorHandler, void*);
+void CPL_DLL CPL_STDCALL CPLPushErrorHandler( CPLErrorHandler );
+void CPL_DLL CPL_STDCALL CPLPushErrorHandlerEx( CPLErrorHandler, void* );
+void CPL_DLL CPL_STDCALL CPLPopErrorHandler(void);
+
+void CPL_DLL CPL_STDCALL CPLDebug( const char *, const char *, ... )  CPL_PRINT_FUNC_FORMAT (2, 3);
+void CPL_DLL CPL_STDCALL _CPLAssert( const char *, const char *, int );
+
+#ifdef DEBUG
+#  define CPLAssert(expr)  ((expr) ? (void)(0) : _CPLAssert(#expr,__FILE__,__LINE__))
+#else
+#  define CPLAssert(expr)
+#endif
+
+CPL_C_END
+
+/*
+ * Helper macros used for input parameters validation.
+ */
+#ifdef DEBUG
+#  define VALIDATE_POINTER_ERR CE_Fatal
+#else
+#  define VALIDATE_POINTER_ERR CE_Failure
+#endif
+
+#define VALIDATE_POINTER0(ptr, func) \
+   do { if( NULL == ptr ) \
+      { \
+        CPLErr const ret = VALIDATE_POINTER_ERR; \
+        CPLError( ret, CPLE_ObjectNull, \
+           "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
+         return; }} while(0)
+
+#define VALIDATE_POINTER1(ptr, func, rc) \
+   do { if( NULL == ptr ) \
+      { \
+          CPLErr const ret = VALIDATE_POINTER_ERR; \
+          CPLError( ret, CPLE_ObjectNull, \
+           "Pointer \'%s\' is NULL in \'%s\'.\n", #ptr, (func)); \
+        return (rc); }} while(0)
+
+/* ==================================================================== */
+/*      Well known error codes.                                         */
+/* ==================================================================== */
+
+#define CPLE_None                       0
+#define CPLE_AppDefined                 1
+#define CPLE_OutOfMemory                2
+#define CPLE_FileIO                     3
+#define CPLE_OpenFailed                 4
+#define CPLE_IllegalArg                 5
+#define CPLE_NotSupported               6
+#define CPLE_AssertionFailed            7
+#define CPLE_NoWriteAccess              8
+#define CPLE_UserInterrupt              9
+#define CPLE_ObjectNull                 10
+
+/* 100 - 299 reserved for GDAL */
+
+#endif /* CPL_ERROR_H_INCLUDED */

+ 92 - 0
libpq_test/include/cpl_hash_set.h

@@ -0,0 +1,92 @@
+/**********************************************************************
+ * $Id: cpl_hash_set.h 27044 2014-03-16 23:41:27Z rouault $
+ *
+ * Name:     cpl_hash_set.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Hash set functions.
+ * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
+ *
+ **********************************************************************
+ * Copyright (c) 2008-2009, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_HASH_SET_H_INCLUDED
+#define _CPL_HASH_SET_H_INCLUDED
+
+#include "cpl_port.h"
+
+/**
+ * \file cpl_hash_set.h
+ *
+ * Hash set implementation.
+ *
+ * An hash set is a data structure that holds elements that are unique
+ * according to a comparison function. Operations on the hash set, such as
+ * insertion, removal or lookup, are supposed to be fast if an efficient
+ * "hash" function is provided.
+ */
+
+CPL_C_START
+
+/* Types */
+
+typedef struct _CPLHashSet CPLHashSet;
+
+typedef unsigned long (*CPLHashSetHashFunc)(const void* elt);
+
+typedef int          (*CPLHashSetEqualFunc)(const void* elt1, const void* elt2);
+
+typedef void         (*CPLHashSetFreeEltFunc)(void* elt);
+
+typedef int          (*CPLHashSetIterEltFunc)(void* elt, void* user_data);
+
+/* Functions */
+
+CPLHashSet CPL_DLL * CPLHashSetNew(CPLHashSetHashFunc fnHashFunc,
+                                   CPLHashSetEqualFunc fnEqualFunc,
+                                   CPLHashSetFreeEltFunc fnFreeEltFunc);
+
+void         CPL_DLL CPLHashSetDestroy(CPLHashSet* set);
+
+int          CPL_DLL CPLHashSetSize(const CPLHashSet* set);
+
+void         CPL_DLL CPLHashSetForeach(CPLHashSet* set,
+                                       CPLHashSetIterEltFunc fnIterFunc,
+                                       void* user_data);
+
+int          CPL_DLL CPLHashSetInsert(CPLHashSet* set, void* elt);
+
+void         CPL_DLL * CPLHashSetLookup(CPLHashSet* set, const void* elt);
+
+int          CPL_DLL CPLHashSetRemove(CPLHashSet* set, const void* elt);
+
+unsigned long CPL_DLL CPLHashSetHashPointer(const void* elt);
+
+int          CPL_DLL CPLHashSetEqualPointer(const void* elt1, const void* elt2);
+
+unsigned long CPL_DLL CPLHashSetHashStr(const void * pszStr);
+
+int          CPL_DLL CPLHashSetEqualStr(const void* pszStr1, const void* pszStr2);
+
+CPL_C_END
+
+#endif /* _CPL_HASH_SET_H_INCLUDED */
+

+ 105 - 0
libpq_test/include/cpl_http.h

@@ -0,0 +1,105 @@
+/******************************************************************************
+ * $Id: cpl_http.h 27044 2014-03-16 23:41:27Z rouault $
+ *
+ * Project:  Common Portability Library
+ * Purpose:  Function wrapper for libcurl HTTP access.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2006, Frank Warmerdam
+ * Copyright (c) 2009, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_HTTP_H_INCLUDED
+#define CPL_HTTP_H_INCLUDED
+
+#include "cpl_conv.h"
+#include "cpl_string.h"
+#include "cpl_vsi.h"
+
+/**
+ * \file cpl_http.h
+ *
+ * Interface for downloading HTTP, FTP documents
+ */
+
+CPL_C_START
+
+/*! Describe a part of a multipart message */
+typedef struct {
+    /*! NULL terminated array of headers */ char **papszHeaders;
+    
+    /*! Buffer with data of the part     */ GByte *pabyData;
+    /*! Buffer length                    */ int    nDataLen;
+} CPLMimePart;
+
+/*! Describe the result of a CPLHTTPFetch() call */
+typedef struct {
+    /*! cURL error code : 0=success, non-zero if request failed */ 
+    int     nStatus;
+
+    /*! Content-Type of the response */                                
+    char    *pszContentType;
+
+    /*! Error message from curl, or NULL */                            
+    char    *pszErrBuf;
+
+    /*! Length of the pabyData buffer */                               
+    int     nDataLen;
+    int     nDataAlloc;
+
+    /*! Buffer with downloaded data */                                 
+    GByte   *pabyData;
+
+    /*! Headers returned */
+    char    **papszHeaders;
+
+    /*! Number of parts in a multipart message */                      
+    int     nMimePartCount;
+
+    /*! Array of parts (resolved by CPLHTTPParseMultipartMime()) */    
+    CPLMimePart *pasMimePart;
+
+} CPLHTTPResult;
+
+int CPL_DLL   CPLHTTPEnabled( void );
+CPLHTTPResult CPL_DLL *CPLHTTPFetch( const char *pszURL, char **papszOptions);
+void CPL_DLL  CPLHTTPCleanup( void );
+void CPL_DLL  CPLHTTPDestroyResult( CPLHTTPResult *psResult );
+int  CPL_DLL  CPLHTTPParseMultipartMime( CPLHTTPResult *psResult );
+
+/* -------------------------------------------------------------------- */
+/*      The following is related to OAuth2 authorization around         */
+/*      google services like fusion tables, and potentially others      */
+/*      in the future.  Code in cpl_google_oauth2.cpp.                  */
+/*                                                                      */
+/*      These services are built on CPL HTTP services.                  */
+/* -------------------------------------------------------------------- */
+
+char CPL_DLL *GOA2GetAuthorizationURL( const char *pszScope );
+char CPL_DLL *GOA2GetRefreshToken( const char *pszAuthToken,
+                                   const char *pszScope );
+char CPL_DLL *GOA2GetAccessToken( const char *pszRefreshToken,
+                                  const char *pszScope );
+
+CPL_C_END
+
+#endif /* ndef CPL_HTTP_H_INCLUDED */

+ 72 - 0
libpq_test/include/cpl_list.h

@@ -0,0 +1,72 @@
+/**********************************************************************
+ * $Id: cpl_list.h 26927 2014-02-11 15:54:59Z goatbar $
+ *
+ * Name:     cpl_list.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  List functions.
+ * Author:   Andrey Kiselev, dron@remotesensing.org
+ *
+ **********************************************************************
+ * Copyright (c) 2003, Andrey Kiselev <dron@remotesensing.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_LIST_H_INCLUDED
+#define _CPL_LIST_H_INCLUDED
+
+#include "cpl_port.h"
+
+/**
+ * \file cpl_list.h
+ *
+ * Simplest list implementation.  List contains only pointers to stored
+ * objects, not objects itself. All operations regarding allocation and
+ * freeing memory for objects should be performed by the caller.
+ *
+ */
+
+CPL_C_START
+
+/** List element structure. */
+typedef struct _CPLList
+{
+    /*! Pointer to the data object. Should be allocated and freed by the
+     * caller.
+     * */
+    void        *pData;
+    /*! Pointer to the next element in list. NULL, if current element is the
+     * last one.
+     */
+    struct _CPLList    *psNext;
+} CPLList;
+
+CPLList CPL_DLL *CPLListAppend( CPLList *psList, void *pData );
+CPLList CPL_DLL *CPLListInsert( CPLList *psList, void *pData, int nPosition );
+CPLList CPL_DLL *CPLListGetLast( CPLList *psList );
+CPLList CPL_DLL *CPLListGet( CPLList *psList, int nPosition );
+int CPL_DLL CPLListCount( CPLList *psList );
+CPLList CPL_DLL *CPLListRemove( CPLList *psList, int nPosition );
+void CPL_DLL CPLListDestroy( CPLList *psList );
+CPLList CPL_DLL *CPLListGetNext( CPLList *psElement );
+void CPL_DLL *CPLListGetData( CPLList *psElement );
+
+CPL_C_END
+
+#endif /* _CPL_LIST_H_INCLUDED */

+ 160 - 0
libpq_test/include/cpl_minixml.h

@@ -0,0 +1,160 @@
+/**********************************************************************
+ * $Id: cpl_minixml.h 28690 2015-03-08 20:06:12Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Declarations for MiniXML Handler.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ **********************************************************************
+ * Copyright (c) 2001, Frank Warmerdam
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_MINIXML_H_INCLUDED
+#define _CPL_MINIXML_H_INCLUDED
+
+#include "cpl_port.h"
+
+/**
+ * \file cpl_minixml.h
+ *
+ * Definitions for CPL mini XML Parser/Serializer.
+ */
+
+CPL_C_START
+
+typedef enum 
+{
+    /*! Node is an element */           CXT_Element = 0,
+    /*! Node is a raw text value */     CXT_Text = 1,
+    /*! Node is attribute */            CXT_Attribute = 2,  
+    /*! Node is an XML comment. */      CXT_Comment = 3,    
+    /*! Node is a special literal */    CXT_Literal = 4     
+} CPLXMLNodeType;
+
+/**
+ * Document node structure. 
+ *
+ * This C structure is used to hold a single text fragment representing a 
+ * component of the document when parsed.   It should be allocated with the
+ * appropriate CPL function, and freed with CPLDestroyXMLNode().  The structure
+ * contents should not normally be altered by application code, but may be
+ * freely examined by application code.
+ *
+ * Using the psChild and psNext pointers, a heirarchical tree structure
+ * for a document can be represented as a tree of CPLXMLNode structures. 
+ */
+
+typedef struct CPLXMLNode
+{
+    /** 
+     * \brief Node type
+     *
+     * One of CXT_Element, CXT_Text, CXT_Attribute, CXT_Comment, 
+     * or CXT_Literal.
+     */
+    CPLXMLNodeType      eType;       
+    
+    /** 
+     * \brief Node value
+     *
+     * For CXT_Element this is the name of the element, without the angle
+     * brackets.  Note there is a single CXT_Element even when the document
+     * contains a start and end element tag.  The node represents the pair. 
+     * All text or other elements between the start and end tag will appear
+     * as children nodes of this CXT_Element node. 
+     *
+     * For CXT_Attribute the pszValue is the attribute name.  The value of 
+     * the attribute will be a CXT_Text child. 
+     *
+     * For CXT_Text this is the text itself (value of an attribute, or a 
+     * text fragment between an element start and end tags. 
+     *
+     * For CXT_Literal it is all the literal text.  Currently this is just
+     * used for !DOCTYPE lines, and the value would be the entire line. 
+     *
+     * For CXT_Comment the value is all the literal text within the comment, 
+     * but not including the comment start/end indicators ("<--" and "-->"). 
+     */
+    char                *pszValue;   
+
+    /** 
+     * \brief Next sibling. 
+     *
+     * Pointer to next sibling, that is the next node appearing after this
+     * one that has the same parent as this node.  NULL if this node is the
+     * last child of the parent element. 
+     */
+    struct CPLXMLNode  *psNext;     
+
+    /** 
+     * \brief Child node.
+     *
+     * Pointer to first child node, if any.  Only CXT_Element and CXT_Attribute
+     * nodes should have children.  For CXT_Attribute it should be a single
+     * CXT_Text value node, while CXT_Element can have any kind of child. 
+     * The full list of children for a node are identified by walking the 
+     * psNext's starting with the psChild node. 
+     */
+
+    struct CPLXMLNode  *psChild;    
+} CPLXMLNode;
+
+
+CPLXMLNode CPL_DLL *CPLParseXMLString( const char * );
+void       CPL_DLL  CPLDestroyXMLNode( CPLXMLNode * );
+CPLXMLNode CPL_DLL *CPLGetXMLNode( CPLXMLNode *poRoot, 
+                                   const char *pszPath );
+CPLXMLNode CPL_DLL *CPLSearchXMLNode( CPLXMLNode *poRoot, 
+                                      const char *pszTarget );
+const char CPL_DLL *CPLGetXMLValue( CPLXMLNode *poRoot, 
+                                    const char *pszPath, 
+                                    const char *pszDefault );
+CPLXMLNode CPL_DLL *CPLCreateXMLNode( CPLXMLNode *poParent, 
+                                      CPLXMLNodeType eType,
+                                      const char *pszText );
+char       CPL_DLL *CPLSerializeXMLTree( const CPLXMLNode *psNode );
+void       CPL_DLL  CPLAddXMLChild( CPLXMLNode *psParent,
+                                    CPLXMLNode *psChild );
+int        CPL_DLL  CPLRemoveXMLChild( CPLXMLNode *psParent,
+                                       CPLXMLNode *psChild );
+void       CPL_DLL  CPLAddXMLSibling( CPLXMLNode *psOlderSibling,
+                                      CPLXMLNode *psNewSibling );
+CPLXMLNode CPL_DLL *CPLCreateXMLElementAndValue( CPLXMLNode *psParent,
+                                                 const char *pszName,
+                                                 const char *pszValue );
+void       CPL_DLL CPLAddXMLAttributeAndValue( CPLXMLNode *psParent,
+                                                 const char *pszName,
+                                                 const char *pszValue );
+CPLXMLNode CPL_DLL *CPLCloneXMLTree( CPLXMLNode *psTree );
+int        CPL_DLL CPLSetXMLValue( CPLXMLNode *psRoot,  const char *pszPath,
+                                   const char *pszValue );
+void       CPL_DLL CPLStripXMLNamespace( CPLXMLNode *psRoot, 
+                                         const char *pszNameSpace, 
+                                         int bRecurse );
+void       CPL_DLL CPLCleanXMLElementName( char * );
+
+CPLXMLNode CPL_DLL *CPLParseXMLFile( const char *pszFilename );
+int        CPL_DLL CPLSerializeXMLTreeToFile( const CPLXMLNode *psTree,
+                                              const char *pszFilename );
+
+CPL_C_END
+
+#endif /* _CPL_MINIXML_H_INCLUDED */

+ 90 - 0
libpq_test/include/cpl_minizip_ioapi.h

@@ -0,0 +1,90 @@
+/* Modified version by Even Rouault. :
+      - change fill_fopen_filefunc to cpl_fill_fopen_filefunc
+      - Add support for ZIP64
+
+ * Copyright (c) 2008-2012, Even Rouault <even dot rouault at mines-paris dot org>
+
+   Original licence available in port/LICENCE_minizip
+*/
+
+/* ioapi.h -- IO base function header for compress/uncompress .zip
+   files using zlib + zip or unzip API
+
+   Version 1.01e, February 12th, 2005
+
+   Copyright (C) 1998-2005 Gilles Vollant
+*/
+
+#ifndef CPL_MINIZIP_IOAPI_H_INCLUDED
+#define CPL_MINIZIP_IOAPI_H_INCLUDED
+
+#include "cpl_vsi.h"
+#define uLong64 vsi_l_offset
+
+/* Gentoo removed OF from their copy of zconf.h (https://bugs.gentoo.org/show_bug.cgi?id=383179) */
+/* but our copy of minizip needs it. */
+#ifndef OF
+#define OF(args) args
+#endif
+
+#define ZLIB_FILEFUNC_SEEK_CUR (1)
+#define ZLIB_FILEFUNC_SEEK_END (2)
+#define ZLIB_FILEFUNC_SEEK_SET (0)
+
+#define ZLIB_FILEFUNC_MODE_READ      (1)
+#define ZLIB_FILEFUNC_MODE_WRITE     (2)
+#define ZLIB_FILEFUNC_MODE_READWRITEFILTER (3)
+
+#define ZLIB_FILEFUNC_MODE_EXISTING (4)
+#define ZLIB_FILEFUNC_MODE_CREATE   (8)
+
+#ifndef ZCALLBACK
+
+#if (defined(WIN32) || defined (WINDOWS) || defined (_WINDOWS)) && defined(CALLBACK) && defined (USEWINDOWS_CALLBACK)
+#define ZCALLBACK CALLBACK
+#else
+#define ZCALLBACK
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef voidpf (ZCALLBACK *open_file_func) OF((voidpf opaque, const char* filename, int mode));
+typedef uLong  (ZCALLBACK *read_file_func) OF((voidpf opaque, voidpf stream, void* buf, uLong size));
+typedef uLong  (ZCALLBACK *write_file_func) OF((voidpf opaque, voidpf stream, const void* buf, uLong size));
+typedef uLong64   (ZCALLBACK *tell_file_func) OF((voidpf opaque, voidpf stream));
+typedef long   (ZCALLBACK *seek_file_func) OF((voidpf opaque, voidpf stream, uLong64 offset, int origin));
+typedef int    (ZCALLBACK *close_file_func) OF((voidpf opaque, voidpf stream));
+typedef int    (ZCALLBACK *testerror_file_func) OF((voidpf opaque, voidpf stream));
+
+typedef struct zlib_filefunc_def_s
+{
+    open_file_func      zopen_file;
+    read_file_func      zread_file;
+    write_file_func     zwrite_file;
+    tell_file_func      ztell_file;
+    seek_file_func      zseek_file;
+    close_file_func     zclose_file;
+    testerror_file_func zerror_file;
+    voidpf              opaque;
+} zlib_filefunc_def;
+
+
+
+void cpl_fill_fopen_filefunc OF((zlib_filefunc_def* pzlib_filefunc_def));
+
+#define ZREAD(filefunc,filestream,buf,size) ((*((filefunc).zread_file))((filefunc).opaque,filestream,buf,size))
+#define ZWRITE(filefunc,filestream,buf,size) ((*((filefunc).zwrite_file))((filefunc).opaque,filestream,buf,size))
+#define ZTELL(filefunc,filestream) ((*((filefunc).ztell_file))((filefunc).opaque,filestream))
+#define ZSEEK(filefunc,filestream,pos,mode) ((*((filefunc).zseek_file))((filefunc).opaque,filestream,pos,mode))
+#define ZCLOSE(filefunc,filestream) ((*((filefunc).zclose_file))((filefunc).opaque,filestream))
+#define ZERROR(filefunc,filestream) ((*((filefunc).zerror_file))((filefunc).opaque,filestream))
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CPL_MINIZIP_IOAPI_H_INCLUDED */

+ 381 - 0
libpq_test/include/cpl_minizip_unzip.h

@@ -0,0 +1,381 @@
+/* Modified version by Even Rouault. :
+     - Addition of cpl_unzGetCurrentFileZStreamPos
+     - Decoration of symbol names unz* -> cpl_unz*
+     - Undef EXPORT so that we are sure the symbols are not exported
+     - Add support for ZIP64
+
+ * Copyright (c) 2008, Even Rouault <even dot rouault at mines-paris dot org>
+
+   Original licence available in port/LICENCE_minizip
+*/
+
+/* unzip.h -- IO for uncompress .zip files using zlib
+   Version 1.01e, February 12th, 2005
+
+   Copyright (C) 1998-2005 Gilles Vollant
+
+   This unzip package allow extract file from .ZIP file, compatible with PKZip 2.04g
+     WinZip, InfoZip tools and compatible.
+
+   Multi volume ZipFile (span) are not supported.
+   Encryption compatible with pkzip 2.04g only supported
+   Old compressions used by old PKZip 1.x are not supported
+
+
+   I WAIT FEEDBACK at mail info@winimage.com
+   Visit also http://www.winimage.com/zLibDll/unzip.htm for evolution
+
+   Condition of use and distribution are the same than zlib :
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+
+
+*/
+
+/* for more info about .ZIP format, see
+      http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
+      http://www.info-zip.org/pub/infozip/doc/
+   PkWare has also a specification at :
+      ftp://ftp.pkware.com/probdesc.zip
+*/
+
+#ifndef CPL_MINIZIP_UNZIP_H_INCLUDED
+#define CPL_MINIZIP_UNZIP_H_INCLUDED
+
+#include "cpl_vsi.h"
+#define uLong64 vsi_l_offset
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _ZLIB_H
+#include <zlib.h>
+#endif
+
+#ifndef CPL_MINIZIP_IOAPI_H_INCLUDED
+#include "cpl_minizip_ioapi.h"
+#endif
+
+/* GDAL addition */
+#define NOUNCRYPT
+#undef ZEXPORT
+#define ZEXPORT
+
+#if defined(STRICTUNZIP) || defined(STRICTZIPUNZIP)
+/* like the STRICT of WIN32, we define a pointer that cannot be converted
+    from (void*) without cast */
+typedef struct TagunzFile__ { int unused; } unzFile__;
+typedef unzFile__ *unzFile;
+#else
+typedef voidp unzFile;
+#endif
+
+
+#define UNZ_OK                          (0)
+#define UNZ_END_OF_LIST_OF_FILE         (-100)
+#define UNZ_ERRNO                       (Z_ERRNO)
+#define UNZ_EOF                         (0)
+#define UNZ_PARAMERROR                  (-102)
+#define UNZ_BADZIPFILE                  (-103)
+#define UNZ_INTERNALERROR               (-104)
+#define UNZ_CRCERROR                    (-105)
+
+/* tm_unz contain date/time info */
+typedef struct tm_unz_s
+{
+    uInt tm_sec;            /* seconds after the minute - [0,59] */
+    uInt tm_min;            /* minutes after the hour - [0,59] */
+    uInt tm_hour;           /* hours since midnight - [0,23] */
+    uInt tm_mday;           /* day of the month - [1,31] */
+    uInt tm_mon;            /* months since January - [0,11] */
+    uInt tm_year;           /* years - [1980..2044] */
+} tm_unz;
+
+/* unz_global_info structure contain global data about the ZIPfile
+   These data comes from the end of central dir */
+typedef struct unz_global_info_s
+{
+    uLong64 number_entry;         /* total number of entries in
+                                     the central dir on this disk */
+    uLong size_comment;         /* size of the global comment of the zipfile */
+} unz_global_info;
+
+
+/* unz_file_info contain information about a file in the zipfile */
+typedef struct unz_file_info_s
+{
+    uLong version;              /* version made by                 2 bytes */
+    uLong version_needed;       /* version needed to extract       2 bytes */
+    uLong flag;                 /* general purpose bit flag        2 bytes */
+    uLong compression_method;   /* compression method              2 bytes */
+    uLong dosDate;              /* last mod file date in Dos fmt   4 bytes */
+    uLong crc;                  /* crc-32                          4 bytes */
+    uLong64 compressed_size;      /* compressed size                 4 bytes */
+    uLong64 uncompressed_size;    /* uncompressed size               4 bytes */
+    uLong size_filename;        /* filename length                 2 bytes */
+    uLong size_file_extra;      /* extra field length              2 bytes */
+    uLong size_file_comment;    /* file comment length             2 bytes */
+
+    uLong disk_num_start;       /* disk number start               2 bytes */
+    uLong internal_fa;          /* internal file attributes        2 bytes */
+    uLong external_fa;          /* external file attributes        4 bytes */
+
+    tm_unz tmu_date;
+} unz_file_info;
+
+extern int ZEXPORT cpl_unzStringFileNameCompare OF ((const char* fileName1,
+                                                 const char* fileName2,
+                                                 int iCaseSensitivity));
+/*
+   Compare two filename (fileName1,fileName2).
+   If iCaseSenisivity = 1, comparision is case sensitivity (like strcmp)
+   If iCaseSenisivity = 2, comparision is not case sensitivity (like strcmpi
+                                or strcasecmp)
+   If iCaseSenisivity = 0, case sensitivity is defaut of your operating system
+    (like 1 on Unix, 2 on Windows)
+*/
+
+
+extern unzFile ZEXPORT cpl_unzOpen OF((const char *path));
+/*
+  Open a Zip file. path contain the full pathname (by example,
+     on a Windows XP computer "c:\\zlib\\zlib113.zip" or on an Unix computer
+     "zlib/zlib113.zip".
+     If the zipfile cannot be opened (file don't exist or in not valid), the
+       return value is NULL.
+     Else, the return value is a unzFile Handle, usable with other function
+       of this unzip package.
+*/
+
+extern unzFile ZEXPORT cpl_unzOpen2 OF((const char *path,
+                                    zlib_filefunc_def* pzlib_filefunc_def));
+/*
+   Open a Zip file, like unzOpen, but provide a set of file low level API
+      for read/write the zip file (see ioapi.h)
+*/
+
+extern int ZEXPORT cpl_unzClose OF((unzFile file));
+/*
+  Close a ZipFile opened with unzipOpen.
+  If there is files inside the .Zip opened with unzOpenCurrentFile (see later),
+    these files MUST be closed with unzipCloseCurrentFile before call unzipClose.
+  return UNZ_OK if there is no problem. */
+
+extern int ZEXPORT cpl_unzGetGlobalInfo OF((unzFile file,
+                                        unz_global_info *pglobal_info));
+/*
+  Write info about the ZipFile in the *pglobal_info structure.
+  No preparation of the structure is needed
+  return UNZ_OK if there is no problem. */
+
+
+extern int ZEXPORT cpl_unzGetGlobalComment OF((unzFile file,
+                                           char *szComment,
+                                           uLong uSizeBuf));
+/*
+  Get the global comment string of the ZipFile, in the szComment buffer.
+  uSizeBuf is the size of the szComment buffer.
+  return the number of byte copied or an error code <0
+*/
+
+
+/***************************************************************************/
+/* Unzip package allow you browse the directory of the zipfile */
+
+extern int ZEXPORT cpl_unzGoToFirstFile OF((unzFile file));
+/*
+  Set the current file of the zipfile to the first file.
+  return UNZ_OK if there is no problem
+*/
+
+extern int ZEXPORT cpl_unzGoToNextFile OF((unzFile file));
+/*
+  Set the current file of the zipfile to the next file.
+  return UNZ_OK if there is no problem
+  return UNZ_END_OF_LIST_OF_FILE if the actual file was the latest.
+*/
+
+extern int ZEXPORT cpl_unzLocateFile OF((unzFile file,
+                     const char *szFileName,
+                     int iCaseSensitivity));
+/*
+  Try locate the file szFileName in the zipfile.
+  For the iCaseSensitivity signification, see unzStringFileNameCompare
+
+  return value :
+  UNZ_OK if the file is found. It becomes the current file.
+  UNZ_END_OF_LIST_OF_FILE if the file is not found
+*/
+
+
+/* ****************************************** */
+/* Ryan supplied functions */
+/* unz_file_info contain information about a file in the zipfile */
+typedef struct unz_file_pos_s
+{
+    uLong64 pos_in_zip_directory;   /* offset in zip file directory */
+    uLong64 num_of_file;            /* # of file */
+} unz_file_pos;
+
+extern int ZEXPORT cpl_unzGetFilePos(
+    unzFile file,
+    unz_file_pos* file_pos);
+
+extern int ZEXPORT cpl_unzGoToFilePos(
+    unzFile file,
+    unz_file_pos* file_pos);
+
+/* ****************************************** */
+
+extern int ZEXPORT cpl_unzGetCurrentFileInfo OF((unzFile file,
+                         unz_file_info *pfile_info,
+                         char *szFileName,
+                         uLong fileNameBufferSize,
+                         void *extraField,
+                         uLong extraFieldBufferSize,
+                         char *szComment,
+                         uLong commentBufferSize));
+/*
+  Get Info about the current file
+  if pfile_info!=NULL, the *pfile_info structure will contain somes info about
+        the current file
+  if szFileName!=NULL, the filemane string will be copied in szFileName
+            (fileNameBufferSize is the size of the buffer)
+  if extraField!=NULL, the extra field information will be copied in extraField
+            (extraFieldBufferSize is the size of the buffer).
+            This is the Central-header version of the extra field
+  if szComment!=NULL, the comment string of the file will be copied in szComment
+            (commentBufferSize is the size of the buffer)
+*/
+
+
+/** Addition for GDAL : START */
+
+extern uLong64 ZEXPORT cpl_unzGetCurrentFileZStreamPos OF(( unzFile file));
+
+/** Addition for GDAL : END */
+
+
+/***************************************************************************/
+/* for reading the content of the current zipfile, you can open it, read data
+   from it, and close it (you can close it before reading all the file)
+   */
+
+extern int ZEXPORT cpl_unzOpenCurrentFile OF((unzFile file));
+/*
+  Open for reading data the current file in the zipfile.
+  If there is no error, the return value is UNZ_OK.
+*/
+
+extern int ZEXPORT cpl_unzOpenCurrentFilePassword OF((unzFile file,
+                                                  const char* password));
+/*
+  Open for reading data the current file in the zipfile.
+  password is a crypting password
+  If there is no error, the return value is UNZ_OK.
+*/
+
+extern int ZEXPORT cpl_unzOpenCurrentFile2 OF((unzFile file,
+                                           int* method,
+                                           int* level,
+                                           int raw));
+/*
+  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
+    if raw==1
+  *method will receive method of compression, *level will receive level of
+     compression
+  note : you can set level parameter as NULL (if you did not want known level,
+         but you CANNOT set method parameter as NULL
+*/
+
+extern int ZEXPORT cpl_unzOpenCurrentFile3 OF((unzFile file,
+                                           int* method,
+                                           int* level,
+                                           int raw,
+                                           const char* password));
+/*
+  Same than unzOpenCurrentFile, but open for read raw the file (not uncompress)
+    if raw==1
+  *method will receive method of compression, *level will receive level of
+     compression
+  note : you can set level parameter as NULL (if you did not want known level,
+         but you CANNOT set method parameter as NULL
+*/
+
+
+extern int ZEXPORT cpl_unzCloseCurrentFile OF((unzFile file));
+/*
+  Close the file in zip opened with unzOpenCurrentFile
+  Return UNZ_CRCERROR if all the file was read but the CRC is not good
+*/
+
+extern int ZEXPORT cpl_unzReadCurrentFile OF((unzFile file,
+                      voidp buf,
+                      unsigned len));
+/*
+  Read bytes from the current file (opened by unzOpenCurrentFile)
+  buf contain buffer where data must be copied
+  len the size of buf.
+
+  return the number of byte copied if somes bytes are copied
+  return 0 if the end of file was reached
+  return <0 with error code if there is an error
+    (UNZ_ERRNO for IO error, or zLib error for uncompress error)
+*/
+
+extern z_off_t ZEXPORT cpl_unztell OF((unzFile file));
+/*
+  Give the current position in uncompressed data
+*/
+
+extern int ZEXPORT cpl_unzeof OF((unzFile file));
+/*
+  return 1 if the end of file was reached, 0 elsewhere
+*/
+
+extern int ZEXPORT cpl_unzGetLocalExtrafield OF((unzFile file,
+                                             voidp buf,
+                                             unsigned len));
+/*
+  Read extra field from the current file (opened by unzOpenCurrentFile)
+  This is the local-header version of the extra field (sometimes, there is
+    more info in the local-header version than in the central-header)
+
+  if buf==NULL, it return the size of the local extra field
+
+  if buf!=NULL, len is the size of the buffer, the extra header is copied in
+    buf.
+  the return value is the number of bytes copied in buf, or (if <0)
+    the error code
+*/
+
+/***************************************************************************/
+
+/* Get the current file offset */
+extern uLong64 ZEXPORT cpl_unzGetOffset (unzFile file);
+
+/* Set the current file offset */
+extern int ZEXPORT cpl_unzSetOffset (unzFile file, uLong64 pos);
+
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* CPL_MINIZIP_UNZIP_H_INCLUDED */

+ 259 - 0
libpq_test/include/cpl_minizip_zip.h

@@ -0,0 +1,259 @@
+/******************************************************************************
+ * $Id: cpl_minizip_zip.h 20794 2010-10-08 16:58:27Z warmerdam $
+ *
+ * Project:  CPL - Common Portability Library
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ * Purpose:  Adjusted minizip "zip.h" include file for zip services.
+ *
+ * Modified version by Even Rouault. :
+ *   - Decoration of symbol names unz* -> cpl_unz*
+ *   - Undef EXPORT so that we are sure the symbols are not exported
+ *   - Remove old C style function prototypes
+ *   - Added CPL* simplified API at bottom.
+ *
+ *   Original licence available in port/LICENCE_minizip
+ *
+ *****************************************************************************/
+
+/* zip.h -- IO for compress .zip files using zlib
+   Version 1.01e, February 12th, 2005
+
+   Copyright (C) 1998-2005 Gilles Vollant
+
+   This unzip package allow creates .ZIP file, compatible with PKZip 2.04g
+     WinZip, InfoZip tools and compatible.
+   Multi volume ZipFile (span) are not supported.
+   Encryption compatible with pkzip 2.04g only supported
+   Old compressions used by old PKZip 1.x are not supported
+
+  For uncompress .zip file, look at unzip.h
+
+
+   I WAIT FEEDBACK at mail info@winimage.com
+   Visit also http://www.winimage.com/zLibDll/unzip.html for evolution
+
+   Condition of use and distribution are the same than zlib :
+
+  This software is provided 'as-is', without any express or implied
+  warranty.  In no event will the authors be held liable for any damages
+  arising from the use of this software.
+
+  Permission is granted to anyone to use this software for any purpose,
+  including commercial applications, and to alter it and redistribute it
+  freely, subject to the following restrictions:
+
+  1. The origin of this software must not be misrepresented; you must not
+     claim that you wrote the original software. If you use this software
+     in a product, an acknowledgment in the product documentation would be
+     appreciated but is not required.
+  2. Altered source versions must be plainly marked as such, and must not be
+     misrepresented as being the original software.
+  3. This notice may not be removed or altered from any source distribution.
+
+
+*/
+
+/* for more info about .ZIP format, see
+      http://www.info-zip.org/pub/infozip/doc/appnote-981119-iz.zip
+      http://www.info-zip.org/pub/infozip/doc/
+   PkWare has also a specification at :
+      ftp://ftp.pkware.com/probdesc.zip
+*/
+
+#ifndef CPL_MINIZIP_ZIP_H_INCLUDED
+#define CPL_MINIZIP_ZIP_H_INCLUDED
+
+#include "cpl_vsi.h"
+#define uLong64 vsi_l_offset
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#ifndef _ZLIB_H
+#include "zlib.h"
+#endif
+
+#ifndef CPL_MINIZIP_IOAPI_H_INCLUDED
+#include "cpl_minizip_ioapi.h"
+#endif
+
+#define NOCRYPT
+#undef ZEXPORT
+#define ZEXPORT
+
+#if defined(STRICTZIP) || defined(STRICTZIPUNZIP)
+/* like the STRICT of WIN32, we define a pointer that cannot be converted
+    from (void*) without cast */
+typedef struct TagzipFile__ { int unused; } zipFile__;
+typedef zipFile__ *zipFile;
+#else
+typedef voidp zipFile;
+#endif
+
+#define ZIP_OK                          (0)
+#define ZIP_EOF                         (0)
+#define ZIP_ERRNO                       (Z_ERRNO)
+#define ZIP_PARAMERROR                  (-102)
+#define ZIP_BADZIPFILE                  (-103)
+#define ZIP_INTERNALERROR               (-104)
+
+#ifndef DEF_MEM_LEVEL
+#  if MAX_MEM_LEVEL >= 8
+#    define DEF_MEM_LEVEL 8
+#  else
+#    define DEF_MEM_LEVEL  MAX_MEM_LEVEL
+#  endif
+#endif
+/* default memLevel */
+
+/* tm_zip contain date/time info */
+typedef struct tm_zip_s
+{
+    uInt tm_sec;            /* seconds after the minute - [0,59] */
+    uInt tm_min;            /* minutes after the hour - [0,59] */
+    uInt tm_hour;           /* hours since midnight - [0,23] */
+    uInt tm_mday;           /* day of the month - [1,31] */
+    uInt tm_mon;            /* months since January - [0,11] */
+    uInt tm_year;           /* years - [1980..2044] */
+} tm_zip;
+
+typedef struct
+{
+    tm_zip      tmz_date;       /* date in understandable format           */
+    uLong       dosDate;       /* if dos_date == 0, tmu_date is used      */
+/*    uLong       flag;        */   /* general purpose bit flag        2 bytes */
+
+    uLong       internal_fa;    /* internal file attributes        2 bytes */
+    uLong       external_fa;    /* external file attributes        4 bytes */
+} zip_fileinfo;
+
+typedef const char* zipcharpc;
+
+
+#define APPEND_STATUS_CREATE        (0)
+#define APPEND_STATUS_CREATEAFTER   (1)
+#define APPEND_STATUS_ADDINZIP      (2)
+
+extern zipFile ZEXPORT cpl_zipOpen OF((const char *pathname, int append));
+/*
+  Create a zipfile.
+     pathname contain on Windows XP a filename like "c:\\zlib\\zlib113.zip" or on
+       an Unix computer "zlib/zlib113.zip".
+     if the file pathname exist and append==APPEND_STATUS_CREATEAFTER, the zip
+       will be created at the end of the file.
+         (useful if the file contain a self extractor code)
+     if the file pathname exist and append==APPEND_STATUS_ADDINZIP, we will
+       add files in existing zip (be sure you don't add file that doesn't exist)
+     If the zipfile cannot be opened, the return value is NULL.
+     Else, the return value is a zipFile Handle, usable with other function
+       of this zip package.
+*/
+
+/* Note : there is no delete function into a zipfile.
+   If you want delete file into a zipfile, you must open a zipfile, and create another
+   Of couse, you can use RAW reading and writing to copy the file you did not want delte
+*/
+
+extern zipFile ZEXPORT cpl_zipOpen2 OF((const char *pathname,
+                                   int append,
+                                   zipcharpc* globalcomment,
+                                   zlib_filefunc_def* pzlib_filefunc_def));
+
+extern int ZEXPORT cpl_zipOpenNewFileInZip OF((zipFile file,
+                       const char* filename,
+                       const zip_fileinfo* zipfi,
+                       const void* extrafield_local,
+                       uInt size_extrafield_local,
+                       const void* extrafield_global,
+                       uInt size_extrafield_global,
+                       const char* comment,
+                       int method,
+                       int level));
+/*
+  Open a file in the ZIP for writing.
+  filename : the filename in zip (if NULL, '-' without quote will be used
+  *zipfi contain supplemental information
+  if extrafield_local!=NULL and size_extrafield_local>0, extrafield_local
+    contains the extrafield data the the local header
+  if extrafield_global!=NULL and size_extrafield_global>0, extrafield_global
+    contains the extrafield data the the local header
+  if comment != NULL, comment contain the comment string
+  method contain the compression method (0 for store, Z_DEFLATED for deflate)
+  level contain the level of compression (can be Z_DEFAULT_COMPRESSION)
+*/
+
+
+extern int ZEXPORT cpl_zipOpenNewFileInZip2 OF((zipFile file,
+                                            const char* filename,
+                                            const zip_fileinfo* zipfi,
+                                            const void* extrafield_local,
+                                            uInt size_extrafield_local,
+                                            const void* extrafield_global,
+                                            uInt size_extrafield_global,
+                                            const char* comment,
+                                            int method,
+                                            int level,
+                                            int raw));
+
+/*
+  Same than zipOpenNewFileInZip, except if raw=1, we write raw file
+ */
+
+extern int ZEXPORT cpl_zipOpenNewFileInZip3 OF((zipFile file,
+                                            const char* filename,
+                                            const zip_fileinfo* zipfi,
+                                            const void* extrafield_local,
+                                            uInt size_extrafield_local,
+                                            const void* extrafield_global,
+                                            uInt size_extrafield_global,
+                                            const char* comment,
+                                            int method,
+                                            int level,
+                                            int raw,
+                                            int windowBits,
+                                            int memLevel,
+                                            int strategy,
+                                            const char* password,
+                                            uLong crcForCtypting));
+
+/*
+  Same than zipOpenNewFileInZip2, except
+    windowBits,memLevel,,strategy : see parameter strategy in deflateInit2
+    password : crypting password (NULL for no crypting)
+    crcForCtypting : crc of file to compress (needed for crypting)
+ */
+
+
+extern int ZEXPORT cpl_zipWriteInFileInZip OF((zipFile file,
+                       const void* buf,
+                       unsigned len));
+/*
+  Write data in the zipfile
+*/
+
+extern int ZEXPORT cpl_zipCloseFileInZip OF((zipFile file));
+/*
+  Close the current file in the zipfile
+*/
+
+extern int ZEXPORT cpl_zipCloseFileInZipRaw OF((zipFile file,
+                                            uLong uncompressed_size,
+                                            uLong crc32));
+/*
+  Close the current file in the zipfile, for fiel opened with
+    parameter raw=1 in zipOpenNewFileInZip2
+  uncompressed_size and crc32 are value for the uncompressed size
+*/
+
+extern int ZEXPORT cpl_zipClose OF((zipFile file,
+                const char* global_comment));
+/*
+  Close the zipfile
+*/
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _zip_H */

+ 228 - 0
libpq_test/include/cpl_multiproc.h

@@ -0,0 +1,228 @@
+/**********************************************************************
+ * $Id: cpl_multiproc.h 28470 2015-02-12 21:01:32Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Purpose:  CPL Multi-Threading, and process handling portability functions.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ **********************************************************************
+ * Copyright (c) 2002, Frank Warmerdam
+ * Copyright (c) 2008-2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_MULTIPROC_H_INCLUDED_
+#define _CPL_MULTIPROC_H_INCLUDED_
+
+#include "cpl_port.h"
+
+/*
+** There are three primary implementations of the multi-process support
+** controlled by one of CPL_MULTIPROC_WIN32, CPL_MULTIPROC_PTHREAD or
+** CPL_MULTIPROC_STUB being defined.  If none are defined, the stub
+** implementation will be used.
+*/
+
+#if defined(WIN32) && !defined(CPL_MULTIPROC_STUB)
+#  define CPL_MULTIPROC_WIN32
+/* MinGW can have pthread support, so disable it to avoid issues */
+/* in cpl_multiproc.cpp */
+#  undef  CPL_MULTIPROC_PTHREAD
+#endif
+
+#if !defined(CPL_MULTIPROC_WIN32) && !defined(CPL_MULTIPROC_PTHREAD) \
+ && !defined(CPL_MULTIPROC_STUB) && !defined(CPL_MULTIPROC_NONE)
+#  define CPL_MULTIPROC_STUB
+#endif
+
+CPL_C_START
+
+typedef void (*CPLThreadFunc)(void *);
+
+void CPL_DLL *CPLLockFile( const char *pszPath, double dfWaitInSeconds );
+void  CPL_DLL CPLUnlockFile( void *hLock );
+
+#ifdef DEBUG
+typedef struct _CPLMutex  CPLMutex;
+typedef struct _CPLCond   CPLCond;
+typedef struct _CPLJoinableThread CPLJoinableThread;
+#else
+#define CPLMutex void
+#define CPLCond void
+#define CPLJoinableThread void
+#endif
+
+/* Options for CPLCreateMutexEx() and CPLCreateOrAcquireMutexEx() */
+#define CPL_MUTEX_RECURSIVE         0
+#define CPL_MUTEX_ADAPTIVE          1
+
+CPLMutex CPL_DLL *CPLCreateMutex( void ); /* returned acquired */
+CPLMutex CPL_DLL *CPLCreateMutexEx( int nOptions ); /* returned acquired */
+int   CPL_DLL CPLCreateOrAcquireMutex( CPLMutex **, double dfWaitInSeconds );
+int   CPL_DLL CPLCreateOrAcquireMutexEx( CPLMutex **, double dfWaitInSeconds, int nOptions  );
+int   CPL_DLL CPLAcquireMutex( CPLMutex *hMutex, double dfWaitInSeconds );
+void  CPL_DLL CPLReleaseMutex( CPLMutex *hMutex );
+void  CPL_DLL CPLDestroyMutex( CPLMutex *hMutex );
+void  CPL_DLL CPLCleanupMasterMutex( void );
+
+CPLCond  CPL_DLL *CPLCreateCond( void );
+void  CPL_DLL  CPLCondWait( CPLCond *hCond, CPLMutex* hMutex );
+void  CPL_DLL  CPLCondSignal( CPLCond *hCond );
+void  CPL_DLL  CPLCondBroadcast( CPLCond *hCond );
+void  CPL_DLL  CPLDestroyCond( CPLCond *hCond );
+
+GIntBig CPL_DLL CPLGetPID( void );
+int   CPL_DLL CPLCreateThread( CPLThreadFunc pfnMain, void *pArg );
+CPLJoinableThread  CPL_DLL* CPLCreateJoinableThread( CPLThreadFunc pfnMain, void *pArg );
+void  CPL_DLL CPLJoinThread(CPLJoinableThread* hJoinableThread); 
+void  CPL_DLL CPLSleep( double dfWaitInSeconds );
+
+const char CPL_DLL *CPLGetThreadingModel( void );
+
+int CPL_DLL CPLGetNumCPUs( void );
+
+
+typedef struct _CPLLock CPLLock;
+
+/* Currently LOCK_ADAPTIVE_MUTEX is Linux-only and LOCK_SPIN only available */
+/* on systems with pthread_spinlock API (so not MacOsX). If a requested type */
+/* isn't available, it fallbacks to LOCK_RECURSIVE_MUTEX */
+typedef enum
+{
+    LOCK_RECURSIVE_MUTEX,
+    LOCK_ADAPTIVE_MUTEX,
+    LOCK_SPIN
+} CPLLockType;
+
+CPLLock  CPL_DLL *CPLCreateLock( CPLLockType eType ); /* returned NON acquired */
+int   CPL_DLL  CPLCreateOrAcquireLock( CPLLock**, CPLLockType eType );
+int   CPL_DLL  CPLAcquireLock( CPLLock* );
+void  CPL_DLL  CPLReleaseLock( CPLLock* );
+void  CPL_DLL  CPLDestroyLock( CPLLock* );
+void  CPL_DLL  CPLLockSetDebugPerf( CPLLock*, int bEnableIn ); /* only available on x86/x86_64 with GCC for now */
+
+
+CPL_C_END
+
+#ifdef __cplusplus
+
+/* Instanciates the mutex if not already done. The parameter x should be a (void**)  */
+#define CPLMutexHolderD(x)  CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__);
+
+/* Instanciates the mutex with options if not already done. */
+/* The parameter x should be a (void**)  */
+#define CPLMutexHolderExD(x, nOptions)  CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__,nOptions);
+
+/* This variant assumes the the mutex has already been created. If not, it will */
+/* be a no-op. The parameter x should be a (void*) */
+#define CPLMutexHolderOptionalLockD(x)  CPLMutexHolder oHolder(x,1000.0,__FILE__,__LINE__);
+
+class CPL_DLL CPLMutexHolder
+{
+  private:
+    CPLMutex   *hMutex;
+    const char *pszFile;
+    int         nLine;
+
+  public:
+
+    /* Instanciates the mutex if not already done */
+    CPLMutexHolder( CPLMutex **phMutex, double dfWaitInSeconds = 1000.0,
+                    const char *pszFile = __FILE__,
+                    int nLine = __LINE__,
+                    int nOptions = CPL_MUTEX_RECURSIVE);
+
+    /* This variant assumes the the mutex has already been created. If not, it will */
+    /* be a no-op */
+    CPLMutexHolder( CPLMutex* hMutex, double dfWaitInSeconds = 1000.0,
+                    const char *pszFile = __FILE__,
+                    int nLine = __LINE__ );
+
+    ~CPLMutexHolder();
+};
+
+/* Instanciates the lock if not already done. The parameter x should be a (CPLLock**) */
+#define CPLLockHolderD(x, eType)  CPLLockHolder oHolder(x,eType,__FILE__,__LINE__);
+
+/* This variant assumes the the lock has already been created. If not, it will */
+/* be a no-op. The parameter should be (CPLLock*) */
+#define CPLLockHolderOptionalLockD(x)  CPLLockHolder oHolder(x,__FILE__,__LINE__);
+
+class CPL_DLL CPLLockHolder
+{
+  private:
+    CPLLock    *hLock;
+    const char *pszFile;
+    int         nLine;
+
+  public:
+
+    /* Instanciates the lock if not already done */
+    CPLLockHolder( CPLLock **phSpin, CPLLockType eType,
+                    const char *pszFile = __FILE__,
+                    int nLine = __LINE__);
+
+    /* This variant assumes the the lock has already been created. If not, it will */
+    /* be a no-op */
+    CPLLockHolder( CPLLock* hSpin,
+                    const char *pszFile = __FILE__,
+                    int nLine = __LINE__ );
+
+    ~CPLLockHolder();
+};
+
+
+#endif /* def __cplusplus */
+
+/* -------------------------------------------------------------------- */
+/*      Thread local storage.                                           */
+/* -------------------------------------------------------------------- */
+
+#define CTLS_RLBUFFERINFO     		1         /* cpl_conv.cpp */
+#define CTLS_WIN32_COND                 2         /* cpl_multiproc.cpp */
+#define CTLS_CSVTABLEPTR                3         /* cpl_csv.cpp */
+#define CTLS_CSVDEFAULTFILENAME         4         /* cpl_csv.cpp */
+#define CTLS_ERRORCONTEXT               5         /* cpl_error.cpp */
+#define CTLS_GDALDATASET_REC_PROTECT_MAP 6        /* gdaldataset.cpp */
+#define CTLS_PATHBUF                    7         /* cpl_path.cpp */
+#define CTLS_UNUSED3                    8
+#define CTLS_UNUSED4                    9
+#define CTLS_CPLSPRINTF                10         /* cpl_string.h */
+#define CTLS_RESPONSIBLEPID            11         /* gdaldataset.cpp */
+#define CTLS_VERSIONINFO               12         /* gdal_misc.cpp */
+#define CTLS_VERSIONINFO_LICENCE       13         /* gdal_misc.cpp */
+#define CTLS_CONFIGOPTIONS             14         /* cpl_conv.cpp */
+#define CTLS_FINDFILE                  15         /* cpl_findfile.cpp */
+
+#define CTLS_MAX                       32         
+
+CPL_C_START
+void CPL_DLL * CPLGetTLS( int nIndex );
+void CPL_DLL CPLSetTLS( int nIndex, void *pData, int bFreeOnExit );
+
+/* Warning : the CPLTLSFreeFunc must not in any case directly or indirectly */
+/* use or fetch any TLS data, or a terminating thread will hang ! */
+typedef void (*CPLTLSFreeFunc)( void* pData );
+void CPL_DLL CPLSetTLSWithFreeFunc( int nIndex, void *pData, CPLTLSFreeFunc pfnFree );
+
+void CPL_DLL CPLCleanupTLS( void );
+CPL_C_END
+
+#endif /* _CPL_MULTIPROC_H_INCLUDED_ */

+ 288 - 0
libpq_test/include/cpl_odbc.h

@@ -0,0 +1,288 @@
+/******************************************************************************
+ * $Id: cpl_odbc.h 29025 2015-04-26 11:50:20Z tamas $
+ *
+ * Project:  OGR ODBC Driver
+ * Purpose:  Declarations for ODBC Access Cover API.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2003, Frank Warmerdam
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_ODBC_H_INCLUDED
+#define CPL_ODBC_H_INCLUDED
+
+#include "cpl_port.h"
+
+#ifndef WIN32CE /* ODBC is not supported on Windows CE. */
+
+#ifdef WIN32
+#  include <windows.h>
+#endif
+
+#include <sql.h>
+#include <sqlext.h>
+#include <odbcinst.h>
+#include "cpl_string.h"
+
+#ifdef PATH_MAX
+#  define ODBC_FILENAME_MAX PATH_MAX
+#else
+#  define ODBC_FILENAME_MAX (255 + 1) /* Max path length */
+#endif
+
+ 
+/**
+ * \file cpl_odbc.h
+ *
+ * ODBC Abstraction Layer (C++).
+ */
+
+/**
+ * A class providing functions to install or remove ODBC driver.
+ */
+class CPL_DLL CPLODBCDriverInstaller
+{
+    char m_szPathOut[ODBC_FILENAME_MAX];
+    char m_szError[SQL_MAX_MESSAGE_LENGTH];
+    DWORD m_nErrorCode;
+    DWORD m_nUsageCount;
+
+  public:
+    
+    // Default constructor.
+    CPLODBCDriverInstaller();
+
+
+    /**
+     * Installs ODBC driver or updates definition of already installed driver.
+     * Interanally, it calls ODBC's SQLInstallDriverEx function.
+     * 
+     * @param pszDriver - The driver definition as a list of keyword-value
+     * pairs describing the driver (See ODBC API Reference).
+     *
+     * @param pszPathIn - Full path of the target directory of the installation,
+     * or a null pointer (for unixODBC, NULL is passed).
+     *
+     * @param fRequest - The fRequest argument must contain one of
+     * the following values:
+     * ODBC_INSTALL_COMPLETE - (default) complete the installation request
+     * ODBC_INSTALL_INQUIRY - inquire about where a driver can be installed
+     *
+     * @return TRUE indicates success, FALSE if it fails.
+     */
+    int InstallDriver( const char* pszDriver, const char* pszPathIn,
+            WORD fRequest = ODBC_INSTALL_COMPLETE );
+
+    /**
+     * Removes or changes information about the driver from
+     * the Odbcinst.ini entry in the system information.
+     *
+     * @param pszDriverName - The name of the driver as registered in
+     * the Odbcinst.ini key of the system information.
+     * 
+     * @param fRemoveDSN - TRUE: Remove DSNs associated with the driver 
+     * specified in lpszDriver. FALSE: Do not remove DSNs associated
+     * with the driver specified in lpszDriver. 
+     *
+     * @return The function returns TRUE if it is successful,
+     * FALSE if it fails. If no entry exists in the system information
+     * when this function is called, the function returns FALSE.
+     * In order to obtain usage count value, call GetUsageCount().
+     */
+    int RemoveDriver( const char* pszDriverName, int fRemoveDSN = FALSE );
+
+
+    // The usage count of the driver after this function has been called
+    int GetUsageCount() const {  return m_nUsageCount; }
+
+
+    // Path of the target directory where the driver should be installed.
+    // For details, see ODBC API Reference and lpszPathOut
+    // parameter of SQLInstallDriverEx 
+    const char* GetPathOut() const { return m_szPathOut; }
+
+
+    // If InstallDriver returns FALSE, then GetLastError then
+    // error message can be obtained by calling this function.
+    // Internally, it calls ODBC's SQLInstallerError function.
+    const char* GetLastError() const { return m_szError; }
+   
+
+    // If InstallDriver returns FALSE, then GetLastErrorCode then
+    // error code can be obtained by calling this function.
+    // Internally, it calls ODBC's SQLInstallerError function.
+    // See ODBC API Reference for possible error flags.
+    DWORD GetLastErrorCode() const { return m_nErrorCode; }
+};
+
+class CPLODBCStatement;
+
+/* On MSVC SQLULEN is missing in some cases (ie. VC6)
+** but it is always a #define so test this way.   On Unix
+** it is a typedef so we can't always do this.
+*/
+#if defined(_MSC_VER) && !defined(SQLULEN) && !defined(_WIN64)
+#  define MISSING_SQLULEN
+#endif
+
+#if !defined(MISSING_SQLULEN)
+/* ODBC types to support 64 bit compilation */
+#  define _SQLULEN SQLULEN
+#  define _SQLLEN  SQLLEN
+#else
+#  define _SQLULEN SQLUINTEGER
+#  define _SQLLEN  SQLINTEGER
+#endif	/* ifdef SQLULEN */
+
+
+/**
+ * A class representing an ODBC database session. 
+ *
+ * Includes error collection services.
+ */
+
+class CPL_DLL CPLODBCSession {
+    char      m_szLastError[SQL_MAX_MESSAGE_LENGTH + 1];
+    HENV      m_hEnv;
+    HDBC      m_hDBC;
+    int       m_bInTransaction;
+    int       m_bAutoCommit;
+
+  public:
+    CPLODBCSession();
+    ~CPLODBCSession();
+
+    int         EstablishSession( const char *pszDSN, 
+                                  const char *pszUserid, 
+                                  const char *pszPassword );
+    const char  *GetLastError();
+
+    // Transaction handling
+
+    int         ClearTransaction();
+    int         BeginTransaction();
+    int         CommitTransaction();
+    int         RollbackTransaction();
+    int         IsInTransaction() { return m_bInTransaction; }
+
+    // Essentially internal. 
+
+    int         CloseSession();
+
+    int         Failed( int, HSTMT = NULL );
+    HDBC        GetConnection() { return m_hDBC; }
+    HENV        GetEnvironment()  { return m_hEnv; }
+};
+
+/**
+ * Abstraction for statement, and resultset.
+ *
+ * Includes methods for executing an SQL statement, and for accessing the
+ * resultset from that statement.  Also provides for executing other ODBC
+ * requests that produce results sets such as SQLColumns() and SQLTables()
+ * requests.
+ */
+
+class CPL_DLL CPLODBCStatement {
+
+    CPLODBCSession     *m_poSession;
+    HSTMT               m_hStmt;
+
+    SQLSMALLINT    m_nColCount;
+    char         **m_papszColNames;
+    SQLSMALLINT   *m_panColType;
+    char         **m_papszColTypeNames;
+    _SQLULEN      *m_panColSize;
+    SQLSMALLINT   *m_panColPrecision;
+    SQLSMALLINT   *m_panColNullable;
+    char         **m_papszColColumnDef;
+
+    char         **m_papszColValues;
+    _SQLLEN       *m_panColValueLengths;
+    
+    int            Failed( int );
+
+    char          *m_pszStatement;
+    size_t         m_nStatementMax;
+    size_t         m_nStatementLen;
+
+  public:
+    CPLODBCStatement( CPLODBCSession * );
+    ~CPLODBCStatement();
+
+    HSTMT          GetStatement() { return m_hStmt; }
+
+    // Command buffer related.
+    void           Clear();
+    void           AppendEscaped( const char * );
+    void           Append( const char * );
+    void           Append( int );
+    void           Append( double );
+    int            Appendf( const char *, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
+    const char    *GetCommand() { return m_pszStatement; }
+
+    int            ExecuteSQL( const char * = NULL );
+
+    // Results fetching
+    int            Fetch( int nOrientation = SQL_FETCH_NEXT, 
+                          int nOffset = 0 );
+    void           ClearColumnData();
+
+    int            GetColCount();
+    const char    *GetColName( int );
+    short          GetColType( int );
+    const char    *GetColTypeName( int );
+    short          GetColSize( int );
+    short          GetColPrecision( int );
+    short          GetColNullable( int );
+    const char    *GetColColumnDef( int );
+
+    int            GetColId( const char * );
+    const char    *GetColData( int, const char * = NULL );
+    const char    *GetColData( const char *, const char * = NULL );
+    int            GetColDataLength( int );
+    int            GetRowCountAffected();
+
+    // Fetch special metadata.
+    int            GetColumns( const char *pszTable, 
+                               const char *pszCatalog = NULL,
+                               const char *pszSchema = NULL );
+    int            GetPrimaryKeys( const char *pszTable, 
+                                   const char *pszCatalog = NULL,
+                                   const char *pszSchema = NULL );
+
+    int            GetTables( const char *pszCatalog = NULL,
+                              const char *pszSchema = NULL );
+
+    void           DumpResult( FILE *fp, int bShowSchema = FALSE );
+
+    static CPLString GetTypeName( int );
+    static SQLSMALLINT GetTypeMapping( SQLSMALLINT );
+
+    int            CollectResultsInfo();
+};
+
+#endif /* #ifndef WIN32CE */
+
+#endif
+
+

+ 625 - 0
libpq_test/include/cpl_port.h

@@ -0,0 +1,625 @@
+/******************************************************************************
+ * $Id: cpl_port.h 29925 2015-08-30 12:05:05Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ * Purpose:  Include file providing low level portability services for CPL.  
+ *           This should be the first include file for any CPL based code.  
+ *
+ ******************************************************************************
+ * Copyright (c) 1998, 2005, Frank Warmerdam <warmerdam@pobox.com>
+ * Copyright (c) 2008-2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_BASE_H_INCLUDED
+#define CPL_BASE_H_INCLUDED
+
+/**
+ * \file cpl_port.h
+ *
+ * Core portability definitions for CPL.
+ *
+ */
+
+/* ==================================================================== */
+/*      We will use macos_pre10 to indicate compilation with MacOS      */
+/*      versions before MacOS X.                                        */
+/* ==================================================================== */
+#ifdef macintosh
+#  define macos_pre10
+#endif
+
+/* ==================================================================== */
+/*      We will use WIN32 as a standard windows define.                 */
+/* ==================================================================== */
+#if defined(_WIN32) && !defined(WIN32) && !defined(_WIN32_WCE)
+#  define WIN32
+#endif
+
+#if defined(_WINDOWS) && !defined(WIN32) && !defined(_WIN32_WCE)
+#  define WIN32
+#endif
+
+/* ==================================================================== */
+/*      We will use WIN32CE as a standard Windows CE (Mobile) define.   */
+/* ==================================================================== */
+#if defined(_WIN32_WCE)
+#  define WIN32CE
+#endif
+
+/* -------------------------------------------------------------------- */
+/*      The following apparently allow you to use strcpy() and other    */
+/*      functions judged "unsafe" by microsoft in VS 8 (2005).          */
+/* -------------------------------------------------------------------- */
+#ifdef _MSC_VER
+#  ifndef _CRT_SECURE_NO_DEPRECATE
+#    define _CRT_SECURE_NO_DEPRECATE
+#  endif
+#  ifndef _CRT_NONSTDC_NO_DEPRECATE
+#    define _CRT_NONSTDC_NO_DEPRECATE
+#  endif
+#endif
+
+#include "cpl_config.h"
+
+/* ==================================================================== */
+/*      A few sanity checks, mainly to detect problems that sometimes   */
+/*      arise with bad configured cross-compilation.                    */
+/* ==================================================================== */
+
+#if !defined(SIZEOF_INT) || SIZEOF_INT != 4
+#error "Unexpected value for SIZEOF_INT"
+#endif
+
+#if !defined(SIZEOF_UNSIGNED_LONG) || (SIZEOF_UNSIGNED_LONG != 4 && SIZEOF_UNSIGNED_LONG != 8)
+#error "Unexpected value for SIZEOF_UNSIGNED_LONG"
+#endif
+
+#if !defined(SIZEOF_VOIDP) || (SIZEOF_VOIDP != 4 && SIZEOF_VOIDP != 8)
+#error "Unexpected value for SIZEOF_VOIDP"
+#endif
+
+
+/* ==================================================================== */
+/*      This will disable most WIN32 stuff in a Cygnus build which      */
+/*      defines unix to 1.                                              */
+/* ==================================================================== */
+
+#ifdef unix
+#  undef WIN32
+#  undef WIN32CE
+#endif
+
+#if defined(VSI_NEED_LARGEFILE64_SOURCE) && !defined(_LARGEFILE64_SOURCE)
+#  define _LARGEFILE64_SOURCE 1
+#endif
+
+/* ==================================================================== */
+/*      If iconv() is available use extended recoding module.           */
+/*      Stub implementation is always compiled in, because it works     */
+/*      faster than iconv() for encodings it supports.                  */
+/* ==================================================================== */
+
+#if defined(HAVE_ICONV)
+#  define CPL_RECODE_ICONV
+#endif
+
+#define CPL_RECODE_STUB
+
+/* ==================================================================== */
+/*      MinGW stuff                                                     */
+/* ==================================================================== */
+
+/* We need __MSVCRT_VERSION__ >= 0x0601 to have "struct __stat64" */
+/* Latest versions of mingw32 define it, but with older ones, */
+/* we need to define it manually */
+#if defined(__MINGW32__)
+#ifndef __MSVCRT_VERSION__
+#define __MSVCRT_VERSION__ 0x0601
+#endif
+#endif
+
+/* ==================================================================== */
+/*      Standard include files.                                         */
+/* ==================================================================== */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <math.h>
+#include <stdarg.h>
+#include <string.h>
+#include <ctype.h>
+#include <limits.h>
+
+#if !defined(WIN32CE)
+#  include <time.h>
+#else
+#  include <wce_time.h>
+#  include <wce_errno.h>
+#endif
+
+
+#if defined(HAVE_ERRNO_H)
+#  include <errno.h>
+#endif 
+
+#ifdef HAVE_LOCALE_H
+#  include <locale.h>
+#endif
+
+#ifdef HAVE_DIRECT_H
+#  include <direct.h>
+#endif
+
+#if !(defined(WIN32) || defined(WIN32CE))
+#  include <strings.h>
+#endif
+
+#if defined(HAVE_LIBDBMALLOC) && defined(HAVE_DBMALLOC_H) && defined(DEBUG)
+#  define DBMALLOC
+#  include <dbmalloc.h>
+#endif
+
+#if !defined(DBMALLOC) && defined(HAVE_DMALLOC_H)
+#  define USE_DMALLOC
+#  include <dmalloc.h>
+#endif
+
+/* ==================================================================== */
+/*      Base portability stuff ... this stuff may need to be            */
+/*      modified for new platforms.                                     */
+/* ==================================================================== */
+
+/*---------------------------------------------------------------------
+ *        types for 16 and 32 bits integers, etc...
+ *--------------------------------------------------------------------*/
+#if UINT_MAX == 65535
+typedef long            GInt32;
+typedef unsigned long   GUInt32;
+#else
+typedef int             GInt32;
+typedef unsigned int    GUInt32;
+#endif
+
+typedef short           GInt16;
+typedef unsigned short  GUInt16;
+typedef unsigned char   GByte;
+/* hack for PDF driver and poppler >= 0.15.0 that defines incompatible "typedef bool GBool" */
+/* in include/poppler/goo/gtypes.h */
+#ifndef CPL_GBOOL_DEFINED
+#define CPL_GBOOL_DEFINED
+typedef int             GBool;
+#endif
+
+/* -------------------------------------------------------------------- */
+/*      64bit support                                                   */
+/* -------------------------------------------------------------------- */
+
+#if defined(WIN32) && defined(_MSC_VER)
+
+#define VSI_LARGE_API_SUPPORTED
+typedef __int64          GIntBig;
+typedef unsigned __int64 GUIntBig;
+
+#define GINTBIG_MIN     ((GIntBig)(0x80000000) << 32)
+#define GINTBIG_MAX     (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
+
+#elif HAVE_LONG_LONG
+
+typedef long long        GIntBig;
+typedef unsigned long long GUIntBig;
+
+#define GINTBIG_MIN     ((GIntBig)(0x80000000) << 32)
+#define GINTBIG_MAX     (((GIntBig)(0x7FFFFFFF) << 32) | 0xFFFFFFFFU)
+
+#else
+
+typedef long             GIntBig;
+typedef unsigned long    GUIntBig;
+
+#define GINTBIG_MIN     INT_MIN
+#define GINTBIG_MAX     INT_MAX
+#endif
+
+#if SIZEOF_VOIDP == 8
+typedef GIntBig          GPtrDiff_t;
+#else
+typedef int              GPtrDiff_t;
+#endif
+
+#if defined(__MSVCRT__) || (defined(WIN32) && defined(_MSC_VER))
+  #define CPL_FRMT_GB_WITHOUT_PREFIX     "I64"
+#elif HAVE_LONG_LONG
+  #define CPL_FRMT_GB_WITHOUT_PREFIX     "ll"
+#else
+  #define CPL_FRMT_GB_WITHOUT_PREFIX     "l"
+#endif
+
+#define CPL_FRMT_GIB     "%" CPL_FRMT_GB_WITHOUT_PREFIX "d"
+#define CPL_FRMT_GUIB    "%" CPL_FRMT_GB_WITHOUT_PREFIX "u"
+
+/* Workaround VC6 bug */
+#if defined(_MSC_VER) && (_MSC_VER <= 1200)
+#define GUINTBIG_TO_DOUBLE(x) (double)(GIntBig)(x)
+#else
+#define GUINTBIG_TO_DOUBLE(x) (double)(x)
+#endif
+
+/* ==================================================================== */
+/*      Other standard services.                                        */
+/* ==================================================================== */
+#ifdef __cplusplus
+#  define CPL_C_START           extern "C" {
+#  define CPL_C_END             }
+#else
+#  define CPL_C_START
+#  define CPL_C_END
+#endif
+
+#ifndef CPL_DLL
+#if defined(_MSC_VER) && !defined(CPL_DISABLE_DLL)
+#  define CPL_DLL     __declspec(dllexport)
+#else
+#  if defined(USE_GCC_VISIBILITY_FLAG)
+#    define CPL_DLL     __attribute__ ((visibility("default")))
+#  else
+#    define CPL_DLL
+#  endif
+#endif
+#endif
+
+/* Should optional (normally private) interfaces be exported? */
+#ifdef CPL_OPTIONAL_APIS
+#  define CPL_ODLL CPL_DLL
+#else
+#  define CPL_ODLL
+#endif
+
+#ifndef CPL_STDCALL
+#if defined(_MSC_VER) && !defined(CPL_DISABLE_STDCALL)
+#  define CPL_STDCALL     __stdcall
+#else
+#  define CPL_STDCALL
+#endif
+#endif
+
+#ifdef _MSC_VER
+#  define FORCE_CDECL  __cdecl
+#else
+#  define FORCE_CDECL 
+#endif
+
+/* TODO : support for other compilers needed */
+#if (defined(__GNUC__) && !defined(__NO_INLINE__)) || defined(_MSC_VER)
+#define HAS_CPL_INLINE  1
+#define CPL_INLINE __inline
+#elif defined(__SUNPRO_CC)
+#define HAS_CPL_INLINE  1
+#define CPL_INLINE inline
+#else
+#define CPL_INLINE
+#endif
+
+#ifndef NULL
+#  define NULL  0
+#endif
+
+#ifndef FALSE
+#  define FALSE 0
+#endif
+
+#ifndef TRUE
+#  define TRUE  1
+#endif
+
+#ifndef MAX
+#  define MIN(a,b)      ((a<b) ? a : b)
+#  define MAX(a,b)      ((a>b) ? a : b)
+#endif
+
+#ifndef ABS
+#  define ABS(x)        ((x<0) ? (-1*(x)) : x)
+#endif
+
+#ifndef M_PI
+# define M_PI		3.14159265358979323846	/* pi */
+#endif
+
+/* -------------------------------------------------------------------- */
+/*      Macro to test equality of two floating point values.            */
+/*      We use fabs() function instead of ABS() macro to avoid side     */
+/*      effects.                                                        */
+/* -------------------------------------------------------------------- */
+#ifndef CPLIsEqual
+#  define CPLIsEqual(x,y) (fabs((x) - (y)) < 0.0000000000001)
+#endif
+
+/* -------------------------------------------------------------------- */
+/*      Provide macros for case insensitive string comparisons.         */
+/* -------------------------------------------------------------------- */
+#ifndef EQUAL
+#  if defined(WIN32) || defined(WIN32CE)
+#    define STRCASECMP(a,b)         (stricmp(a,b))
+#    define STRNCASECMP(a,b,n)      (strnicmp(a,b,n))
+#  else
+#    define STRCASECMP(a,b)         (strcasecmp(a,b))
+#    define STRNCASECMP(a,b,n)      (strncasecmp(a,b,n))
+#  endif
+#  define EQUALN(a,b,n)           (STRNCASECMP(a,b,n)==0)
+#  define EQUAL(a,b)              (STRCASECMP(a,b)==0)
+#endif
+
+#ifdef macos_pre10
+int strcasecmp(char * str1, char * str2);
+int strncasecmp(char * str1, char * str2, int len);
+char * strdup (char *instr);
+#endif
+
+#ifndef CPL_THREADLOCAL
+#  define CPL_THREADLOCAL
+#endif
+
+/* -------------------------------------------------------------------- */
+/*      Handle isnan() and isinf().  Note that isinf() and isnan()      */
+/*      are supposed to be macros according to C99, defined in math.h   */
+/*      Some systems (ie. Tru64) don't have isinf() at all, so if       */
+/*      the macro is not defined we just assume nothing is infinite.    */
+/*      This may mean we have no real CPLIsInf() on systems with isinf()*/
+/*      function but no corresponding macro, but I can live with        */
+/*      that since it isn't that important a test.                      */
+/* -------------------------------------------------------------------- */
+#ifdef _MSC_VER
+#  include <float.h>
+#  define CPLIsNan(x) _isnan(x)
+#  define CPLIsInf(x) (!_isnan(x) && !_finite(x))
+#  define CPLIsFinite(x) _finite(x)
+#else
+#  define CPLIsNan(x) isnan(x)
+#  ifdef isinf 
+#    define CPLIsInf(x) isinf(x)
+#    define CPLIsFinite(x) (!isnan(x) && !isinf(x))
+#  else
+#    define CPLIsInf(x)    FALSE
+#    define CPLIsFinite(x) (!isnan(x))
+#  endif
+#endif
+
+/*---------------------------------------------------------------------
+ *                         CPL_LSB and CPL_MSB
+ * Only one of these 2 macros should be defined and specifies the byte 
+ * ordering for the current platform.  
+ * This should be defined in the Makefile, but if it is not then
+ * the default is CPL_LSB (Intel ordering, LSB first).
+ *--------------------------------------------------------------------*/
+#if defined(WORDS_BIGENDIAN) && !defined(CPL_MSB) && !defined(CPL_LSB)
+#  define CPL_MSB
+#endif
+
+#if ! ( defined(CPL_LSB) || defined(CPL_MSB) )
+#define CPL_LSB
+#endif
+
+#if defined(CPL_LSB)
+#  define CPL_IS_LSB 1
+#else
+#  define CPL_IS_LSB 0
+#endif
+
+/*---------------------------------------------------------------------
+ *        Little endian <==> big endian byte swap macros.
+ *--------------------------------------------------------------------*/
+
+#define CPL_SWAP16(x) \
+        ((GUInt16)( \
+            (((GUInt16)(x) & 0x00ffU) << 8) | \
+            (((GUInt16)(x) & 0xff00U) >> 8) ))
+
+#define CPL_SWAP16PTR(x) \
+{                                                                 \
+    GByte       byTemp, *_pabyDataT = (GByte *) (x);              \
+                                                                  \
+    byTemp = _pabyDataT[0];                                       \
+    _pabyDataT[0] = _pabyDataT[1];                                \
+    _pabyDataT[1] = byTemp;                                       \
+}                                                                    
+                                                            
+#define CPL_SWAP32(x) \
+        ((GUInt32)( \
+            (((GUInt32)(x) & (GUInt32)0x000000ffUL) << 24) | \
+            (((GUInt32)(x) & (GUInt32)0x0000ff00UL) <<  8) | \
+            (((GUInt32)(x) & (GUInt32)0x00ff0000UL) >>  8) | \
+            (((GUInt32)(x) & (GUInt32)0xff000000UL) >> 24) ))
+
+#define CPL_SWAP32PTR(x) \
+{                                                                 \
+    GByte       byTemp, *_pabyDataT = (GByte *) (x);              \
+                                                                  \
+    byTemp = _pabyDataT[0];                                       \
+    _pabyDataT[0] = _pabyDataT[3];                                \
+    _pabyDataT[3] = byTemp;                                       \
+    byTemp = _pabyDataT[1];                                       \
+    _pabyDataT[1] = _pabyDataT[2];                                \
+    _pabyDataT[2] = byTemp;                                       \
+}                                                                    
+                                                            
+#define CPL_SWAP64PTR(x) \
+{                                                                 \
+    GByte       byTemp, *_pabyDataT = (GByte *) (x);              \
+                                                                  \
+    byTemp = _pabyDataT[0];                                       \
+    _pabyDataT[0] = _pabyDataT[7];                                \
+    _pabyDataT[7] = byTemp;                                       \
+    byTemp = _pabyDataT[1];                                       \
+    _pabyDataT[1] = _pabyDataT[6];                                \
+    _pabyDataT[6] = byTemp;                                       \
+    byTemp = _pabyDataT[2];                                       \
+    _pabyDataT[2] = _pabyDataT[5];                                \
+    _pabyDataT[5] = byTemp;                                       \
+    byTemp = _pabyDataT[3];                                       \
+    _pabyDataT[3] = _pabyDataT[4];                                \
+    _pabyDataT[4] = byTemp;                                       \
+}                                                                    
+                                                            
+
+/* Until we have a safe 64 bits integer data type defined, we'll replace
+ * this version of the CPL_SWAP64() macro with a less efficient one.
+ */
+/*
+#define CPL_SWAP64(x) \
+        ((uint64)( \
+            (uint64)(((uint64)(x) & (uint64)0x00000000000000ffULL) << 56) | \
+            (uint64)(((uint64)(x) & (uint64)0x000000000000ff00ULL) << 40) | \
+            (uint64)(((uint64)(x) & (uint64)0x0000000000ff0000ULL) << 24) | \
+            (uint64)(((uint64)(x) & (uint64)0x00000000ff000000ULL) << 8) | \
+            (uint64)(((uint64)(x) & (uint64)0x000000ff00000000ULL) >> 8) | \
+            (uint64)(((uint64)(x) & (uint64)0x0000ff0000000000ULL) >> 24) | \
+            (uint64)(((uint64)(x) & (uint64)0x00ff000000000000ULL) >> 40) | \
+            (uint64)(((uint64)(x) & (uint64)0xff00000000000000ULL) >> 56) ))
+*/
+
+#define CPL_SWAPDOUBLE(p) CPL_SWAP64PTR(p)
+
+#ifdef CPL_MSB
+#  define CPL_MSBWORD16(x)      (x)
+#  define CPL_LSBWORD16(x)      CPL_SWAP16(x)
+#  define CPL_MSBWORD32(x)      (x)
+#  define CPL_LSBWORD32(x)      CPL_SWAP32(x)
+#  define CPL_MSBPTR16(x)       
+#  define CPL_LSBPTR16(x)       CPL_SWAP16PTR(x)
+#  define CPL_MSBPTR32(x)       
+#  define CPL_LSBPTR32(x)       CPL_SWAP32PTR(x)
+#  define CPL_MSBPTR64(x)       
+#  define CPL_LSBPTR64(x)       CPL_SWAP64PTR(x)
+#else
+#  define CPL_LSBWORD16(x)      (x)
+#  define CPL_MSBWORD16(x)      CPL_SWAP16(x)
+#  define CPL_LSBWORD32(x)      (x)
+#  define CPL_MSBWORD32(x)      CPL_SWAP32(x)
+#  define CPL_LSBPTR16(x)       
+#  define CPL_MSBPTR16(x)       CPL_SWAP16PTR(x)
+#  define CPL_LSBPTR32(x)       
+#  define CPL_MSBPTR32(x)       CPL_SWAP32PTR(x)
+#  define CPL_LSBPTR64(x)       
+#  define CPL_MSBPTR64(x)       CPL_SWAP64PTR(x)
+#endif
+
+/** Return a Int16 from the 2 bytes ordered in LSB order at address x */
+#define CPL_LSBINT16PTR(x)    ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8))
+
+/** Return a Int32 from the 4 bytes ordered in LSB order at address x */
+#define CPL_LSBINT32PTR(x)    ((*(GByte*)(x)) | (*(((GByte*)(x))+1) << 8) | \
+                              (*(((GByte*)(x))+2) << 16) | (*(((GByte*)(x))+3) << 24))
+
+/** Return a signed Int16 from the 2 bytes ordered in LSB order at address x */
+#define CPL_LSBSINT16PTR(x) ((GInt16) CPL_LSBINT16PTR(x))
+
+/** Return a unsigned Int16 from the 2 bytes ordered in LSB order at address x */
+#define CPL_LSBUINT16PTR(x) ((GUInt16)CPL_LSBINT16PTR(x))
+
+/** Return a signed Int32 from the 4 bytes ordered in LSB order at address x */
+#define CPL_LSBSINT32PTR(x) ((GInt32) CPL_LSBINT32PTR(x))
+
+/** Return a unsigned Int32 from the 4 bytes ordered in LSB order at address x */
+#define CPL_LSBUINT32PTR(x) ((GUInt32)CPL_LSBINT32PTR(x))
+
+
+/* Utility macro to explicitly mark intentionally unreferenced parameters. */
+#ifndef UNREFERENCED_PARAM 
+#  ifdef UNREFERENCED_PARAMETER /* May be defined by Windows API */
+#    define UNREFERENCED_PARAM(param) UNREFERENCED_PARAMETER(param)
+#  else
+#    define UNREFERENCED_PARAM(param) ((void)param)
+#  endif /* UNREFERENCED_PARAMETER */
+#endif /* UNREFERENCED_PARAM */
+
+/***********************************************************************
+ * Define CPL_CVSID() macro.  It can be disabled during a build by
+ * defining DISABLE_CPLID in the compiler options.
+ *
+ * The cvsid_aw() function is just there to prevent reports of cpl_cvsid()
+ * being unused.
+ */
+
+#ifndef DISABLE_CVSID
+#if defined(__GNUC__) && __GNUC__ >= 4
+#  define CPL_CVSID(string)     static char cpl_cvsid[] __attribute__((used)) = string;
+#else
+#  define CPL_CVSID(string)     static char cpl_cvsid[] = string; \
+static char *cvsid_aw() { return( cvsid_aw() ? ((char *) NULL) : cpl_cvsid ); }
+#endif
+#else
+#  define CPL_CVSID(string)
+#endif
+
+/* Null terminated variadic */
+#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
+#   define CPL_NULL_TERMINATED     __attribute__((__sentinel__))
+#else
+#   define CPL_NULL_TERMINATED
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
+#define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )  __attribute__((__format__ (__printf__, format_idx, arg_idx)))
+#else
+#define CPL_PRINT_FUNC_FORMAT( format_idx, arg_idx )
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 4 && !defined(DOXYGEN_SKIP)
+#define CPL_WARN_UNUSED_RESULT                        __attribute__((warn_unused_result))
+#else
+#define CPL_WARN_UNUSED_RESULT
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 4
+#  define CPL_UNUSED __attribute((__unused__))
+#else
+/* TODO: add cases for other compilers */
+#  define CPL_UNUSED
+#endif
+
+#if defined(__GNUC__) && __GNUC__ >= 3 && !defined(DOXYGEN_SKIP)
+#define CPL_NO_RETURN                                __attribute__((noreturn))
+#else
+#define CPL_NO_RETURN
+#endif
+
+#if !defined(DOXYGEN_SKIP)
+#if defined(__has_extension)
+  #if __has_extension(attribute_deprecated_with_message)
+    /* Clang extension */
+    #define CPL_WARN_DEPRECATED(x)                       __attribute__ ((deprecated(x)))
+  #else
+    #define CPL_WARN_DEPRECATED(x)
+  #endif
+#elif defined(__GNUC__)
+    #define CPL_WARN_DEPRECATED(x)                       __attribute__ ((deprecated))
+#else
+  #define CPL_WARN_DEPRECATED(x)
+#endif
+#endif
+
+#ifdef WARN_STANDARD_PRINTF
+int vsnprintf(char *str, size_t size, const char* fmt, va_list args) CPL_WARN_DEPRECATED("Use CPLvsnprintf() instead");
+int snprintf(char *str, size_t size, const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(3,4) CPL_WARN_DEPRECATED("Use CPLsnprintf() instead");
+int sprintf(char *str, const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_DEPRECATED("Use CPLsprintf() instead");
+#endif
+
+#endif /* ndef CPL_BASE_H_INCLUDED */

+ 47 - 0
libpq_test/include/cpl_progress.h

@@ -0,0 +1,47 @@
+/******************************************************************************
+ * $Id$
+ *
+ * Project:  CPL - Common Portability Library
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ * Purpose:  Prototypes and definitions for progress functions.
+ *
+ ******************************************************************************
+ * Copyright (c) 2013, Frank Warmerdam
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_PROGRESS_H_INCLUDED
+#define CPL_PROGRESS_H_INCLUDED
+
+#include "cpl_port.h"
+
+CPL_C_START
+
+typedef int (CPL_STDCALL *GDALProgressFunc)(double dfComplete, const char *pszMessage, void *pProgressArg);
+
+int CPL_DLL CPL_STDCALL GDALDummyProgress( double, const char *, void *);
+int CPL_DLL CPL_STDCALL GDALTermProgress( double, const char *, void *);
+int CPL_DLL CPL_STDCALL GDALScaledProgress( double, const char *, void *);
+void CPL_DLL * CPL_STDCALL GDALCreateScaledProgress( double, double,
+                                        GDALProgressFunc, void * );
+void CPL_DLL CPL_STDCALL GDALDestroyScaledProgress( void * );
+CPL_C_END
+
+#endif /* ndef CPL_PROGRESS_H_INCLUDED */

+ 100 - 0
libpq_test/include/cpl_quad_tree.h

@@ -0,0 +1,100 @@
+/**********************************************************************
+ * $Id: cpl_quad_tree.h 27044 2014-03-16 23:41:27Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Implementation of quadtree building and searching functions.
+ *           Derived from shapelib and mapserver implementations
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *           Even Rouault, <even dot rouault at mines dash paris dot org>
+ *
+ ******************************************************************************
+ * Copyright (c) 1999-2008, Frank Warmerdam
+ * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_QUAD_TREE_H_INCLUDED
+#define _CPL_QUAD_TREE_H_INCLUDED
+
+#include "cpl_port.h"
+
+/**
+ * \file cpl_quad_tree.h
+ *
+ * Quad tree implementation.
+ *
+ * A quadtree is a tree data structure in which each internal node
+ * has up to four children. Quadtrees are most often used to partition
+ * a two dimensional space by recursively subdividing it into four
+ * quadrants or regions
+ */
+
+CPL_C_START
+
+/* Types */
+
+typedef struct {
+  double minx, miny, maxx, maxy;
+} CPLRectObj;
+
+typedef struct _CPLQuadTree CPLQuadTree;
+
+typedef void         (*CPLQuadTreeGetBoundsFunc)(const void* hFeature, CPLRectObj* pBounds);
+typedef int          (*CPLQuadTreeForeachFunc)(void* pElt, void* pUserData);
+typedef void         (*CPLQuadTreeDumpFeatureFunc)(const void* hFeature, int nIndentLevel, void* pUserData);
+
+/* Functions */
+
+CPLQuadTree CPL_DLL  *CPLQuadTreeCreate(const CPLRectObj* pGlobalBounds,
+                                        CPLQuadTreeGetBoundsFunc pfnGetBounds);
+void        CPL_DLL   CPLQuadTreeDestroy(CPLQuadTree *hQuadtree);
+
+void        CPL_DLL   CPLQuadTreeSetBucketCapacity(CPLQuadTree *hQuadtree,
+                                                   int nBucketCapacity);
+int         CPL_DLL   CPLQuadTreeGetAdvisedMaxDepth(int nExpectedFeatures);
+void        CPL_DLL   CPLQuadTreeSetMaxDepth(CPLQuadTree *hQuadtree,
+                                             int nMaxDepth);
+
+void        CPL_DLL   CPLQuadTreeInsert(CPLQuadTree *hQuadtree,
+                                        void* hFeature);
+void        CPL_DLL   CPLQuadTreeInsertWithBounds(CPLQuadTree *hQuadtree,
+                                                  void* hFeature,
+                                                  const CPLRectObj* psBounds);
+
+void        CPL_DLL **CPLQuadTreeSearch(const CPLQuadTree *hQuadtree,
+                                        const CPLRectObj* pAoi,
+                                        int* pnFeatureCount);
+
+void        CPL_DLL   CPLQuadTreeForeach(const CPLQuadTree *hQuadtree,
+                                         CPLQuadTreeForeachFunc pfnForeach,
+                                         void* pUserData);
+
+void        CPL_DLL   CPLQuadTreeDump(const CPLQuadTree *hQuadtree,
+                                      CPLQuadTreeDumpFeatureFunc pfnDumpFeatureFunc,
+                                      void* pUserData);
+void        CPL_DLL   CPLQuadTreeGetStats(const CPLQuadTree *hQuadtree,
+                                          int* pnFeatureCount,
+                                          int* pnNodeCount,
+                                          int* pnMaxDepth,
+                                          int* pnMaxBucketCapacity);
+
+CPL_C_END
+
+#endif

+ 79 - 0
libpq_test/include/cpl_spawn.h

@@ -0,0 +1,79 @@
+/**********************************************************************
+ * $Id: cpl_spawn.h 27044 2014-03-16 23:41:27Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Implement CPLSystem().
+ * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
+ *
+ **********************************************************************
+ * Copyright (c) 2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_SPAWN_H_INCLUDED
+#define CPL_SPAWN_H_INCLUDED
+
+#include "cpl_vsi.h"
+
+CPL_C_START
+
+/* -------------------------------------------------------------------- */
+/*      Spawn a process.                                                */
+/* -------------------------------------------------------------------- */
+
+int CPL_DLL CPLSpawn( const char * const papszArgv[], VSILFILE* fin, VSILFILE* fout,
+                      int bDisplayErr );
+
+#ifdef WIN32
+#include <windows.h>
+typedef HANDLE CPL_FILE_HANDLE;
+#define CPL_FILE_INVALID_HANDLE NULL
+typedef DWORD  CPL_PID;
+#else
+#include <sys/types.h>
+typedef int    CPL_FILE_HANDLE;
+#define CPL_FILE_INVALID_HANDLE -1
+typedef pid_t  CPL_PID;
+#endif
+
+typedef struct _CPLSpawnedProcess CPLSpawnedProcess;
+
+CPLSpawnedProcess CPL_DLL* CPLSpawnAsync( int (*pfnMain)(CPL_FILE_HANDLE, CPL_FILE_HANDLE),
+                                          const char * const papszArgv[],
+                                          int bCreateInputPipe,
+                                          int bCreateOutputPipe,
+                                          int bCreateErrorPipe,
+                                          char** papszOptions );
+CPL_PID CPL_DLL CPLSpawnAsyncGetChildProcessId(CPLSpawnedProcess* p);
+int CPL_DLL CPLSpawnAsyncFinish(CPLSpawnedProcess* p, int bWait, int bKill);
+CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetInputFileHandle(CPLSpawnedProcess* p);
+CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetOutputFileHandle(CPLSpawnedProcess* p);
+CPL_FILE_HANDLE CPL_DLL CPLSpawnAsyncGetErrorFileHandle(CPLSpawnedProcess* p);
+void CPL_DLL CPLSpawnAsyncCloseInputFileHandle(CPLSpawnedProcess* p);
+void CPL_DLL CPLSpawnAsyncCloseOutputFileHandle(CPLSpawnedProcess* p);
+void CPL_DLL CPLSpawnAsyncCloseErrorFileHandle(CPLSpawnedProcess* p);
+
+int CPL_DLL CPLPipeRead(CPL_FILE_HANDLE fin, void* data, int length);
+int CPL_DLL CPLPipeWrite(CPL_FILE_HANDLE fout, const void* data, int length);
+
+CPL_C_END
+
+#endif // CPL_SPAWN_H_INCLUDED
+

+ 376 - 0
libpq_test/include/cpl_string.h

@@ -0,0 +1,376 @@
+/**********************************************************************
+ * $Id: cpl_string.h 28025 2014-11-28 00:01:32Z rouault $
+ *
+ * Name:     cpl_string.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  String and StringList functions.
+ * Author:   Daniel Morissette, dmorissette@mapgears.com
+ *
+ **********************************************************************
+ * Copyright (c) 1998, Daniel Morissette
+ * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_STRING_H_INCLUDED
+#define _CPL_STRING_H_INCLUDED
+
+#include "cpl_vsi.h"
+#include "cpl_error.h"
+#include "cpl_conv.h"
+
+/**
+ * \file cpl_string.h
+ *
+ * Various convenience functions for working with strings and string lists. 
+ *
+ * A StringList is just an array of strings with the last pointer being
+ * NULL.  An empty StringList may be either a NULL pointer, or a pointer to
+ * a pointer memory location with a NULL value.
+ *
+ * A common convention for StringLists is to use them to store name/value
+ * lists.  In this case the contents are treated like a dictionary of
+ * name/value pairs.  The actual data is formatted with each string having
+ * the format "<name>:<value>" (though "=" is also an acceptable separator). 
+ * A number of the functions in the file operate on name/value style
+ * string lists (such as CSLSetNameValue(), and CSLFetchNameValue()).
+ *
+ * To some extent the CPLStringList C++ class can be used to abstract
+ * managing string lists a bit but still be able to return them from C
+ * functions.
+ *
+ */
+
+CPL_C_START
+
+char CPL_DLL **CSLAddString(char **papszStrList, const char *pszNewString) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL CSLCount(char **papszStrList);
+const char CPL_DLL *CSLGetField( char **, int );
+void CPL_DLL CPL_STDCALL CSLDestroy(char **papszStrList);
+char CPL_DLL **CSLDuplicate(char **papszStrList) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL **CSLMerge( char **papszOrig, char **papszOverride ) CPL_WARN_UNUSED_RESULT;
+
+char CPL_DLL **CSLTokenizeString(const char *pszString ) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL **CSLTokenizeStringComplex(const char *pszString,
+                                   const char *pszDelimiter,
+                                   int bHonourStrings, int bAllowEmptyTokens ) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL **CSLTokenizeString2( const char *pszString, 
+                                   const char *pszDelimeter, 
+                                   int nCSLTFlags ) CPL_WARN_UNUSED_RESULT;
+
+#define CSLT_HONOURSTRINGS      0x0001
+#define CSLT_ALLOWEMPTYTOKENS   0x0002
+#define CSLT_PRESERVEQUOTES     0x0004
+#define CSLT_PRESERVEESCAPES    0x0008
+#define CSLT_STRIPLEADSPACES    0x0010
+#define CSLT_STRIPENDSPACES     0x0020
+
+int CPL_DLL CSLPrint(char **papszStrList, FILE *fpOut);
+char CPL_DLL **CSLLoad(const char *pszFname) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL **CSLLoad2(const char *pszFname, int nMaxLines, int nMaxCols, char** papszOptions) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL CSLSave(char **papszStrList, const char *pszFname);
+
+char CPL_DLL **CSLInsertStrings(char **papszStrList, int nInsertAtLineNo, 
+                         char **papszNewLines) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL **CSLInsertString(char **papszStrList, int nInsertAtLineNo, 
+                               const char *pszNewLine) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL **CSLRemoveStrings(char **papszStrList, int nFirstLineToDelete,
+                         int nNumToRemove, char ***ppapszRetStrings) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL CSLFindString( char **, const char * );
+int CPL_DLL CSLFindStringCaseSensitive( char **, const char * );
+int CPL_DLL CSLPartialFindString( char **papszHaystack, 
+	const char * pszNeedle );
+int CPL_DLL CSLFindName(char **papszStrList, const char *pszName);
+int CPL_DLL CSLTestBoolean( const char *pszValue );
+int CPL_DLL CSLFetchBoolean( char **papszStrList, const char *pszKey, 
+                             int bDefault );
+
+const char CPL_DLL *
+      CPLParseNameValue(const char *pszNameValue, char **ppszKey );
+const char CPL_DLL *
+      CSLFetchNameValue(char **papszStrList, const char *pszName);
+const char CPL_DLL *
+      CSLFetchNameValueDef(char **papszStrList, const char *pszName,
+                           const char *pszDefault );
+char CPL_DLL **
+      CSLFetchNameValueMultiple(char **papszStrList, const char *pszName);
+char CPL_DLL **
+      CSLAddNameValue(char **papszStrList, 
+                      const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL **
+      CSLSetNameValue(char **papszStrList, 
+                      const char *pszName, const char *pszValue) CPL_WARN_UNUSED_RESULT;
+void CPL_DLL CSLSetNameValueSeparator( char ** papszStrList, 
+                                       const char *pszSeparator );
+
+#define CPLES_BackslashQuotable 0
+#define CPLES_XML               1
+#define CPLES_URL               2
+#define CPLES_SQL               3
+#define CPLES_CSV               4
+#define CPLES_XML_BUT_QUOTES    5
+
+char CPL_DLL *CPLEscapeString( const char *pszString, int nLength, 
+                               int nScheme ) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL *CPLUnescapeString( const char *pszString, int *pnLength,
+                                 int nScheme ) CPL_WARN_UNUSED_RESULT;
+
+char CPL_DLL *CPLBinaryToHex( int nBytes, const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
+GByte CPL_DLL *CPLHexToBinary( const char *pszHex, int *pnBytes ) CPL_WARN_UNUSED_RESULT;
+
+char CPL_DLL *CPLBase64Encode( int nBytes, const GByte *pabyData ) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL CPLBase64DecodeInPlace(GByte* pszBase64);
+
+typedef enum
+{
+    CPL_VALUE_STRING,
+    CPL_VALUE_REAL,
+    CPL_VALUE_INTEGER
+} CPLValueType;
+
+CPLValueType CPL_DLL CPLGetValueType(const char* pszValue);
+
+size_t CPL_DLL CPLStrlcpy(char* pszDest, const char* pszSrc, size_t nDestSize);
+size_t CPL_DLL CPLStrlcat(char* pszDest, const char* pszSrc, size_t nDestSize);
+size_t CPL_DLL CPLStrnlen (const char *pszStr, size_t nMaxLen);
+
+/* -------------------------------------------------------------------- */
+/*      Locale independant formatting functions.                        */
+/* -------------------------------------------------------------------- */
+int CPL_DLL CPLvsnprintf(char *str, size_t size, const char* fmt, va_list args);
+int CPL_DLL CPLsnprintf(char *str, size_t size, const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(3,4);
+int CPL_DLL CPLsprintf(char *str, const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3);
+int CPL_DLL CPLprintf(const char* fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
+int CPL_DLL CPLsscanf(const char* str, const char* fmt, ...); /* caution: only works with limited number of formats */
+
+const char CPL_DLL *CPLSPrintf(const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(1, 2);
+char CPL_DLL **CSLAppendPrintf(char **papszStrList, const char *fmt, ...) CPL_PRINT_FUNC_FORMAT(2, 3) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL CPLVASPrintf(char **buf, const char *fmt, va_list args );
+
+/* -------------------------------------------------------------------- */
+/*      RFC 23 character set conversion/recoding API (cpl_recode.cpp).  */
+/* -------------------------------------------------------------------- */
+#define CPL_ENC_LOCALE     ""
+#define CPL_ENC_UTF8       "UTF-8"
+#define CPL_ENC_UTF16      "UTF-16"
+#define CPL_ENC_UCS2       "UCS-2"
+#define CPL_ENC_UCS4       "UCS-4"
+#define CPL_ENC_ASCII      "ASCII"
+#define CPL_ENC_ISO8859_1  "ISO-8859-1"
+
+int CPL_DLL  CPLEncodingCharSize( const char *pszEncoding );
+void CPL_DLL  CPLClearRecodeWarningFlags( void );
+char CPL_DLL *CPLRecode( const char *pszSource, 
+                         const char *pszSrcEncoding, 
+                         const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL *CPLRecodeFromWChar( const wchar_t *pwszSource, 
+                                  const char *pszSrcEncoding, 
+                                  const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
+wchar_t CPL_DLL *CPLRecodeToWChar( const char *pszSource,
+                                   const char *pszSrcEncoding, 
+                                   const char *pszDstEncoding ) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL CPLIsUTF8(const char* pabyData, int nLen);
+char CPL_DLL *CPLForceToASCII(const char* pabyData, int nLen, char chReplacementChar) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL CPLStrlenUTF8(const char *pszUTF8Str);
+
+CPL_C_END
+
+/************************************************************************/
+/*                              CPLString                               */
+/************************************************************************/
+
+#if defined(__cplusplus) && !defined(CPL_SUPRESS_CPLUSPLUS)
+
+#include <string>
+
+/*
+ * Simple trick to avoid "using" declaration in header for new compilers
+ * but make it still working with old compilers which throw C2614 errors.
+ *
+ * Define MSVC_OLD_STUPID_BEHAVIOUR
+ * for old compilers: VC++ 5 and 6 as well as eVC++ 3 and 4.
+ */
+
+/*
+ * Detect old MSVC++ compiler <= 6.0
+ * 1200 - VC++ 6.0
+ * 1200-1202 - eVC++ 4.0
+ */
+#if defined(_MSC_VER) 
+# if (_MSC_VER <= 1202) 
+#  define MSVC_OLD_STUPID_BEHAVIOUR 
+# endif
+#endif
+
+/* Avoid C2614 errors */
+#ifdef MSVC_OLD_STUPID_BEHAVIOUR
+    using std::string;
+# define gdal_std_string string
+#else
+# define gdal_std_string std::string
+#endif 
+
+/* Remove annoying warnings in Microsoft eVC++ and Microsoft Visual C++ */
+#if defined(WIN32CE)
+#  pragma warning(disable:4251 4275 4786)
+#endif
+
+//! Convenient string class based on std::string.
+class CPL_DLL CPLString : public gdal_std_string
+{
+public:
+
+    
+    CPLString(void) {}
+    CPLString( const std::string &oStr ) : gdal_std_string( oStr ) {}
+    CPLString( const char *pszStr ) : gdal_std_string( pszStr ) {}
+    
+    operator const char* (void) const { return c_str(); }
+
+    char& operator[](std::string::size_type i)
+    {
+        return gdal_std_string::operator[](i);
+    }
+    
+    const char& operator[](std::string::size_type i) const
+    {
+        return gdal_std_string::operator[](i);
+    }
+
+    char& operator[](int i)
+    {
+        return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
+    }
+
+    const char& operator[](int i) const
+    {
+        return gdal_std_string::operator[](static_cast<std::string::size_type>(i));
+    }
+
+    void Clear() { resize(0); }
+
+    // NULL safe assign and free.
+    void Seize(char *pszValue) 
+    {
+        if (pszValue == NULL )
+            Clear();
+        else
+        {
+            *this = pszValue;
+            CPLFree(pszValue);
+        }
+    }
+
+    /* There seems to be a bug in the way the compiler count indices... Should be CPL_PRINT_FUNC_FORMAT (1, 2) */
+    CPLString &Printf( const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (2, 3);
+    CPLString &vPrintf( const char *pszFormat, va_list args );
+    CPLString &FormatC( double dfValue, const char *pszFormat = NULL );
+    CPLString &Trim();
+    CPLString &Recode( const char *pszSrcEncoding, const char *pszDstEncoding );
+
+    /* case insensitive find alternates */
+    size_t    ifind( const std::string & str, size_t pos = 0 ) const;
+    size_t    ifind( const char * s, size_t pos = 0 ) const;
+    CPLString &toupper( void );
+    CPLString &tolower( void );
+};
+
+CPLString CPLOPrintf(const char *pszFormat, ... ) CPL_PRINT_FUNC_FORMAT (1, 2);
+CPLString CPLOvPrintf(const char *pszFormat, va_list args);
+
+/* -------------------------------------------------------------------- */
+/*      URL processing functions, here since they depend on CPLString.  */
+/* -------------------------------------------------------------------- */
+CPLString CPL_DLL CPLURLGetValue(const char* pszURL, const char* pszKey);
+CPLString CPL_DLL CPLURLAddKVP(const char* pszURL, const char* pszKey,
+                               const char* pszValue);
+
+/************************************************************************/
+/*                            CPLStringList                             */
+/************************************************************************/
+
+//! String list class designed around our use of C "char**" string lists.
+class CPL_DLL CPLStringList
+{
+    char **papszList;
+    mutable int nCount;
+    mutable int nAllocation;
+    int    bOwnList;
+    int    bIsSorted;
+
+    void   Initialize();
+    void   MakeOurOwnCopy();
+    void   EnsureAllocation( int nMaxLength );
+    int    FindSortedInsertionPoint( const char *pszLine );
+    
+  public:
+    CPLStringList();
+    CPLStringList( char **papszList, int bTakeOwnership=TRUE );
+    CPLStringList( const CPLStringList& oOther );
+    ~CPLStringList();
+
+    CPLStringList &Clear();
+
+    int    size() const { return Count(); }
+    int    Count() const;
+
+    CPLStringList &AddString( const char *pszNewString );
+    CPLStringList &AddStringDirectly( char *pszNewString );
+
+    CPLStringList &InsertString( int nInsertAtLineNo, const char *pszNewLine )
+    { return InsertStringDirectly( nInsertAtLineNo, CPLStrdup(pszNewLine) ); }
+    CPLStringList &InsertStringDirectly( int nInsertAtLineNo, char *pszNewLine);
+    
+//    CPLStringList &InsertStrings( int nInsertAtLineNo, char **papszNewLines );
+//    CPLStringList &RemoveStrings( int nFirstLineToDelete, int nNumToRemove=1 );
+    
+    int    FindString( const char *pszTarget ) const
+    { return CSLFindString( papszList, pszTarget ); }
+    int    PartialFindString( const char *pszNeedle ) const
+    { return CSLPartialFindString( papszList, pszNeedle ); }
+
+    int    FindName( const char *pszName ) const;
+    int    FetchBoolean( const char *pszKey, int bDefault ) const;
+    const char *FetchNameValue( const char *pszKey ) const;
+    const char *FetchNameValueDef( const char *pszKey, const char *pszDefault ) const;
+    CPLStringList &AddNameValue( const char *pszKey, const char *pszValue );
+    CPLStringList &SetNameValue( const char *pszKey, const char *pszValue );
+
+    CPLStringList &Assign( char **papszListIn, int bTakeOwnership=TRUE );
+    CPLStringList &operator=(char **papszListIn) { return Assign( papszListIn, TRUE ); }
+    CPLStringList &operator=(const CPLStringList& oOther);
+
+    char * operator[](int i);
+    char * operator[](size_t i) { return (*this)[(int)i]; }
+    const char * operator[](int i) const;
+    const char * operator[](size_t i) const { return (*this)[(int)i]; }
+
+    char **List() { return papszList; }
+    char **StealList();
+
+    CPLStringList &Sort();
+    int    IsSorted() const { return bIsSorted; }
+
+    operator char**(void) { return List(); }
+};
+
+#endif /* def __cplusplus && !CPL_SUPRESS_CPLUSPLUS */
+
+#endif /* _CPL_STRING_H_INCLUDED */

+ 41 - 0
libpq_test/include/cpl_time.h

@@ -0,0 +1,41 @@
+/**********************************************************************
+ * $Id: cpl_time.h 29469 2015-07-04 11:42:30Z rouault $
+ *
+ * Name:     cpl_time.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Time functions.
+ * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
+ *
+ **********************************************************************
+ * Copyright (c) 2009, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_TIME_H_INCLUDED
+#define _CPL_TIME_H_INCLUDED
+
+#include <time.h>
+
+#include "cpl_port.h"
+
+struct tm CPL_DLL * CPLUnixTimeToYMDHMS(GIntBig unixTime, struct tm* pRet);
+GIntBig CPL_DLL CPLYMDHMSToUnixTime(const struct tm *brokendowntime);
+
+#endif // _CPL_TIME_H_INCLUDED

+ 389 - 0
libpq_test/include/cpl_virtualmem.h

@@ -0,0 +1,389 @@
+/**********************************************************************
+ * $Id: cpl_virtualmem.h 29330 2015-06-14 12:11:11Z rouault $
+ *
+ * Name:     cpl_virtualmem.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Virtual memory
+ * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
+ *
+ **********************************************************************
+ * Copyright (c) 2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ * 
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ * 
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef _CPL_VIRTUAL_MEM_INCLUDED
+#define _CPL_VIRTUAL_MEM_INCLUDED
+
+#include "cpl_port.h"
+#include "cpl_vsi.h"
+
+CPL_C_START
+
+/**
+ * \file cpl_virtualmem.h
+ *
+ * Virtual memory management.
+ *
+ * This file provides mechanism to define virtual memory mappings, whose content
+ * is allocated transparently and filled on-the-fly. Those virtual memory mappings
+ * can be much larger than the available RAM, but only parts of the virtual
+ * memory mapping, in the limit of the allowed the cache size, will actually be
+ * physically allocated.
+ *
+ * This exploits low-level mechanisms of the operating system (virtual memory
+ * allocation, page protection and handler of virtual memory exceptions).
+ *
+ * It is also possible to create a virtual memory mapping from a file or part
+ * of a file.
+ *
+ * The current implementation is Linux only.
+ */
+
+/** Opaque type that represents a virtual memory mapping. */
+typedef struct CPLVirtualMem CPLVirtualMem;
+
+/** Callback triggered when a still unmapped page of virtual memory is accessed.
+  * The callback has the responsibility of filling the page with relevant values
+  *
+  * @param ctxt virtual memory handle.
+  * @param nOffset offset of the page in the memory mapping.
+  * @param pPageToFill address of the page to fill. Note that the address might
+  *                    be a temporary location, and not at CPLVirtualMemGetAddr() + nOffset.
+  * @param nToFill number of bytes of the page.
+  * @param pUserData user data that was passed to CPLVirtualMemNew().
+  */
+typedef void (*CPLVirtualMemCachePageCbk)(CPLVirtualMem* ctxt,
+                                    size_t nOffset,
+                                    void* pPageToFill,
+                                    size_t nToFill,
+                                    void* pUserData);
+
+/** Callback triggered when a dirty mapped page is going to be freed.
+  * (saturation of cache, or termination of the virtual memory mapping).
+  *
+  * @param ctxt virtual memory handle.
+  * @param nOffset offset of the page in the memory mapping.
+  * @param pPageToBeEvicted address of the page that will be flushed. Note that the address might
+  *                    be a temporary location, and not at CPLVirtualMemGetAddr() + nOffset.
+  * @param nToBeEvicted number of bytes of the page.
+  * @param pUserData user data that was passed to CPLVirtualMemNew().
+  */
+typedef void (*CPLVirtualMemUnCachePageCbk)(CPLVirtualMem* ctxt,
+                                      size_t nOffset,
+                                      const void* pPageToBeEvicted,
+                                      size_t nToBeEvicted,
+                                      void* pUserData);
+
+/** Callback triggered when a virtual memory mapping is destroyed.
+  * @param pUserData user data that was passed to CPLVirtualMemNew().
+ */
+typedef void (*CPLVirtualMemFreeUserData)(void* pUserData);
+
+/** Access mode of a virtual memory mapping. */
+typedef enum
+{
+    /*! The mapping is meant at being read-only, but writes will not be prevented.
+        Note that any content written will be lost. */
+    VIRTUALMEM_READONLY,
+    /*! The mapping is meant at being read-only, and this will be enforced 
+        through the operating system page protection mechanism. */
+    VIRTUALMEM_READONLY_ENFORCED,
+    /*! The mapping is meant at being read-write, and modified pages can be saved
+        thanks to the pfnUnCachePage callback */
+    VIRTUALMEM_READWRITE
+} CPLVirtualMemAccessMode;
+
+
+/** Return the size of a page of virtual memory.
+ *
+ * @return the page size.
+ *
+ * @since GDAL 1.11
+ */
+size_t CPL_DLL CPLGetPageSize(void);
+
+/** Create a new virtual memory mapping.
+ *
+ * This will reserve an area of virtual memory of size nSize, whose size
+ * might be potentially much larger than the physical memory available. Initially,
+ * no physical memory will be allocated. As soon as memory pages will be accessed,
+ * they will be allocated transparently and filled with the pfnCachePage callback.
+ * When the allowed cache size is reached, the least recently used pages will
+ * be unallocated.
+ *
+ * On Linux AMD64 platforms, the maximum value for nSize is 128 TB.
+ * On Linux x86 platforms, the maximum value for nSize is 2 GB.
+ *
+ * Only supported on Linux for now.
+ *
+ * Note that on Linux, this function will install a SIGSEGV handler. The
+ * original handler will be restored by CPLVirtualMemManagerTerminate().
+ *
+ * @param nSize size in bytes of the virtual memory mapping.
+ * @param nCacheSize   size in bytes of the maximum memory that will be really
+ *                     allocated (must ideally fit into RAM).
+ * @param nPageSizeHint hint for the page size. Must be a multiple of the
+ *                      system page size, returned by CPLGetPageSize().
+ *                      Minimum value is generally 4096. Might be set to 0 to
+ *                      let the function determine a default page size.
+ * @param bSingleThreadUsage set to TRUE if there will be no concurrent threads
+ *                           that will access the virtual memory mapping. This can
+ *                           optimize performance a bit.
+ * @param eAccessMode permission to use for the virtual memory mapping.
+ * @param pfnCachePage callback triggered when a still unmapped page of virtual
+ *                     memory is accessed. The callback has the responsibility
+ *                     of filling the page with relevant values.
+ * @param pfnUnCachePage callback triggered when a dirty mapped page is going to
+ *                       be freed (saturation of cache, or termination of the
+ *                       virtual memory mapping). Might be NULL.
+ * @param pfnFreeUserData callback that can be used to free pCbkUserData. Might be
+ *                        NULL
+ * @param pCbkUserData user data passed to pfnCachePage and pfnUnCachePage.
+ *
+ * @return a virtual memory object that must be freed by CPLVirtualMemFree(),
+ *         or NULL in case of failure.
+ *
+ * @since GDAL 1.11
+ */
+
+CPLVirtualMem CPL_DLL *CPLVirtualMemNew(size_t nSize,
+                                        size_t nCacheSize,
+                                        size_t nPageSizeHint,
+                                        int bSingleThreadUsage,
+                                        CPLVirtualMemAccessMode eAccessMode,
+                                        CPLVirtualMemCachePageCbk pfnCachePage,
+                                        CPLVirtualMemUnCachePageCbk pfnUnCachePage,
+                                        CPLVirtualMemFreeUserData pfnFreeUserData,
+                                        void *pCbkUserData);
+
+
+/** Return if virtual memory mapping of a file is available.
+ *
+ * @return TRUE if virtual memory mapping of a file is available.
+ * @since GDAL 1.11
+ */
+int CPL_DLL CPLIsVirtualMemFileMapAvailable(void);
+
+/** Create a new virtual memory mapping from a file.
+ *
+ * The file must be a "real" file recognized by the operating system, and not
+ * a VSI extended virtual file.
+ *
+ * In VIRTUALMEM_READWRITE mode, updates to the memory mapping will be written
+ * in the file.
+ *
+ * On Linux AMD64 platforms, the maximum value for nLength is 128 TB.
+ * On Linux x86 platforms, the maximum value for nLength is 2 GB.
+ *
+ * Only supported on Linux for now.
+ *
+ * @param  fp       Virtual file handle.
+ * @param  nOffset  Offset in the file to start the mapping from.
+ * @param  nLength  Length of the portion of the file to map into memory.
+ * @param eAccessMode Permission to use for the virtual memory mapping. This must
+ *                    be consistent with how the file has been opened.
+ * @param pfnFreeUserData callback that is called when the object is destroyed.
+ * @param pCbkUserData user data passed to pfnFreeUserData.
+ * @return a virtual memory object that must be freed by CPLVirtualMemFree(),
+ *         or NULL in case of failure.
+ *
+ * @since GDAL 1.11
+ */
+CPLVirtualMem CPL_DLL *CPLVirtualMemFileMapNew( VSILFILE* fp,
+                                                vsi_l_offset nOffset,
+                                                vsi_l_offset nLength,
+                                                CPLVirtualMemAccessMode eAccessMode,
+                                                CPLVirtualMemFreeUserData pfnFreeUserData,
+                                                void *pCbkUserData );
+
+/** Create a new virtual memory mapping derived from an other virtual memory
+ *  mapping.
+ *
+ * This may be useful in case of creating mapping for pixel interleaved data.
+ *
+ * The new mapping takes a reference on the base mapping.
+ *
+ * @param pVMemBase Base virtual memory mapping
+ * @param nOffset   Offset in the base virtual memory mapping from which to start
+ *                  the new mapping.
+ * @param nSize     Size of the base virtual memory mapping to expose in the
+ *                  the new mapping.
+ * @param pfnFreeUserData callback that is called when the object is destroyed.
+ * @param pCbkUserData user data passed to pfnFreeUserData.
+ * @return a virtual memory object that must be freed by CPLVirtualMemFree(),
+ *         or NULL in case of failure.
+ *
+ * @since GDAL 1.11
+ */
+CPLVirtualMem CPL_DLL *CPLVirtualMemDerivedNew(CPLVirtualMem* pVMemBase,
+                                               vsi_l_offset nOffset,
+                                               vsi_l_offset nSize,
+                                               CPLVirtualMemFreeUserData pfnFreeUserData,
+                                               void *pCbkUserData);
+
+/** Free a virtual memory mapping.
+ *
+ * The pointer returned by CPLVirtualMemGetAddr() will no longer be valid.
+ * If the virtual memory mapping was created with read/write permissions and that
+ * they are dirty (i.e. modified) pages, they will be flushed through the
+ * pfnUnCachePage callback before being freed.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ *
+ * @since GDAL 1.11
+ */
+void CPL_DLL CPLVirtualMemFree(CPLVirtualMem* ctxt);
+
+/** Return the pointer to the start of a virtual memory mapping.
+ *
+ * The bytes in the range [p:p+CPLVirtualMemGetSize()-1] where p is the pointer
+ * returned by this function will be valid, until CPLVirtualMemFree() is called.
+ *
+ * Note that if a range of bytes used as an argument of a system call
+ * (such as read() or write()) contains pages that have not been "realized", the
+ * system call will fail with EFAULT. CPLVirtualMemPin() can be used to work
+ * around this issue.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ * @return the pointer to the start of a virtual memory mapping.
+ *
+ * @since GDAL 1.11
+ */
+void CPL_DLL *CPLVirtualMemGetAddr(CPLVirtualMem* ctxt);
+
+/** Return the size of the virtual memory mapping.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ * @return the size of the virtual memory mapping.
+ *
+ * @since GDAL 1.11
+ */
+size_t CPL_DLL CPLVirtualMemGetSize(CPLVirtualMem* ctxt);
+
+/** Return if the virtal memory mapping is a direct file mapping.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ * @return TRUE if the virtal memory mapping is a direct file mapping.
+ *
+ * @since GDAL 1.11
+ */
+int CPL_DLL CPLVirtualMemIsFileMapping(CPLVirtualMem* ctxt);
+
+/** Return the access mode of the virtual memory mapping.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ * @return the access mode of the virtual memory mapping.
+ *
+ * @since GDAL 1.11
+ */
+CPLVirtualMemAccessMode CPL_DLL CPLVirtualMemGetAccessMode(CPLVirtualMem* ctxt);
+
+/** Return the page size associated to a virtual memory mapping.
+ *
+ * The value returned will be at least CPLGetPageSize(), but potentially
+ * larger.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ * @return the page size
+ *
+ * @since GDAL 1.11
+ */
+size_t CPL_DLL CPLVirtualMemGetPageSize(CPLVirtualMem* ctxt);
+
+/** Return TRUE if this memory mapping can be accessed safely from concurrent
+ *  threads.
+ *
+ * The situation that can cause problems is when several threads try to access
+ * a page of the mapping that is not yet mapped.
+ *
+ * The return value of this function depends on whether bSingleThreadUsage has
+ * been set of not in CPLVirtualMemNew() and/or the implementation.
+ *
+ * On Linux, this will always return TRUE if bSingleThreadUsage = FALSE.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ * @return TRUE if this memory mapping can be accessed safely from concurrent
+ *         threads.
+ *
+ * @since GDAL 1.11
+ */
+int CPL_DLL CPLVirtualMemIsAccessThreadSafe(CPLVirtualMem* ctxt);
+
+/** Declare that a thread will access a virtual memory mapping.
+ *
+ * This function must be called by a thread that wants to access the
+ * content of a virtual memory mapping, except if the virtual memory mapping has
+ * been created with bSingleThreadUsage = TRUE.
+ *
+ * This function must be paired with CPLVirtualMemUnDeclareThread().
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ *
+ * @since GDAL 1.11
+ */
+void CPL_DLL CPLVirtualMemDeclareThread(CPLVirtualMem* ctxt);
+
+/** Declare that a thread will stop accessing a virtual memory mapping.
+ *
+ * This function must be called by a thread that will no longer access the
+ * content of a virtual memory mapping, except if the virtual memory mapping has
+ * been created with bSingleThreadUsage = TRUE.
+ *
+ * This function must be paired with CPLVirtualMemDeclareThread().
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ *
+ * @since GDAL 1.11
+ */
+void CPL_DLL CPLVirtualMemUnDeclareThread(CPLVirtualMem* ctxt);
+
+/** Make sure that a region of virtual memory will be realized.
+ *
+ * Calling this function is not required, but might be useful when debugging
+ * a process with tools like gdb or valgrind that do not naturally like
+ * segmentation fault signals.
+ *
+ * It is also needed when wanting to provide part of virtual memory mapping
+ * to a system call such as read() or write(). If read() or write() is called
+ * on a memory region not yet realized, the call will fail with EFAULT.
+ *
+ * @param ctxt context returned by CPLVirtualMemNew().
+ * @param pAddr the memory region to pin.
+ * @param nSize the size of the memory region.
+ * @param bWriteOp set to TRUE if the memory are will be accessed in write mode.
+ *
+ * @since GDAL 1.11
+ */
+void CPL_DLL CPLVirtualMemPin(CPLVirtualMem* ctxt,
+                              void* pAddr, size_t nSize, int bWriteOp);
+
+/** Cleanup any resource and handlers related to virtual memory.
+ *
+ * This function must be called after the last CPLVirtualMem object has
+ * been freed.
+ *
+ * @since GDAL 2.0
+ */
+void CPL_DLL CPLVirtualMemManagerTerminate(void);
+
+
+CPL_C_END
+
+#endif /* _CPL_VIRTUAL_MEM_INCLUDED */

+ 284 - 0
libpq_test/include/cpl_vsi.h

@@ -0,0 +1,284 @@
+/******************************************************************************
+ * $Id: cpl_vsi.h 28476 2015-02-13 14:40:11Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ * Purpose:  Include file defining Virtual File System (VSI) functions, a
+ *           layer over POSIX file and other system services. 
+ *
+ ******************************************************************************
+ * Copyright (c) 1998, Frank Warmerdam
+ * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_VSI_H_INCLUDED
+#define CPL_VSI_H_INCLUDED
+
+#include "cpl_port.h"
+/**
+ * \file cpl_vsi.h
+ *
+ * Standard C Covers
+ *
+ * The VSI functions are intended to be hookable aliases for Standard C
+ * I/O, memory allocation and other system functions. They are intended
+ * to allow virtualization of disk I/O so that non file data sources
+ * can be made to appear as files, and so that additional error trapping
+ * and reporting can be interested.  The memory access API is aliased
+ * so that special application memory management services can be used.
+ *
+ * Is is intended that each of these functions retains exactly the same
+ * calling pattern as the original Standard C functions they relate to.
+ * This means we don't have to provide custom documentation, and also means
+ * that the default implementation is very simple.
+ */
+
+
+/* -------------------------------------------------------------------- */
+/*      We need access to ``struct stat''.                              */
+/* -------------------------------------------------------------------- */
+
+/* Unix */
+#if !defined(_WIN32) && !defined(_WIN32_WCE)
+#  include <unistd.h>
+#endif
+
+/* Windows */
+#if !defined(macos_pre10) && !defined(_WIN32_WCE)
+#  include <sys/stat.h>
+#endif
+
+/* Windows CE */
+#if defined(_WIN32_WCE)
+#  include <wce_stat.h>
+#endif
+
+CPL_C_START
+
+/* ==================================================================== */
+/*      stdio file access functions.  These may not support large       */
+/*      files, and don't necessarily go through the virtualization      */
+/*      API.                                                            */
+/* ==================================================================== */
+
+FILE CPL_DLL *  VSIFOpen( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL     VSIFClose( FILE * );
+int CPL_DLL     VSIFSeek( FILE *, long, int );
+long CPL_DLL    VSIFTell( FILE * );
+void CPL_DLL    VSIRewind( FILE * );
+void CPL_DLL    VSIFFlush( FILE * );
+
+size_t CPL_DLL  VSIFRead( void *, size_t, size_t, FILE * );
+size_t CPL_DLL  VSIFWrite( const void *, size_t, size_t, FILE * );
+char CPL_DLL   *VSIFGets( char *, int, FILE * );
+int CPL_DLL     VSIFPuts( const char *, FILE * );
+int CPL_DLL     VSIFPrintf( FILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3);
+
+int CPL_DLL     VSIFGetc( FILE * );
+int CPL_DLL     VSIFPutc( int, FILE * );
+int CPL_DLL     VSIUngetc( int, FILE * );
+int CPL_DLL     VSIFEof( FILE * );
+
+/* ==================================================================== */
+/*      VSIStat() related.                                              */
+/* ==================================================================== */
+
+typedef struct stat VSIStatBuf;
+int CPL_DLL VSIStat( const char *, VSIStatBuf * );
+
+#ifdef _WIN32
+#  define VSI_ISLNK(x)  ( 0 )            /* N/A on Windows */
+#  define VSI_ISREG(x)  ((x) & S_IFREG)
+#  define VSI_ISDIR(x)  ((x) & S_IFDIR)
+#  define VSI_ISCHR(x)  ((x) & S_IFCHR)
+#  define VSI_ISBLK(x)  ( 0 )            /* N/A on Windows */
+#else
+#  define VSI_ISLNK(x)  S_ISLNK(x)
+#  define VSI_ISREG(x)  S_ISREG(x)
+#  define VSI_ISDIR(x)  S_ISDIR(x)
+#  define VSI_ISCHR(x)  S_ISCHR(x)
+#  define VSI_ISBLK(x)  S_ISBLK(x)
+#endif
+
+/* ==================================================================== */
+/*      64bit stdio file access functions.  If we have a big size       */
+/*      defined, then provide protypes for the large file API,          */
+/*      otherwise redefine to use the regular api.                      */
+/* ==================================================================== */
+typedef GUIntBig vsi_l_offset;
+
+/* Make VSIL_STRICT_ENFORCE active in DEBUG builds */
+#ifdef DEBUG
+#define VSIL_STRICT_ENFORCE
+#endif
+
+#ifdef VSIL_STRICT_ENFORCE
+typedef struct _VSILFILE VSILFILE;
+#else
+typedef FILE VSILFILE;
+#endif
+
+VSILFILE CPL_DLL *  VSIFOpenL( const char *, const char * ) CPL_WARN_UNUSED_RESULT;
+int CPL_DLL     VSIFCloseL( VSILFILE * );
+int CPL_DLL     VSIFSeekL( VSILFILE *, vsi_l_offset, int );
+vsi_l_offset CPL_DLL VSIFTellL( VSILFILE * );
+void CPL_DLL    VSIRewindL( VSILFILE * );
+size_t CPL_DLL  VSIFReadL( void *, size_t, size_t, VSILFILE * );
+int CPL_DLL     VSIFReadMultiRangeL( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes, VSILFILE * );
+size_t CPL_DLL  VSIFWriteL( const void *, size_t, size_t, VSILFILE * );
+int CPL_DLL     VSIFEofL( VSILFILE * );
+int CPL_DLL     VSIFTruncateL( VSILFILE *, vsi_l_offset );
+int CPL_DLL     VSIFFlushL( VSILFILE * );
+int CPL_DLL     VSIFPrintfL( VSILFILE *, const char *, ... ) CPL_PRINT_FUNC_FORMAT(2, 3);
+int CPL_DLL     VSIFPutcL( int, VSILFILE * );
+
+int CPL_DLL     VSIIngestFile( VSILFILE* fp,
+                               const char* pszFilename,
+                               GByte** ppabyRet,
+                               vsi_l_offset* pnSize,
+                               GIntBig nMaxSize );
+
+#if defined(VSI_STAT64_T)
+typedef struct VSI_STAT64_T VSIStatBufL;
+#else
+#define VSIStatBufL    VSIStatBuf
+#endif
+
+int CPL_DLL     VSIStatL( const char *, VSIStatBufL * );
+
+#define VSI_STAT_EXISTS_FLAG    0x1
+#define VSI_STAT_NATURE_FLAG    0x2
+#define VSI_STAT_SIZE_FLAG      0x4
+
+int CPL_DLL     VSIStatExL( const char * pszFilename, VSIStatBufL * psStatBuf, int nFlags );
+
+int CPL_DLL     VSIIsCaseSensitiveFS( const char * pszFilename );
+
+void CPL_DLL   *VSIFGetNativeFileDescriptorL( VSILFILE* );
+
+/* ==================================================================== */
+/*      Memory allocation                                               */
+/* ==================================================================== */
+
+void CPL_DLL   *VSICalloc( size_t, size_t ) CPL_WARN_UNUSED_RESULT;
+void CPL_DLL   *VSIMalloc( size_t ) CPL_WARN_UNUSED_RESULT;
+void CPL_DLL    VSIFree( void * );
+void CPL_DLL   *VSIRealloc( void *, size_t ) CPL_WARN_UNUSED_RESULT;
+char CPL_DLL   *VSIStrdup( const char * ) CPL_WARN_UNUSED_RESULT;
+
+/**
+ VSIMalloc2 allocates (nSize1 * nSize2) bytes.
+ In case of overflow of the multiplication, or if memory allocation fails, a
+ NULL pointer is returned and a CE_Failure error is raised with CPLError().
+ If nSize1 == 0 || nSize2 == 0, a NULL pointer will also be returned.
+ CPLFree() or VSIFree() can be used to free memory allocated by this function.
+*/
+void CPL_DLL *VSIMalloc2( size_t nSize1, size_t nSize2 ) CPL_WARN_UNUSED_RESULT;
+
+/**
+ VSIMalloc3 allocates (nSize1 * nSize2 * nSize3) bytes.
+ In case of overflow of the multiplication, or if memory allocation fails, a
+ NULL pointer is returned and a CE_Failure error is raised with CPLError().
+ If nSize1 == 0 || nSize2 == 0 || nSize3 == 0, a NULL pointer will also be returned.
+ CPLFree() or VSIFree() can be used to free memory allocated by this function.
+*/
+void CPL_DLL *VSIMalloc3( size_t nSize1, size_t nSize2, size_t nSize3 ) CPL_WARN_UNUSED_RESULT;
+
+GIntBig CPL_DLL CPLGetPhysicalRAM(void);
+GIntBig CPL_DLL CPLGetUsablePhysicalRAM(void);
+
+/* ==================================================================== */
+/*      Other...                                                        */
+/* ==================================================================== */
+
+#define CPLReadDir VSIReadDir
+char CPL_DLL **VSIReadDir( const char * );
+char CPL_DLL **VSIReadDirRecursive( const char *pszPath );
+int CPL_DLL VSIMkdir( const char * pathname, long mode );
+int CPL_DLL VSIRmdir( const char * pathname );
+int CPL_DLL VSIUnlink( const char * pathname );
+int CPL_DLL VSIRename( const char * oldpath, const char * newpath );
+char CPL_DLL *VSIStrerror( int );
+
+/* ==================================================================== */
+/*      Install special file access handlers.                           */
+/* ==================================================================== */
+void CPL_DLL VSIInstallMemFileHandler(void);
+void CPL_DLL VSIInstallLargeFileHandler(void);
+void CPL_DLL VSIInstallSubFileHandler(void);
+void VSIInstallCurlFileHandler(void);
+void VSIInstallCurlStreamingFileHandler(void);
+void VSIInstallGZipFileHandler(void); /* No reason to export that */
+void VSIInstallZipFileHandler(void); /* No reason to export that */
+void VSIInstallStdinHandler(void); /* No reason to export that */
+void VSIInstallStdoutHandler(void); /* No reason to export that */
+void CPL_DLL VSIInstallSparseFileHandler(void);
+void VSIInstallTarFileHandler(void); /* No reason to export that */
+void CPL_DLL VSICleanupFileManager(void);
+
+VSILFILE CPL_DLL *VSIFileFromMemBuffer( const char *pszFilename,
+                                    GByte *pabyData, 
+                                    vsi_l_offset nDataLength,
+                                    int bTakeOwnership );
+GByte CPL_DLL *VSIGetMemFileBuffer( const char *pszFilename, 
+                                    vsi_l_offset *pnDataLength, 
+                                    int bUnlinkAndSeize );
+
+typedef size_t (*VSIWriteFunction)(const void* ptr, size_t size, size_t nmemb, FILE* stream);
+void CPL_DLL VSIStdoutSetRedirection( VSIWriteFunction pFct, FILE* stream );
+
+/* ==================================================================== */
+/*      Time quering.                                                   */
+/* ==================================================================== */
+
+unsigned long CPL_DLL VSITime( unsigned long * );
+const char CPL_DLL *VSICTime( unsigned long );
+struct tm CPL_DLL *VSIGMTime( const time_t *pnTime,
+                              struct tm *poBrokenTime );
+struct tm CPL_DLL *VSILocalTime( const time_t *pnTime,
+                                 struct tm *poBrokenTime );
+
+/* -------------------------------------------------------------------- */
+/*      the following can be turned on for detailed logging of          */
+/*      almost all IO calls.                                            */
+/* -------------------------------------------------------------------- */
+#ifdef VSI_DEBUG
+
+#ifndef DEBUG
+#  define DEBUG
+#endif
+
+#include "cpl_error.h"
+
+#define VSIDebug4(f,a1,a2,a3,a4)   CPLDebug( "VSI", f, a1, a2, a3, a4 );
+#define VSIDebug3( f, a1, a2, a3 ) CPLDebug( "VSI", f, a1, a2, a3 );
+#define VSIDebug2( f, a1, a2 )     CPLDebug( "VSI", f, a1, a2 );
+#define VSIDebug1( f, a1 )         CPLDebug( "VSI", f, a1 );
+#else
+#define VSIDebug4( f, a1, a2, a3, a4 ) {}
+#define VSIDebug3( f, a1, a2, a3 ) {}
+#define VSIDebug2( f, a1, a2 )     {}
+#define VSIDebug1( f, a1 )         {}
+#endif
+
+CPL_C_END
+
+#endif /* ndef CPL_VSI_H_INCLUDED */

+ 202 - 0
libpq_test/include/cpl_vsi_virtual.h

@@ -0,0 +1,202 @@
+/******************************************************************************
+ * $Id: cpl_vsi_virtual.h 29388 2015-06-17 18:28:29Z rouault $
+ *
+ * Project:  VSI Virtual File System
+ * Purpose:  Declarations for classes related to the virtual filesystem.
+ *           These would only be normally required by applications implmenting
+ *           their own virtual file system classes which should be rare.  
+ *           The class interface may be fragile through versions.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
+ * Copyright (c) 2010-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_VSI_VIRTUAL_H_INCLUDED
+#define CPL_VSI_VIRTUAL_H_INCLUDED
+
+#include "cpl_vsi.h"
+#include "cpl_string.h"
+#include "cpl_multiproc.h"
+
+#if defined(WIN32CE)
+#  include "cpl_wince.h"
+#  include <wce_errno.h>
+#  pragma warning(disable:4786) /* Remove annoying warnings in eVC++ and VC++ 6.0 */
+#endif
+
+#include <map>
+#include <vector>
+#include <string>
+
+/************************************************************************/
+/*                           VSIVirtualHandle                           */
+/************************************************************************/
+
+class CPL_DLL VSIVirtualHandle { 
+  public:
+    virtual int       Seek( vsi_l_offset nOffset, int nWhence ) = 0;
+    virtual vsi_l_offset Tell() = 0;
+    virtual size_t    Read( void *pBuffer, size_t nSize, size_t nMemb ) = 0;
+    virtual int       ReadMultiRange( int nRanges, void ** ppData, const vsi_l_offset* panOffsets, const size_t* panSizes );
+    virtual size_t    Write( const void *pBuffer, size_t nSize,size_t nMemb)=0;
+    virtual int       Eof() = 0;
+    virtual int       Flush() {return 0;}
+    virtual int       Close() = 0;
+    virtual int       Truncate( CPL_UNUSED vsi_l_offset nNewSize ) { return -1; }
+    virtual void     *GetNativeFileDescriptor() { return NULL; }
+    virtual           ~VSIVirtualHandle() { }
+};
+
+/************************************************************************/
+/*                         VSIFilesystemHandler                         */
+/************************************************************************/
+
+class CPL_DLL VSIFilesystemHandler {
+
+public:
+
+    virtual ~VSIFilesystemHandler() {}
+
+    virtual VSIVirtualHandle *Open( const char *pszFilename, 
+                                    const char *pszAccess) = 0;
+    virtual int Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags) = 0;
+    virtual int Unlink( const char *pszFilename )
+                      { (void) pszFilename; errno=ENOENT; return -1; }
+    virtual int Mkdir( const char *pszDirname, long nMode ) 
+                      {(void)pszDirname; (void)nMode; errno=ENOENT; return -1;}
+    virtual int Rmdir( const char *pszDirname ) 
+                      { (void) pszDirname; errno=ENOENT; return -1; }
+    virtual char **ReadDir( const char *pszDirname ) 
+                      { (void) pszDirname; return NULL; }
+    virtual int Rename( const char *oldpath, const char *newpath )
+                      { (void) oldpath; (void)newpath; errno=ENOENT; return -1; }
+    virtual int IsCaseSensitive( const char* pszFilename )
+                      { (void) pszFilename; return TRUE; }
+};
+
+/************************************************************************/
+/*                            VSIFileManager                            */
+/************************************************************************/
+
+class CPL_DLL VSIFileManager 
+{
+private:
+    VSIFilesystemHandler *poDefaultHandler;
+    std::map<std::string, VSIFilesystemHandler *> oHandlers;
+
+    VSIFileManager();
+
+    static VSIFileManager *Get();
+
+public:
+    ~VSIFileManager();
+
+    static VSIFilesystemHandler *GetHandler( const char * );
+    static void InstallHandler( const std::string& osPrefix, 
+                                VSIFilesystemHandler * );
+    /* RemoveHandler is never defined. */
+    /* static void RemoveHandler( const std::string& osPrefix ); */
+};
+
+
+/************************************************************************/
+/* ==================================================================== */
+/*                       VSIArchiveFilesystemHandler                   */
+/* ==================================================================== */
+/************************************************************************/
+
+class VSIArchiveEntryFileOffset
+{
+    public:
+        virtual ~VSIArchiveEntryFileOffset();
+};
+
+typedef struct
+{
+    char         *fileName;
+    vsi_l_offset  uncompressed_size;
+    VSIArchiveEntryFileOffset*      file_pos;
+    int           bIsDir;
+    GIntBig       nModifiedTime;
+} VSIArchiveEntry;
+
+typedef struct
+{
+    time_t       mTime;
+    vsi_l_offset nFileSize;
+    int nEntries;
+    VSIArchiveEntry* entries;
+} VSIArchiveContent;
+
+class VSIArchiveReader
+{
+    public:
+        virtual ~VSIArchiveReader();
+
+        virtual int GotoFirstFile() = 0;
+        virtual int GotoNextFile() = 0;
+        virtual VSIArchiveEntryFileOffset* GetFileOffset() = 0;
+        virtual GUIntBig GetFileSize() = 0;
+        virtual CPLString GetFileName() = 0;
+        virtual GIntBig GetModifiedTime() = 0;
+        virtual int GotoFileOffset(VSIArchiveEntryFileOffset* pOffset) = 0;
+};
+
+class VSIArchiveFilesystemHandler : public VSIFilesystemHandler 
+{
+protected:
+    CPLMutex* hMutex;
+    /* We use a cache that contains the list of files containes in a VSIArchive file as */
+    /* unarchive.c is quite inefficient in listing them. This speeds up access to VSIArchive files */
+    /* containing ~1000 files like a CADRG product */
+    std::map<CPLString,VSIArchiveContent*>   oFileList;
+
+    virtual const char* GetPrefix() = 0;
+    virtual std::vector<CPLString> GetExtensions() = 0;
+    virtual VSIArchiveReader* CreateReader(const char* pszArchiveFileName) = 0;
+
+public:
+    VSIArchiveFilesystemHandler();
+    virtual ~VSIArchiveFilesystemHandler();
+
+    virtual int      Stat( const char *pszFilename, VSIStatBufL *pStatBuf, int nFlags );
+    virtual int      Unlink( const char *pszFilename );
+    virtual int      Rename( const char *oldpath, const char *newpath );
+    virtual int      Mkdir( const char *pszDirname, long nMode );
+    virtual int      Rmdir( const char *pszDirname );
+    virtual char   **ReadDir( const char *pszDirname );
+
+    virtual const VSIArchiveContent* GetContentOfArchive(const char* archiveFilename, VSIArchiveReader* poReader = NULL);
+    virtual char* SplitFilename(const char *pszFilename, CPLString &osFileInArchive, int bCheckMainFileExists);
+    virtual VSIArchiveReader* OpenArchiveFile(const char* archiveFilename, const char* fileInArchiveName);
+    virtual int FindFileInArchive(const char* archiveFilename, const char* fileInArchiveName, const VSIArchiveEntry** archiveEntry);
+};
+
+VSIVirtualHandle CPL_DLL *VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle);
+VSIVirtualHandle* VSICreateBufferedReaderHandle(VSIVirtualHandle* poBaseHandle,
+                                                const GByte* pabyBeginningContent,
+                                                vsi_l_offset nSheatFileSize);
+VSIVirtualHandle* VSICreateCachedFile( VSIVirtualHandle* poBaseHandle, size_t nChunkSize = 32768, size_t nCacheSize = 0 );
+VSIVirtualHandle CPL_DLL *VSICreateGZipWritable( VSIVirtualHandle* poBaseHandle, int bRegularZLibIn, int bAutoCloseBaseHandle );
+
+#endif /* ndef CPL_VSI_VIRTUAL_H_INCLUDED */

+ 49 - 0
libpq_test/include/cpl_vsil_curl_priv.h

@@ -0,0 +1,49 @@
+/******************************************************************************
+ * $Id: cpl_vsil_curl_priv.h 27044 2014-03-16 23:41:27Z rouault $
+ *
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Private API for VSICurl
+ * Author:   Even Rouault, even.rouault at mines-paris.org
+ *
+ ******************************************************************************
+ * Copyright (c) 2012, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_VSIL_CURL_PRIV_H_INCLUDED
+#define CPL_VSIL_CURL_PRIV_H_INCLUDED
+
+#include "cpl_vsi_virtual.h"
+
+/* NOTE: this is private API for GDAL internal use. May change without notice. */
+/* Used by the MBTiles driver for now */
+
+/* Return TRUE to go on downloading, FALSE to stop */
+typedef int (*VSICurlReadCbkFunc) (VSILFILE* fp, void *pabyBuffer, size_t nBufferSize, void* pfnUserData);
+
+/* fp must be a VSICurl file handle, otherwise bad things will happen ! */
+/* bStopOnInterrruptUntilUninstall must be set to TRUE if all downloads */
+/* must be cancelled after a first one has been stopped by the callback function. */
+/* In that case, downloads will restart after uninstalling the callback. */
+int VSICurlInstallReadCbk(VSILFILE* fp, VSICurlReadCbkFunc pfnReadCbk, void* pfnUserData,
+                          int bStopOnInterrruptUntilUninstall);
+int VSICurlUninstallReadCbk(VSILFILE* fp);
+
+#endif // CPL_VSIL_CURL_PRIV_H_INCLUDED

+ 105 - 0
libpq_test/include/cpl_win32ce_api.h

@@ -0,0 +1,105 @@
+/******************************************************************************
+ * $Id: cpl_win32ce_api.h 10645 2007-01-18 02:22:39Z warmerdam $
+ *
+ * Name:     cpl_win32ce_api.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  ASCII wrappers around only Unicode Windows CE API.
+ * Author:   Mateusz £oskot, mloskot@taxussi.com.pl
+ *
+ ******************************************************************************
+ * Copyright (c) 2006, Mateusz £oskot
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+#ifndef _CPL_WINCEAPI_H_INCLUDED
+#define _CPL_WINCEAPI_H_INCLUDED    1
+
+#define WIN32CE
+#if defined(WIN32CE)
+
+#include <windows.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif  /* __cplusplus */
+
+/*
+ * Windows CE API non-Unicode Wrappers
+ */
+
+HMODULE CE_LoadLibraryA(
+    LPCSTR lpLibFileName
+    );
+
+FARPROC CE_GetProcAddressA(
+    HMODULE hModule,
+    LPCSTR lpProcName
+    );
+
+
+DWORD CE_GetModuleFileNameA(
+    HMODULE hModule,
+    LPSTR lpFilename,
+    DWORD nSize
+    );
+
+HANDLE CE_CreateFileA(
+    LPCSTR lpFileName,
+    DWORD dwDesiredAccess,
+    DWORD dwShareMode,
+    LPSECURITY_ATTRIBUTES lpSecurityAttributes,
+    DWORD dwCreationDisposition,
+    DWORD dwFlagsAndAttributes,
+    HANDLE hTemplateFile
+    );
+
+
+/* Replace Windows CE API calls with our own non-Unicode equivalents. */
+
+
+/* XXX - mloskot - those defines are quite confusing ! */
+/*
+#ifdef LoadLibrary
+#  undef  LoadLibrary
+#  define LoadLibrary CE_LoadLibraryA
+#endif
+
+#ifdef GetProcAddress
+#  undef  GetProcAddress
+#  define GetProcAddress CE_GetProcAddressA
+#endif
+
+#ifdef GetModuleFileName
+#  undef  GetModuleFileName
+#  define GetModuleFileName CE_GetModuleFileNameA
+#endif
+
+#ifdef CreateFile
+#  undef  CreateFile
+#  define CreateFile CE_CreateFileA
+#endif
+*/
+
+#ifdef __cplusplus
+}
+#endif  /* __cplusplus */
+
+#endif /* #ifdef WIN32CE */
+
+#endif /* #ifndef _CPL_WINCEAPI_H_INCLUDED */

+ 44 - 0
libpq_test/include/cpl_wince.h

@@ -0,0 +1,44 @@
+/******************************************************************************
+ * $Id: cpl_wince.h 10645 2007-01-18 02:22:39Z warmerdam $
+ *
+ * Name:     cpl_win_api.h
+ * Project:  CPL - Common Portability Library
+ * Purpose:  Windows CE specific declarations.
+ * Author:   Mateusz £oskot, mloskot@taxussi.com.pl
+ *
+ ******************************************************************************
+ * Copyright (c) 2006, Mateusz £oskot
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+#ifndef _CPL_WINCE_H_INCLUDED
+#define _CPL_WINCE_H_INCLUDED
+
+#include "cpl_config.h"
+
+#if defined(WIN32CE)
+
+#include "cpl_conv.h"
+#include "windows.h"
+
+
+
+#endif /* #if defined(WIN32CE) */
+
+#endif /* #ifndef _CPL_WINCE_H_INCLUDED */

+ 66 - 0
libpq_test/include/cplkeywordparser.h

@@ -0,0 +1,66 @@
+/******************************************************************************
+ * $Id: cplkeywordparser.h 20996 2010-10-28 18:38:15Z rouault $
+ *
+ * Project:  Common Portability Library
+ * Purpose:  Implementation of CPLKeywordParser - a class for parsing
+ *           the keyword format used for files like QuickBird .RPB files.
+ *           This is a slight variation on the NASAKeywordParser used for
+ *           the PDS/ISIS2/ISIS3 formats. 
+ * Author:   Frank Warmerdam <warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, Frank Warmerdam <warmerdam@pobox.com>
+ * 
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef CPL_KEYWORD_PARSER
+#define CPL_KEYWORD_PARSER
+
+#include "cpl_string.h"
+
+/************************************************************************/
+/* ==================================================================== */
+/*                          CPLKeywordParser                          */
+/* ==================================================================== */
+/************************************************************************/
+
+class CPLKeywordParser
+{
+    char     **papszKeywordList;
+
+    CPLString osHeaderText;
+    const char *pszHeaderNext;
+
+    void    SkipWhite();
+    int     ReadWord( CPLString &osWord );
+    int     ReadPair( CPLString &osName, CPLString &osValue );
+    int     ReadGroup( const char *pszPathPrefix );
+
+public:
+    CPLKeywordParser();
+    ~CPLKeywordParser();
+
+    int     Ingest( VSILFILE *fp );
+
+    const char *GetKeyword( const char *pszPath, const char *pszDefault=NULL );
+    char  **GetAllKeywords() { return papszKeywordList; }
+};
+
+#endif /* def CPL_KEYWORD_PARSER */

+ 19 - 0
libpq_test/include/dynloader.h

@@ -0,0 +1,19 @@
+/*
+ * src/backend/port/dynloader/win32.h
+ */
+#ifndef PORT_PROTOS_H
+#define PORT_PROTOS_H
+
+#include "utils/dynamic_loader.h"		/* pgrminclude ignore */
+
+#define pg_dlopen(f)	dlopen((f), 1)
+#define pg_dlsym		dlsym
+#define pg_dlclose		dlclose
+#define pg_dlerror		dlerror
+
+char	   *dlerror(void);
+int			dlclose(void *handle);
+void	   *dlsym(void *handle, const char *symbol);
+void	   *dlopen(const char *path, int mode);
+
+#endif   /* PORT_PROTOS_H */

+ 5 - 0
libpq_test/include/ecpg_config.h

@@ -0,0 +1,5 @@
+#if (_MSC_VER > 1200)
+#define HAVE_LONG_LONG_INT_64
+#define ENABLE_THREAD_SAFETY 1
+#define USE_INTEGER_DATETIMES 1
+#endif

+ 90 - 0
libpq_test/include/ecpg_informix.h

@@ -0,0 +1,90 @@
+/*
+ * This file contains stuff needed to be as compatible to Informix as possible.
+ * src/interfaces/ecpg/include/ecpg_informix.h
+ */
+#ifndef _ECPG_INFORMIX_H
+#define _ECPG_INFORMIX_H
+
+#include <ecpglib.h>
+#include <pgtypes_date.h>
+#include <pgtypes_interval.h>
+#include <pgtypes_numeric.h>
+#include <pgtypes_timestamp.h>
+
+#define SQLNOTFOUND 100
+
+#define ECPG_INFORMIX_NUM_OVERFLOW	-1200
+#define ECPG_INFORMIX_NUM_UNDERFLOW -1201
+#define ECPG_INFORMIX_DIVIDE_ZERO	-1202
+#define ECPG_INFORMIX_BAD_YEAR		-1204
+#define ECPG_INFORMIX_BAD_MONTH		-1205
+#define ECPG_INFORMIX_BAD_DAY		-1206
+#define ECPG_INFORMIX_ENOSHORTDATE	-1209
+#define ECPG_INFORMIX_DATE_CONVERT	-1210
+#define ECPG_INFORMIX_OUT_OF_MEMORY -1211
+#define ECPG_INFORMIX_ENOTDMY		-1212
+#define ECPG_INFORMIX_BAD_NUMERIC	-1213
+#define ECPG_INFORMIX_BAD_EXPONENT	-1216
+#define ECPG_INFORMIX_BAD_DATE		-1218
+#define ECPG_INFORMIX_EXTRA_CHARS	-1264
+
+#ifdef __cplusplus
+extern		"C"
+{
+#endif
+
+extern int	rdatestr(date, char *);
+extern void rtoday(date *);
+extern int	rjulmdy(date, short *);
+extern int	rdefmtdate(date *, char *, char *);
+extern int	rfmtdate(date, char *, char *);
+extern int	rmdyjul(short *, date *);
+extern int	rstrdate(char *, date *);
+extern int	rdayofweek(date);
+
+extern int	rfmtlong(long, char *, char *);
+extern int	rgetmsg(int, char *, int);
+extern int	risnull(int, char *);
+extern int	rsetnull(int, char *);
+extern int	rtypalign(int, int);
+extern int	rtypmsize(int, int);
+extern int	rtypwidth(int, int);
+extern void rupshift(char *);
+
+extern int	byleng(char *, int);
+extern void ldchar(char *, int, char *);
+
+extern void ECPG_informix_set_var(int, void *, int);
+extern void *ECPG_informix_get_var(int);
+extern void ECPG_informix_reset_sqlca(void);
+
+/* Informix defines these in decimal.h */
+int			decadd(decimal *, decimal *, decimal *);
+int			deccmp(decimal *, decimal *);
+void		deccopy(decimal *, decimal *);
+int			deccvasc(char *, int, decimal *);
+int			deccvdbl(double, decimal *);
+int			deccvint(int, decimal *);
+int			deccvlong(long, decimal *);
+int			decdiv(decimal *, decimal *, decimal *);
+int			decmul(decimal *, decimal *, decimal *);
+int			decsub(decimal *, decimal *, decimal *);
+int			dectoasc(decimal *, char *, int, int);
+int			dectodbl(decimal *, double *);
+int			dectoint(decimal *, int *);
+int			dectolong(decimal *, long *);
+
+/* Informix defines these in datetime.h */
+extern void dtcurrent(timestamp *);
+extern int	dtcvasc(char *, timestamp *);
+extern int	dtsub(timestamp *, timestamp *, interval *);
+extern int	dttoasc(timestamp *, char *);
+extern int	dttofmtasc(timestamp *, char *, int, char *);
+extern int	intoasc(interval *, char *);
+extern int	dtcvfmtasc(char *, char *, timestamp *);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /* ndef _ECPG_INFORMIX_H */

+ 79 - 0
libpq_test/include/ecpgerrno.h

@@ -0,0 +1,79 @@
+/* src/interfaces/ecpg/include/ecpgerrno.h */
+
+#ifndef _ECPG_ERRNO_H
+#define _ECPG_ERRNO_H
+
+#include <errno.h>
+
+/* This is a list of all error codes the embedded SQL program can return */
+#define ECPG_NO_ERROR		0
+#define ECPG_NOT_FOUND		100
+
+/* system error codes returned by ecpglib get the correct number,
+ * but are made negative
+ */
+#define ECPG_OUT_OF_MEMORY	-ENOMEM
+
+/* first we have a set of ecpg messages, they start at 200 */
+#define ECPG_UNSUPPORTED		-200
+#define ECPG_TOO_MANY_ARGUMENTS		-201
+#define ECPG_TOO_FEW_ARGUMENTS		-202
+#define ECPG_TOO_MANY_MATCHES		-203
+#define ECPG_INT_FORMAT			-204
+#define ECPG_UINT_FORMAT		-205
+#define ECPG_FLOAT_FORMAT		-206
+#define ECPG_NUMERIC_FORMAT		-207
+#define ECPG_INTERVAL_FORMAT		-208
+#define ECPG_DATE_FORMAT		-209
+#define ECPG_TIMESTAMP_FORMAT		-210
+#define ECPG_CONVERT_BOOL		-211
+#define ECPG_EMPTY			-212
+#define ECPG_MISSING_INDICATOR		-213
+#define ECPG_NO_ARRAY			-214
+#define ECPG_DATA_NOT_ARRAY		-215
+#define ECPG_ARRAY_INSERT		-216
+
+#define ECPG_NO_CONN			-220
+#define ECPG_NOT_CONN			-221
+
+#define ECPG_INVALID_STMT		-230
+
+/* dynamic SQL related */
+#define ECPG_UNKNOWN_DESCRIPTOR		-240
+#define ECPG_INVALID_DESCRIPTOR_INDEX	-241
+#define ECPG_UNKNOWN_DESCRIPTOR_ITEM	-242
+#define ECPG_VAR_NOT_NUMERIC		-243
+#define ECPG_VAR_NOT_CHAR		-244
+
+/* finally the backend error messages, they start at 400 */
+#define ECPG_PGSQL			-400
+#define ECPG_TRANS			-401
+#define ECPG_CONNECT			-402
+#define ECPG_DUPLICATE_KEY		-403
+#define ECPG_SUBSELECT_NOT_ONE		-404
+
+/* for compatibility we define some different error codes for the same error
+ * if adding a new one make sure to not double define it */
+#define ECPG_INFORMIX_DUPLICATE_KEY -239
+#define ECPG_INFORMIX_SUBSELECT_NOT_ONE -284
+
+/* backend WARNINGs, starting at 600 */
+#define ECPG_WARNING_UNRECOGNIZED	   -600
+ /* WARNING:  (transaction aborted): queries ignored until END */
+
+ /*
+  * WARNING:  current transaction is aborted, queries ignored until end of
+  * transaction block
+  */
+#define ECPG_WARNING_QUERY_IGNORED	   -601
+ /* WARNING:  PerformPortalClose: portal "*" not found */
+#define ECPG_WARNING_UNKNOWN_PORTAL    -602
+ /* WARNING:  BEGIN: already a transaction in progress */
+#define ECPG_WARNING_IN_TRANSACTION    -603
+ /* WARNING:  AbortTransaction and not in in-progress state */
+ /* WARNING:  COMMIT: no transaction in progress */
+#define ECPG_WARNING_NO_TRANSACTION    -604
+ /* WARNING:  BlankPortalAssignName: portal * already exists */
+#define ECPG_WARNING_PORTAL_EXISTS	   -605
+
+#endif   /* !_ECPG_ERRNO_H */

+ 100 - 0
libpq_test/include/ecpglib.h

@@ -0,0 +1,100 @@
+/*
+ * this is a small part of c.h since we don't want to leak all postgres
+ * definitions into ecpg programs
+ * src/interfaces/ecpg/include/ecpglib.h
+ */
+
+#ifndef _ECPGLIB_H
+#define _ECPGLIB_H
+
+#include "libpq-fe.h"
+#include "ecpgtype.h"
+#include "sqlca.h"
+#include <string.h>
+
+#ifdef ENABLE_NLS
+extern char *ecpg_gettext(const char *msgid) pg_attribute_format_arg(1);
+#else
+#define ecpg_gettext(x) (x)
+#endif
+
+#ifndef __cplusplus
+#ifndef bool
+#define bool char
+#endif   /* ndef bool */
+
+#ifndef true
+#define true	((bool) 1)
+#endif   /* ndef true */
+#ifndef false
+#define false	((bool) 0)
+#endif   /* ndef false */
+#endif   /* not C++ */
+
+#ifndef TRUE
+#define TRUE	1
+#endif   /* TRUE */
+
+#ifndef FALSE
+#define FALSE	0
+#endif   /* FALSE */
+
+#ifdef __cplusplus
+extern		"C"
+{
+#endif
+
+void		ECPGdebug(int, FILE *);
+bool		ECPGstatus(int, const char *);
+bool		ECPGsetcommit(int, const char *, const char *);
+bool		ECPGsetconn(int, const char *);
+bool		ECPGconnect(int, int, const char *, const char *, const char *, const char *, int);
+bool		ECPGdo(const int, const int, const int, const char *, const bool, const int, const char *,...);
+bool		ECPGtrans(int, const char *, const char *);
+bool		ECPGdisconnect(int, const char *);
+bool		ECPGprepare(int, const char *, const bool, const char *, const char *);
+bool		ECPGdeallocate(int, int, const char *, const char *);
+bool		ECPGdeallocate_all(int, int, const char *);
+char	   *ECPGprepared_statement(const char *, const char *, int);
+PGconn	   *ECPGget_PGconn(const char *);
+PGTransactionStatusType ECPGtransactionStatus(const char *);
+
+char	   *ECPGerrmsg(void);
+
+ /* print an error message */
+void		sqlprint(void);
+
+/* define this for simplicity as well as compatibility */
+
+#define		SQLCODE		sqlca.sqlcode
+#define		SQLSTATE		sqlca.sqlstate
+
+/* dynamic SQL */
+
+bool		ECPGdo_descriptor(int, const char *, const char *, const char *);
+bool		ECPGdeallocate_desc(int, const char *);
+bool		ECPGallocate_desc(int, const char *);
+bool		ECPGget_desc_header(int, const char *, int *);
+bool		ECPGget_desc(int, const char *, int,...);
+bool		ECPGset_desc_header(int, const char *, int);
+bool		ECPGset_desc(int, const char *, int,...);
+
+void		ECPGset_noind_null(enum ECPGttype, void *);
+bool		ECPGis_noind_null(enum ECPGttype, void *);
+bool		ECPGdescribe(int, int, bool, const char *, const char *,...);
+
+void		ECPGset_var(int, void *, int);
+void	   *ECPGget_var(int number);
+
+/* dynamic result allocation */
+void		ECPGfree_auto_mem(void);
+
+#ifdef ENABLE_THREAD_SAFETY
+void		ecpg_pthreads_init(void);
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /* _ECPGLIB_H */

+ 106 - 0
libpq_test/include/ecpgtype.h

@@ -0,0 +1,106 @@
+/*
+ * This file implements a data structure that is built and maintained by the
+ * preprocessor.
+ *
+ * All types that can be handled for host variable declarations has to
+ * be handled eventually.
+ *
+ * src/interfaces/ecpg/include/ecpgtype.h
+ */
+
+/*
+ * Here are all the types that we are to handle. Note that it is the type
+ * that is registered and that has nothing whatsoever to do with the storage
+ * class.
+ *
+ * Simple types
+ * integers: char, short, int, long (signed and unsigned)
+ * floats: float, double
+ *
+ * Complex types:
+ * VARCHAR, VARCHAR2 - Strings with length (maxlen is given in the declaration)
+ * Arrays of simple types and of VARCHAR, VARCHAR2 (size given in declaration)
+ * Records build of simple types, arrays and other structs.
+ *
+ * Complicating things:
+ * typedefs and struct names!
+ *
+ * Conclusion:
+ * This is a typically recursive definition. A structure of typed list elements
+ * would probably work fine:
+ */
+
+#ifndef _ECPGTYPE_H
+#define _ECPGTYPE_H
+
+#ifdef __cplusplus
+extern		"C"
+{
+#endif
+
+enum ECPGttype
+{
+	ECPGt_char = 1, ECPGt_unsigned_char, ECPGt_short, ECPGt_unsigned_short,
+	ECPGt_int, ECPGt_unsigned_int, ECPGt_long, ECPGt_unsigned_long,
+	ECPGt_long_long, ECPGt_unsigned_long_long,
+	ECPGt_bool,
+	ECPGt_float, ECPGt_double,
+	ECPGt_varchar, ECPGt_varchar2,
+	ECPGt_numeric,				/* this is a decimal that stores its digits in
+								 * a malloced array */
+	ECPGt_decimal,				/* this is a decimal that stores its digits in
+								 * a fixed array */
+	ECPGt_date,
+	ECPGt_timestamp,
+	ECPGt_interval,
+	ECPGt_array,
+	ECPGt_struct,
+	ECPGt_union,
+	ECPGt_descriptor,			/* sql descriptor, no C variable */
+	ECPGt_char_variable,
+	ECPGt_const,				/* a constant is needed sometimes */
+	ECPGt_EOIT,					/* End of insert types. */
+	ECPGt_EORT,					/* End of result types. */
+	ECPGt_NO_INDICATOR,			/* no indicator */
+	ECPGt_string,				/* trimmed (char *) type */
+	ECPGt_sqlda					/* C struct descriptor */
+};
+
+ /* descriptor items */
+enum ECPGdtype
+{
+	ECPGd_count = 1,
+	ECPGd_data,
+	ECPGd_di_code,
+	ECPGd_di_precision,
+	ECPGd_indicator,
+	ECPGd_key_member,
+	ECPGd_length,
+	ECPGd_name,
+	ECPGd_nullable,
+	ECPGd_octet,
+	ECPGd_precision,
+	ECPGd_ret_length,
+	ECPGd_ret_octet,
+	ECPGd_scale,
+	ECPGd_type,
+	ECPGd_EODT,					/* End of descriptor types. */
+	ECPGd_cardinality
+};
+
+#define IS_SIMPLE_TYPE(type) (((type) >= ECPGt_char && (type) <= ECPGt_interval) || ((type) == ECPGt_string))
+
+/* we also have to handle different statement types */
+enum ECPG_statement_type
+{
+	ECPGst_normal,
+	ECPGst_execute,
+	ECPGst_exec_immediate,
+	ECPGst_prepnormal
+};
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /* _ECPGTYPE_H */

+ 45 - 0
libpq_test/include/evdns.h

@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
+ * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _EVDNS_H_
+#define _EVDNS_H_
+
+/** @file evdns.h
+
+  A dns subsystem for Libevent.
+
+  The <evdns.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/evdns.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other <event2/...>
+  headers.
+ */
+
+#include <event.h>
+#include <event2/dns.h>
+#include <event2/dns_compat.h>
+#include <event2/dns_struct.h>
+
+#endif /* _EVDNS_H_ */

+ 85 - 0
libpq_test/include/event.h

@@ -0,0 +1,85 @@
+/*
+ * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
+ * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _EVENT_H_
+#define _EVENT_H_
+
+/** @file event.h
+
+  A library for writing event-driven network servers.
+
+  The <event.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/event.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other event2/
+  headers.
+ */
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+#include <event2/event-config.h>
+#ifdef _EVENT_HAVE_SYS_TYPES_H
+#include <sys/types.h>
+#endif
+#ifdef _EVENT_HAVE_SYS_TIME_H
+#include <sys/time.h>
+#endif
+#ifdef _EVENT_HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#include <stdarg.h>
+
+/* For int types. */
+#include <evutil.h>
+
+#ifdef WIN32
+#ifndef WIN32_LEAN_AND_MEAN
+#define WIN32_LEAN_AND_MEAN
+#endif
+#include <winsock2.h>
+#include <windows.h>
+#undef WIN32_LEAN_AND_MEAN
+typedef unsigned char u_char;
+typedef unsigned short u_short;
+#endif
+
+#include <event2/event_struct.h>
+#include <event2/event.h>
+#include <event2/event_compat.h>
+#include <event2/buffer.h>
+#include <event2/buffer_compat.h>
+#include <event2/bufferevent.h>
+#include <event2/bufferevent_struct.h>
+#include <event2/bufferevent_compat.h>
+#include <event2/tag.h>
+#include <event2/tag_compat.h>
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* _EVENT_H_ */

+ 45 - 0
libpq_test/include/evhttp.h

@@ -0,0 +1,45 @@
+/*
+ * Copyright 2000-2007 Niels Provos <provos@citi.umich.edu>
+ * Copyright 2007-2012 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _EVHTTP_H_
+#define _EVHTTP_H_
+
+/** @file evhttp.h
+
+  An http implementation subsystem for Libevent.
+
+  The <evhttp.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/http.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other <event2/...>
+  headers.
+ */
+
+#include <event.h>
+#include <event2/http.h>
+#include <event2/http_struct.h>
+#include <event2/http_compat.h>
+
+#endif /* _EVHTTP_H_ */

+ 45 - 0
libpq_test/include/evrpc.h

@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2000-2007 Niels Provos <provos@citi.umich.edu>
+ * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _EVRPC_H_
+#define _EVRPC_H_
+
+/** @file evrpc.h
+
+  An RPC system for Libevent.
+
+  The <evrpc.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/rpc.h> instead.  Depending on what functionality you
+  need, you may also want to include more of the other <event2/...>
+  headers.
+ */
+
+#include <event.h>
+#include <event2/rpc.h>
+#include <event2/rpc_struct.h>
+#include <event2/rpc_compat.h>
+
+#endif /* _EVRPC_H_ */

+ 39 - 0
libpq_test/include/evutil.h

@@ -0,0 +1,39 @@
+/*
+ * Copyright (c) 2007-2012 Niels Provos and Nick Mathewson
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ * 3. The name of the author may not be used to endorse or promote products
+ *    derived from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
+ * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
+ * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
+ * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+#ifndef _EVUTIL_H_
+#define _EVUTIL_H_
+
+/** @file evutil.h
+
+  Utility and compatibility functions for Libevent.
+
+  The <evutil.h> header is deprecated in Libevent 2.0 and later; please
+  use <event2/util.h> instead.
+*/
+
+#include <event2/util.h>
+
+#endif /* _EVUTIL_H_ */

+ 1090 - 0
libpq_test/include/gdal.h

@@ -0,0 +1,1090 @@
+/******************************************************************************
+ * $Id: gdal.h 29330 2015-06-14 12:11:11Z rouault $
+ *
+ * Project:  GDAL Core
+ * Purpose:  GDAL Core C/Public declarations.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 1998, 2002 Frank Warmerdam
+ * Copyright (c) 2007-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_H_INCLUDED
+#define GDAL_H_INCLUDED
+
+/**
+ * \file gdal.h
+ *
+ * Public (C callable) GDAL entry points.
+ */
+
+#ifndef DOXYGEN_SKIP
+#include "gdal_version.h"
+#include "cpl_port.h"
+#include "cpl_error.h"
+#include "cpl_progress.h"
+#include "cpl_virtualmem.h"
+#include "cpl_minixml.h"
+#include "ogr_api.h"
+#endif
+
+/* -------------------------------------------------------------------- */
+/*      Significant constants.                                          */
+/* -------------------------------------------------------------------- */
+
+CPL_C_START
+
+/*! Pixel data types */
+typedef enum {
+    /*! Unknown or unspecified type */ 		    GDT_Unknown = 0,
+    /*! Eight bit unsigned integer */           GDT_Byte = 1,
+    /*! Sixteen bit unsigned integer */         GDT_UInt16 = 2,
+    /*! Sixteen bit signed integer */           GDT_Int16 = 3,
+    /*! Thirty two bit unsigned integer */      GDT_UInt32 = 4,
+    /*! Thirty two bit signed integer */        GDT_Int32 = 5,
+    /*! Thirty two bit floating point */        GDT_Float32 = 6,
+    /*! Sixty four bit floating point */        GDT_Float64 = 7,
+    /*! Complex Int16 */                        GDT_CInt16 = 8,
+    /*! Complex Int32 */                        GDT_CInt32 = 9,
+    /*! Complex Float32 */                      GDT_CFloat32 = 10,
+    /*! Complex Float64 */                      GDT_CFloat64 = 11,
+    GDT_TypeCount = 12          /* maximum type # + 1 */
+} GDALDataType;
+
+int CPL_DLL CPL_STDCALL GDALGetDataTypeSize( GDALDataType );
+int CPL_DLL CPL_STDCALL GDALDataTypeIsComplex( GDALDataType );
+const char CPL_DLL * CPL_STDCALL GDALGetDataTypeName( GDALDataType );
+GDALDataType CPL_DLL CPL_STDCALL GDALGetDataTypeByName( const char * );
+GDALDataType CPL_DLL CPL_STDCALL GDALDataTypeUnion( GDALDataType, GDALDataType );
+
+/**
+* status of the asynchronous stream
+*/
+typedef enum 
+{	
+	GARIO_PENDING = 0,
+	GARIO_UPDATE = 1,
+	GARIO_ERROR = 2,
+	GARIO_COMPLETE = 3,
+	GARIO_TypeCount = 4
+} GDALAsyncStatusType;
+
+const char CPL_DLL * CPL_STDCALL GDALGetAsyncStatusTypeName( GDALAsyncStatusType );
+GDALAsyncStatusType CPL_DLL CPL_STDCALL GDALGetAsyncStatusTypeByName( const char * );
+
+/*! Flag indicating read/write, or read-only access to data. */
+typedef enum {
+    /*! Read only (no update) access */ GA_ReadOnly = 0,
+    /*! Read/write access. */           GA_Update = 1
+} GDALAccess;
+
+/*! Read/Write flag for RasterIO() method */
+typedef enum {
+    /*! Read data */   GF_Read = 0,
+    /*! Write data */  GF_Write = 1
+} GDALRWFlag;
+
+/* NOTE: values are selected to be consistent with GDALResampleAlg of alg/gdalwarper.h */ 
+/** RasterIO() resampling method.
+  * @since GDAL 2.0
+  */
+typedef enum
+{
+    /*! Nearest neighbour */                            GRIORA_NearestNeighbour = 0,
+    /*! Bilinear (2x2 kernel) */                        GRIORA_Bilinear = 1,
+    /*! Cubic Convolution Approximation (4x4 kernel) */ GRIORA_Cubic = 2,
+    /*! Cubic B-Spline Approximation (4x4 kernel) */    GRIORA_CubicSpline = 3,
+    /*! Lanczos windowed sinc interpolation (6x6 kernel) */ GRIORA_Lanczos = 4,
+    /*! Average */                                      GRIORA_Average = 5,
+    /*! Mode (selects the value which appears most often of all the sampled points) */
+                                                        GRIORA_Mode = 6,
+    /*! Gauss blurring */                               GRIORA_Gauss = 7
+    /* NOTE: values 8 to 12 are reserved for max,min,med,Q1,Q3 */
+} GDALRIOResampleAlg;
+
+/* NOTE to developers: only add members, and if so edit INIT_RASTERIO_EXTRA_ARG */
+/* and INIT_RASTERIO_EXTRA_ARG */
+/** Structure to pass extra arguments to RasterIO() method
+  * @since GDAL 2.0
+  */
+typedef struct
+{
+    /*! Version of structure (to allow future extensions of the structure) */ 
+    int                    nVersion;
+
+    /*! Resampling algorithm */ 
+    GDALRIOResampleAlg     eResampleAlg;
+
+    /*! Progress callback */ 
+    GDALProgressFunc       pfnProgress;
+    /*! Progress callback user data */ 
+    void                  *pProgressData;
+
+    /*! Indicate if dfXOff, dfYOff, dfXSize and dfYSize are set.
+        Mostly reserved from the VRT driver to communicate a more precise
+        source window. Must be such that dfXOff - nXOff < 1.0 and
+        dfYOff - nYOff < 1.0 and nXSize - dfXSize < 1.0 and nYSize - dfYSize < 1.0 */
+    int                    bFloatingPointWindowValidity;
+    /*! Pixel offset to the top left corner. Only valid if bFloatingPointWindowValidity = TRUE */
+    double                 dfXOff;
+    /*! Line offset to the top left corner. Only valid if bFloatingPointWindowValidity = TRUE */
+    double                 dfYOff;
+    /*! Width in pixels of the area of interest. Only valid if bFloatingPointWindowValidity = TRUE */
+    double                 dfXSize;
+    /*! Height in pixels of the area of interest. Only valid if bFloatingPointWindowValidity = TRUE */
+    double                 dfYSize;
+} GDALRasterIOExtraArg;
+
+#define RASTERIO_EXTRA_ARG_CURRENT_VERSION  1
+
+/** Macro to initialize an instance of GDALRasterIOExtraArg structure.
+  * @since GDAL 2.0
+  */
+#define INIT_RASTERIO_EXTRA_ARG(s)  \
+    do { (s).nVersion = RASTERIO_EXTRA_ARG_CURRENT_VERSION; \
+         (s).eResampleAlg = GRIORA_NearestNeighbour; \
+         (s).pfnProgress = NULL; \
+         (s).pProgressData = NULL; \
+         (s).bFloatingPointWindowValidity = FALSE; } while(0)
+
+/*! Types of color interpretation for raster bands. */
+typedef enum
+{
+    GCI_Undefined=0,
+    /*! Greyscale */                                      GCI_GrayIndex=1,
+    /*! Paletted (see associated color table) */          GCI_PaletteIndex=2,
+    /*! Red band of RGBA image */                         GCI_RedBand=3,
+    /*! Green band of RGBA image */                       GCI_GreenBand=4,
+    /*! Blue band of RGBA image */                        GCI_BlueBand=5,
+    /*! Alpha (0=transparent, 255=opaque) */              GCI_AlphaBand=6,
+    /*! Hue band of HLS image */                          GCI_HueBand=7,
+    /*! Saturation band of HLS image */                   GCI_SaturationBand=8,
+    /*! Lightness band of HLS image */                    GCI_LightnessBand=9,
+    /*! Cyan band of CMYK image */                        GCI_CyanBand=10,
+    /*! Magenta band of CMYK image */                     GCI_MagentaBand=11,
+    /*! Yellow band of CMYK image */                      GCI_YellowBand=12,
+    /*! Black band of CMLY image */                       GCI_BlackBand=13,
+    /*! Y Luminance */                                    GCI_YCbCr_YBand=14,
+    /*! Cb Chroma */                                      GCI_YCbCr_CbBand=15,
+    /*! Cr Chroma */                                      GCI_YCbCr_CrBand=16,
+    /*! Max current value */                              GCI_Max=16
+} GDALColorInterp;
+
+const char CPL_DLL *GDALGetColorInterpretationName( GDALColorInterp );
+GDALColorInterp CPL_DLL GDALGetColorInterpretationByName( const char *pszName );
+
+/*! Types of color interpretations for a GDALColorTable. */
+typedef enum 
+{
+  /*! Grayscale (in GDALColorEntry.c1) */                      GPI_Gray=0,
+  /*! Red, Green, Blue and Alpha in (in c1, c2, c3 and c4) */  GPI_RGB=1,
+  /*! Cyan, Magenta, Yellow and Black (in c1, c2, c3 and c4)*/ GPI_CMYK=2,
+  /*! Hue, Lightness and Saturation (in c1, c2, and c3) */     GPI_HLS=3
+} GDALPaletteInterp;
+
+const char CPL_DLL *GDALGetPaletteInterpretationName( GDALPaletteInterp );
+
+/* "well known" metadata items. */
+
+#define GDALMD_AREA_OR_POINT   "AREA_OR_POINT" 
+#  define GDALMD_AOP_AREA      "Area"
+#  define GDALMD_AOP_POINT     "Point"
+
+/* -------------------------------------------------------------------- */
+/*      GDAL Specific error codes.                                      */
+/*                                                                      */
+/*      error codes 100 to 299 reserved for GDAL.                       */
+/* -------------------------------------------------------------------- */
+#define CPLE_WrongFormat        200
+
+/* -------------------------------------------------------------------- */
+/*      Define handle types related to various internal classes.        */
+/* -------------------------------------------------------------------- */
+
+/** Opaque type used for the C bindings of the C++ GDALMajorObject class */
+typedef void *GDALMajorObjectH;
+
+/** Opaque type used for the C bindings of the C++ GDALDataset class */
+typedef void *GDALDatasetH;
+
+/** Opaque type used for the C bindings of the C++ GDALRasterBand class */
+typedef void *GDALRasterBandH;
+
+/** Opaque type used for the C bindings of the C++ GDALDriver class */
+typedef void *GDALDriverH;
+
+/** Opaque type used for the C bindings of the C++ GDALColorTable class */
+typedef void *GDALColorTableH;
+
+/** Opaque type used for the C bindings of the C++ GDALRasterAttributeTable class */
+typedef void *GDALRasterAttributeTableH;
+
+/** Opaque type used for the C bindings of the C++ GDALAsyncReader class */
+typedef void *GDALAsyncReaderH;
+
+/** Type to express pixel, line or band spacing. Signed 64 bit integer. */
+typedef GIntBig GSpacing;
+
+/* ==================================================================== */
+/*      Registration/driver related.                                    */
+/* ==================================================================== */
+
+/** Long name of the driver */
+#define GDAL_DMD_LONGNAME "DMD_LONGNAME"
+
+/** URL (relative to http://gdal.org/) to the help page of the driver */
+#define GDAL_DMD_HELPTOPIC "DMD_HELPTOPIC"
+
+/** MIME type handled by the driver. */
+#define GDAL_DMD_MIMETYPE "DMD_MIMETYPE"
+
+/** Extension handled by the driver. */
+#define GDAL_DMD_EXTENSION "DMD_EXTENSION"
+
+/** Connection prefix to provide as the file name of the the open function.
+ * Typically set for non-file based drivers. Generally used with open options.
+ * @since GDAL 2.0
+ */
+#define GDAL_DMD_CONNECTION_PREFIX "DMD_CONNECTION_PREFIX"
+
+/** List of (space separated) extensions handled by the driver.
+ * @since GDAL 2.0
+ */
+#define GDAL_DMD_EXTENSIONS "DMD_EXTENSIONS"
+
+/** XML snippet with creation options. */
+#define GDAL_DMD_CREATIONOPTIONLIST "DMD_CREATIONOPTIONLIST"
+
+/** XML snippet with open options.
+ * @since GDAL 2.0
+ */
+#define GDAL_DMD_OPENOPTIONLIST "DMD_OPENOPTIONLIST" 
+
+/** List of (space separated) raster data types support by the Create()/CreateCopy() API. */
+#define GDAL_DMD_CREATIONDATATYPES "DMD_CREATIONDATATYPES"
+
+/** List of (space separated) vector field types support by the CreateField() API.
+ * @since GDAL 2.0
+ * */
+#define GDAL_DMD_CREATIONFIELDDATATYPES "DMD_CREATIONFIELDDATATYPES"
+
+/** Capability set by a driver that exposes Subdatasets. */
+#define GDAL_DMD_SUBDATASETS "DMD_SUBDATASETS" 
+
+/** Capability set by a driver that implements the Open() API. */
+#define GDAL_DCAP_OPEN       "DCAP_OPEN"
+
+/** Capability set by a driver that implements the Create() API. */
+#define GDAL_DCAP_CREATE     "DCAP_CREATE"
+
+/** Capability set by a driver that implements the CreateCopy() API. */
+#define GDAL_DCAP_CREATECOPY "DCAP_CREATECOPY"
+
+/** Capability set by a driver that can read/create datasets through the VSI*L API. */
+#define GDAL_DCAP_VIRTUALIO  "DCAP_VIRTUALIO"
+
+/** Capability set by a driver having raster capability.
+ * @since GDAL 2.0
+ */
+#define GDAL_DCAP_RASTER     "DCAP_RASTER"
+
+/** Capability set by a driver having vector capability.
+ * @since GDAL 2.0
+ */
+#define GDAL_DCAP_VECTOR     "DCAP_VECTOR"
+
+/** Capability set by a driver that can create fields with NOT NULL constraint. 
+ * @since GDAL 2.0
+ */
+#define GDAL_DCAP_NOTNULL_FIELDS "DCAP_NOTNULL_FIELDS" 
+
+/** Capability set by a driver that can create fields with DEFAULT values. 
+ * @since GDAL 2.0
+ */
+#define GDAL_DCAP_DEFAULT_FIELDS "DCAP_DEFAULT_FIELDS" 
+
+/** Capability set by a driver that can create geometry fields with NOT NULL constraint.
+ * @since GDAL 2.0
+ */
+#define GDAL_DCAP_NOTNULL_GEOMFIELDS "DCAP_NOTNULL_GEOMFIELDS" 
+
+void CPL_DLL CPL_STDCALL GDALAllRegister( void );
+
+GDALDatasetH CPL_DLL CPL_STDCALL GDALCreate( GDALDriverH hDriver,
+                                 const char *, int, int, int, GDALDataType,
+                                 char ** ) CPL_WARN_UNUSED_RESULT;
+GDALDatasetH CPL_DLL CPL_STDCALL
+GDALCreateCopy( GDALDriverH, const char *, GDALDatasetH,
+                int, char **, GDALProgressFunc, void * ) CPL_WARN_UNUSED_RESULT;
+
+GDALDriverH CPL_DLL CPL_STDCALL GDALIdentifyDriver( const char * pszFilename,
+                                            char ** papszFileList );
+GDALDatasetH CPL_DLL CPL_STDCALL
+GDALOpen( const char *pszFilename, GDALAccess eAccess ) CPL_WARN_UNUSED_RESULT;
+GDALDatasetH CPL_DLL CPL_STDCALL GDALOpenShared( const char *, GDALAccess ) CPL_WARN_UNUSED_RESULT;
+
+
+/* Note: we define GDAL_OF_READONLY and GDAL_OF_UPDATE to be on purpose */
+/* equals to GA_ReadOnly and GA_Update */
+
+/** Open in read-only mode.
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_READONLY        0x00
+
+/** Open in update mode.
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_UPDATE          0x01
+
+/** Allow raster and vector drivers to be used.
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_ALL             0x00
+
+/** Allow raster drivers to be used.
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_RASTER          0x02
+
+/** Allow vector drivers to be used.
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_VECTOR          0x04
+/* Some space for GDAL 3.0 new types ;-) */
+/*#define     GDAL_OF_OTHER_KIND1   0x08 */
+/*#define     GDAL_OF_OTHER_KIND2   0x10 */
+#ifndef DOXYGEN_SKIP
+#define     GDAL_OF_KIND_MASK       0x1E
+#endif
+
+/** Open in shared mode.
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_SHARED          0x20
+
+/** Emit error message in case of failed open.
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_VERBOSE_ERROR   0x40
+
+/** Open as internal dataset. Such dataset isn't registered in the global list
+ * of opened dataset. Cannot be used with GDAL_OF_SHARED.
+ *
+ * Used by GDALOpenEx().
+ * @since GDAL 2.0
+ */
+#define     GDAL_OF_INTERNAL        0x80
+
+GDALDatasetH CPL_DLL CPL_STDCALL GDALOpenEx( const char* pszFilename,
+                                             unsigned int nOpenFlags,
+                                             const char* const* papszAllowedDrivers,
+                                             const char* const* papszOpenOptions,
+                                             const char* const* papszSiblingFiles ) CPL_WARN_UNUSED_RESULT;
+
+int          CPL_DLL CPL_STDCALL GDALDumpOpenDatasets( FILE * );
+
+GDALDriverH CPL_DLL CPL_STDCALL GDALGetDriverByName( const char * );
+int CPL_DLL         CPL_STDCALL GDALGetDriverCount( void );
+GDALDriverH CPL_DLL CPL_STDCALL GDALGetDriver( int );
+void        CPL_DLL CPL_STDCALL GDALDestroyDriver( GDALDriverH );
+int         CPL_DLL CPL_STDCALL GDALRegisterDriver( GDALDriverH );
+void        CPL_DLL CPL_STDCALL GDALDeregisterDriver( GDALDriverH );
+void        CPL_DLL CPL_STDCALL GDALDestroyDriverManager( void );
+void        CPL_DLL             GDALDestroy( void );
+CPLErr      CPL_DLL CPL_STDCALL GDALDeleteDataset( GDALDriverH, const char * );
+CPLErr      CPL_DLL CPL_STDCALL GDALRenameDataset( GDALDriverH, 
+                                                   const char * pszNewName,
+                                                   const char * pszOldName );
+CPLErr      CPL_DLL CPL_STDCALL GDALCopyDatasetFiles( GDALDriverH, 
+                                                      const char * pszNewName,
+                                                      const char * pszOldName);
+int         CPL_DLL CPL_STDCALL GDALValidateCreationOptions( GDALDriverH,
+                                                             char** papszCreationOptions);
+
+/* The following are deprecated */
+const char CPL_DLL * CPL_STDCALL GDALGetDriverShortName( GDALDriverH );
+const char CPL_DLL * CPL_STDCALL GDALGetDriverLongName( GDALDriverH );
+const char CPL_DLL * CPL_STDCALL GDALGetDriverHelpTopic( GDALDriverH );
+const char CPL_DLL * CPL_STDCALL GDALGetDriverCreationOptionList( GDALDriverH );
+
+/* ==================================================================== */
+/*      GDAL_GCP                                                        */
+/* ==================================================================== */
+
+/** Ground Control Point */
+typedef struct
+{
+    /** Unique identifier, often numeric */
+    char        *pszId; 
+
+    /** Informational message or "" */
+    char        *pszInfo;
+
+    /** Pixel (x) location of GCP on raster */
+    double      dfGCPPixel;
+    /** Line (y) location of GCP on raster */
+    double      dfGCPLine;
+
+    /** X position of GCP in georeferenced space */
+    double      dfGCPX;
+
+    /** Y position of GCP in georeferenced space */
+    double      dfGCPY;
+
+    /** Elevation of GCP, or zero if not known */
+    double      dfGCPZ;
+} GDAL_GCP;
+
+void CPL_DLL CPL_STDCALL GDALInitGCPs( int, GDAL_GCP * );
+void CPL_DLL CPL_STDCALL GDALDeinitGCPs( int, GDAL_GCP * );
+GDAL_GCP CPL_DLL * CPL_STDCALL GDALDuplicateGCPs( int, const GDAL_GCP * );
+
+int CPL_DLL CPL_STDCALL
+GDALGCPsToGeoTransform( int nGCPCount, const GDAL_GCP *pasGCPs, 
+                        double *padfGeoTransform, int bApproxOK )  CPL_WARN_UNUSED_RESULT; 
+int CPL_DLL CPL_STDCALL
+GDALInvGeoTransform( double *padfGeoTransformIn, 
+                     double *padfInvGeoTransformOut ) CPL_WARN_UNUSED_RESULT;
+void CPL_DLL CPL_STDCALL GDALApplyGeoTransform( double *, double, double, 
+                                                double *, double * );
+void CPL_DLL GDALComposeGeoTransforms(const double *padfGeoTransform1,
+                                      const double *padfGeoTransform2,
+                                      double *padfGeoTransformOut);
+
+/* ==================================================================== */
+/*      major objects (dataset, and, driver, drivermanager).            */
+/* ==================================================================== */
+
+char CPL_DLL  ** CPL_STDCALL GDALGetMetadataDomainList( GDALMajorObjectH hObject );
+char CPL_DLL  ** CPL_STDCALL GDALGetMetadata( GDALMajorObjectH, const char * );
+CPLErr CPL_DLL CPL_STDCALL GDALSetMetadata( GDALMajorObjectH, char **,
+                                            const char * );
+const char CPL_DLL * CPL_STDCALL 
+GDALGetMetadataItem( GDALMajorObjectH, const char *, const char * );
+CPLErr CPL_DLL CPL_STDCALL
+GDALSetMetadataItem( GDALMajorObjectH, const char *, const char *,
+                     const char * );
+const char CPL_DLL * CPL_STDCALL GDALGetDescription( GDALMajorObjectH );
+void CPL_DLL CPL_STDCALL GDALSetDescription( GDALMajorObjectH, const char * );
+
+/* ==================================================================== */
+/*      GDALDataset class ... normally this represents one file.        */
+/* ==================================================================== */
+
+#define GDAL_DS_LAYER_CREATIONOPTIONLIST "DS_LAYER_CREATIONOPTIONLIST" 
+
+GDALDriverH CPL_DLL CPL_STDCALL GDALGetDatasetDriver( GDALDatasetH );
+char CPL_DLL ** CPL_STDCALL GDALGetFileList( GDALDatasetH );
+void CPL_DLL CPL_STDCALL   GDALClose( GDALDatasetH );
+int CPL_DLL CPL_STDCALL     GDALGetRasterXSize( GDALDatasetH );
+int CPL_DLL CPL_STDCALL     GDALGetRasterYSize( GDALDatasetH );
+int CPL_DLL CPL_STDCALL     GDALGetRasterCount( GDALDatasetH );
+GDALRasterBandH CPL_DLL CPL_STDCALL GDALGetRasterBand( GDALDatasetH, int );
+
+CPLErr CPL_DLL  CPL_STDCALL GDALAddBand( GDALDatasetH hDS, GDALDataType eType, 
+                             char **papszOptions );
+
+GDALAsyncReaderH CPL_DLL CPL_STDCALL 
+GDALBeginAsyncReader(GDALDatasetH hDS, int nXOff, int nYOff,
+                     int nXSize, int nYSize,
+                     void *pBuf, int nBufXSize, int nBufYSize,
+                     GDALDataType eBufType, int nBandCount, int* panBandMap,
+                     int nPixelSpace, int nLineSpace, int nBandSpace,
+                     char **papszOptions);
+
+void  CPL_DLL CPL_STDCALL 
+GDALEndAsyncReader(GDALDatasetH hDS, GDALAsyncReaderH hAsynchReaderH);
+
+CPLErr CPL_DLL CPL_STDCALL GDALDatasetRasterIO( 
+    GDALDatasetH hDS, GDALRWFlag eRWFlag,
+    int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize,
+    void * pBuffer, int nBXSize, int nBYSize, GDALDataType eBDataType,
+    int nBandCount, int *panBandCount, 
+    int nPixelSpace, int nLineSpace, int nBandSpace);
+
+CPLErr CPL_DLL CPL_STDCALL GDALDatasetRasterIOEx( 
+    GDALDatasetH hDS, GDALRWFlag eRWFlag,
+    int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize,
+    void * pBuffer, int nBXSize, int nBYSize, GDALDataType eBDataType,
+    int nBandCount, int *panBandCount, 
+    GSpacing nPixelSpace, GSpacing nLineSpace, GSpacing nBandSpace,
+    GDALRasterIOExtraArg* psExtraArg);
+
+CPLErr CPL_DLL CPL_STDCALL GDALDatasetAdviseRead( GDALDatasetH hDS, 
+    int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize,
+    int nBXSize, int nBYSize, GDALDataType eBDataType,
+    int nBandCount, int *panBandCount, char **papszOptions );
+
+const char CPL_DLL * CPL_STDCALL GDALGetProjectionRef( GDALDatasetH );
+CPLErr CPL_DLL CPL_STDCALL GDALSetProjection( GDALDatasetH, const char * );
+CPLErr CPL_DLL CPL_STDCALL GDALGetGeoTransform( GDALDatasetH, double * );
+CPLErr CPL_DLL CPL_STDCALL GDALSetGeoTransform( GDALDatasetH, double * );
+
+int CPL_DLL CPL_STDCALL  GDALGetGCPCount( GDALDatasetH );
+const char CPL_DLL * CPL_STDCALL GDALGetGCPProjection( GDALDatasetH );
+const GDAL_GCP CPL_DLL * CPL_STDCALL GDALGetGCPs( GDALDatasetH );
+CPLErr CPL_DLL CPL_STDCALL GDALSetGCPs( GDALDatasetH, int, const GDAL_GCP *,
+                                        const char * );
+
+void CPL_DLL * CPL_STDCALL GDALGetInternalHandle( GDALDatasetH, const char * );
+int CPL_DLL CPL_STDCALL GDALReferenceDataset( GDALDatasetH );
+int CPL_DLL CPL_STDCALL GDALDereferenceDataset( GDALDatasetH );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALBuildOverviews( GDALDatasetH, const char *, int, int *,
+                    int, int *, GDALProgressFunc, void * );
+void CPL_DLL CPL_STDCALL GDALGetOpenDatasets( GDALDatasetH **hDS, int *pnCount );
+int CPL_DLL CPL_STDCALL GDALGetAccess( GDALDatasetH hDS );
+void CPL_DLL CPL_STDCALL GDALFlushCache( GDALDatasetH hDS );
+
+CPLErr CPL_DLL CPL_STDCALL 
+              GDALCreateDatasetMaskBand( GDALDatasetH hDS, int nFlags );
+
+CPLErr CPL_DLL CPL_STDCALL GDALDatasetCopyWholeRaster(
+    GDALDatasetH hSrcDS, GDALDatasetH hDstDS, char **papszOptions, 
+    GDALProgressFunc pfnProgress, void *pProgressData );
+
+CPLErr CPL_DLL CPL_STDCALL GDALRasterBandCopyWholeRaster(
+    GDALRasterBandH hSrcBand, GDALRasterBandH hDstBand, char **papszOptions,
+    GDALProgressFunc pfnProgress, void *pProgressData );
+
+CPLErr CPL_DLL 
+GDALRegenerateOverviews( GDALRasterBandH hSrcBand, 
+                         int nOverviewCount, GDALRasterBandH *pahOverviewBands,
+                         const char *pszResampling, 
+                         GDALProgressFunc pfnProgress, void *pProgressData );
+
+int    CPL_DLL GDALDatasetGetLayerCount( GDALDatasetH );
+OGRLayerH CPL_DLL GDALDatasetGetLayer( GDALDatasetH, int );
+OGRLayerH CPL_DLL GDALDatasetGetLayerByName( GDALDatasetH, const char * );
+OGRErr    CPL_DLL GDALDatasetDeleteLayer( GDALDatasetH, int );
+OGRLayerH CPL_DLL GDALDatasetCreateLayer( GDALDatasetH, const char *, 
+                                      OGRSpatialReferenceH, OGRwkbGeometryType,
+                                      char ** );
+OGRLayerH CPL_DLL GDALDatasetCopyLayer( GDALDatasetH, OGRLayerH, const char *,
+                                        char ** );
+int    CPL_DLL GDALDatasetTestCapability( GDALDatasetH, const char * );
+OGRLayerH CPL_DLL GDALDatasetExecuteSQL( GDALDatasetH, const char *,
+                                     OGRGeometryH, const char * );
+void   CPL_DLL GDALDatasetReleaseResultSet( GDALDatasetH, OGRLayerH );
+OGRStyleTableH CPL_DLL GDALDatasetGetStyleTable( GDALDatasetH );
+void   CPL_DLL GDALDatasetSetStyleTableDirectly( GDALDatasetH, OGRStyleTableH );
+void   CPL_DLL GDALDatasetSetStyleTable( GDALDatasetH, OGRStyleTableH );
+OGRErr CPL_DLL GDALDatasetStartTransaction(GDALDatasetH hDS, int bForce);
+OGRErr CPL_DLL GDALDatasetCommitTransaction(GDALDatasetH hDS);
+OGRErr CPL_DLL GDALDatasetRollbackTransaction(GDALDatasetH hDS);
+
+
+/* ==================================================================== */
+/*      GDALRasterBand ... one band/channel in a dataset.               */
+/* ==================================================================== */
+
+/**
+ * SRCVAL - Macro which may be used by pixel functions to obtain
+ *          a pixel from a source buffer.
+ */
+#define SRCVAL(papoSource, eSrcType, ii) \
+      (eSrcType == GDT_Byte ? \
+          ((GByte *)papoSource)[ii] : \
+      (eSrcType == GDT_Float32 ? \
+          ((float *)papoSource)[ii] : \
+      (eSrcType == GDT_Float64 ? \
+          ((double *)papoSource)[ii] : \
+      (eSrcType == GDT_Int32 ? \
+          ((GInt32 *)papoSource)[ii] : \
+      (eSrcType == GDT_UInt16 ? \
+          ((GUInt16 *)papoSource)[ii] : \
+      (eSrcType == GDT_Int16 ? \
+          ((GInt16 *)papoSource)[ii] : \
+      (eSrcType == GDT_UInt32 ? \
+          ((GUInt32 *)papoSource)[ii] : \
+      (eSrcType == GDT_CInt16 ? \
+          ((GInt16 *)papoSource)[ii * 2] : \
+      (eSrcType == GDT_CInt32 ? \
+          ((GInt32 *)papoSource)[ii * 2] : \
+      (eSrcType == GDT_CFloat32 ? \
+          ((float *)papoSource)[ii * 2] : \
+      (eSrcType == GDT_CFloat64 ? \
+          ((double *)papoSource)[ii * 2] : 0)))))))))))
+
+typedef CPLErr
+(*GDALDerivedPixelFunc)(void **papoSources, int nSources, void *pData,
+			int nBufXSize, int nBufYSize,
+			GDALDataType eSrcType, GDALDataType eBufType,
+                        int nPixelSpace, int nLineSpace);
+
+GDALDataType CPL_DLL CPL_STDCALL GDALGetRasterDataType( GDALRasterBandH );
+void CPL_DLL CPL_STDCALL 
+GDALGetBlockSize( GDALRasterBandH, int * pnXSize, int * pnYSize );
+
+CPLErr CPL_DLL CPL_STDCALL GDALRasterAdviseRead( GDALRasterBandH hRB, 
+    int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize,
+    int nBXSize, int nBYSize, GDALDataType eBDataType, char **papszOptions );
+
+CPLErr CPL_DLL CPL_STDCALL 
+GDALRasterIO( GDALRasterBandH hRBand, GDALRWFlag eRWFlag,
+              int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize,
+              void * pBuffer, int nBXSize, int nBYSize,GDALDataType eBDataType,
+              int nPixelSpace, int nLineSpace );
+CPLErr CPL_DLL CPL_STDCALL 
+GDALRasterIOEx( GDALRasterBandH hRBand, GDALRWFlag eRWFlag,
+              int nDSXOff, int nDSYOff, int nDSXSize, int nDSYSize,
+              void * pBuffer, int nBXSize, int nBYSize,GDALDataType eBDataType,
+              GSpacing nPixelSpace, GSpacing nLineSpace,
+              GDALRasterIOExtraArg* psExtraArg );
+CPLErr CPL_DLL CPL_STDCALL GDALReadBlock( GDALRasterBandH, int, int, void * );
+CPLErr CPL_DLL CPL_STDCALL GDALWriteBlock( GDALRasterBandH, int, int, void * );
+int CPL_DLL CPL_STDCALL GDALGetRasterBandXSize( GDALRasterBandH );
+int CPL_DLL CPL_STDCALL GDALGetRasterBandYSize( GDALRasterBandH );
+GDALAccess CPL_DLL CPL_STDCALL GDALGetRasterAccess( GDALRasterBandH );
+int CPL_DLL CPL_STDCALL GDALGetBandNumber( GDALRasterBandH );
+GDALDatasetH CPL_DLL CPL_STDCALL GDALGetBandDataset( GDALRasterBandH );
+
+GDALColorInterp CPL_DLL CPL_STDCALL
+GDALGetRasterColorInterpretation( GDALRasterBandH );
+CPLErr CPL_DLL CPL_STDCALL 
+GDALSetRasterColorInterpretation( GDALRasterBandH, GDALColorInterp );
+GDALColorTableH CPL_DLL CPL_STDCALL GDALGetRasterColorTable( GDALRasterBandH );
+CPLErr CPL_DLL CPL_STDCALL GDALSetRasterColorTable( GDALRasterBandH, GDALColorTableH );
+int CPL_DLL CPL_STDCALL GDALHasArbitraryOverviews( GDALRasterBandH );
+int CPL_DLL CPL_STDCALL GDALGetOverviewCount( GDALRasterBandH );
+GDALRasterBandH CPL_DLL CPL_STDCALL GDALGetOverview( GDALRasterBandH, int );
+double CPL_DLL CPL_STDCALL GDALGetRasterNoDataValue( GDALRasterBandH, int * );
+CPLErr CPL_DLL CPL_STDCALL GDALSetRasterNoDataValue( GDALRasterBandH, double );
+char CPL_DLL ** CPL_STDCALL GDALGetRasterCategoryNames( GDALRasterBandH );
+CPLErr CPL_DLL CPL_STDCALL GDALSetRasterCategoryNames( GDALRasterBandH, char ** );
+double CPL_DLL CPL_STDCALL GDALGetRasterMinimum( GDALRasterBandH, int *pbSuccess );
+double CPL_DLL CPL_STDCALL GDALGetRasterMaximum( GDALRasterBandH, int *pbSuccess );
+CPLErr CPL_DLL CPL_STDCALL GDALGetRasterStatistics( 
+    GDALRasterBandH, int bApproxOK, int bForce, 
+    double *pdfMin, double *pdfMax, double *pdfMean, double *pdfStdDev );
+CPLErr CPL_DLL CPL_STDCALL GDALComputeRasterStatistics( 
+    GDALRasterBandH, int bApproxOK, 
+    double *pdfMin, double *pdfMax, double *pdfMean, double *pdfStdDev,
+    GDALProgressFunc pfnProgress, void *pProgressData );
+CPLErr CPL_DLL CPL_STDCALL GDALSetRasterStatistics( 
+    GDALRasterBandH hBand, 
+    double dfMin, double dfMax, double dfMean, double dfStdDev );
+
+const char CPL_DLL * CPL_STDCALL GDALGetRasterUnitType( GDALRasterBandH );
+CPLErr CPL_DLL CPL_STDCALL GDALSetRasterUnitType( GDALRasterBandH hBand, const char *pszNewValue );
+double CPL_DLL CPL_STDCALL GDALGetRasterOffset( GDALRasterBandH, int *pbSuccess );
+CPLErr CPL_DLL CPL_STDCALL GDALSetRasterOffset( GDALRasterBandH hBand, double dfNewOffset);
+double CPL_DLL CPL_STDCALL GDALGetRasterScale( GDALRasterBandH, int *pbSuccess );
+CPLErr CPL_DLL CPL_STDCALL GDALSetRasterScale( GDALRasterBandH hBand, double dfNewOffset );
+void CPL_DLL CPL_STDCALL 
+GDALComputeRasterMinMax( GDALRasterBandH hBand, int bApproxOK,
+                         double adfMinMax[2] );
+CPLErr CPL_DLL CPL_STDCALL GDALFlushRasterCache( GDALRasterBandH hBand );
+CPLErr CPL_DLL CPL_STDCALL GDALGetRasterHistogram( GDALRasterBandH hBand,
+                                       double dfMin, double dfMax,
+                                       int nBuckets, int *panHistogram,
+                                       int bIncludeOutOfRange, int bApproxOK,
+                                       GDALProgressFunc pfnProgress,
+                                       void * pProgressData ) CPL_WARN_DEPRECATED("Use GDALGetRasterHistogramEx() instead");
+CPLErr CPL_DLL CPL_STDCALL GDALGetRasterHistogramEx( GDALRasterBandH hBand,
+                                       double dfMin, double dfMax,
+                                       int nBuckets, GUIntBig *panHistogram,
+                                       int bIncludeOutOfRange, int bApproxOK,
+                                       GDALProgressFunc pfnProgress,
+                                       void * pProgressData );
+CPLErr CPL_DLL CPL_STDCALL GDALGetDefaultHistogram( GDALRasterBandH hBand,
+                                       double *pdfMin, double *pdfMax,
+                                       int *pnBuckets, int **ppanHistogram,
+                                       int bForce,
+                                       GDALProgressFunc pfnProgress,
+                                       void * pProgressData ) CPL_WARN_DEPRECATED("Use GDALGetDefaultHistogramEx() instead");
+CPLErr CPL_DLL CPL_STDCALL GDALGetDefaultHistogramEx( GDALRasterBandH hBand,
+                                       double *pdfMin, double *pdfMax,
+                                       int *pnBuckets, GUIntBig **ppanHistogram,
+                                       int bForce,
+                                       GDALProgressFunc pfnProgress,
+                                       void * pProgressData );
+CPLErr CPL_DLL CPL_STDCALL GDALSetDefaultHistogram( GDALRasterBandH hBand,
+                                       double dfMin, double dfMax,
+                                       int nBuckets, int *panHistogram ) CPL_WARN_DEPRECATED("Use GDALSetDefaultHistogramEx() instead");
+CPLErr CPL_DLL CPL_STDCALL GDALSetDefaultHistogramEx( GDALRasterBandH hBand,
+                                       double dfMin, double dfMax,
+                                       int nBuckets, GUIntBig *panHistogram );
+int CPL_DLL CPL_STDCALL
+GDALGetRandomRasterSample( GDALRasterBandH, int, float * );
+GDALRasterBandH CPL_DLL CPL_STDCALL
+GDALGetRasterSampleOverview( GDALRasterBandH, int );
+GDALRasterBandH CPL_DLL CPL_STDCALL
+GDALGetRasterSampleOverviewEx( GDALRasterBandH, GUIntBig );
+CPLErr CPL_DLL CPL_STDCALL GDALFillRaster( GDALRasterBandH hBand,
+                          double dfRealValue, double dfImaginaryValue );
+CPLErr CPL_DLL CPL_STDCALL
+GDALComputeBandStats( GDALRasterBandH hBand, int nSampleStep, 
+                             double *pdfMean, double *pdfStdDev, 
+                             GDALProgressFunc pfnProgress,
+                             void *pProgressData );
+CPLErr CPL_DLL  GDALOverviewMagnitudeCorrection( GDALRasterBandH hBaseBand, 
+                                        int nOverviewCount, 
+                                        GDALRasterBandH *pahOverviews, 
+                                        GDALProgressFunc pfnProgress, 
+                                        void *pProgressData );
+
+GDALRasterAttributeTableH CPL_DLL CPL_STDCALL GDALGetDefaultRAT( 
+    GDALRasterBandH hBand );
+CPLErr CPL_DLL CPL_STDCALL GDALSetDefaultRAT( GDALRasterBandH, 
+                                              GDALRasterAttributeTableH );
+CPLErr CPL_DLL CPL_STDCALL GDALAddDerivedBandPixelFunc( const char *pszName,
+                                    GDALDerivedPixelFunc pfnPixelFunc );
+
+GDALRasterBandH CPL_DLL CPL_STDCALL GDALGetMaskBand( GDALRasterBandH hBand );
+int CPL_DLL CPL_STDCALL GDALGetMaskFlags( GDALRasterBandH hBand );
+CPLErr CPL_DLL CPL_STDCALL 
+                       GDALCreateMaskBand( GDALRasterBandH hBand, int nFlags );
+
+#define GMF_ALL_VALID     0x01
+#define GMF_PER_DATASET   0x02
+#define GMF_ALPHA         0x04
+#define GMF_NODATA        0x08
+
+/* ==================================================================== */
+/*     GDALAsyncReader                                                  */
+/* ==================================================================== */
+
+GDALAsyncStatusType CPL_DLL CPL_STDCALL 
+GDALARGetNextUpdatedRegion(GDALAsyncReaderH hARIO, double dfTimeout,
+                         int* pnXBufOff, int* pnYBufOff, 
+                         int* pnXBufSize, int* pnYBufSize );
+int CPL_DLL CPL_STDCALL GDALARLockBuffer(GDALAsyncReaderH hARIO,
+                                        double dfTimeout);
+void CPL_DLL CPL_STDCALL GDALARUnlockBuffer(GDALAsyncReaderH hARIO); 
+
+/* -------------------------------------------------------------------- */
+/*      Helper functions.                                               */
+/* -------------------------------------------------------------------- */
+int CPL_DLL CPL_STDCALL GDALGeneralCmdLineProcessor( int nArgc, char ***ppapszArgv, 
+                                         int nOptions );
+void CPL_DLL CPL_STDCALL GDALSwapWords( void *pData, int nWordSize, int nWordCount,
+                            int nWordSkip );
+void CPL_DLL CPL_STDCALL 
+    GDALCopyWords( void * pSrcData, GDALDataType eSrcType, int nSrcPixelOffset,
+                   void * pDstData, GDALDataType eDstType, int nDstPixelOffset,
+                   int nWordCount );
+
+void CPL_DLL 
+GDALCopyBits( const GByte *pabySrcData, int nSrcOffset, int nSrcStep, 
+              GByte *pabyDstData, int nDstOffset, int nDstStep,
+              int nBitCount, int nStepCount );
+
+int CPL_DLL CPL_STDCALL GDALLoadWorldFile( const char *, double * );
+int CPL_DLL CPL_STDCALL GDALReadWorldFile( const char *, const char *,
+                                           double * );
+int CPL_DLL CPL_STDCALL GDALWriteWorldFile( const char *, const char *,
+                                            double * );
+int CPL_DLL CPL_STDCALL GDALLoadTabFile( const char *, double *, char **,
+                                         int *, GDAL_GCP ** );
+int CPL_DLL CPL_STDCALL GDALReadTabFile( const char *, double *, char **,
+                                         int *, GDAL_GCP ** );
+int CPL_DLL CPL_STDCALL GDALLoadOziMapFile( const char *, double *, char **,
+                                            int *, GDAL_GCP ** );
+int CPL_DLL CPL_STDCALL GDALReadOziMapFile( const char * ,  double *,
+                                            char **, int *, GDAL_GCP ** );
+
+const char CPL_DLL * CPL_STDCALL GDALDecToDMS( double, const char *, int );
+double CPL_DLL CPL_STDCALL GDALPackedDMSToDec( double );
+double CPL_DLL CPL_STDCALL GDALDecToPackedDMS( double );
+
+/* Note to developers : please keep this section in sync with ogr_core.h */
+
+#ifndef GDAL_VERSION_INFO_DEFINED
+#define GDAL_VERSION_INFO_DEFINED
+const char CPL_DLL * CPL_STDCALL GDALVersionInfo( const char * );
+#endif
+
+#ifndef GDAL_CHECK_VERSION
+
+int CPL_DLL CPL_STDCALL GDALCheckVersion( int nVersionMajor, int nVersionMinor,
+                                          const char* pszCallingComponentName);
+
+/** Helper macro for GDALCheckVersion()
+  @see GDALCheckVersion()
+  */
+#define GDAL_CHECK_VERSION(pszCallingComponentName) \
+ GDALCheckVersion(GDAL_VERSION_MAJOR, GDAL_VERSION_MINOR, pszCallingComponentName)
+
+#endif
+
+typedef struct { 
+    double      dfLINE_OFF;
+    double      dfSAMP_OFF;
+    double      dfLAT_OFF;
+    double      dfLONG_OFF;
+    double      dfHEIGHT_OFF;
+
+    double      dfLINE_SCALE;
+    double      dfSAMP_SCALE;
+    double      dfLAT_SCALE;
+    double      dfLONG_SCALE;
+    double      dfHEIGHT_SCALE;
+
+    double      adfLINE_NUM_COEFF[20];
+    double      adfLINE_DEN_COEFF[20];
+    double      adfSAMP_NUM_COEFF[20];
+    double      adfSAMP_DEN_COEFF[20];
+    
+    double	dfMIN_LONG;
+    double      dfMIN_LAT;
+    double      dfMAX_LONG;
+    double	dfMAX_LAT;
+
+} GDALRPCInfo;
+
+int CPL_DLL CPL_STDCALL GDALExtractRPCInfo( char **, GDALRPCInfo * );
+
+/* ==================================================================== */
+/*      Color tables.                                                   */
+/* ==================================================================== */
+
+/** Color tuple */
+typedef struct
+{
+    /*! gray, red, cyan or hue */
+    short      c1;      
+
+    /*! green, magenta, or lightness */    
+    short      c2;      
+
+    /*! blue, yellow, or saturation */
+    short      c3;      
+
+    /*! alpha or blackband */
+    short      c4;      
+} GDALColorEntry;
+
+GDALColorTableH CPL_DLL CPL_STDCALL GDALCreateColorTable( GDALPaletteInterp );
+void CPL_DLL CPL_STDCALL GDALDestroyColorTable( GDALColorTableH );
+GDALColorTableH CPL_DLL CPL_STDCALL GDALCloneColorTable( GDALColorTableH );
+GDALPaletteInterp CPL_DLL CPL_STDCALL GDALGetPaletteInterpretation( GDALColorTableH );
+int CPL_DLL CPL_STDCALL GDALGetColorEntryCount( GDALColorTableH );
+const GDALColorEntry CPL_DLL * CPL_STDCALL GDALGetColorEntry( GDALColorTableH, int );
+int CPL_DLL CPL_STDCALL GDALGetColorEntryAsRGB( GDALColorTableH, int, GDALColorEntry *);
+void CPL_DLL CPL_STDCALL GDALSetColorEntry( GDALColorTableH, int, const GDALColorEntry * );
+void CPL_DLL CPL_STDCALL GDALCreateColorRamp( GDALColorTableH hTable, 
+            int nStartIndex, const GDALColorEntry *psStartColor,
+            int nEndIndex, const GDALColorEntry *psEndColor );
+
+/* ==================================================================== */
+/*      Raster Attribute Table						*/
+/* ==================================================================== */
+
+/** Field type of raster attribute table */
+typedef enum {
+    /*! Integer field */	   	   GFT_Integer , 
+    /*! Floating point (double) field */   GFT_Real,
+    /*! String field */                    GFT_String
+} GDALRATFieldType;
+
+/** Field usage of raster attribute table */
+typedef enum {
+    /*! General purpose field. */          GFU_Generic = 0,  
+    /*! Histogram pixel count */           GFU_PixelCount = 1,
+    /*! Class name */                      GFU_Name = 2,
+    /*! Class range minimum */             GFU_Min = 3,
+    /*! Class range maximum */             GFU_Max = 4,
+    /*! Class value (min=max) */           GFU_MinMax = 5,
+    /*! Red class color (0-255) */         GFU_Red = 6,
+    /*! Green class color (0-255) */       GFU_Green = 7,
+    /*! Blue class color (0-255) */        GFU_Blue = 8,
+    /*! Alpha (0=transparent,255=opaque)*/ GFU_Alpha = 9,
+    /*! Color Range Red Minimum */         GFU_RedMin = 10,
+    /*! Color Range Green Minimum */       GFU_GreenMin = 11,
+    /*! Color Range Blue Minimum */        GFU_BlueMin = 12,
+    /*! Color Range Alpha Minimum */       GFU_AlphaMin = 13,
+    /*! Color Range Red Maximum */         GFU_RedMax = 14,
+    /*! Color Range Green Maximum */       GFU_GreenMax = 15,
+    /*! Color Range Blue Maximum */        GFU_BlueMax = 16,
+    /*! Color Range Alpha Maximum */       GFU_AlphaMax = 17,
+    /*! Maximum GFU value */               GFU_MaxCount
+} GDALRATFieldUsage;
+
+GDALRasterAttributeTableH CPL_DLL CPL_STDCALL 
+                                           GDALCreateRasterAttributeTable(void);
+void CPL_DLL CPL_STDCALL GDALDestroyRasterAttributeTable(
+    GDALRasterAttributeTableH );
+
+int CPL_DLL CPL_STDCALL GDALRATGetColumnCount( GDALRasterAttributeTableH );
+
+const char CPL_DLL * CPL_STDCALL GDALRATGetNameOfCol( 
+    GDALRasterAttributeTableH, int );
+GDALRATFieldUsage CPL_DLL CPL_STDCALL GDALRATGetUsageOfCol( 
+    GDALRasterAttributeTableH, int );
+GDALRATFieldType CPL_DLL CPL_STDCALL GDALRATGetTypeOfCol( 
+    GDALRasterAttributeTableH, int );
+
+int CPL_DLL CPL_STDCALL GDALRATGetColOfUsage( GDALRasterAttributeTableH, 
+                                              GDALRATFieldUsage );
+int CPL_DLL CPL_STDCALL GDALRATGetRowCount( GDALRasterAttributeTableH );
+
+const char CPL_DLL * CPL_STDCALL GDALRATGetValueAsString( 
+    GDALRasterAttributeTableH, int ,int);
+int CPL_DLL CPL_STDCALL GDALRATGetValueAsInt( 
+    GDALRasterAttributeTableH, int ,int);
+double CPL_DLL CPL_STDCALL GDALRATGetValueAsDouble( 
+    GDALRasterAttributeTableH, int ,int);
+
+void CPL_DLL CPL_STDCALL GDALRATSetValueAsString( GDALRasterAttributeTableH, int, int,
+                                                  const char * );
+void CPL_DLL CPL_STDCALL GDALRATSetValueAsInt( GDALRasterAttributeTableH, int, int,
+                                               int );
+void CPL_DLL CPL_STDCALL GDALRATSetValueAsDouble( GDALRasterAttributeTableH, int, int,
+                                                  double );
+
+int CPL_DLL CPL_STDCALL GDALRATChangesAreWrittenToFile( GDALRasterAttributeTableH hRAT );
+
+CPLErr CPL_DLL CPL_STDCALL GDALRATValuesIOAsDouble( GDALRasterAttributeTableH hRAT, GDALRWFlag eRWFlag, 
+                                        int iField, int iStartRow, int iLength, double *pdfData );
+CPLErr CPL_DLL CPL_STDCALL GDALRATValuesIOAsInteger( GDALRasterAttributeTableH hRAT, GDALRWFlag eRWFlag, 
+                                        int iField, int iStartRow, int iLength, int *pnData);
+CPLErr CPL_DLL CPL_STDCALL GDALRATValuesIOAsString( GDALRasterAttributeTableH hRAT, GDALRWFlag eRWFlag, 
+                                        int iField, int iStartRow, int iLength, char **papszStrList);
+
+void CPL_DLL CPL_STDCALL GDALRATSetRowCount( GDALRasterAttributeTableH, 
+                                             int );
+CPLErr CPL_DLL CPL_STDCALL GDALRATCreateColumn( GDALRasterAttributeTableH, 
+                                                const char *, 
+                                                GDALRATFieldType, 
+                                                GDALRATFieldUsage );
+CPLErr CPL_DLL CPL_STDCALL GDALRATSetLinearBinning( GDALRasterAttributeTableH, 
+                                                    double, double );
+int CPL_DLL CPL_STDCALL GDALRATGetLinearBinning( GDALRasterAttributeTableH, 
+                                                 double *, double * );
+CPLErr CPL_DLL CPL_STDCALL GDALRATInitializeFromColorTable(
+    GDALRasterAttributeTableH, GDALColorTableH );
+GDALColorTableH CPL_DLL CPL_STDCALL GDALRATTranslateToColorTable(
+    GDALRasterAttributeTableH, int nEntryCount );
+void CPL_DLL CPL_STDCALL GDALRATDumpReadable( GDALRasterAttributeTableH, 
+                                              FILE * );
+GDALRasterAttributeTableH CPL_DLL CPL_STDCALL 
+    GDALRATClone( GDALRasterAttributeTableH );
+
+void CPL_DLL* CPL_STDCALL 
+    GDALRATSerializeJSON( GDALRasterAttributeTableH );
+
+int CPL_DLL CPL_STDCALL GDALRATGetRowOfValue( GDALRasterAttributeTableH , double );
+
+
+/* ==================================================================== */
+/*      GDAL Cache Management                                           */
+/* ==================================================================== */
+
+void CPL_DLL CPL_STDCALL GDALSetCacheMax( int nBytes );
+int CPL_DLL CPL_STDCALL GDALGetCacheMax(void);
+int CPL_DLL CPL_STDCALL GDALGetCacheUsed(void);
+void CPL_DLL CPL_STDCALL GDALSetCacheMax64( GIntBig nBytes );
+GIntBig CPL_DLL CPL_STDCALL GDALGetCacheMax64(void);
+GIntBig CPL_DLL CPL_STDCALL GDALGetCacheUsed64(void);
+
+int CPL_DLL CPL_STDCALL GDALFlushCacheBlock(void);
+
+/* ==================================================================== */
+/*      GDAL virtual memory                                             */
+/* ==================================================================== */
+
+CPLVirtualMem CPL_DLL* GDALDatasetGetVirtualMem( GDALDatasetH hDS,
+                                                 GDALRWFlag eRWFlag,
+                                                 int nXOff, int nYOff,
+                                                 int nXSize, int nYSize,
+                                                 int nBufXSize, int nBufYSize,
+                                                 GDALDataType eBufType,
+                                                 int nBandCount, int* panBandMap,
+                                                 int nPixelSpace,
+                                                 GIntBig nLineSpace,
+                                                 GIntBig nBandSpace,
+                                                 size_t nCacheSize,
+                                                 size_t nPageSizeHint,
+                                                 int bSingleThreadUsage,
+                                                 char **papszOptions );
+
+CPLVirtualMem CPL_DLL* GDALRasterBandGetVirtualMem( GDALRasterBandH hBand,
+                                         GDALRWFlag eRWFlag,
+                                         int nXOff, int nYOff,
+                                         int nXSize, int nYSize,
+                                         int nBufXSize, int nBufYSize,
+                                         GDALDataType eBufType,
+                                         int nPixelSpace,
+                                         GIntBig nLineSpace,
+                                         size_t nCacheSize,
+                                         size_t nPageSizeHint,
+                                         int bSingleThreadUsage,
+                                         char **papszOptions );
+
+CPLVirtualMem CPL_DLL* GDALGetVirtualMemAuto( GDALRasterBandH hBand,
+                                              GDALRWFlag eRWFlag,
+                                              int *pnPixelSpace,
+                                              GIntBig *pnLineSpace,
+                                              char **papszOptions );
+
+typedef enum
+{
+    /*! Tile Interleaved by Pixel: tile (0,0) with internal band interleaved by pixel organization, tile (1, 0), ...  */
+    GTO_TIP,
+    /*! Band Interleaved by Tile : tile (0,0) of first band, tile (0,0) of second band, ... tile (1,0) of fisrt band, tile (1,0) of second band, ... */
+    GTO_BIT,
+    /*! Band SeQuential : all the tiles of first band, all the tiles of following band... */
+    GTO_BSQ
+} GDALTileOrganization;
+
+CPLVirtualMem CPL_DLL* GDALDatasetGetTiledVirtualMem( GDALDatasetH hDS,
+                                                      GDALRWFlag eRWFlag,
+                                                      int nXOff, int nYOff,
+                                                      int nXSize, int nYSize,
+                                                      int nTileXSize, int nTileYSize,
+                                                      GDALDataType eBufType,
+                                                      int nBandCount, int* panBandMap,
+                                                      GDALTileOrganization eTileOrganization,
+                                                      size_t nCacheSize,
+                                                      int bSingleThreadUsage,
+                                                      char **papszOptions );
+
+CPLVirtualMem CPL_DLL* GDALRasterBandGetTiledVirtualMem( GDALRasterBandH hBand,
+                                                         GDALRWFlag eRWFlag,
+                                                         int nXOff, int nYOff,
+                                                         int nXSize, int nYSize,
+                                                         int nTileXSize, int nTileYSize,
+                                                         GDALDataType eBufType,
+                                                         size_t nCacheSize,
+                                                         int bSingleThreadUsage,
+                                                         char **papszOptions );
+
+/* =================================================================== */
+/*      Misc API                                                        */
+/* ==================================================================== */
+
+CPLXMLNode CPL_DLL* GDALGetJPEG2000Structure(const char* pszFilename,
+                                             char** papszOptions);
+
+CPL_C_END
+
+#endif /* ndef GDAL_H_INCLUDED */

+ 482 - 0
libpq_test/include/gdal_alg.h

@@ -0,0 +1,482 @@
+/******************************************************************************
+ * $Id: gdal_alg.h 27850 2014-10-12 16:58:09Z rouault $
+ *
+ * Project:  GDAL Image Processing Algorithms
+ * Purpose:  Prototypes, and definitions for various GDAL based algorithms.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2001, Frank Warmerdam
+ * Copyright (c) 2008-2012, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_ALG_H_INCLUDED
+#define GDAL_ALG_H_INCLUDED
+
+/**
+ * \file gdal_alg.h
+ *
+ * Public (C callable) GDAL algorithm entry points, and definitions.
+ */
+
+#ifndef DOXYGEN_SKIP
+#include "gdal.h"
+#include "cpl_minixml.h"
+#include "ogr_api.h"
+#endif
+
+CPL_C_START
+
+int CPL_DLL CPL_STDCALL GDALComputeMedianCutPCT( GDALRasterBandH hRed, 
+                             GDALRasterBandH hGreen, 
+                             GDALRasterBandH hBlue, 
+                             int (*pfnIncludePixel)(int,int,void*),
+                             int nColors, 
+                             GDALColorTableH hColorTable,
+                             GDALProgressFunc pfnProgress, 
+                             void * pProgressArg );
+
+int CPL_DLL CPL_STDCALL GDALDitherRGB2PCT( GDALRasterBandH hRed, 
+                       GDALRasterBandH hGreen, 
+                       GDALRasterBandH hBlue, 
+                       GDALRasterBandH hTarget, 
+                       GDALColorTableH hColorTable, 
+                       GDALProgressFunc pfnProgress, 
+                       void * pProgressArg );
+
+int CPL_DLL CPL_STDCALL GDALChecksumImage( GDALRasterBandH hBand, 
+                               int nXOff, int nYOff, int nXSize, int nYSize );
+                               
+CPLErr CPL_DLL CPL_STDCALL 
+GDALComputeProximity( GDALRasterBandH hSrcBand, 
+                      GDALRasterBandH hProximityBand,
+                      char **papszOptions,
+                      GDALProgressFunc pfnProgress, 
+                      void * pProgressArg );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALFillNodata( GDALRasterBandH hTargetBand, 
+                GDALRasterBandH hMaskBand,
+                double dfMaxSearchDist, 
+                int bDeprecatedOption,
+                int nSmoothingIterations,
+                char **papszOptions,
+                GDALProgressFunc pfnProgress, 
+                void * pProgressArg );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALPolygonize( GDALRasterBandH hSrcBand, 
+                GDALRasterBandH hMaskBand,
+                OGRLayerH hOutLayer, int iPixValField, 
+                char **papszOptions,
+                GDALProgressFunc pfnProgress, 
+                void * pProgressArg );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALFPolygonize( GDALRasterBandH hSrcBand,
+                GDALRasterBandH hMaskBand,
+                OGRLayerH hOutLayer, int iPixValField,
+                char **papszOptions,
+                GDALProgressFunc pfnProgress,
+                void * pProgressArg );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALSieveFilter( GDALRasterBandH hSrcBand, GDALRasterBandH hMaskBand,
+                 GDALRasterBandH hDstBand,
+                 int nSizeThreshold, int nConnectedness,
+                 char **papszOptions,
+                 GDALProgressFunc pfnProgress, 
+                 void * pProgressArg );
+
+/*
+ * Warp Related.
+ */
+
+typedef int 
+(*GDALTransformerFunc)( void *pTransformerArg, 
+                        int bDstToSrc, int nPointCount, 
+                        double *x, double *y, double *z, int *panSuccess );
+
+#define GDAL_GTI2_SIGNATURE     "GTI2"
+
+typedef struct {
+    GByte abySignature[4];
+    const char *pszClassName;
+    GDALTransformerFunc pfnTransform;
+    void (*pfnCleanup)( void * pTransformerArg );
+    CPLXMLNode *(*pfnSerialize)( void * pTransformerArg );
+    void* (*pfnCreateSimilar)( void* pTransformerArg, double dfSrcRatioX, double dfSrcRatioY );
+} GDALTransformerInfo;
+
+void CPL_DLL GDALDestroyTransformer( void *pTransformerArg );
+int  CPL_DLL GDALUseTransformer( void *pTranformerArg, 
+                                 int bDstToSrc, int nPointCount, 
+                                 double *x, double *y, double *z, 
+                                 int *panSuccess );
+void* GDALCreateSimilarTransformer( void* psTransformerArg, double dfSrcRatioX, double dfSrcRatioY );
+
+
+/* High level transformer for going from image coordinates on one file
+   to image coordiantes on another, potentially doing reprojection, 
+   utilizing GCPs or using the geotransform. */
+
+void CPL_DLL *
+GDALCreateGenImgProjTransformer( GDALDatasetH hSrcDS, const char *pszSrcWKT,
+                                 GDALDatasetH hDstDS, const char *pszDstWKT,
+                                 int bGCPUseOK, double dfGCPErrorThreshold,
+                                 int nOrder );
+void CPL_DLL *
+GDALCreateGenImgProjTransformer2( GDALDatasetH hSrcDS, GDALDatasetH hDstDS, 
+                                  char **papszOptions );
+void CPL_DLL *
+GDALCreateGenImgProjTransformer3( const char *pszSrcWKT,
+                                  const double *padfSrcGeoTransform,
+                                  const char *pszDstWKT,
+                                  const double *padfDstGeoTransform );
+void CPL_DLL GDALSetGenImgProjTransformerDstGeoTransform( void *, 
+                                                          const double * );
+void CPL_DLL GDALDestroyGenImgProjTransformer( void * );
+int CPL_DLL GDALGenImgProjTransform( 
+    void *pTransformArg, int bDstToSrc, int nPointCount,
+    double *x, double *y, double *z, int *panSuccess );
+
+void GDALSetTransformerDstGeoTransform( void *, const double * );
+
+/* Geo to geo reprojection transformer. */
+void CPL_DLL *
+GDALCreateReprojectionTransformer( const char *pszSrcWKT, 
+                                   const char *pszDstWKT );
+void CPL_DLL GDALDestroyReprojectionTransformer( void * );
+int CPL_DLL GDALReprojectionTransform( 
+    void *pTransformArg, int bDstToSrc, int nPointCount,
+    double *x, double *y, double *z, int *panSuccess );
+
+/* GCP based transformer ... forward is to georef coordinates */
+void CPL_DLL *
+GDALCreateGCPTransformer( int nGCPCount, const GDAL_GCP *pasGCPList, 
+                          int nReqOrder, int bReversed );
+			  
+/* GCP based transformer with refinement of the GCPs ... forward is to georef coordinates */
+void CPL_DLL *
+GDALCreateGCPRefineTransformer( int nGCPCount, const GDAL_GCP *pasGCPList, 
+                                int nReqOrder, int bReversed, double tolerance, int minimumGcps);
+			  
+void CPL_DLL GDALDestroyGCPTransformer( void *pTransformArg );
+int CPL_DLL GDALGCPTransform( 
+    void *pTransformArg, int bDstToSrc, int nPointCount,
+    double *x, double *y, double *z, int *panSuccess );
+
+/* Thin Plate Spine transformer ... forward is to georef coordinates */
+
+void CPL_DLL *
+GDALCreateTPSTransformer( int nGCPCount, const GDAL_GCP *pasGCPList, 
+                          int bReversed );
+void CPL_DLL GDALDestroyTPSTransformer( void *pTransformArg );
+int CPL_DLL GDALTPSTransform( 
+    void *pTransformArg, int bDstToSrc, int nPointCount,
+    double *x, double *y, double *z, int *panSuccess );
+
+char CPL_DLL ** RPCInfoToMD( GDALRPCInfo *psRPCInfo );
+
+/* RPC based transformer ... src is pixel/line/elev, dst is long/lat/elev */
+
+void CPL_DLL *
+GDALCreateRPCTransformer( GDALRPCInfo *psRPC, int bReversed, 
+                          double dfPixErrThreshold,
+                          char **papszOptions );
+void CPL_DLL GDALDestroyRPCTransformer( void *pTransformArg );
+int CPL_DLL GDALRPCTransform( 
+    void *pTransformArg, int bDstToSrc, int nPointCount,
+    double *x, double *y, double *z, int *panSuccess );
+
+/* Geolocation transformer */
+
+void CPL_DLL *
+GDALCreateGeoLocTransformer( GDALDatasetH hBaseDS, 
+                             char **papszGeolocationInfo,
+                             int bReversed );
+void CPL_DLL GDALDestroyGeoLocTransformer( void *pTransformArg );
+int CPL_DLL GDALGeoLocTransform( 
+    void *pTransformArg, int bDstToSrc, int nPointCount,
+    double *x, double *y, double *z, int *panSuccess );
+
+/* Approximate transformer */
+void CPL_DLL *
+GDALCreateApproxTransformer( GDALTransformerFunc pfnRawTransformer, 
+                             void *pRawTransformerArg, double dfMaxError );
+void CPL_DLL GDALApproxTransformerOwnsSubtransformer( void *pCBData, 
+                                                      int bOwnFlag );
+void CPL_DLL GDALDestroyApproxTransformer( void *pApproxArg );
+int  CPL_DLL GDALApproxTransform(
+    void *pTransformArg, int bDstToSrc, int nPointCount,
+    double *x, double *y, double *z, int *panSuccess );
+
+                      
+
+
+int CPL_DLL CPL_STDCALL
+GDALSimpleImageWarp( GDALDatasetH hSrcDS, 
+                     GDALDatasetH hDstDS, 
+                     int nBandCount, int *panBandList,
+                     GDALTransformerFunc pfnTransform,
+                     void *pTransformArg,
+                     GDALProgressFunc pfnProgress, 
+                     void *pProgressArg, 
+                     char **papszWarpOptions );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALSuggestedWarpOutput( GDALDatasetH hSrcDS, 
+                         GDALTransformerFunc pfnTransformer,
+                         void *pTransformArg,
+                         double *padfGeoTransformOut, 
+                         int *pnPixels, int *pnLines );
+CPLErr CPL_DLL CPL_STDCALL
+GDALSuggestedWarpOutput2( GDALDatasetH hSrcDS, 
+                          GDALTransformerFunc pfnTransformer,
+                          void *pTransformArg,
+                          double *padfGeoTransformOut, 
+                          int *pnPixels, int *pnLines,
+                          double *padfExtents, 
+                          int nOptions );
+
+CPLXMLNode CPL_DLL *
+GDALSerializeTransformer( GDALTransformerFunc pfnFunc, void *pTransformArg );
+CPLErr CPL_DLL GDALDeserializeTransformer( CPLXMLNode *psTree, 
+                                           GDALTransformerFunc *ppfnFunc, 
+                                           void **ppTransformArg );
+
+CPLErr CPL_DLL
+GDALTransformGeolocations( GDALRasterBandH hXBand, 
+                           GDALRasterBandH hYBand, 
+                           GDALRasterBandH hZBand,
+                           GDALTransformerFunc pfnTransformer, 
+                           void *pTransformArg, 
+                           GDALProgressFunc pfnProgress, 
+                           void *pProgressArg,
+                           char **papszOptions );
+
+/* -------------------------------------------------------------------- */
+/*      Contour Line Generation                                         */
+/* -------------------------------------------------------------------- */
+
+typedef CPLErr (*GDALContourWriter)( double dfLevel, int nPoints,
+                                     double *padfX, double *padfY, void * );
+
+typedef void *GDALContourGeneratorH;
+
+GDALContourGeneratorH CPL_DLL
+GDAL_CG_Create( int nWidth, int nHeight, 
+                int bNoDataSet, double dfNoDataValue,
+                double dfContourInterval, double dfContourBase,
+                GDALContourWriter pfnWriter, void *pCBData );
+CPLErr CPL_DLL GDAL_CG_FeedLine( GDALContourGeneratorH hCG, 
+                                 double *padfScanline );
+void CPL_DLL GDAL_CG_Destroy( GDALContourGeneratorH hCG );
+
+typedef struct 
+{
+    void   *hLayer;
+
+    double adfGeoTransform[6];
+    
+    int    nElevField;
+    int    nIDField;
+    int    nNextID;
+} OGRContourWriterInfo;
+
+CPLErr CPL_DLL 
+OGRContourWriter( double, int, double *, double *, void *pInfo );
+
+CPLErr CPL_DLL
+GDALContourGenerate( GDALRasterBandH hBand, 
+                            double dfContourInterval, double dfContourBase,
+                            int nFixedLevelCount, double *padfFixedLevels,
+                            int bUseNoData, double dfNoDataValue, 
+                            void *hLayer, int iIDField, int iElevField,
+                            GDALProgressFunc pfnProgress, void *pProgressArg );
+
+/************************************************************************/
+/*      Rasterizer API - geometries burned into GDAL raster.            */
+/************************************************************************/
+
+CPLErr CPL_DLL 
+GDALRasterizeGeometries( GDALDatasetH hDS, 
+                         int nBandCount, int *panBandList, 
+                         int nGeomCount, OGRGeometryH *pahGeometries,
+                         GDALTransformerFunc pfnTransformer, 
+                         void *pTransformArg, 
+                         double *padfGeomBurnValue,
+                         char **papszOptions,
+                         GDALProgressFunc pfnProgress, 
+                         void * pProgressArg );
+CPLErr CPL_DLL
+GDALRasterizeLayers( GDALDatasetH hDS, 
+                     int nBandCount, int *panBandList,
+                     int nLayerCount, OGRLayerH *pahLayers,
+                     GDALTransformerFunc pfnTransformer, 
+                     void *pTransformArg, 
+                     double *padfLayerBurnValues,
+                     char **papszOptions,
+                     GDALProgressFunc pfnProgress, 
+                     void *pProgressArg );
+
+CPLErr CPL_DLL 
+GDALRasterizeLayersBuf( void *pData, int nBufXSize, int nBufYSize,
+                        GDALDataType eBufType, int nPixelSpace, int nLineSpace,
+                        int nLayerCount, OGRLayerH *pahLayers,
+                        const char *pszDstProjection,
+                        double *padfDstGeoTransform,
+                        GDALTransformerFunc pfnTransformer, 
+                        void *pTransformArg, double dfBurnValue,
+                        char **papszOptions, GDALProgressFunc pfnProgress, 
+                        void *pProgressArg );
+
+
+/************************************************************************/
+/*  Gridding interface.                                                 */
+/************************************************************************/
+
+/** Gridding Algorithms */
+typedef enum {
+  /*! Inverse distance to a power */    GGA_InverseDistanceToAPower = 1,
+  /*! Moving Average */                 GGA_MovingAverage = 2,
+  /*! Nearest Neighbor */               GGA_NearestNeighbor = 3,
+  /*! Minimum Value (Data Metric) */    GGA_MetricMinimum = 4,
+  /*! Maximum Value (Data Metric) */    GGA_MetricMaximum = 5,
+  /*! Data Range (Data Metric) */       GGA_MetricRange = 6,
+  /*! Number of Points (Data Metric) */ GGA_MetricCount = 7,
+  /*! Average Distance (Data Metric) */ GGA_MetricAverageDistance = 8,
+  /*! Average Distance Between Data Points (Data Metric) */
+                                        GGA_MetricAverageDistancePts = 9
+} GDALGridAlgorithm;
+
+/** Inverse distance to a power method control options */
+typedef struct
+{
+    /*! Weighting power. */
+    double  dfPower;
+    /*! Smoothing parameter. */
+    double  dfSmoothing;
+    /*! Reserved for future use. */
+    double  dfAnisotropyRatio;
+    /*! Reserved for future use. */
+    double  dfAnisotropyAngle;
+    /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius1;
+    /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius2;
+    /*! Angle of ellipse rotation in degrees.
+     *
+     * Ellipse rotated counter clockwise.
+     */
+    double  dfAngle;
+    /*! Maximum number of data points to use.
+     *
+     * Do not search for more points than this number.
+     * If less amount of points found the grid node considered empty and will
+     * be filled with NODATA marker.
+     */
+    GUInt32 nMaxPoints;
+    /*! Minimum number of data points to use.
+     *
+     * If less amount of points found the grid node considered empty and will
+     * be filled with NODATA marker.
+     */
+    GUInt32 nMinPoints;
+    /*! No data marker to fill empty points. */
+    double  dfNoDataValue;
+} GDALGridInverseDistanceToAPowerOptions;
+
+/** Moving average method control options */
+typedef struct
+{
+    /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius1;
+    /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius2;
+    /*! Angle of ellipse rotation in degrees.
+     *
+     * Ellipse rotated counter clockwise.
+     */
+    double  dfAngle;
+    /*! Minimum number of data points to average.
+     *
+     * If less amount of points found the grid node considered empty and will
+     * be filled with NODATA marker.
+     */
+    GUInt32 nMinPoints;
+    /*! No data marker to fill empty points. */
+    double  dfNoDataValue;
+} GDALGridMovingAverageOptions;
+
+/** Nearest neighbor method control options */
+typedef struct
+{
+    /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius1;
+    /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius2;
+    /*! Angle of ellipse rotation in degrees.
+     *
+     * Ellipse rotated counter clockwise.
+     */
+    double  dfAngle;
+    /*! No data marker to fill empty points. */
+    double  dfNoDataValue;
+} GDALGridNearestNeighborOptions;
+
+/** Data metrics method control options */
+typedef struct
+{
+    /*! The first radius (X axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius1;
+    /*! The second radius (Y axis if rotation angle is 0) of search ellipse. */
+    double  dfRadius2;
+    /*! Angle of ellipse rotation in degrees.
+     *
+     * Ellipse rotated counter clockwise.
+     */
+    double  dfAngle;
+    /*! Minimum number of data points to average.
+     *
+     * If less amount of points found the grid node considered empty and will
+     * be filled with NODATA marker.
+     */
+    GUInt32 nMinPoints;
+    /*! No data marker to fill empty points. */
+    double  dfNoDataValue;
+} GDALGridDataMetricsOptions;
+
+CPLErr CPL_DLL
+GDALGridCreate( GDALGridAlgorithm, const void *, GUInt32,
+                const double *, const double *, const double *,
+                double, double, double, double,
+                GUInt32, GUInt32, GDALDataType, void *,
+                GDALProgressFunc, void *);
+
+GDAL_GCP CPL_DLL *
+GDALComputeMatchingPoints( GDALDatasetH hFirstImage,
+                           GDALDatasetH hSecondImage,
+                           char **papszOptions,
+                           int *pnGCPCount ); 
+CPL_C_END
+                            
+#endif /* ndef GDAL_ALG_H_INCLUDED */

+ 229 - 0
libpq_test/include/gdal_alg_priv.h

@@ -0,0 +1,229 @@
+/******************************************************************************
+ * $Id: gdal_alg_priv.h 28826 2015-03-30 17:51:14Z rouault $
+ *
+ * Project:  GDAL Image Processing Algorithms
+ * Purpose:  Prototypes and definitions for various GDAL based algorithms:
+ *           private declarations.
+ * Author:   Andrey Kiselev, dron@ak4719.spb.edu
+ *
+ ******************************************************************************
+ * Copyright (c) 2008, Andrey Kiselev <dron@ak4719.spb.edu>
+ * Copyright (c) 2010-2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_ALG_PRIV_H_INCLUDED
+#define GDAL_ALG_PRIV_H_INCLUDED
+
+#include "gdal_alg.h"
+
+CPL_C_START
+
+/** Source of the burn value */
+typedef enum {
+    /*! Use value from padfBurnValue */    GBV_UserBurnValue = 0,
+    /*! Use value from the Z coordinate */    GBV_Z = 1,
+    /*! Use value form the M value */    GBV_M = 2
+} GDALBurnValueSrc;
+
+typedef enum {
+    GRMA_Replace = 0,
+    GRMA_Add = 1,
+} GDALRasterMergeAlg;
+
+typedef struct {
+    unsigned char * pabyChunkBuf;
+    int nXSize;
+    int nYSize;
+    int nBands;
+    GDALDataType eType;
+    double *padfBurnValue;
+    GDALBurnValueSrc eBurnValueSource;
+    GDALRasterMergeAlg eMergeAlg;
+} GDALRasterizeInfo;
+
+/************************************************************************/
+/*      Low level rasterizer API.                                       */
+/************************************************************************/
+
+typedef void (*llScanlineFunc)( void *, int, int, int, double );
+typedef void (*llPointFunc)( void *, int, int, double );
+
+void GDALdllImagePoint( int nRasterXSize, int nRasterYSize,
+                        int nPartCount, int *panPartSize,
+                        double *padfX, double *padfY, double *padfVariant,
+                        llPointFunc pfnPointFunc, void *pCBData );
+
+void GDALdllImageLine( int nRasterXSize, int nRasterYSize, 
+                       int nPartCount, int *panPartSize,
+                       double *padfX, double *padfY, double *padfVariant,
+                       llPointFunc pfnPointFunc, void *pCBData );
+
+void GDALdllImageLineAllTouched(int nRasterXSize, int nRasterYSize, 
+                                int nPartCount, int *panPartSize,
+                                double *padfX, double *padfY,
+                                double *padfVariant,
+                                llPointFunc pfnPointFunc, void *pCBData );
+
+void GDALdllImageFilledPolygon(int nRasterXSize, int nRasterYSize, 
+                               int nPartCount, int *panPartSize,
+                               double *padfX, double *padfY,
+                               double *padfVariant,
+                               llScanlineFunc pfnScanlineFunc, void *pCBData );
+
+CPL_C_END
+
+/************************************************************************/
+/*                          Polygon Enumerator                          */
+/************************************************************************/
+
+#define GP_NODATA_MARKER -51502112
+
+class GDALRasterPolygonEnumerator
+
+{
+private:
+    void     MergePolygon( int nSrcId, int nDstId );
+    int      NewPolygon( GInt32 nValue );
+
+public:  // these are intended to be readonly.
+
+    GInt32   *panPolyIdMap;
+    GInt32   *panPolyValue;
+
+    int      nNextPolygonId;
+    int      nPolyAlloc;
+
+    int      nConnectedness;
+
+public:
+             GDALRasterPolygonEnumerator( int nConnectedness=4 );
+            ~GDALRasterPolygonEnumerator();
+
+    void     ProcessLine( GInt32 *panLastLineVal, GInt32 *panThisLineVal,
+                          GInt32 *panLastLineId,  GInt32 *panThisLineId, 
+                          int nXSize );
+
+    void     CompleteMerges();
+
+    void     Clear();
+};
+
+#ifdef OGR_ENABLED
+/************************************************************************/
+/*                          Polygon Enumerator                          */
+/*                                                                      */
+/*              Buffers has float values instead og GInt32              */
+/************************************************************************/
+class GDALRasterFPolygonEnumerator
+
+{
+private:
+    void     MergePolygon( int nSrcId, int nDstId );
+    int      NewPolygon( float fValue );
+
+public:  // these are intended to be readonly.
+
+    GInt32   *panPolyIdMap;
+    float    *pafPolyValue;
+
+    int      nNextPolygonId;
+    int      nPolyAlloc;
+
+    int      nConnectedness;
+
+public:
+             GDALRasterFPolygonEnumerator( int nConnectedness=4 );
+            ~GDALRasterFPolygonEnumerator();
+
+    void     ProcessLine( float *pafLastLineVal, float *pafThisLineVal,
+                          GInt32 *panLastLineId,  GInt32 *panThisLineId,
+                          int nXSize );
+
+    void     CompleteMerges();
+
+    void     Clear();
+};
+#endif
+
+typedef void* (*GDALTransformDeserializeFunc)( CPLXMLNode *psTree );
+
+void* GDALRegisterTransformDeserializer(const char* pszTransformName,
+                                       GDALTransformerFunc pfnTransformerFunc,
+                                       GDALTransformDeserializeFunc pfnDeserializeFunc);
+void GDALUnregisterTransformDeserializer(void* pData);
+
+void GDALCleanupTransformDeserializerMutex();
+
+/* Transformer cloning */
+
+void* GDALCreateTPSTransformerInt( int nGCPCount, const GDAL_GCP *pasGCPList, 
+                                   int bReversed, char** papszOptions );
+
+void CPL_DLL * GDALCloneTransformer( void *pTranformerArg );
+
+/************************************************************************/
+/*      Color table related                                             */
+/************************************************************************/
+
+int
+GDALComputeMedianCutPCTInternal( GDALRasterBandH hRed, 
+                           GDALRasterBandH hGreen, 
+                           GDALRasterBandH hBlue, 
+                           GByte* pabyRedBand,
+                           GByte* pabyGreenBand,
+                           GByte* pabyBlueBand,
+                           int (*pfnIncludePixel)(int,int,void*),
+                           int nColors, 
+                           int nBits,
+                           int* panHistogram,
+                           GDALColorTableH hColorTable,
+                           GDALProgressFunc pfnProgress, 
+                           void * pProgressArg );
+
+int GDALDitherRGB2PCTInternal( GDALRasterBandH hRed, 
+                               GDALRasterBandH hGreen, 
+                               GDALRasterBandH hBlue, 
+                               GDALRasterBandH hTarget, 
+                               GDALColorTableH hColorTable,
+                               int nBits,
+                               GInt16* pasDynamicColorMap,
+                               int bDither,
+                               GDALProgressFunc pfnProgress, 
+                               void * pProgressArg );
+
+#define PRIME_FOR_65536                                 98317
+#define MEDIAN_CUT_AND_DITHER_BUFFER_SIZE_65536         (6 * sizeof(int) * PRIME_FOR_65536)
+
+/************************************************************************/
+/*      Float comparison function.                                      */
+/************************************************************************/
+
+/**
+ * Units in the Last Place. This specifies how big an error we are willing to
+ * accept in terms of the value of the least significant digit of the floating
+ * point number’s representation. MAX_ULPS can also be interpreted in terms of
+ * how many representable floats we are willing to accept between A and B. 
+ */
+#define MAX_ULPS 10
+
+GBool GDALFloatEquals(float A, float B);
+
+#endif /* ndef GDAL_ALG_PRIV_H_INCLUDED */

+ 41 - 0
libpq_test/include/gdal_csv.h

@@ -0,0 +1,41 @@
+/******************************************************************************
+ * $Id: gdal_csv.h 27044 2014-03-16 23:41:27Z rouault $
+ *
+ * Project:  Common Portability Library
+ * Purpose:  Functions for reading and scaning CSV (comma separated,
+ *           variable length text files holding tables) files.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 1999, Frank Warmerdam
+ * Copyright (c) 2010, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_CSV_H_INCLUDED
+#define GDAL_CSV_H_INCLUDED
+
+#include "cpl_port.h"
+
+CPL_C_START
+const char * GDALDefaultCSVFilename( const char *pszBasename );
+CPL_C_END
+
+#endif

+ 187 - 0
libpq_test/include/gdal_frmts.h

@@ -0,0 +1,187 @@
+/******************************************************************************
+ * $Id: gdal_frmts.h 28859 2015-04-07 08:40:10Z rouault $
+ *
+ * Project:  GDAL
+ * Purpose:  Prototypes for all format specific driver initializations.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2001, Frank Warmerdam
+ * Copyright (c) 2007-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_FRMTS_H_INCLUDED
+#define GDAL_FRMTS_H_INCLUDED
+
+#include "cpl_port.h"
+
+CPL_C_START
+void CPL_DLL GDALRegister_GDB(void);
+void CPL_DLL GDALRegister_GTiff(void);
+void CPL_DLL GDALRegister_GXF(void);
+void CPL_DLL GDALRegister_OGDI(void);
+void CPL_DLL GDALRegister_HFA(void);
+void CPL_DLL GDALRegister_AAIGrid(void);
+void CPL_DLL GDALRegister_GRASSASCIIGrid(void);
+void CPL_DLL GDALRegister_AIGrid(void);
+void CPL_DLL GDALRegister_AIGrid2(void);
+void CPL_DLL GDALRegister_CEOS(void);
+void CPL_DLL GDALRegister_SAR_CEOS(void);
+void CPL_DLL GDALRegister_SDTS(void);
+void CPL_DLL GDALRegister_ELAS(void);
+void CPL_DLL GDALRegister_EHdr(void);
+void CPL_DLL GDALRegister_GenBin(void);
+void CPL_DLL GDALRegister_PAux(void);
+void CPL_DLL GDALRegister_ENVI(void);
+void CPL_DLL GDALRegister_DOQ1(void);
+void CPL_DLL GDALRegister_DOQ2(void);
+void CPL_DLL GDALRegister_DTED(void);
+void CPL_DLL GDALRegister_MFF(void);
+void CPL_DLL GDALRegister_HKV(void);
+void CPL_DLL GDALRegister_PNG(void);
+void CPL_DLL GDALRegister_DDS(void);
+void CPL_DLL GDALRegister_GTA(void);
+void CPL_DLL GDALRegister_JPEG(void);
+void CPL_DLL GDALRegister_JPEG2000(void);
+void CPL_DLL GDALRegister_JP2KAK(void);
+void CPL_DLL GDALRegister_JPIPKAK(void);
+void CPL_DLL GDALRegister_MEM(void);
+void CPL_DLL GDALRegister_JDEM(void);
+void CPL_DLL GDALRegister_RASDAMAN(void);
+void CPL_DLL GDALRegister_GRASS(void);
+void CPL_DLL GDALRegister_PNM(void);
+void CPL_DLL GDALRegister_GIF(void);
+void CPL_DLL GDALRegister_BIGGIF(void);
+void CPL_DLL GDALRegister_Envisat(void);
+void CPL_DLL GDALRegister_FITS(void);
+void CPL_DLL GDALRegister_ECW(void);
+void CPL_DLL GDALRegister_JP2ECW(void);
+void CPL_DLL GDALRegister_ECW_JP2ECW();
+void CPL_DLL GDALRegister_FujiBAS(void);
+void CPL_DLL GDALRegister_FIT(void);
+void CPL_DLL GDALRegister_VRT(void);
+void CPL_DLL GDALRegister_USGSDEM(void);
+void CPL_DLL GDALRegister_FAST(void);
+void CPL_DLL GDALRegister_HDF4(void);
+void CPL_DLL GDALRegister_HDF4Image(void);
+void CPL_DLL GDALRegister_L1B(void);
+void CPL_DLL GDALRegister_LDF(void);
+void CPL_DLL GDALRegister_BSB(void);
+void CPL_DLL GDALRegister_XPM(void);
+void CPL_DLL GDALRegister_BMP(void);
+void CPL_DLL GDALRegister_GSC(void);
+void CPL_DLL GDALRegister_NITF(void);
+void CPL_DLL GDALRegister_RPFTOC(void);
+void CPL_DLL GDALRegister_ECRGTOC(void);
+void CPL_DLL GDALRegister_MrSID(void);
+void CPL_DLL GDALRegister_MG4Lidar(void);
+void CPL_DLL GDALRegister_PCIDSK(void);
+void CPL_DLL GDALRegister_BT(void);
+void CPL_DLL GDALRegister_DODS(void);
+void CPL_DLL GDALRegister_GMT(void);
+void CPL_DLL GDALRegister_netCDF(void);
+void CPL_DLL GDALRegister_LAN(void);
+void CPL_DLL GDALRegister_CPG(void);
+void CPL_DLL GDALRegister_AirSAR(void);
+void CPL_DLL GDALRegister_RS2(void);
+void CPL_DLL GDALRegister_ILWIS(void);
+void CPL_DLL GDALRegister_PCRaster(void);
+void CPL_DLL GDALRegister_IDA(void);
+void CPL_DLL GDALRegister_NDF(void);
+void CPL_DLL GDALRegister_RMF(void);
+void CPL_DLL GDALRegister_BAG(void);
+void CPL_DLL GDALRegister_HDF5(void);
+void CPL_DLL GDALRegister_HDF5Image(void);
+void CPL_DLL GDALRegister_MSGN(void);
+void CPL_DLL GDALRegister_MSG(void);
+void CPL_DLL GDALRegister_RIK(void);
+void CPL_DLL GDALRegister_Leveller(void);
+void CPL_DLL GDALRegister_SGI(void);
+void CPL_DLL GDALRegister_SRTMHGT(void);
+void CPL_DLL GDALRegister_DIPEx(void);
+void CPL_DLL GDALRegister_ISIS3(void);
+void CPL_DLL GDALRegister_ISIS2(void);
+void CPL_DLL GDALRegister_PDS(void);
+void CPL_DLL GDALRegister_VICAR(void);
+void CPL_DLL GDALRegister_IDRISI(void);
+void CPL_DLL GDALRegister_Terragen(void);
+void CPL_DLL GDALRegister_WCS(void);
+void CPL_DLL GDALRegister_WMS(void);
+void CPL_DLL GDALRegister_HTTP(void);
+void CPL_DLL GDALRegister_SDE(void);
+void CPL_DLL GDALRegister_GSAG(void);
+void CPL_DLL GDALRegister_GSBG(void);
+void CPL_DLL GDALRegister_GS7BG(void);
+void CPL_DLL GDALRegister_GRIB(void);
+void CPL_DLL GDALRegister_INGR(void);
+void CPL_DLL GDALRegister_ERS(void);
+void CPL_DLL GDALRegister_PALSARJaxa(void);
+void CPL_DLL GDALRegister_DIMAP();
+void CPL_DLL GDALRegister_GFF(void);
+void CPL_DLL GDALRegister_COSAR(void);
+void CPL_DLL GDALRegister_TSX(void);
+void CPL_DLL GDALRegister_ADRG(void);
+void CPL_DLL GDALRegister_SRP(void);
+void CPL_DLL GDALRegister_COASP(void);
+void CPL_DLL GDALRegister_BLX(void);
+void CPL_DLL GDALRegister_LCP(void);
+void CPL_DLL GDALRegister_PGCHIP(void);
+void CPL_DLL GDALRegister_TMS(void);
+void CPL_DLL GDALRegister_EIR(void);
+void CPL_DLL GDALRegister_GEOR(void);
+void CPL_DLL GDALRegister_TIL(void);
+void CPL_DLL GDALRegister_R(void);
+void CPL_DLL GDALRegister_Rasterlite(void);
+void CPL_DLL GDALRegister_EPSILON(void);
+void CPL_DLL GDALRegister_PostGISRaster(void);
+void CPL_DLL GDALRegister_NWT_GRD(void);
+void CPL_DLL GDALRegister_NWT_GRC(void);
+void CPL_DLL GDALRegister_SAGA(void);
+void CPL_DLL GDALRegister_KMLSUPEROVERLAY(void);
+void CPL_DLL GDALRegister_GTX(void);
+void CPL_DLL GDALRegister_LOSLAS(void);
+void CPL_DLL GDALRegister_Istar(void);
+void CPL_DLL GDALRegister_NTv2(void);
+void CPL_DLL GDALRegister_CTable2(void);
+void CPL_DLL GDALRegister_JP2OpenJPEG(void);
+void CPL_DLL GDALRegister_XYZ(void);
+void CPL_DLL GDALRegister_HF2(void);
+void CPL_DLL GDALRegister_PDF(void);
+void CPL_DLL GDALRegister_JPEGLS(void);
+void CPL_DLL GDALRegister_MAP(void);
+void CPL_DLL GDALRegister_OZI(void);
+void CPL_DLL GDALRegister_ACE2(void);
+void CPL_DLL GDALRegister_CTG(void);
+void CPL_DLL GDALRegister_E00GRID(void);
+void CPL_DLL GDALRegister_SNODAS(void);
+void CPL_DLL GDALRegister_WEBP(void);
+void CPL_DLL GDALRegister_ZMap(void);
+void CPL_DLL GDALRegister_NGSGEOID(void);
+void CPL_DLL GDALRegister_MBTiles(void);
+void CPL_DLL GDALRegister_ARG(void);
+void CPL_DLL GDALRegister_IRIS(void);
+void CPL_DLL GDALRegister_KRO(void);
+void CPL_DLL GDALRegister_KEA(void);
+void CPL_DLL GDALRegister_ROIPAC(void);
+void CPL_DLL GDALRegister_PLMOSAIC(void);
+CPL_C_END
+
+#endif /* ndef GDAL_FRMTS_H_INCLUDED */

+ 207 - 0
libpq_test/include/gdal_mdreader.h

@@ -0,0 +1,207 @@
+/******************************************************************************
+ * $Id: gdal_mdreader.h 29190 2015-05-13 21:40:30Z bishop $
+ *
+ * Project:  GDAL Core
+ * Purpose:  Read metadata (mainly the remote sensing imagery) from files of 
+ *           different providers like DigitalGlobe, GeoEye etc.
+ * Author:   Dmitry Baryshnikov, polimax@mail.ru
+ *
+ ******************************************************************************
+ * Copyright (c) 2014-2015, NextGIS info@nextgis.ru
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+ 
+#ifndef GDAL_MDREADER_H_INCLUDED
+#define GDAL_MDREADER_H_INCLUDED
+
+
+#include "cpl_port.h"
+#include "gdal_priv.h"
+
+#define MD_DOMAIN_IMD "IMD"              /**< image metadata section */
+#define MD_DOMAIN_RPC "RPC"              /**< rpc metadata section */
+#define MD_DOMAIN_IMAGERY "IMAGERY"      /**< imagery metadata section */
+#define MD_DOMAIN_DEFAULT ""             /**< default metadata section */
+
+#define MD_NAME_ACQDATETIME "ACQUISITIONDATETIME"  /**< Acquisition Date Time property name. The time should be in UTC */
+#define MD_NAME_SATELLITE   "SATELLITEID"          /**< Satellite identificator property name */
+#define MD_NAME_CLOUDCOVER  "CLOUDCOVER"           /**< Cloud coverage property name. The value between 0 - 100 or 999 if n/a */
+#define MD_NAME_MDTYPE      "METADATATYPE"         /**< Metadata reader type property name. The reader processed this metadata */
+
+#define MD_DATETIMEFORMAT "%Y-%m-%d %H:%M:%S"      /**< Date time format */
+#define MD_CLOUDCOVER_NA "999"           /**< The value if cloud cover is n/a */
+
+/**
+ * RPC/RPB specific defines
+ */
+
+#define RPC_LINE_OFF        "LINE_OFF"
+#define RPC_SAMP_OFF        "SAMP_OFF"
+#define RPC_LAT_OFF         "LAT_OFF"
+#define RPC_LONG_OFF        "LONG_OFF"
+#define RPC_HEIGHT_OFF      "HEIGHT_OFF"
+#define RPC_LINE_SCALE      "LINE_SCALE"
+#define RPC_SAMP_SCALE      "SAMP_SCALE"
+#define RPC_LAT_SCALE       "LAT_SCALE"
+#define RPC_LONG_SCALE      "LONG_SCALE"
+#define RPC_HEIGHT_SCALE    "HEIGHT_SCALE"
+#define RPC_LINE_NUM_COEFF  "LINE_NUM_COEFF"
+#define RPC_LINE_DEN_COEFF  "LINE_DEN_COEFF"
+#define RPC_SAMP_NUM_COEFF  "SAMP_NUM_COEFF"
+#define RPC_SAMP_DEN_COEFF  "SAMP_DEN_COEFF"
+
+/**
+ * Enumerator of metadata readers
+ */
+
+typedef enum {
+    MDR_None     = 0x00000000,    /**< no reader */
+    MDR_DG       = 0x00000001,    /**< Digital Globe, METADATATYPE=DG */
+    MDR_GE       = 0x00000002,    /**< Geo Eye,       METADATATYPE=GE */
+    MDR_OV       = 0x00000004,    /**< Orb View,      METADATATYPE=OV */
+    MDR_PLEIADES = 0x00000008,    /**< Pleiades,      METADATATYPE=DIMAP */
+    MDR_SPOT     = 0x00000010,    /**< Spot,          METADATATYPE=DIMAP */
+    MDR_RDK1     = 0x00000020,    /**< Resurs DK1,    METADATATYPE=MSP */
+    MDR_LS       = 0x00000040,    /**< Landsat,       METADATATYPE=ODL */
+    MDR_RE       = 0x00000080,    /**< RapidEye,      METADATATYPE=RE */
+    MDR_KOMPSAT  = 0x00000100,    /**< Kompsat,       METADATATYPE=KARI */
+    MDR_EROS     = 0x00000200,    /**< EROS,          METADATATYPE=EROS */
+    MDR_ALOS     = 0x00000400,    /**< ALOS,          METADATATYPE=ALOS */
+    MDR_ANY  = MDR_DG | MDR_GE | MDR_OV | MDR_PLEIADES | MDR_SPOT | MDR_RDK1 |
+               MDR_LS | MDR_RE | MDR_KOMPSAT | MDR_EROS | MDR_ALOS /**< any reader */
+} MDReaders;
+
+
+/**
+ * The base class for all metadata readers
+ */
+class GDALMDReaderBase{
+public:
+    GDALMDReaderBase(const char *pszPath, char **papszSiblingFiles);
+    virtual ~GDALMDReaderBase();
+
+    /**
+     * @brief Get specified metadata domain
+     * @param pszDomain The metadata domain to return  
+     * @return List of metadata items 
+     */
+    virtual char ** GetMetadataDomain(const char *pszDomain);
+    /**
+     * @brief Fill provided metatada store class
+     * @param poMDMD Metatada store class
+     * @return true on success or false
+     */
+    virtual bool FillMetadata(GDALMultiDomainMetadata* poMDMD);
+    /**
+      * @brief Determine whether the input parameter correspond to the particular 
+      *        provider of remote sensing data completely
+      * @return True if all needed sources files found
+      */
+    virtual const bool HasRequiredFiles() const = 0;
+    /**
+     * @brief Get metadata file names. The caller become owner of returned list
+     *        and have to free it via CSLDestroy.
+     * @return A file name list
+     */
+    virtual char** GetMetadataFiles() const = 0;
+protected:
+    /**
+     * @brief Load metadata to the correspondent IMD, RPB, IMAGERY and DEFAULT
+     *        domains
+     */
+    virtual void LoadMetadata();
+    /**
+     * @brief Convert string like 2012-02-25T00:25:59.9440000Z to time
+     * @param pszDateTime String to convert
+     * @return value in time_t
+     */
+    virtual const time_t GetAcquisitionTimeFromString(const char* pszDateTime);
+    /**
+     * @brief ReadXMLToList Transform xml to list of NULL terminated name=value
+     *        strings
+     * @param psNode A xml node to process
+     * @param papszList A list to fill with name=value strings
+     * @param pszName A name of parent node. For root xml node should be empty.
+     *        If name is not empty, the sibling nodes will not proceed
+     * @return An input list filled with values
+     */
+    virtual char** ReadXMLToList(CPLXMLNode* psNode, char** papszList,
+                         const char* pszName = "");
+    /**
+     * @brief AddXMLNameValueToList Execute from ReadXMLToList to add name and
+     *        value to list. One can override this function for special
+     *        processing input values before add to list.
+     * @param papszList A list to fill with name=value strings
+     * @param pszName A name to add
+     * @param pszValue A value to add
+     * @return An input list filled with values
+     */
+    virtual char** AddXMLNameValueToList(char** papszList, const char *pszName,
+                                         const char *pszValue);
+protected:
+    char **m_papszIMDMD;
+    char **m_papszRPCMD;
+    char **m_papszIMAGERYMD;
+    char **m_papszDEFAULTMD;
+    bool m_bIsMetadataLoad; 
+};
+
+/**
+ * The metadata reader main class.
+ * The main purpose of this class is to provide an correspondent reader 
+ * for provided path. 
+ */
+class CPL_DLL GDALMDReaderManager{
+public:
+    GDALMDReaderManager();
+    virtual ~GDALMDReaderManager();
+    
+    /**
+     * @brief Try to detect metadata reader correspondent to the provided 
+     *        datasource path 
+     * @param pszPath a path to GDALDataset 
+     * @param papszSiblingFiles file list for metadata search purposes
+     * @param nType a preferable reader type (may be the OR of MDReaders)
+     * @return an appropriate reader or NULL if no such reader or error.
+     * The pointer delete by the GDALMDReaderManager, so the user have not
+     * delete it.
+     */
+    virtual GDALMDReaderBase* GetReader(const char *pszPath, 
+                                        char **papszSiblingFiles, 
+                                        GUInt32 nType = MDR_ANY);
+protected:
+    GDALMDReaderBase *m_pReader;
+};
+
+// misc
+CPLString CPLStrip(const CPLString& osString, const char cChar);
+CPLString CPLStripQuotes(const CPLString& osString);
+char** GDALLoadRPBFile( const CPLString& osFilePath );
+char** GDALLoadRPCFile( const CPLString& osFilePath );
+char** GDALLoadIMDFile( const CPLString& osFilePath );
+const bool GDALCheckFileHeader(const CPLString& soFilePath,
+                               const char * pszTestString,
+                               int nBufferSize = 256);
+
+CPLErr GDALWriteRPBFile( const char *pszFilename, char **papszMD );
+CPLErr GDALWriteRPCTXTFile( const char *pszFilename, char **papszMD );
+CPLErr GDALWriteIMDFile( const char *pszFilename, char **papszMD );
+
+#endif //GDAL_MDREADER_H_INCLUDED

+ 316 - 0
libpq_test/include/gdal_pam.h

@@ -0,0 +1,316 @@
+/******************************************************************************
+ * $Id: gdal_pam.h 28899 2015-04-14 09:27:00Z rouault $
+ *
+ * Project:  GDAL Core
+ * Purpose:  Declaration for Peristable Auxiliary Metadata classes.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_PAM_H_INCLUDED
+#define GDAL_PAM_H_INCLUDED
+
+#include "gdal_priv.h"
+
+class GDALPamRasterBand;
+
+/* Clone Info Flags */
+
+#define GCIF_GEOTRANSFORM       0x01
+#define GCIF_PROJECTION         0x02
+#define GCIF_METADATA           0x04
+#define GCIF_GCPS               0x08
+
+#define GCIF_NODATA             0x001000
+#define GCIF_CATEGORYNAMES      0x002000
+#define GCIF_MINMAX             0x004000
+#define GCIF_SCALEOFFSET        0x008000
+#define GCIF_UNITTYPE           0x010000
+#define GCIF_COLORTABLE         0x020000
+#define GCIF_COLORINTERP        0x020000
+#define GCIF_BAND_METADATA      0x040000
+#define GCIF_RAT                0x080000
+#define GCIF_MASK               0x100000
+#define GCIF_BAND_DESCRIPTION   0x200000
+
+#define GCIF_ONLY_IF_MISSING    0x10000000
+#define GCIF_PROCESS_BANDS      0x20000000
+
+#define GCIF_PAM_DEFAULT        (GCIF_GEOTRANSFORM | GCIF_PROJECTION |     \
+                                 GCIF_METADATA | GCIF_GCPS |               \
+                                 GCIF_NODATA | GCIF_CATEGORYNAMES |        \
+                                 GCIF_MINMAX | GCIF_SCALEOFFSET |          \
+                                 GCIF_UNITTYPE | GCIF_COLORTABLE |         \
+                                 GCIF_COLORINTERP | GCIF_BAND_METADATA |   \
+                                 GCIF_RAT | GCIF_MASK |                    \
+                                 GCIF_ONLY_IF_MISSING | GCIF_PROCESS_BANDS|\
+                                 GCIF_BAND_DESCRIPTION) 
+
+/* GDAL PAM Flags */
+/* ERO 2011/04/13 : GPF_AUXMODE seems to be unimplemented */
+#define GPF_DIRTY		0x01  // .pam file needs to be written on close
+#define GPF_TRIED_READ_FAILED   0x02  // no need to keep trying to read .pam.
+#define GPF_DISABLED            0x04  // do not try any PAM stuff. 
+#define GPF_AUXMODE             0x08  // store info in .aux (HFA) file.
+#define GPF_NOSAVE              0x10  // do not try to save pam info.
+
+/* ==================================================================== */
+/*      GDALDatasetPamInfo                                              */
+/*                                                                      */
+/*      We make these things a seperate structure of information        */
+/*      primarily so we can modify it without altering the size of      */
+/*      the GDALPamDataset.  It is an effort to reduce ABI churn for    */
+/*      driver plugins.                                                 */
+/* ==================================================================== */
+class GDALDatasetPamInfo
+{
+public:
+    char        *pszPamFilename;
+
+    char	*pszProjection;
+
+    int         bHaveGeoTransform;
+    double      adfGeoTransform[6];
+
+    int         nGCPCount;
+    GDAL_GCP   *pasGCPList;
+    char       *pszGCPProjection;
+
+    CPLString   osPhysicalFilename;
+    CPLString   osSubdatasetName;
+    CPLString   osAuxFilename;
+
+    int         bHasMetadata;
+};
+
+/* ******************************************************************** */
+/*                           GDALPamDataset                             */
+/* ******************************************************************** */
+
+class CPL_DLL GDALPamDataset : public GDALDataset
+{
+    friend class GDALPamRasterBand;
+
+  private:
+    int IsPamFilenameAPotentialSiblingFile();
+
+  protected:
+                GDALPamDataset(void);
+
+    int         nPamFlags;
+    GDALDatasetPamInfo *psPam;
+
+    virtual CPLXMLNode *SerializeToXML( const char *);
+    virtual CPLErr      XMLInit( CPLXMLNode *, const char * );
+    
+    virtual CPLErr TryLoadXML(char **papszSiblingFiles = NULL);
+    virtual CPLErr TrySaveXML();
+
+    CPLErr  TryLoadAux(char **papszSiblingFiles = NULL);
+    CPLErr  TrySaveAux();
+
+    virtual const char *BuildPamFilename();
+
+    void   PamInitialize();
+    void   PamClear();
+
+    void   SetPhysicalFilename( const char * );
+    const char *GetPhysicalFilename();
+    void   SetSubdatasetName( const char *);
+    const char *GetSubdatasetName();
+
+  public:
+    virtual     ~GDALPamDataset();
+
+    virtual void FlushCache(void);
+
+    virtual const char *GetProjectionRef(void);
+    virtual CPLErr SetProjection( const char * );
+
+    virtual CPLErr GetGeoTransform( double * );
+    virtual CPLErr SetGeoTransform( double * );
+
+    virtual int    GetGCPCount();
+    virtual const char *GetGCPProjection();
+    virtual const GDAL_GCP *GetGCPs();
+    virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
+                            const char *pszGCPProjection );
+
+    virtual CPLErr      SetMetadata( char ** papszMetadata,
+                                     const char * pszDomain = "" );
+    virtual CPLErr      SetMetadataItem( const char * pszName,
+                                         const char * pszValue,
+                                         const char * pszDomain = "" );
+    virtual char      **GetMetadata( const char * pszDomain = "" );
+    virtual const char *GetMetadataItem( const char * pszName,
+                                         const char * pszDomain = "" );
+
+    virtual char      **GetFileList(void);
+
+    virtual CPLErr CloneInfo( GDALDataset *poSrcDS, int nCloneInfoFlags );
+
+    virtual CPLErr IBuildOverviews( const char *pszResampling, 
+                                    int nOverviews, int *panOverviewList, 
+                                    int nListBands, int *panBandList,
+                                    GDALProgressFunc pfnProgress, 
+                                    void * pProgressData );
+
+
+    // "semi private" methods.
+    void   MarkPamDirty() { nPamFlags |= GPF_DIRTY; }
+    GDALDatasetPamInfo *GetPamInfo() { return psPam; }
+    int    GetPamFlags() { return nPamFlags; }
+    void   SetPamFlags(int nValue ) { nPamFlags = nValue; }
+};
+
+/* ==================================================================== */
+/*      GDALRasterBandPamInfo                                           */
+/*                                                                      */
+/*      We make these things a seperate structure of information        */
+/*      primarily so we can modify it without altering the size of      */
+/*      the GDALPamDataset.  It is an effort to reduce ABI churn for    */
+/*      driver plugins.                                                 */
+/* ==================================================================== */
+typedef struct {
+    GDALPamDataset *poParentDS;
+
+    int            bNoDataValueSet;
+    double         dfNoDataValue;
+
+    GDALColorTable *poColorTable;
+
+    GDALColorInterp eColorInterp;
+
+    char           *pszUnitType;
+    char           **papszCategoryNames;
+    
+    double         dfOffset;
+    double         dfScale;
+
+    int            bHaveMinMax;
+    double         dfMin;
+    double         dfMax;
+
+    int            bHaveStats;
+    double         dfMean;
+    double         dfStdDev;
+
+    CPLXMLNode     *psSavedHistograms;
+
+    GDALRasterAttributeTable *poDefaultRAT;
+
+} GDALRasterBandPamInfo;
+
+/* ******************************************************************** */
+/*                          GDALPamRasterBand                           */
+/* ******************************************************************** */
+class CPL_DLL GDALPamRasterBand : public GDALRasterBand
+{
+    friend class GDALPamDataset;
+
+  protected:
+
+    virtual CPLXMLNode *SerializeToXML( const char *pszVRTPath );
+    virtual CPLErr      XMLInit( CPLXMLNode *, const char * );
+    
+    void   PamInitialize();
+    void   PamClear();
+
+    GDALRasterBandPamInfo *psPam;
+
+  public:
+                GDALPamRasterBand();
+    virtual     ~GDALPamRasterBand();
+
+    virtual void        SetDescription( const char * );
+
+    virtual CPLErr SetNoDataValue( double );
+    virtual double GetNoDataValue( int *pbSuccess = NULL );
+
+    virtual CPLErr SetColorTable( GDALColorTable * ); 
+    virtual GDALColorTable *GetColorTable();
+
+    virtual CPLErr SetColorInterpretation( GDALColorInterp );
+    virtual GDALColorInterp GetColorInterpretation();
+
+    virtual const char *GetUnitType();
+    CPLErr SetUnitType( const char * ); 
+
+    virtual char **GetCategoryNames();
+    virtual CPLErr SetCategoryNames( char ** );
+
+    virtual double GetOffset( int *pbSuccess = NULL );
+    CPLErr SetOffset( double );
+    virtual double GetScale( int *pbSuccess = NULL );
+    CPLErr SetScale( double );
+
+    virtual CPLErr  GetHistogram( double dfMin, double dfMax,
+                          int nBuckets, GUIntBig * panHistogram,
+                          int bIncludeOutOfRange, int bApproxOK,
+                          GDALProgressFunc, void *pProgressData );
+
+    virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
+                                        int *pnBuckets, GUIntBig ** ppanHistogram,
+                                        int bForce,
+                                        GDALProgressFunc, void *pProgressData);
+
+    virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
+                                        int nBuckets, GUIntBig *panHistogram );
+
+    virtual CPLErr      SetMetadata( char ** papszMetadata,
+                                     const char * pszDomain = "" );
+    virtual CPLErr      SetMetadataItem( const char * pszName,
+                                         const char * pszValue,
+                                         const char * pszDomain = "" );
+
+    virtual GDALRasterAttributeTable *GetDefaultRAT();
+    virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * );
+
+    // new in GDALPamRasterBand. 
+    virtual CPLErr CloneInfo( GDALRasterBand *poSrcBand, int nCloneInfoFlags );
+
+    // "semi private" methods.
+    GDALRasterBandPamInfo *GetPamInfo() { return psPam; }
+};
+
+// These are mainly helper functions for internal use.
+int CPL_DLL PamParseHistogram( CPLXMLNode *psHistItem, 
+                               double *pdfMin, double *pdfMax, 
+                               int *pnBuckets, GUIntBig **ppanHistogram, 
+                               int *pbIncludeOutOfRange, int *pbApproxOK );
+CPLXMLNode CPL_DLL *
+PamFindMatchingHistogram( CPLXMLNode *psSavedHistograms,
+                          double dfMin, double dfMax, int nBuckets, 
+                          int bIncludeOutOfRange, int bApproxOK );
+CPLXMLNode CPL_DLL *
+PamHistogramToXMLTree( double dfMin, double dfMax,
+                       int nBuckets, GUIntBig * panHistogram,
+                       int bIncludeOutOfRange, int bApprox );
+
+// For managing the proxy file database.
+const char CPL_DLL * PamGetProxy( const char * );
+const char CPL_DLL * PamAllocateProxy( const char * );
+const char CPL_DLL * PamDeallocateProxy( const char * );
+void CPL_DLL PamCleanProxyDB( void );
+
+#endif /* ndef GDAL_PAM_H_INCLUDED */

+ 1237 - 0
libpq_test/include/gdal_priv.h

@@ -0,0 +1,1237 @@
+/******************************************************************************
+ * $Id: gdal_priv.h 29284 2015-06-03 13:26:10Z rouault $
+ *
+ * Name:     gdal_priv.h
+ * Project:  GDAL Core
+ * Purpose:  GDAL Core C++/Private declarations. 
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 1998, Frank Warmerdam
+ * Copyright (c) 2007-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_PRIV_H_INCLUDED
+#define GDAL_PRIV_H_INCLUDED
+
+/* -------------------------------------------------------------------- */
+/*      Predeclare various classes before pulling in gdal.h, the        */
+/*      public declarations.                                            */
+/* -------------------------------------------------------------------- */
+class GDALMajorObject;
+class GDALDataset;
+class GDALRasterBand;
+class GDALDriver;
+class GDALRasterAttributeTable;
+class GDALProxyDataset;
+class GDALProxyRasterBand;
+class GDALAsyncReader;
+
+/* -------------------------------------------------------------------- */
+/*      Pull in the public declarations.  This gets the C apis, and     */
+/*      also various constants.  However, we will still get to          */
+/*      provide the real class definitions for the GDAL classes.        */
+/* -------------------------------------------------------------------- */
+
+#include "gdal.h"
+#include "gdal_frmts.h"
+#include "cpl_vsi.h"
+#include "cpl_conv.h"
+#include "cpl_string.h"
+#include "cpl_minixml.h"
+#include "cpl_multiproc.h"
+#include <vector>
+#include <map>
+#include "ogr_core.h"
+
+#define GMO_VALID                0x0001
+#define GMO_IGNORE_UNIMPLEMENTED 0x0002
+#define GMO_SUPPORT_MD           0x0004
+#define GMO_SUPPORT_MDMD         0x0008
+#define GMO_MD_DIRTY             0x0010
+#define GMO_PAM_CLASS            0x0020
+
+/************************************************************************/
+/*                       GDALMultiDomainMetadata                        */
+/************************************************************************/
+
+class CPL_DLL GDALMultiDomainMetadata
+{
+private:
+    char **papszDomainList;
+    CPLStringList **papoMetadataLists;
+
+public:
+    GDALMultiDomainMetadata();
+    ~GDALMultiDomainMetadata();
+
+    int         XMLInit( CPLXMLNode *psMetadata, int bMerge );
+    CPLXMLNode  *Serialize();
+
+    char      **GetDomainList() { return papszDomainList; }
+
+    char      **GetMetadata( const char * pszDomain = "" );
+    CPLErr      SetMetadata( char ** papszMetadata,
+                             const char * pszDomain = "" );
+    const char *GetMetadataItem( const char * pszName,
+                                 const char * pszDomain = "" );
+    CPLErr      SetMetadataItem( const char * pszName,
+                                 const char * pszValue,
+                                 const char * pszDomain = "" );
+
+    void        Clear();
+};
+
+/* ******************************************************************** */
+/*                           GDALMajorObject                            */
+/*                                                                      */
+/*      Base class providing metadata, description and other            */
+/*      services shared by major objects.                               */
+/* ******************************************************************** */
+
+//! Object with metadata.
+
+class CPL_DLL GDALMajorObject
+{
+  protected:
+    int                 nFlags; // GMO_* flags. 
+    CPLString           sDescription;
+    GDALMultiDomainMetadata oMDMD;
+    
+    char               **BuildMetadataDomainList(char** papszList, int bCheckNonEmpty, ...) CPL_NULL_TERMINATED;
+    
+  public:
+                        GDALMajorObject();
+    virtual            ~GDALMajorObject();
+
+    int                 GetMOFlags();
+    void                SetMOFlags(int nFlagsIn);
+                        
+    virtual const char *GetDescription() const;
+    virtual void        SetDescription( const char * );
+
+    virtual char      **GetMetadataDomainList();
+    
+    virtual char      **GetMetadata( const char * pszDomain = "" );
+    virtual CPLErr      SetMetadata( char ** papszMetadata,
+                                     const char * pszDomain = "" );
+    virtual const char *GetMetadataItem( const char * pszName,
+                                         const char * pszDomain = "" );
+    virtual CPLErr      SetMetadataItem( const char * pszName,
+                                         const char * pszValue,
+                                         const char * pszDomain = "" );
+};
+
+/* ******************************************************************** */
+/*                         GDALDefaultOverviews                         */
+/* ******************************************************************** */
+class CPL_DLL GDALDefaultOverviews
+{
+    friend class GDALDataset;
+
+    GDALDataset *poDS;
+    GDALDataset *poODS;
+    
+    CPLString   osOvrFilename;
+
+    int         bOvrIsAux;
+
+    int         bCheckedForMask;
+    int         bOwnMaskDS;
+    GDALDataset *poMaskDS;
+
+    // for "overview datasets" we record base level info so we can 
+    // find our way back to get overview masks.
+    GDALDataset *poBaseDS;
+
+    // Stuff for deferred initialize/overviewscans...
+    bool        bCheckedForOverviews;
+    void        OverviewScan();
+    char       *pszInitName;
+    int         bInitNameIsOVR;
+    char      **papszInitSiblingFiles;
+
+  public:
+               GDALDefaultOverviews();
+               ~GDALDefaultOverviews();
+
+    void       Initialize( GDALDataset *poDSIn, const char *pszName = NULL, 
+                           char **papszSiblingFiles = NULL,
+                           int bNameIsOVR = FALSE );
+
+    int        IsInitialized();
+
+    int        CloseDependentDatasets();
+
+    // Overview Related
+
+    int        GetOverviewCount(int);
+    GDALRasterBand *GetOverview(int,int);
+
+    CPLErr     BuildOverviews( const char * pszBasename,
+                               const char * pszResampling, 
+                               int nOverviews, int * panOverviewList,
+                               int nBands, int * panBandList,
+                               GDALProgressFunc pfnProgress,
+                               void *pProgressData );
+
+    CPLErr     BuildOverviewsSubDataset( const char * pszPhysicalFile,
+                                         const char * pszResampling, 
+                                         int nOverviews, int * panOverviewList,
+                                         int nBands, int * panBandList,
+                                         GDALProgressFunc pfnProgress,
+                                         void *pProgressData );
+
+    CPLErr     CleanOverviews();
+
+    // Mask Related
+
+    CPLErr     CreateMaskBand( int nFlags, int nBand = -1 );
+    GDALRasterBand *GetMaskBand( int nBand );
+    int        GetMaskFlags( int nBand );
+
+    int        HaveMaskFile( char **papszSiblings = NULL, 
+                             const char *pszBasename = NULL );
+
+    char**     GetSiblingFiles() { return papszInitSiblingFiles; }
+};
+
+/* ******************************************************************** */
+/*                             GDALOpenInfo                             */
+/*                                                                      */
+/*      Structure of data about dataset for open functions.             */
+/* ******************************************************************** */
+
+class CPL_DLL GDALOpenInfo
+{
+    int         bHasGotSiblingFiles;
+    char        **papszSiblingFiles;
+    int         nHeaderBytesTried;
+
+  public:
+                GDALOpenInfo( const char * pszFile, int nOpenFlagsIn,
+                              char **papszSiblingFiles = NULL );
+                ~GDALOpenInfo( void );
+
+    char        *pszFilename;
+    char**      papszOpenOptions;
+
+    GDALAccess  eAccess;
+    int         nOpenFlags;
+
+    int         bStatOK;
+    int         bIsDirectory;
+
+    VSILFILE   *fpL;
+
+    int         nHeaderBytes;
+    GByte       *pabyHeader;
+
+    int         TryToIngest(int nBytes);
+    char      **GetSiblingFiles();
+};
+
+/* ******************************************************************** */
+/*                             GDALDataset                              */
+/* ******************************************************************** */
+
+class OGRLayer;
+class OGRGeometry;
+class OGRSpatialReference;
+class OGRStyleTable;
+class swq_select;
+class swq_select_parse_options;
+typedef struct GDALSQLParseInfo GDALSQLParseInfo;
+
+#ifdef DETECT_OLD_IRASTERIO
+typedef void signature_changed;
+#endif
+
+#ifdef GDAL_COMPILATION
+#define OPTIONAL_OUTSIDE_GDAL(val)
+#else
+#define OPTIONAL_OUTSIDE_GDAL(val) = val
+#endif
+
+//! A set of associated raster bands, usually from one file.
+
+class CPL_DLL GDALDataset : public GDALMajorObject
+{
+    friend GDALDatasetH CPL_STDCALL GDALOpenEx( const char* pszFilename,
+                                 unsigned int nOpenFlags,
+                                 const char* const* papszAllowedDrivers,
+                                 const char* const* papszOpenOptions,
+                                 const char* const* papszSiblingFiles );
+    friend void CPL_STDCALL GDALClose( GDALDatasetH hDS );
+
+    friend class GDALDriver;
+    friend class GDALDefaultOverviews;
+    friend class GDALProxyDataset;
+    friend class GDALDriverManager;
+    
+    void AddToDatasetOpenList();
+
+  protected:
+    GDALDriver  *poDriver;
+    GDALAccess  eAccess;
+
+    // Stored raster information.
+    int         nRasterXSize;
+    int         nRasterYSize;
+    int         nBands;
+    GDALRasterBand **papoBands;
+
+    int         bForceCachedIO;
+
+    int         nRefCount;
+    int         bShared;
+    GByte       bIsInternal;
+    GByte       bSuppressOnClose;
+    GByte       bReserved1;
+    GByte       bReserved2;
+
+                GDALDataset(void);
+
+    void        RasterInitialize( int, int );
+    void        SetBand( int, GDALRasterBand * );
+
+    GDALDefaultOverviews oOvManager;
+    
+    virtual CPLErr IBuildOverviews( const char *, int, int *,
+                                    int, int *, GDALProgressFunc, void * );
+
+#ifdef DETECT_OLD_IRASTERIO
+    virtual signature_changed IRasterIO( GDALRWFlag, int, int, int, int,
+                              void *, int, int, GDALDataType,
+                              int, int *, int, int, int ) {};
+#endif
+
+    virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
+                              void *, int, int, GDALDataType,
+                              int, int *, GSpacing, GSpacing, GSpacing,
+                              GDALRasterIOExtraArg* psExtraArg );
+
+    CPLErr BlockBasedRasterIO( GDALRWFlag, int, int, int, int,
+                               void *, int, int, GDALDataType,
+                               int, int *, GSpacing, GSpacing, GSpacing,
+                               GDALRasterIOExtraArg* psExtraArg );
+    void   BlockBasedFlushCache();
+
+    CPLErr ValidateRasterIOOrAdviseReadParameters(
+                               const char* pszCallingFunc,
+                               int* pbStopProcessingOnCENone,
+                               int nXOff, int nYOff, int nXSize, int nYSize,
+                               int nBufXSize, int nBufYSize, 
+                               int nBandCount, int *panBandMap);
+
+    virtual int         CloseDependentDatasets();
+    
+    int                 ValidateLayerCreationOptions( const char* const* papszLCO );
+    
+    char            **papszOpenOptions;
+
+    friend class GDALRasterBand;
+    
+    int                 EnterReadWrite(GDALRWFlag eRWFlag);
+    void                LeaveReadWrite();
+    
+    
+  public:
+    virtual     ~GDALDataset();
+
+    int         GetRasterXSize( void );
+    int         GetRasterYSize( void );
+    int         GetRasterCount( void );
+    GDALRasterBand *GetRasterBand( int );
+
+    virtual void FlushCache(void);
+
+    virtual const char *GetProjectionRef(void);
+    virtual CPLErr SetProjection( const char * );
+
+    virtual CPLErr GetGeoTransform( double * );
+    virtual CPLErr SetGeoTransform( double * );
+
+    virtual CPLErr        AddBand( GDALDataType eType, 
+                                   char **papszOptions=NULL );
+
+    virtual void *GetInternalHandle( const char * );
+    virtual GDALDriver *GetDriver(void);
+    virtual char      **GetFileList(void);
+    
+    virtual     const char* GetDriverName();
+    
+    virtual int    GetGCPCount();
+    virtual const char *GetGCPProjection();
+    virtual const GDAL_GCP *GetGCPs();
+    virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
+                            const char *pszGCPProjection );
+
+    virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
+                               int nBufXSize, int nBufYSize, 
+                               GDALDataType eDT, 
+                               int nBandCount, int *panBandList,
+                               char **papszOptions );
+
+    virtual CPLErr          CreateMaskBand( int nFlagsIn );
+
+    virtual GDALAsyncReader* 
+        BeginAsyncReader(int nXOff, int nYOff, int nXSize, int nYSize,
+                         void *pBuf, int nBufXSize, int nBufYSize,
+                         GDALDataType eBufType,
+                         int nBandCount, int* panBandMap,
+                         int nPixelSpace, int nLineSpace, int nBandSpace,
+                         char **papszOptions);
+    virtual void EndAsyncReader(GDALAsyncReader *);
+
+    CPLErr      RasterIO( GDALRWFlag, int, int, int, int,
+                          void *, int, int, GDALDataType,
+                          int, int *, GSpacing, GSpacing, GSpacing,
+                          GDALRasterIOExtraArg* psExtraArg
+#ifndef DOXYGEN_SKIP
+                          OPTIONAL_OUTSIDE_GDAL(NULL)
+#endif
+                          );
+
+    int           Reference();
+    int           Dereference();
+    GDALAccess    GetAccess() { return eAccess; }
+
+    int           GetShared();
+    void          MarkAsShared();
+    
+    void          MarkSuppressOnClose() { bSuppressOnClose = TRUE; }
+    
+    char        **GetOpenOptions() { return papszOpenOptions; }
+
+    static GDALDataset **GetOpenDatasets( int *pnDatasetCount );
+
+    CPLErr BuildOverviews( const char *, int, int *,
+                           int, int *, GDALProgressFunc, void * );
+
+    void ReportError(CPLErr eErrClass, int err_no, const char *fmt, ...)  CPL_PRINT_FUNC_FORMAT (4, 5);
+
+private:
+    CPLMutex        *m_hMutex;
+
+    OGRLayer*       BuildLayerFromSelectInfo(swq_select* psSelectInfo,
+                                             OGRGeometry *poSpatialFilter,
+                                             const char *pszDialect,
+                                             swq_select_parse_options* poSelectParseOptions);
+
+  public:
+
+    virtual int         GetLayerCount();
+    virtual OGRLayer    *GetLayer(int);
+    virtual OGRLayer    *GetLayerByName(const char *);
+    virtual OGRErr      DeleteLayer(int);
+
+    virtual int         TestCapability( const char * );
+
+    virtual OGRLayer   *CreateLayer( const char *pszName, 
+                                     OGRSpatialReference *poSpatialRef = NULL,
+                                     OGRwkbGeometryType eGType = wkbUnknown,
+                                     char ** papszOptions = NULL );
+    virtual OGRLayer   *CopyLayer( OGRLayer *poSrcLayer, 
+                                   const char *pszNewName, 
+                                   char **papszOptions = NULL );
+
+    virtual OGRStyleTable *GetStyleTable();
+    virtual void        SetStyleTableDirectly( OGRStyleTable *poStyleTable );
+                            
+    virtual void        SetStyleTable(OGRStyleTable *poStyleTable);
+
+    virtual OGRLayer *  ExecuteSQL( const char *pszStatement,
+                                    OGRGeometry *poSpatialFilter,
+                                    const char *pszDialect );
+    virtual void        ReleaseResultSet( OGRLayer * poResultsSet );
+
+    int                 GetRefCount() const;
+    int                 GetSummaryRefCount() const;
+    OGRErr              Release();
+
+    virtual OGRErr      StartTransaction(int bForce=FALSE);
+    virtual OGRErr      CommitTransaction();
+    virtual OGRErr      RollbackTransaction();
+    
+    static int          IsGenericSQLDialect(const char* pszDialect);
+    
+    // Semi-public methods. Only to be used by in-tree drivers.
+    GDALSQLParseInfo*   BuildParseInfo(swq_select* psSelectInfo,
+                                       swq_select_parse_options* poSelectParseOptions);
+    void                DestroyParseInfo(GDALSQLParseInfo* psParseInfo );
+    OGRLayer *          ExecuteSQL( const char *pszStatement,
+                                    OGRGeometry *poSpatialFilter,
+                                    const char *pszDialect,
+                                    swq_select_parse_options* poSelectParseOptions);
+
+  protected:
+
+    virtual OGRLayer   *ICreateLayer( const char *pszName, 
+                                     OGRSpatialReference *poSpatialRef = NULL,
+                                     OGRwkbGeometryType eGType = wkbUnknown,
+                                     char ** papszOptions = NULL );
+
+    OGRErr              ProcessSQLCreateIndex( const char * );
+    OGRErr              ProcessSQLDropIndex( const char * );
+    OGRErr              ProcessSQLDropTable( const char * );
+    OGRErr              ProcessSQLAlterTableAddColumn( const char * );
+    OGRErr              ProcessSQLAlterTableDropColumn( const char * );
+    OGRErr              ProcessSQLAlterTableAlterColumn( const char * );
+    OGRErr              ProcessSQLAlterTableRenameColumn( const char * );
+
+    OGRStyleTable      *m_poStyleTable;
+};
+
+/* ******************************************************************** */
+/*                           GDALRasterBlock                            */
+/* ******************************************************************** */
+
+//! A single raster block in the block cache.
+
+class CPL_DLL GDALRasterBlock
+{
+    GDALDataType        eType;
+    
+    int                 bDirty;
+    int                 nLockCount;
+
+    int                 nXOff;
+    int                 nYOff;
+       
+    int                 nXSize;
+    int                 nYSize;
+    
+    void                *pData;
+
+    GDALRasterBand      *poBand;
+    
+    GDALRasterBlock     *poNext;
+    GDALRasterBlock     *poPrevious;
+    
+    int                  bMustDetach;
+    
+    void        Touch_unlocked( void );
+    void        Detach_unlocked( void );
+
+  public:
+                GDALRasterBlock( GDALRasterBand *, int, int );
+    virtual     ~GDALRasterBlock();
+
+    CPLErr      Internalize( void );
+    void        Touch( void );      
+    void        MarkDirty( void );  
+    void        MarkClean( void );
+    void        AddLock( void ) { nLockCount++; }
+    void        DropLock( void ) { nLockCount--; }
+    void        Detach();
+
+    CPLErr      Write();
+
+    GDALDataType GetDataType() { return eType; }
+    int         GetXOff() { return nXOff; }
+    int         GetYOff() { return nYOff; }
+    int         GetXSize() { return nXSize; }
+    int         GetYSize() { return nYSize; }
+    int         GetDirty() { return bDirty; }
+    int         GetLockCount() { return nLockCount; }
+
+    void        *GetDataRef( void ) { return pData; }
+    int          GetBlockSize() { return nXSize * nYSize * (GDALGetDataTypeSize(eType) / 8); }
+
+    /// @brief Accessor to source GDALRasterBand object.
+    /// @return source raster band of the raster block.
+    GDALRasterBand *GetBand() { return poBand; }
+
+    static void FlushDirtyBlocks();
+    static int  FlushCacheBlock(int bDirtyBlocksOnly = FALSE);
+    static void Verify();
+
+    static int  SafeLockBlock( GDALRasterBlock ** );
+    
+    /* Should only be called by GDALDestroyDriverManager() */
+    static void DestroyRBMutex();
+};
+
+/* ******************************************************************** */
+/*                             GDALColorTable                           */
+/* ******************************************************************** */
+
+/*! A color table / palette. */
+
+class CPL_DLL GDALColorTable
+{
+    GDALPaletteInterp eInterp;
+
+    std::vector<GDALColorEntry> aoEntries;
+
+public:
+                GDALColorTable( GDALPaletteInterp = GPI_RGB );
+                ~GDALColorTable();
+
+    GDALColorTable *Clone() const;
+    int             IsSame(const GDALColorTable* poOtherCT) const;
+
+    GDALPaletteInterp GetPaletteInterpretation() const;
+
+    int           GetColorEntryCount() const;
+    const GDALColorEntry *GetColorEntry( int ) const;
+    int           GetColorEntryAsRGB( int, GDALColorEntry * ) const;
+    void          SetColorEntry( int, const GDALColorEntry * );
+    int           CreateColorRamp( int, const GDALColorEntry * ,
+                                   int, const GDALColorEntry * );
+};
+
+/* ******************************************************************** */
+/*                            GDALRasterBand                            */
+/* ******************************************************************** */
+
+//! A single raster band (or channel).
+
+class CPL_DLL GDALRasterBand : public GDALMajorObject
+{
+  private:
+    CPLErr eFlushBlockErr;
+
+    void           SetFlushBlockErr( CPLErr eErr );
+
+    friend class GDALRasterBlock;
+    CPLErr         UnreferenceBlock( int nXBlockOff, int nYBlockOff );
+
+  protected:
+    GDALDataset *poDS;
+    int         nBand; /* 1 based */
+
+    int         nRasterXSize;
+    int         nRasterYSize;
+    
+    GDALDataType eDataType;
+    GDALAccess  eAccess;
+
+    /* stuff related to blocking, and raster cache */
+    int         nBlockXSize;
+    int         nBlockYSize;
+    int         nBlocksPerRow;
+    int         nBlocksPerColumn;
+
+    int         bSubBlockingActive;
+    int         nSubBlocksPerRow;
+    int         nSubBlocksPerColumn;
+    GDALRasterBlock **papoBlocks;
+
+    int         nBlockReads;
+    int         bForceCachedIO;
+
+    GDALRasterBand *poMask;
+    bool        bOwnMask;
+    int         nMaskFlags;
+
+    void        InvalidateMaskBand();
+
+    friend class GDALDataset;
+    friend class GDALProxyRasterBand;
+    friend class GDALDefaultOverviews;
+
+    CPLErr RasterIOResampled( GDALRWFlag, int, int, int, int,
+                              void *, int, int, GDALDataType,
+                              GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg );
+
+    int          EnterReadWrite(GDALRWFlag eRWFlag);
+    void         LeaveReadWrite();
+
+  protected:
+    virtual CPLErr IReadBlock( int, int, void * ) = 0;
+    virtual CPLErr IWriteBlock( int, int, void * );
+
+#ifdef DETECT_OLD_IRASTERIO
+    virtual signature_changed IRasterIO( GDALRWFlag, int, int, int, int,
+                              void *, int, int, GDALDataType,
+                              int, int ) {};
+#endif
+
+    virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
+                              void *, int, int, GDALDataType,
+                              GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg );
+    CPLErr         OverviewRasterIO( GDALRWFlag, int, int, int, int,
+                                     void *, int, int, GDALDataType,
+                                     GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg );
+
+    int            InitBlockInfo();
+
+    CPLErr         AdoptBlock( int, int, GDALRasterBlock * );
+    GDALRasterBlock *TryGetLockedBlockRef( int nXBlockOff, int nYBlockYOff );
+
+  public:
+                GDALRasterBand();
+                
+    virtual     ~GDALRasterBand();
+
+    int         GetXSize();
+    int         GetYSize();
+    int         GetBand();
+    GDALDataset*GetDataset();
+
+    GDALDataType GetRasterDataType( void );
+    void        GetBlockSize( int *, int * );
+    GDALAccess  GetAccess();
+    
+    CPLErr      RasterIO( GDALRWFlag, int, int, int, int,
+                          void *, int, int, GDALDataType,
+                          GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg
+#ifndef DOXYGEN_SKIP
+                          OPTIONAL_OUTSIDE_GDAL(NULL)
+#endif
+                          );
+    CPLErr      ReadBlock( int, int, void * );
+
+    CPLErr      WriteBlock( int, int, void * );
+
+    GDALRasterBlock *GetLockedBlockRef( int nXBlockOff, int nYBlockOff, 
+                                        int bJustInitialize = FALSE );
+    CPLErr      FlushBlock( int = -1, int = -1, int bWriteDirtyBlock = TRUE );
+
+    unsigned char*  GetIndexColorTranslationTo(/* const */ GDALRasterBand* poReferenceBand,
+                                               unsigned char* pTranslationTable = NULL,
+                                               int* pApproximateMatching = NULL);
+
+    // New OpengIS CV_SampleDimension stuff.
+
+    virtual CPLErr FlushCache();
+    virtual char **GetCategoryNames();
+    virtual double GetNoDataValue( int *pbSuccess = NULL );
+    virtual double GetMinimum( int *pbSuccess = NULL );
+    virtual double GetMaximum(int *pbSuccess = NULL );
+    virtual double GetOffset( int *pbSuccess = NULL );
+    virtual double GetScale( int *pbSuccess = NULL );
+    virtual const char *GetUnitType();
+    virtual GDALColorInterp GetColorInterpretation();
+    virtual GDALColorTable *GetColorTable();
+    virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
+
+    virtual CPLErr SetCategoryNames( char ** );
+    virtual CPLErr SetNoDataValue( double );
+    virtual CPLErr SetColorTable( GDALColorTable * ); 
+    virtual CPLErr SetColorInterpretation( GDALColorInterp );
+    virtual CPLErr SetOffset( double );
+    virtual CPLErr SetScale( double );
+    virtual CPLErr SetUnitType( const char * );
+
+    virtual CPLErr GetStatistics( int bApproxOK, int bForce,
+                                  double *pdfMin, double *pdfMax, 
+                                  double *pdfMean, double *padfStdDev );
+    virtual CPLErr ComputeStatistics( int bApproxOK, 
+                                      double *pdfMin, double *pdfMax, 
+                                      double *pdfMean, double *pdfStdDev,
+                                      GDALProgressFunc, void *pProgressData );
+    virtual CPLErr SetStatistics( double dfMin, double dfMax, 
+                                  double dfMean, double dfStdDev );
+    virtual CPLErr ComputeRasterMinMax( int, double* );
+
+    virtual int HasArbitraryOverviews();
+    virtual int GetOverviewCount();
+    virtual GDALRasterBand *GetOverview(int);
+    virtual GDALRasterBand *GetRasterSampleOverview( GUIntBig );
+    virtual CPLErr BuildOverviews( const char *, int, int *,
+                                   GDALProgressFunc, void * );
+
+    virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
+                               int nBufXSize, int nBufYSize, 
+                               GDALDataType eDT, char **papszOptions );
+
+    virtual CPLErr  GetHistogram( double dfMin, double dfMax,
+                          int nBuckets, GUIntBig * panHistogram,
+                          int bIncludeOutOfRange, int bApproxOK,
+                          GDALProgressFunc, void *pProgressData );
+
+    virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
+                                        int *pnBuckets, GUIntBig ** ppanHistogram,
+                                        int bForce,
+                                        GDALProgressFunc, void *pProgressData);
+    virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
+                                        int nBuckets, GUIntBig *panHistogram );
+
+    virtual GDALRasterAttributeTable *GetDefaultRAT();
+    virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * );
+
+    virtual GDALRasterBand *GetMaskBand();
+    virtual int             GetMaskFlags();
+    virtual CPLErr          CreateMaskBand( int nFlagsIn );
+
+    virtual CPLVirtualMem  *GetVirtualMemAuto( GDALRWFlag eRWFlag,
+                                               int *pnPixelSpace,
+                                               GIntBig *pnLineSpace,
+                                               char **papszOptions );
+
+    void ReportError(CPLErr eErrClass, int err_no, const char *fmt, ...)  CPL_PRINT_FUNC_FORMAT (4, 5);
+};
+
+/* ******************************************************************** */
+/*                         GDALAllValidMaskBand                         */
+/* ******************************************************************** */
+
+class CPL_DLL GDALAllValidMaskBand : public GDALRasterBand
+{
+  protected:
+    virtual CPLErr IReadBlock( int, int, void * );
+
+  public:
+                GDALAllValidMaskBand( GDALRasterBand * );
+    virtual     ~GDALAllValidMaskBand();
+
+    virtual GDALRasterBand *GetMaskBand();
+    virtual int             GetMaskFlags();
+};
+
+/* ******************************************************************** */
+/*                         GDALNoDataMaskBand                           */
+/* ******************************************************************** */
+
+class CPL_DLL GDALNoDataMaskBand : public GDALRasterBand
+{
+    double          dfNoDataValue;
+    GDALRasterBand *poParent;
+
+  protected:
+    virtual CPLErr IReadBlock( int, int, void * );
+    virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
+                              void *, int, int, GDALDataType,
+                              GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg );
+
+  public:
+                GDALNoDataMaskBand( GDALRasterBand * );
+    virtual     ~GDALNoDataMaskBand();
+};
+
+/* ******************************************************************** */
+/*                  GDALNoDataValuesMaskBand                            */
+/* ******************************************************************** */
+
+class CPL_DLL GDALNoDataValuesMaskBand : public GDALRasterBand
+{
+    double      *padfNodataValues;
+
+  protected:
+    virtual CPLErr IReadBlock( int, int, void * );
+
+  public:
+                GDALNoDataValuesMaskBand( GDALDataset * );
+    virtual     ~GDALNoDataValuesMaskBand();
+};
+
+/* ******************************************************************** */
+/*                         GDALRescaledAlphaBand                        */
+/* ******************************************************************** */
+
+class GDALRescaledAlphaBand : public GDALRasterBand
+{
+    GDALRasterBand *poParent;
+    void           *pTemp;
+
+  protected:
+    virtual CPLErr IReadBlock( int, int, void * );
+    virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
+                              void *, int, int, GDALDataType,
+                              GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg );
+
+  public:
+                GDALRescaledAlphaBand( GDALRasterBand * );
+    virtual     ~GDALRescaledAlphaBand();
+};
+
+/* ******************************************************************** */
+/*                              GDALDriver                              */
+/* ******************************************************************** */
+
+
+/**
+ * \brief Format specific driver.
+ *
+ * An instance of this class is created for each supported format, and
+ * manages information about the format.
+ * 
+ * This roughly corresponds to a file format, though some          
+ * drivers may be gateways to many formats through a secondary     
+ * multi-library.                                                  
+ */
+
+class CPL_DLL GDALDriver : public GDALMajorObject
+{
+  public:
+                        GDALDriver();
+                        ~GDALDriver();
+
+    virtual CPLErr      SetMetadataItem( const char * pszName,
+                                 const char * pszValue,
+                                 const char * pszDomain = "" );
+
+/* -------------------------------------------------------------------- */
+/*      Public C++ methods.                                             */
+/* -------------------------------------------------------------------- */
+    GDALDataset         *Create( const char * pszName,
+                                 int nXSize, int nYSize, int nBands,
+                                 GDALDataType eType, char ** papszOptions ) CPL_WARN_UNUSED_RESULT;
+
+    CPLErr              Delete( const char * pszName );
+    CPLErr              Rename( const char * pszNewName,
+                                const char * pszOldName );
+    CPLErr              CopyFiles( const char * pszNewName,
+                                   const char * pszOldName );
+
+    GDALDataset         *CreateCopy( const char *, GDALDataset *, 
+                                     int, char **,
+                                     GDALProgressFunc pfnProgress, 
+                                     void * pProgressData ) CPL_WARN_UNUSED_RESULT;
+
+/* -------------------------------------------------------------------- */
+/*      The following are semiprivate, not intended to be accessed      */
+/*      by anyone but the formats instantiating and populating the      */
+/*      drivers.                                                        */
+/* -------------------------------------------------------------------- */
+    GDALDataset         *(*pfnOpen)( GDALOpenInfo * );
+
+    GDALDataset         *(*pfnCreate)( const char * pszName,
+                                       int nXSize, int nYSize, int nBands,
+                                       GDALDataType eType,
+                                       char ** papszOptions );
+
+    CPLErr              (*pfnDelete)( const char * pszName );
+
+    GDALDataset         *(*pfnCreateCopy)( const char *, GDALDataset *, 
+                                           int, char **,
+                                           GDALProgressFunc pfnProgress, 
+                                           void * pProgressData );
+
+    void                *pDriverData;
+
+    void                (*pfnUnloadDriver)(GDALDriver *);
+
+    /* Return 1 if the passed file is certainly recognized by the driver */
+    /* Return 0 if the passed file is certainly NOT recognized by the driver */
+    /* Return -1 if the passed file may be or may not be recognized by the driver,
+       and that a potentially costly test must be done with pfnOpen */
+    int                 (*pfnIdentify)( GDALOpenInfo * );
+
+    CPLErr              (*pfnRename)( const char * pszNewName,
+                                      const char * pszOldName );
+    CPLErr              (*pfnCopyFiles)( const char * pszNewName,
+                                         const char * pszOldName );
+
+    /* For legacy OGR drivers */
+    GDALDataset         *(*pfnOpenWithDriverArg)( GDALDriver*, GDALOpenInfo * );
+    GDALDataset         *(*pfnCreateVectorOnly)( GDALDriver*,
+                                                 const char * pszName,
+                                                 char ** papszOptions );
+    CPLErr              (*pfnDeleteDataSource)( GDALDriver*,
+                                                 const char * pszName );
+
+/* -------------------------------------------------------------------- */
+/*      Helper methods.                                                 */
+/* -------------------------------------------------------------------- */
+    GDALDataset         *DefaultCreateCopy( const char *, GDALDataset *, 
+                                            int, char **,
+                                            GDALProgressFunc pfnProgress, 
+                                            void * pProgressData ) CPL_WARN_UNUSED_RESULT;
+    static CPLErr        DefaultCopyMasks( GDALDataset *poSrcDS, 
+                                           GDALDataset *poDstDS, 
+                                           int bStrict );
+    static CPLErr       QuietDelete( const char * pszName );
+
+    CPLErr              DefaultRename( const char * pszNewName,
+                                       const char * pszOldName );
+    CPLErr              DefaultCopyFiles( const char * pszNewName,
+                                          const char * pszOldName );
+};
+
+/* ******************************************************************** */
+/*                          GDALDriverManager                           */
+/* ******************************************************************** */
+
+/**
+ * Class for managing the registration of file format drivers.
+ *
+ * Use GetGDALDriverManager() to fetch the global singleton instance of
+ * this class.
+ */
+
+class CPL_DLL GDALDriverManager : public GDALMajorObject
+{
+    int         nDrivers;
+    GDALDriver  **papoDrivers;
+    std::map<CPLString, GDALDriver*> oMapNameToDrivers;
+    
+    GDALDriver  *GetDriver_unlocked( int iDriver )
+            { return (iDriver >= 0 && iDriver < nDrivers) ? papoDrivers[iDriver] : NULL; }
+    
+    GDALDriver  *GetDriverByName_unlocked( const char * pszName )
+            { return oMapNameToDrivers[CPLString(pszName).toupper()]; }
+    
+ public:
+                GDALDriverManager();
+                ~GDALDriverManager();
+                
+    int         GetDriverCount( void );
+    GDALDriver  *GetDriver( int );
+    GDALDriver  *GetDriverByName( const char * );
+
+    int         RegisterDriver( GDALDriver * );
+    void        DeregisterDriver( GDALDriver * );
+
+    void        AutoLoadDrivers();
+    void        AutoSkipDrivers();
+};
+
+CPL_C_START
+GDALDriverManager CPL_DLL * GetGDALDriverManager( void );
+CPL_C_END
+
+/* ******************************************************************** */
+/*                          GDALAsyncReader                             */
+/* ******************************************************************** */
+
+/**
+ * Class used as a session object for asynchronous requests.  They are
+ * created with GDALDataset::BeginAsyncReader(), and destroyed with
+ * GDALDataset::EndAsyncReader().
+ */
+class CPL_DLL GDALAsyncReader
+{
+  protected:
+    GDALDataset* poDS;
+    int          nXOff;
+    int          nYOff;
+    int          nXSize;
+    int          nYSize;
+    void *       pBuf;
+    int          nBufXSize;
+    int          nBufYSize;
+    GDALDataType eBufType;
+    int          nBandCount;
+    int*         panBandMap;
+    int          nPixelSpace;
+    int          nLineSpace;
+    int          nBandSpace;
+
+  public:
+    GDALAsyncReader();
+    virtual ~GDALAsyncReader();
+
+    GDALDataset* GetGDALDataset() {return poDS;}
+    int GetXOffset() {return nXOff;}
+    int GetYOffset() {return nYOff;}
+    int GetXSize() {return nXSize;}
+    int GetYSize() {return nYSize;}
+    void * GetBuffer() {return pBuf;}
+    int GetBufferXSize() {return nBufXSize;}
+    int GetBufferYSize() {return nBufYSize;}
+    GDALDataType GetBufferType() {return eBufType;}
+    int GetBandCount() {return nBandCount;}
+    int* GetBandMap() {return panBandMap;}
+    int GetPixelSpace() {return nPixelSpace;}
+    int GetLineSpace() {return nLineSpace;}
+    int GetBandSpace() {return nBandSpace;}
+
+    virtual GDALAsyncStatusType 
+        GetNextUpdatedRegion(double dfTimeout,
+                             int* pnBufXOff, int* pnBufYOff,
+                             int* pnBufXSize, int* pnBufYSize) = 0;
+    virtual int LockBuffer( double dfTimeout = -1.0 );
+    virtual void UnlockBuffer();
+};
+
+/* ==================================================================== */
+/*      An assortment of overview related stuff.                        */
+/* ==================================================================== */
+
+/* Not a public symbol for the moment */
+CPLErr 
+GDALRegenerateOverviewsMultiBand(int nBands, GDALRasterBand** papoSrcBands,
+                                 int nOverviews,
+                                 GDALRasterBand*** papapoOverviewBands,
+                                 const char * pszResampling, 
+                                 GDALProgressFunc pfnProgress, void * pProgressData );
+
+typedef CPLErr (*GDALResampleFunction)
+                      ( double dfXRatioDstToSrc,
+                        double dfYRatioDstToSrc,
+                        double dfSrcXDelta,
+                        double dfSrcYDelta,
+                        GDALDataType eWrkDataType,
+                        void * pChunk,
+                        GByte * pabyChunkNodataMask,
+                        int nChunkXOff, int nChunkXSize,
+                        int nChunkYOff, int nChunkYSize,
+                        int nDstXOff, int nDstXOff2,
+                        int nDstYOff, int nDstYOff2,
+                        GDALRasterBand * poOverview,
+                        const char * pszResampling,
+                        int bHasNoData, float fNoDataValue,
+                        GDALColorTable* poColorTable,
+                        GDALDataType eSrcDataType);
+
+GDALResampleFunction GDALGetResampleFunction(const char* pszResampling,
+                                                 int* pnRadius);
+GDALDataType GDALGetOvrWorkDataType(const char* pszResampling,
+                                        GDALDataType eSrcDataType);
+
+CPL_C_START
+
+#ifndef WIN32CE
+
+CPLErr CPL_DLL
+HFAAuxBuildOverviews( const char *pszOvrFilename, GDALDataset *poParentDS,
+                      GDALDataset **ppoDS,
+                      int nBands, int *panBandList,
+                      int nNewOverviews, int *panNewOverviewList, 
+                      const char *pszResampling, 
+                      GDALProgressFunc pfnProgress, 
+                      void *pProgressData );
+
+#endif /* WIN32CE */
+
+CPLErr CPL_DLL 
+GTIFFBuildOverviews( const char * pszFilename,
+                     int nBands, GDALRasterBand **papoBandList, 
+                     int nOverviews, int * panOverviewList,
+                     const char * pszResampling, 
+                     GDALProgressFunc pfnProgress, void * pProgressData );
+
+CPLErr CPL_DLL
+GDALDefaultBuildOverviews( GDALDataset *hSrcDS, const char * pszBasename,
+                           const char * pszResampling, 
+                           int nOverviews, int * panOverviewList,
+                           int nBands, int * panBandList,
+                           GDALProgressFunc pfnProgress, void * pProgressData);
+                           
+int CPL_DLL GDALBandGetBestOverviewLevel(GDALRasterBand* poBand,
+                                         int &nXOff, int &nYOff,
+                                         int &nXSize, int &nYSize,
+                                         int nBufXSize, int nBufYSize) CPL_WARN_DEPRECATED("Use GDALBandGetBestOverviewLevel2 instead");
+int CPL_DLL GDALBandGetBestOverviewLevel2(GDALRasterBand* poBand,
+                                         int &nXOff, int &nYOff,
+                                         int &nXSize, int &nYSize,
+                                         int nBufXSize, int nBufYSize,
+                                         GDALRasterIOExtraArg* psExtraArg);
+
+int CPL_DLL GDALOvLevelAdjust( int nOvLevel, int nXSize ) CPL_WARN_DEPRECATED("Use GDALOvLevelAdjust2 instead");
+int CPL_DLL GDALOvLevelAdjust2( int nOvLevel, int nXSize, int nYSize );
+int CPL_DLL GDALComputeOvFactor( int nOvrXSize, int nRasterXSize,
+                                 int nOvrYSize, int nRasterYSize );
+
+GDALDataset CPL_DLL *
+GDALFindAssociatedAuxFile( const char *pszBasefile, GDALAccess eAccess,
+                           GDALDataset *poDependentDS );
+
+/* ==================================================================== */
+/*      Misc functions.                                                 */
+/* ==================================================================== */
+
+CPLErr CPL_DLL GDALParseGMLCoverage( CPLXMLNode *psTree, 
+                                     int *pnXSize, int *pnYSize,
+                                     double *padfGeoTransform,
+                                     char **ppszProjection );
+
+/* ==================================================================== */
+/*  Infrastructure to check that dataset characteristics are valid      */
+/* ==================================================================== */
+
+int CPL_DLL GDALCheckDatasetDimensions( int nXSize, int nYSize );
+int CPL_DLL GDALCheckBandCount( int nBands, int bIsZeroAllowed );
+
+
+// Test if 2 floating point values match. Useful when comparing values
+// stored as a string at some point. See #3573, #4183, #4506
+#define ARE_REAL_EQUAL(dfVal1, dfVal2) \
+ (dfVal1 == dfVal2 || fabs(dfVal1 - dfVal2) < 1e-10 || (dfVal2 != 0 && fabs(1 - dfVal1 / dfVal2) < 1e-10 ))
+
+/* Internal use only */
+
+/* CPL_DLL exported, but only for in-tree drivers that can be built as plugins */
+int CPL_DLL GDALReadWorldFile2( const char *pszBaseFilename, const char *pszExtension,
+                                double *padfGeoTransform, char** papszSiblingFiles,
+                                char** ppszWorldFileNameOut);
+int GDALReadTabFile2( const char * pszBaseFilename,
+                      double *padfGeoTransform, char **ppszWKT,
+                      int *pnGCPCount, GDAL_GCP **ppasGCPs,
+                      char** papszSiblingFiles, char** ppszTabFileNameOut );
+
+void CPL_DLL GDALCopyRasterIOExtraArg(GDALRasterIOExtraArg* psDestArg,
+                                      GDALRasterIOExtraArg* psSrcArg);
+
+CPL_C_END
+
+void GDALNullifyOpenDatasetsList();
+CPLMutex** GDALGetphDMMutex();
+CPLMutex** GDALGetphDLMutex();
+void GDALNullifyProxyPoolSingleton();
+GDALDriver* GDALGetAPIPROXYDriver();
+void GDALSetResponsiblePIDForCurrentThread(GIntBig responsiblePID);
+GIntBig GDALGetResponsiblePIDForCurrentThread();
+
+CPLString GDALFindAssociatedFile( const char *pszBasename, const char *pszExt,
+                                  char **papszSiblingFiles, int nFlags );
+
+CPLErr EXIFExtractMetadata(char**& papszMetadata,
+                           void *fpL, int nOffset,
+                           int bSwabflag, int nTIFFHEADER,
+                           int& nExifOffset, int& nInterOffset, int& nGPSOffset);
+
+int GDALValidateOpenOptions( GDALDriverH hDriver,
+                             const char* const* papszOptionOptions);
+int GDALValidateOptions( const char* pszOptionList,
+                         const char* const* papszOptionsToValidate,
+                         const char* pszErrorMessageOptionType,
+                         const char* pszErrorMessageContainerName);
+
+GDALRIOResampleAlg GDALRasterIOGetResampleAlg(const char* pszResampling);
+
+void GDALRasterIOExtraArgSetResampleAlg(GDALRasterIOExtraArg* psExtraArg,
+                                        int nXSize, int nYSize,
+                                        int nBufXSize, int nBufYSize);
+
+/* CPL_DLL exported, but only for gdalwarp */
+GDALDataset CPL_DLL* GDALCreateOverviewDataset(GDALDataset* poDS, int nOvrLevel,
+                                               int bThisLevelOnly, int bOwnDS);
+
+#define DIV_ROUND_UP(a, b) ( ((a) % (b)) == 0 ? ((a) / (b)) : (((a) / (b)) + 1) )
+
+// Number of data samples that will be used to compute approximate statistics
+// (minimum value, maximum value, etc.)
+#define GDALSTAT_APPROX_NUMSAMPLES 2500
+
+CPL_C_START
+/* Caution: for technical reason this declaration is duplicated in gdal_crs.c */
+/* so any signature change should be reflected there too */
+void GDALSerializeGCPListToXML( CPLXMLNode* psParentNode,
+                                GDAL_GCP* pasGCPList,
+                                int nGCPCount,
+                                const char* pszGCPProjection );
+void GDALDeserializeGCPListFromXML( CPLXMLNode* psGCPList,
+                                    GDAL_GCP** ppasGCPList,
+                                    int* pnGCPCount,
+                                    char** ppszGCPProjection );
+CPL_C_END
+
+void GDALSerializeOpenOptionsToXML( CPLXMLNode* psParentNode, char** papszOpenOptions);
+char** GDALDeserializeOpenOptionsFromXML( CPLXMLNode* psParentNode );
+
+int GDALCanFileAcceptSidecarFile(const char* pszFilename);
+
+#endif /* ndef GDAL_PRIV_H_INCLUDED */

+ 384 - 0
libpq_test/include/gdal_proxy.h

@@ -0,0 +1,384 @@
+/******************************************************************************
+ * $Id: gdal_proxy.h 28899 2015-04-14 09:27:00Z rouault $
+ *
+ * Project:  GDAL Core
+ * Purpose:  GDAL Core C++/Private declarations
+ * Author:   Even Rouault <even dot rouault at mines dash paris dot org>
+ *
+ ******************************************************************************
+ * Copyright (c) 2008-2014, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_PROXY_H_INCLUDED
+#define GDAL_PROXY_H_INCLUDED
+
+#include "gdal.h"
+
+#ifdef __cplusplus
+
+#include "gdal_priv.h"
+#include "cpl_hash_set.h"
+
+/* ******************************************************************** */
+/*                        GDALProxyDataset                              */
+/* ******************************************************************** */
+
+class CPL_DLL GDALProxyDataset : public GDALDataset
+{
+    protected:
+        virtual GDALDataset *RefUnderlyingDataset() = 0;
+        virtual void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset);
+
+        virtual CPLErr IBuildOverviews( const char *, int, int *,
+                                    int, int *, GDALProgressFunc, void * );
+        virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
+                                void *, int, int, GDALDataType,
+                                int, int *, GSpacing, GSpacing, GSpacing,
+                                GDALRasterIOExtraArg* psExtraArg );
+    public:
+
+        virtual char      **GetMetadataDomainList();
+        virtual char      **GetMetadata( const char * pszDomain  );
+        virtual CPLErr      SetMetadata( char ** papszMetadata,
+                                        const char * pszDomain  );
+        virtual const char *GetMetadataItem( const char * pszName,
+                                            const char * pszDomain  );
+        virtual CPLErr      SetMetadataItem( const char * pszName,
+                                            const char * pszValue,
+                                            const char * pszDomain );
+
+        virtual void FlushCache(void);
+
+        virtual const char *GetProjectionRef(void);
+        virtual CPLErr SetProjection( const char * );
+
+        virtual CPLErr GetGeoTransform( double * );
+        virtual CPLErr SetGeoTransform( double * );
+
+        virtual void *GetInternalHandle( const char * );
+        virtual GDALDriver *GetDriver(void);
+        virtual char      **GetFileList(void);
+
+        virtual int    GetGCPCount();
+        virtual const char *GetGCPProjection();
+        virtual const GDAL_GCP *GetGCPs();
+        virtual CPLErr SetGCPs( int nGCPCount, const GDAL_GCP *pasGCPList,
+                                const char *pszGCPProjection );
+
+        virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
+                                int nBufXSize, int nBufYSize, 
+                                GDALDataType eDT, 
+                                int nBandCount, int *panBandList,
+                                char **papszOptions );
+
+        virtual CPLErr          CreateMaskBand( int nFlags );
+
+};
+
+/* ******************************************************************** */
+/*                         GDALProxyRasterBand                          */
+/* ******************************************************************** */
+
+class CPL_DLL GDALProxyRasterBand : public GDALRasterBand
+{
+    protected:
+        virtual GDALRasterBand* RefUnderlyingRasterBand() = 0;
+        virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
+
+        virtual CPLErr IReadBlock( int, int, void * );
+        virtual CPLErr IWriteBlock( int, int, void * );
+        virtual CPLErr IRasterIO( GDALRWFlag, int, int, int, int,
+                                void *, int, int, GDALDataType,
+                                GSpacing, GSpacing, GDALRasterIOExtraArg* psExtraArg );
+
+    public:
+
+        virtual char      **GetMetadataDomainList();
+        virtual char      **GetMetadata( const char * pszDomain  );
+        virtual CPLErr      SetMetadata( char ** papszMetadata,
+                                        const char * pszDomain  );
+        virtual const char *GetMetadataItem( const char * pszName,
+                                            const char * pszDomain  );
+        virtual CPLErr      SetMetadataItem( const char * pszName,
+                                            const char * pszValue,
+                                            const char * pszDomain );
+        virtual CPLErr FlushCache();
+        virtual char **GetCategoryNames();
+        virtual double GetNoDataValue( int *pbSuccess = NULL );
+        virtual double GetMinimum( int *pbSuccess = NULL );
+        virtual double GetMaximum(int *pbSuccess = NULL );
+        virtual double GetOffset( int *pbSuccess = NULL );
+        virtual double GetScale( int *pbSuccess = NULL );
+        virtual const char *GetUnitType();
+        virtual GDALColorInterp GetColorInterpretation();
+        virtual GDALColorTable *GetColorTable();
+        virtual CPLErr Fill(double dfRealValue, double dfImaginaryValue = 0);
+
+        virtual CPLErr SetCategoryNames( char ** );
+        virtual CPLErr SetNoDataValue( double );
+        virtual CPLErr SetColorTable( GDALColorTable * ); 
+        virtual CPLErr SetColorInterpretation( GDALColorInterp );
+        virtual CPLErr SetOffset( double );
+        virtual CPLErr SetScale( double );
+        virtual CPLErr SetUnitType( const char * );
+
+        virtual CPLErr GetStatistics( int bApproxOK, int bForce,
+                                    double *pdfMin, double *pdfMax, 
+                                    double *pdfMean, double *padfStdDev );
+        virtual CPLErr ComputeStatistics( int bApproxOK, 
+                                        double *pdfMin, double *pdfMax, 
+                                        double *pdfMean, double *pdfStdDev,
+                                        GDALProgressFunc, void *pProgressData );
+        virtual CPLErr SetStatistics( double dfMin, double dfMax, 
+                                    double dfMean, double dfStdDev );
+        virtual CPLErr ComputeRasterMinMax( int, double* );
+
+        virtual int HasArbitraryOverviews();
+        virtual int GetOverviewCount();
+        virtual GDALRasterBand *GetOverview(int);
+        virtual GDALRasterBand *GetRasterSampleOverview( GUIntBig );
+        virtual CPLErr BuildOverviews( const char *, int, int *,
+                                    GDALProgressFunc, void * );
+
+        virtual CPLErr AdviseRead( int nXOff, int nYOff, int nXSize, int nYSize,
+                                int nBufXSize, int nBufYSize, 
+                                GDALDataType eDT, char **papszOptions );
+
+        virtual CPLErr  GetHistogram( double dfMin, double dfMax,
+                            int nBuckets, GUIntBig * panHistogram,
+                            int bIncludeOutOfRange, int bApproxOK,
+                            GDALProgressFunc, void *pProgressData );
+
+        virtual CPLErr GetDefaultHistogram( double *pdfMin, double *pdfMax,
+                                            int *pnBuckets, GUIntBig ** ppanHistogram,
+                                            int bForce,
+                                            GDALProgressFunc, void *pProgressData);
+        virtual CPLErr SetDefaultHistogram( double dfMin, double dfMax,
+                                            int nBuckets, GUIntBig *panHistogram );
+
+        virtual GDALRasterAttributeTable *GetDefaultRAT();
+        virtual CPLErr SetDefaultRAT( const GDALRasterAttributeTable * );
+
+        virtual GDALRasterBand *GetMaskBand();
+        virtual int             GetMaskFlags();
+        virtual CPLErr          CreateMaskBand( int nFlags );
+
+        virtual CPLVirtualMem  *GetVirtualMemAuto( GDALRWFlag eRWFlag,
+                                                int *pnPixelSpace,
+                                                GIntBig *pnLineSpace,
+                                                char **papszOptions );
+};
+
+
+/* ******************************************************************** */
+/*                     GDALProxyPoolDataset                             */
+/* ******************************************************************** */
+
+typedef struct _GDALProxyPoolCacheEntry GDALProxyPoolCacheEntry;
+class     GDALProxyPoolRasterBand;
+
+class CPL_DLL GDALProxyPoolDataset : public GDALProxyDataset
+{
+    private:
+        GIntBig          responsiblePID;
+
+        char            *pszProjectionRef;
+        double           adfGeoTransform[6];
+        int              bHasSrcProjection;
+        int              bHasSrcGeoTransform;
+        char            *pszGCPProjection;
+        int              nGCPCount;
+        GDAL_GCP        *pasGCPList;
+        CPLHashSet      *metadataSet;
+        CPLHashSet      *metadataItemSet;
+
+        GDALProxyPoolCacheEntry* cacheEntry;
+
+    protected:
+        virtual GDALDataset *RefUnderlyingDataset();
+        virtual void UnrefUnderlyingDataset(GDALDataset* poUnderlyingDataset);
+
+        friend class     GDALProxyPoolRasterBand;
+
+    public:
+        GDALProxyPoolDataset(const char* pszSourceDatasetDescription,
+                            int nRasterXSize, int nRasterYSize,
+                            GDALAccess eAccess = GA_ReadOnly,
+                            int bShared = FALSE,
+                            const char * pszProjectionRef = NULL,
+                            double * padfGeoTransform = NULL);
+        ~GDALProxyPoolDataset();
+
+        void         SetOpenOptions(char** papszOpenOptions);
+        void         AddSrcBandDescription( GDALDataType eDataType, int nBlockXSize, int nBlockYSize);
+
+        virtual const char *GetProjectionRef(void);
+        virtual CPLErr SetProjection( const char * );
+
+        virtual CPLErr GetGeoTransform( double * );
+        virtual CPLErr SetGeoTransform( double * );
+
+        /* Special behaviour for the following methods : they return a pointer */
+        /* data type, that must be cached by the proxy, so it doesn't become invalid */
+        /* when the underlying object get closed */
+        virtual char      **GetMetadata( const char * pszDomain  );
+        virtual const char *GetMetadataItem( const char * pszName,
+                                            const char * pszDomain  );
+
+        virtual void *GetInternalHandle( const char * pszRequest );
+
+        virtual const char *GetGCPProjection();
+        virtual const GDAL_GCP *GetGCPs();
+};
+
+/* ******************************************************************** */
+/*                  GDALProxyPoolRasterBand                             */
+/* ******************************************************************** */
+
+class GDALProxyPoolOverviewRasterBand;
+class GDALProxyPoolMaskBand;
+
+class CPL_DLL GDALProxyPoolRasterBand : public GDALProxyRasterBand
+{
+    private:
+        CPLHashSet      *metadataSet;
+        CPLHashSet      *metadataItemSet;
+        char            *pszUnitType;
+        char           **papszCategoryNames;
+        GDALColorTable  *poColorTable;
+
+        int                               nSizeProxyOverviewRasterBand;
+        GDALProxyPoolOverviewRasterBand **papoProxyOverviewRasterBand;
+        GDALProxyPoolMaskBand            *poProxyMaskBand;
+
+        void Init();
+
+    protected:
+        virtual GDALRasterBand* RefUnderlyingRasterBand();
+        virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
+
+        friend class GDALProxyPoolOverviewRasterBand;
+        friend class GDALProxyPoolMaskBand;
+
+    public:
+        GDALProxyPoolRasterBand(GDALProxyPoolDataset* poDS, int nBand,
+                                GDALDataType eDataType,
+                                int nBlockXSize, int nBlockYSize);
+        GDALProxyPoolRasterBand(GDALProxyPoolDataset* poDS,
+                                GDALRasterBand* poUnderlyingRasterBand);
+        ~GDALProxyPoolRasterBand();
+
+        void AddSrcMaskBandDescription( GDALDataType eDataType, int nBlockXSize, int nBlockYSize);
+
+        /* Special behaviour for the following methods : they return a pointer */
+        /* data type, that must be cached by the proxy, so it doesn't become invalid */
+        /* when the underlying object get closed */
+        virtual char      **GetMetadata( const char * pszDomain  );
+        virtual const char *GetMetadataItem( const char * pszName,
+                                            const char * pszDomain  );
+        virtual char **GetCategoryNames();
+        virtual const char *GetUnitType();
+        virtual GDALColorTable *GetColorTable();
+        virtual GDALRasterBand *GetOverview(int);
+        virtual GDALRasterBand *GetRasterSampleOverview( GUIntBig nDesiredSamples); // TODO
+        virtual GDALRasterBand *GetMaskBand();
+
+};
+
+/* ******************************************************************** */
+/*                  GDALProxyPoolOverviewRasterBand                     */
+/* ******************************************************************** */
+
+class GDALProxyPoolOverviewRasterBand : public GDALProxyPoolRasterBand
+{
+    private:
+        GDALProxyPoolRasterBand *poMainBand;
+        int                      nOverviewBand;
+
+        GDALRasterBand          *poUnderlyingMainRasterBand;
+        int                      nRefCountUnderlyingMainRasterBand;
+
+    protected:
+        virtual GDALRasterBand* RefUnderlyingRasterBand();
+        virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
+
+    public:
+        GDALProxyPoolOverviewRasterBand(GDALProxyPoolDataset* poDS,
+                                        GDALRasterBand* poUnderlyingOverviewBand,
+                                        GDALProxyPoolRasterBand* poMainBand,
+                                        int nOverviewBand);
+        ~GDALProxyPoolOverviewRasterBand();
+};
+
+/* ******************************************************************** */
+/*                      GDALProxyPoolMaskBand                           */
+/* ******************************************************************** */
+
+class GDALProxyPoolMaskBand : public GDALProxyPoolRasterBand
+{
+    private:
+        GDALProxyPoolRasterBand *poMainBand;
+
+        GDALRasterBand          *poUnderlyingMainRasterBand;
+        int                      nRefCountUnderlyingMainRasterBand;
+
+    protected:
+        virtual GDALRasterBand* RefUnderlyingRasterBand();
+        virtual void UnrefUnderlyingRasterBand(GDALRasterBand* poUnderlyingRasterBand);
+
+    public:
+        GDALProxyPoolMaskBand(GDALProxyPoolDataset* poDS,
+                              GDALRasterBand* poUnderlyingMaskBand,
+                              GDALProxyPoolRasterBand* poMainBand);
+        GDALProxyPoolMaskBand(GDALProxyPoolDataset* poDS,
+                              GDALProxyPoolRasterBand* poMainBand,
+                              GDALDataType eDataType,
+                              int nBlockXSize, int nBlockYSize);
+        ~GDALProxyPoolMaskBand();
+};
+
+#endif
+
+
+/* ******************************************************************** */
+/*            C types and methods declarations                          */
+/* ******************************************************************** */
+
+
+CPL_C_START
+
+typedef struct GDALProxyPoolDatasetHS *GDALProxyPoolDatasetH;
+
+GDALProxyPoolDatasetH CPL_DLL GDALProxyPoolDatasetCreate(const char* pszSourceDatasetDescription,
+                                                         int nRasterXSize, int nRasterYSize,
+                                                         GDALAccess eAccess, int bShared,
+                                                         const char * pszProjectionRef,
+                                                         double * padfGeoTransform);
+
+void CPL_DLL GDALProxyPoolDatasetDelete(GDALProxyPoolDatasetH hProxyPoolDataset);
+
+void CPL_DLL GDALProxyPoolDatasetAddSrcBandDescription( GDALProxyPoolDatasetH hProxyPoolDataset,
+                                                        GDALDataType eDataType,
+                                                        int nBlockXSize, int nBlockYSize);
+
+CPL_C_END
+
+#endif /* GDAL_PROXY_H_INCLUDED */

+ 349 - 0
libpq_test/include/gdal_rat.h

@@ -0,0 +1,349 @@
+/******************************************************************************
+ * $Id: gdal_rat.h 29243 2015-05-24 15:53:26Z rouault $
+ *
+ * Project:  GDAL Core
+ * Purpose:  GDALRasterAttributeTable class declarations.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_RAT_H_INCLUDED
+#define GDAL_RAT_H_INCLUDED
+
+#include "cpl_minixml.h"
+
+// Clone and Serialize are allowed to fail if GetRowCount()*GetColCount() greater
+// than this number
+#define RAT_MAX_ELEM_FOR_CLONE  1000000
+
+/************************************************************************/
+/*                       GDALRasterAttributeTable                       */
+/************************************************************************/
+
+//! Raster Attribute Table interface.
+class GDALDefaultRasterAttributeTable;
+
+class CPL_DLL GDALRasterAttributeTable 
+{
+public:
+    virtual ~GDALRasterAttributeTable();
+    /**
+     * \brief Copy Raster Attribute Table
+     *
+     * Creates a new copy of an existing raster attribute table.  The new copy
+     * becomes the responsibility of the caller to destroy.
+     * May fail (return NULL) if the attribute table is too large to clone
+     * (GetRowCount() * GetColCount() > RAT_MAX_ELEM_FOR_CLONE)
+     *
+     * This method is the same as the C function GDALRATClone().
+     *
+     * @return new copy of the RAT as an in-memory implementation.
+     */
+    virtual GDALDefaultRasterAttributeTable *Clone() const = 0;
+    
+    /**
+     * \brief Fetch table column count.
+     *
+     * This method is the same as the C function GDALRATGetColumnCount().
+     *
+     * @return the number of columns.
+     */
+    virtual int           GetColumnCount() const = 0;
+
+    /**
+     * \brief Fetch name of indicated column.
+     *
+     * This method is the same as the C function GDALRATGetNameOfCol().
+     *
+     * @param iCol the column index (zero based). 
+     *
+     * @return the column name or an empty string for invalid column numbers.
+     */
+    virtual const char   *GetNameOfCol( int ) const = 0;
+
+    /**
+     * \brief Fetch column usage value. 
+     *
+     * This method is the same as the C function GDALRATGetUsageOfCol().
+     *
+     * @param iCol the column index (zero based).
+     *
+     * @return the column usage, or GFU_Generic for improper column numbers.
+     */
+    virtual GDALRATFieldUsage GetUsageOfCol( int ) const = 0;
+
+    /**
+     * \brief Fetch column type.
+     *
+     * This method is the same as the C function GDALRATGetTypeOfCol().
+     *
+     * @param iCol the column index (zero based).
+     *
+     * @return column type or GFT_Integer if the column index is illegal.
+     */
+    virtual GDALRATFieldType GetTypeOfCol( int ) const = 0;
+    
+    /**
+     * \brief Fetch column index for given usage.
+     *
+     * Returns the index of the first column of the requested usage type, or -1 
+     * if no match is found. 
+     *
+     * This method is the same as the C function GDALRATGetUsageOfCol().
+     *
+     * @param eUsage usage type to search for.
+     *
+     * @return column index, or -1 on failure. 
+     */
+    virtual int           GetColOfUsage( GDALRATFieldUsage ) const = 0;
+
+    /**
+     * \brief Fetch row count.
+     * 
+     * This method is the same as the C function GDALRATGetRowCount().
+     *
+     * @return the number of rows. 
+     */
+    virtual int           GetRowCount() const = 0;
+
+    /**
+     * \brief Fetch field value as a string.
+     *
+     * The value of the requested column in the requested row is returned
+     * as a string.  If the field is numeric, it is formatted as a string
+     * using default rules, so some precision may be lost.
+     *
+     * The returned string is temporary and cannot be expected to be
+     * available after the next GDAL call.
+     * 
+     * This method is the same as the C function GDALRATGetValueAsString().
+     *
+     * @param iRow row to fetch (zero based).
+     * @param iField column to fetch (zero based).
+     * 
+     * @return field value. 
+     */
+    virtual const char   *GetValueAsString( int iRow, int iField ) const = 0;
+
+    /**
+     * \brief Fetch field value as a integer.
+     *
+     * The value of the requested column in the requested row is returned
+     * as an integer.  Non-integer fields will be converted to integer with
+     * the possibility of data loss.
+     *
+     * This method is the same as the C function GDALRATGetValueAsInt().
+     *
+     * @param iRow row to fetch (zero based).
+     * @param iField column to fetch (zero based).
+     * 
+     * @return field value
+     */
+    virtual int           GetValueAsInt( int iRow, int iField ) const = 0;
+
+    /**
+     * \brief Fetch field value as a double.
+     *
+     * The value of the requested column in the requested row is returned
+     * as a double.   Non double fields will be converted to double with
+     * the possibility of data loss.
+     * 
+     * This method is the same as the C function GDALRATGetValueAsDouble().
+     *
+     * @param iRow row to fetch (zero based).
+     * @param iField column to fetch (zero based).
+     * 
+     * @return field value
+     */
+    virtual double        GetValueAsDouble( int iRow, int iField ) const = 0;
+
+    /**
+     * \brief Set field value from string.
+     *
+     * The indicated field (column) on the indicated row is set from the
+     * passed value.  The value will be automatically converted for other field
+     * types, with a possible loss of precision.
+     *
+     * This method is the same as the C function GDALRATSetValueAsString().
+     *
+     * @param iRow row to fetch (zero based).
+     * @param iField column to fetch (zero based).
+     * @param pszValue the value to assign.
+     */
+    virtual void          SetValue( int iRow, int iField, const char *pszValue ) = 0;
+
+    /**
+     * \brief Set field value from integer.
+     *
+     * The indicated field (column) on the indicated row is set from the
+     * passed value.  The value will be automatically converted for other field
+     * types, with a possible loss of precision.
+     *
+     * This method is the same as the C function GDALRATSetValueAsInteger().
+     *
+     * @param iRow row to fetch (zero based).
+     * @param iField column to fetch (zero based).
+     * @param nValue the value to assign.
+     */
+    virtual void          SetValue( int iRow, int iField, int nValue ) = 0;
+
+    /**
+     * \brief Set field value from double.
+     *
+     * The indicated field (column) on the indicated row is set from the
+     * passed value.  The value will be automatically converted for other field
+     * types, with a possible loss of precision.
+     *
+     * This method is the same as the C function GDALRATSetValueAsDouble().
+     *
+     * @param iRow row to fetch (zero based).
+     * @param iField column to fetch (zero based).
+     * @param dfValue the value to assign.
+     */
+    virtual void          SetValue( int iRow, int iField, double dfValue) = 0;
+
+    /**
+     * \brief Determine whether changes made to this RAT are reflected directly in the dataset
+     * 
+     * If this returns FALSE then GDALRasterBand.SetDefaultRAT() should be called. Otherwise
+     * this is unnecessary since changes to this object are reflected in the dataset.
+     *
+     * This method is the same as the C function GDALRATChangesAreWrittenToFile().
+     *
+     */
+    virtual int           ChangesAreWrittenToFile() = 0;
+
+    virtual CPLErr        ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, double *pdfData);
+    virtual CPLErr        ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, int *pnData);
+    virtual CPLErr        ValuesIO(GDALRWFlag eRWFlag, int iField, int iStartRow, int iLength, char **papszStrList);
+
+    virtual void          SetRowCount( int iCount );
+    virtual int           GetRowOfValue( double dfValue ) const;
+    virtual int           GetRowOfValue( int nValue ) const;
+
+    virtual CPLErr        CreateColumn( const char *pszFieldName, 
+                                GDALRATFieldType eFieldType, 
+                                GDALRATFieldUsage eFieldUsage );
+    virtual CPLErr        SetLinearBinning( double dfRow0Min, double dfBinSize );
+    virtual int           GetLinearBinning( double *pdfRow0Min, double *pdfBinSize ) const;
+
+    /**
+     * \brief Serialize
+     * 
+     * May fail (return NULL) if the attribute table is too large to serialize
+     * (GetRowCount() * GetColCount() > RAT_MAX_ELEM_FOR_CLONE)
+     */
+    virtual CPLXMLNode   *Serialize() const;
+    virtual void   *SerializeJSON() const;
+    virtual CPLErr        XMLInit( CPLXMLNode *, const char * );
+
+    virtual CPLErr        InitializeFromColorTable( const GDALColorTable * );
+    virtual GDALColorTable *TranslateToColorTable( int nEntryCount = -1 );
+    
+    virtual void          DumpReadable( FILE * = NULL );
+};
+
+/************************************************************************/
+/*                       GDALRasterAttributeField                       */
+/*                                                                      */
+/*      (private)                                                       */
+/************************************************************************/
+
+class GDALRasterAttributeField
+{
+public:
+    CPLString         sName;
+
+    GDALRATFieldType  eType;
+
+    GDALRATFieldUsage eUsage;
+
+    std::vector<GInt32> anValues;
+    std::vector<double> adfValues;
+    std::vector<CPLString> aosValues;
+};
+
+/************************************************************************/
+/*                    GDALDefaultRasterAttributeTable                   */
+/************************************************************************/
+
+//! Raster Attribute Table container.
+
+class CPL_DLL GDALDefaultRasterAttributeTable : public GDALRasterAttributeTable
+{
+private:
+    std::vector<GDALRasterAttributeField> aoFields;
+
+    int bLinearBinning;
+    double dfRow0Min;
+    double dfBinSize;
+
+    void  AnalyseColumns();
+    int   bColumnsAnalysed;
+    int   nMinCol;
+    int   nMaxCol;
+
+    int   nRowCount;
+
+    CPLString osWorkingResult;
+
+public:
+    GDALDefaultRasterAttributeTable();
+    GDALDefaultRasterAttributeTable(const GDALDefaultRasterAttributeTable&);
+    ~GDALDefaultRasterAttributeTable();
+
+    GDALDefaultRasterAttributeTable *Clone() const;
+    
+    virtual int           GetColumnCount() const;
+
+    virtual const char   *GetNameOfCol( int ) const;
+    virtual GDALRATFieldUsage GetUsageOfCol( int ) const;
+    virtual GDALRATFieldType GetTypeOfCol( int ) const;
+    
+    virtual int           GetColOfUsage( GDALRATFieldUsage ) const;
+
+    virtual int           GetRowCount() const;
+
+    virtual const char   *GetValueAsString( int iRow, int iField ) const;
+    virtual int           GetValueAsInt( int iRow, int iField ) const;
+    virtual double        GetValueAsDouble( int iRow, int iField ) const;
+
+    virtual void          SetValue( int iRow, int iField, const char *pszValue );
+    virtual void          SetValue( int iRow, int iField, double dfValue);
+    virtual void          SetValue( int iRow, int iField, int nValue );
+
+    virtual int           ChangesAreWrittenToFile();
+    virtual void          SetRowCount( int iCount );
+
+    virtual int           GetRowOfValue( double dfValue ) const;
+    virtual int           GetRowOfValue( int nValue ) const;
+
+    virtual CPLErr        CreateColumn( const char *pszFieldName, 
+                                GDALRATFieldType eFieldType, 
+                                GDALRATFieldUsage eFieldUsage );
+    virtual CPLErr        SetLinearBinning( double dfRow0Min, double dfBinSize );
+    virtual int           GetLinearBinning( double *pdfRow0Min, double *pdfBinSize ) const;
+
+};
+
+#endif /* ndef GDAL_RAT_H_INCLUDED */

+ 554 - 0
libpq_test/include/gdal_simplesurf.h

@@ -0,0 +1,554 @@
+/******************************************************************************
+ * Project:  GDAL
+ * Purpose:  Correlator
+ * Author:   Andrew Migal, migal.drew@gmail.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2012, Andrew Migal
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+/**
+ * @file
+ * @author Andrew Migal migal.drew@gmail.com
+ * @brief Class for searching corresponding points on images.
+ */
+
+#ifndef GDALSIMPLESURF_H_
+#define GDALSIMPLESURF_H_
+
+#include "gdal_priv.h"
+#include "cpl_conv.h"
+#include <list>
+
+/**
+ * @brief Class of "feature point" in raster. Used by SURF-based algorithm.
+ *
+ * @details This point presents coordinates of distinctive pixel in image.
+ * In computer vision, feature points - the most "strong" and "unique"
+ * pixels (or areas) in picture, which can be distinguished from others.
+ * For more details, see FAST corner detector, SIFT, SURF and similar algorithms.
+ */
+class GDALFeaturePoint
+{
+public:
+    /**
+     * Standard constructor. Initializes all parameters with negative numbers
+     * and allocates memory for descriptor.
+     */
+    GDALFeaturePoint();
+
+    /**
+     * Copy constructor
+     * @param fp Copied instance of GDALFeaturePoint class
+     */
+    GDALFeaturePoint(const GDALFeaturePoint& fp);
+
+    /**
+     * Create instance of GDALFeaturePoint class
+     *
+     * @param nX X-coordinate (pixel)
+     * @param nY Y-coordinate (line)
+     * @param nScale Scale which contains this point (2, 4, 8, 16 and so on)
+     * @param nRadius Half of the side of descriptor area
+     * @param nSign Sign of Hessian determinant for this point
+     *
+     * @note This constructor normally is invoked by SURF-based algorithm,
+     * which provides all necessary parameters.
+     */
+    GDALFeaturePoint(int nX, int nY, int nScale, int nRadius, int nSign);
+    virtual ~GDALFeaturePoint();
+
+    GDALFeaturePoint& operator=(const GDALFeaturePoint& point);
+
+    /**
+     * Provide access to point's descriptor.
+     *
+     * @param nIndex Position of descriptor's value.
+     * nIndex should be within range from 0 to DESC_SIZE (in current version - 64)
+     *
+     * @return Reference to value of descriptor in 'nIndex' position.
+     * If index is out of range then behaviour is undefined.
+     */
+    double& operator[](int nIndex);
+
+    // Descriptor length
+    static const int DESC_SIZE = 64;
+
+    /**
+     * Fetch X-coordinate (pixel) of point
+     *
+     * @return X-coordinate in pixels
+     */
+    int GetX();
+
+    /**
+     * Set X coordinate of point
+     *
+     * @param nX X coordinate in pixels
+     */
+    void SetX(int nX);
+
+    /**
+     * Fetch Y-coordinate (line) of point.
+     *
+     * @return Y-coordinate in pixels.
+     */
+    int  GetY();
+
+    /**
+     * Set Y coordinate of point.
+     *
+     * @param nY Y coordinate in pixels.
+     */
+    void SetY(int nY);
+
+    /**
+     * Fetch scale of point.
+     *
+     * @return Scale for this point.
+     */
+    int  GetScale();
+
+    /**
+     * Set scale of point.
+     *
+     * @param nScale Scale for this point.
+     */
+    void SetScale(int nScale);
+
+    /**
+     * Fetch radius of point.
+     *
+     * @return Radius for this point.
+     */
+    int  GetRadius();
+
+    /**
+     * Set radius of point.
+     *
+     * @param nRadius Radius for this point.
+     */
+    void SetRadius(int nRadius);
+
+    /**
+     * Fetch sign of Hessian determinant of point.
+     *
+     * @return Sign for this point.
+     */
+    int  GetSign();
+
+    /**
+     * Set sign of point.
+     *
+     * @param nSign Sign of Hessian determinant for this point.
+     */
+    void SetSign(int nSign);
+
+private:
+    // Coordinates of point in image
+    int nX;
+    int nY;
+    // --------------------
+    int nScale;
+    int nRadius;
+    int nSign;
+    // Descriptor array
+    double *padfDescriptor;
+};
+
+/**
+ * @author Andrew Migal migal.drew@gmail.com
+ * @brief Integral image class (summed area table).
+ * @details Integral image is a table for fast computing the sum of
+ * values in rectangular subarea. In more detail, for 2-dimensional array
+ * of numbers this class provides capabilty to get sum of values in
+ * rectangular arbitrary area with any size in constant time.
+ * Integral image is constructed from grayscale picture.
+ */
+class GDALIntegralImage
+{
+public:
+    GDALIntegralImage();
+    virtual ~GDALIntegralImage();
+
+    /**
+     * Compute integral image for specified array. Result is stored internally.
+     *
+     * @param padfImg Pointer to 2-dimensional array of values
+     * @param nHeight Number of rows in array
+     * @param nWidth Number of columns in array
+     */
+    void Initialize(const double **padfImg, int nHeight, int nWidth);
+
+    /**
+     * Fetch value of specified position in integral image.
+     *
+     * @param nRow Row of this position
+     * @param nCol Column of this position
+     *
+     * @return Value in specified position or zero if parameters are out of range.
+     */
+    double GetValue(int nRow, int nCol);
+
+    /**
+     * Get sum of values in specified rectangular grid. Rectangle is constructed
+     * from left top point.
+     *
+     * @param nRow Row of left top point of rectangle
+     * @param nCol Column of left top point of rectangle
+     * @param nWidth Width of rectangular area (number of columns)
+     * @param nHeight Heigth of rectangular area (number of rows)
+     *
+     * @return Sum of values in specified grid.
+     */
+    double GetRectangleSum(int nRow, int nCol, int nWidth, int nHeight);
+
+    /**
+     * Get value of horizontal Haar wavelet in specified square grid.
+     *
+     * @param nRow Row of left top point of square
+     * @param nCol Column of left top point of square
+     * @param nSize Side of the square
+     *
+     * @return Value of horizontal Haar wavelet in specified square grid.
+     */
+    double HaarWavelet_X(int nRow, int nCol, int nSize);
+
+    /**
+     * Get value of vertical Haar wavelet in specified square grid.
+     *
+     * @param nRow Row of left top point of square
+     * @param nCol Column of left top point of square
+     * @param nSize Side of the square
+     *
+     * @return Value of vertical Haar wavelet in specified square grid.
+     */
+    double HaarWavelet_Y(int nRow, int nCol, int nSize);
+
+    /**
+     * Fetch height of integral image.
+     *
+     * @return Height of integral image (number of rows).
+     */
+    int GetHeight();
+
+    /**
+     * Fetch width of integral image.
+     *
+     * @return Width of integral image (number of columns).
+     */
+    int GetWidth();
+
+private:
+    double **pMatrix;
+    int nWidth;
+    int nHeight;
+};
+
+/**
+ * @author Andrew Migal migal.drew@gmail.com
+ * @brief Class for computation and storage of Hessian values in SURF-based algorithm.
+ *
+ * @details SURF-based algorithm normally uses this class for searching
+ * feature points on raster images. Class also contains traces of Hessian matrices
+ * to provide fast computations.
+ */
+class GDALOctaveLayer
+{
+public:
+    GDALOctaveLayer();
+
+    /**
+     * Create instance with provided parameters.
+     *
+     * @param nOctave Number of octave which contains this layer
+     * @param nInterval Number of position in octave
+     *
+     * @note Normally constructor is invoked only by SURF-based algorithm.
+     */
+    GDALOctaveLayer(int nOctave, int nInterval);
+    virtual ~GDALOctaveLayer();
+
+    /**
+     * Perform calculation of Hessian determinats and their signs
+     * for specified integral image. Result is stored internally.
+     *
+     * @param poImg Integral image object, which provides all necessary
+     * data for computation
+     *
+     * @note Normally method is invoked only by SURF-based algorithm.
+     */
+    void ComputeLayer(GDALIntegralImage *poImg);
+
+    /**
+     * Octave which contains this layer (1,2,3...)
+     */
+    int octaveNum;
+    /**
+     * Length of the side of filter
+     */
+    int filterSize;
+    /**
+     * Length of the border
+     */
+    int radius;
+    /**
+     * Scale for this layer
+     */
+    int scale;
+    /**
+     * Image width in pixels
+     */
+    int width;
+    /**
+     * Image height in pixels
+     */
+    int height;
+    /**
+     * Hessian values for image pixels
+     */
+    double **detHessians;
+    /**
+     * Hessian signs for speeded matching
+     */
+    int **signs;
+};
+
+/**
+ * @author Andrew Migal migal.drew@gmail.com
+ * @brief Class for handling octave layers in SURF-based algorithm.
+ * @details Class contains OctaveLayers and provides capability to construct octave space and distinguish
+ * feature points. Normally this class is used only by SURF-based algorithm.
+ */
+class GDALOctaveMap
+{
+public:
+    /**
+     * Create octave space. Octave numbers are start with one. (1, 2, 3, 4, ... )
+     *
+     * @param nOctaveStart Number of bottom octave
+     * @param nOctaveEnd Number of top octave. Should be equal or greater than OctaveStart
+     */
+    GDALOctaveMap(int nOctaveStart, int nOctaveEnd);
+    virtual ~GDALOctaveMap();
+
+    /**
+     * Calculate Hessian values for octave space
+     * (for all stored octave layers) using specified integral image
+     * @param poImg Integral image instance which provides necessary data
+     * @see GDALOctaveLayer
+     */
+    void ComputeMap(GDALIntegralImage *poImg);
+
+    /**
+     * Method makes decision that specified point
+     * in middle octave layer is maximum among all points
+     * from 3x3x3 neighbourhood (surrounding points in
+     * bottom, middle and top layers). Provided layers should be from the same octave's interval.
+     * Detects feature points.
+     *
+     * @param row Row of point, which is candidate to be feature point
+     * @param col Column of point, which is candidate to be feature point
+     * @param bot Bottom octave layer
+     * @param mid Middle octave layer
+     * @param top Top octave layer
+     * @param threshold Threshold for feature point recognition. Detected feature point
+     * will have Hessian value greater than this provided threshold.
+     *
+     * @return TRUE if candidate was evaluated as feature point or FALSE otherwise.
+     */
+    bool PointIsExtremum(int row, int col, GDALOctaveLayer *bot,
+                         GDALOctaveLayer *mid, GDALOctaveLayer *top, double threshold);
+
+    /**
+     * 2-dimensional array of octave layers
+     */
+    GDALOctaveLayer ***pMap;
+
+    /**
+     * Value for constructing internal octave space
+     */
+    static const int INTERVALS = 4;
+
+    /**
+     * Number of bottom octave
+     */
+    int octaveStart;
+
+    /**
+     * Number of top octave. Should be equal or greater than OctaveStart
+     */
+    int octaveEnd;
+};
+
+/**
+ * @author Andrew Migal migal.drew@gmail.com
+ * @brief Class for searching corresponding points on images.
+ * @details Provides capability for detection feature points
+ * and finding equal points on different images.
+ * Class implements simplified version of SURF algorithm (Speeded Up Robust Features).
+ * As original, this realization is scale invariant, but sensitive to rotation.
+ * Images should have similar rotation angles (maximum difference is up to 10-15 degrees),
+ * otherwise algorithm produces incorrect and very unstable results.
+ */
+
+class GDALSimpleSURF
+{
+private:
+    /**
+     * Class stores indexes of pair of point
+     * and distance between them.
+     */
+    class MatchedPointPairInfo
+    {
+    public:
+        MatchedPointPairInfo(int nInd_1, int nInd_2, double dfDist)
+            {
+                ind_1 = nInd_1;
+                ind_2 = nInd_2;
+                euclideanDist = dfDist;
+            }
+
+        int ind_1;
+        int ind_2;
+        double euclideanDist;
+    };
+
+public:
+    /**
+     * Prepare class according to specified parameters. Octave numbers affects
+     * to amount of detected points and their robustness.
+     * Range between bottom and top octaves also affects to required time of detection points
+     * (if range is large, algorithm should perform more operations).
+     * @param nOctaveStart Number of bottom octave. Octave numbers starts with one
+     * @param nOctaveEnd Number of top octave. Should be equal or greater than OctaveStart
+     *
+     * @note
+     * Every octave finds points with specific size. For small images
+     * use small octave numbers, for high resolution - large.
+     * For 1024x1024 images it's normal to use any octave numbers from range 1-6.
+     * (for example, octave start - 1, octave end - 3, or octave start - 2, octave end - 2.)
+     * For larger images, try 1-10 range or even higher.
+     * Pay attention that number of detected point decreases quickly per octave
+     * for particular image. Algorithm finds more points in case of small octave numbers.
+     * If method detects nothing, reduce bottom bound of octave range.
+     *
+     * NOTICE that every octave requires time to compute. Use a little range
+     * or only one octave if execution time is significant.
+     */
+    GDALSimpleSURF(int nOctaveStart, int nOctaveEnd);
+    virtual ~GDALSimpleSURF();
+
+    /**
+     * Convert image with RGB channels to grayscale using "luminosity" method.
+     * Result is used in SURF-based algorithm, but may be used anywhere where
+     * grayscale images with nice contrast are required.
+     *
+     * @param red Image's red channel
+     * @param green Image's green channel
+     * @param blue Image's blue channel
+     * @param nXSize Width of initial image
+     * @param nYSize Height of initial image
+     * @param padfImg Array for resulting grayscale image
+     * @param nHeight Height of resulting image
+     * @param nWidth Width of resulting image
+     *
+     * @return CE_None or CE_Failure if error occurs.
+     */
+    static CPLErr ConvertRGBToLuminosity(
+        GDALRasterBand *red,
+        GDALRasterBand *green,
+        GDALRasterBand *blue,
+        int nXSize, int nYSize,
+        double **padfImg, int nHeight, int nWidth);
+
+    /**
+     * Find feature points using specified integral image.
+     *
+     * @param poImg Integral image to be used
+     * @param dfThreshold Threshold for feature point recognition. Detected feature point
+     * will have Hessian value greater than this provided threshold.
+     *
+     * @note Typical threshold's value is 0,001. But this value
+     * can be various in each case and depends on image's nature.
+     * For example, value can be 0.002 or 0.005.
+     * Fill free to experiment with it.
+     * If threshold is high, than number of detected feature points is small,
+     * and vice versa.
+     */
+    std::vector<GDALFeaturePoint>*
+    ExtractFeaturePoints(GDALIntegralImage *poImg, double dfThreshold);
+
+    /**
+     * Find corresponding points (equal points in two collections).
+     *
+     * @param poMatchPairs Resulting collection for matched points
+     * @param poSecondCollect Points on the first image
+     * @param poSecondCollect Points on the second image
+     * @param dfThreshold Value from 0 to 1. Threshold affects to number of
+     * matched points. If threshold is lower, amount of corresponding
+     * points is larger, and vice versa
+     *
+     * @return CE_None or CE_Failure if error occurs.
+     */
+    static CPLErr MatchFeaturePoints(
+        std::vector<GDALFeaturePoint*> *poMatchPairs,
+        std::vector<GDALFeaturePoint> *poFirstCollect,
+        std::vector<GDALFeaturePoint> *poSecondCollect,
+        double dfThreshold);
+
+private:
+    /**
+     * Compute euclidean distance between descriptors of two feature points.
+     * It's used in comparison and matching of points.
+     *
+     * @param firstPoint First feature point to be compared
+     * @param secondPoint Second feature point to be compared
+     *
+     * @return Euclidean distance between descriptors.
+     */
+    static double GetEuclideanDistance(
+        GDALFeaturePoint &firstPoint, GDALFeaturePoint &secondPoint);
+
+    /**
+     * Set provided distance values to range from 0 to 1.
+     *
+     * @param poList List of distances to be normalized
+     */
+    static void NormalizeDistances(std::list<MatchedPointPairInfo> *poList);
+
+    /**
+     * Compute descriptor for specified feature point.
+     *
+     * @param poPoint Feature point instance
+     * @param poImg image where feature point was found
+     */
+    void SetDescriptor(GDALFeaturePoint *poPoint, GDALIntegralImage *poImg);
+
+
+private:
+    int octaveStart;
+    int octaveEnd;
+    GDALOctaveMap *poOctMap;
+};
+
+
+#endif /* GDALSIMPLESURF_H_ */

+ 29 - 0
libpq_test/include/gdal_version.h

@@ -0,0 +1,29 @@
+
+/* -------------------------------------------------------------------- */
+/*      GDAL Version Information.                                       */
+/* -------------------------------------------------------------------- */
+
+#ifndef GDAL_VERSION_MAJOR
+#  define GDAL_VERSION_MAJOR    2
+#  define GDAL_VERSION_MINOR    0
+#  define GDAL_VERSION_REV      1
+#  define GDAL_VERSION_BUILD    0
+#endif
+
+/* GDAL_COMPUTE_VERSION macro introduced in GDAL 1.10 */
+/* Must be used ONLY to compare with version numbers for GDAL >= 1.10 */
+#ifndef GDAL_COMPUTE_VERSION
+#define GDAL_COMPUTE_VERSION(maj,min,rev) ((maj)*1000000+(min)*10000+(rev)*100)
+#endif
+
+/* Note: the formula to compute GDAL_VERSION_NUM has changed in GDAL 1.10 */
+#ifndef GDAL_VERSION_NUM
+#  define GDAL_VERSION_NUM      (GDAL_COMPUTE_VERSION(GDAL_VERSION_MAJOR,GDAL_VERSION_MINOR,GDAL_VERSION_REV)+GDAL_VERSION_BUILD)
+#endif
+
+#ifndef GDAL_RELEASE_DATE
+#  define GDAL_RELEASE_DATE     20150915
+#endif
+#ifndef GDAL_RELEASE_NAME
+#  define GDAL_RELEASE_NAME     "2.0.1"
+#endif

+ 105 - 0
libpq_test/include/gdal_vrt.h

@@ -0,0 +1,105 @@
+/******************************************************************************
+ * $Id: gdal_vrt.h 12156 2007-09-14 14:05:58Z dron $
+ *
+ * Project:  Virtual GDAL Datasets
+ * Purpose:  C/Public declarations of virtual GDAL dataset objects.
+ * Author:   Andrey Kiselev, dron@ak4719.spb.edu
+ *
+ ******************************************************************************
+ * Copyright (c) 2007, Andrey Kiselev <dron@ak4719.spb.edu>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_VRT_H_INCLUDED
+#define GDAL_VRT_H_INCLUDED
+
+/**
+ * \file gdal_vrt.h
+ *
+ * Public (C callable) entry points for virtual GDAL dataset objects.
+ */
+
+#include "gdal.h"
+#include "cpl_port.h"
+#include "cpl_error.h"
+#include "cpl_minixml.h"
+
+#define VRT_NODATA_UNSET -1234.56
+
+CPL_C_START
+
+void    GDALRegister_VRT(void);
+typedef CPLErr
+(*VRTImageReadFunc)( void *hCBData,
+                     int nXOff, int nYOff, int nXSize, int nYSize,
+                     void *pData );
+
+/* -------------------------------------------------------------------- */
+/*      Define handle types related to various VRT dataset classes.     */
+/* -------------------------------------------------------------------- */
+typedef void *VRTDriverH;
+typedef void *VRTSourceH;
+typedef void *VRTSimpleSourceH;
+typedef void *VRTAveragedSourceH;
+typedef void *VRTComplexSourceH;
+typedef void *VRTFilteredSourceH;
+typedef void *VRTKernelFilteredSourceH;
+typedef void *VRTAverageFilteredSourceH;
+typedef void *VRTFuncSourceH;
+typedef void *VRTDatasetH;
+typedef void *VRTWarpedDatasetH;
+typedef void *VRTRasterBandH;
+typedef void *VRTSourcedRasterBandH;
+typedef void *VRTWarpedRasterBandH;
+typedef void *VRTDerivedRasterBandH;
+typedef void *VRTRawRasterBandH;
+
+/* ==================================================================== */
+/*      VRTDataset class.                                               */
+/* ==================================================================== */
+
+VRTDatasetH CPL_DLL CPL_STDCALL VRTCreate( int, int );
+void CPL_DLL CPL_STDCALL VRTFlushCache( VRTDatasetH );
+CPLXMLNode CPL_DLL * CPL_STDCALL VRTSerializeToXML( VRTDatasetH, const char * );
+int CPL_DLL CPL_STDCALL VRTAddBand( VRTDatasetH, GDALDataType, char ** );
+
+/* ==================================================================== */
+/*      VRTSourcedRasterBand class.                                     */
+/* ==================================================================== */
+
+CPLErr CPL_STDCALL VRTAddSource( VRTSourcedRasterBandH, VRTSourceH );
+CPLErr CPL_DLL CPL_STDCALL VRTAddSimpleSource( VRTSourcedRasterBandH,
+                                               GDALRasterBandH,
+                                               int, int, int, int,
+                                               int, int, int, int,
+                                               const char *, double );
+CPLErr CPL_DLL CPL_STDCALL VRTAddComplexSource( VRTSourcedRasterBandH,
+                                                GDALRasterBandH, 
+                                                int, int, int, int,
+                                                int, int, int, int,
+                                                double, double, double );
+CPLErr CPL_DLL CPL_STDCALL VRTAddFuncSource( VRTSourcedRasterBandH,
+                                             VRTImageReadFunc,
+                                             void *, double );
+
+CPL_C_END
+
+#endif /* GDAL_VRT_H_INCLUDED */
+

+ 241 - 0
libpq_test/include/gdalexif.h

@@ -0,0 +1,241 @@
+/******************************************************************************
+ * $Id: gdalexif.h 24549 2012-06-09 20:14:14Z rouault $
+ *
+ * Project:  JPEG JFIF Driver
+ * Purpose:  Implement GDAL JPEG Support based on IJG libjpeg.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2000, Frank Warmerdam
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#define EXIFOFFSETTAG 0x8769
+#define INTEROPERABILITYOFFSET 0xA005
+#define GPSOFFSETTAG     0x8825
+#define MAXSTRINGLENGTH 65535
+
+#ifdef RENAME_INTERNAL_LIBTIFF_SYMBOLS
+#include "../frmts/gtiff/libtiff/gdal_libtiff_symbol_rename.h"
+#endif
+
+static const struct gpsname {
+    GUInt16     tag;
+    const char* name;
+} gpstags [] = {
+    { 0x00, "EXIF_GPSVersionID" },
+    { 0x01, "EXIF_GPSLatitudeRef" },
+    { 0x02, "EXIF_GPSLatitude" },
+    { 0x03, "EXIF_GPSLongitudeRef" },
+    { 0x04, "EXIF_GPSLongitude" },
+    { 0x05, "EXIF_GPSAltitudeRef" },
+    { 0x06, "EXIF_GPSAltitude" },
+    { 0x07, "EXIF_GPSTimeStamp" }, 
+    { 0x08, "EXIF_GPSSatellites" }, 
+    { 0x09, "EXIF_GPSStatus" }, 
+    { 0x0a, "EXIF_GPSMeasureMode" }, 
+    { 0x0b, "EXIF_GPSDOP" },
+    { 0x0c, "EXIF_GPSSpeedRef"},
+    { 0x0d, "EXIF_GPSSpeed"},
+    { 0x0e, "EXIF_GPSTrackRef"},
+    { 0x0f, "EXIF_GPSTrack"},
+    { 0x10, "EXIF_GPSImgDirectionRef"},
+    { 0x11, "EXIF_GPSImgDirection"},
+    { 0x12, "EXIF_GPSMapDatum"},
+    { 0x13, "EXIF_GPSDestLatitudeRef"},
+    { 0x14, "EXIF_GPSDestLatitude"},
+    { 0x15, "EXIF_GPSDestLongitudeRef"},
+    { 0x16, "EXIF_GPSDestLongitude"},
+    { 0x17, "EXIF_GPSDestBearingRef"},
+    { 0x18, "EXIF_GPSDestBearing"},
+    { 0x19, "EXIF_GPSDestDistanceRef"},
+    { 0x1a, "EXIF_GPSDestDistance"},
+    { 0x1b, "EXIF_GPSProcessingMethod"},
+    { 0x1c, "EXIF_GPSAreaInformation"},
+    { 0x1d, "EXIF_GPSDateStamp"},
+    { 0x1e, "EXIF_GPSDifferential"},  
+    { 0xffff,       ""}
+}; 
+
+static const struct tagname {
+  GUInt16       tag;
+  const char*   name;
+} tagnames [] = {
+
+//    { 0x100,	"EXIF_Image_Width"},
+//    { 0x101,	"EXIF_Image_Length"},
+    { 0x102,	"EXIF_BitsPerSample"},
+    { 0x103,	"EXIF_Compression"},
+    { 0x106,	"EXIF_PhotometricInterpretation"},
+    { 0x10A,	"EXIF_Fill_Order"},
+    { 0x10D,	"EXIF_Document_Name"},
+    { 0x10E,	"EXIF_ImageDescription"},
+    { 0x10F,	"EXIF_Make"},
+    { 0x110,	"EXIF_Model"},
+    { 0x111,	"EXIF_StripOffsets"},
+    { 0x112,	"EXIF_Orientation"},
+    { 0x115,	"EXIF_SamplesPerPixel"},
+    { 0x116,	"EXIF_RowsPerStrip"},
+    { 0x117,	"EXIF_StripByteCounts"},
+    { 0x11A,	"EXIF_XResolution"},
+    { 0x11B,	"EXIF_YResolution"},
+    { 0x11C,	"EXIF_PlanarConfiguration"},
+    { 0x128,	"EXIF_ResolutionUnit"},
+    { 0x12D,	"EXIF_TransferFunction"},
+    { 0x131,	"EXIF_Software"},
+    { 0x132,	"EXIF_DateTime"},
+    { 0x13B,	"EXIF_Artist"},
+    { 0x13E,	"EXIF_WhitePoint"},
+    { 0x13F,	"EXIF_PrimaryChromaticities"},
+    { 0x156,	"EXIF_Transfer_Range"},
+    { 0x200,	"EXIF_JPEG_Proc"},
+    { 0x201,	"EXIF_JPEGInterchangeFormat"},
+    { 0x202,	"EXIF_JPEGInterchangeFormatLength"},
+    { 0x211,	"EXIF_YCbCrCoefficients"},
+    { 0x212,	"EXIF_YCbCrSubSampling"},
+    { 0x213,	"EXIF_YCbCrPositioning"},
+    { 0x214,	"EXIF_ReferenceBlackWhite"},
+    { 0x828D,	"EXIF_CFA_Repeat_Pattern_Dim"},
+    { 0x828E,	"EXIF_CFA_Pattern"},
+    { 0x828F,	"EXIF_Battery_Level"},
+    { 0x8298,	"EXIF_Copyright"},
+    { 0x829A,	"EXIF_ExposureTime"},
+    { 0x829D,	"EXIF_FNumber"},
+    { 0x83BB,	"EXIF_IPTC/NAA"},
+//	{ 0x8769,	"EXIF_Offset"},
+    { 0x8773,	"EXIF_Inter_Color_Profile"},
+    { 0x8822,	"EXIF_ExposureProgram"},
+    { 0x8824,	"EXIF_SpectralSensitivity"},
+//	{ 0x8825,	"EXIF_GPSOffset"},
+    { 0x8827,	"EXIF_ISOSpeedRatings"},
+    { 0x8828,	"EXIF_OECF"},
+    { 0x9000,	"EXIF_ExifVersion"},
+    { 0x9003,	"EXIF_DateTimeOriginal"},
+    { 0x9004,	"EXIF_DateTimeDigitized"},
+    { 0x9101,	"EXIF_ComponentsConfiguration"},
+    { 0x9102,	"EXIF_CompressedBitsPerPixel"},
+    { 0x9201,	"EXIF_ShutterSpeedValue"},
+    { 0x9202,	"EXIF_ApertureValue"},
+    { 0x9203,	"EXIF_BrightnessValue"},
+    { 0x9204,	"EXIF_ExposureBiasValue"},
+    { 0x9205,	"EXIF_MaxApertureValue"},
+    { 0x9206,	"EXIF_SubjectDistance"},
+    { 0x9207,	"EXIF_MeteringMode"},
+    { 0x9208,	"EXIF_LightSource"},
+    { 0x9209,	"EXIF_Flash"},
+    { 0x920A,	"EXIF_FocalLength"},
+    { 0x9214,   "EXIF_SubjectArea"},
+    { 0x927C,	"EXIF_MakerNote"},
+    { 0x9286,	"EXIF_UserComment"},
+    { 0x9290,	"EXIF_SubSecTime"},
+    { 0x9291,	"EXIF_SubSecTime_Original"},
+    { 0x9292,	"EXIF_SubSecTime_Digitized"},
+    { 0xA000,	"EXIF_FlashpixVersion"},
+    { 0xA001,	"EXIF_ColorSpace"},
+    { 0xA002,	"EXIF_PixelXDimension"},
+    { 0xA003,	"EXIF_PixelYDimension"},
+    { 0xA004,       "EXIF_RelatedSoundFile"},
+//	{ 0xA005,	"EXIF_InteroperabilityOffset"},
+    { 0xA20B,	"EXIF_FlashEnergy"},	  // 0x920B in TIFF/EP
+    { 0xA20C,	"EXIF_SpatialFrequencyResponse"},   // 0x920C    -  -
+    { 0xA20E,	"EXIF_FocalPlaneXResolution"},     // 0x920E    -  -
+    { 0xA20F,	"EXIF_FocalPlaneYResolution"},     // 0x920F    -  -
+    { 0xA210,	"EXIF_FocalPlaneResolutionUnit"},  // 0x9210    -  -
+    { 0xA214,	"EXIF_SubjectLocation"},	// 0x9214    -  -
+    { 0xA215,	"EXIF_ExposureIndex"},		// 0x9215    -  -
+    { 0xA217,	"EXIF_SensingMethod"},		// 0x9217    -  -
+    { 0xA300,	"EXIF_FileSource"},
+    { 0xA301,	"EXIF_SceneType"},
+    { 0xA302,   "EXIF_CFAPattern"},
+    { 0xA401,   "EXIF_CustomRendered"},
+    { 0xA402,   "EXIF_ExposureMode"},
+    { 0XA403,   "EXIF_WhiteBalance"},
+    { 0xA404,   "EXIF_DigitalZoomRatio"},
+    { 0xA405,   "EXIF_FocalLengthIn35mmFilm"},
+    { 0xA406,   "EXIF_SceneCaptureType"},
+    { 0xA407,   "EXIF_GainControl"},
+    { 0xA408,   "EXIF_Contrast"},
+    { 0xA409,   "EXIF_Saturation"},
+    { 0xA40A,   "EXIF_Sharpness"},
+    { 0xA40B,   "EXIF_DeviceSettingDescription"},
+    { 0xA40C,   "EXIF_SubjectDistanceRange"},
+    { 0xA420,   "EXIF_ImageUniqueID"},
+    { 0x0000,       ""}
+};
+
+
+static const struct intr_tag {
+  GInt16        tag;
+  const char*   name;
+} intr_tags [] = {
+
+    { 0x1,	"EXIF_Interoperability_Index"},
+    { 0x2,	"EXIF_Interoperability_Version"},
+    { 0x1000,	"EXIF_Related_Image_File_Format"},
+    { 0x1001,	"EXIF_Related_Image_Width"},
+    { 0x1002,	"EXIF_Related_Image_Length"},
+    { 0x0000,       ""}
+};
+
+typedef enum {
+        TIFF_NOTYPE     = 0,    /* placeholder */
+        TIFF_BYTE       = 1,    /* 8-bit unsigned integer */
+        TIFF_ASCII      = 2,    /* 8-bit bytes w/ last byte null */
+        TIFF_SHORT      = 3,    /* 16-bit unsigned integer */
+        TIFF_LONG       = 4,    /* 32-bit unsigned integer */
+        TIFF_RATIONAL   = 5,    /* 64-bit unsigned fraction */
+        TIFF_SBYTE      = 6,    /* !8-bit signed integer */
+        TIFF_UNDEFINED  = 7,    /* !8-bit untyped data */
+        TIFF_SSHORT     = 8,    /* !16-bit signed integer */
+        TIFF_SLONG      = 9,    /* !32-bit signed integer */
+        TIFF_SRATIONAL  = 10,   /* !64-bit signed fraction */
+        TIFF_FLOAT      = 11,   /* !32-bit IEEE floating point */
+        TIFF_DOUBLE     = 12,   /* !64-bit IEEE floating point */
+        TIFF_IFD        = 13    /* %32-bit unsigned integer (offset) */
+} TIFFDataType;
+
+/*
+ * TIFF Image File Directories are comprised of a table of field
+ * descriptors of the form shown below.  The table is sorted in
+ * ascending order by tag.  The values associated with each entry are
+ * disjoint and may appear anywhere in the file (so long as they are
+ * placed on a word boundary).
+ *
+ * If the value is 4 bytes or less, then it is placed in the offset
+ * field to save space.  If the value is less than 4 bytes, it is
+ * left-justified in the offset field.
+ */
+typedef struct {
+        GUInt16          tdir_tag;       /* see below */
+        GUInt16          tdir_type;      /* data type; see below */
+        GUInt32          tdir_count;     /* number of items; length in spec */
+        GUInt32          tdir_offset;    /* byte offset to field data */
+} TIFFDirEntry;
+
+CPL_C_START
+extern	int TIFFDataWidth(TIFFDataType);    /* table of tag datatype widths */
+extern	void TIFFSwabShort(GUInt16*);
+extern	void TIFFSwabLong(GUInt32*);
+extern	void TIFFSwabDouble(double*);
+extern	void TIFFSwabArrayOfShort(GUInt16*, unsigned long);
+extern	void TIFFSwabArrayOfLong(GUInt32*, unsigned long);
+extern	void TIFFSwabArrayOfDouble(double*, unsigned long);
+CPL_C_END
+

+ 57 - 0
libpq_test/include/gdalgeorefpamdataset.h

@@ -0,0 +1,57 @@
+/******************************************************************************
+ * $Id: gdalgeorefpamdataset.h 26571 2013-10-30 10:59:11Z rouault $
+ *
+ * Project:  GDAL 
+ * Purpose:  GDALPamDataset with internal storage for georeferencing, with
+ *           priority for PAM over internal georeferencing
+ * Author:   Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ ******************************************************************************
+ * Copyright (c) 2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_GEOREF_PAM_DATASET_H_INCLUDED
+#define GDAL_GEOREF_PAM_DATASET_H_INCLUDED
+
+#include "gdal_pam.h"
+
+class CPL_DLL GDALGeorefPamDataset : public GDALPamDataset
+{
+  protected:
+    int         bGeoTransformValid;
+    double      adfGeoTransform[6];
+    char        *pszProjection;
+    int         nGCPCount;
+    GDAL_GCP    *pasGCPList;
+
+  public:
+        GDALGeorefPamDataset();
+        ~GDALGeorefPamDataset();
+
+    virtual CPLErr          GetGeoTransform( double * );
+    virtual const char     *GetProjectionRef();
+
+    virtual int             GetGCPCount();
+    virtual const char     *GetGCPProjection();
+    virtual const GDAL_GCP *GetGCPs();
+};
+
+#endif /* GDAL_GEOREF_PAM_DATASET_H_INCLUDED */

+ 122 - 0
libpq_test/include/gdalgrid.h

@@ -0,0 +1,122 @@
+/******************************************************************************
+ * $Id: gdalgrid.h 27044 2014-03-16 23:41:27Z rouault $
+ *
+ * Project:  GDAL Gridding API.
+ * Purpose:  Prototypes, and definitions for of GDAL scattered data gridder.
+ * Author:   Andrey Kiselev, dron@ak4719.spb.edu
+ *
+ ******************************************************************************
+ * Copyright (c) 2007, Andrey Kiselev <dron@ak4719.spb.edu>
+ * Copyright (c) 2012, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDALGRID_H_INCLUDED
+#define GDALGRID_H_INCLUDED
+
+/**
+ * \file gdalgrid.h
+ *
+ * GDAL gridder related entry points and definitions.
+ */
+
+#include "gdal_alg.h"
+
+/*
+ *  GridCreate Algorithm names
+ */
+
+static const char szAlgNameInvDist[] = "invdist";
+static const char szAlgNameAverage[] = "average";
+static const char szAlgNameNearest[] = "nearest";
+static const char szAlgNameMinimum[] = "minimum";
+static const char szAlgNameMaximum[] = "maximum";
+static const char szAlgNameRange[] = "range";
+static const char szAlgNameCount[] = "count";
+static const char szAlgNameAverageDistance[] = "average_distance";
+static const char szAlgNameAverageDistancePts[] = "average_distance_pts";
+
+CPL_C_START
+
+typedef CPLErr (*GDALGridFunction)( const void *, GUInt32,
+                                    const double *, const double *,
+                                    const double *,
+                                    double, double, double *,
+                                    void* );
+CPLErr
+GDALGridInverseDistanceToAPower( const void *, GUInt32,
+                                 const double *, const double *,
+                                 const double *,
+                                 double, double, double *,
+                                 void* );
+CPLErr
+GDALGridInverseDistanceToAPowerNoSearch( const void *, GUInt32,
+                                         const double *, const double *,
+                                         const double *,
+                                         double, double, double *,
+                                         void*  );
+CPLErr
+GDALGridMovingAverage( const void *, GUInt32,
+                       const double *, const double *, const double *,
+                       double, double, double *,
+                       void*  );
+CPLErr
+GDALGridNearestNeighbor( const void *, GUInt32,
+                         const double *, const double *, const double *,
+                         double, double, double *,
+                         void* );
+CPLErr
+GDALGridDataMetricMinimum( const void *, GUInt32,
+                           const double *, const double *, const double *,
+                           double, double, double *,
+                           void*  );
+CPLErr
+GDALGridDataMetricMaximum( const void *, GUInt32,
+                           const double *, const double *, const double *,
+                           double, double, double *,
+                           void*  );
+CPLErr
+GDALGridDataMetricRange( const void *, GUInt32,
+                         const double *, const double *, const double *,
+                         double, double, double *,
+                         void*  );
+CPLErr
+GDALGridDataMetricCount( const void *, GUInt32,
+                         const double *, const double *, const double *,
+                         double, double, double *,
+                         void*  );
+CPLErr
+GDALGridDataMetricAverageDistance( const void *, GUInt32,
+                                   const double *, const double *,
+                                   const double *, double, double, double *,
+                                   void* );
+CPLErr
+GDALGridDataMetricAverageDistancePts( const void *, GUInt32,
+                                      const double *, const double *,
+                                      const double *, double, double,
+                                      double *,
+                                      void*  );
+CPLErr CPL_DLL
+ParseAlgorithmAndOptions( const char *,
+                          GDALGridAlgorithm *,
+                          void ** );
+CPL_C_END
+
+#endif /* GDALGRID_H_INCLUDED */

+ 99 - 0
libpq_test/include/gdalgrid_priv.h

@@ -0,0 +1,99 @@
+/******************************************************************************
+ * $Id: gdalgrid_priv.h 29314 2015-06-05 20:21:11Z rouault $
+ *
+ * Project:  GDAL Gridding API.
+ * Purpose:  Prototypes, and definitions for of GDAL scattered data gridder.
+ * Author:   Even Rouault, <even dot rouault at mines dash paris dot org>
+ *
+ ******************************************************************************
+ * Copyright (c) 2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#include "cpl_error.h"
+#include "cpl_quad_tree.h"
+
+typedef struct
+{
+    const double* padfX;
+    const double* padfY;
+} GDALGridXYArrays;
+
+typedef struct
+{
+    GDALGridXYArrays* psXYArrays;
+    int               i;
+} GDALGridPoint;
+
+typedef struct
+{
+    CPLQuadTree* hQuadTree;
+    double       dfInitialSearchRadius;
+    const float *pafX;
+    const float *pafY;
+    const float *pafZ;
+} GDALGridExtraParameters;
+
+#ifdef HAVE_SSE_AT_COMPILE_TIME
+int CPLHaveRuntimeSSE();
+
+CPLErr
+GDALGridInverseDistanceToAPower2NoSmoothingNoSearchSSE(
+                                        const void *poOptions,
+                                        GUInt32 nPoints,
+                                        const double *unused_padfX,
+                                        const double *unused_padfY,
+                                        const double *unused_padfZ,
+                                        double dfXPoint, double dfYPoint,
+                                        double *pdfValue,
+                                        void* hExtraParamsIn );
+#endif
+
+#ifdef HAVE_AVX_AT_COMPILE_TIME
+int CPLHaveRuntimeAVX();
+
+CPLErr GDALGridInverseDistanceToAPower2NoSmoothingNoSearchAVX(
+                                        const void *poOptions,
+                                        GUInt32 nPoints,
+                                        const double *unused_padfX,
+                                        const double *unused_padfY,
+                                        const double *unused_padfZ,
+                                        double dfXPoint, double dfYPoint,
+                                        double *pdfValue,
+                                        void* hExtraParamsIn );
+#endif
+
+#if defined(__GNUC__) 
+#if defined(__x86_64)
+#define GCC_CPUID(level, a, b, c, d)            \
+  __asm__ ("xchgq %%rbx, %q1\n"                 \
+           "cpuid\n"                            \
+           "xchgq %%rbx, %q1"                   \
+       : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
+       : "0" (level))
+#else
+#define GCC_CPUID(level, a, b, c, d)            \
+  __asm__ ("xchgl %%ebx, %1\n"                  \
+           "cpuid\n"                            \
+           "xchgl %%ebx, %1"                    \
+       : "=a" (a), "=r" (b), "=c" (c), "=d" (d) \
+       : "0" (level))
+#endif
+#endif

+ 60 - 0
libpq_test/include/gdaljp2abstractdataset.h

@@ -0,0 +1,60 @@
+/******************************************************************************
+ * $Id: gdaljp2abstractdataset.h 29131 2015-05-03 14:47:58Z rouault $
+ *
+ * Project:  GDAL 
+ * Purpose:  GDALGeorefPamDataset with helper to read georeferencing and other
+ *           metadata from JP2Boxes
+ * Author:   Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ ******************************************************************************
+ * Copyright (c) 2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_JP2_ABSTRACT_DATASET_H_INCLUDED
+#define GDAL_JP2_ABSTRACT_DATASET_H_INCLUDED
+
+#include "gdalgeorefpamdataset.h"
+
+class CPL_DLL GDALJP2AbstractDataset: public GDALGeorefPamDataset
+{
+    char*               pszWldFilename;
+
+    GDALDataset*        poMemDS;
+    char**              papszMetadataFiles;
+
+  protected:
+    virtual int         CloseDependentDatasets();
+
+  public:
+        GDALJP2AbstractDataset();
+        ~GDALJP2AbstractDataset();
+
+        void LoadJP2Metadata(GDALOpenInfo* poOpenInfo,
+                             const char* pszOverideFilename = NULL);
+        void            LoadVectorLayers(int bOpenRemoteResources = FALSE);
+
+        virtual char      **GetFileList(void);
+
+        virtual int         GetLayerCount();
+        virtual OGRLayer   *GetLayer(int i);
+};
+
+#endif /* GDAL_JP2_ABSTRACT_DATASET_H_INCLUDED */

+ 196 - 0
libpq_test/include/gdaljp2metadata.h

@@ -0,0 +1,196 @@
+/******************************************************************************
+ * $Id: gdaljp2metadata.h 29210 2015-05-19 19:04:28Z rouault $
+ *
+ * Project:  GDAL 
+ * Purpose:  JP2 Box Reader (and GMLJP2 Interpreter)
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2005, Frank Warmerdam <warmerdam@pobox.com>
+ * Copyright (c) 2010-2013, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_JP2READER_H_INCLUDED
+#define GDAL_JP2READER_H_INCLUDED
+
+#include "cpl_conv.h"
+#include "cpl_vsi.h"
+#include "gdal.h"
+#include "gdal_priv.h"
+#include "cpl_minixml.h"
+
+/************************************************************************/
+/*                              GDALJP2Box                              */
+/************************************************************************/
+
+class CPL_DLL GDALJP2Box
+{
+
+    VSILFILE   *fpVSIL;
+
+    char        szBoxType[5];
+
+    GIntBig     nBoxOffset;
+    GIntBig     nBoxLength;
+
+    GIntBig     nDataOffset;
+
+    GByte       abyUUID[16];
+
+    GByte      *pabyData;
+
+public:
+                GDALJP2Box( VSILFILE * = NULL );
+                ~GDALJP2Box();
+
+    int         SetOffset( GIntBig nNewOffset );
+    int         ReadBox();
+
+    int         ReadFirst();
+    int         ReadNext();
+
+    int         ReadFirstChild( GDALJP2Box *poSuperBox );
+    int         ReadNextChild( GDALJP2Box *poSuperBox );
+
+    GIntBig     GetBoxOffset() const { return nBoxOffset; }
+    GIntBig     GetBoxLength() const { return nBoxLength; }
+
+    GIntBig     GetDataOffset() const { return nDataOffset; }
+    GIntBig     GetDataLength();
+
+    const char *GetType() { return szBoxType; }
+    
+    GByte      *ReadBoxData();
+
+    int         IsSuperBox();
+
+    int         DumpReadable( FILE *, int nIndentLevel = 0 );
+
+    VSILFILE   *GetFILE() { return fpVSIL; }
+
+    const GByte *GetUUID() { return abyUUID; }
+
+    // write support
+    void        SetType( const char * );
+    void        SetWritableData( int nLength, const GByte *pabyData );
+    void        AppendWritableData( int nLength, const void *pabyDataIn );
+    void        AppendUInt32( GUInt32 nVal );
+    void        AppendUInt16( GUInt16 nVal );
+    void        AppendUInt8( GByte nVal );
+    const GByte*GetWritableData() { return pabyData; }
+
+    // factory methods.
+    static GDALJP2Box *CreateSuperBox( const char* pszType,
+                                       int nCount, GDALJP2Box **papoBoxes );
+    static GDALJP2Box *CreateAsocBox( int nCount, GDALJP2Box **papoBoxes );
+    static GDALJP2Box *CreateLblBox( const char *pszLabel );
+    static GDALJP2Box *CreateLabelledXMLAssoc( const char *pszLabel,
+                                               const char *pszXML );
+    static GDALJP2Box *CreateUUIDBox( const GByte *pabyUUID, 
+                                      int nDataSize, const GByte *pabyData );
+};
+
+/************************************************************************/
+/*                           GDALJP2Metadata                            */
+/************************************************************************/
+
+typedef struct _GDALJP2GeoTIFFBox GDALJP2GeoTIFFBox;
+
+class CPL_DLL GDALJP2Metadata
+
+{
+private:
+    void    CollectGMLData( GDALJP2Box * );
+    int     GMLSRSLookup( const char *pszURN );
+
+    int    nGeoTIFFBoxesCount;
+    GDALJP2GeoTIFFBox  *pasGeoTIFFBoxes;
+
+    int    nMSIGSize;
+    GByte  *pabyMSIGData;
+    
+    int      GetGMLJP2GeoreferencingInfo( int& nEPSGCode,
+                                          double adfOrigin[2],
+                                          double adfXVector[2],
+                                          double adfYVector[2],
+                                          const char*& pszComment,
+                                          CPLString& osDictBox,
+                                          int& bNeedAxisFlip );
+    static CPLXMLNode* CreateGDALMultiDomainMetadataXML(
+                                       GDALDataset* poSrcDS,
+                                       int bMainMDDomainOnly );
+
+public:
+    char  **papszGMLMetadata;
+    
+    int     bHaveGeoTransform;
+    double  adfGeoTransform[6];
+    int     bPixelIsPoint;
+
+    char   *pszProjection;
+
+    int         nGCPCount;
+    GDAL_GCP    *pasGCPList;
+    
+    char **papszRPCMD;
+
+    char  **papszMetadata; /* TIFFTAG_?RESOLUTION* for now from resd box */
+    char   *pszXMPMetadata;
+    char   *pszGDALMultiDomainMetadata; /* as serialized XML */
+    char   *pszXMLIPR; /* if an IPR box with XML content has been found */
+
+public:
+            GDALJP2Metadata();
+            ~GDALJP2Metadata();
+
+    int     ReadBoxes( VSILFILE * fpVSIL );
+
+    int     ParseJP2GeoTIFF();
+    int     ParseMSIG();
+    int     ParseGMLCoverageDesc();
+
+    int     ReadAndParse( VSILFILE * fpVSIL );
+    int     ReadAndParse( const char *pszFilename );
+
+    // Write oriented. 
+    void    SetProjection( const char *pszWKT );
+    void    SetGeoTransform( double * );
+    void    SetGCPs( int, const GDAL_GCP * );
+    void    SetRPCMD( char** papszRPCMDIn );
+    
+    GDALJP2Box *CreateJP2GeoTIFF();
+    GDALJP2Box *CreateGMLJP2( int nXSize, int nYSize );
+    GDALJP2Box *CreateGMLJP2V2( int nXSize, int nYSize,
+                                const char* pszDefFilename,
+                                GDALDataset* poSrcDS );
+
+    static GDALJP2Box* CreateGDALMultiDomainMetadataXMLBox(
+                                       GDALDataset* poSrcDS,
+                                       int bMainMDDomainOnly );
+    static GDALJP2Box** CreateXMLBoxes( GDALDataset* poSrcDS,
+                                        int* pnBoxes );
+    static GDALJP2Box *CreateXMPBox ( GDALDataset* poSrcDS );
+    static GDALJP2Box *CreateIPRBox ( GDALDataset* poSrcDS );
+    static int   IsUUID_MSI(const GByte *abyUUID);
+    static int   IsUUID_XMP(const GByte *abyUUID);
+};
+
+#endif /* ndef GDAL_JP2READER_H_INCLUDED */

+ 40 - 0
libpq_test/include/gdaljp2metadatagenerator.h

@@ -0,0 +1,40 @@
+/******************************************************************************
+ * $Id: gdaljp2metadatagenerator.h 29048 2015-04-29 14:48:33Z rouault $
+ *
+ * Project:  GDAL 
+ * Purpose:  GDALJP2Metadata: metadata generator
+ * Author:   Even Rouault <even dot rouault at spatialys dot com>
+ *
+ ******************************************************************************
+ * Copyright (c) 2015, European Union Satellite Centre
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDAL_JP2METADATA_GENERATOR_H_INCLUDED
+#define GDAL_JP2METADATA_GENERATOR_H_INCLUDED
+
+
+#include "cpl_string.h"
+#include "cpl_minixml.h"
+
+CPLXMLNode* GDALGMLJP2GenerateMetadata(const CPLString& osTemplateFile,
+                                       const CPLString& osSourceFile);
+
+#endif /* GDAL_JP2METADATA_GENERATOR_H_INCLUDED */

+ 571 - 0
libpq_test/include/gdalsse_priv.h

@@ -0,0 +1,571 @@
+/******************************************************************************
+ * $Id: gdalsse_priv.h 28877 2015-04-08 23:11:36Z rouault $
+ *
+ * Project:  GDAL
+ * Purpose:  SSE2 helper
+ * Author:   Even Rouault <even dot rouault at spatialys dot com>
+ *
+ ******************************************************************************
+ * Copyright (c) 2014, Even Rouault <even dot rouault at spatialys dot com>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDALSSE_PRIV_H_INCLUDED
+#define GDALSSE_PRIV_H_INCLUDED
+
+/* We restrict to 64bit processors because they are guaranteed to have SSE2 */
+/* Could possibly be used too on 32bit, but we would need to check at runtime */
+#if (defined(__x86_64) || defined(_M_X64)) && !defined(USE_SSE2_EMULATION)
+
+/* Requires SSE2 */
+#include <emmintrin.h>
+#include <string.h>
+
+class XMMReg2Double
+{
+  public:
+    __m128d xmm;
+
+    XMMReg2Double() {}
+    XMMReg2Double(double  val)  { xmm = _mm_load_sd (&val); }
+    XMMReg2Double(const XMMReg2Double& other) : xmm(other.xmm) {}
+
+    static inline XMMReg2Double Zero()
+    {
+        XMMReg2Double reg;
+        reg.Zeroize();
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2Val(const double* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2Val(const float* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2ValAligned(const double* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2ValAligned(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2Val(const unsigned char* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2Val(const short* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2Val(const unsigned short* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+    
+    inline void nsLoad2Val(const double* ptr)
+    {
+        xmm = _mm_loadu_pd(ptr);
+    }
+
+    inline void nsLoad2ValAligned(const double* pval)
+    {
+        xmm = _mm_load_pd(pval);
+    }
+
+    inline void nsLoad2Val(const float* pval)
+    {
+        __m128 temp1 = _mm_load_ss(pval);
+        __m128 temp2 = _mm_load_ss(pval + 1);
+        temp1 = _mm_shuffle_ps(temp1, temp2, _MM_SHUFFLE(1,0,1,0));
+        temp1 = _mm_shuffle_ps(temp1, temp1, _MM_SHUFFLE(3,3,2,0));
+        xmm = _mm_cvtps_pd(temp1);
+    }
+
+    inline void nsLoad2Val(const unsigned char* ptr)
+    {
+        __m128i xmm_i = _mm_cvtsi32_si128(*(unsigned short*)(ptr));
+        xmm_i = _mm_unpacklo_epi8(xmm_i, _mm_setzero_si128());
+        xmm_i = _mm_unpacklo_epi16(xmm_i, _mm_setzero_si128());
+        xmm = _mm_cvtepi32_pd(xmm_i);
+    }
+
+    inline void nsLoad2Val(const short* ptr)
+    {
+        int i;
+        memcpy(&i, ptr, 4);
+        __m128i xmm_i = _mm_cvtsi32_si128(i);
+        xmm_i = _mm_unpacklo_epi16(xmm_i,xmm_i); /* 0|0|0|0|0|0|b|a --> 0|0|0|0|b|b|a|a */
+        xmm_i = _mm_srai_epi32(xmm_i, 16);       /* 0|0|0|0|b|b|a|a --> 0|0|0|0|sign(b)|b|sign(a)|a */
+        xmm = _mm_cvtepi32_pd(xmm_i);
+    }
+
+    inline void nsLoad2Val(const unsigned short* ptr)
+    {
+        int i;
+        memcpy(&i, ptr, 4);
+        __m128i xmm_i = _mm_cvtsi32_si128(i);
+        xmm_i = _mm_unpacklo_epi16(xmm_i,xmm_i); /* 0|0|0|0|0|0|b|a --> 0|0|0|0|b|b|a|a */
+        xmm_i = _mm_srli_epi32(xmm_i, 16);       /* 0|0|0|0|b|b|a|a --> 0|0|0|0|0|b|0|a */
+        xmm = _mm_cvtepi32_pd(xmm_i);
+    }
+    
+    static inline void Load4Val(const unsigned char* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        __m128i xmm_i = _mm_cvtsi32_si128(*(int*)(ptr));
+        xmm_i = _mm_unpacklo_epi8(xmm_i, _mm_setzero_si128());
+        xmm_i = _mm_unpacklo_epi16(xmm_i, _mm_setzero_si128());
+        low.xmm = _mm_cvtepi32_pd(xmm_i);
+        high.xmm =  _mm_cvtepi32_pd(_mm_shuffle_epi32(xmm_i,_MM_SHUFFLE(3,2,3,2)));
+    }
+
+    static inline void Load4Val(const short* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.nsLoad2Val(ptr);
+        high.nsLoad2Val(ptr+2);
+    }
+
+    static inline void Load4Val(const unsigned short* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.nsLoad2Val(ptr);
+        high.nsLoad2Val(ptr+2);
+    }
+
+    static inline void Load4Val(const double* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.nsLoad2Val(ptr);
+        high.nsLoad2Val(ptr+2);
+    }
+
+    static inline void Load4Val(const float* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        __m128 temp1 = _mm_loadu_ps(ptr);
+        __m128 temp2 = _mm_shuffle_ps(temp1, temp1, _MM_SHUFFLE(3,2,3,2));
+        low.xmm = _mm_cvtps_pd(temp1);
+        high.xmm = _mm_cvtps_pd(temp2);
+    }
+    
+    inline void Zeroize()
+    {
+        xmm = _mm_setzero_pd();
+    }
+
+    inline const XMMReg2Double& operator= (const XMMReg2Double& other)
+    {
+        xmm = other.xmm;
+        return *this;
+    }
+
+    inline const XMMReg2Double& operator+= (const XMMReg2Double& other)
+    {
+        xmm = _mm_add_pd(xmm, other.xmm);
+        return *this;
+    }
+
+    inline XMMReg2Double operator+ (const XMMReg2Double& other)
+    {
+        XMMReg2Double ret;
+        ret.xmm = _mm_add_pd(xmm, other.xmm);
+        return ret;
+    }
+
+    inline XMMReg2Double operator- (const XMMReg2Double& other)
+    {
+        XMMReg2Double ret;
+        ret.xmm = _mm_sub_pd(xmm, other.xmm);
+        return ret;
+    }
+
+    inline XMMReg2Double operator* (const XMMReg2Double& other)
+    {
+        XMMReg2Double ret;
+        ret.xmm = _mm_mul_pd(xmm, other.xmm);
+        return ret;
+    }
+
+    inline const XMMReg2Double& operator*= (const XMMReg2Double& other)
+    {
+        xmm = _mm_mul_pd(xmm, other.xmm);
+        return *this;
+    }
+
+    inline void AddLowAndHigh()
+    {
+        __m128d xmm2;
+        xmm2 = _mm_shuffle_pd(xmm,xmm,_MM_SHUFFLE2(0,1)); /* transfer high word into low word of xmm2 */
+        xmm = _mm_add_pd(xmm, xmm2);
+    }
+    
+    inline void Store2Double(double* pval)
+    {
+        _mm_storeu_pd(pval, xmm);
+    }
+    
+    inline void Store2DoubleAligned(double* pval)
+    {
+        _mm_store_pd(pval, xmm);
+    }
+
+    inline operator double () const
+    {
+        double val;
+        _mm_store_sd(&val, xmm);
+        return val;
+    }
+};
+
+#else
+
+#warning "Software emulation of SSE2 !"
+
+class XMMReg2Double
+{
+  public:
+    double low;
+    double high;
+
+    XMMReg2Double() {}
+    XMMReg2Double(double  val)  { low = val; high = 0.0; }
+    XMMReg2Double(const XMMReg2Double& other) : low(other.low), high(other.high) {}
+
+    static inline XMMReg2Double Zero()
+    {
+        XMMReg2Double reg;
+        reg.Zeroize();
+        return reg;
+    }
+    
+    static inline XMMReg2Double Load2Val(const double* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2ValAligned(const double* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2ValAligned(ptr);
+        return reg;
+    }
+    
+    static inline XMMReg2Double Load2Val(const float* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2Val(const unsigned char* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    static inline XMMReg2Double Load2Val(const short* ptr)
+    {
+        XMMReg2Double reg;
+        reg.nsLoad2Val(ptr);
+        return reg;
+    }
+
+    inline void nsLoad2Val(const double* pval)
+    {
+        low = pval[0];
+        high = pval[1];
+    }
+
+    inline void nsLoad2ValAligned(const double* pval)
+    {
+        low = pval[0];
+        high = pval[1];
+    }
+
+    inline void nsLoad2Val(const float* pval)
+    {
+        low = pval[0];
+        high = pval[1];
+    }
+
+    inline void nsLoad2Val(const unsigned char* ptr)
+    {
+        low = ptr[0];
+        high = ptr[1];
+    }
+
+    inline void nsLoad2Val(const short* ptr)
+    {
+        low = ptr[0];
+        high = ptr[1];
+    }
+
+    inline void nsLoad2Val(const unsigned short* ptr)
+    {
+        low = ptr[0];
+        high = ptr[1];
+    }
+    
+    static inline void Load4Val(const unsigned char* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.low = ptr[0];
+        low.high = ptr[1];
+        high.low = ptr[2];
+        high.high = ptr[3];
+    }
+
+    static inline void Load4Val(const short* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.nsLoad2Val(ptr);
+        high.nsLoad2Val(ptr+2);
+    }
+
+    static inline void Load4Val(const unsigned short* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.nsLoad2Val(ptr);
+        high.nsLoad2Val(ptr+2);
+    }
+
+    static inline void Load4Val(const double* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.nsLoad2Val(ptr);
+        high.nsLoad2Val(ptr+2);
+    }
+
+    static inline void Load4Val(const float* ptr, XMMReg2Double& low, XMMReg2Double& high)
+    {
+        low.nsLoad2Val(ptr);
+        high.nsLoad2Val(ptr+2);
+    }
+
+    inline void Zeroize()
+    {
+        low = 0.0;
+        high = 0.0;
+    }
+
+    inline const XMMReg2Double& operator= (const XMMReg2Double& other)
+    {
+        low = other.low;
+        high = other.high;
+        return *this;
+    }
+
+    inline const XMMReg2Double& operator+= (const XMMReg2Double& other)
+    {
+        low += other.low;
+        high += other.high;
+        return *this;
+    }
+
+    inline XMMReg2Double operator+ (const XMMReg2Double& other)
+    {
+        XMMReg2Double ret;
+        ret.low = low + other.low;
+        ret.high = high + other.high;
+        return ret;
+    }
+
+    inline XMMReg2Double operator- (const XMMReg2Double& other)
+    {
+        XMMReg2Double ret;
+        ret.low = low - other.low;
+        ret.high = high - other.high;
+        return ret;
+    }
+
+    inline XMMReg2Double operator* (const XMMReg2Double& other)
+    {
+        XMMReg2Double ret;
+        ret.low = low * other.low;
+        ret.high = high * other.high;
+        return ret;
+    }
+
+    inline const XMMReg2Double& operator*= (const XMMReg2Double& other)
+    {
+        low *= other.low;
+        high *= other.high;
+        return *this;
+    }
+
+    inline void AddLowAndHigh()
+    {
+        double add = low + high;
+        low = add;
+        high = add;
+    }
+
+    inline void Store2Double(double* pval)
+    {
+        pval[0] = low;
+        pval[1] = high;
+    }
+    
+    inline void Store2DoubleAligned(double* pval)
+    {
+        pval[0] = low;
+        pval[1] = high;
+    }
+
+    inline operator double () const
+    {
+        return low;
+    }
+};
+
+#endif /*  defined(__x86_64) || defined(_M_X64) */
+
+class XMMReg4Double
+{
+  public:
+    XMMReg2Double low, high;
+
+    XMMReg4Double() {}
+    XMMReg4Double(const XMMReg4Double& other) : low(other.low), high(other.high) {}
+
+    static inline XMMReg4Double Zero()
+    {
+        XMMReg4Double reg;
+        reg.low.Zeroize();
+        reg.high.Zeroize();
+        return reg;
+    }
+    
+    static inline XMMReg4Double Load4Val(const unsigned char* ptr)
+    {
+        XMMReg4Double reg;
+        XMMReg2Double::Load4Val(ptr, reg.low, reg.high);
+        return reg;
+    }
+
+    static inline XMMReg4Double Load4Val(const short* ptr)
+    {
+        XMMReg4Double reg;
+        reg.low.nsLoad2Val(ptr);
+        reg.high.nsLoad2Val(ptr+2);
+        return reg;
+    }
+
+    static inline XMMReg4Double Load4Val(const unsigned short* ptr)
+    {
+        XMMReg4Double reg;
+        reg.low.nsLoad2Val(ptr);
+        reg.high.nsLoad2Val(ptr+2);
+        return reg;
+    }
+
+    static inline XMMReg4Double Load4Val(const double* ptr)
+    {
+        XMMReg4Double reg;
+        reg.low.nsLoad2Val(ptr);
+        reg.high.nsLoad2Val(ptr+2);
+        return reg;
+    }
+
+    static inline XMMReg4Double Load4ValAligned(const double* ptr)
+    {
+        XMMReg4Double reg;
+        reg.low.nsLoad2ValAligned(ptr);
+        reg.high.nsLoad2ValAligned(ptr+2);
+        return reg;
+    }
+
+    static inline XMMReg4Double Load4Val(const float* ptr)
+    {
+        XMMReg4Double reg;
+        XMMReg2Double::Load4Val(ptr, reg.low, reg.high);
+        return reg;
+    }
+    
+    inline const XMMReg4Double& operator= (const XMMReg4Double& other)
+    {
+        low = other.low;
+        high = other.high;
+        return *this;
+    }
+
+    inline const XMMReg4Double& operator+= (const XMMReg4Double& other)
+    {
+        low += other.low;
+        high += other.high;
+        return *this;
+    }
+
+    inline XMMReg4Double operator+ (const XMMReg4Double& other)
+    {
+        XMMReg4Double ret;
+        ret.low = low + other.low;
+        ret.high = high + other.high;
+        return ret;
+    }
+
+    inline XMMReg4Double operator- (const XMMReg4Double& other)
+    {
+        XMMReg4Double ret;
+        ret.low = low - other.low;
+        ret.high = high - other.high;
+        return ret;
+    }
+
+    inline XMMReg4Double operator* (const XMMReg4Double& other)
+    {
+        XMMReg4Double ret;
+        ret.low = low * other.low;
+        ret.high = high * other.high;
+        return ret;
+    }
+
+    inline const XMMReg4Double& operator*= (const XMMReg4Double& other)
+    {
+        low *= other.low;
+        high *= other.high;
+        return *this;
+    }
+
+    inline void AddLowAndHigh()
+    {
+        low = low + high;
+        low.AddLowAndHigh();
+    }
+
+    inline XMMReg2Double& GetLow()
+    {
+        return low;
+    }
+};
+
+#endif /* GDALSSE_PRIV_H_INCLUDED */

+ 450 - 0
libpq_test/include/gdalwarper.h

@@ -0,0 +1,450 @@
+/******************************************************************************
+ * $Id: gdalwarper.h 29330 2015-06-14 12:11:11Z rouault $
+ *
+ * Project:  GDAL High Performance Warper
+ * Purpose:  Prototypes, and definitions for warping related work.
+ * Author:   Frank Warmerdam, warmerdam@pobox.com
+ *
+ ******************************************************************************
+ * Copyright (c) 2003, Frank Warmerdam
+ * Copyright (c) 2009-2012, Even Rouault <even dot rouault at mines-paris dot org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#ifndef GDALWARPER_H_INCLUDED
+#define GDALWARPER_H_INCLUDED
+
+/**
+ * \file gdalwarper.h
+ *
+ * GDAL warper related entry points and definitions.  Eventually it is
+ * expected that this file will be mostly private to the implementation,
+ * and the public C entry points will be available in gdal_alg.h.
+ */
+
+#include "gdal_alg.h"
+#include "cpl_minixml.h"
+#include "cpl_multiproc.h"
+
+CPL_C_START
+
+/* Note: values are selected to be consistent with GDALRIOResampleAlg of gcore/gdal.h */ 
+/*! Warp Resampling Algorithm */
+typedef enum {
+  /*! Nearest neighbour (select on one input pixel) */ GRA_NearestNeighbour=0,
+  /*! Bilinear (2x2 kernel) */                         GRA_Bilinear=1,
+  /*! Cubic Convolution Approximation (4x4 kernel) */  GRA_Cubic=2,
+  /*! Cubic B-Spline Approximation (4x4 kernel) */     GRA_CubicSpline=3,
+  /*! Lanczos windowed sinc interpolation (6x6 kernel) */ GRA_Lanczos=4,
+  /*! Average (computes the average of all non-NODATA contributing pixels) */ GRA_Average=5, 
+  /*! Mode (selects the value which appears most often of all the sampled points) */ GRA_Mode=6,
+  // GRA_Gauss=7 reserved.
+  /*! Max (selects maximum of all non-NODATA contributing pixels) */ GRA_Max=8,
+  /*! Min (selects minimum of all non-NODATA contributing pixels) */ GRA_Min=9,
+  /*! Med (selects median of all non-NODATA contributing pixels) */ GRA_Med=10,
+  /*! Q1 (selects first quartile of all non-NODATA contributing pixels) */ GRA_Q1=11,
+  /*! Q3 (selects third quartile of all non-NODATA contributing pixels) */ GRA_Q3=12
+} GDALResampleAlg;
+
+/*! GWKAverageOrMode Algorithm */
+typedef enum {
+    /*! Average */ GWKAOM_Average=1,
+    /*! Mode */ GWKAOM_Fmode=2,
+    /*! Mode of GDT_Byte, GDT_UInt16, or GDT_Int16 */ GWKAOM_Imode=3,
+    /*! Maximum */ GWKAOM_Max=4,
+    /*! Minimum */ GWKAOM_Min=5,
+    /*! Quantile */ GWKAOM_Quant=6
+} GWKAverageOrModeAlg;
+
+typedef int 
+(*GDALMaskFunc)( void *pMaskFuncArg,
+                 int nBandCount, GDALDataType eType, 
+                 int nXOff, int nYOff, 
+                 int nXSize, int nYSize,
+                 GByte **papabyImageData, 
+                 int bMaskIsFloat, void *pMask );
+
+CPLErr CPL_DLL 
+GDALWarpNoDataMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
+                      int nXOff, int nYOff, int nXSize, int nYSize,
+                      GByte **papabyImageData, int bMaskIsFloat,
+                      void *pValidityMask, int* pbOutAllValid );
+
+CPLErr CPL_DLL 
+GDALWarpDstAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
+                        int nXOff, int nYOff, int nXSize, int nYSize,
+                        GByte ** /*ppImageData */,
+                        int bMaskIsFloat, void *pValidityMask );
+CPLErr CPL_DLL 
+GDALWarpSrcAlphaMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
+                        int nXOff, int nYOff, int nXSize, int nYSize,
+                        GByte ** /*ppImageData */,
+                        int bMaskIsFloat, void *pValidityMask, int* pbOutAllOpaque );
+
+CPLErr CPL_DLL 
+GDALWarpSrcMaskMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
+                       int nXOff, int nYOff, int nXSize, int nYSize,
+                       GByte ** /*ppImageData */,
+                       int bMaskIsFloat, void *pValidityMask );
+
+CPLErr CPL_DLL 
+GDALWarpCutlineMasker( void *pMaskFuncArg, int nBandCount, GDALDataType eType,
+                       int nXOff, int nYOff, int nXSize, int nYSize,
+                       GByte ** /* ppImageData */,
+                       int bMaskIsFloat, void *pValidityMask );
+
+/************************************************************************/
+/*                           GDALWarpOptions                            */
+/************************************************************************/
+
+/** Warp control options for use with GDALWarpOperation::Initialize()  */
+typedef struct {
+    
+    char              **papszWarpOptions;  
+
+    /*! In bytes, 0.0 for internal default */
+    double              dfWarpMemoryLimit; 
+
+    /*! Resampling algorithm to use */
+    GDALResampleAlg     eResampleAlg;
+
+    /*! data type to use during warp operation, GDT_Unknown lets the algorithm
+        select the type */
+    GDALDataType        eWorkingDataType;
+
+    /*! Source image dataset. */
+    GDALDatasetH	hSrcDS;
+
+    /*! Destination image dataset - may be NULL if only using GDALWarpOperation::WarpRegionToBuffer(). */
+    GDALDatasetH        hDstDS;
+
+    /*! Number of bands to process, may be 0 to select all bands. */
+    int                 nBandCount;
+    
+    /*! The band numbers for the source bands to process (1 based) */
+    int                *panSrcBands;
+
+    /*! The band numbers for the destination bands to process (1 based) */
+    int                *panDstBands;
+
+    /*! The source band so use as an alpha (transparency) value, 0=disabled */
+    int                nSrcAlphaBand;
+
+    /*! The dest. band so use as an alpha (transparency) value, 0=disabled */
+    int                nDstAlphaBand;
+
+    /*! The "nodata" value real component for each input band, if NULL there isn't one */
+    double             *padfSrcNoDataReal;
+    /*! The "nodata" value imaginary component - may be NULL even if real 
+      component is provided. */
+    double             *padfSrcNoDataImag;
+
+    /*! The "nodata" value real component for each output band, if NULL there isn't one */
+    double             *padfDstNoDataReal;
+    /*! The "nodata" value imaginary component - may be NULL even if real 
+      component is provided. */
+    double             *padfDstNoDataImag;
+
+    /*! GDALProgressFunc() compatible progress reporting function, or NULL
+      if there isn't one. */
+    GDALProgressFunc    pfnProgress;
+
+    /*! Callback argument to be passed to pfnProgress. */
+    void               *pProgressArg;
+
+    /*! Type of spatial point transformer function */
+    GDALTransformerFunc pfnTransformer;
+
+    /*! Handle to image transformer setup structure */
+    void                *pTransformerArg;
+
+    GDALMaskFunc       *papfnSrcPerBandValidityMaskFunc;
+    void              **papSrcPerBandValidityMaskFuncArg;
+    
+    GDALMaskFunc        pfnSrcValidityMaskFunc;
+    void               *pSrcValidityMaskFuncArg;
+    
+    GDALMaskFunc        pfnSrcDensityMaskFunc;
+    void               *pSrcDensityMaskFuncArg;
+
+    GDALMaskFunc        pfnDstDensityMaskFunc;
+    void               *pDstDensityMaskFuncArg;
+
+    GDALMaskFunc        pfnDstValidityMaskFunc;
+    void               *pDstValidityMaskFuncArg;
+
+    CPLErr              (*pfnPreWarpChunkProcessor)( void *pKern, void *pArg );
+    void               *pPreWarpProcessorArg;
+    
+    CPLErr              (*pfnPostWarpChunkProcessor)( void *pKern, void *pArg);
+    void               *pPostWarpProcessorArg;
+
+    /*! Optional OGRPolygonH for a masking cutline. */
+    void               *hCutline;
+
+    /*! Optional blending distance to apply across cutline in pixels, default is zero. */
+    double              dfCutlineBlendDist;
+
+} GDALWarpOptions;
+
+GDALWarpOptions CPL_DLL * CPL_STDCALL GDALCreateWarpOptions(void);
+void CPL_DLL CPL_STDCALL GDALDestroyWarpOptions( GDALWarpOptions * );
+GDALWarpOptions CPL_DLL * CPL_STDCALL
+GDALCloneWarpOptions( const GDALWarpOptions * );
+
+CPLXMLNode CPL_DLL * CPL_STDCALL
+      GDALSerializeWarpOptions( const GDALWarpOptions * );
+GDALWarpOptions CPL_DLL * CPL_STDCALL
+      GDALDeserializeWarpOptions( CPLXMLNode * );
+
+/************************************************************************/
+/*                         GDALReprojectImage()                         */
+/************************************************************************/
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
+                    GDALDatasetH hDstDS, const char *pszDstWKT,
+                    GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
+                    double dfMaxError,
+                    GDALProgressFunc pfnProgress, void *pProgressArg, 
+                    GDALWarpOptions *psOptions );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALCreateAndReprojectImage( GDALDatasetH hSrcDS, const char *pszSrcWKT, 
+                    const char *pszDstFilename, const char *pszDstWKT,
+                    GDALDriverH hDstDriver, char **papszCreateOptions,
+                    GDALResampleAlg eResampleAlg, double dfWarpMemoryLimit,
+                    double dfMaxError,
+                    GDALProgressFunc pfnProgress, void *pProgressArg, 
+                    GDALWarpOptions *psOptions );
+
+/************************************************************************/
+/*                           VRTWarpedDataset                           */
+/************************************************************************/
+
+GDALDatasetH CPL_DLL CPL_STDCALL
+GDALAutoCreateWarpedVRT( GDALDatasetH hSrcDS, 
+                         const char *pszSrcWKT, const char *pszDstWKT, 
+                         GDALResampleAlg eResampleAlg, 
+                         double dfMaxError, const GDALWarpOptions *psOptions );
+
+GDALDatasetH CPL_DLL CPL_STDCALL 
+GDALCreateWarpedVRT( GDALDatasetH hSrcDS, 
+                     int nPixels, int nLines, double *padfGeoTransform,
+                     GDALWarpOptions *psOptions );
+
+CPLErr CPL_DLL CPL_STDCALL
+GDALInitializeWarpedVRT( GDALDatasetH hDS, 
+                         GDALWarpOptions *psWO );
+
+CPL_C_END
+
+#ifdef __cplusplus 
+
+/************************************************************************/
+/*                            GDALWarpKernel                            */
+/*                                                                      */
+/*      This class represents the lowest level of abstraction.  It      */
+/*      is holds the imagery for one "chunk" of a warp, and the         */
+/*      pre-prepared masks.  All IO is done before and after it's       */
+/*      operation.  This class is not normally used by the              */
+/*      application.                                                    */
+/************************************************************************/
+
+// This is the number of dummy pixels that must be reserved in source arrays
+// in order to satisfy assumptions made in GWKResample(), and more specifically
+// by GWKGetPixelRow() that always read a even number of pixels. So if we are
+// in the situation to read the last pixel of the source array, we need 1 extra
+// dummy pixel to avoid reading out of bounds.
+#define WARP_EXTRA_ELTS    1
+
+class CPL_DLL GDALWarpKernel
+{
+public:
+    char              **papszWarpOptions;
+
+    GDALResampleAlg	eResample;
+    GDALDataType        eWorkingDataType;
+    int                 nBands;
+
+    int                 nSrcXSize;
+    int                 nSrcYSize;
+    int                 nSrcXExtraSize; /* extra pixels (included in nSrcXSize) reserved for filter window. Should be ignored in scale computation */
+    int                 nSrcYExtraSize; /* extra pixels (included in nSrcYSize) reserved for filter window. Should be ignored in scale computation */
+    GByte               **papabySrcImage; /* each subarray must have WARP_EXTRA_ELTS at the end */
+
+    GUInt32           **papanBandSrcValid; /* each subarray must have WARP_EXTRA_ELTS at the end */
+    GUInt32            *panUnifiedSrcValid; /* must have WARP_EXTRA_ELTS at the end */
+    float              *pafUnifiedSrcDensity; /* must have WARP_EXTRA_ELTS at the end */
+
+    int                 nDstXSize;
+    int                 nDstYSize;
+    GByte             **papabyDstImage;
+    GUInt32            *panDstValid;
+    float              *pafDstDensity;
+
+    double              dfXScale;   // Resampling scale, i.e.
+    double              dfYScale;   // nDstSize/nSrcSize.
+    double              dfXFilter;  // Size of filter kernel.
+    double              dfYFilter;
+    int                 nXRadius;   // Size of window to filter.
+    int                 nYRadius;
+    int                 nFiltInitX; // Filtering offset
+    int                 nFiltInitY;
+    
+    int                 nSrcXOff;
+    int                 nSrcYOff;
+
+    int                 nDstXOff;
+    int                 nDstYOff;
+        
+    GDALTransformerFunc pfnTransformer;
+    void                *pTransformerArg;
+
+    GDALProgressFunc    pfnProgress;
+    void                *pProgress;
+
+    double              dfProgressBase;
+    double              dfProgressScale;
+    
+    double              *padfDstNoDataReal;
+
+                       GDALWarpKernel();
+    virtual           ~GDALWarpKernel();
+
+    CPLErr              Validate();
+    CPLErr              PerformWarp();
+};
+
+/************************************************************************/
+/*                         GDALWarpOperation()                          */
+/*                                                                      */
+/*      This object is application created, or created by a higher      */
+/*      level convenience function.  It is responsible for              */
+/*      subdividing the operation into chunks, loading and saving       */
+/*      imagery, and establishing the varios validity and density       */
+/*      masks.  Actual resampling is done by the GDALWarpKernel.        */
+/************************************************************************/
+
+typedef struct _GDALWarpChunk GDALWarpChunk;
+
+class CPL_DLL GDALWarpOperation {
+private:
+    GDALWarpOptions *psOptions;
+
+    void            WipeOptions();
+    int             ValidateOptions();
+
+    CPLErr          ComputeSourceWindow( int nDstXOff, int nDstYOff, 
+                                         int nDstXSize, int nDstYSize,
+                                         int *pnSrcXOff, int *pnSrcYOff, 
+                                         int *pnSrcXSize, int *pnSrcYSize,
+                                         int *pnSrcXExtraSize, int *pnSrcYExtraSize,
+                                         double* pdfSrcFillRatio );
+
+    CPLErr          CreateKernelMask( GDALWarpKernel *, int iBand, 
+                                      const char *pszType );
+
+    CPLMutex        *hIOMutex;
+    CPLMutex        *hWarpMutex;
+
+    int             nChunkListCount;
+    int             nChunkListMax;
+    GDALWarpChunk  *pasChunkList;
+
+    int             bReportTimings;
+    unsigned long   nLastTimeReported;
+
+    void            WipeChunkList();
+    CPLErr          CollectChunkList( int nDstXOff, int nDstYOff, 
+                                      int nDstXSize, int nDstYSize );
+    void            ReportTiming( const char * );
+    
+public:
+                    GDALWarpOperation();
+    virtual        ~GDALWarpOperation();
+
+    CPLErr          Initialize( const GDALWarpOptions *psNewOptions );
+
+    const GDALWarpOptions         *GetOptions();
+
+    CPLErr          ChunkAndWarpImage( int nDstXOff, int nDstYOff, 
+                                       int nDstXSize, int nDstYSize );
+    CPLErr          ChunkAndWarpMulti( int nDstXOff, int nDstYOff, 
+                                       int nDstXSize, int nDstYSize );
+    CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
+                                int nDstXSize, int nDstYSize,
+                                int nSrcXOff=0, int nSrcYOff=0,
+                                int nSrcXSize=0, int nSrcYSize=0,
+                                double dfProgressBase=0.0, double dfProgressScale=1.0);
+    CPLErr          WarpRegion( int nDstXOff, int nDstYOff, 
+                                int nDstXSize, int nDstYSize,
+                                int nSrcXOff, int nSrcYOff,
+                                int nSrcXSize, int nSrcYSize,
+                                int nSrcXExtraSize, int nSrcYExtraSize,
+                                double dfProgressBase, double dfProgressScale);
+    CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
+                                        int nDstXSize, int nDstYSize, 
+                                        void *pDataBuf, 
+                                        GDALDataType eBufDataType,
+                                        int nSrcXOff=0, int nSrcYOff=0,
+                                        int nSrcXSize=0, int nSrcYSize=0,
+                                        double dfProgressBase=0.0, double dfProgressScale=1.0);
+    CPLErr          WarpRegionToBuffer( int nDstXOff, int nDstYOff, 
+                                        int nDstXSize, int nDstYSize, 
+                                        void *pDataBuf, 
+                                        GDALDataType eBufDataType,
+                                        int nSrcXOff, int nSrcYOff,
+                                        int nSrcXSize, int nSrcYSize,
+                                        int nSrcXExtraSize, int nSrcYExtraSize,
+                                        double dfProgressBase, double dfProgressScale);
+};
+
+#endif /* def __cplusplus */
+
+CPL_C_START
+
+typedef void * GDALWarpOperationH;
+
+GDALWarpOperationH CPL_DLL GDALCreateWarpOperation(const GDALWarpOptions* );
+void CPL_DLL GDALDestroyWarpOperation( GDALWarpOperationH );
+CPLErr CPL_DLL GDALChunkAndWarpImage( GDALWarpOperationH, int, int, int, int );
+CPLErr CPL_DLL GDALChunkAndWarpMulti( GDALWarpOperationH, int, int, int, int );
+CPLErr CPL_DLL GDALWarpRegion( GDALWarpOperationH,
+                               int, int, int, int, int, int, int, int );
+CPLErr CPL_DLL GDALWarpRegionToBuffer( GDALWarpOperationH, int, int, int, int,
+                                       void *, GDALDataType,
+                                       int, int, int, int );
+
+/************************************************************************/
+/*      Warping kernel functions                                        */
+/************************************************************************/
+
+int GWKGetFilterRadius(GDALResampleAlg eResampleAlg);
+
+typedef double (*FilterFuncType)(double dfX);
+FilterFuncType GWKGetFilterFunc(GDALResampleAlg eResampleAlg);
+
+typedef double (*FilterFunc4ValuesType)(double* padfVals);
+FilterFunc4ValuesType GWKGetFilterFunc4Values(GDALResampleAlg eResampleAlg);
+
+CPL_C_END
+
+#endif /* ndef GDAL_ALG_H_INCLUDED */

+ 198 - 0
libpq_test/include/gdalwarpkernel_opencl.h

@@ -0,0 +1,198 @@
+/******************************************************************************
+ * $Id: gdalwarpkernel_opencl.h 25068 2012-10-07 14:01:47Z rouault $
+ *
+ * Project:  OpenCL Image Reprojector
+ * Purpose:  Implementation of the GDALWarpKernel reprojector in OpenCL.
+ * Author:   Seth Price, seth@pricepages.org
+ *
+ ******************************************************************************
+ * Copyright (c) 2010, Seth Price <seth@pricepages.org>
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included
+ * in all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
+ * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ ****************************************************************************/
+
+#if defined(HAVE_OPENCL)
+
+/* The following relates to the profiling calls to 
+   clSetCommandQueueProperty() which are not available by default
+   with some OpenCL implementation (ie. ATI) */
+
+#if defined(DEBUG_OPENCL) && DEBUG_OPENCL == 1
+#define CL_USE_DEPRECATED_OPENCL_1_0_APIS
+#endif
+
+#ifdef __APPLE__
+#include <OpenCL/OpenCL.h>
+#else
+#include <CL/opencl.h>
+#endif
+
+#ifdef __cplusplus /* If this is a C++ compiler, use C linkage */
+extern "C" {
+#endif
+
+typedef enum {
+    OCL_Bilinear=10,
+    OCL_Cubic=11,
+    OCL_CubicSpline=12,
+    OCL_Lanczos=13
+} OCLResampAlg;
+
+typedef enum
+{
+    VENDOR_OTHER,
+    VENDOR_AMD,
+    VENDOR_INTEL
+} OCLVendor;
+
+struct oclWarper {
+    cl_command_queue queue;
+    cl_context context;
+    cl_device_id dev;
+    cl_kernel kern1;
+    cl_kernel kern4;
+    
+    int srcWidth;
+    int srcHeight;
+    int dstWidth;
+    int dstHeight;
+    
+    int useUnifiedSrcDensity;
+    int useUnifiedSrcValid;
+    int useDstDensity;
+    int useDstValid;
+    
+    int numBands;
+    int numImages;
+    OCLResampAlg resampAlg;
+    
+    cl_channel_type imageFormat;
+    cl_mem *realWorkCL;
+    union {
+        void **v;
+        char **c;
+        unsigned char **uc;
+        short **s;
+        unsigned short **us;
+        float **f;
+    } realWork;
+    
+    cl_mem *imagWorkCL;
+    union {
+        void **v;
+        char **c;
+        unsigned char **uc;
+        short **s;
+        unsigned short **us;
+        float **f;
+    } imagWork;
+    
+    cl_mem *dstRealWorkCL;
+    union {
+        void **v;
+        char **c;
+        unsigned char **uc;
+        short **s;
+        unsigned short **us;
+        float **f;
+    } dstRealWork;
+    
+    cl_mem *dstImagWorkCL;
+    union {
+        void **v;
+        char **c;
+        unsigned char **uc;
+        short **s;
+        unsigned short **us;
+        float **f;
+    } dstImagWork;
+    
+    unsigned int imgChSize1;
+    cl_channel_order imgChOrder1;
+    unsigned int imgChSize4;
+    cl_channel_order imgChOrder4;
+	char    useVec;
+    
+    cl_mem useBandSrcValidCL;
+    char *useBandSrcValid;
+    
+    cl_mem nBandSrcValidCL;
+    float *nBandSrcValid;
+    
+    cl_mem xyWorkCL;
+    float *xyWork;
+    
+    int xyWidth;
+    int xyHeight;
+    int coordMult;
+    
+    unsigned int xyChSize;
+    cl_channel_order xyChOrder;
+    
+    cl_mem fDstNoDataRealCL;
+    float *fDstNoDataReal;
+
+    OCLVendor eCLVendor;
+};
+
+struct oclWarper* GDALWarpKernelOpenCL_createEnv(int srcWidth, int srcHeight,
+                                                 int dstWidth, int dstHeight,
+                                                 cl_channel_type imageFormat,
+                                                 int numBands, int coordMult,
+                                                 int useImag, int useBandSrcValid,
+                                                 float *fDstDensity,
+                                                 double *dfDstNoDataReal,
+                                                 OCLResampAlg resampAlg, cl_int *envErr);
+
+cl_int GDALWarpKernelOpenCL_setSrcValid(struct oclWarper *warper,
+                                        int *bandSrcValid, int bandNum);
+
+cl_int GDALWarpKernelOpenCL_setSrcImg(struct oclWarper *warper, void *imgData,
+                                      int bandNum);
+
+cl_int GDALWarpKernelOpenCL_setDstImg(struct oclWarper *warper, void *imgData,
+                                      int bandNum);
+
+cl_int GDALWarpKernelOpenCL_setCoordRow(struct oclWarper *warper,
+                                        double *rowSrcX, double *rowSrcY,
+                                        double srcXOff, double srcYOff,
+                                        int *success, int rowNum);
+
+cl_int GDALWarpKernelOpenCL_runResamp(struct oclWarper *warper,
+                                      float *unifiedSrcDensity,
+                                      unsigned int *unifiedSrcValid,
+                                      float *dstDensity,
+                                      unsigned int *dstValid,
+                                      double dfXScale, double dfYScale,
+                                      double dfXFilter, double dfYFilter,
+                                      int nXRadius, int nYRadius,
+                                      int nFiltInitX, int nFiltInitY);
+
+cl_int GDALWarpKernelOpenCL_getRow(struct oclWarper *warper,
+                                   void **rowReal, void **rowImag,
+                                   int rowNum, int bandNum);
+
+cl_int GDALWarpKernelOpenCL_deleteEnv(struct oclWarper *warper);
+
+#ifdef __cplusplus /* If this is a C++ compiler, end C linkage */
+}
+#endif
+
+#endif /* defined(HAVE_OPENCL) */
+

+ 781 - 0
libpq_test/include/geodesic.h

@@ -0,0 +1,781 @@
+/**
+ * \file geodesic.h
+ * \brief Header for the geodesic routines in C
+ *
+ * This an implementation in C of the geodesic algorithms described in
+ * - C. F. F. Karney,
+ *   <a href="https://dx.doi.org/10.1007/s00190-012-0578-z">
+ *   Algorithms for geodesics</a>,
+ *   J. Geodesy <b>87</b>, 43--55 (2013);
+ *   DOI: <a href="https://dx.doi.org/10.1007/s00190-012-0578-z">
+ *   10.1007/s00190-012-0578-z</a>;
+ *   addenda: <a href="http://geographiclib.sf.net/geod-addenda.html">
+ *   geod-addenda.html</a>.
+ * .
+ * The principal advantages of these algorithms over previous ones (e.g.,
+ * Vincenty, 1975) are
+ * - accurate to round off for |<i>f</i>| &lt; 1/50;
+ * - the solution of the inverse problem is always found;
+ * - differential and integral properties of geodesics are computed.
+ *
+ * The shortest path between two points on the ellipsoid at (\e lat1, \e
+ * lon1) and (\e lat2, \e lon2) is called the geodesic.  Its length is
+ * \e s12 and the geodesic from point 1 to point 2 has forward azimuths
+ * \e azi1 and \e azi2 at the two end points.
+ *
+ * Traditionally two geodesic problems are considered:
+ * - the direct problem -- given \e lat1, \e lon1, \e s12, and \e azi1,
+ *   determine \e lat2, \e lon2, and \e azi2.  This is solved by the function
+ *   geod_direct().
+ * - the inverse problem -- given \e lat1, \e lon1, and \e lat2, \e lon2,
+ *   determine \e s12, \e azi1, and \e azi2.  This is solved by the function
+ *   geod_inverse().
+ *
+ * The ellipsoid is specified by its equatorial radius \e a (typically in
+ * meters) and flattening \e f.  The routines are accurate to round off with
+ * double precision arithmetic provided that |<i>f</i>| &lt; 1/50; for the
+ * WGS84 ellipsoid, the errors are less than 15 nanometers.  (Reasonably
+ * accurate results are obtained for |<i>f</i>| &lt; 1/5.)  For a prolate
+ * ellipsoid, specify \e f &lt; 0.
+ *
+ * The routines also calculate several other quantities of interest
+ * - \e S12 is the area between the geodesic from point 1 to point 2 and the
+ *   equator; i.e., it is the area, measured counter-clockwise, of the
+ *   quadrilateral with corners (\e lat1,\e lon1), (0,\e lon1), (0,\e lon2),
+ *   and (\e lat2,\e lon2).
+ * - \e m12, the reduced length of the geodesic is defined such that if
+ *   the initial azimuth is perturbed by \e dazi1 (radians) then the
+ *   second point is displaced by \e m12 \e dazi1 in the direction
+ *   perpendicular to the geodesic.  On a curved surface the reduced
+ *   length obeys a symmetry relation, \e m12 + \e m21 = 0.  On a flat
+ *   surface, we have \e m12 = \e s12.
+ * - \e M12 and \e M21 are geodesic scales.  If two geodesics are
+ *   parallel at point 1 and separated by a small distance \e dt, then
+ *   they are separated by a distance \e M12 \e dt at point 2.  \e M21
+ *   is defined similarly (with the geodesics being parallel to one
+ *   another at point 2).  On a flat surface, we have \e M12 = \e M21
+ *   = 1.
+ * - \e a12 is the arc length on the auxiliary sphere.  This is a
+ *   construct for converting the problem to one in spherical
+ *   trigonometry.  \e a12 is measured in degrees.  The spherical arc
+ *   length from one equator crossing to the next is always 180&deg;.
+ *
+ * If points 1, 2, and 3 lie on a single geodesic, then the following
+ * addition rules hold:
+ * - \e s13 = \e s12 + \e s23
+ * - \e a13 = \e a12 + \e a23
+ * - \e S13 = \e S12 + \e S23
+ * - \e m13 = \e m12 \e M23 + \e m23 \e M21
+ * - \e M13 = \e M12 \e M23 &minus; (1 &minus; \e M12 \e M21) \e
+ *   m23 / \e m12
+ * - \e M31 = \e M32 \e M21 &minus; (1 &minus; \e M23 \e M32) \e
+ *   m12 / \e m23
+ *
+ * The shortest distance returned by the solution of the inverse problem is
+ * (obviously) uniquely defined.  However, in a few special cases there are
+ * multiple azimuths which yield the same shortest distance.  Here is a
+ * catalog of those cases:
+ * - \e lat1 = &minus;\e lat2 (with neither point at a pole).  If \e azi1 =
+ *   \e azi2, the geodesic is unique.  Otherwise there are two geodesics
+ *   and the second one is obtained by setting [\e azi1, \e azi2] = [\e
+ *   azi2, \e azi1], [\e M12, \e M21] = [\e M21, \e M12], \e S12 =
+ *   &minus;\e S12.  (This occurs when the longitude difference is near
+ *   &plusmn;180&deg; for oblate ellipsoids.)
+ * - \e lon2 = \e lon1 &plusmn; 180&deg; (with neither point at a pole).
+ *   If \e azi1 = 0&deg; or &plusmn;180&deg;, the geodesic is unique.
+ *   Otherwise there are two geodesics and the second one is obtained by
+ *   setting [\e azi1, \e azi2] = [&minus;\e azi1, &minus;\e azi2], \e S12
+ *   = &minus;\e S12.  (This occurs when \e lat2 is near &minus;\e lat1 for
+ *   prolate ellipsoids.)
+ * - Points 1 and 2 at opposite poles.  There are infinitely many
+ *   geodesics which can be generated by setting [\e azi1, \e azi2] =
+ *   [\e azi1, \e azi2] + [\e d, &minus;\e d], for arbitrary \e d.  (For
+ *   spheres, this prescription applies when points 1 and 2 are
+ *   antipodal.)
+ * - \e s12 = 0 (coincident points).  There are infinitely many geodesics
+ *   which can be generated by setting [\e azi1, \e azi2] = [\e azi1, \e
+ *   azi2] + [\e d, \e d], for arbitrary \e d.
+ *
+ * These routines are a simple transcription of the corresponding C++ classes
+ * in <a href="http://geographiclib.sf.net"> GeographicLib</a>.  The "class
+ * data" is represented by the structs geod_geodesic, geod_geodesicline,
+ * geod_polygon and pointers to these objects are passed as initial arguments
+ * to the member functions.  Most of the internal comments have been retained.
+ * However, in the process of transcription some documentation has been lost
+ * and the documentation for the C++ classes, GeographicLib::Geodesic,
+ * GeographicLib::GeodesicLine, and GeographicLib::PolygonAreaT, should be
+ * consulted.  The C++ code remains the "reference implementation".  Think
+ * twice about restructuring the internals of the C code since this may make
+ * porting fixes from the C++ code more difficult.
+ *
+ * Copyright (c) Charles Karney (2012-2014) <charles@karney.com> and licensed
+ * under the MIT/X11 License.  For more information, see
+ * http://geographiclib.sourceforge.net/
+ *
+ * This library was distributed with
+ * <a href="../index.html">GeographicLib</a> 1.40.
+ **********************************************************************/
+
+#if !defined(GEODESIC_H)
+#define GEODESIC_H 1
+
+/**
+ * The major version of the geodesic library.  (This tracks the version of
+ * GeographicLib.)
+ **********************************************************************/
+#define GEODESIC_VERSION_MAJOR 1
+/**
+ * The minor version of the geodesic library.  (This tracks the version of
+ * GeographicLib.)
+ **********************************************************************/
+#define GEODESIC_VERSION_MINOR 40
+/**
+ * The patch level of the geodesic library.  (This tracks the version of
+ * GeographicLib.)
+ **********************************************************************/
+#define GEODESIC_VERSION_PATCH 0
+
+#if defined(__cplusplus)
+extern "C" {
+#endif
+
+  /**
+   * The struct containing information about the ellipsoid.  This must be
+   * initialized by geod_init() before use.
+   **********************************************************************/
+  struct geod_geodesic {
+    double a;                   /**< the equatorial radius */
+    double f;                   /**< the flattening */
+    /**< @cond SKIP */
+    double f1, e2, ep2, n, b, c2, etol2;
+    double A3x[6], C3x[15], C4x[21];
+    /**< @endcond */
+  };
+
+  /**
+   * The struct containing information about a single geodesic.  This must be
+   * initialized by geod_lineinit() before use.
+   **********************************************************************/
+  struct geod_geodesicline {
+    double lat1;                /**< the starting latitude */
+    double lon1;                /**< the starting longitude */
+    double azi1;                /**< the starting azimuth */
+    double a;                   /**< the equatorial radius */
+    double f;                   /**< the flattening */
+    /**< @cond SKIP */
+    double b, c2, f1, salp0, calp0, k2,
+      salp1, calp1, ssig1, csig1, dn1, stau1, ctau1, somg1, comg1,
+      A1m1, A2m1, A3c, B11, B21, B31, A4, B41;
+    double C1a[6+1], C1pa[6+1], C2a[6+1], C3a[6], C4a[6];
+    /**< @endcond */
+    unsigned caps;              /**< the capabilities */
+  };
+
+  /**
+   * The struct for accumulating information about a geodesic polygon.  This is
+   * used for computing the perimeter and area of a polygon.  This must be
+   * initialized by geod_polygon_init() before use.
+   **********************************************************************/
+  struct geod_polygon {
+    double lat;                 /**< the current latitude */
+    double lon;                 /**< the current longitude */
+    /**< @cond SKIP */
+    double lat0;
+    double lon0;
+    double A[2];
+    double P[2];
+    int polyline;
+    int crossings;
+    /**< @endcond */
+    unsigned num;               /**< the number of points so far */
+  };
+
+  /**
+   * Initialize a geod_geodesic object.
+   *
+   * @param[out] g a pointer to the object to be initialized.
+   * @param[in] a the equatorial radius (meters).
+   * @param[in] f the flattening.
+   **********************************************************************/
+  void geod_init(struct geod_geodesic* g, double a, double f);
+
+  /**
+   * Initialize a geod_geodesicline object.
+   *
+   * @param[out] l a pointer to the object to be initialized.
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] lat1 latitude of point 1 (degrees).
+   * @param[in] lon1 longitude of point 1 (degrees).
+   * @param[in] azi1 azimuth at point 1 (degrees).
+   * @param[in] caps bitor'ed combination of geod_mask() values specifying the
+   *   capabilities the geod_geodesicline object should possess, i.e., which
+   *   quantities can be returned in calls to geod_position() and
+   *   geod_genposition().
+   *
+   * \e g must have been initialized with a call to geod_init().  \e lat1
+   * should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e azi1
+   * should be in the range [&minus;540&deg;, 540&deg;).
+   *
+   * The geod_mask values are [see geod_mask()]:
+   * - \e caps |= GEOD_LATITUDE for the latitude \e lat2; this is
+   *   added automatically,
+   * - \e caps |= GEOD_LONGITUDE for the latitude \e lon2,
+   * - \e caps |= GEOD_AZIMUTH for the latitude \e azi2; this is
+   *   added automatically,
+   * - \e caps |= GEOD_DISTANCE for the distance \e s12,
+   * - \e caps |= GEOD_REDUCEDLENGTH for the reduced length \e m12,
+   * - \e caps |= GEOD_GEODESICSCALE for the geodesic scales \e M12
+   *   and \e M21,
+   * - \e caps |= GEOD_AREA for the area \e S12,
+   * - \e caps |= GEOD_DISTANCE_IN permits the length of the
+   *   geodesic to be given in terms of \e s12; without this capability the
+   *   length can only be specified in terms of arc length.
+   * .
+   * A value of \e caps = 0 is treated as GEOD_LATITUDE | GEOD_LONGITUDE |
+   * GEOD_AZIMUTH | GEOD_DISTANCE_IN (to support the solution of the "standard"
+   * direct problem).
+   **********************************************************************/
+  void geod_lineinit(struct geod_geodesicline* l,
+                     const struct geod_geodesic* g,
+                     double lat1, double lon1, double azi1, unsigned caps);
+
+  /**
+   * Solve the direct geodesic problem.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] lat1 latitude of point 1 (degrees).
+   * @param[in] lon1 longitude of point 1 (degrees).
+   * @param[in] azi1 azimuth at point 1 (degrees).
+   * @param[in] s12 distance between point 1 and point 2 (meters); it can be
+   *   negative.
+   * @param[out] plat2 pointer to the latitude of point 2 (degrees).
+   * @param[out] plon2 pointer to the longitude of point 2 (degrees).
+   * @param[out] pazi2 pointer to the (forward) azimuth at point 2 (degrees).
+   *
+   * \e g must have been initialized with a call to geod_init().  \e lat1
+   * should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e azi1
+   * should be in the range [&minus;540&deg;, 540&deg;).  The values of \e lon2
+   * and \e azi2 returned are in the range [&minus;180&deg;, 180&deg;).  Any of
+   * the "return" arguments \e plat2, etc., may be replaced by 0, if you do not
+   * need some quantities computed.
+   *
+   * If either point is at a pole, the azimuth is defined by keeping the
+   * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;), and
+   * taking the limit &epsilon; &rarr; 0+.  An arc length greater that 180&deg;
+   * signifies a geodesic which is not a shortest path.  (For a prolate
+   * ellipsoid, an additional condition is necessary for a shortest path: the
+   * longitudinal extent must not exceed of 180&deg;.)
+   *
+   * Example, determine the point 10000 km NE of JFK:
+   @code
+   struct geod_geodesic g;
+   double lat, lon;
+   geod_init(&g, 6378137, 1/298.257223563);
+   geod_direct(&g, 40.64, -73.78, 45.0, 10e6, &lat, &lon, 0);
+   printf("%.5f %.5f\n", lat, lon);
+   @endcode
+   **********************************************************************/
+  void geod_direct(const struct geod_geodesic* g,
+                   double lat1, double lon1, double azi1, double s12,
+                   double* plat2, double* plon2, double* pazi2);
+
+  /**
+   * Solve the inverse geodesic problem.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] lat1 latitude of point 1 (degrees).
+   * @param[in] lon1 longitude of point 1 (degrees).
+   * @param[in] lat2 latitude of point 2 (degrees).
+   * @param[in] lon2 longitude of point 2 (degrees).
+   * @param[out] ps12 pointer to the distance between point 1 and point 2
+   *   (meters).
+   * @param[out] pazi1 pointer to the azimuth at point 1 (degrees).
+   * @param[out] pazi2 pointer to the (forward) azimuth at point 2 (degrees).
+   *
+   * \e g must have been initialized with a call to geod_init().  \e lat1
+   * and \e lat2 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and
+   * \e lon2 should be in the range [&minus;540&deg;, 540&deg;).  The values of
+   * \e azi1 and \e azi2 returned are in the range [&minus;180&deg;, 180&deg;).
+   * Any of the "return" arguments \e ps12, etc., may be replaced by 0, if you
+   * do not need some quantities computed.
+   *
+   * If either point is at a pole, the azimuth is defined by keeping the
+   * longitude fixed, writing \e lat = &plusmn;(90&deg; &minus; &epsilon;), and
+   * taking the limit &epsilon; &rarr; 0+.
+   *
+   * The solution to the inverse problem is found using Newton's method.  If
+   * this fails to converge (this is very unlikely in geodetic applications
+   * but does occur for very eccentric ellipsoids), then the bisection method
+   * is used to refine the solution.
+   *
+   * Example, determine the distance between JFK and Singapore Changi Airport:
+   @code
+   struct geod_geodesic g;
+   double s12;
+   geod_init(&g, 6378137, 1/298.257223563);
+   geod_inverse(&g, 40.64, -73.78, 1.36, 103.99, &s12, 0, 0);
+   printf("%.3f\n", s12);
+   @endcode
+   **********************************************************************/
+  void geod_inverse(const struct geod_geodesic* g,
+                    double lat1, double lon1, double lat2, double lon2,
+                    double* ps12, double* pazi1, double* pazi2);
+
+  /**
+   * Compute the position along a geod_geodesicline.
+   *
+   * @param[in] l a pointer to the geod_geodesicline object specifying the
+   *   geodesic line.
+   * @param[in] s12 distance between point 1 and point 2 (meters); it can be
+   *   negative.
+   * @param[out] plat2 pointer to the latitude of point 2 (degrees).
+   * @param[out] plon2 pointer to the longitude of point 2 (degrees); requires
+   *   that \e l was initialized with \e caps |= GEOD_LONGITUDE.
+   * @param[out] pazi2 pointer to the (forward) azimuth at point 2 (degrees).
+   *
+   * \e l must have been initialized with a call to geod_lineinit() with \e
+   * caps |= GEOD_DISTANCE_IN.  The values of \e lon2 and \e azi2 returned are
+   * in the range [&minus;180&deg;, 180&deg;).  Any of the "return" arguments
+   * \e plat2, etc., may be replaced by 0, if you do not need some quantities
+   * computed.
+   *
+   * Example, compute way points between JFK and Singapore Changi Airport
+   * the "obvious" way using geod_direct():
+   @code
+   struct geod_geodesic g;
+   double s12, azi1, lat[101],lon[101];
+   int i;
+   geod_init(&g, 6378137, 1/298.257223563);
+   geod_inverse(&g, 40.64, -73.78, 1.36, 103.99, &s12, &azi1, 0);
+   for (i = 0; i < 101; ++i) {
+     geod_direct(&g, 40.64, -73.78, azi1, i * s12 * 0.01, lat + i, lon + i, 0);
+     printf("%.5f %.5f\n", lat[i], lon[i]);
+   }
+   @endcode
+   * A faster way using geod_position():
+   @code
+   struct geod_geodesic g;
+   struct geod_geodesicline l;
+   double s12, azi1, lat[101],lon[101];
+   int i;
+   geod_init(&g, 6378137, 1/298.257223563);
+   geod_inverse(&g, 40.64, -73.78, 1.36, 103.99, &s12, &azi1, 0);
+   geod_lineinit(&l, &g, 40.64, -73.78, azi1, 0);
+   for (i = 0; i < 101; ++i) {
+     geod_position(&l, i * s12 * 0.01, lat + i, lon + i, 0);
+     printf("%.5f %.5f\n", lat[i], lon[i]);
+   }
+   @endcode
+   **********************************************************************/
+  void geod_position(const struct geod_geodesicline* l, double s12,
+                     double* plat2, double* plon2, double* pazi2);
+
+  /**
+   * The general direct geodesic problem.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] lat1 latitude of point 1 (degrees).
+   * @param[in] lon1 longitude of point 1 (degrees).
+   * @param[in] azi1 azimuth at point 1 (degrees).
+   * @param[in] flags bitor'ed combination of geod_flags(); \e flags &
+   *   GEOD_ARCMODE determines the meaning of \e s12_a12 and \e flags &
+   *   GEOD_LONG_NOWRAP prevents the value of \e lon2 being wrapped into
+   *   the range [&minus;180&deg;, 180&deg;).
+   * @param[in] s12_a12 if \e flags & GEOD_ARCMODE is 0, this is the distance
+   *   between point 1 and point 2 (meters); otherwise it is the arc length
+   *   between point 1 and point 2 (degrees); it can be negative.
+   * @param[out] plat2 pointer to the latitude of point 2 (degrees).
+   * @param[out] plon2 pointer to the longitude of point 2 (degrees).
+   * @param[out] pazi2 pointer to the (forward) azimuth at point 2 (degrees).
+   * @param[out] ps12 pointer to the distance between point 1 and point 2
+   *   (meters).
+   * @param[out] pm12 pointer to the reduced length of geodesic (meters).
+   * @param[out] pM12 pointer to the geodesic scale of point 2 relative to
+   *   point 1 (dimensionless).
+   * @param[out] pM21 pointer to the geodesic scale of point 1 relative to
+   *   point 2 (dimensionless).
+   * @param[out] pS12 pointer to the area under the geodesic
+   *   (meters<sup>2</sup>).
+   * @return \e a12 arc length of between point 1 and point 2 (degrees).
+   *
+   * \e g must have been initialized with a call to geod_init().  \e lat1
+   * should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and \e azi1
+   * should be in the range [&minus;540&deg;, 540&deg;).  The function
+   * value \e a12 equals \e s12_a12 if \e flags & GEOD_ARCMODE.  Any of the
+   * "return" arguments \e plat2, etc., may be replaced by 0, if you do not
+   * need some quantities computed.
+   *
+   * With \e flags & GEOD_LONG_NOWRAP bit set, the quantity \e lon2 &minus;
+   * \e lon1 indicates how many times the geodesic wrapped around the
+   * ellipsoid.  Because \e lon2 might be outside the normal allowed range
+   * for longitudes, [&minus;540&deg;, 540&deg;), be sure to normalize it,
+   * e.g., with fmod(\e lon2, 360.0) before using it in subsequent
+   * calculations
+   **********************************************************************/
+  double geod_gendirect(const struct geod_geodesic* g,
+                        double lat1, double lon1, double azi1,
+                        unsigned flags, double s12_a12,
+                        double* plat2, double* plon2, double* pazi2,
+                        double* ps12, double* pm12, double* pM12, double* pM21,
+                        double* pS12);
+
+  /**
+   * The general inverse geodesic calculation.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] lat1 latitude of point 1 (degrees).
+   * @param[in] lon1 longitude of point 1 (degrees).
+   * @param[in] lat2 latitude of point 2 (degrees).
+   * @param[in] lon2 longitude of point 2 (degrees).
+   * @param[out] ps12 pointer to the distance between point 1 and point 2
+   *  (meters).
+   * @param[out] pazi1 pointer to the azimuth at point 1 (degrees).
+   * @param[out] pazi2 pointer to the (forward) azimuth at point 2 (degrees).
+   * @param[out] pm12 pointer to the reduced length of geodesic (meters).
+   * @param[out] pM12 pointer to the geodesic scale of point 2 relative to
+   *   point 1 (dimensionless).
+   * @param[out] pM21 pointer to the geodesic scale of point 1 relative to
+   *   point 2 (dimensionless).
+   * @param[out] pS12 pointer to the area under the geodesic
+   *   (meters<sup>2</sup>).
+   * @return \e a12 arc length of between point 1 and point 2 (degrees).
+   *
+   * \e g must have been initialized with a call to geod_init().  \e lat1
+   * and \e lat2 should be in the range [&minus;90&deg;, 90&deg;]; \e lon1 and
+   * \e lon2 should be in the range [&minus;540&deg;, 540&deg;).  Any of the
+   * "return" arguments \e ps12, etc., may be replaced by 0, if you do not need
+   * some quantities computed.
+   **********************************************************************/
+  double geod_geninverse(const struct geod_geodesic* g,
+                         double lat1, double lon1, double lat2, double lon2,
+                         double* ps12, double* pazi1, double* pazi2,
+                         double* pm12, double* pM12, double* pM21,
+                         double* pS12);
+
+  /**
+   * The general position function.
+   *
+   * @param[in] l a pointer to the geod_geodesicline object specifying the
+   *   geodesic line.
+   * @param[in] flags bitor'ed combination of geod_flags(); \e flags &
+   *   GEOD_ARCMODE determines the meaning of \e s12_a12 and \e flags &
+   *   GEOD_LONG_NOWRAP prevents the value of \e lon2 being wrapped into
+   *   the range [&minus;180&deg;, 180&deg;); if \e flags & GEOD_ARCMODE is
+   *   0, then \e l must have been initialized with \e caps |=
+   *   GEOD_DISTANCE_IN.
+   * @param[in] s12_a12 if \e flags & GEOD_ARCMODE is 0, this is the
+   *   distance between point 1 and point 2 (meters); otherwise it is the
+   *   arc length between point 1 and point 2 (degrees); it can be
+   *   negative.
+   * @param[out] plat2 pointer to the latitude of point 2 (degrees).
+   * @param[out] plon2 pointer to the longitude of point 2 (degrees); requires
+   *   that \e l was initialized with \e caps |= GEOD_LONGITUDE.
+   * @param[out] pazi2 pointer to the (forward) azimuth at point 2 (degrees).
+   * @param[out] ps12 pointer to the distance between point 1 and point 2
+   *   (meters); requires that \e l was initialized with \e caps |=
+   *   GEOD_DISTANCE.
+   * @param[out] pm12 pointer to the reduced length of geodesic (meters);
+   *   requires that \e l was initialized with \e caps |= GEOD_REDUCEDLENGTH.
+   * @param[out] pM12 pointer to the geodesic scale of point 2 relative to
+   *   point 1 (dimensionless); requires that \e l was initialized with \e caps
+   *   |= GEOD_GEODESICSCALE.
+   * @param[out] pM21 pointer to the geodesic scale of point 1 relative to
+   *   point 2 (dimensionless); requires that \e l was initialized with \e caps
+   *   |= GEOD_GEODESICSCALE.
+   * @param[out] pS12 pointer to the area under the geodesic
+   *   (meters<sup>2</sup>); requires that \e l was initialized with \e caps |=
+   *   GEOD_AREA.
+   * @return \e a12 arc length of between point 1 and point 2 (degrees).
+   *
+   * \e l must have been initialized with a call to geod_lineinit() with \e
+   * caps |= GEOD_DISTANCE_IN.  The value \e azi2 returned is in the range
+   * [&minus;180&deg;, 180&deg;).  Any of the "return" arguments \e plat2,
+   * etc., may be replaced by 0, if you do not need some quantities
+   * computed.  Requesting a value which \e l is not capable of computing
+   * is not an error; the corresponding argument will not be altered.
+   *
+   * With \e flags & GEOD_LONG_NOWRAP bit set, the quantity \e lon2 &minus;
+   * \e lon1 indicates how many times the geodesic wrapped around the
+   * ellipsoid.  Because \e lon2 might be outside the normal allowed range
+   * for longitudes, [&minus;540&deg;, 540&deg;), be sure to normalize it,
+   * e.g., with fmod(\e lon2, 360.0) before using it in subsequent
+   * calculations
+   *
+   * Example, compute way points between JFK and Singapore Changi Airport
+   * using geod_genposition().  In this example, the points are evenly space in
+   * arc length (and so only approximately equally space in distance).  This is
+   * faster than using geod_position() would be appropriate if drawing the path
+   * on a map.
+   @code
+   struct geod_geodesic g;
+   struct geod_geodesicline l;
+   double a12, azi1, lat[101], lon[101];
+   int i;
+   geod_init(&g, 6378137, 1/298.257223563);
+   a12 = geod_geninverse(&g, 40.64, -73.78, 1.36, 103.99,
+                         0, &azi1, 0, 0, 0, 0, 0);
+   geod_lineinit(&l, &g, 40.64, -73.78, azi1, GEOD_LATITUDE | GEOD_LONGITUDE);
+   for (i = 0; i < 101; ++i) {
+     geod_genposition(&l, 1, i * a12 * 0.01,
+                      lat + i, lon + i, 0, 0, 0, 0, 0, 0);
+     printf("%.5f %.5f\n", lat[i], lon[i]);
+   }
+   @endcode
+   **********************************************************************/
+  double geod_genposition(const struct geod_geodesicline* l,
+                          unsigned flags, double s12_a12,
+                          double* plat2, double* plon2, double* pazi2,
+                          double* ps12, double* pm12,
+                          double* pM12, double* pM21,
+                          double* pS12);
+
+  /**
+   * Initialize a geod_polygon object.
+   *
+   * @param[out] p a pointer to the object to be initialized.
+   * @param[in] polylinep non-zero if a polyline instead of a polygon.
+   *
+   * If \e polylinep is zero, then the sequence of vertices and edges added by
+   * geod_polygon_addpoint() and geod_polygon_addedge() define a polygon and
+   * the perimeter and area are returned by geod_polygon_compute().  If \e
+   * polylinep is non-zero, then the vertices and edges define a polyline and
+   * only the perimeter is returned by geod_polygon_compute().
+   *
+   * The area and perimeter are accumulated at two times the standard floating
+   * point precision to guard against the loss of accuracy with many-sided
+   * polygons.  At any point you can ask for the perimeter and area so far.
+   *
+   * An example of the use of this function is given in the documentation for
+   * geod_polygon_compute().
+   **********************************************************************/
+  void geod_polygon_init(struct geod_polygon* p, int polylinep);
+
+  /**
+   * Add a point to the polygon or polyline.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in,out] p a pointer to the geod_polygon object specifying the
+   *   polygon.
+   * @param[in] lat the latitude of the point (degrees).
+   * @param[in] lon the longitude of the point (degrees).
+   *
+   * \e g and \e p must have been initialized with calls to geod_init() and
+   * geod_polygon_init(), respectively.  The same \e g must be used for all the
+   * points and edges in a polygon.  \e lat should be in the range
+   * [&minus;90&deg;, 90&deg;] and \e lon should be in the range
+   * [&minus;540&deg;, 540&deg;).
+   *
+   * An example of the use of this function is given in the documentation for
+   * geod_polygon_compute().
+   **********************************************************************/
+  void geod_polygon_addpoint(const struct geod_geodesic* g,
+                             struct geod_polygon* p,
+                             double lat, double lon);
+
+  /**
+   * Add an edge to the polygon or polyline.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in,out] p a pointer to the geod_polygon object specifying the
+   *   polygon.
+   * @param[in] azi azimuth at current point (degrees).
+   * @param[in] s distance from current point to next point (meters).
+   *
+   * \e g and \e p must have been initialized with calls to geod_init() and
+   * geod_polygon_init(), respectively.  The same \e g must be used for all the
+   * points and edges in a polygon.  \e azi should be in the range
+   * [&minus;540&deg;, 540&deg;).  This does nothing if no points have been
+   * added yet.  The \e lat and \e lon fields of \e p give the location of
+   * the new vertex.
+   **********************************************************************/
+  void geod_polygon_addedge(const struct geod_geodesic* g,
+                            struct geod_polygon* p,
+                            double azi, double s);
+
+  /**
+   * Return the results for a polygon.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] p a pointer to the geod_polygon object specifying the polygon.
+   * @param[in] reverse if non-zero then clockwise (instead of
+   *   counter-clockwise) traversal counts as a positive area.
+   * @param[in] sign if non-zero then return a signed result for the area if
+   *   the polygon is traversed in the "wrong" direction instead of returning
+   *   the area for the rest of the earth.
+   * @param[out] pA pointer to the area of the polygon (meters<sup>2</sup>);
+   *   only set if \e polyline is non-zero in the call to geod_polygon_init().
+   * @param[out] pP pointer to the perimeter of the polygon or length of the
+   *   polyline (meters).
+   * @return the number of points.
+   *
+   * The area and perimeter are accumulated at two times the standard floating
+   * point precision to guard against the loss of accuracy with many-sided
+   * polygons.  Only simple polygons (which are not self-intersecting) are
+   * allowed.  There's no need to "close" the polygon by repeating the first
+   * vertex.  Set \e pA or \e pP to zero, if you do not want the corresponding
+   * quantity returned.
+   *
+   * Example, compute the perimeter and area of the geodesic triangle with
+   * vertices (0&deg;N,0&deg;E), (0&deg;N,90&deg;E), (90&deg;N,0&deg;E).
+   @code
+   double A, P;
+   int n;
+   struct geod_geodesic g;
+   struct geod_polygon p;
+   geod_init(&g, 6378137, 1/298.257223563);
+   geod_polygon_init(&p, 0);
+
+   geod_polygon_addpoint(&g, &p,  0,  0);
+   geod_polygon_addpoint(&g, &p,  0, 90);
+   geod_polygon_addpoint(&g, &p, 90,  0);
+   n = geod_polygon_compute(&g, &p, 0, 1, &A, &P);
+   printf("%d %.8f %.3f\n", n, P, A);
+   @endcode
+   **********************************************************************/
+  unsigned geod_polygon_compute(const struct geod_geodesic* g,
+                                const struct geod_polygon* p,
+                                int reverse, int sign,
+                                double* pA, double* pP);
+
+  /**
+   * Return the results assuming a tentative final test point is added;
+   * however, the data for the test point is not saved.  This lets you report a
+   * running result for the perimeter and area as the user moves the mouse
+   * cursor.  Ordinary floating point arithmetic is used to accumulate the data
+   * for the test point; thus the area and perimeter returned are less accurate
+   * than if geod_polygon_addpoint() and geod_polygon_compute() are used.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] p a pointer to the geod_polygon object specifying the polygon.
+   * @param[in] lat the latitude of the test point (degrees).
+   * @param[in] lon the longitude of the test point (degrees).
+   * @param[in] reverse if non-zero then clockwise (instead of
+   *   counter-clockwise) traversal counts as a positive area.
+   * @param[in] sign if non-zero then return a signed result for the area if
+   *   the polygon is traversed in the "wrong" direction instead of returning
+   *   the area for the rest of the earth.
+   * @param[out] pA pointer to the area of the polygon (meters<sup>2</sup>);
+   *   only set if \e polyline is non-zero in the call to geod_polygon_init().
+   * @param[out] pP pointer to the perimeter of the polygon or length of the
+   *   polyline (meters).
+   * @return the number of points.
+   *
+   * \e lat should be in the range [&minus;90&deg;, 90&deg;] and \e
+   * lon should be in the range [&minus;540&deg;, 540&deg;).
+   **********************************************************************/
+  unsigned geod_polygon_testpoint(const struct geod_geodesic* g,
+                                  const struct geod_polygon* p,
+                                  double lat, double lon,
+                                  int reverse, int sign,
+                                  double* pA, double* pP);
+
+  /**
+   * Return the results assuming a tentative final test point is added via an
+   * azimuth and distance; however, the data for the test point is not saved.
+   * This lets you report a running result for the perimeter and area as the
+   * user moves the mouse cursor.  Ordinary floating point arithmetic is used
+   * to accumulate the data for the test point; thus the area and perimeter
+   * returned are less accurate than if geod_polygon_addedge() and
+   * geod_polygon_compute() are used.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] p a pointer to the geod_polygon object specifying the polygon.
+   * @param[in] azi azimuth at current point (degrees).
+   * @param[in] s distance from current point to final test point (meters).
+   * @param[in] reverse if non-zero then clockwise (instead of
+   *   counter-clockwise) traversal counts as a positive area.
+   * @param[in] sign if non-zero then return a signed result for the area if
+   *   the polygon is traversed in the "wrong" direction instead of returning
+   *   the area for the rest of the earth.
+   * @param[out] pA pointer to the area of the polygon (meters<sup>2</sup>);
+   *   only set if \e polyline is non-zero in the call to geod_polygon_init().
+   * @param[out] pP pointer to the perimeter of the polygon or length of the
+   *   polyline (meters).
+   * @return the number of points.
+   *
+   * \e azi should be in the range [&minus;540&deg;, 540&deg;).
+   **********************************************************************/
+  unsigned geod_polygon_testedge(const struct geod_geodesic* g,
+                                 const struct geod_polygon* p,
+                                 double azi, double s,
+                                 int reverse, int sign,
+                                 double* pA, double* pP);
+
+  /**
+   * A simple interface for computing the area of a geodesic polygon.
+   *
+   * @param[in] g a pointer to the geod_geodesic object specifying the
+   *   ellipsoid.
+   * @param[in] lats an array of latitudes of the polygon vertices (degrees).
+   * @param[in] lons an array of longitudes of the polygon vertices (degrees).
+   * @param[in] n the number of vertices.
+   * @param[out] pA pointer to the area of the polygon (meters<sup>2</sup>).
+   * @param[out] pP pointer to the perimeter of the polygon (meters).
+   *
+   * \e lats should be in the range [&minus;90&deg;, 90&deg;]; \e lons should
+   * be in the range [&minus;540&deg;, 540&deg;).
+   *
+   * Only simple polygons (which are not self-intersecting) are allowed.
+   * There's no need to "close" the polygon by repeating the first vertex.  The
+   * area returned is signed with counter-clockwise traversal being treated as
+   * positive.
+   *
+   * Example, compute the area of Antarctica:
+   @code
+   double
+     lats[] = {-72.9, -71.9, -74.9, -74.3, -77.5, -77.4, -71.7, -65.9, -65.7,
+               -66.6, -66.9, -69.8, -70.0, -71.0, -77.3, -77.9, -74.7},
+     lons[] = {-74, -102, -102, -131, -163, 163, 172, 140, 113,
+                88, 59, 25, -4, -14, -33, -46, -61};
+   struct geod_geodesic g;
+   double A, P;
+   geod_init(&g, 6378137, 1/298.257223563);
+   geod_polygonarea(&g, lats, lons, (sizeof lats) / (sizeof lats[0]), &A, &P);
+   printf("%.0f %.2f\n", A, P);
+   @endcode
+   **********************************************************************/
+  void geod_polygonarea(const struct geod_geodesic* g,
+                        double lats[], double lons[], int n,
+                        double* pA, double* pP);
+
+  /**
+   * mask values for the \e caps argument to geod_lineinit().
+   **********************************************************************/
+  enum geod_mask {
+    GEOD_NONE         = 0U,                     /**< Calculate nothing */
+    GEOD_LATITUDE     = 1U<<7  | 0U,            /**< Calculate latitude */
+    GEOD_LONGITUDE    = 1U<<8  | 1U<<3,         /**< Calculate longitude */
+    GEOD_AZIMUTH      = 1U<<9  | 0U,            /**< Calculate azimuth */
+    GEOD_DISTANCE     = 1U<<10 | 1U<<0,         /**< Calculate distance */
+    GEOD_DISTANCE_IN  = 1U<<11 | 1U<<0 | 1U<<1, /**< Allow distance as input  */
+    GEOD_REDUCEDLENGTH= 1U<<12 | 1U<<0 | 1U<<2, /**< Calculate reduced length */
+    GEOD_GEODESICSCALE= 1U<<13 | 1U<<0 | 1U<<2, /**< Calculate geodesic scale */
+    GEOD_AREA         = 1U<<14 | 1U<<4,         /**< Calculate reduced length */
+    GEOD_ALL          = 0x7F80U| 0x1FU          /**< Calculate everything */
+  };
+
+  /**
+   * flag values for the \e flags argument to geod_gendirect() and
+   * geod_genposition()
+   **********************************************************************/
+  enum geod_flags {
+    GEOD_NOFLAGS      = 0U,     /**< No flags */
+    GEOD_ARCMODE      = 1U<<0,  /**< Position given in terms of arc distance */
+    GEOD_LONG_NOWRAP  = 1U<<15  /**< Don't wrap longitude */
+  };
+
+#if defined(__cplusplus)
+}
+#endif
+
+#endif

+ 35 - 0
libpq_test/include/geos.h

@@ -0,0 +1,35 @@
+/**********************************************************************
+ *
+ * GEOS - Geometry Engine Open Source
+ * http://geos.osgeo.org
+ *
+ * Copyright (C) 2005 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation. 
+ * See the COPYING file for more information.
+ *
+ **********************************************************************/
+
+#ifndef GEOS_H
+#define GEOS_H
+
+/*
+ * \file geos.h
+ * \brief
+ * This file is intended as an include wrapper for client application.
+ * It includes commonly needed GEOS headers.
+ */
+
+#include <geos/version.h>
+#include <geos/geom.h>
+#include <geos/util.h>
+#include <geos/io.h>
+#include <geos/unload.h>
+
+/// Basic namespace for all GEOS functionalities.
+namespace geos {
+}
+
+#endif

+ 1850 - 0
libpq_test/include/geos_c.h

@@ -0,0 +1,1850 @@
+/************************************************************************
+ *
+ *
+ * C-Wrapper for GEOS library
+ *
+ * Copyright (C) 2010 2011 Sandro Santilli <strk@keybit.net>
+ * Copyright (C) 2005 Refractions Research Inc.
+ *
+ * This is free software; you can redistribute and/or modify it under
+ * the terms of the GNU Lesser General Public Licence as published
+ * by the Free Software Foundation.
+ * See the COPYING file for more information.
+ *
+ * Author: Sandro Santilli <strk@keybit.net>
+ *
+ ***********************************************************************
+ *
+ * GENERAL NOTES:
+ *
+ *	- Remember to call initGEOS() before any use of this library's
+ *	  functions, and call finishGEOS() when done.
+ *
+ *	- Currently you have to explicitly GEOSGeom_destroy() all
+ *	  GEOSGeom objects to avoid memory leaks, and to GEOSFree()
+ *	  all returned char * (unless const).
+ *
+ *	- Functions ending with _r are thread safe; see details in RFC 3
+ *	  http://trac.osgeo.org/geos/wiki/RFC3. 
+ *	  To avoid using by accident non _r functions,
+ *	  define GEOS_USE_ONLY_R_API before including geos_c.h
+ *
+ ***********************************************************************/
+
+#ifndef GEOS_C_H_INCLUDED
+#define GEOS_C_H_INCLUDED
+
+#ifndef __cplusplus
+# include <stddef.h> /* for size_t definition */
+#else
+# include <cstddef>
+using std::size_t;
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/************************************************************************
+ *
+ * Version
+ *
+ ***********************************************************************/
+
+/*
+ * Following 'ifdef' hack fixes problem with generating geos_c.h on Windows,
+ * when building with Visual C++ compiler.
+ *
+ */
+#if defined(_MSC_VER)
+#include <geos/version.h>
+#define GEOS_CAPI_VERSION_MAJOR 1
+#define GEOS_CAPI_VERSION_MINOR 9
+#define GEOS_CAPI_VERSION_PATCH 0
+#define GEOS_CAPI_VERSION "3.5.0-CAPI-1.9.0"
+#else
+#ifndef GEOS_VERSION_MAJOR
+#define GEOS_VERSION_MAJOR 3
+#endif
+#ifndef GEOS_VERSION_MINOR
+#define GEOS_VERSION_MINOR 5
+#endif
+#ifndef GEOS_VERSION_PATCH
+#define GEOS_VERSION_PATCH 0
+#endif
+#ifndef GEOS_VERSION
+#define GEOS_VERSION "3.5.0"
+#endif
+#ifndef GEOS_JTS_PORT
+#define GEOS_JTS_PORT "1.13.0"
+#endif
+
+#define GEOS_CAPI_VERSION_MAJOR 1
+#define GEOS_CAPI_VERSION_MINOR 9
+#define GEOS_CAPI_VERSION_PATCH 0
+#define GEOS_CAPI_VERSION "3.5.0-CAPI-1.9.0"
+#endif
+
+#define GEOS_CAPI_FIRST_INTERFACE GEOS_CAPI_VERSION_MAJOR
+#define GEOS_CAPI_LAST_INTERFACE (GEOS_CAPI_VERSION_MAJOR+GEOS_CAPI_VERSION_MINOR)
+
+/************************************************************************
+ *
+ * (Abstract) type definitions
+ *
+ ************************************************************************/
+
+typedef struct GEOSContextHandle_HS *GEOSContextHandle_t;
+
+typedef void (*GEOSMessageHandler)(const char *fmt, ...);
+
+/*
+ * A GEOS message handler function.
+ *
+ * @param message the message contents
+ * @param userdata the user data pointer that was passed to GEOS when registering this message handler.
+ *
+ *
+ * @see GEOSContext_setErrorMessageHandler
+ * @see GEOSContext_setNoticeMessageHandler
+ */
+typedef void (*GEOSMessageHandler_r)(const char *message, void *userdata);
+
+/* When we're included by geos_c.cpp, those are #defined to the original
+ * JTS definitions via preprocessor. We don't touch them to allow the
+ * compiler to cross-check the declarations. However, for all "normal"
+ * C-API users, we need to define them as "opaque" struct pointers, as
+ * those clients don't have access to the original C++ headers, by design.
+ */
+#ifndef GEOSGeometry
+typedef struct GEOSGeom_t GEOSGeometry;
+typedef struct GEOSPrepGeom_t GEOSPreparedGeometry;
+typedef struct GEOSCoordSeq_t GEOSCoordSequence;
+typedef struct GEOSSTRtree_t GEOSSTRtree;
+typedef struct GEOSBufParams_t GEOSBufferParams;
+#endif
+
+/* Those are compatibility definitions for source compatibility
+ * with GEOS 2.X clients relying on that type.
+ */
+typedef GEOSGeometry* GEOSGeom;
+typedef GEOSCoordSequence* GEOSCoordSeq;
+
+/* Supported geometry types
+ * This was renamed from GEOSGeomTypeId in GEOS 2.2.X, which might
+ * break compatibility, this issue is still under investigation.
+ */
+
+enum GEOSGeomTypes {
+    GEOS_POINT,
+    GEOS_LINESTRING,
+    GEOS_LINEARRING,
+    GEOS_POLYGON,
+    GEOS_MULTIPOINT,
+    GEOS_MULTILINESTRING,
+    GEOS_MULTIPOLYGON,
+    GEOS_GEOMETRYCOLLECTION
+};
+
+/* Byte oders exposed via the c api */
+enum GEOSByteOrders {
+    GEOS_WKB_XDR = 0, /* Big Endian */
+    GEOS_WKB_NDR = 1 /* Little Endian */
+};
+
+typedef void (*GEOSQueryCallback)(void *item, void *userdata);
+
+/************************************************************************
+ *
+ * Initialization, cleanup, version
+ *
+ ***********************************************************************/
+
+#include <geos/export.h>
+
+/*
+ * Register an interruption checking callback
+ *
+ * The callback will be invoked _before_ checking for
+ * interruption, so can be used to request it.
+ */
+typedef void (GEOSInterruptCallback)();
+extern GEOSInterruptCallback GEOS_DLL *GEOS_interruptRegisterCallback(GEOSInterruptCallback* cb);
+/* Request safe interruption of operations */
+extern void GEOS_DLL GEOS_interruptRequest();
+/* Cancel a pending interruption request */
+extern void GEOS_DLL GEOS_interruptCancel();
+
+/*
+ * @deprecated in 3.5.0
+ *     initialize using GEOS_init_r() and set the message handlers using
+ *     GEOSContext_setNoticeHandler_r and/or GEOSContext_setErrorHandler_r
+ */
+extern GEOSContextHandle_t GEOS_DLL initGEOS_r(
+                                    GEOSMessageHandler notice_function,
+                                    GEOSMessageHandler error_function);
+/*
+ * @deprecated in 3.5.0 replaced by GEOS_finish_r.
+ */
+extern void GEOS_DLL finishGEOS_r(GEOSContextHandle_t handle);
+
+extern GEOSContextHandle_t GEOS_DLL GEOS_init_r();
+extern void GEOS_DLL GEOS_finish_r(GEOSContextHandle_t handle);
+
+
+extern GEOSMessageHandler GEOS_DLL GEOSContext_setNoticeHandler_r(GEOSContextHandle_t extHandle,
+                                                                  GEOSMessageHandler nf);
+extern GEOSMessageHandler GEOS_DLL GEOSContext_setErrorHandler_r(GEOSContextHandle_t extHandle,
+                                                                 GEOSMessageHandler ef);
+
+/*
+ * Sets a notice message handler on the given GEOS context.
+ *
+ * @param extHandle the GEOS context
+ * @param nf the message handler
+ * @param userData optional user data pointer that will be passed to the message handler
+ *
+ * @return the previously configured message handler or NULL if no message handler was configured
+ */
+extern GEOSMessageHandler_r GEOS_DLL GEOSContext_setNoticeMessageHandler_r(GEOSContextHandle_t extHandle,
+                                                                           GEOSMessageHandler_r nf,
+                                                                           void *userData);
+
+/*
+ * Sets an error message handler on the given GEOS context.
+ *
+ * @param extHandle the GEOS context
+ * @param ef the message handler
+ * @param userData optional user data pointer that will be passed to the message handler
+ *
+ * @return the previously configured message handler or NULL if no message handler was configured
+ */
+extern GEOSMessageHandler_r GEOS_DLL GEOSContext_setErrorMessageHandler_r(GEOSContextHandle_t extHandle,
+                                                                          GEOSMessageHandler_r ef,
+                                                                          void *userData);
+
+extern const char GEOS_DLL *GEOSversion();
+
+
+/************************************************************************
+ *
+ * NOTE - These functions are DEPRECATED.  Please use the new Reader and
+ * writer APIS!
+ *
+ ***********************************************************************/
+
+extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT_r(GEOSContextHandle_t handle,
+                                                const char *wkt);
+extern char GEOS_DLL *GEOSGeomToWKT_r(GEOSContextHandle_t handle,
+                                      const GEOSGeometry* g);
+
+/*
+ * Specify whether output WKB should be 2d or 3d.
+ * Return previously set number of dimensions.
+ */
+
+extern int GEOS_DLL GEOS_getWKBOutputDims_r(GEOSContextHandle_t handle);
+extern int GEOS_DLL GEOS_setWKBOutputDims_r(GEOSContextHandle_t handle,
+                                            int newDims);
+
+/*
+ * Specify whether the WKB byte order is big or little endian.
+ * The return value is the previous byte order.
+ */
+
+extern int GEOS_DLL GEOS_getWKBByteOrder_r(GEOSContextHandle_t handle);
+extern int GEOS_DLL GEOS_setWKBByteOrder_r(GEOSContextHandle_t handle,
+                                           int byteOrder);
+
+extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf_r(GEOSContextHandle_t handle,
+                                                    const unsigned char *wkb,
+                                                    size_t size);
+extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf_r(GEOSContextHandle_t handle,
+                                                   const GEOSGeometry* g,
+                                                   size_t *size);
+
+extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf_r(GEOSContextHandle_t handle,
+                                                    const unsigned char *hex,
+                                                    size_t size);
+extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf_r(GEOSContextHandle_t handle,
+                                                   const GEOSGeometry* g,
+                                                   size_t *size);
+
+/************************************************************************
+ *
+ * Coordinate Sequence functions
+ *
+ ***********************************************************************/
+
+/*
+ * Create a Coordinate sequence with ``size'' coordinates
+ * of ``dims'' dimensions.
+ * Return NULL on exception.
+ */
+extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create_r(
+                                                GEOSContextHandle_t handle,
+                                                unsigned int size,
+                                                unsigned int dims);
+
+/*
+ * Clone a Coordinate Sequence.
+ * Return NULL on exception.
+ */
+extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone_r(
+                                                GEOSContextHandle_t handle,
+                                                const GEOSCoordSequence* s);
+
+/*
+ * Destroy a Coordinate Sequence.
+ */
+extern void GEOS_DLL GEOSCoordSeq_destroy_r(GEOSContextHandle_t handle,
+                                            GEOSCoordSequence* s);
+
+/*
+ * Set ordinate values in a Coordinate Sequence.
+ * Return 0 on exception.
+ */
+extern int GEOS_DLL GEOSCoordSeq_setX_r(GEOSContextHandle_t handle,
+                                        GEOSCoordSequence* s, unsigned int idx,
+                                        double val);
+extern int GEOS_DLL GEOSCoordSeq_setY_r(GEOSContextHandle_t handle,
+                                        GEOSCoordSequence* s, unsigned int idx,
+                                        double val);
+extern int GEOS_DLL GEOSCoordSeq_setZ_r(GEOSContextHandle_t handle,
+                                        GEOSCoordSequence* s, unsigned int idx,
+                                        double val);
+extern int GEOS_DLL GEOSCoordSeq_setOrdinate_r(GEOSContextHandle_t handle,
+                                               GEOSCoordSequence* s,
+                                               unsigned int idx,
+                                               unsigned int dim, double val);
+
+/*
+ * Get ordinate values from a Coordinate Sequence.
+ * Return 0 on exception.
+ */
+extern int GEOS_DLL GEOSCoordSeq_getX_r(GEOSContextHandle_t handle,
+                                        const GEOSCoordSequence* s,
+                                        unsigned int idx, double *val);
+extern int GEOS_DLL GEOSCoordSeq_getY_r(GEOSContextHandle_t handle,
+                                        const GEOSCoordSequence* s,
+                                        unsigned int idx, double *val);
+extern int GEOS_DLL GEOSCoordSeq_getZ_r(GEOSContextHandle_t handle,
+                                        const GEOSCoordSequence* s,
+                                        unsigned int idx, double *val);
+extern int GEOS_DLL GEOSCoordSeq_getOrdinate_r(GEOSContextHandle_t handle,
+                                               const GEOSCoordSequence* s,
+                                               unsigned int idx,
+                                               unsigned int dim, double *val);
+/*
+ * Get size and dimensions info from a Coordinate Sequence.
+ * Return 0 on exception.
+ */
+extern int GEOS_DLL GEOSCoordSeq_getSize_r(GEOSContextHandle_t handle,
+                                           const GEOSCoordSequence* s,
+                                           unsigned int *size);
+extern int GEOS_DLL GEOSCoordSeq_getDimensions_r(GEOSContextHandle_t handle,
+                                                 const GEOSCoordSequence* s,
+                                                 unsigned int *dims);
+
+/************************************************************************
+ *
+ *  Linear referencing functions -- there are more, but these are
+ *  probably sufficient for most purposes
+ *
+ ***********************************************************************/
+
+/*
+ * GEOSGeometry ownership is retained by caller
+ */
+
+
+/* Return distance of point 'p' projected on 'g' from origin
+ * of 'g'. Geometry 'g' must be a lineal geometry */
+extern double GEOS_DLL GEOSProject_r(GEOSContextHandle_t handle,
+                                     const GEOSGeometry *g,
+                                     const GEOSGeometry *p);
+
+/* Return closest point to given distance within geometry
+ * Geometry must be a LineString */
+extern GEOSGeometry GEOS_DLL *GEOSInterpolate_r(GEOSContextHandle_t handle,
+                                                const GEOSGeometry *g,
+                                                double d);
+
+extern double GEOS_DLL GEOSProjectNormalized_r(GEOSContextHandle_t handle,
+                                               const GEOSGeometry *g,
+                                               const GEOSGeometry *p);
+
+extern GEOSGeometry GEOS_DLL *GEOSInterpolateNormalized_r(
+                                                GEOSContextHandle_t handle,
+                                                const GEOSGeometry *g,
+                                                double d);
+
+/************************************************************************
+ *
+ * Buffer related functions
+ *
+ ***********************************************************************/
+
+
+/* @return NULL on exception */
+extern GEOSGeometry GEOS_DLL *GEOSBuffer_r(GEOSContextHandle_t handle,
+                                           const GEOSGeometry* g,
+                                           double width, int quadsegs);
+
+enum GEOSBufCapStyles {
+	GEOSBUF_CAP_ROUND=1,
+	GEOSBUF_CAP_FLAT=2,
+	GEOSBUF_CAP_SQUARE=3
+};
+
+enum GEOSBufJoinStyles {
+	GEOSBUF_JOIN_ROUND=1,
+	GEOSBUF_JOIN_MITRE=2,
+	GEOSBUF_JOIN_BEVEL=3
+};
+
+/* @return 0 on exception */
+extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create_r(
+                                              GEOSContextHandle_t handle);
+extern void GEOS_DLL GEOSBufferParams_destroy_r(
+                                              GEOSContextHandle_t handle,
+                                              GEOSBufferParams* parms);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setEndCapStyle_r(
+                                              GEOSContextHandle_t handle,
+                                              GEOSBufferParams* p,
+                                              int style);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setJoinStyle_r(
+                                              GEOSContextHandle_t handle,
+                                              GEOSBufferParams* p,
+                                              int joinStyle);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setMitreLimit_r(
+                                              GEOSContextHandle_t handle,
+                                              GEOSBufferParams* p,
+                                              double mitreLimit);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments_r(
+                                              GEOSContextHandle_t handle,
+                                              GEOSBufferParams* p,
+                                              int quadSegs);
+
+/* @param singleSided: 1 for single sided, 0 otherwise */
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setSingleSided_r(
+                                              GEOSContextHandle_t handle,
+                                              GEOSBufferParams* p,
+                                              int singleSided);
+
+/* @return NULL on exception */
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams_r(
+                                              GEOSContextHandle_t handle,
+                                              const GEOSGeometry* g,
+                                              const GEOSBufferParams* p,
+                                              double width);
+
+/* These functions return NULL on exception. */
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle_r(GEOSContextHandle_t handle,
+	const GEOSGeometry* g, double width, int quadsegs, int endCapStyle,
+	int joinStyle, double mitreLimit);
+
+/* These functions return NULL on exception. Only LINESTRINGs are accepted. */
+/* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
+extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer_r(
+	GEOSContextHandle_t handle,
+	const GEOSGeometry* g, double width, int quadsegs,
+	int joinStyle, double mitreLimit, int leftSide);
+
+/*
+ * Only LINESTRINGs are accepted.
+ * @param width : offset distance.
+ *                negative for right side offset.
+ *                positive for left side offset.
+ * @return NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve_r(GEOSContextHandle_t handle,
+	const GEOSGeometry* g, double width, int quadsegs,
+	int joinStyle, double mitreLimit);
+
+
+/************************************************************************
+ *
+ * Geometry Constructors.
+ * GEOSCoordSequence* arguments will become ownership of the returned object.
+ * All functions return NULL on exception.
+ *
+ ***********************************************************************/
+
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint_r(
+                                       GEOSContextHandle_t handle,
+                                       GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint_r(
+                                       GEOSContextHandle_t handle);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing_r(
+                                       GEOSContextHandle_t handle,
+                                       GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString_r(
+                                       GEOSContextHandle_t handle,
+                                       GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString_r(
+                                       GEOSContextHandle_t handle);
+
+/*
+ * Second argument is an array of GEOSGeometry* objects.
+ * The caller remains owner of the array, but pointed-to
+ * objects become ownership of the returned GEOSGeometry.
+ */
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon_r(
+                                       GEOSContextHandle_t handle);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon_r(
+                                       GEOSContextHandle_t handle,
+                                       GEOSGeometry* shell,
+                                       GEOSGeometry** holes,
+                                       unsigned int nholes);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection_r(
+                                       GEOSContextHandle_t handle, int type,
+                                       GEOSGeometry* *geoms,
+                                       unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection_r(
+                                       GEOSContextHandle_t handle, int type);
+
+extern GEOSGeometry GEOS_DLL *GEOSGeom_clone_r(GEOSContextHandle_t handle,
+                                               const GEOSGeometry* g);
+
+/************************************************************************
+ *
+ * Memory management
+ *
+ ***********************************************************************/
+
+extern void GEOS_DLL GEOSGeom_destroy_r(GEOSContextHandle_t handle,
+                                        GEOSGeometry* g);
+
+/************************************************************************
+ *
+ * Topology operations - return NULL on exception.
+ *
+ ***********************************************************************/
+
+extern GEOSGeometry GEOS_DLL *GEOSEnvelope_r(GEOSContextHandle_t handle,
+                                             const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSIntersection_r(GEOSContextHandle_t handle,
+                                                 const GEOSGeometry* g1,
+                                                 const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSConvexHull_r(GEOSContextHandle_t handle,
+                                               const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSDifference_r(GEOSContextHandle_t handle,
+                                               const GEOSGeometry* g1,
+                                               const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSSymDifference_r(GEOSContextHandle_t handle,
+                                                  const GEOSGeometry* g1,
+                                                  const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSBoundary_r(GEOSContextHandle_t handle,
+                                             const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSUnion_r(GEOSContextHandle_t handle,
+                                          const GEOSGeometry* g1,
+                                          const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion_r(GEOSContextHandle_t handle,
+                                          const GEOSGeometry* g);
+/* @deprecated in 3.3.0: use GEOSUnaryUnion_r instead */
+extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded_r(GEOSContextHandle_t handle,
+                                                  const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface_r(GEOSContextHandle_t handle,
+                                                   const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSGetCentroid_r(GEOSContextHandle_t handle,
+                                                const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSNode_r(GEOSContextHandle_t handle,
+                                         const GEOSGeometry* g);
+/* Fast, non-robust intersection between an arbitrary geometry and
+ * a rectangle. The returned geometry may be invalid. */
+extern GEOSGeometry GEOS_DLL *GEOSClipByRect_r(GEOSContextHandle_t handle,
+                                                 const GEOSGeometry* g,
+                                                 double xmin, double ymin,
+                                                 double xmax, double ymax);
+
+/*
+ * all arguments remain ownership of the caller
+ * (both Geometries and pointers)
+ */
+/*
+ * Polygonizes a set of Geometries which contain linework that
+ * represents the edges of a planar graph.
+ *
+ * Any dimension of Geometry is handled - the constituent linework
+ * is extracted to form the edges.
+ *
+ * The edges must be correctly noded; that is, they must only meet
+ * at their endpoints.
+ * The Polygonizer will still run on incorrectly noded input
+ * but will not form polygons from incorrectly noded edges.
+ *
+ * The Polygonizer reports the follow kinds of errors:
+ *
+ * - Dangles - edges which have one or both ends which are
+ *   not incident on another edge endpoint
+ * - Cut Edges - edges which are connected at both ends but
+ *   which do not form part of polygon
+ * - Invalid Ring Lines - edges which form rings which are invalid
+ *   (e.g. the component lines contain a self-intersection)
+ *
+ * Errors are reported to output parameters "cuts", "dangles" and
+ * "invalid" (if not-null). Formed polygons are returned as a
+ * collection. NULL is returned on exception. All returned
+ * geometries must be destroyed by caller.
+ *
+ */
+
+extern GEOSGeometry GEOS_DLL *GEOSPolygonize_r(GEOSContextHandle_t handle,
+                              const GEOSGeometry *const geoms[],
+                              unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges_r(
+                              GEOSContextHandle_t handle,
+                              const GEOSGeometry * const geoms[],
+                              unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full_r(GEOSContextHandle_t handle,
+                              const GEOSGeometry* input, GEOSGeometry** cuts,
+                              GEOSGeometry** dangles, GEOSGeometry** invalidRings);
+
+extern GEOSGeometry GEOS_DLL *GEOSLineMerge_r(GEOSContextHandle_t handle,
+                                              const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSSimplify_r(GEOSContextHandle_t handle,
+                                             const GEOSGeometry* g,
+                                             double tolerance);
+extern GEOSGeometry GEOS_DLL *GEOSTopologyPreserveSimplify_r(
+                              GEOSContextHandle_t handle,
+                              const GEOSGeometry* g, double tolerance);
+
+/*
+ * Return all distinct vertices of input geometry as a MULTIPOINT.
+ * Note that only 2 dimensions of the vertices are considered when
+ * testing for equality.
+ */
+extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints_r(
+                              GEOSContextHandle_t handle,
+                              const GEOSGeometry* g);
+
+/*
+ * Find paths shared between the two given lineal geometries.
+ *
+ * Returns a GEOMETRYCOLLECTION having two elements:
+ * - first element is a MULTILINESTRING containing shared paths
+ *   having the _same_ direction on both inputs
+ * - second element is a MULTILINESTRING containing shared paths
+ *   having the _opposite_ direction on the two inputs
+ *
+ * Returns NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL *GEOSSharedPaths_r(GEOSContextHandle_t handle,
+  const GEOSGeometry* g1, const GEOSGeometry* g2);
+
+/*
+ * Snap first geometry on to second with given tolerance
+ * Returns a newly allocated geometry, or NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL *GEOSSnap_r(GEOSContextHandle_t handle,
+  const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
+
+/*
+ * Return a Delaunay triangulation of the vertex of the given geometry
+ *
+ * @param g the input geometry whose vertex will be used as "sites"
+ * @param tolerance optional snapping tolerance to use for improved robustness
+ * @param onlyEdges if non-zero will return a MULTILINESTRING, otherwise it will
+ *                  return a GEOMETRYCOLLECTION containing triangular POLYGONs.
+ *
+ * @return  a newly allocated geometry, or NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation_r(
+                                  GEOSContextHandle_t handle,
+                                  const GEOSGeometry *g,
+                                  double tolerance,
+                                  int onlyEdges);
+
+/*
+ * Returns the Voronoi polygons of a set of Vertices given as input
+ * 
+ * @param g the input geometry whose vertex will be used as sites.
+ * @param tolerance snapping tolerance to use for improved robustness
+ * @param onlyEdges whether to return only edges of the voronoi cells
+ * @param env clipping envelope for the returned diagram, automatically
+ *            determined if NULL.
+ *            The diagram will be clipped to the larger
+ *            of this envelope or an envelope surrounding the sites.
+ * 
+ * @return a newly allocated geometry, or NULL on exception.
+ */
+extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram_r(
+				GEOSContextHandle_t extHandle, 
+				const GEOSGeometry *g, 
+				const GEOSGeometry *env,
+				double tolerance,
+				int onlyEdges);
+
+
+/************************************************************************
+ *
+ *  Binary predicates - return 2 on exception, 1 on true, 0 on false
+ *
+ ***********************************************************************/
+
+extern char GEOS_DLL GEOSDisjoint_r(GEOSContextHandle_t handle,
+                                    const GEOSGeometry* g1,
+                                    const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSTouches_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry* g1,
+                                   const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSIntersects_r(GEOSContextHandle_t handle,
+                                      const GEOSGeometry* g1,
+                                      const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSCrosses_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry* g1,
+                                   const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSWithin_r(GEOSContextHandle_t handle,
+                                  const GEOSGeometry* g1,
+                                  const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSContains_r(GEOSContextHandle_t handle,
+                                    const GEOSGeometry* g1,
+                                    const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSOverlaps_r(GEOSContextHandle_t handle,
+                                    const GEOSGeometry* g1,
+                                    const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSEquals_r(GEOSContextHandle_t handle,
+                                  const GEOSGeometry* g1,
+                                  const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSEqualsExact_r(GEOSContextHandle_t handle,
+                                       const GEOSGeometry* g1,
+                                       const GEOSGeometry* g2,
+                                       double tolerance);
+extern char GEOS_DLL GEOSCovers_r(GEOSContextHandle_t handle,
+                                  const GEOSGeometry* g1,
+                                  const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSCoveredBy_r(GEOSContextHandle_t handle,
+                                  const GEOSGeometry* g1,
+                                  const GEOSGeometry* g2);
+
+/************************************************************************
+ *
+ *  Prepared Geometry Binary predicates - return 2 on exception, 1 on true, 0 on false
+ *
+ ***********************************************************************/
+
+/*
+ * GEOSGeometry ownership is retained by caller
+ */
+extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare_r(
+                                            GEOSContextHandle_t handle,
+                                            const GEOSGeometry* g);
+
+extern void GEOS_DLL GEOSPreparedGeom_destroy_r(GEOSContextHandle_t handle,
+                                                const GEOSPreparedGeometry* g);
+
+extern char GEOS_DLL GEOSPreparedContains_r(GEOSContextHandle_t handle,
+                                            const GEOSPreparedGeometry* pg1,
+                                            const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedContainsProperly_r(GEOSContextHandle_t handle,
+                                         const GEOSPreparedGeometry* pg1,
+                                         const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedCoveredBy_r(GEOSContextHandle_t handle,
+                                          const GEOSPreparedGeometry* pg1,
+                                          const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedCovers_r(GEOSContextHandle_t handle,
+                                          const GEOSPreparedGeometry* pg1,
+                                          const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedCrosses_r(GEOSContextHandle_t handle,
+                                          const GEOSPreparedGeometry* pg1,
+                                          const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedDisjoint_r(GEOSContextHandle_t handle,
+                                          const GEOSPreparedGeometry* pg1,
+                                          const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedIntersects_r(GEOSContextHandle_t handle,
+                                              const GEOSPreparedGeometry* pg1,
+                                              const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedOverlaps_r(GEOSContextHandle_t handle,
+                                          const GEOSPreparedGeometry* pg1,
+                                          const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedTouches_r(GEOSContextHandle_t handle,
+                                          const GEOSPreparedGeometry* pg1,
+                                          const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedWithin_r(GEOSContextHandle_t handle,
+                                          const GEOSPreparedGeometry* pg1,
+                                          const GEOSGeometry* g2);
+
+/************************************************************************
+ *
+ *  STRtree functions
+ *
+ ***********************************************************************/
+
+/*
+ * GEOSGeometry ownership is retained by caller
+ */
+
+extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create_r(
+                                    GEOSContextHandle_t handle,
+                                    size_t nodeCapacity);
+extern void GEOS_DLL GEOSSTRtree_insert_r(GEOSContextHandle_t handle,
+                                          GEOSSTRtree *tree,
+                                          const GEOSGeometry *g,
+                                          void *item);
+extern void GEOS_DLL GEOSSTRtree_query_r(GEOSContextHandle_t handle,
+                                         GEOSSTRtree *tree,
+                                         const GEOSGeometry *g,
+                                         GEOSQueryCallback callback,
+                                         void *userdata);
+extern void GEOS_DLL GEOSSTRtree_iterate_r(GEOSContextHandle_t handle,
+                                       GEOSSTRtree *tree,
+                                       GEOSQueryCallback callback,
+                                       void *userdata);
+extern char GEOS_DLL GEOSSTRtree_remove_r(GEOSContextHandle_t handle,
+                                          GEOSSTRtree *tree,
+                                          const GEOSGeometry *g,
+                                          void *item);
+extern void GEOS_DLL GEOSSTRtree_destroy_r(GEOSContextHandle_t handle,
+                                           GEOSSTRtree *tree);
+
+
+/************************************************************************
+ *
+ *  Unary predicate - return 2 on exception, 1 on true, 0 on false
+ *
+ ***********************************************************************/
+
+extern char GEOS_DLL GEOSisEmpty_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry* g);
+extern char GEOS_DLL GEOSisSimple_r(GEOSContextHandle_t handle,
+                                    const GEOSGeometry* g);
+extern char GEOS_DLL GEOSisRing_r(GEOSContextHandle_t handle,
+                                  const GEOSGeometry* g);
+extern char GEOS_DLL GEOSHasZ_r(GEOSContextHandle_t handle,
+                                const GEOSGeometry* g);
+extern char GEOS_DLL GEOSisClosed_r(GEOSContextHandle_t handle,
+                                const GEOSGeometry *g);
+
+/************************************************************************
+ *
+ *  Dimensionally Extended 9 Intersection Model related
+ *
+ ***********************************************************************/
+
+/* These are for use with GEOSRelateBoundaryNodeRule (flags param) */
+enum GEOSRelateBoundaryNodeRules {
+	/* MOD2 and OGC are the same rule, and is the default
+	 * used by GEOSRelatePattern
+	 */
+	GEOSRELATE_BNR_MOD2=1,
+	GEOSRELATE_BNR_OGC=1,
+	GEOSRELATE_BNR_ENDPOINT=2,
+	GEOSRELATE_BNR_MULTIVALENT_ENDPOINT=3,
+	GEOSRELATE_BNR_MONOVALENT_ENDPOINT=4
+};
+
+/* return 2 on exception, 1 on true, 0 on false */
+extern char GEOS_DLL GEOSRelatePattern_r(GEOSContextHandle_t handle,
+                                         const GEOSGeometry* g1,
+                                         const GEOSGeometry* g2,
+                                         const char *pat);
+
+/* return NULL on exception, a string to GEOSFree otherwise */
+extern char GEOS_DLL *GEOSRelate_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry* g1,
+                                   const GEOSGeometry* g2);
+
+/* return 2 on exception, 1 on true, 0 on false */
+extern char GEOS_DLL GEOSRelatePatternMatch_r(GEOSContextHandle_t handle,
+                                         const char *mat,
+                                         const char *pat);
+
+/* return NULL on exception, a string to GEOSFree otherwise */
+extern char GEOS_DLL *GEOSRelateBoundaryNodeRule_r(GEOSContextHandle_t handle,
+                                                   const GEOSGeometry* g1,
+                                                   const GEOSGeometry* g2,
+                                                   int bnr);
+
+/************************************************************************
+ *
+ *  Validity checking
+ *
+ ***********************************************************************/
+
+/* These are for use with GEOSisValidDetail (flags param) */
+enum GEOSValidFlags {
+	GEOSVALID_ALLOW_SELFTOUCHING_RING_FORMING_HOLE=1
+};
+
+/* return 2 on exception, 1 on true, 0 on false */
+extern char GEOS_DLL GEOSisValid_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry* g);
+
+/* return NULL on exception, a string to GEOSFree otherwise */
+extern char GEOS_DLL *GEOSisValidReason_r(GEOSContextHandle_t handle,
+                                         const GEOSGeometry* g);
+
+/*
+ * Caller has the responsibility to destroy 'reason' (GEOSFree)
+ * and 'location' (GEOSGeom_destroy) params
+ * return 2 on exception, 1 when valid, 0 when invalid
+ */
+extern char GEOS_DLL GEOSisValidDetail_r(GEOSContextHandle_t handle,
+                                         const GEOSGeometry* g,
+                                         int flags,
+                                         char** reason,
+                                         GEOSGeometry** location);
+
+/************************************************************************
+ *
+ *  Geometry info
+ *
+ ***********************************************************************/
+
+/* Return NULL on exception, result must be freed by caller. */
+extern char GEOS_DLL *GEOSGeomType_r(GEOSContextHandle_t handle,
+                                     const GEOSGeometry* g);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSGeomTypeId_r(GEOSContextHandle_t handle,
+                                     const GEOSGeometry* g);
+
+/* Return 0 on exception */
+extern int GEOS_DLL GEOSGetSRID_r(GEOSContextHandle_t handle,
+                                  const GEOSGeometry* g);
+
+extern void GEOS_DLL GEOSSetSRID_r(GEOSContextHandle_t handle,
+                                   GEOSGeometry* g, int SRID);
+
+/* May be called on all geometries in GEOS 3.x, returns -1 on error and 1
+ * for non-multi geometries. Older GEOS versions only accept
+ * GeometryCollections or Multi* geometries here, and are likely to crash
+ * when fed simple geometries, so beware if you need compatibility with
+ * old GEOS versions.
+ */
+extern int GEOS_DLL GEOSGetNumGeometries_r(GEOSContextHandle_t handle,
+                                           const GEOSGeometry* g);
+
+/*
+ * Return NULL on exception.
+ * Returned object is a pointer to internal storage:
+ * it must NOT be destroyed directly.
+ * Up to GEOS 3.2.0 the input geometry must be a Collection, in
+ * later version it doesn't matter (getGeometryN(0) for a single will
+ * return the input).
+ */
+extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN_r(
+                                    GEOSContextHandle_t handle,
+                                    const GEOSGeometry* g, int n);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSNormalize_r(GEOSContextHandle_t handle,
+                                    GEOSGeometry* g);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSGetNumInteriorRings_r(GEOSContextHandle_t handle,
+                                              const GEOSGeometry* g);
+
+/* Return -1 on exception, Geometry must be a LineString. */
+extern int GEOS_DLL GEOSGeomGetNumPoints_r(GEOSContextHandle_t handle,
+                                       const GEOSGeometry* g);
+
+/* Return -1 on exception, Geometry must be a Point. */
+extern int GEOS_DLL GEOSGeomGetX_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *x);
+extern int GEOS_DLL GEOSGeomGetY_r(GEOSContextHandle_t handle, const GEOSGeometry *g, double *y);
+
+/*
+ * Return NULL on exception, Geometry must be a Polygon.
+ * Returned object is a pointer to internal storage:
+ * it must NOT be destroyed directly.
+ */
+extern const GEOSGeometry GEOS_DLL *GEOSGetInteriorRingN_r(
+                                    GEOSContextHandle_t handle,
+                                    const GEOSGeometry* g, int n);
+
+/*
+ * Return NULL on exception, Geometry must be a Polygon.
+ * Returned object is a pointer to internal storage:
+ * it must NOT be destroyed directly.
+ */
+extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing_r(
+                                    GEOSContextHandle_t handle,
+                                    const GEOSGeometry* g);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSGetNumCoordinates_r(GEOSContextHandle_t handle,
+                                            const GEOSGeometry* g);
+
+/*
+ * Return NULL on exception.
+ * Geometry must be a LineString, LinearRing or Point.
+ */
+extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq_r(
+                                         GEOSContextHandle_t handle,
+                                         const GEOSGeometry* g);
+
+/*
+ * Return 0 on exception (or empty geometry)
+ */
+extern int GEOS_DLL GEOSGeom_getDimensions_r(GEOSContextHandle_t handle,
+                                             const GEOSGeometry* g);
+
+/*
+ * Return 2 or 3.
+ */
+extern int GEOS_DLL GEOSGeom_getCoordinateDimension_r(GEOSContextHandle_t handle,
+                                                      const GEOSGeometry* g);
+
+/*
+ * Return NULL on exception.
+ * Must be LineString and must be freed by called.
+ */
+extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN_r(GEOSContextHandle_t handle, const GEOSGeometry *g, int n);
+extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint_r(GEOSContextHandle_t handle, const GEOSGeometry *g);
+extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint_r(GEOSContextHandle_t handle, const GEOSGeometry *g);
+
+/************************************************************************
+ *
+ *  Misc functions
+ *
+ ***********************************************************************/
+
+/* Return 0 on exception, 1 otherwise */
+extern int GEOS_DLL GEOSArea_r(GEOSContextHandle_t handle,
+                               const GEOSGeometry* g, double *area);
+extern int GEOS_DLL GEOSLength_r(GEOSContextHandle_t handle,
+                                 const GEOSGeometry* g, double *length);
+extern int GEOS_DLL GEOSDistance_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry* g1,
+                                   const GEOSGeometry* g2, double *dist);
+extern int GEOS_DLL GEOSHausdorffDistance_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry *g1,
+                                   const GEOSGeometry *g2,
+                                   double *dist);
+extern int GEOS_DLL GEOSHausdorffDistanceDensify_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry *g1,
+                                   const GEOSGeometry *g2,
+                                   double densifyFrac, double *dist);
+extern int GEOS_DLL GEOSGeomGetLength_r(GEOSContextHandle_t handle,
+                                   const GEOSGeometry *g, double *length);
+
+/* Return 0 on exception, the closest points of the two geometries otherwise.
+ * The first point comes from g1 geometry and the second point comes from g2.
+ */
+extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints_r(
+  GEOSContextHandle_t handle, const GEOSGeometry* g1, const GEOSGeometry* g2);
+
+
+/************************************************************************
+ *
+ * Algorithms
+ *
+ ***********************************************************************/
+
+/* Walking from A to B:
+ *  return -1 if reaching P takes a counter-clockwise (left) turn
+ *  return  1 if reaching P takes a clockwise (right) turn
+ *  return  0 if P is collinear with A-B
+ *
+ * On exceptions, return 2.
+ *
+ */
+extern int GEOS_DLL GEOSOrientationIndex_r(GEOSContextHandle_t handle,
+	double Ax, double Ay, double Bx, double By, double Px, double Py);
+
+
+/************************************************************************
+ *
+ * Reader and Writer APIs
+ *
+ ***********************************************************************/
+
+typedef struct GEOSWKTReader_t GEOSWKTReader;
+typedef struct GEOSWKTWriter_t GEOSWKTWriter;
+typedef struct GEOSWKBReader_t GEOSWKBReader;
+typedef struct GEOSWKBWriter_t GEOSWKBWriter;
+
+
+/* WKT Reader */
+extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create_r(
+                                             GEOSContextHandle_t handle);
+extern void GEOS_DLL GEOSWKTReader_destroy_r(GEOSContextHandle_t handle,
+                                             GEOSWKTReader* reader);
+extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read_r(GEOSContextHandle_t handle,
+                                                   GEOSWKTReader* reader,
+                                                   const char *wkt);
+
+/* WKT Writer */
+extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create_r(
+                                             GEOSContextHandle_t handle);
+extern void GEOS_DLL GEOSWKTWriter_destroy_r(GEOSContextHandle_t handle,
+                                             GEOSWKTWriter* writer);
+extern char GEOS_DLL *GEOSWKTWriter_write_r(GEOSContextHandle_t handle,
+                                            GEOSWKTWriter* writer,
+                                            const GEOSGeometry* g);
+extern void GEOS_DLL GEOSWKTWriter_setTrim_r(GEOSContextHandle_t handle,
+                                            GEOSWKTWriter *writer,
+                                            char trim);
+extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision_r(GEOSContextHandle_t handle,
+                                            GEOSWKTWriter *writer,
+                                            int precision);
+extern void GEOS_DLL GEOSWKTWriter_setOutputDimension_r(GEOSContextHandle_t handle,
+                                                        GEOSWKTWriter *writer,
+                                                        int dim);
+extern int  GEOS_DLL GEOSWKTWriter_getOutputDimension_r(GEOSContextHandle_t handle,
+                                                        GEOSWKTWriter *writer);
+extern void GEOS_DLL GEOSWKTWriter_setOld3D_r(GEOSContextHandle_t handle,
+                                              GEOSWKTWriter *writer,
+                                              int useOld3D);
+
+/* WKB Reader */
+extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create_r(
+                                             GEOSContextHandle_t handle);
+extern void GEOS_DLL GEOSWKBReader_destroy_r(GEOSContextHandle_t handle,
+                                             GEOSWKBReader* reader);
+extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read_r(GEOSContextHandle_t handle,
+                                                   GEOSWKBReader* reader,
+                                                   const unsigned char *wkb,
+                                                   size_t size);
+extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX_r(
+                                            GEOSContextHandle_t handle,
+                                            GEOSWKBReader* reader,
+                                            const unsigned char *hex,
+                                            size_t size);
+
+/* WKB Writer */
+extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create_r(
+                                             GEOSContextHandle_t handle);
+extern void GEOS_DLL GEOSWKBWriter_destroy_r(GEOSContextHandle_t handle,
+                                             GEOSWKBWriter* writer);
+
+/* The caller owns the results for these two methods! */
+extern unsigned char GEOS_DLL *GEOSWKBWriter_write_r(
+                                             GEOSContextHandle_t handle,
+                                             GEOSWKBWriter* writer,
+                                             const GEOSGeometry* g,
+                                             size_t *size);
+extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX_r(
+                                             GEOSContextHandle_t handle,
+                                             GEOSWKBWriter* writer,
+                                             const GEOSGeometry* g,
+                                             size_t *size);
+
+/*
+ * Specify whether output WKB should be 2d or 3d.
+ * Return previously set number of dimensions.
+ */
+extern int GEOS_DLL GEOSWKBWriter_getOutputDimension_r(
+                                  GEOSContextHandle_t handle,
+                                  const GEOSWKBWriter* writer);
+extern void GEOS_DLL GEOSWKBWriter_setOutputDimension_r(
+                                   GEOSContextHandle_t handle,
+                                   GEOSWKBWriter* writer, int newDimension);
+
+/*
+ * Specify whether the WKB byte order is big or little endian.
+ * The return value is the previous byte order.
+ */
+extern int GEOS_DLL GEOSWKBWriter_getByteOrder_r(GEOSContextHandle_t handle,
+                                                 const GEOSWKBWriter* writer);
+extern void GEOS_DLL GEOSWKBWriter_setByteOrder_r(GEOSContextHandle_t handle,
+                                                  GEOSWKBWriter* writer,
+                                                  int byteOrder);
+
+/*
+ * Specify whether SRID values should be output.
+ */
+extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID_r(GEOSContextHandle_t handle,
+                                   const GEOSWKBWriter* writer);
+extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID_r(GEOSContextHandle_t handle,
+                                   GEOSWKBWriter* writer, const char writeSRID);
+
+
+/*
+ * Free buffers returned by stuff like GEOSWKBWriter_write(),
+ * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
+ */
+extern void GEOS_DLL GEOSFree_r(GEOSContextHandle_t handle, void *buffer);
+
+
+/* External code to GEOS can define GEOS_USE_ONLY_R_API to avoid the */
+/* non _r API to be available */
+#ifndef GEOS_USE_ONLY_R_API
+
+/************************************************************************
+ *
+ * Initialization, cleanup, version
+ *
+ ***********************************************************************/
+
+extern void GEOS_DLL initGEOS(GEOSMessageHandler notice_function,
+    GEOSMessageHandler error_function);
+extern void GEOS_DLL finishGEOS(void);
+
+/************************************************************************
+ *
+ * NOTE - These functions are DEPRECATED.  Please use the new Reader and
+ * writer APIS!
+ *
+ ***********************************************************************/
+
+extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKT(const char *wkt);
+extern char GEOS_DLL *GEOSGeomToWKT(const GEOSGeometry* g);
+
+/*
+ * Specify whether output WKB should be 2d or 3d.
+ * Return previously set number of dimensions.
+ */
+extern int GEOS_DLL GEOS_getWKBOutputDims();
+extern int GEOS_DLL GEOS_setWKBOutputDims(int newDims);
+
+/*
+ * Specify whether the WKB byte order is big or little endian.
+ * The return value is the previous byte order.
+ */
+extern int GEOS_DLL GEOS_getWKBByteOrder();
+extern int GEOS_DLL GEOS_setWKBByteOrder(int byteOrder);
+
+extern GEOSGeometry GEOS_DLL *GEOSGeomFromWKB_buf(const unsigned char *wkb, size_t size);
+extern unsigned char GEOS_DLL *GEOSGeomToWKB_buf(const GEOSGeometry* g, size_t *size);
+
+extern GEOSGeometry GEOS_DLL *GEOSGeomFromHEX_buf(const unsigned char *hex, size_t size);
+extern unsigned char GEOS_DLL *GEOSGeomToHEX_buf(const GEOSGeometry* g, size_t *size);
+
+/************************************************************************
+ *
+ * Coordinate Sequence functions
+ *
+ ***********************************************************************/
+
+/*
+ * Create a Coordinate sequence with ``size'' coordinates
+ * of ``dims'' dimensions.
+ * Return NULL on exception.
+ */
+extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_create(unsigned int size, unsigned int dims);
+
+/*
+ * Clone a Coordinate Sequence.
+ * Return NULL on exception.
+ */
+extern GEOSCoordSequence GEOS_DLL *GEOSCoordSeq_clone(const GEOSCoordSequence* s);
+
+/*
+ * Destroy a Coordinate Sequence.
+ */
+extern void GEOS_DLL GEOSCoordSeq_destroy(GEOSCoordSequence* s);
+
+/*
+ * Set ordinate values in a Coordinate Sequence.
+ * Return 0 on exception.
+ */
+extern int GEOS_DLL GEOSCoordSeq_setX(GEOSCoordSequence* s,
+    unsigned int idx, double val);
+extern int GEOS_DLL GEOSCoordSeq_setY(GEOSCoordSequence* s,
+    unsigned int idx, double val);
+extern int GEOS_DLL GEOSCoordSeq_setZ(GEOSCoordSequence* s,
+    unsigned int idx, double val);
+extern int GEOS_DLL GEOSCoordSeq_setOrdinate(GEOSCoordSequence* s,
+    unsigned int idx, unsigned int dim, double val);
+
+/*
+ * Get ordinate values from a Coordinate Sequence.
+ * Return 0 on exception.
+ */
+extern int GEOS_DLL GEOSCoordSeq_getX(const GEOSCoordSequence* s,
+    unsigned int idx, double *val);
+extern int GEOS_DLL GEOSCoordSeq_getY(const GEOSCoordSequence* s,
+    unsigned int idx, double *val);
+extern int GEOS_DLL GEOSCoordSeq_getZ(const GEOSCoordSequence* s,
+    unsigned int idx, double *val);
+extern int GEOS_DLL GEOSCoordSeq_getOrdinate(const GEOSCoordSequence* s,
+    unsigned int idx, unsigned int dim, double *val);
+/*
+ * Get size and dimensions info from a Coordinate Sequence.
+ * Return 0 on exception.
+ */
+extern int GEOS_DLL GEOSCoordSeq_getSize(const GEOSCoordSequence* s,
+    unsigned int *size);
+extern int GEOS_DLL GEOSCoordSeq_getDimensions(const GEOSCoordSequence* s,
+    unsigned int *dims);
+
+/************************************************************************
+ *
+ *  Linear referencing functions -- there are more, but these are
+ *  probably sufficient for most purposes
+ *
+ ***********************************************************************/
+
+/*
+ * GEOSGeometry ownership is retained by caller
+ */
+
+
+/* Return distance of point 'p' projected on 'g' from origin
+ * of 'g'. Geometry 'g' must be a lineal geometry */
+extern double GEOS_DLL GEOSProject(const GEOSGeometry *g,
+                                   const GEOSGeometry* p);
+
+/* Return closest point to given distance within geometry
+ * Geometry must be a LineString */
+extern GEOSGeometry GEOS_DLL *GEOSInterpolate(const GEOSGeometry *g,
+                                              double d);
+
+extern double GEOS_DLL GEOSProjectNormalized(const GEOSGeometry *g,
+                                             const GEOSGeometry* p);
+
+extern GEOSGeometry GEOS_DLL *GEOSInterpolateNormalized(const GEOSGeometry *g,
+                                                        double d);
+
+/************************************************************************
+ *
+ * Buffer related functions
+ *
+ ***********************************************************************/
+
+
+/* @return NULL on exception */
+extern GEOSGeometry GEOS_DLL *GEOSBuffer(const GEOSGeometry* g,
+    double width, int quadsegs);
+
+/* @return 0 on exception */
+extern GEOSBufferParams GEOS_DLL *GEOSBufferParams_create();
+extern void GEOS_DLL GEOSBufferParams_destroy(GEOSBufferParams* parms);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setEndCapStyle(
+                                              GEOSBufferParams* p,
+                                              int style);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setJoinStyle(
+                                              GEOSBufferParams* p,
+                                              int joinStyle);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setMitreLimit(
+                                              GEOSBufferParams* p,
+                                              double mitreLimit);
+
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setQuadrantSegments(
+                                              GEOSBufferParams* p,
+                                              int quadSegs);
+
+/* @param singleSided: 1 for single sided, 0 otherwise */
+/* @return 0 on exception */
+extern int GEOS_DLL GEOSBufferParams_setSingleSided(
+                                              GEOSBufferParams* p,
+                                              int singleSided);
+
+/* @return NULL on exception */
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithParams(
+                                              const GEOSGeometry* g,
+                                              const GEOSBufferParams* p,
+                                              double width);
+
+/* These functions return NULL on exception. */
+extern GEOSGeometry GEOS_DLL *GEOSBufferWithStyle(const GEOSGeometry* g,
+    double width, int quadsegs, int endCapStyle, int joinStyle,
+    double mitreLimit);
+
+/* These functions return NULL on exception. Only LINESTRINGs are accepted. */
+/* @deprecated in 3.3.0: use GEOSOffsetCurve instead */
+extern GEOSGeometry GEOS_DLL *GEOSSingleSidedBuffer(const GEOSGeometry* g,
+    double width, int quadsegs, int joinStyle, double mitreLimit,
+    int leftSide);
+
+/*
+ * Only LINESTRINGs are accepted.
+ * @param width : offset distance.
+ *                negative for right side offset.
+ *                positive for left side offset.
+ * @return NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL *GEOSOffsetCurve(const GEOSGeometry* g,
+    double width, int quadsegs, int joinStyle, double mitreLimit);
+
+/************************************************************************
+ *
+ * Geometry Constructors.
+ * GEOSCoordSequence* arguments will become ownership of the returned object.
+ * All functions return NULL on exception.
+ *
+ ***********************************************************************/
+
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createPoint(GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPoint();
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createLinearRing(GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createLineString(GEOSCoordSequence* s);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyLineString();
+
+/*
+ * Second argument is an array of GEOSGeometry* objects.
+ * The caller remains owner of the array, but pointed-to
+ * objects become ownership of the returned GEOSGeometry.
+ */
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyPolygon();
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createPolygon(GEOSGeometry* shell,
+    GEOSGeometry** holes, unsigned int nholes);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createCollection(int type,
+    GEOSGeometry* *geoms, unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSGeom_createEmptyCollection(int type);
+
+extern GEOSGeometry GEOS_DLL *GEOSGeom_clone(const GEOSGeometry* g);
+
+/************************************************************************
+ *
+ * Memory management
+ *
+ ***********************************************************************/
+
+extern void GEOS_DLL GEOSGeom_destroy(GEOSGeometry* g);
+
+/************************************************************************
+ *
+ * Topology operations - return NULL on exception.
+ *
+ ***********************************************************************/
+
+extern GEOSGeometry GEOS_DLL *GEOSEnvelope(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSIntersection(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSConvexHull(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSSymDifference(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSBoundary(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSUnion(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern GEOSGeometry GEOS_DLL *GEOSUnaryUnion(const GEOSGeometry* g);
+
+/* @deprecated in 3.3.0: use GEOSUnaryUnion instead */
+extern GEOSGeometry GEOS_DLL *GEOSUnionCascaded(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSPointOnSurface(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSGetCentroid(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSNode(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSClipByRect(const GEOSGeometry* g, double xmin, double ymin, double xmax, double ymax);
+
+/*
+ * all arguments remain ownership of the caller
+ * (both Geometries and pointers)
+ */
+extern GEOSGeometry GEOS_DLL *GEOSPolygonize(const GEOSGeometry * const geoms[], unsigned int ngeoms);
+extern GEOSGeometry GEOS_DLL *GEOSPolygonizer_getCutEdges(const GEOSGeometry * const geoms[], unsigned int ngeoms);
+/*
+ * Polygonizes a set of Geometries which contain linework that
+ * represents the edges of a planar graph.
+ *
+ * Any dimension of Geometry is handled - the constituent linework
+ * is extracted to form the edges.
+ *
+ * The edges must be correctly noded; that is, they must only meet
+ * at their endpoints.
+ * The Polygonizer will still run on incorrectly noded input
+ * but will not form polygons from incorrectly noded edges.
+ *
+ * The Polygonizer reports the follow kinds of errors:
+ *
+ * - Dangles - edges which have one or both ends which are
+ *   not incident on another edge endpoint
+ * - Cut Edges - edges which are connected at both ends but
+ *   which do not form part of polygon
+ * - Invalid Ring Lines - edges which form rings which are invalid
+ *   (e.g. the component lines contain a self-intersection)
+ *
+ * Errors are reported to output parameters "cuts", "dangles" and
+ * "invalid" (if not-null). Formed polygons are returned as a
+ * collection. NULL is returned on exception. All returned
+ * geometries must be destroyed by caller.
+ *
+ */
+extern GEOSGeometry GEOS_DLL *GEOSPolygonize_full(const GEOSGeometry* input,
+    GEOSGeometry** cuts, GEOSGeometry** dangles, GEOSGeometry** invalid);
+
+extern GEOSGeometry GEOS_DLL *GEOSLineMerge(const GEOSGeometry* g);
+extern GEOSGeometry GEOS_DLL *GEOSSimplify(const GEOSGeometry* g, double tolerance);
+extern GEOSGeometry GEOS_DLL *GEOSTopologyPreserveSimplify(const GEOSGeometry* g,
+    double tolerance);
+
+/*
+ * Return all distinct vertices of input geometry as a MULTIPOINT.
+ * Note that only 2 dimensions of the vertices are considered when
+ * testing for equality.
+ */
+extern GEOSGeometry GEOS_DLL *GEOSGeom_extractUniquePoints(
+                              const GEOSGeometry* g);
+
+/*
+ * Find paths shared between the two given lineal geometries.
+ *
+ * Returns a GEOMETRYCOLLECTION having two elements:
+ * - first element is a MULTILINESTRING containing shared paths
+ *   having the _same_ direction on both inputs
+ * - second element is a MULTILINESTRING containing shared paths
+ *   having the _opposite_ direction on the two inputs
+ *
+ * Returns NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL *GEOSSharedPaths(const GEOSGeometry* g1,
+  const GEOSGeometry* g2);
+
+/*
+ * Snap first geometry on to second with given tolerance
+ * Returns a newly allocated geometry, or NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL *GEOSSnap(const GEOSGeometry* g1,
+  const GEOSGeometry* g2, double tolerance);
+
+/*
+ * Return a Delaunay triangulation of the vertex of the given geometry
+ *
+ * @param g the input geometry whose vertex will be used as "sites"
+ * @param tolerance optional snapping tolerance to use for improved robustness
+ * @param onlyEdges if non-zero will return a MULTILINESTRING, otherwise it will
+ *                  return a GEOMETRYCOLLECTION containing triangular POLYGONs.
+ *
+ * @return  a newly allocated geometry, or NULL on exception
+ */
+extern GEOSGeometry GEOS_DLL * GEOSDelaunayTriangulation(
+                                  const GEOSGeometry *g,
+                                  double tolerance,
+                                  int onlyEdges);
+
+/*
+ * Returns the Voronoi polygons of a set of Vertices given as input
+ * 
+ * @param g the input geometry whose vertex will be used as sites.
+ * @param tolerance snapping tolerance to use for improved robustness
+ * @param onlyEdges whether to return only edges of the voronoi cells
+ * @param env clipping envelope for the returned diagram, automatically
+ *            determined if NULL.
+ *            The diagram will be clipped to the larger
+ *            of this envelope or an envelope surrounding the sites.
+ * 
+ * @return a newly allocated geometry, or NULL on exception.
+ */
+extern GEOSGeometry GEOS_DLL * GEOSVoronoiDiagram(
+                const GEOSGeometry *g,
+                const GEOSGeometry *env,
+                double tolerance,
+                int onlyEdges);
+
+/************************************************************************
+ *
+ *  Binary predicates - return 2 on exception, 1 on true, 0 on false
+ *
+ ***********************************************************************/
+
+extern char GEOS_DLL GEOSDisjoint(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSTouches(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSIntersects(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSCrosses(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSWithin(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSContains(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSOverlaps(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSEquals(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSEqualsExact(const GEOSGeometry* g1, const GEOSGeometry* g2, double tolerance);
+extern char GEOS_DLL GEOSCovers(const GEOSGeometry* g1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSCoveredBy(const GEOSGeometry* g1, const GEOSGeometry* g2);
+
+/************************************************************************
+ *
+ *  Prepared Geometry Binary predicates - return 2 on exception, 1 on true, 0 on false
+ *
+ ***********************************************************************/
+
+/*
+ * GEOSGeometry ownership is retained by caller
+ */
+extern const GEOSPreparedGeometry GEOS_DLL *GEOSPrepare(const GEOSGeometry* g);
+
+extern void GEOS_DLL GEOSPreparedGeom_destroy(const GEOSPreparedGeometry* g);
+
+extern char GEOS_DLL GEOSPreparedContains(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedContainsProperly(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedCoveredBy(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedCovers(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedCrosses(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedDisjoint(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedIntersects(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedOverlaps(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedTouches(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+extern char GEOS_DLL GEOSPreparedWithin(const GEOSPreparedGeometry* pg1, const GEOSGeometry* g2);
+
+/************************************************************************
+ *
+ *  STRtree functions
+ *
+ ***********************************************************************/
+
+/*
+ * GEOSGeometry ownership is retained by caller
+ */
+
+extern GEOSSTRtree GEOS_DLL *GEOSSTRtree_create(size_t nodeCapacity);
+extern void GEOS_DLL GEOSSTRtree_insert(GEOSSTRtree *tree,
+                                        const GEOSGeometry *g,
+                                        void *item);
+extern void GEOS_DLL GEOSSTRtree_query(GEOSSTRtree *tree,
+                                       const GEOSGeometry *g,
+                                       GEOSQueryCallback callback,
+                                       void *userdata);
+extern void GEOS_DLL GEOSSTRtree_iterate(GEOSSTRtree *tree,
+                                       GEOSQueryCallback callback,
+                                       void *userdata);
+extern char GEOS_DLL GEOSSTRtree_remove(GEOSSTRtree *tree,
+                                        const GEOSGeometry *g,
+                                        void *item);
+extern void GEOS_DLL GEOSSTRtree_destroy(GEOSSTRtree *tree);
+
+
+/************************************************************************
+ *
+ *  Unary predicate - return 2 on exception, 1 on true, 0 on false
+ *
+ ***********************************************************************/
+
+extern char GEOS_DLL GEOSisEmpty(const GEOSGeometry* g);
+extern char GEOS_DLL GEOSisSimple(const GEOSGeometry* g);
+extern char GEOS_DLL GEOSisRing(const GEOSGeometry* g);
+extern char GEOS_DLL GEOSHasZ(const GEOSGeometry* g);
+extern char GEOS_DLL GEOSisClosed(const GEOSGeometry *g);
+
+/************************************************************************
+ *
+ *  Dimensionally Extended 9 Intersection Model related
+ *
+ ***********************************************************************/
+
+/* return 2 on exception, 1 on true, 0 on false */
+extern char GEOS_DLL GEOSRelatePattern(const GEOSGeometry* g1, const GEOSGeometry* g2, const char *pat);
+
+/* return NULL on exception, a string to GEOSFree otherwise */
+extern char GEOS_DLL *GEOSRelate(const GEOSGeometry* g1, const GEOSGeometry* g2);
+
+/* return 2 on exception, 1 on true, 0 on false */
+extern char GEOS_DLL GEOSRelatePatternMatch(const char *mat, const char *pat);
+
+/* return NULL on exception, a string to GEOSFree otherwise */
+extern char GEOS_DLL *GEOSRelateBoundaryNodeRule(const GEOSGeometry* g1,
+                                                 const GEOSGeometry* g2,
+                                                 int bnr);
+
+/************************************************************************
+ *
+ *  Validity checking
+ *
+ ***********************************************************************/
+
+/* return 2 on exception, 1 on true, 0 on false */
+extern char GEOS_DLL GEOSisValid(const GEOSGeometry* g);
+
+/* return NULL on exception, a string to GEOSFree otherwise */
+extern char GEOS_DLL *GEOSisValidReason(const GEOSGeometry *g);
+/*
+ * Caller has the responsibility to destroy 'reason' (GEOSFree)
+ * and 'location' (GEOSGeom_destroy) params
+ * return 2 on exception, 1 when valid, 0 when invalid
+ * Use enum GEOSValidFlags values for the flags param.
+ */
+extern char GEOS_DLL GEOSisValidDetail(const GEOSGeometry* g,
+                                       int flags,
+                                       char** reason, GEOSGeometry** location);
+
+/************************************************************************
+ *
+ *  Geometry info
+ *
+ ***********************************************************************/
+
+/* Return NULL on exception, result must be freed by caller. */
+extern char GEOS_DLL *GEOSGeomType(const GEOSGeometry* g);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSGeomTypeId(const GEOSGeometry* g);
+
+/* Return 0 on exception */
+extern int GEOS_DLL GEOSGetSRID(const GEOSGeometry* g);
+
+extern void GEOS_DLL GEOSSetSRID(GEOSGeometry* g, int SRID);
+
+/* May be called on all geometries in GEOS 3.x, returns -1 on error and 1
+ * for non-multi geometries. Older GEOS versions only accept
+ * GeometryCollections or Multi* geometries here, and are likely to crash
+ * when fed simple geometries, so beware if you need compatibility with
+ * old GEOS versions.
+ */
+extern int GEOS_DLL GEOSGetNumGeometries(const GEOSGeometry* g);
+
+/*
+ * Return NULL on exception.
+ * Returned object is a pointer to internal storage:
+ * it must NOT be destroyed directly.
+ * Up to GEOS 3.2.0 the input geometry must be a Collection, in
+ * later version it doesn't matter (getGeometryN(0) for a single will
+ * return the input).
+ */
+extern const GEOSGeometry GEOS_DLL *GEOSGetGeometryN(const GEOSGeometry* g, int n);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSNormalize(GEOSGeometry* g);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSGetNumInteriorRings(const GEOSGeometry* g);
+
+/* Return -1 on exception, Geometry must be a LineString. */
+extern int GEOS_DLL GEOSGeomGetNumPoints(const GEOSGeometry* g);
+
+/* Return -1 on exception, Geometry must be a Point. */
+extern int GEOS_DLL GEOSGeomGetX(const GEOSGeometry *g, double *x);
+extern int GEOS_DLL GEOSGeomGetY(const GEOSGeometry *g, double *y);
+
+/*
+ * Return NULL on exception, Geometry must be a Polygon.
+ * Returned object is a pointer to internal storage:
+ * it must NOT be destroyed directly.
+ */
+extern const GEOSGeometry GEOS_DLL *GEOSGetInteriorRingN(const GEOSGeometry* g, int n);
+
+/*
+ * Return NULL on exception, Geometry must be a Polygon.
+ * Returned object is a pointer to internal storage:
+ * it must NOT be destroyed directly.
+ */
+extern const GEOSGeometry GEOS_DLL *GEOSGetExteriorRing(const GEOSGeometry* g);
+
+/* Return -1 on exception */
+extern int GEOS_DLL GEOSGetNumCoordinates(const GEOSGeometry* g);
+
+/*
+ * Return NULL on exception.
+ * Geometry must be a LineString, LinearRing or Point.
+ */
+extern const GEOSCoordSequence GEOS_DLL *GEOSGeom_getCoordSeq(const GEOSGeometry* g);
+
+/*
+ * Return 0 on exception (or empty geometry)
+ */
+extern int GEOS_DLL GEOSGeom_getDimensions(const GEOSGeometry* g);
+
+/*
+ * Return 2 or 3.
+ */
+extern int GEOS_DLL GEOSGeom_getCoordinateDimension(const GEOSGeometry* g);
+
+/*
+ * Return NULL on exception.
+ * Must be LineString and must be freed by called.
+ */
+extern GEOSGeometry GEOS_DLL *GEOSGeomGetPointN(const GEOSGeometry *g, int n);
+extern GEOSGeometry GEOS_DLL *GEOSGeomGetStartPoint(const GEOSGeometry *g);
+extern GEOSGeometry GEOS_DLL *GEOSGeomGetEndPoint(const GEOSGeometry *g);
+
+/************************************************************************
+ *
+ *  Misc functions
+ *
+ ***********************************************************************/
+
+/* Return 0 on exception, 1 otherwise */
+extern int GEOS_DLL GEOSArea(const GEOSGeometry* g, double *area);
+extern int GEOS_DLL GEOSLength(const GEOSGeometry* g, double *length);
+extern int GEOS_DLL GEOSDistance(const GEOSGeometry* g1, const GEOSGeometry* g2,
+    double *dist);
+extern int GEOS_DLL GEOSHausdorffDistance(const GEOSGeometry *g1,
+        const GEOSGeometry *g2, double *dist);
+extern int GEOS_DLL GEOSHausdorffDistanceDensify(const GEOSGeometry *g1,
+        const GEOSGeometry *g2, double densifyFrac, double *dist);
+extern int GEOS_DLL GEOSGeomGetLength(const GEOSGeometry *g, double *length);
+
+/* Return 0 on exception, the closest points of the two geometries otherwise.
+ * The first point comes from g1 geometry and the second point comes from g2.
+ */
+extern GEOSCoordSequence GEOS_DLL *GEOSNearestPoints(
+  const GEOSGeometry* g1, const GEOSGeometry* g2);
+
+
+/************************************************************************
+ *
+ * Algorithms
+ *
+ ***********************************************************************/
+
+/* Walking from A to B:
+ *  return -1 if reaching P takes a counter-clockwise (left) turn
+ *  return  1 if reaching P takes a clockwise (right) turn
+ *  return  0 if P is collinear with A-B
+ *
+ * On exceptions, return 2.
+ *
+ */
+extern int GEOS_DLL GEOSOrientationIndex(double Ax, double Ay, double Bx, double By,
+    double Px, double Py);
+
+/************************************************************************
+ *
+ * Reader and Writer APIs
+ *
+ ***********************************************************************/
+
+/* WKT Reader */
+extern GEOSWKTReader GEOS_DLL *GEOSWKTReader_create();
+extern void GEOS_DLL GEOSWKTReader_destroy(GEOSWKTReader* reader);
+extern GEOSGeometry GEOS_DLL *GEOSWKTReader_read(GEOSWKTReader* reader, const char *wkt);
+
+/* WKT Writer */
+extern GEOSWKTWriter GEOS_DLL *GEOSWKTWriter_create();
+extern void GEOS_DLL GEOSWKTWriter_destroy(GEOSWKTWriter* writer);
+extern char GEOS_DLL *GEOSWKTWriter_write(GEOSWKTWriter* writer, const GEOSGeometry* g);
+extern void GEOS_DLL GEOSWKTWriter_setTrim(GEOSWKTWriter *writer, char trim);
+extern void GEOS_DLL GEOSWKTWriter_setRoundingPrecision(GEOSWKTWriter *writer, int precision);
+extern void GEOS_DLL GEOSWKTWriter_setOutputDimension(GEOSWKTWriter *writer, int dim);
+extern int  GEOS_DLL GEOSWKTWriter_getOutputDimension(GEOSWKTWriter *writer);
+extern void GEOS_DLL GEOSWKTWriter_setOld3D(GEOSWKTWriter *writer, int useOld3D);
+
+/* WKB Reader */
+extern GEOSWKBReader GEOS_DLL *GEOSWKBReader_create();
+extern void GEOS_DLL GEOSWKBReader_destroy(GEOSWKBReader* reader);
+extern GEOSGeometry GEOS_DLL *GEOSWKBReader_read(GEOSWKBReader* reader, const unsigned char *wkb, size_t size);
+extern GEOSGeometry GEOS_DLL *GEOSWKBReader_readHEX(GEOSWKBReader* reader, const unsigned char *hex, size_t size);
+
+/* WKB Writer */
+extern GEOSWKBWriter GEOS_DLL *GEOSWKBWriter_create();
+extern void GEOS_DLL GEOSWKBWriter_destroy(GEOSWKBWriter* writer);
+
+/* The caller owns the results for these two methods! */
+extern unsigned char GEOS_DLL *GEOSWKBWriter_write(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
+extern unsigned char GEOS_DLL *GEOSWKBWriter_writeHEX(GEOSWKBWriter* writer, const GEOSGeometry* g, size_t *size);
+
+/*
+ * Specify whether output WKB should be 2d or 3d.
+ * Return previously set number of dimensions.
+ */
+extern int GEOS_DLL GEOSWKBWriter_getOutputDimension(const GEOSWKBWriter* writer);
+extern void GEOS_DLL GEOSWKBWriter_setOutputDimension(GEOSWKBWriter* writer, int newDimension);
+
+/*
+ * Specify whether the WKB byte order is big or little endian.
+ * The return value is the previous byte order.
+ */
+extern int GEOS_DLL GEOSWKBWriter_getByteOrder(const GEOSWKBWriter* writer);
+extern void GEOS_DLL GEOSWKBWriter_setByteOrder(GEOSWKBWriter* writer, int byteOrder);
+
+/*
+ * Specify whether SRID values should be output.
+ */
+extern char GEOS_DLL GEOSWKBWriter_getIncludeSRID(const GEOSWKBWriter* writer);
+extern void GEOS_DLL GEOSWKBWriter_setIncludeSRID(GEOSWKBWriter* writer, const char writeSRID);
+
+/*
+ * Free buffers returned by stuff like GEOSWKBWriter_write(),
+ * GEOSWKBWriter_writeHEX() and GEOSWKTWriter_write().
+ */
+extern void GEOS_DLL GEOSFree(void *buffer);
+
+#endif /* #ifndef GEOS_USE_ONLY_R_API */
+
+
+#ifdef __cplusplus
+} // extern "C"
+#endif
+
+#endif /* #ifndef GEOS_C_H_INCLUDED */

+ 94 - 0
libpq_test/include/gvgcpfit.h

@@ -0,0 +1,94 @@
+#ifndef _GVGCPFIT_H_INCLUDED
+#define _GVGCPFIT_H_INCLUDED
+
+#include "cpl_port.h"
+#include "cpl_conv.h"
+#include "cpl_error.h"
+
+#define EXTERNAL
+#define LOCAL static
+
+#define SUCCESS 0
+#define ABORT -1
+
+
+/*------------------------ Start of file CURVEFIT.H -----------------------*/
+
+/*
+******************************************************************************
+*                                                                            *
+*                                 CURVEFIT.H                                 *
+*                                 =========                                  *
+*                                                                            *
+*   This file contains the function prototype for CURVEFIT.C.                *
+******************************************************************************
+*/
+
+
+#ifndef CURVEFIT_H
+#define CURVEFIT_H
+
+/*- Function prototypes in CURVEFIT.C. -*/
+
+EXTERNAL int svdfit(float x[], float y[], int ndata,
+            double a[], int ma, double **u, double **v, double w[],
+            double *chisq, void (*funcs)(double, double *, int));
+
+EXTERNAL void svbksb(double **u, double w[], double **v, int m,int n,
+            double b[], double x[]);
+
+EXTERNAL void svdvar(double **v, int ma, double w[], double **cvm);
+
+EXTERNAL int svdcmp(double **a, int m, int n, double *w, double **v);
+
+
+#endif
+
+
+/*-------------------------- End of file CURVEFIT.H -----------------------*/
+
+
+
+
+/*----------------------------- FILE polyfit.h ----------------------------*/
+#ifndef __POLYFIT_H
+#define __POLYFIT_H
+
+EXTERNAL int OneDPolyFit( double *rms_err, double *coeffs_array,
+    int fit_order, int no_samples, double *f_array, double *x_array );
+
+EXTERNAL double OneDPolyEval( double *coeff, int order, double x );
+
+EXTERNAL int TwoDPolyFit( double *rms_err, double *coeffs_array,
+    int fit_order, int no_samples, double *f_array, double *x_array,
+    double *y_array );
+
+EXTERNAL double TwoDPolyEval( double *coeff, int order, double x, double y );
+
+EXTERNAL int TwoDPolyGradFit( double *rms_err, double *coeffs_array,
+    int fit_order, int no_samples, double *gradxy_array,
+    double *x_array, double *y_array );
+
+EXTERNAL void TwoDPolyGradEval(double *fgradx, double *fgrady,
+    double *coeff, int order, double x, double y);
+
+EXTERNAL void GetPolyInX (double *xcoeffs, double *xycoeffs, int order,
+    double y);
+
+EXTERNAL void GetPolyInY(double *ycoeffs, double *xycoeffs, int order,
+    double x);
+
+EXTERNAL int ThreeDPolyFit( double *rms_err, double *coeffs_array,
+    int fit_order, int no_samples, double *f_array, double *x_array,
+    double *y_array, double *z_array );
+
+EXTERNAL double ThreeDPolyEval( double *coeff, int order, double x, double y, double z );
+
+
+
+#endif /* __POLYFIT_H */
+
+
+/*---------------------- End of FILE polyfit.h ----------------------------*/
+
+#endif /* ndef _GVGCPFIT_INCLUDED */

+ 242 - 0
libpq_test/include/iconv.h

@@ -0,0 +1,242 @@
+/* Copyright (C) 1999-2003, 2005-2006, 2008-2011 Free Software Foundation, Inc.
+   This file is part of the GNU LIBICONV Library.
+
+   The GNU LIBICONV Library is free software; you can redistribute it
+   and/or modify it under the terms of the GNU Library General Public
+   License as published by the Free Software Foundation; either version 2
+   of the License, or (at your option) any later version.
+
+   The GNU LIBICONV Library is distributed in the hope that it will be
+   useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public
+   License along with the GNU LIBICONV Library; see the file COPYING.LIB.
+   If not, write to the Free Software Foundation, Inc., 51 Franklin Street,
+   Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+/* When installed, this file is called "iconv.h". */
+
+#ifndef _LIBICONV_H
+#define _LIBICONV_H
+
+#define _LIBICONV_VERSION 0x010E    /* version number: (major<<8) + minor */
+extern __declspec (dllimport) int _libiconv_version; /* Likewise */
+
+/* We would like to #include any system header file which could define
+   iconv_t, 1. in order to eliminate the risk that the user gets compilation
+   errors because some other system header file includes /usr/include/iconv.h
+   which defines iconv_t or declares iconv after this file, 2. when compiling
+   for LIBICONV_PLUG, we need the proper iconv_t type in order to produce
+   binary compatible code.
+   But gcc's #include_next is not portable. Thus, once libiconv's iconv.h
+   has been installed in /usr/local/include, there is no way any more to
+   include the original /usr/include/iconv.h. We simply have to get away
+   without it.
+   Ad 1. The risk that a system header file does
+   #include "iconv.h"  or  #include_next "iconv.h"
+   is small. They all do #include <iconv.h>.
+   Ad 2. The iconv_t type is a pointer type in all cases I have seen. (It
+   has to be a scalar type because (iconv_t)(-1) is a possible return value
+   from iconv_open().) */
+
+/* Define iconv_t ourselves. */
+#undef iconv_t
+#define iconv_t libiconv_t
+typedef void* iconv_t;
+
+/* Get size_t declaration.
+   Get wchar_t declaration if it exists. */
+#include <stddef.h>
+
+/* Get errno declaration and values. */
+#include <errno.h>
+/* Some systems, like SunOS 4, don't have EILSEQ. Some systems, like BSD/OS,
+   have EILSEQ in a different header.  On these systems, define EILSEQ
+   ourselves. */
+#ifndef EILSEQ
+#define EILSEQ 
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
+   encoding ‘tocode’. */
+#ifndef LIBICONV_PLUG
+#define iconv_open libiconv_open
+#endif
+extern iconv_t iconv_open (const char* tocode, const char* fromcode);
+
+/* Converts, using conversion descriptor ‘cd’, at most ‘*inbytesleft’ bytes
+   starting at ‘*inbuf’, writing at most ‘*outbytesleft’ bytes starting at
+   ‘*outbuf’.
+   Decrements ‘*inbytesleft’ and increments ‘*inbuf’ by the same amount.
+   Decrements ‘*outbytesleft’ and increments ‘*outbuf’ by the same amount. */
+#ifndef LIBICONV_PLUG
+#define iconv libiconv
+#endif
+extern size_t iconv (iconv_t cd,  char* * inbuf, size_t *inbytesleft, char* * outbuf, size_t *outbytesleft);
+
+/* Frees resources allocated for conversion descriptor ‘cd’. */
+#ifndef LIBICONV_PLUG
+#define iconv_close libiconv_close
+#endif
+extern int iconv_close (iconv_t cd);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#ifndef LIBICONV_PLUG
+
+/* Nonstandard extensions. */
+
+#if 1
+#if 0
+/* Tru64 with Desktop Toolkit C has a bug: <stdio.h> must be included before
+   <wchar.h>.
+   BSD/OS 4.0.1 has a bug: <stddef.h>, <stdio.h> and <time.h> must be
+   included before <wchar.h>.  */
+#include <stddef.h>
+#include <stdio.h>
+#include <time.h>
+#endif
+#include <wchar.h>
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/* A type that holds all memory needed by a conversion descriptor.
+   A pointer to such an object can be used as an iconv_t. */
+typedef struct {
+  void* dummy1[28];
+#if 1
+  mbstate_t dummy2;
+#endif
+} iconv_allocation_t;
+
+/* Allocates descriptor for code conversion from encoding ‘fromcode’ to
+   encoding ‘tocode’ into preallocated memory. Returns an error indicator
+   (0 or -1 with errno set). */
+#define iconv_open_into libiconv_open_into
+extern int iconv_open_into (const char* tocode, const char* fromcode,
+                            iconv_allocation_t* resultp);
+
+/* Control of attributes. */
+#define iconvctl libiconvctl
+extern int iconvctl (iconv_t cd, int request, void* argument);
+
+/* Hook performed after every successful conversion of a Unicode character. */
+typedef void (*iconv_unicode_char_hook) (unsigned int uc, void* data);
+/* Hook performed after every successful conversion of a wide character. */
+typedef void (*iconv_wide_char_hook) (wchar_t wc, void* data);
+/* Set of hooks. */
+struct iconv_hooks {
+  iconv_unicode_char_hook uc_hook;
+  iconv_wide_char_hook wc_hook;
+  void* data;
+};
+
+/* Fallback function.  Invoked when a small number of bytes could not be
+   converted to a Unicode character.  This function should process all
+   bytes from inbuf and may produce replacement Unicode characters by calling
+   the write_replacement callback repeatedly.  */
+typedef void (*iconv_unicode_mb_to_uc_fallback)
+             (const char* inbuf, size_t inbufsize,
+              void (*write_replacement) (const unsigned int *buf, size_t buflen,
+                                         void* callback_arg),
+              void* callback_arg,
+              void* data);
+/* Fallback function.  Invoked when a Unicode character could not be converted
+   to the target encoding.  This function should process the character and
+   may produce replacement bytes (in the target encoding) by calling the
+   write_replacement callback repeatedly.  */
+typedef void (*iconv_unicode_uc_to_mb_fallback)
+             (unsigned int code,
+              void (*write_replacement) (const char *buf, size_t buflen,
+                                         void* callback_arg),
+              void* callback_arg,
+              void* data);
+#if 1
+/* Fallback function.  Invoked when a number of bytes could not be converted to
+   a wide character.  This function should process all bytes from inbuf and may
+   produce replacement wide characters by calling the write_replacement
+   callback repeatedly.  */
+typedef void (*iconv_wchar_mb_to_wc_fallback)
+             (const char* inbuf, size_t inbufsize,
+              void (*write_replacement) (const wchar_t *buf, size_t buflen,
+                                         void* callback_arg),
+              void* callback_arg,
+              void* data);
+/* Fallback function.  Invoked when a wide character could not be converted to
+   the target encoding.  This function should process the character and may
+   produce replacement bytes (in the target encoding) by calling the
+   write_replacement callback repeatedly.  */
+typedef void (*iconv_wchar_wc_to_mb_fallback)
+             (wchar_t code,
+              void (*write_replacement) (const char *buf, size_t buflen,
+                                         void* callback_arg),
+              void* callback_arg,
+              void* data);
+#else
+/* If the wchar_t type does not exist, these two fallback functions are never
+   invoked.  Their argument list therefore does not matter.  */
+typedef void (*iconv_wchar_mb_to_wc_fallback) ();
+typedef void (*iconv_wchar_wc_to_mb_fallback) ();
+#endif
+/* Set of fallbacks. */
+struct iconv_fallbacks {
+  iconv_unicode_mb_to_uc_fallback mb_to_uc_fallback;
+  iconv_unicode_uc_to_mb_fallback uc_to_mb_fallback;
+  iconv_wchar_mb_to_wc_fallback mb_to_wc_fallback;
+  iconv_wchar_wc_to_mb_fallback wc_to_mb_fallback;
+  void* data;
+};
+
+/* Requests for iconvctl. */
+#define ICONV_TRIVIALP            0  /* int *argument */
+#define ICONV_GET_TRANSLITERATE   1  /* int *argument */
+#define ICONV_SET_TRANSLITERATE   2  /* const int *argument */
+#define ICONV_GET_DISCARD_ILSEQ   3  /* int *argument */
+#define ICONV_SET_DISCARD_ILSEQ   4  /* const int *argument */
+#define ICONV_SET_HOOKS           5  /* const struct iconv_hooks *argument */
+#define ICONV_SET_FALLBACKS       6  /* const struct iconv_fallbacks *argument */
+
+/* Listing of locale independent encodings. */
+#define iconvlist libiconvlist
+extern void iconvlist (int (*do_one) (unsigned int namescount,
+                                      const char * const * names,
+                                      void* data),
+                       void* data);
+
+/* Canonicalize an encoding name.
+   The result is either a canonical encoding name, or name itself. */
+extern const char * iconv_canonicalize (const char * name);
+
+/* Support for relocatable packages.  */
+
+/* Sets the original and the current installation prefix of the package.
+   Relocation simply replaces a pathname starting with the original prefix
+   by the corresponding pathname with the current prefix instead.  Both
+   prefixes should be directory names without trailing slash (i.e. use ""
+   instead of "/").  */
+extern void libiconv_set_relocation_prefix (const char *orig_prefix,
+                                            const char *curr_prefix);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif
+
+
+#endif /* _LIBICONV_H */

+ 14 - 0
libpq_test/include/informix/esql/datetime.h

@@ -0,0 +1,14 @@
+/* src/interfaces/ecpg/include/datetime.h */
+
+#ifndef _ECPG_DATETIME_H
+#define _ECPG_DATETIME_H
+
+#include <ecpg_informix.h>
+
+/* source created by ecpg which defines these symbols */
+#ifndef _ECPGLIB_H
+typedef timestamp dtime_t;
+typedef interval intrvl_t;
+#endif   /* ndef _ECPGLIB_H */
+
+#endif   /* ndef _ECPG_DATETIME_H */

+ 13 - 0
libpq_test/include/informix/esql/decimal.h

@@ -0,0 +1,13 @@
+/* src/interfaces/ecpg/include/decimal.h */
+
+#ifndef _ECPG_DECIMAL_H
+#define _ECPG_DECIMAL_H
+
+#include <ecpg_informix.h>
+
+/* source created by ecpg which defines this */
+#ifndef _ECPGLIB_H
+typedef decimal dec_t;
+#endif   /* ndef _ECPGLIB_H */
+
+#endif   /* ndef _ECPG_DECIMAL_H */

+ 57 - 0
libpq_test/include/informix/esql/sqltypes.h

@@ -0,0 +1,57 @@
+#ifndef ECPG_SQLTYPES_H
+#define ECPG_SQLTYPES_H
+
+#include <limits.h>
+
+#define CCHARTYPE	ECPGt_char
+#define CSHORTTYPE	ECPGt_short
+#define CINTTYPE	ECPGt_int
+#define CLONGTYPE	ECPGt_long
+#define CFLOATTYPE	ECPGt_float
+#define CDOUBLETYPE ECPGt_double
+#define CDECIMALTYPE	ECPGt_decimal
+#define CFIXCHARTYPE	108
+#define CSTRINGTYPE ECPGt_char
+#define CDATETYPE	ECPGt_date
+#define CMONEYTYPE	111
+#define CDTIMETYPE	ECPGt_timestamp
+#define CLOCATORTYPE	113
+#define CVCHARTYPE	ECPGt_varchar
+#define CINVTYPE	115
+#define CFILETYPE	116
+#define CINT8TYPE	ECPGt_long_long
+#define CCOLLTYPE		118
+#define CLVCHARTYPE		119
+#define CFIXBINTYPE		120
+#define CVARBINTYPE		121
+#define CBOOLTYPE		ECPGt_bool
+#define CROWTYPE		123
+#define CLVCHARPTRTYPE	124
+#define CTYPEMAX	25
+
+/*
+ * Values used in sqlda->sqlvar[i]->sqltype
+ */
+#define SQLCHAR		ECPGt_char
+#define SQLSMINT	ECPGt_short
+#define SQLINT		ECPGt_int
+#define SQLFLOAT	ECPGt_double
+#define SQLSMFLOAT	ECPGt_float
+#define SQLDECIMAL	ECPGt_decimal
+#define SQLSERIAL	ECPGt_int
+#define SQLDATE		ECPGt_date
+#define SQLDTIME	ECPGt_timestamp
+#define SQLTEXT		ECPGt_char
+#define SQLVCHAR	ECPGt_char
+#define SQLINTERVAL		ECPGt_interval
+#define SQLNCHAR	ECPGt_char
+#define SQLNVCHAR	ECPGt_char
+#ifdef HAVE_LONG_LONG_INT_64
+#define SQLINT8		ECPGt_long_long
+#define SQLSERIAL8	ECPGt_long_long
+#else
+#define SQLINT8		ECPGt_long
+#define SQLSERIAL8	ECPGt_long
+#endif
+
+#endif   /* ndef ECPG_SQLTYPES_H */

+ 1107 - 0
libpq_test/include/internal/c.h

@@ -0,0 +1,1107 @@
+/*-------------------------------------------------------------------------
+ *
+ * c.h
+ *	  Fundamental C definitions.  This is included by every .c file in
+ *	  PostgreSQL (via either postgres.h or postgres_fe.h, as appropriate).
+ *
+ *	  Note that the definitions here are not intended to be exposed to clients
+ *	  of the frontend interface libraries --- so we don't worry much about
+ *	  polluting the namespace with lots of stuff...
+ *
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/c.h
+ *
+ *-------------------------------------------------------------------------
+ */
+/*
+ *----------------------------------------------------------------
+ *	 TABLE OF CONTENTS
+ *
+ *		When adding stuff to this file, please try to put stuff
+ *		into the relevant section, or add new sections as appropriate.
+ *
+ *	  section	description
+ *	  -------	------------------------------------------------
+ *		0)		pg_config.h and standard system headers
+ *		1)		hacks to cope with non-ANSI C compilers
+ *		2)		bool, true, false, TRUE, FALSE, NULL
+ *		3)		standard system types
+ *		4)		IsValid macros for system types
+ *		5)		offsetof, lengthof, endof, alignment
+ *		6)		assertions
+ *		7)		widely useful macros
+ *		8)		random stuff
+ *		9)		system-specific hacks
+ *
+ * NOTE: since this file is included by both frontend and backend modules, it's
+ * almost certainly wrong to put an "extern" declaration here.  typedefs and
+ * macros are the kind of thing that might go here.
+ *
+ *----------------------------------------------------------------
+ */
+#ifndef C_H
+#define C_H
+
+#include "postgres_ext.h"
+
+/* Must undef pg_config_ext.h symbols before including pg_config.h */
+#undef PG_INT64_TYPE
+
+#include "pg_config.h"
+#include "pg_config_manual.h"	/* must be after pg_config.h */
+
+/*
+ * We always rely on the WIN32 macro being set by our build system,
+ * but _WIN32 is the compiler pre-defined macro. So make sure we define
+ * WIN32 whenever _WIN32 is set, to facilitate standalone building.
+ */
+#if defined(_WIN32) && !defined(WIN32)
+#define WIN32
+#endif
+
+#if !defined(WIN32) && !defined(__CYGWIN__)		/* win32 includes further down */
+#include "pg_config_os.h"		/* must be before any system header files */
+#endif
+
+#if _MSC_VER >= 1400 || defined(HAVE_CRTDEFS_H)
+#define errcode __msvc_errcode
+#include <crtdefs.h>
+#undef errcode
+#endif
+
+/*
+ * We have to include stdlib.h here because it defines many of these macros
+ * on some platforms, and we only want our definitions used if stdlib.h doesn't
+ * have its own.  The same goes for stddef and stdarg if present.
+ */
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <stddef.h>
+#include <stdarg.h>
+#ifdef HAVE_STRINGS_H
+#include <strings.h>
+#endif
+#ifdef HAVE_STDINT_H
+#include <stdint.h>
+#endif
+#include <sys/types.h>
+
+#include <errno.h>
+#if defined(WIN32) || defined(__CYGWIN__)
+#include <fcntl.h>				/* ensure O_BINARY is available */
+#endif
+
+#if defined(WIN32) || defined(__CYGWIN__)
+/* We have to redefine some system functions after they are included above. */
+#include "pg_config_os.h"
+#endif
+
+/*
+ * Force disable inlining if PG_FORCE_DISABLE_INLINE is defined. This is used
+ * to work around compiler bugs and might also be useful for investigatory
+ * purposes by defining the symbol in the platform's header..
+ *
+ * This is done early (in slightly the wrong section) as functionality later
+ * in this file might want to rely on inline functions.
+ */
+#ifdef PG_FORCE_DISABLE_INLINE
+#undef inline
+#define inline
+#endif
+
+/* Must be before gettext() games below */
+#include <locale.h>
+
+#define _(x) gettext(x)
+
+#ifdef ENABLE_NLS
+#include <libintl.h>
+#else
+#define gettext(x) (x)
+#define dgettext(d,x) (x)
+#define ngettext(s,p,n) ((n) == 1 ? (s) : (p))
+#define dngettext(d,s,p,n) ((n) == 1 ? (s) : (p))
+#endif
+
+/*
+ *	Use this to mark string constants as needing translation at some later
+ *	time, rather than immediately.  This is useful for cases where you need
+ *	access to the original string and translated string, and for cases where
+ *	immediate translation is not possible, like when initializing global
+ *	variables.
+ *		http://www.gnu.org/software/autoconf/manual/gettext/Special-cases.html
+ */
+#define gettext_noop(x) (x)
+
+
+/* ----------------------------------------------------------------
+ *				Section 1: hacks to cope with non-ANSI C compilers
+ *
+ * type prefixes (const, signed, volatile, inline) are handled in pg_config.h.
+ * ----------------------------------------------------------------
+ */
+
+/*
+ * CppAsString
+ *		Convert the argument to a string, using the C preprocessor.
+ * CppConcat
+ *		Concatenate two arguments together, using the C preprocessor.
+ *
+ * Note: There used to be support here for pre-ANSI C compilers that didn't
+ * support # and ##.  Nowadays, these macros are just for clarity and/or
+ * backward compatibility with existing PostgreSQL code.
+ */
+#define CppAsString(identifier) #identifier
+#define CppConcat(x, y)			x##y
+
+/*
+ * dummyret is used to set return values in macros that use ?: to make
+ * assignments.  gcc wants these to be void, other compilers like char
+ */
+#ifdef __GNUC__					/* GNU cc */
+#define dummyret	void
+#else
+#define dummyret	char
+#endif
+
+/* Which __func__ symbol do we have, if any? */
+#ifdef HAVE_FUNCNAME__FUNC
+#define PG_FUNCNAME_MACRO	__func__
+#else
+#ifdef HAVE_FUNCNAME__FUNCTION
+#define PG_FUNCNAME_MACRO	__FUNCTION__
+#else
+#define PG_FUNCNAME_MACRO	NULL
+#endif
+#endif
+
+/* ----------------------------------------------------------------
+ *				Section 2:	bool, true, false, TRUE, FALSE, NULL
+ * ----------------------------------------------------------------
+ */
+
+/*
+ * bool
+ *		Boolean value, either true or false.
+ *
+ * XXX for C++ compilers, we assume the compiler has a compatible
+ * built-in definition of bool.
+ */
+
+#ifndef __cplusplus
+
+#ifndef bool
+typedef char bool;
+#endif
+
+#ifndef true
+#define true	((bool) 1)
+#endif
+
+#ifndef false
+#define false	((bool) 0)
+#endif
+#endif   /* not C++ */
+
+typedef bool *BoolPtr;
+
+#ifndef TRUE
+#define TRUE	1
+#endif
+
+#ifndef FALSE
+#define FALSE	0
+#endif
+
+/*
+ * NULL
+ *		Null pointer.
+ */
+#ifndef NULL
+#define NULL	((void *) 0)
+#endif
+
+
+/* ----------------------------------------------------------------
+ *				Section 3:	standard system types
+ * ----------------------------------------------------------------
+ */
+
+/*
+ * Pointer
+ *		Variable holding address of any memory resident object.
+ *
+ *		XXX Pointer arithmetic is done with this, so it can't be void *
+ *		under "true" ANSI compilers.
+ */
+typedef char *Pointer;
+
+/*
+ * intN
+ *		Signed integer, EXACTLY N BITS IN SIZE,
+ *		used for numerical computations and the
+ *		frontend/backend protocol.
+ */
+#ifndef HAVE_INT8
+typedef signed char int8;		/* == 8 bits */
+typedef signed short int16;		/* == 16 bits */
+typedef signed int int32;		/* == 32 bits */
+#endif   /* not HAVE_INT8 */
+
+/*
+ * uintN
+ *		Unsigned integer, EXACTLY N BITS IN SIZE,
+ *		used for numerical computations and the
+ *		frontend/backend protocol.
+ */
+#ifndef HAVE_UINT8
+typedef unsigned char uint8;	/* == 8 bits */
+typedef unsigned short uint16;	/* == 16 bits */
+typedef unsigned int uint32;	/* == 32 bits */
+#endif   /* not HAVE_UINT8 */
+
+/*
+ * bitsN
+ *		Unit of bitwise operation, AT LEAST N BITS IN SIZE.
+ */
+typedef uint8 bits8;			/* >= 8 bits */
+typedef uint16 bits16;			/* >= 16 bits */
+typedef uint32 bits32;			/* >= 32 bits */
+
+/*
+ * 64-bit integers
+ */
+#ifdef HAVE_LONG_INT_64
+/* Plain "long int" fits, use it */
+
+#ifndef HAVE_INT64
+typedef long int int64;
+#endif
+#ifndef HAVE_UINT64
+typedef unsigned long int uint64;
+#endif
+#elif defined(HAVE_LONG_LONG_INT_64)
+/* We have working support for "long long int", use that */
+
+#ifndef HAVE_INT64
+typedef long long int int64;
+#endif
+#ifndef HAVE_UINT64
+typedef unsigned long long int uint64;
+#endif
+#else
+/* neither HAVE_LONG_INT_64 nor HAVE_LONG_LONG_INT_64 */
+#error must have a working 64-bit integer datatype
+#endif
+
+/* Decide if we need to decorate 64-bit constants */
+#ifdef HAVE_LL_CONSTANTS
+#define INT64CONST(x)  ((int64) x##LL)
+#define UINT64CONST(x) ((uint64) x##ULL)
+#else
+#define INT64CONST(x)  ((int64) x)
+#define UINT64CONST(x) ((uint64) x)
+#endif
+
+/* snprintf format strings to use for 64-bit integers */
+#define INT64_FORMAT "%" INT64_MODIFIER "d"
+#define UINT64_FORMAT "%" INT64_MODIFIER "u"
+
+/*
+ * 128-bit signed and unsigned integers
+ *		There currently is only a limited support for the type. E.g. 128bit
+ *		literals and snprintf are not supported; but math is.
+ */
+#if defined(PG_INT128_TYPE)
+#define HAVE_INT128
+typedef PG_INT128_TYPE int128;
+typedef unsigned PG_INT128_TYPE uint128;
+#endif
+
+/*
+ * stdint.h limits aren't guaranteed to be present and aren't guaranteed to
+ * have compatible types with our fixed width types. So just define our own.
+ */
+#define PG_INT8_MIN		(-0x7F-1)
+#define PG_INT8_MAX		(0x7F)
+#define PG_UINT8_MAX	(0xFF)
+#define PG_INT16_MIN	(-0x7FFF-1)
+#define PG_INT16_MAX	(0x7FFF)
+#define PG_UINT16_MAX	(0xFFFF)
+#define PG_INT32_MIN	(-0x7FFFFFFF-1)
+#define PG_INT32_MAX	(0x7FFFFFFF)
+#define PG_UINT32_MAX	(0xFFFFFFFF)
+#define PG_INT64_MIN	(-INT64CONST(0x7FFFFFFFFFFFFFFF) - 1)
+#define PG_INT64_MAX	INT64CONST(0x7FFFFFFFFFFFFFFF)
+#define PG_UINT64_MAX	UINT64CONST(0xFFFFFFFFFFFFFFFF)
+
+/* Select timestamp representation (float8 or int64) */
+#ifdef USE_INTEGER_DATETIMES
+#define HAVE_INT64_TIMESTAMP
+#endif
+
+/*
+ * Size
+ *		Size of any memory resident object, as returned by sizeof.
+ */
+typedef size_t Size;
+
+/*
+ * Index
+ *		Index into any memory resident array.
+ *
+ * Note:
+ *		Indices are non negative.
+ */
+typedef unsigned int Index;
+
+/*
+ * Offset
+ *		Offset into any memory resident array.
+ *
+ * Note:
+ *		This differs from an Index in that an Index is always
+ *		non negative, whereas Offset may be negative.
+ */
+typedef signed int Offset;
+
+/*
+ * Common Postgres datatype names (as used in the catalogs)
+ */
+typedef float float4;
+typedef double float8;
+
+/*
+ * Oid, RegProcedure, TransactionId, SubTransactionId, MultiXactId,
+ * CommandId
+ */
+
+/* typedef Oid is in postgres_ext.h */
+
+/*
+ * regproc is the type name used in the include/catalog headers, but
+ * RegProcedure is the preferred name in C code.
+ */
+typedef Oid regproc;
+typedef regproc RegProcedure;
+
+typedef uint32 TransactionId;
+
+typedef uint32 LocalTransactionId;
+
+typedef uint32 SubTransactionId;
+
+#define InvalidSubTransactionId		((SubTransactionId) 0)
+#define TopSubTransactionId			((SubTransactionId) 1)
+
+/* MultiXactId must be equivalent to TransactionId, to fit in t_xmax */
+typedef TransactionId MultiXactId;
+
+typedef uint32 MultiXactOffset;
+
+typedef uint32 CommandId;
+
+#define FirstCommandId	((CommandId) 0)
+#define InvalidCommandId	(~(CommandId)0)
+
+/*
+ * Array indexing support
+ */
+#define MAXDIM 6
+typedef struct
+{
+	int			indx[MAXDIM];
+} IntArray;
+
+/* ----------------
+ *		Variable-length datatypes all share the 'struct varlena' header.
+ *
+ * NOTE: for TOASTable types, this is an oversimplification, since the value
+ * may be compressed or moved out-of-line.  However datatype-specific routines
+ * are mostly content to deal with de-TOASTed values only, and of course
+ * client-side routines should never see a TOASTed value.  But even in a
+ * de-TOASTed value, beware of touching vl_len_ directly, as its representation
+ * is no longer convenient.  It's recommended that code always use the VARDATA,
+ * VARSIZE, and SET_VARSIZE macros instead of relying on direct mentions of
+ * the struct fields.  See postgres.h for details of the TOASTed form.
+ * ----------------
+ */
+struct varlena
+{
+	char		vl_len_[4];		/* Do not touch this field directly! */
+	char		vl_dat[FLEXIBLE_ARRAY_MEMBER];	/* Data content is here */
+};
+
+#define VARHDRSZ		((int32) sizeof(int32))
+
+/*
+ * These widely-used datatypes are just a varlena header and the data bytes.
+ * There is no terminating null or anything like that --- the data length is
+ * always VARSIZE(ptr) - VARHDRSZ.
+ */
+typedef struct varlena bytea;
+typedef struct varlena text;
+typedef struct varlena BpChar;	/* blank-padded char, ie SQL char(n) */
+typedef struct varlena VarChar; /* var-length char, ie SQL varchar(n) */
+
+/*
+ * Specialized array types.  These are physically laid out just the same
+ * as regular arrays (so that the regular array subscripting code works
+ * with them).  They exist as distinct types mostly for historical reasons:
+ * they have nonstandard I/O behavior which we don't want to change for fear
+ * of breaking applications that look at the system catalogs.  There is also
+ * an implementation issue for oidvector: it's part of the primary key for
+ * pg_proc, and we can't use the normal btree array support routines for that
+ * without circularity.
+ */
+typedef struct
+{
+	int32		vl_len_;		/* these fields must match ArrayType! */
+	int			ndim;			/* always 1 for int2vector */
+	int32		dataoffset;		/* always 0 for int2vector */
+	Oid			elemtype;
+	int			dim1;
+	int			lbound1;
+	int16		values[FLEXIBLE_ARRAY_MEMBER];
+} int2vector;
+
+typedef struct
+{
+	int32		vl_len_;		/* these fields must match ArrayType! */
+	int			ndim;			/* always 1 for oidvector */
+	int32		dataoffset;		/* always 0 for oidvector */
+	Oid			elemtype;
+	int			dim1;
+	int			lbound1;
+	Oid			values[FLEXIBLE_ARRAY_MEMBER];
+} oidvector;
+
+/*
+ * Representation of a Name: effectively just a C string, but null-padded to
+ * exactly NAMEDATALEN bytes.  The use of a struct is historical.
+ */
+typedef struct nameData
+{
+	char		data[NAMEDATALEN];
+} NameData;
+typedef NameData *Name;
+
+#define NameStr(name)	((name).data)
+
+/*
+ * Support macros for escaping strings.  escape_backslash should be TRUE
+ * if generating a non-standard-conforming string.  Prefixing a string
+ * with ESCAPE_STRING_SYNTAX guarantees it is non-standard-conforming.
+ * Beware of multiple evaluation of the "ch" argument!
+ */
+#define SQL_STR_DOUBLE(ch, escape_backslash)	\
+	((ch) == '\'' || ((ch) == '\\' && (escape_backslash)))
+
+#define ESCAPE_STRING_SYNTAX	'E'
+
+/* ----------------------------------------------------------------
+ *				Section 4:	IsValid macros for system types
+ * ----------------------------------------------------------------
+ */
+/*
+ * BoolIsValid
+ *		True iff bool is valid.
+ */
+#define BoolIsValid(boolean)	((boolean) == false || (boolean) == true)
+
+/*
+ * PointerIsValid
+ *		True iff pointer is valid.
+ */
+#define PointerIsValid(pointer) ((const void*)(pointer) != NULL)
+
+/*
+ * PointerIsAligned
+ *		True iff pointer is properly aligned to point to the given type.
+ */
+#define PointerIsAligned(pointer, type) \
+		(((uintptr_t)(pointer) % (sizeof (type))) == 0)
+
+#define OidIsValid(objectId)  ((bool) ((objectId) != InvalidOid))
+
+#define RegProcedureIsValid(p)	OidIsValid(p)
+
+
+/* ----------------------------------------------------------------
+ *				Section 5:	offsetof, lengthof, endof, alignment
+ * ----------------------------------------------------------------
+ */
+/*
+ * offsetof
+ *		Offset of a structure/union field within that structure/union.
+ *
+ *		XXX This is supposed to be part of stddef.h, but isn't on
+ *		some systems (like SunOS 4).
+ */
+#ifndef offsetof
+#define offsetof(type, field)	((long) &((type *)0)->field)
+#endif   /* offsetof */
+
+/*
+ * lengthof
+ *		Number of elements in an array.
+ */
+#define lengthof(array) (sizeof (array) / sizeof ((array)[0]))
+
+/*
+ * endof
+ *		Address of the element one past the last in an array.
+ */
+#define endof(array)	(&(array)[lengthof(array)])
+
+/* ----------------
+ * Alignment macros: align a length or address appropriately for a given type.
+ * The fooALIGN() macros round up to a multiple of the required alignment,
+ * while the fooALIGN_DOWN() macros round down.  The latter are more useful
+ * for problems like "how many X-sized structures will fit in a page?".
+ *
+ * NOTE: TYPEALIGN[_DOWN] will not work if ALIGNVAL is not a power of 2.
+ * That case seems extremely unlikely to be needed in practice, however.
+ * ----------------
+ */
+
+#define TYPEALIGN(ALIGNVAL,LEN)  \
+	(((uintptr_t) (LEN) + ((ALIGNVAL) - 1)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
+
+#define SHORTALIGN(LEN)			TYPEALIGN(ALIGNOF_SHORT, (LEN))
+#define INTALIGN(LEN)			TYPEALIGN(ALIGNOF_INT, (LEN))
+#define LONGALIGN(LEN)			TYPEALIGN(ALIGNOF_LONG, (LEN))
+#define DOUBLEALIGN(LEN)		TYPEALIGN(ALIGNOF_DOUBLE, (LEN))
+#define MAXALIGN(LEN)			TYPEALIGN(MAXIMUM_ALIGNOF, (LEN))
+/* MAXALIGN covers only built-in types, not buffers */
+#define BUFFERALIGN(LEN)		TYPEALIGN(ALIGNOF_BUFFER, (LEN))
+#define CACHELINEALIGN(LEN)		TYPEALIGN(PG_CACHE_LINE_SIZE, (LEN))
+
+#define TYPEALIGN_DOWN(ALIGNVAL,LEN)  \
+	(((uintptr_t) (LEN)) & ~((uintptr_t) ((ALIGNVAL) - 1)))
+
+#define SHORTALIGN_DOWN(LEN)	TYPEALIGN_DOWN(ALIGNOF_SHORT, (LEN))
+#define INTALIGN_DOWN(LEN)		TYPEALIGN_DOWN(ALIGNOF_INT, (LEN))
+#define LONGALIGN_DOWN(LEN)		TYPEALIGN_DOWN(ALIGNOF_LONG, (LEN))
+#define DOUBLEALIGN_DOWN(LEN)	TYPEALIGN_DOWN(ALIGNOF_DOUBLE, (LEN))
+#define MAXALIGN_DOWN(LEN)		TYPEALIGN_DOWN(MAXIMUM_ALIGNOF, (LEN))
+
+/*
+ * The above macros will not work with types wider than uintptr_t, like with
+ * uint64 on 32-bit platforms.  That's not problem for the usual use where a
+ * pointer or a length is aligned, but for the odd case that you need to
+ * align something (potentially) wider, use TYPEALIGN64.
+ */
+#define TYPEALIGN64(ALIGNVAL,LEN)  \
+	(((uint64) (LEN) + ((ALIGNVAL) - 1)) & ~((uint64) ((ALIGNVAL) - 1)))
+
+/* we don't currently need wider versions of the other ALIGN macros */
+#define MAXALIGN64(LEN)			TYPEALIGN64(MAXIMUM_ALIGNOF, (LEN))
+
+/* ----------------
+ * Attribute macros
+ *
+ * GCC: https://gcc.gnu.org/onlinedocs/gcc/Function-Attributes.html
+ * GCC: https://gcc.gnu.org/onlinedocs/gcc/Type-Attributes.html
+ * Sunpro: https://docs.oracle.com/cd/E18659_01/html/821-1384/gjzke.html
+ * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/function_attributes.html
+ * XLC: http://www-01.ibm.com/support/knowledgecenter/SSGH2K_11.1.0/com.ibm.xlc111.aix.doc/language_ref/type_attrib.html
+ * ----------------
+ */
+
+/* only GCC supports the unused attribute */
+#ifdef __GNUC__
+#define pg_attribute_unused() __attribute__((unused))
+#else
+#define pg_attribute_unused()
+#endif
+
+/* GCC and XLC support format attributes */
+#if defined(__GNUC__) || defined(__IBMC__)
+#define pg_attribute_format_arg(a) __attribute__((format_arg(a)))
+#define pg_attribute_printf(f,a) __attribute__((format(PG_PRINTF_ATTRIBUTE, f, a)))
+#else
+#define pg_attribute_format_arg(a)
+#define pg_attribute_printf(f,a)
+#endif
+
+/* GCC, Sunpro and XLC support aligned, packed and noreturn */
+#if defined(__GNUC__) || defined(__SUNPRO_C) || defined(__IBMC__)
+#define pg_attribute_aligned(a) __attribute__((aligned(a)))
+#define pg_attribute_noreturn() __attribute__((noreturn))
+#define pg_attribute_packed() __attribute__((packed))
+#define HAVE_PG_ATTRIBUTE_NORETURN 1
+#else
+/*
+ * NB: aligned and packed are not given default definitions because they
+ * affect code functionality; they *must* be implemented by the compiler
+ * if they are to be used.
+ */
+#define pg_attribute_noreturn()
+#endif
+
+/* ----------------------------------------------------------------
+ *				Section 6:	assertions
+ * ----------------------------------------------------------------
+ */
+
+/*
+ * USE_ASSERT_CHECKING, if defined, turns on all the assertions.
+ * - plai  9/5/90
+ *
+ * It should _NOT_ be defined in releases or in benchmark copies
+ */
+
+/*
+ * Assert() can be used in both frontend and backend code. In frontend code it
+ * just calls the standard assert, if it's available. If use of assertions is
+ * not configured, it does nothing.
+ */
+#ifndef USE_ASSERT_CHECKING
+
+#define Assert(condition)	((void)true)
+#define AssertMacro(condition)	((void)true)
+#define AssertArg(condition)	((void)true)
+#define AssertState(condition)	((void)true)
+#define AssertPointerAlignment(ptr, bndr)	((void)true)
+#define Trap(condition, errorType)	((void)true)
+#define TrapMacro(condition, errorType) (true)
+
+#elif defined(FRONTEND)
+
+#include <assert.h>
+#define Assert(p) assert(p)
+#define AssertMacro(p)	((void) assert(p))
+#define AssertArg(condition) assert(condition)
+#define AssertState(condition) assert(condition)
+#define AssertPointerAlignment(ptr, bndr)	((void)true)
+#else							/* USE_ASSERT_CHECKING && !FRONTEND */
+
+/*
+ * Trap
+ *		Generates an exception if the given condition is true.
+ */
+#define Trap(condition, errorType) \
+	do { \
+		if (condition) \
+			ExceptionalCondition(CppAsString(condition), (errorType), \
+								 __FILE__, __LINE__); \
+	} while (0)
+
+/*
+ *	TrapMacro is the same as Trap but it's intended for use in macros:
+ *
+ *		#define foo(x) (AssertMacro(x != 0), bar(x))
+ *
+ *	Isn't CPP fun?
+ */
+#define TrapMacro(condition, errorType) \
+	((bool) (! (condition) || \
+			 (ExceptionalCondition(CppAsString(condition), (errorType), \
+								   __FILE__, __LINE__), 0)))
+
+#define Assert(condition) \
+		Trap(!(condition), "FailedAssertion")
+
+#define AssertMacro(condition) \
+		((void) TrapMacro(!(condition), "FailedAssertion"))
+
+#define AssertArg(condition) \
+		Trap(!(condition), "BadArgument")
+
+#define AssertState(condition) \
+		Trap(!(condition), "BadState")
+
+/*
+ * Check that `ptr' is `bndr' aligned.
+ */
+#define AssertPointerAlignment(ptr, bndr) \
+	Trap(TYPEALIGN(bndr, (uintptr_t)(ptr)) != (uintptr_t)(ptr), \
+		 "UnalignedPointer")
+
+#endif   /* USE_ASSERT_CHECKING && !FRONTEND */
+
+/*
+ * Macros to support compile-time assertion checks.
+ *
+ * If the "condition" (a compile-time-constant expression) evaluates to false,
+ * throw a compile error using the "errmessage" (a string literal).
+ *
+ * gcc 4.6 and up supports _Static_assert(), but there are bizarre syntactic
+ * placement restrictions.  These macros make it safe to use as a statement
+ * or in an expression, respectively.
+ *
+ * Otherwise we fall back on a kluge that assumes the compiler will complain
+ * about a negative width for a struct bit-field.  This will not include a
+ * helpful error message, but it beats not getting an error at all.
+ */
+#ifdef HAVE__STATIC_ASSERT
+#define StaticAssertStmt(condition, errmessage) \
+	do { _Static_assert(condition, errmessage); } while(0)
+#define StaticAssertExpr(condition, errmessage) \
+	({ StaticAssertStmt(condition, errmessage); true; })
+#else							/* !HAVE__STATIC_ASSERT */
+#define StaticAssertStmt(condition, errmessage) \
+	((void) sizeof(struct { int static_assert_failure : (condition) ? 1 : -1; }))
+#define StaticAssertExpr(condition, errmessage) \
+	StaticAssertStmt(condition, errmessage)
+#endif   /* HAVE__STATIC_ASSERT */
+
+
+/*
+ * Compile-time checks that a variable (or expression) has the specified type.
+ *
+ * AssertVariableIsOfType() can be used as a statement.
+ * AssertVariableIsOfTypeMacro() is intended for use in macros, eg
+ *		#define foo(x) (AssertVariableIsOfTypeMacro(x, int), bar(x))
+ *
+ * If we don't have __builtin_types_compatible_p, we can still assert that
+ * the types have the same size.  This is far from ideal (especially on 32-bit
+ * platforms) but it provides at least some coverage.
+ */
+#ifdef HAVE__BUILTIN_TYPES_COMPATIBLE_P
+#define AssertVariableIsOfType(varname, typename) \
+	StaticAssertStmt(__builtin_types_compatible_p(__typeof__(varname), typename), \
+	CppAsString(varname) " does not have type " CppAsString(typename))
+#define AssertVariableIsOfTypeMacro(varname, typename) \
+	((void) StaticAssertExpr(__builtin_types_compatible_p(__typeof__(varname), typename), \
+	 CppAsString(varname) " does not have type " CppAsString(typename)))
+#else							/* !HAVE__BUILTIN_TYPES_COMPATIBLE_P */
+#define AssertVariableIsOfType(varname, typename) \
+	StaticAssertStmt(sizeof(varname) == sizeof(typename), \
+	CppAsString(varname) " does not have type " CppAsString(typename))
+#define AssertVariableIsOfTypeMacro(varname, typename) \
+	((void) StaticAssertExpr(sizeof(varname) == sizeof(typename),		\
+	 CppAsString(varname) " does not have type " CppAsString(typename)))
+#endif   /* HAVE__BUILTIN_TYPES_COMPATIBLE_P */
+
+
+/* ----------------------------------------------------------------
+ *				Section 7:	widely useful macros
+ * ----------------------------------------------------------------
+ */
+/*
+ * Max
+ *		Return the maximum of two numbers.
+ */
+#define Max(x, y)		((x) > (y) ? (x) : (y))
+
+/*
+ * Min
+ *		Return the minimum of two numbers.
+ */
+#define Min(x, y)		((x) < (y) ? (x) : (y))
+
+/*
+ * Abs
+ *		Return the absolute value of the argument.
+ */
+#define Abs(x)			((x) >= 0 ? (x) : -(x))
+
+/*
+ * StrNCpy
+ *	Like standard library function strncpy(), except that result string
+ *	is guaranteed to be null-terminated --- that is, at most N-1 bytes
+ *	of the source string will be kept.
+ *	Also, the macro returns no result (too hard to do that without
+ *	evaluating the arguments multiple times, which seems worse).
+ *
+ *	BTW: when you need to copy a non-null-terminated string (like a text
+ *	datum) and add a null, do not do it with StrNCpy(..., len+1).  That
+ *	might seem to work, but it fetches one byte more than there is in the
+ *	text object.  One fine day you'll have a SIGSEGV because there isn't
+ *	another byte before the end of memory.  Don't laugh, we've had real
+ *	live bug reports from real live users over exactly this mistake.
+ *	Do it honestly with "memcpy(dst,src,len); dst[len] = '\0';", instead.
+ */
+#define StrNCpy(dst,src,len) \
+	do \
+	{ \
+		char * _dst = (dst); \
+		Size _len = (len); \
+\
+		if (_len > 0) \
+		{ \
+			strncpy(_dst, (src), _len); \
+			_dst[_len-1] = '\0'; \
+		} \
+	} while (0)
+
+
+/* Get a bit mask of the bits set in non-long aligned addresses */
+#define LONG_ALIGN_MASK (sizeof(long) - 1)
+
+/*
+ * MemSet
+ *	Exactly the same as standard library function memset(), but considerably
+ *	faster for zeroing small word-aligned structures (such as parsetree nodes).
+ *	This has to be a macro because the main point is to avoid function-call
+ *	overhead.   However, we have also found that the loop is faster than
+ *	native libc memset() on some platforms, even those with assembler
+ *	memset() functions.  More research needs to be done, perhaps with
+ *	MEMSET_LOOP_LIMIT tests in configure.
+ */
+#define MemSet(start, val, len) \
+	do \
+	{ \
+		/* must be void* because we don't know if it is integer aligned yet */ \
+		void   *_vstart = (void *) (start); \
+		int		_val = (val); \
+		Size	_len = (len); \
+\
+		if ((((uintptr_t) _vstart) & LONG_ALIGN_MASK) == 0 && \
+			(_len & LONG_ALIGN_MASK) == 0 && \
+			_val == 0 && \
+			_len <= MEMSET_LOOP_LIMIT && \
+			/* \
+			 *	If MEMSET_LOOP_LIMIT == 0, optimizer should find \
+			 *	the whole "if" false at compile time. \
+			 */ \
+			MEMSET_LOOP_LIMIT != 0) \
+		{ \
+			long *_start = (long *) _vstart; \
+			long *_stop = (long *) ((char *) _start + _len); \
+			while (_start < _stop) \
+				*_start++ = 0; \
+		} \
+		else \
+			memset(_vstart, _val, _len); \
+	} while (0)
+
+/*
+ * MemSetAligned is the same as MemSet except it omits the test to see if
+ * "start" is word-aligned.  This is okay to use if the caller knows a-priori
+ * that the pointer is suitably aligned (typically, because he just got it
+ * from palloc(), which always delivers a max-aligned pointer).
+ */
+#define MemSetAligned(start, val, len) \
+	do \
+	{ \
+		long   *_start = (long *) (start); \
+		int		_val = (val); \
+		Size	_len = (len); \
+\
+		if ((_len & LONG_ALIGN_MASK) == 0 && \
+			_val == 0 && \
+			_len <= MEMSET_LOOP_LIMIT && \
+			MEMSET_LOOP_LIMIT != 0) \
+		{ \
+			long *_stop = (long *) ((char *) _start + _len); \
+			while (_start < _stop) \
+				*_start++ = 0; \
+		} \
+		else \
+			memset(_start, _val, _len); \
+	} while (0)
+
+
+/*
+ * MemSetTest/MemSetLoop are a variant version that allow all the tests in
+ * MemSet to be done at compile time in cases where "val" and "len" are
+ * constants *and* we know the "start" pointer must be word-aligned.
+ * If MemSetTest succeeds, then it is okay to use MemSetLoop, otherwise use
+ * MemSetAligned.  Beware of multiple evaluations of the arguments when using
+ * this approach.
+ */
+#define MemSetTest(val, len) \
+	( ((len) & LONG_ALIGN_MASK) == 0 && \
+	(len) <= MEMSET_LOOP_LIMIT && \
+	MEMSET_LOOP_LIMIT != 0 && \
+	(val) == 0 )
+
+#define MemSetLoop(start, val, len) \
+	do \
+	{ \
+		long * _start = (long *) (start); \
+		long * _stop = (long *) ((char *) _start + (Size) (len)); \
+	\
+		while (_start < _stop) \
+			*_start++ = 0; \
+	} while (0)
+
+
+/*
+ * Mark a point as unreachable in a portable fashion.  This should preferably
+ * be something that the compiler understands, to aid code generation.
+ * In assert-enabled builds, we prefer abort() for debugging reasons.
+ */
+#if defined(HAVE__BUILTIN_UNREACHABLE) && !defined(USE_ASSERT_CHECKING)
+#define pg_unreachable() __builtin_unreachable()
+#elif defined(_MSC_VER) && !defined(USE_ASSERT_CHECKING)
+#define pg_unreachable() __assume(0)
+#else
+#define pg_unreachable() abort()
+#endif
+
+
+/* ----------------------------------------------------------------
+ *				Section 8:	random stuff
+ * ----------------------------------------------------------------
+ */
+
+/* msb for char */
+#define HIGHBIT					(0x80)
+#define IS_HIGHBIT_SET(ch)		((unsigned char)(ch) & HIGHBIT)
+
+#define STATUS_OK				(0)
+#define STATUS_ERROR			(-1)
+#define STATUS_EOF				(-2)
+#define STATUS_FOUND			(1)
+#define STATUS_WAITING			(2)
+
+
+/*
+ * Append PG_USED_FOR_ASSERTS_ONLY to definitions of variables that are only
+ * used in assert-enabled builds, to avoid compiler warnings about unused
+ * variables in assert-disabled builds.
+ */
+#ifdef USE_ASSERT_CHECKING
+#define PG_USED_FOR_ASSERTS_ONLY
+#else
+#define PG_USED_FOR_ASSERTS_ONLY pg_attribute_unused()
+#endif
+
+
+/* gettext domain name mangling */
+
+/*
+ * To better support parallel installations of major PostgreSQL
+ * versions as well as parallel installations of major library soname
+ * versions, we mangle the gettext domain name by appending those
+ * version numbers.  The coding rule ought to be that wherever the
+ * domain name is mentioned as a literal, it must be wrapped into
+ * PG_TEXTDOMAIN().  The macros below do not work on non-literals; but
+ * that is somewhat intentional because it avoids having to worry
+ * about multiple states of premangling and postmangling as the values
+ * are being passed around.
+ *
+ * Make sure this matches the installation rules in nls-global.mk.
+ */
+
+/* need a second indirection because we want to stringize the macro value, not the name */
+#define CppAsString2(x) CppAsString(x)
+
+#ifdef SO_MAJOR_VERSION
+#define PG_TEXTDOMAIN(domain) (domain CppAsString2(SO_MAJOR_VERSION) "-" PG_MAJORVERSION)
+#else
+#define PG_TEXTDOMAIN(domain) (domain "-" PG_MAJORVERSION)
+#endif
+
+
+/* ----------------------------------------------------------------
+ *				Section 9: system-specific hacks
+ *
+ *		This should be limited to things that absolutely have to be
+ *		included in every source file.  The port-specific header file
+ *		is usually a better place for this sort of thing.
+ * ----------------------------------------------------------------
+ */
+
+/*
+ *	NOTE:  this is also used for opening text files.
+ *	WIN32 treats Control-Z as EOF in files opened in text mode.
+ *	Therefore, we open files in binary mode on Win32 so we can read
+ *	literal control-Z.  The other affect is that we see CRLF, but
+ *	that is OK because we can already handle those cleanly.
+ */
+#if defined(WIN32) || defined(__CYGWIN__)
+#define PG_BINARY	O_BINARY
+#define PG_BINARY_A "ab"
+#define PG_BINARY_R "rb"
+#define PG_BINARY_W "wb"
+#else
+#define PG_BINARY	0
+#define PG_BINARY_A "a"
+#define PG_BINARY_R "r"
+#define PG_BINARY_W "w"
+#endif
+
+/*
+ * Provide prototypes for routines not present in a particular machine's
+ * standard C library.
+ */
+
+#if !HAVE_DECL_SNPRINTF
+extern int	snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
+#endif
+
+#if !HAVE_DECL_VSNPRINTF
+extern int	vsnprintf(char *str, size_t count, const char *fmt, va_list args);
+#endif
+
+#if !defined(HAVE_MEMMOVE) && !defined(memmove)
+#define memmove(d, s, c)		bcopy(s, d, c)
+#endif
+
+/* no special DLL markers on most ports */
+#ifndef PGDLLIMPORT
+#define PGDLLIMPORT
+#endif
+#ifndef PGDLLEXPORT
+#define PGDLLEXPORT
+#endif
+
+/*
+ * The following is used as the arg list for signal handlers.  Any ports
+ * that take something other than an int argument should override this in
+ * their pg_config_os.h file.  Note that variable names are required
+ * because it is used in both the prototypes as well as the definitions.
+ * Note also the long name.  We expect that this won't collide with
+ * other names causing compiler warnings.
+ */
+
+#ifndef SIGNAL_ARGS
+#define SIGNAL_ARGS  int postgres_signal_arg
+#endif
+
+/*
+ * When there is no sigsetjmp, its functionality is provided by plain
+ * setjmp. Incidentally, nothing provides setjmp's functionality in
+ * that case.  We now support the case only on Windows.
+ */
+#ifdef WIN32
+#define sigjmp_buf jmp_buf
+#define sigsetjmp(x,y) setjmp(x)
+#define siglongjmp longjmp
+#endif
+
+#if defined(HAVE_FDATASYNC) && !HAVE_DECL_FDATASYNC
+extern int	fdatasync(int fildes);
+#endif
+
+/* If strtoq() exists, rename it to the more standard strtoll() */
+#if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOLL) && defined(HAVE_STRTOQ)
+#define strtoll strtoq
+#define HAVE_STRTOLL 1
+#endif
+
+/* If strtouq() exists, rename it to the more standard strtoull() */
+#if defined(HAVE_LONG_LONG_INT_64) && !defined(HAVE_STRTOULL) && defined(HAVE_STRTOUQ)
+#define strtoull strtouq
+#define HAVE_STRTOULL 1
+#endif
+
+/*
+ * We assume if we have these two functions, we have their friends too, and
+ * can use the wide-character functions.
+ */
+#if defined(HAVE_WCSTOMBS) && defined(HAVE_TOWLOWER)
+#define USE_WIDE_UPPER_LOWER
+#endif
+
+/* EXEC_BACKEND defines */
+#ifdef EXEC_BACKEND
+#define NON_EXEC_STATIC
+#else
+#define NON_EXEC_STATIC static
+#endif
+
+/* /port compatibility functions */
+#include "port.h"
+
+#endif   /* C_H */

+ 675 - 0
libpq_test/include/internal/libpq-int.h

@@ -0,0 +1,675 @@
+/*-------------------------------------------------------------------------
+ *
+ * libpq-int.h
+ *	  This file contains internal definitions meant to be used only by
+ *	  the frontend libpq library, not by applications that call it.
+ *
+ *	  An application can include this file if it wants to bypass the
+ *	  official API defined by libpq-fe.h, but code that does so is much
+ *	  more likely to break across PostgreSQL releases than code that uses
+ *	  only the official API.
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/interfaces/libpq/libpq-int.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifndef LIBPQ_INT_H
+#define LIBPQ_INT_H
+
+/* We assume libpq-fe.h has already been included. */
+#include "postgres_fe.h"
+#include "libpq-events.h"
+
+#include <time.h>
+#include <sys/types.h>
+#ifndef WIN32
+#include <sys/time.h>
+#endif
+
+#ifdef ENABLE_THREAD_SAFETY
+#ifdef WIN32
+#include "pthread-win32.h"
+#else
+#include <pthread.h>
+#endif
+#include <signal.h>
+#endif
+
+/* include stuff common to fe and be */
+#include "getaddrinfo.h"
+#include "libpq/pqcomm.h"
+/* include stuff found in fe only */
+#include "pqexpbuffer.h"
+
+#ifdef ENABLE_GSS
+#if defined(HAVE_GSSAPI_H)
+#include <gssapi.h>
+#else
+#include <gssapi/gssapi.h>
+#endif
+#endif
+
+#ifdef ENABLE_SSPI
+#define SECURITY_WIN32
+#if defined(WIN32) && !defined(WIN32_ONLY_COMPILER)
+#include <ntsecapi.h>
+#endif
+#include <security.h>
+#undef SECURITY_WIN32
+
+#ifndef ENABLE_GSS
+/*
+ * Define a fake structure compatible with GSSAPI on Unix.
+ */
+typedef struct
+{
+	void	   *value;
+	int			length;
+} gss_buffer_desc;
+#endif
+#endif   /* ENABLE_SSPI */
+
+#ifdef USE_OPENSSL
+#include <openssl/ssl.h>
+#include <openssl/err.h>
+
+#if (OPENSSL_VERSION_NUMBER >= 0x00907000L) && !defined(OPENSSL_NO_ENGINE)
+#define USE_SSL_ENGINE
+#endif
+#endif   /* USE_OPENSSL */
+
+/*
+ * POSTGRES backend dependent Constants.
+ */
+#define CMDSTATUS_LEN 64		/* should match COMPLETION_TAG_BUFSIZE */
+
+/*
+ * PGresult and the subsidiary types PGresAttDesc, PGresAttValue
+ * represent the result of a query (or more precisely, of a single SQL
+ * command --- a query string given to PQexec can contain multiple commands).
+ * Note we assume that a single command can return at most one tuple group,
+ * hence there is no need for multiple descriptor sets.
+ */
+
+/* Subsidiary-storage management structure for PGresult.
+ * See space management routines in fe-exec.c for details.
+ * Note that space[k] refers to the k'th byte starting from the physical
+ * head of the block --- it's a union, not a struct!
+ */
+typedef union pgresult_data PGresult_data;
+
+union pgresult_data
+{
+	PGresult_data *next;		/* link to next block, or NULL */
+	char		space[1];		/* dummy for accessing block as bytes */
+};
+
+/* Data about a single parameter of a prepared statement */
+typedef struct pgresParamDesc
+{
+	Oid			typid;			/* type id */
+} PGresParamDesc;
+
+/*
+ * Data for a single attribute of a single tuple
+ *
+ * We use char* for Attribute values.
+ *
+ * The value pointer always points to a null-terminated area; we add a
+ * null (zero) byte after whatever the backend sends us.  This is only
+ * particularly useful for text values ... with a binary value, the
+ * value might have embedded nulls, so the application can't use C string
+ * operators on it.  But we add a null anyway for consistency.
+ * Note that the value itself does not contain a length word.
+ *
+ * A NULL attribute is a special case in two ways: its len field is NULL_LEN
+ * and its value field points to null_field in the owning PGresult.  All the
+ * NULL attributes in a query result point to the same place (there's no need
+ * to store a null string separately for each one).
+ */
+
+#define NULL_LEN		(-1)	/* pg_result len for NULL value */
+
+typedef struct pgresAttValue
+{
+	int			len;			/* length in bytes of the value */
+	char	   *value;			/* actual value, plus terminating zero byte */
+} PGresAttValue;
+
+/* Typedef for message-field list entries */
+typedef struct pgMessageField
+{
+	struct pgMessageField *next;	/* list link */
+	char		code;			/* field code */
+	char		contents[FLEXIBLE_ARRAY_MEMBER];		/* value, nul-terminated */
+} PGMessageField;
+
+/* Fields needed for notice handling */
+typedef struct
+{
+	PQnoticeReceiver noticeRec; /* notice message receiver */
+	void	   *noticeRecArg;
+	PQnoticeProcessor noticeProc;		/* notice message processor */
+	void	   *noticeProcArg;
+} PGNoticeHooks;
+
+typedef struct PGEvent
+{
+	PGEventProc proc;			/* the function to call on events */
+	char	   *name;			/* used only for error messages */
+	void	   *passThrough;	/* pointer supplied at registration time */
+	void	   *data;			/* optional state (instance) data */
+	bool		resultInitialized;		/* T if RESULTCREATE/COPY succeeded */
+} PGEvent;
+
+struct pg_result
+{
+	int			ntups;
+	int			numAttributes;
+	PGresAttDesc *attDescs;
+	PGresAttValue **tuples;		/* each PGresTuple is an array of
+								 * PGresAttValue's */
+	int			tupArrSize;		/* allocated size of tuples array */
+	int			numParameters;
+	PGresParamDesc *paramDescs;
+	ExecStatusType resultStatus;
+	char		cmdStatus[CMDSTATUS_LEN];		/* cmd status from the query */
+	int			binary;			/* binary tuple values if binary == 1,
+								 * otherwise text */
+
+	/*
+	 * These fields are copied from the originating PGconn, so that operations
+	 * on the PGresult don't have to reference the PGconn.
+	 */
+	PGNoticeHooks noticeHooks;
+	PGEvent    *events;
+	int			nEvents;
+	int			client_encoding;	/* encoding id */
+
+	/*
+	 * Error information (all NULL if not an error result).  errMsg is the
+	 * "overall" error message returned by PQresultErrorMessage.  If we have
+	 * per-field info then it is stored in a linked list.
+	 */
+	char	   *errMsg;			/* error message, or NULL if no error */
+	PGMessageField *errFields;	/* message broken into fields */
+	char	   *errQuery;		/* text of triggering query, if available */
+
+	/* All NULL attributes in the query result point to this null string */
+	char		null_field[1];
+
+	/*
+	 * Space management information.  Note that attDescs and error stuff, if
+	 * not null, point into allocated blocks.  But tuples points to a
+	 * separately malloc'd block, so that we can realloc it.
+	 */
+	PGresult_data *curBlock;	/* most recently allocated block */
+	int			curOffset;		/* start offset of free space in block */
+	int			spaceLeft;		/* number of free bytes remaining in block */
+};
+
+/* PGAsyncStatusType defines the state of the query-execution state machine */
+typedef enum
+{
+	PGASYNC_IDLE,				/* nothing's happening, dude */
+	PGASYNC_BUSY,				/* query in progress */
+	PGASYNC_READY,				/* result ready for PQgetResult */
+	PGASYNC_COPY_IN,			/* Copy In data transfer in progress */
+	PGASYNC_COPY_OUT,			/* Copy Out data transfer in progress */
+	PGASYNC_COPY_BOTH			/* Copy In/Out data transfer in progress */
+} PGAsyncStatusType;
+
+/* PGQueryClass tracks which query protocol we are now executing */
+typedef enum
+{
+	PGQUERY_SIMPLE,				/* simple Query protocol (PQexec) */
+	PGQUERY_EXTENDED,			/* full Extended protocol (PQexecParams) */
+	PGQUERY_PREPARE,			/* Parse only (PQprepare) */
+	PGQUERY_DESCRIBE			/* Describe Statement or Portal */
+} PGQueryClass;
+
+/* PGSetenvStatusType defines the state of the PQSetenv state machine */
+/* (this is used only for 2.0-protocol connections) */
+typedef enum
+{
+	SETENV_STATE_CLIENT_ENCODING_SEND,	/* About to send an Environment Option */
+	SETENV_STATE_CLIENT_ENCODING_WAIT,	/* Waiting for above send to complete */
+	SETENV_STATE_OPTION_SEND,	/* About to send an Environment Option */
+	SETENV_STATE_OPTION_WAIT,	/* Waiting for above send to complete */
+	SETENV_STATE_QUERY1_SEND,	/* About to send a status query */
+	SETENV_STATE_QUERY1_WAIT,	/* Waiting for query to complete */
+	SETENV_STATE_QUERY2_SEND,	/* About to send a status query */
+	SETENV_STATE_QUERY2_WAIT,	/* Waiting for query to complete */
+	SETENV_STATE_IDLE
+} PGSetenvStatusType;
+
+/* Typedef for the EnvironmentOptions[] array */
+typedef struct PQEnvironmentOption
+{
+	const char *envName,		/* name of an environment variable */
+			   *pgName;			/* name of corresponding SET variable */
+} PQEnvironmentOption;
+
+/* Typedef for parameter-status list entries */
+typedef struct pgParameterStatus
+{
+	struct pgParameterStatus *next;		/* list link */
+	char	   *name;			/* parameter name */
+	char	   *value;			/* parameter value */
+	/* Note: name and value are stored in same malloc block as struct is */
+} pgParameterStatus;
+
+/* large-object-access data ... allocated only if large-object code is used. */
+typedef struct pgLobjfuncs
+{
+	Oid			fn_lo_open;		/* OID of backend function lo_open		*/
+	Oid			fn_lo_close;	/* OID of backend function lo_close		*/
+	Oid			fn_lo_creat;	/* OID of backend function lo_creat		*/
+	Oid			fn_lo_create;	/* OID of backend function lo_create	*/
+	Oid			fn_lo_unlink;	/* OID of backend function lo_unlink	*/
+	Oid			fn_lo_lseek;	/* OID of backend function lo_lseek		*/
+	Oid			fn_lo_lseek64;	/* OID of backend function lo_lseek64	*/
+	Oid			fn_lo_tell;		/* OID of backend function lo_tell		*/
+	Oid			fn_lo_tell64;	/* OID of backend function lo_tell64	*/
+	Oid			fn_lo_truncate; /* OID of backend function lo_truncate	*/
+	Oid			fn_lo_truncate64;		/* OID of function lo_truncate64 */
+	Oid			fn_lo_read;		/* OID of backend function LOread		*/
+	Oid			fn_lo_write;	/* OID of backend function LOwrite		*/
+} PGlobjfuncs;
+
+/* PGdataValue represents a data field value being passed to a row processor.
+ * It could be either text or binary data; text data is not zero-terminated.
+ * A SQL NULL is represented by len < 0; then value is still valid but there
+ * are no data bytes there.
+ */
+typedef struct pgDataValue
+{
+	int			len;			/* data length in bytes, or <0 if NULL */
+	const char *value;			/* data value, without zero-termination */
+} PGdataValue;
+
+/*
+ * PGconn stores all the state data associated with a single connection
+ * to a backend.
+ */
+struct pg_conn
+{
+	/* Saved values of connection options */
+	char	   *pghost;			/* the machine on which the server is running */
+	char	   *pghostaddr;		/* the numeric IP address of the machine on
+								 * which the server is running.  Takes
+								 * precedence over above. */
+	char	   *pgport;			/* the server's communication port number */
+	char	   *pgunixsocket;	/* the directory of the server's Unix-domain
+								 * socket; if NULL, use DEFAULT_PGSOCKET_DIR */
+	char	   *pgtty;			/* tty on which the backend messages is
+								 * displayed (OBSOLETE, NOT USED) */
+	char	   *connect_timeout;	/* connection timeout (numeric string) */
+	char	   *client_encoding_initial;		/* encoding to use */
+	char	   *pgoptions;		/* options to start the backend with */
+	char	   *appname;		/* application name */
+	char	   *fbappname;		/* fallback application name */
+	char	   *dbName;			/* database name */
+	char	   *replication;	/* connect as the replication standby? */
+	char	   *pguser;			/* Postgres username and password, if any */
+	char	   *pgpass;
+	char	   *keepalives;		/* use TCP keepalives? */
+	char	   *keepalives_idle;	/* time between TCP keepalives */
+	char	   *keepalives_interval;	/* time between TCP keepalive
+										 * retransmits */
+	char	   *keepalives_count;		/* maximum number of TCP keepalive
+										 * retransmits */
+	char	   *sslmode;		/* SSL mode (require,prefer,allow,disable) */
+	char	   *sslcompression; /* SSL compression (0 or 1) */
+	char	   *sslkey;			/* client key filename */
+	char	   *sslcert;		/* client certificate filename */
+	char	   *sslrootcert;	/* root certificate filename */
+	char	   *sslcrl;			/* certificate revocation list filename */
+	char	   *requirepeer;	/* required peer credentials for local sockets */
+
+#if defined(ENABLE_GSS) || defined(ENABLE_SSPI)
+	char	   *krbsrvname;		/* Kerberos service name */
+#endif
+
+	/* Optional file to write trace info to */
+	FILE	   *Pfdebug;
+
+	/* Callback procedures for notice message processing */
+	PGNoticeHooks noticeHooks;
+
+	/* Event procs registered via PQregisterEventProc */
+	PGEvent    *events;			/* expandable array of event data */
+	int			nEvents;		/* number of active events */
+	int			eventArraySize; /* allocated array size */
+
+	/* Status indicators */
+	ConnStatusType status;
+	PGAsyncStatusType asyncStatus;
+	PGTransactionStatusType xactStatus; /* never changes to ACTIVE */
+	PGQueryClass queryclass;
+	char	   *last_query;		/* last SQL command, or NULL if unknown */
+	char		last_sqlstate[6];		/* last reported SQLSTATE */
+	bool		options_valid;	/* true if OK to attempt connection */
+	bool		nonblocking;	/* whether this connection is using nonblock
+								 * sending semantics */
+	bool		singleRowMode;	/* return current query result row-by-row? */
+	char		copy_is_binary; /* 1 = copy binary, 0 = copy text */
+	int			copy_already_done;		/* # bytes already returned in COPY
+										 * OUT */
+	PGnotify   *notifyHead;		/* oldest unreported Notify msg */
+	PGnotify   *notifyTail;		/* newest unreported Notify msg */
+
+	/* Connection data */
+	/* See PQconnectPoll() for how we use 'int' and not 'pgsocket'. */
+	pgsocket	sock;			/* FD for socket, PGINVALID_SOCKET if
+								 * unconnected */
+	SockAddr	laddr;			/* Local address */
+	SockAddr	raddr;			/* Remote address */
+	ProtocolVersion pversion;	/* FE/BE protocol version in use */
+	int			sversion;		/* server version, e.g. 70401 for 7.4.1 */
+	bool		auth_req_received;		/* true if any type of auth req
+										 * received */
+	bool		password_needed;	/* true if server demanded a password */
+	bool		dot_pgpass_used;	/* true if used .pgpass */
+	bool		sigpipe_so;		/* have we masked SIGPIPE via SO_NOSIGPIPE? */
+	bool		sigpipe_flag;	/* can we mask SIGPIPE via MSG_NOSIGNAL? */
+
+	/* Transient state needed while establishing connection */
+	struct addrinfo *addrlist;	/* list of possible backend addresses */
+	struct addrinfo *addr_cur;	/* the one currently being tried */
+	int			addrlist_family;	/* needed to know how to free addrlist */
+	PGSetenvStatusType setenv_state;	/* for 2.0 protocol only */
+	const PQEnvironmentOption *next_eo;
+	bool		send_appname;	/* okay to send application_name? */
+
+	/* Miscellaneous stuff */
+	int			be_pid;			/* PID of backend --- needed for cancels */
+	int			be_key;			/* key of backend --- needed for cancels */
+	char		md5Salt[4];		/* password salt received from backend */
+	pgParameterStatus *pstatus; /* ParameterStatus data */
+	int			client_encoding;	/* encoding id */
+	bool		std_strings;	/* standard_conforming_strings */
+	PGVerbosity verbosity;		/* error/notice message verbosity */
+	PGContextVisibility show_context;	/* whether to show CONTEXT field */
+	PGlobjfuncs *lobjfuncs;		/* private state for large-object access fns */
+
+	/* Buffer for data received from backend and not yet processed */
+	char	   *inBuffer;		/* currently allocated buffer */
+	int			inBufSize;		/* allocated size of buffer */
+	int			inStart;		/* offset to first unconsumed data in buffer */
+	int			inCursor;		/* next byte to tentatively consume */
+	int			inEnd;			/* offset to first position after avail data */
+
+	/* Buffer for data not yet sent to backend */
+	char	   *outBuffer;		/* currently allocated buffer */
+	int			outBufSize;		/* allocated size of buffer */
+	int			outCount;		/* number of chars waiting in buffer */
+
+	/* State for constructing messages in outBuffer */
+	int			outMsgStart;	/* offset to msg start (length word); if -1,
+								 * msg has no length word */
+	int			outMsgEnd;		/* offset to msg end (so far) */
+
+	/* Row processor interface workspace */
+	PGdataValue *rowBuf;		/* array for passing values to rowProcessor */
+	int			rowBufLen;		/* number of entries allocated in rowBuf */
+
+	/* Status for asynchronous result construction */
+	PGresult   *result;			/* result being constructed */
+	PGresult   *next_result;	/* next result (used in single-row mode) */
+
+	/* Assorted state for SSL, GSS, etc */
+
+#ifdef USE_SSL
+	bool		allow_ssl_try;	/* Allowed to try SSL negotiation */
+	bool		wait_ssl_try;	/* Delay SSL negotiation until after
+								 * attempting normal connection */
+	bool		ssl_in_use;
+#ifdef USE_OPENSSL
+	SSL		   *ssl;			/* SSL status, if have SSL connection */
+	X509	   *peer;			/* X509 cert of server */
+#ifdef USE_SSL_ENGINE
+	ENGINE	   *engine;			/* SSL engine, if any */
+#else
+	void	   *engine;			/* dummy field to keep struct the same if
+								 * OpenSSL version changes */
+#endif
+#endif   /* USE_OPENSSL */
+#endif   /* USE_SSL */
+
+#ifdef ENABLE_GSS
+	gss_ctx_id_t gctx;			/* GSS context */
+	gss_name_t	gtarg_nam;		/* GSS target name */
+	gss_buffer_desc ginbuf;		/* GSS input token */
+	gss_buffer_desc goutbuf;	/* GSS output token */
+#endif
+
+#ifdef ENABLE_SSPI
+#ifndef ENABLE_GSS
+	gss_buffer_desc ginbuf;		/* GSS input token */
+#else
+	char	   *gsslib;			/* What GSS librart to use ("gssapi" or
+								 * "sspi") */
+#endif
+	CredHandle *sspicred;		/* SSPI credentials handle */
+	CtxtHandle *sspictx;		/* SSPI context */
+	char	   *sspitarget;		/* SSPI target name */
+	int			usesspi;		/* Indicate if SSPI is in use on the
+								 * connection */
+#endif
+
+	/* Buffer for current error message */
+	PQExpBufferData errorMessage;		/* expansible string */
+
+	/* Buffer for receiving various parts of messages */
+	PQExpBufferData workBuffer; /* expansible string */
+};
+
+/* PGcancel stores all data necessary to cancel a connection. A copy of this
+ * data is required to safely cancel a connection running on a different
+ * thread.
+ */
+struct pg_cancel
+{
+	SockAddr	raddr;			/* Remote address */
+	int			be_pid;			/* PID of backend --- needed for cancels */
+	int			be_key;			/* key of backend --- needed for cancels */
+};
+
+
+/* String descriptions of the ExecStatusTypes.
+ * direct use of this array is deprecated; call PQresStatus() instead.
+ */
+extern char *const pgresStatus[];
+
+
+#ifdef USE_SSL
+
+#ifndef WIN32
+#define USER_CERT_FILE		".postgresql/postgresql.crt"
+#define USER_KEY_FILE		".postgresql/postgresql.key"
+#define ROOT_CERT_FILE		".postgresql/root.crt"
+#define ROOT_CRL_FILE		".postgresql/root.crl"
+#else
+/* On Windows, the "home" directory is already PostgreSQL-specific */
+#define USER_CERT_FILE		"postgresql.crt"
+#define USER_KEY_FILE		"postgresql.key"
+#define ROOT_CERT_FILE		"root.crt"
+#define ROOT_CRL_FILE		"root.crl"
+#endif
+
+#endif   /* USE_SSL */
+
+/* ----------------
+ * Internal functions of libpq
+ * Functions declared here need to be visible across files of libpq,
+ * but are not intended to be called by applications.  We use the
+ * convention "pqXXX" for internal functions, vs. the "PQxxx" names
+ * used for application-visible routines.
+ * ----------------
+ */
+
+/* === in fe-connect.c === */
+
+extern void pqDropConnection(PGconn *conn, bool flushInput);
+extern int pqPacketSend(PGconn *conn, char pack_type,
+			 const void *buf, size_t buf_len);
+extern bool pqGetHomeDirectory(char *buf, int bufsize);
+
+#ifdef ENABLE_THREAD_SAFETY
+extern pgthreadlock_t pg_g_threadlock;
+
+#define PGTHREAD_ERROR(msg) \
+	do { \
+		fprintf(stderr, "%s\n", msg); \
+		abort(); \
+	} while (0)
+
+
+#define pglock_thread()		pg_g_threadlock(true)
+#define pgunlock_thread()	pg_g_threadlock(false)
+#else
+#define pglock_thread()		((void) 0)
+#define pgunlock_thread()	((void) 0)
+#endif
+
+/* === in fe-exec.c === */
+
+extern void pqSetResultError(PGresult *res, const char *msg);
+extern void pqCatenateResultError(PGresult *res, const char *msg);
+extern void *pqResultAlloc(PGresult *res, size_t nBytes, bool isBinary);
+extern char *pqResultStrdup(PGresult *res, const char *str);
+extern void pqClearAsyncResult(PGconn *conn);
+extern void pqSaveErrorResult(PGconn *conn);
+extern PGresult *pqPrepareAsyncResult(PGconn *conn);
+extern void pqInternalNotice(const PGNoticeHooks *hooks, const char *fmt,...) pg_attribute_printf(2, 3);
+extern void pqSaveMessageField(PGresult *res, char code,
+				   const char *value);
+extern void pqSaveParameterStatus(PGconn *conn, const char *name,
+					  const char *value);
+extern int	pqRowProcessor(PGconn *conn, const char **errmsgp);
+extern void pqHandleSendFailure(PGconn *conn);
+
+/* === in fe-protocol2.c === */
+
+extern PostgresPollingStatusType pqSetenvPoll(PGconn *conn);
+
+extern char *pqBuildStartupPacket2(PGconn *conn, int *packetlen,
+					  const PQEnvironmentOption *options);
+extern void pqParseInput2(PGconn *conn);
+extern int	pqGetCopyData2(PGconn *conn, char **buffer, int async);
+extern int	pqGetline2(PGconn *conn, char *s, int maxlen);
+extern int	pqGetlineAsync2(PGconn *conn, char *buffer, int bufsize);
+extern int	pqEndcopy2(PGconn *conn);
+extern PGresult *pqFunctionCall2(PGconn *conn, Oid fnid,
+				int *result_buf, int *actual_result_len,
+				int result_is_int,
+				const PQArgBlock *args, int nargs);
+
+/* === in fe-protocol3.c === */
+
+extern char *pqBuildStartupPacket3(PGconn *conn, int *packetlen,
+					  const PQEnvironmentOption *options);
+extern void pqParseInput3(PGconn *conn);
+extern int	pqGetErrorNotice3(PGconn *conn, bool isError);
+extern void pqBuildErrorMessage3(PQExpBuffer msg, const PGresult *res,
+					 PGVerbosity verbosity, PGContextVisibility show_context);
+extern int	pqGetCopyData3(PGconn *conn, char **buffer, int async);
+extern int	pqGetline3(PGconn *conn, char *s, int maxlen);
+extern int	pqGetlineAsync3(PGconn *conn, char *buffer, int bufsize);
+extern int	pqEndcopy3(PGconn *conn);
+extern PGresult *pqFunctionCall3(PGconn *conn, Oid fnid,
+				int *result_buf, int *actual_result_len,
+				int result_is_int,
+				const PQArgBlock *args, int nargs);
+
+/* === in fe-misc.c === */
+
+ /*
+  * "Get" and "Put" routines return 0 if successful, EOF if not. Note that for
+  * Get, EOF merely means the buffer is exhausted, not that there is
+  * necessarily any error.
+  */
+extern int	pqCheckOutBufferSpace(size_t bytes_needed, PGconn *conn);
+extern int	pqCheckInBufferSpace(size_t bytes_needed, PGconn *conn);
+extern int	pqGetc(char *result, PGconn *conn);
+extern int	pqPutc(char c, PGconn *conn);
+extern int	pqGets(PQExpBuffer buf, PGconn *conn);
+extern int	pqGets_append(PQExpBuffer buf, PGconn *conn);
+extern int	pqPuts(const char *s, PGconn *conn);
+extern int	pqGetnchar(char *s, size_t len, PGconn *conn);
+extern int	pqSkipnchar(size_t len, PGconn *conn);
+extern int	pqPutnchar(const char *s, size_t len, PGconn *conn);
+extern int	pqGetInt(int *result, size_t bytes, PGconn *conn);
+extern int	pqPutInt(int value, size_t bytes, PGconn *conn);
+extern int	pqPutMsgStart(char msg_type, bool force_len, PGconn *conn);
+extern int	pqPutMsgEnd(PGconn *conn);
+extern int	pqReadData(PGconn *conn);
+extern int	pqFlush(PGconn *conn);
+extern int	pqWait(int forRead, int forWrite, PGconn *conn);
+extern int pqWaitTimed(int forRead, int forWrite, PGconn *conn,
+			time_t finish_time);
+extern int	pqReadReady(PGconn *conn);
+extern int	pqWriteReady(PGconn *conn);
+
+/* === in fe-secure.c === */
+
+extern int	pqsecure_initialize(PGconn *);
+extern void pqsecure_destroy(void);
+extern PostgresPollingStatusType pqsecure_open_client(PGconn *);
+extern void pqsecure_close(PGconn *);
+extern ssize_t pqsecure_read(PGconn *, void *ptr, size_t len);
+extern ssize_t pqsecure_write(PGconn *, const void *ptr, size_t len);
+extern ssize_t pqsecure_raw_read(PGconn *, void *ptr, size_t len);
+extern ssize_t pqsecure_raw_write(PGconn *, const void *ptr, size_t len);
+
+#if defined(ENABLE_THREAD_SAFETY) && !defined(WIN32)
+extern int	pq_block_sigpipe(sigset_t *osigset, bool *sigpipe_pending);
+extern void pq_reset_sigpipe(sigset_t *osigset, bool sigpipe_pending,
+				 bool got_epipe);
+#endif
+
+/*
+ * The SSL implementation provides these functions (fe-secure-openssl.c)
+ */
+extern void pgtls_init_library(bool do_ssl, int do_crypto);
+extern int	pgtls_init(PGconn *conn);
+extern PostgresPollingStatusType pgtls_open_client(PGconn *conn);
+extern void pgtls_close(PGconn *conn);
+extern ssize_t pgtls_read(PGconn *conn, void *ptr, size_t len);
+extern bool pgtls_read_pending(PGconn *conn);
+extern ssize_t pgtls_write(PGconn *conn, const void *ptr, size_t len);
+
+/*
+ * this is so that we can check if a connection is non-blocking internally
+ * without the overhead of a function call
+ */
+#define pqIsnonblocking(conn)	((conn)->nonblocking)
+
+#ifdef ENABLE_NLS
+extern char *libpq_gettext(const char *msgid) pg_attribute_format_arg(1);
+extern char *libpq_ngettext(const char *msgid, const char *msgid_plural, unsigned long n) pg_attribute_format_arg(1) pg_attribute_format_arg(2);
+#else
+#define libpq_gettext(x) (x)
+#define libpq_ngettext(s, p, n) ((n) == 1 ? (s) : (p))
+#endif
+
+/*
+ * These macros are needed to let error-handling code be portable between
+ * Unix and Windows.  (ugh)
+ */
+#ifdef WIN32
+#define SOCK_ERRNO (WSAGetLastError())
+#define SOCK_STRERROR winsock_strerror
+#define SOCK_ERRNO_SET(e) WSASetLastError(e)
+#else
+#define SOCK_ERRNO errno
+#define SOCK_STRERROR pqStrerror
+#define SOCK_ERRNO_SET(e) (errno = (e))
+#endif
+
+#endif   /* LIBPQ_INT_H */

+ 206 - 0
libpq_test/include/internal/libpq/pqcomm.h

@@ -0,0 +1,206 @@
+/*-------------------------------------------------------------------------
+ *
+ * pqcomm.h
+ *		Definitions common to frontends and backends.
+ *
+ * NOTE: for historical reasons, this does not correspond to pqcomm.c.
+ * pqcomm.c's routines are declared in libpq.h.
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/libpq/pqcomm.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PQCOMM_H
+#define PQCOMM_H
+
+#include <sys/socket.h>
+#include <netdb.h>
+#ifdef HAVE_SYS_UN_H
+#include <sys/un.h>
+#endif
+#include <netinet/in.h>
+
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE
+
+#ifndef HAVE_STRUCT_SOCKADDR_STORAGE_SS_FAMILY
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_FAMILY
+#define ss_family __ss_family
+#else
+#error struct sockaddr_storage does not provide an ss_family member
+#endif
+#endif
+
+#ifdef HAVE_STRUCT_SOCKADDR_STORAGE___SS_LEN
+#define ss_len __ss_len
+#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
+#endif
+#else							/* !HAVE_STRUCT_SOCKADDR_STORAGE */
+
+/* Define a struct sockaddr_storage if we don't have one. */
+
+struct sockaddr_storage
+{
+	union
+	{
+		struct sockaddr sa;		/* get the system-dependent fields */
+		int64		ss_align;	/* ensures struct is properly aligned */
+		char		ss_pad[128];	/* ensures struct has desired size */
+	}			ss_stuff;
+};
+
+#define ss_family	ss_stuff.sa.sa_family
+/* It should have an ss_len field if sockaddr has sa_len. */
+#ifdef HAVE_STRUCT_SOCKADDR_SA_LEN
+#define ss_len		ss_stuff.sa.sa_len
+#define HAVE_STRUCT_SOCKADDR_STORAGE_SS_LEN 1
+#endif
+#endif   /* HAVE_STRUCT_SOCKADDR_STORAGE */
+
+typedef struct
+{
+	struct sockaddr_storage addr;
+	ACCEPT_TYPE_ARG3 salen;
+} SockAddr;
+
+/* Configure the UNIX socket location for the well known port. */
+
+#define UNIXSOCK_PATH(path, port, sockdir) \
+		snprintf(path, sizeof(path), "%s/.s.PGSQL.%d", \
+				((sockdir) && *(sockdir) != '\0') ? (sockdir) : \
+				DEFAULT_PGSOCKET_DIR, \
+				(port))
+
+/*
+ * The maximum workable length of a socket path is what will fit into
+ * struct sockaddr_un.  This is usually only 100 or so bytes :-(.
+ *
+ * For consistency, always pass a MAXPGPATH-sized buffer to UNIXSOCK_PATH(),
+ * then complain if the resulting string is >= UNIXSOCK_PATH_BUFLEN bytes.
+ * (Because the standard API for getaddrinfo doesn't allow it to complain in
+ * a useful way when the socket pathname is too long, we have to test for
+ * this explicitly, instead of just letting the subroutine return an error.)
+ */
+#define UNIXSOCK_PATH_BUFLEN sizeof(((struct sockaddr_un *) NULL)->sun_path)
+
+
+/*
+ * These manipulate the frontend/backend protocol version number.
+ *
+ * The major number should be incremented for incompatible changes.  The minor
+ * number should be incremented for compatible changes (eg. additional
+ * functionality).
+ *
+ * If a backend supports version m.n of the protocol it must actually support
+ * versions m.[0..n].  Backend support for version m-1 can be dropped after a
+ * `reasonable' length of time.
+ *
+ * A frontend isn't required to support anything other than the current
+ * version.
+ */
+
+#define PG_PROTOCOL_MAJOR(v)	((v) >> 16)
+#define PG_PROTOCOL_MINOR(v)	((v) & 0x0000ffff)
+#define PG_PROTOCOL(m,n)	(((m) << 16) | (n))
+
+/* The earliest and latest frontend/backend protocol version supported. */
+
+#define PG_PROTOCOL_EARLIEST	PG_PROTOCOL(1,0)
+#define PG_PROTOCOL_LATEST		PG_PROTOCOL(3,0)
+
+typedef uint32 ProtocolVersion; /* FE/BE protocol version number */
+
+typedef ProtocolVersion MsgType;
+
+
+/*
+ * Packet lengths are 4 bytes in network byte order.
+ *
+ * The initial length is omitted from the packet layouts appearing below.
+ */
+
+typedef uint32 PacketLen;
+
+
+/*
+ * Old-style startup packet layout with fixed-width fields.  This is used in
+ * protocol 1.0 and 2.0, but not in later versions.  Note that the fields
+ * in this layout are '\0' terminated only if there is room.
+ */
+
+#define SM_DATABASE		64
+#define SM_USER			32
+/* We append database name if db_user_namespace true. */
+#define SM_DATABASE_USER (SM_DATABASE+SM_USER+1)		/* +1 for @ */
+#define SM_OPTIONS		64
+#define SM_UNUSED		64
+#define SM_TTY			64
+
+typedef struct StartupPacket
+{
+	ProtocolVersion protoVersion;		/* Protocol version */
+	char		database[SM_DATABASE];	/* Database name */
+	/* Db_user_namespace appends dbname */
+	char		user[SM_USER];	/* User name */
+	char		options[SM_OPTIONS];	/* Optional additional args */
+	char		unused[SM_UNUSED];		/* Unused */
+	char		tty[SM_TTY];	/* Tty for debug output */
+} StartupPacket;
+
+extern bool Db_user_namespace;
+
+/*
+ * In protocol 3.0 and later, the startup packet length is not fixed, but
+ * we set an arbitrary limit on it anyway.  This is just to prevent simple
+ * denial-of-service attacks via sending enough data to run the server
+ * out of memory.
+ */
+#define MAX_STARTUP_PACKET_LENGTH 10000
+
+
+/* These are the authentication request codes sent by the backend. */
+
+#define AUTH_REQ_OK			0	/* User is authenticated  */
+#define AUTH_REQ_KRB4		1	/* Kerberos V4. Not supported any more. */
+#define AUTH_REQ_KRB5		2	/* Kerberos V5. Not supported any more. */
+#define AUTH_REQ_PASSWORD	3	/* Password */
+#define AUTH_REQ_CRYPT		4	/* crypt password. Not supported any more. */
+#define AUTH_REQ_MD5		5	/* md5 password */
+#define AUTH_REQ_SCM_CREDS	6	/* transfer SCM credentials */
+#define AUTH_REQ_GSS		7	/* GSSAPI without wrap() */
+#define AUTH_REQ_GSS_CONT	8	/* Continue GSS exchanges */
+#define AUTH_REQ_SSPI		9	/* SSPI negotiate without wrap() */
+#define AUTH_REQ_SASL	   10	/* SASL authentication. Not supported before
+								 * libpq version 10. */
+
+typedef uint32 AuthRequest;
+
+
+/*
+ * A client can also send a cancel-current-operation request to the postmaster.
+ * This is uglier than sending it directly to the client's backend, but it
+ * avoids depending on out-of-band communication facilities.
+ *
+ * The cancel request code must not match any protocol version number
+ * we're ever likely to use.  This random choice should do.
+ */
+#define CANCEL_REQUEST_CODE PG_PROTOCOL(1234,5678)
+
+typedef struct CancelRequestPacket
+{
+	/* Note that each field is stored in network byte order! */
+	MsgType		cancelRequestCode;		/* code to identify a cancel request */
+	uint32		backendPID;		/* PID of client's backend */
+	uint32		cancelAuthCode; /* secret key to authorize cancel */
+} CancelRequestPacket;
+
+
+/*
+ * A client can also start by sending a SSL negotiation request, to get a
+ * secure channel.
+ */
+#define NEGOTIATE_SSL_CODE PG_PROTOCOL(1234,5679)
+
+#endif   /* PQCOMM_H */

+ 477 - 0
libpq_test/include/internal/port.h

@@ -0,0 +1,477 @@
+/*-------------------------------------------------------------------------
+ *
+ * port.h
+ *	  Header for src/port/ compatibility functions.
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/port.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PG_PORT_H
+#define PG_PORT_H
+
+#include <ctype.h>
+#include <netdb.h>
+#include <pwd.h>
+
+/* socket has a different definition on WIN32 */
+#ifndef WIN32
+typedef int pgsocket;
+
+#define PGINVALID_SOCKET (-1)
+#else
+typedef SOCKET pgsocket;
+
+#define PGINVALID_SOCKET INVALID_SOCKET
+#endif
+
+/* non-blocking */
+extern bool pg_set_noblock(pgsocket sock);
+extern bool pg_set_block(pgsocket sock);
+
+/* Portable path handling for Unix/Win32 (in path.c) */
+
+extern bool has_drive_prefix(const char *filename);
+extern char *first_dir_separator(const char *filename);
+extern char *last_dir_separator(const char *filename);
+extern char *first_path_var_separator(const char *pathlist);
+extern void join_path_components(char *ret_path,
+					 const char *head, const char *tail);
+extern void canonicalize_path(char *path);
+extern void make_native_path(char *path);
+extern void cleanup_path(char *path);
+extern bool path_contains_parent_reference(const char *path);
+extern bool path_is_relative_and_below_cwd(const char *path);
+extern bool path_is_prefix_of_path(const char *path1, const char *path2);
+extern char *make_absolute_path(const char *path);
+extern const char *get_progname(const char *argv0);
+extern void get_share_path(const char *my_exec_path, char *ret_path);
+extern void get_etc_path(const char *my_exec_path, char *ret_path);
+extern void get_include_path(const char *my_exec_path, char *ret_path);
+extern void get_pkginclude_path(const char *my_exec_path, char *ret_path);
+extern void get_includeserver_path(const char *my_exec_path, char *ret_path);
+extern void get_lib_path(const char *my_exec_path, char *ret_path);
+extern void get_pkglib_path(const char *my_exec_path, char *ret_path);
+extern void get_locale_path(const char *my_exec_path, char *ret_path);
+extern void get_doc_path(const char *my_exec_path, char *ret_path);
+extern void get_html_path(const char *my_exec_path, char *ret_path);
+extern void get_man_path(const char *my_exec_path, char *ret_path);
+extern bool get_home_path(char *ret_path);
+extern void get_parent_directory(char *path);
+
+/* common/pgfnames.c */
+extern char **pgfnames(const char *path);
+extern void pgfnames_cleanup(char **filenames);
+
+/*
+ *	is_absolute_path
+ *
+ *	By making this a macro we avoid needing to include path.c in libpq.
+ */
+#ifndef WIN32
+#define IS_DIR_SEP(ch)	((ch) == '/')
+
+#define is_absolute_path(filename) \
+( \
+	IS_DIR_SEP((filename)[0]) \
+)
+#else
+#define IS_DIR_SEP(ch)	((ch) == '/' || (ch) == '\\')
+
+/* See path_is_relative_and_below_cwd() for how we handle 'E:abc'. */
+#define is_absolute_path(filename) \
+( \
+	IS_DIR_SEP((filename)[0]) || \
+	(isalpha((unsigned char) ((filename)[0])) && (filename)[1] == ':' && \
+	 IS_DIR_SEP((filename)[2])) \
+)
+#endif
+
+/* Portable locale initialization (in exec.c) */
+extern void set_pglocale_pgservice(const char *argv0, const char *app);
+
+/* Portable way to find binaries (in exec.c) */
+extern int	find_my_exec(const char *argv0, char *retpath);
+extern int find_other_exec(const char *argv0, const char *target,
+				const char *versionstr, char *retpath);
+
+/* Windows security token manipulation (in exec.c) */
+#ifdef WIN32
+extern BOOL AddUserToTokenDacl(HANDLE hToken);
+#endif
+
+
+#if defined(WIN32) || defined(__CYGWIN__)
+#define EXE ".exe"
+#else
+#define EXE ""
+#endif
+
+#if defined(WIN32) && !defined(__CYGWIN__)
+#define DEVNULL "nul"
+#else
+#define DEVNULL "/dev/null"
+#endif
+
+/* Portable delay handling */
+extern void pg_usleep(long microsec);
+
+/* Portable SQL-like case-independent comparisons and conversions */
+extern int	pg_strcasecmp(const char *s1, const char *s2);
+extern int	pg_strncasecmp(const char *s1, const char *s2, size_t n);
+extern unsigned char pg_toupper(unsigned char ch);
+extern unsigned char pg_tolower(unsigned char ch);
+extern unsigned char pg_ascii_toupper(unsigned char ch);
+extern unsigned char pg_ascii_tolower(unsigned char ch);
+
+#ifdef USE_REPL_SNPRINTF
+
+/*
+ * Versions of libintl >= 0.13 try to replace printf() and friends with
+ * macros to their own versions that understand the %$ format.  We do the
+ * same, so disable their macros, if they exist.
+ */
+#ifdef vsnprintf
+#undef vsnprintf
+#endif
+#ifdef snprintf
+#undef snprintf
+#endif
+#ifdef sprintf
+#undef sprintf
+#endif
+#ifdef vfprintf
+#undef vfprintf
+#endif
+#ifdef fprintf
+#undef fprintf
+#endif
+#ifdef printf
+#undef printf
+#endif
+
+extern int	pg_vsnprintf(char *str, size_t count, const char *fmt, va_list args);
+extern int	pg_snprintf(char *str, size_t count, const char *fmt,...) pg_attribute_printf(3, 4);
+extern int	pg_sprintf(char *str, const char *fmt,...) pg_attribute_printf(2, 3);
+extern int	pg_vfprintf(FILE *stream, const char *fmt, va_list args);
+extern int	pg_fprintf(FILE *stream, const char *fmt,...) pg_attribute_printf(2, 3);
+extern int	pg_printf(const char *fmt,...) pg_attribute_printf(1, 2);
+
+/*
+ *	The GCC-specific code below prevents the pg_attribute_printf above from
+ *	being replaced, and this is required because gcc doesn't know anything
+ *	about pg_printf.
+ */
+#ifdef __GNUC__
+#define vsnprintf(...)	pg_vsnprintf(__VA_ARGS__)
+#define snprintf(...)	pg_snprintf(__VA_ARGS__)
+#define sprintf(...)	pg_sprintf(__VA_ARGS__)
+#define vfprintf(...)	pg_vfprintf(__VA_ARGS__)
+#define fprintf(...)	pg_fprintf(__VA_ARGS__)
+#define printf(...)		pg_printf(__VA_ARGS__)
+#else
+#define vsnprintf		pg_vsnprintf
+#define snprintf		pg_snprintf
+#define sprintf			pg_sprintf
+#define vfprintf		pg_vfprintf
+#define fprintf			pg_fprintf
+#define printf			pg_printf
+#endif
+#endif   /* USE_REPL_SNPRINTF */
+
+#if defined(WIN32)
+/*
+ * Versions of libintl >= 0.18? try to replace setlocale() with a macro
+ * to their own versions.  Remove the macro, if it exists, because it
+ * ends up calling the wrong version when the backend and libintl use
+ * different versions of msvcrt.
+ */
+#if defined(setlocale)
+#undef setlocale
+#endif
+
+/*
+ * Define our own wrapper macro around setlocale() to work around bugs in
+ * Windows' native setlocale() function.
+ */
+extern char *pgwin32_setlocale(int category, const char *locale);
+
+#define setlocale(a,b) pgwin32_setlocale(a,b)
+#endif   /* WIN32 */
+
+/* Portable prompt handling */
+extern char *simple_prompt(const char *prompt, int maxlen, bool echo);
+
+#ifdef WIN32
+#define PG_SIGNAL_COUNT 32
+#define kill(pid,sig)	pgkill(pid,sig)
+extern int	pgkill(int pid, int sig);
+#endif
+
+extern int	pclose_check(FILE *stream);
+
+/* Global variable holding time zone information. */
+#if defined(WIN32) || defined(__CYGWIN__)
+#define TIMEZONE_GLOBAL _timezone
+#define TZNAME_GLOBAL _tzname
+#else
+#define TIMEZONE_GLOBAL timezone
+#define TZNAME_GLOBAL tzname
+#endif
+
+#if defined(WIN32) || defined(__CYGWIN__)
+/*
+ *	Win32 doesn't have reliable rename/unlink during concurrent access.
+ */
+extern int	pgrename(const char *from, const char *to);
+extern int	pgunlink(const char *path);
+
+/* Include this first so later includes don't see these defines */
+#ifdef WIN32_ONLY_COMPILER
+#include <io.h>
+#endif
+
+#define rename(from, to)		pgrename(from, to)
+#define unlink(path)			pgunlink(path)
+#endif   /* defined(WIN32) || defined(__CYGWIN__) */
+
+/*
+ *	Win32 also doesn't have symlinks, but we can emulate them with
+ *	junction points on newer Win32 versions.
+ *
+ *	Cygwin has its own symlinks which work on Win95/98/ME where
+ *	junction points don't, so use those instead.  We have no way of
+ *	knowing what type of system Cygwin binaries will be run on.
+ *		Note: Some CYGWIN includes might #define WIN32.
+ */
+#if defined(WIN32) && !defined(__CYGWIN__)
+extern int	pgsymlink(const char *oldpath, const char *newpath);
+extern int	pgreadlink(const char *path, char *buf, size_t size);
+extern bool pgwin32_is_junction(char *path);
+
+#define symlink(oldpath, newpath)	pgsymlink(oldpath, newpath)
+#define readlink(path, buf, size)	pgreadlink(path, buf, size)
+#endif
+
+extern bool rmtree(const char *path, bool rmtopdir);
+
+/*
+ * stat() is not guaranteed to set the st_size field on win32, so we
+ * redefine it to our own implementation that is.
+ *
+ * We must pull in sys/stat.h here so the system header definition
+ * goes in first, and we redefine that, and not the other way around.
+ *
+ * Some frontends don't need the size from stat, so if UNSAFE_STAT_OK
+ * is defined we don't bother with this.
+ */
+#if defined(WIN32) && !defined(__CYGWIN__) && !defined(UNSAFE_STAT_OK)
+#include <sys/stat.h>
+extern int	pgwin32_safestat(const char *path, struct stat * buf);
+
+#define stat(a,b) pgwin32_safestat(a,b)
+#endif
+
+#if defined(WIN32) && !defined(__CYGWIN__)
+
+/*
+ * open() and fopen() replacements to allow deletion of open files and
+ * passing of other special options.
+ */
+#define		O_DIRECT	0x80000000
+extern int	pgwin32_open(const char *, int,...);
+extern FILE *pgwin32_fopen(const char *, const char *);
+
+#ifndef FRONTEND
+#define		open(a,b,c) pgwin32_open(a,b,c)
+#define		fopen(a,b) pgwin32_fopen(a,b)
+#endif
+
+/*
+ * Mingw-w64 headers #define popen and pclose to _popen and _pclose.  We want
+ * to use our popen wrapper, rather than plain _popen, so override that.  For
+ * consistency, use our version of pclose, too.
+ */
+#ifdef popen
+#undef popen
+#endif
+#ifdef pclose
+#undef pclose
+#endif
+
+/*
+ * system() and popen() replacements to enclose the command in an extra
+ * pair of quotes.
+ */
+extern int	pgwin32_system(const char *command);
+extern FILE *pgwin32_popen(const char *command, const char *type);
+
+#define system(a) pgwin32_system(a)
+#define popen(a,b) pgwin32_popen(a,b)
+#define pclose(a) _pclose(a)
+
+/* New versions of MingW have gettimeofday, old mingw and msvc don't */
+#ifndef HAVE_GETTIMEOFDAY
+/* Last parameter not used */
+extern int	gettimeofday(struct timeval * tp, struct timezone * tzp);
+#endif
+#else							/* !WIN32 */
+
+/*
+ *	Win32 requires a special close for sockets and pipes, while on Unix
+ *	close() does them all.
+ */
+#define closesocket close
+#endif   /* WIN32 */
+
+/*
+ * On Windows, setvbuf() does not support _IOLBF mode, and interprets that
+ * as _IOFBF.  To add insult to injury, setvbuf(file, NULL, _IOFBF, 0)
+ * crashes outright if "parameter validation" is enabled.  Therefore, in
+ * places where we'd like to select line-buffered mode, we fall back to
+ * unbuffered mode instead on Windows.  Always use PG_IOLBF not _IOLBF
+ * directly in order to implement this behavior.
+ */
+#ifndef WIN32
+#define PG_IOLBF	_IOLBF
+#else
+#define PG_IOLBF	_IONBF
+#endif
+
+/*
+ * Default "extern" declarations or macro substitutes for library routines.
+ * When necessary, these routines are provided by files in src/port/.
+ */
+#ifndef HAVE_CRYPT
+extern char *crypt(const char *key, const char *setting);
+#endif
+
+/* WIN32 handled in port/win32.h */
+#ifndef WIN32
+#define pgoff_t off_t
+#ifdef __NetBSD__
+extern int	fseeko(FILE *stream, off_t offset, int whence);
+extern off_t ftello(FILE *stream);
+#endif
+#endif
+
+extern double pg_erand48(unsigned short xseed[3]);
+extern long pg_lrand48(void);
+extern void pg_srand48(long seed);
+
+#ifndef HAVE_FLS
+extern int	fls(int mask);
+#endif
+
+#ifndef HAVE_FSEEKO
+#define fseeko(a, b, c) fseek(a, b, c)
+#define ftello(a)		ftell(a)
+#endif
+
+#if !defined(HAVE_GETPEEREID) && !defined(WIN32)
+extern int	getpeereid(int sock, uid_t *uid, gid_t *gid);
+#endif
+
+#ifndef HAVE_ISINF
+extern int	isinf(double x);
+#endif
+
+#ifndef HAVE_MKDTEMP
+extern char *mkdtemp(char *path);
+#endif
+
+#ifndef HAVE_RINT
+extern double rint(double x);
+#endif
+
+#ifndef HAVE_INET_ATON
+#include <netinet/in.h>
+#include <arpa/inet.h>
+extern int	inet_aton(const char *cp, struct in_addr * addr);
+#endif
+
+#if !HAVE_DECL_STRLCAT
+extern size_t strlcat(char *dst, const char *src, size_t siz);
+#endif
+
+#if !HAVE_DECL_STRLCPY
+extern size_t strlcpy(char *dst, const char *src, size_t siz);
+#endif
+
+#if !defined(HAVE_RANDOM) && !defined(__BORLANDC__)
+extern long random(void);
+#endif
+
+#ifndef HAVE_UNSETENV
+extern void unsetenv(const char *name);
+#endif
+
+#ifndef HAVE_SRANDOM
+extern void srandom(unsigned int seed);
+#endif
+
+#ifndef HAVE_SSL_GET_CURRENT_COMPRESSION
+#define SSL_get_current_compression(x) 0
+#endif
+
+/* thread.h */
+extern char *pqStrerror(int errnum, char *strerrbuf, size_t buflen);
+
+#ifndef WIN32
+extern int pqGetpwuid(uid_t uid, struct passwd * resultbuf, char *buffer,
+		   size_t buflen, struct passwd ** result);
+#endif
+
+extern int pqGethostbyname(const char *name,
+				struct hostent * resultbuf,
+				char *buffer, size_t buflen,
+				struct hostent ** result,
+				int *herrno);
+
+extern void pg_qsort(void *base, size_t nel, size_t elsize,
+		 int (*cmp) (const void *, const void *));
+extern int	pg_qsort_strcmp(const void *a, const void *b);
+
+#define qsort(a,b,c,d) pg_qsort(a,b,c,d)
+
+typedef int (*qsort_arg_comparator) (const void *a, const void *b, void *arg);
+
+extern void qsort_arg(void *base, size_t nel, size_t elsize,
+		  qsort_arg_comparator cmp, void *arg);
+
+/* port/chklocale.c */
+extern int	pg_get_encoding_from_locale(const char *ctype, bool write_message);
+
+#if defined(WIN32) && !defined(FRONTEND)
+extern int	pg_codepage_to_encoding(UINT cp);
+#endif
+
+/* port/inet_net_ntop.c */
+extern char *inet_net_ntop(int af, const void *src, int bits,
+			  char *dst, size_t size);
+
+/* port/pgcheckdir.c */
+extern int	pg_check_dir(const char *dir);
+
+/* port/pgmkdirp.c */
+extern int	pg_mkdir_p(char *path, int omode);
+
+/* port/pqsignal.c */
+typedef void (*pqsigfunc) (int signo);
+extern pqsigfunc pqsignal(int signo, pqsigfunc func);
+#ifndef WIN32
+extern pqsigfunc pqsignal_no_restart(int signo, pqsigfunc func);
+#else
+#define pqsignal_no_restart(signo, func) pqsignal(signo, func)
+#endif
+
+/* port/quotes.c */
+extern char *escape_single_quotes_ascii(const char *src);
+
+/* port/wait_error.c */
+extern char *wait_result_to_str(int exit_status);
+
+#endif   /* PG_PORT_H */

+ 29 - 0
libpq_test/include/internal/postgres_fe.h

@@ -0,0 +1,29 @@
+/*-------------------------------------------------------------------------
+ *
+ * postgres_fe.h
+ *	  Primary include file for PostgreSQL client-side .c files
+ *
+ * This should be the first file included by PostgreSQL client libraries and
+ * application programs --- but not by backend modules, which should include
+ * postgres.h.
+ *
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1995, Regents of the University of California
+ *
+ * src/include/postgres_fe.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef POSTGRES_FE_H
+#define POSTGRES_FE_H
+
+#ifndef FRONTEND
+#define FRONTEND 1
+#endif
+
+#include "c.h"
+
+#include "common/fe_memutils.h"
+
+#endif   /* POSTGRES_FE_H */

+ 182 - 0
libpq_test/include/internal/pqexpbuffer.h

@@ -0,0 +1,182 @@
+/*-------------------------------------------------------------------------
+ *
+ * pqexpbuffer.h
+ *	  Declarations/definitions for "PQExpBuffer" functions.
+ *
+ * PQExpBuffer provides an indefinitely-extensible string data type.
+ * It can be used to buffer either ordinary C strings (null-terminated text)
+ * or arbitrary binary data.  All storage is allocated with malloc().
+ *
+ * This module is essentially the same as the backend's StringInfo data type,
+ * but it is intended for use in frontend libpq and client applications.
+ * Thus, it does not rely on palloc() nor elog().
+ *
+ * It does rely on vsnprintf(); if configure finds that libc doesn't provide
+ * a usable vsnprintf(), then a copy of our own implementation of it will
+ * be linked into libpq.
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/interfaces/libpq/pqexpbuffer.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef PQEXPBUFFER_H
+#define PQEXPBUFFER_H
+
+/*-------------------------
+ * PQExpBufferData holds information about an extensible string.
+ *		data	is the current buffer for the string (allocated with malloc).
+ *		len		is the current string length.  There is guaranteed to be
+ *				a terminating '\0' at data[len], although this is not very
+ *				useful when the string holds binary data rather than text.
+ *		maxlen	is the allocated size in bytes of 'data', i.e. the maximum
+ *				string size (including the terminating '\0' char) that we can
+ *				currently store in 'data' without having to reallocate
+ *				more space.  We must always have maxlen > len.
+ *
+ * An exception occurs if we failed to allocate enough memory for the string
+ * buffer.  In that case data points to a statically allocated empty string,
+ * and len = maxlen = 0.
+ *-------------------------
+ */
+typedef struct PQExpBufferData
+{
+	char	   *data;
+	size_t		len;
+	size_t		maxlen;
+} PQExpBufferData;
+
+typedef PQExpBufferData *PQExpBuffer;
+
+/*------------------------
+ * Test for a broken (out of memory) PQExpBuffer.
+ * When a buffer is "broken", all operations except resetting or deleting it
+ * are no-ops.
+ *------------------------
+ */
+#define PQExpBufferBroken(str)	\
+	((str) == NULL || (str)->maxlen == 0)
+
+/*------------------------
+ * Same, but for use when using a static or local PQExpBufferData struct.
+ * For that, a null-pointer test is useless and may draw compiler warnings.
+ *------------------------
+ */
+#define PQExpBufferDataBroken(buf)	\
+	((buf).maxlen == 0)
+
+/*------------------------
+ * Initial size of the data buffer in a PQExpBuffer.
+ * NB: this must be large enough to hold error messages that might
+ * be returned by PQrequestCancel().
+ *------------------------
+ */
+#define INITIAL_EXPBUFFER_SIZE	256
+
+/*------------------------
+ * There are two ways to create a PQExpBuffer object initially:
+ *
+ * PQExpBuffer stringptr = createPQExpBuffer();
+ *		Both the PQExpBufferData and the data buffer are malloc'd.
+ *
+ * PQExpBufferData string;
+ * initPQExpBuffer(&string);
+ *		The data buffer is malloc'd but the PQExpBufferData is presupplied.
+ *		This is appropriate if the PQExpBufferData is a field of another
+ *		struct.
+ *-------------------------
+ */
+
+/*------------------------
+ * createPQExpBuffer
+ * Create an empty 'PQExpBufferData' & return a pointer to it.
+ */
+extern PQExpBuffer createPQExpBuffer(void);
+
+/*------------------------
+ * initPQExpBuffer
+ * Initialize a PQExpBufferData struct (with previously undefined contents)
+ * to describe an empty string.
+ */
+extern void initPQExpBuffer(PQExpBuffer str);
+
+/*------------------------
+ * To destroy a PQExpBuffer, use either:
+ *
+ * destroyPQExpBuffer(str);
+ *		free()s both the data buffer and the PQExpBufferData.
+ *		This is the inverse of createPQExpBuffer().
+ *
+ * termPQExpBuffer(str)
+ *		free()s the data buffer but not the PQExpBufferData itself.
+ *		This is the inverse of initPQExpBuffer().
+ *
+ * NOTE: some routines build up a string using PQExpBuffer, and then
+ * release the PQExpBufferData but return the data string itself to their
+ * caller.  At that point the data string looks like a plain malloc'd
+ * string.
+ */
+extern void destroyPQExpBuffer(PQExpBuffer str);
+extern void termPQExpBuffer(PQExpBuffer str);
+
+/*------------------------
+ * resetPQExpBuffer
+ *		Reset a PQExpBuffer to empty
+ *
+ * Note: if possible, a "broken" PQExpBuffer is returned to normal.
+ */
+extern void resetPQExpBuffer(PQExpBuffer str);
+
+/*------------------------
+ * enlargePQExpBuffer
+ * Make sure there is enough space for 'needed' more bytes in the buffer
+ * ('needed' does not include the terminating null).
+ *
+ * Returns 1 if OK, 0 if failed to enlarge buffer.  (In the latter case
+ * the buffer is left in "broken" state.)
+ */
+extern int	enlargePQExpBuffer(PQExpBuffer str, size_t needed);
+
+/*------------------------
+ * printfPQExpBuffer
+ * Format text data under the control of fmt (an sprintf-like format string)
+ * and insert it into str.  More space is allocated to str if necessary.
+ * This is a convenience routine that does the same thing as
+ * resetPQExpBuffer() followed by appendPQExpBuffer().
+ */
+extern void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...) pg_attribute_printf(2, 3);
+
+/*------------------------
+ * appendPQExpBuffer
+ * Format text data under the control of fmt (an sprintf-like format string)
+ * and append it to whatever is already in str.  More space is allocated
+ * to str if necessary.  This is sort of like a combination of sprintf and
+ * strcat.
+ */
+extern void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...) pg_attribute_printf(2, 3);
+
+/*------------------------
+ * appendPQExpBufferStr
+ * Append the given string to a PQExpBuffer, allocating more space
+ * if necessary.
+ */
+extern void appendPQExpBufferStr(PQExpBuffer str, const char *data);
+
+/*------------------------
+ * appendPQExpBufferChar
+ * Append a single byte to str.
+ * Like appendPQExpBuffer(str, "%c", ch) but much faster.
+ */
+extern void appendPQExpBufferChar(PQExpBuffer str, char ch);
+
+/*------------------------
+ * appendBinaryPQExpBuffer
+ * Append arbitrary binary data to a PQExpBuffer, allocating more space
+ * if necessary.
+ */
+extern void appendBinaryPQExpBuffer(PQExpBuffer str,
+						const char *data, size_t datalen);
+
+#endif   /* PQEXPBUFFER_H */

+ 46 - 0
libpq_test/include/libcharset.h

@@ -0,0 +1,46 @@
+/* Copyright (C) 2003 Free Software Foundation, Inc.
+   This file is part of the GNU CHARSET Library.
+
+   The GNU CHARSET Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Library General Public License as
+   published by the Free Software Foundation; either version 2 of the
+   License, or (at your option) any later version.
+
+   The GNU CHARSET Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Library General Public License for more details.
+
+   You should have received a copy of the GNU Library General Public License
+   along with the GNU CHARSET Library; see the file COPYING.LIB.  If not,
+   write to the Free Software Foundation, Inc., 51 Franklin Street,
+   Fifth Floor, Boston, MA 02110-1301, USA.  */
+
+#ifndef _LIBCHARSET_H
+#define _LIBCHARSET_H
+
+#include <localcharset.h>
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Support for relocatable packages.  */
+
+/* Sets the original and the current installation prefix of the package.
+   Relocation simply replaces a pathname starting with the original prefix
+   by the corresponding pathname with the current prefix instead.  Both
+   prefixes should be directory names without trailing slash (i.e. use ""
+   instead of "/").  */
+extern void libcharset_set_relocation_prefix (const char *orig_prefix,
+                                              const char *curr_prefix);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* _LIBCHARSET_H */

+ 464 - 0
libpq_test/include/libintl.h

@@ -0,0 +1,464 @@
+/* Message catalogs for internationalization.
+   Copyright (C) 1995-1997, 2000-2012 Free Software Foundation, Inc.
+
+   This program is free software: you can redistribute it and/or modify
+   it under the terms of the GNU Lesser General Public License as published by
+   the Free Software Foundation; either version 2.1 of the License, or
+   (at your option) any later version.
+
+   This program is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+   GNU Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public License
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
+
+#ifndef _LIBINTL_H
+#define _LIBINTL_H 1
+
+#include <locale.h>
+#if (defined __APPLE__ && defined __MACH__) && 0
+# include <xlocale.h>
+#endif
+
+/* The LC_MESSAGES locale category is the category used by the functions
+   gettext() and dgettext().  It is specified in POSIX, but not in ANSI C.
+   On systems that don't define it, use an arbitrary value instead.
+   On Solaris, <locale.h> defines __LOCALE_H (or _LOCALE_H in Solaris 2.5)
+   then includes <libintl.h> (i.e. this file!) and then only defines
+   LC_MESSAGES.  To avoid a redefinition warning, don't define LC_MESSAGES
+   in this case.  */
+#if !defined LC_MESSAGES && !(defined __LOCALE_H || (defined _LOCALE_H && defined __sun))
+# define LC_MESSAGES 1729
+#endif
+
+/* We define an additional symbol to signal that we use the GNU
+   implementation of gettext.  */
+#define __USE_GNU_GETTEXT 1
+
+/* Provide information about the supported file formats.  Returns the
+   maximum minor revision number supported for a given major revision.  */
+#define __GNU_GETTEXT_SUPPORTED_REVISION(major) \
+  ((major) == 0 || (major) == 1 ? 1 : -1)
+
+/* Resolve a platform specific conflict on DJGPP.  GNU gettext takes
+   precedence over _conio_gettext.  */
+#ifdef __DJGPP__
+# undef gettext
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/* Version number: (major<<16) + (minor<<8) + subminor */
+#define LIBINTL_VERSION 0x001300
+extern int libintl_version;
+
+
+/* We redirect the functions to those prefixed with "libintl_".  This is
+   necessary, because some systems define gettext/textdomain/... in the C
+   library (namely, Solaris 2.4 and newer, and GNU libc 2.0 and newer).
+   If we used the unprefixed names, there would be cases where the
+   definition in the C library would override the one in the libintl.so
+   shared library.  Recall that on ELF systems, the symbols are looked
+   up in the following order:
+     1. in the executable,
+     2. in the shared libraries specified on the link command line, in order,
+     3. in the dependencies of the shared libraries specified on the link
+        command line,
+     4. in the dlopen()ed shared libraries, in the order in which they were
+        dlopen()ed.
+   The definition in the C library would override the one in libintl.so if
+   either
+     * -lc is given on the link command line and -lintl isn't, or
+     * -lc is given on the link command line before -lintl, or
+     * libintl.so is a dependency of a dlopen()ed shared library but not
+       linked to the executable at link time.
+   Since Solaris gettext() behaves differently than GNU gettext(), this
+   would be unacceptable.
+
+   The redirection happens by default through macros in C, so that &gettext
+   is independent of the compilation unit, but through inline functions in
+   C++, in order not to interfere with the name mangling of class fields or
+   class methods called 'gettext'.  */
+
+/* The user can define _INTL_REDIRECT_INLINE or _INTL_REDIRECT_MACROS.
+   If he doesn't, we choose the method.  A third possible method is
+   _INTL_REDIRECT_ASM, supported only by GCC.  */
+#if !(defined _INTL_REDIRECT_INLINE || defined _INTL_REDIRECT_MACROS)
+# if defined __GNUC__ && __GNUC__ >= 2 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1) && !defined __MINGW32__ && !(__GNUC__ == 2 && defined _AIX) && (defined __STDC__ || defined __cplusplus)
+#  define _INTL_REDIRECT_ASM
+# else
+#  ifdef __cplusplus
+#   define _INTL_REDIRECT_INLINE
+#  else
+#   define _INTL_REDIRECT_MACROS
+#  endif
+# endif
+#endif
+/* Auxiliary macros.  */
+#ifdef _INTL_REDIRECT_ASM
+# define _INTL_ASM(cname) __asm__ (_INTL_ASMNAME (__USER_LABEL_PREFIX__, #cname))
+# define _INTL_ASMNAME(prefix,cnamestring) _INTL_STRINGIFY (prefix) cnamestring
+# define _INTL_STRINGIFY(prefix) #prefix
+#else
+# define _INTL_ASM(cname)
+#endif
+
+/* _INTL_MAY_RETURN_STRING_ARG(n) declares that the given function may return
+   its n-th argument literally.  This enables GCC to warn for example about
+   printf (gettext ("foo %y")).  */
+#if defined __GNUC__ && __GNUC__ >= 3 && !(defined __APPLE_CC__ && __APPLE_CC__ > 1 && defined __cplusplus)
+# define _INTL_MAY_RETURN_STRING_ARG(n) __attribute__ ((__format_arg__ (n)))
+#else
+# define _INTL_MAY_RETURN_STRING_ARG(n)
+#endif
+
+/* Look up MSGID in the current default message catalog for the current
+   LC_MESSAGES locale.  If not found, returns MSGID itself (the default
+   text).  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_gettext (const char *__msgid)
+       _INTL_MAY_RETURN_STRING_ARG (1);
+static inline char *gettext (const char *__msgid)
+{
+  return libintl_gettext (__msgid);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define gettext libintl_gettext
+#endif
+extern char *gettext (const char *__msgid)
+       _INTL_ASM (libintl_gettext)
+       _INTL_MAY_RETURN_STRING_ARG (1);
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog for the current
+   LC_MESSAGES locale.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dgettext (const char *__domainname, const char *__msgid)
+       _INTL_MAY_RETURN_STRING_ARG (2);
+static inline char *dgettext (const char *__domainname, const char *__msgid)
+{
+  return libintl_dgettext (__domainname, __msgid);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dgettext libintl_dgettext
+#endif
+extern char *dgettext (const char *__domainname, const char *__msgid)
+       _INTL_ASM (libintl_dgettext)
+       _INTL_MAY_RETURN_STRING_ARG (2);
+#endif
+
+/* Look up MSGID in the DOMAINNAME message catalog for the current CATEGORY
+   locale.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dcgettext (const char *__domainname, const char *__msgid,
+                                int __category)
+       _INTL_MAY_RETURN_STRING_ARG (2);
+static inline char *dcgettext (const char *__domainname, const char *__msgid,
+                               int __category)
+{
+  return libintl_dcgettext (__domainname, __msgid, __category);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dcgettext libintl_dcgettext
+#endif
+extern char *dcgettext (const char *__domainname, const char *__msgid,
+                        int __category)
+       _INTL_ASM (libintl_dcgettext)
+       _INTL_MAY_RETURN_STRING_ARG (2);
+#endif
+
+
+/* Similar to 'gettext' but select the plural form corresponding to the
+   number N.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_ngettext (const char *__msgid1, const char *__msgid2,
+                               unsigned long int __n)
+       _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
+static inline char *ngettext (const char *__msgid1, const char *__msgid2,
+                              unsigned long int __n)
+{
+  return libintl_ngettext (__msgid1, __msgid2, __n);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define ngettext libintl_ngettext
+#endif
+extern char *ngettext (const char *__msgid1, const char *__msgid2,
+                       unsigned long int __n)
+       _INTL_ASM (libintl_ngettext)
+       _INTL_MAY_RETURN_STRING_ARG (1) _INTL_MAY_RETURN_STRING_ARG (2);
+#endif
+
+/* Similar to 'dgettext' but select the plural form corresponding to the
+   number N.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dngettext (const char *__domainname, const char *__msgid1,
+                                const char *__msgid2, unsigned long int __n)
+       _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
+static inline char *dngettext (const char *__domainname, const char *__msgid1,
+                               const char *__msgid2, unsigned long int __n)
+{
+  return libintl_dngettext (__domainname, __msgid1, __msgid2, __n);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dngettext libintl_dngettext
+#endif
+extern char *dngettext (const char *__domainname,
+                        const char *__msgid1, const char *__msgid2,
+                        unsigned long int __n)
+       _INTL_ASM (libintl_dngettext)
+       _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
+#endif
+
+/* Similar to 'dcgettext' but select the plural form corresponding to the
+   number N.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_dcngettext (const char *__domainname,
+                                 const char *__msgid1, const char *__msgid2,
+                                 unsigned long int __n, int __category)
+       _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
+static inline char *dcngettext (const char *__domainname,
+                                const char *__msgid1, const char *__msgid2,
+                                unsigned long int __n, int __category)
+{
+  return libintl_dcngettext (__domainname, __msgid1, __msgid2, __n, __category);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define dcngettext libintl_dcngettext
+#endif
+extern char *dcngettext (const char *__domainname,
+                         const char *__msgid1, const char *__msgid2,
+                         unsigned long int __n, int __category)
+       _INTL_ASM (libintl_dcngettext)
+       _INTL_MAY_RETURN_STRING_ARG (2) _INTL_MAY_RETURN_STRING_ARG (3);
+#endif
+
+
+
+/* Set the current default message catalog to DOMAINNAME.
+   If DOMAINNAME is null, return the current default.
+   If DOMAINNAME is "", reset to the default of "messages".  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_textdomain (const char *__domainname);
+static inline char *textdomain (const char *__domainname)
+{
+  return libintl_textdomain (__domainname);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define textdomain libintl_textdomain
+#endif
+extern char *textdomain (const char *__domainname)
+       _INTL_ASM (libintl_textdomain);
+#endif
+
+/* Specify that the DOMAINNAME message catalog will be found
+   in DIRNAME rather than in the system locale data base.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_bindtextdomain (const char *__domainname,
+                                     const char *__dirname);
+static inline char *bindtextdomain (const char *__domainname,
+                                    const char *__dirname)
+{
+  return libintl_bindtextdomain (__domainname, __dirname);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define bindtextdomain libintl_bindtextdomain
+#endif
+extern char *bindtextdomain (const char *__domainname, const char *__dirname)
+       _INTL_ASM (libintl_bindtextdomain);
+#endif
+
+/* Specify the character encoding in which the messages from the
+   DOMAINNAME message catalog will be returned.  */
+#ifdef _INTL_REDIRECT_INLINE
+extern char *libintl_bind_textdomain_codeset (const char *__domainname,
+                                              const char *__codeset);
+static inline char *bind_textdomain_codeset (const char *__domainname,
+                                             const char *__codeset)
+{
+  return libintl_bind_textdomain_codeset (__domainname, __codeset);
+}
+#else
+#ifdef _INTL_REDIRECT_MACROS
+# define bind_textdomain_codeset libintl_bind_textdomain_codeset
+#endif
+extern char *bind_textdomain_codeset (const char *__domainname,
+                                      const char *__codeset)
+       _INTL_ASM (libintl_bind_textdomain_codeset);
+#endif
+
+
+
+/* Support for format strings with positions in *printf(), following the
+   POSIX/XSI specification.
+   Note: These replacements for the *printf() functions are visible only
+   in source files that #include <libintl.h> or #include "gettext.h".
+   Packages that use *printf() in source files that don't refer to _()
+   or gettext() but for which the format string could be the return value
+   of _() or gettext() need to add this #include.  Oh well.  */
+
+#if !0
+
+#include <stdio.h>
+#include <stddef.h>
+
+/* Get va_list.  */
+#if (defined __STDC__ && __STDC__) || defined __cplusplus || defined _MSC_VER
+# include <stdarg.h>
+#else
+# include <varargs.h>
+#endif
+
+#if !(defined fprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef fprintf
+#define fprintf libintl_fprintf
+extern int fprintf (FILE *, const char *, ...);
+#endif
+#if !(defined vfprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef vfprintf
+#define vfprintf libintl_vfprintf
+extern int vfprintf (FILE *, const char *, va_list);
+#endif
+
+#if !(defined printf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef printf
+#if defined __NetBSD__ || defined __BEOS__ || defined __CYGWIN__ || defined __MINGW32__
+/* Don't break __attribute__((format(printf,M,N))).
+   This redefinition is only possible because the libc in NetBSD, Cygwin,
+   mingw does not have a function __printf__.
+   Alternatively, we could have done this redirection only when compiling with
+   __GNUC__, together with a symbol redirection:
+       extern int printf (const char *, ...)
+              __asm__ (#__USER_LABEL_PREFIX__ "libintl_printf");
+   But doing it now would introduce a binary incompatibility with already
+   distributed versions of libintl on these systems.  */
+# define libintl_printf __printf__
+#endif
+#define printf libintl_printf
+extern int printf (const char *, ...);
+#endif
+#if !(defined vprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef vprintf
+#define vprintf libintl_vprintf
+extern int vprintf (const char *, va_list);
+#endif
+
+#if !(defined sprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef sprintf
+#define sprintf libintl_sprintf
+extern int sprintf (char *, const char *, ...);
+#endif
+#if !(defined vsprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef vsprintf
+#define vsprintf libintl_vsprintf
+extern int vsprintf (char *, const char *, va_list);
+#endif
+
+#if 1
+
+#if !(defined snprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef snprintf
+#define snprintf libintl_snprintf
+extern int snprintf (char *, size_t, const char *, ...);
+#endif
+#if !(defined vsnprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef vsnprintf
+#define vsnprintf libintl_vsnprintf
+extern int vsnprintf (char *, size_t, const char *, va_list);
+#endif
+
+#endif
+
+#if 0
+
+#if !(defined asprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef asprintf
+#define asprintf libintl_asprintf
+extern int asprintf (char **, const char *, ...);
+#endif
+#if !(defined vasprintf && defined _GL_STDIO_H) /* don't override gnulib */
+#undef vasprintf
+#define vasprintf libintl_vasprintf
+extern int vasprintf (char **, const char *, va_list);
+#endif
+
+#endif
+
+#if 0
+
+#undef fwprintf
+#define fwprintf libintl_fwprintf
+extern int fwprintf (FILE *, const wchar_t *, ...);
+#undef vfwprintf
+#define vfwprintf libintl_vfwprintf
+extern int vfwprintf (FILE *, const wchar_t *, va_list);
+
+#undef wprintf
+#define wprintf libintl_wprintf
+extern int wprintf (const wchar_t *, ...);
+#undef vwprintf
+#define vwprintf libintl_vwprintf
+extern int vwprintf (const wchar_t *, va_list);
+
+#undef swprintf
+#define swprintf libintl_swprintf
+extern int swprintf (wchar_t *, size_t, const wchar_t *, ...);
+#undef vswprintf
+#define vswprintf libintl_vswprintf
+extern int vswprintf (wchar_t *, size_t, const wchar_t *, va_list);
+
+#endif
+
+#endif
+
+
+/* Support for the locale chosen by the user.  */
+#if (defined __APPLE__ && defined __MACH__) || defined _WIN32 || defined __WIN32__ || defined __CYGWIN__
+
+#ifndef GNULIB_defined_setlocale /* don't override gnulib */
+#undef setlocale
+#define setlocale libintl_setlocale
+extern char *setlocale (int, const char *);
+#endif
+
+#if 0
+
+#undef newlocale
+#define newlocale libintl_newlocale
+extern locale_t newlocale (int, const char *, locale_t);
+
+#endif
+
+#endif
+
+
+/* Support for relocatable packages.  */
+
+/* Sets the original and the current installation prefix of the package.
+   Relocation simply replaces a pathname starting with the original prefix
+   by the corresponding pathname with the current prefix instead.  Both
+   prefixes should be directory names without trailing slash (i.e. use ""
+   instead of "/").  */
+#define libintl_set_relocation_prefix libintl_set_relocation_prefix
+extern void
+       libintl_set_relocation_prefix (const char *orig_prefix,
+                                      const char *curr_prefix);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* libintl.h */

+ 94 - 0
libpq_test/include/libpq-events.h

@@ -0,0 +1,94 @@
+/*-------------------------------------------------------------------------
+ *
+ * libpq-events.h
+ *	  This file contains definitions that are useful to applications
+ *	  that invoke the libpq "events" API, but are not interesting to
+ *	  ordinary users of libpq.
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/interfaces/libpq/libpq-events.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifndef LIBPQ_EVENTS_H
+#define LIBPQ_EVENTS_H
+
+#include "libpq-fe.h"
+
+#ifdef __cplusplus
+extern		"C"
+{
+#endif
+
+/* Callback Event Ids */
+typedef enum
+{
+	PGEVT_REGISTER,
+	PGEVT_CONNRESET,
+	PGEVT_CONNDESTROY,
+	PGEVT_RESULTCREATE,
+	PGEVT_RESULTCOPY,
+	PGEVT_RESULTDESTROY
+} PGEventId;
+
+typedef struct
+{
+	PGconn	   *conn;
+} PGEventRegister;
+
+typedef struct
+{
+	PGconn	   *conn;
+} PGEventConnReset;
+
+typedef struct
+{
+	PGconn	   *conn;
+} PGEventConnDestroy;
+
+typedef struct
+{
+	PGconn	   *conn;
+	PGresult   *result;
+} PGEventResultCreate;
+
+typedef struct
+{
+	const PGresult *src;
+	PGresult   *dest;
+} PGEventResultCopy;
+
+typedef struct
+{
+	PGresult   *result;
+} PGEventResultDestroy;
+
+typedef int (*PGEventProc) (PGEventId evtId, void *evtInfo, void *passThrough);
+
+/* Registers an event proc with the given PGconn. */
+extern int PQregisterEventProc(PGconn *conn, PGEventProc proc,
+					const char *name, void *passThrough);
+
+/* Sets the PGconn instance data for the provided proc to data. */
+extern int	PQsetInstanceData(PGconn *conn, PGEventProc proc, void *data);
+
+/* Gets the PGconn instance data for the provided proc. */
+extern void *PQinstanceData(const PGconn *conn, PGEventProc proc);
+
+/* Sets the PGresult instance data for the provided proc to data. */
+extern int	PQresultSetInstanceData(PGresult *result, PGEventProc proc, void *data);
+
+/* Gets the PGresult instance data for the provided proc. */
+extern void *PQresultInstanceData(const PGresult *result, PGEventProc proc);
+
+/* Fires RESULTCREATE events for an application-created PGresult. */
+extern int	PQfireResultCreateEvents(PGconn *conn, PGresult *res);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /* LIBPQ_EVENTS_H */

+ 607 - 0
libpq_test/include/libpq-fe.h

@@ -0,0 +1,607 @@
+/*-------------------------------------------------------------------------
+ *
+ * libpq-fe.h
+ *	  This file contains definitions for structures and
+ *	  externs for functions used by frontend postgres applications.
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/interfaces/libpq/libpq-fe.h
+ *
+ *-------------------------------------------------------------------------
+ */
+
+#ifndef LIBPQ_FE_H
+#define LIBPQ_FE_H
+
+#ifdef __cplusplus
+extern		"C"
+{
+#endif
+
+#include <stdio.h>
+
+/*
+ * postgres_ext.h defines the backend's externally visible types,
+ * such as Oid.
+ */
+#include "postgres_ext.h"
+
+/*
+ * Option flags for PQcopyResult
+ */
+#define PG_COPYRES_ATTRS		  0x01
+#define PG_COPYRES_TUPLES		  0x02	/* Implies PG_COPYRES_ATTRS */
+#define PG_COPYRES_EVENTS		  0x04
+#define PG_COPYRES_NOTICEHOOKS	  0x08
+
+/* Application-visible enum types */
+
+/*
+ * Although it is okay to add to these lists, values which become unused
+ * should never be removed, nor should constants be redefined - that would
+ * break compatibility with existing code.
+ */
+
+typedef enum
+{
+	CONNECTION_OK,
+	CONNECTION_BAD,
+	/* Non-blocking mode only below here */
+
+	/*
+	 * The existence of these should never be relied upon - they should only
+	 * be used for user feedback or similar purposes.
+	 */
+	CONNECTION_STARTED,			/* Waiting for connection to be made.  */
+	CONNECTION_MADE,			/* Connection OK; waiting to send.     */
+	CONNECTION_AWAITING_RESPONSE,		/* Waiting for a response from the
+										 * postmaster.        */
+	CONNECTION_AUTH_OK,			/* Received authentication; waiting for
+								 * backend startup. */
+	CONNECTION_SETENV,			/* Negotiating environment. */
+	CONNECTION_SSL_STARTUP,		/* Negotiating SSL. */
+	CONNECTION_NEEDED			/* Internal state: connect() needed */
+} ConnStatusType;
+
+typedef enum
+{
+	PGRES_POLLING_FAILED = 0,
+	PGRES_POLLING_READING,		/* These two indicate that one may	  */
+	PGRES_POLLING_WRITING,		/* use select before polling again.   */
+	PGRES_POLLING_OK,
+	PGRES_POLLING_ACTIVE		/* unused; keep for awhile for backwards
+								 * compatibility */
+} PostgresPollingStatusType;
+
+typedef enum
+{
+	PGRES_EMPTY_QUERY = 0,		/* empty query string was executed */
+	PGRES_COMMAND_OK,			/* a query command that doesn't return
+								 * anything was executed properly by the
+								 * backend */
+	PGRES_TUPLES_OK,			/* a query command that returns tuples was
+								 * executed properly by the backend, PGresult
+								 * contains the result tuples */
+	PGRES_COPY_OUT,				/* Copy Out data transfer in progress */
+	PGRES_COPY_IN,				/* Copy In data transfer in progress */
+	PGRES_BAD_RESPONSE,			/* an unexpected response was recv'd from the
+								 * backend */
+	PGRES_NONFATAL_ERROR,		/* notice or warning message */
+	PGRES_FATAL_ERROR,			/* query failed */
+	PGRES_COPY_BOTH,			/* Copy In/Out data transfer in progress */
+	PGRES_SINGLE_TUPLE			/* single tuple from larger resultset */
+} ExecStatusType;
+
+typedef enum
+{
+	PQTRANS_IDLE,				/* connection idle */
+	PQTRANS_ACTIVE,				/* command in progress */
+	PQTRANS_INTRANS,			/* idle, within transaction block */
+	PQTRANS_INERROR,			/* idle, within failed transaction */
+	PQTRANS_UNKNOWN				/* cannot determine status */
+} PGTransactionStatusType;
+
+typedef enum
+{
+	PQERRORS_TERSE,				/* single-line error messages */
+	PQERRORS_DEFAULT,			/* recommended style */
+	PQERRORS_VERBOSE			/* all the facts, ma'am */
+} PGVerbosity;
+
+typedef enum
+{
+	PQSHOW_CONTEXT_NEVER,		/* never show CONTEXT field */
+	PQSHOW_CONTEXT_ERRORS,		/* show CONTEXT for errors only (default) */
+	PQSHOW_CONTEXT_ALWAYS		/* always show CONTEXT field */
+} PGContextVisibility;
+
+/*
+ * PGPing - The ordering of this enum should not be altered because the
+ * values are exposed externally via pg_isready.
+ */
+
+typedef enum
+{
+	PQPING_OK,					/* server is accepting connections */
+	PQPING_REJECT,				/* server is alive but rejecting connections */
+	PQPING_NO_RESPONSE,			/* could not establish connection */
+	PQPING_NO_ATTEMPT			/* connection not attempted (bad params) */
+} PGPing;
+
+/* PGconn encapsulates a connection to the backend.
+ * The contents of this struct are not supposed to be known to applications.
+ */
+typedef struct pg_conn PGconn;
+
+/* PGresult encapsulates the result of a query (or more precisely, of a single
+ * SQL command --- a query string given to PQsendQuery can contain multiple
+ * commands and thus return multiple PGresult objects).
+ * The contents of this struct are not supposed to be known to applications.
+ */
+typedef struct pg_result PGresult;
+
+/* PGcancel encapsulates the information needed to cancel a running
+ * query on an existing connection.
+ * The contents of this struct are not supposed to be known to applications.
+ */
+typedef struct pg_cancel PGcancel;
+
+/* PGnotify represents the occurrence of a NOTIFY message.
+ * Ideally this would be an opaque typedef, but it's so simple that it's
+ * unlikely to change.
+ * NOTE: in Postgres 6.4 and later, the be_pid is the notifying backend's,
+ * whereas in earlier versions it was always your own backend's PID.
+ */
+typedef struct pgNotify
+{
+	char	   *relname;		/* notification condition name */
+	int			be_pid;			/* process ID of notifying server process */
+	char	   *extra;			/* notification parameter */
+	/* Fields below here are private to libpq; apps should not use 'em */
+	struct pgNotify *next;		/* list link */
+} PGnotify;
+
+/* Function types for notice-handling callbacks */
+typedef void (*PQnoticeReceiver) (void *arg, const PGresult *res);
+typedef void (*PQnoticeProcessor) (void *arg, const char *message);
+
+/* Print options for PQprint() */
+typedef char pqbool;
+
+typedef struct _PQprintOpt
+{
+	pqbool		header;			/* print output field headings and row count */
+	pqbool		align;			/* fill align the fields */
+	pqbool		standard;		/* old brain dead format */
+	pqbool		html3;			/* output html tables */
+	pqbool		expanded;		/* expand tables */
+	pqbool		pager;			/* use pager for output if needed */
+	char	   *fieldSep;		/* field separator */
+	char	   *tableOpt;		/* insert to HTML <table ...> */
+	char	   *caption;		/* HTML <caption> */
+	char	  **fieldName;		/* null terminated array of replacement field
+								 * names */
+} PQprintOpt;
+
+/* ----------------
+ * Structure for the conninfo parameter definitions returned by PQconndefaults
+ * or PQconninfoParse.
+ *
+ * All fields except "val" point at static strings which must not be altered.
+ * "val" is either NULL or a malloc'd current-value string.  PQconninfoFree()
+ * will release both the val strings and the PQconninfoOption array itself.
+ * ----------------
+ */
+typedef struct _PQconninfoOption
+{
+	char	   *keyword;		/* The keyword of the option			*/
+	char	   *envvar;			/* Fallback environment variable name	*/
+	char	   *compiled;		/* Fallback compiled in default value	*/
+	char	   *val;			/* Option's current value, or NULL		 */
+	char	   *label;			/* Label for field in connect dialog	*/
+	char	   *dispchar;		/* Indicates how to display this field in a
+								 * connect dialog. Values are: "" Display
+								 * entered value as is "*" Password field -
+								 * hide value "D"  Debug option - don't show
+								 * by default */
+	int			dispsize;		/* Field size in characters for dialog	*/
+} PQconninfoOption;
+
+/* ----------------
+ * PQArgBlock -- structure for PQfn() arguments
+ * ----------------
+ */
+typedef struct
+{
+	int			len;
+	int			isint;
+	union
+	{
+		int		   *ptr;		/* can't use void (dec compiler barfs)	 */
+		int			integer;
+	}			u;
+} PQArgBlock;
+
+/* ----------------
+ * PGresAttDesc -- Data about a single attribute (column) of a query result
+ * ----------------
+ */
+typedef struct pgresAttDesc
+{
+	char	   *name;			/* column name */
+	Oid			tableid;		/* source table, if known */
+	int			columnid;		/* source column, if known */
+	int			format;			/* format code for value (text/binary) */
+	Oid			typid;			/* type id */
+	int			typlen;			/* type size */
+	int			atttypmod;		/* type-specific modifier info */
+} PGresAttDesc;
+
+/* ----------------
+ * Exported functions of libpq
+ * ----------------
+ */
+
+/* ===	in fe-connect.c === */
+
+/* make a new client connection to the backend */
+/* Asynchronous (non-blocking) */
+extern PGconn *PQconnectStart(const char *conninfo);
+extern PGconn *PQconnectStartParams(const char *const * keywords,
+					 const char *const * values, int expand_dbname);
+extern PostgresPollingStatusType PQconnectPoll(PGconn *conn);
+
+/* Synchronous (blocking) */
+extern PGconn *PQconnectdb(const char *conninfo);
+extern PGconn *PQconnectdbParams(const char *const * keywords,
+				  const char *const * values, int expand_dbname);
+extern PGconn *PQsetdbLogin(const char *pghost, const char *pgport,
+			 const char *pgoptions, const char *pgtty,
+			 const char *dbName,
+			 const char *login, const char *pwd);
+
+#define PQsetdb(M_PGHOST,M_PGPORT,M_PGOPT,M_PGTTY,M_DBNAME)  \
+	PQsetdbLogin(M_PGHOST, M_PGPORT, M_PGOPT, M_PGTTY, M_DBNAME, NULL, NULL)
+
+/* close the current connection and free the PGconn data structure */
+extern void PQfinish(PGconn *conn);
+
+/* get info about connection options known to PQconnectdb */
+extern PQconninfoOption *PQconndefaults(void);
+
+/* parse connection options in same way as PQconnectdb */
+extern PQconninfoOption *PQconninfoParse(const char *conninfo, char **errmsg);
+
+/* return the connection options used by a live connection */
+extern PQconninfoOption *PQconninfo(PGconn *conn);
+
+/* free the data structure returned by PQconndefaults() or PQconninfoParse() */
+extern void PQconninfoFree(PQconninfoOption *connOptions);
+
+/*
+ * close the current connection and restablish a new one with the same
+ * parameters
+ */
+/* Asynchronous (non-blocking) */
+extern int	PQresetStart(PGconn *conn);
+extern PostgresPollingStatusType PQresetPoll(PGconn *conn);
+
+/* Synchronous (blocking) */
+extern void PQreset(PGconn *conn);
+
+/* request a cancel structure */
+extern PGcancel *PQgetCancel(PGconn *conn);
+
+/* free a cancel structure */
+extern void PQfreeCancel(PGcancel *cancel);
+
+/* issue a cancel request */
+extern int	PQcancel(PGcancel *cancel, char *errbuf, int errbufsize);
+
+/* backwards compatible version of PQcancel; not thread-safe */
+extern int	PQrequestCancel(PGconn *conn);
+
+/* Accessor functions for PGconn objects */
+extern char *PQdb(const PGconn *conn);
+extern char *PQuser(const PGconn *conn);
+extern char *PQpass(const PGconn *conn);
+extern char *PQhost(const PGconn *conn);
+extern char *PQport(const PGconn *conn);
+extern char *PQtty(const PGconn *conn);
+extern char *PQoptions(const PGconn *conn);
+extern ConnStatusType PQstatus(const PGconn *conn);
+extern PGTransactionStatusType PQtransactionStatus(const PGconn *conn);
+extern const char *PQparameterStatus(const PGconn *conn,
+				  const char *paramName);
+extern int	PQprotocolVersion(const PGconn *conn);
+extern int	PQserverVersion(const PGconn *conn);
+extern char *PQerrorMessage(const PGconn *conn);
+extern int	PQsocket(const PGconn *conn);
+extern int	PQbackendPID(const PGconn *conn);
+extern int	PQconnectionNeedsPassword(const PGconn *conn);
+extern int	PQconnectionUsedPassword(const PGconn *conn);
+extern int	PQclientEncoding(const PGconn *conn);
+extern int	PQsetClientEncoding(PGconn *conn, const char *encoding);
+
+/* SSL information functions */
+extern int	PQsslInUse(PGconn *conn);
+extern void *PQsslStruct(PGconn *conn, const char *struct_name);
+extern const char *PQsslAttribute(PGconn *conn, const char *attribute_name);
+extern const char *const * PQsslAttributeNames(PGconn *conn);
+
+/* Get the OpenSSL structure associated with a connection. Returns NULL for
+ * unencrypted connections or if any other TLS library is in use. */
+extern void *PQgetssl(PGconn *conn);
+
+/* Tell libpq whether it needs to initialize OpenSSL */
+extern void PQinitSSL(int do_init);
+
+/* More detailed way to tell libpq whether it needs to initialize OpenSSL */
+extern void PQinitOpenSSL(int do_ssl, int do_crypto);
+
+/* Set verbosity for PQerrorMessage and PQresultErrorMessage */
+extern PGVerbosity PQsetErrorVerbosity(PGconn *conn, PGVerbosity verbosity);
+
+/* Set CONTEXT visibility for PQerrorMessage and PQresultErrorMessage */
+extern PGContextVisibility PQsetErrorContextVisibility(PGconn *conn,
+							PGContextVisibility show_context);
+
+/* Enable/disable tracing */
+extern void PQtrace(PGconn *conn, FILE *debug_port);
+extern void PQuntrace(PGconn *conn);
+
+/* Override default notice handling routines */
+extern PQnoticeReceiver PQsetNoticeReceiver(PGconn *conn,
+					PQnoticeReceiver proc,
+					void *arg);
+extern PQnoticeProcessor PQsetNoticeProcessor(PGconn *conn,
+					 PQnoticeProcessor proc,
+					 void *arg);
+
+/*
+ *	   Used to set callback that prevents concurrent access to
+ *	   non-thread safe functions that libpq needs.
+ *	   The default implementation uses a libpq internal mutex.
+ *	   Only required for multithreaded apps that use kerberos
+ *	   both within their app and for postgresql connections.
+ */
+typedef void (*pgthreadlock_t) (int acquire);
+
+extern pgthreadlock_t PQregisterThreadLock(pgthreadlock_t newhandler);
+
+/* === in fe-exec.c === */
+
+/* Simple synchronous query */
+extern PGresult *PQexec(PGconn *conn, const char *query);
+extern PGresult *PQexecParams(PGconn *conn,
+			 const char *command,
+			 int nParams,
+			 const Oid *paramTypes,
+			 const char *const * paramValues,
+			 const int *paramLengths,
+			 const int *paramFormats,
+			 int resultFormat);
+extern PGresult *PQprepare(PGconn *conn, const char *stmtName,
+		  const char *query, int nParams,
+		  const Oid *paramTypes);
+extern PGresult *PQexecPrepared(PGconn *conn,
+			   const char *stmtName,
+			   int nParams,
+			   const char *const * paramValues,
+			   const int *paramLengths,
+			   const int *paramFormats,
+			   int resultFormat);
+
+/* Interface for multiple-result or asynchronous queries */
+extern int	PQsendQuery(PGconn *conn, const char *query);
+extern int PQsendQueryParams(PGconn *conn,
+				  const char *command,
+				  int nParams,
+				  const Oid *paramTypes,
+				  const char *const * paramValues,
+				  const int *paramLengths,
+				  const int *paramFormats,
+				  int resultFormat);
+extern int PQsendPrepare(PGconn *conn, const char *stmtName,
+			  const char *query, int nParams,
+			  const Oid *paramTypes);
+extern int PQsendQueryPrepared(PGconn *conn,
+					const char *stmtName,
+					int nParams,
+					const char *const * paramValues,
+					const int *paramLengths,
+					const int *paramFormats,
+					int resultFormat);
+extern int	PQsetSingleRowMode(PGconn *conn);
+extern PGresult *PQgetResult(PGconn *conn);
+
+/* Routines for managing an asynchronous query */
+extern int	PQisBusy(PGconn *conn);
+extern int	PQconsumeInput(PGconn *conn);
+
+/* LISTEN/NOTIFY support */
+extern PGnotify *PQnotifies(PGconn *conn);
+
+/* Routines for copy in/out */
+extern int	PQputCopyData(PGconn *conn, const char *buffer, int nbytes);
+extern int	PQputCopyEnd(PGconn *conn, const char *errormsg);
+extern int	PQgetCopyData(PGconn *conn, char **buffer, int async);
+
+/* Deprecated routines for copy in/out */
+extern int	PQgetline(PGconn *conn, char *string, int length);
+extern int	PQputline(PGconn *conn, const char *string);
+extern int	PQgetlineAsync(PGconn *conn, char *buffer, int bufsize);
+extern int	PQputnbytes(PGconn *conn, const char *buffer, int nbytes);
+extern int	PQendcopy(PGconn *conn);
+
+/* Set blocking/nonblocking connection to the backend */
+extern int	PQsetnonblocking(PGconn *conn, int arg);
+extern int	PQisnonblocking(const PGconn *conn);
+extern int	PQisthreadsafe(void);
+extern PGPing PQping(const char *conninfo);
+extern PGPing PQpingParams(const char *const * keywords,
+			 const char *const * values, int expand_dbname);
+
+/* Force the write buffer to be written (or at least try) */
+extern int	PQflush(PGconn *conn);
+
+/*
+ * "Fast path" interface --- not really recommended for application
+ * use
+ */
+extern PGresult *PQfn(PGconn *conn,
+	 int fnid,
+	 int *result_buf,
+	 int *result_len,
+	 int result_is_int,
+	 const PQArgBlock *args,
+	 int nargs);
+
+/* Accessor functions for PGresult objects */
+extern ExecStatusType PQresultStatus(const PGresult *res);
+extern char *PQresStatus(ExecStatusType status);
+extern char *PQresultErrorMessage(const PGresult *res);
+extern char *PQresultVerboseErrorMessage(const PGresult *res,
+							PGVerbosity verbosity,
+							PGContextVisibility show_context);
+extern char *PQresultErrorField(const PGresult *res, int fieldcode);
+extern int	PQntuples(const PGresult *res);
+extern int	PQnfields(const PGresult *res);
+extern int	PQbinaryTuples(const PGresult *res);
+extern char *PQfname(const PGresult *res, int field_num);
+extern int	PQfnumber(const PGresult *res, const char *field_name);
+extern Oid	PQftable(const PGresult *res, int field_num);
+extern int	PQftablecol(const PGresult *res, int field_num);
+extern int	PQfformat(const PGresult *res, int field_num);
+extern Oid	PQftype(const PGresult *res, int field_num);
+extern int	PQfsize(const PGresult *res, int field_num);
+extern int	PQfmod(const PGresult *res, int field_num);
+extern char *PQcmdStatus(PGresult *res);
+extern char *PQoidStatus(const PGresult *res);	/* old and ugly */
+extern Oid	PQoidValue(const PGresult *res);	/* new and improved */
+extern char *PQcmdTuples(PGresult *res);
+extern char *PQgetvalue(const PGresult *res, int tup_num, int field_num);
+extern int	PQgetlength(const PGresult *res, int tup_num, int field_num);
+extern int	PQgetisnull(const PGresult *res, int tup_num, int field_num);
+extern int	PQnparams(const PGresult *res);
+extern Oid	PQparamtype(const PGresult *res, int param_num);
+
+/* Describe prepared statements and portals */
+extern PGresult *PQdescribePrepared(PGconn *conn, const char *stmt);
+extern PGresult *PQdescribePortal(PGconn *conn, const char *portal);
+extern int	PQsendDescribePrepared(PGconn *conn, const char *stmt);
+extern int	PQsendDescribePortal(PGconn *conn, const char *portal);
+
+/* Delete a PGresult */
+extern void PQclear(PGresult *res);
+
+/* For freeing other alloc'd results, such as PGnotify structs */
+extern void PQfreemem(void *ptr);
+
+/* Exists for backward compatibility.  bjm 2003-03-24 */
+#define PQfreeNotify(ptr) PQfreemem(ptr)
+
+/* Error when no password was given. */
+/* Note: depending on this is deprecated; use PQconnectionNeedsPassword(). */
+#define PQnoPasswordSupplied	"fe_sendauth: no password supplied\n"
+
+/* Create and manipulate PGresults */
+extern PGresult *PQmakeEmptyPGresult(PGconn *conn, ExecStatusType status);
+extern PGresult *PQcopyResult(const PGresult *src, int flags);
+extern int	PQsetResultAttrs(PGresult *res, int numAttributes, PGresAttDesc *attDescs);
+extern void *PQresultAlloc(PGresult *res, size_t nBytes);
+extern int	PQsetvalue(PGresult *res, int tup_num, int field_num, char *value, int len);
+
+/* Quoting strings before inclusion in queries. */
+extern size_t PQescapeStringConn(PGconn *conn,
+				   char *to, const char *from, size_t length,
+				   int *error);
+extern char *PQescapeLiteral(PGconn *conn, const char *str, size_t len);
+extern char *PQescapeIdentifier(PGconn *conn, const char *str, size_t len);
+extern unsigned char *PQescapeByteaConn(PGconn *conn,
+				  const unsigned char *from, size_t from_length,
+				  size_t *to_length);
+extern unsigned char *PQunescapeBytea(const unsigned char *strtext,
+				size_t *retbuflen);
+
+/* These forms are deprecated! */
+extern size_t PQescapeString(char *to, const char *from, size_t length);
+extern unsigned char *PQescapeBytea(const unsigned char *from, size_t from_length,
+			  size_t *to_length);
+
+
+
+/* === in fe-print.c === */
+
+extern void PQprint(FILE *fout,				/* output stream */
+		const PGresult *res,
+		const PQprintOpt *ps);	/* option structure */
+
+/*
+ * really old printing routines
+ */
+extern void PQdisplayTuples(const PGresult *res,
+				FILE *fp,		/* where to send the output */
+				int fillAlign,	/* pad the fields with spaces */
+				const char *fieldSep,	/* field separator */
+				int printHeader,	/* display headers? */
+				int quiet);
+
+extern void PQprintTuples(const PGresult *res,
+			  FILE *fout,		/* output stream */
+			  int printAttName, /* print attribute names */
+			  int terseOutput,	/* delimiter bars */
+			  int width);		/* width of column, if 0, use variable width */
+
+
+/* === in fe-lobj.c === */
+
+/* Large-object access routines */
+extern int	lo_open(PGconn *conn, Oid lobjId, int mode);
+extern int	lo_close(PGconn *conn, int fd);
+extern int	lo_read(PGconn *conn, int fd, char *buf, size_t len);
+extern int	lo_write(PGconn *conn, int fd, const char *buf, size_t len);
+extern int	lo_lseek(PGconn *conn, int fd, int offset, int whence);
+extern pg_int64 lo_lseek64(PGconn *conn, int fd, pg_int64 offset, int whence);
+extern Oid	lo_creat(PGconn *conn, int mode);
+extern Oid	lo_create(PGconn *conn, Oid lobjId);
+extern int	lo_tell(PGconn *conn, int fd);
+extern pg_int64 lo_tell64(PGconn *conn, int fd);
+extern int	lo_truncate(PGconn *conn, int fd, size_t len);
+extern int	lo_truncate64(PGconn *conn, int fd, pg_int64 len);
+extern int	lo_unlink(PGconn *conn, Oid lobjId);
+extern Oid	lo_import(PGconn *conn, const char *filename);
+extern Oid	lo_import_with_oid(PGconn *conn, const char *filename, Oid lobjId);
+extern int	lo_export(PGconn *conn, Oid lobjId, const char *filename);
+
+/* === in fe-misc.c === */
+
+/* Get the version of the libpq library in use */
+extern int	PQlibVersion(void);
+
+/* Determine length of multibyte encoded char at *s */
+extern int	PQmblen(const char *s, int encoding);
+
+/* Determine display length of multibyte encoded char at *s */
+extern int	PQdsplen(const char *s, int encoding);
+
+/* Get encoding id from environment variable PGCLIENTENCODING */
+extern int	PQenv2encoding(void);
+
+/* === in fe-auth.c === */
+
+extern char *PQencryptPassword(const char *passwd, const char *user);
+
+/* === in encnames.c === */
+
+extern int	pg_char_to_encoding(const char *name);
+extern const char *pg_encoding_to_char(int encoding);
+extern int	pg_valid_server_encoding_id(int encoding);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif   /* LIBPQ_FE_H */

+ 24 - 0
libpq_test/include/libpq/libpq-fs.h

@@ -0,0 +1,24 @@
+/*-------------------------------------------------------------------------
+ *
+ * libpq-fs.h
+ *	  definitions for using Inversion file system routines (ie, large objects)
+ *
+ *
+ * Portions Copyright (c) 1996-2016, PostgreSQL Global Development Group
+ * Portions Copyright (c) 1994, Regents of the University of California
+ *
+ * src/include/libpq/libpq-fs.h
+ *
+ *-------------------------------------------------------------------------
+ */
+#ifndef LIBPQ_FS_H
+#define LIBPQ_FS_H
+
+/*
+ *	Read/write mode flags for inversion (large object) calls
+ */
+
+#define INV_WRITE		0x00020000
+#define INV_READ		0x00040000
+
+#endif   /* LIBPQ_FS_H */

+ 96 - 0
libpq_test/include/libxml/DOCBparser.h

@@ -0,0 +1,96 @@
+/*
+ * Summary: old DocBook SGML parser
+ * Description: interface for a DocBook SGML non-verifying parser
+ * This code is DEPRECATED, and should not be used anymore.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __DOCB_PARSER_H__
+#define __DOCB_PARSER_H__
+#include <libxml/xmlversion.h>
+
+#ifdef LIBXML_DOCB_ENABLED
+
+#include <libxml/parser.h>
+#include <libxml/parserInternals.h>
+
+#ifndef IN_LIBXML
+#ifdef __GNUC__
+#warning "The DOCBparser module has been deprecated in libxml2-2.6.0"
+#endif
+#endif
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Most of the back-end structures from XML and SGML are shared.
+ */
+typedef xmlParserCtxt docbParserCtxt;
+typedef xmlParserCtxtPtr docbParserCtxtPtr;
+typedef xmlSAXHandler docbSAXHandler;
+typedef xmlSAXHandlerPtr docbSAXHandlerPtr;
+typedef xmlParserInput docbParserInput;
+typedef xmlParserInputPtr docbParserInputPtr;
+typedef xmlDocPtr docbDocPtr;
+
+/*
+ * There is only few public functions.
+ */
+XMLPUBFUN int XMLCALL
+		     docbEncodeEntities(unsigned char *out,
+                                        int *outlen,
+                                        const unsigned char *in,
+                                        int *inlen, int quoteChar);
+
+XMLPUBFUN docbDocPtr XMLCALL
+		     docbSAXParseDoc   (xmlChar *cur,
+                                        const char *encoding,
+                                        docbSAXHandlerPtr sax,
+                                        void *userData);
+XMLPUBFUN docbDocPtr XMLCALL
+		     docbParseDoc      (xmlChar *cur,
+                                        const char *encoding);
+XMLPUBFUN docbDocPtr XMLCALL
+		     docbSAXParseFile  (const char *filename,
+                                        const char *encoding,
+                                        docbSAXHandlerPtr sax,
+                                        void *userData);
+XMLPUBFUN docbDocPtr XMLCALL
+		     docbParseFile     (const char *filename,
+                                        const char *encoding);
+
+/**
+ * Interfaces for the Push mode.
+ */
+XMLPUBFUN void XMLCALL
+		     docbFreeParserCtxt      (docbParserCtxtPtr ctxt);
+XMLPUBFUN docbParserCtxtPtr XMLCALL
+		     docbCreatePushParserCtxt(docbSAXHandlerPtr sax,
+                                              void *user_data,
+                                              const char *chunk,
+                                              int size,
+                                              const char *filename,
+                                              xmlCharEncoding enc);
+XMLPUBFUN int XMLCALL
+		     docbParseChunk          (docbParserCtxtPtr ctxt,
+                                              const char *chunk,
+                                              int size,
+                                              int terminate);
+XMLPUBFUN docbParserCtxtPtr XMLCALL
+		     docbCreateFileParserCtxt(const char *filename,
+                                              const char *encoding);
+XMLPUBFUN int XMLCALL
+		     docbParseDocument       (docbParserCtxtPtr ctxt);
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBXML_DOCB_ENABLED */
+
+#endif /* __DOCB_PARSER_H__ */

+ 306 - 0
libpq_test/include/libxml/HTMLparser.h

@@ -0,0 +1,306 @@
+/*
+ * Summary: interface for an HTML 4.0 non-verifying parser
+ * Description: this module implements an HTML 4.0 non-verifying parser
+ *              with API compatible with the XML parser ones. It should
+ *              be able to parse "real world" HTML, even if severely
+ *              broken from a specification point of view.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __HTML_PARSER_H__
+#define __HTML_PARSER_H__
+#include <libxml/xmlversion.h>
+#include <libxml/parser.h>
+
+#ifdef LIBXML_HTML_ENABLED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Most of the back-end structures from XML and HTML are shared.
+ */
+typedef xmlParserCtxt htmlParserCtxt;
+typedef xmlParserCtxtPtr htmlParserCtxtPtr;
+typedef xmlParserNodeInfo htmlParserNodeInfo;
+typedef xmlSAXHandler htmlSAXHandler;
+typedef xmlSAXHandlerPtr htmlSAXHandlerPtr;
+typedef xmlParserInput htmlParserInput;
+typedef xmlParserInputPtr htmlParserInputPtr;
+typedef xmlDocPtr htmlDocPtr;
+typedef xmlNodePtr htmlNodePtr;
+
+/*
+ * Internal description of an HTML element, representing HTML 4.01
+ * and XHTML 1.0 (which share the same structure).
+ */
+typedef struct _htmlElemDesc htmlElemDesc;
+typedef htmlElemDesc *htmlElemDescPtr;
+struct _htmlElemDesc {
+    const char *name;	/* The tag name */
+    char startTag;      /* Whether the start tag can be implied */
+    char endTag;        /* Whether the end tag can be implied */
+    char saveEndTag;    /* Whether the end tag should be saved */
+    char empty;         /* Is this an empty element ? */
+    char depr;          /* Is this a deprecated element ? */
+    char dtd;           /* 1: only in Loose DTD, 2: only Frameset one */
+    char isinline;      /* is this a block 0 or inline 1 element */
+    const char *desc;   /* the description */
+
+/* NRK Jan.2003
+ * New fields encapsulating HTML structure
+ *
+ * Bugs:
+ *	This is a very limited representation.  It fails to tell us when
+ *	an element *requires* subelements (we only have whether they're
+ *	allowed or not), and it doesn't tell us where CDATA and PCDATA
+ *	are allowed.  Some element relationships are not fully represented:
+ *	these are flagged with the word MODIFIER
+ */
+    const char** subelts;		/* allowed sub-elements of this element */
+    const char* defaultsubelt;	/* subelement for suggested auto-repair
+					   if necessary or NULL */
+    const char** attrs_opt;		/* Optional Attributes */
+    const char** attrs_depr;		/* Additional deprecated attributes */
+    const char** attrs_req;		/* Required attributes */
+};
+
+/*
+ * Internal description of an HTML entity.
+ */
+typedef struct _htmlEntityDesc htmlEntityDesc;
+typedef htmlEntityDesc *htmlEntityDescPtr;
+struct _htmlEntityDesc {
+    unsigned int value;	/* the UNICODE value for the character */
+    const char *name;	/* The entity name */
+    const char *desc;   /* the description */
+};
+
+/*
+ * There is only few public functions.
+ */
+XMLPUBFUN const htmlElemDesc * XMLCALL
+			htmlTagLookup	(const xmlChar *tag);
+XMLPUBFUN const htmlEntityDesc * XMLCALL
+			htmlEntityLookup(const xmlChar *name);
+XMLPUBFUN const htmlEntityDesc * XMLCALL
+			htmlEntityValueLookup(unsigned int value);
+
+XMLPUBFUN int XMLCALL
+			htmlIsAutoClosed(htmlDocPtr doc,
+					 htmlNodePtr elem);
+XMLPUBFUN int XMLCALL
+			htmlAutoCloseTag(htmlDocPtr doc,
+					 const xmlChar *name,
+					 htmlNodePtr elem);
+XMLPUBFUN const htmlEntityDesc * XMLCALL
+			htmlParseEntityRef(htmlParserCtxtPtr ctxt,
+					 const xmlChar **str);
+XMLPUBFUN int XMLCALL
+			htmlParseCharRef(htmlParserCtxtPtr ctxt);
+XMLPUBFUN void XMLCALL
+			htmlParseElement(htmlParserCtxtPtr ctxt);
+
+XMLPUBFUN htmlParserCtxtPtr XMLCALL
+			htmlNewParserCtxt(void);
+
+XMLPUBFUN htmlParserCtxtPtr XMLCALL
+			htmlCreateMemoryParserCtxt(const char *buffer,
+						   int size);
+
+XMLPUBFUN int XMLCALL
+			htmlParseDocument(htmlParserCtxtPtr ctxt);
+XMLPUBFUN htmlDocPtr XMLCALL
+			htmlSAXParseDoc	(xmlChar *cur,
+					 const char *encoding,
+					 htmlSAXHandlerPtr sax,
+					 void *userData);
+XMLPUBFUN htmlDocPtr XMLCALL
+			htmlParseDoc	(xmlChar *cur,
+					 const char *encoding);
+XMLPUBFUN htmlDocPtr XMLCALL
+			htmlSAXParseFile(const char *filename,
+					 const char *encoding,
+					 htmlSAXHandlerPtr sax,
+					 void *userData);
+XMLPUBFUN htmlDocPtr XMLCALL
+			htmlParseFile	(const char *filename,
+					 const char *encoding);
+XMLPUBFUN int XMLCALL
+			UTF8ToHtml	(unsigned char *out,
+					 int *outlen,
+					 const unsigned char *in,
+					 int *inlen);
+XMLPUBFUN int XMLCALL
+			htmlEncodeEntities(unsigned char *out,
+					 int *outlen,
+					 const unsigned char *in,
+					 int *inlen, int quoteChar);
+XMLPUBFUN int XMLCALL
+			htmlIsScriptAttribute(const xmlChar *name);
+XMLPUBFUN int XMLCALL
+			htmlHandleOmittedElem(int val);
+
+#ifdef LIBXML_PUSH_ENABLED
+/**
+ * Interfaces for the Push mode.
+ */
+XMLPUBFUN htmlParserCtxtPtr XMLCALL
+			htmlCreatePushParserCtxt(htmlSAXHandlerPtr sax,
+						 void *user_data,
+						 const char *chunk,
+						 int size,
+						 const char *filename,
+						 xmlCharEncoding enc);
+XMLPUBFUN int XMLCALL
+			htmlParseChunk		(htmlParserCtxtPtr ctxt,
+						 const char *chunk,
+						 int size,
+						 int terminate);
+#endif /* LIBXML_PUSH_ENABLED */
+
+XMLPUBFUN void XMLCALL
+			htmlFreeParserCtxt	(htmlParserCtxtPtr ctxt);
+
+/*
+ * New set of simpler/more flexible APIs
+ */
+/**
+ * xmlParserOption:
+ *
+ * This is the set of XML parser options that can be passed down
+ * to the xmlReadDoc() and similar calls.
+ */
+typedef enum {
+    HTML_PARSE_RECOVER  = 1<<0, /* Relaxed parsing */
+    HTML_PARSE_NODEFDTD = 1<<2, /* do not default a doctype if not found */
+    HTML_PARSE_NOERROR	= 1<<5,	/* suppress error reports */
+    HTML_PARSE_NOWARNING= 1<<6,	/* suppress warning reports */
+    HTML_PARSE_PEDANTIC	= 1<<7,	/* pedantic error reporting */
+    HTML_PARSE_NOBLANKS	= 1<<8,	/* remove blank nodes */
+    HTML_PARSE_NONET	= 1<<11,/* Forbid network access */
+    HTML_PARSE_NOIMPLIED= 1<<13,/* Do not add implied html/body... elements */
+    HTML_PARSE_COMPACT  = 1<<16,/* compact small text nodes */
+    HTML_PARSE_IGNORE_ENC=1<<21 /* ignore internal document encoding hint */
+} htmlParserOption;
+
+XMLPUBFUN void XMLCALL
+		htmlCtxtReset		(htmlParserCtxtPtr ctxt);
+XMLPUBFUN int XMLCALL
+		htmlCtxtUseOptions	(htmlParserCtxtPtr ctxt,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlReadDoc		(const xmlChar *cur,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlReadFile		(const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlReadMemory		(const char *buffer,
+					 int size,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlReadFd		(int fd,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlReadIO		(xmlInputReadCallback ioread,
+					 xmlInputCloseCallback ioclose,
+					 void *ioctx,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlCtxtReadDoc		(xmlParserCtxtPtr ctxt,
+					 const xmlChar *cur,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlCtxtReadFile		(xmlParserCtxtPtr ctxt,
+					 const char *filename,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlCtxtReadMemory		(xmlParserCtxtPtr ctxt,
+					 const char *buffer,
+					 int size,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlCtxtReadFd		(xmlParserCtxtPtr ctxt,
+					 int fd,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlCtxtReadIO		(xmlParserCtxtPtr ctxt,
+					 xmlInputReadCallback ioread,
+					 xmlInputCloseCallback ioclose,
+					 void *ioctx,
+					 const char *URL,
+					 const char *encoding,
+					 int options);
+
+/* NRK/Jan2003: further knowledge of HTML structure
+ */
+typedef enum {
+  HTML_NA = 0 ,		/* something we don't check at all */
+  HTML_INVALID = 0x1 ,
+  HTML_DEPRECATED = 0x2 ,
+  HTML_VALID = 0x4 ,
+  HTML_REQUIRED = 0xc /* VALID bit set so ( & HTML_VALID ) is TRUE */
+} htmlStatus ;
+
+/* Using htmlElemDesc rather than name here, to emphasise the fact
+   that otherwise there's a lookup overhead
+*/
+XMLPUBFUN htmlStatus XMLCALL htmlAttrAllowed(const htmlElemDesc*, const xmlChar*, int) ;
+XMLPUBFUN int XMLCALL htmlElementAllowedHere(const htmlElemDesc*, const xmlChar*) ;
+XMLPUBFUN htmlStatus XMLCALL htmlElementStatusHere(const htmlElemDesc*, const htmlElemDesc*) ;
+XMLPUBFUN htmlStatus XMLCALL htmlNodeStatus(const htmlNodePtr, int) ;
+/**
+ * htmlDefaultSubelement:
+ * @elt: HTML element
+ *
+ * Returns the default subelement for this element
+ */
+#define htmlDefaultSubelement(elt) elt->defaultsubelt
+/**
+ * htmlElementAllowedHereDesc:
+ * @parent: HTML parent element
+ * @elt: HTML element
+ *
+ * Checks whether an HTML element description may be a
+ * direct child of the specified element.
+ *
+ * Returns 1 if allowed; 0 otherwise.
+ */
+#define htmlElementAllowedHereDesc(parent,elt) \
+	htmlElementAllowedHere((parent), (elt)->name)
+/**
+ * htmlRequiredAttrs:
+ * @elt: HTML element
+ *
+ * Returns the attributes required for the specified element.
+ */
+#define htmlRequiredAttrs(elt) (elt)->attrs_req
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBXML_HTML_ENABLED */
+#endif /* __HTML_PARSER_H__ */

+ 147 - 0
libpq_test/include/libxml/HTMLtree.h

@@ -0,0 +1,147 @@
+/*
+ * Summary: specific APIs to process HTML tree, especially serialization
+ * Description: this module implements a few function needed to process
+ *              tree in an HTML specific way.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __HTML_TREE_H__
+#define __HTML_TREE_H__
+
+#include <stdio.h>
+#include <libxml/xmlversion.h>
+#include <libxml/tree.h>
+#include <libxml/HTMLparser.h>
+
+#ifdef LIBXML_HTML_ENABLED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+/**
+ * HTML_TEXT_NODE:
+ *
+ * Macro. A text node in a HTML document is really implemented
+ * the same way as a text node in an XML document.
+ */
+#define HTML_TEXT_NODE		XML_TEXT_NODE
+/**
+ * HTML_ENTITY_REF_NODE:
+ *
+ * Macro. An entity reference in a HTML document is really implemented
+ * the same way as an entity reference in an XML document.
+ */
+#define HTML_ENTITY_REF_NODE	XML_ENTITY_REF_NODE
+/**
+ * HTML_COMMENT_NODE:
+ *
+ * Macro. A comment in a HTML document is really implemented
+ * the same way as a comment in an XML document.
+ */
+#define HTML_COMMENT_NODE	XML_COMMENT_NODE
+/**
+ * HTML_PRESERVE_NODE:
+ *
+ * Macro. A preserved node in a HTML document is really implemented
+ * the same way as a CDATA section in an XML document.
+ */
+#define HTML_PRESERVE_NODE	XML_CDATA_SECTION_NODE
+/**
+ * HTML_PI_NODE:
+ *
+ * Macro. A processing instruction in a HTML document is really implemented
+ * the same way as a processing instruction in an XML document.
+ */
+#define HTML_PI_NODE		XML_PI_NODE
+
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlNewDoc		(const xmlChar *URI,
+					 const xmlChar *ExternalID);
+XMLPUBFUN htmlDocPtr XMLCALL
+		htmlNewDocNoDtD		(const xmlChar *URI,
+					 const xmlChar *ExternalID);
+XMLPUBFUN const xmlChar * XMLCALL
+		htmlGetMetaEncoding	(htmlDocPtr doc);
+XMLPUBFUN int XMLCALL
+		htmlSetMetaEncoding	(htmlDocPtr doc,
+					 const xmlChar *encoding);
+#ifdef LIBXML_OUTPUT_ENABLED
+XMLPUBFUN void XMLCALL
+		htmlDocDumpMemory	(xmlDocPtr cur,
+					 xmlChar **mem,
+					 int *size);
+XMLPUBFUN void XMLCALL
+		htmlDocDumpMemoryFormat	(xmlDocPtr cur,
+					 xmlChar **mem,
+					 int *size,
+					 int format);
+XMLPUBFUN int XMLCALL
+		htmlDocDump		(FILE *f,
+					 xmlDocPtr cur);
+XMLPUBFUN int XMLCALL
+		htmlSaveFile		(const char *filename,
+					 xmlDocPtr cur);
+XMLPUBFUN int XMLCALL
+		htmlNodeDump		(xmlBufferPtr buf,
+					 xmlDocPtr doc,
+					 xmlNodePtr cur);
+XMLPUBFUN void XMLCALL
+		htmlNodeDumpFile	(FILE *out,
+					 xmlDocPtr doc,
+					 xmlNodePtr cur);
+XMLPUBFUN int XMLCALL
+		htmlNodeDumpFileFormat	(FILE *out,
+					 xmlDocPtr doc,
+					 xmlNodePtr cur,
+					 const char *encoding,
+					 int format);
+XMLPUBFUN int XMLCALL
+		htmlSaveFileEnc		(const char *filename,
+					 xmlDocPtr cur,
+					 const char *encoding);
+XMLPUBFUN int XMLCALL
+		htmlSaveFileFormat	(const char *filename,
+					 xmlDocPtr cur,
+					 const char *encoding,
+					 int format);
+
+XMLPUBFUN void XMLCALL
+		htmlNodeDumpFormatOutput(xmlOutputBufferPtr buf,
+					 xmlDocPtr doc,
+					 xmlNodePtr cur,
+					 const char *encoding,
+					 int format);
+XMLPUBFUN void XMLCALL
+		htmlDocContentDumpOutput(xmlOutputBufferPtr buf,
+					 xmlDocPtr cur,
+					 const char *encoding);
+XMLPUBFUN void XMLCALL
+		htmlDocContentDumpFormatOutput(xmlOutputBufferPtr buf,
+					 xmlDocPtr cur,
+					 const char *encoding,
+					 int format);
+XMLPUBFUN void XMLCALL
+		htmlNodeDumpOutput	(xmlOutputBufferPtr buf,
+					 xmlDocPtr doc,
+					 xmlNodePtr cur,
+					 const char *encoding);
+
+#endif /* LIBXML_OUTPUT_ENABLED */
+
+XMLPUBFUN int XMLCALL
+		htmlIsBooleanAttr	(const xmlChar *name);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBXML_HTML_ENABLED */
+
+#endif /* __HTML_TREE_H__ */
+

+ 173 - 0
libpq_test/include/libxml/SAX.h

@@ -0,0 +1,173 @@
+/*
+ * Summary: Old SAX version 1 handler, deprecated
+ * Description: DEPRECATED set of SAX version 1 interfaces used to
+ *              build the DOM tree.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+
+#ifndef __XML_SAX_H__
+#define __XML_SAX_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxml/xmlversion.h>
+#include <libxml/parser.h>
+#include <libxml/xlink.h>
+
+#ifdef LIBXML_LEGACY_ENABLED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+XMLPUBFUN const xmlChar * XMLCALL
+		getPublicId			(void *ctx);
+XMLPUBFUN const xmlChar * XMLCALL
+		getSystemId			(void *ctx);
+XMLPUBFUN void XMLCALL
+		setDocumentLocator		(void *ctx,
+						 xmlSAXLocatorPtr loc);
+
+XMLPUBFUN int XMLCALL
+		getLineNumber			(void *ctx);
+XMLPUBFUN int XMLCALL
+		getColumnNumber			(void *ctx);
+
+XMLPUBFUN int XMLCALL
+		isStandalone			(void *ctx);
+XMLPUBFUN int XMLCALL
+		hasInternalSubset		(void *ctx);
+XMLPUBFUN int XMLCALL
+		hasExternalSubset		(void *ctx);
+
+XMLPUBFUN void XMLCALL
+		internalSubset			(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *ExternalID,
+						 const xmlChar *SystemID);
+XMLPUBFUN void XMLCALL
+		externalSubset			(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *ExternalID,
+						 const xmlChar *SystemID);
+XMLPUBFUN xmlEntityPtr XMLCALL
+		getEntity			(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN xmlEntityPtr XMLCALL
+		getParameterEntity		(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN xmlParserInputPtr XMLCALL
+		resolveEntity			(void *ctx,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId);
+
+XMLPUBFUN void XMLCALL
+		entityDecl			(void *ctx,
+						 const xmlChar *name,
+						 int type,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId,
+						 xmlChar *content);
+XMLPUBFUN void XMLCALL
+		attributeDecl			(void *ctx,
+						 const xmlChar *elem,
+						 const xmlChar *fullname,
+						 int type,
+						 int def,
+						 const xmlChar *defaultValue,
+						 xmlEnumerationPtr tree);
+XMLPUBFUN void XMLCALL
+		elementDecl			(void *ctx,
+						 const xmlChar *name,
+						 int type,
+						 xmlElementContentPtr content);
+XMLPUBFUN void XMLCALL
+		notationDecl			(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId);
+XMLPUBFUN void XMLCALL
+		unparsedEntityDecl		(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId,
+						 const xmlChar *notationName);
+
+XMLPUBFUN void XMLCALL
+		startDocument			(void *ctx);
+XMLPUBFUN void XMLCALL
+		endDocument			(void *ctx);
+XMLPUBFUN void XMLCALL
+		attribute			(void *ctx,
+						 const xmlChar *fullname,
+						 const xmlChar *value);
+XMLPUBFUN void XMLCALL
+		startElement			(void *ctx,
+						 const xmlChar *fullname,
+						 const xmlChar **atts);
+XMLPUBFUN void XMLCALL
+		endElement			(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN void XMLCALL
+		reference			(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN void XMLCALL
+		characters			(void *ctx,
+						 const xmlChar *ch,
+						 int len);
+XMLPUBFUN void XMLCALL
+		ignorableWhitespace		(void *ctx,
+						 const xmlChar *ch,
+						 int len);
+XMLPUBFUN void XMLCALL
+		processingInstruction		(void *ctx,
+						 const xmlChar *target,
+						 const xmlChar *data);
+XMLPUBFUN void XMLCALL
+		globalNamespace			(void *ctx,
+						 const xmlChar *href,
+						 const xmlChar *prefix);
+XMLPUBFUN void XMLCALL
+		setNamespace			(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN xmlNsPtr XMLCALL
+		getNamespace			(void *ctx);
+XMLPUBFUN int XMLCALL
+		checkNamespace			(void *ctx,
+						 xmlChar *nameSpace);
+XMLPUBFUN void XMLCALL
+		namespaceDecl			(void *ctx,
+						 const xmlChar *href,
+						 const xmlChar *prefix);
+XMLPUBFUN void XMLCALL
+		comment				(void *ctx,
+						 const xmlChar *value);
+XMLPUBFUN void XMLCALL
+		cdataBlock			(void *ctx,
+						 const xmlChar *value,
+						 int len);
+
+#ifdef LIBXML_SAX1_ENABLED
+XMLPUBFUN void XMLCALL
+		initxmlDefaultSAXHandler	(xmlSAXHandlerV1 *hdlr,
+						 int warning);
+#ifdef LIBXML_HTML_ENABLED
+XMLPUBFUN void XMLCALL
+		inithtmlDefaultSAXHandler	(xmlSAXHandlerV1 *hdlr);
+#endif
+#ifdef LIBXML_DOCB_ENABLED
+XMLPUBFUN void XMLCALL
+		initdocbDefaultSAXHandler	(xmlSAXHandlerV1 *hdlr);
+#endif
+#endif /* LIBXML_SAX1_ENABLED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBXML_LEGACY_ENABLED */
+
+#endif /* __XML_SAX_H__ */

+ 178 - 0
libpq_test/include/libxml/SAX2.h

@@ -0,0 +1,178 @@
+/*
+ * Summary: SAX2 parser interface used to build the DOM tree
+ * Description: those are the default SAX2 interfaces used by
+ *              the library when building DOM tree.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+
+#ifndef __XML_SAX2_H__
+#define __XML_SAX2_H__
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <libxml/xmlversion.h>
+#include <libxml/parser.h>
+#include <libxml/xlink.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+XMLPUBFUN const xmlChar * XMLCALL
+		xmlSAX2GetPublicId		(void *ctx);
+XMLPUBFUN const xmlChar * XMLCALL
+		xmlSAX2GetSystemId		(void *ctx);
+XMLPUBFUN void XMLCALL
+		xmlSAX2SetDocumentLocator	(void *ctx,
+						 xmlSAXLocatorPtr loc);
+
+XMLPUBFUN int XMLCALL
+		xmlSAX2GetLineNumber		(void *ctx);
+XMLPUBFUN int XMLCALL
+		xmlSAX2GetColumnNumber		(void *ctx);
+
+XMLPUBFUN int XMLCALL
+		xmlSAX2IsStandalone		(void *ctx);
+XMLPUBFUN int XMLCALL
+		xmlSAX2HasInternalSubset	(void *ctx);
+XMLPUBFUN int XMLCALL
+		xmlSAX2HasExternalSubset	(void *ctx);
+
+XMLPUBFUN void XMLCALL
+		xmlSAX2InternalSubset		(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *ExternalID,
+						 const xmlChar *SystemID);
+XMLPUBFUN void XMLCALL
+		xmlSAX2ExternalSubset		(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *ExternalID,
+						 const xmlChar *SystemID);
+XMLPUBFUN xmlEntityPtr XMLCALL
+		xmlSAX2GetEntity		(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN xmlEntityPtr XMLCALL
+		xmlSAX2GetParameterEntity	(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN xmlParserInputPtr XMLCALL
+		xmlSAX2ResolveEntity		(void *ctx,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId);
+
+XMLPUBFUN void XMLCALL
+		xmlSAX2EntityDecl		(void *ctx,
+						 const xmlChar *name,
+						 int type,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId,
+						 xmlChar *content);
+XMLPUBFUN void XMLCALL
+		xmlSAX2AttributeDecl		(void *ctx,
+						 const xmlChar *elem,
+						 const xmlChar *fullname,
+						 int type,
+						 int def,
+						 const xmlChar *defaultValue,
+						 xmlEnumerationPtr tree);
+XMLPUBFUN void XMLCALL
+		xmlSAX2ElementDecl		(void *ctx,
+						 const xmlChar *name,
+						 int type,
+						 xmlElementContentPtr content);
+XMLPUBFUN void XMLCALL
+		xmlSAX2NotationDecl		(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId);
+XMLPUBFUN void XMLCALL
+		xmlSAX2UnparsedEntityDecl	(void *ctx,
+						 const xmlChar *name,
+						 const xmlChar *publicId,
+						 const xmlChar *systemId,
+						 const xmlChar *notationName);
+
+XMLPUBFUN void XMLCALL
+		xmlSAX2StartDocument		(void *ctx);
+XMLPUBFUN void XMLCALL
+		xmlSAX2EndDocument		(void *ctx);
+#if defined(LIBXML_SAX1_ENABLED) || defined(LIBXML_HTML_ENABLED) || \
+    defined(LIBXML_WRITER_ENABLED) || defined(LIBXML_DOCB_ENABLED) || \
+    defined(LIBXML_LEGACY_ENABLED)
+XMLPUBFUN void XMLCALL
+		xmlSAX2StartElement		(void *ctx,
+						 const xmlChar *fullname,
+						 const xmlChar **atts);
+XMLPUBFUN void XMLCALL
+		xmlSAX2EndElement		(void *ctx,
+						 const xmlChar *name);
+#endif /* LIBXML_SAX1_ENABLED or LIBXML_HTML_ENABLED or LIBXML_LEGACY_ENABLED */
+XMLPUBFUN void XMLCALL
+		xmlSAX2StartElementNs		(void *ctx,
+						 const xmlChar *localname,
+						 const xmlChar *prefix,
+						 const xmlChar *URI,
+						 int nb_namespaces,
+						 const xmlChar **namespaces,
+						 int nb_attributes,
+						 int nb_defaulted,
+						 const xmlChar **attributes);
+XMLPUBFUN void XMLCALL
+		xmlSAX2EndElementNs		(void *ctx,
+						 const xmlChar *localname,
+						 const xmlChar *prefix,
+						 const xmlChar *URI);
+XMLPUBFUN void XMLCALL
+		xmlSAX2Reference		(void *ctx,
+						 const xmlChar *name);
+XMLPUBFUN void XMLCALL
+		xmlSAX2Characters		(void *ctx,
+						 const xmlChar *ch,
+						 int len);
+XMLPUBFUN void XMLCALL
+		xmlSAX2IgnorableWhitespace	(void *ctx,
+						 const xmlChar *ch,
+						 int len);
+XMLPUBFUN void XMLCALL
+		xmlSAX2ProcessingInstruction	(void *ctx,
+						 const xmlChar *target,
+						 const xmlChar *data);
+XMLPUBFUN void XMLCALL
+		xmlSAX2Comment			(void *ctx,
+						 const xmlChar *value);
+XMLPUBFUN void XMLCALL
+		xmlSAX2CDataBlock		(void *ctx,
+						 const xmlChar *value,
+						 int len);
+
+#ifdef LIBXML_SAX1_ENABLED
+XMLPUBFUN int XMLCALL
+		xmlSAXDefaultVersion		(int version);
+#endif /* LIBXML_SAX1_ENABLED */
+
+XMLPUBFUN int XMLCALL
+		xmlSAXVersion			(xmlSAXHandler *hdlr,
+						 int version);
+XMLPUBFUN void XMLCALL
+		xmlSAX2InitDefaultSAXHandler    (xmlSAXHandler *hdlr,
+						 int warning);
+#ifdef LIBXML_HTML_ENABLED
+XMLPUBFUN void XMLCALL
+		xmlSAX2InitHtmlDefaultSAXHandler(xmlSAXHandler *hdlr);
+XMLPUBFUN void XMLCALL
+		htmlDefaultSAXHandlerInit	(void);
+#endif
+#ifdef LIBXML_DOCB_ENABLED
+XMLPUBFUN void XMLCALL
+		xmlSAX2InitDocbDefaultSAXHandler(xmlSAXHandler *hdlr);
+XMLPUBFUN void XMLCALL
+		docbDefaultSAXHandlerInit	(void);
+#endif
+XMLPUBFUN void XMLCALL
+		xmlDefaultSAXHandlerInit	(void);
+#ifdef __cplusplus
+}
+#endif
+#endif /* __XML_SAX2_H__ */

+ 126 - 0
libpq_test/include/libxml/c14n.h

@@ -0,0 +1,126 @@
+/*
+ * Summary: Provide Canonical XML and Exclusive XML Canonicalization
+ * Description: the c14n modules provides a
+ *
+ * "Canonical XML" implementation
+ * http://www.w3.org/TR/xml-c14n
+ *
+ * and an
+ *
+ * "Exclusive XML Canonicalization" implementation
+ * http://www.w3.org/TR/xml-exc-c14n
+
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Aleksey Sanin <aleksey@aleksey.com>
+ */
+#ifndef __XML_C14N_H__
+#define __XML_C14N_H__
+#ifdef LIBXML_C14N_ENABLED
+#ifdef LIBXML_OUTPUT_ENABLED
+
+#ifdef __cplusplus
+extern "C" {
+#endif /* __cplusplus */
+
+#include <libxml/xmlversion.h>
+#include <libxml/tree.h>
+#include <libxml/xpath.h>
+
+/*
+ * XML Canonicazation
+ * http://www.w3.org/TR/xml-c14n
+ *
+ * Exclusive XML Canonicazation
+ * http://www.w3.org/TR/xml-exc-c14n
+ *
+ * Canonical form of an XML document could be created if and only if
+ *  a) default attributes (if any) are added to all nodes
+ *  b) all character and parsed entity references are resolved
+ * In order to achive this in libxml2 the document MUST be loaded with
+ * following global setings:
+ *
+ *    xmlLoadExtDtdDefaultValue = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
+ *    xmlSubstituteEntitiesDefault(1);
+ *
+ * or corresponding parser context setting:
+ *    xmlParserCtxtPtr ctxt;
+ *
+ *    ...
+ *    ctxt->loadsubset = XML_DETECT_IDS | XML_COMPLETE_ATTRS;
+ *    ctxt->replaceEntities = 1;
+ *    ...
+ */
+
+/*
+ * xmlC14NMode:
+ *
+ * Predefined values for C14N modes
+ *
+ */
+typedef enum {
+    XML_C14N_1_0            = 0,    /* Origianal C14N 1.0 spec */
+    XML_C14N_EXCLUSIVE_1_0  = 1,    /* Exclusive C14N 1.0 spec */
+    XML_C14N_1_1            = 2     /* C14N 1.1 spec */
+} xmlC14NMode;
+
+XMLPUBFUN int XMLCALL
+		xmlC14NDocSaveTo	(xmlDocPtr doc,
+					 xmlNodeSetPtr nodes,
+					 int mode, /* a xmlC14NMode */
+					 xmlChar **inclusive_ns_prefixes,
+					 int with_comments,
+					 xmlOutputBufferPtr buf);
+
+XMLPUBFUN int XMLCALL
+		xmlC14NDocDumpMemory	(xmlDocPtr doc,
+					 xmlNodeSetPtr nodes,
+					 int mode, /* a xmlC14NMode */
+					 xmlChar **inclusive_ns_prefixes,
+					 int with_comments,
+					 xmlChar **doc_txt_ptr);
+
+XMLPUBFUN int XMLCALL
+		xmlC14NDocSave		(xmlDocPtr doc,
+					 xmlNodeSetPtr nodes,
+					 int mode, /* a xmlC14NMode */
+					 xmlChar **inclusive_ns_prefixes,
+					 int with_comments,
+					 const char* filename,
+					 int compression);
+
+
+/**
+ * This is the core C14N function
+ */
+/**
+ * xmlC14NIsVisibleCallback:
+ * @user_data: user data
+ * @node: the curent node
+ * @parent: the parent node
+ *
+ * Signature for a C14N callback on visible nodes
+ *
+ * Returns 1 if the node should be included
+ */
+typedef int (*xmlC14NIsVisibleCallback)	(void* user_data,
+					 xmlNodePtr node,
+					 xmlNodePtr parent);
+
+XMLPUBFUN int XMLCALL
+		xmlC14NExecute		(xmlDocPtr doc,
+					 xmlC14NIsVisibleCallback is_visible_callback,
+					 void* user_data,
+					 int mode, /* a xmlC14NMode */
+					 xmlChar **inclusive_ns_prefixes,
+					 int with_comments,
+					 xmlOutputBufferPtr buf);
+
+#ifdef __cplusplus
+}
+#endif /* __cplusplus */
+
+#endif /* LIBXML_OUTPUT_ENABLED */
+#endif /* LIBXML_C14N_ENABLED */
+#endif /* __XML_C14N_H__ */
+

+ 182 - 0
libpq_test/include/libxml/catalog.h

@@ -0,0 +1,182 @@
+/**
+ * Summary: interfaces to the Catalog handling system
+ * Description: the catalog module implements the support for
+ * XML Catalogs and SGML catalogs
+ *
+ * SGML Open Technical Resolution TR9401:1997.
+ * http://www.jclark.com/sp/catalog.htm
+ *
+ * XML Catalogs Working Draft 06 August 2001
+ * http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __XML_CATALOG_H__
+#define __XML_CATALOG_H__
+
+#include <stdio.h>
+
+#include <libxml/xmlversion.h>
+#include <libxml/xmlstring.h>
+#include <libxml/tree.h>
+
+#ifdef LIBXML_CATALOG_ENABLED
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/**
+ * XML_CATALOGS_NAMESPACE:
+ *
+ * The namespace for the XML Catalogs elements.
+ */
+#define XML_CATALOGS_NAMESPACE					\
+    (const xmlChar *) "urn:oasis:names:tc:entity:xmlns:xml:catalog"
+/**
+ * XML_CATALOG_PI:
+ *
+ * The specific XML Catalog Processing Instuction name.
+ */
+#define XML_CATALOG_PI						\
+    (const xmlChar *) "oasis-xml-catalog"
+
+/*
+ * The API is voluntarily limited to general cataloging.
+ */
+typedef enum {
+    XML_CATA_PREFER_NONE = 0,
+    XML_CATA_PREFER_PUBLIC = 1,
+    XML_CATA_PREFER_SYSTEM
+} xmlCatalogPrefer;
+
+typedef enum {
+    XML_CATA_ALLOW_NONE = 0,
+    XML_CATA_ALLOW_GLOBAL = 1,
+    XML_CATA_ALLOW_DOCUMENT = 2,
+    XML_CATA_ALLOW_ALL = 3
+} xmlCatalogAllow;
+
+typedef struct _xmlCatalog xmlCatalog;
+typedef xmlCatalog *xmlCatalogPtr;
+
+/*
+ * Operations on a given catalog.
+ */
+XMLPUBFUN xmlCatalogPtr XMLCALL
+		xmlNewCatalog		(int sgml);
+XMLPUBFUN xmlCatalogPtr XMLCALL
+		xmlLoadACatalog		(const char *filename);
+XMLPUBFUN xmlCatalogPtr XMLCALL
+		xmlLoadSGMLSuperCatalog	(const char *filename);
+XMLPUBFUN int XMLCALL
+		xmlConvertSGMLCatalog	(xmlCatalogPtr catal);
+XMLPUBFUN int XMLCALL
+		xmlACatalogAdd		(xmlCatalogPtr catal,
+					 const xmlChar *type,
+					 const xmlChar *orig,
+					 const xmlChar *replace);
+XMLPUBFUN int XMLCALL
+		xmlACatalogRemove	(xmlCatalogPtr catal,
+					 const xmlChar *value);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlACatalogResolve	(xmlCatalogPtr catal,
+					 const xmlChar *pubID,
+	                                 const xmlChar *sysID);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlACatalogResolveSystem(xmlCatalogPtr catal,
+					 const xmlChar *sysID);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlACatalogResolvePublic(xmlCatalogPtr catal,
+					 const xmlChar *pubID);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlACatalogResolveURI	(xmlCatalogPtr catal,
+					 const xmlChar *URI);
+#ifdef LIBXML_OUTPUT_ENABLED
+XMLPUBFUN void XMLCALL
+		xmlACatalogDump		(xmlCatalogPtr catal,
+					 FILE *out);
+#endif /* LIBXML_OUTPUT_ENABLED */
+XMLPUBFUN void XMLCALL
+		xmlFreeCatalog		(xmlCatalogPtr catal);
+XMLPUBFUN int XMLCALL
+		xmlCatalogIsEmpty	(xmlCatalogPtr catal);
+
+/*
+ * Global operations.
+ */
+XMLPUBFUN void XMLCALL
+		xmlInitializeCatalog	(void);
+XMLPUBFUN int XMLCALL
+		xmlLoadCatalog		(const char *filename);
+XMLPUBFUN void XMLCALL
+		xmlLoadCatalogs		(const char *paths);
+XMLPUBFUN void XMLCALL
+		xmlCatalogCleanup	(void);
+#ifdef LIBXML_OUTPUT_ENABLED
+XMLPUBFUN void XMLCALL
+		xmlCatalogDump		(FILE *out);
+#endif /* LIBXML_OUTPUT_ENABLED */
+XMLPUBFUN xmlChar * XMLCALL
+		xmlCatalogResolve	(const xmlChar *pubID,
+	                                 const xmlChar *sysID);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlCatalogResolveSystem	(const xmlChar *sysID);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlCatalogResolvePublic	(const xmlChar *pubID);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlCatalogResolveURI	(const xmlChar *URI);
+XMLPUBFUN int XMLCALL
+		xmlCatalogAdd		(const xmlChar *type,
+					 const xmlChar *orig,
+					 const xmlChar *replace);
+XMLPUBFUN int XMLCALL
+		xmlCatalogRemove	(const xmlChar *value);
+XMLPUBFUN xmlDocPtr XMLCALL
+		xmlParseCatalogFile	(const char *filename);
+XMLPUBFUN int XMLCALL
+		xmlCatalogConvert	(void);
+
+/*
+ * Strictly minimal interfaces for per-document catalogs used
+ * by the parser.
+ */
+XMLPUBFUN void XMLCALL
+		xmlCatalogFreeLocal	(void *catalogs);
+XMLPUBFUN void * XMLCALL
+		xmlCatalogAddLocal	(void *catalogs,
+					 const xmlChar *URL);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlCatalogLocalResolve	(void *catalogs,
+					 const xmlChar *pubID,
+	                                 const xmlChar *sysID);
+XMLPUBFUN xmlChar * XMLCALL
+		xmlCatalogLocalResolveURI(void *catalogs,
+					 const xmlChar *URI);
+/*
+ * Preference settings.
+ */
+XMLPUBFUN int XMLCALL
+		xmlCatalogSetDebug	(int level);
+XMLPUBFUN xmlCatalogPrefer XMLCALL
+		xmlCatalogSetDefaultPrefer(xmlCatalogPrefer prefer);
+XMLPUBFUN void XMLCALL
+		xmlCatalogSetDefaults	(xmlCatalogAllow allow);
+XMLPUBFUN xmlCatalogAllow XMLCALL
+		xmlCatalogGetDefaults	(void);
+
+
+/* DEPRECATED interfaces */
+XMLPUBFUN const xmlChar * XMLCALL
+		xmlCatalogGetSystem	(const xmlChar *sysID);
+XMLPUBFUN const xmlChar * XMLCALL
+		xmlCatalogGetPublic	(const xmlChar *pubID);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* LIBXML_CATALOG_ENABLED */
+#endif /* __XML_CATALOG_H__ */

+ 230 - 0
libpq_test/include/libxml/chvalid.h

@@ -0,0 +1,230 @@
+/*
+ * Summary: Unicode character range checking
+ * Description: this module exports interfaces for the character
+ *               range validation APIs
+ *
+ * This file is automatically generated from the cvs source
+ * definition files using the genChRanges.py Python script
+ *
+ * Generation date: Mon Mar 27 11:09:48 2006
+ * Sources: chvalid.def
+ * Author: William Brack <wbrack@mmm.com.hk>
+ */
+
+#ifndef __XML_CHVALID_H__
+#define __XML_CHVALID_H__
+
+#include <libxml/xmlversion.h>
+#include <libxml/xmlstring.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Define our typedefs and structures
+ *
+ */
+typedef struct _xmlChSRange xmlChSRange;
+typedef xmlChSRange *xmlChSRangePtr;
+struct _xmlChSRange {
+    unsigned short	low;
+    unsigned short	high;
+};
+
+typedef struct _xmlChLRange xmlChLRange;
+typedef xmlChLRange *xmlChLRangePtr;
+struct _xmlChLRange {
+    unsigned int	low;
+    unsigned int	high;
+};
+
+typedef struct _xmlChRangeGroup xmlChRangeGroup;
+typedef xmlChRangeGroup *xmlChRangeGroupPtr;
+struct _xmlChRangeGroup {
+    int			nbShortRange;
+    int			nbLongRange;
+    const xmlChSRange	*shortRange;	/* points to an array of ranges */
+    const xmlChLRange	*longRange;
+};
+
+/**
+ * Range checking routine
+ */
+XMLPUBFUN int XMLCALL
+		xmlCharInRange(unsigned int val, const xmlChRangeGroup *group);
+
+
+/**
+ * xmlIsBaseChar_ch:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsBaseChar_ch(c)	(((0x41 <= (c)) && ((c) <= 0x5a)) || \
+				 ((0x61 <= (c)) && ((c) <= 0x7a)) || \
+				 ((0xc0 <= (c)) && ((c) <= 0xd6)) || \
+				 ((0xd8 <= (c)) && ((c) <= 0xf6)) || \
+				  (0xf8 <= (c)))
+
+/**
+ * xmlIsBaseCharQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsBaseCharQ(c)	(((c) < 0x100) ? \
+				 xmlIsBaseChar_ch((c)) : \
+				 xmlCharInRange((c), &xmlIsBaseCharGroup))
+
+XMLPUBVAR const xmlChRangeGroup xmlIsBaseCharGroup;
+
+/**
+ * xmlIsBlank_ch:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsBlank_ch(c)	(((c) == 0x20) || \
+				 ((0x9 <= (c)) && ((c) <= 0xa)) || \
+				 ((c) == 0xd))
+
+/**
+ * xmlIsBlankQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsBlankQ(c)		(((c) < 0x100) ? \
+				 xmlIsBlank_ch((c)) : 0)
+
+
+/**
+ * xmlIsChar_ch:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsChar_ch(c)		(((0x9 <= (c)) && ((c) <= 0xa)) || \
+				 ((c) == 0xd) || \
+				  (0x20 <= (c)))
+
+/**
+ * xmlIsCharQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsCharQ(c)		(((c) < 0x100) ? \
+				 xmlIsChar_ch((c)) :\
+				(((0x100 <= (c)) && ((c) <= 0xd7ff)) || \
+				 ((0xe000 <= (c)) && ((c) <= 0xfffd)) || \
+				 ((0x10000 <= (c)) && ((c) <= 0x10ffff))))
+
+XMLPUBVAR const xmlChRangeGroup xmlIsCharGroup;
+
+/**
+ * xmlIsCombiningQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsCombiningQ(c)	(((c) < 0x100) ? \
+				 0 : \
+				 xmlCharInRange((c), &xmlIsCombiningGroup))
+
+XMLPUBVAR const xmlChRangeGroup xmlIsCombiningGroup;
+
+/**
+ * xmlIsDigit_ch:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsDigit_ch(c)	(((0x30 <= (c)) && ((c) <= 0x39)))
+
+/**
+ * xmlIsDigitQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsDigitQ(c)		(((c) < 0x100) ? \
+				 xmlIsDigit_ch((c)) : \
+				 xmlCharInRange((c), &xmlIsDigitGroup))
+
+XMLPUBVAR const xmlChRangeGroup xmlIsDigitGroup;
+
+/**
+ * xmlIsExtender_ch:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsExtender_ch(c)	(((c) == 0xb7))
+
+/**
+ * xmlIsExtenderQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsExtenderQ(c)	(((c) < 0x100) ? \
+				 xmlIsExtender_ch((c)) : \
+				 xmlCharInRange((c), &xmlIsExtenderGroup))
+
+XMLPUBVAR const xmlChRangeGroup xmlIsExtenderGroup;
+
+/**
+ * xmlIsIdeographicQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsIdeographicQ(c)	(((c) < 0x100) ? \
+				 0 :\
+				(((0x4e00 <= (c)) && ((c) <= 0x9fa5)) || \
+				 ((c) == 0x3007) || \
+				 ((0x3021 <= (c)) && ((c) <= 0x3029))))
+
+XMLPUBVAR const xmlChRangeGroup xmlIsIdeographicGroup;
+XMLPUBVAR const unsigned char xmlIsPubidChar_tab[256];
+
+/**
+ * xmlIsPubidChar_ch:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsPubidChar_ch(c)	(xmlIsPubidChar_tab[(c)])
+
+/**
+ * xmlIsPubidCharQ:
+ * @c: char to validate
+ *
+ * Automatically generated by genChRanges.py
+ */
+#define xmlIsPubidCharQ(c)	(((c) < 0x100) ? \
+				 xmlIsPubidChar_ch((c)) : 0)
+
+XMLPUBFUN int XMLCALL
+		xmlIsBaseChar(unsigned int ch);
+XMLPUBFUN int XMLCALL
+		xmlIsBlank(unsigned int ch);
+XMLPUBFUN int XMLCALL
+		xmlIsChar(unsigned int ch);
+XMLPUBFUN int XMLCALL
+		xmlIsCombining(unsigned int ch);
+XMLPUBFUN int XMLCALL
+		xmlIsDigit(unsigned int ch);
+XMLPUBFUN int XMLCALL
+		xmlIsExtender(unsigned int ch);
+XMLPUBFUN int XMLCALL
+		xmlIsIdeographic(unsigned int ch);
+XMLPUBFUN int XMLCALL
+		xmlIsPubidChar(unsigned int ch);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* __XML_CHVALID_H__ */

+ 217 - 0
libpq_test/include/libxml/debugXML.h

@@ -0,0 +1,217 @@
+/*
+ * Summary: Tree debugging APIs
+ * Description: Interfaces to a set of routines used for debugging the tree
+ *              produced by the XML parser.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __DEBUG_XML__
+#define __DEBUG_XML__
+#include <stdio.h>
+#include <libxml/xmlversion.h>
+#include <libxml/tree.h>
+
+#ifdef LIBXML_DEBUG_ENABLED
+
+#include <libxml/xpath.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * The standard Dump routines.
+ */
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpString	(FILE *output,
+				 const xmlChar *str);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpAttr	(FILE *output,
+				 xmlAttrPtr attr,
+				 int depth);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpAttrList	(FILE *output,
+				 xmlAttrPtr attr,
+				 int depth);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpOneNode	(FILE *output,
+				 xmlNodePtr node,
+				 int depth);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpNode	(FILE *output,
+				 xmlNodePtr node,
+				 int depth);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpNodeList	(FILE *output,
+				 xmlNodePtr node,
+				 int depth);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpDocumentHead(FILE *output,
+				 xmlDocPtr doc);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpDocument	(FILE *output,
+				 xmlDocPtr doc);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpDTD		(FILE *output,
+				 xmlDtdPtr dtd);
+XMLPUBFUN void XMLCALL
+	xmlDebugDumpEntities	(FILE *output,
+				 xmlDocPtr doc);
+
+/****************************************************************
+ *								*
+ *			Checking routines			*
+ *								*
+ ****************************************************************/
+
+XMLPUBFUN int XMLCALL
+	xmlDebugCheckDocument	(FILE * output,
+				 xmlDocPtr doc);
+
+/****************************************************************
+ *								*
+ *			XML shell helpers			*
+ *								*
+ ****************************************************************/
+
+XMLPUBFUN void XMLCALL
+	xmlLsOneNode		(FILE *output, xmlNodePtr node);
+XMLPUBFUN int XMLCALL
+	xmlLsCountNode		(xmlNodePtr node);
+
+XMLPUBFUN const char * XMLCALL
+	xmlBoolToText		(int boolval);
+
+/****************************************************************
+ *								*
+ *	 The XML shell related structures and functions		*
+ *								*
+ ****************************************************************/
+
+#ifdef LIBXML_XPATH_ENABLED
+/**
+ * xmlShellReadlineFunc:
+ * @prompt:  a string prompt
+ *
+ * This is a generic signature for the XML shell input function.
+ *
+ * Returns a string which will be freed by the Shell.
+ */
+typedef char * (* xmlShellReadlineFunc)(char *prompt);
+
+/**
+ * xmlShellCtxt:
+ *
+ * A debugging shell context.
+ * TODO: add the defined function tables.
+ */
+typedef struct _xmlShellCtxt xmlShellCtxt;
+typedef xmlShellCtxt *xmlShellCtxtPtr;
+struct _xmlShellCtxt {
+    char *filename;
+    xmlDocPtr doc;
+    xmlNodePtr node;
+    xmlXPathContextPtr pctxt;
+    int loaded;
+    FILE *output;
+    xmlShellReadlineFunc input;
+};
+
+/**
+ * xmlShellCmd:
+ * @ctxt:  a shell context
+ * @arg:  a string argument
+ * @node:  a first node
+ * @node2:  a second node
+ *
+ * This is a generic signature for the XML shell functions.
+ *
+ * Returns an int, negative returns indicating errors.
+ */
+typedef int (* xmlShellCmd) (xmlShellCtxtPtr ctxt,
+                             char *arg,
+			     xmlNodePtr node,
+			     xmlNodePtr node2);
+
+XMLPUBFUN void XMLCALL
+	xmlShellPrintXPathError	(int errorType,
+				 const char *arg);
+XMLPUBFUN void XMLCALL
+	xmlShellPrintXPathResult(xmlXPathObjectPtr list);
+XMLPUBFUN int XMLCALL
+	xmlShellList		(xmlShellCtxtPtr ctxt,
+				 char *arg,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+XMLPUBFUN int XMLCALL
+	xmlShellBase		(xmlShellCtxtPtr ctxt,
+				 char *arg,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+XMLPUBFUN int XMLCALL
+	xmlShellDir		(xmlShellCtxtPtr ctxt,
+				 char *arg,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+XMLPUBFUN int XMLCALL
+	xmlShellLoad		(xmlShellCtxtPtr ctxt,
+				 char *filename,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+#ifdef LIBXML_OUTPUT_ENABLED
+XMLPUBFUN void XMLCALL
+	xmlShellPrintNode	(xmlNodePtr node);
+XMLPUBFUN int XMLCALL
+	xmlShellCat		(xmlShellCtxtPtr ctxt,
+				 char *arg,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+XMLPUBFUN int XMLCALL
+	xmlShellWrite		(xmlShellCtxtPtr ctxt,
+				 char *filename,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+XMLPUBFUN int XMLCALL
+	xmlShellSave		(xmlShellCtxtPtr ctxt,
+				 char *filename,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+#endif /* LIBXML_OUTPUT_ENABLED */
+#ifdef LIBXML_VALID_ENABLED
+XMLPUBFUN int XMLCALL
+	xmlShellValidate	(xmlShellCtxtPtr ctxt,
+				 char *dtd,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+#endif /* LIBXML_VALID_ENABLED */
+XMLPUBFUN int XMLCALL
+	xmlShellDu		(xmlShellCtxtPtr ctxt,
+				 char *arg,
+				 xmlNodePtr tree,
+				 xmlNodePtr node2);
+XMLPUBFUN int XMLCALL
+	xmlShellPwd		(xmlShellCtxtPtr ctxt,
+				 char *buffer,
+				 xmlNodePtr node,
+				 xmlNodePtr node2);
+
+/*
+ * The Shell interface.
+ */
+XMLPUBFUN void XMLCALL
+	xmlShell		(xmlDocPtr doc,
+				 char *filename,
+				 xmlShellReadlineFunc input,
+				 FILE *output);
+
+#endif /* LIBXML_XPATH_ENABLED */
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* LIBXML_DEBUG_ENABLED */
+#endif /* __DEBUG_XML__ */

+ 86 - 0
libpq_test/include/libxml/dict.h

@@ -0,0 +1,86 @@
+/*
+ * Summary: string dictionary
+ * Description: dictionary of reusable strings, just used to avoid allocation
+ *         and freeing operations.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __XML_DICT_H__
+#define __XML_DICT_H__
+
+#ifdef __cplusplus
+#define __XML_EXTERNC	extern "C"
+#else
+#define __XML_EXTERNC
+#endif
+
+/*
+ * The dictionary.
+ */
+__XML_EXTERNC typedef struct _xmlDict xmlDict;
+__XML_EXTERNC typedef xmlDict *xmlDictPtr;
+
+#include <limits.h>
+#include <libxml/xmlversion.h>
+#include <libxml/tree.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Initializer
+ */
+XMLPUBFUN int XMLCALL  xmlInitializeDict(void);
+
+/*
+ * Constructor and destructor.
+ */
+XMLPUBFUN xmlDictPtr XMLCALL
+			xmlDictCreate	(void);
+XMLPUBFUN size_t XMLCALL
+			xmlDictSetLimit	(xmlDictPtr dict,
+                                         size_t limit);
+XMLPUBFUN size_t XMLCALL
+			xmlDictGetUsage (xmlDictPtr dict);
+XMLPUBFUN xmlDictPtr XMLCALL
+			xmlDictCreateSub(xmlDictPtr sub);
+XMLPUBFUN int XMLCALL
+			xmlDictReference(xmlDictPtr dict);
+XMLPUBFUN void XMLCALL
+			xmlDictFree	(xmlDictPtr dict);
+
+/*
+ * Lookup of entry in the dictionary.
+ */
+XMLPUBFUN const xmlChar * XMLCALL
+			xmlDictLookup	(xmlDictPtr dict,
+		                         const xmlChar *name,
+		                         int len);
+XMLPUBFUN const xmlChar * XMLCALL
+			xmlDictExists	(xmlDictPtr dict,
+		                         const xmlChar *name,
+		                         int len);
+XMLPUBFUN const xmlChar * XMLCALL
+			xmlDictQLookup	(xmlDictPtr dict,
+		                         const xmlChar *prefix,
+		                         const xmlChar *name);
+XMLPUBFUN int XMLCALL
+			xmlDictOwns	(xmlDictPtr dict,
+					 const xmlChar *str);
+XMLPUBFUN int XMLCALL
+			xmlDictSize	(xmlDictPtr dict);
+
+/*
+ * Cleanup function
+ */
+XMLPUBFUN void XMLCALL
+                        xmlDictCleanup  (void);
+
+#ifdef __cplusplus
+}
+#endif
+#endif /* ! __XML_DICT_H__ */

+ 240 - 0
libpq_test/include/libxml/encoding.h

@@ -0,0 +1,240 @@
+/*
+ * Summary: interface for the encoding conversion functions
+ * Description: interface for the encoding conversion functions needed for
+ *              XML basic encoding and iconv() support.
+ *
+ * Related specs are
+ * rfc2044        (UTF-8 and UTF-16) F. Yergeau Alis Technologies
+ * [ISO-10646]    UTF-8 and UTF-16 in Annexes
+ * [ISO-8859-1]   ISO Latin-1 characters codes.
+ * [UNICODE]      The Unicode Consortium, "The Unicode Standard --
+ *                Worldwide Character Encoding -- Version 1.0", Addison-
+ *                Wesley, Volume 1, 1991, Volume 2, 1992.  UTF-8 is
+ *                described in Unicode Technical Report #4.
+ * [US-ASCII]     Coded Character Set--7-bit American Standard Code for
+ *                Information Interchange, ANSI X3.4-1986.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __XML_CHAR_ENCODING_H__
+#define __XML_CHAR_ENCODING_H__
+
+#include <libxml/xmlversion.h>
+
+#ifdef LIBXML_ICONV_ENABLED
+#include <iconv.h>
+#endif
+#ifdef LIBXML_ICU_ENABLED
+#include <unicode/ucnv.h>
+#endif
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * xmlCharEncoding:
+ *
+ * Predefined values for some standard encodings.
+ * Libxml does not do beforehand translation on UTF8 and ISOLatinX.
+ * It also supports ASCII, ISO-8859-1, and UTF16 (LE and BE) by default.
+ *
+ * Anything else would have to be translated to UTF8 before being
+ * given to the parser itself. The BOM for UTF16 and the encoding
+ * declaration are looked at and a converter is looked for at that
+ * point. If not found the parser stops here as asked by the XML REC. A
+ * converter can be registered by the user using xmlRegisterCharEncodingHandler
+ * but the current form doesn't allow stateful transcoding (a serious
+ * problem agreed !). If iconv has been found it will be used
+ * automatically and allow stateful transcoding, the simplest is then
+ * to be sure to enable iconv and to provide iconv libs for the encoding
+ * support needed.
+ *
+ * Note that the generic "UTF-16" is not a predefined value.  Instead, only
+ * the specific UTF-16LE and UTF-16BE are present.
+ */
+typedef enum {
+    XML_CHAR_ENCODING_ERROR=   -1, /* No char encoding detected */
+    XML_CHAR_ENCODING_NONE=	0, /* No char encoding detected */
+    XML_CHAR_ENCODING_UTF8=	1, /* UTF-8 */
+    XML_CHAR_ENCODING_UTF16LE=	2, /* UTF-16 little endian */
+    XML_CHAR_ENCODING_UTF16BE=	3, /* UTF-16 big endian */
+    XML_CHAR_ENCODING_UCS4LE=	4, /* UCS-4 little endian */
+    XML_CHAR_ENCODING_UCS4BE=	5, /* UCS-4 big endian */
+    XML_CHAR_ENCODING_EBCDIC=	6, /* EBCDIC uh! */
+    XML_CHAR_ENCODING_UCS4_2143=7, /* UCS-4 unusual ordering */
+    XML_CHAR_ENCODING_UCS4_3412=8, /* UCS-4 unusual ordering */
+    XML_CHAR_ENCODING_UCS2=	9, /* UCS-2 */
+    XML_CHAR_ENCODING_8859_1=	10,/* ISO-8859-1 ISO Latin 1 */
+    XML_CHAR_ENCODING_8859_2=	11,/* ISO-8859-2 ISO Latin 2 */
+    XML_CHAR_ENCODING_8859_3=	12,/* ISO-8859-3 */
+    XML_CHAR_ENCODING_8859_4=	13,/* ISO-8859-4 */
+    XML_CHAR_ENCODING_8859_5=	14,/* ISO-8859-5 */
+    XML_CHAR_ENCODING_8859_6=	15,/* ISO-8859-6 */
+    XML_CHAR_ENCODING_8859_7=	16,/* ISO-8859-7 */
+    XML_CHAR_ENCODING_8859_8=	17,/* ISO-8859-8 */
+    XML_CHAR_ENCODING_8859_9=	18,/* ISO-8859-9 */
+    XML_CHAR_ENCODING_2022_JP=  19,/* ISO-2022-JP */
+    XML_CHAR_ENCODING_SHIFT_JIS=20,/* Shift_JIS */
+    XML_CHAR_ENCODING_EUC_JP=   21,/* EUC-JP */
+    XML_CHAR_ENCODING_ASCII=    22 /* pure ASCII */
+} xmlCharEncoding;
+
+/**
+ * xmlCharEncodingInputFunc:
+ * @out:  a pointer to an array of bytes to store the UTF-8 result
+ * @outlen:  the length of @out
+ * @in:  a pointer to an array of chars in the original encoding
+ * @inlen:  the length of @in
+ *
+ * Take a block of chars in the original encoding and try to convert
+ * it to an UTF-8 block of chars out.
+ *
+ * Returns the number of bytes written, -1 if lack of space, or -2
+ *     if the transcoding failed.
+ * The value of @inlen after return is the number of octets consumed
+ *     if the return value is positive, else unpredictiable.
+ * The value of @outlen after return is the number of octets consumed.
+ */
+typedef int (* xmlCharEncodingInputFunc)(unsigned char *out, int *outlen,
+                                         const unsigned char *in, int *inlen);
+
+
+/**
+ * xmlCharEncodingOutputFunc:
+ * @out:  a pointer to an array of bytes to store the result
+ * @outlen:  the length of @out
+ * @in:  a pointer to an array of UTF-8 chars
+ * @inlen:  the length of @in
+ *
+ * Take a block of UTF-8 chars in and try to convert it to another
+ * encoding.
+ * Note: a first call designed to produce heading info is called with
+ * in = NULL. If stateful this should also initialize the encoder state.
+ *
+ * Returns the number of bytes written, -1 if lack of space, or -2
+ *     if the transcoding failed.
+ * The value of @inlen after return is the number of octets consumed
+ *     if the return value is positive, else unpredictiable.
+ * The value of @outlen after return is the number of octets produced.
+ */
+typedef int (* xmlCharEncodingOutputFunc)(unsigned char *out, int *outlen,
+                                          const unsigned char *in, int *inlen);
+
+
+/*
+ * Block defining the handlers for non UTF-8 encodings.
+ * If iconv is supported, there are two extra fields.
+ */
+#ifdef LIBXML_ICU_ENABLED
+struct _uconv_t {
+  UConverter *uconv; /* for conversion between an encoding and UTF-16 */
+  UConverter *utf8; /* for conversion between UTF-8 and UTF-16 */
+};
+typedef struct _uconv_t uconv_t;
+#endif
+
+typedef struct _xmlCharEncodingHandler xmlCharEncodingHandler;
+typedef xmlCharEncodingHandler *xmlCharEncodingHandlerPtr;
+struct _xmlCharEncodingHandler {
+    char                       *name;
+    xmlCharEncodingInputFunc   input;
+    xmlCharEncodingOutputFunc  output;
+#ifdef LIBXML_ICONV_ENABLED
+    iconv_t                    iconv_in;
+    iconv_t                    iconv_out;
+#endif /* LIBXML_ICONV_ENABLED */
+#ifdef LIBXML_ICU_ENABLED
+    uconv_t                    *uconv_in;
+    uconv_t                    *uconv_out;
+#endif /* LIBXML_ICU_ENABLED */
+};
+
+#ifdef __cplusplus
+}
+#endif
+#include <libxml/tree.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * Interfaces for encoding handlers.
+ */
+XMLPUBFUN void XMLCALL
+	xmlInitCharEncodingHandlers	(void);
+XMLPUBFUN void XMLCALL
+	xmlCleanupCharEncodingHandlers	(void);
+XMLPUBFUN void XMLCALL
+	xmlRegisterCharEncodingHandler	(xmlCharEncodingHandlerPtr handler);
+XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
+	xmlGetCharEncodingHandler	(xmlCharEncoding enc);
+XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
+	xmlFindCharEncodingHandler	(const char *name);
+XMLPUBFUN xmlCharEncodingHandlerPtr XMLCALL
+	xmlNewCharEncodingHandler	(const char *name,
+					 xmlCharEncodingInputFunc input,
+					 xmlCharEncodingOutputFunc output);
+
+/*
+ * Interfaces for encoding names and aliases.
+ */
+XMLPUBFUN int XMLCALL
+	xmlAddEncodingAlias		(const char *name,
+					 const char *alias);
+XMLPUBFUN int XMLCALL
+	xmlDelEncodingAlias		(const char *alias);
+XMLPUBFUN const char * XMLCALL
+	xmlGetEncodingAlias		(const char *alias);
+XMLPUBFUN void XMLCALL
+	xmlCleanupEncodingAliases	(void);
+XMLPUBFUN xmlCharEncoding XMLCALL
+	xmlParseCharEncoding		(const char *name);
+XMLPUBFUN const char * XMLCALL
+	xmlGetCharEncodingName		(xmlCharEncoding enc);
+
+/*
+ * Interfaces directly used by the parsers.
+ */
+XMLPUBFUN xmlCharEncoding XMLCALL
+	xmlDetectCharEncoding		(const unsigned char *in,
+					 int len);
+
+XMLPUBFUN int XMLCALL
+	xmlCharEncOutFunc		(xmlCharEncodingHandler *handler,
+					 xmlBufferPtr out,
+					 xmlBufferPtr in);
+
+XMLPUBFUN int XMLCALL
+	xmlCharEncInFunc		(xmlCharEncodingHandler *handler,
+					 xmlBufferPtr out,
+					 xmlBufferPtr in);
+XMLPUBFUN int XMLCALL
+	xmlCharEncFirstLine		(xmlCharEncodingHandler *handler,
+					 xmlBufferPtr out,
+					 xmlBufferPtr in);
+XMLPUBFUN int XMLCALL
+	xmlCharEncCloseFunc		(xmlCharEncodingHandler *handler);
+
+/*
+ * Export a few useful functions
+ */
+#ifdef LIBXML_OUTPUT_ENABLED
+XMLPUBFUN int XMLCALL
+	UTF8Toisolat1			(unsigned char *out,
+					 int *outlen,
+					 const unsigned char *in,
+					 int *inlen);
+#endif /* LIBXML_OUTPUT_ENABLED */
+XMLPUBFUN int XMLCALL
+	isolat1ToUTF8			(unsigned char *out,
+					 int *outlen,
+					 const unsigned char *in,
+					 int *inlen);
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __XML_CHAR_ENCODING_H__ */

+ 151 - 0
libpq_test/include/libxml/entities.h

@@ -0,0 +1,151 @@
+/*
+ * Summary: interface for the XML entities handling
+ * Description: this module provides some of the entity API needed
+ *              for the parser and applications.
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Daniel Veillard
+ */
+
+#ifndef __XML_ENTITIES_H__
+#define __XML_ENTITIES_H__
+
+#include <libxml/xmlversion.h>
+#include <libxml/tree.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+/*
+ * The different valid entity types.
+ */
+typedef enum {
+    XML_INTERNAL_GENERAL_ENTITY = 1,
+    XML_EXTERNAL_GENERAL_PARSED_ENTITY = 2,
+    XML_EXTERNAL_GENERAL_UNPARSED_ENTITY = 3,
+    XML_INTERNAL_PARAMETER_ENTITY = 4,
+    XML_EXTERNAL_PARAMETER_ENTITY = 5,
+    XML_INTERNAL_PREDEFINED_ENTITY = 6
+} xmlEntityType;
+
+/*
+ * An unit of storage for an entity, contains the string, the value
+ * and the linkind data needed for the linking in the hash table.
+ */
+
+struct _xmlEntity {
+    void           *_private;	        /* application data */
+    xmlElementType          type;       /* XML_ENTITY_DECL, must be second ! */
+    const xmlChar          *name;	/* Entity name */
+    struct _xmlNode    *children;	/* First child link */
+    struct _xmlNode        *last;	/* Last child link */
+    struct _xmlDtd       *parent;	/* -> DTD */
+    struct _xmlNode        *next;	/* next sibling link  */
+    struct _xmlNode        *prev;	/* previous sibling link  */
+    struct _xmlDoc          *doc;       /* the containing document */
+
+    xmlChar                *orig;	/* content without ref substitution */
+    xmlChar             *content;	/* content or ndata if unparsed */
+    int                   length;	/* the content length */
+    xmlEntityType          etype;	/* The entity type */
+    const xmlChar    *ExternalID;	/* External identifier for PUBLIC */
+    const xmlChar      *SystemID;	/* URI for a SYSTEM or PUBLIC Entity */
+
+    struct _xmlEntity     *nexte;	/* unused */
+    const xmlChar           *URI;	/* the full URI as computed */
+    int                    owner;	/* does the entity own the childrens */
+    int			 checked;	/* was the entity content checked */
+					/* this is also used to count entities
+					 * references done from that entity
+					 * and if it contains '<' */
+};
+
+/*
+ * All entities are stored in an hash table.
+ * There is 2 separate hash tables for global and parameter entities.
+ */
+
+typedef struct _xmlHashTable xmlEntitiesTable;
+typedef xmlEntitiesTable *xmlEntitiesTablePtr;
+
+/*
+ * External functions:
+ */
+
+#ifdef LIBXML_LEGACY_ENABLED
+XMLPUBFUN void XMLCALL
+		xmlInitializePredefinedEntities	(void);
+#endif /* LIBXML_LEGACY_ENABLED */
+
+XMLPUBFUN xmlEntityPtr XMLCALL
+			xmlNewEntity		(xmlDocPtr doc,
+						 const xmlChar *name,
+						 int type,
+						 const xmlChar *ExternalID,
+						 const xmlChar *SystemID,
+						 const xmlChar *content);
+XMLPUBFUN xmlEntityPtr XMLCALL
+			xmlAddDocEntity		(xmlDocPtr doc,
+						 const xmlChar *name,
+						 int type,
+						 const xmlChar *ExternalID,
+						 const xmlChar *SystemID,
+						 const xmlChar *content);
+XMLPUBFUN xmlEntityPtr XMLCALL
+			xmlAddDtdEntity		(xmlDocPtr doc,
+						 const xmlChar *name,
+						 int type,
+						 const xmlChar *ExternalID,
+						 const xmlChar *SystemID,
+						 const xmlChar *content);
+XMLPUBFUN xmlEntityPtr XMLCALL
+			xmlGetPredefinedEntity	(const xmlChar *name);
+XMLPUBFUN xmlEntityPtr XMLCALL
+			xmlGetDocEntity		(const xmlDoc *doc,
+						 const xmlChar *name);
+XMLPUBFUN xmlEntityPtr XMLCALL
+			xmlGetDtdEntity		(xmlDocPtr doc,
+						 const xmlChar *name);
+XMLPUBFUN xmlEntityPtr XMLCALL
+			xmlGetParameterEntity	(xmlDocPtr doc,
+						 const xmlChar *name);
+#ifdef LIBXML_LEGACY_ENABLED
+XMLPUBFUN const xmlChar * XMLCALL
+			xmlEncodeEntities	(xmlDocPtr doc,
+						 const xmlChar *input);
+#endif /* LIBXML_LEGACY_ENABLED */
+XMLPUBFUN xmlChar * XMLCALL
+			xmlEncodeEntitiesReentrant(xmlDocPtr doc,
+						 const xmlChar *input);
+XMLPUBFUN xmlChar * XMLCALL
+			xmlEncodeSpecialChars	(const xmlDoc *doc,
+						 const xmlChar *input);
+XMLPUBFUN xmlEntitiesTablePtr XMLCALL
+			xmlCreateEntitiesTable	(void);
+#ifdef LIBXML_TREE_ENABLED
+XMLPUBFUN xmlEntitiesTablePtr XMLCALL
+			xmlCopyEntitiesTable	(xmlEntitiesTablePtr table);
+#endif /* LIBXML_TREE_ENABLED */
+XMLPUBFUN void XMLCALL
+			xmlFreeEntitiesTable	(xmlEntitiesTablePtr table);
+#ifdef LIBXML_OUTPUT_ENABLED
+XMLPUBFUN void XMLCALL
+			xmlDumpEntitiesTable	(xmlBufferPtr buf,
+						 xmlEntitiesTablePtr table);
+XMLPUBFUN void XMLCALL
+			xmlDumpEntityDecl	(xmlBufferPtr buf,
+						 xmlEntityPtr ent);
+#endif /* LIBXML_OUTPUT_ENABLED */
+#ifdef LIBXML_LEGACY_ENABLED
+XMLPUBFUN void XMLCALL
+			xmlCleanupPredefinedEntities(void);
+#endif /* LIBXML_LEGACY_ENABLED */
+
+
+#ifdef __cplusplus
+}
+#endif
+
+# endif /* __XML_ENTITIES_H__ */

+ 509 - 0
libpq_test/include/libxml/globals.h

@@ -0,0 +1,509 @@
+/*
+ * Summary: interface for all global variables of the library
+ * Description: all the global variables and thread handling for
+ *              those variables is handled by this module.
+ *
+ * The bottom of this file is automatically generated by build_glob.py
+ * based on the description file global.data
+ *
+ * Copy: See Copyright for the status of this software.
+ *
+ * Author: Gary Pennington <Gary.Pennington@uk.sun.com>, Daniel Veillard
+ */
+
+#ifndef __XML_GLOBALS_H
+#define __XML_GLOBALS_H
+
+#include <libxml/xmlversion.h>
+#include <libxml/parser.h>
+#include <libxml/xmlerror.h>
+#include <libxml/SAX.h>
+#include <libxml/SAX2.h>
+#include <libxml/xmlmemory.h>
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+XMLPUBFUN void XMLCALL xmlInitGlobals(void);
+XMLPUBFUN void XMLCALL xmlCleanupGlobals(void);
+
+/**
+ * xmlParserInputBufferCreateFilenameFunc:
+ * @URI: the URI to read from
+ * @enc: the requested source encoding
+ *
+ * Signature for the function doing the lookup for a suitable input method
+ * corresponding to an URI.
+ *
+ * Returns the new xmlParserInputBufferPtr in case of success or NULL if no
+ *         method was found.
+ */
+typedef xmlParserInputBufferPtr (*xmlParserInputBufferCreateFilenameFunc) (const char *URI,
+									   xmlCharEncoding enc);
+
+
+/**
+ * xmlOutputBufferCreateFilenameFunc:
+ * @URI: the URI to write to
+ * @enc: the requested target encoding
+ *
+ * Signature for the function doing the lookup for a suitable output method
+ * corresponding to an URI.
+ *
+ * Returns the new xmlOutputBufferPtr in case of success or NULL if no
+ *         method was found.
+ */
+typedef xmlOutputBufferPtr (*xmlOutputBufferCreateFilenameFunc) (const char *URI,
+								 xmlCharEncodingHandlerPtr encoder,
+								 int compression);
+
+XMLPUBFUN xmlParserInputBufferCreateFilenameFunc
+XMLCALL xmlParserInputBufferCreateFilenameDefault (xmlParserInputBufferCreateFilenameFunc func);
+XMLPUBFUN xmlOutputBufferCreateFilenameFunc
+XMLCALL xmlOutputBufferCreateFilenameDefault (xmlOutputBufferCreateFilenameFunc func);
+
+/*
+ * Externally global symbols which need to be protected for backwards
+ * compatibility support.
+ */
+
+#undef	docbDefaultSAXHandler
+#undef	htmlDefaultSAXHandler
+#undef	oldXMLWDcompatibility
+#undef	xmlBufferAllocScheme
+#undef	xmlDefaultBufferSize
+#undef	xmlDefaultSAXHandler
+#undef	xmlDefaultSAXLocator
+#undef	xmlDoValidityCheckingDefaultValue
+#undef	xmlFree
+#undef	xmlGenericError
+#undef	xmlStructuredError
+#undef	xmlGenericErrorContext
+#undef	xmlStructuredErrorContext
+#undef	xmlGetWarningsDefaultValue
+#undef	xmlIndentTreeOutput
+#undef  xmlTreeIndentString
+#undef	xmlKeepBlanksDefaultValue
+#undef	xmlLineNumbersDefaultValue
+#undef	xmlLoadExtDtdDefaultValue
+#undef	xmlMalloc
+#undef	xmlMallocAtomic
+#undef	xmlMemStrdup
+#undef	xmlParserDebugEntities
+#undef	xmlParserVersion
+#undef	xmlPedanticParserDefaultValue
+#undef	xmlRealloc
+#undef	xmlSaveNoEmptyTags
+#undef	xmlSubstituteEntitiesDefaultValue
+#undef  xmlRegisterNodeDefaultValue
+#undef  xmlDeregisterNodeDefaultValue
+#undef  xmlLastError
+#undef  xmlParserInputBufferCreateFilenameValue
+#undef  xmlOutputBufferCreateFilenameValue
+
+/**
+ * xmlRegisterNodeFunc:
+ * @node: the current node
+ *
+ * Signature for the registration callback of a created node
+ */
+typedef void (*xmlRegisterNodeFunc) (xmlNodePtr node);
+/**
+ * xmlDeregisterNodeFunc:
+ * @node: the current node
+ *
+ * Signature for the deregistration callback of a discarded node
+ */
+typedef void (*xmlDeregisterNodeFunc) (xmlNodePtr node);
+
+typedef struct _xmlGlobalState xmlGlobalState;
+typedef xmlGlobalState *xmlGlobalStatePtr;
+struct _xmlGlobalState
+{
+	const char *xmlParserVersion;
+
+	xmlSAXLocator xmlDefaultSAXLocator;
+	xmlSAXHandlerV1 xmlDefaultSAXHandler;
+	xmlSAXHandlerV1 docbDefaultSAXHandler;
+	xmlSAXHandlerV1 htmlDefaultSAXHandler;
+
+	xmlFreeFunc xmlFree;
+	xmlMallocFunc xmlMalloc;
+	xmlStrdupFunc xmlMemStrdup;
+	xmlReallocFunc xmlRealloc;
+
+	xmlGenericErrorFunc xmlGenericError;
+	xmlStructuredErrorFunc xmlStructuredError;
+	void *xmlGenericErrorContext;
+
+	int oldXMLWDcompatibility;
+
+	xmlBufferAllocationScheme xmlBufferAllocScheme;
+	int xmlDefaultBufferSize;
+
+	int xmlSubstituteEntitiesDefaultValue;
+	int xmlDoValidityCheckingDefaultValue;
+	int xmlGetWarningsDefaultValue;
+	int xmlKeepBlanksDefaultValue;
+	int xmlLineNumbersDefaultValue;
+	int xmlLoadExtDtdDefaultValue;
+	int xmlParserDebugEntities;
+	int xmlPedanticParserDefaultValue;
+
+	int xmlSaveNoEmptyTags;
+	int xmlIndentTreeOutput;
+	const char *xmlTreeIndentString;
+
+	xmlRegisterNodeFunc xmlRegisterNodeDefaultValue;
+	xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue;
+
+	xmlMallocFunc xmlMallocAtomic;
+	xmlError xmlLastError;
+
+	xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue;
+	xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue;
+
+	void *xmlStructuredErrorContext;
+};
+
+#ifdef __cplusplus
+}
+#endif
+#include <libxml/threads.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+XMLPUBFUN void XMLCALL	xmlInitializeGlobalState(xmlGlobalStatePtr gs);
+
+XMLPUBFUN void XMLCALL xmlThrDefSetGenericErrorFunc(void *ctx, xmlGenericErrorFunc handler);
+
+XMLPUBFUN void XMLCALL xmlThrDefSetStructuredErrorFunc(void *ctx, xmlStructuredErrorFunc handler);
+
+XMLPUBFUN xmlRegisterNodeFunc XMLCALL xmlRegisterNodeDefault(xmlRegisterNodeFunc func);
+XMLPUBFUN xmlRegisterNodeFunc XMLCALL xmlThrDefRegisterNodeDefault(xmlRegisterNodeFunc func);
+XMLPUBFUN xmlDeregisterNodeFunc XMLCALL xmlDeregisterNodeDefault(xmlDeregisterNodeFunc func);
+XMLPUBFUN xmlDeregisterNodeFunc XMLCALL xmlThrDefDeregisterNodeDefault(xmlDeregisterNodeFunc func);
+
+XMLPUBFUN xmlOutputBufferCreateFilenameFunc XMLCALL
+	xmlThrDefOutputBufferCreateFilenameDefault(xmlOutputBufferCreateFilenameFunc func);
+XMLPUBFUN xmlParserInputBufferCreateFilenameFunc XMLCALL
+	xmlThrDefParserInputBufferCreateFilenameDefault(
+				xmlParserInputBufferCreateFilenameFunc func);
+
+/** DOC_DISABLE */
+/*
+ * In general the memory allocation entry points are not kept
+ * thread specific but this can be overridden by LIBXML_THREAD_ALLOC_ENABLED
+ *    - xmlMalloc
+ *    - xmlMallocAtomic
+ *    - xmlRealloc
+ *    - xmlMemStrdup
+ *    - xmlFree
+ */
+
+#ifdef LIBXML_THREAD_ALLOC_ENABLED
+#ifdef LIBXML_THREAD_ENABLED
+XMLPUBFUN  xmlMallocFunc * XMLCALL __xmlMalloc(void);
+#define xmlMalloc \
+(*(__xmlMalloc()))
+#else
+XMLPUBVAR xmlMallocFunc xmlMalloc;
+#endif
+
+#ifdef LIBXML_THREAD_ENABLED
+XMLPUBFUN  xmlMallocFunc * XMLCALL __xmlMallocAtomic(void);
+#define xmlMallocAtomic \
+(*(__xmlMallocAtomic()))
+#else
+XMLPUBVAR xmlMallocFunc xmlMallocAtomic;
+#endif
+
+#ifdef LIBXML_THREAD_ENABLED
+XMLPUBFUN  xmlReallocFunc * XMLCALL __xmlRealloc(void);
+#define xmlRealloc \
+(*(__xmlRealloc()))
+#else
+XMLPUBVAR xmlReallocFunc xmlRealloc;
+#endif
+
+#ifdef LIBXML_THREAD_ENABLED
+XMLPUBFUN  xmlFreeFunc * XMLCALL __xmlFree(void);
+#define xmlFree \
+(*(__xmlFree()))
+#else
+XMLPUBVAR xmlFreeFunc xmlFree;
+#endif
+
+#ifdef LIBXML_THREAD_ENABLED
+XMLPUBFUN  xmlStrdupFunc * XMLCALL __xmlMemStrdup(void);
+#define xmlMemStrdup \
+(*(__xmlMemStrdup()))
+#else
+XMLPUBVAR xmlStrdupFunc xmlMemStrdup;
+#endif
+
+#else /* !LIBXML_THREAD_ALLOC_ENABLED */
+XMLPUBVAR xmlMallocFunc xmlMalloc;
+XMLPUBVAR xmlMallocFunc xmlMallocAtomic;
+XMLPUBVAR xmlReallocFunc xmlRealloc;
+XMLPUBVAR xmlFreeFunc xmlFree;
+XMLPUBVAR xmlStrdupFunc xmlMemStrdup;
+#endif /* LIBXML_THREAD_ALLOC_ENABLED */
+
+#ifdef LIBXML_DOCB_ENABLED
+XMLPUBFUN  xmlSAXHandlerV1 * XMLCALL __docbDefaultSAXHandler(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define docbDefaultSAXHandler \
+(*(__docbDefaultSAXHandler()))
+#else
+XMLPUBVAR xmlSAXHandlerV1 docbDefaultSAXHandler;
+#endif
+#endif
+
+#ifdef LIBXML_HTML_ENABLED
+XMLPUBFUN xmlSAXHandlerV1 * XMLCALL __htmlDefaultSAXHandler(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define htmlDefaultSAXHandler \
+(*(__htmlDefaultSAXHandler()))
+#else
+XMLPUBVAR xmlSAXHandlerV1 htmlDefaultSAXHandler;
+#endif
+#endif
+
+XMLPUBFUN xmlError * XMLCALL __xmlLastError(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlLastError \
+(*(__xmlLastError()))
+#else
+XMLPUBVAR xmlError xmlLastError;
+#endif
+
+/*
+ * Everything starting from the line below is
+ * Automatically generated by build_glob.py.
+ * Do not modify the previous line.
+ */
+
+
+XMLPUBFUN int * XMLCALL __oldXMLWDcompatibility(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define oldXMLWDcompatibility \
+(*(__oldXMLWDcompatibility()))
+#else
+XMLPUBVAR int oldXMLWDcompatibility;
+#endif
+
+XMLPUBFUN xmlBufferAllocationScheme * XMLCALL __xmlBufferAllocScheme(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlBufferAllocScheme \
+(*(__xmlBufferAllocScheme()))
+#else
+XMLPUBVAR xmlBufferAllocationScheme xmlBufferAllocScheme;
+#endif
+XMLPUBFUN xmlBufferAllocationScheme XMLCALL
+	xmlThrDefBufferAllocScheme(xmlBufferAllocationScheme v);
+
+XMLPUBFUN int * XMLCALL __xmlDefaultBufferSize(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlDefaultBufferSize \
+(*(__xmlDefaultBufferSize()))
+#else
+XMLPUBVAR int xmlDefaultBufferSize;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefDefaultBufferSize(int v);
+
+XMLPUBFUN xmlSAXHandlerV1 * XMLCALL __xmlDefaultSAXHandler(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlDefaultSAXHandler \
+(*(__xmlDefaultSAXHandler()))
+#else
+XMLPUBVAR xmlSAXHandlerV1 xmlDefaultSAXHandler;
+#endif
+
+XMLPUBFUN xmlSAXLocator * XMLCALL __xmlDefaultSAXLocator(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlDefaultSAXLocator \
+(*(__xmlDefaultSAXLocator()))
+#else
+XMLPUBVAR xmlSAXLocator xmlDefaultSAXLocator;
+#endif
+
+XMLPUBFUN int * XMLCALL __xmlDoValidityCheckingDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlDoValidityCheckingDefaultValue \
+(*(__xmlDoValidityCheckingDefaultValue()))
+#else
+XMLPUBVAR int xmlDoValidityCheckingDefaultValue;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefDoValidityCheckingDefaultValue(int v);
+
+XMLPUBFUN xmlGenericErrorFunc * XMLCALL __xmlGenericError(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlGenericError \
+(*(__xmlGenericError()))
+#else
+XMLPUBVAR xmlGenericErrorFunc xmlGenericError;
+#endif
+
+XMLPUBFUN xmlStructuredErrorFunc * XMLCALL __xmlStructuredError(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlStructuredError \
+(*(__xmlStructuredError()))
+#else
+XMLPUBVAR xmlStructuredErrorFunc xmlStructuredError;
+#endif
+
+XMLPUBFUN void * * XMLCALL __xmlGenericErrorContext(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlGenericErrorContext \
+(*(__xmlGenericErrorContext()))
+#else
+XMLPUBVAR void * xmlGenericErrorContext;
+#endif
+
+XMLPUBFUN void * * XMLCALL __xmlStructuredErrorContext(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlStructuredErrorContext \
+(*(__xmlStructuredErrorContext()))
+#else
+XMLPUBVAR void * xmlStructuredErrorContext;
+#endif
+
+XMLPUBFUN int * XMLCALL __xmlGetWarningsDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlGetWarningsDefaultValue \
+(*(__xmlGetWarningsDefaultValue()))
+#else
+XMLPUBVAR int xmlGetWarningsDefaultValue;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefGetWarningsDefaultValue(int v);
+
+XMLPUBFUN int * XMLCALL __xmlIndentTreeOutput(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlIndentTreeOutput \
+(*(__xmlIndentTreeOutput()))
+#else
+XMLPUBVAR int xmlIndentTreeOutput;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefIndentTreeOutput(int v);
+
+XMLPUBFUN const char * * XMLCALL __xmlTreeIndentString(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlTreeIndentString \
+(*(__xmlTreeIndentString()))
+#else
+XMLPUBVAR const char * xmlTreeIndentString;
+#endif
+XMLPUBFUN const char * XMLCALL xmlThrDefTreeIndentString(const char * v);
+
+XMLPUBFUN int * XMLCALL __xmlKeepBlanksDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlKeepBlanksDefaultValue \
+(*(__xmlKeepBlanksDefaultValue()))
+#else
+XMLPUBVAR int xmlKeepBlanksDefaultValue;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefKeepBlanksDefaultValue(int v);
+
+XMLPUBFUN int * XMLCALL __xmlLineNumbersDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlLineNumbersDefaultValue \
+(*(__xmlLineNumbersDefaultValue()))
+#else
+XMLPUBVAR int xmlLineNumbersDefaultValue;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefLineNumbersDefaultValue(int v);
+
+XMLPUBFUN int * XMLCALL __xmlLoadExtDtdDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlLoadExtDtdDefaultValue \
+(*(__xmlLoadExtDtdDefaultValue()))
+#else
+XMLPUBVAR int xmlLoadExtDtdDefaultValue;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefLoadExtDtdDefaultValue(int v);
+
+XMLPUBFUN int * XMLCALL __xmlParserDebugEntities(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlParserDebugEntities \
+(*(__xmlParserDebugEntities()))
+#else
+XMLPUBVAR int xmlParserDebugEntities;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefParserDebugEntities(int v);
+
+XMLPUBFUN const char * * XMLCALL __xmlParserVersion(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlParserVersion \
+(*(__xmlParserVersion()))
+#else
+XMLPUBVAR const char * xmlParserVersion;
+#endif
+
+XMLPUBFUN int * XMLCALL __xmlPedanticParserDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlPedanticParserDefaultValue \
+(*(__xmlPedanticParserDefaultValue()))
+#else
+XMLPUBVAR int xmlPedanticParserDefaultValue;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefPedanticParserDefaultValue(int v);
+
+XMLPUBFUN int * XMLCALL __xmlSaveNoEmptyTags(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlSaveNoEmptyTags \
+(*(__xmlSaveNoEmptyTags()))
+#else
+XMLPUBVAR int xmlSaveNoEmptyTags;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefSaveNoEmptyTags(int v);
+
+XMLPUBFUN int * XMLCALL __xmlSubstituteEntitiesDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlSubstituteEntitiesDefaultValue \
+(*(__xmlSubstituteEntitiesDefaultValue()))
+#else
+XMLPUBVAR int xmlSubstituteEntitiesDefaultValue;
+#endif
+XMLPUBFUN int XMLCALL xmlThrDefSubstituteEntitiesDefaultValue(int v);
+
+XMLPUBFUN xmlRegisterNodeFunc * XMLCALL __xmlRegisterNodeDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlRegisterNodeDefaultValue \
+(*(__xmlRegisterNodeDefaultValue()))
+#else
+XMLPUBVAR xmlRegisterNodeFunc xmlRegisterNodeDefaultValue;
+#endif
+
+XMLPUBFUN xmlDeregisterNodeFunc * XMLCALL __xmlDeregisterNodeDefaultValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlDeregisterNodeDefaultValue \
+(*(__xmlDeregisterNodeDefaultValue()))
+#else
+XMLPUBVAR xmlDeregisterNodeFunc xmlDeregisterNodeDefaultValue;
+#endif
+
+XMLPUBFUN xmlParserInputBufferCreateFilenameFunc * XMLCALL \
+				__xmlParserInputBufferCreateFilenameValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlParserInputBufferCreateFilenameValue \
+(*(__xmlParserInputBufferCreateFilenameValue()))
+#else
+XMLPUBVAR xmlParserInputBufferCreateFilenameFunc xmlParserInputBufferCreateFilenameValue;
+#endif
+
+XMLPUBFUN xmlOutputBufferCreateFilenameFunc * XMLCALL __xmlOutputBufferCreateFilenameValue(void);
+#ifdef LIBXML_THREAD_ENABLED
+#define xmlOutputBufferCreateFilenameValue \
+(*(__xmlOutputBufferCreateFilenameValue()))
+#else
+XMLPUBVAR xmlOutputBufferCreateFilenameFunc xmlOutputBufferCreateFilenameValue;
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+
+#endif /* __XML_GLOBALS_H */

Some files were not shown because too many files changed in this diff